Skip to content

Commit

Permalink
lm32: Use header files from asm-generic whenever possible
Browse files Browse the repository at this point in the history
This patch changes some of the lm32 arch header files to use the corresponding
file from asm-generic instead of their own implementation.
The replaced files look like they were copied from other archs (mainly
microblaze) before the existence of the asm-generic header files.

This patch only contains changes which should not change the lm32 userspace
linux ABI, thus existing software images can still be used.
We could (and probably should) though replace some more files with their
asm-generic equivalent, if we change the userspace ABI.

The code size of a typical kernel image is exactly the same before and after
the patch has been applied, but it is not identical regarding to the
instructions used(md5sum differs).

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
  • Loading branch information
larsclausen authored and Takeshi Matsuya committed Jan 20, 2011
1 parent b8eacce commit 84422e8
Show file tree
Hide file tree
Showing 19 changed files with 32 additions and 926 deletions.
140 changes: 1 addition & 139 deletions arch/lm32/include/asm/atomic.h
Original file line number Diff line number Diff line change
@@ -1,139 +1 @@
#ifndef _ASM_LM32_ATOMIC_H
#define _ASM_LM32_ATOMIC_H

#include <linux/types.h>

/*
* Atomic operations that C can't guarantee us. Useful for
* resource counting etc..
*/

#define ATOMIC_INIT(i) { (i) }

#define atomic_read(v) ((v)->counter)
#define atomic_set(v, i) (((v)->counter) = i)

#include <asm/system.h>
#include <linux/kernel.h>

static __inline__ int atomic_add_return(int i, atomic_t *v)
{
int ret,flags;
flags = arch_local_irq_save();
ret = v->counter += i;
arch_local_irq_restore(flags);
return ret;
}

#define atomic_add(i, v) atomic_add_return(i, v)
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)

static __inline__ int atomic_sub_return(int i, atomic_t *v)
{
int ret,flags;
flags = arch_local_irq_save();
ret = v->counter -= i;
arch_local_irq_restore(flags);
return ret;
}

#define atomic_sub(i, v) atomic_sub_return(i, v)
#define atomic_sub_and_test(i,v) (atomic_sub_return(i, v) == 0)

static __inline__ int atomic_inc_return(atomic_t *v)
{
int ret,flags;
flags = arch_local_irq_save();
v->counter++;
ret = v->counter;
arch_local_irq_restore(flags);
return ret;
}

#define atomic_inc(v) atomic_inc_return(v)

/*
* atomic_inc_and_test - increment and test
* @v: pointer of type atomic_t
*
* Atomically increments @v by 1
* and returns true if the result is zero, or false for all
* other cases.
*/
#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)

static __inline__ int atomic_dec_return(atomic_t *v)
{
int ret,flags;
flags = arch_local_irq_save();
--v->counter;
ret = v->counter;
arch_local_irq_restore(flags);
return ret;
}

#define atomic_dec(v) atomic_dec_return(v)

static __inline__ int atomic_dec_and_test(atomic_t *v)
{
int ret,flags;
flags = arch_local_irq_save();
--v->counter;
ret = v->counter;
arch_local_irq_restore(flags);
return ret == 0;
}

static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
{
int ret;
unsigned long flags;

flags = arch_local_irq_save();
ret = v->counter;
if (likely(ret == old))
v->counter = new;
arch_local_irq_restore(flags);
return ret;
}

#define atomic_xchg(v, new) (xchg(&((v)->counter), new))

static inline int atomic_add_unless(atomic_t *v, int a, int u)
{
int ret;
unsigned long flags;

flags = arch_local_irq_save();
ret = v->counter;
if (ret != u)
v->counter += a;
arch_local_irq_restore(flags);
return ret != u;
}
#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)

static __inline__ void atomic_clear_mask(unsigned long mask, unsigned long *v)
{
unsigned long flags;
flags = arch_local_irq_save();
*v &= mask;
arch_local_irq_restore(flags);
}

static __inline__ void atomic_set_mask(unsigned long mask, unsigned long *v)
{
unsigned long flags;
flags = arch_local_irq_save();
*v |= mask;
arch_local_irq_restore(flags);
}

