*
*/
#include <hal/pci.h>
-#include <sys/pci_hba.h>
#include <klibc/string.h>
#include <lunaix/fs/twifs.h>
}
int
-pci_bind_definition(struct pci_device_def* pcidev_def, int* more)
+pci_bind_definition(struct pci_device_def* pcidef, bool* more)
{
- u32_t class = pcidev_def->dev_class;
- u32_t devid_mask = pcidev_def->ident_mask;
- u32_t devid = pcidev_def->dev_ident & devid_mask;
-
- if (!pcidev_def->devdef.bind) {
+ if (!pcidef->devdef.bind) {
ERROR("pcidev %xh:%xh.%d is unbindable",
- pcidev_def->devdef.class.fn_grp,
- pcidev_def->devdef.class.device,
- pcidev_def->devdef.class.variant);
+ pcidef->devdef.class.fn_grp,
+ pcidef->devdef.class.device,
+ pcidef->devdef.class.variant);
return EINVAL;
}
- *more = 0;
+ *more = false;
- int bind_attempted = 0;
+ bool bind_attempted = 0;
int errno = 0;
struct device_def* devdef;
continue;
}
- if (class != PCI_DEV_CLASS(pos->class_info)) {
- continue;
- }
+ bool matched;
- int matched = (pos->device_info & devid_mask) == devid;
+ assert(pcidef->test_compatibility);
+ matched = pcidef->test_compatibility(pcidef, pos);
if (!matched) {
continue;
}
if (bind_attempted) {
- *more = 1;
+ *more = true;
break;
}
- bind_attempted = 1;
- devdef = &pcidev_def->devdef;
+ bind_attempted = true;
+ devdef = &pcidef->devdef;
errno = devdef->bind(devdef, &pos->dev);
if (errno) {
continue;
}
- pos->binding.def = &pcidev_def->devdef;
+ pos->binding.def = &pcidef->devdef;
}
return errno;
int
pci_bind_definition_all(struct pci_device_def* pcidef)
{
- int more = 0, e = 0;
+ int e = 0;
+ bool more = false;
do {
- if (!(e = pci_bind_definition(pcidef, &more))) {
+ if ((e = pci_bind_definition(pcidef, &more))) {
break;
}
} while (more);
{
u32_t bar;
struct pci_base_addr* ba;
- for (size_t i = 0; i < 6; i++) {
+ for (size_t i = 0; i < PCI_BAR_COUNT; i++) {
ba = &device->bar[i];
ba->size = pci_bar_sizing(device, &bar, i + 1);
if (PCI_BAR_MMIO(bar)) {
return NULL;
}
+void
+pci_apply_command(struct pci_device* pcidev, pci_reg_t cmd)
+{
+ pci_reg_t rcmd;
+ ptr_t base;
+
+ base = pcidev->cspace_base;
+ rcmd = pci_read_cspace(base, PCI_REG_STATUS_CMD);
+
+ cmd = cmd & 0xffff;
+ rcmd = (rcmd & 0xffff0000) | cmd;
+
+ pci_write_cspace(base, PCI_REG_STATUS_CMD, rcmd);
+}
+
static void
__pci_read_cspace(struct twimap* map)
{