1 /** $MirOS: src/sys/dev/usb/usb_port.h,v 1.4 2005/07/04 01:42:38 tg Exp $ */ 2 /* $OpenBSD: usb_port.h,v 1.58 2005/06/17 23:50:33 deraadt Exp $ */ 3 /* $NetBSD: usb_port.h,v 1.62 2003/02/15 18:33:30 augustss Exp $ */ 4 /* $FreeBSD: src/sys/dev/usb/usb_port.h,v 1.21 1999/11/17 22:33:47 n_hibma Exp $ */ 5 6 /* 7 * Copyright (c) 1998 The NetBSD Foundation, Inc. 8 * All rights reserved. 9 * 10 * This code is derived from software contributed to The NetBSD Foundation 11 * by Lennart Augustsson (lennart@augustsson.net) at 12 * Carlstedt Research & Technology. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. All advertising materials mentioning features or use of this software 23 * must display the following acknowledgement: 24 * This product includes software developed by the NetBSD 25 * Foundation, Inc. and its contributors. 26 * 4. Neither the name of The NetBSD Foundation nor the names of its 27 * contributors may be used to endorse or promote products derived 28 * from this software without specific prior written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 34 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 40 * POSSIBILITY OF SUCH DAMAGE. 41 */ 42 43 #ifndef _USB_PORT_H 44 #define _USB_PORT_H 45 46 /* 47 * Macro's to cope with the differences between operating systems. 48 */ 49 50 #if defined(__NetBSD__) 51 /* 52 * NetBSD 53 */ 54 55 #include "opt_usbverbose.h" 56 57 #if defined(_KERNEL) 58 #include <sys/mallocvar.h> 59 60 MALLOC_DECLARE(M_USB); 61 MALLOC_DECLARE(M_USBDEV); 62 MALLOC_DECLARE(M_USBHC); 63 64 #endif 65 66 #define USB_USE_SOFTINTR 67 68 #ifdef USB_DEBUG 69 #define UKBD_DEBUG 1 70 #define UHIDEV_DEBUG 1 71 #define UHID_DEBUG 1 72 #define OHCI_DEBUG 1 73 #define UGEN_DEBUG 1 74 #define UHCI_DEBUG 1 75 #define UHUB_DEBUG 1 76 #define ULPT_DEBUG 1 77 #define UCOM_DEBUG 1 78 #define UPLCOM_DEBUG 1 79 #define UMCT_DEBUG 1 80 #define UMODEM_DEBUG 1 81 #define UAUDIO_DEBUG 1 82 #define AUE_DEBUG 1 83 #define AXE_DEBUG 1 84 #define CUE_DEBUG 1 85 #define KUE_DEBUG 1 86 #define UDAV_DEBUG 1 87 #define URL_DEBUG 1 88 #define UMASS_DEBUG 1 89 #define UVISOR_DEBUG 1 90 #define UPL_DEBUG 1 91 #define UZCOM_DEBUG 1 92 #define URIO_DEBUG 1 93 #define UFTDI_DEBUG 1 94 #define USCANNER_DEBUG 1 95 #define USSCANNER_DEBUG 1 96 #define UIRDA_DEBUG 1 97 #define USTIR_DEBUG 1 98 #define UISDATA_DEBUG 1 99 #define UDSBR_DEBUG 1 100 #define UBT_DEBUG 1 101 #define UAX_DEBUG 1 102 #define UIPAQ_DEBUG 1 103 #define Static 104 #else 105 #define Static static 106 #endif 107 108 #define SCSI_MODE_SENSE MODE_SENSE 109 110 #define UMASS_ATAPISTR "atapibus" 111 112 typedef struct proc *usb_proc_ptr; 113 114 typedef struct device *device_ptr_t; 115 #define USBBASEDEVICE struct device 116 #define USBDEV(bdev) (&(bdev)) 117 #define USBDEVNAME(bdev) ((bdev).dv_xname) 118 #define USBDEVUNIT(bdev) ((bdev).dv_unit) 119 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname) 120 #define USBGETSOFTC(d) ((void *)(d)) 121 122 #define DECLARE_USB_DMA_T \ 123 struct usb_dma_block; \ 124 typedef struct { \ 125 struct usb_dma_block *block; \ 126 u_int offs; \ 127 } usb_dma_t 128 129 typedef struct callout usb_callout_t; 130 #define usb_callout_init(h) callout_init(&(h)) 131 #define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d)) 132 #define usb_callout_pending(h) callout_pending(&(h)) 133 #define usb_uncallout(h, f, d) callout_stop(&(h)) 134 135 #define usb_lockmgr(l, f, sl, p) lockmgr((l), (f), (sl)) 136 137 #define usb_kthread_create1 kthread_create1 138 #define usb_kthread_create kthread_create 139 140 typedef struct malloc_type *usb_malloc_type; 141 142 #define Ether_ifattach ether_ifattach 143 #define IF_INPUT(ifp, m) (*(ifp)->if_input)((ifp), (m)) 144 145 #define logprintf printf 146 147 #define USB_DNAME(dname) dname 148 #define USB_DECLARE_DRIVER(dname) \ 149 int __CONCAT(dname,_match)(struct device *, struct cfdata *, void *); \ 150 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \ 151 int __CONCAT(dname,_detach)(struct device *, int); \ 152 int __CONCAT(dname,_activate)(struct device *, enum devact); \ 153 \ 154 extern struct cfdriver __CONCAT(dname,_cd); \ 155 \ 156 CFATTACH_DECL(USB_DNAME(dname), \ 157 sizeof(struct ___CONCAT(dname,_softc)), \ 158 ___CONCAT(dname,_match), \ 159 ___CONCAT(dname,_attach), \ 160 ___CONCAT(dname,_detach), \ 161 ___CONCAT(dname,_activate)) 162 163 #define USB_MATCH(dname) \ 164 int __CONCAT(dname,_match)(struct device *parent, struct cfdata *match, void *aux) 165 166 #define USB_MATCH_START(dname, uaa) \ 167 struct usb_attach_arg *uaa = aux 168 169 #define USB_ATTACH(dname) \ 170 void __CONCAT(dname,_attach)(struct device *parent, struct device *self, void *aux) 171 172 #define USB_ATTACH_START(dname, sc, uaa) \ 173 struct __CONCAT(dname,_softc) *sc = \ 174 (struct __CONCAT(dname,_softc) *)self; \ 175 struct usb_attach_arg *uaa = aux 176 177 /* Returns from attach */ 178 #define USB_ATTACH_ERROR_RETURN return 179 #define USB_ATTACH_SUCCESS_RETURN return 180 181 #define USB_ATTACH_SETUP printf("\n") 182 183 #define USB_DETACH(dname) \ 184 int __CONCAT(dname,_detach)(struct device *self, int flags) 185 186 #define USB_DETACH_START(dname, sc) \ 187 struct __CONCAT(dname,_softc) *sc = \ 188 (struct __CONCAT(dname,_softc) *)self 189 190 #define USB_GET_SC_OPEN(dname, unit, sc) \ 191 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \ 192 return (ENXIO); \ 193 sc = __CONCAT(dname,_cd).cd_devs[unit]; \ 194 if (sc == NULL) \ 195 return (ENXIO) 196 197 #define USB_GET_SC(dname, unit, sc) \ 198 sc = __CONCAT(dname,_cd).cd_devs[unit] 199 200 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \ 201 (config_found_sm(parent, args, print, sub)) 202 203 #elif defined(__OpenBSD__) 204 /* 205 * OpenBSD 206 */ 207 #include <sys/timeout.h> 208 209 #undef USB_USE_SOFTINTR 210 211 #ifdef USB_DEBUG 212 #define UKBD_DEBUG 1 213 #define UHIDEV_DEBUG 1 214 #define UHID_DEBUG 1 215 #define OHCI_DEBUG 1 216 #define UGEN_DEBUG 1 217 #define UHCI_DEBUG 1 218 #define UHUB_DEBUG 1 219 #define ULPT_DEBUG 1 220 #define UCOM_DEBUG 1 221 #define UPLCOM_DEBUG 1 222 #define UMCT_DEBUG 1 223 #define UMODEM_DEBUG 1 224 #define UAUDIO_DEBUG 1 225 #define AUE_DEBUG 1 226 #define CUE_DEBUG 1 227 #define KUE_DEBUG 1 228 #define UDAV_DEBUG 1 229 #define UMASS_DEBUG 1 230 #define UVISOR_DEBUG 1 231 #define UPL_DEBUG 1 232 #define UZCOM_DEBUG 1 233 #define URIO_DEBUG 1 234 #define UFTDI_DEBUG 1 235 #define USCANNER_DEBUG 1 236 #define USSCANNER_DEBUG 1 237 #define UISDATA_DEBUG 1 238 #define UDSBR_DEBUG 1 239 #define UIPAQ_DEBUG 1 240 #endif 241 242 #define Static 243 244 #define UMASS_ATAPISTR "atapiscsi" 245 246 /* periph_quirks */ 247 #define PQUIRK_NOSENSE ADEV_NOSENSE /* can't REQUEST SENSE */ 248 #define PQUIRK_ONLYBIG SDEV_ONLYBIG 249 250 #define sel_klist si_note 251 252 typedef struct proc *usb_proc_ptr; 253 254 #define UCOMBUSCF_PORTNO 0 255 #define UCOMBUSCF_PORTNO_DEFAULT -1 256 #define UHIDBUSCF_REPORTID 0 257 #define UHIDBUSCF_REPORTID_DEFAULT -1 258 259 #define mstohz(ms) ((ms) * hz / 1000) 260 261 /* 262 * The UHCI/OHCI controllers are little endian, so on big endian machines 263 * the data stored in memory needs to be swapped. 264 */ 265 266 #define sel_klist si_note 267 268 #define usb_kthread_create1 kthread_create 269 #define usb_kthread_create kthread_create_deferred 270 271 typedef int usb_malloc_type; 272 273 #define Ether_ifattach(ifp, eaddr) ether_ifattach(ifp) 274 #define if_deactivate(x) 275 #define IF_INPUT(ifp, m) ether_input_mbuf((ifp), (m)) 276 277 #define logprintf printf 278 279 #define swap_bytes_change_sign16_le swap_bytes_change_sign16 280 #define change_sign16_swap_bytes_le change_sign16_swap_bytes 281 #define change_sign16_le change_sign16 282 283 #define ulinear8_to_slinear16_le ulinear8_to_linear16_le 284 #define ulinear8_to_slinear16_be ulinear8_to_linear16_be 285 #define slinear16_to_ulinear8_le linear16_to_ulinear8_le 286 #define slinear16_to_ulinear8_be linear16_to_ulinear8_be 287 288 typedef struct device *device_ptr_t; 289 #define USBBASEDEVICE struct device 290 #define USBDEV(bdev) (&(bdev)) 291 #define USBDEVNAME(bdev) ((bdev).dv_xname) 292 #define USBDEVUNIT(bdev) ((bdev).dv_unit) 293 #define USBDEVPTRNAME(bdevptr) ((bdevptr)->dv_xname) 294 #define USBGETSOFTC(d) ((void *)(d)) 295 296 #define DECLARE_USB_DMA_T \ 297 struct usb_dma_block; \ 298 typedef struct { \ 299 struct usb_dma_block *block; \ 300 u_int offs; \ 301 } usb_dma_t 302 303 typedef struct timeout usb_callout_t; 304 #define usb_callout_init(h) timeout_set(&(h), NULL, NULL) 305 #define usb_callout(h, t, f, d) \ 306 do { \ 307 timeout_del(&(h)); \ 308 timeout_set(&(h), (f), (d)); \ 309 timeout_add(&(h), (t)); \ 310 } while (0) 311 #define usb_callout_pending(h) timeout_pending(&(h)) 312 #define usb_uncallout(h, f, d) timeout_del(&(h)) 313 314 #define usb_lockmgr(l, f, sl, p) lockmgr((l), (f), (sl), (p)) 315 316 #define USB_DECLARE_DRIVER_CLASS(dname, devclass) \ 317 int __CONCAT(dname,_match)(struct device *, void *, void *); \ 318 void __CONCAT(dname,_attach)(struct device *, struct device *, void *); \ 319 int __CONCAT(dname,_detach)(struct device *, int); \ 320 int __CONCAT(dname,_activate)(struct device *, enum devact); \ 321 \ 322 struct cfdriver __CONCAT(dname,_cd) = { \ 323 NULL, #dname, devclass \ 324 }; \ 325 \ 326 const struct cfattach __CONCAT(dname,_ca) = { \ 327 sizeof(struct __CONCAT(dname,_softc)), \ 328 __CONCAT(dname,_match), \ 329 __CONCAT(dname,_attach), \ 330 __CONCAT(dname,_detach), \ 331 __CONCAT(dname,_activate), \ 332 } 333 334 #define USB_DECLARE_DRIVER(dname) USB_DECLARE_DRIVER_CLASS(dname, DV_DULL) 335 336 #define USB_MATCH(dname) \ 337 int \ 338 __CONCAT(dname,_match)(parent, match, aux) \ 339 struct device *parent; \ 340 void *match; \ 341 void *aux; 342 343 #define USB_MATCH_START(dname, uaa) \ 344 struct usb_attach_arg *uaa = aux 345 346 #define USB_ATTACH(dname) \ 347 void \ 348 __CONCAT(dname,_attach)(parent, self, aux) \ 349 struct device *parent; \ 350 struct device *self; \ 351 void *aux; 352 353 #define USB_ATTACH_START(dname, sc, uaa) \ 354 struct __CONCAT(dname,_softc) *sc = \ 355 (struct __CONCAT(dname,_softc) *)self; \ 356 struct usb_attach_arg *uaa = aux 357 358 /* Returns from attach */ 359 #define USB_ATTACH_ERROR_RETURN return 360 #define USB_ATTACH_SUCCESS_RETURN return 361 362 #define USB_ATTACH_SETUP printf("\n") 363 364 #define USB_DETACH(dname) \ 365 int \ 366 __CONCAT(dname,_detach)(self, flags) \ 367 struct device *self; \ 368 int flags; 369 370 #define USB_DETACH_START(dname, sc) \ 371 struct __CONCAT(dname,_softc) *sc = \ 372 (struct __CONCAT(dname,_softc) *)self 373 374 #define USB_GET_SC_OPEN(dname, unit, sc) \ 375 if (unit >= __CONCAT(dname,_cd).cd_ndevs) \ 376 return (ENXIO); \ 377 sc = __CONCAT(dname,_cd).cd_devs[unit]; \ 378 if (sc == NULL) \ 379 return (ENXIO) 380 381 #define USB_GET_SC(dname, unit, sc) \ 382 sc = __CONCAT(dname,_cd).cd_devs[unit] 383 384 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \ 385 (config_found_sm(parent, args, print, sub)) 386 387 #elif defined(__FreeBSD__) 388 /* 389 * FreeBSD 390 */ 391 392 #include "opt_usb.h" 393 394 #if defined(_KERNEL) 395 #include <sys/malloc.h> 396 397 MALLOC_DECLARE(M_USB); 398 MALLOC_DECLARE(M_USBDEV); 399 MALLOC_DECLARE(M_USBHC); 400 401 #endif 402 403 #define Static 404 405 #define USBVERBOSE 406 407 #define device_ptr_t device_t 408 #define USBBASEDEVICE device_t 409 #define USBDEV(bdev) (bdev) 410 #define USBDEVNAME(bdev) device_get_nameunit(bdev) 411 #define USBDEVUNIT(bdev) device_get_unit(bdev) 412 #define USBDEVPTRNAME(bdev) device_get_nameunit(bdev) 413 #define USBGETSOFTC(bdev) (device_get_softc(bdev)) 414 415 #define DECLARE_USB_DMA_T typedef void * usb_dma_t 416 417 typedef struct proc *usb_proc_ptr; 418 419 /* XXX Change this when FreeBSD has memset 420 */ 421 #define memcpy(d, s, l) bcopy((s),(d),(l)) 422 #define memset(d, v, l) bzero((d),(l)) 423 #define bswap32(x) swap32(x) 424 #define kthread_create1(f, s, p, a0, a1) \ 425 kthread_create((f), (s), (p), RFHIGHPID, (a0), (a1)) 426 427 typedef struct callout_handle usb_callout_t; 428 #define usb_callout_init(h) callout_handle_init(&(h)) 429 #define usb_callout(h, t, f, d) ((h) = timeout((f), (d), (t))) 430 #define usb_uncallout(h, f, d) uncallout((f), (d), (h)) 431 432 #define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0) 433 #define clfree(p) clist_free_cblocks((p)) 434 435 #define powerhook_establish(fn, sc) (fn) 436 #define powerhook_disestablish(hdl) 437 #define PWR_RESUME 0 438 439 #define config_detach(dev, flag) device_delete_child(device_get_parent(dev), dev) 440 441 typedef struct malloc_type *usb_malloc_type; 442 443 #define USB_DECLARE_DRIVER_INIT(dname, init) \ 444 Static device_probe_t __CONCAT(dname,_match); \ 445 Static device_attach_t __CONCAT(dname,_attach); \ 446 Static device_detach_t __CONCAT(dname,_detach); \ 447 \ 448 Static devclass_t __CONCAT(dname,_devclass); \ 449 \ 450 Static device_method_t __CONCAT(dname,_methods)[] = { \ 451 DEVMETHOD(device_probe, __CONCAT(dname,_match)), \ 452 DEVMETHOD(device_attach, __CONCAT(dname,_attach)), \ 453 DEVMETHOD(device_detach, __CONCAT(dname,_detach)), \ 454 init, \ 455 {0,0} \ 456 }; \ 457 \ 458 Static driver_t __CONCAT(dname,_driver) = { \ 459 #dname, \ 460 __CONCAT(dname,_methods), \ 461 sizeof(struct __CONCAT(dname,_softc)) \ 462 } 463 #define METHODS_NONE {0,0} 464 #define USB_DECLARE_DRIVER(dname) USB_DECLARE_DRIVER_INIT(dname, METHODS_NONE) 465 466 467 #define USB_MATCH(dname) \ 468 Static int \ 469 __CONCAT(dname,_match)(device_t self) 470 471 #define USB_MATCH_START(dname, uaa) \ 472 struct usb_attach_arg *uaa = device_get_ivars(self) 473 474 #define USB_ATTACH(dname) \ 475 Static int \ 476 __CONCAT(dname,_attach)(device_t self) 477 478 #define USB_ATTACH_START(dname, sc, uaa) \ 479 struct __CONCAT(dname,_softc) *sc = device_get_softc(self); \ 480 struct usb_attach_arg *uaa = device_get_ivars(self) 481 482 /* Returns from attach */ 483 #define USB_ATTACH_ERROR_RETURN return ENXIO 484 #define USB_ATTACH_SUCCESS_RETURN return 0 485 486 #define USB_ATTACH_SETUP \ 487 sc->sc_dev = self; \ 488 device_set_desc_copy(self, devinfo) 489 490 #define USB_DETACH(dname) \ 491 Static int \ 492 __CONCAT(dname,_detach)(device_t self) 493 494 #define USB_DETACH_START(dname, sc) \ 495 struct __CONCAT(dname,_softc) *sc = device_get_softc(self) 496 497 #define USB_GET_SC_OPEN(dname, unit, sc) \ 498 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit); \ 499 if (sc == NULL) \ 500 return (ENXIO) 501 502 #define USB_GET_SC(dname, unit, sc) \ 503 sc = devclass_get_softc(__CONCAT(dname,_devclass), unit) 504 505 #define USB_DO_ATTACH(dev, bdev, parent, args, print, sub) \ 506 (device_probe_and_attach((bdev)) == 0 ? (bdev) : 0) 507 508 /* conversion from one type of queue to the other */ 509 #define SIMPLEQ_REMOVE_HEAD STAILQ_REMOVE_HEAD 510 #define SIMPLEQ_INSERT_HEAD STAILQ_INSERT_HEAD 511 #define SIMPLEQ_INSERT_TAIL STAILQ_INSERT_TAIL 512 #define SIMPLEQ_NEXT STAILQ_NEXT 513 #define SIMPLEQ_FIRST STAILQ_FIRST 514 #define SIMPLEQ_HEAD STAILQ_HEAD 515 #define SIMPLEQ_INIT STAILQ_INIT 516 #define SIMPLEQ_HEAD_INITIALIZER STAILQ_HEAD_INITIALIZER 517 #define SIMPLEQ_ENTRY STAILQ_ENTRY 518 519 #include <sys/syslog.h> 520 /* 521 #define logprintf(args...) log(LOG_DEBUG, args) 522 */ 523 #define logprintf printf 524 525 #endif /* __FreeBSD__ */ 526 527 #endif /* _USB_PORT_H */ 528