AHCI: Use fls() from BitUtils.

This commit is contained in:
Augustin Cavalier 2024-10-19 10:54:26 -04:00
parent 2cac2468d1
commit 09b0f82c10
3 changed files with 3 additions and 17 deletions

View File

@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <new>
#include <util/BitUtils.h>
#define TRACE(a...) dprintf("ahci: " a)
#define FLOW(a...) dprintf("ahci: " a)
@ -335,7 +336,8 @@ AHCIController::ResetController()
if (fPCIVendorID == PCI_VENDOR_INTEL) {
// Intel PCS—Port Control and Status
// SATA port enable bits must be set
int portCount = std::max(fls(fRegs->pi), 1 + (int)((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK));
int portCount = std::max((int)fls(fRegs->pi),
1 + (int)((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK));
if (portCount > 8) {
// TODO: fix this when specification available
TRACE("don't know how to enable SATA ports 9 to %d\n", portCount);

View File

@ -126,17 +126,3 @@ swap_words(void *data, size_t size)
word++;
}
}
int
fls(unsigned mask)
{
if (mask == 0)
return 0;
int pos = 1;
while (mask != 1) {
mask >>= 1;
pos++;
}
return pos;
}

View File

@ -20,8 +20,6 @@ status_t sg_memcpy(const physical_entry *sgTable, int sgCount, const void *data,
void swap_words(void *data, size_t size);
int fls(unsigned mask);
#ifdef __cplusplus
}
#endif