Home | History | Annotate | Line # | Download | only in boot
io.c revision 1.4.100.1
      1  1.4.100.1      mrg /*	$NetBSD: io.c,v 1.4.100.1 2012/06/02 11:09:07 mrg 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 
     40  1.4.100.1      mrg volatile u_char *PCI_mem = (u_char *)0xc0000000;
     41        1.1   nonaka volatile u_char *ISA_io  = (u_char *)0x80000000;
     42        1.3  garbled volatile u_char *ISA_mem = (u_char *)0xc0000000;
     43        1.3  garbled volatile char *videomem = (char *)0xc00b8000; /* + vram offset */
     44        1.3  garbled 
     45  1.4.100.1      mrg static int dcache_line_size = 32;
     46  1.4.100.1      mrg 
     47        1.1   nonaka 
     48        1.1   nonaka void
     49        1.2  garbled outb(int port, char val)
     50        1.1   nonaka {
     51        1.1   nonaka 
     52        1.1   nonaka 	ISA_io[port] = val;
     53        1.1   nonaka }
     54        1.1   nonaka 
     55        1.3  garbled inline void
     56        1.3  garbled outw(int port, u_int16_t val)
     57        1.3  garbled {
     58        1.3  garbled         outb(port, val>>8);
     59        1.3  garbled         outb(port+1, val);
     60        1.3  garbled }
     61        1.3  garbled 
     62        1.1   nonaka u_char
     63        1.2  garbled inb(int port)
     64        1.1   nonaka {
     65        1.1   nonaka 
     66        1.1   nonaka 	return (ISA_io[port]);
     67        1.1   nonaka }
     68        1.1   nonaka 
     69  1.4.100.1      mrg u_char
     70  1.4.100.1      mrg readb(u_long addr)
     71  1.4.100.1      mrg {
     72  1.4.100.1      mrg 
     73  1.4.100.1      mrg 	return PCI_mem[addr];
     74  1.4.100.1      mrg }
     75  1.4.100.1      mrg 
     76  1.4.100.1      mrg u_short
     77  1.4.100.1      mrg readw(u_long addr)
     78  1.4.100.1      mrg {
     79  1.4.100.1      mrg 
     80  1.4.100.1      mrg 	return le16toh(*((u_short *)&PCI_mem[addr]));
     81  1.4.100.1      mrg }
     82  1.4.100.1      mrg 
     83        1.1   nonaka u_long
     84  1.4.100.1      mrg readl(u_long addr)
     85        1.1   nonaka {
     86        1.1   nonaka 
     87  1.4.100.1      mrg 	return le32toh(*((u_long *)&PCI_mem[addr]));
     88        1.1   nonaka }
     89        1.3  garbled 
     90        1.3  garbled void
     91  1.4.100.1      mrg writeb(u_long addr, u_char val)
     92        1.3  garbled {
     93        1.3  garbled 
     94  1.4.100.1      mrg 	PCI_mem[addr] = val;
     95  1.4.100.1      mrg }
     96  1.4.100.1      mrg 
     97  1.4.100.1      mrg void
     98  1.4.100.1      mrg writel(u_long addr, u_long val)
     99  1.4.100.1      mrg {
    100  1.4.100.1      mrg 
    101  1.4.100.1      mrg 	*((u_long *)&PCI_mem[addr]) = htole32(val);
    102  1.4.100.1      mrg }
    103  1.4.100.1      mrg 
    104  1.4.100.1      mrg void
    105  1.4.100.1      mrg _wbinv(uint32_t adr, uint32_t siz)
    106  1.4.100.1      mrg {
    107  1.4.100.1      mrg 	uint32_t bnd;
    108  1.4.100.1      mrg 
    109  1.4.100.1      mrg 	asm volatile("eieio");
    110  1.4.100.1      mrg 	for (bnd = adr + siz; adr < bnd; adr += dcache_line_size)
    111  1.4.100.1      mrg 		asm volatile ("dcbf 0,%0" :: "r"(adr));
    112  1.4.100.1      mrg 	asm volatile ("sync");
    113  1.4.100.1      mrg }
    114  1.4.100.1      mrg 
    115  1.4.100.1      mrg void
    116  1.4.100.1      mrg _inv(uint32_t adr, uint32_t siz)
    117  1.4.100.1      mrg {
    118  1.4.100.1      mrg 	uint32_t bnd, off;
    119  1.4.100.1      mrg 
    120  1.4.100.1      mrg 	off = adr & (dcache_line_size - 1);
    121  1.4.100.1      mrg 	adr -= off;
    122  1.4.100.1      mrg 	siz += off;
    123  1.4.100.1      mrg 	asm volatile ("eieio");
    124  1.4.100.1      mrg 	if (off != 0) {
    125  1.4.100.1      mrg 		/* wbinv() leading unaligned dcache line */
    126  1.4.100.1      mrg 		asm volatile ("dcbf 0,%0" :: "r"(adr));
    127  1.4.100.1      mrg 		if (siz < dcache_line_size)
    128  1.4.100.1      mrg 			goto done;
    129  1.4.100.1      mrg 		adr += dcache_line_size;
    130  1.4.100.1      mrg 		siz -= dcache_line_size;
    131  1.4.100.1      mrg 	}
    132  1.4.100.1      mrg 	bnd = adr + siz;
    133  1.4.100.1      mrg 	off = bnd & (dcache_line_size - 1);
    134  1.4.100.1      mrg 	if (off != 0) {
    135  1.4.100.1      mrg 		/* wbinv() trailing unaligned dcache line */
    136  1.4.100.1      mrg 		asm volatile ("dcbf 0,%0" :: "r"(bnd)); /* it's OK */
    137  1.4.100.1      mrg 		if (siz < dcache_line_size)
    138  1.4.100.1      mrg 			goto done;
    139  1.4.100.1      mrg 		siz -= off;
    140        1.3  garbled 	}
    141  1.4.100.1      mrg 	for (bnd = adr + siz; adr < bnd; adr += dcache_line_size) {
    142  1.4.100.1      mrg 		/* inv() intermediate dcache lines if ever */
    143  1.4.100.1      mrg 		asm volatile ("dcbi 0,%0" :: "r"(adr));
    144  1.4.100.1      mrg 	}
    145  1.4.100.1      mrg   done:
    146  1.4.100.1      mrg 	asm volatile ("sync");
    147        1.3  garbled }
    148        1.3  garbled 
    149  1.4.100.1      mrg u_long
    150  1.4.100.1      mrg local_to_PCI(u_long addr)
    151        1.3  garbled {
    152        1.3  garbled 
    153  1.4.100.1      mrg 	return ((addr & 0x7FFFFFFF) | 0x80000000);
    154        1.3  garbled }
    155