From fc6ea2ef78bb89c7712618ee05d8685d3be5358e Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 18 Feb 2022 21:35:38 -0500 Subject: [PATCH] freebsd_network: Cleanup bustag handling. * Add an enum with general BUS_SPACE_TAG values for use across platforms. * Add proper entries for generic IRQs and MSIs and make use of them. --- src/libs/compat/freebsd_network/bus.cpp | 12 +++++------ .../freebsd_network/compat/machine/_bus.h | 21 ++++++++++++------- .../freebsd_network/compat/machine/x86/bus.h | 4 ++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/libs/compat/freebsd_network/bus.cpp b/src/libs/compat/freebsd_network/bus.cpp index dc7fe5f517..372d2fdaba 100644 --- a/src/libs/compat/freebsd_network/bus.cpp +++ b/src/libs/compat/freebsd_network/bus.cpp @@ -77,10 +77,8 @@ bus_alloc_irq_resource(device_t dev, struct resource *res) if (irq == 0 || irq == 0xff) return -1; - /* TODO: IRQ resources! */ - res->r_bustag = 0; + res->r_bustag = BUS_SPACE_TAG_IRQ; res->r_bushandle = irq; - return 0; } @@ -119,7 +117,7 @@ bus_alloc_mem_resource(device_t dev, struct resource *res, pci_info *info, if (res->r_mapped_area < B_OK) return -1; - res->r_bustag = X86_BUS_SPACE_MEM; + res->r_bustag = BUS_SPACE_TAG_MEM; res->r_bushandle = (bus_space_handle_t)virtualAddr; return 0; } @@ -144,7 +142,7 @@ bus_alloc_ioport_resource(device_t dev, struct resource *res, pci_info *info, if (pci_enable_io(dev, SYS_RES_IOPORT) != 0) return -1; - res->r_bustag = X86_BUS_SPACE_IO; + res->r_bustag = BUS_SPACE_TAG_IO; res->r_bushandle = info->u.h0.base_registers[bar_index]; return 0; } @@ -193,7 +191,7 @@ bus_alloc_resource(device_t dev, int type, int *rid, unsigned long start, // msi or msi-x interrupt at index *rid - 1 pci_info *info; info = &((struct root_device_softc *)dev->root->softc)->pci_info; - res->r_bustag = 1; + res->r_bustag = BUS_SPACE_TAG_MSI; res->r_bushandle = info->u.h0.interrupt_line + *rid - 1; result = 0; } @@ -404,7 +402,7 @@ bus_setup_intr(device_t dev, struct resource *res, int flags, intr_wrapper, intr, 0); } - if (status == B_OK && res->r_bustag == 1 && gPCIx86 != NULL) { + if (status == B_OK && res->r_bustag == BUS_SPACE_TAG_MSI && gPCIx86 != NULL) { // this is an msi, enable it pci_info *info = &((struct root_device_softc *)dev->root->softc)->pci_info; diff --git a/src/libs/compat/freebsd_network/compat/machine/_bus.h b/src/libs/compat/freebsd_network/compat/machine/_bus.h index 131711b8dd..aa577d760b 100644 --- a/src/libs/compat/freebsd_network/compat/machine/_bus.h +++ b/src/libs/compat/freebsd_network/compat/machine/_bus.h @@ -13,24 +13,31 @@ typedef phys_addr_t bus_addr_t; +typedef int bus_space_tag_t; +enum { + BUS_SPACE_TAG_INVALID = 0, + + BUS_SPACE_TAG_IO, + BUS_SPACE_TAG_MEM, + BUS_SPACE_TAG_IRQ, + BUS_SPACE_TAG_MSI, +}; + + #ifdef B_HAIKU_64_BIT typedef uint64_t bus_size_t; - -typedef uint64_t bus_space_tag_t; typedef uint64_t bus_space_handle_t; #else +typedef uint32_t bus_size_t; +typedef unsigned int bus_space_handle_t; + #if defined(__HAIKU_ARCH_PHYSICAL_64_BIT) && defined(__i386__) #define PAE 1 #endif -typedef uint32_t bus_size_t; - -typedef int bus_space_tag_t; -typedef unsigned int bus_space_handle_t; - #endif diff --git a/src/libs/compat/freebsd_network/compat/machine/x86/bus.h b/src/libs/compat/freebsd_network/compat/machine/x86/bus.h index 3d18f028a5..099c142be9 100644 --- a/src/libs/compat/freebsd_network/compat/machine/x86/bus.h +++ b/src/libs/compat/freebsd_network/compat/machine/x86/bus.h @@ -109,8 +109,8 @@ /* * Values for the x86 bus space tag, not to be used directly by MI code. */ -#define X86_BUS_SPACE_IO 0 /* space is i/o space */ -#define X86_BUS_SPACE_MEM 1 /* space is mem space */ +#define X86_BUS_SPACE_IO BUS_SPACE_TAG_IO /* space is i/o space */ +#define X86_BUS_SPACE_MEM BUS_SPACE_TAG_MEM /* space is mem space */ #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF