summaryrefslogtreecommitdiff
path: root/compote.c
diff options
context:
space:
mode:
Diffstat (limited to 'compote.c')
-rw-r--r--compote.c71
1 files changed, 14 insertions, 57 deletions
diff --git a/compote.c b/compote.c
index ba825c4..d32987b 100644
--- a/compote.c
+++ b/compote.c
@@ -28,22 +28,6 @@
#include "compote.h"
#include "compote-uapi.h"
-static inline uint32_t nvk_sq_cmd(unsigned subc, unsigned method, unsigned len)
-{
- return ((method >> 2) & 0x1fff) |
- ((len & 0xfff) << 16) |
- ((subc & 0x7) << 13) |
- (0x1 << 29);
-}
-
-static inline uint32_t nvk_ni_cmd(unsigned subc, unsigned method, unsigned len)
-{
- return ((method >> 2) & 0x1fff) |
- ((len & 0xfff) << 16) |
- ((subc & 0x7) << 13) |
- (0x3 << 29);
-}
-
int compote_context_new(compote_context_t **ctxp)
{
struct compote_ioctl_channel_alloc arg;
@@ -185,50 +169,23 @@ int compote_context_execute(compote_context_t *ctx,
return compote_context_ioctl(ctx, COMPOTE_IOCTL_CHAN_EXEC, &arg);
}
-int main(int argc, char *argv[])
+void *malloc_below40(unsigned nbytes)
{
- compote_context_t *ctx;
- compote_mo_t *mo;
- int ret;
+ static unsigned long addr = 16 << 20;
+ void *ptr;
- ret = compote_context_new(&ctx);
- if (ret) {
- return ret;
- }
+ nbytes += ((1 << 12) - 1);
+ nbytes &= ~((1 << 12) - 1);
- ret = compote_mo_new(ctx, &mo, 64 << 10);
- if (ret) {
- goto out;
- }
-
- {
- uint32_t *ptr = mo->ptr;
- uint32_t *sem = &ptr[128 >> 2];
-
- ptr[128 >> 2] = 0xcafedead;
-
- ptr[0] = nvk_sq_cmd(1, 0x10, 4);
- ptr[1] = ((unsigned long)sem) >> 32;
- ptr[2] = ((unsigned long)sem) & 0xffffffff;
- ptr[3] = 0xdeadcafe;
- ptr[4] = 0x00000002;
-
- ret = compote_context_execute(ctx, ptr, 5);
- if (ret) {
- goto out;
- }
-
- for (unsigned c = 0; (c < 10) && (ptr[128 >> 2] != 0xdeadcafe); c++) {
- printf("[%4d] = 0x%08x 0x%08x 0x%08x\n", 128 >> 2, sem[0], sem[1], sem[2]);
- sleep(1);
+ do {
+ if ((addr + nbytes) > (1UL << 40)) {
+ return NULL;
}
- printf("[%4d] = 0x%08x 0x%08x 0x%08x\n", 128 >> 2, sem[0], sem[1], sem[2]);
- }
-
- printf("La compote c'est bon !\n");
+ printf("addr 0x%p\n", (void *)addr);
+ ptr = mmap((void *)addr, nbytes, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
+ addr += nbytes;
+ } while (ptr == MAP_FAILED);
-out:
- compote_mo_del(ctx, &mo);
- compote_context_del(&ctx);
- return ret;
+ return ptr;
}