View | Details | Raw Unified | Return to bug 145591
Collapse All | Expand All

(-)linux-2.6.15/drivers/ide/ide-acpi.c.orig (+680 lines)
Line 0 Link Here
1
/*
2
 * ide-acpi.c
3
 * Provides ACPI support for IDE drives.
4
 *
5
 * Copyright (C) 2005 Intel Corp.
6
 * Copyright (C) 2005 Randy Dunlap
7
 * Copyright (C) 2006 SUSE Linux Products GmbH
8
 * Copyright (C) 2006 Hannes Reinecke
9
 */
10
11
#include <linux/ata.h>
12
#include <linux/delay.h>
13
#include <linux/device.h>
14
#include <linux/errno.h>
15
#include <linux/kernel.h>
16
#include <acpi/acpi.h>
17
#include <linux/ide.h>
18
#include <linux/pci.h>
19
20
#include <acpi/acpi_bus.h>
21
#include <acpi/acnames.h>
22
#include <acpi/acnamesp.h>
23
#include <acpi/acparser.h>
24
#include <acpi/acexcep.h>
25
#include <acpi/acmacros.h>
26
#include <acpi/actypes.h>
27
28
#define REGS_PER_GTF		7
29
struct taskfile_array {
30
	u8	tfa[REGS_PER_GTF];	/* regs. 0x1f1 - 0x1f7 */
31
};
32
33
struct GTM_buffer {
34
	__u32	PIO_speed0;
35
	__u32	DMA_speed0;
36
	__u32	PIO_speed1;
37
	__u32	DMA_speed1;
38
	__u32	GTM_flags;
39
};
40
41
struct ide_acpi_drive_link {
42
	ide_drive_t	*drive;
43
	acpi_handle	 obj_handle;
44
	u8		 idbuff[512];
45
};
46
47
struct ide_acpi_hwif_link {
48
	ide_hwif_t			*hwif;
49
	acpi_handle			 obj_handle;
50
	struct GTM_buffer		 gtm;
51
	struct ide_acpi_drive_link	 master;
52
	struct ide_acpi_drive_link	 slave;
53
};
54
	
