Home | History | Annotate | Line # | Download | only in pci
pci_milan.c revision 1.11
      1 /*	$NetBSD: pci_milan.c,v 1.11 2009/03/14 15:36:03 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: pci_milan.c,v 1.11 2009/03/14 15:36:03 dsl Exp $");
     34 
     35 #include <sys/types.h>
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 
     40 #include <dev/pci/pcivar.h>
     41 #include <dev/pci/pcireg.h>
     42 
     43 #include <dev/isa/isavar.h>		/* isa_intr_{dis}establish */
     44 #include <dev/isa/isareg.h>		/* isa_intr_{dis}establish */
     45 
     46 #include <sys/bswap.h>
     47 #include <machine/isa_machdep.h>	/* isa_intr_{dis}establish */
     48 
     49 #include <atari/pci/pci_vga.h>
     50 #include <atari/dev/grf_etreg.h>
     51 
     52 int
     53 pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
     54 {
     55 	return (6);
     56 }
     57 
     58 /*
     59  * These are defined in locore.s:
     60  */
     61 pcireg_t	milan_pci_confread(pcitag_t);
     62 void		milan_pci_confwrite(u_long, pcireg_t);
     63 u_long		plx_status;
     64 
     65 pcireg_t
     66 pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
     67 {
     68 	u_long		data;
     69 
     70 	data = bswap32(milan_pci_confread(tag | reg));
     71 	if ((plx_status) & 0xf9000000) {
     72 		/*
     73 		 * Access error, assume nothing there...
     74 		 */
     75 		data = 0xffffffff;
     76 	}
     77 	return(data);
     78 }
     79 
     80 
     81 void
     82 pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
     83 {
     84 	milan_pci_confwrite(tag | reg, bswap32(data));
     85 }
     86 
     87 int
     88 pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
     89 		 int attr, uint64_t data)
     90 {
     91 
     92 	switch (attr) {
     93 	case PCI_INTR_MPSAFE:
     94 		return 0;
     95 	default:
     96 		return ENODEV;
     97 	}
     98 }
     99 
    100 void *
    101 pci_intr_establish(pc, ih, level, ih_fun, ih_arg)
    102 	pci_chipset_tag_t	pc;
    103 	pci_intr_handle_t	ih;
    104 	int			level;
    105 	int			(*ih_fun)(void *);
    106 	void			*ih_arg;
    107 {
    108 	if (ih == 0 || ih >= 16 || ih == 2)
    109 		panic("pci_intr_establish: bogus handle 0x%x", ih);
    110 	return isa_intr_establish(NULL, ih, IST_LEVEL, level, ih_fun, ih_arg);
    111 }
    112 
    113 void
    114 pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
    115 {
    116 	isa_intr_disestablish(NULL, cookie);
    117 }
    118 
    119 /*
    120  * VGA related stuff...
    121  * XXX: Currently, you can only boot the Milan through loadbsd.ttp, hence the
    122  *      text mode ;-)
    123  * It looks like the Milan BIOS is initializing the VGA card in a reasonably
    124  * standard text mode. However, the screen mode is 640*480 instead of 640*400.
    125  * Since wscons does not handle the right by default, the card is reprogrammed
    126  * to 640*400 using only 'standard' VGA registers (I hope!). So this ought to
    127  * work on cards other than the S3Trio card I have tested it on.
    128  */
    129 static u_char crt_tab[] = {
    130 	0x60, 0x53, 0x4f, 0x14, 0x56, 0x05, 0xc1, 0x1f,
    131 	0x00, 0x4f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
    132 	0x98, 0x3d, 0x8f, 0x28, 0x0f, 0x8f, 0xc1, 0xc3,
    133 	0xff };
    134 
    135 /*
    136  * XXX: Why are we repeating this everywhere! (Leo)
    137  */
    138 #define PCI_LINMEMBASE  0x0e000000
    139 
    140 void
    141 milan_vga_init(pci_chipset_tag_t pc, pcitag_t tag, int id, volatile u_char *ba, u_char *fb)
    142 {
    143 	int			i, csr;
    144 
    145 	/* Turn on the card */
    146 	pci_conf_write(pc, tag, PCI_MAPREG_START, PCI_LINMEMBASE);
    147 	csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    148 	csr |= (PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_IO_ENABLE);
    149 	csr |= PCI_COMMAND_MASTER_ENABLE;
    150 	pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
    151 
    152 	/*
    153 	 * Make sure we're allowed to write all crt-registers and reload them.
    154 	 */
    155 	WCrt(ba, CRT_ID_END_VER_RETR, (RCrt(ba, CRT_ID_END_VER_RETR) & 0x7f));
    156 
    157 	for (i = 0; i < 0x18; i++)
    158 		WCrt(ba, i, crt_tab[i]);
    159 
    160 	/*
    161 	 * The Milan has a white border... make it black
    162 	 */
    163 	WAttr(ba, 0x11, 0|0x20);
    164 }
    165