source: mainline/uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.h@ 0d4b110

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0d4b110 was 0d4b110, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

ohci: Sanitize includes.

Include what you use.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup drvusbohci
29 * @{
30 */
31/** @file
32 * @brief OHCI driver
33 */
34#ifndef DRV_OHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
35#define DRV_OHCI_HW_STRUCT_TRANSFER_DESCRIPTOR_H
36
37#include <assert.h>
38#include <stdbool.h>
39#include <stdint.h>
40
41#include "mem_access.h"
42#include "completion_codes.h"
43
44/* OHCI TDs can handle up to 8KB buffers, however, it can use max 2 pages.
45 * Using 4KB buffers guarantees the page count condition.
46 * (OHCI assumes 4KB pages) */
47#define OHCI_TD_MAX_TRANSFER (4 * 1024)
48
49/**
50 * Transfer Descriptor representation.
51 *
52 * See OHCI spec chapter 4.3.1 General Transfer Descriptor on page 19
53 * (pdf page 33) for details.
54 */
55typedef struct td {
56 /** Status field. Do not touch on active TDs. */
57 volatile uint32_t status;
58#define TD_STATUS_ROUND_FLAG (1 << 18)
59#define TD_STATUS_DP_MASK (0x3) /* Direction/PID */
60#define TD_STATUS_DP_SHIFT (19)
61#define TD_STATUS_DP_SETUP (0x0)
62#define TD_STATUS_DP_OUT (0x1)
63#define TD_STATUS_DP_IN (0x2)
64#define TD_STATUS_DI_MASK (0x7) /* Delay interrupt, wait n frames before irq */
65#define TD_STATUS_DI_SHIFT (21)
66#define TD_STATUS_DI_NO_INTERRUPT (0x7)
67#define TD_STATUS_T_FLAG (1 << 24) /* Explicit toggle bit value for this TD */
68#define TD_STATUS_T_USE_TD_FLAG (1 << 25) /* 1 = use bit 24 as toggle bit */
69#define TD_STATUS_EC_MASK (0x3) /* Error count */
70#define TD_STATUS_EC_SHIFT (26)
71#define TD_STATUS_CC_MASK (0xf) /* Condition code */
72#define TD_STATUS_CC_SHIFT (28)
73
74 /**
75 * Current buffer pointer.
76 * Phys address of the first byte to be transferred. */
77 volatile uint32_t cbp;
78
79 /** Pointer to the next TD in chain. 16-byte aligned. */
80 volatile uint32_t next;
81#define TD_NEXT_PTR_MASK (0xfffffff0)
82#define TD_NEXT_PTR_SHIFT (0)
83
84 /**
85 * Buffer end.
86 * Phys address of the last byte of the transfer.
87 * @note this does not have to be on the same page as cbp.
88 */
89 volatile uint32_t be;
90} __attribute__((packed)) td_t;
91
92void td_init(td_t *instance, const td_t *next,
93 usb_direction_t dir, const void *buffer, size_t size, int toggle);
94
95/**
96 * Check TD for completion.
97 * @param instance TD structure.
98 * @return true if the TD was accessed and processed by hw, false otherwise.
99 */
100inline static bool td_is_finished(const td_t *instance)
101{
102 assert(instance);
103 const int cc =(OHCI_MEM32_RD(instance->status)
104 >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
105 /* This value is changed on transfer completion,
106 * either to CC_NOERROR or and error code.
107 * See OHCI spec 4.3.1.3.5 p. 23 (pdf 37) */
108 if (cc != CC_NOACCESS1 && cc != CC_NOACCESS2) {
109 return true;
110 }
111 return false;
112}
113
114/**
115 * Get error code that indicates transfer status.
116 * @param instance TD structure.
117 * @return Error code.
118 */
119static inline int td_error(const td_t *instance)
120{
121 assert(instance);
122 const int cc = (OHCI_MEM32_RD(instance->status)
123 >> TD_STATUS_CC_SHIFT) & TD_STATUS_CC_MASK;
124 return cc_to_rc(cc);
125}
126
127/**
128 * Get remaining portion of buffer to be read/written
129 * @param instance TD structure
130 * @return size of remaining buffer.
131 */
132static inline size_t td_remain_size(td_t *instance)
133{
134 assert(instance);
135 /* Current buffer pointer is cleared on successful transfer */
136 if (instance->cbp == 0)
137 return 0;
138 /* Buffer end points to the last byte of transfer buffer, so add 1 */
139 return OHCI_MEM32_RD(instance->be) - OHCI_MEM32_RD(instance->cbp) + 1;
140}
141#endif
142/**
143 * @}
144 */
Note: See TracBrowser for help on using the repository browser.