2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2014 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
17 #include "scif_main.h"
18 #include "../bus/scif_bus.h"
19 #include "scif_peer_bus.h"
21 static inline struct scif_peer_dev *
22 dev_to_scif_peer(struct device *dev)
24 return container_of(dev, struct scif_peer_dev, dev);
27 static inline struct scif_peer_driver *
28 drv_to_scif_peer(struct device_driver *drv)
30 return container_of(drv, struct scif_peer_driver, driver);
33 static int scif_peer_dev_match(struct device *dv, struct device_driver *dr)
35 return !strncmp(dev_name(dv), dr->name, 4);
38 static int scif_peer_dev_probe(struct device *d)
40 struct scif_peer_dev *dev = dev_to_scif_peer(d);
41 struct scif_peer_driver *drv = drv_to_scif_peer(dev->dev.driver);
43 return drv->probe(dev);
46 static int scif_peer_dev_remove(struct device *d)
48 struct scif_peer_dev *dev = dev_to_scif_peer(d);
49 struct scif_peer_driver *drv = drv_to_scif_peer(dev->dev.driver);
55 static struct bus_type scif_peer_bus = {
56 .name = "scif_peer_bus",
57 .match = scif_peer_dev_match,
58 .probe = scif_peer_dev_probe,
59 .remove = scif_peer_dev_remove,
62 int scif_peer_register_driver(struct scif_peer_driver *driver)
64 driver->driver.bus = &scif_peer_bus;
65 return driver_register(&driver->driver);
68 void scif_peer_unregister_driver(struct scif_peer_driver *driver)
70 driver_unregister(&driver->driver);
73 static void scif_peer_release_dev(struct device *d)
75 struct scif_peer_dev *sdev = dev_to_scif_peer(d);
76 struct scif_dev *scifdev = &scif_dev[sdev->dnode];
78 scif_cleanup_scifdev(scifdev);
82 struct scif_peer_dev *
83 scif_peer_register_device(struct scif_dev *scifdev)
86 struct scif_peer_dev *spdev;
88 spdev = kzalloc(sizeof(*spdev), GFP_KERNEL);
90 return ERR_PTR(-ENOMEM);
92 spdev->dev.parent = scifdev->sdev->dev.parent;
93 spdev->dev.release = scif_peer_release_dev;
94 spdev->dnode = scifdev->node;
95 spdev->dev.bus = &scif_peer_bus;
97 dev_set_name(&spdev->dev, "scif_peer-dev%u", spdev->dnode);
99 * device_register() causes the bus infrastructure to look for a
102 ret = device_register(&spdev->dev);
111 void scif_peer_unregister_device(struct scif_peer_dev *sdev)
113 device_unregister(&sdev->dev);
116 int scif_peer_bus_init(void)
118 return bus_register(&scif_peer_bus);
121 void scif_peer_bus_exit(void)
123 bus_unregister(&scif_peer_bus);