⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 omap_mmc.c

📁 xen虚拟机源代码安装包
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * OMAP on-chip MMC/SD host emulation. * * Copyright (C) 2006-2007 Andrzej Zaborowski  <balrog@zabor.org> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */#include "hw.h"#include "omap.h"#include "sd.h"struct omap_mmc_s {    target_phys_addr_t base;    qemu_irq irq;    qemu_irq *dma;    qemu_irq coverswitch;    omap_clk clk;    SDState *card;    uint16_t last_cmd;    uint16_t sdio;    uint16_t rsp[8];    uint32_t arg;    int lines;    int dw;    int mode;    int enable;    int be;    int rev;    uint16_t status;    uint16_t mask;    uint8_t cto;    uint16_t dto;    int clkdiv;    uint16_t fifo[32];    int fifo_start;    int fifo_len;    uint16_t blen;    uint16_t blen_counter;    uint16_t nblk;    uint16_t nblk_counter;    int tx_dma;    int rx_dma;    int af_level;    int ae_level;    int ddir;    int transfer;    int cdet_wakeup;    int cdet_enable;    int cdet_state;    qemu_irq cdet;};static void omap_mmc_interrupts_update(struct omap_mmc_s *s){    qemu_set_irq(s->irq, !!(s->status & s->mask));}static void omap_mmc_fifolevel_update(struct omap_mmc_s *host){    if (!host->transfer && !host->fifo_len) {        host->status &= 0xf3ff;        return;    }    if (host->fifo_len > host->af_level && host->ddir) {        if (host->rx_dma) {            host->status &= 0xfbff;            qemu_irq_raise(host->dma[1]);        } else            host->status |= 0x0400;    } else {        host->status &= 0xfbff;        qemu_irq_lower(host->dma[1]);    }    if (host->fifo_len < host->ae_level && !host->ddir) {        if (host->tx_dma) {            host->status &= 0xf7ff;            qemu_irq_raise(host->dma[0]);        } else            host->status |= 0x0800;    } else {        qemu_irq_lower(host->dma[0]);        host->status &= 0xf7ff;    }}typedef enum {    sd_nore = 0,	/* no response */    sd_r1,		/* normal response command */    sd_r2,		/* CID, CSD registers */    sd_r3,		/* OCR register */    sd_r6 = 6,		/* Published RCA response */    sd_r1b = -1,} sd_rsp_type_t;static void omap_mmc_command(struct omap_mmc_s *host, int cmd, int dir,                sd_cmd_type_t type, int busy, sd_rsp_type_t resptype, int init){    uint32_t rspstatus, mask;    int rsplen, timeout;    struct sd_request_s request;    uint8_t response[16];    if (init && cmd == 0) {        host->status |= 0x0001;        return;    }    if (resptype == sd_r1 && busy)        resptype = sd_r1b;    if (type == sd_adtc) {        host->fifo_start = 0;        host->fifo_len = 0;        host->transfer = 1;        host->ddir = dir;    } else        host->transfer = 0;    timeout = 0;    mask = 0;    rspstatus = 0;    request.cmd = cmd;    request.arg = host->arg;    request.crc = 0; /* FIXME */    rsplen = sd_do_command(host->card, &request, response);    /* TODO: validate CRCs */    switch (resptype) {    case sd_nore:        rsplen = 0;        break;    case sd_r1:    case sd_r1b:        if (rsplen < 4) {            timeout = 1;            break;        }        rsplen = 4;        mask = OUT_OF_RANGE | ADDRESS_ERROR | BLOCK_LEN_ERROR |                ERASE_SEQ_ERROR | ERASE_PARAM | WP_VIOLATION |                LOCK_UNLOCK_FAILED | COM_CRC_ERROR | ILLEGAL_COMMAND |                CARD_ECC_FAILED | CC_ERROR | SD_ERROR |                CID_CSD_OVERWRITE;        if (host->sdio & (1 << 13))            mask |= AKE_SEQ_ERROR;        rspstatus = (response[0] << 24) | (response[1] << 16) |                (response[2] << 8) | (response[3] << 0);        break;    case sd_r2:        if (rsplen < 16) {            timeout = 1;            break;        }        rsplen = 16;        break;    case sd_r3:        if (rsplen < 4) {            timeout = 1;            break;        }        rsplen = 4;        rspstatus = (response[0] << 24) | (response[1] << 16) |                (response[2] << 8) | (response[3] << 0);        if (rspstatus & 0x80000000)            host->status &= 0xe000;        else            host->status |= 0x1000;        break;    case sd_r6:        if (rsplen < 4) {            timeout = 1;            break;        }        rsplen = 4;        mask = 0xe000 | AKE_SEQ_ERROR;        rspstatus = (response[2] << 8) | (response[3] << 0);    }    if (rspstatus & mask)        host->status |= 0x4000;    else        host->status &= 0xb000;    if (rsplen)        for (rsplen = 0; rsplen < 8; rsplen ++)            host->rsp[~rsplen & 7] = response[(rsplen << 1) | 1] |                    (response[(rsplen << 1) | 0] << 8);    if (timeout)        host->status |= 0x0080;    else if (cmd == 12)        host->status |= 0x0005;	/* Makes it more real */    else        host->status |= 0x0001;}static void omap_mmc_transfer(struct omap_mmc_s *host){    uint8_t value;    if (!host->transfer)        return;    while (1) {        if (host->ddir) {            if (host->fifo_len > host->af_level)                break;            value = sd_read_data(host->card);            host->fifo[(host->fifo_start + host->fifo_len) & 31] = value;            if (-- host->blen_counter) {                value = sd_read_data(host->card);                host->fifo[(host->fifo_start + host->fifo_len) & 31] |=                        value << 8;                host->blen_counter --;            }            host->fifo_len ++;        } else {            if (!host->fifo_len)                break;            value = host->fifo[host->fifo_start] & 0xff;            sd_write_data(host->card, value);            if (-- host->blen_counter) {                value = host->fifo[host->fifo_start] >> 8;                sd_write_data(host->card, value);                host->blen_counter --;            }            host->fifo_start ++;            host->fifo_len --;            host->fifo_start &= 31;        }        if (host->blen_counter == 0) {            host->nblk_counter --;            host->blen_counter = host->blen;            if (host->nblk_counter == 0) {                host->nblk_counter = host->nblk;                host->transfer = 0;                host->status |= 0x0008;                break;            }        }    }}static void omap_mmc_update(void *opaque){    struct omap_mmc_s *s = opaque;    omap_mmc_transfer(s);    omap_mmc_fifolevel_update(s);    omap_mmc_interrupts_update(s);}void omap_mmc_reset(struct omap_mmc_s *host){    host->last_cmd = 0;    memset(host->rsp, 0, sizeof(host->rsp));    host->arg = 0;    host->dw = 0;    host->mode = 0;    host->enable = 0;    host->status = 0;    host->mask = 0;    host->cto = 0;    host->dto = 0;    host->fifo_len = 0;    host->blen = 0;    host->blen_counter = 0;    host->nblk = 0;    host->nblk_counter = 0;    host->tx_dma = 0;    host->rx_dma = 0;    host->ae_level = 0x00;    host->af_level = 0x1f;    host->transfer = 0;    host->cdet_wakeup = 0;    host->cdet_enable = 0;    qemu_set_irq(host->coverswitch, host->cdet_state);    host->clkdiv = 0;}static uint32_t omap_mmc_read(void *opaque, target_phys_addr_t offset){    uint16_t i;    struct omap_mmc_s *s = (struct omap_mmc_s *) opaque;    offset &= OMAP_MPUI_REG_MASK;    switch (offset) {    case 0x00:	/* MMC_CMD */        return s->last_cmd;    case 0x04:	/* MMC_ARGL */        return s->arg & 0x0000ffff;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -