Skip to content

Instantly share code, notes, and snippets.

@four0four
Last active June 1, 2023 21:18
Show Gist options
  • Save four0four/6bb30f67dff7e58664a4711eefde7cb8 to your computer and use it in GitHub Desktop.
Save four0four/6bb30f67dff7e58664a4711eefde7cb8 to your computer and use it in GitHub Desktop.

Revisions

  1. four0four revised this gist Jun 1, 2023. No changes.
  2. four0four revised this gist Jun 1, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion smurw-gpu.c
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,7 @@ int main(int argc, char* argv[])
    do_write = 1;
    }

    if((fd = open(filename, O_RDWR | O_SYNC)) == -1) exit(-1);
    if((fd = open(filename, O_RDWR | O_SYNC)) == -1) exit(-1);
    //fprintf(stderr, "%s opened.\n", filename);


  3. four0four revised this gist Jun 1, 2023. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions smurw-gpu.c
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,6 @@ int main(int argc, char* argv[])
    int fd = -1;
    char *filename = argv[1];
    uint32_t target = strtoul(argv[2], 0, 0);
    size_t map_size = 0x1000;
    uint32_t writeval = 0;
    int do_write = 0;

    @@ -49,7 +48,7 @@ int main(int argc, char* argv[])


    void *map_base =
    mmap(0, map_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

    //fprintf(stderr, "%p\n", map_base);

  4. four0four created this gist Jun 1, 2023.
    71 changes: 71 additions & 0 deletions smurw-gpu.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    /* smutool Tool for SMU
    * Copyright (C) 2015 Damien Zammit <[email protected]>
    * Copyright (C) 2023 Sheep Sun <[email protected]>
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    * See <http://www.gnu.org/licenses/>.
    */

    #include <stdio.h>
    #include <inttypes.h>
    #include <pci/pci.h>
    #include <fcntl.h>
    #include <sys/mman.h>
    #include <sys/io.h>
    #include <stdlib.h>
    #include <unistd.h>


    #define SMU_DATA 0x204
    #define SMU_ADDR 0x200


    int main(int argc, char* argv[])
    {

    int fd = -1;
    char *filename = argv[1];
    uint32_t target = strtoul(argv[2], 0, 0);
    size_t map_size = 0x1000;
    uint32_t writeval = 0;
    int do_write = 0;


    if(argc > 3) {
    writeval = strtoul(argv[3], 0, 0);
    do_write = 1;
    }

    if((fd = open(filename, O_RDWR | O_SYNC)) == -1) exit(-1);
    //fprintf(stderr, "%s opened.\n", filename);


    void *map_base =
    mmap(0, map_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

    //fprintf(stderr, "%p\n", map_base);

    volatile uint32_t *smu_data_m = map_base + SMU_DATA;
    volatile uint32_t *smu_addr_m = map_base + SMU_ADDR;
    if (do_write == 0) {
    *smu_addr_m = target;
    uint32_t res = *smu_data_m;
    //fprintf(stderr, "[%p] -> 0x%08x\n",target, res) ;
    printf("0x%08x\n",res);
    } else {
    *smu_addr_m = target;
    *smu_data_m = writeval;
    //fprintf(stderr, "0x%08x -> [%p] (-> 0x%08x)\n", writeval, target, *smu_data_m);
    }

    //fprintf(stderr, "exiting\n");
    return 0;
    }