Tue Nov 9 12:24:48 2010 UTC ()
Update sti(4) from OpenBSD bringing across support for sti @ pci.

Thanks to Adam Hoka for testing.


(skrll)
diff -r1.1 -r1.2 src/share/man/man4/sti.4
diff -r1.102 -r1.103 src/sys/arch/hp700/conf/GENERIC
diff -r1.23 -r1.24 src/sys/arch/hp700/conf/files.hp700
diff -r0 -r1.1 src/sys/arch/hp700/dev/sti_pci_machdep.c
diff -r1.19 -r1.20 src/sys/arch/hp700/dev/sti_sgc.c
diff -r1.12 -r1.13 src/sys/dev/ic/sti.c
diff -r1.4 -r1.5 src/sys/dev/ic/stireg.h
diff -r1.5 -r1.6 src/sys/dev/ic/stivar.h
diff -r1.331 -r1.332 src/sys/dev/pci/files.pci
diff -r0 -r1.1 src/sys/dev/pci/sti_pci.c

cvs diff -r1.1 -r1.2 src/share/man/man4/sti.4 (expand / switch to unified diff)

--- src/share/man/man4/sti.4 2004/09/22 16:38:26 1.1
+++ src/share/man/man4/sti.4 2010/11/09 12:24:47 1.2
@@ -1,82 +1,83 @@ @@ -1,82 +1,83 @@
1.\" $NetBSD: sti.4,v 1.1 2004/09/22 16:38:26 jkunz Exp $ 1.\" $NetBSD: sti.4,v 1.2 2010/11/09 12:24:47 skrll Exp $
2.\" $OpenBSD: sti.4,v 1.14 2004/06/08 02:54:53 mickey Exp $ 2.\" $OpenBSD: sti.4,v 1.19 2007/05/31 19:19:52 jmc Exp $
3.\" 3.\"
4.\" Copyright (c) 2001 Michael Shalayeff 4.\" Copyright (c) 2001 Michael Shalayeff
5.\" All rights reserved. 5.\" All rights reserved.
6.\" 6.\"
7.\" Redistribution and use in source and binary forms, with or without 7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions 8.\" modification, are permitted provided that the following conditions
9.\" are met: 9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright 10.\" 1. Redistributions of source code must retain the above copyright
11.\" notice, this list of conditions and the following disclaimer. 11.\" notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\" notice, this list of conditions and the following disclaimer in the 13.\" notice, this list of conditions and the following disclaimer in the
14.\" documentation and/or other materials provided with the distribution. 14.\" documentation and/or other materials provided with the distribution.
15.\" 15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19.\" IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 19.\" IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22.\" SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 25.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26.\" THE POSSIBILITY OF SUCH DAMAGE. 26.\" THE POSSIBILITY OF SUCH DAMAGE.
27.\" 27.\"
28.Dd May 11, 2001 28.Dd November 9, 2010
29.Dt STI 4 29.Dt STI 4
30.Os 30.Os
31.Sh NAME 31.Sh NAME
32.Nm sti 32.Nm sti
33.Nd HP Standard Text Interface 33.Nd HP Standard Text Interface
34.Sh SYNOPSIS 34.Sh SYNOPSIS
35.Cd "sti* at mainbus0 irq ?" 35.Cd "sti* at mainbus0"
36.Cd "sti* at phantomas0 irq ?" 36.Cd "sti* at phantomas?"
37.\" .Cd "sti* at pci? device ? function ?" 37.Cd "sti* at pci?"
38.Cd "wsdisplay* at sti? console ?" 38.Cd "wsdisplay* at sti?"
39.Sh DESCRIPTION 39.Sh DESCRIPTION
40The 40The
41.Nm 41.Nm
42was created by HP to provide uniform frame-buffer access operations 42was created by HP to provide uniform frame-buffer access operations
43for their 9000/300 and 9000/700 series of workstations. 43for their 9000/300 and 9000/700 series of workstations.
44.Pp 44.Pp
45The following models are supported 45The following models are supported
46(though not all features or frame buffer depths may be available): 46(though not all features or frame buffer depths may be available):
47.Bl -column "Visualize FX10pro" "Bits" "Mem" "3D" "machines" -offset left 47.Bl -column "Visualize FX10pro" "Bits" "Mem" "3D" "machines" -offset left
48.It "Model" Ta "Bits" Ta "Mem" Ta "3D" Ta "Machines/Cards" 48.It "Model" Ta "Bits" Ta "Mem" Ta "3D" Ta "Machines/Cards"
 49.It "EVRX" Ta "8" Ta "2" Ta "" Ta "HP9000/425e"
49.\" .It "Timber" Ta "8" Ta "2" Ta "" Ta "HP9000/705/710" 50.\" .It "Timber" Ta "8" Ta "2" Ta "" Ta "HP9000/705/710"
50.It "GRX" Ta "8g" Ta "2" Ta "" Ta "SGC" 51.It "GRX" Ta "8g" Ta "2" Ta "" Ta "SGC"
51.It "CRX" Ta "8" Ta "2" Ta "" Ta "SGC" 52.It "CRX" Ta "8" Ta "2" Ta "" Ta "SGC"
52.It "Tomcat" Ta "8" Ta "2" Ta "" Ta "SGC" 53.It "Tomcat" Ta "8" Ta "2" Ta "" Ta "SGC"
53.It "Stinger" Ta "8" Ta "2" Ta "" Ta "HP9000/7[12]5/74[257]i" 54.It "Stinger" Ta "8" Ta "2" Ta "" Ta "HP9000/7[12]5/74[257]i"
54.It "Artist" Ta "8" Ta "2" Ta "" Ta "HP9000/712/7[12]5/74[38]i" 55.It "Artist" Ta "8" Ta "2" Ta "" Ta "HP9000/712/7[12]5/74[38]i"
55.It "CRX-24" Ta "24" Ta "16" Ta "" Ta "SGC" 56.It "CRX-24" Ta "24" Ta "16" Ta "" Ta "SGC"
56.\" .It "CRX-24Z" Ta "24" Ta "16" Ta "y" Ta "SGC" 57.\" .It "CRX-24Z" Ta "24" Ta "16" Ta "y" Ta "SGC"
57.\" .It "CRX-48Z" Ta "24" Ta "16" Ta "y" Ta "SGC/GSC" 58.\" .It "CRX-48Z" Ta "24" Ta "16" Ta "y" Ta "SGC/GSC"
58.It "HCRX-8" Ta "8" Ta "2" Ta "" Ta "GSC" 59.It "HCRX-8" Ta "8" Ta "2" Ta "" Ta "GSC"
59.\" .It "HCRX-8Z" Ta "8" Ta "2" Ta "y" Ta "GSC" 60.\" .It "HCRX-8Z" Ta "8" Ta "2" Ta "y" Ta "GSC"
60.It "HCRX-24" Ta "24" Ta "16" Ta "" Ta "GSC" 61.It "HCRX-24" Ta "24" Ta "16" Ta "" Ta "GSC"
61.\" .It "HCRX-24Z" Ta "24" Ta "16" Ta "y" Ta "GSC" 62.\" .It "HCRX-24Z" Ta "24" Ta "16" Ta "y" Ta "GSC"
62.\" .It "Visualize 8" Ta "8" Ta "2" Ta "y" Ta "GSC" 63.\" .It "Visualize 8" Ta "8" Ta "2" Ta "y" Ta "GSC"
63.It "Visualize EG" Ta "16" Ta "2" Ta "" Ta "HP B/C-class, GSC/PCI" 64.It "Visualize EG" Ta "16" Ta "2" Ta "" Ta "HP B/C-class, GSC/PCI"
64.\" .It "Visualize 24" Ta "24" Ta "16" Ta "y" Ta "GSC" 65.\" .It "Visualize 24" Ta "24" Ta "16" Ta "y" Ta "GSC"
65.\" .It "Visualize 48" Ta "24" Ta "16" Ta "y" Ta "GSC" 66.\" .It "Visualize 48" Ta "24" Ta "16" Ta "y" Ta "GSC"
66.\" .It "Visualize 48XP" Ta "24" Ta "16" Ta "y" Ta "GSC" 67.\" .It "Visualize 48XP" Ta "24" Ta "16" Ta "y" Ta "GSC"
67.\" .It "Visualize FXE" Ta "24" Ta "24" Ta "y" Ta "PCI 32/66" 68.It "Visualize FXE" Ta "24" Ta "24" Ta "y" Ta "PCI 32/66"
68.\" .It "Visualize FX2" Ta "24" Ta "24" Ta "y" Ta "PCI 64/66" 69.It "Visualize FX2" Ta "24" Ta "24" Ta "y" Ta "PCI 64/66"
69.\" .It "Visualize FX4/FX6" Ta "24" Ta "32" Ta "y" Ta "PCI 64/66" 70.It "Visualize FX4/FX6" Ta "24" Ta "32" Ta "y" Ta "PCI 64/66"
70.\" .It "Visualize FX5pro" Ta "24" Ta "64" Ta "y" Ta "PCI 64/66" 71.\" .It "Visualize FX5pro" Ta "24" Ta "64" Ta "y" Ta "PCI 64/66"
71.\" .It "Visualize FX10pro" Ta "24" Ta "128" Ta "y" Ta "PCI 64/66" 72.\" .It "Visualize FX10pro" Ta "24" Ta "128" Ta "y" Ta "PCI 64/66"
72.El 73.El
73.Pp 74.Pp
74Implementation consists of a set of functions burnt in to the PROM 75Implementation consists of a set of functions burnt in to the PROM
75on the card and providing the following set of functions (see below 76on the card and providing the following set of functions (see below
76for PROM revision history on functions supported by particular PROM 77for PROM revision history on functions supported by particular PROM
77revision): 78revision):
78.Pp 79.Pp
79.Bl -bullet -compact 80.Bl -bullet -compact
80.It 81.It
81Initialize graphics. 82Initialize graphics.
82.It 83.It

cvs diff -r1.102 -r1.103 src/sys/arch/hp700/conf/Attic/GENERIC (expand / switch to unified diff)

--- src/sys/arch/hp700/conf/Attic/GENERIC 2010/08/17 00:02:28 1.102
+++ src/sys/arch/hp700/conf/Attic/GENERIC 2010/11/09 12:24:47 1.103
@@ -1,39 +1,39 @@ @@ -1,39 +1,39 @@
1# $NetBSD: GENERIC,v 1.102 2010/08/17 00:02:28 dyoung Exp $ 1# $NetBSD: GENERIC,v 1.103 2010/11/09 12:24:47 skrll Exp $
2# 2#
3# GENERIC machine description file 3# GENERIC machine description file
4# 4#
5# This machine description file is used to generate the default NetBSD 5# This machine description file is used to generate the default NetBSD
6# kernel. The generic kernel does not include all options, subsystems 6# kernel. The generic kernel does not include all options, subsystems
7# and device drivers, but should be useful for most applications. 7# and device drivers, but should be useful for most applications.
8# 8#
9# The machine description file can be customised for your specific 9# The machine description file can be customised for your specific
10# machine to reduce the kernel size and improve its performance. 10# machine to reduce the kernel size and improve its performance.
11# 11#
12# For further information on compiling NetBSD kernels, see the config(8) 12# For further information on compiling NetBSD kernels, see the config(8)
13# man page. 13# man page.
14# 14#
15# For further information on hardware support for this architecture, see 15# For further information on hardware support for this architecture, see
16# the intro(4) man page. For further information about kernel options 16# the intro(4) man page. For further information about kernel options
17# for this architecture, see the options(4) man page. For an explanation 17# for this architecture, see the options(4) man page. For an explanation
18# of each device driver in this file see the section 4 man page for the 18# of each device driver in this file see the section 4 man page for the
19# device. 19# device.
20 20
21include "arch/hp700/conf/std.hp700" 21include "arch/hp700/conf/std.hp700"
22 22
23options INCLUDE_CONFIG_FILE # embed config file in kernel binary 23options INCLUDE_CONFIG_FILE # embed config file in kernel binary
24options SYSCTL_INCLUDE_DESCR # Include sysctl descriptions in kernel 24options SYSCTL_INCLUDE_DESCR # Include sysctl descriptions in kernel
25 25
26#ident "GENERIC-$Revision: 1.102 $" 26#ident "GENERIC-$Revision: 1.103 $"
27 27
28maxusers 32 # estimated number of users 28maxusers 32 # estimated number of users
29 29
30# CPU support. At least one is REQUIRED. 30# CPU support. At least one is REQUIRED.
31options HP7000_CPU # PCX, PCX-S 31options HP7000_CPU # PCX, PCX-S
32options HP7100_CPU,HP7150_CPU # PCX-T 32options HP7100_CPU,HP7150_CPU # PCX-T
33options HP7100LC_CPU # PCX-L 33options HP7100LC_CPU # PCX-L
34options HP7200_CPU,HP7250_CPU # PCX-T' 34options HP7200_CPU,HP7250_CPU # PCX-T'
35options HP7300LC_CPU # PCX-L2 35options HP7300LC_CPU # PCX-L2
36options HP8000_CPU # PCX-U (in 32bit mode) 36options HP8000_CPU # PCX-U (in 32bit mode)
37options HP8200_CPU # PCX-V/U+ (in 32bit mode) 37options HP8200_CPU # PCX-V/U+ (in 32bit mode)
38options HP8500_CPU # PCX-W (in 32bit mode) 38options HP8500_CPU # PCX-W (in 32bit mode)
39options HP8600_CPU # PCX-W+ (in 32bit mode) 39options HP8600_CPU # PCX-W+ (in 32bit mode)
@@ -221,26 +221,28 @@ mem* at mainbus0 # /dev/*mem and memory @@ -221,26 +221,28 @@ mem* at mainbus0 # /dev/*mem and memory
221 221
222# Coprocessor/SFU Support 222# Coprocessor/SFU Support
223#fpu* at mainbus0 # HP PA-RISC fpu (iv N/A) 223#fpu* at mainbus0 # HP PA-RISC fpu (iv N/A)
224#pmu* at mainbus0 # HP PA-RISC perfomance monitor unit (iv 29) 224#pmu* at mainbus0 # HP PA-RISC perfomance monitor unit (iv 29)
225 225
226# Miscellaneous 226# Miscellaneous
227pdc0 at mainbus0 # PDC/IODC wrapper for boot console 227pdc0 at mainbus0 # PDC/IODC wrapper for boot console
228power0 at mainbus0 # power/fail manager 228power0 at mainbus0 # power/fail manager
229lcd0 at mainbus0 # LCD 229lcd0 at mainbus0 # LCD
230 230
231# STI graphics 231# STI graphics
232sti* at mainbus0 # [H]CRX-{8,24,48}[Z] and Visualize graphics 232sti* at mainbus0 # [H]CRX-{8,24,48}[Z] and Visualize graphics
233sti* at phantomas? # [H]CRX-{8,24,48}[Z] and Visualize graphics 233sti* at phantomas? # [H]CRX-{8,24,48}[Z] and Visualize graphics
 234#sti* at uturn?
 235sti* at pci? # EG-PCI, FX*
234 236
235# Basic Bus Support 237# Basic Bus Support
236lasi* at mainbus0 # LASI host adapter ( LSI PN??? ) 238lasi* at mainbus0 # LASI host adapter ( LSI PN??? )
237asp* at mainbus0 # this one comes w/ Viper and leds 239asp* at mainbus0 # this one comes w/ Viper and leds
238wax* at mainbus0 # Wax GSC to GSC Bus Adapter 240wax* at mainbus0 # Wax GSC to GSC Bus Adapter
239mongoose* at mainbus0 irq 17 # EISA Bus Adapter ( i82350 or TI??? ) 241mongoose* at mainbus0 irq 17 # EISA Bus Adapter ( i82350 or TI??? )
240#vmeb* at mainbus0 irq ? # VME bus adapter 242#vmeb* at mainbus0 irq ? # VME bus adapter
241phantomas* at mainbus0 # Phantom PseudoBC GSC+ Port 243phantomas* at mainbus0 # Phantom PseudoBC GSC+ Port
242 244
243lasi* at phantomas? # LASI on [ABCJ?]* 245lasi* at phantomas? # LASI on [ABCJ?]*
244dino* at phantomas? # PCI bus bridge 246dino* at phantomas? # PCI bus bridge
245wax* at phantomas? # Wax GSC to GSC Bus Adapter 247wax* at phantomas? # Wax GSC to GSC Bus Adapter
246 248

cvs diff -r1.23 -r1.24 src/sys/arch/hp700/conf/Attic/files.hp700 (expand / switch to unified diff)

--- src/sys/arch/hp700/conf/Attic/files.hp700 2010/06/01 10:20:28 1.23
+++ src/sys/arch/hp700/conf/Attic/files.hp700 2010/11/09 12:24:47 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: files.hp700,v 1.23 2010/06/01 10:20:28 skrll Exp $ 1# $NetBSD: files.hp700,v 1.24 2010/11/09 12:24:47 skrll Exp $
2# 2#
3# $OpenBSD: files.hp700,v 1.31 2001/06/26 02:41:25 mickey Exp $ 3# $OpenBSD: files.hp700,v 1.31 2001/06/26 02:41:25 mickey Exp $
4# 4#
5# hppa-specific configuration info 5# hppa-specific configuration info
6 6
7# maxpartitions must be the first item in files.${ARCH} 7# maxpartitions must be the first item in files.${ARCH}
8maxpartitions 16 8maxpartitions 16
9 9
10maxusers 2 8 64 10maxusers 2 8 64
11 11
12# Status LEDs 12# Status LEDs
13defflag USELEDS 13defflag USELEDS
14 14
@@ -140,27 +140,28 @@ attach dino at gedoens @@ -140,27 +140,28 @@ attach dino at gedoens
140file arch/hp700/dev/dino.c dino 140file arch/hp700/dev/dino.c dino
141 141
142attach com at dino with com_dino 142attach com at dino with com_dino
143file arch/hp700/dev/com_dino.c com_dino 143file arch/hp700/dev/com_dino.c com_dino
144 144
145# Elroy, Ropes to PCI Bridge. Supports 4X PCI and dual address cycle. 145# Elroy, Ropes to PCI Bridge. Supports 4X PCI and dual address cycle.
146# Mercury; QuickSilver is an AGP also 146# Mercury; QuickSilver is an AGP also
147device elroy: pcibus 147device elroy: pcibus
148attach elroy at gedoens 148attach elroy at gedoens
149file arch/hp700/dev/elroy.c elroy 149file arch/hp700/dev/elroy.c elroy
150file arch/hp700/dev/apic.c elroy 150file arch/hp700/dev/apic.c elroy
151 151
152attach sti at gedoens with sti_gedoens 152attach sti at gedoens with sti_gedoens
153file arch/hp700/dev/sti_sgc.c sti_gedoens 153file arch/hp700/dev/sti_sgc.c sti_gedoens
 154file arch/hp700/dev/sti_pci_machdep.c sti_pci
154 155
155attach siop at gedoens with siop_gedoens 156attach siop at gedoens with siop_gedoens
156file arch/hp700/dev/siop_sgc.c siop_gedoens 157file arch/hp700/dev/siop_sgc.c siop_gedoens
157 158
158device ssio {[irq = -1]} 159device ssio {[irq = -1]}
159attach ssio at pci 160attach ssio at pci
160file arch/hp700/dev/ssio.c ssio 161file arch/hp700/dev/ssio.c ssio
161 162
162attach com at ssio with com_ssio 163attach com at ssio with com_ssio
163file arch/hp700/dev/com_ssio.c com_ssio 164file arch/hp700/dev/com_ssio.c com_ssio
164 165
165attach lpt at ssio with lpt_ssio 166attach lpt at ssio with lpt_ssio
166file arch/hp700/dev/lpt_ssio.c lpt_ssio 167file arch/hp700/dev/lpt_ssio.c lpt_ssio

File Added: src/sys/arch/hp700/dev/Attic/sti_pci_machdep.c
/*	$NetBSD: sti_pci_machdep.c,v 1.1 2010/11/09 12:24:47 skrll Exp $	*/

/*	$OpenBSD: sti_pci_machdep.c,v 1.2 2009/04/10 17:11:27 miod Exp $	*/

/*
 * Copyright (c) 2007, 2009 Miodrag Vallat.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice, this permission notice, and the disclaimer below
 * appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <machine/iomod.h>
#include <machine/autoconf.h>

#include <dev/pci/pcivar.h>

#include <hp700/hp700/machdep.h>

int	sti_pci_is_console(struct pci_attach_args *, bus_addr_t *);

int
sti_pci_is_console(struct pci_attach_args *paa, bus_addr_t *bases)
{
	hppa_hpa_t consaddr;
	uint32_t cf;
	int pagezero_cookie;
	int bar;
	int rc;

	KASSERT(paa != NULL);

	pagezero_cookie = hp700_pagezero_map();
	consaddr = (hppa_hpa_t)PAGE0->mem_cons.pz_hpa;
	hp700_pagezero_unmap(pagezero_cookie);
	/*
	 * PAGE0 console information will point to one of our BARs,
	 * but depending on the particular sti model, this might not
	 * be the BAR mapping the rom (region #0).
	 *
	 * For example, on Visualize FXe, regions #0, #2 and #3 are
	 * mapped by BAR 0x18, while region #1 is mapped by BAR 0x10,
	 * which matches PAGE0 console address.
	 *
	 * Rather than trying to be smart, reread the region->BAR array
	 * again, and compare the BAR mapping region #1 against PAGE0
	 * values, we simply try all the valid BARs; if any of them
	 * matches what PAGE0 says, then we are the console, and it
	 * doesn't matter which BAR matched.
	 */
	for (bar = PCI_MAPREG_START; bar <= PCI_MAPREG_PPB_END; ) {
		bus_addr_t addr;
		bus_size_t size;

		cf = pci_conf_read(paa->pa_pc, paa->pa_tag, bar);

		rc = pci_mapreg_info(paa->pa_pc, paa->pa_tag, bar,
		    PCI_MAPREG_TYPE(cf), &addr, &size, NULL);

		if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_IO) {
			bar += 4;
		} else {
			if (PCI_MAPREG_MEM_TYPE(cf) ==
			    PCI_MAPREG_MEM_TYPE_64BIT)
				bar += 8;
			else
				bar += 4;
		}

		if (rc == 0 && (hppa_hpa_t)addr == consaddr)
			return 1;
	}

	return 0;
}

cvs diff -r1.19 -r1.20 src/sys/arch/hp700/dev/Attic/sti_sgc.c (expand / switch to unified diff)

--- src/sys/arch/hp700/dev/Attic/sti_sgc.c 2010/03/06 19:36:33 1.19
+++ src/sys/arch/hp700/dev/Attic/sti_sgc.c 2010/11/09 12:24:47 1.20
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: sti_sgc.c,v 1.19 2010/03/06 19:36:33 skrll Exp $ */ 1/* $NetBSD: sti_sgc.c,v 1.20 2010/11/09 12:24:47 skrll Exp $ */
2 2
3/* $OpenBSD: sti_sgc.c,v 1.21 2003/12/22 23:39:06 mickey Exp $ */ 3/* $OpenBSD: sti_sgc.c,v 1.38 2009/02/06 22:51:04 miod Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 2000-2003 Michael Shalayeff 6 * Copyright (c) 2000-2003 Michael Shalayeff
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
@@ -25,239 +25,262 @@ @@ -25,239 +25,262 @@
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE. 28 * THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30/* 30/*
31 * These cards has to be known to work so far: 31 * These cards has to be known to work so far:
32 * - HPA1991AGrayscale rev 0.02 (705/35) (byte-wide) 32 * - HPA1991AGrayscale rev 0.02 (705/35) (byte-wide)
33 * - HPA1991AC19 rev 0.02 (715/33) (byte-wide) 33 * - HPA1991AC19 rev 0.02 (715/33) (byte-wide)
34 * - HPA208LC1280 rev 8.04 (712/80) just works 34 * - HPA208LC1280 rev 8.04 (712/80) just works
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.19 2010/03/06 19:36:33 skrll Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.20 2010/11/09 12:24:47 skrll Exp $");
39 39
40#include "opt_cputype.h" 40#include "opt_cputype.h"
41 41
42#include <sys/param.h> 42#include <sys/param.h>
43#include <sys/systm.h> 43#include <sys/systm.h>
44#include <sys/device.h> 44#include <sys/device.h>
45 45
46#include <uvm/uvm.h> 46#include <uvm/uvm.h>
47 47
48#include <machine/bus.h> 48#include <machine/bus.h>
49#include <machine/cpu.h> 49#include <machine/cpu.h>
50#include <machine/iomod.h> 50#include <machine/iomod.h>
51#include <machine/autoconf.h> 51#include <machine/autoconf.h>
52 52
53#include <dev/wscons/wsdisplayvar.h> 53#include <dev/wscons/wsdisplayvar.h>
54#include <dev/wscons/wsconsio.h> 54#include <dev/wscons/wsconsio.h>
55 55
56#include <dev/ic/stireg.h> 56#include <dev/ic/stireg.h>
57#include <dev/ic/stivar.h> 57#include <dev/ic/stivar.h>
58 58
59#include <hp700/dev/cpudevs.h> 59#include <hp700/dev/cpudevs.h>
60#include <hp700/hp700/machdep.h> 60#include <hp700/hp700/machdep.h>
61 61
 62#ifdef STIDEBUG
 63#define DPRINTF(s) do { \
 64 if (stidebug) \
 65 printf s; \
 66} while(0)
 67
 68extern int stidebug;
 69#else
 70#define DPRINTF(s) /* */
 71#endif
 72
