1 /* 2 * Copyright(c) 2009 Intel Corporation. All rights reserved. 3 * 4 * SPDX-License-Identifier: GPL-2.0+ BSD-3-Clause 5 */ 6 7 #ifndef _LINUX_SFI_H 8 #define _LINUX_SFI_H 9 10 #include <errno.h> 11 #include <linux/types.h> 12 13 /* Table signatures reserved by the SFI specification */ 14 #define SFI_SIG_SYST "SYST" 15 #define SFI_SIG_FREQ "FREQ" 16 #define SFI_SIG_CPUS "CPUS" 17 #define SFI_SIG_MTMR "MTMR" 18 #define SFI_SIG_MRTC "MRTC" 19 #define SFI_SIG_MMAP "MMAP" 20 #define SFI_SIG_APIC "APIC" 21 #define SFI_SIG_XSDT "XSDT" 22 #define SFI_SIG_WAKE "WAKE" 23 #define SFI_SIG_DEVS "DEVS" 24 #define SFI_SIG_GPIO "GPIO" 25 26 #define SFI_SIGNATURE_SIZE 4 27 #define SFI_OEM_ID_SIZE 6 28 #define SFI_OEM_TABLE_ID_SIZE 8 29 30 #define SFI_NAME_LEN 16 31 #define SFI_TABLE_MAX_ENTRIES 16 32 33 #define SFI_GET_NUM_ENTRIES(ptable, entry_type) \ 34 ((ptable->header.len - sizeof(struct sfi_table_header)) / \ 35 (sizeof(entry_type))) 36 /* 37 * Table structures must be byte-packed to match the SFI specification, 38 * as they are provided by the BIOS. 39 */ 40 struct __packed sfi_table_header { 41 char sig[SFI_SIGNATURE_SIZE]; 42 u32 len; 43 u8 rev; 44 u8 csum; 45 char oem_id[SFI_OEM_ID_SIZE]; 46 char oem_table_id[SFI_OEM_TABLE_ID_SIZE]; 47 }; 48 49 struct __packed sfi_table_simple { 50 struct sfi_table_header header; 51 u64 pentry[1]; 52 }; 53 54 /* Comply with UEFI spec 2.1 */ 55 struct __packed sfi_mem_entry { 56 u32 type; 57 u64 phys_start; 58 u64 virt_start; 59 u64 pages; 60 u64 attrib; 61 }; 62 63 struct __packed sfi_cpu_table_entry { 64 u32 apic_id; 65 }; 66 67 struct __packed sfi_cstate_table_entry { 68 u32 hint; /* MWAIT hint */ 69 u32 latency; /* latency in ms */ 70 }; 71 72 struct __packed sfi_apic_table_entry { 73 u64 phys_addr; /* phy base addr for APIC reg */ 74 }; 75 76 struct __packed sfi_freq_table_entry { 77 u32 freq_mhz; /* in MHZ */ 78 u32 latency; /* transition latency in ms */ 79 u32 ctrl_val; /* value to write to PERF_CTL */ 80 }; 81 82 struct __packed sfi_wake_table_entry { 83 u64 phys_addr; /* pointer to where the wake vector locates */ 84 }; 85 86 struct __packed sfi_timer_table_entry { 87 u64 phys_addr; /* phy base addr for the timer */ 88 u32 freq_hz; /* in HZ */ 89 u32 irq; 90 }; 91 92 struct __packed sfi_rtc_table_entry { 93 u64 phys_addr; /* phy base addr for the RTC */ 94 u32 irq; 95 }; 96 97 struct __packed sfi_device_table_entry { 98 u8 type; /* bus type, I2C, SPI or ...*/ 99 u8 host_num; /* attached to host 0, 1...*/ 100 u16 addr; 101 u8 irq; 102 u32 max_freq; 103 char name[SFI_NAME_LEN]; 104 }; 105 106 enum { 107 SFI_DEV_TYPE_SPI = 0, 108 SFI_DEV_TYPE_I2C, 109 SFI_DEV_TYPE_UART, 110 SFI_DEV_TYPE_HSI, 111 SFI_DEV_TYPE_IPC, 112 SFI_DEV_TYPE_SD, 113 }; 114 115 struct __packed sfi_gpio_table_entry { 116 char controller_name[SFI_NAME_LEN]; 117 u16 pin_no; 118 char pin_name[SFI_NAME_LEN]; 119 }; 120 121 struct sfi_xsdt_header { 122 uint32_t oem_revision; 123 uint32_t creator_id; 124 uint32_t creator_revision; 125 }; 126 127 typedef int (*sfi_table_handler) (struct sfi_table_header *table); 128 129 /** 130 * write_sfi_table() - Write Simple Firmware Interface tables 131 * 132 * @base: Address to write table to 133 * @return address to use for the next table 134 */ 135 u32 write_sfi_table(u32 base); 136 137 #endif /*_LINUX_SFI_H */ 138