/* Atomic operations are already serializing */
#define smp_mb__before_atomic_dec() barrier()
#define smp_mb__after_atomic_dec() barrier()
#define smp_mb__before_atomic_inc() barrier()
#define smp_mb__after_atomic_inc() barrier()

#include <asm-generic/atomic-long.h>
#endif /* _ASM_LM32_ATOMIC __ */
#include <asm-generic/atomic.h>
1 change: 1 addition & 0 deletions arch/lm32/include/asm/cmpxchg-local.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/cmpxchg-local.h>
1 change: 1 addition & 0 deletions arch/lm32/include/asm/cmpxchg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <asm-generic/cmpxchg.h>
26 changes: 1 addition & 25 deletions arch/lm32/include/asm/current.h
Original file line number Diff line number Diff line change
@@ -1,25 +1 @@
/*
* Based on:
* include/asm-blackfin/current.h
* (C) Copyright 2000, Lineo, David McCullough <davidm@uclinux.org>
*
* rather than dedicate a register (as the m68k source does), we
* just keep a global, we should probably just change it all to be
* current and lose _current_task.
*/

#ifndef _LM32_ASM_CURRENT_H
#define _LM32_ASM_CURRENT_H

#include <linux/thread_info.h>

struct task_struct;

static inline struct task_struct *get_current(void)
{
return(current_thread_info()->task);
}

#define current (get_current())

#endif /* _LM32_ASM_CURRENT_H */
#include <asm-generic/current.h>
14 changes: 1 addition & 13 deletions arch/lm32/include/asm/fb.h
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
#ifndef _ASM_FB_H_
#define _ASM_FB_H_
#include <linux/device.h>

/* Caching is off in the I/O space quadrant by design. */
#define fb_pgprotect(...) do {} while (0)

static inline int fb_is_primary_device(struct fb_info *info)
{
return 0;
}

#endif /* _ASM_FB_H_ */
#include <asm-generic/fb.h>
1 change: 0 additions & 1 deletion arch/lm32/include/asm/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ extern void iounmap(void *addr);
#define dma_cache_wback_inv(_start,_size) do { } while (0)

/* Pages to physical address... */
#define page_to_phys(page) ((page - mem_map) << PAGE_SHIFT)
#define page_to_bus(page) ((page - mem_map) << PAGE_SHIFT)

/*
Expand Down
5 changes: 0 additions & 5 deletions arch/lm32/include/asm/mman.h
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
#ifndef _ASM_LM32_MMAN_H__
#define _ASM_LM32_MMAN_H__

#include <asm-generic/mman.h>

#endif /* _ASM_LM32_MMAN_H__ */
33 changes: 1 addition & 32 deletions arch/lm32/include/asm/mmu_context.h
Original file line number Diff line number Diff line change
@@ -1,32 +1 @@
#ifndef _LM32_MMU_CONTEXT_H
#define _LM32_MMU_CONTEXT_H

#include <asm/setup.h>
#include <asm/page.h>
#include <asm/pgalloc.h>
#include <asm-generic/mm_hooks.h>

static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
{
}

static inline int
init_new_context(struct task_struct *tsk, struct mm_struct *mm)
{
return(0);
}

#define destroy_context(mm) do { } while(0)

static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, struct task_struct *tsk)
{
}

#define deactivate_mm(tsk,mm) do { } while (0)

static inline void activate_mm(struct mm_struct *prev_mm,
struct mm_struct *next_mm)
{
}

#endif
#include <asm-generic/mmu_context.h>
9 changes: 1 addition & 8 deletions arch/lm32/include/asm/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
#ifndef _LM32_ASM_MODULE_H
#define _LM32_ASM_MODULE_H

struct mod_arch_specific
{
int foo;
};

#define Elf_Shdr Elf32_Shdr
#define Elf_Sym Elf32_Sym
#define Elf_Ehdr Elf32_Ehdr
#include <asm-generic/module.h>

#define MODULE_ARCH_VERMAGIC "LM32v1"

