Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: C  |  size: 1.99 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // DMA-list transfers: programming example
  2.  
  3. // The C-language sample program included here creates a DMA list and, in the last line, uses an spu_mfcdma32 intrinsic to issue a single DMA-list
  4. // command (getl) to transfer a main-storage region into LS.
  5.  
  6. /* dma_list_sample.c - SPU MFC-DMA list sample code.
  7.  *
  8.  * This sample defines a transfer-element data structure, which
  9.  * contains the element's transfer size and low-order 32 bytes of the effective
  10.  * address. Also defined in the structure, but not used by this sample,
  11.  * is the DMA-list stall-and-notify bit, which can be used to indicate
  12.  * that the MFC should suspend list execution after transferring a list
  13.  * element whose stall-and-notify bit is set.
  14.  */
  15.  
  16. #include <spu_mfcio.h>
  17.  
  18. struct dma_list_elem {
  19.     union {
  20.                 unsigned int all32;
  21.                 struct {
  22.                         unsigned nbytes: 31;
  23.                         unsigned stall:  1;
  24.                 } bits;
  25.     } size;
  26.     unsigned int ea_low;
  27. };
  28.  
  29. /*
  30. typedef struct mfc_list_element{
  31.         unsigned int notify;
  32.         unsigned int reserved;
  33.         unsigned int size;
  34.         unsigned int eal;
  35. } mfc_list_element_t;
  36. */
  37.  
  38. struct dma_list_elem list[16] __attribute__ ((aligned (8)));
  39.  
  40. void get_large_region(void *dst, unsigned int ea_low, unsigned int nbytes)
  41. {
  42.     unsigned int i = 0;
  43.     unsigned int tagid = 0;
  44.     unsigned int listsize;
  45.  
  46.     /* get_large_region
  47.      *    Use a single DMA list command request to transfer
  48.      *    a "large" memory region into LS. The total size to
  49.      *    be copied may be larger than the MFC's single element
  50.      *    transfer limit of 16kb.
  51.      */
  52.  
  53.     if (!nbytes)
  54.         return;
  55.  
  56.     while (nbytes > 0) {
  57.                 unsigned int sz;
  58.  
  59.                 sz = (nbytes < 16384) ? nbytes : 16384;
  60.                 list[i].size.all32 = sz;
  61.                 list[i].ea_low = ea_low;
  62.  
  63.                 nbytes -= sz;
  64.                 ea_low += sz;
  65.                 i++;
  66.     }
  67.  
  68.  
  69.     /* Specify the list size and initiate the list transfer */
  70.     listsize = i * sizeof(struct dma_list_elem);
  71.     spu_mfcdma32(dst, (unsigned int) &list[0], listsize, tagid, MFC_GETL_CMD);
  72. }