Home | History | Annotate | Line # | Download | only in dev
ibm405gp.c revision 1.6
      1  1.6   matt /*	$NetBSD: ibm405gp.c,v 1.6 2011/06/22 18:06:34 matt Exp $	*/
      2  1.1    scw 
      3  1.1    scw /*
      4  1.1    scw  * Copyright 2001 Wasabi Systems, Inc.
      5  1.1    scw  * All rights reserved.
      6  1.1    scw  *
      7  1.1    scw  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8  1.1    scw  *
      9  1.1    scw  * Redistribution and use in source and binary forms, with or without
     10  1.1    scw  * modification, are permitted provided that the following conditions
     11  1.1    scw  * are met:
     12  1.1    scw  * 1. Redistributions of source code must retain the above copyright
     13  1.1    scw  *    notice, this list of conditions and the following disclaimer.
     14  1.1    scw  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1    scw  *    notice, this list of conditions and the following disclaimer in the
     16  1.1    scw  *    documentation and/or other materials provided with the distribution.
     17  1.1    scw  * 3. All advertising materials mentioning features or use of this software
     18  1.1    scw  *    must display the following acknowledgement:
     19  1.1    scw  *      This product includes software developed for the NetBSD Project by
     20  1.1    scw  *      Wasabi Systems, Inc.
     21  1.1    scw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1    scw  *    or promote products derived from this software without specific prior
     23  1.1    scw  *    written permission.
     24  1.1    scw  *
     25  1.1    scw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1    scw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1    scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1    scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1    scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1    scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1    scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1    scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1    scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1    scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1    scw  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1    scw  */
     37  1.2  lukem 
     38  1.2  lukem #include <sys/cdefs.h>
     39  1.6   matt __KERNEL_RCSID(0, "$NetBSD: ibm405gp.c,v 1.6 2011/06/22 18:06:34 matt Exp $");
     40  1.1    scw 
     41  1.1    scw #include <sys/param.h>
     42  1.1    scw #include <sys/device.h>
     43  1.1    scw #include <sys/systm.h>
     44  1.3    scw #include <sys/extent.h>
     45  1.5   matt #include <sys/bus.h>
     46  1.1    scw 
     47  1.1    scw #include <dev/pci/pcivar.h>
     48  1.1    scw 
     49  1.1    scw #include <powerpc/ibm4xx/ibm405gp.h>
     50  1.6   matt #include <powerpc/ibm4xx/pci_machdep.h>
     51  1.1    scw #include <powerpc/ibm4xx/dev/pcicreg.h>
     52  1.1    scw 
     53  1.3    scw static struct powerpc_bus_space pcicfg_tag = {
     54  1.3    scw 	_BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
     55  1.3    scw 	IBM405GP_PCIL0_BASE, 0x0, 0x40
     56  1.3    scw };
     57  1.3    scw static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(1)]
     58  1.3    scw     __attribute__((aligned(8)));
     59  1.3    scw static bus_space_tag_t pcicfg_iot = &pcicfg_tag;
     60  1.1    scw static bus_space_handle_t pcicfg_ioh = 0;
     61  1.1    scw 
     62  1.1    scw #define PCI0_MEM_BASE	0x80000000
     63  1.1    scw 
     64  1.6   matt static struct genppc_pci_chipset genppc_ibm4xx_chipset = {
     65  1.6   matt 	.pc_conf_v =		NULL,
     66  1.6   matt 	.pc_attach_hook =	ibm4xx_pci_attach_hook,
     67  1.6   matt 	.pc_bus_maxdevs =	ibm4xx_pci_bus_maxdevs,
     68  1.6   matt 	.pc_make_tag =		ibm4xx_pci_make_tag,
     69  1.6   matt 	.pc_conf_read =		ibm4xx_pci_conf_read,
     70  1.6   matt 	.pc_conf_write =	ibm4xx_pci_conf_write,
     71  1.6   matt 
     72  1.6   matt 	.pc_intr_v =		&genppc_ibm4xx_chipset,
     73  1.6   matt 	.pc_intr_map =		genppc_pci_intr_map,
     74  1.6   matt 	.pc_intr_string =	genppc_pci_intr_string,
     75  1.6   matt 	.pc_intr_evcnt =	genppc_pci_intr_evcnt,
     76  1.6   matt 	.pc_intr_establish =	genppc_pci_intr_establish,
     77  1.6   matt 	.pc_intr_disestablish =	genppc_pci_intr_disestablish,
     78  1.6   matt 	.pc_intr_setattr =	ibm4xx_pci_intr_setattr,
     79  1.6   matt 
     80  1.6   matt 	.pc_conf_interrupt =	ibm4xx_pci_conf_interrupt,
     81  1.6   matt 	.pc_decompose_tag =	ibm4xx_pci_decompose_tag,
     82  1.6   matt 	.pc_conf_hook =		ibm4xx_pci_conf_hook,
     83  1.6   matt };
     84  1.6   matt 
     85  1.6   matt pci_chipset_tag_t
     86  1.6   matt ibm4xx_get_pci_chipset_tag(void)
     87  1.6   matt {
     88  1.6   matt 	return &genppc_ibm4xx_chipset;
     89  1.6   matt }
     90  1.6   matt 
     91  1.6   matt static void
     92  1.6   matt setup_pcicfg_window(void)
     93  1.1    scw {
     94  1.1    scw 	if (pcicfg_ioh)
     95  1.1    scw 		return;
     96  1.3    scw 	if (bus_space_init(&pcicfg_tag,
     97  1.3    scw 	    "pcicfg", ex_storage, sizeof(ex_storage)) ||
     98  1.3    scw 	    bus_space_map(pcicfg_iot, 0, 0x40 , 0, &pcicfg_ioh))
     99  1.1    scw 		panic("Cannot map PCI configuration registers");
    100  1.1    scw }
    101  1.1    scw 
    102  1.1    scw /*
    103  1.1    scw  * Setup proper Local<->PCI mapping
    104  1.1    scw  * PCI memory window: 256M @ PCI0MEMBASE with direct memory translation
    105  1.1    scw  */
    106  1.6   matt void
    107  1.6   matt ibm4xx_setup_pci(void)
    108  1.1    scw {
    109  1.6   matt 	pci_chipset_tag_t pc = &genppc_ibm4xx_chipset;
    110  1.1    scw 	pcitag_t tag;
    111  1.1    scw 
    112  1.1    scw 	setup_pcicfg_window();
    113  1.1    scw 
    114  1.1    scw 	/* Disable all three memory mappers */
    115  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0MA, 0x00000000); /* disabled */
    116  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1MA, 0x00000000); /* disabled */
    117  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2MA, 0x00000000); /* disabled */
    118  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1MS, 0x00000000); /* Can't really disable PTM1. */
    119  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM2MS, 0x00000000); /* disabled */
    120  1.1    scw 
    121  1.1    scw 
    122  1.1    scw 	/* Setup memory map #0 */
    123  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0MA, 0xF0000001); /* 256M non-prefetchable, enabled */
    124  1.1    scw 
    125  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0LA, PCI0_MEM_BASE);
    126  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0PCILA, PCI0_MEM_BASE);
    127  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0PCIHA, 0);
    128  1.1    scw 
    129  1.1    scw 	/* Configure PCI bridge */
    130  1.6   matt 	tag = pci_make_tag(pc, 0, 0, 0);
    131  1.6   matt 	// x = pci_conf_read(pc, tag, PCI0_CMD);		/* Read PCI command register */
    132  1.6   matt 	// pci_conf_write(pc, tag, PCI0_CMD, x | MA | ME);	/* enable bus mastering and memory space */
    133  1.1    scw 
    134  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1MS, 0xF0000001);	/* Enable PTM1 */
    135  1.1    scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1LA, 0);
    136  1.6   matt 	pci_conf_write(pc, tag, PCIC_PTM1BAR, 0);	/* Set up proper PCI->Local address base.  Always enabled */
    137  1.6   matt 	pci_conf_write(pc, tag, PCIC_PTM2BAR, 0);
    138  1.1    scw }
    139  1.1    scw 
    140  1.6   matt void
    141  1.6   matt ibm4xx_show_pci_map(void)
    142  1.1    scw {
    143  1.6   matt 	pci_chipset_tag_t pc = &genppc_ibm4xx_chipset;
    144  1.1    scw 	paddr_t la, lm, pl, ph;
    145  1.1    scw 	pcitag_t tag;
    146  1.1    scw 
    147  1.1    scw 	setup_pcicfg_window();
    148  1.1    scw 
    149  1.1    scw 	printf("Local -> PCI map\n");
    150  1.1    scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0LA);
    151  1.1    scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0MA);
    152  1.1    scw 	pl = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0PCILA);
    153  1.1    scw 	ph = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0PCIHA);
    154  1.1    scw 	printf("0: %08lx,%08lx -> %08lx%08lx %sprefetchable, %s\n", la, lm, ph, pl,
    155  1.1    scw 	    (lm & 2) ? "":"not ",
    156  1.1    scw 	    (lm & 1) ? "enabled":"disabled");
    157  1.1    scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1LA);
    158  1.1    scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1MA);
    159  1.1    scw 	pl = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1PCILA);
    160  1.1    scw 	ph = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1PCIHA);
    161  1.1    scw 	printf("1: %08lx,%08lx -> %08lx%08lx %sprefetchable, %s\n", la, lm, ph, pl,
    162  1.1    scw 	    (lm & 2) ? "":"not ",
    163  1.1    scw 	    (lm & 1) ? "enabled":"disabled");
    164  1.1    scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2LA);
    165  1.1    scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2MA);
    166  1.1    scw 	pl = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2PCILA);
    167  1.1    scw 	ph = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2PCIHA);
    168  1.1    scw 	printf("2: %08lx,%08lx -> %08lx%08lx %sprefetchable, %s\n", la, lm, ph, pl,
    169  1.1    scw 	    (lm & 2) ? "":"not ",
    170  1.1    scw 	    (lm & 1) ? "enabled":"disabled");
    171  1.1    scw 	printf("PCI -> Local map\n");
    172  1.1    scw 
    173  1.6   matt 	tag = pci_make_tag(pc, 0, 0, 0);
    174  1.6   matt 	pl = pci_conf_read(pc, tag, PCIC_PTM1BAR);
    175  1.1    scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1LA);
    176  1.1    scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1MS);
    177  1.1    scw 	printf("1: %08lx -> %08lx,%08lx %s\n", pl, la, lm,
    178  1.1    scw 	    (lm & 1)?"enabled":"disabled");
    179  1.6   matt 	pl = pci_conf_read(pc, tag, PCIC_PTM2BAR);
    180  1.1    scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM2LA);
    181  1.1    scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM2MS);
    182  1.1    scw 	printf("2: %08lx -> %08lx,%08lx %s\n", pl, la, lm,
    183  1.1    scw 	    (lm & 1)?"enabled":"disabled");
    184  1.1    scw }
    185