Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / exec / opendevice.c
blob58260a3577bb16dc11e6b29c8eb06b3ca8f1aa17
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Open a device.
6 Lang: english
7 */
8 #include <aros/config.h>
9 #include <exec/execbase.h>
10 #include <exec/devices.h>
11 #include <exec/io.h>
12 #include <exec/errors.h>
13 #include <aros/libcall.h>
14 #include <exec/libraries.h>
15 #include <proto/exec.h>
17 #ifndef DEBUG_SetFunction
18 # define DEBUG_SetFunction 0
19 #endif
20 #undef DEBUG
21 #if DEBUG_SetFunction
22 # define DEBUG 1
23 #endif
24 #include <aros/debug.h>
25 #undef kprintf
27 char *const timername = "timer.device";
28 char *const inputname = "input.device";
30 /*****************************************************************************
32 NAME */
34 AROS_LH4(BYTE, OpenDevice,
36 /* SYNOPSIS */
37 AROS_LHA(CONST_STRPTR, devName, A0),
38 AROS_LHA(ULONG, unitNumber, D0),
39 AROS_LHA(struct IORequest *, iORequest, A1),
40 AROS_LHA(ULONG, flags, D1),
42 /* LOCATION */
43 struct ExecBase *, SysBase, 74, Exec)
45 /* FUNCTION
46 Tries to open a device and fill the iORequest structure. An error
47 is returned if this fails, 0 if all went well.
49 If the device doesn't exist in the current system device list, then
50 first the system ROMtag module list, then if the DOS is running,
51 then the DEVS: directory will be tried.
53 INPUTS
54 devName - Pointer to the devices's name.
55 unitNumber - The unit number. Most often 0.
56 iORequest - Pointer do device specific information.
57 Will be filled out by the device.
58 Must lie in public (or at least shared) memory.
59 flags - Some flags to give to the device.
61 RESULT
62 Error code or 0 if all went well. The same value can be found
63 in the io_Error field.
65 NOTES
67 EXAMPLE
69 BUGS
71 SEE ALSO
72 OpenDevice()
74 INTERNALS
76 *****************************************************************************/
78 AROS_LIBFUNC_INIT
80 struct Device *device;
81 BYTE ret=IOERR_OPENFAIL;
83 D(bug("OpenDevice $%lx $%lx $%lx %ld (\"%s\") by \"%s\"\n", devName, unitNumber, iORequest,
84 flags, (devName > (STRPTR)1) ? devName : (UBYTE *)"(null)", SysBase->ThisTask->tc_Node.ln_Name));
86 /* Arbitrate for the device list */
87 Forbid();
90 Kludge for compatibility with V40 kickstart. DO NOT depend on this!
91 See TaggedOpenLibrary() for more info.
93 if (devName == (STRPTR)0) devName = timername;
94 else if(devName == (STRPTR)1) devName = inputname;
96 /* Look for the device in our list */
97 device=(struct Device *)FindName(&SysBase->DeviceList,devName);
99 /* Something found ? */
100 if(device!=NULL)
102 /* Init iorequest */
103 iORequest->io_Error=0;
104 iORequest->io_Device=device;
105 iORequest->io_Unit = NULL;
107 /* Call Open vector. */
108 AROS_LVO_CALL3NR(void,
109 AROS_LCA(struct IORequest *,iORequest,A1),
110 AROS_LCA(ULONG,unitNumber,D0),
111 AROS_LCA(ULONG,flags,D1),
112 struct Device *, device, 1, dev
115 /* Check for error */
116 ret=iORequest->io_Error;
117 if(ret)
118 /* Mark request as non-open */
119 iORequest->io_Device=NULL;
123 * We cannot handle loading devices from disk. But thankfully this is
124 * taken care of by dos.library (well lddemon really). It replaces
125 * this function with one of its own via the SetFunction() call.
128 /* All done. */
129 Permit();
130 return ret;
131 AROS_LIBFUNC_EXIT
132 } /* OpenDevice */