psycho.c (108470) | psycho.c (108800) |
---|---|
1/* 2 * Copyright (c) 1999, 2000 Matthew R. Green 3 * All rights reserved. 4 * Copyright 2001 by Thomas Moestl <tmm@FreeBSD.org>. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * from: NetBSD: psycho.c,v 1.39 2001/10/07 20:30:41 eeh Exp 30 * | 1/* 2 * Copyright (c) 1999, 2000 Matthew R. Green 3 * All rights reserved. 4 * Copyright 2001 by Thomas Moestl <tmm@FreeBSD.org>. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * from: NetBSD: psycho.c,v 1.39 2001/10/07 20:30:41 eeh Exp 30 * |
31 * $FreeBSD: head/sys/sparc64/pci/psycho.c 108470 2002-12-30 21:18:15Z schweikh $ | 31 * $FreeBSD: head/sys/sparc64/pci/psycho.c 108800 2003-01-06 16:51:06Z tmm $ |
32 */ 33 34/* 35 * Support for `psycho' and `psycho+' UPA to PCI bridge and 36 * UltraSPARC IIi and IIe `sabre' PCI controllers. 37 */ 38 39#include "opt_psycho.h" --- 315 unchanged lines hidden (view full) --- 355 sc->sc_mode = desc->pd_mode; 356 357 /* 358 * The psycho gets three register banks: 359 * (0) per-PBM configuration and status registers 360 * (1) per-PBM PCI configuration space, containing only the 361 * PBM 256-byte PCI header 362 * (2) the shared psycho configuration registers (struct psychoreg) | 32 */ 33 34/* 35 * Support for `psycho' and `psycho+' UPA to PCI bridge and 36 * UltraSPARC IIi and IIe `sabre' PCI controllers. 37 */ 38 39#include "opt_psycho.h" --- 315 unchanged lines hidden (view full) --- 355 sc->sc_mode = desc->pd_mode; 356 357 /* 358 * The psycho gets three register banks: 359 * (0) per-PBM configuration and status registers 360 * (1) per-PBM PCI configuration space, containing only the 361 * PBM 256-byte PCI header 362 * (2) the shared psycho configuration registers (struct psychoreg) |
363 * 364 * XXX use the prom address for the psycho registers? we do so far. | |
365 */ 366 reg = nexus_get_reg(dev); 367 nreg = nexus_get_nreg(dev); 368 /* Register layouts are different. stuupid. */ 369 if (sc->sc_mode == PSYCHO_MODE_PSYCHO) { 370 if (nreg <= 2) 371 panic("psycho_attach: %d not enough registers", nreg); 372 sc->sc_basepaddr = (vm_offset_t)UPA_REG_PHYS(®[2]); --- 42 unchanged lines hidden (view full) --- 415 if (pcictl_offs < sc->sc_basepaddr) 416 panic("psycho_attach: bogus pci control register location"); 417 sc->sc_pcictl = pcictl_offs - sc->sc_basepaddr; 418 csr = PSYCHO_READ8(sc, PSR_CS); 419 sc->sc_ign = 0x7c0; /* APB IGN is always 0x7c */ 420 if (sc->sc_mode == PSYCHO_MODE_PSYCHO) 421 sc->sc_ign = PSYCHO_GCSR_IGN(csr) << 6; 422 | 363 */ 364 reg = nexus_get_reg(dev); 365 nreg = nexus_get_nreg(dev); 366 /* Register layouts are different. stuupid. */ 367 if (sc->sc_mode == PSYCHO_MODE_PSYCHO) { 368 if (nreg <= 2) 369 panic("psycho_attach: %d not enough registers", nreg); 370 sc->sc_basepaddr = (vm_offset_t)UPA_REG_PHYS(®[2]); --- 42 unchanged lines hidden (view full) --- 413 if (pcictl_offs < sc->sc_basepaddr) 414 panic("psycho_attach: bogus pci control register location"); 415 sc->sc_pcictl = pcictl_offs - sc->sc_basepaddr; 416 csr = PSYCHO_READ8(sc, PSR_CS); 417 sc->sc_ign = 0x7c0; /* APB IGN is always 0x7c */ 418 if (sc->sc_mode == PSYCHO_MODE_PSYCHO) 419 sc->sc_ign = PSYCHO_GCSR_IGN(csr) << 6; 420 |
423 device_printf(dev, "%s, impl %d, version %d, ign %x ", | 421 device_printf(dev, "%s, impl %d, version %d, ign %#x\n", |
424 desc->pd_name, (int)PSYCHO_GCSR_IMPL(csr), 425 (int)PSYCHO_GCSR_VERS(csr), sc->sc_ign); 426 427 /* 428 * Setup the PCI control register 429 */ 430 csr = PCICTL_READ8(sc, PCR_CS); 431 csr |= PCICTL_MRLM | PCICTL_ARB_PARK | PCICTL_ERRINTEN | PCICTL_4ENABLE; 432 csr &= ~(PCICTL_SERR | PCICTL_CPU_PRIO | PCICTL_ARB_PRIO | 433 PCICTL_RTRYWAIT); 434 PCICTL_WRITE8(sc, PCR_CS, csr); 435 | 422 desc->pd_name, (int)PSYCHO_GCSR_IMPL(csr), 423 (int)PSYCHO_GCSR_VERS(csr), sc->sc_ign); 424 425 /* 426 * Setup the PCI control register 427 */ 428 csr = PCICTL_READ8(sc, PCR_CS); 429 csr |= PCICTL_MRLM | PCICTL_ARB_PARK | PCICTL_ERRINTEN | PCICTL_4ENABLE; 430 csr &= ~(PCICTL_SERR | PCICTL_CPU_PRIO | PCICTL_ARB_PRIO | 431 PCICTL_RTRYWAIT); 432 PCICTL_WRITE8(sc, PCR_CS, csr); 433 |
434 if (sc->sc_mode == PSYCHO_MODE_SABRE) { 435 /* 436 * Use the PROM preset for now. 437 */ 438 csr = PCICTL_READ8(sc, PCR_TAS); 439 if (csr == 0) 440 panic("psycho_attach: sabre TAS not initialized."); 441 sc->sc_dvmabase = (ffs(csr) - 1) << PCITAS_ADDR_SHIFT; 442 } else 443 sc->sc_dvmabase = -1; 444 |
|
436 /* Grab the psycho ranges */ 437 psycho_get_ranges(sc->sc_node, &sc->sc_range, &sc->sc_nrange); 438 439 /* Initialize memory and i/o rmans */ 440 sc->sc_io_rman.rm_type = RMAN_ARRAY; 441 sc->sc_io_rman.rm_descr = "Psycho PCI I/O Ports"; 442 if (rman_init(&sc->sc_io_rman) != 0 || 443 rman_manage_region(&sc->sc_io_rman, 0, PSYCHO_IO_SIZE) != 0) --- 293 unchanged lines hidden (view full) --- 737 * On the UltraSPARC-IIi/IIe, IOMMU misses/protection faults cause 738 * the AFAR to be set to the physical address of the TTE entry that 739 * was invalid/write protected. Call into the iommu code to have 740 * them decoded to virtual IO addresses. 741 */ 742 if ((afsr & UEAFSR_P_DTE) != 0) 743 iommu_decode_fault(sc->sc_is, afar); 744 /* It's uncorrectable. Dump the regs and panic. */ | 445 /* Grab the psycho ranges */ 446 psycho_get_ranges(sc->sc_node, &sc->sc_range, &sc->sc_nrange); 447 448 /* Initialize memory and i/o rmans */ 449 sc->sc_io_rman.rm_type = RMAN_ARRAY; 450 sc->sc_io_rman.rm_descr = "Psycho PCI I/O Ports"; 451 if (rman_init(&sc->sc_io_rman) != 0 || 452 rman_manage_region(&sc->sc_io_rman, 0, PSYCHO_IO_SIZE) != 0) --- 293 unchanged lines hidden (view full) --- 746 * On the UltraSPARC-IIi/IIe, IOMMU misses/protection faults cause 747 * the AFAR to be set to the physical address of the TTE entry that 748 * was invalid/write protected. Call into the iommu code to have 749 * them decoded to virtual IO addresses. 750 */ 751 if ((afsr & UEAFSR_P_DTE) != 0) 752 iommu_decode_fault(sc->sc_is, afar); 753 /* It's uncorrectable. Dump the regs and panic. */ |
745 panic("%s: uncorrectable DMA error AFAR %#lx AFSR %#lx\n", | 754 panic("%s: uncorrectable DMA error AFAR %#lx AFSR %#lx", |
746 device_get_name(sc->sc_dev), (u_long)afar, (u_long)afsr); 747} 748 749static void 750psycho_ce(void *arg) 751{ 752 struct psycho_softc *sc = (struct psycho_softc *)arg; 753 u_int64_t afar, afsr; --- 10 unchanged lines hidden (view full) --- 764psycho_bus_a(void *arg) 765{ 766 struct psycho_softc *sc = (struct psycho_softc *)arg; 767 u_int64_t afar, afsr; 768 769 afar = PSYCHO_READ8(sc, PSR_PCICTL0 + PCR_AFA); 770 afsr = PSYCHO_READ8(sc, PSR_PCICTL0 + PCR_AFS); 771 /* It's uncorrectable. Dump the regs and panic. */ | 755 device_get_name(sc->sc_dev), (u_long)afar, (u_long)afsr); 756} 757 758static void 759psycho_ce(void *arg) 760{ 761 struct psycho_softc *sc = (struct psycho_softc *)arg; 762 u_int64_t afar, afsr; --- 10 unchanged lines hidden (view full) --- 773psycho_bus_a(void *arg) 774{ 775 struct psycho_softc *sc = (struct psycho_softc *)arg; 776 u_int64_t afar, afsr; 777 778 afar = PSYCHO_READ8(sc, PSR_PCICTL0 + PCR_AFA); 779 afsr = PSYCHO_READ8(sc, PSR_PCICTL0 + PCR_AFS); 780 /* It's uncorrectable. Dump the regs and panic. */ |
772 panic("%s: PCI bus A error AFAR %#lx AFSR %#lx\n", | 781 panic("%s: PCI bus A error AFAR %#lx AFSR %#lx", |
773 device_get_name(sc->sc_dev), (u_long)afar, (u_long)afsr); 774} 775 776static void 777psycho_bus_b(void *arg) 778{ 779 struct psycho_softc *sc = (struct psycho_softc *)arg; 780 u_int64_t afar, afsr; 781 782 afar = PSYCHO_READ8(sc, PSR_PCICTL1 + PCR_AFA); 783 afsr = PSYCHO_READ8(sc, PSR_PCICTL1 + PCR_AFS); 784 /* It's uncorrectable. Dump the regs and panic. */ | 782 device_get_name(sc->sc_dev), (u_long)afar, (u_long)afsr); 783} 784 785static void 786psycho_bus_b(void *arg) 787{ 788 struct psycho_softc *sc = (struct psycho_softc *)arg; 789 u_int64_t afar, afsr; 790 791 afar = PSYCHO_READ8(sc, PSR_PCICTL1 + PCR_AFA); 792 afsr = PSYCHO_READ8(sc, PSR_PCICTL1 + PCR_AFS); 793 /* It's uncorrectable. Dump the regs and panic. */ |
785 panic("%s: PCI bus B error AFAR %#lx AFSR %#lx\n", | 794 panic("%s: PCI bus B error AFAR %#lx AFSR %#lx", |
786 device_get_name(sc->sc_dev), (u_long)afar, (u_long)afsr); 787} 788 789static void 790psycho_powerfail(void *arg) 791{ 792 793 /* We lost power. Try to shut down NOW. */ --- 21 unchanged lines hidden (view full) --- 815#endif /* PSYCHO_MAP_WAKEUP */ 816 817/* initialise the IOMMU... */ 818void 819psycho_iommu_init(struct psycho_softc *sc, int tsbsize) 820{ 821 char *name; 822 struct iommu_state *is = sc->sc_is; | 795 device_get_name(sc->sc_dev), (u_long)afar, (u_long)afsr); 796} 797 798static void 799psycho_powerfail(void *arg) 800{ 801 802 /* We lost power. Try to shut down NOW. */ --- 21 unchanged lines hidden (view full) --- 824#endif /* PSYCHO_MAP_WAKEUP */ 825 826/* initialise the IOMMU... */ 827void 828psycho_iommu_init(struct psycho_softc *sc, int tsbsize) 829{ 830 char *name; 831 struct iommu_state *is = sc->sc_is; |
823 u_int32_t iobase = -1; 824 int *vdma = NULL; 825 int nitem; | |
826 827 /* punch in our copies */ 828 is->is_bustag = sc->sc_bustag; 829 is->is_bushandle = sc->sc_bushandle; 830 is->is_iommu = PSR_IOMMU; 831 is->is_dtag = PSR_IOMMU_TLB_TAG_DIAG; 832 is->is_ddram = PSR_IOMMU_TLB_DATA_DIAG; 833 is->is_dqueue = PSR_IOMMU_QUEUE_DIAG; 834 is->is_dva = PSR_IOMMU_SVADIAG; 835 is->is_dtcmp = PSR_IOMMU_TLB_CMP_DIAG; 836 | 832 833 /* punch in our copies */ 834 is->is_bustag = sc->sc_bustag; 835 is->is_bushandle = sc->sc_bushandle; 836 is->is_iommu = PSR_IOMMU; 837 is->is_dtag = PSR_IOMMU_TLB_TAG_DIAG; 838 is->is_ddram = PSR_IOMMU_TLB_DATA_DIAG; 839 is->is_dqueue = PSR_IOMMU_QUEUE_DIAG; 840 is->is_dva = PSR_IOMMU_SVADIAG; 841 is->is_dtcmp = PSR_IOMMU_TLB_CMP_DIAG; 842 |
837 /* 838 * Separate the men from the boys. Get the `virtual-dma' 839 * property for sabre and use that to make sure the damn 840 * iommu works. 841 * 842 * We could query the `#virtual-dma-size-cells' and 843 * `#virtual-dma-addr-cells' and DTRT, but I'm lazy. 844 */ 845 nitem = OF_getprop_alloc(sc->sc_node, "virtual-dma", sizeof(vdma), 846 (void **)&vdma); 847 if (nitem > 0) { 848 iobase = vdma[0]; 849 tsbsize = ffs(vdma[1]); 850 if (tsbsize < 25 || tsbsize > 31 || 851 (vdma[1] & ~(1 << (tsbsize - 1))) != 0) { 852 printf("bogus tsb size %x, using 7\n", vdma[1]); 853 tsbsize = 31; 854 } 855 tsbsize -= 24; 856 free(vdma, M_OFWPROP); 857 } 858 | |
859 /* give us a nice name.. */ 860 name = (char *)malloc(32, M_DEVBUF, M_NOWAIT); 861 if (name == 0) 862 panic("couldn't malloc iommu name"); 863 snprintf(name, 32, "%s dvma", device_get_name(sc->sc_dev)); 864 | 843 /* give us a nice name.. */ 844 name = (char *)malloc(32, M_DEVBUF, M_NOWAIT); 845 if (name == 0) 846 panic("couldn't malloc iommu name"); 847 snprintf(name, 32, "%s dvma", device_get_name(sc->sc_dev)); 848 |
865 iommu_init(name, is, tsbsize, iobase, 0); | 849 iommu_init(name, is, tsbsize, sc->sc_dvmabase, 0); |
866} 867 868static void 869psycho_binit(device_t busdev, struct ofw_pci_bdesc *obd) 870{ 871 872#ifdef PSYCHO_DEBUG 873 printf("psycho at %u/%u/%u: setting bus #s to %u/%u/%u\n", --- 311 unchanged lines hidden (view full) --- 1185 case SYS_RES_MEMORY: 1186 rm = &sc->sc_mem_rman; 1187 bt = sc->sc_memt; 1188 bh = sc->sc_bh[PCI_CS_MEM32]; 1189 break; 1190 case SYS_RES_IOPORT: 1191 rm = &sc->sc_io_rman; 1192 bt = sc->sc_iot; | 850} 851 852static void 853psycho_binit(device_t busdev, struct ofw_pci_bdesc *obd) 854{ 855 856#ifdef PSYCHO_DEBUG 857 printf("psycho at %u/%u/%u: setting bus #s to %u/%u/%u\n", --- 311 unchanged lines hidden (view full) --- 1169 case SYS_RES_MEMORY: 1170 rm = &sc->sc_mem_rman; 1171 bt = sc->sc_memt; 1172 bh = sc->sc_bh[PCI_CS_MEM32]; 1173 break; 1174 case SYS_RES_IOPORT: 1175 rm = &sc->sc_io_rman; 1176 bt = sc->sc_iot; |
1193 /* XXX: probably should use ranges property here. */ | |
1194 bh = sc->sc_bh[PCI_CS_IO]; 1195 break; 1196 default: 1197 return (NULL); 1198 } 1199 1200 rv = rman_reserve_resource(rm, start, end, count, flags, child); 1201 if (rv == NULL) --- 197 unchanged lines hidden --- | 1177 bh = sc->sc_bh[PCI_CS_IO]; 1178 break; 1179 default: 1180 return (NULL); 1181 } 1182 1183 rv = rman_reserve_resource(rm, start, end, count, flags, child); 1184 if (rv == NULL) --- 197 unchanged lines hidden --- |