usb-ohci.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:18k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * URB OHCI HCD (Host Controller Driver) for USB.
  3.  * 
  4.  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5.  * (C) Copyright 2000-2001 David Brownell <dbrownell@users.sourceforge.net>
  6.  * 
  7.  * usb-ohci.h
  8.  */
  9.  
  10. static int cc_to_error[16] = { 
  11. /* mapping of the OHCI CC status to error codes */ 
  12. /* No  Error  */               USB_ST_NOERROR,
  13. /* CRC Error  */               USB_ST_CRC,
  14. /* Bit Stuff  */               USB_ST_BITSTUFF,
  15. /* Data Togg  */               USB_ST_CRC,
  16. /* Stall      */               USB_ST_STALL,
  17. /* DevNotResp */               USB_ST_NORESPONSE,
  18. /* PIDCheck   */               USB_ST_BITSTUFF,
  19. /* UnExpPID   */               USB_ST_BITSTUFF,
  20. /* DataOver   */               USB_ST_DATAOVERRUN,
  21. /* DataUnder  */               USB_ST_DATAUNDERRUN,
  22. /* reservd    */               USB_ST_NORESPONSE,
  23. /* reservd    */               USB_ST_NORESPONSE,
  24. /* BufferOver */               USB_ST_BUFFEROVERRUN,
  25. /* BuffUnder  */               USB_ST_BUFFERUNDERRUN,
  26. /* Not Access */               USB_ST_NORESPONSE,
  27. /* Not Access */               USB_ST_NORESPONSE 
  28. };
  29. #include <linux/config.h>
  30. /* ED States */
  31. #define ED_NEW  0x00
  32. #define ED_UNLINK  0x01
  33. #define ED_OPER 0x02
  34. #define ED_DEL 0x04
  35. #define ED_URB_DEL   0x08
  36. /* usb_ohci_ed */
  37. struct ed {
  38. __u32 hwINFO;       
  39. __u32 hwTailP;
  40. __u32 hwHeadP;
  41. __u32 hwNextED;
  42. struct ed * ed_prev;  
  43. __u8 int_period;
  44. __u8 int_branch;
  45. __u8 int_load; 
  46. __u8 int_interval;
  47. __u8 state;
  48. __u8 type; 
  49. __u16 last_iso;
  50. struct ed * ed_rm_list;
  51. dma_addr_t dma;
  52. __u32 unused[3];
  53. } __attribute((aligned(16)));
  54. typedef struct ed ed_t;
  55.  
  56. /* TD info field */
  57. #define TD_CC       0xf0000000
  58. #define TD_CC_GET(td_p) ((td_p >>28) & 0x0f)
  59. #define TD_CC_SET(td_p, cc) (td_p) = ((td_p) & 0x0fffffff) | (((cc) & 0x0f) << 28)
  60. #define TD_EC       0x0C000000
  61. #define TD_T        0x03000000
  62. #define TD_T_DATA0  0x02000000
  63. #define TD_T_DATA1  0x03000000
  64. #define TD_T_TOGGLE 0x00000000
  65. #define TD_R        0x00040000
  66. #define TD_DI       0x00E00000
  67. #define TD_DI_SET(X) (((X) & 0x07)<< 21)
  68. #define TD_DP       0x00180000
  69. #define TD_DP_SETUP 0x00000000
  70. #define TD_DP_IN    0x00100000
  71. #define TD_DP_OUT   0x00080000
  72. #define TD_ISO     0x00010000
  73. #define TD_DEL      0x00020000
  74. /* CC Codes */
  75. #define TD_CC_NOERROR      0x00
  76. #define TD_CC_CRC          0x01
  77. #define TD_CC_BITSTUFFING  0x02
  78. #define TD_CC_DATATOGGLEM  0x03
  79. #define TD_CC_STALL        0x04
  80. #define TD_DEVNOTRESP      0x05
  81. #define TD_PIDCHECKFAIL    0x06
  82. #define TD_UNEXPECTEDPID   0x07
  83. #define TD_DATAOVERRUN     0x08
  84. #define TD_DATAUNDERRUN    0x09
  85. #define TD_BUFFEROVERRUN   0x0C
  86. #define TD_BUFFERUNDERRUN  0x0D
  87. #define TD_NOTACCESSED     0x0F
  88. #define MAXPSW 1
  89. struct td {
  90. __u32 hwINFO;
  91.    __u32 hwCBP; /* Current Buffer Pointer */
  92.    __u32 hwNextTD; /* Next TD Pointer */
  93.    __u32 hwBE; /* Memory Buffer End Pointer */
  94.    __u16 hwPSW[MAXPSW];
  95.    __u8 unused;
  96.    __u8 index;
  97.    struct ed * ed;
  98.    struct td * next_dl_td;
  99.    struct urb * urb;
  100. dma_addr_t td_dma;
  101. dma_addr_t data_dma;
  102. __u32 unused2[2];
  103. } __attribute((aligned(32))); /* normally 16, iso needs 32 */
  104. typedef struct td td_t;
  105. #define OHCI_ED_SKIP (1 << 14)
  106. /*
  107.  * The HCCA (Host Controller Communications Area) is a 256 byte
  108.  * structure defined in the OHCI spec. that the host controller is
  109.  * told the base address of.  It must be 256-byte aligned.
  110.  */
  111.  
  112. #define NUM_INTS 32 /* part of the OHCI standard */
  113. struct ohci_hcca {
  114. __u32 int_table[NUM_INTS]; /* Interrupt ED table */
  115. __u16 frame_no; /* current frame number */
  116. __u16 pad1; /* set to 0 on each frame_no change */
  117. __u32 done_head; /* info returned for an interrupt */
  118. u8 reserved_for_hc[116];
  119. } __attribute((aligned(256)));
  120.   
  121. /*
  122.  * Maximum number of root hub ports.  
  123.  */
  124. #define MAX_ROOT_PORTS 15 /* maximum OHCI root hub ports */
  125. /*
  126.  * This is the structure of the OHCI controller's memory mapped I/O
  127.  * region.  This is Memory Mapped I/O.  You must use the readl() and
  128.  * writel() macros defined in asm/io.h to access these!!
  129.  */
  130. struct ohci_regs {
  131. /* control and status registers */
  132. __u32 revision;
  133. __u32 control;
  134. __u32 cmdstatus;
  135. __u32 intrstatus;
  136. __u32 intrenable;
  137. __u32 intrdisable;
  138. /* memory pointers */
  139. __u32 hcca;
  140. __u32 ed_periodcurrent;
  141. __u32 ed_controlhead;
  142. __u32 ed_controlcurrent;
  143. __u32 ed_bulkhead;
  144. __u32 ed_bulkcurrent;
  145. __u32 donehead;
  146. /* frame counters */
  147. __u32 fminterval;
  148. __u32 fmremaining;
  149. __u32 fmnumber;
  150. __u32 periodicstart;
  151. __u32 lsthresh;
  152. /* Root hub ports */
  153. struct ohci_roothub_regs {
  154. __u32 a;
  155. __u32 b;
  156. __u32 status;
  157. __u32 portstatus[MAX_ROOT_PORTS];
  158. } roothub;
  159. } __attribute((aligned(32)));
  160. /* OHCI CONTROL AND STATUS REGISTER MASKS */
  161. /*
  162.  * HcControl (control) register masks
  163.  */
  164. #define OHCI_CTRL_CBSR (3 << 0) /* control/bulk service ratio */
  165. #define OHCI_CTRL_PLE (1 << 2) /* periodic list enable */
  166. #define OHCI_CTRL_IE (1 << 3) /* isochronous enable */
  167. #define OHCI_CTRL_CLE (1 << 4) /* control list enable */
  168. #define OHCI_CTRL_BLE (1 << 5) /* bulk list enable */
  169. #define OHCI_CTRL_HCFS (3 << 6) /* host controller functional state */
  170. #define OHCI_CTRL_IR (1 << 8) /* interrupt routing */
  171. #define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
  172. #define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
  173. /* pre-shifted values for HCFS */
  174. # define OHCI_USB_RESET (0 << 6)
  175. # define OHCI_USB_RESUME (1 << 6)
  176. # define OHCI_USB_OPER (2 << 6)
  177. # define OHCI_USB_SUSPEND (3 << 6)
  178. /*
  179.  * HcCommandStatus (cmdstatus) register masks
  180.  */
  181. #define OHCI_HCR (1 << 0) /* host controller reset */
  182. #define OHCI_CLF   (1 << 1) /* control list filled */
  183. #define OHCI_BLF   (1 << 2) /* bulk list filled */
  184. #define OHCI_OCR   (1 << 3) /* ownership change request */
  185. #define OHCI_SOC   (3 << 16) /* scheduling overrun count */
  186. /*
  187.  * masks used with interrupt registers:
  188.  * HcInterruptStatus (intrstatus)
  189.  * HcInterruptEnable (intrenable)
  190.  * HcInterruptDisable (intrdisable)
  191.  */
  192. #define OHCI_INTR_SO (1 << 0) /* scheduling overrun */
  193. #define OHCI_INTR_WDH (1 << 1) /* writeback of done_head */
  194. #define OHCI_INTR_SF (1 << 2) /* start frame */
  195. #define OHCI_INTR_RD (1 << 3) /* resume detect */
  196. #define OHCI_INTR_UE (1 << 4) /* unrecoverable error */
  197. #define OHCI_INTR_FNO (1 << 5) /* frame number overflow */
  198. #define OHCI_INTR_RHSC (1 << 6) /* root hub status change */
  199. #define OHCI_INTR_OC (1 << 30) /* ownership change */
  200. #define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */
  201. /* Virtual Root HUB */
  202. struct virt_root_hub {
  203. int devnum; /* Address of Root Hub endpoint */ 
  204. void * urb;
  205. void * int_addr;
  206. int send;
  207. int interval;
  208. struct timer_list rh_int_timer;
  209. };
  210. /* USB HUB CONSTANTS (not OHCI-specific; see hub.h) */
  211.  
  212. /* destination of request */
  213. #define RH_INTERFACE               0x01
  214. #define RH_ENDPOINT                0x02
  215. #define RH_OTHER                   0x03
  216. #define RH_CLASS                   0x20
  217. #define RH_VENDOR                  0x40
  218. /* Requests: bRequest << 8 | bmRequestType */
  219. #define RH_GET_STATUS           0x0080
  220. #define RH_CLEAR_FEATURE        0x0100
  221. #define RH_SET_FEATURE          0x0300
  222. #define RH_SET_ADDRESS 0x0500
  223. #define RH_GET_DESCRIPTOR 0x0680
  224. #define RH_SET_DESCRIPTOR       0x0700
  225. #define RH_GET_CONFIGURATION 0x0880
  226. #define RH_SET_CONFIGURATION 0x0900
  227. #define RH_GET_STATE            0x0280
  228. #define RH_GET_INTERFACE        0x0A80
  229. #define RH_SET_INTERFACE        0x0B00
  230. #define RH_SYNC_FRAME           0x0C80
  231. /* Our Vendor Specific Request */
  232. #define RH_SET_EP               0x2000
  233. /* Hub port features */
  234. #define RH_PORT_CONNECTION         0x00
  235. #define RH_PORT_ENABLE             0x01
  236. #define RH_PORT_SUSPEND            0x02
  237. #define RH_PORT_OVER_CURRENT       0x03
  238. #define RH_PORT_RESET              0x04
  239. #define RH_PORT_POWER              0x08
  240. #define RH_PORT_LOW_SPEED          0x09
  241. #define RH_C_PORT_CONNECTION       0x10
  242. #define RH_C_PORT_ENABLE           0x11
  243. #define RH_C_PORT_SUSPEND          0x12
  244. #define RH_C_PORT_OVER_CURRENT     0x13
  245. #define RH_C_PORT_RESET            0x14  
  246. /* Hub features */
  247. #define RH_C_HUB_LOCAL_POWER       0x00
  248. #define RH_C_HUB_OVER_CURRENT      0x01
  249. #define RH_DEVICE_REMOTE_WAKEUP    0x00
  250. #define RH_ENDPOINT_STALL          0x01
  251. #define RH_ACK                     0x01
  252. #define RH_REQ_ERR                 -1
  253. #define RH_NACK                    0x00
  254. /* OHCI ROOT HUB REGISTER MASKS */
  255.  
  256. /* roothub.portstatus [i] bits */
  257. #define RH_PS_CCS            0x00000001    /* current connect status */
  258. #define RH_PS_PES            0x00000002    /* port enable status*/
  259. #define RH_PS_PSS            0x00000004    /* port suspend status */
  260. #define RH_PS_POCI           0x00000008    /* port over current indicator */
  261. #define RH_PS_PRS            0x00000010   /* port reset status */
  262. #define RH_PS_PPS            0x00000100    /* port power status */
  263. #define RH_PS_LSDA           0x00000200     /* low speed device attached */
  264. #define RH_PS_CSC            0x00010000  /* connect status change */
  265. #define RH_PS_PESC           0x00020000    /* port enable status change */
  266. #define RH_PS_PSSC           0x00040000     /* port suspend status change */
  267. #define RH_PS_OCIC           0x00080000     /* over current indicator change */
  268. #define RH_PS_PRSC           0x00100000    /* port reset status change */
  269. /* roothub.status bits */
  270. #define RH_HS_LPS      0x00000001 /* local power status */
  271. #define RH_HS_OCI      0x00000002 /* over current indicator */
  272. #define RH_HS_DRWE      0x00008000 /* device remote wakeup enable */
  273. #define RH_HS_LPSC      0x00010000 /* local power status change */
  274. #define RH_HS_OCIC      0x00020000 /* over current indicator change */
  275. #define RH_HS_CRWE      0x80000000 /* clear remote wakeup enable */
  276. /* roothub.b masks */
  277. #define RH_B_DR 0x0000ffff /* device removable flags */
  278. #define RH_B_PPCM 0xffff0000 /* port power control mask */
  279. /* roothub.a masks */
  280. #define RH_A_NDP (0xff << 0) /* number of downstream ports */
  281. #define RH_A_PSM (1 << 8) /* power switching mode */
  282. #define RH_A_NPS (1 << 9) /* no power switching */
  283. #define RH_A_DT (1 << 10) /* device type (mbz) */
  284. #define RH_A_OCPM (1 << 11) /* over current protection mode */
  285. #define RH_A_NOCP (1 << 12) /* no over current protection */
  286. #define RH_A_POTPGT (0xff << 24) /* power on to power good time */
  287. /* urb */
  288. typedef struct 
  289. {
  290. ed_t * ed;
  291. __u16 length; // number of tds associated with this request
  292. __u16 td_cnt; // number of tds already serviced
  293. int   state;
  294. wait_queue_head_t * wait;
  295. td_t * td[0]; // list pointer to all corresponding TDs associated with this request
  296. } urb_priv_t;
  297. #define URB_DEL 1
  298. /* Hash struct used for TD/ED hashing */
  299. struct hash_t {
  300. void *virt;
  301. dma_addr_t dma;
  302. struct hash_t *next; // chaining for collision cases
  303. };
  304. /* List of TD/ED hash entries */
  305. struct hash_list_t {
  306. struct hash_t *head;
  307. struct hash_t *tail;
  308. };
  309. #define TD_HASH_SIZE    64    /* power'o'two */
  310. #define ED_HASH_SIZE    64    /* power'o'two */
  311. #define TD_HASH_FUNC(td_dma) ((td_dma ^ (td_dma >> 5)) % TD_HASH_SIZE)
  312. #define ED_HASH_FUNC(ed_dma) ((ed_dma ^ (ed_dma >> 5)) % ED_HASH_SIZE)
  313. /*
  314.  * This is the full ohci controller description
  315.  *
  316.  * Note how the "proper" USB information is just
  317.  * a subset of what the full implementation needs. (Linus)
  318.  */
  319. typedef struct ohci {
  320. struct ohci_hcca *hcca; /* hcca */
  321. dma_addr_t hcca_dma;
  322. int irq;
  323. int disabled; /* e.g. got a UE, we're hung */
  324. int sleeping;
  325. atomic_t resume_count; /* defending against multiple resumes */
  326. unsigned long flags; /* for HC bugs */
  327. #define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
  328. #define OHCI_QUIRK_SUCKYIO 0x02 /* NSC superio */
  329. struct ohci_regs * regs; /* OHCI controller's memory */
  330. struct list_head ohci_hcd_list; /* list of all ohci_hcd */
  331. struct ohci * next;  // chain of ohci device contexts
  332. struct list_head timeout_list;
  333. // struct list_head urb_list;  // list of all pending urbs
  334. // spinlock_t urb_list_lock;  // lock to keep consistency 
  335.   
  336. int ohci_int_load[32]; /* load of the 32 Interrupt Chains (for load balancing)*/
  337. ed_t * ed_rm_list[2];     /* lists of all endpoints to be removed */
  338. ed_t * ed_bulktail;       /* last endpoint of bulk list */
  339. ed_t * ed_controltail;    /* last endpoint of control list */
  340.   ed_t * ed_isotail;        /* last endpoint of iso list */
  341. int intrstatus;
  342. __u32 hc_control; /* copy of the hc control reg */
  343. struct usb_bus * bus;    
  344. struct usb_device * dev[128];
  345. struct virt_root_hub rh;
  346. /* PCI device handle, settings, ... */
  347. struct pci_dev *ohci_dev;
  348. u8 pci_latency;
  349. struct pci_pool *td_cache;
  350. struct pci_pool *dev_cache;
  351. struct hash_list_t td_hash[TD_HASH_SIZE];
  352. struct hash_list_t ed_hash[ED_HASH_SIZE];
  353. } ohci_t;
  354. #define NUM_EDS 32 /* num of preallocated endpoint descriptors */
  355. struct ohci_device {
  356. ed_t  ed[NUM_EDS];
  357. dma_addr_t dma;
  358. int ed_cnt;
  359. wait_queue_head_t * wait;
  360. };
  361. // #define ohci_to_usb(ohci) ((ohci)->usb)
  362. #define usb_to_ohci(usb) ((struct ohci_device *)(usb)->hcpriv)
  363. /* hcd */
  364. /* endpoint */
  365. static int ep_link(ohci_t * ohci, ed_t * ed);
  366. static int ep_unlink(ohci_t * ohci, ed_t * ed);
  367. static ed_t * ep_add_ed(struct usb_device * usb_dev, unsigned int pipe, int interval, int load, int mem_flags);
  368. static void ep_rm_ed(struct usb_device * usb_dev, ed_t * ed);
  369. /* td */
  370. static void td_fill(ohci_t * ohci, unsigned int info, dma_addr_t data, int len, struct urb * urb, int index);
  371. static void td_submit_urb(struct urb * urb);
  372. /* root hub */
  373. static int rh_submit_urb(struct urb * urb);
  374. static int rh_unlink_urb(struct urb * urb);
  375. static int rh_init_int_timer(struct urb * urb);
  376. /*-------------------------------------------------------------------------*/
  377. #define ALLOC_FLAGS (in_interrupt () || current->state != TASK_RUNNING ? GFP_ATOMIC : GFP_KERNEL)
  378. #ifdef DEBUG
  379. # define OHCI_MEM_FLAGS SLAB_POISON
  380. #else
  381. # define OHCI_MEM_FLAGS 0
  382. #endif
  383.  
  384. #ifndef CONFIG_PCI
  385. # error "usb-ohci currently requires PCI-based controllers"
  386. /* to support non-PCI OHCIs, you need custom bus/mem/... glue */
  387. #endif
  388. /* Recover a TD/ED using its collision chain */
  389. static inline void *
  390. dma_to_ed_td (struct hash_list_t * entry, dma_addr_t dma)
  391. {
  392. struct hash_t * scan = entry->head;
  393. while (scan && scan->dma != dma)
  394. scan = scan->next;
  395. if (!scan)
  396. BUG();
  397. return scan->virt;
  398. }
  399. static inline struct ed *
  400. dma_to_ed (struct ohci * hc, dma_addr_t ed_dma)
  401. {
  402. return (struct ed *) dma_to_ed_td(&(hc->ed_hash[ED_HASH_FUNC(ed_dma)]),
  403.       ed_dma);
  404. }
  405. static inline struct td *
  406. dma_to_td (struct ohci * hc, dma_addr_t td_dma)
  407. {
  408. return (struct td *) dma_to_ed_td(&(hc->td_hash[TD_HASH_FUNC(td_dma)]),
  409.       td_dma);
  410. }
  411. /* Add a hash entry for a TD/ED; return true on success */
  412. static inline int
  413. hash_add_ed_td(struct hash_list_t * entry, void * virt, dma_addr_t dma)
  414. {
  415. struct hash_t * scan;
  416. scan = (struct hash_t *)kmalloc(sizeof(struct hash_t), ALLOC_FLAGS);
  417. if (!scan)
  418. return 0;
  419. if (!entry->tail) {
  420. entry->head = entry->tail = scan;
  421. } else {
  422. entry->tail->next = scan;
  423. entry->tail = scan;
  424. }
  425. scan->virt = virt;
  426. scan->dma = dma;
  427. scan->next = NULL;
  428. return 1;
  429. }
  430. static inline int
  431. hash_add_ed (struct ohci * hc, struct ed * ed)
  432. {
  433. return hash_add_ed_td (&(hc->ed_hash[ED_HASH_FUNC(ed->dma)]),
  434. ed, ed->dma);
  435. }
  436. static inline int
  437. hash_add_td (struct ohci * hc, struct td * td)
  438. {
  439. return hash_add_ed_td (&(hc->td_hash[TD_HASH_FUNC(td->td_dma)]),
  440. td, td->td_dma);
  441. }
  442. static inline void
  443. hash_free_ed_td (struct hash_list_t * entry, void * virt)
  444. {
  445. struct hash_t *scan, *prev;
  446. scan = prev = entry->head;
  447. // Find and unlink hash entry
  448. while (scan && scan->virt != virt) {
  449. prev = scan;
  450. scan = scan->next;
  451. }
  452. if (scan) {
  453. if (scan == entry->head) {
  454. if (entry->head == entry->tail)
  455. entry->head = entry->tail = NULL;
  456. else
  457. entry->head = scan->next;
  458. } else if (scan == entry->tail) {
  459. entry->tail = prev;
  460. prev->next = NULL;
  461. } else
  462. prev->next = scan->next;
  463. kfree(scan);
  464. }
  465. }
  466. static inline void
  467. hash_free_ed (struct ohci * hc, struct ed * ed)
  468. {
  469. hash_free_ed_td (&(hc->ed_hash[ED_HASH_FUNC(ed->dma)]), ed);
  470. }
  471. static inline void
  472. hash_free_td (struct ohci * hc, struct td * td)
  473. {
  474. hash_free_ed_td (&(hc->td_hash[TD_HASH_FUNC(td->td_dma)]), td);
  475. }
  476. static int ohci_mem_init (struct ohci *ohci)
  477. {
  478. ohci->td_cache = pci_pool_create ("ohci_td", ohci->ohci_dev,
  479. sizeof (struct td),
  480. 32 /* byte alignment */,
  481. 0 /* no page-crossing issues */,
  482. GFP_KERNEL | OHCI_MEM_FLAGS);
  483. if (!ohci->td_cache)
  484. return -ENOMEM;
  485. ohci->dev_cache = pci_pool_create ("ohci_dev", ohci->ohci_dev,
  486. sizeof (struct ohci_device),
  487. 16 /* byte alignment */,
  488. 0 /* no page-crossing issues */,
  489. GFP_KERNEL | OHCI_MEM_FLAGS);
  490. if (!ohci->dev_cache)
  491. return -ENOMEM;
  492. return 0;
  493. }
  494. static void ohci_mem_cleanup (struct ohci *ohci)
  495. {
  496. if (ohci->td_cache) {
  497. pci_pool_destroy (ohci->td_cache);
  498. ohci->td_cache = 0;
  499. }
  500. if (ohci->dev_cache) {
  501. pci_pool_destroy (ohci->dev_cache);
  502. ohci->dev_cache = 0;
  503. }
  504. }
  505. /* TDs ... */
  506. static inline struct td *
  507. td_alloc (struct ohci *hc, int mem_flags)
  508. {
  509. dma_addr_t dma;
  510. struct td *td;
  511. td = pci_pool_alloc (hc->td_cache, mem_flags, &dma);
  512. if (td) {
  513. td->td_dma = dma;
  514. /* hash it for later reverse mapping */
  515. if (!hash_add_td (hc, td)) {
  516. pci_pool_free (hc->td_cache, td, dma);
  517. return NULL;
  518. }
  519. }
  520. return td;
  521. }
  522. static inline void
  523. td_free (struct ohci *hc, struct td *td)
  524. {
  525. hash_free_td (hc, td);
  526. pci_pool_free (hc->td_cache, td, td->td_dma);
  527. }
  528. /* DEV + EDs ... only the EDs need to be consistent */
  529. static inline struct ohci_device *
  530. dev_alloc (struct ohci *hc, int mem_flags)
  531. {
  532. dma_addr_t dma;
  533. struct ohci_device *dev;
  534. int i, offset;
  535. dev = pci_pool_alloc (hc->dev_cache, mem_flags, &dma);
  536. if (dev) {
  537. memset (dev, 0, sizeof (*dev));
  538. dev->dma = dma;
  539. offset = ((char *)&dev->ed) - ((char *)dev);
  540. for (i = 0; i < NUM_EDS; i++, offset += sizeof dev->ed [0])
  541. dev->ed [i].dma = dma + offset;
  542. /* add to hashtable if used */
  543. }
  544. return dev;
  545. }
  546. static inline void
  547. dev_free (struct ohci *hc, struct ohci_device *dev)
  548. {
  549. pci_pool_free (hc->dev_cache, dev, dev->dma);
  550. }