public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] acpiphp extension for 2.6.7
@ 2004-06-22 19:53 Vernon Mauery
  2004-06-24 21:45 ` Greg KH
       [not found] ` <200407071147.57604@bilbo.math.uni-mannheim.de>
  0 siblings, 2 replies; 19+ messages in thread
From: Vernon Mauery @ 2004-06-22 19:53 UTC (permalink / raw)
  To: lkml; +Cc: gregkh, Pat Gaughen, Chris McDermott, Jess Botts

According to the specification, ACPI does not have a standard way of
querying or manipulating the attention LED of hotplug slots.  Here is a
patch that allows for device specific ACPI code to be registered with
the acpiphp driver as callbacks for setting/getting the status of the
attention LED.

This patch was made against the 2.6.7 mainline kernel and adds the first
driver to take advantage of the acpiphp attention LED callbacks,
supporting about 5 of IBM's platforms that use acpiphp.  It also some
other functionality in addition to the LED getter/setter callback that
IBM's active PCI team needed from their hotplug userspace program.  It
adds reading events from the hotplug slot and forwarding them on to the
ACPI subsystem and exporting a binary table in the
/sys/bus/pci/slots/apci_table file.

--Vernon


diff -Nur linux-2.6.7/drivers/pci/hotplug/Kconfig linux-2.6.7.apci/drivers/pci/hotplug/Kconfig
--- linux-2.6.7/drivers/pci/hotplug/Kconfig	2004-06-15 22:19:17.000000000 -0700
+++ linux-2.6.7.apci/drivers/pci/hotplug/Kconfig	2004-06-22 11:49:38.082484048 -0700
@@ -88,6 +88,18 @@
 
 	  When in doubt, say N.
 
+config HOTPLUG_PCI_ACPI_IBM
+	tristate "ACPI PCI Hotplug driver IBM extensions"
+	depends on HOTPLUG_PCI_ACPI
+	help
+	  Say Y here if you have an IBM system that supports PCI Hotplug using
+	  ACPI.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called acpiphp_ibm.
+
+	  When in doubt, say N.
+
 config HOTPLUG_PCI_CPCI
 	bool "CompactPCI Hotplug driver"
 	depends on HOTPLUG_PCI
diff -Nur linux-2.6.7/drivers/pci/hotplug/Makefile linux-2.6.7.apci/drivers/pci/hotplug/Makefile
--- linux-2.6.7/drivers/pci/hotplug/Makefile	2004-06-15 22:19:43.000000000 -0700
+++ linux-2.6.7.apci/drivers/pci/hotplug/Makefile	2004-06-22 11:49:38.083483896 -0700
@@ -7,6 +7,7 @@
 obj-$(CONFIG_HOTPLUG_PCI_COMPAQ)	+= cpqphp.o
 obj-$(CONFIG_HOTPLUG_PCI_IBM)		+= ibmphp.o
 obj-$(CONFIG_HOTPLUG_PCI_ACPI)		+= acpiphp.o
+obj-$(CONFIG_HOTPLUG_PCI_ACPI_IBM)	+= acpiphp_ibm.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_ZT5550)	+= cpcihp_zt5550.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_GENERIC)	+= cpcihp_generic.o
 obj-$(CONFIG_HOTPLUG_PCI_PCIE)		+= pciehp.o
diff -Nur linux-2.6.7/drivers/pci/hotplug/acpiphp.h linux-2.6.7.apci/drivers/pci/hotplug/acpiphp.h
--- linux-2.6.7/drivers/pci/hotplug/acpiphp.h	2004-06-15 22:20:26.000000000 -0700
+++ linux-2.6.7.apci/drivers/pci/hotplug/acpiphp.h	2004-06-22 11:49:38.084483744 -0700
@@ -172,6 +172,22 @@
 };
 
 
+/**
+ * struct acpiphp_attention_info - device specific attention registration
+ *
+ * ACPI has no generic method of setting/getting attention status
+ * this allows for device specific driver registration
+ */
+typedef int (*acpiphp_set_attn_callback)(struct hotplug_slot *slot, u8 status);
+typedef int (*acpiphp_get_attn_callback)(struct hotplug_slot *slot, u8 *status);
+struct acpiphp_attention_info
+{
+	acpiphp_set_attn_callback set_attn;
+	acpiphp_get_attn_callback get_attn;
+	struct module *owner;
+};
+
+
 /* PCI bus bridge HID */
 #define ACPI_PCI_HOST_HID		"PNP0A03"
 
@@ -212,6 +228,12 @@
 
 /* function prototypes */
 
+/* acpiphp_core.c */
+extern int acpiphp_register_attention_info(
+		struct acpiphp_attention_info*info);
+extern int acpiphp_unregister_attention_info(
+		struct acpiphp_attention_info *info);
+
 /* acpiphp_glue.c */
 extern int acpiphp_glue_init (void);
 extern void acpiphp_glue_exit (void);
diff -Nur linux-2.6.7/drivers/pci/hotplug/acpiphp_core.c linux-2.6.7.apci/drivers/pci/hotplug/acpiphp_core.c
--- linux-2.6.7/drivers/pci/hotplug/acpiphp_core.c	2004-06-15 22:19:37.000000000 -0700
+++ linux-2.6.7.apci/drivers/pci/hotplug/acpiphp_core.c	2004-06-22 11:49:38.084483744 -0700
@@ -51,6 +51,8 @@
 
 /* local variables */
 static int num_slots;
+static spinlock_t attn_info_lock = SPIN_LOCK_UNLOCKED;
+static struct acpiphp_attention_info attention_info;
 
 #define DRIVER_VERSION	"0.4"
 #define DRIVER_AUTHOR	"Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>"
@@ -62,10 +64,15 @@
 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
 module_param(debug, bool, 644);
 
+/* export the attention callback registration methods */
+EXPORT_SYMBOL_GPL(acpiphp_register_attention_info);
+EXPORT_SYMBOL_GPL(acpiphp_unregister_attention_info);
+
 static int enable_slot		(struct hotplug_slot *slot);
 static int disable_slot		(struct hotplug_slot *slot);
 static int set_attention_status (struct hotplug_slot *slot, u8 value);
 static int get_power_status	(struct hotplug_slot *slot, u8 *value);
+static int get_attention_status (struct hotplug_slot *slot, u8 *value);
 static int get_address		(struct hotplug_slot *slot, u32 *value);
 static int get_latch_status	(struct hotplug_slot *slot, u8 *value);
 static int get_adapter_status	(struct hotplug_slot *slot, u8 *value);
@@ -76,11 +83,68 @@
 	.disable_slot		= disable_slot,
 	.set_attention_status	= set_attention_status,
 	.get_power_status	= get_power_status,
+	.get_attention_status	= get_attention_status,
 	.get_latch_status	= get_latch_status,
 	.get_adapter_status	= get_adapter_status,
 	.get_address		= get_address,
 };
 
+
+/**
+    * acpiphp_register_attention_info - set attention LED callback
+    *
+    * this is used to register a hardware specific acpi driver
+    * that manipulates the attention LED.  All the fields in
+    * info must be set.
+    *
+    */
+int acpiphp_register_attention_info(struct acpiphp_attention_info *info)
+{
+	int retval = 0;
+	unsigned long flags;
+
+	if (!info || !info->owner || !info->set_attn || !info->get_attn)
+		retval = -1;
+	else {
+		spin_lock_irqsave(&attn_info_lock, flags);
+		if (!attention_info.owner)
+			memcpy(&attention_info, info,
+					sizeof(struct acpiphp_attention_info));
+		spin_unlock_irqrestore(&attn_info_lock, flags);
+	}
+	return retval;
+}
+
+
+/**
+ * acpiphp_unregister_attention_info - unset attention LED callback
+ *
+ * this is used to un-register a hardware specific acpi driver
+ * that manipulates the attention LED.  Both fields must
+ * match the current attention info to reset it.
+ *
+ */
+int acpiphp_unregister_attention_info(struct acpiphp_attention_info *info)
+{
+	int retval = 0;
+	unsigned long flags;
+
+	if (!info || !info->owner || !info->set_attn || !info->get_attn)
+		retval = -1;
+	else {
+		spin_lock_irqsave(&attn_info_lock, flags);
+		if (memcmp(&attention_info, info, 
+				sizeof(struct acpiphp_attention_info)) == 0)
+			memset(&attention_info, 0,
+					sizeof(struct acpiphp_attention_info));
+		else
+			retval = -1;
+		spin_unlock_irqrestore(&attn_info_lock, flags);
+	}
+	return retval;
+}
+
+
 /**
  * enable_slot - power on and enable a slot
  * @hotplug_slot: slot to enable
@@ -120,29 +184,33 @@
 /**
  * set_attention_status - set attention LED
  *
- * TBD:
  * ACPI doesn't have known method to manipulate
- * attention status LED.
+ * attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to blink the light for us.
  *
  */
-static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
+static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
 {
+	int retval = -1;
+	unsigned long flags;
+	struct acpiphp_attention_info info;
+
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
-	switch (status) {
-		case 0:
-			/* FIXME turn light off */
-			hotplug_slot->info->attention_status = 0;
-			break;
-
-		case 1:
-		default:
-			/* FIXME turn light on */
-			hotplug_slot->info->attention_status = 1;
-			break;
+	spin_lock_irqsave(&attn_info_lock, flags);
+	memcpy(&info, &attention_info, sizeof(struct acpiphp_attention_info));
+	spin_unlock_irqrestore(&attn_info_lock, flags);
+
+	if (info.set_attn && try_module_get(info.owner)) {
+		retval = info.set_attn(hotplug_slot, status);
+		module_put(info.owner);
 	}
 
-	return 0;
+	if (!retval)
+		hotplug_slot->info->attention_status = (status) ? 1 : 0;
+
+	return retval;
 }
 
 /**
@@ -166,6 +234,39 @@
 }
 
 /**
+ * get_attention_status - get attention LED status
+ *
+ * ACPI doesn't have known method to determine the state
+ * of the attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to determine its state
+ *
+ */
+static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
+{
+	int retval = 0;
+	struct acpiphp_attention_info info;
+	unsigned long flags;
+
+	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
+
+	spin_lock_irqsave(&attn_info_lock, flags);
+	memcpy(&info, &attention_info, sizeof(struct acpiphp_attention_info));
+	spin_unlock_irqrestore(&attn_info_lock, flags);
+
+	if (info.get_attn && try_module_get(info.owner)) {
+		retval = info.get_attn(hotplug_slot, value);
+		module_put(info.owner);
+	} else {
+		dbg("%s: no get_attn callback, returning stored value\n",
+				__FUNCTION__);
+		*value = hotplug_slot->info->attention_status;
+	}
+	return retval;
+}
+
+
+/**
  * get_latch_status - get latch status of a slot
  * @hotplug_slot: slot to get status
  * @value: pointer to store status
@@ -307,7 +408,7 @@
 
 		slot->acpi_slot = get_slot_from_id(i);
 		slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
-		slot->hotplug_slot->info->attention_status = acpiphp_get_attention_status(slot->acpi_slot);
+		slot->hotplug_slot->info->attention_status = 0;
 		slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
 		slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
 		slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
@@ -361,6 +462,7 @@
 	info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
 
 	acpiphp_debug = debug;
+	memset(&attention_info, 0, sizeof(struct acpiphp_attention_info));
 
 	/* read all the ACPI info from the system */
 	retval = init_acpi();
diff -Nur linux-2.6.7/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.7.apci/drivers/pci/hotplug/acpiphp_glue.c
--- linux-2.6.7/drivers/pci/hotplug/acpiphp_glue.c	2004-06-15 22:19:10.000000000 -0700
+++ linux-2.6.7.apci/drivers/pci/hotplug/acpiphp_glue.c	2004-06-22 11:49:38.108480096 -0700
@@ -1302,20 +1302,6 @@
 
 
 /*
- * attention LED ON: 1
- *		OFF: 0
- *
- * TBD
- * no direct attention led status information via ACPI
- *
- */
-u8 acpiphp_get_attention_status(struct acpiphp_slot *slot)
-{
-	return 0;
-}
-
-
-/*
  * latch closed:  1
  * latch   open:  0
  */
diff -Nur linux-2.6.7/drivers/pci/hotplug/acpiphp_ibm.c linux-2.6.7.apci/drivers/pci/hotplug/acpiphp_ibm.c
--- linux-2.6.7/drivers/pci/hotplug/acpiphp_ibm.c	1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.7.apci/drivers/pci/hotplug/acpiphp_ibm.c	2004-06-22 11:49:38.108480096 -0700
@@ -0,0 +1,471 @@
+/*
+ * ACPI PCI Hot Plug IBM Extension
+ *
+ * Copyright (C) 2004 Vernon Mauery <vernux@us.ibm.com>
+ * Copyright (C) 2004 IBM Corp.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Send feedback to <vernux@us.ibm.com>
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <acpi/acpi_bus.h>
+#include <linux/sysfs.h>
+#include <linux/kobject.h>
+#include <asm/uaccess.h>
+//#include <linux/moduleparam.h>
+
+#include "acpiphp.h"
+#include "pci_hotplug.h"
+
+#define DRIVER_VERSION	"1.0.1"
+#define DRIVER_AUTHOR	"Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
+#define DRIVER_DESC	"ACPI Hot Plug PCI Controller Driver IBM extension"
+
+static int debug;
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_PARM(debug, "i");
+MODULE_PARM_DESC(debug, " Debugging mode enabled or not");
+#define MY_NAME "acpiphp_ibm"
+
+#ifdef dbg
+#undef dbg
+#endif
+#define dbg(format, arg...)				\
+do {							\
+	if (debug)					\
+		printk(KERN_DEBUG "%s: " format,	\
+				MY_NAME , ## arg);	\
+} while (0)
+
+#define FOUND_APCI 0x61504349
+/* these are the names for the IBM ACPI pseudo-device */
+#define IBM_HARDWARE_ID1 "IBM37D0"
+#define IBM_HARDWARE_ID2 "IBM37D4"
+
+/* union apci_descriptor - allows access to the
+ * various device descriptors that are embedded in the
+ * aPCI table
+ */
+union apci_descriptor {
+	struct {
+		char sig[4];
+		u8   len;
+	} header;
+	struct {
+		u8  type;
+		u8  len;
+		u16 slot_id;
+		u8  bus_id;
+		u8  dev_num;
+		u8  slot_num;
+		u8  slot_attr[2];
+		u8  attn;
+		u8  status[2];
+		u8  sun;
+	} slot;
+	struct {
+		u8 type;
+		u8 len;
+	} generic;
+};
+
+/* struct notification - keeps info about the device
+ * that cause the ACPI notification event
+ */
+struct notification {
+	struct acpi_device *device;
+	u8                  event;
+};
+
+/* forward declarations of functions for this module
+ */
+static int ibm_set_attention_status (struct hotplug_slot *slot, u8 status);
+static int ibm_get_attention_status (struct hotplug_slot *slot, u8 *status);
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context);
+static int ibm_get_table_from_acpi(char **bufp);
+static ssize_t ibm_read_apci_table(struct kobject *kobj,
+		char *buffer, loff_t pos, size_t size);
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv);
+static int __init ibm_acpiphp_init(void);
+static void __exit ibm_acpiphp_exit(void);
+
+/* static global variables
+ */
+static acpi_handle ibm_acpi_handle = NULL;
+static struct notification ibm_note;
+static struct bin_attribute ibm_apci_table_attr = {
+	    .attr = {
+		    .name = "apci_table",
+		    .owner = THIS_MODULE,
+		    .mode = S_IRUGO,
+	    },
+	    .read = ibm_read_apci_table,
+	    .write = NULL,
+};
+static struct acpiphp_attention_info ibm_attention_info = 
+{
+	.set_attn = ibm_set_attention_status,
+	.get_attn = ibm_get_attention_status,
+	.owner = THIS_MODULE,
+};
+
+
+/*
+ * ibm_set_attention_status - callback method to set the attention LED
+ *
+ * this method is registered with the acpiphp module as a callback
+ * to do the device specific task of setting the LED status
+ *
+ */
+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;
+
+	if (!slot || !slot->private)
+		return -1;
+	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+	if (!acpi_slot)
+		return -1;
+
+	dbg("%s: set slot %d attention status to %d\n", __FUNCTION__,
+			acpi_slot->sun, (status ? 1 : 0));
+
+	args[0].type = ACPI_TYPE_INTEGER;
+	args[0].integer.value = acpi_slot->sun;
+	args[1].type = ACPI_TYPE_INTEGER;
+	args[1].integer.value = (status) ? 1 : 0;
+
+	stat = acpi_evaluate_integer(ibm_acpi_handle, "APLS", &params, &rc);
+	if (ACPI_FAILURE(stat)) {
+		retval = -1;
+		err("APLS evaluation failed:  0x%08x\n", stat);
+	} else if (!rc) {
+		retval = -1;
+		err("APLS method failed:  0x%08lx\n", rc);
+	}
+	return retval;
+}
+
+/*
+ * ibm_get_attention_status - callback method to get attention LED status
+ *
+ * this method is registered with the acpiphp module as a callback
+ * to do the device specific task of getting the LED status
+ * 
+ * Because there is no direct method of getting the LED status directly
+ * from an ACPI call, we read the aPCI table and parse out our
+ * slot descriptor to read the status from that.
+ *
+ */
+static int ibm_get_attention_status (struct hotplug_slot *slot, u8 *status)
+{
+	int retval = -1, ind = 0, size;
+	char *table = NULL;
+	struct acpiphp_slot *acpi_slot;
+	union apci_descriptor *des;
+
+	if (!slot || !slot->private)
+		goto get_attn_done;
+	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+	if (!acpi_slot)
+		goto get_attn_done;
+
+	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;
+	}
+
+	dbg("%s: get slot %d attention status is %d retval=%x\n",
+			__FUNCTION__, acpi_slot->sun, *status, retval);
+
+get_attn_done:
+	if (table)
+		kfree(table);
+	return retval;
+}
+
+/*
+ * ibm_handle_events - listens for ACPI events for the IBM37D0 device
+ *
+ * this method is registered as a callback with the ACPI subsystem
+ * it is called when this device has an event to notify the OS of
+ *
+ * the events actually come from the device as two events that get
+ * synthesized into one event with data by this function.  The event
+ * ID comes first and then the slot number that caused it.  We report
+ * this as one event to the OS.
+ *
+ */
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context)
+{
+	// FIXME: this may have re-entrancy errors with event being static...
+	u8 detail = event & 0x0f;
+	u8 subevent = event & 0xf0;
+
+	struct notification *note = (struct notification *)context;
+
+	dbg("%s: Received notification %02x\n", __FUNCTION__, event);
+
+	if (subevent == 0x80) {
+		dbg("%s: generationg bus event\n", __FUNCTION__);
+		acpi_bus_generate_event(note->device, note->event, detail);
+	} else
+		note->event = event;
+}
+
+/*
+ * ibm_get_table_from_acpi - reads the APLS buffer from ACPI
+ * 
+ * this method reads the APLS buffer in from ACPI and
+ * stores the "stripped" table into a single buffer
+ * it allocates and passes the address back in bufp
+ *
+ * if NULL is passed in as buffer, this method only calculates
+ * the size of the table and returns that without filling
+ * in the buffer
+ *
+ * returns < 0 on error or the size of the table on success
+ */
+static int ibm_get_table_from_acpi(char **bufp)
+{
+	union acpi_object *package;
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	acpi_status status;
+	char *lbuf = NULL;
+	int i, size = -1;
+
+	status = acpi_evaluate_object(ibm_acpi_handle, "APCI", NULL, &buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  APCI evaluation failed\n", __FUNCTION__);
+		return -ENODEV;
+	}
+
+	package = (union acpi_object *) buffer.pointer;
+	if(!(package) ||
+			(package->type != ACPI_TYPE_PACKAGE) ||
+			!(package->package.elements)) {
+		err("%s:  Invalid APCI object\n", __FUNCTION__);
+		goto read_table_done;
+	}
+
+	for(size = 0, i = 0; i < package->package.count; i++) {
+		if (package->package.elements[i].type != ACPI_TYPE_BUFFER) {
+			err("%s:  Invalid APCI element %d\n", __FUNCTION__, i);
+			goto read_table_done;
+		}
+		size += package->package.elements[i].buffer.length;
+	}
+
+	if (bufp == NULL)
+		goto read_table_done;
+
+	lbuf = kmalloc(size, GFP_KERNEL);
+	dbg("%s: element count: %i, ASL table size: %i, &table = 0x%x\n",
+			__FUNCTION__, package->package.count, size, (int)lbuf);
+
+	if (lbuf) {
+		*bufp = lbuf;
+		memset(lbuf, 0, size);
+	} else {
+		size = -ENOMEM;
+		goto read_table_done;
+	}
+
+	size = 0;
+	for (i=0; i<package->package.count; i++) {
+		memcpy(&lbuf[size],
+				package->package.elements[i].buffer.pointer,
+				package->package.elements[i].buffer.length);
+		size += package->package.elements[i].buffer.length;
+	}
+
+read_table_done:
+	kfree(buffer.pointer);
+	return size;
+}
+
+/* ibm_read_apci_table - callback for the sysfs apci_table file
+ *
+ * gets registered with sysfs as the reader callback
+ * to be executed when /sys/bus/pci/slots/apci_table gets read
+ *
+ * since we don't get notified on open and close for this file,
+ * things get really tricky here...
+ * our solution is to only allow reading the table in all at once
+ */
+static ssize_t ibm_read_apci_table(struct kobject *kobj,
+		char *buffer, loff_t pos, size_t size)
+{
+	int bytes_read = -EINVAL;
+	char *table = NULL;
+	
+	dbg("%s: pos = %d, size = %d\n", __FUNCTION__, (int)pos, size);
+
+	if (pos == 0) {
+		bytes_read = ibm_get_table_from_acpi(&table);
+		if (bytes_read > 0 && bytes_read <= size)
+			memcpy(buffer, table, bytes_read);
+		if (table)
+			kfree(table);
+	}
+	return bytes_read;
+}
+
+/* ibm_find_acpi_device - callback to find our ACPI device
+ *
+ * used as a callback when calling acpi_walk_namespace
+ * to find our device.  When this method returns non-zero
+ * acpi_walk_namespace quits its search and returns our value
+ */
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv)
+{
+	acpi_handle *phandle = (acpi_handle *)context;
+	acpi_status status; 
+	struct acpi_device_info info; 
+	struct acpi_buffer info_buffer = {
+		.length = sizeof(struct acpi_device_info),
+		.pointer = &info,
+	};
+
+	status = acpi_get_object_info(handle, &info_buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  Failed to get device information", __FUNCTION__);
+		return 0;
+	}
+	info.hardware_id.value[sizeof(info.hardware_id.value) - 1] = '\0';
+
+	if(info.current_status && (info.valid & ACPI_VALID_HID) &&
+			(!strcmp(info.hardware_id.value, IBM_HARDWARE_ID1) ||
+			!strcmp(info.hardware_id.value, IBM_HARDWARE_ID2))) {
+		dbg("found hardware: %s, handle: %x\n", info.hardware_id.value,
+				(unsigned int)handle);
+		*phandle = handle;
+		/* returning non-zero causes the search to stop
+		 * and returns this value to the caller of 
+		 * acpi_walk_namespace, but it also causes some warnings
+		 * in the acpi debug code to print...
+		 */
+		return FOUND_APCI;
+	}
+	return 0;
+}
+
+static int __init ibm_acpiphp_init(void)
+{
+	int retval = 0;
+	acpi_status status;
+	struct acpi_device *device;
+	struct kobject *slotdir = &pci_hotplug_slots_subsys.kset.kobj;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+			ACPI_UINT32_MAX, ibm_find_acpi_device,
+			&ibm_acpi_handle, NULL) != FOUND_APCI) {
+		err("%s: acpi_walk_namespace failed\n", __FUNCTION__);
+		return -ENODEV;
+	}
+	dbg("%s: found IBM aPCI device\n", __FUNCTION__);
+	if (acpi_bus_get_device(ibm_acpi_handle, &device)) {
+		err("%s: acpi_bus_get_device failed\n", __FUNCTION__);
+		return -ENODEV;
+	}
+	if (acpiphp_register_attention_info(&ibm_attention_info))
+		return -ENODEV;
+
+	ibm_note.device = device;
+	status = acpi_install_notify_handler(
+			ibm_acpi_handle,
+			ACPI_DEVICE_NOTIFY,
+			ibm_handle_events,
+			(void *)&ibm_note);
+	if (ACPI_FAILURE(status))
+	{
+		err("%s:  Failed to register notification handler\n",
+				__FUNCTION__);
+		retval = -EBUSY;
+		goto init_cleanup;
+	}
+
+	ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
+	retval = sysfs_create_bin_file(slotdir, &ibm_apci_table_attr);
+
+	return retval;
+
+init_cleanup:
+	acpiphp_unregister_attention_info(&ibm_attention_info);
+	return retval;
+}
+
+static void __exit ibm_acpiphp_exit(void)
+{
+	acpi_status status;
+	struct kobject *slotdir = &pci_hotplug_slots_subsys.kset.kobj;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpiphp_unregister_attention_info(&ibm_attention_info))
+		err("%s: attention info deregistration failed", __FUNCTION__);
+
+	   status = acpi_remove_notify_handler(
+			   ibm_acpi_handle,
+			   ACPI_DEVICE_NOTIFY,
+			   ibm_handle_events);
+	   if (ACPI_FAILURE(status))
+		   err("%s:  Notification handler removal failed\n",
+				   __FUNCTION__);
+	// remove the /sys entries
+	if (sysfs_remove_bin_file(slotdir, &ibm_apci_table_attr))
+		err("%s: removal of sysfs file apci_table failed\n",
+				__FUNCTION__);
+}
+
+module_init(ibm_acpiphp_init);
+module_exit(ibm_acpiphp_exit);
+
+



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] acpiphp extension for 2.6.7
  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
                     ` (4 more replies)
       [not found] ` <200407071147.57604@bilbo.math.uni-mannheim.de>
  1 sibling, 5 replies; 19+ messages in thread
