Module Name:    src
Committed By:   kiyohara
Date:           Thu Oct 14 06:12:54 UTC 2010

Modified Files:
        src/sys/arch/bebox/stand/boot: boot.c boot.h vreset.c
Added Files:
        src/sys/arch/bebox/stand/boot: pci.c

Log Message:
Add pci.c.  Splitted from vreset.c
And cleanup vreset.c.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/bebox/stand/boot/boot.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/bebox/stand/boot/boot.h
cvs rdiff -u -r0 -r1.5 src/sys/arch/bebox/stand/boot/pci.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/bebox/stand/boot/vreset.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/bebox/stand/boot/boot.c
diff -u src/sys/arch/bebox/stand/boot/boot.c:1.18 src/sys/arch/bebox/stand/boot/boot.c:1.19
--- src/sys/arch/bebox/stand/boot/boot.c:1.18	Wed Mar 18 10:22:26 2009
+++ src/sys/arch/bebox/stand/boot/boot.c	Thu Oct 14 06:12:54 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.18 2009/03/18 10:22:26 cegger Exp $	*/
+/*	$NetBSD: boot.c,v 1.19 2010/10/14 06:12:54 kiyohara Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -74,6 +74,8 @@
 		cpu1();
 	resetCPU1();
 
+	scanPCI();
+
 	/*
 	 * console init
 	 */

Index: src/sys/arch/bebox/stand/boot/boot.h
diff -u src/sys/arch/bebox/stand/boot/boot.h:1.8 src/sys/arch/bebox/stand/boot/boot.h:1.9
--- src/sys/arch/bebox/stand/boot/boot.h:1.8	Thu Oct 14 05:52:01 2010
+++ src/sys/arch/bebox/stand/boot/boot.h	Thu Oct 14 06:12:54 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.h,v 1.8 2010/10/14 05:52:01 kiyohara Exp $	*/
+/*	$NetBSD: boot.h,v 1.9 2010/10/14 06:12:54 kiyohara Exp $	*/
 
 #define	TICKS_PER_SEC	(33000000 / 4)		/* 33MHz */
 #define	NS_PER_TICK	(1000000000 / TICKS_PER_SEC)
@@ -75,6 +75,19 @@
 int db_monitor(void);
 
 /*
+ * pci
+ */
+void scanPCI(void);
+int findPCIVga(void);
+void enablePCI(int, int, int, int);
+int PCISlotnum(u_int, u_int, u_int);
+int PCIVendor(int);
+u_long PCIAddress(int, u_int, int);
+#ifdef DEBUG
+void printslots(void);
+#endif
+
+/*
  * tgets
  */
 int tgets(char *);

Index: src/sys/arch/bebox/stand/boot/vreset.c
diff -u src/sys/arch/bebox/stand/boot/vreset.c:1.11 src/sys/arch/bebox/stand/boot/vreset.c:1.12
--- src/sys/arch/bebox/stand/boot/vreset.c:1.11	Mon May 26 16:28:39 2008
+++ src/sys/arch/bebox/stand/boot/vreset.c	Thu Oct 14 06:12:54 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: vreset.c,v 1.11 2008/05/26 16:28:39 kiyohara Exp $	*/
+/*	$NetBSD: vreset.c,v 1.12 2010/10/14 06:12:54 kiyohara Exp $	*/
 
 /*
  * Copyright (C) 1995-1997 Gary Thomas ([email protected])
@@ -42,14 +42,9 @@
 
 #ifdef CONS_VGA
 #include <lib/libsa/stand.h>
-#include <sys/bswap.h>
 #include "boot.h"
 #include "iso_font.h"
 
-#if 0
-static char rcsid[] = "vreset.c 2.0 1997 kane  PEK'97 Exp $";
-#endif
-
 /*
  * VGA Register
  */
@@ -436,18 +431,14 @@
 	0x0C, 0x00, 0x0F, 0x08, 0x00
 };
 
