Skip to content

Commit aafe4db

Browse files
arndbArnd Bergmann
authored andcommitted
asm-generic: add generic versions of common headers
These are all kernel internal interfaces that get copied around a lot. In most cases, architectures can provide their own optimized versions, but these generic versions can work as well. I have tried to use the most common contents of each header to allow existing architectures to migrate easily. Thanks to Remis for suggesting a number of cleanups. Signed-off-by: Remis Lima Baima <remis.developer@googlemail.com> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent 9858c60 commit aafe4db

18 files changed

Lines changed: 558 additions & 0 deletions

include/asm-generic/bugs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef __ASM_GENERIC_BUGS_H
2+
#define __ASM_GENERIC_BUGS_H
3+
/*
4+
* This file is included by 'init/main.c' to check for
5+
* architecture-dependent bugs.
6+
*/
7+
8+
static inline void check_bugs(void) { }
9+
10+
#endif /* __ASM_GENERIC_BUGS_H */

include/asm-generic/current.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef __ASM_GENERIC_CURRENT_H
2+
#define __ASM_GENERIC_CURRENT_H
3+
4+
#include <linux/thread_info.h>
5+
6+
#define get_current() (current_thread_info()->task)
7+
#define current get_current()
8+
9+
#endif /* __ASM_GENERIC_CURRENT_H */

include/asm-generic/delay.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef __ASM_GENERIC_DELAY_H
2+
#define __ASM_GENERIC_DELAY_H
3+
4+
extern void __udelay(unsigned long usecs);
5+
extern void __delay(unsigned long loops);
6+
7+
#define udelay(n) __udelay(n)
8+
9+
#endif /* __ASM_GENERIC_DELAY_H */

include/asm-generic/fb.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __ASM_GENERIC_FB_H_
2+
#define __ASM_GENERIC_FB_H_
3+
#include <linux/fb.h>
4+
5+
#define fb_pgprotect(...) do {} while (0)
6+
7+
static inline int fb_is_primary_device(struct fb_info *info)
8+
{
9+
return 0;
10+
}
11+
12+
#endif /* __ASM_GENERIC_FB_H_ */

include/asm-generic/hardirq.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef __ASM_GENERIC_HARDIRQ_H
2+
#define __ASM_GENERIC_HARDIRQ_H
3+
4+
#include <linux/cache.h>
5+
#include <linux/threads.h>
6+
#include <linux/irq.h>
7+
8+
typedef struct {
9+
unsigned long __softirq_pending;
10+
} ____cacheline_aligned irq_cpustat_t;
11+
12+
#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
13+
14+
#ifndef HARDIRQ_BITS
15+
#define HARDIRQ_BITS 8
16+
#endif
17+
18+
/*
19+
* The hardirq mask has to be large enough to have
20+
* space for potentially all IRQ sources in the system
21+
* nesting on a single CPU:
22+
*/
23+
#if (1 << HARDIRQ_BITS) < NR_IRQS
24+
# error HARDIRQ_BITS is too low!
25+
#endif
26+
27+
#ifndef ack_bad_irq
28+
static inline void ack_bad_irq(unsigned int irq)
29+
{
30+
printk(KERN_CRIT "unexpected IRQ trap at vector %02x\n", irq);
31+
}
32+
#endif
33+
34+
#endif /* __ASM_GENERIC_HARDIRQ_H */

include/asm-generic/irq.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef __ASM_GENERIC_IRQ_H
2+
#define __ASM_GENERIC_IRQ_H
3+
4+
/*
5+
* NR_IRQS is the upper bound of how many interrupts can be handled
6+
* in the platform. It is used to size the static irq_map array,
7+
* so don't make it too big.
8+
*/
9+
#ifndef NR_IRQS
10+
#define NR_IRQS 64
11+
#endif
12+
13+
static inline int irq_canonicalize(int irq)
14+
{
15+
return irq;
16+
}
17+
18+
#endif /* __ASM_GENERIC_IRQ_H */

