1,036 changes: 664 additions & 372 deletions repos/os/src/drivers/nvme/main.cc

Large diffs are not rendered by default.

100 changes: 0 additions & 100 deletions repos/os/src/drivers/nvme/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,106 +30,6 @@ namespace Util {
virtual void free(Genode::Ram_dataspace_capability) = 0;
};

/*
* Wrap Bit_array into a convinient Bitmap allocator
*/
template <unsigned BITS>
struct Bitmap
{
struct Full : Genode::Exception { };

static constexpr addr_t INVALID { BITS - 1 };
Genode::Bit_array<BITS> _array { };
size_t _used { 0 };

addr_t _find_free(size_t const bits)
{
for (size_t i = 0; i < BITS; i += bits) {
if (_array.get(i, bits)) { continue; }
return i;
}
throw Full();
}

/**
* Return index from where given number of bits was allocated
*
* \param bits number of bits to allocate
*
* \return index of start bit
*/
addr_t alloc(size_t const bits)
{
addr_t const start = _find_free(bits);
_array.set(start, bits);
_used += bits;
return start;
}

/**
* Free given number of bits from start index
*
* \param start index of the start bit
* \param bits number of bits to free
*/
void free(addr_t const start, size_t const bits)
{
_used -= bits;
_array.clear(start, bits);
}
};

/*
* Wrap array into convinient interface
*
* The used datatype T must implement the following methods:
*
* bool valid() const returns true if the object is valid
* void invalidate() adjusts the object so that valid() returns false
*/
template <typename T, size_t CAP>
struct Slots
{
T _entries[CAP] { };

/**
* Lookup slot
*/
template <typename FUNC>
T *lookup(FUNC const &func)
{
for (size_t i = 0; i < CAP; i++) {
if (!_entries[i].valid()) { continue; }
if ( func(_entries[i])) { return &_entries[i]; }
}
return nullptr;
}

/**
* Get free slot
*/
T *get()
{
for (size_t i = 0; i < CAP; i++) {
if (!_entries[i].valid()) { return &_entries[i]; }
}
return nullptr;
}

/**
* Iterate over all slots until FUNC returns true
*/
template <typename FUNC>
bool for_each(FUNC const &func)
{
for (size_t i = 0; i < CAP; i++) {
if (!_entries[i].valid()) { continue; }
if ( func(_entries[i])) { return true; }
}
return false;
}
};

/**
* Extract string from memory
*
Expand Down