fed up with those stupid warnings
[mmotm.git] / drivers / vbus / bus-proxy.c
blob88cd9048335f043a8318cc251f966dbaf1d9360b
1 /*
2 * Copyright 2009 Novell. All Rights Reserved.
4 * Author:
5 * Gregory Haskins <ghaskins@novell.com>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License
9 * as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <linux/module.h>
22 #include <linux/vbus_driver.h>
24 MODULE_AUTHOR("Gregory Haskins");
25 MODULE_LICENSE("GPL");
27 #define VBUS_PROXY_NAME "vbus-proxy"
29 static struct vbus_device_proxy *to_dev(struct device *_dev)
31 return _dev ? container_of(_dev, struct vbus_device_proxy, dev) : NULL;
34 static struct vbus_driver *to_drv(struct device_driver *_drv)
36 return container_of(_drv, struct vbus_driver, drv);
40 * This function is invoked whenever a new driver and/or device is added
41 * to check if there is a match
43 static int vbus_dev_proxy_match(struct device *_dev, struct device_driver *_drv)
45 struct vbus_device_proxy *dev = to_dev(_dev);
46 struct vbus_driver *drv = to_drv(_drv);
48 return !strcmp(dev->type, drv->type);
52 * This function is invoked after the bus infrastructure has already made a
53 * match. The device will contain a reference to the paired driver which
54 * we will extract.
56 static int vbus_dev_proxy_probe(struct device *_dev)
58 int ret = 0;
59 struct vbus_device_proxy *dev = to_dev(_dev);
60 struct vbus_driver *drv = to_drv(_dev->driver);
62 if (drv->ops->probe)
63 ret = drv->ops->probe(dev);
65 return ret;
68 static struct bus_type vbus_proxy = {
69 .name = VBUS_PROXY_NAME,
70 .match = vbus_dev_proxy_match,
73 static struct device vbus_proxy_rootdev = {
74 .parent = NULL,
75 .init_name = VBUS_PROXY_NAME,
78 static int __init vbus_init(void)
80 int ret;
82 ret = bus_register(&vbus_proxy);
83 BUG_ON(ret < 0);
85 ret = device_register(&vbus_proxy_rootdev);
86 BUG_ON(ret < 0);
88 return 0;
91 postcore_initcall(vbus_init);
93 static void device_release(struct device *dev)
95 struct vbus_device_proxy *_dev;
97 _dev = container_of(dev, struct vbus_device_proxy, dev);
99 _dev->ops->release(_dev);
102 int vbus_device_proxy_register(struct vbus_device_proxy *new)
104 new->dev.parent = &vbus_proxy_rootdev;
105 new->dev.bus = &vbus_proxy;
106 new->dev.release = &device_release;
108 return device_register(&new->dev);
110 EXPORT_SYMBOL_GPL(vbus_device_proxy_register);
112 void vbus_device_proxy_unregister(struct vbus_device_proxy *dev)
114 device_unregister(&dev->dev);
116 EXPORT_SYMBOL_GPL(vbus_device_proxy_unregister);
118 static int match_device_id(struct device *_dev, void *data)
120 struct vbus_device_proxy *dev = to_dev(_dev);
121 u64 id = *(u64 *)data;
123 return dev->id == id;
126 struct vbus_device_proxy *vbus_device_proxy_find(u64 id)
128 struct device *dev;
130 dev = bus_find_device(&vbus_proxy, NULL, &id, &match_device_id);
132 return to_dev(dev);
134 EXPORT_SYMBOL_GPL(vbus_device_proxy_find);
136 int vbus_driver_register(struct vbus_driver *new)
138 new->drv.bus = &vbus_proxy;
139 new->drv.name = new->type;
140 new->drv.owner = new->owner;
141 new->drv.probe = vbus_dev_proxy_probe;
143 return driver_register(&new->drv);
145 EXPORT_SYMBOL_GPL(vbus_driver_register);
147 void vbus_driver_unregister(struct vbus_driver *drv)
149 driver_unregister(&drv->drv);
151 EXPORT_SYMBOL_GPL(vbus_driver_unregister);
154 *---------------------------------
155 * driver-side IOQ helper
156 *---------------------------------
158 static void
159 vbus_driver_ioq_release(struct ioq *ioq)
161 kfree(ioq->head_desc);
162 kfree(ioq);
165 static struct ioq_ops vbus_driver_ioq_ops = {
166 .release = vbus_driver_ioq_release,
170 int vbus_driver_ioq_alloc(struct vbus_device_proxy *dev, int id, int prio,
171 size_t count, struct ioq **ioq)
173 struct ioq *_ioq;
174 struct ioq_ring_head *head = NULL;
175 struct shm_signal *signal = NULL;
176 size_t len = IOQ_HEAD_DESC_SIZE(count);
177 int ret = -ENOMEM;
179 _ioq = kzalloc(sizeof(*_ioq), GFP_KERNEL);
180 if (!_ioq)
181 goto error;
183 head = kzalloc(len, GFP_KERNEL | GFP_DMA);
184 if (!head)
185 goto error;
187 head->magic = IOQ_RING_MAGIC;
188 head->ver = IOQ_RING_VER;
189 head->count = count;
191 ret = dev->ops->shm(dev, id, prio, head, len,
192 &head->signal, &signal, 0);
193 if (ret < 0)
194 goto error;
196 ioq_init(_ioq,
197 &vbus_driver_ioq_ops,
198 ioq_locality_north,
199 head,
200 signal,
201 count);
203 *ioq = _ioq;
205 return 0;
207 error:
208 kfree(_ioq);
209 kfree(head);
211 if (signal)
212 shm_signal_put(signal);
214 return ret;
216 EXPORT_SYMBOL_GPL(vbus_driver_ioq_alloc);