summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Skeggs <bskeggs@redhat.com>2015-08-20 14:54:15 +1000
committerBen Skeggs <bskeggs@redhat.com>2015-08-28 12:37:36 +1000
commitb9b0ad3ef8a6c5354c88a2571da6f5a7e790fdbb (patch)
tree6c69ac3d0689124e5c5236b940a2509237578d0a /lib
parent29cdc9107aeb62faf8f9a82229efc8a47303b802 (diff)
downloadnouveau-b9b0ad3ef8a6c5354c88a2571da6f5a7e790fdbb.tar.gz
device: tidy ctor/dtor interfaces
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/main.c44
-rw-r--r--lib/null.c8
-rw-r--r--lib/priv.h3
3 files changed, 31 insertions, 24 deletions
diff --git a/lib/main.c b/lib/main.c
index 3a71da75c..09ff15fab 100644
--- a/lib/main.c
+++ b/lib/main.c
@@ -97,7 +97,7 @@ nvos_ioremap(u64 addr, u64 size)
int i;
list_for_each_entry(odev, &os_device_list, head) {
- struct pci_device *pdev = odev->base.pdev->pdev;
+ struct pci_device *pdev = odev->pdev.pdev;
for (i = 0; i < ARRAY_SIZE(pdev->regions); i++) {
if (addr >= pdev->regions[i].base_addr &&
addr + size <= pdev->regions[i].base_addr +
@@ -134,11 +134,18 @@ nvos_iounmap(void __iomem *ptr)
/******************************************************************************
* client interfaces
*****************************************************************************/
+static void
+os_fini_device(struct os_device *odev)
+{
+ nvkm_device_del(&odev->device);
+ list_del(&odev->head);
+ kfree(odev);
+}
+
static int
os_init_device(struct pci_device *pdev, u64 handle, const char *cfg, const char *dbg)
{
struct os_device *odev;
- struct pci_dev *ldev;
int ret;
ret = pci_device_probe(pdev);
@@ -147,28 +154,28 @@ os_init_device(struct pci_device *pdev, u64 handle, const char *cfg, const char
return ret;
}
- list_for_each_entry(odev, &os_device_list, head) {
- if (odev->base.handle == handle)
- return -EEXIST;
- }
+ odev = calloc(1, sizeof(*odev));
+ if (!odev)
+ return -ENOMEM;
- ldev = malloc(sizeof(*ldev));
- snprintf(ldev->dev.name, sizeof(ldev->dev.name), "%04x:%02x:%02x.%1x",
+ snprintf(odev->pdev.dev.name, sizeof(odev->pdev.dev.name),
+ "%04x:%02x:%02x.%1x",
pdev->domain, pdev->bus, pdev->dev, pdev->func);
- ldev->pdev = pdev;
- ldev->device = pdev->dev;
- ldev->subsystem_vendor = pdev->subvendor_id;
- ldev->subsystem_device = pdev->subdevice_id;
+ odev->pdev.pdev = pdev;
+ odev->pdev.device = pdev->vendor_id;
+ odev->pdev.subsystem_vendor = pdev->subvendor_id;
+ odev->pdev.subsystem_device = pdev->subdevice_id;
+ list_add_tail(&odev->head, &os_device_list);
- ret = nvkm_device_create(ldev, NVKM_BUS_PCI, handle, ldev->dev.name,
- cfg, dbg, &odev);
+ ret = nvkm_device_new(&odev->pdev, NVKM_BUS_PCI, handle,
+ odev->pdev.dev.name, cfg, dbg,
+ &odev->device);
if (ret) {
fprintf(stderr, "failed to create device, %d\n", ret);
- free(ldev);
+ os_fini_device(odev);
return ret;
}
- list_add_tail(&odev->head, &os_device_list);
return 0;
}
@@ -216,10 +223,7 @@ os_fini(void)
struct os_device *odev, *temp;
list_for_each_entry_safe(odev, temp, &os_device_list, head) {
- struct pci_dev *ldev = odev->base.pdev;
- list_del(&odev->head);
- nvkm_object_ref(NULL, (struct nvkm_object **)&odev);
- free(ldev);
+ os_fini_device(odev);
}
pci_system_cleanup();
diff --git a/lib/null.c b/lib/null.c
index 2bb073441..73b9f33f3 100644
--- a/lib/null.c
+++ b/lib/null.c
@@ -48,15 +48,17 @@ null_pci_dev = {
static void
null_fini(void)
{
- nvkm_object_ref(NULL, (struct nvkm_object **)&null_device);
+ nvkm_device_del(&null_device);
}
-static int
+static void
null_init(const char *cfg, const char *dbg, bool init)
{
- return nvkm_device_create(&null_pci_dev, NVKM_BUS_PCI,
+ int ret = nvkm_device_new(&null_pci_dev, NVKM_BUS_PCI,
~0ULL, "0000:00:00.0", cfg, dbg,
&null_device);
+ if (ret)
+ null_fini();
}
static void
diff --git a/lib/priv.h b/lib/priv.h
index cae0acd75..2e4f1039e 100644
--- a/lib/priv.h
+++ b/lib/priv.h
@@ -7,10 +7,11 @@
#include <unistd.h>
struct os_device {
- struct nvkm_device base;
+ struct nvkm_device *device;
struct list_head head;
char *cfg;
char *dbg;
+ struct pci_dev pdev;
};
#endif