Home | History | Annotate | Line # | Download | only in boot
io.c revision 1.4.96.1
      1  1.4.96.1     yamt /*	$NetBSD: io.c,v 1.4.96.1 2012/05/23 10:07:48 yamt 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.96.1     yamt 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.96.1     yamt static int dcache_line_size = 32;
     46  1.4.96.1     yamt 
     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.96.1     yamt u_char
     70  1.4.96.1     yamt readb(u_long addr)
     71  1.4.96.1     yamt {
     72  1.4.96.1     yamt 
     73  1.4.96.1     yamt 	return PCI_mem[addr];
     74  1.4.96.1     yamt }
     75  1.4.96.1     yamt 
     76  1.4.96.1     yamt u_short
     77  1.4.96.1     yamt readw(u_long addr)
     78  1.4.96.1     yamt {
     79  1.4.96.1     yamt 
     80  1.4.96.1     yamt 	return le16toh(*((u_short *)&PCI_mem[addr]));
     81  1.4.96.1     yamt }
     82  1.4.96.1     yamt 
     83       1.1   nonaka u_long
     84  1.4.96.1     yamt readl(u_long addr)
     85       1.1   nonaka {
     86       1.1   nonaka 
     87  1.4.96.1     yamt 	return le32toh(*((u_long *)&PCI_mem[addr]));
     88       1.1   nonaka }
     89       1.3  garbled 
     90       1.3  garbled void
     91  1.4.96.1     yamt writeb(u_long addr, u_char val)
     92       1.3  garbled {
     93       1.3  garbled 
     94  1.4.96.1     yamt 	PCI_mem[addr] = val;
     95  1.4.96.1     yamt }
     96  1.4.96.1     yamt 
     97  1.4.96.1     yamt void
     98  1.4.96.1     yamt writel(u_long addr, u_long val)
     99  1.4.96.1     yamt {
    100  1.4.96.1     yamt 
    101  1.4.96.1     yamt 	*((u_long *)&PCI_mem[addr]) = htole32(val);
    102  1.4.96.1     yamt }
    103  1.4.96.1     yamt 
    104  1.4.96.1     yamt void
    105  1.4.96.1     yamt _wbinv(uint32_t adr, uint32_t siz)
    106  1.4.96.1     yamt {
    107  1.4.96.1     yamt 	uint32_t bnd;
    108  1.4.96.1     yamt 
    109  1.4.96.1     yamt 	asm volatile("eieio");
    110  1.4.96.1     yamt 	for (bnd = adr + siz; adr < bnd; adr += dcache_line_size)
    111  1.4.96.1     yamt 		asm volatile ("dcbf 0,%0" :: "r"(adr));
    112  1.4.96.1     yamt 	asm volatile ("sync");
    113  1.4.96.1     yamt }
    114  1.4.96.1     yamt 
    115  1.4.96.1     yamt void
    116  1.4.96.1     yamt _inv(uint32_t adr, uint32_t siz)
    117  1.4.96.1     yamt {
    118  1.4.96.1     yamt 	uint32_t bnd, off;
    119  1.4.96.1     yamt 
    120  1.4.96.1     yamt 	off = adr & (dcache_line_size - 1);
    121  1.4.96.1     yamt 	adr -= off;
    122  1.4.96.1     yamt 	siz += off;
    123  1.4.96.1     yamt 	asm volatile ("eieio");
    124  1.4.96.1     yamt 	if (off != 0) {
    125  1.4.96.1     yamt 		/* wbinv() leading unaligned dcache line */
    126  1.4.96.1     yamt 		asm volatile ("dcbf 0,%0" :: "r"(adr));
    127  1.4.96.1     yamt 		if (siz < dcache_line_size)
    128  1.4.96.1     yamt 			goto done;
    129  1.4.96.1     yamt 		adr += dcache_line_size;
    130  1.4.96.1     yamt 		siz -= dcache_line_size;
    131  1.4.96.1     yamt 	}
    132  1.4.96.1     yamt 	bnd = adr + siz;
    133  1.4.96.1     yamt 	off = bnd & (dcache_line_size - 1);
    134  1.4.96.1     yamt 	if (off != 0) {
    135  1.4.96.1     yamt 		/* wbinv() trailing unaligned dcache line */
    136  1.4.96.1     yamt 		asm volatile ("dcbf 0,%0" :: "r"(bnd)); /* it's OK */
    137  1.4.96.1     yamt 		if (siz < dcache_line_size)
    138  1.4.96.1     yamt 			goto done;
    139  1.4.96.1     yamt 		siz -= off;
    140       1.3  garbled 	}
    141  1.4.96.1     yamt 	for (bnd = adr + siz; adr < bnd; adr += dcache_line_size) {
    142  1.4.96.1     yamt 		/* inv() intermediate dcache lines if ever */
    143  1.4.96.1     yamt 		asm volatile ("dcbi 0,%0" :: "r"(adr));
    144  1.4.96.1     yamt 	}
    145  1.4.96.1     yamt   done:
    146  1.4.96.1     yamt 	asm volatile ("sync");
    147       1.3  garbled }
    148       1.3  garbled 
    149  1.4.96.1     yamt u_long
    150  1.4.96.1     yamt local_to_PCI(u_long addr)
    151       1.3  garbled {
    152       1.3  garbled 
    153  1.4.96.1     yamt 	return ((addr & 0x7FFFFFFF) | 0x80000000);
    154       1.3  garbled }
    155