-void enablePCIvideo(int);
-static int scanPCI(void);
-static int PCIVendor(int);
-int delayLoop(int);
-void writeAttr(u_char, u_char, u_char);
-void setTextRegs(struct VgaRegs *);
-void setTextCLUT(void);
-void loadFont(u_char *);
-void unlockS3(void);
-#ifdef DEBUG
-static void printslots(void);
-#endif
+
+static int delayLoop(int);
+static void writeAttr(u_char, u_char, u_char);
+static void setTextRegs(struct VgaRegs *);
+static void setTextCLUT(void);
+static void loadFont(u_char *);
+static void unlockS3(void);
+statuc void enablePCIvideo(int);
 
 void
 vga_reset(u_char *ISA_mem)
@@ -461,8 +452,8 @@
 		return;
 
 	/* If no VGA responding in text mode, then we have some work to do... */
-	slot = scanPCI();            	/* find video card in use  */
-	enablePCIvideo(slot);          	/* enable I/O to card      */
+	slot = findPCIVga();		/* find video card in use */
+	enablePCIvideo(slot);		/* enable I/O to card */
 
 	/*
          * Note: the PCI scanning code does not yet work correctly
@@ -527,16 +518,33 @@
 	};
 
 #ifdef DEBUG
-	printslots();
+	printPCIslots();
 	delayLoop(5);
 #endif
 	delayLoop(2);		/* give time for the video monitor to come up */
 }
 
+static int
+delayLoop(int k)
+{
+	volatile int a, b;
+	volatile int i, j;
+	a = 0;
+	do {
+		for (i = 0; i < 500; i++) {
+			b = i;
+			for (j = 0; j < 200; j++) {
+				a = b+j;
+			}
+		}
+	} while (k--);
+	return a;
+}
+
 /*
  * Write to VGA Attribute registers.
  */
-void
+static void
 writeAttr(u_char index, u_char data, u_char videoOn)
 {
 	u_char v;
@@ -548,7 +556,7 @@
 	outb(0x3c0, data);
 }
 
-void
+static void
 setTextRegs(struct VgaRegs *svp)
 {
 	int i;
@@ -574,7 +582,7 @@
 	writeAttr(0x14, 0x00, 1);	/* color select; video on */
 }
 
-void
+static void
 setTextCLUT(void)
 {
 	int i;
@@ -591,7 +599,7 @@
 	}
 }
 
-void
+static void
 loadFont(u_char *ISA_mem)
 {
 	int i, j;
@@ -603,7 +611,7 @@
 	 */
 	i = inb(0x3DA);		/* Reset Attr toggle */
 
-	outb(0x3C0,0x30);
+	outb(0x3C0, 0x30);
 	outb(0x3C0, 0x01);	/* graphics mode */
 
 	outw(0x3C4, 0x0001);	/* reset sequencer */
@@ -622,7 +630,7 @@
 	}
 }
 
-void
+static void
 unlockS3(void)
 {
 	/* From the S3 manual */
@@ -670,118 +678,17 @@
 	outb(0x3D5, inb(0x3D5)&~0x10);
 }
 
-/* ============ */
-
-
-#define NSLOTS 5
-#define NPCIREGS  5
-
-/*
- * should use devfunc number/indirect method to be totally safe on
- * all machines, this works for now on 3 slot Moto boxes
- */
-
-struct PCI_ConfigInfo {
-	u_long * config_addr;
-	u_long regs[NPCIREGS];
-} PCI_slots [NSLOTS] = {
-	{ (u_long *)0x80800800, { 0xDE, 0xAD, 0xBE, 0xEF } },
-	{ (u_long *)0x80801000, { 0xDE, 0xAD, 0xBE, 0xEF } },
-	{ (u_long *)0x80802000, { 0xDE, 0xAD, 0xBE, 0xEF } },
-	{ (u_long *)0x80804000, { 0xDE, 0xAD, 0xBE, 0xEF } },
-	{ (u_long *)0x80808000, { 0xDE, 0xAD, 0xBE, 0xEF } },
-};
-
-
 /*
  * The following code modifies the PCI Command register
  * to enable memory and I/O accesses.
  */
-void
+static void
 enablePCIvideo(int slot)
 {
-	volatile u_char *ppci;
 
-	ppci = (u_char *)PCI_slots[slot].config_addr;
-	ppci[4] = 0x0003;	/* enable memory and I/O accesses */
-	__asm volatile("eieio");
+	enablePCI(slot, 1, 1, 0);	/* Enable IO and Memory */
 
 	outb(0x3d4, 0x11);
 	outb(0x3d5, 0x0e);	/* unlock CR0-CR7 */
 }
