summaryrefslogtreecommitdiff
path: root/util/i915tool/pci.c
blob: ca942dc31478ee41c56c4dfd6e3920a80f1ec5f7 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * This file is part of i915tool
 *
 * Copyright (C) 2012 The ChromiumOS Authors.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

#include "video.h"

int find_idlist(struct drm_device *dev, u16 vendor, u16 device)
{
	extern const struct pci_device_id pciidlist[];
	int succ = 0;
	int i;
	for(i = 0; pciidlist[i].vendor && !succ; i++){
		if (vendor == pciidlist[i].vendor && device ==
				pciidlist[i].device){
			dev->dev_private->info =
				(void *)(pciidlist[i].driver_data);
			succ = 1;
		}
	}
	return succ;
}

/* there's only going to be one device ... */
int pci_dev_find(struct drm_device *dev)
{
	struct pci_access *pacc = NULL;
	struct pci_dev *temp;
	int succ = 0;
        pacc = pci_alloc();
	if (! pacc)
		return 0;
        pci_init(pacc);
        pci_scan_bus(pacc);

	for (temp = pacc->devices; temp && ! dev->pdev; temp = temp->next){
		if ((temp->device_class & 0xff00) == PCI_CLASS_DISPLAY_VGA ) {
			pci_fill_info(temp, PCI_FILL_IDENT |
					PCI_FILL_BASES | PCI_FILL_CLASS);
			dev->pdev = temp;
		}
	}

	if (dev->pdev)
		succ = find_idlist(dev, dev->pdev->vendor_id,
					dev->pdev->device_id);
	return succ;
}

/* Support library for kernel style pci functions. We could do a semantic
 * patch for it but this is easier to debug as we can fill it with prints
 * if we want. And no cpp abuse here. Keep it simple.
 */

void pci_read_config_byte(struct pci_dev *dev, unsigned long offset, u8 *val)
{
	*val = pci_read_byte(dev, offset);
}

void pci_write_config_byte(struct pci_dev *dev, unsigned long offset, u8 val)
{
	pci_write_byte(dev, offset, val);
}

void pci_read_config_word(struct pci_dev *dev, unsigned long offset, u16 *val)
{
	*val = pci_read_word(dev, offset);
}

void pci_write_config_word(struct pci_dev *dev, unsigned long offset, u16 val)
{
	pci_write_word(dev, offset, val);
}

void pci_read_config_dword(struct pci_dev *dev, unsigned long offset, u32 *val)
{
	*val = pci_read_long(dev, offset);
}

void pci_write_config_dword(struct pci_dev *dev, unsigned long offset, u32 val)
{
	pci_write_long(dev, offset, val);
}