FirmIO: Use uintptr_t for 64-bit compatibility
parent
2e3b738e76
commit
91abf378f8
|
|
@ -48,6 +48,7 @@ private:
|
|||
};
|
||||
|
||||
struct Msg {
|
||||
using Ref = uintptr_t;
|
||||
enum class Command : uint32_t {
|
||||
ComData = 0xAA000000,
|
||||
ComFree = 0xAA000001,
|
||||
|
|
@ -56,15 +57,15 @@ private:
|
|||
struct Data {
|
||||
uint32_t addr;
|
||||
uint32_t len;
|
||||
uint32_t ref;
|
||||
Ref ref;
|
||||
uint32_t addr1;
|
||||
uint32_t len1;
|
||||
uint32_t ref1;
|
||||
Ref ref1;
|
||||
uint32_t reserved;
|
||||
};
|
||||
struct Free {
|
||||
uint32_t refCount;
|
||||
uint32_t ref[6];
|
||||
Ref ref[6];
|
||||
};
|
||||
union Payload {
|
||||
Data data;
|
||||
|
|
@ -97,12 +98,13 @@ private:
|
|||
|
||||
class Mempool {
|
||||
public:
|
||||
using PhysicalAddress = uintptr_t;
|
||||
static constexpr const size_t BlockSize = 4096;
|
||||
|
||||
Mempool(uint8_t* start, uint32_t size, uint8_t* virt, uint32_t phys);
|
||||
Mempool(uint8_t* start, uint32_t size, uint8_t* virt, PhysicalAddress phys);
|
||||
uint8_t* alloc(uint32_t size);
|
||||
bool free(uint8_t* addr);
|
||||
uint32_t translate(uint8_t* addr) const;
|
||||
PhysicalAddress translate(uint8_t* addr) const;
|
||||
|
||||
private:
|
||||
struct BlockInfo {
|
||||
|
|
@ -118,7 +120,7 @@ private:
|
|||
std::atomic<uint32_t> usedBlocks;
|
||||
|
||||
uint8_t* const virtualAddress;
|
||||
const uint32_t physicalAddress;
|
||||
const PhysicalAddress physicalAddress;
|
||||
};
|
||||
|
||||
int fd = -1;
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ bool FirmIO::writeInternal(const std::vector<uint8_t>& bytes) {
|
|||
Msg msg = { Msg::Command::ComData };
|
||||
msg.payload.data.addr = outMemory->translate(sharedData);
|
||||
msg.payload.data.len = static_cast<uint32_t>(bytes.size());
|
||||
msg.payload.data.ref = reinterpret_cast<uint32_t>(sharedData);
|
||||
msg.payload.data.ref = reinterpret_cast<Msg::Ref>(sharedData);
|
||||
|
||||
if(!out->write(&msg))
|
||||
return false;
|
||||
|
|
@ -325,7 +325,7 @@ bool FirmIO::MsgQueue::isFull() const {
|
|||
return ((info->head + 1) & (info->size - 1)) == info->tail;
|
||||
}
|
||||
|
||||
FirmIO::Mempool::Mempool(uint8_t* start, uint32_t size, uint8_t* virt, uint32_t phys)
|
||||
FirmIO::Mempool::Mempool(uint8_t* start, uint32_t size, uint8_t* virt, PhysicalAddress phys)
|
||||
: blocks(size / BlockSize), usedBlocks(0),
|
||||
virtualAddress(virt), physicalAddress(phys) {
|
||||
size_t idx = 0;
|
||||
|
|
@ -370,6 +370,6 @@ bool FirmIO::Mempool::free(uint8_t* addr) {
|
|||
return true;
|
||||
}
|
||||
|
||||
uint32_t FirmIO::Mempool::translate(uint8_t* addr) const {
|
||||
return reinterpret_cast<uint32_t>(addr - virtualAddress + physicalAddress);
|
||||
FirmIO::Mempool::PhysicalAddress FirmIO::Mempool::translate(uint8_t* addr) const {
|
||||
return reinterpret_cast<PhysicalAddress>(addr - virtualAddress + physicalAddress);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue