Commit 5e655772 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by Linus Torvalds
Browse files

[PATCH] openfirmware: generate device table for userspace

This converts the usage of struct of_match to struct of_device_id,
similar to pci_device_id.  This allows a device table to be generated,
which can be parsed by depmod(8) to generate a map file for module
loading.

In order for hotplug to work with macio devices, patches to
module-init-tools and hotplug must be applied.  Those patches are
available at:

 ftp://ftp.suse.com/pub/people/jeffm/linux/macio-hotplug/

Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 159f597a
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <asm/errno.h> #include <asm/errno.h>
#include <asm/of_device.h> #include <asm/of_device.h>
...@@ -15,20 +16,20 @@ ...@@ -15,20 +16,20 @@
* Used by a driver to check whether an of_device present in the * Used by a driver to check whether an of_device present in the
* system is in its list of supported devices. * system is in its list of supported devices.
*/ */
const struct of_match * of_match_device(const struct of_match *matches, const struct of_device_id * of_match_device(const struct of_device_id *matches,
const struct of_device *dev) const struct of_device *dev)
{ {
if (!dev->node) if (!dev->node)
return NULL; return NULL;
while (matches->name || matches->type || matches->compatible) { while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
int match = 1; int match = 1;
if (matches->name && matches->name != OF_ANY_MATCH) if (matches->name[0])
match &= dev->node->name match &= dev->node->name
&& !strcmp(matches->name, dev->node->name); && !strcmp(matches->name, dev->node->name);
if (matches->type && matches->type != OF_ANY_MATCH) if (matches->type[0])
match &= dev->node->type match &= dev->node->type
&& !strcmp(matches->type, dev->node->type); && !strcmp(matches->type, dev->node->type);
if (matches->compatible && matches->compatible != OF_ANY_MATCH) if (matches->compatible[0])
match &= device_is_compatible(dev->node, match &= device_is_compatible(dev->node,
matches->compatible); matches->compatible);
if (match) if (match)
...@@ -42,7 +43,7 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv) ...@@ -42,7 +43,7 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
{ {
struct of_device * of_dev = to_of_device(dev); struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * of_drv = to_of_platform_driver(drv); struct of_platform_driver * of_drv = to_of_platform_driver(drv);
const struct of_match * matches = of_drv->match_table; const struct of_device_id * matches = of_drv->match_table;
if (!matches) if (!matches)
return 0; return 0;
...@@ -75,7 +76,7 @@ static int of_device_probe(struct device *dev) ...@@ -75,7 +76,7 @@ static int of_device_probe(struct device *dev)
int error = -ENODEV; int error = -ENODEV;
struct of_platform_driver *drv; struct of_platform_driver *drv;
struct of_device *of_dev; struct of_device *of_dev;
const struct of_match *match; const struct of_device_id *match;
drv = to_of_platform_driver(dev->driver); drv = to_of_platform_driver(dev->driver);
of_dev = to_of_device(dev); of_dev = to_of_device(dev);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <asm/errno.h> #include <asm/errno.h>
#include <asm/of_device.h> #include <asm/of_device.h>
...@@ -15,20 +16,20 @@ ...@@ -15,20 +16,20 @@
* Used by a driver to check whether an of_device present in the * Used by a driver to check whether an of_device present in the
* system is in its list of supported devices. * system is in its list of supported devices.
*/ */
const struct of_match * of_match_device(const struct of_match *matches, const struct of_device_id *of_match_device(const struct of_device_id *matches,
const struct of_device *dev) const struct of_device *dev)
{ {
if (!dev->node) if (!dev->node)
return NULL; return NULL;
while (matches->name || matches->type || matches->compatible) { while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
int match = 1; int match = 1;
if (matches->name && matches->name != OF_ANY_MATCH) if (matches->name[0])
match &= dev->node->name match &= dev->node->name
&& !strcmp(matches->name, dev->node->name); && !strcmp(matches->name, dev->node->name);
if (matches->type && matches->type != OF_ANY_MATCH) if (matches->type[0])
match &= dev->node->type match &= dev->node->type
&& !strcmp(matches->type, dev->node->type); && !strcmp(matches->type, dev->node->type);
if (matches->compatible && matches->compatible != OF_ANY_MATCH) if (matches->compatible[0])
match &= device_is_compatible(dev->node, match &= device_is_compatible(dev->node,
matches->compatible); matches->compatible);
if (match) if (match)
...@@ -42,7 +43,7 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv) ...@@ -42,7 +43,7 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
{ {
struct of_device * of_dev = to_of_device(dev); struct of_device * of_dev = to_of_device(dev);
struct of_platform_driver * of_drv = to_of_platform_driver(drv); struct of_platform_driver * of_drv = to_of_platform_driver(drv);
const struct of_match * matches = of_drv->match_table; const struct of_device_id * matches = of_drv->match_table;
if (!matches) if (!matches)
return 0; return 0;
...@@ -75,7 +76,7 @@ static int of_device_probe(struct device *dev) ...@@ -75,7 +76,7 @@ static int of_device_probe(struct device *dev)
int error = -ENODEV; int error = -ENODEV;
struct of_platform_driver *drv; struct of_platform_driver *drv;
struct of_device *of_dev; struct of_device *of_dev;
const struct of_match *match; const struct of_device_id *match;
drv = to_of_platform_driver(dev->driver); drv = to_of_platform_driver(dev->driver);
of_dev = to_of_device(dev); of_dev = to_of_device(dev);
......
...@@ -698,7 +698,7 @@ dispose_iface(struct device *dev) ...@@ -698,7 +698,7 @@ dispose_iface(struct device *dev)
} }
static int static int
create_iface_macio(struct macio_dev* dev, const struct of_match *match) create_iface_macio(struct macio_dev* dev, const struct of_device_id *match)
{ {
return create_iface(dev->ofdev.node, &dev->ofdev.dev); return create_iface(dev->ofdev.node, &dev->ofdev.dev);
} }
...@@ -710,7 +710,7 @@ dispose_iface_macio(struct macio_dev* dev) ...@@ -710,7 +710,7 @@ dispose_iface_macio(struct macio_dev* dev)
} }
static int static int
create_iface_of_platform(struct of_device* dev, const struct of_match *match) create_iface_of_platform(struct of_device* dev, const struct of_device_id *match)
{ {
return create_iface(dev->node, &dev->dev); return create_iface(dev->node, &dev->dev);
} }
...@@ -721,10 +721,9 @@ dispose_iface_of_platform(struct of_device* dev) ...@@ -721,10 +721,9 @@ dispose_iface_of_platform(struct of_device* dev)
return dispose_iface(&dev->dev); return dispose_iface(&dev->dev);
} }
static struct of_match i2c_keywest_match[] = static struct of_device_id i2c_keywest_match[] =
{ {
{ {
.name = OF_ANY_MATCH,
.type = "i2c", .type = "i2c",
.compatible = "keywest" .compatible = "keywest"
}, },
......
...@@ -1419,7 +1419,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif) ...@@ -1419,7 +1419,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
* Attach to a macio probed interface * Attach to a macio probed interface
*/ */
static int __devinit static int __devinit
pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_match *match) pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
{ {
void __iomem *base; void __iomem *base;
unsigned long regbase; unsigned long regbase;
...@@ -1637,27 +1637,19 @@ pmac_ide_pci_resume(struct pci_dev *pdev) ...@@ -1637,27 +1637,19 @@ pmac_ide_pci_resume(struct pci_dev *pdev)
return rc; return rc;
} }
static struct of_match pmac_ide_macio_match[] = static struct of_device_id pmac_ide_macio_match[] =
{ {
{ {
.name = "IDE", .name = "IDE",
.type = OF_ANY_MATCH,
.compatible = OF_ANY_MATCH
}, },
{ {
.name = "ATA", .name = "ATA",
.type = OF_ANY_MATCH,
.compatible = OF_ANY_MATCH
}, },
{ {
.name = OF_ANY_MATCH,
.type = "ide", .type = "ide",
.compatible = OF_ANY_MATCH
}, },
{ {
.name = OF_ANY_MATCH,
.type = "ata", .type = "ata",
.compatible = OF_ANY_MATCH
}, },
{}, {},
}; };
......
...@@ -33,7 +33,7 @@ static int macio_bus_match(struct device *dev, struct device_driver *drv) ...@@ -33,7 +33,7 @@ static int macio_bus_match(struct device *dev, struct device_driver *drv)
{ {
struct macio_dev * macio_dev = to_macio_device(dev); struct macio_dev * macio_dev = to_macio_device(dev);
struct macio_driver * macio_drv = to_macio_driver(drv); struct macio_driver * macio_drv = to_macio_driver(drv);
const struct of_match * matches = macio_drv->match_table; const struct of_device_id * matches = macio_drv->match_table;
if (!matches) if (!matches)
return 0; return 0;
...@@ -66,7 +66,7 @@ static int macio_device_probe(struct device *dev) ...@@ -66,7 +66,7 @@ static int macio_device_probe(struct device *dev)
int error = -ENODEV; int error = -ENODEV;
struct macio_driver *drv; struct macio_driver *drv;
struct macio_dev *macio_dev; struct macio_dev *macio_dev;
const struct of_match *match; const struct of_device_id *match;
drv = to_macio_driver(dev->driver); drv = to_macio_driver(dev->driver);
macio_dev = to_macio_device(dev); macio_dev = to_macio_device(dev);
......
...@@ -642,7 +642,7 @@ static int __pmac media_bay_task(void *x) ...@@ -642,7 +642,7 @@ static int __pmac media_bay_task(void *x)
} }
} }
static int __devinit media_bay_attach(struct macio_dev *mdev, const struct of_match *match) static int __devinit media_bay_attach(struct macio_dev *mdev, const struct of_device_id *match)
{ {
struct media_bay_info* bay; struct media_bay_info* bay;
u32 __iomem *regbase; u32 __iomem *regbase;
...@@ -797,23 +797,20 @@ static struct mb_ops keylargo_mb_ops __pmacdata = { ...@@ -797,23 +797,20 @@ static struct mb_ops keylargo_mb_ops __pmacdata = {
* Therefore we do it all by polling the media bay once each tick. * Therefore we do it all by polling the media bay once each tick.
*/ */
static struct of_match media_bay_match[] = static struct of_device_id media_bay_match[] =
{ {
{ {
.name = "media-bay", .name = "media-bay",
.type = OF_ANY_MATCH,
.compatible = "keylargo-media-bay", .compatible = "keylargo-media-bay",
.data = &keylargo_mb_ops, .data = &keylargo_mb_ops,
}, },
{ {
.name = "media-bay", .name = "media-bay",
.type = OF_ANY_MATCH,
.compatible = "heathrow-media-bay", .compatible = "heathrow-media-bay",
.data = &heathrow_mb_ops, .data = &heathrow_mb_ops,
}, },
{ {
.name = "media-bay", .name = "media-bay",
.type = OF_ANY_MATCH,
.compatible = "ohare-media-bay", .compatible = "ohare-media-bay",
.data = &ohare_mb_ops, .data = &ohare_mb_ops,
}, },
......
...@@ -120,6 +120,7 @@ ...@@ -120,6 +120,7 @@
#include <asm/system.h> #include <asm/system.h>
#include <asm/sections.h> #include <asm/sections.h>
#include <asm/of_device.h> #include <asm/of_device.h>
#include <asm/macio.h>
#include "therm_pm72.h" #include "therm_pm72.h"
...@@ -1986,7 +1987,7 @@ static void fcu_lookup_fans(struct device_node *fcu_node) ...@@ -1986,7 +1987,7 @@ static void fcu_lookup_fans(struct device_node *fcu_node)
} }
} }
static int fcu_of_probe(struct of_device* dev, const struct of_match *match) static int fcu_of_probe(struct of_device* dev, const struct of_device_id *match)
{ {
int rc; int rc;
...@@ -2009,12 +2010,10 @@ static int fcu_of_remove(struct of_device* dev) ...@@ -2009,12 +2010,10 @@ static int fcu_of_remove(struct of_device* dev)
return 0; return 0;
} }
static struct of_match fcu_of_match[] = static struct of_device_id fcu_match[] =
{ {
{ {
.name = OF_ANY_MATCH,
.type = "fcu", .type = "fcu",
.compatible = OF_ANY_MATCH
}, },
{}, {},
}; };
...@@ -2022,7 +2021,7 @@ static struct of_match fcu_of_match[] = ...@@ -2022,7 +2021,7 @@ static struct of_match fcu_of_match[] =
static struct of_platform_driver fcu_of_platform_driver = static struct of_platform_driver fcu_of_platform_driver =
{ {
.name = "temperature", .name = "temperature",
.match_table = fcu_of_match, .match_table = fcu_match,
.probe = fcu_of_probe, .probe = fcu_of_probe,
.remove = fcu_of_remove .remove = fcu_of_remove
}; };
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <asm/system.h> #include <asm/system.h>
#include <asm/sections.h> #include <asm/sections.h>
#include <asm/of_device.h> #include <asm/of_device.h>
#include <asm/macio.h>
#define LOG_TEMP 0 /* continously log temperature */ #define LOG_TEMP 0 /* continously log temperature */
...@@ -450,7 +451,7 @@ do_probe( struct i2c_adapter *adapter, int addr, int kind ) ...@@ -450,7 +451,7 @@ do_probe( struct i2c_adapter *adapter, int addr, int kind )
/************************************************************************/ /************************************************************************/
static int static int
therm_of_probe( struct of_device *dev, const struct of_match *match ) therm_of_probe( struct of_device *dev, const struct of_device_id *match )
{ {
return i2c_add_driver( &g4fan_driver ); return i2c_add_driver( &g4fan_driver );
} }
...@@ -461,9 +462,8 @@ therm_of_remove( struct of_device *dev ) ...@@ -461,9 +462,8 @@ therm_of_remove( struct of_device *dev )
return i2c_del_driver( &g4fan_driver ); return i2c_del_driver( &g4fan_driver );
} }
static struct of_match therm_of_match[] = {{ static struct of_device_id therm_of_match[] = {{
.name = "fan", .name = "fan",
.type = OF_ANY_MATCH,
.compatible = "adm1030" .compatible = "adm1030"
}, {} }, {}
}; };
......
...@@ -1261,7 +1261,7 @@ static void bmac_reset_and_enable(struct net_device *dev) ...@@ -1261,7 +1261,7 @@ static void bmac_reset_and_enable(struct net_device *dev)
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock_irqrestore(&bp->lock, flags);
} }
static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_match *match) static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_id *match)
{ {
int j, rev, ret; int j, rev, ret;
struct bmac_data *bp; struct bmac_data *bp;
...@@ -1645,16 +1645,13 @@ static int __devexit bmac_remove(struct macio_dev *mdev) ...@@ -1645,16 +1645,13 @@ static int __devexit bmac_remove(struct macio_dev *mdev)
return 0; return 0;
} }
static struct of_match bmac_match[] = static struct of_device_id bmac_match[] =
{ {
{ {
.name = "bmac", .name = "bmac",
.type = OF_ANY_MATCH,
.compatible = OF_ANY_MATCH,
.data = (void *)0, .data = (void *)0,
}, },
{ {
.name = OF_ANY_MATCH,
.type = "network", .type = "network",
.compatible = "bmac+", .compatible = "bmac+",
.data = (void *)1, .data = (void *)1,
......
...@@ -109,7 +109,7 @@ bitrev(int b) ...@@ -109,7 +109,7 @@ bitrev(int b)
} }
static int __devinit mace_probe(struct macio_dev *mdev, const struct of_match *match) static int __devinit mace_probe(struct macio_dev *mdev, const struct of_device_id *match)
{ {
struct device_node *mace = macio_get_of_node(mdev); struct device_node *mace = macio_get_of_node(mdev);
struct net_device *dev; struct net_device *dev;
...@@ -1009,12 +1009,10 @@ static irqreturn_t mace_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs) ...@@ -1009,12 +1009,10 @@ static irqreturn_t mace_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static struct of_match mace_match[] = static struct of_device_id mace_match[] =
{ {
{ {
.name = "mace", .name = "mace",
.type = OF_ANY_MATCH,
.compatible = OF_ANY_MATCH
}, },
{}, {},
}; };
......
...@@ -184,7 +184,7 @@ static int airport_hard_reset(struct orinoco_private *priv) ...@@ -184,7 +184,7 @@ static int airport_hard_reset(struct orinoco_private *priv)
} }
static int static int
airport_attach(struct macio_dev *mdev, const struct of_match *match) airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
{ {
struct orinoco_private *priv; struct orinoco_private *priv;
struct net_device *dev; struct net_device *dev;
...@@ -266,16 +266,16 @@ MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>"); ...@@ -266,16 +266,16 @@ MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
MODULE_DESCRIPTION("Driver for the Apple Airport wireless card."); MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
MODULE_LICENSE("Dual MPL/GPL"); MODULE_LICENSE("Dual MPL/GPL");
static struct of_match airport_match[] = static struct of_device_id airport_match[] =
{ {
{ {
.name = "radio", .name = "radio",
.type = OF_ANY_MATCH,
.compatible = OF_ANY_MATCH
}, },
{}, {},
}; };
MODULE_DEVICE_TABLE (of, airport_match);
static struct macio_driver airport_driver = static struct macio_driver airport_driver =
{ {
.name = DRIVER_NAME, .name = DRIVER_NAME,
......
...@@ -424,7 +424,7 @@ static struct scsi_host_template mac53c94_template = { ...@@ -424,7 +424,7 @@ static struct scsi_host_template mac53c94_template = {
.use_clustering = DISABLE_CLUSTERING, .use_clustering = DISABLE_CLUSTERING,
}; };
static int mac53c94_probe(struct macio_dev *mdev, const struct of_match *match) static int mac53c94_probe(struct macio_dev *mdev, const struct of_device_id *match)
{ {
struct device_node *node = macio_get_of_node(mdev); struct device_node *node = macio_get_of_node(mdev);
struct pci_dev *pdev = macio_get_pci_dev(mdev); struct pci_dev *pdev = macio_get_pci_dev(mdev);
...@@ -544,15 +544,14 @@ static int mac53c94_remove(struct macio_dev *mdev) ...@@ -544,15 +544,14 @@ static int mac53c94_remove(struct macio_dev *mdev)
} }
static struct of_match mac53c94_match[] = static struct of_device_id mac53c94_match[] =
{ {
{ {
.name = "53c94", .name = "53c94",
.type = OF_ANY_MATCH,
.compatible = OF_ANY_MATCH
}, },
{}, {},
}; };
MODULE_DEVICE_TABLE (of, mac53c94_match);
static struct macio_driver mac53c94_driver = static struct macio_driver mac53c94_driver =
{ {
......