From: Greg KH @ 2004-06-24 21:45 UTC (permalink / raw)
  To: Vernon Mauery; +Cc: lkml, Pat Gaughen, Chris McDermott, Jess Botts

On Tue, Jun 22, 2004 at 12:53:49PM -0700, Vernon Mauery wrote:
> According to the specification, ACPI does not have a standard way of
> querying or manipulating the attention LED of hotplug slots.  Here is a
> patch that allows for device specific ACPI code to be registered with
> the acpiphp driver as callbacks for setting/getting the status of the
> attention LED.

The LED stuff looks good (few minor comments below), but the ACPI table
info should be moved to the ACPI core to provide this to all ACPI tables
in the /sys/firmware/acpi tree.

> +static struct acpiphp_attention_info attention_info;

This should just be a pointer, not the whole structure.  Then just set
it to whatever pointer is passed to you from the module.

> +/**
> +    * acpiphp_register_attention_info - set attention LED callback
> +    *
> +    * this is used to register a hardware specific acpi driver
> +    * that manipulates the attention LED.  All the fields in
> +    * info must be set.
> +    *
> +    */
> +int acpiphp_register_attention_info(struct acpiphp_attention_info *info)
> +{
> +	int retval = 0;
> +	unsigned long flags;
> +
> +	if (!info || !info->owner || !info->set_attn || !info->get_attn)
> +		retval = -1;
> +	else {
> +		spin_lock_irqsave(&attn_info_lock, flags);

Why lock here?  What could race?

And why the irqsave lock?

> +		if (!attention_info.owner)
> +			memcpy(&attention_info, info,
> +					sizeof(struct acpiphp_attention_info));
> +		spin_unlock_irqrestore(&attn_info_lock, flags);
> +	}
> +	return retval;
> +}
> +
> +
> +/**
> + * acpiphp_unregister_attention_info - unset attention LED callback
> + *
> + * this is used to un-register a hardware specific acpi driver
> + * that manipulates the attention LED.  Both fields must
> + * match the current attention info to reset it.
> + *
> + */
> +int acpiphp_unregister_attention_info(struct acpiphp_attention_info *info)
> +{
> +	int retval = 0;
> +	unsigned long flags;
> +
> +	if (!info || !info->owner || !info->set_attn || !info->get_attn)
> +		retval = -1;
> +	else {
> +		spin_lock_irqsave(&attn_info_lock, flags);
> +		if (memcmp(&attention_info, info, 
> +				sizeof(struct acpiphp_attention_info)) == 0)
> +			memset(&attention_info, 0,
> +					sizeof(struct acpiphp_attention_info));
> +		else
> +			retval = -1;
> +		spin_unlock_irqrestore(&attn_info_lock, flags);
> +	}
> +	return retval;
> +}
> +
> +
>  /**
>   * enable_slot - power on and enable a slot
>   * @hotplug_slot: slot to enable
> @@ -120,29 +184,33 @@
>  /**
>   * set_attention_status - set attention LED
>   *
> - * TBD:
>   * ACPI doesn't have known method to manipulate
> - * attention status LED.
> + * attention status LED, so we use a callback that
> + * was registered with us.  This allows hardware specific
> + * ACPI implementations to blink the light for us.
>   *
>   */
> -static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
> +static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
>  {
> +	int retval = -1;
> +	unsigned long flags;
> +	struct acpiphp_attention_info info;
> +
>  	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
>  
> -	switch (status) {
> -		case 0:
> -			/* FIXME turn light off */
> -			hotplug_slot->info->attention_status = 0;
> -			break;
> -
> -		case 1:
> -		default:
> -			/* FIXME turn light on */
> -			hotplug_slot->info->attention_status = 1;
> -			break;
> +	spin_lock_irqsave(&attn_info_lock, flags);
> +	memcpy(&info, &attention_info, sizeof(struct acpiphp_attention_info));
> +	spin_unlock_irqrestore(&attn_info_lock, flags);

Again, why lock?  And why copy the whole structure?  And it's on the
stack, which isn't very nice.  Same comment applies to the get_
function.

> +
> +	if (info.set_attn && try_module_get(info.owner)) {
> +		retval = info.set_attn(hotplug_slot, status);
> +		module_put(info.owner);
>  	}
>  
> -	return 0;
> +	if (!retval)
> +		hotplug_slot->info->attention_status = (status) ? 1 : 0;

Why change the value based on the return value of the call?  This
shouldn't be set at all.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] acpiphp extension for 2.6.7
  2004-06-24 21:45 ` Greg KH
@ 2004-06-25 16:42   ` Vernon Mauery
  2004-06-29 18:47   ` Vernon Mauery
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 19+ messages in thread
From: Vernon Mauery @ 2004-06-25 16:42 UTC (permalink / raw)
  To: Greg KH; +Cc: lkml, Pat Gaughen, Chris McDermott, Jess Botts

On Thu, 2004-06-24 at 14:45, Greg KH wrote: 
> > +int acpiphp_register_attention_info(struct acpiphp_attention_info *info)
> > +{
> > +	int retval = 0;
> > +	unsigned long flags;
> > +
> > +	if (!info || !info->owner || !info->set_attn || !info->get_attn)
> > +		retval = -1;
> > +	else {
> > +		spin_lock_irqsave(&attn_info_lock, flags);
> 
> Why lock here?  What could race?

If this function is only ever called from a module's init_module
function, then our global data is protected by the kernel's
module_mutex.  But is the assumption that it is never called from other
code safe to make?  It manipulates global data, so it needs to be
protected somehow...

> And why the irqsave lock?
Not sure.  That can be changed.

> > -static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
> > +static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
> >  {
> > +	int retval = -1;
> > +	unsigned long flags;
> > +	struct acpiphp_attention_info info;
> > +
> >  	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
> >  
> > -	switch (status) {
> > -		case 0:
> > -			/* FIXME turn light off */
> > -			hotplug_slot->info->attention_status = 0;
> > -			break;
> > -
> > -		case 1:
> > -		default:
> > -			/* FIXME turn light on */
> > -			hotplug_slot->info->attention_status = 1;
> > -			break;
> > +	spin_lock_irqsave(&attn_info_lock, flags);
> > +	memcpy(&info, &attention_info, sizeof(struct acpiphp_attention_info));
> > +	spin_unlock_irqrestore(&attn_info_lock, flags);
> 
> Again, why lock?  And why copy the whole structure?  And it's on the
> stack, which isn't very nice.  Same comment applies to the get_
> function.

Getting a local copy of the data structure within the lock ensures that
this function is reentrant.  But if we can make the same guarantee that
this funtion is called only on module_exit (again protected by the
module_mutex) then we can move to a pointer and no local lock.

> > +
> > +	if (info.set_attn && try_module_get(info.owner)) {
> > +		retval = info.set_attn(hotplug_slot, status);
> > +		module_put(info.owner);
> >  	}
> >  
> > -	return 0;
> > +	if (!retval)
> > +		hotplug_slot->info->attention_status = (status) ? 1 : 0;
> 
> Why change the value based on the return value of the call?  This
> shouldn't be set at all.

Oops.  This was a snippet of legacy code that was around before I
figured out how to read the LED value from hardware.  I will drop it.

--Vernon



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] acpiphp extension for 2.6.7
  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
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 19+ messages in thread
From: Vernon Mauery @ 2004-06-29 18:47 UTC (permalink / raw)
  To: Greg KH; +Cc: lkml, Pat Gaughen, Chris McDermott, Jess Botts,
	linux-hotplug-devel

On Thu, 2004-06-24 at 14:45, Greg KH wrote: 
> The LED stuff looks good (few minor comments below), but the ACPI table
> info should be moved to the ACPI core to provide this to all ACPI tables
> in the /sys/firmware/acpi tree.

I took it out of this patch, but it might be a while until I can figure
out how to correctly modify the ACPI core to do that...

But the rest of your changes I implemented and have included in this
patch.

--Vernon



diff -X ignore_files -Nur linux-2.6.7.orig/drivers/pci/hotplug/Kconfig linux-2.6.7-apci/drivers/pci/hotplug/Kconfig
--- linux-2.6.7.orig/drivers/pci/hotplug/Kconfig	2004-06-15 22:19:17.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/Kconfig	2004-06-22 11:49:38.000000000 -0700
@@ -88,6 +88,18 @@
 
 	  When in doubt, say N.
 
+config HOTPLUG_PCI_ACPI_IBM
+	tristate "ACPI PCI Hotplug driver IBM extensions"
+	depends on HOTPLUG_PCI_ACPI
+	help
+	  Say Y here if you have an IBM system that supports PCI Hotplug using
+	  ACPI.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called acpiphp_ibm.
+
+	  When in doubt, say N.
+
 config HOTPLUG_PCI_CPCI
 	bool "CompactPCI Hotplug driver"
 	depends on HOTPLUG_PCI
diff -X ignore_files -Nur linux-2.6.7.orig/drivers/pci/hotplug/Makefile linux-2.6.7-apci/drivers/pci/hotplug/Makefile
--- linux-2.6.7.orig/drivers/pci/hotplug/Makefile	2004-06-15 22:19:43.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/Makefile	2004-06-22 11:49:38.000000000 -0700
@@ -7,6 +7,7 @@
 obj-$(CONFIG_HOTPLUG_PCI_COMPAQ)	+= cpqphp.o
 obj-$(CONFIG_HOTPLUG_PCI_IBM)		+= ibmphp.o
 obj-$(CONFIG_HOTPLUG_PCI_ACPI)		+= acpiphp.o
+obj-$(CONFIG_HOTPLUG_PCI_ACPI_IBM)	+= acpiphp_ibm.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_ZT5550)	+= cpcihp_zt5550.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_GENERIC)	+= cpcihp_generic.o
 obj-$(CONFIG_HOTPLUG_PCI_PCIE)		+= pciehp.o
diff -X ignore_files -Nur linux-2.6.7.orig/drivers/pci/hotplug/acpiphp.h linux-2.6.7-apci/drivers/pci/hotplug/acpiphp.h
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp.h	2004-06-15 22:20:26.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp.h	2004-06-22 11:49:38.000000000 -0700
@@ -172,6 +172,22 @@
 };
 
 
+/**
+ * struct acpiphp_attention_info - device specific attention registration
+ *
+ * ACPI has no generic method of setting/getting attention status
+ * this allows for device specific driver registration
+ */
+typedef int (*acpiphp_set_attn_callback)(struct hotplug_slot *slot, u8 status);
+typedef int (*acpiphp_get_attn_callback)(struct hotplug_slot *slot, u8 *status);
+struct acpiphp_attention_info
+{
+	acpiphp_set_attn_callback set_attn;
+	acpiphp_get_attn_callback get_attn;
+	struct module *owner;
+};
+
+
 /* PCI bus bridge HID */
 #define ACPI_PCI_HOST_HID		"PNP0A03"
 
@@ -212,6 +228,12 @@
 
 /* function prototypes */
 
+/* acpiphp_core.c */
+extern int acpiphp_register_attention_info(
+		struct acpiphp_attention_info*info);
+extern int acpiphp_unregister_attention_info(
+		struct acpiphp_attention_info *info);
+
 /* acpiphp_glue.c */
 extern int acpiphp_glue_init (void);
 extern void acpiphp_glue_exit (void);
diff -X ignore_files -Nur linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_core.c linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_core.c
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_core.c	2004-06-15 22:19:37.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_core.c	2004-06-29 11:12:41.754945480 -0700
@@ -51,6 +51,7 @@
 
 /* local variables */
 static int num_slots;
+static struct acpiphp_attention_info *attention_info = NULL;
 
 #define DRIVER_VERSION	"0.4"
 #define DRIVER_AUTHOR	"Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>"
@@ -62,10 +63,15 @@
 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
 module_param(debug, bool, 644);
 
+/* export the attention callback registration methods */
+EXPORT_SYMBOL_GPL(acpiphp_register_attention_info);
+EXPORT_SYMBOL_GPL(acpiphp_unregister_attention_info);
+
 static int enable_slot		(struct hotplug_slot *slot);
 static int disable_slot		(struct hotplug_slot *slot);
 static int set_attention_status (struct hotplug_slot *slot, u8 value);
 static int get_power_status	(struct hotplug_slot *slot, u8 *value);
+static int get_attention_status (struct hotplug_slot *slot, u8 *value);
 static int get_address		(struct hotplug_slot *slot, u32 *value);
 static int get_latch_status	(struct hotplug_slot *slot, u8 *value);
 static int get_adapter_status	(struct hotplug_slot *slot, u8 *value);
@@ -76,11 +82,54 @@
 	.disable_slot		= disable_slot,
 	.set_attention_status	= set_attention_status,
 	.get_power_status	= get_power_status,
+	.get_attention_status	= get_attention_status,
 	.get_latch_status	= get_latch_status,
 	.get_adapter_status	= get_adapter_status,
 	.get_address		= get_address,
 };
 
+
+/**
+    * acpiphp_register_attention_info - set attention LED callback
+    *
+    * this is used to register a hardware specific acpi driver
+    * that manipulates the attention LED.  All the fields in
+    * info must be set.
+    *
+    */
+int acpiphp_register_attention_info(struct acpiphp_attention_info *info)
+{
+	int retval = -1;
+
+	if (info && info->owner && info->set_attn &&
+			info->get_attn && !attention_info) {
+		retval = 0;
+		attention_info = info;
+	}
+	return retval;
+}
+
+
+/**
+ * acpiphp_unregister_attention_info - unset attention LED callback
+ *
+ * this is used to un-register a hardware specific acpi driver
+ * that manipulates the attention LED.  The pointer to the 
+ * info struct must be the same as the one used to set it.
+ *
+ */
+int acpiphp_unregister_attention_info(struct acpiphp_attention_info *info)
+{
+	int retval = -1;
+
+	if (info && attention_info == info) {
+		attention_info = NULL;
+		retval = 0;
+	}
+	return retval;
+}
+
+
 /**
  * enable_slot - power on and enable a slot
  * @hotplug_slot: slot to enable
@@ -120,29 +169,24 @@
 /**
  * set_attention_status - set attention LED
  *
- * TBD:
  * ACPI doesn't have known method to manipulate
- * attention status LED.
+ * attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to blink the light for us.
  *
  */
 static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
 {
+	int retval = -1;
+
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
-	switch (status) {
-		case 0:
-			/* FIXME turn light off */
-			hotplug_slot->info->attention_status = 0;
-			break;
-
-		case 1:
-		default:
-			/* FIXME turn light on */
-			hotplug_slot->info->attention_status = 1;
-			break;
+	if (attention_info && attention_info->set_attn &&
+			try_module_get(attention_info->owner)) {
+		retval = attention_info->set_attn(hotplug_slot, status);
+		module_put(attention_info->owner);
 	}
-
-	return 0;
+	return retval;
 }
 
 /**
@@ -166,6 +210,30 @@
 }
 
 /**
+ * get_attention_status - get attention LED status
+ *
+ * ACPI doesn't have known method to determine the state
+ * of the attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to determine its state
+ *
+ */
+static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
+{
+	int retval = -1;
+
+	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
+
+	if (attention_info && attention_info->get_attn &&
+			try_module_get(attention_info->owner)) {
+		retval = attention_info->get_attn(hotplug_slot, value);
+		module_put(attention_info->owner);
+	}
+	return retval;
+}
+
+
+/**
  * get_latch_status - get latch status of a slot
  * @hotplug_slot: slot to get status
  * @value: pointer to store status
@@ -307,7 +375,7 @@
 
 		slot->acpi_slot = get_slot_from_id(i);
 		slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
-		slot->hotplug_slot->info->attention_status = acpiphp_get_attention_status(slot->acpi_slot);
+		slot->hotplug_slot->info->attention_status = 0;
 		slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
 		slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
 		slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
diff -X ignore_files -Nur linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_glue.c
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_glue.c	2004-06-15 22:19:10.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_glue.c	2004-06-22 11:49:38.000000000 -0700
@@ -1302,20 +1302,6 @@
 
 
 /*
- * attention LED ON: 1
- *		OFF: 0
- *
- * TBD
- * no direct attention led status information via ACPI
- *
- */
-u8 acpiphp_get_attention_status(struct acpiphp_slot *slot)
-{
-	return 0;
-}
-
-
-/*
  * latch closed:  1
  * latch   open:  0
  */
diff -X ignore_files -Nur linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_ibm.c linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_ibm.c
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_ibm.c	1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_ibm.c	2004-06-29 11:35:37.843748184 -0700
@@ -0,0 +1,426 @@
+/*
+ * ACPI PCI Hot Plug IBM Extension
+ *
+ * Copyright (C) 2004 Vernon Mauery <vernux@us.ibm.com>
+ * Copyright (C) 2004 IBM Corp.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Send feedback to <vernux@us.ibm.com>
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <acpi/acpi_bus.h>
+#include <asm/uaccess.h>
+
+#include "acpiphp.h"
+#include "pci_hotplug.h"
+
+#define DRIVER_VERSION	"1.0.1"
+#define DRIVER_AUTHOR	"Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
+#define DRIVER_DESC	"ACPI Hot Plug PCI Controller Driver IBM extension"
+
+static int debug;
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_PARM(debug, "i");
+MODULE_PARM_DESC(debug, " Debugging mode enabled or not");
+#define MY_NAME "acpiphp_ibm"
+
+#ifdef dbg
+#undef dbg
+#endif
+#define dbg(format, arg...)				\
+do {							\
+	if (debug)					\
+		printk(KERN_DEBUG "%s: " format,	\
+				MY_NAME , ## arg);	\
+} while (0)
+
+#define FOUND_APCI 0x61504349
+/* these are the names for the IBM ACPI pseudo-device */
+#define IBM_HARDWARE_ID1 "IBM37D0"
+#define IBM_HARDWARE_ID2 "IBM37D4"
+
+/* union apci_descriptor - allows access to the
+ * various device descriptors that are embedded in the
+ * aPCI table
+ */
+union apci_descriptor {
+	struct {
+		char sig[4];
+		u8   len;
+	} header;
+	struct {
+		u8  type;
+		u8  len;
+		u16 slot_id;
+		u8  bus_id;
+		u8  dev_num;
+		u8  slot_num;
+		u8  slot_attr[2];
+		u8  attn;
+		u8  status[2];
+		u8  sun;
+	} slot;
+	struct {
+		u8 type;
+		u8 len;
+	} generic;
+};
+
+/* struct notification - keeps info about the device
+ * that cause the ACPI notification event
+ */
+struct notification {
+	struct acpi_device *device;
+	u8                  event;
+};
+
+/* forward declarations of functions for this module
+ */
+static int ibm_set_attention_status (struct hotplug_slot *slot, u8 status);
+static int ibm_get_attention_status (struct hotplug_slot *slot, u8 *status);
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context);
+static int ibm_get_table_from_acpi(char **bufp);
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv);
+static int __init ibm_acpiphp_init(void);
+static void __exit ibm_acpiphp_exit(void);
+
+/* static global variables
+ */
+static acpi_handle ibm_acpi_handle = NULL;
+static struct notification ibm_note;
+static struct acpiphp_attention_info ibm_attention_info = 
+{
+	.set_attn = ibm_set_attention_status,
+	.get_attn = ibm_get_attention_status,
+	.owner = THIS_MODULE,
+};
+
+
+/*
+ * ibm_set_attention_status - callback method to set the attention LED
+ *
+ * this method is registered with the acpiphp module as a callback
+ * to do the device specific task of setting the LED status
+ *
+ */
+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;
+
+	if (!slot || !slot->private)
+		return -1;
+	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+	if (!acpi_slot)
+		return -1;
+
+	dbg("%s: set slot %d attention status to %d\n", __FUNCTION__,
+			acpi_slot->sun, (status ? 1 : 0));
+
+	args[0].type = ACPI_TYPE_INTEGER;
+	args[0].integer.value = acpi_slot->sun;
+	args[1].type = ACPI_TYPE_INTEGER;
+	args[1].integer.value = (status) ? 1 : 0;
+
+	stat = acpi_evaluate_integer(ibm_acpi_handle, "APLS", &params, &rc);
+	if (ACPI_FAILURE(stat)) {
+		retval = -1;
+		err("APLS evaluation failed:  0x%08x\n", stat);
+	} else if (!rc) {
+		retval = -1;
+		err("APLS method failed:  0x%08lx\n", rc);
+	}
+	return retval;
+}
+
+/*
+ * ibm_get_attention_status - callback method to get attention LED status
+ *
+ * this method is registered with the acpiphp module as a callback
+ * to do the device specific task of getting the LED status
+ * 
+ * Because there is no direct method of getting the LED status directly
+ * from an ACPI call, we read the aPCI table and parse out our
+ * slot descriptor to read the status from that.
+ *
+ */
+static int ibm_get_attention_status (struct hotplug_slot *slot, u8 *status)
+{
+	int retval = -1, ind = 0, size;
+	char *table = NULL;
+	struct acpiphp_slot *acpi_slot;
+	union apci_descriptor *des;
+
+	if (!slot || !slot->private)
+		goto get_attn_done;
+	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+	if (!acpi_slot)
+		goto get_attn_done;
+
+	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;
+	}
+
+	dbg("%s: get slot %d attention status is %d retval=%x\n",
+			__FUNCTION__, acpi_slot->sun, *status, retval);
+
+get_attn_done:
+	if (table)
+		kfree(table);
+	return retval;
+}
+
+/*
+ * ibm_handle_events - listens for ACPI events for the IBM37D0 device
+ *
+ * this method is registered as a callback with the ACPI subsystem
+ * it is called when this device has an event to notify the OS of
+ *
+ * the events actually come from the device as two events that get
+ * synthesized into one event with data by this function.  The event
+ * ID comes first and then the slot number that caused it.  We report
+ * this as one event to the OS.
+ *
+ */
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context)
+{
+	// FIXME: this may have re-entrancy errors with event being static...
+	u8 detail = event & 0x0f;
+	u8 subevent = event & 0xf0;
+
+	struct notification *note = (struct notification *)context;
+
+	dbg("%s: Received notification %02x\n", __FUNCTION__, event);
+
+	if (subevent == 0x80) {
+		dbg("%s: generationg bus event\n", __FUNCTION__);
+		acpi_bus_generate_event(note->device, note->event, detail);
+	} else
+		note->event = event;
+}
+
+/*
+ * ibm_get_table_from_acpi - reads the APLS buffer from ACPI
+ * 
+ * this method reads the APLS buffer in from ACPI and
+ * stores the "stripped" table into a single buffer
+ * it allocates and passes the address back in bufp
+ *
+ * if NULL is passed in as buffer, this method only calculates
+ * the size of the table and returns that without filling
+ * in the buffer
+ *
+ * returns < 0 on error or the size of the table on success
+ */
+static int ibm_get_table_from_acpi(char **bufp)
+{
+	union acpi_object *package;
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	acpi_status status;
+	char *lbuf = NULL;
+	int i, size = -1;
+
+	status = acpi_evaluate_object(ibm_acpi_handle, "APCI", NULL, &buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  APCI evaluation failed\n", __FUNCTION__);
+		return -ENODEV;
+	}
+
+	package = (union acpi_object *) buffer.pointer;
+	if(!(package) ||
+			(package->type != ACPI_TYPE_PACKAGE) ||
+			!(package->package.elements)) {
+		err("%s:  Invalid APCI object\n", __FUNCTION__);
+		goto read_table_done;
+	}
+
+	for(size = 0, i = 0; i < package->package.count; i++) {
+		if (package->package.elements[i].type != ACPI_TYPE_BUFFER) {
+			err("%s:  Invalid APCI element %d\n", __FUNCTION__, i);
+			goto read_table_done;
+		}
+		size += package->package.elements[i].buffer.length;
+	}
+
+	if (bufp == NULL)
+		goto read_table_done;
+
+	lbuf = kmalloc(size, GFP_KERNEL);
+	dbg("%s: element count: %i, ASL table size: %i, &table = 0x%x\n",
+			__FUNCTION__, package->package.count, size, (int)lbuf);
+
+	if (lbuf) {
+		*bufp = lbuf;
+		memset(lbuf, 0, size);
+	} else {
+		size = -ENOMEM;
+		goto read_table_done;
+	}
+
+	size = 0;
+	for (i=0; i<package->package.count; i++) {
+		memcpy(&lbuf[size],
+				package->package.elements[i].buffer.pointer,
+				package->package.elements[i].buffer.length);
+		size += package->package.elements[i].buffer.length;
+	}
+
+read_table_done:
+	kfree(buffer.pointer);
+	return size;
+}
+
+
+/* ibm_find_acpi_device - callback to find our ACPI device
+ *
+ * used as a callback when calling acpi_walk_namespace
+ * to find our device.  When this method returns non-zero
+ * acpi_walk_namespace quits its search and returns our value
+ */
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv)
+{
+	acpi_handle *phandle = (acpi_handle *)context;
+	acpi_status status; 
+	struct acpi_device_info info; 
+	struct acpi_buffer info_buffer = {
+		.length = sizeof(struct acpi_device_info),
+		.pointer = &info,
+	};
+
+	status = acpi_get_object_info(handle, &info_buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  Failed to get device information", __FUNCTION__);
+		return 0;
+	}
+	info.hardware_id.value[sizeof(info.hardware_id.value) - 1] = '\0';
+
+	if(info.current_status && (info.valid & ACPI_VALID_HID) &&
+			(!strcmp(info.hardware_id.value, IBM_HARDWARE_ID1) ||
+			!strcmp(info.hardware_id.value, IBM_HARDWARE_ID2))) {
+		dbg("found hardware: %s, handle: %x\n", info.hardware_id.value,
+				(unsigned int)handle);
+		*phandle = handle;
+		/* returning non-zero causes the search to stop
+		 * and returns this value to the caller of 
+		 * acpi_walk_namespace, but it also causes some warnings
+		 * in the acpi debug code to print...
+		 */
+		return FOUND_APCI;
+	}
+	return 0;
+}
+
+static int __init ibm_acpiphp_init(void)
+{
+	int retval = 0;
+	acpi_status status;
+	struct acpi_device *device;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+			ACPI_UINT32_MAX, ibm_find_acpi_device,
+			&ibm_acpi_handle, NULL) != FOUND_APCI) {
+		err("%s: acpi_walk_namespace failed\n", __FUNCTION__);
+		retval = -ENODEV;
+		goto init_return;
+	}
+	dbg("%s: found IBM aPCI device\n", __FUNCTION__);
+	if (acpi_bus_get_device(ibm_acpi_handle, &device)) {
+		err("%s: acpi_bus_get_device failed\n", __FUNCTION__);
+		retval = -ENODEV;
+		goto init_return;
+	}
+	if (acpiphp_register_attention_info(&ibm_attention_info))
+		retval = -ENODEV;
+		goto init_return;
+
+	ibm_note.device = device;
+	status = acpi_install_notify_handler(
+			ibm_acpi_handle,
+			ACPI_DEVICE_NOTIFY,
+			ibm_handle_events,
+			(void *)&ibm_note);
+	if (ACPI_FAILURE(status))
+	{
+		err("%s:  Failed to register notification handler\n",
+				__FUNCTION__);
+		retval = -EBUSY;
+		goto init_cleanup;
+	}
+
+	return retval;
+
+init_cleanup:
+	acpiphp_unregister_attention_info(&ibm_attention_info);
+init_return:
+	return retval;
+}
+
+static void __exit ibm_acpiphp_exit(void)
+{
+	acpi_status status;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpiphp_unregister_attention_info(&ibm_attention_info))
+		err("%s: attention info deregistration failed", __FUNCTION__);
+
+	   status = acpi_remove_notify_handler(
+			   ibm_acpi_handle,
+			   ACPI_DEVICE_NOTIFY,
+			   ibm_handle_events);
+	   if (ACPI_FAILURE(status))
+		   err("%s:  Notification handler removal failed\n",
+				   __FUNCTION__);
+}
+
+module_init(ibm_acpiphp_init);
+module_exit(ibm_acpiphp_exit);
+
+



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] [0/2] acpiphp extension for 2.6.7
  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   ` Vernon Mauery
  2004-07-02 20:58     ` [Pcihpd-discuss] " Greg KH
  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
  4 siblings, 1 reply; 19+ messages in thread
From: Vernon Mauery @ 2004-06-29 23:50 UTC (permalink / raw)
  To: Greg KH; +Cc: lkml, Pat Gaughen, Chris McDermott, Jess Botts, pcihpd-discuss

After much discussion, dissection, rewriting and reading (documentation
of course), I finally think this patch is ready to be included in the
kernel.  I have chosen to split it into 2 parts because really, that's
what it is -- a patch to acpiphp that allows other modules to register
attention LED callback functions and also a new module that does just
that for the IBM ACPI systems.  These patches were made against the
2.6.7 kernel tree.

01 - acpiphp-attention.patch

        This patch adds the ability to register callback functions with
        the acpiphp core to set and get the current attention LED
        status.  The reason this is needed is because there is not set
        ACPI standard for how this is done so each hardware platform may
        implement it differently.  To keep hardware specific code out of
        acpiphp, we allow other modules to register their code with it.


02 - acpiphp_ibm-v1.0.1c.patch

        This patch adds the first driver that actually uses the callback
        function for attention LEDs that the acpiphp-attention patch
        adds.  It searches the ACPI namespace for IBM hardware, sets up
        the callbacks and sets up a handler to read ACPI events and
        forward them on to /proc/acpi/event.  It also exports an ACPI
        table that shows current hotplug status to userland.


The two patches are to follow.

--Vernon



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] [1/2] acpiphp extension for 2.6.7
  2004-06-24 21:45 ` Greg KH
                     ` (2 preceding siblings ...)
  2004-06-29 23:50   ` [PATCH] [0/2] " Vernon Mauery
@ 2004-06-29 23:50   ` Vernon Mauery
  2004-06-29 23:50   ` [PATCH] [2/2] " Vernon Mauery
  4 siblings, 0 replies; 19+ messages in thread
From: Vernon Mauery @ 2004-06-29 23:50 UTC (permalink / raw)
  To: Greg KH; +Cc: lkml, Pat Gaughen, Chris McDermott, Jess Botts, pcihpd-discuss

01 - acpiphp-attention.patch

        This patch adds the ability to register callback functions with
        the acpiphp core to set and get the current attention LED
        status.  The reason this is needed is because there is not set
        ACPI standard for how this is done so each hardware platform may
        implement it differently.  To keep hardware specific code out of
        acpiphp, we allow other modules to register their code with it.


 acpiphp.h      |   22 ++++++++++++
 acpiphp_core.c |  100 +++++++++++++++++++++++++++++++++++++++++++++++----------
 acpiphp_glue.c |   14 -------
 3 files changed, 106 insertions(+), 30 deletions(-)


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


=====================================================================


diff -ruN -X dontdiff linux-2.6.7.orig/drivers/pci/hotplug/acpiphp.h linux-2.6.7-apci/drivers/pci/hotplug/acpiphp.h
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp.h	2004-06-15 22:20:26.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp.h	2004-06-22 11:49:38.000000000 -0700
@@ -172,6 +172,22 @@
 };
 
 
+/**
+ * struct acpiphp_attention_info - device specific attention registration
+ *
+ * ACPI has no generic method of setting/getting attention status
+ * this allows for device specific driver registration
+ */
+typedef int (*acpiphp_set_attn_callback)(struct hotplug_slot *slot, u8 status);
+typedef int (*acpiphp_get_attn_callback)(struct hotplug_slot *slot, u8 *status);
+struct acpiphp_attention_info
+{
+	acpiphp_set_attn_callback set_attn;
+	acpiphp_get_attn_callback get_attn;
+	struct module *owner;
+};
+
+
 /* PCI bus bridge HID */
 #define ACPI_PCI_HOST_HID		"PNP0A03"
 
@@ -212,6 +228,12 @@
 
 /* function prototypes */
 
+/* acpiphp_core.c */
+extern int acpiphp_register_attention_info(
+		struct acpiphp_attention_info*info);
+extern int acpiphp_unregister_attention_info(
+		struct acpiphp_attention_info *info);
+
 /* acpiphp_glue.c */
 extern int acpiphp_glue_init (void);
 extern void acpiphp_glue_exit (void);
diff -ruN -X dontdiff linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_core.c linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_core.c
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_core.c	2004-06-15 22:19:37.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_core.c	2004-06-29 11:12:41.754945480 -0700
@@ -51,6 +51,7 @@
 
 /* local variables */
 static int num_slots;
+static struct acpiphp_attention_info *attention_info = NULL;
 
 #define DRIVER_VERSION	"0.4"
 #define DRIVER_AUTHOR	"Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>"
@@ -62,10 +63,15 @@
 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
 module_param(debug, bool, 644);
 
+/* export the attention callback registration methods */
+EXPORT_SYMBOL_GPL(acpiphp_register_attention_info);
+EXPORT_SYMBOL_GPL(acpiphp_unregister_attention_info);
+
 static int enable_slot		(struct hotplug_slot *slot);
 static int disable_slot		(struct hotplug_slot *slot);
 static int set_attention_status (struct hotplug_slot *slot, u8 value);
 static int get_power_status	(struct hotplug_slot *slot, u8 *value);
+static int get_attention_status (struct hotplug_slot *slot, u8 *value);
 static int get_address		(struct hotplug_slot *slot, u32 *value);
 static int get_latch_status	(struct hotplug_slot *slot, u8 *value);
 static int get_adapter_status	(struct hotplug_slot *slot, u8 *value);
@@ -76,11 +82,54 @@
 	.disable_slot		= disable_slot,
 	.set_attention_status	= set_attention_status,
 	.get_power_status	= get_power_status,
+	.get_attention_status	= get_attention_status,
 	.get_latch_status	= get_latch_status,
 	.get_adapter_status	= get_adapter_status,
 	.get_address		= get_address,
 };
 
