aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-12-18 02:33:03 -0500
committerJeff Garzik <jeff@garzik.org>2008-01-23 05:24:12 -0500
commit7c77fa4d51b1480bcec2e898c94d6912fe063c16 (patch)
treed7d18fb22c8df2425878d02f4b415c06efa56457
parent9cde9ed151e170f2e2a530f7ec0032dfbe9f443b (diff)
libata: separate out ata_acpi_gtm_xfermask() from pacpi_discover_modes()
Finding out matching transfer mode from ACPI GTM values is useful for other purposes too. Separate out the function and timing tables from pata_acpi::pacpi_discover_modes(). Other than checking shared-configuration bit after doing ata_acpi_gtm() in pacpi_discover_modes() which should be safe, this patch doesn't introduce any behavior change. Signed-off-by: Tejun Heo <htejun@gmail.com> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Jeff Garzik <jeff@garzik.org>
-rw-r--r--drivers/ata/libata-acpi.c78
-rw-r--r--drivers/ata/pata_acpi.c66
-rw-r--r--include/linux/libata.h25
3 files changed, 114 insertions, 55 deletions
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index ebc4dfcf2f19..d6697baf243d 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -441,6 +441,84 @@ static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf)
441 return rc; 441 return rc;
442} 442}
443 443
444/* Welcome to ACPI, bring a bucket */
445const unsigned int ata_acpi_pio_cycle[7] = {
446 600, 383, 240, 180, 120, 100, 80
447};
448EXPORT_SYMBOL_GPL(ata_acpi_pio_cycle);
449
450const unsigned int ata_acpi_mwdma_cycle[5] = {
451 480, 150, 120, 100, 80
452};
453EXPORT_SYMBOL_GPL(ata_acpi_mwdma_cycle);
454
455const unsigned int ata_acpi_udma_cycle[7] = {
456 120, 80, 60, 45, 30, 20, 15
457};
458EXPORT_SYMBOL_GPL(ata_acpi_udma_cycle);
459
460/**
461 * ata_acpi_gtm_xfermode - determine xfermode from GTM parameter
462 * @dev: target device
463 * @gtm: GTM parameter to use
464 *
465 * Determine xfermask for @dev from @gtm.
466 *
467 * LOCKING:
468 * None.
469 *
470 * RETURNS:
471 * Determined xfermask.
472 */
473unsigned long ata_acpi_gtm_xfermask(struct ata_device *dev,
474 const struct ata_acpi_gtm *gtm)
475{
476 int unit, i;
477 u32 t;
478 unsigned long mask = (0x7f << ATA_SHIFT_UDMA) | (0x7 << ATA_SHIFT_MWDMA) | (0x1F << ATA_SHIFT_PIO);
479
480 /* we always use the 0 slot for crap hardware */
481 unit = dev->devno;
482 if (!(gtm->flags & 0x10))
483 unit = 0;
484
485 /* start by scanning for PIO modes */
486 for (i = 0; i < 7; i++) {
487 t = gtm->drive[unit].pio;
488 if (t <= ata_acpi_pio_cycle[i]) {
489 mask |= (2 << (ATA_SHIFT_PIO + i)) - 1;
490 break;
491 }
492 }
493
494 /* See if we have MWDMA or UDMA data. We don't bother with
495 * MWDMA if UDMA is available as this means the BIOS set UDMA
496 * and our error changedown if it works is UDMA to PIO anyway.
497 */
498 if (gtm->flags & (1 << (2 * unit))) {
499 /* MWDMA */
500 for (i = 0; i < 5; i++) {
501 t = gtm->drive[unit].dma;
502 if (t <= ata_acpi_mwdma_cycle[i]) {
503 mask |= (2 << (ATA_SHIFT_MWDMA + i)) - 1;
504 break;
505 }
506 }
507 } else {
508 /* UDMA */
509 for (i = 0; i < 7; i++) {
510 t = gtm->drive[unit].dma;
511 if (t <= ata_acpi_udma_cycle[i]) {
512 mask |= (2 << (ATA_SHIFT_UDMA + i)) - 1;
513 break;
514 }
515 }
516 }
517
518 return mask;
519}
520EXPORT_SYMBOL_GPL(ata_acpi_gtm_xfermask);
521
444/** 522/**
445 * ata_acpi_cbl_80wire - Check for 80 wire cable 523 * ata_acpi_cbl_80wire - Check for 80 wire cable
446 * @ap: Port to check 524 * @ap: Port to check
diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
index e4542ab9c7f8..a4737a3d31cb 100644
--- a/drivers/ata/pata_acpi.c
+++ b/drivers/ata/pata_acpi.c
@@ -81,17 +81,6 @@ static void pacpi_error_handler(struct ata_port *ap)
81 NULL, ata_std_postreset); 81 NULL, ata_std_postreset);
82} 82}
83 83
84/* Welcome to ACPI, bring a bucket */
85static const unsigned int pio_cycle[7] = {
86 600, 383, 240, 180, 120, 100, 80
87};
88static const unsigned int mwdma_cycle[5] = {
89 480, 150, 120, 100, 80
90};
91static const unsigned int udma_cycle[7] = {
92 120, 80, 60, 45, 30, 20, 15
93};
94
95/** 84/**
96 * pacpi_discover_modes - filter non ACPI modes 85 * pacpi_discover_modes - filter non ACPI modes
97 * @adev: ATA device 86 * @adev: ATA device
@@ -103,56 +92,20 @@ static const unsigned int udma_cycle[7] = {
103 92
104static unsigned long pacpi_discover_modes(struct ata_port *ap, struct ata_device *adev) 93static unsigned long pacpi_discover_modes(struct ata_port *ap, struct ata_device *adev)
105{ 94{
106 int unit = adev->devno;
107 struct pata_acpi *acpi = ap->private_data; 95 struct pata_acpi *acpi = ap->private_data;
108 int i;
109 u32 t;
110 unsigned long mask = (0x7f << ATA_SHIFT_UDMA) | (0x7 << ATA_SHIFT_MWDMA) | (0x1F << ATA_SHIFT_PIO);
111
112 struct ata_acpi_gtm probe; 96 struct ata_acpi_gtm probe;
97 unsigned int xfer_mask;
113 98
114 probe = acpi->gtm; 99 probe = acpi->gtm;
115 100
116 /* We always use the 0 slot for crap hardware */
117 if (!(probe.flags & 0x10))
118 unit = 0;
119
120 ata_acpi_gtm(ap, &probe); 101 ata_acpi_gtm(ap, &probe);
121 102
122 /* Start by scanning for PIO modes */ 103 xfer_mask = ata_acpi_gtm_xfermask(adev, &probe);
123 for (i = 0; i < 7; i++) {
124 t = probe.drive[unit].pio;
125 if (t <= pio_cycle[i]) {
126 mask |= (2 << (ATA_SHIFT_PIO + i)) - 1;
127 break;
128 }
129 }
130 104
131 /* See if we have MWDMA or UDMA data. We don't bother with MWDMA 105 if (xfer_mask & (0xF8 << ATA_SHIFT_UDMA))
132 if UDMA is availabe as this means the BIOS set UDMA and our
133 error changedown if it works is UDMA to PIO anyway */
134 if (probe.flags & (1 << (2 * unit))) {
135 /* MWDMA */
136 for (i = 0; i < 5; i++) {
137 t = probe.drive[unit].dma;
138 if (t <= mwdma_cycle[i]) {
139 mask |= (2 << (ATA_SHIFT_MWDMA + i)) - 1;
140 break;
141 }
142 }
143 } else {
144 /* UDMA */
145 for (i = 0; i < 7; i++) {
146 t = probe.drive[unit].dma;
147 if (t <= udma_cycle[i]) {
148 mask |= (2 << (ATA_SHIFT_UDMA + i)) - 1;
149 break;
150 }
151 }
152 }
153 if (mask & (0xF8 << ATA_SHIFT_UDMA))
154 ap->cbl = ATA_CBL_PATA80; 106 ap->cbl = ATA_CBL_PATA80;
155 return mask; 107
108 return xfer_mask;
156} 109}
157 110
158/** 111/**
@@ -185,7 +138,8 @@ static void pacpi_set_piomode(struct ata_port *ap, struct ata_device *adev)
185 unit = 0; 138 unit = 0;
186 139
187 /* Now stuff the nS values into the structure */ 140 /* Now stuff the nS values into the structure */
188 acpi->gtm.drive[unit].pio = pio_cycle[adev->pio_mode - XFER_PIO_0]; 141 acpi->gtm.drive[unit].pio =
142 ata_acpi_pio_cycle[adev->pio_mode - XFER_PIO_0];
189 ata_acpi_stm(ap, &acpi->gtm); 143 ata_acpi_stm(ap, &acpi->gtm);
190 /* See what mode we actually got */ 144 /* See what mode we actually got */
191 ata_acpi_gtm(ap, &acpi->gtm); 145 ata_acpi_gtm(ap, &acpi->gtm);
@@ -207,10 +161,12 @@ static void pacpi_set_dmamode(struct ata_port *ap, struct ata_device *adev)
207 161
208 /* Now stuff the nS values into the structure */ 162 /* Now stuff the nS values into the structure */
209 if (adev->dma_mode >= XFER_UDMA_0) { 163 if (adev->dma_mode >= XFER_UDMA_0) {
210 acpi->gtm.drive[unit].dma = udma_cycle[adev->dma_mode - XFER_UDMA_0]; 164 acpi->gtm.drive[unit].dma =
165 ata_acpi_udma_cycle[adev->dma_mode - XFER_UDMA_0];
211 acpi->gtm.flags |= (1 << (2 * unit)); 166 acpi->gtm.flags |= (1 << (2 * unit));
212 } else { 167 } else {
213 acpi->gtm.drive[unit].dma = mwdma_cycle[adev->dma_mode - XFER_MW_DMA_0]; 168 acpi->gtm.drive[unit].dma =
169 ata_acpi_mwdma_cycle[adev->dma_mode - XFER_MW_DMA_0];
214 acpi->gtm.flags &= ~(1 << (2 * unit)); 170 acpi->gtm.flags &= ~(1 << (2 * unit));
215 } 171 }
216 ata_acpi_stm(ap, &acpi->gtm); 172 ata_acpi_stm(ap, &acpi->gtm);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index bdb7c6e13993..8022e5b2224d 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -961,6 +961,10 @@ enum {
961 961
962/* libata-acpi.c */ 962/* libata-acpi.c */
963#ifdef CONFIG_ATA_ACPI 963#ifdef CONFIG_ATA_ACPI
964extern const unsigned int ata_acpi_pio_cycle[7];
965extern const unsigned int ata_acpi_mwdma_cycle[5];
966extern const unsigned int ata_acpi_udma_cycle[7];
967
964static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap) 968static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
965{ 969{
966 if (ap->pflags & ATA_PFLAG_INIT_GTM_VALID) 970 if (ap->pflags & ATA_PFLAG_INIT_GTM_VALID)
@@ -970,12 +974,33 @@ static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
970extern int ata_acpi_cbl_80wire(struct ata_port *ap); 974extern int ata_acpi_cbl_80wire(struct ata_port *ap);
971int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm); 975int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm);
972int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm); 976int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm);
977unsigned long ata_acpi_gtm_xfermask(struct ata_device *dev,
978 const struct ata_acpi_gtm *gtm);
979
973#else 980#else
974static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap) 981static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
975{ 982{
976 return NULL; 983 return NULL;
977} 984}
978static inline int ata_acpi_cbl_80wire(struct ata_port *ap) { return 0; } 985static inline int ata_acpi_cbl_80wire(struct ata_port *ap) { return 0; }
986
987static inline int ata_acpi_stm(const struct ata_port *ap,
988 struct ata_acpi_gtm *stm)
989{
990 return -ENOSYS;
991}
992
993static inline int ata_acpi_gtm(const struct ata_port *ap,
994 struct ata_acpi_gtm *stm)
995{
996 return -ENOSYS;
997}
998
999static inline unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
1000 const struct ata_acpi_gtm *gtm)
1001{
1002 return 0;
1003}
979#endif 1004#endif
980 1005
981#ifdef CONFIG_PCI 1006#ifdef CONFIG_PCI