From fc512703417b443f7d7f631a5cf8b028ed45885e Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 4 Jul 2016 18:59:49 +0200 Subject: [PATCH] Allow unprivileged use of radeontop via console With appropriate privileges on the /dev/dri/cardN files, it is possible to run radeontop as normal user. At minimum you need read/write permissions: sudo setfacl -m u:$USER:rw /dev/dri/card* You also need to be the DRM Master (i.e. Xorg must not be active on a console). --- README.md | 2 +- auth.c | 31 +++++++++++++++++++++++++++++++ detect.c | 1 + include/radeontop.h | 3 +++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 auth.c diff --git a/README.md b/README.md index fc4adc8..0512517 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ RadeonTop View your GPU utilization, both for the total activity percent and individual blocks. -Requires root rights or other permissions to /dev/mem. +Requires access to /dev/dri/cardN files or /dev/mem (root privileges). Supported cards --------------- diff --git a/auth.c b/auth.c new file mode 100644 index 0000000..45b3c3e --- /dev/null +++ b/auth.c @@ -0,0 +1,31 @@ +/* + Copyright (C) 2016 Peter Wu + + 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, version 3 of the License. + + 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. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "radeontop.h" + +void authenticate_drm(int fd) { + drm_magic_t magic; + + /* Obtain magic for our DRM client. */ + if (drmGetMagic(fd, &magic) < 0) { + return; + } + + /* Try self-authenticate (if we are somehow the master). */ + if (drmAuthMagic(fd, magic) == 0) { + return; + } +} diff --git a/detect.c b/detect.c index d3cc7bd..f77708d 100644 --- a/detect.c +++ b/detect.c @@ -135,6 +135,7 @@ unsigned int init_pci(unsigned char bus, const unsigned char forcemem) { use_ioctl = 0; if (drm_fd >= 0) { + authenticate_drm(drm_fd); uint32_t rreg = 0x8010; use_ioctl = get_drm_value(drm_fd, RADEON_INFO_READ_REG, &rreg); } diff --git a/include/radeontop.h b/include/radeontop.h index bf61bb1..12e7ca9 100644 --- a/include/radeontop.h +++ b/include/radeontop.h @@ -48,6 +48,9 @@ enum { #define RADEON_INFO_READ_REG 0x24 #endif +// auth.c +void authenticate_drm(int fd); + // radeontop.c void die(const char *why); int get_drm_value(int fd, unsigned request, uint32_t *out);