+
+/**
+    * acpiphp_register_attention_info - set attention LED callback
+    *
+    * this is used to register a hardware specific acpi driver
+    * that manipulates the attention LED.  All the fields in
+    * info must be set.
+    *
+    */
+int acpiphp_register_attention_info(struct acpiphp_attention_info *info)
+{
+	int retval = -1;
+
+	if (info && info->owner && info->set_attn &&
+			info->get_attn && !attention_info) {
+		retval = 0;
+		attention_info = info;
+	}
+	return retval;
+}
+
+
+/**
+ * acpiphp_unregister_attention_info - unset attention LED callback
+ *
+ * this is used to un-register a hardware specific acpi driver
+ * that manipulates the attention LED.  The pointer to the 
+ * info struct must be the same as the one used to set it.
+ *
+ */
+int acpiphp_unregister_attention_info(struct acpiphp_attention_info *info)
+{
+	int retval = -1;
+
+	if (info && attention_info == info) {
+		attention_info = NULL;
+		retval = 0;
+	}
+	return retval;
+}
+
+
 /**
  * enable_slot - power on and enable a slot
  * @hotplug_slot: slot to enable
@@ -120,29 +169,24 @@
 /**
  * set_attention_status - set attention LED
  *
- * TBD:
  * ACPI doesn't have known method to manipulate
- * attention status LED.
+ * attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to blink the light for us.
  *
  */
 static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
 {
+	int retval = -1;
+
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
-	switch (status) {
-		case 0:
-			/* FIXME turn light off */
-			hotplug_slot->info->attention_status = 0;
-			break;
-
-		case 1:
-		default:
-			/* FIXME turn light on */
-			hotplug_slot->info->attention_status = 1;
-			break;
+	if (attention_info && attention_info->set_attn &&
+			try_module_get(attention_info->owner)) {
+		retval = attention_info->set_attn(hotplug_slot, status);
+		module_put(attention_info->owner);
 	}
-
-	return 0;
+	return retval;
 }
 
 /**
@@ -166,6 +210,30 @@
 }
 
 /**
+ * get_attention_status - get attention LED status
+ *
+ * ACPI doesn't have known method to determine the state
+ * of the attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to determine its state
+ *
+ */
+static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
+{
+	int retval = -1;
+
+	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
+
+	if (attention_info && attention_info->get_attn &&
+			try_module_get(attention_info->owner)) {
+		retval = attention_info->get_attn(hotplug_slot, value);
+		module_put(attention_info->owner);
+	}
+	return retval;
+}
+
+
+/**
  * get_latch_status - get latch status of a slot
  * @hotplug_slot: slot to get status
  * @value: pointer to store status
@@ -307,7 +375,7 @@
 
 		slot->acpi_slot = get_slot_from_id(i);
 		slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
-		slot->hotplug_slot->info->attention_status = acpiphp_get_attention_status(slot->acpi_slot);
+		slot->hotplug_slot->info->attention_status = 0;
 		slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
 		slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
 		slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
diff -ruN -X dontdiff linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_glue.c linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_glue.c
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_glue.c	2004-06-15 22:19:10.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_glue.c	2004-06-22 11:49:38.000000000 -0700
@@ -1302,20 +1302,6 @@
 
 
 /*
- * attention LED ON: 1
- *		OFF: 0
- *
- * TBD
- * no direct attention led status information via ACPI
- *
- */
-u8 acpiphp_get_attention_status(struct acpiphp_slot *slot)
-{
-	return 0;
-}
-
-
-/*
  * latch closed:  1
  * latch   open:  0
  */




^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] [2/2] acpiphp extension for 2.6.7
  2004-06-24 21:45 ` Greg KH
                     ` (3 preceding siblings ...)
  2004-06-29 23:50   ` [PATCH] [1/2] acpiphp extension for 2.6.7 Vernon Mauery
@ 2004-06-29 23:50   ` Vernon Mauery
  4 siblings, 0 replies; 19+ messages in thread
