3 * Purpose: Hypertransport Interrupt Capability
5 * Copyright (C) 2006 Linux Networx
6 * Copyright (C) Eric Biederman <ebiederman@lnxi.com>
10 #include <linux/pci.h>
11 #include <linux/spinlock.h>
12 #include <linux/slab.h>
13 #include <linux/gfp.h>
14 #include <linux/htirq.h>
16 /* Global ht irq lock.
18 * This is needed to serialize access to the data port in hypertransport
21 * With multiple simultaneous hypertransport irq devices it might pay
22 * to make this more fine grained. But start with simple, stupid, and correct.
24 static DEFINE_SPINLOCK(ht_irq_lock);
32 void write_ht_irq_low(unsigned int irq, u32 data)
34 struct ht_irq_cfg *cfg = get_irq_data(irq);
36 spin_lock_irqsave(&ht_irq_lock, flags);
37 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
38 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
39 spin_unlock_irqrestore(&ht_irq_lock, flags);
42 void write_ht_irq_high(unsigned int irq, u32 data)
44 struct ht_irq_cfg *cfg = get_irq_data(irq);
46 spin_lock_irqsave(&ht_irq_lock, flags);
47 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx + 1);
48 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
49 spin_unlock_irqrestore(&ht_irq_lock, flags);
52 u32 read_ht_irq_low(unsigned int irq)
54 struct ht_irq_cfg *cfg = get_irq_data(irq);
57 spin_lock_irqsave(&ht_irq_lock, flags);
58 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
59 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
60 spin_unlock_irqrestore(&ht_irq_lock, flags);
64 u32 read_ht_irq_high(unsigned int irq)
66 struct ht_irq_cfg *cfg = get_irq_data(irq);
69 spin_lock_irqsave(&ht_irq_lock, flags);
70 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx + 1);
71 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
72 spin_unlock_irqrestore(&ht_irq_lock, flags);
76 void mask_ht_irq(unsigned int irq)
78 struct ht_irq_cfg *cfg;
82 cfg = get_irq_data(irq);
84 spin_lock_irqsave(&ht_irq_lock, flags);
85 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
86 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
88 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
89 spin_unlock_irqrestore(&ht_irq_lock, flags);
92 void unmask_ht_irq(unsigned int irq)
94 struct ht_irq_cfg *cfg;
98 cfg = get_irq_data(irq);
100 spin_lock_irqsave(&ht_irq_lock, flags);
101 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
102 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
104 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
105 spin_unlock_irqrestore(&ht_irq_lock, flags);
109 * ht_create_irq - create an irq and attach it to a device.
110 * @dev: The hypertransport device to find the irq capability on.
111 * @idx: Which of the possible irqs to attach to.
113 * ht_create_irq is needs to be called for all hypertransport devices
114 * that generate irqs.
116 * The irq number of the new irq or a negative error value is returned.
118 int ht_create_irq(struct pci_dev *dev, int idx)
120 struct ht_irq_cfg *cfg;
127 pos = pci_find_capability(dev, PCI_CAP_ID_HT);
130 pci_read_config_byte(dev, pos + 3, &subtype);
131 if (subtype == HT_CAPTYPE_IRQ)
133 pos = pci_find_next_capability(dev, pos, PCI_CAP_ID_HT);
138 /* Verify the idx I want to use is in range */
139 spin_lock_irqsave(&ht_irq_lock, flags);
140 pci_write_config_byte(dev, pos + 2, 1);
141 pci_read_config_dword(dev, pos + 4, &data);
142 spin_unlock_irqrestore(&ht_irq_lock, flags);
144 max_irq = (data >> 16) & 0xff;
148 cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
154 cfg->idx = 0x10 + (idx * 2);
161 set_irq_data(irq, cfg);
163 if (arch_setup_ht_irq(irq, dev) < 0) {
172 * ht_destroy_irq - destroy an irq created with ht_create_irq
174 * This reverses ht_create_irq removing the specified irq from
175 * existence. The irq should be free before this happens.
177 void ht_destroy_irq(unsigned int irq)
179 struct ht_irq_cfg *cfg;
181 cfg = get_irq_data(irq);
182 set_irq_chip(irq, NULL);
183 set_irq_data(irq, NULL);
189 EXPORT_SYMBOL(ht_create_irq);
190 EXPORT_SYMBOL(ht_destroy_irq);