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>
15 /* Global ht irq lock.
17 * This is needed to serialize access to the data port in hypertransport
20 * With multiple simultaneous hypertransport irq devices it might pay
21 * to make this more fine grained. But start with simple, stupid, and correct.
23 static DEFINE_SPINLOCK(ht_irq_lock);
31 void write_ht_irq_low(unsigned int irq, u32 data)
33 struct ht_irq_cfg *cfg = get_irq_data(irq);
35 spin_lock_irqsave(&ht_irq_lock, flags);
36 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
37 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
38 spin_unlock_irqrestore(&ht_irq_lock, flags);
41 void write_ht_irq_high(unsigned int irq, u32 data)
43 struct ht_irq_cfg *cfg = get_irq_data(irq);
45 spin_lock_irqsave(&ht_irq_lock, flags);
46 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx + 1);
47 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
48 spin_unlock_irqrestore(&ht_irq_lock, flags);
51 u32 read_ht_irq_low(unsigned int irq)
53 struct ht_irq_cfg *cfg = get_irq_data(irq);
56 spin_lock_irqsave(&ht_irq_lock, flags);
57 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
58 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
59 spin_unlock_irqrestore(&ht_irq_lock, flags);
63 u32 read_ht_irq_high(unsigned int irq)
65 struct ht_irq_cfg *cfg = get_irq_data(irq);
68 spin_lock_irqsave(&ht_irq_lock, flags);
69 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx + 1);
70 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
71 spin_unlock_irqrestore(&ht_irq_lock, flags);
75 void mask_ht_irq(unsigned int irq)
77 struct ht_irq_cfg *cfg;
81 cfg = get_irq_data(irq);
83 spin_lock_irqsave(&ht_irq_lock, flags);
84 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
85 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
87 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
88 spin_unlock_irqrestore(&ht_irq_lock, flags);
91 void unmask_ht_irq(unsigned int irq)
93 struct ht_irq_cfg *cfg;
97 cfg = get_irq_data(irq);
99 spin_lock_irqsave(&ht_irq_lock, flags);
100 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
101 pci_read_config_dword(cfg->dev, cfg->pos + 4, &data);
103 pci_write_config_dword(cfg->dev, cfg->pos + 4, data);
104 spin_unlock_irqrestore(&ht_irq_lock, flags);
108 * ht_create_irq - create an irq and attach it to a device.
109 * @dev: The hypertransport device to find the irq capability on.
110 * @idx: Which of the possible irqs to attach to.
112 * ht_create_irq is needs to be called for all hypertransport devices
113 * that generate irqs.
115 * The irq number of the new irq or a negative error value is returned.
117 int ht_create_irq(struct pci_dev *dev, int idx)
119 struct ht_irq_cfg *cfg;
126 pos = pci_find_capability(dev, PCI_CAP_ID_HT);
129 pci_read_config_byte(dev, pos + 3, &subtype);
130 if (subtype == HT_CAPTYPE_IRQ)
132 pos = pci_find_next_capability(dev, pos, PCI_CAP_ID_HT);
137 /* Verify the idx I want to use is in range */
138 spin_lock_irqsave(&ht_irq_lock, flags);
139 pci_write_config_byte(dev, pos + 2, 1);
140 pci_read_config_dword(dev, pos + 4, &data);
141 spin_unlock_irqrestore(&ht_irq_lock, flags);
143 max_irq = (data >> 16) & 0xff;
147 cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
153 cfg->idx = 0x10 + (idx * 2);
160 set_irq_data(irq, cfg);
162 if (arch_setup_ht_irq(irq, dev) < 0) {
171 * ht_destroy_irq - destroy an irq created with ht_create_irq
173 * This reverses ht_create_irq removing the specified irq from
174 * existence. The irq should be free before this happens.
176 void ht_destroy_irq(unsigned int irq)
178 struct ht_irq_cfg *cfg;
180 cfg = get_irq_data(irq);
181 set_irq_chip(irq, NULL);
182 set_irq_data(irq, NULL);
188 EXPORT_SYMBOL(ht_create_irq);
189 EXPORT_SYMBOL(ht_destroy_irq);