1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SSERVICE_H 27 #define _SSERVICE_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 typedef int(f_tt)(int, ...); /* for lint - cc -v quieting */ 36 37 /* 38 * identifiers for all SS functions implemented 39 */ 40 #define SS_GetAdapter 0 41 #define SS_GetPage 1 42 #define SS_GetSocket 2 43 #define SS_GetStatus 3 44 #define SS_GetWindow 4 45 #define SS_InquireAdapter 5 46 #define SS_InquireSocket 6 47 #define SS_InquireWindow 7 48 #define SS_ResetSocket 8 49 #define SS_SetPage 9 50 #define SS_SetAdapter 10 51 #define SS_SetSocket 11 52 #define SS_SetWindow 12 53 #define SS_SetIRQHandler 13 54 #define SS_ClearIRQHandler 14 55 #define CSGetActiveDip 98 56 #define CSInitDev 99 57 #define CSRegister 100 58 #define CSCISInit 101 59 #define CSUnregister 102 60 61 /* 62 * XXX 63 */ 64 #define CISGetAddress 103 65 #define CISSetAddress 104 66 #define CSCardRemoved 105 67 #define CSGetCookiesAndDip 106 68 69 /* 70 * returns a la Socket Services 71 */ 72 73 #define SUCCESS 0x00 74 #define BAD_ADAPTER 0x01 75 #define BAD_ATTRIBUTE 0x02 76 #define BAD_BASE 0x03 77 #define BAD_EDC 0x04 78 #define BAD_IRQ 0x06 79 #define BAD_OFFSET 0x07 80 #define BAD_PAGE 0x08 81 #define READ_FAILURE 0x09 82 #define BAD_SIZE 0x0a 83 #define BAD_SOCKET 0x0b 84 #define BAD_TYPE 0x0d 85 #define BAD_VCC 0x0e 86 #define BAD_VPP 0x0f 87 #define BAD_WINDOW 0x11 88 #define WRITE_FAILURE 0x12 89 #define NO_CARD 0x14 90 #define BAD_FUNCTION 0x15 91 #define BAD_MODE 0x16 92 #define BAD_SPEED 0x17 93 #define BUSY 0x18 94 #define NO_RESOURCE 0x20 95 96 /* events for callback */ 97 /* card related events */ 98 #define PCE_CARD_REMOVAL 0 /* card removed */ 99 #define PCE_CARD_INSERT 1 /* card inserted */ 100 #define PCE_CARD_READY 2 /* ready state changed */ 101 #define PCE_CARD_BATTERY_WARN 3 /* battery is getting low */ 102 #define PCE_CARD_BATTERY_DEAD 4 /* battery is dead */ 103 #define PCE_CARD_STATUS_CHANGE 5 /* card status change for I/O card */ 104 #define PCE_CARD_WRITE_PROTECT 6 /* card write protect status change */ 105 #define PCE_CARD_RESET 7 /* client requested reset complete */ 106 #define PCE_CARD_UNLOCK 8 /* lock has been unlocked (opt) */ 107 #define PCE_CLIENT_INFO 9 /* someone wants client information */ 108 #define PCE_EJECTION_COMPLETE 10 /* Motor has finished ejecting card */ 109 #define PCE_EJECTION_REQUEST 11 /* request to eject card */ 110 #define PCE_ERASE_COMPLETE 12 /* a Flash Erase request completed */ 111 #define PCE_EXCLUSIVE_COMPLETE 13 112 #define PCE_EXCLUSIVE_REQUEST 14 113 #define PCE_INSERTION_COMPLETE 15 114 #define PCE_INSERTION_REQUEST 16 115 #define PCE_REGISTRATION_COMPLETE 17 116 #define PCE_RESET_COMPLETE 18 117 #define PCE_RESET_PHYSICAL 19 118 #define PCE_RESET_REQUEST 20 119 #define PCE_TIMER_EXPIRED 21 120 121 /* added for SPARC CPR support */ 122 #define PCE_PM_RESUME 22 123 #define PCE_PM_SUSPEND 23 124 125 /* added for dynamic nexus registration */ 126 #define PCE_SS_INIT_STATE 24 /* SS init state */ 127 #define PCE_ADD_SOCKET 25 /* add a new socket */ 128 #define PCE_DROP_SOCKET 26 /* drop an existing socket */ 129 130 #define PCE_DEV_IDENT 30 /* The nexus has identified the device */ 131 #define PCE_INIT_DEV 31 /* asking for a device */ 132 133 #define PCE_E2M(event) (1 << (event)) 134 135 /* event callback uses an indirect call -- make it look like a function */ 136 #define CS_EVENT(event, socket, arg) (*pcmcia_cs_event) (event, socket, arg) 137 138 /* values for "socket number" field for PCE_SS_INIT_STATE event */ 139 #define PCE_SS_STATE_INIT 0x0001 /* SS ready for callbacks */ 140 #define PCE_SS_STATE_DEINIT 0x0002 /* SS not ready for callbacks */ 141 142 /* 143 * The following structure is to support CSRegister 144 */ 145 typedef struct csregister { 146 uint32_t cs_magic; /* magic number */ 147 uint32_t cs_version; /* CS version number */ 148 /* CS entry point */ 149 int (*cs_card_services)(int, ...); 150 /* CS event entry point */ 151 f_tt *cs_event; 152 } csregister_t; 153 154 /* GetAdapter(get_adapter_t) */ 155 156 typedef struct get_adapter { 157 unsigned state; /* adapter hardware state */ 158 irq_t SCRouting; /* status change IRQ routing */ 159 } get_adapter_t; 160 161 /* IRQ definitions */ 162 #define IRQ_ENABLE 0x8000 163 164 /* GetPage(get_page_t) */ 165 166 typedef struct get_page { 167 unsigned window; /* window number */ 168 unsigned page; /* page number within window */ 169 unsigned state; /* page state: */ 170 /* 171 * PS_ATTRIBUTE 172 * PS_COMMON 173 * PS_IO (for DoRight?) 174 * PS_ENABLED 175 * PS_WP 176 */ 177 off_t offset; /* PC card's memory offset */ 178 } get_page_t; 179 180 /* 181 * PS flags 182 */ 183 184 #define PS_ATTRIBUTE 0x01 185 #define PS_ENABLED 0x02 186 #define PS_WP 0x04 187 #define PS_IO 0x08 /* needed? for DoRight */ 188 189 /* GetSocket(get_socket_t) */ 190 191 typedef struct get_socket { 192 unsigned socket; /* socket number */ 193 unsigned SCIntMask; /* status change interrupt mask */ 194 unsigned VccLevel; /* VCC voltage in 1/10 volt */ 195 unsigned Vpp1Level; /* VPP1 voltage in 1/10 volt */ 196 unsigned Vpp2Level; /* VPP2 voltage in 1/10 volt */ 197 unsigned state; /* latched status change signals */ 198 unsigned CtlInd; /* controls and indicators */ 199 irq_t IRQRouting; /* I/O IRQ routing */ 200 unsigned IFType; /* memory-only or memory & I/O */ 201 } get_socket_t; 202 203 /* GetStatus(get_ss_status_t) */ 204 205 typedef struct get_ss_status { 206 unsigned socket; /* socket number */ 207 unsigned CardState; /* real-time card state */ 208 unsigned SocketState; /* latched status change signals */ 209 unsigned CtlInd; /* controls and indicators */ 210 irq_t IRQRouting; /* I/O IRQ routing */ 211 unsigned IFType; /* memory-only or memory & I/O */ 212 } get_ss_status_t; 213 214 /* 215 * Socket specific flags and capabilities 216 */ 217 218 #define SBM_WP 0x01 219 #define SBM_LOCKED 0x02 220 #define SBM_EJECT 0x04 221 #define SBM_INSERT 0x08 222 #define SBM_BVD1 0x10 223 #define SBM_BVD2 0x20 224 #define SBM_RDYBSY 0x40 225 #define SBM_CD 0x80 226 227 /* capabilities only */ 228 #define SBM_LOCK 0x10 229 #define SBM_BATT 0x20 230 #define SBM_BUSY 0x40 231 #define SBM_XID 0x80 232 233 /* GetWindow(get_window_t) */ 234 typedef uint32_t speed_t; /* memory speed in nanoseconds */ 235 236 typedef struct get_window { 237 unsigned window; /* window number */ 238 unsigned socket; /* socket this window is assigned to */ 239 unsigned size; /* size in bytes */ 240 unsigned state; /* current state of window hardware */ 241 uint_t speed; /* speed in nanoseconds */ 242 uint_t base; 243 ddi_acc_handle_t handle; /* base addr in host space */ 244 } get_window_t; 245 246 /* 247 * window flags (state and capabilities) 248 */ 249 #define WS_IO 0x01 250 #define WS_ENABLED 0x02 251 #define WS_16BIT 0x04 252 #define WS_PAGED 0x80 253 #define WS_EISA 0x10 254 #define WS_CENABLE 0x20 255 #define WS_EXACT_MAPIN 0x40 /* map exactly what's asked for */ 256 257 /* Inquire Adapter(inquire_adapter_t) */ 258 259 typedef struct inquire_adapter { 260 unsigned NumSockets; /* number of sockets */ 261 unsigned NumWindows; /* number of windows */ 262 unsigned NumEDCs; /* number of EDCs */ 263 264 unsigned AdpCaps; /* adapter power capabilities */ 265 irq_t ActiveHigh; /* active high status change IRQ */ 266 irq_t ActiveLow; /* active low status change IRQ */ 267 int NumPower; /* number of power entries */ 268 struct power_entry { 269 unsigned PowerLevel; /* voltage in 1/10 volt */ 270 unsigned ValidSignals; /* voltage is valid for: */ 271 /* 272 * VCC 273 * VPP1 274 * VPP2 275 * if none are set, this is end 276 * of list 277 */ 278 } *power_entry; 279 int NumInterrupts; /* number of interrupts supportable */ 280 struct intr_entry { 281 int pri; 282 int intr; 283 } *AvailInterrupts; /* array of intrs, one per intr */ 284 uint_t ResourceFlags; /* resource allocation requirements */ 285 } inquire_adapter_t; 286 287 #define VCC 0x80 288 #define VPP1 0x40 289 #define VPP2 0x20 290 #define V_MASK (VCC|VPP1|VPP2) 291 292 #define RES_OWN_IRQ 0x0001 /* adapter owns own IRQ resources */ 293 #define RES_OWN_IO 0x0002 /* adapter owns own I/O resources */ 294 #define RES_OWN_MEM 0x0004 /* adapter owns own memory resources */ 295 #define RES_IRQ_NEXUS 0x0008 /* adapter/nexus must multiplex IRQs */ 296 #define RES_IRQ_SHAREABLE 0x0010 /* IRQ can be shared */ 297 298 /* InquireSocket(inquire_socket_t) */ 299 300 typedef struct inquire_socket { 301 unsigned socket; /* socket number */ 302 unsigned SCIntCaps; /* status change interrupt events */ 303 unsigned SCRptCaps; /* reportable status change events */ 304 unsigned CtlIndCaps; /* controls and indicators */ 305 unsigned SocketCaps; /* socket capabilities */ 306 irq_t ActiveHigh; /* active high status change IRQ */ 307 irq_t ActiveLow; /* active low status change IRQ */ 308 } inquire_socket_t; 309 310 /* InquireWindow(inquire_window_t) */ 311 312 typedef struct memwin_char { 313 unsigned MemWndCaps; /* memory window characteristcs */ 314 baseaddr_t FirstByte; /* first byte in host space */ 315 baseaddr_t LastByte; /* last byte in host space */ 316 unsigned MinSize; /* minimum window size */ 317 unsigned MaxSize; /* maximum window size */ 318 unsigned ReqGran; /* window size constraints */ 319 unsigned ReqBase; /* base address alignment boundry */ 320 unsigned ReqOffset; /* offset alignment boundry */ 321 unsigned Slowest; /* slowest speed in nanoseconds */ 322 unsigned Fastest; /* fastest speed in nanoseconds */ 323 } mem_win_char_t; 324 325 typedef struct iowin_char { 326 unsigned IOWndCaps; /* I/O window characteristcs */ 327 baseaddr_t FirstByte; /* first byte in host space */ 328 baseaddr_t LastByte; /* last byte in host space */ 329 unsigned MinSize; /* minimum window size */ 330 unsigned MaxSize; /* maximum window size */ 331 unsigned ReqGran; /* window size constraints */ 332 unsigned AddrLines; /* number of address lines decoded */ 333 unsigned EISASlot; /* EISA I/O address decoding */ 334 } iowin_char_t; 335 336 typedef struct inquire_window { 337 unsigned window; /* window number */ 338 unsigned WndCaps; /* window capabilities */ 339 socket_enum_t Sockets; /* window<->socket assignment mask */ 340 /* note that we always declare both forms */ 341 mem_win_char_t mem_win_char; 342 iowin_char_t iowin_char; 343 } inquire_window_t; 344 345 346 /* interface definitions */ 347 #define IF_CARDBUS 0x00 /* CardBus interface */ 348 #define IF_IO 0x01 /* IO + memory */ 349 #define IF_MEMORY 0x02 /* memory only */ 350 #define IF_TYPE_MASK 0x03 351 352 #define DREQ_MASK 0x0c 353 #define DREQ_NONE 0x00 354 #define DREQ_SPKR 0x04 355 #define DREQ_IOIS16 0x08 356 #define DREQ_INPACK 0x0c 357 358 #define DMA_CHAN_MASK 0xf0 359 #define DMA_GET_CHAN(x) (((x) >> 4) & 0xF) 360 #define DMA_SET_CHAN(x, y) (((x) & 0xF) | ((y) & ~DMA_CHAN_MASK)) 361 362 #define IF_CB 0x04 363 #define IF_DMA 0x08 364 #define IF_VSKEY 0x10 365 #define IF_33VC 0x20 366 #define IF_XXVCC 0x40 367 368 369 #define PC_PAGESIZE 0x4000 /* 16K page size */ 370 371 /* window capabilities */ 372 /* generic */ 373 #define WC_IO 0x0004 374 #define WC_WAIT 0x0080 375 #define WC_COMMON 0x0001 376 #define WC_ATTRIBUTE 0x0002 377 /* I/O and memory */ 378 #define WC_BASE 0x0001 379 #define WC_SIZE 0x0002 380 #define WC_WENABLE 0x0004 381 #define WC_8BIT 0x0008 382 #define WC_16BIT 0x0010 383 #define WC_BALIGN 0x0020 384 #define WC_POW2 0x0040 385 /* memory only */ 386 #define WC_CALIGN 0x0080 387 #define WC_PAVAIL 0x0100 388 #define WC_PSHARED 0x0200 389 #define WC_PENABLE 0x0400 390 #define WC_WP 0x0800 391 /* I/O only */ 392 #define WC_INPACK 0x0080 393 #define WC_EISA 0x0100 394 #define WC_CENABLE 0x0200 395 /* Solaris/SPARC */ 396 #define WC_IO_RANGE_PER_WINDOW 0x8000 /* I/O range unique for each window */ 397 398 /* SetPage(set_page_t *) */ 399 typedef struct set_page { 400 unsigned window; /* window number */ 401 unsigned page; /* page number */ 402 unsigned state; /* page state */ 403 off_t offset; /* offset in PC card space */ 404 } set_page_t; 405 406 /* SetSocket(set_socket_t) */ 407 408 typedef struct set_socket { 409 unsigned socket; /* socket number */ 410 unsigned SCIntMask; /* status change enables */ 411 unsigned Vcontrol; /* power control flags */ 412 unsigned VccLevel; /* Vcc power index level */ 413 unsigned Vpp1Level; /* Vpp1 power index level */ 414 unsigned Vpp2Level; /* Vpp2 power index level */ 415 unsigned State; 416 unsigned CtlInd; /* control and indicator bits */ 417 irq_t IREQRouting; /* I/O IRQ routing */ 418 unsigned IFType; /* interface type (mem/IO) */ 419 } set_socket_t; 420 421 #define VCTL_CISREAD 0x01 /* controlled by Vcc/Vpp sense pins */ 422 #define VCTL_OVERRIDE 0x02 /* 16-bit cards, ignore the sense pins */ 423 424 /* SetIRQHandler(set_irq_handler_t) */ 425 426 typedef struct set_irq_handler { 427 unsigned socket; /* associate with a socket for now */ 428 unsigned irq; 429 unsigned handler_id; /* ID of this client's handler */ 430 f_tt *handler; /* client IO IRQ handler entry point */ 431 void *arg1; /* arg to call client handler with */ 432 void *arg2; /* arg to call client handler with */ 433 ddi_iblock_cookie_t *iblk_cookie; /* iblk cookie pointer */ 434 ddi_idevice_cookie_t *idev_cookie; /* idev cookie pointer */ 435 } set_irq_handler_t; 436 437 #define IRQ_ANY 0x0 438 439 /* interrupt priority levels */ 440 #define PRIORITY_LOW 0x00 441 #define PRIORITY_HIGH 0x10 442 443 /* ClearIRQHandler(clear_irq_handler_t) */ 444 445 typedef struct clear_irq_handler { 446 unsigned socket; 447 unsigned handler_id; /* client handler ID to remove */ 448 f_tt *handler; /* client IO IRQ handler entry point */ 449 } clear_irq_handler_t; 450 451 /* SetWindow(set_window_t) */ 452 453 typedef struct set_window { 454 unsigned window; /* window number */ 455 unsigned socket; /* socket number */ 456 unsigned WindowSize; /* window size in bytes */ 457 unsigned state; /* window state */ 458 unsigned speed; /* window speed, nanoseconds */ 459 uint_t base; 460 ddi_acc_handle_t handle; /* base addr in host space */ 461 dev_info_t *child; /* child's dip */ 462 ddi_device_acc_attr_t attr; 463 } set_window_t; 464 465 /* CSInitDev */ 466 typedef 467 struct ss_make_device_node { 468 uint32_t flags; /* operation flags */ 469 dev_info_t *dip; /* dip for this client */ 470 char *name; /* device node path and name */ 471 char *slot; /* slot name string */ 472 char *busaddr; /* bus addr name string */ 473 int spec_type; /* dev special type (block/char) */ 474 int minor_num; /* device node minor number */ 475 char *node_type; /* device node type */ 476 } ss_make_device_node_t; 477 478 #define SS_CSINITDEV_CREATE_DEVICE 0x01 /* create device node */ 479 #define SS_CSINITDEV_REMOVE_DEVICE 0x02 /* remove device node */ 480 #define SS_CSINITDEV_USE_SLOT 0x04 /* use slot name from caller */ 481 #define SS_CSINITDEV_USE_BUSADDR 0x08 /* use bus addr from caller */ 482 #define SS_CSINITDEV_MORE_DEVICES 0x10 /* send PCE_INIT_DEV */ 483 #define SS_CSINITDEV_SEND_DEV_EVENT 0x10 /* send PCE_INIT_DEV */ 484 485 /* 486 * csss_adapter_info_t - provides additional per-socket adapter info 487 */ 488 typedef struct csss_adapter_info_t { 489 char name[MODMAXNAMELEN]; /* adapter name */ 490 int major; /* adapter major number */ 491 int minor; /* adapter minor number */ 492 int number; /* canonical adapter number */ 493 int num_sockets; /* # sockets on this adapter */ 494 int first_socket; /* first socket # on this adapter */ 495 } csss_adapter_info_t; 496 497 /* CSGetCookiesAndDip */ 498 typedef struct get_cookies_and_dip_t { 499 unsigned socket; /* socket number */ 500 dev_info_t *dip; /* adapter instance dip */ 501 ddi_iblock_cookie_t *iblock; /* for event handler */ 502 ddi_idevice_cookie_t *idevice; /* for event handler */ 503 csss_adapter_info_t adapter_info; /* adapter info for socket */ 504 } get_cookies_and_dip_t; 505 506 /* ResetSocket */ 507 #define RESET_MODE_FULL 0 /* Reset to SocketServices Specification */ 508 #define RESET_MODE_CARD_ONLY 1 /* only reset the card itself */ 509 510 /* union of all exported functions functions */ 511 typedef 512 union sservice { 513 get_adapter_t get_adapter; 514 get_page_t get_page; 515 get_socket_t get_socket; 516 get_window_t get_window; 517 get_ss_status_t get_ss_status; 518 inquire_adapter_t inquire_adapter; 519 inquire_socket_t inquire_socket; 520 inquire_window_t inquire_window; 521 set_page_t set_page; 522 set_socket_t set_socket; 523 set_irq_handler_t set_irq_handler; 524 set_window_t set_window; 525 get_cookies_and_dip_t get_cookies; 526 ss_make_device_node_t make_device; 527 } sservice_t; 528 529 /* event manager structures */ 530 struct pcm_make_dev { 531 int socket; 532 int flags; 533 int op; 534 dev_t dev; 535 int type; 536 char driver[MODMAXNAMELEN]; 537 char path[MAXPATHLEN]; 538 }; 539 540 #define PCM_EVENT_MORE 0x0001 /* more events of this type coming */ 541 542 #ifdef _KERNEL 543 544 #include <sys/sunndi.h> 545 546 /* 547 * prototypes for nexi 548 */ 549 550 int pcmcia_attach(dev_info_t *, struct pcmcia_adapter_nexus_private *); 551 int pcmcia_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); 552 int pcmcia_prop_op(dev_t, dev_info_t *, dev_info_t *, ddi_prop_op_t, 553 int, char *, caddr_t, int *); 554 int pcmcia_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 555 ddi_intr_handle_impl_t *hdlp, void *result); 556 557 int pcmcia_open(dev_t *, int, int, cred_t *); 558 int pcmcia_close(dev_t, int, int, cred_t *); 559 int pcmcia_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 560 int pcmcia_power(dev_info_t *, int, int); 561 void pcmcia_begin_resume(dev_info_t *); 562 void pcmcia_wait_insert(dev_info_t *); 563 564 565 /* resource allocation functions and structure */ 566 typedef struct ra_return { 567 uint_t ra_addr_hi; 568 uint_t ra_addr_lo; 569 uint_t ra_len; 570 } ra_return_t; 571 572 int pcmcia_alloc_mem(dev_info_t *, ndi_ra_request_t *, ra_return_t *, 573 dev_info_t **); 574 int pcmcia_alloc_io(dev_info_t *, ndi_ra_request_t *, ra_return_t *, 575 dev_info_t **); 576 int pcmcia_free_mem(dev_info_t *, ra_return_t *); 577 int pcmcia_free_io(dev_info_t *, ra_return_t *); 578 int pcmcia_map_reg(dev_info_t *, dev_info_t *, ra_return_t *, 579 uint32_t, caddr_t *, ddi_acc_handle_t *, 580 ddi_device_acc_attr_t *, uint32_t); 581 int pcmcia_bus_map(dev_info_t *, dev_info_t *, ddi_map_req_t *, 582 off_t, off_t, caddr_t *); 583 584 #endif /* _KERNEL */ 585 586 #ifdef __cplusplus 587 } 588 #endif 589 590 #endif /* _SSERVICE_H */ 591