Fix apic build with kvm disabled
[qemu/qemu-dev-zwu.git] / kvm / test / lib / x86 / fwcfg.c
blobe2cdd1577e714a9947f79ac8c1e0d9eb91f936d2
1 #include "fwcfg.h"
2 #include "smp.h"
4 static struct spinlock lock;
6 uint64_t fwcfg_get_u(uint16_t index, int bytes)
8 uint64_t r = 0;
9 uint8_t b;
10 int i;
12 spin_lock(&lock);
13 asm volatile ("out %0, %1" : : "a"(index), "d"((uint16_t)BIOS_CFG_IOPORT));
14 for (i = 0; i < bytes; ++i) {
15 asm volatile ("in %1, %0" : "=a"(b) : "d"((uint16_t)(BIOS_CFG_IOPORT + 1)));
16 r |= (uint64_t)b << (i * 8);
18 spin_unlock(&lock);
19 return r;
22 uint8_t fwcfg_get_u8(unsigned index)
24 return fwcfg_get_u(index, 1);
27 uint16_t fwcfg_get_u16(unsigned index)
29 return fwcfg_get_u(index, 2);
32 uint32_t fwcfg_get_u32(unsigned index)
34 return fwcfg_get_u(index, 4);
37 uint64_t fwcfg_get_u64(unsigned index)
39 return fwcfg_get_u(index, 8);
42 unsigned fwcfg_get_nb_cpus(void)
44 return fwcfg_get_u16(FW_CFG_NB_CPUS);