1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <cpu/x86/smm.h>
4 #include <device/device.h>
5 #include <device/pci_def.h>
6 #include <device/pci_ops.h>
8 void smm_pci_get_stored_resources(const volatile struct smm_pci_resource_info
**out_slots
,
11 *out_slots
= smm_get_pci_resource_store();
12 *out_size
= CONFIG_SMM_PCI_RESOURCE_STORE_NUM_SLOTS
;
15 bool smm_pci_resource_store_fill_resources(struct smm_pci_resource_info
*slots
, size_t num_slots
,
16 const struct device
**devices
, size_t num_devices
)
20 for (size_t i_dev
= 0; i_dev
< num_devices
; i_dev
++) {
21 if (i_slot
>= num_slots
) {
22 printk(BIOS_ERR
, "Failed to store all PCI resources, number of devices exceeds %zd slots\n",
27 if (!is_pci(devices
[i_dev
])) {
28 printk(BIOS_WARNING
, "Skipping storing PCI resources for device at index %zd, not a PCI device\n",
33 pci_devfn_t pci_addr
= PCI_BDF(devices
[i_dev
]);
34 slots
[i_slot
].pci_addr
= pci_addr
;
35 slots
[i_slot
].class_device
= PCI_CLASS_GET_DEVICE(devices
[i_dev
]->class);
36 slots
[i_slot
].class_prog
= PCI_CLASS_GET_PROG(devices
[i_dev
]->class);
37 slots
[i_slot
].vendor_id
= devices
[i_dev
]->vendor
;
38 slots
[i_slot
].device_id
= devices
[i_dev
]->device
;
41 for (const struct resource
*res
= devices
[i_dev
]->resource_list
; res
!= NULL
;
43 slots
[i_slot
].resources
[i_res
] = *res
;
44 slots
[i_slot
].resources
[i_res
].next
= NULL
;
47 slots
[i_slot
].resources
[i_res
- 1].next
= (struct resource
*)&slots
[i_slot
].resources
[i_res
];
49 if (++i_res
>= SMM_PCI_RESOURCE_STORE_NUM_RESOURCES
) {
51 printk(BIOS_WARNING
, "Number of PCI resources exceeds supported storage count\n");
62 void __weak
smm_mainboard_pci_resource_store_init(struct smm_pci_resource_info
*slots
,
67 void smm_pci_resource_store_init(struct smm_runtime
*smm_runtime
)
69 smm_mainboard_pci_resource_store_init(&smm_runtime
->pci_resources
[0],
70 CONFIG_SMM_PCI_RESOURCE_STORE_NUM_SLOTS
);