From peter.edwards@openet-telecom.com  Mon Feb 16 03:36:34 2004
Return-Path: <peter.edwards@openet-telecom.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 0DC5916A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Feb 2004 03:36:34 -0800 (PST)
Received: from sweeper.openet-telecom.com (mail.openet-telecom.com [62.17.151.60])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 56A9143D2F
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Feb 2004 03:36:33 -0800 (PST)
	(envelope-from peter.edwards@openet-telecom.com)
Received: from mail.openet-telecom.com (unverified) by sweeper.openet-telecom.com
 (Content Technologies SMTPRS 4.3.10) with ESMTP id <T67ca8834480a000211560@sweeper.openet-telecom.com> for <FreeBSD-gnats-submit@freebsd.org>;
 Mon, 16 Feb 2004 11:39:15 +0000
Received: from banjo.openet-telecom.lan (10.0.3.126) by mail.openet-telecom.com (NPlex 6.5.027)
        id 40308B31000004A7 for FreeBSD-gnats-submit@freebsd.org; Mon, 16 Feb 2004 11:37:35 +0000
Received: from banjo.openet-telecom.lan (localhost [127.0.0.1])
	by banjo.openet-telecom.lan (8.12.10/8.12.10) with ESMTP id i1GBaVIe094071
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 16 Feb 2004 11:36:31 GMT
	(envelope-from petere@banjo.openet-telecom.lan)
Received: (from petere@localhost)
	by banjo.openet-telecom.lan (8.12.10/8.12.10/Submit) id i1GBaVVW094070;
	Mon, 16 Feb 2004 11:36:31 GMT
	(envelope-from petere)
Message-Id: <200402161136.i1GBaVVW094070@banjo.openet-telecom.lan>
Date: Mon, 16 Feb 2004 11:36:31 GMT
From: Peter Edwards <peter.edwards@openet-telecom.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] AGP misconfigures i845G chipset, causing VBIOS problems
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         62906
>Category:       kern
>Synopsis:       [agp] [patch] AGP misconfigures i845G chipset, causing VBIOS problems
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 16 03:40:07 PST 2004
>Closed-Date:    Sun Dec 09 14:06:42 UTC 2007
>Last-Modified:  Sun Dec 09 14:06:42 UTC 2007
>Originator:     Peter Edwards
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
>Environment:
System: FreeBSD banjo.openet-telecom.lan 5.2-CURRENT FreeBSD 5.2-CURRENT #1: Tue Jan 13 11:10:00 GMT 2004 petere@banjo.openet-telecom.lan:/home/petere/FreeBSD/obj/home/petere/FreeBSD/src/sys/BANJO i386


	
>Description:

[Orignally sent some of this to -current: I've since looked at the
relevant data sheets from intel to verify that I was DTRT, and want
to record the problem & fix here for posterity]

Machines with the i845G chipset are being programmed incorrectly.
The end of the probe routine (agp_intel.c v1.19, line 220) reads:

>	default: /* Intel Generic (maybe) */
>		pci_write_config(dev, AGP_INTEL_ERRSTS + 1, 7, 1);

The 845G device ID isn't recognised by the driver, so this is what
happens to it.

There's a non-default case for a large number of devices above,
which do something similar with a register defined as
AGP_INTEL_I8XX_ERRSTS.

The AGP_INTEL__I8XX_* definitions are correct for the 845G chipset,
while the register at 0x92 (== AGP_INTEL_ERRSTS + 1) is defined as
a "programmable attribute map register.", affecting legacy BIOS
memory segment in the range C8000 to CFFFF. Writing 0x7 to it seems
to mark 0xC8000 to 0xCBFFF as read/write enable, and disables 0xCC000
to 0xCFFFF

This is pretty much the observed behaviour: the Video BIOS from
0xCC000 on to 0xCFFFF reads back as an all-ones bit pattern, causing
no end of grief to both the X server (hangs) and the VESA module
(panics kernel)

>How-To-Repeat:
Get a machine with one of these chipsets in it, and try loading the
VESA module, or starting X.  To show the BIOS contents, try:

# dd if=/dev/mem count=64 bs=1024 iseek=768 | hd | more
Everything looks normal up to 0xCC000, then lots of "FF"s

>Fix:

Just recognise the device ID in the attach routine (see below). The
default fallthrough should probably be changed, though.


Index: sys/pci/agp_intel.c
===================================================================
RCS file: /usr/cvs/FreeBSD-CVS/src/sys/pci/agp_intel.c,v
retrieving revision 1.19
diff -u -r1.19 agp_intel.c
--- sys/pci/agp_intel.c	17 Sep 2003 02:58:17 -0000	1.19
+++ sys/pci/agp_intel.c	13 Feb 2004 22:03:42 -0000
@@ -111,6 +111,9 @@
 
 	case 0x25788086:
 		return ("Intel 82875P host to AGP bridge");
+
+	case 0x25608086: /* i845G */
+		return ("Intel 82845G host to AGP bridge");
 	};
 
 	if (pci_get_vendor(dev) == 0x8086)
@@ -236,11 +239,13 @@
 	case 0x25318086: /* i860 */
 	case 0x25708086: /* i865 */
 	case 0x25788086: /* i875P */
+	case 0x25608086: /* i845G */
 		pci_write_config(dev, AGP_INTEL_I8XX_ERRSTS, 0x00ff, 2);
 		break;
 
 	default: /* Intel Generic (maybe) */
 		pci_write_config(dev, AGP_INTEL_ERRSTS + 1, 7, 1);
+		break;
 	}
 
 	return 0;
@@ -278,6 +283,7 @@
 				& ~(1 << 1)), 1);
 
 	case 0x1a308086: /* i845 */
+	case 0x25608086: /* i845G */
 	case 0x33408086: /* i855 */
 	case 0x25708086: /* i865 */
 	case 0x25788086: /* i875P */
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: peadar 
State-Changed-When: Sat Mar 13 08:04:41 PST 2004 
State-Changed-Why:  
Patch applied, but more work needed. 


Responsible-Changed-From-To: freebsd-bugs->peadar 
Responsible-Changed-By: peadar 
Responsible-Changed-When: Sat Mar 13 08:04:41 PST 2004 
Responsible-Changed-Why:  
Originator got a commit bit of his own. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=62906 
State-Changed-From-To: analyzed->suspended 
State-Changed-By: linimon 
State-Changed-When: Tue Jul 31 14:49:00 UTC 2007 
State-Changed-Why:  
The patch was committed, but there may be other, similar, work that needs 
to be done. 

Since committer is away from FreeBSD work right now, return this to the 
pool in case anyone else wants to take a look. 


Responsible-Changed-From-To: peadar->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Jul 31 14:49:00 UTC 2007 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=62906 
State-Changed-From-To: suspended->closed 
State-Changed-By: remko 
State-Changed-When: Sun Dec 9 14:06:41 UTC 2007 
State-Changed-Why:  
I think this is fixed with the code currently in -CURRENT and RELENG_7, 
please checkout 7.0-BETA4 and let me know in case I got this wrong 

http://www.freebsd.org/cgi/query-pr.cgi?pr=62906 
>Unformatted:

I've committed the original patch, but after further consideration,
a little more work is neccessary. The 845G devices should behave
correctly now, but other devices that attach as "generic" may fail
in similar ways.

The default behaviour for generic devices doesn't appear to be
generic enough, so the proper fix will envolve removing the default
fallback for otherwise unrecognised Intel host/AGP bridges, and
ensuring that all known devices are handled correctly.

Once I get a chance to find and read the data sheets for all of the
currently known devices, I'll revisit the PR.
