-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Linux litepcie kernel module source
- Loading branch information
Showing
23 changed files
with
3,101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
Language: Cpp | ||
AlignAfterOpenBracket: DontAlign | ||
AlignConsecutiveMacros: false | ||
AlignConsecutiveAssignments: false | ||
AlignConsecutiveDeclarations: false | ||
AlignEscapedNewlines: DontAlign | ||
AlignOperands: true | ||
AlignTrailingComments: false | ||
AllowAllArgumentsOnNextLine: true | ||
AllowAllConstructorInitializersOnNextLine: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortBlocksOnASingleLine: Never | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: InlineOnly | ||
AllowShortLambdasOnASingleLine: All | ||
AllowShortIfStatementsOnASingleLine: Never | ||
AllowShortLoopsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: false | ||
BinPackArguments: false | ||
BinPackParameters: false | ||
BreakBeforeBraces: Custom | ||
BraceWrapping: | ||
AfterCaseLabel: false | ||
AfterControlStatement: Always | ||
AfterEnum: false | ||
AfterFunction: true | ||
AfterStruct: false | ||
AfterUnion: false | ||
AfterExternBlock: false | ||
BeforeElse: true | ||
IndentBraces: false | ||
SplitEmptyFunction: true | ||
SplitEmptyRecord: true | ||
SplitEmptyNamespace: true | ||
BreakBeforeBinaryOperators: None | ||
BreakInheritanceList: BeforeComma | ||
BreakBeforeTernaryOperators: true | ||
ColumnLimit: 132 | ||
ContinuationIndentWidth: 4 | ||
DeriveLineEnding: false | ||
DerivePointerAlignment: false | ||
IncludeBlocks: Preserve | ||
|
||
IndentCaseLabels: false | ||
IndentGotoLabels: true | ||
IndentPPDirectives: BeforeHash | ||
IndentWidth: 4 | ||
IndentWrappedFunctionNames: false | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: 1 | ||
PenaltyBreakAssignment: 2 | ||
PenaltyBreakBeforeFirstCallParameter: 19 | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyBreakTemplateDeclaration: 10 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 60 | ||
PointerAlignment: Right | ||
ReflowComments: false | ||
SortIncludes: false | ||
SpaceAfterCStyleCast: false | ||
SpaceAfterLogicalNot: false | ||
SpaceBeforeAssignmentOperators: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceInEmptyBlock: false | ||
SpaceInEmptyParentheses: false | ||
SpacesBeforeTrailingComments: 1 | ||
SpacesInAngles: false | ||
SpacesInConditionalStatement: false | ||
SpacesInContainerLiterals: true | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
SpaceBeforeSquareBrackets: false | ||
TabWidth: 4 | ||
UseCRLF: false | ||
UseTab: Never | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR) | ||
|
||
project(litepcie-kernel VERSION 0.1.0 LANGUAGES C) | ||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake") | ||
set(MODULE_NAME litepcie) | ||
|
||
find_package(LinuxKernelHeaders REQUIRED) | ||
|
||
# Get kernel version | ||
execute_process(COMMAND uname -r | ||
OUTPUT_VARIABLE KERNEL_RELEASE | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
set(KERNEL_SOURCE_DIR /lib/modules/${KERNEL_RELEASE}/build) | ||
|
||
# Get architecture | ||
execute_process(COMMAND uname -m | ||
OUTPUT_VARIABLE ARCH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
# ARCH might be 'aarch64', but the linux lib directories might be named 'arm64' | ||
if(${ARCH} STREQUAL "aarch64" AND NOT EXISTS ${KERNEL_SOURCE_DIR}/arch/${ARCH}) | ||
set(ARCH "arm64") | ||
endif() | ||
|
||
# where Kbuild file will be placed | ||
set(KBUILD_FILE_DIR ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
# Generate the Kbuild file through cmake. | ||
FILE(WRITE ${KBUILD_FILE_DIR}/Kbuild | ||
"ccflags-y = -Wno-declaration-after-statement | ||
ccflags-y = -I${KBUILD_FILE_DIR}/bsp | ||
obj-m = litepcie.o" | ||
) | ||
|
||
set(MODULE_OBJECT ${KBUILD_FILE_DIR}/${MODULE_NAME}.ko) | ||
set(KBUILD_CMD | ||
$(MAKE) | ||
-C ${KERNEL_SOURCE_DIR} | ||
ARCH=${ARCH} | ||
# Informs kbuild that an external module is being built. | ||
# The value given to "M" is the absolute path of the directory where the external module (kbuild file) is located. | ||
M=${KBUILD_FILE_DIR} | ||
modules | ||
) | ||
|
||
set(KBUILD_CLEAN_CMD | ||
$(MAKE) | ||
-C ${KERNEL_SOURCE_DIR} | ||
ARCH=${ARCH} | ||
M=${KBUILD_FILE_DIR} | ||
clean | ||
) | ||
|
||
set(KERNEL_SOURCE_RELATIVE_PATHS | ||
litepcie.c | ||
litepcie.h | ||
boards.h | ||
bsp/config.h | ||
bsp/csr.h | ||
bsp/flags.h | ||
bsp/mem.h | ||
bsp/soc.h | ||
) | ||
|
||
# Copy all source files into build directory and compile there, as the Kbuild produces artifacts in tree | ||
foreach(SRC_FILENAME ${KERNEL_SOURCE_RELATIVE_PATHS}) | ||
configure_file(${CMAKE_CURRENT_LIST_DIR}/${SRC_FILENAME} ${KBUILD_FILE_DIR}/${SRC_FILENAME} COPYONLY) | ||
endforeach() | ||
|
||
add_custom_command(OUTPUT ${MODULE_OBJECT} | ||
COMMAND ${KBUILD_CLEAN_CMD} | ||
COMMAND ${KBUILD_CMD} | ||
WORKING_DIRECTORY ${KBUILD_FILE_DIR} | ||
DEPENDS ${CMAKE_CURRENT_LIST_DIR} # rebuild if anything changes in the source dir | ||
VERBATIM | ||
COMMENT "Building Linux kernel module in dir: ${KBUILD_FILE_DIR}" | ||
) | ||
|
||
add_custom_target(litepcie-kernel ALL DEPENDS ${MODULE_OBJECT}) | ||
|
||
# If module is already loaded, unload it | ||
install(CODE "exec_program(${CMAKE_CURRENT_LIST_DIR}/unload.sh ARGS ${MODULE_NAME})") | ||
set(KERNEL_MODULE_DESTINATION /lib/modules/${KERNELRELEASE}/extra) | ||
install( | ||
FILES ${MODULE_OBJECT} | ||
DESTINATION ${KERNEL_MODULE_DESTINATION} | ||
) | ||
# load installed module | ||
install(CODE "exec_program(${CMAKE_CURRENT_LIST_DIR}/install.sh ARGS ${MODULE_NAME})") | ||
|
||
add_custom_target(uninstall-kernel-module | ||
COMMAND ${CMAKE_CURRENT_LIST_DIR}/uninstall.sh ${MODULE_NAME} | ||
COMMENT "Uninstalling Linux kernel module ${MODULE_NAME}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Makefile for kernel module | ||
KERNEL_VERSION:=$(shell uname -r) | ||
KERNEL_PATH?=/lib/modules/$(KERNEL_VERSION)/build | ||
# ARCH?=$(shell uname -m) | ||
# ARCH might be 'aarch64', but the linux lib directories might be named 'arm64' | ||
ARCH?=$(shell if [ "$(shell uname -m)" = "aarch64" ] && [ ! -d $(KERNEL_PATH)/arch/$(shell uname -m) ]; then echo "arm64"; else echo $(shell uname -m); fi) | ||
|
||
obj-m = litepcie.o | ||
litepcie-objs = main.o | ||
|
||
all: litepcie.ko | ||
|
||
export EXTRA_CFLAGS := -std=gnu99 -Wno-declaration-after-statement | ||
|
||
litepcie.ko: main.c | ||
make -C $(KERNEL_PATH) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=$(shell pwd) modules | ||
|
||
litepcie.ko: litepcie.h config.h flags.h csr.h soc.h | ||
|
||
clean: | ||
make -C $(KERNEL_PATH) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=$(shell pwd) clean | ||
rm -f *~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Linux litepcie driver | ||
|
||
Linux Litepcie kernel module for communicating with LimeSDR devices using PCIe interface. | ||
|
||
## Installation | ||
<pre> | ||
mkdir build && cd build | ||
cmake ../ && cmake --build . | ||
sudo make install | ||
</pre> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#ifndef LMS_BOARDS_H | ||
#define LMS_BOARDS_H | ||
|
||
enum eLMS_DEV { | ||
LMS_DEV_UNKNOWN = 0, | ||
LMS_DEV_EVB6 = 1, | ||
LMS_DEV_DIGIGREEN = 2, | ||
LMS_DEV_DIGIRED = 3, //2x USB3, LMS6002, | ||
LMS_DEV_EVB7 = 4, | ||
LMS_DEV_ZIPPER = 5, //MyRiad bridge to FMC, HSMC bridge | ||
LMS_DEV_SOCKETBOARD = 6, | ||
LMS_DEV_EVB7V2 = 7, | ||
LMS_DEV_STREAM = 8, //Altera Cyclone IV, USB3, 2x 128 MB RAM, RFDIO, FMC | ||
LMS_DEV_NOVENA = 9, //Freescale iMX6 CPU | ||
LMS_DEV_DATASPARK = 10, //Altera Cyclone V, 2x 256 MB RAM, 2x FMC (HPC, LPC), USB3 | ||
LMS_DEV_RFSPARK = 11, //LMS7002 EVB | ||
LMS_DEV_LMS6002USB = 12, //LM6002-USB (USB stick: FX3, FPGA, LMS6002, RaspberryPi con) | ||
LMS_DEV_RFESPARK = 13, //LMS7002 EVB | ||
LMS_DEV_LIMESDR = 14, //LimeSDR-USB, 32bit FX3, 2xRAM, LMS7 | ||
LMS_DEV_LIMESDR_PCIE = 15, | ||
LMS_DEV_LIMESDR_QPCIE = 16, //2x LMS, 14 bit ADC and DAC | ||
LMS_DEV_LIMESDRMINI = 17, //FTDI + MAX10 + LMS | ||
LMS_DEV_USTREAM = 18, //with expansion booards (uMyriad) | ||
LMS_DEV_LIMESDR_SONY_PA = 19, //stand alone board with Sony PAs, tuners | ||
LMS_DEV_LIMESDR_USB_SP = 20, | ||
LMS_DEV_LMS7002M_ULTIMATE_EVB = 21, | ||
LMS_DEV_LIMENET_MICRO = 22, //Raspberry Pi CM3(L), Ethernet, MAX10, LMS7002, | ||
LMS_DEV_LIMESDR_CORE_SDR = 23, //LMS7002, Intel Cyclone 4, RAM, GNSS | ||
LMS_DEV_LIMESDR_CORE_HE = 24, //PA board | ||
LMS_DEV_LIMESDRMINI_V2 = 25, //FTDI + ECP5 + LMS | ||
LMS_DEV_LIMESDR_X3 = 26, // 3xLMS | ||
LMS_DEV_LIMESDR_XTRX = 27, // XTRX | ||
LMS_DEV_LIME_MM_X8 = 28, // X8 | ||
|
||
LMS_DEV_COUNT | ||
}; | ||
|
||
const char LMS_DEV_NAMES[][80] = { | ||
"UNKNOWN", | ||
"EVB6", | ||
"DigiGreen", | ||
"DigiRed", | ||
"EVB7", | ||
"ZIPPER", | ||
"Socket Board", | ||
"EVB7_v2", | ||
"Stream", | ||
"Novena", | ||
"DataSpark", | ||
"RF-Spark", | ||
"LMS6002-USB Stick", | ||
"RF-ESpark", | ||
"LimeSDR-USB", | ||
"LimeSDR-PCIe", | ||
"QPCIe", | ||
"LimeSDR-Mini", | ||
"uStream", | ||
"LimeSDR SONY PA", | ||
"LimeSDR-USB SP", | ||
"LMS7002M Ultimate EVB", | ||
"LimeNET-Micro", | ||
"LimeSDR-Core", | ||
"LimeSDR-Core-HE", | ||
"LimeSDR-Mini_v2", | ||
"LimeX3", | ||
"LimeXTRX", | ||
"LimeMM-X8", | ||
}; | ||
|
||
static inline const char *GetDeviceName(enum eLMS_DEV device) | ||
{ | ||
if (LMS_DEV_UNKNOWN < device && device < LMS_DEV_COUNT) | ||
return LMS_DEV_NAMES[device]; | ||
else | ||
return LMS_DEV_NAMES[LMS_DEV_UNKNOWN]; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DisableFormat: true |
Oops, something went wrong.