From 25ff76e4d7f8ba7f6c1a2db80bf4a05dac0a0e23 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Sun, 6 Jul 2014 00:07:32 -0700 Subject: [PATCH] Fixing warnings and checking AHCI caps --- include/string.h | 15 +++++++++++++++ sys/dev/ahci.c | 44 +++++++++++++++++++++++++++++++------------- sys/include/kmem.h | 9 +++++++++ sys/kern/libc.c | 4 ++-- 4 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 include/string.h create mode 100644 sys/include/kmem.h diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..d4625ea --- /dev/null +++ b/include/string.h @@ -0,0 +1,15 @@ + +#ifndef __STRING_H__ +#define __STRING_H__ + +#include + +void *memcpy(void *dst, const void *src, size_t len); +void *memset(void *dst, int c, size_t len); + +int strcmp(const char *s1, const char *s2); +char *strcpy(char *to, const char *from); +size_t strlen(const char *str); + +#endif /* __STRING_H__ */ + diff --git a/sys/dev/ahci.c b/sys/dev/ahci.c index 7cd35ba..5379932 100644 --- a/sys/dev/ahci.c +++ b/sys/dev/ahci.c @@ -1,7 +1,9 @@ #include +#include #include +#include #include #include @@ -84,6 +86,9 @@ typedef struct AHCIHostControl uint32_t vs; // Version } AHCIHostControl; +#define AHCI_CAP_S64A 0x80000000 /* Supports 64-bit Addressing */ +#define AHCI_CAP_SNCQ 0x40000000 /* Supports NCQ */ + #define AHCI_GHC_AE 0x80000000 #define AHCI_GHC_IE 0x00000002 #define AHCI_GHC_HR 0x00000001 @@ -320,6 +325,8 @@ AHCI_IssueCommand(AHCI *ahci, int port, SGArray *sga, void *cfis, int len) cl->cmds[0].flag = len >> 2; p->ci = 1; + + return 0; } void @@ -483,15 +490,10 @@ AHCI_Configure(PCIDevice dev) // XXX: Register IRQ // Setup - hc = dev.bars[AHCI_ABAR].base; - ahci->hc = hc; - - // Disable Interrupts - hc->ghc &= ~AHCI_GHC_IE; - - // Enable AHCI Controller - hc->ghc |= AHCI_GHC_AE; + hc = (volatile AHCIHostControl *)(uintptr_t)dev.bars[AHCI_ABAR].base; + ahci->hc = (AHCIHostControl *)hc; + uint32_t caps = hc->cap; uint32_t ports = hc->pi; uint32_t vers = hc->vs; @@ -502,13 +504,29 @@ AHCI_Configure(PCIDevice dev) kprintf("AHCI: Currently only supports %d ports\n", AHCI_MAX_PORTS); } + if (caps & AHCI_CAP_S64A) { + kprintf("AHCI: Supports 64-bit Addressing\n"); + } else { + kprintf("AHCI: Controller does not support 64-bit addressing!\n"); + return; + } + + if (caps & AHCI_CAP_SNCQ) + kprintf("AHCI: Supports NCQ\n"); + + // Disable Interrupts + hc->ghc &= ~AHCI_GHC_IE; + + // Enable AHCI Controller + hc->ghc |= AHCI_GHC_AE; + int p; for (p = 0; p < AHCI_MAX_PORTS; p++) { if (ports & (1 << p)) { - ahci->port[p] = dev.bars[AHCI_ABAR].base + - AHCI_PORT_OFFSET + AHCI_PORT_LENGTH * p; + ahci->port[p] = (AHCIPort *)(uintptr_t)(dev.bars[AHCI_ABAR].base + + AHCI_PORT_OFFSET + AHCI_PORT_LENGTH * p); } else { ahci->port[p] = 0; } @@ -525,18 +543,18 @@ AHCI_Configure(PCIDevice dev) ahci->ctbl[p][c] = (AHCICommandTable *)PAlloc_AllocPage(); memset(ahci->ctbl[p][c], 0, sizeof(AHCICommandTable)); // XXX: VA2PA - ahci->clst[p]->cmds[c].ctba = ahci->ctbl[p][c]; + ahci->clst[p]->cmds[c].ctba = (uint64_t)ahci->ctbl[p][c]; } ahci->clst[p] = (AHCICommandList *)PAlloc_AllocPage(); memset(ahci->clst[p], 0, sizeof(AHCICommandList)); // XXX: VA2PA - port->clba = ahci->clst[p]; + port->clba = (uint64_t)ahci->clst[p]; ahci->rfis[p] = (AHCIRecvFIS *)PAlloc_AllocPage(); memset(ahci->rfis[p], 0, sizeof(AHCIRecvFIS)); // XXX: VA2PA - port->fb = ahci->rfis[p]; + port->fb = (uint64_t)ahci->rfis[p]; } } diff --git a/sys/include/kmem.h b/sys/include/kmem.h new file mode 100644 index 0000000..9c6b957 --- /dev/null +++ b/sys/include/kmem.h @@ -0,0 +1,9 @@ + +#ifndef __KMEM_H__ +#define __KMEM_H__ + +void *PAlloc_AllocPage(); +void PAlloc_FreePage(void *pg); + +#endif /* __KMEM_H__ */ + diff --git a/sys/kern/libc.c b/sys/kern/libc.c index 1fe76ab..b9ca85f 100644 --- a/sys/kern/libc.c +++ b/sys/kern/libc.c @@ -4,7 +4,7 @@ * All rights reserved. */ -#include +#include char * strcpy(char *to, const char *from) @@ -37,7 +37,7 @@ strlen(const char *str) } void * -memset(void *dst, uint8_t c, size_t length) +memset(void *dst, int c, size_t length) { uint8_t *p = (uint8_t *)dst;