Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Jeff Mahoney and committed by
Linus Torvalds
5e655772 159f597a

+91 -93
+8 -7
arch/ppc/syslib/of_device.c
··· 3 3 #include <linux/kernel.h> 4 4 #include <linux/init.h> 5 5 #include <linux/module.h> 6 + #include <linux/mod_devicetable.h> 6 7 #include <asm/errno.h> 7 8 #include <asm/of_device.h> 8 9 ··· 16 15 * Used by a driver to check whether an of_device present in the 17 16 * system is in its list of supported devices. 18 17 */ 19 - const struct of_match * of_match_device(const struct of_match *matches, 18 + const struct of_device_id * of_match_device(const struct of_device_id *matches, 20 19 const struct of_device *dev) 21 20 { 22 21 if (!dev->node) 23 22 return NULL; 24 - while (matches->name || matches->type || matches->compatible) { 23 + while (matches->name[0] || matches->type[0] || matches->compatible[0]) { 25 24 int match = 1; 26 - if (matches->name && matches->name != OF_ANY_MATCH) 25 + if (matches->name[0]) 27 26 match &= dev->node->name 28 27 && !strcmp(matches->name, dev->node->name); 29 - if (matches->type && matches->type != OF_ANY_MATCH) 28 + if (matches->type[0]) 30 29 match &= dev->node->type 31 30 && !strcmp(matches->type, dev->node->type); 32 - if (matches->compatible && matches->compatible != OF_ANY_MATCH) 31 + if (matches->compatible[0]) 33 32 match &= device_is_compatible(dev->node, 34 33 matches->compatible); 35 34 if (match) ··· 43 42 { 44 43 struct of_device * of_dev = to_of_device(dev); 45 44 struct of_platform_driver * of_drv = to_of_platform_driver(drv); 46 - const struct of_match * matches = of_drv->match_table; 45 + const struct of_device_id * matches = of_drv->match_table; 47 46 48 47 if (!matches) 49 48 return 0; ··· 76 75 int error = -ENODEV; 77 76 struct of_platform_driver *drv; 78 77 struct of_device *of_dev; 79 - const struct of_match *match; 78 + const struct of_device_id *match; 80 79 81 80 drv = to_of_platform_driver(dev->driver); 82 81 of_dev = to_of_device(dev);
+8 -7
arch/ppc64/kernel/of_device.c
··· 3 3 #include <linux/kernel.h> 4 4 #include <linux/init.h> 5 5 #include <linux/module.h> 6 + #include <linux/mod_devicetable.h> 6 7 #include <asm/errno.h> 7 8 #include <asm/of_device.h> 8 9 ··· 16 15 * Used by a driver to check whether an of_device present in the 17 16 * system is in its list of supported devices. 18 17 */ 19 - const struct of_match * of_match_device(const struct of_match *matches, 18 + const struct of_device_id *of_match_device(const struct of_device_id *matches, 20 19 const struct of_device *dev) 21 20 { 22 21 if (!dev->node) 23 22 return NULL; 24 - while (matches->name || matches->type || matches->compatible) { 23 + while (matches->name[0] || matches->type[0] || matches->compatible[0]) { 25 24 int match = 1; 26 - if (matches->name && matches->name != OF_ANY_MATCH) 25 + if (matches->name[0]) 27 26 match &= dev->node->name 28 27 && !strcmp(matches->name, dev->node->name); 29 - if (matches->type && matches->type != OF_ANY_MATCH) 28 + if (matches->type[0]) 30 29 match &= dev->node->type 31 30 && !strcmp(matches->type, dev->node->type); 32 - if (matches->compatible && matches->compatible != OF_ANY_MATCH) 31 + if (matches->compatible[0]) 33 32 match &= device_is_compatible(dev->node, 34 33 matches->compatible); 35 34 if (match) ··· 43 42 { 44 43 struct of_device * of_dev = to_of_device(dev); 45 44 struct of_platform_driver * of_drv = to_of_platform_driver(drv); 46 - const struct of_match * matches = of_drv->match_table; 45 + const struct of_device_id * matches = of_drv->match_table; 47 46 48 47 if (!matches) 49 48 return 0; ··· 76 75 int error = -ENODEV; 77 76 struct of_platform_driver *drv; 78 77 struct of_device *of_dev; 79 - const struct of_match *match; 78 + const struct of_device_id *match; 80 79 81 80 drv = to_of_platform_driver(dev->driver); 82 81 of_dev = to_of_device(dev);
+3 -4
drivers/i2c/busses/i2c-keywest.c
··· 698 698 } 699 699 700 700 static int 701 - create_iface_macio(struct macio_dev* dev, const struct of_match *match) 701 + create_iface_macio(struct macio_dev* dev, const struct of_device_id *match) 702 702 { 703 703 return create_iface(dev->ofdev.node, &dev->ofdev.dev); 704 704 } ··· 710 710 } 711 711 712 712 static int 713 - create_iface_of_platform(struct of_device* dev, const struct of_match *match) 713 + create_iface_of_platform(struct of_device* dev, const struct of_device_id *match) 714 714 { 715 715 return create_iface(dev->node, &dev->dev); 716 716 } ··· 721 721 return dispose_iface(&dev->dev); 722 722 } 723 723 724 - static struct of_match i2c_keywest_match[] = 724 + static struct of_device_id i2c_keywest_match[] = 725 725 { 726 726 { 727 - .name = OF_ANY_MATCH, 728 727 .type = "i2c", 729 728 .compatible = "keywest" 730 729 },
+2 -10
drivers/ide/ppc/pmac.c
··· 1419 1419 * Attach to a macio probed interface 1420 1420 */ 1421 1421 static int __devinit 1422 - pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_match *match) 1422 + pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match) 1423 1423 { 1424 1424 void __iomem *base; 1425 1425 unsigned long regbase; ··· 1637 1637 return rc; 1638 1638 } 1639 1639 1640 - static struct of_match pmac_ide_macio_match[] = 1640 + static struct of_device_id pmac_ide_macio_match[] = 1641 1641 { 1642 1642 { 1643 1643 .name = "IDE", 1644 - .type = OF_ANY_MATCH, 1645 - .compatible = OF_ANY_MATCH 1646 1644 }, 1647 1645 { 1648 1646 .name = "ATA", 1649 - .type = OF_ANY_MATCH, 1650 - .compatible = OF_ANY_MATCH 1651 1647 }, 1652 1648 { 1653 - .name = OF_ANY_MATCH, 1654 1649 .type = "ide", 1655 - .compatible = OF_ANY_MATCH 1656 1650 }, 1657 1651 { 1658 - .name = OF_ANY_MATCH, 1659 1652 .type = "ata", 1660 - .compatible = OF_ANY_MATCH 1661 1653 }, 1662 1654 {}, 1663 1655 };
+2 -2
drivers/macintosh/macio_asic.c
··· 33 33 { 34 34 struct macio_dev * macio_dev = to_macio_device(dev); 35 35 struct macio_driver * macio_drv = to_macio_driver(drv); 36 - const struct of_match * matches = macio_drv->match_table; 36 + const struct of_device_id * matches = macio_drv->match_table; 37 37 38 38 if (!matches) 39 39 return 0; ··· 66 66 int error = -ENODEV; 67 67 struct macio_driver *drv; 68 68 struct macio_dev *macio_dev; 69 - const struct of_match *match; 69 + const struct of_device_id *match; 70 70 71 71 drv = to_macio_driver(dev->driver); 72 72 macio_dev = to_macio_device(dev);
+2 -5
drivers/macintosh/mediabay.c
··· 642 642 } 643 643 } 644 644 645 - static int __devinit media_bay_attach(struct macio_dev *mdev, const struct of_match *match) 645 + static int __devinit media_bay_attach(struct macio_dev *mdev, const struct of_device_id *match) 646 646 { 647 647 struct media_bay_info* bay; 648 648 u32 __iomem *regbase; ··· 797 797 * Therefore we do it all by polling the media bay once each tick. 798 798 */ 799 799 800 - static struct of_match media_bay_match[] = 800 + static struct of_device_id media_bay_match[] = 801 801 { 802 802 { 803 803 .name = "media-bay", 804 - .type = OF_ANY_MATCH, 805 804 .compatible = "keylargo-media-bay", 806 805 .data = &keylargo_mb_ops, 807 806 }, 808 807 { 809 808 .name = "media-bay", 810 - .type = OF_ANY_MATCH, 811 809 .compatible = "heathrow-media-bay", 812 810 .data = &heathrow_mb_ops, 813 811 }, 814 812 { 815 813 .name = "media-bay", 816 - .type = OF_ANY_MATCH, 817 814 .compatible = "ohare-media-bay", 818 815 .data = &ohare_mb_ops, 819 816 },
+4 -5
drivers/macintosh/therm_pm72.c
··· 120 120 #include <asm/system.h> 121 121 #include <asm/sections.h> 122 122 #include <asm/of_device.h> 123 + #include <asm/macio.h> 123 124 124 125 #include "therm_pm72.h" 125 126 ··· 1987 1986 } 1988 1987 } 1989 1988 1990 - static int fcu_of_probe(struct of_device* dev, const struct of_match *match) 1989 + static int fcu_of_probe(struct of_device* dev, const struct of_device_id *match) 1991 1990 { 1992 1991 int rc; 1993 1992 ··· 2010 2009 return 0; 2011 2010 } 2012 2011 2013 - static struct of_match fcu_of_match[] = 2012 + static struct of_device_id fcu_match[] = 2014 2013 { 2015 2014 { 2016 - .name = OF_ANY_MATCH, 2017 2015 .type = "fcu", 2018 - .compatible = OF_ANY_MATCH 2019 2016 }, 2020 2017 {}, 2021 2018 }; ··· 2021 2022 static struct of_platform_driver fcu_of_platform_driver = 2022 2023 { 2023 2024 .name = "temperature", 2024 - .match_table = fcu_of_match, 2025 + .match_table = fcu_match, 2025 2026 .probe = fcu_of_probe, 2026 2027 .remove = fcu_of_remove 2027 2028 };
+3 -3
drivers/macintosh/therm_windtunnel.c
··· 43 43 #include <asm/system.h> 44 44 #include <asm/sections.h> 45 45 #include <asm/of_device.h> 46 + #include <asm/macio.h> 46 47 47 48 #define LOG_TEMP 0 /* continously log temperature */ 48 49 ··· 451 450 /************************************************************************/ 452 451 453 452 static int 454 - therm_of_probe( struct of_device *dev, const struct of_match *match ) 453 + therm_of_probe( struct of_device *dev, const struct of_device_id *match ) 455 454 { 456 455 return i2c_add_driver( &g4fan_driver ); 457 456 } ··· 462 461 return i2c_del_driver( &g4fan_driver ); 463 462 } 464 463 465 - static struct of_match therm_of_match[] = {{ 464 + static struct of_device_id therm_of_match[] = {{ 466 465 .name = "fan", 467 - .type = OF_ANY_MATCH, 468 466 .compatible = "adm1030" 469 467 }, {} 470 468 };
+2 -5
drivers/net/bmac.c
··· 1261 1261 spin_unlock_irqrestore(&bp->lock, flags); 1262 1262 } 1263 1263 1264 - static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_match *match) 1264 + static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_id *match) 1265 1265 { 1266 1266 int j, rev, ret; 1267 1267 struct bmac_data *bp; ··· 1645 1645 return 0; 1646 1646 } 1647 1647 1648 - static struct of_match bmac_match[] = 1648 + static struct of_device_id bmac_match[] = 1649 1649 { 1650 1650 { 1651 1651 .name = "bmac", 1652 - .type = OF_ANY_MATCH, 1653 - .compatible = OF_ANY_MATCH, 1654 1652 .data = (void *)0, 1655 1653 }, 1656 1654 { 1657 - .name = OF_ANY_MATCH, 1658 1655 .type = "network", 1659 1656 .compatible = "bmac+", 1660 1657 .data = (void *)1,
+2 -4
drivers/net/mace.c
··· 109 109 } 110 110 111 111 112 - static int __devinit mace_probe(struct macio_dev *mdev, const struct of_match *match) 112 + static int __devinit mace_probe(struct macio_dev *mdev, const struct of_device_id *match) 113 113 { 114 114 struct device_node *mace = macio_get_of_node(mdev); 115 115 struct net_device *dev; ··· 1009 1009 return IRQ_HANDLED; 1010 1010 } 1011 1011 1012 - static struct of_match mace_match[] = 1012 + static struct of_device_id mace_match[] = 1013 1013 { 1014 1014 { 1015 1015 .name = "mace", 1016 - .type = OF_ANY_MATCH, 1017 - .compatible = OF_ANY_MATCH 1018 1016 }, 1019 1017 {}, 1020 1018 };
+4 -4
drivers/net/wireless/airport.c
··· 184 184 } 185 185 186 186 static int 187 - airport_attach(struct macio_dev *mdev, const struct of_match *match) 187 + airport_attach(struct macio_dev *mdev, const struct of_device_id *match) 188 188 { 189 189 struct orinoco_private *priv; 190 190 struct net_device *dev; ··· 266 266 MODULE_DESCRIPTION("Driver for the Apple Airport wireless card."); 267 267 MODULE_LICENSE("Dual MPL/GPL"); 268 268 269 - static struct of_match airport_match[] = 269 + static struct of_device_id airport_match[] = 270 270 { 271 271 { 272 272 .name = "radio", 273 - .type = OF_ANY_MATCH, 274 - .compatible = OF_ANY_MATCH 275 273 }, 276 274 {}, 277 275 }; 276 + 277 + MODULE_DEVICE_TABLE (of, airport_match); 278 278 279 279 static struct macio_driver airport_driver = 280 280 {
+3 -4
drivers/scsi/mac53c94.c
··· 424 424 .use_clustering = DISABLE_CLUSTERING, 425 425 }; 426 426 427 - static int mac53c94_probe(struct macio_dev *mdev, const struct of_match *match) 427 + static int mac53c94_probe(struct macio_dev *mdev, const struct of_device_id *match) 428 428 { 429 429 struct device_node *node = macio_get_of_node(mdev); 430 430 struct pci_dev *pdev = macio_get_pci_dev(mdev); ··· 544 544 } 545 545 546 546 547 - static struct of_match mac53c94_match[] = 547 + static struct of_device_id mac53c94_match[] = 548 548 { 549 549 { 550 550 .name = "53c94", 551 - .type = OF_ANY_MATCH, 552 - .compatible = OF_ANY_MATCH 553 551 }, 554 552 {}, 555 553 }; 554 + MODULE_DEVICE_TABLE (of, mac53c94_match); 556 555 557 556 static struct macio_driver mac53c94_driver = 558 557 {
+3 -5
drivers/scsi/mesh.c
··· 1847 1847 .use_clustering = DISABLE_CLUSTERING, 1848 1848 }; 1849 1849 1850 - static int mesh_probe(struct macio_dev *mdev, const struct of_match *match) 1850 + static int mesh_probe(struct macio_dev *mdev, const struct of_device_id *match) 1851 1851 { 1852 1852 struct device_node *mesh = macio_get_of_node(mdev); 1853 1853 struct pci_dev* pdev = macio_get_pci_dev(mdev); ··· 2012 2012 } 2013 2013 2014 2014 2015 - static struct of_match mesh_match[] = 2015 + static struct of_device_id mesh_match[] = 2016 2016 { 2017 2017 { 2018 2018 .name = "mesh", 2019 - .type = OF_ANY_MATCH, 2020 - .compatible = OF_ANY_MATCH 2021 2019 }, 2022 2020 { 2023 - .name = OF_ANY_MATCH, 2024 2021 .type = "scsi", 2025 2022 .compatible = "chrp,mesh0" 2026 2023 }, 2027 2024 {}, 2028 2025 }; 2026 + MODULE_DEVICE_TABLE (of, mesh_match); 2029 2027 2030 2028 static struct macio_driver mesh_driver = 2031 2029 {
+3 -6
drivers/serial/pmac_zilog.c
··· 1545 1545 /* 1546 1546 * Called upon match with an escc node in the devive-tree. 1547 1547 */ 1548 - static int pmz_attach(struct macio_dev *mdev, const struct of_match *match) 1548 + static int pmz_attach(struct macio_dev *mdev, const struct of_device_id *match) 1549 1549 { 1550 1550 int i; 1551 1551 ··· 1850 1850 return rc; 1851 1851 } 1852 1852 1853 - static struct of_match pmz_match[] = 1853 + static struct of_device_id pmz_match[] = 1854 1854 { 1855 1855 { 1856 1856 .name = "ch-a", 1857 - .type = OF_ANY_MATCH, 1858 - .compatible = OF_ANY_MATCH 1859 1857 }, 1860 1858 { 1861 1859 .name = "ch-b", 1862 - .type = OF_ANY_MATCH, 1863 - .compatible = OF_ANY_MATCH 1864 1860 }, 1865 1861 {}, 1866 1862 }; 1863 + MODULE_DEVICE_TABLE (of, pmz_match); 1867 1864 1868 1865 static struct macio_driver pmz_driver = 1869 1866 {
+2 -4
drivers/video/platinumfb.c
··· 523 523 #define invalidate_cache(addr) 524 524 #endif 525 525 526 - static int __devinit platinumfb_probe(struct of_device* odev, const struct of_match *match) 526 + static int __devinit platinumfb_probe(struct of_device* odev, const struct of_device_id *match) 527 527 { 528 528 struct device_node *dp = odev->node; 529 529 struct fb_info *info; ··· 647 647 return 0; 648 648 } 649 649 650 - static struct of_match platinumfb_match[] = 650 + static struct of_device_id platinumfb_match[] = 651 651 { 652 652 { 653 653 .name = "platinum", 654 - .type = OF_ANY_MATCH, 655 - .compatible = OF_ANY_MATCH, 656 654 }, 657 655 {}, 658 656 };
+3 -2
include/asm-ppc/macio.h
··· 1 1 #ifndef __MACIO_ASIC_H__ 2 2 #define __MACIO_ASIC_H__ 3 3 4 + #include <linux/mod_devicetable.h> 4 5 #include <asm/of_device.h> 5 6 6 7 extern struct bus_type macio_bus_type; ··· 121 120 struct macio_driver 122 121 { 123 122 char *name; 124 - struct of_match *match_table; 123 + struct of_device_id *match_table; 125 124 struct module *owner; 126 125 127 - int (*probe)(struct macio_dev* dev, const struct of_match *match); 126 + int (*probe)(struct macio_dev* dev, const struct of_device_id *match); 128 127 int (*remove)(struct macio_dev* dev); 129 128 130 129 int (*suspend)(struct macio_dev* dev, pm_message_t state);
+4 -16
include/asm-ppc/of_device.h
··· 24 24 }; 25 25 #define to_of_device(d) container_of(d, struct of_device, dev) 26 26 27 - /* 28 - * Struct used for matching a device 29 - */ 30 - struct of_match 31 - { 32 - char *name; 33 - char *type; 34 - char *compatible; 35 - void *data; 36 - }; 37 - #define OF_ANY_MATCH ((char *)-1L) 38 - 39 - extern const struct of_match *of_match_device( 40 - const struct of_match *matches, const struct of_device *dev); 27 + extern const struct of_device_id *of_match_device( 28 + const struct of_device_id *matches, const struct of_device *dev); 41 29 42 30 extern struct of_device *of_dev_get(struct of_device *dev); 43 31 extern void of_dev_put(struct of_device *dev); ··· 37 49 struct of_platform_driver 38 50 { 39 51 char *name; 40 - struct of_match *match_table; 52 + struct of_device_id *match_table; 41 53 struct module *owner; 42 54 43 - int (*probe)(struct of_device* dev, const struct of_match *match); 55 + int (*probe)(struct of_device* dev, const struct of_device_id *match); 44 56 int (*remove)(struct of_device* dev); 45 57 46 58 int (*suspend)(struct of_device* dev, pm_message_t state);
+11
include/linux/mod_devicetable.h
··· 174 174 __u8 proto; 175 175 }; 176 176 177 + /* 178 + * Struct used for matching a device 179 + */ 180 + struct of_device_id 181 + { 182 + char name[32]; 183 + char type[32]; 184 + char compatible[128]; 185 + void *data; 186 + }; 187 + 177 188 178 189 /* PCMCIA */ 179 190
+22
scripts/mod/file2alias.c
··· 25 25 #include <stdint.h> 26 26 #endif 27 27 28 + #include <ctype.h> 29 + 28 30 typedef uint32_t __u32; 29 31 typedef uint16_t __u16; 30 32 typedef unsigned char __u8; ··· 325 323 326 324 327 325 326 + static int do_of_entry (const char *filename, struct of_device_id *of, char *alias) 327 + { 328 + char *tmp; 329 + sprintf (alias, "of:N%sT%sC%s", 330 + of->name[0] ? of->name : "*", 331 + of->type[0] ? of->type : "*", 332 + of->compatible[0] ? of->compatible : "*"); 333 + 334 + /* Replace all whitespace with underscores */ 335 + for (tmp = alias; tmp && *tmp; tmp++) 336 + if (isspace (*tmp)) 337 + *tmp = '_'; 338 + 339 + return 1; 340 + } 341 + 328 342 /* Ignore any prefix, eg. v850 prepends _ */ 329 343 static inline int sym_is(const char *symbol, const char *name) 330 344 { ··· 419 401 else if (sym_is(symname, "__mod_pcmcia_device_table")) 420 402 do_table(symval, sym->st_size, sizeof(struct pcmcia_device_id), 421 403 do_pcmcia_entry, mod); 404 + else if (sym_is(symname, "__mod_of_device_table")) 405 + do_table(symval, sym->st_size, sizeof(struct of_device_id), 406 + do_of_entry, mod); 407 + 422 408 } 423 409 424 410 /* Now add out buffered information to the generated C source */