static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)

{

    bool page_aligned = false;

    unsigned int n, begin;

    const uint16_t block_size = s->blksize & 0x0fff;

    uint32_t boundary_chk = 1 << (((s->blksize & 0xf000) >> 12) + 12);

    uint32_t boundary_count = boundary_chk - (s->sdmasysad % boundary_chk);



    /* XXX: Some sd/mmc drivers (for example, u-boot-slp) do not account for

     * possible stop at page boundary if initial address is not page aligned,

     * allow them to work properly */

    if ((s->sdmasysad % boundary_chk) == 0) {

        page_aligned = true;

    }



    if (s->trnmod & SDHC_TRNS_READ) {

        s->prnsts |= SDHC_DOING_READ | SDHC_DATA_INHIBIT |

                SDHC_DAT_LINE_ACTIVE;

        while (s->blkcnt) {

            if (s->data_count == 0) {

                for (n = 0; n < block_size; n++) {

                    s->fifo_buffer[n] = sdbus_read_data(&s->sdbus);

                }

            }

            begin = s->data_count;

            if (((boundary_count + begin) < block_size) && page_aligned) {

                s->data_count = boundary_count + begin;

                boundary_count = 0;

             } else {

                s->data_count = block_size;

                boundary_count -= block_size - begin;

                if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {

                    s->blkcnt--;

                }

            }

            dma_memory_write(&address_space_memory, s->sdmasysad,

                             &s->fifo_buffer[begin], s->data_count - begin);

            s->sdmasysad += s->data_count - begin;

            if (s->data_count == block_size) {

                s->data_count = 0;

            }

            if (page_aligned && boundary_count == 0) {

                break;

            }

        }

    } else {

        s->prnsts |= SDHC_DOING_WRITE | SDHC_DATA_INHIBIT |

                SDHC_DAT_LINE_ACTIVE;

        while (s->blkcnt) {

            begin = s->data_count;

            if (((boundary_count + begin) < block_size) && page_aligned) {

                s->data_count = boundary_count + begin;

                boundary_count = 0;

             } else {

                s->data_count = block_size;

                boundary_count -= block_size - begin;

            }

            dma_memory_read(&address_space_memory, s->sdmasysad,

                            &s->fifo_buffer[begin], s->data_count);

            s->sdmasysad += s->data_count - begin;

            if (s->data_count == block_size) {

                for (n = 0; n < block_size; n++) {

                    sdbus_write_data(&s->sdbus, s->fifo_buffer[n]);

                }

                s->data_count = 0;

                if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {

                    s->blkcnt--;

                }

            }

            if (page_aligned && boundary_count == 0) {

                break;

            }

        }

    }



    if (s->blkcnt == 0) {

        sdhci_end_transfer(s);

    } else {

        if (s->norintstsen & SDHC_NISEN_DMA) {

            s->norintsts |= SDHC_NIS_DMA;

        }

        sdhci_update_irq(s);

    }

}

static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)

