Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd/drm2/include/linux Add pci_bus_read/write_c...



details:   https://anonhg.NetBSD.org/src/rev/fda8efb52fd5
branches:  trunk
changeset: 992637:fda8efb52fd5
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 07:20:05 2018 +0000

description:
Add pci_bus_read/write_config_{byte,word,dword}.

diffstat:

 sys/external/bsd/drm2/include/linux/pci.h |  82 ++++++++++++++++++++++++++++--
 1 files changed, 75 insertions(+), 7 deletions(-)

diffs (132 lines):

diff -r 9588c641d7bf -r fda8efb52fd5 sys/external/bsd/drm2/include/linux/pci.h
--- a/sys/external/bsd/drm2/include/linux/pci.h Mon Aug 27 07:19:55 2018 +0000
+++ b/sys/external/bsd/drm2/include/linux/pci.h Mon Aug 27 07:20:05 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci.h,v 1.27 2018/08/27 07:03:02 riastradh Exp $       */
+/*     $NetBSD: pci.h,v 1.28 2018/08/27 07:20:05 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -68,7 +68,8 @@
 struct pci_driver;
 
 struct pci_bus {
-       u_int           number;
+       u_int                   number;
+       pci_chipset_tag_t       pb_pc;
 };
 
 struct pci_device_id {
@@ -195,6 +196,7 @@
 #endif
        pdev->bus = kmem_zalloc(sizeof(struct pci_bus), KM_NOSLEEP);
        pdev->bus->number = pa->pa_bus;
+       pdev->bus->pb_pc = pa->pa_pc;
        pdev->devfn = PCI_DEVFN(pa->pa_device, pa->pa_function);
        pdev->vendor = PCI_VENDOR(pa->pa_id);
        pdev->device = PCI_PRODUCT(pa->pa_id);
@@ -262,8 +264,53 @@
        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(struct pci_dev *pdev, int reg, unsigned int bytes,
+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));
@@ -273,24 +320,45 @@
 
        KASSERT(bytes <= 4);
        KASSERT(!ISSET(value, ~mask));
-       pci_read_config_dword(pdev, reg32, &value32);
+       value32 = pci_conf_read(pc, tag, reg32);
        value32 &=~ (mask << shift);
        value32 |= (value << shift);
-       pci_write_config_dword(pdev, reg32, value32);
+       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, reg, 2, value);
+       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, reg, 1, 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;
 }
 



Home | Main Index | Thread Index | Old Index