aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/libata-acpi.c
diff options
context:
space:
mode:
authorMatthew Garrett <mjg@redhat.com>2012-06-25 04:13:04 -0400
committerJeff Garzik <jgarzik@redhat.com>2012-06-29 11:38:11 -0400
commit30dcf76acc695cbd2fa919e294670fe9552e16e7 (patch)
tree77156836889ea87b90058dd23f634f0f7d99b757 /drivers/ata/libata-acpi.c
parent6b66d95895c149cbc04d4fac5a2f5477c543a8ae (diff)
libata: migrate ACPI code over to new bindings
Now that we have the ability to directly glue the ACPI namespace to the driver model in libata, we don't need the custom code to handle the same thing. Remove it and migrate the functions over to the new code. Signed-off-by: Matthew Garrett <mjg@redhat.com> Signed-off-by: Holger Macht <holger@homac.de> Signed-off-by: Lin Ming <ming.m.lin@intel.com> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers/ata/libata-acpi.c')
-rw-r--r--drivers/ata/libata-acpi.c161
1 files changed, 36 insertions, 125 deletions
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index b3025a7d71e3..c6f0101fd253 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -47,7 +47,14 @@ static void ata_acpi_clear_gtf(struct ata_device *dev)
47 dev->gtf_cache = NULL; 47 dev->gtf_cache = NULL;
48} 48}
49 49
50static acpi_handle ap_acpi_handle(struct ata_port *ap) 50/**
51 * ata_ap_acpi_handle - provide the acpi_handle for an ata_port
52 * @ap: the acpi_handle returned will correspond to this port
53 *
54 * Returns the acpi_handle for the ACPI namespace object corresponding to
55 * the ata_port passed into the function, or NULL if no such object exists
56 */
57acpi_handle ata_ap_acpi_handle(struct ata_port *ap)
51{ 58{
52 if (ap->flags & ATA_FLAG_ACPI_SATA) 59 if (ap->flags & ATA_FLAG_ACPI_SATA)
53 return NULL; 60 return NULL;
@@ -64,8 +71,16 @@ static acpi_handle ap_acpi_handle(struct ata_port *ap)
64 return acpi_get_child(DEVICE_ACPI_HANDLE(ap->host->dev), 71 return acpi_get_child(DEVICE_ACPI_HANDLE(ap->host->dev),
65 ap->port_no); 72 ap->port_no);
66} 73}
74EXPORT_SYMBOL(ata_ap_acpi_handle);
67 75
68static acpi_handle dev_acpi_handle(struct ata_device *dev) 76/**
77 * ata_dev_acpi_handle - provide the acpi_handle for an ata_device
78 * @dev: the acpi_device returned will correspond to this port
79 *
80 * Returns the acpi_handle for the ACPI namespace object corresponding to
81 * the ata_device passed into the function, or NULL if no such object exists
82 */
83acpi_handle ata_dev_acpi_handle(struct ata_device *dev)
69{ 84{
70 acpi_integer adr; 85 acpi_integer adr;
71 struct ata_port *ap = dev->link->ap; 86 struct ata_port *ap = dev->link->ap;
@@ -77,66 +92,9 @@ static acpi_handle dev_acpi_handle(struct ata_device *dev)
77 adr = SATA_ADR(ap->port_no, dev->link->pmp); 92 adr = SATA_ADR(ap->port_no, dev->link->pmp);
78 return acpi_get_child(DEVICE_ACPI_HANDLE(ap->host->dev), adr); 93 return acpi_get_child(DEVICE_ACPI_HANDLE(ap->host->dev), adr);
79 } else 94 } else
80 return acpi_get_child(ap_acpi_handle(ap), dev->devno); 95 return acpi_get_child(ata_ap_acpi_handle(ap), dev->devno);
81}
82
83/**
84 * ata_acpi_associate_sata_port - associate SATA port with ACPI objects
85 * @ap: target SATA port
86 *
87 * Look up ACPI objects associated with @ap and initialize acpi_handle
88 * fields of @ap, the port and devices accordingly.
89 *
90 * LOCKING:
91 * EH context.
92 *
93 * RETURNS:
94 * 0 on success, -errno on failure.
95 */
96void ata_acpi_associate_sata_port(struct ata_port *ap)
97{
98 WARN_ON(!(ap->flags & ATA_FLAG_ACPI_SATA));
99
100 if (!sata_pmp_attached(ap)) {
101 u64 adr = SATA_ADR(ap->port_no, NO_PORT_MULT);
102
103 ap->link.device->acpi_handle =
104 acpi_get_child(ap->host->acpi_handle, adr);
105 } else {
106 struct ata_link *link;
107
108 ap->link.device->acpi_handle = NULL;
109
110 ata_for_each_link(link, ap, EDGE) {
111 u64 adr = SATA_ADR(ap->port_no, link->pmp);
112
113 link->device->acpi_handle =
114 acpi_get_child(ap->host->acpi_handle, adr);
115 }
116 }
117}
118
119static void ata_acpi_associate_ide_port(struct ata_port *ap)
120{
121 int max_devices, i;
122
123 ap->acpi_handle = acpi_get_child(ap->host->acpi_handle, ap->port_no);
124 if (!ap->acpi_handle)
125 return;
126
127 max_devices = 1;
128 if (ap->flags & ATA_FLAG_SLAVE_POSS)
129 max_devices++;
130
131 for (i = 0; i < max_devices; i++) {
132 struct ata_device *dev = &ap->link.device[i];
133
134 dev->acpi_handle = acpi_get_child(ap->acpi_handle, i);
135 }
136
137 if (ata_acpi_gtm(ap, &ap->__acpi_init_gtm) == 0)
138 ap->pflags |= ATA_PFLAG_INIT_GTM_VALID;
139} 96}
97EXPORT_SYMBOL(ata_dev_acpi_handle);
140 98
141/* @ap and @dev are the same as ata_acpi_handle_hotplug() */ 99/* @ap and @dev are the same as ata_acpi_handle_hotplug() */
142static void ata_acpi_detach_device(struct ata_port *ap, struct ata_device *dev) 100static void ata_acpi_detach_device(struct ata_port *ap, struct ata_device *dev)
@@ -262,56 +220,6 @@ static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
262}; 220};
263 221
264/** 222/**
265 * ata_acpi_associate - associate ATA host with ACPI objects
266 * @host: target ATA host
267 *
268 * Look up ACPI objects associated with @host and initialize
269 * acpi_handle fields of @host, its ports and devices accordingly.
270 *
271 * LOCKING:
272 * EH context.
273 *
274 * RETURNS:
275 * 0 on success, -errno on failure.
276 */
277void ata_acpi_associate(struct ata_host *host)
278{
279 int i, j;
280
281 if (!is_pci_dev(host->dev) || libata_noacpi)
282 return;
283
284 host->acpi_handle = DEVICE_ACPI_HANDLE(host->dev);
285 if (!host->acpi_handle)
286 return;
287
288 for (i = 0; i < host->n_ports; i++) {
289 struct ata_port *ap = host->ports[i];
290
291 if (host->ports[0]->flags & ATA_FLAG_ACPI_SATA)
292 ata_acpi_associate_sata_port(ap);
293 else
294 ata_acpi_associate_ide_port(ap);
295
296 if (ap->acpi_handle) {
297 /* we might be on a docking station */
298 register_hotplug_dock_device(ap->acpi_handle,
299 &ata_acpi_ap_dock_ops, ap);
300 }
301
302 for (j = 0; j < ata_link_max_devices(&ap->link); j++) {
303 struct ata_device *dev = &ap->link.device[j];
304
305 if (dev->acpi_handle) {
306 /* we might be on a docking station */
307 register_hotplug_dock_device(dev->acpi_handle,
308 &ata_acpi_dev_dock_ops, dev);
309 }
310 }
311 }
312}
313
314/**
315 * ata_acpi_dissociate - dissociate ATA host from ACPI objects 223 * ata_acpi_dissociate - dissociate ATA host from ACPI objects
316 * @host: target ATA host 224 * @host: target ATA host
317 * 225 *
@@ -332,7 +240,7 @@ void ata_acpi_dissociate(struct ata_host *host)
332 struct ata_port *ap = host->ports[i]; 240 struct ata_port *ap = host->ports[i];
333 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); 241 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
334 242
335 if (ap->acpi_handle && gtm) 243 if (ata_ap_acpi_handle(ap) && gtm)
336 ata_acpi_stm(ap, gtm); 244 ata_acpi_stm(ap, gtm);
337 } 245 }
338} 246}
@@ -357,7 +265,8 @@ int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *gtm)
357 acpi_status status; 265 acpi_status status;
358 int rc = 0; 266 int rc = 0;
359 267
360 status = acpi_evaluate_object(ap->acpi_handle, "_GTM", NULL, &output); 268 status = acpi_evaluate_object(ata_ap_acpi_handle(ap), "_GTM", NULL,
269 &output);
361 270
362 rc = -ENOENT; 271 rc = -ENOENT;
363 if (status == AE_NOT_FOUND) 272 if (status == AE_NOT_FOUND)
@@ -427,7 +336,8 @@ int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm)
427 input.count = 3; 336 input.count = 3;
428 input.pointer = in_params; 337 input.pointer = in_params;
429 338
430 status = acpi_evaluate_object(ap->acpi_handle, "_STM", &input, NULL); 339 status = acpi_evaluate_object(ata_ap_acpi_handle(ap), "_STM", &input,
340 NULL);
431 341
432 if (status == AE_NOT_FOUND) 342 if (status == AE_NOT_FOUND)
433 return -ENOENT; 343 return -ENOENT;
@@ -484,7 +394,8 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf)
484 __func__, ap->port_no); 394 __func__, ap->port_no);
485 395
486 /* _GTF has no input parameters */ 396 /* _GTF has no input parameters */
487 status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output); 397 status = acpi_evaluate_object(ata_dev_acpi_handle(dev), "_GTF", NULL,
398 &output);
488 out_obj = dev->gtf_cache = output.pointer; 399 out_obj = dev->gtf_cache = output.pointer;
489 400
490 if (ACPI_FAILURE(status)) { 401 if (ACPI_FAILURE(status)) {
@@ -850,7 +761,8 @@ static int ata_acpi_push_id(struct ata_device *dev)
850 761
851 /* It's OK for _SDD to be missing too. */ 762 /* It's OK for _SDD to be missing too. */
852 swap_buf_le16(dev->id, ATA_ID_WORDS); 763 swap_buf_le16(dev->id, ATA_ID_WORDS);
853 status = acpi_evaluate_object(dev->acpi_handle, "_SDD", &input, NULL); 764 status = acpi_evaluate_object(ata_dev_acpi_handle(dev), "_SDD", &input,
765 NULL);
854 swap_buf_le16(dev->id, ATA_ID_WORDS); 766 swap_buf_le16(dev->id, ATA_ID_WORDS);
855 767
856 if (status == AE_NOT_FOUND) 768 if (status == AE_NOT_FOUND)
@@ -900,7 +812,7 @@ void ata_acpi_on_resume(struct ata_port *ap)
900 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap); 812 const struct ata_acpi_gtm *gtm = ata_acpi_init_gtm(ap);
901 struct ata_device *dev; 813 struct ata_device *dev;
902 814
903 if (ap->acpi_handle && gtm) { 815 if (ata_ap_acpi_handle(ap) && gtm) {
904 /* _GTM valid */ 816 /* _GTM valid */
905 817
906 /* restore timing parameters */ 818 /* restore timing parameters */
@@ -941,22 +853,22 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
941{ 853{
942 struct ata_device *dev; 854 struct ata_device *dev;
943 855
944 if (!ap->acpi_handle || (ap->flags & ATA_FLAG_ACPI_SATA)) 856 if (!ata_ap_acpi_handle(ap) || (ap->flags & ATA_FLAG_ACPI_SATA))
945 return; 857 return;
946 858
947 /* channel first and then drives for power on and vica versa 859 /* channel first and then drives for power on and vica versa
948 for power off */ 860 for power off */
949 if (state.event == PM_EVENT_ON) 861 if (state.event == PM_EVENT_ON)
950 acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0); 862 acpi_bus_set_power(ata_ap_acpi_handle(ap), ACPI_STATE_D0);
951 863
952 ata_for_each_dev(dev, &ap->link, ENABLED) { 864 ata_for_each_dev(dev, &ap->link, ENABLED) {
953 if (dev->acpi_handle) 865 if (ata_dev_acpi_handle(dev))
954 acpi_bus_set_power(dev->acpi_handle, 866 acpi_bus_set_power(ata_dev_acpi_handle(dev),
955 state.event == PM_EVENT_ON ? 867 state.event == PM_EVENT_ON ?
956 ACPI_STATE_D0 : ACPI_STATE_D3); 868 ACPI_STATE_D0 : ACPI_STATE_D3);
957 } 869 }
958 if (state.event != PM_EVENT_ON) 870 if (state.event != PM_EVENT_ON)
959 acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D3); 871 acpi_bus_set_power(ata_ap_acpi_handle(ap), ACPI_STATE_D3);
960} 872}
961 873
962/** 874/**
@@ -981,7 +893,7 @@ int ata_acpi_on_devcfg(struct ata_device *dev)
981 int nr_executed = 0; 893 int nr_executed = 0;
982 int rc; 894 int rc;
983 895
984 if (!dev->acpi_handle) 896 if (!ata_dev_acpi_handle(dev))
985 return 0; 897 return 0;
986 898
987 /* do we need to do _GTF? */ 899 /* do we need to do _GTF? */
@@ -1027,7 +939,6 @@ int ata_acpi_on_devcfg(struct ata_device *dev)
1027 } 939 }
1028 940
1029 ata_dev_warn(dev, "ACPI: failed the second time, disabled\n"); 941 ata_dev_warn(dev, "ACPI: failed the second time, disabled\n");
1030 dev->acpi_handle = NULL;
1031 942
1032 /* We can safely continue if no _GTF command has been executed 943 /* We can safely continue if no _GTF command has been executed
1033 * and port is not frozen. 944 * and port is not frozen.
@@ -1093,7 +1004,7 @@ static int ata_acpi_bind_device(struct ata_port *ap, struct scsi_device *sdev,
1093 else 1004 else
1094 ata_dev = &ap->link.device[sdev->id]; 1005 ata_dev = &ap->link.device[sdev->id];
1095 1006
1096 *handle = dev_acpi_handle(ata_dev); 1007 *handle = ata_dev_acpi_handle(ata_dev);
1097 1008
1098 if (!*handle) 1009 if (!*handle)
1099 return -ENODEV; 1010 return -ENODEV;