1184610Salfred/* $FreeBSD$ */ 2184610Salfred/*- 3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4184610Salfred * 5184610Salfred * Redistribution and use in source and binary forms, with or without 6184610Salfred * modification, are permitted provided that the following conditions 7184610Salfred * are met: 8184610Salfred * 1. Redistributions of source code must retain the above copyright 9184610Salfred * notice, this list of conditions and the following disclaimer. 10184610Salfred * 2. Redistributions in binary form must reproduce the above copyright 11184610Salfred * notice, this list of conditions and the following disclaimer in the 12184610Salfred * documentation and/or other materials provided with the distribution. 13184610Salfred * 14184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17184610Salfred * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24184610Salfred * SUCH DAMAGE. 25184610Salfred */ 26184610Salfred 27194230Sthompsa#ifndef _USB_PROCESS_H_ 28194230Sthompsa#define _USB_PROCESS_H_ 29184610Salfred 30246122Shselasky#ifndef USB_GLOBAL_INCLUDE_FILE 31217350Sjhb#include <sys/interrupt.h> 32184610Salfred#include <sys/priority.h> 33217350Sjhb#include <sys/runq.h> 34246122Shselasky#endif 35184610Salfred 36184610Salfred/* defines */ 37286773Shselasky#define USB_PRI_HIGHEST PI_SWI(SWI_TTY) 38217350Sjhb#define USB_PRI_HIGH PI_SWI(SWI_NET) 39217350Sjhb#define USB_PRI_MED PI_SWI(SWI_CAMBIO) 40184610Salfred 41184610Salfred#define USB_PROC_WAIT_TIMEOUT 2 42184610Salfred#define USB_PROC_WAIT_DRAIN 1 43184610Salfred#define USB_PROC_WAIT_NORMAL 0 44184610Salfred 45184610Salfred/* structure prototypes */ 46184610Salfred 47192984Sthompsastruct usb_proc_msg; 48249795Shselaskystruct usb_device; 49184610Salfred 50184610Salfred/* 51184610Salfred * The following structure defines the USB process. 52184610Salfred */ 53192984Sthompsastruct usb_process { 54192984Sthompsa TAILQ_HEAD(, usb_proc_msg) up_qhead; 55184610Salfred struct cv up_cv; 56184610Salfred struct cv up_drain; 57184610Salfred 58196274Sthompsa#if (__FreeBSD_version >= 800000) 59196274Sthompsa struct thread *up_ptr; 60196274Sthompsa#else 61184610Salfred struct proc *up_ptr; 62196274Sthompsa#endif 63184610Salfred struct thread *up_curtd; 64184610Salfred struct mtx *up_mtx; 65184610Salfred 66193074Sthompsa usb_size_t up_msg_num; 67184610Salfred 68184610Salfred uint8_t up_prio; 69184610Salfred uint8_t up_gone; 70184610Salfred uint8_t up_msleep; 71184610Salfred uint8_t up_csleep; 72184610Salfred uint8_t up_dsleep; 73184610Salfred}; 74184610Salfred 75184610Salfred/* prototypes */ 76184610Salfred 77194228Sthompsauint8_t usb_proc_is_gone(struct usb_process *up); 78194228Sthompsaint usb_proc_create(struct usb_process *up, struct mtx *p_mtx, 79188411Sthompsa const char *pmesg, uint8_t prio); 80194228Sthompsavoid usb_proc_drain(struct usb_process *up); 81194228Sthompsavoid usb_proc_mwait(struct usb_process *up, void *pm0, void *pm1); 82194228Sthompsavoid usb_proc_free(struct usb_process *up); 83194228Sthompsavoid *usb_proc_msignal(struct usb_process *up, void *pm0, void *pm1); 84196498Salfredvoid usb_proc_rewakeup(struct usb_process *up); 85263423Shselaskyint usb_proc_is_called_from(struct usb_process *up); 86184610Salfred 87249795Shselaskyvoid usb_proc_explore_mwait(struct usb_device *, void *, void *); 88249795Shselaskyvoid *usb_proc_explore_msignal(struct usb_device *, void *, void *); 89249795Shselaskyvoid usb_proc_explore_lock(struct usb_device *); 90249795Shselaskyvoid usb_proc_explore_unlock(struct usb_device *); 91249795Shselasky 92194230Sthompsa#endif /* _USB_PROCESS_H_ */ 93