File size: 865 Bytes
8df6da4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "fwcfg.h"
#include "smp.h"

static struct spinlock lock;

static uint64_t fwcfg_get_u(uint16_t index, int bytes)
{
    uint64_t r = 0;
    uint8_t b;
    int i;

    spin_lock(&lock);
    asm volatile ("out %0, %1" : : "a"(index), "d"((uint16_t)BIOS_CFG_IOPORT));
    for (i = 0; i < bytes; ++i) {
        asm volatile ("in %1, %0" : "=a"(b) : "d"((uint16_t)(BIOS_CFG_IOPORT + 1)));
        r |= (uint64_t)b << (i * 8);
    }
    spin_unlock(&lock);
    return r;
}

uint8_t fwcfg_get_u8(unsigned index)
{
    return fwcfg_get_u(index, 1);
}

uint16_t fwcfg_get_u16(unsigned index)
{
    return fwcfg_get_u(index, 2);
}

uint32_t fwcfg_get_u32(unsigned index)
{
    return fwcfg_get_u(index, 4);
}

uint64_t fwcfg_get_u64(unsigned index)
{
    return fwcfg_get_u(index, 8);
}

unsigned fwcfg_get_nb_cpus(void)
{
    return fwcfg_get_u16(FW_CFG_NB_CPUS);
}