55
#define DEBUGGING	1
56
/* note: adds function name and KERN_DEBUG */
57
#ifdef DEBUGGING
58
#define DEBPRINT(fmt, args...)	\
59
		printk(KERN_DEBUG "%s: " fmt, __FUNCTION__, ## args)
60
#else
61
#define DEBPRINT(fmt, args...)	do {} while (0)
62
#endif	/* DEBUGGING */
63
64
extern int ide_noacpi;
65
extern int ide_noacpitfs;
66
67
/**
68
 * pata_get_dev_handle - finds acpi_handle and PCI device.function
69
 * @dev: device to locate
70
 * @handle: returned acpi_handle for @dev
71
 * @pcidevfn: return PCI device.func for @dev
72
 *
73
 * Returns the ACPI object handle to the corresponding PCI device.
74
 *
75
 * Returns 0 on success, <0 on error.
76
 */
77
static int pata_get_dev_handle(struct device *dev, acpi_handle *handle,
78
			       acpi_integer *pcidevfn)
79
{
80
	unsigned int domain, bus, devnum, func;
81
	acpi_integer addr;
82
	acpi_handle dev_handle, parent_handle;
83
	int scanned;
84
	struct acpi_buffer buffer = {.length = ACPI_ALLOCATE_BUFFER,
85
					.pointer = NULL};
86
	acpi_status status;
87
	struct acpi_device_info	*dinfo = NULL;
88
	int ret = -ENODEV;
89
90
	DEBPRINT("ENTER: dev->bus_id='%s'\n", dev->bus_id);
91
92
	if ((scanned = sscanf(dev->bus_id, "%x:%x:%x.%x",
93
			&domain, &bus, &devnum, &func)) != 4) {
94
		DEBPRINT("sscanf ret. %d\n", scanned);
95
		goto err;
96
	}
97
98
	dev_handle = DEVICE_ACPI_HANDLE(dev);
99
	parent_handle = DEVICE_ACPI_HANDLE(dev->parent);
100
101
	status = acpi_get_object_info(parent_handle, &buffer);
102
	if (ACPI_FAILURE(status)) {
103
		DEBPRINT("get_object_info for parent failed\n");
104
		goto err;
105
	}
106
	dinfo = buffer.pointer;
107
	if (dinfo && (dinfo->valid & ACPI_VALID_ADR) &&
108
	    dinfo->address == bus) {
109
		/* ACPI spec for _ADR for PCI bus: */
110
		addr = (acpi_integer)(devnum << 16 | func);
111
		*pcidevfn = addr;
112
		*handle = dev_handle;
113
	} else {
114
		DEBPRINT("get_object_info for parent has wrong "
115
			" bus: %llu, should be %d\n",
116
			dinfo ? (unsigned long long)dinfo->address : -1ULL,
117
			bus);
118
		goto err;
119
	}
120
121
	DEBPRINT("for dev=0x%x.%x, addr=0x%llx, parent=0x%p, *handle=0x%p\n",
122
		 devnum, func, (unsigned long long)addr,
123
		 dev->parent, *handle);
124
	if (!*handle)
125
		goto err;
126
	ret = 0;
127
err:
128
	acpi_os_free(dinfo);
129
	return ret;
130
}
131
132
/**
133
 * ide_acpi_hwif_get_handle - Get ACPI object handle for a given hwif
134
 * @hwif: device to locate
135
 *
136
 * Retrieves the object handle of a given hwif. According to the ACPI
137
 * spec is the hwif a child of the PCI device.
138
 *
139
 * Returns handle on success, 0 on error.
140
 */
141
acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif)
142
{
143
	struct device		*dev = hwif->gendev.parent;
144
	acpi_handle		dev_handle;
145
	acpi_integer		pcidevfn;
146
	acpi_handle		chan_handle;
147
	int			err;
148
149
	DEBPRINT("ENTER: device %s\n", hwif->name);
150
151
	if (!dev) {
152
		DEBPRINT("no PCI device for %s\n", hwif->name);
153
		return NULL;
154
	}
155
156
	err = pata_get_dev_handle(dev, &dev_handle, &pcidevfn);
157
	if (err < 0) {
158
		DEBPRINT("pata_get_dev_handle failed (%d)\n", err);
159
		return NULL;
160
	}
161
162
	/* get child objects of dev_handle == channel objects,
163
	 * + _their_ children == drive objects */
164
	/* channel is ap->hard_port_no */
165
	chan_handle = acpi_get_child(dev_handle, hwif->channel);
166
	DEBPRINT("chan adr=%d: handle=0x%p\n",
167
		 hwif->channel, chan_handle);
168
169
	return chan_handle;
170
}
171
172
/**
173
 * ide_acpi_drive_get_handle - Get ACPI object handle for a given drive
174
 * @drive: device to locate
175
 *
176
 * Retrieves the object handle of a given drive. According to the ACPI
177
 * spec the drive is a child of the hwif.
178
 *
179
 * Returns handle on success, 0 on error.
180
 */
181
acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive)
182
{
183
	ide_hwif_t	*hwif = HWIF(drive);
184
	int		 port;
185
	acpi_handle	 drive_handle;
186
187
	if (!hwif->acpidata)
188
		return NULL;
189
190
	if (!hwif->acpidata->obj_handle)
191
		return NULL;
192
193
	port = hwif->channel ? drive->dn - 2: drive->dn;
194
195
	DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
196
		 drive->name, hwif->channel, port);
197
198
199
	/* TBD: could also check ACPI object VALID bits */
200
	drive_handle = acpi_get_child(hwif->acpidata->obj_handle, port);
201
	DEBPRINT("drive %s handle 0x%p\n", drive->name, drive_handle);
202
203
	return drive_handle;
204
}
205
206
/**
207
 * do_drive_get_GTF - get the drive bootup default taskfile settings
208
 * @drive: the drive for which the taskfile settings should be retrieved
209
 * @gtf_length: number of bytes of _GTF data returned at @gtf_address
210
 * @gtf_address: buffer containing _GTF taskfile arrays
211
 *
212
 * The _GTF method has no input parameters.
213
 * It returns a variable number of register set values (registers
214
 * hex 1F1..1F7, taskfiles).
215
 * The <variable number> is not known in advance, so have ACPI-CA
216
 * allocate the buffer as needed and return it, then free it later.
217
 *
218
 * The returned @gtf_length and @gtf_address are only valid if the
219
 * function return value is 0.
220
 */
221
int do_drive_get_GTF(ide_drive_t *drive,
222
		     unsigned int *gtf_length, unsigned long *gtf_address,
223
		     unsigned long *obj_loc)
