aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lguest
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2008-05-30 16:09:42 -0400
committerRusty Russell <rusty@rustcorp.com.au>2008-05-30 01:09:42 -0400
commitb769f579081943f14e0ff03b7b0bd3a11cf14625 (patch)
tree026d89b6d937af43af4a692bcf547e032f0c58cc /drivers/lguest
parent5610bd1524332fe7d651eb56cc780e32763a2ac3 (diff)
virtio: set device index in common code.
Anthony Liguori points out that three different transports use the virtio code, but each one keeps its own counter to set the virtio_device's index field. In theory (though not in current practice) this means that names could be duplicated, and that risk grows as more transports are created. So we move the selection of the unique virtio_device.index into the common code in virtio.c, which has the side-benefit of removing duplicate code. The only complexity is that lguest and S/390 use the index to uniquely identify the device in case of catastrophic failure before register_virtio_device() is called: now we use the offset within the descriptor page as a unique identifier for the printks. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Carsten Otte <cotte@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Chris Lalancette <clalance@redhat.com> Cc: Anthony Liguori <anthony@codemonkey.ws>
Diffstat (limited to 'drivers/lguest')
-rw-r--r--drivers/lguest/lguest_device.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index f4fdf351a7c7..1a8de57289eb 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -20,9 +20,6 @@
20/* The pointer to our (page) of device descriptions. */ 20/* The pointer to our (page) of device descriptions. */
21static void *lguest_devices; 21static void *lguest_devices;
22 22
23/* Unique numbering for lguest devices. */
24static unsigned int dev_index;
25
26/* For Guests, device memory can be used as normal memory, so we cast away the 23/* For Guests, device memory can be used as normal memory, so we cast away the
27 * __iomem to quieten sparse. */ 24 * __iomem to quieten sparse. */
28static inline void *lguest_map(unsigned long phys_addr, unsigned long pages) 25static inline void *lguest_map(unsigned long phys_addr, unsigned long pages)
@@ -325,8 +322,10 @@ static struct device lguest_root = {
325 * As Andrew Tridgell says, "Untested code is buggy code". 322 * As Andrew Tridgell says, "Untested code is buggy code".
326 * 323 *
327 * It's worth reading this carefully: we start with a pointer to the new device 324 * It's worth reading this carefully: we start with a pointer to the new device
328 * descriptor in the "lguest_devices" page. */ 325 * descriptor in the "lguest_devices" page, and the offset into the device
329static void add_lguest_device(struct lguest_device_desc *d) 326 * descriptor page so we can uniquely identify it if things go badly wrong. */
327static void add_lguest_device(struct lguest_device_desc *d,
328 unsigned int offset)
330{ 329{
331 struct lguest_device *ldev; 330 struct lguest_device *ldev;
332 331
@@ -334,18 +333,14 @@ static void add_lguest_device(struct lguest_device_desc *d)
334 * it. */ 333 * it. */
335 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); 334 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
336 if (!ldev) { 335 if (!ldev) {
337 printk(KERN_EMERG "Cannot allocate lguest dev %u\n", 336 printk(KERN_EMERG "Cannot allocate lguest dev %u type %u\n",
338 dev_index++); 337 offset, d->type);
339 return; 338 return;
340 } 339 }
341 340
342 /* This devices' parent is the lguest/ dir. */ 341 /* This devices' parent is the lguest/ dir. */
343 ldev->vdev.dev.parent = &lguest_root; 342 ldev->vdev.dev.parent = &lguest_root;
344 /* We have a unique device index thanks to the dev_index counter. */ 343 /* We have a unique device index thanks to the dev_index counter. */
345 ldev->vdev.index = dev_index++;
346 /* The device type comes straight from the descriptor. There's also a
347 * device vendor field in the virtio_device struct, which we leave as
348 * 0. */
349 ldev->vdev.id.device = d->type; 344 ldev->vdev.id.device = d->type;
350 /* We have a simple set of routines for querying the device's 345 /* We have a simple set of routines for querying the device's
351 * configuration information and setting its status. */ 346 * configuration information and setting its status. */
@@ -357,8 +352,8 @@ static void add_lguest_device(struct lguest_device_desc *d)
357 * virtio_device and calls device_register(). This makes the bus 352 * virtio_device and calls device_register(). This makes the bus
358 * infrastructure look for a matching driver. */ 353 * infrastructure look for a matching driver. */
359 if (register_virtio_device(&ldev->vdev) != 0) { 354 if (register_virtio_device(&ldev->vdev) != 0) {
360 printk(KERN_ERR "Failed to register lguest device %u\n", 355 printk(KERN_ERR "Failed to register lguest dev %u type %u\n",
361 ldev->vdev.index); 356 offset, d->type);
362 kfree(ldev); 357 kfree(ldev);
363 } 358 }
364} 359}
@@ -379,7 +374,7 @@ static void scan_devices(void)
379 break; 374 break;
380 375
381 printk("Device at %i has size %u\n", i, desc_size(d)); 376 printk("Device at %i has size %u\n", i, desc_size(d));
382 add_lguest_device(d); 377 add_lguest_device(d, i);
383 } 378 }
384} 379}
385 380