mbgtools-lx  4.2.8
rsrc_lx.c
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: rsrc_lx.c 1.9 2018/11/22 16:39:43 martin TRASH $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Interface functions for the Linux resource manager.
10  *
11  * -----------------------------------------------------------------------
12  * $Log: rsrc_lx.c $
13  * Revision 1.9 2018/11/22 16:39:43 martin
14  * Refactored debug logging stuff.
15  * Revision 1.8 2018/07/16 12:59:18 martin
16  * New functions rsrc_alloc_mem() and rsrc_dealloc_mem().
17  * rsrc_alloc_ports() doesn't expect a decode_width parameter anymore.
18  * Account for pcps_driver_name renamed to driver_name.
19  * Conditional debug code controlled by DEBUG_RSRC.
20  * Revision 1.7 2017/07/05 18:20:02 martin
21  * Use Meinberg error codes.
22  * Doxygen comments.
23  * Revision 1.6 2011/07/20 15:02:44 martin
24  * Account for modified type of symbol pcps_driver_name.
25  * Revision 1.5 2009/07/22 12:31:31 martin
26  * Cleaned up region handling across kernel versions.
27  * Revision 1.4 2008/12/05 12:02:06 martin
28  * Expect port addr as ulong.
29  * Revision 1.3 2004/11/09 14:49:56 martin
30  * Modified resource allocation code to match latest requirements.
31  * Included some macros to support calls used with older kernels.
32  * Revision 1.2 2001/03/05 16:26:59 MARTIN
33  * Removed obsolete/unused functions.
34  *
35  **************************************************************************/
36 
37 #define _RSRC_LX
38  #include <rsrc_lx.h>
39 #undef _RSRC_LX
40 
41 #include <mbgerror.h>
42 #include <mbgddmsg.h>
43 
44 #include <linux/ioport.h>
45 #include <linux/version.h>
46 
47 extern const char driver_name[];
48 
49 
50 
51 /*HDR*/
61 {
62  struct resource *p = request_region( port, n, driver_name );
63 
64  if ( p == NULL ) // error
65  {
66  _mbg_kdd_msg_2( MBG_LOG_ERR, "Failed to request I/O region %03lX (%lu)", port, n );
67  return MBG_ERR_CLAIM_RSRC;
68  }
69 
70  _mbgddmsg_3( DEBUG_RSRC, MBG_LOG_INFO, "Requested I/O region: %03lX (%lu): %p", port, n, p );
71 
72  return MBG_SUCCESS;
73 
74 } // rsrc_alloc_ports
75 
76 
77 
78 /*HDR*/
86 {
87  release_region( port, n );
88 
89  _mbgddmsg_2( DEBUG_RSRC, MBG_LOG_INFO, "Released I/O region: %03lX (%lu)", port, n );
90 
91 } // rsrc_dealloc_ports
92 
93 
94 
95 /*HDR*/
104 int rsrc_alloc_mem( ulong start, ulong len )
105 {
106  struct resource *p = request_mem_region( start, len, driver_name );
107 
108  if ( p == NULL ) // error
109  {
110  _mbg_kdd_msg_2( MBG_LOG_ERR, "Failed to request mem region %llX (%lu)",
111  (unsigned long long) start, len );
112  return MBG_ERR_CLAIM_RSRC;
113  }
114 
115  _mbgddmsg_3( DEBUG_RSRC, MBG_LOG_DEBUG, "Requested mem region: %llX (%lu): %p",
116  (unsigned long long) start, len, p );
117 
118  return MBG_SUCCESS;
119 
120 } // rsrc_alloc_mem
121 
122 
123 
124 /*HDR*/
131 void rsrc_dealloc_mem( ulong start, ulong len )
132 {
133  release_mem_region( start, len );
134 
135  _mbgddmsg_2( DEBUG_RSRC, MBG_LOG_DEBUG, "Released mem region: %llX (%lu)",
136  (unsigned long long) start, len );
137 
138 } // rsrc_dealloc_mem
139 
140 
141 
#define _mbgddmsg_3(_f, _lvl, _fmt, _p1, _p2, _p3)
Definition: mbgddmsg.h:330
void rsrc_dealloc_mem(ulong start, ulong len)
Release a memory resource range which has been allocated before.
Definition: rsrc_lx.c:131
#define DEBUG_RSRC
Definition: rsrc.h:38
int rsrc_alloc_mem(ulong start, ulong len)
Try to allocate a memory resource range.
Definition: rsrc_lx.c:104
int rsrc_alloc_ports(ulong port, ulong n)
Try to allocate an I/O port resource range.
Definition: rsrc_lx.c:60
#define MBG_SUCCESS
Error codes used with Meinberg devices and drivers.
Definition: mbgerror.h:259
#define _mbgddmsg_2(_f, _lvl, _fmt, _p1, _p2)
Definition: mbgddmsg.h:324
const char driver_name[]
#define MBG_ERR_CLAIM_RSRC
Failed to claim port or mem resource.
Definition: mbgerror.h:283
void rsrc_dealloc_ports(ulong port, ulong n)
Release an I/O port resource range which has been allocated before.
Definition: rsrc_lx.c:85
#define _mbg_kdd_msg_2(_lvl, _fmt, _p1, _p2)
Definition: mbgddmsg.h:239
unsigned long ulong
Definition: words.h:292