224
{
225
	acpi_status			status;
226
	struct acpi_buffer		output;
227
	union acpi_object 		*out_obj;
228
	ide_hwif_t			*hwif = HWIF(drive);
229
	struct device			*dev = hwif->gendev.parent;
230
	int				err = -ENODEV;
231
	int				port;
232
233
	*gtf_length = 0;
234
	*gtf_address = 0UL;
235
	*obj_loc = 0UL;
236
237
	if (ide_noacpi)
238
		return 0;
239
240
	if (!dev) {
241
		DEBPRINT("no PCI device for %s\n", hwif->name);
242
		goto out;
243
	}
244
245
	if (!hwif->acpidata) {
246
		DEBPRINT("no ACPI data for %s\n", hwif->name);
247
		goto out;
248
	}
249
250
	port = hwif->channel ? drive->dn - 2: drive->dn;
251
252
	if (!drive->acpidata) {
253
		if (port == 0) {
254
			drive->acpidata = &hwif->acpidata->master;
255
			hwif->acpidata->master.drive = drive;
256
		} else {
257
			drive->acpidata = &hwif->acpidata->slave;
258
			hwif->acpidata->slave.drive = drive;
259
		}
260
	}
261
262
	DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
263
		 hwif->name, dev->bus_id, port, hwif->channel);
264
265
	if (!drive->present) {
266
		DEBPRINT("%s drive %d:%d not present\n",
267
			 hwif->name, hwif->channel, port);
268
		goto out;
269
	}
270
271
	/* Get this drive's _ADR info. if not already known. */
272
	if (!drive->acpidata->obj_handle) {
273
		drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
274
		if (!drive->acpidata->obj_handle) {
275
			DEBPRINT("No ACPI object found for %s\n",
276
				 drive->name);
277
			goto out;
278
		}
279
	}
280
281
	/* Setting up output buffer */
282
	output.length = ACPI_ALLOCATE_BUFFER;
283
	output.pointer = NULL;	/* ACPI-CA sets this; save/free it later */
284
285
	/* _GTF has no input parameters */
286
	err = -EIO;
287
	status = acpi_evaluate_object(drive->acpidata->obj_handle, "_GTF",
288
				      NULL, &output);
289
	if (ACPI_FAILURE(status)) {
290
		printk(KERN_DEBUG
291
		       "%s: Run _GTF error: status = 0x%x\n",
292
		       __FUNCTION__, status);
293
		goto out_free;
294
	}
295
296
	if (!output.length || !output.pointer) {
297
		DEBPRINT("Run _GTF: "
298
		       "length or ptr is NULL (0x%llx, 0x%p)\n",
299
		       (unsigned long long)output.length,
300
		       output.pointer);
301
		goto out_free;
302
	}
303
304
	out_obj = output.pointer;
305
	if (out_obj->type != ACPI_TYPE_BUFFER) {
306
		DEBPRINT("Run _GTF: error: "
307
		       "expected object type of ACPI_TYPE_BUFFER, "
308
		       "got 0x%x\n", out_obj->type);
309
		err = -ENOENT;
310
		goto out_free;
311
	}
312
313
	if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
314
	    out_obj->buffer.length % REGS_PER_GTF) {
315
		printk(KERN_ERR
316
		       "%s: unexpected GTF length (%d) or addr (0x%p)\n",
317
		       __FUNCTION__, out_obj->buffer.length,
318
		       out_obj->buffer.pointer);
319
		err = -ENOENT;
320
		goto out_free;
321
	}
322
323
	*gtf_length = out_obj->buffer.length;
324
	*gtf_address = (unsigned long)out_obj->buffer.pointer;
325
	*obj_loc = (unsigned long)out_obj;
326
	DEBPRINT("returning gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
327
		 *gtf_length, *gtf_address, *obj_loc);
328
	err = 0;
329
out_free:
330
	acpi_os_free(output.pointer);
331
out:
332
	return err;
333
}
334
335
/**
336
 * taskfile_load_raw - send taskfile registers to drive
337
 * @drive: drive to which output is sent
338
 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
339
 *
340
 * Outputs IDE taskfile to the drive.
341
 */
342
static int taskfile_load_raw(ide_drive_t *drive,
343
			      const struct taskfile_array *gtf)
