summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/ata/libata-acpi.c161
-rw-r--r--drivers/ata/libata-core.c3
-rw-r--r--drivers/ata/libata-pmp.c4
-rw-r--r--drivers/ata/libata.h5
-rw-r--r--drivers/ata/pata_acpi.c4
-rw-r--r--include/linux/libata.h7
6 files changed, 40 insertions, 144 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;
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index bd33b4a7ac13..7705191b5a81 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -6049,9 +6049,6 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
6049 if (rc) 6049 if (rc)
6050 goto err_tadd; 6050 goto err_tadd;
6051 6051
6052 /* associate with ACPI nodes */
6053 ata_acpi_associate(host);
6054
6055 /* set cable, sata_spd_limit and report */ 6052 /* set cable, sata_spd_limit and report */
6056 for (i = 0; i < host->n_ports; i++) { 6053 for (i = 0; i < host->n_ports; i++) {
6057 struct ata_port *ap = host->ports[i]; 6054 struct ata_port *ap = host->ports[i];
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index 21b80c555c60..61c59ee45ce9 100644
--- a/drivers/ata/libata-pmp.c
+++ b/drivers/ata/libata-pmp.c
@@ -529,8 +529,6 @@ int sata_pmp_attach(struct ata_device *dev)
529 ata_for_each_link(tlink, ap, EDGE) 529 ata_for_each_link(tlink, ap, EDGE)
530 sata_link_init_spd(tlink); 530 sata_link_init_spd(tlink);
531 531
532 ata_acpi_associate_sata_port(ap);
533
534 return 0; 532 return 0;
535 533
536 fail: 534 fail:
@@ -570,8 +568,6 @@ static void sata_pmp_detach(struct ata_device *dev)
570 ap->nr_pmp_links = 0; 568 ap->nr_pmp_links = 0;
571 link->pmp = 0; 569 link->pmp = 0;
572 spin_unlock_irqrestore(ap->lock, flags); 570 spin_unlock_irqrestore(ap->lock, flags);
573
574 ata_acpi_associate_sata_port(ap);
575} 571}
576 572
577/** 573/**
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 7f48b602b01b..b0d5294982eb 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -112,9 +112,6 @@ extern void __ata_port_probe(struct ata_port *ap);
112/* libata-acpi.c */ 112/* libata-acpi.c */
113#ifdef CONFIG_ATA_ACPI 113#ifdef CONFIG_ATA_ACPI
114extern unsigned int ata_acpi_gtf_filter; 114extern unsigned int ata_acpi_gtf_filter;
115
116extern void ata_acpi_associate_sata_port(struct ata_port *ap);
117extern void ata_acpi_associate(struct ata_host *host);
118extern void ata_acpi_dissociate(struct ata_host *host); 115extern void ata_acpi_dissociate(struct ata_host *host);
119extern int ata_acpi_on_suspend(struct ata_port *ap); 116extern int ata_acpi_on_suspend(struct ata_port *ap);
120extern void ata_acpi_on_resume(struct ata_port *ap); 117extern void ata_acpi_on_resume(struct ata_port *ap);
@@ -124,8 +121,6 @@ extern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
124extern int ata_acpi_register(void); 121extern int ata_acpi_register(void);
125extern void ata_acpi_unregister(void); 122extern void ata_acpi_unregister(void);
126#else 123#else
127static inline void ata_acpi_associate_sata_port(struct ata_port *ap) { }
128static inline void ata_acpi_associate(struct ata_host *host) { }
129static inline void ata_acpi_dissociate(struct ata_host *host) { } 124static inline void ata_acpi_dissociate(struct ata_host *host) { }
130static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; } 125static inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
131static inline void ata_acpi_on_resume(struct ata_port *ap) { } 126static inline void ata_acpi_on_resume(struct ata_port *ap) { }
diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
index 54145edf50e8..b63ca3b54fb9 100644
--- a/drivers/ata/pata_acpi.c
+++ b/drivers/ata/pata_acpi.c
@@ -39,7 +39,7 @@ static int pacpi_pre_reset(struct ata_link *link, unsigned long deadline)
39{ 39{
40 struct ata_port *ap = link->ap; 40 struct ata_port *ap = link->ap;
41 struct pata_acpi *acpi = ap->private_data; 41 struct pata_acpi *acpi = ap->private_data;
42 if (ap->acpi_handle == NULL || ata_acpi_gtm(ap, &acpi->gtm) < 0) 42 if (ata_ap_acpi_handle(ap) == NULL || ata_acpi_gtm(ap, &acpi->gtm) < 0)
43 return -ENODEV; 43 return -ENODEV;
44 44
45 return ata_sff_prereset(link, deadline); 45 return ata_sff_prereset(link, deadline);
@@ -195,7 +195,7 @@ static int pacpi_port_start(struct ata_port *ap)
195 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 195 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
196 struct pata_acpi *acpi; 196 struct pata_acpi *acpi;
197 197
198 if (ap->acpi_handle == NULL) 198 if (ata_ap_acpi_handle(ap) == NULL)
199 return -ENODEV; 199 return -ENODEV;
200 200
201 acpi = ap->private_data = devm_kzalloc(&pdev->dev, sizeof(struct pata_acpi), GFP_KERNEL); 201 acpi = ap->private_data = devm_kzalloc(&pdev->dev, sizeof(struct pata_acpi), GFP_KERNEL);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 6e887c742a27..888feef3cda4 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -545,9 +545,6 @@ struct ata_host {
545 struct mutex eh_mutex; 545 struct mutex eh_mutex;
546 struct task_struct *eh_owner; 546 struct task_struct *eh_owner;
547 547
548#ifdef CONFIG_ATA_ACPI
549 acpi_handle acpi_handle;
550#endif
551 struct ata_port *simplex_claimed; /* channel owning the DMA */ 548 struct ata_port *simplex_claimed; /* channel owning the DMA */
552 struct ata_port *ports[0]; 549 struct ata_port *ports[0];
553}; 550};
@@ -615,7 +612,6 @@ struct ata_device {
615 struct scsi_device *sdev; /* attached SCSI device */ 612 struct scsi_device *sdev; /* attached SCSI device */
616 void *private_data; 613 void *private_data;
617#ifdef CONFIG_ATA_ACPI 614#ifdef CONFIG_ATA_ACPI
618 acpi_handle acpi_handle;
619 union acpi_object *gtf_cache; 615 union acpi_object *gtf_cache;
620 unsigned int gtf_filter; 616 unsigned int gtf_filter;
621#endif 617#endif
@@ -797,7 +793,6 @@ struct ata_port {
797 void *private_data; 793 void *private_data;
798 794
799#ifdef CONFIG_ATA_ACPI 795#ifdef CONFIG_ATA_ACPI
800 acpi_handle acpi_handle;
801 struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */ 796 struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */
802#endif 797#endif
803 /* owned by EH */ 798 /* owned by EH */
@@ -1114,6 +1109,8 @@ int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm);
1114int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm); 1109int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm);
1115unsigned long ata_acpi_gtm_xfermask(struct ata_device *dev, 1110unsigned long ata_acpi_gtm_xfermask(struct ata_device *dev,
1116 const struct ata_acpi_gtm *gtm); 1111 const struct ata_acpi_gtm *gtm);
1112acpi_handle ata_ap_acpi_handle(struct ata_port *ap);
1113acpi_handle ata_dev_acpi_handle(struct ata_device *dev);
1117int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm); 1114int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm);
1118#else 1115#else
1119static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap) 1116static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)