summaryrefslogtreecommitdiff
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
parent395156e3e0283a68aef23341d26b42c7362a27d0 (diff)
downloadnouveau-79a8ba77d3d0243e8dca597763aecf43e5bc582e.tar.gz
device: separate construction of pci/tegra devices
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
-rw-r--r--Makefile3
-rw-r--r--drm/nouveau/include/nvif/os.h3
-rw-r--r--drm/nouveau/include/nvkm/core/client.h4
-rw-r--r--drm/nouveau/include/nvkm/core/device.h30
-rw-r--r--drm/nouveau/include/nvkm/core/pci.h14
-rw-r--r--drm/nouveau/include/nvkm/core/tegra.h14
-rw-r--r--drm/nouveau/nouveau_drm.c15
-rw-r--r--drm/nouveau/nvkm/engine/device/Kbuild2
-rw-r--r--drm/nouveau/nvkm/engine/device/base.c104
-rw-r--r--drm/nouveau/nvkm/engine/device/pci.c100
-rw-r--r--drm/nouveau/nvkm/engine/device/priv.h9
-rw-r--r--drm/nouveau/nvkm/engine/device/tegra.c66
-rw-r--r--lib/include/nvif/os.h30
-rw-r--r--lib/main.c40
-rw-r--r--lib/null.c9
15 files changed, 356 insertions, 87 deletions
diff --git a/Makefile b/Makefile
index c003ff4e1..ca54a4dd4 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,8 @@ CFLAGS += -I$(lib)/include -I$(drm)/include -I$(drm)/include/nvkm \
-DCONFIG_NOUVEAU_DEBUG=7 \
-DCONFIG_NOUVEAU_DEBUG_DEFAULT=3 \
-DCONFIG_NOUVEAU_I2C_INTERNAL \
- -DCONFIG_NOUVEAU_I2C_INTERNAL_DEFAULT
+ -DCONFIG_NOUVEAU_I2C_INTERNAL_DEFAULT \
+ -DCONFIG_NOUVEAU_PLATFORM_DRIVER=y
ENVYAS ?= envyas
ENVYPP = $(CC) -E -CC -xc $(1) | $(CC) -E - | sed -e "/^\#/d"
INSTALL ?= install
diff --git a/drm/nouveau/include/nvif/os.h b/drm/nouveau/include/nvif/os.h
index bdd05ee7e..54492cb50 100644
--- a/drm/nouveau/include/nvif/os.h
+++ b/drm/nouveau/include/nvif/os.h
@@ -27,6 +27,8 @@
#include <asm/unaligned.h>
+#include <soc/tegra/fuse.h>
+
#ifndef ioread32_native
#ifdef __BIG_ENDIAN
#define ioread16_native ioread16be
@@ -40,5 +42,4 @@
#define iowrite32_native iowrite32
#endif /* def __BIG_ENDIAN else */
#endif /* !ioread32_native */
-
#endif
diff --git a/drm/nouveau/include/nvkm/core/client.h b/drm/nouveau/include/nvkm/core/client.h
index 977c8a85e..dd0db88f8 100644
--- a/drm/nouveau/include/nvkm/core/client.h
+++ b/drm/nouveau/include/nvkm/core/client.h
@@ -28,7 +28,9 @@ nvkm_client(void *obj)
struct nvkm_object *client = nv_object(obj);
while (client && client->parent)
client = client->parent;
- return (void *)client;
+ if (client && nv_iclass(client, NV_CLIENT_CLASS))
+ return (void *)client;
+ return NULL;
}
int nvkm_client_new(const char *name, u64 device, const char *cfg,
diff --git a/drm/nouveau/include/nvkm/core/device.h b/drm/nouveau/include/nvkm/core/device.h
index 875c247d4..eb843e3ff 100644
--- a/drm/nouveau/include/nvkm/core/device.h
+++ b/drm/nouveau/include/nvkm/core/device.h
@@ -65,22 +65,25 @@ enum nvkm_devidx {
struct nvkm_device {
struct nvkm_engine engine;
+ const struct nvkm_device_func *func;
+ const struct nvkm_device_quirk *quirk;
+ struct device *dev;
+ u64 handle;
+ const char *name;
+ const char *cfgopt;
+ const char *dbgopt;
+
struct list_head head;
struct mutex mutex;
int refcount;
struct pci_dev *pdev;
struct platform_device *platformdev;
- struct device *dev;
- u64 handle;
void __iomem *pri;
struct nvkm_event event;
- const char *cfgopt;
- const char *dbgopt;
- const char *name;
const char *cname;
u64 disable_mask;
@@ -150,6 +153,17 @@ struct nvkm_device {
struct nouveau_platform_gpu *gpu;
};
+struct nvkm_device_func {
+ struct nvkm_device_pci *(*pci)(struct nvkm_device *);
+ struct nvkm_device_tegra *(*tegra)(struct nvkm_device *);
+ void *(*dtor)(struct nvkm_device *);
+ int (*preinit)(struct nvkm_device *);
+ void (*fini)(struct nvkm_device *, bool suspend);
+};
+
+struct nvkm_device_quirk {
+};
+
struct nvkm_device *nvkm_device_find(u64 name);
int nvkm_device_list(u64 *name, int size);
@@ -214,13 +228,7 @@ enum nv_bus_type {
extern struct nvkm_ofuncs nvkm_udevice_ofuncs;
-int nvkm_device_new(void *, enum nv_bus_type type, u64 name,
- const char *sname, const char *cfg, const char *dbg,
- bool detect, bool mmio, u64 subdev_mask,
- struct nvkm_device **);
void nvkm_device_del(struct nvkm_device **);
-int nvkm_device_init(struct nvkm_device *);
-int nvkm_device_fini(struct nvkm_device *, bool suspend);
/* device logging */
#define nvdev_printk_(d,l,p,f,a...) do { \
diff --git a/drm/nouveau/include/nvkm/core/pci.h b/drm/nouveau/include/nvkm/core/pci.h
new file mode 100644
index 000000000..78d41be20
--- /dev/null
+++ b/drm/nouveau/include/nvkm/core/pci.h
@@ -0,0 +1,14 @@
+#ifndef __NVKM_DEVICE_PCI_H__
+#define __NVKM_DEVICE_PCI_H__
+#include <core/device.h>
+
+struct nvkm_device_pci {
+ struct nvkm_device device;
+ struct pci_dev *pdev;
+ bool suspend;
+};
+
+int nvkm_device_pci_new(struct pci_dev *, const char *cfg, const char *dbg,
+ bool detect, bool mmio, u64 subdev_mask,
+ struct nvkm_device **);
+#endif
diff --git a/drm/nouveau/include/nvkm/core/tegra.h b/drm/nouveau/include/nvkm/core/tegra.h
new file mode 100644
index 000000000..162986e7f
--- /dev/null
+++ b/drm/nouveau/include/nvkm/core/tegra.h
@@ -0,0 +1,14 @@
+#ifndef __NVKM_DEVICE_TEGRA_H__
+#define __NVKM_DEVICE_TEGRA_H__
+#include <core/device.h>
+
+struct nvkm_device_tegra {
+ struct nvkm_device device;
+ struct platform_device *pdev;
+};
+
+int nvkm_device_tegra_new(struct platform_device *,
+ const char *cfg, const char *dbg,
+ bool detect, bool mmio, u64 subdev_mask,
+ struct nvkm_device **);
+#endif
diff --git a/drm/nouveau/nouveau_drm.c b/drm/nouveau/nouveau_drm.c
index 37dbd5e1c..e638ae7c0 100644
--- a/drm/nouveau/nouveau_drm.c
+++ b/drm/nouveau/nouveau_drm.c
@@ -32,9 +32,10 @@
#include "drmP.h"
#include "drm_crtc_helper.h"
-#include <core/device.h>
#include <core/gpuobj.h>
#include <core/option.h>
+#include <core/pci.h>
+#include <core/tegra.h>
#include "nouveau_drm.h"
#include "nouveau_dma.h"
@@ -326,9 +327,8 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
remove_conflicting_framebuffers(aper, "nouveaufb", boot);
kfree(aper);
- ret = nvkm_device_new(pdev, NVKM_BUS_PCI, nouveau_pci_name(pdev),
- pci_name(pdev), nouveau_config, nouveau_debug,
- true, true, ~0ULL, &device);
+ ret = nvkm_device_pci_new(pdev, nouveau_config, nouveau_debug,
+ true, true, ~0ULL, &device);
if (ret)
return ret;
@@ -1036,11 +1036,8 @@ nouveau_platform_device_create(struct platform_device *pdev,
struct drm_device *drm;
int err;
- err = nvkm_device_new(pdev, NVKM_BUS_PLATFORM,
- nouveau_platform_name(pdev),
- dev_name(&pdev->dev), nouveau_config,
- nouveau_debug, true, true, ~0ULL,
- pdevice);
+ err = nvkm_device_tegra_new(pdev, nouveau_config, nouveau_debug,
+ true, true, ~0ULL, pdevice);
if (err)
goto err_free;
diff --git a/drm/nouveau/nvkm/engine/device/Kbuild b/drm/nouveau/nvkm/engine/device/Kbuild
index 47c8fe8f9..91110cd25 100644
--- a/drm/nouveau/nvkm/engine/device/Kbuild
+++ b/drm/nouveau/nvkm/engine/device/Kbuild
@@ -1,6 +1,8 @@
nvkm-y += nvkm/engine/device/acpi.o
nvkm-y += nvkm/engine/device/base.o
nvkm-y += nvkm/engine/device/ctrl.o
+nvkm-y += nvkm/engine/device/pci.o
+nvkm-y += nvkm/engine/device/tegra.o
nvkm-y += nvkm/engine/device/user.o
nvkm-y += nvkm/engine/device/nv04.o
diff --git a/drm/nouveau/nvkm/engine/device/base.c b/drm/nouveau/nvkm/engine/device/base.c
index b7892e6f0..c7d8e2902 100644
--- a/drm/nouveau/nvkm/engine/device/base.c
+++ b/drm/nouveau/nvkm/engine/device/base.c
@@ -32,19 +32,25 @@
static DEFINE_MUTEX(nv_devices_mutex);
static LIST_HEAD(nv_devices);
-struct nvkm_device *
-nvkm_device_find(u64 name)
+static struct nvkm_device *
+nvkm_device_find_locked(u64 handle)
{
- struct nvkm_device *device, *match = NULL;
- mutex_lock(&nv_devices_mutex);
+ struct nvkm_device *device;
list_for_each_entry(device, &nv_devices, head) {
- if (device->handle == name) {
- match = device;
- break;
- }
+ if (device->handle == handle)
+ return device;
}
+ return NULL;
+}
+
+struct nvkm_device *
+nvkm_device_find(u64 handle)
+{
+ struct nvkm_device *device;
+ mutex_lock(&nv_devices_mutex);
+ device = nvkm_device_find_locked(handle);
mutex_unlock(&nv_devices_mutex);
- return match;
+ return device;
}
int
@@ -62,6 +68,7 @@ nvkm_device_list(u64 *name, int size)
}
#include <core/parent.h>
+#include <core/client.h>
struct nvkm_device *
nv_device(void *obj)
@@ -70,7 +77,8 @@ nv_device(void *obj)
if (device->engine == NULL) {
while (device && device->parent) {
- if (nv_mclass(device) == 0x0080) {
+ if (!nv_iclass(device, NV_SUBDEV_CLASS) &&
+ device->parent == &nvkm_client(device)->namedb.parent.object) {
struct {
struct nvkm_parent base;
struct nvkm_device *device;
@@ -125,6 +133,9 @@ nvkm_device_fini(struct nvkm_device *device, bool suspend)
}
ret = nvkm_acpi_fini(device, suspend);
+
+ if (device->func->fini)
+ device->func->fini(device, suspend);
fail:
for (; ret && i < NVDEV_SUBDEV_NR; i++) {
if ((subdev = device->subdev[i])) {
@@ -141,11 +152,39 @@ fail:
}
int
+nvkm_device_preinit(struct nvkm_device *device)
+{
+ int ret;
+ s64 time;
+
+ nvdev_trace(device, "preinit running...\n");
+ time = ktime_to_us(ktime_get());
+
+ if (device->func->preinit) {
+ ret = device->func->preinit(device);
+ if (ret)
+ goto fail;
+ }
+
+ time = ktime_to_us(ktime_get()) - time;
+ nvdev_trace(device, "preinit completed in %lldus\n", time);
+ return 0;
+
+fail:
+ nvdev_error(device, "preinit failed with %d\n", ret);
+ return ret;
+}
+
+int
nvkm_device_init(struct nvkm_device *device)
{
struct nvkm_object *subdev;
int ret, i = 0, c;
+ ret = nvkm_device_preinit(device);
+ if (ret)
+ return ret;
+
ret = nvkm_acpi_init(device);
if (ret)
goto fail;
@@ -287,12 +326,6 @@ nv_device_get_irq(struct nvkm_device *device, bool stall)
}
}
-static struct nvkm_oclass
-nvkm_device_oclass = {
- .ofuncs = &(struct nvkm_ofuncs) {
- },
-};
-
void
nvkm_device_del(struct nvkm_device **pdevice)
{
@@ -308,20 +341,28 @@ nvkm_device_del(struct nvkm_device **pdevice)
if (device->pri)
iounmap(device->pri);
list_del(&device->head);
+
+ if (device->func->dtor)
+ *pdevice = device->func->dtor(device);
mutex_unlock(&nv_devices_mutex);
- nvkm_engine_destroy(&device->engine);
+ kfree(*pdevice);
*pdevice = NULL;
}
}
+static const struct nvkm_engine_func
+nvkm_device_func = {
+};
+
int
-nvkm_device_new(void *dev, enum nv_bus_type type, u64 name,
- const char *sname, const char *cfg, const char *dbg,
- bool detect, bool mmio, u64 subdev_mask,
- struct nvkm_device **pdevice)
+nvkm_device_ctor(const struct nvkm_device_func *func,
+ const struct nvkm_device_quirk *quirk,
+ void *dev, enum nv_bus_type type, u64 handle,
+ const char *name, const char *cfg, const char *dbg,
+ bool detect, bool mmio, u64 subdev_mask,
+ struct nvkm_device *device)
{
- struct nvkm_device *device;
u64 mmio_base, mmio_size;
u32 boot0, strap;
void __iomem *map;
@@ -329,17 +370,17 @@ nvkm_device_new(void *dev, enum nv_bus_type type, u64 name,
int i;
mutex_lock(&nv_devices_mutex);
- list_for_each_entry(device, &nv_devices, head) {
- if (device->handle == name)
- goto done;
- }
+ if (nvkm_device_find_locked(handle))
+ goto done;
- ret = nvkm_engine_create(NULL, NULL, &nvkm_device_oclass, true,
- "DEVICE", "device", &device);
- *pdevice = device;
+ ret = nvkm_engine_ctor(&nvkm_device_func, device, 0, 0,
+ true, &device->engine);
+ device->engine.subdev.object.parent = NULL;
+ device->func = func;
if (ret)
goto done;
+ device->quirk = quirk;
switch (type) {
case NVKM_BUS_PCI:
device->pdev = dev;
@@ -350,12 +391,11 @@ nvkm_device_new(void *dev, enum nv_bus_type type, u64 name,
device->dev = &device->platformdev->dev;
break;
}
- device->handle = name;
+ device->handle = handle;
device->cfgopt = cfg;
device->dbgopt = dbg;
- device->name = sname;
+ device->name = name;
- nv_subdev(device)->debug = nvkm_dbgopt(device->dbgopt, "DEVICE");
list_add_tail(&device->head, &nv_devices);
ret = nvkm_event_init(&nvkm_device_event_func, 1, 1, &device->event);
diff --git a/drm/nouveau/nvkm/engine/device/pci.c b/drm/nouveau/nvkm/engine/device/pci.c
new file mode 100644
index 000000000..1a1d1e584
--- /dev/null
+++ b/drm/nouveau/nvkm/engine/device/pci.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2015 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Ben Skeggs <bskeggs@redhat.com>
+ */
+#include <core/pci.h>
+#include "priv.h"
+
+static struct nvkm_device_pci *
+nvkm_device_pci(struct nvkm_device *device)
+{
+ return container_of(device, struct nvkm_device_pci, device);
+}
+
+static void
+nvkm_device_pci_fini(struct nvkm_device *device, bool suspend)
+{
+ struct nvkm_device_pci *pdev = nvkm_device_pci(device);
+ if (suspend) {
+ pci_disable_device(pdev->pdev);
+ pdev->suspend = true;
+ }
+}
+
+static int
+nvkm_device_pci_preinit(struct nvkm_device *device)
+{
+ struct nvkm_device_pci *pdev = nvkm_device_pci(device);
+ if (pdev->suspend) {
+ int ret = pci_enable_device(pdev->pdev);
+ if (ret)
+ return ret;
+ pci_set_master(pdev->pdev);
+ pdev->suspend = false;
+ }
+ return 0;
+}
+
+static void *
+nvkm_device_pci_dtor(struct nvkm_device *device)
+{
+ struct nvkm_device_pci *pdev = nvkm_device_pci(device);
+ pci_disable_device(pdev->pdev);
+ return pdev;
+}
+
+static const struct nvkm_device_func
+nvkm_device_pci_func = {
+ .pci = nvkm_device_pci,
+ .dtor = nvkm_device_pci_dtor,
+ .preinit = nvkm_device_pci_preinit,
+ .fini = nvkm_device_pci_fini,
+};
+
+int
+nvkm_device_pci_new(struct pci_dev *pci_dev, const char *cfg, const char *dbg,
+ bool detect, bool mmio, u64 subdev_mask,
+ struct nvkm_device **pdevice)
+{
+ struct nvkm_device_pci *pdev;
+ int ret;
+
+ ret = pci_enable_device(pci_dev);
+ if (ret)
+ return ret;
+
+ if (!(pdev = kzalloc(sizeof(*pdev), GFP_KERNEL))) {
+ pci_disable_device(pci_dev);
+ return -ENOMEM;
+ }
+ *pdevice = &pdev->device;
+ pdev->pdev = pci_dev;
+
+ return nvkm_device_ctor(&nvkm_device_pci_func, NULL,
+ pci_dev, NVKM_BUS_PCI,
+ (u64)pci_domain_nr(pci_dev->bus) << 32 |
+ pci_dev->bus->number << 16 |
+ PCI_SLOT(pci_dev->devfn) << 8 |
+ PCI_FUNC(pci_dev->devfn), NULL,
+ cfg, dbg, detect, mmio, subdev_mask,
+ &pdev->device);
+}
diff --git a/drm/nouveau/nvkm/engine/device/priv.h b/drm/nouveau/nvkm/engine/device/priv.h
index 8d3590e7b..df9c15503 100644
--- a/drm/nouveau/nvkm/engine/device/priv.h
+++ b/drm/nouveau/nvkm/engine/device/priv.h
@@ -2,6 +2,15 @@
#define __NVKM_DEVICE_PRIV_H__
#include <core/device.h>
+int nvkm_device_ctor(const struct nvkm_device_func *,
+ const struct nvkm_device_quirk *,
+ void *, enum nv_bus_type type, u64 handle,
+ const char *name, const char *cfg, const char *dbg,
+ bool detect, bool mmio, u64 subdev_mask,
+ struct nvkm_device *);
+int nvkm_device_init(struct nvkm_device *);
+int nvkm_device_fini(struct nvkm_device *, bool suspend);
+
extern struct nvkm_oclass nvkm_control_oclass[];
int nv04_identify(struct nvkm_device *);
diff --git a/drm/nouveau/nvkm/engine/device/tegra.c b/drm/nouveau/nvkm/engine/device/tegra.c
new file mode 100644
index 000000000..0a5e5b88f
--- /dev/null
+++ b/drm/nouveau/nvkm/engine/device/tegra.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2015 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Ben Skeggs <bskeggs@redhat.com>
+ */
+#include <core/tegra.h>
+#ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER
+#include "priv.h"
+
+static struct nvkm_device_tegra *
+nvkm_device_tegra(struct nvkm_device *obj)
+{
+ return container_of(obj, struct nvkm_device_tegra, device);
+}
+
+static const struct nvkm_device_func
+nvkm_device_tegra_func = {
+ .tegra = nvkm_device_tegra,
+};
+
+int
+nvkm_device_tegra_new(struct platform_device *pdev,
+ const char *cfg, const char *dbg,
+ bool detect, bool mmio, u64 subdev_mask,
+ struct nvkm_device **pdevice)
+{
+ struct nvkm_device_tegra *tdev;
+
+ if (!(tdev = kzalloc(sizeof(*tdev), GFP_KERNEL)))
+ return -ENOMEM;
+ *pdevice = &tdev->device;
+ tdev->pdev = pdev;
+
+ return nvkm_device_ctor(&nvkm_device_tegra_func, NULL, pdev,
+ NVKM_BUS_PLATFORM, pdev->id, NULL,
+ cfg, dbg, detect, mmio, subdev_mask,
+ &tdev->device);
+}
+#else
+int
+nvkm_device_tegra_new(struct platform_device *pdev,
+ const char *cfg, const char *dbg,
+ bool detect, bool mmio, u64 subdev_mask,
+ struct nvkm_device **pdevice)
+{
+ return -ENOSYS;
+}
+#endif
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();
}