diff options
Diffstat (limited to 'drivers/ata/libata-acpi.c')
-rw-r--r-- | drivers/ata/libata-acpi.c | 914 |
1 files changed, 401 insertions, 513 deletions
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c index 02236739b40f..c059f78ad944 100644 --- a/drivers/ata/libata-acpi.c +++ b/drivers/ata/libata-acpi.c | |||
@@ -24,15 +24,13 @@ | |||
24 | #include <acpi/acmacros.h> | 24 | #include <acpi/acmacros.h> |
25 | #include <acpi/actypes.h> | 25 | #include <acpi/actypes.h> |
26 | 26 | ||
27 | #define SATA_ROOT_PORT(x) (((x) >> 16) & 0xffff) | ||
28 | #define SATA_PORT_NUMBER(x) ((x) & 0xffff) /* or NO_PORT_MULT */ | ||
29 | #define NO_PORT_MULT 0xffff | 27 | #define NO_PORT_MULT 0xffff |
30 | #define SATA_ADR_RSVD 0xffffffff | 28 | #define SATA_ADR(root,pmp) (((root) << 16) | (pmp)) |
31 | 29 | ||
32 | #define REGS_PER_GTF 7 | 30 | #define REGS_PER_GTF 7 |
33 | struct taskfile_array { | 31 | struct ata_acpi_gtf { |
34 | u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */ | 32 | u8 tf[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */ |
35 | }; | 33 | } __packed; |
36 | 34 | ||
37 | /* | 35 | /* |
38 | * Helper - belongs in the PCI layer somewhere eventually | 36 | * Helper - belongs in the PCI layer somewhere eventually |
@@ -42,237 +40,173 @@ static int is_pci_dev(struct device *dev) | |||
42 | return (dev->bus == &pci_bus_type); | 40 | return (dev->bus == &pci_bus_type); |
43 | } | 41 | } |
44 | 42 | ||
43 | static void ata_acpi_associate_sata_port(struct ata_port *ap) | ||
44 | { | ||
45 | acpi_integer adr = SATA_ADR(ap->port_no, NO_PORT_MULT); | ||
46 | |||
47 | ap->device->acpi_handle = acpi_get_child(ap->host->acpi_handle, adr); | ||
48 | } | ||
49 | |||
50 | static void ata_acpi_associate_ide_port(struct ata_port *ap) | ||
51 | { | ||
52 | int max_devices, i; | ||
53 | |||
54 | ap->acpi_handle = acpi_get_child(ap->host->acpi_handle, ap->port_no); | ||
55 | if (!ap->acpi_handle) | ||
56 | return; | ||
57 | |||
58 | max_devices = 1; | ||
59 | if (ap->flags & ATA_FLAG_SLAVE_POSS) | ||
60 | max_devices++; | ||
61 | |||
62 | for (i = 0; i < max_devices; i++) { | ||
63 | struct ata_device *dev = &ap->device[i]; | ||
64 | |||
65 | dev->acpi_handle = acpi_get_child(ap->acpi_handle, i); | ||
66 | } | ||
67 | } | ||
68 | |||
45 | /** | 69 | /** |
46 | * sata_get_dev_handle - finds acpi_handle and PCI device.function | 70 | * ata_acpi_associate - associate ATA host with ACPI objects |
47 | * @dev: device to locate | 71 | * @host: target ATA host |
48 | * @handle: returned acpi_handle for @dev | 72 | * |
49 | * @pcidevfn: return PCI device.func for @dev | 73 | * Look up ACPI objects associated with @host and initialize |
74 | * acpi_handle fields of @host, its ports and devices accordingly. | ||
50 | * | 75 | * |
51 | * This function is somewhat SATA-specific. Or at least the | 76 | * LOCKING: |
52 | * PATA & SATA versions of this function are different, | 77 | * EH context. |
53 | * so it's not entirely generic code. | ||
54 | * | 78 | * |
55 | * Returns 0 on success, <0 on error. | 79 | * RETURNS: |
80 | * 0 on success, -errno on failure. | ||
56 | */ | 81 | */ |
57 | static int sata_get_dev_handle(struct device *dev, acpi_handle *handle, | 82 | void ata_acpi_associate(struct ata_host *host) |
58 | acpi_integer *pcidevfn) | ||
59 | { | 83 | { |
60 | struct pci_dev *pci_dev; | 84 | int i; |
61 | acpi_integer addr; | 85 | |
62 | 86 | if (!is_pci_dev(host->dev) || libata_noacpi) | |
63 | if (!is_pci_dev(dev)) | 87 | return; |
64 | return -ENODEV; | 88 | |
65 | 89 | host->acpi_handle = DEVICE_ACPI_HANDLE(host->dev); | |
66 | pci_dev = to_pci_dev(dev); /* NOTE: PCI-specific */ | 90 | if (!host->acpi_handle) |
67 | /* Please refer to the ACPI spec for the syntax of _ADR. */ | 91 | return; |
68 | addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn); | 92 | |
69 | *pcidevfn = addr; | 93 | for (i = 0; i < host->n_ports; i++) { |
70 | *handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr); | 94 | struct ata_port *ap = host->ports[i]; |
71 | if (!*handle) | 95 | |
72 | return -ENODEV; | 96 | if (host->ports[0]->flags & ATA_FLAG_ACPI_SATA) |
73 | return 0; | 97 | ata_acpi_associate_sata_port(ap); |
98 | else | ||
99 | ata_acpi_associate_ide_port(ap); | ||
100 | } | ||
74 | } | 101 | } |
75 | 102 | ||
76 | /** | 103 | /** |
77 | * pata_get_dev_handle - finds acpi_handle and PCI device.function | 104 | * ata_acpi_gtm - execute _GTM |
78 | * @dev: device to locate | 105 | * @ap: target ATA port |
79 | * @handle: returned acpi_handle for @dev | 106 | * @gtm: out parameter for _GTM result |
80 | * @pcidevfn: return PCI device.func for @dev | 107 | * |
108 | * Evaluate _GTM and store the result in @gtm. | ||
81 | * | 109 | * |
82 | * The PATA and SATA versions of this function are different. | 110 | * LOCKING: |
111 | * EH context. | ||
83 | * | 112 | * |
84 | * Returns 0 on success, <0 on error. | 113 | * RETURNS: |
114 | * 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure. | ||
85 | */ | 115 | */ |
86 | static int pata_get_dev_handle(struct device *dev, acpi_handle *handle, | 116 | static int ata_acpi_gtm(const struct ata_port *ap, struct ata_acpi_gtm *gtm) |
87 | acpi_integer *pcidevfn) | ||
88 | { | 117 | { |
89 | unsigned int bus, devnum, func; | 118 | struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER }; |
90 | acpi_integer addr; | 119 | union acpi_object *out_obj; |
91 | acpi_handle dev_handle, parent_handle; | ||
92 | struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER, | ||
93 | .pointer = NULL}; | ||
94 | acpi_status status; | 120 | acpi_status status; |
95 | struct acpi_device_info *dinfo = NULL; | 121 | int rc = 0; |
96 | int ret = -ENODEV; | 122 | |
97 | struct pci_dev *pdev; | 123 | status = acpi_evaluate_object(ap->acpi_handle, "_GTM", NULL, &output); |
98 | 124 | ||
99 | if (!is_pci_dev(dev)) | 125 | rc = -ENOENT; |
100 | return -ENODEV; | 126 | if (status == AE_NOT_FOUND) |
101 | 127 | goto out_free; | |
102 | pdev = to_pci_dev(dev); | 128 | |
103 | 129 | rc = -EINVAL; | |
104 | bus = pdev->bus->number; | 130 | if (ACPI_FAILURE(status)) { |
105 | devnum = PCI_SLOT(pdev->devfn); | 131 | ata_port_printk(ap, KERN_ERR, |
106 | func = PCI_FUNC(pdev->devfn); | 132 | "ACPI get timing mode failed (AE 0x%x)\n", |
107 | 133 | status); | |
108 | dev_handle = DEVICE_ACPI_HANDLE(dev); | 134 | goto out_free; |
109 | parent_handle = DEVICE_ACPI_HANDLE(dev->parent); | ||
110 | |||
111 | status = acpi_get_object_info(parent_handle, &buffer); | ||
112 | if (ACPI_FAILURE(status)) | ||
113 | goto err; | ||
114 | |||
115 | dinfo = buffer.pointer; | ||
116 | if (dinfo && (dinfo->valid & ACPI_VALID_ADR) && | ||
117 | dinfo->address == bus) { | ||
118 | /* ACPI spec for _ADR for PCI bus: */ | ||
119 | addr = (acpi_integer)(devnum << 16 | func); | ||
120 | *pcidevfn = addr; | ||
121 | *handle = dev_handle; | ||
122 | } else { | ||
123 | goto err; | ||
124 | } | 135 | } |
125 | 136 | ||
126 | if (!*handle) | 137 | out_obj = output.pointer; |
127 | goto err; | 138 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
128 | ret = 0; | 139 | ata_port_printk(ap, KERN_WARNING, |
129 | err: | 140 | "_GTM returned unexpected object type 0x%x\n", |
130 | kfree(dinfo); | 141 | out_obj->type); |
131 | return ret; | ||
132 | } | ||
133 | 142 | ||
134 | struct walk_info { /* can be trimmed some */ | 143 | goto out_free; |
135 | struct device *dev; | ||
136 | struct acpi_device *adev; | ||
137 | acpi_handle handle; | ||
138 | acpi_integer pcidevfn; | ||
139 | unsigned int drivenum; | ||
140 | acpi_handle obj_handle; | ||
141 | struct ata_port *ataport; | ||
142 | struct ata_device *atadev; | ||
143 | u32 sata_adr; | ||
144 | int status; | ||
145 | char basepath[ACPI_PATHNAME_MAX]; | ||
146 | int basepath_len; | ||
147 | }; | ||
148 | |||
149 | static acpi_status get_devices(acpi_handle handle, | ||
150 | u32 level, void *context, void **return_value) | ||
151 | { | ||
152 | acpi_status status; | ||
153 | struct walk_info *winfo = context; | ||
154 | struct acpi_buffer namebuf = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
155 | char *pathname; | ||
156 | struct acpi_buffer buffer; | ||
157 | struct acpi_device_info *dinfo; | ||
158 | |||
159 | status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &namebuf); | ||
160 | if (status) | ||
161 | goto ret; | ||
162 | pathname = namebuf.pointer; | ||
163 | |||
164 | buffer.length = ACPI_ALLOCATE_BUFFER; | ||
165 | buffer.pointer = NULL; | ||
166 | status = acpi_get_object_info(handle, &buffer); | ||
167 | if (ACPI_FAILURE(status)) | ||
168 | goto out2; | ||
169 | |||
170 | dinfo = buffer.pointer; | ||
171 | |||
172 | /* find full device path name for pcidevfn */ | ||
173 | if (dinfo && (dinfo->valid & ACPI_VALID_ADR) && | ||
174 | dinfo->address == winfo->pcidevfn) { | ||
175 | if (ata_msg_probe(winfo->ataport)) | ||
176 | ata_dev_printk(winfo->atadev, KERN_DEBUG, | ||
177 | ":%s: matches pcidevfn (0x%llx)\n", | ||
178 | pathname, winfo->pcidevfn); | ||
179 | strlcpy(winfo->basepath, pathname, | ||
180 | sizeof(winfo->basepath)); | ||
181 | winfo->basepath_len = strlen(pathname); | ||
182 | goto out; | ||
183 | } | 144 | } |
184 | 145 | ||
185 | /* if basepath is not yet known, ignore this object */ | 146 | if (out_obj->buffer.length != sizeof(struct ata_acpi_gtm)) { |
186 | if (!winfo->basepath_len) | 147 | ata_port_printk(ap, KERN_ERR, |
187 | goto out; | 148 | "_GTM returned invalid length %d\n", |
188 | 149 | out_obj->buffer.length); | |
189 | /* if this object is in scope of basepath, maybe use it */ | 150 | goto out_free; |
190 | if (strncmp(pathname, winfo->basepath, | ||
191 | winfo->basepath_len) == 0) { | ||
192 | if (!(dinfo->valid & ACPI_VALID_ADR)) | ||
193 | goto out; | ||
194 | if (ata_msg_probe(winfo->ataport)) | ||
195 | ata_dev_printk(winfo->atadev, KERN_DEBUG, | ||
196 | "GOT ONE: (%s) root_port = 0x%llx," | ||
197 | " port_num = 0x%llx\n", pathname, | ||
198 | SATA_ROOT_PORT(dinfo->address), | ||
199 | SATA_PORT_NUMBER(dinfo->address)); | ||
200 | /* heuristics: */ | ||
201 | if (SATA_PORT_NUMBER(dinfo->address) != NO_PORT_MULT) | ||
202 | if (ata_msg_probe(winfo->ataport)) | ||
203 | ata_dev_printk(winfo->atadev, | ||
204 | KERN_DEBUG, "warning: don't" | ||
205 | " know how to handle SATA port" | ||
206 | " multiplier\n"); | ||
207 | if (SATA_ROOT_PORT(dinfo->address) == | ||
208 | winfo->ataport->port_no && | ||
209 | SATA_PORT_NUMBER(dinfo->address) == NO_PORT_MULT) { | ||
210 | if (ata_msg_probe(winfo->ataport)) | ||
211 | ata_dev_printk(winfo->atadev, | ||
212 | KERN_DEBUG, | ||
213 | "THIS ^^^^^ is the requested" | ||
214 | " SATA drive (handle = 0x%p)\n", | ||
215 | handle); | ||
216 | winfo->sata_adr = dinfo->address; | ||
217 | winfo->obj_handle = handle; | ||
218 | } | ||
219 | } | 151 | } |
220 | out: | ||
221 | kfree(dinfo); | ||
222 | out2: | ||
223 | kfree(pathname); | ||
224 | 152 | ||
225 | ret: | 153 | memcpy(gtm, out_obj->buffer.pointer, sizeof(struct ata_acpi_gtm)); |
226 | return status; | 154 | rc = 0; |
155 | out_free: | ||
156 | kfree(output.pointer); | ||
157 | return rc; | ||
227 | } | 158 | } |
228 | 159 | ||
229 | /* Get the SATA drive _ADR object. */ | 160 | /** |
230 | static int get_sata_adr(struct device *dev, acpi_handle handle, | 161 | * ata_acpi_stm - execute _STM |
231 | acpi_integer pcidevfn, unsigned int drive, | 162 | * @ap: target ATA port |
232 | struct ata_port *ap, | 163 | * @stm: timing parameter to _STM |
233 | struct ata_device *atadev, u32 *dev_adr) | 164 | * |
165 | * Evaluate _STM with timing parameter @stm. | ||
166 | * | ||
167 | * LOCKING: | ||
168 | * EH context. | ||
169 | * | ||
170 | * RETURNS: | ||
171 | * 0 on success, -ENOENT if _STM doesn't exist, -errno on failure. | ||
172 | */ | ||
173 | static int ata_acpi_stm(const struct ata_port *ap, struct ata_acpi_gtm *stm) | ||
234 | { | 174 | { |
235 | acpi_status status; | 175 | acpi_status status; |
236 | struct walk_info *winfo; | 176 | struct acpi_object_list input; |
237 | int err = -ENOMEM; | 177 | union acpi_object in_params[3]; |
238 | |||
239 | winfo = kzalloc(sizeof(struct walk_info), GFP_KERNEL); | ||
240 | if (!winfo) | ||
241 | goto out; | ||
242 | |||
243 | winfo->dev = dev; | ||
244 | winfo->atadev = atadev; | ||
245 | winfo->ataport = ap; | ||
246 | if (acpi_bus_get_device(handle, &winfo->adev) < 0) | ||
247 | if (ata_msg_probe(ap)) | ||
248 | ata_dev_printk(winfo->atadev, KERN_DEBUG, | ||
249 | "acpi_bus_get_device failed\n"); | ||
250 | winfo->handle = handle; | ||
251 | winfo->pcidevfn = pcidevfn; | ||
252 | winfo->drivenum = drive; | ||
253 | 178 | ||
254 | status = acpi_get_devices(NULL, get_devices, winfo, NULL); | 179 | in_params[0].type = ACPI_TYPE_BUFFER; |
180 | in_params[0].buffer.length = sizeof(struct ata_acpi_gtm); | ||
181 | in_params[0].buffer.pointer = (u8 *)stm; | ||
182 | /* Buffers for id may need byteswapping ? */ | ||
183 | in_params[1].type = ACPI_TYPE_BUFFER; | ||
184 | in_params[1].buffer.length = 512; | ||
185 | in_params[1].buffer.pointer = (u8 *)ap->device[0].id; | ||
186 | in_params[2].type = ACPI_TYPE_BUFFER; | ||
187 | in_params[2].buffer.length = 512; | ||
188 | in_params[2].buffer.pointer = (u8 *)ap->device[1].id; | ||
189 | |||
190 | input.count = 3; | ||
191 | input.pointer = in_params; | ||
192 | |||
193 | status = acpi_evaluate_object(ap->acpi_handle, "_STM", &input, NULL); | ||
194 | |||
195 | if (status == AE_NOT_FOUND) | ||
196 | return -ENOENT; | ||
255 | if (ACPI_FAILURE(status)) { | 197 | if (ACPI_FAILURE(status)) { |
256 | if (ata_msg_probe(ap)) | 198 | ata_port_printk(ap, KERN_ERR, |
257 | ata_dev_printk(winfo->atadev, KERN_DEBUG, | 199 | "ACPI set timing mode failed (status=0x%x)\n", status); |
258 | "%s: acpi_get_devices failed\n", | 200 | return -EINVAL; |
259 | __FUNCTION__); | ||
260 | err = -ENODEV; | ||
261 | } else { | ||
262 | *dev_adr = winfo->sata_adr; | ||
263 | atadev->obj_handle = winfo->obj_handle; | ||
264 | err = 0; | ||
265 | } | 201 | } |
266 | kfree(winfo); | 202 | return 0; |
267 | out: | ||
268 | return err; | ||
269 | } | 203 | } |
270 | 204 | ||
271 | /** | 205 | /** |
272 | * do_drive_get_GTF - get the drive bootup default taskfile settings | 206 | * ata_dev_get_GTF - get the drive bootup default taskfile settings |
273 | * @dev: target ATA device | 207 | * @dev: target ATA device |
274 | * @gtf_length: number of bytes of _GTF data returned at @gtf_address | 208 | * @gtf: output parameter for buffer containing _GTF taskfile arrays |
275 | * @gtf_address: buffer containing _GTF taskfile arrays | 209 | * @ptr_to_free: pointer which should be freed |
276 | * | 210 | * |
277 | * This applies to both PATA and SATA drives. | 211 | * This applies to both PATA and SATA drives. |
278 | * | 212 | * |
@@ -282,121 +216,41 @@ out: | |||
282 | * The <variable number> is not known in advance, so have ACPI-CA | 216 | * The <variable number> is not known in advance, so have ACPI-CA |
283 | * allocate the buffer as needed and return it, then free it later. | 217 | * allocate the buffer as needed and return it, then free it later. |
284 | * | 218 | * |
285 | * The returned @gtf_length and @gtf_address are only valid if the | 219 | * LOCKING: |
286 | * function return value is 0. | 220 | * EH context. |
221 | * | ||
222 | * RETURNS: | ||
223 | * Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't | ||
224 | * contain valid data. -errno on other errors. | ||
287 | */ | 225 | */ |
288 | static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length, | 226 | static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf, |
289 | unsigned long *gtf_address, unsigned long *obj_loc) | 227 | void **ptr_to_free) |
290 | { | 228 | { |
291 | struct ata_port *ap = dev->ap; | 229 | struct ata_port *ap = dev->ap; |
292 | acpi_status status; | 230 | acpi_status status; |
293 | acpi_handle dev_handle = NULL; | ||
294 | acpi_handle chan_handle, drive_handle; | ||
295 | acpi_integer pcidevfn = 0; | ||
296 | u32 dev_adr; | ||
297 | struct acpi_buffer output; | 231 | struct acpi_buffer output; |
298 | union acpi_object *out_obj; | 232 | union acpi_object *out_obj; |
299 | struct device *gdev = ap->host->dev; | 233 | int rc = 0; |
300 | int err = -ENODEV; | ||
301 | 234 | ||
302 | *gtf_length = 0; | 235 | /* set up output buffer */ |
303 | *gtf_address = 0UL; | 236 | output.length = ACPI_ALLOCATE_BUFFER; |
304 | *obj_loc = 0UL; | 237 | output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ |
305 | |||
306 | if (libata_noacpi) | ||
307 | return 0; | ||
308 | 238 | ||
309 | if (ata_msg_probe(ap)) | 239 | if (ata_msg_probe(ap)) |
310 | ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n", | 240 | ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n", |
311 | __FUNCTION__, ap->port_no); | 241 | __FUNCTION__, ap->port_no); |
312 | 242 | ||
313 | if (!ata_dev_enabled(dev) || (ap->flags & ATA_FLAG_DISABLED)) { | ||
314 | if (ata_msg_probe(ap)) | ||
315 | ata_dev_printk(dev, KERN_DEBUG, "%s: ERR: " | ||
316 | "ata_dev_present: %d, PORT_DISABLED: %lu\n", | ||
317 | __FUNCTION__, ata_dev_enabled(dev), | ||
318 | ap->flags & ATA_FLAG_DISABLED); | ||
319 | goto out; | ||
320 | } | ||
321 | |||
322 | /* Don't continue if device has no _ADR method. | ||
323 | * _GTF is intended for known motherboard devices. */ | ||
324 | if (!(ap->flags & ATA_FLAG_ACPI_SATA)) { | ||
325 | err = pata_get_dev_handle(gdev, &dev_handle, &pcidevfn); | ||
326 | if (err < 0) { | ||
327 | if (ata_msg_probe(ap)) | ||
328 | ata_dev_printk(dev, KERN_DEBUG, | ||
329 | "%s: pata_get_dev_handle failed (%d)\n", | ||
330 | __FUNCTION__, err); | ||
331 | goto out; | ||
332 | } | ||
333 | } else { | ||
334 | err = sata_get_dev_handle(gdev, &dev_handle, &pcidevfn); | ||
335 | if (err < 0) { | ||
336 | if (ata_msg_probe(ap)) | ||
337 | ata_dev_printk(dev, KERN_DEBUG, | ||
338 | "%s: sata_get_dev_handle failed (%d\n", | ||
339 | __FUNCTION__, err); | ||
340 | goto out; | ||
341 | } | ||
342 | } | ||
343 | |||
344 | /* Get this drive's _ADR info. if not already known. */ | ||
345 | if (!dev->obj_handle) { | ||
346 | if (!(ap->flags & ATA_FLAG_ACPI_SATA)) { | ||
347 | /* get child objects of dev_handle == channel objects, | ||
348 | * + _their_ children == drive objects */ | ||
349 | /* channel is ap->port_no */ | ||
350 | chan_handle = acpi_get_child(dev_handle, | ||
351 | ap->port_no); | ||
352 | if (ata_msg_probe(ap)) | ||
353 | ata_dev_printk(dev, KERN_DEBUG, | ||
354 | "%s: chan adr=%d: chan_handle=0x%p\n", | ||
355 | __FUNCTION__, ap->port_no, | ||
356 | chan_handle); | ||
357 | if (!chan_handle) { | ||
358 | err = -ENODEV; | ||
359 | goto out; | ||
360 | } | ||
361 | /* TBD: could also check ACPI object VALID bits */ | ||
362 | drive_handle = acpi_get_child(chan_handle, dev->devno); | ||
363 | if (!drive_handle) { | ||
364 | err = -ENODEV; | ||
365 | goto out; | ||
366 | } | ||
367 | dev_adr = dev->devno; | ||
368 | dev->obj_handle = drive_handle; | ||
369 | } else { /* for SATA mode */ | ||
370 | dev_adr = SATA_ADR_RSVD; | ||
371 | err = get_sata_adr(gdev, dev_handle, pcidevfn, 0, | ||
372 | ap, dev, &dev_adr); | ||
373 | } | ||
374 | if (err < 0 || dev_adr == SATA_ADR_RSVD || | ||
375 | !dev->obj_handle) { | ||
376 | if (ata_msg_probe(ap)) | ||
377 | ata_dev_printk(dev, KERN_DEBUG, | ||
378 | "%s: get_sata/pata_adr failed: " | ||
379 | "err=%d, dev_adr=%u, obj_handle=0x%p\n", | ||
380 | __FUNCTION__, err, dev_adr, | ||
381 | dev->obj_handle); | ||
382 | goto out; | ||
383 | } | ||
384 | } | ||
385 | |||
386 | /* Setting up output buffer */ | ||
387 | output.length = ACPI_ALLOCATE_BUFFER; | ||
388 | output.pointer = NULL; /* ACPI-CA sets this; save/free it later */ | ||
389 | |||
390 | /* _GTF has no input parameters */ | 243 | /* _GTF has no input parameters */ |
391 | err = -EIO; | 244 | status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output); |
392 | status = acpi_evaluate_object(dev->obj_handle, "_GTF", | 245 | |
393 | NULL, &output); | ||
394 | if (ACPI_FAILURE(status)) { | 246 | if (ACPI_FAILURE(status)) { |
395 | if (ata_msg_probe(ap)) | 247 | if (status != AE_NOT_FOUND) { |
396 | ata_dev_printk(dev, KERN_DEBUG, | 248 | ata_dev_printk(dev, KERN_WARNING, |
397 | "%s: Run _GTF error: status = 0x%x\n", | 249 | "_GTF evaluation failed (AE 0x%x)\n", |
398 | __FUNCTION__, status); | 250 | status); |
399 | goto out; | 251 | rc = -EIO; |
252 | } | ||
253 | goto out_free; | ||
400 | } | 254 | } |
401 | 255 | ||
402 | if (!output.length || !output.pointer) { | 256 | if (!output.length || !output.pointer) { |
@@ -406,43 +260,39 @@ static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length, | |||
406 | __FUNCTION__, | 260 | __FUNCTION__, |
407 | (unsigned long long)output.length, | 261 | (unsigned long long)output.length, |
408 | output.pointer); | 262 | output.pointer); |
409 | kfree(output.pointer); | 263 | goto out_free; |
410 | goto out; | ||
411 | } | 264 | } |
412 | 265 | ||
413 | out_obj = output.pointer; | 266 | out_obj = output.pointer; |
414 | if (out_obj->type != ACPI_TYPE_BUFFER) { | 267 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
415 | kfree(output.pointer); | 268 | ata_dev_printk(dev, KERN_WARNING, |
416 | if (ata_msg_probe(ap)) | 269 | "_GTF unexpected object type 0x%x\n", |
417 | ata_dev_printk(dev, KERN_DEBUG, "%s: Run _GTF: " | 270 | out_obj->type); |
418 | "error: expected object type of " | 271 | rc = -EINVAL; |
419 | " ACPI_TYPE_BUFFER, got 0x%x\n", | 272 | goto out_free; |
420 | __FUNCTION__, out_obj->type); | ||
421 | err = -ENOENT; | ||
422 | goto out; | ||
423 | } | 273 | } |
424 | 274 | ||
425 | if (!out_obj->buffer.length || !out_obj->buffer.pointer || | 275 | if (out_obj->buffer.length % REGS_PER_GTF) { |
426 | out_obj->buffer.length % REGS_PER_GTF) { | 276 | ata_dev_printk(dev, KERN_WARNING, |
427 | if (ata_msg_drv(ap)) | 277 | "unexpected _GTF length (%d)\n", |
428 | ata_dev_printk(dev, KERN_ERR, | 278 | out_obj->buffer.length); |
429 | "%s: unexpected GTF length (%d) or addr (0x%p)\n", | 279 | rc = -EINVAL; |
430 | __FUNCTION__, out_obj->buffer.length, | 280 | goto out_free; |
431 | out_obj->buffer.pointer); | ||
432 | err = -ENOENT; | ||
433 | goto out; | ||
434 | } | 281 | } |
435 | 282 | ||
436 | *gtf_length = out_obj->buffer.length; | 283 | *ptr_to_free = out_obj; |
437 | *gtf_address = (unsigned long)out_obj->buffer.pointer; | 284 | *gtf = (void *)out_obj->buffer.pointer; |
438 | *obj_loc = (unsigned long)out_obj; | 285 | rc = out_obj->buffer.length / REGS_PER_GTF; |
286 | |||
439 | if (ata_msg_probe(ap)) | 287 | if (ata_msg_probe(ap)) |
440 | ata_dev_printk(dev, KERN_DEBUG, "%s: returning " | 288 | ata_dev_printk(dev, KERN_DEBUG, "%s: returning " |
441 | "gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n", | 289 | "gtf=%p, gtf_count=%d, ptr_to_free=%p\n", |
442 | __FUNCTION__, *gtf_length, *gtf_address, *obj_loc); | 290 | __FUNCTION__, *gtf, rc, *ptr_to_free); |
443 | err = 0; | 291 | return rc; |
444 | out: | 292 | |
445 | return err; | 293 | out_free: |
294 | kfree(output.pointer); | ||
295 | return rc; | ||
446 | } | 296 | } |
447 | 297 | ||
448 | /** | 298 | /** |
@@ -461,154 +311,99 @@ out: | |||
461 | * function also waits for idle after writing control and before | 311 | * function also waits for idle after writing control and before |
462 | * writing the remaining registers. | 312 | * writing the remaining registers. |
463 | * | 313 | * |
464 | * LOCKING: TBD: | 314 | * LOCKING: |
465 | * Inherited from caller. | 315 | * EH context. |
316 | * | ||
317 | * RETURNS: | ||
318 | * 0 on success, -errno on failure. | ||
466 | */ | 319 | */ |
467 | static void taskfile_load_raw(struct ata_device *dev, | 320 | static int taskfile_load_raw(struct ata_device *dev, |
468 | const struct taskfile_array *gtf) | 321 | const struct ata_acpi_gtf *gtf) |
469 | { | 322 | { |
470 | struct ata_port *ap = dev->ap; | 323 | struct ata_port *ap = dev->ap; |
471 | struct ata_taskfile tf; | 324 | struct ata_taskfile tf, rtf; |
472 | unsigned int err; | 325 | unsigned int err_mask; |
473 | 326 | ||
474 | if (ata_msg_probe(ap)) | 327 | if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0) |
475 | ata_dev_printk(dev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: " | 328 | && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0) |
476 | "%02x %02x %02x %02x %02x %02x %02x\n", | 329 | && (gtf->tf[6] == 0)) |
477 | __FUNCTION__, | 330 | return 0; |
478 | gtf->tfa[0], gtf->tfa[1], gtf->tfa[2], | ||
479 | gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]); | ||
480 | |||
481 | if ((gtf->tfa[0] == 0) && (gtf->tfa[1] == 0) && (gtf->tfa[2] == 0) | ||
482 | && (gtf->tfa[3] == 0) && (gtf->tfa[4] == 0) && (gtf->tfa[5] == 0) | ||
483 | && (gtf->tfa[6] == 0)) | ||
484 | return; | ||
485 | 331 | ||
486 | ata_tf_init(dev, &tf); | 332 | ata_tf_init(dev, &tf); |
487 | 333 | ||
488 | /* convert gtf to tf */ | 334 | /* convert gtf to tf */ |
489 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */ | 335 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */ |
490 | tf.protocol = ATA_PROT_NODATA; | 336 | tf.protocol = ATA_PROT_NODATA; |
491 | tf.feature = gtf->tfa[0]; /* 0x1f1 */ | 337 | tf.feature = gtf->tf[0]; /* 0x1f1 */ |
492 | tf.nsect = gtf->tfa[1]; /* 0x1f2 */ | 338 | tf.nsect = gtf->tf[1]; /* 0x1f2 */ |
493 | tf.lbal = gtf->tfa[2]; /* 0x1f3 */ | 339 | tf.lbal = gtf->tf[2]; /* 0x1f3 */ |
494 | tf.lbam = gtf->tfa[3]; /* 0x1f4 */ | 340 | tf.lbam = gtf->tf[3]; /* 0x1f4 */ |
495 | tf.lbah = gtf->tfa[4]; /* 0x1f5 */ | 341 | tf.lbah = gtf->tf[4]; /* 0x1f5 */ |
496 | tf.device = gtf->tfa[5]; /* 0x1f6 */ | 342 | tf.device = gtf->tf[5]; /* 0x1f6 */ |
497 | tf.command = gtf->tfa[6]; /* 0x1f7 */ | 343 | tf.command = gtf->tf[6]; /* 0x1f7 */ |
498 | |||
499 | err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0); | ||
500 | if (err && ata_msg_probe(ap)) | ||
501 | ata_dev_printk(dev, KERN_ERR, | ||
502 | "%s: ata_exec_internal failed: %u\n", | ||
503 | __FUNCTION__, err); | ||
504 | } | ||
505 | |||
506 | /** | ||
507 | * do_drive_set_taskfiles - write the drive taskfile settings from _GTF | ||
508 | * @dev: target ATA device | ||
509 | * @gtf_length: total number of bytes of _GTF taskfiles | ||
510 | * @gtf_address: location of _GTF taskfile arrays | ||
511 | * | ||
512 | * This applies to both PATA and SATA drives. | ||
513 | * | ||
514 | * Write {gtf_address, length gtf_length} in groups of | ||
515 | * REGS_PER_GTF bytes. | ||
516 | */ | ||
517 | static int do_drive_set_taskfiles(struct ata_device *dev, | ||
518 | unsigned int gtf_length, | ||
519 | unsigned long gtf_address) | ||
520 | { | ||
521 | struct ata_port *ap = dev->ap; | ||
522 | int err = -ENODEV; | ||
523 | int gtf_count = gtf_length / REGS_PER_GTF; | ||
524 | int ix; | ||
525 | struct taskfile_array *gtf; | ||
526 | 344 | ||
527 | if (ata_msg_probe(ap)) | 345 | if (ata_msg_probe(ap)) |
528 | ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n", | 346 | ata_dev_printk(dev, KERN_DEBUG, "executing ACPI cmd " |
529 | __FUNCTION__, ap->port_no); | 347 | "%02x/%02x:%02x:%02x:%02x:%02x:%02x\n", |
530 | 348 | tf.command, tf.feature, tf.nsect, | |
531 | if (libata_noacpi || !(ap->flags & ATA_FLAG_ACPI_SATA)) | 349 | tf.lbal, tf.lbam, tf.lbah, tf.device); |
532 | return 0; | 350 | |
533 | 351 | rtf = tf; | |
534 | if (!ata_dev_enabled(dev) || (ap->flags & ATA_FLAG_DISABLED)) | 352 | err_mask = ata_exec_internal(dev, &rtf, NULL, DMA_NONE, NULL, 0); |
535 | goto out; | 353 | if (err_mask) { |
536 | if (!gtf_count) /* shouldn't be here */ | 354 | ata_dev_printk(dev, KERN_ERR, |
537 | goto out; | 355 | "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x failed " |
538 | 356 | "(Emask=0x%x Stat=0x%02x Err=0x%02x)\n", | |
539 | if (gtf_length % REGS_PER_GTF) { | 357 | tf.command, tf.feature, tf.nsect, tf.lbal, tf.lbam, |
540 | if (ata_msg_drv(ap)) | 358 | tf.lbah, tf.device, err_mask, rtf.command, rtf.feature); |
541 | ata_dev_printk(dev, KERN_ERR, | 359 | return -EIO; |
542 | "%s: unexpected GTF length (%d)\n", | ||
543 | __FUNCTION__, gtf_length); | ||
544 | goto out; | ||
545 | } | ||
546 | |||
547 | for (ix = 0; ix < gtf_count; ix++) { | ||
548 | gtf = (struct taskfile_array *) | ||
549 | (gtf_address + ix * REGS_PER_GTF); | ||
550 | |||
551 | /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */ | ||
552 | taskfile_load_raw(dev, gtf); | ||
553 | } | 360 | } |
554 | 361 | ||
555 | err = 0; | 362 | return 0; |
556 | out: | ||
557 | return err; | ||
558 | } | 363 | } |
559 | 364 | ||
560 | /** | 365 | /** |
561 | * ata_acpi_exec_tfs - get then write drive taskfile settings | 366 | * ata_acpi_exec_tfs - get then write drive taskfile settings |
562 | * @ap: the ata_port for the drive | 367 | * @dev: target ATA device |
563 | * | 368 | * |
564 | * This applies to both PATA and SATA drives. | 369 | * Evaluate _GTF and excute returned taskfiles. |
370 | * | ||
371 | * LOCKING: | ||
372 | * EH context. | ||
373 | * | ||
374 | * RETURNS: | ||
375 | * Number of executed taskfiles on success, 0 if _GTF doesn't exist or | ||
376 | * doesn't contain valid data. -errno on other errors. | ||
565 | */ | 377 | */ |
566 | int ata_acpi_exec_tfs(struct ata_port *ap) | 378 | static int ata_acpi_exec_tfs(struct ata_device *dev) |
567 | { | 379 | { |
568 | int ix; | 380 | struct ata_acpi_gtf *gtf = NULL; |
569 | int ret = 0; | 381 | void *ptr_to_free = NULL; |
570 | unsigned int gtf_length; | 382 | int gtf_count, i, rc; |
571 | unsigned long gtf_address; | 383 | |
572 | unsigned long obj_loc; | 384 | /* get taskfiles */ |
573 | 385 | rc = ata_dev_get_GTF(dev, >f, &ptr_to_free); | |
574 | if (libata_noacpi) | 386 | if (rc < 0) |
575 | return 0; | 387 | return rc; |
576 | /* | 388 | gtf_count = rc; |
577 | * TBD - implement PATA support. For now, | 389 | |
578 | * we should not run GTF on PATA devices since some | 390 | /* execute them */ |
579 | * PATA require execution of GTM/STM before GTF. | 391 | for (i = 0, rc = 0; i < gtf_count; i++) { |
580 | */ | 392 | int tmp; |
581 | if (!(ap->flags & ATA_FLAG_ACPI_SATA)) | 393 | |
582 | return 0; | 394 | /* ACPI errors are eventually ignored. Run till the |
583 | 395 | * end even after errors. | |
584 | for (ix = 0; ix < ATA_MAX_DEVICES; ix++) { | 396 | */ |
585 | struct ata_device *dev = &ap->device[ix]; | 397 | tmp = taskfile_load_raw(dev, gtf++); |
586 | 398 | if (!rc) | |
587 | if (!ata_dev_enabled(dev)) | 399 | rc = tmp; |
588 | continue; | ||
589 | |||
590 | ret = do_drive_get_GTF(dev, >f_length, >f_address, | ||
591 | &obj_loc); | ||
592 | if (ret < 0) { | ||
593 | if (ata_msg_probe(ap)) | ||
594 | ata_port_printk(ap, KERN_DEBUG, | ||
595 | "%s: get_GTF error (%d)\n", | ||
596 | __FUNCTION__, ret); | ||
597 | break; | ||
598 | } | ||
599 | |||
600 | ret = do_drive_set_taskfiles(dev, gtf_length, gtf_address); | ||
601 | kfree((void *)obj_loc); | ||
602 | if (ret < 0) { | ||
603 | if (ata_msg_probe(ap)) | ||
604 | ata_port_printk(ap, KERN_DEBUG, | ||
605 | "%s: set_taskfiles error (%d)\n", | ||
606 | __FUNCTION__, ret); | ||
607 | break; | ||
608 | } | ||
609 | } | 400 | } |
610 | 401 | ||
611 | return ret; | 402 | kfree(ptr_to_free); |
403 | |||
404 | if (rc == 0) | ||
405 | return gtf_count; | ||
406 | return rc; | ||
612 | } | 407 | } |
613 | 408 | ||
614 | /** | 409 | /** |
@@ -620,62 +415,25 @@ int ata_acpi_exec_tfs(struct ata_port *ap) | |||
620 | * ATM this function never returns a failure. It is an optional | 415 | * ATM this function never returns a failure. It is an optional |
621 | * method and if it fails for whatever reason, we should still | 416 | * method and if it fails for whatever reason, we should still |
622 | * just keep going. | 417 | * just keep going. |
418 | * | ||
419 | * LOCKING: | ||
420 | * EH context. | ||
421 | * | ||
422 | * RETURNS: | ||
423 | * 0 on success, -errno on failure. | ||
623 | */ | 424 | */ |
624 | int ata_acpi_push_id(struct ata_device *dev) | 425 | static int ata_acpi_push_id(struct ata_device *dev) |
625 | { | 426 | { |
626 | struct ata_port *ap = dev->ap; | 427 | struct ata_port *ap = dev->ap; |
627 | acpi_handle handle; | ||
628 | acpi_integer pcidevfn; | ||
629 | int err; | 428 | int err; |
630 | struct device *gdev = ap->host->dev; | ||
631 | u32 dev_adr; | ||
632 | acpi_status status; | 429 | acpi_status status; |
633 | struct acpi_object_list input; | 430 | struct acpi_object_list input; |
634 | union acpi_object in_params[1]; | 431 | union acpi_object in_params[1]; |
635 | 432 | ||
636 | if (libata_noacpi) | ||
637 | return 0; | ||
638 | |||
639 | if (ata_msg_probe(ap)) | 433 | if (ata_msg_probe(ap)) |
640 | ata_dev_printk(dev, KERN_DEBUG, "%s: ix = %d, port#: %d\n", | 434 | ata_dev_printk(dev, KERN_DEBUG, "%s: ix = %d, port#: %d\n", |
641 | __FUNCTION__, dev->devno, ap->port_no); | 435 | __FUNCTION__, dev->devno, ap->port_no); |
642 | 436 | ||
643 | /* Don't continue if not a SATA device. */ | ||
644 | if (!(ap->flags & ATA_FLAG_ACPI_SATA)) { | ||
645 | if (ata_msg_probe(ap)) | ||
646 | ata_dev_printk(dev, KERN_DEBUG, | ||
647 | "%s: Not a SATA device\n", __FUNCTION__); | ||
648 | goto out; | ||
649 | } | ||
650 | |||
651 | /* Don't continue if device has no _ADR method. | ||
652 | * _SDD is intended for known motherboard devices. */ | ||
653 | err = sata_get_dev_handle(gdev, &handle, &pcidevfn); | ||
654 | if (err < 0) { | ||
655 | if (ata_msg_probe(ap)) | ||
656 | ata_dev_printk(dev, KERN_DEBUG, | ||
657 | "%s: sata_get_dev_handle failed (%d\n", | ||
658 | __FUNCTION__, err); | ||
659 | goto out; | ||
660 | } | ||
661 | |||
662 | /* Get this drive's _ADR info, if not already known */ | ||
663 | if (!dev->obj_handle) { | ||
664 | dev_adr = SATA_ADR_RSVD; | ||
665 | err = get_sata_adr(gdev, handle, pcidevfn, dev->devno, ap, dev, | ||
666 | &dev_adr); | ||
667 | if (err < 0 || dev_adr == SATA_ADR_RSVD || | ||
668 | !dev->obj_handle) { | ||
669 | if (ata_msg_probe(ap)) | ||
670 | ata_dev_printk(dev, KERN_DEBUG, | ||
671 | "%s: get_sata_adr failed: " | ||
672 | "err=%d, dev_adr=%u, obj_handle=0x%p\n", | ||
673 | __FUNCTION__, err, dev_adr, | ||
674 | dev->obj_handle); | ||
675 | goto out; | ||
676 | } | ||
677 | } | ||
678 | |||
679 | /* Give the drive Identify data to the drive via the _SDD method */ | 437 | /* Give the drive Identify data to the drive via the _SDD method */ |
680 | /* _SDD: set up input parameters */ | 438 | /* _SDD: set up input parameters */ |
681 | input.count = 1; | 439 | input.count = 1; |
@@ -687,20 +445,150 @@ int ata_acpi_push_id(struct ata_device *dev) | |||
687 | 445 | ||
688 | /* It's OK for _SDD to be missing too. */ | 446 | /* It's OK for _SDD to be missing too. */ |
689 | swap_buf_le16(dev->id, ATA_ID_WORDS); | 447 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
690 | status = acpi_evaluate_object(dev->obj_handle, "_SDD", &input, NULL); | 448 | status = acpi_evaluate_object(dev->acpi_handle, "_SDD", &input, NULL); |
691 | swap_buf_le16(dev->id, ATA_ID_WORDS); | 449 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
692 | 450 | ||
693 | err = ACPI_FAILURE(status) ? -EIO : 0; | 451 | err = ACPI_FAILURE(status) ? -EIO : 0; |
694 | if (err < 0) { | 452 | if (err < 0) |
695 | if (ata_msg_probe(ap)) | 453 | ata_dev_printk(dev, KERN_WARNING, |
696 | ata_dev_printk(dev, KERN_DEBUG, | 454 | "ACPI _SDD failed (AE 0x%x)\n", status); |
697 | "%s _SDD error: status = 0x%x\n", | 455 | |
698 | __FUNCTION__, status); | 456 | return err; |
457 | } | ||
458 | |||
459 | /** | ||
460 | * ata_acpi_on_suspend - ATA ACPI hook called on suspend | ||
461 | * @ap: target ATA port | ||
462 | * | ||
463 | * This function is called when @ap is about to be suspended. All | ||
464 | * devices are already put to sleep but the port_suspend() callback | ||
465 | * hasn't been executed yet. Error return from this function aborts | ||
466 | * suspend. | ||
467 | * | ||
468 | * LOCKING: | ||
469 | * EH context. | ||
470 | * | ||
471 | * RETURNS: | ||
472 | * 0 on success, -errno on failure. | ||
473 | */ | ||
474 | int ata_acpi_on_suspend(struct ata_port *ap) | ||
475 | { | ||
476 | unsigned long flags; | ||
477 | int rc; | ||
478 | |||
479 | /* proceed iff per-port acpi_handle is valid */ | ||
480 | if (!ap->acpi_handle) | ||
481 | return 0; | ||
482 | BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA); | ||
483 | |||
484 | /* store timing parameters */ | ||
485 | rc = ata_acpi_gtm(ap, &ap->acpi_gtm); | ||
486 | |||
487 | spin_lock_irqsave(ap->lock, flags); | ||
488 | if (rc == 0) | ||
489 | ap->pflags |= ATA_PFLAG_GTM_VALID; | ||
490 | else | ||
491 | ap->pflags &= ~ATA_PFLAG_GTM_VALID; | ||
492 | spin_unlock_irqrestore(ap->lock, flags); | ||
493 | |||
494 | if (rc == -ENOENT) | ||
495 | rc = 0; | ||
496 | return rc; | ||
497 | } | ||
498 | |||
499 | /** | ||
500 | * ata_acpi_on_resume - ATA ACPI hook called on resume | ||
501 | * @ap: target ATA port | ||
502 | * | ||
503 | * This function is called when @ap is resumed - right after port | ||
504 | * itself is resumed but before any EH action is taken. | ||
505 | * | ||
506 | * LOCKING: | ||
507 | * EH context. | ||
508 | */ | ||
509 | void ata_acpi_on_resume(struct ata_port *ap) | ||
510 | { | ||
511 | int i; | ||
512 | |||
513 | if (ap->acpi_handle && (ap->pflags & ATA_PFLAG_GTM_VALID)) { | ||
514 | BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA); | ||
515 | |||
516 | /* restore timing parameters */ | ||
517 | ata_acpi_stm(ap, &ap->acpi_gtm); | ||
699 | } | 518 | } |
700 | 519 | ||
701 | /* always return success */ | 520 | /* schedule _GTF */ |
702 | out: | 521 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
703 | return 0; | 522 | ap->device[i].flags |= ATA_DFLAG_ACPI_PENDING; |
704 | } | 523 | } |
705 | 524 | ||
525 | /** | ||
526 | * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration | ||
527 | * @dev: target ATA device | ||
528 | * | ||
529 | * This function is called when @dev is about to be configured. | ||
530 | * IDENTIFY data might have been modified after this hook is run. | ||
531 | * | ||
532 | * LOCKING: | ||
533 | * EH context. | ||
534 | * | ||
535 | * RETURNS: | ||
536 | * Positive number if IDENTIFY data needs to be refreshed, 0 if not, | ||
537 | * -errno on failure. | ||
538 | */ | ||
539 | int ata_acpi_on_devcfg(struct ata_device *dev) | ||
540 | { | ||
541 | struct ata_port *ap = dev->ap; | ||
542 | struct ata_eh_context *ehc = &ap->eh_context; | ||
543 | int acpi_sata = ap->flags & ATA_FLAG_ACPI_SATA; | ||
544 | int rc; | ||
545 | |||
546 | if (!dev->acpi_handle) | ||
547 | return 0; | ||
548 | |||
549 | /* do we need to do _GTF? */ | ||
550 | if (!(dev->flags & ATA_DFLAG_ACPI_PENDING) && | ||
551 | !(acpi_sata && (ehc->i.flags & ATA_EHI_DID_HARDRESET))) | ||
552 | return 0; | ||
553 | |||
554 | /* do _SDD if SATA */ | ||
555 | if (acpi_sata) { | ||
556 | rc = ata_acpi_push_id(dev); | ||
557 | if (rc) | ||
558 | goto acpi_err; | ||
559 | } | ||
560 | |||
561 | /* do _GTF */ | ||
562 | rc = ata_acpi_exec_tfs(dev); | ||
563 | if (rc < 0) | ||
564 | goto acpi_err; | ||
565 | |||
566 | dev->flags &= ~ATA_DFLAG_ACPI_PENDING; | ||
567 | |||
568 | /* refresh IDENTIFY page if any _GTF command has been executed */ | ||
569 | if (rc > 0) { | ||
570 | rc = ata_dev_reread_id(dev, 0); | ||
571 | if (rc < 0) { | ||
572 | ata_dev_printk(dev, KERN_ERR, "failed to IDENTIFY " | ||
573 | "after ACPI commands\n"); | ||
574 | return rc; | ||
575 | } | ||
576 | } | ||
706 | 577 | ||
578 | return 0; | ||
579 | |||
580 | acpi_err: | ||
581 | /* let EH retry on the first failure, disable ACPI on the second */ | ||
582 | if (dev->flags & ATA_DFLAG_ACPI_FAILED) { | ||
583 | ata_dev_printk(dev, KERN_WARNING, "ACPI on devcfg failed the " | ||
584 | "second time, disabling (errno=%d)\n", rc); | ||
585 | |||
586 | dev->acpi_handle = NULL; | ||
587 | |||
588 | /* if port is working, request IDENTIFY reload and continue */ | ||
589 | if (!(ap->pflags & ATA_PFLAG_FROZEN)) | ||
590 | rc = 1; | ||
591 | } | ||
592 | dev->flags |= ATA_DFLAG_ACPI_FAILED; | ||
593 | return rc; | ||
594 | } | ||