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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * ohci1394.h - driver for OHCI 1394 boards
  3.  * Copyright (C)1999,2000 Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au>
  4.  *                        Gord Peters <GordPeters@smarttech.com>
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software Foundation,
  18.  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  */
  20. #ifndef _OHCI1394_H
  21. #define _OHCI1394_H
  22. #include <asm/io.h>
  23. #include "ieee1394_types.h"
  24. #include <asm/io.h>
  25. #define OHCI1394_DRIVER_NAME      "ohci1394"
  26. #define OHCI1394_MAX_AT_REQ_RETRIES 0x2
  27. #define OHCI1394_MAX_AT_RESP_RETRIES 0x2
  28. #define OHCI1394_MAX_PHYS_RESP_RETRIES 0x8
  29. #define OHCI1394_MAX_SELF_ID_ERRORS 16
  30. #define AR_REQ_NUM_DESC 4 /* number of AR req descriptors */
  31. #define AR_REQ_BUF_SIZE PAGE_SIZE /* size of AR req buffers */
  32. #define AR_REQ_SPLIT_BUF_SIZE PAGE_SIZE /* split packet buffer */
  33. #define AR_RESP_NUM_DESC 4 /* number of AR resp descriptors */
  34. #define AR_RESP_BUF_SIZE PAGE_SIZE /* size of AR resp buffers */
  35. #define AR_RESP_SPLIT_BUF_SIZE PAGE_SIZE /* split packet buffer */
  36. #define IR_NUM_DESC 16 /* number of IR descriptors */
  37. #define IR_BUF_SIZE PAGE_SIZE /* 4096 bytes/buffer */
  38. #define IR_SPLIT_BUF_SIZE PAGE_SIZE /* split packet buffer */
  39. #define IT_NUM_DESC 16 /* number of IT descriptors */
  40. #define AT_REQ_NUM_DESC 32 /* number of AT req descriptors */
  41. #define AT_RESP_NUM_DESC 32 /* number of AT resp descriptors */
  42. #define OHCI_LOOP_COUNT 100 /* Number of loops for reg read waits */
  43. #define OHCI_CONFIG_ROM_LEN 1024 /* Length of the mapped configrom space */
  44. #define OHCI1394_SI_DMA_BUF_SIZE 8192 /* length of the selfid buffer */
  45. /* PCI configuration space addresses */
  46. #define OHCI1394_PCI_HCI_Control 0x40
  47. struct dma_cmd {
  48.         u32 control;
  49.         u32 address;
  50.         u32 branchAddress;
  51.         u32 status;
  52. };
  53. /*
  54.  * FIXME:
  55.  * It is important that a single at_dma_prg does not cross a page boundary
  56.  * The proper way to do it would be to do the check dynamically as the
  57.  * programs are inserted into the AT fifo.
  58.  */
  59. struct at_dma_prg {
  60. struct dma_cmd begin;
  61. quadlet_t data[4];
  62. struct dma_cmd end;
  63. quadlet_t pad[4]; /* FIXME: quick hack for memory alignment */
  64. };
  65. /* identify whether a DMA context is asynchronous or isochronous */
  66. enum context_type { DMA_CTX_ASYNC_REQ, DMA_CTX_ASYNC_RESP, DMA_CTX_ISO };
  67. /* DMA receive context */
  68. struct dma_rcv_ctx {
  69. struct ti_ohci *ohci;
  70. enum context_type type;
  71. int ctx;
  72. unsigned int num_desc;
  73. unsigned int buf_size;
  74. unsigned int split_buf_size;
  75. /* dma block descriptors */
  76.         struct dma_cmd **prg_cpu;
  77.         dma_addr_t *prg_bus;
  78. /* dma buffers */
  79.         quadlet_t **buf_cpu;
  80.         dma_addr_t *buf_bus;
  81.         unsigned int buf_ind;
  82.         unsigned int buf_offset;
  83.         quadlet_t *spb;
  84.         spinlock_t lock;
  85.         struct tasklet_struct task;
  86. int ctrlClear;
  87. int ctrlSet;
  88. int cmdPtr;
  89. };
  90. /* DMA transmit context */
  91. struct dma_trm_ctx {
  92. struct ti_ohci *ohci;
  93. enum context_type type;
  94. int ctx;
  95. unsigned int num_desc;
  96. /* dma block descriptors */
  97.         struct at_dma_prg **prg_cpu;
  98. dma_addr_t *prg_bus;
  99.         unsigned int prg_ind;
  100.         unsigned int sent_ind;
  101. int free_prgs;
  102.         quadlet_t *branchAddrPtr;
  103. /* list of packets inserted in the AT FIFO */
  104. struct list_head fifo_list;
  105. /* list of pending packets to be inserted in the AT FIFO */
  106. struct list_head pending_list;
  107.         spinlock_t lock;
  108.         struct tasklet_struct task;
  109. int ctrlClear;
  110. int ctrlSet;
  111. int cmdPtr;
  112. };
  113. struct ohci1394_iso_tasklet {
  114. struct tasklet_struct tasklet;
  115. struct list_head link;
  116. int context;
  117. enum { OHCI_ISO_TRANSMIT, OHCI_ISO_RECEIVE } type;
  118. };
  119. struct ti_ohci {
  120.         int id; /* sequential card number */
  121.         struct pci_dev *dev;
  122. enum { 
  123. OHCI_INIT_ALLOC_HOST,
  124. OHCI_INIT_HAVE_MEM_REGION,
  125. OHCI_INIT_HAVE_IOMAPPING,
  126. OHCI_INIT_HAVE_CONFIG_ROM_BUFFER,
  127. OHCI_INIT_HAVE_SELFID_BUFFER,
  128. OHCI_INIT_HAVE_TXRX_BUFFERS__MAYBE,
  129. OHCI_INIT_HAVE_IRQ,
  130. OHCI_INIT_DONE,
  131. } init_state;
  132.         
  133.         /* remapped memory spaces */
  134.         void *registers; 
  135. /* dma buffer for self-id packets */
  136.         quadlet_t *selfid_buf_cpu;
  137.         dma_addr_t selfid_buf_bus;
  138. /* buffer for csr config rom */
  139.         quadlet_t *csr_config_rom_cpu; 
  140.         dma_addr_t csr_config_rom_bus; 
  141. int csr_config_rom_length;
  142. unsigned int max_packet_size;
  143.         /* async receive */
  144. struct dma_rcv_ctx ar_resp_context;
  145. struct dma_rcv_ctx ar_req_context;
  146. /* async transmit */
  147. struct dma_trm_ctx at_resp_context;
  148. struct dma_trm_ctx at_req_context;
  149.         /* iso receive */
  150. struct dma_rcv_ctx ir_context;
  151. struct ohci1394_iso_tasklet ir_tasklet;
  152.         spinlock_t IR_channel_lock;
  153. int nb_iso_rcv_ctx;
  154. unsigned long ir_ctx_usage; /* use test_and_set_bit() for atomicity */
  155.         /* iso transmit */
  156. struct dma_trm_ctx it_context;
  157. struct ohci1394_iso_tasklet it_tasklet;
  158. int nb_iso_xmit_ctx;
  159. unsigned long it_ctx_usage; /* use test_and_set_bit() for atomicity */
  160.         u64 ISO_channel_usage;
  161.         /* IEEE-1394 part follows */
  162.         struct hpsb_host *host;
  163.         int phyid, isroot;
  164.         spinlock_t phy_reg_lock;
  165. spinlock_t event_lock;
  166. int self_id_errors;
  167. /* Tasklets for iso receive and transmit, used by video1394,
  168.  * amdtp and dv1394 */
  169. struct list_head iso_tasklet_list;
  170. spinlock_t iso_tasklet_list_lock;
  171. /* Swap the selfid buffer? */
  172. unsigned int selfid_swap:1;
  173. /* Some Apple chipset seem to swap incoming headers for us */
  174. unsigned int no_swap_incoming:1;
  175. };
  176. static inline int cross_bound(unsigned long addr, unsigned int size)
  177. {
  178. int cross=0;
  179. if (size>PAGE_SIZE) {
  180. cross = size/PAGE_SIZE;
  181. size -= cross*PAGE_SIZE;
  182. }
  183. if ((PAGE_SIZE-addr%PAGE_SIZE)<size)
  184. cross++;
  185. return cross;
  186. }
  187. /*
  188.  * Register read and write helper functions.
  189.  */
  190. static inline void reg_write(const struct ti_ohci *ohci, int offset, u32 data)
  191. {
  192.         writel(data, ohci->registers + offset);
  193. }
  194. static inline u32 reg_read(const struct ti_ohci *ohci, int offset)
  195. {
  196.         return readl(ohci->registers + offset);
  197. }
  198. /* 2 KiloBytes of register space */
  199. #define OHCI1394_REGISTER_SIZE                0x800       
  200. /* Offsets relative to context bases defined below */
  201. #define OHCI1394_ContextControlSet            0x000
  202. #define OHCI1394_ContextControlClear          0x004
  203. #define OHCI1394_ContextCommandPtr            0x00C
  204. /* register map */
  205. #define OHCI1394_Version                      0x000
  206. #define OHCI1394_GUID_ROM                     0x004
  207. #define OHCI1394_ATRetries                    0x008
  208. #define OHCI1394_CSRData                      0x00C
  209. #define OHCI1394_CSRCompareData               0x010
  210. #define OHCI1394_CSRControl                   0x014
  211. #define OHCI1394_ConfigROMhdr                 0x018
  212. #define OHCI1394_BusID                        0x01C
  213. #define OHCI1394_BusOptions                   0x020
  214. #define OHCI1394_GUIDHi                       0x024
  215. #define OHCI1394_GUIDLo                       0x028
  216. #define OHCI1394_ConfigROMmap                 0x034
  217. #define OHCI1394_PostedWriteAddressLo         0x038
  218. #define OHCI1394_PostedWriteAddressHi         0x03C
  219. #define OHCI1394_VendorID                     0x040
  220. #define OHCI1394_HCControlSet                 0x050
  221. #define OHCI1394_HCControlClear               0x054
  222. #define OHCI1394_SelfIDBuffer                 0x064
  223. #define OHCI1394_SelfIDCount                  0x068
  224. #define OHCI1394_IRMultiChanMaskHiSet         0x070
  225. #define OHCI1394_IRMultiChanMaskHiClear       0x074
  226. #define OHCI1394_IRMultiChanMaskLoSet         0x078
  227. #define OHCI1394_IRMultiChanMaskLoClear       0x07C
  228. #define OHCI1394_IntEventSet                  0x080
  229. #define OHCI1394_IntEventClear                0x084
  230. #define OHCI1394_IntMaskSet                   0x088
  231. #define OHCI1394_IntMaskClear                 0x08C
  232. #define OHCI1394_IsoXmitIntEventSet           0x090
  233. #define OHCI1394_IsoXmitIntEventClear         0x094
  234. #define OHCI1394_IsoXmitIntMaskSet            0x098
  235. #define OHCI1394_IsoXmitIntMaskClear          0x09C
  236. #define OHCI1394_IsoRecvIntEventSet           0x0A0
  237. #define OHCI1394_IsoRecvIntEventClear         0x0A4
  238. #define OHCI1394_IsoRecvIntMaskSet            0x0A8
  239. #define OHCI1394_IsoRecvIntMaskClear          0x0AC
  240. #define OHCI1394_FairnessControl              0x0DC
  241. #define OHCI1394_LinkControlSet               0x0E0
  242. #define OHCI1394_LinkControlClear             0x0E4
  243. #define OHCI1394_NodeID                       0x0E8
  244. #define OHCI1394_PhyControl                   0x0EC
  245. #define OHCI1394_IsochronousCycleTimer        0x0F0
  246. #define OHCI1394_AsReqFilterHiSet             0x100
  247. #define OHCI1394_AsReqFilterHiClear           0x104
  248. #define OHCI1394_AsReqFilterLoSet             0x108
  249. #define OHCI1394_AsReqFilterLoClear           0x10C
  250. #define OHCI1394_PhyReqFilterHiSet            0x110
  251. #define OHCI1394_PhyReqFilterHiClear          0x114
  252. #define OHCI1394_PhyReqFilterLoSet            0x118
  253. #define OHCI1394_PhyReqFilterLoClear          0x11C
  254. #define OHCI1394_PhyUpperBound                0x120
  255. #define OHCI1394_AsReqTrContextBase           0x180
  256. #define OHCI1394_AsReqTrContextControlSet     0x180
  257. #define OHCI1394_AsReqTrContextControlClear   0x184
  258. #define OHCI1394_AsReqTrCommandPtr            0x18C
  259. #define OHCI1394_AsRspTrContextBase           0x1A0
  260. #define OHCI1394_AsRspTrContextControlSet     0x1A0
  261. #define OHCI1394_AsRspTrContextControlClear   0x1A4
  262. #define OHCI1394_AsRspTrCommandPtr            0x1AC
  263. #define OHCI1394_AsReqRcvContextBase          0x1C0
  264. #define OHCI1394_AsReqRcvContextControlSet    0x1C0
  265. #define OHCI1394_AsReqRcvContextControlClear  0x1C4
  266. #define OHCI1394_AsReqRcvCommandPtr           0x1CC
  267. #define OHCI1394_AsRspRcvContextBase          0x1E0
  268. #define OHCI1394_AsRspRcvContextControlSet    0x1E0
  269. #define OHCI1394_AsRspRcvContextControlClear  0x1E4
  270. #define OHCI1394_AsRspRcvCommandPtr           0x1EC
  271. /* Isochronous transmit registers */
  272. /* Add (16 * n) for context n */
  273. #define OHCI1394_IsoXmitContextBase           0x200
  274. #define OHCI1394_IsoXmitContextControlSet     0x200
  275. #define OHCI1394_IsoXmitContextControlClear   0x204
  276. #define OHCI1394_IsoXmitCommandPtr            0x20C
  277. /* Isochronous receive registers */
  278. /* Add (32 * n) for context n */
  279. #define OHCI1394_IsoRcvContextBase            0x400
  280. #define OHCI1394_IsoRcvContextControlSet      0x400
  281. #define OHCI1394_IsoRcvContextControlClear    0x404
  282. #define OHCI1394_IsoRcvCommandPtr             0x40C
  283. #define OHCI1394_IsoRcvContextMatch           0x410
  284. /* Interrupts Mask/Events */
  285. #define OHCI1394_reqTxComplete           0x00000001
  286. #define OHCI1394_respTxComplete          0x00000002
  287. #define OHCI1394_ARRQ                    0x00000004
  288. #define OHCI1394_ARRS                    0x00000008
  289. #define OHCI1394_RQPkt                   0x00000010
  290. #define OHCI1394_RSPkt                   0x00000020
  291. #define OHCI1394_isochTx                 0x00000040
  292. #define OHCI1394_isochRx                 0x00000080
  293. #define OHCI1394_postedWriteErr          0x00000100
  294. #define OHCI1394_lockRespErr             0x00000200
  295. #define OHCI1394_selfIDComplete          0x00010000
  296. #define OHCI1394_busReset                0x00020000
  297. #define OHCI1394_phy                     0x00080000
  298. #define OHCI1394_cycleSynch              0x00100000
  299. #define OHCI1394_cycle64Seconds          0x00200000
  300. #define OHCI1394_cycleLost               0x00400000
  301. #define OHCI1394_cycleInconsistent       0x00800000
  302. #define OHCI1394_unrecoverableError      0x01000000
  303. #define OHCI1394_cycleTooLong            0x02000000
  304. #define OHCI1394_phyRegRcvd              0x04000000
  305. #define OHCI1394_masterIntEnable         0x80000000
  306. /* DMA Control flags */
  307. #define DMA_CTL_OUTPUT_MORE              0x00000000
  308. #define DMA_CTL_OUTPUT_LAST              0x10000000
  309. #define DMA_CTL_INPUT_MORE               0x20000000
  310. #define DMA_CTL_INPUT_LAST               0x30000000
  311. #define DMA_CTL_UPDATE                   0x08000000
  312. #define DMA_CTL_IMMEDIATE                0x02000000
  313. #define DMA_CTL_IRQ                      0x00300000
  314. #define DMA_CTL_BRANCH                   0x000c0000
  315. #define DMA_CTL_WAIT                     0x00030000
  316. /* OHCI evt_* error types, table 3-2 of the OHCI 1.1 spec. */
  317. #define EVT_NO_STATUS 0x0 /* No event status */
  318. #define EVT_RESERVED 0x1 /* Reserved, not used !!! */
  319. #define EVT_LONG_PACKET 0x2 /* The revc data was longer than the buf */
  320. #define EVT_MISSING_ACK 0x3 /* A subaction gap was detected before an ack
  321.    arrived, or recv'd ack had a parity error */
  322. #define EVT_UNDERRUN 0x4 /* Underrun on corresponding FIFO, packet
  323.    truncated */
  324. #define EVT_OVERRUN 0x5 /* A recv FIFO overflowed on reception of ISO
  325.    packet */
  326. #define EVT_DESCRIPTOR_READ 0x6 /* An unrecoverable error occured while host was
  327.    reading a descriptor block */
  328. #define EVT_DATA_READ 0x7 /* An error occured while host controller was
  329.    attempting to read from host memory in the data
  330.    stage of descriptor processing */
  331. #define EVT_DATA_WRITE 0x8 /* An error occured while host controller was
  332.    attempting to write either during the data stage
  333.    of descriptor processing, or when processing a single
  334.    16-bit host memory write */
  335. #define EVT_BUS_RESET 0x9 /* Identifies a PHY packet in the recv buffer as
  336.    being a synthesized bus reset packet */
  337. #define OHCI1394_TCODE_PHY               0xE
  338. void ohci1394_init_iso_tasklet(struct ohci1394_iso_tasklet *tasklet, 
  339.        int type,
  340.        void (*func)(unsigned long), 
  341.        unsigned long data);
  342. int ohci1394_register_iso_tasklet(struct ti_ohci *ohci,
  343.   struct ohci1394_iso_tasklet *tasklet);
  344. void ohci1394_unregister_iso_tasklet(struct ti_ohci *ohci,
  345.      struct ohci1394_iso_tasklet *tasklet);
  346. void ohci1394_stop_context      (struct ti_ohci *ohci, int reg, char *msg);
  347. struct ti_ohci *ohci1394_get_struct(int card_num);
  348. #endif