59 #if defined( MBG_TGT_BSD ) 61 #include <sys/param.h> 62 #include <sys/types.h> 65 #if !defined(__NetBSD_Version__) || __NetBSD_Version__ < 599005500 66 #include <machine/bus.h> 72 #if defined( MBG_TGT_DOS ) 80 #if defined( MBG_TGT_QNX ) 82 #if defined( MBG_TGT_QNX_NTO ) // compiling for QNX Neutrino 87 #else // compiling for QNX4 89 #if defined( __WATCOMC__ ) // using Watcom C 101 #if defined( MBG_TGT_NETWARE ) 108 #if defined( MBG_TGT_OS2 ) 124 #if !defined( MBG_USE_MM_IO_FOR_PCI ) 125 #define MBG_USE_MM_IO_FOR_PCI 0 129 #if defined( MBG_TGT_DOS ) 141 #if MBG_USE_MM_IO_FOR_PCI 142 #if !defined( MBG_TGT_LINUX ) 143 #error Not supported for target environment. 149 #if defined( MBG_TGT_WIN32 ) 159 #define _mbg_ioremap( _base, _num ) ( _base ) 160 #define _mbg_iounmap( _base, _num ) _nop_macro_fnc() 162 #elif defined( MBG_TGT_LINUX ) 164 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 10 ) ) 165 #define _MBG_IOMEM volatile __iomem 178 #if MBG_USE_MM_IO_FOR_PCI 182 #define _mbg_ioremap( _base, _num ) ioremap_nocache( (_base), (_num) ) 183 #define _mbg_iounmap( _base, _num ) iounmap( (_base) ) 189 #define _mbg_ioremap( _base, _num ) ( _base ) 190 #define _mbg_iounmap( _base, _num ) _nop_macro_fnc() 194 #elif defined( MBG_TGT_BSD ) 196 #define _MBG_IOMEM volatile 198 #if defined( MBG_TGT_NETBSD ) && !defined( __LP64__ ) 199 #define MBG_IOMEM_ADDR_RAW uint32_t 201 #define MBG_IOMEM_ADDR_RAW uint64_t 212 #define _mbg_ioremap( _base, _num ) 0 213 #define _mbg_iounmap( _base, _num ) _nop_macro_fnc() 215 #elif defined( MBG_TGT_NO_TGT ) 219 #else // QNX, DOS, ... 221 #define _MBG_IOMEM volatile FAR 229 #define _mbg_ioremap( _base, _num ) ( _base ) 230 #define _mbg_iounmap( _base, _num ) _nop_macro_fnc() 236 #if defined( MBG_TGT_FREEBSD ) 241 struct resource *res;
243 bus_space_handle_t bsh;
246 #define EXT_RSRC_INFO EXT_RSRC_INFO 248 #elif defined( MBG_TGT_NETBSD ) 256 bus_space_handle_t bsh;
261 #define EXT_RSRC_INFO EXT_RSRC_INFO 275 #if defined( EXT_RSRC_INFO ) 294 #if defined( EXT_RSRC_INFO ) 313 #if defined( EXT_RSRC_INFO ) 332 #if MBG_TGT_HAS_64BIT_TYPES 342 #if defined( MBG_TGT_WIN32 ) 344 PHYSICAL_ADDRESS phys_addr;
353 #elif defined( MBG_TGT_LINUX ) 361 #elif defined( MBG_TGT_FREEBSD ) 366 #elif defined( MBG_TGT_NETBSD ) 369 p->
start_mapped = bus_space_vaddr( &p->ext.bst, &p->ext.bsh );
371 #elif defined( MBG_TGT_NO_TGT ) 373 _mbg_map_iomem_rsrc_no_tgt( p );
401 #if defined( MBG_TGT_WIN32 ) 403 #elif defined( MBG_TGT_LINUX ) 405 #elif defined( MBG_TGT_FREEBSD ) 406 #if !defined( DEBUG ) 407 #warning Need to implement unmapping 409 #elif defined( MBG_TGT_NETBSD ) 410 #if !defined( DEBUG ) 411 #warning Need to implement unmapping 413 #elif defined( MBG_TGT_QNX ) 415 #if defined( MBG_TGT_QNX_NTO ) // compiling for QNX Neutrino 421 #endif // target specific code 440 #if MBG_TGT_HAS_64BIT_TYPES 479 #if defined( MBG_TGT_LINUX ) 480 #define _mbg_mmiowb() _mmiowb() 482 #define _mbg_mmiowb() _nop_macro_fnc() 485 #if !defined( _mbg_rmb ) 486 #define _mbg_rmb() _nop_macro_fnc() 489 #if !defined( _mbg_wmb ) 490 #define _mbg_wmb() _nop_macro_fnc() 558 #if defined( MBG_TGT_LINUX ) 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) ) 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) ) 587 #define _mbg_mmrd8_offs( _dev, _rsrc_idx, _iomem_offs ) \ 588 _mbg_mmrd8( (uint8_t _MBG_IOMEM *) (_dev)->mm_asic_addr + (_iomem_offs) ) 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) ) 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) ) 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) ) 607 #if !MBG_USE_MM_IO_FOR_PCI 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) ) ) 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) ) 624 #elif defined( MBG_TGT_BSD ) 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) ) ) 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) ) 640 #elif defined( MBG_TGT_WIN32 ) 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) ) 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) ) 663 #define _mbg_mmrd8_offs( _dev, _rsrc_idx, _iomem_offs ) \ 664 _mbg_mmrd8( (uint8_t _MBG_IOMEM *) (_dev)->mm_asic_addr + (_iomem_offs) ) 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) ) 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) ) 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) ) ) 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) ) 698 #elif defined( MBG_TGT_DOS ) || defined( MBG_TGT_NETWARE ) || defined( MBG_TGT_OS2 ) 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) ) ) 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) ) 714 #elif defined( MBG_TGT_QNX ) 718 #if defined( MBG_TGT_QNX_NTO ) // compiling for QNX Neutrino 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) ) ) 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) ) 737 #else // compiling for QNX 4 739 #if defined( __WATCOMC__ ) // using Watcom C 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) ) ) 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) ) 763 #if !defined( _mbg_mmrd8 ) 764 #define _mbg_mmrd8( _iomem_addr ) mbg_mmrd8( (_iomem_addr) ) 767 #if !defined( _mbg_mmrd16_native ) 768 #define _mbg_mmrd16_native( _iomem_addr ) mbg_mmrd16_native( (_iomem_addr) ) 771 #if !defined( _mbg_mmrd32_native ) 772 #define _mbg_mmrd32_native( _iomem_addr ) mbg_mmrd32_native( (_iomem_addr) ) 776 #if !defined( _mbg_mmwr8 ) 777 #define _mbg_mmwr8( _iomem_addr, _val ) mbg_wrmm8( (_val), (_iomem_addr) ) 780 #if !defined( _mbg_mmwr16_native ) 781 #define _mbg_mmwr16_native( _iomem_addr, _val ) mbg_wrmm16_native( (_val), (_iomem_addr) ) 784 #if !defined( _mbg_mmwr32_native ) 785 #define _mbg_mmwr32_native( _iomem_addr, _val ) mbg_wrmm32_native( (_val), (_iomem_addr) ) 789 #if MBG_USE_MM_IO_FOR_PCI 795 #define _mbg_inp8 _mbg_mmrd8 796 #define _mbg_inp16 _mbg_mmrd16 797 #define _mbg_inp32 _mbg_mmrd32 799 #define _mbg_outp8 _mbg_mmwr8 800 #define _mbg_outp16 _mbg_mmwr16 801 #define _mbg_outp32 _mbg_mmwr32 static __mbg_inline uint32_t mbg_mmrd32_native(uint32_t volatile __iomem *p)
MBG_IOPORT_ADDR_RAW base_raw
A raw port base address.
ulong MBG_IOPORT_ADDR_MAPPED
static __mbg_inline uint8_t mbg_mmrd8_native(uint8_t volatile __iomem *p)
static __mbg_inline void mbg_unmap_ioport_rsrc(MBG_IOPORT_RSRC *p)
Unmap an I/O port resource to release the virtual address.
static __mbg_inline uint16_t mbg_mmrd16_native(uint16_t volatile __iomem *p)
MBG_IOMEM_ADDR_MAPPED start_mapped
A mapped I/O memory start address.
ulong num
Number of addresses in this range.
void volatile __iomem * MBG_IOMEM_ADDR_MAPPED
uint64_t MBG_IOMEM_ADDR_RAW
uint16_t num
The IRQ number.
MBG_IOPORT_ADDR_MAPPED base_mapped
A mapped port base address.
IRQ resource information for a device.
#define MBG_ERR_NO_MEM
Failed to allocate memory.
#define MBG_SUCCESS
Error codes used with Meinberg devices and drivers.
static __mbg_inline int mbg_map_ioport_rsrc(MBG_IOPORT_RSRC *p)
Map an I/O port resource to get a virtual address.
I/O port resource information for a device.
ulong MBG_IOPORT_ADDR_RAW
static __mbg_inline int mbg_map_iomem_rsrc(MBG_IOMEM_RSRC *p)
Map I/O memory resource to get a virtual address.
static __mbg_inline void mbg_wrmm32_native(uint32_t val, uint32_t volatile __iomem *p)
static __mbg_inline void mbg_unmap_iomem_rsrc(MBG_IOMEM_RSRC *p)
Unmap an I/O memory resource to release the virtual address.
ulong len
Number of addresses in this range.
#define _mbg_ioremap(_base, _num)
MBG_IOMEM_ADDR_RAW start_raw
A raw I/O memory start address.
unsigned __int64 uint64_t
#define _mbg_kdd_msg_2(_lvl, _fmt, _p1, _p2)
Bus memory resource information for a device.
static __mbg_inline void mbg_wrmm16_native(uint16_t val, uint16_t volatile __iomem *p)
#define _mbg_iounmap(_base, _num)
static __mbg_inline void mbg_wrmm8_native(uint8_t val, uint8_t volatile __iomem *p)