File: pnp-access.c

package info (click to toggle)
isapnptools 1.21-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 736 kB
  • ctags: 360
  • sloc: ansic: 4,381; yacc: 1,383; perl: 123; makefile: 114; sh: 89
file content (173 lines) | stat: -rw-r--r-- 6,109 bytes parent folder | download
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*****************************************************************************
**
** pnp-access.c
*/
static char st_pnp_access_version[] __attribute__((unused)) = "$Id: pnp-access.c,v 0.0 1999/12/02 22:28:02 fox Exp $";
/*
**
** Contains the interrogate_isapnp() procedure, which encapsulates
** everything having to do with creation of the ISA PnP resources
** list.
**
** Copyright (C) P.J.H.Fox (fox@roestock.demon.co.uk)
** Modifications by Omer Zak (omerz@actcom.co.il)
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Library General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
** Library General Public License for more details.
**
** You should have received a copy of the GNU Library General Public
** License along with this library; if not, write to the 
** Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
** Boston, MA  02111-1307  USA.
**
******************************************************************************
**
** Bug reports and fixes - to  P.J.H.Fox (fox@roestock.demon.co.uk)
** Note:  by sending unsolicited commercial/political/religious
**        E-mail messages (known also as "spam") to any E-mail address
**        mentioned in this file, you irrevocably agree to pay the
**        receipient US$500.- (plus any legal expenses incurred while
**        trying to collect the amount due) per unsolicited
**        commercial/political/religious E-mail message - for
**        the service of receiving your E-mail message.
**
*****************************************************************************/

#include <stdio.h>            /* only for NULL declaration */
#include <setjmp.h>
#include "release.h"
#include "callbacks.h"
#include "pnp-access.h"
#include "iopl.h"
#include "res-access.h"
#ifdef REALTIME
#include "realtime.h"
#endif
#include "errenum.h"

/****************************************************************************/
/* Fatal error callback - is not visible to the user */
fatal_error     pnpdump_fatal_error_callback;

jmp_buf st_fatal_error_jmp_buf;  /* Used to handle fatal errors */
int st_fatal_isapnp_error_code;  /* set by the callback for
				 ** interrogate_isapnp()
				 */

void
pnpdump_fatal_error_callback(int in_isapnp_error)
{
  longjmp(st_fatal_error_jmp_buf,st_fatal_isapnp_error_code);

  /*
!!!!!!!! PREVIOUS CODE - MOVE TO DEMO2 !!!!!!!!!!!!
  if (in_isapnp_error >= ISAPNP_E_LAST_ERROR_CODE) {
    fprintf(stderr, "Unknown fatal error - error code is %d.\n",
	    in_isapnp_error);
  }
  else {
    fprintf(stderr,"%s\n",st_error_messages[in_isapnp_error]);
  }
  exit(1);
!!!!!!!!!!!!! End of previous code !!!!!!!!!
  */
}

/*****************************************************************************
** Interrogate the ISA PnP cards and optionally allocate resources.
** The arguments are:
** in_args_p - points at a structure containing all input arguments and
**             settings of the command line flags (if any).
** out_results_p - points at a structure containing all results.
**
** The return value of the procedure is 0 for normal return.  In this
** case, *out_results_p contains valid results.
** If anything was wrong, a nonzero value is returned.
*/

int
interrogate_isapnp(const interrogate_args *in_args_p,
		   interrogate_results *out_results_p)
{
  int l_card_index;
  int l_ret;

  /**************************************************************************/
  /* First thing to do - initialize callbacks */
  l_ret = setjmp(st_fatal_error_jmp_buf);
  if (l_ret != 0) {
    /* Returned here from a longjmp() call */
    return(st_fatal_isapnp_error_code);
  }
  callbacks_init(pnpdump_fatal_error_callback,
		 in_args_p->m_non_fatal_error_callback_p,
		 in_args_p->m_progress_report_callback_p);

  /**************************************************************************/

  if (acquire_pnp_io_privileges() != 0) {
    return(ISAPNP_E_PNPACC_NO_PERMISSION);
  }

  /**************************************************************************/

  /* Have to do this anyway to check readport for clashes */
  alloc_system_resources();
#ifdef REALTIME
  setroundrobin(in_args_p->m_realtime_timeout);
#endif /* REALTIME */

  /**************************************************************************/

  /* Now get board info */
  /* It is to be noted that the following code is kludge, and it should be
  ** cleaned up in a future version of the libisapnp library.
  */
  /* Arguments for initiate() */
  do_fullreset = in_args_p->m_reset_flag;
  do_ignorecsum = in_args_p->m_ignore_csum_flag;
  debug_isolate = in_args_p->m_debug_flag;
  boards_found = (in_args_p->m_numcards >= 0) ? in_args_p->m_numcards : 0;
  read_port = (in_args_p->m_readport >= 0) ? in_args_p->m_readport : 0;
  initiate();

  /* Retrieve actual No. of boards found and actual read_port used. */
  out_results_p->m_numcards_found = boards_found;
  out_results_p->m_readport_found = read_port;

  /* Actually retrieve board information */
  out_results_p->m_resource_p = NULL;
  out_results_p->m_resource_count = 0;
  for (l_card_index = 1;
       l_card_index <= out_results_p->m_numcards_found;
       l_card_index++) {
    read_board(l_card_index,
	       &out_results_p->m_resource_p,
	       &out_results_p->m_resource_count);
    /* Here one could call dumpregs() (or equivalent) if one wants
    ** the detailed information from the card's registers.
    */
  }

  /* Finished getting board information. */
#ifdef REALTIME
  /* No longer need real-time scheduling */
  normal_sched();
#endif /* REALTIME */
  /* Release resources */
  if (relinquish_pnp_io_privileges() != 0) {
    return(ISAPNP_E_PNPACC_NO_PERMS_RELEASE);
  }

  return(0);
}

/****************************************************************************/
/* End of pnp-access.c */