Home | History | Annotate | Line # | Download | only in boot
pci.c revision 1.2
      1 /*	$Id: pci.c,v 1.2 1998/10/28 02:47:35 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 #include <dev/pci/pcidevs.h>
     42 
     43 #define	PCI_CONF_REG(dev,reg)		\
     44 	*(u_int32_t *)(0x80800000 | (1 << dev) | reg)
     45 
     46 u_int32_t
     47 pci_conf_read(dev, reg)
     48 	int dev;
     49 	int reg;
     50 {
     51 	if (dev < 11 || dev > 18)
     52 		return 0xffffffff;
     53 	if (reg < 0 || reg > 255)
     54 		return 0xffffffff;
     55 
     56 	return (u_int32_t)bswap32(PCI_CONF_REG(dev, reg));
     57 }
     58 
     59 pci_conf_write(dev, reg, data)
     60 	int dev;
     61 	int reg;
     62 	u_int32_t data;
     63 {
     64 	if (dev < 11 || dev > 18)
     65 		return;
     66 	if (reg < 0 || reg > 255)
     67 		return;
     68 
     69 	PCI_CONF_REG(dev, reg) = (u_int32_t)bswap32(data);
     70 }
     71 
     72 pci_init()
     73 {
     74 	int dev;
     75 	u_int32_t data;
     76 
     77 	/*
     78 	 * On board NCR53C810A
     79 	 */
     80 	pci_conf_write(12, 0x10, 0x01000001);
     81 	pci_conf_write(12, 0x14, 0x01000000);
     82 	data = pci_conf_read(12, PCI_INTERRUPT_REG);
     83 	pci_conf_write(12, PCI_INTERRUPT_REG, data & 0xffff00ff | 20 << 8);
     84 
     85 	/*
     86 	 * remap Video
     87 	 */
     88 	for (dev = 13; dev < 18; dev++) {
     89 
     90 		data = pci_conf_read(dev, PCI_CLASS_REG);
     91 
     92 		if (PCI_CLASS(data) == PCI_CLASS_DISPLAY) {
     93 
     94 			data = pci_conf_read(dev, PCI_COMMAND_STATUS_REG);
     95 
     96 			if (data &
     97 			    (PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE)) {
     98 				/*
     99 				 * Initialized PCI Video
    100 				 */
    101 				data = pci_conf_read(dev, PCI_ID_REG);
    102 
    103 				if (PCI_VENDOR(data) == PCI_VENDOR_S3) {
    104 					pci_conf_write(dev, 0x10, 0x0);
    105 				} else {
    106 					data = pci_conf_read(dev, 0x10);
    107 					pci_conf_write(dev, 0x10,
    108 						data & 0x0fffffff);
    109 
    110 					data = pci_conf_read(dev, 0x14);
    111 					pci_conf_write(dev, 0x14,
    112 						data & 0x0fffffff);
    113 				}
    114 			}
    115 		}
    116 	}
    117 }
    118