xref: /freebsd/sys/dev/usb/usb_process.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
102ac6454SAndrew Thompson /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
3*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
4718cf2ccSPedro F. Giffuni  *
502ac6454SAndrew Thompson  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
602ac6454SAndrew Thompson  *
702ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
802ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
902ac6454SAndrew Thompson  * are met:
1002ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1102ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1202ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1302ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1402ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1502ac6454SAndrew Thompson  *
1602ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1702ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1802ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1902ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2002ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2102ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2202ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2302ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2402ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2502ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2602ac6454SAndrew Thompson  * SUCH DAMAGE.
2702ac6454SAndrew Thompson  */
2802ac6454SAndrew Thompson 
2975973647SAndrew Thompson #ifndef _USB_PROCESS_H_
3075973647SAndrew Thompson #define	_USB_PROCESS_H_
3102ac6454SAndrew Thompson 
32d2b99310SHans Petter Selasky #ifndef USB_GLOBAL_INCLUDE_FILE
336a9736a8SJohn Baldwin #include <sys/interrupt.h>
3402ac6454SAndrew Thompson #include <sys/priority.h>
356a9736a8SJohn Baldwin #include <sys/runq.h>
36d2b99310SHans Petter Selasky #endif
3702ac6454SAndrew Thompson 
3802ac6454SAndrew Thompson /* defines */
3943ea03d7SHans Petter Selasky #define	USB_PRI_HIGHEST	PI_SWI(SWI_TTY)
406a9736a8SJohn Baldwin #define	USB_PRI_HIGH	PI_SWI(SWI_NET)
416a9736a8SJohn Baldwin #define	USB_PRI_MED	PI_SWI(SWI_CAMBIO)
4202ac6454SAndrew Thompson 
4302ac6454SAndrew Thompson #define	USB_PROC_WAIT_TIMEOUT 2
4402ac6454SAndrew Thompson #define	USB_PROC_WAIT_DRAIN   1
4502ac6454SAndrew Thompson #define	USB_PROC_WAIT_NORMAL  0
4602ac6454SAndrew Thompson 
4702ac6454SAndrew Thompson /* structure prototypes */
4802ac6454SAndrew Thompson 
49760bc48eSAndrew Thompson struct usb_proc_msg;
50751aaf5aSHans Petter Selasky struct usb_device;
5102ac6454SAndrew Thompson 
5202ac6454SAndrew Thompson /*
5302ac6454SAndrew Thompson  * The following structure defines the USB process.
5402ac6454SAndrew Thompson  */
55760bc48eSAndrew Thompson struct usb_process {
56760bc48eSAndrew Thompson 	TAILQ_HEAD(, usb_proc_msg) up_qhead;
5702ac6454SAndrew Thompson 	struct cv up_cv;
5802ac6454SAndrew Thompson 	struct cv up_drain;
5902ac6454SAndrew Thompson 
60532b1952SAndrew Thompson 	struct thread *up_ptr;
6102ac6454SAndrew Thompson 	struct thread *up_curtd;
6202ac6454SAndrew Thompson 	struct mtx *up_mtx;
6302ac6454SAndrew Thompson 
64f9cb546cSAndrew Thompson 	usb_size_t up_msg_num;
6502ac6454SAndrew Thompson 
6602ac6454SAndrew Thompson 	uint8_t	up_prio;
6702ac6454SAndrew Thompson 	uint8_t	up_gone;
6802ac6454SAndrew Thompson 	uint8_t	up_msleep;
6902ac6454SAndrew Thompson 	uint8_t	up_csleep;
7002ac6454SAndrew Thompson 	uint8_t	up_dsleep;
7102ac6454SAndrew Thompson };
7202ac6454SAndrew Thompson 
7302ac6454SAndrew Thompson /* prototypes */
7402ac6454SAndrew Thompson 
75a593f6b8SAndrew Thompson uint8_t	usb_proc_is_gone(struct usb_process *up);
76a593f6b8SAndrew Thompson int	usb_proc_create(struct usb_process *up, struct mtx *p_mtx,
7702ac6454SAndrew Thompson 	    const char *pmesg, uint8_t prio);
78a593f6b8SAndrew Thompson void	usb_proc_drain(struct usb_process *up);
79a593f6b8SAndrew Thompson void	usb_proc_mwait(struct usb_process *up, void *pm0, void *pm1);
80a593f6b8SAndrew Thompson void	usb_proc_free(struct usb_process *up);
81a593f6b8SAndrew Thompson void   *usb_proc_msignal(struct usb_process *up, void *pm0, void *pm1);
82cb18f7d1SAlfred Perlstein void	usb_proc_rewakeup(struct usb_process *up);
83d008478eSHans Petter Selasky int	usb_proc_is_called_from(struct usb_process *up);
8402ac6454SAndrew Thompson 
85751aaf5aSHans Petter Selasky void	usb_proc_explore_mwait(struct usb_device *, void *, void *);
86751aaf5aSHans Petter Selasky void   *usb_proc_explore_msignal(struct usb_device *, void *, void *);
87751aaf5aSHans Petter Selasky void	usb_proc_explore_lock(struct usb_device *);
88751aaf5aSHans Petter Selasky void	usb_proc_explore_unlock(struct usb_device *);
89751aaf5aSHans Petter Selasky 
9075973647SAndrew Thompson #endif					/* _USB_PROCESS_H_ */
91