011fe81
From 3f00de9c207fb4b3f9e45fd775650404ce087aac Mon Sep 17 00:00:00 2001
78a3d7d
From: Vladimir Serbinenko <phcoder@gmail.com>
78a3d7d
Date: Wed, 29 Jan 2014 23:46:17 +0100
58fe9aa
Subject: [PATCH 053/152] 	* grub-core/disk/ahci.c: Add safety cleanups.
78a3d7d
78a3d7d
---
78a3d7d
 ChangeLog             |  4 ++++
78a3d7d
 grub-core/disk/ahci.c | 10 ++++++++++
78a3d7d
 2 files changed, 14 insertions(+)
78a3d7d
78a3d7d
diff --git a/ChangeLog b/ChangeLog
011fe81
index 9bb1817..15300b0 100644
78a3d7d
--- a/ChangeLog
78a3d7d
+++ b/ChangeLog
78a3d7d
@@ -1,5 +1,9 @@
78a3d7d
 2014-01-29  Vladimir Serbinenko  <phcoder@gmail.com>
78a3d7d
 
78a3d7d
+	* grub-core/disk/ahci.c: Add safety cleanups.
78a3d7d
+
78a3d7d
+2014-01-29  Vladimir Serbinenko  <phcoder@gmail.com>
78a3d7d
+
78a3d7d
 	* grub-core/disk/ahci.c: Allocate and clean space for all possible 32
78a3d7d
 	slots to avoid pointing to uninited area.
78a3d7d
 
78a3d7d
diff --git a/grub-core/disk/ahci.c b/grub-core/disk/ahci.c
78a3d7d
index d63fd09..643e691 100644
78a3d7d
--- a/grub-core/disk/ahci.c
78a3d7d
+++ b/grub-core/disk/ahci.c
78a3d7d
@@ -454,6 +454,7 @@ grub_ahci_pciinit (grub_pci_device_t dev,
78a3d7d
 	adevs[i]->hba->ports[adevs[i]->port].fis_base = grub_dma_get_phys (adevs[i]->rfis);
78a3d7d
 	adevs[i]->hba->ports[adevs[i]->port].command_list_base
78a3d7d
 	  = grub_dma_get_phys (adevs[i]->command_list_chunk);
78a3d7d
+	adevs[i]->hba->ports[adevs[i]->port].command_issue = 0;
78a3d7d
 	adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_FRE;
78a3d7d
       }
78a3d7d
 
78a3d7d
@@ -600,6 +601,9 @@ grub_ahci_pciinit (grub_pci_device_t dev,
78a3d7d
 	failed_adevs[i] = adevs[i];
78a3d7d
 	adevs[i] = 0;
78a3d7d
       }
78a3d7d
+
78a3d7d
+  grub_dprintf ("ahci", "cleaning up failed devs\n");
78a3d7d
+
78a3d7d
   for (i = 0; i < nports; i++)
78a3d7d
     if (failed_adevs[i] && (fr_running & (1 << i)))
78a3d7d
       failed_adevs[i]->hba->ports[failed_adevs[i]->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
78a3d7d
@@ -855,6 +859,12 @@ grub_ahci_reset_port (struct grub_ahci_device *dev, int force)
78a3d7d
     {
78a3d7d
       struct grub_disk_ata_pass_through_parms parms2;
78a3d7d
       dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
78a3d7d
+      dev->hba->ports[dev->port].command_issue = 0;
78a3d7d
+      dev->command_list[0].config = 0;
78a3d7d
+      dev->command_table[0].prdt[0].unused = 0;
78a3d7d
+      dev->command_table[0].prdt[0].size = 0;
78a3d7d
+      dev->command_table[0].prdt[0].data_base = 0;
78a3d7d
+
78a3d7d
       endtime = grub_get_time_ms () + 1000;
78a3d7d
       while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
78a3d7d
 	if (grub_get_time_ms () > endtime)
78a3d7d
-- 
37b39b7
1.9.3
78a3d7d