summaryrefslogtreecommitdiff
path: root/sys/src/cmd/aux/realemu/pci.c
blob: fda24cb8ef9312b2a671485e8c375da684dab8e8 (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
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"

static Pcidev *devs;

Pcidev*
pciopen(int bdf)
{
	char path[64];
	Pcidev *pci;

	for(pci = devs; pci != nil; pci = pci->next){
		if(pci->bdf == bdf){
			if(pci->fd < 0)
				return nil;
			return pci;
		}
	}

	pci = malloc(sizeof(Pcidev));
	pci->bdf = bdf;

	snprint(path, sizeof(path), "#$/pci/%d.%d.%draw",
		BDFBNO(bdf), BDFDNO(bdf), BDFFNO(bdf));
	pci->fd = open(path, ORDWR);

	pci->next = devs;
	devs = pci;

	return pci;
}

int
pcicfgr(Pcidev *pci, void *data, int len, int addr)
{
	return pread(pci->fd, data, len, addr);
}

int
pcicfgw(Pcidev *pci, void *data, int len, int addr)
{
	return pwrite(pci->fd, data, len, addr);
}