Mercurial > vordog
annotate vordog.c @ 3:60a234c9c03f
Add 2-clause BSD license
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 08 Jul 2008 12:13:58 +0800 |
parents | 0b9854adb86c |
children | e59963b503cb |
rev | line source |
---|---|
3 | 1 /*- |
2 * Copyright (c) 2008 Kueifong Li <thinker@branda.to>. | |
3 * All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * | |
14 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | |
15 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
16 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
24 * POSSIBILITY OF SUCH DAMAGE. | |
25 */ | |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 #include <sys/param.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 #include <sys/bus.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 #include <sys/conf.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 #include <sys/kernel.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 #include <sys/module.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 #include <sys/systm.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 #include <sys/proc.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 #include <sys/ioccom.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 #include <sys/types.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 #include <sys/malloc.h> |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 #include "vordog.h" |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 |
3 | 38 #if 0 |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 #undef __FreeBSD_version |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 #define __FreeBSD_version 800029 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 #endif |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 #define VD_STATUS 0x841 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 #define VD_INITVAL 0x84a |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 #define VD_CTR 0x84b |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 typedef struct vd_softc { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 struct cdev *_cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 device_t dev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 int open_cnt; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
51 int init_val; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 } *vd_softc_t; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 #define CDEV_2_SOFTC(_cdev) ((_cdev)->si_drv1) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 static int |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 vordog_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 vd_softc_t sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 printf("vordog_open\n"); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
61 sc = CDEV_2_SOFTC(dev); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 sc->open_cnt++; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
63 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
64 return 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
66 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
67 static int |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
68 vordog_close(struct cdev *dev, int fflag, int devtype, struct thread *td) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
69 vd_softc_t sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
71 printf("vordog_close\n"); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
72 sc = CDEV_2_SOFTC(dev); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
73 sc->open_cnt--; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
74 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
75 return 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
76 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
77 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
78 static int |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
79 vordog_go_detach(void) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 devclass_t vd_dc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
81 device_t vd_dev, nexus_dev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
82 int r; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
83 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
84 printf("go_detach 1\n"); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
85 vd_dc = devclass_find("vordog"); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
86 if(vd_dc == NULL) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
87 return EINVAL; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
88 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
89 printf("go_detach 2\n"); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
90 vd_dev = devclass_get_device(vd_dc, 0); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
91 if(vd_dev == NULL) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
92 return EINVAL; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
93 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
94 printf("go_detach 3\n"); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
95 nexus_dev = device_get_parent(vd_dev); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
96 if(nexus_dev == NULL) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
97 return EINVAL; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
98 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
99 printf("go_detach 4\n"); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
100 r = device_delete_child(nexus_dev, vd_dev); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
101 return r; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
102 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
103 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
104 static void |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
105 setup_timer(vordog_cfg_t cfg) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
106 int val; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
107 #define VD_TIMER_RST 0xc |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
108 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
109 val = cfg->init_val & 0xff; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
110 outb(VD_INITVAL, val); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
111 val = 0x80 | ((cfg->unit & 0x3) << 4) | VD_TIMER_RST; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
112 outb(VD_CTR, val); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
113 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
114 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
115 static void |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
116 reset_timer(int init_val) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
117 outb(VD_STATUS, 0xc0); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
118 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
119 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
120 static void |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
121 disable_timer(void) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
122 outb(VD_CTR, 0); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
123 outb(VD_STATUS, 0xc0); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
124 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
125 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
126 static int |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
127 vordog_ioctl(struct cdev *dev, u_long cmd, caddr_t data, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
128 int fflag, struct thread *td) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
129 int r = 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
130 vd_softc_t sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
131 vordog_cfg_t cfg; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
132 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
133 sc = CDEV_2_SOFTC(dev); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
134 switch(cmd) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
135 case VDCTL_ENABLE: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
136 cfg = (vordog_cfg_t)data; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
137 sc->init_val = cfg->init_val & 0xff; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
138 setup_timer(cfg); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
139 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
140 case VDCTL_RESET: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
141 reset_timer(sc->init_val); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
142 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
143 case VDCTL_DISABLE: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
144 disable_timer(); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
145 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
146 default: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
147 r = EINVAL; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
148 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
149 return r; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
150 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
151 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
152 struct cdevsw vordog_cdevsw = { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
153 .d_version = D_VERSION, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
154 .d_open = vordog_open, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
155 .d_close = vordog_close, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
156 .d_ioctl = vordog_ioctl, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
157 .d_name = "vordog", |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
158 }; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
159 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
160 static void vordog_identify(driver_t *driver, device_t parent) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
161 device_t vordog; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
162 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
163 /* make sure vordog device is not in the bus. */ |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
164 vordog = device_find_child(parent, "vordog", 0); |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
165 if(vordog != NULL) |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
166 return; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
167 vordog = BUS_ADD_CHILD(parent, 10, "vordog", 0); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
168 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
169 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
170 static int vordog_probe(device_t dev) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
171 int b; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
172 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
173 b = inb(VD_INITVAL); |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
174 if(b != 0) |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
175 return EINVAL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
176 b = inb(VD_CTR); |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
177 if(b != 0) |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
178 return EINVAL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
179 b = inb(VD_STATUS); |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
180 if(b != 0) |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
181 return EINVAL; |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
182 return 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
183 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
184 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
185 static int vordog_attach(device_t dev) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
186 vd_softc_t sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
187 struct cdev *_cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
188 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
189 sc = (vd_softc_t)malloc(sizeof(struct vd_softc), M_TEMP, M_WAITOK); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
190 if(sc == NULL) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
191 return ENOMEM; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
192 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
193 _cdev = make_dev(&vordog_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "vordog0"); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
194 if(_cdev == NULL) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
195 free(sc, M_TEMP); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
196 return EINVAL; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
197 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
198 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
199 sc->_cdev = _cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
200 sc->dev = dev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
201 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
202 device_set_softc(dev, sc); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
203 CDEV_2_SOFTC(_cdev) = sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
204 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
205 sc->open_cnt = 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
206 sc->init_val = 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
207 |
1
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
208 device_set_desc(dev, "Watchdog of Vortex86 SoC"); |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
209 device_printf(dev, "<Vortex86 SoC watchdog> at port 0x%x\n", VD_STATUS); |
0b9854adb86c
Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents:
0
diff
changeset
|
210 |
0
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
211 return 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
212 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
213 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
214 static int vordog_detach(device_t dev) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
215 vd_softc_t sc; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
216 struct cdev *_cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
217 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
218 sc = device_get_softc(dev); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
219 if(sc->open_cnt != 0) |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
220 return EBUSY; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
221 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
222 _cdev = sc->_cdev; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
223 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
224 destroy_dev(_cdev); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
225 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
226 free(sc, M_TEMP); |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
227 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
228 return 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
229 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
230 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
231 static device_method_t vordog_methods[] = { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
232 DEVMETHOD(device_identify, vordog_identify), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
233 DEVMETHOD(device_probe, vordog_probe), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
234 DEVMETHOD(device_attach, vordog_attach), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
235 DEVMETHOD(device_detach, vordog_detach), |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
236 {0, 0} |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
237 }; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
238 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
239 static driver_t vordog_driver = { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
240 "vordog", |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
241 vordog_methods, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
242 0, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
243 }; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
244 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
245 static int |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
246 vordog_evh(module_t mod, int cmd, void *arg) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
247 int r = 0; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
248 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
249 switch(cmd) { |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
250 case MOD_LOAD: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
251 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
252 case MOD_UNLOAD: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
253 vordog_go_detach(); /* remove device from parent */ |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
254 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
255 case MOD_SHUTDOWN: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
256 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
257 default: |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
258 r = EINVAL; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
259 break; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
260 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
261 return r; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
262 } |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
263 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
264 static devclass_t vordog_devclass; |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
265 |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
266 DRIVER_MODULE(vordog, nexus, vordog_driver, vordog_devclass, |
71475f5afa92
Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
267 vordog_evh, NULL); |