Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/pcic.c
+++ new/usr/src/uts/common/io/pcic.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * PCIC device/interrupt handler
29 29 * The "pcic" driver handles the Intel 82365SL, Cirrus Logic
30 30 * and Toshiba (and possibly other clones) PCMCIA adapter chip
31 31 * sets. It implements a subset of Socket Services as defined
32 32 * in the Solaris PCMCIA design documents
33 33 */
34 34
35 35 /*
36 36 * currently defined "properties"
37 37 *
38 38 * clock-frequency bus clock frequency
39 39 * smi system management interrupt override
40 40 * need-mult-irq need status IRQ for each pair of sockets
41 41 * disable-audio don't route audio signal to speaker
42 42 */
43 43
44 44
45 45 #include <sys/types.h>
46 46 #include <sys/inttypes.h>
47 47 #include <sys/param.h>
48 48 #include <sys/systm.h>
49 49 #include <sys/user.h>
50 50 #include <sys/buf.h>
51 51 #include <sys/file.h>
52 52 #include <sys/uio.h>
53 53 #include <sys/conf.h>
54 54 #include <sys/stat.h>
55 55 #include <sys/autoconf.h>
56 56 #include <sys/vtoc.h>
57 57 #include <sys/dkio.h>
58 58 #include <sys/ddi.h>
59 59 #include <sys/sunddi.h>
60 60 #include <sys/sunndi.h>
61 61 #include <sys/var.h>
62 62 #include <sys/callb.h>
63 63 #include <sys/open.h>
64 64 #include <sys/ddidmareq.h>
65 65 #include <sys/dma_engine.h>
66 66 #include <sys/kstat.h>
67 67 #include <sys/kmem.h>
68 68 #include <sys/modctl.h>
69 69 #include <sys/pci.h>
70 70 #include <sys/pci_impl.h>
71 71
72 72 #include <sys/pctypes.h>
73 73 #include <sys/pcmcia.h>
74 74 #include <sys/sservice.h>
75 75
76 76 #include <sys/note.h>
77 77
78 78 #include <sys/pcic_reg.h>
79 79 #include <sys/pcic_var.h>
80 80
81 81 #if defined(__i386) || defined(__amd64)
82 82 #include <sys/pci_cfgspace.h>
83 83 #endif
84 84
85 85 #if defined(__sparc)
86 86 #include <sys/pci/pci_nexus.h>
87 87 #endif
88 88
89 89 #include <sys/hotplug/hpcsvc.h>
90 90 #include "cardbus/cardbus.h"
91 91
92 92 #define SOFTC_SIZE (sizeof (anp_t))
93 93
94 94 static int pcic_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
95 95 static int pcic_attach(dev_info_t *, ddi_attach_cmd_t);
96 96 static int pcic_detach(dev_info_t *, ddi_detach_cmd_t);
97 97 static int32_t pcic_quiesce(dev_info_t *);
98 98 static uint_t pcic_intr(caddr_t, caddr_t);
99 99 static int pcic_do_io_intr(pcicdev_t *, uint32_t);
100 100 static int pcic_probe(dev_info_t *);
101 101
102 102 static int pcic_open(dev_t *, int, int, cred_t *);
103 103 static int pcic_close(dev_t, int, int, cred_t *);
104 104 static int pcic_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
105 105
106 106 typedef struct pcm_regs pcm_regs_t;
107 107
108 108 static void pcic_init_assigned(dev_info_t *);
109 109 static int pcic_apply_avail_ranges(dev_info_t *, pcm_regs_t *,
110 110 pci_regspec_t *, int);
111 111 int pci_resource_setup_avail(dev_info_t *, pci_regspec_t *, int);
112 112
113 113 /*
114 114 * On x86 platforms the ddi_iobp_alloc(9F) and ddi_mem_alloc(9F) calls
115 115 * are xlated into DMA ctlops. To make this nexus work on x86, we
116 116 * need to have the default ddi_dma_mctl ctlops in the bus_ops
117 117 * structure, just to pass the request to the parent. The correct
118 118 * ctlops should be ddi_no_dma_mctl because so far we don't do DMA.
119 119 */
120 120 static
121 121 struct bus_ops pcmciabus_ops = {
122 122 BUSO_REV,
123 123 pcmcia_bus_map,
124 124 NULL,
125 125 NULL,
126 126 NULL,
127 127 i_ddi_map_fault,
128 128 ddi_no_dma_map,
129 129 ddi_no_dma_allochdl,
130 130 ddi_no_dma_freehdl,
131 131 ddi_no_dma_bindhdl,
132 132 ddi_no_dma_unbindhdl,
133 133 ddi_no_dma_flush,
134 134 ddi_no_dma_win,
135 135 ddi_dma_mctl,
136 136 pcmcia_ctlops,
137 137 pcmcia_prop_op,
138 138 NULL, /* (*bus_get_eventcookie)(); */
139 139 NULL, /* (*bus_add_eventcall)(); */
140 140 NULL, /* (*bus_remove_eventcall)(); */
141 141 NULL, /* (*bus_post_event)(); */
142 142 NULL, /* (*bus_intr_ctl)(); */
143 143 NULL, /* (*bus_config)(); */
144 144 NULL, /* (*bus_unconfig)(); */
145 145 NULL, /* (*bus_fm_init)(); */
146 146 NULL, /* (*bus_fm_fini)(); */
147 147 NULL, /* (*bus_enter)() */
148 148 NULL, /* (*bus_exit)() */
149 149 NULL, /* (*bus_power)() */
150 150 pcmcia_intr_ops /* (*bus_intr_op)(); */
151 151 };
152 152
153 153 static struct cb_ops pcic_cbops = {
154 154 pcic_open,
155 155 pcic_close,
156 156 nodev,
157 157 nodev,
158 158 nodev,
159 159 nodev,
160 160 nodev,
161 161 pcic_ioctl,
162 162 nodev,
163 163 nodev,
164 164 nodev,
165 165 nochpoll,
166 166 ddi_prop_op,
167 167 NULL,
168 168 #ifdef CARDBUS
169 169 D_NEW | D_MP | D_HOTPLUG
170 170 #else
171 171 D_NEW | D_MP
172 172 #endif
173 173 };
174 174
175 175 static struct dev_ops pcic_devops = {
176 176 DEVO_REV,
177 177 0,
178 178 pcic_getinfo,
179 179 nulldev,
180 180 pcic_probe,
181 181 pcic_attach,
182 182 pcic_detach,
183 183 nulldev,
184 184 &pcic_cbops,
185 185 &pcmciabus_ops,
186 186 NULL,
187 187 pcic_quiesce, /* devo_quiesce */
188 188 };
189 189
190 190 void *pcic_soft_state_p = NULL;
191 191 static int pcic_maxinst = -1;
192 192
193 193 int pcic_do_insertion = 1;
194 194 int pcic_do_removal = 1;
195 195
196 196 struct irqmap {
197 197 int irq;
198 198 int count;
199 199 } pcic_irq_map[16];
200 200
201 201
202 202 int pcic_debug = 0x0;
203 203 static void pcic_err(dev_info_t *dip, int level, const char *fmt, ...);
204 204 extern void cardbus_dump_pci_config(dev_info_t *dip);
205 205 extern void cardbus_dump_socket(dev_info_t *dip);
206 206 extern int cardbus_validate_iline(dev_info_t *dip, ddi_acc_handle_t handle);
207 207 static void pcic_dump_debqueue(char *msg);
208 208
209 209 #if defined(PCIC_DEBUG)
210 210 static void xxdmp_all_regs(pcicdev_t *, int, uint32_t);
211 211
212 212 #define pcic_mutex_enter(a) \
213 213 { \
214 214 pcic_err(NULL, 10, "Set lock at %d\n", __LINE__); \
215 215 mutex_enter(a); \
216 216 };
217 217
218 218 #define pcic_mutex_exit(a) \
219 219 { \
220 220 pcic_err(NULL, 10, "Clear lock at %d\n", __LINE__); \
221 221 mutex_exit(a); \
222 222 };
223 223
224 224 #else
225 225 #define pcic_mutex_enter(a) mutex_enter(a)
226 226 #define pcic_mutex_exit(a) mutex_exit(a)
227 227 #endif
228 228
229 229 #define PCIC_VCC_3VLEVEL 1
230 230 #define PCIC_VCC_5VLEVEL 2
231 231 #define PCIC_VCC_12LEVEL 3
232 232
233 233 /* bit patterns to select voltage levels */
234 234 int pcic_vpp_levels[13] = {
235 235 0, 0, 0,
236 236 1, /* 3.3V */
237 237 0,
238 238 1, /* 5V */
239 239 0, 0, 0, 0, 0, 0,
240 240 2 /* 12V */
241 241 };
242 242
243 243 uint8_t pcic_cbv_levels[13] = {
244 244 0, 0, 0,
245 245 3, /* 3.3V */
246 246 0,
247 247 2, /* 5V */
248 248 0, 0, 0, 0, 0, 0,
249 249 1 /* 12V */
250 250 };
251 251
252 252 struct power_entry pcic_power[4] = {
253 253 {
254 254 0, VCC|VPP1|VPP2
255 255 },
256 256 {
257 257 33, /* 3.3Volt */
258 258 VCC|VPP1|VPP2
259 259 },
260 260 {
261 261 5*10, /* 5Volt */
262 262 VCC|VPP1|VPP2 /* currently only know about this */
263 263 },
264 264 {
265 265 12*10, /* 12Volt */
266 266 VPP1|VPP2
267 267 }
268 268 };
269 269
270 270 /*
271 271 * Base used to allocate ranges of PCI memory on x86 systems
272 272 * Each instance gets a chunk above the base that is used to map
273 273 * in the memory and I/O windows for that device.
274 274 * Pages below the base are also allocated for the EXCA registers,
275 275 * one per instance.
276 276 */
277 277 #define PCIC_PCI_MEMCHUNK 0x1000000
278 278
279 279 static int pcic_wait_insert_time = 5000000; /* In micro-seconds */
280 280 static int pcic_debounce_time = 200000; /* In micro-seconds */
281 281
282 282 struct debounce {
283 283 pcic_socket_t *pcs;
284 284 clock_t expire;
285 285 struct debounce *next;
286 286 };
287 287
288 288 static struct debounce *pcic_deb_queue = NULL;
289 289 static kmutex_t pcic_deb_mtx;
290 290 static kcondvar_t pcic_deb_cv;
291 291 static kthread_t *pcic_deb_threadid;
292 292
293 293 static inthandler_t *pcic_handlers;
294 294
295 295 static void pcic_setup_adapter(pcicdev_t *);
296 296 static int pcic_change(pcicdev_t *, int);
297 297 static int pcic_ll_reset(pcicdev_t *, int);
298 298 static void pcic_mswait(pcicdev_t *, int, int);
299 299 static boolean_t pcic_check_ready(pcicdev_t *, int);
300 300 static void pcic_set_cdtimers(pcicdev_t *, int, uint32_t, int);
301 301 static void pcic_ready_wait(pcicdev_t *, int);
302 302 extern int pcmcia_get_intr(dev_info_t *, int);
303 303 extern int pcmcia_return_intr(dev_info_t *, int);
304 304 extern void pcmcia_cb_suspended(int);
305 305 extern void pcmcia_cb_resumed(int);
306 306
307 307 static int pcic_callback(dev_info_t *, int (*)(), int);
308 308 static int pcic_inquire_adapter(dev_info_t *, inquire_adapter_t *);
309 309 static int pcic_get_adapter(dev_info_t *, get_adapter_t *);
310 310 static int pcic_get_page(dev_info_t *, get_page_t *);
311 311 static int pcic_get_socket(dev_info_t *, get_socket_t *);
312 312 static int pcic_get_status(dev_info_t *, get_ss_status_t *);
313 313 static int pcic_get_window(dev_info_t *, get_window_t *);
314 314 static int pcic_inquire_socket(dev_info_t *, inquire_socket_t *);
315 315 static int pcic_inquire_window(dev_info_t *, inquire_window_t *);
316 316 static int pcic_reset_socket(dev_info_t *, int, int);
317 317 static int pcic_set_page(dev_info_t *, set_page_t *);
318 318 static int pcic_set_window(dev_info_t *, set_window_t *);
319 319 static int pcic_set_socket(dev_info_t *, set_socket_t *);
320 320 static int pcic_set_interrupt(dev_info_t *, set_irq_handler_t *);
321 321 static int pcic_clear_interrupt(dev_info_t *, clear_irq_handler_t *);
322 322 static void pcic_pm_detection(void *);
323 323 static void pcic_iomem_pci_ctl(ddi_acc_handle_t, uchar_t *, unsigned);
324 324 static int clext_reg_read(pcicdev_t *, int, uchar_t);
325 325 static void clext_reg_write(pcicdev_t *, int, uchar_t, uchar_t);
326 326 static int pcic_calc_speed(pcicdev_t *, uint32_t);
327 327 static int pcic_card_state(pcicdev_t *, pcic_socket_t *);
328 328 static int pcic_find_pci_type(pcicdev_t *);
329 329 static void pcic_82092_smiirq_ctl(pcicdev_t *, int, int, int);
330 330 static void pcic_handle_cd_change(pcicdev_t *, pcic_socket_t *, uint8_t);
331 331 static uint_t pcic_cd_softint(caddr_t, caddr_t);
332 332 static uint8_t pcic_getb(pcicdev_t *, int, int);
333 333 static void pcic_putb(pcicdev_t *, int, int, int8_t);
334 334 static int pcic_set_vcc_level(pcicdev_t *, set_socket_t *);
335 335 static uint_t pcic_softintr(caddr_t, caddr_t);
336 336
337 337 static void pcic_debounce(pcic_socket_t *);
338 338 static void pcic_do_resume(pcicdev_t *);
339 339 static void *pcic_add_debqueue(pcic_socket_t *, int);
340 340 static void pcic_rm_debqueue(void *);
341 341 static void pcic_deb_thread();
342 342
343 343 static boolean_t pcic_load_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp);
344 344 static void pcic_unload_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp);
345 345 static uint32_t pcic_getcb(pcicdev_t *pcic, int reg);
346 346 static void pcic_putcb(pcicdev_t *pcic, int reg, uint32_t value);
347 347 static void pcic_cb_enable_intr(dev_info_t *);
348 348 static void pcic_cb_disable_intr(dev_info_t *);
349 349 static void pcic_enable_io_intr(pcicdev_t *pcic, int socket, int irq);
350 350 static void pcic_disable_io_intr(pcicdev_t *pcic, int socket);
351 351
352 352 static cb_nexus_cb_t pcic_cbnexus_ops = {
353 353 pcic_cb_enable_intr,
354 354 pcic_cb_disable_intr
355 355 };
356 356
357 357 static int pcic_exca_powerctl(pcicdev_t *pcic, int socket, int powerlevel);
358 358 static int pcic_cbus_powerctl(pcicdev_t *pcic, int socket);
359 359
360 360 #if defined(__sparc)
361 361 static int pcic_fault(enum pci_fault_ops op, void *arg);
362 362 #endif
363 363
364 364
365 365 /*
366 366 * pcmcia interface operations structure
367 367 * this is the private interface that is exported to the nexus
368 368 */
369 369 pcmcia_if_t pcic_if_ops = {
370 370 PCIF_MAGIC,
371 371 PCIF_VERSION,
372 372 pcic_callback,
373 373 pcic_get_adapter,
374 374 pcic_get_page,
375 375 pcic_get_socket,
376 376 pcic_get_status,
377 377 pcic_get_window,
378 378 pcic_inquire_adapter,
379 379 pcic_inquire_socket,
380 380 pcic_inquire_window,
381 381 pcic_reset_socket,
382 382 pcic_set_page,
383 383 pcic_set_window,
384 384 pcic_set_socket,
385 385 pcic_set_interrupt,
386 386 pcic_clear_interrupt,
387 387 NULL,
388 388 };
389 389
390 390 /*
391 391 * chip type identification routines
392 392 * this list of functions is searched until one of them succeeds
393 393 * or all fail. i82365SL is assumed if failed.
394 394 */
395 395 static int pcic_ci_cirrus(pcicdev_t *);
396 396 static int pcic_ci_vadem(pcicdev_t *);
397 397 static int pcic_ci_ricoh(pcicdev_t *);
398 398
399 399 int (*pcic_ci_funcs[])(pcicdev_t *) = {
400 400 pcic_ci_cirrus,
401 401 pcic_ci_vadem,
402 402 pcic_ci_ricoh,
↓ open down ↓ |
402 lines elided |
↑ open up ↑ |
403 403 NULL
404 404 };
405 405
406 406 static struct modldrv modldrv = {
407 407 &mod_driverops, /* Type of module. This one is a driver */
408 408 "PCIC PCMCIA adapter driver", /* Name of the module. */
409 409 &pcic_devops, /* driver ops */
410 410 };
411 411
412 412 static struct modlinkage modlinkage = {
413 - MODREV_1, (void *)&modldrv, NULL
413 + MODREV_1, { (void *)&modldrv, NULL }
414 414 };
415 415
416 416 int
417 417 _init()
418 418 {
419 419 int stat;
420 420
421 421 /* Allocate soft state */
422 422 if ((stat = ddi_soft_state_init(&pcic_soft_state_p,
423 423 SOFTC_SIZE, 2)) != DDI_SUCCESS)
424 424 return (stat);
425 425
426 426 if ((stat = mod_install(&modlinkage)) != 0)
427 427 ddi_soft_state_fini(&pcic_soft_state_p);
428 428
429 429 return (stat);
430 430 }
431 431
432 432 int
433 433 _fini()
434 434 {
435 435 int stat = 0;
436 436
437 437 if ((stat = mod_remove(&modlinkage)) != 0)
438 438 return (stat);
439 439
440 440 if (pcic_deb_threadid) {
441 441 mutex_enter(&pcic_deb_mtx);
442 442 pcic_deb_threadid = 0;
443 443 while (!pcic_deb_threadid)
444 444 cv_wait(&pcic_deb_cv, &pcic_deb_mtx);
445 445 pcic_deb_threadid = 0;
446 446 mutex_exit(&pcic_deb_mtx);
447 447
448 448 mutex_destroy(&pcic_deb_mtx);
449 449 cv_destroy(&pcic_deb_cv);
450 450 }
451 451
452 452 ddi_soft_state_fini(&pcic_soft_state_p);
453 453
454 454 return (stat);
455 455 }
456 456
457 457 int
458 458 _info(struct modinfo *modinfop)
459 459 {
460 460 return (mod_info(&modlinkage, modinfop));
461 461 }
462 462
463 463 /*
464 464 * pcic_getinfo()
465 465 * provide instance/device information about driver
466 466 */
467 467 /*ARGSUSED*/
468 468 static int
469 469 pcic_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
470 470 {
471 471 anp_t *anp;
472 472 int error = DDI_SUCCESS;
473 473 minor_t minor;
474 474
475 475 switch (cmd) {
476 476 case DDI_INFO_DEVT2DEVINFO:
477 477 minor = getminor((dev_t)arg);
478 478 minor &= 0x7f;
479 479 if (!(anp = ddi_get_soft_state(pcic_soft_state_p, minor)))
480 480 *result = NULL;
481 481 else
482 482 *result = anp->an_dip;
483 483 break;
484 484 case DDI_INFO_DEVT2INSTANCE:
485 485 minor = getminor((dev_t)arg);
486 486 minor &= 0x7f;
487 487 *result = (void *)((long)minor);
488 488 break;
489 489 default:
490 490 error = DDI_FAILURE;
491 491 break;
492 492 }
493 493 return (error);
494 494 }
495 495
496 496 static int
497 497 pcic_probe(dev_info_t *dip)
498 498 {
499 499 int value;
500 500 ddi_device_acc_attr_t attr;
501 501 ddi_acc_handle_t handle;
502 502 uchar_t *index, *data;
503 503
504 504 if (ddi_dev_is_sid(dip) == DDI_SUCCESS)
505 505 return (DDI_PROBE_DONTCARE);
506 506
507 507 /*
508 508 * find a PCIC device (any vendor)
509 509 * while there can be up to 4 such devices in
510 510 * a system, we currently only look for 1
511 511 * per probe. There will be up to 2 chips per
512 512 * instance since they share I/O space
513 513 */
514 514 attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
515 515 attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
516 516 attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
517 517
518 518 if (ddi_regs_map_setup(dip, PCIC_ISA_CONTROL_REG_NUM,
519 519 (caddr_t *)&index,
520 520 PCIC_ISA_CONTROL_REG_OFFSET,
521 521 PCIC_ISA_CONTROL_REG_LENGTH,
522 522 &attr, &handle) != DDI_SUCCESS)
523 523 return (DDI_PROBE_FAILURE);
524 524
525 525 data = index + 1;
526 526
527 527 #if defined(PCIC_DEBUG)
528 528 if (pcic_debug)
529 529 cmn_err(CE_CONT, "pcic_probe: entered\n");
530 530 if (pcic_debug)
531 531 cmn_err(CE_CONT, "\tindex=%p\n", (void *)index);
532 532 #endif
533 533 ddi_put8(handle, index, PCIC_CHIP_REVISION);
534 534 ddi_put8(handle, data, 0);
535 535 value = ddi_get8(handle, data);
536 536 #if defined(PCIC_DEBUG)
537 537 if (pcic_debug)
538 538 cmn_err(CE_CONT, "\tchip revision register = %x\n", value);
539 539 #endif
540 540 if ((value & PCIC_REV_MASK) >= PCIC_REV_LEVEL_LOW &&
541 541 (value & 0x30) == 0) {
542 542 /*
543 543 * we probably have a PCIC chip in the system
544 544 * do a little more checking. If we find one,
545 545 * reset everything in case of softboot
546 546 */
547 547 ddi_put8(handle, index, PCIC_MAPPING_ENABLE);
548 548 ddi_put8(handle, data, 0);
549 549 value = ddi_get8(handle, data);
550 550 #if defined(PCIC_DEBUG)
551 551 if (pcic_debug)
552 552 cmn_err(CE_CONT, "\tzero test = %x\n", value);
553 553 #endif
554 554 /* should read back as zero */
555 555 if (value == 0) {
556 556 /*
557 557 * we do have one and it is off the bus
558 558 */
559 559 #if defined(PCIC_DEBUG)
560 560 if (pcic_debug)
561 561 cmn_err(CE_CONT, "pcic_probe: success\n");
562 562 #endif
563 563 ddi_regs_map_free(&handle);
564 564 return (DDI_PROBE_SUCCESS);
565 565 }
566 566 }
567 567 #if defined(PCIC_DEBUG)
568 568 if (pcic_debug)
569 569 cmn_err(CE_CONT, "pcic_probe: failed\n");
570 570 #endif
571 571 ddi_regs_map_free(&handle);
572 572 return (DDI_PROBE_FAILURE);
573 573 }
574 574
575 575 /*
576 576 * These are just defaults they can also be changed via a property in the
577 577 * conf file.
578 578 */
579 579 static int pci_config_reg_num = PCIC_PCI_CONFIG_REG_NUM;
580 580 static int pci_control_reg_num = PCIC_PCI_CONTROL_REG_NUM;
581 581 static int pcic_do_pcmcia_sr = 1;
582 582 static int pcic_use_cbpwrctl = PCF_CBPWRCTL;
583 583
584 584 /*
585 585 * enable insertion/removal interrupt for 32bit cards
586 586 */
587 587 static int
588 588 cardbus_enable_cd_intr(dev_info_t *dip)
589 589 {
590 590 ddi_acc_handle_t iohandle;
591 591 caddr_t ioaddr;
592 592 ddi_device_acc_attr_t attr;
593 593 attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
594 594 attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
595 595 attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
596 596 (void) ddi_regs_map_setup(dip, 1,
597 597 (caddr_t *)&ioaddr,
598 598 0,
599 599 4096,
600 600 &attr, &iohandle);
601 601
602 602 /* CSC Interrupt: Card detect interrupt on */
603 603 ddi_put32(iohandle, (uint32_t *)(ioaddr+CB_STATUS_MASK),
604 604 ddi_get32(iohandle,
605 605 (uint32_t *)(ioaddr+CB_STATUS_MASK)) | CB_SE_CCDMASK);
606 606
607 607 ddi_put32(iohandle, (uint32_t *)(ioaddr+CB_STATUS_EVENT),
608 608 ddi_get32(iohandle, (uint32_t *)(ioaddr+CB_STATUS_EVENT)));
609 609
610 610 ddi_regs_map_free(&iohandle);
611 611 return (1);
612 612 }
613 613
614 614 /*
615 615 * quiesce(9E) entry point.
616 616 *
617 617 * This function is called when the system is single-threaded at high
618 618 * PIL with preemption disabled. Therefore, this function must not be
619 619 * blocked.
620 620 *
621 621 * This function returns DDI_SUCCESS on success, or DDI_FAILURE on failure.
622 622 * DDI_FAILURE indicates an error condition and should almost never happen.
623 623 */
624 624 static int32_t
625 625 pcic_quiesce(dev_info_t *dip)
626 626 {
627 627 anp_t *anp = ddi_get_driver_private(dip);
628 628 pcicdev_t *pcic = anp->an_private;
629 629 int i;
630 630
631 631 for (i = 0; i < pcic->pc_numsockets; i++) {
632 632 pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 0);
633 633 pcic_putb(pcic, i, PCIC_CARD_DETECT, 0);
634 634 pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
635 635 /* disable interrupts and put card into RESET */
636 636 pcic_putb(pcic, i, PCIC_INTERRUPT, 0);
637 637 /* poweroff socket */
638 638 pcic_putb(pcic, i, PCIC_POWER_CONTROL, 0);
639 639 pcic_putcb(pcic, CB_CONTROL, 0);
640 640 }
641 641
642 642 return (DDI_SUCCESS);
643 643 }
644 644
645 645 /*
646 646 * pcic_attach()
647 647 * attach the PCIC (Intel 82365SL/CirrusLogic/Toshiba) driver
648 648 * to the system. This is a child of "sysbus" since that is where
649 649 * the hardware lives, but it provides services to the "pcmcia"
650 650 * nexus driver. It gives a pointer back via its private data
651 651 * structure which contains both the dip and socket services entry
652 652 * points
653 653 */
654 654 static int
655 655 pcic_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
656 656 {
657 657 anp_t *pcic_nexus;
658 658 pcicdev_t *pcic;
659 659 int irqlevel, value;
660 660 int pci_cfrn, pci_ctrn;
661 661 int i, j, smi, actual;
662 662 char *typename;
663 663 char bus_type[16] = "(unknown)";
664 664 int len = sizeof (bus_type);
665 665 ddi_device_acc_attr_t attr;
666 666 anp_t *anp = ddi_get_driver_private(dip);
667 667 uint_t pri;
668 668
669 669 #if defined(PCIC_DEBUG)
670 670 if (pcic_debug) {
671 671 cmn_err(CE_CONT, "pcic_attach: entered\n");
672 672 }
673 673 #endif
674 674 switch (cmd) {
675 675 case DDI_ATTACH:
676 676 break;
677 677 case DDI_RESUME:
678 678 pcic = anp->an_private;
679 679 /*
680 680 * for now, this is a simulated resume.
681 681 * a real one may need different things.
682 682 */
683 683 if (pcic != NULL && pcic->pc_flags & PCF_SUSPENDED) {
684 684 mutex_enter(&pcic->pc_lock);
685 685 /* should probe for new sockets showing up */
686 686 pcic_setup_adapter(pcic);
687 687 pcic->pc_flags &= ~PCF_SUSPENDED;
688 688 mutex_exit(&pcic->pc_lock);
689 689 (void) pcmcia_begin_resume(dip);
690 690
691 691 pcic_do_resume(pcic);
692 692 #ifdef CARDBUS
693 693 cardbus_restore_children(ddi_get_child(dip));
694 694 #endif
695 695
696 696 /*
697 697 * for complete implementation need END_RESUME (later)
698 698 */
699 699 return (DDI_SUCCESS);
700 700
701 701 }
702 702 return (DDI_SUCCESS);
703 703 default:
704 704 return (DDI_FAILURE);
705 705 }
706 706
707 707 /*
708 708 * Allocate soft state associated with this instance.
709 709 */
710 710 if (ddi_soft_state_zalloc(pcic_soft_state_p,
711 711 ddi_get_instance(dip)) != DDI_SUCCESS) {
712 712 cmn_err(CE_CONT, "pcic%d: Unable to alloc state\n",
713 713 ddi_get_instance(dip));
714 714 return (DDI_FAILURE);
715 715 }
716 716
717 717 pcic_nexus = ddi_get_soft_state(pcic_soft_state_p,
718 718 ddi_get_instance(dip));
719 719
720 720 pcic = kmem_zalloc(sizeof (pcicdev_t), KM_SLEEP);
721 721
722 722 pcic->dip = dip;
723 723 pcic_nexus->an_dip = dip;
724 724 pcic_nexus->an_if = &pcic_if_ops;
725 725 pcic_nexus->an_private = pcic;
726 726 pcic->pc_numpower = sizeof (pcic_power)/sizeof (pcic_power[0]);
727 727 pcic->pc_power = pcic_power;
728 728
729 729 pci_ctrn = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP,
730 730 "pci-control-reg-number", pci_control_reg_num);
731 731 pci_cfrn = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP,
732 732 "pci-config-reg-number", pci_config_reg_num);
733 733
734 734 ddi_set_driver_private(dip, pcic_nexus);
735 735
736 736 /*
737 737 * pcic->pc_irq is really the IPL level we want to run at
738 738 * set the default values here and override from intr spec
739 739 */
740 740 pcic->pc_irq = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP,
741 741 "interrupt-priorities", -1);
742 742
743 743 if (pcic->pc_irq == -1) {
744 744 int actual;
745 745 uint_t pri;
746 746 ddi_intr_handle_t hdl;
747 747
748 748 /* see if intrspec tells us different */
749 749 if (ddi_intr_alloc(dip, &hdl, DDI_INTR_TYPE_FIXED,
750 750 0, 1, &actual, DDI_INTR_ALLOC_NORMAL) == DDI_SUCCESS) {
751 751 if (ddi_intr_get_pri(hdl, &pri) == DDI_SUCCESS)
752 752 pcic->pc_irq = pri;
753 753 else
754 754 pcic->pc_irq = LOCK_LEVEL + 1;
755 755 (void) ddi_intr_free(hdl);
756 756 }
757 757 }
758 758 pcic_nexus->an_ipl = pcic->pc_irq;
759 759
760 760 /*
761 761 * Check our parent bus type. We do different things based on which
762 762 * bus we're on.
763 763 */
764 764 if (ddi_prop_op(DDI_DEV_T_ANY, ddi_get_parent(dip),
765 765 PROP_LEN_AND_VAL_BUF, DDI_PROP_CANSLEEP,
766 766 "device_type", (caddr_t)&bus_type[0], &len) !=
767 767 DDI_PROP_SUCCESS) {
768 768 if (ddi_prop_op(DDI_DEV_T_ANY, ddi_get_parent(dip),
769 769 PROP_LEN_AND_VAL_BUF, DDI_PROP_CANSLEEP,
770 770 "bus-type", (caddr_t)&bus_type[0], &len) !=
771 771 DDI_PROP_SUCCESS) {
772 772
773 773 cmn_err(CE_CONT,
774 774 "pcic%d: can't find parent bus type\n",
775 775 ddi_get_instance(dip));
776 776
777 777 kmem_free(pcic, sizeof (pcicdev_t));
778 778 ddi_soft_state_free(pcic_soft_state_p,
779 779 ddi_get_instance(dip));
780 780 return (DDI_FAILURE);
781 781 }
782 782 } /* ddi_prop_op("device_type") */
783 783
784 784 if (strcmp(bus_type, DEVI_PCI_NEXNAME) == 0 ||
785 785 strcmp(bus_type, DEVI_PCIEX_NEXNAME) == 0) {
786 786 pcic->pc_flags = PCF_PCIBUS;
787 787 } else {
788 788 cmn_err(CE_WARN, "!pcic%d: non-pci mode (%s) not supported, "
789 789 "set BIOS to yenta mode if applicable\n",
790 790 ddi_get_instance(dip), bus_type);
791 791 kmem_free(pcic, sizeof (pcicdev_t));
792 792 ddi_soft_state_free(pcic_soft_state_p,
793 793 ddi_get_instance(dip));
794 794 return (DDI_FAILURE);
795 795 }
796 796
797 797 if ((pcic->bus_speed = ddi_getprop(DDI_DEV_T_ANY, ddi_get_parent(dip),
798 798 DDI_PROP_CANSLEEP,
799 799 "clock-frequency", 0)) == 0) {
800 800 if (pcic->pc_flags & PCF_PCIBUS)
801 801 pcic->bus_speed = PCIC_PCI_DEF_SYSCLK;
802 802 else
803 803 pcic->bus_speed = PCIC_ISA_DEF_SYSCLK;
804 804 } else {
805 805 /*
806 806 * OBP can declare the speed in Hz...
807 807 */
808 808 if (pcic->bus_speed > 1000000)
809 809 pcic->bus_speed /= 1000000;
810 810 } /* ddi_prop_op("clock-frequency") */
811 811
812 812 pcic->pc_io_type = PCIC_IO_TYPE_82365SL; /* default mode */
813 813
814 814 #ifdef PCIC_DEBUG
815 815 if (pcic_debug) {
816 816 cmn_err(CE_CONT,
817 817 "pcic%d: parent bus type = [%s], speed = %d MHz\n",
818 818 ddi_get_instance(dip),
819 819 bus_type, pcic->bus_speed);
820 820 }
821 821 #endif
822 822
823 823 /*
824 824 * The reg properties on a PCI node are different than those
825 825 * on a non-PCI node. Handle that difference here.
826 826 * If it turns out to be a CardBus chip, we have even more
827 827 * differences.
828 828 */
829 829 if (pcic->pc_flags & PCF_PCIBUS) {
830 830 int class_code;
831 831 #if defined(__i386) || defined(__amd64)
832 832 pcic->pc_base = 0x1000000;
833 833 pcic->pc_bound = (uint32_t)~0;
834 834 pcic->pc_iobase = 0x1000;
835 835 pcic->pc_iobound = 0xefff;
836 836 #elif defined(__sparc)
837 837 pcic->pc_base = 0x0;
838 838 pcic->pc_bound = (uint32_t)~0;
839 839 pcic->pc_iobase = 0x00000;
840 840 pcic->pc_iobound = 0xffff;
841 841 #endif
842 842
843 843 /* usually need to get at config space so map first */
844 844 attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
845 845 attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
846 846 attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
847 847
848 848 if (ddi_regs_map_setup(dip, pci_cfrn,
849 849 (caddr_t *)&pcic->cfgaddr,
850 850 PCIC_PCI_CONFIG_REG_OFFSET,
851 851 PCIC_PCI_CONFIG_REG_LENGTH,
852 852 &attr,
853 853 &pcic->cfg_handle) !=
854 854 DDI_SUCCESS) {
855 855 cmn_err(CE_CONT,
856 856 "pcic%d: unable to map config space"
857 857 "regs\n",
858 858 ddi_get_instance(dip));
859 859
860 860 kmem_free(pcic, sizeof (pcicdev_t));
861 861 return (DDI_FAILURE);
862 862 } /* ddi_regs_map_setup */
863 863
864 864 class_code = ddi_getprop(DDI_DEV_T_ANY, dip,
865 865 DDI_PROP_CANSLEEP|DDI_PROP_DONTPASS,
866 866 "class-code", -1);
867 867 #ifdef PCIC_DEBUG
868 868 if (pcic_debug) {
869 869 cmn_err(CE_CONT, "pcic_attach class_code=%x\n",
870 870 class_code);
871 871 }
872 872 #endif
873 873
874 874 switch (class_code) {
875 875 case PCIC_PCI_CARDBUS:
876 876 pcic->pc_flags |= PCF_CARDBUS;
877 877 pcic->pc_io_type = PCIC_IO_TYPE_YENTA;
878 878 /*
879 879 * Get access to the adapter registers on the
880 880 * PCI bus. A 4K memory page
881 881 */
882 882 #if defined(PCIC_DEBUG)
883 883 pcic_err(dip, 8, "Is Cardbus device\n");
884 884 if (pcic_debug) {
885 885 int nr;
886 886 long rs;
887 887 (void) ddi_dev_nregs(dip, &nr);
888 888 pcic_err(dip, 9, "\tdev, cfgaddr 0x%p,"
889 889 "cfghndl 0x%p nregs %d",
890 890 (void *)pcic->cfgaddr,
891 891 (void *)pcic->cfg_handle, nr);
892 892
893 893 (void) ddi_dev_regsize(dip,
894 894 PCIC_PCI_CONTROL_REG_NUM, &rs);
895 895
896 896 pcic_err(dip, 9, "\tsize of reg %d is 0x%x\n",
897 897 PCIC_PCI_CONTROL_REG_NUM, (int)rs);
898 898 }
899 899 #endif
900 900 attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
901 901 attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
902 902 attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
903 903
904 904 if (ddi_regs_map_setup(dip, pci_ctrn,
905 905 (caddr_t *)&pcic->ioaddr,
906 906 PCIC_PCI_CONTROL_REG_OFFSET,
907 907 PCIC_CB_CONTROL_REG_LENGTH,
908 908 &attr, &pcic->handle) !=
909 909 DDI_SUCCESS) {
910 910 cmn_err(CE_CONT,
911 911 "pcic%d: unable to map PCI regs\n",
912 912 ddi_get_instance(dip));
913 913 ddi_regs_map_free(&pcic->cfg_handle);
914 914 kmem_free(pcic, sizeof (pcicdev_t));
915 915 return (DDI_FAILURE);
916 916 } /* ddi_regs_map_setup */
917 917
918 918 /*
919 919 * Find out the chip type - If we're on a PCI bus,
920 920 * the adapter has that information in the PCI
921 921 * config space.
922 922 * Note that we call pcic_find_pci_type here since
923 923 * it needs a valid mapped pcic->handle to
924 924 * access some of the adapter registers in
925 925 * some cases.
926 926 */
927 927 if (pcic_find_pci_type(pcic) != DDI_SUCCESS) {
928 928 ddi_regs_map_free(&pcic->handle);
929 929 ddi_regs_map_free(&pcic->cfg_handle);
930 930 kmem_free(pcic, sizeof (pcicdev_t));
931 931 cmn_err(CE_WARN, "pcic: %s: unsupported "
932 932 "bridge\n", ddi_get_name_addr(dip));
933 933 return (DDI_FAILURE);
934 934 }
935 935 break;
936 936
937 937 default:
938 938 case PCIC_PCI_PCMCIA:
939 939 /*
940 940 * Get access to the adapter IO registers on the
941 941 * PCI bus config space.
942 942 */
943 943 attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
944 944 attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
945 945 attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
946 946
947 947 /*
948 948 * We need a default mapping to the adapter's IO
949 949 * control register space. For most adapters
950 950 * that are of class PCIC_PCI_PCMCIA (or of
951 951 * a default class) the control registers
952 952 * will be using the 82365-type control/data
953 953 * format.
954 954 */
955 955 if (ddi_regs_map_setup(dip, pci_ctrn,
956 956 (caddr_t *)&pcic->ioaddr,
957 957 PCIC_PCI_CONTROL_REG_OFFSET,
958 958 PCIC_PCI_CONTROL_REG_LENGTH,
959 959 &attr,
960 960 &pcic->handle) != DDI_SUCCESS) {
961 961 cmn_err(CE_CONT,
962 962 "pcic%d: unable to map PCI regs\n",
963 963 ddi_get_instance(dip));
964 964 ddi_regs_map_free(&pcic->cfg_handle);
965 965 kmem_free(pcic, sizeof (pcicdev_t));
966 966 return (DDI_FAILURE);
967 967 } /* ddi_regs_map_setup */
968 968
969 969 /*
970 970 * Find out the chip type - If we're on a PCI bus,
971 971 * the adapter has that information in the PCI
972 972 * config space.
973 973 * Note that we call pcic_find_pci_type here since
974 974 * it needs a valid mapped pcic->handle to
975 975 * access some of the adapter registers in
976 976 * some cases.
977 977 */
978 978 if (pcic_find_pci_type(pcic) != DDI_SUCCESS) {
979 979 ddi_regs_map_free(&pcic->handle);
980 980 ddi_regs_map_free(&pcic->cfg_handle);
981 981 kmem_free(pcic, sizeof (pcicdev_t));
982 982 cmn_err(CE_WARN, "pcic: %s: unsupported "
983 983 "bridge\n",
984 984 ddi_get_name_addr(dip));
985 985 return (DDI_FAILURE);
986 986 }
987 987
988 988 /*
989 989 * Some PCI-PCMCIA(R2) adapters are Yenta-compliant
990 990 * for extended registers even though they are
991 991 * not CardBus adapters. For those adapters,
992 992 * re-map pcic->handle to be large enough to
993 993 * encompass the Yenta registers.
994 994 */
995 995 switch (pcic->pc_type) {
996 996 case PCIC_TI_PCI1031:
997 997 ddi_regs_map_free(&pcic->handle);
998 998
999 999 if (ddi_regs_map_setup(dip,
1000 1000 PCIC_PCI_CONTROL_REG_NUM,
1001 1001 (caddr_t *)&pcic->ioaddr,
1002 1002 PCIC_PCI_CONTROL_REG_OFFSET,
1003 1003 PCIC_CB_CONTROL_REG_LENGTH,
1004 1004 &attr,
1005 1005 &pcic->handle) != DDI_SUCCESS) {
1006 1006 cmn_err(CE_CONT,
1007 1007 "pcic%d: unable to map "
1008 1008 "PCI regs\n",
1009 1009 ddi_get_instance(dip));
1010 1010 ddi_regs_map_free(&pcic->cfg_handle);
1011 1011 kmem_free(pcic, sizeof (pcicdev_t));
1012 1012 return (DDI_FAILURE);
1013 1013 } /* ddi_regs_map_setup */
1014 1014 break;
1015 1015 default:
1016 1016 break;
1017 1017 } /* switch (pcic->pc_type) */
1018 1018 break;
1019 1019 } /* switch (class_code) */
1020 1020 } else {
1021 1021 /*
1022 1022 * We're not on a PCI bus, so assume an ISA bus type
1023 1023 * register property. Get access to the adapter IO
1024 1024 * registers on a non-PCI bus.
1025 1025 */
1026 1026 attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
1027 1027 attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
1028 1028 attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
1029 1029 pcic->mem_reg_num = PCIC_ISA_MEM_REG_NUM;
1030 1030 pcic->io_reg_num = PCIC_ISA_IO_REG_NUM;
1031 1031
1032 1032 if (ddi_regs_map_setup(dip, PCIC_ISA_CONTROL_REG_NUM,
1033 1033 (caddr_t *)&pcic->ioaddr,
1034 1034 PCIC_ISA_CONTROL_REG_OFFSET,
1035 1035 PCIC_ISA_CONTROL_REG_LENGTH,
1036 1036 &attr,
1037 1037 &pcic->handle) != DDI_SUCCESS) {
1038 1038 cmn_err(CE_CONT,
1039 1039 "pcic%d: unable to map ISA registers\n",
1040 1040 ddi_get_instance(dip));
1041 1041
1042 1042 kmem_free(pcic, sizeof (pcicdev_t));
1043 1043 return (DDI_FAILURE);
1044 1044 } /* ddi_regs_map_setup */
1045 1045
1046 1046 /* ISA bus is limited to 24-bits, but not first 640K */
1047 1047 pcic->pc_base = 0xd0000;
1048 1048 pcic->pc_bound = (uint32_t)~0;
1049 1049 pcic->pc_iobase = 0x1000;
1050 1050 pcic->pc_iobound = 0xefff;
1051 1051 } /* !PCF_PCIBUS */
1052 1052
1053 1053 #ifdef PCIC_DEBUG
1054 1054 if (pcic_debug) {
1055 1055 cmn_err(CE_CONT, "pcic_attach pc_flags=%x pc_type=%x\n",
1056 1056 pcic->pc_flags, pcic->pc_type);
1057 1057 }
1058 1058 #endif
1059 1059
1060 1060 /*
1061 1061 * Setup various adapter registers for the PCI case. For the
1062 1062 * non-PCI case, find out the chip type.
1063 1063 */
1064 1064 if (pcic->pc_flags & PCF_PCIBUS) {
1065 1065 int iline;
1066 1066 #if defined(__sparc)
1067 1067 iline = 0;
1068 1068 #else
1069 1069 iline = cardbus_validate_iline(dip, pcic->cfg_handle);
1070 1070 #endif
1071 1071
1072 1072 /* set flags and socket counts based on chip type */
1073 1073 switch (pcic->pc_type) {
1074 1074 uint32_t cfg;
1075 1075 case PCIC_INTEL_i82092:
1076 1076 cfg = ddi_get8(pcic->cfg_handle,
1077 1077 pcic->cfgaddr + PCIC_82092_PCICON);
1078 1078 /* we can only support 4 Socket version */
1079 1079 if (cfg & PCIC_82092_4_SOCKETS) {
1080 1080 pcic->pc_numsockets = 4;
1081 1081 pcic->pc_type = PCIC_INTEL_i82092;
1082 1082 if (iline != 0xFF)
1083 1083 pcic->pc_intr_mode =
1084 1084 PCIC_INTR_MODE_PCI_1;
1085 1085 else
1086 1086 pcic->pc_intr_mode = PCIC_INTR_MODE_ISA;
1087 1087 } else {
1088 1088 cmn_err(CE_CONT,
1089 1089 "pcic%d: Intel 82092 adapter "
1090 1090 "in unsupported configuration: 0x%x",
1091 1091 ddi_get_instance(pcic->dip), cfg);
1092 1092 pcic->pc_numsockets = 0;
1093 1093 } /* PCIC_82092_4_SOCKETS */
1094 1094 break;
1095 1095 case PCIC_CL_PD6730:
1096 1096 case PCIC_CL_PD6729:
1097 1097 pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1;
1098 1098 cfg = ddi_getprop(DDI_DEV_T_ANY, dip,
1099 1099 DDI_PROP_CANSLEEP,
1100 1100 "interrupts", 0);
1101 1101 /* if not interrupt pin then must use ISA style IRQs */
1102 1102 if (cfg == 0 || iline == 0xFF)
1103 1103 pcic->pc_intr_mode = PCIC_INTR_MODE_ISA;
1104 1104 else {
1105 1105 /*
1106 1106 * we have the option to use PCI interrupts.
1107 1107 * this might not be optimal but in some cases
1108 1108 * is the only thing possible (sparc case).
1109 1109 * we now deterine what is possible.
1110 1110 */
1111 1111 pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1;
1112 1112 }
1113 1113 pcic->pc_numsockets = 2;
1114 1114 pcic->pc_flags |= PCF_IO_REMAP;
1115 1115 break;
1116 1116 case PCIC_TI_PCI1031:
1117 1117 /* this chip doesn't do CardBus but looks like one */
1118 1118 pcic->pc_flags &= ~PCF_CARDBUS;
1119 1119 /* FALLTHROUGH */
1120 1120 default:
1121 1121 pcic->pc_flags |= PCF_IO_REMAP;
1122 1122 /* FALLTHROUGH */
1123 1123 /* indicate feature even if not supported */
1124 1124 pcic->pc_flags |= PCF_DMA | PCF_ZV;
1125 1125 /* Not sure if these apply to all these chips */
1126 1126 pcic->pc_flags |= (PCF_VPPX|PCF_33VCAP);
1127 1127 pcic->pc_flags |= pcic_use_cbpwrctl;
1128 1128
1129 1129 pcic->pc_numsockets = 1; /* one per function */
1130 1130 if (iline != 0xFF) {
1131 1131 uint8_t cfg;
1132 1132 pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1;
1133 1133
1134 1134 cfg = ddi_get8(pcic->cfg_handle,
1135 1135 (pcic->cfgaddr + PCIC_BRIDGE_CTL_REG));
1136 1136 cfg &= (~PCIC_FUN_INT_MOD_ISA);
1137 1137 ddi_put8(pcic->cfg_handle, (pcic->cfgaddr +
1138 1138 PCIC_BRIDGE_CTL_REG), cfg);
1139 1139 }
1140 1140 else
1141 1141 pcic->pc_intr_mode = PCIC_INTR_MODE_ISA;
1142 1142 pcic->pc_io_type = PCIC_IOTYPE_YENTA;
1143 1143 break;
1144 1144 }
1145 1145 } else {
1146 1146 /*
1147 1147 * We're not on a PCI bus so do some more
1148 1148 * checking for adapter type here.
1149 1149 * For the non-PCI bus case:
1150 1150 * It could be any one of a number of different chips
1151 1151 * If we can't determine anything else, it is assumed
1152 1152 * to be an Intel 82365SL. The Cirrus Logic PD6710
1153 1153 * has an extension register that provides unique
1154 1154 * identification. Toshiba chip isn't detailed as yet.
1155 1155 */
1156 1156
1157 1157 /* Init the CL id mode */
1158 1158 pcic_putb(pcic, 0, PCIC_CHIP_INFO, 0);
1159 1159 value = pcic_getb(pcic, 0, PCIC_CHIP_INFO);
1160 1160
1161 1161 /* default to Intel i82365SL and then refine */
1162 1162 pcic->pc_type = PCIC_I82365SL;
1163 1163 pcic->pc_chipname = PCIC_TYPE_I82365SL;
1164 1164 for (value = 0; pcic_ci_funcs[value] != NULL; value++) {
1165 1165 /* go until one succeeds or none left */
1166 1166 if (pcic_ci_funcs[value](pcic))
1167 1167 break;
1168 1168 }
1169 1169
1170 1170 /* any chip specific flags get set here */
1171 1171 switch (pcic->pc_type) {
1172 1172 case PCIC_CL_PD6722:
1173 1173 pcic->pc_flags |= PCF_DMA;
1174 1174 }
1175 1175
1176 1176 for (i = 0; i < PCIC_MAX_SOCKETS; i++) {
1177 1177 /*
1178 1178 * look for total number of sockets.
1179 1179 * basically check each possible socket for
1180 1180 * presence like in probe
1181 1181 */
1182 1182
1183 1183 /* turn all windows off */
1184 1184 pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
1185 1185 value = pcic_getb(pcic, i, PCIC_MAPPING_ENABLE);
1186 1186
1187 1187 /*
1188 1188 * if a zero is read back, then this socket
1189 1189 * might be present. It would be except for
1190 1190 * some systems that map the secondary PCIC
1191 1191 * chip space back to the first.
1192 1192 */
1193 1193 if (value != 0) {
1194 1194 /* definitely not so skip */
1195 1195 /* note: this is for Compaq support */
1196 1196 continue;
1197 1197 }
1198 1198
1199 1199 /* further tests */
1200 1200 value = pcic_getb(pcic, i, PCIC_CHIP_REVISION) &
1201 1201 PCIC_REV_MASK;
1202 1202 if (!(value >= PCIC_REV_LEVEL_LOW &&
1203 1203 value <= PCIC_REV_LEVEL_HI))
1204 1204 break;
1205 1205
1206 1206 pcic_putb(pcic, i, PCIC_SYSMEM_0_STARTLOW, 0xaa);
1207 1207 pcic_putb(pcic, i, PCIC_SYSMEM_1_STARTLOW, 0x55);
1208 1208 value = pcic_getb(pcic, i, PCIC_SYSMEM_0_STARTLOW);
1209 1209
1210 1210 j = pcic_getb(pcic, i, PCIC_SYSMEM_1_STARTLOW);
1211 1211 if (value != 0xaa || j != 0x55)
1212 1212 break;
1213 1213
1214 1214 /*
1215 1215 * at this point we know if we have hardware
1216 1216 * of some type and not just the bus holding
1217 1217 * a pattern for us. We still have to determine
1218 1218 * the case where more than 2 sockets are
1219 1219 * really the same due to peculiar mappings of
1220 1220 * hardware.
1221 1221 */
1222 1222 j = pcic->pc_numsockets++;
1223 1223 pcic->pc_sockets[j].pcs_flags = 0;
1224 1224 pcic->pc_sockets[j].pcs_io = pcic->ioaddr;
1225 1225 pcic->pc_sockets[j].pcs_socket = i;
1226 1226
1227 1227 /* put PC Card into RESET, just in case */
1228 1228 value = pcic_getb(pcic, i, PCIC_INTERRUPT);
1229 1229 pcic_putb(pcic, i, PCIC_INTERRUPT,
1230 1230 value & ~PCIC_RESET);
1231 1231 }
1232 1232
1233 1233 #if defined(PCIC_DEBUG)
1234 1234 if (pcic_debug)
1235 1235 cmn_err(CE_CONT, "num sockets = %d\n",
1236 1236 pcic->pc_numsockets);
1237 1237 #endif
1238 1238 if (pcic->pc_numsockets == 0) {
1239 1239 ddi_regs_map_free(&pcic->handle);
1240 1240 kmem_free(pcic, sizeof (pcicdev_t));
1241 1241 return (DDI_FAILURE);
1242 1242 }
1243 1243
1244 1244 /*
1245 1245 * need to think this through again in light of
1246 1246 * Compaq not following the model that all the
1247 1247 * chip vendors recommend. IBM 755 seems to be
1248 1248 * afflicted as well. Basically, if the vendor
1249 1249 * wired things wrong, socket 0 responds for socket 2
1250 1250 * accesses, etc.
1251 1251 */
1252 1252 if (pcic->pc_numsockets > 2) {
1253 1253 int count = pcic->pc_numsockets / 4;
1254 1254 for (i = 0; i < count; i++) {
1255 1255 /* put pattern into socket 0 */
1256 1256 pcic_putb(pcic, i,
1257 1257 PCIC_SYSMEM_0_STARTLOW, 0x11);
1258 1258
1259 1259 /* put pattern into socket 2 */
1260 1260 pcic_putb(pcic, i + 2,
1261 1261 PCIC_SYSMEM_0_STARTLOW, 0x33);
1262 1262
1263 1263 /* read back socket 0 */
1264 1264 value = pcic_getb(pcic, i,
1265 1265 PCIC_SYSMEM_0_STARTLOW);
1266 1266
1267 1267 /* read back chip 1 socket 0 */
1268 1268 j = pcic_getb(pcic, i + 2,
1269 1269 PCIC_SYSMEM_0_STARTLOW);
1270 1270 if (j == value) {
1271 1271 pcic->pc_numsockets -= 2;
1272 1272 }
1273 1273 }
1274 1274 }
1275 1275
1276 1276 smi = 0xff; /* no more override */
1277 1277
1278 1278 if (ddi_getprop(DDI_DEV_T_NONE, dip,
1279 1279 DDI_PROP_DONTPASS, "need-mult-irq",
1280 1280 0xffff) != 0xffff)
1281 1281 pcic->pc_flags |= PCF_MULT_IRQ;
1282 1282
1283 1283 } /* !PCF_PCIBUS */
1284 1284
1285 1285 /*
1286 1286 * some platforms/busses need to have resources setup
1287 1287 * this is temporary until a real resource allocator is
1288 1288 * implemented.
1289 1289 */
1290 1290
1291 1291 pcic_init_assigned(dip);
1292 1292
1293 1293 typename = pcic->pc_chipname;
1294 1294
1295 1295 #ifdef PCIC_DEBUG
1296 1296 if (pcic_debug) {
1297 1297 int nregs, nintrs;
1298 1298
1299 1299 if (ddi_dev_nregs(dip, &nregs) != DDI_SUCCESS)
1300 1300 nregs = 0;
1301 1301
1302 1302 if (ddi_dev_nintrs(dip, &nintrs) != DDI_SUCCESS)
1303 1303 nintrs = 0;
1304 1304
1305 1305 cmn_err(CE_CONT,
1306 1306 "pcic%d: %d register sets, %d interrupts\n",
1307 1307 ddi_get_instance(dip), nregs, nintrs);
1308 1308
1309 1309 nintrs = 0;
1310 1310 while (nregs--) {
1311 1311 off_t size;
1312 1312
1313 1313 if (ddi_dev_regsize(dip, nintrs, &size) ==
1314 1314 DDI_SUCCESS) {
1315 1315 cmn_err(CE_CONT,
1316 1316 "\tregnum %d size %ld (0x%lx)"
1317 1317 "bytes",
1318 1318 nintrs, size, size);
1319 1319 if (nintrs ==
1320 1320 (pcic->pc_io_type == PCIC_IO_TYPE_82365SL ?
1321 1321 PCIC_ISA_CONTROL_REG_NUM :
1322 1322 PCIC_PCI_CONTROL_REG_NUM))
1323 1323 cmn_err(CE_CONT,
1324 1324 " mapped at: 0x%p\n",
1325 1325 (void *)pcic->ioaddr);
1326 1326 else
1327 1327 cmn_err(CE_CONT, "\n");
1328 1328 } else {
1329 1329 cmn_err(CE_CONT,
1330 1330 "\tddi_dev_regsize(rnumber"
1331 1331 "= %d) returns DDI_FAILURE\n",
1332 1332 nintrs);
1333 1333 }
1334 1334 nintrs++;
1335 1335 } /* while */
1336 1336 } /* if (pcic_debug) */
1337 1337 #endif
1338 1338
1339 1339 cv_init(&pcic->pm_cv, NULL, CV_DRIVER, NULL);
1340 1340
1341 1341 if (!ddi_getprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS,
1342 1342 "disable-audio", 0))
1343 1343 pcic->pc_flags |= PCF_AUDIO;
1344 1344
1345 1345 if (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP,
1346 1346 "disable-cardbus", 0))
1347 1347 pcic->pc_flags &= ~PCF_CARDBUS;
1348 1348
1349 1349 (void) ddi_prop_update_string(DDI_DEV_T_NONE, dip, PCICPROP_CTL,
1350 1350 typename);
1351 1351
1352 1352 /*
1353 1353 * Init all socket SMI levels to 0 (no SMI)
1354 1354 */
1355 1355 for (i = 0; i < PCIC_MAX_SOCKETS; i++) {
1356 1356 pcic->pc_sockets[i].pcs_smi = 0;
1357 1357 pcic->pc_sockets[i].pcs_debounce_id = 0;
1358 1358 pcic->pc_sockets[i].pcs_pcic = pcic;
1359 1359 }
1360 1360 pcic->pc_lastreg = -1; /* just to make sure we are in sync */
1361 1361
1362 1362 /*
1363 1363 * Setup the IRQ handler(s)
1364 1364 */
1365 1365 switch (pcic->pc_intr_mode) {
1366 1366 int xx;
1367 1367 case PCIC_INTR_MODE_ISA:
1368 1368 /*
1369 1369 * On a non-PCI bus, we just use whatever SMI IRQ level was
1370 1370 * specified above, and the IO IRQ levels are allocated
1371 1371 * dynamically.
1372 1372 */
1373 1373 for (xx = 15, smi = 0; xx >= 0; xx--) {
1374 1374 if (PCIC_IRQ(xx) &
1375 1375 PCIC_AVAIL_IRQS) {
1376 1376 smi = pcmcia_get_intr(dip, xx);
1377 1377 if (smi >= 0)
1378 1378 break;
1379 1379 }
1380 1380 }
1381 1381 #if defined(PCIC_DEBUG)
1382 1382 if (pcic_debug)
1383 1383 cmn_err(CE_NOTE, "\tselected IRQ %d as SMI\n", smi);
1384 1384 #endif
1385 1385 /* init to same so share is easy */
1386 1386 for (i = 0; i < pcic->pc_numsockets; i++)
1387 1387 pcic->pc_sockets[i].pcs_smi = smi;
1388 1388 /* any special handling of IRQ levels */
1389 1389 if (pcic->pc_flags & PCF_MULT_IRQ) {
1390 1390 for (i = 2; i < pcic->pc_numsockets; i++) {
1391 1391 if ((i & 1) == 0) {
1392 1392 int xx;
1393 1393 for (xx = 15, smi = 0; xx >= 0; xx--) {
1394 1394 if (PCIC_IRQ(xx) &
1395 1395 PCIC_AVAIL_IRQS) {
1396 1396 smi =
1397 1397 pcmcia_get_intr(dip,
1398 1398 xx);
1399 1399 if (smi >= 0)
1400 1400 break;
1401 1401 }
1402 1402 }
1403 1403 }
1404 1404 if (smi >= 0)
1405 1405 pcic->pc_sockets[i].pcs_smi = smi;
1406 1406 }
1407 1407 }
1408 1408 pcic->pc_intr_htblp = kmem_alloc(pcic->pc_numsockets *
1409 1409 sizeof (ddi_intr_handle_t), KM_SLEEP);
1410 1410 for (i = 0, irqlevel = -1; i < pcic->pc_numsockets; i++) {
1411 1411 struct intrspec *ispecp;
1412 1412 struct ddi_parent_private_data *pdp;
1413 1413
1414 1414 if (irqlevel == pcic->pc_sockets[i].pcs_smi)
1415 1415 continue;
1416 1416 else {
1417 1417 irqlevel = pcic->pc_sockets[i].pcs_smi;
1418 1418 }
1419 1419 /*
1420 1420 * now convert the allocated IRQ into an intrspec
1421 1421 * and ask our parent to add it. Don't use
1422 1422 * the ddi_add_intr since we don't have a
1423 1423 * default intrspec in all cases.
1424 1424 *
1425 1425 * note: this sort of violates DDI but we don't
1426 1426 * get hardware intrspecs for many of the devices.
1427 1427 * at the same time, we know how to allocate them
1428 1428 * so we do the right thing.
1429 1429 */
1430 1430 if (ddi_intr_alloc(dip, &pcic->pc_intr_htblp[i],
1431 1431 DDI_INTR_TYPE_FIXED, 0, 1, &actual,
1432 1432 DDI_INTR_ALLOC_NORMAL) != DDI_SUCCESS) {
1433 1433 cmn_err(CE_WARN, "%s: ddi_intr_alloc failed",
1434 1434 ddi_get_name(dip));
1435 1435 goto isa_exit1;
1436 1436 }
1437 1437
1438 1438 /*
1439 1439 * See earlier note:
1440 1440 * Since some devices don't have 'intrspec'
1441 1441 * we make one up in rootnex.
1442 1442 *
1443 1443 * However, it is not properly initialized as
1444 1444 * the data it needs is present in this driver
1445 1445 * and there is no interface to pass that up.
1446 1446 * Specially 'irqlevel' is very important and
1447 1447 * it is part of pcic struct.
1448 1448 *
1449 1449 * Set 'intrspec' up here; otherwise adding the
1450 1450 * interrupt will fail.
1451 1451 */
1452 1452 pdp = ddi_get_parent_data(dip);
1453 1453 ispecp = (struct intrspec *)&pdp->par_intr[0];
1454 1454 ispecp->intrspec_vec = irqlevel;
1455 1455 ispecp->intrspec_pri = pcic->pc_irq;
1456 1456
1457 1457 /* Stay compatible w/ PCMCIA */
1458 1458 pcic->pc_pri = (ddi_iblock_cookie_t)
1459 1459 (uintptr_t)pcic->pc_irq;
1460 1460 pcic->pc_dcookie.idev_priority =
1461 1461 (uintptr_t)pcic->pc_pri;
1462 1462 pcic->pc_dcookie.idev_vector = (ushort_t)irqlevel;
1463 1463
1464 1464 (void) ddi_intr_set_pri(pcic->pc_intr_htblp[i],
1465 1465 pcic->pc_irq);
1466 1466
1467 1467 if (i == 0) {
1468 1468 mutex_init(&pcic->intr_lock, NULL, MUTEX_DRIVER,
1469 1469 DDI_INTR_PRI(pcic->pc_irq));
1470 1470 mutex_init(&pcic->pc_lock, NULL, MUTEX_DRIVER,
1471 1471 NULL);
1472 1472 }
1473 1473
1474 1474 if (ddi_intr_add_handler(pcic->pc_intr_htblp[i],
1475 1475 pcic_intr, (caddr_t)pcic, NULL)) {
1476 1476 cmn_err(CE_WARN,
1477 1477 "%s: ddi_intr_add_handler failed",
1478 1478 ddi_get_name(dip));
1479 1479 goto isa_exit2;
1480 1480 }
1481 1481
1482 1482 if (ddi_intr_enable(pcic->pc_intr_htblp[i])) {
1483 1483 cmn_err(CE_WARN, "%s: ddi_intr_enable failed",
1484 1484 ddi_get_name(dip));
1485 1485 for (j = i; j < 0; j--)
1486 1486 (void) ddi_intr_remove_handler(
1487 1487 pcic->pc_intr_htblp[j]);
1488 1488 goto isa_exit2;
1489 1489 }
1490 1490 }
1491 1491 break;
1492 1492 case PCIC_INTR_MODE_PCI_1:
1493 1493 case PCIC_INTR_MODE_PCI:
1494 1494 /*
1495 1495 * If we're on a PCI bus, we route all interrupts, both SMI
1496 1496 * and IO interrupts, through a single interrupt line.
1497 1497 * Assign the SMI IRQ level to the IO IRQ level here.
1498 1498 */
1499 1499 pcic->pc_pci_intr_hdlp = kmem_alloc(sizeof (ddi_intr_handle_t),
1500 1500 KM_SLEEP);
1501 1501 if (ddi_intr_alloc(dip, pcic->pc_pci_intr_hdlp,
1502 1502 DDI_INTR_TYPE_FIXED, 0, 1, &actual,
1503 1503 DDI_INTR_ALLOC_NORMAL) != DDI_SUCCESS)
1504 1504 goto pci_exit1;
1505 1505
1506 1506 if (ddi_intr_get_pri(pcic->pc_pci_intr_hdlp[0],
1507 1507 &pri) != DDI_SUCCESS) {
1508 1508 (void) ddi_intr_free(pcic->pc_pci_intr_hdlp[0]);
1509 1509 goto pci_exit1;
1510 1510 }
1511 1511
1512 1512 pcic->pc_pri = (void *)(uintptr_t)pri;
1513 1513 mutex_init(&pcic->intr_lock, NULL, MUTEX_DRIVER, pcic->pc_pri);
1514 1514 mutex_init(&pcic->pc_lock, NULL, MUTEX_DRIVER, NULL);
1515 1515
1516 1516 if (ddi_intr_add_handler(pcic->pc_pci_intr_hdlp[0],
1517 1517 pcic_intr, (caddr_t)pcic, NULL))
1518 1518 goto pci_exit2;
1519 1519
1520 1520 if (ddi_intr_enable(pcic->pc_pci_intr_hdlp[0])) {
1521 1521 (void) ddi_intr_remove_handler(
1522 1522 pcic->pc_pci_intr_hdlp[0]);
1523 1523 goto pci_exit2;
1524 1524 }
1525 1525
1526 1526 /* Stay compatible w/ PCMCIA */
1527 1527 pcic->pc_dcookie.idev_priority = (ushort_t)pri;
1528 1528
1529 1529 /* init to same (PCI) so share is easy */
1530 1530 for (i = 0; i < pcic->pc_numsockets; i++)
1531 1531 pcic->pc_sockets[i].pcs_smi = 0xF; /* any valid */
1532 1532 break;
1533 1533 }
1534 1534
1535 1535 /*
1536 1536 * Setup the adapter hardware to some reasonable defaults.
1537 1537 */
1538 1538 mutex_enter(&pcic->pc_lock);
1539 1539 /* mark the driver state as attached */
1540 1540 pcic->pc_flags |= PCF_ATTACHED;
1541 1541 pcic_setup_adapter(pcic);
1542 1542
1543 1543 for (j = 0; j < pcic->pc_numsockets; j++)
1544 1544 if (ddi_intr_add_softint(dip,
1545 1545 &pcic->pc_sockets[j].pcs_cd_softint_hdl,
1546 1546 PCIC_SOFTINT_PRI_VAL, pcic_cd_softint,
1547 1547 (caddr_t)&pcic->pc_sockets[j]) != DDI_SUCCESS)
1548 1548 goto pci_exit2;
1549 1549
1550 1550 #if defined(PCIC_DEBUG)
1551 1551 if (pcic_debug)
1552 1552 cmn_err(CE_CONT, "type = %s sockets = %d\n", typename,
1553 1553 pcic->pc_numsockets);
1554 1554 #endif
1555 1555
1556 1556 pcic_nexus->an_iblock = &pcic->pc_pri;
1557 1557 pcic_nexus->an_idev = &pcic->pc_dcookie;
1558 1558
1559 1559 mutex_exit(&pcic->pc_lock);
1560 1560
1561 1561 #ifdef CARDBUS
1562 1562 (void) cardbus_enable_cd_intr(dip);
1563 1563 if (pcic_debug) {
1564 1564
1565 1565 cardbus_dump_pci_config(dip);
1566 1566 cardbus_dump_socket(dip);
1567 1567 }
1568 1568
1569 1569 /*
1570 1570 * Give the Cardbus misc module a chance to do it's per-adapter
1571 1571 * instance setup. Note that there is no corresponding detach()
1572 1572 * call.
1573 1573 */
1574 1574 if (pcic->pc_flags & PCF_CARDBUS)
1575 1575 if (cardbus_attach(dip, &pcic_cbnexus_ops) != DDI_SUCCESS) {
1576 1576 cmn_err(CE_CONT,
1577 1577 "pcic_attach: cardbus_attach failed\n");
1578 1578 goto pci_exit2;
1579 1579 }
1580 1580 #endif
1581 1581
1582 1582 /*
1583 1583 * Give the PCMCIA misc module a chance to do it's per-adapter
1584 1584 * instance setup.
1585 1585 */
1586 1586 if ((i = pcmcia_attach(dip, pcic_nexus)) != DDI_SUCCESS)
1587 1587 goto pci_exit2;
1588 1588
1589 1589 if (pcic_maxinst == -1) {
1590 1590 /* This assumes that all instances run at the same IPL. */
1591 1591 mutex_init(&pcic_deb_mtx, NULL, MUTEX_DRIVER, NULL);
1592 1592 cv_init(&pcic_deb_cv, NULL, CV_DRIVER, NULL);
1593 1593 pcic_deb_threadid = thread_create((caddr_t)NULL, 0,
1594 1594 pcic_deb_thread, (caddr_t)NULL, 0, &p0, TS_RUN,
1595 1595 v.v_maxsyspri - 2);
1596 1596 }
1597 1597 pcic_maxinst = max(pcic_maxinst, ddi_get_instance(dip));
1598 1598 /*
1599 1599 * Setup a debounce timeout to do an initial card detect
1600 1600 * and enable interrupts.
1601 1601 */
1602 1602 for (j = 0; j < pcic->pc_numsockets; j++) {
1603 1603 pcic->pc_sockets[j].pcs_debounce_id =
1604 1604 pcic_add_debqueue(&pcic->pc_sockets[j],
1605 1605 drv_usectohz(pcic_debounce_time));
1606 1606 }
1607 1607
1608 1608 return (i);
1609 1609
1610 1610 isa_exit2:
1611 1611 mutex_destroy(&pcic->intr_lock);
1612 1612 mutex_destroy(&pcic->pc_lock);
1613 1613 for (j = i; j < 0; j--)
1614 1614 (void) ddi_intr_free(pcic->pc_intr_htblp[j]);
1615 1615 isa_exit1:
1616 1616 (void) pcmcia_return_intr(dip, pcic->pc_sockets[i].pcs_smi);
1617 1617 ddi_regs_map_free(&pcic->handle);
1618 1618 if (pcic->pc_flags & PCF_PCIBUS)
1619 1619 ddi_regs_map_free(&pcic->cfg_handle);
1620 1620 kmem_free(pcic->pc_intr_htblp, pcic->pc_numsockets *
1621 1621 sizeof (ddi_intr_handle_t));
1622 1622 kmem_free(pcic, sizeof (pcicdev_t));
1623 1623 return (DDI_FAILURE);
1624 1624
1625 1625 pci_exit2:
1626 1626 mutex_destroy(&pcic->intr_lock);
1627 1627 mutex_destroy(&pcic->pc_lock);
1628 1628 (void) ddi_intr_free(pcic->pc_pci_intr_hdlp[0]);
1629 1629 pci_exit1:
1630 1630 ddi_regs_map_free(&pcic->handle);
1631 1631 if (pcic->pc_flags & PCF_PCIBUS)
1632 1632 ddi_regs_map_free(&pcic->cfg_handle);
1633 1633 kmem_free(pcic->pc_pci_intr_hdlp, sizeof (ddi_intr_handle_t));
1634 1634 kmem_free(pcic, sizeof (pcicdev_t));
1635 1635 return (DDI_FAILURE);
1636 1636 }
1637 1637
1638 1638 /*
1639 1639 * pcic_detach()
1640 1640 * request to detach from the system
1641 1641 */
1642 1642 static int
1643 1643 pcic_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
1644 1644 {
1645 1645 anp_t *anp = ddi_get_driver_private(dip);
1646 1646 pcicdev_t *pcic = anp->an_private;
1647 1647 int i;
1648 1648
1649 1649 switch (cmd) {
1650 1650 case DDI_DETACH:
1651 1651 /* don't detach if the nexus still talks to us */
1652 1652 if (pcic->pc_callback != NULL)
1653 1653 return (DDI_FAILURE);
1654 1654
1655 1655 /* kill off the pm simulation */
1656 1656 if (pcic->pc_pmtimer)
1657 1657 (void) untimeout(pcic->pc_pmtimer);
1658 1658
1659 1659 /* turn everything off for all sockets and chips */
1660 1660 for (i = 0; i < pcic->pc_numsockets; i++) {
1661 1661 if (pcic->pc_sockets[i].pcs_debounce_id)
1662 1662 pcic_rm_debqueue(
1663 1663 pcic->pc_sockets[i].pcs_debounce_id);
1664 1664 pcic->pc_sockets[i].pcs_debounce_id = 0;
1665 1665
1666 1666 pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 0);
1667 1667 pcic_putb(pcic, i, PCIC_CARD_DETECT, 0);
1668 1668 pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
1669 1669 /* disable interrupts and put card into RESET */
1670 1670 pcic_putb(pcic, i, PCIC_INTERRUPT, 0);
1671 1671 }
1672 1672 (void) ddi_intr_disable(pcic->pc_pci_intr_hdlp[0]);
1673 1673 (void) ddi_intr_remove_handler(pcic->pc_pci_intr_hdlp[0]);
1674 1674 (void) ddi_intr_free(pcic->pc_pci_intr_hdlp[0]);
1675 1675 kmem_free(pcic->pc_pci_intr_hdlp, sizeof (ddi_intr_handle_t));
1676 1676 pcic->pc_flags = 0;
1677 1677 mutex_destroy(&pcic->pc_lock);
1678 1678 mutex_destroy(&pcic->intr_lock);
1679 1679 cv_destroy(&pcic->pm_cv);
1680 1680 if (pcic->pc_flags & PCF_PCIBUS)
1681 1681 ddi_regs_map_free(&pcic->cfg_handle);
1682 1682 if (pcic->handle)
1683 1683 ddi_regs_map_free(&pcic->handle);
1684 1684 kmem_free(pcic, sizeof (pcicdev_t));
1685 1685 ddi_soft_state_free(pcic_soft_state_p, ddi_get_instance(dip));
1686 1686 return (DDI_SUCCESS);
1687 1687
1688 1688 case DDI_SUSPEND:
1689 1689 case DDI_PM_SUSPEND:
1690 1690 /*
1691 1691 * we got a suspend event (either real or imagined)
1692 1692 * so notify the nexus proper that all existing cards
1693 1693 * should go away.
1694 1694 */
1695 1695 mutex_enter(&pcic->pc_lock);
1696 1696 #ifdef CARDBUS
1697 1697 if (pcic->pc_flags & PCF_CARDBUS) {
1698 1698 for (i = 0; i < pcic->pc_numsockets; i++) {
1699 1699 if ((pcic->pc_sockets[i].pcs_flags &
1700 1700 (PCS_CARD_PRESENT|PCS_CARD_ISCARDBUS)) ==
1701 1701 (PCS_CARD_PRESENT|PCS_CARD_ISCARDBUS)) {
1702 1702
1703 1703 pcmcia_cb_suspended(
1704 1704 pcic->pc_sockets[i].pcs_socket);
1705 1705 }
1706 1706 }
1707 1707
1708 1708 cardbus_save_children(ddi_get_child(dip));
1709 1709 }
1710 1710 #endif
1711 1711 /* turn everything off for all sockets and chips */
1712 1712 for (i = 0; i < pcic->pc_numsockets; i++) {
1713 1713 if (pcic->pc_sockets[i].pcs_debounce_id)
1714 1714 pcic_rm_debqueue(
1715 1715 pcic->pc_sockets[i].pcs_debounce_id);
1716 1716 pcic->pc_sockets[i].pcs_debounce_id = 0;
1717 1717
1718 1718 pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 0);
1719 1719 pcic_putb(pcic, i, PCIC_CARD_DETECT, 0);
1720 1720 pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
1721 1721 /* disable interrupts and put card into RESET */
1722 1722 pcic_putb(pcic, i, PCIC_INTERRUPT, 0);
1723 1723 pcic_putb(pcic, i, PCIC_POWER_CONTROL, 0);
1724 1724 if (pcic->pc_flags & PCF_CBPWRCTL)
1725 1725 pcic_putcb(pcic, CB_CONTROL, 0);
1726 1726
1727 1727 if (pcic->pc_sockets[i].pcs_flags & PCS_CARD_PRESENT) {
1728 1728 pcic->pc_sockets[i].pcs_flags = PCS_STARTING;
1729 1729 /*
1730 1730 * Because we are half way through a save
1731 1731 * all this does is schedule a removal event
1732 1732 * to cs for when the system comes back.
1733 1733 * This doesn't actually matter.
1734 1734 */
1735 1735 if (!pcic_do_pcmcia_sr && pcic_do_removal &&
1736 1736 pcic->pc_callback) {
1737 1737 PC_CALLBACK(pcic->dip, pcic->pc_cb_arg,
1738 1738 PCE_CARD_REMOVAL,
1739 1739 pcic->pc_sockets[i].pcs_socket);
1740 1740 }
1741 1741 }
1742 1742 }
1743 1743
1744 1744 pcic->pc_flags |= PCF_SUSPENDED;
1745 1745 mutex_exit(&pcic->pc_lock);
1746 1746
1747 1747 /*
1748 1748 * when true power management exists, save the adapter
1749 1749 * state here to enable a recovery. For the emulation
1750 1750 * condition, the state is gone
1751 1751 */
1752 1752 return (DDI_SUCCESS);
1753 1753
1754 1754 default:
1755 1755 return (EINVAL);
1756 1756 }
1757 1757 }
1758 1758
1759 1759 static uint32_t pcic_tisysctl_onbits = ((1<<27) | (1<<15) | (1<<14));
1760 1760 static uint32_t pcic_tisysctl_offbits = 0;
1761 1761 static uint32_t pcic_default_latency = 0x40;
1762 1762
1763 1763 static void
1764 1764 pcic_setup_adapter(pcicdev_t *pcic)
1765 1765 {
1766 1766 int i;
1767 1767 int value, flags;
1768 1768
1769 1769 #if defined(__i386) || defined(__amd64)
1770 1770 pci_regspec_t *reg;
1771 1771 uchar_t bus, dev, func;
1772 1772 uint_t classcode;
1773 1773 int length;
1774 1774 #endif
1775 1775
1776 1776 if (pcic->pc_flags & PCF_PCIBUS) {
1777 1777 /*
1778 1778 * all PCI-to-PCMCIA bus bridges need memory and I/O enabled
1779 1779 */
1780 1780 flags = (PCIC_ENABLE_IO | PCIC_ENABLE_MEM);
1781 1781 pcic_iomem_pci_ctl(pcic->cfg_handle, pcic->cfgaddr, flags);
1782 1782 }
1783 1783 /* enable each socket */
1784 1784 for (i = 0; i < pcic->pc_numsockets; i++) {
1785 1785 pcic->pc_sockets[i].pcs_flags = 0;
1786 1786 /* find out the socket capabilities (I/O vs memory) */
1787 1787 value = pcic_getb(pcic, i,
1788 1788 PCIC_CHIP_REVISION) & PCIC_REV_ID_MASK;
1789 1789 if (value == PCIC_REV_ID_IO || value == PCIC_REV_ID_BOTH)
1790 1790 pcic->pc_sockets[i].pcs_flags |= PCS_SOCKET_IO;
1791 1791
1792 1792 /* disable all windows just in case */
1793 1793 pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
1794 1794
1795 1795 switch (pcic->pc_type) {
1796 1796 uint32_t cfg32;
1797 1797 uint16_t cfg16;
1798 1798 uint8_t cfg;
1799 1799
1800 1800 /* enable extended registers for Vadem */
1801 1801 case PCIC_VADEM_VG469:
1802 1802 case PCIC_VADEM:
1803 1803
1804 1804 /* enable card status change interrupt for socket */
1805 1805 break;
1806 1806
1807 1807 case PCIC_I82365SL:
1808 1808 break;
1809 1809
1810 1810 case PCIC_CL_PD6710:
1811 1811 pcic_putb(pcic, 0, PCIC_MISC_CTL_2, PCIC_LED_ENABLE);
1812 1812 break;
1813 1813
1814 1814 /*
1815 1815 * On the CL_6730, we need to set up the interrupt
1816 1816 * signalling mode (PCI mode) and set the SMI and
1817 1817 * IRQ interrupt lines to PCI/level-mode.
1818 1818 */
1819 1819 case PCIC_CL_PD6730:
1820 1820 switch (pcic->pc_intr_mode) {
1821 1821 case PCIC_INTR_MODE_PCI_1:
1822 1822 clext_reg_write(pcic, i, PCIC_CLEXT_MISC_CTL_3,
1823 1823 ((clext_reg_read(pcic, i,
1824 1824 PCIC_CLEXT_MISC_CTL_3) &
1825 1825 ~PCIC_CLEXT_INT_PCI) |
1826 1826 PCIC_CLEXT_INT_PCI));
1827 1827 clext_reg_write(pcic, i, PCIC_CLEXT_EXT_CTL_1,
1828 1828 (PCIC_CLEXT_IRQ_LVL_MODE |
1829 1829 PCIC_CLEXT_SMI_LVL_MODE));
1830 1830 cfg = PCIC_CL_LP_DYN_MODE;
1831 1831 pcic_putb(pcic, i, PCIC_MISC_CTL_2, cfg);
1832 1832 break;
1833 1833 case PCIC_INTR_MODE_ISA:
1834 1834 break;
1835 1835 }
1836 1836 break;
1837 1837 /*
1838 1838 * On the CL_6729, we set the SMI and IRQ interrupt
1839 1839 * lines to PCI/level-mode. as well as program the
1840 1840 * correct clock speed divider bit.
1841 1841 */
1842 1842 case PCIC_CL_PD6729:
1843 1843 switch (pcic->pc_intr_mode) {
1844 1844 case PCIC_INTR_MODE_PCI_1:
1845 1845 clext_reg_write(pcic, i, PCIC_CLEXT_EXT_CTL_1,
1846 1846 (PCIC_CLEXT_IRQ_LVL_MODE |
1847 1847 PCIC_CLEXT_SMI_LVL_MODE));
1848 1848
1849 1849 break;
1850 1850 case PCIC_INTR_MODE_ISA:
1851 1851 break;
1852 1852 }
1853 1853 if (pcic->bus_speed > PCIC_PCI_25MHZ && i == 0) {
1854 1854 cfg = 0;
1855 1855 cfg |= PCIC_CL_TIMER_CLK_DIV;
1856 1856 pcic_putb(pcic, i, PCIC_MISC_CTL_2, cfg);
1857 1857 }
1858 1858 break;
1859 1859 case PCIC_INTEL_i82092:
1860 1860 cfg = PCIC_82092_EN_TIMING;
1861 1861 if (pcic->bus_speed < PCIC_SYSCLK_33MHZ)
1862 1862 cfg |= PCIC_82092_PCICLK_25MHZ;
1863 1863 ddi_put8(pcic->cfg_handle, pcic->cfgaddr +
1864 1864 PCIC_82092_PCICON, cfg);
1865 1865 break;
1866 1866 case PCIC_TI_PCI1130:
1867 1867 case PCIC_TI_PCI1131:
1868 1868 case PCIC_TI_PCI1250:
1869 1869 case PCIC_TI_PCI1031:
1870 1870 cfg = ddi_get8(pcic->cfg_handle,
1871 1871 pcic->cfgaddr + PCIC_DEVCTL_REG);
1872 1872 cfg &= ~PCIC_DEVCTL_INTR_MASK;
1873 1873 switch (pcic->pc_intr_mode) {
1874 1874 case PCIC_INTR_MODE_ISA:
1875 1875 cfg |= PCIC_DEVCTL_INTR_ISA;
1876 1876 break;
1877 1877 }
1878 1878 #ifdef PCIC_DEBUG
1879 1879 if (pcic_debug) {
1880 1880 cmn_err(CE_CONT, "pcic_setup_adapter: "
1881 1881 "write reg 0x%x=%x \n",
1882 1882 PCIC_DEVCTL_REG, cfg);
1883 1883 }
1884 1884 #endif
1885 1885 ddi_put8(pcic->cfg_handle,
1886 1886 pcic->cfgaddr + PCIC_DEVCTL_REG,
1887 1887 cfg);
1888 1888
1889 1889 cfg = ddi_get8(pcic->cfg_handle,
1890 1890 pcic->cfgaddr + PCIC_CRDCTL_REG);
1891 1891 cfg &= ~(PCIC_CRDCTL_PCIINTR|PCIC_CRDCTL_PCICSC|
1892 1892 PCIC_CRDCTL_PCIFUNC);
1893 1893 switch (pcic->pc_intr_mode) {
1894 1894 case PCIC_INTR_MODE_PCI_1:
1895 1895 cfg |= PCIC_CRDCTL_PCIINTR |
1896 1896 PCIC_CRDCTL_PCICSC |
1897 1897 PCIC_CRDCTL_PCIFUNC;
1898 1898 pcic->pc_flags |= PCF_USE_SMI;
1899 1899 break;
1900 1900 }
1901 1901 #ifdef PCIC_DEBUG
1902 1902 if (pcic_debug) {
1903 1903 cmn_err(CE_CONT, "pcic_setup_adapter: "
1904 1904 " write reg 0x%x=%x \n",
1905 1905 PCIC_CRDCTL_REG, cfg);
1906 1906 }
1907 1907 #endif
1908 1908 ddi_put8(pcic->cfg_handle,
1909 1909 pcic->cfgaddr + PCIC_CRDCTL_REG,
1910 1910 cfg);
1911 1911 break;
1912 1912 case PCIC_TI_PCI1221:
1913 1913 case PCIC_TI_PCI1225:
1914 1914 cfg = ddi_get8(pcic->cfg_handle,
1915 1915 pcic->cfgaddr + PCIC_DEVCTL_REG);
1916 1916 cfg |= (PCIC_DEVCTL_INTR_DFLT | PCIC_DEVCTL_3VCAPABLE);
1917 1917 #ifdef PCIC_DEBUG
1918 1918 if (pcic_debug) {
1919 1919 cmn_err(CE_CONT, "pcic_setup_adapter: "
1920 1920 " write reg 0x%x=%x \n",
1921 1921 PCIC_DEVCTL_REG, cfg);
1922 1922 }
1923 1923 #endif
1924 1924 ddi_put8(pcic->cfg_handle,
1925 1925 pcic->cfgaddr + PCIC_DEVCTL_REG, cfg);
1926 1926
1927 1927 cfg = ddi_get8(pcic->cfg_handle,
1928 1928 pcic->cfgaddr + PCIC_DIAG_REG);
1929 1929 if (pcic->pc_type == PCIC_TI_PCI1225) {
1930 1930 cfg |= (PCIC_DIAG_CSC | PCIC_DIAG_ASYNC);
1931 1931 } else {
1932 1932 cfg |= PCIC_DIAG_ASYNC;
1933 1933 }
1934 1934 pcic->pc_flags |= PCF_USE_SMI;
1935 1935 #ifdef PCIC_DEBUG
1936 1936 if (pcic_debug) {
1937 1937 cmn_err(CE_CONT, "pcic_setup_adapter: "
1938 1938 " write reg 0x%x=%x \n",
1939 1939 PCIC_DIAG_REG, cfg);
1940 1940 }
1941 1941 #endif
1942 1942 ddi_put8(pcic->cfg_handle,
1943 1943 pcic->cfgaddr + PCIC_DIAG_REG, cfg);
1944 1944 break;
1945 1945 case PCIC_TI_PCI1520:
1946 1946 case PCIC_TI_PCI1510:
1947 1947 case PCIC_TI_VENDOR:
1948 1948 if (pcic->pc_intr_mode == PCIC_INTR_MODE_ISA) {
1949 1949 /* functional intr routed by ExCA register */
1950 1950 cfg = ddi_get8(pcic->cfg_handle,
1951 1951 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
1952 1952 cfg |= PCIC_FUN_INT_MOD_ISA;
1953 1953 ddi_put8(pcic->cfg_handle,
1954 1954 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
1955 1955 cfg);
1956 1956
1957 1957 /* IRQ serialized interrupts */
1958 1958 cfg = ddi_get8(pcic->cfg_handle,
1959 1959 pcic->cfgaddr + PCIC_DEVCTL_REG);
1960 1960 cfg &= ~PCIC_DEVCTL_INTR_MASK;
1961 1961 cfg |= PCIC_DEVCTL_INTR_ISA;
1962 1962 ddi_put8(pcic->cfg_handle,
1963 1963 pcic->cfgaddr + PCIC_DEVCTL_REG,
1964 1964 cfg);
1965 1965 break;
1966 1966 }
1967 1967
1968 1968 /* CSC interrupt routed to PCI */
1969 1969 cfg = ddi_get8(pcic->cfg_handle,
1970 1970 pcic->cfgaddr + PCIC_DIAG_REG);
1971 1971 cfg |= (PCIC_DIAG_CSC | PCIC_DIAG_ASYNC);
1972 1972 ddi_put8(pcic->cfg_handle,
1973 1973 pcic->cfgaddr + PCIC_DIAG_REG, cfg);
1974 1974
1975 1975 #if defined(__i386) || defined(__amd64)
1976 1976 /*
1977 1977 * Some TI chips have 2 cardbus slots(function0 and
1978 1978 * function1), and others may have just 1 cardbus slot.
1979 1979 * The interrupt routing register is shared between the
1980 1980 * 2 functions and can only be accessed through
1981 1981 * function0. Here we check the presence of the second
1982 1982 * cardbus slot and do the right thing.
1983 1983 */
1984 1984
1985 1985 if (ddi_getlongprop(DDI_DEV_T_ANY, pcic->dip,
1986 1986 DDI_PROP_DONTPASS, "reg", (caddr_t)®,
1987 1987 &length) != DDI_PROP_SUCCESS) {
1988 1988 cmn_err(CE_WARN,
1989 1989 "pcic_setup_adapter(), failed to"
1990 1990 " read reg property\n");
1991 1991 break;
1992 1992 }
1993 1993
1994 1994 bus = PCI_REG_BUS_G(reg->pci_phys_hi);
1995 1995 dev = PCI_REG_DEV_G(reg->pci_phys_hi);
1996 1996 func = PCI_REG_FUNC_G(reg->pci_phys_hi);
1997 1997 kmem_free((caddr_t)reg, length);
1998 1998
1999 1999 if (func != 0) {
2000 2000 break;
2001 2001 }
2002 2002
2003 2003 classcode = (*pci_getl_func)(bus, dev, 1,
2004 2004 PCI_CONF_REVID);
2005 2005 classcode >>= 8;
2006 2006 if (classcode != 0x060700 &&
2007 2007 classcode != 0x060500) {
2008 2008 break;
2009 2009 }
2010 2010
2011 2011 /* Parallel PCI interrupts only */
2012 2012 cfg = ddi_get8(pcic->cfg_handle,
2013 2013 pcic->cfgaddr + PCIC_DEVCTL_REG);
2014 2014 cfg &= ~PCIC_DEVCTL_INTR_MASK;
2015 2015 ddi_put8(pcic->cfg_handle,
2016 2016 pcic->cfgaddr + PCIC_DEVCTL_REG,
2017 2017 cfg);
2018 2018
2019 2019 /* tie INTA and INTB together */
2020 2020 cfg = ddi_get8(pcic->cfg_handle,
2021 2021 (pcic->cfgaddr + PCIC_SYSCTL_REG + 3));
2022 2022 cfg |= PCIC_SYSCTL_INTRTIE;
2023 2023 ddi_put8(pcic->cfg_handle, (pcic->cfgaddr +
2024 2024 PCIC_SYSCTL_REG + 3), cfg);
2025 2025 #endif
2026 2026
2027 2027 break;
2028 2028 case PCIC_TI_PCI1410:
2029 2029 cfg = ddi_get8(pcic->cfg_handle,
2030 2030 pcic->cfgaddr + PCIC_DIAG_REG);
2031 2031 cfg |= (PCIC_DIAG_CSC | PCIC_DIAG_ASYNC);
2032 2032 ddi_put8(pcic->cfg_handle,
2033 2033 pcic->cfgaddr + PCIC_DIAG_REG, cfg);
2034 2034 break;
2035 2035 case PCIC_TOSHIBA_TOPIC100:
2036 2036 case PCIC_TOSHIBA_TOPIC95:
2037 2037 case PCIC_TOSHIBA_VENDOR:
2038 2038 cfg = ddi_get8(pcic->cfg_handle, pcic->cfgaddr +
2039 2039 PCIC_TOSHIBA_SLOT_CTL_REG);
2040 2040 cfg |= (PCIC_TOSHIBA_SCR_SLOTON |
2041 2041 PCIC_TOSHIBA_SCR_SLOTEN);
2042 2042 cfg &= (~PCIC_TOSHIBA_SCR_PRT_MASK);
2043 2043 cfg |= PCIC_TOSHIBA_SCR_PRT_3E2;
2044 2044 ddi_put8(pcic->cfg_handle, pcic->cfgaddr +
2045 2045 PCIC_TOSHIBA_SLOT_CTL_REG, cfg);
2046 2046 cfg = ddi_get8(pcic->cfg_handle, pcic->cfgaddr +
2047 2047 PCIC_TOSHIBA_INTR_CTL_REG);
2048 2048 switch (pcic->pc_intr_mode) {
2049 2049 case PCIC_INTR_MODE_ISA:
2050 2050 cfg &= ~PCIC_TOSHIBA_ICR_SRC;
2051 2051 ddi_put8(pcic->cfg_handle,
2052 2052 pcic->cfgaddr +
2053 2053 PCIC_TOSHIBA_INTR_CTL_REG, cfg);
2054 2054
2055 2055 cfg = ddi_get8(pcic->cfg_handle,
2056 2056 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
2057 2057 cfg |= PCIC_FUN_INT_MOD_ISA;
2058 2058 ddi_put8(pcic->cfg_handle,
2059 2059 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
2060 2060 cfg);
2061 2061 break;
2062 2062 case PCIC_INTR_MODE_PCI_1:
2063 2063 cfg |= PCIC_TOSHIBA_ICR_SRC;
2064 2064 cfg &= (~PCIC_TOSHIBA_ICR_PIN_MASK);
2065 2065 cfg |= PCIC_TOSHIBA_ICR_PIN_INTA;
2066 2066 ddi_put8(pcic->cfg_handle,
2067 2067 pcic->cfgaddr +
2068 2068 PCIC_TOSHIBA_INTR_CTL_REG, cfg);
2069 2069 break;
2070 2070 }
2071 2071 break;
2072 2072 case PCIC_O2MICRO_VENDOR:
2073 2073 cfg32 = ddi_get32(pcic->cfg_handle,
2074 2074 (uint32_t *)(pcic->cfgaddr +
2075 2075 PCIC_O2MICRO_MISC_CTL));
2076 2076 switch (pcic->pc_intr_mode) {
2077 2077 case PCIC_INTR_MODE_ISA:
2078 2078 cfg32 |= (PCIC_O2MICRO_ISA_LEGACY |
2079 2079 PCIC_O2MICRO_INT_MOD_PCI);
2080 2080 ddi_put32(pcic->cfg_handle,
2081 2081 (uint32_t *)(pcic->cfgaddr +
2082 2082 PCIC_O2MICRO_MISC_CTL),
2083 2083 cfg32);
2084 2084 cfg = ddi_get8(pcic->cfg_handle,
2085 2085 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
2086 2086 cfg |= PCIC_FUN_INT_MOD_ISA;
2087 2087 ddi_put8(pcic->cfg_handle,
2088 2088 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
2089 2089 cfg);
2090 2090 break;
2091 2091 case PCIC_INTR_MODE_PCI_1:
2092 2092 cfg32 &= ~PCIC_O2MICRO_ISA_LEGACY;
2093 2093 cfg32 |= PCIC_O2MICRO_INT_MOD_PCI;
2094 2094 ddi_put32(pcic->cfg_handle,
2095 2095 (uint32_t *)(pcic->cfgaddr +
2096 2096 PCIC_O2MICRO_MISC_CTL),
2097 2097 cfg32);
2098 2098 break;
2099 2099 }
2100 2100 break;
2101 2101 case PCIC_RICOH_VENDOR:
2102 2102 if (pcic->pc_intr_mode == PCIC_INTR_MODE_ISA) {
2103 2103 cfg16 = ddi_get16(pcic->cfg_handle,
2104 2104 (uint16_t *)(pcic->cfgaddr +
2105 2105 PCIC_RICOH_MISC_CTL_2));
2106 2106 cfg16 |= (PCIC_RICOH_CSC_INT_MOD |
2107 2107 PCIC_RICOH_FUN_INT_MOD);
2108 2108 ddi_put16(pcic->cfg_handle,
2109 2109 (uint16_t *)(pcic->cfgaddr +
2110 2110 PCIC_RICOH_MISC_CTL_2),
2111 2111 cfg16);
2112 2112
2113 2113 cfg16 = ddi_get16(pcic->cfg_handle,
2114 2114 (uint16_t *)(pcic->cfgaddr +
2115 2115 PCIC_RICOH_MISC_CTL));
2116 2116 cfg16 |= PCIC_RICOH_SIRQ_EN;
2117 2117 ddi_put16(pcic->cfg_handle,
2118 2118 (uint16_t *)(pcic->cfgaddr +
2119 2119 PCIC_RICOH_MISC_CTL),
2120 2120 cfg16);
2121 2121
2122 2122 cfg = ddi_get8(pcic->cfg_handle,
2123 2123 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
2124 2124 cfg |= PCIC_FUN_INT_MOD_ISA;
2125 2125 ddi_put8(pcic->cfg_handle,
2126 2126 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
2127 2127 cfg);
2128 2128 }
2129 2129 break;
2130 2130 default:
2131 2131 break;
2132 2132 } /* switch */
2133 2133
2134 2134 /*
2135 2135 * The default value in the EEPROM (loaded on reset) for
2136 2136 * MFUNC0/MFUNC1 may be incorrect. Here we make sure that
2137 2137 * MFUNC0 is connected to INTA, and MFUNC1 is connected to
2138 2138 * INTB. This applies to all TI CardBus controllers.
2139 2139 */
2140 2140 if ((pcic->pc_type >> 16) == PCIC_TI_VENDORID &&
2141 2141 pcic->pc_intr_mode == PCIC_INTR_MODE_PCI_1) {
2142 2142 value = ddi_get32(pcic->cfg_handle,
2143 2143 (uint32_t *)(pcic->cfgaddr + PCIC_MFROUTE_REG));
2144 2144 value &= ~0xff;
2145 2145 ddi_put32(pcic->cfg_handle, (uint32_t *)(pcic->cfgaddr +
2146 2146 PCIC_MFROUTE_REG), value|PCIC_TI_MFUNC_SEL);
2147 2147 }
2148 2148
2149 2149 /* setup general card status change interrupt */
2150 2150 switch (pcic->pc_type) {
2151 2151 case PCIC_TI_PCI1225:
2152 2152 case PCIC_TI_PCI1221:
2153 2153 case PCIC_TI_PCI1031:
2154 2154 case PCIC_TI_PCI1520:
2155 2155 case PCIC_TI_PCI1410:
2156 2156 pcic_putb(pcic, i, PCIC_MANAGEMENT_INT,
2157 2157 PCIC_CHANGE_DEFAULT);
2158 2158 break;
2159 2159 default:
2160 2160 if (pcic->pc_intr_mode ==
2161 2161 PCIC_INTR_MODE_PCI_1) {
2162 2162 pcic_putb(pcic, i, PCIC_MANAGEMENT_INT,
2163 2163 PCIC_CHANGE_DEFAULT);
2164 2164 break;
2165 2165 } else {
2166 2166 pcic_putb(pcic, i, PCIC_MANAGEMENT_INT,
2167 2167 PCIC_CHANGE_DEFAULT |
2168 2168 (pcic->pc_sockets[i].pcs_smi << 4));
2169 2169 break;
2170 2170 }
2171 2171 }
2172 2172
2173 2173 pcic->pc_flags |= PCF_INTRENAB;
2174 2174
2175 2175 /* take card out of RESET */
2176 2176 pcic_putb(pcic, i, PCIC_INTERRUPT, PCIC_RESET);
2177 2177 /* turn power off and let CS do this */
2178 2178 pcic_putb(pcic, i, PCIC_POWER_CONTROL, 0);
2179 2179
2180 2180 /* final chip specific initialization */
2181 2181 switch (pcic->pc_type) {
2182 2182 case PCIC_VADEM:
2183 2183 pcic_putb(pcic, i, PCIC_VG_CONTROL,
2184 2184 PCIC_VC_DELAYENABLE);
2185 2185 pcic->pc_flags |= PCF_DEBOUNCE;
2186 2186 /* FALLTHROUGH */
2187 2187 case PCIC_I82365SL:
2188 2188 pcic_putb(pcic, i, PCIC_GLOBAL_CONTROL,
2189 2189 PCIC_GC_CSC_WRITE);
2190 2190 /* clear any pending interrupts */
2191 2191 value = pcic_getb(pcic, i, PCIC_CARD_STATUS_CHANGE);
2192 2192 pcic_putb(pcic, i, PCIC_CARD_STATUS_CHANGE, value);
2193 2193 break;
2194 2194 /* The 82092 uses PCI config space to enable interrupts */
2195 2195 case PCIC_INTEL_i82092:
2196 2196 pcic_82092_smiirq_ctl(pcic, i, PCIC_82092_CTL_SMI,
2197 2197 PCIC_82092_INT_ENABLE);
2198 2198 break;
2199 2199 case PCIC_CL_PD6729:
2200 2200 if (pcic->bus_speed >= PCIC_PCI_DEF_SYSCLK && i == 0) {
2201 2201 value = pcic_getb(pcic, i, PCIC_MISC_CTL_2);
2202 2202 pcic_putb(pcic, i, PCIC_MISC_CTL_2,
2203 2203 value | PCIC_CL_TIMER_CLK_DIV);
2204 2204 }
2205 2205 break;
2206 2206 } /* switch */
2207 2207
2208 2208 #if defined(PCIC_DEBUG)
2209 2209 if (pcic_debug)
2210 2210 cmn_err(CE_CONT,
2211 2211 "socket %d value=%x, flags = %x (%s)\n",
2212 2212 i, value, pcic->pc_sockets[i].pcs_flags,
2213 2213 (pcic->pc_sockets[i].pcs_flags &
2214 2214 PCS_CARD_PRESENT) ?
2215 2215 "card present" : "no card");
2216 2216 #endif
2217 2217 }
2218 2218 }
2219 2219
2220 2220 /*
2221 2221 * pcic_intr(caddr_t, caddr_t)
2222 2222 * interrupt handler for the PCIC style adapter
2223 2223 * handles all basic interrupts and also checks
2224 2224 * for status changes and notifies the nexus if
2225 2225 * necessary
2226 2226 *
2227 2227 * On PCI bus adapters, also handles all card
2228 2228 * IO interrupts.
2229 2229 */
2230 2230 /*ARGSUSED*/
2231 2231 uint32_t
2232 2232 pcic_intr(caddr_t arg1, caddr_t arg2)
2233 2233 {
2234 2234 pcicdev_t *pcic = (pcicdev_t *)arg1;
2235 2235 int value = 0, i, ret = DDI_INTR_UNCLAIMED;
2236 2236 uint8_t status;
2237 2237 uint_t io_ints;
2238 2238
2239 2239 #if defined(PCIC_DEBUG)
2240 2240 pcic_err(pcic->dip, 0xf,
2241 2241 "pcic_intr: enter pc_flags=0x%x PCF_ATTACHED=0x%x"
2242 2242 " pc_numsockets=%d \n",
2243 2243 pcic->pc_flags, PCF_ATTACHED, pcic->pc_numsockets);
2244 2244 #endif
2245 2245
2246 2246 if (!(pcic->pc_flags & PCF_ATTACHED))
2247 2247 return (DDI_INTR_UNCLAIMED);
2248 2248
2249 2249 mutex_enter(&pcic->intr_lock);
2250 2250
2251 2251 if (pcic->pc_flags & PCF_SUSPENDED) {
2252 2252 mutex_exit(&pcic->intr_lock);
2253 2253 return (ret);
2254 2254 }
2255 2255
2256 2256 /*
2257 2257 * need to change to only ACK and touch the slot that
2258 2258 * actually caused the interrupt. Currently everything
2259 2259 * is acked
2260 2260 *
2261 2261 * we need to look at all known sockets to determine
2262 2262 * what might have happened, so step through the list
2263 2263 * of them
2264 2264 */
2265 2265
2266 2266 /*
2267 2267 * Set the bitmask for IO interrupts to initially include all sockets
2268 2268 */
2269 2269 io_ints = (1 << pcic->pc_numsockets) - 1;
2270 2270
2271 2271 for (i = 0; i < pcic->pc_numsockets; i++) {
2272 2272 int card_type;
2273 2273 pcic_socket_t *sockp;
2274 2274 int value_cb = 0;
2275 2275
2276 2276 sockp = &pcic->pc_sockets[i];
2277 2277 /* get the socket's I/O addresses */
2278 2278
2279 2279 if (sockp->pcs_flags & PCS_WAITING) {
2280 2280 io_ints &= ~(1 << i);
2281 2281 continue;
2282 2282 }
2283 2283
2284 2284 if (sockp->pcs_flags & PCS_CARD_IO)
2285 2285 card_type = IF_IO;
2286 2286 else
2287 2287 card_type = IF_MEMORY;
2288 2288
2289 2289 if (pcic->pc_io_type == PCIC_IO_TYPE_YENTA)
2290 2290 value_cb = pcic_getcb(pcic, CB_STATUS_EVENT);
2291 2291
2292 2292 value = pcic_change(pcic, i);
2293 2293
2294 2294 if ((value != 0) || (value_cb != 0)) {
2295 2295 int x = pcic->pc_cb_arg;
2296 2296
2297 2297 ret = DDI_INTR_CLAIMED;
2298 2298
2299 2299 #if defined(PCIC_DEBUG)
2300 2300 pcic_err(pcic->dip, 0x9,
2301 2301 "card_type = %d, value_cb = 0x%x\n",
2302 2302 card_type,
2303 2303 value_cb ? value_cb :
2304 2304 pcic_getcb(pcic, CB_STATUS_EVENT));
2305 2305 if (pcic_debug)
2306 2306 cmn_err(CE_CONT,
2307 2307 "\tchange on socket %d (%x)\n", i,
2308 2308 value);
2309 2309 #endif
2310 2310 /* find out what happened */
2311 2311 status = pcic_getb(pcic, i, PCIC_INTERFACE_STATUS);
2312 2312
2313 2313 /* acknowledge the interrupt */
2314 2314 if (value_cb)
2315 2315 pcic_putcb(pcic, CB_STATUS_EVENT, value_cb);
2316 2316
2317 2317 if (value)
2318 2318 pcic_putb(pcic, i, PCIC_CARD_STATUS_CHANGE,
2319 2319 value);
2320 2320
2321 2321 if (pcic->pc_callback == NULL) {
2322 2322 /* if not callback handler, nothing to do */
2323 2323 continue;
2324 2324 }
2325 2325
2326 2326 /* Card Detect */
2327 2327 if (value & PCIC_CD_DETECT ||
2328 2328 value_cb & CB_PS_CCDMASK) {
2329 2329 uint8_t irq;
2330 2330 #if defined(PCIC_DEBUG)
2331 2331 if (pcic_debug)
2332 2332 cmn_err(CE_CONT,
2333 2333 "\tcd_detect: status=%x,"
2334 2334 " flags=%x\n",
2335 2335 status, sockp->pcs_flags);
2336 2336 #else
2337 2337 #ifdef lint
2338 2338 if (status == 0)
2339 2339 status++;
2340 2340 #endif
2341 2341 #endif
2342 2342 /*
2343 2343 * Turn off all interrupts for this socket here.
2344 2344 */
2345 2345 irq = pcic_getb(pcic, sockp->pcs_socket,
2346 2346 PCIC_MANAGEMENT_INT);
2347 2347 irq &= ~PCIC_CHANGE_MASK;
2348 2348 pcic_putb(pcic, sockp->pcs_socket,
2349 2349 PCIC_MANAGEMENT_INT, irq);
2350 2350
2351 2351 pcic_putcb(pcic, CB_STATUS_MASK, 0x0);
2352 2352
2353 2353 /*
2354 2354 * Put the socket in debouncing state so that
2355 2355 * the leaf driver won't receive interrupts.
2356 2356 * Crucial for handling surprise-removal.
2357 2357 */
2358 2358 sockp->pcs_flags |= PCS_DEBOUNCING;
2359 2359
2360 2360 if (!sockp->pcs_cd_softint_flg) {
2361 2361 sockp->pcs_cd_softint_flg = 1;
2362 2362 (void) ddi_intr_trigger_softint(
2363 2363 sockp->pcs_cd_softint_hdl, NULL);
2364 2364 }
2365 2365
2366 2366 io_ints &= ~(1 << i);
2367 2367 } /* PCIC_CD_DETECT */
2368 2368
2369 2369 /* Ready/Change Detect */
2370 2370 sockp->pcs_state ^= SBM_RDYBSY;
2371 2371 if (card_type == IF_MEMORY && value & PCIC_RD_DETECT) {
2372 2372 sockp->pcs_flags |= PCS_READY;
2373 2373 PC_CALLBACK(pcic->dip, x, PCE_CARD_READY, i);
2374 2374 }
2375 2375
2376 2376 /* Battery Warn Detect */
2377 2377 if (card_type == IF_MEMORY &&
2378 2378 value & PCIC_BW_DETECT &&
2379 2379 !(sockp->pcs_state & SBM_BVD2)) {
2380 2380 sockp->pcs_state |= SBM_BVD2;
2381 2381 PC_CALLBACK(pcic->dip, x,
2382 2382 PCE_CARD_BATTERY_WARN, i);
2383 2383 }
2384 2384
2385 2385 /* Battery Dead Detect */
2386 2386 if (value & PCIC_BD_DETECT) {
2387 2387 /*
2388 2388 * need to work out event if RI not enabled
2389 2389 * and card_type == IF_IO
2390 2390 */
2391 2391 if (card_type == IF_MEMORY &&
2392 2392 !(sockp->pcs_state & SBM_BVD1)) {
2393 2393 sockp->pcs_state |= SBM_BVD1;
2394 2394 PC_CALLBACK(pcic->dip, x,
2395 2395 PCE_CARD_BATTERY_DEAD,
2396 2396 i);
2397 2397 } else {
2398 2398 /*
2399 2399 * information in pin replacement
2400 2400 * register if one is available
2401 2401 */
2402 2402 PC_CALLBACK(pcic->dip, x,
2403 2403 PCE_CARD_STATUS_CHANGE,
2404 2404 i);
2405 2405 } /* IF_MEMORY */
2406 2406 } /* PCIC_BD_DETECT */
2407 2407 } /* if pcic_change */
2408 2408 /*
2409 2409 * for any controllers that we can detect whether a socket
2410 2410 * had an interrupt for the PC Card, we should sort that out
2411 2411 * here.
2412 2412 */
2413 2413 } /* for pc_numsockets */
2414 2414
2415 2415 /*
2416 2416 * If we're on a PCI bus, we may need to cycle through each IO
2417 2417 * interrupt handler that is registered since they all
2418 2418 * share the same interrupt line.
2419 2419 */
2420 2420
2421 2421
2422 2422 #if defined(PCIC_DEBUG)
2423 2423 pcic_err(pcic->dip, 0xf,
2424 2424 "pcic_intr: pc_intr_mode=%d pc_type=%x io_ints=0x%x\n",
2425 2425 pcic->pc_intr_mode, pcic->pc_type, io_ints);
2426 2426 #endif
2427 2427
2428 2428 if (io_ints) {
2429 2429 if (pcic_do_io_intr(pcic, io_ints) == DDI_INTR_CLAIMED)
2430 2430 ret = DDI_INTR_CLAIMED;
2431 2431 }
2432 2432
2433 2433 mutex_exit(&pcic->intr_lock);
2434 2434
2435 2435 #if defined(PCIC_DEBUG)
2436 2436 pcic_err(pcic->dip, 0xf,
2437 2437 "pcic_intr: ret=%d value=%d DDI_INTR_CLAIMED=%d\n",
2438 2438 ret, value, DDI_INTR_CLAIMED);
2439 2439 #endif
2440 2440
2441 2441 return (ret);
2442 2442 }
2443 2443
2444 2444 /*
2445 2445 * pcic_change()
2446 2446 * check to see if this socket had a change in state
2447 2447 * by checking the status change register
2448 2448 */
2449 2449 static int
2450 2450 pcic_change(pcicdev_t *pcic, int socket)
2451 2451 {
2452 2452 return (pcic_getb(pcic, socket, PCIC_CARD_STATUS_CHANGE));
2453 2453 }
2454 2454
2455 2455 /*
2456 2456 * pcic_do_io_intr - calls client interrupt handlers
2457 2457 */
2458 2458 static int
2459 2459 pcic_do_io_intr(pcicdev_t *pcic, uint32_t sockets)
2460 2460 {
2461 2461 inthandler_t *tmp;
2462 2462 int ret = DDI_INTR_UNCLAIMED;
2463 2463
2464 2464 #if defined(PCIC_DEBUG)
2465 2465 pcic_err(pcic->dip, 0xf,
2466 2466 "pcic_do_io_intr: pcic=%p sockets=%d irq_top=%p\n",
2467 2467 (void *)pcic, (int)sockets, (void *)pcic->irq_top);
2468 2468 #endif
2469 2469
2470 2470 if (pcic->irq_top != NULL) {
2471 2471 tmp = pcic->irq_current;
2472 2472
2473 2473 do {
2474 2474 int cur = pcic->irq_current->socket;
2475 2475 pcic_socket_t *sockp =
2476 2476 &pcic->pc_sockets[cur];
2477 2477
2478 2478 #if defined(PCIC_DEBUG)
2479 2479 pcic_err(pcic->dip, 0xf,
2480 2480 "\t pcs_flags=0x%x PCS_CARD_PRESENT=0x%x\n",
2481 2481 sockp->pcs_flags, PCS_CARD_PRESENT);
2482 2482 pcic_err(pcic->dip, 0xf,
2483 2483 "\t sockets=%d cur=%d intr=%p arg1=%p "
2484 2484 "arg2=%p\n",
2485 2485 sockets, cur, (void *)pcic->irq_current->intr,
2486 2486 pcic->irq_current->arg1,
2487 2487 pcic->irq_current->arg2);
2488 2488 #endif
2489 2489 if ((sockp->pcs_flags & PCS_CARD_PRESENT) &&
2490 2490 !(sockp->pcs_flags & PCS_DEBOUNCING) &&
2491 2491 (sockets & (1 << cur))) {
2492 2492
2493 2493 if ((*pcic->irq_current->intr)(pcic->irq_current->arg1,
2494 2494 pcic->irq_current->arg2) == DDI_INTR_CLAIMED)
2495 2495 ret = DDI_INTR_CLAIMED;
2496 2496
2497 2497 #if defined(PCIC_DEBUG)
2498 2498 pcic_err(pcic->dip, 0xf,
2499 2499 "\t ret=%d DDI_INTR_CLAIMED=%d\n",
2500 2500 ret, DDI_INTR_CLAIMED);
2501 2501 #endif
2502 2502 }
2503 2503
2504 2504
2505 2505 if ((pcic->irq_current = pcic->irq_current->next) == NULL)
2506 2506 pcic->irq_current = pcic->irq_top;
2507 2507
2508 2508 } while (pcic->irq_current != tmp);
2509 2509
2510 2510 if ((pcic->irq_current = pcic->irq_current->next) == NULL)
2511 2511 pcic->irq_current = pcic->irq_top;
2512 2512
2513 2513 } else {
2514 2514 ret = DDI_INTR_UNCLAIMED;
2515 2515 }
2516 2516
2517 2517 #if defined(PCIC_DEBUG)
2518 2518 pcic_err(pcic->dip, 0xf,
2519 2519 "pcic_do_io_intr: exit ret=%d DDI_INTR_CLAIMED=%d\n",
2520 2520 ret, DDI_INTR_CLAIMED);
2521 2521 #endif
2522 2522
2523 2523 return (ret);
2524 2524
2525 2525 }
2526 2526
2527 2527 /*
2528 2528 * pcic_inquire_adapter()
2529 2529 * SocketServices InquireAdapter function
2530 2530 * get characteristics of the physical adapter
2531 2531 */
2532 2532 /*ARGSUSED*/
2533 2533 static int
2534 2534 pcic_inquire_adapter(dev_info_t *dip, inquire_adapter_t *config)
2535 2535 {
2536 2536 anp_t *anp = ddi_get_driver_private(dip);
2537 2537 pcicdev_t *pcic = anp->an_private;
2538 2538
2539 2539 config->NumSockets = pcic->pc_numsockets;
2540 2540 config->NumWindows = pcic->pc_numsockets * PCIC_NUMWINSOCK;
2541 2541 config->NumEDCs = 0;
2542 2542 config->AdpCaps = 0;
2543 2543 config->ActiveHigh = 0;
2544 2544 config->ActiveLow = PCIC_AVAIL_IRQS;
2545 2545 config->NumPower = pcic->pc_numpower;
2546 2546 config->power_entry = pcic->pc_power; /* until we resolve this */
2547 2547 #if defined(PCIC_DEBUG)
2548 2548 if (pcic_debug) {
2549 2549 cmn_err(CE_CONT, "pcic_inquire_adapter:\n");
2550 2550 cmn_err(CE_CONT, "\tNumSockets=%d\n", config->NumSockets);
2551 2551 cmn_err(CE_CONT, "\tNumWindows=%d\n", config->NumWindows);
2552 2552 }
2553 2553 #endif
2554 2554 config->ResourceFlags = 0;
2555 2555 switch (pcic->pc_intr_mode) {
2556 2556 case PCIC_INTR_MODE_PCI_1:
2557 2557 config->ResourceFlags |= RES_OWN_IRQ | RES_IRQ_NEXUS |
2558 2558 RES_IRQ_SHAREABLE;
2559 2559 break;
2560 2560 }
2561 2561 return (SUCCESS);
2562 2562 }
2563 2563
2564 2564 /*
2565 2565 * pcic_callback()
2566 2566 * The PCMCIA nexus calls us via this function
2567 2567 * in order to set the callback function we are
2568 2568 * to call the nexus with
2569 2569 */
2570 2570 /*ARGSUSED*/
2571 2571 static int
2572 2572 pcic_callback(dev_info_t *dip, int (*handler)(), int arg)
2573 2573 {
2574 2574 anp_t *anp = ddi_get_driver_private(dip);
2575 2575 pcicdev_t *pcic = anp->an_private;
2576 2576
2577 2577 if (handler != NULL) {
2578 2578 pcic->pc_callback = handler;
2579 2579 pcic->pc_cb_arg = arg;
2580 2580 pcic->pc_flags |= PCF_CALLBACK;
2581 2581 } else {
2582 2582 pcic->pc_callback = NULL;
2583 2583 pcic->pc_cb_arg = 0;
2584 2584 pcic->pc_flags &= ~PCF_CALLBACK;
2585 2585 }
2586 2586 /*
2587 2587 * we're now registered with the nexus
2588 2588 * it is acceptable to do callbacks at this point.
2589 2589 * don't call back from here though since it could block
2590 2590 */
2591 2591 return (PC_SUCCESS);
2592 2592 }
2593 2593
2594 2594 /*
2595 2595 * pcic_calc_speed (pcicdev_t *pcic, uint32_t speed)
2596 2596 * calculate the speed bits from the specified memory speed
2597 2597 * there may be more to do here
2598 2598 */
2599 2599
2600 2600 static int
2601 2601 pcic_calc_speed(pcicdev_t *pcic, uint32_t speed)
2602 2602 {
2603 2603 uint32_t wspeed = 1; /* assume 1 wait state when unknown */
2604 2604 uint32_t bspeed = PCIC_ISA_DEF_SYSCLK;
2605 2605
2606 2606 switch (pcic->pc_type) {
2607 2607 case PCIC_I82365SL:
2608 2608 case PCIC_VADEM:
2609 2609 case PCIC_VADEM_VG469:
2610 2610 default:
2611 2611 /* Intel chip wants it in waitstates */
2612 2612 wspeed = mhztons(PCIC_ISA_DEF_SYSCLK) * 3;
2613 2613 if (speed <= wspeed)
2614 2614 wspeed = 0;
2615 2615 else if (speed <= (wspeed += mhztons(bspeed)))
2616 2616 wspeed = 1;
2617 2617 else if (speed <= (wspeed += mhztons(bspeed)))
2618 2618 wspeed = 2;
2619 2619 else
2620 2620 wspeed = 3;
2621 2621 wspeed <<= 6; /* put in right bit positions */
2622 2622 break;
2623 2623
2624 2624 case PCIC_INTEL_i82092:
2625 2625 wspeed = SYSMEM_82092_80NS;
2626 2626 if (speed > 80)
2627 2627 wspeed = SYSMEM_82092_100NS;
2628 2628 if (speed > 100)
2629 2629 wspeed = SYSMEM_82092_150NS;
2630 2630 if (speed > 150)
2631 2631 wspeed = SYSMEM_82092_200NS;
2632 2632 if (speed > 200)
2633 2633 wspeed = SYSMEM_82092_250NS;
2634 2634 if (speed > 250)
2635 2635 wspeed = SYSMEM_82092_600NS;
2636 2636 wspeed <<= 5; /* put in right bit positions */
2637 2637 break;
2638 2638
2639 2639 } /* switch */
2640 2640
2641 2641 return (wspeed);
2642 2642 }
2643 2643
2644 2644 /*
2645 2645 * These values are taken from the PC Card Standard Electrical Specification.
2646 2646 * Generally the larger value is taken if 2 are possible.
2647 2647 */
2648 2648 static struct pcic_card_times {
2649 2649 uint16_t cycle; /* Speed as found in the atribute space of he card. */
2650 2650 uint16_t setup; /* Corresponding address setup time. */
2651 2651 uint16_t width; /* Corresponding width, OE or WE. */
2652 2652 uint16_t hold; /* Corresponding data or address hold time. */
2653 2653 } pcic_card_times[] = {
2654 2654
2655 2655 /*
2656 2656 * Note: The rounded up times for 250, 200 & 150 have been increased
2657 2657 * due to problems with the 3-Com ethernet cards (pcelx) on UBIIi.
2658 2658 * See BugID 00663.
2659 2659 */
2660 2660
2661 2661 /*
2662 2662 * Rounded up times Original times from
2663 2663 * that add up to the the PCMCIA Spec.
2664 2664 * cycle time.
2665 2665 */
2666 2666 {600, 180, 370, 140}, /* 100, 300, 70 */
2667 2667 {400, 120, 300, 90}, /* Made this one up */
2668 2668 {250, 100, 190, 70}, /* 30, 150, 30 */
2669 2669 {200, 80, 170, 70}, /* 20, 120, 30 */
2670 2670 {150, 50, 110, 40}, /* 20, 80, 20 */
2671 2671 {100, 40, 80, 40}, /* 10, 60, 15 */
2672 2672 {0, 10, 60, 15} /* 10, 60, 15 */
2673 2673 };
2674 2674
2675 2675 /*
2676 2676 * pcic_set_cdtimers
2677 2677 * This is specific to several Cirrus Logic chips
2678 2678 */
2679 2679 static void
2680 2680 pcic_set_cdtimers(pcicdev_t *pcic, int socket, uint32_t speed, int tset)
2681 2681 {
2682 2682 int cmd, set, rec, offset, clk_pulse;
2683 2683 struct pcic_card_times *ctp;
2684 2684
2685 2685 if ((tset == IOMEM_CLTIMER_SET_1) || (tset == SYSMEM_CLTIMER_SET_1))
2686 2686 offset = 3;
2687 2687 else
2688 2688 offset = 0;
2689 2689
2690 2690 clk_pulse = mhztons(pcic->bus_speed);
2691 2691 for (ctp = pcic_card_times; speed < ctp->cycle; ctp++)
2692 2692 ;
2693 2693
2694 2694 /*
2695 2695 * Add (clk_pulse/2) and an extra 1 to account for rounding errors.
2696 2696 */
2697 2697 set = ((ctp->setup + 10 + 1 + (clk_pulse/2))/clk_pulse) - 1;
2698 2698 if (set < 0)
2699 2699 set = 0;
2700 2700
2701 2701 cmd = ((ctp->width + 10 + 1 + (clk_pulse/2))/clk_pulse) - 1;
2702 2702 if (cmd < 0)
2703 2703 cmd = 0;
2704 2704
2705 2705 rec = ((ctp->hold + 10 + 1 + (clk_pulse/2))/clk_pulse) - 2;
2706 2706 if (rec < 0)
2707 2707 rec = 0;
2708 2708
2709 2709 #if defined(PCIC_DEBUG)
2710 2710 pcic_err(pcic->dip, 8, "pcic_set_cdtimers(%d, Timer Set %d)\n"
2711 2711 "ct=%d, cp=%d, cmd=0x%x, setup=0x%x, rec=0x%x\n",
2712 2712 (unsigned)speed, offset == 3 ? 1 : 0,
2713 2713 ctp->cycle, clk_pulse, cmd, set, rec);
2714 2714 #endif
2715 2715
2716 2716 pcic_putb(pcic, socket, PCIC_TIME_COMMAND_0 + offset, cmd);
2717 2717 pcic_putb(pcic, socket, PCIC_TIME_SETUP_0 + offset, set);
2718 2718 pcic_putb(pcic, socket, PCIC_TIME_RECOVER_0 + offset, rec);
2719 2719 }
2720 2720
2721 2721 /*
2722 2722 * pcic_set_window
2723 2723 * essentially the same as the Socket Services specification
2724 2724 * We use socket and not adapter since they are identifiable
2725 2725 * but the rest is the same
2726 2726 *
2727 2727 * dip pcic driver's device information
2728 2728 * window parameters for the request
2729 2729 */
2730 2730 static int
2731 2731 pcic_set_window(dev_info_t *dip, set_window_t *window)
2732 2732 {
2733 2733 anp_t *anp = ddi_get_driver_private(dip);
2734 2734 pcicdev_t *pcic = anp->an_private;
2735 2735 int select;
2736 2736 int socket, pages, which, ret;
2737 2737 pcic_socket_t *sockp = &pcic->pc_sockets[window->socket];
2738 2738 ra_return_t res;
2739 2739 ndi_ra_request_t req;
2740 2740 uint32_t base = window->base;
2741 2741
2742 2742 #if defined(PCIC_DEBUG)
2743 2743 if (pcic_debug) {
2744 2744 cmn_err(CE_CONT, "pcic_set_window: entered\n");
2745 2745 cmn_err(CE_CONT,
2746 2746 "\twindow=%d, socket=%d, WindowSize=%d, speed=%d\n",
2747 2747 window->window, window->socket, window->WindowSize,
2748 2748 window->speed);
2749 2749 cmn_err(CE_CONT,
2750 2750 "\tbase=%x, state=%x\n", (unsigned)window->base,
2751 2751 (unsigned)window->state);
2752 2752 }
2753 2753 #endif
2754 2754
2755 2755 /*
2756 2756 * do some basic sanity checking on what we support
2757 2757 * we don't do paged mode
2758 2758 */
2759 2759 if (window->state & WS_PAGED) {
2760 2760 cmn_err(CE_WARN, "pcic_set_window: BAD_ATTRIBUTE\n");
2761 2761 return (BAD_ATTRIBUTE);
2762 2762 }
2763 2763
2764 2764 /*
2765 2765 * we don't care about previous mappings.
2766 2766 * Card Services will deal with that so don't
2767 2767 * even check
2768 2768 */
2769 2769
2770 2770 socket = window->socket;
2771 2771
2772 2772 if (!(window->state & WS_IO)) {
2773 2773 int win, tmp;
2774 2774 pcs_memwin_t *memp;
2775 2775 #if defined(PCIC_DEBUG)
2776 2776 if (pcic_debug)
2777 2777 cmn_err(CE_CONT, "\twindow type is memory\n");
2778 2778 #endif
2779 2779 /* this is memory window mapping */
2780 2780 win = window->window % PCIC_NUMWINSOCK;
2781 2781 tmp = window->window / PCIC_NUMWINSOCK;
2782 2782
2783 2783 /* only windows 2-6 can do memory mapping */
2784 2784 if (tmp != window->socket || win < PCIC_IOWINDOWS) {
2785 2785 cmn_err(CE_CONT,
2786 2786 "\tattempt to map to non-mem window\n");
2787 2787 return (BAD_WINDOW);
2788 2788 }
2789 2789
2790 2790 if (window->WindowSize == 0)
2791 2791 window->WindowSize = MEM_MIN;
2792 2792 else if ((window->WindowSize & (PCIC_PAGE-1)) != 0) {
2793 2793 cmn_err(CE_WARN, "pcic_set_window: BAD_SIZE\n");
2794 2794 return (BAD_SIZE);
2795 2795 }
2796 2796
2797 2797 mutex_enter(&pcic->pc_lock); /* protect the registers */
2798 2798
2799 2799 memp = &sockp->pcs_windows[win].mem;
2800 2800 memp->pcw_speed = window->speed;
2801 2801
2802 2802 win -= PCIC_IOWINDOWS; /* put in right range */
2803 2803
2804 2804 if (window->WindowSize != memp->pcw_len)
2805 2805 which = memp->pcw_len;
2806 2806 else
2807 2807 which = 0;
2808 2808
2809 2809 if (window->state & WS_ENABLED) {
2810 2810 uint32_t wspeed;
2811 2811 #if defined(PCIC_DEBUG)
2812 2812 if (pcic_debug) {
2813 2813 cmn_err(CE_CONT,
2814 2814 "\tbase=%x, win=%d\n", (unsigned)base,
2815 2815 win);
2816 2816 if (which)
2817 2817 cmn_err(CE_CONT,
2818 2818 "\tneed to remap window\n");
2819 2819 }
2820 2820 #endif
2821 2821
2822 2822 if (which && (memp->pcw_status & PCW_MAPPED)) {
2823 2823 ddi_regs_map_free(&memp->pcw_handle);
2824 2824 res.ra_addr_lo = memp->pcw_base;
2825 2825 res.ra_len = memp->pcw_len;
2826 2826 (void) pcmcia_free_mem(memp->res_dip, &res);
2827 2827 memp->pcw_status &= ~(PCW_MAPPED|PCW_ENABLED);
2828 2828 memp->pcw_hostmem = NULL;
2829 2829 memp->pcw_base = NULL;
2830 2830 memp->pcw_len = 0;
2831 2831 }
2832 2832
2833 2833 which = window->WindowSize >> PAGE_SHIFT;
2834 2834
2835 2835 if (!(memp->pcw_status & PCW_MAPPED)) {
2836 2836 ret = 0;
2837 2837
2838 2838 memp->pcw_base = base;
2839 2839 bzero(&req, sizeof (req));
2840 2840 req.ra_len = which << PAGE_SHIFT;
2841 2841 req.ra_addr = (uint64_t)memp->pcw_base;
2842 2842 req.ra_boundbase = pcic->pc_base;
2843 2843 req.ra_boundlen = pcic->pc_bound;
2844 2844 req.ra_flags = (memp->pcw_base ?
2845 2845 NDI_RA_ALLOC_SPECIFIED : 0) |
2846 2846 NDI_RA_ALLOC_BOUNDED;
2847 2847 req.ra_align_mask =
2848 2848 (PAGESIZE - 1) | (PCIC_PAGE - 1);
2849 2849 #if defined(PCIC_DEBUG)
2850 2850 pcic_err(dip, 8,
2851 2851 "\tlen 0x%"PRIx64
2852 2852 "addr 0x%"PRIx64"bbase 0x%"PRIx64
2853 2853 " blen 0x%"PRIx64" flags 0x%x"
2854 2854 " algn 0x%"PRIx64"\n",
2855 2855 req.ra_len, req.ra_addr,
2856 2856 req.ra_boundbase,
2857 2857 req.ra_boundlen, req.ra_flags,
2858 2858 req.ra_align_mask);
2859 2859 #endif
2860 2860
2861 2861 ret = pcmcia_alloc_mem(dip, &req, &res,
2862 2862 &memp->res_dip);
2863 2863 if (ret == DDI_FAILURE) {
2864 2864 mutex_exit(&pcic->pc_lock);
2865 2865 cmn_err(CE_WARN,
2866 2866 "\tpcmcia_alloc_mem() failed\n");
2867 2867 return (BAD_SIZE);
2868 2868 }
2869 2869 memp->pcw_base = res.ra_addr_lo;
2870 2870 base = memp->pcw_base;
2871 2871
2872 2872 #if defined(PCIC_DEBUG)
2873 2873 if (pcic_debug)
2874 2874 cmn_err(CE_CONT,
2875 2875 "\tsetwindow: new base=%x\n",
2876 2876 (unsigned)memp->pcw_base);
2877 2877 #endif
2878 2878 memp->pcw_len = window->WindowSize;
2879 2879
2880 2880 which = pcmcia_map_reg(pcic->dip,
2881 2881 window->child,
2882 2882 &res,
2883 2883 (uint32_t)(window->state &
2884 2884 0xffff) |
2885 2885 (window->socket << 16),
2886 2886 (caddr_t *)&memp->pcw_hostmem,
2887 2887 &memp->pcw_handle,
2888 2888 &window->attr, NULL);
2889 2889
2890 2890 if (which != DDI_SUCCESS) {
2891 2891
2892 2892 cmn_err(CE_WARN, "\tpcmcia_map_reg() "
2893 2893 "failed\n");
2894 2894
2895 2895 res.ra_addr_lo = memp->pcw_base;
2896 2896 res.ra_len = memp->pcw_len;
2897 2897 (void) pcmcia_free_mem(memp->res_dip,
2898 2898 &res);
2899 2899
2900 2900 mutex_exit(&pcic->pc_lock);
2901 2901
2902 2902 return (BAD_WINDOW);
2903 2903 }
2904 2904 memp->pcw_status |= PCW_MAPPED;
2905 2905 #if defined(PCIC_DEBUG)
2906 2906 if (pcic_debug)
2907 2907 cmn_err(CE_CONT,
2908 2908 "\tmap=%x, hostmem=%p\n",
2909 2909 which,
2910 2910 (void *)memp->pcw_hostmem);
2911 2911 #endif
2912 2912 } else {
2913 2913 base = memp->pcw_base;
2914 2914 }
2915 2915
2916 2916 /* report the handle back to caller */
2917 2917 window->handle = memp->pcw_handle;
2918 2918
2919 2919 #if defined(PCIC_DEBUG)
2920 2920 if (pcic_debug) {
2921 2921 cmn_err(CE_CONT,
2922 2922 "\twindow mapped to %x@%x len=%d\n",
2923 2923 (unsigned)window->base,
2924 2924 (unsigned)memp->pcw_base,
2925 2925 memp->pcw_len);
2926 2926 }
2927 2927 #endif
2928 2928
2929 2929 /* find the register set offset */
2930 2930 select = win * PCIC_MEM_1_OFFSET;
2931 2931 #if defined(PCIC_DEBUG)
2932 2932 if (pcic_debug)
2933 2933 cmn_err(CE_CONT, "\tselect=%x\n", select);
2934 2934 #endif
2935 2935
2936 2936 /*
2937 2937 * at this point, the register window indicator has
2938 2938 * been converted to be an offset from the first
2939 2939 * set of registers that are used for programming
2940 2940 * the window mapping and the offset used to select
2941 2941 * the correct set of registers to access the
2942 2942 * specified socket. This allows basing everything
2943 2943 * off the _0 window
2944 2944 */
2945 2945
2946 2946 /* map the physical page base address */
2947 2947 which = (window->state & WS_16BIT) ? SYSMEM_DATA_16 : 0;
2948 2948 which |= (window->speed <= MEM_SPEED_MIN) ?
2949 2949 SYSMEM_ZERO_WAIT : 0;
2950 2950
2951 2951 /* need to select register set */
2952 2952 select = PCIC_MEM_1_OFFSET * win;
2953 2953
2954 2954 pcic_putb(pcic, socket,
2955 2955 PCIC_SYSMEM_0_STARTLOW + select,
2956 2956 SYSMEM_LOW(base));
2957 2957 pcic_putb(pcic, socket,
2958 2958 PCIC_SYSMEM_0_STARTHI + select,
2959 2959 SYSMEM_HIGH(base) | which);
2960 2960
2961 2961 /*
2962 2962 * Some adapters can decode window addresses greater
2963 2963 * than 16-bits worth, so handle them here.
2964 2964 */
2965 2965 switch (pcic->pc_type) {
2966 2966 case PCIC_INTEL_i82092:
2967 2967 pcic_putb(pcic, socket,
2968 2968 PCIC_82092_CPAGE,
2969 2969 SYSMEM_EXT(base));
2970 2970 break;
2971 2971 case PCIC_CL_PD6729:
2972 2972 case PCIC_CL_PD6730:
2973 2973 clext_reg_write(pcic, socket,
2974 2974 PCIC_CLEXT_MMAP0_UA + win,
2975 2975 SYSMEM_EXT(base));
2976 2976 break;
2977 2977 case PCIC_TI_PCI1130:
2978 2978 /*
2979 2979 * Note that the TI chip has one upper byte
2980 2980 * per socket so all windows get bound to a
2981 2981 * 16MB segment. This must be detected and
2982 2982 * handled appropriately. We can detect that
2983 2983 * it is done by seeing if the pc_base has
2984 2984 * changed and changing when the register
2985 2985 * is first set. This will force the bounds
2986 2986 * to be correct.
2987 2987 */
2988 2988 if (pcic->pc_bound == 0xffffffff) {
2989 2989 pcic_putb(pcic, socket,
2990 2990 PCIC_TI_WINDOW_PAGE_PCI,
2991 2991 SYSMEM_EXT(base));
2992 2992 pcic->pc_base = SYSMEM_EXT(base) << 24;
2993 2993 pcic->pc_bound = 0x1000000;
2994 2994 }
2995 2995 break;
2996 2996 case PCIC_TI_PCI1031:
2997 2997 case PCIC_TI_PCI1131:
2998 2998 case PCIC_TI_PCI1250:
2999 2999 case PCIC_TI_PCI1225:
3000 3000 case PCIC_TI_PCI1221:
3001 3001 case PCIC_SMC_34C90:
3002 3002 case PCIC_CL_PD6832:
3003 3003 case PCIC_RICOH_RL5C466:
3004 3004 case PCIC_TI_PCI1410:
3005 3005 case PCIC_ENE_1410:
3006 3006 case PCIC_TI_PCI1510:
3007 3007 case PCIC_TI_PCI1520:
3008 3008 case PCIC_O2_OZ6912:
3009 3009 case PCIC_TI_PCI1420:
3010 3010 case PCIC_ENE_1420:
3011 3011 case PCIC_TI_VENDOR:
3012 3012 case PCIC_TOSHIBA_TOPIC100:
3013 3013 case PCIC_TOSHIBA_TOPIC95:
3014 3014 case PCIC_TOSHIBA_VENDOR:
3015 3015 case PCIC_RICOH_VENDOR:
3016 3016 case PCIC_O2MICRO_VENDOR:
3017 3017 pcic_putb(pcic, socket,
3018 3018 PCIC_YENTA_MEM_PAGE + win,
3019 3019 SYSMEM_EXT(base));
3020 3020 break;
3021 3021 default:
3022 3022 cmn_err(CE_NOTE, "pcic_set_window: unknown "
3023 3023 "cardbus vendor:0x%X\n",
3024 3024 pcic->pc_type);
3025 3025 pcic_putb(pcic, socket,
3026 3026 PCIC_YENTA_MEM_PAGE + win,
3027 3027 SYSMEM_EXT(base));
3028 3028
3029 3029 break;
3030 3030 } /* switch */
3031 3031
3032 3032 /*
3033 3033 * specify the length of the mapped range
3034 3034 * we convert to pages (rounding up) so that
3035 3035 * the hardware gets the right thing
3036 3036 */
3037 3037 pages = (window->WindowSize+PCIC_PAGE-1)/PCIC_PAGE;
3038 3038
3039 3039 /*
3040 3040 * Setup this window's timing.
3041 3041 */
3042 3042 switch (pcic->pc_type) {
3043 3043 case PCIC_CL_PD6729:
3044 3044 case PCIC_CL_PD6730:
3045 3045 case PCIC_CL_PD6710:
3046 3046 case PCIC_CL_PD6722:
3047 3047 wspeed = SYSMEM_CLTIMER_SET_0;
3048 3048 pcic_set_cdtimers(pcic, socket,
3049 3049 window->speed,
3050 3050 wspeed);
3051 3051 break;
3052 3052
3053 3053 case PCIC_INTEL_i82092:
3054 3054 default:
3055 3055 wspeed = pcic_calc_speed(pcic, window->speed);
3056 3056 break;
3057 3057 } /* switch */
3058 3058
3059 3059 #if defined(PCIC_DEBUG)
3060 3060 if (pcic_debug)
3061 3061 cmn_err(CE_CONT,
3062 3062 "\twindow %d speed bits = %x for "
3063 3063 "%dns\n",
3064 3064 win, (unsigned)wspeed, window->speed);
3065 3065 #endif
3066 3066
3067 3067 pcic_putb(pcic, socket, PCIC_SYSMEM_0_STOPLOW + select,
3068 3068 SYSMEM_LOW(base +
3069 3069 (pages * PCIC_PAGE)-1));
3070 3070
3071 3071 wspeed |= SYSMEM_HIGH(base + (pages * PCIC_PAGE)-1);
3072 3072 pcic_putb(pcic, socket, PCIC_SYSMEM_0_STOPHI + select,
3073 3073 wspeed);
3074 3074
3075 3075 /*
3076 3076 * now map the card's memory pages - we start with page
3077 3077 * 0
3078 3078 * we also default to AM -- set page might change it
3079 3079 */
3080 3080 base = memp->pcw_base;
3081 3081 pcic_putb(pcic, socket,
3082 3082 PCIC_CARDMEM_0_LOW + select,
3083 3083 CARDMEM_LOW(0 - (uint32_t)base));
3084 3084
3085 3085 pcic_putb(pcic, socket,
3086 3086 PCIC_CARDMEM_0_HI + select,
3087 3087 CARDMEM_HIGH(0 - (uint32_t)base) |
3088 3088 CARDMEM_REG_ACTIVE);
3089 3089
3090 3090 /*
3091 3091 * enable the window even though redundant
3092 3092 * and SetPage may do it again.
3093 3093 */
3094 3094 select = pcic_getb(pcic, socket,
3095 3095 PCIC_MAPPING_ENABLE);
3096 3096 select |= SYSMEM_WINDOW(win);
3097 3097 pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, select);
3098 3098 memp->pcw_offset = 0;
3099 3099 memp->pcw_status |= PCW_ENABLED;
3100 3100 } else {
3101 3101 /*
3102 3102 * not only do we unmap the memory, the
3103 3103 * window has been turned off.
3104 3104 */
3105 3105 if (which && memp->pcw_status & PCW_MAPPED) {
3106 3106 ddi_regs_map_free(&memp->pcw_handle);
3107 3107 res.ra_addr_lo = memp->pcw_base;
3108 3108 res.ra_len = memp->pcw_len;
3109 3109 (void) pcmcia_free_mem(memp->res_dip, &res);
3110 3110 memp->pcw_hostmem = NULL;
3111 3111 memp->pcw_status &= ~PCW_MAPPED;
3112 3112 }
3113 3113
3114 3114 /* disable current mapping */
3115 3115 select = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
3116 3116 select &= ~SYSMEM_WINDOW(win);
3117 3117 pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, select);
3118 3118 memp->pcw_status &= ~PCW_ENABLED;
3119 3119 }
3120 3120 memp->pcw_len = window->WindowSize;
3121 3121 window->handle = memp->pcw_handle;
3122 3122 #if defined(PCIC_DEBUG)
3123 3123 if (pcic_debug)
3124 3124 xxdmp_all_regs(pcic, window->socket, -1);
3125 3125 #endif
3126 3126 } else {
3127 3127 /*
3128 3128 * This is a request for an IO window
3129 3129 */
3130 3130 int win, tmp;
3131 3131 pcs_iowin_t *winp;
3132 3132 /* I/O windows */
3133 3133 #if defined(PCIC_DEBUG)
3134 3134 if (pcic_debug)
3135 3135 cmn_err(CE_CONT, "\twindow type is I/O\n");
3136 3136 #endif
3137 3137
3138 3138 /* only windows 0 and 1 can do I/O */
3139 3139 win = window->window % PCIC_NUMWINSOCK;
3140 3140 tmp = window->window / PCIC_NUMWINSOCK;
3141 3141
3142 3142 if (win >= PCIC_IOWINDOWS || tmp != window->socket) {
3143 3143 cmn_err(CE_WARN,
3144 3144 "\twindow is out of range (%d)\n",
3145 3145 window->window);
3146 3146 return (BAD_WINDOW);
3147 3147 }
3148 3148
3149 3149 mutex_enter(&pcic->pc_lock); /* protect the registers */
3150 3150
3151 3151 winp = &sockp->pcs_windows[win].io;
3152 3152 winp->pcw_speed = window->speed;
3153 3153 if (window->WindowSize != 1 && window->WindowSize & 1) {
3154 3154 /* we don't want an odd-size window */
3155 3155 window->WindowSize++;
3156 3156 }
3157 3157 winp->pcw_len = window->WindowSize;
3158 3158
3159 3159 if (window->state & WS_ENABLED) {
3160 3160 if (winp->pcw_status & PCW_MAPPED) {
3161 3161 ddi_regs_map_free(&winp->pcw_handle);
3162 3162 res.ra_addr_lo = winp->pcw_base;
3163 3163 res.ra_len = winp->pcw_len;
3164 3164 (void) pcmcia_free_io(winp->res_dip, &res);
3165 3165 winp->pcw_status &= ~(PCW_MAPPED|PCW_ENABLED);
3166 3166 }
3167 3167
3168 3168 /*
3169 3169 * if the I/O address wasn't allocated, allocate
3170 3170 * it now. If it was allocated, it better
3171 3171 * be free to use.
3172 3172 * The winp->pcw_offset value is set and used
3173 3173 * later on if the particular adapter
3174 3174 * that we're running on has the ability
3175 3175 * to translate IO accesses to the card
3176 3176 * (such as some adapters in the Cirrus
3177 3177 * Logic family).
3178 3178 */
3179 3179 winp->pcw_offset = 0;
3180 3180
3181 3181 /*
3182 3182 * Setup the request parameters for the
3183 3183 * requested base and length. If
3184 3184 * we're on an adapter that has
3185 3185 * IO window offset registers, then
3186 3186 * we don't need a specific base
3187 3187 * address, just a length, and then
3188 3188 * we'll cause the correct IO address
3189 3189 * to be generated on the socket by
3190 3190 * setting up the IO window offset
3191 3191 * registers.
3192 3192 * For adapters that support this capability, we
3193 3193 * always use the IO window offset registers,
3194 3194 * even if the passed base/length would be in
3195 3195 * range.
3196 3196 */
3197 3197 base = window->base;
3198 3198 bzero(&req, sizeof (req));
3199 3199 req.ra_len = window->WindowSize;
3200 3200
3201 3201 req.ra_addr = (uint64_t)
3202 3202 ((pcic->pc_flags & PCF_IO_REMAP) ? 0 : base);
3203 3203 req.ra_flags = (req.ra_addr) ?
3204 3204 NDI_RA_ALLOC_SPECIFIED : 0;
3205 3205
3206 3206 req.ra_flags |= NDI_RA_ALIGN_SIZE;
3207 3207 /* need to rethink this */
3208 3208 req.ra_boundbase = pcic->pc_iobase;
3209 3209 req.ra_boundlen = pcic->pc_iobound;
3210 3210 req.ra_flags |= NDI_RA_ALLOC_BOUNDED;
3211 3211
3212 3212 #if defined(PCIC_DEBUG)
3213 3213 pcic_err(dip, 8,
3214 3214 "\tlen 0x%"PRIx64" addr 0x%"PRIx64
3215 3215 "bbase 0x%"PRIx64
3216 3216 "blen 0x%"PRIx64" flags 0x%x algn 0x%"
3217 3217 PRIx64"\n",
3218 3218 req.ra_len, (uint64_t)req.ra_addr,
3219 3219 req.ra_boundbase,
3220 3220 req.ra_boundlen, req.ra_flags,
3221 3221 req.ra_align_mask);
3222 3222 #endif
3223 3223
3224 3224 /*
3225 3225 * Try to allocate the space. If we fail this,
3226 3226 * return the appropriate error depending
3227 3227 * on whether the caller specified a
3228 3228 * specific base address or not.
3229 3229 */
3230 3230 if (pcmcia_alloc_io(dip, &req, &res,
3231 3231 &winp->res_dip) == DDI_FAILURE) {
3232 3232 winp->pcw_status &= ~PCW_ENABLED;
3233 3233 mutex_exit(&pcic->pc_lock);
3234 3234 cmn_err(CE_WARN, "Failed to alloc I/O:\n"
3235 3235 "\tlen 0x%" PRIx64 " addr 0x%" PRIx64
3236 3236 "bbase 0x%" PRIx64
3237 3237 "blen 0x%" PRIx64 "flags 0x%x"
3238 3238 "algn 0x%" PRIx64 "\n",
3239 3239 req.ra_len, req.ra_addr,
3240 3240 req.ra_boundbase,
3241 3241 req.ra_boundlen, req.ra_flags,
3242 3242 req.ra_align_mask);
3243 3243
3244 3244 return (base?BAD_BASE:BAD_SIZE);
3245 3245 } /* pcmcia_alloc_io */
3246 3246
3247 3247 /*
3248 3248 * Don't change the original base. Either we use
3249 3249 * the offset registers below (PCF_IO_REMAP is set)
3250 3250 * or it was allocated correctly anyway.
3251 3251 */
3252 3252 winp->pcw_base = res.ra_addr_lo;
3253 3253
3254 3254 #if defined(PCIC_DEBUG)
3255 3255 pcic_err(dip, 8,
3256 3256 "\tsetwindow: new base=%x orig base 0x%x\n",
3257 3257 (unsigned)winp->pcw_base, base);
3258 3258 #endif
3259 3259
3260 3260 if ((which = pcmcia_map_reg(pcic->dip,
3261 3261 window->child,
3262 3262 &res,
3263 3263 (uint32_t)(window->state &
3264 3264 0xffff) |
3265 3265 (window->socket << 16),
3266 3266 (caddr_t *)&winp->pcw_hostmem,
3267 3267 &winp->pcw_handle,
3268 3268 &window->attr,
3269 3269 base)) != DDI_SUCCESS) {
3270 3270
3271 3271 cmn_err(CE_WARN, "pcmcia_map_reg()"
3272 3272 "failed\n");
3273 3273
3274 3274 res.ra_addr_lo = winp->pcw_base;
3275 3275 res.ra_len = winp->pcw_len;
3276 3276 (void) pcmcia_free_io(winp->res_dip,
3277 3277 &res);
3278 3278
3279 3279 mutex_exit(&pcic->pc_lock);
3280 3280 return (BAD_WINDOW);
3281 3281 }
3282 3282
3283 3283 window->handle = winp->pcw_handle;
3284 3284 winp->pcw_status |= PCW_MAPPED;
3285 3285
3286 3286 /* find the register set offset */
3287 3287 select = win * PCIC_IO_OFFSET;
3288 3288
3289 3289 #if defined(PCIC_DEBUG)
3290 3290 if (pcic_debug) {
3291 3291 cmn_err(CE_CONT,
3292 3292 "\tenable: window=%d, select=%x, "
3293 3293 "base=%x, handle=%p\n",
3294 3294 win, select,
3295 3295 (unsigned)window->base,
3296 3296 (void *)window->handle);
3297 3297 }
3298 3298 #endif
3299 3299 /*
3300 3300 * at this point, the register window indicator has
3301 3301 * been converted to be an offset from the first
3302 3302 * set of registers that are used for programming
3303 3303 * the window mapping and the offset used to select
3304 3304 * the correct set of registers to access the
3305 3305 * specified socket. This allows basing everything
3306 3306 * off the _0 window
3307 3307 */
3308 3308
3309 3309 /* map the I/O base in */
3310 3310 pcic_putb(pcic, socket,
3311 3311 PCIC_IO_ADDR_0_STARTLOW + select,
3312 3312 LOW_BYTE((uint32_t)winp->pcw_base));
3313 3313 pcic_putb(pcic, socket,
3314 3314 PCIC_IO_ADDR_0_STARTHI + select,
3315 3315 HIGH_BYTE((uint32_t)winp->pcw_base));
3316 3316
3317 3317 pcic_putb(pcic, socket,
3318 3318 PCIC_IO_ADDR_0_STOPLOW + select,
3319 3319 LOW_BYTE((uint32_t)winp->pcw_base +
3320 3320 window->WindowSize - 1));
3321 3321 pcic_putb(pcic, socket,
3322 3322 PCIC_IO_ADDR_0_STOPHI + select,
3323 3323 HIGH_BYTE((uint32_t)winp->pcw_base +
3324 3324 window->WindowSize - 1));
3325 3325
3326 3326 /*
3327 3327 * We've got the requested IO space, now see if we
3328 3328 * need to adjust the IO window offset registers
3329 3329 * so that the correct IO address is generated
3330 3330 * at the socket. If this window doesn't have
3331 3331 * this capability, then we're all done setting
3332 3332 * up the IO resources.
3333 3333 */
3334 3334 if (pcic->pc_flags & PCF_IO_REMAP) {
3335 3335
3336 3336
3337 3337 /*
3338 3338 * Note that only 16 bits are used to program
3339 3339 * the registers but leave 32 bits on pcw_offset
3340 3340 * so that we can generate the original base
3341 3341 * in get_window()
3342 3342 */
3343 3343 winp->pcw_offset = (base - winp->pcw_base);
3344 3344
3345 3345 pcic_putb(pcic, socket,
3346 3346 PCIC_IO_OFFSET_LOW +
3347 3347 (win * PCIC_IO_OFFSET_OFFSET),
3348 3348 winp->pcw_offset & 0x0ff);
3349 3349 pcic_putb(pcic, socket,
3350 3350 PCIC_IO_OFFSET_HI +
3351 3351 (win * PCIC_IO_OFFSET_OFFSET),
3352 3352 (winp->pcw_offset >> 8) & 0x0ff);
3353 3353
3354 3354 } /* PCF_IO_REMAP */
3355 3355
3356 3356 /* now get the other details (size, etc) right */
3357 3357
3358 3358 /*
3359 3359 * Set the data size control bits here. Most of the
3360 3360 * adapters will ignore IOMEM_16BIT when
3361 3361 * IOMEM_IOCS16 is set, except for the Intel
3362 3362 * 82092, which only pays attention to the
3363 3363 * IOMEM_16BIT bit. Sigh... Intel can't even
3364 3364 * make a proper clone of their own chip.
3365 3365 * The 82092 also apparently can't set the timing
3366 3366 * of I/O windows.
3367 3367 */
3368 3368 which = (window->state & WS_16BIT) ?
3369 3369 (IOMEM_16BIT | IOMEM_IOCS16) : 0;
3370 3370
3371 3371 switch (pcic->pc_type) {
3372 3372 case PCIC_CL_PD6729:
3373 3373 case PCIC_CL_PD6730:
3374 3374 case PCIC_CL_PD6710:
3375 3375 case PCIC_CL_PD6722:
3376 3376 case PCIC_CL_PD6832:
3377 3377 /*
3378 3378 * Select Timer Set 1 - this will take
3379 3379 * effect when the PCIC_IO_CONTROL
3380 3380 * register is written to later on;
3381 3381 * the call to pcic_set_cdtimers
3382 3382 * just sets up the timer itself.
3383 3383 */
3384 3384 which |= IOMEM_CLTIMER_SET_1;
3385 3385 pcic_set_cdtimers(pcic, socket,
3386 3386 window->speed,
3387 3387 IOMEM_CLTIMER_SET_1);
3388 3388 which |= IOMEM_IOCS16;
3389 3389 break;
3390 3390 case PCIC_TI_PCI1031:
3391 3391
3392 3392 if (window->state & WS_16BIT)
3393 3393 which |= IOMEM_WAIT16;
3394 3394
3395 3395 break;
3396 3396 case PCIC_TI_PCI1130:
3397 3397
3398 3398 if (window->state & WS_16BIT)
3399 3399 which |= IOMEM_WAIT16;
3400 3400
3401 3401 break;
3402 3402 case PCIC_INTEL_i82092:
3403 3403 break;
3404 3404 default:
3405 3405 if (window->speed >
3406 3406 mhztons(pcic->bus_speed) * 3)
3407 3407 which |= IOMEM_WAIT16;
3408 3408 #ifdef notdef
3409 3409 if (window->speed <
3410 3410 mhztons(pcic->bus_speed) * 6)
3411 3411 which |= IOMEM_ZERO_WAIT;
3412 3412 #endif
3413 3413 break;
3414 3414 } /* switch (pc_type) */
3415 3415
3416 3416 /*
3417 3417 * Setup the data width and timing
3418 3418 */
3419 3419 select = pcic_getb(pcic, socket, PCIC_IO_CONTROL);
3420 3420 select &= ~(PCIC_IO_WIN_MASK << (win * 4));
3421 3421 select |= IOMEM_SETWIN(win, which);
3422 3422 pcic_putb(pcic, socket, PCIC_IO_CONTROL, select);
3423 3423
3424 3424 /*
3425 3425 * Enable the IO window
3426 3426 */
3427 3427 select = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
3428 3428 pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE,
3429 3429 select | IOMEM_WINDOW(win));
3430 3430
3431 3431 winp->pcw_status |= PCW_ENABLED;
3432 3432
3433 3433 #if defined(PCIC_DEBUG)
3434 3434 if (pcic_debug) {
3435 3435 cmn_err(CE_CONT,
3436 3436 "\twhich = %x, select = %x (%x)\n",
3437 3437 which, select,
3438 3438 IOMEM_SETWIN(win, which));
3439 3439 xxdmp_all_regs(pcic, window->socket * 0x40, 24);
3440 3440 }
3441 3441 #endif
3442 3442 } else {
3443 3443 /*
3444 3444 * not only do we unmap the IO space, the
3445 3445 * window has been turned off.
3446 3446 */
3447 3447 if (winp->pcw_status & PCW_MAPPED) {
3448 3448 ddi_regs_map_free(&winp->pcw_handle);
3449 3449 res.ra_addr_lo = winp->pcw_base;
3450 3450 res.ra_len = winp->pcw_len;
3451 3451 (void) pcmcia_free_io(winp->res_dip, &res);
3452 3452 winp->pcw_status &= ~PCW_MAPPED;
3453 3453 }
3454 3454
3455 3455 /* disable current mapping */
3456 3456 select = pcic_getb(pcic, socket,
3457 3457 PCIC_MAPPING_ENABLE);
3458 3458 pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE,
3459 3459 select &= ~IOMEM_WINDOW(win));
3460 3460 winp->pcw_status &= ~PCW_ENABLED;
3461 3461
3462 3462 winp->pcw_base = 0;
3463 3463 winp->pcw_len = 0;
3464 3464 winp->pcw_offset = 0;
3465 3465 window->base = 0;
3466 3466 /* now make sure we don't accidentally re-enable */
3467 3467 /* find the register set offset */
3468 3468 select = win * PCIC_IO_OFFSET;
3469 3469 pcic_putb(pcic, socket,
3470 3470 PCIC_IO_ADDR_0_STARTLOW + select, 0);
3471 3471 pcic_putb(pcic, socket,
3472 3472 PCIC_IO_ADDR_0_STARTHI + select, 0);
3473 3473 pcic_putb(pcic, socket,
3474 3474 PCIC_IO_ADDR_0_STOPLOW + select, 0);
3475 3475 pcic_putb(pcic, socket,
3476 3476 PCIC_IO_ADDR_0_STOPHI + select, 0);
3477 3477 }
3478 3478 }
3479 3479 mutex_exit(&pcic->pc_lock);
3480 3480
3481 3481 return (SUCCESS);
3482 3482 }
3483 3483
3484 3484 /*
3485 3485 * pcic_card_state()
3486 3486 * compute the instantaneous Card State information
3487 3487 */
3488 3488 static int
3489 3489 pcic_card_state(pcicdev_t *pcic, pcic_socket_t *sockp)
3490 3490 {
3491 3491 int value, result;
3492 3492 #if defined(PCIC_DEBUG)
3493 3493 int orig_value;
3494 3494 #endif
3495 3495
3496 3496 mutex_enter(&pcic->pc_lock); /* protect the registers */
3497 3497
3498 3498 value = pcic_getb(pcic, sockp->pcs_socket, PCIC_INTERFACE_STATUS);
3499 3499
3500 3500 #if defined(PCIC_DEBUG)
3501 3501 orig_value = value;
3502 3502 if (pcic_debug >= 8)
3503 3503 cmn_err(CE_CONT, "pcic_card_state(%p) if status = %b for %d\n",
3504 3504 (void *)sockp,
3505 3505 value,
3506 3506 "\020\1BVD1\2BVD2\3CD1\4CD2\5WP\6RDY\7PWR\10~GPI",
3507 3507 sockp->pcs_socket);
3508 3508 #endif
3509 3509 /*
3510 3510 * Lie to socket services if we are not ready.
3511 3511 * This is when we are starting up or during debounce timeouts
3512 3512 * or if the card is a cardbus card.
3513 3513 */
3514 3514 if (!(sockp->pcs_flags & (PCS_STARTING|PCS_CARD_ISCARDBUS)) &&
3515 3515 !sockp->pcs_debounce_id &&
3516 3516 (value & PCIC_ISTAT_CD_MASK) == PCIC_CD_PRESENT_OK) {
3517 3517 result = SBM_CD;
3518 3518
3519 3519 if (value & PCIC_WRITE_PROTECT || !(value & PCIC_POWER_ON))
3520 3520 result |= SBM_WP;
3521 3521 if (value & PCIC_POWER_ON) {
3522 3522 if (value & PCIC_READY)
3523 3523 result |= SBM_RDYBSY;
3524 3524 value = (~value) & (PCIC_BVD1 | PCIC_BVD2);
3525 3525 if (value & PCIC_BVD1)
3526 3526 result |= SBM_BVD1;
3527 3527 if (value & PCIC_BVD2)
3528 3528 result |= SBM_BVD2;
3529 3529 }
3530 3530 } else
3531 3531 result = 0;
3532 3532
3533 3533 mutex_exit(&pcic->pc_lock);
3534 3534
3535 3535 #if defined(PCIC_DEBUG)
3536 3536 pcic_err(pcic->dip, 8,
3537 3537 "pcic_card_state(%p) if status = %b for %d (rval=0x%x)\n",
3538 3538 (void *) sockp, orig_value,
3539 3539 "\020\1BVD1\2BVD2\3CD1\4CD2\5WP\6RDY\7PWR\10~GPI",
3540 3540 sockp->pcs_socket, result);
3541 3541 #endif
3542 3542
3543 3543 return (result);
3544 3544 }
3545 3545
3546 3546 /*
3547 3547 * pcic_set_page()
3548 3548 * SocketServices SetPage function
3549 3549 * set the page of PC Card memory that should be in the mapped
3550 3550 * window
3551 3551 */
3552 3552 /*ARGSUSED*/
3553 3553 static int
3554 3554 pcic_set_page(dev_info_t *dip, set_page_t *page)
3555 3555 {
3556 3556 anp_t *anp = ddi_get_driver_private(dip);
3557 3557 pcicdev_t *pcic = anp->an_private;
3558 3558 int select;
3559 3559 int which, socket, window;
3560 3560 uint32_t base;
3561 3561 pcs_memwin_t *memp;
3562 3562
3563 3563 /* get real socket/window numbers */
3564 3564 window = page->window % PCIC_NUMWINSOCK;
3565 3565 socket = page->window / PCIC_NUMWINSOCK;
3566 3566
3567 3567 #if defined(PCIC_DEBUG)
3568 3568 if (pcic_debug) {
3569 3569 cmn_err(CE_CONT,
3570 3570 "pcic_set_page: window=%d, socket=%d, page=%d\n",
3571 3571 window, socket, page->page);
3572 3572 }
3573 3573 #endif
3574 3574 /* only windows 2-6 work on memory */
3575 3575 if (window < PCIC_IOWINDOWS)
3576 3576 return (BAD_WINDOW);
3577 3577
3578 3578 /* only one page supported (but any size) */
3579 3579 if (page->page != 0)
3580 3580 return (BAD_PAGE);
3581 3581
3582 3582 mutex_enter(&pcic->pc_lock); /* protect the registers */
3583 3583
3584 3584 memp = &pcic->pc_sockets[socket].pcs_windows[window].mem;
3585 3585 window -= PCIC_IOWINDOWS;
3586 3586
3587 3587 #if defined(PCIC_DEBUG)
3588 3588 if (pcic_debug)
3589 3589 cmn_err(CE_CONT, "\tpcw_base=%x, pcw_hostmem=%p, pcw_len=%x\n",
3590 3590 (uint32_t)memp->pcw_base,
3591 3591 (void *)memp->pcw_hostmem, memp->pcw_len);
3592 3592 #endif
3593 3593
3594 3594 /* window must be enabled */
3595 3595 if (!(memp->pcw_status & PCW_ENABLED))
3596 3596 return (BAD_ATTRIBUTE);
3597 3597
3598 3598 /* find the register set offset */
3599 3599 select = window * PCIC_MEM_1_OFFSET;
3600 3600 #if defined(PCIC_DEBUG)
3601 3601 if (pcic_debug)
3602 3602 cmn_err(CE_CONT, "\tselect=%x\n", select);
3603 3603 #endif
3604 3604
3605 3605 /*
3606 3606 * now map the card's memory pages - we start with page 0
3607 3607 */
3608 3608
3609 3609 which = 0; /* assume simple case */
3610 3610 if (page->state & PS_ATTRIBUTE) {
3611 3611 which |= CARDMEM_REG_ACTIVE;
3612 3612 memp->pcw_status |= PCW_ATTRIBUTE;
3613 3613 } else {
3614 3614 memp->pcw_status &= ~PCW_ATTRIBUTE;
3615 3615 }
3616 3616
3617 3617 /*
3618 3618 * if caller says Write Protect, enforce it.
3619 3619 */
3620 3620 if (page->state & PS_WP) {
3621 3621 which |= CARDMEM_WRITE_PROTECT;
3622 3622 memp->pcw_status |= PCW_WP;
3623 3623 } else {
3624 3624 memp->pcw_status &= ~PCW_WP;
3625 3625 }
3626 3626 #if defined(PCIC_DEBUG)
3627 3627 if (pcic_debug) {
3628 3628 cmn_err(CE_CONT, "\tmemory type = %s\n",
3629 3629 (which & CARDMEM_REG_ACTIVE) ? "attribute" : "common");
3630 3630 if (which & CARDMEM_WRITE_PROTECT)
3631 3631 cmn_err(CE_CONT, "\twrite protect\n");
3632 3632 cmn_err(CE_CONT, "\tpage offset=%x pcw_base=%x (%x)\n",
3633 3633 (unsigned)page->offset,
3634 3634 (unsigned)memp->pcw_base,
3635 3635 (int)page->offset - (int)memp->pcw_base & 0xffffff);
3636 3636 }
3637 3637 #endif
3638 3638 /* address computation based on 64MB range and not larger */
3639 3639 base = (uint32_t)memp->pcw_base & 0x3ffffff;
3640 3640 pcic_putb(pcic, socket, PCIC_CARDMEM_0_LOW + select,
3641 3641 CARDMEM_LOW((int)page->offset - (int)base));
3642 3642 (void) pcic_getb(pcic, socket, PCIC_CARDMEM_0_LOW + select);
3643 3643 pcic_putb(pcic, socket, PCIC_CARDMEM_0_HI + select,
3644 3644 CARDMEM_HIGH((int)page->offset - base) | which);
3645 3645 (void) pcic_getb(pcic, socket, PCIC_CARDMEM_0_HI + select);
3646 3646
3647 3647 /*
3648 3648 * while not really necessary, this just makes sure
3649 3649 * nothing turned the window off behind our backs
3650 3650 */
3651 3651 which = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
3652 3652 which |= SYSMEM_WINDOW(window);
3653 3653 pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, which);
3654 3654 (void) pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
3655 3655
3656 3656 memp->pcw_offset = (off_t)page->offset;
3657 3657
3658 3658 #if defined(PCIC_DEBUG)
3659 3659 if (pcic_debug) {
3660 3660 cmn_err(CE_CONT, "\tbase=%p, *base=%x\n",
3661 3661 (void *)memp->pcw_hostmem,
3662 3662 (uint32_t)*memp->pcw_hostmem);
3663 3663
3664 3664 xxdmp_all_regs(pcic, socket, -1);
3665 3665
3666 3666 cmn_err(CE_CONT, "\tbase=%p, *base=%x\n",
3667 3667 (void *)memp->pcw_hostmem,
3668 3668 (uint32_t)*memp->pcw_hostmem);
3669 3669 }
3670 3670 #endif
3671 3671
3672 3672 if (which & PCW_ATTRIBUTE)
3673 3673 pcic_mswait(pcic, socket, 2);
3674 3674
3675 3675 mutex_exit(&pcic->pc_lock);
3676 3676
3677 3677 return (SUCCESS);
3678 3678 }
3679 3679
3680 3680 /*
3681 3681 * pcic_set_vcc_level()
3682 3682 *
3683 3683 * set voltage based on adapter information
3684 3684 *
3685 3685 * this routine implements a limited solution for support of 3.3v cards.
3686 3686 * the general solution, which would fully support the pcmcia spec
3687 3687 * as far as allowing client drivers to request which voltage levels
3688 3688 * to be set, requires more framework support and driver changes - ess
3689 3689 */
3690 3690 static int
3691 3691 pcic_set_vcc_level(pcicdev_t *pcic, set_socket_t *socket)
3692 3692 {
3693 3693 uint32_t socket_present_state;
3694 3694
3695 3695 #if defined(PCIC_DEBUG)
3696 3696 if (pcic_debug) {
3697 3697 cmn_err(CE_CONT,
3698 3698 "pcic_set_vcc_level(pcic=%p, VccLevel=%d)\n",
3699 3699 (void *)pcic, socket->VccLevel);
3700 3700 }
3701 3701 #endif
3702 3702
3703 3703 /*
3704 3704 * check VccLevel
3705 3705 * if this is zero, power is being turned off
3706 3706 * if it is non-zero, power is being turned on.
3707 3707 */
3708 3708 if (socket->VccLevel == 0) {
3709 3709 return (0);
3710 3710 }
3711 3711
3712 3712 /*
3713 3713 * range checking for sanity's sake
3714 3714 */
3715 3715 if (socket->VccLevel >= pcic->pc_numpower) {
3716 3716 return (BAD_VCC);
3717 3717 }
3718 3718
3719 3719 switch (pcic->pc_io_type) {
3720 3720 /*
3721 3721 * Yenta-compliant adapters have vcc info in the extended registers
3722 3722 * Other adapters can be added as needed, but the 'default' case
3723 3723 * has been left as it was previously so as not to break existing
3724 3724 * adapters.
3725 3725 */
3726 3726 case PCIC_IO_TYPE_YENTA:
3727 3727 /*
3728 3728 * Here we ignore the VccLevel passed in and read the
3729 3729 * card type from the adapter socket present state register
3730 3730 */
3731 3731 socket_present_state =
3732 3732 ddi_get32(pcic->handle, (uint32_t *)(pcic->ioaddr +
3733 3733 PCIC_PRESENT_STATE_REG));
3734 3734 #if defined(PCIC_DEBUG)
3735 3735 if (pcic_debug) {
3736 3736 cmn_err(CE_CONT,
3737 3737 "socket present state = 0x%x\n",
3738 3738 socket_present_state);
3739 3739 }
3740 3740 #endif
3741 3741 switch (socket_present_state & PCIC_VCC_MASK) {
3742 3742 case PCIC_VCC_3VCARD:
3743 3743 /* fall through */
3744 3744 case PCIC_VCC_3VCARD|PCIC_VCC_5VCARD:
3745 3745 socket->VccLevel = PCIC_VCC_3VLEVEL;
3746 3746 return
3747 3747 (POWER_3VCARD_ENABLE|POWER_OUTPUT_ENABLE);
3748 3748 case PCIC_VCC_5VCARD:
3749 3749 socket->VccLevel = PCIC_VCC_5VLEVEL;
3750 3750 return
3751 3751 (POWER_CARD_ENABLE|POWER_OUTPUT_ENABLE);
3752 3752 default:
3753 3753 /*
3754 3754 * if no card is present, this can be the
3755 3755 * case of a client making a SetSocket call
3756 3756 * after card removal. In this case we return
3757 3757 * the current power level
3758 3758 */
3759 3759 return ((unsigned)ddi_get8(pcic->handle,
3760 3760 pcic->ioaddr + CB_R2_OFFSET +
3761 3761 PCIC_POWER_CONTROL));
3762 3762 }
3763 3763
3764 3764 default:
3765 3765
3766 3766 switch (socket->VccLevel) {
3767 3767 case PCIC_VCC_3VLEVEL:
3768 3768 return (BAD_VCC);
3769 3769 case PCIC_VCC_5VLEVEL:
3770 3770 /* enable Vcc */
3771 3771 return (POWER_CARD_ENABLE|POWER_OUTPUT_ENABLE);
3772 3772 default:
3773 3773 return (BAD_VCC);
3774 3774 }
3775 3775 }
3776 3776 }
3777 3777
3778 3778
3779 3779 /*
3780 3780 * pcic_set_socket()
3781 3781 * Socket Services SetSocket call
3782 3782 * sets basic socket configuration
3783 3783 */
3784 3784 static int
3785 3785 pcic_set_socket(dev_info_t *dip, set_socket_t *socket)
3786 3786 {
3787 3787 anp_t *anp = ddi_get_driver_private(dip);
3788 3788 pcicdev_t *pcic = anp->an_private;
3789 3789 pcic_socket_t *sockp = &pcic->pc_sockets[socket->socket];
3790 3790 int irq, interrupt, mirq;
3791 3791 int powerlevel = 0;
3792 3792 int ind, value, orig_pwrctl;
3793 3793
3794 3794 #if defined(PCIC_DEBUG)
3795 3795 if (pcic_debug) {
3796 3796 cmn_err(CE_CONT,
3797 3797 "pcic_set_socket(dip=%p, socket=%d)"
3798 3798 " Vcc=%d Vpp1=%d Vpp2=%d\n", (void *)dip,
3799 3799 socket->socket, socket->VccLevel, socket->Vpp1Level,
3800 3800 socket->Vpp2Level);
3801 3801 }
3802 3802 #endif
3803 3803 /*
3804 3804 * check VccLevel, etc. before setting mutex
3805 3805 * if this is zero, power is being turned off
3806 3806 * if it is non-zero, power is being turned on.
3807 3807 * the default case is to assume Vcc only.
3808 3808 */
3809 3809
3810 3810 /* this appears to be very implementation specific */
3811 3811
3812 3812 if (socket->Vpp1Level != socket->Vpp2Level)
3813 3813 return (BAD_VPP);
3814 3814
3815 3815 if (socket->VccLevel == 0 || !(sockp->pcs_flags & PCS_CARD_PRESENT)) {
3816 3816 powerlevel = 0;
3817 3817 sockp->pcs_vcc = 0;
3818 3818 sockp->pcs_vpp1 = 0;
3819 3819 sockp->pcs_vpp2 = 0;
3820 3820 } else {
3821 3821 #if defined(PCIC_DEBUG)
3822 3822 pcic_err(dip, 9, "\tVcc=%d Vpp1Level=%d, Vpp2Level=%d\n",
3823 3823 socket->VccLevel, socket->Vpp1Level, socket->Vpp2Level);
3824 3824 #endif
3825 3825 /* valid Vcc power level? */
3826 3826 if (socket->VccLevel >= pcic->pc_numpower)
3827 3827 return (BAD_VCC);
3828 3828
3829 3829 switch (pcic_power[socket->VccLevel].PowerLevel) {
3830 3830 case 33: /* 3.3V */
3831 3831 case 60: /* for bad CIS in Option GPRS card */
3832 3832 if (!(pcic->pc_flags & PCF_33VCAP)) {
3833 3833 cmn_err(CE_WARN,
3834 3834 "%s%d: Bad Request for 3.3V "
3835 3835 "(Controller incapable)\n",
3836 3836 ddi_get_name(pcic->dip),
3837 3837 ddi_get_instance(pcic->dip));
3838 3838 return (BAD_VCC);
3839 3839 }
3840 3840 /* FALLTHROUGH */
3841 3841 case 50: /* 5V */
3842 3842 if ((pcic->pc_io_type == PCIC_IO_TYPE_YENTA) &&
3843 3843 pcic_getcb(pcic, CB_PRESENT_STATE) &
3844 3844 CB_PS_33VCARD) {
3845 3845 /*
3846 3846 * This is actually a 3.3V card.
3847 3847 * Solaris Card Services
3848 3848 * doesn't understand 3.3V
3849 3849 * so we cheat and change
3850 3850 * the setting to the one appropriate to 3.3V.
3851 3851 * Note that this is the entry number
3852 3852 * in the pcic_power[] array.
3853 3853 */
3854 3854 sockp->pcs_vcc = PCIC_VCC_3VLEVEL;
3855 3855 } else
3856 3856 sockp->pcs_vcc = socket->VccLevel;
3857 3857 break;
3858 3858 default:
3859 3859 return (BAD_VCC);
3860 3860 }
3861 3861
3862 3862 /* enable Vcc */
3863 3863 powerlevel = POWER_CARD_ENABLE;
3864 3864
3865 3865 #if defined(PCIC_DEBUG)
3866 3866 if (pcic_debug) {
3867 3867 cmn_err(CE_CONT, "\tVcc=%d powerlevel=%x\n",
3868 3868 socket->VccLevel, powerlevel);
3869 3869 }
3870 3870 #endif
3871 3871 ind = 0; /* default index to 0 power */
3872 3872 if ((int)socket->Vpp1Level >= 0 &&
3873 3873 socket->Vpp1Level < pcic->pc_numpower) {
3874 3874 if (!(pcic_power[socket->Vpp1Level].ValidSignals
3875 3875 & VPP1)) {
3876 3876 return (BAD_VPP);
3877 3877 }
3878 3878 ind = pcic_power[socket->Vpp1Level].PowerLevel/10;
3879 3879 powerlevel |= pcic_vpp_levels[ind];
3880 3880 sockp->pcs_vpp1 = socket->Vpp1Level;
3881 3881 }
3882 3882 if ((int)socket->Vpp2Level >= 0 &&
3883 3883 socket->Vpp2Level < pcic->pc_numpower) {
3884 3884 if (!(pcic_power[socket->Vpp2Level].ValidSignals
3885 3885 & VPP2)) {
3886 3886 return (BAD_VPP);
3887 3887 }
3888 3888 ind = pcic_power[socket->Vpp2Level].PowerLevel/10;
3889 3889 powerlevel |= (pcic_vpp_levels[ind] << 2);
3890 3890 sockp->pcs_vpp2 = socket->Vpp2Level;
3891 3891 }
3892 3892
3893 3893 if (pcic->pc_flags & PCF_VPPX) {
3894 3894 /*
3895 3895 * this adapter doesn't allow separate Vpp1/Vpp2
3896 3896 * if one is turned on, both are turned on and only
3897 3897 * the Vpp1 bits should be set
3898 3898 */
3899 3899 if (sockp->pcs_vpp2 != sockp->pcs_vpp1) {
3900 3900 /* must be the same if one not zero */
3901 3901 if (sockp->pcs_vpp1 != 0 &&
3902 3902 sockp->pcs_vpp2 != 0) {
3903 3903 cmn_err(CE_WARN,
3904 3904 "%s%d: Bad Power Request "
3905 3905 "(Vpp1/2 not the same)\n",
3906 3906 ddi_get_name(pcic->dip),
3907 3907 ddi_get_instance(pcic->dip));
3908 3908 return (BAD_VPP);
3909 3909 }
3910 3910 }
3911 3911 powerlevel &= ~(3<<2);
3912 3912 }
3913 3913
3914 3914 #if defined(PCIC_DEBUG)
3915 3915 if (pcic_debug) {
3916 3916 cmn_err(CE_CONT, "\tpowerlevel=%x, ind=%x\n",
3917 3917 powerlevel, ind);
3918 3918 }
3919 3919 #endif
3920 3920 }
3921 3921 mutex_enter(&pcic->pc_lock); /* protect the registers */
3922 3922
3923 3923 /* turn socket->IREQRouting off while programming */
3924 3924 interrupt = pcic_getb(pcic, socket->socket, PCIC_INTERRUPT);
3925 3925 interrupt &= ~PCIC_INTR_MASK;
3926 3926 if (pcic->pc_flags & PCF_USE_SMI)
3927 3927 interrupt |= PCIC_INTR_ENABLE;
3928 3928 pcic_putb(pcic, socket->socket, PCIC_INTERRUPT, interrupt);
3929 3929
3930 3930 switch (pcic->pc_type) {
3931 3931 case PCIC_INTEL_i82092:
3932 3932 pcic_82092_smiirq_ctl(pcic, socket->socket, PCIC_82092_CTL_IRQ,
3933 3933 PCIC_82092_INT_DISABLE);
3934 3934 break;
3935 3935 default:
3936 3936 break;
3937 3937 } /* switch */
3938 3938
3939 3939 /* the SCIntMask specifies events to detect */
3940 3940 mirq = pcic_getb(pcic, socket->socket, PCIC_MANAGEMENT_INT);
3941 3941
3942 3942 #if defined(PCIC_DEBUG)
3943 3943 if (pcic_debug)
3944 3944 cmn_err(CE_CONT,
3945 3945 "\tSCIntMask=%x, interrupt=%x, mirq=%x\n",
3946 3946 socket->SCIntMask, interrupt, mirq);
3947 3947 #endif
3948 3948 mirq &= ~(PCIC_BD_DETECT|PCIC_BW_DETECT|PCIC_RD_DETECT);
3949 3949 pcic_putb(pcic, socket->socket, PCIC_MANAGEMENT_INT,
3950 3950 mirq & ~PCIC_CHANGE_MASK);
3951 3951
3952 3952 /* save the mask we want to use */
3953 3953 sockp->pcs_intmask = socket->SCIntMask;
3954 3954
3955 3955 /*
3956 3956 * Until there is a card present it's not worth enabling
3957 3957 * any interrupts except "Card detect". This is done
3958 3958 * elsewhere in the driver so don't change things if
3959 3959 * there is no card!
3960 3960 */
3961 3961 if (sockp->pcs_flags & PCS_CARD_PRESENT) {
3962 3962
3963 3963 /* now update the hardware to reflect events desired */
3964 3964 if (sockp->pcs_intmask & SBM_BVD1 || socket->IFType == IF_IO)
3965 3965 mirq |= PCIC_BD_DETECT;
3966 3966
3967 3967 if (sockp->pcs_intmask & SBM_BVD2)
3968 3968 mirq |= PCIC_BW_DETECT;
3969 3969
3970 3970 if (sockp->pcs_intmask & SBM_RDYBSY)
3971 3971 mirq |= PCIC_RD_DETECT;
3972 3972
3973 3973 if (sockp->pcs_intmask & SBM_CD)
3974 3974 mirq |= PCIC_CD_DETECT;
3975 3975 }
3976 3976
3977 3977 if (sockp->pcs_flags & PCS_READY) {
3978 3978 /*
3979 3979 * card just came ready.
3980 3980 * make sure enough time elapses
3981 3981 * before touching it.
3982 3982 */
3983 3983 sockp->pcs_flags &= ~PCS_READY;
3984 3984 pcic_mswait(pcic, socket->socket, 10);
3985 3985 }
3986 3986
3987 3987 #if defined(PCIC_DEBUG)
3988 3988 if (pcic_debug) {
3989 3989 cmn_err(CE_CONT, "\tstatus change set to %x\n", mirq);
3990 3990 }
3991 3991 #endif
3992 3992
3993 3993 switch (pcic->pc_type) {
3994 3994 case PCIC_I82365SL:
3995 3995 case PCIC_VADEM:
3996 3996 case PCIC_VADEM_VG469:
3997 3997 /*
3998 3998 * The Intel version has different options. This is a
3999 3999 * special case of GPI which might be used for eject
4000 4000 */
4001 4001
4002 4002 irq = pcic_getb(pcic, socket->socket, PCIC_CARD_DETECT);
4003 4003 if (sockp->pcs_intmask & (SBM_EJECT|SBM_INSERT) &&
4004 4004 pcic->pc_flags & PCF_GPI_EJECT) {
4005 4005 irq |= PCIC_GPI_ENABLE;
4006 4006 } else {
4007 4007 irq &= ~PCIC_GPI_ENABLE;
4008 4008 }
4009 4009 pcic_putb(pcic, socket->socket, PCIC_CARD_DETECT, irq);
4010 4010 break;
4011 4011 case PCIC_CL_PD6710:
4012 4012 case PCIC_CL_PD6722:
4013 4013 if (socket->IFType == IF_IO) {
4014 4014 pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_2, 0x0);
4015 4015 value = pcic_getb(pcic, socket->socket,
4016 4016 PCIC_MISC_CTL_1);
4017 4017 if (pcic->pc_flags & PCF_AUDIO)
4018 4018 value |= PCIC_MC_SPEAKER_ENB;
4019 4019 pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_1,
4020 4020 value);
4021 4021 } else {
4022 4022 value = pcic_getb(pcic, socket->socket,
4023 4023 PCIC_MISC_CTL_1);
4024 4024 value &= ~PCIC_MC_SPEAKER_ENB;
4025 4025 pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_1,
4026 4026 value);
4027 4027 }
4028 4028 break;
4029 4029 case PCIC_CL_PD6729:
4030 4030 case PCIC_CL_PD6730:
4031 4031 case PCIC_CL_PD6832:
4032 4032 value = pcic_getb(pcic, socket->socket, PCIC_MISC_CTL_1);
4033 4033 if ((socket->IFType == IF_IO) && (pcic->pc_flags & PCF_AUDIO)) {
4034 4034 value |= PCIC_MC_SPEAKER_ENB;
4035 4035 } else {
4036 4036 value &= ~PCIC_MC_SPEAKER_ENB;
4037 4037 }
4038 4038
4039 4039 if (pcic_power[sockp->pcs_vcc].PowerLevel == 33)
4040 4040 value |= PCIC_MC_3VCC;
4041 4041 else
4042 4042 value &= ~PCIC_MC_3VCC;
4043 4043
4044 4044 pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_1, value);
4045 4045 break;
4046 4046
4047 4047 case PCIC_O2_OZ6912:
4048 4048 value = pcic_getcb(pcic, CB_MISCCTRL);
4049 4049 if ((socket->IFType == IF_IO) && (pcic->pc_flags & PCF_AUDIO))
4050 4050 value |= (1<<25);
4051 4051 else
4052 4052 value &= ~(1<<25);
4053 4053 pcic_putcb(pcic, CB_MISCCTRL, value);
4054 4054 if (pcic_power[sockp->pcs_vcc].PowerLevel == 33)
4055 4055 powerlevel |= 0x08;
4056 4056 break;
4057 4057
4058 4058 case PCIC_TI_PCI1250:
4059 4059 case PCIC_TI_PCI1221:
4060 4060 case PCIC_TI_PCI1225:
4061 4061 case PCIC_TI_PCI1410:
4062 4062 case PCIC_ENE_1410:
4063 4063 case PCIC_TI_PCI1510:
4064 4064 case PCIC_TI_PCI1520:
4065 4065 case PCIC_TI_PCI1420:
4066 4066 case PCIC_ENE_1420:
4067 4067 value = ddi_get8(pcic->cfg_handle,
4068 4068 pcic->cfgaddr + PCIC_CRDCTL_REG);
4069 4069 if ((socket->IFType == IF_IO) && (pcic->pc_flags & PCF_AUDIO)) {
4070 4070 value |= PCIC_CRDCTL_SPKR_ENBL;
4071 4071 } else {
4072 4072 value &= ~PCIC_CRDCTL_SPKR_ENBL;
4073 4073 }
4074 4074 ddi_put8(pcic->cfg_handle,
4075 4075 pcic->cfgaddr + PCIC_CRDCTL_REG, value);
4076 4076 if (pcic_power[sockp->pcs_vcc].PowerLevel == 33)
4077 4077 powerlevel |= 0x08;
4078 4078 break;
4079 4079 }
4080 4080
4081 4081 /*
4082 4082 * ctlind processing -- we can ignore this
4083 4083 * there aren't any outputs on the chip for this and
4084 4084 * the GUI will display what it thinks is correct
4085 4085 */
4086 4086
4087 4087 /*
4088 4088 * If outputs are enabled and the power is going off
4089 4089 * turn off outputs first.
4090 4090 */
4091 4091
4092 4092 /* power setup -- if necessary */
4093 4093 orig_pwrctl = pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL);
4094 4094 if ((orig_pwrctl & POWER_OUTPUT_ENABLE) && sockp->pcs_vcc == 0) {
4095 4095 orig_pwrctl &= ~POWER_OUTPUT_ENABLE;
4096 4096 pcic_putb(pcic, socket->socket,
4097 4097 PCIC_POWER_CONTROL, orig_pwrctl);
4098 4098 (void) pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL);
4099 4099 }
4100 4100
4101 4101 if (pcic->pc_flags & PCF_CBPWRCTL) {
4102 4102 value = pcic_cbus_powerctl(pcic, socket->socket);
4103 4103 powerlevel = 0;
4104 4104 } else
4105 4105 value = pcic_exca_powerctl(pcic, socket->socket, powerlevel);
4106 4106
4107 4107 if (value != SUCCESS) {
4108 4108 mutex_exit(&pcic->pc_lock);
4109 4109 return (value);
4110 4110 }
4111 4111
4112 4112 /*
4113 4113 * If outputs were disabled and the power is going on
4114 4114 * turn on outputs afterwards.
4115 4115 */
4116 4116 if (!(orig_pwrctl & POWER_OUTPUT_ENABLE) && sockp->pcs_vcc != 0) {
4117 4117 orig_pwrctl = pcic_getb(pcic, socket->socket,
4118 4118 PCIC_POWER_CONTROL);
4119 4119 orig_pwrctl |= POWER_OUTPUT_ENABLE;
4120 4120 pcic_putb(pcic, socket->socket,
4121 4121 PCIC_POWER_CONTROL, orig_pwrctl);
4122 4122 (void) pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL);
4123 4123 }
4124 4124
4125 4125 /*
4126 4126 * Once we have done the power stuff can re-enable management
4127 4127 * interrupts.
4128 4128 */
4129 4129 pcic_putb(pcic, socket->socket, PCIC_MANAGEMENT_INT, mirq);
4130 4130
4131 4131 #if defined(PCIC_DEBUG)
4132 4132 pcic_err(dip, 8, "\tmanagement int set to %x pwrctl to 0x%x "
4133 4133 "cbctl 0x%x\n",
4134 4134 mirq, pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL),
4135 4135 pcic_getcb(pcic, CB_CONTROL));
4136 4136 #endif
4137 4137
4138 4138 /* irq processing */
4139 4139 if (socket->IFType == IF_IO) {
4140 4140 /* IRQ only for I/O */
4141 4141 irq = socket->IREQRouting & PCIC_INTR_MASK;
4142 4142 value = pcic_getb(pcic, socket->socket, PCIC_INTERRUPT);
4143 4143 value &= ~PCIC_INTR_MASK;
4144 4144
4145 4145 /* to enable I/O operation */
4146 4146 value |= PCIC_IO_CARD | PCIC_RESET;
4147 4147 sockp->pcs_flags |= PCS_CARD_IO;
4148 4148 if (irq != sockp->pcs_irq) {
4149 4149 if (sockp->pcs_irq != 0)
4150 4150 cmn_err(CE_CONT,
4151 4151 "SetSocket: IRQ mismatch %x != %x!\n",
4152 4152 irq, sockp->pcs_irq);
4153 4153 else
4154 4154 sockp->pcs_irq = irq;
4155 4155 }
4156 4156 irq = sockp->pcs_irq;
4157 4157
4158 4158 pcic_putb(pcic, socket->socket, PCIC_INTERRUPT, value);
4159 4159 if (socket->IREQRouting & IRQ_ENABLE) {
4160 4160 pcic_enable_io_intr(pcic, socket->socket, irq);
4161 4161 sockp->pcs_flags |= PCS_IRQ_ENABLED;
4162 4162 } else {
4163 4163 pcic_disable_io_intr(pcic, socket->socket);
4164 4164 sockp->pcs_flags &= ~PCS_IRQ_ENABLED;
4165 4165 }
4166 4166 #if defined(PCIC_DEBUG)
4167 4167 if (pcic_debug) {
4168 4168 cmn_err(CE_CONT,
4169 4169 "\tsocket type is I/O and irq %x is %s\n", irq,
4170 4170 (socket->IREQRouting & IRQ_ENABLE) ?
4171 4171 "enabled" : "not enabled");
4172 4172 xxdmp_all_regs(pcic, socket->socket, 20);
4173 4173 }
4174 4174 #endif
4175 4175 } else {
4176 4176 /* make sure I/O mode is off */
4177 4177
4178 4178 sockp->pcs_irq = 0;
4179 4179
4180 4180 value = pcic_getb(pcic, socket->socket, PCIC_INTERRUPT);
4181 4181 value &= ~PCIC_IO_CARD;
4182 4182 pcic_putb(pcic, socket->socket, PCIC_INTERRUPT, value);
4183 4183 pcic_disable_io_intr(pcic, socket->socket);
4184 4184 sockp->pcs_flags &= ~(PCS_CARD_IO|PCS_IRQ_ENABLED);
4185 4185 }
4186 4186
4187 4187 sockp->pcs_state &= ~socket->State;
4188 4188
4189 4189 mutex_exit(&pcic->pc_lock);
4190 4190 return (SUCCESS);
4191 4191 }
4192 4192
4193 4193 /*
4194 4194 * pcic_inquire_socket()
4195 4195 * SocketServices InquireSocket function
4196 4196 * returns basic characteristics of the socket
4197 4197 */
4198 4198 /*ARGSUSED*/
4199 4199 static int
4200 4200 pcic_inquire_socket(dev_info_t *dip, inquire_socket_t *socket)
4201 4201 {
4202 4202 anp_t *anp = ddi_get_driver_private(dip);
4203 4203 pcicdev_t *pcic = anp->an_private;
4204 4204 int value;
4205 4205
4206 4206 socket->SCIntCaps = PCIC_DEFAULT_INT_CAPS;
4207 4207 socket->SCRptCaps = PCIC_DEFAULT_RPT_CAPS;
4208 4208 socket->CtlIndCaps = PCIC_DEFAULT_CTL_CAPS;
4209 4209 value = pcic->pc_sockets[socket->socket].pcs_flags;
4210 4210 socket->SocketCaps = (value & PCS_SOCKET_IO) ? IF_IO : IF_MEMORY;
4211 4211 socket->ActiveHigh = 0;
4212 4212 /* these are the usable IRQs */
4213 4213 socket->ActiveLow = 0xfff0;
4214 4214 return (SUCCESS);
4215 4215 }
4216 4216
4217 4217 /*
4218 4218 * pcic_inquire_window()
4219 4219 * SocketServices InquireWindow function
4220 4220 * returns detailed characteristics of the window
4221 4221 * this is where windows get tied to sockets
4222 4222 */
4223 4223 /*ARGSUSED*/
4224 4224 static int
4225 4225 pcic_inquire_window(dev_info_t *dip, inquire_window_t *window)
4226 4226 {
4227 4227 int type, socket;
4228 4228
4229 4229 type = window->window % PCIC_NUMWINSOCK;
4230 4230 socket = window->window / PCIC_NUMWINSOCK;
4231 4231
4232 4232 #if defined(PCIC_DEBUG)
4233 4233 if (pcic_debug >= 8)
4234 4234 cmn_err(CE_CONT,
4235 4235 "pcic_inquire_window: window = %d/%d socket=%d\n",
4236 4236 window->window, type, socket);
4237 4237 #endif
4238 4238 if (type < PCIC_IOWINDOWS) {
4239 4239 window->WndCaps = WC_IO|WC_WAIT;
4240 4240 type = IF_IO;
4241 4241 } else {
4242 4242 window->WndCaps = WC_COMMON|WC_ATTRIBUTE|WC_WAIT;
4243 4243 type = IF_MEMORY;
4244 4244 }
4245 4245
4246 4246 /* initialize the socket map - one socket per window */
4247 4247 PR_ZERO(window->Sockets);
4248 4248 PR_SET(window->Sockets, socket);
4249 4249
4250 4250 if (type == IF_IO) {
4251 4251 iowin_char_t *io;
4252 4252 io = &window->iowin_char;
4253 4253 io->IOWndCaps = WC_BASE|WC_SIZE|WC_WENABLE|WC_8BIT|
4254 4254 WC_16BIT;
4255 4255 io->FirstByte = (baseaddr_t)IOMEM_FIRST;
4256 4256 io->LastByte = (baseaddr_t)IOMEM_LAST;
4257 4257 io->MinSize = IOMEM_MIN;
4258 4258 io->MaxSize = IOMEM_MAX;
4259 4259 io->ReqGran = IOMEM_GRAN;
4260 4260 io->AddrLines = IOMEM_DECODE;
4261 4261 io->EISASlot = 0;
4262 4262 } else {
4263 4263 mem_win_char_t *mem;
4264 4264 mem = &window->mem_win_char;
4265 4265 mem->MemWndCaps = WC_BASE|WC_SIZE|WC_WENABLE|WC_8BIT|
4266 4266 WC_16BIT|WC_WP;
4267 4267
4268 4268 mem->FirstByte = (baseaddr_t)MEM_FIRST;
4269 4269 mem->LastByte = (baseaddr_t)MEM_LAST;
4270 4270
4271 4271 mem->MinSize = MEM_MIN;
4272 4272 mem->MaxSize = MEM_MAX;
4273 4273 mem->ReqGran = PCIC_PAGE;
4274 4274 mem->ReqBase = 0;
4275 4275 mem->ReqOffset = PCIC_PAGE;
4276 4276 mem->Slowest = MEM_SPEED_MAX;
4277 4277 mem->Fastest = MEM_SPEED_MIN;
4278 4278 }
4279 4279 return (SUCCESS);
4280 4280 }
4281 4281
4282 4282 /*
4283 4283 * pcic_get_adapter()
4284 4284 * SocketServices GetAdapter function
4285 4285 * this is nearly a no-op.
4286 4286 */
4287 4287 /*ARGSUSED*/
4288 4288 static int
4289 4289 pcic_get_adapter(dev_info_t *dip, get_adapter_t *adapt)
4290 4290 {
4291 4291 anp_t *anp = ddi_get_driver_private(dip);
4292 4292 pcicdev_t *pcic = anp->an_private;
4293 4293
4294 4294 if (pcic->pc_flags & PCF_INTRENAB)
4295 4295 adapt->SCRouting = IRQ_ENABLE;
4296 4296 adapt->state = 0;
4297 4297 return (SUCCESS);
4298 4298 }
4299 4299
4300 4300 /*
4301 4301 * pcic_get_page()
4302 4302 * SocketServices GetPage function
4303 4303 * returns info about the window
4304 4304 */
4305 4305 /*ARGSUSED*/
4306 4306 static int
4307 4307 pcic_get_page(dev_info_t *dip, get_page_t *page)
4308 4308 {
4309 4309 anp_t *anp = ddi_get_driver_private(dip);
4310 4310 pcicdev_t *pcic = anp->an_private;
4311 4311 int socket, window;
4312 4312 pcs_memwin_t *winp;
4313 4313
4314 4314 socket = page->window / PCIC_NUMWINSOCK;
4315 4315 window = page->window % PCIC_NUMWINSOCK;
4316 4316
4317 4317 /* I/O windows are the first two */
4318 4318 if (window < PCIC_IOWINDOWS || socket >= pcic->pc_numsockets) {
4319 4319 return (BAD_WINDOW);
4320 4320 }
4321 4321
4322 4322 winp = &pcic->pc_sockets[socket].pcs_windows[window].mem;
4323 4323
4324 4324 if (page->page != 0)
4325 4325 return (BAD_PAGE);
4326 4326
4327 4327 page->state = 0;
4328 4328 if (winp->pcw_status & PCW_ENABLED)
4329 4329 page->state |= PS_ENABLED;
4330 4330 if (winp->pcw_status & PCW_ATTRIBUTE)
4331 4331 page->state |= PS_ATTRIBUTE;
4332 4332 if (winp->pcw_status & PCW_WP)
4333 4333 page->state |= PS_WP;
4334 4334
4335 4335 page->offset = (off_t)winp->pcw_offset;
4336 4336
4337 4337 return (SUCCESS);
4338 4338 }
4339 4339
4340 4340 /*
4341 4341 * pcic_get_socket()
4342 4342 * SocketServices GetSocket
4343 4343 * returns information about the current socket setting
4344 4344 */
4345 4345 /*ARGSUSED*/
4346 4346 static int
4347 4347 pcic_get_socket(dev_info_t *dip, get_socket_t *socket)
4348 4348 {
4349 4349 anp_t *anp = ddi_get_driver_private(dip);
4350 4350 pcicdev_t *pcic = anp->an_private;
4351 4351 int socknum, irq_enabled;
4352 4352 pcic_socket_t *sockp;
4353 4353
4354 4354 socknum = socket->socket;
4355 4355 sockp = &pcic->pc_sockets[socknum];
4356 4356
4357 4357 socket->SCIntMask = sockp->pcs_intmask;
4358 4358 sockp->pcs_state = pcic_card_state(pcic, sockp);
4359 4359
4360 4360 socket->state = sockp->pcs_state;
4361 4361 if (socket->state & SBM_CD) {
4362 4362 socket->VccLevel = sockp->pcs_vcc;
4363 4363 socket->Vpp1Level = sockp->pcs_vpp1;
4364 4364 socket->Vpp2Level = sockp->pcs_vpp2;
4365 4365 irq_enabled = (sockp->pcs_flags & PCS_IRQ_ENABLED) ?
4366 4366 IRQ_ENABLE : 0;
4367 4367 socket->IRQRouting = sockp->pcs_irq | irq_enabled;
4368 4368 socket->IFType = (sockp->pcs_flags & PCS_CARD_IO) ?
4369 4369 IF_IO : IF_MEMORY;
4370 4370 } else {
4371 4371 socket->VccLevel = 0;
4372 4372 socket->Vpp1Level = 0;
4373 4373 socket->Vpp2Level = 0;
4374 4374 socket->IRQRouting = 0;
4375 4375 socket->IFType = IF_MEMORY;
4376 4376 }
4377 4377 socket->CtlInd = 0; /* no indicators */
4378 4378
4379 4379 return (SUCCESS);
4380 4380 }
4381 4381
4382 4382 /*
4383 4383 * pcic_get_status()
4384 4384 * SocketServices GetStatus
4385 4385 * returns status information about the PC Card in
4386 4386 * the selected socket
4387 4387 */
4388 4388 /*ARGSUSED*/
4389 4389 static int
4390 4390 pcic_get_status(dev_info_t *dip, get_ss_status_t *status)
4391 4391 {
4392 4392 anp_t *anp = ddi_get_driver_private(dip);
4393 4393 pcicdev_t *pcic = anp->an_private;
4394 4394 int socknum, irq_enabled;
4395 4395 pcic_socket_t *sockp;
4396 4396
4397 4397 socknum = status->socket;
4398 4398 sockp = &pcic->pc_sockets[socknum];
4399 4399
4400 4400 status->CardState = pcic_card_state(pcic, sockp);
4401 4401 status->SocketState = sockp->pcs_state;
4402 4402 status->CtlInd = 0; /* no indicators */
4403 4403
4404 4404 if (sockp->pcs_flags & PCS_CARD_PRESENT)
4405 4405 status->SocketState |= SBM_CD;
4406 4406 if (status->CardState & SBM_CD) {
4407 4407 irq_enabled = (sockp->pcs_flags & PCS_CARD_ENABLED) ?
4408 4408 IRQ_ENABLE : 0;
4409 4409 status->IRQRouting = sockp->pcs_irq | irq_enabled;
4410 4410 status->IFType = (sockp->pcs_flags & PCS_CARD_IO) ?
4411 4411 IF_IO : IF_MEMORY;
4412 4412 } else {
4413 4413 status->IRQRouting = 0;
4414 4414 status->IFType = IF_MEMORY;
4415 4415 }
4416 4416
4417 4417 #if defined(PCIC_DEBUG)
4418 4418 if (pcic_debug >= 8)
4419 4419 cmn_err(CE_CONT, "pcic_get_status: socket=%d, CardState=%x,"
4420 4420 "SocketState=%x\n",
4421 4421 socknum, status->CardState, status->SocketState);
4422 4422 #endif
4423 4423 switch (pcic->pc_type) {
4424 4424 uint32_t present_state;
4425 4425 case PCIC_TI_PCI1410:
4426 4426 case PCIC_TI_PCI1520:
4427 4427 case PCIC_TI_PCI1420:
4428 4428 case PCIC_ENE_1420:
4429 4429 case PCIC_TOSHIBA_TOPIC100:
4430 4430 case PCIC_TOSHIBA_TOPIC95:
4431 4431 case PCIC_TOSHIBA_VENDOR:
4432 4432 case PCIC_O2MICRO_VENDOR:
4433 4433 case PCIC_TI_VENDOR:
4434 4434 case PCIC_RICOH_VENDOR:
4435 4435 present_state = pcic_getcb(pcic, CB_PRESENT_STATE);
4436 4436 if (present_state & PCIC_CB_CARD)
4437 4437 status->IFType = IF_CARDBUS;
4438 4438 #if defined(PCIC_DEBUG)
4439 4439 if (pcic_debug >= 8)
4440 4440 cmn_err(CE_CONT,
4441 4441 "pcic_get_status: present_state=0x%x\n",
4442 4442 present_state);
4443 4443 #endif
4444 4444 break;
4445 4445 default:
4446 4446 break;
4447 4447 }
4448 4448
4449 4449 return (SUCCESS);
4450 4450 }
4451 4451
4452 4452 /*
4453 4453 * pcic_get_window()
4454 4454 * SocketServices GetWindow function
4455 4455 * returns state information about the specified window
4456 4456 */
4457 4457 /*ARGSUSED*/
4458 4458 static int
4459 4459 pcic_get_window(dev_info_t *dip, get_window_t *window)
4460 4460 {
4461 4461 anp_t *anp = ddi_get_driver_private(dip);
4462 4462 pcicdev_t *pcic = anp->an_private;
4463 4463 int socket, win;
4464 4464 pcic_socket_t *sockp;
4465 4465 pcs_memwin_t *winp;
4466 4466
4467 4467 socket = window->window / PCIC_NUMWINSOCK;
4468 4468 win = window->window % PCIC_NUMWINSOCK;
4469 4469 #if defined(PCIC_DEBUG)
4470 4470 if (pcic_debug) {
4471 4471 cmn_err(CE_CONT, "pcic_get_window(socket=%d, window=%d)\n",
4472 4472 socket, win);
4473 4473 }
4474 4474 #endif
4475 4475
4476 4476 if (socket > pcic->pc_numsockets)
4477 4477 return (BAD_WINDOW);
4478 4478
4479 4479 sockp = &pcic->pc_sockets[socket];
4480 4480 winp = &sockp->pcs_windows[win].mem;
4481 4481
4482 4482 window->socket = socket;
4483 4483 window->size = winp->pcw_len;
4484 4484 window->speed = winp->pcw_speed;
4485 4485 window->handle = (ddi_acc_handle_t)winp->pcw_handle;
4486 4486 window->base = (uint32_t)winp->pcw_base + winp->pcw_offset;
4487 4487
4488 4488 if (win >= PCIC_IOWINDOWS) {
4489 4489 window->state = 0;
4490 4490 } else {
4491 4491 window->state = WS_IO;
4492 4492 }
4493 4493 if (winp->pcw_status & PCW_ENABLED)
4494 4494 window->state |= WS_ENABLED;
4495 4495
4496 4496 if (winp->pcw_status & PCS_CARD_16BIT)
4497 4497 window->state |= WS_16BIT;
4498 4498 #if defined(PCIC_DEBUG)
4499 4499 if (pcic_debug)
4500 4500 cmn_err(CE_CONT, "\tsize=%d, speed=%d, base=%p, state=%x\n",
4501 4501 window->size, (unsigned)window->speed,
4502 4502 (void *)window->handle, window->state);
4503 4503 #endif
4504 4504
4505 4505 return (SUCCESS);
4506 4506 }
4507 4507
4508 4508 /*
4509 4509 * pcic_ll_reset
4510 4510 * low level reset
4511 4511 * separated out so it can be called when already locked
4512 4512 *
4513 4513 * There are two variables that control the RESET timing:
4514 4514 * pcic_prereset_time - time in mS before asserting RESET
4515 4515 * pcic_reset_time - time in mS to assert RESET
4516 4516 *
4517 4517 */
4518 4518 int pcic_prereset_time = 1;
4519 4519 int pcic_reset_time = 10;
4520 4520 int pcic_postreset_time = 20;
4521 4521 int pcic_vpp_is_vcc_during_reset = 0;
4522 4522
4523 4523 static int
4524 4524 pcic_ll_reset(pcicdev_t *pcic, int socket)
4525 4525 {
4526 4526 int windowbits, iobits;
4527 4527 uint32_t pwr;
4528 4528
4529 4529 /* save windows that were on */
4530 4530 windowbits = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
4531 4531 if (pcic_reset_time == 0)
4532 4532 return (windowbits);
4533 4533 /* turn all windows off */
4534 4534 pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, 0);
4535 4535
4536 4536 #if defined(PCIC_DEBUG)
4537 4537 pcic_err(pcic->dip, 6,
4538 4538 "pcic_ll_reset(socket %d) powerlevel=%x cbctl 0x%x cbps 0x%x\n",
4539 4539 socket, pcic_getb(pcic, socket, PCIC_POWER_CONTROL),
4540 4540 pcic_getcb(pcic, CB_CONTROL),
4541 4541 pcic_getcb(pcic, CB_PRESENT_STATE));
4542 4542 #endif
4543 4543
4544 4544 if (pcic_vpp_is_vcc_during_reset) {
4545 4545
4546 4546 /*
4547 4547 * Set VPP to VCC for the duration of the reset - for aironet
4548 4548 * card.
4549 4549 */
4550 4550 if (pcic->pc_flags & PCF_CBPWRCTL) {
4551 4551 pwr = pcic_getcb(pcic, CB_CONTROL);
4552 4552 pcic_putcb(pcic, CB_CONTROL, (pwr&~CB_C_VPPMASK)|CB_C_VPPVCC);
4553 4553 (void) pcic_getcb(pcic, CB_CONTROL);
4554 4554 } else {
4555 4555 pwr = pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
4556 4556 pcic_putb(pcic, socket, PCIC_POWER_CONTROL,
4557 4557 pwr | 1);
4558 4558 (void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
4559 4559 }
4560 4560 }
4561 4561
4562 4562 if (pcic_prereset_time > 0) {
4563 4563 pcic_err(pcic->dip, 8, "pcic_ll_reset pre_wait %d mS\n",
4564 4564 pcic_prereset_time);
4565 4565 pcic_mswait(pcic, socket, pcic_prereset_time);
4566 4566 }
4567 4567
4568 4568 /* turn interrupts off and start a reset */
4569 4569 pcic_err(pcic->dip, 8,
4570 4570 "pcic_ll_reset turn interrupts off and start a reset\n");
4571 4571 iobits = pcic_getb(pcic, socket, PCIC_INTERRUPT);
4572 4572 iobits &= ~(PCIC_INTR_MASK | PCIC_RESET);
4573 4573 pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits);
4574 4574 (void) pcic_getb(pcic, socket, PCIC_INTERRUPT);
4575 4575
4576 4576 switch (pcic->pc_type) {
4577 4577 case PCIC_INTEL_i82092:
4578 4578 pcic_82092_smiirq_ctl(pcic, socket, PCIC_82092_CTL_IRQ,
4579 4579 PCIC_82092_INT_DISABLE);
4580 4580 break;
4581 4581 default:
4582 4582 break;
4583 4583 } /* switch */
4584 4584
4585 4585 pcic->pc_sockets[socket].pcs_state = 0;
4586 4586
4587 4587 if (pcic_reset_time > 0) {
4588 4588 pcic_err(pcic->dip, 8, "pcic_ll_reset reset_wait %d mS\n",
4589 4589 pcic_reset_time);
4590 4590 pcic_mswait(pcic, socket, pcic_reset_time);
4591 4591 }
4592 4592
4593 4593 pcic_err(pcic->dip, 8, "pcic_ll_reset take it out of reset now\n");
4594 4594
4595 4595 /* take it out of RESET now */
4596 4596 pcic_putb(pcic, socket, PCIC_INTERRUPT, PCIC_RESET | iobits);
4597 4597 (void) pcic_getb(pcic, socket, PCIC_INTERRUPT);
4598 4598
4599 4599 /*
4600 4600 * can't access the card for 20ms, but we really don't
4601 4601 * want to sit around that long. The pcic is still usable.
4602 4602 * memory accesses must wait for RDY to come up.
4603 4603 */
4604 4604 if (pcic_postreset_time > 0) {
4605 4605 pcic_err(pcic->dip, 8, "pcic_ll_reset post_wait %d mS\n",
4606 4606 pcic_postreset_time);
4607 4607 pcic_mswait(pcic, socket, pcic_postreset_time);
4608 4608 }
4609 4609
4610 4610 if (pcic_vpp_is_vcc_during_reset > 1) {
4611 4611
4612 4612 /*
4613 4613 * Return VPP power to whatever it was before.
4614 4614 */
4615 4615 if (pcic->pc_flags & PCF_CBPWRCTL) {
4616 4616 pcic_putcb(pcic, CB_CONTROL, pwr);
4617 4617 (void) pcic_getcb(pcic, CB_CONTROL);
4618 4618 } else {
4619 4619 pcic_putb(pcic, socket, PCIC_POWER_CONTROL, pwr);
4620 4620 (void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
4621 4621 }
4622 4622 }
4623 4623
4624 4624 pcic_err(pcic->dip, 7, "pcic_ll_reset returning 0x%x\n", windowbits);
4625 4625
4626 4626 return (windowbits);
4627 4627 }
4628 4628
4629 4629 /*
4630 4630 * pcic_reset_socket()
4631 4631 * SocketServices ResetSocket function
4632 4632 * puts the PC Card in the socket into the RESET state
4633 4633 * and then takes it out after the the cycle time
4634 4634 * The socket is back to initial state when done
4635 4635 */
4636 4636 static int
4637 4637 pcic_reset_socket(dev_info_t *dip, int socket, int mode)
4638 4638 {
4639 4639 anp_t *anp = ddi_get_driver_private(dip);
4640 4640 pcicdev_t *pcic = anp->an_private;
4641 4641 int value;
4642 4642 int i, mint;
4643 4643 pcic_socket_t *sockp;
4644 4644
4645 4645 #if defined(PCIC_DEBUG)
4646 4646 if (pcic_debug >= 8)
4647 4647 cmn_err(CE_CONT, "pcic_reset_socket(%p, %d, %d/%s)\n",
4648 4648 (void *)dip, socket, mode,
4649 4649 mode == RESET_MODE_FULL ? "full" : "partial");
4650 4650 #endif
4651 4651
4652 4652 mutex_enter(&pcic->pc_lock); /* protect the registers */
4653 4653
4654 4654 /* Turn off management interupts. */
4655 4655 mint = pcic_getb(pcic, socket, PCIC_MANAGEMENT_INT);
4656 4656 pcic_putb(pcic, socket, PCIC_MANAGEMENT_INT, mint & ~PCIC_CHANGE_MASK);
4657 4657
4658 4658 sockp = &pcic->pc_sockets[socket];
4659 4659
4660 4660 value = pcic_ll_reset(pcic, socket);
4661 4661 if (mode == RESET_MODE_FULL) {
4662 4662 /* disable and unmap all mapped windows */
4663 4663 for (i = 0; i < PCIC_NUMWINSOCK; i++) {
4664 4664 if (i < PCIC_IOWINDOWS) {
4665 4665 if (sockp->pcs_windows[i].io.pcw_status &
4666 4666 PCW_MAPPED) {
4667 4667 pcs_iowin_t *io;
4668 4668 io = &sockp->pcs_windows[i].io;
4669 4669 io->pcw_status &= ~PCW_ENABLED;
4670 4670 }
4671 4671 } else {
4672 4672 if (sockp->pcs_windows[i].mem.pcw_status &
4673 4673 PCW_MAPPED) {
4674 4674 pcs_memwin_t *mem;
4675 4675 mem = &sockp->pcs_windows[i].mem;
4676 4676 mem->pcw_status &= ~PCW_ENABLED;
4677 4677 }
4678 4678 }
4679 4679 }
4680 4680 } else {
4681 4681 /* turn windows back on */
4682 4682 pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, value);
4683 4683 /* wait the rest of the time here */
4684 4684 pcic_mswait(pcic, socket, 10);
4685 4685 }
4686 4686 pcic_putb(pcic, socket, PCIC_MANAGEMENT_INT, mint);
4687 4687 mutex_exit(&pcic->pc_lock);
4688 4688 return (SUCCESS);
4689 4689 }
4690 4690
4691 4691 /*
4692 4692 * pcic_set_interrupt()
4693 4693 * SocketServices SetInterrupt function
4694 4694 */
4695 4695 static int
4696 4696 pcic_set_interrupt(dev_info_t *dip, set_irq_handler_t *handler)
4697 4697 {
4698 4698 anp_t *anp = ddi_get_driver_private(dip);
4699 4699 pcicdev_t *pcic = anp->an_private;
4700 4700 int value = DDI_SUCCESS;
4701 4701 inthandler_t *intr;
4702 4702
4703 4703 #if defined(PCIC_DEBUG)
4704 4704 if (pcic_debug) {
4705 4705 cmn_err(CE_CONT,
4706 4706 "pcic_set_interrupt: entered pc_intr_mode=0x%x\n",
4707 4707 pcic->pc_intr_mode);
4708 4708 cmn_err(CE_CONT,
4709 4709 "\t irq_top=%p handler=%p handler_id=%x\n",
4710 4710 (void *)pcic->irq_top, (void *)handler->handler,
4711 4711 handler->handler_id);
4712 4712 }
4713 4713 #endif
4714 4714
4715 4715 /*
4716 4716 * If we're on a PCI bus, we route all IO IRQs through a single
4717 4717 * PCI interrupt (typically INT A#) so we don't have to do
4718 4718 * much other than add the caller to general interrupt handler
4719 4719 * and set some state.
4720 4720 */
4721 4721
4722 4722 intr = kmem_zalloc(sizeof (inthandler_t), KM_NOSLEEP);
4723 4723 if (intr == NULL)
4724 4724 return (NO_RESOURCE);
4725 4725
4726 4726 switch (pcic->pc_intr_mode) {
4727 4727 case PCIC_INTR_MODE_PCI_1:
4728 4728 /*
4729 4729 * We only allow above-lock-level IO IRQ handlers
4730 4730 * in the PCI bus case.
4731 4731 */
4732 4732
4733 4733 mutex_enter(&pcic->intr_lock);
4734 4734
4735 4735 if (pcic->irq_top == NULL) {
4736 4736 pcic->irq_top = intr;
4737 4737 pcic->irq_current = pcic->irq_top;
4738 4738 } else {
4739 4739 while (pcic->irq_current->next != NULL)
4740 4740 pcic->irq_current = pcic->irq_current->next;
4741 4741 pcic->irq_current->next = intr;
4742 4742 pcic->irq_current = pcic->irq_current->next;
4743 4743 }
4744 4744
4745 4745 pcic->irq_current->intr =
4746 4746 (ddi_intr_handler_t *)handler->handler;
4747 4747 pcic->irq_current->handler_id = handler->handler_id;
4748 4748 pcic->irq_current->arg1 = handler->arg1;
4749 4749 pcic->irq_current->arg2 = handler->arg2;
4750 4750 pcic->irq_current->socket = handler->socket;
4751 4751
4752 4752 mutex_exit(&pcic->intr_lock);
4753 4753
4754 4754 handler->iblk_cookie = &pcic->pc_pri;
4755 4755 handler->idev_cookie = &pcic->pc_dcookie;
4756 4756 break;
4757 4757
4758 4758 default:
4759 4759 intr->intr = (ddi_intr_handler_t *)handler->handler;
4760 4760 intr->handler_id = handler->handler_id;
4761 4761 intr->arg1 = handler->arg1;
4762 4762 intr->arg2 = handler->arg2;
4763 4763 intr->socket = handler->socket;
4764 4764 intr->irq = handler->irq;
4765 4765
4766 4766 /*
4767 4767 * need to revisit this to see if interrupts can be
4768 4768 * shared someday. Note that IRQ is set in the common
4769 4769 * code.
4770 4770 */
4771 4771 mutex_enter(&pcic->pc_lock);
4772 4772 if (pcic->pc_handlers == NULL) {
4773 4773 pcic->pc_handlers = intr;
4774 4774 intr->next = intr->prev = intr;
4775 4775 } else {
4776 4776 insque(intr, pcic->pc_handlers);
4777 4777 }
4778 4778 mutex_exit(&pcic->pc_lock);
4779 4779
4780 4780 break;
4781 4781 }
4782 4782
4783 4783 /*
4784 4784 * need to fill in cookies in event of multiple high priority
4785 4785 * interrupt handlers on same IRQ
4786 4786 */
4787 4787
4788 4788 #if defined(PCIC_DEBUG)
4789 4789 if (pcic_debug) {
4790 4790 cmn_err(CE_CONT,
4791 4791 "pcic_set_interrupt: exit irq_top=%p value=%d\n",
4792 4792 (void *)pcic->irq_top, value);
4793 4793 }
4794 4794 #endif
4795 4795
4796 4796 if (value == DDI_SUCCESS) {
4797 4797 return (SUCCESS);
4798 4798 } else {
4799 4799 return (BAD_IRQ);
4800 4800 }
4801 4801 }
4802 4802
4803 4803 /*
4804 4804 * pcic_clear_interrupt()
4805 4805 * SocketServices ClearInterrupt function
4806 4806 *
4807 4807 * Interrupts for PCIC are complicated by the fact that we must
4808 4808 * follow several different models for interrupts.
4809 4809 * ISA: there is an interrupt per adapter and per socket and
4810 4810 * they can't be shared.
4811 4811 * PCI: some adapters have one PCI interrupt available while others
4812 4812 * have up to 4. Solaris may or may not allow us to use more
4813 4813 * than 1 so we essentially share them all at this point.
4814 4814 * Hybrid: PCI bridge but interrupts wired to host interrupt controller.
4815 4815 * This is like ISA but we have to fudge and create an intrspec
4816 4816 * that PCI's parent understands and bypass the PCI nexus.
4817 4817 * multifunction: this requires sharing the interrupts on a per-socket
4818 4818 * basis.
4819 4819 */
4820 4820 static int
4821 4821 pcic_clear_interrupt(dev_info_t *dip, clear_irq_handler_t *handler)
4822 4822 {
4823 4823 anp_t *anp = ddi_get_driver_private(dip);
4824 4824 pcicdev_t *pcic = anp->an_private;
4825 4825 inthandler_t *intr, *prev, *current;
4826 4826 int i;
4827 4827
4828 4828 /*
4829 4829 * If we're on a PCI bus, we route all IO IRQs through a single
4830 4830 * PCI interrupt (typically INT A#) so we don't have to do
4831 4831 * much other than remove the caller from the general
4832 4832 * interrupt handler callout list.
4833 4833 */
4834 4834
4835 4835 #if defined(PCIC_DEBUG)
4836 4836 if (pcic_debug) {
4837 4837 cmn_err(CE_CONT,
4838 4838 "pcic_clear_interrupt: entered pc_intr_mode=0x%x\n",
4839 4839 pcic->pc_intr_mode);
4840 4840 cmn_err(CE_CONT,
4841 4841 "\t irq_top=%p handler=%p handler_id=%x\n",
4842 4842 (void *)pcic->irq_top, (void *)handler->handler,
4843 4843 handler->handler_id);
4844 4844 }
4845 4845 #endif
4846 4846
4847 4847 switch (pcic->pc_intr_mode) {
4848 4848 case PCIC_INTR_MODE_PCI_1:
4849 4849
4850 4850 mutex_enter(&pcic->intr_lock);
4851 4851 if (pcic->irq_top == NULL) {
4852 4852 mutex_exit(&pcic->intr_lock);
4853 4853 return (BAD_IRQ);
4854 4854 }
4855 4855
4856 4856 intr = NULL;
4857 4857 pcic->irq_current = pcic->irq_top;
4858 4858
4859 4859 while ((pcic->irq_current != NULL) &&
4860 4860 (pcic->irq_current->handler_id !=
4861 4861 handler->handler_id)) {
4862 4862 intr = pcic->irq_current;
4863 4863 pcic->irq_current = pcic->irq_current->next;
4864 4864 }
4865 4865
4866 4866 if (pcic->irq_current == NULL) {
4867 4867 mutex_exit(&pcic->intr_lock);
4868 4868 return (BAD_IRQ);
4869 4869 }
4870 4870
4871 4871 if (intr != NULL) {
4872 4872 intr->next = pcic->irq_current->next;
4873 4873 } else {
4874 4874 pcic->irq_top = pcic->irq_current->next;
4875 4875 }
4876 4876
4877 4877 current = pcic->irq_current;
4878 4878 pcic->irq_current = pcic->irq_top;
4879 4879 mutex_exit(&pcic->intr_lock);
4880 4880 kmem_free(current, sizeof (inthandler_t));
4881 4881
4882 4882 break;
4883 4883
4884 4884 default:
4885 4885
4886 4886 mutex_enter(&pcic->pc_lock);
4887 4887 intr = pcic_handlers;
4888 4888 prev = (inthandler_t *)&pcic_handlers;
4889 4889
4890 4890 while (intr != NULL) {
4891 4891 if (intr->handler_id == handler->handler_id) {
4892 4892 i = intr->irq & PCIC_INTR_MASK;
4893 4893 if (--pcic_irq_map[i].count == 0) {
4894 4894 /* multi-handler form */
4895 4895 (void) ddi_intr_disable(pcic->pc_intr_htblp[i]);
4896 4896 (void) ddi_intr_remove_handler(
4897 4897 pcic->pc_intr_htblp[i]);
4898 4898 (void) ddi_intr_free(pcic->pc_intr_htblp[i]);
4899 4899 (void) pcmcia_return_intr(pcic->dip, i);
4900 4900 #if defined(PCIC_DEBUG)
4901 4901 if (pcic_debug) {
4902 4902 cmn_err(CE_CONT,
4903 4903 "removing interrupt %d at %s "
4904 4904 "priority\n", i, "high");
4905 4905 cmn_err(CE_CONT,
4906 4906 "ddi_remove_intr(%p, %x, %p)\n",
4907 4907 (void *)dip,
4908 4908 0,
4909 4909 (void *)intr->iblk_cookie);
4910 4910 }
4911 4911 #endif
4912 4912 }
4913 4913 prev->next = intr->next;
4914 4914 kmem_free(intr, sizeof (inthandler_t));
4915 4915 intr = prev->next;
4916 4916 } else {
4917 4917 prev = intr;
4918 4918 intr = intr->next;
4919 4919 } /* if (handler_id) */
4920 4920 } /* while */
4921 4921
4922 4922 mutex_exit(&pcic->pc_lock);
4923 4923 }
4924 4924
4925 4925 #if defined(PCIC_DEBUG)
4926 4926 if (pcic_debug) {
4927 4927 cmn_err(CE_CONT,
4928 4928 "pcic_clear_interrupt: exit irq_top=%p\n",
4929 4929 (void *)pcic->irq_top);
4930 4930 }
4931 4931 #endif
4932 4932
4933 4933
4934 4934 return (SUCCESS);
4935 4935 }
4936 4936
4937 4937 struct intel_regs {
4938 4938 char *name;
4939 4939 int off;
4940 4940 char *fmt;
4941 4941 } iregs[] = {
4942 4942 {"ident ", 0},
4943 4943 {"if-status ", 1, "\020\1BVD1\2BVD2\3CD1\4CD2\5WP\6RDY\7PWR\10~GPI"},
4944 4944 {"power ", 2, "\020\1Vpp1c0\2Vpp1c1\3Vpp2c0\4Vpp2c1\5PE\6AUTO"
4945 4945 "\7DRD\10OE"},
4946 4946 {"cardstatus", 4, "\020\1BD\2BW\3RC\4CD\5GPI\6R1\7R2\010R3"},
4947 4947 {"enable ", 6, "\020\1MW0\2MW1\3MW2\4MW3\5MW4\6MEM16\7IO0\10IO1"},
4948 4948 {"cd-gcr ", 0x16, "\020\1MDI16\2CRE\3GPIE\4GPIT\5CDR\6S/W"},
4949 4949 {"GCR ", 0x1e, "\020\1PD\2LEVEL\3WCSC\4PLS14"},
4950 4950 {"int-gcr ", 3, "\020\5INTR\6IO\7~RST\10RI"},
4951 4951 {"management", 5, "\020\1BDE\2BWE\3RE\4CDE"},
4952 4952 {"volt-sense", 0x1f, "\020\1A_VS1\2A_VS2\3B_VS1\4B_VS2"},
4953 4953 {"volt-sel ", 0x2f, "\020\5EXTCONF\6BUSSELECT\7MIXEDV\10ISAV"},
4954 4954 {"VG ext A ", 0x3c, "\20\3IVS\4CABLE\5CSTEP\6TEST\7RIO"},
4955 4955 {"io-ctrl ", 7, "\020\1DS0\2IOCS0\3ZWS0\4WS0\5DS1\6IOS1\7ZWS1\10WS1"},
4956 4956 {"io0-slow ", 8},
4957 4957 {"io0-shi ", 9},
4958 4958 {"io0-elow ", 0xa},
4959 4959 {"io0-ehi ", 0xb},
4960 4960 {"io1-slow ", 0xc},
4961 4961 {"io1-shi ", 0xd},
4962 4962 {"io1-elow ", 0xe},
4963 4963 {"io1-ehi ", 0xf},
4964 4964 {"mem0-slow ", 0x10},
4965 4965 {"mem0-shi ", 0x11, "\020\7ZW\10DS"},
4966 4966 {"mem0-elow ", 0x12},
4967 4967 {"mem0-ehi ", 0x13, "\020\7WS0\10WS1"},
4968 4968 {"card0-low ", 0x14},
4969 4969 {"card0-hi ", 0x15, "\020\7AM\10WP"},
4970 4970 {"mem1-slow ", 0x18},
4971 4971 {"mem1-shi ", 0x19, "\020\7ZW\10DS"},
4972 4972 {"mem1-elow ", 0x1a},
4973 4973 {"mem1-ehi ", 0x1b, "\020\7WS0\10WS1"},
4974 4974 {"card1-low ", 0x1c},
4975 4975 {"card1-hi ", 0x1d, "\020\7AM\10WP"},
4976 4976 {"mem2-slow ", 0x20},
4977 4977 {"mem2-shi ", 0x21, "\020\7ZW\10DS"},
4978 4978 {"mem2-elow ", 0x22},
4979 4979 {"mem2-ehi ", 0x23, "\020\7WS0\10WS1"},
4980 4980 {"card2-low ", 0x24},
4981 4981 {"card2-hi ", 0x25, "\020\7AM\10WP"},
4982 4982 {"mem3-slow ", 0x28},
4983 4983 {"mem3-shi ", 0x29, "\020\7ZW\10DS"},
4984 4984 {"mem3-elow ", 0x2a},
4985 4985 {"mem3-ehi ", 0x2b, "\020\7WS0\10WS1"},
4986 4986 {"card3-low ", 0x2c},
4987 4987 {"card3-hi ", 0x2d, "\020\7AM\10WP"},
4988 4988
4989 4989 {"mem4-slow ", 0x30},
4990 4990 {"mem4-shi ", 0x31, "\020\7ZW\10DS"},
4991 4991 {"mem4-elow ", 0x32},
4992 4992 {"mem4-ehi ", 0x33, "\020\7WS0\10WS1"},
4993 4993 {"card4-low ", 0x34},
4994 4994 {"card4-hi ", 0x35, "\020\7AM\10WP"},
4995 4995 {"mpage0 ", 0x40},
4996 4996 {"mpage1 ", 0x41},
4997 4997 {"mpage2 ", 0x42},
4998 4998 {"mpage3 ", 0x43},
4999 4999 {"mpage4 ", 0x44},
5000 5000 {NULL},
5001 5001 };
↓ open down ↓ |
4578 lines elided |
↑ open up ↑ |
5002 5002
5003 5003 static struct intel_regs cregs[] = {
5004 5004 {"misc-ctl1 ", 0x16, "\20\2VCC3\3PMI\4PSI\5SPKR\10INPACK"},
5005 5005 {"fifo ", 0x17, "\20\6DIOP\7DMEMP\10EMPTY"},
5006 5006 {"misc-ctl2 ", 0x1e, "\20\1XCLK\2LOW\3SUSP\4CORE5V\5TCD\10RIOUT"},
5007 5007 {"chip-info ", 0x1f, "\20\6DUAL"},
5008 5008 {"IO-offlow0", 0x36},
5009 5009 {"IO-offhi0 ", 0x37},
5010 5010 {"IO-offlow1", 0x38},
5011 5011 {"IO-offhi1 ", 0x39},
5012 - NULL,
5012 + {NULL}
5013 5013 };
5014 5014
5015 5015 static struct intel_regs cxregs[] = {
5016 5016 {"ext-ctl-1 ", 0x03,
5017 5017 "\20\1VCCLCK\2AUTOCLR\3LED\4INVIRQC\5INVIRQM\6PUC"},
5018 5018 {"misc-ctl3 ", 0x25, "\20\5HWSUSP"},
5019 5019 {"mem0-up ", 0x05},
5020 5020 {"mem1-up ", 0x06},
5021 5021 {"mem2-up ", 0x07},
5022 5022 {"mem3-up ", 0x08},
5023 5023 {"mem4-up ", 0x09},
5024 5024 {NULL}
5025 5025 };
5026 5026
5027 5027 void
5028 5028 xxdmp_cl_regs(pcicdev_t *pcic, int socket, uint32_t len)
5029 5029 {
5030 5030 int i, value, j;
5031 5031 char buff[256];
5032 5032 char *fmt;
5033 5033
5034 5034 cmn_err(CE_CONT, "--------- Cirrus Logic Registers --------\n");
5035 5035 for (buff[0] = '\0', i = 0; cregs[i].name != NULL && len-- != 0; i++) {
5036 5036 int sval;
5037 5037 if (cregs[i].off == PCIC_MISC_CTL_2)
5038 5038 sval = 0;
5039 5039 else
5040 5040 sval = socket;
5041 5041 value = pcic_getb(pcic, sval, cregs[i].off);
5042 5042 if (i & 1) {
5043 5043 if (cregs[i].fmt)
5044 5044 fmt = "%s\t%s\t%b\n";
5045 5045 else
5046 5046 fmt = "%s\t%s\t%x\n";
5047 5047 cmn_err(CE_CONT, fmt, buff,
5048 5048 cregs[i].name, value, cregs[i].fmt);
5049 5049 buff[0] = '\0';
5050 5050 } else {
5051 5051 if (cregs[i].fmt)
5052 5052 fmt = "\t%s\t%b";
5053 5053 else
5054 5054 fmt = "\t%s\t%x";
5055 5055 (void) sprintf(buff, fmt,
5056 5056 cregs[i].name, value, cregs[i].fmt);
5057 5057 for (j = strlen(buff); j < 40; j++)
5058 5058 buff[j] = ' ';
5059 5059 buff[40] = '\0';
5060 5060 }
5061 5061 }
5062 5062 cmn_err(CE_CONT, "%s\n", buff);
5063 5063
5064 5064 i = pcic_getb(pcic, socket, PCIC_TIME_SETUP_0);
5065 5065 j = pcic_getb(pcic, socket, PCIC_TIME_SETUP_1);
5066 5066 cmn_err(CE_CONT, "\tsetup-tim0\t%x\tsetup-tim1\t%x\n", i, j);
5067 5067
5068 5068 i = pcic_getb(pcic, socket, PCIC_TIME_COMMAND_0);
5069 5069 j = pcic_getb(pcic, socket, PCIC_TIME_COMMAND_1);
5070 5070 cmn_err(CE_CONT, "\tcmd-tim0 \t%x\tcmd-tim1 \t%x\n", i, j);
5071 5071
5072 5072 i = pcic_getb(pcic, socket, PCIC_TIME_RECOVER_0);
5073 5073 j = pcic_getb(pcic, socket, PCIC_TIME_RECOVER_1);
5074 5074 cmn_err(CE_CONT, "\trcvr-tim0 \t%x\trcvr-tim1 \t%x\n", i, j);
5075 5075
5076 5076 cmn_err(CE_CONT, "--------- Extended Registers --------\n");
5077 5077
5078 5078 for (buff[0] = '\0', i = 0; cxregs[i].name != NULL && len-- != 0; i++) {
5079 5079 value = clext_reg_read(pcic, socket, cxregs[i].off);
5080 5080 if (i & 1) {
5081 5081 if (cxregs[i].fmt)
5082 5082 fmt = "%s\t%s\t%b\n";
5083 5083 else
5084 5084 fmt = "%s\t%s\t%x\n";
5085 5085 cmn_err(CE_CONT, fmt, buff,
5086 5086 cxregs[i].name, value, cxregs[i].fmt);
5087 5087 buff[0] = '\0';
5088 5088 } else {
5089 5089 if (cxregs[i].fmt)
5090 5090 fmt = "\t%s\t%b";
5091 5091 else
5092 5092 fmt = "\t%s\t%x";
5093 5093 (void) sprintf(buff, fmt,
5094 5094 cxregs[i].name, value, cxregs[i].fmt);
5095 5095 for (j = strlen(buff); j < 40; j++)
5096 5096 buff[j] = ' ';
5097 5097 buff[40] = '\0';
5098 5098 }
5099 5099 }
5100 5100 }
5101 5101
5102 5102 #if defined(PCIC_DEBUG)
5103 5103 static void
5104 5104 xxdmp_all_regs(pcicdev_t *pcic, int socket, uint32_t len)
5105 5105 {
5106 5106 int i, value, j;
5107 5107 char buff[256];
5108 5108 char *fmt;
5109 5109
5110 5110 #if defined(PCIC_DEBUG)
5111 5111 if (pcic_debug < 2)
5112 5112 return;
5113 5113 #endif
5114 5114 cmn_err(CE_CONT,
5115 5115 "----------- PCIC Registers for socket %d---------\n",
5116 5116 socket);
5117 5117 cmn_err(CE_CONT,
5118 5118 "\tname value name value\n");
5119 5119
5120 5120 for (buff[0] = '\0', i = 0; iregs[i].name != NULL && len-- != 0; i++) {
5121 5121 value = pcic_getb(pcic, socket, iregs[i].off);
5122 5122 if (i & 1) {
5123 5123 if (iregs[i].fmt)
5124 5124 fmt = "%s\t%s\t%b\n";
5125 5125 else
5126 5126 fmt = "%s\t%s\t%x\n";
5127 5127 cmn_err(CE_CONT, fmt, buff,
5128 5128 iregs[i].name, value, iregs[i].fmt);
5129 5129 buff[0] = '\0';
5130 5130 } else {
5131 5131 if (iregs[i].fmt)
5132 5132 fmt = "\t%s\t%b";
5133 5133 else
5134 5134 fmt = "\t%s\t%x";
5135 5135 (void) sprintf(buff, fmt,
5136 5136 iregs[i].name, value, iregs[i].fmt);
5137 5137 for (j = strlen(buff); j < 40; j++)
5138 5138 buff[j] = ' ';
5139 5139 buff[40] = '\0';
5140 5140 }
5141 5141 }
5142 5142 switch (pcic->pc_type) {
5143 5143 case PCIC_CL_PD6710:
5144 5144 case PCIC_CL_PD6722:
5145 5145 case PCIC_CL_PD6729:
5146 5146 case PCIC_CL_PD6832:
5147 5147 (void) xxdmp_cl_regs(pcic, socket, 0xFFFF);
5148 5148 break;
5149 5149 }
5150 5150 cmn_err(CE_CONT, "%s\n", buff);
5151 5151 }
5152 5152 #endif
5153 5153
5154 5154 /*
5155 5155 * pcic_mswait(ms)
5156 5156 * sleep ms milliseconds
5157 5157 * call drv_usecwait once for each ms
5158 5158 */
5159 5159 static void
5160 5160 pcic_mswait(pcicdev_t *pcic, int socket, int ms)
5161 5161 {
5162 5162 if (ms) {
5163 5163 pcic->pc_sockets[socket].pcs_flags |= PCS_WAITING;
5164 5164 pcic_mutex_exit(&pcic->pc_lock);
5165 5165 delay(drv_usectohz(ms*1000));
5166 5166 pcic_mutex_enter(&pcic->pc_lock);
5167 5167 pcic->pc_sockets[socket].pcs_flags &= ~PCS_WAITING;
5168 5168 }
5169 5169 }
5170 5170
5171 5171 /*
5172 5172 * pcic_check_ready(pcic, index, off)
5173 5173 * Wait for card to come ready
5174 5174 * We only wait if the card is NOT in RESET
5175 5175 * and power is on.
5176 5176 */
5177 5177 static boolean_t
5178 5178 pcic_check_ready(pcicdev_t *pcic, int socket)
5179 5179 {
5180 5180 int ifstate, intstate;
5181 5181
5182 5182 intstate = pcic_getb(pcic, socket, PCIC_INTERRUPT);
5183 5183 ifstate = pcic_getb(pcic, socket, PCIC_INTERFACE_STATUS);
5184 5184
5185 5185 if ((intstate & PCIC_RESET) &&
5186 5186 ((ifstate & (PCIC_READY|PCIC_POWER_ON|PCIC_ISTAT_CD_MASK)) ==
5187 5187 (PCIC_READY|PCIC_POWER_ON|PCIC_CD_PRESENT_OK)))
5188 5188 return (B_TRUE);
5189 5189
5190 5190 #ifdef PCIC_DEBUG
5191 5191 pcic_err(NULL, 5, "pcic_check_read: Card not ready, intstate = 0x%x, "
5192 5192 "ifstate = 0x%x\n", intstate, ifstate);
5193 5193 if (pcic_debug) {
5194 5194 pcic_debug += 4;
5195 5195 xxdmp_all_regs(pcic, socket, -1);
5196 5196 pcic_debug -= 4;
5197 5197 }
5198 5198 #endif
5199 5199 return (B_FALSE);
5200 5200 }
5201 5201
5202 5202 /*
5203 5203 * Cirrus Logic extended register read/write routines
5204 5204 */
5205 5205 static int
5206 5206 clext_reg_read(pcicdev_t *pcic, int sn, uchar_t ext_reg)
5207 5207 {
5208 5208 int val;
5209 5209
5210 5210 switch (pcic->pc_io_type) {
5211 5211 case PCIC_IO_TYPE_YENTA:
5212 5212 val = ddi_get8(pcic->handle,
5213 5213 pcic->ioaddr + CB_CLEXT_OFFSET + ext_reg);
5214 5214 break;
5215 5215 default:
5216 5216 pcic_putb(pcic, sn, PCIC_CL_EXINDEX, ext_reg);
5217 5217 val = pcic_getb(pcic, sn, PCIC_CL_EXINDEX + 1);
5218 5218 break;
5219 5219 }
5220 5220
5221 5221 return (val);
5222 5222 }
5223 5223
5224 5224 static void
5225 5225 clext_reg_write(pcicdev_t *pcic, int sn, uchar_t ext_reg, uchar_t value)
5226 5226 {
5227 5227 switch (pcic->pc_io_type) {
5228 5228 case PCIC_IO_TYPE_YENTA:
5229 5229 ddi_put8(pcic->handle,
5230 5230 pcic->ioaddr + CB_CLEXT_OFFSET + ext_reg, value);
5231 5231 break;
5232 5232 default:
5233 5233 pcic_putb(pcic, sn, PCIC_CL_EXINDEX, ext_reg);
5234 5234 pcic_putb(pcic, sn, PCIC_CL_EXINDEX + 1, value);
5235 5235 break;
5236 5236 }
5237 5237 }
5238 5238
5239 5239 /*
5240 5240 * Misc PCI functions
5241 5241 */
5242 5242 static void
5243 5243 pcic_iomem_pci_ctl(ddi_acc_handle_t handle, uchar_t *cfgaddr, unsigned flags)
5244 5244 {
5245 5245 unsigned cmd;
5246 5246
5247 5247 if (flags & (PCIC_ENABLE_IO | PCIC_ENABLE_MEM)) {
5248 5248 cmd = ddi_get16(handle, (ushort_t *)(cfgaddr + 4));
5249 5249 if ((cmd & (PCI_COMM_IO|PCI_COMM_MAE)) ==
5250 5250 (PCI_COMM_IO|PCI_COMM_MAE))
5251 5251 return;
5252 5252
5253 5253 if (flags & PCIC_ENABLE_IO)
5254 5254 cmd |= PCI_COMM_IO;
5255 5255
5256 5256 if (flags & PCIC_ENABLE_MEM)
5257 5257 cmd |= PCI_COMM_MAE;
5258 5258
5259 5259 ddi_put16(handle, (ushort_t *)(cfgaddr + 4), cmd);
5260 5260 } /* if (PCIC_ENABLE_IO | PCIC_ENABLE_MEM) */
5261 5261 }
5262 5262
5263 5263 /*
5264 5264 * pcic_find_pci_type - Find and return PCI-PCMCIA adapter type
5265 5265 */
5266 5266 static int
5267 5267 pcic_find_pci_type(pcicdev_t *pcic)
5268 5268 {
5269 5269 uint32_t vend, device;
5270 5270
5271 5271 vend = ddi_getprop(DDI_DEV_T_ANY, pcic->dip,
5272 5272 DDI_PROP_CANSLEEP|DDI_PROP_DONTPASS,
5273 5273 "vendor-id", -1);
5274 5274 device = ddi_getprop(DDI_DEV_T_ANY, pcic->dip,
5275 5275 DDI_PROP_CANSLEEP|DDI_PROP_DONTPASS,
5276 5276 "device-id", -1);
5277 5277
5278 5278 device = PCI_ID(vend, device);
5279 5279 pcic->pc_type = device;
5280 5280 pcic->pc_chipname = "PCI:unknown";
5281 5281
5282 5282 switch (device) {
5283 5283 case PCIC_INTEL_i82092:
5284 5284 pcic->pc_chipname = PCIC_TYPE_i82092;
5285 5285 break;
5286 5286 case PCIC_CL_PD6729:
5287 5287 pcic->pc_chipname = PCIC_TYPE_PD6729;
5288 5288 /*
5289 5289 * Some 6730's incorrectly identify themselves
5290 5290 * as a 6729, so we need to do some more tests
5291 5291 * here to see if the device that's claiming
5292 5292 * to be a 6729 is really a 6730.
5293 5293 */
5294 5294 if ((clext_reg_read(pcic, 0, PCIC_CLEXT_MISC_CTL_3) &
5295 5295 PCIC_CLEXT_MISC_CTL_3_REV_MASK) ==
5296 5296 0) {
5297 5297 pcic->pc_chipname = PCIC_TYPE_PD6730;
5298 5298 pcic->pc_type = PCIC_CL_PD6730;
5299 5299 }
5300 5300 break;
5301 5301 case PCIC_CL_PD6730:
5302 5302 pcic->pc_chipname = PCIC_TYPE_PD6730;
5303 5303 break;
5304 5304 case PCIC_CL_PD6832:
5305 5305 pcic->pc_chipname = PCIC_TYPE_PD6832;
5306 5306 break;
5307 5307 case PCIC_SMC_34C90:
5308 5308 pcic->pc_chipname = PCIC_TYPE_34C90;
5309 5309 break;
5310 5310 case PCIC_TOSHIBA_TOPIC95:
5311 5311 pcic->pc_chipname = PCIC_TYPE_TOPIC95;
5312 5312 break;
5313 5313 case PCIC_TOSHIBA_TOPIC100:
5314 5314 pcic->pc_chipname = PCIC_TYPE_TOPIC100;
5315 5315 break;
5316 5316 case PCIC_TI_PCI1031:
5317 5317 pcic->pc_chipname = PCIC_TYPE_PCI1031;
5318 5318 break;
5319 5319 case PCIC_TI_PCI1130:
5320 5320 pcic->pc_chipname = PCIC_TYPE_PCI1130;
5321 5321 break;
5322 5322 case PCIC_TI_PCI1131:
5323 5323 pcic->pc_chipname = PCIC_TYPE_PCI1131;
5324 5324 break;
5325 5325 case PCIC_TI_PCI1250:
5326 5326 pcic->pc_chipname = PCIC_TYPE_PCI1250;
5327 5327 break;
5328 5328 case PCIC_TI_PCI1225:
5329 5329 pcic->pc_chipname = PCIC_TYPE_PCI1225;
5330 5330 break;
5331 5331 case PCIC_TI_PCI1410:
5332 5332 pcic->pc_chipname = PCIC_TYPE_PCI1410;
5333 5333 break;
5334 5334 case PCIC_TI_PCI1510:
5335 5335 pcic->pc_chipname = PCIC_TYPE_PCI1510;
5336 5336 break;
5337 5337 case PCIC_TI_PCI1520:
5338 5338 pcic->pc_chipname = PCIC_TYPE_PCI1520;
5339 5339 break;
5340 5340 case PCIC_TI_PCI1221:
5341 5341 pcic->pc_chipname = PCIC_TYPE_PCI1221;
5342 5342 break;
5343 5343 case PCIC_TI_PCI1050:
5344 5344 pcic->pc_chipname = PCIC_TYPE_PCI1050;
5345 5345 break;
5346 5346 case PCIC_ENE_1410:
5347 5347 pcic->pc_chipname = PCIC_TYPE_1410;
5348 5348 break;
5349 5349 case PCIC_O2_OZ6912:
5350 5350 pcic->pc_chipname = PCIC_TYPE_OZ6912;
5351 5351 break;
5352 5352 case PCIC_RICOH_RL5C466:
5353 5353 pcic->pc_chipname = PCIC_TYPE_RL5C466;
5354 5354 break;
5355 5355 case PCIC_TI_PCI1420:
5356 5356 pcic->pc_chipname = PCIC_TYPE_PCI1420;
5357 5357 break;
5358 5358 case PCIC_ENE_1420:
5359 5359 pcic->pc_chipname = PCIC_TYPE_1420;
5360 5360 break;
5361 5361 default:
5362 5362 switch (PCI_ID(vend, (uint32_t)0)) {
5363 5363 case PCIC_TOSHIBA_VENDOR:
5364 5364 pcic->pc_chipname = PCIC_TYPE_TOSHIBA;
5365 5365 pcic->pc_type = PCIC_TOSHIBA_VENDOR;
5366 5366 break;
5367 5367 case PCIC_TI_VENDOR:
5368 5368 pcic->pc_chipname = PCIC_TYPE_TI;
5369 5369 pcic->pc_type = PCIC_TI_VENDOR;
5370 5370 break;
5371 5371 case PCIC_O2MICRO_VENDOR:
5372 5372 pcic->pc_chipname = PCIC_TYPE_O2MICRO;
5373 5373 pcic->pc_type = PCIC_O2MICRO_VENDOR;
5374 5374 break;
5375 5375 case PCIC_RICOH_VENDOR:
5376 5376 pcic->pc_chipname = PCIC_TYPE_RICOH;
5377 5377 pcic->pc_type = PCIC_RICOH_VENDOR;
5378 5378 break;
5379 5379 default:
5380 5380 if (!(pcic->pc_flags & PCF_CARDBUS))
5381 5381 return (DDI_FAILURE);
5382 5382 pcic->pc_chipname = PCIC_TYPE_YENTA;
5383 5383 break;
5384 5384 }
5385 5385 }
5386 5386 return (DDI_SUCCESS);
5387 5387 }
5388 5388
5389 5389 static void
5390 5390 pcic_82092_smiirq_ctl(pcicdev_t *pcic, int socket, int intr, int state)
5391 5391 {
5392 5392 uchar_t ppirr = ddi_get8(pcic->cfg_handle,
5393 5393 pcic->cfgaddr + PCIC_82092_PPIRR);
5394 5394 uchar_t val;
5395 5395
5396 5396 if (intr == PCIC_82092_CTL_SMI) {
5397 5397 val = PCIC_82092_SMI_CTL(socket,
5398 5398 PCIC_82092_INT_DISABLE);
5399 5399 ppirr &= ~val;
5400 5400 val = PCIC_82092_SMI_CTL(socket, state);
5401 5401 ppirr |= val;
5402 5402 } else {
5403 5403 val = PCIC_82092_IRQ_CTL(socket,
5404 5404 PCIC_82092_INT_DISABLE);
5405 5405 ppirr &= ~val;
5406 5406 val = PCIC_82092_IRQ_CTL(socket, state);
5407 5407 ppirr |= val;
5408 5408 }
5409 5409 ddi_put8(pcic->cfg_handle, pcic->cfgaddr + PCIC_82092_PPIRR,
5410 5410 ppirr);
5411 5411 }
5412 5412
5413 5413 static uint_t
5414 5414 pcic_cd_softint(caddr_t arg1, caddr_t arg2)
5415 5415 {
5416 5416 pcic_socket_t *sockp = (pcic_socket_t *)arg1;
5417 5417 uint_t rc = DDI_INTR_UNCLAIMED;
5418 5418
5419 5419 _NOTE(ARGUNUSED(arg2))
5420 5420
5421 5421 mutex_enter(&sockp->pcs_pcic->pc_lock);
5422 5422 if (sockp->pcs_cd_softint_flg) {
5423 5423 uint8_t status;
5424 5424 sockp->pcs_cd_softint_flg = 0;
5425 5425 rc = DDI_INTR_CLAIMED;
5426 5426 status = pcic_getb(sockp->pcs_pcic, sockp->pcs_socket,
5427 5427 PCIC_INTERFACE_STATUS);
5428 5428 pcic_handle_cd_change(sockp->pcs_pcic, sockp, status);
5429 5429 }
5430 5430 mutex_exit(&sockp->pcs_pcic->pc_lock);
5431 5431 return (rc);
5432 5432 }
5433 5433
5434 5434 int pcic_debounce_cnt = PCIC_REM_DEBOUNCE_CNT;
5435 5435 int pcic_debounce_intr_time = PCIC_REM_DEBOUNCE_TIME;
5436 5436 int pcic_debounce_cnt_ok = PCIC_DEBOUNCE_OK_CNT;
5437 5437
5438 5438 #ifdef CARDBUS
5439 5439 static uint32_t pcic_cbps_on = 0;
5440 5440 static uint32_t pcic_cbps_off = CB_PS_NOTACARD | CB_PS_CCDMASK |
5441 5441 CB_PS_XVCARD | CB_PS_YVCARD;
5442 5442 #else
5443 5443 static uint32_t pcic_cbps_on = CB_PS_16BITCARD;
5444 5444 static uint32_t pcic_cbps_off = CB_PS_NOTACARD | CB_PS_CCDMASK |
5445 5445 CB_PS_CBCARD |
5446 5446 CB_PS_XVCARD | CB_PS_YVCARD;
5447 5447 #endif
5448 5448 static void
5449 5449 pcic_handle_cd_change(pcicdev_t *pcic, pcic_socket_t *sockp, uint8_t status)
5450 5450 {
5451 5451 boolean_t do_debounce = B_FALSE;
5452 5452 int debounce_time = drv_usectohz(pcic_debounce_time);
5453 5453 uint8_t irq;
5454 5454 timeout_id_t debounce;
5455 5455
5456 5456 /*
5457 5457 * Always reset debounce but may need to check original state later.
5458 5458 */
5459 5459 debounce = sockp->pcs_debounce_id;
5460 5460 sockp->pcs_debounce_id = 0;
5461 5461
5462 5462 /*
5463 5463 * Check to see whether a card is present or not. There are
5464 5464 * only two states that we are concerned with - the state
5465 5465 * where both CD pins are asserted, which means that the
5466 5466 * card is fully seated, and the state where neither CD
5467 5467 * pin is asserted, which means that the card is not
5468 5468 * present.
5469 5469 * The CD signals are generally very noisy and cause a lot of
5470 5470 * contact bounce as the card is being inserted and
5471 5471 * removed, so we need to do some software debouncing.
5472 5472 */
5473 5473
5474 5474 #ifdef PCIC_DEBUG
5475 5475 pcic_err(pcic->dip, 6,
5476 5476 "pcic%d handle_cd_change: socket %d card status 0x%x"
5477 5477 " deb 0x%p\n", ddi_get_instance(pcic->dip),
5478 5478 sockp->pcs_socket, status, debounce);
5479 5479 #endif
5480 5480 switch (status & PCIC_ISTAT_CD_MASK) {
5481 5481 case PCIC_CD_PRESENT_OK:
5482 5482 sockp->pcs_flags &= ~(PCS_CARD_REMOVED|PCS_CARD_CBREM);
5483 5483 if (!(sockp->pcs_flags & PCS_CARD_PRESENT)) {
5484 5484 uint32_t cbps;
5485 5485 #ifdef PCIC_DEBUG
5486 5486 pcic_err(pcic->dip, 8, "New card (0x%x)\n", sockp->pcs_flags);
5487 5487 #endif
5488 5488 cbps = pcic_getcb(pcic, CB_PRESENT_STATE);
5489 5489 #ifdef PCIC_DEBUG
5490 5490 pcic_err(pcic->dip, 8, "CBus PS (0x%x)\n", cbps);
5491 5491 #endif
5492 5492 /*
5493 5493 * Check the CB bits are sane.
5494 5494 */
5495 5495 if ((cbps & pcic_cbps_on) != pcic_cbps_on ||
5496 5496 cbps & pcic_cbps_off) {
5497 5497 cmn_err(CE_WARN,
5498 5498 "%s%d: Odd Cardbus Present State 0x%x\n",
5499 5499 ddi_get_name(pcic->dip),
5500 5500 ddi_get_instance(pcic->dip),
5501 5501 cbps);
5502 5502 pcic_putcb(pcic, CB_EVENT_FORCE, CB_EF_CVTEST);
5503 5503 debounce = 0;
5504 5504 debounce_time = drv_usectohz(1000000);
5505 5505 }
5506 5506 if (debounce) {
5507 5507 sockp->pcs_flags |= PCS_CARD_PRESENT;
5508 5508 if (pcic_do_insertion) {
5509 5509
5510 5510 cbps = pcic_getcb(pcic, CB_PRESENT_STATE);
5511 5511
5512 5512 if (cbps & CB_PS_16BITCARD) {
5513 5513 pcic_err(pcic->dip,
5514 5514 8, "16 bit card inserted\n");
5515 5515 sockp->pcs_flags |= PCS_CARD_IS16BIT;
5516 5516 /* calls pcm_adapter_callback() */
5517 5517 if (pcic->pc_callback) {
5518 5518
5519 5519 (void) ddi_prop_update_string(
5520 5520 DDI_DEV_T_NONE,
5521 5521 pcic->dip, PCM_DEVICETYPE,
5522 5522 "pccard");
5523 5523 PC_CALLBACK(pcic->dip,
5524 5524 pcic->pc_cb_arg,
5525 5525 PCE_CARD_INSERT,
5526 5526 sockp->pcs_socket);
5527 5527 }
5528 5528 } else if (cbps & CB_PS_CBCARD) {
5529 5529 pcic_err(pcic->dip,
5530 5530 8, "32 bit card inserted\n");
5531 5531
5532 5532 if (pcic->pc_flags & PCF_CARDBUS) {
5533 5533 sockp->pcs_flags |=
5534 5534 PCS_CARD_ISCARDBUS;
5535 5535 #ifdef CARDBUS
5536 5536 if (!pcic_load_cardbus(pcic,
5537 5537 sockp)) {
5538 5538 pcic_unload_cardbus(
5539 5539 pcic, sockp);
5540 5540 }
5541 5541
5542 5542 #else
5543 5543 cmn_err(CE_NOTE,
5544 5544 "32 bit Cardbus not"
5545 5545 " supported in"
5546 5546 " this device driver\n");
5547 5547 #endif
5548 5548 } else {
5549 5549 /*
5550 5550 * Ignore the card
5551 5551 */
5552 5552 cmn_err(CE_NOTE,
5553 5553 "32 bit Cardbus not"
5554 5554 " supported on this"
5555 5555 " device\n");
5556 5556 }
5557 5557 } else {
5558 5558 cmn_err(CE_NOTE,
5559 5559 "Unsupported PCMCIA card"
5560 5560 " inserted\n");
5561 5561 }
5562 5562 }
5563 5563 } else {
5564 5564 do_debounce = B_TRUE;
5565 5565 }
5566 5566 } else {
5567 5567 /*
5568 5568 * It is possible to come through here if the system
5569 5569 * starts up with cards already inserted. Do nothing
5570 5570 * and don't worry about it.
5571 5571 */
5572 5572 #ifdef PCIC_DEBUG
5573 5573 pcic_err(pcic->dip, 5,
5574 5574 "pcic%d: Odd card insertion indication on socket %d\n",
5575 5575 ddi_get_instance(pcic->dip),
5576 5576 sockp->pcs_socket);
5577 5577 #endif
5578 5578 }
5579 5579 break;
5580 5580
5581 5581 default:
5582 5582 if (!(sockp->pcs_flags & PCS_CARD_PRESENT)) {
5583 5583 /*
5584 5584 * Someone has started to insert a card so delay a while.
5585 5585 */
5586 5586 do_debounce = B_TRUE;
5587 5587 break;
5588 5588 }
5589 5589 /*
5590 5590 * Otherwise this is basically the same as not present
5591 5591 * so fall through.
5592 5592 */
5593 5593
5594 5594 /* FALLTHRU */
5595 5595 case 0:
5596 5596 if (sockp->pcs_flags & PCS_CARD_PRESENT) {
5597 5597 if (pcic->pc_flags & PCF_CBPWRCTL) {
5598 5598 pcic_putcb(pcic, CB_CONTROL, 0);
5599 5599 } else {
5600 5600 pcic_putb(pcic, sockp->pcs_socket,
5601 5601 PCIC_POWER_CONTROL, 0);
5602 5602 (void) pcic_getb(pcic, sockp->pcs_socket,
5603 5603 PCIC_POWER_CONTROL);
5604 5604 }
5605 5605 #ifdef PCIC_DEBUG
5606 5606 pcic_err(pcic->dip, 8, "Card removed\n");
5607 5607 #endif
5608 5608 sockp->pcs_flags &= ~PCS_CARD_PRESENT;
5609 5609
5610 5610 if (sockp->pcs_flags & PCS_CARD_IS16BIT) {
5611 5611 sockp->pcs_flags &= ~PCS_CARD_IS16BIT;
5612 5612 if (pcic_do_removal && pcic->pc_callback) {
5613 5613 PC_CALLBACK(pcic->dip, pcic->pc_cb_arg,
5614 5614 PCE_CARD_REMOVAL, sockp->pcs_socket);
5615 5615 }
5616 5616 }
5617 5617 if (sockp->pcs_flags & PCS_CARD_ISCARDBUS) {
5618 5618 sockp->pcs_flags &= ~PCS_CARD_ISCARDBUS;
5619 5619 sockp->pcs_flags |= PCS_CARD_CBREM;
5620 5620 }
5621 5621 sockp->pcs_flags |= PCS_CARD_REMOVED;
5622 5622
5623 5623 do_debounce = B_TRUE;
5624 5624 }
5625 5625 if (debounce && (sockp->pcs_flags & PCS_CARD_REMOVED)) {
5626 5626 if (sockp->pcs_flags & PCS_CARD_CBREM) {
5627 5627 /*
5628 5628 * Ensure that we do the unloading in the
5629 5629 * debounce handler, that way we're not doing
5630 5630 * nasty things in an interrupt handler. e.g.
5631 5631 * a USB device will wait for data which will
5632 5632 * obviously never come because we've
5633 5633 * unplugged the device, but the wait will
5634 5634 * wait forever because no interrupts can
5635 5635 * come in...
5636 5636 */
5637 5637 #ifdef CARDBUS
5638 5638 pcic_unload_cardbus(pcic, sockp);
5639 5639 /* pcic_dump_all(pcic); */
5640 5640 #endif
5641 5641 sockp->pcs_flags &= ~PCS_CARD_CBREM;
5642 5642 }
5643 5643 sockp->pcs_flags &= ~PCS_CARD_REMOVED;
5644 5644 }
5645 5645 break;
5646 5646 } /* switch */
5647 5647
5648 5648 if (do_debounce) {
5649 5649 /*
5650 5650 * Delay doing
5651 5651 * anything for a while so that things can settle
5652 5652 * down a little. Interrupts are already disabled.
5653 5653 * Reset the state and we'll reevaluate the
5654 5654 * whole kit 'n kaboodle when the timeout fires
5655 5655 */
5656 5656 #ifdef PCIC_DEBUG
5657 5657 pcic_err(pcic->dip, 8, "Queueing up debounce timeout for "
5658 5658 "socket %d.%d\n",
5659 5659 ddi_get_instance(pcic->dip),
5660 5660 sockp->pcs_socket);
5661 5661 #endif
5662 5662 sockp->pcs_debounce_id =
5663 5663 pcic_add_debqueue(sockp, debounce_time);
5664 5664
5665 5665 /*
5666 5666 * We bug out here without re-enabling interrupts. They will
5667 5667 * be re-enabled when the debounce timeout swings through
5668 5668 * here.
5669 5669 */
5670 5670 return;
5671 5671 }
5672 5672
5673 5673 /*
5674 5674 * Turn on Card detect interrupts. Other interrupts will be
5675 5675 * enabled during set_socket calls.
5676 5676 *
5677 5677 * Note that set_socket only changes interrupt settings when there
5678 5678 * is a card present.
5679 5679 */
5680 5680 irq = pcic_getb(pcic, sockp->pcs_socket, PCIC_MANAGEMENT_INT);
5681 5681 irq |= PCIC_CD_DETECT;
5682 5682 pcic_putb(pcic, sockp->pcs_socket, PCIC_MANAGEMENT_INT, irq);
5683 5683 pcic_putcb(pcic, CB_STATUS_MASK, CB_SE_CCDMASK);
5684 5684
5685 5685 /* Out from debouncing state */
5686 5686 sockp->pcs_flags &= ~PCS_DEBOUNCING;
5687 5687
5688 5688 pcic_err(pcic->dip, 7, "Leaving pcic_handle_cd_change\n");
5689 5689 }
5690 5690
5691 5691 /*
5692 5692 * pcic_getb()
5693 5693 * get an I/O byte based on the yardware decode method
5694 5694 */
5695 5695 static uint8_t
5696 5696 pcic_getb(pcicdev_t *pcic, int socket, int reg)
5697 5697 {
5698 5698 int work;
5699 5699
5700 5700 #if defined(PCIC_DEBUG)
5701 5701 if (pcic_debug == 0x7fff) {
5702 5702 cmn_err(CE_CONT, "pcic_getb0: pcic=%p socket=%d reg=%d\n",
5703 5703 (void *)pcic, socket, reg);
5704 5704 cmn_err(CE_CONT, "pcic_getb1: type=%d handle=%p ioaddr=%p \n",
5705 5705 pcic->pc_io_type, (void *)pcic->handle,
5706 5706 (void *)pcic->ioaddr);
5707 5707 }
5708 5708 #endif
5709 5709
5710 5710 switch (pcic->pc_io_type) {
5711 5711 case PCIC_IO_TYPE_YENTA:
5712 5712 return (ddi_get8(pcic->handle,
5713 5713 pcic->ioaddr + CB_R2_OFFSET + reg));
5714 5714 default:
5715 5715 work = (socket * PCIC_SOCKET_1) | reg;
5716 5716 ddi_put8(pcic->handle, pcic->ioaddr, work);
5717 5717 return (ddi_get8(pcic->handle, pcic->ioaddr + 1));
5718 5718 }
5719 5719 }
5720 5720
5721 5721 static void
5722 5722 pcic_putb(pcicdev_t *pcic, int socket, int reg, int8_t value)
5723 5723 {
5724 5724 int work;
5725 5725
5726 5726 #if defined(PCIC_DEBUG)
5727 5727 if (pcic_debug == 0x7fff) {
5728 5728 cmn_err(CE_CONT,
5729 5729 "pcic_putb0: pcic=%p socket=%d reg=%d value=%x \n",
5730 5730 (void *)pcic, socket, reg, value);
5731 5731 cmn_err(CE_CONT,
5732 5732 "pcic_putb1: type=%d handle=%p ioaddr=%p \n",
5733 5733 pcic->pc_io_type, (void *)pcic->handle,
5734 5734 (void *)pcic->ioaddr);
5735 5735 }
5736 5736 #endif
5737 5737
5738 5738
5739 5739 switch (pcic->pc_io_type) {
5740 5740 case PCIC_IO_TYPE_YENTA:
5741 5741 ddi_put8(pcic->handle, pcic->ioaddr + CB_R2_OFFSET + reg,
5742 5742 value);
5743 5743 break;
5744 5744 default:
5745 5745 work = (socket * PCIC_SOCKET_1) | reg;
5746 5746 ddi_put8(pcic->handle, pcic->ioaddr, work);
5747 5747 ddi_put8(pcic->handle, pcic->ioaddr + 1, value);
5748 5748 break;
5749 5749 }
5750 5750 }
5751 5751
5752 5752 /*
5753 5753 * chip identification functions
5754 5754 */
5755 5755
5756 5756 /*
5757 5757 * chip identification: Cirrus Logic PD6710/6720/6722
5758 5758 */
5759 5759 static int
5760 5760 pcic_ci_cirrus(pcicdev_t *pcic)
5761 5761 {
5762 5762 int value1, value2;
5763 5763
5764 5764 /* Init the CL id mode */
5765 5765 value1 = pcic_getb(pcic, 0, PCIC_CHIP_INFO);
5766 5766 pcic_putb(pcic, 0, PCIC_CHIP_INFO, 0);
5767 5767 value1 = pcic_getb(pcic, 0, PCIC_CHIP_INFO);
5768 5768 value2 = pcic_getb(pcic, 0, PCIC_CHIP_INFO);
5769 5769
5770 5770 if ((value1 & PCIC_CI_ID) == PCIC_CI_ID &&
5771 5771 (value2 & PCIC_CI_ID) == 0) {
5772 5772 /* chip is a Cirrus Logic and not Intel */
5773 5773 pcic->pc_type = PCIC_CL_PD6710;
5774 5774 if (value1 & PCIC_CI_SLOTS)
5775 5775 pcic->pc_chipname = PCIC_TYPE_PD6720;
5776 5776 else
5777 5777 pcic->pc_chipname = PCIC_TYPE_PD6710;
5778 5778 /* now fine tune things just in case a 6722 */
5779 5779 value1 = clext_reg_read(pcic, 0, PCIC_CLEXT_DMASK_0);
5780 5780 if (value1 == 0) {
5781 5781 clext_reg_write(pcic, 0, PCIC_CLEXT_SCRATCH, 0x55);
5782 5782 value1 = clext_reg_read(pcic, 0, PCIC_CLEXT_SCRATCH);
5783 5783 if (value1 == 0x55) {
5784 5784 pcic->pc_chipname = PCIC_TYPE_PD6722;
5785 5785 pcic->pc_type = PCIC_CL_PD6722;
5786 5786 clext_reg_write(pcic, 0, PCIC_CLEXT_SCRATCH, 0);
5787 5787 }
5788 5788 }
5789 5789 return (1);
5790 5790 }
5791 5791 return (0);
5792 5792 }
5793 5793
5794 5794 /*
5795 5795 * chip identification: Vadem (VG365/465/468/469)
5796 5796 */
5797 5797
5798 5798 static void
5799 5799 pcic_vadem_enable(pcicdev_t *pcic)
5800 5800 {
5801 5801 ddi_put8(pcic->handle, pcic->ioaddr, PCIC_VADEM_P1);
5802 5802 ddi_put8(pcic->handle, pcic->ioaddr, PCIC_VADEM_P2);
5803 5803 ddi_put8(pcic->handle, pcic->ioaddr, pcic->pc_lastreg);
5804 5804 }
5805 5805
5806 5806 static int
5807 5807 pcic_ci_vadem(pcicdev_t *pcic)
5808 5808 {
5809 5809 int value;
5810 5810
5811 5811 pcic_vadem_enable(pcic);
5812 5812 value = pcic_getb(pcic, 0, PCIC_CHIP_REVISION);
5813 5813 pcic_putb(pcic, 0, PCIC_CHIP_REVISION, 0xFF);
5814 5814 if (pcic_getb(pcic, 0, PCIC_CHIP_REVISION) ==
5815 5815 (value | PCIC_VADEM_D3) ||
5816 5816 (pcic_getb(pcic, 0, PCIC_CHIP_REVISION) & PCIC_REV_MASK) ==
5817 5817 PCIC_VADEM_469) {
5818 5818 int vadem, new;
5819 5819 pcic_vadem_enable(pcic);
5820 5820 vadem = pcic_getb(pcic, 0, PCIC_VG_DMA) &
5821 5821 ~(PCIC_V_UNLOCK | PCIC_V_VADEMREV);
5822 5822 new = vadem | (PCIC_V_VADEMREV|PCIC_V_UNLOCK);
5823 5823 pcic_putb(pcic, 0, PCIC_VG_DMA, new);
5824 5824 value = pcic_getb(pcic, 0, PCIC_CHIP_REVISION);
5825 5825
5826 5826 /* want to lock but leave mouse or other on */
5827 5827 pcic_putb(pcic, 0, PCIC_VG_DMA, vadem);
5828 5828 switch (value & PCIC_REV_MASK) {
5829 5829 case PCIC_VADEM_365:
5830 5830 pcic->pc_chipname = PCIC_VG_365;
5831 5831 pcic->pc_type = PCIC_VADEM;
5832 5832 break;
5833 5833 case PCIC_VADEM_465:
5834 5834 pcic->pc_chipname = PCIC_VG_465;
5835 5835 pcic->pc_type = PCIC_VADEM;
5836 5836 pcic->pc_flags |= PCF_1SOCKET;
5837 5837 break;
5838 5838 case PCIC_VADEM_468:
5839 5839 pcic->pc_chipname = PCIC_VG_468;
5840 5840 pcic->pc_type = PCIC_VADEM;
5841 5841 break;
5842 5842 case PCIC_VADEM_469:
5843 5843 pcic->pc_chipname = PCIC_VG_469;
5844 5844 pcic->pc_type = PCIC_VADEM_VG469;
5845 5845 break;
5846 5846 }
5847 5847 return (1);
5848 5848 }
5849 5849 return (0);
5850 5850 }
5851 5851
5852 5852 /*
5853 5853 * chip identification: Ricoh
5854 5854 */
5855 5855 static int
5856 5856 pcic_ci_ricoh(pcicdev_t *pcic)
5857 5857 {
5858 5858 int value;
5859 5859
5860 5860 value = pcic_getb(pcic, 0, PCIC_RF_CHIP_IDENT);
5861 5861 switch (value) {
5862 5862 case PCIC_RF_296:
5863 5863 pcic->pc_type = PCIC_RICOH;
5864 5864 pcic->pc_chipname = PCIC_TYPE_RF5C296;
5865 5865 return (1);
5866 5866 case PCIC_RF_396:
5867 5867 pcic->pc_type = PCIC_RICOH;
5868 5868 pcic->pc_chipname = PCIC_TYPE_RF5C396;
5869 5869 return (1);
5870 5870 }
5871 5871 return (0);
5872 5872 }
5873 5873
5874 5874
5875 5875 /*
5876 5876 * set up available address spaces in busra
5877 5877 */
5878 5878 static void
5879 5879 pcic_init_assigned(dev_info_t *dip)
5880 5880 {
5881 5881 pcm_regs_t *pcic_avail_p;
5882 5882 pci_regspec_t *pci_avail_p, *regs;
5883 5883 int len, entries, rlen;
5884 5884 dev_info_t *pdip;
5885 5885
5886 5886 if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
5887 5887 "available", (caddr_t)&pcic_avail_p, &len) == DDI_PROP_SUCCESS) {
5888 5888 /*
5889 5889 * found "available" property at the cardbus/pcmcia node
5890 5890 * need to translate address space entries from pcmcia
5891 5891 * format to pci format
5892 5892 */
5893 5893 entries = len / sizeof (pcm_regs_t);
5894 5894 pci_avail_p = kmem_alloc(sizeof (pci_regspec_t) * entries,
5895 5895 KM_SLEEP);
5896 5896 if (pcic_apply_avail_ranges(dip, pcic_avail_p, pci_avail_p,
5897 5897 entries) == DDI_SUCCESS)
5898 5898 (void) pci_resource_setup_avail(dip, pci_avail_p,
5899 5899 entries);
5900 5900 kmem_free(pcic_avail_p, len);
5901 5901 kmem_free(pci_avail_p, entries * sizeof (pci_regspec_t));
5902 5902 return;
5903 5903 }
5904 5904
5905 5905 /*
5906 5906 * "legacy" platforms will have "available" property in pci node
5907 5907 */
5908 5908 for (pdip = ddi_get_parent(dip); pdip; pdip = ddi_get_parent(pdip)) {
5909 5909 if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, DDI_PROP_DONTPASS,
5910 5910 "available", (caddr_t)&pci_avail_p, &len) ==
5911 5911 DDI_PROP_SUCCESS) {
5912 5912 /* (void) pci_resource_setup(pdip); */
5913 5913 kmem_free(pci_avail_p, len);
5914 5914 break;
5915 5915 }
5916 5916 }
5917 5917
5918 5918 if (pdip == NULL) {
5919 5919 int len;
5920 5920 char bus_type[16] = "(unknown)";
5921 5921 dev_info_t *par;
5922 5922
5923 5923 cmn_err(CE_CONT,
5924 5924 "?pcic_init_assigned: no available property for pcmcia\n");
5925 5925
5926 5926 /*
5927 5927 * This code is taken from pci_resource_setup() but does
5928 5928 * not attempt to use the "available" property to populate
5929 5929 * the ndi maps that are created.
5930 5930 * The fact that we will actually
5931 5931 * free some resource below (that was allocated by OBP)
5932 5932 * should be enough to be going on with.
5933 5933 */
5934 5934 for (par = dip; par != NULL; par = ddi_get_parent(par)) {
5935 5935 len = sizeof (bus_type);
5936 5936
5937 5937 if ((ddi_prop_op(DDI_DEV_T_ANY, par,
5938 5938 PROP_LEN_AND_VAL_BUF,
5939 5939 DDI_PROP_CANSLEEP | DDI_PROP_DONTPASS,
5940 5940 "device_type",
5941 5941 (caddr_t)&bus_type, &len) == DDI_SUCCESS) &&
5942 5942 (strcmp(bus_type, DEVI_PCI_NEXNAME) == 0 ||
5943 5943 strcmp(bus_type, DEVI_PCIEX_NEXNAME) == 0))
5944 5944 break;
5945 5945 }
5946 5946 if (par != NULL &&
5947 5947 (ndi_ra_map_setup(par, NDI_RA_TYPE_MEM) != NDI_SUCCESS ||
5948 5948 ndi_ra_map_setup(par, NDI_RA_TYPE_IO) != NDI_SUCCESS))
5949 5949 par = NULL;
5950 5950 } else {
5951 5951 #ifdef CARDBUS
5952 5952 cardbus_bus_range_t *bus_range;
5953 5953 int k;
5954 5954
5955 5955 if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, 0, "bus-range",
5956 5956 (caddr_t)&bus_range, &k) == DDI_PROP_SUCCESS) {
5957 5957 if (bus_range->lo != bus_range->hi)
5958 5958 pcic_err(pdip, 9, "allowable bus range is "
5959 5959 "%u->%u\n", bus_range->lo, bus_range->hi);
5960 5960 else {
5961 5961 pcic_err(pdip, 0,
5962 5962 "!No spare PCI bus numbers, range is "
5963 5963 "%u->%u, cardbus isn't usable\n",
5964 5964 bus_range->lo, bus_range->hi);
5965 5965 }
5966 5966 kmem_free(bus_range, k);
5967 5967 } else
5968 5968 pcic_err(pdip, 0, "!No bus-range property seems to "
5969 5969 "have been set up\n");
5970 5970 #endif
5971 5971 /*
5972 5972 * Have a valid parent with the "available" property
5973 5973 */
5974 5974 (void) pci_resource_setup(pdip);
5975 5975 }
5976 5976
5977 5977 if ((strcmp(ddi_get_name(dip), "pcma") == 0) &&
5978 5978 ddi_getlongprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS,
5979 5979 "assigned-addresses",
5980 5980 (caddr_t)®s, &rlen) == DDI_SUCCESS) {
5981 5981 ra_return_t ra;
5982 5982
5983 5983 /*
5984 5984 * On the UltraBook IIi the ranges are assigned under
5985 5985 * openboot. If we don't free them here the first I/O
5986 5986 * space that can be used is up above 0x10000 which
5987 5987 * doesn't work for this driver due to restrictions
5988 5988 * on the PCI I/O addresses the controllers can cope with.
5989 5989 * They are never going to be used by anything else
5990 5990 * so free them up to the general pool. AG.
5991 5991 */
5992 5992 pcic_err(dip, 1, "Free assigned addresses\n");
5993 5993
5994 5994 if ((PCI_REG_ADDR_G(regs[0].pci_phys_hi) ==
5995 5995 PCI_REG_ADDR_G(PCI_ADDR_MEM32)) &&
5996 5996 regs[0].pci_size_low == 0x1000000) {
5997 5997 ra.ra_addr_lo = regs[0].pci_phys_low;
5998 5998 ra.ra_len = regs[0].pci_size_low;
5999 5999 (void) pcmcia_free_mem(dip, &ra);
6000 6000 }
6001 6001 if ((PCI_REG_ADDR_G(regs[1].pci_phys_hi) ==
6002 6002 PCI_REG_ADDR_G(PCI_ADDR_IO)) &&
6003 6003 (regs[1].pci_size_low == 0x8000 ||
6004 6004 regs[1].pci_size_low == 0x4000)) /* UB-IIi || UB-I */
6005 6005 {
6006 6006 ra.ra_addr_lo = regs[1].pci_phys_low;
6007 6007 ra.ra_len = regs[1].pci_size_low;
6008 6008 (void) pcmcia_free_io(dip, &ra);
6009 6009 }
6010 6010 kmem_free((caddr_t)regs, rlen);
6011 6011 }
6012 6012 }
6013 6013
6014 6014 /*
6015 6015 * translate "available" from pcmcia format to pci format
6016 6016 */
6017 6017 static int
6018 6018 pcic_apply_avail_ranges(dev_info_t *dip, pcm_regs_t *pcic_p,
6019 6019 pci_regspec_t *pci_p, int entries)
6020 6020 {
6021 6021 int i, range_len, range_entries;
6022 6022 pcic_ranges_t *pcic_range_p;
6023 6023
6024 6024 if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "ranges",
6025 6025 (caddr_t)&pcic_range_p, &range_len) != DDI_PROP_SUCCESS) {
6026 6026 cmn_err(CE_CONT, "?pcic_apply_avail_ranges: "
6027 6027 "no ranges property for pcmcia\n");
6028 6028 return (DDI_FAILURE);
6029 6029 }
6030 6030
6031 6031 range_entries = range_len / sizeof (pcic_ranges_t);
6032 6032
6033 6033 /* for each "available" entry to be translated */
6034 6034 for (i = 0; i < entries; i++, pcic_p++, pci_p++) {
6035 6035 int j;
6036 6036 pcic_ranges_t *range_p = pcic_range_p;
6037 6037 pci_p->pci_phys_hi = -1u; /* default invalid value */
6038 6038
6039 6039 /* for each "ranges" entry to be searched */
6040 6040 for (j = 0; j < range_entries; j++, range_p++) {
6041 6041 uint64_t range_end = range_p->pcic_range_caddrlo +
6042 6042 range_p->pcic_range_size;
6043 6043 uint64_t avail_end = pcic_p->phys_lo + pcic_p->phys_len;
6044 6044
6045 6045 if ((range_p->pcic_range_caddrhi != pcic_p->phys_hi) ||
6046 6046 (range_p->pcic_range_caddrlo > pcic_p->phys_lo) ||
6047 6047 (range_end < avail_end))
6048 6048 continue;
6049 6049
6050 6050 pci_p->pci_phys_hi = range_p->pcic_range_paddrhi;
6051 6051 pci_p->pci_phys_mid = range_p->pcic_range_paddrmid;
6052 6052 pci_p->pci_phys_low = range_p->pcic_range_paddrlo
6053 6053 + (pcic_p->phys_lo - range_p->pcic_range_caddrlo);
6054 6054 pci_p->pci_size_hi = 0;
6055 6055 pci_p->pci_size_low = pcic_p->phys_len;
6056 6056 }
6057 6057 }
6058 6058 kmem_free(pcic_range_p, range_len);
6059 6059 return (DDI_SUCCESS);
6060 6060 }
6061 6061
6062 6062 static int
6063 6063 pcic_open(dev_t *dev, int flag, int otyp, cred_t *cred)
6064 6064 {
6065 6065 #ifdef CARDBUS
6066 6066 if (cardbus_is_cb_minor(*dev))
6067 6067 return (cardbus_open(dev, flag, otyp, cred));
6068 6068 #endif
6069 6069 return (EINVAL);
6070 6070 }
6071 6071
6072 6072 static int
6073 6073 pcic_close(dev_t dev, int flag, int otyp, cred_t *cred)
6074 6074 {
6075 6075 #ifdef CARDBUS
6076 6076 if (cardbus_is_cb_minor(dev))
6077 6077 return (cardbus_close(dev, flag, otyp, cred));
6078 6078 #endif
6079 6079 return (EINVAL);
6080 6080 }
6081 6081
6082 6082 static int
6083 6083 pcic_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *cred,
6084 6084 int *rval)
6085 6085 {
6086 6086 #ifdef CARDBUS
6087 6087 if (cardbus_is_cb_minor(dev))
6088 6088 return (cardbus_ioctl(dev, cmd, arg, mode, cred, rval));
6089 6089 #endif
6090 6090 return (EINVAL);
6091 6091 }
6092 6092
6093 6093
6094 6094 static boolean_t
6095 6095 pcic_load_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp)
6096 6096 {
6097 6097 uint32_t present_state;
6098 6098 dev_info_t *dip = pcic->dip;
6099 6099 set_socket_t s;
6100 6100 get_socket_t g;
6101 6101 boolean_t retval;
6102 6102 unsigned vccLevel;
6103 6103
6104 6104 pcic_err(dip, 8, "entering pcic_load_cardbus\n");
6105 6105
6106 6106 pcic_mutex_exit(&pcic->pc_lock);
6107 6107
6108 6108 bzero(&s, sizeof (set_socket_t));
6109 6109 s.socket = sockp->pcs_socket;
6110 6110 s.SCIntMask = SBM_CD|SBM_RDYBSY;
6111 6111 s.IFType = IF_CARDBUS;
6112 6112 s.State = (unsigned)~0;
6113 6113
6114 6114 present_state = pcic_getcb(pcic, CB_PRESENT_STATE);
6115 6115 if (present_state & PCIC_VCC_3VCARD)
6116 6116 s.VccLevel = PCIC_VCC_3VLEVEL;
6117 6117 else if (present_state & PCIC_VCC_5VCARD)
6118 6118 s.VccLevel = PCIC_VCC_5VLEVEL;
6119 6119 else {
6120 6120 cmn_err(CE_CONT,
6121 6121 "pcic_load_cardbus: unsupported card voltage\n");
6122 6122 goto failure;
6123 6123 }
6124 6124 vccLevel = s.VccLevel;
6125 6125 s.Vpp1Level = s.Vpp2Level = 0;
6126 6126
6127 6127 if (pcic_set_socket(dip, &s) != SUCCESS)
6128 6128 goto failure;
6129 6129
6130 6130 if (pcic_reset_socket(dip, sockp->pcs_socket,
6131 6131 RESET_MODE_CARD_ONLY) != SUCCESS)
6132 6132 goto failure;
6133 6133
6134 6134 bzero(&g, sizeof (get_socket_t));
6135 6135 g.socket = sockp->pcs_socket;
6136 6136 if (pcic_get_socket(dip, &g) != SUCCESS)
6137 6137 goto failure;
6138 6138
6139 6139 bzero(&s, sizeof (set_socket_t));
6140 6140 s.socket = sockp->pcs_socket;
6141 6141 s.SCIntMask = SBM_CD;
6142 6142 s.IREQRouting = g.IRQRouting;
6143 6143 s.IFType = g.IFType;
6144 6144 s.CtlInd = g.CtlInd;
6145 6145 s.State = (unsigned)~0;
6146 6146 s.VccLevel = vccLevel;
6147 6147 s.Vpp1Level = s.Vpp2Level = 0;
6148 6148
6149 6149 retval = pcic_set_socket(dip, &s);
6150 6150 pcmcia_cb_resumed(s.socket);
6151 6151 if (retval != SUCCESS)
6152 6152 goto failure;
6153 6153
6154 6154 retval = cardbus_load_cardbus(dip, sockp->pcs_socket, pcic->pc_base);
6155 6155 goto exit;
6156 6156
6157 6157 failure:
6158 6158 retval = B_FALSE;
6159 6159
6160 6160 exit:
6161 6161 pcic_mutex_enter(&pcic->pc_lock);
6162 6162 pcic_err(dip, 8, "exit pcic_load_cardbus (%s)\n",
6163 6163 retval ? "success" : "failure");
6164 6164 return (retval);
6165 6165 }
6166 6166
6167 6167 static void
6168 6168 pcic_unload_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp)
6169 6169 {
6170 6170 dev_info_t *dip = pcic->dip;
6171 6171 set_socket_t s;
6172 6172
6173 6173 pcic_mutex_exit(&pcic->pc_lock);
6174 6174
6175 6175 cardbus_unload_cardbus(dip);
6176 6176
6177 6177 bzero(&s, sizeof (set_socket_t));
6178 6178 s.socket = sockp->pcs_socket;
6179 6179 s.SCIntMask = SBM_CD|SBM_RDYBSY;
6180 6180 s.IREQRouting = 0;
6181 6181 s.IFType = IF_MEMORY;
6182 6182 s.CtlInd = 0;
6183 6183 s.State = 0;
6184 6184 s.VccLevel = s.Vpp1Level = s.Vpp2Level = 0;
6185 6185
6186 6186 (void) pcic_set_socket(dip, &s);
6187 6187
6188 6188 pcic_mutex_enter(&pcic->pc_lock);
6189 6189 }
6190 6190
6191 6191 static uint32_t
6192 6192 pcic_getcb(pcicdev_t *pcic, int reg)
6193 6193 {
6194 6194 ASSERT(pcic->pc_io_type == PCIC_IO_TYPE_YENTA);
6195 6195
6196 6196 return (ddi_get32(pcic->handle,
6197 6197 (uint32_t *)(pcic->ioaddr + CB_CB_OFFSET + reg)));
6198 6198 }
6199 6199
6200 6200 static void
6201 6201 pcic_putcb(pcicdev_t *pcic, int reg, uint32_t value)
6202 6202 {
6203 6203 ASSERT(pcic->pc_io_type == PCIC_IO_TYPE_YENTA);
6204 6204
6205 6205 ddi_put32(pcic->handle,
6206 6206 (uint32_t *)(pcic->ioaddr + CB_CB_OFFSET + reg), value);
6207 6207 }
6208 6208
6209 6209 static void
6210 6210 pcic_enable_io_intr(pcicdev_t *pcic, int socket, int irq)
6211 6211 {
6212 6212 uint8_t value;
6213 6213 uint16_t brdgctl;
6214 6214
6215 6215 value = pcic_getb(pcic, socket, PCIC_INTERRUPT) & ~PCIC_INTR_MASK;
6216 6216 pcic_putb(pcic, socket, PCIC_INTERRUPT, value | irq);
6217 6217
6218 6218 switch (pcic->pc_type) {
6219 6219 case PCIC_INTEL_i82092:
6220 6220 pcic_82092_smiirq_ctl(pcic, socket, PCIC_82092_CTL_IRQ,
6221 6221 PCIC_82092_INT_ENABLE);
6222 6222 break;
6223 6223 case PCIC_O2_OZ6912:
6224 6224 value = pcic_getb(pcic, 0, PCIC_CENTDMA);
6225 6225 value |= 0x8;
6226 6226 pcic_putb(pcic, 0, PCIC_CENTDMA, value);
6227 6227 break;
6228 6228 case PCIC_CL_PD6832:
6229 6229 case PCIC_TI_PCI1250:
6230 6230 case PCIC_TI_PCI1221:
6231 6231 case PCIC_TI_PCI1225:
6232 6232 case PCIC_TI_PCI1410:
6233 6233 case PCIC_ENE_1410:
6234 6234 case PCIC_TI_PCI1510:
6235 6235 case PCIC_TI_PCI1520:
6236 6236 case PCIC_TI_PCI1420:
6237 6237 case PCIC_ENE_1420:
6238 6238 /* route card functional interrupts to PCI interrupts */
6239 6239 brdgctl = ddi_get16(pcic->cfg_handle,
6240 6240 (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL));
6241 6241 pcic_err(NULL, 1,
6242 6242 "pcic_enable_io_intr brdgctl(0x%x) was: 0x%x\n",
6243 6243 PCI_CBUS_BRIDGE_CTRL, brdgctl);
6244 6244 brdgctl &= ~PCIC_BRDGCTL_INTR_MASK;
6245 6245 ddi_put16(pcic->cfg_handle,
6246 6246 (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL),
6247 6247 brdgctl);
6248 6248 /* Flush the write */
6249 6249 (void) ddi_get16(pcic->cfg_handle,
6250 6250 (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL));
6251 6251 break;
6252 6252 default:
6253 6253 break;
6254 6254 }
6255 6255 }
6256 6256
6257 6257 static void
6258 6258 pcic_disable_io_intr(pcicdev_t *pcic, int socket)
6259 6259 {
6260 6260 uint8_t value;
6261 6261 uint16_t brdgctl;
6262 6262
6263 6263 value = pcic_getb(pcic, socket, PCIC_INTERRUPT) & ~PCIC_INTR_MASK;
6264 6264 pcic_putb(pcic, socket, PCIC_INTERRUPT, value);
6265 6265
6266 6266 switch (pcic->pc_type) {
6267 6267 case PCIC_INTEL_i82092:
6268 6268 pcic_82092_smiirq_ctl(pcic, socket, PCIC_82092_CTL_IRQ,
6269 6269 PCIC_82092_INT_DISABLE);
6270 6270 break;
6271 6271 case PCIC_O2_OZ6912:
6272 6272 value = pcic_getb(pcic, 0, PCIC_CENTDMA);
6273 6273 value &= ~0x8;
6274 6274 pcic_putb(pcic, 0, PCIC_CENTDMA, value);
6275 6275 /* Flush the write */
6276 6276 (void) pcic_getb(pcic, 0, PCIC_CENTDMA);
6277 6277 break;
6278 6278 case PCIC_CL_PD6832:
6279 6279 case PCIC_TI_PCI1250:
6280 6280 case PCIC_TI_PCI1221:
6281 6281 case PCIC_TI_PCI1225:
6282 6282 case PCIC_TI_PCI1410:
6283 6283 case PCIC_ENE_1410:
6284 6284 case PCIC_TI_PCI1510:
6285 6285 case PCIC_TI_PCI1520:
6286 6286 case PCIC_TI_PCI1420:
6287 6287 case PCIC_ENE_1420:
6288 6288 /*
6289 6289 * This maps I/O interrupts to ExCA which
6290 6290 * have been turned off by the write to
6291 6291 * PCIC_INTERRUPT above. It would appear to
6292 6292 * be the only way to actually turn I/O Ints off
6293 6293 * while retaining CS Ints.
6294 6294 */
6295 6295 brdgctl = ddi_get16(pcic->cfg_handle,
6296 6296 (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL));
6297 6297 pcic_err(NULL, 1,
6298 6298 "pcic_disable_io_intr brdgctl(0x%x) was: 0x%x\n",
6299 6299 PCI_CBUS_BRIDGE_CTRL, brdgctl);
6300 6300 brdgctl |= PCIC_BRDGCTL_INTR_MASK;
6301 6301 ddi_put16(pcic->cfg_handle,
6302 6302 (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL),
6303 6303 brdgctl);
6304 6304 /* Flush the write */
6305 6305 (void) ddi_get16(pcic->cfg_handle,
6306 6306 (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL));
6307 6307 break;
6308 6308 default:
6309 6309 break;
6310 6310 }
6311 6311 }
6312 6312
6313 6313 static void
6314 6314 pcic_cb_enable_intr(dev_info_t *dip)
6315 6315 {
6316 6316 anp_t *anp = ddi_get_driver_private(dip);
6317 6317 pcicdev_t *pcic = anp->an_private;
6318 6318
6319 6319 mutex_enter(&pcic->pc_lock);
6320 6320 pcic_enable_io_intr(pcic, 0, pcic->pc_sockets[0].pcs_irq);
6321 6321 mutex_exit(&pcic->pc_lock);
6322 6322 }
6323 6323
6324 6324 static void
6325 6325 pcic_cb_disable_intr(dev_info_t *dip)
6326 6326 {
6327 6327 anp_t *anp = ddi_get_driver_private(dip);
6328 6328 pcicdev_t *pcic = anp->an_private;
6329 6329
6330 6330 mutex_enter(&pcic->pc_lock);
6331 6331 pcic_disable_io_intr(pcic, 0);
6332 6332 mutex_exit(&pcic->pc_lock);
6333 6333 }
6334 6334
6335 6335 static int
6336 6336 log_pci_cfg_err(ushort_t e, int bridge_secondary)
6337 6337 {
6338 6338 int nerr = 0;
6339 6339 if (e & PCI_STAT_PERROR) {
6340 6340 nerr++;
6341 6341 cmn_err(CE_CONT, "detected parity error.\n");
6342 6342 }
6343 6343 if (e & PCI_STAT_S_SYSERR) {
6344 6344 nerr++;
6345 6345 if (bridge_secondary)
6346 6346 cmn_err(CE_CONT, "received system error.\n");
6347 6347 else
6348 6348 cmn_err(CE_CONT, "signalled system error.\n");
6349 6349 }
6350 6350 if (e & PCI_STAT_R_MAST_AB) {
6351 6351 nerr++;
6352 6352 cmn_err(CE_CONT, "received master abort.\n");
6353 6353 }
6354 6354 if (e & PCI_STAT_R_TARG_AB)
6355 6355 cmn_err(CE_CONT, "received target abort.\n");
6356 6356 if (e & PCI_STAT_S_TARG_AB)
6357 6357 cmn_err(CE_CONT, "signalled target abort\n");
6358 6358 if (e & PCI_STAT_S_PERROR) {
6359 6359 nerr++;
6360 6360 cmn_err(CE_CONT, "signalled parity error\n");
6361 6361 }
6362 6362 return (nerr);
6363 6363 }
6364 6364
6365 6365 #if defined(__sparc)
6366 6366 static int
6367 6367 pcic_fault(enum pci_fault_ops op, void *arg)
6368 6368 {
6369 6369 pcicdev_t *pcic = (pcicdev_t *)arg;
6370 6370 ushort_t pci_cfg_stat =
6371 6371 pci_config_get16(pcic->cfg_handle, PCI_CONF_STAT);
6372 6372 ushort_t pci_cfg_sec_stat =
6373 6373 pci_config_get16(pcic->cfg_handle, 0x16);
6374 6374 char nm[24];
6375 6375 int nerr = 0;
6376 6376
6377 6377 cardbus_dump_pci_config(pcic->dip);
6378 6378
6379 6379 switch (op) {
6380 6380 case FAULT_LOG:
6381 6381 (void) sprintf(nm, "%s-%d", ddi_driver_name(pcic->dip),
6382 6382 ddi_get_instance(pcic->dip));
6383 6383
6384 6384 cmn_err(CE_WARN, "%s: PCIC fault log start:\n", nm);
6385 6385 cmn_err(CE_WARN, "%s: primary err (%x):\n", nm, pci_cfg_stat);
6386 6386 nerr += log_pci_cfg_err(pci_cfg_stat, 0);
6387 6387 cmn_err(CE_WARN, "%s: sec err (%x):\n", nm, pci_cfg_sec_stat);
6388 6388 nerr += log_pci_cfg_err(pci_cfg_sec_stat, 1);
6389 6389 cmn_err(CE_CONT, "%s: PCI fault log end.\n", nm);
6390 6390 return (nerr);
6391 6391 case FAULT_POKEFINI:
6392 6392 case FAULT_RESET:
6393 6393 pci_config_put16(pcic->cfg_handle,
6394 6394 PCI_CONF_STAT, pci_cfg_stat);
6395 6395 pci_config_put16(pcic->cfg_handle, 0x16, pci_cfg_sec_stat);
6396 6396 break;
6397 6397 case FAULT_POKEFLT:
6398 6398 if (!(pci_cfg_stat & PCI_STAT_S_SYSERR))
6399 6399 return (1);
6400 6400 if (!(pci_cfg_sec_stat & PCI_STAT_R_MAST_AB))
6401 6401 return (1);
6402 6402 break;
6403 6403 default:
6404 6404 break;
6405 6405 }
6406 6406 return (DDI_SUCCESS);
6407 6407 }
6408 6408 #endif
6409 6409
6410 6410 static void
6411 6411 pcic_do_resume(pcicdev_t *pcic)
6412 6412 {
6413 6413 int i, interrupt;
6414 6414 uint8_t cfg;
6415 6415
6416 6416
6417 6417 #if defined(PCIC_DEBUG)
6418 6418 pcic_err(NULL, 6, "pcic_do_resume(): entered\n");
6419 6419 #endif
6420 6420
6421 6421 pcic_mutex_enter(&pcic->pc_lock); /* protect the registers */
6422 6422 for (i = 0; i < pcic->pc_numsockets; i++) {
6423 6423 /* Enable interrupts on PCI if needs be */
6424 6424 interrupt = pcic_getb(pcic, i, PCIC_INTERRUPT);
6425 6425 if (pcic->pc_flags & PCF_USE_SMI)
6426 6426 interrupt |= PCIC_INTR_ENABLE;
6427 6427 pcic_putb(pcic, i, PCIC_INTERRUPT,
6428 6428 PCIC_RESET | interrupt);
6429 6429 pcic->pc_sockets[i].pcs_debounce_id =
6430 6430 pcic_add_debqueue(&pcic->pc_sockets[i],
6431 6431 drv_usectohz(pcic_debounce_time));
6432 6432 }
6433 6433 pcic_mutex_exit(&pcic->pc_lock); /* protect the registers */
6434 6434 if (pcic_do_pcmcia_sr)
6435 6435 (void) pcmcia_wait_insert(pcic->dip);
6436 6436 /*
6437 6437 * The CardBus controller may be in RESET state after the
6438 6438 * system is resumed from sleeping. The RESET bit is in
6439 6439 * the Bridge Control register. This is true for all(TI,
6440 6440 * Toshiba ToPIC95/97, RICOH, and O2Micro) CardBus
6441 6441 * controllers. Need to clear the RESET bit explicitly.
6442 6442 */
6443 6443 cfg = ddi_get8(pcic->cfg_handle,
6444 6444 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
6445 6445 if (cfg & (1<<6)) {
6446 6446 cfg &= ~(1<<6);
6447 6447 ddi_put8(pcic->cfg_handle,
6448 6448 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
6449 6449 cfg);
6450 6450 cfg = ddi_get8(pcic->cfg_handle,
6451 6451 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
6452 6452 if (cfg & (1<<6)) {
6453 6453 pcic_err(pcic->dip, 1,
6454 6454 "Failed to take pcic out of reset");
6455 6455 }
6456 6456 }
6457 6457
6458 6458 }
6459 6459
6460 6460 static void
6461 6461 pcic_debounce(pcic_socket_t *pcs)
6462 6462 {
6463 6463 uint8_t status, stschng;
6464 6464
6465 6465 pcic_mutex_enter(&pcs->pcs_pcic->pc_lock);
6466 6466 pcs->pcs_flags &= ~PCS_STARTING;
6467 6467 stschng = pcic_getb(pcs->pcs_pcic, pcs->pcs_socket,
6468 6468 PCIC_CARD_STATUS_CHANGE);
6469 6469 status = pcic_getb(pcs->pcs_pcic, pcs->pcs_socket,
6470 6470 PCIC_INTERFACE_STATUS);
6471 6471 #ifdef PCIC_DEBUG
6472 6472 pcic_err(pcs->pcs_pcic->dip, 8,
6473 6473 "pcic_debounce(0x%p, dip=0x%p) socket %d st 0x%x "
6474 6474 "chg 0x%x flg 0x%x\n",
6475 6475 (void *)pcs, (void *) pcs->pcs_pcic->dip, pcs->pcs_socket,
6476 6476 status, stschng, pcs->pcs_flags);
6477 6477 #endif
6478 6478
6479 6479 pcic_putb(pcs->pcs_pcic, pcs->pcs_socket, PCIC_CARD_STATUS_CHANGE,
6480 6480 PCIC_CD_DETECT);
6481 6481 pcic_handle_cd_change(pcs->pcs_pcic, pcs, status);
6482 6482 pcic_mutex_exit(&pcs->pcs_pcic->pc_lock);
6483 6483 }
6484 6484
6485 6485 static void
6486 6486 pcic_deb_thread()
6487 6487 {
6488 6488 callb_cpr_t cprinfo;
6489 6489 struct debounce *debp;
6490 6490 clock_t lastt;
6491 6491
6492 6492 CALLB_CPR_INIT(&cprinfo, &pcic_deb_mtx,
6493 6493 callb_generic_cpr, "pcic debounce thread");
6494 6494 mutex_enter(&pcic_deb_mtx);
6495 6495 while (pcic_deb_threadid) {
6496 6496 while (pcic_deb_queue) {
6497 6497 #ifdef PCIC_DEBUG
6498 6498 pcic_dump_debqueue("Thread");
6499 6499 #endif
6500 6500 debp = pcic_deb_queue;
6501 6501 (void) drv_getparm(LBOLT, &lastt);
6502 6502 if (lastt >= debp->expire) {
6503 6503 pcic_deb_queue = debp->next;
6504 6504 mutex_exit(&pcic_deb_mtx);
6505 6505 pcic_debounce(debp->pcs);
6506 6506 mutex_enter(&pcic_deb_mtx);
6507 6507 kmem_free(debp, sizeof (*debp));
6508 6508 } else {
6509 6509 (void) cv_timedwait(&pcic_deb_cv,
6510 6510 &pcic_deb_mtx, debp->expire);
6511 6511 }
6512 6512 }
6513 6513 CALLB_CPR_SAFE_BEGIN(&cprinfo);
6514 6514 cv_wait(&pcic_deb_cv, &pcic_deb_mtx);
6515 6515 CALLB_CPR_SAFE_END(&cprinfo, &pcic_deb_mtx);
6516 6516 }
6517 6517 pcic_deb_threadid = (kthread_t *)1;
6518 6518 cv_signal(&pcic_deb_cv);
6519 6519 CALLB_CPR_EXIT(&cprinfo); /* Also exits the mutex */
6520 6520 thread_exit();
6521 6521 }
6522 6522
6523 6523 static void *
6524 6524 pcic_add_debqueue(pcic_socket_t *pcs, int clocks)
6525 6525 {
6526 6526 clock_t lbolt;
6527 6527 struct debounce *dbp, **dbpp = &pcic_deb_queue;
6528 6528
6529 6529 (void) drv_getparm(LBOLT, &lbolt);
6530 6530 dbp = kmem_alloc(sizeof (struct debounce), KM_SLEEP);
6531 6531
6532 6532 dbp->expire = lbolt + clocks;
6533 6533 dbp->pcs = pcs;
6534 6534 mutex_enter(&pcic_deb_mtx);
6535 6535 while (*dbpp) {
6536 6536 if (dbp->expire > (*dbpp)->expire)
6537 6537 dbpp = &((*dbpp)->next);
6538 6538 else
6539 6539 break;
6540 6540 }
6541 6541 dbp->next = *dbpp;
6542 6542 *dbpp = dbp;
6543 6543 #ifdef PCIC_DEBUG
6544 6544 pcic_dump_debqueue("Add");
6545 6545 #endif
6546 6546 cv_signal(&pcic_deb_cv);
6547 6547 mutex_exit(&pcic_deb_mtx);
6548 6548 return (dbp);
6549 6549 }
6550 6550
6551 6551 static void
6552 6552 pcic_rm_debqueue(void *id)
6553 6553 {
6554 6554 struct debounce *dbp, **dbpp = &pcic_deb_queue;
6555 6555
6556 6556 dbp = (struct debounce *)id;
6557 6557 mutex_enter(&pcic_deb_mtx);
6558 6558 while (*dbpp) {
6559 6559 if (*dbpp == dbp) {
6560 6560 *dbpp = dbp->next;
6561 6561 kmem_free(dbp, sizeof (*dbp));
6562 6562 #ifdef PCIC_DEBUG
6563 6563 pcic_dump_debqueue("Remove");
6564 6564 #endif
6565 6565 cv_signal(&pcic_deb_cv);
6566 6566 mutex_exit(&pcic_deb_mtx);
6567 6567 return;
6568 6568 }
6569 6569 dbpp = &((*dbpp)->next);
6570 6570 }
6571 6571 pcic_err(NULL, 6, "pcic: Failed to find debounce id 0x%p\n", id);
6572 6572 mutex_exit(&pcic_deb_mtx);
6573 6573 }
6574 6574
6575 6575
6576 6576 static int pcic_powerdelay = 0;
6577 6577
6578 6578 static int
6579 6579 pcic_exca_powerctl(pcicdev_t *pcic, int socket, int powerlevel)
6580 6580 {
6581 6581 int ind, value, orig_pwrctl;
6582 6582
6583 6583 /* power setup -- if necessary */
6584 6584 orig_pwrctl = pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
6585 6585
6586 6586 #if defined(PCIC_DEBUG)
6587 6587 pcic_err(pcic->dip, 6,
6588 6588 "pcic_exca_powerctl(socket %d) powerlevel=%x orig 0x%x\n",
6589 6589 socket, powerlevel, orig_pwrctl);
6590 6590 #endif
6591 6591 /* Preserve the PCIC_OUTPUT_ENABLE (control lines output enable) bit. */
6592 6592 powerlevel = (powerlevel & ~POWER_OUTPUT_ENABLE) |
6593 6593 (orig_pwrctl & POWER_OUTPUT_ENABLE);
6594 6594 if (powerlevel != orig_pwrctl) {
6595 6595 if (powerlevel & ~POWER_OUTPUT_ENABLE) {
6596 6596 int ifs;
6597 6597 /*
6598 6598 * set power to socket
6599 6599 * note that the powerlevel was calculated earlier
6600 6600 */
6601 6601 pcic_putb(pcic, socket, PCIC_POWER_CONTROL, powerlevel);
6602 6602 (void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
6603 6603
6604 6604 /*
6605 6605 * this second write to the power control register
6606 6606 * is needed to resolve a problem on
6607 6607 * the IBM ThinkPad 750
6608 6608 * where the first write doesn't latch.
6609 6609 * The second write appears to always work and
6610 6610 * doesn't hurt the operation of other chips
6611 6611 * so we can just use it -- this is good since we can't
6612 6612 * determine what chip the 750 actually uses
6613 6613 * (I suspect an early Ricoh).
6614 6614 */
6615 6615 pcic_putb(pcic, socket, PCIC_POWER_CONTROL, powerlevel);
6616 6616
6617 6617 value = pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
6618 6618 pcic_mswait(pcic, socket, pcic_powerdelay);
6619 6619 #if defined(PCIC_DEBUG)
6620 6620 pcic_err(pcic->dip, 8,
6621 6621 "\tpowerlevel reg = %x (ifs %x)\n",
6622 6622 value, pcic_getb(pcic, socket,
6623 6623 PCIC_INTERFACE_STATUS));
6624 6624 pcic_err(pcic->dip, 8,
6625 6625 "CBus regs: PS 0x%x, Control 0x%x\n",
6626 6626 pcic_getcb(pcic, CB_PRESENT_STATE),
6627 6627 pcic_getcb(pcic, CB_CONTROL));
6628 6628 #endif
6629 6629 /*
6630 6630 * since power was touched, make sure it says it
6631 6631 * is on. This lets it become stable.
6632 6632 */
6633 6633 for (ind = 0; ind < 20; ind++) {
6634 6634 ifs = pcic_getb(pcic, socket,
6635 6635 PCIC_INTERFACE_STATUS);
6636 6636 if (ifs & PCIC_POWER_ON)
6637 6637 break;
6638 6638 else {
6639 6639 pcic_putb(pcic, socket,
6640 6640 PCIC_POWER_CONTROL, 0);
6641 6641 (void) pcic_getb(pcic, socket,
6642 6642 PCIC_POWER_CONTROL);
6643 6643 pcic_mswait(pcic, socket, 40);
6644 6644 if (ind == 10) {
6645 6645 pcic_putcb(pcic, CB_EVENT_FORCE,
6646 6646 CB_EF_CVTEST);
6647 6647 pcic_mswait(pcic, socket, 100);
6648 6648 }
6649 6649 pcic_putb(pcic, socket,
6650 6650 PCIC_POWER_CONTROL,
6651 6651 powerlevel & ~POWER_OUTPUT_ENABLE);
6652 6652 (void) pcic_getb(pcic, socket,
6653 6653 PCIC_POWER_CONTROL);
6654 6654 pcic_mswait(pcic, socket,
6655 6655 pcic_powerdelay);
6656 6656 pcic_putb(pcic, socket,
6657 6657 PCIC_POWER_CONTROL, powerlevel);
6658 6658 (void) pcic_getb(pcic, socket,
6659 6659 PCIC_POWER_CONTROL);
6660 6660 pcic_mswait(pcic, socket,
6661 6661 pcic_powerdelay);
6662 6662 }
6663 6663 }
6664 6664
6665 6665 if (!(ifs & PCIC_POWER_ON)) {
6666 6666 cmn_err(CE_WARN,
6667 6667 "pcic socket %d: Power didn't get turned"
6668 6668 "on!\nif status 0x%x pwrc 0x%x(x%x) "
6669 6669 "misc1 0x%x igc 0x%x ind %d\n",
6670 6670 socket, ifs,
6671 6671 pcic_getb(pcic, socket, PCIC_POWER_CONTROL),
6672 6672 orig_pwrctl,
6673 6673 pcic_getb(pcic, socket, PCIC_MISC_CTL_1),
6674 6674 pcic_getb(pcic, socket, PCIC_INTERRUPT),
6675 6675 ind);
6676 6676 return (BAD_VCC);
6677 6677 }
6678 6678 #if defined(PCIC_DEBUG)
6679 6679 pcic_err(pcic->dip, 8,
6680 6680 "\tind = %d, if status %x pwrc 0x%x "
6681 6681 "misc1 0x%x igc 0x%x\n",
6682 6682 ind, ifs,
6683 6683 pcic_getb(pcic, socket, PCIC_POWER_CONTROL),
6684 6684 pcic_getb(pcic, socket, PCIC_MISC_CTL_1),
6685 6685 pcic_getb(pcic, socket, PCIC_INTERRUPT));
6686 6686 #endif
6687 6687 } else {
6688 6688 /* explicitly turned off the power */
6689 6689 pcic_putb(pcic, socket, PCIC_POWER_CONTROL, powerlevel);
6690 6690 (void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
6691 6691 }
6692 6692 }
6693 6693 return (SUCCESS);
6694 6694 }
6695 6695
6696 6696 static int pcic_cbdoreset_during_poweron = 1;
6697 6697 static int
6698 6698 pcic_cbus_powerctl(pcicdev_t *pcic, int socket)
6699 6699 {
6700 6700 uint32_t cbctl = 0, orig_cbctl, cbstev, cbps;
6701 6701 int ind, iobits;
6702 6702 pcic_socket_t *sockp = &pcic->pc_sockets[socket];
6703 6703
6704 6704 pcic_putcb(pcic, CB_STATUS_EVENT, CB_SE_POWER_CYCLE);
6705 6705
6706 6706 ind = pcic_power[sockp->pcs_vpp1].PowerLevel/10;
6707 6707 cbctl |= pcic_cbv_levels[ind];
6708 6708
6709 6709 ind = pcic_power[sockp->pcs_vcc].PowerLevel/10;
6710 6710 cbctl |= (pcic_cbv_levels[ind]<<4);
6711 6711
6712 6712 orig_cbctl = pcic_getcb(pcic, CB_CONTROL);
6713 6713
6714 6714 #if defined(PCIC_DEBUG)
6715 6715 pcic_err(pcic->dip, 6,
6716 6716 "pcic_cbus_powerctl(socket %d) vcc %d vpp1 %d "
6717 6717 "cbctl 0x%x->0x%x\n",
6718 6718 socket, sockp->pcs_vcc, sockp->pcs_vpp1, orig_cbctl, cbctl);
6719 6719 #endif
6720 6720 if (cbctl != orig_cbctl) {
6721 6721 if (pcic_cbdoreset_during_poweron &&
6722 6722 (orig_cbctl & (CB_C_VCCMASK|CB_C_VPPMASK)) == 0) {
6723 6723 iobits = pcic_getb(pcic, socket, PCIC_INTERRUPT);
6724 6724 pcic_putb(pcic, socket, PCIC_INTERRUPT,
6725 6725 iobits & ~PCIC_RESET);
6726 6726 }
6727 6727 pcic_putcb(pcic, CB_CONTROL, cbctl);
6728 6728
6729 6729 if ((cbctl & CB_C_VCCMASK) == (orig_cbctl & CB_C_VCCMASK)) {
6730 6730 pcic_mswait(pcic, socket, pcic_powerdelay);
6731 6731 return (SUCCESS);
6732 6732 }
6733 6733 for (ind = 0; ind < 20; ind++) {
6734 6734 cbstev = pcic_getcb(pcic, CB_STATUS_EVENT);
6735 6735
6736 6736 if (cbstev & CB_SE_POWER_CYCLE) {
6737 6737
6738 6738 /*
6739 6739 * delay 400 ms: though the standard defines that the Vcc
6740 6740 * set-up time is 20 ms, some PC-Card bridge requires longer
6741 6741 * duration.
6742 6742 * Note: We should check the status AFTER the delay to give time
6743 6743 * for things to stabilize.
6744 6744 */
6745 6745 pcic_mswait(pcic, socket, 400);
6746 6746
6747 6747 cbps = pcic_getcb(pcic, CB_PRESENT_STATE);
6748 6748 if (cbctl && !(cbps & CB_PS_POWER_CYCLE)) {
6749 6749 /* break; */
6750 6750 cmn_err(CE_WARN, "cbus_powerctl: power off??\n");
6751 6751 }
6752 6752 if (cbctl & CB_PS_BADVCC) {
6753 6753 cmn_err(CE_WARN, "cbus_powerctl: bad power request\n");
6754 6754 break;
6755 6755 }
6756 6756
6757 6757 #if defined(PCIC_DEBUG)
6758 6758 pcic_err(pcic->dip, 8,
6759 6759 "cbstev = 0x%x cbps = 0x%x cbctl 0x%x(0x%x)",
6760 6760 cbstev, pcic_getcb(pcic, CB_PRESENT_STATE),
6761 6761 cbctl, orig_cbctl);
6762 6762 #endif
6763 6763 if (pcic_cbdoreset_during_poweron &&
6764 6764 (orig_cbctl & (CB_C_VCCMASK|CB_C_VPPMASK)) == 0) {
6765 6765 pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits);
6766 6766 }
6767 6767 return (SUCCESS);
6768 6768 }
6769 6769 pcic_mswait(pcic, socket, 40);
6770 6770 }
6771 6771 if (pcic_cbdoreset_during_poweron &&
6772 6772 (orig_cbctl & (CB_C_VCCMASK|CB_C_VPPMASK)) == 0) {
6773 6773 pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits);
6774 6774 }
6775 6775 cmn_err(CE_WARN,
6776 6776 "pcic socket %d: Power didn't get turned on/off!\n"
6777 6777 "cbstev = 0x%x cbps = 0x%x cbctl 0x%x(0x%x) "
6778 6778 "vcc %d vpp1 %d", socket, cbstev,
6779 6779 pcic_getcb(pcic, CB_PRESENT_STATE),
6780 6780 cbctl, orig_cbctl, sockp->pcs_vcc, sockp->pcs_vpp1);
6781 6781 return (BAD_VCC);
6782 6782 }
6783 6783 return (SUCCESS);
6784 6784 }
6785 6785
6786 6786 static int pcic_do_pprintf = 0;
6787 6787
6788 6788 static void
6789 6789 pcic_dump_debqueue(char *msg)
6790 6790 {
6791 6791 struct debounce *debp = pcic_deb_queue;
6792 6792 clock_t lbolt;
6793 6793
6794 6794 (void) drv_getparm(LBOLT, &lbolt);
6795 6795 pcic_err(NULL, 6, debp ? "pcic debounce list (%s) lbolt 0x%x:\n" :
6796 6796 "pcic debounce_list (%s) EMPTY lbolt 0x%x\n", msg, lbolt);
6797 6797 while (debp) {
6798 6798 pcic_err(NULL, 6, "%p: exp 0x%x next 0x%p id 0x%p\n",
6799 6799 (void *) debp, (int)debp->expire, (void *) debp->next,
6800 6800 debp->pcs->pcs_debounce_id);
6801 6801 debp = debp->next;
6802 6802 }
6803 6803 }
6804 6804
6805 6805
6806 6806 /* PRINTFLIKE3 */
6807 6807 static void
6808 6808 pcic_err(dev_info_t *dip, int level, const char *fmt, ...)
6809 6809 {
6810 6810 if (pcic_debug && (level <= pcic_debug)) {
6811 6811 va_list adx;
6812 6812 int instance;
6813 6813 char buf[256];
6814 6814 const char *name;
6815 6815 #if !defined(PCIC_DEBUG)
6816 6816 int ce;
6817 6817 char qmark = 0;
6818 6818
6819 6819 if (level <= 3)
6820 6820 ce = CE_WARN;
6821 6821 else
6822 6822 ce = CE_CONT;
6823 6823 if (level == 4)
6824 6824 qmark = 1;
6825 6825 #endif
6826 6826
6827 6827 if (dip) {
6828 6828 instance = ddi_get_instance(dip);
6829 6829 /* name = ddi_binding_name(dip); */
6830 6830 name = ddi_driver_name(dip);
6831 6831 } else {
6832 6832 instance = 0;
6833 6833 name = "";
6834 6834 }
6835 6835
6836 6836 va_start(adx, fmt);
6837 6837 (void) vsprintf(buf, fmt, adx);
6838 6838 va_end(adx);
6839 6839
6840 6840 #if defined(PCIC_DEBUG)
6841 6841 if (pcic_do_pprintf) {
6842 6842 if (dip) {
6843 6843 if (instance >= 0)
6844 6844 prom_printf("%s(%d),0x%p: %s", name,
6845 6845 instance, (void *)dip, buf);
6846 6846 else
6847 6847 prom_printf("%s,0x%p: %s",
6848 6848 name, (void *)dip, buf);
6849 6849 } else
6850 6850 prom_printf(buf);
6851 6851 } else {
6852 6852 if (dip) {
6853 6853 if (instance >= 0)
6854 6854 cmn_err(CE_CONT, "%s(%d),0x%p: %s",
6855 6855 name, instance, (void *) dip, buf);
6856 6856 else
6857 6857 cmn_err(CE_CONT, "%s,0x%p: %s",
6858 6858 name, (void *) dip, buf);
6859 6859 } else
6860 6860 cmn_err(CE_CONT, buf);
6861 6861 }
6862 6862 #else
6863 6863 if (dip)
6864 6864 cmn_err(ce, qmark ? "?%s%d: %s" : "%s%d: %s", name,
6865 6865 instance, buf);
6866 6866 else
6867 6867 cmn_err(ce, qmark ? "?%s" : buf, buf);
6868 6868 #endif
6869 6869 }
6870 6870 }
↓ open down ↓ |
1848 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX