Skip to content

Commit 6e0c6f0

Browse files
committed
[libamc] Provide a convenience API around asking the kernel for a physical memory region
1 parent cf729a1 commit 6e0c6f0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

programs/subprojects/libamc/libamc.c

+15
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,18 @@ bool libamc_handle_message(amc_message_t* msg) {
125125
}
126126
return false;
127127
}
128+
129+
void amc_alloc_physical_range(uintptr_t buffer_size, uintptr_t* out_phys_base, uintptr_t* out_virt_base) {
130+
printf("amc_alloc_physical_range(buffer_size=%p, out_phys=%p, out_virt=%p)\n", (void*)buffer_size, out_phys_base, out_virt_base);
131+
assert(out_phys_base && out_virt_base, "out-parameters must be provided");
132+
amc_alloc_physical_range_request_t req = {
133+
.event = AMC_ALLOC_PHYSICAL_RANGE_REQUEST,
134+
.size = buffer_size
135+
};
136+
amc_message_send(AXLE_CORE_SERVICE_NAME, &req, sizeof(req));
137+
amc_message_t* out_resp;
138+
amc_message_await__u32_event(AXLE_CORE_SERVICE_NAME, AMC_ALLOC_PHYSICAL_RANGE_RESPONSE, &out_resp);
139+
amc_alloc_physical_range_response_t* phys_range_info = (amc_alloc_physical_range_response_t*)out_resp->body;
140+
*out_phys_base = phys_range_info->phys_base;
141+
*out_virt_base = phys_range_info->virt_base;
142+
}

programs/subprojects/libamc/libamc.h

+3
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ void amc_msg_u32_5__request_response_sync(
5252

5353
bool libamc_handle_message(amc_message_t* msg);
5454

55+
// Convenience helpers around messages to core
56+
void amc_alloc_physical_range(uintptr_t buffer_size, uintptr_t* out_phys_base, uintptr_t* out_virt_base);
57+
5558
#endif

0 commit comments

Comments
 (0)