Commit 4700c4bc authored by Tejun Heo's avatar Tejun Heo Committed by Jeff Garzik

libata-acpi: clean up ata_acpi_exec_tfs()

This patch cleans up ata_acpi_exec_tfs() and its friends.

* Rename taskfile_array to ata_acpi_gtf and make it __packed as it's
  used as argument to ACPI method, and use pointer to ata_acpi_gtf and
  number of taskfiles to represent _GTF taskfiles instead of a pointer
  casted into unsigned long and byte count.  This makes argument
  re-checking in do_drive_set_taskfiles() unnecessary.

* Pointer in void * not in unsigned long.

* Clean up do_drive_get_GTF() error handling and make
  do_drive_get_GTF() return number of taskfiles on success, 0 if _GTF
  doesn't exist or doesn't contain valid ata.  -errno on other errors.

* Remove superflous check for acpi->buffer.pointer.

* Update taskfile_load_raw() such that printed messages look similar
  to the messages printed by ata_eh_report().

* s/do_drive_get_GTF/ata_dev_get_GTF/
  s/do_drive_set_taskfiles/ata_dev_set_taskfiles/
Signed-off-by: default avatarTejun Heo <htejun@gmail.com>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent fafbae87
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
#define SATA_ADR(root,pmp) (((root) << 16) | (pmp)) #define SATA_ADR(root,pmp) (((root) << 16) | (pmp))
#define REGS_PER_GTF 7 #define REGS_PER_GTF 7
struct taskfile_array { struct ata_acpi_gtf {
u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */ u8 tf[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
}; } __packed;
/* /*
* Helper - belongs in the PCI layer somewhere eventually * Helper - belongs in the PCI layer somewhere eventually
...@@ -101,10 +101,10 @@ void ata_acpi_associate(struct ata_host *host) ...@@ -101,10 +101,10 @@ void ata_acpi_associate(struct ata_host *host)
} }
/** /**
* do_drive_get_GTF - get the drive bootup default taskfile settings * ata_dev_get_GTF - get the drive bootup default taskfile settings
* @dev: target ATA device * @dev: target ATA device
* @gtf_length: number of bytes of _GTF data returned at @gtf_address * @gtf: output parameter for buffer containing _GTF taskfile arrays
* @gtf_address: buffer containing _GTF taskfile arrays * @ptr_to_free: pointer which should be freed
* *
* This applies to both PATA and SATA drives. * This applies to both PATA and SATA drives.
* *
...@@ -114,24 +114,28 @@ void ata_acpi_associate(struct ata_host *host) ...@@ -114,24 +114,28 @@ void ata_acpi_associate(struct ata_host *host)
* The <variable number> is not known in advance, so have ACPI-CA * The <variable number> is not known in advance, so have ACPI-CA
* allocate the buffer as needed and return it, then free it later. * allocate the buffer as needed and return it, then free it later.
* *
* The returned @gtf_length and @gtf_address are only valid if the * LOCKING:
* function return value is 0. * EH context.
*
* RETURNS:
* Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't
* contain valid data. -errno on other errors.
*/ */
static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length, static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
unsigned long *gtf_address, unsigned long *obj_loc) void **ptr_to_free)
{ {
struct ata_port *ap = dev->ap; struct ata_port *ap = dev->ap;
acpi_status status; acpi_status status;
struct acpi_buffer output; struct acpi_buffer output;
union acpi_object *out_obj; union acpi_object *out_obj;
int err = -ENODEV; int rc = 0;
*gtf_length = 0; /* set up output buffer */
*gtf_address = 0UL; output.length = ACPI_ALLOCATE_BUFFER;
*obj_loc = 0UL; output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
if (!dev->acpi_handle) if (!dev->acpi_handle)
return 0; goto out_free;
if (ata_msg_probe(ap)) if (ata_msg_probe(ap))
ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n", ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
...@@ -143,23 +147,20 @@ static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length, ...@@ -143,23 +147,20 @@ static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length,
"ata_dev_present: %d, PORT_DISABLED: %lu\n", "ata_dev_present: %d, PORT_DISABLED: %lu\n",
__FUNCTION__, ata_dev_enabled(dev), __FUNCTION__, ata_dev_enabled(dev),
ap->flags & ATA_FLAG_DISABLED); ap->flags & ATA_FLAG_DISABLED);
goto out; goto out_free;
} }
/* 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 */ /* _GTF has no input parameters */
err = -EIO; status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output);
status = acpi_evaluate_object(dev->acpi_handle, "_GTF",
NULL, &output);
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
if (ata_msg_probe(ap)) if (status != AE_NOT_FOUND) {
ata_dev_printk(dev, KERN_DEBUG, ata_dev_printk(dev, KERN_WARNING,
"%s: Run _GTF error: status = 0x%x\n", "_GTF evaluation failed (AE 0x%x)\n",
__FUNCTION__, status); status);
goto out; rc = -EIO;
}
goto out_free;
} }
if (!output.length || !output.pointer) { if (!output.length || !output.pointer) {
...@@ -169,43 +170,43 @@ static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length, ...@@ -169,43 +170,43 @@ static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length,
__FUNCTION__, __FUNCTION__,
(unsigned long long)output.length, (unsigned long long)output.length,
output.pointer); output.pointer);
kfree(output.pointer); goto out_free;
goto out;
} }
out_obj = output.pointer; out_obj = output.pointer;
if (out_obj->type != ACPI_TYPE_BUFFER) { if (out_obj->type != ACPI_TYPE_BUFFER) {
kfree(output.pointer);
if (ata_msg_probe(ap)) if (ata_msg_probe(ap))
ata_dev_printk(dev, KERN_DEBUG, "%s: Run _GTF: " ata_dev_printk(dev, KERN_DEBUG, "%s: Run _GTF: "
"error: expected object type of " "error: expected object type of "
" ACPI_TYPE_BUFFER, got 0x%x\n", " ACPI_TYPE_BUFFER, got 0x%x\n",
__FUNCTION__, out_obj->type); __FUNCTION__, out_obj->type);
err = -ENOENT; rc = -EINVAL;
goto out; goto out_free;
} }
if (!out_obj->buffer.length || !out_obj->buffer.pointer || if (out_obj->buffer.length % REGS_PER_GTF) {
out_obj->buffer.length % REGS_PER_GTF) {
if (ata_msg_drv(ap)) if (ata_msg_drv(ap))
ata_dev_printk(dev, KERN_ERR, ata_dev_printk(dev, KERN_ERR,
"%s: unexpected GTF length (%d) or addr (0x%p)\n", "%s: unexpected GTF length (%d) or addr (0x%p)\n",
__FUNCTION__, out_obj->buffer.length, __FUNCTION__, out_obj->buffer.length,
out_obj->buffer.pointer); out_obj->buffer.pointer);
err = -ENOENT; rc = -EINVAL;
goto out; goto out_free;
} }
*gtf_length = out_obj->buffer.length; *ptr_to_free = out_obj;
*gtf_address = (unsigned long)out_obj->buffer.pointer; *gtf = (void *)out_obj->buffer.pointer;
*obj_loc = (unsigned long)out_obj; rc = out_obj->buffer.length / REGS_PER_GTF;
if (ata_msg_probe(ap)) if (ata_msg_probe(ap))
ata_dev_printk(dev, KERN_DEBUG, "%s: returning " ata_dev_printk(dev, KERN_DEBUG, "%s: returning "
"gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n", "gtf=%p, gtf_count=%d, ptr_to_free=%p\n",
__FUNCTION__, *gtf_length, *gtf_address, *obj_loc); __FUNCTION__, *gtf, rc, *ptr_to_free);
err = 0; return rc;
out:
return err; out_free:
kfree(output.pointer);
return rc;
} }
/** /**
...@@ -224,68 +225,78 @@ out: ...@@ -224,68 +225,78 @@ out:
* function also waits for idle after writing control and before * function also waits for idle after writing control and before
* writing the remaining registers. * writing the remaining registers.
* *
* LOCKING: TBD: * LOCKING:
* Inherited from caller. * EH context.
*
* RETURNS:
* 0 on success, -errno on failure.
*/ */
static void taskfile_load_raw(struct ata_device *dev, static int taskfile_load_raw(struct ata_device *dev,
const struct taskfile_array *gtf) const struct ata_acpi_gtf *gtf)
{ {
struct ata_port *ap = dev->ap; struct ata_port *ap = dev->ap;
struct ata_taskfile tf; struct ata_taskfile tf, rtf;
unsigned int err; unsigned int err_mask;
if (ata_msg_probe(ap))
ata_dev_printk(dev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: "
"%02x %02x %02x %02x %02x %02x %02x\n",
__FUNCTION__,
gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
if ((gtf->tfa[0] == 0) && (gtf->tfa[1] == 0) && (gtf->tfa[2] == 0) if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0)
&& (gtf->tfa[3] == 0) && (gtf->tfa[4] == 0) && (gtf->tfa[5] == 0) && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0)
&& (gtf->tfa[6] == 0)) && (gtf->tf[6] == 0))
return; return 0;
ata_tf_init(dev, &tf); ata_tf_init(dev, &tf);
/* convert gtf to tf */ /* convert gtf to tf */
tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */ tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */
tf.protocol = ATA_PROT_NODATA; tf.protocol = ATA_PROT_NODATA;
tf.feature = gtf->tfa[0]; /* 0x1f1 */ tf.feature = gtf->tf[0]; /* 0x1f1 */
tf.nsect = gtf->tfa[1]; /* 0x1f2 */ tf.nsect = gtf->tf[1]; /* 0x1f2 */
tf.lbal = gtf->tfa[2]; /* 0x1f3 */ tf.lbal = gtf->tf[2]; /* 0x1f3 */
tf.lbam = gtf->tfa[3]; /* 0x1f4 */ tf.lbam = gtf->tf[3]; /* 0x1f4 */
tf.lbah = gtf->tfa[4]; /* 0x1f5 */ tf.lbah = gtf->tf[4]; /* 0x1f5 */
tf.device = gtf->tfa[5]; /* 0x1f6 */ tf.device = gtf->tf[5]; /* 0x1f6 */
tf.command = gtf->tfa[6]; /* 0x1f7 */ tf.command = gtf->tf[6]; /* 0x1f7 */
err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0); if (ata_msg_probe(ap))
if (err && ata_msg_probe(ap)) ata_dev_printk(dev, KERN_DEBUG, "executing ACPI cmd "
"%02x/%02x:%02x:%02x:%02x:%02x:%02x\n",
tf.command, tf.feature, tf.nsect,
tf.lbal, tf.lbam, tf.lbah, tf.device);
rtf = tf;
err_mask = ata_exec_internal(dev, &rtf, NULL, DMA_NONE, NULL, 0);
if (err_mask) {
ata_dev_printk(dev, KERN_ERR, ata_dev_printk(dev, KERN_ERR,
"%s: ata_exec_internal failed: %u\n", "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x failed "
__FUNCTION__, err); "(Emask=0x%x Stat=0x%02x Err=0x%02x)\n",
tf.command, tf.feature, tf.nsect, tf.lbal, tf.lbam,
tf.lbah, tf.device, err_mask, rtf.command, rtf.feature);
return -EIO;
}
return 0;
} }
/** /**
* do_drive_set_taskfiles - write the drive taskfile settings from _GTF * ata_dev_set_taskfiles - write the drive taskfile settings from _GTF
* @dev: target ATA device * @dev: target ATA device
* @gtf_length: total number of bytes of _GTF taskfiles * @gtf: pointer to array of _GTF taskfiles to execute
* @gtf_address: location of _GTF taskfile arrays * @gtf_count: number of taskfiles
* *
* This applies to both PATA and SATA drives. * This applies to both PATA and SATA drives.
* *
* Write {gtf_address, length gtf_length} in groups of * Execute taskfiles in @gtf.
* REGS_PER_GTF bytes. *
* LOCKING:
* EH context.
*
* RETURNS:
* 0 on success, -errno on failure.
*/ */
static int do_drive_set_taskfiles(struct ata_device *dev, static int ata_dev_set_taskfiles(struct ata_device *dev,
unsigned int gtf_length, struct ata_acpi_gtf *gtf, int gtf_count)
unsigned long gtf_address)
{ {
struct ata_port *ap = dev->ap; struct ata_port *ap = dev->ap;
int err = -ENODEV;
int gtf_count = gtf_length / REGS_PER_GTF;
int ix; int ix;
struct taskfile_array *gtf;
if (ata_msg_probe(ap)) if (ata_msg_probe(ap))
ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n", ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
...@@ -295,29 +306,13 @@ static int do_drive_set_taskfiles(struct ata_device *dev, ...@@ -295,29 +306,13 @@ static int do_drive_set_taskfiles(struct ata_device *dev,
return 0; return 0;
if (!ata_dev_enabled(dev) || (ap->flags & ATA_FLAG_DISABLED)) if (!ata_dev_enabled(dev) || (ap->flags & ATA_FLAG_DISABLED))
goto out; return -ENODEV;
if (!gtf_count) /* shouldn't be here */
goto out;
if (gtf_length % REGS_PER_GTF) {
if (ata_msg_drv(ap))
ata_dev_printk(dev, KERN_ERR,
"%s: unexpected GTF length (%d)\n",
__FUNCTION__, gtf_length);
goto out;
}
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* */ /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
taskfile_load_raw(dev, gtf); for (ix = 0; ix < gtf_count; ix++)
} taskfile_load_raw(dev, gtf++);
err = 0; return 0;
out:
return err;
} }
/** /**
...@@ -328,11 +323,7 @@ out: ...@@ -328,11 +323,7 @@ out:
*/ */
int ata_acpi_exec_tfs(struct ata_port *ap) int ata_acpi_exec_tfs(struct ata_port *ap)
{ {
int ix; int ix, ret = 0;
int ret = 0;
unsigned int gtf_length;
unsigned long gtf_address;
unsigned long obj_loc;
/* /*
* TBD - implement PATA support. For now, * TBD - implement PATA support. For now,
...@@ -344,12 +335,16 @@ int ata_acpi_exec_tfs(struct ata_port *ap) ...@@ -344,12 +335,16 @@ int ata_acpi_exec_tfs(struct ata_port *ap)
for (ix = 0; ix < ATA_MAX_DEVICES; ix++) { for (ix = 0; ix < ATA_MAX_DEVICES; ix++) {
struct ata_device *dev = &ap->device[ix]; struct ata_device *dev = &ap->device[ix];
struct ata_acpi_gtf *gtf = NULL;
int gtf_count;
void *ptr_to_free = NULL;
if (!ata_dev_enabled(dev)) if (!ata_dev_enabled(dev))
continue; continue;
ret = do_drive_get_GTF(dev, &gtf_length, &gtf_address, ret = ata_dev_get_GTF(dev, &gtf, &ptr_to_free);
&obj_loc); if (ret == 0)
continue;
if (ret < 0) { if (ret < 0) {
if (ata_msg_probe(ap)) if (ata_msg_probe(ap))
ata_port_printk(ap, KERN_DEBUG, ata_port_printk(ap, KERN_DEBUG,
...@@ -357,9 +352,10 @@ int ata_acpi_exec_tfs(struct ata_port *ap) ...@@ -357,9 +352,10 @@ int ata_acpi_exec_tfs(struct ata_port *ap)
__FUNCTION__, ret); __FUNCTION__, ret);
break; break;
} }
gtf_count = ret;
ret = do_drive_set_taskfiles(dev, gtf_length, gtf_address); ret = ata_dev_set_taskfiles(dev, gtf, gtf_count);
kfree((void *)obj_loc); kfree(ptr_to_free);
if (ret < 0) { if (ret < 0) {
if (ata_msg_probe(ap)) if (ata_msg_probe(ap))
ata_port_printk(ap, KERN_DEBUG, ata_port_printk(ap, KERN_DEBUG,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment