Home | History | Annotate | Line # | Download | only in boot
pci.c revision 1.1
      1 /*	$Id: pci.c,v 1.1 1998/10/26 00:45:47 sakamoto Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Kazuki Sakamoto.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <stand.h>
     40 #include <dev/pci/pcireg.h>
     41 
     42 #define	PCI_CONF_REG(dev,reg)		\
     43 	*(u_int32_t *)(0x80800000 | (1 << dev) | reg)
     44 
     45 u_int32_t
     46 pci_conf_read(dev, reg)
     47 	int dev;
     48 	int reg;
     49 {
     50 	if (dev < 11 || dev > 18)
     51 		return 0xffffffff;
     52 	if (reg < 0 || reg > 255)
     53 		return 0xffffffff;
     54 
     55 	return (u_int32_t)bswap32(PCI_CONF_REG(dev, reg));
     56 }
     57 
     58 pci_conf_write(dev, reg, data)
     59 	int dev;
     60 	int reg;
     61 	u_int32_t data;
     62 {
     63 	if (dev < 11 || dev > 18)
     64 		return;
     65 	if (reg < 0 || reg > 255)
     66 		return;
     67 
     68 	PCI_CONF_REG(dev, reg) = (u_int32_t)bswap32(data);
     69 }
     70 
     71 pci_init()
     72 {
     73 	int dev;
     74 	u_int32_t data;
     75 
     76 	/*
     77 	 * On board NCR53C810A
     78 	 */
     79 	pci_conf_write(12, 0x10, 0x01000001);
     80 	pci_conf_write(12, 0x14, 0x01000000);
     81 	data = pci_conf_read(12, PCI_INTERRUPT_REG);
     82 	pci_conf_write(12, PCI_INTERRUPT_REG, data & 0xffff00ff | 20 << 8);
     83 
     84 	/*
     85 	 * remap Video
     86 	 */
     87 	for (dev = 13; dev < 18; dev++) {
     88 
     89 		data = pci_conf_read(dev, PCI_CLASS_REG);
     90 
     91 		if (PCI_CLASS(data) == PCI_CLASS_DISPLAY) {
     92 
     93 			data = pci_conf_read(dev, PCI_COMMAND_STATUS_REG);
     94 
     95 			if (data &
     96 			    (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE)) {
     97 				/*
     98 				 * Initialized PCI Video
     99 				 */
    100 				pci_conf_write(dev, 0x10, 0x0);
    101 			}
    102 		}
    103 	}
    104 }
    105