xref: /rk3399_rockchip-uboot/arch/x86/include/asm/sfi.h (revision e71de54a4943ac481e8bcdb0a132c52ab90f23fe)
16388e357SSimon Glass /*
26388e357SSimon Glass  * Copyright(c) 2009 Intel Corporation. All rights reserved.
36388e357SSimon Glass  *
46388e357SSimon Glass  * SPDX-License-Identifier:	GPL-2.0+	BSD-3-Clause
56388e357SSimon Glass  */
66388e357SSimon Glass 
76388e357SSimon Glass #ifndef _LINUX_SFI_H
86388e357SSimon Glass #define _LINUX_SFI_H
96388e357SSimon Glass 
106388e357SSimon Glass #include <errno.h>
116388e357SSimon Glass #include <linux/types.h>
126388e357SSimon Glass 
136388e357SSimon Glass /* Table signatures reserved by the SFI specification */
146388e357SSimon Glass #define SFI_SIG_SYST		"SYST"
156388e357SSimon Glass #define SFI_SIG_FREQ		"FREQ"
166388e357SSimon Glass #define SFI_SIG_CPUS		"CPUS"
176388e357SSimon Glass #define SFI_SIG_MTMR		"MTMR"
186388e357SSimon Glass #define SFI_SIG_MRTC		"MRTC"
196388e357SSimon Glass #define SFI_SIG_MMAP		"MMAP"
206388e357SSimon Glass #define SFI_SIG_APIC		"APIC"
216388e357SSimon Glass #define SFI_SIG_XSDT		"XSDT"
226388e357SSimon Glass #define SFI_SIG_WAKE		"WAKE"
236388e357SSimon Glass #define SFI_SIG_DEVS		"DEVS"
246388e357SSimon Glass #define SFI_SIG_GPIO		"GPIO"
256388e357SSimon Glass 
266388e357SSimon Glass #define SFI_SIGNATURE_SIZE	4
276388e357SSimon Glass #define SFI_OEM_ID_SIZE		6
286388e357SSimon Glass #define SFI_OEM_TABLE_ID_SIZE	8
296388e357SSimon Glass 
306388e357SSimon Glass #define SFI_NAME_LEN		16
316388e357SSimon Glass #define SFI_TABLE_MAX_ENTRIES	16
326388e357SSimon Glass 
336388e357SSimon Glass #define SFI_GET_NUM_ENTRIES(ptable, entry_type) \
346388e357SSimon Glass 	((ptable->header.len - sizeof(struct sfi_table_header)) / \
356388e357SSimon Glass 	(sizeof(entry_type)))
366388e357SSimon Glass /*
376388e357SSimon Glass  * Table structures must be byte-packed to match the SFI specification,
386388e357SSimon Glass  * as they are provided by the BIOS.
396388e357SSimon Glass  */
406388e357SSimon Glass struct __packed sfi_table_header {
416388e357SSimon Glass 	char	sig[SFI_SIGNATURE_SIZE];
426388e357SSimon Glass 	u32	len;
436388e357SSimon Glass 	u8	rev;
446388e357SSimon Glass 	u8	csum;
456388e357SSimon Glass 	char	oem_id[SFI_OEM_ID_SIZE];
466388e357SSimon Glass 	char	oem_table_id[SFI_OEM_TABLE_ID_SIZE];
476388e357SSimon Glass };
486388e357SSimon Glass 
496388e357SSimon Glass struct __packed sfi_table_simple {
506388e357SSimon Glass 	struct sfi_table_header		header;
516388e357SSimon Glass 	u64				pentry[1];
526388e357SSimon Glass };
536388e357SSimon Glass 
546388e357SSimon Glass /* Comply with UEFI spec 2.1 */
556388e357SSimon Glass struct __packed sfi_mem_entry {
566388e357SSimon Glass 	u32	type;
576388e357SSimon Glass 	u64	phys_start;
586388e357SSimon Glass 	u64	virt_start;
596388e357SSimon Glass 	u64	pages;
606388e357SSimon Glass 	u64	attrib;
616388e357SSimon Glass };
626388e357SSimon Glass 
63*e71de54aSFelipe Balbi /* Memory type definitions */
64*e71de54aSFelipe Balbi enum sfi_mem_type {
65*e71de54aSFelipe Balbi 	SFI_MEM_RESERVED,
66*e71de54aSFelipe Balbi 	SFI_LOADER_CODE,
67*e71de54aSFelipe Balbi 	SFI_LOADER_DATA,
68*e71de54aSFelipe Balbi 	SFI_BOOT_SERVICE_CODE,
69*e71de54aSFelipe Balbi 	SFI_BOOT_SERVICE_DATA,
70*e71de54aSFelipe Balbi 	SFI_RUNTIME_SERVICE_CODE,
71*e71de54aSFelipe Balbi 	SFI_RUNTIME_SERVICE_DATA,
72*e71de54aSFelipe Balbi 	SFI_MEM_CONV,
73*e71de54aSFelipe Balbi 	SFI_MEM_UNUSABLE,
74*e71de54aSFelipe Balbi 	SFI_ACPI_RECLAIM,
75*e71de54aSFelipe Balbi 	SFI_ACPI_NVS,
76*e71de54aSFelipe Balbi 	SFI_MEM_MMIO,
77*e71de54aSFelipe Balbi 	SFI_MEM_IOPORT,
78*e71de54aSFelipe Balbi 	SFI_PAL_CODE,
79*e71de54aSFelipe Balbi 	SFI_MEM_TYPEMAX,
80*e71de54aSFelipe Balbi };
81*e71de54aSFelipe Balbi 
826388e357SSimon Glass struct __packed sfi_cpu_table_entry {
836388e357SSimon Glass 	u32	apic_id;
846388e357SSimon Glass };
856388e357SSimon Glass 
866388e357SSimon Glass struct __packed sfi_cstate_table_entry {
876388e357SSimon Glass 	u32	hint;		/* MWAIT hint */
886388e357SSimon Glass 	u32	latency;	/* latency in ms */
896388e357SSimon Glass };
906388e357SSimon Glass 
916388e357SSimon Glass struct __packed sfi_apic_table_entry {
926388e357SSimon Glass 	u64	phys_addr;	/* phy base addr for APIC reg */
936388e357SSimon Glass };
946388e357SSimon Glass 
956388e357SSimon Glass struct __packed sfi_freq_table_entry {
966388e357SSimon Glass 	u32	freq_mhz;	/* in MHZ */
976388e357SSimon Glass 	u32	latency;	/* transition latency in ms */
986388e357SSimon Glass 	u32	ctrl_val;	/* value to write to PERF_CTL */
996388e357SSimon Glass };
1006388e357SSimon Glass 
1016388e357SSimon Glass struct __packed sfi_wake_table_entry {
1026388e357SSimon Glass 	u64	phys_addr;	/* pointer to where the wake vector locates */
1036388e357SSimon Glass };
1046388e357SSimon Glass 
1056388e357SSimon Glass struct __packed sfi_timer_table_entry {
1066388e357SSimon Glass 	u64	phys_addr;	/* phy base addr for the timer */
1076388e357SSimon Glass 	u32	freq_hz;	/* in HZ */
1086388e357SSimon Glass 	u32	irq;
1096388e357SSimon Glass };
1106388e357SSimon Glass 
1116388e357SSimon Glass struct __packed sfi_rtc_table_entry {
1126388e357SSimon Glass 	u64	phys_addr;	/* phy base addr for the RTC */
1136388e357SSimon Glass 	u32	irq;
1146388e357SSimon Glass };
1156388e357SSimon Glass 
1166388e357SSimon Glass struct __packed sfi_device_table_entry {
1176388e357SSimon Glass 	u8	type;		/* bus type, I2C, SPI or ...*/
1186388e357SSimon Glass 	u8	host_num;	/* attached to host 0, 1...*/
1196388e357SSimon Glass 	u16	addr;
1206388e357SSimon Glass 	u8	irq;
1216388e357SSimon Glass 	u32	max_freq;
1226388e357SSimon Glass 	char	name[SFI_NAME_LEN];
1236388e357SSimon Glass };
1246388e357SSimon Glass 
1256388e357SSimon Glass enum {
1266388e357SSimon Glass 	SFI_DEV_TYPE_SPI	= 0,
1276388e357SSimon Glass 	SFI_DEV_TYPE_I2C,
1286388e357SSimon Glass 	SFI_DEV_TYPE_UART,
1296388e357SSimon Glass 	SFI_DEV_TYPE_HSI,
1306388e357SSimon Glass 	SFI_DEV_TYPE_IPC,
1316388e357SSimon Glass 	SFI_DEV_TYPE_SD,
1326388e357SSimon Glass };
1336388e357SSimon Glass 
1346388e357SSimon Glass struct __packed sfi_gpio_table_entry {
1356388e357SSimon Glass 	char	controller_name[SFI_NAME_LEN];
1366388e357SSimon Glass 	u16	pin_no;
1376388e357SSimon Glass 	char	pin_name[SFI_NAME_LEN];
1386388e357SSimon Glass };
1396388e357SSimon Glass 
1406388e357SSimon Glass struct sfi_xsdt_header {
1416388e357SSimon Glass 	uint32_t oem_revision;
1426388e357SSimon Glass 	uint32_t creator_id;
1436388e357SSimon Glass 	uint32_t creator_revision;
1446388e357SSimon Glass };
1456388e357SSimon Glass 
1466388e357SSimon Glass typedef int (*sfi_table_handler) (struct sfi_table_header *table);
1476388e357SSimon Glass 
1486388e357SSimon Glass /**
1496388e357SSimon Glass  * write_sfi_table() - Write Simple Firmware Interface tables
1506388e357SSimon Glass  *
1516388e357SSimon Glass  * @base:	Address to write table to
1526388e357SSimon Glass  * @return address to use for the next table
1536388e357SSimon Glass  */
15442fd8c19SSimon Glass ulong write_sfi_table(ulong base);
1556388e357SSimon Glass 
1566388e357SSimon Glass #endif /*_LINUX_SFI_H */
157