summaryrefslogtreecommitdiff
path: root/bin/nv_rifunc.h
blob: 82fa77ba754d04db122b6730f08d93fb8189cb74 (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
47
48
#include <stdlib.h>

#include <core/os.h>
#include <core/object.h>
#include <core/device.h>

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

static CAST
nv_rfb(struct nouveau_object *device, u64 offset)
{
	struct pci_dev *pdev = nv_device(device)->pdev;
	u64 page = (offset & ~(PAGE_SIZE - 1));
	u64 addr = (offset &  (PAGE_SIZE - 1));

	if (nv_device(device)->card_type < NV_40 ||
	    nv_device(device)->card_type > NV_E0) {
		printk("unsupported chipset\n");
		exit(1);
	}

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

		if (pci_resource_len(pdev, 2)) {
			map = ioremap(pci_resource_start(pdev, 2) +
				      page, PAGE_SIZE);
		} else {
			map = ioremap(pci_resource_start(pdev, 3) +
				      page, PAGE_SIZE);
		}

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

		map_page = page;
	}

	return *(CAST *)(map + addr);
}

#define READ(o) nv_rfb(device, (o))
#define ENABLE  (NV_DEVICE_DISABLE_MMIO | NV_DEVICE_DISABLE_IDENTIFY)
#include "nv_rdfunc.h"