SOURCES (LINUX_2_6_17): linux-2.6.17-ide-acpi-support.patch (NEW) ...

mguevara mguevara at pld-linux.org
Mon Oct 23 14:06:21 CEST 2006


Author: mguevara                     Date: Mon Oct 23 12:06:21 2006 GMT
Module: SOURCES                       Tag: LINUX_2_6_17
---- Log message:
- http://svn.uludag.org.tr/pardus/devel/kernel/kernel/files/suse/ide-acpi-support.patch
  to replace old nx8220 suspend hack - will be bconded and will appear in the 
  LINUX_2_6_17 after successfull tests on a test machine.
  Taken from SuSE, but is included in Ubuntu from 2.6.15

---- Files affected:
SOURCES:
   linux-2.6.17-ide-acpi-support.patch (NONE -> 1.1.2.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/linux-2.6.17-ide-acpi-support.patch
diff -u /dev/null SOURCES/linux-2.6.17-ide-acpi-support.patch:1.1.2.1
--- /dev/null	Mon Oct 23 14:06:21 2006
+++ SOURCES/linux-2.6.17-ide-acpi-support.patch	Mon Oct 23 14:06:16 2006
@@ -0,0 +1,915 @@
+From: Hannes Reinecke <hare at suse.de>
+Subject: ACPI support for IDE devices
+References: 145591 - FATE #151275
+
+This patch implements ACPI integration for generic IDE devices.
+The ACPI spec mandates that some methods are called during suspend and
+resume. And consequently there most modern Laptops cannot resume
+properly without it.
+
+According to the spec, we should call '_GTM' (Get Timing) upon suspend
+to store the current IDE adapter settings.
+Upon resume we should call '_STM' (Set Timing) to initialize the
+adapter with the stored settings; afterwards '_GTF' (Get Taskfile)
+should be called which returns a buffer with some IDE initialisation
+commands. Those commands should be passed to the drive.
+
+There are two module params which control the behaviour of this patch:
+
+'ide=noacpi'
+	Do not call any ACPI methods (Disables any ACPI method calls)
+'ide=acpigtf'
+	Enable execution of _GTF methods upon resume.
+	Has no effect if 'ide=noacpi' is set.
+'ide=acpionboot'
+	Enable execution of ACPI methods during boot.
+	This might be required on some machines if 'ide=acpigtf' is
+	selected as some machines modify the _GTF information
+	depending on the drive identification passed down with _STM.
+
+Signed-off-by: Hannes Reinecke <hare at suse.de>
+
+---
+ drivers/ide/Kconfig     |    7 
+ drivers/ide/Makefile    |    1 
+ drivers/ide/ide-acpi.c  |  696 ++++++++++++++++++++++++++++++++++++++++++++++++
+ drivers/ide/ide-probe.c |    3 
+ drivers/ide/ide.c       |   36 ++
+ include/linux/ide.h     |   27 +
+ 6 files changed, 770 insertions(+)
+
+--- linux-2.6.17.orig/drivers/ide/Kconfig
++++ linux-2.6.17/drivers/ide/Kconfig
+@@ -262,6 +262,13 @@ config BLK_DEV_IDESCSI
+ 	  If both this SCSI emulation and native ATAPI support are compiled
+ 	  into the kernel, the native support will be used.
+ 
++config BLK_DEV_IDEACPI
++	bool "IDE ACPI support"
++	depends on ACPI
++	---help---
++	  Implement ACPI support for generic IDE devices. On modern
++	  machines ACPI support is required to properly handle ACPI S3 states.
++
+ config IDE_TASK_IOCTL
+ 	bool "IDE Taskfile Access"
+ 	help
+--- linux-2.6.17.orig/drivers/ide/Makefile
++++ linux-2.6.17/drivers/ide/Makefile
+@@ -22,6 +22,7 @@ ide-core-$(CONFIG_BLK_DEV_IDEPCI)	+= set
+ ide-core-$(CONFIG_BLK_DEV_IDEDMA)	+= ide-dma.o
+ ide-core-$(CONFIG_PROC_FS)		+= ide-proc.o
+ ide-core-$(CONFIG_BLK_DEV_IDEPNP)	+= ide-pnp.o
++ide-core-$(CONFIG_BLK_DEV_IDEACPI)	+= ide-acpi.o
+ 
+ # built-in only drivers from arm/
+ ide-core-$(CONFIG_IDE_ARM)		+= arm/ide_arm.o
+--- /dev/null
++++ linux-2.6.17/drivers/ide/ide-acpi.c
+@@ -0,0 +1,696 @@
++/*
++ * ide-acpi.c
++ * Provides ACPI support for IDE drives.
++ *
++ * Copyright (C) 2005 Intel Corp.
++ * Copyright (C) 2005 Randy Dunlap
++ * Copyright (C) 2006 SUSE Linux Products GmbH
++ * Copyright (C) 2006 Hannes Reinecke
++ */
++
++#include <linux/ata.h>
++#include <linux/delay.h>
++#include <linux/device.h>
++#include <linux/errno.h>
++#include <linux/kernel.h>
++#include <acpi/acpi.h>
++#include <linux/ide.h>
++#include <linux/pci.h>
++
++#include <acpi/acpi_bus.h>
++#include <acpi/acnames.h>
++#include <acpi/acnamesp.h>
++#include <acpi/acparser.h>
++#include <acpi/acexcep.h>
++#include <acpi/acmacros.h>
++#include <acpi/actypes.h>
++
++#define REGS_PER_GTF		7
++struct taskfile_array {
++	u8	tfa[REGS_PER_GTF];	/* regs. 0x1f1 - 0x1f7 */
++};
++
++struct GTM_buffer {
++	u32	PIO_speed0;
++	u32	DMA_speed0;
++	u32	PIO_speed1;
++	u32	DMA_speed1;
++	u32	GTM_flags;
++};
++
++struct ide_acpi_drive_link {
++	ide_drive_t	*drive;
++	acpi_handle	 obj_handle;
++	u8		 idbuff[512];
++};
++
++struct ide_acpi_hwif_link {
++	ide_hwif_t			*hwif;
++	acpi_handle			 obj_handle;
++	struct GTM_buffer		 gtm;
++	struct ide_acpi_drive_link	 master;
++	struct ide_acpi_drive_link	 slave;
++};
++
++#undef DEBUGGING
++/* note: adds function name and KERN_DEBUG */
++#ifdef DEBUGGING
++#define DEBPRINT(fmt, args...)	\
++		printk(KERN_DEBUG "%s: " fmt, __FUNCTION__, ## args)
++#else
++#define DEBPRINT(fmt, args...)	do {} while (0)
++#endif	/* DEBUGGING */
++
++extern int ide_noacpi;
++extern int ide_noacpitfs;
++extern int ide_noacpionboot;
++
++/**
++ * ide_get_dev_handle - finds acpi_handle and PCI device.function
++ * @dev: device to locate
++ * @handle: returned acpi_handle for @dev
++ * @pcidevfn: return PCI device.func for @dev
++ *
++ * Returns the ACPI object handle to the corresponding PCI device.
++ *
++ * Returns 0 on success, <0 on error.
++ */
++static int ide_get_dev_handle(struct device *dev, acpi_handle *handle,
++			       acpi_integer *pcidevfn)
++{
++	struct pci_dev *pdev = to_pci_dev(dev);
++	unsigned int bus, devnum, func;
++	acpi_integer addr;
++	acpi_handle dev_handle;
++	struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER,
++					.pointer = NULL};
++	acpi_status status;
++	struct acpi_device_info	*dinfo = NULL;
++	int ret = -ENODEV;
++
++	bus = pdev->bus->number;
++	devnum = PCI_SLOT(pdev->devfn);
++	func = PCI_FUNC(pdev->devfn);
++	/* ACPI _ADR encoding for PCI bus: */
++	addr = (acpi_integer)(devnum << 16 | func);
++
++	DEBPRINT("ENTER: pci %02x:%02x.%01x\n", bus, devnum, func);
++
++	dev_handle = DEVICE_ACPI_HANDLE(dev);
++	if (!dev_handle) {
++		DEBPRINT("no acpi handle for device\n");
++		goto err;
++	}
++
++	status = acpi_get_object_info(dev_handle, &buffer);
++	if (ACPI_FAILURE(status)) {
++		DEBPRINT("get_object_info for device failed\n");
++		goto err;
++	}
++	dinfo = buffer.pointer;
++	if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
++	    dinfo->address == addr) {
++		*pcidevfn = addr;
++		*handle = dev_handle;
++	} else {
++		DEBPRINT("get_object_info for device has wrong "
++			" address: %llu, should be %u\n",
++			dinfo ? (unsigned long long)dinfo->address : -1ULL,
++			(unsigned int)addr);
++		goto err;
++	}
++
++	DEBPRINT("for dev=0x%x.%x, addr=0x%llx, *handle=0x%p\n",
++		 devnum, func, (unsigned long long)addr, *handle);
++	ret = 0;
++err:
++	kfree(dinfo);
++	return ret;
++}
++
++/**
++ * ide_acpi_hwif_get_handle - Get ACPI object handle for a given hwif
++ * @hwif: device to locate
++ *
++ * Retrieves the object handle for a given hwif.
++ *
++ * Returns handle on success, 0 on error.
++ */
++static acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif)
++{
++	struct device		*dev = hwif->gendev.parent;
++	acpi_handle		dev_handle;
++	acpi_integer		pcidevfn;
++	acpi_handle		chan_handle;
++	int			err;
++
++	DEBPRINT("ENTER: device %s\n", hwif->name);
++
++	if (!dev) {
++		DEBPRINT("no PCI device for %s\n", hwif->name);
++		return NULL;
++	}
++
++	err = ide_get_dev_handle(dev, &dev_handle, &pcidevfn);
++	if (err < 0) {
++		DEBPRINT("ide_get_dev_handle failed (%d)\n", err);
++		return NULL;
++	}
++
++	/* get child objects of dev_handle == channel objects,
++	 * + _their_ children == drive objects */
++	/* channel is hwif->channel */
++	chan_handle = acpi_get_child(dev_handle, hwif->channel);
++	DEBPRINT("chan adr=%d: handle=0x%p\n",
++		 hwif->channel, chan_handle);
++
++	return chan_handle;
++}
++
++/**
++ * ide_acpi_drive_get_handle - Get ACPI object handle for a given drive
++ * @drive: device to locate
++ *
++ * Retrieves the object handle of a given drive. According to the ACPI
++ * spec the drive is a child of the hwif.
++ *
++ * Returns handle on success, 0 on error.
++ */
++static acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive)
++{
++	ide_hwif_t	*hwif = HWIF(drive);
++	int		 port;
++	acpi_handle	 drive_handle;
++
++	if (!hwif->acpidata)
++		return NULL;
++
++	if (!hwif->acpidata->obj_handle)
++		return NULL;
++
++	port = hwif->channel ? drive->dn - 2: drive->dn;
++
++	DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
++		 drive->name, hwif->channel, port);
++
++
++	/* TBD: could also check ACPI object VALID bits */
++	drive_handle = acpi_get_child(hwif->acpidata->obj_handle, port);
++	DEBPRINT("drive %s handle 0x%p\n", drive->name, drive_handle);
++
++	return drive_handle;
++}
++
++/**
++ * do_drive_get_GTF - get the drive bootup default taskfile settings
++ * @drive: the drive for which the taskfile settings should be retrieved
++ * @gtf_length: number of bytes of _GTF data returned at @gtf_address
++ * @gtf_address: buffer containing _GTF taskfile arrays
++ *
++ * The _GTF method has no input parameters.
++ * It returns a variable number of register set values (registers
++ * hex 1F1..1F7, taskfiles).
++ * The <variable number> is not known in advance, so have ACPI-CA
++ * allocate the buffer as needed and return it, then free it later.
++ *
++ * The returned @gtf_length and @gtf_address are only valid if the
++ * function return value is 0.
++ */
++static int do_drive_get_GTF(ide_drive_t *drive,
++		     unsigned int *gtf_length, unsigned long *gtf_address,
++		     unsigned long *obj_loc)
++{
++	acpi_status			status;
++	struct acpi_buffer		output;
++	union acpi_object 		*out_obj;
++	ide_hwif_t			*hwif = HWIF(drive);
++	struct device			*dev = hwif->gendev.parent;
++	int				err = -ENODEV;
++	int				port;
++
++	*gtf_length = 0;
++	*gtf_address = 0UL;
++	*obj_loc = 0UL;
++
++	if (ide_noacpi)
++		return 0;
++
++	if (!dev) {
++		DEBPRINT("no PCI device for %s\n", hwif->name);
++		goto out;
++	}
++
++	if (!hwif->acpidata) {
++		DEBPRINT("no ACPI data for %s\n", hwif->name);
++		goto out;
++	}
++
++	port = hwif->channel ? drive->dn - 2: drive->dn;
++
++	if (!drive->acpidata) {
++		if (port == 0) {
++			drive->acpidata = &hwif->acpidata->master;
++			hwif->acpidata->master.drive = drive;
++		} else {
++			drive->acpidata = &hwif->acpidata->slave;
++			hwif->acpidata->slave.drive = drive;
++		}
++	}
++
++	DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
++		 hwif->name, dev->bus_id, port, hwif->channel);
++
++	if (!drive->present) {
++		DEBPRINT("%s drive %d:%d not present\n",
++			 hwif->name, hwif->channel, port);
++		goto out;
++	}
++
++	/* Get this drive's _ADR info. if not already known. */
++	if (!drive->acpidata->obj_handle) {
++		drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
++		if (!drive->acpidata->obj_handle) {
++			DEBPRINT("No ACPI object found for %s\n",
++				 drive->name);
++			goto out;
++		}
++	}
++
++	/* Setting up output buffer */
++	output.length = ACPI_ALLOCATE_BUFFER;
++	output.pointer = NULL;	/* ACPI-CA sets this; save/free it later */
++
++	/* _GTF has no input parameters */
++	err = -EIO;
++	status = acpi_evaluate_object(drive->acpidata->obj_handle, "_GTF",
++				      NULL, &output);
++	if (ACPI_FAILURE(status)) {
++		printk(KERN_DEBUG
++		       "%s: Run _GTF error: status = 0x%x\n",
++		       __FUNCTION__, status);
++		goto out;
++	}
++
++	if (!output.length || !output.pointer) {
++		DEBPRINT("Run _GTF: "
++		       "length or ptr is NULL (0x%llx, 0x%p)\n",
++		       (unsigned long long)output.length,
++		       output.pointer);
++		goto out;
++	}
++
++	out_obj = output.pointer;
++	if (out_obj->type != ACPI_TYPE_BUFFER) {
++		DEBPRINT("Run _GTF: error: "
++		       "expected object type of ACPI_TYPE_BUFFER, "
++		       "got 0x%x\n", out_obj->type);
++		err = -ENOENT;
++		kfree(output.pointer);
++		goto out;
++	}
++
++	if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
++	    out_obj->buffer.length % REGS_PER_GTF) {
++		printk(KERN_ERR
++		       "%s: unexpected GTF length (%d) or addr (0x%p)\n",
++		       __FUNCTION__, out_obj->buffer.length,
++		       out_obj->buffer.pointer);
++		err = -ENOENT;
++		kfree(output.pointer);
++		goto out;
++	}
++
++	*gtf_length = out_obj->buffer.length;
++	*gtf_address = (unsigned long)out_obj->buffer.pointer;
++	*obj_loc = (unsigned long)out_obj;
++	DEBPRINT("returning gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
++		 *gtf_length, *gtf_address, *obj_loc);
++	err = 0;
++out:
++	return err;
++}
++
++/**
++ * taskfile_load_raw - send taskfile registers to drive
++ * @drive: drive to which output is sent
++ * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
++ *
++ * Outputs IDE taskfile to the drive.
++ */
++static int taskfile_load_raw(ide_drive_t *drive,
++			      const struct taskfile_array *gtf)
++{
++	ide_task_t args;
++	int err = 0;
++
++	DEBPRINT("(0x1f1-1f7): hex: "
++	       "%02x %02x %02x %02x %02x %02x %02x\n",
++	       gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
++	       gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
++
++	memset(&args, 0, sizeof(ide_task_t));
++	args.command_type = IDE_DRIVE_TASK_NO_DATA;
++	args.data_phase   = TASKFILE_IN;
++	args.handler      = &task_no_data_intr;
++
++	/* convert gtf to IDE Taskfile */
++	args.tfRegister[1] = gtf->tfa[0];	/* 0x1f1 */
++	args.tfRegister[2] = gtf->tfa[1];	/* 0x1f2 */
++	args.tfRegister[3] = gtf->tfa[2];	/* 0x1f3 */
++	args.tfRegister[4] = gtf->tfa[3];	/* 0x1f4 */
++	args.tfRegister[5] = gtf->tfa[4];	/* 0x1f5 */
++	args.tfRegister[6] = gtf->tfa[5];	/* 0x1f6 */
++	args.tfRegister[7] = gtf->tfa[6];	/* 0x1f7 */
++
++	if (ide_noacpitfs) {
++		DEBPRINT("_GTF execution disabled\n");
++		return err;
++	}
++
++	err = ide_raw_taskfile(drive, &args, NULL);
++	if (err)
++		printk(KERN_ERR "%s: ide_raw_taskfile failed: %u\n",
++		       __FUNCTION__, err);
++
++	return err;
++}
++
++/**
++ * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
++ * @drive: the drive to which the taskfile command should be sent
++ * @gtf_length: total number of bytes of _GTF taskfiles
++ * @gtf_address: location of _GTF taskfile arrays
++ *
++ * Write {gtf_address, length gtf_length} in groups of
++ * REGS_PER_GTF bytes.
++ */
++static int do_drive_set_taskfiles(ide_drive_t *drive,
++				  unsigned int gtf_length,
++				  unsigned long gtf_address)
++{
++	int			rc = -ENODEV, err;
++	int			gtf_count = gtf_length / REGS_PER_GTF;
++	int			ix;
++	struct taskfile_array	*gtf;
++
++	if (ide_noacpi)
++		return 0;
++
++	DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
++
++	if (!drive->present)
++		goto out;
++	if (!gtf_count)		/* shouldn't be here */
++		goto out;
++
++	DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n",
++		 gtf_length, gtf_length, gtf_count, gtf_address);
++
++	if (gtf_length % REGS_PER_GTF) {
++		printk(KERN_ERR "%s: unexpected GTF length (%d)\n",
++		       __FUNCTION__, gtf_length);
++		goto out;
++	}
++
++	rc = 0;
++	for (ix = 0; ix < gtf_count; ix++) {
++		gtf = (struct taskfile_array *)
++			(gtf_address + ix * REGS_PER_GTF);
++
++		/* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
++		err = taskfile_load_raw(drive, gtf);
++		if (err)
++			rc = err;
++	}
++
++out:
++	return rc;
++}
++
++/**
++ * ide_acpi_exec_tfs - get then write drive taskfile settings
++ * @drive: the drive for which the taskfile settings should be
++ *         written.
++ *
++ * According to the ACPI spec this should be called after _STM
++ * has been evaluated for the interface. Some ACPI vendors interpret
++ * that as a hard requirement and modify the taskfile according
++ * to the Identify Drive information passed down with _STM.
++ * So one should really make sure to call this only after _STM has
++ * been executed.
++ */
++int ide_acpi_exec_tfs(ide_drive_t *drive)
++{
++	int		ret;
++	unsigned int	gtf_length;
++	unsigned long	gtf_address;
++	unsigned long	obj_loc;
++
++	if (ide_noacpi)
++		return 0;
++
++	DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn);
++
++	ret = do_drive_get_GTF(drive, &gtf_length, &gtf_address, &obj_loc);
++	if (ret < 0) {
++		DEBPRINT("get_GTF error (%d)\n", ret);
++		return ret;
++	}
++
++	DEBPRINT("call set_taskfiles, drive=%s\n", drive->name);
++
++	ret = do_drive_set_taskfiles(drive, gtf_length, gtf_address);
++	kfree((void *)obj_loc);
++	if (ret < 0) {
++		DEBPRINT("set_taskfiles error (%d)\n", ret);
++	}
++
++	DEBPRINT("ret=%d\n", ret);
++
++	return ret;
++}
++EXPORT_SYMBOL_GPL(ide_acpi_exec_tfs);
++
++/**
++ * ide_acpi_get_timing - get the channel (controller) timings
++ * @hwif: target IDE interface (channel)
++ *
++ * This function executes the _GTM ACPI method for the target channel.
++ *
++ */
++void ide_acpi_get_timing(ide_hwif_t *hwif)
++{
++	acpi_status		status;
++	struct acpi_buffer	output;
++	union acpi_object 	*out_obj;
++
++	if (ide_noacpi)
++		return;
++
++	DEBPRINT("ENTER:\n");
++
++	if (!hwif->acpidata) {
++		DEBPRINT("no ACPI data for %s\n", hwif->name);
++		return;
++	}
++
++	/* Setting up output buffer for _GTM */
++	output.length = ACPI_ALLOCATE_BUFFER;
++	output.pointer = NULL;	/* ACPI-CA sets this; save/free it later */
++
++	/* _GTM has no input parameters */
++	status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_GTM",
++				      NULL, &output);
++
++	DEBPRINT("_GTM status: %d, outptr: 0x%p, outlen: 0x%llx\n",
++		 status, output.pointer,
++		 (unsigned long long)output.length);
++
++	if (ACPI_FAILURE(status)) {
++		DEBPRINT("Run _GTM error: status = 0x%x\n", status);
++		return;
++	}
++
++	if (!output.length || !output.pointer) {
++		DEBPRINT("Run _GTM: length or ptr is NULL (0x%llx, 0x%p)\n",
++		       (unsigned long long)output.length,
++		       output.pointer);
++		kfree(output.pointer);
++		return;
++	}
++
++	out_obj = output.pointer;
<<Diff was trimmed, longer than 597 lines>>


More information about the pld-cvs-commit mailing list