-
-#define DEVID   0
-#define CMD     1
-#define CLASS   2
-#define MEMBASE 4
-
-int
-scanPCI(void)
-{
-	int slt, r;
-	struct PCI_ConfigInfo *pslot;
-	int theSlot = -1;
-	int highVgaSlot = -1;
-
-	for (slt = 0; slt < NSLOTS; slt++) {
-		pslot = &PCI_slots[slt];
-		for (r = 0; r < NPCIREGS; r++) {
-			pslot->regs[r] = bswap32(pslot->config_addr[r]);
-		}
-
-		if (pslot->regs[DEVID] != 0xFFFFFFFF) {     /* card in slot ? */
-			if ((pslot->regs[CLASS] & 0xFFFFFF00) == 0x03000000) { /* VGA ? */
-				highVgaSlot = slt;
-				if ((pslot->regs[CMD] & 0x03)) { /* did firmware enable it ? */
-					theSlot = slt;
-				}
-			}
-		}
-	}
-
-	if (theSlot == -1)
-		theSlot = highVgaSlot;
-
-	return theSlot;
-}
-
-int
-delayLoop(int k)
-{
-	volatile int a, b;
-	volatile int i, j;
-	a = 0;
-	do {
-		for (i = 0; i < 500; i++) {
-			b = i;
-			for (j = 0; j < 200; j++) {
-				a = b+j;
-			}
-		}
-	} while (k--);
-	return a;
-}
-
-/* return Vendor ID of card in the slot */
-static int
-PCIVendor(int slotnum)
-{
-	struct PCI_ConfigInfo *pslot;
-
-	pslot = &PCI_slots[slotnum];
-
-	return (pslot->regs[DEVID] & 0xFFFF);
-}
-
-#ifdef DEBUG
-static void
-printslots(void)
-{
-	int i;
-	for (i = 0; i < NSLOTS; i++) {
-		printf("PCI Slot number: %d", i);
-		printf(" Vendor ID: 0x%x\n", PCIVendor(i));
-	}
-}
-#endif /* DEBUG */
 #endif /* CONS_VGA */

Added files:

