blob: 830ec6ea0ee4694f06de406cf7743a19102a470b (
plain) (
tree)
|
|
/* Copyright 2024 Joshua Bakita
* Implementation of Kernel-specific function implementations
*/
#include "nvdebug_linux.h"
#include <asm/io.h> // For read[l,q] and write[l,q]
// Similar to nvgpu_readl()
// (except we don't try to resolve situations where regs is NULL)
u32 nvdebug_readl(struct nvdebug_state *s, u32 r) {
u32 ret;
if (unlikely(!s->regs || (s->g && !gk20a_regs(s->g)))) {
printk(KERN_ERR "[nvdebug] nvdebug_readl: Unable to read; registers unavailable. Is GPU on?\n");
return -1;
}
ret = readl(s->regs + r);
// According to open-gpu-kernel-modules, the GPU "will return 0xbad in the
// upper 3 nibbles when there is a possible issue". Further code uses the
// middle three nibbles as an error code, and ignores the bottom two.
if ((ret & 0xfff00000) == 0xbad00000) {
printk(KERN_ERR "[nvdebug] nvdebug_readl: Unable to read from register offset %#x; bad data of %#10x\n", r, ret);
// It would be best to check INTR_0_PRI_* error is pending, to verify
// that this was actually a bad read. Possible future work...
// Generally a failure here in the context of nvdebug indicates that a
// register does not exist on this platform, but one can know for sure
// by checking which NV_PPRIV_SYS_PRI_ERROR_CODE_* define the bad read
// matches.
return -1;
}
return ret;
}
// quadword version of nvdebug_readl()
u64 nvdebug_readq(struct nvdebug_state *s, u32 r) {
u64 ret;
if (unlikely(!s->regs || (s->g && !gk20a_regs(s->g)))) {
printk(KERN_ERR "[nvdebug] nvdebug_readq: Unable to read; registers unavailable. Is GPU on?\n");
return -1;
}
// readq seems to always (?) return the uppermost 32 bits as 0, so workaround with readl
ret = readl(s->regs + r);
ret |= ((u64)readl(s->regs + r + 4)) << 32;
// See comment in nvdebug_readl() regarding error checking
if ((ret & 0xfff00000ull) == 0xbad00000ull) {
printk(KERN_ERR "[nvdebug] nvdebug_readq: Unable to read from register offset %#x; bad data of %#18llx\n", r, ret);
return -1;
}
return ret;
}
// Similar to nvgpu_writel()
void nvdebug_writel(struct nvdebug_state *s, u32 r, u32 v) {
if (unlikely(!s->regs || (s->g && !gk20a_regs(s->g)))) {
printk(KERN_ERR "[nvdebug] nvdebug_writel: Unable to write; registers unavailable. Is GPU on?\n");
return;
}
writel_relaxed(v, s->regs + r);
wmb();
}
// quadword version of nvdebug_writel()
// XXX: Not clear this works on all platforms
void nvdebug_writeq(struct nvdebug_state *s, u32 r, u64 v) {
if (unlikely(!s->regs || (s->g && !gk20a_regs(s->g)))) {
printk(KERN_ERR "[nvdebug] nvdebug_writeq: Unable to write; registers unavailable. Is GPU on?\n");
return;
}
writeq_relaxed(v, s->regs + r);
wmb();
}
|