1 /* $NetBSD: podulebus.c,v 1.20 2005/12/11 12:16:05 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1994-1996 Mark Brinicombe. 5 * Copyright (c) 1994 Brini. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Brini. 19 * 4. The name of the company nor the name of the author may be used to 20 * endorse or promote products derived from this software without specific 21 * prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED 24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * RiscBSD kernel project 36 * 37 * podulebus.c 38 * 39 * Podule probe and configuration routines 40 * 41 * Created : 07/11/94 42 */ 43 44 #include <sys/param.h> 45 46 __KERNEL_RCSID(0, "$NetBSD: podulebus.c,v 1.20 2005/12/11 12:16:05 christos Exp $"); 47 48 #include <sys/systm.h> 49 #include <sys/kernel.h> 50 #include <sys/conf.h> 51 #include <sys/malloc.h> 52 #include <sys/device.h> 53 #include <uvm/uvm_extern.h> 54 #include <machine/io.h> 55 #include <arm/arm32/katelib.h> 56 #include <machine/intr.h> 57 #include <machine/bootconfig.h> 58 #include <machine/pmap.h> 59 #include <arm/iomd/iomdreg.h> 60 #include <arm/iomd/iomdvar.h> 61 #include <acorn32/podulebus/podulebus.h> 62 #include <dev/podulebus/podules.h> 63 #include <dev/podulebus/podule_data.h> 64 65 #include "locators.h" 66 67 /* Array of podule structures, one per possible podule */ 68 69 podule_t podules[MAX_PODULES + MAX_NETSLOTS]; 70 71 extern struct bus_space podulebus_bs_tag; 72 73 /* Declare prototypes */ 74 75 u_int poduleread __P((u_int, int)); 76 int podulebusmatch(struct device *, struct cfdata *, void *); 77 void podulebusattach(struct device *, struct device *, void *); 78 int podulebusprint(void *, const char *); 79 int podulebussubmatch(struct device *, struct cfdata *, 80 const int *, void *); 81 void podulechunkdirectory(podule_t *); 82 void podulescan(struct device *); 83 84 /* 85 * int podulebusmatch(struct device *parent, void *match, void *aux) 86 * 87 * Probe for the podule bus. Currently all this does is return 1 to 88 * indicate that the podule bus was found. 89 */ 90 91 int 92 podulebusmatch(parent, cf, aux) 93 struct device *parent; 94 struct cfdata *cf; 95 void *aux; 96 { 97 switch (IOMD_ID) { 98 case RPC600_IOMD_ID: 99 case ARM7500_IOC_ID: 100 case ARM7500FE_IOC_ID: 101 return(1); 102 } 103 return (0); 104 } 105 106 107 int 108 podulebusprint(aux, name) 109 void *aux; 110 const char *name; 111 { 112 struct podule_attach_args *pa = aux; 113 114 if (name) 115 aprint_normal("podule at %s", name); 116 if (pa->pa_podule->slottype == SLOT_POD) 117 aprint_normal(" slot %d", pa->pa_podule_number); 118 else if (pa->pa_podule->slottype == SLOT_NET) 119 aprint_normal(" [ netslot %d ]", 120 pa->pa_podule_number - MAX_PODULES); 121 #ifdef DIAGNOSTIC 122 else 123 panic("Invalid slot type"); 124 #endif 125 126 return (UNCONF); 127 } 128 129 130 int 131 podulebussubmatch(parent, cf, ldesc, aux) 132 struct device *parent; 133 struct cfdata *cf; 134 const int *ldesc; 135 void *aux; 136 { 137 struct podule_attach_args *pa = aux; 138 139 /* Return priority 0 or 1 for wildcarded podule */ 140 141 if (cf->cf_loc[PODULEBUSCF_SLOT] == PODULEBUSCF_SLOT_DEFAULT) 142 return(config_match(parent, cf, aux)); 143 144 /* Return higher priority if we match the specific podule */ 145 146 else if (cf->cf_loc[PODULEBUSCF_SLOT] == pa->pa_podule_number) 147 return(config_match(parent, cf, aux) * 8); 148 149 /* Fail */ 150 return(0); 151 } 152 153 154 #if 0 155 void 156 dump_podule(podule) 157 podule_t *podule; 158 { 159 printf("podule%d: ", podule->podulenum); 160 printf("flags0=%02x ", podule->flags0); 161 printf("flags1=%02x ", podule->flags1); 162 printf("reserved=%02x ", podule->reserved); 163 printf("product=%02x ", podule->product); 164 printf("manufacturer=%02x ", podule->manufacturer); 165 printf("country=%02x ", podule->country); 166 printf("irq_addr=%08x ", podule->irq_addr); 167 printf("irq_mask=%02x ", podule->irq_mask); 168 printf("fiq_addr=%08x ", podule->fiq_addr); 169 printf("fiq_mask=%02x ", podule->fiq_mask); 170 printf("fast_base=%08x ", podule->fast_base); 171 printf("medium_base=%08x ", podule->medium_base); 172 printf("slow_base=%08x ", podule->slow_base); 173 printf("sync_base=%08x ", podule->sync_base); 174 printf("mod_base=%08x ", podule->mod_base); 175 printf("easi_base=%08x ", podule->easi_base); 176 printf("attached=%d ", podule->attached); 177 printf("slottype=%d ", podule->slottype); 178 printf("podulenum=%d ", podule->podulenum); 179 printf("description=%s ", podule->description); 180 printf("\n"); 181 } 182 #endif 183 184 void 185 podulechunkdirectory(podule) 186 podule_t *podule; 187 { 188 u_int address; 189 u_int id; 190 u_int size; 191 u_int addr; 192 int loop; 193 int done_f5; 194 195 done_f5 = 0; 196 address = 0x40; 197 198 do { 199 id = podule->read_rom(podule->sync_base, address); 200 size = podule->read_rom(podule->sync_base, address + 4); 201 size |= (podule->read_rom(podule->sync_base, address + 8) << 8); 202 size |= (podule->read_rom(podule->sync_base, address + 12) << 16); 203 if (id == 0xf5) { 204 addr = podule->read_rom(podule->sync_base, address + 16); 205 addr |= (podule->read_rom(podule->sync_base, address + 20) << 8); 206 addr |= (podule->read_rom(podule->sync_base, address + 24) << 16); 207 addr |= (podule->read_rom(podule->sync_base, address + 28) << 24); 208 if (addr < 0x800 && done_f5 == 0) { 209 done_f5 = 1; 210 for (loop = 0; loop < size; ++loop) { 211 if (loop < PODULE_DESCRIPTION_LENGTH) { 212 podule->description[loop] = 213 podule->read_rom(podule->sync_base, (addr + loop)*4); 214 podule->description[loop + 1] = 0; 215 } 216 } 217 } 218 } 219 #ifdef DEBUG_CHUNK_DIR 220 if (id == 0xf5 || id == 0xf1 || id == 0xf2 || id == 0xf3 || id == 0xf4 || id == 0xf6) { 221 addr = podule->read_rom(podule->sync_base, address + 16); 222 addr |= (podule->read_rom(podule->sync_base, address + 20) << 8); 223 addr |= (podule->read_rom(podule->sync_base, address + 24) << 16); 224 addr |= (podule->read_rom(podule->sync_base, address + 28) << 24); 225 printf("<%04x.%04x.%04x.%04x>", id, address, addr, size); 226 if (addr < 0x800) { 227 for (loop = 0; loop < size; ++loop) { 228 printf("%c", podule->read_rom(podule->sync_base, (addr + loop)*4)); 229 } 230 printf("\\n\n"); 231 } 232 } 233 #endif 234 address += 32; 235 } while (id != 0 && address < 0x800); 236 } 237 238 239 void 240 poduleexamine(podule, dev, slottype) 241 podule_t *podule; 242 struct device *dev; 243 int slottype; 244 { 245 struct manufacturer_description *man_desc; 246 struct podule_description *pod_desc; 247 248 /* Test to see if the podule is present */ 249 250 if ((podule->flags0 & 0x02) == 0x00) { 251 podule->slottype = slottype; 252 if (slottype == SLOT_NET) 253 printf("netslot%d at %s : ", podule->podulenum - MAX_PODULES, 254 dev->dv_xname); 255 else 256 printf("podule%d at %s : ", podule->podulenum, 257 dev->dv_xname); 258 259 /* Is it Acorn conformant ? */ 260 261 if (podule->flags0 & 0x80) 262 printf("Non-Acorn conformant expansion card\n"); 263 else { 264 int id; 265 266 /* Is it a simple podule ? */ 267 268 id = (podule->flags0 >> 3) & 0x0f; 269 if (id != 0) 270 printf("Simple expansion card <%x>\n", id); 271 else { 272 /* Scan the chunk directory if present for tags we use */ 273 if (podule->flags1 & PODULE_FLAGS_CD) 274 podulechunkdirectory(podule); 275 276 /* Do we know this manufacturer ? */ 277 man_desc = known_manufacturers; 278 while (man_desc->description) { 279 if (man_desc->manufacturer_id == 280 podule->manufacturer) 281 break; 282 ++man_desc; 283 } 284 if (!man_desc->description) 285 printf("man=%04x : ", podule->manufacturer); 286 else 287 printf("%s : ", man_desc->description); 288 289 /* Do we know this product ? */ 290 291 pod_desc = known_podules; 292 while (pod_desc->description) { 293 if (pod_desc->product_id == podule->product) 294 break; 295 ++pod_desc; 296 } 297 if (!pod_desc->description) 298 printf("prod=%04x : ", 299 podule->product); 300 else 301 printf("%s : ", pod_desc->description); 302 printf("%s\n", podule->description); 303 } 304 } 305 } 306 } 307 308 309 u_int 310 poduleread(address, offset) 311 u_int address; 312 int offset; 313 { 314 315 return(ReadByte(address + offset)); 316 } 317 318 void 319 podulescan(dev) 320 struct device *dev; 321 { 322 int loop; 323 podule_t *podule; 324 u_char *address; 325 u_int offset = 0; 326 327 /* Loop round all the podules */ 328 329 for (loop = 0; loop < MAX_PODULES; ++loop, offset += SIMPLE_PODULE_SIZE) { 330 podule = &podules[loop]; 331 podule->podulenum = loop; 332 podule->attached = 0; 333 podule->slottype = SLOT_NONE; 334 podule->interrupt = IRQ_PODULE; 335 podule->read_rom = poduleread; 336 podule->dma_channel = -1; 337 podule->dma_interrupt = -1; 338 podule->description[0] = 0; 339 340 if (loop == 4) offset += PODULE_GAP; 341 address = ((u_char *)SYNC_PODULE_BASE) + offset; 342 343 if ((address[0] & 0x02) == 0x00) { 344 podule->fast_base = FAST_PODULE_BASE + offset; 345 podule->medium_base = MEDIUM_PODULE_BASE + offset; 346 podule->slow_base = SLOW_PODULE_BASE + offset; 347 podule->sync_base = SYNC_PODULE_BASE + offset; 348 podule->mod_base = MOD_PODULE_BASE + offset; 349 podule->easi_base = EASI_BASE + loop * EASI_SIZE; 350 } else { 351 address = ((u_char *)EASI_BASE) + loop * EASI_SIZE; 352 if ((address[0] & 0x02) != 0x00) 353 continue; 354 355 podule->fast_base = 0; 356 podule->medium_base = 0; 357 podule->slow_base = 0; 358 podule->sync_base = 0; 359 podule->mod_base = 0; 360 podule->easi_base = EASI_BASE + loop * EASI_SIZE; 361 } 362 363 /* XXX - Really needs to be linked to a DMA manager */ 364 if (IOMD_ID == RPC600_IOMD_ID) { 365 switch (loop) { 366 case 0: 367 podule->dma_channel = 2; 368 podule->dma_interrupt = IRQ_DMACH2; 369 break; 370 case 1: 371 podule->dma_channel = 3; 372 podule->dma_interrupt = IRQ_DMACH3; 373 break; 374 } 375 } 376 377 /* Get information from the podule header */ 378 379 podule->flags0 = address[0]; 380 if ((podule->flags0 & 0x78) == 0) { 381 podule->flags1 = address[4]; 382 podule->reserved = address[8]; 383 podule->product = address[12] + (address[16] << 8); 384 podule->manufacturer = address[20] + (address[24] << 8); 385 podule->country = address[28]; 386 if (podule->flags1 & PODULE_FLAGS_IS) { 387 podule->irq_addr = address[52] + (address[56] << 8) + (address[60] << 16); 388 podule->irq_addr += podule->slow_base; 389 podule->irq_mask = address[48]; 390 if (podule->irq_mask == 0) 391 podule->irq_mask = 0x01; 392 podule->fiq_addr = address[36] + (address[40] << 8) + (address[44] << 16); 393 podule->fiq_addr += podule->slow_base; 394 podule->fiq_mask = address[32]; 395 if (podule->fiq_mask == 0) 396 podule->fiq_mask = 0x04; 397 } else { 398 podule->irq_addr = podule->slow_base; 399 podule->irq_mask = 0x01; 400 podule->fiq_addr = podule->slow_base; 401 podule->fiq_mask = 0x04; 402 } 403 } 404 405 poduleexamine(podule, dev, SLOT_POD); 406 } 407 } 408 409 410 /* 411 * void podulebusattach(struct device *parent, struct device *dev, void *aux) 412 * 413 * Attach podulebus. 414 * This probes all the podules and sets up the podules array with 415 * information found in the podule headers. 416 * After identifing all the podules, all the children of the podulebus 417 * are probed and attached. 418 */ 419 420 void 421 podulebusattach(parent, self, aux) 422 struct device *parent; 423 struct device *self; 424 void *aux; 425 { 426 int loop; 427 struct podule_attach_args pa; 428 #if 0 429 int easi_time; 430 int bit; 431 #endif 432 unsigned int value; 433 char argstring[20]; 434 435 #if 0 436 easi_time = IOMD_READ_BYTE(IOMD_ECTCR); 437 printf(": easi timings="); 438 for (bit = 0x01; bit < 0x100; bit = bit << 1) 439 if (easi_time & bit) 440 printf("C"); 441 else 442 printf("A"); 443 #endif 444 printf("\n"); 445 446 447 #if 0 /* XXXJRT */ 448 /* Ok we need to map in the podulebus */ 449 /* with the new pmap mappings have to be done when the L1 tables 450 * are built during initarm 451 */ 452 /* Map the FAST and SYNC simple podules */ 453 pmap_map_section((vm_offset_t)pmap_kernel()->pm_pdir, 454 SYNC_PODULE_BASE & 0xfff00000, SYNC_PODULE_HW_BASE & 0xfff00000, 455 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 456 cpu_tlb_flushD(); 457 /* Now map the EASI space */ 458 459 for (loop = 0; loop < MAX_PODULES; ++loop) { 460 int loop1; 461 462 for (loop1 = loop * EASI_SIZE; loop1 < ((loop + 1) * EASI_SIZE); 463 loop1 += L1_S_SIZE) 464 pmap_map_section((vm_offset_t)pmap_kernel()->pm_pdir, 465 EASI_BASE + loop1, EASI_HW_BASE + loop1, 466 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE); 467 } 468 cpu_tlb_flushD(); 469 #endif 470 /* 471 * The MEDIUM and SLOW simple podules and the module space will have been 472 * mapped when the IOMD and COMBO we mapped in for the RPC 473 */ 474 475 /* Find out what hardware is bolted on */ 476 477 podulescan(self); 478 netslotscan(self); 479 480 /* Look for drivers to attach */ 481 482 for (loop = 0; loop < MAX_PODULES+MAX_NETSLOTS; ++loop) { 483 #if 1 484 /* Provide backwards compat for a while */ 485 sprintf(argstring, "podule%d.disable", loop); 486 if (get_bootconf_option(boot_args, argstring, 487 BOOTOPT_TYPE_BOOLEAN, &value)) { 488 if (value) { 489 if (podules[loop].slottype != SLOT_NONE) 490 printf("podule%d: Disabled\n", loop); 491 continue; 492 } 493 } 494 #endif 495 sprintf(argstring, "podule%d=", loop); 496 if (get_bootconf_option(boot_args, argstring, 497 BOOTOPT_TYPE_HEXINT, &value)) { 498 /* Override the ID */ 499 podules[loop].manufacturer = value >> 16; 500 podules[loop].product = value & 0xffff; 501 /* Any old description is now wrong */ 502 podules[loop].description[0] = 0; 503 if (value != 0xffff) { 504 printf("podule%d: ID overriden man=%04x prod=%04x\n", 505 loop, podules[loop].manufacturer, 506 podules[loop].product); 507 podules[loop].slottype = SLOT_POD; 508 pa.pa_podule_number = loop; 509 pa.pa_ih = pa.pa_podule_number; 510 pa.pa_podule = &podules[loop]; 511 pa.pa_iot = &podulebus_bs_tag; 512 config_found_sm_loc(self, "podulebus", NULL, &pa, 513 podulebusprint, podulebussubmatch); 514 continue; 515 } 516 if (value == 0xffff) { 517 printf("podule%d: Disabled\n", loop); 518 continue; 519 } 520 } 521 522 if (podules[loop].slottype != SLOT_NONE) { 523 pa.pa_podule_number = loop; 524 pa.pa_ih = pa.pa_podule_number; 525 pa.pa_podule = &podules[loop]; 526 pa.pa_iot = &podulebus_bs_tag; 527 config_found_sm_loc(self, "podulebus", NULL, &pa, 528 podulebusprint, podulebussubmatch); 529 } 530 } 531 } 532 533 534 CFATTACH_DECL(podulebus, sizeof(struct device), 535 podulebusmatch, podulebusattach, NULL, NULL); 536 537 /* Useful functions that drivers may share */ 538 539 /* 540 * Match a podule structure with the specified parameters 541 * Returns 0 if the match failed 542 * The required_slot is not used at the moment. 543 */ 544 545 int 546 matchpodule(pa, manufacturer, product, required_slot) 547 struct podule_attach_args *pa; 548 int manufacturer; 549 int product; 550 int required_slot; 551 { 552 if (pa->pa_podule->attached) 553 panic("podulebus: Podule already attached"); 554 555 if (IS_PODULE(pa, manufacturer, product)) 556 return(1); 557 558 return(0); 559 } 560 561 void * 562 podulebus_irq_establish(ih, ipl, func, arg, ev) 563 podulebus_intr_handle_t ih; 564 int ipl; 565 int (*func) __P((void *)); 566 void *arg; 567 struct evcnt *ev; 568 { 569 570 /* XXX We don't actually use the evcnt supplied, just its name. */ 571 return intr_claim(podules[ih].interrupt, ipl, ev->ev_group, func, 572 arg); 573 } 574 575 /* 576 * Generate a bus_space_tag_t with the specified address-bus shift. 577 */ 578 void 579 podulebus_shift_tag(tag, shift, tagp) 580 bus_space_tag_t tag, *tagp; 581 u_int shift; 582 { 583 584 /* 585 * For the podulebus, the bus tag cookie is the shift to apply 586 * to registers, so duplicate the bus space tag and change the 587 * cookie. 588 */ 589 590 /* XXX never freed, but podules are never detached anyway. */ 591 *tagp = malloc(sizeof(struct bus_space), M_DEVBUF, M_WAITOK); 592 **tagp = *tag; 593 (*tagp)->bs_cookie = (void *)shift; 594 } 595 596 int 597 podulebus_initloader(struct podulebus_attach_args *pa) 598 { 599 600 /* No loader support at present on arm32, so always fail. */ 601 return -1; 602 } 603 604 int 605 podloader_readbyte(struct podulebus_attach_args *pa, u_int addr) 606 { 607 608 panic("podloader_readbyte"); 609 } 610 611 void 612 podloader_writebyte(struct podulebus_attach_args *pa, u_int addr, int val) 613 { 614 615 panic("podloader_writebyte"); 616 } 617 618 void 619 podloader_reset(struct podulebus_attach_args *pa) 620 { 621 622 panic("podloader_reset"); 623 } 624 625 int 626 podloader_callloader(struct podulebus_attach_args *pa, u_int r0, u_int r1) 627 { 628 629 panic("podloader_callloader"); 630 } 631 632 /* End of podulebus.c */ 633