summaryrefslogtreecommitdiff
path: root/drivers/xen/xen-pciback/conf_space_capability.c
blob: 0ea84d6335f46f6f38c542e8d7274725fa0bc6c4 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * PCI Backend - Handles the virtual fields found on the capability lists
 *               in the configuration space.
 *
 * Author: Ryan Wilson <hap9@epoch.ncsc.mil>
 */

#include <linux/kernel.h>
#include <linux/pci.h>
#include "pciback.h"
#include "conf_space.h"
#include "conf_space_capability.h"

static LIST_HEAD(capabilities);

static const struct config_field caplist_header[] = {
	{
	 .offset    = PCI_CAP_LIST_ID,
	 .size      = 2, /* encompass PCI_CAP_LIST_ID & PCI_CAP_LIST_NEXT */
	 .u.w.read  = pciback_read_config_word,
	 .u.w.write = NULL,
	},
	{}
};

static inline void register_capability(struct pciback_config_capability *cap)
{
	list_add_tail(&cap->cap_list, &capabilities);
}

int pciback_config_capability_add_fields(struct pci_dev *dev)
{
	int err = 0;
	struct pciback_config_capability *cap;
	int cap_offset;

	list_for_each_entry(cap, &capabilities, cap_list) {
		cap_offset = pci_find_capability(dev, cap->capability);
		if (cap_offset) {
			dev_dbg(&dev->dev, "Found capability 0x%x at 0x%x\n",
				cap->capability, cap_offset);

			err = pciback_config_add_fields_offset(dev,
							       caplist_header,
							       cap_offset);
			if (err)
				goto out;
			err = pciback_config_add_fields_offset(dev,
							       cap->fields,
							       cap_offset);
			if (err)
				goto out;
		}
	}

out:
	return err;
}

int pciback_config_capability_init(void)
{
	register_capability(&pciback_config_capability_vpd);
	register_capability(&pciback_config_capability_pm);

	return 0;
}