Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
bd39b7f
Documentation
arch
block
crypto
drivers
acorn
acpi
atm
base
block
bluetooth
cdrom
char
connector
cpufreq
crypto
dio
eisa
fc4
firmware
hwmon
i2c
ide
ieee1394
infiniband
input
isdn
macintosh
mca
md
media
message
mfd
misc
mmc
mtd
net
nubus
oprofile
parisc
parport
pci
pcmcia
pnp
rapidio
s390
sbus
scsi
serial
sh
sn
tc
telephony
usb
atm
class
core
Kconfig
Makefile
buffer.c
config.c
devices.c
devio.c
driver.c
file.c
hcd-pci.c
hcd.c
hcd.h
hub.c
hub.h
inode.c
message.c
notify.c
otg_whitelist.h
sysfs.c
urb.c
usb.c
usb.h
gadget
host
image
input
media
misc
mon
net
serial
storage
Kconfig
Makefile
README
usb-skeleton.c
video
w1
zorro
Kconfig
Makefile
fs
include
init
ipc
kernel
lib
mm
net
scripts
security
sound
usr
.gitignore
COPYING
CREDITS
Kbuild
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
drivers
/
usb
/
core
/
buffer.c
Blame
Blame
Latest commit
History
History
149 lines (128 loc) · 3.15 KB
Breadcrumbs
linux
/
drivers
/
usb
/
core
/
buffer.c
Top
File metadata and controls
Code
Blame
149 lines (128 loc) · 3.15 KB
Raw
/* * 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, regardles of bus type. */ #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/device.h> #include <linux/mm.h> #include <asm/io.h> #include <asm/scatterlist.h> #include <linux/dma-mapping.h> #include <linux/dmapool.h> #include <linux/usb.h> #include "hcd.h" /* * DMA-Coherent Buffers */ /* FIXME tune these based on pool statistics ... */ static const size_t pool_max [HCD_BUFFER_POOLS] = { /* platforms without dma-friendly caches might need to * prevent cacheline sharing... */ 32, 128, 512, PAGE_SIZE / 2 /* bigger --> allocate pages */ }; /* 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, or returns a negative * errno value on error. * * Call hcd_buffer_destroy() to clean up after using those pools. */ int hcd_buffer_create (struct usb_hcd *hcd) { char name [16]; int i, size; if (!hcd->self.controller->dma_mask) return 0; for (i = 0; i < HCD_BUFFER_POOLS; i++) { if (!(size = pool_max [i])) 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; } /** * 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; 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; } } } /* sometimes alloc/free could use kmalloc with SLAB_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->hcpriv; int i; /* some USB hosts just use PIO */ if (!bus->controller->dma_mask) { *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, 0); } void hcd_buffer_free ( struct usb_bus *bus, size_t size, void *addr, dma_addr_t dma ) { struct usb_hcd *hcd = bus->hcpriv; int i; if (!addr) return; if (!bus->controller->dma_mask) { 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); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
You can’t perform that action at this time.