62#define STI_ROMSIZE (sizeof(struct sti_dd) * 4) 73#define STI_ROMSIZE (sizeof(struct sti_dd) * 4)
63#define STI_ID_FDDI 0x280b31af /* Medusa FDDI ROM id */ 74#define STI_ID_FDDI 0x280b31af /* Medusa FDDI ROM id */
64 75
65/* gecko optional graphics */ 76/* gecko optional graphics */
66#define STI_GOPT1_REV 0x17 77#define STI_GOPT1_REV 0x17
67#define STI_GOPT2_REV 0x70 78#define STI_GOPT2_REV 0x70
68#define STI_GOPT3_REV 0xd0 79#define STI_GOPT3_REV 0xd0
69#define STI_GOPT4_REV 0x00 80#define STI_GOPT4_REV 0x00
70#define STI_GOPT5_REV 0x20 81#define STI_GOPT5_REV 0x20
71#define STI_GOPT6_REV 0x40 82#define STI_GOPT6_REV 0x40
72#define STI_GOPT7_REV 0x30 83#define STI_GOPT7_REV 0x30
73 84
74/* internal EG */ 85const char sti_sgc_opt[] = {
75#define STI_INEG_REV 0x60 86 STI_GOPT1_REV,
76#define STI_INEG_PROM 0xf0011000 87 STI_GOPT2_REV,
 88 STI_GOPT3_REV,
 89 STI_GOPT4_REV,
 90 STI_GOPT5_REV,
 91 STI_GOPT6_REV,
 92 STI_GOPT7_REV
 93};
77 94
78int sti_sgc_probe(device_t, cfdata_t, void *); 95int sti_sgc_probe(device_t, cfdata_t, void *);
79void sti_sgc_attach(device_t, device_t, void *); 96void sti_sgc_attach(device_t, device_t, void *);
80 97
81CFATTACH_DECL_NEW(sti_gedoens, sizeof(struct sti_softc), sti_sgc_probe, sti_sgc_attach, 98void sti_sgc_end_attach(device_t);
82 NULL, NULL); 99
 100extern struct cfdriver sti_cd;
 101
 102CFATTACH_DECL_NEW(sti_gedoens, sizeof(struct sti_softc), sti_sgc_probe,
 103 sti_sgc_attach, NULL, NULL);
83 104
84paddr_t sti_sgc_getrom(struct confargs *); 105paddr_t sti_sgc_getrom(struct confargs *);
85 106
86/* 107/*
87 * Locate STI ROM. 108 * Locate STI ROM.
88 * On some machines it may not be part of the HPA space. 109 * On some machines it may not be part of the HPA space.
89 */ 110 */
90paddr_t 111paddr_t
91sti_sgc_getrom(struct confargs *ca) 112sti_sgc_getrom(struct confargs *ca)
92{ 113{
93 paddr_t rom; 114 paddr_t rom;
94 int pagezero_cookie; 115 int pagezero_cookie;
95 116
96 rom = ca->ca_hpa; 117 pagezero_cookie = hp700_pagezero_map();
 118 rom = PAGE0->pd_resv2[1];
 119 hp700_pagezero_unmap(pagezero_cookie);
97 120
98 if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC) { 121 if (ca->ca_type.iodc_sv_model == HPPA_FIO_GSGC) {
99 return rom; 122 int i;
 123 for (i = sizeof(sti_sgc_opt); i--; )
 124 if (sti_sgc_opt[i] == ca->ca_type.iodc_revision)
 125 break;
 126 if (i < 0)
 127 rom = 0;
100 } 128 }
101 129
102 switch (ca->ca_type.iodc_revision) { 130 if (rom < HPPA_IOBEGIN) {
103 case STI_GOPT1_REV: 131 if (ca->ca_naddrs > 0)
104 case STI_GOPT2_REV: 132 rom = ca->ca_addrs[0].addr;
105 case STI_GOPT3_REV: 133 else
106 case STI_GOPT4_REV: 134 rom = ca->ca_hpa;
107 case STI_GOPT5_REV: 
108 case STI_GOPT6_REV: 
109 case STI_GOPT7_REV: 
110 /* these share the onboard's prom */ 
111 pagezero_cookie = hp700_pagezero_map(); 
112 rom = PAGE0->pd_resv2[1]; 
113 hp700_pagezero_unmap(pagezero_cookie); 
114 break; 
115 
116 case STI_INEG_REV: 
117 rom = STI_INEG_PROM; 
118 break; 
119 } 135 }
 136
120 return rom; 137 return rom;
121} 138}
122 139
123int 140int
124sti_sgc_probe(device_t parent, cfdata_t cf, void *aux) 141sti_sgc_probe(device_t parent, cfdata_t cf, void *aux)
125{ 142{
126 struct confargs *ca = aux; 143 struct confargs *ca = aux;
127 bus_space_handle_t romh; 144 bus_space_handle_t romh;
128 paddr_t rom; 145 paddr_t rom;
129 uint32_t id, romend; 146 uint32_t id, romend;
130 u_char devtype; 147 u_char devtype;
131 int rv = 0, romunmapped = 0; 148 int rv = 0, romunmapped = 0;
132 149
 150 /* due to the graphic nature of this program do probe only one */
 151 if (cf->cf_unit > sti_cd.cd_ndevs)
 152 return 0;
 153
133 if (ca->ca_type.iodc_type != HPPA_TYPE_FIO) 154 if (ca->ca_type.iodc_type != HPPA_TYPE_FIO)
134 return (0); 155 return 0;
135 156
136 /* these need futher checking for the graphics id */ 157 /* these need further checking for the graphics id */
137 if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC && 158 if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC &&
138 ca->ca_type.iodc_sv_model != HPPA_FIO_SGC) 159 ca->ca_type.iodc_sv_model != HPPA_FIO_SGC)
139 return 0; 160 return 0;
140 161
141 rom = sti_sgc_getrom(ca); 162 rom = sti_sgc_getrom(ca);
142#ifdef STIDEBUG 163 DPRINTF(("%s: hpa=%x, rom=%x\n", __func__, (uint)ca->ca_hpa,
143 printf ("sti: hpa=%x, rom=%x\n", (uint)ca->ca_hpa, (uint)rom); 164 (uint)rom));
144#endif 
145 165
146 /* if it does not map, probably part of the lasi space */ 166 /* if it does not map, probably part of the lasi space */
147 if ((rv = bus_space_map(ca->ca_iot, rom, STI_ROMSIZE, 0, &romh))) { 167 if ((rv = bus_space_map(ca->ca_iot, rom, STI_ROMSIZE, 0, &romh))) {
148#ifdef STIDEBUG 168 DPRINTF(("%s: can't map rom space (%d)\n", __func__, rv));
149 printf ("sti: can't map rom space (%d)\n", rv); 169
150#endif 
151 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) { 170 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) {
152 romh = rom; 171 romh = rom;
153 romunmapped++; 172 romunmapped++;
154 } else { 173 } else {
155 /* in this case nobody has no freaking idea */ 174 /* in this case nobody has no freaking idea */
156 return 0; 175 return 0;
157 } 176 }
158 } 177 }
159 178
160 devtype = bus_space_read_1(ca->ca_iot, romh, 3); 179 devtype = bus_space_read_1(ca->ca_iot, romh, 3);
161 180
162#ifdef STIDEBUG 181 DPRINTF(("%s: devtype=%d\n", __func__, devtype));
163 printf("sti: devtype=%d\n", devtype); 
164#endif 
165 rv = 1; 182 rv = 1;
166 switch (devtype) { 183 switch (devtype) {
167 case STI_DEVTYPE4: 184 case STI_DEVTYPE4:
168 id = bus_space_read_4(ca->ca_iot, romh, STI_DEV4_DD_GRID); 185 id = bus_space_read_4(ca->ca_iot, romh, STI_DEV4_DD_GRID);
169 romend = bus_space_read_4(ca->ca_iot, romh, STI_DEV4_DD_ROMEND); 
170 break; 186 break;
171 case STI_DEVTYPE1: 187 case STI_DEVTYPE1:
172 id = (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID 188 id = (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
173 + 3) << 24) | 189 + 3) << 24) |
174 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID 190 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
175 + 7) << 16) | 191 + 7) << 16) |
176 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID 192 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
177 + 11) << 8) | 193 + 11) << 8) |
178 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID 194 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
179 + 15)); 195 + 15));
180 romend = (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND 
181 + 3) << 24) | 
182 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND 
183 + 7) << 16) | 
184 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND 
185 + 11) << 8) | 
186 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND 
187 + 15)); 
188 break; 196 break;
189 default: 197 default:
190#ifdef STIDEBUG 198 DPRINTF(("%s: unknown type (%x)\n", __func__, devtype));
191 printf("sti: unknown type (%x)\n", devtype); 
192#endif 
193 rv = 0; 199 rv = 0;
194 romend = 0; 200 romend = 0;
195 } 201 }
196 202
197 if (rv && 203 if (rv &&
198 ca->ca_type.iodc_sv_model == HPPA_FIO_SGC && id == STI_ID_FDDI) { 204 ca->ca_type.iodc_sv_model == HPPA_FIO_SGC && id == STI_ID_FDDI) {
199#ifdef STIDEBUG 205 DPRINTF(("%s: not a graphics device\n", __func__));
200 printf("sti: not a graphics device\n"); 
201#endif 
202 rv = 0; 206 rv = 0;
203 } 207 }
204 208
205 if (ca->ca_naddrs >= sizeof(ca->ca_addrs) / sizeof(ca->ca_addrs[0])) { 209 if (ca->ca_naddrs >= sizeof(ca->ca_addrs) / sizeof(ca->ca_addrs[0])) {
206 printf("sti: address list overflow\n"); 210 printf("sti: address list overflow\n");
207 return (0); 211 return 0;
208 } 212 }
209 213
210 ca->ca_addrs[ca->ca_naddrs].addr = rom; 214 ca->ca_addrs[ca->ca_naddrs].addr = rom;
211 ca->ca_addrs[ca->ca_naddrs].size = round_page(romend); 215 ca->ca_addrs[ca->ca_naddrs].size = sti_rom_size(ca->ca_iot, romh);
212 ca->ca_naddrs++; 216 ca->ca_naddrs++;
213 217
214 if (!romunmapped) 218 if (!romunmapped)
215 bus_space_unmap(ca->ca_iot, romh, STI_ROMSIZE); 219 bus_space_unmap(ca->ca_iot, romh, STI_ROMSIZE);
216 return (rv); 220 return rv;
217} 221}
218 222
219void 223void
220sti_sgc_attach(device_t parent, device_t self, void *aux) 224sti_sgc_attach(device_t parent, device_t self, void *aux)
221{ 225{
222 struct sti_softc *sc = device_private(self); 226 struct sti_softc *sc = device_private(self);
223 struct confargs *ca = aux; 227 struct confargs *ca = aux;
 228 bus_space_handle_t romh;
 229 hppa_hpa_t consaddr;
 230 int pagezero_cookie;
224 paddr_t rom; 231 paddr_t rom;
225 uint32_t romlen; 232 uint32_t romlen;
226 int rv; 233 int rv;
227 int pagezero_cookie; 234 int i;
228 235
229 pagezero_cookie = hp700_pagezero_map(); 236 pagezero_cookie = hp700_pagezero_map();
 237 consaddr = (hppa_hpa_t)PAGE0->mem_cons.pz_hpa;
 238 hp700_pagezero_unmap(pagezero_cookie);
 239
230 sc->sc_dev = self; 240 sc->sc_dev = self;
231 sc->memt = sc->iot = ca->ca_iot; 241 sc->sc_enable_rom = NULL;
232 sc->base = ca->ca_hpa; 242 sc->sc_disable_rom = NULL;
233 243
234 /* we stashed rom addr/len into the last slot during probe */ 244 /* we stashed rom addr/len into the last slot during probe */
235 rom = ca->ca_addrs[ca->ca_naddrs - 1].addr; 245 rom = ca->ca_addrs[ca->ca_naddrs - 1].addr;
236 romlen = ca->ca_addrs[ca->ca_naddrs - 1].size; 246 romlen = ca->ca_addrs[ca->ca_naddrs - 1].size;
237 if ((rv = bus_space_map(ca->ca_iot, rom, romlen, 0, &sc->romh))) { 247
 248 if ((rv = bus_space_map(ca->ca_iot, rom, romlen, 0, &romh))) {
238 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) 249 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN)
239 sc->romh = rom; 250 romh = rom;
240 else { 251 else {
241 aprint_error(": can't map rom space (%d)\n", rv); 252 aprint_error(": can't map rom space (%d)\n", rv);
242 return; 253 return;
243 } 254 }
244 } 255 }
245 256
 257 sc->bases[0] = romh;
 258 for (i = 1; i < STI_REGION_MAX; i++)
 259 sc->bases[i] = ca->ca_hpa;
 260
246#ifdef HP7300LC_CPU 261#ifdef HP7300LC_CPU
247 /* 262 /*
248 * PCXL2: enable accel I/O for this space, see PCX-L2 ERS "ACCEL_IO". 263 * PCXL2: enable accel I/O for this space, see PCX-L2 ERS "ACCEL_IO".
249 * "pcxl2_ers.{ps,pdf}", (section / chapter . rel. page / abs. page) 264 * "pcxl2_ers.{ps,pdf}", (section / chapter . rel. page / abs. page)
250 * 8.7.4 / 8-12 / 92, 11.3.14 / 11-14 / 122 and 14.8 / 14-5 / 203. 265 * 8.7.4 / 8-12 / 92, 11.3.14 / 11-14 / 122 and 14.8 / 14-5 / 203.
251 */ 266 */
252 if (hppa_cpu_info->hci_cputype == hpcxl2 267 if (hppa_cpu_info->hci_cputype == hpcxl2
253 && ca->ca_hpa >= PCXL2_ACCEL_IO_START 268 && ca->ca_hpa >= PCXL2_ACCEL_IO_START
254 && ca->ca_hpa <= PCXL2_ACCEL_IO_END) 269 && ca->ca_hpa <= PCXL2_ACCEL_IO_END)
255 eaio_l2(PCXL2_ACCEL_IO_ADDR2MASK(ca->ca_hpa)); 270 eaio_l2(PCXL2_ACCEL_IO_ADDR2MASK(ca->ca_hpa));
256#endif /* HP7300LC_CPU */ 271#endif /* HP7300LC_CPU */
257 272
258 sc->sc_devtype = bus_space_read_1(sc->iot, sc->romh, 3); 273 if (ca->ca_hpa == consaddr)
259 if (ca->ca_hpa == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa) 
260 sc->sc_flags |= STI_CONSOLE; 274 sc->sc_flags |= STI_CONSOLE;
261 hp700_pagezero_unmap(pagezero_cookie); 275 if (sti_attach_common(sc, ca->ca_iot, ca->ca_iot, romh,
262 sti_attach_common(sc); 276 STI_CODEBASE_PA) == 0)
 277 config_interrupts(self, sti_sgc_end_attach);
 278}
 279
 280void
 281sti_sgc_end_attach(device_t dev)
 282{
 283 struct sti_softc *sc = device_private(dev);
 284
 285 sti_end_attach(sc);
263} 286}

cvs diff -r1.12 -r1.13 src/sys/dev/ic/sti.c (expand / switch to unified diff)

--- src/sys/dev/ic/sti.c 2010/11/01 06:41:50 1.12
+++ src/sys/dev/ic/sti.c 2010/11/09 12:24:48 1.13
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: sti.c,v 1.12 2010/11/01 06:41:50 skrll Exp $ */ 1/* $NetBSD: sti.c,v 1.13 2010/11/09 12:24:48 skrll Exp $ */
2 2
3/* $OpenBSD: sti.c,v 1.35 2003/12/16 06:07:13 mickey Exp $ */ 3/* $OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 2000-2003 Michael Shalayeff 6 * Copyright (c) 2000-2003 Michael Shalayeff
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
@@ -25,45 +25,59 @@ @@ -25,45 +25,59 @@
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE. 28 * THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30/* 30/*
31 * TODO: 31 * TODO:
32 * call sti procs asynchronously; 32 * call sti procs asynchronously;
33 * implement console scroll-back; 33 * implement console scroll-back;
34 * X11 support. 34 * X11 support.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.12 2010/11/01 06:41:50 skrll Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.13 2010/11/09 12:24:48 skrll Exp $");
39 39
40#include "wsdisplay.h" 40#include "wsdisplay.h"
41 41
42#include <sys/param.h> 42#include <sys/param.h>
43#include <sys/systm.h> 43#include <sys/systm.h>
44#include <sys/device.h> 44#include <sys/device.h>
45#include <sys/malloc.h> 45#include <sys/malloc.h>
46 46
47#include <uvm/uvm.h> 47#include <uvm/uvm.h>
48 48
49#include <sys/bus.h> 49#include <sys/bus.h>
50 50
51#include <dev/wscons/wsdisplayvar.h> 51#include <dev/wscons/wsdisplayvar.h>
52#include <dev/wscons/wsconsio.h> 52#include <dev/wscons/wsconsio.h>
53 53
54#include <dev/ic/stireg.h> 54#include <dev/ic/stireg.h>
55#include <dev/ic/stivar.h> 55#include <dev/ic/stivar.h>
56 56
 57#include "sti_pci.h"
 58
 59#ifdef STIDEBUG
 60
 61#define DPRINTF(s) do { \
 62 if (stidebug) \
 63 printf s; \
 64} while(0)
 65
 66int stidebug = 1;
 67#else
 68#define DPRINTF(s) /* */
 69#endif
 70
