fwcfg.c 865 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "fwcfg.h"
  2. #include "smp.h"
  3. static struct spinlock lock;
  4. static uint64_t fwcfg_get_u(uint16_t index, int bytes)
  5. {
  6. uint64_t r = 0;
  7. uint8_t b;
  8. int i;
  9. spin_lock(&lock);
  10. asm volatile ("out %0, %1" : : "a"(index), "d"((uint16_t)BIOS_CFG_IOPORT));
  11. for (i = 0; i < bytes; ++i) {
  12. asm volatile ("in %1, %0" : "=a"(b) : "d"((uint16_t)(BIOS_CFG_IOPORT + 1)));
  13. r |= (uint64_t)b << (i * 8);
  14. }
  15. spin_unlock(&lock);
  16. return r;
  17. }
  18. uint8_t fwcfg_get_u8(unsigned index)
  19. {
  20. return fwcfg_get_u(index, 1);
  21. }
  22. uint16_t fwcfg_get_u16(unsigned index)
  23. {
  24. return fwcfg_get_u(index, 2);
  25. }
  26. uint32_t fwcfg_get_u32(unsigned index)
  27. {
  28. return fwcfg_get_u(index, 4);
  29. }
  30. uint64_t fwcfg_get_u64(unsigned index)
  31. {
  32. return fwcfg_get_u(index, 8);
  33. }
  34. unsigned fwcfg_get_nb_cpus(void)
  35. {
  36. return fwcfg_get_u16(FW_CFG_NB_CPUS);
  37. }