Merge branch 'x86/uaccess' into core/percpu
[linux-2.6] / arch / sparc / prom / devops_32.c
1 /*
2  * devops.c:  Device operations using the PROM.
3  *
4  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5  */
6 #include <linux/types.h>
7 #include <linux/kernel.h>
8 #include <linux/sched.h>
9
10 #include <asm/openprom.h>
11 #include <asm/oplib.h>
12
13 extern void restore_current(void);
14
15 /* Open the device described by the string 'dstr'.  Returns the handle
16  * to that device used for subsequent operations on that device.
17  * Returns -1 on failure.
18  */
19 int
20 prom_devopen(char *dstr)
21 {
22         int handle;
23         unsigned long flags;
24         spin_lock_irqsave(&prom_lock, flags);
25         switch(prom_vers) {
26         case PROM_V0:
27                 handle = (*(romvec->pv_v0devops.v0_devopen))(dstr);
28                 if(handle == 0) handle = -1;
29                 break;
30         case PROM_V2:
31         case PROM_V3:
32                 handle = (*(romvec->pv_v2devops.v2_dev_open))(dstr);
33                 break;
34         default:
35                 handle = -1;
36                 break;
37         };
38         restore_current();
39         spin_unlock_irqrestore(&prom_lock, flags);
40
41         return handle;
42 }
43
44 /* Close the device described by device handle 'dhandle'. */
45 int
46 prom_devclose(int dhandle)
47 {
48         unsigned long flags;
49         spin_lock_irqsave(&prom_lock, flags);
50         switch(prom_vers) {
51         case PROM_V0:
52                 (*(romvec->pv_v0devops.v0_devclose))(dhandle);
53                 break;
54         case PROM_V2:
55         case PROM_V3:
56                 (*(romvec->pv_v2devops.v2_dev_close))(dhandle);
57                 break;
58         default:
59                 break;
60         };
61         restore_current();
62         spin_unlock_irqrestore(&prom_lock, flags);
63         return 0;
64 }
65
66 /* Seek to specified location described by 'seekhi' and 'seeklo'
67  * for device 'dhandle'.
68  */
69 void
70 prom_seek(int dhandle, unsigned int seekhi, unsigned int seeklo)
71 {
72         unsigned long flags;
73         spin_lock_irqsave(&prom_lock, flags);
74         switch(prom_vers) {
75         case PROM_V0:
76                 (*(romvec->pv_v0devops.v0_seekdev))(dhandle, seekhi, seeklo);
77                 break;
78         case PROM_V2:
79         case PROM_V3:
80                 (*(romvec->pv_v2devops.v2_dev_seek))(dhandle, seekhi, seeklo);
81                 break;
82         default:
83                 break;
84         };
85         restore_current();
86         spin_unlock_irqrestore(&prom_lock, flags);
87
88         return;
89 }