1*0f09ed48Sprovos /* $NetBSD: pci_milan.c,v 1.4 2002/09/27 15:35:54 provos Exp $ */ 268f5fe6eSleo 368f5fe6eSleo /*- 468f5fe6eSleo * Copyright (c) 2001 The NetBSD Foundation, Inc. 568f5fe6eSleo * All rights reserved. 668f5fe6eSleo * 768f5fe6eSleo * This code is derived from software contributed to The NetBSD Foundation 868f5fe6eSleo * by Leo Weppelman. 968f5fe6eSleo * 1068f5fe6eSleo * Redistribution and use in source and binary forms, with or without 1168f5fe6eSleo * modification, are permitted provided that the following conditions 1268f5fe6eSleo * are met: 1368f5fe6eSleo * 1. Redistributions of source code must retain the above copyright 1468f5fe6eSleo * notice, this list of conditions and the following disclaimer. 1568f5fe6eSleo * 2. Redistributions in binary form must reproduce the above copyright 1668f5fe6eSleo * notice, this list of conditions and the following disclaimer in the 1768f5fe6eSleo * documentation and/or other materials provided with the distribution. 1868f5fe6eSleo * 3. All advertising materials mentioning features or use of this software 1968f5fe6eSleo * must display the following acknowledgement: 2068f5fe6eSleo * This product includes software developed by the NetBSD 2168f5fe6eSleo * Foundation, Inc. and its contributors. 2268f5fe6eSleo * 4. Neither the name of The NetBSD Foundation nor the names of its 2368f5fe6eSleo * contributors may be used to endorse or promote products derived 2468f5fe6eSleo * from this software without specific prior written permission. 2568f5fe6eSleo * 2668f5fe6eSleo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2768f5fe6eSleo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2868f5fe6eSleo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2968f5fe6eSleo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3068f5fe6eSleo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3168f5fe6eSleo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3268f5fe6eSleo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3368f5fe6eSleo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3468f5fe6eSleo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3568f5fe6eSleo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3668f5fe6eSleo * POSSIBILITY OF SUCH DAMAGE. 3768f5fe6eSleo */ 3868f5fe6eSleo 3968f5fe6eSleo #include <sys/types.h> 4068f5fe6eSleo #include <sys/param.h> 4168f5fe6eSleo #include <sys/systm.h> 4268f5fe6eSleo #include <sys/device.h> 4368f5fe6eSleo 4468f5fe6eSleo #include <dev/pci/pcivar.h> 4568f5fe6eSleo #include <dev/pci/pcireg.h> 4668f5fe6eSleo 472112cf10Sleo #include <dev/isa/isavar.h> /* isa_intr_{dis}establish */ 482112cf10Sleo #include <dev/isa/isareg.h> /* isa_intr_{dis}establish */ 492112cf10Sleo 5068f5fe6eSleo #include <machine/bswap.h> 512112cf10Sleo #include <machine/isa_machdep.h> /* isa_intr_{dis}establish */ 5268f5fe6eSleo 53b1ff453aSleo #include <atari/pci/pci_vga.h> 54b1ff453aSleo #include <atari/dev/grf_etreg.h> 55b1ff453aSleo 5668f5fe6eSleo int 5768f5fe6eSleo pci_bus_maxdevs(pc, busno) 5868f5fe6eSleo pci_chipset_tag_t pc; 5968f5fe6eSleo int busno; 6068f5fe6eSleo { 6168f5fe6eSleo return (6); 6268f5fe6eSleo } 6368f5fe6eSleo 6468f5fe6eSleo /* 6568f5fe6eSleo * These are defined in locore.s: 6668f5fe6eSleo */ 6768f5fe6eSleo pcireg_t milan_pci_confread(pcitag_t); 6868f5fe6eSleo void milan_pci_confwrite(u_long, pcireg_t); 6968f5fe6eSleo u_long plx_status; 7068f5fe6eSleo 7168f5fe6eSleo pcireg_t 7268f5fe6eSleo pci_conf_read(pc, tag, reg) 7368f5fe6eSleo pci_chipset_tag_t pc; 7468f5fe6eSleo pcitag_t tag; 7568f5fe6eSleo int reg; 7668f5fe6eSleo { 7768f5fe6eSleo u_long data; 7868f5fe6eSleo 7968f5fe6eSleo data = bswap32(milan_pci_confread(tag | reg)); 8068f5fe6eSleo if ((plx_status) & 0xf9000000) { 8168f5fe6eSleo /* 8268f5fe6eSleo * Access error, assume nothing there... 8368f5fe6eSleo */ 8468f5fe6eSleo data = 0xffffffff; 8568f5fe6eSleo } 8668f5fe6eSleo return(data); 8768f5fe6eSleo } 8868f5fe6eSleo 8968f5fe6eSleo 9068f5fe6eSleo void 9168f5fe6eSleo pci_conf_write(pc, tag, reg, data) 9268f5fe6eSleo pci_chipset_tag_t pc; 9368f5fe6eSleo pcitag_t tag; 9468f5fe6eSleo int reg; 9568f5fe6eSleo pcireg_t data; 9668f5fe6eSleo { 9768f5fe6eSleo milan_pci_confwrite(tag | reg, bswap32(data)); 9868f5fe6eSleo } 9968f5fe6eSleo 10068f5fe6eSleo void * 10168f5fe6eSleo pci_intr_establish(pc, ih, level, ih_fun, ih_arg) 10268f5fe6eSleo pci_chipset_tag_t pc; 10368f5fe6eSleo pci_intr_handle_t ih; 10468f5fe6eSleo int level; 10568f5fe6eSleo int (*ih_fun) __P((void *)); 10668f5fe6eSleo void *ih_arg; 10768f5fe6eSleo { 1082112cf10Sleo if (ih == 0 || ih >= 16 || ih == 2) 109*0f09ed48Sprovos panic("pci_intr_establish: bogus handle 0x%x", ih); 1102112cf10Sleo return isa_intr_establish(NULL, ih, IST_LEVEL, level, ih_fun, ih_arg); 11168f5fe6eSleo } 11268f5fe6eSleo 11368f5fe6eSleo void 11468f5fe6eSleo pci_intr_disestablish(pc, cookie) 11568f5fe6eSleo pci_chipset_tag_t pc; 11668f5fe6eSleo void *cookie; 11768f5fe6eSleo { 1182112cf10Sleo isa_intr_disestablish(NULL, cookie); 11968f5fe6eSleo } 120b1ff453aSleo 121b1ff453aSleo /* 122b1ff453aSleo * VGA related stuff... 123b1ff453aSleo * XXX: Currently, you can only boot the Milan through loadbsd.ttp, hence the 124b1ff453aSleo * text mode ;-) 125b1ff453aSleo * It looks like the Milan BIOS is initializing the VGA card in a reasonably 126b1ff453aSleo * standard text mode. However, the screen mode is 640*480 instead of 640*400. 127b1ff453aSleo * Since wscons does not handle the right by default, the card is reprogrammed 128b1ff453aSleo * to 640*400 using only 'standard' VGA registers (I hope!). So this ought to 129b1ff453aSleo * work on cards other than the S3Trio card I have tested it on. 130b1ff453aSleo */ 131b1ff453aSleo static u_char crt_tab[] = { 132b1ff453aSleo 0x60, 0x53, 0x4f, 0x14, 0x56, 0x05, 0xc1, 0x1f, 133b1ff453aSleo 0x00, 0x4f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 134b1ff453aSleo 0x98, 0x3d, 0x8f, 0x28, 0x0f, 0x8f, 0xc1, 0xc3, 135b1ff453aSleo 0xff }; 136b1ff453aSleo 137b1ff453aSleo /* 138b1ff453aSleo * XXX: Why are we repeating this everywhere! (Leo) 139b1ff453aSleo */ 140b1ff453aSleo #define PCI_LINMEMBASE 0x0e000000 141b1ff453aSleo 142b1ff453aSleo void 143b1ff453aSleo milan_vga_init(pc, tag, id, ba, fb) 144b1ff453aSleo pci_chipset_tag_t pc; 145b1ff453aSleo pcitag_t tag; 146b1ff453aSleo int id; 147b1ff453aSleo volatile u_char *ba; 148b1ff453aSleo u_char *fb; 149b1ff453aSleo { 150b1ff453aSleo int i, csr; 151b1ff453aSleo 152b1ff453aSleo /* Turn on the card */ 153b1ff453aSleo pci_conf_write(pc, tag, PCI_MAPREG_START, PCI_LINMEMBASE); 154b1ff453aSleo csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); 155b1ff453aSleo csr |= (PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_IO_ENABLE); 156b1ff453aSleo csr |= PCI_COMMAND_MASTER_ENABLE; 157b1ff453aSleo pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr); 158b1ff453aSleo 159b1ff453aSleo /* 160b1ff453aSleo * Make sure we're allowed to write all crt-registers and reload them. 161b1ff453aSleo */ 162b1ff453aSleo WCrt(ba, CRT_ID_END_VER_RETR, (RCrt(ba, CRT_ID_END_VER_RETR) & 0x7f)); 163b1ff453aSleo 164b1ff453aSleo for (i = 0; i < 0x18; i++) 165b1ff453aSleo WCrt(ba, i, crt_tab[i]); 166b1ff453aSleo 167b1ff453aSleo /* 168b1ff453aSleo * The Milan has a white border... make it black 169b1ff453aSleo */ 170b1ff453aSleo WAttr(ba, 0x11, 0|0x20); 171b1ff453aSleo } 172