proc: remove PDE_DATA() completely
[linux-block.git] / drivers / nubus / bus.c
CommitLineData
7f86c765
FT
1// SPDX-License-Identifier: GPL-2.0
2//
3// Bus implementation for the NuBus subsystem.
4//
5// Copyright (C) 2017 Finn Thain
6
7#include <linux/device.h>
a8c5cb99 8#include <linux/dma-mapping.h>
7f86c765
FT
9#include <linux/list.h>
10#include <linux/nubus.h>
11#include <linux/seq_file.h>
12#include <linux/slab.h>
13
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)
16
17static int nubus_bus_match(struct device *dev, struct device_driver *driver)
18{
19 return 1;
20}
21
22static int nubus_device_probe(struct device *dev)
23{
24 struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
25 int err = -ENODEV;
26
27 if (ndrv->probe)
28 err = ndrv->probe(to_nubus_board(dev));
29 return err;
30}
31
fc7a6209 32static void nubus_device_remove(struct device *dev)
7f86c765
FT
33{
34 struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
7f86c765 35
f52c9ccb 36 if (ndrv->remove)
fc7a6209 37 ndrv->remove(to_nubus_board(dev));
7f86c765
FT
38}
39
40struct bus_type nubus_bus_type = {
41 .name = "nubus",
42 .match = nubus_bus_match,
43 .probe = nubus_device_probe,
44 .remove = nubus_device_remove,
45};
46EXPORT_SYMBOL(nubus_bus_type);
47
48int nubus_driver_register(struct nubus_driver *ndrv)
49{
50 ndrv->driver.bus = &nubus_bus_type;
51 return driver_register(&ndrv->driver);
52}
53EXPORT_SYMBOL(nubus_driver_register);
54
55void nubus_driver_unregister(struct nubus_driver *ndrv)
56{
57 driver_unregister(&ndrv->driver);
58}
59EXPORT_SYMBOL(nubus_driver_unregister);
60
61static struct device nubus_parent = {
62 .init_name = "nubus",
63};
64
bdeeed09 65static int __init nubus_bus_register(void)
7f86c765 66{
bdeeed09
FT
67 return bus_register(&nubus_bus_type);
68}
69postcore_initcall(nubus_bus_register);
7f86c765 70
bdeeed09
FT
71int __init nubus_parent_device_register(void)
72{
73 return device_register(&nubus_parent);
7f86c765
FT
74}
75
76static void nubus_device_release(struct device *dev)
77{
78 struct nubus_board *board = to_nubus_board(dev);
79 struct nubus_rsrc *fres, *tmp;
80
81 list_for_each_entry_safe(fres, tmp, &nubus_func_rsrcs, list)
82 if (fres->board == board) {
83 list_del(&fres->list);
84 kfree(fres);
85 }
86 kfree(board);
87}
88
89int nubus_device_register(struct nubus_board *board)
90{
91 board->dev.parent = &nubus_parent;
92 board->dev.release = nubus_device_release;
93 board->dev.bus = &nubus_bus_type;
94 dev_set_name(&board->dev, "slot.%X", board->slot);
a8c5cb99
FT
95 board->dev.dma_mask = &board->dev.coherent_dma_mask;
96 dma_set_mask(&board->dev, DMA_BIT_MASK(32));
7f86c765
FT
97 return device_register(&board->dev);
98}
99
100static int nubus_print_device_name_fn(struct device *dev, void *data)
101{
102 struct nubus_board *board = to_nubus_board(dev);
103 struct seq_file *m = data;
104
105 seq_printf(m, "Slot %X: %s\n", board->slot, board->name);
106 return 0;
107}
108
109int nubus_proc_show(struct seq_file *m, void *data)
110{
111 return bus_for_each_dev(&nubus_bus_type, NULL, m,
112 nubus_print_device_name_fn);
113}