1 // SPDX-License-Identifier: GPL-2.0
2 /* Tests for presence or absence of hardware registers.
3 * This code was originally in atari/config.c, but I noticed
4 * that it was also in drivers/nubus/nubus.c and I wanted to
5 * use it in hp300/config.c, so it seemed sensible to pull it
6 * out into its own file.
8 * The test is for use when trying to read a hardware register
9 * that isn't present would cause a bus error. We set up a
10 * temporary handler so that this doesn't kill the kernel.
12 * There is a test-by-reading and a test-by-writing; I present
13 * them here complete with the comments from the original atari
15 * -- PMM <pmaydell@chiark.greenend.org.uk>, 05/1998
18 /* This function tests for the presence of an address, specially a
19 * hardware register address. It is called very early in the kernel
20 * initialization process, when the VBR register isn't set up yet. On
21 * an Atari, it still points to address 0, which is unmapped. So a bus
22 * error would cause another bus error while fetching the exception
23 * vector, and the CPU would do nothing at all. So we needed to set up
24 * a temporary VBR and a vector table for the duration of the test.
27 #include <linux/module.h>
29 int hwreg_present(volatile void *regp
)
33 long save_sp
, save_vbr
;
36 local_irq_save(flags
);
37 __asm__
__volatile__ (
39 "movel #Lberr1,%4@(8)\n\t"
49 : "=&d" (ret
), "=&r" (save_sp
), "=&r" (save_vbr
)
50 : "a" (regp
), "a" (tmp_vectors
)
52 local_irq_restore(flags
);
56 EXPORT_SYMBOL(hwreg_present
);
58 /* Basically the same, but writes a value into a word register, protected
59 * by a bus error handler. Returns 1 if successful, 0 otherwise.
62 int hwreg_write(volatile void *regp
, unsigned short val
)
66 long save_sp
, save_vbr
;
69 local_irq_save(flags
);
70 __asm__
__volatile__ (
72 "movel #Lberr2,%4@(8)\n\t"
79 * If this nop isn't present, 'ret' may already be loaded
80 * with 1 at the time the bus error happens!
86 : "=&d" (ret
), "=&r" (save_sp
), "=&r" (save_vbr
)
87 : "a" (regp
), "a" (tmp_vectors
), "g" (val
)
89 local_irq_restore(flags
);
93 EXPORT_SYMBOL(hwreg_write
);