aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/ata_piix.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2008-03-24 23:22:49 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-04-17 15:44:17 -0400
commit029cfd6b74fc5c517865fad78cf4a3ea8d9b664a (patch)
tree4a40f44f29321e433497a51d2f6cfe1922ae1d58 /drivers/ata/ata_piix.c
parent68d1d07b510bb57a504588adc2bd2758adea0965 (diff)
libata: implement and use ops inheritance
libata lets low level drivers build ata_port_operations table and register it with libata core layer. This allows low level drivers high level of flexibility but also burdens them with lots of boilerplate entries. This becomes worse for drivers which support related similar controllers which differ slightly. They share most of the operations except for a few. However, the driver still needs to list all operations for each variant. This results in large number of duplicate entries, which is not only inefficient but also error-prone as it becomes very difficult to tell what the actual differences are. This duplicate boilerplates all over the low level drivers also make updating the core layer exteremely difficult and error-prone. When compounded with multi-branched development model, it ends up accumulating inconsistencies over time. Some of those inconsistencies cause immediate problems and fixed. Others just remain there dormant making maintenance increasingly difficult. To rectify the problem, this patch implements ata_port_operations inheritance. To allow LLDs to easily re-use their own ops tables overriding only specific methods, this patch implements poor man's class inheritance. An ops table has ->inherits field which can be set to any ops table as long as it doesn't create a loop. When the host is started, the inheritance chain is followed and any operation which isn't specified is taken from the nearest ancestor which has it specified. This operation is called finalization and done only once per an ops table and the LLD doesn't have to do anything special about it other than making the ops table non-const such that libata can update it. libata provides four base ops tables lower drivers can inherit from - base, sata, pmp, sff and bmdma. To avoid overriding these ops accidentaly, these ops are declared const and LLDs should always inherit these instead of using them directly. After finalization, all the ops table are identical before and after the patch except for setting .irq_handler to ata_interrupt in drivers which didn't use to. The .irq_handler doesn't have any actual effect and the field will soon be removed by later patch. * sata_sx4 is still using old style EH and currently doesn't take advantage of ops inheritance. Signed-off-by: Tejun Heo <htejun@gmail.com>
Diffstat (limited to 'drivers/ata/ata_piix.c')
-rw-r--r--drivers/ata/ata_piix.c149
1 files changed, 14 insertions, 135 deletions
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 9f887b2c92df..bb46b61a7c6b 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -294,155 +294,34 @@ static struct scsi_host_template piix_sht = {
294 ATA_BMDMA_SHT(DRV_NAME), 294 ATA_BMDMA_SHT(DRV_NAME),
295}; 295};
296 296
297static const struct ata_port_operations piix_pata_ops = { 297static struct ata_port_operations piix_pata_ops = {
298 .inherits = &ata_bmdma_port_ops,
299 .cable_detect = ata_cable_40wire,
298 .set_piomode = piix_set_piomode, 300 .set_piomode = piix_set_piomode,
299 .set_dmamode = piix_set_dmamode, 301 .set_dmamode = piix_set_dmamode,
300 .mode_filter = ata_pci_default_filter,
301
302 .tf_load = ata_tf_load,
303 .tf_read = ata_tf_read,
304 .check_status = ata_check_status,
305 .exec_command = ata_exec_command,
306 .dev_select = ata_std_dev_select,
307
308 .bmdma_setup = ata_bmdma_setup,
309 .bmdma_start = ata_bmdma_start,
310 .bmdma_stop = ata_bmdma_stop,
311 .bmdma_status = ata_bmdma_status,
312 .qc_prep = ata_qc_prep,
313 .qc_issue = ata_qc_issue_prot,
314 .data_xfer = ata_data_xfer,
315
316 .freeze = ata_bmdma_freeze,
317 .thaw = ata_bmdma_thaw,
318 .error_handler = piix_pata_error_handler, 302 .error_handler = piix_pata_error_handler,
319 .post_internal_cmd = ata_bmdma_post_internal_cmd, 303};
320 .cable_detect = ata_cable_40wire,
321
322 .irq_clear = ata_bmdma_irq_clear,
323 .irq_on = ata_irq_on,
324 304
325 .port_start = ata_sff_port_start, 305static struct ata_port_operations piix_vmw_ops = {
306 .inherits = &piix_pata_ops,
307 .bmdma_status = piix_vmw_bmdma_status,
326}; 308};
327 309
328static const struct ata_port_operations ich_pata_ops = { 310static struct ata_port_operations ich_pata_ops = {
329 .set_piomode = piix_set_piomode, 311 .inherits = &piix_pata_ops,
330 .set_dmamode = ich_set_dmamode,
331 .mode_filter = ata_pci_default_filter,
332
333 .tf_load = ata_tf_load,
334 .tf_read = ata_tf_read,
335 .check_status = ata_check_status,
336 .exec_command = ata_exec_command,
337 .dev_select = ata_std_dev_select,
338
339 .bmdma_setup = ata_bmdma_setup,
340 .bmdma_start = ata_bmdma_start,
341 .bmdma_stop = ata_bmdma_stop,
342 .bmdma_status = ata_bmdma_status,
343 .qc_prep = ata_qc_prep,
344 .qc_issue = ata_qc_issue_prot,
345 .data_xfer = ata_data_xfer,
346
347 .freeze = ata_bmdma_freeze,
348 .thaw = ata_bmdma_thaw,
349 .error_handler = piix_pata_error_handler,
350 .post_internal_cmd = ata_bmdma_post_internal_cmd,
351 .cable_detect = ich_pata_cable_detect, 312 .cable_detect = ich_pata_cable_detect,
352 313 .set_dmamode = ich_set_dmamode,
353 .irq_clear = ata_bmdma_irq_clear,
354 .irq_on = ata_irq_on,
355
356 .port_start = ata_sff_port_start,
357}; 314};
358 315
359static const struct ata_port_operations piix_sata_ops = { 316static struct ata_port_operations piix_sata_ops = {
360 .tf_load = ata_tf_load, 317 .inherits = &ata_bmdma_port_ops,
361 .tf_read = ata_tf_read,
362 .check_status = ata_check_status,
363 .exec_command = ata_exec_command,
364 .dev_select = ata_std_dev_select,
365
366 .bmdma_setup = ata_bmdma_setup,
367 .bmdma_start = ata_bmdma_start,
368 .bmdma_stop = ata_bmdma_stop,
369 .bmdma_status = ata_bmdma_status,
370 .qc_prep = ata_qc_prep,
371 .qc_issue = ata_qc_issue_prot,
372 .data_xfer = ata_data_xfer,
373
374 .mode_filter = ata_pci_default_filter,
375 .freeze = ata_bmdma_freeze,
376 .thaw = ata_bmdma_thaw,
377 .error_handler = ata_bmdma_error_handler,
378 .post_internal_cmd = ata_bmdma_post_internal_cmd,
379
380 .irq_clear = ata_bmdma_irq_clear,
381 .irq_on = ata_irq_on,
382
383 .port_start = ata_sff_port_start,
384}; 318};
385 319
386static const struct ata_port_operations piix_vmw_ops = { 320static struct ata_port_operations piix_sidpr_sata_ops = {
387 .set_piomode = piix_set_piomode, 321 .inherits = &piix_sata_ops,
388 .set_dmamode = piix_set_dmamode,
389 .mode_filter = ata_pci_default_filter,
390
391 .tf_load = ata_tf_load,
392 .tf_read = ata_tf_read,
393 .check_status = ata_check_status,
394 .exec_command = ata_exec_command,
395 .dev_select = ata_std_dev_select,
396
397 .bmdma_setup = ata_bmdma_setup,
398 .bmdma_start = ata_bmdma_start,
399 .bmdma_stop = ata_bmdma_stop,
400 .bmdma_status = piix_vmw_bmdma_status,
401 .qc_prep = ata_qc_prep,
402 .qc_issue = ata_qc_issue_prot,
403 .data_xfer = ata_data_xfer,
404
405 .freeze = ata_bmdma_freeze,
406 .thaw = ata_bmdma_thaw,
407 .error_handler = piix_pata_error_handler,
408 .post_internal_cmd = ata_bmdma_post_internal_cmd,
409 .cable_detect = ata_cable_40wire,
410
411 .irq_handler = ata_interrupt,
412 .irq_clear = ata_bmdma_irq_clear,
413 .irq_on = ata_irq_on,
414
415 .port_start = ata_sff_port_start,
416};
417
418static const struct ata_port_operations piix_sidpr_sata_ops = {
419 .tf_load = ata_tf_load,
420 .tf_read = ata_tf_read,
421 .check_status = ata_check_status,
422 .exec_command = ata_exec_command,
423 .dev_select = ata_std_dev_select,
424
425 .bmdma_setup = ata_bmdma_setup,
426 .bmdma_start = ata_bmdma_start,
427 .bmdma_stop = ata_bmdma_stop,
428 .bmdma_status = ata_bmdma_status,
429 .qc_prep = ata_qc_prep,
430 .qc_issue = ata_qc_issue_prot,
431 .data_xfer = ata_data_xfer,
432
433 .scr_read = piix_sidpr_scr_read, 322 .scr_read = piix_sidpr_scr_read,
434 .scr_write = piix_sidpr_scr_write, 323 .scr_write = piix_sidpr_scr_write,
435
436 .mode_filter = ata_pci_default_filter,
437 .freeze = ata_bmdma_freeze,
438 .thaw = ata_bmdma_thaw,
439 .error_handler = piix_sidpr_error_handler, 324 .error_handler = piix_sidpr_error_handler,
440 .post_internal_cmd = ata_bmdma_post_internal_cmd,
441
442 .irq_clear = ata_bmdma_irq_clear,
443 .irq_on = ata_irq_on,
444
445 .port_start = ata_sff_port_start,
446}; 325};
447 326
448static const struct piix_map_db ich5_map_db = { 327static const struct piix_map_db ich5_map_db = {