#define CVP_BAR 0 /* BAR used for data transfer in memory mode */ #define CVP_DUMMY_WR 244 /* dummy writes to clear CvP state machine */ #define TIMEOUT_US 2000 /* CVP STATUS timeout for USERMODE polling */
/* switches between CvP clock and internal clock */ staticvoid altera_cvp_dummy_write(struct altera_cvp_conf *conf)
{ unsignedint i;
u32 val;
/* set 1 CVP clock cycle for every CVP Data Register Write */
altera_read_config_dword(conf, VSE_CVP_MODE_CTRL, &val);
val &= ~VSE_CVP_MODE_CTRL_NUMCLKS_MASK;
val |= 1 << VSE_CVP_MODE_CTRL_NUMCLKS_OFF;
altera_write_config_dword(conf, VSE_CVP_MODE_CTRL, val);
for (i = 0; i < CVP_DUMMY_WR; i++)
conf->write_data(conf, 0); /* dummy data, could be any value */
}
/* STEP 10 (optional) - check CVP_CONFIG_ERROR flag */
ret = altera_read_config_dword(conf, VSE_CVP_STATUS, &val); if (ret || (val & VSE_CVP_STATUS_CFG_ERR)) {
dev_err(&mgr->dev, "CVP_CONFIG_ERROR after %zu bytes!\n",
bytes); return -EPROTO;
} return 0;
}
/* * CvP Version2 Functions * Recent Intel FPGAs use a credit mechanism to throttle incoming * bitstreams and a different method of clearing the state.
*/
staticint altera_cvp_v2_clear_state(struct altera_cvp_conf *conf)
{
u32 val; int ret;
/* Clear the START_XFER and CVP_CONFIG bits */
ret = altera_read_config_dword(conf, VSE_CVP_PROG_CTRL, &val); if (ret) {
dev_err(&conf->pci_dev->dev, "Error reading CVP Program Control Register\n"); return ret;
}
val &= ~VSE_CVP_PROG_CTRL_MASK;
ret = altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val); if (ret) {
dev_err(&conf->pci_dev->dev, "Error writing CVP Program Control Register\n"); return ret;
}
do {
ret = altera_read_config_byte(conf, VSE_CVP_TX_CREDITS, &val); if (ret) {
dev_err(&conf->pci_dev->dev, "Error reading CVP Credit Register\n"); return ret;
}
/* Return if there is space in FIFO */ if (val - (u8)conf->sent_packets) return 0;
ret = altera_cvp_chk_error(mgr, blocks * ALTERA_CVP_V2_SIZE); if (ret) {
dev_err(&conf->pci_dev->dev, "CE Bit error credit reg[0x%x]:sent[0x%x]\n",
val, conf->sent_packets); return -EAGAIN;
}
/* Limit the check credit byte traffic */
usleep_range(V2_CHECK_CREDIT_US, V2_CHECK_CREDIT_US + 1);
} while (timeout--);
dev_err(&conf->pci_dev->dev, "Timeout waiting for credit\n"); return -ETIMEDOUT;
}
staticint altera_cvp_send_block(struct altera_cvp_conf *conf, const u32 *data, size_t len)
{
u32 mask, words = len / sizeof(u32); int i, remainder;
for (i = 0; i < words; i++)
conf->write_data(conf, *data++);
/* write up to 3 trailing bytes, if any */
remainder = len % sizeof(u32); if (remainder) {
mask = BIT(remainder * 8) - 1; if (mask)
conf->write_data(conf, *data & mask);
}
/* STEP 12 - reset START_XFER bit */
altera_read_config_dword(conf, VSE_CVP_PROG_CTRL, &val);
val &= ~VSE_CVP_PROG_CTRL_START_XFER;
altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val);
/* STEP 13 - reset CVP_CONFIG bit */
val &= ~VSE_CVP_PROG_CTRL_CONFIG;
altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val);
/* * STEP 14 * - set CVP_NUMCLKS to 1 and then issue CVP_DUMMY_WR dummy * writes to the HIP
*/ if (conf->priv->switch_clk)
conf->priv->switch_clk(conf);
/* STEP 15 - poll CVP_CONFIG_READY bit for 0 with 10us timeout */
ret = altera_cvp_wait_status(conf, VSE_CVP_STATUS_CFG_RDY, 0,
conf->priv->poll_time_us); if (ret)
dev_err(&mgr->dev, "CFG_RDY == 0 timeout\n");
if (iflags & FPGA_MGR_PARTIAL_RECONFIG) {
dev_err(&mgr->dev, "Partial reconfiguration not supported.\n"); return -EINVAL;
}
/* Determine allowed clock to data ratio */ if (iflags & FPGA_MGR_COMPRESSED_BITSTREAM)
conf->numclks = 8; /* ratio for all compressed images */ elseif (iflags & FPGA_MGR_ENCRYPTED_BITSTREAM)
conf->numclks = 4; /* for uncompressed and encrypted images */ else
conf->numclks = 1; /* for uncompressed and unencrypted images */
/* STEP 1 - read CVP status and check CVP_EN flag */
altera_read_config_dword(conf, VSE_CVP_STATUS, &val); if (!(val & VSE_CVP_STATUS_CVP_EN)) {
dev_err(&mgr->dev, "CVP mode off: 0x%04x\n", val); return -ENODEV;
}
if (val & VSE_CVP_STATUS_CFG_RDY) {
dev_warn(&mgr->dev, "CvP already started, tear down first\n");
ret = altera_cvp_teardown(mgr, info); if (ret) return ret;
}
/* * STEP 2 * - set HIP_CLK_SEL and CVP_MODE (must be set in the order mentioned)
*/ /* switch from fabric to PMA clock */
altera_read_config_dword(conf, VSE_CVP_MODE_CTRL, &val);
val |= VSE_CVP_MODE_CTRL_HIP_CLK_SEL;
altera_write_config_dword(conf, VSE_CVP_MODE_CTRL, val);
/* set CVP mode */
altera_read_config_dword(conf, VSE_CVP_MODE_CTRL, &val);
val |= VSE_CVP_MODE_CTRL_CVP_MODE;
altera_write_config_dword(conf, VSE_CVP_MODE_CTRL, val);
/* * STEP 3 * - set CVP_NUMCLKS to 1 and issue CVP_DUMMY_WR dummy writes to the HIP
*/ if (conf->priv->switch_clk)
conf->priv->switch_clk(conf);
if (conf->priv->clear_state) {
ret = conf->priv->clear_state(conf); if (ret) {
dev_err(&mgr->dev, "Problem clearing out state\n"); return ret;
}
}
conf->sent_packets = 0;
/* STEP 4 - set CVP_CONFIG bit */
altera_read_config_dword(conf, VSE_CVP_PROG_CTRL, &val); /* request control block to begin transfer using CVP */
val |= VSE_CVP_PROG_CTRL_CONFIG;
altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val);
/* STEP 5 - poll CVP_CONFIG READY for 1 with timeout */
ret = altera_cvp_wait_status(conf, VSE_CVP_STATUS_CFG_RDY,
VSE_CVP_STATUS_CFG_RDY,
conf->priv->poll_time_us); if (ret) {
dev_warn(&mgr->dev, "CFG_RDY == 1 timeout\n"); return ret;
}
/* * STEP 6 * - set CVP_NUMCLKS to 1 and issue CVP_DUMMY_WR dummy writes to the HIP
*/ if (conf->priv->switch_clk)
conf->priv->switch_clk(conf);
if (altera_cvp_chkcfg) {
ret = altera_cvp_chk_error(mgr, 0); if (ret) {
dev_warn(&mgr->dev, "CFG_RDY == 1 timeout\n"); return ret;
}
}
/* STEP 7 - set START_XFER */
altera_read_config_dword(conf, VSE_CVP_PROG_CTRL, &val);
val |= VSE_CVP_PROG_CTRL_START_XFER;
altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val);
/* STEP 8 - start transfer (set CVP_NUMCLKS for bitstream) */ if (conf->priv->switch_clk) {
altera_read_config_dword(conf, VSE_CVP_MODE_CTRL, &val);
val &= ~VSE_CVP_MODE_CTRL_NUMCLKS_MASK;
val |= conf->numclks << VSE_CVP_MODE_CTRL_NUMCLKS_OFF;
altera_write_config_dword(conf, VSE_CVP_MODE_CTRL, val);
} return 0;
}
/* STEP 9 - write 32-bit data from RBF file to CVP data register */
data = (u32 *)buf;
remaining = count;
done = 0;
while (remaining) { /* Use credit throttling if available */ if (conf->priv->wait_credit) {
status = conf->priv->wait_credit(mgr, done); if (status) {
dev_err(&conf->pci_dev->dev, "Wait Credit ERR: 0x%x\n", status); return status;
}
}
len = min(conf->priv->block_size, remaining);
altera_cvp_send_block(conf, data, len);
data += len / sizeof(u32);
done += len;
remaining -= len;
conf->sent_packets++;
/* * STEP 10 (optional) and STEP 11 * - check error flag * - loop until data transfer completed * Config images can be huge (more than 40 MiB), so * only check after a new 4k data block has been written. * This reduces the number of checks and speeds up the * configuration process.
*/ if (altera_cvp_chkcfg && !(done % SZ_4K)) {
status = altera_cvp_chk_error(mgr, done); if (status < 0) return status;
}
}
if (altera_cvp_chkcfg)
status = altera_cvp_chk_error(mgr, count);
/* Discover the Vendor Specific Offset for this device */
offset = pci_find_next_ext_capability(pdev, 0, PCI_EXT_CAP_ID_VNDR); if (!offset) {
dev_err(&pdev->dev, "No Vendor Specific Offset.\n"); return -ENODEV;
}
/* * First check if this is the expected FPGA device. PCI config * space access works without enabling the PCI device, memory * space access is enabled further down.
*/
pci_read_config_word(pdev, offset + VSE_PCIE_EXT_CAP_ID, &val); if (val != VSE_PCIE_EXT_CAP_ID_VAL) {
dev_err(&pdev->dev, "Wrong EXT_CAP_ID value 0x%x\n", val); return -ENODEV;
}
pci_read_config_dword(pdev, offset + VSE_CVP_STATUS, ®val); if (!(regval & VSE_CVP_STATUS_CVP_EN)) {
dev_err(&pdev->dev, "CVP is disabled for this device: CVP_STATUS Reg 0x%x\n",
regval); return -ENODEV;
}
conf = devm_kzalloc(&pdev->dev, sizeof(*conf), GFP_KERNEL); if (!conf) return -ENOMEM;
conf->vsec_offset = offset;
/* * Enable memory BAR access. We cannot use pci_enable_device() here * because it will make the driver unusable with FPGA devices that * have additional big IOMEM resources (e.g. 4GiB BARs) on 32-bit * platform. Such BARs will not have an assigned address range and * pci_enable_device() will fail, complaining about not claimed BAR, * even if the concerned BAR is not needed for FPGA configuration * at all. Thus, enable the device via PCI config space command.
*/
pci_read_config_word(pdev, PCI_COMMAND, &cmd); if (!(cmd & PCI_COMMAND_MEMORY)) {
cmd |= PCI_COMMAND_MEMORY;
pci_write_config_word(pdev, PCI_COMMAND, cmd);
}
ret = pci_request_region(pdev, CVP_BAR, "CVP"); if (ret) {
dev_err(&pdev->dev, "Requesting CVP BAR region failed\n"); goto err_disable;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.