57void sti_cursor(void *, int, int, int); 71void sti_cursor(void *, int, int, int);
58int sti_mapchar(void *, int, u_int *); 72int sti_mapchar(void *, int, u_int *);
59void sti_putchar(void *, int, int, u_int, long); 73void sti_putchar(void *, int, int, u_int, long);
60void sti_copycols(void *, int, int, int, int); 74void sti_copycols(void *, int, int, int, int);
61void sti_erasecols(void *, int, int, int, long); 75void sti_erasecols(void *, int, int, int, long);
62void sti_copyrows(void *, int, int, int); 76void sti_copyrows(void *, int, int, int);
63void sti_eraserows(void *, int, int, long); 77void sti_eraserows(void *, int, int, long);
64int sti_alloc_attr(void *, int, int, int, long *); 78int sti_alloc_attr(void *, int, int, int, long *);
65 79
66struct wsdisplay_emulops sti_emulops = { 80struct wsdisplay_emulops sti_emulops = {
67 sti_cursor, 81 sti_cursor,
68 sti_mapchar, 82 sti_mapchar,
69 sti_putchar, 83 sti_putchar,
@@ -81,456 +95,827 @@ int sti_alloc_screen(void *, const struc @@ -81,456 +95,827 @@ int sti_alloc_screen(void *, const struc
81 void sti_free_screen(void *, void *); 95 void sti_free_screen(void *, void *);
82int sti_show_screen(void *, void *, int, void (*cb)(void *, int, int), void *); 96int sti_show_screen(void *, void *, int, void (*cb)(void *, int, int), void *);
83int sti_load_font(void *, void *, struct wsdisplay_font *); 97int sti_load_font(void *, void *, struct wsdisplay_font *);
84 98
85const struct wsdisplay_accessops sti_accessops = { 99const struct wsdisplay_accessops sti_accessops = {
86 sti_ioctl, 100 sti_ioctl,
87 sti_mmap, 101 sti_mmap,
88 sti_alloc_screen, 102 sti_alloc_screen,
89 sti_free_screen, 103 sti_free_screen,
90 sti_show_screen, 104 sti_show_screen,
91 sti_load_font 105 sti_load_font
92}; 106};
93 107
94struct wsscreen_descr sti_default_screen = { 108enum sti_bmove_funcs {
95 "default", 0, 0, 109 bmf_clear, bmf_copy, bmf_invert, bmf_underline
96 &sti_emulops, 
97 0, 0, 
98 WSSCREEN_REVERSE | WSSCREEN_UNDERLINE 
99}; 110};
100 111
101const struct wsscreen_descr *sti_default_scrlist[] = { 112int sti_init(struct sti_screen *, int);
102 &sti_default_screen 113#define STI_TEXTMODE 0x01
103}; 114#define STI_CLEARSCR 0x02
 115int sti_inqcfg(struct sti_screen *, struct sti_inqconfout *);
 116void sti_bmove(struct sti_screen *, int, int, int, int, int, int,
 117 enum sti_bmove_funcs);
 118int sti_setcment(struct sti_screen *, u_int, u_char, u_char, u_char);
 119
 120struct sti_screen *sti_attach_screen(struct sti_softc *, int);
 121void sti_describe_screen(struct sti_softc *, struct sti_screen *);
 122
 123int sti_fetchfonts(struct sti_screen *, struct sti_inqconfout *, uint32_t,
 124 u_int);
 125void sti_region_setup(struct sti_screen *);
 126int sti_rom_setup(struct sti_rom *, bus_space_tag_t, bus_space_tag_t,
 127 bus_space_handle_t, bus_addr_t *, u_int);
 128int sti_screen_setup(struct sti_screen *, int);
 129
 130#if NSTI_PCI > 0
 131#define STI_ENABLE_ROM(sc) \
 132do { \
 133 if ((sc) != NULL && (sc)->sc_enable_rom != NULL) \
 134 (*(sc)->sc_enable_rom)(sc); \
 135} while (0)
 136#define STI_DISABLE_ROM(sc) \
 137do { \
 138 if ((sc) != NULL && (sc)->sc_disable_rom != NULL) \
 139 (*(sc)->sc_disable_rom)(sc); \
 140} while (0)
 141#else
 142#define STI_ENABLE_ROM(sc) do { /* nothing */ } while (0)
 143#define STI_DISABLE_ROM(sc) do { /* nothing */ } while (0)
 144#endif
104 145
105struct wsscreen_list sti_default_screenlist = { 146/* Macros to read larger than 8 bit values from byte roms */
106 sizeof(sti_default_scrlist) / sizeof(sti_default_scrlist[0]), 147#define parseshort(o) \
107 sti_default_scrlist 148 ((bus_space_read_1(memt, romh, (o) + 3) << 8) | \
108}; 149 (bus_space_read_1(memt, romh, (o) + 7)))
 150#define parseword(o) \
 151 ((bus_space_read_1(memt, romh, (o) + 3) << 24) | \
 152 (bus_space_read_1(memt, romh, (o) + 7) << 16) | \
 153 (bus_space_read_1(memt, romh, (o) + 11) << 8) | \
 154 (bus_space_read_1(memt, romh, (o) + 15)))
109 155
110enum sti_bmove_funcs { 156int
111 bmf_clear, bmf_copy, bmf_invert, bmf_underline 157sti_attach_common(struct sti_softc *sc, bus_space_tag_t iot,
112}; 158 bus_space_tag_t memt, bus_space_handle_t romh, u_int codebase)
 159{
 160 struct sti_rom *rom;
 161 int rc;
 162
 163 rom = (struct sti_rom *)malloc(sizeof(*rom), M_DEVBUF,
 164 M_NOWAIT | M_ZERO);
 165 if (rom == NULL) {
 166 aprint_error("cannot allocate rom data\n");
 167 return ENOMEM;
 168 }
 169
 170 rom->rom_softc = sc;
 171 rc = sti_rom_setup(rom, iot, memt, romh, sc->bases, codebase);
 172 if (rc != 0) {
 173 free(rom, M_DEVBUF);
 174 return rc;
 175 }
113 176
114int sti_init(struct sti_softc *, int); 177 sc->sc_rom = rom;
115int sti_inqcfg(struct sti_softc *, struct sti_inqconfout *); 
116void sti_bmove(struct sti_softc *, int, int, int, int, int, int, 
117 enum sti_bmove_funcs); 
118int sti_setcment(struct sti_softc *, u_int, u_char, u_char, u_char); 
119int sti_fetchfonts(struct sti_softc *, struct sti_inqconfout *, uint32_t); 
120void sti_attach_deferred(device_t); 
121 178
122void 179 sti_describe(sc);
123sti_attach_common(struct sti_softc *sc) 180
 181 sc->sc_scr = sti_attach_screen(sc,
 182 sc->sc_flags & STI_CONSOLE ? 0 : STI_CLEARSCR);
 183 if (sc->sc_scr == NULL)
 184 rc = ENOMEM;
 185
 186 return rc;
 187}
 188
 189struct sti_screen *
 190sti_attach_screen(struct sti_softc *sc, int flags)
 191{
 192 struct sti_screen *scr;
 193 int rc;
 194
 195 scr = (struct sti_screen *)malloc(sizeof(*scr), M_DEVBUF,
 196 M_NOWAIT | M_ZERO);
 197 if (scr == NULL) {
 198 aprint_error("cannot allocate screen data\n");
 199 return NULL;
 200 }
 201
 202 scr->scr_rom = sc->sc_rom;
 203 rc = sti_screen_setup(scr, flags);
 204 if (rc != 0) {
 205 free(scr, M_DEVBUF);
 206 return NULL;
 207 }
 208
 209 sti_describe_screen(sc, scr);
 210
 211 return scr;
 212}
 213
 214int
 215sti_rom_setup(struct sti_rom *rom, bus_space_tag_t iot, bus_space_tag_t memt,
 216 bus_space_handle_t romh, bus_addr_t *bases, u_int codebase)
124{ 217{
125 struct sti_inqconfout cfg; 
126 struct sti_einqconfout ecfg; 
127 bus_space_handle_t fbh; 
128 struct sti_dd *dd; 218 struct sti_dd *dd;
129 struct sti_cfg *cc; 
130 int error, size, i; 219 int error, size, i;
131 uint8_t *p = (uint8_t *)sc->sc_code; 
132 uint32_t addr, eaddr; 
133 struct sti_region r; 
134 uint32_t *q; 
135 uint32_t tmp; 
136 220
137 dd = &sc->sc_dd; 221 KASSERT(rom != NULL);
138 if (sc->sc_devtype == STI_DEVTYPE1) { 222 STI_ENABLE_ROM(rom->rom_softc);
139#define parseshort(o) \ 223
140 ((bus_space_read_1(sc->memt, sc->romh, (o) + 3) << 8) | \ 224 rom->iot = iot;
141 (bus_space_read_1(sc->memt, sc->romh, (o) + 7))) 225 rom->memt = memt;
142#define parseword(o) \ 226 rom->romh = romh;
143 ((bus_space_read_1(sc->memt, sc->romh, (o) + 3) << 24) | \ 227 rom->bases = bases;
144 (bus_space_read_1(sc->memt, sc->romh, (o) + 7) << 16) | \ 228
145 (bus_space_read_1(sc->memt, sc->romh, (o) + 11) << 8) | \ 229 /*
146 (bus_space_read_1(sc->memt, sc->romh, (o) + 15))) 230 * Get ROM header and code function pointers.
147 231 */
148 dd->dd_type = bus_space_read_1(sc->memt, sc->romh, 0x03); 232 dd = &rom->rom_dd;
149 dd->dd_nmon = bus_space_read_1(sc->memt, sc->romh, 0x07); 233 rom->rom_devtype = bus_space_read_1(memt, romh, 3);
150 dd->dd_grrev = bus_space_read_1(sc->memt, sc->romh, 0x0b); 234 if (rom->rom_devtype == STI_DEVTYPE1) {
151 dd->dd_lrrev = bus_space_read_1(sc->memt, sc->romh, 0x0f); 235 dd->dd_type = bus_space_read_1(memt, romh, 0x03);
 236 dd->dd_nmon = bus_space_read_1(memt, romh, 0x07);
 237 dd->dd_grrev = bus_space_read_1(memt, romh, 0x0b);
 238 dd->dd_lrrev = bus_space_read_1(memt, romh, 0x0f);
152 dd->dd_grid[0] = parseword(0x10); 239 dd->dd_grid[0] = parseword(0x10);
153 dd->dd_grid[1] = parseword(0x20); 240 dd->dd_grid[1] = parseword(0x20);
154 dd->dd_fntaddr = parseword(0x30) & ~3; 241 dd->dd_fntaddr = parseword(0x30) & ~3;
155 dd->dd_maxst = parseword(0x40); 242 dd->dd_maxst = parseword(0x40);
156 dd->dd_romend = parseword(0x50) & ~3; 243 dd->dd_romend = parseword(0x50) & ~3;
157 dd->dd_reglst = parseword(0x60) & ~3; 244 dd->dd_reglst = parseword(0x60) & ~3;
158 dd->dd_maxreent= parseshort(0x70); 245 dd->dd_maxreent= parseshort(0x70);
159 dd->dd_maxtimo = parseshort(0x78); 246 dd->dd_maxtimo = parseshort(0x78);
160 dd->dd_montbl = parseword(0x80) & ~3; 247 dd->dd_montbl = parseword(0x80) & ~3;
161 dd->dd_udaddr = parseword(0x90) & ~3; 248 dd->dd_udaddr = parseword(0x90) & ~3;
162 dd->dd_stimemreq=parseword(0xa0); 249 dd->dd_stimemreq=parseword(0xa0);
163 dd->dd_udsize = parseword(0xb0); 250 dd->dd_udsize = parseword(0xb0);
164 dd->dd_pwruse = parseshort(0xc0); 251 dd->dd_pwruse = parseshort(0xc0);
165 dd->dd_bussup = bus_space_read_1(sc->memt, sc->romh, 0xcb); 252 dd->dd_bussup = bus_space_read_1(memt, romh, 0xcb);
166 dd->dd_ebussup = bus_space_read_1(sc->memt, sc->romh, 0xcf); 253 dd->dd_ebussup = bus_space_read_1(memt, romh, 0xcf);
167 dd->dd_altcodet= bus_space_read_1(sc->memt, sc->romh, 0xd3); 254 dd->dd_altcodet= bus_space_read_1(memt, romh, 0xd3);
168 dd->dd_eddst[0]= bus_space_read_1(sc->memt, sc->romh, 0xd7); 255 dd->dd_eddst[0]= bus_space_read_1(memt, romh, 0xd7);
169 dd->dd_eddst[1]= bus_space_read_1(sc->memt, sc->romh, 0xdb); 256 dd->dd_eddst[1]= bus_space_read_1(memt, romh, 0xdb);
170 dd->dd_eddst[2]= bus_space_read_1(sc->memt, sc->romh, 0xdf); 257 dd->dd_eddst[2]= bus_space_read_1(memt, romh, 0xdf);
171 dd->dd_cfbaddr = parseword(0xe0) & ~3; 258 dd->dd_cfbaddr = parseword(0xe0) & ~3;
172 259
173 dd->dd_pacode[0x0] = parseword(0x100) & ~3; 260 codebase <<= 2;
174 dd->dd_pacode[0x1] = parseword(0x110) & ~3; 261 dd->dd_pacode[0x0] = parseword(codebase + 0x00) & ~3;
175 dd->dd_pacode[0x2] = parseword(0x120) & ~3; 262 dd->dd_pacode[0x1] = parseword(codebase + 0x10) & ~3;
176 dd->dd_pacode[0x3] = parseword(0x130) & ~3; 263 dd->dd_pacode[0x2] = parseword(codebase + 0x20) & ~3;
177 dd->dd_pacode[0x4] = parseword(0x140) & ~3; 264 dd->dd_pacode[0x3] = parseword(codebase + 0x30) & ~3;
178 dd->dd_pacode[0x5] = parseword(0x150) & ~3; 265 dd->dd_pacode[0x4] = parseword(codebase + 0x40) & ~3;
179 dd->dd_pacode[0x6] = parseword(0x160) & ~3; 266 dd->dd_pacode[0x5] = parseword(codebase + 0x50) & ~3;
180 dd->dd_pacode[0x7] = parseword(0x170) & ~3; 267 dd->dd_pacode[0x6] = parseword(codebase + 0x60) & ~3;
181 dd->dd_pacode[0x8] = parseword(0x180) & ~3; 268 dd->dd_pacode[0x7] = parseword(codebase + 0x70) & ~3;
182 dd->dd_pacode[0x9] = parseword(0x190) & ~3; 269 dd->dd_pacode[0x8] = parseword(codebase + 0x80) & ~3;
183 dd->dd_pacode[0xa] = parseword(0x1a0) & ~3; 270 dd->dd_pacode[0x9] = parseword(codebase + 0x90) & ~3;
184 dd->dd_pacode[0xb] = parseword(0x1b0) & ~3; 271 dd->dd_pacode[0xa] = parseword(codebase + 0xa0) & ~3;
185 dd->dd_pacode[0xc] = parseword(0x1c0) & ~3; 272 dd->dd_pacode[0xb] = parseword(codebase + 0xb0) & ~3;
186 dd->dd_pacode[0xd] = parseword(0x1d0) & ~3; 273 dd->dd_pacode[0xc] = parseword(codebase + 0xc0) & ~3;
187 dd->dd_pacode[0xe] = parseword(0x1e0) & ~3; 274 dd->dd_pacode[0xd] = parseword(codebase + 0xd0) & ~3;
188 dd->dd_pacode[0xf] = parseword(0x1f0) & ~3; 275 dd->dd_pacode[0xe] = parseword(codebase + 0xe0) & ~3;
189 } else /* STI_DEVTYPE4 */ 276 dd->dd_pacode[0xf] = parseword(codebase + 0xf0) & ~3;
190 bus_space_read_region_4(sc->memt, sc->romh, 0, (uint32_t *)dd, 277 } else { /* STI_DEVTYPE4 */
 278 bus_space_read_region_stream_4(memt, romh, 0, (uint32_t *)dd,
191 sizeof(*dd) / 4); 279 sizeof(*dd) / 4);
 280 /* fix pacode... */
 281 bus_space_read_region_stream_4(memt, romh, codebase,
 282 (uint32_t *)dd->dd_pacode, sizeof(dd->dd_pacode) / 4);
 283 }
192 284
193#ifdef STIDEBUG 285 STI_DISABLE_ROM(rom->rom_softc);
194 printf("dd:\n" 286
195 "devtype=%x, rev=%x;%d, altt=%x, gid=%016llx, font=%x, mss=%x\n" 287 DPRINTF(("dd:\n"
 288 "devtype=%x, rev=%x;%d, altt=%x, gid=%08x%08x, font=%x, mss=%x\n"
196 "end=%x, regions=%x, msto=%x, timo=%d, mont=%x, user=%x[%x]\n" 289 "end=%x, regions=%x, msto=%x, timo=%d, mont=%x, user=%x[%x]\n"
197 "memrq=%x, pwr=%d, bus=%x, ebus=%x, cfb=%x\n" 290 "memrq=%x, pwr=%d, bus=%x, ebus=%x, cfb=%x\n"
198 "code=", 291 "code=",
199 dd->dd_type & 0xff, dd->dd_grrev, dd->dd_lrrev, dd->dd_altcodet, 292 dd->dd_type & 0xff, dd->dd_grrev, dd->dd_lrrev, dd->dd_altcodet,
200 *(uint64_t *)dd->dd_grid, dd->dd_fntaddr, dd->dd_maxst, 293 dd->dd_grid[0], dd->dd_grid[1], dd->dd_fntaddr, dd->dd_maxst,
201 dd->dd_romend, dd->dd_reglst, dd->dd_maxreent, dd->dd_maxtimo, 294 dd->dd_romend, dd->dd_reglst, dd->dd_maxreent, dd->dd_maxtimo,
202 dd->dd_montbl, dd->dd_udaddr, dd->dd_udsize, dd->dd_stimemreq, 295 dd->dd_montbl, dd->dd_udaddr, dd->dd_udsize, dd->dd_stimemreq,
203 dd->dd_pwruse, dd->dd_bussup, dd->dd_ebussup, dd->dd_cfbaddr); 296 dd->dd_pwruse, dd->dd_bussup, dd->dd_ebussup, dd->dd_cfbaddr));
204 printf("%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n", 297 DPRINTF(("%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n",
205 dd->dd_pacode[0x0], dd->dd_pacode[0x1], dd->dd_pacode[0x2], 298 dd->dd_pacode[0x0], dd->dd_pacode[0x1], dd->dd_pacode[0x2],
206 dd->dd_pacode[0x3], dd->dd_pacode[0x4], dd->dd_pacode[0x5], 299 dd->dd_pacode[0x3], dd->dd_pacode[0x4], dd->dd_pacode[0x5],
207 dd->dd_pacode[0x6], dd->dd_pacode[0x7], dd->dd_pacode[0x8], 300 dd->dd_pacode[0x6], dd->dd_pacode[0x7], dd->dd_pacode[0x8],
208 dd->dd_pacode[0x9], dd->dd_pacode[0xa], dd->dd_pacode[0xb], 301 dd->dd_pacode[0x9], dd->dd_pacode[0xa], dd->dd_pacode[0xb],
209 dd->dd_pacode[0xc], dd->dd_pacode[0xd], dd->dd_pacode[0xe], 302 dd->dd_pacode[0xc], dd->dd_pacode[0xd], dd->dd_pacode[0xe],
210 dd->dd_pacode[0xf]); 303 dd->dd_pacode[0xf]));
211#endif 304
212 /* divise code size, could be less than STI_END entries */ 305 /*
213 for (i = STI_END; !dd->dd_pacode[i]; i--); 306 * Figure out how many bytes we need for the STI code.
 307 * Note there could be fewer than STI_END pointer entries
 308 * populated, especially on older devices.
 309 */
 310 for (i = STI_END; !dd->dd_pacode[i]; i--)
 311 ;
 312
214 size = dd->dd_pacode[i] - dd->dd_pacode[STI_BEGIN]; 313 size = dd->dd_pacode[i] - dd->dd_pacode[STI_BEGIN];
215 if (sc->sc_devtype == STI_DEVTYPE1) 314
 315 if (rom->rom_devtype == STI_DEVTYPE1)
216 size = (size + 3) / 4; 316 size = (size + 3) / 4;
217 if (!(sc->sc_code = uvm_km_alloc(kernel_map, round_page(size), 0, 317 if (size == 0) {
 318 aprint_error(": no code for the requested platform\n");
 319 return EINVAL;
 320 }
 321
 322 DPRINTF(("code size %x/%x\n", size, round_page(size)));
 323
 324 if (!(rom->rom_code = uvm_km_alloc(kernel_map, round_page(size), 0,
218 UVM_KMF_WIRED))) { 325 UVM_KMF_WIRED))) {
219 printf(": cannot allocate %u bytes for code\n", size); 326 aprint_error(": cannot allocate %u bytes for code\n", size);
220 return; 327 return ENOMEM;
221 } 328 }
222#ifdef STIDEBUG 
223 printf("code=0x%x[%x]\n", (uint)sc->sc_code, size); 
224#endif 
225 329
226 /* copy code into memory */ 330 /*
227 if (sc->sc_devtype == STI_DEVTYPE1) { 331 * Copy code into memory and make it executable.
228 p = (uint8_t *)sc->sc_code; 332 */
 333
 334 STI_ENABLE_ROM(rom->rom_softc);
 335
 336 if (rom->rom_devtype == STI_DEVTYPE1) {
 337 uint8_t *p;
 338 uint32_t addr, eaddr;
 339
 340 p = (uint8_t *)rom->rom_code;
 341
229 for (addr = dd->dd_pacode[STI_BEGIN], eaddr = addr + size * 4; 342 for (addr = dd->dd_pacode[STI_BEGIN], eaddr = addr + size * 4;
230 addr < eaddr; addr += 4 ) 343 addr < eaddr; addr += 4 ) {
231 *p++ = bus_space_read_4(sc->memt, sc->romh, addr) 344 *p++ = bus_space_read_4(memt, romh, addr)
232 & 0xff; 345 & 0xff;
233 346 }
234 } else /* STI_DEVTYPE4 */ 347 } else { /* STI_DEVTYPE4 */
235 bus_space_read_region_4(sc->memt, sc->romh, 348 bus_space_read_region_stream_4(memt, romh,
236 dd->dd_pacode[STI_BEGIN], (uint32_t *)sc->sc_code, 349 dd->dd_pacode[STI_BEGIN], (uint32_t *)rom->rom_code,
237 size / 4); 350 size / 4);
 351 }
 352
 353 STI_DISABLE_ROM(rom->rom_softc);
238 354
239#define O(i) (dd->dd_pacode[(i)] ? (sc->sc_code + \ 355 if ((error = uvm_map_protect(kernel_map, rom->rom_code,
240 (dd->dd_pacode[(i)] - dd->dd_pacode[0]) / \ 356 rom->rom_code + round_page(size), UVM_PROT_RX, FALSE))) {
241 (sc->sc_devtype == STI_DEVTYPE1 ? 4 : 1)) : 0) 357 aprint_error(": uvm_map_protect failed (%d)\n", error);
242 sc->init = (sti_init_t) O(STI_INIT_GRAPH); 358 uvm_km_free(kernel_map, rom->rom_code, round_page(size),
243 sc->mgmt = (sti_mgmt_t) O(STI_STATE_MGMT); 
244 sc->unpmv = (sti_unpmv_t) O(STI_FONT_UNPMV); 
245 sc->blkmv = (sti_blkmv_t) O(STI_BLOCK_MOVE); 
246 sc->test = (sti_test_t) O(STI_SELF_TEST); 
247 sc->exhdl = (sti_exhdl_t) O(STI_EXCEP_HDLR); 
248 sc->inqconf = (sti_inqconf_t)O(STI_INQ_CONF); 
249 sc->scment = (sti_scment_t)O(STI_SCM_ENT); 
250 sc->dmac = (sti_dmac_t) O(STI_DMA_CTRL); 
251 sc->flowc = (sti_flowc_t) O(STI_FLOW_CTRL); 
252 sc->utiming = (sti_utiming_t)O(STI_UTIMING); 
253 sc->pmgr = (sti_pmgr_t) O(STI_PROC_MGR); 
254 sc->util = (sti_util_t) O(STI_UTIL); 
255 
256 if ((error = uvm_map_protect(kernel_map, sc->sc_code, 
257 sc->sc_code + round_page(size), UVM_PROT_RX, FALSE))) { 
258 printf(": uvm_map_protect failed (%d)\n", error); 
259 uvm_km_free(kernel_map, sc->sc_code, round_page(size), 
260 UVM_KMF_WIRED); 359 UVM_KMF_WIRED);
261 return; 360 return error;
262 } 361 }
263 362
264 cc = &sc->sc_cfg; 363 /*
265 memset(cc, 0, sizeof (*cc)); 364 * Setup code function pointers.
266 i = dd->dd_reglst; 365 */
267#ifdef STIDEBUG 
268 printf("stiregions @%d:\n", i); 
269#endif 
270 r.last = 0; 
271 for (q = cc->regions; !r.last && 
272 q < &cc->regions[STI_REGION_MAX]; q++) { 
273 366
274 if (sc->sc_devtype == STI_DEVTYPE1) 367#define O(i) \
275 tmp = parseword(i), i += 16; 368 (dd->dd_pacode[(i)] == 0 ? 0 : \
276 else 369 (rom->rom_code + (dd->dd_pacode[(i)] - dd->dd_pacode[0]) / \
277 tmp = bus_space_read_4(sc->memt, sc->romh, i), i += 4; 370 (rom->rom_devtype == STI_DEVTYPE1 ? 4 : 1)))
278 memcpy(&r, &tmp, sizeof (r)); 371 rom->init = (sti_init_t) O(STI_INIT_GRAPH);
 372 rom->mgmt = (sti_mgmt_t) O(STI_STATE_MGMT);
 373 rom->unpmv = (sti_unpmv_t) O(STI_FONT_UNPMV);
 374 rom->blkmv = (sti_blkmv_t) O(STI_BLOCK_MOVE);
 375 rom->test = (sti_test_t) O(STI_SELF_TEST);
 376 rom->exhdl = (sti_exhdl_t) O(STI_EXCEP_HDLR);
 377 rom->inqconf = (sti_inqconf_t)O(STI_INQ_CONF);
 378 rom->scment = (sti_scment_t)O(STI_SCM_ENT);
 379 rom->dmac = (sti_dmac_t) O(STI_DMA_CTRL);
 380 rom->flowc = (sti_flowc_t) O(STI_FLOW_CTRL);
 381 rom->utiming = (sti_utiming_t)O(STI_UTIMING);
 382 rom->pmgr = (sti_pmgr_t) O(STI_PROC_MGR);
 383 rom->util = (sti_util_t) O(STI_UTIL);
 384
 385#undef O
 386 /*
 387 * Set colormap entry is not implemented until 8.04, so force
 388 * a NULL pointer here.
 389 */
 390
 391 if (dd->dd_grrev < STI_REVISION(8, 4)) {
 392 rom->scment = NULL;
 393 }
 394
 395 return 0;
 396}
 397
 398/*
 399 * Map all regions.
 400 */
 401void
 402sti_region_setup(struct sti_screen *scr)
 403{
 404 struct sti_rom *rom = scr->scr_rom;
 405 bus_space_tag_t memt = rom->memt;
 406 bus_space_handle_t romh = rom->romh;
 407 bus_addr_t *bases = rom->bases;
 408 struct sti_dd *dd = &rom->rom_dd;
 409 struct sti_cfg *cc = &scr->scr_cfg;
 410 bus_space_handle_t bh;
 411 struct sti_region regions[STI_REGION_MAX], *r;
 412 u_int regno, regcnt;
 413 bus_addr_t addr;
 414
 415 DPRINTF(("stiregions @ %x:\n", dd->dd_reglst));
 416
 417 /*
 418 * Read the region information.
 419 */
 420
 421 STI_ENABLE_ROM(rom->rom_softc);
 422
 423 if (rom->rom_devtype == STI_DEVTYPE1) {
 424 for (regno = 0; regno < STI_REGION_MAX; regno++)
 425 *(u_int *)(regions + regno) =
 426 parseword(dd->dd_reglst + regno * 0x10);
 427 } else {
 428 bus_space_read_region_stream_4(memt, romh, dd->dd_reglst,
 429 (uint32_t *)regions, sizeof(regions) / 4);
 430 }
 431
 432 STI_DISABLE_ROM(rom->rom_softc);
 433
 434 /*
 435 * Count them.
 436 */
 437
 438 for (regcnt = 0, r = regions; regcnt < STI_REGION_MAX; regcnt++, r++)
 439 if (r->last)
 440 break;
 441 regcnt++;
 442
 443 /*
 444 * Map them.
 445 */
 446
 447 for (regno = 0, r = regions; regno < regcnt; regno++, r++) {
 448 if (r->length == 0)
 449 continue;
 450
 451 /*
 452 * Assume an existing mapping exists.
 453 */
 454 addr = bases[regno] + (r->offset << PGSHIFT);
 455 DPRINTF(("%08x @ 0x%08x%s%s%s%s",
 456 r->length << PGSHIFT, (int)addr, r->sys_only ? " sys" : "",
 457 r->cache ? " cache" : "", r->btlb ? " btlb" : "",
 458 r->last ? " last" : ""));
 459
 460 /*
 461 * Region #0 is always the rom, and it should have been
 462 * mapped already.
 463 * XXX This expects a 1:1 mapping...
 464 */
 465 if (regno == 0 && romh == bases[0]) {
 466 cc->regions[0] = addr;
 467 continue;
 468 }
 469
 470 /* XXXNH BUS_SPACE_MAP_CACHEABLE */
 471 if (bus_space_map(memt, addr, r->length << PGSHIFT,
 472 r->cache ? BUS_SPACE_MAP_CACHEABLE : 0, &bh)) {
 473 DPRINTF((" - already mapped region\n"));
 474 } else {
 475 DPRINTF(("\n"));
 476
 477 /* XXX should use bus_space_vaddr */
 478 addr = (bus_addr_t)bh;
 479 if (regno == 1) {
 480 scr->fbaddr = addr;
 481 scr->fblen = r->length << PGSHIFT;
 482 }
 483 }
 484
 485 cc->regions[regno] = addr;
 486 }
279 487
280 *q = (q == cc->regions ? sc->romh : sc->base) + 
281 (r.offset << PGSHIFT); 
282#ifdef STIDEBUG 488#ifdef STIDEBUG
283 printf("%x @ 0x%x%s%s%s%s\n", 489 /*
284 r.length << PGSHIFT, *q, r.sys_only ? " sys" : "", 490 * Make sure we'll trap accessing unmapped regions
285 r.cache ? " cache" : "", r.btlb ? " btlb" : "", 491 */
286 r.last ? " last" : ""); 492 for (regno = 0; regno < STI_REGION_MAX; regno++)
 493 if (cc->regions[regno] == 0)
 494 cc->regions[regno] = 0x81234567;
287#endif 495#endif
 496}
288 497
289 /* rom has already been mapped */ 498int
290 if (q != cc->regions) { 499sti_screen_setup(struct sti_screen *scr, int flags)
291 if (bus_space_map(sc->memt, *q, 500{
292 r.length << PGSHIFT, 0, &fbh)) { 501 struct sti_rom *rom = scr->scr_rom;
 502 bus_space_tag_t memt = rom->memt;
 503 bus_space_handle_t romh = rom->romh;
 504 struct sti_dd *dd = &rom->rom_dd;
 505 struct sti_cfg *cc = &scr->scr_cfg;
 506 struct sti_inqconfout cfg;
 507 struct sti_einqconfout ecfg;
293#ifdef STIDEBUG 508#ifdef STIDEBUG
294 printf("already mapped region\n"); 509 char buf[256];
295#endif 510#endif
296 } else { 511 int error, i;
297 if (q - cc->regions == 1) { 512 int geometry_kluge = 0;
298 sc->fbaddr = *q; 513 u_int fontindex = 0;
299 sc->fblen = r.length << PGSHIFT; 514
300 } 515 KASSERT(scr != NULL);
301 *q = fbh; 516 memset(cc, 0, sizeof(*cc));
302 } 517 cc->ext_cfg = &scr->scr_ecfg;
 518 memset(cc->ext_cfg, 0, sizeof(*cc->ext_cfg));
 519
 520 if (dd->dd_stimemreq) {
 521 scr->scr_ecfg.addr =
 522 malloc(dd->dd_stimemreq, M_DEVBUF, M_NOWAIT);
 523 if (!scr->scr_ecfg.addr) {
 524 aprint_error("cannot allocate %d bytes for STI\n",
 525 dd->dd_stimemreq);
 526 return ENOMEM;
303 } 527 }
304 } 528 }
305 529
306 if ((error = sti_init(sc, 0))) { 530 sti_region_setup(scr);
307 printf(": can not initialize (%d)\n", error); 531
308 return; 532 if ((error = sti_init(scr, 0))) {
 533 aprint_error(": cannot initialize (%d)\n", error);
 534 goto fail;
309 } 535 }
310 536
311 memset(&cfg, 0, sizeof(cfg)); 537 memset(&cfg, 0, sizeof(cfg));
312 memset(&ecfg, 0, sizeof(ecfg)); 538 memset(&ecfg, 0, sizeof(ecfg));
313 cfg.ext = &ecfg; 539 cfg.ext = &ecfg;
314 if ((error = sti_inqcfg(sc, &cfg))) { 540 if ((error = sti_inqcfg(scr, &cfg))) {
315 printf(": error %d inquiring config\n", error); 541 aprint_error(": error %d inquiring config\n", error);
316 return; 542 goto fail;
317 } 543 }
318 544
319 if ((error = sti_init(sc, STI_TEXTMODE))) { 545 /*
320 printf(": can not initialize (%d)\n", error); 546 * Older (rev 8.02) boards report wrong offset values,
321 return; 547 * similar to the displayable area size, at least in m68k mode.
 548 * Attempt to detect this and adjust here.
 549 */
 550 if (cfg.owidth == cfg.width &&
 551 cfg.oheight == cfg.height)
 552 geometry_kluge = 1;
 553
 554 if (geometry_kluge) {
 555 scr->scr_cfg.oscr_width = cfg.owidth =
 556 cfg.fbwidth - cfg.width;
 557 scr->scr_cfg.oscr_height = cfg.oheight =
 558 cfg.fbheight - cfg.height;
322 } 559 }
323 560
 561 /*
 562 * Save a few fields for sti_describe_screen() later
 563 */
 564 scr->fbheight = cfg.fbheight;
 565 scr->fbwidth = cfg.fbwidth;
 566 scr->oheight = cfg.oheight;
 567 scr->owidth = cfg.owidth;
 568 memcpy(scr->name, cfg.name, sizeof(scr->name));
 569
 570 if ((error = sti_init(scr, STI_TEXTMODE | flags))) {
 571 aprint_error(": cannot initialize (%d)\n", error);
 572 goto fail;
 573 }
324#ifdef STIDEBUG 574#ifdef STIDEBUG
325 printf("conf: bpp=%d planes=%d attr=%d\n" 575 snprintb(buf, sizeof(buf), STI_INQCONF_BITS, cfg.attributes);
326 "crt=0x%x:0x%x:0x%x hw=0x%x:0x%x:0x%x\n", 576 DPRINTF(("conf: bpp=%d planes=%d attr=%s\n"
327 cfg.bpp, cfg.planes, cfg.attributes, 577 "crt=0x%x:0x%x:0x%x hw=0x%x:0x%x:0x%x\n", cfg.bpp,
 578 cfg.planes, buf,
328 ecfg.crt_config[0], ecfg.crt_config[1], ecfg.crt_config[2], 579 ecfg.crt_config[0], ecfg.crt_config[1], ecfg.crt_config[2],
329 ecfg.crt_hw[0], ecfg.crt_hw[1], ecfg.crt_hw[2]); 580 ecfg.crt_hw[0], ecfg.crt_hw[1], ecfg.crt_hw[2]));
330#endif 581#endif
331 sc->sc_wsmode = WSDISPLAYIO_MODE_EMUL; 582 scr->scr_bpp = cfg.bppu;
332 sc->sc_bpp = cfg.bppu; 583
333 printf(": %s rev %d.%02d;%d, ID 0x%016llX\n" 584 /*
334 "%s: %dx%d frame buffer, %dx%dx%d display, offset %dx%d\n", 585 * Although scr->scr_ecfg.current_monitor is not filled by
335 cfg.name, dd->dd_grrev >> 4, dd->dd_grrev & 0xf, dd->dd_lrrev, 586 * sti_init() as expected, we can nevertheless walk the monitor
336 *(uint64_t *)dd->dd_grid, device_xname(sc->sc_dev), cfg.fbwidth, 587 * list, if there is any, and if we find a mode matching our
337 cfg.fbheight, cfg.width, cfg.height, cfg.bppu, cfg.owidth, 588 * resolution, pick its font index.
338 cfg.oheight); 589 */
339 590 if (dd->dd_montbl != 0) {
340 if ((error = sti_fetchfonts(sc, &cfg, dd->dd_fntaddr))) { 591 STI_ENABLE_ROM(rom->rom_softc);
341 aprint_error_dev(sc->sc_dev, "cannot fetch fonts (%d)\n", 592
342 error); 593 for (i = 0; i < dd->dd_nmon; i++) {
343 return; 594 u_int offs = dd->dd_montbl + 8 * i;
 595 uint32_t m[2];
 596 sti_mon_t mon = (void *)m;
 597 if (rom->rom_devtype == STI_DEVTYPE1) {
 598 m[0] = parseword(4 * offs);
 599 m[1] = parseword(4 * (offs + 4));
 600 } else {
 601 bus_space_read_region_stream_4(memt, romh, offs,
 602 (uint32_t *)mon, sizeof(*mon) / 4);
 603 }
 604
 605 if (mon->width == scr->scr_cfg.scr_width &&
 606 mon->height == scr->scr_cfg.scr_height) {
 607 fontindex = mon->font;
 608 break;
 609 }
 610 }
 611
 612 STI_DISABLE_ROM(rom->rom_softc);
 613
 614 DPRINTF(("font index: %d\n", fontindex));
 615 }
 616
 617 if ((error = sti_fetchfonts(scr, &cfg, dd->dd_fntaddr, fontindex))) {
 618 aprint_error(": cannot fetch fonts (%d)\n", error);
 619 goto fail;
344 } 620 }
345 621
346 /* 622 /*
347 * parse screen descriptions: 623 * setup screen descriptions:
348 * figure number of fonts supported; 624 * figure number of fonts supported;
349 * allocate wscons structures; 625 * allocate wscons structures;
350 * calculate dimensions. 626 * calculate dimensions.
351 */ 627 */
352 628
353 sti_default_screen.ncols = cfg.width / sc->sc_curfont.width; 629 scr->scr_wsd.name = "std";
354 sti_default_screen.nrows = cfg.height / sc->sc_curfont.height; 630 scr->scr_wsd.ncols = cfg.width / scr->scr_curfont.width;
355 sti_default_screen.fontwidth = sc->sc_curfont.width; 631 scr->scr_wsd.nrows = cfg.height / scr->scr_curfont.height;
356 sti_default_screen.fontheight = sc->sc_curfont.height; 632 scr->scr_wsd.textops = &sti_emulops;
 633 scr->scr_wsd.fontwidth = scr->scr_curfont.width;
 634 scr->scr_wsd.fontheight = scr->scr_curfont.height;
 635 scr->scr_wsd.capabilities = WSSCREEN_REVERSE | WSSCREEN_UNDERLINE;
 636
 637 scr->scr_scrlist[0] = &scr->scr_wsd;
 638 scr->scr_screenlist.nscreens = 1;
 639 scr->scr_screenlist.screens =
 640 (const struct wsscreen_descr **)scr->scr_scrlist;
357 641
358#if NWSDISPLAY > 0 642 return 0;
359 config_interrupts(sc->sc_dev, sti_attach_deferred); 643
360#endif 644fail:
 645 /* XXX free resources */
 646 if (scr->scr_ecfg.addr != NULL) {
 647 free(scr->scr_ecfg.addr, M_DEVBUF);
 648 scr->scr_ecfg.addr = NULL;
 649 }
361 650
 651 return ENXIO;
362} 652}
363 653
364void 654void
365sti_attach_deferred(device_t dev) 655sti_describe_screen(struct sti_softc *sc, struct sti_screen *scr)
366{ 656{
367 struct sti_softc *sc = device_private(dev); 657 struct sti_font *fp = &scr->scr_curfont;
368 struct wsemuldisplaydev_attach_args waa; 658
369 long defattr; 659 aprint_normal("%s: %s, %dx%d frame buffer, %dx%dx%d display\n",
 660 device_xname(sc->sc_dev), scr->name, scr->fbwidth, scr->fbheight,
 661 scr->scr_cfg.scr_width, scr->scr_cfg.scr_height, scr->scr_bpp);
 662
 663 aprint_normal("%s: %dx%d font type %d, %d bpc, charset %d-%d\n",
 664 device_xname(sc->sc_dev), fp->width, fp->height,
 665 fp->type, fp->bpc, fp->first, fp->last);
 666}
 667
 668void
 669sti_describe(struct sti_softc *sc)
 670{
 671 struct sti_rom *rom = sc->sc_rom;
 672 struct sti_dd *dd = &rom->rom_dd;
 673
 674 aprint_normal(": rev %d.%02d;%d, ID 0x%08X%08X\n",
 675 dd->dd_grrev >> 4, dd->dd_grrev & 0xf,
 676 dd->dd_lrrev, dd->dd_grid[0], dd->dd_grid[1]);
 677
 678 if (sc->sc_scr != NULL)
 679 sti_describe_screen(sc, sc->sc_scr);
 680}
 681
 682void
 683sti_end_attach(struct sti_softc *sc)
 684{
 685 struct sti_screen *scr = sc->sc_scr;
 686
 687 if (scr == NULL)
 688 return;
 689#if NWSDISPLAY > 0
 690 else {
 691 struct wsemuldisplaydev_attach_args waa;
 692 scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL;
 693
 694 waa.console = sc->sc_flags & STI_CONSOLE ? 1 : 0;
 695 waa.scrdata = &scr->scr_screenlist;
 696 waa.accessops = &sti_accessops;
 697 waa.accesscookie = scr;
 698
 699 /* attach as console if required */
 700 if (waa.console && !ISSET(sc->sc_flags, STI_ATTACHED)) {
 701 long defattr;
 702
 703 sti_alloc_attr(scr, 0, 0, 0, &defattr);
 704 wsdisplay_cnattach(&scr->scr_wsd, scr,
 705 0, scr->scr_wsd.nrows - 1, defattr);
 706 sc->sc_flags |= STI_ATTACHED;
 707 }
 708
 709 config_found(sc->sc_dev, &waa, wsemuldisplaydevprint);
 710 }
 711#endif
 712}
370 713
371 waa.console = sc->sc_flags & STI_CONSOLE ? 1 : 0; 714u_int
372 waa.scrdata = &sti_default_screenlist; 715sti_rom_size(bus_space_tag_t memt, bus_space_handle_t romh)
373 waa.accessops = &sti_accessops; 716{
374 waa.accesscookie = sc; 717 int devtype;
 718 u_int romend;
375 719
376 /* attach as console if required */ 720 devtype = bus_space_read_1(memt, romh, 3);
377 if (waa.console) { 721 if (devtype == STI_DEVTYPE4) {
378 sti_alloc_attr(sc, 0, 0, 0, &defattr); 722 bus_space_read_region_stream_4(memt, romh, STI_DEV4_DD_ROMEND,
379 wsdisplay_cnattach(&sti_default_screen, sc, 723 (uint32_t *)&romend, 1);
380 0, sti_default_screen.nrows - 1, defattr); 724 } else {
 725 romend = parseword(STI_DEV1_DD_ROMEND);
381 } 726 }
382 727
383 config_found(sc->sc_dev, &waa, wsemuldisplaydevprint); 728 DPRINTF(("%s: %08x (%08x)\n", __func__, romend, round_page(romend)));
 729
 730 return round_page(romend);
384} 731}
385 732
386int 733int
387sti_fetchfonts(struct sti_softc *sc, struct sti_inqconfout *cfg, uint32_t addr) 734sti_fetchfonts(struct sti_screen *scr, struct sti_inqconfout *cfg,
 735 uint32_t baseaddr, u_int fontindex)