From: Vernon Mauery @ 2004-06-29 23:50 UTC (permalink / raw)
  To: Greg KH; +Cc: lkml, Pat Gaughen, Chris McDermott, Jess Botts, pcihpd-discuss

02 - acpiphp_ibm-v1.0.1c.patch

        This patch adds the first driver that actually uses the callback
        function for attention LEDs that the acpiphp-attention patch
        adds.  It searches the ACPI namespace for IBM hardware, sets up
        the callbacks and sets up a handler to read ACPI events and
        forward them on to /proc/acpi/event.  It also exports an ACPI
        table that shows current hotplug status to userland.


 Kconfig       |   12 +
 Makefile      |    1
 acpiphp_ibm.c |  476 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 489 insertions(+)


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


=====================================================================


diff -ruN -X dontdiff linux-2.6.7.orig/drivers/pci/hotplug/Kconfig linux-2.6.7-apci/drivers/pci/hotplug/Kconfig
--- linux-2.6.7.orig/drivers/pci/hotplug/Kconfig	2004-06-15 22:19:17.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/Kconfig	2004-06-22 11:49:38.000000000 -0700
@@ -88,6 +88,18 @@
 
 	  When in doubt, say N.
 
+config HOTPLUG_PCI_ACPI_IBM
+	tristate "ACPI PCI Hotplug driver IBM extensions"
+	depends on HOTPLUG_PCI_ACPI
+	help
+	  Say Y here if you have an IBM system that supports PCI Hotplug using
+	  ACPI.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called acpiphp_ibm.
+
+	  When in doubt, say N.
+
 config HOTPLUG_PCI_CPCI
 	bool "CompactPCI Hotplug driver"
 	depends on HOTPLUG_PCI
diff -ruN -X dontdiff linux-2.6.7.orig/drivers/pci/hotplug/Makefile linux-2.6.7-apci/drivers/pci/hotplug/Makefile
--- linux-2.6.7.orig/drivers/pci/hotplug/Makefile	2004-06-15 22:19:43.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/Makefile	2004-06-22 11:49:38.000000000 -0700
@@ -7,6 +7,7 @@
 obj-$(CONFIG_HOTPLUG_PCI_COMPAQ)	+= cpqphp.o
 obj-$(CONFIG_HOTPLUG_PCI_IBM)		+= ibmphp.o
 obj-$(CONFIG_HOTPLUG_PCI_ACPI)		+= acpiphp.o
+obj-$(CONFIG_HOTPLUG_PCI_ACPI_IBM)	+= acpiphp_ibm.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_ZT5550)	+= cpcihp_zt5550.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_GENERIC)	+= cpcihp_generic.o
 obj-$(CONFIG_HOTPLUG_PCI_PCIE)		+= pciehp.o
