int spapr_tce_dma_read(VIOsPAPRDevice *dev, uint64_t taddr, void *buf,

                       uint32_t size)

{

#ifdef DEBUG_TCE

    fprintf(stderr, "spapr_tce_dma_write taddr=0x%llx size=0x%x\n",

            (unsigned long long)taddr, size);

#endif



    /* Check for bypass */

    if (dev->flags & VIO_PAPR_FLAG_DMA_BYPASS) {

        cpu_physical_memory_read(taddr, buf, size);

        return 0;

    }



    while (size) {

        uint64_t tce;

        uint32_t lsize;

        uint64_t txaddr;



        /* Check if we are in bound */

        if (taddr >= dev->rtce_window_size) {

#ifdef DEBUG_TCE

            fprintf(stderr, "spapr_tce_dma_read out of bounds\n");

#endif

            return H_DEST_PARM;

        }

        tce = dev->rtce_table[taddr >> SPAPR_VIO_TCE_PAGE_SHIFT].tce;



        /* How much til end of page ? */

        lsize = MIN(size, ((~taddr) & SPAPR_VIO_TCE_PAGE_MASK) + 1);



        /* Check TCE */

        if (!(tce & 1)) {

            return H_DEST_PARM;

        }



        /* Translate */

        txaddr = (tce & ~SPAPR_VIO_TCE_PAGE_MASK) |

            (taddr & SPAPR_VIO_TCE_PAGE_MASK);



#ifdef DEBUG_TCE

        fprintf(stderr, " -> write to txaddr=0x%llx, size=0x%x\n",

                (unsigned long long)txaddr, lsize);

#endif

        /* Do it */

        cpu_physical_memory_read(txaddr, buf, lsize);

        buf += lsize;

        taddr += lsize;

        size -= lsize;

    }

    return H_SUCCESS;

}

int spapr_tce_dma_read(VIOsPAPRDevice *dev, uint64_t taddr, void *buf,

                       uint32_t size)

{

#ifdef DEBUG_TCE

    fprintf(stderr, "spapr_tce_dma_write taddr=0x%llx size=0x%x\n",

            (unsigned long long)taddr, size);

#endif



    

    if (dev->flags & VIO_PAPR_FLAG_DMA_BYPASS) {

        cpu_physical_memory_read(taddr, buf, size);

        return 0;

    }



    while (size) {

        uint64_t tce;

        uint32_t lsize;

        uint64_t txaddr;



        

        if (taddr >= dev->rtce_window_size) {

#ifdef DEBUG_TCE

            fprintf(stderr, "spapr_tce_dma_read out of bounds\n");

#endif

            return H_DEST_PARM;

        }

        tce = dev->rtce_table[taddr >> SPAPR_VIO_TCE_PAGE_SHIFT].tce;



        

        lsize = MIN(size, ((~taddr) & SPAPR_VIO_TCE_PAGE_MASK) + 1);



        

        if (!(tce & 1)) {

            return H_DEST_PARM;

        }



        

        txaddr = (tce & ~SPAPR_VIO_TCE_PAGE_MASK) |

            (taddr & SPAPR_VIO_TCE_PAGE_MASK);



#ifdef DEBUG_TCE

        fprintf(stderr, " -> write to txaddr=0x%llx, size=0x%x\n",

                (unsigned long long)txaddr, lsize);

#endif

        

        cpu_physical_memory_read(txaddr, buf, lsize);

        buf += lsize;

        taddr += lsize;

        size -= lsize;

    }

    return H_SUCCESS;

}

