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