2 * Copyright 2009 Novell. All Rights Reserved.
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
56 static int vbus_dev_proxy_probe(struct device
*_dev
)
59 struct vbus_device_proxy
*dev
= to_dev(_dev
);
60 struct vbus_driver
*drv
= to_drv(_dev
->driver
);
63 ret
= drv
->ops
->probe(dev
);
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
= {
75 .init_name
= VBUS_PROXY_NAME
,
78 static int __init
vbus_init(void)
82 ret
= bus_register(&vbus_proxy
);
85 ret
= device_register(&vbus_proxy_rootdev
);
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
)
130 dev
= bus_find_device(&vbus_proxy
, NULL
, &id
, &match_device_id
);
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 *---------------------------------
159 vbus_driver_ioq_release(struct ioq
*ioq
)
161 kfree(ioq
->head_desc
);
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
)
174 struct ioq_ring_head
*head
= NULL
;
175 struct shm_signal
*signal
= NULL
;
176 size_t len
= IOQ_HEAD_DESC_SIZE(count
);
179 _ioq
= kzalloc(sizeof(*_ioq
), GFP_KERNEL
);
183 head
= kzalloc(len
, GFP_KERNEL
| GFP_DMA
);
187 head
->magic
= IOQ_RING_MAGIC
;
188 head
->ver
= IOQ_RING_VER
;
191 ret
= dev
->ops
->shm(dev
, id
, prio
, head
, len
,
192 &head
->signal
, &signal
, 0);
197 &vbus_driver_ioq_ops
,
212 shm_signal_put(signal
);
216 EXPORT_SYMBOL_GPL(vbus_driver_ioq_alloc
);