388{ 736{
389 struct sti_font *fp = &sc->sc_curfont; 737 struct sti_rom *rom = scr->scr_rom;
 738 bus_space_tag_t memt = rom->memt;
 739 bus_space_handle_t romh = rom->romh;
 740 struct sti_font *fp = &scr->scr_curfont;
 741 uint32_t addr;
390 int size; 742 int size;
391#ifdef notyet 743#ifdef notyet
392 int uc; 744 int uc;
393 struct { 745 struct {
394 struct sti_unpmvflags flags; 746 struct sti_unpmvflags flags;
395 struct sti_unpmvin in; 747 struct sti_unpmvin in;
396 struct sti_unpmvout out; 748 struct sti_unpmvout out;
397 } a; 749 } a;
398#endif 750#endif
399 751
400 /* 752 /*
401 * Get the first PROM font in memory 753 * Get the first PROM font in memory
402 */ 754 */
 755
 756 STI_ENABLE_ROM(rom->rom_softc);
 757
 758rescan:
 759 addr = baseaddr;
403 do { 760 do {
404 if (sc->sc_devtype == STI_DEVTYPE1) { 761 if (rom->rom_devtype == STI_DEVTYPE1) {
405 fp->first = parseshort(addr + 0x00); 762 fp->first = parseshort(addr + 0x00);
406 fp->last = parseshort(addr + 0x08); 763 fp->last = parseshort(addr + 0x08);
407 fp->width = bus_space_read_1(sc->memt, sc->romh, 764 fp->width = bus_space_read_1(memt, romh, addr + 0x13);
408 addr + 0x13); 765 fp->height = bus_space_read_1(memt, romh, addr + 0x17);
409 fp->height = bus_space_read_1(sc->memt, sc->romh, 766 fp->type = bus_space_read_1(memt, romh, addr + 0x1b);
410 addr + 0x17); 767 fp->bpc = bus_space_read_1(memt, romh, addr + 0x1f);
411 fp->type = bus_space_read_1(sc->memt, sc->romh, 768 fp->next = parseword(addr + 0x20);
412 addr + 0x1b); 769 fp->uheight= bus_space_read_1(memt, romh, addr + 0x33);
413 fp->bpc = bus_space_read_1(sc->memt, sc->romh, 770 fp->uoffset= bus_space_read_1(memt, romh, addr + 0x37);
414 addr + 0x1f); 771 } else { /* STI_DEVTYPE4 */
415 fp->next = parseword(addr + 0x23); 772 bus_space_read_region_stream_4(memt, romh, addr,
416 fp->uheight= bus_space_read_1(sc->memt, sc->romh, 
417 addr + 0x33); 
418 fp->uoffset= bus_space_read_1(sc->memt, sc->romh, 
419 addr + 0x37); 
420 } else /* STI_DEVTYPE4 */ 
421 bus_space_read_region_4(sc->memt, sc->romh, addr, 
422 (uint32_t *)fp, sizeof(struct sti_font) / 4); 773 (uint32_t *)fp, sizeof(struct sti_font) / 4);
 774 }
423 775
424 printf("%s: %dx%d font type %d, %d bpc, charset %d-%d\n", 776#ifdef STIDEBUG
425 device_xname(sc->sc_dev), fp->width, fp->height, fp->type, 777 STI_DISABLE_ROM(rom->rom_softc);
426 fp->bpc, fp->first, fp->last); 778 DPRINTF(("%s: %dx%d font type %d, %d bpc, charset %d-%d\n",
427 779 device_xname(scr->scr_rom->rom_softc->sc_dev), fp->width,
428 size = sizeof(struct sti_font) + 780 fp->height, fp->type, fp->bpc, fp->first, fp->last));
429 (fp->last - fp->first + 1) * fp->bpc; 781 STI_ENABLE_ROM(rom->rom_softc);
430 if (sc->sc_devtype == STI_DEVTYPE1) 782#endif
431 size *= 4; 
432 sc->sc_romfont = malloc(size, M_DEVBUF, M_NOWAIT); 
433 if (sc->sc_romfont == NULL) 
434 return (ENOMEM); 
435 783
436 bus_space_read_region_4(sc->memt, sc->romh, addr, 784 if (fontindex == 0) {
437 (uint32_t *)sc->sc_romfont, size / 4); 785 size = sizeof(struct sti_font) +
 786 (fp->last - fp->first + 1) * fp->bpc;
 787 if (rom->rom_devtype == STI_DEVTYPE1)
 788 size *= 4;
 789 scr->scr_romfont = malloc(size, M_DEVBUF, M_NOWAIT);
 790 if (scr->scr_romfont == NULL)
 791 return ENOMEM;
438 792
439 addr = 0; /* fp->next */ 793 bus_space_read_region_stream_4(memt, romh, addr,
440 } while (addr); 794 (uint32_t *)scr->scr_romfont, size / 4);
 795 break;
 796 }
 797
 798 addr = baseaddr + fp->next;
 799 fontindex--;
 800 } while (fp->next != 0);
 801
 802 /*
 803 * If our font index was bogus, we did not find the expected font.
 804 * In this case, pick the first one and be done with it.
 805 */
 806 if (fp->next == 0 && scr->scr_romfont == NULL) {
 807 fontindex = 0;
 808 goto rescan;
 809 }
 810
 811 STI_DISABLE_ROM(rom->rom_softc);
441 812
442#ifdef notyet 813#ifdef notyet
443 /* 814 /*
444 * If there is enough room in the off-screen framebuffer memory, 815 * If there is enough room in the off-screen framebuffer memory,
445 * display all the characters there in order to display them 816 * display all the characters there in order to display them
446 * faster with blkmv operations rather than unpmv later on. 817 * faster with blkmv operations rather than unpmv later on.
447 */ 818 */
448 if (size <= cfg->fbheight * 819 if (size <= cfg->fbheight *
449 (cfg->fbwidth - cfg->width - cfg->owidth)) { 820 (cfg->fbwidth - cfg->width - cfg->owidth)) {
450 memset(&a, 0, sizeof(a)); 821 memset(&a, 0, sizeof(a));
451 a.flags.flags = STI_UNPMVF_WAIT; 822 a.flags.flags = STI_UNPMVF_WAIT;
452 a.in.fg_colour = STI_COLOUR_WHITE; 823 a.in.fg_colour = STI_COLOUR_WHITE;
453 a.in.bg_colour = STI_COLOUR_BLACK; 824 a.in.bg_colour = STI_COLOUR_BLACK;
454 a.in.font_addr = sc->sc_romfont; 825 a.in.font_addr = scr->scr_romfont;
455 826
456 sc->sc_fontmaxcol = cfg->fbheight / fp->height; 827 scr->scr_fontmaxcol = cfg->fbheight / fp->height;
457 sc->sc_fontbase = cfg->width + cfg->owidth; 828 scr->scr_fontbase = cfg->width + cfg->owidth;
458 for (uc = fp->first; uc <= fp->last; uc++) { 829 for (uc = fp->first; uc <= fp->last; uc++) {
459 a.in.x = ((uc - fp->first) / sc->sc_fontmaxcol) * 830 a.in.x = ((uc - fp->first) / scr->scr_fontmaxcol) *
460 fp->width + sc->sc_fontbase; 831 fp->width + scr->scr_fontbase;
461 a.in.y = ((uc - fp->first) % sc->sc_fontmaxcol) * 832 a.in.y = ((uc - fp->first) % scr->scr_fontmaxcol) *
462 fp->height; 833 fp->height;
463 a.in.index = uc; 834 a.in.index = uc;
464 835
465 (*sc->unpmv)(&a.flags, &a.in, &a.out, &sc->sc_cfg); 836 (*scr->unpmv)(&a.flags, &a.in, &a.out, &scr->scr_cfg);
466 if (a.out.errno) { 837 if (a.out.errno) {
467 aprint_error_dev(sc->sc_dev, "unpmv %d returned %d\n", 838 aprint_error_dev(sc->sc_dev, "unpmv %d "
468 uc, a.out.errno); 839 "returned %d\n", uc, a.out.errno);
469 return (0); 840 return 0;
470 } 841 }
471 } 842 }
472 843
473 free(sc->sc_romfont, M_DEVBUF); 844 free(scr->scr_romfont, M_DEVBUF);
474 sc->sc_romfont = NULL; 845 scr->scr_romfont = NULL;
475 } 846 }
476#endif 847#endif
477 848
478 return (0); 849 return 0;
479} 850}
480 851
 852/*
 853 * Wrappers around STI code pointers
 854 */
