/* pasemi_dma_alloc_chan - Allocate a DMA channel * @type: Type of channel to allocate * @total_size: Total size of structure to allocate (to allow for more * room behind the structure to be used by the client) * @offset: Offset in bytes from start of the total structure to the beginning * of struct pasemi_dmachan. Needed when struct pasemi_dmachan is * not the first member of the client structure. * * pasemi_dma_alloc_chan allocates a DMA channel for use by a client. The * type argument specifies whether it's a RX or TX channel, and in the case * of TX channels which group it needs to belong to (if any). * * Returns a pointer to the total structure allocated on success, NULL * on failure.
*/ void *pasemi_dma_alloc_chan(enum pasemi_dmachan_type type, int total_size, int offset)
{ void *buf; struct pasemi_dmachan *chan; int chno;
/* pasemi_dma_free_chan - Free a previously allocated channel * @chan: Channel to free * * Frees a previously allocated channel. It will also deallocate any * descriptor ring associated with the channel, if allocated.
*/ void pasemi_dma_free_chan(struct pasemi_dmachan *chan)
{ if (chan->ring_virt)
pasemi_dma_free_ring(chan);
switch (chan->chan_type & (RXCHAN|TXCHAN)) { case RXCHAN:
pasemi_free_rx_chan(chan->chno); break; case TXCHAN:
pasemi_free_tx_chan(chan->chno); break;
}
/* pasemi_dma_alloc_ring - Allocate descriptor ring for a channel * @chan: Channel for which to allocate * @ring_size: Ring size in 64-bit (8-byte) words * * Allocate a descriptor ring for a channel. Returns 0 on success, errno * on failure. The passed in struct pasemi_dmachan is updated with the * virtual and DMA addresses of the ring.
*/ int pasemi_dma_alloc_ring(struct pasemi_dmachan *chan, int ring_size)
{
BUG_ON(chan->ring_virt);
/* pasemi_dma_free_ring - Free an allocated descriptor ring for a channel * @chan: Channel for which to free the descriptor ring * * Frees a previously allocated descriptor ring for a channel.
*/ void pasemi_dma_free_ring(struct pasemi_dmachan *chan)
{
BUG_ON(!chan->ring_virt);
/* pasemi_dma_start_chan - Start a DMA channel * @chan: Channel to start * @cmdsta: Additional CCMDSTA/TCMDSTA bits to write * * Enables (starts) a DMA channel with optional additional arguments.
*/ void pasemi_dma_start_chan(conststruct pasemi_dmachan *chan, const u32 cmdsta)
{ if (chan->chan_type == RXCHAN)
pasemi_write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(chan->chno),
cmdsta | PAS_DMA_RXCHAN_CCMDSTA_EN); else
pasemi_write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(chan->chno),
cmdsta | PAS_DMA_TXCHAN_TCMDSTA_EN);
}
EXPORT_SYMBOL(pasemi_dma_start_chan);
/* pasemi_dma_stop_chan - Stop a DMA channel * @chan: Channel to stop * * Stops (disables) a DMA channel. This is done by setting the ST bit in the * CMDSTA register and waiting on the ACT (active) bit to clear, then * finally disabling the whole channel. * * This function will only try for a short while for the channel to stop, if * it doesn't it will return failure. * * Returns 1 on success, 0 on failure.
*/ #define MAX_RETRIES 5000 int pasemi_dma_stop_chan(conststruct pasemi_dmachan *chan)
{ int reg, retries;
u32 sta;
if (chan->chan_type == RXCHAN) {
reg = PAS_DMA_RXCHAN_CCMDSTA(chan->chno);
pasemi_write_dma_reg(reg, PAS_DMA_RXCHAN_CCMDSTA_ST); for (retries = 0; retries < MAX_RETRIES; retries++) {
sta = pasemi_read_dma_reg(reg); if (!(sta & PAS_DMA_RXCHAN_CCMDSTA_ACT)) {
pasemi_write_dma_reg(reg, 0); return 1;
}
cond_resched();
}
} else {
reg = PAS_DMA_TXCHAN_TCMDSTA(chan->chno);
pasemi_write_dma_reg(reg, PAS_DMA_TXCHAN_TCMDSTA_ST); for (retries = 0; retries < MAX_RETRIES; retries++) {
sta = pasemi_read_dma_reg(reg); if (!(sta & PAS_DMA_TXCHAN_TCMDSTA_ACT)) {
pasemi_write_dma_reg(reg, 0); return 1;
}
cond_resched();
}
}
return 0;
}
EXPORT_SYMBOL(pasemi_dma_stop_chan);
/* pasemi_dma_alloc_buf - Allocate a buffer to use for DMA * @chan: Channel to allocate for * @size: Size of buffer in bytes * @handle: DMA handle * * Allocate a buffer to be used by the DMA engine for read/write, * similar to dma_alloc_coherent(). * * Returns the virtual address of the buffer, or NULL in case of failure.
*/ void *pasemi_dma_alloc_buf(struct pasemi_dmachan *chan, int size,
dma_addr_t *handle)
{ return dma_alloc_coherent(&dma_pdev->dev, size, handle, GFP_KERNEL);
}
EXPORT_SYMBOL(pasemi_dma_alloc_buf);
/* pasemi_dma_free_buf - Free a buffer used for DMA * @chan: Channel the buffer was allocated for * @size: Size of buffer in bytes * @handle: DMA handle * * Frees a previously allocated buffer.
*/ void pasemi_dma_free_buf(struct pasemi_dmachan *chan, int size,
dma_addr_t *handle)
{
dma_free_coherent(&dma_pdev->dev, size, handle, GFP_KERNEL);
}
EXPORT_SYMBOL(pasemi_dma_free_buf);
/* pasemi_dma_alloc_flag - Allocate a flag (event) for channel synchronization * * Allocates a flag for use with channel synchronization (event descriptors). * Returns allocated flag (0-63), < 0 on error.
*/ int pasemi_dma_alloc_flag(void)
{ int bit;
retry:
bit = find_first_bit(flags_free, MAX_FLAGS); if (bit >= MAX_FLAGS) return -ENOSPC; if (!test_and_clear_bit(bit, flags_free)) goto retry;
/* pasemi_dma_free_flag - Deallocates a flag (event) * @flag: Flag number to deallocate * * Frees up a flag so it can be reused for other purposes.
*/ void pasemi_dma_free_flag(int flag)
{
BUG_ON(test_bit(flag, flags_free));
BUG_ON(flag >= MAX_FLAGS);
set_bit(flag, flags_free);
}
EXPORT_SYMBOL(pasemi_dma_free_flag);
/* pasemi_dma_set_flag - Sets a flag (event) to 1 * @flag: Flag number to set active * * Sets the flag provided to 1.
*/ void pasemi_dma_set_flag(int flag)
{
BUG_ON(flag >= MAX_FLAGS); if (flag < 32)
pasemi_write_dma_reg(PAS_DMA_TXF_SFLG0, 1 << flag); else
pasemi_write_dma_reg(PAS_DMA_TXF_SFLG1, 1 << flag);
}
EXPORT_SYMBOL(pasemi_dma_set_flag);
/* pasemi_dma_clear_flag - Sets a flag (event) to 0 * @flag: Flag number to set inactive * * Sets the flag provided to 0.
*/ void pasemi_dma_clear_flag(int flag)
{
BUG_ON(flag >= MAX_FLAGS); if (flag < 32)
pasemi_write_dma_reg(PAS_DMA_TXF_CFLG0, 1 << flag); else
pasemi_write_dma_reg(PAS_DMA_TXF_CFLG1, 1 << flag);
}
EXPORT_SYMBOL(pasemi_dma_clear_flag);
/* pasemi_dma_alloc_fun - Allocate a function engine * * Allocates a function engine to use for crypto/checksum offload * Returns allocated engine (0-8), < 0 on error.
*/ int pasemi_dma_alloc_fun(void)
{ int bit;
retry:
bit = find_first_bit(fun_free, MAX_FLAGS); if (bit >= MAX_FLAGS) return -ENOSPC; if (!test_and_clear_bit(bit, fun_free)) goto retry;
/* pasemi_dma_free_fun - Deallocates a function engine * @flag: Engine number to deallocate * * Frees up a function engine so it can be used for other purposes.
*/ void pasemi_dma_free_fun(int fun)
{
BUG_ON(test_bit(fun, fun_free));
BUG_ON(fun >= MAX_FLAGS);
set_bit(fun, fun_free);
}
EXPORT_SYMBOL(pasemi_dma_free_fun);
dn = pci_device_to_OF_node(p); if (!dn) goto fallback;
ret = of_iomap(dn, index); if (!ret) goto fallback;
return ret;
fallback: /* This is hardcoded and ugly, but we have some firmware versions * that don't provide the register space in the device tree. Luckily * they are at well-known locations so we can just do the math here.
*/ return ioremap(0xe0000000 + (p->devfn << 12), 0x2000);
}
/* pasemi_dma_init - Initialize the PA Semi DMA library * * This function initializes the DMA library. It must be called before * any other function in the library. * * Returns 0 on success, errno on failure.
*/ int pasemi_dma_init(void)
{ static DEFINE_SPINLOCK(init_lock); struct pci_dev *iob_pdev; struct pci_dev *pdev; struct resource res; struct device_node *dn; int i, intf, err = 0; unsignedlong timeout;
u32 tmp;
if (!machine_is(pasemi)) return -ENODEV;
spin_lock(&init_lock);
/* Make sure we haven't already initialized */ if (dma_pdev) goto out;
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.