revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / opendevice.c
blob000e96c57379ce8e4a02e7e6b12fc0bdd5cdd6ea
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Open a device.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <exec/execbase.h>
11 #include <exec/devices.h>
12 #include <exec/io.h>
13 #include <exec/errors.h>
14 #include <aros/libcall.h>
15 #include <exec/libraries.h>
16 #include <proto/exec.h>
18 #include "exec_intern.h"
19 #include "exec_debug.h"
20 #include "exec_locks.h"
22 /*****************************************************************************
24 NAME */
26 AROS_LH4(LONG, OpenDevice,
28 /* SYNOPSIS */
29 AROS_LHA(CONST_STRPTR, devName, A0),
30 AROS_LHA(IPTR, unitNumber, D0),
31 AROS_LHA(struct IORequest *, iORequest, A1),
32 AROS_LHA(ULONG, flags, D1),
34 /* LOCATION */
35 struct ExecBase *, SysBase, 74, Exec)
37 /* FUNCTION
38 Tries to open a device and fill the iORequest structure. An error
39 is returned if this fails, 0 if all went well.
41 If the device doesn't exist in the current system device list, then
42 first the system ROMtag module list, then if the DOS is running,
43 then the DEVS: directory will be tried.
45 INPUTS
46 devName - Pointer to the devices's name.
47 unitNumber - The unit number. Most often 0. In some special cases this can be
48 a pointer to something (device-dependent).
49 iORequest - Pointer to device specific information.
50 Will be filled out by the device.
51 Must lie in public (or at least shared) memory.
52 flags - Some flags to give to the device.
54 RESULT
55 Error code or 0 if all went well. The same value can be found
56 in the io_Error field.
58 NOTES
59 Return type is internally extended to LONG in all existing official ROMs
60 (EXT.W D0 + EXT.L D0) DoIO() and WaitIO() do the same.
61 Many programs assume LONG return code, even some WB utilities.
63 EXAMPLE
65 BUGS
67 SEE ALSO
68 OpenDevice()
70 INTERNALS
72 *****************************************************************************/
74 AROS_LIBFUNC_INIT
77 * Kludge for compatibility with V40 kickstart. DO NOT depend on this!
78 * See TaggedOpenLibrary() for more info.
80 switch ((IPTR)devName)
82 case 0:
83 devName = "timer.device";
84 break;
86 case 1:
87 devName = "input.device";
88 break;
91 D(bug("[exec] OpenDevice(\"%s\", %ld, 0x%p, %d) by \"%s\"\n", devName, unitNumber, iORequest,
92 flags, GET_THIS_TASK->tc_Node.ln_Name));
94 /* Arbitrate for the device list */
95 EXEC_LOCK_LIST_READ_AND_FORBID(&SysBase->DeviceList);
97 /* Look for the device in our list */
98 iORequest->io_Unit = NULL;
100 iORequest->io_Device = (struct Device *)FindName(&SysBase->DeviceList, devName);
102 EXEC_UNLOCK_LIST(&SysBase->DeviceList);
104 D(bug("[OpenDevice] Found resident 0x%p\n", iORequest->io_Device));
106 /* Something found ? */
107 if (iORequest->io_Device)
109 iORequest->io_Error = 0;
111 /* Call Open vector. */
112 AROS_LVO_CALL3NR(void,
113 AROS_LCA(struct IORequest *,iORequest,A1),
114 AROS_LCA(IPTR, unitNumber,D0),
115 AROS_LCA(ULONG,flags,D1),
116 struct Device *, iORequest->io_Device, 1, dev);
118 /* Check for error */
119 if (iORequest->io_Error)
120 /* Mark request as non-open */
121 iORequest->io_Device=NULL;
123 else
124 iORequest->io_Error = IOERR_OPENFAIL;
127 * We cannot handle loading devices from disk. But thankfully this is
128 * taken care of by dos.library (well lddemon really). It replaces
129 * this function with one of its own via the SetFunction() call.
132 /* All done. */
133 Permit();
135 D(bug("[OpenDevice] Returning device 0x%p, unit 0x%p, error %d\n", iORequest->io_Device, iORequest->io_Unit, iORequest->io_Error));
137 return iORequest->io_Error;
139 AROS_LIBFUNC_EXIT
140 } /* OpenDevice */