Index: src/sys/arch/bebox/stand/boot/pci.c
diff -u /dev/null src/sys/arch/bebox/stand/boot/pci.c:1.5
--- /dev/null	Thu Oct 14 06:12:54 2010
+++ src/sys/arch/bebox/stand/boot/pci.c	Thu Oct 14 06:12:54 2010
@@ -0,0 +1,194 @@
+/*	$NetBSD: pci.c,v 1.5 2010/10/14 06:12:54 kiyohara Exp $	*/
+
+/*
+ * Copyright (C) 1995-1997 Gary Thomas ([email protected])
+ * All rights reserved.
+ *
+ * Adapted from a program by:
+ *                                      Steve Sellgren
+ *                                      San Francisco Indigo Company
+ *                                      [email protected]
+ * Adapted for Moto boxes by:
+ *                                      Pat Kane & Mark Scott, 1996
+ * Fixed for IBM/PowerStack II          Pat Kane 1997
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Gary Thomas.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <lib/libsa/stand.h>
+#include <sys/bswap.h>
+#include <dev/pci/pcireg.h>
+#include "boot.h"
+
+#define NSLOTS 5
+#define NPCIREGS  10
+
+
+/*
+ * should use devfunc number/indirect method to be totally safe on
+ * all machines, this works for now on 3 slot Moto boxes
+ */
+
+#define PCI_CONFIG_SPACE_BASE	0x80800000
+#define PCI_CONFIG_SPACE(d, f)	\
+		(u_long *)(PCI_CONFIG_SPACE_BASE | (1 << (d)) | ((f) << 8))
+
+struct PCI_ConfigInfo {
+	u_long *config_addr;
+	u_long regs[NPCIREGS];
+} PCI_slots [NSLOTS] = {
+	{ PCI_CONFIG_SPACE(11, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
+	{ PCI_CONFIG_SPACE(12, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
+	{ PCI_CONFIG_SPACE(13, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
+	{ PCI_CONFIG_SPACE(14, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
+	{ PCI_CONFIG_SPACE(15, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
+};
+
+
+#define DEVID		(PCI_ID_REG >> 2)
+#define CMD		(PCI_COMMAND_STATUS_REG >> 2)
+#define CLASS		(PCI_CLASS_REG >> 2)
+#define BAR_BASE	(PCI_MAPREG_START >> 2)
+
+/*
+ * The following code modifies the PCI Command register
+ * to enable memory and I/O accesses.
+ */
+void
+enablePCI(int slot, int io, int mem, int master)
+{
+	volatile u_char *ppci;
+	u_char enable = 0;
+
+	if (io)
+		enable |= PCI_COMMAND_IO_ENABLE;
+	if (mem)
+		enable |= PCI_COMMAND_MEM_ENABLE;
+	if (master)
+		enable |= PCI_COMMAND_MASTER_ENABLE;
+
+	ppci = (u_char *)&PCI_slots[slot].config_addr[CMD];
+	*ppci = enable;
+	__asm volatile("eieio");
+}
+
+void
+scanPCI(void)
+{
+	struct PCI_ConfigInfo *pslot;
+	int slt, r;
+
+	for (slt = 0; slt < NSLOTS; slt++) {
+		pslot = &PCI_slots[slt];
+		for (r = 0; r < NPCIREGS; r++)
+			pslot->regs[r] = bswap32(pslot->config_addr[r]);
+	}
+}
+
+int
+findPCIVga(void)
+{
+	struct PCI_ConfigInfo *pslot;
+	int theSlot = -1;
+	int highVgaSlot = -1;
+	int slt;
+
+	for (slt = 0; slt < NSLOTS; slt++) {
+		pslot = &PCI_slots[slt];
+		if (pslot->regs[DEVID] != 0xffffffff) {	/* card in slot ? */
+			if (PCI_CLASS(pslot->regs[CLASS]) ==
+			    PCI_CLASS_DISPLAY) {
+				highVgaSlot = slt;
+				if ((pslot->regs[CMD] & 0x03)) { /* did firmware enable it ? */
+					theSlot = slt;
+				}
+			}
+		}
+	}
+	if (theSlot == -1)
+		theSlot = highVgaSlot;
+
+	return theSlot;
+}
+
+int
+PCISlotnum(u_int bus, u_int dev, u_int func)
+{
+	u_long *tag;
+	int i;
+
+	if (bus != 0 ||
+	    dev < 11 || dev > 15 ||
+	    func > 7)
+		return -1;
+
+	tag = PCI_CONFIG_SPACE(dev, func);
+	for (i = 0; i < sizeof(PCI_slots) / sizeof(struct PCI_ConfigInfo); i++)
+		if (tag == PCI_slots[i].config_addr)
+			return i;
+	return -1;
+}
+
+/* return Vendor ID of card in the slot */
+int
+PCIVendor(int slotnum)
+{
+	struct PCI_ConfigInfo *pslot;
+
+	pslot = &PCI_slots[slotnum];
+
+	return pslot->regs[DEVID] & 0xffff;
+}
+
+/* return mapped address for I/O or Memory */
+u_long
+PCIAddress(int slotnum, u_int bar, int type)
+{
+	struct PCI_ConfigInfo *pslot;
+
+	if (bar >= 6)
+		return 0xffffffff;
+
+	pslot = &PCI_slots[slotnum];
+
+	if (pslot->regs[DEVID] == 0xffffffff ||
+	    PCI_MAPREG_TYPE(pslot->regs[BAR_BASE + bar]) != type)
+		return 0xffffffff;
+
+	return PCI_MAPREG_MEM_ADDR(pslot->regs[BAR_BASE + bar]);
+}
+
+#ifdef DEBUG
+void
+printPCIslots(void)
+{
+	int i;
+	for (i = 0; i < NSLOTS; i++) {
+		printf("PCI Slot number: %d", i);
+		printf(" Vendor ID: 0x%x\n", PCIVendor(i));
+	}
+}
+#endif /* DEBUG */

Reply via email to