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