Expand Down
125 changes: 3 additions & 122 deletions arch/lm32/include/asm/page.h
Original file line number Diff line number Diff line change
@@ -1,125 +1,6 @@
/*
* (C) Copyright 2007
* Theobroma Systems <www.theobroma-systems.com>
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
/*
* Based on:
* include/asm-v850/page.h -- VM ops
*
* Copyright (C) 2001,02,03,05 NEC Electronics Corporation
* Copyright (C) 2001,02,03,05 Miles Bader <miles@gnu.org>
*
* This file is subject to the terms and conditions of the GNU General
* Public License. See the file COPYING in the main directory of this
* archive for more details.
*
* Written by Miles Bader <miles@gnu.org>
*/
#include <asm-generic/page.h>

#ifndef _LM32_ASM_PAGE_H
#define _LM32_ASM_PAGE_H
#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC )

#include <linux/const.h>
#include <asm/setup.h>
#include <asm/io.h>

#ifdef __KERNEL__

/* PAGE_SHIFT determines the page size */

/* TODO: determine good page size, 12 means 2^12 bytes page size */
#define PAGE_SHIFT (13)
#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))

#ifndef __ASSEMBLY__

#define get_user_page(vaddr) __get_free_page(GFP_KERNEL)
#define free_user_page(page, addr) free_page(addr)

#define clear_page(page) memset((page), 0, PAGE_SIZE)
#define copy_page(to,from) memcpy((to), (from), PAGE_SIZE)

#define clear_user_page(page, vaddr, pg) clear_page(page)
#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)

/*
* These are used to make use of C type-checking..
*/
typedef struct { unsigned long pte; } pte_t;
typedef struct { unsigned long pmd[16]; } pmd_t;
typedef struct { unsigned long pgd; } pgd_t;
typedef struct { unsigned long pgprot; } pgprot_t;
typedef struct page *pgtable_t;

#define pte_val(x) ((x).pte)
#define pmd_val(x) ((&x)->pmd[0])
#define pgd_val(x) ((x).pgd)
#define pgprot_val(x) ((x).pgprot)

#define __pte(x) ((pte_t) { (x) } )
#define __pmd(x) ((pmd_t) { (x) } )
#define __pgd(x) ((pgd_t) { (x) } )
#define __pgprot(x) ((pgprot_t) { (x) } )

/* to align the pointer to the (next) page boundary */
//#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)

extern unsigned long memory_start;
extern unsigned long memory_end;

#endif /* !__ASSEMBLY__ */

#define PAGE_OFFSET 0x00000000

#ifndef __ASSEMBLY__

/* No virtual memory. */
#define __virt_to_phys(addr) (addr)
#define __phys_to_virt(addr) (addr)

#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)

#define virt_to_page(addr) (mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT))
#define page_to_virt(page) ((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET)

//#define pfn_to_page(pfn) virt_to_page(pfn_to_virt(pfn))
//#define page_to_pfn(page) virt_to_pfn(page_to_virt(page))
#define pfn_valid(pfn) ((pfn) < max_mapnr)

#define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \
((void *)(kaddr) < (void *)memory_end))

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC )

#define __pa(vaddr) ((unsigned long)(vaddr))
#define __va(paddr) ((void *)(paddr))

#endif /* __ASSEMBLY__ */

#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>

#endif /* __KERNEL__ */

#endif /* _LM32_PAGE_H */
17 changes: 1 addition & 16 deletions arch/lm32/include/asm/param.h
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
#ifndef _LM32_ASM_PARAM_H
#define _LM32_ASM_PARAM_H

#ifdef __KERNEL__
#define HZ CONFIG_HZ /* Internal kernel timer frequency */
#define USER_HZ HZ
#define CLOCKS_PER_SEC (USER_HZ)
#endif

#ifndef NOGROUP
#define NOGROUP (-1)
#endif

#define MAXHOSTNAMELEN 64 /* max length of hostname */

#endif /* _LM32_ASM_PARAM_H */
#include <asm-generic/param.h>
Loading

0 comments on commit 84422e8

Please sign in to comment.