13 #include <linux/kernel.h>
14 #include <linux/pci.h>
16 #include <linux/export.h>
19 #include <linux/slab.h>
22 #include <asm/machdep.h>
29 #define MSIC_CTRL_REG 0x0
32 #define MSIC_BASE_ADDR_HI_REG 0x3
33 #define MSIC_BASE_ADDR_LO_REG 0x4
36 #define MSIC_READ_OFFSET_REG 0x5
37 #define MSIC_WRITE_OFFSET_REG 0x6
41 #define MSIC_CTRL_ENABLE 0x0001
42 #define MSIC_CTRL_FIFO_FULL_ENABLE 0x0002
43 #define MSIC_CTRL_IRQ_ENABLE 0x0008
44 #define MSIC_CTRL_FULL_STOP_ENABLE 0x0010
50 #define MSIC_FIFO_SIZE_SHIFT 16
51 #define MSIC_FIFO_SIZE_BYTES (1 << MSIC_FIFO_SIZE_SHIFT)
57 #define MSIC_CTRL_FIFO_SIZE (((MSIC_FIFO_SIZE_SHIFT - 15) << 8) & 0x300)
63 #define MSIC_FIFO_SIZE_MASK ((MSIC_FIFO_SIZE_BYTES - 1) & ~0xFu)
66 #define MSIC_FIFO_ENTRY_SIZE 0x10
83 static inline void axon_msi_debug_setup(
struct device_node *
dn,
88 static void msic_dcr_write(
struct axon_msic *msic,
unsigned int dcr_n,
u32 val)
90 pr_devel(
"axon_msi: dcr_write(0x%x, 0x%x)\n", val, dcr_n);
92 dcr_write(msic->
dcr_host, dcr_n, val);
95 static void axon_msi_cascade(
unsigned int irq,
struct irq_desc *
desc)
98 struct axon_msic *msic = irq_get_handler_data(irq);
99 u32 write_offset, msi;
104 pr_devel(
"axon_msi: original write_offset 0x%x\n", write_offset);
109 while (msic->
read_offset != write_offset && retry < 100) {
114 pr_devel(
"axon_msi: woff %x roff %x msi %x\n",
117 if (msi <
nr_irqs && irq_get_chip_data(msi) == msic) {
129 pr_devel(
"axon_msi: invalid irq 0x%x!\n", msi);
134 pr_devel(
"axon_msi: late irq 0x%x, retry %d\n",
160 dn = of_node_get(pci_device_to_OF_node(dev));
162 dev_dbg(&dev->
dev,
"axon_msi: no pci_dn found\n");
174 "axon_msi: no msi-translator property found\n");
183 "axon_msi: msi-translator doesn't point to a node\n");
189 dev_dbg(&dev->
dev,
"axon_msi: no irq_domain found for node %s\n",
202 static int axon_msi_check_device(
struct pci_dev *dev,
int nvec,
int type)
204 if (!find_msi_translator(dev))
217 dn = of_node_get(pci_device_to_OF_node(dev));
219 dev_dbg(&dev->
dev,
"axon_msi: no pci_dn found\n");
239 "axon_msi: no msi-address-(32|64) properties found\n");
254 "axon_msi: malformed msi-address-(32|64) property\n");
264 static int axon_msi_setup_msi_irqs(
struct pci_dev *dev,
int nvec,
int type)
266 unsigned int virq,
rc;
271 msic = find_msi_translator(dev);
275 rc = setup_msi_msg_address(dev, &msg);
283 "axon_msi: virq allocation failed!\n");
286 dev_dbg(&dev->
dev,
"axon_msi: allocated virq 0x%x\n", virq);
296 static void axon_msi_teardown_msi_irqs(
struct pci_dev *dev)
300 dev_dbg(&dev->
dev,
"axon_msi: tearing down msi irqs\n");
311 static struct irq_chip msic_irq_chip = {
318 static int msic_host_map(
struct irq_domain *
h,
unsigned int virq,
328 .map = msic_host_map,
336 pr_devel(
"axon_msi: disabling %s\n",
348 int dcr_base, dcr_len;
362 if (dcr_base == 0 || dcr_len == 0) {
364 "axon_msi: couldn't parse dcr properties on %s\n",
369 msic->
dcr_host = dcr_map(dn, dcr_base, dcr_len);
395 printk(
KERN_ERR "axon_msi: couldn't allocate irq_domain for %s\n",
401 irq_set_chained_handler(virq, axon_msi_cascade);
402 pr_devel(
"axon_msi: irq 0x%x setup for axon_msi\n", virq);
417 ppc_md.setup_msi_irqs = axon_msi_setup_msi_irqs;
418 ppc_md.teardown_msi_irqs = axon_msi_teardown_msi_irqs;
419 ppc_md.msi_check_device = axon_msi_check_device;
421 axon_msi_debug_setup(dn, msic);
437 static const struct of_device_id axon_msi_device_id[] = {
439 .compatible =
"ibm,axon-msic"
445 .probe = axon_msi_probe,
446 .shutdown = axon_msi_shutdown,
450 .of_match_table = axon_msi_device_id,
454 static int __init axon_msi_init(
void)
483 if (addr == OF_BAD_ADDR) {
484 pr_devel(
"axon_msi: couldn't translate reg property\n");
488 msic->trigger =
ioremap(addr, 0x4);
489 if (!msic->trigger) {
490 pr_devel(
"axon_msi: ioremap failed\n");
498 pr_devel(
"axon_msi: debugfs_create_file failed!\n");