Skip to content

Commit 7d9e6f5

Browse files
tudorlChristoph Hellwig
authored andcommitted
usb: host: ohci-sm501: init genalloc for local memory
In preparation for dropping the existing "coherent" dma mem declaration APIs, replace the current dma_declare_coherent_memory() based mechanism with the creation of a genalloc pool that will be used in the OHCI subsystem as replacement for the DMA APIs. Signed-off-by: Laurentiu Tudor <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent b0310c2 commit 7d9e6f5

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

drivers/usb/host/ohci-sm501.c

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,40 +110,18 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
110110
goto err0;
111111
}
112112

113-
/* The sm501 chip is equipped with local memory that may be used
114-
* by on-chip devices such as the video controller and the usb host.
115-
* This driver uses dma_declare_coherent_memory() to make sure
116-
* usb allocations with dma_alloc_coherent() allocate from
117-
* this local memory. The dma_handle returned by dma_alloc_coherent()
118-
* will be an offset starting from 0 for the first local memory byte.
119-
*
120-
* So as long as data is allocated using dma_alloc_coherent() all is
121-
* fine. This is however not always the case - buffers may be allocated
122-
* using kmalloc() - so the usb core needs to be told that it must copy
123-
* data into our local memory if the buffers happen to be placed in
124-
* regular memory. The HCD_LOCAL_MEM flag does just that.
125-
*/
126-
127-
retval = dma_declare_coherent_memory(dev, mem->start,
128-
mem->start - mem->parent->start,
129-
resource_size(mem));
130-
if (retval) {
131-
dev_err(dev, "cannot declare coherent memory\n");
132-
goto err1;
133-
}
134-
135113
/* allocate, reserve and remap resources for registers */
136114
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
137115
if (res == NULL) {
138116
dev_err(dev, "no resource definition for registers\n");
139117
retval = -ENOENT;
140-
goto err2;
118+
goto err1;
141119
}
142120

143121
hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
144122
if (!hcd) {
145123
retval = -ENOMEM;
146-
goto err2;
124+
goto err1;
147125
}
148126

149127
hcd->rsrc_start = res->start;
@@ -164,6 +142,24 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
164142

165143
ohci_hcd_init(hcd_to_ohci(hcd));
166144

145+
/* The sm501 chip is equipped with local memory that may be used
146+
* by on-chip devices such as the video controller and the usb host.
147+
* This driver uses genalloc so that usb allocations with
148+
* gen_pool_dma_alloc() allocate from this local memory. The dma_handle
149+
* returned by gen_pool_dma_alloc() will be an offset starting from 0
150+
* for the first local memory byte.
151+
*
152+
* So as long as data is allocated using gen_pool_dma_alloc() all is
153+
* fine. This is however not always the case - buffers may be allocated
154+
* using kmalloc() - so the usb core needs to be told that it must copy
155+
* data into our local memory if the buffers happen to be placed in
156+
* regular memory. The HCD_LOCAL_MEM flag does just that.
157+
*/
158+
159+
if (usb_hcd_setup_local_mem(hcd, mem->start,
160+
mem->start - mem->parent->start,
161+
resource_size(mem)) < 0)
162+
goto err5;
167163
retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
168164
if (retval)
169165
goto err5;
@@ -181,8 +177,6 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev)
181177
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
182178
err3:
183179
usb_put_hcd(hcd);
184-
err2:
185-
dma_release_declared_memory(dev);
186180
err1:
187181
release_mem_region(mem->start, resource_size(mem));
188182
err0:
@@ -197,7 +191,6 @@ static int ohci_hcd_sm501_drv_remove(struct platform_device *pdev)
197191
usb_remove_hcd(hcd);
198192
release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
199193
usb_put_hcd(hcd);
200-
dma_release_declared_memory(&pdev->dev);
201194
mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
202195
if (mem)
203196
release_mem_region(mem->start, resource_size(mem));

0 commit comments

Comments
 (0)