72 #if defined( __MSDOS__ )
74 #define OUTP(_p, _d) outportb(_p, _d)
75 #define OUTPW(_p, _d) outport(_p, _d)
76 #define INP(_p) inportb(_p)
77 #define INPW(_p) inport(_p)
78 #define OUTP_P(_p, _d) outportb(_p, _d)
79 #define OUTPW_P(_p, _d) outport(_p, _d)
80 #define INP_P(_p) inportb(_p)
81 #define INPW_P(_p) inport(_p)
82 #elif defined( _MSC_VER )
86 #define OUTP(_p, _d) _outp((WORD) (_p), (BYTE) (_d))
87 #define OUTPW(_p, _d) _outpw((WORD) (_p), (WORD) (_d))
88 #define OUTPD(_p, _d) _outpd((WORD) (_p), (unsigned int) (_d))
89 #define INP(_p) _inp((WORD) (_p))
90 #define INPW(_p) _inpw((WORD) (_p))
91 #define INPD(_p) _inpd((WORD) (_p))
92 #define OUTP_P(_p, _d) {_outp((WORD) (_p), (int) (_d)); _outp((WORD)0x80,0);}
93 #define OUTPW_P(_p, _d) {_outpw((WORD) (_p), (WORD) (_d)); _outp((WORD)0x80,0);}
94 #define INP_P(_p) _inp((WORD) (_p)); _outp((WORD)0x80,0);
95 #define INPW_P(_p) _inpw((WORD) (_p));_outp((WORD)0x80,0);
96 #elif defined( __linux__ )
97 #if !defined(__OPTIMIZE__)
98 #error Please compile hyt1331.c with the -O flag to make port access possible
104 #define OUTP(_p, _d) outb(_d, _p)
105 #define OUTPW(_p, _d) outw(_d, _p)
106 #define INP(_p) inb(_p)
107 #define INPW(_p) inw(_p)
108 #define OUTP_P(_p, _d) outb_p(_d, _p)
109 #define OUTPW_P(_p, _d) outw_p(_d, _p)
110 #define INP_P(_p) inb_p(_p)
111 #define INPW_P(_p) inw_p(_p)
116 #define MAX_DEVICES 4
125 INLINE
void cam8i(
const int c,
const int n,
const int a,
const int f, BYTE * d)
129 adr =
io_base[c >> 2] + ((c % 3) << 4);
134 status = (BYTE) INP(adr + 6);
135 *((BYTE *) d) = INP(adr);
140 INLINE
void cami(
const int c,
const int n,
const int a,
const int f,
WORD * d)
144 adr =
io_base[c >> 2] + ((c % 3) << 4);
149 status = (BYTE) INP(adr + 6);
150 *((BYTE *) d) = INP(adr);
151 *(((BYTE *) d) + 1) = INP(adr + 2);
156 INLINE
void cam16i(
const int c,
const int n,
const int a,
const int f,
WORD * d)
163 INLINE
void cam24i(
const int c,
const int n,
const int a,
const int f,
DWORD * d)
168 adr =
io_base[c >> 2] + ((c % 3) << 4);
173 status = (BYTE) INP(adr + 6);
174 *((BYTE *) d) = INP(adr);
175 *(((BYTE *) d) + 1) = INP(adr + 2);
176 *(((BYTE *) d) + 2) = INP(adr + 4);
177 *(((BYTE *) d) + 3) = 0;
182 INLINE
void cam8i_q(
const int c,
const int n,
const int a,
const int f,
183 BYTE * d,
int *x,
int *q)
188 adr =
io_base[c >> 2] + ((c % 3) << 4);
193 status = (BYTE) INP(adr + 6);
194 *((BYTE *) d) = INP(adr);
202 INLINE
void cam16i_q(
const int c,
const int n,
const int a,
const int f,
203 WORD * d,
int *x,
int *q)
208 adr =
io_base[c >> 2] + ((c % 3) << 4);
213 status = (BYTE) INP(adr + 6);
214 *((BYTE *) d) = INP(adr);
215 *(((BYTE *) d) + 1) = INP(adr + 2);
223 INLINE
void cam24i_q(
const int c,
const int n,
const int a,
const int f,
224 DWORD * d,
int *x,
int *q)
228 adr =
io_base[c >> 2] + ((c % 3) << 4);
233 status = (BYTE) INP(adr + 6);
234 *((BYTE *) d) = INP(adr);
235 *(((BYTE *) d) + 1) = INP(adr + 2);
236 *(((BYTE *) d) + 2) = INP(adr + 4);
237 *(((BYTE *) d) + 3) = 0;
245 INLINE
void cam16i_r(
const int c,
const int n,
const int a,
const int f,
246 WORD ** d,
const int r)
250 adr =
io_base[c >> 2] + ((c % 3) << 4);
256 status = (BYTE) INP(adr + 6);
257 *((BYTE *) * d) = INP(adr);
258 *(((BYTE *) * d) + 1) = INP(adr + 2);
263 for (i = 0; i < (r - 1); i++)
264 *((*d)++) = INPW(adr + 12);
269 INLINE
void cam24i_r(
const int c,
const int n,
const int a,
const int f,
270 DWORD ** d,
const int r)
274 adr =
io_base[c >> 2] + ((c % 3) << 4);
278 for (i = 0; i < r; i++) {
280 status = (BYTE) INP(adr + 6);
281 *((BYTE *) * d) = INP(adr);
282 *(((BYTE *) * d) + 1) = INP(adr + 2);
283 *(((BYTE *) * d) + 2) = INP(adr + 4);
284 *(((BYTE *) * d) + 3) = 0;
318 INLINE
void cam16i_rq(
const int c,
const int n,
const int a,
const int f,
319 WORD ** d,
const int r)
325 adr =
io_base[c >> 2] + ((c % 3) << 4);
334 for (i = 0; i < r; i++) {
336 **d = INPW_P(adr + 12);
337 fail = ((BYTE) INP(adr + 6)) & 0x20;
348 INLINE
void cam24i_rq(
const int c,
const int n,
const int a,
const int f,
349 DWORD ** d,
const int r)
354 adr =
io_base[c >> 2] + ((c % 3) << 4);
363 for (i = 0; i < r; i++) {
365 *(((BYTE *) * d) + 2) = INP(adr + 4);
366 *(((BYTE *) * d) + 3) = 0;
367 *((
WORD *) * d) = INPW_P(adr + 12);
368 fail = ((BYTE) INP(adr + 6)) & 0x20;
379 INLINE
void cam16i_sa(
const int c,
const int n,
const int a,
const int f,
380 WORD ** d,
const int r)
385 adr =
io_base[c >> 2] + ((c % 3) << 4);
387 OUTP_P(adr + 10, 49);
389 OUTP(adr + 6, a - 1);
393 for (i = 0; i < r; i++)
394 *((*d)++) = INPW_P(adr + 12);
397 OUTP_P(adr + 10, 48);
399 for (i = 0; i < r; i++)
400 cami(c, n, a + i, f, (*d)++);
405 INLINE
void cam24i_sa(
const int c,
const int n,
const int a,
const int f,
406 DWORD ** d,
const int r)
411 adr =
io_base[c >> 2] + ((c % 3) << 4);
414 OUTP_P(adr + 10, 49);
416 OUTP(adr + 6, a - 1);
419 for (i = 0; i < r; i++) {
421 *(((BYTE *) * d) + 2) = INP(adr + 4);
422 *(((BYTE *) * d) + 3) = 0;
423 *((
WORD *) * d) = INPW_P(adr + 12);
428 OUTP_P(adr + 10, 48);
430 for (i = 0; i < r; i++)
431 cam24i(c, n, a + i, f, (*d)++);
436 INLINE
void cam16i_sn(
const int c,
const int n,
const int a,
const int f,
437 WORD ** d,
const int r)
441 for (i = 0; i < r; i++)
442 cam16i(c, n + i, a, f, (*d)++);
447 INLINE
void cam24i_sn(
const int c,
const int n,
const int a,
const int f,
448 DWORD ** d,
const int r)
452 for (i = 0; i < r; i++)
453 cam24i(c, n + i, a, f, (*d)++);
458 INLINE
void cam8o(
const int c,
const int n,
const int a,
const int f, BYTE d)
462 adr =
io_base[c >> 2] + ((c % 3) << 4);
471 INLINE
void camo(
const int c,
const int n,
const int a,
const int f,
WORD d)
475 adr =
io_base[c >> 2] + ((c % 3) << 4);
479 OUTP(adr + 2, *(((BYTE *) & d) + 1));
486 INLINE
void cam16o(
const int c,
const int n,
const int a,
const int f,
WORD d)
493 INLINE
void cam24o(
const int c,
const int n,
const int a,
const int f,
DWORD d)
497 adr =
io_base[c >> 2] + ((c % 3) << 4);
500 OUTP(adr + 2, *(((BYTE *) & d) + 1));
501 OUTP(adr + 4, *(((BYTE *) & d) + 2));
508 INLINE
void cam16o_q(
const int c,
const int n,
const int a,
const int f,
509 WORD d,
int *x,
int *q)
513 adr =
io_base[c >> 2] + ((c % 3) << 4);
516 OUTP(adr + 2, *(((BYTE *) & d) + 1));
520 status = (BYTE) INP(adr + 6);
527 INLINE
void cam24o_q(
const int c,
const int n,
const int a,
const int f,
528 DWORD d,
int *x,
int *q)
532 adr =
io_base[c >> 2] + ((c % 3) << 4);
535 OUTP(adr + 2, *(((BYTE *) & d) + 1));
536 OUTP(adr + 4, *(((BYTE *) & d) + 2));
540 status = (BYTE) INP(adr + 6);
547 INLINE
void cam8o_r(
const int c,
const int n,
const int a,
const int f,
548 BYTE * d,
const int r)
552 adr =
io_base[c >> 2] + ((c % 3) << 4);
556 OUTP(adr, *((BYTE *) d));
560 for (i = 0; i < r - 1; i++)
561 OUTPW(adr + 12, (BYTE) * (++d));
566 INLINE
void cam16o_r(
const int c,
const int n,
const int a,
const int f,
567 WORD * d,
const int r)
571 adr =
io_base[c >> 2] + ((c % 3) << 4);
575 OUTP(adr, *((BYTE *) d));
576 OUTP(adr + 2, *(((BYTE *) d) + 1));
580 for (i = 0; i < r - 1; i++)
581 OUTPW(adr + 12, *(++d));
586 INLINE
void cam24o_r(
const int c,
const int n,
const int a,
const int f,
587 DWORD * d,
const int r)
591 adr =
io_base[c >> 2] + ((c % 3) << 4);
595 OUTP(adr, *((BYTE *) d));
596 OUTP(adr + 2, *(((BYTE *) d) + 1));
597 OUTP(adr + 4, *(((BYTE *) d) + 2));
601 for (i = 0; i < r - 1; i++) {
603 OUTP(adr + 4, *(((BYTE *) d) + 2));
604 OUTPW(adr + 12, (
WORD) * d);
612 unsigned int adr, n, a, f;
618 adr =
io_base[c >> 2] + ((c % 3) << 4);
619 a = (BYTE) INP(adr + 10);
620 n = (BYTE) INP(adr + 10);
621 f = (BYTE) INP(adr + 10);
623 if (n != 1 || a != 2 || f != 32)
631 INLINE
void camc(
const int c,
const int n,
const int a,
const int f)
635 adr =
io_base[c >> 2] + ((c % 3) << 4);
643 INLINE
void camc_q(
const int c,
const int n,
const int a,
const int f,
int *q)
647 adr =
io_base[c >> 2] + ((c % 3) << 4);
652 status = (BYTE) INP(adr + 6);
658 INLINE
void camc_sa(
const int c,
const int n,
const int a,
const int f,
const int r)
662 for (i = 0; i < r; i++)
663 camc(c, n, a + i, f);
668 INLINE
void camc_sn(
const int c,
const int n,
const int a,
const int f,
const int r)
672 for (i = 0; i < r; i++)
673 camc(c, n + i, a, f);
682 adr =
io_base[c >> 2] + ((c % 3) << 4);
692 adr =
io_base[c >> 2] + ((c % 3) << 4);
703 adr =
io_base[c >> 2] + ((c % 3) << 4);
704 status = (BYTE) INP(adr + 6);
705 return (status & 1) > 0;
714 adr =
io_base[c >> 2] + ((c % 3) << 4);
724 adr =
io_base[c >> 2] + ((c % 3) << 4);
736 adr =
io_base[c >> 2] + ((c % 3) << 4);
737 OUTP(adr + 10, 64 + n);
748 adr =
io_base[c >> 2] + ((c % 3) << 4);
749 OUTP(adr + 10, 128 + n);
759 adr =
io_base[c >> 2] + ((c % 3) << 4);
770 adr =
io_base[c >> 2] + ((c % 3) << 4);
781 adr =
io_base[c >> 2] + ((c % 3) << 4);
782 status = (BYTE) INP(adr + 6);
783 return (status & (1 << 2)) > 0;
794 unsigned int adr, csr;
796 adr =
io_base[c >> 2] + ((c % 3) << 4);
797 csr = (BYTE) INP(adr + 6);
798 if (csr & (1 << 3)) {
799 *lam = ((BYTE) INP(adr + 8)) & 0x1F;
800 *lam = 1 << (*lam - 1);
820 adr =
io_base[c >> 2] + ((c % 3) << 4);
827 char *client_name,
char *rpc_server)
843 DWORD buffer[] = { 6, 0, 0, 0 };
846 vi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
850 if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
851 hdio = CreateFile(
"\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL,
852 OPEN_EXISTING, 0, NULL);
853 if (hdio == INVALID_HANDLE_VALUE) {
854 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
861 if (!DeviceIoControl(hdio, (
DWORD) 0x9c406000, &buffer,
sizeof(buffer),
862 NULL, 0, &size, NULL))
868 #elif defined(__linux__)
885 if (ioperm(start, end - start + 1, 1) < 0) {
886 printf(
"hyt1331.c: Cannot call ioperm() (no root privileges)\n");
891 printf(
"hyt1331.c: Cannot call iopl() (no root privileges)\n");
901 #error This driver cannot be compiled under this operating system
915 DWORD buffer[] = { 7, 0, 0, 0 };
918 vi.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
922 if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
923 hdio = CreateFile(
"\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL,
924 OPEN_EXISTING, 0, NULL);
925 if (hdio == INVALID_HANDLE_VALUE) {
926 printf(
"hyt1331.c: Cannot access IO ports (No DirectIO driver installed)\n");
933 if (!DeviceIoControl(hdio, (
DWORD) 0x9c406000, &buffer,
sizeof(buffer),
934 NULL, 0, &size, NULL))
940 #elif defined(__linux__)
945 if (ioperm(start, end - start + 0, 0) < 0) {
946 printf(
"hyt1331.c: Cannot call ioperm() (no root privileges)\n");
951 printf(
"hyt1331.c: Cannot call iopl() (no root privileges)\n");
965 int pci_scan(
int vendor_id,
int device_id,
int n_dev, BYTE * pirq,
DWORD * ba)
972 DWORD base_addr[6],
irq, dfn, vend, vend_id, dev_id;
974 f = fopen(
"/proc/bus/pci/devices",
"r");
979 while (fgets(line,
sizeof(line), f)) {
980 sscanf(line,
"%x %x %x %lx %lx %lx %lx %lx %lx",
985 &base_addr[1], &base_addr[2], &base_addr[3], &base_addr[4], &base_addr[5]);
987 vend_id = vend >> 16U;
988 dev_id = vend & 0xFFFF;
995 if (vend_id == vendor_id && dev_id == device_id)
1006 memcpy(ba, base_addr,
sizeof(base_addr));
1012 #elif defined(_MSC_VER)
1014 DWORD buffer[] = { 8, 0, 0, 0 };
1019 hdio = CreateFile(
"\\\\.\\directio", GENERIC_READ, FILE_SHARE_READ, NULL,
1020 OPEN_EXISTING, 0, NULL);
1021 if (hdio == INVALID_HANDLE_VALUE) {
1022 printf(
"hyt1331.c: Cannot access DirectIO driver\n");
1026 buffer[1] = vendor_id;
1027 buffer[2] = device_id;
1028 buffer[3] = n_dev + 1;
1029 if (!DeviceIoControl(hdio, (
DWORD) 0x9c406000, &buffer,
sizeof(buffer),
1030 retbuf,
sizeof(retbuf), &size, NULL))
1036 *pirq = (BYTE) retbuf[0];
1037 memcpy(ba, retbuf + 1,
sizeof(
DWORD) * 6);
1048 (
"Cannot access ports. Please run with \"dio <prog>\" or compile with \"-DDO_IOPERM\"\n");
1049 signal(SIGSEGV, SIG_DFL);
1056 BYTE
status, n_dev,
i, n, a, f;
1057 WORD isa_io_base[] = { 0x200, 0x280, 0x300, 0x380 };
1065 for (n_dev = 0;; n_dev++) {
1066 if (!
pci_scan(0x1196, 0x5331, n_dev + 1,
irq + n_dev, base_addr))
1069 io_base[n_dev] = (
WORD) (base_addr[3] & (~0x3UL));
1071 printf(
"hyt1331.c: Found PCI card at 0x%X, IRQ %d\n",
io_base[n_dev],
irq[n_dev]);
1074 signal(SIGSEGV, SIG_DFL);
1083 for (i = 0; i < 4; i++) {
1084 base_test = isa_io_base[
i];
1087 signal(SIGSEGV, SIG_DFL);
1093 status = INP(base_test);
1100 OUTP(base_test + 8, 1);
1101 OUTP(base_test + 6, 2);
1102 OUTP(base_test + 10, 32);
1104 a = (BYTE) INP(base_test + 10);
1105 n = (BYTE) INP(base_test + 10);
1106 f = (BYTE) INP(base_test + 10);
1108 if (n != 1 || a != 2 || f != 32) {
1114 printf(
"hyt1331.c: Found ISA card at 0x%X\n", base_test);
1120 printf(
"hyt1331.c: No PCI or ISA cards found\n");
1121 signal(SIGSEGV, SIG_DFL);
1130 signal(SIGSEGV, SIG_DFL);
1133 for (i = 0; i < n_dev; i++) {
1135 if (!(status & (1 << 6))) {