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