public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vernon Mauery <vernux@us.ibm.com>
To: Greg KH <greg@kroah.com>
Cc: pcihpd <pcihpd-discuss@lists.sourceforge.net>,
	lkml <linux-kernel@vger.kernel.org>, Greg KH <gregkh@us.ibm.com>,
	Pat Gaughen <gone@us.ibm.com>, Chris McDermott <lcm@us.ibm.com>,
	Jess Botts <botts@us.ibm.com>
Subject: [PATCH] acpiphp extension fixes for 2.6.9-rc2
Date: Thu, 16 Sep 2004 11:23:13 -0700	[thread overview]
Message-ID: <1095358993.13519.8.camel@localhost.localdomain> (raw)
In-Reply-To: <20040708232827.GA20755@kroah.com>

This patch fixes an off by one error that one of the IBM machines that
uses the acpiphp_ibm driver.  The slots were numbered starting at 0 in
BIOS instead of starting at 1 like the pci hotplug subsystem names
them.  So this patch provides a lookup to translate the Linux slot
numbers to the internal ACPI numbers.

 acpiphp_ibm.c |   96 +++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 59 insertions(+), 37 deletions(-)

Signed-off-by: Vernon Mauery <vernux@us.ibm.com>

=====================================================================
diff -Nuar -X dontdiff linux-2.6.9-rc2.orig/drivers/pci/hotplug/acpiphp_ibm.c linux-2.6.9-rc2-avatar/drivers/pci/hotplug/acpiphp_ibm.c
--- linux-2.6.9-rc2.orig/drivers/pci/hotplug/acpiphp_ibm.c	2004-09-15 21:03:53.694926544 -0700
+++ linux-2.6.9-rc2-avatar/drivers/pci/hotplug/acpiphp_ibm.c	2004-09-16 17:56:22.551563832 -0700
@@ -64,6 +64,8 @@
 #define IBM_HARDWARE_ID1 "IBM37D0"
 #define IBM_HARDWARE_ID2 "IBM37D4"
 
