Index: head/stand/kshim/bsd_kernel.h =================================================================== --- head/stand/kshim/bsd_kernel.h (revision 367786) +++ head/stand/kshim/bsd_kernel.h (revision 367787) @@ -1,660 +1,663 @@ /* $FreeBSD$ */ /*- * Copyright (c) 2011 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _BSD_KERNEL_H_ #define _BSD_KERNEL_H_ -#define _KERNEL +#if !defined(_STANDALONE) +#error "_STANDALONE is not defined!" +#endif + #undef __FreeBSD_version -#define __FreeBSD_version 1100000 +#define __FreeBSD_version 1300000 #include #include #include #define howmany(x, y) (((x)+((y)-1))/(y)) #define nitems(x) (sizeof((x)) / sizeof((x)[0])) #define isalpha(x) (((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z')) #define isdigit(x) ((x) >= '0' && (x) <= '9') #define panic(...) do { printf("USB PANIC: " __VA_ARGS__); while (1) ; } while (0) #define rebooting 0 #define M_USB 0 #define M_USBDEV 0 #define USB_PROC_MAX 3 #define USB_BUS_GIANT_PROC(bus) (usb_process + 2) #define USB_BUS_NON_GIANT_BULK_PROC(bus) (usb_process + 2) #define USB_BUS_NON_GIANT_ISOC_PROC(bus) (usb_process + 2) #define USB_BUS_EXPLORE_PROC(bus) (usb_process + 0) #define USB_BUS_CONTROL_XFER_PROC(bus) (usb_process + 1) #define SYSCTL_DECL(...) struct sysctl_ctx_list { }; struct sysctl_req { void *newptr; }; #define SYSCTL_HANDLER_ARGS void *oidp, void *arg1, \ uint32_t arg2, struct sysctl_req *req #define SYSCTL_NODE(name,...) struct { } name __used #define SYSCTL_INT(...) #define SYSCTL_UINT(...) #define SYSCTL_PROC(...) #define SYSCTL_ADD_NODE(...) NULL #define SYSCTL_ADD_U16(...) NULL #define SYSCTL_ADD_PROC(...) NULL #define sysctl_handle_int(...) EOPNOTSUPP #define sysctl_handle_string(...) EOPNOTSUPP #define sysctl_ctx_init(ctx) do { (void)(ctx); } while (0) #define sysctl_ctx_free(ctx) do { (void)(ctx); } while (0) #define TUNABLE_INT(...) #define MALLOC_DECLARE(...) #define MALLOC_DEFINE(...) #define EVENTHANDLER_DECLARE(...) #define EVENTHANDLER_INVOKE(...) #define KASSERT(...) #define SCHEDULER_STOPPED(x) (0) #define PI_SWI(...) (0) #define UNIQ_NAME(x) x #define UNIQ_NAME_STR(x) #x #define DEVCLASS_MAXUNIT 32 #define MOD_LOAD 1 #define MOD_UNLOAD 2 #define DEVMETHOD(what,func) { #what, (void *)&func } #define DEVMETHOD_END {0,0} #define EARLY_DRIVER_MODULE(a, b, c, d, e, f, g) DRIVER_MODULE(a, b, c, d, e, f) #define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ static struct module_data bsd_##name##_##busname##_driver_mod = { \ evh, arg, #busname, #name, #busname "/" #name, \ &driver, &devclass, { 0, 0 } }; \ SYSINIT(bsd_##name##_##busname##_driver_mod, SI_SUB_DRIVERS, \ SI_ORDER_MIDDLE, module_register, \ &bsd_##name##_##busname##_driver_mod) #define SYSINIT(uniq, subs, order, _func, _data) \ const struct sysinit UNIQ_NAME(sysinit_##uniq) = { \ .func = (_func), \ .data = __DECONST(void *, _data) \ }; \ SYSINIT_ENTRY(uniq##_entry, "sysinit", (subs), \ (order), "const struct sysinit", \ UNIQ_NAME_STR(sysinit_##uniq), "SYSINIT") #define SYSUNINIT(uniq, subs, order, _func, _data) \ const struct sysinit UNIQ_NAME(sysuninit_##uniq) = { \ .func = (_func), \ .data = __DECONST(void *, _data) \ }; \ SYSINIT_ENTRY(uniq##_entry, "sysuninit", (subs), \ (order), "const struct sysuninit", \ UNIQ_NAME_STR(sysuninit_##uniq), "SYSUNINIT") #define MODULE_DEPEND(...) #define MODULE_VERSION(...) #define NULL ((void *)0) #define BUS_SPACE_BARRIER_READ 0x01 #define BUS_SPACE_BARRIER_WRITE 0x02 #define hz 1000 #undef PAGE_SIZE #define PAGE_SIZE 4096 #undef MIN #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #undef MAX #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define MTX_DEF 0 #define MTX_SPIN 0 #define MTX_RECURSE 0 #define SX_DUPOK 0 #define SX_NOWITNESS 0 #define WITNESS_WARN(...) #define cold 0 #define BUS_PROBE_GENERIC 0 #define BUS_PROBE_DEFAULT (-20) #define CALLOUT_RETURNUNLOCKED 0x1 #undef ffs #define ffs(x) __builtin_ffs(x) #undef va_list #define va_list __builtin_va_list #undef va_size #define va_size(type) __builtin_va_size(type) #undef va_start #define va_start(ap, last) __builtin_va_start(ap, last) #undef va_end #define va_end(ap) __builtin_va_end(ap) #undef va_arg #define va_arg(ap, type) __builtin_va_arg((ap), type) #define DEVICE_ATTACH(dev, ...) \ (((device_attach_t *)(device_get_method(dev, "device_attach")))(dev,## __VA_ARGS__)) #define DEVICE_DETACH(dev, ...) \ (((device_detach_t *)(device_get_method(dev, "device_detach")))(dev,## __VA_ARGS__)) #define DEVICE_PROBE(dev, ...) \ (((device_probe_t *)(device_get_method(dev, "device_probe")))(dev,## __VA_ARGS__)) #define DEVICE_RESUME(dev, ...) \ (((device_resume_t *)(device_get_method(dev, "device_resume")))(dev,## __VA_ARGS__)) #define DEVICE_SHUTDOWN(dev, ...) \ (((device_shutdown_t *)(device_get_method(dev, "device_shutdown")))(dev,## __VA_ARGS__)) #define DEVICE_SUSPEND(dev, ...) \ (((device_suspend_t *)(device_get_method(dev, "device_suspend")))(dev,## __VA_ARGS__)) #define USB_HANDLE_REQUEST(dev, ...) \ (((usb_handle_request_t *)(device_get_method(dev, "usb_handle_request")))(dev,## __VA_ARGS__)) #define USB_TAKE_CONTROLLER(dev, ...) \ (((usb_take_controller_t *)(device_get_method(dev, "usb_take_controller")))(dev,## __VA_ARGS__)) #define GPIO_PIN_SET(dev, ...) \ (((gpio_pin_set_t *)(device_get_method(dev, "gpio_pin_set")))(dev,## __VA_ARGS__)) #define GPIO_PIN_SETFLAGS(dev, ...) \ (((gpio_pin_setflags_t *)(device_get_method(dev, "gpio_pin_setflags")))(dev,## __VA_ARGS__)) enum { SI_SUB_DUMMY = 0x0000000, SI_SUB_LOCK = 0x1B00000, SI_SUB_KLD = 0x2000000, SI_SUB_DRIVERS = 0x3100000, SI_SUB_PSEUDO = 0x7000000, SI_SUB_KICK_SCHEDULER = 0xa000000, SI_SUB_RUN_SCHEDULER = 0xfffffff }; enum { SI_ORDER_FIRST = 0x0000000, SI_ORDER_SECOND = 0x0000001, SI_ORDER_THIRD = 0x0000002, SI_ORDER_FOURTH = 0x0000003, SI_ORDER_MIDDLE = 0x1000000, SI_ORDER_ANY = 0xfffffff /* last */ }; struct uio; struct thread; struct malloc_type; struct usb_process; #ifndef INT32_MAX #define INT32_MAX 0x7fffffff #endif #ifndef HAVE_STANDARD_DEFS #define _UINT8_T_DECLARED typedef unsigned char uint8_t; #define _INT8_T_DECLARED typedef signed char int8_t; #define _UINT16_T_DECLARED typedef unsigned short uint16_t; #define _INT16_T_DECLARED typedef signed short int16_t; #define _UINT32_T_DECLARED typedef unsigned int uint32_t; #define _INT32_T_DECLARED typedef signed int int32_t; #define _UINT64_T_DECLARED typedef unsigned long long uint64_t; #define _INT16_T_DECLARED typedef signed long long int64_t; typedef uint16_t uid_t; typedef uint16_t gid_t; typedef uint16_t mode_t; typedef uint8_t *caddr_t; #define _UINTPTR_T_DECLARED typedef unsigned long uintptr_t; #define _SIZE_T_DECLARED typedef unsigned long size_t; typedef unsigned long u_long; #endif typedef unsigned long bus_addr_t; typedef unsigned long bus_size_t; typedef struct bus_dma_segment { bus_addr_t ds_addr; /* DMA address */ bus_size_t ds_len; /* length of transfer */ } bus_dma_segment_t; struct bus_dma_tag { uint32_t alignment; uint32_t maxsize; }; typedef void *bus_dmamap_t; typedef struct bus_dma_tag *bus_dma_tag_t; typedef enum { BUS_DMA_LOCK = 0x01, BUS_DMA_UNLOCK = 0x02, } bus_dma_lock_op_t; typedef void *bus_space_tag_t; typedef uint8_t *bus_space_handle_t; typedef int bus_dma_filter_t(void *, bus_addr_t); typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); typedef uint32_t bool; /* SYSINIT API */ #include struct sysinit { void (*func) (void *arg); void *data; }; /* MUTEX API */ struct mtx { int owned; struct mtx *parent; }; #define mtx_assert(...) do { } while (0) void mtx_init(struct mtx *, const char *, const char *, int); void mtx_lock(struct mtx *); void mtx_unlock(struct mtx *); #define mtx_lock_spin(x) mtx_lock(x) #define mtx_unlock_spin(x) mtx_unlock(x) int mtx_owned(struct mtx *); void mtx_destroy(struct mtx *); extern struct mtx Giant; /* SX API */ struct sx { int owned; }; #define sx_assert(...) do { } while (0) #define sx_init(...) sx_init_flags(__VA_ARGS__, 0) void sx_init_flags(struct sx *, const char *, int); void sx_destroy(struct sx *); void sx_xlock(struct sx *); void sx_xunlock(struct sx *); int sx_xlocked(struct sx *); /* CONDVAR API */ struct cv { int sleeping; }; void cv_init(struct cv *, const char *desc); void cv_destroy(struct cv *); void cv_wait(struct cv *, struct mtx *); int cv_timedwait(struct cv *, struct mtx *, int); void cv_signal(struct cv *); void cv_broadcast(struct cv *); /* CALLOUT API */ typedef void callout_fn_t (void *); extern volatile int ticks; struct callout { LIST_ENTRY(callout) entry; callout_fn_t *c_func; void *c_arg; struct mtx *mtx; int flags; int timeout; }; void callout_init_mtx(struct callout *, struct mtx *, int); void callout_reset(struct callout *, int, callout_fn_t *, void *); void callout_stop(struct callout *); void callout_drain(struct callout *); int callout_pending(struct callout *); void callout_process(int timeout); /* DEVICE API */ struct driver; struct devclass; struct device; struct module; struct module_data; typedef struct driver driver_t; typedef struct devclass *devclass_t; typedef struct device *device_t; typedef void (driver_intr_t)(void *arg); typedef int (driver_filter_t)(void *arg); #define FILTER_STRAY 0x01 #define FILTER_HANDLED 0x02 #define FILTER_SCHEDULE_THREAD 0x04 typedef int device_attach_t (device_t dev); typedef int device_detach_t (device_t dev); typedef int device_resume_t (device_t dev); typedef int device_shutdown_t (device_t dev); typedef int device_probe_t (device_t dev); typedef int device_suspend_t (device_t dev); typedef int gpio_pin_set_t (device_t dev, uint32_t, unsigned int); typedef int gpio_pin_setflags_t (device_t dev, uint32_t, uint32_t); typedef int bus_child_location_str_t (device_t parent, device_t child, char *buf, size_t buflen); typedef int bus_child_pnpinfo_str_t (device_t parent, device_t child, char *buf, size_t buflen); typedef void bus_driver_added_t (device_t dev, driver_t *driver); struct device_method { const char *desc; void *const func; }; typedef struct device_method device_method_t; struct device { TAILQ_HEAD(device_list, device) dev_children; TAILQ_ENTRY(device) dev_link; struct device *dev_parent; const struct module_data *dev_module; void *dev_sc; void *dev_aux; driver_filter_t *dev_irq_filter; driver_intr_t *dev_irq_fn; void *dev_irq_arg; uint16_t dev_unit; char dev_nameunit[64]; char dev_desc[64]; uint8_t dev_res_alloc:1; uint8_t dev_quiet:1; uint8_t dev_softc_set:1; uint8_t dev_softc_alloc:1; uint8_t dev_attached:1; uint8_t dev_fixed_class:1; uint8_t dev_unit_manual:1; }; struct devclass { device_t dev_list[DEVCLASS_MAXUNIT]; }; struct driver { const char *name; const struct device_method *methods; uint32_t size; }; struct module_data { int (*callback) (struct module *, int, void *arg); void *arg; const char *bus_name; const char *mod_name; const char *long_name; const struct driver *driver; struct devclass **devclass_pp; TAILQ_ENTRY(module_data) entry; }; device_t device_get_parent(device_t dev); void *device_get_method(device_t dev, const char *what); const char *device_get_name(device_t dev); const char *device_get_nameunit(device_t dev); #define device_printf(dev, fmt,...) \ printf("%s: " fmt, device_get_nameunit(dev),## __VA_ARGS__) device_t device_add_child(device_t dev, const char *name, int unit); void device_quiet(device_t dev); void device_set_interrupt(device_t dev, driver_filter_t *, driver_intr_t *, void *); void device_run_interrupts(device_t parent); void device_set_ivars(device_t dev, void *ivars); void *device_get_ivars(device_t dev); const char *device_get_desc(device_t dev); int device_probe_and_attach(device_t dev); int device_detach(device_t dev); void *device_get_softc(device_t dev); void device_set_softc(device_t dev, void *softc); int device_delete_child(device_t dev, device_t child); int device_delete_children(device_t dev); int device_is_attached(device_t dev); void device_set_desc(device_t dev, const char *desc); void device_set_desc_copy(device_t dev, const char *desc); int device_get_unit(device_t dev); void *devclass_get_softc(devclass_t dc, int unit); int devclass_get_maxunit(devclass_t dc); device_t devclass_get_device(devclass_t dc, int unit); devclass_t devclass_find(const char *classname); #define bus_get_dma_tag(...) (NULL) int bus_generic_detach(device_t dev); int bus_generic_resume(device_t dev); int bus_generic_shutdown(device_t dev); int bus_generic_suspend(device_t dev); int bus_generic_print_child(device_t dev, device_t child); void bus_generic_driver_added(device_t dev, driver_t *driver); int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); /* BUS SPACE API */ void bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t data); void bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t data); void bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t data); uint8_t bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset); uint16_t bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset); uint32_t bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset); void bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t *datap, bus_size_t count); void bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t *datap, bus_size_t count); void bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t *datap, bus_size_t count); void bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t *datap, bus_size_t count); void bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t *datap, bus_size_t count); void bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t *datap, bus_size_t count); void bus_space_read_region_1(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, uint8_t *datap, bus_size_t count); void bus_space_write_region_1(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, uint8_t *datap, bus_size_t count); void bus_space_read_region_4(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, uint32_t *datap, bus_size_t count); void bus_space_write_region_4(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, uint32_t *datap, bus_size_t count); void bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, bus_size_t length, int flags); void module_register(void *); /* LIB-C */ void *memset(void *, int, size_t len); void *memcpy(void *, const void *, size_t len); int printf(const char *,...) __printflike(1, 2); int snprintf(char *restrict str, size_t size, const char *restrict format,...) __printflike(3, 4); size_t strlen(const char *s); /* MALLOC API */ #undef malloc #define malloc(s,x,f) usb_malloc(s) void *usb_malloc(size_t); #undef free #define free(p,x) usb_free(p) void usb_free(void *); #define strdup(p,x) usb_strdup(p) char *usb_strdup(const char *str); /* ENDIANNESS */ #ifndef HAVE_ENDIAN_DEFS /* Assume little endian */ #define htole64(x) ((uint64_t)(x)) #define le64toh(x) ((uint64_t)(x)) #define htole32(x) ((uint32_t)(x)) #define le32toh(x) ((uint32_t)(x)) #define htole16(x) ((uint16_t)(x)) #define le16toh(x) ((uint16_t)(x)) #define be32toh(x) ((uint32_t)(x)) #define htobe32(x) ((uint32_t)(x)) #else #include #endif /* USB */ typedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate); typedef int usb_take_controller_t (device_t dev); void usb_idle(void); void usb_init(void); void usb_uninit(void); /* set some defaults */ #ifndef USB_POOL_SIZE #define USB_POOL_SIZE (1024*1024) /* 1 MByte */ #endif int pause(const char *, int); void DELAY(unsigned int); /* OTHER */ struct selinfo { }; /* SYSTEM STARTUP API */ extern const void *sysinit_data[]; extern const void *sysuninit_data[]; /* Resources */ enum intr_type { INTR_TYPE_TTY = 1, INTR_TYPE_BIO = 2, INTR_TYPE_NET = 4, INTR_TYPE_CAM = 8, INTR_TYPE_MISC = 16, INTR_TYPE_CLK = 32, INTR_TYPE_AV = 64, INTR_EXCL = 256, /* exclusive interrupt */ INTR_MPSAFE = 512, /* this interrupt is SMP safe */ INTR_ENTROPY = 1024, /* this interrupt provides entropy */ INTR_MD1 = 4096, /* flag reserved for MD use */ INTR_MD2 = 8192, /* flag reserved for MD use */ INTR_MD3 = 16384, /* flag reserved for MD use */ INTR_MD4 = 32768 /* flag reserved for MD use */ }; struct resource_i { u_long r_start; /* index of the first entry in this resource */ u_long r_end; /* index of the last entry (inclusive) */ }; struct resource { struct resource_i *__r_i; bus_space_tag_t r_bustag; /* bus_space tag */ bus_space_handle_t r_bushandle; /* bus_space handle */ }; struct resource_spec { int type; int rid; int flags; }; #define SYS_RES_IRQ 1 /* interrupt lines */ #define SYS_RES_DRQ 2 /* isa dma lines */ #define SYS_RES_MEMORY 3 /* i/o memory */ #define SYS_RES_IOPORT 4 /* i/o ports */ #define RF_ALLOCATED 0x0001 /* resource has been reserved */ #define RF_ACTIVE 0x0002 /* resource allocation has been activated */ #define RF_SHAREABLE 0x0004 /* resource permits contemporaneous sharing */ #define RF_SPARE1 0x0008 #define RF_SPARE2 0x0010 #define RF_FIRSTSHARE 0x0020 /* first in sharing list */ #define RF_PREFETCHABLE 0x0040 /* resource is prefetchable */ #define RF_OPTIONAL 0x0080 /* for bus_alloc_resources() */ int bus_alloc_resources(device_t, struct resource_spec *, struct resource **); int bus_release_resource(device_t, int, int, struct resource *); void bus_release_resources(device_t, const struct resource_spec *, struct resource **); struct resource *bus_alloc_resource_any(device_t, int, int *, unsigned int); int bus_generic_attach(device_t); bus_space_tag_t rman_get_bustag(struct resource *); bus_space_handle_t rman_get_bushandle(struct resource *); u_long rman_get_size(struct resource *); int bus_setup_intr(device_t, struct resource *, int, driver_filter_t, driver_intr_t, void *, void **); int bus_teardown_intr(device_t, struct resource *, void *); int ofw_bus_status_okay(device_t); int ofw_bus_is_compatible(device_t, char *); extern int (*bus_alloc_resource_any_cb)(struct resource *res, device_t dev, int type, int *rid, unsigned int flags); extern int (*ofw_bus_status_ok_cb)(device_t dev); extern int (*ofw_bus_is_compatible_cb)(device_t dev, char *name); #ifndef strlcpy #define strlcpy(d,s,n) snprintf((d),(n),"%s",(s)) #endif /* Should be defined in user application since it is machine-dependent */ extern int delay(unsigned int); /* BUS dma */ #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF #define BUS_SPACE_MAXADDR 0xFFFFFFFF #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF #define BUS_SPACE_MAXSIZE 0xFFFFFFFF #define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ #define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ #define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ #define BUS_DMA_BUS2 0x20 #define BUS_DMA_BUS3 0x40 #define BUS_DMA_BUS4 0x80 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, bus_size_t boundary, bus_addr_t lowaddr, bus_addr_t highaddr, bus_dma_filter_t *filter, void *filterarg, bus_size_t maxsize, int nsegments, bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, void *lockfuncarg, bus_dma_tag_t *dmat); int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp); void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); int bus_dma_tag_destroy(bus_dma_tag_t dmat); #endif /* _BSD_KERNEL_H_ */ Index: head/sys/dev/usb/usb.h =================================================================== --- head/sys/dev/usb/usb.h (revision 367786) +++ head/sys/dev/usb/usb.h (revision 367787) @@ -1,809 +1,809 @@ /* $FreeBSD$ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. * Copyright (c) 1998 Lennart Augustsson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * This file contains standard definitions for the following USB * protocol versions: * * USB v1.0 * USB v1.1 * USB v2.0 * USB v3.0 */ #ifndef _USB_STANDARD_H_ #define _USB_STANDARD_H_ -#if defined(_KERNEL) +#if defined(_KERNEL) || defined(_STANDALONE) #ifndef USB_GLOBAL_INCLUDE_FILE #include "opt_usb.h" #endif /* Declare parent SYSCTL USB node. */ #ifdef SYSCTL_DECL SYSCTL_DECL(_hw_usb); #endif #ifndef USB_GLOBAL_INCLUDE_FILE #include #endif MALLOC_DECLARE(M_USB); MALLOC_DECLARE(M_USBDEV); -#endif /* _KERNEL */ +#endif /* _KERNEL || _STANDALONE */ #ifndef USB_GLOBAL_INCLUDE_FILE #include #include #endif #define USB_STACK_VERSION 2000 /* 2.0 */ /* Definition of some hardcoded USB constants. */ #define USB_MAX_IPACKET 8 /* initial USB packet size */ #define USB_EP_MAX (2*16) /* hardcoded */ #define USB_ROOT_HUB_ADDR 1 /* index */ #define USB_MIN_DEVICES 2 /* unused + root HUB */ #define USB_UNCONFIG_INDEX 0xFF /* internal use only */ #define USB_IFACE_INDEX_ANY 0xFF /* internal use only */ #define USB_START_ADDR 0 /* default USB device BUS address * after USB bus reset */ #define USB_CONTROL_ENDPOINT 0 /* default control endpoint */ #define USB_FRAMES_PER_SECOND_FS 1000 /* full speed */ #define USB_FRAMES_PER_SECOND_HS 8000 /* high speed */ #define USB_FS_BYTES_PER_HS_UFRAME 188 /* bytes */ #define USB_HS_MICRO_FRAMES_MAX 8 /* units */ #define USB_ISOC_TIME_MAX 128 /* ms */ /* * Minimum time a device needs to be powered down to go through a * power cycle. These values are not in the USB specification. */ #define USB_POWER_DOWN_TIME 200 /* ms */ #define USB_PORT_POWER_DOWN_TIME 100 /* ms */ /* Definition of software USB power modes */ #define USB_POWER_MODE_OFF 0 /* turn off device */ #define USB_POWER_MODE_ON 1 /* always on */ #define USB_POWER_MODE_SAVE 2 /* automatic suspend and resume */ #define USB_POWER_MODE_SUSPEND 3 /* force suspend */ #define USB_POWER_MODE_RESUME 4 /* force resume */ /* These are the values from the USB specification. */ #define USB_PORT_RESET_DELAY_SPEC 10 /* ms */ #define USB_PORT_ROOT_RESET_DELAY_SPEC 50 /* ms */ #define USB_PORT_RESET_RECOVERY_SPEC 10 /* ms */ #define USB_PORT_POWERUP_DELAY_SPEC 100 /* ms */ #define USB_PORT_RESUME_DELAY_SPEC 20 /* ms */ #define USB_SET_ADDRESS_SETTLE_SPEC 2 /* ms */ #define USB_RESUME_DELAY_SPEC (20*5) /* ms */ #define USB_RESUME_WAIT_SPEC 10 /* ms */ #define USB_RESUME_RECOVERY_SPEC 10 /* ms */ #define USB_EXTRA_POWER_UP_TIME_SPEC 0 /* ms */ /* Allow for marginal and non-conforming devices. */ #define USB_PORT_RESET_DELAY 50 /* ms */ #define USB_PORT_ROOT_RESET_DELAY 200 /* ms */ #define USB_PORT_RESET_RECOVERY 250 /* ms */ #define USB_PORT_POWERUP_DELAY 300 /* ms */ #define USB_PORT_RESUME_DELAY (20*2) /* ms */ #define USB_SET_ADDRESS_SETTLE 10 /* ms */ #define USB_RESUME_DELAY (50*5) /* ms */ #define USB_RESUME_WAIT 50 /* ms */ #define USB_RESUME_RECOVERY 50 /* ms */ #define USB_EXTRA_POWER_UP_TIME 20 /* ms */ #define USB_MIN_POWER 100 /* mA */ #define USB_MAX_POWER 500 /* mA */ #define USB_BUS_RESET_DELAY 100 /* ms */ /* * USB record layout in memory: * * - USB config 0 * - USB interfaces * - USB alternative interfaces * - USB endpoints * * - USB config 1 * - USB interfaces * - USB alternative interfaces * - USB endpoints */ /* Declaration of USB records */ struct usb_device_request { uByte bmRequestType; uByte bRequest; uWord wValue; uWord wIndex; uWord wLength; } __packed; typedef struct usb_device_request usb_device_request_t; #define UT_WRITE 0x00 #define UT_READ 0x80 #define UT_STANDARD 0x00 #define UT_CLASS 0x20 #define UT_VENDOR 0x40 #define UT_DEVICE 0x00 #define UT_INTERFACE 0x01 #define UT_ENDPOINT 0x02 #define UT_OTHER 0x03 #define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE) #define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE) #define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT) #define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE) #define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE) #define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT) #define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE) #define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE) #define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER) #define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT) #define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE) #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE) #define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER) #define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT) #define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE) #define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE) #define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER) #define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT) #define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE) #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE) #define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER) #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT) /* Requests */ #define UR_GET_STATUS 0x00 #define UR_CLEAR_FEATURE 0x01 #define UR_SET_FEATURE 0x03 #define UR_SET_ADDRESS 0x05 #define UR_GET_DESCRIPTOR 0x06 #define UDESC_DEVICE 0x01 #define UDESC_CONFIG 0x02 #define UDESC_STRING 0x03 #define USB_LANGUAGE_TABLE 0x00 /* language ID string index */ #define UDESC_INTERFACE 0x04 #define UDESC_ENDPOINT 0x05 #define UDESC_DEVICE_QUALIFIER 0x06 #define UDESC_OTHER_SPEED_CONFIGURATION 0x07 #define UDESC_INTERFACE_POWER 0x08 #define UDESC_OTG 0x09 #define UDESC_DEBUG 0x0A #define UDESC_IFACE_ASSOC 0x0B /* interface association */ #define UDESC_BOS 0x0F /* binary object store */ #define UDESC_DEVICE_CAPABILITY 0x10 #define UDESC_CS_DEVICE 0x21 /* class specific */ #define UDESC_CS_CONFIG 0x22 #define UDESC_CS_STRING 0x23 #define UDESC_CS_INTERFACE 0x24 #define UDESC_CS_ENDPOINT 0x25 #define UDESC_HUB 0x29 #define UDESC_SS_HUB 0x2A /* super speed */ #define UDESC_ENDPOINT_SS_COMP 0x30 /* super speed */ #define UR_SET_DESCRIPTOR 0x07 #define UR_GET_CONFIG 0x08 #define UR_SET_CONFIG 0x09 #define UR_GET_INTERFACE 0x0a #define UR_SET_INTERFACE 0x0b #define UR_SYNCH_FRAME 0x0c #define UR_SET_SEL 0x30 #define UR_ISOCH_DELAY 0x31 /* HUB specific request */ #define UR_GET_BUS_STATE 0x02 #define UR_CLEAR_TT_BUFFER 0x08 #define UR_RESET_TT 0x09 #define UR_GET_TT_STATE 0x0a #define UR_STOP_TT 0x0b #define UR_SET_AND_TEST 0x0c /* USB 2.0 only */ #define UR_SET_HUB_DEPTH 0x0c /* USB 3.0 only */ #define USB_SS_HUB_DEPTH_MAX 5 #define UR_GET_PORT_ERR_COUNT 0x0d /* Feature numbers */ #define UF_ENDPOINT_HALT 0 #define UF_DEVICE_REMOTE_WAKEUP 1 #define UF_TEST_MODE 2 #define UF_U1_ENABLE 0x30 #define UF_U2_ENABLE 0x31 #define UF_LTM_ENABLE 0x32 /* HUB specific features */ #define UHF_C_HUB_LOCAL_POWER 0 #define UHF_C_HUB_OVER_CURRENT 1 #define UHF_PORT_CONNECTION 0 #define UHF_PORT_ENABLE 1 #define UHF_PORT_SUSPEND 2 #define UHF_PORT_OVER_CURRENT 3 #define UHF_PORT_RESET 4 #define UHF_PORT_LINK_STATE 5 #define UHF_PORT_POWER 8 #define UHF_PORT_LOW_SPEED 9 #define UHF_PORT_L1 10 #define UHF_C_PORT_CONNECTION 16 #define UHF_C_PORT_ENABLE 17 #define UHF_C_PORT_SUSPEND 18 #define UHF_C_PORT_OVER_CURRENT 19 #define UHF_C_PORT_RESET 20 #define UHF_PORT_TEST 21 #define UHF_PORT_INDICATOR 22 #define UHF_C_PORT_L1 23 /* SuperSpeed HUB specific features */ #define UHF_PORT_U1_TIMEOUT 23 #define UHF_PORT_U2_TIMEOUT 24 #define UHF_C_PORT_LINK_STATE 25 #define UHF_C_PORT_CONFIG_ERROR 26 #define UHF_PORT_REMOTE_WAKE_MASK 27 #define UHF_BH_PORT_RESET 28 #define UHF_C_BH_PORT_RESET 29 #define UHF_FORCE_LINKPM_ACCEPT 30 /* SuperSpeed suspend support */ #define USB_INTERFACE_FUNC_SUSPEND 0 #define USB_INTERFACE_FUNC_SUSPEND_LP (1 << 8) #define USB_INTERFACE_FUNC_SUSPEND_RW (1 << 9) struct usb_descriptor { uByte bLength; uByte bDescriptorType; uByte bDescriptorSubtype; } __packed; typedef struct usb_descriptor usb_descriptor_t; struct usb_device_descriptor { uByte bLength; uByte bDescriptorType; uWord bcdUSB; #define UD_USB_2_0 0x0200 #define UD_USB_3_0 0x0300 #define UD_IS_USB2(d) ((d)->bcdUSB[1] == 0x02) #define UD_IS_USB3(d) ((d)->bcdUSB[1] == 0x03) uByte bDeviceClass; uByte bDeviceSubClass; uByte bDeviceProtocol; uByte bMaxPacketSize; /* The fields below are not part of the initial descriptor. */ uWord idVendor; uWord idProduct; uWord bcdDevice; uByte iManufacturer; uByte iProduct; uByte iSerialNumber; uByte bNumConfigurations; } __packed; typedef struct usb_device_descriptor usb_device_descriptor_t; /* Binary Device Object Store (BOS) */ struct usb_bos_descriptor { uByte bLength; uByte bDescriptorType; uWord wTotalLength; uByte bNumDeviceCaps; } __packed; typedef struct usb_bos_descriptor usb_bos_descriptor_t; /* Binary Device Object Store Capability */ struct usb_bos_cap_descriptor { uByte bLength; uByte bDescriptorType; uByte bDevCapabilityType; #define USB_DEVCAP_RESERVED 0x00 #define USB_DEVCAP_WUSB 0x01 #define USB_DEVCAP_USB2EXT 0x02 #define USB_DEVCAP_SUPER_SPEED 0x03 #define USB_DEVCAP_CONTAINER_ID 0x04 /* data ... */ } __packed; typedef struct usb_bos_cap_descriptor usb_bos_cap_descriptor_t; struct usb_devcap_usb2ext_descriptor { uByte bLength; uByte bDescriptorType; uByte bDevCapabilityType; uDWord bmAttributes; #define USB_V2EXT_LPM (1U << 1) #define USB_V2EXT_BESL_SUPPORTED (1U << 2) #define USB_V2EXT_BESL_BASELINE_VALID (1U << 3) #define USB_V2EXT_BESL_DEEP_VALID (1U << 4) #define USB_V2EXT_BESL_BASELINE_GET(x) (((x) >> 8) & 0xF) #define USB_V2EXT_BESL_DEEP_GET(x) (((x) >> 12) & 0xF) } __packed; typedef struct usb_devcap_usb2ext_descriptor usb_devcap_usb2ext_descriptor_t; struct usb_devcap_ss_descriptor { uByte bLength; uByte bDescriptorType; uByte bDevCapabilityType; uByte bmAttributes; uWord wSpeedsSupported; uByte bFunctionalitySupport; uByte bU1DevExitLat; uWord wU2DevExitLat; } __packed; typedef struct usb_devcap_ss_descriptor usb_devcap_ss_descriptor_t; struct usb_devcap_container_id_descriptor { uByte bLength; uByte bDescriptorType; uByte bDevCapabilityType; uByte bReserved; uByte bContainerID; } __packed; typedef struct usb_devcap_container_id_descriptor usb_devcap_container_id_descriptor_t; /* Device class codes */ #define UDCLASS_IN_INTERFACE 0x00 #define UDCLASS_COMM 0x02 #define UDCLASS_HUB 0x09 #define UDSUBCLASS_HUB 0x00 #define UDPROTO_FSHUB 0x00 #define UDPROTO_HSHUBSTT 0x01 #define UDPROTO_HSHUBMTT 0x02 #define UDPROTO_SSHUB 0x03 #define UDCLASS_DIAGNOSTIC 0xdc #define UDCLASS_WIRELESS 0xe0 #define UDSUBCLASS_RF 0x01 #define UDPROTO_BLUETOOTH 0x01 #define UDCLASS_VENDOR 0xff struct usb_config_descriptor { uByte bLength; uByte bDescriptorType; uWord wTotalLength; uByte bNumInterface; uByte bConfigurationValue; #define USB_UNCONFIG_NO 0 uByte iConfiguration; uByte bmAttributes; #define UC_BUS_POWERED 0x80 #define UC_SELF_POWERED 0x40 #define UC_REMOTE_WAKEUP 0x20 uByte bMaxPower; /* max current in 2 mA units */ #define UC_POWER_FACTOR 2 } __packed; typedef struct usb_config_descriptor usb_config_descriptor_t; struct usb_interface_descriptor { uByte bLength; uByte bDescriptorType; uByte bInterfaceNumber; uByte bAlternateSetting; uByte bNumEndpoints; uByte bInterfaceClass; uByte bInterfaceSubClass; uByte bInterfaceProtocol; uByte iInterface; } __packed; typedef struct usb_interface_descriptor usb_interface_descriptor_t; struct usb_interface_assoc_descriptor { uByte bLength; uByte bDescriptorType; uByte bFirstInterface; uByte bInterfaceCount; uByte bFunctionClass; uByte bFunctionSubClass; uByte bFunctionProtocol; uByte iFunction; } __packed; typedef struct usb_interface_assoc_descriptor usb_interface_assoc_descriptor_t; /* Interface class codes */ #define UICLASS_UNSPEC 0x00 #define UICLASS_AUDIO 0x01 /* audio */ #define UISUBCLASS_AUDIOCONTROL 1 #define UISUBCLASS_AUDIOSTREAM 2 #define UISUBCLASS_MIDISTREAM 3 #define UICLASS_CDC 0x02 /* communication */ #define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1 #define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2 #define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3 #define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4 #define UISUBCLASS_CAPI_CONTROLMODEL 5 #define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6 #define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7 #define UISUBCLASS_WIRELESS_HANDSET_CM 8 #define UISUBCLASS_DEVICE_MGMT 9 #define UISUBCLASS_MOBILE_DIRECT_LINE_MODEL 10 #define UISUBCLASS_OBEX 11 #define UISUBCLASS_ETHERNET_EMULATION_MODEL 12 #define UISUBCLASS_NETWORK_CONTROL_MODEL 13 #define UIPROTO_CDC_NONE 0 #define UIPROTO_CDC_AT 1 #define UIPROTO_CDC_EEM 7 #define UICLASS_HID 0x03 #define UISUBCLASS_BOOT 1 #define UIPROTO_BOOT_KEYBOARD 1 #define UIPROTO_MOUSE 2 #define UICLASS_PHYSICAL 0x05 #define UICLASS_IMAGE 0x06 #define UISUBCLASS_SIC 1 /* still image class */ #define UICLASS_PRINTER 0x07 #define UISUBCLASS_PRINTER 1 #define UIPROTO_PRINTER_UNI 1 #define UIPROTO_PRINTER_BI 2 #define UIPROTO_PRINTER_1284 3 #define UICLASS_MASS 0x08 #define UISUBCLASS_RBC 1 #define UISUBCLASS_SFF8020I 2 #define UISUBCLASS_QIC157 3 #define UISUBCLASS_UFI 4 #define UISUBCLASS_SFF8070I 5 #define UISUBCLASS_SCSI 6 #define UIPROTO_MASS_CBI_I 0 #define UIPROTO_MASS_CBI 1 #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */ #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */ #define UICLASS_HUB 0x09 #define UISUBCLASS_HUB 0 #define UIPROTO_FSHUB 0 #define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */ #define UIPROTO_HSHUBMTT 1 #define UICLASS_CDC_DATA 0x0a #define UISUBCLASS_DATA 0x00 #define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */ #define UIPROTO_DATA_HDLC 0x31 /* HDLC */ #define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */ #define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */ #define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */ #define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */ #define UIPROTO_DATA_V42BIS 0x90 /* Data compression */ #define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */ #define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */ #define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */ #define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */ #define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc. */ #define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */ #define UIPROTO_DATA_NCM 0x01 /* Network Control Model */ #define UICLASS_SMARTCARD 0x0b #define UICLASS_FIRM_UPD 0x0c #define UICLASS_SECURITY 0x0d #define UICLASS_DIAGNOSTIC 0xdc #define UICLASS_WIRELESS 0xe0 #define UISUBCLASS_RF 0x01 #define UIPROTO_BLUETOOTH 0x01 #define UIPROTO_RNDIS 0x03 #define UICLASS_IAD 0xEF /* Interface Association Descriptor */ #define UISUBCLASS_SYNC 0x01 #define UIPROTO_ACTIVESYNC 0x01 #define UICLASS_APPL_SPEC 0xfe #define UISUBCLASS_FIRMWARE_DOWNLOAD 1 #define UISUBCLASS_IRDA 2 #define UIPROTO_IRDA 0 #define UICLASS_VENDOR 0xff #define UISUBCLASS_XBOX360_CONTROLLER 0x5d #define UIPROTO_XBOX360_GAMEPAD 0x01 struct usb_endpoint_descriptor { uByte bLength; uByte bDescriptorType; uByte bEndpointAddress; #define UE_GET_DIR(a) ((a) & 0x80) #define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7)) #define UE_DIR_IN 0x80 /* IN-token endpoint, fixed */ #define UE_DIR_OUT 0x00 /* OUT-token endpoint, fixed */ #define UE_DIR_RX 0xfd /* for internal use only! */ #define UE_DIR_TX 0xfe /* for internal use only! */ #define UE_DIR_ANY 0xff /* for internal use only! */ #define UE_ADDR 0x0f #define UE_ADDR_ANY 0xff /* for internal use only! */ #define UE_GET_ADDR(a) ((a) & UE_ADDR) uByte bmAttributes; #define UE_XFERTYPE 0x03 #define UE_CONTROL 0x00 #define UE_ISOCHRONOUS 0x01 #define UE_BULK 0x02 #define UE_INTERRUPT 0x03 #define UE_BULK_INTR 0xfe /* for internal use only! */ #define UE_TYPE_ANY 0xff /* for internal use only! */ #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE) #define UE_ISO_TYPE 0x0c #define UE_ISO_ASYNC 0x04 #define UE_ISO_ADAPT 0x08 #define UE_ISO_SYNC 0x0c #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE) #define UE_ISO_USAGE 0x30 #define UE_ISO_USAGE_DATA 0x00 #define UE_ISO_USAGE_FEEDBACK 0x10 #define UE_ISO_USAGE_IMPLICT_FB 0x20 #define UE_GET_ISO_USAGE(a) ((a) & UE_ISO_USAGE) uWord wMaxPacketSize; #define UE_ZERO_MPS 0xFFFF /* for internal use only */ uByte bInterval; } __packed; typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t; struct usb_endpoint_ss_comp_descriptor { uByte bLength; uByte bDescriptorType; uByte bMaxBurst; uByte bmAttributes; #define UE_GET_BULK_STREAMS(x) ((x) & 0x0F) #define UE_GET_SS_ISO_MULT(x) ((x) & 0x03) uWord wBytesPerInterval; } __packed; typedef struct usb_endpoint_ss_comp_descriptor usb_endpoint_ss_comp_descriptor_t; struct usb_string_descriptor { uByte bLength; uByte bDescriptorType; uWord bString[126]; uByte bUnused; } __packed; typedef struct usb_string_descriptor usb_string_descriptor_t; #define USB_MAKE_STRING_DESC(m,name) \ static const struct { \ uByte bLength; \ uByte bDescriptorType; \ uByte bData[sizeof((uint8_t []){m})]; \ } __packed name = { \ .bLength = sizeof(name), \ .bDescriptorType = UDESC_STRING, \ .bData = { m }, \ } struct usb_string_lang { uByte bLength; uByte bDescriptorType; uByte bData[2]; } __packed; typedef struct usb_string_lang usb_string_lang_t; struct usb_hub_descriptor { uByte bDescLength; uByte bDescriptorType; uByte bNbrPorts; uWord wHubCharacteristics; #define UHD_PWR 0x0003 #define UHD_PWR_GANGED 0x0000 #define UHD_PWR_INDIVIDUAL 0x0001 #define UHD_PWR_NO_SWITCH 0x0002 #define UHD_COMPOUND 0x0004 #define UHD_OC 0x0018 #define UHD_OC_GLOBAL 0x0000 #define UHD_OC_INDIVIDUAL 0x0008 #define UHD_OC_NONE 0x0010 #define UHD_TT_THINK 0x0060 #define UHD_TT_THINK_8 0x0000 #define UHD_TT_THINK_16 0x0020 #define UHD_TT_THINK_24 0x0040 #define UHD_TT_THINK_32 0x0060 #define UHD_PORT_IND 0x0080 uByte bPwrOn2PwrGood; /* delay in 2 ms units */ #define UHD_PWRON_FACTOR 2 uByte bHubContrCurrent; uByte DeviceRemovable[32]; /* max 255 ports */ #define UHD_NOT_REMOV(desc, i) \ (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1) uByte PortPowerCtrlMask[1]; /* deprecated */ } __packed; typedef struct usb_hub_descriptor usb_hub_descriptor_t; struct usb_hub_ss_descriptor { uByte bLength; uByte bDescriptorType; uByte bNbrPorts; uWord wHubCharacteristics; uByte bPwrOn2PwrGood; /* delay in 2 ms units */ uByte bHubContrCurrent; uByte bHubHdrDecLat; uWord wHubDelay; uByte DeviceRemovable[32]; /* max 255 ports */ } __packed; typedef struct usb_hub_ss_descriptor usb_hub_ss_descriptor_t; /* minimum HUB descriptor (8-ports maximum) */ struct usb_hub_descriptor_min { uByte bDescLength; uByte bDescriptorType; uByte bNbrPorts; uWord wHubCharacteristics; uByte bPwrOn2PwrGood; uByte bHubContrCurrent; uByte DeviceRemovable[1]; uByte PortPowerCtrlMask[1]; } __packed; typedef struct usb_hub_descriptor_min usb_hub_descriptor_min_t; struct usb_device_qualifier { uByte bLength; uByte bDescriptorType; uWord bcdUSB; uByte bDeviceClass; uByte bDeviceSubClass; uByte bDeviceProtocol; uByte bMaxPacketSize0; uByte bNumConfigurations; uByte bReserved; } __packed; typedef struct usb_device_qualifier usb_device_qualifier_t; struct usb_otg_descriptor { uByte bLength; uByte bDescriptorType; uByte bmAttributes; #define UOTG_SRP 0x01 #define UOTG_HNP 0x02 } __packed; typedef struct usb_otg_descriptor usb_otg_descriptor_t; /* OTG feature selectors */ #define UOTG_B_HNP_ENABLE 3 #define UOTG_A_HNP_SUPPORT 4 #define UOTG_A_ALT_HNP_SUPPORT 5 struct usb_status { uWord wStatus; /* Device status flags */ #define UDS_SELF_POWERED 0x0001 #define UDS_REMOTE_WAKEUP 0x0002 /* Endpoint status flags */ #define UES_HALT 0x0001 } __packed; typedef struct usb_status usb_status_t; struct usb_hub_status { uWord wHubStatus; #define UHS_LOCAL_POWER 0x0001 #define UHS_OVER_CURRENT 0x0002 uWord wHubChange; } __packed; typedef struct usb_hub_status usb_hub_status_t; struct usb_port_status { uWord wPortStatus; #define UPS_CURRENT_CONNECT_STATUS 0x0001 #define UPS_PORT_ENABLED 0x0002 #define UPS_SUSPEND 0x0004 #define UPS_OVERCURRENT_INDICATOR 0x0008 #define UPS_RESET 0x0010 #define UPS_PORT_L1 0x0020 /* USB 2.0 only */ /* The link-state bits are valid for Super-Speed USB HUBs */ #define UPS_PORT_LINK_STATE_GET(x) (((x) >> 5) & 0xF) #define UPS_PORT_LINK_STATE_SET(x) (((x) & 0xF) << 5) #define UPS_PORT_LS_U0 0x00 #define UPS_PORT_LS_U1 0x01 #define UPS_PORT_LS_U2 0x02 #define UPS_PORT_LS_U3 0x03 #define UPS_PORT_LS_SS_DIS 0x04 #define UPS_PORT_LS_RX_DET 0x05 #define UPS_PORT_LS_SS_INA 0x06 #define UPS_PORT_LS_POLL 0x07 #define UPS_PORT_LS_RECOVER 0x08 #define UPS_PORT_LS_HOT_RST 0x09 #define UPS_PORT_LS_COMP_MODE 0x0A #define UPS_PORT_LS_LOOPBACK 0x0B #define UPS_PORT_LS_RESUME 0x0F #define UPS_PORT_POWER 0x0100 #define UPS_PORT_POWER_SS 0x0200 /* super-speed only */ #define UPS_LOW_SPEED 0x0200 #define UPS_HIGH_SPEED 0x0400 #define UPS_OTHER_SPEED 0x0600 /* currently FreeBSD specific */ #define UPS_PORT_TEST 0x0800 #define UPS_PORT_INDICATOR 0x1000 #define UPS_PORT_MODE_DEVICE 0x8000 /* currently FreeBSD specific */ uWord wPortChange; #define UPS_C_CONNECT_STATUS 0x0001 #define UPS_C_PORT_ENABLED 0x0002 #define UPS_C_SUSPEND 0x0004 #define UPS_C_OVERCURRENT_INDICATOR 0x0008 #define UPS_C_PORT_RESET 0x0010 #define UPS_C_PORT_L1 0x0020 /* USB 2.0 only */ #define UPS_C_BH_PORT_RESET 0x0020 /* USB 3.0 only */ #define UPS_C_PORT_LINK_STATE 0x0040 #define UPS_C_PORT_CONFIG_ERROR 0x0080 } __packed; typedef struct usb_port_status usb_port_status_t; /* * The "USB_SPEED" macros defines all the supported USB speeds. */ enum usb_dev_speed { USB_SPEED_VARIABLE, USB_SPEED_LOW, USB_SPEED_FULL, USB_SPEED_HIGH, USB_SPEED_SUPER, }; #define USB_SPEED_MAX (USB_SPEED_SUPER+1) /* * The "USB_REV" macros defines all the supported USB revisions. */ enum usb_revision { USB_REV_UNKNOWN, USB_REV_PRE_1_0, USB_REV_1_0, USB_REV_1_1, USB_REV_2_0, USB_REV_2_5, USB_REV_3_0 }; #define USB_REV_MAX (USB_REV_3_0+1) /* * Supported host controller modes. */ enum usb_hc_mode { USB_MODE_HOST, /* initiates transfers */ USB_MODE_DEVICE, /* bus transfer target */ USB_MODE_DUAL /* can be host or device */ }; #define USB_MODE_MAX (USB_MODE_DUAL+1) /* * The "USB_STATE" enums define all the supported device states. */ enum usb_dev_state { USB_STATE_DETACHED, USB_STATE_ATTACHED, USB_STATE_POWERED, USB_STATE_ADDRESSED, USB_STATE_CONFIGURED, }; #define USB_STATE_MAX (USB_STATE_CONFIGURED+1) /* * The "USB_EP_MODE" macros define all the currently supported * endpoint modes. */ enum usb_ep_mode { USB_EP_MODE_DEFAULT, USB_EP_MODE_STREAMS, /* USB3.0 specific */ USB_EP_MODE_HW_MASS_STORAGE, USB_EP_MODE_HW_SERIAL, USB_EP_MODE_HW_ETHERNET_CDC, USB_EP_MODE_HW_ETHERNET_NCM, USB_EP_MODE_MAX }; #endif /* _USB_STANDARD_H_ */ Index: head/sys/dev/usb/usb_pf.h =================================================================== --- head/sys/dev/usb/usb_pf.h (revision 367786) +++ head/sys/dev/usb/usb_pf.h (revision 367787) @@ -1,122 +1,122 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1990, 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from the Stanford/CMU enet packet filter, * (net/enet.c) distributed as part of 4.3BSD, and code contributed * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence * Berkeley Laboratory. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _DEV_USB_PF_H #define _DEV_USB_PF_H struct usbpf_pkthdr { uint32_t up_totlen; /* Total length including all headers */ uint32_t up_busunit; /* Host controller unit number */ uint8_t up_address; /* USB device index */ uint8_t up_mode; /* Mode of transfer */ #define USBPF_MODE_HOST 0 #define USBPF_MODE_DEVICE 1 uint8_t up_type; /* points SUBMIT / DONE */ uint8_t up_xfertype; /* Transfer type, see USB2.0 spec. */ uint32_t up_flags; /* Transfer flags */ #define USBPF_FLAG_FORCE_SHORT_XFER (1 << 0) #define USBPF_FLAG_SHORT_XFER_OK (1 << 1) #define USBPF_FLAG_SHORT_FRAMES_OK (1 << 2) #define USBPF_FLAG_PIPE_BOF (1 << 3) #define USBPF_FLAG_PROXY_BUFFER (1 << 4) #define USBPF_FLAG_EXT_BUFFER (1 << 5) #define USBPF_FLAG_MANUAL_STATUS (1 << 6) #define USBPF_FLAG_NO_PIPE_OK (1 << 7) #define USBPF_FLAG_STALL_PIPE (1 << 8) uint32_t up_status; /* Transfer status */ #define USBPF_STATUS_OPEN (1 << 0) #define USBPF_STATUS_TRANSFERRING (1 << 1) #define USBPF_STATUS_DID_DMA_DELAY (1 << 2) #define USBPF_STATUS_DID_CLOSE (1 << 3) #define USBPF_STATUS_DRAINING (1 << 4) #define USBPF_STATUS_STARTED (1 << 5) #define USBPF_STATUS_BW_RECLAIMED (1 << 6) #define USBPF_STATUS_CONTROL_XFR (1 << 7) #define USBPF_STATUS_CONTROL_HDR (1 << 8) #define USBPF_STATUS_CONTROL_ACT (1 << 9) #define USBPF_STATUS_CONTROL_STALL (1 << 10) #define USBPF_STATUS_SHORT_FRAMES_OK (1 << 11) #define USBPF_STATUS_SHORT_XFER_OK (1 << 12) #define USBPF_STATUS_BDMA_ENABLE (1 << 13) #define USBPF_STATUS_BDMA_NO_POST_SYNC (1 << 14) #define USBPF_STATUS_BDMA_SETUP (1 << 15) #define USBPF_STATUS_ISOCHRONOUS_XFR (1 << 16) #define USBPF_STATUS_CURR_DMA_SET (1 << 17) #define USBPF_STATUS_CAN_CANCEL_IMMED (1 << 18) #define USBPF_STATUS_DOING_CALLBACK (1 << 19) uint32_t up_error; /* USB error, see USB_ERR_XXX */ uint32_t up_interval; /* For interrupt and isoc (ms) */ uint32_t up_frames; /* Number of following frames */ uint32_t up_packet_size; /* Packet size used */ uint32_t up_packet_count; /* Packet count used */ uint32_t up_endpoint; /* USB endpoint / stream ID */ uint8_t up_speed; /* USB speed, see USB_SPEED_XXX */ /* sizeof(struct usbpf_pkthdr) == 128 bytes */ uint8_t up_reserved[83]; }; struct usbpf_framehdr { /* * The frame length field excludes length of frame header and * any alignment. */ uint32_t length; #define USBPF_FRAME_ALIGN(x) (((x) + 3) & ~3) uint32_t flags; #define USBPF_FRAMEFLAG_READ (1 << 0) #define USBPF_FRAMEFLAG_DATA_FOLLOWS (1 << 1) }; #define USBPF_HDR_LEN 128 /* bytes */ #define USBPF_FRAME_HDR_LEN 8 /* bytes */ extern uint8_t usbpf_pkthdr_size_ok[ (sizeof(struct usbpf_pkthdr) == USBPF_HDR_LEN) ? 1 : -1]; extern uint8_t usbpf_framehdr_size_ok[ (sizeof(struct usbpf_framehdr) == USBPF_FRAME_HDR_LEN) ? 1 : -1]; #define USBPF_XFERTAP_SUBMIT 0 #define USBPF_XFERTAP_DONE 1 -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_STANDALONE) void usbpf_attach(struct usb_bus *); void usbpf_detach(struct usb_bus *); void usbpf_xfertap(struct usb_xfer *, int); -#endif +#endif /* _KERNEL || _STANDALONE */ +#endif /* _DEV_USB_PF_H */ -#endif Index: head/sys/dev/usb/usbdi.h =================================================================== --- head/sys/dev/usb/usbdi.h (revision 367786) +++ head/sys/dev/usb/usbdi.h (revision 367787) @@ -1,713 +1,713 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2009 Andrew Thompson * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _USB_USBDI_H_ #define _USB_USBDI_H_ struct usb_fifo; struct usb_xfer; struct usb_device; struct usb_attach_arg; struct usb_interface; struct usb_endpoint; struct usb_page_cache; struct usb_page_search; struct usb_process; struct usb_proc_msg; struct usb_mbuf; struct usb_fs_privdata; struct mbuf; typedef enum { /* keep in sync with usb_errstr_table */ USB_ERR_NORMAL_COMPLETION = 0, USB_ERR_PENDING_REQUESTS, /* 1 */ USB_ERR_NOT_STARTED, /* 2 */ USB_ERR_INVAL, /* 3 */ USB_ERR_NOMEM, /* 4 */ USB_ERR_CANCELLED, /* 5 */ USB_ERR_BAD_ADDRESS, /* 6 */ USB_ERR_BAD_BUFSIZE, /* 7 */ USB_ERR_BAD_FLAG, /* 8 */ USB_ERR_NO_CALLBACK, /* 9 */ USB_ERR_IN_USE, /* 10 */ USB_ERR_NO_ADDR, /* 11 */ USB_ERR_NO_PIPE, /* 12 */ USB_ERR_ZERO_NFRAMES, /* 13 */ USB_ERR_ZERO_MAXP, /* 14 */ USB_ERR_SET_ADDR_FAILED, /* 15 */ USB_ERR_NO_POWER, /* 16 */ USB_ERR_TOO_DEEP, /* 17 */ USB_ERR_IOERROR, /* 18 */ USB_ERR_NOT_CONFIGURED, /* 19 */ USB_ERR_TIMEOUT, /* 20 */ USB_ERR_SHORT_XFER, /* 21 */ USB_ERR_STALLED, /* 22 */ USB_ERR_INTERRUPTED, /* 23 */ USB_ERR_DMA_LOAD_FAILED, /* 24 */ USB_ERR_BAD_CONTEXT, /* 25 */ USB_ERR_NO_ROOT_HUB, /* 26 */ USB_ERR_NO_INTR_THREAD, /* 27 */ USB_ERR_NOT_LOCKED, /* 28 */ USB_ERR_MAX } usb_error_t; /* * Flags for transfers */ #define USB_FORCE_SHORT_XFER 0x0001 /* force a short transmit last */ #define USB_SHORT_XFER_OK 0x0004 /* allow short reads */ #define USB_DELAY_STATUS_STAGE 0x0010 /* insert delay before STATUS stage */ #define USB_USER_DATA_PTR 0x0020 /* internal flag */ #define USB_MULTI_SHORT_OK 0x0040 /* allow multiple short frames */ #define USB_MANUAL_STATUS 0x0080 /* manual ctrl status */ #define USB_NO_TIMEOUT 0 #define USB_DEFAULT_TIMEOUT 5000 /* 5000 ms = 5 seconds */ -#if defined(_KERNEL) +#if defined(_KERNEL) || defined(_STANDALONE) /* typedefs */ typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t); typedef void (usb_proc_callback_t)(struct usb_proc_msg *); typedef usb_error_t (usb_handle_req_t)(struct usb_device *, struct usb_device_request *, const void **, uint16_t *); typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags); typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags); typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags); typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo); typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m); /* USB events */ #ifndef USB_GLOBAL_INCLUDE_FILE #include #endif typedef void (*usb_dev_configured_t)(void *, struct usb_device *, struct usb_attach_arg *); EVENTHANDLER_DECLARE(usb_dev_configured, usb_dev_configured_t); /* * The following macros are used used to convert milliseconds into * HZ. We use 1024 instead of 1000 milliseconds per second to save a * full division. */ #define USB_MS_HZ 1024 #define USB_MS_TO_TICKS(ms) \ (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ) /* * Common queue structure for USB transfers. */ struct usb_xfer_queue { TAILQ_HEAD(, usb_xfer) head; struct usb_xfer *curr; /* current USB transfer processed */ void (*command) (struct usb_xfer_queue *pq); uint8_t recurse_1:1; uint8_t recurse_2:1; uint8_t recurse_3:1; uint8_t reserved:5; }; /* * The following structure defines an USB endpoint * USB endpoint. */ struct usb_endpoint { /* queue of USB transfers */ struct usb_xfer_queue endpoint_q[USB_MAX_EP_STREAMS]; struct usb_endpoint_descriptor *edesc; struct usb_endpoint_ss_comp_descriptor *ecomp; const struct usb_pipe_methods *methods; /* set by HC driver */ uint16_t isoc_next; uint8_t toggle_next:1; /* next data toggle value */ uint8_t is_stalled:1; /* set if endpoint is stalled */ uint8_t is_synced:1; /* set if we a synchronised */ uint8_t unused:5; uint8_t iface_index; /* not used by "default endpoint" */ uint8_t refcount_alloc; /* allocation refcount */ uint8_t refcount_bw; /* bandwidth refcount */ #define USB_EP_REF_MAX 0x3f /* High-Speed resource allocation (valid if "refcount_bw" > 0) */ uint8_t usb_smask; /* USB start mask */ uint8_t usb_cmask; /* USB complete mask */ uint8_t usb_uframe; /* USB microframe */ /* USB endpoint mode, see USB_EP_MODE_XXX */ uint8_t ep_mode; }; /* * The following structure defines an USB interface. */ struct usb_interface { struct usb_interface_descriptor *idesc; device_t subdev; uint8_t alt_index; uint8_t parent_iface_index; /* Linux compat */ struct usb_host_interface *altsetting; struct usb_host_interface *cur_altsetting; struct usb_device *linux_udev; void *bsd_priv_sc; /* device specific information */ char *pnpinfo; /* additional PnP-info for this interface */ uint8_t num_altsetting; /* number of alternate settings */ uint8_t bsd_iface_index; }; /* * The following structure defines a set of USB transfer flags. */ struct usb_xfer_flags { uint8_t force_short_xfer:1; /* force a short transmit transfer * last */ uint8_t short_xfer_ok:1; /* allow short receive transfers */ uint8_t short_frames_ok:1; /* allow short frames */ uint8_t pipe_bof:1; /* block pipe on failure */ uint8_t proxy_buffer:1; /* makes buffer size a factor of * "max_frame_size" */ uint8_t ext_buffer:1; /* uses external DMA buffer */ uint8_t manual_status:1; /* non automatic status stage on * control transfers */ uint8_t no_pipe_ok:1; /* set if "USB_ERR_NO_PIPE" error can * be ignored */ uint8_t stall_pipe:1; /* set if the endpoint belonging to * this USB transfer should be stalled * before starting this transfer! */ uint8_t pre_scale_frames:1; /* "usb_config->frames" is * assumed to give the * buffering time in * milliseconds and is * converted into the nearest * number of frames when the * USB transfer is setup. This * option only has effect for * ISOCHRONOUS transfers. */ }; /* * The following structure define an USB configuration, that basically * is used when setting up an USB transfer. */ struct usb_config { usb_callback_t *callback; /* USB transfer callback */ usb_frlength_t bufsize; /* total pipe buffer size in bytes */ usb_frcount_t frames; /* maximum number of USB frames */ usb_timeout_t interval; /* interval in milliseconds */ #define USB_DEFAULT_INTERVAL 0 usb_timeout_t timeout; /* transfer timeout in milliseconds */ struct usb_xfer_flags flags; /* transfer flags */ usb_stream_t stream_id; /* USB3.0 specific */ enum usb_hc_mode usb_mode; /* host or device mode */ uint8_t type; /* pipe type */ uint8_t endpoint; /* pipe number */ uint8_t direction; /* pipe direction */ uint8_t ep_index; /* pipe index match to use */ uint8_t if_index; /* "ifaces" index to use */ }; /* * Use these macro when defining USB device ID arrays if you want to * have your driver module automatically loaded in host, device or * both modes respectively: */ #if USB_HAVE_ID_SECTION #define STRUCT_USB_HOST_ID \ struct usb_device_id __section("usb_host_id") #define STRUCT_USB_DEVICE_ID \ struct usb_device_id __section("usb_device_id") #define STRUCT_USB_DUAL_ID \ struct usb_device_id __section("usb_dual_id") #else #define STRUCT_USB_HOST_ID \ struct usb_device_id #define STRUCT_USB_DEVICE_ID \ struct usb_device_id #define STRUCT_USB_DUAL_ID \ struct usb_device_id #endif /* USB_HAVE_ID_SECTION */ /* * The following structure is used when looking up an USB driver for * an USB device. It is inspired by the Linux structure called * "usb_device_id". */ struct usb_device_id { /* Select which fields to match against */ #if BYTE_ORDER == LITTLE_ENDIAN uint16_t match_flag_vendor:1, match_flag_product:1, match_flag_dev_lo:1, match_flag_dev_hi:1, match_flag_dev_class:1, match_flag_dev_subclass:1, match_flag_dev_protocol:1, match_flag_int_class:1, match_flag_int_subclass:1, match_flag_int_protocol:1, match_flag_unused:6; #else uint16_t match_flag_unused:6, match_flag_int_protocol:1, match_flag_int_subclass:1, match_flag_int_class:1, match_flag_dev_protocol:1, match_flag_dev_subclass:1, match_flag_dev_class:1, match_flag_dev_hi:1, match_flag_dev_lo:1, match_flag_product:1, match_flag_vendor:1; #endif /* Used for product specific matches; the BCD range is inclusive */ uint16_t idVendor; uint16_t idProduct; uint16_t bcdDevice_lo; uint16_t bcdDevice_hi; /* Used for device class matches */ uint8_t bDeviceClass; uint8_t bDeviceSubClass; uint8_t bDeviceProtocol; /* Used for interface class matches */ uint8_t bInterfaceClass; uint8_t bInterfaceSubClass; uint8_t bInterfaceProtocol; #if USB_HAVE_COMPAT_LINUX /* which fields to match against */ uint16_t match_flags; #define USB_DEVICE_ID_MATCH_VENDOR 0x0001 #define USB_DEVICE_ID_MATCH_PRODUCT 0x0002 #define USB_DEVICE_ID_MATCH_DEV_LO 0x0004 #define USB_DEVICE_ID_MATCH_DEV_HI 0x0008 #define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010 #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020 #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040 #define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200 #endif /* Hook for driver specific information */ unsigned long driver_info; } __aligned(32); #define USB_STD_PNP_INFO "M16:mask;U16:vendor;U16:product;L16:release;G16:release;" \ "U8:devclass;U8:devsubclass;U8:devproto;" \ "U8:intclass;U8:intsubclass;U8:intprotocol;" #define USB_STD_PNP_HOST_INFO USB_STD_PNP_INFO "T:mode=host;" #define USB_STD_PNP_DEVICE_INFO USB_STD_PNP_INFO "T:mode=device;" #define USB_PNP_HOST_INFO(table) \ MODULE_PNP_INFO(USB_STD_PNP_HOST_INFO, uhub, table, table, \ sizeof(table) / sizeof(table[0])) #define USB_PNP_DEVICE_INFO(table) \ MODULE_PNP_INFO(USB_STD_PNP_DEVICE_INFO, uhub, table, table, \ sizeof(table) / sizeof(table[0])) #define USB_PNP_DUAL_INFO(table) \ MODULE_PNP_INFO(USB_STD_PNP_INFO, uhub, table, table, \ sizeof(table) / sizeof(table[0])) /* check that the size of the structure above is correct */ extern char usb_device_id_assert[(sizeof(struct usb_device_id) == 32) ? 1 : -1]; #define USB_VENDOR(vend) \ .match_flag_vendor = 1, .idVendor = (vend) #define USB_PRODUCT(prod) \ .match_flag_product = 1, .idProduct = (prod) #define USB_VP(vend,prod) \ USB_VENDOR(vend), USB_PRODUCT(prod) #define USB_VPI(vend,prod,info) \ USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info) #define USB_DEV_BCD_GTEQ(lo) /* greater than or equal */ \ .match_flag_dev_lo = 1, .bcdDevice_lo = (lo) #define USB_DEV_BCD_LTEQ(hi) /* less than or equal */ \ .match_flag_dev_hi = 1, .bcdDevice_hi = (hi) #define USB_DEV_CLASS(dc) \ .match_flag_dev_class = 1, .bDeviceClass = (dc) #define USB_DEV_SUBCLASS(dsc) \ .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc) #define USB_DEV_PROTOCOL(dp) \ .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp) #define USB_IFACE_CLASS(ic) \ .match_flag_int_class = 1, .bInterfaceClass = (ic) #define USB_IFACE_SUBCLASS(isc) \ .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc) #define USB_IFACE_PROTOCOL(ip) \ .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip) #define USB_IF_CSI(class,subclass,info) \ USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info) #define USB_DRIVER_INFO(n) \ .driver_info = (n) #define USB_GET_DRIVER_INFO(did) \ (did)->driver_info /* * The following structure keeps information that is used to match * against an array of "usb_device_id" elements. */ struct usbd_lookup_info { uint16_t idVendor; uint16_t idProduct; uint16_t bcdDevice; uint8_t bDeviceClass; uint8_t bDeviceSubClass; uint8_t bDeviceProtocol; uint8_t bInterfaceClass; uint8_t bInterfaceSubClass; uint8_t bInterfaceProtocol; uint8_t bIfaceIndex; uint8_t bIfaceNum; uint8_t bConfigIndex; uint8_t bConfigNum; }; /* Structure used by probe and attach */ struct usb_attach_arg { struct usbd_lookup_info info; device_t temp_dev; /* for internal use */ unsigned long driver_info; /* for internal use */ void *driver_ivar; struct usb_device *device; /* current device */ struct usb_interface *iface; /* current interface */ enum usb_hc_mode usb_mode; /* host or device mode */ uint8_t port; uint8_t dev_state; #define UAA_DEV_READY 0 #define UAA_DEV_DISABLED 1 #define UAA_DEV_EJECTING 2 }; /* * General purpose locking wrappers to ease supporting * USB polled mode: */ #ifdef INVARIANTS #define USB_MTX_ASSERT(_m, _t) do { \ if (!USB_IN_POLLING_MODE_FUNC()) \ mtx_assert(_m, _t); \ } while (0) #else #define USB_MTX_ASSERT(_m, _t) do { } while (0) #endif #define USB_MTX_LOCK(_m) do { \ if (!USB_IN_POLLING_MODE_FUNC()) \ mtx_lock(_m); \ } while (0) #define USB_MTX_UNLOCK(_m) do { \ if (!USB_IN_POLLING_MODE_FUNC()) \ mtx_unlock(_m); \ } while (0) #define USB_MTX_LOCK_SPIN(_m) do { \ if (!USB_IN_POLLING_MODE_FUNC()) \ mtx_lock_spin(_m); \ } while (0) #define USB_MTX_UNLOCK_SPIN(_m) do { \ if (!USB_IN_POLLING_MODE_FUNC()) \ mtx_unlock_spin(_m); \ } while (0) /* * The following is a wrapper for the callout structure to ease * porting the code to other platforms. */ struct usb_callout { struct callout co; }; #define usb_callout_init_mtx(c,m,f) callout_init_mtx(&(c)->co,m,f) #define usb_callout_reset(c,...) do { \ if (!USB_IN_POLLING_MODE_FUNC()) \ callout_reset(&(c)->co, __VA_ARGS__); \ } while (0) #define usb_callout_reset_sbt(c,...) do { \ if (!USB_IN_POLLING_MODE_FUNC()) \ callout_reset_sbt(&(c)->co, __VA_ARGS__); \ } while (0) #define usb_callout_stop(c) do { \ if (!USB_IN_POLLING_MODE_FUNC()) { \ callout_stop(&(c)->co); \ } else { \ /* \ * Cannot stop callout when \ * polling. Set dummy callback \ * function instead: \ */ \ (c)->co.c_func = &usbd_dummy_timeout; \ } \ } while (0) #define usb_callout_drain(c) callout_drain(&(c)->co) #define usb_callout_pending(c) callout_pending(&(c)->co) /* USB transfer states */ #define USB_ST_SETUP 0 #define USB_ST_TRANSFERRED 1 #define USB_ST_ERROR 2 /* USB handle request states */ #define USB_HR_NOT_COMPLETE 0 #define USB_HR_COMPLETE_OK 1 #define USB_HR_COMPLETE_ERR 2 /* * The following macro will return the current state of an USB * transfer like defined by the "USB_ST_XXX" enums. */ #define USB_GET_STATE(xfer) (usbd_xfer_state(xfer)) /* * The following structure defines the USB process message header. */ struct usb_proc_msg { TAILQ_ENTRY(usb_proc_msg) pm_qentry; usb_proc_callback_t *pm_callback; usb_size_t pm_num; }; #define USB_FIFO_TX 0 #define USB_FIFO_RX 1 /* * Locking note for the following functions. All the * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called * locked. The others are called unlocked. */ struct usb_fifo_methods { usb_fifo_open_t *f_open; usb_fifo_close_t *f_close; usb_fifo_ioctl_t *f_ioctl; /* * NOTE: The post-ioctl callback is called after the USB reference * gets locked in the IOCTL handler: */ usb_fifo_ioctl_t *f_ioctl_post; usb_fifo_cmd_t *f_start_read; usb_fifo_cmd_t *f_stop_read; usb_fifo_cmd_t *f_start_write; usb_fifo_cmd_t *f_stop_write; usb_fifo_filter_t *f_filter_read; usb_fifo_filter_t *f_filter_write; const char *basename[4]; const char *postfix[4]; }; struct usb_fifo_sc { struct usb_fifo *fp[2]; struct usb_fs_privdata *dev; }; const char *usbd_errstr(usb_error_t error); void *usbd_find_descriptor(struct usb_device *udev, void *id, uint8_t iface_index, uint8_t type, uint8_t type_mask, uint8_t subtype, uint8_t subtype_mask); struct usb_config_descriptor *usbd_get_config_descriptor( struct usb_device *udev); struct usb_device_descriptor *usbd_get_device_descriptor( struct usb_device *udev); struct usb_interface *usbd_get_iface(struct usb_device *udev, uint8_t iface_index); struct usb_interface_descriptor *usbd_get_interface_descriptor( struct usb_interface *iface); struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index, const struct usb_config *setup); struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val); usb_error_t usbd_interface_count(struct usb_device *udev, uint8_t *count); enum usb_hc_mode usbd_get_mode(struct usb_device *udev); enum usb_dev_speed usbd_get_speed(struct usb_device *udev); void device_set_usb_desc(device_t dev); void usb_pause_mtx(struct mtx *mtx, int _ticks); usb_error_t usbd_set_pnpinfo(struct usb_device *udev, uint8_t iface_index, const char *pnpinfo); usb_error_t usbd_add_dynamic_quirk(struct usb_device *udev, uint16_t quirk); usb_error_t usbd_set_endpoint_mode(struct usb_device *udev, struct usb_endpoint *ep, uint8_t ep_mode); uint8_t usbd_get_endpoint_mode(struct usb_device *udev, struct usb_endpoint *ep); const struct usb_device_id *usbd_lookup_id_by_info( const struct usb_device_id *id, usb_size_t sizeof_id, const struct usbd_lookup_info *info); int usbd_lookup_id_by_uaa(const struct usb_device_id *id, usb_size_t sizeof_id, struct usb_attach_arg *uaa); usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx, struct usb_device_request *req, void *data, uint16_t flags, uint16_t *actlen, usb_timeout_t timeout); #define usbd_do_request(u,m,r,d) \ usbd_do_request_flags(u,m,r,d,0,NULL,USB_DEFAULT_TIMEOUT) uint8_t usbd_clear_stall_callback(struct usb_xfer *xfer1, struct usb_xfer *xfer2); uint8_t usbd_get_interface_altindex(struct usb_interface *iface); usb_error_t usbd_set_alt_interface_index(struct usb_device *udev, uint8_t iface_index, uint8_t alt_index); uint32_t usbd_get_isoc_fps(struct usb_device *udev); uint32_t usbd_get_max_frame_length(const struct usb_endpoint_descriptor *, const struct usb_endpoint_ss_comp_descriptor *, enum usb_dev_speed); usb_error_t usbd_transfer_setup(struct usb_device *udev, const uint8_t *ifaces, struct usb_xfer **pxfer, const struct usb_config *setup_start, uint16_t n_setup, void *priv_sc, struct mtx *priv_mtx); void usbd_transfer_submit(struct usb_xfer *xfer); void usbd_transfer_clear_stall(struct usb_xfer *xfer); void usbd_transfer_drain(struct usb_xfer *xfer); uint8_t usbd_transfer_pending(struct usb_xfer *xfer); void usbd_transfer_start(struct usb_xfer *xfer); void usbd_transfer_stop(struct usb_xfer *xfer); void usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup); void usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max); void usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index, uint8_t parent_index); uint8_t usbd_get_bus_index(struct usb_device *udev); uint8_t usbd_get_device_index(struct usb_device *udev); void usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode); uint8_t usbd_filter_power_mode(struct usb_device *udev, uint8_t power_mode); uint8_t usbd_device_attached(struct usb_device *udev); usb_frlength_t usbd_xfer_old_frame_length(struct usb_xfer *xfer, usb_frcount_t frindex); void usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen, int *aframes, int *nframes); struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *, usb_frcount_t); void *usbd_xfer_get_frame_buffer(struct usb_xfer *, usb_frcount_t); void *usbd_xfer_softc(struct usb_xfer *xfer); void *usbd_xfer_get_priv(struct usb_xfer *xfer); void usbd_xfer_set_priv(struct usb_xfer *xfer, void *); void usbd_xfer_set_interval(struct usb_xfer *xfer, int); uint8_t usbd_xfer_state(struct usb_xfer *xfer); void usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, void *ptr, usb_frlength_t len); void usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex, void **ptr, int *len); void usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset, usb_frcount_t frindex); usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer); usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer); usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer); uint8_t usbd_xfer_get_fps_shift(struct usb_xfer *xfer); usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex); void usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex, usb_frlength_t len); void usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout); void usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n); void usbd_xfer_set_stall(struct usb_xfer *xfer); int usbd_xfer_is_stalled(struct usb_xfer *xfer); void usbd_xfer_set_flag(struct usb_xfer *xfer, int flag); void usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag); uint16_t usbd_xfer_get_timestamp(struct usb_xfer *xfer); uint8_t usbd_xfer_maxp_was_clamped(struct usb_xfer *xfer); void usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset, const void *ptr, usb_frlength_t len); int usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset, const void *ptr, usb_frlength_t len); void usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset, void *ptr, usb_frlength_t len); int usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset, void *ptr, usb_frlength_t len); void usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset, struct usb_page_search *res); void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset, struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len); void usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset, usb_frlength_t len); void usbd_start_re_enumerate(struct usb_device *udev); usb_error_t usbd_start_set_config(struct usb_device *, uint8_t); int usbd_in_polling_mode(void); void usbd_dummy_timeout(void *); int usb_fifo_attach(struct usb_device *udev, void *priv_sc, struct mtx *priv_mtx, struct usb_fifo_methods *pm, struct usb_fifo_sc *f_sc, uint16_t unit, int16_t subunit, uint8_t iface_index, uid_t uid, gid_t gid, int mode); void usb_fifo_detach(struct usb_fifo_sc *f_sc); int usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize, uint16_t nbuf); void usb_fifo_free_buffer(struct usb_fifo *f); uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo); void usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc, usb_frlength_t offset, usb_frlength_t len, uint8_t what); void usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr, usb_size_t len, uint8_t what); uint8_t usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len); void usb_fifo_put_data_error(struct usb_fifo *fifo); uint8_t usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc, usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen, uint8_t what); uint8_t usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr, usb_size_t len, usb_size_t *actlen, uint8_t what); uint8_t usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr, usb_size_t *plen); void usb_fifo_reset(struct usb_fifo *f); void usb_fifo_wakeup(struct usb_fifo *f); void usb_fifo_get_data_error(struct usb_fifo *fifo); void *usb_fifo_softc(struct usb_fifo *fifo); void usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t); void usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t); void usb_fifo_free(struct usb_fifo *f); -#endif /* _KERNEL */ -#endif /* _USB_USBDI_H_ */ +#endif /* _KERNEL || _STANDALONE */ +#endif /* _USB_USBDI_H_ */ Index: head/sys/dev/usb/usbhid.h =================================================================== --- head/sys/dev/usb/usbhid.h (revision 367786) +++ head/sys/dev/usb/usbhid.h (revision 367787) @@ -1,278 +1,278 @@ /* $FreeBSD$ */ /*- * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. * Copyright (c) 1998 Lennart Augustsson. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _USB_HID_H_ #define _USB_HID_H_ #ifndef USB_GLOBAL_INCLUDE_FILE #include #endif #define UR_GET_HID_DESCRIPTOR 0x06 #define UDESC_HID 0x21 #define UDESC_REPORT 0x22 #define UDESC_PHYSICAL 0x23 #define UR_SET_HID_DESCRIPTOR 0x07 #define UR_GET_REPORT 0x01 #define UR_SET_REPORT 0x09 #define UR_GET_IDLE 0x02 #define UR_SET_IDLE 0x0a #define UR_GET_PROTOCOL 0x03 #define UR_SET_PROTOCOL 0x0b struct usb_hid_descriptor { uByte bLength; uByte bDescriptorType; uWord bcdHID; uByte bCountryCode; uByte bNumDescriptors; struct { uByte bDescriptorType; uWord wDescriptorLength; } descrs[1]; } __packed; #define USB_HID_DESCRIPTOR_SIZE(n) (9+((n)*3)) /* Usage pages */ #define HUP_UNDEFINED 0x0000 #define HUP_GENERIC_DESKTOP 0x0001 #define HUP_SIMULATION 0x0002 #define HUP_VR_CONTROLS 0x0003 #define HUP_SPORTS_CONTROLS 0x0004 #define HUP_GAMING_CONTROLS 0x0005 #define HUP_KEYBOARD 0x0007 #define HUP_LEDS 0x0008 #define HUP_BUTTON 0x0009 #define HUP_ORDINALS 0x000a #define HUP_TELEPHONY 0x000b #define HUP_CONSUMER 0x000c #define HUP_DIGITIZERS 0x000d #define HUP_PHYSICAL_IFACE 0x000e #define HUP_UNICODE 0x0010 #define HUP_ALPHANUM_DISPLAY 0x0014 #define HUP_MONITOR 0x0080 #define HUP_MONITOR_ENUM_VAL 0x0081 #define HUP_VESA_VC 0x0082 #define HUP_VESA_CMD 0x0083 #define HUP_POWER 0x0084 #define HUP_BATTERY_SYSTEM 0x0085 #define HUP_BARCODE_SCANNER 0x008b #define HUP_SCALE 0x008c #define HUP_CAMERA_CONTROL 0x0090 #define HUP_ARCADE 0x0091 #define HUP_MICROSOFT 0xff00 /* Usages, generic desktop */ #define HUG_POINTER 0x0001 #define HUG_MOUSE 0x0002 #define HUG_JOYSTICK 0x0004 #define HUG_GAME_PAD 0x0005 #define HUG_KEYBOARD 0x0006 #define HUG_KEYPAD 0x0007 #define HUG_X 0x0030 #define HUG_Y 0x0031 #define HUG_Z 0x0032 #define HUG_RX 0x0033 #define HUG_RY 0x0034 #define HUG_RZ 0x0035 #define HUG_SLIDER 0x0036 #define HUG_DIAL 0x0037 #define HUG_WHEEL 0x0038 #define HUG_HAT_SWITCH 0x0039 #define HUG_COUNTED_BUFFER 0x003a #define HUG_BYTE_COUNT 0x003b #define HUG_MOTION_WAKEUP 0x003c #define HUG_VX 0x0040 #define HUG_VY 0x0041 #define HUG_VZ 0x0042 #define HUG_VBRX 0x0043 #define HUG_VBRY 0x0044 #define HUG_VBRZ 0x0045 #define HUG_VNO 0x0046 #define HUG_TWHEEL 0x0048 /* M$ Wireless Intellimouse Wheel */ #define HUG_SYSTEM_CONTROL 0x0080 #define HUG_SYSTEM_POWER_DOWN 0x0081 #define HUG_SYSTEM_SLEEP 0x0082 #define HUG_SYSTEM_WAKEUP 0x0083 #define HUG_SYSTEM_CONTEXT_MENU 0x0084 #define HUG_SYSTEM_MAIN_MENU 0x0085 #define HUG_SYSTEM_APP_MENU 0x0086 #define HUG_SYSTEM_MENU_HELP 0x0087 #define HUG_SYSTEM_MENU_EXIT 0x0088 #define HUG_SYSTEM_MENU_SELECT 0x0089 #define HUG_SYSTEM_MENU_RIGHT 0x008a #define HUG_SYSTEM_MENU_LEFT 0x008b #define HUG_SYSTEM_MENU_UP 0x008c #define HUG_SYSTEM_MENU_DOWN 0x008d #define HUG_APPLE_EJECT 0x00b8 /* Usages Digitizers */ #define HUD_UNDEFINED 0x0000 #define HUD_DIGITIZER 0x0001 #define HUD_PEN 0x0002 #define HUD_TOUCHSCREEN 0x0004 #define HUD_TOUCHPAD 0x0005 #define HUD_CONFIG 0x000e #define HUD_FINGER 0x0022 #define HUD_TIP_PRESSURE 0x0030 #define HUD_BARREL_PRESSURE 0x0031 #define HUD_IN_RANGE 0x0032 #define HUD_TOUCH 0x0033 #define HUD_UNTOUCH 0x0034 #define HUD_TAP 0x0035 #define HUD_QUALITY 0x0036 #define HUD_DATA_VALID 0x0037 #define HUD_TRANSDUCER_INDEX 0x0038 #define HUD_TABLET_FKEYS 0x0039 #define HUD_PROGRAM_CHANGE_KEYS 0x003a #define HUD_BATTERY_STRENGTH 0x003b #define HUD_INVERT 0x003c #define HUD_X_TILT 0x003d #define HUD_Y_TILT 0x003e #define HUD_AZIMUTH 0x003f #define HUD_ALTITUDE 0x0040 #define HUD_TWIST 0x0041 #define HUD_TIP_SWITCH 0x0042 #define HUD_SEC_TIP_SWITCH 0x0043 #define HUD_BARREL_SWITCH 0x0044 #define HUD_ERASER 0x0045 #define HUD_TABLET_PICK 0x0046 #define HUD_CONFIDENCE 0x0047 #define HUD_WIDTH 0x0048 #define HUD_HEIGHT 0x0049 #define HUD_CONTACTID 0x0051 #define HUD_INPUT_MODE 0x0052 #define HUD_DEVICE_INDEX 0x0053 #define HUD_CONTACTCOUNT 0x0054 #define HUD_CONTACT_MAX 0x0055 #define HUD_SCAN_TIME 0x0056 #define HUD_SURFACE_SWITCH 0x0057 #define HUD_BUTTONS_SWITCH 0x0058 #define HUD_BUTTON_TYPE 0x0059 #define HUD_LATENCY_MODE 0x0060 /* Usages, Consumer */ #define HUC_AC_PAN 0x0238 #define HID_USAGE2(p,u) (((p) << 16) | (u)) #define UHID_INPUT_REPORT 0x01 #define UHID_OUTPUT_REPORT 0x02 #define UHID_FEATURE_REPORT 0x03 /* Bits in the input/output/feature items */ #define HIO_CONST 0x001 #define HIO_VARIABLE 0x002 #define HIO_RELATIVE 0x004 #define HIO_WRAP 0x008 #define HIO_NONLINEAR 0x010 #define HIO_NOPREF 0x020 #define HIO_NULLSTATE 0x040 #define HIO_VOLATILE 0x080 #define HIO_BUFBYTES 0x100 /* Units of Measure */ #define HUM_CENTIMETER 0x11 #define HUM_RADIAN 0x12 #define HUM_INCH 0x13 #define HUM_DEGREE 0x14 -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_STANDALONE) struct usb_config_descriptor; enum hid_kind { hid_input, hid_output, hid_feature, hid_collection, hid_endcollection }; struct hid_location { uint32_t size; uint32_t count; uint32_t pos; }; struct hid_item { /* Global */ int32_t _usage_page; int32_t logical_minimum; int32_t logical_maximum; int32_t physical_minimum; int32_t physical_maximum; int32_t unit_exponent; int32_t unit; int32_t report_ID; /* Local */ int32_t usage; int32_t usage_minimum; int32_t usage_maximum; int32_t designator_index; int32_t designator_minimum; int32_t designator_maximum; int32_t string_index; int32_t string_minimum; int32_t string_maximum; int32_t set_delimiter; /* Misc */ int32_t collection; int collevel; enum hid_kind kind; uint32_t flags; /* Location */ struct hid_location loc; }; /* prototypes from "usb_hid.c" */ struct hid_data *hid_start_parse(const void *d, usb_size_t len, int kindset); void hid_end_parse(struct hid_data *s); int hid_get_item(struct hid_data *s, struct hid_item *h); int hid_report_size(const void *buf, usb_size_t len, enum hid_kind k, uint8_t *id); int hid_locate(const void *desc, usb_size_t size, int32_t usage, enum hid_kind kind, uint8_t index, struct hid_location *loc, uint32_t *flags, uint8_t *id); int32_t hid_get_data(const uint8_t *buf, usb_size_t len, struct hid_location *loc); uint32_t hid_get_data_unsigned(const uint8_t *buf, usb_size_t len, struct hid_location *loc); void hid_put_data_unsigned(uint8_t *buf, usb_size_t len, struct hid_location *loc, unsigned int value); int hid_is_collection(const void *desc, usb_size_t size, int32_t usage); struct usb_hid_descriptor *hid_get_descriptor_from_usb( struct usb_config_descriptor *cd, struct usb_interface_descriptor *id); usb_error_t usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx, void **descp, uint16_t *sizep, struct malloc_type *mem, uint8_t iface_index); int32_t hid_item_resolution(struct hid_item *hi); int hid_is_mouse(const void *d_ptr, uint16_t d_len); int hid_is_keyboard(const void *d_ptr, uint16_t d_len); -#endif /* _KERNEL */ -#endif /* _USB_HID_H_ */ +#endif /* _KERNEL || _STANDALONE */ +#endif /* _USB_HID_H_ */