diff -ruN -X dontdiff linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_ibm.c linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_ibm.c
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_ibm.c	1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_ibm.c	2004-06-29 16:06:59.877502816 -0700
@@ -0,0 +1,476 @@
+/*
+ * ACPI PCI Hot Plug IBM Extension
+ *
+ * Copyright (C) 2004 Vernon Mauery <vernux@us.ibm.com>
+ * Copyright (C) 2004 IBM Corp.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Send feedback to <vernux@us.ibm.com>
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <acpi/acpi_bus.h>
+#include <linux/sysfs.h>
+#include <linux/kobject.h>
+#include <asm/uaccess.h>
+//#include <linux/moduleparam.h>
+
+#include "acpiphp.h"
+#include "pci_hotplug.h"
+
+#define DRIVER_VERSION	"1.0.1"
+#define DRIVER_AUTHOR	"Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
+#define DRIVER_DESC	"ACPI Hot Plug PCI Controller Driver IBM extension"
+
+static int debug;
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRIVER_VERSION);
+MODULE_PARM(debug, "i");
+MODULE_PARM_DESC(debug, " Debugging mode enabled or not");
+#define MY_NAME "acpiphp_ibm"
+
+#ifdef dbg
+#undef dbg
+#endif
+#define dbg(format, arg...)				\
+do {							\
+	if (debug)					\
+		printk(KERN_DEBUG "%s: " format,	\
+				MY_NAME , ## arg);	\
+} while (0)
+
+#define FOUND_APCI 0x61504349
+/* these are the names for the IBM ACPI pseudo-device */
+#define IBM_HARDWARE_ID1 "IBM37D0"
+#define IBM_HARDWARE_ID2 "IBM37D4"
+
+/* union apci_descriptor - allows access to the
+ * various device descriptors that are embedded in the
+ * aPCI table
+ */
+union apci_descriptor {
+	struct {
+		char sig[4];
+		u8   len;
+	} header;
+	struct {
+		u8  type;
+		u8  len;
+		u16 slot_id;
+		u8  bus_id;
+		u8  dev_num;
+		u8  slot_num;
+		u8  slot_attr[2];
+		u8  attn;
+		u8  status[2];
+		u8  sun;
+	} slot;
+	struct {
+		u8 type;
+		u8 len;
+	} generic;
+};
+
+/* struct notification - keeps info about the device
+ * that cause the ACPI notification event
+ */
+struct notification {
+	struct acpi_device *device;
+	u8                  event;
+};
+
+/* forward declarations of functions for this module
+ */
+static int ibm_set_attention_status (struct hotplug_slot *slot, u8 status);
+static int ibm_get_attention_status (struct hotplug_slot *slot, u8 *status);
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context);
+static int ibm_get_table_from_acpi(char **bufp);
+static ssize_t ibm_read_apci_table(struct kobject *kobj,
+		char *buffer, loff_t pos, size_t size);
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv);
+static int __init ibm_acpiphp_init(void);
+static void __exit ibm_acpiphp_exit(void);
+
+/* static global variables
+ */
+static acpi_handle ibm_acpi_handle = NULL;
+static struct notification ibm_note;
+static struct bin_attribute ibm_apci_table_attr = {
+	    .attr = {
+		    .name = "apci_table",
+		    .owner = THIS_MODULE,
+		    .mode = S_IRUGO,
+	    },
+	    .read = ibm_read_apci_table,
+	    .write = NULL,
+};
+static struct acpiphp_attention_info ibm_attention_info = 
+{
+	.set_attn = ibm_set_attention_status,
+	.get_attn = ibm_get_attention_status,
+	.owner = THIS_MODULE,
+};
+
+
+/*
+ * ibm_set_attention_status - callback method to set the attention LED
+ *
+ * this method is registered with the acpiphp module as a callback
+ * to do the device specific task of setting the LED status
+ *
+ */
+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;
+
+	if (!slot || !slot->private)
+		return -EINVAL;
+	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+	if (!acpi_slot)
+		return -EINVAL;
+
+	dbg("%s: set slot %d attention status to %d\n", __FUNCTION__,
+			acpi_slot->sun, (status ? 1 : 0));
+
+	args[0].type = ACPI_TYPE_INTEGER;
+	args[0].integer.value = acpi_slot->sun;
+	args[1].type = ACPI_TYPE_INTEGER;
+	args[1].integer.value = (status) ? 1 : 0;
+
+	stat = acpi_evaluate_integer(ibm_acpi_handle, "APLS", &params, &rc);
+	if (ACPI_FAILURE(stat)) {
+		retval = -ENODEV;
+		err("APLS evaluation failed:  0x%08x\n", stat);
+	} else if (!rc) {
+		retval = -ERANGE;
+		err("APLS method failed:  0x%08lx\n", rc);
+	}
+	return retval;
+}
+
+/*
+ * ibm_get_attention_status - callback method to get attention LED status
+ *
+ * this method is registered with the acpiphp module as a callback
+ * to do the device specific task of getting the LED status
+ * 
+ * Because there is no direct method of getting the LED status directly
+ * from an ACPI call, we read the aPCI table and parse out our
+ * slot descriptor to read the status from that.
+ *
+ */
+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;
+
+	if (!slot || !slot->private)
+		goto get_attn_done;
+	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+	if (!acpi_slot)
+		goto get_attn_done;
+
+	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;
+	}
+
+	dbg("%s: get slot %d attention status is %d retval=%x\n",
+			__FUNCTION__, acpi_slot->sun, *status, retval);
+
+get_attn_done:
+	if (table)
+		kfree(table);
+	return retval;
+}
+
+/*
+ * ibm_handle_events - listens for ACPI events for the IBM37D0 device
+ *
+ * this method is registered as a callback with the ACPI subsystem
+ * it is called when this device has an event to notify the OS of
+ *
+ * the events actually come from the device as two events that get
+ * synthesized into one event with data by this function.  The event
+ * ID comes first and then the slot number that caused it.  We report
+ * this as one event to the OS.
+ *
+ */
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context)
+{
+	// FIXME: this may have re-entrancy errors with event being static...
+	u8 detail = event & 0x0f;
+	u8 subevent = event & 0xf0;
+
+	struct notification *note = (struct notification *)context;
+
+	dbg("%s: Received notification %02x\n", __FUNCTION__, event);
+
+	if (subevent == 0x80) {
+		dbg("%s: generationg bus event\n", __FUNCTION__);
+		acpi_bus_generate_event(note->device, note->event, detail);
+	} else
+		note->event = event;
+}
+
+/*
+ * ibm_get_table_from_acpi - reads the APLS buffer from ACPI
+ * 
+ * this method reads the APLS buffer in from ACPI and
+ * stores the "stripped" table into a single buffer
+ * it allocates and passes the address back in bufp
+ *
+ * if NULL is passed in as buffer, this method only calculates
+ * the size of the table and returns that without filling
+ * in the buffer
+ *
+ * returns < 0 on error or the size of the table on success
+ */
+static int ibm_get_table_from_acpi(char **bufp)
+{
+	union acpi_object *package;
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	acpi_status status;
+	char *lbuf = NULL;
+	int i, size = -EIO;
+
+	status = acpi_evaluate_object(ibm_acpi_handle, "APCI", NULL, &buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  APCI evaluation failed\n", __FUNCTION__);
+		return -ENODEV;
+	}
+
+	package = (union acpi_object *) buffer.pointer;
+	if(!(package) ||
+			(package->type != ACPI_TYPE_PACKAGE) ||
+			!(package->package.elements)) {
+		err("%s:  Invalid APCI object\n", __FUNCTION__);
+		goto read_table_done;
+	}
+
+	for(size = 0, i = 0; i < package->package.count; i++) {
+		if (package->package.elements[i].type != ACPI_TYPE_BUFFER) {
+			err("%s:  Invalid APCI element %d\n", __FUNCTION__, i);
+			goto read_table_done;
+		}
+		size += package->package.elements[i].buffer.length;
+	}
+
+	if (bufp == NULL)
+		goto read_table_done;
+
+	lbuf = kmalloc(size, GFP_KERNEL);
+	dbg("%s: element count: %i, ASL table size: %i, &table = 0x%x\n",
+			__FUNCTION__, package->package.count, size, (int)lbuf);
+
+	if (lbuf) {
+		*bufp = lbuf;
+		memset(lbuf, 0, size);
+	} else {
+		size = -ENOMEM;
+		goto read_table_done;
+	}
+
+	size = 0;
+	for (i=0; i<package->package.count; i++) {
+		memcpy(&lbuf[size],
+				package->package.elements[i].buffer.pointer,
+				package->package.elements[i].buffer.length);
+		size += package->package.elements[i].buffer.length;
+	}
+
+read_table_done:
+	kfree(buffer.pointer);
+	return size;
+}
+
+/* ibm_read_apci_table - callback for the sysfs apci_table file
+ *
+ * gets registered with sysfs as the reader callback
+ * to be executed when /sys/bus/pci/slots/apci_table gets read
+ *
+ * since we don't get notified on open and close for this file,
+ * things get really tricky here...
+ * our solution is to only allow reading the table in all at once
+ */
+static ssize_t ibm_read_apci_table(struct kobject *kobj,
+		char *buffer, loff_t pos, size_t size)
+{
+	int bytes_read = -EINVAL;
+	char *table = NULL;
+	
+	dbg("%s: pos = %d, size = %d\n", __FUNCTION__, (int)pos, size);
+
+	if (pos == 0) {
+		bytes_read = ibm_get_table_from_acpi(&table);
+		if (bytes_read > 0 && bytes_read <= size)
+			memcpy(buffer, table, bytes_read);
+		if (table)
+			kfree(table);
+	}
+	return bytes_read;
+}
+
+/* ibm_find_acpi_device - callback to find our ACPI device
+ *
+ * used as a callback when calling acpi_walk_namespace
+ * to find our device.  When this method returns non-zero
+ * acpi_walk_namespace quits its search and returns our value
+ */
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv)
+{
+	acpi_handle *phandle = (acpi_handle *)context;
+	acpi_status status; 
+	struct acpi_device_info info; 
+	struct acpi_buffer info_buffer = {
+		.length = sizeof(struct acpi_device_info),
+		.pointer = &info,
+	};
+
+	status = acpi_get_object_info(handle, &info_buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  Failed to get device information", __FUNCTION__);
+		return 0;
+	}
+	info.hardware_id.value[sizeof(info.hardware_id.value) - 1] = '\0';
+
+	if(info.current_status && (info.valid & ACPI_VALID_HID) &&
+			(!strcmp(info.hardware_id.value, IBM_HARDWARE_ID1) ||
+			!strcmp(info.hardware_id.value, IBM_HARDWARE_ID2))) {
+		dbg("found hardware: %s, handle: %x\n", info.hardware_id.value,
+				(unsigned int)handle);
+		*phandle = handle;
+		/* returning non-zero causes the search to stop
+		 * and returns this value to the caller of 
+		 * acpi_walk_namespace, but it also causes some warnings
+		 * in the acpi debug code to print...
+		 */
+		return FOUND_APCI;
+	}
+	return 0;
+}
+
+static int __init ibm_acpiphp_init(void)
+{
+	int retval = 0;
+	acpi_status status;
+	struct acpi_device *device;
+	struct kobject *sysdir = &pci_hotplug_slots_subsys.kset.kobj;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+			ACPI_UINT32_MAX, ibm_find_acpi_device,
+			&ibm_acpi_handle, NULL) != FOUND_APCI) {
+		err("%s: acpi_walk_namespace failed\n", __FUNCTION__);
+		retval = -ENODEV;
+		goto init_return;
+	}
+	dbg("%s: found IBM aPCI device\n", __FUNCTION__);
+	if (acpi_bus_get_device(ibm_acpi_handle, &device)) {
+		err("%s: acpi_bus_get_device failed\n", __FUNCTION__);
+		retval = -ENODEV;
+		goto init_return;
+	}
+	if (acpiphp_register_attention_info(&ibm_attention_info)) {
+		retval = -ENODEV;
+		goto init_return;
+	}
+
+	ibm_note.device = device;
+	status = acpi_install_notify_handler(
+			ibm_acpi_handle,
+			ACPI_DEVICE_NOTIFY,
+			ibm_handle_events,
+			(void *)&ibm_note);
+	if (ACPI_FAILURE(status))
+	{
+		err("%s:  Failed to register notification handler\n",
+				__FUNCTION__);
+		retval = -EBUSY;
+		goto init_cleanup;
+	}
+
+	ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
+	retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
+
+	return retval;
+
+init_cleanup:
+	acpiphp_unregister_attention_info(&ibm_attention_info);
+init_return:
+	return retval;
+}
+
+static void __exit ibm_acpiphp_exit(void)
+{
+	acpi_status status;
+	struct kobject *sysdir = &pci_hotplug_slots_subsys.kset.kobj;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpiphp_unregister_attention_info(&ibm_attention_info))
+		err("%s: attention info deregistration failed", __FUNCTION__);
+
+	   status = acpi_remove_notify_handler(
+			   ibm_acpi_handle,
+			   ACPI_DEVICE_NOTIFY,
+			   ibm_handle_events);
+	   if (ACPI_FAILURE(status))
+		   err("%s:  Notification handler removal failed\n",
+				   __FUNCTION__);
+	// remove the /sys entries
+	if (sysfs_remove_bin_file(sysdir, &ibm_apci_table_attr))
+		err("%s: removal of sysfs file apci_table failed\n",
+				__FUNCTION__);
+}
+
+module_init(ibm_acpiphp_init);
+module_exit(ibm_acpiphp_exit);
+
+



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [Pcihpd-discuss] [PATCH] [0/2] acpiphp extension for 2.6.7
  2004-06-29 23:50   ` [PATCH] [0/2] " Vernon Mauery
@ 2004-07-02 20:58     ` Greg KH
  2004-07-03  0:02       ` [PATCH] [0/2] acpiphp extension for 2.6.7 (take 3) Vernon Mauery
                         ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Greg KH @ 2004-07-02 20:58 UTC (permalink / raw)
  To: Vernon Mauery
  Cc: Greg KH, lkml, Pat Gaughen, Chris McDermott, Jess Botts,
	pcihpd-discuss

On Tue, Jun 29, 2004 at 04:50:33PM -0700, Vernon Mauery wrote:
> After much discussion, dissection, rewriting and reading (documentation
> of course), I finally think this patch is ready to be included in the
> kernel.  I have chosen to split it into 2 parts because really, that's
> what it is -- a patch to acpiphp that allows other modules to register
> attention LED callback functions and also a new module that does just
> that for the IBM ACPI systems.  These patches were made against the
> 2.6.7 kernel tree.

I'm going to hold off applying these till you address the issues raised
on the mailing list.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] [0/2] acpiphp extension for 2.6.7 (take 3)
  2004-07-02 20:58     ` [Pcihpd-discuss] " Greg KH
@ 2004-07-03  0:02       ` Vernon Mauery
  2004-07-03  0:02       ` [PATCH] [1/2] " Vernon Mauery
  2004-07-03  0:02       ` [PATCH] [2/2] " Vernon Mauery
  2 siblings, 0 replies; 19+ messages in thread
From: Vernon Mauery @ 2004-07-03  0:02 UTC (permalink / raw)
  To: Greg KH; +Cc: Greg KH, lkml, Pat Gaughen, Chris McDermott, Jess Botts, pcihpd

On Fri, 2004-07-02 at 13:58, Greg KH wrote:
> I'm going to hold off applying these till you address the issues raised
> on the mailing list.

Greg,

I think I have fixed the problems that have been discussed on the
lists.  Many of the fixes had to do with too many checks on pointers.  I
killed all the checks except for the ones that would make the machine
oops immediately.  That was the guideline I used to make the decision on
what was a worthy check or not.  Let me know what you think about the
new version

Just for good measure, the description is included below again. :)

The two patches are to follow

--Vernon


After much discussion, dissection, rewriting and reading (documentation
of course), I finally think this patch is ready to be included in the
kernel.  I have chosen to split it into 2 parts because really, that's
what it is -- a patch to acpiphp that allows other modules to register
attention LED callback functions and also a new module that does just
that for the IBM ACPI systems.  These patches were made against the
2.6.7 kernel tree.

01 - acpiphp-attention-v0.1d.patch

        This patch adds the ability to register callback functions with
        the acpiphp core to set and get the current attention LED
        status.  The reason this is needed is because there is not set
        ACPI standard for how this is done so each hardware platform may
        implement it differently.  To keep hardware specific code out of
        acpiphp, we allow other modules to register their code with it.


02 - acpiphp_ibm-v1.0.1d.patch

        This patch adds the first driver that actually uses the callback
        function for attention LEDs that the acpiphp-attention patch
        adds.  It searches the ACPI namespace for IBM hardware, sets up
        the callbacks and sets up a handler to read ACPI events and
        forward them on to /proc/acpi/event.  It also exports an ACPI
        table that shows current hotplug status to userland.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] [1/2] acpiphp extension for 2.6.7 (take 3)
  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       ` Vernon Mauery
  2004-07-03  0:02       ` [PATCH] [2/2] " Vernon Mauery
  2 siblings, 0 replies; 19+ messages in thread
From: Vernon Mauery @ 2004-07-03  0:02 UTC (permalink / raw)
  To: Greg KH; +Cc: Greg KH, lkml, Pat Gaughen, Chris McDermott, Jess Botts, pcihpd

01 - acpiphp-attention-v0.1d.patch

        This patch adds the ability to register callback functions with
        the acpiphp core to set and get the current attention LED
        status.  The reason this is needed is because there is not set
        ACPI standard for how this is done so each hardware platform may
        implement it differently.  To keep hardware specific code out of
        acpiphp, we allow other modules to register their code with it.


 acpiphp.h      |   16 +++++++
 acpiphp_core.c |  127 ++++++++++++++++++++++++++++++++++++++++++++-------------
 acpiphp_glue.c |   14 ------
 3 files changed, 115 insertions(+), 42 deletions(-)


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


=====================================================================


--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp.h	2004-06-15 22:20:26.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp.h	2004-07-02 15:29:45.000000000 -0700
@@ -171,6 +171,18 @@
 	struct pci_resource *bus_head;
 };
 
+/**
+ * struct acpiphp_attention_info - device specific attention registration
+ *
+ * ACPI has no generic method of setting/getting attention status
+ * this allows for device specific driver registration
+ */
+struct acpiphp_attention_info
+{
+	int (*set_attn)(struct hotplug_slot *slot, u8 status);
+	int (*get_attn)(struct hotplug_slot *slot, u8 *status);
+	struct module *owner;
+};
 
 /* PCI bus bridge HID */
 #define ACPI_PCI_HOST_HID		"PNP0A03"
@@ -212,6 +224,10 @@
 
 /* function prototypes */
 
+/* acpiphp_core.c */
+extern int acpiphp_register_attention(struct acpiphp_attention_info*info);
+extern int acpiphp_unregister_attention(struct acpiphp_attention_info *info);
+
 /* acpiphp_glue.c */
 extern int acpiphp_glue_init (void);
 extern void acpiphp_glue_exit (void);
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_core.c	2004-06-15 22:19:37.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_core.c	2004-07-02 15:36:36.000000000 -0700
@@ -51,6 +51,7 @@
 
 /* local variables */
 static int num_slots;
+static struct acpiphp_attention_info *attention_info;
 
 #define DRIVER_VERSION	"0.4"
 #define DRIVER_AUTHOR	"Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>"
@@ -62,10 +63,15 @@
 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
 module_param(debug, bool, 644);
 
+/* export the attention callback registration methods */
+EXPORT_SYMBOL_GPL(acpiphp_register_attention);
+EXPORT_SYMBOL_GPL(acpiphp_unregister_attention);
+
 static int enable_slot		(struct hotplug_slot *slot);
 static int disable_slot		(struct hotplug_slot *slot);
 static int set_attention_status (struct hotplug_slot *slot, u8 value);
 static int get_power_status	(struct hotplug_slot *slot, u8 *value);
+static int get_attention_status (struct hotplug_slot *slot, u8 *value);
 static int get_address		(struct hotplug_slot *slot, u32 *value);
 static int get_latch_status	(struct hotplug_slot *slot, u8 *value);
 static int get_adapter_status	(struct hotplug_slot *slot, u8 *value);
@@ -76,11 +82,54 @@
 	.disable_slot		= disable_slot,
 	.set_attention_status	= set_attention_status,
 	.get_power_status	= get_power_status,
+	.get_attention_status	= get_attention_status,
 	.get_latch_status	= get_latch_status,
 	.get_adapter_status	= get_adapter_status,
 	.get_address		= get_address,
 };
 
+
+/**
+ * acpiphp_register_attention - set attention LED callback
+ * @info: must be completely filled with LED callbacks
+ *
+ * Description: this is used to register a hardware specific ACPI
+ * driver that manipulates the attention LED.  All the fields in
+ * info must be set.
+ **/
+int acpiphp_register_attention(struct acpiphp_attention_info *info)
+{
+	int retval = -1;
+
+	if (info && info->owner && info->set_attn &&
+			info->get_attn && !attention_info) {
+		retval = 0;
+		attention_info = info;
+	}
+	return retval;
+}
+
+
+/**
+ * acpiphp_unregister_attention - unset attention LED callback
+ * @info: must match the pointer used to register
+ *
+ * Description: this is used to un-register a hardware specific acpi
+ * driver that manipulates the attention LED.  The pointer to the 
+ * info struct must be the same as the one used to set it.
+ **/
+int acpiphp_unregister_attention(struct acpiphp_attention_info *info)
+{
+	int retval = -1;
+
+	if (info && attention_info == info) {
+		attention_info = NULL;
+		retval = 0;
+	}
+	return retval;
+}
+
+
 /**
  * enable_slot - power on and enable a slot
  * @hotplug_slot: slot to enable
@@ -117,33 +166,29 @@
 }
 
 
-/**
- * set_attention_status - set attention LED
- *
- * TBD:
- * ACPI doesn't have known method to manipulate
- * attention status LED.
- *
- */
-static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
-{
-	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
-
-	switch (status) {
-		case 0:
-			/* FIXME turn light off */
-			hotplug_slot->info->attention_status = 0;
-			break;
-
-		case 1:
-		default:
-			/* FIXME turn light on */
-			hotplug_slot->info->attention_status = 1;
-			break;
-	}
-
-	return 0;
-}
+ /**
+  * set_attention_status - set attention LED
+ * @hotplug_slot: slot to set attention LED on
+ * @status: value to set attention LED to (0 or 1)
+ *
+ * attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to blink the light for us.
+ **/
+ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
+ {
+	int retval = -1;
+
+ 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
+ 
+	if (attention_info && try_module_get(attention_info->owner)) {
+		retval = attention_info->set_attn(hotplug_slot, status);
+		module_put(attention_info->owner);
+	} else
+		attention_info = NULL;
+	return retval;
+ }
+ 
 
 /**
  * get_power_status - get power status of a slot
@@ -165,6 +210,32 @@
 	return 0;
 }
 
+
+ /**
+ * get_attention_status - get attention LED status
+ * @hotplug_slot: slot to get status from
+ * @value: returns with value of attention LED
+ *
+ * ACPI doesn't have known method to determine the state
+ * of the attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to determine its state
+ **/
+static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
+{
+	int retval = -1;
+
+	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
+
+	if (attention_info && try_module_get(attention_info->owner)) {
+		retval = attention_info->get_attn(hotplug_slot, value);
+		module_put(attention_info->owner);
+	} else
+		attention_info = NULL;
+	return retval;
+}
+
+
 /**
  * get_latch_status - get latch status of a slot
  * @hotplug_slot: slot to get status
@@ -307,7 +378,7 @@
 
 		slot->acpi_slot = get_slot_from_id(i);
 		slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
-		slot->hotplug_slot->info->attention_status = acpiphp_get_attention_status(slot->acpi_slot);
+		slot->hotplug_slot->info->attention_status = 0;
 		slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
 		slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
 		slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_glue.c	2004-06-15 22:19:10.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_glue.c	2004-07-02 15:37:00.000000000 -0700
@@ -1302,20 +1302,6 @@
 
 
 /*
- * attention LED ON: 1
- *		OFF: 0
- *
- * TBD
- * no direct attention led status information via ACPI
- *
- */
-u8 acpiphp_get_attention_status(struct acpiphp_slot *slot)
-{
-	return 0;
-}
-
-
-/*
  * latch closed:  1
  * latch   open:  0
  */




^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] [2/2] acpiphp extension for 2.6.7 (take 3)
  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       ` Vernon Mauery
  2 siblings, 0 replies; 19+ messages in thread
