Skip to content

Instantly share code, notes, and snippets.

@JJL772
Created December 5, 2024 02:27

Revisions

  1. JJL772 revised this gist Dec 5, 2024. 1 changed file with 1 addition and 13 deletions.
    14 changes: 1 addition & 13 deletions kernel-warnings.cpp
    Original file line number Diff line number Diff line change
    @@ -32,14 +32,14 @@ int main(int argc, char** argv)
    return -1;
    }

    #ifdef DMA_MAP
    uint32_t count, size;
    auto** buffs = dmaMapDma(fd, &count, &size);
    if (!buffs || buffs == MAP_FAILED) {
    perror("dmaMapDma failed");
    exit(1);
    }

    // This is unnecessary, but done for testing. you should see warnings immediately after the memory is mapped.
    for (int b = 0; b < count; ++b) {
    auto* buf = (uint8_t*)buffs[b];
    for (int i = 0; i < size; ++i) {
    @@ -53,18 +53,6 @@ int main(int argc, char** argv)
    }
    }
    dmaUnMapDma(fd, buffs);
    #else
    auto* ptr = dmaMapRegister(fd, AXI_VERSION_OFFSET, 0x1000);
    if (!ptr || ptr == MAP_FAILED) {
    perror("Unable to map memory");
    exit(1);
    }

    auto* scr = static_cast<uint32_t*>(ptr) + 0x1;
    //*scr = 0xDEADBEEF;

    dmaUnMapRegister(fd, ptr, 0x1000);
    #endif

    close(fd);

  2. JJL772 created this gist Dec 5, 2024.
    72 changes: 72 additions & 0 deletions kernel-warnings.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    #include "getopt.h"

    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>

    #include "DmaDriver.h"

    #define AXI_VERSION_OFFSET 0x20000

    #define DMA_MAP

    int main(int argc, char** argv)
    {
    char dev[256] = "/dev/datagpu_0";
    int o = 0;
    while ((o = getopt(argc, argv, "d:")) != -1) {
    switch (o) {
    case 'd':
    strcpy(dev, optarg);
    break;
    default:
    break;
    }
    }

    printf("Opening %s\n", dev);

    int fd;
    if ((fd = open(dev, O_RDWR)) < 0) {
    perror("Could not open device");
    return -1;
    }

    #ifdef DMA_MAP
    uint32_t count, size;
    auto** buffs = dmaMapDma(fd, &count, &size);
    if (!buffs || buffs == MAP_FAILED) {
    perror("dmaMapDma failed");
    exit(1);
    }

    for (int b = 0; b < count; ++b) {
    auto* buf = (uint8_t*)buffs[b];
    for (int i = 0; i < size; ++i) {
    buf[i] = 0xAA;
    }

    for (int i = 0; i < size; ++i) {
    if (buf[i] != 0xAA) {
    printf("Bad b=%d, i=%d\n", b,i);
    }
    }
    }
    dmaUnMapDma(fd, buffs);
    #else
    auto* ptr = dmaMapRegister(fd, AXI_VERSION_OFFSET, 0x1000);
    if (!ptr || ptr == MAP_FAILED) {
    perror("Unable to map memory");
    exit(1);
    }

    auto* scr = static_cast<uint32_t*>(ptr) + 0x1;
    //*scr = 0xDEADBEEF;

    dmaUnMapRegister(fd, ptr, 0x1000);
    #endif

    close(fd);

    return 0;
    }