xref: /aosp_15_r20/external/coreboot/src/acpi/acpigen_pci.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpigen.h>
4 #include <acpi/acpigen_pci.h>
5 #include <assert.h>
6 #include <device/device.h>
7 #include <device/pci_def.h>
8 #include <device/pci_type.h>
9 #include <types.h>
10 
acpigen_write_ADR_pci_devfn(pci_devfn_t devfn)11 void acpigen_write_ADR_pci_devfn(pci_devfn_t devfn)
12 {
13 	/*
14 	 * _ADR for PCI Bus is encoded as follows:
15 	 * [63:32] - unused
16 	 * [31:16] - device #
17 	 * [15:0]  - function #
18 	 */
19 	acpigen_write_ADR(PCI_SLOT(devfn) << 16 | PCI_FUNC(devfn));
20 }
21 
acpigen_write_ADR_pci_device(const struct device * dev)22 void acpigen_write_ADR_pci_device(const struct device *dev)
23 {
24 	assert(dev->path.type == DEVICE_PATH_PCI);
25 	acpigen_write_ADR_pci_devfn(dev->path.pci.devfn);
26 }
27 
acpigen_write_PRT_GSI_entry(unsigned int pci_dev,unsigned int acpi_pin,unsigned int gsi)28 void acpigen_write_PRT_GSI_entry(unsigned int pci_dev, unsigned int acpi_pin, unsigned int gsi)
29 {
30 	acpigen_write_package(4);
31 	acpigen_write_dword((pci_dev << 16) | 0xffff);
32 	acpigen_write_byte(acpi_pin);
33 
34 	/* Source */
35 	acpigen_write_byte(0);
36 
37 	/* Source Index */
38 	acpigen_write_dword(gsi);
39 
40 	acpigen_pop_len(); /* Package */
41 }
42 
acpigen_write_PRT_source_entry(unsigned int pci_dev,unsigned int acpi_pin,const char * source_path,unsigned int index)43 void acpigen_write_PRT_source_entry(unsigned int pci_dev, unsigned int acpi_pin,
44 				    const char *source_path, unsigned int index)
45 {
46 	acpigen_write_package(4);
47 	acpigen_write_dword((pci_dev << 16) | 0xffff);
48 	acpigen_write_byte(acpi_pin);
49 
50 	/* Source */
51 	acpigen_emit_namestring(source_path);
52 
53 	/* Source Index */
54 	acpigen_write_dword(index);
55 
56 	acpigen_pop_len(); /* Package */
57 }
58