Skip to content

Commit

Permalink
drivers/ukbus/pci: Map PCI regions on runtime
Browse files Browse the repository at this point in the history
Update the PCI driver to map PCI regions on runtime if paging is
enabled.

Signed-off-by: Michalis Pappas <[email protected]>
Reviewed-by: Sergiu Moga <[email protected]>
Reviewed-by: Razvan Deaconescu <[email protected]>
Approved-by: Razvan Deaconescu <[email protected]>
GitHub-Closes: unikraft#1465
  • Loading branch information
michpappas authored and unikraft-bot committed Aug 9, 2024
1 parent ad1c8e7 commit 5369a56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions drivers/ukbus/pci/arch/arm64/pci_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
*/

#include <string.h>
#include <uk/errptr.h>
#include <uk/print.h>
#include <uk/plat/common/cpu.h>
#include <uk/bus/pci.h>
Expand Down Expand Up @@ -91,6 +92,15 @@ static int arch_pci_driver_add_device(struct pci_driver *drv,
memcpy(&dev->addr, addr, sizeof(dev->addr));
dev->drv = drv;

#if CONFIG_PAGING
/* TODO Properly query the BAR size */
base = uk_bus_pf_devmap(base, __PAGE_SIZE);
if (unlikely(PTRISERR(base))) {
uk_pr_err("Could not map device (%d)\n", PTR2ERR(base));
return PTR2ERR(base);
}
#endif /* CONFIG_PAGING */

dev->base = base;
dev->irq = irq;
uk_pr_info("pci dev base(0x%lx) irq(%ld)\n", dev->base, dev->irq);
Expand Down
17 changes: 15 additions & 2 deletions drivers/ukbus/pci/pci_ecam.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <stdbool.h>
#include <uk/bus/platform.h>
#include <uk/errptr.h>
#include <uk/list.h>
#include <uk/alloc.h>
#include <uk/print.h>
Expand Down Expand Up @@ -406,6 +407,7 @@ static int gen_pci_probe(struct pf_device *pfdev __unused)
__u64 reg_size;
struct pci_range range;
struct pci_range_parser parser;
__vaddr_t vaddr __maybe_unused;
const char *comp;
int err;

Expand All @@ -432,10 +434,21 @@ static int gen_pci_probe(struct pf_device *pfdev __unused)
reg_size = reg_size << 32 | fdt32_to_cpu(prop[3]);
}

#if CONFIG_PAGING
vaddr = uk_bus_pf_devmap(reg_base, reg_size);
if (unlikely(PTRISERR(vaddr))) {
uk_pr_err("Could not map MMIO region at 0x%lx - 0x%lx (%d)\n",
reg_base, reg_base + reg_size, PTR2ERR(vaddr));
return PTR2ERR(vaddr);
}
pcw.config_base = vaddr;
#else /* !CONFIG_PAGING */
pcw.config_base = reg_base;
#endif /* !CONFIG_PAGING */

pcw.config_space_size = reg_size;
uk_pr_info("generic pci config base(0x%lx),size(0x%lx)\n",
reg_base, reg_size);
uk_pr_info("generic pci config base(0x%lx), size(0x%lx)\n",
reg_base, reg_size);

/* 2.Get the bus range of pci controller */
prop = fdt_getprop(dtb, gen_pci_fdt, "bus-range", &prop_len);
Expand Down

0 comments on commit 5369a56

Please sign in to comment.