include/asm-generic/irqflags.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#ifndef __ASM_GENERIC_IRQFLAGS_H
2+
#define __ASM_GENERIC_IRQFLAGS_H
3+
4+
/*
5+
* All architectures should implement at least the first two functions,
6+
* usually inline assembly will be the best way.
7+
*/
8+
#ifndef RAW_IRQ_DISABLED
9+
#define RAW_IRQ_DISABLED 0
10+
#define RAW_IRQ_ENABLED 1
11+
#endif
12+
13+
/* read interrupt enabled status */
14+
#ifndef __raw_local_save_flags
15+
unsigned long __raw_local_save_flags(void);
16+
#endif
17+
18+
/* set interrupt enabled status */
19+
#ifndef raw_local_irq_restore
20+
void raw_local_irq_restore(unsigned long flags);
21+
#endif
22+
23+
/* get status and disable interrupts */
24+
#ifndef __raw_local_irq_save
25+
static inline unsigned long __raw_local_irq_save(void)
26+
{
27+
unsigned long flags;
28+
flags = __raw_local_save_flags();
29+
raw_local_irq_restore(RAW_IRQ_DISABLED);
30+
return flags;
31+
}
32+
#endif
33+
34+
/* test flags */
35+
#ifndef raw_irqs_disabled_flags
36+
static inline int raw_irqs_disabled_flags(unsigned long flags)
37+
{
38+
return flags == RAW_IRQ_DISABLED;
39+
}
40+
#endif
41+
42+
/* unconditionally enable interrupts */
43+
#ifndef raw_local_irq_enable
44+
static inline void raw_local_irq_enable(void)
45+
{
46+
raw_local_irq_restore(RAW_IRQ_ENABLED);
47+
}
48+
#endif
49+
50+
/* unconditionally disable interrupts */
51+
#ifndef raw_local_irq_disable
52+
static inline void raw_local_irq_disable(void)
53+
{
54+
raw_local_irq_restore(RAW_IRQ_DISABLED);
55+
}
56+
#endif
57+
58+
/* test hardware interrupt enable bit */
59+
#ifndef raw_irqs_disabled
60+
static inline int raw_irqs_disabled(void)
61+
{
62+
return raw_irqs_disabled_flags(__raw_local_save_flags());
63+
}
64+
#endif
65+
66+
#define raw_local_save_flags(flags) \
67+
do { (flags) = __raw_local_save_flags(); } while (0)
68+
69+
#define raw_local_irq_save(flags) \
70+
do { (flags) = __raw_local_irq_save(); } while (0)
71+
72+
#endif /* __ASM_GENERIC_IRQFLAGS_H */

include/asm-generic/kmap_types.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef _ASM_GENERIC_KMAP_TYPES_H
2+
#define _ASM_GENERIC_KMAP_TYPES_H
3+
4+
#ifdef CONFIG_DEBUG_HIGHMEM
5+
# define D(n) __KM_FENCE_##n ,
6+
#else
7+
# define D(n)
8+
#endif
9+
10+
enum km_type {
11+
D(0) KM_BOUNCE_READ,
12+
D(1) KM_SKB_SUNRPC_DATA,
13+
D(2) KM_SKB_DATA_SOFTIRQ,
14+
D(3) KM_USER0,
15+
D(4) KM_USER1,
16+
D(5) KM_BIO_SRC_IRQ,
17+
D(6) KM_BIO_DST_IRQ,
18+
D(7) KM_PTE0,
19+
D(8) KM_PTE1,
20+
D(9) KM_IRQ0,
21+
D(10) KM_IRQ1,
22+
D(11) KM_SOFTIRQ0,
23+
D(12) KM_SOFTIRQ1,
24+
D(13) KM_SYNC_ICACHE,
25+
D(14) KM_SYNC_DCACHE,
26+
D(15) KM_UML_USERCOPY, /* UML specific, for copy_*_user - used in do_op_one_page */
27+
D(16) KM_TYPE_NR
28+
};
29+
30+
#undef D
31+
32+
#endif

include/asm-generic/linkage.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef __ASM_GENERIC_LINKAGE_H
2+
#define __ASM_GENERIC_LINKAGE_H
3+
/*
4+
* linux/linkage.h provides reasonable defaults.
5+
* an architecture can override them by providing its own version.
6+
*/
7+
8+
#endif /* __ASM_GENERIC_LINKAGE_H */

include/asm-generic/module.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef __ASM_GENERIC_MODULE_H
2+
#define __ASM_GENERIC_MODULE_H
3+
4+
/*
5+
* Many architectures just need a simple module
6+
* loader without arch specific data.
7+
*/
8+
struct mod_arch_specific
9+
{
10+
};
11+
12+
#ifdef CONFIG_64BIT
13+
#define Elf_Shdr Elf64_Shdr
14+
#define Elf_Sym Elf64_Sym
15+
#define Elf_Ehdr Elf64_Ehdr
16+
#else
17+
#define Elf_Shdr Elf32_Shdr
18+
#define Elf_Sym Elf32_Sym
19+
#define Elf_Ehdr Elf32_Ehdr
20+
#endif
21+
22+
#endif /* __ASM_GENERIC_MODULE_H */

0 commit comments

Comments
 (0)