move dma_mask into struct device
Subsystems (4)
RFC PATCH 1/1 move dma_mask into struct device
Attached is a patch which moves dma_mask into struct device and cleans up the scsi mid-layer to use it (instead of using struct pci_dev). The advantage to doing this is probably most apparent on non-pci bus architectures where currently you have to construct a fake pci_dev just so you can get the bounce buffers to work correctly.
The patch tries to perturb the minimum amount of code, so dma_mask in struct device is simply a pointer to the one in pci_dev. However, it will make it easy for me now to add generic device to MCA without having to go the fake pci route.
This patch completely removes knowledge of pci devices from the SCSI mid-layer.
I have compiled and tested this, but obviously, since I have an MCA machine, it's not of much value to the pci code changes, so if someone with a PCI machine could check those out, I'd be grateful.
The main problem SCSI has with this is the scsi_ioctl_get_pci which is used to get the pci slot name. Although, this can be fixed up afterwards with Matthew Wilcox's name change patch.
I'd like to see this as the beginning of a move away from bus specific code to using generic device code (where possible). Comments and feedback welcome.
James
===== drivers/pci/probe.c 1.17 vs edited =====
drivers/pci/probe.c +1 -0
@@ -449,6 +449,7 @@/* now put in global tree */ strcpy (dev->dev.name,dev->name);strcpy (dev->dev.bus_id,dev->slot_name); + dev->dev->dma_mask = &dev->dma_mask;device_register (&dev->dev);return dev;
===== drivers/scsi/hosts.h 1.36 vs edited =====
drivers/scsi/hosts.h +11 -5
@@ -468,10 +468,10 @@unsigned int max_host_blocked;/* -* For SCSI hosts which are PCI devices, set pci_dev so that -* we can do BIOS EDD 3.0 mappings +* This is a pointer to the generic device for this host (i.e. the +* device on the bus); */ -struct pci_dev *pci_dev; +struct device *dev;/* * Support for driverfs filesystem
@@ -521,11 +521,17 @@ shost->host_lock = lock; } +static inline void scsi_set_device (struct Scsi_Host *shost, +struct device *dev) +{ + shost->dev = dev; + shost->host_driverfs_dev.parent = dev; +} +static inline void scsi_set_pci_device (struct Scsi_Host *shost,struct pci_dev *pdev) { - shost->pci_dev = pdev; - shost->host_driverfs_dev.parent=&pdev->dev; +scsi_set_device (shost, &pdev->dev); }
===== drivers/scsi/scsi_ioctl.c 1.12 vs edited =====
drivers/scsi/scsi_ioctl.c +3 -3
@@ -396,9 +396,9 @@ scsi_ioctl_get_pci(Scsi_Device * dev, void *arg) { -if (!dev->host->pci_dev)return -ENXIO ; -return copy_to_user (arg, dev->host->pci_dev->slot_name, -sizeof (dev->host->pci_dev->slot_name)); +if (!dev->host->dev)return -ENXIO ; +return copy_to_user (arg, dev->host->dev->name, +sizeof (dev->host->dev->name)); }
===== drivers/scsi/scsi_scan.c 1.35 vs edited =====
drivers/scsi/scsi_scan.c +2 -2
@@ -436,8 +436,8 @@u64 bounce_limit;if (sh->highmem_io) { -if (sh->pci_dev &&PCI_DMA_BUS_IS_PHYS ) { - bounce_limit = sh->pci_dev->dma_mask; +if (sh->dev && sh->dev->dma_mask &&PCI_DMA_BUS_IS_PHYS ) { + bounce_limit = *sh->dev->dma_mask; }else {/* * Platforms with virtual-DMA translation
===== drivers/scsi/st.c 1.42 vs edited =====
drivers/scsi/st.c +2 -2
@@ -3786,8 +3786,8 @@* hardware have no practical limit. */ bounce_limit =BLK_BOUNCE_ANY ; - else if (SDp->host->pci_dev) - bounce_limit = SDp->host->pci_dev->dma_mask; + else if (SDp->host->dev && SDp->host->dev->dma_mask) + bounce_limit = *SDp->host->dev->dma_mask; }else if (SDp->host->unchecked_isa_dma) bounce_limit =BLK_BOUNCE_ISA ; bounce_limit >>=PAGE_SHIFT ;
===== include/linux/device.h 1.58 vs edited =====
include/linux/device.h +1 -0
@@ -300,6 +300,7 @@being off. */ unsigned char *saved_state;/* saved device state */ +u64 *dma_mask;/* dma mask (if dma'able device) */ void (*release)(struct device * dev); };
drivers/pci/probe.c line 452
Quoted 8 lines · J.E.J. Bottomley [[email protected]] wrote:
=====
drivers/pci/probe.c1.17 vs edited =====drivers/pci/probe.c +1
-0@@ -449,6 +449,7 @@/* now put in global tree */ strcpy (dev->dev.name,dev->name);strcpy (dev->dev.bus_id,dev->slot_name); + dev->dev->dma_mask = &dev->dma_mask;
I got a compile error here. This should be.
dev->dev.dma_mask = &dev->dma_mask;
I did not have a current bk handy on the lab machine, but I ran it on a 2.5.47 view with a few offset warnings.
The machine is a 2x pci systems with the following drivers loaded:
aic7xxx, ips, qlogicisp.
It just booted and ran a little IO.
-andmike
--
Michael Anderson
[email protected]
Quoted 24 lines · J.E.J. Bottomley
drivers/scsi/hosts.h +7
-3@@ -468,10 +468,10 @@unsigned int max_host_blocked;/* -* For SCSI hosts which are PCI devices, set pci_dev so that -* we can do BIOS EDD 3.0 mappings +* This is a pointer to the generic device for this host (i.e. the +* device on the bus); */ -struct pci_dev *pci_dev; +struct device *dev;/* * Support for driverfs filesystem @@ -521,11 +521,17 @@ shost->host_lock = lock; } +static inline void scsi_set_device (struct Scsi_Host *shost, +struct device *dev) +{ + shost->dev = dev;
drivers/scsi/hosts.h line 535
Quoted 10 lines
drivers/scsi/hosts.h +4
-2+ shost->host_driverfs_dev.parent = dev; +} +static inline void scsi_set_pci_device (struct Scsi_Host *shost,struct pci_dev *pdev) { - shost->pci_dev = pdev; - shost->host_driverfs_dev.parent=&pdev->dev; +scsi_set_device (shost, &pdev->dev); }
Can shost->host_driverfs_dev.parent be used instead of adding and using a duplicate shost->dev?
-- Patrick Mansfield
Quoted 2 lines · [email protected] said:
Can
shost->host_driverfs_dev.parentbe used instead of adding and using a duplicateshost->dev?
I think so. I believe the parent is always the device we're looking for. I'll make the fix.
James