#ifdef DEBUG_TCE #endif     return H_SUCCESS; #ifdef DEBUG_TCE #endif #ifdef DEBUG_TCE     fprintf(stderr, "spapr_tce_dma_write taddr=0x%llx size=0x%x\n",             (unsigned long long)taddr, size); #endif     if (dev->flags & VIO_PAPR_FLAG_DMA_BYPASS) {         return 0;     while (size) {         uint64_t tce;         uint32_t lsize;         uint64_t txaddr;         if (taddr >= dev->rtce_window_size) { #ifdef DEBUG_TCE #endif             return H_DEST_PARM;         tce = dev->rtce_table[taddr >> SPAPR_VIO_TCE_PAGE_SHIFT].tce;         lsize = MIN(size, ((~taddr) & SPAPR_VIO_TCE_PAGE_MASK) + 1);             return H_DEST_PARM;         txaddr = (tce & ~SPAPR_VIO_TCE_PAGE_MASK) |             (taddr & SPAPR_VIO_TCE_PAGE_MASK); #ifdef DEBUG_TCE         fprintf(stderr, " -> write to txaddr=0x%llx, size=0x%x\n",                 (unsigned long long)txaddr, lsize); #endif         buf += lsize;         taddr += lsize;         size -= lsize; #ifdef DEBUG_TCE             (unsigned long long)taddr, size); #endif int spapr_tce_dma_read(VIOsPAPRDevice *dev, uint64_t taddr, void *buf,                        uint32_t size) #ifdef DEBUG_TCE     fprintf(stderr, "spapr_tce_dma_write taddr=0x%llx size=0x%x\n",             (unsigned long long)taddr, size); #endif     if (dev->flags & VIO_PAPR_FLAG_DMA_BYPASS) {         cpu_physical_memory_read(taddr, buf, size);         return 0;     while (size) {         uint64_t tce;         uint32_t lsize;         uint64_t txaddr;         if (taddr >= dev->rtce_window_size) { #ifdef DEBUG_TCE             fprintf(stderr, "spapr_tce_dma_read out of bounds\n"); #endif             return H_DEST_PARM;         tce = dev->rtce_table[taddr >> SPAPR_VIO_TCE_PAGE_SHIFT].tce;         lsize = MIN(size, ((~taddr) & SPAPR_VIO_TCE_PAGE_MASK) + 1);         if (!(tce & 1)) {             return H_DEST_PARM;         txaddr = (tce & ~SPAPR_VIO_TCE_PAGE_MASK) |             (taddr & SPAPR_VIO_TCE_PAGE_MASK); #ifdef DEBUG_TCE         fprintf(stderr, " -> write to txaddr=0x%llx, size=0x%x\n",                 (unsigned long long)txaddr, lsize); #endif         cpu_physical_memory_read(txaddr, buf, lsize);         buf += lsize;         taddr += lsize;         size -= lsize;     return H_SUCCESS;
int FUNC_0(VIOsPAPRDevice *VAR_0, uint64_t VAR_1, void *VAR_2,

                       uint32_t VAR_3)

{

#ifdef DEBUG_TCE

    fprintf(stderr, "spapr_tce_dma_write VAR_1=0x%llx VAR_3=0x%x\n",

            (unsigned long long)VAR_1, VAR_3);

#endif



    

    if (VAR_0->flags & VIO_PAPR_FLAG_DMA_BYPASS) {

        cpu_physical_memory_read(VAR_1, VAR_2, VAR_3);

        return 0;

    }



    while (VAR_3) {

        uint64_t tce;

        uint32_t lsize;

        uint64_t txaddr;



        

        if (VAR_1 >= VAR_0->rtce_window_size) {

#ifdef DEBUG_TCE

            fprintf(stderr, "FUNC_0 out of bounds\n");

#endif

            return H_DEST_PARM;

        }

        tce = VAR_0->rtce_table[VAR_1 >> SPAPR_VIO_TCE_PAGE_SHIFT].tce;



        

        lsize = MIN(VAR_3, ((~VAR_1) & SPAPR_VIO_TCE_PAGE_MASK) + 1);



        

        if (!(tce & 1)) {

            return H_DEST_PARM;

        }



        

        txaddr = (tce & ~SPAPR_VIO_TCE_PAGE_MASK) |

            (VAR_1 & SPAPR_VIO_TCE_PAGE_MASK);



#ifdef DEBUG_TCE

        fprintf(stderr, " -> write to txaddr=0x%llx, VAR_3=0x%x\n",

                (unsigned long long)txaddr, lsize);

#endif

        

        cpu_physical_memory_read(txaddr, VAR_2, lsize);

        VAR_2 += lsize;

        VAR_1 += lsize;

        VAR_3 -= lsize;

    }

    return H_SUCCESS;

}

int FUNC_0(VIOsPAPRDevice *VAR_0, uint64_t VAR_1, void *VAR_2,
uint32_t VAR_3)
{ #ifdef DEBUG_TCE
fprintf(stderr, "spapr_tce_dma_write VAR_1=0x%llx VAR_3=0x%x\n",
(unsigned long long)VAR_1, VAR_3); #endif
if (VAR_0->flags & VIO_PAPR_FLAG_DMA_BYPASS) { cpu_physical_memory_read(VAR_1, VAR_2, VAR_3); return 0; } while (VAR_3) { uint64_t tce; uint32_t lsize; uint64_t txaddr; if (VAR_1 >= VAR_0->rtce_window_size) { #ifdef DEBUG_TCE
fprintf(stderr, "FUNC_0 out of bounds\n"); #endif
return H_DEST_PARM; } tce = VAR_0->rtce_table[VAR_1 >> SPAPR_VIO_TCE_PAGE_SHIFT].tce; lsize = MIN(VAR_3, ((~VAR_1) & SPAPR_VIO_TCE_PAGE_MASK) + 1); if (!(tce & 1)) { return H_DEST_PARM; } txaddr = (tce & ~SPAPR_VIO_TCE_PAGE_MASK) |
(VAR_1 & SPAPR_VIO_TCE_PAGE_MASK); #ifdef DEBUG_TCE
fprintf(stderr, " -> write to txaddr=0x%llx, VAR_3=0x%x\n",
(unsigned long long)txaddr, lsize); #endif
cpu_physical_memory_read(txaddr, VAR_2, lsize); VAR_2 += lsize; VAR_1 += lsize; VAR_3 -= lsize; } return H_SUCCESS; }