diff --git a/ffa-acs-drv/COPYING b/ffa-acs-drv/COPYING new file mode 100644 index 0000000000000000000000000000000000000000..6d45519c8c6cc926a7d6d96ebc45de7226f66099 --- /dev/null +++ b/ffa-acs-drv/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, 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 Library 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. + + + Copyright (C) + + 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 St, 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. + + , 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 Library General +Public License instead of this License. diff --git a/ffa-acs-drv/Makefile b/ffa-acs-drv/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..d8d1dffb00829f7942788373da683506280f8d9c --- /dev/null +++ b/ffa-acs-drv/Makefile @@ -0,0 +1,73 @@ +## @file + # FFA ACS Kernel module Makefile + # + # This program is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License version 2 as + # published by the Free Software Foundation. + # + # 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, see . + # + # Copyright (C) 2021-2024 Arm Limited + # + # +## + +export CROSS_COMPILE ?= aarch64-linux-gnu- +export ARCH ?= arm64 + +# ACS Make commandline arguments +VERBOSITY ?= 3 +PLATFORM_NS_HYPERVISOR_PRESENT ?= 0 +PLATFORM_SPMC_EL ?= 2 +PLATFORM_SP_EL ?= 1 +SUITE ?= all +PLATFORM_FFA_V_1_0 ?= 0 +PLATFORM_FFA_V_1_1 ?= 0 +PLATFORM_FFA_V_ALL ?= 1 + +ACS_MACROS += -DVM1_COMPILE -DTARGET_LINUX +ACS_MACROS += -DVERBOSITY=$(VERBOSITY) +ACS_MACROS += -DPLATFORM_NS_HYPERVISOR_PRESENT=$(PLATFORM_NS_HYPERVISOR_PRESENT) +ACS_MACROS += -DPLATFORM_SPMC_EL=$(PLATFORM_SPMC_EL) +ACS_MACROS += -DPLATFORM_SP_EL=$(PLATFORM_SP_EL) +ACS_MACROS += -DSUITE=$(SUITE) +ACS_MACROS += -DPLATFORM_FFA_V_1_0=$(PLATFORM_FFA_V_1_0) +ACS_MACROS += -DPLATFORM_FFA_V_1_1=$(PLATFORM_FFA_V_1_1) +ACS_MACROS += -DPLATFORM_FFA_V_ALL=$(PLATFORM_FFA_V_ALL) + +#since we have copied the files locally +ACS_DIR ?= ./ +ACS_INCLUDE = -I$(PWD)/$(ACS_DIR)/val/inc -I$(PWD)/$(ACS_DIR)/common/inc -I$(PWD)/$(ACS_DIR)/pal_linux/inc -I$(PWD)/$(ACS_DIR)/test/common + +obj-m += ffa-acs.o +ffa-acs-objs += ffa_acs.o \ + ffa_acs_test.o \ + ffa_acs_val.o \ + ffa_acs_pal.o + +ccflags-y=$(ACS_MACROS) $(ACS_INCLUDE) -Wall -Werror + +all: +ifeq ($(KERNEL_SRC),) + echo " KERNEL_SRC variable should be set to kernel path " + exit 1 +else + echo "Kernel source is set to $(KERNEL_SRC)" +endif + + make -C $(KERNEL_SRC) M=$(PWD) modules + +modules_install: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules_install + +clean: + make -C $(KERNEL_SRC) M=$(PWD) clean + rm -rf build + find $(ACS_DIR) -type f -name "*.o" -delete + find $(ACS_DIR) -type f -name "*.o.cmd" -delete diff --git a/ffa-acs-drv/README.md b/ffa-acs-drv/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c207d87a665d1d7d973a432ec10199f5ebf355c2 --- /dev/null +++ b/ffa-acs-drv/README.md @@ -0,0 +1,65 @@ + +# FF-A ACS - Linux Kernel Module + +This document provides information on executing [ff-a-acs tests](https://github.com/ARM-software/ff-a-acs.git) from the Linux application. This needs Linux kernel module files to load FF-A ACS Test VM1 endpoint code at kernel level and run as part of Linux kernel. These files are hosted under ffa-acs-drv directory. The procedure to build and run FF-A tests with Linux is described here. + +## This release +- Release Version - v0.9 +- Maintained by [ff-a-acs](https://github.com/ARM-software/ff-a-acs.git) manitainers + +## Prerequisites +- Linux kernel source version 5.0 +- Linaro GCC tool chain 5.3 or above +- Build environment for AArch64 Linux kernel + +## Building the kernel module +Follow the below steps to create kernel module for VM1 endpoint code: + +* Checkout the sources: +1. mkdir ; cd +2. git clone https://git.gitlab.arm.com/linux-arm/linux-acs.git +3. git clone https://github.com/ARM-software/ff-a-acs.git + +* Porting steps for Linux kernel +1. Apply the /linux-acs/ffa-acs-drv/kernel/0001-FFA-ACS-Linux-v5.0.patch to your kernel-v5.0 source tree. +2. Build the kernel. + +* Build steps for FFA ACS kernel module +1. cd /linux-acs/ffa-acs-drv +2. Set CROSS_COMPILE to the ARM64 toolchain path. You may want to set additional env flags mentioned in **Option Information** to change the default values of the ACS Make variables. +3. Set KERNEL_SRC to the +4. ./setup.sh +5. ./linux_ffa_acs.sh + +* ffa-acs.ko file is generated for VM1 endpoint code.
+ +**Options information**:
+ 1. SUITE= is the sub test suite name specified in **test/** directory. The default value is -DSUITE=all
+ 2. VERBOSE=. Print verbosity level. Supported print levels are 1(INFO & above), 2(DEBUG & above), 3(TEST & above), 4(WARN & ERROR) and 5(ERROR). Default value is 3.
+ 3. PLATFORM_SPMC_EL=: EL number where the target SPMC component runs. Supported values are 1 and 2. The default value is 2.
+ 4. PLATFORM_SP_EL=: EL number where the test secure endpoints are expected to run. Supported values are 0 and 1. The default value is 1.
+ 5. PLATFORM_NS_HYPERVISOR_PRESENT=<0|1>: Does the system support the non-secure hypervisor component? 1 for yes, 0 for no. The default vaule is 0. System is expected to intergrate and load all the three of nonsecure test endpoints if the value is set to 1. Otherwise needs to use single non-secure test endpoint(vm1) which would act as NS OS kernel.
+ 6. PLATFORM_FFA_V_1_0=<0|1>: It runs only tests that are supported by the Arm FF-A v1.0 specification. The default value is 0.
+ 7. PLATFORM_FFA_V_1_1=<0|1>: It only tests the Arm FF-A v1.1 specifications as updates to Arm FF-A v1.0. The default value is 0.
+ 8. PLATFORM_FFA_V_ALL=<0|1>: It runs all tests that are supported by the Arm FF-A v1.1 specification. The default value is 1.
+ + +## Build the Linux Application +Perform below steps to generate ffa_acs executable file:
+1. cd /ffa-a-acs/linux_app/ +2. Export CROSS_COMPILE with the ARM64 toolchain path. +3. make + + +## Loading the kernel module +Before the FF-A ACS Linux application can run, load the FFA ACS kernel module using the +insmod command.
+ ``` + shell> insmod ffa-acs.ko + ``` +## Run the Linux application + +Run the FF-A ACS Linux application as below:
+``` + shell> ./ffa_acs +``` diff --git a/ffa-acs-drv/ffa_acs.c b/ffa-acs-drv/ffa_acs.c new file mode 100644 index 0000000000000000000000000000000000000000..7f6f11905478b3bd304c45ff04e3b58b3b44097a --- /dev/null +++ b/ffa-acs-drv/ffa_acs.c @@ -0,0 +1,84 @@ +/* + * FFA ACS Kernel module Main file. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021 Arm Limited + * + */ + +#include "ffa_acs.h" + +static int ffa_proc_open(struct inode *sp_inode, struct file *sp_file) +{ + return 0; +} + +static int ffa_proc_release(struct inode *sp_indoe, struct file *sp_file) +{ + return 0; +} + +static ssize_t ffa_proc_read(struct file *sp_file, char __user *buf, size_t size, loff_t *offset) +{ + return 0; +} + +static ssize_t ffa_proc_write(struct file *sp_file, const char __user *buf, + size_t size, loff_t *offset) +{ + val_main(); + + return size; +} +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0) +struct file_operations ffa_fops = { + .open = ffa_proc_open, + .read = ffa_proc_read, + .write = ffa_proc_write, + .release = ffa_proc_release +}; +#else +static const struct proc_ops ffa_fops = { + .proc_open = ffa_proc_open, + .proc_read = ffa_proc_read, + .proc_write = ffa_proc_write, + .proc_release = ffa_proc_release +}; +#endif + +/* Create proc entry for communication between user and kernel levels */ +static int __init init_ffa_acs(void) +{ + printk(KERN_INFO "\tInit FFA ACS driver \n"); + + if (!proc_create("ffa_acs", 0, NULL, &ffa_fops)) { + printk(KERN_ERR "ERROR! proc_create\n"); + remove_proc_entry("ffa_acs", NULL); + return -1; + } + + return 0; +} + +/* Remove the proc entry while unloading the driver */ +static void __exit exit_ffa_acs(void) +{ + remove_proc_entry("ffa_acs", NULL); + printk(KERN_INFO "Exit FFA ACS driver \n"); +} + +MODULE_INFO(intree, "Y"); +MODULE_LICENSE("GPL"); +module_init(init_ffa_acs); +module_exit(exit_ffa_acs); diff --git a/ffa-acs-drv/ffa_acs.h b/ffa-acs-drv/ffa_acs.h new file mode 100644 index 0000000000000000000000000000000000000000..5a6b54485883f0aebc70d59d5405086db34e4c6f --- /dev/null +++ b/ffa-acs-drv/ffa_acs.h @@ -0,0 +1,33 @@ +/* + * FFA ACS Kernel module header file. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021 Arm Limited + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "val_framework.h" +#include "val_memory.h" +#include "val_test_dispatch.h" + diff --git a/ffa-acs-drv/kernel/0001-FFA-ACS-Linux-v5.0.patch b/ffa-acs-drv/kernel/0001-FFA-ACS-Linux-v5.0.patch new file mode 100644 index 0000000000000000000000000000000000000000..de4eeefc19960f3ac837f63811a25a3c2e452891 --- /dev/null +++ b/ffa-acs-drv/kernel/0001-FFA-ACS-Linux-v5.0.patch @@ -0,0 +1,127 @@ +From 15344cc288ace34d29e4b3a82a3e4c29ebbf3720 Mon Sep 17 00:00:00 2001 +From: Mahesh Bireddy +Date: Fri, 29 Jul 2022 17:37:31 +0800 +Subject: [PATCH] FFA ACS Linux v5.0 + +Signed-off-by: Mahesh Bireddy +--- + arch/arm64/kernel/smp.c | 13 ++++++++++++- + drivers/irqchip/irq-gic-v3.c | 17 +++++++++++++++++ + include/linux/irqdomain.h | 3 +++ + kernel/irq/irqdomain.c | 1 + + 4 files changed, 33 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c +index 1598d6f72..40aff3581 100644 +--- a/arch/arm64/kernel/smp.c ++++ b/arch/arm64/kernel/smp.c +@@ -63,6 +63,7 @@ + #define CREATE_TRACE_POINTS + #include + ++#define FFA_ACS_SRI_INTERRUPT 8 + DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number); + EXPORT_PER_CPU_SYMBOL(cpu_number); + +@@ -82,7 +83,8 @@ enum ipi_msg_type { + IPI_CPU_CRASH_STOP, + IPI_TIMER, + IPI_IRQ_WORK, +- IPI_WAKEUP ++ IPI_WAKEUP, ++ IPI_FFA_SRI = FFA_ACS_SRI_INTERRUPT + }; + + #ifdef CONFIG_HOTPLUG_CPU +@@ -94,6 +96,11 @@ static inline int op_cpu_kill(unsigned int cpu) + } + #endif + ++/* ACS FFA patch */ ++static void acs_ffa_sri_handler(void) ++{ ++ return; ++} + + /* + * Boot a secondary CPU, and assign it the specified idle task. +@@ -889,6 +896,10 @@ void handle_IPI(int ipinr, struct pt_regs *regs) + } + break; + ++ case IPI_FFA_SRI: ++ acs_ffa_sri_handler(); ++ break; ++ + #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST + case IPI_TIMER: + irq_enter(); +diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c +index 0868a9d81..2cbd78adf 100644 +--- a/drivers/irqchip/irq-gic-v3.c ++++ b/drivers/irqchip/irq-gic-v3.c +@@ -69,6 +69,9 @@ static DEFINE_STATIC_KEY_TRUE(supports_deactivate_key); + static struct gic_kvm_info gic_v3_kvm_info; + static DEFINE_PER_CPU(bool, has_rss); + ++/* ACS GIC Patch */ ++struct irq_domain *acs_irq_domain = NULL; ++ + #define MPIDR_RS(mpidr) (((mpidr) & 0xF0UL) >> 4) + #define gic_data_rdist() (this_cpu_ptr(gic_data.rdists.rdist)) + #define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base) +@@ -98,6 +101,15 @@ static inline void __iomem *gic_dist_base(struct irq_data *d) + return NULL; + } + ++struct irq_domain* acs_get_irq_domain(void) ++{ ++ if (acs_irq_domain) ++ return acs_irq_domain; ++ ++ return NULL; ++} ++EXPORT_SYMBOL(acs_get_irq_domain); ++ + static void gic_do_wait_for_rwp(void __iomem *base) + { + u32 count = 1000000; /* 1s! */ +@@ -1000,6 +1012,11 @@ static int gic_irq_domain_alloc(struct irq_domain *domain, unsigned int virq, + return ret; + } + ++ /* ACS GIC Patch */ ++ if (domain) { ++ acs_irq_domain = domain; ++ } ++ + return 0; + } + +diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h +index 35965f41d..9610d55bc 100644 +--- a/include/linux/irqdomain.h ++++ b/include/linux/irqdomain.h +@@ -582,4 +582,7 @@ static inline bool irq_domain_check_msi_remap(void) + } + #endif /* !CONFIG_IRQ_DOMAIN */ + ++/* ACS GIC Patch */ ++struct irq_domain* acs_get_irq_domain(void); ++ + #endif /* _LINUX_IRQDOMAIN_H */ +diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c +index 8b0be4bd6..9d94c7ad2 100644 +--- a/kernel/irq/irqdomain.c ++++ b/kernel/irq/irqdomain.c +@@ -1332,6 +1332,7 @@ int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, + irq_free_descs(virq, nr_irqs); + return ret; + } ++EXPORT_SYMBOL(__irq_domain_alloc_irqs); + + /* The irq_data was moved, fix the revmap to refer to the new location */ + static void irq_domain_fix_revmap(struct irq_data *d) +-- +2.18.0 + diff --git a/ffa-acs-drv/linux_ffa_acs.sh b/ffa-acs-drv/linux_ffa_acs.sh new file mode 100755 index 0000000000000000000000000000000000000000..e9202a3502b0ef6a9ff622ec9e0fff27a5e4944e --- /dev/null +++ b/ffa-acs-drv/linux_ffa_acs.sh @@ -0,0 +1,53 @@ +#!/bin/bash +## + # + # This program is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License version 2 as + # published by the Free Software Foundation. + # + # 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, see . + # + # Copyright (C) 2021 Arm Limited + # +## + +echo "==================================================================" +echo "This script will compile the Linux FFA ACS Kernel module " +echo "==================================================================" + +FFA_ACS_PATH=`pwd` +if [ -z $KERNEL_SRC ] +then + echo "Error: set KERNEL_SRC path" + exit 0 +fi + +if [ -z $CROSS_COMPILE ] +then + echo "Error: set CROSS_COMPILE path" + exit 0 +fi + +cd $FFA_ACS_PATH/pal_linux +make clean +make +cp ffa_acs_pal.o $FFA_ACS_PATH/ + +cd $FFA_ACS_PATH/val/ +make clean +make +cp ffa_acs_val.o $FFA_ACS_PATH/ + +cd $FFA_ACS_PATH/test/ +make clean +make +cp ffa_acs_test.o $FFA_ACS_PATH/ + +cd $FFA_ACS_PATH/ +make diff --git a/ffa-acs-drv/pal_linux/Makefile b/ffa-acs-drv/pal_linux/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..8c3ae91776597015f9d218d7ad9dadf943bf3583 --- /dev/null +++ b/ffa-acs-drv/pal_linux/Makefile @@ -0,0 +1,77 @@ +## @file + # FFA ACS Kernel module Makefile + # + # This program is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License version 2 as + # published by the Free Software Foundation. + # + # 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, see . + # + # Copyright (C) 2021 Arm Limited + # + # +## + +export CROSS_COMPILE ?= aarch64-linux-gnu- +export ARCH ?= arm64 + +# ACS Make commandline arguments +VERBOSITY ?= 3 +PLATFORM_NS_HYPERVISOR_PRESENT ?= 0 +PLATFORM_SPMC_EL ?= 2 +PLATFORM_SP_EL ?= 1 +SUITE ?= all +PLATFORM_FFA_V_1_0 ?= 0 +PLATFORM_FFA_V_1_1 ?= 0 +PLATFORM_FFA_V_ALL ?= 1 + +ACS_MACROS += -DVM1_COMPILE -DTARGET_LINUX +ACS_MACROS += -DVERBOSITY=$(VERBOSITY) +ACS_MACROS += -DPLATFORM_NS_HYPERVISOR_PRESENT=$(PLATFORM_NS_HYPERVISOR_PRESENT) +ACS_MACROS += -DPLATFORM_SPMC_EL=$(PLATFORM_SPMC_EL) +ACS_MACROS += -DPLATFORM_SP_EL=$(PLATFORM_SP_EL) +ACS_MACROS += -DSUITE=$(SUITE) +ACS_MACROS += -DPLATFORM_FFA_V_1_0=$(PLATFORM_FFA_V_1_0) +ACS_MACROS += -DPLATFORM_FFA_V_1_1=$(PLATFORM_FFA_V_1_1) +ACS_MACROS += -DPLATFORM_FFA_V_ALL=$(PLATFORM_FFA_V_ALL) + +#since we have copied the files locally +ACS_DIR ?= . +PAL_SRC = $(ACS_DIR)/src + +ACS_INCLUDE = -I$(PWD)/$(ACS_DIR)/inc -I$(PWD)/$(ACS_DIR)/../common/inc +obj-m += ffa_acs_pal.o + +ffa_acs_pal-objs += $(PAL_SRC)/pal_driver.o \ + $(PAL_SRC)/pal_mmio.o \ + $(PAL_SRC)/pal_irq.o \ + $(PAL_SRC)/pal_smmuv3_testengine.o \ + $(PAL_SRC)/pal_vcpu_setup.o \ + $(PAL_SRC)/pal_misc.o + +ccflags-y=$(ACS_MACROS) $(ACS_INCLUDE) -Wall -Werror + +all: +ifeq ($(KERNEL_SRC),) + echo " KERNEL_SRC variable should be set to kernel path " + exit 1 +else + echo "Kernel source is set to $(KERNEL_SRC)" +endif + + make -C $(KERNEL_SRC) M=$(PWD) modules + +modules_install: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules_install + +clean: + make -C $(KERNEL_SRC) M=$(PWD) clean + find $(ACS_DIR) -type f -name "*.o" -delete + find $(ACS_DIR) -type f -name "*.o.cmd" -delete + diff --git a/ffa-acs-drv/pal_linux/inc/pal_arch_helpers.h b/ffa-acs-drv/pal_linux/inc/pal_arch_helpers.h new file mode 100644 index 0000000000000000000000000000000000000000..71b3d7846f588a157658bd31a902f88fa4c2d9fc --- /dev/null +++ b/ffa-acs-drv/pal_linux/inc/pal_arch_helpers.h @@ -0,0 +1,53 @@ +/* + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021 Arm Limited + * + */ + +#ifndef ARCH_HELPERS_H +#define ARCH_HELPERS_H + +#define MPIDR_MT_MASK (1 << 24) +#define MPIDR_AFFLVL_MASK 0xffUL +#define MPIDR_AFF0_SHIFT 0 +#define MPIDR_AFF1_SHIFT (8) +#define MPIDR_AFF2_SHIFT (16) +#define MPIDR_AFF3_SHIFT 32UL + +/* + * The MPIDR_MAX_AFFLVL count starts from 0. Take care to + * add one while using this macro to define array sizes. + * TODO: Support only the first 3 affinity levels for now. + */ +#define MPIDR_MAX_AFFLVL (2) + +#define MPID_MASK (MPIDR_MT_MASK | \ + (MPIDR_AFFLVL_MASK << MPIDR_AFF3_SHIFT) | \ + (MPIDR_AFFLVL_MASK << MPIDR_AFF2_SHIFT) | \ + (MPIDR_AFFLVL_MASK << MPIDR_AFF1_SHIFT) | \ + (MPIDR_AFFLVL_MASK << MPIDR_AFF0_SHIFT)) + +/* Define function for system instruction with type specifier */ +#define DEFINE_SYSOP_TYPE_FUNC(_op, _type) \ +static inline void _op ## _type(void) \ +{ \ + __asm__ (#_op " " #_type); \ +} + +DEFINE_SYSOP_TYPE_FUNC(dsb, sy) +DEFINE_SYSOP_TYPE_FUNC(dmb, sy) +DEFINE_SYSOP_TYPE_FUNC(dmb, st) + +#endif /* ARCH_HELPERS_H */ diff --git a/ffa-acs-drv/pal_linux/inc/pal_config_def.h b/ffa-acs-drv/pal_linux/inc/pal_config_def.h new file mode 100644 index 0000000000000000000000000000000000000000..97ea5f904d66fafb6037f7a9ea516edbde099764 --- /dev/null +++ b/ffa-acs-drv/pal_linux/inc/pal_config_def.h @@ -0,0 +1,113 @@ +/* + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021-2024 Arm Limited + * + */ + +#ifndef _PAL_CONFIG_H_ +#define _PAL_CONFIG_H_ + +#ifndef __ASSEMBLY__ +#include "pal_arch_helpers.h" +#endif + +#define PLATFORM_PAGE_SIZE 0x1000 + +#define PAGE_SIZE_4K 0x1000 +#define PAGE_SIZE_16K (4 * 0x1000) +#define PAGE_SIZE_64K (16 * 0x1000) + +/* Non-secure UART assigned to VM1 - PL011_UART2_BASE */ +#define PLATFORM_NS_UART_BASE 0x1c0b0000 +#define PLATFORM_NS_UART_SIZE 0x10000 + +/* Secure UART assigned to SP1 - PL011_UART2_BASE */ +#define PLATFORM_S_UART_BASE 0x1c0b0000 +#define PLATFORM_S_UART_SIZE 0x10000 + +/* Non-volatile memory range assigned to SP3 */ +#define PLATFORM_NVM_BASE (0x80000000+0x2800000) +#define PLATFORM_NVM_SIZE 0x10000 + +/* Base address of watchdog assigned to SP3 */ +#define PLATFORM_WDOG_BASE 0x1C0F0000 //(SP805) +#define PLATFORM_WDOG_SIZE 0x10000 +#define PLATFORM_WDOG_LOAD_VALUE (0x3E7 * 10 * 1000) // 10sec +#define PLATFORM_WD_INTR_NUM 32 + +/* Base address of trusted watchdog (SP805) */ +#define PLATFORM_SP805_TWDOG_BASE 0x2A490000 +#define PLATFORM_TWDOG_SIZE 0x10000 +#define PLATFORM_TWDOG_INTID 56 + +#define PLATFORM_NS_WD_BASE 0x2A440000 +#define PLATFORM_NS_WD_SIZE 0x1000 +#define PLATFORM_NS_WD_INTR 59 + +/* + * Base address of read only memory region + */ +#define PLATFORM_MEM_READ_ONLY_BASE 0xfe300000 +#define PLATFORM_MEM_READ_ONLY_SIZE 0x1000 + +/* SMMU upstream device memory region 8KB */ +#define PLAT_SMMU_UPSTREAM_DEVICE_MEM_REGION 0x78000000 + +/* SMMU stream id */ +#define PLATFORM_SMMU_STREAM_ID 1 + +/* + * Retrieving of memory region by specifying address ranges. + * this is about retrieving memory without handle value and + * specifying the offset field in the endpoint memory access descriptor. + * Supported values: 0(NOT_SUPPORTED), 1(SUPPORTED) + */ +#define PLATFORM_MEM_RETRIEVE_USING_ADDRESS_RANGES 0 + +/* INNER_SHAREBLE and OUTER_SHAREABLE flag support + * Supported values: 0(NOT_SUPPORTED), 1(SUPPORTED) + */ +#define PLATFORM_OUTER_SHAREABLE_SUPPORT_ONLY 0 +#define PLATFORM_INNER_SHAREABLE_SUPPORT_ONLY 1 +#define PLATFORM_INNER_OUTER_SHAREABLE_SUPPORT 0 + +/* + * Secure Partition manifest info. + */ + +/* Test Partition IDs assigned by the system */ +#define PLATFORM_SP1_ID (1 | (1 << 15)) +#define PLATFORM_SP2_ID (2 | (1 << 15)) +#define PLATFORM_SP3_ID (3 | (1 << 15)) +#define PLATFORM_SP4_ID (4 | (1 << 15)) + +#if (PLATFORM_NS_HYPERVISOR_PRESENT == 1) + #if (PLATFORM_PRIMARY_SCHEDULER_EL == 2) + #define PLATFORM_VM1_ID 1 + #define PLATFORM_VM2_ID 2 + #define PLATFORM_VM3_ID 3 + #elif (PLATFORM_PRIMARY_SCHEDULER_EL == 1) + // Assuming Primary scheduler ID = 1 + #define PLATFORM_VM1_ID 2 + #define PLATFORM_VM2_ID 3 + #define PLATFORM_VM3_ID 4 + #endif +#endif + +/* + * CPU info + */ +#define PLATFORM_NO_OF_CPUS 8 +#endif /* _PAL_CONFIG_H_ */ diff --git a/ffa-acs-drv/pal_linux/inc/pal_smmuv3_testengine.h b/ffa-acs-drv/pal_linux/inc/pal_smmuv3_testengine.h new file mode 100644 index 0000000000000000000000000000000000000000..cfc71134b147f255f2a004a14ba588d0255de3a3 --- /dev/null +++ b/ffa-acs-drv/pal_linux/inc/pal_smmuv3_testengine.h @@ -0,0 +1,114 @@ +/* + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021-2023 Arm Limited + * + */ + +#ifndef _PAL_SMMUV3_TESTENGINE_H_ +#define _PAL_SMMUV3_TESTENGINE_H_ + +#include "pal_interfaces.h" + +/* The register file consists of two pages, each of which is 64 KiB + * Page 0 : 'User' page + * 1 : 'Privileged' page + * + * Each page consists of a number of frames, each of which corresponds to an independent + * thread of work. + * Frame 0 in the User page corresponds to Frame 0 in the Priv page. + * Each Frame is 128 bytes long. + */ + +/* PCTRL bit 0 -- ssd-ns -- 1 if the stream belongs to the non-secure world. + * 0 if the stream belongs to the secure world + */ + +/* The engine memcpy's from region [begin, end_incl] to address udata[0]. + * + * If stride is 0 then ENGINE_ERROR is produced, udata[2] contains the error + * address. No MSI is generated. + * + * If stride is 1 then this is a normal memcpy(). If stride is larger then + * not all the data will be copied. + * + * The order and size of the transactions used are determined randomly using + * seed. If seed is: + * 0 -- do them from lowest address to highest address + * ~0u -- do them in reverse order + * otherwise use the value as a seed to do them in random order + * The ability to do them in a non-random order means that we stand a + * chance of getting merged event records. + * + * This models a work-load to start with some reads and then do some writes. + * ENGINE_MEMCPY = 2. + */ + +/* Poll 'cmd' until not being ENGINE_MEMCPY: + * - ENGINE_FRAME_MISCONFIGURED + * - ENGINE_ERROR + * - ENGINE_NO_FRAME + * - ENGINE_HALTED -- The engine is halted. All others are errors of one kind + * or another. + */ + +/* Privileged page base address */ +#define P_FRAME_BASE 0x2bff0000 +/* User page base address */ +#define U_FRAME_BASE 0x2bfe0000 +/* Each frame is 128 bytes long */ +#define FRAME_SIZE 0x80 + +/* Privileged frame fields */ +#define PCTRL 0x0 +#define DOWNSTREAM_PORT_INDEX 0x4 +#define STREAM_ID 0x8 +#define SUBSTREAM_ID 0xC + +/* User frame fields */ +#define CMD 0x0 +#define UCTRL 0x4 +#define SEED 0x24 +#define BEGIN 0x28 +#define END_CTRL 0x30 +#define STRIDE 0x38 +#define UDATA 0x40 + +#define NO_SUBSTREAMID 0xFFFFFFFF + +enum cmd_t { + /* The frame was misconfigured. */ + ENGINE_FRAME_MISCONFIGURED = ~0u - 1, + + /* The engine encountered an error (downstream transaction aborted). */ + ENGINE_ERROR = ~0u, + + /* This frame is unimplemented or in use by the secure world. + * + * A user _can_ write this to cmd and it will be considered to be ENGINE_HALTED. + */ + ENGINE_NO_FRAME = 0, + + /* The engine is halted. */ + ENGINE_HALTED = 1, + + /* This initiates memory transfer from source to destination */ + ENGINE_MEMCPY = 2 +}; + +/* Configures SMMU test engine and initiates DMA transfer from source address to destination */ +uint32_t smmuv3_configure_testengine(uint32_t stream_id, uint64_t source, uint64_t dest, + uint64_t size, bool secure); + +#endif /* _PAL_SMMUV3_TESTENGINE_H_ */ diff --git a/ffa-acs-drv/pal_linux/src/pal_driver.c b/ffa-acs-drv/pal_linux/src/pal_driver.c new file mode 100644 index 0000000000000000000000000000000000000000..0545afe9774786a7a7bdbcee2ba6c01974a3aad0 --- /dev/null +++ b/ffa-acs-drv/pal_linux/src/pal_driver.c @@ -0,0 +1,144 @@ +/* + * PSA FFA ACS Platform module. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021 Arm Limited + * + */ + +#include +#include +#include +#include +#include + +#include "pal_interfaces.h" +#include "pal_smmuv3_testengine.h" + +#define MSG_SIZE 80 + +uint32_t pal_printf(const char *msg, uint64_t data1, uint64_t data2) +{ + char buf[MSG_SIZE]; + + snprintf(buf, MSG_SIZE, msg, data1, data2); + printk("%s", buf); + + return PAL_SUCCESS; +} + +uint32_t pal_nvm_write(uint32_t offset, void *buffer, size_t size) +{ + /* Empty api - not in use */ + (void)offset; + (void)buffer; + (void)size; + return PAL_SUCCESS; +} + +uint32_t pal_nvm_read(uint32_t offset, void *buffer, size_t size) +{ + /* Empty api - not in use */ + (void)offset; + (void)buffer; + (void)size; + return PAL_SUCCESS; +} + +uint32_t pal_watchdog_enable(void) +{ + /* Empty api - not in use */ + return PAL_SUCCESS; +} + +uint32_t pal_watchdog_disable(void) +{ + /* Empty api - not in use */ + return PAL_SUCCESS; +} + +uint32_t pal_twdog_enable(uint32_t ms) +{ + /* Empty api - not in use */ + (void)ms; + return PAL_SUCCESS; +} + +uint32_t pal_twdog_disable(void) +{ + /* Empty api - not in use */ + return PAL_SUCCESS; +} + +void pal_twdog_intr_enable(void) +{ + /* Empty api - not in use */ + return; +} + +void pal_twdog_intr_disable(void) +{ + /* Empty api - not in use */ + return; +} + +void pal_ns_wdog_enable(uint32_t ms) +{ + pal_mmio_write32(PLATFORM_NS_WD_BASE + 0x8, ms); + pal_mmio_write32(PLATFORM_NS_WD_BASE, 1); +} + +void pal_ns_wdog_disable(void) +{ + pal_mmio_write32(PLATFORM_NS_WD_BASE, 0); +} + +void pal_ns_wdog_intr_enable(void) +{ + /* Empty api - not in use */ + return; +} + +void pal_ns_wdog_intr_disable(void) +{ + /* Empty api - not in use */ + return; +} + +uint64_t pal_sleep(uint32_t ms) +{ + /* Empty api - not in use */ + (void)ms; + return PAL_SUCCESS; +} + +void pal_secure_intr_enable(uint32_t int_id, enum interrupt_pin pin) +{ + /* Empty api - not in use */ + return; +} + +void pal_secure_intr_disable(uint32_t int_id, enum interrupt_pin pin) +{ + /* Empty api - not in use */ + return; +} + +uint32_t pal_smmu_device_configure(uint32_t stream_id, uint64_t source, uint64_t dest, + uint64_t size, bool secure) +{ + return smmuv3_configure_testengine(stream_id, source, dest, size, secure); +} + +MODULE_LICENSE("GPL"); diff --git a/ffa-acs-drv/pal_linux/src/pal_irq.c b/ffa-acs-drv/pal_linux/src/pal_irq.c new file mode 100644 index 0000000000000000000000000000000000000000..e4489ae137f831fa4b83b39c0307c67ea8951442 --- /dev/null +++ b/ffa-acs-drv/pal_linux/src/pal_irq.c @@ -0,0 +1,129 @@ +/* + * FF-A ACS Platform module. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021-2023 Arm Limited + * + * Author: Mahesh Bireddy + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pal_interfaces.h" +#include "pal_irq.h" + +static int8_t *dev = "FFA"; + +void pal_irq_setup(void) +{ + return; +} + +int pal_irq_handler_dispatcher(void) +{ + return 0; +} + +void pal_irq_enable(unsigned int irq_num, uint8_t irq_priority) +{ + return; +} + +void pal_irq_disable(unsigned int irq_num) +{ + return; +} + +int pal_irq_register_handler(unsigned int irq_num, handler_irq_t irq_handler) +{ + uint64_t flags = 0; + int32_t ret = 0; + int32_t virq; + struct irq_domain *domain = NULL; + struct irq_fwspec *fwspec; + + domain = acs_get_irq_domain(); + if (!domain) { + pal_printf("Domain is null\n", 0, 0); + return PAL_ERROR; + } + + fwspec = kmalloc(sizeof(struct irq_fwspec), GFP_KERNEL); + if (!fwspec) { + pal_printf("Fwspec allocation failed\n", 0, 0); + return PAL_ERROR; + } + + fwspec->param_count = 3; + fwspec->param[0] = 0; + /* Interrupt type LEVEL 0 EDGE RISING 1 */ + fwspec->param[1] = irq_num-32; + fwspec->param[2] = 4; + fwspec->fwnode = domain->fwnode; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0) + fwspec->fwnode->type = FWNODE_IRQCHIP; +#endif + + if (irq_domain_is_hierarchy(domain)) { + virq = __irq_domain_alloc_irqs(domain, -1, 1, NUMA_NO_NODE, fwspec, false, NULL); + if (virq <= 0) { + ret = PAL_ERROR; + goto error; + } + } else { + /* Create mapping */ + virq = irq_create_mapping(domain, irq_num); + if (!virq) { + ret = PAL_ERROR; + goto error; + } + } + + ret = request_irq(virq, (irq_handler_t)irq_handler, flags, "FFA", dev); + if (ret) { + pal_printf("ERROR: Cannot request IRQ %x err %d\n", irq_num, ret); + ret = PAL_ERROR; + goto error; + } + +error: + kfree(fwspec); + return ret; +} + +int pal_irq_unregister_handler(unsigned int irq_num) +{ + uint32_t virq; + struct irq_domain *domain = NULL; + + domain = acs_get_irq_domain(); + virq = irq_create_mapping(domain, irq_num); + free_irq(virq, dev); + irq_dispose_mapping(virq); + + return PAL_SUCCESS; +} + +void pal_send_sgi(unsigned int sgi_id, unsigned int core_pos) +{ + return; +} diff --git a/ffa-acs-drv/pal_linux/src/pal_misc.c b/ffa-acs-drv/pal_linux/src/pal_misc.c new file mode 100644 index 0000000000000000000000000000000000000000..3f866031d960e21581ed103bc6ea67e0f1c4ecf0 --- /dev/null +++ b/ffa-acs-drv/pal_linux/src/pal_misc.c @@ -0,0 +1,84 @@ +/* + * FF-A ACS Platform module. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021 Arm Limited + * + * Author: Jaykumar P Patel + * + */ + +#include +#include +#include +#include "pal_interfaces.h" + +/* Note - This is unused for linux target */ +uint32_t pal_get_endpoint_device_map(void **region_list, size_t *no_of_mem_regions) +{ + *region_list = NULL; + *no_of_mem_regions = 0; + + return PAL_SUCCESS; +} + +uint32_t pal_terminate_simulation(void) +{ + return PAL_SUCCESS; +} + +void *pal_mem_virt_to_phys(void *va) +{ + return (void *)virt_to_phys(va); +} + +void *pal_memory_alloc(uint64_t size) +{ + uint32_t order = (size/PAGE_SIZE_4K)/2; + void *ptr; + + ptr = (void *)__get_free_pages(GFP_KERNEL, order); + if (!ptr) + { + pal_printf("\tpal_memory_alloc failed \n", 0, 0); + return NULL; + } + + return ptr; +} + +uint32_t pal_memory_free(void *address, uint64_t size) +{ + uint32_t order = (size/PAGE_SIZE_4K)/2; + + free_pages((uint64_t)address, order); + + return PAL_SUCCESS; +} + +int pal_memcmp(void *src, void *dest, size_t len) +{ + return memcmp(src, dest, len); +} + +void *pal_memset(void *dst, int val, size_t count) +{ + memset(dst, val, count); + return dst; +} + +void *pal_memcpy(void *dst, const void *src, size_t len) +{ + return memcpy(dst, src, len); +} diff --git a/ffa-acs-drv/pal_linux/src/pal_mmio.c b/ffa-acs-drv/pal_linux/src/pal_mmio.c new file mode 100644 index 0000000000000000000000000000000000000000..4aa26857c5921b7ca2b6e54b3bfc725c55a49928 --- /dev/null +++ b/ffa-acs-drv/pal_linux/src/pal_mmio.c @@ -0,0 +1,192 @@ +/* + * FF-A ACS Platform module. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021 Arm Limited + * + * Author: Mahesh Bireddy + * + */ + +#include +#include +#include +#include "pal_interfaces.h" +#include "pal_mmio.h" + +/* MMIO read/write access functions */ +/** + @brief Provides a single point of abstraction to read 8 bit data from + Memory Mapped IO address + + @param addr 64-bit address + + @return 8-bit data read from the input address +**/ +uint8_t pal_mmio_read8(uint64_t addr) +{ + uint8_t data; + void __iomem *p; + + p = ioremap(addr, 16); + data = ioread8(p); + + iounmap(p); + + return data; +} + +/** + @brief Provides a single point of abstraction to read 16 bit data from + Memory Mapped IO address + + @param addr 64-bit address + + @return 16-bit data read from the input address +**/ +uint16_t pal_mmio_read16(uint64_t addr) +{ + uint16_t data; + void __iomem *p; + + p = ioremap(addr, 16); + data = ioread16(p); + + iounmap(p); + + return data; +} + +/** + @brief Provides a single point of abstraction to read 64 bit data from + Memory Mapped IO address + + @param addr 64-bit address + + @return 64-bit data read from the input address +**/ +uint64_t pal_mmio_read64(uint64_t addr) +{ + uint64_t data; + void __iomem *p; + + p = ioremap(addr, 16); + data = ioread64(p); + + iounmap(p); + + return data; +} + +/** + @brief Provides a single point of abstraction to read 32-bit data from + Memory Mapped IO address + + @param addr 64-bit address + + @return 32-bit data read from the input address +**/ +uint32_t pal_mmio_read32(uint64_t addr) +{ + uint32_t data; + void __iomem *p; + + if (addr & 0x3) { + addr = addr & ~(0x3); //make sure addr is aligned to 4 bytes + } + p = ioremap(addr, 16); + //Print(L"Address = %8x ", addr); + data = ioread32(p); + + //Print(L" data = %8x \n", data); + iounmap(p); + + return data; +} + +/** + @brief Provides a single point of abstraction to write 8-bit data to + Memory Mapped IO address + + @param addr 64-bit address + @param data 8-bit data to write to address + + @return None +**/ +void pal_mmio_write8(uint64_t addr, uint8_t data) +{ + void __iomem *p; + p = ioremap(addr, 16); + //Print(L"Address = %8x Data = %8x \n", addr, data); + iowrite8(data, p); + + iounmap(p); +} + +/** + @brief Provides a single point of abstraction to write 16-bit data to + Memory Mapped IO address + + @param addr 64-bit address + @param data 16-bit data to write to address + + @return None +**/ +void pal_mmio_write16(uint64_t addr, uint16_t data) +{ + void __iomem *p; + p = ioremap(addr, 16); + //Print(L"Address = %8x Data = %8x \n", addr, data); + iowrite16(data, p); + + iounmap(p); +} + +/** + @brief Provides a single point of abstraction to write 64-bit data to + Memory Mapped IO address + + @param addr 64-bit address + @param data 64-bit data to write to address + + @return None +**/ +void pal_mmio_write64(uint64_t addr, uint64_t data) +{ + void __iomem *p; + p = ioremap(addr, 16); + //Print(L"Address = %16x Data = %16x \n", addr, data); + iowrite64(data, p); + + iounmap(p); +} + +/** + @brief Provides a single point of abstraction to write 32-bit data to + Memory Mapped IO address + + @param addr 64-bit address + @param data 32-bit data to write to address + + @return None +**/ +void pal_mmio_write32(uint64_t addr, uint32_t data) +{ + void __iomem *p; + p = ioremap(addr, 16); + //Print(L"Address = %8x Data = %8x \n", addr, data); + iowrite32(data, p); + + iounmap(p); +} diff --git a/ffa-acs-drv/pal_linux/src/pal_smmuv3_testengine.c b/ffa-acs-drv/pal_linux/src/pal_smmuv3_testengine.c new file mode 100644 index 0000000000000000000000000000000000000000..31834aa971836bae079a372e6894c318bd748326 --- /dev/null +++ b/ffa-acs-drv/pal_linux/src/pal_smmuv3_testengine.c @@ -0,0 +1,106 @@ +/* + * PSA FFA ACS Platform module. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021-2023 Arm Limited + * + */ + +#include +#include +#include +#include + +#include "pal_interfaces.h" +#include "pal_smmuv3_testengine.h" + +#define PAGE_SIZE_4K 0x1000 +#define F_IDX(n) (n * FRAME_SIZE) +#define TIME_OUT 0x100000 + +uint32_t smmuv3_configure_testengine(uint32_t stream_id, uint64_t source, uint64_t dest, + uint64_t size, bool secure) +{ + uint32_t num_frames = (uint32_t)size/PAGE_SIZE_4K; + uint64_t begin = 0; + uint64_t end_ctrl; + uint64_t o_buf; + uint32_t ssd_ns; + uint32_t data; + uint64_t time_out = TIME_OUT; + uint32_t i; + + /* TODO Add assert condtion for source and destination address */ + if (num_frames < 1) + return PAL_ERROR; + + if (secure) + ssd_ns = 0; + else + ssd_ns = 1; + + for (i = 0; i < num_frames; i++) + { + begin = source + (i * PAGE_SIZE_4K); + end_ctrl = begin + (PAGE_SIZE_4K - 1); + o_buf = dest + (i * PAGE_SIZE_4K); + /* Initialize the Privileged frame */ + pal_mmio_write32((P_FRAME_BASE + PCTRL + F_IDX(i)), ssd_ns); + pal_mmio_write32((P_FRAME_BASE + DOWNSTREAM_PORT_INDEX + F_IDX(i)), 0); + pal_mmio_write32((P_FRAME_BASE + STREAM_ID + F_IDX(i)), stream_id); + pal_mmio_write32((P_FRAME_BASE + SUBSTREAM_ID + F_IDX(i)), NO_SUBSTREAMID); + + /* Initialize the user frame */ + pal_mmio_write32((U_FRAME_BASE + UCTRL + F_IDX(i)), 0); + pal_mmio_write32((U_FRAME_BASE + SEED + F_IDX(i)), 0); + pal_mmio_write64((U_FRAME_BASE + BEGIN + F_IDX(i)), begin); + pal_mmio_write64((U_FRAME_BASE + END_CTRL + F_IDX(i)), end_ctrl); + pal_mmio_write32((U_FRAME_BASE + STRIDE + F_IDX(i)), 0x1); + pal_mmio_write64((U_FRAME_BASE + UDATA + F_IDX(i)), o_buf); + pal_mmio_write32((U_FRAME_BASE + CMD + F_IDX(i)), ENGINE_MEMCPY); + + while (--time_out) + { + data = pal_mmio_read32((U_FRAME_BASE + CMD + F_IDX(i))); + + if (data == ENGINE_MEMCPY) + continue; + + if (data != ENGINE_HALTED) + { + pal_printf("ERROR: SMMU data transfer failed\n", 0, 0); + return PAL_ERROR; + } + else + break; + } + + if (!time_out) + { + pal_printf("ERROR: SMMU test engine timeout\n", 0, 0); + return PAL_ERROR; + } + + time_out = TIME_OUT; + } + + + if (pal_memcmp((void *)begin, (void *)dest, size)) + { + pal_printf("ERROR: SMMU: Data mismatched\n", 0, 0); + return PAL_ERROR; + } + + return PAL_SUCCESS; +} diff --git a/ffa-acs-drv/pal_linux/src/pal_vcpu_setup.c b/ffa-acs-drv/pal_linux/src/pal_vcpu_setup.c new file mode 100644 index 0000000000000000000000000000000000000000..7716389543a4877d3911ba5686714dd85d2d0a7f --- /dev/null +++ b/ffa-acs-drv/pal_linux/src/pal_vcpu_setup.c @@ -0,0 +1,55 @@ +/* + * FF-A ACS Platform module. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, see . + * + * Copyright (C) 2021 Arm Limited + * + * Author: Mahesh Bireddy + * + */ + +#include +#include +#include +#include "pal_interfaces.h" + +uint32_t pal_get_no_of_cpus(void) +{ + return num_online_cpus(); +} + +uint32_t pal_get_cpuid(uint64_t mpdir) +{ + return read_cpuid_id(); +} + +uint64_t pal_get_mpid(uint32_t cpuid) +{ + return read_cpuid_mpidr(); +} + +uint32_t pal_power_on_cpu(uint64_t mpidr) +{ + return PAL_SUCCESS; +} + +uint32_t pal_power_off_cpu(void) +{ + return PAL_SUCCESS; +} + +void pal_secondary_cpu_boot_entry(void) +{ + return; +} diff --git a/ffa-acs-drv/setup.sh b/ffa-acs-drv/setup.sh new file mode 100755 index 0000000000000000000000000000000000000000..6604ad904e77f012c849871f7df3c256cba8e17b --- /dev/null +++ b/ffa-acs-drv/setup.sh @@ -0,0 +1,36 @@ +#!/bin/bash +## + # + # This program is free software; you can redistribute it and/or modify + # it under the terms of the GNU General Public License version 2 as + # published by the Free Software Foundation. + # + # 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, see . + # + # Copyright (C) 2021 Arm Limited + # +## + +echo "==================================================================" +echo "This script will copy the necessary files for Kernel module build " +echo "to the present directory" +echo "==================================================================" + +if [ $# -ne 1 ]; +then + echo "Give ACS_PATH as the arguments to the script" + return 0 +fi + +export ACS_PATH=$1 +echo -e "ACS_PATH is set to -> \e[93m $ACS_PATH\e[0m" + +cp -r $ACS_PATH/val . +cp -r $ACS_PATH/test . +cp -r $ACS_PATH/platform/common .