Commit b7072b24 authored by Todd Poynor's avatar Todd Poynor Committed by Greg Kroah-Hartman

staging: gasket: core: move core PCI calls to device drivers

Remove gasket wrapping of PCI probe, enable, disable, and remove
functions.  Replace with calls to add and remove PCI gasket devices,
to be called by the gasket device drivers.
Signed-off-by: default avatarTodd Poynor <toddpoynor@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a81d6789
...@@ -51,9 +51,6 @@ struct gasket_internal_desc { ...@@ -51,9 +51,6 @@ struct gasket_internal_desc {
/* Kernel-internal device class. */ /* Kernel-internal device class. */
struct class *class; struct class *class;
/* PCI subsystem metadata associated with this driver. */
struct pci_driver pci;
/* Instantiated / present devices of this type. */ /* Instantiated / present devices of this type. */
struct gasket_dev *devs[GASKET_DEV_MAX]; struct gasket_dev *devs[GASKET_DEV_MAX];
}; };
...@@ -368,10 +365,10 @@ static void gasket_unmap_pci_bar(struct gasket_dev *dev, int bar_num) ...@@ -368,10 +365,10 @@ static void gasket_unmap_pci_bar(struct gasket_dev *dev, int bar_num)
} }
/* /*
* Setup PCI & set up memory mapping for the specified device. * Setup PCI memory mapping for the specified device.
* *
* Enables the PCI device, reads the BAR registers and sets up pointers to the * Reads the BAR registers and sets up pointers to the device's memory mapped
* device's memory mapped IO space. * IO space.
* *
* Returns 0 on success and a negative value otherwise. * Returns 0 on success and a negative value otherwise.
*/ */
...@@ -380,14 +377,6 @@ static int gasket_setup_pci(struct pci_dev *pci_dev, ...@@ -380,14 +377,6 @@ static int gasket_setup_pci(struct pci_dev *pci_dev,
{ {
int i, mapped_bars, ret; int i, mapped_bars, ret;
ret = pci_enable_device(pci_dev);
if (ret) {
dev_err(gasket_dev->dev, "cannot enable PCI device\n");
return ret;
}
pci_set_master(pci_dev);
for (i = 0; i < GASKET_NUM_BARS; i++) { for (i = 0; i < GASKET_NUM_BARS; i++) {
ret = gasket_map_pci_bar(gasket_dev, i); ret = gasket_map_pci_bar(gasket_dev, i);
if (ret) { if (ret) {
...@@ -402,19 +391,16 @@ static int gasket_setup_pci(struct pci_dev *pci_dev, ...@@ -402,19 +391,16 @@ static int gasket_setup_pci(struct pci_dev *pci_dev,
for (i = 0; i < mapped_bars; i++) for (i = 0; i < mapped_bars; i++)
gasket_unmap_pci_bar(gasket_dev, i); gasket_unmap_pci_bar(gasket_dev, i);
pci_disable_device(pci_dev);
return -ENOMEM; return -ENOMEM;
} }
/* Unmaps memory and cleans up PCI for the specified device. */ /* Unmaps memory for the specified device. */
static void gasket_cleanup_pci(struct gasket_dev *gasket_dev) static void gasket_cleanup_pci(struct gasket_dev *gasket_dev)
{ {
int i; int i;
for (i = 0; i < GASKET_NUM_BARS; i++) for (i = 0; i < GASKET_NUM_BARS; i++)
gasket_unmap_pci_bar(gasket_dev, i); gasket_unmap_pci_bar(gasket_dev, i);
pci_disable_device(gasket_dev->pci_dev);
} }
/* Determine the health of the Gasket device. */ /* Determine the health of the Gasket device. */
...@@ -1443,15 +1429,14 @@ static int gasket_enable_dev(struct gasket_internal_desc *internal_desc, ...@@ -1443,15 +1429,14 @@ static int gasket_enable_dev(struct gasket_internal_desc *internal_desc,
} }
/* /*
* PCI subsystem probe function. * Add PCI gasket device.
*
* Called when a Gasket device is found. Allocates device metadata, maps device
* memory, and calls gasket_enable_dev to prepare the device for active use.
* *
* Returns 0 if successful and a negative value otherwise. * Called by Gasket device probe function.
* Allocates device metadata, maps device memory, and calls gasket_enable_dev
* to prepare the device for active use.
*/ */
static int gasket_pci_probe(struct pci_dev *pci_dev, int gasket_pci_add_device(struct pci_dev *pci_dev,
const struct pci_device_id *id) struct gasket_dev **gasket_devp)
{ {
int ret; int ret;
const char *kobj_name = dev_name(&pci_dev->dev); const char *kobj_name = dev_name(&pci_dev->dev);
...@@ -1460,13 +1445,14 @@ static int gasket_pci_probe(struct pci_dev *pci_dev, ...@@ -1460,13 +1445,14 @@ static int gasket_pci_probe(struct pci_dev *pci_dev,
const struct gasket_driver_desc *driver_desc; const struct gasket_driver_desc *driver_desc;
struct device *parent; struct device *parent;
pr_info("Add Gasket device %s\n", kobj_name); pr_debug("add PCI device %s\n", kobj_name);
mutex_lock(&g_mutex); mutex_lock(&g_mutex);
internal_desc = lookup_internal_desc(pci_dev); internal_desc = lookup_internal_desc(pci_dev);
mutex_unlock(&g_mutex); mutex_unlock(&g_mutex);
if (!internal_desc) { if (!internal_desc) {
pr_err("PCI probe called for unknown driver type\n"); dev_err(&pci_dev->dev,
"PCI add device called for unknown driver type\n");
return -ENODEV; return -ENODEV;
} }
...@@ -1530,6 +1516,7 @@ static int gasket_pci_probe(struct pci_dev *pci_dev, ...@@ -1530,6 +1516,7 @@ static int gasket_pci_probe(struct pci_dev *pci_dev,
goto fail5; goto fail5;
} }
*gasket_devp = gasket_dev;
return 0; return 0;
fail5: fail5:
...@@ -1545,14 +1532,10 @@ static int gasket_pci_probe(struct pci_dev *pci_dev, ...@@ -1545,14 +1532,10 @@ static int gasket_pci_probe(struct pci_dev *pci_dev,
gasket_free_dev(gasket_dev); gasket_free_dev(gasket_dev);
return ret; return ret;
} }
EXPORT_SYMBOL(gasket_pci_add_device);
/* /* Remove a PCI gasket device. */
* PCI subsystem remove function. void gasket_pci_remove_device(struct pci_dev *pci_dev)
*
* Called to remove a Gasket device. Finds the device in the device list and
* cleans up metadata.
*/
static void gasket_pci_remove(struct pci_dev *pci_dev)
{ {
int i; int i;
struct gasket_internal_desc *internal_desc; struct gasket_internal_desc *internal_desc;
...@@ -1583,8 +1566,8 @@ static void gasket_pci_remove(struct pci_dev *pci_dev) ...@@ -1583,8 +1566,8 @@ static void gasket_pci_remove(struct pci_dev *pci_dev)
if (!gasket_dev) if (!gasket_dev)
return; return;
pr_info("remove %s device %s\n", internal_desc->driver_desc->name, dev_dbg(gasket_dev->dev, "remove %s PCI gasket device\n",
gasket_dev->kobj_name); internal_desc->driver_desc->name);
gasket_disable_dev(gasket_dev); gasket_disable_dev(gasket_dev);
gasket_cleanup_pci(gasket_dev); gasket_cleanup_pci(gasket_dev);
...@@ -1597,6 +1580,7 @@ static void gasket_pci_remove(struct pci_dev *pci_dev) ...@@ -1597,6 +1580,7 @@ static void gasket_pci_remove(struct pci_dev *pci_dev)
device_destroy(internal_desc->class, gasket_dev->dev_info.devt); device_destroy(internal_desc->class, gasket_dev->dev_info.devt);
gasket_free_dev(gasket_dev); gasket_free_dev(gasket_dev);
} }
EXPORT_SYMBOL(gasket_pci_remove_device);
/** /**
* Lookup a name by number in a num_name table. * Lookup a name by number in a num_name table.
...@@ -1770,11 +1754,6 @@ int gasket_register_device(const struct gasket_driver_desc *driver_desc) ...@@ -1770,11 +1754,6 @@ int gasket_register_device(const struct gasket_driver_desc *driver_desc)
internal = &g_descs[desc_idx]; internal = &g_descs[desc_idx];
mutex_init(&internal->mutex); mutex_init(&internal->mutex);
memset(internal->devs, 0, sizeof(struct gasket_dev *) * GASKET_DEV_MAX); memset(internal->devs, 0, sizeof(struct gasket_dev *) * GASKET_DEV_MAX);
memset(&internal->pci, 0, sizeof(internal->pci));
internal->pci.name = driver_desc->name;
internal->pci.id_table = driver_desc->pci_id_table;
internal->pci.probe = gasket_pci_probe;
internal->pci.remove = gasket_pci_remove;
internal->class = internal->class =
class_create(driver_desc->module, driver_desc->name); class_create(driver_desc->module, driver_desc->name);
...@@ -1785,33 +1764,18 @@ int gasket_register_device(const struct gasket_driver_desc *driver_desc) ...@@ -1785,33 +1764,18 @@ int gasket_register_device(const struct gasket_driver_desc *driver_desc)
goto unregister_gasket_driver; goto unregister_gasket_driver;
} }
/*
* Not using pci_register_driver() (without underscores), as it
* depends on KBUILD_MODNAME, and this is a shared file.
*/
ret = __pci_register_driver(&internal->pci, driver_desc->module,
driver_desc->name);
if (ret) {
pr_err("cannot register %s pci driver [ret=%d]\n",
driver_desc->name, ret);
goto fail1;
}
ret = register_chrdev_region(MKDEV(driver_desc->major, ret = register_chrdev_region(MKDEV(driver_desc->major,
driver_desc->minor), GASKET_DEV_MAX, driver_desc->minor), GASKET_DEV_MAX,
driver_desc->name); driver_desc->name);
if (ret) { if (ret) {
pr_err("cannot register %s char driver [ret=%d]\n", pr_err("cannot register %s char driver [ret=%d]\n",
driver_desc->name, ret); driver_desc->name, ret);
goto fail2; goto destroy_class;
} }
return 0; return 0;
fail2: destroy_class:
pci_unregister_driver(&internal->pci);
fail1:
class_destroy(internal->class); class_destroy(internal->class);
unregister_gasket_driver: unregister_gasket_driver:
...@@ -1848,8 +1812,6 @@ void gasket_unregister_device(const struct gasket_driver_desc *driver_desc) ...@@ -1848,8 +1812,6 @@ void gasket_unregister_device(const struct gasket_driver_desc *driver_desc)
unregister_chrdev_region(MKDEV(driver_desc->major, driver_desc->minor), unregister_chrdev_region(MKDEV(driver_desc->major, driver_desc->minor),
GASKET_DEV_MAX); GASKET_DEV_MAX);
pci_unregister_driver(&internal_desc->pci);
class_destroy(internal_desc->class); class_destroy(internal_desc->class);
/* Finally, effectively "remove" the driver. */ /* Finally, effectively "remove" the driver. */
......
...@@ -607,6 +607,12 @@ int gasket_register_device(const struct gasket_driver_desc *desc); ...@@ -607,6 +607,12 @@ int gasket_register_device(const struct gasket_driver_desc *desc);
*/ */
void gasket_unregister_device(const struct gasket_driver_desc *desc); void gasket_unregister_device(const struct gasket_driver_desc *desc);
/* Add a PCI gasket device. */
int gasket_pci_add_device(struct pci_dev *pci_dev,
struct gasket_dev **gasket_devp);
/* Remove a PCI gasket device. */
void gasket_pci_remove_device(struct pci_dev *pci_dev);
/* /*
* Reset the Gasket device. * Reset the Gasket device.
* @gasket_dev: Gasket device struct. * @gasket_dev: Gasket device struct.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment