1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/alpha/kernel/sys_marvel.c
8 #include <linux/kernel.h>
9 #include <linux/types.h>
11 #include <linux/sched.h>
12 #include <linux/pci.h>
13 #include <linux/init.h>
14 #include <linux/bitops.h>
16 #include <asm/ptrace.h>
19 #include <asm/mmu_context.h>
21 #include <asm/core_marvel.h>
22 #include <asm/hwrpb.h>
23 #include <asm/tlbflush.h>
30 #include "machvec_impl.h"
32 #if NR_IRQS < MARVEL_NR_IRQS
33 # error NR_IRQS < MARVEL_NR_IRQS !!!
41 io7_device_interrupt(unsigned long vector)
47 * Vector is 0x800 + (interrupt)
49 * where (interrupt) is:
51 * ...16|15 14|13 4|3 0
52 * -----+-----+--------+---
57 * 0x0800 - 0x0ff0 - 0x0800 + (LSI id << 4)
58 * 0x1000 - 0x2ff0 - 0x1000 + (MSI_DAT<8:0> << 4)
61 irq = ((vector & 0xffff) - 0x800) >> 4;
63 irq += 16; /* offset for legacy */
64 irq &= MARVEL_IRQ_VEC_IRQ_MASK; /* not too many bits */
65 irq |= pid << MARVEL_IRQ_VEC_PE_SHIFT; /* merge the pid */
70 static volatile unsigned long *
71 io7_get_irq_ctl(unsigned int irq, struct io7 **pio7)
73 volatile unsigned long *ctl;
77 pid = irq >> MARVEL_IRQ_VEC_PE_SHIFT;
79 if (!(io7 = marvel_find_io7(pid))) {
81 "%s for nonexistent io7 -- vec %x, pid %d\n",
86 irq &= MARVEL_IRQ_VEC_IRQ_MASK; /* isolate the vector */
87 irq -= 16; /* subtract legacy bias */
91 "%s for invalid irq -- pid %d adjusted irq %x\n",
96 ctl = &io7->csrs->PO7_LSI_CTL[irq & 0xff].csr; /* assume LSI */
97 if (irq >= 0x80) /* MSI */
98 ctl = &io7->csrs->PO7_MSI_CTL[((irq - 0x80) >> 5) & 0x0f].csr;
100 if (pio7) *pio7 = io7;
105 io7_enable_irq(struct irq_data *d)
107 volatile unsigned long *ctl;
108 unsigned int irq = d->irq;
111 ctl = io7_get_irq_ctl(irq, &io7);
113 printk(KERN_ERR "%s: get_ctl failed for irq %x\n",
118 raw_spin_lock(&io7->irq_lock);
122 raw_spin_unlock(&io7->irq_lock);
126 io7_disable_irq(struct irq_data *d)
128 volatile unsigned long *ctl;
129 unsigned int irq = d->irq;
132 ctl = io7_get_irq_ctl(irq, &io7);
134 printk(KERN_ERR "%s: get_ctl failed for irq %x\n",
139 raw_spin_lock(&io7->irq_lock);
140 *ctl &= ~(1UL << 24);
143 raw_spin_unlock(&io7->irq_lock);
147 marvel_irq_noop(struct irq_data *d)
152 static struct irq_chip marvel_legacy_irq_type = {
154 .irq_mask = marvel_irq_noop,
155 .irq_unmask = marvel_irq_noop,
158 static struct irq_chip io7_lsi_irq_type = {
160 .irq_unmask = io7_enable_irq,
161 .irq_mask = io7_disable_irq,
162 .irq_mask_ack = io7_disable_irq,
165 static struct irq_chip io7_msi_irq_type = {
167 .irq_unmask = io7_enable_irq,
168 .irq_mask = io7_disable_irq,
169 .irq_ack = marvel_irq_noop,
173 io7_redirect_irq(struct io7 *io7,
174 volatile unsigned long *csr,
180 val &= ~(0x1ffUL << 24); /* clear the target pid */
181 val |= ((unsigned long)where << 24); /* set the new target pid */
189 io7_redirect_one_lsi(struct io7 *io7, unsigned int which, unsigned int where)
194 * LSI_CTL has target PID @ 14
196 val = io7->csrs->PO7_LSI_CTL[which].csr;
197 val &= ~(0x1ffUL << 14); /* clear the target pid */
198 val |= ((unsigned long)where << 14); /* set the new target pid */
200 io7->csrs->PO7_LSI_CTL[which].csr = val;
202 io7->csrs->PO7_LSI_CTL[which].csr;
206 io7_redirect_one_msi(struct io7 *io7, unsigned int which, unsigned int where)
211 * MSI_CTL has target PID @ 14
213 val = io7->csrs->PO7_MSI_CTL[which].csr;
214 val &= ~(0x1ffUL << 14); /* clear the target pid */
215 val |= ((unsigned long)where << 14); /* set the new target pid */
217 io7->csrs->PO7_MSI_CTL[which].csr = val;
219 io7->csrs->PO7_MSI_CTL[which].csr;
223 init_one_io7_lsi(struct io7 *io7, unsigned int which, unsigned int where)
226 * LSI_CTL has target PID @ 14
228 io7->csrs->PO7_LSI_CTL[which].csr = ((unsigned long)where << 14);
230 io7->csrs->PO7_LSI_CTL[which].csr;
234 init_one_io7_msi(struct io7 *io7, unsigned int which, unsigned int where)
237 * MSI_CTL has target PID @ 14
239 io7->csrs->PO7_MSI_CTL[which].csr = ((unsigned long)where << 14);
241 io7->csrs->PO7_MSI_CTL[which].csr;
245 init_io7_irqs(struct io7 *io7,
246 struct irq_chip *lsi_ops,
247 struct irq_chip *msi_ops)
249 long base = (io7->pe << MARVEL_IRQ_VEC_PE_SHIFT) + 16;
252 printk("Initializing interrupts for IO7 at PE %u - base %lx\n",
256 * Where should interrupts from this IO7 go?
258 * They really should be sent to the local CPU to avoid having to
259 * traverse the mesh, but if it's not an SMP kernel, they have to
260 * go to the boot CPU. Send them all to the boot CPU for now,
261 * as each secondary starts, it can redirect it's local device
264 printk(" Interrupts reported to CPU at PE %u\n", boot_cpuid);
266 raw_spin_lock(&io7->irq_lock);
268 /* set up the error irqs */
269 io7_redirect_irq(io7, &io7->csrs->HLT_CTL.csr, boot_cpuid);
270 io7_redirect_irq(io7, &io7->csrs->HPI_CTL.csr, boot_cpuid);
271 io7_redirect_irq(io7, &io7->csrs->CRD_CTL.csr, boot_cpuid);
272 io7_redirect_irq(io7, &io7->csrs->STV_CTL.csr, boot_cpuid);
273 io7_redirect_irq(io7, &io7->csrs->HEI_CTL.csr, boot_cpuid);
275 /* Set up the lsi irqs. */
276 for (i = 0; i < 128; ++i) {
277 irq_set_chip_and_handler(base + i, lsi_ops, handle_level_irq);
278 irq_set_status_flags(i, IRQ_LEVEL);
281 /* Disable the implemented irqs in hardware. */
282 for (i = 0; i < 0x60; ++i)
283 init_one_io7_lsi(io7, i, boot_cpuid);
285 init_one_io7_lsi(io7, 0x74, boot_cpuid);
286 init_one_io7_lsi(io7, 0x75, boot_cpuid);
289 /* Set up the msi irqs. */
290 for (i = 128; i < (128 + 512); ++i) {
291 irq_set_chip_and_handler(base + i, msi_ops, handle_level_irq);
292 irq_set_status_flags(i, IRQ_LEVEL);
295 for (i = 0; i < 16; ++i)
296 init_one_io7_msi(io7, i, boot_cpuid);
298 raw_spin_unlock(&io7->irq_lock);
302 marvel_init_irq(void)
305 struct io7 *io7 = NULL;
307 /* Reserve the legacy irqs. */
308 for (i = 0; i < 16; ++i) {
309 irq_set_chip_and_handler(i, &marvel_legacy_irq_type,
313 /* Init the io7 irqs. */
314 for (io7 = NULL; (io7 = marvel_next_io7(io7)) != NULL; )
315 init_io7_irqs(io7, &io7_lsi_irq_type, &io7_msi_irq_type);
319 marvel_map_irq(const struct pci_dev *cdev, u8 slot, u8 pin)
321 struct pci_dev *dev = (struct pci_dev *)cdev;
322 struct pci_controller *hose = dev->sysdata;
323 struct io7_port *io7_port = hose->sysdata;
324 struct io7 *io7 = io7_port->io7;
325 int msi_loc, msi_data_off;
331 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &intline);
334 msi_loc = dev->msi_cap;
337 pci_read_config_word(dev, msi_loc + PCI_MSI_FLAGS, &msg_ctl);
339 if (msg_ctl & PCI_MSI_FLAGS_ENABLE) {
340 msi_data_off = PCI_MSI_DATA_32;
341 if (msg_ctl & PCI_MSI_FLAGS_64BIT)
342 msi_data_off = PCI_MSI_DATA_64;
343 pci_read_config_word(dev, msi_loc + msi_data_off, &msg_dat);
345 irq = msg_dat & 0x1ff; /* we use msg_data<8:0> */
346 irq += 0x80; /* offset for lsi */
349 printk("PCI:%d:%d:%d (hose %d) is using MSI\n",
351 PCI_SLOT(dev->devfn),
352 PCI_FUNC(dev->devfn),
354 printk(" %d message(s) from 0x%04x\n",
355 1 << ((msg_ctl & PCI_MSI_FLAGS_QSIZE) >> 4),
357 printk(" reporting on %d IRQ(s) from %d (0x%x)\n",
358 1 << ((msg_ctl & PCI_MSI_FLAGS_QSIZE) >> 4),
359 (irq + 16) | (io7->pe << MARVEL_IRQ_VEC_PE_SHIFT),
360 (irq + 16) | (io7->pe << MARVEL_IRQ_VEC_PE_SHIFT));
364 pci_write_config_word(dev, msi_loc + PCI_MSI_FLAGS,
365 msg_ctl & ~PCI_MSI_FLAGS_ENABLE);
366 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &intline);
369 printk(" forcing LSI interrupt on irq %d [0x%x]\n", irq, irq);
373 irq += 16; /* offset for legacy */
374 irq |= io7->pe << MARVEL_IRQ_VEC_PE_SHIFT; /* merge the pid */
380 marvel_init_pci(void)
384 marvel_register_error_handlers();
386 /* Indicate that we trust the console to configure things properly */
387 pci_set_flags(PCI_PROBE_ONLY);
389 locate_and_init_vga(NULL);
391 /* Clear any io7 errors. */
392 for (io7 = NULL; (io7 = marvel_next_io7(io7)) != NULL; )
393 io7_clear_errors(io7);
397 marvel_init_rtc(void)
403 marvel_smp_callin(void)
405 int cpuid = hard_smp_processor_id();
406 struct io7 *io7 = marvel_find_io7(cpuid);
413 * There is a local IO7 - redirect all of its interrupts here.
415 printk("Redirecting IO7 interrupts to local CPU at PE %u\n", cpuid);
417 /* Redirect the error IRQS here. */
418 io7_redirect_irq(io7, &io7->csrs->HLT_CTL.csr, cpuid);
419 io7_redirect_irq(io7, &io7->csrs->HPI_CTL.csr, cpuid);
420 io7_redirect_irq(io7, &io7->csrs->CRD_CTL.csr, cpuid);
421 io7_redirect_irq(io7, &io7->csrs->STV_CTL.csr, cpuid);
422 io7_redirect_irq(io7, &io7->csrs->HEI_CTL.csr, cpuid);
424 /* Redirect the implemented LSIs here. */
425 for (i = 0; i < 0x60; ++i)
426 io7_redirect_one_lsi(io7, i, cpuid);
428 io7_redirect_one_lsi(io7, 0x74, cpuid);
429 io7_redirect_one_lsi(io7, 0x75, cpuid);
431 /* Redirect the MSIs here. */
432 for (i = 0; i < 16; ++i)
433 io7_redirect_one_msi(io7, i, cpuid);
439 struct alpha_machine_vector marvel_ev7_mv __initmv = {
440 .vector_name = "MARVEL/EV7",
443 .rtc_boot_cpu_only = 1,
445 .machine_check = marvel_machine_check,
446 .max_isa_dma_address = ALPHA_MAX_ISA_DMA_ADDRESS,
447 .min_io_address = DEFAULT_IO_BASE,
448 .min_mem_address = DEFAULT_MEM_BASE,
449 .pci_dac_offset = IO7_DAC_OFFSET,
451 .nr_irqs = MARVEL_NR_IRQS,
452 .device_interrupt = io7_device_interrupt,
454 .agp_info = marvel_agp_info,
456 .smp_callin = marvel_smp_callin,
457 .init_arch = marvel_init_arch,
458 .init_irq = marvel_init_irq,
459 .init_rtc = marvel_init_rtc,
460 .init_pci = marvel_init_pci,
461 .kill_arch = marvel_kill_arch,
462 .pci_map_irq = marvel_map_irq,
463 .pci_swizzle = common_swizzle,