mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-07-23 09:56:02 +00:00
lib/intel_* Use igt checks and macros
Various stuff all over. Most done with the igt.cocci spatch, but with a few fixups by hand. And add igt_core.h includes where needed. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
parent
baa6f8b34f
commit
71ac5de5a4
@ -455,7 +455,7 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
|
|||||||
* The kms id of the created framebuffer.
|
* The kms id of the created framebuffer.
|
||||||
*/
|
*/
|
||||||
unsigned int igt_create_fb(int fd, int width, int height, uint32_t format,
|
unsigned int igt_create_fb(int fd, int width, int height, uint32_t format,
|
||||||
unsigned int tiling, struct igt_fb *fb)
|
unsigned tiling, struct igt_fb *fb)
|
||||||
{
|
{
|
||||||
return igt_create_fb_with_bo_size(fd, width, height, format, tiling, fb, 0);
|
return igt_create_fb_with_bo_size(fd, width, height, format, tiling, fb, 0);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "i915_drm.h"
|
#include "i915_drm.h"
|
||||||
|
|
||||||
#include "intel_chipset.h"
|
#include "intel_chipset.h"
|
||||||
|
#include "igt_core.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:intel_chipset
|
* SECTION:intel_chipset
|
||||||
@ -74,11 +75,8 @@ intel_get_pci_device(void)
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = pci_system_init();
|
error = pci_system_init();
|
||||||
if (error != 0) {
|
igt_fail_on_f(error != 0,
|
||||||
fprintf(stderr, "Couldn't initialize PCI system: %s\n",
|
"Couldn't initialize PCI system\n");
|
||||||
strerror(error));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Grab the graphics card. Try the canonical slot first, then
|
/* Grab the graphics card. Try the canonical slot first, then
|
||||||
* walk the entire PCI bus for a matching device. */
|
* walk the entire PCI bus for a matching device. */
|
||||||
@ -105,11 +103,8 @@ intel_get_pci_device(void)
|
|||||||
errx(1, "Couldn't find graphics card");
|
errx(1, "Couldn't find graphics card");
|
||||||
|
|
||||||
error = pci_device_probe(pci_dev);
|
error = pci_device_probe(pci_dev);
|
||||||
if (error != 0) {
|
igt_fail_on_f(error != 0,
|
||||||
fprintf(stderr, "Couldn't probe graphics card: %s\n",
|
"Couldn't probe graphics card\n");
|
||||||
strerror(error));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pci_dev->vendor_id != 0x8086)
|
if (pci_dev->vendor_id != 0x8086)
|
||||||
errx(1, "Graphics card is non-intel");
|
errx(1, "Graphics card is non-intel");
|
||||||
@ -145,7 +140,7 @@ intel_get_drm_devid(int fd)
|
|||||||
gp.value = (int *)&devid;
|
gp.value = (int *)&devid;
|
||||||
|
|
||||||
ret = ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
|
ret = ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
|
||||||
assert(ret == 0);
|
igt_assert(ret == 0);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "intel_io.h"
|
#include "intel_io.h"
|
||||||
#include "intel_reg.h"
|
#include "intel_reg.h"
|
||||||
|
#include "igt_core.h"
|
||||||
|
|
||||||
#define TIMEOUT_US 500000
|
#define TIMEOUT_US 500000
|
||||||
|
|
||||||
@ -33,8 +35,7 @@ static int vlv_sideband_rw(uint32_t port, uint8_t opcode, uint32_t addr,
|
|||||||
(bar << IOSF_BAR_SHIFT);
|
(bar << IOSF_BAR_SHIFT);
|
||||||
|
|
||||||
if (intel_register_read(VLV_IOSF_DOORBELL_REQ) & IOSF_SB_BUSY) {
|
if (intel_register_read(VLV_IOSF_DOORBELL_REQ) & IOSF_SB_BUSY) {
|
||||||
fprintf(stderr, "warning: pcode (%s) mailbox access failed\n",
|
igt_warn("warning: pcode (%s) mailbox access failed\n", is_read ? "read" : "write");
|
||||||
is_read ? "read" : "write");
|
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +52,7 @@ static int vlv_sideband_rw(uint32_t port, uint8_t opcode, uint32_t addr,
|
|||||||
timeout < TIMEOUT_US);
|
timeout < TIMEOUT_US);
|
||||||
|
|
||||||
if (timeout >= TIMEOUT_US) {
|
if (timeout >= TIMEOUT_US) {
|
||||||
fprintf(stderr, "timeout waiting for pcode %s (%d) to finish\n",
|
igt_warn("timeout waiting for pcode %s (%d) to finish\n", is_read ? "read" : "write", addr);
|
||||||
is_read ? "read" : "write", addr);
|
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include "intel_io.h"
|
#include "intel_io.h"
|
||||||
|
#include "igt_core.h"
|
||||||
#include "igt_debugfs.h"
|
#include "igt_debugfs.h"
|
||||||
#include "intel_chipset.h"
|
#include "intel_chipset.h"
|
||||||
|
|
||||||
@ -93,18 +94,13 @@ intel_mmio_use_dump_file(char *file)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
fd = open(file, O_RDWR);
|
fd = open(file, O_RDWR);
|
||||||
if (fd == -1) {
|
igt_fail_on_f(fd == -1,
|
||||||
fprintf(stderr, "Couldn't open %s: %s\n", file,
|
"Couldn't open %s\n", file);
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fstat(fd, &st);
|
fstat(fd, &st);
|
||||||
mmio = mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
|
mmio = mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
|
||||||
if (mmio == MAP_FAILED) {
|
igt_fail_on_f(mmio == MAP_FAILED,
|
||||||
fprintf(stderr, "Couldn't mmap %s: %s\n", file,
|
"Couldn't mmap %s\n", file);
|
||||||
strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,11 +141,8 @@ intel_mmio_use_pci_bar(struct pci_device *pci_dev)
|
|||||||
PCI_DEV_MAP_FLAG_WRITABLE,
|
PCI_DEV_MAP_FLAG_WRITABLE,
|
||||||
&mmio);
|
&mmio);
|
||||||
|
|
||||||
if (error != 0) {
|
igt_fail_on_f(error != 0,
|
||||||
fprintf(stderr, "Couldn't map MMIO region: %s\n",
|
"Couldn't map MMIO region\n");
|
||||||
strerror(error));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -180,7 +173,7 @@ intel_register_access_init(struct pci_device *pci_dev, int safe)
|
|||||||
if (mmio == NULL)
|
if (mmio == NULL)
|
||||||
intel_mmio_use_pci_bar(pci_dev);
|
intel_mmio_use_pci_bar(pci_dev);
|
||||||
|
|
||||||
assert(mmio != NULL);
|
igt_assert(mmio != NULL);
|
||||||
|
|
||||||
if (mmio_data.inited)
|
if (mmio_data.inited)
|
||||||
return -1;
|
return -1;
|
||||||
@ -254,10 +247,10 @@ intel_register_read(uint32_t reg)
|
|||||||
struct intel_register_range *range;
|
struct intel_register_range *range;
|
||||||
uint32_t ret;
|
uint32_t ret;
|
||||||
|
|
||||||
assert(mmio_data.inited);
|
igt_assert(mmio_data.inited);
|
||||||
|
|
||||||
if (intel_gen(mmio_data.i915_devid) >= 6)
|
if (intel_gen(mmio_data.i915_devid) >= 6)
|
||||||
assert(mmio_data.key != -1);
|
igt_assert(mmio_data.key != -1);
|
||||||
|
|
||||||
if (!mmio_data.safe)
|
if (!mmio_data.safe)
|
||||||
goto read_out;
|
goto read_out;
|
||||||
@ -267,8 +260,7 @@ intel_register_read(uint32_t reg)
|
|||||||
INTEL_RANGE_READ);
|
INTEL_RANGE_READ);
|
||||||
|
|
||||||
if(!range) {
|
if(!range) {
|
||||||
fprintf(stderr, "Register read blocked for safety "
|
igt_warn("Register read blocked for safety ""(*0x%08x)\n", reg);
|
||||||
"(*0x%08x)\n", reg);
|
|
||||||
ret = 0xffffffff;
|
ret = 0xffffffff;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -295,10 +287,10 @@ intel_register_write(uint32_t reg, uint32_t val)
|
|||||||
{
|
{
|
||||||
struct intel_register_range *range;
|
struct intel_register_range *range;
|
||||||
|
|
||||||
assert(mmio_data.inited);
|
igt_assert(mmio_data.inited);
|
||||||
|
|
||||||
if (intel_gen(mmio_data.i915_devid) >= 6)
|
if (intel_gen(mmio_data.i915_devid) >= 6)
|
||||||
assert(mmio_data.key != -1);
|
igt_assert(mmio_data.key != -1);
|
||||||
|
|
||||||
if (!mmio_data.safe)
|
if (!mmio_data.safe)
|
||||||
goto write_out;
|
goto write_out;
|
||||||
@ -307,10 +299,8 @@ intel_register_write(uint32_t reg, uint32_t val)
|
|||||||
reg,
|
reg,
|
||||||
INTEL_RANGE_WRITE);
|
INTEL_RANGE_WRITE);
|
||||||
|
|
||||||
if (!range) {
|
igt_warn_on_f(!range,
|
||||||
fprintf(stderr, "Register write blocked for safety "
|
"Register write blocked for safety ""(*0x%08x = 0x%x)\n", reg, val);
|
||||||
"(*0x%08x = 0x%x)\n", reg, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
write_out:
|
write_out:
|
||||||
*(volatile uint32_t *)((volatile char *)mmio + reg) = val;
|
*(volatile uint32_t *)((volatile char *)mmio + reg) = val;
|
||||||
|
@ -67,7 +67,7 @@ intel_get_total_ram_mb(void)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = sysinfo(&sysinf);
|
ret = sysinfo(&sysinf);
|
||||||
assert(ret == 0);
|
igt_assert(ret == 0);
|
||||||
|
|
||||||
retval = sysinf.totalram;
|
retval = sysinf.totalram;
|
||||||
retval *= sysinf.mem_unit;
|
retval *= sysinf.mem_unit;
|
||||||
@ -108,7 +108,7 @@ intel_get_avail_ram_mb(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = sysinfo(&sysinf);
|
ret = sysinfo(&sysinf);
|
||||||
assert(ret == 0);
|
igt_assert(ret == 0);
|
||||||
|
|
||||||
retval = sysinf.freeram;
|
retval = sysinf.freeram;
|
||||||
retval *= sysinf.mem_unit;
|
retval *= sysinf.mem_unit;
|
||||||
@ -142,7 +142,7 @@ intel_get_total_swap_mb(void)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = sysinfo(&sysinf);
|
ret = sysinfo(&sysinf);
|
||||||
assert(ret == 0);
|
igt_assert(ret == 0);
|
||||||
|
|
||||||
retval = sysinf.freeswap;
|
retval = sysinf.freeswap;
|
||||||
retval *= sysinf.mem_unit;
|
retval *= sysinf.mem_unit;
|
||||||
@ -154,7 +154,7 @@ intel_get_total_swap_mb(void)
|
|||||||
int n, i;
|
int n, i;
|
||||||
|
|
||||||
if ((n = swapctl(SC_GETNSWP, NULL)) == -1) {
|
if ((n = swapctl(SC_GETNSWP, NULL)) == -1) {
|
||||||
perror("swapctl: GETNSWP");
|
igt_warn("swapctl: GETNSWP");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
@ -165,7 +165,7 @@ intel_get_total_swap_mb(void)
|
|||||||
swt = malloc(sizeof(struct swaptable) + (n * sizeof(swapent_t)));
|
swt = malloc(sizeof(struct swaptable) + (n * sizeof(swapent_t)));
|
||||||
buf = malloc(n * MAXPATHLEN);
|
buf = malloc(n * MAXPATHLEN);
|
||||||
if (!swt || !buf) {
|
if (!swt || !buf) {
|
||||||
perror("malloc");
|
igt_warn("malloc");
|
||||||
} else {
|
} else {
|
||||||
swt->swt_n = n;
|
swt->swt_n = n;
|
||||||
for (i = 0 ; i < n; i++) {
|
for (i = 0 ; i < n; i++) {
|
||||||
@ -173,7 +173,7 @@ intel_get_total_swap_mb(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((n = swapctl(SC_LIST, swt)) == -1) {
|
if ((n = swapctl(SC_LIST, swt)) == -1) {
|
||||||
perror("swapctl: LIST");
|
igt_warn("swapctl: LIST");
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < swt->swt_n; i++) {
|
for (i = 0; i < swt->swt_n; i++) {
|
||||||
totalpages += swt->swt_ent[i].ste_pages;
|
totalpages += swt->swt_ent[i].ste_pages;
|
||||||
@ -273,8 +273,8 @@ void *mmio;
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
printf("Total RAM: %" PRIu64 " Mb\n", intel_get_total_ram_mb());
|
igt_info("Total RAM: %"PRIu64" Mb\n", intel_get_total_ram_mb());
|
||||||
printf("Total Swap: %" PRIu64 " Mb\n", intel_get_total_swap_mb());
|
igt_info("Total Swap: %"PRIu64" Mb\n", intel_get_total_swap_mb());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,10 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "intel_io.h"
|
#include "intel_io.h"
|
||||||
#include "intel_chipset.h"
|
#include "intel_chipset.h"
|
||||||
|
#include "igt_core.h"
|
||||||
|
|
||||||
static struct intel_register_range gen_bwcl_register_map[] = {
|
static struct intel_register_range gen_bwcl_register_map[] = {
|
||||||
{0x00000000, 0x00000fff, INTEL_RANGE_RW},
|
{0x00000000, 0x00000fff, INTEL_RANGE_RW},
|
||||||
@ -141,9 +143,7 @@ intel_get_register_map(uint32_t devid)
|
|||||||
map.map = gen4_register_map;
|
map.map = gen4_register_map;
|
||||||
map.top = 0x80000;
|
map.top = 0x80000;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Gen2/3 Ranges are not supported. Please use "
|
igt_fail_on("Gen2/3 Ranges are not supported. Please use ""unsafe access.");
|
||||||
"unsafe access.");
|
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
map.alignment_mask = 0x3;
|
map.alignment_mask = 0x3;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user