From: Pintu Agarwal <pintu_agarwal@yahoo.com>
To: "Américo Wang" <xiyou.wangcong@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: help for kernel initcall section (init.h)
Date: Mon, 22 Aug 2011 07:17:07 -0700 (PDT) [thread overview]
Message-ID: <1314022627.68014.YahooMailNeo@web162017.mail.bf1.yahoo.com> (raw)
In-Reply-To: <CAM_iQpV7D1s9oisy1Zx6-MeiruEwm3BQ5sg1UqpmraF0BazXuA@mail.gmail.com>
----- Original Message -----
> From: Américo Wang <xiyou.wangcong@gmail.com>
> To: Pintu Agarwal <pintu_agarwal@yahoo.com>
> Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
> Sent: Monday, 22 August 2011 2:38 PM
> Subject: Re: help for kernel initcall section (init.h)
>
> On Sun, Aug 21, 2011 at 11:54 AM, Pintu Agarwal <pintu_agarwal@yahoo.com>
> wrote:
>> Hi,
>>
>> I need some help in modifying initcall section in init.h.
>>
>> That is :
>>
>> #define __define_initcall(level,fn,id) \
>> static initcall_t __initcall_##fn##id __used \
>> __attribute__((__section__(".initcall" level
> ".init"))) = fn
>>
>> I have to create two different kinds (and later more) of init section and
> use one of them based on some condition.
>> For example, I have one init section for normal mode and one init section
> for charger mode.
>> During charger mode, I do not have to execute all the initcall so a
> charger.initcall is create with lesser init function.
>> The charger initcall section is as follows:
>> #define __define_charger_initcall(level,fn,id) \
>> static initcall_t __charger_initcall_##fn##id __used \
>> __attribute__((__section__(".charger.initcall" level
> ".init"))) = fn
>>
>>
>> Now the problem is that during compile time both of them needs to be
> polulated based on CHARGER_MODE is enabled or disabled.
>> How can this decision be taken during compile time under the macro
> "__define_initcall" ??
>>
>> Something like :
>>
>> #define __define_initcall(level,fn,id) \
>> static initcall_t
> __initcall_##fn##id __used \
>>
> __attribute__((__section__(".initcall" level ".init"))) =
> fn \
>> #if
> defined(CHARGER_MODE) \
>> static initcall_t
> __charger_initcall_##fn##id __used \
>>
> __attribute__((__section__(".charger.initcall"
> level ".init"))) = fn \
>> #endif
>
> Hi,
>
> Why not
>
> X_initcall(foo_initcall);
> #ifdef CHARGER_MODE
> X_initcall(foo_charger_initcall);
> #endif
>
> ?
>
No the requirement is not to do like this.
This requires defining 2 set of init calls, one for normal and one for charger init call.
We do not want to define separate init calls for charger.
We just want to take a decision during compile time to determine which initcalls should be used during charger mode.
Thus we need compile time comparison in macro which helps us in determining whether _this__ init call should be added in charger.init section or not.
Thus we can do as follows:-
------------------------------------------------------------------------------------------------------------------------------------
#define __define_initcall(level,fn,id) static initcall_t __initcall_##fn##id __used __attribute__ ((__section__(".initcall" level ".init"))) = fn \
#ifdef CHARGER_MODE \
static initcall_t __charger_initcall_##fn##id __used __attribute__ ((__section__(".charger.initcall" level ".init"))) = fn \
#endif
#define device_initcall(fn) __define_initcall("6", fn, 6, 1)
#define __initcall(fn) device_initcall(fn)
#define module_init(x) __initcall(x);
#define early_initcall(fn) module_init(fn)
------------------------------------------------------------------------------------------------------------------------------------
Basically we need something like:
#define __define_initcall(....) \
/* polupate init section */ \
#ifdef CHARGER_MODE \
/* polupate charger.init section also */ \
#elif ANOTHER_MODE \
/* polupate another.init section also */ \
#elif ....
.............
.............
#endif
Is it possible to do "#if or #ifdef" inside "#define" ?????
Basically, we need to populate each.init section based on some compile time condition.
How can we do that????
Thanks,
Pintu
prev parent reply other threads:[~2011-08-22 14:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-21 3:54 Pintu Agarwal
2011-08-22 9:08 ` Américo Wang
2011-08-22 14:17 ` Pintu Agarwal [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1314022627.68014.YahooMailNeo@web162017.mail.bf1.yahoo.com \
--to=pintu_agarwal@yahoo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®