481int 855int
482sti_init(struct sti_softc *sc, int mode) 856sti_init(struct sti_screen *scr, int mode)
483{ 857{
 858 struct sti_rom *rom = scr->scr_rom;
484 struct { 859 struct {
485 struct sti_initflags flags; 860 struct sti_initflags flags;
486 struct sti_initin in; 861 struct sti_initin in;
 862 struct sti_einitin ein;
487 struct sti_initout out; 863 struct sti_initout out;
488 } a; 864 } a;
489 865
 866 KASSERT(rom != NULL);
490 memset(&a, 0, sizeof(a)); 867 memset(&a, 0, sizeof(a));
491 868
492 a.flags.flags = STI_INITF_WAIT | STI_INITF_CMB | STI_INITF_EBET | 869 a.flags.flags = STI_INITF_WAIT | STI_INITF_CMB | STI_INITF_EBET |
493 (mode & STI_TEXTMODE ? STI_INITF_TEXT | STI_INITF_PBET | 870 (mode & STI_TEXTMODE ? STI_INITF_TEXT | STI_INITF_PBET |
494 STI_INITF_PBETI | STI_INITF_ICMT : 0); 871 STI_INITF_PBETI | STI_INITF_ICMT : 0) |
 872 (mode & STI_CLEARSCR ? STI_INITF_CLEAR : 0);
495 a.in.text_planes = 1; 873 a.in.text_planes = 1;
496#ifdef STIDEBUG 874 a.in.ext_in = &a.ein;
497 printf("%s: init,%p(%x, %p, %p, %p)\n", device_xname(sc->sc_dev), 875
498 sc->init, a.flags.flags, &a.in, &a.out, &sc->sc_cfg); 876 DPRINTF(("%s: init,%p(%x, %p, %p, %p)\n",
499#endif 877 device_xname(rom->rom_softc->sc_dev), rom->init, a.flags.flags,
500 (*sc->init)(&a.flags, &a.in, &a.out, &sc->sc_cfg); 878 &a.in, &a.out, &scr->scr_cfg));
501 return (a.out.text_planes != a.in.text_planes || a.out.errno); 879
 880 (*rom->init)(&a.flags, &a.in, &a.out, &scr->scr_cfg);
 881
 882 if (a.out.text_planes != a.in.text_planes)
 883 return -1; /* not colliding with sti errno values */
 884 return a.out.errno;
502} 885}
503 886
504int 887int
505sti_inqcfg(struct sti_softc *sc, struct sti_inqconfout *out) 888sti_inqcfg(struct sti_screen *scr, struct sti_inqconfout *out)
506{ 889{
 890 struct sti_rom *rom = scr->scr_rom;
507 struct { 891 struct {
508 struct sti_inqconfflags flags; 892 struct sti_inqconfflags flags;
509 struct sti_inqconfin in; 893 struct sti_inqconfin in;
510 } a; 894 } a;
511 895
512 memset(&a, 0, sizeof(a)); 896 memset(&a, 0, sizeof(a));
513 897
514 a.flags.flags = STI_INQCONFF_WAIT; 898 a.flags.flags = STI_INQCONFF_WAIT;
515 (*sc->inqconf)(&a.flags, &a.in, out, &sc->sc_cfg); 899 (*rom->inqconf)(&a.flags, &a.in, out, &scr->scr_cfg);
516 900
517 return out->errno; 901 return out->errno;
518} 902}
519 903
520void 904void
521sti_bmove(struct sti_softc *sc, int x1, int y1, int x2, int y2, int h, int w, 905sti_bmove(struct sti_screen *scr, int x1, int y1, int x2, int y2, int h, int w,
522 enum sti_bmove_funcs f) 906 enum sti_bmove_funcs f)
523{ 907{
 908 struct sti_rom *rom = scr->scr_rom;
524 struct { 909 struct {
525 struct sti_blkmvflags flags; 910 struct sti_blkmvflags flags;
526 struct sti_blkmvin in; 911 struct sti_blkmvin in;
527 struct sti_blkmvout out; 912 struct sti_blkmvout out;
528 } a; 913 } a;
529 914
530 memset(&a, 0, sizeof(a)); 915 memset(&a, 0, sizeof(a));
531 916
532 a.flags.flags = STI_BLKMVF_WAIT; 917 a.flags.flags = STI_BLKMVF_WAIT;
533 switch (f) { 918 switch (f) {
534 case bmf_clear: 919 case bmf_clear:
535 a.flags.flags |= STI_BLKMVF_CLR; 920 a.flags.flags |= STI_BLKMVF_CLR;
536 a.in.bg_colour = STI_COLOUR_BLACK; 921 a.in.bg_colour = STI_COLOUR_BLACK;
@@ -543,316 +928,387 @@ sti_bmove(struct sti_softc *sc, int x1,  @@ -543,316 +928,387 @@ sti_bmove(struct sti_softc *sc, int x1,
543 case bmf_invert: 928 case bmf_invert:
544 a.flags.flags |= STI_BLKMVF_COLR; 929 a.flags.flags |= STI_BLKMVF_COLR;
545 a.in.fg_colour = STI_COLOUR_BLACK; 930 a.in.fg_colour = STI_COLOUR_BLACK;
546 a.in.bg_colour = STI_COLOUR_WHITE; 931 a.in.bg_colour = STI_COLOUR_WHITE;
547 break; 932 break;
548 } 933 }
549 a.in.srcx = x1; 934 a.in.srcx = x1;
550 a.in.srcy = y1; 935 a.in.srcy = y1;
551 a.in.dstx = x2; 936 a.in.dstx = x2;
552 a.in.dsty = y2; 937 a.in.dsty = y2;
553 a.in.height = h; 938 a.in.height = h;
554 a.in.width = w; 939 a.in.width = w;
555 940
556 (*sc->blkmv)(&a.flags, &a.in, &a.out, &sc->sc_cfg); 941 (*rom->blkmv)(&a.flags, &a.in, &a.out, &scr->scr_cfg);
557#ifdef STIDEBUG 942#ifdef STIDEBUG
558 if (a.out.errno) 943 if (a.out.errno)
559 aprint_error_dev(sc->sc_dev, "blkmv returned %d\n", 944 printf("%s: blkmv returned %d\n",
560 a.out.errno); 945 device_xname(rom->rom_softc->sc_dev), a.out.errno);
561#endif 946#endif
562} 947}
563 948
564int 949int
565sti_setcment(struct sti_softc *sc, u_int i, u_char r, u_char g, u_char b) 950sti_setcment(struct sti_screen *scr, u_int i, u_char r, u_char g, u_char b)
566{ 951{
 952 struct sti_rom *rom = scr->scr_rom;
567 struct { 953 struct {
568 struct sti_scmentflags flags; 954 struct sti_scmentflags flags;
569 struct sti_scmentin in; 955 struct sti_scmentin in;
570 struct sti_scmentout out; 956 struct sti_scmentout out;
571 } a; 957 } a;
572 958
573 memset(&a, 0, sizeof(a)); 959 memset(&a, 0, sizeof(a));
574 960
575 a.flags.flags = STI_SCMENTF_WAIT; 961 a.flags.flags = STI_SCMENTF_WAIT;
576 a.in.entry = i; 962 a.in.entry = i;
577 a.in.value = (r << 16) | (g << 8) | b; 963 a.in.value = (r << 16) | (g << 8) | b;
578 964
579 (*sc->scment)(&a.flags, &a.in, &a.out, &sc->sc_cfg); 965 (*rom->scment)(&a.flags, &a.in, &a.out, &scr->scr_cfg);
580 966
581 return a.out.errno; 967 return a.out.errno;
582} 968}
583 969
 970/*
 971 * wsdisplay accessops
 972 */
584int 973int
585sti_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l) 974sti_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
586{ 975{
587 struct sti_softc *sc = v; 976 struct sti_screen *scr = (struct sti_screen *)v;
 977 struct sti_rom *rom = scr->scr_rom;
588 struct wsdisplay_fbinfo *wdf; 978 struct wsdisplay_fbinfo *wdf;
589 struct wsdisplay_cmap *cmapp; 979 struct wsdisplay_cmap *cmapp;
590 u_int mode, idx, count; 980 u_int mode, idx, count;
591 int i, ret; 981 int i, ret;
592 982
593 ret = 0; 983 ret = 0;
594 switch (cmd) { 984 switch (cmd) {
595 case WSDISPLAYIO_GMODE: 985 case WSDISPLAYIO_GMODE:
596 *(u_int *)data = sc->sc_wsmode; 986 *(u_int *)data = scr->scr_wsmode;
597 break; 987 break;
598 988
599 case WSDISPLAYIO_SMODE: 989 case WSDISPLAYIO_SMODE:
600 mode = *(u_int *)data; 990 mode = *(u_int *)data;
601 if (sc->sc_wsmode == WSDISPLAYIO_MODE_EMUL && 991 if (scr->scr_wsmode == WSDISPLAYIO_MODE_EMUL &&
602 mode == WSDISPLAYIO_MODE_DUMBFB) 992 mode == WSDISPLAYIO_MODE_DUMBFB)
603 ret = sti_init(sc, 0); 993 ret = sti_init(scr, 0);
604 else if (sc->sc_wsmode == WSDISPLAYIO_MODE_DUMBFB && 994 else if (scr->scr_wsmode == WSDISPLAYIO_MODE_DUMBFB &&
605 mode == WSDISPLAYIO_MODE_EMUL) 995 mode == WSDISPLAYIO_MODE_EMUL)
606 ret = sti_init(sc, STI_TEXTMODE); 996 ret = sti_init(scr, STI_TEXTMODE);
607 sc->sc_wsmode = mode; 997 scr->scr_wsmode = mode;
608 break; 998 break;
609 999
610 case WSDISPLAYIO_GTYPE: 1000 case WSDISPLAYIO_GTYPE:
611 *(u_int *)data = WSDISPLAY_TYPE_STI; 1001 *(u_int *)data = WSDISPLAY_TYPE_STI;
612 break; 1002 break;
613 1003
614 case WSDISPLAYIO_GINFO: 1004 case WSDISPLAYIO_GINFO:
615 wdf = (struct wsdisplay_fbinfo *)data; 1005 wdf = (struct wsdisplay_fbinfo *)data;
616 wdf->height = sc->sc_cfg.scr_height; 1006 wdf->height = scr->scr_cfg.scr_height;
617 wdf->width = sc->sc_cfg.scr_width; 1007 wdf->width = scr->scr_cfg.scr_width;
618 wdf->depth = sc->sc_bpp; 1008 wdf->depth = scr->scr_bpp;
619 wdf->cmsize = STI_NCMAP; 1009 if (rom->scment == NULL)
 1010 wdf->cmsize = 0;
 1011 else
 1012 wdf->cmsize = STI_NCMAP;
620 break; 1013 break;
621 1014
622 case WSDISPLAYIO_LINEBYTES: 1015 case WSDISPLAYIO_LINEBYTES:
623 *(u_int *)data = sc->sc_cfg.fb_width; 1016 *(u_int *)data = scr->scr_cfg.fb_width;
624 break; 1017 break;
625 1018
626 case WSDISPLAYIO_GETCMAP: 1019 case WSDISPLAYIO_GETCMAP:
627 if (sc->scment == NULL) 1020 if (rom->scment == NULL)
628 return ENOTTY; 1021 return ENOTTY;
629 cmapp = (struct wsdisplay_cmap *)data; 1022 cmapp = (struct wsdisplay_cmap *)data;
630 idx = cmapp->index; 1023 idx = cmapp->index;
631 count = cmapp->count; 1024 count = cmapp->count;
632 if (idx > STI_NCMAP || idx + count >= STI_NCMAP) 1025 if (idx >= STI_NCMAP || idx + count > STI_NCMAP)
633 return EINVAL; 1026 return EINVAL;
634 if ((ret = copyout(&sc->sc_rcmap[idx], cmapp->red, count))) 1027 if ((ret = copyout(&scr->scr_rcmap[idx], cmapp->red, count)))
635 break; 1028 break;
636 if ((ret = copyout(&sc->sc_gcmap[idx], cmapp->green, count))) 1029 if ((ret = copyout(&scr->scr_gcmap[idx], cmapp->green, count)))
637 break; 1030 break;
638 if ((ret = copyout(&sc->sc_bcmap[idx], cmapp->blue, count))) 1031 if ((ret = copyout(&scr->scr_bcmap[idx], cmapp->blue, count)))
639 break; 1032 break;
640 break; 1033 break;
641 1034
642 case WSDISPLAYIO_PUTCMAP: 1035 case WSDISPLAYIO_PUTCMAP:
643 if (sc->scment == NULL) 1036 if (rom->scment == NULL)
644 return ENOTTY; 1037 return ENOTTY;
645 cmapp = (struct wsdisplay_cmap *)data; 1038 cmapp = (struct wsdisplay_cmap *)data;
646 idx = cmapp->index; 1039 idx = cmapp->index;
647 count = cmapp->count; 1040 count = cmapp->count;
648 if (idx > STI_NCMAP || idx + count >= STI_NCMAP) 1041 if (idx >= STI_NCMAP || idx + count > STI_NCMAP)
649 return EINVAL; 1042 return EINVAL;
650 if ((ret = copyin(cmapp->red, &sc->sc_rcmap[idx], count))) 1043 if ((ret = copyin(cmapp->red, &scr->scr_rcmap[idx], count)))
651 break; 1044 break;
652 if ((ret = copyin(cmapp->green, &sc->sc_gcmap[idx], count))) 1045 if ((ret = copyin(cmapp->green, &scr->scr_gcmap[idx], count)))
653 break; 1046 break;
654 if ((ret = copyin(cmapp->blue, &sc->sc_bcmap[idx], count))) 1047 if ((ret = copyin(cmapp->blue, &scr->scr_bcmap[idx], count)))
655 break; 1048 break;
656 for (i = idx + count - 1; i >= idx; i--) 1049 for (i = idx + count - 1; i >= idx; i--)
657 if ((ret = sti_setcment(sc, i, sc->sc_rcmap[i], 1050 if ((ret = sti_setcment(scr, i, scr->scr_rcmap[i],
658 sc->sc_gcmap[i], sc->sc_bcmap[i]))) { 1051 scr->scr_gcmap[i], scr->scr_bcmap[i]))) {
659#ifdef STIDEBUG 1052
660 printf("sti_ioctl: " 1053 DPRINTF(("sti_ioctl: "
661 "sti_setcment(%d, %u, %u, %u): %%d\n", i, 1054 "sti_setcment(%d, %u, %u, %u): %%d\n", i,
662 (u_int)sc->sc_rcmap[i], 1055 (u_int)scr->scr_rcmap[i],
663 (u_int)sc->sc_gcmap[i], 1056 (u_int)scr->scr_gcmap[i],
664 (u_int)sc->sc_bcmap[i]); 1057 (u_int)scr->scr_bcmap[i]));
665#endif 1058
666 ret = EINVAL; 1059 ret = EINVAL;
667 break; 1060 break;
668 } 1061 }
669 break; 1062 break;
670 1063
671 case WSDISPLAYIO_SVIDEO: 1064 case WSDISPLAYIO_SVIDEO:
672 case WSDISPLAYIO_GVIDEO: 1065 case WSDISPLAYIO_GVIDEO:
673 case WSDISPLAYIO_GCURPOS: 1066 case WSDISPLAYIO_GCURPOS:
674 case WSDISPLAYIO_SCURPOS: 1067 case WSDISPLAYIO_SCURPOS:
675 case WSDISPLAYIO_GCURMAX: 1068 case WSDISPLAYIO_GCURMAX:
676 case WSDISPLAYIO_GCURSOR: 1069 case WSDISPLAYIO_GCURSOR:
677 case WSDISPLAYIO_SCURSOR: 1070 case WSDISPLAYIO_SCURSOR:
678 default: 1071 default:
679 return (ENOTTY); /* not supported yet */ 1072 return ENOTTY; /* not supported yet */
680 } 1073 }
681 1074
682 return (ret); 1075 return ret;
683} 1076}
684 1077
685paddr_t 1078paddr_t
686sti_mmap(void *v, void *vs, off_t offset, int prot) 1079sti_mmap(void *v, void *vs, off_t offset, int prot)
687{ 1080{
 1081#if 0
 1082 struct sti_screen *scr = (struct sti_screen *)v;
 1083#endif
688 /* XXX not finished */ 1084 /* XXX not finished */
689 return -1; 1085 return -1;
690} 1086}
691 1087
692int 1088int
693sti_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep, 1089sti_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
694 int *cxp, int *cyp, long *defattr) 1090 int *cxp, int *cyp, long *defattr)
695{ 1091{
696 struct sti_softc *sc = v; 1092 struct sti_screen *scr = (struct sti_screen *)v;
697 1093
698 if (sc->sc_nscreens > 0) 1094 if (scr->scr_nscreens > 0)
699 return ENOMEM; 1095 return ENOMEM;
700 1096
701 *cookiep = sc; 1097 *cookiep = scr;
702 *cxp = 0; 1098 *cxp = 0;
703 *cyp = 0; 1099 *cyp = 0;
704 sti_alloc_attr(sc, 0, 0, 0, defattr); 1100 sti_alloc_attr(scr, 0, 0, 0, defattr);
705 sc->sc_nscreens++; 1101 scr->scr_nscreens++;
 1102
706 return 0; 1103 return 0;
707} 1104}
708 1105
709void 1106void
710sti_free_screen(void *v, void *cookie) 1107sti_free_screen(void *v, void *cookie)
711{ 1108{
712 struct sti_softc *sc = v; 1109 struct sti_screen *scr = (struct sti_screen *)v;
713 1110
714 sc->sc_nscreens--; 1111 scr->scr_nscreens--;
715} 1112}
716 1113
717int 1114int
718sti_show_screen(void *v, void *cookie, int waitok, void (*cb)(void *, int, int), void *cbarg) 1115sti_show_screen(void *v, void *cookie, int waitok, void (*cb)(void *, int, int),
 1116 void *cbarg)
719{ 1117{
 1118#if 0
 1119 struct sti_screen *scr = (struct sti_screen *)v;
 1120#endif
 1121
720 return 0; 1122 return 0;
721} 1123}
722 1124
723int 1125int
724sti_load_font(void *v, void *cookie, struct wsdisplay_font *font) 1126sti_load_font(void *v, void *cookie, struct wsdisplay_font *font)
725{ 1127{
 1128#if 0
 1129 struct sti_screen *scr = (struct sti_screen *)v;
 1130#endif
 1131
726 return -1; 1132 return -1;
727} 1133}
728 1134
 1135/*
 1136 * wsdisplay emulops
 1137 */
729void 1138void
730sti_cursor(void *v, int on, int row, int col) 1139sti_cursor(void *v, int on, int row, int col)
731{ 1140{
732 struct sti_softc *sc = v; 1141 struct sti_screen *scr = (struct sti_screen *)v;
733 struct sti_font *fp = &sc->sc_curfont; 1142 struct sti_font *fp = &scr->scr_curfont;
734 1143
735 sti_bmove(sc, col * fp->width, row * fp->height, col * fp->width, 1144 sti_bmove(scr, col * fp->width, row * fp->height, col * fp->width,
736 row * fp->height, fp->height, fp->width, bmf_invert); 1145 row * fp->height, fp->height, fp->width, bmf_invert);
737} 1146}
738 1147
 1148/*
 1149 * ISO 8859-1 part of Unicode to HP Roman font index conversion array.
 1150 */
 1151static const uint8_t
 1152sti_unitoroman[0x100 - 0xa0] = {
 1153 0xa0, 0xb8, 0xbf, 0xbb, 0xba, 0xbc, 0, 0xbd,
 1154 0xab, 0, 0xf9, 0xfb, 0, 0xf6, 0, 0xb0,
 1155
 1156 0xb3, 0xfe, 0, 0, 0xa8, 0xf3, 0xf4, 0xf2,
 1157 0, 0, 0xfa, 0xfd, 0xf7, 0xf8, 0, 0xb9,
 1158
 1159 0xa1, 0xe0, 0xa2, 0xe1, 0xd8, 0xd0, 0xd3, 0xb4,
 1160 0xa3, 0xdc, 0xa4, 0xa5, 0xe6, 0xe5, 0xa6, 0xa7,
 1161
 1162 0xe3, 0xb6, 0xe8, 0xe7, 0xdf, 0xe9, 0xda, 0,
 1163 0xd2, 0xad, 0xed, 0xae, 0xdb, 0xb1, 0xf0, 0xde,
 1164
 1165 0xc8, 0xc4, 0xc0, 0xe2, 0xcc, 0xd4, 0xd7, 0xb5,
 1166 0xc9, 0xc5, 0xc1, 0xcd, 0xd9, 0xd5, 0xd1, 0xdd,
 1167
 1168 0xe4, 0xb7, 0xca, 0xc6, 0xc2, 0xea, 0xce, 0,
 1169 0xd6, 0xcb, 0xc7, 0xc3, 0xcf, 0xb2, 0xf1, 0xef
 1170};
 1171
739int 1172int
740sti_mapchar(void *v, int uni, u_int *index) 1173sti_mapchar(void *v, int uni, u_int *index)
741{ 1174{
742 if (uni < 256) 1175 struct sti_screen *scr = (struct sti_screen *)v;
743 *index = uni; 1176 struct sti_font *fp = &scr->scr_curfont;
 1177 int c;
 1178
 1179 switch (fp->type) {
 1180 case STI_FONT_HPROMAN8:
 1181 if (uni >= 0x80 && uni < 0xa0)
 1182 c = -1;
 1183 else if (uni >= 0xa0 && uni < 0x100) {
 1184 c = (int)sti_unitoroman[uni - 0xa0];
 1185 if (c == 0)
 1186 c = -1;
 1187 } else
 1188 c = uni;
 1189 break;
 1190 default:
 1191 c = uni;
 1192 break;
 1193 }
744 1194
745 return 1; 1195 if (c == -1 || c < fp->first || c > fp->last) {
 1196 *index = ' ';
 1197 return 0;
 1198 }
 1199
 1200 *index = c;
 1201 return 5;
746} 1202}
747 1203
748void 1204void
749sti_putchar(void *v, int row, int col, u_int uc, long attr) 1205sti_putchar(void *v, int row, int col, u_int uc, long attr)
750{ 1206{
751 struct sti_softc *sc = v; 1207 struct sti_screen *scr = (struct sti_screen *)v;
752 struct sti_font *fp = &sc->sc_curfont; 1208 struct sti_rom *rom = scr->scr_rom;
 1209 struct sti_font *fp = &scr->scr_curfont;
753 1210
754 if (sc->sc_romfont != NULL) { 1211 if (scr->scr_romfont != NULL) {
755 /* 1212 /*
756 * Font is in memory, use unpmv 1213 * Font is in memory, use unpmv
757 */ 1214 */
758 struct { 1215 struct {
759 struct sti_unpmvflags flags; 1216 struct sti_unpmvflags flags;
760 struct sti_unpmvin in; 1217 struct sti_unpmvin in;
761 struct sti_unpmvout out; 1218 struct sti_unpmvout out;
762 } a; 1219 } a;
763 1220
764 memset(&a, 0, sizeof(a)); 1221 memset(&a, 0, sizeof(a));
765 1222
766 a.flags.flags = STI_UNPMVF_WAIT; 1223 a.flags.flags = STI_UNPMVF_WAIT;
767 /* XXX does not handle text attributes */ 1224 /* XXX does not handle text attributes */
768 a.in.fg_colour = STI_COLOUR_WHITE; 1225 a.in.fg_colour = STI_COLOUR_WHITE;
769 a.in.bg_colour = STI_COLOUR_BLACK; 1226 a.in.bg_colour = STI_COLOUR_BLACK;
770 a.in.x = col * fp->width; 1227 a.in.x = col * fp->width;
771 a.in.y = row * fp->height; 1228 a.in.y = row * fp->height;
772 a.in.font_addr = sc->sc_romfont; 1229 a.in.font_addr = scr->scr_romfont;
773 a.in.index = uc; 1230 a.in.index = uc;
774 1231
775 (*sc->unpmv)(&a.flags, &a.in, &a.out, &sc->sc_cfg); 1232 (*rom->unpmv)(&a.flags, &a.in, &a.out, &scr->scr_cfg);
776 } else { 1233 } else {
777 /* 1234 /*
778 * Font is in frame buffer, use blkmv 1235 * Font is in frame buffer, use blkmv
779 */ 1236 */
780 struct { 1237 struct {
781 struct sti_blkmvflags flags; 1238 struct sti_blkmvflags flags;
782 struct sti_blkmvin in; 1239 struct sti_blkmvin in;
783 struct sti_blkmvout out; 1240 struct sti_blkmvout out;
784 } a; 1241 } a;
785 1242
786 memset(&a, 0, sizeof(a)); 1243 memset(&a, 0, sizeof(a));
787 1244
788 a.flags.flags = STI_BLKMVF_WAIT; 1245 a.flags.flags = STI_BLKMVF_WAIT;
789 /* XXX does not handle text attributes */ 1246 /* XXX does not handle text attributes */
790 a.in.fg_colour = STI_COLOUR_WHITE; 1247 a.in.fg_colour = STI_COLOUR_WHITE;
791 a.in.bg_colour = STI_COLOUR_BLACK; 1248 a.in.bg_colour = STI_COLOUR_BLACK;
792 1249
793 a.in.srcx = ((uc - fp->first) / sc->sc_fontmaxcol) * 1250 a.in.srcx = ((uc - fp->first) / scr->scr_fontmaxcol) *
794 fp->width + sc->sc_fontbase; 1251 fp->width + scr->scr_fontbase;
795 a.in.srcy = ((uc - fp->first) % sc->sc_fontmaxcol) * 1252 a.in.srcy = ((uc - fp->first) % scr->scr_fontmaxcol) *
796 fp->height; 1253 fp->height;
797 a.in.dstx = col * fp->width; 1254 a.in.dstx = col * fp->width;
798 a.in.dsty = row * fp->height; 1255 a.in.dsty = row * fp->height;
799 a.in.height = fp->height; 1256 a.in.height = fp->height;
800 a.in.width = fp->width; 1257 a.in.width = fp->width;
801 1258
802 (*sc->blkmv)(&a.flags, &a.in, &a.out, &sc->sc_cfg); 1259 (*rom->blkmv)(&a.flags, &a.in, &a.out, &scr->scr_cfg);
803 } 1260 }
804} 1261}
805 1262
806void 1263void
807sti_copycols(void *v, int row, int srccol, int dstcol, int ncols) 1264sti_copycols(void *v, int row, int srccol, int dstcol, int ncols)
808{ 1265{
809 struct sti_softc *sc = v; 1266 struct sti_screen *scr = (struct sti_screen *)v;
810 struct sti_font *fp = &sc->sc_curfont; 1267 struct sti_font *fp = &scr->scr_curfont;
811 1268
812 sti_bmove(sc, srccol * fp->width, row * fp->height, dstcol * fp->width, 1269 sti_bmove(scr, srccol * fp->width, row * fp->height, dstcol * fp->width,
813 row * fp->height, fp->height, ncols * fp->width, bmf_copy); 1270 row * fp->height, fp->height, ncols * fp->width, bmf_copy);
814} 1271}
815 1272
816void 1273void
817sti_erasecols(void *v, int row, int startcol, int ncols, long attr) 1274sti_erasecols(void *v, int row, int startcol, int ncols, long attr)
818{ 1275{
819 struct sti_softc *sc = v; 1276 struct sti_screen *scr = (struct sti_screen *)v;
820 struct sti_font *fp = &sc->sc_curfont; 1277 struct sti_font *fp = &scr->scr_curfont;
821 1278
822 sti_bmove(sc, startcol * fp->width, row * fp->height, 1279 sti_bmove(scr, startcol * fp->width, row * fp->height,
823 startcol * fp->width, row * fp->height, fp->height, 1280 startcol * fp->width, row * fp->height, fp->height,
824 ncols * fp->width, bmf_clear); 1281 ncols * fp->width, bmf_clear);
825} 1282}
826 1283
827void 1284void
828sti_copyrows(void *v, int srcrow, int dstrow, int nrows) 1285sti_copyrows(void *v, int srcrow, int dstrow, int nrows)
829{ 1286{
830 struct sti_softc *sc = v; 1287 struct sti_screen *scr = (struct sti_screen *)v;
831 struct sti_font *fp = &sc->sc_curfont; 1288 struct sti_font *fp = &scr->scr_curfont;
832 1289
833 sti_bmove(sc, sc->sc_cfg.oscr_width, srcrow * fp->height, 1290 sti_bmove(scr, 0, srcrow * fp->height, 0, dstrow * fp->height,
834 sc->sc_cfg.oscr_width, dstrow * fp->height, 1291 nrows * fp->height, scr->scr_cfg.scr_width, bmf_copy);
835 nrows * fp->height, sc->sc_cfg.scr_width, bmf_copy); 
836} 1292}
837 1293
838void 1294void
839sti_eraserows(void *v, int srcrow, int nrows, long attr) 1295sti_eraserows(void *v, int srcrow, int nrows, long attr)
840{ 1296{
841 struct sti_softc *sc = v; 1297 struct sti_screen *scr = (struct sti_screen *)v;
842 struct sti_font *fp = &sc->sc_curfont; 1298 struct sti_font *fp = &scr->scr_curfont;
843 1299
844 sti_bmove(sc, sc->sc_cfg.oscr_width, srcrow * fp->height, 1300 sti_bmove(scr, 0, srcrow * fp->height, 0, srcrow * fp->height,
845 sc->sc_cfg.oscr_width, srcrow * fp->height, 1301 nrows * fp->height, scr->scr_cfg.scr_width, bmf_clear);
846 nrows * fp->height, sc->sc_cfg.scr_width, bmf_clear); 
847} 1302}
848 1303
849int 1304int
850sti_alloc_attr(void *v, int fg, int bg, int flags, long *pattr) 1305sti_alloc_attr(void *v, int fg, int bg, int flags, long *pattr)
851{ 1306{
852 /* struct sti_softc *sc = v; */ 1307#if 0
 1308 struct sti_screen *scr = (struct sti_screen *)v;
 1309#endif
853 1310
854 *pattr = 0; 1311 *pattr = 0;
855 1312
856 return 0; 1313 return 0;
857} 1314}
858 

