lapic.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * From Coreboot file of same name
  3. *
  4. * Copyright (C) 2014 Google, Inc
  5. *
  6. * SPDX-License-Identifier: GPL-2.0
  7. */
  8. #ifndef _ARCH_ASM_LAPIC_H
  9. #define _ARCH_ASM_LAPIC_H
  10. #include <asm/io.h>
  11. #include <asm/lapic_def.h>
  12. #include <asm/msr.h>
  13. #include <asm/processor.h>
  14. static inline __attribute__((always_inline))
  15. unsigned long lapic_read(unsigned long reg)
  16. {
  17. return readl(LAPIC_DEFAULT_BASE + reg);
  18. }
  19. static inline __attribute__((always_inline))
  20. void lapic_write(unsigned long reg, unsigned long val)
  21. {
  22. writel(val, LAPIC_DEFAULT_BASE + reg);
  23. }
  24. static inline __attribute__((always_inline)) void lapic_wait_icr_idle(void)
  25. {
  26. do { } while (lapic_read(LAPIC_ICR) & LAPIC_ICR_BUSY);
  27. }
  28. static inline void enable_lapic(void)
  29. {
  30. msr_t msr;
  31. msr = msr_read(LAPIC_BASE_MSR);
  32. msr.hi &= 0xffffff00;
  33. msr.lo &= 0x000007ff;
  34. msr.lo |= LAPIC_DEFAULT_BASE | (1 << 11);
  35. msr_write(LAPIC_BASE_MSR, msr);
  36. }
  37. static inline void disable_lapic(void)
  38. {
  39. msr_t msr;
  40. msr = msr_read(LAPIC_BASE_MSR);
  41. msr.lo &= ~(1 << 11);
  42. msr_write(LAPIC_BASE_MSR, msr);
  43. }
  44. static inline __attribute__((always_inline)) unsigned long lapicid(void)
  45. {
  46. return lapic_read(LAPIC_ID) >> 24;
  47. }
  48. #endif