39#include <sys/malloc.h>
41#include <sys/endian.h>
42#include <sys/kernel.h>
43#include <sys/module.h>
47#include <vm/vm_extern.h>
48#include <vm/vm_page.h>
49#include <vm/vm_phys.h>
51#include <contrib/dev/acpica/include/acpi.h>
52#include <contrib/dev/acpica/include/accommon.h>
54#include <dev/acpica/acpivar.h>
55#include <dev/acpica/acpi_pcibvar.h>
65#define AP_NS_SHARED_MEM_BASE 0x06000000
66#define N1SDP_MAX_SEGMENTS 2
67#define BDF_TABLE_SIZE (16 * 1024)
68#define PCI_CFG_SPACE_SIZE 0x1000
71 "pci_n1sdp.c assumes a 4k or 16k page size when mapping the shared data");
99 VM_MEMATTR_UNCACHEABLE);
101 for (i = 0; i < nitems(m); i++) {
102 m[i] = PHYS_TO_VM_PAGE(paddr + i * PAGE_SIZE);
108 printf(
"%s: Can't allocate KVA memory.", __func__);
112 pmap_qenter(vaddr, m, nitems(m));
122 sizeof(uint32_t) * shared_data->
nr_bdfs;
129 for (i = 0; i < table_count; i++)
130 printf(
"valid bdf %x\n",
135 pmap_qremove(vaddr, nitems(m));
157 for (i = 0; i < table_count; i++)
167 ACPI_DEVICE_INFO *devinfo;
168 ACPI_TABLE_HEADER *hdr;
173 if (acpi_disabled(
"pcib") || (h = acpi_get_handle(
dev)) == NULL ||
174 ACPI_FAILURE(AcpiGetObjectInfo(h, &devinfo)))
177 root = (devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0;
183 status = AcpiGetTable(ACPI_SIG_MCFG, 1, &hdr);
187 if (memcmp(hdr->OemId,
"ARMLTD", ACPI_OEM_ID_SIZE) != 0 ||
188 memcmp(hdr->OemTableId,
"ARMN1SDP", ACPI_OEM_TABLE_ID_SIZE) != 0 ||
189 hdr->OemRevision != 0x20181101)
192 device_set_desc(
dev,
"ARM N1SDP PCI host controller");
193 return (BUS_PROBE_DEFAULT);
208 sc = device_get_softc(
dev);
209 handle = acpi_get_handle(
dev);
213 if (ACPI_FAILURE(
status)) {
214 device_printf(
dev,
"No _SEG for PCI Bus\n");
219 device_printf(
dev,
"Unknown PCI Bus segment (domain) %d\n",
228 device_add_child(
dev,
"pci", -1);
229 return (bus_generic_attach(
dev));
234 bus_space_tag_t *bst, bus_space_handle_t *bsh, bus_size_t *offset)
238 sc = device_get_softc(
dev);
260 u_int
func, u_int
reg,
int bytes)
265 bus_space_handle_t h;
270 sc_n1sdp = device_get_softc(
dev);
271 sc_acpi = &sc_n1sdp->
acpi;
283 data = bus_space_read_4(t, h, offset & ~3);
287 data >>= (offset & 3) * 8;
291 data >>= (offset & 3) * 8;
306 u_int
func, u_int
reg, uint32_t
val,
int bytes)
311 bus_space_handle_t h;
316 sc_n1sdp = device_get_softc(
dev);
317 sc_acpi = &sc_n1sdp->
acpi;
329 data = bus_space_read_4(t, h, offset & ~3);
333 data &= ~(0xff << ((offset & 3) * 8));
334 data |= (
val & 0xff) << ((offset & 3) * 8);
337 data &= ~(0xffff << ((offset & 3) * 8));
338 data |= (
val & 0xffff) << ((offset & 3) * 8);
347 bus_space_write_4(t, h, offset & ~3,
data);
#define PCIE_ADDR_OFFSET(bus, slot, func, reg)
int pci_host_generic_acpi_init(device_t dev)
static int n1sdp_pcie_acpi_attach(device_t dev)
static uint32_t n1sdp_pcie_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, int bytes)
static int n1sdp_check_bdf(struct generic_pcie_n1sdp_softc *sc, u_int bus, u_int slot, u_int func)
#define N1SDP_MAX_SEGMENTS
static void n1sdp_pcie_write_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, uint32_t val, int bytes)
DRIVER_MODULE(n1sdp_pcib, acpi, n1sdp_pcie_acpi_driver, n1sdp_pcie_acpi_devclass, 0, 0)
#define AP_NS_SHARED_MEM_BASE
static int n1sdp_get_bus_space(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, bus_space_tag_t *bst, bus_space_handle_t *bsh, bus_size_t *offset)
_Static_assert(BDF_TABLE_SIZE >=PAGE_SIZE, "pci_n1sdp.c assumes a 4k or 16k page size when mapping the shared data")
static int n1sdp_pcie_acpi_probe(device_t dev)
DEFINE_CLASS_1(pcib, n1sdp_pcie_acpi_driver, n1sdp_pcie_acpi_methods, sizeof(struct generic_pcie_n1sdp_softc), generic_pcie_acpi_driver)
static device_method_t n1sdp_pcie_acpi_methods[]
static devclass_t n1sdp_pcie_acpi_devclass
static int n1sdp_init(struct generic_pcie_n1sdp_softc *sc)
#define PCI_CFG_SPACE_SIZE
static uint32_t pcib_read_config(device_t dev, u_int b, u_int s, u_int f, u_int reg, int width)
static void pcib_write_config(device_t dev, u_int b, u_int s, u_int f, u_int reg, uint32_t val, int width)
struct generic_pcie_core_softc base
struct generic_pcie_acpi_softc acpi
bus_space_handle_t n1_bsh
struct pcie_discovery_data * n1_discovery_data