1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/cpuvar.h> 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 #include <sys/sunddi.h> 33 #include <sys/ddi.h> 34 #include <sys/sysmacros.h> 35 #include <sys/note.h> 36 37 #include <sys/modctl.h> /* for modload() */ 38 #include <sys/platform_module.h> 39 #include <sys/errno.h> 40 #include <sys/daktari.h> 41 #include <sys/machsystm.h> 42 #include <sys/promif.h> 43 #include <vm/page.h> 44 #include <sys/memnode.h> 45 #include <vm/vm_dep.h> 46 47 /* I2C Stuff */ 48 #include <sys/i2c/clients/i2c_client.h> 49 50 51 int (*p2get_mem_unum)(int, uint64_t, char *, int, int *); 52 53 /* Daktari Keyswitch Information */ 54 #define DAK_KEY_POLL_PORT 3 55 #define DAK_KEY_POLL_BIT 2 56 #define DAK_KEY_POLL_INTVL 10 57 58 static boolean_t key_locked_bit; 59 static clock_t keypoll_timeout_hz; 60 61 /* 62 * Table that maps memory slices to a specific memnode. 63 */ 64 int slice_to_memnode[DAK_MAX_SLICE]; 65 66 /* 67 * For software memory interleaving support. 68 */ 69 static void update_mem_bounds(int, int, int, uint64_t, uint64_t); 70 71 static uint64_t 72 slice_table[DAK_SBD_SLOTS][DAK_CPUS_PER_BOARD][DAK_BANKS_PER_MC][2]; 73 74 #define SLICE_PA 0 75 #define SLICE_SPAN 1 76 77 int (*daktari_ssc050_get_port_bit) (dev_info_t *, int, int, uint8_t *, int); 78 extern void (*abort_seq_handler)(); 79 static int daktari_dev_search(dev_info_t *, void *); 80 static void keyswitch_poll(void *); 81 static void daktari_abort_seq_handler(char *msg); 82 83 void 84 startup_platform(void) 85 { 86 /* 87 * Disable an active h/w watchdog timer 88 * upon exit to OBP. 89 */ 90 extern int disable_watchdog_on_exit; 91 disable_watchdog_on_exit = 1; 92 } 93 94 int 95 set_platform_tsb_spares() 96 { 97 return (0); 98 } 99 100 #pragma weak mmu_init_large_pages 101 102 void 103 set_platform_defaults(void) 104 { 105 extern void mmu_init_large_pages(size_t); 106 107 if ((mmu_page_sizes == max_mmu_page_sizes) && 108 (mmu_ism_pagesize != MMU_PAGESIZE32M)) { 109 if (&mmu_init_large_pages) 110 mmu_init_large_pages(mmu_ism_pagesize); 111 } 112 } 113 114 void 115 load_platform_modules(void) 116 { 117 if (modload("misc", "pcihp") < 0) { 118 cmn_err(CE_NOTE, "pcihp driver failed to load"); 119 } 120 if (modload("drv", "pmc") < 0) { 121 cmn_err(CE_NOTE, "pmc driver failed to load"); 122 } 123 124 } 125 126 void 127 load_platform_drivers(void) 128 { 129 char **drv; 130 dev_info_t *keysw_dip; 131 132 static char *boot_time_drivers[] = { 133 "hpc3130", 134 "todds1287", 135 "mc-us3", 136 "ssc050", 137 "pcisch", 138 NULL 139 }; 140 141 for (drv = boot_time_drivers; *drv; drv++) { 142 if (i_ddi_attach_hw_nodes(*drv) != DDI_SUCCESS) 143 cmn_err(CE_WARN, "Failed to install \"%s\" driver.", 144 *drv); 145 } 146 147 /* 148 * mc-us3 & ssc050 must stay loaded for plat_get_mem_unum() 149 * and keyswitch_poll() 150 */ 151 (void) ddi_hold_driver(ddi_name_to_major("mc-us3")); 152 (void) ddi_hold_driver(ddi_name_to_major("ssc050")); 153 154 /* Gain access into the ssc050_get_port function */ 155 daktari_ssc050_get_port_bit = (int (*) (dev_info_t *, int, int, 156 uint8_t *, int)) modgetsymvalue("ssc050_get_port_bit", 0); 157 if (daktari_ssc050_get_port_bit == NULL) { 158 cmn_err(CE_WARN, "cannot find ssc050_get_port_bit"); 159 return; 160 } 161 162 ddi_walk_devs(ddi_root_node(), daktari_dev_search, (void *)&keysw_dip); 163 ASSERT(keysw_dip != NULL); 164 165 keypoll_timeout_hz = drv_usectohz(10 * MICROSEC); 166 keyswitch_poll(keysw_dip); 167 abort_seq_handler = daktari_abort_seq_handler; 168 } 169 170 static int 171 daktari_dev_search(dev_info_t *dip, void *arg) 172 { 173 char *compatible = NULL; /* Search tree for "i2c-ssc050" */ 174 int *dev_regs; /* Info about where the device is. */ 175 uint_t len; 176 int err; 177 178 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 179 "compatible", &compatible) != DDI_PROP_SUCCESS) 180 return (DDI_WALK_CONTINUE); 181 182 if (strcmp(compatible, "i2c-ssc050") == 0) { 183 ddi_prop_free(compatible); 184 185 err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 186 DDI_PROP_DONTPASS, "reg", &dev_regs, &len); 187 if (err != DDI_PROP_SUCCESS) { 188 return (DDI_WALK_CONTINUE); 189 } 190 /* 191 * regs[0] contains the bus number and regs[1] 192 * contains the device address of the i2c device. 193 * 0x82 is the device address of the i2c device 194 * from which the key switch position is read. 195 */ 196 if (dev_regs[0] == 0 && dev_regs[1] == 0x82) { 197 *((dev_info_t **)arg) = dip; 198 ddi_prop_free(dev_regs); 199 return (DDI_WALK_TERMINATE); 200 } 201 ddi_prop_free(dev_regs); 202 } else { 203 ddi_prop_free(compatible); 204 } 205 return (DDI_WALK_CONTINUE); 206 } 207 208 static void 209 keyswitch_poll(void *arg) 210 { 211 dev_info_t *dip = arg; 212 uchar_t port_byte; 213 int port = DAK_KEY_POLL_PORT; 214 int bit = DAK_KEY_POLL_BIT; 215 int err; 216 217 err = daktari_ssc050_get_port_bit(dip, port, bit, 218 &port_byte, I2C_NOSLEEP); 219 if (err != 0) { 220 return; 221 } 222 223 key_locked_bit = (boolean_t)((port_byte & 0x1)); 224 timeout(keyswitch_poll, (caddr_t)dip, keypoll_timeout_hz); 225 } 226 227 static void 228 daktari_abort_seq_handler(char *msg) 229 { 230 if (key_locked_bit == 0) 231 cmn_err(CE_CONT, "KEY in LOCKED position, " 232 "ignoring debug enter sequence"); 233 else { 234 debug_enter(msg); 235 } 236 } 237 238 239 int 240 plat_cpu_poweron(struct cpu *cp) 241 { 242 _NOTE(ARGUNUSED(cp)) 243 return (ENOTSUP); 244 } 245 246 int 247 plat_cpu_poweroff(struct cpu *cp) 248 { 249 _NOTE(ARGUNUSED(cp)) 250 return (ENOTSUP); 251 } 252 253 /* 254 * Given a pfn, return the board and beginning/end of the page's 255 * memory controller's address range. 256 */ 257 static int 258 plat_discover_slice(pfn_t pfn, pfn_t *first, pfn_t *last) 259 { 260 int bd, cpu, bank; 261 262 for (bd = 0; bd < DAK_SBD_SLOTS; bd++) { 263 for (cpu = 0; cpu < DAK_CPUS_PER_BOARD; cpu++) { 264 for (bank = 0; bank < DAK_BANKS_PER_MC; bank++) { 265 uint64_t *slice = slice_table[bd][cpu][bank]; 266 uint64_t base = btop(slice[SLICE_PA]); 267 uint64_t len = btop(slice[SLICE_SPAN]); 268 if (len && pfn >= base && pfn < (base + len)) { 269 *first = base; 270 *last = base + len - 1; 271 return (bd); 272 } 273 } 274 } 275 } 276 panic("plat_discover_slice: no slice for pfn 0x%lx\n", pfn); 277 /* NOTREACHED */ 278 } 279 280 /*ARGSUSED*/ 281 void 282 plat_freelist_process(int mnode) 283 {} 284 285 286 /* 287 * Called for each board/cpu/PA range detected in plat_fill_mc(). 288 */ 289 static void 290 update_mem_bounds(int boardid, int cpuid, int bankid, 291 uint64_t base, uint64_t size) 292 { 293 uint64_t end; 294 int mnode; 295 296 slice_table[boardid][cpuid][bankid][SLICE_PA] = base; 297 slice_table[boardid][cpuid][bankid][SLICE_SPAN] = size; 298 299 end = base + size - 1; 300 301 /* 302 * First see if this board already has a memnode associated 303 * with it. If not, see if this slice has a memnode. This 304 * covers the cases where a single slice covers multiple 305 * boards (cross-board interleaving) and where a single 306 * board has multiple slices (1+GB DIMMs). 307 */ 308 if ((mnode = plat_lgrphand_to_mem_node(boardid)) == -1) { 309 if ((mnode = slice_to_memnode[PA_2_SLICE(base)]) == -1) 310 mnode = mem_node_alloc(); 311 312 ASSERT(mnode >= 0); 313 ASSERT(mnode < MAX_MEM_NODES); 314 plat_assign_lgrphand_to_mem_node(boardid, mnode); 315 } 316 317 base = P2ALIGN(base, (1ul << PA_SLICE_SHIFT)); 318 319 while (base < end) { 320 slice_to_memnode[PA_2_SLICE(base)] = mnode; 321 base += (1ul << PA_SLICE_SHIFT); 322 } 323 } 324 325 /* 326 * Dynamically detect memory slices in the system by decoding 327 * the cpu memory decoder registers at boot time. 328 */ 329 void 330 plat_fill_mc(pnode_t nodeid) 331 { 332 uint64_t mc_addr, saf_addr; 333 uint64_t mc_decode[DAK_BANKS_PER_MC]; 334 uint64_t base, size; 335 uint64_t saf_mask; 336 uint64_t offset; 337 uint32_t regs[4]; 338 int len; 339 int local_mc; 340 int portid; 341 int boardid; 342 int cpuid; 343 int i; 344 345 if ((prom_getprop(nodeid, "portid", (caddr_t)&portid) < 0) || 346 (portid == -1)) 347 return; 348 349 /* 350 * Decode the board number from the MC portid. Assumes 351 * portid == safari agentid. 352 */ 353 boardid = DAK_GETSLOT(portid); 354 cpuid = DAK_GETSID(portid); 355 356 /* 357 * The "reg" property returns 4 32-bit values. The first two are 358 * combined to form a 64-bit address. The second two are for a 359 * 64-bit size, but we don't actually need to look at that value. 360 */ 361 len = prom_getproplen(nodeid, "reg"); 362 if (len != (sizeof (uint32_t) * 4)) { 363 prom_printf("Warning: malformed 'reg' property\n"); 364 return; 365 } 366 if (prom_getprop(nodeid, "reg", (caddr_t)regs) < 0) 367 return; 368 mc_addr = ((uint64_t)regs[0]) << 32; 369 mc_addr |= (uint64_t)regs[1]; 370 371 /* 372 * Figure out whether the memory controller we are examining 373 * belongs to this CPU or a different one. 374 */ 375 saf_addr = lddsafaddr(8); 376 saf_mask = (uint64_t)SAF_MASK; 377 if ((mc_addr & saf_mask) == saf_addr) 378 local_mc = 1; 379 else 380 local_mc = 0; 381 382 for (i = 0; i < DAK_BANKS_PER_MC; i++) { 383 /* 384 * Memory decode masks are at offsets 0x10 - 0x28. 385 */ 386 offset = 0x10 + (i << 3); 387 388 /* 389 * If the memory controller is local to this CPU, we use 390 * the special ASI to read the decode registers. 391 * Otherwise, we load the values from a magic address in 392 * I/O space. 393 */ 394 if (local_mc) 395 mc_decode[i] = lddmcdecode(offset); 396 else 397 mc_decode[i] = lddphysio(mc_addr | offset); 398 399 /* 400 * If the upper bit is set, we have a valid mask 401 */ 402 if ((int64_t)mc_decode[i] < 0) { 403 /* 404 * The memory decode register is a bitmask field, 405 * so we can decode that into both a base and 406 * a span. 407 */ 408 base = MC_BASE(mc_decode[i]) << PHYS2UM_SHIFT; 409 size = MC_UK2SPAN(mc_decode[i]); 410 update_mem_bounds(boardid, cpuid, i, base, size); 411 } 412 } 413 } 414 415 416 /* 417 * This routine is run midway through the boot process. By the time we get 418 * here, we know about all the active CPU boards in the system, and we have 419 * extracted information about each board's memory from the memory 420 * controllers. We have also figured out which ranges of memory will be 421 * assigned to which memnodes, so we walk the slice table to build the table 422 * of memnodes. 423 */ 424 /* ARGSUSED */ 425 void 426 plat_build_mem_nodes(u_longlong_t *list, size_t nelems) 427 { 428 int slice; 429 pfn_t basepfn; 430 pgcnt_t npgs; 431 432 mem_node_pfn_shift = PFN_SLICE_SHIFT; 433 mem_node_physalign = (1ull << PA_SLICE_SHIFT); 434 npgs = 1ull << PFN_SLICE_SHIFT; 435 436 for (slice = 0; slice < DAK_MAX_SLICE; slice++) { 437 if (slice_to_memnode[slice] == -1) 438 continue; 439 basepfn = (uint64_t)slice << PFN_SLICE_SHIFT; 440 mem_node_add_slice(basepfn, basepfn + npgs - 1); 441 } 442 } 443 444 445 446 /* 447 * Daktari support for lgroups. 448 * 449 * On Daktari, an lgroup platform handle == slot number. 450 * 451 * Mappings between lgroup handles and memnodes are managed 452 * in addition to mappings between memory slices and memnodes 453 * to support cross-board interleaving as well as multiple 454 * slices per board (e.g. >1GB DIMMs). The initial mapping 455 * of memnodes to lgroup handles is determined at boot time. 456 */ 457 int 458 plat_pfn_to_mem_node(pfn_t pfn) 459 { 460 return (slice_to_memnode[PFN_2_SLICE(pfn)]); 461 } 462 463 /* 464 * Return the platform handle for the lgroup containing the given CPU 465 * 466 * For Daktari, lgroup platform handle == slot number 467 */ 468 lgrp_handle_t 469 plat_lgrp_cpu_to_hand(processorid_t id) 470 { 471 return (DAK_GETSLOT(id)); 472 } 473 474 /* 475 * Platform specific lgroup initialization 476 */ 477 void 478 plat_lgrp_init(void) 479 { 480 int i; 481 482 /* 483 * Initialize lookup tables to invalid values so we catch 484 * any illegal use of them. 485 */ 486 for (i = 0; i < DAK_MAX_SLICE; i++) { 487 slice_to_memnode[i] = -1; 488 } 489 } 490 491 /* 492 * Return latency between "from" and "to" lgroups 493 * 494 * This latency number can only be used for relative comparison 495 * between lgroups on the running system, cannot be used across platforms, 496 * and may not reflect the actual latency. It is platform and implementation 497 * specific, so platform gets to decide its value. It would be nice if the 498 * number was at least proportional to make comparisons more meaningful though. 499 * NOTE: The numbers below are supposed to be load latencies for uncached 500 * memory divided by 10. 501 */ 502 int 503 plat_lgrp_latency(lgrp_handle_t from, lgrp_handle_t to) 504 { 505 /* 506 * Return min remote latency when there are more than two lgroups 507 * (root and child) and getting latency between two different lgroups 508 * or root is involved 509 */ 510 if (lgrp_optimizations() && (from != to || 511 from == LGRP_DEFAULT_HANDLE || to == LGRP_DEFAULT_HANDLE)) 512 return (21); 513 else 514 return (19); 515 } 516 /* 517 * No platform drivers on this platform 518 */ 519 char *platform_module_list[] = { 520 (char *)0 521 }; 522 523 /*ARGSUSED*/ 524 void 525 plat_tod_fault(enum tod_fault_type tod_bad) 526 { 527 } 528 529 /*ARGSUSED*/ 530 int 531 plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id, 532 int flt_in_memory, ushort_t flt_status, char *buf, int buflen, int *lenp) 533 { 534 if (flt_in_memory && (p2get_mem_unum != NULL)) 535 return (p2get_mem_unum(synd_code, P2ALIGN(flt_addr, 8), 536 buf, buflen, lenp)); 537 else 538 return (ENOTSUP); 539 } 540 541 /* 542 * This platform hook gets called from mc_add_mem_unum_label() in the mc-us3 543 * driver giving each platform the opportunity to add platform 544 * specific label information to the unum for ECC error logging purposes. 545 */ 546 void 547 plat_add_mem_unum_label(char *unum, int mcid, int bank, int dimm) 548 { 549 _NOTE(ARGUNUSED(bank, dimm)) 550 551 char board = DAK_GETSLOT_LABEL(mcid); 552 char old_unum[UNUM_NAMLEN]; 553 554 strcpy(old_unum, unum); 555 snprintf(unum, UNUM_NAMLEN, "Slot %c: %s", board, old_unum); 556 } 557 558 int 559 plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp) 560 { 561 char board = DAK_GETSLOT_LABEL(cpuid); 562 563 if (snprintf(buf, buflen, "Slot %c", board) >= buflen) { 564 return (ENOSPC); 565 } else { 566 *lenp = strlen(buf); 567 return (0); 568 } 569 } 570 571 /* 572 * The zuluvm module requires a dmv interrupt for each installed zulu board. 573 */ 574 void 575 plat_dmv_params(uint_t *hwint, uint_t *swint) 576 { 577 *hwint = 0; 578 *swint = DAK_SBD_SLOTS - 1; 579 } 580