/*                                                                          */
/* Function    : define PCI utils                                           */
/*                                                                          */
/* Macros      1)                                                           */
/*                                                                          */
/*                                                                          */

#include  "windef.h"
#include  "string.h"
#ifndef _MBDR_DSP_XPCI_MANAGE_UTILS_H
#define _MBDR_DSP_XPCI_MANAGE_UTILS_H

/* if input buffer is larger than following limit,              */
/* routine will wait in place till write transuction terminates */
#define MBDR_DSP_XPCI_MANAGE_UTILS_MEMCPY_WRITE_TEMP_BUF_BYTE_SIZE 256

/* copy via pci from DSP memory to external device           */
/* routine: 1) waits till PCI channel is free                */
/*          2) copies input buffer to local temporary buffer */
/*          3) operates PCI channel                          */
/* remark: 1) parameters order reminds stadard C memcpy      */
/*         2) while routine exits data may not arrived to destination, */
/*            but user is able to use input buffer                     */
/* I/O                  */
/* 1) po_src_external_buf_bofs - destination external device*/
/*                       physical address {only 4K values are valid}         */
/* 2) pi_dsp_src_buf_p                 - DSP source buffer pointer           */
/* 3) pi_byte_size                     - buffer byte size,                   */
/*                                       valid values 4,8,12,16,....         */
/* 4) pi_external_device_xpci_base_tbl_index - device PCI base address is     */
/*      being read from:                                                     */
/*        mbdr_dsp_xpci_utils_base_tbl[pi_external_device_xpci_base_tbl_index] */
/*                                                                           */
/* Global: 1) mbdr_dsp_xpci_utils_base_tbl - created and initialized by user  */
extern void mbdr_dsp_xpci_manage_utils_memcpy_write(
                         LONG    po_src_external_buf_bofs,
                         void   *pi_dsp_src_buf_p,
                         size_t  pi_byte_size,
                         LONG    pi_mbdr_dsp_xpci_utils_base_tbl_index);


/* copy via pci from DSP memory to external device           */
/* routine: 1) waits till PCI channel is free                */
/*          2) copies input buffer to local temporary buffer */
/*          3) operates PCI channel                          */
/* remark: 1) parameters order reminds stadard C memcpy      */
/*         2) while routine exits data may not arrived to destination, */
/*            but user is able to use input buffer                     */
/* I/O                  */
/* 1) po_src_external_buf_xpci_p - destination PCI address as view from DSP */
/* 2) pi_dsp_src_buf_p                 - DSP source buffer pointer     */
/* 3) pi_byte_size                     - buffer byte size,             */
/*                                       valid values 4,8,12,16,....   */
/*                                                                     */
extern void* mbdr_dsp_xpci_manage_utils_memcpy_write_no_base(
                         void         *po_src_external_buf_xpci_p,
                         const void   *pi_dsp_src_buf_p,
                         USHORT        pi_byte_size,
                         USHORT        pi_xpci_memcpy_code);

/* writes via pci input 32bit data to required PCI device    */
/*                                                           */
/* routine: 1) waits till PCI channel is free                */
/*          2) copies input DW to temporary buffer           */
/*          3) operates PCI channel                          */
/* remark: 1) while routine exits data may not arrived to destination, */
/* I/O                  */
/* 1) po_src_external_buf_bofs - destination external device*/
/*                       physical address {DW aligne}                        */
/* 2) pi_32bit_data      - DW that is sent to destination                    */
/* 3) pi_external_device_xpci_base_tbl_index - device PCI base address is     */
/*      being read from:                                                     */
/*        mbdr_dsp_xpci_utils_base_tbl[pi_external_device_xpci_base_tbl_index] */
/*                                                                           */
/* Global: 1) mbdr_dsp_xpci_utils_base_tbl - created and initialized by user  */
extern void mbdr_dsp_xpci_manage_utils_write_dw(
                         LONG    po_src_external_buf_bofs,
                         LONG    pi_32bit_data,
                         LONG    pi_mbdr_dsp_xpci_utils_base_tbl_index,
                         USHORT  pi_xpci_memcpy_code);

/* writes via pci input 32bit data to required PCI device    */
/*                                                           */
/* routine: 1) waits till PCI channel is free                */
/*          2) copies input DW to temporary buffer           */
/*          3) operates PCI channel                          */
/* remark: 1) while routine exits data may not arrived to destination, */
/* I/O                  */
/* 1) pi_32bit_data      - DW that is sent to destination                 */
/* 2) po_dst_external_buf_xpci_p - destination external device PCI address */
/* 3) pi_xpci_memcpy_code - future use for driver                          */
/*                                                                        */
extern void mbdr_dsp_xpci_manage_utils_write_dw_no_base(
                         LONG    pi_32bit_data,
                         LONG   *po_dst_external_buf_xpci_p,
                         USHORT  pi_xpci_memcpy_code);

/* read via pci into DSP memory from external device         */
/* routine: 1) waits till PCI channel is free                */
/*          2) operates PCI read channel                     */
/*          3) polls PCI till end of transaction             */
/* copy via pci from external PCI device to DSP memory  */
/* remark: parameters order reminds stadard C memcpy    */
/* I/O                  */
/* 1) po_dsp_dst_buf_p                 - DSP destination buffer pointer      */
/*                                       {align 4}                           */
/* 2) pi_src_external_buf_bofs - external device source     */
/*                         buffer physical address {only 4K values are valid}*/
/* 3) pi_byte_size                     - buffer byte size,                   */
/*                                       valid values 4,8,12,16,....         */
/* 4) pi_external_device_xpci_base_tbl_index - device PCI base address is     */
/*      being read from:                                                     */
/*        mbdr_dsp_xpci_utils_base_tbl[pi_external_device_xpci_base_tbl_index] */
/*                                                                           */
/* Global: 1) mbdr_dsp_xpci_utils_base_tbl - created and initialized by user  */
extern void mbdr_dsp_xpci_manage_utils_memcpy_read(
                    void   *po_dsp_dst_buf_p,
                    LONG    pi_src_external_buf_bofs,
                    size_t  pi_byte_size,
                    LONG    pi_mbdr_dsp_xpci_utils_base_tbl_index);

/* polls till end of previous transaction */
extern void mbdr_dsp_xpci_manage_utils_poll_till_end_of_transaction(void);

#endif
