Linux driver Macro __setup (str, FN)

Source: Internet
Author: User

(i). Defined as follows:

#define __setup (str, fn) \__setup_param (str, FN, FN,0)#define __setup_param (str, unique_id, FN, early) \Static Char__setup_str_# #unique_id [] __initdata __aligned (1) = str; \Static structObs_kernel_param __setup_# #unique_id \__used __section (. Init.setup) __attribute__ ((Aligned (sizeof(Long)))) = {__setup_str_# #unique_id, FN, early}structObs_kernel_param {Const Char*STR;int(*setup_func) (Char*);intEarly;};

(b). Example: (From: NET/CORE/DEV.C)

__setup ("netdev=", Netdev_boot_setup) '
From (a) can be converted to:

__setup_param("netdev=", netdev_boot_setup, netdev_boot_setup, 0)

=====>

#define __setup_param("netdev=", netdev_boot_setup, netdev_boot_setup, 0) \staticchar __setup_str_netdev_boot_setup[] __initdata __aligned(1"netdev="staticstruct obs_kernel_param __setup_unique_id __used __section(.init.setup) __attribute__((aligned((sizeof(long0 }

__setup (str, FN)
STR is the keyword, and FN is the correlation handler function. __setup just tells the kernel to execute FN When the input string contains str when it starts. STR must end with a "=" character to make the Parse_args more convenient to parse. Any text immediately following the "=" will be passed as input to FN.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Continue to take __setup ("netdev=", Netdev_boot_setup) for example:
To achieve netdev_boot_setup, which form does it appear in? :

struct obs_kernel_param {    constchar *str;    int (*setup_func)(char *);    int early;};

This should be done in the form of:

int netdev_boot_setup(char *str){    ...    0;}

When the kernel starts parsing parameters with a "Netdev" string, the Netdev_boot_setup function is executed and the string after "netdev=" is passed as a parameter.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux driver Macro __setup (str, FN)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.