From: Vernon Mauery @ 2004-07-03  0:02 UTC (permalink / raw)
  To: Greg KH; +Cc: Greg KH, lkml, Pat Gaughen, Chris McDermott, Jess Botts, pcihpd

02 - acpiphp_ibm-v1.0.1d.patch

        This patch adds the first driver that actually uses the callback
        function for attention LEDs that the acpiphp-attention patch
        adds.  It searches the ACPI namespace for IBM hardware, sets up
        the callbacks and sets up a handler to read ACPI events and
        forward them on to /proc/acpi/event.  It also exports an ACPI
        table that shows current hotplug status to userland.


 Kconfig       |   12 +
 Makefile      |    1
 acpiphp_ibm.c |  474 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 487 insertions(+)


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


=====================================================================


--- linux-2.6.7.orig/drivers/pci/hotplug/Makefile	2004-06-15 22:19:43.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/Makefile	2004-07-02 15:24:23.000000000 -0700
@@ -7,6 +7,7 @@
 obj-$(CONFIG_HOTPLUG_PCI_COMPAQ)	+= cpqphp.o
 obj-$(CONFIG_HOTPLUG_PCI_IBM)		+= ibmphp.o
 obj-$(CONFIG_HOTPLUG_PCI_ACPI)		+= acpiphp.o
+obj-$(CONFIG_HOTPLUG_PCI_ACPI_IBM)	+= acpiphp_ibm.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_ZT5550)	+= cpcihp_zt5550.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_GENERIC)	+= cpcihp_generic.o
 obj-$(CONFIG_HOTPLUG_PCI_PCIE)		+= pciehp.o
--- linux-2.6.7.orig/drivers/pci/hotplug/Kconfig	2004-06-15 22:19:17.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/Kconfig	2004-07-02 15:24:23.000000000 -0700
@@ -88,6 +88,18 @@
 
 	  When in doubt, say N.
 
+config HOTPLUG_PCI_ACPI_IBM
+	tristate "ACPI PCI Hotplug driver IBM extensions"
+	depends on HOTPLUG_PCI_ACPI
+	help
+	  Say Y here if you have an IBM system that supports PCI Hotplug using
+	  ACPI.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called acpiphp_ibm.
+
+	  When in doubt, say N.
+
 config HOTPLUG_PCI_CPCI
 	bool "CompactPCI Hotplug driver"
 	depends on HOTPLUG_PCI
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_ibm.c	1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_ibm.c	2004-07-02 15:27:02.000000000 -0700
@@ -0,0 +1,474 @@
+/*
+ * ACPI PCI Hot Plug IBM Extension
+ *
+ * Copyright (C) 2004 Vernon Mauery <vernux@us.ibm.com>
+ * Copyright (C) 2004 IBM Corp.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Send feedback to <vernux@us.ibm.com>
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <acpi/acpi_bus.h>
+#include <linux/sysfs.h>
+#include <linux/kobject.h>
+#include <asm/uaccess.h>
+#include <linux/moduleparam.h>
+
+#include "acpiphp.h"
+#include "pci_hotplug.h"
+
+#define DRIVER_VERSION	"1.0.1"
+#define DRIVER_AUTHOR	"Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
+#define DRIVER_DESC	"ACPI Hot Plug PCI Controller Driver IBM extension"
+
+static int debug;
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRIVER_VERSION);
+module_param(debug, bool, 644);
+MODULE_PARM_DESC(debug, " Debugging mode enabled or not");
+#define MY_NAME "acpiphp_ibm"
+
+#undef dbg
+#define dbg(format, arg...)				\
+do {							\
+	if (debug)					\
+		printk(KERN_DEBUG "%s: " format,	\
+				MY_NAME , ## arg);	\
+} while (0)
+
+#define FOUND_APCI 0x61504349
+/* these are the names for the IBM ACPI pseudo-device */
+#define IBM_HARDWARE_ID1 "IBM37D0"
+#define IBM_HARDWARE_ID2 "IBM37D4"
+
+/* union apci_descriptor - allows access to the
+ * various device descriptors that are embedded in the
+ * aPCI table
+ */
+union apci_descriptor {
+	struct {
+		char sig[4];
+		u8   len;
+	} header;
+	struct {
+		u8  type;
+		u8  len;
+		u16 slot_id;
+		u8  bus_id;
+		u8  dev_num;
+		u8  slot_num;
+		u8  slot_attr[2];
+		u8  attn;
+		u8  status[2];
+		u8  sun;
+	} slot;
+	struct {
+		u8 type;
+		u8 len;
+	} generic;
+};
+
+/* struct notification - keeps info about the device
+ * that cause the ACPI notification event
+ */
+struct notification {
+	struct acpi_device *device;
+	u8                  event;
+};
+
+static int ibm_set_attention_status(struct hotplug_slot *slot, u8 status);
+static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status);
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context);
+static int ibm_get_table_from_acpi(char **bufp);
+static ssize_t ibm_read_apci_table(struct kobject *kobj,
+		char *buffer, loff_t pos, size_t size);
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv);
+static int __init ibm_acpiphp_init(void);
+static void __exit ibm_acpiphp_exit(void);
+
+static acpi_handle ibm_acpi_handle;
+static struct notification ibm_note;
+static struct bin_attribute ibm_apci_table_attr = {
+	    .attr = {
+		    .name = "apci_table",
+		    .owner = THIS_MODULE,
+		    .mode = S_IRUGO,
+	    },
+	    .read = ibm_read_apci_table,
+	    .write = NULL,
+};
+static struct acpiphp_attention_info ibm_attention_info = 
+{
+	.set_attn = ibm_set_attention_status,
+	.get_attn = ibm_get_attention_status,
+	.owner = THIS_MODULE,
+};
+
+
+/**
+ * ibm_set_attention_status - callback method to set the attention LED
+ * @slot: the hotplug_slot to work with
+ * @status: what to set the LED to (0 or 1)
+ *
+ * Description: this method is registered with the acpiphp module as a
+ * callback to do the device specific task of setting the LED status
+ **/
+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;
+
+	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+
+	dbg("%s: set slot %d attention status to %d\n", __FUNCTION__,
+			acpi_slot->sun, (status ? 1 : 0));
+
+	args[0].type = ACPI_TYPE_INTEGER;
+	args[0].integer.value = acpi_slot->sun;
+	args[1].type = ACPI_TYPE_INTEGER;
+	args[1].integer.value = (status) ? 1 : 0;
+
+	stat = acpi_evaluate_integer(ibm_acpi_handle, "APLS", &params, &rc);
+	if (ACPI_FAILURE(stat)) {
+		retval = -ENODEV;
+		err("APLS evaluation failed:  0x%08x\n", stat);
+	} else if (!rc) {
+		retval = -ERANGE;
+		err("APLS method failed:  0x%08lx\n", rc);
+	}
+	return retval;
+}
+
+/**
+ * ibm_get_attention_status - callback method to get attention LED status
+ * @slot: the hotplug_slot to work with
+ * @status: returns what the LED is set to (0 or 1)
+ *
+ * Description: this method is registered with the acpiphp module as a
+ * callback to do the device specific task of getting the LED status
+ * 
+ * Because there is no direct method of getting the LED status directly
+ * from an ACPI call, we read the aPCI table and parse out our
+ * slot descriptor to read the status from that.
+ **/
+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;
+
+	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;
+	}
+
+	dbg("%s: get slot %d attention status is %d retval=%x\n",
+			__FUNCTION__, acpi_slot->sun, *status, retval);
+
+get_attn_done:
+	kfree(table);
+	return retval;
+}
+
+/**
+ * ibm_handle_events - listens for ACPI events for the IBM37D0 device
+ * @handle: an ACPI handle to the device that caused the event
+ * @event: the event info (device specific)
+ * @context: passed context (our notification struct)
+ *
+ * Description: this method is registered as a callback with the ACPI
+ * subsystem it is called when this device has an event to notify the OS of
+ *
+ * The events actually come from the device as two events that get
+ * synthesized into one event with data by this function.  The event
+ * ID comes first and then the slot number that caused it.  We report
+ * this as one event to the OS.
+ *
+ * From section 5.6.2.2 of the ACPI 2.0 spec, I understand that the OSPM will
+ * only re-enable the interrupt that causes this event AFTER this method
+ * has returned, thereby enforcing serial access for the notification struct.
+ **/
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context)
+{
+	u8 detail = event & 0x0f;
+	u8 subevent = event & 0xf0;
+	struct notification *note = context;
+
+	dbg("%s: Received notification %02x\n", __FUNCTION__, event);
+
+	if (subevent == 0x80) {
+		dbg("%s: generationg bus event\n", __FUNCTION__);
+		acpi_bus_generate_event(note->device, note->event, detail);
+	} else
+		note->event = event;
+}
+
+/**
+ * ibm_get_table_from_acpi - reads the APLS buffer from ACPI
+ * @bufp: address to pointer to allocate for the table
+ *
+ * Description: this method reads the APLS buffer in from ACPI and
+ * stores the "stripped" table into a single buffer
+ * it allocates and passes the address back in bufp
+ *
+ * If NULL is passed in as buffer, this method only calculates
+ * the size of the table and returns that without filling
+ * in the buffer
+ *
+ * returns < 0 on error or the size of the table on success
+ **/
+static int ibm_get_table_from_acpi(char **bufp)
+{
+	union acpi_object *package;
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	acpi_status status;
+	char *lbuf = NULL;
+	int i, size = -EIO;
+
+	status = acpi_evaluate_object(ibm_acpi_handle, "APCI", NULL, &buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  APCI evaluation failed\n", __FUNCTION__);
+		return -ENODEV;
+	}
+
+	package = (union acpi_object *) buffer.pointer;
+	if(!(package) ||
+			(package->type != ACPI_TYPE_PACKAGE) ||
+			!(package->package.elements)) {
+		err("%s:  Invalid APCI object\n", __FUNCTION__);
+		goto read_table_done;
+	}
+
+	for(size = 0, i = 0; i < package->package.count; i++) {
+		if (package->package.elements[i].type != ACPI_TYPE_BUFFER) {
+			err("%s:  Invalid APCI element %d\n", __FUNCTION__, i);
+			goto read_table_done;
+		}
+		size += package->package.elements[i].buffer.length;
+	}
+
+	if (bufp == NULL)
+		goto read_table_done;
+
+	lbuf = kmalloc(size, GFP_KERNEL);
+	dbg("%s: element count: %i, ASL table size: %i, &table = 0x%p\n",
+			__FUNCTION__, package->package.count, size, lbuf);
+
+	if (lbuf) {
+		*bufp = lbuf;
+		memset(lbuf, 0, size);
+	} else {
+		size = -ENOMEM;
+		goto read_table_done;
+	}
+
+	size = 0;
+	for (i=0; i<package->package.count; i++) {
+		memcpy(&lbuf[size],
+				package->package.elements[i].buffer.pointer,
+				package->package.elements[i].buffer.length);
+		size += package->package.elements[i].buffer.length;
+	}
+
+read_table_done:
+	kfree(buffer.pointer);
+	return size;
+}
+
+/**
+ * ibm_read_apci_table - callback for the sysfs apci_table file
+ * @kobj: the kobject this binary attribute is a part of
+ * @buffer: the kernel space buffer to fill
+ * @pos: the offset into the file
+ * @size: the number of bytes requested
+ *
+ * Description: gets registered with sysfs as the reader callback
+ * to be executed when /sys/bus/pci/slots/apci_table gets read
+ *
+ * Since we don't get notified on open and close for this file,
+ * things get really tricky here...
+ * our solution is to only allow reading the table in all at once
+ **/
+static ssize_t ibm_read_apci_table(struct kobject *kobj,
+		char *buffer, loff_t pos, size_t size)
+{
+	int bytes_read = -EINVAL;
+	char *table = NULL;
+	
+	dbg("%s: pos = %d, size = %d\n", __FUNCTION__, (int)pos, size);
+
+	if (pos == 0) {
+		bytes_read = ibm_get_table_from_acpi(&table);
+		if (bytes_read > 0 && bytes_read <= size)
+			memcpy(buffer, table, bytes_read);
+		kfree(table);
+	}
+	return bytes_read;
+}
+
+/**
+ * ibm_find_acpi_device - callback to find our ACPI device
+ * @handle: the ACPI handle of the device we are inspecting
+ * @lvl: depth into the namespace tree
+ * @context: a pointer to our handle to fill when we find the device
+ * @rv: a return value to fill if desired
+ *
+ * Description: used as a callback when calling acpi_walk_namespace
+ * to find our device.  When this method returns non-zero
+ * acpi_walk_namespace quits its search and returns our value
+ **/
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv)
+{
+	acpi_handle *phandle = (acpi_handle *)context;
+	acpi_status status; 
+	struct acpi_device_info info; 
+	struct acpi_buffer info_buffer = {
+		.length = sizeof(struct acpi_device_info),
+		.pointer = &info,
+	};
+
+	status = acpi_get_object_info(handle, &info_buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  Failed to get device information", __FUNCTION__);
+		return 0;
+	}
+	info.hardware_id.value[sizeof(info.hardware_id.value) - 1] = '\0';
+
+	if(info.current_status && (info.valid & ACPI_VALID_HID) &&
+			(!strcmp(info.hardware_id.value, IBM_HARDWARE_ID1) ||
+			!strcmp(info.hardware_id.value, IBM_HARDWARE_ID2))) {
+		dbg("found hardware: %s, handle: %x\n", info.hardware_id.value,
+				(unsigned int)handle);
+		*phandle = handle;
+		/* returning non-zero causes the search to stop
+		 * and returns this value to the caller of 
+		 * acpi_walk_namespace, but it also causes some warnings
+		 * in the acpi debug code to print...
+		 */
+		return FOUND_APCI;
+	}
+	return 0;
+}
+
+static int __init ibm_acpiphp_init(void)
+{
+	int retval = 0;
+	acpi_status status;
+	struct acpi_device *device;
+	struct kobject *sysdir = &pci_hotplug_slots_subsys.kset.kobj;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+			ACPI_UINT32_MAX, ibm_find_acpi_device,
+			&ibm_acpi_handle, NULL) != FOUND_APCI) {
+		err("%s: acpi_walk_namespace failed\n", __FUNCTION__);
+		retval = -ENODEV;
+		goto init_return;
+	}
+	dbg("%s: found IBM aPCI device\n", __FUNCTION__);
+	if (acpi_bus_get_device(ibm_acpi_handle, &device)) {
+		err("%s: acpi_bus_get_device failed\n", __FUNCTION__);
+		retval = -ENODEV;
+		goto init_return;
+	}
+	if (acpiphp_register_attention(&ibm_attention_info)) {
+		retval = -ENODEV;
+		goto init_return;
+	}
+
+	ibm_note.device = device;
+	status = acpi_install_notify_handler(
+			ibm_acpi_handle,
+			ACPI_DEVICE_NOTIFY,
+			ibm_handle_events,
+			&ibm_note);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  Failed to register notification handler\n",
+				__FUNCTION__);
+		retval = -EBUSY;
+		goto init_cleanup;
+	}
+
+	ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
+	retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
+
+	return retval;
+
+init_cleanup:
+	acpiphp_unregister_attention(&ibm_attention_info);
+init_return:
+	return retval;
+}
+
+static void __exit ibm_acpiphp_exit(void)
+{
+	acpi_status status;
+	struct kobject *sysdir = &pci_hotplug_slots_subsys.kset.kobj;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpiphp_unregister_attention(&ibm_attention_info))
+		err("%s: attention info deregistration failed", __FUNCTION__);
+
+	   status = acpi_remove_notify_handler(
+			   ibm_acpi_handle,
+			   ACPI_DEVICE_NOTIFY,
+			   ibm_handle_events);
+	   if (ACPI_FAILURE(status))
+		   err("%s:  Notification handler removal failed\n",
+				   __FUNCTION__);
+	// remove the /sys entries
+	if (sysfs_remove_bin_file(sysdir, &ibm_apci_table_attr))
+		err("%s: removal of sysfs file apci_table failed\n",
+				__FUNCTION__);
+}
+
+module_init(ibm_acpiphp_init);
+module_exit(ibm_acpiphp_exit);



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] [0/2] acpiphp extension for 2.6.7 (final)
       [not found]         ` <20040708232827.GA20755@kroah.com>
@ 2004-07-09  0:11           ` Vernon Mauery
  2004-07-09  0:12           ` [PATCH] [1/2] " Vernon Mauery
                             ` (2 subsequent siblings)
  3 siblings, 0 replies; 19+ messages in thread
