xtensa: remove NO_IRQ definitions

These definitions (-1) were correct when used as a hardware IRQ number,
but are incorrect as a mapped IRQ number.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: fix build warning in 64-bit build environment

This fixes the following build warnings:

arch/xtensa/mm/misc.S: Assembler messages:
arch/xtensa/mm/misc.S:143: Warning: value 0xffffffff30000106 truncated to 0x30000106
arch/xtensa/mm/misc.S:197: Warning: value 0xffffffff30000106 truncated to 0x30000106

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: fix build warning from gcc-4.7.2

This fixes the following build warning:

arch/xtensa/include/asm/vectors.h:70:5: warning: "XCHAL_HAVE_VECBASE" is not defined [-Wundef]

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: fix arch spinlock function names

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: fix __delay for small loop count

Avoid __delay counter underflow for loop counts < 2.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: enable HAVE_IRQ_TIME_ACCOUNTING

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: mark ccount as continuous clocksource

This allows ccount to be used as highres timer.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: update clockevent setup for SMP

Provide per-cpu ccount_timer objects and use them appropriately.
Extract per-cpu clockevent setup function.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: call check_s32c1i after trap_init

Otherwise exceptions may occur prior to exception handling mechanism
initialization, resulting in silently dead system.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: move init_mmu declaration to mmu_context.h

Secondary CPUs need this declaration to initialize their MMUs.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: move built-in PIC to drivers/irqchip

Extract xtensa built-in interrupt controller implementation from
xtensa/kernel/irq.c and move it to other irqchips, providing way to
instantiate it from the device tree.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: clean up do_interrupt/do_IRQ

- set up irq registers and call irq_enter/irq_exit once for each kernel
  entry due to interrupt;
- don't attempt to clear current IRQ in the do_interrupt, IRQ handler
  will take care of it;
- find pending interrupt with highest priority before every ISR
  invocation.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: clear timer IRQ unconditionally in its handler

PIC irq_ack doesn't clear timer IRQ, because timer interrupt handler
usually set up new timer by writing to ccompare register and thus
clearing timer IRQ. However timer may not be set up in the IRQ handler,
e.g. with tickless idle on SMP, or when CPU is going offline, leaving
timer IRQ raised and making do_interrupt attempting to handle it
forever.

To fix this always write current value of ccompare SR chosen to be linux
timer back to that SR on entry to timer interrupt handler.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: add MX irqchip

MX is an interrupt distributor used in some SMP-capable xtensa
configurations.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: add SMP support

This is largely based on SMP code from the xtensa-2.6.29-smp tree by
Piet Delaney, Marc Gauthier, Joe Taylor, Christian Zankel (and possibly
other Tensilica folks).

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: add Three Core HiFi-2 MX Variant.

This variant is equipped with MX and is capable of running SMP linux.

Signed-off-by: Piet Delaney <piet.delaney@gmail.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: implement CPU hotplug

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: deliver signal raised in double exception handler

This fixes infinite loop in the kernel on userspace access to unaligned
address in unmapped memory region.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
xtensa: use buddy allocator instead of slub for page table allocation

This fixes kernel crash in __slab_free when CONFIG_SLUB is selected and
USE_SPLIT_PTLOCKS is true.

This happens because spinlock_t ptl and struct page *first_page overlap
in the struct page. The following call chain makes allocation of order
3 and initializes first_page pointer in its 7 tail pages:

 do_page_fault
  handle_mm_fault
   __pte_alloc
    kmem_cache_alloc
     __slab_alloc
      new_slab
       __alloc_pages_nodemask
        get_page_from_freelist
         prep_compound_page

Later pte_offset_map_lock is called with one of these tail pages
overwriting its first_page pointer:

 do_fork
  copy_process
   dup_mm
    copy_page_range
     copy_pte_range
      pte_alloc_map_lock
       pte_offset_map_lock

Finally kmem_cache_free is called for that tail page, which calls
slab_free(s, virt_to_head_page(x),... but virt_to_head_page here
returns NULL, because the page's first_page pointer was overwritten
earlier:

 exit_mmap
  free_pgtables
   free_pgd_range
    free_pud_range
     free_pmd_range
      free_pte_range
       pte_free
        kmem_cache_free
         slab_free
          __slab_free

__slab_free touches NULL struct page.

Slab should not be used to allocate page tables.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>