344
{
345
	ide_task_t args;
346
	int err = 0;
347
348
	DEBPRINT("(0x1f1-1f7): hex: "
349
	       "%02x %02x %02x %02x %02x %02x %02x\n",
350
	       gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
351
	       gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
352
353
	memset(&args, 0, sizeof(ide_task_t));
354
	args.command_type = IDE_DRIVE_TASK_NO_DATA;
355
	args.data_phase   = TASKFILE_IN;
356
	args.handler      = &task_no_data_intr;
357
358
	/* convert gtf to IDE Taskfile */
359
	args.tfRegister[1] = gtf->tfa[0];	/* 0x1f1 */
360
	args.tfRegister[2] = gtf->tfa[1];	/* 0x1f2 */
361
	args.tfRegister[3] = gtf->tfa[2];	/* 0x1f3 */
362
	args.tfRegister[4] = gtf->tfa[3];	/* 0x1f4 */
363
	args.tfRegister[5] = gtf->tfa[4];	/* 0x1f5 */
364
	args.tfRegister[6] = gtf->tfa[5];	/* 0x1f6 */
365
	args.tfRegister[7] = gtf->tfa[6];	/* 0x1f7 */
366
367
	if (ide_noacpitfs)
368
		return err;
369
370
	err = ide_raw_taskfile(drive, &args, NULL);
371
	if (err)
372
		printk(KERN_ERR "%s: ide_raw_taskfile failed: %u\n",
373
		       __FUNCTION__, err);
374
375
	return err;
376
}
377
378
/**
379
 * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
380
 * @drive: the drive to which the taskfile command should be sent
381
 * @gtf_length: total number of bytes of _GTF taskfiles
382
 * @gtf_address: location of _GTF taskfile arrays
383
 *
384
 * Write {gtf_address, length gtf_length} in groups of
385
 * REGS_PER_GTF bytes.
386
 */
387
static int do_drive_set_taskfiles(ide_drive_t *drive,
388
				  unsigned int gtf_length,
389
				  unsigned long gtf_address)
390
{
391
	int			err = -ENODEV;
392
	int			gtf_count = gtf_length / REGS_PER_GTF;
393
	int			ix;
394
	struct taskfile_array	*gtf;
395
396
	if (ide_noacpi)
397
		return 0;
398
399
	DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
400
401
	if (!drive->present)
402
		goto out;
403
	if (!gtf_count)		/* shouldn't be here */
404
		goto out;
405
406
	DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n",
407
		 gtf_length, gtf_length, gtf_count, gtf_address);
408
409
	if (gtf_length % REGS_PER_GTF) {
410
		printk(KERN_ERR "%s: unexpected GTF length (%d)\n",
411
		       __FUNCTION__, gtf_length);
412
		goto out;
413
	}
414
415
	for (ix = 0; ix < gtf_count; ix++) {
416
		gtf = (struct taskfile_array *)
417
			(gtf_address + ix * REGS_PER_GTF);
418
419
		/* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
420
		err = taskfile_load_raw(drive, gtf);
421
		if (err)
422
			break;
423
	}
424
425
out:
426
	return err;
427
}
428
429
/**
430
 * ide_acpi_exec_tfs - get then write drive taskfile settings
431
 * @drive: the drive for which the taskfile settings should be
432
 *         written.
433
 *
434
 * According to the ACPI spec this should be called after _STM
435
 * has been evaluated for the interface. Some ACPI vendors interpret
436
 * that as a hard requirement and modify the taskfile according
437
 * to the Identify Drive information passed down with _STM.
438
 * So one should really make sure to call this only after _STM has
439
 * been executed.
440
 */
441
int ide_acpi_exec_tfs(ide_drive_t *drive)
442
{
443
	int		ret;
444
	unsigned int	gtf_length;
445
	unsigned long	gtf_address;
446
	unsigned long	obj_loc;
447
448
	if (ide_noacpi)
449
		return 0;
450
451
	DEBPRINT("call get_GTF, drive=%s port=%d\n", drive->name, drive->dn);
452
453
	ret = do_drive_get_GTF(drive, &gtf_length, &gtf_address, &obj_loc);
454
	if (ret < 0) {
455
		DEBPRINT("get_GTF error (%d)\n", ret);
456
		return ret;
457
	}
458
459
	DEBPRINT("call set_taskfiles, drive=%s\n", drive->name);
460
461
	ret = do_drive_set_taskfiles(drive, gtf_length, gtf_address);
462
	acpi_os_free((void *)obj_loc);
463
	if (ret < 0) {
464
		DEBPRINT("set_taskfiles error (%d)\n", ret);
465
	}
466
467
	DEBPRINT("ret=%d\n", ret);
468
469
	return ret;
470
}
471
EXPORT_SYMBOL_GPL(ide_acpi_exec_tfs);
472
473
/**
474
 * ide_acpi_get_timing - get the channel (controller) timings
475
 * @hwif: target IDE interface (channel)
476
 *
477
 * This function executes the _GTM ACPI method for the target channel.
478
 *
479
 */
480
void ide_acpi_get_timing(ide_hwif_t *hwif)
481
{
482
	acpi_status		status;
483
	struct acpi_buffer	output;
484
	union acpi_object 	*out_obj;
485
486
	if (ide_noacpi)
487
		return;
488
489
	DEBPRINT("ENTER:\n");
490
491
	if (!hwif->acpidata) {
492
		DEBPRINT("no ACPI data for %s\n", hwif->name);
493
		return;
494
	}
495
496
	/* Setting up output buffer for _GTM */
497
	output.length = ACPI_ALLOCATE_BUFFER;
498
	output.pointer = NULL;	/* ACPI-CA sets this; save/free it later */
499
500
	/* _GTM has no input parameters */
501
	status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_GTM",
502
				      NULL, &output);
503
504
	DEBPRINT("_GTM status: %d, outptr: 0x%p, outlen: 0x%llx\n",
505
		 status, output.pointer,
506
		 (unsigned long long)output.length);
507
508
	if (ACPI_FAILURE(status)) {
509
		DEBPRINT("Run _GTM error: status = 0x%x\n", status);
510
		return;
511
	}
512
513
	if (!output.length || !output.pointer) {
514
		DEBPRINT("Run _GTM: length or ptr is NULL (0x%llx, 0x%p)\n",
515
		       (unsigned long long)output.length,
516
		       output.pointer);
517
		acpi_os_free(output.pointer);
518
		return;
519
	}
520
521
	out_obj = output.pointer;
522
	if (out_obj->type != ACPI_TYPE_BUFFER) {
523
		acpi_os_free(output.pointer);
524
		DEBPRINT("Run _GTM: error: "
525
		       "expected object type of ACPI_TYPE_BUFFER, "
526
		       "got 0x%x\n", out_obj->type);
527
		return;
528
	}
529
530
	if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
531
	    out_obj->buffer.length != sizeof(struct GTM_buffer)) {
532
		acpi_os_free(output.pointer);
533
		printk(KERN_ERR
534
		       "%s: unexpected _GTM length (0x%x)[should be 0x%x] or addr (0x%p)\n",
535
		       __FUNCTION__, out_obj->buffer.length,
536
		       sizeof(struct GTM_buffer), out_obj->buffer.pointer);
537
		return;
538
	}
539
540
	memcpy(&hwif->acpidata->gtm, out_obj->buffer.pointer,
541
	       sizeof(struct GTM_buffer));
542
543
	DEBPRINT("_GTM info: ptr: 0x%p, len: 0x%x, exp.len: 0x%Zx\n",
544
		 out_obj->buffer.pointer, out_obj->buffer.length, 
545
		 sizeof(struct GTM_buffer));
546
547
	DEBPRINT("_GTM fields: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
548
		 hwif->acpidata->gtm.PIO_speed0,
549
		 hwif->acpidata->gtm.DMA_speed0,
550
		 hwif->acpidata->gtm.PIO_speed1,
551
		 hwif->acpidata->gtm.DMA_speed1,
552
		 hwif->acpidata->gtm.GTM_flags);
553
554
	acpi_os_free(output.pointer);
555
}
556
EXPORT_SYMBOL_GPL(ide_acpi_get_timing);
557
558
/**
559
 * ide_acpi_push_timing - set the channel (controller) timings
560
 * @hwif: target IDE interface (channel)
561
 *
562
 * This function executes the _STM ACPI method for the target channel.
563
 *
564
 * _STM requires Identify Drive data, which has to passed as an argument.
565
 * Unfortunately hd_driveid is a mangled version which we can't readily
566
 * use; hence we'll get the information afresh.
567
 */
