Patchwork ahci: fix lst+fis mapping

login
register
mail settings
Submitter Gerd Hoffmann
Date Nov. 19, 2010, 11:06 p.m.
Message ID <1290207997-3984-1-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/72326/
State New
Headers show

Comments

Gerd Hoffmann - Nov. 19, 2010, 11:06 p.m.
The ahci map_page() function checks whenever it got a full page mapped.
This is wrong.   The data structures are much smaller:  command list is
1k and fis is 256 bytes.  Checking whenever we can access that much
bytes without crossing a page border is good enougth.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/ahci.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
Alexander Graf - Nov. 21, 2010, 2:04 a.m.
On 20.11.2010, at 00:06, Gerd Hoffmann wrote:

> The ahci map_page() function checks whenever it got a full page mapped.
> This is wrong.   The data structures are much smaller:  command list is
> 1k and fis is 256 bytes.  Checking whenever we can access that much
> bytes without crossing a page border is good enougth.

Looks good :). Do you want me to incorporate this with the next revision of my patch set or keep it separate?


Alex
Gerd Hoffmann - Nov. 22, 2010, 9:14 a.m.
On 11/21/10 03:04, Alexander Graf wrote:
>
> On 20.11.2010, at 00:06, Gerd Hoffmann wrote:
>
>> The ahci map_page() function checks whenever it got a full page
>> mapped. This is wrong.   The data structures are much smaller:
>> command list is 1k and fis is 256 bytes.  Checking whenever we can
>> access that much bytes without crossing a page border is good
>> enougth.
>
> Looks good :). Do you want me to incorporate this with the next
> revision of my patch set or keep it separate?

Feel free to squash it in.

cheers,
   Gerd

Patch

diff --git a/hw/ahci.c b/hw/ahci.c
index 0ee021e..fdd5572 100644
--- a/hw/ahci.c
+++ b/hw/ahci.c
@@ -411,16 +411,16 @@  static void ahci_check_irq(AHCIState *s)
     }
 }
 
-static void map_page(uint8_t **ptr, uint64_t addr)
+static void map_page(uint8_t **ptr, uint64_t addr, uint32_t wanted)
 {
-    target_phys_addr_t len = 4096;
+    target_phys_addr_t len = wanted;
 
     if (*ptr) {
         cpu_physical_memory_unmap(*ptr, 1, len, len);
     }
 
     *ptr = cpu_physical_memory_map(addr, &len, 1);
-    if (len < 4096) {
+    if (len < wanted) {
         *ptr = NULL;
     }
 }
@@ -435,22 +435,22 @@  static void  ahci_port_write(AHCIState *s, int port, int offset, uint32_t val)
         case PORT_LST_ADDR:
             pr->lst_addr = val;
             map_page(&s->dev[port].lst,
-                     ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr);
+                     ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr, 1024);
             break;
         case PORT_LST_ADDR_HI:
             pr->lst_addr_hi = val;
             map_page(&s->dev[port].lst,
-                     ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr);
+                     ((uint64_t)pr->lst_addr_hi << 32) | pr->lst_addr, 1024);
             break;
         case PORT_FIS_ADDR:
             pr->fis_addr = val;
             map_page(&s->dev[port].res_fis,
-                     ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr);
+                     ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr, 256);
             break;
         case PORT_FIS_ADDR_HI:
             pr->fis_addr_hi = val;
             map_page(&s->dev[port].res_fis,
-                     ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr);
+                     ((uint64_t)pr->fis_addr_hi << 32) | pr->fis_addr, 256);
             break;
         case PORT_IRQ_STAT:
             pr->irq_stat &= ~val;