Linux Audio

Check our new training course

Linux BSP development engineering services

Need help to port Linux and bootloaders to your hardware?
Loading...
v3.1
 
 1/* Tests for presence or absence of hardware registers.
 2 * This code was originally in atari/config.c, but I noticed
 3 * that it was also in drivers/nubus/nubus.c and I wanted to
 4 * use it in hp300/config.c, so it seemed sensible to pull it
 5 * out into its own file.
 6 *
 7 * The test is for use when trying to read a hardware register
 8 * that isn't present would cause a bus error. We set up a
 9 * temporary handler so that this doesn't kill the kernel.
10 *
11 * There is a test-by-reading and a test-by-writing; I present
12 * them here complete with the comments from the original atari
13 * config.c...
14 *                -- PMM <pmaydell@chiark.greenend.org.uk>, 05/1998
15 */
16
17/* This function tests for the presence of an address, specially a
18 * hardware register address. It is called very early in the kernel
19 * initialization process, when the VBR register isn't set up yet. On
20 * an Atari, it still points to address 0, which is unmapped. So a bus
21 * error would cause another bus error while fetching the exception
22 * vector, and the CPU would do nothing at all. So we needed to set up
23 * a temporary VBR and a vector table for the duration of the test.
24 */
25
26#include <linux/module.h>
27
28int hwreg_present( volatile void *regp )
 
 
29{
30    int	ret = 0;
31    long	save_sp, save_vbr;
32    long	tmp_vectors[3];
33
34    __asm__ __volatile__
35	(	"movec	%/vbr,%2\n\t"
36		"movel	#Lberr1,%4@(8)\n\t"
37                "movec	%4,%/vbr\n\t"
38		"movel	%/sp,%1\n\t"
39		"moveq	#0,%0\n\t"
40		"tstb	%3@\n\t"
 
 
41		"nop\n\t"
42		"moveq	#1,%0\n"
43                "Lberr1:\n\t"
44		"movel	%1,%/sp\n\t"
45		"movec	%2,%/vbr"
46		: "=&d" (ret), "=&r" (save_sp), "=&r" (save_vbr)
47		: "a" (regp), "a" (tmp_vectors)
48                );
 
49
50    return( ret );
51}
52EXPORT_SYMBOL(hwreg_present);
53
54/* Basically the same, but writes a value into a word register, protected
55 * by a bus error handler. Returns 1 if successful, 0 otherwise.
56 */
57
58int hwreg_write( volatile void *regp, unsigned short val )
59{
60	int		ret;
61	long	save_sp, save_vbr;
62	long	tmp_vectors[3];
63
64	__asm__ __volatile__
65	(	"movec	%/vbr,%2\n\t"
66		"movel	#Lberr2,%4@(8)\n\t"
67		"movec	%4,%/vbr\n\t"
68		"movel	%/sp,%1\n\t"
69		"moveq	#0,%0\n\t"
70		"movew	%5,%3@\n\t"
71		"nop	\n\t"	/* If this nop isn't present, 'ret' may already be
72				 * loaded with 1 at the time the bus error
73				 * happens! */
74		"moveq	#1,%0\n"
 
 
 
 
75	"Lberr2:\n\t"
76		"movel	%1,%/sp\n\t"
77		"movec	%2,%/vbr"
78		: "=&d" (ret), "=&r" (save_sp), "=&r" (save_vbr)
79		: "a" (regp), "a" (tmp_vectors), "g" (val)
80	);
 
81
82	return( ret );
83}
84EXPORT_SYMBOL(hwreg_write);
85
v6.8
 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.
 7 *
 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.
11 *
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
14 * config.c...
15 *                -- PMM <pmaydell@chiark.greenend.org.uk>, 05/1998
16 */
17
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.
25 */
26
27#include <linux/module.h>
28
29#include <asm/hwtest.h>
30
31int 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), "=&r" (save_vbr)
52		: "a" (regp), "a" (tmp_vectors)
53	);
54	local_irq_restore(flags);
55
56	return ret;
57}
58EXPORT_SYMBOL(hwreg_present);
59
60/* Basically the same, but writes a value into a word register, protected
61 * by a bus error handler. Returns 1 if successful, 0 otherwise.
62 */
63
64int hwreg_write(volatile void *regp, unsigned short val)
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, 'ret' may already be loaded
82		 * with 1 at the time the bus error happens!
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), "=&r" (save_vbr)
89		: "a" (regp), "a" (tmp_vectors), "g" (val)
90	);
91	local_irq_restore(flags);
92
93	return ret;
94}
95EXPORT_SYMBOL(hwreg_write);
96