Merge 5.0-rc6 into driver-core-next
[linux/fpc-iii.git] / drivers / nubus / bus.c
blobad3d17c42e23ccef936430210b36e9e649034e01
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Bus implementation for the NuBus subsystem.
4 //
5 // Copyright (C) 2017 Finn Thain
7 #include <linux/device.h>
8 #include <linux/dma-mapping.h>
9 #include <linux/list.h>
10 #include <linux/nubus.h>
11 #include <linux/seq_file.h>
12 #include <linux/slab.h>
14 #define to_nubus_board(d) container_of(d, struct nubus_board, dev)
15 #define to_nubus_driver(d) container_of(d, struct nubus_driver, driver)
17 static int nubus_bus_match(struct device *dev, struct device_driver *driver)
19 return 1;
22 static int nubus_device_probe(struct device *dev)
24 struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
25 int err = -ENODEV;
27 if (ndrv->probe)
28 err = ndrv->probe(to_nubus_board(dev));
29 return err;
32 static int nubus_device_remove(struct device *dev)
34 struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
35 int err = -ENODEV;
37 if (dev->driver && ndrv->remove)
38 err = ndrv->remove(to_nubus_board(dev));
39 return err;
42 struct bus_type nubus_bus_type = {
43 .name = "nubus",
44 .match = nubus_bus_match,
45 .probe = nubus_device_probe,
46 .remove = nubus_device_remove,
48 EXPORT_SYMBOL(nubus_bus_type);
50 int nubus_driver_register(struct nubus_driver *ndrv)
52 ndrv->driver.bus = &nubus_bus_type;
53 return driver_register(&ndrv->driver);
55 EXPORT_SYMBOL(nubus_driver_register);
57 void nubus_driver_unregister(struct nubus_driver *ndrv)
59 driver_unregister(&ndrv->driver);
61 EXPORT_SYMBOL(nubus_driver_unregister);
63 static struct device nubus_parent = {
64 .init_name = "nubus",
67 static int __init nubus_bus_register(void)
69 return bus_register(&nubus_bus_type);
71 postcore_initcall(nubus_bus_register);
73 int __init nubus_parent_device_register(void)
75 return device_register(&nubus_parent);
78 static void nubus_device_release(struct device *dev)
80 struct nubus_board *board = to_nubus_board(dev);
81 struct nubus_rsrc *fres, *tmp;
83 list_for_each_entry_safe(fres, tmp, &nubus_func_rsrcs, list)
84 if (fres->board == board) {
85 list_del(&fres->list);
86 kfree(fres);
88 kfree(board);
91 int nubus_device_register(struct nubus_board *board)
93 board->dev.parent = &nubus_parent;
94 board->dev.release = nubus_device_release;
95 board->dev.bus = &nubus_bus_type;
96 dev_set_name(&board->dev, "slot.%X", board->slot);
97 board->dev.dma_mask = &board->dev.coherent_dma_mask;
98 dma_set_mask(&board->dev, DMA_BIT_MASK(32));
99 return device_register(&board->dev);
102 static int nubus_print_device_name_fn(struct device *dev, void *data)
104 struct nubus_board *board = to_nubus_board(dev);
105 struct seq_file *m = data;
107 seq_printf(m, "Slot %X: %s\n", board->slot, board->name);
108 return 0;
111 int nubus_proc_show(struct seq_file *m, void *data)
113 return bus_for_each_dev(&nubus_bus_type, NULL, m,
114 nubus_print_device_name_fn);