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 * There's basically 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 pci_pool or pci_alloc_consistent
17 * - driver buffers, read/written by HC ... the hcd glue or the
18 * device driver provides us with dma addresses
20 * There's also PCI "register" data, which is memory mapped.
21 * No memory seen by this driver is pagable.
24 /*-------------------------------------------------------------------------*/
26 static struct usb_hcd
*ohci_hcd_alloc (void)
28 struct ohci_hcd
*ohci
;
30 ohci
= (struct ohci_hcd
*) kmalloc (sizeof *ohci
, GFP_KERNEL
);
32 memset (ohci
, 0, sizeof (struct ohci_hcd
));
38 static void ohci_hcd_free (struct usb_hcd
*hcd
)
40 kfree (hcd_to_ohci (hcd
));
43 /*-------------------------------------------------------------------------*/
45 static int ohci_mem_init (struct ohci_hcd
*ohci
)
47 ohci
->td_cache
= pci_pool_create ("ohci_td", ohci
->hcd
.pdev
,
49 32 /* byte alignment */,
50 0 /* no page-crossing issues */);
53 ohci
->ed_cache
= pci_pool_create ("ohci_ed", ohci
->hcd
.pdev
,
55 16 /* byte alignment */,
56 0 /* no page-crossing issues */);
57 if (!ohci
->ed_cache
) {
58 pci_pool_destroy (ohci
->td_cache
);
64 static void ohci_mem_cleanup (struct ohci_hcd
*ohci
)
67 pci_pool_destroy (ohci
->td_cache
);
71 pci_pool_destroy (ohci
->ed_cache
);
76 /*-------------------------------------------------------------------------*/
78 /* ohci "done list" processing needs this mapping */
79 static inline struct td
*
80 dma_to_td (struct ohci_hcd
*hc
, dma_addr_t td_dma
)
85 td
= hc
->td_hash
[TD_HASH_FUNC(td_dma
)];
86 while (td
&& td
->td_dma
!= td_dma
)
93 td_alloc (struct ohci_hcd
*hc
, int mem_flags
)
98 td
= pci_pool_alloc (hc
->td_cache
, mem_flags
, &dma
);
100 /* in case hc fetches it, make it look dead */
101 memset (td
, 0, sizeof *td
);
102 td
->hwNextTD
= cpu_to_le32 (dma
);
104 /* hashed in td_fill */
110 td_free (struct ohci_hcd
*hc
, struct td
*td
)
112 struct td
**prev
= &hc
->td_hash
[TD_HASH_FUNC (td
->td_dma
)];
114 while (*prev
&& *prev
!= td
)
115 prev
= &(*prev
)->td_hash
;
118 else if ((td
->hwINFO
& TD_DONE
) != 0)
119 ohci_dbg (hc
, "no hash for td %p\n", td
);
120 pci_pool_free (hc
->td_cache
, td
, td
->td_dma
);
123 /*-------------------------------------------------------------------------*/
127 ed_alloc (struct ohci_hcd
*hc
, int mem_flags
)
132 ed
= pci_pool_alloc (hc
->ed_cache
, mem_flags
, &dma
);
134 memset (ed
, 0, sizeof (*ed
));
135 INIT_LIST_HEAD (&ed
->td_list
);
142 ed_free (struct ohci_hcd
*hc
, struct ed
*ed
)
144 pci_pool_free (hc
->ed_cache
, ed
, ed
->dma
);