568
void ide_acpi_push_timing(ide_hwif_t *hwif)
569
{
570
	int			err;
571
	acpi_status		status;
572
	struct acpi_object_list	input;
573
	union acpi_object 	in_params[3];
574
	struct ide_acpi_drive_link	*master = &hwif->acpidata->master;
575
	struct ide_acpi_drive_link	*slave = &hwif->acpidata->slave;
576
577
	if (ide_noacpi)
578
		return;
579
580
	DEBPRINT("ENTER:\n");
581
582
	if (!hwif->acpidata) {
583
		DEBPRINT("no ACPI data for %s\n", hwif->name);
584
		return;
585
	}
586
587
	if (!master->drive)
588
		master->drive = &hwif->drives[0];
589
590
	if (!slave->drive)
591
		slave->drive = &hwif->drives[1];
592
593
	if (master->drive->present) {
594
		err = taskfile_lib_get_identify(master->drive, master->idbuff);
595
		if (err) {
596
			DEBPRINT("identify device %s failed (%d)\n",
597
				 master->drive->name, err);
598
			return;
599
		}
600
	}
601
		
602
	if (slave->drive->present) {
603
		err = taskfile_lib_get_identify(slave->drive, slave->idbuff);
604
		if (err) {
605
			DEBPRINT("identify device %s failed (%d)\n",
606
				 slave->drive->name, err);
607
			return;
608
		}
609
	}
610
611
	/* Give the GTM buffer + drive Identify data to the channel via the
612
	 * _STM method: */
613
	/* setup input parameters buffer for _STM */
614
	input.count = 3;
615
	input.pointer = in_params;
616
	in_params[0].type = ACPI_TYPE_BUFFER;
617
	in_params[0].buffer.length = sizeof(struct GTM_buffer);
618
	in_params[0].buffer.pointer = (u8 *)&hwif->acpidata->gtm;
619
	in_params[1].type = ACPI_TYPE_BUFFER;
620
	in_params[1].buffer.length = sizeof(struct hd_driveid);
621
	in_params[1].buffer.pointer = (u8 *)&master->idbuff;
622
	in_params[2].type = ACPI_TYPE_BUFFER;
623
	in_params[2].buffer.length = sizeof(struct hd_driveid);
624
	in_params[2].buffer.pointer = (u8 *)&slave->idbuff;
625
	/* Output buffer: _STM has no output */
626
627
	status = acpi_evaluate_object(hwif->acpidata->obj_handle, "_STM",
628
				      &input, NULL);
629
630
	if (ACPI_FAILURE(status)) {
631
		DEBPRINT("Run _STM error: status = 0x%x\n", status);
632
	}
633
	DEBPRINT("_STM status: %d\n", status);
634
}
635
EXPORT_SYMBOL_GPL(ide_acpi_push_timing);
636
637
void ide_acpi_init(ide_hwif_t *hwif)
638
{
639
	int unit;
640
641
	hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL);
