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