Commit d1acc791 authored by Federico Vaga's avatar Federico Vaga

Merge remote-tracking branch 'sw/master'

parents b3454979 e09d458f
*.o
*.ko
*.mod.c
.*.o.cmd
.*.ko.cmd
*.mod.d
*.o.d
*.tmp
.tmp_versions
modules.order
Module.symvers
\#*
*~
# Change Log
## [0.9.0] - 2017-10-13
### Added
- unittest
### Fixes
- add missing header in the repository
- add delay in the unlocking sequence
## [0.8.0] - 2017-10-12
### Added
- char device to program the Application FPGA
- sysfs attribute to unlock programming
- documentation!
## [0.0.0] - 2017-09-28
### Added
- basic Linux device driver
\ No newline at end of file
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
svec
Copyright (C) 2017 cohtdrivers
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 of the License, or
(at your option) any later version.
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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
-include Makefile.specific
# include parent_common.mk for buildsystem's defines
#use absolute path for REPO_PARENT
REPO_PARENT ?= $(shell /bin/pwd)/..
-include $(REPO_PARENT)/parent_common.mk
DIRS = kernel doc
.PHONY: all clean modules install modules_install $(DIRS)
all clean modules install modules_install: $(DIRS)
clean: TARGET = clean
modules: TARGET = modules
install: TARGET = install
modules_install: TARGET = modules_install
$(DIRS):
$(MAKE) -C $@ $(TARGET)
.. image:: ./doc/svec-logo.png
SVEC Driver
===========
This is the simplified version of the SVEC driver which only purpose is
to export an interface to enable the users to program their bitstream on
the SVEC FPGA.
Build Sources
=============
In order to be able to build this SVEC driver you need the VMEBUS sources
at hand, otherwise you cannot compile the kernel sources.
The documentation is written in reStructuredText and it generates HTML files
and man pages. For this you need the python docutils package installed
If the requirements are satified you can run the following commant in
the project root directory:
.. code::
make VMEBUS=/path/to/vmebus/
Futuristic Vision
=================
Actually this is not a driver for the SVEC card but for that little gateware
core in the SVEC bootloader FPGA. In the future we can think about standardize
other designs around this concept. Then this driver will become the FPGA
programmer driver for a set of devices.
*.man
*.html
*.pdf
\ No newline at end of file
MANUAL=svec-device
all: img doc
doc: html man
html:
rst2html $(MANUAL).rst > $(MANUAL).html
man:
rst2man --syntax-highlight=none $(MANUAL).rst > $(MANUAL).man
img: svec-logo.png
svec-logo.png: svec-logo.svg
inkscape -f $< -e $@
clean:
rm -f *.html *.man *.png
====
SVEC
====
---------------------------------------------
programming application FPGA
---------------------------------------------
:Author: Federico Vaga <federico.vaga@cern.ch>
:organization: CERN
:Date: 2017-10-12
:Copyright: GNU GPL, version 2 or any later version
:Version: 0.9.0
:Manual section: 4
:Manual group: CERN BECOHT Toolkit
Description
===========
The file ``/dev/svec.[0-N]`` is a character device, usually of mode 0440
and owner root:root. The number ``[0-N]`` represents a *SVEC Module* instance.
It is used to program the *Application FPGA* of a `SVEC module`_ on the VME bus.
The programming procedure consists in taking an FPGA bit-stream from the user
and writing it in the Application FPGA on the SVEC Module.
Once the device has been closed the Application FPGA become active and,
if valid, it will run the FPGA bit-stream provided by the user.
In order to prevent accidental programming, the Application FPGA programming
procedure is protected by the sysfs attribute ``AFPGA/lock``, usually of mode
0644 and owner root:root. On read it returns a string representing the current
locking status. On write it accepts only the strings:
- "unlock" to unlock the programming procedure.
- "lock" to lock the programming procedure
Once the programming procedure has been completed, the device go back to the
locking status.
The complete programming procedure is:
#. unlock the programming procedure by writing "unlock" in ``AFPGA/lock``
#. write the FPGA bit-stream in the character device ``/dev/svec.<N>``
Files
=====
/dev/svec.[0-N]
/sys/bus/vme/device/vme.[0-N]/svec/svec.[0-N]/AFPGA/lock
.. _`SVEC module`: https://www.ohwr.org/projects/svec/
Examples
========
.. code:: sh
echo "unlock" > /sys/bus/vme/devices/vme.8/svec/svec.8/AFPGA/lock
dd if=/path/to/bitstream.bin of=/dev/svec.8
.. code:: sh
echo "unlock" > /sys/bus/vme/devices/vme.8/svec/svec.8/AFPGA/lock
cat /path/to/bitstream.bin > /dev/svec.8
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="61.325069mm"
height="30.285677mm"
viewBox="0 0 61.325069 30.285677"
version="1.1"
id="svg8"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
sodipodi:docname="svec-logo.svg">
<defs
id="defs2">
<pattern
inkscape:collect="always"
xlink:href="#Strips1_1"
id="pattern6282"
patternTransform="matrix(10.797808,0,0,10.925543,-5.9115722,-10.514179)" />
<pattern
inkscape:stockid="Stripes 1:1"
id="Strips1_1"
patternTransform="translate(0,0) scale(10,10)"
height="1"
width="2"
patternUnits="userSpaceOnUse"
inkscape:collect="always">
<rect
id="rect5563"
height="2"
width="1"
y="-0.5"
x="0"
style="fill:black;stroke:none" />
</pattern>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="98.155692"
inkscape:cy="242.73542"
inkscape:document-units="mm"
inkscape:current-layer="layer3"
showgrid="false"
inkscape:window-width="1045"
inkscape:window-height="747"
inkscape:window-x="858"
inkscape:window-y="251"
inkscape:window-maximized="0" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="module"
style="display:inline"
transform="translate(-37.920465,-96.604592)">
<rect
style="fill:#008000;fill-opacity:1;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.06060606;paint-order:markers fill stroke"
id="rect4558"
width="61.192772"
height="15.032468"
x="37.98661"
y="111.79166" />
<g
id="g4601">
<rect
y="100.4505"
x="38.139359"
height="26.193871"
width="28.987604"
id="rect4511-0-5"
style="display:inline;fill:#008000;fill-opacity:1;stroke:#000000;stroke-width:0.09502652;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke" />
<g
id="g4593">
<rect
style="fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke"
id="rect4560"
width="3.7797618"
height="3.7797618"
x="38.139359"
y="96.670738" />
<rect
style="display:inline;fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke"
id="rect4560-2"
width="3.7797618"
height="3.7797618"
x="63.347206"
y="96.670738" />
<rect
style="display:inline;fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke"
id="rect4560-0"
width="3.7797618"
height="3.7797618"
x="46.541973"
y="96.670738" />
<rect
style="display:inline;fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke"
id="rect4560-5"
width="3.7797618"
height="3.7797618"
x="54.944592"
y="96.670738" />
</g>
</g>
<g
transform="translate(32.052422,0.17975616)"
style="display:inline"
id="g4601-5">
<rect
y="100.4505"
x="38.139359"
height="26.193871"
width="28.987604"
id="rect4511-0-5-2"
style="display:inline;fill:#008000;fill-opacity:1;stroke:#000000;stroke-width:0.09502652;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke" />
<g
id="g4593-9">
<rect
style="fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke"
id="rect4560-02"
width="3.7797618"
height="3.7797618"
x="38.139359"
y="96.670738" />
<rect
style="display:inline;fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke"
id="rect4560-2-8"
width="3.7797618"
height="3.7797618"
x="63.347206"
y="96.670738" />
<rect
style="display:inline;fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke"
id="rect4560-0-3"
width="3.7797618"
height="3.7797618"
x="46.541973"
y="96.670738" />
<rect
style="display:inline;fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:0.13229166;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.11616163;paint-order:markers fill stroke"
id="rect4560-5-8"
width="3.7797618"
height="3.7797618"
x="54.944592"
y="96.670738" />
</g>
</g>
</g>
<g
inkscape:groupmode="layer"
id="layer3"
inkscape:label="cloud"
transform="translate(-37.920465,-96.604592)">
<path
style="opacity:0.95400002;fill:#ffffff;fill-opacity:0.92929293;stroke:url(#pattern6282);stroke-width:0.1401132;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.04545456;paint-order:markers fill stroke"
d="m 96.543104,119.10787 c 8e-6,6.10384 -0.102199,7.76776 -27.627573,7.69409 -28.442888,-0.0761 -28.494238,-1.59025 -28.49423,-7.69409 6e-6,-6.10383 12.563297,-11.05197 28.060901,-11.05197 15.497604,0 28.060896,4.94813 28.060902,11.05197 z"
id="path4639"
inkscape:connector-curvature="0"
sodipodi:nodetypes="sssss" />
</g>
<g
inkscape:label="text"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-37.920465,-96.604592)">
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10.58333302px;line-height:6.61458302px;font-family:monospace;-inkscape-font-specification:'monospace, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
x="44.979176"
y="124.03809"
id="text4506"><tspan
sodipodi:role="line"
id="tspan4504"
x="44.979176"
y="124.03809"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:16.93333244px;font-family:'Latin Modern Mono Prop Light';-inkscape-font-specification:'Latin Modern Mono Prop Light, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458332px">SVEC</tspan></text>
</g>
</svg>
# add versions of supermodule. It is useful when svec-sw is included as sub-module
# of a bigger project that we want to track
ifdef CONFIG_SUPER_REPO
ifdef CONFIG_SUPER_REPO_VERSION
SUBMODULE_VERSIONS += MODULE_INFO(version_$(CONFIG_SUPER_REPO),\"$(CONFIG_SUPER_REPO_VERSION)\");
endif
endif
# add versions of used submodules
ccflags-y += -DADDITIONAL_VERSIONS="$(SUBMODULE_VERSIONS)"
ccflags-y += -DGIT_VERSION=\"$(GIT_VERSION)\"
ccflags-y += -I$(VMEBRIDGE_ABS)/include -I$(FPGA_MGR_ABS)/include
KBUILD_EXTRA_SYMBOLS += $(VMEBRIDGE_ABS)/driver/Module.symvers
KBUILD_EXTRA_SYMBOLS += $(FPGA_MGR_ABS)/drivers/fpga/Module.symvers
obj-m := svec.o
svec-objs := svec-core.o
# include parent_common.mk for buildsystem's defines
#use absolute path for REPO_PARENT
REPO_PARENT ?= $(shell /bin/pwd)/../..
-include $(REPO_PARENT)/parent_common.mk
LINUX ?= /lib/modules/$(shell uname -r)/build
VMEBRIDGE_ABS ?= $(abspath $(VMEBRIDGE))
FPGA_MGR_ABS ?= $(abspath $(FPGA_MGR))
GIT_VERSION = $(shell git describe --dirty --long --tags)
export GIT_VERSION
all: modules
.PHONY: all modules clean help install modules_install
modules help install modules_install:
$(MAKE) -C $(LINUX) M=$(shell pwd) GIT_VERSION=$(GIT_VERSION) VMEBRIDGE_ABS=$(VMEBRIDGE_ABS) FPGA_MGR_ABS=$(FPGA_MGR_ABS) $@
# be able to run the "clean" rule even if $(LINUX) is not valid
clean:
rm -rf *.o *~ .*.cmd *.ko *.mod.c .tmp_versions Module.symvers \
Module.markers modules.order
/*
Register definitions for slave core: Xilinx FPGA loader
* File : xloader_regs.h
* Author : auto-generated by wbgen2 from xloader_wb.wb
* Created : Thu Jun 21 15:17:30 2012
* Standard : ANSI C
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE xloader_wb.wb
DO NOT HAND-EDIT UNLESS IT'S ABSOLUTELY NECESSARY!
*/
#ifndef __WBGEN2_REGDEFS_XLOADER_WB_WB
#define __WBGEN2_REGDEFS_XLOADER_WB_WB
#if defined( __GNUC__)
#define PACKED __attribute__ ((packed))
#else
#error "Unsupported compiler?"
#endif
#ifndef __WBGEN2_MACROS_DEFINED__
#define __WBGEN2_MACROS_DEFINED__
#define WBGEN2_GEN_MASK(offset, size) (((1<<(size))-1) << (offset))
#define WBGEN2_GEN_WRITE(value, offset, size) (((value) & ((1<<(size))-1)) << (offset))
#define WBGEN2_GEN_READ(reg, offset, size) (((reg) >> (offset)) & ((1<<(size))-1))
#define WBGEN2_SIGN_EXTEND(value, bits) (((value) & (1<<bits) ? ~((1<<(bits))-1): 0 ) | (value))
#endif
/* definitions for register: Control/status register */
/* definitions for field: Start configuration in reg: Control/status register */
#define XLDR_CSR_START WBGEN2_GEN_MASK(0, 1)
/* definitions for field: Configuration done in reg: Control/status register */
#define XLDR_CSR_DONE WBGEN2_GEN_MASK(1, 1)
/* definitions for field: Configuration error in reg: Control/status register */
#define XLDR_CSR_ERROR WBGEN2_GEN_MASK(2, 1)
/* definitions for field: Loader busy in reg: Control/status register */
#define XLDR_CSR_BUSY WBGEN2_GEN_MASK(3, 1)
/* definitions for field: Byte order select in reg: Control/status register */
#define XLDR_CSR_MSBF WBGEN2_GEN_MASK(4, 1)
/* definitions for field: Software resest in reg: Control/status register */
#define XLDR_CSR_SWRST WBGEN2_GEN_MASK(5, 1)
/* definitions for field: Exit bootloader mode in reg: Control/status register */
#define XLDR_CSR_EXIT WBGEN2_GEN_MASK(6, 1)
/* definitions for field: Serial clock divider in reg: Control/status register */
#define XLDR_CSR_CLKDIV_MASK WBGEN2_GEN_MASK(8, 6)
#define XLDR_CSR_CLKDIV_SHIFT 8
#define XLDR_CSR_CLKDIV_W(value) WBGEN2_GEN_WRITE(value, 8, 6)
#define XLDR_CSR_CLKDIV_R(reg) WBGEN2_GEN_READ(reg, 8, 6)
/* definitions for register: Bootloader Trigger Register */
/* definitions for register: GPIO Output Register */
/* definitions for register: ID Register */
/* definitions for register: FIFO 'Bitstream FIFO' data input register 0 */
/* definitions for field: Entry size in reg: FIFO 'Bitstream FIFO' data input register 0 */
#define XLDR_FIFO_R0_XSIZE_MASK WBGEN2_GEN_MASK(0, 2)
#define XLDR_FIFO_R0_XSIZE_SHIFT 0
#define XLDR_FIFO_R0_XSIZE_W(value) WBGEN2_GEN_WRITE(value, 0, 2)
#define XLDR_FIFO_R0_XSIZE_R(reg) WBGEN2_GEN_READ(reg, 0, 2)
/* definitions for field: Last xfer in reg: FIFO 'Bitstream FIFO' data input register 0 */
#define XLDR_FIFO_R0_XLAST WBGEN2_GEN_MASK(2, 1)
/* definitions for register: FIFO 'Bitstream FIFO' data input register 1 */
/* definitions for field: Data in reg: FIFO 'Bitstream FIFO' data input register 1 */
#define XLDR_FIFO_R1_XDATA_MASK WBGEN2_GEN_MASK(0, 32)
#define XLDR_FIFO_R1_XDATA_SHIFT 0
#define XLDR_FIFO_R1_XDATA_W(value) WBGEN2_GEN_WRITE(value, 0, 32)
#define XLDR_FIFO_R1_XDATA_R(reg) WBGEN2_GEN_READ(reg, 0, 32)
/* definitions for register: FIFO 'Bitstream FIFO' control/status register */
/* definitions for field: FIFO full flag in reg: FIFO 'Bitstream FIFO' control/status register */
#define XLDR_FIFO_CSR_FULL WBGEN2_GEN_MASK(16, 1)
/* definitions for field: FIFO empty flag in reg: FIFO 'Bitstream FIFO' control/status register */
#define XLDR_FIFO_CSR_EMPTY WBGEN2_GEN_MASK(17, 1)
/* definitions for field: FIFO clear in reg: FIFO 'Bitstream FIFO' control/status register */
#define XLDR_FIFO_CSR_CLEAR_BUS WBGEN2_GEN_MASK(18, 1)
/* definitions for field: FIFO counter in reg: FIFO 'Bitstream FIFO' control/status register */
#define XLDR_FIFO_CSR_USEDW_MASK WBGEN2_GEN_MASK(0, 8)
#define XLDR_FIFO_CSR_USEDW_SHIFT 0
#define XLDR_FIFO_CSR_USEDW_W(value) WBGEN2_GEN_WRITE(value, 0, 8)
#define XLDR_FIFO_CSR_USEDW_R(reg) WBGEN2_GEN_READ(reg, 0, 8)
/* [0x0]: REG Control/status register */
#define XLDR_REG_CSR 0x00000000
/* [0x4]: REG Bootloader Trigger Register */
#define XLDR_REG_BTRIGR 0x00000004
/* [0x8]: REG GPIO Output Register */
#define XLDR_REG_GPIOR 0x00000008
/* [0xc]: REG ID Register */
#define XLDR_REG_IDR 0x0000000c
/* [0x10]: REG FIFO 'Bitstream FIFO' data input register 0 */
#define XLDR_REG_FIFO_R0 0x00000010
/* [0x14]: REG FIFO 'Bitstream FIFO' data input register 1 */
#define XLDR_REG_FIFO_R1 0x00000014
/* [0x18]: REG FIFO 'Bitstream FIFO' control/status register */
#define XLDR_REG_FIFO_CSR 0x00000018
#endif
/*
* SPDX-License-Identifier: GPLv2
*
* Copyright (C) 2017 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@cern.ch>
*
* Based on the SVEC version of:
* Author: Juan David Gonzalez Cobas <dcobas@cern.ch>
* Author: Luis Fernando Ruiz Gago <lfruiz@cern.ch>
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU GPL, version 2 or any later version
*
* Driver for SVEC (Simple VME FMC carrier) board.
*/
#include <linux/bitmap.h>
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/firmware.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/jhash.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
#include <linux/fpga/fpga-mgr.h>
#include <vmebus.h>
#include "hw/xloader_regs.h"
#define SVEC_BASE_LOADER 0x70000
static void svec_csr_write(u8 value, void *base, u32 offset)
{
offset -= offset % 4;
iowrite32be(value, base + offset);
}
/**
* Byte sequence to unlock and clear the Application FPGA
*/
static const uint32_t boot_unlock_sequence[8] = {
0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0xba, 0xbe
};
/**
* struct svec_dev - SVEC instance
* It describes a SVEC device instance.
* @vdev VME device instance
* @bitstream_last_word last data to write into the FPGA
* @bistream_last_word_size last data size to write in the FPGA. This is a dirty
* and ugly hack in order to properly handle a dirty
* and ugly interface. The SVEC bootloader does not
* accept emtpy transfers and neither to declare the
* transmission over without sending data.
* @fpgA_status state of the Application FPGA
* The user must lock the spinlock `lock` when using the following variables in
* this data structure: flags.
*/
struct svec_dev {
struct vme_dev *vdev;
char name[8];
uint32_t bitstream_last_word;
uint32_t bitstream_last_word_size;
enum fpga_mgr_states fpga_status;
};
/**
* Writes a "magic" unlock sequence, activating the System FPGA bootloader
* regardless of what is going on in the Application FPGA. This clears
* the Application FPGA as well by resetting the FPGA chip.
* @svec a valid SVEC device instance
* Return: 0 on success, otherwise a negative errno number
*/
static int svec_fpga_reset(struct fpga_manager *mgr)
{
struct svec_dev *svec = mgr->priv;
void *loader_addr = svec->vdev->map_cr.kernel_va + SVEC_BASE_LOADER;
int i;
for (i = 0; i < 8; i++) {
iowrite32be(boot_unlock_sequence[i],
loader_addr + XLDR_REG_BTRIGR);
mdelay(1);
}
return 0;
}
/**
* Checks if the SVEC is in bootloader mode. If true, it implies that
* the Appliocation FPGA has no bitstream loaded.
* @svec a valid SVEC device instance
* Return: 1 if it is active (unlocked), 0 if it is not active (locked),
* otherwise a negative errno number
*/
static int svec_fpga_loader_is_active(struct fpga_manager *mgr)
{
struct svec_dev *svec = mgr->priv;
void *loader_addr = svec->vdev->map_cr.kernel_va + SVEC_BASE_LOADER;
char buf[5];
uint32_t idc;
idc = ioread32be(loader_addr + XLDR_REG_IDR);
idc = htonl(idc);
memset(buf, 0, 5);
strncpy(buf, (char *)&idc, 4);
return (strncmp(buf, "SVEC", 4) == 0);
}
/**
* It is usable only when there is a valid CR/CSR space mapped
* @mgr FPGA manager instance
* @word the bytes to write
* @size the number of valid bytes in the word
* @is_last 1 if this is the last word of a bitstream
* Return 0 on success, otherwise a negative errno number.
* EAGAIN the loader FIFO was temporary full, retry
* EINVAL invalid size
*/
static int svec_fpga_write_word(struct fpga_manager *mgr,
const uint32_t word, ssize_t size,
unsigned int is_last)
{
struct svec_dev *svec = mgr->priv;
void *loader_addr = svec->vdev->map_cr.kernel_va + SVEC_BASE_LOADER;
uint32_t xldr_fifo_r0; /* Bitstream data input control register */
uint32_t xldr_fifo_r1; /* Bitstream data input register */
int rv, try = 10000;
static int cnt = 0;
if (size <= 0 || size >= 5) {
return -EINVAL;
}
xldr_fifo_r0 = ((size - 1) & 0x3) | (is_last ? XLDR_FIFO_R0_XLAST : 0);
xldr_fifo_r1 = htonl(word);
do {
rv = ioread32be(loader_addr + XLDR_REG_FIFO_CSR);
} while (rv & XLDR_FIFO_CSR_FULL && --try >= 0);
if(rv & XLDR_FIFO_CSR_FULL)
return -EBUSY; /* bootloader busy */
iowrite32be(xldr_fifo_r0, loader_addr + XLDR_REG_FIFO_R0);
iowrite32be(xldr_fifo_r1, loader_addr + XLDR_REG_FIFO_R1);
cnt++;
return 0;
}
/**
* It starts the programming procedure
* It is usable only when there is a valid CR/CSR space mapped
* @mgr FPGA manager instance
* Return 0 on success, otherwise a negative errno number.
*/
static int svec_fpga_write_start(struct fpga_manager *mgr)
{
struct svec_dev *svec = mgr->priv;
void *loader_addr = svec->vdev->map_cr.kernel_va + SVEC_BASE_LOADER;
int err, succ;
/* reset the FPGA */
err = svec_fpga_reset(mgr);
if (err) {
dev_err(&mgr->dev, "FPGA reset failed\n");
goto err_reset;
}
/* check if the FPGA loader is active */
succ = svec_fpga_loader_is_active(mgr);
if (!succ) {
dev_err(&mgr->dev, "FPGA loader unavailable\n");
err = -ENXIO;
goto err_active;
}
/* Reset the Xilinx Passive Serial boot interface */
iowrite32be(XLDR_CSR_SWRST,
loader_addr + XLDR_REG_CSR);
/* Start configuration process by providing BigEndian data */
iowrite32be(XLDR_CSR_START | XLDR_CSR_MSBF,
loader_addr + XLDR_REG_CSR);
err_active:
err_reset:
return err;
}
/**
* It starts the programming procedure.
* It is usable only when there is a valid CR/CSR space mapped
* @mgr FPGA manager instance
* Return 0 on success, otherwise a negative errno number
*/
static int svec_fpga_write_stop(struct fpga_manager *mgr,
struct fpga_image_info *info)
{
struct svec_dev *svec = mgr->priv;
void *loader_addr = svec->vdev->map_cr.kernel_va + SVEC_BASE_LOADER;
u64 timeout;
int rval = 0, err;
err = svec_fpga_write_word(mgr,
svec->bitstream_last_word,
svec->bitstream_last_word_size,
1);
if (err == -EINVAL)
err = 0;
if (err)
goto out;
/* Reset the bitstream programming words */
svec->bitstream_last_word = -1;
svec->bitstream_last_word_size = -1;
/* Two seconds later */
timeout = get_jiffies_64() + usecs_to_jiffies(info->config_complete_timeout_us);
while (time_before64(get_jiffies_64(), timeout)) {
rval = ioread32be(loader_addr + XLDR_REG_CSR);
if (rval & XLDR_CSR_DONE)
break;
msleep(1);
}
if (!(rval & XLDR_CSR_DONE)) {
dev_err(&mgr->dev, "error: FPGA program timeout.\n");
err = -EIO;
}
if (rval & XLDR_CSR_ERROR) {
dev_err(&mgr->dev, "Bitstream loaded, status ERROR\n");
err = -EINVAL;
}
out:
/* give the VME bus control to App FPGA */
iowrite32be(XLDR_CSR_EXIT, loader_addr + XLDR_REG_CSR);
/* give the VME core a little while to settle up */
msleep(10);
return err;
}
/**
* It writes the given buffer into the FPGA
* @mgr FPGA manager instance
* @buf data buffer to write
* @size buffer size
* Return the number of written bytes on success (greater or equal to zero),
* otherwise a negative errno number
*/
static size_t svec_fpga_write_buf(struct fpga_manager *mgr,
const void *buf, size_t size)
{
struct svec_dev *svec = mgr->priv;
const uint32_t *data = buf;
int i, err = 0;
i = 0;
while (i < size) {
err = svec_fpga_write_word(mgr,
svec->bitstream_last_word,
svec->bitstream_last_word_size,
0);
if (err && !(err == -EINVAL && i == 0))
goto out;
/*
* EINVAL is "fine" here because the first time we give a
* wrong size in order to have a working hack
*/
svec->bitstream_last_word = data[i >> 2];
svec->bitstream_last_word_size = (size - i > 4 ? 4 : size - i);
i += svec->bitstream_last_word_size;
}
err = 0;
out:
return err;
}
static enum fpga_mgr_states svec_fpga_state(struct fpga_manager *mgr)
{
return mgr->state;
}
static int svec_fpga_write_init(struct fpga_manager *mgr,
struct fpga_image_info *info,
const char *buf, size_t count)
{
struct svec_dev *svec = mgr->priv;
/* Reset the bitstream programming words */
svec->bitstream_last_word = -1;
svec->bitstream_last_word_size = -1;
return svec_fpga_write_start(mgr);
}
static int svec_fpga_write(struct fpga_manager *mgr, const char *buf, size_t count)
{
return svec_fpga_write_buf(mgr, buf, count);
}
static int svec_fpga_write_complete(struct fpga_manager *mgr,
struct fpga_image_info *info)
{
return svec_fpga_write_stop(mgr, info);
}
static void svec_fpga_remove(struct fpga_manager *mgr)
{
/* do nothing */
}
static const struct fpga_manager_ops svec_fpga_ops = {
.initial_header_size = 0,
.state = svec_fpga_state,
.write_init = svec_fpga_write_init,
.write = svec_fpga_write,
.write_complete = svec_fpga_write_complete,
.fpga_remove = svec_fpga_remove,
};
#define SVEC_USER_CSR_INT_LEVEL 0x7FF5B
#define SVEC_USER_CSR_INT_VECTOR 0x7FF5F
static int svec_vme_init(struct svec_dev *svec)
{
struct vme_dev *vdev = svec->vdev;
int err;
err = vme_csr_enable(vdev, 0);
if (err)
return err;
/* Configure the SVEC VME interface */
svec_csr_write(vdev->irq_vector, vdev->map_cr.kernel_va,
SVEC_USER_CSR_INT_VECTOR);
svec_csr_write(vdev->irq_level, vdev->map_cr.kernel_va,
SVEC_USER_CSR_INT_LEVEL);
err = vme_csr_enable(vdev, 1);
if (err)
return err;
return 0;
}
/**
* It initialize a new SVEC instance
* @pdev correspondend Linux device instance
* @ndev (Deprecated) device number
* Return: 0 on success, otherwise a negative number correspondent to an errno
*/
static int svec_probe(struct device *dev, unsigned int ndev)
{
struct vme_dev *vdev = to_vme_dev(dev);
struct svec_dev *svec;
int err;
svec = kzalloc(sizeof(struct svec_dev), GFP_KERNEL);
if (!svec) {
err = -ENOMEM;
goto err;
}
svec->vdev = vdev;
svec->fpga_status = FPGA_MGR_STATE_UNKNOWN;
snprintf(svec->name, 8, "svec.%d", vdev->slot);
err = fpga_mgr_register(&svec->vdev->dev, svec->name,
&svec_fpga_ops, svec);
if (err)
goto err_fpga_reg;
svec_vme_init(svec);
return 0;
err_fpga_reg:
kfree(svec);
err:
dev_err(dev, "Failed to register SVEC device\n");
return err;
}
/**
* It removes a SVEC device instance
* @vdev Linux device pointer
* @ndev DEPRECATED Device instance
* Return: 0 on success, otherwise a negative errno number
*/
static int svec_remove(struct device *vdev, unsigned int ndev)
{
fpga_mgr_unregister(vdev);
return 0;
}
/**
* List of supported SVEC instances.
* Note that the CR space is part of the FPGA, so different FPGAs may have
* different IDs but they can be SVEC compatible. For example, and FMC-TDC
* bitstream for SVEC it is compatible even if it is a bitstream that drivers
* the FMC mezzanines as well.
* For the time being this case is not considered.
*/
static const struct vme_device_id svec_id_table[] = {
{"fmc-svec-a24", 0x00080030, 0x00000198, 0x00000001},
{"fmc-svec-a32", 0x00080030, 0x00000198, 0x00000001},
{"\0", 0, 0, 0},
};
static struct vme_driver svec_driver = {
.probe = svec_probe,
.remove = svec_remove,
.driver = {
.name = KBUILD_MODNAME,
},
.id_table = svec_id_table,
};
static int __init svec_init(void)
{
return vme_register_driver(&svec_driver, 0);
}
static void __exit svec_exit(void)
{
vme_unregister_driver(&svec_driver);
}
module_init(svec_init);
module_exit(svec_exit);
MODULE_AUTHOR("Federico Vaga <federico.vaga@cern.ch>");
MODULE_AUTHOR("Juan David Gonzalez Cobas <dcobas@cern.ch>");
MODULE_LICENSE("GPL v2");
MODULE_VERSION(GIT_VERSION);
MODULE_DESCRIPTION("svec driver");
ADDITIONAL_VERSIONS;
import os
import unittest
class SvecTestProgramming(unittest.TestCase):
def setUp(self):
slot = os.environ["VME_SLOT"]
self.file_path = "/sys/bus/vme/devices/vme.{}/svec/svec.{}/AFPGA/lock".format(slot, slot)
self.dev_path = "/dev/svec.{}".format(slot)
self.bitstream = os.environ["BITSTREAM"]
def test_01(self):
"""It writes a dummy FPGA bitstream"""
with open(self.file_path, "w") as f:
f.write("unlock")
with open(self.bitstream, "rb") as d:
with open(self.dev_path, "wb") as f:
f.write(d.read())
with open(self.file_path, "r") as f:
val = f.read().strip()
self.assertEqual(val, "locked")
import os
import random
import string
import unittest
class SvecTestProgrammingLock(unittest.TestCase):
def setUp(self):
slot = os.environ["VME_SLOT"]
self.file_path = "/sys/bus/vme/devices/vme.{}/svec/svec.{}/AFPGA/lock".format(slot, slot)
self.dev_path = "/dev/svec.{}".format(slot)
def test_01(self):
"""It flips the previous lock status"""
with open(self.file_path, "r") as f:
val = f.read().strip()
for i in range(2):
new = "lock" if val == "unlocked" else "unlock"
with open(self.file_path, "w") as f:
f.write(new)
with open(self.file_path, "r") as f:
val = f.read().strip()
self.assertEqual(val, "{}ed".format(new))
def test_02(self):
"""It writes invalid commands to the lock attribute"""
chars = (random.choice(string.ascii_uppercase) for _ in range(3))
with self.assertRaises(OSError):
with open(self.file_path) as f:
f.write(''.join(chars))
def test_03(self):
"""It unlocks the programming"""
with open(self.file_path, "w") as f:
f.write("unlock")
with open(self.file_path, "r") as f:
val = f.read().strip()
self.assertEqual(val, "unlocked")
# we should be able to open the device
with open(self.dev_path) as f:
pass
# It should lock automatically
with open(self.file_path, "r") as f:
val = f.read().strip()
self.assertEqual(val, "locked")
def test_04(self):
"""It locks the programming"""
with open(self.file_path, "w") as f:
f.write("lock")
with open(self.file_path, "r") as f:
val = f.read().strip()
self.assertEqual(val, "locked")
# we should not be able to open the device
with self.assertRaises(OSError):
f = open(self.dev_path)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment