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