642
	if (!hwif->acpidata)
643
		return;
644
645
	hwif->acpidata->obj_handle = ide_acpi_hwif_get_handle(hwif);
646
	if (!hwif->acpidata->obj_handle) {
647
		DEBPRINT("no ACPI object for %s found\n", hwif->name);
648
		kfree(hwif->acpidata);
649
		hwif->acpidata = NULL;
650
		return;
651
	}
652
653
	if (hwif->drives[0].present) {
654
		hwif->acpidata->master.drive = &hwif->drives[0];
655
		hwif->drives[0].acpidata = &hwif->acpidata->master;
656
	}
657
658
	if (hwif->drives[1].present) {
659
		hwif->acpidata->slave.drive = &hwif->drives[1];
660
		hwif->drives[1].acpidata = &hwif->acpidata->slave;
661
	}
662
663
	/*
664
	 * ACPI requires us to call _STM on startup
665
	 */
666
	ide_acpi_get_timing(hwif);
667
	ide_acpi_push_timing(hwif);
668
669
	for (unit = 0; unit < MAX_DRIVES; ++unit) {
670
		ide_drive_t *drive = &hwif->drives[unit];
671
672
		if (drive->present) {
673
674
			/* Execute ACPI startup code */
675
			ide_acpi_exec_tfs(drive);
676
		}
677
			
678
	}
679
}
680
EXPORT_SYMBOL_GPL(ide_acpi_init);
(-)linux-2.6.15/drivers/ide/Makefile.orig (+1 lines)
Lines 22-27 ide-core-$(CONFIG_BLK_DEV_IDEPCI) += set Link Here
22
ide-core-$(CONFIG_BLK_DEV_IDEDMA)	+= ide-dma.o
22
ide-core-$(CONFIG_BLK_DEV_IDEDMA)	+= ide-dma.o
23
ide-core-$(CONFIG_PROC_FS)		+= ide-proc.o
23
ide-core-$(CONFIG_PROC_FS)		+= ide-proc.o
24
ide-core-$(CONFIG_BLK_DEV_IDEPNP)	+= ide-pnp.o
24
ide-core-$(CONFIG_BLK_DEV_IDEPNP)	+= ide-pnp.o
25
ide-core-$(CONFIG_BLK_DEV_IDEACPI)	+= ide-acpi.o
25
26
26
# built-in only drivers from arm/
27
# built-in only drivers from arm/
27
ide-core-$(CONFIG_IDE_ARM)		+= arm/ide_arm.o
28
ide-core-$(CONFIG_IDE_ARM)		+= arm/ide_arm.o
(-)linux-2.6.15/drivers/ide/ide-probe.c.orig (+3 lines)
Lines 1387-1392 static int hwif_init(ide_hwif_t *hwif) Link Here
1387
1387
1388
done:
1388
done:
1389
	init_gendisk(hwif);