From: Vernon Mauery @ 2004-07-09  0:11 UTC (permalink / raw)
  To: Greg KH; +Cc: pcihpd, Greg KH, lkml, Pat Gaughen, Chris McDermott, Jess Botts

On Thu, 2004-07-08 at 16:28, Greg KH wrote:
> Those checks are fine with me, I don't have a problem with them.
> 
> > Either way, after I make the other fixes (and possibly this one), should
> > I resubmit both patches together or just 1 of 2 alone?
> 
> Resend both of them, that way I'm reminded that they both need to be
> applied :)
> 

Just for good measure, the description is included below again. :)

The two patches are to follow

--Vernon


After much discussion, dissection, rewriting and reading (documentation
of course), I finally think this patch is ready to be included in the
kernel.  I have chosen to split it into 2 parts because really, that's
what it is -- a patch to acpiphp that allows other modules to register
attention LED callback functions and also a new module that does just
that for the IBM ACPI systems.  These patches were made against the
2.6.7 kernel tree.

01 - acpiphp-attention-v0.1d.patch

        This patch adds the ability to register callback functions with
        the acpiphp core to set and get the current attention LED
        status.  The reason this is needed is because there is not set
        ACPI standard for how this is done so each hardware platform may
        implement it differently.  To keep hardware specific code out of
        acpiphp, we allow other modules to register their code with it.


02 - acpiphp_ibm-v1.0.1d.patch

        This patch adds the first driver that actually uses the callback
        function for attention LEDs that the acpiphp-attention patch
        adds.  It searches the ACPI namespace for IBM hardware, sets up
        the callbacks and sets up a handler to read ACPI events and
        forward them on to /proc/acpi/event.  It also exports an ACPI
        table that shows current hotplug status to userland.




^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] [1/2] acpiphp extension for 2.6.7 (final)
       [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           ` Vernon Mauery
  2004-07-14 22:52             ` Greg KH
  2004-07-09  0:12           ` [PATCH] [2/2] " Vernon Mauery
  2004-09-16 18:23           ` [PATCH] acpiphp extension fixes for 2.6.9-rc2 Vernon Mauery
  3 siblings, 1 reply; 19+ messages in thread
From: Vernon Mauery @ 2004-07-09  0:12 UTC (permalink / raw)
  To: Greg KH; +Cc: pcihpd, lkml, Greg KH, Pat Gaughen, Chris McDermott, Jess Botts

01 - acpiphp-attention-v0.1e.patch

        This patch adds the ability to register callback functions with
        the acpiphp core to set and get the current attention LED
        status.  The reason this is needed is because there is not set
        ACPI standard for how this is done so each hardware platform may
        implement it differently.  To keep hardware specific code out of
        acpiphp, we allow other modules to register their code with it.


 acpiphp.h      |   16 +++++++
 acpiphp_core.c |  127 ++++++++++++++++++++++++++++++++++++++++++++-------------
 acpiphp_glue.c |   14 ------
 3 files changed, 115 insertions(+), 42 deletions(-)

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

=====================================================================

--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp.h	2004-06-15 22:20:26.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp.h	2004-07-08 16:54:07.996176600 -0700
@@ -171,6 +171,18 @@
 	struct pci_resource *bus_head;
 };
 
+/**
+ * struct acpiphp_attention_info - device specific attention registration
+ *
+ * ACPI has no generic method of setting/getting attention status
+ * this allows for device specific driver registration
+ */
+struct acpiphp_attention_info
+{
+	int (*set_attn)(struct hotplug_slot *slot, u8 status);
+	int (*get_attn)(struct hotplug_slot *slot, u8 *status);
+	struct module *owner;
+};
 
 /* PCI bus bridge HID */
 #define ACPI_PCI_HOST_HID		"PNP0A03"
@@ -212,6 +224,10 @@
 
 /* function prototypes */
 
+/* acpiphp_core.c */
+extern int acpiphp_register_attention(struct acpiphp_attention_info*info);
+extern int acpiphp_unregister_attention(struct acpiphp_attention_info *info);
+
 /* acpiphp_glue.c */
 extern int acpiphp_glue_init (void);
 extern void acpiphp_glue_exit (void);
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_core.c	2004-06-15 22:19:37.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_core.c	2004-07-08 16:54:07.997176448 -0700
@@ -51,6 +51,7 @@
 
 /* local variables */
 static int num_slots;
+static struct acpiphp_attention_info *attention_info;
 
 #define DRIVER_VERSION	"0.4"
 #define DRIVER_AUTHOR	"Greg Kroah-Hartman <gregkh@us.ibm.com>, Takayoshi Kochi <t-kochi@bq.jp.nec.com>"
@@ -62,10 +63,15 @@
 MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
 module_param(debug, bool, 644);
 
+/* export the attention callback registration methods */
+EXPORT_SYMBOL_GPL(acpiphp_register_attention);
+EXPORT_SYMBOL_GPL(acpiphp_unregister_attention);
+
 static int enable_slot		(struct hotplug_slot *slot);
 static int disable_slot		(struct hotplug_slot *slot);
 static int set_attention_status (struct hotplug_slot *slot, u8 value);
 static int get_power_status	(struct hotplug_slot *slot, u8 *value);
+static int get_attention_status (struct hotplug_slot *slot, u8 *value);
 static int get_address		(struct hotplug_slot *slot, u32 *value);
 static int get_latch_status	(struct hotplug_slot *slot, u8 *value);
 static int get_adapter_status	(struct hotplug_slot *slot, u8 *value);
@@ -76,11 +82,54 @@
 	.disable_slot		= disable_slot,
 	.set_attention_status	= set_attention_status,
 	.get_power_status	= get_power_status,
+	.get_attention_status	= get_attention_status,
 	.get_latch_status	= get_latch_status,
 	.get_adapter_status	= get_adapter_status,
 	.get_address		= get_address,
 };
 
