summaryrefslogtreecommitdiff
path: root/bin/nv_wifunc.h
blob: aaa597c2d1920603861a355a6c95d18518d93531 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdlib.h>

#include <nvif/device.h>

static void __iomem *map = NULL;
static u64 map_page = ~0ULL;

static void
nv_wfb(struct nvif_device *device, u64 offset, CAST data)
{
	struct nvkm_device *nv = nvxx_device(device);
	u64 page = (offset & ~(PAGE_SIZE - 1));
	u64 addr = (offset &  (PAGE_SIZE - 1));

	if (device->info.family < NV_DEVICE_INFO_V0_CURIE ||
	    device->info.family > NV_DEVICE_INFO_V0_MAXWELL) {
		printk("unsupported chipset\n");
		exit(1);
	}

	if (map_page != page) {
		if (map)
			iounmap(map);

		if (nv->func->resource_size(nv, 2)) {
			map = ioremap(nv->func->resource_addr(nv, 2) +
				      page, PAGE_SIZE);
		} else {
			map = ioremap(nv->func->resource_addr(nv, 3) +
				      page, PAGE_SIZE);
		}

		if (!map) {
			printk("map failed\n");
			exit(1);
		}

		map_page = page;
	}

	*(CAST *)(map + addr) = data;
}

#define WRITE(o,v) nv_wfb(device, (o), (v))
#define DETECT true
#include "nv_wrfunc.h"