ia64/xen-unstable

view tools/firmware/hvmloader/util.h @ 18394:dade7f0bdc8d

hvm: Use main memory for video memory.

When creating an HVM domain, if e.g. another domain is created before
qemu allocates video memory, the extra 8MB memory ballooning is not
available any more, because it got consumed by the other domain.

This fixes it by taking video memory from the main memory:

- make hvmloader use e820_malloc to reserve some of the main memory
and notify ioemu of its address through the Xen platform PCI card.
- add XENMAPSPACE_mfn to the xen_add_to_physmap memory op, to allow
ioemu to move the MFNs between the original position and the PCI
mapping, when LFB acceleration is disabled/enabled
- add a remove_from_physmap memory op, to allow ioemu to unmap it
completely for the case of old guests with acceleration disabled.
- add xc_domain_memory_translate_gpfn_list to libxc to allow ioemu to
get the MFNs of the video memory.
- have xend save the PCI memory space instead of ioemu: if a memory
page is there, the guest can access it like usual memory, so xend
can safely be responsible to save it. The extra benefit is that
live migration will apply the logdirty optimization there too.
- handle old saved images, populating the video memory from ioemu if
really needed.

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Aug 27 14:53:39 2008 +0100 (2008-08-27)
parents 2ec019301ad8
children f20e5039b168
line source
1 #ifndef __HVMLOADER_UTIL_H__
2 #define __HVMLOADER_UTIL_H__
4 #include <stdarg.h>
5 #include <stdint.h>
7 #undef offsetof
8 #define offsetof(t, m) ((unsigned long)&((t *)0)->m)
10 #undef NULL
11 #define NULL ((void*)0)
13 void __assert_failed(char *assertion, char *file, int line)
14 __attribute__((noreturn));
15 #define ASSERT(p) \
16 do { if (!(p)) __assert_failed(#p, __FILE__, __LINE__); } while (0)
17 void __bug(char *file, int line) __attribute__((noreturn));
18 #define BUG() __bug(__FILE__, __LINE__)
19 #define BUG_ON(p) do { if (p) BUG(); } while (0)
20 #define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
22 /* MSR access */
23 void wrmsr(uint32_t idx, uint64_t v);
24 uint64_t rdmsr(uint32_t idx);
26 /* I/O output */
27 void outb(uint16_t addr, uint8_t val);
28 void outw(uint16_t addr, uint16_t val);
29 void outl(uint16_t addr, uint32_t val);
31 /* I/O input */
32 uint8_t inb(uint16_t addr);
33 uint16_t inw(uint16_t addr);
34 uint32_t inl(uint16_t addr);
36 /* CMOS access */
37 uint8_t cmos_inb(uint8_t idx);
38 void cmos_outb(uint8_t idx, uint8_t val);
40 /* APIC access */
41 uint32_t ioapic_read(uint32_t reg);
42 void ioapic_write(uint32_t reg, uint32_t val);
43 uint32_t lapic_read(uint32_t reg);
44 void lapic_write(uint32_t reg, uint32_t val);
46 /* PCI access */
47 uint32_t pci_read(uint32_t devfn, uint32_t reg, uint32_t len);
48 #define pci_readb(devfn, reg) ((uint8_t) pci_read(devfn, reg, 1))
49 #define pci_readw(devfn, reg) ((uint16_t)pci_read(devfn, reg, 2))
50 #define pci_readl(devfn, reg) ((uint32_t)pci_read(devfn, reg, 4))
51 void pci_write(uint32_t devfn, uint32_t reg, uint32_t len, uint32_t val);
52 #define pci_writeb(devfn, reg, val) (pci_write(devfn, reg, 1, (uint8_t) val))
53 #define pci_writew(devfn, reg, val) (pci_write(devfn, reg, 2, (uint16_t)val))
54 #define pci_writel(devfn, reg, val) (pci_write(devfn, reg, 4, (uint32_t)val))
56 /* Get CPU speed in MHz. */
57 uint16_t get_cpu_mhz(void);
59 /* Do cpuid instruction, with operation 'idx' */
60 void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx,
61 uint32_t *ecx, uint32_t *edx);
63 /* Read the TSC register. */
64 static inline uint64_t rdtsc(void)
65 {
66 uint64_t tsc;
67 asm volatile ( "rdtsc" : "=A" (tsc) );
68 return tsc;
69 }
71 /* Relax the CPU and let the compiler know that time passes. */
72 static inline void cpu_relax(void)
73 {
74 asm volatile ( "rep ; nop" : : : "memory" );
75 }
77 /* Memory barriers. */
78 #define barrier() asm volatile ( "" : : : "memory" )
79 #define rmb() barrier()
80 #define wmb() barrier()
81 #define mb() asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" )
83 /*
84 * Divide a 64-bit dividend by a 32-bit divisor.
85 * (1) Overwrites the 64-bit dividend _in_place_ with the quotient
86 * (2) Returns the 32-bit remainder
87 */
88 #define do_div(n, base) ({ \
89 unsigned long __upper, __low, __high, __mod, __base; \
90 __base = (base); \
91 asm ( "" : "=a" (__low), "=d" (__high) : "A" (n) ); \
92 __upper = __high; \
93 if ( __high ) \
94 { \
95 __upper = __high % (__base); \
96 __high = __high / (__base); \
97 } \
98 asm ( "divl %2" \
99 : "=a" (__low), "=d" (__mod) \
100 : "rm" (__base), "0" (__low), "1" (__upper) ); \
101 asm ( "" : "=A" (n) : "a" (__low), "d" (__high) ); \
102 __mod; \
103 })
105 /* HVM-builder info. */
106 int get_vcpu_nr(void);
107 int get_acpi_enabled(void);
108 int get_apic_mode(void);
110 /* String and memory functions */
111 int strcmp(const char *cs, const char *ct);
112 int strncmp(const char *s1, const char *s2, uint32_t n);
113 char *strcpy(char *dest, const char *src);
114 char *strncpy(char *dest, const char *src, unsigned n);
115 unsigned strlen(const char *s);
116 int memcmp(const void *s1, const void *s2, unsigned n);
117 void *memcpy(void *dest, const void *src, unsigned n);
118 void *memmove(void *dest, const void *src, unsigned n);
119 void *memset(void *s, int c, unsigned n);
120 char *itoa(char *a, unsigned int i);
122 /* convert a byte to two lowercase hex digits, with no terminating NUL
123 character. digits[] must have at least two elements. */
124 void byte_to_hex(char *digits, uint8_t byte);
126 /* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
127 string. Pre-condition: sizeof(dest) >= 37 */
128 void uuid_to_string(char *dest, uint8_t *uuid);
130 /* Debug output */
131 int printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
132 int vprintf(const char *fmt, va_list ap);
134 /* Reserve a RAM region in the e820 table. */
135 uint32_t e820_malloc(uint32_t size, uint32_t align);
137 /* Prepare the 32bit BIOS */
138 void highbios_setup(void);
140 /* Miscellaneous. */
141 void cacheattr_init(void);
142 void create_mp_tables(void);
143 int hvm_write_smbios_tables(void);
144 void smp_initialise(void);
146 #ifndef NDEBUG
147 void perform_tests(void);
148 #else
149 #define perform_tests() ((void)0)
150 #endif
152 #define isdigit(c) ((c) >= '0' && (c) <= '9')
154 extern char _start[], _end[];
156 #endif /* __HVMLOADER_UTIL_H__ */