0001
0002
0003
0004
0005
0006
0007 #include <linux/device.h>
0008 #include <linux/dma-mapping.h>
0009 #include <linux/list.h>
0010 #include <linux/nubus.h>
0011 #include <linux/seq_file.h>
0012 #include <linux/slab.h>
0013
0014 #define to_nubus_board(d) container_of(d, struct nubus_board, dev)
0015 #define to_nubus_driver(d) container_of(d, struct nubus_driver, driver)
0016
0017 static int nubus_bus_match(struct device *dev, struct device_driver *driver)
0018 {
0019 return 1;
0020 }
0021
0022 static int nubus_device_probe(struct device *dev)
0023 {
0024 struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
0025 int err = -ENODEV;
0026
0027 if (ndrv->probe)
0028 err = ndrv->probe(to_nubus_board(dev));
0029 return err;
0030 }
0031
0032 static void nubus_device_remove(struct device *dev)
0033 {
0034 struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
0035
0036 if (ndrv->remove)
0037 ndrv->remove(to_nubus_board(dev));
0038 }
0039
0040 struct bus_type nubus_bus_type = {
0041 .name = "nubus",
0042 .match = nubus_bus_match,
0043 .probe = nubus_device_probe,
0044 .remove = nubus_device_remove,
0045 };
0046 EXPORT_SYMBOL(nubus_bus_type);
0047
0048 int nubus_driver_register(struct nubus_driver *ndrv)
0049 {
0050 ndrv->driver.bus = &nubus_bus_type;
0051 return driver_register(&ndrv->driver);
0052 }
0053 EXPORT_SYMBOL(nubus_driver_register);
0054
0055 void nubus_driver_unregister(struct nubus_driver *ndrv)
0056 {
0057 driver_unregister(&ndrv->driver);
0058 }
0059 EXPORT_SYMBOL(nubus_driver_unregister);
0060
0061 static struct device nubus_parent = {
0062 .init_name = "nubus",
0063 };
0064
0065 static int __init nubus_bus_register(void)
0066 {
0067 return bus_register(&nubus_bus_type);
0068 }
0069 postcore_initcall(nubus_bus_register);
0070
0071 int __init nubus_parent_device_register(void)
0072 {
0073 return device_register(&nubus_parent);
0074 }
0075
0076 static void nubus_device_release(struct device *dev)
0077 {
0078 struct nubus_board *board = to_nubus_board(dev);
0079 struct nubus_rsrc *fres, *tmp;
0080
0081 list_for_each_entry_safe(fres, tmp, &nubus_func_rsrcs, list)
0082 if (fres->board == board) {
0083 list_del(&fres->list);
0084 kfree(fres);
0085 }
0086 kfree(board);
0087 }
0088
0089 int nubus_device_register(struct nubus_board *board)
0090 {
0091 board->dev.parent = &nubus_parent;
0092 board->dev.release = nubus_device_release;
0093 board->dev.bus = &nubus_bus_type;
0094 dev_set_name(&board->dev, "slot.%X", board->slot);
0095 board->dev.dma_mask = &board->dev.coherent_dma_mask;
0096 dma_set_mask(&board->dev, DMA_BIT_MASK(32));
0097 return device_register(&board->dev);
0098 }
0099
0100 static int nubus_print_device_name_fn(struct device *dev, void *data)
0101 {
0102 struct nubus_board *board = to_nubus_board(dev);
0103 struct seq_file *m = data;
0104
0105 seq_printf(m, "Slot %X: %s\n", board->slot, board->name);
0106 return 0;
0107 }
0108
0109 int nubus_proc_show(struct seq_file *m, void *data)
0110 {
0111 return bus_for_each_dev(&nubus_bus_type, NULL, m,
0112 nubus_print_device_name_fn);
0113 }