[denali] Add a stub client for denali
This commit is contained in:
parent
a202bf2371
commit
45cf2115da
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
class MappedMemoryRegion {
|
||||
public:
|
||||
|
@ -8,6 +9,7 @@ class MappedMemoryRegion {
|
|||
static MappedMemoryRegion DirectPhysical(uint64_t phys_addr, uint64_t size);
|
||||
static MappedMemoryRegion ContiguousPhysical(uint64_t size);
|
||||
static MappedMemoryRegion Default(uint64_t size);
|
||||
static MappedMemoryRegion FromCapability(z_cap_t vmmo_cap);
|
||||
|
||||
MappedMemoryRegion() {}
|
||||
// TODO: Disallow copy before doing any cleanup here.
|
||||
|
|
|
@ -35,3 +35,11 @@ MappedMemoryRegion MappedMemoryRegion::Default(uint64_t size) {
|
|||
|
||||
return MappedMemoryRegion(vmmo_cap, 0, vaddr, size);
|
||||
}
|
||||
|
||||
MappedMemoryRegion MappedMemoryRegion::FromCapability(z_cap_t vmmo_cap) {
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
|
||||
|
||||
// FIXME: get the size here.
|
||||
return MappedMemoryRegion(vmmo_cap, 0, vaddr, 0);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ add_executable(denali
|
|||
|
||||
target_include_directories(denali
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
target_link_libraries(denali
|
||||
cxx
|
||||
|
@ -20,3 +20,19 @@ set_target_properties(denali PROPERTIES
|
|||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
||||
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
|
||||
)
|
||||
|
||||
add_library(libdenali
|
||||
client/denali_client.cpp
|
||||
)
|
||||
|
||||
target_include_directories(libdenali
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
target_link_libraries(libdenali
|
||||
mammoth_lib)
|
||||
|
||||
set_target_properties(libdenali PROPERTIES
|
||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
||||
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
|
||||
)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#include "denali/denali_client.h"
|
||||
|
||||
#include <mammoth/debug.h>
|
||||
|
||||
#include "denali/denali.h"
|
||||
|
||||
MappedMemoryRegion DenaliClient::ReadSectors(uint64_t device_id, uint64_t lba,
|
||||
uint64_t num_sectors) {
|
||||
DenaliRead read{
|
||||
.device_id = device_id,
|
||||
.lba = lba,
|
||||
.size = num_sectors,
|
||||
};
|
||||
check(channel_.WriteStruct(&read));
|
||||
|
||||
DenaliReadResponse resp;
|
||||
uint64_t mem_cap;
|
||||
check(channel_.ReadStructAndCap(&resp, &mem_cap));
|
||||
|
||||
return MappedMemoryRegion::FromCapability(mem_cap);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <mammoth/channel.h>
|
||||
#include <mammoth/memory_region.h>
|
||||
|
||||
class DenaliClient {
|
||||
public:
|
||||
DenaliClient(const Channel& channel) : channel_(channel) {}
|
||||
|
||||
MappedMemoryRegion ReadSectors(uint64_t device_id, uint64_t lba,
|
||||
uint64_t num_sectors);
|
||||
|
||||
private:
|
||||
Channel channel_;
|
||||
};
|
Loading…
Reference in New Issue