{

    bool page_aligned = false;

    unsigned int n, begin;

    const uint16_t block_size = s->blksize & 0x0fff;

    uint32_t boundary_chk = 1 << (((s->blksize & 0xf000) >> 12) + 12);

    uint32_t boundary_count = boundary_chk - (s->sdmasysad % boundary_chk);



    





    if ((s->sdmasysad % boundary_chk) == 0) {

        page_aligned = true;

    }



    if (s->trnmod & SDHC_TRNS_READ) {

        s->prnsts |= SDHC_DOING_READ | SDHC_DATA_INHIBIT |

                SDHC_DAT_LINE_ACTIVE;

        while (s->blkcnt) {

            if (s->data_count == 0) {

                for (n = 0; n < block_size; n++) {

                    s->fifo_buffer[n] = sdbus_read_data(&s->sdbus);

                }

            }

            begin = s->data_count;

            if (((boundary_count + begin) < block_size) && page_aligned) {

                s->data_count = boundary_count + begin;

                boundary_count = 0;

             } else {

                s->data_count = block_size;

                boundary_count -= block_size - begin;

                if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {

                    s->blkcnt--;

                }

            }

            dma_memory_write(&address_space_memory, s->sdmasysad,

                             &s->fifo_buffer[begin], s->data_count - begin);

            s->sdmasysad += s->data_count - begin;

            if (s->data_count == block_size) {

                s->data_count = 0;

            }

            if (page_aligned && boundary_count == 0) {

                break;

            }

        }

    } else {

        s->prnsts |= SDHC_DOING_WRITE | SDHC_DATA_INHIBIT |

                SDHC_DAT_LINE_ACTIVE;

        while (s->blkcnt) {

            begin = s->data_count;

            if (((boundary_count + begin) < block_size) && page_aligned) {

                s->data_count = boundary_count + begin;

                boundary_count = 0;

             } else {

                s->data_count = block_size;

                boundary_count -= block_size - begin;

            }

            dma_memory_read(&address_space_memory, s->sdmasysad,

                            &s->fifo_buffer[begin], s->data_count);

            s->sdmasysad += s->data_count - begin;

            if (s->data_count == block_size) {

                for (n = 0; n < block_size; n++) {

                    sdbus_write_data(&s->sdbus, s->fifo_buffer[n]);

                }

                s->data_count = 0;

                if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {

                    s->blkcnt--;

                }

            }

            if (page_aligned && boundary_count == 0) {

                break;

            }

        }

    }



    if (s->blkcnt == 0) {

        sdhci_end_transfer(s);

    } else {

        if (s->norintstsen & SDHC_NISEN_DMA) {

            s->norintsts |= SDHC_NIS_DMA;

        }

        sdhci_update_irq(s);

    }

}

static void FUNC_0(SDHCIState *VAR_0)

{

    bool page_aligned = false;

    unsigned int VAR_1, VAR_2;

    const uint16_t VAR_3 = VAR_0->blksize & 0x0fff;

    uint32_t boundary_chk = 1 << (((VAR_0->blksize & 0xf000) >> 12) + 12);

    uint32_t boundary_count = boundary_chk - (VAR_0->sdmasysad % boundary_chk);



    





    if ((VAR_0->sdmasysad % boundary_chk) == 0) {

        page_aligned = true;

    }



    if (VAR_0->trnmod & SDHC_TRNS_READ) {

        VAR_0->prnsts |= SDHC_DOING_READ | SDHC_DATA_INHIBIT |

                SDHC_DAT_LINE_ACTIVE;

        while (VAR_0->blkcnt) {

            if (VAR_0->data_count == 0) {

                for (VAR_1 = 0; VAR_1 < VAR_3; VAR_1++) {

                    VAR_0->fifo_buffer[VAR_1] = sdbus_read_data(&VAR_0->sdbus);

                }

            }

            VAR_2 = VAR_0->data_count;

            if (((boundary_count + VAR_2) < VAR_3) && page_aligned) {

                VAR_0->data_count = boundary_count + VAR_2;

                boundary_count = 0;

             } else {

                VAR_0->data_count = VAR_3;

                boundary_count -= VAR_3 - VAR_2;

                if (VAR_0->trnmod & SDHC_TRNS_BLK_CNT_EN) {

                    VAR_0->blkcnt--;

                }

            }

            dma_memory_write(&address_space_memory, VAR_0->sdmasysad,

                             &VAR_0->fifo_buffer[VAR_2], VAR_0->data_count - VAR_2);

            VAR_0->sdmasysad += VAR_0->data_count - VAR_2;

            if (VAR_0->data_count == VAR_3) {

                VAR_0->data_count = 0;

            }

            if (page_aligned && boundary_count == 0) {

                break;

            }

        }

    } else {

        VAR_0->prnsts |= SDHC_DOING_WRITE | SDHC_DATA_INHIBIT |

                SDHC_DAT_LINE_ACTIVE;

        while (VAR_0->blkcnt) {

            VAR_2 = VAR_0->data_count;

            if (((boundary_count + VAR_2) < VAR_3) && page_aligned) {

                VAR_0->data_count = boundary_count + VAR_2;

                boundary_count = 0;

             } else {

                VAR_0->data_count = VAR_3;

                boundary_count -= VAR_3 - VAR_2;

            }

            dma_memory_read(&address_space_memory, VAR_0->sdmasysad,

                            &VAR_0->fifo_buffer[VAR_2], VAR_0->data_count);

            VAR_0->sdmasysad += VAR_0->data_count - VAR_2;

            if (VAR_0->data_count == VAR_3) {

                for (VAR_1 = 0; VAR_1 < VAR_3; VAR_1++) {

                    sdbus_write_data(&VAR_0->sdbus, VAR_0->fifo_buffer[VAR_1]);

                }

                VAR_0->data_count = 0;

                if (VAR_0->trnmod & SDHC_TRNS_BLK_CNT_EN) {

                    VAR_0->blkcnt--;

                }

            }

            if (page_aligned && boundary_count == 0) {

                break;

            }

        }

    }



    if (VAR_0->blkcnt == 0) {

        sdhci_end_transfer(VAR_0);

    } else {

        if (VAR_0->norintstsen & SDHC_NISEN_DMA) {

            VAR_0->norintsts |= SDHC_NIS_DMA;

        }

        sdhci_update_irq(VAR_0);

    }

}

