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