x86/speculation/mds: Fix documentation typo
[linux/fpc-iii.git] / drivers / pci / htirq.c
blobbb88c26f5144d2288c46448115101299570184ba
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * File: htirq.c
4 * Purpose: Hypertransport Interrupt Capability
6 * Copyright (C) 2006 Linux Networx
7 * Copyright (C) Eric Biederman <ebiederman@lnxi.com>
8 */
10 #include <linux/irq.h>
11 #include <linux/pci.h>
12 #include <linux/spinlock.h>
13 #include <linux/export.h>
14 #include <linux/slab.h>
15 #include <linux/htirq.h>
17 /* Global ht irq lock.
19 * This is needed to serialize access to the data port in hypertransport
20 * irq capability.
22 * With multiple simultaneous hypertransport irq devices it might pay
23 * to make this more fine grained. But start with simple, stupid, and correct.
25 static DEFINE_SPINLOCK(ht_irq_lock);
27 void write_ht_irq_msg(unsigned int irq, struct ht_irq_msg *msg)
29 struct ht_irq_cfg *cfg = irq_get_handler_data(irq);
30 unsigned long flags;
32 spin_lock_irqsave(&ht_irq_lock, flags);
33 if (cfg->msg.address_lo != msg->address_lo) {
34 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx);
35 pci_write_config_dword(cfg->dev, cfg->pos + 4, msg->address_lo);
37 if (cfg->msg.address_hi != msg->address_hi) {
38 pci_write_config_byte(cfg->dev, cfg->pos + 2, cfg->idx + 1);
39 pci_write_config_dword(cfg->dev, cfg->pos + 4, msg->address_hi);
41 if (cfg->update)
42 cfg->update(cfg->dev, irq, msg);
43 spin_unlock_irqrestore(&ht_irq_lock, flags);
44 cfg->msg = *msg;
47 void fetch_ht_irq_msg(unsigned int irq, struct ht_irq_msg *msg)
49 struct ht_irq_cfg *cfg = irq_get_handler_data(irq);
51 *msg = cfg->msg;
54 void mask_ht_irq(struct irq_data *data)
56 struct ht_irq_cfg *cfg = irq_data_get_irq_handler_data(data);
57 struct ht_irq_msg msg = cfg->msg;
59 msg.address_lo |= 1;
60 write_ht_irq_msg(data->irq, &msg);
63 void unmask_ht_irq(struct irq_data *data)
65 struct ht_irq_cfg *cfg = irq_data_get_irq_handler_data(data);
66 struct ht_irq_msg msg = cfg->msg;
68 msg.address_lo &= ~1;
69 write_ht_irq_msg(data->irq, &msg);
72 /**
73 * __ht_create_irq - create an irq and attach it to a device.
74 * @dev: The hypertransport device to find the irq capability on.
75 * @idx: Which of the possible irqs to attach to.
76 * @update: Function to be called when changing the htirq message
78 * The irq number of the new irq or a negative error value is returned.
80 int __ht_create_irq(struct pci_dev *dev, int idx, ht_irq_update_t *update)
82 int max_irq, pos, irq;
83 unsigned long flags;
84 u32 data;
86 pos = pci_find_ht_capability(dev, HT_CAPTYPE_IRQ);
87 if (!pos)
88 return -EINVAL;
90 /* Verify the idx I want to use is in range */
91 spin_lock_irqsave(&ht_irq_lock, flags);
92 pci_write_config_byte(dev, pos + 2, 1);
93 pci_read_config_dword(dev, pos + 4, &data);
94 spin_unlock_irqrestore(&ht_irq_lock, flags);
96 max_irq = (data >> 16) & 0xff;
97 if (idx > max_irq)
98 return -EINVAL;
100 irq = arch_setup_ht_irq(idx, pos, dev, update);
101 if (irq > 0)
102 dev_dbg(&dev->dev, "irq %d for HT\n", irq);
104 return irq;
106 EXPORT_SYMBOL(__ht_create_irq);
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 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 return __ht_create_irq(dev, idx, NULL);
122 EXPORT_SYMBOL(ht_create_irq);
125 * ht_destroy_irq - destroy an irq created with ht_create_irq
126 * @irq: irq to be destroyed
128 * This reverses ht_create_irq removing the specified irq from
129 * existence. The irq should be free before this happens.
131 void ht_destroy_irq(unsigned int irq)
133 arch_teardown_ht_irq(irq);
135 EXPORT_SYMBOL(ht_destroy_irq);