1f9f848faSopenharmony_ci/*- 2f9f848faSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause 3f9f848faSopenharmony_ci * 4f9f848faSopenharmony_ci * Copyright (c) 2008-2019 Hans Petter Selasky. All rights reserved. 5f9f848faSopenharmony_ci * 6f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without 7f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions 8f9f848faSopenharmony_ci * are met: 9f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright 10f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer. 11f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 12f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer in the 13f9f848faSopenharmony_ci * documentation and/or other materials provided with the distribution. 14f9f848faSopenharmony_ci * 15f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16f9f848faSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17f9f848faSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18f9f848faSopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19f9f848faSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20f9f848faSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21f9f848faSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22f9f848faSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23f9f848faSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24f9f848faSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25f9f848faSopenharmony_ci * SUCH DAMAGE. 26f9f848faSopenharmony_ci */ 27f9f848faSopenharmony_ci 28f9f848faSopenharmony_ci#ifndef _USB_BUS_H_ 29f9f848faSopenharmony_ci#define _USB_BUS_H_ 30f9f848faSopenharmony_ci 31f9f848faSopenharmony_ci/* 32f9f848faSopenharmony_ci * The following structure defines the USB explore message sent to the USB 33f9f848faSopenharmony_ci * explore process. 34f9f848faSopenharmony_ci */ 35f9f848faSopenharmony_ci 36f9f848faSopenharmony_cistruct usb_bus_msg { 37f9f848faSopenharmony_ci struct usb_proc_msg hdr; 38f9f848faSopenharmony_ci struct usb_bus *bus; 39f9f848faSopenharmony_ci}; 40f9f848faSopenharmony_ci 41f9f848faSopenharmony_ci/* 42f9f848faSopenharmony_ci * The following structure defines an USB BUS. There is one USB BUS 43f9f848faSopenharmony_ci * for every Host or Device controller. 44f9f848faSopenharmony_ci */ 45f9f848faSopenharmony_cistruct usb_bus { 46f9f848faSopenharmony_ci#if USB_HAVE_ROOT_MOUNT_HOLD 47f9f848faSopenharmony_ci struct root_hold_token *bus_roothold; 48f9f848faSopenharmony_ci#endif 49f9f848faSopenharmony_ci 50f9f848faSopenharmony_ci/* convenience macros */ 51f9f848faSopenharmony_ci#define USB_BUS_TT_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus) 52f9f848faSopenharmony_ci#define USB_BUS_CS_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus) 53f9f848faSopenharmony_ci 54f9f848faSopenharmony_ci#if USB_HAVE_PER_BUS_PROCESS 55f9f848faSopenharmony_ci#define USB_BUS_GIANT_PROC(bus) (&(bus)->giant_callback_proc) 56f9f848faSopenharmony_ci#define USB_BUS_NON_GIANT_ISOC_PROC(bus) (&(bus)->non_giant_isoc_callback_proc) 57f9f848faSopenharmony_ci#define USB_BUS_NON_GIANT_BULK_PROC(bus) (&(bus)->non_giant_bulk_callback_proc) 58f9f848faSopenharmony_ci#define USB_BUS_EXPLORE_PROC(bus) (&(bus)->explore_proc) 59f9f848faSopenharmony_ci#define USB_BUS_CONTROL_XFER_PROC(bus) (&(bus)->control_xfer_proc) 60f9f848faSopenharmony_ci /* 61f9f848faSopenharmony_ci * There are three callback processes. One for Giant locked 62f9f848faSopenharmony_ci * callbacks. One for non-Giant locked non-periodic callbacks 63f9f848faSopenharmony_ci * and one for non-Giant locked periodic callbacks. This 64f9f848faSopenharmony_ci * should avoid congestion and reduce response time in most 65f9f848faSopenharmony_ci * cases. 66f9f848faSopenharmony_ci */ 67f9f848faSopenharmony_ci struct usb_process giant_callback_proc; 68f9f848faSopenharmony_ci struct usb_process non_giant_isoc_callback_proc; 69f9f848faSopenharmony_ci struct usb_process non_giant_bulk_callback_proc; 70f9f848faSopenharmony_ci 71f9f848faSopenharmony_ci /* Explore process */ 72f9f848faSopenharmony_ci struct usb_process explore_proc; 73f9f848faSopenharmony_ci 74f9f848faSopenharmony_ci /* Control request process */ 75f9f848faSopenharmony_ci struct usb_process control_xfer_proc; 76f9f848faSopenharmony_ci#endif 77f9f848faSopenharmony_ci 78f9f848faSopenharmony_ci struct usb_bus_msg explore_msg[2]; 79f9f848faSopenharmony_ci struct usb_bus_msg detach_msg[2]; 80f9f848faSopenharmony_ci struct usb_bus_msg attach_msg[2]; 81f9f848faSopenharmony_ci struct usb_bus_msg suspend_msg[2]; 82f9f848faSopenharmony_ci struct usb_bus_msg resume_msg[2]; 83f9f848faSopenharmony_ci struct usb_bus_msg reset_msg[2]; 84f9f848faSopenharmony_ci struct usb_bus_msg shutdown_msg[2]; 85f9f848faSopenharmony_ci /* 86f9f848faSopenharmony_ci * This mutex protects the USB hardware: 87f9f848faSopenharmony_ci */ 88f9f848faSopenharmony_ci struct mtx bus_mtx; 89f9f848faSopenharmony_ci struct mtx bus_spin_lock; 90f9f848faSopenharmony_ci struct usb_xfer_queue intr_q; 91f9f848faSopenharmony_ci struct usb_callout power_wdog; /* power management */ 92f9f848faSopenharmony_ci 93f9f848faSopenharmony_ci device_t parent; 94f9f848faSopenharmony_ci device_t bdev; /* filled by HC driver */ 95f9f848faSopenharmony_ci 96f9f848faSopenharmony_ci#if USB_HAVE_BUSDMA 97f9f848faSopenharmony_ci struct usb_dma_parent_tag dma_parent_tag[1]; 98f9f848faSopenharmony_ci struct usb_dma_tag dma_tags[USB_BUS_DMA_TAG_MAX]; 99f9f848faSopenharmony_ci#endif 100f9f848faSopenharmony_ci const struct usb_bus_methods *methods; /* filled by HC driver */ 101f9f848faSopenharmony_ci struct usb_device **devices; 102f9f848faSopenharmony_ci 103f9f848faSopenharmony_ci struct ifnet *ifp; /* only for USB Packet Filter */ 104f9f848faSopenharmony_ci 105f9f848faSopenharmony_ci usb_power_mask_t hw_power_state; /* see USB_HW_POWER_XXX */ 106f9f848faSopenharmony_ci usb_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX]; 107f9f848faSopenharmony_ci 108f9f848faSopenharmony_ci uint16_t isoc_time_last; /* in milliseconds */ 109f9f848faSopenharmony_ci 110f9f848faSopenharmony_ci uint8_t alloc_failed; /* Set if memory allocation failed. */ 111f9f848faSopenharmony_ci uint8_t driver_added_refcount; /* Current driver generation count */ 112f9f848faSopenharmony_ci enum usb_revision usbrev; /* USB revision. See "USB_REV_XXX". */ 113f9f848faSopenharmony_ci 114f9f848faSopenharmony_ci uint8_t devices_max; /* maximum number of USB devices */ 115f9f848faSopenharmony_ci uint8_t do_probe; /* set if USB should be re-probed */ 116f9f848faSopenharmony_ci uint8_t no_explore; /* don't explore USB ports */ 117f9f848faSopenharmony_ci uint8_t dma_bits; /* number of DMA address lines */ 118f9f848faSopenharmony_ci uint8_t control_ep_quirk; /* need 64kByte buffer for data stage */ 119f9f848faSopenharmony_ci}; 120f9f848faSopenharmony_ci 121f9f848faSopenharmony_ci#endif /* _USB_BUS_H_ */ 122