1389
	init_gendisk(hwif);
1390
1391
	ide_acpi_init(hwif);
1392
1390
	hwif->present = 1;	/* success */
1393
	hwif->present = 1;	/* success */
1391
	return 1;
1394
	return 1;
1392
1395
(-)linux-2.6.15/drivers/ide/ide.c.orig (+30 lines)
Lines 189-194 int noautodma = 1; Link Here
189
189
190
EXPORT_SYMBOL(noautodma);
190
EXPORT_SYMBOL(noautodma);
191
191
192
#ifdef CONFIG_BLK_DEV_IDEACPI
193
int ide_noacpi = 0;
194
int ide_noacpitfs = 0;
195
#endif
196
192
/*
197
/*
193
 * This is declared extern in ide.h, for access by other IDE modules:
198
 * This is declared extern in ide.h, for access by other IDE modules:
194
 */
199
 */
Lines 1222-1231 EXPORT_SYMBOL(system_bus_clock); Link Here
1222
static int generic_ide_suspend(struct device *dev, pm_message_t state)
1227
static int generic_ide_suspend(struct device *dev, pm_message_t state)
1223
{
1228
{
1224
	ide_drive_t *drive = dev->driver_data;
1229
	ide_drive_t *drive = dev->driver_data;
1230
	ide_hwif_t *hwif = HWIF(drive);
1225
	struct request rq;
1231
	struct request rq;
1226
	struct request_pm_state rqpm;
1232
	struct request_pm_state rqpm;
1227
	ide_task_t args;
1233
	ide_task_t args;
1228
1234
1235
	/* Call ACPI _GTM only once */
1236
	if (!(drive->dn % 2))
1237
		ide_acpi_get_timing(hwif);	
1238
1229
	memset(&rq, 0, sizeof(rq));
1239
	memset(&rq, 0, sizeof(rq));
1230
	memset(&rqpm, 0, sizeof(rqpm));
1240
	memset(&rqpm, 0, sizeof(rqpm));
1231
	memset(&args, 0, sizeof(args));
1241
	memset(&args, 0, sizeof(args));
Lines 1241-1250 static int generic_ide_suspend(struct de Link Here
1241
static int generic_ide_resume(struct device *dev)
1251
static int generic_ide_resume(struct device *dev)
1242
{
1252
{
1243
	ide_drive_t *drive = dev->driver_data;
1253
	ide_drive_t *drive = dev->driver_data;
1254
	ide_hwif_t *hwif = HWIF(drive);
1244
	struct request rq;
1255
	struct request rq;
1245
	struct request_pm_state rqpm;
1256
	struct request_pm_state rqpm;
1246
	ide_task_t args;
1257
	ide_task_t args;
1247
1258
1259
	/* Call ACPI _STM only once */
1260
	if (!(drive->dn % 2))
1261
		ide_acpi_push_timing(hwif);	
1262
1263
	ide_acpi_exec_tfs(drive);
1264
1248
	memset(&rq, 0, sizeof(rq));
1265
	memset(&rq, 0, sizeof(rq));
1249
	memset(&rqpm, 0, sizeof(rqpm));
1266
	memset(&rqpm, 0, sizeof(rqpm));
1250
	memset(&args, 0, sizeof(args));
1267
	memset(&args, 0, sizeof(args));
Lines 1545-1550 static int __init ide_setup(char *s) Link Here
1545
	}
1562
	}
1546
#endif /* CONFIG_BLK_DEV_IDEPCI */
1563
#endif /* CONFIG_BLK_DEV_IDEPCI */
1547
1564
1565
#ifdef CONFIG_BLK_DEV_IDEACPI
1566
	if (!strcmp(s, "ide=noacpi")) {
1567
		printk(" : Disable IDE ACPI support.\n");
1568
		ide_noacpi = 1;
1569
		return 1;
1570
	}
1571
	if (!strcmp(s, "ide=nogtf")) {
1572
		printk(" : Disable IDE ACPI _GTF support.\n");
1573
		ide_noacpitfs = 1;
1574
		return 1;
1575
	}
1576
#endif /* CONFIG_BLK_DEV_IDEACPI */
1577
1548
	if (!strncmp(s, "idewait=", 8)) {
1578
	if (!strncmp(s, "idewait=", 8)) {
1549
		char *dummy;
1579
		char *dummy;
1550
		ide_wait_ms = simple_strtol(s+8, &dummy, 10);
1580
		ide_wait_ms = simple_strtol(s+8, &dummy, 10);
(-)linux-2.6.15/include/linux/ide.h.orig (+25 lines)
Lines 19-24 Link Here
19
#include <linux/device.h>
19
#include <linux/device.h>
20
#include <linux/pci.h>
20
#include <linux/pci.h>
21
#include <linux/completion.h>
21
#include <linux/completion.h>
22
#include <acpi/acpi.h>
22
#include <asm/byteorder.h>
23
#include <asm/byteorder.h>
23
#include <asm/system.h>
24
#include <asm/system.h>
24
#include <asm/io.h>
25
#include <asm/io.h>
Lines 541-546 typedef enum { Link Here
541
struct ide_driver_s;
542
struct ide_driver_s;
542
struct ide_settings_s;
543
struct ide_settings_s;
543
544
545
#ifdef CONFIG_BLK_DEV_IDEACPI
546
struct ide_acpi_drive_link;
547
struct ide_acpi_hwif_link;
548
#endif
549
544
typedef struct ide_drive_s {
550
typedef struct ide_drive_s {
545
	char		name[4];	/* drive name, such as "hda" */
551
	char		name[4];	/* drive name, such as "hda" */
546
        char            driver_req[10];	/* requests specific driver */
552
        char            driver_req[10];	/* requests specific driver */
Lines 637-642 typedef struct ide_drive_s { Link Here
637
643
638
	int		lun;		/* logical unit */
644
	int		lun;		/* logical unit */
639
	int		crc_count;	/* crc counter to reduce drive speed */
645
	int		crc_count;	/* crc counter to reduce drive speed */
646
#ifdef CONFIG_BLK_DEV_IDEACPI
647
	struct ide_acpi_drive_link *acpidata;
648
#endif
640
	struct list_head list;
649
	struct list_head list;
641
	struct device	gendev;
650
	struct device	gendev;
642
	struct completion gendev_rel_comp;	/* to deal with device release() */
651
	struct completion gendev_rel_comp;	/* to deal with device release() */
Lines 802-807 typedef struct hwif_s { Link Here
802
	unsigned dma;
811
	unsigned dma;
803
812
804
	void (*led_act)(void *data, int rw);
813
	void (*led_act)(void *data, int rw);
814
815
#ifdef CONFIG_BLK_DEV_IDEACPI
816
	struct ide_acpi_hwif_link *acpidata;
817
#endif
805
} ____cacheline_internodealigned_in_smp ide_hwif_t;
818
} ____cacheline_internodealigned_in_smp ide_hwif_t;
806
819
807
/*
820
/*
Lines 1293-1298 static inline void ide_dma_verbose(ide_d Link Here
1293
static inline void ide_release_dma(ide_hwif_t *drive) {;}
1306
static inline void ide_release_dma(ide_hwif_t *drive) {;}
1294
#endif
1307
#endif
1295
1308
1309
#ifdef CONFIG_BLK_DEV_IDEACPI
1310
extern int ide_acpi_exec_tfs(ide_drive_t *drive);
1311
extern void ide_acpi_get_timing(ide_hwif_t *hwif);
1312
extern void ide_acpi_push_timing(ide_hwif_t *hwif);
1313
extern void ide_acpi_init(ide_hwif_t *hwif);
1314
#else
1315
static inline int ide_acpi_exec_tfs(ide_drive_t *drive) { return 0; }
1316
static inline void ide_acpi_get_timing(ide_hwif_t *hwif) { ; }
1317
static inline void ide_acpi_push_timing(ide_hwif_t *hwif) { ; }
1318
static inline void ide_acpi_init(ide_hwif_t *hwif) { ; }
1319
#endif
1320
1296
extern int ide_hwif_request_regions(ide_hwif_t *hwif);
1321
extern int ide_hwif_request_regions(ide_hwif_t *hwif);
1297
extern void ide_hwif_release_regions(ide_hwif_t* hwif);
1322
extern void ide_hwif_release_regions(ide_hwif_t* hwif);
1298
extern void ide_unregister (unsigned int index);
1323
extern void ide_unregister (unsigned int index);

Return to bug 145591