Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Move the Linux PCI shim into its very own .c file.



details:   https://anonhg.NetBSD.org/src/rev/31a9d1c430db
branches:  trunk
changeset: 835340:31a9d1c430db
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 14:16:38 2018 +0000

description:
Move the Linux PCI shim into its very own .c file.

The poor thing has deserved this for a very long time, even though it
is full of kludges.  Also I'm tired of recompiling everything every
time I touch it.

diffstat:

 sys/external/bsd/drm2/include/linux/pci.h      |  804 +++---------------------
 sys/external/bsd/drm2/linux/files.drmkms_linux |    3 +-
 sys/external/bsd/drm2/linux/linux_pci.c        |  760 +++++++++++++++++++++++
 sys/modules/drmkms_linux/Makefile              |    3 +-
 4 files changed, 870 insertions(+), 700 deletions(-)

diffs (truncated from 1633 to 300 lines):

diff -r c35b395ed748 -r 31a9d1c430db sys/external/bsd/drm2/include/linux/pci.h
--- a/sys/external/bsd/drm2/include/linux/pci.h Mon Aug 27 14:16:17 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/pci.h Mon Aug 27 14:16:38 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci.h,v 1.36 2018/08/27 14:16:04 riastradh Exp $       */
+/*     $NetBSD: pci.h,v 1.37 2018/08/27 14:16:38 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -172,720 +172,128 @@
        bool                    no_64bit_msi;
 };
 
-static inline device_t
-pci_dev_dev(struct pci_dev *pdev)
-{
-       return pdev->pd_dev;
-}
-
-/* XXX Nouveau kludge!  */
-static inline struct drm_device *
-pci_get_drvdata(struct pci_dev *pdev)
-{
-       return pdev->pd_drm_dev;
-}
-
-static inline void
-linux_pci_dev_init(struct pci_dev *pdev, device_t dev, device_t parent,
-    const struct pci_attach_args *pa, int kludges)
-{
-       const uint32_t subsystem_id = pci_conf_read(pa->pa_pc, pa->pa_tag,
-           PCI_SUBSYS_ID_REG);
-       unsigned i;
-
-       pdev->pd_pa = *pa;
-       pdev->pd_kludges = kludges;
-       pdev->pd_rom_vaddr = NULL;
-       pdev->pd_dev = dev;
-#if (NACPICA > 0)
-       pdev->pd_ad = acpi_pcidev_find(0 /*XXX segment*/, pa->pa_bus,
-           pa->pa_device, pa->pa_function);
-#else
-       pdev->pd_ad = NULL;
-#endif
-       pdev->pd_saved_state = NULL;
-       pdev->pd_intr_handles = NULL;
-       pdev->bus = kmem_zalloc(sizeof(*pdev->bus), KM_NOSLEEP);
-       pdev->bus->pb_pc = pa->pa_pc;
-       pdev->bus->pb_dev = parent;
-       pdev->bus->number = pa->pa_bus;
-       pdev->devfn = PCI_DEVFN(pa->pa_device, pa->pa_function);
-       pdev->vendor = PCI_VENDOR(pa->pa_id);
-       pdev->device = PCI_PRODUCT(pa->pa_id);
-       pdev->subsystem_vendor = PCI_SUBSYS_VENDOR(subsystem_id);
-       pdev->subsystem_device = PCI_SUBSYS_ID(subsystem_id);
-       pdev->revision = PCI_REVISION(pa->pa_class);
-       pdev->class = __SHIFTOUT(pa->pa_class, 0xffffff00UL); /* ? */
-
-       CTASSERT(__arraycount(pdev->pd_resources) == PCI_NUM_RESOURCES);
-       for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-               const int reg = PCI_BAR(i);
-
-               pdev->pd_resources[i].type = pci_mapreg_type(pa->pa_pc,
-                   pa->pa_tag, reg);
-               if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, reg,
-                       pdev->pd_resources[i].type,
-                       &pdev->pd_resources[i].addr,
-                       &pdev->pd_resources[i].size,
-                       &pdev->pd_resources[i].flags)) {
-                       pdev->pd_resources[i].addr = 0;
-                       pdev->pd_resources[i].size = 0;
-                       pdev->pd_resources[i].flags = 0;
-               }
-               pdev->pd_resources[i].kva = NULL;
-       }
-}
-
-static inline int
-pci_find_capability(struct pci_dev *pdev, int cap)
-{
-       return pci_get_capability(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, cap,
-           NULL, NULL);
-}
-
-static inline int
-pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep)
-{
-       KASSERT(!ISSET(reg, 3));
-       *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg);
-       return 0;
-}
-
-static inline int
-pci_read_config_word(struct pci_dev *pdev, int reg, uint16_t *valuep)
-{
-       KASSERT(!ISSET(reg, 1));
-       *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
-           (reg &~ 2)) >> (8 * (reg & 2));
-       return 0;
-}
-
-static inline int
-pci_read_config_byte(struct pci_dev *pdev, int reg, uint8_t *valuep)
-{
-       *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
-           (reg &~ 3)) >> (8 * (reg & 3));
-       return 0;
-}
-
-static inline int
-pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value)
-{
-       KASSERT(!ISSET(reg, 3));
-       pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, value);
-       return 0;
-}
-
-static inline int
-pci_bus_read_config_dword(struct pci_bus *bus, unsigned devfn, int reg,
-    uint32_t *valuep)
-{
-       pcitag_t tag = pci_make_tag(bus->pb_pc, bus->number, PCI_SLOT(devfn),
-           PCI_FUNC(devfn));
-
-       KASSERT(!ISSET(reg, 1));
-       *valuep = pci_conf_read(bus->pb_pc, tag, reg & ~3) >> (8 * (reg & 3));
-
-       return 0;
-}
-
-static inline int
-pci_bus_read_config_word(struct pci_bus *bus, unsigned devfn, int reg,
-    uint16_t *valuep)
-{
-       pcitag_t tag = pci_make_tag(bus->pb_pc, bus->number, PCI_SLOT(devfn),
-           PCI_FUNC(devfn));
-       KASSERT(!ISSET(reg, 1));
-       *valuep = pci_conf_read(bus->pb_pc, tag, reg &~ 2) >> (8 * (reg & 2));
-       return 0;
-}
-
-static inline int
-pci_bus_read_config_byte(struct pci_bus *bus, unsigned devfn, int reg,
-    uint8_t *valuep)
-{
-       pcitag_t tag = pci_make_tag(bus->pb_pc, bus->number, PCI_SLOT(devfn),
-           PCI_FUNC(devfn));
-       *valuep = pci_conf_read(bus->pb_pc, tag, reg &~ 3) >> (8 * (reg & 3));
-       return 0;
-}
-
-static inline int
-pci_bus_write_config_dword(struct pci_bus *bus, unsigned devfn, int reg,
-    uint32_t value)
-{
-       pcitag_t tag = pci_make_tag(bus->pb_pc, bus->number, PCI_SLOT(devfn),
-           PCI_FUNC(devfn));
-       KASSERT(!ISSET(reg, 3));
-       pci_conf_write(bus->pb_pc, tag, reg, value);
-       return 0;
-}
-
-static inline void
-pci_rmw_config(pci_chipset_tag_t pc, pcitag_t tag, int reg, unsigned int bytes,
-    uint32_t value)
-{
-       const uint32_t mask = ~((~0UL) << (8 * bytes));
-       const int reg32 = (reg &~ 3);
-       const unsigned int shift = (8 * (reg & 3));
-       uint32_t value32;
-
-       KASSERT(bytes <= 4);
-       KASSERT(!ISSET(value, ~mask));
-       value32 = pci_conf_read(pc, tag, reg32);
-       value32 &=~ (mask << shift);
-       value32 |= (value << shift);
-       pci_conf_write(pc, tag, reg32, value32);
-}
-
-static inline int
-pci_write_config_word(struct pci_dev *pdev, int reg, uint16_t value)
-{
-       KASSERT(!ISSET(reg, 1));
-       pci_rmw_config(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, 2, value);
-       return 0;
-}
-
-static inline int
-pci_write_config_byte(struct pci_dev *pdev, int reg, uint8_t value)
-{
-       pci_rmw_config(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, 1, value);
-       return 0;
-}
-
-static inline int
-pci_bus_write_config_word(struct pci_bus *bus, unsigned devfn, int reg,
-    uint16_t value)
-{
-       pcitag_t tag = pci_make_tag(bus->pb_pc, bus->number, PCI_SLOT(devfn),
-           PCI_FUNC(devfn));
-       KASSERT(!ISSET(reg, 1));
-       pci_rmw_config(bus->pb_pc, tag, reg, 2, value);
-       return 0;
-}
-
-static inline int
-pci_bus_write_config_byte(struct pci_bus *bus, unsigned devfn, int reg,
-    uint8_t value)
-{
-       pcitag_t tag = pci_make_tag(bus->pb_pc, bus->number, PCI_SLOT(devfn),
-           PCI_FUNC(devfn));
-       pci_rmw_config(bus->pb_pc, tag, reg, 1, value);
-       return 0;
-}
-
-static inline int
-pci_enable_msi(struct pci_dev *pdev)
-{
-#ifdef notyet
-       const struct pci_attach_args *const pa = &pdev->pd_pa;
-
-       if (pci_msi_alloc_exact(pa, &pdev->pd_intr_handles, 1))
-               return -EINVAL;
-
-       pdev->msi_enabled = 1;
-       return 0;
-#else
-       return -ENOSYS;
-#endif
-}
-
-static inline void
-pci_disable_msi(struct pci_dev *pdev __unused)
-{
-       const struct pci_attach_args *const pa = &pdev->pd_pa;
-
-       if (pdev->pd_intr_handles != NULL) {
-               pci_intr_release(pa->pa_pc, pdev->pd_intr_handles, 1);
-               pdev->pd_intr_handles = NULL;
-       }
-       pdev->msi_enabled = 0;
-}
-
-static inline void
-pci_set_master(struct pci_dev *pdev)
-{
-       pcireg_t csr;
-
-       csr = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
-           PCI_COMMAND_STATUS_REG);
-       csr |= PCI_COMMAND_MASTER_ENABLE;
-       pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
-           PCI_COMMAND_STATUS_REG, csr);
-}
-
-static inline void
-pci_clear_master(struct pci_dev *pdev)
-{
-       pcireg_t csr;
-
-       csr = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
-           PCI_COMMAND_STATUS_REG);
-       csr &= ~(pcireg_t)PCI_COMMAND_MASTER_ENABLE;
-       pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
-           PCI_COMMAND_STATUS_REG, csr);
-}
-
 #define        PCIBIOS_MIN_MEM 0x100000        /* XXX bogus x86 kludge bollocks */
 
-static inline bus_addr_t
-pcibios_align_resource(void *p, const struct resource *resource,
-    bus_addr_t addr, bus_size_t size)
-{
-       panic("pcibios_align_resource has accessed unaligned neurons!");
-}
-
-static inline int
-pci_bus_alloc_resource(struct pci_bus *bus, struct resource *resource,
-    bus_size_t size, bus_size_t align, bus_addr_t start, int type __unused,
-    bus_addr_t (*align_fn)(void *, const struct resource *, bus_addr_t,
-       bus_size_t) __unused,
-    struct pci_dev *pdev)
-{
-       const struct pci_attach_args *const pa = &pdev->pd_pa;
-       bus_space_tag_t bst;
-       int error;
-
-       switch (resource->flags) {
-       case IORESOURCE_MEM:
-               bst = pa->pa_memt;
-               break;
-
-       case IORESOURCE_IO:
-               bst = pa->pa_iot;
-               break;
-
-       default:
-               panic("I don't know what kind of resource you want!");
-       }
-



Home | Main Index | Thread Index | Old Index