diff options
Diffstat (limited to 'arch/powerpc/kernel/pci_iommu.c')
-rw-r--r-- | arch/powerpc/kernel/pci_iommu.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/arch/powerpc/kernel/pci_iommu.c b/arch/powerpc/kernel/pci_iommu.c index c1d95e14bbed..0688b2534acb 100644 --- a/arch/powerpc/kernel/pci_iommu.c +++ b/arch/powerpc/kernel/pci_iommu.c | |||
@@ -44,16 +44,16 @@ | |||
44 | */ | 44 | */ |
45 | #define PCI_GET_DN(dev) ((struct device_node *)((dev)->sysdata)) | 45 | #define PCI_GET_DN(dev) ((struct device_node *)((dev)->sysdata)) |
46 | 46 | ||
47 | static inline struct iommu_table *devnode_table(struct device *dev) | 47 | static inline struct iommu_table *device_to_table(struct device *hwdev) |
48 | { | 48 | { |
49 | struct pci_dev *pdev; | 49 | struct pci_dev *pdev; |
50 | 50 | ||
51 | if (!dev) { | 51 | if (!hwdev) { |
52 | pdev = ppc64_isabridge_dev; | 52 | pdev = ppc64_isabridge_dev; |
53 | if (!pdev) | 53 | if (!pdev) |
54 | return NULL; | 54 | return NULL; |
55 | } else | 55 | } else |
56 | pdev = to_pci_dev(dev); | 56 | pdev = to_pci_dev(hwdev); |
57 | 57 | ||
58 | return PCI_DN(PCI_GET_DN(pdev))->iommu_table; | 58 | return PCI_DN(PCI_GET_DN(pdev))->iommu_table; |
59 | } | 59 | } |
@@ -85,14 +85,15 @@ static inline unsigned long device_to_mask(struct device *hwdev) | |||
85 | static void *pci_iommu_alloc_coherent(struct device *hwdev, size_t size, | 85 | static void *pci_iommu_alloc_coherent(struct device *hwdev, size_t size, |
86 | dma_addr_t *dma_handle, gfp_t flag) | 86 | dma_addr_t *dma_handle, gfp_t flag) |
87 | { | 87 | { |
88 | return iommu_alloc_coherent(devnode_table(hwdev), size, dma_handle, | 88 | return iommu_alloc_coherent(device_to_table(hwdev), size, dma_handle, |
89 | device_to_mask(hwdev), flag); | 89 | device_to_mask(hwdev), flag, |
90 | pcibus_to_node(to_pci_dev(hwdev)->bus)); | ||
90 | } | 91 | } |
91 | 92 | ||
92 | static void pci_iommu_free_coherent(struct device *hwdev, size_t size, | 93 | static void pci_iommu_free_coherent(struct device *hwdev, size_t size, |
93 | void *vaddr, dma_addr_t dma_handle) | 94 | void *vaddr, dma_addr_t dma_handle) |
94 | { | 95 | { |
95 | iommu_free_coherent(devnode_table(hwdev), size, vaddr, dma_handle); | 96 | iommu_free_coherent(device_to_table(hwdev), size, vaddr, dma_handle); |
96 | } | 97 | } |
97 | 98 | ||
98 | /* Creates TCEs for a user provided buffer. The user buffer must be | 99 | /* Creates TCEs for a user provided buffer. The user buffer must be |
@@ -104,7 +105,7 @@ static void pci_iommu_free_coherent(struct device *hwdev, size_t size, | |||
104 | static dma_addr_t pci_iommu_map_single(struct device *hwdev, void *vaddr, | 105 | static dma_addr_t pci_iommu_map_single(struct device *hwdev, void *vaddr, |
105 | size_t size, enum dma_data_direction direction) | 106 | size_t size, enum dma_data_direction direction) |
106 | { | 107 | { |
107 | return iommu_map_single(devnode_table(hwdev), vaddr, size, | 108 | return iommu_map_single(device_to_table(hwdev), vaddr, size, |
108 | device_to_mask(hwdev), direction); | 109 | device_to_mask(hwdev), direction); |
109 | } | 110 | } |
110 | 111 | ||
@@ -112,27 +113,27 @@ static dma_addr_t pci_iommu_map_single(struct device *hwdev, void *vaddr, | |||
112 | static void pci_iommu_unmap_single(struct device *hwdev, dma_addr_t dma_handle, | 113 | static void pci_iommu_unmap_single(struct device *hwdev, dma_addr_t dma_handle, |
113 | size_t size, enum dma_data_direction direction) | 114 | size_t size, enum dma_data_direction direction) |
114 | { | 115 | { |
115 | iommu_unmap_single(devnode_table(hwdev), dma_handle, size, direction); | 116 | iommu_unmap_single(device_to_table(hwdev), dma_handle, size, direction); |
116 | } | 117 | } |
117 | 118 | ||
118 | 119 | ||
119 | static int pci_iommu_map_sg(struct device *pdev, struct scatterlist *sglist, | 120 | static int pci_iommu_map_sg(struct device *pdev, struct scatterlist *sglist, |
120 | int nelems, enum dma_data_direction direction) | 121 | int nelems, enum dma_data_direction direction) |
121 | { | 122 | { |
122 | return iommu_map_sg(pdev, devnode_table(pdev), sglist, | 123 | return iommu_map_sg(pdev, device_to_table(pdev), sglist, |
123 | nelems, device_to_mask(pdev), direction); | 124 | nelems, device_to_mask(pdev), direction); |
124 | } | 125 | } |
125 | 126 | ||
126 | static void pci_iommu_unmap_sg(struct device *pdev, struct scatterlist *sglist, | 127 | static void pci_iommu_unmap_sg(struct device *pdev, struct scatterlist *sglist, |
127 | int nelems, enum dma_data_direction direction) | 128 | int nelems, enum dma_data_direction direction) |
128 | { | 129 | { |
129 | iommu_unmap_sg(devnode_table(pdev), sglist, nelems, direction); | 130 | iommu_unmap_sg(device_to_table(pdev), sglist, nelems, direction); |
130 | } | 131 | } |
131 | 132 | ||
132 | /* We support DMA to/from any memory page via the iommu */ | 133 | /* We support DMA to/from any memory page via the iommu */ |
133 | static int pci_iommu_dma_supported(struct device *dev, u64 mask) | 134 | static int pci_iommu_dma_supported(struct device *dev, u64 mask) |
134 | { | 135 | { |
135 | struct iommu_table *tbl = devnode_table(dev); | 136 | struct iommu_table *tbl = device_to_table(dev); |
136 | 137 | ||
137 | if (!tbl || tbl->it_offset > mask) { | 138 | if (!tbl || tbl->it_offset > mask) { |
138 | printk(KERN_INFO "Warning: IOMMU table offset too big for device mask\n"); | 139 | printk(KERN_INFO "Warning: IOMMU table offset too big for device mask\n"); |
@@ -147,13 +148,17 @@ static int pci_iommu_dma_supported(struct device *dev, u64 mask) | |||
147 | return 1; | 148 | return 1; |
148 | } | 149 | } |
149 | 150 | ||
151 | struct dma_mapping_ops pci_iommu_ops = { | ||
152 | .alloc_coherent = pci_iommu_alloc_coherent, | ||
153 | .free_coherent = pci_iommu_free_coherent, | ||
154 | .map_single = pci_iommu_map_single, | ||
155 | .unmap_single = pci_iommu_unmap_single, | ||
156 | .map_sg = pci_iommu_map_sg, | ||
157 | .unmap_sg = pci_iommu_unmap_sg, | ||
158 | .dma_supported = pci_iommu_dma_supported, | ||
159 | }; | ||
160 | |||
150 | void pci_iommu_init(void) | 161 | void pci_iommu_init(void) |
151 | { | 162 | { |
152 | pci_dma_ops.alloc_coherent = pci_iommu_alloc_coherent; | 163 | pci_dma_ops = pci_iommu_ops; |
153 | pci_dma_ops.free_coherent = pci_iommu_free_coherent; | ||
154 | pci_dma_ops.map_single = pci_iommu_map_single; | ||
155 | pci_dma_ops.unmap_single = pci_iommu_unmap_single; | ||
156 | pci_dma_ops.map_sg = pci_iommu_map_sg; | ||
157 | pci_dma_ops.unmap_sg = pci_iommu_unmap_sg; | ||
158 | pci_dma_ops.dma_supported = pci_iommu_dma_supported; | ||
159 | } | 164 | } |