summaryrefslogtreecommitdiff
path: root/devel/picprg/patches/patch-ac
blob: a6a53b59ae6d08ef4aa5c6cfa2149b8c3a47636f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
$NetBSD: patch-ac,v 1.1.1.1 2005/09/24 09:30:54 dsainty Exp $

The programmer makes direct I/O bus accesses via the i386 in/out instructions.
Port this to work via the NetBSD i386_set_ioperm() interface.

--- lowlvl.c	2002-05-29 00:54:00.000000000 +1200
+++ lowlvl.c	2005-09-12 23:41:56.000000000 +1200
@@ -42,15 +42,17 @@
    
    ------------------------------------------------------------------------ */
 #include "picprg.h"
-#include <fcntl.h>
-#include <linux/lp.h>
+
 #include <sys/ioctl.h>
 #include <sys/time.h>
-#include <asm/system.h>
+#include <sys/types.h>
+
+#include <machine/sysarch.h>
+
+#include <fcntl.h>
+#include <string.h>
 
-/* Aisha changed because address will be stored, 3-21-00 */
-uint portaddr;
-#define LP_B(x) (portaddr)
+#define LP_B(x) (x)
 
 extern int debug;			/* Deug level 			*/
 extern dev_id_p pic_device;		/* PIC device info 		*/
@@ -122,15 +124,12 @@
 };
 
 
-extern int ioperm(unsigned long port,unsigned long length,int state);
-
 /* -----------------------------------------------------------------------
    Port control routines -- easier than asm/io.h's routines
    ----------------------------------------------------------------------- */
 static inline void
 outb ( char val, short port)
 {
-  ioperm(port, 1, 1);
   __asm__ volatile ("out%B0 %0,%1" : :"a" (val), "d" (port));
 }
 
@@ -138,8 +137,7 @@
 inb (short port)
 {
   unsigned int ret;
-  
-  ioperm(port, 1, 1);  
+
   __asm__ volatile ("in%B0 %1,%0" : "=a" (ret) : "d" (port));
   
   return ret;
@@ -366,53 +364,23 @@
    ----------------------------------------------------------------------- */
 int init_port()
 {
-  char	printer[128];
-  FILE *parport;
-  int	fd,linux24=0;
-      
-  sprintf(printer,"/dev/lp%d", pconfig.port );
+  if (debug)
+    printf( "I/O base address is 0x%x\n", LP_B( pconfig.port ) );
 
-  fd=open(printer,O_WRONLY);
-  
-  /*  Aisha changed, 3/21/00 
-      ... and BAJ rechanged 5/16/02 to get port address from /proc/parport... */
-    if ( fd<0 )
-    {
-       perror(NULL);
-      return 0;
-    }
-    
-   /* BAJ Add. If the printer port is cool then set portaddr to the base value 
-      listed in /proc/parport/<port>/hardware */
+  {
+    unsigned long iomap[32];
+    unsigned int portoffset;
 
-    close(fd);
-    sprintf(printer,"/proc/parport/%d/hardware",pconfig.port);
-    parport=fopen(printer,"r");
-    if (!parport) {
-      // BAJ Add 5/28/02. Check for Linux 2.4 kernel parport parameters
-
-      sprintf(printer,"/proc/sys/dev/parport/parport%d/base-addr",pconfig.port);
-      parport=fopen(printer,"r");
-      if (!parport) {
-         fprintf(stderr,"Cannot open parport info file %s.\n\n",printer);
-         return 0;
-      }
-      else
-         linux24=1;
+    memset(iomap, '\0xff', sizeof(iomap));
+    for (portoffset = 0; portoffset < 3; portoffset++) {
+      unsigned int portnumber = LP_B(pconfig.port) + portoffset;
+      iomap[portnumber / 32] &= ~(unsigned long)(1 << (portnumber % 32));
     }
-    
-    if ((fscanf(parport,linux24?"%d":"base: %x",&portaddr)) != 1) {
-      fprintf(stderr,"Cannot read base address from parport info file %s.\n\n",printer);
+
+    if (i386_set_ioperm(iomap) == -1) {
+      perror("i386_set_ioperm failed");
       return 0;
     }
-    if ( debug )  
-    printf( "I/O base address for %s is 0x%x\n", printer, LP_B( pconfig.port ) );
-
-  /* Get permission to access the config register */
-  if ( ioperm( LP_B( pconfig.port )+1, 1L, 1) <0 )
-  {
-    printf("access to port 0x%x denied\n", LP_B( pconfig.port )+1 );
-    return 0;
   }
 
   /* Get the initial states of data and command lines */