cvs diff -r1.4 -r1.5 src/sys/dev/ic/stireg.h (expand / switch to unified diff)

--- src/sys/dev/ic/stireg.h 2010/11/01 06:41:50 1.4
+++ src/sys/dev/ic/stireg.h 2010/11/09 12:24:48 1.5
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: stireg.h,v 1.4 2010/11/01 06:41:50 skrll Exp $ */ 1/* $NetBSD: stireg.h,v 1.5 2010/11/09 12:24:48 skrll Exp $ */
2 2
3/* $OpenBSD: stireg.h,v 1.8 2003/08/19 02:52:38 mickey Exp $ */ 3/* $OpenBSD: stireg.h,v 1.13 2009/01/28 17:37:40 miod Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 2000 Michael Shalayeff 6 * Copyright (c) 2000 Michael Shalayeff
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
@@ -46,42 +46,49 @@ @@ -46,42 +46,49 @@
46#define STI_BLOCK_MOVE 3 46#define STI_BLOCK_MOVE 3
47#define STI_SELF_TEST 4 47#define STI_SELF_TEST 4
48#define STI_EXCEP_HDLR 5 48#define STI_EXCEP_HDLR 5
49#define STI_INQ_CONF 6 49#define STI_INQ_CONF 6
50#define STI_SCM_ENT 7 50#define STI_SCM_ENT 7
51#define STI_DMA_CTRL 8 51#define STI_DMA_CTRL 8
52#define STI_FLOW_CTRL 9 52#define STI_FLOW_CTRL 9
53#define STI_UTIMING 10 53#define STI_UTIMING 10
54#define STI_PROC_MGR 11 54#define STI_PROC_MGR 11
55#define STI_UTIL 12 55#define STI_UTIL 12
56#define STI_END 13 56#define STI_END 13
57#define STI_CODECNT 16 57#define STI_CODECNT 16
58 58
 59#define STI_CODEBASE_MAIN 0x40
 60#define STI_CODEBASE_ALT 0x80
 61
 62#define STI_CODEBASE_PA STI_CODEBASE_MAIN
 63#define STI_CODEBASE_M68K STI_CODEBASE_ALT
 64#define STI_CODEBASE_PA64 STI_CODEBASE_ALT
 65
59/* sti returns */ 66/* sti returns */
60#define STI_OK 0 67#define STI_OK 0
61#define STI_FAIL -1 68#define STI_FAIL -1
62#define STI_NRDY 1 69#define STI_NRDY 1
63 70
64/* sti errno */ 71/* sti errno */
65#define STI_NOERRNO 0 /* no error */ 72#define STI_NOERRNO 0 /* no error */
66#define STI_BADREENTLVL 1 /* bad reentry level */ 73#define STI_BADREENTLVL 1 /* bad reentry level */
67#define STI_NOREGIONSDEF 2 /* region table is not setup */ 74#define STI_NOREGIONSDEF 2 /* region table is not setup */
68#define STI_ILLNPLANES 3 /* invalid num of text planes */ 75#define STI_ILLNPLANES 3 /* invalid num of text planes */
69#define STI_ILLINDEX 4 /* invalid fond index */ 76#define STI_ILLINDEX 4 /* invalid font index */
70#define STI_ILLLOC 5 /* invalid font location */ 77#define STI_ILLLOC 5 /* invalid font location */
71#define STI_ILLCOLOUR 6 /* invalid colour */ 78#define STI_ILLCOLOUR 6 /* invalid colour */
72#define STI_ILLBLKMVFROM 7 /* invalid from in blkmv */ 79#define STI_ILLBLKMVFROM 7 /* invalid from in blkmv */
73#define STI_ILLBLKMVTO 8 /* invalid to in blkmv */ 80#define STI_ILLBLKMVTO 8 /* invalid to in blkmv */
74#define STI_ILLBLKMVSIZE 9 /* invalid siz in blkmv */ 81#define STI_ILLBLKMVSIZE 9 /* invalid size in blkmv */
75#define STI_BEIUNSUPP 10 /* bus error ints unsupported */ 82#define STI_BEIUNSUPP 10 /* bus error ints unsupported */
76#define STI_UNXPBE 11 /* unexpected bus error */ 83#define STI_UNXPBE 11 /* unexpected bus error */
77#define STI_UNXHWF 12 /* unexpected hardware failure */ 84#define STI_UNXHWF 12 /* unexpected hardware failure */
78#define STI_NEGCFG 13 /* no ext global config struct */ 85#define STI_NEGCFG 13 /* no ext global config struct */
79#define STI_NEIG 14 /* no ext init struct */ 86#define STI_NEIG 14 /* no ext init struct */
80#define STI_ILLSCME 15 /* invalid set cmap entry */ 87#define STI_ILLSCME 15 /* invalid set cmap entry */
81#define STI_ILLCMVAL 16 /* invalid cmap value */ 88#define STI_ILLCMVAL 16 /* invalid cmap value */
82#define STI_NORESMEM 17 /* no requested global memory */ 89#define STI_NORESMEM 17 /* no requested global memory */
83#define STI_RESMEMCORR 18 /* reserved memory corrupted */ 90#define STI_RESMEMCORR 18 /* reserved memory corrupted */
84#define STI_ILLNTBLKMV 19 /* invalid non-text blkmv */ 91#define STI_ILLNTBLKMV 19 /* invalid non-text blkmv */
85#define STI_ILLMONITOR 20 /* monitor selection is out of range */ 92#define STI_ILLMONITOR 20 /* monitor selection is out of range */
86#define STI_ILLEXCADDR 21 /* invalid excpt handler addr */ 93#define STI_ILLEXCADDR 21 /* invalid excpt handler addr */
87#define STI_ILLEXCFLAGS 22 /* invalid excpt handler flags */ 94#define STI_ILLEXCFLAGS 22 /* invalid excpt handler flags */
@@ -96,38 +103,36 @@ @@ -96,38 +103,36 @@
96#define STI_NOOUTPTR 254 /* no way you can get it */ 103#define STI_NOOUTPTR 254 /* no way you can get it */
97#define STI_NOLOCK 255 /* kernel dishonour graphics lock */ 104#define STI_NOLOCK 255 /* kernel dishonour graphics lock */
98 105
99/* colours */ 106/* colours */
100#define STI_COLOUR_BLACK 0 107#define STI_COLOUR_BLACK 0
101#define STI_COLOUR_WHITE 1 108#define STI_COLOUR_WHITE 1
102#define STI_COLOUR_RED 2 109#define STI_COLOUR_RED 2
103#define STI_COLOUR_YELLOW 3 110#define STI_COLOUR_YELLOW 3
104#define STI_COLOUR_GREEN 4 111#define STI_COLOUR_GREEN 4
105#define STI_COLOUR_CYAN 5 112#define STI_COLOUR_CYAN 5
106#define STI_COLOUR_BLUE 6 113#define STI_COLOUR_BLUE 6
107#define STI_COLOUR_MAGENTA 7 114#define STI_COLOUR_MAGENTA 7
108 115
109#pragma pack(1) 
110 
111 /* LSB high */ 116 /* LSB high */
112struct sti_dd { 117struct sti_dd {
113 uint32_t dd_type; /* 0x00 device type */ 118 uint32_t dd_type; /* 0x00 device type */
114#define STI_DEVTYPE1 1 119#define STI_DEVTYPE1 1
115#define STI_DEVTYPE4 3 120#define STI_DEVTYPE4 3
116 uint8_t dd_unused; 121 uint8_t dd_unused;
117 uint8_t dd_nmon; /* 0x05 number monitor rates */ 122 uint8_t dd_nmon; /* 0x05 number monitor rates */
118 uint8_t dd_grrev; /* 0x06 global rom revision */ 123 uint8_t dd_grrev; /* 0x06 global rom revision */
119 uint8_t dd_lrrev; /* 0x07 local rom revision */ 124 uint8_t dd_lrrev; /* 0x07 local rom revision */
120 uint8_t dd_grid[8]; /* 0x08 graphics id */ 125 uint32_t dd_grid[2]; /* 0x08 graphics id */
121#define STI_DEV4_DD_GRID 0x08 /* offset for STI_DEVTYPE4 */ 126#define STI_DEV4_DD_GRID 0x08 /* offset for STI_DEVTYPE4 */
122#define STI_DEV1_DD_GRID 0x10 /* offset for STI_DEVTYPE1 */ 127#define STI_DEV1_DD_GRID 0x10 /* offset for STI_DEVTYPE1 */
123 uint32_t dd_fntaddr; /* 0x10 font start address */ 128 uint32_t dd_fntaddr; /* 0x10 font start address */
124 uint32_t dd_maxst; /* 0x14 max state storage */ 129 uint32_t dd_maxst; /* 0x14 max state storage */
125 uint32_t dd_romend; /* 0x18 rom last address */ 130 uint32_t dd_romend; /* 0x18 rom last address */
126#define STI_DEV4_DD_ROMEND 0x18 /* offset for STI_DEVTYPE4 */ 131#define STI_DEV4_DD_ROMEND 0x18 /* offset for STI_DEVTYPE4 */
127#define STI_DEV1_DD_ROMEND 0x50 /* offset for STI_DEVTYPE1 */ 132#define STI_DEV1_DD_ROMEND 0x50 /* offset for STI_DEVTYPE1 */
128 uint32_t dd_reglst; /* 0x1c device region list */ 133 uint32_t dd_reglst; /* 0x1c device region list */
129 uint16_t dd_maxreent; /* 0x20 max reent storage */ 134 uint16_t dd_maxreent; /* 0x20 max reent storage */
130 uint16_t dd_maxtimo; /* 0x22 max execution timeout .1 sec */ 135 uint16_t dd_maxtimo; /* 0x22 max execution timeout .1 sec */
131 uint32_t dd_montbl; /* 0x24 mon table address, array of 136 uint32_t dd_montbl; /* 0x24 mon table address, array of
132 names num of dd_nmon */ 137 names num of dd_nmon */
133 uint32_t dd_udaddr; /* 0x28 user data address */ 138 uint32_t dd_udaddr; /* 0x28 user data address */
@@ -145,462 +150,478 @@ struct sti_dd { @@ -145,462 +150,478 @@ struct sti_dd {
145#define STI_BUSSUPPORT_2DECODE 0x80 /* single address decoder */ 150#define STI_BUSSUPPORT_2DECODE 0x80 /* single address decoder */
146 uint8_t dd_ebussup; /* 0x37 extended bus support */ 151 uint8_t dd_ebussup; /* 0x37 extended bus support */
147#define STI_EBUSSUPPORT_DMA 0x01 /* supports dma */ 152#define STI_EBUSSUPPORT_DMA 0x01 /* supports dma */
148#define STI_EBUSSUPPORT_PIOLOCK 0x02 /* no implicit locking for dma */ 153#define STI_EBUSSUPPORT_PIOLOCK 0x02 /* no implicit locking for dma */
149 uint8_t dd_altcodet; /* 0x38 alternate code type */ 154 uint8_t dd_altcodet; /* 0x38 alternate code type */
150#define STI_ALTCODE_UNKNOWN 0x00 155#define STI_ALTCODE_UNKNOWN 0x00
151#define STI_ALTCODE_PA64 0x01 /* alt code is in pa64 */ 156#define STI_ALTCODE_PA64 0x01 /* alt code is in pa64 */
152 uint8_t dd_eddst[3]; /* 0x39 extended DD struct */ 157 uint8_t dd_eddst[3]; /* 0x39 extended DD struct */
153 uint32_t dd_cfbaddr; /* 0x3c CFB address, location of 158 uint32_t dd_cfbaddr; /* 0x3c CFB address, location of
154 X11 driver to be used for 159 X11 driver to be used for
155 servers w/o accel */ 160 servers w/o accel */
156 uint32_t dd_pacode[16]; /* 0x40 routines for pa-risc */ 161 uint32_t dd_pacode[16]; /* 0x40 routines for pa-risc */
157 uint32_t dd_altcode[16]; /* 0x80 routines for m68k/i386 */ 162 uint32_t dd_altcode[16]; /* 0x80 routines for m68k/i386 */
158}; 163} __packed;
 164
 165#define STI_REVISION(maj, min) (((maj) << 4) | ((min) & 0x0f))
159 166
160/* after the last region there is one indirect list ptr */ 167/* after the last region there is one indirect list ptr */
161struct sti_region { 168struct sti_region {
162 u_int offset :14; /* page offset dev io space relative */ 169 u_int offset :14; /* page offset dev io space relative */
163 u_int sys_only: 1; /* whether allow user access */ 170 u_int sys_only: 1; /* whether allow user access */
164 u_int cache : 1; /* map in cache */ 171 u_int cache : 1; /* map in cache */
165 u_int btlb : 1; /* should use BTLB if available */ 172 u_int btlb : 1; /* should use BTLB if available */
166 u_int last : 1; /* last region in the list */ 173 u_int last : 1; /* last region in the list */
167 u_int length :14; /* size in pages */ 174 u_int length :14; /* size in pages */
168}; 175} __packed;
169 176
170struct sti_font { 177struct sti_font {
171 uint16_t first; 178 uint16_t first;
172 uint16_t last; 179 uint16_t last;
173 uint8_t width; 180 uint8_t width;
174 uint8_t height; 181 uint8_t height;
175 uint8_t type; 182 uint8_t type;
176#define STI_FONT_HPROMAN8 1 183#define STI_FONT_HPROMAN8 1
177#define STI_FONT_KANA8 2 184#define STI_FONT_KANA8 2
178 uint8_t bpc; 185 uint8_t bpc;
179 uint32_t next; 186 uint32_t next;
180 uint8_t uheight; 187 uint8_t uheight;
181 uint8_t uoffset; 188 uint8_t uoffset;
182 uint8_t unused[2]; 189 uint8_t unused[2];
183}; 190} __packed;
184 191
185struct sti_fontcfg { 192struct sti_fontcfg {
186 uint16_t first; 193 uint16_t first;
187 uint16_t last; 194 uint16_t last;
188 uint8_t width; 195 uint8_t width;
189 uint8_t height; 196 uint8_t height;
190 uint8_t type; 197 uint8_t type;
191 uint8_t bpc; 198 uint8_t bpc;
192 uint8_t uheight; 199 uint8_t uheight;
193 uint8_t uoffset; 200 uint8_t uoffset;
194}; 201} __packed;
 202
 203typedef struct sti_mon {
 204 uint32_t width: 12;
 205 uint32_t height: 12;
 206 uint32_t hz: 7; /* low 7 bits of refresh rate */
 207 uint32_t flat: 1; /* flatpanel */
 208 uint32_t vesa: 1; /* vesa mode */
 209 uint32_t grey: 1; /* greyscale */
 210 uint32_t dblbuf: 1; /* double buffered */
 211 uint32_t user: 1; /* user-defined mode */
 212 uint32_t stereo: 1; /* stereo display */
 213 uint32_t sam: 1; /* ? */
 214 uint32_t : 15;
 215 uint32_t hz_upper: 3; /* upper 3 bits of refresh rate */
 216 uint32_t font: 8; /* rom font index */
 217} __packed *sti_mon_t;
195 218
196typedef struct sti_ecfg { 219typedef struct sti_ecfg {
197 uint8_t current_monitor; 220 uint8_t current_monitor;
198 uint8_t uf_boot; 221 uint8_t uf_boot;
199 uint16_t power; /* power dissipation Watts */ 222 uint16_t power; /* power dissipation Watts */
200 uint32_t freq_ref; 223 uint32_t freq_ref;
201 uint32_t *addr; /* memory block of size dd_stimemreq */ 224 uint32_t *addr; /* memory block of size dd_stimemreq */
202 void *future; 225 void *future;
203} *sti_ecfg_t; 226} __packed *sti_ecfg_t;
204 227
205typedef struct sti_cfg { 228typedef struct sti_cfg {
206 uint32_t text_planes; 229 uint32_t text_planes;
207 uint16_t scr_width; 230 uint16_t scr_width;
208 uint16_t scr_height; 231 uint16_t scr_height;
209 uint16_t oscr_width; 232 uint16_t oscr_width;
210 uint16_t oscr_height; 233 uint16_t oscr_height;
211 uint16_t fb_width; 234 uint16_t fb_width;
212 uint16_t fb_height; 235 uint16_t fb_height;
213 uint32_t regions[STI_REGION_MAX]; 236 uint32_t regions[STI_REGION_MAX];
214 uint32_t reent_level; 237 uint32_t reent_level;
215 uint32_t *save_addr; 238 uint32_t *save_addr;
216 sti_ecfg_t ext_cfg; 239 sti_ecfg_t ext_cfg;
217} *sti_cfg_t; 240} __packed *sti_cfg_t;
218 241
219 242
220/* routine types */ 243/* routine types */
221#define STI_DEP(n) \ 244#define STI_DEP(n) \
222 typedef int (*sti_##n##_t)( \ 245 typedef int (*sti_##n##_t)( \
223 sti_##n##flags_t, sti_##n##in_t, sti_##n##out_t, sti_cfg_t); 246 sti_##n##flags_t, sti_##n##in_t, sti_##n##out_t, sti_cfg_t);
224 247
225typedef struct sti_initflags { 248typedef struct sti_initflags {
226 uint32_t flags; 249 uint32_t flags;
227#define STI_INITF_WAIT 0x80000000 250#define STI_INITF_WAIT 0x80000000
228#define STI_INITF_RESET 0x40000000 251#define STI_INITF_RESET 0x40000000
229#define STI_INITF_TEXT 0x20000000 252#define STI_INITF_TEXT 0x20000000
230#define STI_INITF_NTEXT 0x10000000 253#define STI_INITF_NTEXT 0x10000000
231#define STI_INITF_CLEAR 0x08000000 254#define STI_INITF_CLEAR 0x08000000
232#define STI_INITF_CMB 0x04000000 /* non-text planes cmap black */ 255#define STI_INITF_CMB 0x04000000 /* non-text planes cmap black */
233#define STI_INITF_EBET 0x02000000 /* enable bus error timer */ 256#define STI_INITF_EBET 0x02000000 /* enable bus error timer */
234#define STI_INITF_EBETI 0x01000000 /* enable bus error timer interrupt */ 257#define STI_INITF_EBETI 0x01000000 /* enable bus error timer interrupt */
235#define STI_INITF_PTS 0x00800000 /* preserve text settings */ 258#define STI_INITF_PTS 0x00800000 /* preserve text settings */
236#define STI_INITF_PNTS 0x00400000 /* preserve non-text settings */ 259#define STI_INITF_PNTS 0x00400000 /* preserve non-text settings */
237#define STI_INITF_PBET 0x00200000 /* preserve BET settings */ 260#define STI_INITF_PBET 0x00200000 /* preserve BET settings */
238#define STI_INITF_PBETI 0x00100000 /* preserve BETI settings */ 261#define STI_INITF_PBETI 0x00100000 /* preserve BETI settings */
239#define STI_INITF_ICMT 0x00080000 /* init cmap for text planes */ 262#define STI_INITF_ICMT 0x00080000 /* init cmap for text planes */
240#define STI_INITF_SCMT 0x00040000 /* change current monitor type */ 263#define STI_INITF_SCMT 0x00040000 /* change current monitor type */
241#define STI_INITF_RIE 0x00020000 /* retain int enables */ 264#define STI_INITF_RIE 0x00020000 /* retain int enables */
242 void *future; 265 void *future;
243} *sti_initflags_t; 266} __packed *sti_initflags_t;
244 267
245typedef struct sti_einitin { 268typedef struct sti_einitin {
246 uint8_t mon_type; 269 uint8_t mon_type;
247 uint8_t pad; 270 uint8_t pad;
248 uint16_t inflight; /* possible on pci */ 271 uint16_t inflight; /* possible on pci */
249 void *future; 272 void *future;
250} *sti_einitin_t; 273} __packed *sti_einitin_t;
251 274
252typedef struct sti_initin { 275typedef struct sti_initin {
253 uint32_t text_planes; /* number of planes for text */ 276 uint32_t text_planes; /* number of planes for text */
254 sti_einitin_t ext_in; 277 sti_einitin_t ext_in;
255} *sti_initin_t; 278} __packed *sti_initin_t;
256 279
257typedef struct sti_initout { 280typedef struct sti_initout {
258 int32_t errno; 281 int32_t errno;
259 uint32_t text_planes; /* number of planes used for text */ 282 uint32_t text_planes; /* number of planes used for text */
260 void *future; 283 void *future;
261} *sti_initout_t; 284} __packed *sti_initout_t;
262 285
263STI_DEP(init); 286STI_DEP(init);
264 287
265typedef struct sti_mgmtflags { 288typedef struct sti_mgmtflags {
266 uint32_t flags; 289 uint32_t flags;
267#define STI_MGMTF_WAIT 0x80000000 290#define STI_MGMTF_WAIT 0x80000000
268#define STI_MGMTF_SAVE 0x40000000 291#define STI_MGMTF_SAVE 0x40000000
269#define STI_MGMTF_RALL 0x20000000 /* restore all display planes */ 292#define STI_MGMTF_RALL 0x20000000 /* restore all display planes */
270 void *future; 293 void *future;
271} *sti_mgmtflags_t; 294} __packed *sti_mgmtflags_t;
272 295
273typedef struct sti_mgmtin { 296typedef struct sti_mgmtin {
274 void *addr; 297 void *addr;
275 void *future; 298 void *future;
276} *sti_mgmtin_t; 299} __packed *sti_mgmtin_t;
277 300
278typedef struct sti_mgmtout { 301typedef struct sti_mgmtout {
279 int32_t errno; 302 int32_t errno;
280 void *future; 303 void *future;
281} *sti_mgmtout_t; 304} __packed *sti_mgmtout_t;
282 305
283STI_DEP(mgmt); 306STI_DEP(mgmt);
284 307
285typedef struct sti_unpmvflags { 308typedef struct sti_unpmvflags {
286 uint32_t flags; 309 uint32_t flags;
287#define STI_UNPMVF_WAIT 0x80000000 310#define STI_UNPMVF_WAIT 0x80000000
288#define STI_UNPMVF_NTXT 0x40000000 /* intp non-text planes */ 311#define STI_UNPMVF_NTXT 0x40000000 /* intp non-text planes */
289 void *future; 312 void *future;
290} *sti_unpmvflags_t; 313} __packed *sti_unpmvflags_t;
291 314
292typedef struct sti_unpmvin { 315typedef struct sti_unpmvin {
293 uint32_t *font_addr; /* font */ 316 uint32_t *font_addr; /* font */
294 uint16_t index; /* character index in the font */ 317 uint16_t index; /* character index in the font */
295 uint8_t fg_colour; 318 uint8_t fg_colour;
296 uint8_t bg_colour; 319 uint8_t bg_colour;
297 uint16_t x, y; 320 uint16_t x, y;
298 void *future; 321 void *future;
299} *sti_unpmvin_t; 322} __packed *sti_unpmvin_t;
300 323
301typedef struct sti_unpmvout { 324typedef struct sti_unpmvout {
302 uint32_t errno; 325 uint32_t errno;
303 void *future; 326 void *future;
304} *sti_unpmvout_t; 327} __packed *sti_unpmvout_t;
305 328
306STI_DEP(unpmv); 329STI_DEP(unpmv);
307 330
308typedef struct sti_blkmvflags { 331typedef struct sti_blkmvflags {
309 uint32_t flags; 332 uint32_t flags;
310#define STI_BLKMVF_WAIT 0x80000000 333#define STI_BLKMVF_WAIT 0x80000000
311#define STI_BLKMVF_COLR 0x40000000 /* change colour on move */ 334#define STI_BLKMVF_COLR 0x40000000 /* change colour on move */
312#define STI_BLKMVF_CLR 0x20000000 /* clear on move */ 335#define STI_BLKMVF_CLR 0x20000000 /* clear on move */
313#define STI_BLKMVF_NTXT 0x10000000 /* move in non-text planes */ 336#define STI_BLKMVF_NTXT 0x10000000 /* move in non-text planes */
314 void *future; 337 void *future;
315} *sti_blkmvflags_t; 338} __packed *sti_blkmvflags_t;
316 339
317typedef struct sti_blkmvin { 340typedef struct sti_blkmvin {
318 uint8_t fg_colour; 341 uint8_t fg_colour;
319 uint8_t bg_colour; 342 uint8_t bg_colour;
320 uint16_t srcx, srcy, dstx, dsty; 343 uint16_t srcx, srcy, dstx, dsty;
321 uint16_t width, height; 344 uint16_t width, height;
322 uint16_t pad; 345 uint16_t pad;
323 void *future; 346 void *future;
324} *sti_blkmvin_t; 347} __packed *sti_blkmvin_t;
325 348
326typedef struct sti_blkmvout { 349typedef struct sti_blkmvout {
327 uint32_t errno; 350 uint32_t errno;
328 void *future; 351 void *future;
329} *sti_blkmvout_t; 352} __packed *sti_blkmvout_t;
330 353
331STI_DEP(blkmv); 354STI_DEP(blkmv);
332 355
333typedef struct sti_testflags { 356typedef struct sti_testflags {
334 uint32_t flags; 357 uint32_t flags;
335#define STI_TESTF_WAIT 0x80000000 358#define STI_TESTF_WAIT 0x80000000
336#define STI_TESTF_ETST 0x40000000 359#define STI_TESTF_ETST 0x40000000
337 void *future; 360 void *future;
338} *sti_testflags_t; 361} __packed *sti_testflags_t;
339 362
340typedef struct sti_testin { 363typedef struct sti_testin {
341 void *future; 364 void *future;
342} *sti_testin_t; 365} __packed *sti_testin_t;
343 366
344typedef struct sti_testout { 367typedef struct sti_testout {
345 uint32_t errno; 368 uint32_t errno;
346 uint32_t result; 369 uint32_t result;
347 void *future; 370 void *future;
348} *sti_testout_t; 371} __packed *sti_testout_t;
349 372
350STI_DEP(test); 373STI_DEP(test);
351 374
352typedef struct sti_exhdlflags { 375typedef struct sti_exhdlflags {
353 uint32_t flags; 376 uint32_t flags;
354#define STI_EXHDLF_WAIT 0x80000000 377#define STI_EXHDLF_WAIT 0x80000000
355#define STI_EXHDLF_CINT 0x40000000 /* clear int */ 378#define STI_EXHDLF_CINT 0x40000000 /* clear int */
356#define STI_EXHDLF_CBE 0x20000000 /* clear BE */ 379#define STI_EXHDLF_CBE 0x20000000 /* clear BE */
357#define STI_EXHDLF_PINT 0x10000000 /* preserve int */ 380#define STI_EXHDLF_PINT 0x10000000 /* preserve int */
358#define STI_EXHDLF_RINT 0x08000000 /* restore int */ 381#define STI_EXHDLF_RINT 0x08000000 /* restore int */
359#define STI_EXHDLF_WEIM 0x04000000 /* write eim w/ sti_eexhdlin */ 382#define STI_EXHDLF_WEIM 0x04000000 /* write eim w/ sti_eexhdlin */
360#define STI_EXHDLF_REIM 0x02000000 /* read eim to sti_eexhdlout */ 383#define STI_EXHDLF_REIM 0x02000000 /* read eim to sti_eexhdlout */
361#define STI_EXHDLF_GIE 0x01000000 /* global int enable */ 384#define STI_EXHDLF_GIE 0x01000000 /* global int enable */
362#define STI_EXHDLF_PGIE 0x00800000 385#define STI_EXHDLF_PGIE 0x00800000
363#define STI_EXHDLF_WIEM 0x00400000 386#define STI_EXHDLF_WIEM 0x00400000
364#define STI_EXHDLF_EIEM 0x00200000 387#define STI_EXHDLF_EIEM 0x00200000
365#define STI_EXHDLF_BIC 0x00100000 /* begin int cycle */ 388#define STI_EXHDLF_BIC 0x00100000 /* begin int cycle */
366#define STI_EXHDLF_EIC 0x00080000 /* end int cycle */ 389#define STI_EXHDLF_EIC 0x00080000 /* end int cycle */
367#define STI_EXHDLF_RIE 0x00040000 /* reset do not clear int enables */ 390#define STI_EXHDLF_RIE 0x00040000 /* reset do not clear int enables */
368 void *future; 391 void *future;
369} *sti_exhdlflags_t; 392} __packed *sti_exhdlflags_t;
370 393
371typedef struct sti_eexhdlin { 394typedef struct sti_eexhdlin {
372 uint32_t eim_addr; 395 uint32_t eim_addr;
373 uint32_t eim_data; 396 uint32_t eim_data;
374 uint32_t iem; /* enable mask */ 397 uint32_t iem; /* enable mask */
375 uint32_t icm; /* clear mask */ 398 uint32_t icm; /* clear mask */
376 void *future; 399 void *future;
377} *sti_eexhdlin_t; 400} __packed *sti_eexhdlin_t;
378 401
379typedef struct sti_exhdlint { 402typedef struct sti_exhdlint {
380 uint32_t flags; 403 uint32_t flags;
381#define STI_EXHDLINT_BET 0x80000000 /* bus error timer */ 404#define STI_EXHDLINT_BET 0x80000000 /* bus error timer */
382#define STI_EXHDLINT_HW 0x40000000 /* high water */ 405#define STI_EXHDLINT_HW 0x40000000 /* high water */
383#define STI_EXHDLINT_LW 0x20000000 /* low water */ 406#define STI_EXHDLINT_LW 0x20000000 /* low water */
384#define STI_EXHDLINT_TM 0x10000000 /* texture map */ 407#define STI_EXHDLINT_TM 0x10000000 /* texture map */
385#define STI_EXHDLINT_VB 0x08000000 /* vertical blank */ 408#define STI_EXHDLINT_VB 0x08000000 /* vertical blank */
386#define STI_EXHDLINT_UDC 0x04000000 /* unbuffered dma complete */ 409#define STI_EXHDLINT_UDC 0x04000000 /* unbuffered dma complete */
387#define STI_EXHDLINT_BDC 0x02000000 /* buffered dma complete */ 410#define STI_EXHDLINT_BDC 0x02000000 /* buffered dma complete */
388#define STI_EXHDLINT_UDPC 0x01000000 /* unbuf priv dma complete */ 411#define STI_EXHDLINT_UDPC 0x01000000 /* unbuf priv dma complete */
389#define STI_EXHDLINT_BDPC 0x00800000 /* buffered priv dma complete */ 412#define STI_EXHDLINT_BDPC 0x00800000 /* buffered priv dma complete */
390} *sti_exhdlint_t; 413} __packed *sti_exhdlint_t;
391 414
392typedef struct sti_exhdlin { 415typedef struct sti_exhdlin {
393 sti_exhdlint_t addr; 416 sti_exhdlint_t addr;
394 sti_eexhdlin_t ext; 417 sti_eexhdlin_t ext;
395} *sti_exhdlin_t; 418} __packed *sti_exhdlin_t;
396 419
397typedef struct sti_eexhdlout { 420typedef struct sti_eexhdlout {
398 uint32_t eim_addr; 421 uint32_t eim_addr;
399 uint32_t eim_data; 422 uint32_t eim_data;
400 uint32_t iem; /* enable mask */ 423 uint32_t iem; /* enable mask */
401 uint32_t icm; /* clear mask */ 424 uint32_t icm; /* clear mask */
402 void *future; 425 void *future;
403} *sti_eexhdlout_t; 426} __packed *sti_eexhdlout_t;
404 427
405typedef struct sti_exhdlout { 428typedef struct sti_exhdlout {
406 uint32_t errno; 429 uint32_t errno;
407 uint32_t flags; 430 uint32_t flags;
408#define STI_EXHDLO_BE 0x80000000 /* BE was intercepted */ 431#define STI_EXHDLO_BE 0x80000000 /* BE was intercepted */
409#define STI_EXHDLO_IP 0x40000000 /* there is int pending */ 432#define STI_EXHDLO_IP 0x40000000 /* there is int pending */
410#define STI_EXHDLO_IE 0x20000000 /* global enable set */ 433#define STI_EXHDLO_IE 0x20000000 /* global enable set */
411 sti_eexhdlout_t ext; 434 sti_eexhdlout_t ext;
412} *sti_exhdlout_t; 435} __packed *sti_exhdlout_t;
413 436
414STI_DEP(exhdl); 437STI_DEP(exhdl);
415 438
416typedef struct sti_inqconfflags { 439typedef struct sti_inqconfflags {
417 uint32_t flags; 440 uint32_t flags;
418#define STI_INQCONFF_WAIT 0x80000000 441#define STI_INQCONFF_WAIT 0x80000000
419 void *future; 442 void *future;
420} *sti_inqconfflags_t; 443} __packed *sti_inqconfflags_t;
421 444
422typedef struct sti_inqconfin { 445typedef struct sti_inqconfin {
423 void *future; 446 void *future;
424} *sti_inqconfin_t; 447} __packed *sti_inqconfin_t;
425 448
426typedef struct sti_einqconfout { 449typedef struct sti_einqconfout {
427 uint32_t crt_config[3]; 450 uint32_t crt_config[3];
428 uint32_t crt_hw[3]; 451 uint32_t crt_hw[3];
429 void *future; 452 void *future;
430} *sti_einqconfout_t; 453} __packed *sti_einqconfout_t;
431 454
432typedef struct sti_inqconfout { 455typedef struct sti_inqconfout {
433 uint32_t errno; 456 uint32_t errno;
434 uint16_t width, height, owidth, oheight, fbwidth, fbheight; 457 uint16_t width, height, owidth, oheight, fbwidth, fbheight;
435 uint32_t bpp; /* bits per pixel */ 458 uint32_t bpp; /* bits per pixel */
436 uint32_t bppu; /* accessible bpp */ 459 uint32_t bppu; /* accessible bpp */
437 uint32_t planes; 460 uint32_t planes;
438 uint8_t name[STI_DEVNAME_LEN]; 461 uint8_t name[STI_DEVNAME_LEN];
439 uint32_t attributes; 462 uint32_t attributes;
440#define STI_INQCONF_Y2X 0x0001 /* pixel is higher tan wider */ 463#define STI_INQCONF_Y2X 0x0001 /* pixel is higher than wider */
441#define STI_INQCONF_HWBLKMV 0x0002 /* hw blkmv is present */ 464#define STI_INQCONF_HWBLKMV 0x0002 /* hw blkmv is present */
442#define STI_INQCONF_AHW 0x0004 /* adv hw accel */ 465#define STI_INQCONF_AHW 0x0004 /* adv hw accel */
443#define STI_INQCONF_INT 0x0008 /* can interrupt */ 466#define STI_INQCONF_INT 0x0008 /* can interrupt */
444#define STI_INQCONF_GONOFF 0x0010 /* supports on/off */ 467#define STI_INQCONF_GONOFF 0x0010 /* supports on/off */
445#define STI_INQCONF_AONOFF 0x0020 /* supports alpha on/off */ 468#define STI_INQCONF_AONOFF 0x0020 /* supports alpha on/off */
446#define STI_INQCONF_VARY 0x0040 /* variable fb height */ 469#define STI_INQCONF_VARY 0x0040 /* variable fb height */
447#define STI_INQCONF_ODDBYTES 0x0080 /* use only odd fb bytes */ 470#define STI_INQCONF_ODDBYTES 0x0080 /* use only odd fb bytes */
448#define STI_INQCONF_FLUSH 0x0100 /* fb cache requires flushing */ 471#define STI_INQCONF_FLUSH 0x0100 /* fb cache requires flushing */
449#define STI_INQCONF_DMA 0x0200 /* supports dma */ 472#define STI_INQCONF_DMA 0x0200 /* supports dma */
450#define STI_INQCONF_VDMA 0x0400 /* supports vdma */ 473#define STI_INQCONF_VDMA 0x0400 /* supports vdma */
451#define STI_INQCONF_YUV1 0x2000 /* supports YUV type 1 */ 474#define STI_INQCONF_YUV1 0x2000 /* supports YUV type 1 */
452#define STI_INQCONF_YUV2 0x4000 /* supports YUV type 2 */ 475#define STI_INQCONF_YUV2 0x4000 /* supports YUV type 2 */
453#define STI_INQCONF_BITS \ 476#define STI_INQCONF_BITS \
454 "\020\001y2x\002hwblkmv\003ahw\004int\005gonoff\006aonoff\007vary"\ 477 "\020\001y2x\002hwblkmv\003ahw\004int\005gonoff\006aonoff\007vary"\
455 "\010oddb\011flush\012dma\013vdma\016yuv1\017yuv2" 478 "\010oddb\011flush\012dma\013vdma\016yuv1\017yuv2"
456 sti_einqconfout_t ext; 479 sti_einqconfout_t ext;
457} *sti_inqconfout_t; 480} __packed *sti_inqconfout_t;
458 481
459STI_DEP(inqconf); 482STI_DEP(inqconf);
460 483
461typedef struct sti_scmentflags { 484typedef struct sti_scmentflags {
462 uint32_t flags; 485 uint32_t flags;
463#define STI_SCMENTF_WAIT 0x80000000 486#define STI_SCMENTF_WAIT 0x80000000
464 void *future; 487 void *future;
465} *sti_scmentflags_t; 488} __packed *sti_scmentflags_t;
466 489
467typedef struct sti_scmentin { 490typedef struct sti_scmentin {
468 uint32_t entry; 491 uint32_t entry;
469 uint32_t value; 492 uint32_t value;
470 void *future; 493 void *future;
471} *sti_scmentin_t; 494} __packed *sti_scmentin_t;
472 495
473typedef struct sti_scmentout { 496typedef struct sti_scmentout {
474 uint32_t errno; 497 uint32_t errno;
475 void *future; 498 void *future;
476} *sti_scmentout_t; 499} __packed *sti_scmentout_t;
477 500
478STI_DEP(scment); 501STI_DEP(scment);
479 502
480typedef struct sti_dmacflags { 503typedef struct sti_dmacflags {
481 uint32_t flags; 504 uint32_t flags;
482#define STI_DMACF_WAIT 0x80000000 505#define STI_DMACF_WAIT 0x80000000
483#define STI_DMACF_PRIV 0x40000000 /* priv dma */ 506#define STI_DMACF_PRIV 0x40000000 /* priv dma */
484#define STI_DMACF_DIS 0x20000000 /* disable */ 507#define STI_DMACF_DIS 0x20000000 /* disable */
485#define STI_DMACF_BUF 0x10000000 /* buffered */ 508#define STI_DMACF_BUF 0x10000000 /* buffered */
486#define STI_DMACF_MRK 0x08000000 /* write a marker */ 509#define STI_DMACF_MRK 0x08000000 /* write a marker */
487#define STI_DMACF_ABRT 0x04000000 /* abort dma xfer */ 510#define STI_DMACF_ABRT 0x04000000 /* abort dma xfer */
488 void *future; 511 void *future;
489} *sti_dmacflags_t; 512} __packed *sti_dmacflags_t;
490 513
491typedef struct sti_dmacin { 514typedef struct sti_dmacin {
492 uint32_t pa_upper; 515 uint32_t pa_upper;
493 uint32_t pa_lower; 516 uint32_t pa_lower;
494 uint32_t len; 517 uint32_t len;
495 uint32_t mrk_data; 518 uint32_t mrk_data;
496 uint32_t mrk_off; 519 uint32_t mrk_off;
497 void *future; 520 void *future;
498} *sti_dmacin_t; 521} __packed *sti_dmacin_t;
499 522
500typedef struct sti_dmacout { 523typedef struct sti_dmacout {
501 uint32_t errno; 524 uint32_t errno;
502 void *future; 525 void *future;
503} *sti_dmacout_t; 526} __packed *sti_dmacout_t;
504 527
505STI_DEP(dmac); 528STI_DEP(dmac);
506 529
507typedef struct sti_flowcflags { 530typedef struct sti_flowcflags {
508 uint32_t flags; 531 uint32_t flags;
509#define STI_FLOWCF_WAIT 0x80000000 532#define STI_FLOWCF_WAIT 0x80000000
510#define STI_FLOWCF_CHW 0x40000000 /* check high water */ 533#define STI_FLOWCF_CHW 0x40000000 /* check high water */
511#define STI_FLOWCF_WHW 0x20000000 /* write high water */ 534#define STI_FLOWCF_WHW 0x20000000 /* write high water */
512#define STI_FLOWCF_WLW 0x10000000 /* write low water */ 535#define STI_FLOWCF_WLW 0x10000000 /* write low water */
513#define STI_FLOWCF_PCSE 0x08000000 /* preserve cse */ 536#define STI_FLOWCF_PCSE 0x08000000 /* preserve cse */
514#define STI_FLOWCF_CSE 0x04000000 537#define STI_FLOWCF_CSE 0x04000000
515#define STI_FLOWCF_CSWF 0x02000000 /* cs write fine */ 538#define STI_FLOWCF_CSWF 0x02000000 /* cs write fine */
516#define STI_FLOWCF_CSWC 0x01000000 /* cs write coarse */ 539#define STI_FLOWCF_CSWC 0x01000000 /* cs write coarse */
517#define STI_FLOWCF_CSWQ 0x00800000 /* cs write fifo */ 540#define STI_FLOWCF_CSWQ 0x00800000 /* cs write fifo */
518 void *future; 541 void *future;
519} *sti_flowcflags_t; 542} __packed *sti_flowcflags_t;
520 543
521typedef struct sti_flowcin { 544typedef struct sti_flowcin {
522 uint32_t retry; 545 uint32_t retry;
523 uint32_t bufz; 546 uint32_t bufz;
524 uint32_t hwcnt; 547 uint32_t hwcnt;
525 uint32_t lwcnt; 548 uint32_t lwcnt;
526 uint32_t csfv; /* cs fine value */ 549 uint32_t csfv; /* cs fine value */
527 uint32_t cscv; /* cs coarse value */ 550 uint32_t cscv; /* cs coarse value */
528 uint32_t csqc; /* cs fifo count */ 551 uint32_t csqc; /* cs fifo count */
529 void *future; 552 void *future;
530} *sti_flowcin_t; 553} __packed *sti_flowcin_t;
531 554
532typedef struct sti_flowcout { 555typedef struct sti_flowcout {
533 uint32_t errno; 556 uint32_t errno;
534 uint32_t retry_result; 557 uint32_t retry_result;
535 uint32_t fifo_size; 558 uint32_t fifo_size;
536 void *future; 559 void *future;
537} *sti_flowcout_t; 560} __packed *sti_flowcout_t;
538 561
539STI_DEP(flowc); 562STI_DEP(flowc);
540 563
541typedef struct sti_utimingflags { 564typedef struct sti_utimingflags {
542 uint32_t flags; 565 uint32_t flags;
543#define STI_UTIMF_WAIT 0x80000000 566#define STI_UTIMF_WAIT 0x80000000
544#define STI_UTIMF_HKS 0x40000000 /* has kbuf_size */ 567#define STI_UTIMF_HKS 0x40000000 /* has kbuf_size */
545 void *future; 568 void *future;
546} *sti_utimingflags_t; 569} __packed *sti_utimingflags_t;
547 570
548typedef struct sti_utimingin { 571typedef struct sti_utimingin {
549 void *data; 572 void *data;
550 void *kbuf; 573 void *kbuf;
551 void *future; 574 void *future;
552} *sti_utimingin_t; 575} __packed *sti_utimingin_t;
553 576
554typedef struct sti_utimingout { 577typedef struct sti_utimingout {
555 uint32_t errno; 578 uint32_t errno;
556 uint32_t kbuf_size; /* buffer required size */ 579 uint32_t kbuf_size; /* buffer required size */
557 void *future; 580 void *future;
558} *sti_utimingout_t; 581} __packed *sti_utimingout_t;
559 582
560STI_DEP(utiming); 583STI_DEP(utiming);
561 584
562typedef struct sti_pmgrflags { 585typedef struct sti_pmgrflags {
563 uint32_t flags; 586 uint32_t flags;
564#define STI_UTIMF_WAIT 0x80000000 587#define STI_UTIMF_WAIT 0x80000000
565#define STI_UTIMOP_CLEANUP 0x00000000 588#define STI_UTIMOP_CLEANUP 0x00000000
566#define STI_UTIMOP_BAC 0x10000000 589#define STI_UTIMOP_BAC 0x10000000
567#define STI_UTIMF_CRIT 0x04000000 590#define STI_UTIMF_CRIT 0x04000000
568#define STI_UTIMF_BUFF 0x02000000 591#define STI_UTIMF_BUFF 0x02000000
569#define STI_UTIMF_IBUFF 0x01000000 592#define STI_UTIMF_IBUFF 0x01000000
570 void *future; 593 void *future;
571} *sti_pmgrflags_t; 594} __packed *sti_pmgrflags_t;
572 595
573typedef struct sti_pmgrin { 596typedef struct sti_pmgrin {
574 uint32_t reserved[4]; 597 uint32_t reserved[4];
575 void *future; 598 void *future;
576} *sti_pmgrin_t; 599} __packed *sti_pmgrin_t;
577 600
578typedef struct sti_pmgrout { 601typedef struct sti_pmgrout {
579 int32_t errno; 602 int32_t errno;
580 void *future; 603 void *future;
581} *sti_pmgrout_t; 604} __packed *sti_pmgrout_t;
582 605
583STI_DEP(pmgr); 606STI_DEP(pmgr);
584 607
585typedef struct sti_utilflags { 608typedef struct sti_utilflags {
586 uint32_t flags; 609 uint32_t flags;
587#define STI_UTILF_ROOT 0x80000000 /* was called as root */ 610#define STI_UTILF_ROOT 0x80000000 /* was called as root */
588 void *future; 611 void *future;
589} *sti_utilflags_t; 612} __packed *sti_utilflags_t;
590 613
591typedef struct sti_utilin { 614typedef struct sti_utilin {
592 uint32_t in_size; 615 uint32_t in_size;
593 uint32_t out_size; 616 uint32_t out_size;
594 uint8_t *buf; 617 uint8_t *buf;
595} *sti_utilin_t; 618} __packed *sti_utilin_t;
596 619
597typedef struct sti_utilout { 620typedef struct sti_utilout {
598 int32_t errno; 621 int32_t errno;
599 void *future; 622 void *future;
600} *sti_utilout_t; 623} __packed *sti_utilout_t;
601 624
602STI_DEP(util); 625STI_DEP(util);
603 626
604#pragma pack() 
605 
606#endif /* _IC_STIREG_H_ */ 627#endif /* _IC_STIREG_H_ */

cvs diff -r1.5 -r1.6 src/sys/dev/ic/stivar.h (expand / switch to unified diff)

--- src/sys/dev/ic/stivar.h 2010/11/01 06:41:50 1.5
+++ src/sys/dev/ic/stivar.h 2010/11/09 12:24:48 1.6
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1/* $NetBSD: stivar.h,v 1.5 2010/11/01 06:41:50 skrll Exp $ */ 1/* $NetBSD: stivar.h,v 1.6 2010/11/09 12:24:48 skrll Exp $ */
2 2
3/* $OpenBSD: stivar.h,v 1.15 2003/12/16 06:07:13 mickey Exp $ */ 3/* $OpenBSD: stivar.h,v 1.24 2009/02/06 22:51:04 miod Exp $ */
4 4
5/* 5/*
6 * Copyright (c) 2000-2003 Michael Shalayeff 6 * Copyright (c) 2000-2003 Michael Shalayeff
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
@@ -21,62 +21,114 @@ @@ -21,62 +21,114 @@
21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE. 28 * THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31#ifndef _IC_STIVAR_H_ 31#ifndef _IC_STIVAR_H_
32#define _IC_STIVAR_H_ 32#define _IC_STIVAR_H_
33 33
 34struct sti_softc;
 35
 36/*
 37 * STI ROM information - one per device
 38 */
 39struct sti_rom {
 40 struct sti_softc *rom_softc; /* backpointer to device */
 41 int rom_devtype;
 42
 43 bus_space_tag_t iot, memt; /* XXX iot unused */
 44 bus_space_handle_t romh;
 45 bus_addr_t *bases;
 46
 47 struct sti_dd rom_dd; /* in word format */
 48
 49 vaddr_t rom_code;
 50 sti_init_t init;
 51 sti_mgmt_t mgmt;
 52 sti_unpmv_t unpmv;
 53 sti_blkmv_t blkmv;
 54 sti_test_t test;
 55 sti_exhdl_t exhdl;
 56 sti_inqconf_t inqconf;
 57 sti_scment_t scment;
 58 sti_dmac_t dmac;
 59 sti_flowc_t flowc;
 60 sti_utiming_t utiming;
 61 sti_pmgr_t pmgr;
 62 sti_util_t util;
 63};
 64
 65/*
 66 * STI screen information - one per head
 67 */
 68struct sti_screen {
 69 struct sti_rom *scr_rom;
 70
 71#ifdef notyet
 72 u_int scr_flags;
 73#endif
 74
 75 int scr_bpp;
 76
 77 struct sti_font scr_curfont;
 78 struct sti_cfg scr_cfg;
 79 struct sti_ecfg scr_ecfg;
 80 char name[STI_DEVNAME_LEN];
 81
 82 void *scr_romfont; /* ROM font copy in memory... */
 83 u_int scr_fontmaxcol;/* ...or in off-screen area */
 84 u_int scr_fontbase;
 85
 86 uint8_t scr_rcmap[STI_NCMAP],
 87 scr_gcmap[STI_NCMAP],
 88 scr_bcmap[STI_NCMAP];
 89
 90 uint16_t fbheight, fbwidth;
 91 uint16_t oheight, owidth; /* offscreen size */
 92 bus_addr_t fbaddr;
 93 bus_size_t fblen;
 94
 95 /* wsdisplay information */
 96 int scr_nscreens;
 97 u_int scr_wsmode;
 98 struct wsscreen_descr scr_wsd;
 99 struct wsscreen_descr *scr_scrlist[1];
 100 struct wsscreen_list scr_screenlist;
 101};
 102
 103/*
 104 * STI Device state
 105 */
34struct sti_softc { 106struct sti_softc {
35 device_t sc_dev; 107 device_t sc_dev;
 108#if notyet
36 void *sc_ih; 109 void *sc_ih;
 110#endif
37 111
38 u_int sc_wsmode; 112 u_int sc_flags;
39 u_int sc_flags; 113#define STI_CONSOLE 0x0001 /* first head is console... */
40#define STI_TEXTMODE 0x0001 114#define STI_ATTACHED 0x0002 /* ... and wsdisplay_cnattach() has been done */
41#define STI_CLEARSCR 0x0002 115#define STI_ROM_ENABLED 0x0004 /* PCI ROM is enabled */
42#define STI_CONSOLE 0x0004 116
43 int sc_devtype; 117 bus_addr_t bases[STI_REGION_MAX];
44 int sc_nscreens; 118 struct sti_rom *sc_rom;
45 int sc_bpp; 119 struct sti_screen *sc_scr;
46 120
47 bus_space_tag_t iot, memt; 121 /* optional, required for PCI */
48 bus_space_handle_t romh; 122 void (*sc_enable_rom)(struct sti_softc *);
49 bus_addr_t base, fbaddr; 123 void (*sc_disable_rom)(struct sti_softc *);
50 bus_size_t fblen; 
51 
52 struct sti_dd sc_dd; /* in word format */ 
53 struct sti_font sc_curfont; 
54 struct sti_cfg sc_cfg; 
55 struct sti_ecfg sc_ecfg; 
56 
57 void *sc_romfont; /* ROM font copy, either in memory... */ 
58 u_int sc_fontmaxcol; /* ...or in off-screen frame buffer */ 
59 u_int sc_fontbase; 
60 
61 uint8_t sc_rcmap[STI_NCMAP], sc_gcmap[STI_NCMAP], sc_bcmap[STI_NCMAP]; 
62 vaddr_t sc_code; 
63 
64 sti_init_t init; 
65 sti_mgmt_t mgmt; 
66 sti_unpmv_t unpmv; 
67 sti_blkmv_t blkmv; 
68 sti_test_t test; 
69 sti_exhdl_t exhdl; 
70 sti_inqconf_t inqconf; 
71 sti_scment_t scment; 
72 sti_dmac_t dmac; 
73 sti_flowc_t flowc; 
74 sti_utiming_t utiming; 
75 sti_pmgr_t pmgr; 
76 sti_util_t util; 
77}; 124};
78 125
79void sti_attach_common(struct sti_softc *sc); 126int sti_attach_common(struct sti_softc *, bus_space_tag_t, bus_space_tag_t,
80int sti_intr(void *v); 127 bus_space_handle_t, u_int);
 128int sti_cnattach(struct sti_rom *, struct sti_screen *, bus_space_tag_t,
 129 bus_addr_t *, u_int);
 130void sti_describe(struct sti_softc *);
 131void sti_end_attach(struct sti_softc *);
 132u_int sti_rom_size(bus_space_tag_t, bus_space_handle_t);
81 133
82#endif /* _IC_STIVAR_H_ */ 134#endif /* _IC_STIVAR_H_ */

cvs diff -r1.331 -r1.332 src/sys/dev/pci/files.pci (expand / switch to unified diff)

--- src/sys/dev/pci/files.pci 2010/11/06 14:56:12 1.331
+++ src/sys/dev/pci/files.pci 2010/11/09 12:24:48 1.332
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: files.pci,v 1.331 2010/11/06 14:56:12 jakllsch Exp $ 1# $NetBSD: files.pci,v 1.332 2010/11/09 12:24:48 skrll Exp $
2# 2#
3# Config file and device description for machine-independent PCI code. 3# Config file and device description for machine-independent PCI code.
4# Included by ports that need it. Requires that the SCSI files be 4# Included by ports that need it. Requires that the SCSI files be
5# defined first. 5# defined first.
6 6
7defflag opt_pci.h PCIVERBOSE PCI_CONFIG_DUMP PCI_NETBSD_CONFIGURE 7defflag opt_pci.h PCIVERBOSE PCI_CONFIG_DUMP PCI_NETBSD_CONFIGURE
8defparam opt_pci.h PCI_NETBSD_ENABLE_IDE 8defparam opt_pci.h PCI_NETBSD_ENABLE_IDE
9 9
10defflag opt_bktr.h BKTR_430_FX_MODE BKTR_GPIO_ACCESS BKTR_NO_MSP_RESET 10defflag opt_bktr.h BKTR_430_FX_MODE BKTR_GPIO_ACCESS BKTR_NO_MSP_RESET
11 BKTR_REVERSE_MUTE BKTR_SIS_VIA_MODE BKTR_USE_PLL 11 BKTR_REVERSE_MUTE BKTR_SIS_VIA_MODE BKTR_USE_PLL
12defparam opt_bktr.h BKTR_OVERRIDE_CARD BKTR_OVERRIDE_TUNER BKTR_OVERRIDE_DBX 12defparam opt_bktr.h BKTR_OVERRIDE_CARD BKTR_OVERRIDE_TUNER BKTR_OVERRIDE_DBX
13 BKTR_OVERRIDE_MSP BKTR_SYSTEM_DEFAULT 13 BKTR_OVERRIDE_MSP BKTR_SYSTEM_DEFAULT
14 14
@@ -416,26 +416,30 @@ file dev/pci/if_esh_pci.c esh_pci @@ -416,26 +416,30 @@ file dev/pci/if_esh_pci.c esh_pci
416defflag opt_vga.h VGA_POST: X86EMU 416defflag opt_vga.h VGA_POST: X86EMU
417attach vga at pci with vga_pci 417attach vga at pci with vga_pci
418file dev/pci/vga_pci.c vga_pci needs-flag 418file dev/pci/vga_pci.c vga_pci needs-flag
419 419
420# DEC TGA 420# DEC TGA
421device tga: wsemuldisplaydev, rasops8, rasops32 421device tga: wsemuldisplaydev, rasops8, rasops32
422attach tga at pci 422attach tga at pci
423file dev/pci/tga.c tga needs-flag 423file dev/pci/tga.c tga needs-flag
424file dev/pci/tga_conf.c tga 424file dev/pci/tga_conf.c tga
425file dev/ic/bt485.c tga 425file dev/ic/bt485.c tga
426file dev/ic/bt463.c tga 426file dev/ic/bt463.c tga
427file dev/ic/ibm561.c tga 427file dev/ic/ibm561.c tga
428 428
 429# HP Visualize
 430attach sti at pci with sti_pci
 431file dev/pci/sti_pci.c sti_pci needs-flag
 432
429# Integraphics Systems IGA168x and CyberPro framebuffers (linear non-VGA mode) 433# Integraphics Systems IGA168x and CyberPro framebuffers (linear non-VGA mode)
430# device declaration in sys/conf/files 434# device declaration in sys/conf/files
431attach igsfb at pci with igsfb_pci 435attach igsfb at pci with igsfb_pci
432file dev/pci/igsfb_pci.c igsfb_pci 436file dev/pci/igsfb_pci.c igsfb_pci
433 437
434# Brooktree Bt848 video capture 438# Brooktree Bt848 video capture
435device bktr: radiodev 439device bktr: radiodev
436attach bktr at pci 440attach bktr at pci
437file dev/pci/bktr/bktr_audio.c bktr 441file dev/pci/bktr/bktr_audio.c bktr
438file dev/pci/bktr/bktr_card.c bktr 442file dev/pci/bktr/bktr_card.c bktr
439file dev/pci/bktr/bktr_core.c bktr 443file dev/pci/bktr/bktr_core.c bktr
440file dev/pci/bktr/bktr_os.c bktr needs-flag 444file dev/pci/bktr/bktr_os.c bktr needs-flag
441file dev/pci/bktr/bktr_tuner.c bktr 445file dev/pci/bktr/bktr_tuner.c bktr

File Added: src/sys/dev/pci/sti_pci.c
/*	$NetBSD: sti_pci.c,v 1.1 2010/11/09 12:24:48 skrll Exp $	*/

/*	$OpenBSD: sti_pci.c,v 1.7 2009/02/06 22:51:04 miod Exp $	*/

/*
 * Copyright (c) 2006, 2007 Miodrag Vallat.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice, this permission notice, and the disclaimer below
 * appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>

#include <dev/wscons/wsdisplayvar.h>

#include <dev/ic/stireg.h>
#include <dev/ic/stivar.h>

#ifdef STIDEBUG
#define	DPRINTF(s)	do {	\
	if (stidebug)		\
		printf s;	\
} while(0)

extern int stidebug;
#else
#define	DPRINTF(s)	/* */
#endif

int	sti_pci_match(device_t, cfdata_t, void *);
void	sti_pci_attach(device_t, device_t, void *);

void	sti_pci_end_attach(device_t dev);

struct	sti_pci_softc {
	device_t		sc_dev;

	struct sti_softc	sc_base;

	pci_chipset_tag_t	sc_pc;
	pcitag_t		sc_tag;

	bus_space_handle_t	sc_romh;
};

CFATTACH_DECL_NEW(sti_pci, sizeof(struct sti_pci_softc),
    sti_pci_match, sti_pci_attach, NULL, NULL);

int	sti_readbar(struct sti_softc *, struct pci_attach_args *, u_int, int);
int	sti_check_rom(struct sti_pci_softc *, struct pci_attach_args *);
void	sti_pci_enable_rom(struct sti_softc *);
void	sti_pci_disable_rom(struct sti_softc *);
void	sti_pci_enable_rom_internal(struct sti_pci_softc *);
void	sti_pci_disable_rom_internal(struct sti_pci_softc *);

int	sti_pci_is_console(struct pci_attach_args *, bus_addr_t *);

#define PCI_ROM_ENABLE                  0x00000001
#define PCI_ROM_ADDR_MASK               0xfffff800
#define PCI_ROM_ADDR(mr)                                                \
            ((mr) & PCI_ROM_ADDR_MASK)
#define PCI_ROM_SIZE(mr)                                                \
            (PCI_ROM_ADDR(mr) & -PCI_ROM_ADDR(mr))

int
sti_pci_match(device_t parent, cfdata_t cf, void *aux)
{
	struct pci_attach_args *paa = aux;

	if (PCI_VENDOR(paa->pa_id) != PCI_VENDOR_HP)
		return 0;

	if (PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_EG ||
	    PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FX2 ||
	    PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FX4 ||
	    PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FX6 ||
	    PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FXE)
		return 1;

	return 0;
}

void
sti_pci_attach(device_t parent, device_t self, void *aux)
{
	struct sti_pci_softc *spc = device_private(self);
	struct pci_attach_args *paa = aux;
	int ret;

	spc->sc_dev = self;

	spc->sc_pc = paa->pa_pc;
	spc->sc_tag = paa->pa_tag;
	spc->sc_base.sc_dev = self;
	spc->sc_base.sc_enable_rom = sti_pci_enable_rom;
	spc->sc_base.sc_disable_rom = sti_pci_disable_rom;

	aprint_normal("\n");

	if (sti_check_rom(spc, paa) != 0)
		return;

	aprint_normal("%s", device_xname(self));
	ret = sti_pci_is_console(paa, spc->sc_base. bases);
	if (ret != 0)
		spc->sc_base.sc_flags |= STI_CONSOLE;

	ret = sti_attach_common(&spc->sc_base, paa->pa_iot, paa->pa_memt,
	    spc->sc_romh, STI_CODEBASE_MAIN);
	if (ret == 0)
		config_interrupts(self, sti_pci_end_attach);

}

void sti_pci_end_attach(device_t dev)
{
	struct sti_pci_softc *spc = device_private(dev);
	struct sti_softc *sc = &spc->sc_base;

	sti_end_attach(sc);
}


/*
 * Grovel the STI ROM image.
 */
int
sti_check_rom(struct sti_pci_softc *spc, struct pci_attach_args *pa)
{
	struct sti_softc *sc = &spc->sc_base;
	pcireg_t address, mask;
	bus_space_handle_t romh;
	bus_size_t romsize, subsize, stiromsize;
	bus_addr_t selected, offs, suboffs;
	uint32_t tmp;
	int i;
	int rc;

	/* sort of inline sti_pci_enable_rom(sc) */
	address = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM);
	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, ~PCI_ROM_ENABLE);
	mask = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM);
	address |= PCI_ROM_ENABLE;
	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, address);
	sc->sc_flags |= STI_ROM_ENABLED;
	/*
	 * Map the complete ROM for now.
	 */

	romsize = PCI_ROM_SIZE(mask);
	DPRINTF(("%s: mapping rom @ %lx for %lx\n", __func__,
	    (long)PCI_ROM_ADDR(address), (long)romsize));

	rc = bus_space_map(pa->pa_memt, PCI_ROM_ADDR(address), romsize,
	    0, &romh);
	if (rc != 0) {
		aprint_error_dev(sc->sc_dev, "can't map PCI ROM (%d)\n", rc);
		goto fail2;
	}

	sti_pci_disable_rom_internal(spc);
	/*
	 * Iterate over the ROM images, pick the best candidate.
	 */

	selected = (bus_addr_t)-1;
	for (offs = 0; offs < romsize; offs += subsize) {
		sti_pci_enable_rom_internal(spc);
		/*
		 * Check for a valid ROM header.
		 */
		tmp = bus_space_read_4(pa->pa_memt, romh, offs + 0);
		tmp = le32toh(tmp);
		if (tmp != 0x55aa0000) {
			sti_pci_disable_rom_internal(spc);
			if (offs == 0) {
				aprint_error_dev(sc->sc_dev,
				    "invalid PCI ROM header signature (%08x)\n",
				     tmp);
				rc = EINVAL;
			}
			break;
		}

		/*
		 * Check ROM type.
		 */
		tmp = bus_space_read_4(pa->pa_memt, romh, offs + 4);
		tmp = le32toh(tmp);
		if (tmp != 0x00000001) {	/* 1 == STI ROM */
			sti_pci_disable_rom_internal(spc);
			if (offs == 0) {
				aprint_error_dev(sc->sc_dev,
				    "invalid PCI ROM type (%08x)\n", tmp);
				rc = EINVAL;
			}
			break;
		}

		subsize = (bus_addr_t)bus_space_read_2(pa->pa_memt, romh,
		    offs + 0x0c);
		subsize <<= 9;

#ifdef STIDEBUG
		sti_pci_disable_rom_internal(spc);
		DPRINTF(("ROM offset %08x size %08x type %08x",
		    (u_int)offs, (u_int)subsize, tmp));
		sti_pci_enable_rom_internal(spc);
#endif

		/*
		 * Check for a valid ROM data structure.
		 * We do not need it except to know what architecture the ROM
		 * code is for.
		 */

		suboffs = offs +(bus_addr_t)bus_space_read_2(pa->pa_memt, romh,
		    offs + 0x18);
		tmp = bus_space_read_4(pa->pa_memt, romh, suboffs + 0);
		tmp = le32toh(tmp);
		if (tmp != 0x50434952) {	/* PCIR */
			sti_pci_disable_rom_internal(spc);
			if (offs == 0) {
				aprint_error_dev(sc->sc_dev, "invalid PCI data"
				    " signature (%08x)\n", tmp);
				rc = EINVAL;
			} else {
				DPRINTF((" invalid PCI data signature %08x\n",
				    tmp));
				continue;
			}
		}

		tmp = bus_space_read_1(pa->pa_memt, romh, suboffs + 0x14);
		sti_pci_disable_rom_internal(spc);
		DPRINTF((" code %02x", tmp));

		switch (tmp) {
#ifdef __hppa__
		case 0x10:
			if (selected == (bus_addr_t)-1)
				selected = offs;
			break;
#endif
#ifdef __i386__
		case 0x00:
			if (selected == (bus_addr_t)-1)
				selected = offs;
			break;
#endif
		default:
#ifdef STIDEBUG
			DPRINTF((" (wrong architecture)"));
#endif
			break;
		}
		DPRINTF(("%s\n", selected == offs ? " -> SELECTED" : ""));
	}

	if (selected == (bus_addr_t)-1) {
		if (rc == 0) {
			aprint_error_dev(sc->sc_dev, "found no ROM with "
			    "correct microcode architecture\n");
			rc = ENOEXEC;
		}
		goto fail;
	}

	/*
	 * Read the STI region BAR assignments.
	 */

	sti_pci_enable_rom_internal(spc);
	offs = selected +
	    (bus_addr_t)bus_space_read_2(pa->pa_memt, romh, selected + 0x0e);
	for (i = 0; i < STI_REGION_MAX; i++) {
		rc = sti_readbar(sc, pa, i,
		    bus_space_read_1(pa->pa_memt, romh, offs + i));
		if (rc != 0)
			goto fail;
	}

	/*
	 * Find out where the STI ROM itself lies, and its size.
	 */

	offs = selected +
	    (bus_addr_t)bus_space_read_4(pa->pa_memt, romh, selected + 0x08);
	stiromsize = (bus_addr_t)bus_space_read_4(pa->pa_memt, romh,
	    offs + 0x18);
	stiromsize = le32toh(stiromsize);
	sti_pci_disable_rom_internal(spc);

	/*
	 * Replace our mapping with a smaller mapping of only the area
	 * we are interested in.
	 */

	DPRINTF(("remapping rom @ %lx for %lx\n",
	    (long)(PCI_ROM_ADDR(address) + offs), (long)stiromsize));
	bus_space_unmap(pa->pa_memt, romh, romsize);
	rc = bus_space_map(pa->pa_memt, PCI_ROM_ADDR(address) + offs,
	    stiromsize, 0, &spc->sc_romh);
	if (rc != 0) {
		aprint_error_dev(sc->sc_dev, "can't map STI ROM (%d)\n",
		    rc);
		goto fail2;
	}
 	sti_pci_disable_rom_internal(spc);
	sc->sc_flags &= ~STI_ROM_ENABLED;

	return 0;

