From nobody@FreeBSD.org  Wed Mar 26 17:59:01 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 20B14FE8
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 26 Mar 2014 17:59:01 +0000 (UTC)
Received: from cgiserv.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client did not present a certificate)
	by mx1.freebsd.org (Postfix) with ESMTPS id 02E65377
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 26 Mar 2014 17:59:01 +0000 (UTC)
Received: from cgiserv.freebsd.org ([127.0.1.6])
	by cgiserv.freebsd.org (8.14.8/8.14.8) with ESMTP id s2QHx037093172
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 26 Mar 2014 17:59:00 GMT
	(envelope-from nobody@cgiserv.freebsd.org)
Received: (from nobody@localhost)
	by cgiserv.freebsd.org (8.14.8/8.14.8/Submit) id s2QHx0cq093171;
	Wed, 26 Mar 2014 17:59:00 GMT
	(envelope-from nobody)
Message-Id: <201403261759.s2QHx0cq093171@cgiserv.freebsd.org>
Date: Wed, 26 Mar 2014 17:59:00 GMT
From: Takuya ASADA <syuu@freebsd.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Intel Baytrail-M NUC panics because of buggy ACPI table
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         187965
>Category:       kern
>Synopsis:       [acpi] [patch] Intel Baytrail-M NUC panics because of buggy ACPI table
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    takawata
>State:          patched
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 26 18:00:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Mon Apr 21 18:29:25 UTC 2014
>Originator:     Takuya ASADA
>Release:        CURRENT
>Organization:
Cloudius Systems
>Environment:
FreeBSD nuc 11.0-CURRENT FreeBSD 11.0-CURRENT #5 ff55131(master)-dirty: Thu Mar 27 09:05:10 JST 2014     root@nuc:/usr/obj/usr/home/syuu/freebsd/sys/GENERIC  amd64
>Description:
Intel Baytrail-M NUC(DN2820FYKH) does not able to boot FreeBSD-CURRENT/amd64, because of its buggy ACPI table.

It has two incorrect parameters on MADT: 

Type=Local APIC NMI
ACPI CPU=1
LINT Pin=60
Flags={Polarity=active-hi, Trigger=0x2} <-- trigger value is incorrect. 2 is reserved

Type=Local APIC NMI
ACPI CPU=2
LINT Pin=61
Flags={Polarity=0x2, Trigger=level} <-- polarity value is incorrect. 2 is reserved

Because of this, interrupt_trigger() panics with "Bogus Interrupt Trigger Mode".
Also interrupt_polarity() panics with "Bogus Interrupt Polarity".

I think this is BIOS bug, but we can do some workaround for the machine.
>How-To-Repeat:
Boot -CURRENT on NUC.
>Fix:
Linux uses level trigger and low polarity if the value is 0x2(reserved).
http://lxr.linux.no/linux+v3.13.5/arch/x86/kernel/acpi/boot.c#L1094

We can do similar workaround, but with warning message.
Patch is attached.

Patch attached with submission follows:

diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC
index cf18f2d..946923b 100644
--- a/sys/amd64/conf/GENERIC
+++ b/sys/amd64/conf/GENERIC
@@ -312,7 +312,7 @@ options 	USB_DEBUG		# enable debug msgs
 device		uhci			# UHCI PCI->USB interface
 device		ohci			# OHCI PCI->USB interface
 device		ehci			# EHCI PCI->USB interface (USB 2.0)
-device		xhci			# XHCI PCI->USB interface (USB 3.0)
+#device		xhci			# XHCI PCI->USB interface (USB 3.0)
 device		usb			# USB Bus (required)
 device		ukbd			# Keyboard
 device		umass			# Disks/Mass storage - Requires scbus and da
diff --git a/sys/x86/acpica/madt.c b/sys/x86/acpica/madt.c
index 9dfb77f..fdc86c0 100644
--- a/sys/x86/acpica/madt.c
+++ b/sys/x86/acpica/madt.c
@@ -308,14 +308,15 @@ interrupt_polarity(UINT16 IntiFlags, UINT8 Source)
 	case ACPI_MADT_POLARITY_ACTIVE_LOW:
 		return (INTR_POLARITY_LOW);
 	default:
-		panic("Bogus Interrupt Polarity");
+		printf("Bogus Interrupt Polarity %x, set to low\n",
+			IntiFlags & ACPI_MADT_POLARITY_MASK);
+		return (INTR_POLARITY_LOW);
 	}
 }
 
 static enum intr_trigger
 interrupt_trigger(UINT16 IntiFlags, UINT8 Source)
 {
-
 	switch (IntiFlags & ACPI_MADT_TRIGGER_MASK) {
 	case ACPI_MADT_TRIGGER_CONFORMS:
 		if (Source == AcpiGbl_FADT.SciInterrupt)
@@ -327,7 +328,9 @@ interrupt_trigger(UINT16 IntiFlags, UINT8 Source)
 	case ACPI_MADT_TRIGGER_LEVEL:
 		return (INTR_TRIGGER_LEVEL);
 	default:
-		panic("Bogus Interrupt Trigger Mode");
+		printf("Bogus Interrupt Trigger Mode %x, set to level\n",
+			IntiFlags & ACPI_MADT_TRIGGER_MASK);
+		return (INTR_TRIGGER_LEVEL);
 	}
 }
 


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->open 
State-Changed-By: linimon 
State-Changed-When: Sun Apr 20 01:48:45 UTC 2014 
State-Changed-Why:  
reclassify. 


Responsible-Changed-From-To: freebsd-amd64->freebsd-acpi 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Apr 20 01:48:45 UTC 2014 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=187965 
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Mon Apr 21 18:28:02 UTC 2014 
State-Changed-Why:  
This was fixed in HEAD in r263795 and r263859. 


Responsible-Changed-From-To: freebsd-acpi->takawata 
Responsible-Changed-By: jhb 
Responsible-Changed-When: Mon Apr 21 18:28:02 UTC 2014 
Responsible-Changed-Why:  
This was fixed in HEAD in r263795 and r263859. 

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