]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
8b955b0d EB |
2 | /* |
3 | * File: htirq.c | |
4 | * Purpose: Hypertransport Interrupt Capability | |
5 | * | |
6 | * Copyright (C) 2006 Linux Networx | |
7 | * Copyright (C) Eric Biederman <ebiederman@lnxi.com> | |
8 | */ | |
9 | ||
10 | #include <linux/irq.h> | |
11 | #include <linux/pci.h> | |
12 | #include <linux/spinlock.h> | |
363c75db | 13 | #include <linux/export.h> |
8b955b0d | 14 | #include <linux/slab.h> |
95d77884 | 15 | #include <linux/htirq.h> |
8b955b0d EB |
16 | |
17 | /* Global ht irq lock. | |
18 | * | |
19 | * This is needed to serialize access to the data port in hypertransport | |
20 | * irq capability. | |
21 | * | |
22 | * With multiple simultaneous hypertransport irq devices it might pay | |
23 | * to make this more fine grained. But start with simple, stupid, and correct. | |
24 | */ | |
25 | static DEFINE_SPINLOCK(ht_irq_lock); | |
26 | ||
ec68307c | 27 | void write_ht_irq_msg(unsigned int irq, struct ht_irq_msg *msg) |
8b955b0d | 28 | { |
dced35ae | 29 | struct ht_irq_cfg *cfg = irq_get_handler_data(irq); |
8b955b0d | 30 | unsigned long flags; |
49e07d8f | 31 | |
8b955b0d | 32 | spin_lock_irqsave(&ht_irq_lock, flags); |
ec68307c EB |
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); | |
36 | } | |
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); | |
40 | } | |
43539c38 EB |
41 | if (cfg->update) |
42 | cfg->update(cfg->dev, irq, msg); | |
8b955b0d | 43 | spin_unlock_irqrestore(&ht_irq_lock, flags); |
ec68307c | 44 | cfg->msg = *msg; |
8b955b0d EB |
45 | } |
46 | ||
ec68307c | 47 | void fetch_ht_irq_msg(unsigned int irq, struct ht_irq_msg *msg) |
8b955b0d | 48 | { |
dced35ae | 49 | struct ht_irq_cfg *cfg = irq_get_handler_data(irq); |
49e07d8f | 50 | |
ec68307c | 51 | *msg = cfg->msg; |
8b955b0d EB |
52 | } |
53 | ||
e9f7ac66 | 54 | void mask_ht_irq(struct irq_data *data) |
8b955b0d | 55 | { |
dced35ae | 56 | struct ht_irq_cfg *cfg = irq_data_get_irq_handler_data(data); |
e9f7ac66 | 57 | struct ht_irq_msg msg = cfg->msg; |
8b955b0d | 58 | |
ec68307c | 59 | msg.address_lo |= 1; |
e9f7ac66 | 60 | write_ht_irq_msg(data->irq, &msg); |
8b955b0d EB |
61 | } |
62 | ||
e9f7ac66 | 63 | void unmask_ht_irq(struct irq_data *data) |
8b955b0d | 64 | { |
dced35ae | 65 | struct ht_irq_cfg *cfg = irq_data_get_irq_handler_data(data); |
e9f7ac66 | 66 | struct ht_irq_msg msg = cfg->msg; |
8b955b0d | 67 | |
ec68307c | 68 | msg.address_lo &= ~1; |
e9f7ac66 | 69 | write_ht_irq_msg(data->irq, &msg); |
8b955b0d EB |
70 | } |
71 | ||
72 | /** | |
43539c38 | 73 | * __ht_create_irq - create an irq and attach it to a device. |
8b955b0d EB |
74 | * @dev: The hypertransport device to find the irq capability on. |
75 | * @idx: Which of the possible irqs to attach to. | |
43539c38 | 76 | * @update: Function to be called when changing the htirq message |
8b955b0d EB |
77 | * |
78 | * The irq number of the new irq or a negative error value is returned. | |
79 | */ | |
43539c38 | 80 | int __ht_create_irq(struct pci_dev *dev, int idx, ht_irq_update_t *update) |
8b955b0d | 81 | { |
59b47ddc | 82 | int max_irq, pos, irq; |
8b955b0d EB |
83 | unsigned long flags; |
84 | u32 data; | |
8b955b0d | 85 | |
120a50df | 86 | pos = pci_find_ht_capability(dev, HT_CAPTYPE_IRQ); |
8b955b0d EB |
87 | if (!pos) |
88 | return -EINVAL; | |
89 | ||
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); | |
95 | ||
96 | max_irq = (data >> 16) & 0xff; | |
3c78bc61 | 97 | if (idx > max_irq) |
8b955b0d EB |
98 | return -EINVAL; |
99 | ||
49e07d8f JL |
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); | |
8b955b0d EB |
103 | |
104 | return irq; | |
105 | } | |
b7fe9434 | 106 | EXPORT_SYMBOL(__ht_create_irq); |
8b955b0d | 107 | |
43539c38 EB |
108 | /** |
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. | |
112 | * | |
113 | * ht_create_irq needs to be called for all hypertransport devices | |
114 | * that generate irqs. | |
115 | * | |
116 | * The irq number of the new irq or a negative error value is returned. | |
117 | */ | |
118 | int ht_create_irq(struct pci_dev *dev, int idx) | |
119 | { | |
120 | return __ht_create_irq(dev, idx, NULL); | |
121 | } | |
b7fe9434 | 122 | EXPORT_SYMBOL(ht_create_irq); |
43539c38 | 123 | |
8b955b0d EB |
124 | /** |
125 | * ht_destroy_irq - destroy an irq created with ht_create_irq | |
cffb2faf | 126 | * @irq: irq to be destroyed |
8b955b0d EB |
127 | * |
128 | * This reverses ht_create_irq removing the specified irq from | |
129 | * existence. The irq should be free before this happens. | |
130 | */ | |
131 | void ht_destroy_irq(unsigned int irq) | |
132 | { | |
49e07d8f | 133 | arch_teardown_ht_irq(irq); |
8b955b0d | 134 | } |
8b955b0d | 135 | EXPORT_SYMBOL(ht_destroy_irq); |