Release 4.7 drivers/usb/core/buffer.c
/*
* DMA memory management for framework level HCD code (hc_driver)
*
* This implementation plugs in through generic "usb_bus" level methods,
* and should work with all USB controllers, regardless of bus type.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/mm.h>
#include <linux/io.h>
#include <linux/dma-mapping.h>
#include <linux/dmapool.h>
#include <linux/usb.h>
#include <linux/usb/hcd.h>
/*
* DMA-Coherent Buffers
*/
/* FIXME tune these based on pool statistics ... */
static size_t pool_max[HCD_BUFFER_POOLS] = {
32, 128, 512, 2048,
};
void __init usb_init_pool_max(void)
{
/*
* The pool_max values must never be smaller than
* ARCH_KMALLOC_MINALIGN.
*/
if (ARCH_KMALLOC_MINALIGN <= 32)
; /* Original value is okay */
else if (ARCH_KMALLOC_MINALIGN <= 64)
pool_max[0] = 64;
else if (ARCH_KMALLOC_MINALIGN <= 128)
pool_max[0] = 0; /* Don't use this pool */
else
BUILD_BUG(); /* We don't allow this */
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
sebastian andrzej siewior | sebastian andrzej siewior | 51 | 100.00% | 1 | 100.00% |
| Total | 51 | 100.00% | 1 | 100.00% |
/* SETUP primitives */
/**
* hcd_buffer_create - initialize buffer pools
* @hcd: the bus whose buffer pools are to be initialized
* Context: !in_interrupt()
*
* Call this as part of initializing a host controller that uses the dma
* memory allocators. It initializes some pools of dma-coherent memory that
* will be shared by all drivers using that controller.
*
* Call hcd_buffer_destroy() to clean up after using those pools.
*
* Return: 0 if successful. A negative errno value otherwise.
*/
int hcd_buffer_create(struct usb_hcd *hcd)
{
char name[16];
int i, size;
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
(!hcd->self.controller->dma_mask &&
!(hcd->driver->flags & HCD_LOCAL_MEM)))
return 0;
for (i = 0; i < HCD_BUFFER_POOLS; i++) {
size = pool_max[i];
if (!size)
continue;
snprintf(name, sizeof(name), "buffer-%d", size);
hcd->pool[i] = dma_pool_create(name, hcd->self.controller,
size, size, 0);
if (!hcd->pool[i]) {
hcd_buffer_destroy(hcd);
return -ENOMEM;
}
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david brownell | david brownell | 100 | 69.44% | 1 | 14.29% |
chris humbert | chris humbert | 14 | 9.72% | 1 | 14.29% |
magnus damm | magnus damm | 11 | 7.64% | 1 | 14.29% |
geert uytterhoeven | geert uytterhoeven | 8 | 5.56% | 1 | 14.29% |
greg kroah-hartman | greg kroah-hartman | 5 | 3.47% | 1 | 14.29% |
deepak saxena | deepak saxena | 4 | 2.78% | 1 | 14.29% |
nizam haider | nizam haider | 2 | 1.39% | 1 | 14.29% |
| Total | 144 | 100.00% | 7 | 100.00% |
/**
* hcd_buffer_destroy - deallocate buffer pools
* @hcd: the bus whose buffer pools are to be destroyed
* Context: !in_interrupt()
*
* This frees the buffer pools created by hcd_buffer_create().
*/
void hcd_buffer_destroy(struct usb_hcd *hcd)
{
int i;
if (!IS_ENABLED(CONFIG_HAS_DMA))
return;
for (i = 0; i < HCD_BUFFER_POOLS; i++) {
struct dma_pool *pool = hcd->pool[i];
if (pool) {
dma_pool_destroy(pool);
hcd->pool[i] = NULL;
}
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david brownell | david brownell | 57 | 82.61% | 1 | 25.00% |
geert uytterhoeven | geert uytterhoeven | 9 | 13.04% | 1 | 25.00% |
deepak saxena | deepak saxena | 2 | 2.90% | 1 | 25.00% |
mika kukkonen | mika kukkonen | 1 | 1.45% | 1 | 25.00% |
| Total | 69 | 100.00% | 4 | 100.00% |
/* sometimes alloc/free could use kmalloc with GFP_DMA, for
* better sharing and to leverage mm/slab.c intelligence.
*/
void *hcd_buffer_alloc(
struct usb_bus *bus,
size_t size,
gfp_t mem_flags,
dma_addr_t *dma
)
{
struct usb_hcd *hcd = bus_to_hcd(bus);
int i;
if (size == 0)
return NULL;
/* some USB hosts just use PIO */
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
(!bus->controller->dma_mask &&
!(hcd->driver->flags & HCD_LOCAL_MEM))) {
*dma = ~(dma_addr_t) 0;
return kmalloc(size, mem_flags);
}
for (i = 0; i < HCD_BUFFER_POOLS; i++) {
if (size <= pool_max[i])
return dma_pool_alloc(hcd->pool[i], mem_flags, dma);
}
return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david brownell | david brownell | 107 | 73.29% | 2 | 22.22% |
magnus damm | magnus damm | 11 | 7.53% | 1 | 11.11% |
chunfeng yun | chunfeng yun | 9 | 6.16% | 1 | 11.11% |
geert uytterhoeven | geert uytterhoeven | 8 | 5.48% | 1 | 11.11% |
deepak saxena | deepak saxena | 6 | 4.11% | 1 | 11.11% |
alan stern | alan stern | 3 | 2.05% | 1 | 11.11% |
al viro | al viro | 1 | 0.68% | 1 | 11.11% |
johannes berg | johannes berg | 1 | 0.68% | 1 | 11.11% |
| Total | 146 | 100.00% | 9 | 100.00% |
void hcd_buffer_free(
struct usb_bus *bus,
size_t size,
void *addr,
dma_addr_t dma
)
{
struct usb_hcd *hcd = bus_to_hcd(bus);
int i;
if (!addr)
return;
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
(!bus->controller->dma_mask &&
!(hcd->driver->flags & HCD_LOCAL_MEM))) {
kfree(addr);
return;
}
for (i = 0; i < HCD_BUFFER_POOLS; i++) {
if (size <= pool_max[i]) {
dma_pool_free(hcd->pool[i], addr, dma);
return;
}
}
dma_free_coherent(hcd->self.controller, size, addr, dma);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david brownell | david brownell | 104 | 79.39% | 3 | 42.86% |
magnus damm | magnus damm | 11 | 8.40% | 1 | 14.29% |
geert uytterhoeven | geert uytterhoeven | 8 | 6.11% | 1 | 14.29% |
deepak saxena | deepak saxena | 5 | 3.82% | 1 | 14.29% |
alan stern | alan stern | 3 | 2.29% | 1 | 14.29% |
| Total | 131 | 100.00% | 7 | 100.00% |
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david brownell | david brownell | 403 | 67.73% | 5 | 22.73% |
sebastian andrzej siewior | sebastian andrzej siewior | 53 | 8.91% | 1 | 4.55% |
magnus damm | magnus damm | 33 | 5.55% | 1 | 4.55% |
geert uytterhoeven | geert uytterhoeven | 33 | 5.55% | 1 | 4.55% |
deepak saxena | deepak saxena | 29 | 4.87% | 1 | 4.55% |
chris humbert | chris humbert | 14 | 2.35% | 1 | 4.55% |
chunfeng yun | chunfeng yun | 9 | 1.51% | 1 | 4.55% |
alan stern | alan stern | 6 | 1.01% | 1 | 4.55% |
greg kroah-hartman | greg kroah-hartman | 5 | 0.84% | 1 | 4.55% |
nizam haider | nizam haider | 2 | 0.34% | 1 | 4.55% |
tobias ollmann | tobias ollmann | 1 | 0.17% | 1 | 4.55% |
yacine belkadi | yacine belkadi | 1 | 0.17% | 1 | 4.55% |
johannes berg | johannes berg | 1 | 0.17% | 1 | 4.55% |
al viro | al viro | 1 | 0.17% | 1 | 4.55% |
christoph lameter | christoph lameter | 1 | 0.17% | 1 | 4.55% |
mika kukkonen | mika kukkonen | 1 | 0.17% | 1 | 4.55% |
rahul bedarkar | rahul bedarkar | 1 | 0.17% | 1 | 4.55% |
eric lescouet | eric lescouet | 1 | 0.17% | 1 | 4.55% |
| Total | 595 | 100.00% | 22 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.