1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Based on acpi.c from coreboot
4  *
5  * Copyright (C) 2015, Saket Sinha <saket.sinha89@gmail.com>
6  * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
7  */
8 
9 #ifndef __ASM_ACPI_TABLE_H__
10 #define __ASM_ACPI_TABLE_H__
11 
12 #ifndef __ACPI__
13 
14 #include <pci.h>
15 
16 struct acpi_facs;
17 struct acpi_fadt;
18 struct acpi_global_nvs;
19 struct acpi_madt_ioapic;
20 struct acpi_madt_irqoverride;
21 struct acpi_madt_lapic_nmi;
22 struct acpi_mcfg_mmconfig;
23 struct acpi_table_header;
24 
25 /* These can be used by the target port */
26 
27 void acpi_fill_header(struct acpi_table_header *header, char *signature);
28 void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
29 		      void *dsdt);
30 int acpi_create_madt_lapics(u32 current);
31 int acpi_create_madt_ioapic(struct acpi_madt_ioapic *ioapic, u8 id,
32 			    u32 addr, u32 gsi_base);
33 int acpi_create_madt_irqoverride(struct acpi_madt_irqoverride *irqoverride,
34 				 u8 bus, u8 source, u32 gsirq, u16 flags);
35 int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi,
36 			       u8 cpu, u16 flags, u8 lint);
37 u32 acpi_fill_madt(u32 current);
38 int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base,
39 			      u16 seg_nr, u8 start, u8 end);
40 u32 acpi_fill_mcfg(u32 current);
41 u32 acpi_fill_csrt(u32 current);
42 
43 /**
44  * acpi_write_hpet() - Write out a HPET table
45  *
46  * Write out the table for High-Precision Event Timers
47  *
48  * @ctx: Current ACPI context
49  * @return 0 if OK, -ve on error
50  */
51 int acpi_write_hpet(struct acpi_ctx *ctx);
52 
53 /**
54  * acpi_write_dbg2_pci_uart() - Write out a DBG2 table
55  *
56  * @ctx: Current ACPI context
57  * @dev: Debug UART device to describe
58  * @access_size: Access size for UART (e.g. ACPI_ACCESS_SIZE_DWORD_ACCESS)
59  * @return 0 if OK, -ve on error
60  */
61 int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev,
62 			     uint access_size);
63 
64 /**
65  * acpi_create_gnvs() - Create a GNVS (Global Non Volatile Storage) table
66  *
67  * @gnvs: Table to fill in
68  * @return 0 if OK, -ve on error
69  */
70 int acpi_create_gnvs(struct acpi_global_nvs *gnvs);
71 
72 ulong write_acpi_tables(ulong start);
73 
74 /**
75  * acpi_get_rsdp_addr() - get ACPI RSDP table address
76  *
77  * This routine returns the ACPI RSDP table address in the system memory.
78  *
79  * @return:	ACPI RSDP table address
80  */
81 ulong acpi_get_rsdp_addr(void);
82 
83 /**
84  * arch_read_sci_irq_select() - Read the system-control interrupt number
85  *
86  * @returns value of IRQ register in the PMC
87  */
88 int arch_read_sci_irq_select(void);
89 
90 /**
91  * arch_write_sci_irq_select() - Set the system-control interrupt number
92  *
93  * @scis: New value for IRQ register in the PMC
94  */
95 int arch_write_sci_irq_select(uint scis);
96 
97 /**
98  * arch_madt_sci_irq_polarity() - Return the priority to use for the MADT
99  *
100  * @sci: System-control interrupt number
101  * @return priority to use (MP_IRQ_POLARITY_...)
102  */
103 int arch_madt_sci_irq_polarity(int sci);
104 
105 /**
106  * acpi_create_dmar_drhd() - Create a table for DMA remapping with the IOMMU
107  *
108  * See here for the specification
109  * https://software.intel.com/sites/default/files/managed/c5/15/vt-directed-io-spec.pdf
110  *
111  * @ctx: ACPI context pointer
112  * @flags: (DRHD_INCLUDE_...)
113  * @segment: PCI segment asscociated with this unit
114  * @bar: Base address of remapping hardware register-set for this unit
115  */
116 void acpi_create_dmar_drhd(struct acpi_ctx *ctx, uint flags, uint segment,
117 			   u64 bar);
118 
119 /**
120  * acpi_create_dmar_rmrr() - Set up an RMRR
121  *
122  * This sets up a Reserved-Memory Region Reporting structure, used to allow
123  * DMA to regions used by devices that the BIOS controls.
124  *
125  * @ctx: ACPI context pointer
126  * @segment: PCI segment asscociated with this unit
127  * @bar: Base address of mapping
128  * @limit: End address of mapping
129  */
130 void acpi_create_dmar_rmrr(struct acpi_ctx *ctx, uint segment, u64 bar,
131 			   u64 limit);
132 
133 /**
134  * acpi_dmar_drhd_fixup() - Set the length of an DRHD
135  *
136  * This sets the DRHD length field based on the current ctx->current
137  *
138  * @ctx: ACPI context pointer
139  * @base: Address of the start of the DRHD
140  */
141 void acpi_dmar_drhd_fixup(struct acpi_ctx *ctx, void *base);
142 
143 /**
144  * acpi_dmar_rmrr_fixup() - Set the length of an RMRR
145  *
146  * This sets the RMRR length field based on the current ctx->current
147  *
148  * @ctx: ACPI context pointer
149  * @base: Address of the start of the RMRR
150  */
151 void acpi_dmar_rmrr_fixup(struct acpi_ctx *ctx, void *base);
152 
153 /**
154  * acpi_create_dmar_ds_pci() - Set up a DMAR scope for a PCI device
155  *
156  * @ctx: ACPI context pointer
157  * @bdf: PCI device to add
158  * @return length of mapping in bytes
159  */
160 int acpi_create_dmar_ds_pci(struct acpi_ctx *ctx, pci_dev_t bdf);
161 
162 /**
163  * acpi_create_dmar_ds_pci_br() - Set up a DMAR scope for a PCI bridge
164  *
165  * This is used to provide a mapping for a PCI bridge
166  *
167  * @ctx: ACPI context pointer
168  * @bdf: PCI device to add
169  * @return length of mapping in bytes
170  */
171 int acpi_create_dmar_ds_pci_br(struct acpi_ctx *ctx, pci_dev_t bdf);
172 
173 /**
174  * acpi_create_dmar_ds_ioapic() - Set up a DMAR scope for an IOAPIC device
175  *
176  * @ctx: ACPI context pointer
177  * @enumeration_id: Enumeration ID (typically 2)
178  * @bdf: PCI device to add
179  * @return length of mapping in bytes
180  */
181 int acpi_create_dmar_ds_ioapic(struct acpi_ctx *ctx, uint enumeration_id,
182 			       pci_dev_t bdf);
183 
184 /**
185  * acpi_create_dmar_ds_msi_hpet() - Set up a DMAR scope for an HPET
186  *
187  * Sets up a scope for a High-Precision Event Timer that supports
188  * Message-Signalled Interrupts
189  *
190  * @ctx: ACPI context pointer
191  * @enumeration_id: Enumeration ID (typically 0)
192  * @bdf: PCI device to add
193  * @return length of mapping in bytes
194  */
195 int acpi_create_dmar_ds_msi_hpet(struct acpi_ctx *ctx, uint enumeration_id,
196 				 pci_dev_t bdf);
197 
198 /**
199  * acpi_fadt_common() - Handle common parts of filling out an FADT
200  *
201  * This sets up the Fixed ACPI Description Table
202  *
203  * @fadt: Pointer to place to put FADT
204  * @facs: Pointer to the FACS
205  * @dsdt: Pointer to the DSDT
206  */
207 void acpi_fadt_common(struct acpi_fadt *fadt, struct acpi_facs *facs,
208 		      void *dsdt);
209 
210 /**
211  * intel_acpi_fill_fadt() - Set up the contents of the FADT
212  *
213  * This sets up parts of the Fixed ACPI Description Table that are common to
214  * Intel chips
215  *
216  * @fadt: Pointer to place to put FADT
217  */
218 void intel_acpi_fill_fadt(struct acpi_fadt *fadt);
219 
220 #endif /* !__ACPI__ */
221 
222 #endif /* __ASM_ACPI_TABLE_H__ */
223