Home | History | Annotate | Line # | Download | only in boot
io.c revision 1.3
      1  1.3  garbled /*	$NetBSD: io.c,v 1.3 2006/04/13 18:46:46 garbled Exp $	*/
      2  1.1   nonaka 
      3  1.1   nonaka /*-
      4  1.1   nonaka  * Copyright (C) 1995-1997 Gary Thomas (gdt (at) linuxppc.org)
      5  1.1   nonaka  * All rights reserved.
      6  1.1   nonaka  *
      7  1.1   nonaka  * PCI/ISA I/O support
      8  1.1   nonaka  *
      9  1.1   nonaka  * Redistribution and use in source and binary forms, with or without
     10  1.1   nonaka  * modification, are permitted provided that the following conditions
     11  1.1   nonaka  * are met:
     12  1.1   nonaka  * 1. Redistributions of source code must retain the above copyright
     13  1.1   nonaka  *    notice, this list of conditions and the following disclaimer.
     14  1.1   nonaka  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1   nonaka  *    notice, this list of conditions and the following disclaimer in the
     16  1.1   nonaka  *    documentation and/or other materials provided with the distribution.
     17  1.1   nonaka  * 3. All advertising materials mentioning features or use of this software
     18  1.1   nonaka  *    must display the following acknowledgement:
     19  1.1   nonaka  *      This product includes software developed by Gary Thomas.
     20  1.1   nonaka  * 4. The name of the author may not be used to endorse or promote products
     21  1.1   nonaka  *    derived from this software without specific prior written permission.
     22  1.1   nonaka  *
     23  1.1   nonaka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  1.1   nonaka  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  1.1   nonaka  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  1.1   nonaka  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  1.1   nonaka  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  1.1   nonaka  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  1.1   nonaka  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  1.1   nonaka  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  1.1   nonaka  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  1.1   nonaka  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  1.1   nonaka  */
     34  1.1   nonaka 
     35  1.1   nonaka #include <lib/libsa/stand.h>
     36  1.3  garbled #include <sys/bswap.h>
     37  1.1   nonaka #include "boot.h"
     38  1.1   nonaka 
     39  1.3  garbled #define PCI_NSLOTS	8
     40  1.3  garbled #define PCI_NREGS	5
     41  1.3  garbled #define PCI_DEVID	0
     42  1.3  garbled #define PCI_CMD		1
     43  1.3  garbled #define PCI_CLASS	2
     44  1.3  garbled #define PCI_MEMBASE	4
     45  1.3  garbled 
     46  1.3  garbled 
     47  1.1   nonaka volatile u_char *ISA_io  = (u_char *)0x80000000;
     48  1.3  garbled volatile u_char *ISA_mem = (u_char *)0xc0000000;
     49  1.3  garbled volatile char *videomem = (char *)0xc00b8000; /* + vram offset */
     50  1.3  garbled 
     51  1.3  garbled struct PCI_cinfo {
     52  1.3  garbled 	u_long *config_addr;
     53  1.3  garbled 	u_long regs[PCI_NREGS];
     54  1.3  garbled } PCI_slots[PCI_NSLOTS] = {
     55  1.3  garbled 	{ (u_long *)0x80808000, {0xDEADBEEF,} },
     56  1.3  garbled 	{ (u_long *)0x80800800, {0xDEADBEEF,} },
     57  1.3  garbled 	{ (u_long *)0x80801000, {0xDEADBEEF,} },
     58  1.3  garbled 	{ (u_long *)0x80802000, {0xDEADBEEF,} },
     59  1.3  garbled 	{ (u_long *)0x80804000, {0xDEADBEEF,} },
     60  1.3  garbled 	{ (u_long *)0x80810000, {0xDEADBEEF,} },
     61  1.3  garbled 	{ (u_long *)0x80820000, {0xDEADBEEF,} },
     62  1.3  garbled 	{ (u_long *)0x80840000, {0xDEADBEEF,} },
     63  1.3  garbled };
     64  1.1   nonaka 
     65  1.1   nonaka void
     66  1.2  garbled outb(int port, char val)
     67  1.1   nonaka {
     68  1.1   nonaka 
     69  1.1   nonaka 	ISA_io[port] = val;
     70  1.1   nonaka }
     71  1.1   nonaka 
     72  1.3  garbled inline void
     73  1.3  garbled outw(int port, u_int16_t val)
     74  1.3  garbled {
     75  1.3  garbled         outb(port, val>>8);
     76  1.3  garbled         outb(port+1, val);
     77  1.3  garbled }
     78  1.3  garbled 
     79  1.1   nonaka u_char
     80  1.2  garbled inb(int port)
     81  1.1   nonaka {
     82  1.1   nonaka 
     83  1.1   nonaka 	return (ISA_io[port]);
     84  1.1   nonaka }
     85  1.1   nonaka 
     86  1.1   nonaka u_long
     87  1.2  garbled local_to_PCI(u_long addr)
     88  1.1   nonaka {
     89  1.1   nonaka 
     90  1.1   nonaka 	return ((addr & 0x7FFFFFFF) | 0x80000000);
     91  1.1   nonaka }
     92  1.3  garbled 
     93  1.3  garbled void
     94  1.3  garbled unlockVideo(int slot)
     95  1.3  garbled {
     96  1.3  garbled 	volatile u_int8_t *ppci;
     97  1.3  garbled 
     98  1.3  garbled 	ppci = (u_int8_t *)PCI_slots[slot].config_addr;
     99  1.3  garbled 	ppci[4] = 0x0003;	/* enable memory and IO Access */
    100  1.3  garbled 	ppci[0x10] = 0x00000;	/* Turn off memory mapping */
    101  1.3  garbled 	ppci[0x11] = 0x00000;	/* mem base = 0 */
    102  1.3  garbled 	ppci[0x12] = 0x00000;
    103  1.3  garbled 	ppci[0x13] = 0x00000;
    104  1.3  garbled 	__asm__ volatile("eieio");
    105  1.3  garbled 
    106  1.3  garbled 	outb(0x3d4, 0x11);
    107  1.3  garbled 	outb(0x3d5, 0x0e);   /* unlock CR0-CR7 */
    108  1.3  garbled }
    109  1.3  garbled 
    110  1.3  garbled int
    111  1.3  garbled scan_PCI(int start)
    112  1.3  garbled {
    113  1.3  garbled 	int slot, r;
    114  1.3  garbled 	struct PCI_cinfo *pslot;
    115  1.3  garbled 	int VGAslot = -1;
    116  1.3  garbled 	int highVGAslot = 0;
    117  1.3  garbled 
    118  1.3  garbled 	for (slot = start + 1; slot < PCI_NSLOTS; slot++) {
    119  1.3  garbled 		pslot = &PCI_slots[slot];
    120  1.3  garbled 		for (r = 0; r < PCI_NREGS; r++)
    121  1.3  garbled 			pslot->regs[r] = bswap32(pslot->config_addr[r]);
    122  1.3  garbled 		if (pslot->regs[PCI_DEVID] != 0xffffffff) {
    123  1.3  garbled 			/* we have a card */
    124  1.3  garbled 			if (((pslot->regs[PCI_CLASS] & 0xffffff00) ==
    125  1.3  garbled 				0x03000000) ||
    126  1.3  garbled 			    ((pslot->regs[PCI_CLASS] & 0xffffff00) ==
    127  1.3  garbled 				0x00010000)) {
    128  1.3  garbled 				/* it's a VGA card */
    129  1.3  garbled 				highVGAslot = slot;
    130  1.3  garbled 				if ((pslot->regs[PCI_CMD] & 0x03)) {
    131  1.3  garbled 					/* fW enabled it */
    132  1.3  garbled 					VGAslot = slot;
    133  1.3  garbled 					break;
    134  1.3  garbled 				}
    135  1.3  garbled 			}
    136  1.3  garbled 		}
    137  1.3  garbled 	}
    138  1.3  garbled 	return VGAslot;
    139  1.3  garbled }
    140  1.3  garbled 
    141  1.3  garbled int
    142  1.3  garbled PCI_vendor(int slotnum)
    143  1.3  garbled {
    144  1.3  garbled 	struct PCI_cinfo *pslot = &PCI_slots[slotnum];
    145  1.3  garbled 
    146  1.3  garbled 	return (pslot->regs[PCI_DEVID] & 0xffff);
    147  1.3  garbled }
    148