This is just an outline of the USB stack: what it is going to look like. It is definately not

ready for testing. Also the documentation is far from complete (it's in it's early phases).
Unfortunately I don't have enough experience in hardware programming to prototype
it first, so I'll be testing the things that I design in the document.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4275 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Niels Sascha Reedijk
2003-08-12 20:36:24 +00:00
parent e8d1b6e166
commit 1501c2bf3e
15 changed files with 1073 additions and 0 deletions
+189
View File
@@ -0,0 +1,189 @@
/*
** USB.h - Version 2 USB Device Driver API
**
** Copyright 1999, Be Incorporated. All Rights Reserved.
**
*/
#ifndef _USB_H
#define _USB_H
#include <KernelExport.h>
#include <bus_manager.h>
#include <USB_spec.h>
#include <USB_rle.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct usb_module_info usb_module_info;
/* these are opaque handles to internal stack objects */
typedef struct usb_device usb_device;
typedef struct usb_interface usb_interface;
typedef struct usb_pipe usb_pipe;
typedef struct usb_endpoint_info usb_endpoint_info;
typedef struct usb_interface_info usb_interface_info;
typedef struct usb_interface_list usb_interface_list;
typedef struct usb_configuration_info usb_configuration_info;
typedef struct usb_notify_hooks {
status_t (*device_added)(const usb_device *device, void **cookie);
status_t (*device_removed)(void *cookie);
} usb_notify_hooks;
typedef struct usb_support_descriptor {
uint8 dev_class;
uint8 dev_subclass;
uint8 dev_protocol;
uint16 vendor;
uint16 product;
} usb_support_descriptor;
/* ie, I support any hub device:
** usb_support_descriptor hub_devs = { 9, 0, 0, 0, 0 };
*/
struct usb_endpoint_info {
usb_endpoint_descriptor *descr; /* descriptor and handle */
usb_pipe *handle; /* of this endpoint/pipe */
};
struct usb_interface_info {
usb_interface_descriptor *descr; /* descriptor and handle */
usb_interface *handle; /* of this interface */
size_t endpoint_count; /* count and list of endpoints */
usb_endpoint_info *endpoint; /* in this interface */
size_t generic_count; /* unparsed descriptors in this */
usb_descriptor **generic; /* interface */
};
struct usb_interface_list {
size_t alt_count; /* count and list of alternate */
usb_interface_info *alt; /* interfaces available */
usb_interface_info *active; /* currently active alternate */
};
struct usb_configuration_info {
usb_configuration_descriptor *descr; /* descriptor of this config */
size_t interface_count; /* interfaces in this config */
usb_interface_list *interface;
};
typedef void (*usb_callback_func)(void *cookie, uint32 status,
void *data, uint32 actual_len);
struct usb_module_info {
bus_manager_info binfo;
/* inform the bus manager of our intent to support a set of devices */
status_t (*register_driver)(const char *driver_name,
const usb_support_descriptor *descriptors,
size_t count,
const char *optional_republish_driver_name);
/* request notification from the bus manager for add/remove of devices we
support */
status_t (*install_notify)(const char *driver_name,
const usb_notify_hooks *hooks);
status_t (*uninstall_notify)(const char *driver_name);
/* get the device descriptor */
const usb_device_descriptor *(*get_device_descriptor)(const usb_device *dev);
/* get the nth supported configuration */
const usb_configuration_info *(*get_nth_configuration)(const usb_device *dev, uint index);
/* get the active configuration */
const usb_configuration_info *(*get_configuration)(const usb_device *dev);
/* set the active configuration */
status_t (*set_configuration)(const usb_device *dev,
const usb_configuration_info *configuration);
status_t (*set_alt_interface)(const usb_device *dev,
const usb_interface_info *ifc);
/* standard device requests -- convenience functions */
/* obj may be a usb_device*, usb_pipe*, or usb_interface* */
status_t (*set_feature)(const void *object, uint16 selector);
status_t (*clear_feature)(const void *object, uint16 selector);
status_t (*get_status)(const void *object, uint16 *status);
status_t (*get_descriptor)(const usb_device *d,
uint8 type, uint8 index, uint16 lang,
void *data, size_t len, size_t *actual_len);
/* generic device request function */
status_t (*send_request)(const usb_device *d,
uint8 request_type, uint8 request,
uint16 value, uint16 index, uint16 length,
void *data, size_t data_len, size_t *actual_len);
/* async request queueing */
status_t (*queue_interrupt)(const usb_pipe *handle,
void *data, size_t len,
usb_callback_func notify, void *cookie);
status_t (*queue_bulk)(const usb_pipe *handle,
void *data, size_t len,
usb_callback_func notify, void *cookie);
status_t (*queue_isochronous)(const usb_pipe *handle,
void *data, size_t len,
rlea* rle_array, uint16 buffer_duration_ms,
usb_callback_func notify, void *cookie);
status_t (*queue_request)(const usb_device *d,
uint8 request_type, uint8 request,
uint16 value, uint16 index, uint16 length,
void *data, size_t data_len,
usb_callback_func notify, void *cookie);
status_t (*set_pipe_policy)(const usb_pipe *handle, uint8 max_num_queued_packets,
uint16 max_buffer_duration_ms, uint16 sample_size);
/* cancel pending async requests to an endpoint */
status_t (*cancel_queued_transfers)(const usb_pipe *handle);
/* tuning, timeouts, etc */
status_t (*usb_ioctl)(uint32 opcode, void* buf, size_t buf_size);
};
/* status code for usb callback functions */
#define B_USB_STATUS_SUCCESS 0x0000
#define B_USB_STATUS_DEVICE_CRC_ERROR 0x0002
#define B_USB_STATUS_DEVICE_TIMEOUT 0x0004
#define B_USB_STATUS_DEVICE_STALLED 0x0008
#define B_USB_STATUS_IRP_CANCELLED_BY_REQUEST 0x0010
#define B_USB_STATUS_DRIVER_INTERNAL_ERROR 0x0020
#define B_USB_STATUS_ADAPTER_HARDWARE_ERROR 0x0040
#define B_USB_STATUS_ISOCH_IRP_ABORTED 0x0080
/* result codes for usb bus manager functions */
#define B_USBD_SUCCESS 0
#define B_USBD_BAD_HANDLE 1
#define B_USBD_BAD_ARGS 2
#define B_USBD_NO_DATA 3
#define B_USBD_DEVICE_FAILURE 4
#define B_USBD_COMMAND_FAILED 5
#define B_USBD_PIPE_NOT_CONFIGURED 6
#define B_USBD_DEVICE_ERROR 7
#define B_USBD_PIPE_ERROR 8
#define B_USBD_NO_MEMORY 9
#define B_USB_MODULE_NAME "bus_managers/usb/v2"
#ifdef __cplusplus
}
#endif
#endif
+91
View File
@@ -0,0 +1,91 @@
/*
** USB_rle.h
**
** Copyright 1999, Be Incorporated. All Rights Reserved.
**
*/
#ifndef _USB_RLE_H
#define _USB_RLE_H
#ifdef __cplusplus
extern "C" {
#endif
struct _usbd_param_hdr;
/*
Run Length encoding records for isochronous IN transfers.
Run Length encoding records are used to identify which samples in
the buffer are good which are bad and which are missing.
Bad bytes are not extracted from the buffer, but are padded to next
nearest sample boundary. The ultimate consumer of the buffer
should also receive the RLE array.
RLE records are constructed based on the following rules:
1. an RLE record contains a sample count and a status
(good, bad, missing or unknown). A buffer has
associated with it an array of rle records. The number of
rle records available is specified in the RLE header. The
number used is also in the RLE header.
2. Within the scope of a buffer, successive packets with the
same completion status are represented with (1) rle record.
For example, after three transactions which have completion
status of success, the byte count in the rle record for this
position in the data stream represents the bytes received in
all three packets.
3. New rle records are initialized each time the status for a
given packet differs from that of the previous packet.
*/
#define RLE_GOOD 1
#define RLE_BAD 2
#define RLE_MISSING 3
#define RLE_UNKNOWN 4
/*
Name: rle
Purpose: used to represent the state of a portion of a data buffer
Fields:
rle_status will contain only the values: RLE_GOOD, RLE_BAD, RLE_MISSING
sample_count the number of usb samples in the buffer associated with this rle
record.
Notes:
If the buffer length field in queue_buffer_single structure changes to an
uint32 from uin16, then the sample_count data type must
track this change.
*/
typedef struct rle {
uint16 rle_status;
uint16 sample_count;
} rle;
/*
Name: rlea
Purpose: used as the primary rle information data structure between the
USB driver stack and a consuming client.
Fields:
length the number of rle records available in this structure.
num_valid filled in by the USB driver. indicates the number of valid
records filled.
rles[] unconstrained array of rle records.
*/
typedef struct rlea {
uint16 length;
uint16 num_valid;
rle rles[1];
} rlea;
#ifdef __cplusplus
}
#endif
#endif
+144
View File
@@ -0,0 +1,144 @@
/*
** USB_spec.h
**
** Copyright 1999, Be Incorporated. All Rights Reserved.
**
** This file contains structures and constants based on the USB Specification 1.1
**
*/
#ifndef _USB_SPEC_H
#define _USB_SPEC_H
#ifdef __cplusplus
extern "C" {
#endif
/* request types (target & direction) for send_request() */
/* cf USB Spec Rev 1.1, table 9-2, p 183 */
#define USB_REQTYPE_DEVICE_IN 0x80
#define USB_REQTYPE_DEVICE_OUT 0x00
#define USB_REQTYPE_INTERFACE_IN 0x81
#define USB_REQTYPE_INTERFACE_OUT 0x01
#define USB_REQTYPE_ENDPOINT_IN 0x82
#define USB_REQTYPE_ENDPOINT_OUT 0x02
#define USB_REQTYPE_OTHER_OUT 0x03
#define USB_REQTYPE_OTHER_IN 0x83
/* request types for send_request() */
/* cf USB Spec Rev 1.1, table 9-2, p 183 */
#define USB_REQTYPE_STANDARD 0x00
#define USB_REQTYPE_CLASS 0x20
#define USB_REQTYPE_VENDOR 0x40
#define USB_REQTYPE_RESERVED 0x60
#define USB_REQTYPE_MASK 0x9F
/* standard request values for send_request() */
/* cf USB Spec Rev 1.1, table 9-4, p 187 */
#define USB_REQUEST_GET_STATUS 0
#define USB_REQUEST_CLEAR_FEATURE 1
#define USB_REQUEST_SET_FEATURE 3
#define USB_REQUEST_SET_ADDRESS 5
#define USB_REQUEST_GET_DESCRIPTOR 6
#define USB_REQUEST_SET_DESCRIPTOR 7
#define USB_REQUEST_GET_CONFIGURATION 8
#define USB_REQUEST_SET_CONFIGURATION 9
#define USB_REQUEST_GET_INTERFACE 10
#define USB_REQUEST_SET_INTERFACE 11
#define USB_REQUEST_SYNCH_FRAME 12
/* used by {set,get}_descriptor() */
/* cf USB Spec Rev 1.1, table 9-5, p 187 */
#define USB_DESCRIPTOR_DEVICE 1
#define USB_DESCRIPTOR_CONFIGURATION 2
#define USB_DESCRIPTOR_STRING 3
#define USB_DESCRIPTOR_INTERFACE 4
#define USB_DESCRIPTOR_ENDPOINT 5
/* used by {set,clear}_feature() */
/* cf USB Spec Rev 1.1, table 9-6, p 188 */
#define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1
#define USB_FEATURE_ENDPOINT_HALT 0
typedef struct {
/* cf USB Spec Rev 1.1, table 9-7, p 197 */
uint8 length;
uint8 descriptor_type; /* USB_DESCRIPTOR_DEVICE */
uint16 usb_version; /* USB_DESCRIPTOR_DEVICE_LENGTH */
uint8 device_class;
uint8 device_subclass;
uint8 device_protocol;
uint8 max_packet_size_0;
uint16 vendor_id;
uint16 product_id;
uint16 device_version;
uint8 manufacturer;
uint8 product;
uint8 serial_number;
uint8 num_configurations;
} _PACKED usb_device_descriptor;
typedef struct {
/* cf USB Spec Rev 1.1, table 9-8, p 199 */
uint8 length;
uint8 descriptor_type; /* USB_DESCRIPTOR_CONFIGURATION */
uint16 total_length; /* USB_DESCRIPTOR_CONFIGURATION_LENGTH */
uint8 number_interfaces;
uint8 configuration_value;
uint8 configuration;
uint8 attributes;
uint8 max_power;
} _PACKED usb_configuration_descriptor;
typedef struct {
/* cf USB Spec Rev 1.1, table 9-9, p 202 */
uint8 length;
uint8 descriptor_type; /* USB_DESCRIPTOR_INTERFACE */
uint8 interface_number; /* USB_DESCRIPTOR_INTERFACE_LENGTH */
uint8 alternate_setting;
uint8 num_endpoints;
uint8 interface_class;
uint8 interface_subclass;
uint8 interface_protocol;
uint8 interface;
} _PACKED usb_interface_descriptor;
typedef struct {
/* cf USB Spec Rev 1.1, table 9-10, p 203 */
uint8 length;
uint8 descriptor_type; /* USB_DESCRIPTOR_ENDPOINT */
uint8 endpoint_address; /* USB_DESCRIPTOR_ENDPOINT_LENGTH */
uint8 attributes;
uint16 max_packet_size;
uint8 interval;
} _PACKED usb_endpoint_descriptor;
typedef struct {
/* cf USB Spec Rev 1.1, table 9-12, p 205 */
uint8 length; /* USB_DESCRIPTOR_STRING */
uint8 descriptor_type;
uchar string[1];
} _PACKED usb_string_descriptor;
typedef struct {
uint8 length;
uint8 descriptor_type;
uint8 data[1];
} _PACKED usb_generic_descriptor;
typedef union {
usb_generic_descriptor generic;
usb_device_descriptor device;
usb_interface_descriptor interface;
usb_endpoint_descriptor endpoint;
usb_configuration_descriptor configuration;
usb_string_descriptor string;
} usb_descriptor;
#ifdef __cplusplus
}
#endif
#endif