+
+/**
+ * acpiphp_register_attention - set attention LED callback
+ * @info: must be completely filled with LED callbacks
+ *
+ * Description: this is used to register a hardware specific ACPI
+ * driver that manipulates the attention LED.  All the fields in
+ * info must be set.
+ **/
+int acpiphp_register_attention(struct acpiphp_attention_info *info)
+{
+	int retval = -EINVAL;
+
+	if (info && info->owner && info->set_attn &&
+			info->get_attn && !attention_info) {
+		retval = 0;
+		attention_info = info;
+	}
+	return retval;
+}
+
+
+/**
+ * acpiphp_unregister_attention - unset attention LED callback
+ * @info: must match the pointer used to register
+ *
+ * Description: this is used to un-register a hardware specific acpi
+ * driver that manipulates the attention LED.  The pointer to the 
+ * info struct must be the same as the one used to set it.
+ **/
+int acpiphp_unregister_attention(struct acpiphp_attention_info *info)
+{
+	int retval = -EINVAL;
+
+	if (info && attention_info == info) {
+		attention_info = NULL;
+		retval = 0;
+	}
+	return retval;
+}
+
+
 /**
  * enable_slot - power on and enable a slot
  * @hotplug_slot: slot to enable
@@ -117,33 +166,29 @@
 }
 
 
-/**
- * set_attention_status - set attention LED
- *
- * TBD:
- * ACPI doesn't have known method to manipulate
- * attention status LED.
- *
- */
-static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
-{
-	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
-
-	switch (status) {
-		case 0:
-			/* FIXME turn light off */
-			hotplug_slot->info->attention_status = 0;
-			break;
-
-		case 1:
-		default:
-			/* FIXME turn light on */
-			hotplug_slot->info->attention_status = 1;
-			break;
-	}
-
-	return 0;
-}
+ /**
+  * set_attention_status - set attention LED
+ * @hotplug_slot: slot to set attention LED on
+ * @status: value to set attention LED to (0 or 1)
+ *
+ * attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to blink the light for us.
+ **/
+ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
+ {
+	int retval = -ENODEV;
+
+ 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
+ 
+	if (attention_info && try_module_get(attention_info->owner)) {
+		retval = attention_info->set_attn(hotplug_slot, status);
+		module_put(attention_info->owner);
+	} else
+		attention_info = NULL;
+	return retval;
+ }
+ 
 
 /**
  * get_power_status - get power status of a slot
@@ -165,6 +210,32 @@
 	return 0;
 }
 
+
+ /**
+ * get_attention_status - get attention LED status
+ * @hotplug_slot: slot to get status from
+ * @value: returns with value of attention LED
+ *
+ * ACPI doesn't have known method to determine the state
+ * of the attention status LED, so we use a callback that
+ * was registered with us.  This allows hardware specific
+ * ACPI implementations to determine its state
+ **/
+static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
+{
+	int retval = -EINVAL;
+
+	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
+
+	if (attention_info && try_module_get(attention_info->owner)) {
+		retval = attention_info->get_attn(hotplug_slot, value);
+		module_put(attention_info->owner);
+	} else
+		attention_info = NULL;
+	return retval;
+}
+
+
 /**
  * get_latch_status - get latch status of a slot
  * @hotplug_slot: slot to get status
@@ -307,7 +378,7 @@
 
 		slot->acpi_slot = get_slot_from_id(i);
 		slot->hotplug_slot->info->power_status = acpiphp_get_power_status(slot->acpi_slot);
-		slot->hotplug_slot->info->attention_status = acpiphp_get_attention_status(slot->acpi_slot);
+		slot->hotplug_slot->info->attention_status = 0;
 		slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
 		slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
 		slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_glue.c	2004-06-15 22:19:10.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_glue.c	2004-07-08 16:54:07.998176296 -0700
@@ -1302,20 +1302,6 @@
 
 
 /*
- * attention LED ON: 1
- *		OFF: 0
- *
- * TBD
- * no direct attention led status information via ACPI
- *
- */
-u8 acpiphp_get_attention_status(struct acpiphp_slot *slot)
-{
-	return 0;
-}
-
-
-/*
  * latch closed:  1
  * latch   open:  0
  */



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] [2/2] acpiphp extension for 2.6.7 (final)
       [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-09  0:12           ` Vernon Mauery
  2004-07-14 22:52             ` Greg KH
  2004-09-16 18:23           ` [PATCH] acpiphp extension fixes for 2.6.9-rc2 Vernon Mauery
  3 siblings, 1 reply; 19+ messages in thread
From: Vernon Mauery @ 2004-07-09  0:12 UTC (permalink / raw)
  To: Greg KH; +Cc: pcihpd, lkml, Greg KH, Pat Gaughen, Chris McDermott, Jess Botts

02 - acpiphp_ibm-v1.0.1e.patch

        This patch adds the first driver that actually uses the callback
        function for attention LEDs that the acpiphp-attention patch
        adds.  It searches the ACPI namespace for IBM hardware, sets up
        the callbacks and sets up a handler to read ACPI events and
        forward them on to /proc/acpi/event.  It also exports an ACPI
        table that shows current hotplug status to userland.


 Kconfig       |   12 +
 Makefile      |    1
 acpiphp_ibm.c |  474 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 487 insertions(+)

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

=====================================================================

--- linux-2.6.7.orig/drivers/pci/hotplug/Makefile	2004-06-15 22:19:43.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/Makefile	2004-07-08 16:54:14.635167320 -0700
@@ -7,6 +7,7 @@
 obj-$(CONFIG_HOTPLUG_PCI_COMPAQ)	+= cpqphp.o
 obj-$(CONFIG_HOTPLUG_PCI_IBM)		+= ibmphp.o
 obj-$(CONFIG_HOTPLUG_PCI_ACPI)		+= acpiphp.o
+obj-$(CONFIG_HOTPLUG_PCI_ACPI_IBM)	+= acpiphp_ibm.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_ZT5550)	+= cpcihp_zt5550.o
 obj-$(CONFIG_HOTPLUG_PCI_CPCI_GENERIC)	+= cpcihp_generic.o
 obj-$(CONFIG_HOTPLUG_PCI_PCIE)		+= pciehp.o
--- linux-2.6.7.orig/drivers/pci/hotplug/Kconfig	2004-06-15 22:19:17.000000000 -0700
+++ linux-2.6.7-apci/drivers/pci/hotplug/Kconfig	2004-07-08 16:54:14.636167168 -0700
@@ -88,6 +88,18 @@
 
 	  When in doubt, say N.
 
+config HOTPLUG_PCI_ACPI_IBM
+	tristate "ACPI PCI Hotplug driver IBM extensions"
+	depends on HOTPLUG_PCI_ACPI
+	help
+	  Say Y here if you have an IBM system that supports PCI Hotplug using
+	  ACPI.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called acpiphp_ibm.
+
+	  When in doubt, say N.
+
 config HOTPLUG_PCI_CPCI
 	bool "CompactPCI Hotplug driver"
 	depends on HOTPLUG_PCI
--- linux-2.6.7.orig/drivers/pci/hotplug/acpiphp_ibm.c	1969-12-31 16:00:00.000000000 -0800
+++ linux-2.6.7-apci/drivers/pci/hotplug/acpiphp_ibm.c	2004-07-08 16:54:14.637167016 -0700
@@ -0,0 +1,474 @@
+/*
+ * ACPI PCI Hot Plug IBM Extension
+ *
+ * Copyright (C) 2004 Vernon Mauery <vernux@us.ibm.com>
+ * Copyright (C) 2004 IBM Corp.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Send feedback to <vernux@us.ibm.com>
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <acpi/acpi_bus.h>
+#include <linux/sysfs.h>
+#include <linux/kobject.h>
+#include <asm/uaccess.h>
+#include <linux/moduleparam.h>
+
+#include "acpiphp.h"
+#include "pci_hotplug.h"
+
+#define DRIVER_VERSION	"1.0.1"
+#define DRIVER_AUTHOR	"Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
+#define DRIVER_DESC	"ACPI Hot Plug PCI Controller Driver IBM extension"
+
+static int debug;
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+MODULE_VERSION(DRIVER_VERSION);
+module_param(debug, bool, 644);
+MODULE_PARM_DESC(debug, " Debugging mode enabled or not");
+#define MY_NAME "acpiphp_ibm"
+
+#undef dbg
+#define dbg(format, arg...)				\
+do {							\
+	if (debug)					\
+		printk(KERN_DEBUG "%s: " format,	\
+				MY_NAME , ## arg);	\
+} while (0)
+
+#define FOUND_APCI 0x61504349
+/* these are the names for the IBM ACPI pseudo-device */
+#define IBM_HARDWARE_ID1 "IBM37D0"
+#define IBM_HARDWARE_ID2 "IBM37D4"
+
+/* union apci_descriptor - allows access to the
+ * various device descriptors that are embedded in the
+ * aPCI table
+ */
+union apci_descriptor {
+	struct {
+		char sig[4];
+		u8   len;
+	} header;
+	struct {
+		u8  type;
+		u8  len;
+		u16 slot_id;
+		u8  bus_id;
+		u8  dev_num;
+		u8  slot_num;
+		u8  slot_attr[2];
+		u8  attn;
+		u8  status[2];
+		u8  sun;
+	} slot;
+	struct {
+		u8 type;
+		u8 len;
+	} generic;
+};
+
+/* struct notification - keeps info about the device
+ * that cause the ACPI notification event
+ */
+struct notification {
+	struct acpi_device *device;
+	u8                  event;
+};
+
+static int ibm_set_attention_status(struct hotplug_slot *slot, u8 status);
+static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status);
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context);
+static int ibm_get_table_from_acpi(char **bufp);
+static ssize_t ibm_read_apci_table(struct kobject *kobj,
+		char *buffer, loff_t pos, size_t size);
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv);
+static int __init ibm_acpiphp_init(void);
+static void __exit ibm_acpiphp_exit(void);
+
+static acpi_handle ibm_acpi_handle;
+static struct notification ibm_note;
+static struct bin_attribute ibm_apci_table_attr = {
+	    .attr = {
+		    .name = "apci_table",
+		    .owner = THIS_MODULE,
+		    .mode = S_IRUGO,
+	    },
+	    .read = ibm_read_apci_table,
+	    .write = NULL,
+};
+static struct acpiphp_attention_info ibm_attention_info = 
+{
+	.set_attn = ibm_set_attention_status,
+	.get_attn = ibm_get_attention_status,
+	.owner = THIS_MODULE,
+};
+
+
+/**
+ * ibm_set_attention_status - callback method to set the attention LED
+ * @slot: the hotplug_slot to work with
+ * @status: what to set the LED to (0 or 1)
+ *
+ * Description: this method is registered with the acpiphp module as a
+ * callback to do the device specific task of setting the LED status
+ **/
+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;
+
+	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+
+	dbg("%s: set slot %d attention status to %d\n", __FUNCTION__,
+			acpi_slot->sun, (status ? 1 : 0));
+
+	args[0].type = ACPI_TYPE_INTEGER;
+	args[0].integer.value = acpi_slot->sun;
+	args[1].type = ACPI_TYPE_INTEGER;
+	args[1].integer.value = (status) ? 1 : 0;
+
+	stat = acpi_evaluate_integer(ibm_acpi_handle, "APLS", &params, &rc);
+	if (ACPI_FAILURE(stat)) {
+		retval = -ENODEV;
+		err("APLS evaluation failed:  0x%08x\n", stat);
+	} else if (!rc) {
+		retval = -ERANGE;
+		err("APLS method failed:  0x%08lx\n", rc);
+	}
+	return retval;
+}
+
+/**
+ * ibm_get_attention_status - callback method to get attention LED status
+ * @slot: the hotplug_slot to work with
+ * @status: returns what the LED is set to (0 or 1)
+ *
+ * Description: this method is registered with the acpiphp module as a
+ * callback to do the device specific task of getting the LED status
+ * 
+ * Because there is no direct method of getting the LED status directly
+ * from an ACPI call, we read the aPCI table and parse out our
+ * slot descriptor to read the status from that.
+ **/
+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;
+
+	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;
+	}
+
+	dbg("%s: get slot %d attention status is %d retval=%x\n",
+			__FUNCTION__, acpi_slot->sun, *status, retval);
+
+get_attn_done:
+	kfree(table);
+	return retval;
+}
+
+/**
+ * ibm_handle_events - listens for ACPI events for the IBM37D0 device
+ * @handle: an ACPI handle to the device that caused the event
+ * @event: the event info (device specific)
+ * @context: passed context (our notification struct)
+ *
+ * Description: this method is registered as a callback with the ACPI
+ * subsystem it is called when this device has an event to notify the OS of
+ *
+ * The events actually come from the device as two events that get
+ * synthesized into one event with data by this function.  The event
+ * ID comes first and then the slot number that caused it.  We report
+ * this as one event to the OS.
+ *
+ * From section 5.6.2.2 of the ACPI 2.0 spec, I understand that the OSPM will
+ * only re-enable the interrupt that causes this event AFTER this method
+ * has returned, thereby enforcing serial access for the notification struct.
+ **/
+static void ibm_handle_events(acpi_handle handle, u32 event, void *context)
+{
+	u8 detail = event & 0x0f;
+	u8 subevent = event & 0xf0;
+	struct notification *note = context;
+
+	dbg("%s: Received notification %02x\n", __FUNCTION__, event);
+
+	if (subevent == 0x80) {
+		dbg("%s: generationg bus event\n", __FUNCTION__);
+		acpi_bus_generate_event(note->device, note->event, detail);
+	} else
+		note->event = event;
+}
+
+/**
+ * ibm_get_table_from_acpi - reads the APLS buffer from ACPI
+ * @bufp: address to pointer to allocate for the table
+ *
+ * Description: this method reads the APLS buffer in from ACPI and
+ * stores the "stripped" table into a single buffer
+ * it allocates and passes the address back in bufp
+ *
+ * If NULL is passed in as buffer, this method only calculates
+ * the size of the table and returns that without filling
+ * in the buffer
+ *
+ * returns < 0 on error or the size of the table on success
+ **/
+static int ibm_get_table_from_acpi(char **bufp)
+{
+	union acpi_object *package;
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	acpi_status status;
+	char *lbuf = NULL;
+	int i, size = -EIO;
+
+	status = acpi_evaluate_object(ibm_acpi_handle, "APCI", NULL, &buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  APCI evaluation failed\n", __FUNCTION__);
+		return -ENODEV;
+	}
+
+	package = (union acpi_object *) buffer.pointer;
+	if(!(package) ||
+			(package->type != ACPI_TYPE_PACKAGE) ||
+			!(package->package.elements)) {
+		err("%s:  Invalid APCI object\n", __FUNCTION__);
+		goto read_table_done;
+	}
+
+	for(size = 0, i = 0; i < package->package.count; i++) {
+		if (package->package.elements[i].type != ACPI_TYPE_BUFFER) {
+			err("%s:  Invalid APCI element %d\n", __FUNCTION__, i);
+			goto read_table_done;
+		}
+		size += package->package.elements[i].buffer.length;
+	}
+
+	if (bufp == NULL)
+		goto read_table_done;
+
+	lbuf = kmalloc(size, GFP_KERNEL);
+	dbg("%s: element count: %i, ASL table size: %i, &table = 0x%p\n",
+			__FUNCTION__, package->package.count, size, lbuf);
+
+	if (lbuf) {
+		*bufp = lbuf;
+		memset(lbuf, 0, size);
+	} else {
+		size = -ENOMEM;
+		goto read_table_done;
+	}
+
+	size = 0;
+	for (i=0; i<package->package.count; i++) {
+		memcpy(&lbuf[size],
+				package->package.elements[i].buffer.pointer,
+				package->package.elements[i].buffer.length);
+		size += package->package.elements[i].buffer.length;
+	}
+
+read_table_done:
+	kfree(buffer.pointer);
+	return size;
+}
+
+/**
+ * ibm_read_apci_table - callback for the sysfs apci_table file
+ * @kobj: the kobject this binary attribute is a part of
+ * @buffer: the kernel space buffer to fill
+ * @pos: the offset into the file
+ * @size: the number of bytes requested
+ *
+ * Description: gets registered with sysfs as the reader callback
+ * to be executed when /sys/bus/pci/slots/apci_table gets read
+ *
+ * Since we don't get notified on open and close for this file,
+ * things get really tricky here...
+ * our solution is to only allow reading the table in all at once
+ **/
+static ssize_t ibm_read_apci_table(struct kobject *kobj,
+		char *buffer, loff_t pos, size_t size)
+{
+	int bytes_read = -EINVAL;
+	char *table = NULL;
+	
+	dbg("%s: pos = %d, size = %d\n", __FUNCTION__, (int)pos, size);
+
+	if (pos == 0) {
+		bytes_read = ibm_get_table_from_acpi(&table);
+		if (bytes_read > 0 && bytes_read <= size)
+			memcpy(buffer, table, bytes_read);
+		kfree(table);
+	}
+	return bytes_read;
+}
+
+/**
+ * ibm_find_acpi_device - callback to find our ACPI device
+ * @handle: the ACPI handle of the device we are inspecting
+ * @lvl: depth into the namespace tree
+ * @context: a pointer to our handle to fill when we find the device
+ * @rv: a return value to fill if desired
+ *
+ * Description: used as a callback when calling acpi_walk_namespace
+ * to find our device.  When this method returns non-zero
+ * acpi_walk_namespace quits its search and returns our value
+ **/
+static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
+		u32 lvl, void *context, void **rv)
+{
+	acpi_handle *phandle = (acpi_handle *)context;
+	acpi_status status; 
+	struct acpi_device_info info; 
+	struct acpi_buffer info_buffer = {
+		.length = sizeof(struct acpi_device_info),
+		.pointer = &info,
+	};
+
+	status = acpi_get_object_info(handle, &info_buffer);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  Failed to get device information", __FUNCTION__);
+		return 0;
+	}
+	info.hardware_id.value[sizeof(info.hardware_id.value) - 1] = '\0';
+
+	if(info.current_status && (info.valid & ACPI_VALID_HID) &&
+			(!strcmp(info.hardware_id.value, IBM_HARDWARE_ID1) ||
+			!strcmp(info.hardware_id.value, IBM_HARDWARE_ID2))) {
+		dbg("found hardware: %s, handle: %x\n", info.hardware_id.value,
+				(unsigned int)handle);
+		*phandle = handle;
+		/* returning non-zero causes the search to stop
+		 * and returns this value to the caller of 
+		 * acpi_walk_namespace, but it also causes some warnings
+		 * in the acpi debug code to print...
+		 */
+		return FOUND_APCI;
+	}
+	return 0;
+}
+
+static int __init ibm_acpiphp_init(void)
+{
+	int retval = 0;
+	acpi_status status;
+	struct acpi_device *device;
+	struct kobject *sysdir = &pci_hotplug_slots_subsys.kset.kobj;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+			ACPI_UINT32_MAX, ibm_find_acpi_device,
+			&ibm_acpi_handle, NULL) != FOUND_APCI) {
+		err("%s: acpi_walk_namespace failed\n", __FUNCTION__);
+		retval = -ENODEV;
+		goto init_return;
+	}
+	dbg("%s: found IBM aPCI device\n", __FUNCTION__);
+	if (acpi_bus_get_device(ibm_acpi_handle, &device)) {
+		err("%s: acpi_bus_get_device failed\n", __FUNCTION__);
+		retval = -ENODEV;
+		goto init_return;
+	}
+	if (acpiphp_register_attention(&ibm_attention_info)) {
+		retval = -ENODEV;
+		goto init_return;
+	}
+
+	ibm_note.device = device;
+	status = acpi_install_notify_handler(
+			ibm_acpi_handle,
+			ACPI_DEVICE_NOTIFY,
+			ibm_handle_events,
+			&ibm_note);
+	if (ACPI_FAILURE(status)) {
+		err("%s:  Failed to register notification handler\n",
+				__FUNCTION__);
+		retval = -EBUSY;
+		goto init_cleanup;
+	}
+
+	ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
+	retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
+
+	return retval;
+
+init_cleanup:
+	acpiphp_unregister_attention(&ibm_attention_info);
+init_return:
+	return retval;
+}
+
+static void __exit ibm_acpiphp_exit(void)
+{
+	acpi_status status;
+	struct kobject *sysdir = &pci_hotplug_slots_subsys.kset.kobj;
+
+	dbg("%s\n", __FUNCTION__);
+
+	if (acpiphp_unregister_attention(&ibm_attention_info))
+		err("%s: attention info deregistration failed", __FUNCTION__);
+
+	   status = acpi_remove_notify_handler(
+			   ibm_acpi_handle,
+			   ACPI_DEVICE_NOTIFY,
+			   ibm_handle_events);
+	   if (ACPI_FAILURE(status))
+		   err("%s:  Notification handler removal failed\n",
+				   __FUNCTION__);
+	// remove the /sys entries
+	if (sysfs_remove_bin_file(sysdir, &ibm_apci_table_attr))
+		err("%s: removal of sysfs file apci_table failed\n",
+				__FUNCTION__);
+}
+
+module_init(ibm_acpiphp_init);
+module_exit(ibm_acpiphp_exit);



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] [1/2] acpiphp extension for 2.6.7 (final)
  2004-07-09  0:12           ` [PATCH] [1/2] " Vernon Mauery
@ 2004-07-14 22:52             ` Greg KH
  0 siblings, 0 replies; 19+ messages in thread
From: Greg KH @ 2004-07-14 22:52 UTC (permalink / raw)
  To: Vernon Mauery
  Cc: pcihpd, lkml, Greg KH, Pat Gaughen, Chris McDermott, Jess Botts

On Thu, Jul 08, 2004 at 05:12:36PM -0700, Vernon Mauery wrote:
> 01 - acpiphp-attention-v0.1e.patch
> 
>         This patch adds the ability to register callback functions with
>         the acpiphp core to set and get the current attention LED
>         status.  The reason this is needed is because there is not set
>         ACPI standard for how this is done so each hardware platform may
>         implement it differently.  To keep hardware specific code out of
>         acpiphp, we allow other modules to register their code with it.
> 
> 
>  acpiphp.h      |   16 +++++++
>  acpiphp_core.c |  127 ++++++++++++++++++++++++++++++++++++++++++++-------------
>  acpiphp_glue.c |   14 ------
>  3 files changed, 115 insertions(+), 42 deletions(-)
> 
> Signed-off-by: Vernon Mauery <vernux@us.ibm.com>

Applied, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] [2/2] acpiphp extension for 2.6.7 (final)
  2004-07-09  0:12           ` [PATCH] [2/2] " Vernon Mauery
@ 2004-07-14 22:52             ` Greg KH
  0 siblings, 0 replies; 19+ messages in thread
From: Greg KH @ 2004-07-14 22:52 UTC (permalink / raw)
  To: Vernon Mauery
  Cc: pcihpd, lkml, Greg KH, Pat Gaughen, Chris McDermott, Jess Botts

On Thu, Jul 08, 2004 at 05:12:43PM -0700, Vernon Mauery wrote:
> 02 - acpiphp_ibm-v1.0.1e.patch
> 
>         This patch adds the first driver that actually uses the callback
>         function for attention LEDs that the acpiphp-attention patch
>         adds.  It searches the ACPI namespace for IBM hardware, sets up
>         the callbacks and sets up a handler to read ACPI events and
>         forward them on to /proc/acpi/event.  It also exports an ACPI
>         table that shows current hotplug status to userland.
> 
> 
>  Kconfig       |   12 +
>  Makefile      |    1
>  acpiphp_ibm.c |  474 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 487 insertions(+)
> 
> Signed-off-by: Vernon Mauery <vernux@us.ibm.com>

Applied, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] acpiphp extension fixes for 2.6.9-rc2
       [not found]         ` <20040708232827.GA20755@kroah.com>
                             ` (2 preceding siblings ...)
  2004-07-09  0:12           ` [PATCH] [2/2] " Vernon Mauery
@ 2004-09-16 18:23           ` Vernon Mauery
  2004-09-17 22:10             ` Vernon Mauery
  3 siblings, 1 reply; 19+ messages in thread
From: Vernon Mauery @ 2004-09-16 18:23 UTC (permalink / raw)
  To: Greg KH; +Cc: pcihpd, lkml, Greg KH, Pat Gaughen, Chris McDermott, Jess Botts

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;
 }
 
 /**



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] acpiphp extension fixes for 2.6.9-rc2
  2004-09-16 18:23           ` [PATCH] acpiphp extension fixes for 2.6.9-rc2 Vernon Mauery
@ 2004-09-17 22:10             ` Vernon Mauery
  2004-09-22 20:29               ` Greg KH
  0 siblings, 1 reply; 19+ messages in thread
From: Vernon Mauery @ 2004-09-17 22:10 UTC (permalink / raw)
  To: Greg KH; +Cc: pcihpd, lkml, Greg KH, Pat Gaughen, Chris McDermott, Jess Botts

On Thu, 2004-09-16 at 11:23, Vernon Mauery wrote:
> This patch fixes an off by one error that one of the IBM machines that

I realized today that I had an off by one error myself.  I had one line
in the wrong place by one (i.e. accessing a pointer into the table after
calling kfree on the table).  So, please disregard the last patch and
apply this one instead.

For the record...

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 |  101 ++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 63 insertions(+), 38 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 08:33:58.000000000 -0700
+++ linux-2.6.9-rc2.avatar/drivers/pci/hotplug/acpiphp_ibm.c	2004-09-17 07:55:34.949356584 -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
@@ -84,6 +86,7 @@
 		u8  attn;
 		u8  status[2];
 		u8  sun;
+		u8  res[3];
 	} slot;
 	struct {
 		u8 type;
@@ -128,6 +131,43 @@
 	.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:
+	if (ret) {
+		ret = kmalloc(sizeof(union apci_descriptor), GFP_KERNEL);
+		memcpy(ret, des, sizeof(union apci_descriptor));
+	}
+	kfree(table);
+	return ret;
+}
 
 /**
  * ibm_set_attention_status - callback method to set the attention LED
@@ -139,32 +179,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 +223,21 @@
  **/
 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;
+	union apci_descriptor *ibm_slot;
 
-	acpi_slot = ((struct slot *)(slot->private))->acpi_slot;
+	ibm_slot = 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 (ibm_slot->slot.attn & 0xa0 || ibm_slot->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__,
+			ibm_slot->slot.slot_num, ibm_slot->slot.slot_id,
+			*status);
 
-get_attn_done:
-	kfree(table);
-	return retval;
+	kfree(ibm_slot);
+	return 0;
 }
 
 /**



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] acpiphp extension fixes for 2.6.9-rc2
  2004-09-17 22:10             ` Vernon Mauery
@ 2004-09-22 20:29               ` Greg KH
  0 siblings, 0 replies; 19+ messages in thread
From: Greg KH @ 2004-09-22 20:29 UTC (permalink / raw)
  To: Vernon Mauery
  Cc: pcihpd, lkml, Greg KH, Pat Gaughen, Chris McDermott, Jess Botts

On Fri, Sep 17, 2004 at 03:10:03PM -0700, Vernon Mauery wrote:
> On Thu, 2004-09-16 at 11:23, Vernon Mauery wrote:
> > This patch fixes an off by one error that one of the IBM machines that
> 
> I realized today that I had an off by one error myself.  I had one line
> in the wrong place by one (i.e. accessing a pointer into the table after
> calling kfree on the table).  So, please disregard the last patch and
> apply this one instead.
> 
> For the record...
> 
> 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 |  101 ++++++++++++++++++++++++++++++++++++----------------------
>  1 files changed, 63 insertions(+), 38 deletions(-)
> 
> Signed-off-by: Vernon Mauery <vernux@us.ibm.com>

Applied, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2004-09-22 20:30 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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           ` [PATCH] acpiphp extension fixes for 2.6.9-rc2 Vernon Mauery
2004-09-17 22:10             ` Vernon Mauery
2004-09-22 20:29               ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox