]> rtime.felk.cvut.cz Git - mcf548x/linux.git/blob - arch/m68k/mm/hwtest.c
Current (FEC from 2.6.31 port, no CAN, no I2C, no PCI)
[mcf548x/linux.git] / arch / m68k / mm / hwtest.c
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
28 /* On Coldfire if XLB arbiter isn't set up this would kill the kernel.
29  * So let's not do this.
30  */
31
32 #ifndef CONFIG_COLDFIRE 
33 int hwreg_present( volatile void *regp )
34 {
35     int ret = 0;
36     long        save_sp, save_vbr;
37     long        tmp_vectors[3];
38
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
55     return( ret );
56 }
57 EXPORT_SYMBOL(hwreg_present);
58
59 /* Basically the same, but writes a value into a word register, protected
60  * by a bus error handler. Returns 1 if successful, 0 otherwise.
61  */
62
63 int hwreg_write( volatile void *regp, unsigned short val )
64 {
65         int             ret;
66         long    save_sp, save_vbr;
67         long    tmp_vectors[3];
68
69         __asm__ __volatile__
70         (       "movec  %/vbr,%2\n\t"
71                 "movel  #Lberr2,%4@(8)\n\t"
72                 "movec  %4,%/vbr\n\t"
73                 "movel  %/sp,%1\n\t"
74                 "moveq  #0,%0\n\t"
75                 "movew  %5,%3@\n\t"
76                 "nop    \n\t"   /* If this nop isn't present, 'ret' may already be
77                                  * loaded with 1 at the time the bus error
78                                  * happens! */
79                 "moveq  #1,%0\n"
80         "Lberr2:\n\t"
81                 "movel  %1,%/sp\n\t"
82                 "movec  %2,%/vbr"
83                 : "=&d" (ret), "=&r" (save_sp), "=&r" (save_vbr)
84                 : "a" (regp), "a" (tmp_vectors), "g" (val)
85         );
86
87         return( ret );
88 }
89 EXPORT_SYMBOL(hwreg_write);
90 #endif 
91