ia64/xen-unstable

view extras/mini-os/include/ia64/os.h @ 19848:5839491bbf20

[IA64] replace MAX_VCPUS with d->max_vcpus where necessary.

don't use MAX_VCPUS, and use vcpu::max_vcpus.
The changeset of 2f9e1348aa98 introduced max_vcpus to allow more vcpus
per guest. This patch is ia64 counter part.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 11:26:05 2009 +0900 (2009-06-29)
parents 7ef733b961c8
children
line source
1 /*
2 * Copyright (C) 2007 - Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
3 *
4 ****************************************************************************
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
25 #if !defined(__OS_H__)
26 #define __OS_H__
28 #if !defined(__ASSEMBLY__)
30 #include <mini-os/types.h>
31 #include "ia64_cpu.h"
32 #include "atomic.h"
33 #include "efi.h"
34 #include "sal.h"
35 #include "pal.h"
36 #include <mini-os/hypervisor.h>
37 #include <mini-os/kernel.h>
40 typedef uint64_t paddr_t; /* Physical address. */
41 #ifndef HAVE_LIBC
42 typedef uint64_t caddr_t; /* rr7/kernel memory address. */
43 #endif
45 #include "page.h"
46 #include "mm.h"
49 void arch_init(start_info_t *si); /* in common.c */
50 void arch_print_info(void); /* in common.c */
51 void arch_fini(void);
54 /* Size of xen_ia64_boot_param.command_line */
55 #define COMMAND_LINE_SIZE 512
57 extern struct xen_ia64_boot_param* ia64_boot_paramP;
58 extern struct xen_ia64_boot_param ia64BootParamG;
59 extern char boot_cmd_line[];
60 extern efi_system_table_t* efiSysTableP;
61 extern int bootverbose;
63 extern void ia64_probe_sapics(void);
67 /* Contains the needed stuff from efi. */
68 struct efi
69 {
71 efi_system_table_t* efiSysTableP;
72 efi_set_virtual_address_map_t setVirtAddrMapF;
73 efi_get_time_t getTimeF;
74 efi_reset_system_t resetSystemF;
76 };
78 struct machine_fw
79 {
80 struct efi efi;
82 uint64_t ia64_port_base; /* physical address */
83 uint64_t ia64_pal_base; /* virtual rr7 address */
85 sal_system_table_t* ia64_sal_tableP;
86 sal_entry_t* ia64_sal_entryP; /* SAL_PROC entrypoint */
88 uint64_t ia64_efi_acpi_table; /* physical address */
89 uint64_t ia64_efi_acpi20_table; /* physical address */
91 uint64_t mach_mem_start; /* phys start addr of machine memory */
92 uint64_t mach_mem_size; /* size of machine memory */
94 uint64_t kernstart; /* virt address of kern text start */
95 uint64_t kernend;
96 uint64_t kernpstart; /* phys address of kern text start */
97 uint64_t kernpend;
98 };
100 extern struct machine_fw machineFwG;
102 #define ia64_sal_entry machineFwG.ia64_sal_entryP
104 #define smp_processor_id() 0
106 static inline uint64_t
107 xchg8(uint64_t* ptr, uint64_t x) \
108 {
109 uint64_t oldVal;
110 asm volatile ("xchg8 %0=[%1],%2" : "=r" (oldVal)
111 : "r" (ptr), "r" (x) : "memory");
112 return oldVal;
113 }
114 #define xchg xchg8
116 // Counts the number of 1-bits in x.
117 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
118 # define get_popcnt(x) __builtin_popcountl(x)
119 #else
120 # define get_popcnt(x) \
121 ({ \
122 uint64_t num; \
123 asm ("popcnt %0=%1" : "=r" (num) : "r" (x)); \
124 num; \
125 })
126 #endif
128 /**
129 * __ffs - find first bit in word.
130 * @x: The word to search
131 *
132 * Undefined if no bit exists, so code should check against 0 first.
133 */
134 static inline unsigned long
135 __ffs (unsigned long x)
136 {
137 unsigned long result;
139 result = get_popcnt((x-1) & ~x);
140 return result;
141 }
144 static inline void
145 synch_clear_bit(int num, volatile void *addr)
146 {
147 clear_bit(num, addr);
148 }
150 static inline void
151 synch_set_bit(int num, volatile void *addr)
152 {
153 set_bit(num, addr);
154 }
156 static inline int
157 synch_test_bit(int nr, const volatile void *addr)
158 {
159 return test_bit(nr, addr);
160 }
162 static inline int
163 synch_test_and_set_bit(int num, volatile void * addr)
164 {
165 return test_and_set_bit(num, addr);
166 }
169 #define synch_cmpxchg(ptr, old, new) \
170 ((__typeof__(*(ptr)))__synch_cmpxchg((ptr),\
171 (unsigned long)(old), \
172 (unsigned long)(new), \
173 sizeof(*(ptr))))
175 static inline unsigned long
176 __synch_cmpxchg(volatile void *ptr, uint64_t old, uint64_t new, int size)
177 {
178 switch (size)
179 {
180 case 1:
181 return ia64_cmpxchg_acq_8(ptr, old, new);
182 case 2:
183 return ia64_cmpxchg_acq_16(ptr, old, new);
184 case 4:
185 return ia64_cmpxchg_acq_32(ptr, old, new);
186 case 8:
187 return ia64_cmpxchg_acq_64(ptr, old, new);
188 }
189 return ia64_cmpxchg_acq_64(ptr, old, new);
190 }
192 extern shared_info_t *HYPERVISOR_shared_info;
195 /*
196 * This code is from the originally os.h and should be put in a
197 * common header file!
198 */
200 /*
201 * The use of 'barrier' in the following reflects their use as local-lock
202 * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following
203 * critical operations are executed. All critical operations must complete
204 * /before/ reentrancy is permitted (e.g., __sti()). Alpha architecture also
205 * includes these barriers, for example.
206 */
208 #define __cli() \
209 do { \
210 vcpu_info_t *_vcpu; \
211 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
212 _vcpu->evtchn_upcall_mask = 1; \
213 barrier(); \
214 } while (0)
216 #define __sti() \
217 do { \
218 vcpu_info_t *_vcpu; \
219 barrier(); \
220 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
221 _vcpu->evtchn_upcall_mask = 0; \
222 barrier(); /* unmask then check (avoid races) */ \
223 if (unlikely(_vcpu->evtchn_upcall_pending)) \
224 force_evtchn_callback(); \
225 } while (0)
227 #define __save_flags(x) \
228 do { \
229 vcpu_info_t *_vcpu; \
230 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
231 (x) = _vcpu->evtchn_upcall_mask; \
232 } while (0)
234 #define __restore_flags(x) \
235 do { \
236 vcpu_info_t *_vcpu; \
237 barrier(); \
238 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
239 if ((_vcpu->evtchn_upcall_mask = (x)) == 0) { \
240 barrier(); /* unmask then check (avoid races) */ \
241 if ( unlikely(_vcpu->evtchn_upcall_pending) ) \
242 force_evtchn_callback(); \
243 }\
244 } while (0)
246 #define safe_halt() ((void)0)
248 #define __save_and_cli(x) \
249 do { \
250 vcpu_info_t *_vcpu; \
251 _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
252 (x) = _vcpu->evtchn_upcall_mask; \
253 _vcpu->evtchn_upcall_mask = 1; \
254 barrier(); \
255 } while (0)
257 #define local_irq_save(x) __save_and_cli(x)
258 #define local_irq_restore(x) __restore_flags(x)
259 #define local_save_flags(x) __save_flags(x)
260 #define local_irq_disable() __cli()
261 #define local_irq_enable() __sti()
263 #define irqs_disabled() \
264 (HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].evtchn_upcall_mask)
266 /* This is a barrier for the compiler only, NOT the processor! */
267 #define barrier() __asm__ __volatile__("": : :"memory")
269 #define mb() ia64_mf()
270 #define rmb() mb()
271 #define wmb() mb()
274 #define BUG() \
275 { printk("mini-os BUG at %s:%d!\n", __FILE__, __LINE__); do_exit(); }
277 #define PRINT_BV(_fmt, _params...) \
278 if (bootverbose) \
279 printk(_fmt , ## _params)
281 #endif /* !defined(__ASSEMBLY__) */
283 #if defined(__ASSEMBLY__)
285 #define UL_CONST(x) x
286 #define UL_TYPE(x) x
288 #else /* defined(__ASSEMBLY__) */
290 #define UL_CONST(x) x##UL
291 #define UL_TYPE(x) ((uint64_t)x)
293 #endif /* defined(__ASSEMBLY__) */
295 #endif /* !defined(__OS_H__) */