annotate vordog.c @ 1:0b9854adb86c

Remove tedious messages and daemonize vd_watchdog.
author Thinker K.F. Li <thinker@branda.to>
date Tue, 08 Jul 2008 11:07:31 +0800
parents 71475f5afa92
children 60a234c9c03f
rev   line source
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <sys/param.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <sys/bus.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <sys/conf.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <sys/kernel.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <sys/module.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #include <sys/systm.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include <sys/proc.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 #include <sys/ioccom.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 #include <sys/types.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 #include <sys/malloc.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 #include "vordog.h"
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 #if 1
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 #undef __FreeBSD_version
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 #define __FreeBSD_version 800029
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 #endif
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 #define VD_STATUS 0x841
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 #define VD_INITVAL 0x84a
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 #define VD_CTR 0x84b
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 typedef struct vd_softc {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 struct cdev *_cdev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 device_t dev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 int open_cnt;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 int init_val;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 } *vd_softc_t;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 #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
30
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 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
33 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 printf("vordog_open\n");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 sc = CDEV_2_SOFTC(dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 sc->open_cnt++;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 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
44 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 printf("vordog_close\n");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 sc = CDEV_2_SOFTC(dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 sc->open_cnt--;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 vordog_go_detach(void) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 devclass_t vd_dc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 device_t vd_dev, nexus_dev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 int r;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 printf("go_detach 1\n");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 vd_dc = devclass_find("vordog");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 if(vd_dc == NULL)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 return EINVAL;
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 printf("go_detach 2\n");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 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
66 if(vd_dev == NULL)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 return EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 printf("go_detach 3\n");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 nexus_dev = device_get_parent(vd_dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 if(nexus_dev == NULL)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 return EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 printf("go_detach 4\n");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 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
76 return r;
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
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 static void
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 setup_timer(vordog_cfg_t cfg) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 int val;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 #define VD_TIMER_RST 0xc
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 val = cfg->init_val & 0xff;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 outb(VD_INITVAL, val);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 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
87 outb(VD_CTR, val);
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
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 static void
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 reset_timer(int init_val) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 outb(VD_STATUS, 0xc0);
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
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 static void
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 disable_timer(void) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97 outb(VD_CTR, 0);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 outb(VD_STATUS, 0xc0);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 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
103 int fflag, struct thread *td) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 int r = 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 vordog_cfg_t cfg;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 sc = CDEV_2_SOFTC(dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
109 switch(cmd) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
110 case VDCTL_ENABLE:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 cfg = (vordog_cfg_t)data;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 sc->init_val = cfg->init_val & 0xff;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113 setup_timer(cfg);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 case VDCTL_RESET:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116 reset_timer(sc->init_val);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 case VDCTL_DISABLE:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 disable_timer();
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
120 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 default:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
122 r = EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
123 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 return r;
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
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 struct cdevsw vordog_cdevsw = {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 .d_version = D_VERSION,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129 .d_open = vordog_open,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 .d_close = vordog_close,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 .d_ioctl = vordog_ioctl,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132 .d_name = "vordog",
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 };
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 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
136 device_t vordog;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 /* 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
139 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
140 if(vordog != NULL)
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141 return;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142 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
143 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 static int vordog_probe(device_t dev) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 int b;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148 b = inb(VD_INITVAL);
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
149 if(b != 0)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
150 return EINVAL;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 b = inb(VD_CTR);
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
152 if(b != 0)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
153 return EINVAL;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154 b = inb(VD_STATUS);
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
155 if(b != 0)
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
156 return EINVAL;
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157 return 0;
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 int vordog_attach(device_t dev) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162 struct cdev *_cdev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
163
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
164 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
165 if(sc == NULL)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 return ENOMEM;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
168 _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
169 if(_cdev == NULL) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 free(sc, M_TEMP);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171 return EINVAL;
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
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 sc->_cdev = _cdev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175 sc->dev = dev;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
177 device_set_softc(dev, sc);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
178 CDEV_2_SOFTC(_cdev) = sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
180 sc->open_cnt = 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181 sc->init_val = 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
182
1
0b9854adb86c Remove tedious messages and daemonize vd_watchdog.
Thinker K.F. Li <thinker@branda.to>
parents: 0
diff changeset
183 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
184 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
185
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
186 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
187 }
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 static int vordog_detach(device_t dev) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
190 vd_softc_t sc;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
191 struct cdev *_cdev;
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 sc = device_get_softc(dev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 if(sc->open_cnt != 0)
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195 return EBUSY;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
197 _cdev = sc->_cdev;
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 destroy_dev(_cdev);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
200
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
201 free(sc, M_TEMP);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
202
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 return 0;
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
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
206 static device_method_t vordog_methods[] = {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
207 DEVMETHOD(device_identify, vordog_identify),
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
208 DEVMETHOD(device_probe, vordog_probe),
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
209 DEVMETHOD(device_attach, vordog_attach),
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
210 DEVMETHOD(device_detach, vordog_detach),
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
211 {0, 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 driver_t vordog_driver = {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
215 "vordog",
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
216 vordog_methods,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
217 0,
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
218 };
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
219
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
220 static int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
221 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
222 int r = 0;
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 switch(cmd) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
225 case MOD_LOAD:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
226 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
227 case MOD_UNLOAD:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
228 vordog_go_detach(); /* remove device from parent */
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
229 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
230 case MOD_SHUTDOWN:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
231 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
232 default:
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
233 r = EINVAL;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
234 break;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
235 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
236 return r;
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 devclass_t vordog_devclass;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
240
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
241 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
242 vordog_evh, NULL);