1 | #define _GNU_SOURCE
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include <errno.h>
|
---|
5 | #include <string.h>
|
---|
6 | #include <sys/types.h>
|
---|
7 | #include <unistd.h>
|
---|
8 | #include <fcntl.h>
|
---|
9 | #include <sys/mman.h>
|
---|
10 | #include <sys/ioctl.h>
|
---|
11 | #include <signal.h>
|
---|
12 |
|
---|
13 | #include "dev/pci/sis1100_var.h"
|
---|
14 |
|
---|
15 | int sis_base[]={0, 0x60000, 0x70000};
|
---|
16 |
|
---|
17 | /****************************************************************************/
|
---|
18 | static int vme_read(int p, int base, int addr)
|
---|
19 | {
|
---|
20 | int res;
|
---|
21 | struct sis1100_vme_req req;
|
---|
22 |
|
---|
23 | req.size=4;
|
---|
24 | req.am=0x9;
|
---|
25 | req.addr=base+addr;
|
---|
26 | res=ioctl(p, SIS3100_VME_READ, &req);
|
---|
27 | if (res)
|
---|
28 | printf("vme read 0x%08x: res=%s, error=0x%x\n",
|
---|
29 | req.addr, strerror(errno), req.error);
|
---|
30 | return req.data;
|
---|
31 | }
|
---|
32 | /****************************************************************************/
|
---|
33 | static void vme_write(int p, int base, int addr, int data)
|
---|
34 | {
|
---|
35 | int res;
|
---|
36 | struct sis1100_vme_req req;
|
---|
37 |
|
---|
38 | req.size=4;
|
---|
39 | req.am=0x9;
|
---|
40 | req.addr=base+addr;
|
---|
41 | req.data=data;
|
---|
42 | res=ioctl(p, SIS3100_VME_WRITE, &req);
|
---|
43 | if (res)
|
---|
44 | printf("vme write 0x%08x, 0x%08x: res=%s, error=0x%x\n",
|
---|
45 | req.addr, req.data, strerror(errno), req.error);
|
---|
46 | }
|
---|
47 | /****************************************************************************/
|
---|
48 | volatile int idx, irq, irqcount=0;
|
---|
49 |
|
---|
50 | static void sighnd(int sig)
|
---|
51 | {
|
---|
52 | irq++; irqcount++;
|
---|
53 | fprintf(stderr, "got sig %d\n", sig);
|
---|
54 | }
|
---|
55 | /****************************************************************************/
|
---|
56 | int main(int argc, char* argv[])
|
---|
57 | {
|
---|
58 | int p, module, idx;
|
---|
59 | struct sigaction action, old_action;
|
---|
60 | struct sis1100_irq_ctl irqctl;
|
---|
61 | struct sis1100_irq_get irqget;
|
---|
62 | struct sis1100_irq_ack irqack;
|
---|
63 |
|
---|
64 | if (argc!=2)
|
---|
65 | {
|
---|
66 | fprintf(stderr, "usage: %s path\n", argv[0]);
|
---|
67 | return 1;
|
---|
68 | }
|
---|
69 |
|
---|
70 | if ((p=open(argv[1], O_RDWR, 0))<0) return 1;
|
---|
71 |
|
---|
72 | action.sa_handler=sighnd;
|
---|
73 | sigemptyset(&action.sa_mask);
|
---|
74 | action.sa_flags=0;
|
---|
75 | sigaction(SIGUSR1, &action, &old_action);
|
---|
76 |
|
---|
77 | /*
|
---|
78 | * sigemptyset(&mask);
|
---|
79 | * sigaddset(&mask, SIGUSR1);
|
---|
80 | * sigprocmask(SIG_BLOCK, &mask, &old_mask);
|
---|
81 | */
|
---|
82 |
|
---|
83 | for (module=0; module<3; module++) {
|
---|
84 | vme_write(p, sis_base[module], 0x60, 0); /* reset */
|
---|
85 | }
|
---|
86 |
|
---|
87 | irqctl.irq_mask=0xffff; /* ALL levels; just for fun */
|
---|
88 | irqctl.signal=SIGUSR1;
|
---|
89 | if (ioctl(p, SIS1100_IRQ_CTL, &irqctl)<0) {
|
---|
90 | fprintf(stderr, "ioctl(SIS3100_IRQ_CTL): %s\n", strerror(errno));
|
---|
91 | return 1;
|
---|
92 | }
|
---|
93 |
|
---|
94 | idx=0;
|
---|
95 | for (module=0; module<3; module++) {
|
---|
96 | int base, level;
|
---|
97 | base=sis_base[module];
|
---|
98 | level=module+1;
|
---|
99 | vme_write(p, base, 0x20, 0); /* fifo clear */
|
---|
100 | vme_write(p, base, 0x28, 0); /* enable next logic */
|
---|
101 | vme_write(p, base, 0x0, 0x400000); /* enable irq source 2 (half full) */
|
---|
102 | vme_write(p, base, 0x4, 0x800|((level&7)<<9)|level);
|
---|
103 |
|
---|
104 | irq=0;
|
---|
105 | while (!irq) {
|
---|
106 | idx++;
|
---|
107 | vme_write(p, base, 0x24, 0); /* clock */
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | /*
|
---|
112 | * sigsuspend(&old_mask);
|
---|
113 | * fprintf(stderr, "after suspend\n");
|
---|
114 | */
|
---|
115 |
|
---|
116 | while (1) {
|
---|
117 | int base, count, data;
|
---|
118 | irqget.irq_mask=0xffff;
|
---|
119 | irqget.immediate_ack=0;
|
---|
120 | if (ioctl(p, SIS1100_IRQ_GET, &irqget)<0) {
|
---|
121 | fprintf(stderr, "ioctl(SIS1100_IRQ_GET): %s\n", strerror(errno));
|
---|
122 | return 1;
|
---|
123 | }
|
---|
124 | printf("got irqs 0x%08x level=%d vector 0x%x\n",
|
---|
125 | irqget.irqs, irqget.level, irqget.vector);
|
---|
126 | if (!irqget.irqs) return 0;
|
---|
127 |
|
---|
128 | base=sis_base[irqget.vector-1];
|
---|
129 | count=0;
|
---|
130 | while ((vme_read(p, base, 0x0)&0x100)==0) {
|
---|
131 | data=vme_read(p, base, 0x100);
|
---|
132 | count++;
|
---|
133 | }
|
---|
134 | printf("count=%d\n", count);
|
---|
135 |
|
---|
136 | irqack.irq_mask=1<<irqget.level;
|
---|
137 | if (ioctl(p, SIS1100_IRQ_ACK, &irqack)<0) {
|
---|
138 | fprintf(stderr, "ioctl(SIS1100_IRQ_ACK): %s\n", strerror(errno));
|
---|
139 | return 1;
|
---|
140 | }
|
---|
141 | }
|
---|
142 | sigaction(SIGUSR1, &old_action, 0);
|
---|
143 |
|
---|
144 | close(p);
|
---|
145 | return 0;
|
---|
146 | }
|
---|
147 | /****************************************************************************/
|
---|
148 | /****************************************************************************/
|
---|