mbgtools-lx  4.2.8
mbggenio.h
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: mbggenio.h 1.9 2018/11/22 14:52:53 martin TRASH $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Definitions for generic port I/O.
10  *
11  * -----------------------------------------------------------------------
12  * $Log: mbggenio.h $
13  * Revision 1.9 2018/11/22 14:52:53 martin
14  * Moved definition of FAR here.
15  * Fixed build for QNX and MBG_TGT_NO_TGT.
16  * Don't use __iomem attribute with very old Linux kernels.
17  * Moved DEBUG_RSRC stuff to pcpsdrvr.c.
18  * Revision 1.8 2018/07/05 09:08:48 martin
19  * Moved some I/O related definitions here.
20  * Renamed I/O macros and distinguish between macros
21  * that convert endianess, and macros that don't.
22  * Use system functions to implement our own memory mapped
23  * I/O macros since those usually include barriers.
24  * Revision 1.7 2017/08/10 13:53:37 martin
25  * Unified extended resource properties handling.
26  * Revision 1.6 2012/10/02 18:43:36 martin
27  * Fixed includes for NetBSD.
28  * Specify I/O range number when calling port I/O macros
29  * so they can be used for different ranges under BSD.
30  * Account for modified resource handling under *BSD.
31  * Revision 1.5 2008/12/05 13:27:33 martin
32  * Generally put macro arguments in brackets for evaluation
33  * to avoid potential side effects.
34  * There has been a problem with an improper written outp() macro
35  * in the Borland C 3.1 library's conio.h file.
36  * Support mapped I/O resources.
37  * Revision 1.4 2008/02/05 13:38:57 martin
38  * Added support for QNX.
39  * Revision 1.3 2007/03/21 14:48:56 martin
40  * Use standard inp(), outp() also under Windows since the generic
41  * Windows functions READ_PORT_UCHA(), etc., are not very
42  * compatible across DDK versions.
43  * Revision 1.2 2007/03/02 10:23:34Z martin
44  * Renamed generic port I/O macros.
45  * Fully support Linux, *BSD, Windows, NetWare, DOS, and OS/2.
46  * Revision 1.1 2006/09/20 10:47:21 martin
47  *
48  **************************************************************************/
49 
50 #ifndef _MBGGENIO_H
51 #define _MBGGENIO_H
52 
53 
54 /* Other headers to be included */
55 
56 #include <mbg_arch.h>
57 #include <mbgddmsg.h>
58 
59 #if defined( MBG_TGT_BSD )
60 
61  #include <sys/param.h>
62  #include <sys/types.h>
63  #include <sys/bus.h>
64 
65  #if !defined(__NetBSD_Version__) || __NetBSD_Version__ < 599005500
66  #include <machine/bus.h>
67  #endif
68 
69 #endif
70 
71 
72 #if defined( MBG_TGT_DOS )
73 
74  #include <conio.h>
75  #include <xportio.h>
76 
77 #endif
78 
79 
80 #if defined( MBG_TGT_QNX )
81 
82  #if defined( MBG_TGT_QNX_NTO ) // compiling for QNX Neutrino
83 
84  // Don't know if we have to distinguish between different compilers.
85  #include <hw/inout.h>
86 
87  #else // compiling for QNX4
88 
89  #if defined( __WATCOMC__ ) // using Watcom C
90 
91  // Include prototypes of port I/O functions
92  // which should match the calls used in the mbglib functions.
93  #include <conio.h>
94  #endif
95 
96  #endif
97 
98 #endif
99 
100 
101 #if defined( MBG_TGT_NETWARE )
102 
103  #include <conio.h>
104 
105 #endif
106 
107 
108 #if defined( MBG_TGT_OS2 )
109 
110  #include <conio.h>
111  #include <xportio.h>
112 
113 #endif
114 
115 
116 
117 /* Start of header body */
118 
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
122 
123 
124 #if !defined( MBG_USE_MM_IO_FOR_PCI )
125  #define MBG_USE_MM_IO_FOR_PCI 0
126 #endif
127 
128 
129 #if defined( MBG_TGT_DOS )
130  #define FAR far
131 #else
132  #define FAR
133 #endif
134 
135 
136 // These definitions are used to provide a consistent
137 // resource handling across different platforms.
138 // This is kept completely inside the kernel drivers, so the
139 // structures can be modified safely, as appropriate.
140 
141 #if MBG_USE_MM_IO_FOR_PCI
142  #if !defined( MBG_TGT_LINUX )
143  #error Not supported for target environment.
144  #endif
145 #endif
146 
147 
148 
149 #if defined( MBG_TGT_WIN32 )
150 
151  #define _MBG_IOMEM
152 
154  typedef void _MBG_IOMEM *MBG_IOMEM_ADDR_MAPPED;
155 
158 
159  #define _mbg_ioremap( _base, _num ) ( _base )
160  #define _mbg_iounmap( _base, _num ) _nop_macro_fnc()
161 
162 #elif defined( MBG_TGT_LINUX )
163 
164  #if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 10 ) )
165  #define _MBG_IOMEM volatile __iomem
166  #else
167  // Older kernels don't know "__iomem". We could at least
168  // use the "volatile" attribute, but some kernel API functions
169  // which expect such an address as parameter even expect a
170  // pointer that is not "volatile", so we don't use that either
171  // for such old kernels.
172  #define _MBG_IOMEM
173  #endif
174 
177 
178  #if MBG_USE_MM_IO_FOR_PCI
179  typedef MBG_IOMEM_ADDR_RAW MBG_IOPORT_ADDR_RAW;
180  typedef MBG_IOMEM_ADDR_MAPPED MBG_IOPORT_ADDR_MAPPED;
181 
182  #define _mbg_ioremap( _base, _num ) ioremap_nocache( (_base), (_num) )
183  #define _mbg_iounmap( _base, _num ) iounmap( (_base) )
184 
185  #else
188 
189  #define _mbg_ioremap( _base, _num ) ( _base )
190  #define _mbg_iounmap( _base, _num ) _nop_macro_fnc()
191 
192  #endif
193 
194 #elif defined( MBG_TGT_BSD )
195 
196  #define _MBG_IOMEM volatile
197 
198  #if defined( MBG_TGT_NETBSD ) && !defined( __LP64__ )
199  #define MBG_IOMEM_ADDR_RAW uint32_t
200  #else
201  #define MBG_IOMEM_ADDR_RAW uint64_t
202  #endif
203 
204  typedef void _MBG_IOMEM *MBG_IOMEM_ADDR_MAPPED;
205 
206  typedef ulong MBG_IOPORT_ADDR_RAW;
208 
209  // TODO Check if this is true:
210  // Under *BSD we use only the offset. The base address
211  // is determined by a handle.
212  #define _mbg_ioremap( _base, _num ) 0
213  #define _mbg_iounmap( _base, _num ) _nop_macro_fnc()
214 
215 #elif defined( MBG_TGT_NO_TGT )
216 
217  // Nothing to do here.
218 
219 #else // QNX, DOS, ...
220 
221  #define _MBG_IOMEM volatile FAR
222 
223  typedef uint32_t MBG_IOMEM_ADDR_RAW;
224  typedef void _MBG_IOMEM *MBG_IOMEM_ADDR_MAPPED;
225 
228 
229  #define _mbg_ioremap( _base, _num ) ( _base )
230  #define _mbg_iounmap( _base, _num ) _nop_macro_fnc()
231 
232 #endif
233 
234 
235 
236 #if defined( MBG_TGT_FREEBSD )
237 
238 typedef struct
239 {
240  int rid;
241  struct resource *res;
242  bus_space_tag_t bst;
243  bus_space_handle_t bsh;
244 
245 } EXT_RSRC_INFO;
246 #define EXT_RSRC_INFO EXT_RSRC_INFO
247 
248 #elif defined( MBG_TGT_NETBSD )
249 
250 typedef struct
251 {
252  int reg;
253  int type;
254  int valid;
255  bus_space_tag_t bst;
256  bus_space_handle_t bsh;
257  bus_addr_t base;
258  bus_size_t size;
259 
260 } EXT_RSRC_INFO;
261 #define EXT_RSRC_INFO EXT_RSRC_INFO
262 
263 #endif
264 
265 
266 
273 typedef struct
274 {
275  #if defined( EXT_RSRC_INFO )
276  EXT_RSRC_INFO ext;
277  #endif
278  MBG_IOMEM_ADDR_RAW start_raw;
279  MBG_IOMEM_ADDR_MAPPED start_mapped;
281 
283 
284 
285 
292 typedef struct
293 {
294  #if defined( EXT_RSRC_INFO )
295  EXT_RSRC_INFO ext;
296  #endif
297  MBG_IOPORT_ADDR_RAW base_raw;
298  MBG_IOPORT_ADDR_MAPPED base_mapped;
300 
302 
303 
304 
311 typedef struct
312 {
313  #if defined( EXT_RSRC_INFO )
314  EXT_RSRC_INFO ext;
315  #endif
317 
318 } MBG_IRQ_RSRC;
319 
320 
321 
329 static __mbg_inline
331 {
332  #if MBG_TGT_HAS_64BIT_TYPES
333  if ( p->start_mapped )
334  {
335  // This should never happen. Either the resource has already
336  // been mapped, or the structure is uninitialized.
337  _mbg_kdd_msg_2( MBG_LOG_WARN, "WARNING: mem rsrc %" PRIX64 " already mapped to %p",
338  (uint64_t) p->start_raw, p->start_mapped );
339  }
340  #endif
341 
342  #if defined( MBG_TGT_WIN32 )
343  {
344  PHYSICAL_ADDRESS phys_addr;
345 
346  phys_addr.QuadPart = p->start_raw;
347 
348  // NTKERNELAPI PVOID MmMapIoSpace( PHYSICAL_ADDRESS PhysicalAddress,
349  // SIZE_T NumberOfBytes,
350  // MEMORY_CACHING_TYPE CacheType );
351  p->start_mapped = MmMapIoSpace( phys_addr, p->len, MmNonCached );
352  }
353  #elif defined( MBG_TGT_LINUX )
354 
355  // void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size);
356  p->start_mapped = ioremap_nocache( p->start_raw, p->len );
357 
358  // TODO Or, if the kernel supports this, use
359  // void *memremap(resource_size_t offset, size_t size, unsigned long flags);
360 
361  #elif defined( MBG_TGT_FREEBSD )
362 
363  // void *rman_get_virtual(struct resource *r);
364  p->start_mapped = rman_get_virtual( &p->ext.res );
365 
366  #elif defined( MBG_TGT_NETBSD )
367 
368  // void *bus_space_vaddr(bus_space_tag_t space, bus_space_handle_t handle);
369  p->start_mapped = bus_space_vaddr( &p->ext.bst, &p->ext.bsh );
370 
371  #elif defined( MBG_TGT_NO_TGT )
372 
373  _mbg_map_iomem_rsrc_no_tgt( p );
374 
375  #else // DOS, ...
376 
377  // same as the physical address
379 
380  #endif // target specific code
381 
382  if ( p->start_mapped == NULL ) // error ...
383  return MBG_ERR_NO_MEM;
384 
385  return MBG_SUCCESS;
386 
387 } // mbg_map_iomem_rsrc
388 
389 
390 
396 static __mbg_inline
398 {
399  if ( p->start_mapped )
400  {
401  #if defined( MBG_TGT_WIN32 )
402  MmUnmapIoSpace( p->start_mapped, p->len );
403  #elif defined( MBG_TGT_LINUX )
404  iounmap( p->start_mapped );
405  #elif defined( MBG_TGT_FREEBSD )
406  #if !defined( DEBUG )
407  #warning Need to implement unmapping
408  #endif
409  #elif defined( MBG_TGT_NETBSD )
410  #if !defined( DEBUG )
411  #warning Need to implement unmapping
412  #endif
413  #elif defined( MBG_TGT_QNX )
414 
415  #if defined( MBG_TGT_QNX_NTO ) // compiling for QNX Neutrino
416  // FIXME TODO Call mmap_device_io() ?
417  #endif
418 
419  #else // DOS, ...
420  // nothing to do
421  #endif // target specific code
422 
423  p->start_mapped = NULL;
424  }
425 
426 } // mbg_unmap_iomem_rsrc
427 
428 
429 
437 static __mbg_inline
439 {
440  #if MBG_TGT_HAS_64BIT_TYPES
441  if ( p->base_mapped )
442  {
443  // This should never happen. Either the resource has already
444  // been mapped, or the structure is uninitialized.
445  _mbg_kdd_msg_2( MBG_LOG_WARN, "WARNING: I/O port rsrc %" PRIX64 " already mapped to %" PRIX64,
446  (uint64_t) p->base_raw, (uint64_t) p->base_mapped );
447  }
448  #endif
449 
450  p->base_mapped = _mbg_ioremap( p->base_raw, p->num );
451 
452  return MBG_SUCCESS;
453 
454 } // mbg_map_ioport_rsrc
455 
456 
457 
463 static __mbg_inline
465 {
466  if ( p->base_mapped )
467  {
468  _mbg_iounmap( p->base_raw, p->num );
470  }
471 
472 } // mbg_unmap_ioport_rsrc
473 
474 
475 
476 // The I/O memory write barrier should be used whenever a write
477 // access to the device occurs without a subsequent read, immediately
478 // before a spinlock is released.
479 #if defined( MBG_TGT_LINUX )
480  #define _mbg_mmiowb() _mmiowb()
481 #else
482  #define _mbg_mmiowb() _nop_macro_fnc()
483 #endif
484 
485 #if !defined( _mbg_rmb )
486  #define _mbg_rmb() _nop_macro_fnc()
487 #endif
488 
489 #if !defined( _mbg_wmb )
490  #define _mbg_wmb() _nop_macro_fnc()
491 #endif
492 
493 
494 
495 // Direct access to an I/O memory location, which may suffer from execution
496 // being reordered by the CPU, unless barriers are explicitly inserted.
497 // If _mbg_rmb() and _mbg_wmb() may have been defined as empty functions.
498 
499 static __mbg_inline
501 {
502  uint8_t val = *p;
503  _mbg_rmb();
504  return val;
505 
506 } // mbg_mmrd8_native
507 
508 
509 
510 static __mbg_inline
512 {
513  uint16_t val = *p;
514  _mbg_rmb();
515  return val;
516 
517 } // mbg_mmrd16_native
518 
519 
520 static __mbg_inline
521 uint32_t mbg_mmrd32_native( uint32_t _MBG_IOMEM *p )
522 {
523  uint32_t val = *p;
524  _mbg_rmb();
525  return val;
526 
527 } // mbg_mmrd32_native
528 
529 
530 static __mbg_inline
532 {
533  *p = val;
534  _mbg_wmb();
535 
536 } // mbg_mmrd8
537 
538 
539 static __mbg_inline
541 {
542  *p = val;
543  _mbg_wmb();
544 
545 } // mbg_mmrd16_native
546 
547 
548 static __mbg_inline
549 void mbg_wrmm32_native( uint32_t val, uint32_t _MBG_IOMEM *p )
550 {
551  *p = val;
552  _mbg_wmb();
553 
554 } // mbg_mmrd32_native
555 
556 
557 
558 #if defined( MBG_TGT_LINUX )
559 
560  // readX() / writeX() functions include barriers, and the 16 bit
561  // and 32 bit versions also convert the endianess to CPU endianess.
562 
563  // Since the OS functions already convert to CPU endianess
564  // we need to convert back if we need native endianess.
565  // This may result in a a little degradation of the performance
566  // on big endian targets. However, little endian targets are not
567  // affected since no conversion is required at all.
568  // TODO We might try to use memcpy_fromio() or something on bigendian
569  // targets to prevent endian conversion. However, this may be even
570  // slower since this may always do byte-wise access.
571 
572  #define _mbg_mmrd8( _iomem_addr ) readb( (_iomem_addr) )
573  #define _mbg_mmrd16_native( _iomem_addr ) _cpu_to_mbg16( readw( (_iomem_addr) ) )
574  #define _mbg_mmrd32_native( _iomem_addr ) _cpu_to_mbg32( readl( (_iomem_addr) ) )
575  #define _mbg_mmrd16_to_cpu( _iomem_addr ) readw( (_iomem_addr) )
576  #define _mbg_mmrd32_to_cpu( _iomem_addr ) readl( (_iomem_addr) )
577 
578  #define _mbg_mmwr8( _iomem_addr, _val ) writeb( (_val), (_iomem_addr) )
579  #define _mbg_mmwr16_native( _iomem_addr, _val ) writew( _mbg_to_cpu16( (_val) ), (_iomem_addr) )
580  #define _mbg_mmwr32_native( _iomem_addr, _val ) writel( _mbg_to_cpu32( (_val) ), (_iomem_addr) )
581  #define _mbg_mmwr16_to_mbg( _iomem_addr, _val ) writew( (_val), (_iomem_addr) )
582  #define _mbg_mmwr32_to_mbg( _iomem_addr, _val ) writel( (_val), (_iomem_addr) )
583 
584 
585  // TODO implement associated _mbg_mmwrX_offs(), _mbg_inpX_offs(),
586  // and _mbg_outpX_offs() macros.
587  #define _mbg_mmrd8_offs( _dev, _rsrc_idx, _iomem_offs ) \
588  _mbg_mmrd8( (uint8_t _MBG_IOMEM *) (_dev)->mm_asic_addr + (_iomem_offs) )
589 
590  #define _mbg_mmrd32_to_cpu_offs( _dev, _rsrc_idx, _iomem_offs ) \
591  _mbg_mmrd32_to_cpu( (uint8_t _MBG_IOMEM *) (_dev)->mm_addr_asic + (_iomem_offs) )
592 
593 
594  #if 0 // TODO
595  // The macros below expect additional parameters. Eventually,
596  // something like this is required for *BSD.
597 
598  #define _mbg_mmrd8_x( _dev, _rsrc_idx, _iomem_addr ) _mbg_mmrd8( (_iomem_addr) )
599  #define _mbg_mmrd16_to_cpu_x( _dev, _rsrc_idx, _iomem_addr ) _mbg_mmrd16_to_cpu( (_iomem_addr) )
600  #define _mbg_mmrd32_to_cpu_x( _dev, _rsrc_idx, _iomem_addr ) _mbg_mmrd32_to_cpu( (_iomem_addr) )
601 
602  #define _mbg_mmwr8_to_mbg_x( _dev, _rsrc_idx, _iomem_addr, _val ) _mbg_mmwr8_to_mbg( (_val), (_iomem_addr) )
603  #define _mbg_mmwr16_to_mbg_x( _dev, _rsrc_idx, _iomem_addr, _val ) _mbg_mmwr16_to_mbg( (_val), (_iomem_addr) )
604  #define _mbg_mmwr32_to_mbg_x( _dev, _rsrc_idx, _iomem_addr, _val ) _mbg_mmwr32_to_mbg( (_val), (_iomem_addr) )
605  #endif
606 
607  #if !MBG_USE_MM_IO_FOR_PCI
608  // Use Linux functions to access the legacy I/O ports
609 
610  #define _mbg_inp8( _dev, _rsrc_idx, _port_addr ) ( (uint8_t) inb( (_port_addr) ) )
611  #define _mbg_inp16_native( _dev, _rsrc_idx, _port_addr ) _cpu_to_mbg16( inw( (_port_addr) ) )
612  #define _mbg_inp32_native( _dev, _rsrc_idx, _port_addr ) _cpu_to_mbg32( inl( (_port_addr) ) )
613  #define _mbg_inp16_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) inw( (_port_addr) ) )
614  #define _mbg_inp32_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) inl( (_port_addr) ) )
615 
616  #define _mbg_outp8( _dev, _rsrc_idx, _port_addr, _val ) outb( (_val), (_port_addr) )
617  #define _mbg_outp16_native( _dev, _rsrc_idx, _port_addr, _val ) outw( _mbg_to_cpu16( (_val) ), (_port_addr) )
618  #define _mbg_outp32_native( _dev, _rsrc_idx, _port_addr, _val ) outl( _mbg_to_cpu32( (_val) ), (_port_addr) )
619  #define _mbg_outp16_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) outw( (_val), (_port_addr) )
620  #define _mbg_outp32_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) outl( (_val), (_port_addr) )
621 
622  #endif
623 
624 #elif defined( MBG_TGT_BSD )
625 
626  #define _mbg_inp8( _dev, _rsrc_idx, _port_addr ) ( (uint8_t) bus_space_read_1( ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bst ), \
627  ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bsh ), (_port_addr) ) )
628  #define _mbg_inp16( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) bus_space_read_2( ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bst ), \
629  ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bsh ), (_port_addr) ) )
630  #define _mbg_inp32( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) bus_space_read_4( ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bst), \
631  ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bsh ), (_port_addr) ) )
632 
633  #define _mbg_outp8( _dev, _rsrc_idx, _port_addr, _val ) bus_space_write_1( ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bst ), \
634  ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bsh ), (_port_addr), (_val) )
635  #define _mbg_outp16( _dev, _rsrc_idx, _port_addr, _val ) bus_space_write_2( ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bst ), \
636  ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bsh ), (_port_addr), (_val) )
637  #define _mbg_outp32( _dev, _rsrc_idx, _port_addr, _val ) bus_space_write_4( ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bst ), \
638  ( (_dev)->rsrc_info.port[_rsrc_idx].ext.bsh ), (_port_addr), (_val) )
639 
640 #elif defined( MBG_TGT_WIN32 )
641 
642  // Only X86 / X86_64 supported, so we don't care about endianess conversion.
643 
644  #if 1
645  // Use READ_REGISTER_UCHAR(), WRITE_REGISTER_UCHAR() and friends ...
646 
647  #define _mbg_mmrd8( _iomem_addr ) READ_REGISTER_UCHAR( (_iomem_addr) )
648  #define _mbg_mmrd16_native( _iomem_addr ) READ_REGISTER_USHORT( (_iomem_addr) )
649  #define _mbg_mmrd32_native( _iomem_addr ) READ_REGISTER_ULONG( (_iomem_addr) )
650  #define _mbg_mmrd16_to_cpu( _iomem_addr ) READ_REGISTER_USHORT( (_iomem_addr) )
651  #define _mbg_mmrd32_to_cpu( _iomem_addr ) READ_REGISTER_ULONG( (_iomem_addr) )
652 
653  #define _mbg_mmwr8( _iomem_addr, _val ) WRITE_REGISTER_UCHAR( (_iomem_addr), (_val) )
654  #define _mbg_mmwr16_native( _iomem_addr, _val ) WRITE_REGISTER_USHORT( (_iomem_addr), (_val) )
655  #define _mbg_mmwr32_native( _iomem_addr, _val ) WRITE_REGISTER_ULONG( (_iomem_addr), (_val) )
656  #define _mbg_mmwr16_to_mbg( _iomem_addr, _val ) WRITE_REGISTER_USHORT( (_iomem_addr), (_val) )
657  #define _mbg_mmwr32_to_mbg( _iomem_addr, _val ) WRITE_REGISTER_ULONG( (_iomem_addr), (_val) )
658 
659  #endif
660 
661  // TODO implement associated _mbg_mmwrX_offs(), _mbg_inpX_offs(),
662  // and _mbg_outpX_offs() macros.
663  #define _mbg_mmrd8_offs( _dev, _rsrc_idx, _iomem_offs ) \
664  _mbg_mmrd8( (uint8_t _MBG_IOMEM *) (_dev)->mm_asic_addr + (_iomem_offs) )
665 
666  #if 0
667  // Use READ_PORT_UCHAR(), WRITE_PORT_UCHAR() and friends ...
668 
669  #define _mbg_inp8( _dev, _rsrc_idx, _port_addr ) READ_PORT_UCHAR( (_port_addr) )
670  #define _mbg_inp16_native( _dev, _rsrc_idx, _port_addr ) READ_PORT_USHORT( (_port_addr) )
671  #define _mbg_inp32_native( _dev, _rsrc_idx, _port_addr ) READ_PORT_ULONG( (_port_addr) )
672  #define _mbg_inp16_to_cpu( _dev, _rsrc_idx, _port_addr ) READ_PORT_USHORT( (_port_addr) )
673  #define _mbg_inp32_to_cpu( _dev, _rsrc_idx, _port_addr ) READ_PORT_ULONG( (_port_addr) )
674 
675  #define _mbg_outp8( _dev, _rsrc_idx, _port_addr, _val ) WRITE_PORT_UCHAR( (_port_addr), (_val) )
676  #define _mbg_outp16_native( _dev, _rsrc_idx, _port_addr, _val ) WRITE_PORT_USHORT( (_port_addr), (_val) )
677  #define _mbg_outp32_native( _dev, _rsrc_idx, _port_addr, _val ) WRITE_PORT_ULONG( (_port_addr), (_val) )
678  #define _mbg_outp16_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) WRITE_PORT_USHORT( (_port_addr), (_val) )
679  #define _mbg_outp32_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) WRITE_PORT_ULONG( (_port_addr), (_val) )
680 
681  #else
682  // Use inp() / outp() and friends.
683 
684  #define _mbg_inp8( _dev, _rsrc_idx, _port_addr ) ( (uint8_t) inp( (_port_addr) ) )
685  #define _mbg_inp16_native( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) inpw( (_port_addr) ) )
686  #define _mbg_inp32_native( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) inpd( (_port_addr) ) )
687  #define _mbg_inp16_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) inpw( (_port_addr) ) )
688  #define _mbg_inp32_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) inpd( (_port_addr) ) )
689 
690  #define _mbg_outp8( _dev, _rsrc_idx, _port_addr, _val ) outp( (_port_addr), (_val) )
691  #define _mbg_outp16_native( _dev, _rsrc_idx, _port_addr, _val ) outpw( (_port_addr), (_val) )
692  #define _mbg_outp32_native( _dev, _rsrc_idx, _port_addr, _val ) outpd( (_port_addr), (_val) )
693  #define _mbg_outp16_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) outpw( (_port_addr), (_val) )
694  #define _mbg_outp32_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) outpd( (_port_addr), (_val) )
695 
696  #endif
697 
698 #elif defined( MBG_TGT_DOS ) || defined( MBG_TGT_NETWARE ) || defined( MBG_TGT_OS2 )
699 
700  // Only X86 / X86_64 supported, so we don't care about endianess conversion.
701 
702  #define _mbg_inp8( _dev, _rsrc_idx, _port_addr ) ( (uint8_t) inp( (_port_addr) ) )
703  #define _mbg_inp16_native( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) inpw( (_port_addr) ) )
704  #define _mbg_inp32_native( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) inpd( (_port_addr) ) )
705  #define _mbg_inp16_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) inpw( (_port_addr) ) )
706  #define _mbg_inp32_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) inpd( (_port_addr) ) )
707 
708  #define _mbg_outp8( _dev, _rsrc_idx, _port_addr, _val ) outp( (_port_addr), (_val) )
709  #define _mbg_outp16_native( _dev, _rsrc_idx, _port_addr, _val ) outpw( (_port_addr), (_val) )
710  #define _mbg_outp32_native( _dev, _rsrc_idx, _port_addr, _val ) outpd( (_port_addr), (_val) )
711  #define _mbg_outp16_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) outpw( (_port_addr), (_val) )
712  #define _mbg_outp32_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) outpd( (_port_addr), (_val) )
713 
714 #elif defined( MBG_TGT_QNX )
715 
716  // Only X86 / X86_64 supported, so we don't care about endianess conversion.
717 
718  #if defined( MBG_TGT_QNX_NTO ) // compiling for QNX Neutrino
719 
720  // ATTENTION: mmap_device_io() must be called on non-x86 architectures
721  // to remap the ports, otherwise a segmentation fault will occur if
722  // the port I/O functions are being called.
723  // FIXME This should be done in the probe routine.
724 
725  #define _mbg_inp8( _dev, _rsrc_idx, _port_addr ) ( (uint8_t) in8( (_port_addr) ) )
726  #define _mbg_inp16_native( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) in16( (_port_addr) ) )
727  #define _mbg_inp32_native( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) in32( (_port_addr) ) )
728  #define _mbg_inp16_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) in16( (_port_addr) ) )
729  #define _mbg_inp32_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) in32( (_port_addr) ) )
730 
731  #define _mbg_outp8( _dev, _rsrc_idx, _port_addr, _val ) out8( (_port_addr), (_val) )
732  #define _mbg_outp16_native( _dev, _rsrc_idx, _port_addr, _val ) out16( (_port_addr), (_val) )
733  #define _mbg_outp32_native( _dev, _rsrc_idx, _port_addr, _val ) out32( (_port_addr), (_val) )
734  #define _mbg_outp16_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) out16( (_port_addr), (_val) )
735  #define _mbg_outp32_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) out32( (_port_addr), (_val) )
736 
737  #else // compiling for QNX 4
738 
739  #if defined( __WATCOMC__ ) // using Watcom C
740 
741  #define _mbg_inp8( _dev, _rsrc_idx, _port_addr ) ( (uint8_t) inp( (_port_addr) ) )
742  #define _mbg_inp16_native( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) inpw( (_port_addr) ) )
743  #define _mbg_inp32_native( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) inpd( (_port_addr) ) )
744  #define _mbg_inp16_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint16_t) inpw( (_port_addr) ) )
745  #define _mbg_inp32_to_cpu( _dev, _rsrc_idx, _port_addr ) ( (uint32_t) inpd( (_port_addr) ) )
746 
747  #define _mbg_outp8( _dev, _rsrc_idx, _port_addr, _val ) outp( (_port_addr), (_val) )
748  #define _mbg_outp16_native( _dev, _rsrc_idx, _port_addr, _val ) outpw( (_port_addr), (_val) )
749  #define _mbg_outp32_native( _dev, _rsrc_idx, _port_addr, _val ) outpd( (_port_addr), (_val) )
750  #define _mbg_outp16_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) outpw( (_port_addr), (_val) )
751  #define _mbg_outp32_to_mbg( _dev, _rsrc_idx, _port_addr, _val ) outpd( (_port_addr), (_val) )
752 
753  #endif
754 
755  #endif
756 
757 #endif
758 
759 
760 // If no specific memory access functions have been defined above
761 // then we use our inline functions by default.
762 
763 #if !defined( _mbg_mmrd8 )
764  #define _mbg_mmrd8( _iomem_addr ) mbg_mmrd8( (_iomem_addr) )
765 #endif
766 
767 #if !defined( _mbg_mmrd16_native )
768  #define _mbg_mmrd16_native( _iomem_addr ) mbg_mmrd16_native( (_iomem_addr) )
769 #endif
770 
771 #if !defined( _mbg_mmrd32_native )
772  #define _mbg_mmrd32_native( _iomem_addr ) mbg_mmrd32_native( (_iomem_addr) )
773 #endif
774 
775 
776 #if !defined( _mbg_mmwr8 )
777  #define _mbg_mmwr8( _iomem_addr, _val ) mbg_wrmm8( (_val), (_iomem_addr) )
778 #endif
779 
780 #if !defined( _mbg_mmwr16_native )
781  #define _mbg_mmwr16_native( _iomem_addr, _val ) mbg_wrmm16_native( (_val), (_iomem_addr) )
782 #endif
783 
784 #if !defined( _mbg_mmwr32_native )
785  #define _mbg_mmwr32_native( _iomem_addr, _val ) mbg_wrmm32_native( (_val), (_iomem_addr) )
786 #endif
787 
788 
789 #if MBG_USE_MM_IO_FOR_PCI
790  // TODO This needs to be updated, if it's to be used.
791  // On systems where legacy I/O ports are mapped to special
792  // memory ranges we also use memory access functions
793  // to access legacy I/O ports.
794 
795  #define _mbg_inp8 _mbg_mmrd8
796  #define _mbg_inp16 _mbg_mmrd16
797  #define _mbg_inp32 _mbg_mmrd32
798 
799  #define _mbg_outp8 _mbg_mmwr8
800  #define _mbg_outp16 _mbg_mmwr16
801  #define _mbg_outp32 _mbg_mmwr32
802 #endif
803 
804 
805 #ifdef __cplusplus
806 }
807 #endif
808 
809 /* End of header body */
810 
811 #endif /* _MBGGENIO_H */
static __mbg_inline uint32_t mbg_mmrd32_native(uint32_t volatile __iomem *p)
Definition: mbggenio.h:521
MBG_IOPORT_ADDR_RAW base_raw
A raw port base address.
Definition: mbggenio.h:297
ulong MBG_IOPORT_ADDR_MAPPED
Definition: mbggenio.h:187
static __mbg_inline uint8_t mbg_mmrd8_native(uint8_t volatile __iomem *p)
Definition: mbggenio.h:500
unsigned short uint16_t
Definition: words.h:213
#define _MBG_IOMEM
Definition: mbggenio.h:165
static __mbg_inline void mbg_unmap_ioport_rsrc(MBG_IOPORT_RSRC *p)
Unmap an I/O port resource to release the virtual address.
Definition: mbggenio.h:464
static __mbg_inline uint16_t mbg_mmrd16_native(uint16_t volatile __iomem *p)
Definition: mbggenio.h:511
MBG_IOMEM_ADDR_MAPPED start_mapped
A mapped I/O memory start address.
Definition: mbggenio.h:279
#define _mbg_rmb()
Definition: mbggenio.h:486
ulong num
Number of addresses in this range.
Definition: mbggenio.h:299
void volatile __iomem * MBG_IOMEM_ADDR_MAPPED
Definition: mbggenio.h:176
uint64_t MBG_IOMEM_ADDR_RAW
Definition: mbggenio.h:175
uint16_t num
The IRQ number.
Definition: mbggenio.h:316
unsigned char uint8_t
Definition: words.h:210
MBG_IOPORT_ADDR_MAPPED base_mapped
A mapped port base address.
Definition: mbggenio.h:298
IRQ resource information for a device.
Definition: mbggenio.h:311
#define MBG_ERR_NO_MEM
Failed to allocate memory.
Definition: mbgerror.h:282
#define MBG_SUCCESS
Error codes used with Meinberg devices and drivers.
Definition: mbgerror.h:259
static __mbg_inline int mbg_map_ioport_rsrc(MBG_IOPORT_RSRC *p)
Map an I/O port resource to get a virtual address.
Definition: mbggenio.h:438
I/O port resource information for a device.
Definition: mbggenio.h:292
ulong MBG_IOPORT_ADDR_RAW
Definition: mbggenio.h:186
static __mbg_inline int mbg_map_iomem_rsrc(MBG_IOMEM_RSRC *p)
Map I/O memory resource to get a virtual address.
Definition: mbggenio.h:330
#define _mbg_wmb()
Definition: mbggenio.h:490
static __mbg_inline void mbg_wrmm32_native(uint32_t val, uint32_t volatile __iomem *p)
Definition: mbggenio.h:549
static __mbg_inline void mbg_unmap_iomem_rsrc(MBG_IOMEM_RSRC *p)
Unmap an I/O memory resource to release the virtual address.
Definition: mbggenio.h:397
ulong len
Number of addresses in this range.
Definition: mbggenio.h:280
#define _mbg_ioremap(_base, _num)
Definition: mbggenio.h:189
MBG_IOMEM_ADDR_RAW start_raw
A raw I/O memory start address.
Definition: mbggenio.h:278
unsigned __int64 uint64_t
Definition: words.h:250
#define _mbg_kdd_msg_2(_lvl, _fmt, _p1, _p2)
Definition: mbgddmsg.h:239
unsigned long ulong
Definition: words.h:292
Bus memory resource information for a device.
Definition: mbggenio.h:273
static __mbg_inline void mbg_wrmm16_native(uint16_t val, uint16_t volatile __iomem *p)
Definition: mbggenio.h:540
#define _mbg_iounmap(_base, _num)
Definition: mbggenio.h:190
static __mbg_inline void mbg_wrmm8_native(uint8_t val, uint8_t volatile __iomem *p)
Definition: mbggenio.h:531