fail:
	bus_space_unmap(pa->pa_memt, romh, romsize);
fail2:
	sti_pci_disable_rom_internal(spc);

	return rc;
}

/*
 * Decode a BAR register.
 */
int
sti_readbar(struct sti_softc *sc, struct pci_attach_args *pa, u_int region,
    int bar)
{
	bus_addr_t addr;
	bus_size_t size;
	uint32_t cf;
	int rc;

	if (bar == 0) {
		sc->bases[region] = 0;
		return (0);
	}

#ifdef DIAGNOSTIC
	if (bar < PCI_MAPREG_START || bar > PCI_MAPREG_PPB_END) {
		sti_pci_disable_rom(sc);
		printf("%s: unexpected bar %02x for region %d\n",
		    device_xname(sc->sc_dev), bar, region);
		sti_pci_enable_rom(sc);
	}
#endif

	cf = pci_conf_read(pa->pa_pc, pa->pa_tag, bar);

	rc = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, PCI_MAPREG_TYPE(cf),
	    &addr, &size, NULL);

	if (rc != 0) {
		sti_pci_disable_rom(sc);
		aprint_error_dev(sc->sc_dev, "invalid bar %02x for region %d\n",
		    bar, region);
		sti_pci_enable_rom(sc);
		return (rc);
	}

	sc->bases[region] = addr;
	return (0);
}

/*
 * Enable PCI ROM.
 */
void
sti_pci_enable_rom_internal(struct sti_pci_softc *spc)
{
	pcireg_t address;

	KASSERT(spc != NULL);

	address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM);
	address |= PCI_ROM_ENABLE;
	pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address);
}

void
sti_pci_enable_rom(struct sti_softc *sc)
{
	struct sti_pci_softc *spc = device_private(sc->sc_dev);

	if (!ISSET(sc->sc_flags, STI_ROM_ENABLED)) {
		sti_pci_enable_rom_internal(spc);
	}
	SET(sc->sc_flags, STI_ROM_ENABLED);
}

/*
 * Disable PCI ROM.
 */
void
sti_pci_disable_rom_internal(struct sti_pci_softc *spc)
{
	pcireg_t address;

	KASSERT(spc != NULL);

	address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM);
	address &= ~PCI_ROM_ENABLE;
	pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address);
}

void
sti_pci_disable_rom(struct sti_softc *sc)
{
	struct sti_pci_softc *spc = device_private(sc->sc_dev);

	if (ISSET(sc->sc_flags, STI_ROM_ENABLED)) {
		sti_pci_disable_rom_internal(spc);
	}
	CLR(sc->sc_flags, STI_ROM_ENABLED);
}