sfi.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * sfi.c - x86 architecture SFI support.
  3. *
  4. * Copyright (c) 2009, Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. */
  20. #define KMSG_COMPONENT "SFI"
  21. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  22. #include <linux/bootmem.h>
  23. #include <linux/cpumask.h>
  24. #include <linux/module.h>
  25. #include <linux/acpi.h>
  26. #include <linux/init.h>
  27. #include <linux/efi.h>
  28. #include <linux/irq.h>
  29. #include <linux/sfi.h>
  30. #include <linux/io.h>
  31. #include <asm/io_apic.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/mpspec.h>
  34. #include <asm/setup.h>
  35. #include <asm/apic.h>
  36. #include <asm/e820.h>
  37. #ifdef CONFIG_X86_LOCAL_APIC
  38. static unsigned long sfi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
  39. void __init mp_sfi_register_lapic_address(unsigned long address)
  40. {
  41. mp_lapic_addr = address;
  42. set_fixmap_nocache(FIX_APIC_BASE, mp_lapic_addr);
  43. if (boot_cpu_physical_apicid == -1U)
  44. boot_cpu_physical_apicid = read_apic_id();
  45. pr_info("Boot CPU = %d\n", boot_cpu_physical_apicid);
  46. }
  47. /* All CPUs enumerated by SFI must be present and enabled */
  48. void __cpuinit mp_sfi_register_lapic(u8 id)
  49. {
  50. int boot_cpu = 0;
  51. if (MAX_APICS - id <= 0) {
  52. pr_warning("Processor #%d invalid (max %d)\n",
  53. id, MAX_APICS);
  54. return;
  55. }
  56. if (id == boot_cpu_physical_apicid)
  57. boot_cpu = 1;
  58. pr_info("registering lapic[%d]\n", id);
  59. generic_processor_info(id, GET_APIC_VERSION(apic_read(APIC_LVR)));
  60. }
  61. static int __init sfi_parse_cpus(struct sfi_table_header *table)
  62. {
  63. struct sfi_table_simple *sb;
  64. struct sfi_cpu_table_entry *pentry;
  65. int i;
  66. int cpu_num;
  67. sb = (struct sfi_table_simple *)table;
  68. cpu_num = SFI_GET_NUM_ENTRIES(sb, struct sfi_cpu_table_entry);
  69. pentry = (struct sfi_cpu_table_entry *)sb->pentry;
  70. for (i = 0; i < cpu_num; i++) {
  71. mp_sfi_register_lapic(pentry->apic_id);
  72. pentry++;
  73. }
  74. smp_found_config = 1;
  75. return 0;
  76. }
  77. #endif /* CONFIG_X86_LOCAL_APIC */
  78. #ifdef CONFIG_X86_IO_APIC
  79. static u32 gsi_base;
  80. static int __init sfi_parse_ioapic(struct sfi_table_header *table)
  81. {
  82. struct sfi_table_simple *sb;
  83. struct sfi_apic_table_entry *pentry;
  84. int i, num;
  85. sb = (struct sfi_table_simple *)table;
  86. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_apic_table_entry);
  87. pentry = (struct sfi_apic_table_entry *)sb->pentry;
  88. for (i = 0; i < num; i++) {
  89. mp_register_ioapic(i, pentry->phys_addr, gsi_base);
  90. gsi_base += io_apic_get_redir_entries(i);
  91. pentry++;
  92. }
  93. WARN(pic_mode, KERN_WARNING
  94. "SFI: pic_mod shouldn't be 1 when IOAPIC table is present\n");
  95. pic_mode = 0;
  96. return 0;
  97. }
  98. #endif /* CONFIG_X86_IO_APIC */
  99. /*
  100. * sfi_platform_init(): register lapics & io-apics
  101. */
  102. int __init sfi_platform_init(void)
  103. {
  104. #ifdef CONFIG_X86_LOCAL_APIC
  105. mp_sfi_register_lapic_address(sfi_lapic_addr);
  106. sfi_table_parse(SFI_SIG_CPUS, NULL, NULL, sfi_parse_cpus);
  107. #endif
  108. #ifdef CONFIG_X86_IO_APIC
  109. sfi_table_parse(SFI_SIG_APIC, NULL, NULL, sfi_parse_ioapic);
  110. #endif
  111. return 0;
  112. }