diff options
Diffstat (limited to 'sys/include/dev/pci')
-rw-r--r-- | sys/include/dev/pci/pci.h | 16 | ||||
-rw-r--r-- | sys/include/dev/pci/pciregs.h | 13 | ||||
-rw-r--r-- | sys/include/dev/pci/resource.h | 51 |
3 files changed, 77 insertions, 3 deletions
diff --git a/sys/include/dev/pci/pci.h b/sys/include/dev/pci/pci.h index 497bfc7..144b500 100644 --- a/sys/include/dev/pci/pci.h +++ b/sys/include/dev/pci/pci.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team. + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,20 +54,29 @@ struct pci_device { uint8_t slot; uint8_t func; + uint16_t segment; uint16_t msix_capoff; uint16_t device_id; uint16_t vendor_id; uint8_t pci_class; uint8_t pci_subclass; uint8_t prog_if; + uint8_t hdr_type; + uint8_t pci_express : 1; + + uint8_t pri_bus; + uint8_t sec_bus; + uint8_t sub_bus; + uintptr_t bar[6]; uint8_t irq_line; + TAILQ_ENTRY(pci_device) link; }; struct msi_intr { const char *name; - void(*handler)(void *); + int(*handler)(void *); }; pcireg_t pci_readl(struct pci_device *dev, uint32_t offset); @@ -77,6 +86,9 @@ int pci_map_bar(struct pci_device *dev, uint8_t barno, void **vap); void pci_writel(struct pci_device *dev, uint32_t offset, pcireg_t val); int pci_enable_msix(struct pci_device *dev, const struct msi_intr *intr); +void pci_add_device(struct pci_device *dev); + +void pci_msix_eoi(void); int pci_init(void); #endif /* !_PCI_H_ */ diff --git a/sys/include/dev/pci/pciregs.h b/sys/include/dev/pci/pciregs.h index f0ed4d2..29e4072 100644 --- a/sys/include/dev/pci/pciregs.h +++ b/sys/include/dev/pci/pciregs.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team. + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,8 +35,10 @@ #define PCIREG_VENDOR_ID 0x00 /* 16 bits */ #define PCIREG_DEVICE_ID 0x02 /* 16 bits */ #define PCIREG_CLASSREV 0x08 /* 32 bits */ +#define PCIREG_HDRTYPE 0x0e /* 8 bits */ #define PCIREG_BAR0 0x10 /* 32 bits */ #define PCIREG_BAR1 0x14 /* 32 bits */ +#define PCIREG_BUSES 0x18 /* 24 bits */ #define PCIREG_BAR2 0x18 /* 32 bits */ #define PCIREG_BAR3 0x1C /* 32 bits */ #define PCIREG_BAR4 0x20 /* 32 bits */ @@ -51,6 +53,11 @@ #define PCIREG_REVID(CLASSREV) (CLASSREV & 0xFF) #define PCIREG_PROGIF(CLASSREV) ((CLASSREV >> 8) & 0xFF) +/* Macros to extract PCI_BUSES bits */ +#define PCIREG_PRIBUS(BUSES) (BUSES & 0xFF) +#define PCIREG_SECBUS(BUSES) ((BUSES >> 8) & 0xFF) +#define PCIREG_SUBBUS(BUSES) ((BUSES >> 16) & 0xFF) + /* Macros to extract PCIREG_CMDSTATUS bits */ #define PCIREG_COMMAND(CMDSTATUS) (CMDSTATUS & 0xFFFF) #define PCIREG_STATUS(CMDSTATUS) (CMDSTATUS >> 16) @@ -74,4 +81,8 @@ #define PCI_BAR_32(BAR) (PCI_BAR_TYPE(BAR) == 0x0) #define PCI_BAR_64(BAR) (PCI_BAR_TYPE(BAR) == 0x2) +/* PCI header types */ +#define PCI_HDRTYPE_NORMAL 0x00 +#define PCI_HDRTYPE_BRIDGE 0x01 + #endif /* _PCI_PCIREGS_H_ */ diff --git a/sys/include/dev/pci/resource.h b/sys/include/dev/pci/resource.h new file mode 100644 index 0000000..b469e8f --- /dev/null +++ b/sys/include/dev/pci/resource.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _PCI_RESOURCE_H_ +#define _PCI_RESOURCE_H_ + +#include <machine/bus.h> + +/* Enable/disable DMA (bus mastering in this case) */ +int pcir_enable_dma(struct bus_resource *brp, void *devp); +int pcir_disable_dma(struct bus_resource *brp, void *devp); + +/* Set/unset bus resource semantics */ +int pcir_set_sem(struct bus_resource *brp, bus_sem_t sem); +int pcir_clr_sem(struct bus_resource *brp, bus_sem_t sem); + +/* DMA buffer helpers (XXX: unused for now) */ +int pcir_dma_alloc(struct bus_resource *brp, void *res); +int pcir_dma_free(struct bus_resource *brp, void *p); + +/* DMA transaction helpers (XXX: unused for now) */ +ssize_t pcir_dma_in(struct bus_resource *brp, void *p); +ssize_t pcir_dma_out(struct bus_resource *brp, void *p); + +#endif /* !_PCI_RESOURCE_H_ */ |