2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. 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 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27/* 28 * Including this file is mandatory for all USB related c-files in the kernel. 29 */ 30 31#ifndef _USB_CORE_H_ 32#define _USB_CORE_H_ 33 34/* 35 * The following macro will tell if an USB transfer is currently 36 * receiving or transferring data. 37 */ 38#define USB_GET_DATA_ISREAD(xfer) ((xfer)->flags_int.usb_mode == \ 39 USB_MODE_DEVICE ? (((xfer)->endpointno & UE_DIR_IN) ? 0 : 1) : \ 40 (((xfer)->endpointno & UE_DIR_IN) ? 1 : 0)) 41 42/* macros */ 43 44#define USB_BUS_LOCK(_b) mtx_lock(&(_b)->bus_mtx) 45#define USB_BUS_UNLOCK(_b) mtx_unlock(&(_b)->bus_mtx) 46#define USB_BUS_LOCK_ASSERT(_b, _t) mtx_assert(&(_b)->bus_mtx, _t) 47#define USB_XFER_LOCK(_x) mtx_lock((_x)->xroot->xfer_mtx) 48#define USB_XFER_UNLOCK(_x) mtx_unlock((_x)->xroot->xfer_mtx) 49#define USB_XFER_LOCK_ASSERT(_x, _t) mtx_assert((_x)->xroot->xfer_mtx, _t) 50 51/* helper for converting pointers to integers */ 52#define USB_P2U(ptr) \ 53 (((const uint8_t *)(ptr)) - ((const uint8_t *)0)) 54 55/* helper for computing offsets */ 56#define USB_ADD_BYTES(ptr,size) \ 57 ((void *)(USB_P2U(ptr) + (size))) 58 59/* debug macro */ 60#define USB_ASSERT KASSERT 61 62/* structure prototypes */ 63 64struct file; 65struct usb_bus; 66struct usb_device; 67struct usb_device_request; 68struct usb_page; 69struct usb_page_cache; 70struct usb_xfer; 71struct usb_xfer_root;
|