Home | History | Annotate | Line # | Download | only in pci
pci_milan.c revision 1.7
      1 /*	$NetBSD: pci_milan.c,v 1.7 2006/01/29 21:42:41 dsl Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Leo Weppelman.
      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 <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: pci_milan.c,v 1.7 2006/01/29 21:42:41 dsl Exp $");
     41 
     42 #include <sys/types.h>
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/device.h>
     46 
     47 #include <dev/pci/pcivar.h>
     48 #include <dev/pci/pcireg.h>
     49 
     50 #include <dev/isa/isavar.h>		/* isa_intr_{dis}establish */
     51 #include <dev/isa/isareg.h>		/* isa_intr_{dis}establish */
     52 
     53 #include <sys/bswap.h>
     54 #include <machine/isa_machdep.h>	/* isa_intr_{dis}establish */
     55 
     56 #include <atari/pci/pci_vga.h>
     57 #include <atari/dev/grf_etreg.h>
     58 
     59 int
     60 pci_bus_maxdevs(pc, busno)
     61 	pci_chipset_tag_t pc;
     62 	int busno;
     63 {
     64 	return (6);
     65 }
     66 
     67 /*
     68  * These are defined in locore.s:
     69  */
     70 pcireg_t	milan_pci_confread(pcitag_t);
     71 void		milan_pci_confwrite(u_long, pcireg_t);
     72 u_long		plx_status;
     73 
     74 pcireg_t
     75 pci_conf_read(pc, tag, reg)
     76 	pci_chipset_tag_t pc;
     77 	pcitag_t tag;
     78 	int reg;
     79 {
     80 	u_long		data;
     81 
     82 	data = bswap32(milan_pci_confread(tag | reg));
     83 	if ((plx_status) & 0xf9000000) {
     84 		/*
     85 		 * Access error, assume nothing there...
     86 		 */
     87 		data = 0xffffffff;
     88 	}
     89 	return(data);
     90 }
     91 
     92 
     93 void
     94 pci_conf_write(pc, tag, reg, data)
     95 	pci_chipset_tag_t pc;
     96 	pcitag_t tag;
     97 	int reg;
     98 	pcireg_t data;
     99 {
    100 	milan_pci_confwrite(tag | reg, bswap32(data));
    101 }
    102 
    103 void *
    104 pci_intr_establish(pc, ih, level, ih_fun, ih_arg)
    105 	pci_chipset_tag_t	pc;
    106 	pci_intr_handle_t	ih;
    107 	int			level;
    108 	int			(*ih_fun) __P((void *));
    109 	void			*ih_arg;
    110 {
    111 	if (ih == 0 || ih >= 16 || ih == 2)
    112 		panic("pci_intr_establish: bogus handle 0x%x", ih);
    113 	return isa_intr_establish(NULL, ih, IST_LEVEL, level, ih_fun, ih_arg);
    114 }
    115 
    116 void
    117 pci_intr_disestablish(pc, cookie)
    118 	pci_chipset_tag_t pc;
    119 	void *cookie;
    120 {
    121 	isa_intr_disestablish(NULL, cookie);
    122 }
    123 
    124 /*
    125  * VGA related stuff...
    126  * XXX: Currently, you can only boot the Milan through loadbsd.ttp, hence the
    127  *      text mode ;-)
    128  * It looks like the Milan BIOS is initializing the VGA card in a reasonably
    129  * standard text mode. However, the screen mode is 640*480 instead of 640*400.
    130  * Since wscons does not handle the right by default, the card is reprogrammed
    131  * to 640*400 using only 'standard' VGA registers (I hope!). So this ought to
    132  * work on cards other than the S3Trio card I have tested it on.
    133  */
    134 static u_char crt_tab[] = {
    135 	0x60, 0x53, 0x4f, 0x14, 0x56, 0x05, 0xc1, 0x1f,
    136 	0x00, 0x4f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
    137 	0x98, 0x3d, 0x8f, 0x28, 0x0f, 0x8f, 0xc1, 0xc3,
    138 	0xff };
    139 
    140 /*
    141  * XXX: Why are we repeating this everywhere! (Leo)
    142  */
    143 #define PCI_LINMEMBASE  0x0e000000
    144 
    145 void
    146 milan_vga_init(pc, tag, id, ba, fb)
    147 	pci_chipset_tag_t	pc;
    148 	pcitag_t		tag;
    149 	int			id;
    150 	volatile u_char		*ba;
    151 	u_char			*fb;
    152 {
    153 	int			i, csr;
    154 
    155 	/* Turn on the card */
    156 	pci_conf_write(pc, tag, PCI_MAPREG_START, PCI_LINMEMBASE);
    157 	csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    158 	csr |= (PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_IO_ENABLE);
    159 	csr |= PCI_COMMAND_MASTER_ENABLE;
    160 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
    161 
    162 	/*
    163 	 * Make sure we're allowed to write all crt-registers and reload them.
    164 	 */
    165 	WCrt(ba, CRT_ID_END_VER_RETR, (RCrt(ba, CRT_ID_END_VER_RETR) & 0x7f));
    166 
    167 	for (i = 0; i < 0x18; i++)
    168 		WCrt(ba, i, crt_tab[i]);
    169 
    170 	/*
    171 	 * The Milan has a white border... make it black
    172 	 */
    173 	WAttr(ba, 0x11, 0|0x20);
    174 }
    175