nfs: new subdir Documentation/filesystems/nfs
[safe/jmp/linux-2.6] / drivers / pnp / core.c
index 1dfdc32..5dba909 100644 (file)
@@ -2,7 +2,6 @@
  * core.c - contains all core device and protocol registration functions
  *
  * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
- *
  */
 
 #include <linux/pnp.h>
@@ -48,15 +47,11 @@ void *pnp_alloc(long size)
  *
  *  Ex protocols: ISAPNP, PNPBIOS, etc
  */
-
 int pnp_register_protocol(struct pnp_protocol *protocol)
 {
        int nodenum;
        struct list_head *pos;
 
-       if (!protocol)
-               return -EINVAL;
-
        INIT_LIST_HEAD(&protocol->devices);
        INIT_LIST_HEAD(&protocol->cards);
        nodenum = 0;
@@ -75,14 +70,13 @@ int pnp_register_protocol(struct pnp_protocol *protocol)
        spin_unlock(&pnp_lock);
 
        protocol->number = nodenum;
-       sprintf(protocol->dev.bus_id, "pnp%d", nodenum);
+       dev_set_name(&protocol->dev, "pnp%d", nodenum);
        return device_register(&protocol->dev);
 }
 
 /**
  * pnp_protocol_unregister - removes a pnp protocol from the pnp layer
  * @protocol: pointer to the corresponding pnp_protocol structure
- *
  */
 void pnp_unregister_protocol(struct pnp_protocol *protocol)
 {
@@ -96,8 +90,7 @@ static void pnp_free_ids(struct pnp_dev *dev)
 {
        struct pnp_id *id;
        struct pnp_id *next;
-       if (!dev)
-               return;
+
        id = dev->id;
        while (id) {
                next = id->next;
@@ -106,33 +99,72 @@ static void pnp_free_ids(struct pnp_dev *dev)
        }
 }
 
+void pnp_free_resource(struct pnp_resource *pnp_res)
+{
+       list_del(&pnp_res->list);
+       kfree(pnp_res);
+}
+
+void pnp_free_resources(struct pnp_dev *dev)
+{
+       struct pnp_resource *pnp_res, *tmp;
+
+       list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) {
+               pnp_free_resource(pnp_res);
+       }
+}
+
 static void pnp_release_device(struct device *dmdev)
 {
        struct pnp_dev *dev = to_pnp_dev(dmdev);
-       pnp_free_option(dev->independent);
-       pnp_free_option(dev->dependent);
+
        pnp_free_ids(dev);
+       pnp_free_resources(dev);
+       pnp_free_options(dev);
        kfree(dev);
 }
 
-int __pnp_add_device(struct pnp_dev *dev)
+struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid)
 {
-       int ret;
-       pnp_fixup_device(dev);
+       struct pnp_dev *dev;
+       struct pnp_id *dev_id;
+
+       dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
+       if (!dev)
+               return NULL;
+
+       INIT_LIST_HEAD(&dev->resources);
+       INIT_LIST_HEAD(&dev->options);
+       dev->protocol = protocol;
+       dev->number = id;
+       dev->dma_mask = DMA_BIT_MASK(24);
+
+       dev->dev.parent = &dev->protocol->dev;
        dev->dev.bus = &pnp_bus_type;
        dev->dev.dma_mask = &dev->dma_mask;
-       dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK;
+       dev->dev.coherent_dma_mask = dev->dma_mask;
        dev->dev.release = &pnp_release_device;
+
+       dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
+
+       dev_id = pnp_add_id(dev, pnpid);
+       if (!dev_id) {
+               kfree(dev);
+               return NULL;
+       }
+
+       return dev;
+}
+
+int __pnp_add_device(struct pnp_dev *dev)
+{
+       pnp_fixup_device(dev);
        dev->status = PNP_READY;
        spin_lock(&pnp_lock);
        list_add_tail(&dev->global_list, &pnp_global);
        list_add_tail(&dev->protocol_list, &dev->protocol->devices);
        spin_unlock(&pnp_lock);
-
-       ret = device_register(&dev->dev);
-       if (ret == 0)
-               pnp_interface_attach_device(dev);
-       return ret;
+       return device_register(&dev->dev);
 }
 
 /*
@@ -141,15 +173,27 @@ int __pnp_add_device(struct pnp_dev *dev)
  *
  *  adds to driver model, name database, fixups, interface, etc.
  */
-
 int pnp_add_device(struct pnp_dev *dev)
 {
-       if (!dev || !dev->protocol || dev->card)
+       int ret;
+       char buf[128];
+       int len = 0;
+       struct pnp_id *id;
+
+       if (dev->card)
                return -EINVAL;
-       dev->dev.parent = &dev->protocol->dev;
-       sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
-               dev->number);
-       return __pnp_add_device(dev);
+
+       ret = __pnp_add_device(dev);
+       if (ret)
+               return ret;
+
+       buf[0] = '\0';
+       for (id = dev->id; id; id = id->next)
+               len += scnprintf(buf + len, sizeof(buf) - len, " %s", id->id);
+
+       pnp_dbg(&dev->dev, "%s device, IDs%s (%s)\n",
+               dev->protocol->name, buf, dev->active ? "active" : "disabled");
+       return 0;
 }
 
 void __pnp_remove_device(struct pnp_dev *dev)
@@ -161,32 +205,20 @@ void __pnp_remove_device(struct pnp_dev *dev)
        device_unregister(&dev->dev);
 }
 
-/**
- * pnp_remove_device - removes a pnp device from the pnp layer
- * @dev: pointer to dev to add
- *
- * this function will free all mem used by dev
- */
-#if 0
-void pnp_remove_device(struct pnp_dev *dev)
-{
-       if (!dev || dev->card)
-               return;
-       __pnp_remove_device(dev);
-}
-#endif /*  0  */
-
 static int __init pnp_init(void)
 {
-       printk(KERN_INFO "Linux Plug and Play Support v0.97 (c) Adam Belay\n");
        return bus_register(&pnp_bus_type);
 }
 
 subsys_initcall(pnp_init);
 
-#if 0
-EXPORT_SYMBOL(pnp_register_protocol);
-EXPORT_SYMBOL(pnp_unregister_protocol);
-EXPORT_SYMBOL(pnp_add_device);
-EXPORT_SYMBOL(pnp_remove_device);
-#endif /*  0  */
+int pnp_debug;
+
+#if defined(CONFIG_PNP_DEBUG_MESSAGES)
+static int __init pnp_debug_setup(char *__unused)
+{
+       pnp_debug = 1;
+       return 1;
+}
+__setup("pnp.debug", pnp_debug_setup);
+#endif