### Advised Boot Setup Commands (Default) Source: https://www.kernel.org/doc/html/latest/scsi/ncr53c8xx.html Example of advised boot setup commands for a default configuration. ```text ncr53c8xx=mpar:y,spar:y,disc:y,specf:3,fsn:n,ultra:2,fsn:n,revprob:n,verb:1 tags:0,sync:50,debug:0,burst:7,led:0,wide:1,settle:2,diff:0,irqm:0 ``` -------------------------------- ### insmod Command Example Source: https://www.kernel.org/doc/html/latest/_sources/scsi/ncr53c8xx.rst.txt Example of installing the driver module with options using 'insmod'. This achieves the same configuration as the boot setup command example, using spaces as separators. ```bash insmod ncr53c8xx.o ncr53c8xx="tags:4 sync:10 debug:0x200" ``` -------------------------------- ### Boot Setup Command Example Source: https://www.kernel.org/doc/html/latest/_sources/scsi/ncr53c8xx.rst.txt Example of passing setup commands to the ncr53c8xx driver at boot time using LILO. This enables tagged commands, sets synchronous negotiation speed, and enables debug flags. ```bash lilo: linux root=/dev/hda2 ncr53c8xx=tags:4,sync:10,debug:0x200 ``` -------------------------------- ### Board-Specific Setup Code Example Source: https://www.kernel.org/doc/html/latest/_sources/arch/sh/new-machine.rst.txt Provides definitions for get_system_type() and platform_setup(), which are required for board-specific setup code. This example demonstrates minimal setup for an imaginary board. ```c /* * arch/sh/boards/vapor/setup.c - Setup code for imaginary board */ #include const char *get_system_type(void) { return "FooTech Vaporboard"; } int __init platform_setup(void) { /* * If our hardware actually existed, we would do real * setup here. Though it's also sane to leave this empty * if there's no real init work that has to be done for * this board. */ /* Start-up imaginary PCI ... */ /* And whatever else ... */ return 0; } ``` -------------------------------- ### Advised Boot Setup Commands (Personal System) Source: https://www.kernel.org/doc/html/latest/scsi/ncr53c8xx.html Example of advised boot setup commands for a personal system that works flawlessly. ```text ncr53c8xx=mpar:y,spar:y,disc:y,specf:1,fsn:n,ultra:2,fsn:n,revprob:n,verb:1 tags:32,sync:12,debug:0,burst:7,led:1,wide:1,settle:2,diff:0,irqm:0 ``` -------------------------------- ### Advised Boot Setup Commands (Safe System) Source: https://www.kernel.org/doc/html/latest/scsi/ncr53c8xx.html Example of advised boot setup commands for a safe but not fast system. ```text ncr53c8xx=safe:y,mpar:y,disc:y ncr53c8xx=safe:y,disc:y ncr53c8xx=safe:y,mpar:y ncr53c8xx=safe:y ``` -------------------------------- ### LILO Boot Setup Command Example Source: https://www.kernel.org/doc/html/latest/scsi/sym53c8xx_2.html Example of passing driver configuration parameters via the LILO boot loader. This example sets commands per lun, sync speed, and debug flags. ```bash lilo: linux root=/dev/sda2 sym53c8xx.cmd_per_lun=4 sym53c8xx.sync=10 sym53c8xx.debug=0x200 ``` -------------------------------- ### Modprobe Boot Setup Command Example Source: https://www.kernel.org/doc/html/latest/scsi/sym53c8xx_2.html Example of loading the driver module with specific options using modprobe. This mirrors the LILO example for setting commands per lun, sync speed, and debug flags. ```bash modprobe sym53c8xx cmd_per_lun=4 sync=10 debug=0x200 ``` -------------------------------- ### IIO Trigger Setup Example Source: https://www.kernel.org/doc/html/latest/_sources/driver-api/iio/triggers.rst.txt A practical example demonstrating how to allocate, configure, and register an IIO trigger within a driver. ```APIDOC ## IIO Trigger Setup Example ```c struct iio_trigger_ops trigger_ops = { .set_trigger_state = sample_trigger_state, .validate_device = sample_validate_device, }; struct iio_trigger *trig; /* first, allocate memory for our trigger */ trig = iio_trigger_alloc(dev, "trig-%s-%d", name, idx); /* setup trigger operations field */ trig->ops = &trigger_ops; /* now register the trigger with the IIO core */ iio_trigger_register(trig); ``` ``` -------------------------------- ### Finalize Disk Image Setup Source: https://www.kernel.org/doc/html/latest/bpf/s390.html Run this command after starting the virtual machine for the first time to complete the disk image setup. ```bash /debootstrap/debootstrap --second-stage ``` -------------------------------- ### Start 9pfs server (diod) Source: https://www.kernel.org/doc/html/latest/filesystems/9p.html Example command to start the 'diod' 9pfs server on the host. This server listens on a specified address and port, exporting the current directory. ```bash $ diod -f -n -d 0 -S -l 0.0.0.0:9999 -e $PWD ``` -------------------------------- ### IIO HW Consumer Setup Example Source: https://www.kernel.org/doc/html/latest/driver-api/iio/hw-consumer.html Demonstrates a typical setup for an IIO Hardware Consumer, including allocation, enabling, and disabling the consumer. This pattern is used when IIO devices are directly connected in hardware. ```c static struct iio_hw_consumer *hwc; static const struct iio_info adc_info = { .read_raw = adc_read_raw, }; static int adc_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { ret = iio_hw_consumer_enable(hwc); /* Acquire data */ ret = iio_hw_consumer_disable(hwc); } static int adc_probe(struct platform_device *pdev) { hwc = devm_iio_hw_consumer_alloc(&iio->dev); } ``` -------------------------------- ### Download, Configure, Build, and Install Linux Kernel Source: https://www.kernel.org/doc/html/latest/admin-guide/quickly-build-trimmed-linux.html Use these commands to download fresh Linux mainline sources, configure them using localmodconfig, build the kernel, and install it. Ensure you have sufficient disk space and necessary build tools installed. This is the initial setup for building your own kernel. ```bash git clone --depth 1 -b master \ https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git ~/linux/ cd ~/linux/ # Hint: if you want to apply patches, do it at this point. See below for details. # Hint: it's recommended to tag your build at this point. See below for details. yes "" | make localmodconfig # Hint: at this point you might want to adjust the build configuration; you'll # have to, if you are running Debian. See below for details. make -j $(nproc --all) # Note: on many commodity distributions the next command suffices, but on Arch # Linux, its derivatives, and some others it does not. See below for details. command -v installkernel && sudo make modules_install install reboot ``` -------------------------------- ### Setup MCE on x86 Source: https://www.kernel.org/doc/html/latest/virt/kvm/api.html Initializes Machine Check Exception (MCE) support for a virtual machine on x86 architecture. Specifies which MCE capabilities should be enabled. ```c u64 mcg_cap (in) ``` -------------------------------- ### Setup and Example Cpuset Configuration Source: https://www.kernel.org/doc/html/latest/_sources/admin-guide/cgroup-v1/cpusets.rst.txt Demonstrates the steps to create a new cpuset, configure its CPU and memory nodes, and launch a subshell within it. This example uses shell commands to interact with the cpuset virtual file system. ```bash mount -t cgroup -ocpuset cpuset /sys/fs/cgroup/cpuset cd /sys/fs/cgroup/cpuset mkdir Charlie cd Charlie /bin/echo 2-3 > cpuset.cpus /bin/echo 1 > cpuset.mems /bin/echo $$ > tasks sh # The subshell 'sh' is now running in cpuset Charlie # The next line should display '/Charlie' cat /proc/self/cpuset ``` -------------------------------- ### SCSI sym53c8xx Device Setup Example Source: https://www.kernel.org/doc/html/latest/_sources/scsi/sym53c8xx_2.rst.txt This is an example of the device setup entries in the sym53c8xx NVRAM, showing parameters for up to 16 devices. ```text 0f 00 08 08 64 00 0a 00 - id 0 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 - id 15 ``` -------------------------------- ### Example: Pointing to SETUP_E820_EXT data using setup_indirect Source: https://www.kernel.org/doc/html/latest/arch/x86/boot.html Illustrates how to use setup_data and setup_indirect to reference SETUP_E820_EXT data. ```c struct setup_data { .next = 0, /* or */ .type = SETUP_INDIRECT, .len = sizeof(setup_indirect), .data[sizeof(setup_indirect)] = (struct setup_indirect) { .type = SETUP_INDIRECT | SETUP_E820_EXT, .reserved = 0, .len = , .addr = , }, } ``` -------------------------------- ### Example udev Install Rules Script Source: https://www.kernel.org/doc/html/latest/_sources/admin-guide/aoe/examples.rst.txt This script is used for installing udev rules related to AoE. ```shell #!/bin/sh # Install udev rules cp udev/rules.d/aoe.rules /etc/udev/rules.d/ # Reload udev rules udevadm control --reload-rules udevadm trigger echo "AoE udev rules installed." ``` -------------------------------- ### Get Environment Variable Example Source: https://www.kernel.org/doc/html/latest/trace/rv/monitor_synthesis.html Example implementation for ha_get_env function, handling the 'preemptible' environment variable. ```c static u64 ha_get_env(struct ha_monitor *ha_mon, enum envs env) { if (env == preemptible) return preempt_count() == 0; return ENV_INVALID_VALUE; } ``` -------------------------------- ### Create and Test 'Hello World' Initramfs Source: https://www.kernel.org/doc/html/latest/filesystems/ramfs-rootfs-initramfs.html This example demonstrates creating a minimal initramfs containing a statically linked 'Hello World' program and testing it using QEMU. It includes C code for the program and shell commands for compilation and archive creation. ```c #include #include int main(int argc, char *argv[]) { printf("Hello world!\n"); sleep(999999999); } ``` ```bash cat > hello.c << EOF #include #include int main(int argc, char *argv[]) { printf("Hello world!\n"); sleep(999999999); } EOF gcc -static hello.c -o init echo init | cpio -o -H newc | gzip > test.cpio.gz # Testing external initramfs using the initrd loading mechanism. qemu -kernel /boot/vmlinuz -initrd test.cpio.gz /dev/zero ``` -------------------------------- ### Get GGTT Start Offset Source: https://www.kernel.org/doc/html/latest/gpu/xe/xe_mm.html Retrieves the starting offset of the GGTT. Used to determine the base address for GGTT mappings. ```c u64 xe_ggtt_start(struct xe_ggtt *ggtt) ``` -------------------------------- ### Get Starting Index for Iteration Source: https://www.kernel.org/doc/html/latest/driver-api/generic_pt.html Retrieves the starting index for iterating over a page table range within the current state. ```c unsigned int pt_range_to_index(const struct pt_state *pts) ``` -------------------------------- ### Start Guest3 with VFIO-AP Source: https://www.kernel.org/doc/html/latest/_sources/arch/s390/vfio-ap.rst.txt Launch Guest3 using QEMU, enabling AP features and specifying the VFIO-AP device with its sysfs path. ```bash /usr/bin/qemu-system-s390x ... -cpu host,ap=on,apqci=on,apft=on,apqi=on \ -device vfio-ap,sysfsdev=/sys/devices/vfio_ap/matrix/$uuid3 ... ``` -------------------------------- ### Customize Module Installation Path with INSTALL_MOD_PATH Source: https://www.kernel.org/doc/html/latest/kbuild/modules.html To change the default installation directory for modules, set the INSTALL_MOD_PATH variable. This example shows installing modules to '/frodo/lib/modules/$(KERNELRELEASE)/kernel/'. ```bash $ make INSTALL_MOD_PATH=/frodo modules_install => Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel/ ``` -------------------------------- ### Mounting and Running FunctionFS Daemons Source: https://www.kernel.org/doc/html/latest/usb/functionfs.html This example demonstrates how to load the FunctionFS kernel module, create mount points for MTP and HID functions, and start user-space daemons for each. It shows the typical workflow for setting up a gadget with multiple FunctionFS interfaces. ```bash $ insmod g_ffs.ko idVendor= iSerialNumber= functions=mtp,hid $ mkdir /dev/ffs-mtp && mount -t functionfs mtp /dev/ffs-mtp $ ( cd /dev/ffs-mtp && mtp-daemon ) & $ mkdir /dev/ffs-hid && mount -t functionfs hid /dev/ffs-hid $ ( cd /dev/ffs-hid && hid-daemon ) & ``` -------------------------------- ### KVM s390 Get Storage Keys Structure Source: https://www.kernel.org/doc/html/latest/virt/kvm/api.html Defines the structure used for retrieving guest storage key values on the s390 architecture. Ensure the buffer pointed to by skeydata_addr is large enough to hold the requested number of bytes. ```c struct kvm_s390_skeys { __u64 start_gfn; __u64 count; __u64 skeydata_addr; __u32 flags; __u32 reserved[9]; }; /* Example setup for KVM_S390_GET_SKEYS */ struct kvm_s390_skeys skey_data; unsigned char key_buffer[KVM_S390_SKEYS_MAX]; skey_data.start_gfn = first_guest_frame; skey_data.count = number_of_frames; skey_data.skeydata_addr = (unsigned long)key_buffer; skey_data.flags = 0; ret = ioctl(kvm_fd, KVM_S390_GET_SKEYS, &skey_data); ``` -------------------------------- ### Typical Firmware Workflow Example Source: https://www.kernel.org/doc/html/latest/_sources/driver-api/firmware/request_firmware.rst.txt Illustrates the common workflow for requesting, using, and releasing firmware. ```c if(request_firmware(&fw_entry, $FIRMWARE, device) == 0) copy_fw_to_device(fw_entry->data, fw_entry->size); release_firmware(fw_entry); ``` -------------------------------- ### Start Guest1 with VFIO-AP Source: https://www.kernel.org/doc/html/latest/_sources/arch/s390/vfio-ap.rst.txt Launch Guest1 using QEMU, enabling AP features and specifying the VFIO-AP device with its sysfs path. ```bash /usr/bin/qemu-system-s390x ... -cpu host,ap=on,apqci=on,apft=on,apqi=on \ -device vfio-ap,sysfsdev=/sys/devices/vfio_ap/matrix/$uuid1 ... ``` -------------------------------- ### EP93xx Framebuffer Platform Setup Callback Source: https://www.kernel.org/doc/html/latest/_sources/fb/ep93xx-fb.rst.txt Implement the setup callback for the EP93xx framebuffer driver. This function is called when the driver is installed. ```c static int some_board_fb_setup(struct platform_device *pdev) { struct ep93xxfb_mach_info *mach_info = pdev->dev.platform_data; struct fb_info *fb_info = platform_get_drvdata(pdev); /* Board specific framebuffer setup */ } ``` -------------------------------- ### Bind Mount Example Source: https://www.kernel.org/doc/html/latest/_sources/filesystems/sharedsubtree.rst.txt Demonstrates setting up a bind mount. This is a prerequisite for shared subtree operations. ```bash mount --bind /root/tmp /root/tmp ``` -------------------------------- ### Get Feature Example Source: https://www.kernel.org/doc/html/latest/_sources/userspace-api/fwctl/fwctl-cxl.rst.txt Example C code demonstrating how to use `ioctl(FWCTL_RPC)` to retrieve feature details from a CXL device. ```c static int cxl_fwctl_rpc_get_test_feature(int fd, struct test_feature *feat_ctx, const uint32_t expected_data) { struct cxl_mbox_get_feat_in *feat_in; struct fwctl_rpc_cxl_out *out; struct fwctl_rpc rpc = {0}; struct fwctl_rpc_cxl *in; size_t out_size, in_size; uint32_t val; void *data; int rc; in_size = sizeof(*in) + sizeof(*feat_in); rc = posix_memalign((void **)&in, 16, in_size); if (rc) return -ENOMEM; memset(in, 0, in_size); feat_in = &in->get_feat_in; uuid_copy(feat_in->uuid, feat_ctx->uuid); feat_in->count = feat_ctx->get_size; out_size = sizeof(*out) + feat_ctx->get_size; rc = posix_memalign((void **)&out, 16, out_size); if (rc) goto free_in; memset(out, 0, out_size); in->opcode = CXL_MBOX_OPCODE_GET_FEATURE; in->op_size = sizeof(*feat_in); rpc.size = sizeof(rpc); rpc.scope = FWCTL_RPC_CONFIGURATION; rpc.in_len = in_size; rpc.out_len = out_size; rpc.in = (uint64_t)(uint64_t *)in; rpc.out = (uint64_t)(uint64_t *)out; rc = send_command(fd, &rpc, out); if (rc) goto free_all; // ... process output data ... free_all: free(out); free_in: free(in); return rc; } ``` -------------------------------- ### Starting UML Instance with Specific Configurations Source: https://www.kernel.org/doc/html/latest/virt/uml/user_mode_linux_howto_v2.html Launches a UML instance with specified memory, UBD root device, tap network interface, and console configurations. ```bash # linux mem=2048M umid=TEST \ ubd0=Filesystem.img \ vec0:transport=tap,ifname=tap0,depth=128,gro=1 \ root=/dev/ubda con=null con0=null,fd:2 con1=fd:0,fd:1 ``` -------------------------------- ### NCR53C8XX Boot Setup Command Example Source: https://www.kernel.org/doc/html/latest/scsi/ncr53c8xx.html Example of passing configuration options to the ncr53c8xx driver at boot time using LILO. This sets tagged commands to 4, synchronous negotiation speed to 10, and enables the DEBUG_NEGO flag. ```bash lilo: linux root=/dev/hda2 ncr53c8xx=tags:4,sync:10,debug:0x200 ``` -------------------------------- ### Preemptirqsoff Trace Output Example Source: https://www.kernel.org/doc/html/latest/trace/ftrace.html This is an example output of the preemptirqsoff tracer, showing latency, task information, and the start and end points of the traced event. ```text # tracer: preemptirqsoff # # preemptirqsoff latency trace v1.1.5 on 3.8.0-test+ # -------------------------------------------------------------------- # latency: 100 us, #4/4, CPU#3 | (M:preempt VP:0, KP:0, SP:0 HP:0 #P:4) # ----------------- # | task: ls-2230 (uid:0 nice:0 policy:0 rt_prio:0) # ----------------- # => started at: ata_scsi_queuecmd # => ended at: ata_scsi_queuecmd # # # _------=> CPU# # / _-----=> irqs-off # | / _----=> need-resched # || / _---=> hardirq/softirq # |||| / _--=> preempt-depth # ||||| / delay # cmd pid ||||| time | caller ``` -------------------------------- ### SCSI sym53c8xx NVRAM Header Example Source: https://www.kernel.org/doc/html/latest/_sources/scsi/sym53c8xx_2.rst.txt This is an example of the header section found in the sym53c8xx NVRAM. It includes a start marker, byte count, and checksum. ```text 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 0f 00 08 08 64 00 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fe fe 00 00 00 00 ``` -------------------------------- ### Prepare and Build Kernel Source: https://www.kernel.org/doc/html/latest/admin-guide/bug-bisect.html Copy your base configuration and update it for the current codebase. Then, build the kernel. ```bash cp ~/prepared_kernel_.config .config make olddefconfig ``` -------------------------------- ### Format and Open LUKS Device with cryptsetup Source: https://www.kernel.org/doc/html/latest/_sources/admin-guide/device-mapper/dm-crypt.rst.txt This example demonstrates the standard procedure for setting up disk encryption using LUKS with cryptsetup. It formats the device and then opens it for use. ```shell #!/bin/sh cryptsetup luksFormat $1 cryptsetup luksOpen $1 crypt1 ``` -------------------------------- ### Starting CAN Network Device with Bit-Rate Source: https://www.kernel.org/doc/html/latest/networking/can.html Start a CAN network device by defining proper bit-timing parameters before bringing the interface up. This example uses the bitrate argument. ```bash $ ip link set canX up type can bitrate 125000 ``` -------------------------------- ### ACPI tracing boot parameters example Source: https://www.kernel.org/doc/html/latest/_sources/firmware-guide/acpi/method-tracing.rst.txt Example of how to use ACPI tracing parameters as boot arguments to configure tracing settings at system startup. ```bash acpi.trace_debug_layer=0x80 acpi.trace_debug_level=0x10 \ acpi.trace_method_name=_SB.LID0._LID acpi.trace_state=opcode-once ``` -------------------------------- ### Start 9pfs Server (diod) Source: https://www.kernel.org/doc/html/latest/_sources/filesystems/9p.rst.txt Example command to start the 'diod' 9pfs server on a development host. This server listens on all interfaces on port 9999. ```bash $ diod -f -n -d 0 -S -l 0.0.0.0:9999 -e $PWD ``` -------------------------------- ### EP93xx Framebuffer Setup Callback Source: https://www.kernel.org/doc/html/latest/fb/ep93xx-fb.html Example of a board-specific setup function for the EP93xx framebuffer driver. It receives the platform device and retrieves framebuffer information. ```c static int some_board_fb_setup(struct platform_device *pdev) { struct ep93xxfb_mach_info *mach_info = pdev->dev.platform_data; struct fb_info *fb_info = platform_get_drvdata(pdev); /* Board specific framebuffer setup */ } ``` -------------------------------- ### Initialize media_build Tree Source: https://www.kernel.org/doc/html/latest/admin-guide/media/building.html Run the './build' script to prepare the media_build backport tree for compilation. May need to be run twice. ```bash $ ./build ``` -------------------------------- ### Start Guest2 with VFIO-AP Source: https://www.kernel.org/doc/html/latest/_sources/arch/s390/vfio-ap.rst.txt Launch Guest2 using QEMU, enabling AP features and specifying the VFIO-AP device with its sysfs path. ```bash /usr/bin/qemu-system-s390x ... -cpu host,ap=on,apqci=on,apft=on,apqi=on \ -device vfio-ap,sysfsdev=/sys/devices/vfio_ap/matrix/$uuid2 ... ``` -------------------------------- ### tty_standard_install Source: https://www.kernel.org/doc/html/latest/driver-api/tty/tty_struct.html Performs standard installation operations for a TTY driver. If the driver overrides the tty->ops->install function, it can call this function to complete the standard setup. ```APIDOC ## tty_standard_install ### Description Performs standard installation operations for a TTY driver. If the driver overrides the tty->ops->install function, it can call this function to complete the standard setup. ### Parameters - **driver** (struct tty_driver *) - The driver for the tty. - **tty** (struct tty_struct *) - The tty. ### Return int - Success or error code. ``` -------------------------------- ### IIO HW Consumer Setup Example Source: https://www.kernel.org/doc/html/latest/_sources/driver-api/iio/hw-consumer.rst.txt Demonstrates the typical setup for an IIO HW consumer, including allocation and usage within a device probe and read function. Ensure the `hwc` variable is properly allocated before use. ```c static struct iio_hw_consumer *hwc; static const struct iio_info adc_info = { .read_raw = adc_read_raw, }; static int adc_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { ret = iio_hw_consumer_enable(hwc); /* Acquire data */ ret = iio_hw_consumer_disable(hwc); } static int adc_probe(struct platform_device *pdev) { hwc = devm_iio_hw_consumer_alloc(&iio->dev); } ``` -------------------------------- ### Example: Pointing to SETUP_E820_EXT using setup_indirect Source: https://www.kernel.org/doc/html/latest/_sources/arch/x86/boot.rst.txt Illustrates how to use setup_indirect to reference external data like SETUP_E820_EXT. This involves nesting setup_indirect within a setup_data structure. ```c struct setup_data { .next = 0, /* or */ .type = SETUP_INDIRECT, .len = sizeof(setup_indirect), .data[sizeof(setup_indirect)] = (struct setup_indirect) { .type = SETUP_INDIRECT | SETUP_E820_EXT, .reserved = 0, .len = , .addr = , }, } ``` -------------------------------- ### Example Threaded NAPI Get Output Source: https://www.kernel.org/doc/html/latest/networking/napi.html An example output from the 'ynl napi-get' command, showing the configuration parameters for a NAPI, including the PID of the busy-polling kthread. ```text $ {'defer-hard-irqs': 0, 'gro-flush-timeout': 0, 'id': 66, 'ifindex': 2, 'irq-suspend-timeout': 0, 'pid': 258, 'threaded': 'busy-poll'} ``` -------------------------------- ### Start SRCU Grace Period and Get Cookie Source: https://www.kernel.org/doc/html/latest/core-api/kernel-api.html Provides a cookie and ensures an SRCU grace period is started. Useful for polling grace period completion. ```c unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp); ``` -------------------------------- ### Boot config file example for kernel and init parameters Source: https://www.kernel.org/doc/html/latest/_sources/admin-guide/bootconfig.rst.txt Example of a boot configuration file defining parameters for the kernel command line and the init process. Parameters under `kernel` are passed to the kernel cmdline, and parameters under `init` are passed to the init process. ```json kernel { root = 01234567-89ab-cdef-0123-456789abcd } init { splash } ``` -------------------------------- ### SCSI sym53c8xx Controller Setup Example Source: https://www.kernel.org/doc/html/latest/_sources/scsi/sym53c8xx_2.rst.txt This snippet shows the layout for controller setup within the sym53c8xx NVRAM. It includes flag bits and host ID configuration. ```text 00 30 00 00 00 00 07 00 00 00 00 00 00 00 07 04 10 04 00 00 ``` -------------------------------- ### Creating a "Hello World" Initramfs Source: https://www.kernel.org/doc/html/latest/_sources/filesystems/ramfs-rootfs-initramfs.rst.txt This example demonstrates how to create a simple initramfs that executes a "Hello world!" program. It involves writing C code, compiling it statically, creating a cpio archive, and then compressing it. This is useful for testing initramfs functionality with emulators. ```c #include #include int main(int argc, char *argv[]) { printf("Hello world!\n"); sleep(999999999); } ``` ```bash gcc -static hello.c -o init echo init | cpio -o -H newc | gzip > test.cpio.gz ``` ```bash qemu -kernel /boot/vmlinuz -initrd test.cpio.gz /dev/zero ``` -------------------------------- ### Loading c101 module with example parameters Source: https://www.kernel.org/doc/html/latest/networking/generic-hdlc.html An example of loading the c101 module with concrete hardware parameter values. ```bash insmod c101 hw=9,0xdc000 ``` -------------------------------- ### Start Application on Core 1 Source: https://www.kernel.org/doc/html/latest/_sources/trace/coresight/panic.rst.txt Starts a 'dd' command to generate random data and write it to /dev/null on core 1. This is part of the setup for invoking a kernel panic. ```bash #taskset -c 1 dd if=/dev/urandom of=/dev/null & ``` -------------------------------- ### Get Interface Index and Bind Socket Source: https://www.kernel.org/doc/html/latest/networking/can.html Example demonstrating how to get the interface index for a CAN device (e.g., 'can0') using ioctl and then bind a raw CAN socket to that interface. ```c int s; struct sockaddr_can addr; struct ifreq ifr; s = socket(PF_CAN, SOCK_RAW, CAN_RAW); strcpy(ifr.ifr_name, "can0" ); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; bind(s, (struct sockaddr *)&addr, sizeof(addr)); (..) ``` -------------------------------- ### Bootstrap and Start OrangeFS Server (from source) Source: https://www.kernel.org/doc/html/latest/filesystems/orangefs.html Starts the OrangeFS server using the configuration file generated from source. This command bootstraps and then runs the server. ```bash /opt/ofs/sbin/pvfs2-server -f /etc/pvfs2.conf /opt/ofs/sbin/pvfs2-server /etc/pvfs2.conf ``` -------------------------------- ### IIO Triggered Buffer Setup Example Source: https://www.kernel.org/doc/html/latest/_sources/driver-api/iio/triggered-buffers.rst.txt Demonstrates the typical setup for an IIO triggered buffer, including defining buffer setup operations, poll functions, and trigger handlers. This is usually called within a device's probe function. ```c const struct iio_buffer_setup_ops sensor_buffer_setup_ops = { .preenable = sensor_buffer_preenable, .postenable = sensor_buffer_postenable, .postdisable = sensor_buffer_postdisable, .predisable = sensor_buffer_predisable, }; irqreturn_t sensor_iio_pollfunc(int irq, void *p) { pf->timestamp = iio_get_time_ns((struct indio_dev *)p); return IRQ_WAKE_THREAD; } irqreturn_t sensor_trigger_handler(int irq, void *p) { u16 buf[8]; int i = 0; /* read data for each active channel */ for_each_set_bit(bit, active_scan_mask, masklength) buf[i++] = sensor_get_data(bit) iio_push_to_buffers_with_timestamp(indio_dev, buf, timestamp); iio_trigger_notify_done(trigger); return IRQ_HANDLED; } /* setup triggered buffer, usually in probe function */ iio_triggered_buffer_setup(indio_dev, sensor_iio_polfunc, sensor_trigger_handler, sensor_buffer_setup_ops); ``` -------------------------------- ### Basic Key-Value Syntax Example Source: https://www.kernel.org/doc/html/latest/admin-guide/bootconfig.html Illustrates the fundamental key-value pair structure in boot configuration files. Keys are dot-connected words, and values are strings terminated by specific delimiters. ```bootconfig KEY[.WORD[...]] = VALUE[, VALUE2[...]][;] ``` -------------------------------- ### Initrd fstab Example Source: https://www.kernel.org/doc/html/latest/_sources/power/swsusp-dmcrypt.rst.txt Example fstab content for an initrd, mounting necessary file systems and defining device mappings. ```config /dev/hda1 /mnt ext3 ro 0 0 none /proc proc defaults,noatime,nodiratime 0 0 none /sys sysfs defaults,noatime,nodiratime 0 0 ``` -------------------------------- ### Mount CIFS Share Example Source: https://www.kernel.org/doc/html/latest/_sources/admin-guide/cifs/usage.rst.txt This is an example of the mount syntax used to access Samba, Mac, or Windows servers once CIFS VFS support is built into the kernel or installed as a module. ```bash mount -t cifs //server/share /mnt/cifs -o user=username,password=password ``` -------------------------------- ### Get Last CD-ROM Session Info Source: https://www.kernel.org/doc/html/latest/_sources/cdrom/cdrom-standard.rst.txt Implement the old ioctl() to get the start of the last session on the current disc. The argument is sanitized to CDROM_LBA but can be returned in CDROM_MSF format. ```c int get_last_session(struct cdrom_device_info *cdi, struct cdrom_multisession *ms_info) ```