1 // SPDX-License-Identifier: GPL-2.0 1 2 /* Tests for presence or absence of hardware r 3 * This code was originally in atari/config.c, 4 * that it was also in drivers/nubus/nubus.c a 5 * use it in hp300/config.c, so it seemed sens 6 * out into its own file. 7 * 8 * The test is for use when trying to read a h 9 * that isn't present would cause a bus error. 10 * temporary handler so that this doesn't kill 11 * 12 * There is a test-by-reading and a test-by-wr 13 * them here complete with the comments from t 14 * config.c... 15 * -- PMM <pmaydell@chiark.gree 16 */ 17 18 /* This function tests for the presence of an 19 * hardware register address. It is called ver 20 * initialization process, when the VBR regist 21 * an Atari, it still points to address 0, whi 22 * error would cause another bus error while f 23 * vector, and the CPU would do nothing at all 24 * a temporary VBR and a vector table for the 25 */ 26 27 #include <linux/module.h> 28 29 #include <asm/hwtest.h> 30 31 int hwreg_present(volatile void *regp) 32 { 33 int ret = 0; 34 unsigned long flags; 35 long save_sp, save_vbr; 36 long tmp_vectors[3]; 37 38 local_irq_save(flags); 39 __asm__ __volatile__ ( 40 "movec %/vbr,%2\n\t" 41 "movel #Lberr1,%4@(8)\n\t" 42 "movec %4,%/vbr\n\t" 43 "movel %/sp,%1\n\t" 44 "moveq #0,%0\n\t" 45 "tstb %3@\n\t" 46 "nop\n\t" 47 "moveq #1,%0\n" 48 "Lberr1:\n\t" 49 "movel %1,%/sp\n\t" 50 "movec %2,%/vbr" 51 : "=&d" (ret), "=&r" (save_sp) 52 : "a" (regp), "a" (tmp_vectors 53 ); 54 local_irq_restore(flags); 55 56 return ret; 57 } 58 EXPORT_SYMBOL(hwreg_present); 59 60 /* Basically the same, but writes a value into 61 * by a bus error handler. Returns 1 if succes 62 */ 63 64 int hwreg_write(volatile void *regp, unsigned 65 { 66 int ret; 67 unsigned long flags; 68 long save_sp, save_vbr; 69 long tmp_vectors[3]; 70 71 local_irq_save(flags); 72 __asm__ __volatile__ ( 73 "movec %/vbr,%2\n\t" 74 "movel #Lberr2,%4@(8)\n\t" 75 "movec %4,%/vbr\n\t" 76 "movel %/sp,%1\n\t" 77 "moveq #0,%0\n\t" 78 "movew %5,%3@\n\t" 79 "nop\n\t" 80 /* 81 * If this nop isn't present, 82 * with 1 at the time the bus 83 */ 84 "moveq #1,%0\n" 85 "Lberr2:\n\t" 86 "movel %1,%/sp\n\t" 87 "movec %2,%/vbr" 88 : "=&d" (ret), "=&r" (save_sp) 89 : "a" (regp), "a" (tmp_vectors 90 ); 91 local_irq_restore(flags); 92 93 return ret; 94 } 95 EXPORT_SYMBOL(hwreg_write); 96 97
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.