/alps/ipecamera

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to tests/dma/xilinx/xilinx_dma.sh

  • Committer: Suren A. Chilingaryan
  • Date: 2015-04-27 00:28:57 UTC
  • Revision ID: csa@suren.me-20150427002857-82fk6r3e8rfgy4wr
First stand-alone ipecamera implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/bash
2
 
 
3
 
BAR=0
4
 
USE=1
5
 
ITERATIONS=2
6
 
BUFFERS=16
7
 
 
8
 
function pci {
9
 
    PCILIB_PATH=`pwd`/..
10
 
    LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $*
11
 
}
12
 
 
13
 
 
14
 
function reset {
15
 
    pci -b $BAR -w 0 1
16
 
    usleep 1000
17
 
    pci -b $BAR -w 0 0
18
 
    pci -b $BAR -w 4 0
19
 
}
20
 
 
21
 
function read_cfg {
22
 
#    echo $1 1>&2
23
 
    pci -a config -r 0x$1 | awk '{ print $2; }'
24
 
}
25
 
 
26
 
function parse_config {
27
 
    info=0x`pci -b $BAR -r 0 | awk '{ print $2; }'`
28
 
    model=`printf "%X" $((info>>24))`
29
 
    if [ $model -eq 14 ]; then
30
 
        model="Xilinx Virtex-6"
31
 
    else
32
 
        model="Xilinx $model"
33
 
    fi
34
 
    version=$(((info >> 8) & 0xFF))
35
 
    data_width=$((16 * (2 ** ((info >> 16) & 0xF))))
36
 
    
37
 
    echo "$model, build $version, $data_width bits"
38
 
 
39
 
 
40
 
    next=`read_cfg 34 | cut -c 7-8`
41
 
 
42
 
    while [ $next -ne 0 ]; do
43
 
        cap=`read_cfg $next`
44
 
        capid=`echo $cap | cut -c 7-8`
45
 
        if [ $capid -eq 10 ]; then
46
 
            addr=`printf "%X" $((0x$next + 12))`
47
 
            pcie_link1=`read_cfg $addr`
48
 
            addr=`printf "%X" $((0x$next + 16))`
49
 
            pcie_link2=`read_cfg $addr`
50
 
 
51
 
            link_speed=$((((0x$pcie_link2 & 0xF0000) >> 16)))
52
 
            link_width=$((((0x$pcie_link2 & 0x3F00000) >> 20)))
53
 
 
54
 
            dev_link_speed=$((((0x$pcie_link1 & 0xF))))
55
 
            dev_link_width=$((((0x$pcie_link1 & 0x3F0) >> 4)))
56
 
        fi
57
 
        next=`echo $cap | cut -c 5-6`
58
 
    done
59
 
 
60
 
    echo "Link: PCIe gen$link_speed x$link_width"
61
 
    if [ $link_speed -ne $dev_link_speed -o $link_width -ne $dev_link_width ]; then
62
 
        echo " * But device capable of gen$dev_link_speed x$dev_link_width"
63
 
    fi
64
 
    
65
 
    info=0x`read_cfg 40`
66
 
    max_tlp=$((2 ** (5 + ((info & 0xE0) >> 5))))
67
 
    echo "TLP: 32 dwords (transfering 32 TLP per request)"
68
 
    if [ $max_tlp -ne 32 ]; then
69
 
        echo " * But device is able to transfer TLP up to $max_tlp bytes"
70
 
    fi
71
 
    
72
 
    # 2500 MT/s, but PCIe gen1 and gen2 uses 10 bit encoding
73
 
    speed=$((link_width * link_speed * 2500 / 10))
74
 
}
75
 
 
76
 
reset
77
 
parse_config
78
 
 
79
 
pci --enable-irq
80
 
pci --acknowledge-irq
81
 
 
82
 
pci --free-kernel-memory $USE
83
 
pci --alloc-kernel-memory $USE --type c2s -s $BUFFERS
84
 
bus=`pci --list-kernel-memory 00100001 | awk '{ print $4; }' | grep 00`
85
 
#ptr=`pci --list-kernel-memory 00100001 | awk '{ print $2; }' | grep 00`
86
 
 
87
 
# TLP size
88
 
pci -b $BAR -w 0x0C 0x20
89
 
# TLP count
90
 
pci -b $BAR -w 0x10 0x20
91
 
# Data
92
 
pci -b $BAR -w 0x14 0x13131313
93
 
 
94
 
dmaperf=0
95
 
for i in `seq 1 $ITERATIONS`; do
96
 
  for addr in $bus; do 
97
 
    pci -b $BAR -w 0x08 0x$addr
98
 
 
99
 
#Trigger
100
 
    pci -b $BAR -w 0x04 0x01
101
 
    pci --wait-irq
102
 
#    pci -b $BAR -w 0x04 0x00
103
 
 
104
 
    status=`pci -b $BAR -r 0x04 | awk '{print $2; }' | cut -c 5-8`
105
 
    if [ $status != "0101" ]; then
106
 
        echo "Read failed, invalid status: $status"
107
 
    fi
108
 
 
109
 
    dmaperf=$((dmaperf + 0x`pci -b $BAR -r 0x28 | awk '{print $2}'`))
110
 
    reset
111
 
  done
112
 
done
113
 
 
114
 
pci --free-kernel-memory $USE
115
 
pci --disable-irq
116
 
 
117
 
echo
118
 
# Don't ask me about this formula
119
 
echo "Performance reported by FPGA: $((4096 * BUFFERS * ITERATIONS * $speed / $dmaperf / 8)) MB/s"
120
 
 
121
 
#pci -b $BAR  -r 0 -s 32