ia64/xen-unstable

annotate extras/mini-os/include/ia64/os.h @ 16838:945820bfedb6

minios: POSIX fixes
Fixes some functions which are POSIX. Also make them ifndef HAVE_LIBC.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jan 22 14:20:22 2008 +0000 (2008-01-22)
parents 03c2236e0089
children e35a379e7fe9
rev   line source
awilliam@13907 1 /*
awilliam@13907 2 * Copyright (C) 2007 - Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
awilliam@13907 3 *
awilliam@13907 4 ****************************************************************************
awilliam@13907 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
awilliam@13907 6 * of this software and associated documentation files (the "Software"), to
awilliam@13907 7 * deal in the Software without restriction, including without limitation the
awilliam@13907 8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
awilliam@13907 9 * sell copies of the Software, and to permit persons to whom the Software is
awilliam@13907 10 * furnished to do so, subject to the following conditions:
awilliam@13907 11 *
awilliam@13907 12 * The above copyright notice and this permission notice shall be included in
awilliam@13907 13 * all copies or substantial portions of the Software.
awilliam@13907 14 *
awilliam@13907 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
awilliam@13907 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
awilliam@13907 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
awilliam@13907 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
awilliam@13907 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
awilliam@13907 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
awilliam@13907 21 * DEALINGS IN THE SOFTWARE.
awilliam@13907 22 */
awilliam@13907 23
awilliam@13907 24
awilliam@13907 25 #if !defined(__OS_H__)
awilliam@13907 26 #define __OS_H__
awilliam@13907 27
awilliam@13907 28 #if !defined(__ASSEMBLY__)
awilliam@13907 29
awilliam@13907 30 #include "types.h"
awilliam@13907 31 #include "endian.h"
awilliam@13907 32 #include "ia64_cpu.h"
awilliam@13907 33 #include "atomic.h"
awilliam@13907 34 #include "efi.h"
awilliam@13907 35 #include "sal.h"
awilliam@13907 36 #include "pal.h"
awilliam@13907 37 #include "hypervisor.h"
awilliam@13907 38
awilliam@13907 39
awilliam@13907 40 typedef uint64_t paddr_t; /* Physical address. */
keir@16838 41 #ifndef HAVE_LIBC
awilliam@13907 42 typedef uint64_t caddr_t; /* rr7/kernel memory address. */
keir@16838 43 #endif
awilliam@13907 44
awilliam@13907 45 #include "page.h"
awilliam@13907 46 #include "mm.h"
awilliam@13907 47
awilliam@13907 48
keir@16731 49 void do_exit(void) __attribute__((noreturn));
awilliam@13907 50 void arch_init(start_info_t *si); /* in common.c */
awilliam@13907 51 void arch_print_info(void); /* in common.c */
awilliam@13907 52
awilliam@13907 53
awilliam@13907 54 /* Size of xen_ia64_boot_param.command_line */
awilliam@13907 55 #define COMMAND_LINE_SIZE 512
awilliam@13907 56
awilliam@14302 57 extern struct xen_ia64_boot_param* ia64_boot_paramP;
awilliam@13907 58 extern struct xen_ia64_boot_param ia64BootParamG;
awilliam@13907 59 extern char boot_cmd_line[];
awilliam@13907 60 extern efi_system_table_t* efiSysTableP;
awilliam@13907 61 extern int bootverbose;
awilliam@13907 62
awilliam@13907 63 extern void ia64_probe_sapics(void);
awilliam@13907 64
awilliam@13907 65
awilliam@13907 66
awilliam@13907 67 /* Contains the needed stuff from efi. */
awilliam@13907 68 struct efi
awilliam@13907 69 {
awilliam@13907 70
awilliam@13907 71 efi_system_table_t* efiSysTableP;
awilliam@13907 72 efi_set_virtual_address_map_t setVirtAddrMapF;
awilliam@13907 73 efi_get_time_t getTimeF;
awilliam@13907 74 efi_reset_system_t resetSystemF;
awilliam@13907 75
awilliam@13907 76 };
awilliam@13907 77
awilliam@13907 78 struct machine_fw
awilliam@13907 79 {
awilliam@13907 80 struct efi efi;
awilliam@13907 81
awilliam@13907 82 uint64_t ia64_port_base; /* physical address */
awilliam@13907 83 uint64_t ia64_pal_base; /* virtual rr7 address */
awilliam@13907 84
awilliam@13907 85 sal_system_table_t* ia64_sal_tableP;
awilliam@13907 86 sal_entry_t* ia64_sal_entryP; /* SAL_PROC entrypoint */
awilliam@13907 87
awilliam@13907 88 uint64_t ia64_efi_acpi_table; /* physical address */
awilliam@13907 89 uint64_t ia64_efi_acpi20_table; /* physical address */
awilliam@13907 90
awilliam@13907 91 uint64_t mach_mem_start; /* phys start addr of machine memory */
awilliam@13907 92 uint64_t mach_mem_size; /* size of machine memory */
awilliam@13907 93
awilliam@13907 94 uint64_t kernstart; /* virt address of kern text start */
awilliam@13907 95 uint64_t kernend;
awilliam@13907 96 uint64_t kernpstart; /* phys address of kern text start */
awilliam@13907 97 uint64_t kernpend;
awilliam@13907 98 };
awilliam@13907 99
awilliam@13907 100 extern struct machine_fw machineFwG;
awilliam@13907 101
awilliam@13907 102 #define ia64_sal_entry machineFwG.ia64_sal_entryP
awilliam@13907 103
awilliam@13907 104 #define smp_processor_id() 0
awilliam@13907 105
awilliam@13907 106 static inline uint64_t
awilliam@13907 107 xchg8(uint64_t* ptr, uint64_t x) \
awilliam@13907 108 {
awilliam@13907 109 uint64_t oldVal;
awilliam@13907 110 asm volatile ("xchg8 %0=[%1],%2" : "=r" (oldVal)
awilliam@13907 111 : "r" (ptr), "r" (x) : "memory");
awilliam@13907 112 return oldVal;
awilliam@13907 113 }
awilliam@13907 114 #define xchg xchg8
awilliam@13907 115
awilliam@13907 116 // Counts the number of 1-bits in x.
awilliam@13907 117 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
awilliam@13907 118 # define get_popcnt(x) __builtin_popcountl(x)
awilliam@13907 119 #else
awilliam@13907 120 # define get_popcnt(x) \
awilliam@13907 121 ({ \
awilliam@13907 122 uint64_t num; \
awilliam@13907 123 asm ("popcnt %0=%1" : "=r" (num) : "r" (x)); \
awilliam@13907 124 num; \
awilliam@13907 125 })
awilliam@13907 126 #endif
awilliam@13907 127
awilliam@13907 128 /**
awilliam@13907 129 * __ffs - find first bit in word.
awilliam@13907 130 * @x: The word to search
awilliam@13907 131 *
awilliam@13907 132 * Undefined if no bit exists, so code should check against 0 first.
awilliam@13907 133 */
awilliam@13907 134 static inline unsigned long
awilliam@13907 135 __ffs (unsigned long x)
awilliam@13907 136 {
awilliam@13907 137 unsigned long result;
awilliam@13907 138
awilliam@13907 139 result = get_popcnt((x-1) & ~x);
awilliam@13907 140 return result;
awilliam@13907 141 }
awilliam@13907 142
awilliam@13907 143
awilliam@13907 144 static inline void
awilliam@13907 145 synch_clear_bit(int num, volatile void *addr)
awilliam@13907 146 {
awilliam@13907 147 clear_bit(num, addr);
awilliam@13907 148 }
awilliam@13907 149
awilliam@13907 150 static inline void
awilliam@13907 151 synch_set_bit(int num, volatile void *addr)
awilliam@13907 152 {
awilliam@13907 153 set_bit(num, addr);
awilliam@13907 154 }
awilliam@13907 155
awilliam@13907 156 static inline int
awilliam@13907 157 synch_test_bit(int nr, const volatile void *addr)
awilliam@13907 158 {
awilliam@13907 159 return test_bit(nr, addr);
awilliam@13907 160 }
awilliam@13907 161
awilliam@13907 162 static inline int
awilliam@13907 163 synch_test_and_set_bit(int num, volatile void * addr)
awilliam@13907 164 {
awilliam@13907 165 return test_and_set_bit(num, addr);
awilliam@13907 166 }
awilliam@13907 167
awilliam@13907 168
awilliam@13907 169 #define synch_cmpxchg(ptr, old, new) \
awilliam@13907 170 ((__typeof__(*(ptr)))__synch_cmpxchg((ptr),\
awilliam@13907 171 (unsigned long)(old), \
awilliam@13907 172 (unsigned long)(new), \
awilliam@13907 173 sizeof(*(ptr))))
awilliam@13907 174
awilliam@13907 175 static inline unsigned long
awilliam@13907 176 __synch_cmpxchg(volatile void *ptr, uint64_t old, uint64_t new, int size)
awilliam@13907 177 {
awilliam@13907 178 switch (size)
awilliam@13907 179 {
awilliam@13907 180 case 1:
awilliam@13907 181 return ia64_cmpxchg_acq_8(ptr, old, new);
awilliam@13907 182 case 2:
awilliam@13907 183 return ia64_cmpxchg_acq_16(ptr, old, new);
awilliam@13907 184 case 4:
awilliam@13907 185 return ia64_cmpxchg_acq_32(ptr, old, new);
awilliam@13907 186 case 8:
awilliam@13907 187 return ia64_cmpxchg_acq_64(ptr, old, new);
awilliam@13907 188 }
awilliam@13907 189 return ia64_cmpxchg_acq_64(ptr, old, new);
awilliam@13907 190 }
awilliam@13907 191
awilliam@13907 192 /*
awilliam@13907 193 * Force a proper event-channel callback from Xen after clearing the
awilliam@13907 194 * callback mask. We do this in a very simple manner, by making a call
awilliam@13907 195 * down into Xen. The pending flag will be checked by Xen on return.
awilliam@13907 196 */
awilliam@13907 197 static inline void
awilliam@13907 198 force_evtchn_callback(void)
awilliam@13907 199 {
awilliam@13907 200 (void)HYPERVISOR_xen_version(0, NULL);
awilliam@13907 201 }
awilliam@13907 202
awilliam@13907 203 extern shared_info_t *HYPERVISOR_shared_info;
awilliam@13907 204
awilliam@13907 205 static inline int
awilliam@13907 206 HYPERVISOR_shutdown(unsigned int reason)
awilliam@13907 207 {
awilliam@13907 208 struct sched_shutdown sched_shutdown = {
awilliam@13907 209 .reason = reason
awilliam@13907 210 };
awilliam@13907 211
awilliam@13907 212 int rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
awilliam@13907 213
awilliam@13907 214 if (rc == -ENOSYS)
awilliam@13907 215 rc = HYPERVISOR_sched_op_compat(SCHEDOP_shutdown, reason);
awilliam@13907 216
awilliam@13907 217 return rc;
awilliam@13907 218 }
awilliam@13907 219
awilliam@13907 220
awilliam@13907 221 /*
awilliam@13907 222 * This code is from the originally os.h and should be put in a
awilliam@13907 223 * common header file!
awilliam@13907 224 */
awilliam@13907 225
awilliam@13907 226 /*
awilliam@13907 227 * The use of 'barrier' in the following reflects their use as local-lock
awilliam@13907 228 * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following
awilliam@13907 229 * critical operations are executed. All critical operations must complete
awilliam@13907 230 * /before/ reentrancy is permitted (e.g., __sti()). Alpha architecture also
awilliam@13907 231 * includes these barriers, for example.
awilliam@13907 232 */
awilliam@13907 233
awilliam@13907 234 #define __cli() \
awilliam@13907 235 do { \
awilliam@13907 236 vcpu_info_t *_vcpu; \
awilliam@13907 237 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
awilliam@13907 238 _vcpu->evtchn_upcall_mask = SWAP(1); \
awilliam@13907 239 barrier(); \
awilliam@13907 240 } while (0)
awilliam@13907 241
awilliam@13907 242 #define __sti() \
awilliam@13907 243 do { \
awilliam@13907 244 vcpu_info_t *_vcpu; \
awilliam@13907 245 barrier(); \
awilliam@13907 246 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
awilliam@13907 247 _vcpu->evtchn_upcall_mask = 0; \
awilliam@13907 248 barrier(); /* unmask then check (avoid races) */ \
awilliam@13907 249 if (unlikely(SWAP(_vcpu->evtchn_upcall_pending))) \
awilliam@13907 250 force_evtchn_callback(); \
awilliam@13907 251 } while (0)
awilliam@13907 252
awilliam@13907 253 #define __save_flags(x) \
awilliam@13907 254 do { \
awilliam@13907 255 vcpu_info_t *_vcpu; \
awilliam@13907 256 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
awilliam@13907 257 (x) = SWAP(_vcpu->evtchn_upcall_mask); \
awilliam@13907 258 } while (0)
awilliam@13907 259
awilliam@13907 260 #define __restore_flags(x) \
awilliam@13907 261 do { \
awilliam@13907 262 vcpu_info_t *_vcpu; \
awilliam@13907 263 barrier(); \
awilliam@13907 264 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
awilliam@13907 265 if ((_vcpu->evtchn_upcall_mask = (x)) == 0) { \
awilliam@13907 266 barrier(); /* unmask then check (avoid races) */ \
awilliam@13907 267 if ( unlikely(SWAP(_vcpu->evtchn_upcall_pending)) ) \
awilliam@13907 268 force_evtchn_callback(); \
awilliam@13907 269 }\
awilliam@13907 270 } while (0)
awilliam@13907 271
awilliam@13907 272 #define safe_halt() ((void)0)
awilliam@13907 273
awilliam@13907 274 #define __save_and_cli(x) \
awilliam@13907 275 do { \
awilliam@13907 276 vcpu_info_t *_vcpu; \
awilliam@13907 277 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
awilliam@13907 278 (x) = SWAP(_vcpu->evtchn_upcall_mask); \
awilliam@13907 279 _vcpu->evtchn_upcall_mask = SWAP(1); \
awilliam@13907 280 barrier(); \
awilliam@13907 281 } while (0)
awilliam@13907 282
awilliam@13907 283 #define local_irq_save(x) __save_and_cli(x)
awilliam@13907 284 #define local_irq_restore(x) __restore_flags(x)
awilliam@13907 285 #define local_save_flags(x) __save_flags(x)
awilliam@13907 286 #define local_irq_disable() __cli()
awilliam@13907 287 #define local_irq_enable() __sti()
awilliam@13907 288
awilliam@13907 289 #define irqs_disabled() \
awilliam@13907 290 SWAP(HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].evtchn_upcall_mask)
awilliam@13907 291
awilliam@13907 292 /* This is a barrier for the compiler only, NOT the processor! */
awilliam@13907 293 #define barrier() __asm__ __volatile__("": : :"memory")
awilliam@13907 294
awilliam@13907 295 #define mb() ia64_mf()
awilliam@13907 296 #define rmb() mb()
awilliam@13907 297 #define wmb() mb()
awilliam@13907 298
awilliam@13907 299
awilliam@13907 300 #define BUG() \
awilliam@13907 301 { printk("mini-os BUG at %s:%d!\n", __FILE__, __LINE__); do_exit(); }
awilliam@13907 302
awilliam@13907 303 #define PRINT_BV(_fmt, _params...) \
awilliam@13907 304 if (bootverbose) \
awilliam@13907 305 printk(_fmt , ## _params)
awilliam@13907 306
awilliam@13907 307 #endif /* !defined(__ASSEMBLY__) */
awilliam@13907 308
awilliam@13907 309 #if defined(__ASSEMBLY__)
awilliam@13907 310
awilliam@13907 311 #define UL_CONST(x) x
awilliam@13907 312 #define UL_TYPE(x) x
awilliam@13907 313
awilliam@13907 314 #else /* defined(__ASSEMBLY__) */
awilliam@13907 315
awilliam@13907 316 #define UL_CONST(x) x##UL
awilliam@13907 317 #define UL_TYPE(x) ((uint64_t)x)
awilliam@13907 318
awilliam@13907 319 #endif /* defined(__ASSEMBLY__) */
awilliam@13907 320
awilliam@13907 321 #endif /* !defined(__OS_H__) */