sfi.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /* sfi.h Simple Firmware Interface */
  2. /*
  3. This file is provided under a dual BSD/GPLv2 license. When using or
  4. redistributing this file, you may do so under either license.
  5. GPL LICENSE SUMMARY
  6. Copyright(c) 2009 Intel Corporation. All rights reserved.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of version 2 of the GNU General Public License as
  9. published by the Free Software Foundation.
  10. This program is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. The full GNU General Public License is included in this distribution
  18. in the file called LICENSE.GPL.
  19. BSD LICENSE
  20. Copyright(c) 2009 Intel Corporation. All rights reserved.
  21. Redistribution and use in source and binary forms, with or without
  22. modification, are permitted provided that the following conditions
  23. are met:
  24. * Redistributions of source code must retain the above copyright
  25. notice, this list of conditions and the following disclaimer.
  26. * Redistributions in binary form must reproduce the above copyright
  27. notice, this list of conditions and the following disclaimer in
  28. the documentation and/or other materials provided with the
  29. distribution.
  30. * Neither the name of Intel Corporation nor the names of its
  31. contributors may be used to endorse or promote products derived
  32. from this software without specific prior written permission.
  33. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  34. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  35. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  36. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  37. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  39. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  40. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  41. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  43. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. */
  45. #ifndef _LINUX_SFI_H
  46. #define _LINUX_SFI_H
  47. #include <linux/init.h>
  48. #include <linux/types.h>
  49. /* Table signatures reserved by the SFI specification */
  50. #define SFI_SIG_SYST "SYST"
  51. #define SFI_SIG_FREQ "FREQ"
  52. #define SFI_SIG_IDLE "IDLE"
  53. #define SFI_SIG_CPUS "CPUS"
  54. #define SFI_SIG_MTMR "MTMR"
  55. #define SFI_SIG_MRTC "MRTC"
  56. #define SFI_SIG_MMAP "MMAP"
  57. #define SFI_SIG_APIC "APIC"
  58. #define SFI_SIG_XSDT "XSDT"
  59. #define SFI_SIG_WAKE "WAKE"
  60. #define SFI_SIG_DEVS "DEVS"
  61. #define SFI_SIG_GPIO "GPIO"
  62. #define SFI_SIGNATURE_SIZE 4
  63. #define SFI_OEM_ID_SIZE 6
  64. #define SFI_OEM_TABLE_ID_SIZE 8
  65. #define SFI_NAME_LEN 16
  66. #define SFI_SYST_SEARCH_BEGIN 0x000E0000
  67. #define SFI_SYST_SEARCH_END 0x000FFFFF
  68. #define SFI_GET_NUM_ENTRIES(ptable, entry_type) \
  69. ((ptable->header.len - sizeof(struct sfi_table_header)) / \
  70. (sizeof(entry_type)))
  71. /*
  72. * Table structures must be byte-packed to match the SFI specification,
  73. * as they are provided by the BIOS.
  74. */
  75. struct sfi_table_header {
  76. char sig[SFI_SIGNATURE_SIZE];
  77. u32 len;
  78. u8 rev;
  79. u8 csum;
  80. char oem_id[SFI_OEM_ID_SIZE];
  81. char oem_table_id[SFI_OEM_TABLE_ID_SIZE];
  82. } __packed;
  83. struct sfi_table_simple {
  84. struct sfi_table_header header;
  85. u64 pentry[1];
  86. } __packed;
  87. /* Comply with UEFI spec 2.1 */
  88. struct sfi_mem_entry {
  89. u32 type;
  90. u64 phys_start;
  91. u64 virt_start;
  92. u64 pages;
  93. u64 attrib;
  94. } __packed;
  95. struct sfi_cpu_table_entry {
  96. u32 apic_id;
  97. } __packed;
  98. struct sfi_cstate_table_entry {
  99. u32 hint; /* MWAIT hint */
  100. u32 latency; /* latency in ms */
  101. } __packed;
  102. struct sfi_apic_table_entry {
  103. u64 phys_addr; /* phy base addr for APIC reg */
  104. } __packed;
  105. struct sfi_freq_table_entry {
  106. u32 freq_mhz; /* in MHZ */
  107. u32 latency; /* transition latency in ms */
  108. u32 ctrl_val; /* value to write to PERF_CTL */
  109. } __packed;
  110. struct sfi_wake_table_entry {
  111. u64 phys_addr; /* pointer to where the wake vector locates */
  112. } __packed;
  113. struct sfi_timer_table_entry {
  114. u64 phys_addr; /* phy base addr for the timer */
  115. u32 freq_hz; /* in HZ */
  116. u32 irq;
  117. } __packed;
  118. struct sfi_rtc_table_entry {
  119. u64 phys_addr; /* phy base addr for the RTC */
  120. u32 irq;
  121. } __packed;
  122. struct sfi_device_table_entry {
  123. u8 type; /* bus type, I2C, SPI or ...*/
  124. #define SFI_DEV_TYPE_SPI 0
  125. #define SFI_DEV_TYPE_I2C 1
  126. #define SFI_DEV_TYPE_UART 2
  127. #define SFI_DEV_TYPE_HSI 3
  128. #define SFI_DEV_TYPE_IPC 4
  129. u8 host_num; /* attached to host 0, 1...*/
  130. u16 addr;
  131. u8 irq;
  132. u32 max_freq;
  133. char name[SFI_NAME_LEN];
  134. } __packed;
  135. struct sfi_gpio_table_entry {
  136. char controller_name[SFI_NAME_LEN];
  137. u16 pin_no;
  138. char pin_name[SFI_NAME_LEN];
  139. } __packed;
  140. typedef int (*sfi_table_handler) (struct sfi_table_header *table);
  141. #ifdef CONFIG_SFI
  142. extern void __init sfi_init(void);
  143. extern int __init sfi_platform_init(void);
  144. extern void __init sfi_init_late(void);
  145. extern int sfi_table_parse(char *signature, char *oem_id, char *oem_table_id,
  146. sfi_table_handler handler);
  147. extern int sfi_disabled;
  148. static inline void disable_sfi(void)
  149. {
  150. sfi_disabled = 1;
  151. }
  152. #else /* !CONFIG_SFI */
  153. static inline void sfi_init(void)
  154. {
  155. }
  156. static inline void sfi_init_late(void)
  157. {
  158. }
  159. #define sfi_disabled 0
  160. static inline int sfi_table_parse(char *signature, char *oem_id,
  161. char *oem_table_id,
  162. sfi_table_handler handler)
  163. {
  164. return -1;
  165. }
  166. #endif /* !CONFIG_SFI */
  167. #endif /*_LINUX_SFI_H*/