summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Skeggs <bskeggs@redhat.com>2015-08-20 14:54:17 +1000
committerBen Skeggs <bskeggs@redhat.com>2015-08-28 12:37:38 +1000
commit79a8ba77d3d0243e8dca597763aecf43e5bc582e (patch)
treecab0babde59409caf45789632a78f801a265bbe8 /lib
parent395156e3e0283a68aef23341d26b42c7362a27d0 (diff)
downloadnouveau-79a8ba77d3d0243e8dca597763aecf43e5bc582e.tar.gz
device: separate construction of pci/tegra devices
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/include/nvif/os.h30
-rw-r--r--lib/main.c40
-rw-r--r--lib/null.c9
3 files changed, 47 insertions, 32 deletions
diff --git a/lib/include/nvif/os.h b/lib/include/nvif/os.h
index e1bb3b9e7..30f03cc9e 100644
--- a/lib/include/nvif/os.h
+++ b/lib/include/nvif/os.h
@@ -783,6 +783,11 @@ iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
#define PCI_CAP_ID_AGP 0x02
+struct pci_bus {
+ u16 domain;
+ u8 number;
+};
+
struct pci_dev {
struct pci_device *pdev;
struct device dev;
@@ -790,8 +795,27 @@ struct pci_dev {
u16 subsystem_vendor;
u16 subsystem_device;
int irq;
+ struct pci_bus _bus;
+ struct pci_bus *bus;
+ u8 devfn;
};
+static inline void
+pci_disable_device(struct pci_dev *pdev)
+{
+}
+
+static inline int
+pci_enable_device(struct pci_dev *pdev)
+{
+ return 0;
+}
+
+static inline void
+pci_set_master(struct pci_dev *pdev)
+{
+}
+
static inline struct device_node *
pci_device_to_OF_node(const struct pci_dev *pdev)
{
@@ -909,7 +933,10 @@ pci_disable_msi(struct pci_dev *pdev)
{
}
-#define PCI_DEVFN(a,b) 0
+#define PCI_DEVFN(a,b) (((a) << 3) | (b))
+#define PCI_SLOT(a) ((a) >> 3)
+#define PCI_FUNC(a) ((a) & 0x07)
+#define pci_domain_nr(a) (a)->domain
#define pci_get_bus_and_slot(a, b) NULL
#define pci_read_config_dword(a,b,c) *(c) = 0
@@ -919,6 +946,7 @@ pci_disable_msi(struct pci_dev *pdev)
struct platform_device {
struct device dev;
+ u64 id;
};
static inline struct resource *
diff --git a/lib/main.c b/lib/main.c
index 0102a7768..4103b0831 100644
--- a/lib/main.c
+++ b/lib/main.c
@@ -29,15 +29,10 @@
#include <nvif/class.h>
#include <nvif/event.h>
-#include <core/object.h>
-#include <core/handle.h>
-#include <core/client.h>
-#include <core/device.h>
+#include <core/pci.h>
#include <core/ioctl.h>
#include <core/event.h>
-#include <subdev/mc.h>
-
#include "priv.h"
static DEFINE_MUTEX(os_mutex);
@@ -147,7 +142,7 @@ os_fini_device(struct os_device *odev)
}
static int
-os_init_device(struct pci_device *pdev, u64 handle, const char *cfg, const char *dbg)
+os_init_device(struct pci_device *pdev, const char *cfg, const char *dbg)
{
struct os_device *odev;
int ret;
@@ -169,12 +164,15 @@ os_init_device(struct pci_device *pdev, u64 handle, const char *cfg, const char
odev->pdev.device = pdev->vendor_id;
odev->pdev.subsystem_vendor = pdev->subvendor_id;
odev->pdev.subsystem_device = pdev->subdevice_id;
+ odev->pdev._bus.domain = pdev->domain;
+ odev->pdev._bus.number = pdev->bus;
+ odev->pdev.bus = &odev->pdev._bus;
+ odev->pdev.devfn = PCI_DEVFN(pdev->dev, pdev->func);
list_add_tail(&odev->head, &os_device_list);
- ret = nvkm_device_new(&odev->pdev, NVKM_BUS_PCI, handle,
- odev->pdev.dev.name, cfg, dbg,
- os_device_detect, os_device_mmio,
- os_device_subdev, &odev->device);
+ ret = nvkm_device_pci_new(&odev->pdev, cfg, dbg, os_device_detect,
+ os_device_mmio, os_device_subdev,
+ &odev->device);
if (ret) {
fprintf(stderr, "failed to create device, %d\n", ret);
os_fini_device(odev);
@@ -185,12 +183,11 @@ os_init_device(struct pci_device *pdev, u64 handle, const char *cfg, const char
}
static int
-os_init(const char *cfg, const char *dbg, bool init)
+os_init(const char *cfg, const char *dbg)
{
struct pci_device_iterator *iter;
struct pci_device *pdev;
- u64 handle;
- int ret, n = 0;
+ int ret;
ret = pci_system_init();
if (ret) {
@@ -205,18 +202,7 @@ os_init(const char *cfg, const char *dbg, bool init)
if (pdev->vendor_id != 0x10de)
continue;
- handle = ((u64)pdev->domain << 32) | (pdev->bus << 16) |
- (pdev->dev << 8) | pdev->func;
-
- if (!init) {
- printf("%d: 0x%010llx PCI:%04x:%02x:%02x:%02x "
- "(%04x:%04x)\n", n++, handle, pdev->domain,
- pdev->bus, pdev->dev, pdev->func,
- pdev->vendor_id, pdev->device_id);
- continue;
- }
-
- os_init_device(pdev, handle, cfg, dbg);
+ os_init_device(pdev, cfg, dbg);
}
pci_iterator_destroy(iter);
return 0;
@@ -286,7 +272,7 @@ os_client_init(const char *name, u64 device, const char *cfg,
mutex_lock(&os_mutex);
if (os_client_nr++ == 0)
- os_init(cfg, dbg, true);
+ os_init(cfg, dbg);
mutex_unlock(&os_mutex);
ret = nvkm_client_new(name, device, cfg, dbg, &client);
diff --git a/lib/null.c b/lib/null.c
index 5a7b7f9ae..f9b4b1332 100644
--- a/lib/null.c
+++ b/lib/null.c
@@ -30,6 +30,7 @@
#include <nvif/event.h>
#include <core/ioctl.h>
+#include <core/pci.h>
#include "priv.h"
@@ -43,6 +44,7 @@ null_pci_dev = {
},
.pdev = &(struct pci_device) {
},
+ .bus = &null_pci_dev._bus,
};
static void
@@ -54,10 +56,9 @@ null_fini(void)
static void
null_init(const char *cfg, const char *dbg, bool init)
{
- int ret = nvkm_device_new(&null_pci_dev, NVKM_BUS_PCI,
- ~0ULL, "0000:00:00.0", cfg, dbg,
- os_device_detect, os_device_mmio,
- os_device_subdev, &null_device);
+ int ret = nvkm_device_pci_new(&null_pci_dev, cfg, dbg, os_device_detect,
+ os_device_mmio, os_device_subdev,
+ &null_device);
if (ret)
null_fini();
}