forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/usb/host/ohci-mem.c
....@@ -36,6 +36,13 @@
3636
3737 static int ohci_mem_init (struct ohci_hcd *ohci)
3838 {
39
+ /*
40
+ * HCs with local memory allocate from localmem_pool so there's
41
+ * no need to create the below dma pools.
42
+ */
43
+ if (ohci_to_hcd(ohci)->localmem_pool)
44
+ return 0;
45
+
3946 ohci->td_cache = dma_pool_create ("ohci_td",
4047 ohci_to_hcd(ohci)->self.controller,
4148 sizeof (struct td),
....@@ -57,14 +64,10 @@
5764
5865 static void ohci_mem_cleanup (struct ohci_hcd *ohci)
5966 {
60
- if (ohci->td_cache) {
61
- dma_pool_destroy (ohci->td_cache);
62
- ohci->td_cache = NULL;
63
- }
64
- if (ohci->ed_cache) {
65
- dma_pool_destroy (ohci->ed_cache);
66
- ohci->ed_cache = NULL;
67
- }
67
+ dma_pool_destroy(ohci->td_cache);
68
+ ohci->td_cache = NULL;
69
+ dma_pool_destroy(ohci->ed_cache);
70
+ ohci->ed_cache = NULL;
6871 }
6972
7073 /*-------------------------------------------------------------------------*/
....@@ -88,8 +91,13 @@
8891 {
8992 dma_addr_t dma;
9093 struct td *td;
94
+ struct usb_hcd *hcd = ohci_to_hcd(hc);
9195
92
- td = dma_pool_zalloc (hc->td_cache, mem_flags, &dma);
96
+ if (hcd->localmem_pool)
97
+ td = gen_pool_dma_zalloc_align(hcd->localmem_pool,
98
+ sizeof(*td), &dma, 32);
99
+ else
100
+ td = dma_pool_zalloc(hc->td_cache, mem_flags, &dma);
93101 if (td) {
94102 /* in case hc fetches it, make it look dead */
95103 td->hwNextTD = cpu_to_hc32 (hc, dma);
....@@ -103,6 +111,7 @@
103111 td_free (struct ohci_hcd *hc, struct td *td)
104112 {
105113 struct td **prev = &hc->td_hash [TD_HASH_FUNC (td->td_dma)];
114
+ struct usb_hcd *hcd = ohci_to_hcd(hc);
106115
107116 while (*prev && *prev != td)
108117 prev = &(*prev)->td_hash;
....@@ -110,7 +119,12 @@
110119 *prev = td->td_hash;
111120 else if ((td->hwINFO & cpu_to_hc32(hc, TD_DONE)) != 0)
112121 ohci_dbg (hc, "no hash for td %p\n", td);
113
- dma_pool_free (hc->td_cache, td, td->td_dma);
122
+
123
+ if (hcd->localmem_pool)
124
+ gen_pool_free(hcd->localmem_pool, (unsigned long)td,
125
+ sizeof(*td));
126
+ else
127
+ dma_pool_free(hc->td_cache, td, td->td_dma);
114128 }
115129
116130 /*-------------------------------------------------------------------------*/
....@@ -121,8 +135,13 @@
121135 {
122136 dma_addr_t dma;
123137 struct ed *ed;
138
+ struct usb_hcd *hcd = ohci_to_hcd(hc);
124139
125
- ed = dma_pool_zalloc (hc->ed_cache, mem_flags, &dma);
140
+ if (hcd->localmem_pool)
141
+ ed = gen_pool_dma_zalloc_align(hcd->localmem_pool,
142
+ sizeof(*ed), &dma, 16);
143
+ else
144
+ ed = dma_pool_zalloc(hc->ed_cache, mem_flags, &dma);
126145 if (ed) {
127146 INIT_LIST_HEAD (&ed->td_list);
128147 ed->dma = dma;
....@@ -133,6 +152,12 @@
133152 static void
134153 ed_free (struct ohci_hcd *hc, struct ed *ed)
135154 {
136
- dma_pool_free (hc->ed_cache, ed, ed->dma);
155
+ struct usb_hcd *hcd = ohci_to_hcd(hc);
156
+
157
+ if (hcd->localmem_pool)
158
+ gen_pool_free(hcd->localmem_pool, (unsigned long)ed,
159
+ sizeof(*ed));
160
+ else
161
+ dma_pool_free(hc->ed_cache, ed, ed->dma);
137162 }
138163