source: mainline/uspace/drv/uhci-hcd/uhci_struct/transfer_descriptor.h@ 9a818a9

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

Adds support for tracker scheduling and callback

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * Copyright (c) 2010 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 usb
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
34#ifndef DRV_UHCI_TRANSFER_DESCRIPTOR_H
35#define DRV_UHCI_TRANSFER_DESCRIPTOR_H
36
37#include <mem.h>
38#include <usb/usb.h>
39
40#include "utils/malloc32.h"
41#include "callback.h"
42#include "link_pointer.h"
43
44/** UHCI Transfer Descriptor */
45typedef struct transfer_descriptor {
46 link_pointer_t next;
47
48 volatile uint32_t status;
49
50#define TD_STATUS_RESERVED_MASK 0xc000f800
51#define TD_STATUS_SPD_FLAG ( 1 << 29 )
52#define TD_STATUS_ERROR_COUNT_POS ( 27 )
53#define TD_STATUS_ERROR_COUNT_MASK ( 0x3 )
54#define TD_STATUS_ERROR_COUNT_DEFAULT 3
55#define TD_STATUS_LOW_SPEED_FLAG ( 1 << 26 )
56#define TD_STATUS_ISOCHRONOUS_FLAG ( 1 << 25 )
57#define TD_STATUS_COMPLETE_INTERRUPT_FLAG ( 1 << 24 )
58
59#define TD_STATUS_ERROR_ACTIVE ( 1 << 23 )
60#define TD_STATUS_ERROR_STALLED ( 1 << 22 )
61#define TD_STATUS_ERROR_BUFFER ( 1 << 21 )
62#define TD_STATUS_ERROR_BABBLE ( 1 << 20 )
63#define TD_STATUS_ERROR_NAK ( 1 << 19 )
64#define TD_STATUS_ERROR_CRC ( 1 << 18 )
65#define TD_STATUS_ERROR_BIT_STUFF ( 1 << 17 )
66#define TD_STATUS_ERROR_RESERVED ( 1 << 16 )
67#define TD_STATUS_ERROR_POS 16
68#define TD_STATUS_ERROR_MASK ( 0xff )
69
70#define TD_STATUS_ACTLEN_POS 0
71#define TD_STATUS_ACTLEN_MASK 0x7ff
72
73 volatile uint32_t device;
74
75#define TD_DEVICE_MAXLEN_POS 21
76#define TD_DEVICE_MAXLEN_MASK ( 0x7ff )
77#define TD_DEVICE_RESERVED_FLAG ( 1 << 20 )
78#define TD_DEVICE_DATA_TOGGLE_ONE_FLAG ( 1 << 19 )
79#define TD_DEVICE_ENDPOINT_POS 15
80#define TD_DEVICE_ENDPOINT_MASK ( 0xf )
81#define TD_DEVICE_ADDRESS_POS 8
82#define TD_DEVICE_ADDRESS_MASK ( 0x7f )
83#define TD_DEVICE_PID_POS 0
84#define TD_DEVICE_PID_MASK ( 0xff )
85
86 volatile uint32_t buffer_ptr;
87
88 /* there is 16 bytes of data available here
89 * those are used to store callback pointer
90 * and next pointer. Thus, there is some free space
91 * on 32bits systems.
92 */
93 struct transfer_descriptor *next_va;
94 callback_t *callback;
95} __attribute__((packed)) transfer_descriptor_t;
96
97
98void transfer_descriptor_init(transfer_descriptor_t *instance,
99 int error_count, size_t size, bool isochronous, usb_target_t target,
100 int pid, void *buffer);
101
102static inline transfer_descriptor_t * transfer_descriptor_get(
103 int error_count, size_t size, bool isochronous, usb_target_t target,
104 int pid, void *buffer)
105{
106 transfer_descriptor_t * instance =
107 malloc32(sizeof(transfer_descriptor_t));
108
109 if (instance)
110 transfer_descriptor_init(
111 instance, error_count, size, isochronous, target, pid, buffer);
112 return instance;
113}
114
115void transfer_descriptor_fini(transfer_descriptor_t *instance);
116
117static inline void transfer_descriptor_dispose(transfer_descriptor_t *instance)
118{
119 assert(instance);
120 transfer_descriptor_fini(instance);
121 free32(instance);
122}
123
124int transfer_descriptor_status(transfer_descriptor_t *instance);
125
126static inline bool transfer_descriptor_is_active(
127 transfer_descriptor_t *instance)
128{
129 assert(instance);
130 return instance->status & TD_STATUS_ERROR_ACTIVE;
131}
132
133static inline void transfer_descriptor_append(
134 transfer_descriptor_t *instance, transfer_descriptor_t *item)
135{
136 assert(instance);
137 instance->next_va = item;
138 instance->next = (uintptr_t)addr_to_phys(item) & LINK_POINTER_ADDRESS_MASK;
139}
140#endif
141/**
142 * @}
143 */
Note: See TracBrowser for help on using the repository browser.