1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * linux/arch/arm/kernel/fiq.c 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 1998 Russell King 61da177e4SLinus Torvalds * Copyright (C) 1998, 1999 Phil Blundell 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * FIQ support written by Philip Blundell <philb@gnu.org>, 1998. 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * FIQ support re-written by Russell King to be more generic 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * We now properly support a method by which the FIQ handlers can 131da177e4SLinus Torvalds * be stacked onto the vector. We still do not support sharing 141da177e4SLinus Torvalds * the FIQ vector itself. 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * Operation is as follows: 171da177e4SLinus Torvalds * 1. Owner A claims FIQ: 181da177e4SLinus Torvalds * - default_fiq relinquishes control. 191da177e4SLinus Torvalds * 2. Owner A: 201da177e4SLinus Torvalds * - inserts code. 211da177e4SLinus Torvalds * - sets any registers, 221da177e4SLinus Torvalds * - enables FIQ. 231da177e4SLinus Torvalds * 3. Owner B claims FIQ: 241da177e4SLinus Torvalds * - if owner A has a relinquish function. 251da177e4SLinus Torvalds * - disable FIQs. 261da177e4SLinus Torvalds * - saves any registers. 271da177e4SLinus Torvalds * - returns zero. 281da177e4SLinus Torvalds * 4. Owner B: 291da177e4SLinus Torvalds * - inserts code. 301da177e4SLinus Torvalds * - sets any registers, 311da177e4SLinus Torvalds * - enables FIQ. 321da177e4SLinus Torvalds * 5. Owner B releases FIQ: 331da177e4SLinus Torvalds * - Owner A is asked to reacquire FIQ: 341da177e4SLinus Torvalds * - inserts code. 351da177e4SLinus Torvalds * - restores saved registers. 361da177e4SLinus Torvalds * - enables FIQ. 371da177e4SLinus Torvalds * 6. Goto 3 381da177e4SLinus Torvalds */ 391da177e4SLinus Torvalds #include <linux/module.h> 401da177e4SLinus Torvalds #include <linux/kernel.h> 411da177e4SLinus Torvalds #include <linux/init.h> 424a2581a0SThomas Gleixner #include <linux/interrupt.h> 431da177e4SLinus Torvalds #include <linux/seq_file.h> 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds #include <asm/cacheflush.h> 4615d07dc9SRussell King #include <asm/cp15.h> 471da177e4SLinus Torvalds #include <asm/fiq.h> 48*85e18ed3SArnd Bergmann #include <asm/mach/irq.h> 491da177e4SLinus Torvalds #include <asm/irq.h> 50247055aaSCatalin Marinas #include <asm/traps.h> 511da177e4SLinus Torvalds 52e39e3f3eSRussell King #define FIQ_OFFSET ({ \ 53e39e3f3eSRussell King extern void *vector_fiq_offset; \ 54e39e3f3eSRussell King (unsigned)&vector_fiq_offset; \ 55e39e3f3eSRussell King }) 56e39e3f3eSRussell King 57c0e7f7eeSDaniel Thompson static unsigned long dfl_fiq_insn; 58c0e7f7eeSDaniel Thompson static struct pt_regs dfl_fiq_regs; 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds /* Default reacquire function 611da177e4SLinus Torvalds * - we always relinquish FIQ control 621da177e4SLinus Torvalds * - we always reacquire FIQ control 631da177e4SLinus Torvalds */ 641da177e4SLinus Torvalds static int fiq_def_op(void *ref, int relinquish) 651da177e4SLinus Torvalds { 66c0e7f7eeSDaniel Thompson if (!relinquish) { 67c0e7f7eeSDaniel Thompson /* Restore default handler and registers */ 68c0e7f7eeSDaniel Thompson local_fiq_disable(); 69c0e7f7eeSDaniel Thompson set_fiq_regs(&dfl_fiq_regs); 70c0e7f7eeSDaniel Thompson set_fiq_handler(&dfl_fiq_insn, sizeof(dfl_fiq_insn)); 71c0e7f7eeSDaniel Thompson local_fiq_enable(); 72c0e7f7eeSDaniel Thompson 73c0e7f7eeSDaniel Thompson /* FIXME: notify irq controller to standard enable FIQs */ 74c0e7f7eeSDaniel Thompson } 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds return 0; 771da177e4SLinus Torvalds } 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds static struct fiq_handler default_owner = { 801da177e4SLinus Torvalds .name = "default", 811da177e4SLinus Torvalds .fiq_op = fiq_def_op, 821da177e4SLinus Torvalds }; 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds static struct fiq_handler *current_fiq = &default_owner; 851da177e4SLinus Torvalds 86f13cd417SRussell King int show_fiq_list(struct seq_file *p, int prec) 871da177e4SLinus Torvalds { 881da177e4SLinus Torvalds if (current_fiq != &default_owner) 89f13cd417SRussell King seq_printf(p, "%*s: %s\n", prec, "FIQ", 90f13cd417SRussell King current_fiq->name); 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds return 0; 931da177e4SLinus Torvalds } 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds void set_fiq_handler(void *start, unsigned int length) 961da177e4SLinus Torvalds { 97e39e3f3eSRussell King void *base = vectors_page; 98e39e3f3eSRussell King unsigned offset = FIQ_OFFSET; 99e39e3f3eSRussell King 100e39e3f3eSRussell King memcpy(base + offset, start, length); 1012ba85e7aSRussell King if (!cache_is_vipt_nonaliasing()) 102ce450ebfSChristoph Hellwig flush_icache_range((unsigned long)base + offset, 103ce450ebfSChristoph Hellwig (unsigned long)base + offset + length); 104e39e3f3eSRussell King flush_icache_range(0xffff0000 + offset, 0xffff0000 + offset + length); 1051da177e4SLinus Torvalds } 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds int claim_fiq(struct fiq_handler *f) 1081da177e4SLinus Torvalds { 1091da177e4SLinus Torvalds int ret = 0; 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds if (current_fiq) { 1121da177e4SLinus Torvalds ret = -EBUSY; 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds if (current_fiq->fiq_op != NULL) 1151da177e4SLinus Torvalds ret = current_fiq->fiq_op(current_fiq->dev_id, 1); 1161da177e4SLinus Torvalds } 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds if (!ret) { 1191da177e4SLinus Torvalds f->next = current_fiq; 1201da177e4SLinus Torvalds current_fiq = f; 1211da177e4SLinus Torvalds } 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds return ret; 1241da177e4SLinus Torvalds } 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds void release_fiq(struct fiq_handler *f) 1271da177e4SLinus Torvalds { 1281da177e4SLinus Torvalds if (current_fiq != f) { 1294ed89f22SRussell King pr_err("%s FIQ trying to release %s FIQ\n", 1301da177e4SLinus Torvalds f->name, current_fiq->name); 1311da177e4SLinus Torvalds dump_stack(); 1321da177e4SLinus Torvalds return; 1331da177e4SLinus Torvalds } 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds do 1361da177e4SLinus Torvalds current_fiq = current_fiq->next; 1371da177e4SLinus Torvalds while (current_fiq->fiq_op(current_fiq->dev_id, 0)); 1381da177e4SLinus Torvalds } 1391da177e4SLinus Torvalds 140bc89663aSShawn Guo static int fiq_start; 141bc89663aSShawn Guo 1421da177e4SLinus Torvalds void enable_fiq(int fiq) 1431da177e4SLinus Torvalds { 144bc89663aSShawn Guo enable_irq(fiq + fiq_start); 1451da177e4SLinus Torvalds } 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds void disable_fiq(int fiq) 1481da177e4SLinus Torvalds { 149bc89663aSShawn Guo disable_irq(fiq + fiq_start); 1501da177e4SLinus Torvalds } 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds EXPORT_SYMBOL(set_fiq_handler); 153dc2eb928SDave Martin EXPORT_SYMBOL(__set_fiq_regs); /* defined in fiqasm.S */ 154dc2eb928SDave Martin EXPORT_SYMBOL(__get_fiq_regs); /* defined in fiqasm.S */ 1551da177e4SLinus Torvalds EXPORT_SYMBOL(claim_fiq); 1561da177e4SLinus Torvalds EXPORT_SYMBOL(release_fiq); 1571da177e4SLinus Torvalds EXPORT_SYMBOL(enable_fiq); 1581da177e4SLinus Torvalds EXPORT_SYMBOL(disable_fiq); 1591da177e4SLinus Torvalds 160bc89663aSShawn Guo void __init init_FIQ(int start) 1611da177e4SLinus Torvalds { 162e39e3f3eSRussell King unsigned offset = FIQ_OFFSET; 163c0e7f7eeSDaniel Thompson dfl_fiq_insn = *(unsigned long *)(0xffff0000 + offset); 164c0e7f7eeSDaniel Thompson get_fiq_regs(&dfl_fiq_regs); 165bc89663aSShawn Guo fiq_start = start; 1661da177e4SLinus Torvalds } 167