Home | History | Annotate | Line # | Download | only in dev
ibm405gp.c revision 1.1
      1  1.1  scw /*	$NetBSD: ibm405gp.c,v 1.1 2002/12/09 12:28:12 scw 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.1  scw 
     38  1.1  scw #include <sys/param.h>
     39  1.1  scw #include <sys/device.h>
     40  1.1  scw #include <sys/systm.h>
     41  1.1  scw 
     42  1.1  scw #include <machine/bus.h>
     43  1.1  scw #include <dev/pci/pcivar.h>
     44  1.1  scw 
     45  1.1  scw #include <powerpc/ibm4xx/ibm405gp.h>
     46  1.1  scw #include <powerpc/ibm4xx/dev/pcicreg.h>
     47  1.1  scw 
     48  1.1  scw static bus_space_tag_t	pcicfg_iot = ibm4xx_make_bus_space_tag(0, 0);
     49  1.1  scw static bus_space_handle_t pcicfg_ioh = 0;
     50  1.1  scw 
     51  1.1  scw #define PCI0_MEM_BASE	0x80000000
     52  1.1  scw 
     53  1.1  scw static void setup_pcicfg_window(void)
     54  1.1  scw {
     55  1.1  scw 	if (pcicfg_ioh)
     56  1.1  scw 		return;
     57  1.1  scw 	if (bus_space_map(pcicfg_iot, IBM405GP_PCIL0_BASE, 0x40 , 0, &pcicfg_ioh))
     58  1.1  scw 		panic("Cannot map PCI configuration registers");
     59  1.1  scw }
     60  1.1  scw 
     61  1.1  scw /*
     62  1.1  scw  * Setup proper Local<->PCI mapping
     63  1.1  scw  * PCI memory window: 256M @ PCI0MEMBASE with direct memory translation
     64  1.1  scw  */
     65  1.1  scw void ibm4xx_setup_pci(void)
     66  1.1  scw {
     67  1.1  scw 	pcitag_t tag;
     68  1.1  scw 
     69  1.1  scw 	setup_pcicfg_window();
     70  1.1  scw 
     71  1.1  scw 	/* Disable all three memory mappers */
     72  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0MA, 0x00000000); /* disabled */
     73  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1MA, 0x00000000); /* disabled */
     74  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2MA, 0x00000000); /* disabled */
     75  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1MS, 0x00000000); /* Can't really disable PTM1. */
     76  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM2MS, 0x00000000); /* disabled */
     77  1.1  scw 
     78  1.1  scw 
     79  1.1  scw 	/* Setup memory map #0 */
     80  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0MA, 0xF0000001); /* 256M non-prefetchable, enabled */
     81  1.1  scw 
     82  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0LA, PCI0_MEM_BASE);
     83  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0PCILA, PCI0_MEM_BASE);
     84  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0PCIHA, 0);
     85  1.1  scw 
     86  1.1  scw 	/* Configure PCI bridge */
     87  1.1  scw 	tag = pci_make_tag(0, 0, 0, 0);
     88  1.1  scw 	// x = pci_conf_read(0, tag, PCI0_CMD);		/* Read PCI command register */
     89  1.1  scw 	// pci_conf_write(0, tag, PCI0_CMD, x | MA | ME);	/* enable bus mastering and memory space */
     90  1.1  scw 
     91  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1MS, 0xF0000001);	/* Enable PTM1 */
     92  1.1  scw 	bus_space_write_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1LA, 0);
     93  1.1  scw 	pci_conf_write(0, tag, PCIC_PTM1BAR, 0);	/* Set up proper PCI->Local address base.  Always enabled */
     94  1.1  scw 	pci_conf_write(0, tag, PCIC_PTM2BAR, 0);
     95  1.1  scw }
     96  1.1  scw 
     97  1.1  scw void ibm4xx_show_pci_map(void)
     98  1.1  scw {
     99  1.1  scw 	paddr_t la, lm, pl, ph;
    100  1.1  scw 	pcitag_t tag;
    101  1.1  scw 
    102  1.1  scw 	setup_pcicfg_window();
    103  1.1  scw 
    104  1.1  scw 	printf("Local -> PCI map\n");
    105  1.1  scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0LA);
    106  1.1  scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0MA);
    107  1.1  scw 	pl = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0PCILA);
    108  1.1  scw 	ph = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM0PCIHA);
    109  1.1  scw 	printf("0: %08lx,%08lx -> %08lx%08lx %sprefetchable, %s\n", la, lm, ph, pl,
    110  1.1  scw 	    (lm & 2) ? "":"not ",
    111  1.1  scw 	    (lm & 1) ? "enabled":"disabled");
    112  1.1  scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1LA);
    113  1.1  scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1MA);
    114  1.1  scw 	pl = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1PCILA);
    115  1.1  scw 	ph = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM1PCIHA);
    116  1.1  scw 	printf("1: %08lx,%08lx -> %08lx%08lx %sprefetchable, %s\n", la, lm, ph, pl,
    117  1.1  scw 	    (lm & 2) ? "":"not ",
    118  1.1  scw 	    (lm & 1) ? "enabled":"disabled");
    119  1.1  scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2LA);
    120  1.1  scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2MA);
    121  1.1  scw 	pl = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2PCILA);
    122  1.1  scw 	ph = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PMM2PCIHA);
    123  1.1  scw 	printf("2: %08lx,%08lx -> %08lx%08lx %sprefetchable, %s\n", la, lm, ph, pl,
    124  1.1  scw 	    (lm & 2) ? "":"not ",
    125  1.1  scw 	    (lm & 1) ? "enabled":"disabled");
    126  1.1  scw 	printf("PCI -> Local map\n");
    127  1.1  scw 
    128  1.1  scw 	tag = pci_make_tag(0, 0, 0, 0);
    129  1.1  scw 	pl = pci_conf_read(0, tag, PCIC_PTM1BAR);
    130  1.1  scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1LA);
    131  1.1  scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM1MS);
    132  1.1  scw 	printf("1: %08lx -> %08lx,%08lx %s\n", pl, la, lm,
    133  1.1  scw 	    (lm & 1)?"enabled":"disabled");
    134  1.1  scw 	pl = pci_conf_read(0, tag, PCIC_PTM2BAR);
    135  1.1  scw 	la = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM2LA);
    136  1.1  scw 	lm = bus_space_read_4(pcicfg_iot, pcicfg_ioh, PCIL_PTM2MS);
    137  1.1  scw 	printf("2: %08lx -> %08lx,%08lx %s\n", pl, la, lm,
    138  1.1  scw 	    (lm & 1)?"enabled":"disabled");
    139  1.1  scw }
    140