help for kernel initcall section (init.h)
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
Right now this cannot be done, as macro cannot exists inside a macro statement.
If any body have any alternative or better idea of doing this please help.
In gernal, how can I take decision during compile time itself and decide which initcall to be used instead of calling all of them.
Thanks, Regards.
Pintu
Quoted 24 lines · Pintu Agarwal
Hi,
I need some help in modifying initcall section in
init.h.That is :
#define
__define_initcall(level,fn,id)\
staticinitcall_t__initcall_##fn##id__used\
__attribute__((__section__(".initcall" level ".init"))) = fnI 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)\
staticinitcall_t__charger_initcall_##fn##id__used\
__attribute__((__section__(".charger.initcall" level ".init"))) = fnNow the problem is that during compile time both of them needs to be polulated based on
CHARGER_MODEis enabled or disabled. How can this decision be taken during compile time under the macro "__define_initcall" ??Something like :
Quoted 7 lines
#define __define_initcall(level,fn,id) \
staticinitcall_t__initcall_##fn##id__used\
__attribute__((__section__(".initcall" level ".init")))= fn \
#if defined(CHARGER_MODE) \
staticinitcall_t__charger_initcall_##fn##id __used \
__attribute__((__section__(".charger.initcall" level ".init"))) = fn \
#endif
Hi,
Why not
X_initcall(foo_initcall);
#ifdef CHARGER_MODEX_initcall(foo_charger_initcall);
#endif
? ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
----- Original Message -----
Quoted 56 lines
From: Américo Wang <[email protected]>
To: Pintu Agarwal <[email protected]>
Cc: "[email protected]" <[email protected]>
Sent: Monday, 22 August 2011 2:38 PM
Subject: Re: help for kernel initcall section (init.h)Quoted 9 lines · Pintu Agarwal
Hi,
I need some help in modifying initcall section in
init.h.That is :
#define
__define_initcall(level,fn,id)\
staticinitcall_t__initcall_##fn##id__used\
__attribute__((__section__(".initcall" level".init"))) = fn
Quoted 2 lines
I have to create two different kinds (and later more) of init section and
use one of them based on some condition.
Quoted 1 line
For example, I have one init section for normal mode and one init section
for charger mode.
Quoted 1 line
During charger mode, I do not have to execute all the initcall so a
charger.initcall is create with lesser init function.
Quoted 4 lines
The charger initcall section is as follows:
#define__define_charger_initcall(level,fn,id)\
staticinitcall_t__charger_initcall_##fn##id__used\
__attribute__((__section__(".charger.initcall" level".init"))) = fn
Quoted 3 lines
Now the problem is that during compile time both of them needs to be
polulated based on
CHARGER_MODEis enabled or disabled.Quoted 1 line
How can this decision be taken during compile time under the macro
"
__define_initcall" ??Quoted 5 lines
Something like :
#define __define_initcall(level,fn,id) \
staticinitcall_t__initcall_##fn##id
__used\Quoted 1 line
__attribute__((__section__(".initcall" level ".init")))= fn \Quoted 1 line
#if
defined(CHARGER_MODE) \
Quoted 1 line
static
initcall_t__charger_initcall_##fn##id __used \
Quoted 1 line
__attribute__((__section__(".charger.initcall" level ".init"))) = fn \
Quoted 1 line
#endif
Hi,
Quoted 9 lines
Why not
X_initcall(foo_initcall);
#ifdefCHARGER_MODEX_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