Lines 1214-1219
Link Here
|
1214 |
|
1214 |
|
1215 |
EXPORT_SYMBOL(system_bus_clock); |
1215 |
EXPORT_SYMBOL(system_bus_clock); |
1216 |
|
1216 |
|
|
|
1217 |
#if 1 |
1218 |
#include <linux/acpi.h> |
1219 |
#define DBG(x...) printk(x) |
1220 |
static int ide_acpi_find_device(struct device *dev, acpi_handle *handle) |
1221 |
{ |
1222 |
int i, tmp; |
1223 |
acpi_integer addr; |
1224 |
|
1225 |
if (sscanf(dev->bus_id, "%u.%u", &tmp, &i) != 2) |
1226 |
return -ENODEV; |
1227 |
|
1228 |
addr = i; |
1229 |
*handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr); |
1230 |
if (!*handle) |
1231 |
return -ENODEV; |
1232 |
return 0; |
1233 |
} |
1234 |
|
1235 |
/* This assumes the ide controller is a PCI device */ |
1236 |
static int ide_acpi_find_channel(struct device *dev, acpi_handle *handle) |
1237 |
{ |
1238 |
int num; |
1239 |
int channel; |
1240 |
acpi_integer addr; |
1241 |
|
1242 |
num = sscanf(dev->bus_id, "ide%x", &channel); |
1243 |
|
1244 |
if (num != 1 || !dev->parent) |
1245 |
return -ENODEV; |
1246 |
addr = channel; |
1247 |
*handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr); |
1248 |
if (!*handle) |
1249 |
return -ENODEV; |
1250 |
return 0; |
1251 |
} |
1252 |
|
1253 |
static struct acpi_bus_type ide_acpi_bus = { |
1254 |
.bus = &ide_bus_type, |
1255 |
.find_device = ide_acpi_find_device, |
1256 |
.find_bridge = ide_acpi_find_channel, |
1257 |
}; |
1258 |
|
1259 |
static int __init ide_acpi_init(void) |
1260 |
{ |
1261 |
return register_acpi_bus_type(&ide_acpi_bus); |
1262 |
} |
1263 |
|
1264 |
#define MAX_DEVICES 10 |
1265 |
#define GTM_LEN (sizeof(u32) * 5) |
1266 |
static struct acpi_ide_stat { |
1267 |
acpi_handle handle; /* channel device"s handle */ |
1268 |
u32 gtm[GTM_LEN/sizeof(u32)]; /* info from _GTM */ |
1269 |
struct hd_driveid id_buff[2]; |
1270 |
int channel_handled; |
1271 |
} device_state[MAX_DEVICES]; |
1272 |
|
1273 |
static struct acpi_ide_stat *ide_get_acpi_state(acpi_handle handle) |
1274 |
{ |
1275 |
int i; |
1276 |
for (i = 0; i < MAX_DEVICES; i ++) |
1277 |
if (device_state[i].handle == handle) |
1278 |
break; |
1279 |
if (i < MAX_DEVICES) |
1280 |
return &device_state[i]; |
1281 |
for (i = 0; i < MAX_DEVICES; i ++) |
1282 |
if (device_state[i].handle == NULL) |
1283 |
break; |
1284 |
if (i >= MAX_DEVICES) |
1285 |
return NULL; |
1286 |
|
1287 |
memset(&device_state[i], 0, sizeof(struct acpi_ide_stat)); |
1288 |
return &device_state[i]; |
1289 |
} |
1290 |
|
1291 |
int acpi_ide_suspend(struct device *dev) |
1292 |
{ |
1293 |
acpi_handle handle, parent_handle; |
1294 |
struct acpi_ide_stat *stat; |
1295 |
acpi_status status; |
1296 |
struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
1297 |
union acpi_object *package; |
1298 |
ide_drive_t *drive = dev->driver_data; |
1299 |
int drive_id = 0; |
1300 |
|
1301 |
handle = DEVICE_ACPI_HANDLE(dev); |
1302 |
if (!handle) { |
1303 |
DBG("IDE device ACPI handler is NULL\n"); |
1304 |
return -ENODEV; |
1305 |
} |
1306 |
if (ACPI_FAILURE(acpi_get_parent(handle, &parent_handle))) { |
1307 |
printk(KERN_ERR "ACPI get parent handler error\n"); |
1308 |
return -ENODEV; |
1309 |
} |
1310 |
stat = ide_get_acpi_state(parent_handle); |
1311 |
if (stat == NULL) |
1312 |
return -ENODEV; |
1313 |
if (stat->channel_handled) { |
1314 |
drive_id = 1; |
1315 |
goto id; |
1316 |
} |
1317 |
|
1318 |
status = acpi_evaluate_object(parent_handle, "_GTM", NULL, &buffer); |
1319 |
if (ACPI_FAILURE(status)) { |
1320 |
printk(KERN_ERR "Error evaluating _GTM\n"); |
1321 |
return -ENODEV; |
1322 |
} |
1323 |
package = (union acpi_object *) buffer.pointer; |
1324 |
if (package->buffer.length != GTM_LEN) { |
1325 |
printk(KERN_ERR "Buffer length returned by _GTM is wrong\n"); |
1326 |
kfree(buffer.pointer); |
1327 |
return -ENODEV; |
1328 |
} |
1329 |
memcpy(stat->gtm, package->buffer.pointer, GTM_LEN); |
1330 |
stat->handle = parent_handle; |
1331 |
stat->channel_handled = 1; |
1332 |
kfree(buffer.pointer); |
1333 |
id: |
1334 |
taskfile_lib_get_identify(drive, &stat->id_buff[drive_id]); |
1335 |
DBG("GTM info %x,%x,%x,%x,%x\n", stat->gtm[0], |
1336 |
stat->gtm[1], stat->gtm[2], |
1337 |
stat->gtm[3], stat->gtm[4]); |
1338 |
return 0; |
1339 |
} |
1340 |
|
1341 |
static int acpi_ide_stm(struct acpi_ide_stat *stat) |
1342 |
{ |
1343 |
struct acpi_object_list input; |
1344 |
union acpi_object params[3]; |
1345 |
acpi_status status; |
1346 |
|
1347 |
input.count = 3; |
1348 |
input.pointer = params; |
1349 |
params[0].type = ACPI_TYPE_BUFFER; |
1350 |
params[0].buffer.length = sizeof(stat->gtm); |
1351 |
params[0].buffer.pointer = (char*)stat->gtm; |
1352 |
|
1353 |
params[1].type = ACPI_TYPE_BUFFER; |
1354 |
params[1].buffer.length = sizeof(stat->id_buff[0]); |
1355 |
params[1].buffer.pointer = (char *)&stat->id_buff[0]; |
1356 |
|
1357 |
params[2].type = ACPI_TYPE_BUFFER; |
1358 |
params[2].buffer.length = sizeof(stat->id_buff[1]); |
1359 |
params[2].buffer.pointer = (char *)&stat->id_buff[1]; |
1360 |
|
1361 |
status = acpi_evaluate_object(stat->handle, "_STM", &input, NULL); |
1362 |
if (ACPI_FAILURE(status)) { |
1363 |
printk(KERN_ERR "Evaluating _STM error\n"); |
1364 |
return -ENODEV; |
1365 |
} |
1366 |
return 0; |
1367 |
} |
1368 |
|
1369 |
static int acpi_ide_gtf(acpi_handle handle, ide_drive_t *drive) |
1370 |
{ |
1371 |
struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; |
1372 |
ide_task_t args; |
1373 |
int index = 0; |
1374 |
unsigned char *data; |
1375 |
union acpi_object *package = NULL; |
1376 |
acpi_status status; |
1377 |
|
1378 |
status = acpi_evaluate_object(handle, "_GTF", NULL, &output); |
1379 |
if (ACPI_FAILURE(status)) { |
1380 |
printk(KERN_ERR "evaluate _GTF error\n"); |
1381 |
return -ENODEV; |
1382 |
} |
1383 |
package = (union acpi_object *) output.pointer; |
1384 |
if (package->type != ACPI_TYPE_BUFFER |
1385 |
|| (package->buffer.length % 7) != 0) { |
1386 |
kfree(output.pointer); |
1387 |
printk(KERN_ERR "_GTF returned value is wrong\n"); |
1388 |
return -ENODEV; |
1389 |
} |
1390 |
printk("start GTF\n"); |
1391 |
|
1392 |
data = package->buffer.pointer; |
1393 |
while (index < package->buffer.length) { |
1394 |
memset(&args, 0, sizeof(ide_task_t)); |
1395 |
args.tfRegister[IDE_ERROR_OFFSET] = data[index]; |
1396 |
args.tfRegister[IDE_NSECTOR_OFFSET] = data[index + 1]; |
1397 |
args.tfRegister[IDE_SECTOR_OFFSET] = data[index + 2]; |
1398 |
args.tfRegister[IDE_LCYL_OFFSET] = data[index + 3]; |
1399 |
args.tfRegister[IDE_HCYL_OFFSET] = data[index + 4]; |
1400 |
args.tfRegister[IDE_SELECT_OFFSET] = data[index + 5]; |
1401 |
args.tfRegister[IDE_STATUS_OFFSET] = data[index + 6]; |
1402 |
args.command_type = IDE_DRIVE_TASK_NO_DATA; |
1403 |
args.handler = &task_no_data_intr; |
1404 |
printk("data %x,%x,%x,%x,%x,%x,%x\n", |
1405 |
data[index], data[index+1], data[index+2], |
1406 |
data[index+3],data[index+4],data[index+5], |
1407 |
data[index+6]); |
1408 |
/* submit command request */ |
1409 |
// printk("return value %d\n", ide_raw_taskfile(drive, &args, NULL)); |
1410 |
index += 7; |
1411 |
} |
1412 |
kfree(output.pointer); |
1413 |
return 0; |
1414 |
} |
1415 |
|
1416 |
int acpi_ide_resume(struct device *dev) |
1417 |
{ |
1418 |
acpi_handle handle, parent_handle; |
1419 |
struct acpi_ide_stat *stat; |
1420 |
ide_drive_t *drive = dev->driver_data; |
1421 |
|
1422 |
handle = DEVICE_ACPI_HANDLE(dev); |
1423 |
if (!handle) { |
1424 |
DBG("IDE device ACPI handler is NULL\n"); |
1425 |
return -ENODEV; |
1426 |
} |
1427 |
if (ACPI_FAILURE(acpi_get_parent(handle, &parent_handle))) { |
1428 |
printk(KERN_ERR "ACPI get parent handler error\n"); |
1429 |
return -ENODEV; |
1430 |
} |
1431 |
stat = ide_get_acpi_state(parent_handle); |
1432 |
if (stat == NULL || stat->handle != parent_handle) |
1433 |
return -ENODEV; |
1434 |
|
1435 |
if (stat->channel_handled == 0) { |
1436 |
stat->handle = NULL; |
1437 |
goto gtf; |
1438 |
} |
1439 |
DBG("Start STM\n"); |
1440 |
if (acpi_ide_stm(stat)) |
1441 |
return -ENODEV; |
1442 |
stat->channel_handled = 0; |
1443 |
gtf: |
1444 |
return acpi_ide_gtf(handle, drive); |
1445 |
} |
1446 |
#endif |
1447 |
|
1217 |
static int generic_ide_suspend(struct device *dev, pm_message_t state) |
1448 |
static int generic_ide_suspend(struct device *dev, pm_message_t state) |
1218 |
{ |
1449 |
{ |
1219 |
ide_drive_t *drive = dev->driver_data; |
1450 |
ide_drive_t *drive = dev->driver_data; |
Lines 1230-1235
Link Here
|
1230 |
rqpm.pm_step = ide_pm_state_start_suspend; |
1461 |
rqpm.pm_step = ide_pm_state_start_suspend; |
1231 |
rqpm.pm_state = state.event; |
1462 |
rqpm.pm_state = state.event; |
1232 |
|
1463 |
|
|
|
1464 |
acpi_ide_suspend(dev); |
1233 |
return ide_do_drive_cmd(drive, &rq, ide_wait); |
1465 |
return ide_do_drive_cmd(drive, &rq, ide_wait); |
1234 |
} |
1466 |
} |
1235 |
|
1467 |
|
Lines 1239-1245
Link Here
|
1239 |
struct request rq; |
1471 |
struct request rq; |
1240 |
struct request_pm_state rqpm; |
1472 |
struct request_pm_state rqpm; |
1241 |
ide_task_t args; |
1473 |
ide_task_t args; |
1242 |
|
1474 |
acpi_ide_resume(dev); |
1243 |
memset(&rq, 0, sizeof(rq)); |
1475 |
memset(&rq, 0, sizeof(rq)); |
1244 |
memset(&rqpm, 0, sizeof(rqpm)); |
1476 |
memset(&rqpm, 0, sizeof(rqpm)); |
1245 |
memset(&args, 0, sizeof(args)); |
1477 |
memset(&args, 0, sizeof(args)); |
Lines 1922-1927
Link Here
|
1922 |
devfs_mk_dir("ide"); |
2154 |
devfs_mk_dir("ide"); |
1923 |
system_bus_speed = ide_system_bus_speed(); |
2155 |
system_bus_speed = ide_system_bus_speed(); |
1924 |
|
2156 |
|
|
|
2157 |
ide_acpi_init(); |
1925 |
bus_register(&ide_bus_type); |
2158 |
bus_register(&ide_bus_type); |
1926 |
|
2159 |
|
1927 |
init_ide_data(); |
2160 |
init_ide_data(); |