+#define hpslot_to_sun(A) (((struct slot *)((A)->private))->acpi_slot->sun)
+
 /* union apci_descriptor - allows access to the
  * various device descriptors that are embedded in the
  * aPCI table
@@ -128,6 +130,42 @@
 	.owner = THIS_MODULE,
 };
 
+/**
+ * ibm_slot_from_id - workaround for bad ibm hardware
+ * @id: the slot number that linux refers to the slot by
+ *
+ * Description: this method returns the aCPI slot descriptor
+ * corresponding to the Linux slot number.  This descriptor
+ * has info about the aPCI slot id and attention status.
+ * This descriptor must be freed using kfree when done.
+ **/
+static union apci_descriptor *ibm_slot_from_id(int id)
+{
+	int ind = 0, size;
+	union apci_descriptor *ret = NULL, *des;
+	char *table;
+
+	size = ibm_get_table_from_acpi(&table);
+	des = (union apci_descriptor *)table;
+	if (memcmp(des->header.sig, "aPCI", 4) != 0)
+		goto ibm_slot_done;
+
+	des = (union apci_descriptor *)&table[ind += des->header.len];
+	while (ind < size && (des->generic.type != 0x82 ||
+			des->slot.slot_num != id))
+		des = (union apci_descriptor *)&table[ind += des->generic.len];
+
+	if (ind < size && des->slot.slot_num == id)
+		ret = des;
+
+ibm_slot_done:
+	kfree(table);
+	if (ret) {
+		ret = kmalloc(sizeof(union apci_descriptor), GFP_KERNEL);
+		memcpy(ret, des, sizeof(union apci_descriptor));
+	}
+	return ret;
+}
 
 /**
  * ibm_set_attention_status - callback method to set the attention LED
@@ -139,32 +177,34 @@
  **/
 static int ibm_set_attention_status(struct hotplug_slot *slot, u8 status)
 {
-	int retval = 0;
 	union acpi_object args[2]; 
 	struct acpi_object_list params = { .pointer = args, .count = 2 };
 	acpi_status stat; 
-	unsigned long rc = 0;
-	struct acpiphp_slot *acpi_slot;
+	unsigned long rc;
+	union apci_descriptor *ibm_slot;
 
-	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+	ibm_slot = ibm_slot_from_id(hpslot_to_sun(slot));
 
-	dbg("%s: set slot %d attention status to %d\n", __FUNCTION__,
-			acpi_slot->sun, (status ? 1 : 0));
+	dbg("%s: set slot %d (%d) attention status to %d\n", __FUNCTION__,
+			ibm_slot->slot.slot_num, ibm_slot->slot.slot_id,
+			(status ? 1 : 0));
 
 	args[0].type = ACPI_TYPE_INTEGER;
-	args[0].integer.value = acpi_slot->sun;
+	args[0].integer.value = ibm_slot->slot.slot_id;
 	args[1].type = ACPI_TYPE_INTEGER;
 	args[1].integer.value = (status) ? 1 : 0;
 
+	kfree(ibm_slot);
+
 	stat = acpi_evaluate_integer(ibm_acpi_handle, "APLS", &params, &rc);
 	if (ACPI_FAILURE(stat)) {
-		retval = -ENODEV;
 		err("APLS evaluation failed:  0x%08x\n", stat);
+		return -ENODEV;
 	} else if (!rc) {
-		retval = -ERANGE;
 		err("APLS method failed:  0x%08lx\n", rc);
+		return -ERANGE;
 	}
-	return retval;
+	return 0;
 }
 
 /**
@@ -181,38 +221,20 @@
  **/
 static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status)
 {
-	int retval = -EINVAL, ind = 0, size;
-	char *table = NULL;
-	struct acpiphp_slot *acpi_slot;
 	union apci_descriptor *des;
 
-	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+	des = ibm_slot_from_id(hpslot_to_sun(slot));
 
-	size = ibm_get_table_from_acpi(&table);
-	if (size <= 0 || !table)
-		goto get_attn_done;
-	// read the header
-	des = (union apci_descriptor *)&table[ind];
-	if (memcmp(des->header.sig, "aPCI", 4) != 0)
-		goto get_attn_done;
-	des = (union apci_descriptor *)&table[ind += des->header.len];
-	while (ind < size && (des->generic.type != 0x82 ||
-			des->slot.slot_id != acpi_slot->sun))
-		des = (union apci_descriptor *)&table[ind += des->generic.len];
-	if (ind < size && des->slot.slot_id == acpi_slot->sun) {
-		retval = 0;
-		if (des->slot.attn & 0xa0 || des->slot.status[1] & 0x08)
-			*status = 1;
-		else
-			*status = 0;
-	}
+	if (des->slot.attn & 0xa0 || des->slot.status[1] & 0x08)
+		*status = 1;
+	else
+		*status = 0;
 
-	dbg("%s: get slot %d attention status is %d retval=%x\n",
-			__FUNCTION__, acpi_slot->sun, *status, retval);
+	dbg("%s: get slot %d (%d) attention status is %d\n", __FUNCTION__,
+			des->slot.slot_num, des->slot.slot_id, *status);
 
-get_attn_done:
-	kfree(table);
-	return retval;
+	kfree(des);
+	return 0;
 }
 
 /**



  parent reply	other threads:[~2004-09-16 18:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-22 19:53 [PATCH] acpiphp extension for 2.6.7 Vernon Mauery
2004-06-24 21:45 ` Greg KH
2004-06-25 16:42   ` Vernon Mauery
2004-06-29 18:47   ` Vernon Mauery
2004-06-29 23:50   ` [PATCH] [0/2] " Vernon Mauery
2004-07-02 20:58     ` [Pcihpd-discuss] " Greg KH
2004-07-03  0:02       ` [PATCH] [0/2] acpiphp extension for 2.6.7 (take 3) Vernon Mauery
2004-07-03  0:02       ` [PATCH] [1/2] " Vernon Mauery
2004-07-03  0:02       ` [PATCH] [2/2] " Vernon Mauery
2004-06-29 23:50   ` [PATCH] [1/2] acpiphp extension for 2.6.7 Vernon Mauery
2004-06-29 23:50   ` [PATCH] [2/2] " Vernon Mauery
     [not found] ` <200407071147.57604@bilbo.math.uni-mannheim.de>
     [not found]   ` <1089216410.24908.5.camel@bluerat>
     [not found]     ` <200407081209.42927@bilbo.math.uni-mannheim.de>
     [not found]       ` <1089328415.2089.194.camel@bluerat>
     [not found]         ` <20040708232827.GA20755@kroah.com>
2004-07-09  0:11           ` [PATCH] [0/2] acpiphp extension for 2.6.7 (final) Vernon Mauery
2004-07-09  0:12           ` [PATCH] [1/2] " Vernon Mauery
2004-07-14 22:52             ` Greg KH
2004-07-09  0:12           ` [PATCH] [2/2] " Vernon Mauery
2004-07-14 22:52             ` Greg KH
2004-09-16 18:23           ` Vernon Mauery [this message]
2004-09-17 22:10             ` [PATCH] acpiphp extension fixes for 2.6.9-rc2 Vernon Mauery
2004-09-22 20:29               ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1095358993.13519.8.camel@localhost.localdomain \
    --to=vernux@us.ibm.com \
    --cc=botts@us.ibm.com \
    --cc=gone@us.ibm.com \
    --cc=greg@kroah.com \
    --cc=gregkh@us.ibm.com \
    --cc=lcm@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pcihpd-discuss@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox