aboutsummaryrefslogtreecommitdiffstats
path: root/linux-2.6.9-xen-sparse/arch/xen/i386/pci/irq.c
blob: b7761350a9a9e918ee7058225779c515902eb6b1 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 *	Low-Level PCI Support for PC -- Routing of Interrupts
 *
 *	(c) 1999--2000 Martin Mares <mj@ucw.cz>
 */

#include <linux/config.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <asm/io.h>
#include <asm/smp.h>
#include <asm/io_apic.h>
#include <asm/hw_irq.h>

#include "pci.h"

#include <asm/xen-public/xen.h>
#include <asm/xen-public/physdev.h>

/*
 * Never use: 0, 1, 2 (timer, keyboard, and cascade)
 * Avoid using: 13, 14 and 15 (FP error and IDE).
 * Penalize: 3, 4, 6, 7, 12 (known ISA uses: serial, floppy, parallel and mouse)
 */
unsigned int pcibios_irq_mask = 0xfff8;

static int pirq_penalty[16] = {
	1000000, 1000000, 1000000, 1000, 1000, 0, 1000, 1000,
	0, 0, 0, 0, 1000, 100000, 100000, 100000
};

int (*pcibios_enable_irq)(struct pci_dev *dev) = NULL;


static int __init pcibios_irq_init(void)
{
	int bus;
	physdev_op_t op;

	DBG("PCI: IRQ init\n");

	if (pcibios_enable_irq || raw_pci_ops == NULL)
		return 0;

	op.cmd = PHYSDEVOP_PCI_PROBE_ROOT_BUSES;
	if (HYPERVISOR_physdev_op(&op) != 0) {
		printk(KERN_WARNING "PCI: System does not support PCI\n");
		return 0;
	}

	printk(KERN_INFO "PCI: Probing PCI hardware\n");
	for (bus = 0; bus < 256; bus++)
		if (test_bit(bus, (unsigned long *)
			&op.u.pci_probe_root_buses.busmask[0]))
			(void)pcibios_scan_root(bus);

	pcibios_enable_irq = pirq_enable_irq;

	return 0;
}

subsys_initcall(pcibios_irq_init);


void pcibios_penalize_isa_irq(int irq)
{
	/*
	 *  If any ISAPnP device reports an IRQ in its list of possible
	 *  IRQ's, we try to avoid assigning it to PCI devices.
	 */
	pirq_penalty[irq] += 100;
}

int pirq_enable_irq(struct pci_dev *dev)
{
	int err;
	u8  pin;
	physdev_op_t op;

	/* Inform Xen that we are going to use this device. */
	op.cmd = PHYSDEVOP_PCI_INITIALISE_DEVICE;
	op.u.pci_initialise_device.bus  = dev->bus->number;
	op.u.pci_initialise_device.dev  = PCI_SLOT(dev->devfn);
	op.u.pci_initialise_device.func = PCI_FUNC(dev->devfn);
	if ( (err = HYPERVISOR_physdev_op(&op)) != 0 )
		return err;

	/* Now we can bind to the very final IRQ line. */
	pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &pin);
	dev->irq = pin;

	/* Sanity-check that an interrupt-producing device is routed
	 * to an IRQ. */
	pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
	if (pin != 0) {
		if (dev->irq != 0)
			printk(KERN_INFO "PCI: Obtained IRQ %d for device %s\n",
			    dev->irq, dev->slot_name);
		else
			printk(KERN_WARNING "PCI: No IRQ known for interrupt "
			    "pin %c of device %s.\n", 'A' + pin - 1,
			    dev->slot_name);
	}

	return 0;
}

int pci_vector_resources(int last, int nr_released)
{
	int count = nr_released;

	int next = last;
	int offset = (last % 8);

	while (next < FIRST_SYSTEM_VECTOR) {
		next += 8;
#ifdef CONFIG_X86_64
		if (next == IA32_SYSCALL_VECTOR)
			continue;
#else
		if (next == SYSCALL_VECTOR)
			continue;
#endif
		count++;
		if (next >= FIRST_SYSTEM_VECTOR) {
			if (offset%8) {
				next = FIRST_DEVICE_VECTOR + offset;
				offset++;
				continue;
			}
			count--;
		}
	}

	return count;
}