static void FUNC_0(SDHCIState *VAR_0)
{ bool page_aligned = false; unsigned int VAR_1, VAR_2; const uint16_t VAR_3 = VAR_0->blksize & 0x0fff; uint32_t boundary_chk = 1 << (((VAR_0->blksize & 0xf000) >> 12) + 12); uint32_t boundary_count = boundary_chk - (VAR_0->sdmasysad % boundary_chk); if ((VAR_0->sdmasysad % boundary_chk) == 0) { page_aligned = true; } if (VAR_0->trnmod & SDHC_TRNS_READ) { VAR_0->prnsts |= SDHC_DOING_READ | SDHC_DATA_INHIBIT |
SDHC_DAT_LINE_ACTIVE; while (VAR_0->blkcnt) { if (VAR_0->data_count == 0) { for (VAR_1 = 0; VAR_1 < VAR_3; VAR_1++) { VAR_0->fifo_buffer[VAR_1] = sdbus_read_data(&VAR_0->sdbus); } } VAR_2 = VAR_0->data_count; if (((boundary_count + VAR_2) < VAR_3) && page_aligned) { VAR_0->data_count = boundary_count + VAR_2; boundary_count = 0; } else { VAR_0->data_count = VAR_3; boundary_count -= VAR_3 - VAR_2; if (VAR_0->trnmod & SDHC_TRNS_BLK_CNT_EN) { VAR_0->blkcnt--; } } dma_memory_write(&address_space_memory, VAR_0->sdmasysad,
&VAR_0->fifo_buffer[VAR_2], VAR_0->data_count - VAR_2); VAR_0->sdmasysad += VAR_0->data_count - VAR_2; if (VAR_0->data_count == VAR_3) { VAR_0->data_count = 0; } if (page_aligned && boundary_count == 0) { break; } } } else { VAR_0->prnsts |= SDHC_DOING_WRITE | SDHC_DATA_INHIBIT |
SDHC_DAT_LINE_ACTIVE; while (VAR_0->blkcnt) { VAR_2 = VAR_0->data_count; if (((boundary_count + VAR_2) < VAR_3) && page_aligned) { VAR_0->data_count = boundary_count + VAR_2; boundary_count = 0; } else { VAR_0->data_count = VAR_3; boundary_count -= VAR_3 - VAR_2; } dma_memory_read(&address_space_memory, VAR_0->sdmasysad,
&VAR_0->fifo_buffer[VAR_2], VAR_0->data_count); VAR_0->sdmasysad += VAR_0->data_count - VAR_2; if (VAR_0->data_count == VAR_3) { for (VAR_1 = 0; VAR_1 < VAR_3; VAR_1++) { sdbus_write_data(&VAR_0->sdbus, VAR_0->fifo_buffer[VAR_1]); } VAR_0->data_count = 0; if (VAR_0->trnmod & SDHC_TRNS_BLK_CNT_EN) { VAR_0->blkcnt--; } } if (page_aligned && boundary_count == 0) { break; } } } if (VAR_0->blkcnt == 0) { sdhci_end_transfer(VAR_0); } else { if (VAR_0->norintstsen & SDHC_NISEN_DMA) { VAR_0->norintsts |= SDHC_NIS_DMA; } sdhci_update_irq(VAR_0); } }