Fixing warnings and checking AHCI caps
This commit is contained in:
parent
504d962949
commit
25ff76e4d7
15
include/string.h
Normal file
15
include/string.h
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
#ifndef __STRING_H__
|
||||
#define __STRING_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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__ */
|
||||
|
@ -1,7 +1,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <kassert.h>
|
||||
#include <kmem.h>
|
||||
#include <pci.h>
|
||||
#include <sga.h>
|
||||
|
||||
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
9
sys/include/kmem.h
Normal file
9
sys/include/kmem.h
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
#ifndef __KMEM_H__
|
||||
#define __KMEM_H__
|
||||
|
||||
void *PAlloc_AllocPage();
|
||||
void PAlloc_FreePage(void *pg);
|
||||
|
||||
#endif /* __KMEM_H__ */
|
||||
|
@ -4,7 +4,7 @@
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user