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.
This commit is contained in:
Augustin Cavalier 2022-02-18 21:35:38 -05:00
parent 843a8ad7a7
commit fc6ea2ef78
3 changed files with 21 additions and 16 deletions

View File

@ -77,10 +77,8 @@ bus_alloc_irq_resource(device_t dev, struct resource *res)
if (irq == 0 || irq == 0xff) if (irq == 0 || irq == 0xff)
return -1; return -1;
/* TODO: IRQ resources! */ res->r_bustag = BUS_SPACE_TAG_IRQ;
res->r_bustag = 0;
res->r_bushandle = irq; res->r_bushandle = irq;
return 0; 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) if (res->r_mapped_area < B_OK)
return -1; return -1;
res->r_bustag = X86_BUS_SPACE_MEM; res->r_bustag = BUS_SPACE_TAG_MEM;
res->r_bushandle = (bus_space_handle_t)virtualAddr; res->r_bushandle = (bus_space_handle_t)virtualAddr;
return 0; 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) if (pci_enable_io(dev, SYS_RES_IOPORT) != 0)
return -1; 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]; res->r_bushandle = info->u.h0.base_registers[bar_index];
return 0; 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 // msi or msi-x interrupt at index *rid - 1
pci_info *info; pci_info *info;
info = &((struct root_device_softc *)dev->root->softc)->pci_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; res->r_bushandle = info->u.h0.interrupt_line + *rid - 1;
result = 0; result = 0;
} }
@ -404,7 +402,7 @@ bus_setup_intr(device_t dev, struct resource *res, int flags,
intr_wrapper, intr, 0); 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 // this is an msi, enable it
pci_info *info pci_info *info
= &((struct root_device_softc *)dev->root->softc)->pci_info; = &((struct root_device_softc *)dev->root->softc)->pci_info;

View File

@ -13,24 +13,31 @@
typedef phys_addr_t bus_addr_t; 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 #ifdef B_HAIKU_64_BIT
typedef uint64_t bus_size_t; typedef uint64_t bus_size_t;
typedef uint64_t bus_space_tag_t;
typedef uint64_t bus_space_handle_t; typedef uint64_t bus_space_handle_t;
#else #else
typedef uint32_t bus_size_t;
typedef unsigned int bus_space_handle_t;
#if defined(__HAIKU_ARCH_PHYSICAL_64_BIT) && defined(__i386__) #if defined(__HAIKU_ARCH_PHYSICAL_64_BIT) && defined(__i386__)
#define PAE 1 #define PAE 1
#endif #endif
typedef uint32_t bus_size_t;
typedef int bus_space_tag_t;
typedef unsigned int bus_space_handle_t;
#endif #endif

View File

@ -109,8 +109,8 @@
/* /*
* Values for the x86 bus space tag, not to be used directly by MI code. * 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_IO BUS_SPACE_TAG_IO /* space is i/o space */
#define X86_BUS_SPACE_MEM 1 /* space is mem space */ #define X86_BUS_SPACE_MEM BUS_SPACE_TAG_MEM /* space is mem space */
#define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
#define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF