2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7 * This file is licenced under the GPL.
10 /*-------------------------------------------------------------------------*/
13 * OHCI deals with three types of memory:
14 * - data used only by the HCD ... kmalloc is fine
15 * - async and periodic schedules, shared by HC and HCD ... these
16 * need to use dma_pool or dma_alloc_coherent
17 * - driver buffers, read/written by HC ... the hcd glue or the
18 * device driver provides us with dma addresses
20 * There's also "register" data, which is memory mapped.
21 * No memory seen by this driver (or any HCD) may be paged out.
24 /*-------------------------------------------------------------------------*/
26 static void admhc_hcd_init(struct admhcd
*ahcd
)
28 ahcd
->next_statechange
= jiffies
;
29 spin_lock_init(&ahcd
->lock
);
32 /*-------------------------------------------------------------------------*/
34 static int admhc_mem_init(struct admhcd
*ahcd
)
36 ahcd
->td_cache
= dma_pool_create("admhc_td",
37 admhcd_to_hcd(ahcd
)->self
.controller
,
39 TD_ALIGN
, /* byte alignment */
40 0 /* no page-crossing issues */
45 ahcd
->ed_cache
= dma_pool_create("admhc_ed",
46 admhcd_to_hcd(ahcd
)->self
.controller
,
48 ED_ALIGN
, /* byte alignment */
49 0 /* no page-crossing issues */
57 dma_pool_destroy(ahcd
->td_cache
);
58 ahcd
->td_cache
= NULL
;
63 static void admhc_mem_cleanup(struct admhcd
*ahcd
)
66 dma_pool_destroy(ahcd
->td_cache
);
67 ahcd
->td_cache
= NULL
;
71 dma_pool_destroy(ahcd
->ed_cache
);
72 ahcd
->ed_cache
= NULL
;
76 /*-------------------------------------------------------------------------*/
79 static struct td
*td_alloc(struct admhcd
*ahcd
, gfp_t mem_flags
)
84 td
= dma_pool_alloc(ahcd
->td_cache
, mem_flags
, &dma
);
88 /* in case ahcd fetches it, make it look dead */
89 memset(td
, 0, sizeof *td
);
95 static void td_free(struct admhcd
*ahcd
, struct td
*td
)
97 dma_pool_free(ahcd
->td_cache
, td
, td
->td_dma
);
100 /*-------------------------------------------------------------------------*/
103 static struct ed
*ed_alloc(struct admhcd
*ahcd
, gfp_t mem_flags
)
108 ed
= dma_pool_alloc(ahcd
->ed_cache
, mem_flags
, &dma
);
112 memset(ed
, 0, sizeof(*ed
));
115 INIT_LIST_HEAD(&ed
->urb_pending
);
120 static void ed_free(struct admhcd
*ahcd
, struct ed
*ed
)
122 dma_pool_free(ahcd
->ed_cache
, ed
, ed
->dma
);
125 /*-------------------------------------------------------------------------*/
128 static void urb_priv_free(struct admhcd
*ahcd
, struct urb_priv
*urb_priv
)
132 for (i
= 0; i
< urb_priv
->td_cnt
; i
++)
134 td_free(ahcd
, urb_priv
->td
[i
]);
139 static struct urb_priv
*urb_priv_alloc(struct admhcd
*ahcd
, int num_tds
,
142 struct urb_priv
*priv
;
145 /* allocate the private part of the URB */
146 priv
= kzalloc(sizeof(*priv
) + sizeof(struct td
) * num_tds
, mem_flags
);
150 /* allocate the TDs */
151 for (i
= 0; i
< num_tds
; i
++) {
152 priv
->td
[i
] = td_alloc(ahcd
, mem_flags
);
153 if (priv
->td
[i
] == NULL
)
155 priv
->td
[i
]->index
= i
;
158 INIT_LIST_HEAD(&priv
->pending
);
159 priv
->td_cnt
= num_tds
;
164 urb_priv_free(ahcd
, priv
);
This page took 0.048385 seconds and 5 git commands to generate.