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