summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ioctl/ioctl-number.txt1
-rw-r--r--MAINTAINERS13
-rw-r--r--Makefile8
-rw-r--r--arch/tile/Kbuild3
-rw-r--r--arch/tile/Kconfig481
-rw-r--r--arch/tile/Kconfig.debug26
-rw-r--r--arch/tile/Makefile77
-rw-r--r--arch/tile/configs/tilegx_defconfig411
-rw-r--r--arch/tile/configs/tilepro_defconfig524
-rw-r--r--arch/tile/gxio/Kconfig34
-rw-r--r--arch/tile/gxio/Makefile11
-rw-r--r--arch/tile/gxio/dma_queue.c176
-rw-r--r--arch/tile/gxio/iorpc_globals.c89
-rw-r--r--arch/tile/gxio/iorpc_mpipe.c593
-rw-r--r--arch/tile/gxio/iorpc_mpipe_info.c102
-rw-r--r--arch/tile/gxio/iorpc_trio.c350
-rw-r--r--arch/tile/gxio/iorpc_uart.c77
-rw-r--r--arch/tile/gxio/iorpc_usb_host.c99
-rw-r--r--arch/tile/gxio/kiorpc.c61
-rw-r--r--arch/tile/gxio/mpipe.c584
-rw-r--r--arch/tile/gxio/trio.c49
-rw-r--r--arch/tile/gxio/uart.c87
-rw-r--r--arch/tile/gxio/usb_host.c91
-rw-r--r--arch/tile/include/arch/mpipe.h371
-rw-r--r--arch/tile/include/arch/mpipe_constants.h42
-rw-r--r--arch/tile/include/arch/mpipe_def.h39
-rw-r--r--arch/tile/include/arch/mpipe_shm.h521
-rw-r--r--arch/tile/include/arch/mpipe_shm_def.h23
-rw-r--r--arch/tile/include/arch/spr_def.h109
-rw-r--r--arch/tile/include/arch/trio.h111
-rw-r--r--arch/tile/include/arch/trio_constants.h36
-rw-r--r--arch/tile/include/arch/trio_def.h41
-rw-r--r--arch/tile/include/arch/trio_pcie_intfc.h229
-rw-r--r--arch/tile/include/arch/trio_pcie_intfc_def.h32
-rw-r--r--arch/tile/include/arch/trio_pcie_rc.h156
-rw-r--r--arch/tile/include/arch/trio_pcie_rc_def.h24
-rw-r--r--arch/tile/include/arch/trio_shm.h125
-rw-r--r--arch/tile/include/arch/trio_shm_def.h19
-rw-r--r--arch/tile/include/arch/uart.h300
-rw-r--r--arch/tile/include/arch/uart_def.h120
-rw-r--r--arch/tile/include/arch/usb_host.h26
-rw-r--r--arch/tile/include/arch/usb_host_def.h19
-rw-r--r--arch/tile/include/asm/Kbuild18
-rw-r--r--arch/tile/include/asm/asm-offsets.h1
-rw-r--r--arch/tile/include/asm/atomic.h210
-rw-r--r--arch/tile/include/asm/atomic_32.h297
-rw-r--r--arch/tile/include/asm/atomic_64.h200
-rw-r--r--arch/tile/include/asm/backtrace.h162
-rw-r--r--arch/tile/include/asm/barrier.h100
-rw-r--r--arch/tile/include/asm/bitops.h94
-rw-r--r--arch/tile/include/asm/bitops_32.h126
-rw-r--r--arch/tile/include/asm/bitops_64.h95
-rw-r--r--arch/tile/include/asm/cache.h64
-rw-r--r--arch/tile/include/asm/cacheflush.h160
-rw-r--r--arch/tile/include/asm/checksum.h42
-rw-r--r--arch/tile/include/asm/cmpxchg.h132
-rw-r--r--arch/tile/include/asm/compat.h233
-rw-r--r--arch/tile/include/asm/current.h31
-rw-r--r--arch/tile/include/asm/delay.h34
-rw-r--r--arch/tile/include/asm/device.h33
-rw-r--r--arch/tile/include/asm/div64.h17
-rw-r--r--arch/tile/include/asm/dma-mapping.h50
-rw-r--r--arch/tile/include/asm/dma.h25
-rw-r--r--arch/tile/include/asm/elf.h182
-rw-r--r--arch/tile/include/asm/fixmap.h87
-rw-r--r--arch/tile/include/asm/ftrace.h42
-rw-r--r--arch/tile/include/asm/futex.h166
-rw-r--r--arch/tile/include/asm/hardirq.h45
-rw-r--r--arch/tile/include/asm/hardwall.h30
-rw-r--r--arch/tile/include/asm/highmem.h71
-rw-r--r--arch/tile/include/asm/homecache.h123
-rw-r--r--arch/tile/include/asm/hugetlb.h122
-rw-r--r--arch/tile/include/asm/hv_driver.h60
-rw-r--r--arch/tile/include/asm/ide.h25
-rw-r--r--arch/tile/include/asm/insn.h59
-rw-r--r--arch/tile/include/asm/io.h509
-rw-r--r--arch/tile/include/asm/irq.h87
-rw-r--r--arch/tile/include/asm/irq_work.h15
-rw-r--r--arch/tile/include/asm/irqflags.h311
-rw-r--r--arch/tile/include/asm/jump_label.h58
-rw-r--r--arch/tile/include/asm/kdebug.h28
-rw-r--r--arch/tile/include/asm/kexec.h65
-rw-r--r--arch/tile/include/asm/kgdb.h71
-rw-r--r--arch/tile/include/asm/kmap_types.h28
-rw-r--r--arch/tile/include/asm/kprobes.h83
-rw-r--r--arch/tile/include/asm/linkage.h51
-rw-r--r--arch/tile/include/asm/mmu.h32
-rw-r--r--arch/tile/include/asm/mmu_context.h137
-rw-r--r--arch/tile/include/asm/mmzone.h70
-rw-r--r--arch/tile/include/asm/module.h40
-rw-r--r--arch/tile/include/asm/page.h345
-rw-r--r--arch/tile/include/asm/pci.h229
-rw-r--r--arch/tile/include/asm/percpu.h52
-rw-r--r--arch/tile/include/asm/perf_event.h22
-rw-r--r--arch/tile/include/asm/pgalloc.h164
-rw-r--r--arch/tile/include/asm/pgtable.h518
-rw-r--r--arch/tile/include/asm/pgtable_32.h122
-rw-r--r--arch/tile/include/asm/pgtable_64.h172
-rw-r--r--arch/tile/include/asm/pmc.h64
-rw-r--r--arch/tile/include/asm/processor.h368
-rw-r--r--arch/tile/include/asm/ptrace.h97
-rw-r--r--arch/tile/include/asm/sections.h44
-rw-r--r--arch/tile/include/asm/setup.h57
-rw-r--r--arch/tile/include/asm/sigframe.h33
-rw-r--r--arch/tile/include/asm/signal.h29
-rw-r--r--arch/tile/include/asm/smp.h139
-rw-r--r--arch/tile/include/asm/spinlock.h24
-rw-r--r--arch/tile/include/asm/spinlock_32.h109
-rw-r--r--arch/tile/include/asm/spinlock_64.h138
-rw-r--r--arch/tile/include/asm/spinlock_types.h60
-rw-r--r--arch/tile/include/asm/stack.h73
-rw-r--r--arch/tile/include/asm/string.h34
-rw-r--r--arch/tile/include/asm/switch_to.h77
-rw-r--r--arch/tile/include/asm/syscall.h111
-rw-r--r--arch/tile/include/asm/syscalls.h70
-rw-r--r--arch/tile/include/asm/thread_info.h167
-rw-r--r--arch/tile/include/asm/tile-desc.h19
-rw-r--r--arch/tile/include/asm/tile-desc_32.h553
-rw-r--r--arch/tile/include/asm/tile-desc_64.h483
-rw-r--r--arch/tile/include/asm/timex.h52
-rw-r--r--arch/tile/include/asm/tlb.h25
-rw-r--r--arch/tile/include/asm/tlbflush.h123
-rw-r--r--arch/tile/include/asm/topology.h52
-rw-r--r--arch/tile/include/asm/traps.h93
-rw-r--r--arch/tile/include/asm/uaccess.h411
-rw-r--r--arch/tile/include/asm/unaligned.h43
-rw-r--r--arch/tile/include/asm/unistd.h20
-rw-r--r--arch/tile/include/asm/user.h21
-rw-r--r--arch/tile/include/asm/vdso.h55
-rw-r--r--arch/tile/include/asm/vga.h39
-rw-r--r--arch/tile/include/asm/word-at-a-time.h43
-rw-r--r--arch/tile/include/gxio/common.h40
-rw-r--r--arch/tile/include/gxio/dma_queue.h161
-rw-r--r--arch/tile/include/gxio/iorpc_globals.h38
-rw-r--r--arch/tile/include/gxio/iorpc_mpipe.h144
-rw-r--r--arch/tile/include/gxio/iorpc_mpipe_info.h50
-rw-r--r--arch/tile/include/gxio/iorpc_trio.h104
-rw-r--r--arch/tile/include/gxio/iorpc_uart.h40
-rw-r--r--arch/tile/include/gxio/iorpc_usb_host.h46
-rw-r--r--arch/tile/include/gxio/kiorpc.h29
-rw-r--r--arch/tile/include/gxio/mpipe.h1871
-rw-r--r--arch/tile/include/gxio/trio.h298
-rw-r--r--arch/tile/include/gxio/uart.h105
-rw-r--r--arch/tile/include/gxio/usb_host.h87
-rw-r--r--arch/tile/include/hv/drv_mpipe_intf.h605
-rw-r--r--arch/tile/include/hv/drv_mshim_intf.h50
-rw-r--r--arch/tile/include/hv/drv_pcie_rc_intf.h38
-rw-r--r--arch/tile/include/hv/drv_srom_intf.h41
-rw-r--r--arch/tile/include/hv/drv_trio_intf.h199
-rw-r--r--arch/tile/include/hv/drv_uart_intf.h33
-rw-r--r--arch/tile/include/hv/drv_usb_host_intf.h39
-rw-r--r--arch/tile/include/hv/drv_xgbe_impl.h300
-rw-r--r--arch/tile/include/hv/drv_xgbe_intf.h615
-rw-r--r--arch/tile/include/hv/hypervisor.h2656
-rw-r--r--arch/tile/include/hv/iorpc.h714
-rw-r--r--arch/tile/include/hv/netio_errors.h122
-rw-r--r--arch/tile/include/hv/netio_intf.h2975
-rw-r--r--arch/tile/include/hv/syscall_public.h42
-rw-r--r--arch/tile/include/uapi/arch/abi.h101
-rw-r--r--arch/tile/include/uapi/arch/chip.h22
-rw-r--r--arch/tile/include/uapi/arch/chip_tilegx.h259
-rw-r--r--arch/tile/include/uapi/arch/chip_tilepro.h259
-rw-r--r--arch/tile/include/uapi/arch/icache.h94
-rw-r--r--arch/tile/include/uapi/arch/interrupts.h20
-rw-r--r--arch/tile/include/uapi/arch/interrupts_32.h310
-rw-r--r--arch/tile/include/uapi/arch/interrupts_64.h279
-rw-r--r--arch/tile/include/uapi/arch/intreg.h71
-rw-r--r--arch/tile/include/uapi/arch/opcode.h22
-rw-r--r--arch/tile/include/uapi/arch/opcode_tilegx.h1407
-rw-r--r--arch/tile/include/uapi/arch/opcode_tilepro.h1473
-rw-r--r--arch/tile/include/uapi/arch/sim.h644
-rw-r--r--arch/tile/include/uapi/arch/sim_def.h506
-rw-r--r--arch/tile/include/uapi/arch/spr_def.h27
-rw-r--r--arch/tile/include/uapi/arch/spr_def_32.h256
-rw-r--r--arch/tile/include/uapi/arch/spr_def_64.h217
-rw-r--r--arch/tile/include/uapi/asm/Kbuild24
-rw-r--r--arch/tile/include/uapi/asm/auxvec.h24
-rw-r--r--arch/tile/include/uapi/asm/bitsperlong.h27
-rw-r--r--arch/tile/include/uapi/asm/byteorder.h20
-rw-r--r--arch/tile/include/uapi/asm/cachectl.h43
-rw-r--r--arch/tile/include/uapi/asm/hardwall.h52
-rw-r--r--arch/tile/include/uapi/asm/kvm_para.h2
-rw-r--r--arch/tile/include/uapi/asm/mman.h43
-rw-r--r--arch/tile/include/uapi/asm/ptrace.h99
-rw-r--r--arch/tile/include/uapi/asm/setup.h22
-rw-r--r--arch/tile/include/uapi/asm/sigcontext.h44
-rw-r--r--arch/tile/include/uapi/asm/siginfo.h27
-rw-r--r--arch/tile/include/uapi/asm/signal.h28
-rw-r--r--arch/tile/include/uapi/asm/stat.h5
-rw-r--r--arch/tile/include/uapi/asm/swab.h24
-rw-r--r--arch/tile/include/uapi/asm/unistd.h38
-rw-r--r--arch/tile/kernel/Makefile38
-rw-r--r--arch/tile/kernel/asm-offsets.c84
-rw-r--r--arch/tile/kernel/backtrace.c683
-rw-r--r--arch/tile/kernel/compat.c117
-rw-r--r--arch/tile/kernel/compat_signal.c172
-rw-r--r--arch/tile/kernel/early_printk.c75
-rw-r--r--arch/tile/kernel/entry.S64
-rw-r--r--arch/tile/kernel/ftrace.c239
-rw-r--r--arch/tile/kernel/hardwall.c1096
-rw-r--r--arch/tile/kernel/head_32.S183
-rw-r--r--arch/tile/kernel/head_64.S279
-rw-r--r--arch/tile/kernel/hvglue.S76
-rw-r--r--arch/tile/kernel/hvglue_trace.c270
-rw-r--r--arch/tile/kernel/intvec_32.S1906
-rw-r--r--arch/tile/kernel/intvec_64.S1564
-rw-r--r--arch/tile/kernel/irq.c280
-rw-r--r--arch/tile/kernel/jump_label.c62
-rw-r--r--arch/tile/kernel/kgdb.c497
-rw-r--r--arch/tile/kernel/kprobes.c527
-rw-r--r--arch/tile/kernel/machine_kexec.c298
-rw-r--r--arch/tile/kernel/mcount_64.S211
-rw-r--r--arch/tile/kernel/messaging.c115
-rw-r--r--arch/tile/kernel/module.c231
-rw-r--r--arch/tile/kernel/pci-dma.c607
-rw-r--r--arch/tile/kernel/pci.c592
-rw-r--r--arch/tile/kernel/pci_gx.c1592
-rw-r--r--arch/tile/kernel/perf_event.c1005
-rw-r--r--arch/tile/kernel/pmc.c118
-rw-r--r--arch/tile/kernel/proc.c160
-rw-r--r--arch/tile/kernel/process.c659
-rw-r--r--arch/tile/kernel/ptrace.c316
-rw-r--r--arch/tile/kernel/reboot.c51
-rw-r--r--arch/tile/kernel/regs_32.S145
-rw-r--r--arch/tile/kernel/regs_64.S145
-rw-r--r--arch/tile/kernel/relocate_kernel_32.S269
-rw-r--r--arch/tile/kernel/relocate_kernel_64.S263
-rw-r--r--arch/tile/kernel/setup.c1743
-rw-r--r--arch/tile/kernel/signal.c411
-rw-r--r--arch/tile/kernel/single_step.c786
-rw-r--r--arch/tile/kernel/smp.c287
-rw-r--r--arch/tile/kernel/smpboot.c269
-rw-r--r--arch/tile/kernel/stack.c539
-rw-r--r--arch/tile/kernel/sys.c130
-rw-r--r--arch/tile/kernel/sysfs.c266
-rw-r--r--arch/tile/kernel/tile-desc_32.c2605
-rw-r--r--arch/tile/kernel/tile-desc_64.c2218
-rw-r--r--arch/tile/kernel/time.c306
-rw-r--r--arch/tile/kernel/tlb.c104
-rw-r--r--arch/tile/kernel/traps.c421
-rw-r--r--arch/tile/kernel/unaligned.c1603
-rw-r--r--arch/tile/kernel/usb.c71
-rw-r--r--arch/tile/kernel/vdso.c197
-rw-r--r--arch/tile/kernel/vdso/Makefile117
-rw-r--r--arch/tile/kernel/vdso/vdso.S28
-rw-r--r--arch/tile/kernel/vdso/vdso.lds.S89
-rw-r--r--arch/tile/kernel/vdso/vdso32.S28
-rw-r--r--arch/tile/kernel/vdso/vgettimeofday.c198
-rw-r--r--arch/tile/kernel/vdso/vrt_sigreturn.S30
-rw-r--r--arch/tile/kernel/vmlinux.lds.S105
-rw-r--r--arch/tile/kvm/Kconfig39
-rw-r--r--arch/tile/lib/Makefile19
-rw-r--r--arch/tile/lib/atomic_32.c206
-rw-r--r--arch/tile/lib/atomic_asm_32.S205
-rw-r--r--arch/tile/lib/cacheflush.c167
-rw-r--r--arch/tile/lib/checksum.c89
-rw-r--r--arch/tile/lib/cpumask.c54
-rw-r--r--arch/tile/lib/delay.c45
-rw-r--r--arch/tile/lib/exports.c94
-rw-r--r--arch/tile/lib/memchr_32.c71
-rw-r--r--arch/tile/lib/memchr_64.c69
-rw-r--r--arch/tile/lib/memcpy_32.S544
-rw-r--r--arch/tile/lib/memcpy_64.c367
-rw-r--r--arch/tile/lib/memcpy_user_64.c85
-rw-r--r--arch/tile/lib/memmove.c63
-rw-r--r--arch/tile/lib/memset_32.c143
-rw-r--r--arch/tile/lib/memset_64.c142
-rw-r--r--arch/tile/lib/spinlock_32.c251
-rw-r--r--arch/tile/lib/spinlock_64.c97
-rw-r--r--arch/tile/lib/spinlock_common.h64
-rw-r--r--arch/tile/lib/strchr_32.c64
-rw-r--r--arch/tile/lib/strchr_64.c62
-rw-r--r--arch/tile/lib/string-endian.h44
-rw-r--r--arch/tile/lib/strlen_32.c36
-rw-r--r--arch/tile/lib/strlen_64.c35
-rw-r--r--arch/tile/lib/strnlen_32.c47
-rw-r--r--arch/tile/lib/strnlen_64.c48
-rw-r--r--arch/tile/lib/uaccess.c24
-rw-r--r--arch/tile/lib/usercopy_32.S89
-rw-r--r--arch/tile/lib/usercopy_64.S89
-rw-r--r--arch/tile/mm/Makefile9
-rw-r--r--arch/tile/mm/elf.c165
-rw-r--r--arch/tile/mm/extable.c30
-rw-r--r--arch/tile/mm/fault.c924
-rw-r--r--arch/tile/mm/highmem.c277
-rw-r--r--arch/tile/mm/homecache.c428
-rw-r--r--arch/tile/mm/hugetlbpage.c348
-rw-r--r--arch/tile/mm/init.c956
-rw-r--r--arch/tile/mm/migrate.h56
-rw-r--r--arch/tile/mm/migrate_32.S192
-rw-r--r--arch/tile/mm/migrate_64.S167
-rw-r--r--arch/tile/mm/mmap.c93
-rw-r--r--arch/tile/mm/pgtable.c550
-rw-r--r--drivers/pci/quirks.c19
-rw-r--r--samples/kprobes/kprobe_example.c8
-rw-r--r--tools/arch/tile/include/asm/barrier.h16
-rw-r--r--tools/arch/tile/include/uapi/asm/bitsperlong.h27
-rw-r--r--tools/arch/tile/include/uapi/asm/mman.h16
-rw-r--r--tools/scripts/Makefile.arch11
-rwxr-xr-xtools/testing/ktest/ktest.pl2
300 files changed, 1 insertions, 69477 deletions
diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 6501389d55b9..84bb74dcae12 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -305,7 +305,6 @@ Code Seq#(hex) Include File Comments
3050xA0 all linux/sdp/sdp.h Industrial Device Project 3050xA0 all linux/sdp/sdp.h Industrial Device Project
306 <mailto:kenji@bitgate.com> 306 <mailto:kenji@bitgate.com>
3070xA1 0 linux/vtpm_proxy.h TPM Emulator Proxy Driver 3070xA1 0 linux/vtpm_proxy.h TPM Emulator Proxy Driver
3080xA2 00-0F arch/tile/include/asm/hardwall.h
3090xA3 80-8F Port ACL in development: 3080xA3 80-8F Port ACL in development:
310 <mailto:tlewis@mindspring.com> 309 <mailto:tlewis@mindspring.com>
3110xA3 90-9F linux/dtlk.h 3100xA3 90-9F linux/dtlk.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 9e0c097824f5..ac6083ae4f94 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13840,19 +13840,6 @@ S: Orphan
13840F: drivers/net/wireless/ti/ 13840F: drivers/net/wireless/ti/
13841F: include/linux/wl12xx.h 13841F: include/linux/wl12xx.h
13842 13842
13843TILE ARCHITECTURE
13844W: http://www.mellanox.com/repository/solutions/tile-scm/
13845S: Orphan
13846F: arch/tile/
13847F: drivers/char/tile-srom.c
13848F: drivers/edac/tile_edac.c
13849F: drivers/net/ethernet/tile/
13850F: drivers/rtc/rtc-tile.c
13851F: drivers/tty/hvc/hvc_tile.c
13852F: drivers/tty/serial/tilegx.c
13853F: drivers/usb/host/*-tilegx.c
13854F: include/linux/usb/tilegx.h
13855
13856TIMEKEEPING, CLOCKSOURCE CORE, NTP, ALARMTIMER 13843TIMEKEEPING, CLOCKSOURCE CORE, NTP, ALARMTIMER
13857M: John Stultz <john.stultz@linaro.org> 13844M: John Stultz <john.stultz@linaro.org>
13858M: Thomas Gleixner <tglx@linutronix.de> 13845M: Thomas Gleixner <tglx@linutronix.de>
diff --git a/Makefile b/Makefile
index c4322dea3ca2..4114da991ae3 100644
--- a/Makefile
+++ b/Makefile
@@ -339,14 +339,6 @@ ifeq ($(ARCH),sh64)
339 SRCARCH := sh 339 SRCARCH := sh
340endif 340endif
341 341
342# Additional ARCH settings for tile
343ifeq ($(ARCH),tilepro)
344 SRCARCH := tile
345endif
346ifeq ($(ARCH),tilegx)
347 SRCARCH := tile
348endif
349
350KCONFIG_CONFIG ?= .config 342KCONFIG_CONFIG ?= .config
351export KCONFIG_CONFIG 343export KCONFIG_CONFIG
352 344
diff --git a/arch/tile/Kbuild b/arch/tile/Kbuild
deleted file mode 100644
index a9b922716092..000000000000
--- a/arch/tile/Kbuild
+++ /dev/null
@@ -1,3 +0,0 @@
1
2obj-y += kernel/
3obj-y += mm/
diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
deleted file mode 100644
index ef9d403cbbe4..000000000000
--- a/arch/tile/Kconfig
+++ /dev/null
@@ -1,481 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2# For a description of the syntax of this configuration file,
3# see Documentation/kbuild/kconfig-language.txt.
4
5config TILE
6 def_bool y
7 select ARCH_HAS_DEVMEM_IS_ALLOWED
8 select ARCH_HAVE_NMI_SAFE_CMPXCHG
9 select ARCH_WANT_FRAME_POINTERS
10 select CC_OPTIMIZE_FOR_SIZE
11 select EDAC_SUPPORT
12 select GENERIC_CLOCKEVENTS
13 select GENERIC_FIND_FIRST_BIT
14 select GENERIC_IRQ_PROBE
15 select GENERIC_IRQ_SHOW
16 select GENERIC_PENDING_IRQ if SMP
17 select GENERIC_STRNCPY_FROM_USER
18 select GENERIC_STRNLEN_USER
19 select HAVE_ARCH_SECCOMP_FILTER
20 select HAVE_ARCH_TRACEHOOK
21 select HAVE_CONTEXT_TRACKING
22 select HAVE_DEBUG_BUGVERBOSE
23 select HAVE_DEBUG_KMEMLEAK
24 select HAVE_DEBUG_STACKOVERFLOW
25 select HAVE_DMA_API_DEBUG
26 select HAVE_EXIT_THREAD
27 select HAVE_KVM if !TILEGX
28 select HAVE_NMI if USE_PMC
29 select HAVE_PERF_EVENTS
30 select HAVE_SYSCALL_TRACEPOINTS
31 select MODULES_USE_ELF_RELA
32 select SYSCTL_EXCEPTION_TRACE
33 select SYS_HYPERVISOR
34 select USER_STACKTRACE_SUPPORT
35 select USE_PMC if PERF_EVENTS
36 select VIRT_TO_BUS
37
38config MMU
39 def_bool y
40
41config GENERIC_CSUM
42 def_bool y
43
44config HAVE_ARCH_ALLOC_REMAP
45 def_bool y
46
47config HAVE_SETUP_PER_CPU_AREA
48 def_bool y
49
50config NEED_PER_CPU_PAGE_FIRST_CHUNK
51 def_bool y
52
53config SYS_SUPPORTS_HUGETLBFS
54 def_bool y
55
56# Support for additional huge page sizes besides HPAGE_SIZE.
57# The software support is currently only present in the TILE-Gx
58# hypervisor. TILEPro in any case does not support page sizes
59# larger than the default HPAGE_SIZE.
60config HUGETLB_SUPER_PAGES
61 depends on HUGETLB_PAGE && TILEGX
62 def_bool y
63
64config GENERIC_TIME_VSYSCALL
65 def_bool y
66
67# Enable PMC if PERF_EVENTS, OPROFILE, or WATCHPOINTS are enabled.
68config USE_PMC
69 bool
70
71# FIXME: tilegx can implement a more efficient rwsem.
72config RWSEM_GENERIC_SPINLOCK
73 def_bool y
74
75# We only support gcc 4.4 and above, so this should work.
76config ARCH_SUPPORTS_OPTIMIZED_INLINING
77 def_bool y
78
79config ARCH_PHYS_ADDR_T_64BIT
80 def_bool y
81
82config ARCH_DMA_ADDR_T_64BIT
83 def_bool y
84
85config NEED_DMA_MAP_STATE
86 def_bool y
87
88config ARCH_HAS_DMA_SET_COHERENT_MASK
89 bool
90
91config LOCKDEP_SUPPORT
92 def_bool y
93
94config STACKTRACE_SUPPORT
95 def_bool y
96 select STACKTRACE
97
98# We use discontigmem for now; at some point we may want to switch
99# to sparsemem (Tilera bug 7996).
100config ARCH_DISCONTIGMEM_ENABLE
101 def_bool y
102
103config ARCH_DISCONTIGMEM_DEFAULT
104 def_bool y
105
106config TRACE_IRQFLAGS_SUPPORT
107 def_bool y
108
109# SMP is required for Tilera Linux.
110config SMP
111 def_bool y
112
113config HVC_TILE
114 depends on TTY
115 select HVC_DRIVER
116 select HVC_IRQ if TILEGX
117 def_bool y
118
119# Building with ARCH=tilegx (or ARCH=tile) implies using the
120# 64-bit TILE-Gx toolchain, so force CONFIG_TILEGX on.
121config TILEGX
122 def_bool ARCH != "tilepro"
123 select ARCH_SUPPORTS_ATOMIC_RMW
124 select GENERIC_IRQ_LEGACY_ALLOC_HWIRQ
125 select HAVE_ARCH_JUMP_LABEL
126 select HAVE_ARCH_KGDB
127 select HAVE_DYNAMIC_FTRACE
128 select HAVE_FTRACE_MCOUNT_RECORD
129 select HAVE_FUNCTION_GRAPH_TRACER
130 select HAVE_FUNCTION_TRACER
131 select HAVE_KPROBES
132 select HAVE_KRETPROBES
133 select SPARSE_IRQ
134
135config TILEPRO
136 def_bool !TILEGX
137
138config 64BIT
139 def_bool TILEGX
140
141config ARCH_DEFCONFIG
142 string
143 default "arch/tile/configs/tilepro_defconfig" if !TILEGX
144 default "arch/tile/configs/tilegx_defconfig" if TILEGX
145
146config PGTABLE_LEVELS
147 int
148 default 3 if 64BIT
149 default 2
150
151source "init/Kconfig"
152
153source "kernel/Kconfig.freezer"
154
155menu "Tilera-specific configuration"
156
157config NR_CPUS
158 int "Maximum number of tiles (2-255)"
159 range 2 255
160 depends on SMP
161 default "64"
162 ---help---
163 Building with 64 is the recommended value, but a slightly
164 smaller kernel memory footprint results from using a smaller
165 value on chips with fewer tiles.
166
167choice
168 prompt "Kernel page size"
169 default PAGE_SIZE_64KB
170 help
171 This lets you select the page size of the kernel. For best
172 performance on memory-intensive applications, a page size of 64KB
173 is recommended. For workloads involving many small files, many
174 connections, etc., it may be better to select 16KB, which uses
175 memory more efficiently at some cost in TLB performance.
176
177 Note that for TILEPro, you must also rebuild the hypervisor
178 with a matching page size.
179
180config PAGE_SIZE_4KB
181 bool "4KB" if TILEPRO
182
183config PAGE_SIZE_16KB
184 bool "16KB"
185
186config PAGE_SIZE_64KB
187 bool "64KB"
188
189endchoice
190
191source "kernel/Kconfig.hz"
192
193config KEXEC
194 bool "kexec system call"
195 select KEXEC_CORE
196 ---help---
197 kexec is a system call that implements the ability to shutdown your
198 current kernel, and to start another kernel. It is like a reboot
199 but it is independent of the system firmware. It is used
200 to implement the "mboot" Tilera booter.
201
202 The name comes from the similarity to the exec system call.
203
204config COMPAT
205 bool "Support 32-bit TILE-Gx binaries in addition to 64-bit"
206 depends on TILEGX
207 select COMPAT_BINFMT_ELF
208 default y
209 ---help---
210 If enabled, the kernel will support running TILE-Gx binaries
211 that were built with the -m32 option.
212
213config SECCOMP
214 bool "Enable seccomp to safely compute untrusted bytecode"
215 depends on PROC_FS
216 help
217 This kernel feature is useful for number crunching applications
218 that may need to compute untrusted bytecode during their
219 execution. By using pipes or other transports made available to
220 the process as file descriptors supporting the read/write
221 syscalls, it's possible to isolate those applications in
222 their own address space using seccomp. Once seccomp is
223 enabled via prctl, it cannot be disabled and the task is only
224 allowed to execute a few safe syscalls defined by each seccomp
225 mode.
226
227 If unsure, say N.
228
229config SYSVIPC_COMPAT
230 def_bool y
231 depends on COMPAT && SYSVIPC
232
233# We do not currently support disabling HIGHMEM on tilepro.
234config HIGHMEM
235 bool # "Support for more than 512 MB of RAM"
236 default !TILEGX
237 ---help---
238 Linux can use the full amount of RAM in the system by
239 default. However, the address space of TILE processors is
240 only 4 Gigabytes large. That means that, if you have a large
241 amount of physical memory, not all of it can be "permanently
242 mapped" by the kernel. The physical memory that's not
243 permanently mapped is called "high memory".
244
245 If you are compiling a kernel which will never run on a
246 machine with more than 512 MB total physical RAM, answer
247 "false" here. This will result in the kernel mapping all of
248 physical memory into the top 1 GB of virtual memory space.
249
250 If unsure, say "true".
251
252config ZONE_DMA32
253 def_bool y
254
255config IOMMU_HELPER
256 bool
257
258config NEED_SG_DMA_LENGTH
259 bool
260
261config SWIOTLB
262 bool
263 default TILEGX
264 select DMA_DIRECT_OPS
265 select IOMMU_HELPER
266 select NEED_SG_DMA_LENGTH
267 select ARCH_HAS_DMA_SET_COHERENT_MASK
268
269# We do not currently support disabling NUMA.
270config NUMA
271 bool # "NUMA Memory Allocation and Scheduler Support"
272 depends on SMP && DISCONTIGMEM
273 default y
274 ---help---
275 NUMA memory allocation is required for TILE processors
276 unless booting with memory striping enabled in the
277 hypervisor, or with only a single memory controller.
278 It is recommended that this option always be enabled.
279
280config NODES_SHIFT
281 int "Log base 2 of the max number of memory controllers"
282 default 2
283 depends on NEED_MULTIPLE_NODES
284 ---help---
285 By default, 2, i.e. 2^2 == 4 DDR2 controllers.
286 In a system with more controllers, this value should be raised.
287
288choice
289 depends on !TILEGX
290 prompt "Memory split" if EXPERT
291 default VMSPLIT_3G
292 ---help---
293 Select the desired split between kernel and user memory.
294
295 If the address range available to the kernel is less than the
296 physical memory installed, the remaining memory will be available
297 as "high memory". Accessing high memory is a little more costly
298 than low memory, as it needs to be mapped into the kernel first.
299 Note that increasing the kernel address space limits the range
300 available to user programs, making the address space there
301 tighter. Selecting anything other than the default 3G/1G split
302 will also likely make your kernel incompatible with binary-only
303 kernel modules.
304
305 If you are not absolutely sure what you are doing, leave this
306 option alone!
307
308 config VMSPLIT_3_75G
309 bool "3.75G/0.25G user/kernel split (no kernel networking)"
310 config VMSPLIT_3_5G
311 bool "3.5G/0.5G user/kernel split"
312 config VMSPLIT_3G
313 bool "3G/1G user/kernel split"
314 config VMSPLIT_2_75G
315 bool "2.75G/1.25G user/kernel split (for full 1G low memory)"
316 config VMSPLIT_2_5G
317 bool "2.5G/1.5G user/kernel split"
318 config VMSPLIT_2_25G
319 bool "2.25G/1.75G user/kernel split"
320 config VMSPLIT_2G
321 bool "2G/2G user/kernel split"
322 config VMSPLIT_1G
323 bool "1G/3G user/kernel split"
324endchoice
325
326config PAGE_OFFSET
327 hex
328 depends on !64BIT
329 default 0xF0000000 if VMSPLIT_3_75G
330 default 0xE0000000 if VMSPLIT_3_5G
331 default 0xB0000000 if VMSPLIT_2_75G
332 default 0xA0000000 if VMSPLIT_2_5G
333 default 0x90000000 if VMSPLIT_2_25G
334 default 0x80000000 if VMSPLIT_2G
335 default 0x40000000 if VMSPLIT_1G
336 default 0xC0000000
337
338source "mm/Kconfig"
339
340source "kernel/Kconfig.preempt"
341
342config CMDLINE_BOOL
343 bool "Built-in kernel command line"
344 default n
345 ---help---
346 Allow for specifying boot arguments to the kernel at
347 build time. On some systems (e.g. embedded ones), it is
348 necessary or convenient to provide some or all of the
349 kernel boot arguments with the kernel itself (that is,
350 to not rely on the boot loader to provide them.)
351
352 To compile command line arguments into the kernel,
353 set this option to 'Y', then fill in the
354 the boot arguments in CONFIG_CMDLINE.
355
356 Systems with fully functional boot loaders (e.g. mboot, or
357 if booting over PCI) should leave this option set to 'N'.
358
359config CMDLINE
360 string "Built-in kernel command string"
361 depends on CMDLINE_BOOL
362 default ""
363 ---help---
364 Enter arguments here that should be compiled into the kernel
365 image and used at boot time. If the boot loader provides a
366 command line at boot time, it is appended to this string to
367 form the full kernel command line, when the system boots.
368
369 However, you can use the CONFIG_CMDLINE_OVERRIDE option to
370 change this behavior.
371
372 In most cases, the command line (whether built-in or provided
373 by the boot loader) should specify the device for the root
374 file system.
375
376config CMDLINE_OVERRIDE
377 bool "Built-in command line overrides boot loader arguments"
378 default n
379 depends on CMDLINE_BOOL
380 ---help---
381 Set this option to 'Y' to have the kernel ignore the boot loader
382 command line, and use ONLY the built-in command line.
383
384 This is used to work around broken boot loaders. This should
385 be set to 'N' under normal conditions.
386
387config VMALLOC_RESERVE
388 hex
389 default 0x2000000
390
391config HARDWALL
392 bool "Hardwall support to allow access to user dynamic network"
393 default y
394
395config KERNEL_PL
396 int "Processor protection level for kernel"
397 range 1 2
398 default 2 if TILEGX
399 default 1 if !TILEGX
400 ---help---
401 Since MDE 4.2, the Tilera hypervisor runs the kernel
402 at PL2 by default. If running under an older hypervisor,
403 or as a KVM guest, you must run at PL1. (The current
404 hypervisor may also be recompiled with "make HV_PL=2" to
405 allow it to run a kernel at PL1, but clients running at PL1
406 are not expected to be supported indefinitely.)
407
408 If you're not sure, don't change the default.
409
410source "arch/tile/gxio/Kconfig"
411
412endmenu # Tilera-specific configuration
413
414menu "Bus options"
415
416config PCI
417 bool "PCI support"
418 default y
419 select PCI_DOMAINS
420 select GENERIC_PCI_IOMAP
421 select TILE_GXIO_TRIO if TILEGX
422 select PCI_MSI if TILEGX
423 ---help---
424 Enable PCI root complex support, so PCIe endpoint devices can
425 be attached to the Tile chip. Many, but not all, PCI devices
426 are supported under Tilera's root complex driver.
427
428config PCI_DOMAINS
429 bool
430
431config NO_IOMEM
432 def_bool !PCI
433
434config NO_IOPORT_MAP
435 def_bool !PCI
436
437config TILE_PCI_IO
438 bool "PCI I/O space support"
439 default n
440 depends on PCI
441 depends on TILEGX
442 ---help---
443 Enable PCI I/O space support on TILEGx. Since the PCI I/O space
444 is used by few modern PCIe endpoint devices, its support is disabled
445 by default to save the TRIO PIO Region resource for other purposes.
446
447source "drivers/pci/Kconfig"
448
449config TILE_USB
450 tristate "Tilera USB host adapter support"
451 default y
452 depends on USB
453 depends on TILEGX
454 select TILE_GXIO_USB_HOST
455 ---help---
456 Provides USB host adapter support for the built-in EHCI and OHCI
457 interfaces on TILE-Gx chips.
458
459endmenu
460
461menu "Executable file formats"
462
463source "fs/Kconfig.binfmt"
464
465endmenu
466
467source "net/Kconfig"
468
469source "drivers/Kconfig"
470
471source "fs/Kconfig"
472
473source "arch/tile/Kconfig.debug"
474
475source "security/Kconfig"
476
477source "crypto/Kconfig"
478
479source "lib/Kconfig"
480
481source "arch/tile/kvm/Kconfig"
diff --git a/arch/tile/Kconfig.debug b/arch/tile/Kconfig.debug
deleted file mode 100644
index 9f665d1a805f..000000000000
--- a/arch/tile/Kconfig.debug
+++ /dev/null
@@ -1,26 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2menu "Kernel hacking"
3
4source "lib/Kconfig.debug"
5
6config EARLY_PRINTK
7 bool "Early printk" if EXPERT && DEBUG_KERNEL
8 default y
9 help
10 Write kernel log output directly via the hypervisor console.
11
12 This is useful for kernel debugging when your machine crashes very
13 early before the console code is initialized. For normal operation
14 it is not recommended because it looks ugly and doesn't cooperate
15 with klogd/syslogd. You should normally N here,
16 unless you want to debug such a crash.
17
18config TILE_HVGLUE_TRACE
19 bool "Provide wrapper functions for hypervisor ABI calls"
20 default n
21 help
22 Provide wrapper functions for the hypervisor ABI calls
23 defined in arch/tile/kernel/hvglue.S. This allows tracing
24 mechanisms, etc., to have visibility into those calls.
25
26endmenu
diff --git a/arch/tile/Makefile b/arch/tile/Makefile
deleted file mode 100644
index 8fa0befba32b..000000000000
--- a/arch/tile/Makefile
+++ /dev/null
@@ -1,77 +0,0 @@
1#
2# This file is subject to the terms and conditions of the GNU General Public
3# License. See the file "COPYING" in the main directory of this archive
4# for more details.
5#
6# This file is included by the global makefile so that you can add your own
7# architecture-specific flags and dependencies. Remember to do have actions
8# for "archclean" and "archdep" for cleaning up and making dependencies for
9# this architecture
10
11# If building with TILERA_ROOT set (i.e. using the Tilera Multicore
12# Development Environment) we can set CROSS_COMPILE based on that.
13# If we're not cross-compiling, make sure we're on the right architecture.
14# Only bother to test for a few common targets, to avoid useless errors.
15ifeq ($(CROSS_COMPILE),)
16 ifdef TILERA_ROOT
17 CROSS_COMPILE := $(TILERA_ROOT)/bin/tile-
18 else
19 goals := $(if $(MAKECMDGOALS), $(MAKECMDGOALS), all)
20 ifneq ($(strip $(filter vmlinux modules all,$(goals))),)
21 HOST_ARCH := $(shell uname -m)
22 ifneq ($(HOST_ARCH),$(ARCH))
23$(error Set TILERA_ROOT or CROSS_COMPILE when building $(ARCH) on $(HOST_ARCH))
24 endif
25 endif
26 endif
27endif
28
29# The tile compiler may emit .eh_frame information for backtracing.
30# In kernel modules, this causes load failures due to unsupported relocations.
31KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
32
33LIBGCC_PATH := \
34 $(shell $(CC) $(KBUILD_CFLAGS) $(KCFLAGS) -print-libgcc-file-name)
35
36# Provide the path to use for "make defconfig".
37# We default to the newer TILE-Gx architecture if only "tile" is given.
38ifeq ($(ARCH),tile)
39 KBUILD_DEFCONFIG := tilegx_defconfig
40else
41 KBUILD_DEFCONFIG := $(ARCH)_defconfig
42endif
43
44# Used as a file extension when useful, e.g. head_$(BITS).o
45# Not needed for (e.g.) "$(CC) -m32" since the compiler automatically
46# uses the right default anyway.
47export BITS
48ifeq ($(CONFIG_TILEGX),y)
49BITS := 64
50else
51BITS := 32
52endif
53
54CHECKFLAGS += -m$(BITS)
55
56head-y := arch/tile/kernel/head_$(BITS).o
57
58libs-y += arch/tile/lib/
59libs-y += $(LIBGCC_PATH)
60
61# See arch/tile/Kbuild for content of core part of the kernel
62core-y += arch/tile/
63
64core-$(CONFIG_TILE_GXIO) += arch/tile/gxio/
65
66ifdef TILERA_ROOT
67INSTALL_PATH ?= $(TILERA_ROOT)/tile/boot
68endif
69
70install:
71 install -D -m 755 vmlinux $(INSTALL_PATH)/vmlinux-$(KERNELRELEASE)
72 install -D -m 644 .config $(INSTALL_PATH)/config-$(KERNELRELEASE)
73 install -D -m 644 System.map $(INSTALL_PATH)/System.map-$(KERNELRELEASE)
74
75define archhelp
76 echo ' install - install kernel into $(INSTALL_PATH)'
77endef
diff --git a/arch/tile/configs/tilegx_defconfig b/arch/tile/configs/tilegx_defconfig
deleted file mode 100644
index 357a4c271ad4..000000000000
--- a/arch/tile/configs/tilegx_defconfig
+++ /dev/null
@@ -1,411 +0,0 @@
1CONFIG_TILEGX=y
2CONFIG_SYSVIPC=y
3CONFIG_POSIX_MQUEUE=y
4CONFIG_FHANDLE=y
5CONFIG_AUDIT=y
6CONFIG_NO_HZ=y
7CONFIG_BSD_PROCESS_ACCT=y
8CONFIG_BSD_PROCESS_ACCT_V3=y
9CONFIG_TASKSTATS=y
10CONFIG_TASK_DELAY_ACCT=y
11CONFIG_TASK_XACCT=y
12CONFIG_TASK_IO_ACCOUNTING=y
13CONFIG_LOG_BUF_SHIFT=19
14CONFIG_CGROUPS=y
15CONFIG_CGROUP_DEBUG=y
16CONFIG_CGROUP_DEVICE=y
17CONFIG_CPUSETS=y
18CONFIG_CGROUP_CPUACCT=y
19CONFIG_CGROUP_SCHED=y
20CONFIG_RT_GROUP_SCHED=y
21CONFIG_BLK_CGROUP=y
22CONFIG_NAMESPACES=y
23CONFIG_RELAY=y
24CONFIG_BLK_DEV_INITRD=y
25CONFIG_RD_XZ=y
26CONFIG_SYSCTL_SYSCALL=y
27CONFIG_EMBEDDED=y
28# CONFIG_COMPAT_BRK is not set
29CONFIG_PROFILING=y
30CONFIG_KPROBES=y
31CONFIG_MODULES=y
32CONFIG_MODULE_FORCE_LOAD=y
33CONFIG_MODULE_UNLOAD=y
34CONFIG_BLK_DEV_INTEGRITY=y
35CONFIG_PARTITION_ADVANCED=y
36CONFIG_OSF_PARTITION=y
37CONFIG_AMIGA_PARTITION=y
38CONFIG_MAC_PARTITION=y
39CONFIG_BSD_DISKLABEL=y
40CONFIG_MINIX_SUBPARTITION=y
41CONFIG_SOLARIS_X86_PARTITION=y
42CONFIG_UNIXWARE_DISKLABEL=y
43CONFIG_SGI_PARTITION=y
44CONFIG_SUN_PARTITION=y
45CONFIG_KARMA_PARTITION=y
46CONFIG_CFQ_GROUP_IOSCHED=y
47CONFIG_NR_CPUS=100
48CONFIG_HZ_100=y
49# CONFIG_COMPACTION is not set
50CONFIG_PREEMPT_VOLUNTARY=y
51CONFIG_TILE_PCI_IO=y
52CONFIG_PCI_DEBUG=y
53# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
54CONFIG_BINFMT_MISC=y
55CONFIG_NET=y
56CONFIG_PACKET=y
57CONFIG_UNIX=y
58CONFIG_XFRM_USER=y
59CONFIG_XFRM_SUB_POLICY=y
60CONFIG_XFRM_STATISTICS=y
61CONFIG_NET_KEY=m
62CONFIG_NET_KEY_MIGRATE=y
63CONFIG_INET=y
64CONFIG_IP_MULTICAST=y
65CONFIG_IP_ADVANCED_ROUTER=y
66CONFIG_IP_MULTIPLE_TABLES=y
67CONFIG_IP_ROUTE_MULTIPATH=y
68CONFIG_IP_ROUTE_VERBOSE=y
69CONFIG_NET_IPIP=m
70CONFIG_IP_MROUTE=y
71CONFIG_IP_PIMSM_V1=y
72CONFIG_IP_PIMSM_V2=y
73CONFIG_SYN_COOKIES=y
74CONFIG_INET_AH=m
75CONFIG_INET_ESP=m
76CONFIG_INET_IPCOMP=m
77CONFIG_INET_XFRM_MODE_TRANSPORT=m
78CONFIG_INET_XFRM_MODE_TUNNEL=m
79CONFIG_INET_XFRM_MODE_BEET=m
80CONFIG_INET_DIAG=m
81CONFIG_TCP_CONG_ADVANCED=y
82CONFIG_TCP_CONG_HSTCP=m
83CONFIG_TCP_CONG_HYBLA=m
84CONFIG_TCP_CONG_SCALABLE=m
85CONFIG_TCP_CONG_LP=m
86CONFIG_TCP_CONG_VENO=m
87CONFIG_TCP_CONG_YEAH=m
88CONFIG_TCP_CONG_ILLINOIS=m
89CONFIG_TCP_MD5SIG=y
90CONFIG_IPV6=y
91CONFIG_IPV6_ROUTER_PREF=y
92CONFIG_IPV6_ROUTE_INFO=y
93CONFIG_IPV6_OPTIMISTIC_DAD=y
94CONFIG_INET6_AH=m
95CONFIG_INET6_ESP=m
96CONFIG_INET6_IPCOMP=m
97CONFIG_IPV6_MIP6=m
98CONFIG_INET6_XFRM_MODE_TRANSPORT=m
99CONFIG_INET6_XFRM_MODE_TUNNEL=m
100CONFIG_INET6_XFRM_MODE_BEET=m
101CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m
102CONFIG_IPV6_SIT=m
103CONFIG_IPV6_TUNNEL=m
104CONFIG_IPV6_MULTIPLE_TABLES=y
105CONFIG_IPV6_MROUTE=y
106CONFIG_IPV6_PIMSM_V2=y
107CONFIG_NETLABEL=y
108CONFIG_RDS=m
109CONFIG_RDS_TCP=m
110CONFIG_BRIDGE=m
111CONFIG_VLAN_8021Q=m
112CONFIG_VLAN_8021Q_GVRP=y
113CONFIG_PHONET=m
114CONFIG_NET_SCHED=y
115CONFIG_NET_SCH_CBQ=m
116CONFIG_NET_SCH_HTB=m
117CONFIG_NET_SCH_HFSC=m
118CONFIG_NET_SCH_PRIO=m
119CONFIG_NET_SCH_MULTIQ=m
120CONFIG_NET_SCH_RED=m
121CONFIG_NET_SCH_SFQ=m
122CONFIG_NET_SCH_TEQL=m
123CONFIG_NET_SCH_TBF=m
124CONFIG_NET_SCH_GRED=m
125CONFIG_NET_SCH_DSMARK=m
126CONFIG_NET_SCH_NETEM=m
127CONFIG_NET_SCH_DRR=m
128CONFIG_NET_SCH_INGRESS=m
129CONFIG_NET_CLS_BASIC=m
130CONFIG_NET_CLS_TCINDEX=m
131CONFIG_NET_CLS_ROUTE4=m
132CONFIG_NET_CLS_FW=m
133CONFIG_NET_CLS_U32=m
134CONFIG_CLS_U32_PERF=y
135CONFIG_CLS_U32_MARK=y
136CONFIG_NET_CLS_RSVP=m
137CONFIG_NET_CLS_RSVP6=m
138CONFIG_NET_CLS_FLOW=m
139CONFIG_NET_CLS_CGROUP=y
140CONFIG_NET_EMATCH=y
141CONFIG_NET_EMATCH_CMP=m
142CONFIG_NET_EMATCH_NBYTE=m
143CONFIG_NET_EMATCH_U32=m
144CONFIG_NET_EMATCH_META=m
145CONFIG_NET_EMATCH_TEXT=m
146CONFIG_NET_CLS_ACT=y
147CONFIG_NET_ACT_POLICE=m
148CONFIG_NET_ACT_GACT=m
149CONFIG_GACT_PROB=y
150CONFIG_NET_ACT_MIRRED=m
151CONFIG_NET_ACT_NAT=m
152CONFIG_NET_ACT_PEDIT=m
153CONFIG_NET_ACT_SIMP=m
154CONFIG_NET_ACT_SKBEDIT=m
155CONFIG_NET_CLS_IND=y
156CONFIG_DCB=y
157CONFIG_DNS_RESOLVER=y
158# CONFIG_WIRELESS is not set
159CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
160CONFIG_DEVTMPFS=y
161CONFIG_DEVTMPFS_MOUNT=y
162CONFIG_CONNECTOR=y
163CONFIG_BLK_DEV_LOOP=y
164CONFIG_BLK_DEV_CRYPTOLOOP=m
165CONFIG_BLK_DEV_SX8=m
166CONFIG_BLK_DEV_RAM=y
167CONFIG_BLK_DEV_RAM_SIZE=16384
168CONFIG_ATA_OVER_ETH=m
169CONFIG_RAID_ATTRS=m
170CONFIG_BLK_DEV_SD=y
171CONFIG_SCSI_CONSTANTS=y
172CONFIG_SCSI_LOGGING=y
173CONFIG_SCSI_SAS_ATA=y
174CONFIG_ISCSI_TCP=m
175CONFIG_SCSI_MVSAS=y
176# CONFIG_SCSI_MVSAS_DEBUG is not set
177CONFIG_SCSI_MVSAS_TASKLET=y
178CONFIG_ATA=y
179CONFIG_SATA_AHCI=y
180CONFIG_SATA_SIL24=y
181# CONFIG_ATA_SFF is not set
182CONFIG_MD=y
183CONFIG_BLK_DEV_MD=y
184CONFIG_MD_LINEAR=m
185CONFIG_MD_RAID0=m
186CONFIG_MD_RAID1=m
187CONFIG_MD_RAID10=m
188CONFIG_MD_RAID456=m
189CONFIG_MD_FAULTY=m
190CONFIG_BLK_DEV_DM=m
191CONFIG_DM_DEBUG=y
192CONFIG_DM_CRYPT=m
193CONFIG_DM_SNAPSHOT=m
194CONFIG_DM_MIRROR=m
195CONFIG_DM_LOG_USERSPACE=m
196CONFIG_DM_ZERO=m
197CONFIG_DM_MULTIPATH=m
198CONFIG_DM_MULTIPATH_QL=m
199CONFIG_DM_MULTIPATH_ST=m
200CONFIG_DM_DELAY=m
201CONFIG_DM_UEVENT=y
202CONFIG_TARGET_CORE=m
203CONFIG_TCM_IBLOCK=m
204CONFIG_TCM_FILEIO=m
205CONFIG_TCM_PSCSI=m
206CONFIG_LOOPBACK_TARGET=m
207CONFIG_ISCSI_TARGET=m
208CONFIG_FUSION=y
209CONFIG_FUSION_SAS=y
210CONFIG_NETDEVICES=y
211CONFIG_BONDING=m
212CONFIG_DUMMY=m
213CONFIG_IFB=m
214CONFIG_MACVLAN=m
215CONFIG_MACVTAP=m
216CONFIG_NETCONSOLE=m
217CONFIG_NETCONSOLE_DYNAMIC=y
218CONFIG_TUN=y
219CONFIG_VETH=m
220CONFIG_NET_DSA_MV88E6060=y
221CONFIG_NET_DSA_MV88E6XXX=y
222CONFIG_SKY2=y
223CONFIG_PTP_1588_CLOCK_TILEGX=y
224# CONFIG_WLAN is not set
225# CONFIG_INPUT_MOUSEDEV is not set
226# CONFIG_INPUT_KEYBOARD is not set
227# CONFIG_INPUT_MOUSE is not set
228# CONFIG_SERIO is not set
229# CONFIG_VT is not set
230# CONFIG_LEGACY_PTYS is not set
231CONFIG_SERIAL_TILEGX=y
232CONFIG_HW_RANDOM=y
233CONFIG_HW_RANDOM_TIMERIOMEM=m
234CONFIG_I2C=y
235CONFIG_I2C_CHARDEV=y
236# CONFIG_HWMON is not set
237CONFIG_WATCHDOG=y
238CONFIG_WATCHDOG_NOWAYOUT=y
239# CONFIG_VGA_ARB is not set
240CONFIG_DRM=m
241CONFIG_DRM_TDFX=m
242CONFIG_DRM_R128=m
243CONFIG_DRM_MGA=m
244CONFIG_DRM_VIA=m
245CONFIG_DRM_SAVAGE=m
246CONFIG_USB=y
247CONFIG_USB_EHCI_HCD=y
248CONFIG_USB_OHCI_HCD=y
249CONFIG_USB_STORAGE=y
250CONFIG_EDAC=y
251CONFIG_RTC_CLASS=y
252CONFIG_RTC_DRV_TILE=y
253CONFIG_EXT2_FS=y
254CONFIG_EXT2_FS_XATTR=y
255CONFIG_EXT2_FS_POSIX_ACL=y
256CONFIG_EXT2_FS_SECURITY=y
257CONFIG_EXT2_FS_XIP=y
258CONFIG_EXT3_FS=y
259CONFIG_EXT3_FS_POSIX_ACL=y
260CONFIG_EXT3_FS_SECURITY=y
261CONFIG_EXT4_FS=y
262CONFIG_EXT4_FS_POSIX_ACL=y
263CONFIG_EXT4_FS_SECURITY=y
264CONFIG_XFS_FS=y
265CONFIG_XFS_QUOTA=y
266CONFIG_XFS_POSIX_ACL=y
267CONFIG_GFS2_FS=m
268CONFIG_GFS2_FS_LOCKING_DLM=y
269CONFIG_BTRFS_FS=m
270CONFIG_BTRFS_FS_POSIX_ACL=y
271CONFIG_QUOTA=y
272CONFIG_QUOTA_NETLINK_INTERFACE=y
273# CONFIG_PRINT_QUOTA_WARNING is not set
274CONFIG_QFMT_V2=y
275CONFIG_AUTOFS4_FS=m
276CONFIG_FUSE_FS=y
277CONFIG_CUSE=m
278CONFIG_FSCACHE=m
279CONFIG_FSCACHE_STATS=y
280CONFIG_CACHEFILES=m
281CONFIG_ISO9660_FS=m
282CONFIG_JOLIET=y
283CONFIG_ZISOFS=y
284CONFIG_UDF_FS=m
285CONFIG_MSDOS_FS=m
286CONFIG_VFAT_FS=m
287CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
288CONFIG_PROC_KCORE=y
289CONFIG_TMPFS=y
290CONFIG_TMPFS_POSIX_ACL=y
291CONFIG_HUGETLBFS=y
292CONFIG_ECRYPT_FS=m
293CONFIG_CRAMFS=m
294CONFIG_SQUASHFS=m
295CONFIG_NFS_FS=m
296CONFIG_NFS_V3_ACL=y
297CONFIG_NFS_V4=m
298CONFIG_NFS_V4_1=y
299CONFIG_NFS_FSCACHE=y
300CONFIG_NFSD=m
301CONFIG_NFSD_V3_ACL=y
302CONFIG_NFSD_V4=y
303CONFIG_CIFS=m
304CONFIG_CIFS_STATS=y
305CONFIG_CIFS_WEAK_PW_HASH=y
306CONFIG_CIFS_UPCALL=y
307CONFIG_CIFS_XATTR=y
308CONFIG_CIFS_POSIX=y
309CONFIG_CIFS_DFS_UPCALL=y
310CONFIG_CIFS_FSCACHE=y
311CONFIG_NLS_DEFAULT="utf8"
312CONFIG_NLS_CODEPAGE_437=y
313CONFIG_NLS_CODEPAGE_737=m
314CONFIG_NLS_CODEPAGE_775=m
315CONFIG_NLS_CODEPAGE_850=m
316CONFIG_NLS_CODEPAGE_852=m
317CONFIG_NLS_CODEPAGE_855=m
318CONFIG_NLS_CODEPAGE_857=m
319CONFIG_NLS_CODEPAGE_860=m
320CONFIG_NLS_CODEPAGE_861=m
321CONFIG_NLS_CODEPAGE_862=m
322CONFIG_NLS_CODEPAGE_863=m
323CONFIG_NLS_CODEPAGE_864=m
324CONFIG_NLS_CODEPAGE_865=m
325CONFIG_NLS_CODEPAGE_866=m
326CONFIG_NLS_CODEPAGE_869=m
327CONFIG_NLS_CODEPAGE_936=m
328CONFIG_NLS_CODEPAGE_950=m
329CONFIG_NLS_CODEPAGE_932=m
330CONFIG_NLS_CODEPAGE_949=m
331CONFIG_NLS_CODEPAGE_874=m
332CONFIG_NLS_ISO8859_8=m
333CONFIG_NLS_CODEPAGE_1250=m
334CONFIG_NLS_CODEPAGE_1251=m
335CONFIG_NLS_ASCII=y
336CONFIG_NLS_ISO8859_1=m
337CONFIG_NLS_ISO8859_2=m
338CONFIG_NLS_ISO8859_3=m
339CONFIG_NLS_ISO8859_4=m
340CONFIG_NLS_ISO8859_5=m
341CONFIG_NLS_ISO8859_6=m
342CONFIG_NLS_ISO8859_7=m
343CONFIG_NLS_ISO8859_9=m
344CONFIG_NLS_ISO8859_13=m
345CONFIG_NLS_ISO8859_14=m
346CONFIG_NLS_ISO8859_15=m
347CONFIG_NLS_KOI8_R=m
348CONFIG_NLS_KOI8_U=m
349CONFIG_NLS_UTF8=m
350CONFIG_DLM=m
351CONFIG_DLM_DEBUG=y
352CONFIG_DYNAMIC_DEBUG=y
353CONFIG_DEBUG_INFO=y
354CONFIG_DEBUG_INFO_REDUCED=y
355# CONFIG_ENABLE_WARN_DEPRECATED is not set
356CONFIG_STRIP_ASM_SYMS=y
357CONFIG_DEBUG_FS=y
358CONFIG_HEADERS_CHECK=y
359# CONFIG_FRAME_POINTER is not set
360CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y
361CONFIG_DEBUG_VM=y
362CONFIG_DEBUG_MEMORY_INIT=y
363CONFIG_DEBUG_STACKOVERFLOW=y
364CONFIG_LOCKUP_DETECTOR=y
365CONFIG_SCHEDSTATS=y
366CONFIG_TIMER_STATS=y
367CONFIG_DEBUG_LIST=y
368CONFIG_DEBUG_CREDENTIALS=y
369CONFIG_RCU_CPU_STALL_TIMEOUT=60
370CONFIG_ASYNC_RAID6_TEST=m
371CONFIG_KGDB=y
372CONFIG_SECURITY=y
373CONFIG_SECURITYFS=y
374CONFIG_SECURITY_NETWORK=y
375CONFIG_SECURITY_NETWORK_XFRM=y
376CONFIG_SECURITY_SELINUX=y
377CONFIG_SECURITY_SELINUX_BOOTPARAM=y
378CONFIG_SECURITY_SELINUX_DISABLE=y
379CONFIG_CRYPTO_PCRYPT=m
380CONFIG_CRYPTO_CRYPTD=m
381CONFIG_CRYPTO_TEST=m
382CONFIG_CRYPTO_CCM=m
383CONFIG_CRYPTO_GCM=m
384CONFIG_CRYPTO_CTS=m
385CONFIG_CRYPTO_LRW=m
386CONFIG_CRYPTO_PCBC=m
387CONFIG_CRYPTO_XTS=m
388CONFIG_CRYPTO_HMAC=y
389CONFIG_CRYPTO_XCBC=m
390CONFIG_CRYPTO_VMAC=m
391CONFIG_CRYPTO_MICHAEL_MIC=m
392CONFIG_CRYPTO_RMD128=m
393CONFIG_CRYPTO_RMD160=m
394CONFIG_CRYPTO_RMD256=m
395CONFIG_CRYPTO_RMD320=m
396CONFIG_CRYPTO_SHA1=y
397CONFIG_CRYPTO_SHA512=m
398CONFIG_CRYPTO_TGR192=m
399CONFIG_CRYPTO_WP512=m
400CONFIG_CRYPTO_ANUBIS=m
401CONFIG_CRYPTO_BLOWFISH=m
402CONFIG_CRYPTO_CAMELLIA=m
403CONFIG_CRYPTO_CAST5=m
404CONFIG_CRYPTO_CAST6=m
405CONFIG_CRYPTO_FCRYPT=m
406CONFIG_CRYPTO_KHAZAD=m
407CONFIG_CRYPTO_SEED=m
408CONFIG_CRYPTO_SERPENT=m
409CONFIG_CRYPTO_TEA=m
410CONFIG_CRYPTO_TWOFISH=m
411CONFIG_CRYPTO_LZO=m
diff --git a/arch/tile/configs/tilepro_defconfig b/arch/tile/configs/tilepro_defconfig
deleted file mode 100644
index da2858755fa1..000000000000
--- a/arch/tile/configs/tilepro_defconfig
+++ /dev/null
@@ -1,524 +0,0 @@
1CONFIG_SYSVIPC=y
2CONFIG_POSIX_MQUEUE=y
3CONFIG_AUDIT=y
4CONFIG_NO_HZ=y
5CONFIG_HIGH_RES_TIMERS=y
6CONFIG_BSD_PROCESS_ACCT=y
7CONFIG_BSD_PROCESS_ACCT_V3=y
8CONFIG_TASKSTATS=y
9CONFIG_TASK_DELAY_ACCT=y
10CONFIG_TASK_XACCT=y
11CONFIG_TASK_IO_ACCOUNTING=y
12CONFIG_LOG_BUF_SHIFT=19
13CONFIG_CGROUPS=y
14CONFIG_CGROUP_DEBUG=y
15CONFIG_CGROUP_DEVICE=y
16CONFIG_CPUSETS=y
17CONFIG_CGROUP_CPUACCT=y
18CONFIG_CGROUP_SCHED=y
19CONFIG_RT_GROUP_SCHED=y
20CONFIG_BLK_CGROUP=y
21CONFIG_NAMESPACES=y
22CONFIG_RELAY=y
23CONFIG_BLK_DEV_INITRD=y
24CONFIG_RD_XZ=y
25CONFIG_SYSCTL_SYSCALL=y
26CONFIG_EMBEDDED=y
27# CONFIG_COMPAT_BRK is not set
28CONFIG_PROFILING=y
29CONFIG_MODULES=y
30CONFIG_MODULE_FORCE_LOAD=y
31CONFIG_MODULE_UNLOAD=y
32CONFIG_BLK_DEV_INTEGRITY=y
33CONFIG_PARTITION_ADVANCED=y
34CONFIG_OSF_PARTITION=y
35CONFIG_AMIGA_PARTITION=y
36CONFIG_MAC_PARTITION=y
37CONFIG_BSD_DISKLABEL=y
38CONFIG_MINIX_SUBPARTITION=y
39CONFIG_SOLARIS_X86_PARTITION=y
40CONFIG_UNIXWARE_DISKLABEL=y
41CONFIG_SGI_PARTITION=y
42CONFIG_SUN_PARTITION=y
43CONFIG_KARMA_PARTITION=y
44CONFIG_CFQ_GROUP_IOSCHED=y
45CONFIG_HZ_100=y
46# CONFIG_COMPACTION is not set
47CONFIG_PREEMPT_VOLUNTARY=y
48CONFIG_PCI_DEBUG=y
49# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
50CONFIG_BINFMT_MISC=y
51CONFIG_NET=y
52CONFIG_PACKET=y
53CONFIG_UNIX=y
54CONFIG_XFRM_USER=y
55CONFIG_XFRM_SUB_POLICY=y
56CONFIG_XFRM_STATISTICS=y
57CONFIG_NET_KEY=m
58CONFIG_NET_KEY_MIGRATE=y
59CONFIG_INET=y
60CONFIG_IP_MULTICAST=y
61CONFIG_IP_ADVANCED_ROUTER=y
62CONFIG_IP_MULTIPLE_TABLES=y
63CONFIG_IP_ROUTE_MULTIPATH=y
64CONFIG_IP_ROUTE_VERBOSE=y
65CONFIG_NET_IPIP=m
66CONFIG_IP_MROUTE=y
67CONFIG_IP_PIMSM_V1=y
68CONFIG_IP_PIMSM_V2=y
69CONFIG_SYN_COOKIES=y
70CONFIG_INET_AH=m
71CONFIG_INET_ESP=m
72CONFIG_INET_IPCOMP=m
73CONFIG_INET_XFRM_MODE_TRANSPORT=m
74CONFIG_INET_XFRM_MODE_TUNNEL=m
75CONFIG_INET_XFRM_MODE_BEET=m
76CONFIG_INET_DIAG=m
77CONFIG_TCP_CONG_ADVANCED=y
78CONFIG_TCP_CONG_HSTCP=m
79CONFIG_TCP_CONG_HYBLA=m
80CONFIG_TCP_CONG_SCALABLE=m
81CONFIG_TCP_CONG_LP=m
82CONFIG_TCP_CONG_VENO=m
83CONFIG_TCP_CONG_YEAH=m
84CONFIG_TCP_CONG_ILLINOIS=m
85CONFIG_TCP_MD5SIG=y
86CONFIG_IPV6=y
87CONFIG_IPV6_ROUTER_PREF=y
88CONFIG_IPV6_ROUTE_INFO=y
89CONFIG_IPV6_OPTIMISTIC_DAD=y
90CONFIG_INET6_AH=m
91CONFIG_INET6_ESP=m
92CONFIG_INET6_IPCOMP=m
93CONFIG_IPV6_MIP6=m
94CONFIG_INET6_XFRM_MODE_TRANSPORT=m
95CONFIG_INET6_XFRM_MODE_TUNNEL=m
96CONFIG_INET6_XFRM_MODE_BEET=m
97CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m
98CONFIG_IPV6_SIT=m
99CONFIG_IPV6_TUNNEL=m
100CONFIG_IPV6_MULTIPLE_TABLES=y
101CONFIG_IPV6_MROUTE=y
102CONFIG_IPV6_PIMSM_V2=y
103CONFIG_NETLABEL=y
104CONFIG_NETFILTER=y
105CONFIG_NF_CONNTRACK=m
106CONFIG_NF_CONNTRACK_SECMARK=y
107CONFIG_NF_CONNTRACK_ZONES=y
108CONFIG_NF_CONNTRACK_EVENTS=y
109CONFIG_NF_CT_PROTO_DCCP=m
110CONFIG_NF_CT_PROTO_UDPLITE=m
111CONFIG_NF_CONNTRACK_AMANDA=m
112CONFIG_NF_CONNTRACK_FTP=m
113CONFIG_NF_CONNTRACK_H323=m
114CONFIG_NF_CONNTRACK_IRC=m
115CONFIG_NF_CONNTRACK_NETBIOS_NS=m
116CONFIG_NF_CONNTRACK_PPTP=m
117CONFIG_NF_CONNTRACK_SANE=m
118CONFIG_NF_CONNTRACK_SIP=m
119CONFIG_NF_CONNTRACK_TFTP=m
120CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
121CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
122CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=m
123CONFIG_NETFILTER_XT_TARGET_DSCP=m
124CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
125CONFIG_NETFILTER_XT_TARGET_MARK=m
126CONFIG_NETFILTER_XT_TARGET_NFLOG=m
127CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
128CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
129CONFIG_NETFILTER_XT_TARGET_TEE=m
130CONFIG_NETFILTER_XT_TARGET_TPROXY=m
131CONFIG_NETFILTER_XT_TARGET_TRACE=m
132CONFIG_NETFILTER_XT_TARGET_SECMARK=m
133CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
134CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
135CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
136CONFIG_NETFILTER_XT_MATCH_COMMENT=m
137CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
138CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
139CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
140CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
141CONFIG_NETFILTER_XT_MATCH_DCCP=m
142CONFIG_NETFILTER_XT_MATCH_DSCP=m
143CONFIG_NETFILTER_XT_MATCH_ESP=m
144CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
145CONFIG_NETFILTER_XT_MATCH_HELPER=m
146CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
147CONFIG_NETFILTER_XT_MATCH_IPVS=m
148CONFIG_NETFILTER_XT_MATCH_LENGTH=m
149CONFIG_NETFILTER_XT_MATCH_LIMIT=m
150CONFIG_NETFILTER_XT_MATCH_MAC=m
151CONFIG_NETFILTER_XT_MATCH_MARK=m
152CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
153CONFIG_NETFILTER_XT_MATCH_OSF=m
154CONFIG_NETFILTER_XT_MATCH_OWNER=m
155CONFIG_NETFILTER_XT_MATCH_POLICY=m
156CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
157CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
158CONFIG_NETFILTER_XT_MATCH_QUOTA=m
159CONFIG_NETFILTER_XT_MATCH_RATEEST=m
160CONFIG_NETFILTER_XT_MATCH_REALM=m
161CONFIG_NETFILTER_XT_MATCH_RECENT=m
162CONFIG_NETFILTER_XT_MATCH_SOCKET=m
163CONFIG_NETFILTER_XT_MATCH_STATE=m
164CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
165CONFIG_NETFILTER_XT_MATCH_STRING=m
166CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
167CONFIG_NETFILTER_XT_MATCH_TIME=m
168CONFIG_NETFILTER_XT_MATCH_U32=m
169CONFIG_IP_VS=m
170CONFIG_IP_VS_IPV6=y
171CONFIG_IP_VS_PROTO_TCP=y
172CONFIG_IP_VS_PROTO_UDP=y
173CONFIG_IP_VS_PROTO_ESP=y
174CONFIG_IP_VS_PROTO_AH=y
175CONFIG_IP_VS_PROTO_SCTP=y
176CONFIG_IP_VS_RR=m
177CONFIG_IP_VS_WRR=m
178CONFIG_IP_VS_LC=m
179CONFIG_IP_VS_WLC=m
180CONFIG_IP_VS_LBLC=m
181CONFIG_IP_VS_LBLCR=m
182CONFIG_IP_VS_SED=m
183CONFIG_IP_VS_NQ=m
184CONFIG_NF_CONNTRACK_IPV4=m
185# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set
186CONFIG_IP_NF_IPTABLES=y
187CONFIG_IP_NF_MATCH_AH=m
188CONFIG_IP_NF_MATCH_ECN=m
189CONFIG_IP_NF_MATCH_TTL=m
190CONFIG_IP_NF_FILTER=y
191CONFIG_IP_NF_TARGET_REJECT=y
192CONFIG_IP_NF_MANGLE=m
193CONFIG_IP_NF_TARGET_ECN=m
194CONFIG_IP_NF_TARGET_TTL=m
195CONFIG_IP_NF_RAW=m
196CONFIG_IP_NF_SECURITY=m
197CONFIG_IP_NF_ARPTABLES=m
198CONFIG_IP_NF_ARPFILTER=m
199CONFIG_IP_NF_ARP_MANGLE=m
200CONFIG_NF_CONNTRACK_IPV6=m
201CONFIG_IP6_NF_MATCH_AH=m
202CONFIG_IP6_NF_MATCH_EUI64=m
203CONFIG_IP6_NF_MATCH_FRAG=m
204CONFIG_IP6_NF_MATCH_OPTS=m
205CONFIG_IP6_NF_MATCH_HL=m
206CONFIG_IP6_NF_MATCH_IPV6HEADER=m
207CONFIG_IP6_NF_MATCH_MH=m
208CONFIG_IP6_NF_MATCH_RT=m
209CONFIG_IP6_NF_TARGET_HL=m
210CONFIG_IP6_NF_FILTER=m
211CONFIG_IP6_NF_TARGET_REJECT=m
212CONFIG_IP6_NF_MANGLE=m
213CONFIG_IP6_NF_RAW=m
214CONFIG_IP6_NF_SECURITY=m
215CONFIG_BRIDGE_NF_EBTABLES=m
216CONFIG_BRIDGE_EBT_BROUTE=m
217CONFIG_BRIDGE_EBT_T_FILTER=m
218CONFIG_BRIDGE_EBT_T_NAT=m
219CONFIG_BRIDGE_EBT_802_3=m
220CONFIG_BRIDGE_EBT_AMONG=m
221CONFIG_BRIDGE_EBT_ARP=m
222CONFIG_BRIDGE_EBT_IP=m
223CONFIG_BRIDGE_EBT_IP6=m
224CONFIG_BRIDGE_EBT_LIMIT=m
225CONFIG_BRIDGE_EBT_MARK=m
226CONFIG_BRIDGE_EBT_PKTTYPE=m
227CONFIG_BRIDGE_EBT_STP=m
228CONFIG_BRIDGE_EBT_VLAN=m
229CONFIG_BRIDGE_EBT_ARPREPLY=m
230CONFIG_BRIDGE_EBT_DNAT=m
231CONFIG_BRIDGE_EBT_MARK_T=m
232CONFIG_BRIDGE_EBT_REDIRECT=m
233CONFIG_BRIDGE_EBT_SNAT=m
234CONFIG_BRIDGE_EBT_LOG=m
235CONFIG_BRIDGE_EBT_ULOG=m
236CONFIG_BRIDGE_EBT_NFLOG=m
237CONFIG_RDS=m
238CONFIG_RDS_TCP=m
239CONFIG_BRIDGE=m
240CONFIG_VLAN_8021Q=m
241CONFIG_VLAN_8021Q_GVRP=y
242CONFIG_PHONET=m
243CONFIG_NET_SCHED=y
244CONFIG_NET_SCH_CBQ=m
245CONFIG_NET_SCH_HTB=m
246CONFIG_NET_SCH_HFSC=m
247CONFIG_NET_SCH_PRIO=m
248CONFIG_NET_SCH_MULTIQ=m
249CONFIG_NET_SCH_RED=m
250CONFIG_NET_SCH_SFQ=m
251CONFIG_NET_SCH_TEQL=m
252CONFIG_NET_SCH_TBF=m
253CONFIG_NET_SCH_GRED=m
254CONFIG_NET_SCH_DSMARK=m
255CONFIG_NET_SCH_NETEM=m
256CONFIG_NET_SCH_DRR=m
257CONFIG_NET_SCH_INGRESS=m
258CONFIG_NET_CLS_BASIC=m
259CONFIG_NET_CLS_TCINDEX=m
260CONFIG_NET_CLS_ROUTE4=m
261CONFIG_NET_CLS_FW=m
262CONFIG_NET_CLS_U32=m
263CONFIG_CLS_U32_PERF=y
264CONFIG_CLS_U32_MARK=y
265CONFIG_NET_CLS_RSVP=m
266CONFIG_NET_CLS_RSVP6=m
267CONFIG_NET_CLS_FLOW=m
268CONFIG_NET_CLS_CGROUP=y
269CONFIG_NET_EMATCH=y
270CONFIG_NET_EMATCH_CMP=m
271CONFIG_NET_EMATCH_NBYTE=m
272CONFIG_NET_EMATCH_U32=m
273CONFIG_NET_EMATCH_META=m
274CONFIG_NET_EMATCH_TEXT=m
275CONFIG_NET_CLS_ACT=y
276CONFIG_NET_ACT_POLICE=m
277CONFIG_NET_ACT_GACT=m
278CONFIG_GACT_PROB=y
279CONFIG_NET_ACT_MIRRED=m
280CONFIG_NET_ACT_IPT=m
281CONFIG_NET_ACT_NAT=m
282CONFIG_NET_ACT_PEDIT=m
283CONFIG_NET_ACT_SIMP=m
284CONFIG_NET_ACT_SKBEDIT=m
285CONFIG_NET_CLS_IND=y
286CONFIG_DCB=y
287CONFIG_DNS_RESOLVER=y
288# CONFIG_WIRELESS is not set
289CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
290CONFIG_DEVTMPFS=y
291CONFIG_DEVTMPFS_MOUNT=y
292CONFIG_CONNECTOR=y
293CONFIG_BLK_DEV_LOOP=y
294CONFIG_BLK_DEV_CRYPTOLOOP=m
295CONFIG_BLK_DEV_SX8=m
296CONFIG_BLK_DEV_RAM=y
297CONFIG_BLK_DEV_RAM_SIZE=16384
298CONFIG_ATA_OVER_ETH=m
299CONFIG_RAID_ATTRS=m
300CONFIG_BLK_DEV_SD=y
301CONFIG_SCSI_CONSTANTS=y
302CONFIG_SCSI_LOGGING=y
303CONFIG_ATA=y
304CONFIG_SATA_SIL24=y
305# CONFIG_ATA_SFF is not set
306CONFIG_MD=y
307CONFIG_BLK_DEV_MD=y
308CONFIG_MD_LINEAR=m
309CONFIG_MD_RAID0=m
310CONFIG_MD_RAID1=m
311CONFIG_MD_RAID10=m
312CONFIG_MD_RAID456=m
313CONFIG_MD_FAULTY=m
314CONFIG_BLK_DEV_DM=m
315CONFIG_DM_DEBUG=y
316CONFIG_DM_CRYPT=m
317CONFIG_DM_SNAPSHOT=m
318CONFIG_DM_MIRROR=m
319CONFIG_DM_LOG_USERSPACE=m
320CONFIG_DM_ZERO=m
321CONFIG_DM_MULTIPATH=m
322CONFIG_DM_MULTIPATH_QL=m
323CONFIG_DM_MULTIPATH_ST=m
324CONFIG_DM_DELAY=m
325CONFIG_DM_UEVENT=y
326CONFIG_FUSION=y
327CONFIG_FUSION_SAS=y
328CONFIG_NETDEVICES=y
329CONFIG_BONDING=m
330CONFIG_DUMMY=m
331CONFIG_IFB=m
332CONFIG_MACVLAN=m
333CONFIG_MACVTAP=m
334CONFIG_NETCONSOLE=m
335CONFIG_NETCONSOLE_DYNAMIC=y
336CONFIG_TUN=y
337CONFIG_VETH=m
338CONFIG_NET_DSA_MV88E6060=y
339CONFIG_NET_DSA_MV88E6XXX=y
340# CONFIG_NET_VENDOR_3COM is not set
341CONFIG_E1000E=y
342# CONFIG_WLAN is not set
343# CONFIG_INPUT_MOUSEDEV is not set
344# CONFIG_INPUT_KEYBOARD is not set
345# CONFIG_INPUT_MOUSE is not set
346# CONFIG_SERIO is not set
347# CONFIG_VT is not set
348# CONFIG_LEGACY_PTYS is not set
349CONFIG_HW_RANDOM=y
350CONFIG_HW_RANDOM_TIMERIOMEM=m
351CONFIG_I2C=y
352CONFIG_I2C_CHARDEV=y
353# CONFIG_HWMON is not set
354CONFIG_WATCHDOG=y
355CONFIG_WATCHDOG_NOWAYOUT=y
356# CONFIG_VGA_ARB is not set
357# CONFIG_USB_SUPPORT is not set
358CONFIG_EDAC=y
359CONFIG_RTC_CLASS=y
360CONFIG_RTC_DRV_TILE=y
361CONFIG_EXT2_FS=y
362CONFIG_EXT2_FS_XATTR=y
363CONFIG_EXT2_FS_POSIX_ACL=y
364CONFIG_EXT2_FS_SECURITY=y
365CONFIG_EXT2_FS_XIP=y
366CONFIG_EXT3_FS=y
367CONFIG_EXT3_FS_POSIX_ACL=y
368CONFIG_EXT3_FS_SECURITY=y
369CONFIG_EXT4_FS=y
370CONFIG_EXT4_FS_POSIX_ACL=y
371CONFIG_EXT4_FS_SECURITY=y
372CONFIG_XFS_FS=y
373CONFIG_XFS_QUOTA=y
374CONFIG_XFS_POSIX_ACL=y
375CONFIG_GFS2_FS=m
376CONFIG_GFS2_FS_LOCKING_DLM=y
377CONFIG_BTRFS_FS=m
378CONFIG_BTRFS_FS_POSIX_ACL=y
379CONFIG_QUOTA=y
380CONFIG_QUOTA_NETLINK_INTERFACE=y
381# CONFIG_PRINT_QUOTA_WARNING is not set
382CONFIG_QFMT_V2=y
383CONFIG_AUTOFS4_FS=m
384CONFIG_FUSE_FS=y
385CONFIG_CUSE=m
386CONFIG_FSCACHE=m
387CONFIG_FSCACHE_STATS=y
388CONFIG_CACHEFILES=m
389CONFIG_ISO9660_FS=m
390CONFIG_JOLIET=y
391CONFIG_ZISOFS=y
392CONFIG_UDF_FS=m
393CONFIG_MSDOS_FS=m
394CONFIG_VFAT_FS=m
395CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
396CONFIG_PROC_KCORE=y
397CONFIG_TMPFS=y
398CONFIG_TMPFS_POSIX_ACL=y
399CONFIG_HUGETLBFS=y
400CONFIG_CONFIGFS_FS=m
401CONFIG_ECRYPT_FS=m
402CONFIG_CRAMFS=m
403CONFIG_SQUASHFS=m
404CONFIG_NFS_FS=m
405CONFIG_NFS_V3_ACL=y
406CONFIG_NFS_V4=m
407CONFIG_NFS_V4_1=y
408CONFIG_NFS_FSCACHE=y
409CONFIG_NFSD=m
410CONFIG_NFSD_V3_ACL=y
411CONFIG_NFSD_V4=y
412CONFIG_CIFS=m
413CONFIG_CIFS_STATS=y
414CONFIG_CIFS_WEAK_PW_HASH=y
415CONFIG_CIFS_UPCALL=y
416CONFIG_CIFS_XATTR=y
417CONFIG_CIFS_POSIX=y
418CONFIG_CIFS_DFS_UPCALL=y
419CONFIG_CIFS_FSCACHE=y
420CONFIG_NLS=y
421CONFIG_NLS_DEFAULT="utf8"
422CONFIG_NLS_CODEPAGE_437=y
423CONFIG_NLS_CODEPAGE_737=m
424CONFIG_NLS_CODEPAGE_775=m
425CONFIG_NLS_CODEPAGE_850=m
426CONFIG_NLS_CODEPAGE_852=m
427CONFIG_NLS_CODEPAGE_855=m
428CONFIG_NLS_CODEPAGE_857=m
429CONFIG_NLS_CODEPAGE_860=m
430CONFIG_NLS_CODEPAGE_861=m
431CONFIG_NLS_CODEPAGE_862=m
432CONFIG_NLS_CODEPAGE_863=m
433CONFIG_NLS_CODEPAGE_864=m
434CONFIG_NLS_CODEPAGE_865=m
435CONFIG_NLS_CODEPAGE_866=m
436CONFIG_NLS_CODEPAGE_869=m
437CONFIG_NLS_CODEPAGE_936=m
438CONFIG_NLS_CODEPAGE_950=m
439CONFIG_NLS_CODEPAGE_932=m
440CONFIG_NLS_CODEPAGE_949=m
441CONFIG_NLS_CODEPAGE_874=m
442CONFIG_NLS_ISO8859_8=m
443CONFIG_NLS_CODEPAGE_1250=m
444CONFIG_NLS_CODEPAGE_1251=m
445CONFIG_NLS_ASCII=y
446CONFIG_NLS_ISO8859_1=m
447CONFIG_NLS_ISO8859_2=m
448CONFIG_NLS_ISO8859_3=m
449CONFIG_NLS_ISO8859_4=m
450CONFIG_NLS_ISO8859_5=m
451CONFIG_NLS_ISO8859_6=m
452CONFIG_NLS_ISO8859_7=m
453CONFIG_NLS_ISO8859_9=m
454CONFIG_NLS_ISO8859_13=m
455CONFIG_NLS_ISO8859_14=m
456CONFIG_NLS_ISO8859_15=m
457CONFIG_NLS_KOI8_R=m
458CONFIG_NLS_KOI8_U=m
459CONFIG_NLS_UTF8=m
460CONFIG_DLM=m
461CONFIG_DLM_DEBUG=y
462CONFIG_DYNAMIC_DEBUG=y
463CONFIG_DEBUG_INFO=y
464CONFIG_DEBUG_INFO_REDUCED=y
465# CONFIG_ENABLE_WARN_DEPRECATED is not set
466CONFIG_FRAME_WARN=2048
467CONFIG_STRIP_ASM_SYMS=y
468CONFIG_DEBUG_FS=y
469CONFIG_HEADERS_CHECK=y
470# CONFIG_FRAME_POINTER is not set
471CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y
472CONFIG_MAGIC_SYSRQ=y
473CONFIG_DEBUG_VM=y
474CONFIG_DEBUG_MEMORY_INIT=y
475CONFIG_DEBUG_STACKOVERFLOW=y
476CONFIG_LOCKUP_DETECTOR=y
477CONFIG_SCHEDSTATS=y
478CONFIG_TIMER_STATS=y
479CONFIG_DEBUG_LIST=y
480CONFIG_DEBUG_CREDENTIALS=y
481CONFIG_RCU_CPU_STALL_TIMEOUT=60
482CONFIG_ASYNC_RAID6_TEST=m
483CONFIG_SECURITY=y
484CONFIG_SECURITYFS=y
485CONFIG_SECURITY_NETWORK=y
486CONFIG_SECURITY_NETWORK_XFRM=y
487CONFIG_SECURITY_SELINUX=y
488CONFIG_SECURITY_SELINUX_BOOTPARAM=y
489CONFIG_SECURITY_SELINUX_DISABLE=y
490CONFIG_CRYPTO_PCRYPT=m
491CONFIG_CRYPTO_CRYPTD=m
492CONFIG_CRYPTO_TEST=m
493CONFIG_CRYPTO_CCM=m
494CONFIG_CRYPTO_GCM=m
495CONFIG_CRYPTO_CTS=m
496CONFIG_CRYPTO_LRW=m
497CONFIG_CRYPTO_PCBC=m
498CONFIG_CRYPTO_XTS=m
499CONFIG_CRYPTO_HMAC=y
500CONFIG_CRYPTO_XCBC=m
501CONFIG_CRYPTO_VMAC=m
502CONFIG_CRYPTO_MICHAEL_MIC=m
503CONFIG_CRYPTO_RMD128=m
504CONFIG_CRYPTO_RMD160=m
505CONFIG_CRYPTO_RMD256=m
506CONFIG_CRYPTO_RMD320=m
507CONFIG_CRYPTO_SHA1=y
508CONFIG_CRYPTO_SHA512=m
509CONFIG_CRYPTO_TGR192=m
510CONFIG_CRYPTO_WP512=m
511CONFIG_CRYPTO_ANUBIS=m
512CONFIG_CRYPTO_BLOWFISH=m
513CONFIG_CRYPTO_CAMELLIA=m
514CONFIG_CRYPTO_CAST5=m
515CONFIG_CRYPTO_CAST6=m
516CONFIG_CRYPTO_FCRYPT=m
517CONFIG_CRYPTO_KHAZAD=m
518CONFIG_CRYPTO_SEED=m
519CONFIG_CRYPTO_SERPENT=m
520CONFIG_CRYPTO_TEA=m
521CONFIG_CRYPTO_TWOFISH=m
522CONFIG_CRYPTO_LZO=m
523CONFIG_CRC_CCITT=m
524CONFIG_CRC7=m
diff --git a/arch/tile/gxio/Kconfig b/arch/tile/gxio/Kconfig
deleted file mode 100644
index 903c8646bdd7..000000000000
--- a/arch/tile/gxio/Kconfig
+++ /dev/null
@@ -1,34 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2# Support direct access to TILE-Gx hardware from user space, via the
3# gxio library, or from kernel space, via kernel IORPC support.
4config TILE_GXIO
5 bool
6 depends on TILEGX
7
8# Support direct access to the common I/O DMA facility within the
9# TILE-Gx mPIPE and Trio hardware from kernel space.
10config TILE_GXIO_DMA
11 bool
12 select TILE_GXIO
13
14# Support direct access to the TILE-Gx mPIPE hardware from kernel space.
15config TILE_GXIO_MPIPE
16 bool
17 select TILE_GXIO
18 select TILE_GXIO_DMA
19
20# Support direct access to the TILE-Gx TRIO hardware from kernel space.
21config TILE_GXIO_TRIO
22 bool
23 select TILE_GXIO
24 select TILE_GXIO_DMA
25
26# Support direct access to the TILE-Gx USB hardware from kernel space.
27config TILE_GXIO_USB_HOST
28 bool
29 select TILE_GXIO
30
31# Support direct access to the TILE-Gx UART hardware from kernel space.
32config TILE_GXIO_UART
33 bool
34 select TILE_GXIO
diff --git a/arch/tile/gxio/Makefile b/arch/tile/gxio/Makefile
deleted file mode 100644
index fcc903c4cf87..000000000000
--- a/arch/tile/gxio/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2#
3# Makefile for the Tile-Gx device access support.
4#
5
6obj-$(CONFIG_TILE_GXIO) += iorpc_globals.o kiorpc.o
7obj-$(CONFIG_TILE_GXIO_DMA) += dma_queue.o
8obj-$(CONFIG_TILE_GXIO_MPIPE) += mpipe.o iorpc_mpipe.o iorpc_mpipe_info.o
9obj-$(CONFIG_TILE_GXIO_TRIO) += trio.o iorpc_trio.o
10obj-$(CONFIG_TILE_GXIO_UART) += uart.o iorpc_uart.o
11obj-$(CONFIG_TILE_GXIO_USB_HOST) += usb_host.o iorpc_usb_host.o
diff --git a/arch/tile/gxio/dma_queue.c b/arch/tile/gxio/dma_queue.c
deleted file mode 100644
index b7ba577d82ca..000000000000
--- a/arch/tile/gxio/dma_queue.c
+++ /dev/null
@@ -1,176 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/io.h>
16#include <linux/atomic.h>
17#include <linux/module.h>
18#include <gxio/dma_queue.h>
19
20/* Wait for a memory read to complete. */
21#define wait_for_value(val) \
22 __asm__ __volatile__("move %0, %0" :: "r"(val))
23
24/* The index is in the low 16. */
25#define DMA_QUEUE_INDEX_MASK ((1 << 16) - 1)
26
27/*
28 * The hardware descriptor-ring type.
29 * This matches the types used by mpipe (MPIPE_EDMA_POST_REGION_VAL_t)
30 * and trio (TRIO_PUSH_DMA_REGION_VAL_t or TRIO_PULL_DMA_REGION_VAL_t).
31 * See those types for more documentation on the individual fields.
32 */
33typedef union {
34 struct {
35#ifndef __BIG_ENDIAN__
36 uint64_t ring_idx:16;
37 uint64_t count:16;
38 uint64_t gen:1;
39 uint64_t __reserved:31;
40#else
41 uint64_t __reserved:31;
42 uint64_t gen:1;
43 uint64_t count:16;
44 uint64_t ring_idx:16;
45#endif
46 };
47 uint64_t word;
48} __gxio_ring_t;
49
50void __gxio_dma_queue_init(__gxio_dma_queue_t *dma_queue,
51 void *post_region_addr, unsigned int num_entries)
52{
53 /*
54 * Limit 65536 entry rings to 65535 credits because we only have a
55 * 16 bit completion counter.
56 */
57 int64_t credits = (num_entries < 65536) ? num_entries : 65535;
58
59 memset(dma_queue, 0, sizeof(*dma_queue));
60
61 dma_queue->post_region_addr = post_region_addr;
62 dma_queue->hw_complete_count = 0;
63 dma_queue->credits_and_next_index = credits << DMA_QUEUE_CREDIT_SHIFT;
64}
65
66EXPORT_SYMBOL_GPL(__gxio_dma_queue_init);
67
68void __gxio_dma_queue_update_credits(__gxio_dma_queue_t *dma_queue)
69{
70 __gxio_ring_t val;
71 uint64_t count;
72 uint64_t delta;
73 uint64_t new_count;
74
75 /*
76 * Read the 64-bit completion count without touching the cache, so
77 * we later avoid having to evict any sharers of this cache line
78 * when we update it below.
79 */
80 uint64_t orig_hw_complete_count =
81 cmpxchg(&dma_queue->hw_complete_count,
82 -1, -1);
83
84 /* Make sure the load completes before we access the hardware. */
85 wait_for_value(orig_hw_complete_count);
86
87 /* Read the 16-bit count of how many packets it has completed. */
88 val.word = __gxio_mmio_read(dma_queue->post_region_addr);
89 count = val.count;
90
91 /*
92 * Calculate the number of completions since we last updated the
93 * 64-bit counter. It's safe to ignore the high bits because the
94 * maximum credit value is 65535.
95 */
96 delta = (count - orig_hw_complete_count) & 0xffff;
97 if (delta == 0)
98 return;
99
100 /*
101 * Try to write back the count, advanced by delta. If we race with
102 * another thread, this might fail, in which case we return
103 * immediately on the assumption that some credits are (or at least
104 * were) available.
105 */
106 new_count = orig_hw_complete_count + delta;
107 if (cmpxchg(&dma_queue->hw_complete_count,
108 orig_hw_complete_count,
109 new_count) != orig_hw_complete_count)
110 return;
111
112 /*
113 * We succeeded in advancing the completion count; add back the
114 * corresponding number of egress credits.
115 */
116 __insn_fetchadd(&dma_queue->credits_and_next_index,
117 (delta << DMA_QUEUE_CREDIT_SHIFT));
118}
119
120EXPORT_SYMBOL_GPL(__gxio_dma_queue_update_credits);
121
122/*
123 * A separate 'blocked' method for put() so that backtraces and
124 * profiles will clearly indicate that we're wasting time spinning on
125 * egress availability rather than actually posting commands.
126 */
127int64_t __gxio_dma_queue_wait_for_credits(__gxio_dma_queue_t *dma_queue,
128 int64_t modifier)
129{
130 int backoff = 16;
131 int64_t old;
132
133 do {
134 int i;
135 /* Back off to avoid spamming memory networks. */
136 for (i = backoff; i > 0; i--)
137 __insn_mfspr(SPR_PASS);
138
139 /* Check credits again. */
140 __gxio_dma_queue_update_credits(dma_queue);
141 old = __insn_fetchaddgez(&dma_queue->credits_and_next_index,
142 modifier);
143
144 /* Calculate bounded exponential backoff for next iteration. */
145 if (backoff < 256)
146 backoff *= 2;
147 } while (old + modifier < 0);
148
149 return old;
150}
151
152EXPORT_SYMBOL_GPL(__gxio_dma_queue_wait_for_credits);
153
154int64_t __gxio_dma_queue_reserve_aux(__gxio_dma_queue_t *dma_queue,
155 unsigned int num, int wait)
156{
157 return __gxio_dma_queue_reserve(dma_queue, num, wait != 0, true);
158}
159
160EXPORT_SYMBOL_GPL(__gxio_dma_queue_reserve_aux);
161
162int __gxio_dma_queue_is_complete(__gxio_dma_queue_t *dma_queue,
163 int64_t completion_slot, int update)
164{
165 if (update) {
166 if (READ_ONCE(dma_queue->hw_complete_count) >
167 completion_slot)
168 return 1;
169
170 __gxio_dma_queue_update_credits(dma_queue);
171 }
172
173 return READ_ONCE(dma_queue->hw_complete_count) > completion_slot;
174}
175
176EXPORT_SYMBOL_GPL(__gxio_dma_queue_is_complete);
diff --git a/arch/tile/gxio/iorpc_globals.c b/arch/tile/gxio/iorpc_globals.c
deleted file mode 100644
index e178e90805a2..000000000000
--- a/arch/tile/gxio/iorpc_globals.c
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#include "gxio/iorpc_globals.h"
17
18struct arm_pollfd_param {
19 union iorpc_pollfd pollfd;
20};
21
22int __iorpc_arm_pollfd(int fd, int pollfd_cookie)
23{
24 struct arm_pollfd_param temp;
25 struct arm_pollfd_param *params = &temp;
26
27 params->pollfd.kernel.cookie = pollfd_cookie;
28
29 return hv_dev_pwrite(fd, 0, (HV_VirtAddr) params, sizeof(*params),
30 IORPC_OP_ARM_POLLFD);
31}
32
33EXPORT_SYMBOL(__iorpc_arm_pollfd);
34
35struct close_pollfd_param {
36 union iorpc_pollfd pollfd;
37};
38
39int __iorpc_close_pollfd(int fd, int pollfd_cookie)
40{
41 struct close_pollfd_param temp;
42 struct close_pollfd_param *params = &temp;
43
44 params->pollfd.kernel.cookie = pollfd_cookie;
45
46 return hv_dev_pwrite(fd, 0, (HV_VirtAddr) params, sizeof(*params),
47 IORPC_OP_CLOSE_POLLFD);
48}
49
50EXPORT_SYMBOL(__iorpc_close_pollfd);
51
52struct get_mmio_base_param {
53 HV_PTE base;
54};
55
56int __iorpc_get_mmio_base(int fd, HV_PTE *base)
57{
58 int __result;
59 struct get_mmio_base_param temp;
60 struct get_mmio_base_param *params = &temp;
61
62 __result =
63 hv_dev_pread(fd, 0, (HV_VirtAddr) params, sizeof(*params),
64 IORPC_OP_GET_MMIO_BASE);
65 *base = params->base;
66
67 return __result;
68}
69
70EXPORT_SYMBOL(__iorpc_get_mmio_base);
71
72struct check_mmio_offset_param {
73 unsigned long offset;
74 unsigned long size;
75};
76
77int __iorpc_check_mmio_offset(int fd, unsigned long offset, unsigned long size)
78{
79 struct check_mmio_offset_param temp;
80 struct check_mmio_offset_param *params = &temp;
81
82 params->offset = offset;
83 params->size = size;
84
85 return hv_dev_pwrite(fd, 0, (HV_VirtAddr) params, sizeof(*params),
86 IORPC_OP_CHECK_MMIO_OFFSET);
87}
88
89EXPORT_SYMBOL(__iorpc_check_mmio_offset);
diff --git a/arch/tile/gxio/iorpc_mpipe.c b/arch/tile/gxio/iorpc_mpipe.c
deleted file mode 100644
index e19325c4c431..000000000000
--- a/arch/tile/gxio/iorpc_mpipe.c
+++ /dev/null
@@ -1,593 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#include "gxio/iorpc_mpipe.h"
17
18struct alloc_buffer_stacks_param {
19 unsigned int count;
20 unsigned int first;
21 unsigned int flags;
22};
23
24int gxio_mpipe_alloc_buffer_stacks(gxio_mpipe_context_t *context,
25 unsigned int count, unsigned int first,
26 unsigned int flags)
27{
28 struct alloc_buffer_stacks_param temp;
29 struct alloc_buffer_stacks_param *params = &temp;
30
31 params->count = count;
32 params->first = first;
33 params->flags = flags;
34
35 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
36 sizeof(*params),
37 GXIO_MPIPE_OP_ALLOC_BUFFER_STACKS);
38}
39
40EXPORT_SYMBOL(gxio_mpipe_alloc_buffer_stacks);
41
42struct init_buffer_stack_aux_param {
43 union iorpc_mem_buffer buffer;
44 unsigned int stack;
45 unsigned int buffer_size_enum;
46};
47
48int gxio_mpipe_init_buffer_stack_aux(gxio_mpipe_context_t *context,
49 void *mem_va, size_t mem_size,
50 unsigned int mem_flags, unsigned int stack,
51 unsigned int buffer_size_enum)
52{
53 int __result;
54 unsigned long long __cpa;
55 pte_t __pte;
56 struct init_buffer_stack_aux_param temp;
57 struct init_buffer_stack_aux_param *params = &temp;
58
59 __result = va_to_cpa_and_pte(mem_va, &__cpa, &__pte);
60 if (__result != 0)
61 return __result;
62 params->buffer.kernel.cpa = __cpa;
63 params->buffer.kernel.size = mem_size;
64 params->buffer.kernel.pte = __pte;
65 params->buffer.kernel.flags = mem_flags;
66 params->stack = stack;
67 params->buffer_size_enum = buffer_size_enum;
68
69 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
70 sizeof(*params),
71 GXIO_MPIPE_OP_INIT_BUFFER_STACK_AUX);
72}
73
74EXPORT_SYMBOL(gxio_mpipe_init_buffer_stack_aux);
75
76
77struct alloc_notif_rings_param {
78 unsigned int count;
79 unsigned int first;
80 unsigned int flags;
81};
82
83int gxio_mpipe_alloc_notif_rings(gxio_mpipe_context_t *context,
84 unsigned int count, unsigned int first,
85 unsigned int flags)
86{
87 struct alloc_notif_rings_param temp;
88 struct alloc_notif_rings_param *params = &temp;
89
90 params->count = count;
91 params->first = first;
92 params->flags = flags;
93
94 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
95 sizeof(*params), GXIO_MPIPE_OP_ALLOC_NOTIF_RINGS);
96}
97
98EXPORT_SYMBOL(gxio_mpipe_alloc_notif_rings);
99
100struct init_notif_ring_aux_param {
101 union iorpc_mem_buffer buffer;
102 unsigned int ring;
103};
104
105int gxio_mpipe_init_notif_ring_aux(gxio_mpipe_context_t *context, void *mem_va,
106 size_t mem_size, unsigned int mem_flags,
107 unsigned int ring)
108{
109 int __result;
110 unsigned long long __cpa;
111 pte_t __pte;
112 struct init_notif_ring_aux_param temp;
113 struct init_notif_ring_aux_param *params = &temp;
114
115 __result = va_to_cpa_and_pte(mem_va, &__cpa, &__pte);
116 if (__result != 0)
117 return __result;
118 params->buffer.kernel.cpa = __cpa;
119 params->buffer.kernel.size = mem_size;
120 params->buffer.kernel.pte = __pte;
121 params->buffer.kernel.flags = mem_flags;
122 params->ring = ring;
123
124 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
125 sizeof(*params),
126 GXIO_MPIPE_OP_INIT_NOTIF_RING_AUX);
127}
128
129EXPORT_SYMBOL(gxio_mpipe_init_notif_ring_aux);
130
131struct request_notif_ring_interrupt_param {
132 union iorpc_interrupt interrupt;
133 unsigned int ring;
134};
135
136int gxio_mpipe_request_notif_ring_interrupt(gxio_mpipe_context_t *context,
137 int inter_x, int inter_y,
138 int inter_ipi, int inter_event,
139 unsigned int ring)
140{
141 struct request_notif_ring_interrupt_param temp;
142 struct request_notif_ring_interrupt_param *params = &temp;
143
144 params->interrupt.kernel.x = inter_x;
145 params->interrupt.kernel.y = inter_y;
146 params->interrupt.kernel.ipi = inter_ipi;
147 params->interrupt.kernel.event = inter_event;
148 params->ring = ring;
149
150 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
151 sizeof(*params),
152 GXIO_MPIPE_OP_REQUEST_NOTIF_RING_INTERRUPT);
153}
154
155EXPORT_SYMBOL(gxio_mpipe_request_notif_ring_interrupt);
156
157struct enable_notif_ring_interrupt_param {
158 unsigned int ring;
159};
160
161int gxio_mpipe_enable_notif_ring_interrupt(gxio_mpipe_context_t *context,
162 unsigned int ring)
163{
164 struct enable_notif_ring_interrupt_param temp;
165 struct enable_notif_ring_interrupt_param *params = &temp;
166
167 params->ring = ring;
168
169 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
170 sizeof(*params),
171 GXIO_MPIPE_OP_ENABLE_NOTIF_RING_INTERRUPT);
172}
173
174EXPORT_SYMBOL(gxio_mpipe_enable_notif_ring_interrupt);
175
176struct alloc_notif_groups_param {
177 unsigned int count;
178 unsigned int first;
179 unsigned int flags;
180};
181
182int gxio_mpipe_alloc_notif_groups(gxio_mpipe_context_t *context,
183 unsigned int count, unsigned int first,
184 unsigned int flags)
185{
186 struct alloc_notif_groups_param temp;
187 struct alloc_notif_groups_param *params = &temp;
188
189 params->count = count;
190 params->first = first;
191 params->flags = flags;
192
193 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
194 sizeof(*params), GXIO_MPIPE_OP_ALLOC_NOTIF_GROUPS);
195}
196
197EXPORT_SYMBOL(gxio_mpipe_alloc_notif_groups);
198
199struct init_notif_group_param {
200 unsigned int group;
201 gxio_mpipe_notif_group_bits_t bits;
202};
203
204int gxio_mpipe_init_notif_group(gxio_mpipe_context_t *context,
205 unsigned int group,
206 gxio_mpipe_notif_group_bits_t bits)
207{
208 struct init_notif_group_param temp;
209 struct init_notif_group_param *params = &temp;
210
211 params->group = group;
212 params->bits = bits;
213
214 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
215 sizeof(*params), GXIO_MPIPE_OP_INIT_NOTIF_GROUP);
216}
217
218EXPORT_SYMBOL(gxio_mpipe_init_notif_group);
219
220struct alloc_buckets_param {
221 unsigned int count;
222 unsigned int first;
223 unsigned int flags;
224};
225
226int gxio_mpipe_alloc_buckets(gxio_mpipe_context_t *context, unsigned int count,
227 unsigned int first, unsigned int flags)
228{
229 struct alloc_buckets_param temp;
230 struct alloc_buckets_param *params = &temp;
231
232 params->count = count;
233 params->first = first;
234 params->flags = flags;
235
236 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
237 sizeof(*params), GXIO_MPIPE_OP_ALLOC_BUCKETS);
238}
239
240EXPORT_SYMBOL(gxio_mpipe_alloc_buckets);
241
242struct init_bucket_param {
243 unsigned int bucket;
244 MPIPE_LBL_INIT_DAT_BSTS_TBL_t bucket_info;
245};
246
247int gxio_mpipe_init_bucket(gxio_mpipe_context_t *context, unsigned int bucket,
248 MPIPE_LBL_INIT_DAT_BSTS_TBL_t bucket_info)
249{
250 struct init_bucket_param temp;
251 struct init_bucket_param *params = &temp;
252
253 params->bucket = bucket;
254 params->bucket_info = bucket_info;
255
256 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
257 sizeof(*params), GXIO_MPIPE_OP_INIT_BUCKET);
258}
259
260EXPORT_SYMBOL(gxio_mpipe_init_bucket);
261
262struct alloc_edma_rings_param {
263 unsigned int count;
264 unsigned int first;
265 unsigned int flags;
266};
267
268int gxio_mpipe_alloc_edma_rings(gxio_mpipe_context_t *context,
269 unsigned int count, unsigned int first,
270 unsigned int flags)
271{
272 struct alloc_edma_rings_param temp;
273 struct alloc_edma_rings_param *params = &temp;
274
275 params->count = count;
276 params->first = first;
277 params->flags = flags;
278
279 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
280 sizeof(*params), GXIO_MPIPE_OP_ALLOC_EDMA_RINGS);
281}
282
283EXPORT_SYMBOL(gxio_mpipe_alloc_edma_rings);
284
285struct init_edma_ring_aux_param {
286 union iorpc_mem_buffer buffer;
287 unsigned int ring;
288 unsigned int channel;
289};
290
291int gxio_mpipe_init_edma_ring_aux(gxio_mpipe_context_t *context, void *mem_va,
292 size_t mem_size, unsigned int mem_flags,
293 unsigned int ring, unsigned int channel)
294{
295 int __result;
296 unsigned long long __cpa;
297 pte_t __pte;
298 struct init_edma_ring_aux_param temp;
299 struct init_edma_ring_aux_param *params = &temp;
300
301 __result = va_to_cpa_and_pte(mem_va, &__cpa, &__pte);
302 if (__result != 0)
303 return __result;
304 params->buffer.kernel.cpa = __cpa;
305 params->buffer.kernel.size = mem_size;
306 params->buffer.kernel.pte = __pte;
307 params->buffer.kernel.flags = mem_flags;
308 params->ring = ring;
309 params->channel = channel;
310
311 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
312 sizeof(*params), GXIO_MPIPE_OP_INIT_EDMA_RING_AUX);
313}
314
315EXPORT_SYMBOL(gxio_mpipe_init_edma_ring_aux);
316
317
318int gxio_mpipe_commit_rules(gxio_mpipe_context_t *context, const void *blob,
319 size_t blob_size)
320{
321 const void *params = blob;
322
323 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params, blob_size,
324 GXIO_MPIPE_OP_COMMIT_RULES);
325}
326
327EXPORT_SYMBOL(gxio_mpipe_commit_rules);
328
329struct register_client_memory_param {
330 unsigned int iotlb;
331 HV_PTE pte;
332 unsigned int flags;
333};
334
335int gxio_mpipe_register_client_memory(gxio_mpipe_context_t *context,
336 unsigned int iotlb, HV_PTE pte,
337 unsigned int flags)
338{
339 struct register_client_memory_param temp;
340 struct register_client_memory_param *params = &temp;
341
342 params->iotlb = iotlb;
343 params->pte = pte;
344 params->flags = flags;
345
346 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
347 sizeof(*params),
348 GXIO_MPIPE_OP_REGISTER_CLIENT_MEMORY);
349}
350
351EXPORT_SYMBOL(gxio_mpipe_register_client_memory);
352
353struct link_open_aux_param {
354 _gxio_mpipe_link_name_t name;
355 unsigned int flags;
356};
357
358int gxio_mpipe_link_open_aux(gxio_mpipe_context_t *context,
359 _gxio_mpipe_link_name_t name, unsigned int flags)
360{
361 struct link_open_aux_param temp;
362 struct link_open_aux_param *params = &temp;
363
364 params->name = name;
365 params->flags = flags;
366
367 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
368 sizeof(*params), GXIO_MPIPE_OP_LINK_OPEN_AUX);
369}
370
371EXPORT_SYMBOL(gxio_mpipe_link_open_aux);
372
373struct link_close_aux_param {
374 int mac;
375};
376
377int gxio_mpipe_link_close_aux(gxio_mpipe_context_t *context, int mac)
378{
379 struct link_close_aux_param temp;
380 struct link_close_aux_param *params = &temp;
381
382 params->mac = mac;
383
384 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
385 sizeof(*params), GXIO_MPIPE_OP_LINK_CLOSE_AUX);
386}
387
388EXPORT_SYMBOL(gxio_mpipe_link_close_aux);
389
390struct link_set_attr_aux_param {
391 int mac;
392 uint32_t attr;
393 int64_t val;
394};
395
396int gxio_mpipe_link_set_attr_aux(gxio_mpipe_context_t *context, int mac,
397 uint32_t attr, int64_t val)
398{
399 struct link_set_attr_aux_param temp;
400 struct link_set_attr_aux_param *params = &temp;
401
402 params->mac = mac;
403 params->attr = attr;
404 params->val = val;
405
406 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
407 sizeof(*params), GXIO_MPIPE_OP_LINK_SET_ATTR_AUX);
408}
409
410EXPORT_SYMBOL(gxio_mpipe_link_set_attr_aux);
411
412struct get_timestamp_aux_param {
413 uint64_t sec;
414 uint64_t nsec;
415 uint64_t cycles;
416};
417
418int gxio_mpipe_get_timestamp_aux(gxio_mpipe_context_t *context, uint64_t *sec,
419 uint64_t *nsec, uint64_t *cycles)
420{
421 int __result;
422 struct get_timestamp_aux_param temp;
423 struct get_timestamp_aux_param *params = &temp;
424
425 __result =
426 hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
427 GXIO_MPIPE_OP_GET_TIMESTAMP_AUX);
428 *sec = params->sec;
429 *nsec = params->nsec;
430 *cycles = params->cycles;
431
432 return __result;
433}
434
435EXPORT_SYMBOL(gxio_mpipe_get_timestamp_aux);
436
437struct set_timestamp_aux_param {
438 uint64_t sec;
439 uint64_t nsec;
440 uint64_t cycles;
441};
442
443int gxio_mpipe_set_timestamp_aux(gxio_mpipe_context_t *context, uint64_t sec,
444 uint64_t nsec, uint64_t cycles)
445{
446 struct set_timestamp_aux_param temp;
447 struct set_timestamp_aux_param *params = &temp;
448
449 params->sec = sec;
450 params->nsec = nsec;
451 params->cycles = cycles;
452
453 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
454 sizeof(*params), GXIO_MPIPE_OP_SET_TIMESTAMP_AUX);
455}
456
457EXPORT_SYMBOL(gxio_mpipe_set_timestamp_aux);
458
459struct adjust_timestamp_aux_param {
460 int64_t nsec;
461};
462
463int gxio_mpipe_adjust_timestamp_aux(gxio_mpipe_context_t *context, int64_t nsec)
464{
465 struct adjust_timestamp_aux_param temp;
466 struct adjust_timestamp_aux_param *params = &temp;
467
468 params->nsec = nsec;
469
470 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
471 sizeof(*params),
472 GXIO_MPIPE_OP_ADJUST_TIMESTAMP_AUX);
473}
474
475EXPORT_SYMBOL(gxio_mpipe_adjust_timestamp_aux);
476
477struct config_edma_ring_blks_param {
478 unsigned int ering;
479 unsigned int max_blks;
480 unsigned int min_snf_blks;
481 unsigned int db;
482};
483
484int gxio_mpipe_config_edma_ring_blks(gxio_mpipe_context_t *context,
485 unsigned int ering, unsigned int max_blks,
486 unsigned int min_snf_blks, unsigned int db)
487{
488 struct config_edma_ring_blks_param temp;
489 struct config_edma_ring_blks_param *params = &temp;
490
491 params->ering = ering;
492 params->max_blks = max_blks;
493 params->min_snf_blks = min_snf_blks;
494 params->db = db;
495
496 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
497 sizeof(*params),
498 GXIO_MPIPE_OP_CONFIG_EDMA_RING_BLKS);
499}
500
501EXPORT_SYMBOL(gxio_mpipe_config_edma_ring_blks);
502
503struct adjust_timestamp_freq_param {
504 int32_t ppb;
505};
506
507int gxio_mpipe_adjust_timestamp_freq(gxio_mpipe_context_t *context, int32_t ppb)
508{
509 struct adjust_timestamp_freq_param temp;
510 struct adjust_timestamp_freq_param *params = &temp;
511
512 params->ppb = ppb;
513
514 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
515 sizeof(*params),
516 GXIO_MPIPE_OP_ADJUST_TIMESTAMP_FREQ);
517}
518
519EXPORT_SYMBOL(gxio_mpipe_adjust_timestamp_freq);
520
521struct arm_pollfd_param {
522 union iorpc_pollfd pollfd;
523};
524
525int gxio_mpipe_arm_pollfd(gxio_mpipe_context_t *context, int pollfd_cookie)
526{
527 struct arm_pollfd_param temp;
528 struct arm_pollfd_param *params = &temp;
529
530 params->pollfd.kernel.cookie = pollfd_cookie;
531
532 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
533 sizeof(*params), GXIO_MPIPE_OP_ARM_POLLFD);
534}
535
536EXPORT_SYMBOL(gxio_mpipe_arm_pollfd);
537
538struct close_pollfd_param {
539 union iorpc_pollfd pollfd;
540};
541
542int gxio_mpipe_close_pollfd(gxio_mpipe_context_t *context, int pollfd_cookie)
543{
544 struct close_pollfd_param temp;
545 struct close_pollfd_param *params = &temp;
546
547 params->pollfd.kernel.cookie = pollfd_cookie;
548
549 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
550 sizeof(*params), GXIO_MPIPE_OP_CLOSE_POLLFD);
551}
552
553EXPORT_SYMBOL(gxio_mpipe_close_pollfd);
554
555struct get_mmio_base_param {
556 HV_PTE base;
557};
558
559int gxio_mpipe_get_mmio_base(gxio_mpipe_context_t *context, HV_PTE *base)
560{
561 int __result;
562 struct get_mmio_base_param temp;
563 struct get_mmio_base_param *params = &temp;
564
565 __result =
566 hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
567 GXIO_MPIPE_OP_GET_MMIO_BASE);
568 *base = params->base;
569
570 return __result;
571}
572
573EXPORT_SYMBOL(gxio_mpipe_get_mmio_base);
574
575struct check_mmio_offset_param {
576 unsigned long offset;
577 unsigned long size;
578};
579
580int gxio_mpipe_check_mmio_offset(gxio_mpipe_context_t *context,
581 unsigned long offset, unsigned long size)
582{
583 struct check_mmio_offset_param temp;
584 struct check_mmio_offset_param *params = &temp;
585
586 params->offset = offset;
587 params->size = size;
588
589 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
590 sizeof(*params), GXIO_MPIPE_OP_CHECK_MMIO_OFFSET);
591}
592
593EXPORT_SYMBOL(gxio_mpipe_check_mmio_offset);
diff --git a/arch/tile/gxio/iorpc_mpipe_info.c b/arch/tile/gxio/iorpc_mpipe_info.c
deleted file mode 100644
index 77019c6e9b4a..000000000000
--- a/arch/tile/gxio/iorpc_mpipe_info.c
+++ /dev/null
@@ -1,102 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#include "gxio/iorpc_mpipe_info.h"
17
18struct instance_aux_param {
19 _gxio_mpipe_link_name_t name;
20};
21
22int gxio_mpipe_info_instance_aux(gxio_mpipe_info_context_t *context,
23 _gxio_mpipe_link_name_t name)
24{
25 struct instance_aux_param temp;
26 struct instance_aux_param *params = &temp;
27
28 params->name = name;
29
30 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
31 sizeof(*params), GXIO_MPIPE_INFO_OP_INSTANCE_AUX);
32}
33
34EXPORT_SYMBOL(gxio_mpipe_info_instance_aux);
35
36struct enumerate_aux_param {
37 _gxio_mpipe_link_name_t name;
38 _gxio_mpipe_link_mac_t mac;
39};
40
41int gxio_mpipe_info_enumerate_aux(gxio_mpipe_info_context_t *context,
42 unsigned int idx,
43 _gxio_mpipe_link_name_t *name,
44 _gxio_mpipe_link_mac_t *mac)
45{
46 int __result;
47 struct enumerate_aux_param temp;
48 struct enumerate_aux_param *params = &temp;
49
50 __result =
51 hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
52 (((uint64_t)idx << 32) |
53 GXIO_MPIPE_INFO_OP_ENUMERATE_AUX));
54 *name = params->name;
55 *mac = params->mac;
56
57 return __result;
58}
59
60EXPORT_SYMBOL(gxio_mpipe_info_enumerate_aux);
61
62struct get_mmio_base_param {
63 HV_PTE base;
64};
65
66int gxio_mpipe_info_get_mmio_base(gxio_mpipe_info_context_t *context,
67 HV_PTE *base)
68{
69 int __result;
70 struct get_mmio_base_param temp;
71 struct get_mmio_base_param *params = &temp;
72
73 __result =
74 hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
75 GXIO_MPIPE_INFO_OP_GET_MMIO_BASE);
76 *base = params->base;
77
78 return __result;
79}
80
81EXPORT_SYMBOL(gxio_mpipe_info_get_mmio_base);
82
83struct check_mmio_offset_param {
84 unsigned long offset;
85 unsigned long size;
86};
87
88int gxio_mpipe_info_check_mmio_offset(gxio_mpipe_info_context_t *context,
89 unsigned long offset, unsigned long size)
90{
91 struct check_mmio_offset_param temp;
92 struct check_mmio_offset_param *params = &temp;
93
94 params->offset = offset;
95 params->size = size;
96
97 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
98 sizeof(*params),
99 GXIO_MPIPE_INFO_OP_CHECK_MMIO_OFFSET);
100}
101
102EXPORT_SYMBOL(gxio_mpipe_info_check_mmio_offset);
diff --git a/arch/tile/gxio/iorpc_trio.c b/arch/tile/gxio/iorpc_trio.c
deleted file mode 100644
index 1d3cedb9aeb4..000000000000
--- a/arch/tile/gxio/iorpc_trio.c
+++ /dev/null
@@ -1,350 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#include "gxio/iorpc_trio.h"
17
18struct alloc_asids_param {
19 unsigned int count;
20 unsigned int first;
21 unsigned int flags;
22};
23
24int gxio_trio_alloc_asids(gxio_trio_context_t *context, unsigned int count,
25 unsigned int first, unsigned int flags)
26{
27 struct alloc_asids_param temp;
28 struct alloc_asids_param *params = &temp;
29
30 params->count = count;
31 params->first = first;
32 params->flags = flags;
33
34 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
35 sizeof(*params), GXIO_TRIO_OP_ALLOC_ASIDS);
36}
37
38EXPORT_SYMBOL(gxio_trio_alloc_asids);
39
40
41struct alloc_memory_maps_param {
42 unsigned int count;
43 unsigned int first;
44 unsigned int flags;
45};
46
47int gxio_trio_alloc_memory_maps(gxio_trio_context_t *context,
48 unsigned int count, unsigned int first,
49 unsigned int flags)
50{
51 struct alloc_memory_maps_param temp;
52 struct alloc_memory_maps_param *params = &temp;
53
54 params->count = count;
55 params->first = first;
56 params->flags = flags;
57
58 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
59 sizeof(*params), GXIO_TRIO_OP_ALLOC_MEMORY_MAPS);
60}
61
62EXPORT_SYMBOL(gxio_trio_alloc_memory_maps);
63
64struct alloc_scatter_queues_param {
65 unsigned int count;
66 unsigned int first;
67 unsigned int flags;
68};
69
70int gxio_trio_alloc_scatter_queues(gxio_trio_context_t *context,
71 unsigned int count, unsigned int first,
72 unsigned int flags)
73{
74 struct alloc_scatter_queues_param temp;
75 struct alloc_scatter_queues_param *params = &temp;
76
77 params->count = count;
78 params->first = first;
79 params->flags = flags;
80
81 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
82 sizeof(*params),
83 GXIO_TRIO_OP_ALLOC_SCATTER_QUEUES);
84}
85
86EXPORT_SYMBOL(gxio_trio_alloc_scatter_queues);
87
88struct alloc_pio_regions_param {
89 unsigned int count;
90 unsigned int first;
91 unsigned int flags;
92};
93
94int gxio_trio_alloc_pio_regions(gxio_trio_context_t *context,
95 unsigned int count, unsigned int first,
96 unsigned int flags)
97{
98 struct alloc_pio_regions_param temp;
99 struct alloc_pio_regions_param *params = &temp;
100
101 params->count = count;
102 params->first = first;
103 params->flags = flags;
104
105 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
106 sizeof(*params), GXIO_TRIO_OP_ALLOC_PIO_REGIONS);
107}
108
109EXPORT_SYMBOL(gxio_trio_alloc_pio_regions);
110
111struct init_pio_region_aux_param {
112 unsigned int pio_region;
113 unsigned int mac;
114 uint32_t bus_address_hi;
115 unsigned int flags;
116};
117
118int gxio_trio_init_pio_region_aux(gxio_trio_context_t *context,
119 unsigned int pio_region, unsigned int mac,
120 uint32_t bus_address_hi, unsigned int flags)
121{
122 struct init_pio_region_aux_param temp;
123 struct init_pio_region_aux_param *params = &temp;
124
125 params->pio_region = pio_region;
126 params->mac = mac;
127 params->bus_address_hi = bus_address_hi;
128 params->flags = flags;
129
130 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
131 sizeof(*params), GXIO_TRIO_OP_INIT_PIO_REGION_AUX);
132}
133
134EXPORT_SYMBOL(gxio_trio_init_pio_region_aux);
135
136
137struct init_memory_map_mmu_aux_param {
138 unsigned int map;
139 unsigned long va;
140 uint64_t size;
141 unsigned int asid;
142 unsigned int mac;
143 uint64_t bus_address;
144 unsigned int node;
145 unsigned int order_mode;
146};
147
148int gxio_trio_init_memory_map_mmu_aux(gxio_trio_context_t *context,
149 unsigned int map, unsigned long va,
150 uint64_t size, unsigned int asid,
151 unsigned int mac, uint64_t bus_address,
152 unsigned int node,
153 unsigned int order_mode)
154{
155 struct init_memory_map_mmu_aux_param temp;
156 struct init_memory_map_mmu_aux_param *params = &temp;
157
158 params->map = map;
159 params->va = va;
160 params->size = size;
161 params->asid = asid;
162 params->mac = mac;
163 params->bus_address = bus_address;
164 params->node = node;
165 params->order_mode = order_mode;
166
167 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
168 sizeof(*params),
169 GXIO_TRIO_OP_INIT_MEMORY_MAP_MMU_AUX);
170}
171
172EXPORT_SYMBOL(gxio_trio_init_memory_map_mmu_aux);
173
174struct get_port_property_param {
175 struct pcie_trio_ports_property trio_ports;
176};
177
178int gxio_trio_get_port_property(gxio_trio_context_t *context,
179 struct pcie_trio_ports_property *trio_ports)
180{
181 int __result;
182 struct get_port_property_param temp;
183 struct get_port_property_param *params = &temp;
184
185 __result =
186 hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
187 GXIO_TRIO_OP_GET_PORT_PROPERTY);
188 *trio_ports = params->trio_ports;
189
190 return __result;
191}
192
193EXPORT_SYMBOL(gxio_trio_get_port_property);
194
195struct config_legacy_intr_param {
196 union iorpc_interrupt interrupt;
197 unsigned int mac;
198 unsigned int intx;
199};
200
201int gxio_trio_config_legacy_intr(gxio_trio_context_t *context, int inter_x,
202 int inter_y, int inter_ipi, int inter_event,
203 unsigned int mac, unsigned int intx)
204{
205 struct config_legacy_intr_param temp;
206 struct config_legacy_intr_param *params = &temp;
207
208 params->interrupt.kernel.x = inter_x;
209 params->interrupt.kernel.y = inter_y;
210 params->interrupt.kernel.ipi = inter_ipi;
211 params->interrupt.kernel.event = inter_event;
212 params->mac = mac;
213 params->intx = intx;
214
215 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
216 sizeof(*params), GXIO_TRIO_OP_CONFIG_LEGACY_INTR);
217}
218
219EXPORT_SYMBOL(gxio_trio_config_legacy_intr);
220
221struct config_msi_intr_param {
222 union iorpc_interrupt interrupt;
223 unsigned int mac;
224 unsigned int mem_map;
225 uint64_t mem_map_base;
226 uint64_t mem_map_limit;
227 unsigned int asid;
228};
229
230int gxio_trio_config_msi_intr(gxio_trio_context_t *context, int inter_x,
231 int inter_y, int inter_ipi, int inter_event,
232 unsigned int mac, unsigned int mem_map,
233 uint64_t mem_map_base, uint64_t mem_map_limit,
234 unsigned int asid)
235{
236 struct config_msi_intr_param temp;
237 struct config_msi_intr_param *params = &temp;
238
239 params->interrupt.kernel.x = inter_x;
240 params->interrupt.kernel.y = inter_y;
241 params->interrupt.kernel.ipi = inter_ipi;
242 params->interrupt.kernel.event = inter_event;
243 params->mac = mac;
244 params->mem_map = mem_map;
245 params->mem_map_base = mem_map_base;
246 params->mem_map_limit = mem_map_limit;
247 params->asid = asid;
248
249 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
250 sizeof(*params), GXIO_TRIO_OP_CONFIG_MSI_INTR);
251}
252
253EXPORT_SYMBOL(gxio_trio_config_msi_intr);
254
255
256struct set_mps_mrs_param {
257 uint16_t mps;
258 uint16_t mrs;
259 unsigned int mac;
260};
261
262int gxio_trio_set_mps_mrs(gxio_trio_context_t *context, uint16_t mps,
263 uint16_t mrs, unsigned int mac)
264{
265 struct set_mps_mrs_param temp;
266 struct set_mps_mrs_param *params = &temp;
267
268 params->mps = mps;
269 params->mrs = mrs;
270 params->mac = mac;
271
272 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
273 sizeof(*params), GXIO_TRIO_OP_SET_MPS_MRS);
274}
275
276EXPORT_SYMBOL(gxio_trio_set_mps_mrs);
277
278struct force_rc_link_up_param {
279 unsigned int mac;
280};
281
282int gxio_trio_force_rc_link_up(gxio_trio_context_t *context, unsigned int mac)
283{
284 struct force_rc_link_up_param temp;
285 struct force_rc_link_up_param *params = &temp;
286
287 params->mac = mac;
288
289 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
290 sizeof(*params), GXIO_TRIO_OP_FORCE_RC_LINK_UP);
291}
292
293EXPORT_SYMBOL(gxio_trio_force_rc_link_up);
294
295struct force_ep_link_up_param {
296 unsigned int mac;
297};
298
299int gxio_trio_force_ep_link_up(gxio_trio_context_t *context, unsigned int mac)
300{
301 struct force_ep_link_up_param temp;
302 struct force_ep_link_up_param *params = &temp;
303
304 params->mac = mac;
305
306 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
307 sizeof(*params), GXIO_TRIO_OP_FORCE_EP_LINK_UP);
308}
309
310EXPORT_SYMBOL(gxio_trio_force_ep_link_up);
311
312struct get_mmio_base_param {
313 HV_PTE base;
314};
315
316int gxio_trio_get_mmio_base(gxio_trio_context_t *context, HV_PTE *base)
317{
318 int __result;
319 struct get_mmio_base_param temp;
320 struct get_mmio_base_param *params = &temp;
321
322 __result =
323 hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
324 GXIO_TRIO_OP_GET_MMIO_BASE);
325 *base = params->base;
326
327 return __result;
328}
329
330EXPORT_SYMBOL(gxio_trio_get_mmio_base);
331
332struct check_mmio_offset_param {
333 unsigned long offset;
334 unsigned long size;
335};
336
337int gxio_trio_check_mmio_offset(gxio_trio_context_t *context,
338 unsigned long offset, unsigned long size)
339{
340 struct check_mmio_offset_param temp;
341 struct check_mmio_offset_param *params = &temp;
342
343 params->offset = offset;
344 params->size = size;
345
346 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
347 sizeof(*params), GXIO_TRIO_OP_CHECK_MMIO_OFFSET);
348}
349
350EXPORT_SYMBOL(gxio_trio_check_mmio_offset);
diff --git a/arch/tile/gxio/iorpc_uart.c b/arch/tile/gxio/iorpc_uart.c
deleted file mode 100644
index b9a6d6193d73..000000000000
--- a/arch/tile/gxio/iorpc_uart.c
+++ /dev/null
@@ -1,77 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#include "gxio/iorpc_uart.h"
17
18struct cfg_interrupt_param {
19 union iorpc_interrupt interrupt;
20};
21
22int gxio_uart_cfg_interrupt(gxio_uart_context_t *context, int inter_x,
23 int inter_y, int inter_ipi, int inter_event)
24{
25 struct cfg_interrupt_param temp;
26 struct cfg_interrupt_param *params = &temp;
27
28 params->interrupt.kernel.x = inter_x;
29 params->interrupt.kernel.y = inter_y;
30 params->interrupt.kernel.ipi = inter_ipi;
31 params->interrupt.kernel.event = inter_event;
32
33 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
34 sizeof(*params), GXIO_UART_OP_CFG_INTERRUPT);
35}
36
37EXPORT_SYMBOL(gxio_uart_cfg_interrupt);
38
39struct get_mmio_base_param {
40 HV_PTE base;
41};
42
43int gxio_uart_get_mmio_base(gxio_uart_context_t *context, HV_PTE *base)
44{
45 int __result;
46 struct get_mmio_base_param temp;
47 struct get_mmio_base_param *params = &temp;
48
49 __result =
50 hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
51 GXIO_UART_OP_GET_MMIO_BASE);
52 *base = params->base;
53
54 return __result;
55}
56
57EXPORT_SYMBOL(gxio_uart_get_mmio_base);
58
59struct check_mmio_offset_param {
60 unsigned long offset;
61 unsigned long size;
62};
63
64int gxio_uart_check_mmio_offset(gxio_uart_context_t *context,
65 unsigned long offset, unsigned long size)
66{
67 struct check_mmio_offset_param temp;
68 struct check_mmio_offset_param *params = &temp;
69
70 params->offset = offset;
71 params->size = size;
72
73 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
74 sizeof(*params), GXIO_UART_OP_CHECK_MMIO_OFFSET);
75}
76
77EXPORT_SYMBOL(gxio_uart_check_mmio_offset);
diff --git a/arch/tile/gxio/iorpc_usb_host.c b/arch/tile/gxio/iorpc_usb_host.c
deleted file mode 100644
index 9c820073bfc0..000000000000
--- a/arch/tile/gxio/iorpc_usb_host.c
+++ /dev/null
@@ -1,99 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#include "gxio/iorpc_usb_host.h"
17
18struct cfg_interrupt_param {
19 union iorpc_interrupt interrupt;
20};
21
22int gxio_usb_host_cfg_interrupt(gxio_usb_host_context_t *context, int inter_x,
23 int inter_y, int inter_ipi, int inter_event)
24{
25 struct cfg_interrupt_param temp;
26 struct cfg_interrupt_param *params = &temp;
27
28 params->interrupt.kernel.x = inter_x;
29 params->interrupt.kernel.y = inter_y;
30 params->interrupt.kernel.ipi = inter_ipi;
31 params->interrupt.kernel.event = inter_event;
32
33 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
34 sizeof(*params), GXIO_USB_HOST_OP_CFG_INTERRUPT);
35}
36
37EXPORT_SYMBOL(gxio_usb_host_cfg_interrupt);
38
39struct register_client_memory_param {
40 HV_PTE pte;
41 unsigned int flags;
42};
43
44int gxio_usb_host_register_client_memory(gxio_usb_host_context_t *context,
45 HV_PTE pte, unsigned int flags)
46{
47 struct register_client_memory_param temp;
48 struct register_client_memory_param *params = &temp;
49
50 params->pte = pte;
51 params->flags = flags;
52
53 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
54 sizeof(*params),
55 GXIO_USB_HOST_OP_REGISTER_CLIENT_MEMORY);
56}
57
58EXPORT_SYMBOL(gxio_usb_host_register_client_memory);
59
60struct get_mmio_base_param {
61 HV_PTE base;
62};
63
64int gxio_usb_host_get_mmio_base(gxio_usb_host_context_t *context, HV_PTE *base)
65{
66 int __result;
67 struct get_mmio_base_param temp;
68 struct get_mmio_base_param *params = &temp;
69
70 __result =
71 hv_dev_pread(context->fd, 0, (HV_VirtAddr) params, sizeof(*params),
72 GXIO_USB_HOST_OP_GET_MMIO_BASE);
73 *base = params->base;
74
75 return __result;
76}
77
78EXPORT_SYMBOL(gxio_usb_host_get_mmio_base);
79
80struct check_mmio_offset_param {
81 unsigned long offset;
82 unsigned long size;
83};
84
85int gxio_usb_host_check_mmio_offset(gxio_usb_host_context_t *context,
86 unsigned long offset, unsigned long size)
87{
88 struct check_mmio_offset_param temp;
89 struct check_mmio_offset_param *params = &temp;
90
91 params->offset = offset;
92 params->size = size;
93
94 return hv_dev_pwrite(context->fd, 0, (HV_VirtAddr) params,
95 sizeof(*params),
96 GXIO_USB_HOST_OP_CHECK_MMIO_OFFSET);
97}
98
99EXPORT_SYMBOL(gxio_usb_host_check_mmio_offset);
diff --git a/arch/tile/gxio/kiorpc.c b/arch/tile/gxio/kiorpc.c
deleted file mode 100644
index c8096aa5a3fc..000000000000
--- a/arch/tile/gxio/kiorpc.c
+++ /dev/null
@@ -1,61 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE-Gx IORPC support for kernel I/O drivers.
15 */
16
17#include <linux/mmzone.h>
18#include <linux/module.h>
19#include <linux/io.h>
20#include <gxio/iorpc_globals.h>
21#include <gxio/kiorpc.h>
22
23#ifdef DEBUG_IORPC
24#define TRACE(FMT, ...) pr_info(SIMPLE_MSG_LINE FMT, ## __VA_ARGS__)
25#else
26#define TRACE(...)
27#endif
28
29/* Create kernel-VA-space MMIO mapping for an on-chip IO device. */
30void __iomem *iorpc_ioremap(int hv_fd, resource_size_t offset,
31 unsigned long size)
32{
33 pgprot_t mmio_base, prot = { 0 };
34 unsigned long pfn;
35 int err;
36
37 /* Look up the shim's lotar and base PA. */
38 err = __iorpc_get_mmio_base(hv_fd, &mmio_base);
39 if (err) {
40 TRACE("get_mmio_base() failure: %d\n", err);
41 return NULL;
42 }
43
44 /* Make sure the HV driver approves of our offset and size. */
45 err = __iorpc_check_mmio_offset(hv_fd, offset, size);
46 if (err) {
47 TRACE("check_mmio_offset() failure: %d\n", err);
48 return NULL;
49 }
50
51 /*
52 * mmio_base contains a base pfn and homing coordinates. Turn
53 * it into an MMIO pgprot and offset pfn.
54 */
55 prot = hv_pte_set_lotar(prot, hv_pte_get_lotar(mmio_base));
56 pfn = pte_pfn(mmio_base) + PFN_DOWN(offset);
57
58 return ioremap_prot(PFN_PHYS(pfn), size, prot);
59}
60
61EXPORT_SYMBOL(iorpc_ioremap);
diff --git a/arch/tile/gxio/mpipe.c b/arch/tile/gxio/mpipe.c
deleted file mode 100644
index 34de300ab320..000000000000
--- a/arch/tile/gxio/mpipe.c
+++ /dev/null
@@ -1,584 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/*
16 * Implementation of mpipe gxio calls.
17 */
18
19#include <linux/errno.h>
20#include <linux/io.h>
21#include <linux/module.h>
22#include <linux/string.h>
23
24#include <gxio/iorpc_globals.h>
25#include <gxio/iorpc_mpipe.h>
26#include <gxio/iorpc_mpipe_info.h>
27#include <gxio/kiorpc.h>
28#include <gxio/mpipe.h>
29
30/* HACK: Avoid pointless "shadow" warnings. */
31#define link link_shadow
32
33int gxio_mpipe_init(gxio_mpipe_context_t *context, unsigned int mpipe_index)
34{
35 char file[32];
36
37 int fd;
38 int i;
39
40 if (mpipe_index >= GXIO_MPIPE_INSTANCE_MAX)
41 return -EINVAL;
42
43 snprintf(file, sizeof(file), "mpipe/%d/iorpc", mpipe_index);
44 fd = hv_dev_open((HV_VirtAddr) file, 0);
45
46 context->fd = fd;
47
48 if (fd < 0) {
49 if (fd >= GXIO_ERR_MIN && fd <= GXIO_ERR_MAX)
50 return fd;
51 else
52 return -ENODEV;
53 }
54
55 /* Map in the MMIO space. */
56 context->mmio_cfg_base = (void __force *)
57 iorpc_ioremap(fd, HV_MPIPE_CONFIG_MMIO_OFFSET,
58 HV_MPIPE_CONFIG_MMIO_SIZE);
59 if (context->mmio_cfg_base == NULL)
60 goto cfg_failed;
61
62 context->mmio_fast_base = (void __force *)
63 iorpc_ioremap(fd, HV_MPIPE_FAST_MMIO_OFFSET,
64 HV_MPIPE_FAST_MMIO_SIZE);
65 if (context->mmio_fast_base == NULL)
66 goto fast_failed;
67
68 /* Initialize the stacks. */
69 for (i = 0; i < 8; i++)
70 context->__stacks.stacks[i] = 255;
71
72 context->instance = mpipe_index;
73
74 return 0;
75
76 fast_failed:
77 iounmap((void __force __iomem *)(context->mmio_cfg_base));
78 cfg_failed:
79 hv_dev_close(context->fd);
80 context->fd = -1;
81 return -ENODEV;
82}
83
84EXPORT_SYMBOL_GPL(gxio_mpipe_init);
85
86int gxio_mpipe_destroy(gxio_mpipe_context_t *context)
87{
88 iounmap((void __force __iomem *)(context->mmio_cfg_base));
89 iounmap((void __force __iomem *)(context->mmio_fast_base));
90 return hv_dev_close(context->fd);
91}
92
93EXPORT_SYMBOL_GPL(gxio_mpipe_destroy);
94
95static int16_t gxio_mpipe_buffer_sizes[8] =
96 { 128, 256, 512, 1024, 1664, 4096, 10368, 16384 };
97
98gxio_mpipe_buffer_size_enum_t gxio_mpipe_buffer_size_to_buffer_size_enum(size_t
99 size)
100{
101 int i;
102 for (i = 0; i < 7; i++)
103 if (size <= gxio_mpipe_buffer_sizes[i])
104 break;
105 return i;
106}
107
108EXPORT_SYMBOL_GPL(gxio_mpipe_buffer_size_to_buffer_size_enum);
109
110size_t gxio_mpipe_buffer_size_enum_to_buffer_size(gxio_mpipe_buffer_size_enum_t
111 buffer_size_enum)
112{
113 if (buffer_size_enum > 7)
114 buffer_size_enum = 7;
115
116 return gxio_mpipe_buffer_sizes[buffer_size_enum];
117}
118
119EXPORT_SYMBOL_GPL(gxio_mpipe_buffer_size_enum_to_buffer_size);
120
121size_t gxio_mpipe_calc_buffer_stack_bytes(unsigned long buffers)
122{
123 const int BUFFERS_PER_LINE = 12;
124
125 /* Count the number of cachelines. */
126 unsigned long lines =
127 (buffers + BUFFERS_PER_LINE - 1) / BUFFERS_PER_LINE;
128
129 /* Convert to bytes. */
130 return lines * CHIP_L2_LINE_SIZE();
131}
132
133EXPORT_SYMBOL_GPL(gxio_mpipe_calc_buffer_stack_bytes);
134
135int gxio_mpipe_init_buffer_stack(gxio_mpipe_context_t *context,
136 unsigned int stack,
137 gxio_mpipe_buffer_size_enum_t
138 buffer_size_enum, void *mem, size_t mem_size,
139 unsigned int mem_flags)
140{
141 int result;
142
143 memset(mem, 0, mem_size);
144
145 result = gxio_mpipe_init_buffer_stack_aux(context, mem, mem_size,
146 mem_flags, stack,
147 buffer_size_enum);
148 if (result < 0)
149 return result;
150
151 /* Save the stack. */
152 context->__stacks.stacks[buffer_size_enum] = stack;
153
154 return 0;
155}
156
157EXPORT_SYMBOL_GPL(gxio_mpipe_init_buffer_stack);
158
159int gxio_mpipe_init_notif_ring(gxio_mpipe_context_t *context,
160 unsigned int ring,
161 void *mem, size_t mem_size,
162 unsigned int mem_flags)
163{
164 return gxio_mpipe_init_notif_ring_aux(context, mem, mem_size,
165 mem_flags, ring);
166}
167
168EXPORT_SYMBOL_GPL(gxio_mpipe_init_notif_ring);
169
170int gxio_mpipe_init_notif_group_and_buckets(gxio_mpipe_context_t *context,
171 unsigned int group,
172 unsigned int ring,
173 unsigned int num_rings,
174 unsigned int bucket,
175 unsigned int num_buckets,
176 gxio_mpipe_bucket_mode_t mode)
177{
178 int i;
179 int result;
180
181 gxio_mpipe_bucket_info_t bucket_info = { {
182 .group = group,
183 .mode = mode,
184 }
185 };
186
187 gxio_mpipe_notif_group_bits_t bits = { {0} };
188
189 for (i = 0; i < num_rings; i++)
190 gxio_mpipe_notif_group_add_ring(&bits, ring + i);
191
192 result = gxio_mpipe_init_notif_group(context, group, bits);
193 if (result != 0)
194 return result;
195
196 for (i = 0; i < num_buckets; i++) {
197 bucket_info.notifring = ring + (i % num_rings);
198
199 result = gxio_mpipe_init_bucket(context, bucket + i,
200 bucket_info);
201 if (result != 0)
202 return result;
203 }
204
205 return 0;
206}
207
208EXPORT_SYMBOL_GPL(gxio_mpipe_init_notif_group_and_buckets);
209
210int gxio_mpipe_init_edma_ring(gxio_mpipe_context_t *context,
211 unsigned int ring, unsigned int channel,
212 void *mem, size_t mem_size,
213 unsigned int mem_flags)
214{
215 memset(mem, 0, mem_size);
216
217 return gxio_mpipe_init_edma_ring_aux(context, mem, mem_size, mem_flags,
218 ring, channel);
219}
220
221EXPORT_SYMBOL_GPL(gxio_mpipe_init_edma_ring);
222
223void gxio_mpipe_rules_init(gxio_mpipe_rules_t *rules,
224 gxio_mpipe_context_t *context)
225{
226 rules->context = context;
227 memset(&rules->list, 0, sizeof(rules->list));
228}
229
230EXPORT_SYMBOL_GPL(gxio_mpipe_rules_init);
231
232int gxio_mpipe_rules_begin(gxio_mpipe_rules_t *rules,
233 unsigned int bucket, unsigned int num_buckets,
234 gxio_mpipe_rules_stacks_t *stacks)
235{
236 int i;
237 int stack = 255;
238
239 gxio_mpipe_rules_list_t *list = &rules->list;
240
241 /* Current rule. */
242 gxio_mpipe_rules_rule_t *rule =
243 (gxio_mpipe_rules_rule_t *) (list->rules + list->head);
244
245 unsigned int head = list->tail;
246
247 /*
248 * Align next rule properly.
249 *Note that "dmacs_and_vlans" will also be aligned.
250 */
251 unsigned int pad = 0;
252 while (((head + pad) % __alignof__(gxio_mpipe_rules_rule_t)) != 0)
253 pad++;
254
255 /*
256 * Verify room.
257 * ISSUE: Mark rules as broken on error?
258 */
259 if (head + pad + sizeof(*rule) >= sizeof(list->rules))
260 return GXIO_MPIPE_ERR_RULES_FULL;
261
262 /* Verify num_buckets is a power of 2. */
263 if (__builtin_popcount(num_buckets) != 1)
264 return GXIO_MPIPE_ERR_RULES_INVALID;
265
266 /* Add padding to previous rule. */
267 rule->size += pad;
268
269 /* Start a new rule. */
270 list->head = head + pad;
271
272 rule = (gxio_mpipe_rules_rule_t *) (list->rules + list->head);
273
274 /* Default some values. */
275 rule->headroom = 2;
276 rule->tailroom = 0;
277 rule->capacity = 16384;
278
279 /* Save the bucket info. */
280 rule->bucket_mask = num_buckets - 1;
281 rule->bucket_first = bucket;
282
283 for (i = 8 - 1; i >= 0; i--) {
284 int maybe =
285 stacks ? stacks->stacks[i] : rules->context->__stacks.
286 stacks[i];
287 if (maybe != 255)
288 stack = maybe;
289 rule->stacks.stacks[i] = stack;
290 }
291
292 if (stack == 255)
293 return GXIO_MPIPE_ERR_RULES_INVALID;
294
295 /* NOTE: Only entries at the end of the array can be 255. */
296 for (i = 8 - 1; i > 0; i--) {
297 if (rule->stacks.stacks[i] == 255) {
298 rule->stacks.stacks[i] = stack;
299 rule->capacity =
300 gxio_mpipe_buffer_size_enum_to_buffer_size(i -
301 1);
302 }
303 }
304
305 rule->size = sizeof(*rule);
306 list->tail = list->head + rule->size;
307
308 return 0;
309}
310
311EXPORT_SYMBOL_GPL(gxio_mpipe_rules_begin);
312
313int gxio_mpipe_rules_add_channel(gxio_mpipe_rules_t *rules,
314 unsigned int channel)
315{
316 gxio_mpipe_rules_list_t *list = &rules->list;
317
318 gxio_mpipe_rules_rule_t *rule =
319 (gxio_mpipe_rules_rule_t *) (list->rules + list->head);
320
321 /* Verify channel. */
322 if (channel >= 32)
323 return GXIO_MPIPE_ERR_RULES_INVALID;
324
325 /* Verify begun. */
326 if (list->tail == 0)
327 return GXIO_MPIPE_ERR_RULES_EMPTY;
328
329 rule->channel_bits |= (1UL << channel);
330
331 return 0;
332}
333
334EXPORT_SYMBOL_GPL(gxio_mpipe_rules_add_channel);
335
336int gxio_mpipe_rules_set_headroom(gxio_mpipe_rules_t *rules, uint8_t headroom)
337{
338 gxio_mpipe_rules_list_t *list = &rules->list;
339
340 gxio_mpipe_rules_rule_t *rule =
341 (gxio_mpipe_rules_rule_t *) (list->rules + list->head);
342
343 /* Verify begun. */
344 if (list->tail == 0)
345 return GXIO_MPIPE_ERR_RULES_EMPTY;
346
347 rule->headroom = headroom;
348
349 return 0;
350}
351
352EXPORT_SYMBOL_GPL(gxio_mpipe_rules_set_headroom);
353
354int gxio_mpipe_rules_commit(gxio_mpipe_rules_t *rules)
355{
356 gxio_mpipe_rules_list_t *list = &rules->list;
357 unsigned int size =
358 offsetof(gxio_mpipe_rules_list_t, rules) + list->tail;
359 return gxio_mpipe_commit_rules(rules->context, list, size);
360}
361
362EXPORT_SYMBOL_GPL(gxio_mpipe_rules_commit);
363
364int gxio_mpipe_iqueue_init(gxio_mpipe_iqueue_t *iqueue,
365 gxio_mpipe_context_t *context,
366 unsigned int ring,
367 void *mem, size_t mem_size, unsigned int mem_flags)
368{
369 /* The init call below will verify that "mem_size" is legal. */
370 unsigned int num_entries = mem_size / sizeof(gxio_mpipe_idesc_t);
371
372 iqueue->context = context;
373 iqueue->idescs = (gxio_mpipe_idesc_t *)mem;
374 iqueue->ring = ring;
375 iqueue->num_entries = num_entries;
376 iqueue->mask_num_entries = num_entries - 1;
377 iqueue->log2_num_entries = __builtin_ctz(num_entries);
378 iqueue->head = 1;
379#ifdef __BIG_ENDIAN__
380 iqueue->swapped = 0;
381#endif
382
383 /* Initialize the "tail". */
384 __gxio_mmio_write(mem, iqueue->head);
385
386 return gxio_mpipe_init_notif_ring(context, ring, mem, mem_size,
387 mem_flags);
388}
389
390EXPORT_SYMBOL_GPL(gxio_mpipe_iqueue_init);
391
392int gxio_mpipe_equeue_init(gxio_mpipe_equeue_t *equeue,
393 gxio_mpipe_context_t *context,
394 unsigned int ering,
395 unsigned int channel,
396 void *mem, unsigned int mem_size,
397 unsigned int mem_flags)
398{
399 /* The init call below will verify that "mem_size" is legal. */
400 unsigned int num_entries = mem_size / sizeof(gxio_mpipe_edesc_t);
401
402 /* Offset used to read number of completed commands. */
403 MPIPE_EDMA_POST_REGION_ADDR_t offset;
404
405 int result = gxio_mpipe_init_edma_ring(context, ering, channel,
406 mem, mem_size, mem_flags);
407 if (result < 0)
408 return result;
409
410 memset(equeue, 0, sizeof(*equeue));
411
412 offset.word = 0;
413 offset.region =
414 MPIPE_MMIO_ADDR__REGION_VAL_EDMA -
415 MPIPE_MMIO_ADDR__REGION_VAL_IDMA;
416 offset.ring = ering;
417
418 __gxio_dma_queue_init(&equeue->dma_queue,
419 context->mmio_fast_base + offset.word,
420 num_entries);
421 equeue->edescs = mem;
422 equeue->mask_num_entries = num_entries - 1;
423 equeue->log2_num_entries = __builtin_ctz(num_entries);
424 equeue->context = context;
425 equeue->ering = ering;
426 equeue->channel = channel;
427
428 return 0;
429}
430
431EXPORT_SYMBOL_GPL(gxio_mpipe_equeue_init);
432
433int gxio_mpipe_set_timestamp(gxio_mpipe_context_t *context,
434 const struct timespec64 *ts)
435{
436 cycles_t cycles = get_cycles();
437 return gxio_mpipe_set_timestamp_aux(context, (uint64_t)ts->tv_sec,
438 (uint64_t)ts->tv_nsec,
439 (uint64_t)cycles);
440}
441EXPORT_SYMBOL_GPL(gxio_mpipe_set_timestamp);
442
443int gxio_mpipe_get_timestamp(gxio_mpipe_context_t *context,
444 struct timespec64 *ts)
445{
446 int ret;
447 cycles_t cycles_prev, cycles_now, clock_rate;
448 cycles_prev = get_cycles();
449 ret = gxio_mpipe_get_timestamp_aux(context, (uint64_t *)&ts->tv_sec,
450 (uint64_t *)&ts->tv_nsec,
451 (uint64_t *)&cycles_now);
452 if (ret < 0) {
453 return ret;
454 }
455
456 clock_rate = get_clock_rate();
457 ts->tv_nsec -= (cycles_now - cycles_prev) * 1000000000LL / clock_rate;
458 if (ts->tv_nsec < 0) {
459 ts->tv_nsec += 1000000000LL;
460 ts->tv_sec -= 1;
461 }
462 return ret;
463}
464EXPORT_SYMBOL_GPL(gxio_mpipe_get_timestamp);
465
466int gxio_mpipe_adjust_timestamp(gxio_mpipe_context_t *context, int64_t delta)
467{
468 return gxio_mpipe_adjust_timestamp_aux(context, delta);
469}
470EXPORT_SYMBOL_GPL(gxio_mpipe_adjust_timestamp);
471
472/* Get our internal context used for link name access. This context is
473 * special in that it is not associated with an mPIPE service domain.
474 */
475static gxio_mpipe_context_t *_gxio_get_link_context(void)
476{
477 static gxio_mpipe_context_t context;
478 static gxio_mpipe_context_t *contextp;
479 static int tried_open = 0;
480 static DEFINE_MUTEX(mutex);
481
482 mutex_lock(&mutex);
483
484 if (!tried_open) {
485 int i = 0;
486 tried_open = 1;
487
488 /*
489 * "4" here is the maximum possible number of mPIPE shims; it's
490 * an exaggeration but we shouldn't ever go beyond 2 anyway.
491 */
492 for (i = 0; i < 4; i++) {
493 char file[80];
494
495 snprintf(file, sizeof(file), "mpipe/%d/iorpc_info", i);
496 context.fd = hv_dev_open((HV_VirtAddr) file, 0);
497 if (context.fd < 0)
498 continue;
499
500 contextp = &context;
501 break;
502 }
503 }
504
505 mutex_unlock(&mutex);
506
507 return contextp;
508}
509
510int gxio_mpipe_link_instance(const char *link_name)
511{
512 _gxio_mpipe_link_name_t name;
513 gxio_mpipe_context_t *context = _gxio_get_link_context();
514
515 if (!context)
516 return GXIO_ERR_NO_DEVICE;
517
518 if (strscpy(name.name, link_name, sizeof(name.name)) < 0)
519 return GXIO_ERR_NO_DEVICE;
520
521 return gxio_mpipe_info_instance_aux(context, name);
522}
523EXPORT_SYMBOL_GPL(gxio_mpipe_link_instance);
524
525int gxio_mpipe_link_enumerate_mac(int idx, char *link_name, uint8_t *link_mac)
526{
527 int rv;
528 _gxio_mpipe_link_name_t name;
529 _gxio_mpipe_link_mac_t mac;
530
531 gxio_mpipe_context_t *context = _gxio_get_link_context();
532 if (!context)
533 return GXIO_ERR_NO_DEVICE;
534
535 rv = gxio_mpipe_info_enumerate_aux(context, idx, &name, &mac);
536 if (rv >= 0) {
537 if (strscpy(link_name, name.name, sizeof(name.name)) < 0)
538 return GXIO_ERR_INVAL_MEMORY_SIZE;
539 memcpy(link_mac, mac.mac, sizeof(mac.mac));
540 }
541
542 return rv;
543}
544
545EXPORT_SYMBOL_GPL(gxio_mpipe_link_enumerate_mac);
546
547int gxio_mpipe_link_open(gxio_mpipe_link_t *link,
548 gxio_mpipe_context_t *context, const char *link_name,
549 unsigned int flags)
550{
551 _gxio_mpipe_link_name_t name;
552 int rv;
553
554 if (strscpy(name.name, link_name, sizeof(name.name)) < 0)
555 return GXIO_ERR_NO_DEVICE;
556
557 rv = gxio_mpipe_link_open_aux(context, name, flags);
558 if (rv < 0)
559 return rv;
560
561 link->context = context;
562 link->channel = rv >> 8;
563 link->mac = rv & 0xFF;
564
565 return 0;
566}
567
568EXPORT_SYMBOL_GPL(gxio_mpipe_link_open);
569
570int gxio_mpipe_link_close(gxio_mpipe_link_t *link)
571{
572 return gxio_mpipe_link_close_aux(link->context, link->mac);
573}
574
575EXPORT_SYMBOL_GPL(gxio_mpipe_link_close);
576
577int gxio_mpipe_link_set_attr(gxio_mpipe_link_t *link, uint32_t attr,
578 int64_t val)
579{
580 return gxio_mpipe_link_set_attr_aux(link->context, link->mac, attr,
581 val);
582}
583
584EXPORT_SYMBOL_GPL(gxio_mpipe_link_set_attr);
diff --git a/arch/tile/gxio/trio.c b/arch/tile/gxio/trio.c
deleted file mode 100644
index 69f0b8df3ce3..000000000000
--- a/arch/tile/gxio/trio.c
+++ /dev/null
@@ -1,49 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/*
16 * Implementation of trio gxio calls.
17 */
18
19#include <linux/errno.h>
20#include <linux/io.h>
21#include <linux/module.h>
22
23#include <gxio/trio.h>
24#include <gxio/iorpc_globals.h>
25#include <gxio/iorpc_trio.h>
26#include <gxio/kiorpc.h>
27
28int gxio_trio_init(gxio_trio_context_t *context, unsigned int trio_index)
29{
30 char file[32];
31 int fd;
32
33 snprintf(file, sizeof(file), "trio/%d/iorpc", trio_index);
34 fd = hv_dev_open((HV_VirtAddr) file, 0);
35 if (fd < 0) {
36 context->fd = -1;
37
38 if (fd >= GXIO_ERR_MIN && fd <= GXIO_ERR_MAX)
39 return fd;
40 else
41 return -ENODEV;
42 }
43
44 context->fd = fd;
45
46 return 0;
47}
48
49EXPORT_SYMBOL_GPL(gxio_trio_init);
diff --git a/arch/tile/gxio/uart.c b/arch/tile/gxio/uart.c
deleted file mode 100644
index ba585175ef88..000000000000
--- a/arch/tile/gxio/uart.c
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/*
16 * Implementation of UART gxio calls.
17 */
18
19#include <linux/io.h>
20#include <linux/errno.h>
21#include <linux/module.h>
22
23#include <gxio/uart.h>
24#include <gxio/iorpc_globals.h>
25#include <gxio/iorpc_uart.h>
26#include <gxio/kiorpc.h>
27
28int gxio_uart_init(gxio_uart_context_t *context, int uart_index)
29{
30 char file[32];
31 int fd;
32
33 snprintf(file, sizeof(file), "uart/%d/iorpc", uart_index);
34 fd = hv_dev_open((HV_VirtAddr) file, 0);
35 if (fd < 0) {
36 if (fd >= GXIO_ERR_MIN && fd <= GXIO_ERR_MAX)
37 return fd;
38 else
39 return -ENODEV;
40 }
41
42 context->fd = fd;
43
44 /* Map in the MMIO space. */
45 context->mmio_base = (void __force *)
46 iorpc_ioremap(fd, HV_UART_MMIO_OFFSET, HV_UART_MMIO_SIZE);
47
48 if (context->mmio_base == NULL) {
49 hv_dev_close(context->fd);
50 context->fd = -1;
51 return -ENODEV;
52 }
53
54 return 0;
55}
56
57EXPORT_SYMBOL_GPL(gxio_uart_init);
58
59int gxio_uart_destroy(gxio_uart_context_t *context)
60{
61 iounmap((void __force __iomem *)(context->mmio_base));
62 hv_dev_close(context->fd);
63
64 context->mmio_base = NULL;
65 context->fd = -1;
66
67 return 0;
68}
69
70EXPORT_SYMBOL_GPL(gxio_uart_destroy);
71
72/* UART register write wrapper. */
73void gxio_uart_write(gxio_uart_context_t *context, uint64_t offset,
74 uint64_t word)
75{
76 __gxio_mmio_write(context->mmio_base + offset, word);
77}
78
79EXPORT_SYMBOL_GPL(gxio_uart_write);
80
81/* UART register read wrapper. */
82uint64_t gxio_uart_read(gxio_uart_context_t *context, uint64_t offset)
83{
84 return __gxio_mmio_read(context->mmio_base + offset);
85}
86
87EXPORT_SYMBOL_GPL(gxio_uart_read);
diff --git a/arch/tile/gxio/usb_host.c b/arch/tile/gxio/usb_host.c
deleted file mode 100644
index 785afad7922e..000000000000
--- a/arch/tile/gxio/usb_host.c
+++ /dev/null
@@ -1,91 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/*
16 *
17 * Implementation of USB gxio calls.
18 */
19
20#include <linux/io.h>
21#include <linux/errno.h>
22#include <linux/module.h>
23
24#include <gxio/iorpc_globals.h>
25#include <gxio/iorpc_usb_host.h>
26#include <gxio/kiorpc.h>
27#include <gxio/usb_host.h>
28
29int gxio_usb_host_init(gxio_usb_host_context_t *context, int usb_index,
30 int is_ehci)
31{
32 char file[32];
33 int fd;
34
35 if (is_ehci)
36 snprintf(file, sizeof(file), "usb_host/%d/iorpc/ehci",
37 usb_index);
38 else
39 snprintf(file, sizeof(file), "usb_host/%d/iorpc/ohci",
40 usb_index);
41
42 fd = hv_dev_open((HV_VirtAddr) file, 0);
43 if (fd < 0) {
44 if (fd >= GXIO_ERR_MIN && fd <= GXIO_ERR_MAX)
45 return fd;
46 else
47 return -ENODEV;
48 }
49
50 context->fd = fd;
51
52 // Map in the MMIO space.
53 context->mmio_base =
54 (void __force *)iorpc_ioremap(fd, 0, HV_USB_HOST_MMIO_SIZE);
55
56 if (context->mmio_base == NULL) {
57 hv_dev_close(context->fd);
58 return -ENODEV;
59 }
60
61 return 0;
62}
63
64EXPORT_SYMBOL_GPL(gxio_usb_host_init);
65
66int gxio_usb_host_destroy(gxio_usb_host_context_t *context)
67{
68 iounmap((void __force __iomem *)(context->mmio_base));
69 hv_dev_close(context->fd);
70
71 context->mmio_base = NULL;
72 context->fd = -1;
73
74 return 0;
75}
76
77EXPORT_SYMBOL_GPL(gxio_usb_host_destroy);
78
79void *gxio_usb_host_get_reg_start(gxio_usb_host_context_t *context)
80{
81 return context->mmio_base;
82}
83
84EXPORT_SYMBOL_GPL(gxio_usb_host_get_reg_start);
85
86size_t gxio_usb_host_get_reg_len(gxio_usb_host_context_t *context)
87{
88 return HV_USB_HOST_MMIO_SIZE;
89}
90
91EXPORT_SYMBOL_GPL(gxio_usb_host_get_reg_len);
diff --git a/arch/tile/include/arch/mpipe.h b/arch/tile/include/arch/mpipe.h
deleted file mode 100644
index 904538e754d8..000000000000
--- a/arch/tile/include/arch/mpipe.h
+++ /dev/null
@@ -1,371 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_MPIPE_H__
18#define __ARCH_MPIPE_H__
19
20#include <arch/abi.h>
21#include <arch/mpipe_def.h>
22
23#ifndef __ASSEMBLER__
24
25/*
26 * MMIO Ingress DMA Release Region Address.
27 * This is a description of the physical addresses used to manipulate ingress
28 * credit counters. Accesses to this address space should use an address of
29 * this form and a value like that specified in IDMA_RELEASE_REGION_VAL.
30 */
31
32__extension__
33typedef union
34{
35 struct
36 {
37#ifndef __BIG_ENDIAN__
38 /* Reserved. */
39 uint_reg_t __reserved_0 : 3;
40 /* NotifRing to be released */
41 uint_reg_t ring : 8;
42 /* Bucket to be released */
43 uint_reg_t bucket : 13;
44 /* Enable NotifRing release */
45 uint_reg_t ring_enable : 1;
46 /* Enable Bucket release */
47 uint_reg_t bucket_enable : 1;
48 /*
49 * This field of the address selects the region (address space) to be
50 * accessed. For the iDMA release region, this field must be 4.
51 */
52 uint_reg_t region : 3;
53 /* Reserved. */
54 uint_reg_t __reserved_1 : 6;
55 /* This field of the address indexes the 32 entry service domain table. */
56 uint_reg_t svc_dom : 5;
57 /* Reserved. */
58 uint_reg_t __reserved_2 : 24;
59#else /* __BIG_ENDIAN__ */
60 uint_reg_t __reserved_2 : 24;
61 uint_reg_t svc_dom : 5;
62 uint_reg_t __reserved_1 : 6;
63 uint_reg_t region : 3;
64 uint_reg_t bucket_enable : 1;
65 uint_reg_t ring_enable : 1;
66 uint_reg_t bucket : 13;
67 uint_reg_t ring : 8;
68 uint_reg_t __reserved_0 : 3;
69#endif
70 };
71
72 uint_reg_t word;
73} MPIPE_IDMA_RELEASE_REGION_ADDR_t;
74
75/*
76 * MMIO Ingress DMA Release Region Value - Release NotifRing and/or Bucket.
77 * Provides release of the associated NotifRing. The address of the MMIO
78 * operation is described in IDMA_RELEASE_REGION_ADDR.
79 */
80
81__extension__
82typedef union
83{
84 struct
85 {
86#ifndef __BIG_ENDIAN__
87 /*
88 * Number of packets being released. The load balancer's count of
89 * inflight packets will be decremented by this amount for the associated
90 * Bucket and/or NotifRing
91 */
92 uint_reg_t count : 16;
93 /* Reserved. */
94 uint_reg_t __reserved : 48;
95#else /* __BIG_ENDIAN__ */
96 uint_reg_t __reserved : 48;
97 uint_reg_t count : 16;
98#endif
99 };
100
101 uint_reg_t word;
102} MPIPE_IDMA_RELEASE_REGION_VAL_t;
103
104/*
105 * MMIO Buffer Stack Manager Region Address.
106 * This MMIO region is used for posting or fetching buffers to/from the
107 * buffer stack manager. On an MMIO load, this pops a buffer descriptor from
108 * the top of stack if one is available. On an MMIO store, this pushes a
109 * buffer to the stack. The value read or written is described in
110 * BSM_REGION_VAL.
111 */
112
113__extension__
114typedef union
115{
116 struct
117 {
118#ifndef __BIG_ENDIAN__
119 /* Reserved. */
120 uint_reg_t __reserved_0 : 3;
121 /* BufferStack being accessed. */
122 uint_reg_t stack : 5;
123 /* Reserved. */
124 uint_reg_t __reserved_1 : 18;
125 /*
126 * This field of the address selects the region (address space) to be
127 * accessed. For the buffer stack manager region, this field must be 6.
128 */
129 uint_reg_t region : 3;
130 /* Reserved. */
131 uint_reg_t __reserved_2 : 6;
132 /* This field of the address indexes the 32 entry service domain table. */
133 uint_reg_t svc_dom : 5;
134 /* Reserved. */
135 uint_reg_t __reserved_3 : 24;
136#else /* __BIG_ENDIAN__ */
137 uint_reg_t __reserved_3 : 24;
138 uint_reg_t svc_dom : 5;
139 uint_reg_t __reserved_2 : 6;
140 uint_reg_t region : 3;
141 uint_reg_t __reserved_1 : 18;
142 uint_reg_t stack : 5;
143 uint_reg_t __reserved_0 : 3;
144#endif
145 };
146
147 uint_reg_t word;
148} MPIPE_BSM_REGION_ADDR_t;
149
150/*
151 * MMIO Buffer Stack Manager Region Value.
152 * This MMIO region is used for posting or fetching buffers to/from the
153 * buffer stack manager. On an MMIO load, this pops a buffer descriptor from
154 * the top of stack if one is available. On an MMIO store, this pushes a
155 * buffer to the stack. The address of the MMIO operation is described in
156 * BSM_REGION_ADDR.
157 */
158
159__extension__
160typedef union
161{
162 struct
163 {
164#ifndef __BIG_ENDIAN__
165 /* Reserved. */
166 uint_reg_t __reserved_0 : 7;
167 /*
168 * Base virtual address of the buffer. Must be sign extended by consumer.
169 */
170 int_reg_t va : 35;
171 /* Reserved. */
172 uint_reg_t __reserved_1 : 6;
173 /*
174 * Index of the buffer stack to which this buffer belongs. Ignored on
175 * writes since the offset bits specify the stack being accessed.
176 */
177 uint_reg_t stack_idx : 5;
178 /* Reserved. */
179 uint_reg_t __reserved_2 : 3;
180 /*
181 * Instance ID. For devices that support automatic buffer return between
182 * mPIPE instances, this field indicates the buffer owner. If the INST
183 * field does not match the mPIPE's instance number when a packet is
184 * egressed, buffers with HWB set will be returned to the other mPIPE
185 * instance. Note that not all devices support multi-mPIPE buffer
186 * return. The MPIPE_EDMA_INFO.REMOTE_BUFF_RTN_SUPPORT bit indicates
187 * whether the INST field in the buffer descriptor is populated by iDMA
188 * hardware. This field is ignored on writes.
189 */
190 uint_reg_t inst : 2;
191 /*
192 * Reads as one to indicate that this is a hardware managed buffer.
193 * Ignored on writes since all buffers on a given stack are the same size.
194 */
195 uint_reg_t hwb : 1;
196 /*
197 * Encoded size of buffer (ignored on writes):
198 * 0 = 128 bytes
199 * 1 = 256 bytes
200 * 2 = 512 bytes
201 * 3 = 1024 bytes
202 * 4 = 1664 bytes
203 * 5 = 4096 bytes
204 * 6 = 10368 bytes
205 * 7 = 16384 bytes
206 */
207 uint_reg_t size : 3;
208 /*
209 * Valid indication for the buffer. Ignored on writes.
210 * 0 : Valid buffer descriptor popped from stack.
211 * 3 : Could not pop a buffer from the stack. Either the stack is empty,
212 * or the hardware's prefetch buffer is empty for this stack.
213 */
214 uint_reg_t c : 2;
215#else /* __BIG_ENDIAN__ */
216 uint_reg_t c : 2;
217 uint_reg_t size : 3;
218 uint_reg_t hwb : 1;
219 uint_reg_t inst : 2;
220 uint_reg_t __reserved_2 : 3;
221 uint_reg_t stack_idx : 5;
222 uint_reg_t __reserved_1 : 6;
223 int_reg_t va : 35;
224 uint_reg_t __reserved_0 : 7;
225#endif
226 };
227
228 uint_reg_t word;
229} MPIPE_BSM_REGION_VAL_t;
230
231/*
232 * MMIO Egress DMA Post Region Address.
233 * Used to post descriptor locations to the eDMA descriptor engine. The
234 * value to be written is described in EDMA_POST_REGION_VAL
235 */
236
237__extension__
238typedef union
239{
240 struct
241 {
242#ifndef __BIG_ENDIAN__
243 /* Reserved. */
244 uint_reg_t __reserved_0 : 3;
245 /* eDMA ring being accessed */
246 uint_reg_t ring : 6;
247 /* Reserved. */
248 uint_reg_t __reserved_1 : 17;
249 /*
250 * This field of the address selects the region (address space) to be
251 * accessed. For the egress DMA post region, this field must be 5.
252 */
253 uint_reg_t region : 3;
254 /* Reserved. */
255 uint_reg_t __reserved_2 : 6;
256 /* This field of the address indexes the 32 entry service domain table. */
257 uint_reg_t svc_dom : 5;
258 /* Reserved. */
259 uint_reg_t __reserved_3 : 24;
260#else /* __BIG_ENDIAN__ */
261 uint_reg_t __reserved_3 : 24;
262 uint_reg_t svc_dom : 5;
263 uint_reg_t __reserved_2 : 6;
264 uint_reg_t region : 3;
265 uint_reg_t __reserved_1 : 17;
266 uint_reg_t ring : 6;
267 uint_reg_t __reserved_0 : 3;
268#endif
269 };
270
271 uint_reg_t word;
272} MPIPE_EDMA_POST_REGION_ADDR_t;
273
274/*
275 * MMIO Egress DMA Post Region Value.
276 * Used to post descriptor locations to the eDMA descriptor engine. The
277 * address is described in EDMA_POST_REGION_ADDR.
278 */
279
280__extension__
281typedef union
282{
283 struct
284 {
285#ifndef __BIG_ENDIAN__
286 /*
287 * For writes, this specifies the current ring tail pointer prior to any
288 * post. For example, to post 1 or more descriptors starting at location
289 * 23, this would contain 23 (not 24). On writes, this index must be
290 * masked based on the ring size. The new tail pointer after this post
291 * is COUNT+RING_IDX (masked by the ring size).
292 *
293 * For reads, this provides the hardware descriptor fetcher's head
294 * pointer. The descriptors prior to the head pointer, however, may not
295 * yet have been processed so this indicator is only used to determine
296 * how full the ring is and if software may post more descriptors.
297 */
298 uint_reg_t ring_idx : 16;
299 /*
300 * For writes, this specifies number of contiguous descriptors that are
301 * being posted. Software may post up to RingSize descriptors with a
302 * single MMIO store. A zero in this field on a write will "wake up" an
303 * eDMA ring and cause it fetch descriptors regardless of the hardware's
304 * current view of the state of the tail pointer.
305 *
306 * For reads, this field provides a rolling count of the number of
307 * descriptors that have been completely processed. This may be used by
308 * software to determine when buffers associated with a descriptor may be
309 * returned or reused. When the ring's flush bit is cleared by software
310 * (after having been set by HW or SW), the COUNT will be cleared.
311 */
312 uint_reg_t count : 16;
313 /*
314 * For writes, this specifies the generation number of the tail being
315 * posted. Note that if tail+cnt wraps to the beginning of the ring, the
316 * eDMA hardware assumes that the descriptors posted at the beginning of
317 * the ring are also valid so it is okay to post around the wrap point.
318 *
319 * For reads, this is the current generation number. Valid descriptors
320 * will have the inverse of this generation number.
321 */
322 uint_reg_t gen : 1;
323 /* Reserved. */
324 uint_reg_t __reserved : 31;
325#else /* __BIG_ENDIAN__ */
326 uint_reg_t __reserved : 31;
327 uint_reg_t gen : 1;
328 uint_reg_t count : 16;
329 uint_reg_t ring_idx : 16;
330#endif
331 };
332
333 uint_reg_t word;
334} MPIPE_EDMA_POST_REGION_VAL_t;
335
336/*
337 * Load Balancer Bucket Status Data.
338 * Read/Write data for load balancer Bucket-Status Table. 4160 entries
339 * indexed by LBL_INIT_CTL.IDX when LBL_INIT_CTL.STRUCT_SEL is BSTS_TBL
340 */
341
342__extension__
343typedef union
344{
345 struct
346 {
347#ifndef __BIG_ENDIAN__
348 /* NotifRing currently assigned to this bucket. */
349 uint_reg_t notifring : 8;
350 /* Current reference count. */
351 uint_reg_t count : 16;
352 /* Group associated with this bucket. */
353 uint_reg_t group : 5;
354 /* Mode select for this bucket. */
355 uint_reg_t mode : 3;
356 /* Reserved. */
357 uint_reg_t __reserved : 32;
358#else /* __BIG_ENDIAN__ */
359 uint_reg_t __reserved : 32;
360 uint_reg_t mode : 3;
361 uint_reg_t group : 5;
362 uint_reg_t count : 16;
363 uint_reg_t notifring : 8;
364#endif
365 };
366
367 uint_reg_t word;
368} MPIPE_LBL_INIT_DAT_BSTS_TBL_t;
369#endif /* !defined(__ASSEMBLER__) */
370
371#endif /* !defined(__ARCH_MPIPE_H__) */
diff --git a/arch/tile/include/arch/mpipe_constants.h b/arch/tile/include/arch/mpipe_constants.h
deleted file mode 100644
index 84022ac5fe82..000000000000
--- a/arch/tile/include/arch/mpipe_constants.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15
16#ifndef __ARCH_MPIPE_CONSTANTS_H__
17#define __ARCH_MPIPE_CONSTANTS_H__
18
19#define MPIPE_NUM_CLASSIFIERS 16
20#define MPIPE_CLS_MHZ 1200
21
22#define MPIPE_NUM_EDMA_RINGS 64
23
24#define MPIPE_NUM_SGMII_MACS 16
25#define MPIPE_NUM_XAUI_MACS 16
26#define MPIPE_NUM_LOOPBACK_CHANNELS 4
27#define MPIPE_NUM_NON_LB_CHANNELS 28
28
29#define MPIPE_NUM_IPKT_BLOCKS 1536
30
31#define MPIPE_NUM_BUCKETS 4160
32
33#define MPIPE_NUM_NOTIF_RINGS 256
34
35#define MPIPE_NUM_NOTIF_GROUPS 32
36
37#define MPIPE_NUM_TLBS_PER_ASID 16
38#define MPIPE_TLB_IDX_WIDTH 4
39
40#define MPIPE_MMIO_NUM_SVC_DOM 32
41
42#endif /* __ARCH_MPIPE_CONSTANTS_H__ */
diff --git a/arch/tile/include/arch/mpipe_def.h b/arch/tile/include/arch/mpipe_def.h
deleted file mode 100644
index c3d30217fc66..000000000000
--- a/arch/tile/include/arch/mpipe_def.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_MPIPE_DEF_H__
18#define __ARCH_MPIPE_DEF_H__
19#define MPIPE_MMIO_ADDR__REGION_SHIFT 26
20#define MPIPE_MMIO_ADDR__REGION_VAL_CFG 0x0
21#define MPIPE_MMIO_ADDR__REGION_VAL_IDMA 0x4
22#define MPIPE_MMIO_ADDR__REGION_VAL_EDMA 0x5
23#define MPIPE_MMIO_ADDR__REGION_VAL_BSM 0x6
24#define MPIPE_BSM_REGION_VAL__VA_SHIFT 7
25#define MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_128 0x0
26#define MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_256 0x1
27#define MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_512 0x2
28#define MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_1024 0x3
29#define MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_1664 0x4
30#define MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_4096 0x5
31#define MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_10368 0x6
32#define MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_16384 0x7
33#define MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_DFA 0x0
34#define MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_FIXED 0x1
35#define MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_ALWAYS_PICK 0x2
36#define MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_STICKY 0x3
37#define MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_STICKY_RAND 0x7
38#define MPIPE_LBL_NR_STATE__FIRST_WORD 0x2138
39#endif /* !defined(__ARCH_MPIPE_DEF_H__) */
diff --git a/arch/tile/include/arch/mpipe_shm.h b/arch/tile/include/arch/mpipe_shm.h
deleted file mode 100644
index 13b3c4300e50..000000000000
--- a/arch/tile/include/arch/mpipe_shm.h
+++ /dev/null
@@ -1,521 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17
18#ifndef __ARCH_MPIPE_SHM_H__
19#define __ARCH_MPIPE_SHM_H__
20
21#include <arch/abi.h>
22#include <arch/mpipe_shm_def.h>
23
24#ifndef __ASSEMBLER__
25/**
26 * MPIPE eDMA Descriptor.
27 * The eDMA descriptor is written by software and consumed by hardware. It
28 * is used to specify the location of egress packet data to be sent out of
29 * the chip via one of the packet interfaces.
30 */
31
32__extension__
33typedef union
34{
35 struct
36 {
37 /* Word 0 */
38
39#ifndef __BIG_ENDIAN__
40 /**
41 * Generation number. Used to indicate a valid descriptor in ring. When
42 * a new descriptor is written into the ring, software must toggle this
43 * bit. The net effect is that the GEN bit being written into new
44 * descriptors toggles each time the ring tail pointer wraps.
45 */
46 uint_reg_t gen : 1;
47 /**
48 * For devices with EDMA reorder support, this field allows the
49 * descriptor to select the egress FIFO. The associated DMA ring must
50 * have ALLOW_EFIFO_SEL enabled.
51 */
52 uint_reg_t efifo_sel : 6;
53 /** Reserved. Must be zero. */
54 uint_reg_t r0 : 1;
55 /** Checksum generation enabled for this transfer. */
56 uint_reg_t csum : 1;
57 /**
58 * Nothing to be sent. Used, for example, when software has dropped a
59 * packet but still wishes to return all of the associated buffers.
60 */
61 uint_reg_t ns : 1;
62 /**
63 * Notification interrupt will be delivered when packet has been egressed.
64 */
65 uint_reg_t notif : 1;
66 /**
67 * Boundary indicator. When 1, this transfer includes the EOP for this
68 * command. Must be clear on all but the last descriptor for an egress
69 * packet.
70 */
71 uint_reg_t bound : 1;
72 /** Reserved. Must be zero. */
73 uint_reg_t r1 : 4;
74 /**
75 * Number of bytes to be sent for this descriptor. When zero, no data
76 * will be moved and the buffer descriptor will be ignored. If the
77 * buffer descriptor indicates that it is chained, the low 7 bits of the
78 * VA indicate the offset within the first buffer (e.g. 127 bytes is the
79 * maximum offset into the first buffer). If the size exceeds a single
80 * buffer, subsequent buffer descriptors will be fetched prior to
81 * processing the next eDMA descriptor in the ring.
82 */
83 uint_reg_t xfer_size : 14;
84 /** Reserved. Must be zero. */
85 uint_reg_t r2 : 2;
86 /**
87 * Destination of checksum relative to CSUM_START relative to the first
88 * byte moved by this descriptor. Must be zero if CSUM=0 in this
89 * descriptor. Must be less than XFER_SIZE (e.g. the first byte of the
90 * CSUM_DEST must be within the span of this descriptor).
91 */
92 uint_reg_t csum_dest : 8;
93 /**
94 * Start byte of checksum relative to the first byte moved by this
95 * descriptor. If this is not the first descriptor for the egress
96 * packet, CSUM_START is still relative to the first byte in this
97 * descriptor. Must be zero if CSUM=0 in this descriptor.
98 */
99 uint_reg_t csum_start : 8;
100 /**
101 * Initial value for 16-bit 1's compliment checksum if enabled via CSUM.
102 * Specified in network order. That is, bits[7:0] will be added to the
103 * byte pointed to by CSUM_START and bits[15:8] will be added to the byte
104 * pointed to by CSUM_START+1 (with appropriate 1's compliment carries).
105 * Must be zero if CSUM=0 in this descriptor.
106 */
107 uint_reg_t csum_seed : 16;
108#else /* __BIG_ENDIAN__ */
109 uint_reg_t csum_seed : 16;
110 uint_reg_t csum_start : 8;
111 uint_reg_t csum_dest : 8;
112 uint_reg_t r2 : 2;
113 uint_reg_t xfer_size : 14;
114 uint_reg_t r1 : 4;
115 uint_reg_t bound : 1;
116 uint_reg_t notif : 1;
117 uint_reg_t ns : 1;
118 uint_reg_t csum : 1;
119 uint_reg_t r0 : 1;
120 uint_reg_t efifo_sel : 6;
121 uint_reg_t gen : 1;
122#endif
123
124 /* Word 1 */
125
126#ifndef __BIG_ENDIAN__
127 /** Virtual address. Must be sign extended by consumer. */
128 int_reg_t va : 42;
129 /** Reserved. */
130 uint_reg_t __reserved_0 : 6;
131 /** Index of the buffer stack to which this buffer belongs. */
132 uint_reg_t stack_idx : 5;
133 /** Reserved. */
134 uint_reg_t __reserved_1 : 3;
135 /**
136 * Instance ID. For devices that support automatic buffer return between
137 * mPIPE instances, this field indicates the buffer owner. If the INST
138 * field does not match the mPIPE's instance number when a packet is
139 * egressed, buffers with HWB set will be returned to the other mPIPE
140 * instance. Note that not all devices support multi-mPIPE buffer
141 * return. The MPIPE_EDMA_INFO.REMOTE_BUFF_RTN_SUPPORT bit indicates
142 * whether the INST field in the buffer descriptor is populated by iDMA
143 * hardware.
144 */
145 uint_reg_t inst : 2;
146 /**
147 * Always set to one by hardware in iDMA packet descriptors. For eDMA,
148 * indicates whether the buffer will be released to the buffer stack
149 * manager. When 0, software is responsible for releasing the buffer.
150 */
151 uint_reg_t hwb : 1;
152 /**
153 * Encoded size of buffer. Set by the ingress hardware for iDMA packet
154 * descriptors. For eDMA descriptors, indicates the buffer size if .c
155 * indicates a chained packet. If an eDMA descriptor is not chained and
156 * the .hwb bit is not set, this field is ignored and the size is
157 * specified by the .xfer_size field.
158 * 0 = 128 bytes
159 * 1 = 256 bytes
160 * 2 = 512 bytes
161 * 3 = 1024 bytes
162 * 4 = 1664 bytes
163 * 5 = 4096 bytes
164 * 6 = 10368 bytes
165 * 7 = 16384 bytes
166 */
167 uint_reg_t size : 3;
168 /**
169 * Chaining configuration for the buffer. Indicates that an ingress
170 * packet or egress command is chained across multiple buffers, with each
171 * buffer's size indicated by the .size field.
172 */
173 uint_reg_t c : 2;
174#else /* __BIG_ENDIAN__ */
175 uint_reg_t c : 2;
176 uint_reg_t size : 3;
177 uint_reg_t hwb : 1;
178 uint_reg_t inst : 2;
179 uint_reg_t __reserved_1 : 3;
180 uint_reg_t stack_idx : 5;
181 uint_reg_t __reserved_0 : 6;
182 int_reg_t va : 42;
183#endif
184
185 };
186
187 /** Word access */
188 uint_reg_t words[2];
189} MPIPE_EDMA_DESC_t;
190
191/**
192 * MPIPE Packet Descriptor.
193 * The packet descriptor is filled by the mPIPE's classification,
194 * load-balancing, and buffer management services. Some fields are consumed
195 * by mPIPE hardware, and others are consumed by Tile software.
196 */
197
198__extension__
199typedef union
200{
201 struct
202 {
203 /* Word 0 */
204
205#ifndef __BIG_ENDIAN__
206 /**
207 * Notification ring into which this packet descriptor is written.
208 * Typically written by load balancer, but can be overridden by
209 * classification program if NR is asserted.
210 */
211 uint_reg_t notif_ring : 8;
212 /** Source channel for this packet. Written by mPIPE DMA hardware. */
213 uint_reg_t channel : 5;
214 /** Reserved. */
215 uint_reg_t __reserved_0 : 1;
216 /**
217 * MAC Error.
218 * Generated by the MAC interface. Asserted if there was an overrun of
219 * the MAC's receive FIFO. This condition generally only occurs if the
220 * mPIPE clock is running too slowly.
221 */
222 uint_reg_t me : 1;
223 /**
224 * Truncation Error.
225 * Written by the iDMA hardware. Asserted if packet was truncated due to
226 * insufficient space in iPkt buffer
227 */
228 uint_reg_t tr : 1;
229 /**
230 * Written by the iDMA hardware. Indicates the number of bytes written
231 * to Tile memory. In general, this is the actual size of the packet as
232 * received from the MAC. But if the packet is truncated due to running
233 * out of buffers or due to the iPkt buffer filling up, then the L2_SIZE
234 * will be reduced to reflect the actual number of valid bytes written to
235 * Tile memory.
236 */
237 uint_reg_t l2_size : 14;
238 /**
239 * CRC Error.
240 * Generated by the MAC. Asserted if MAC indicated an L2 CRC error or
241 * other L2 error (bad length etc.) on the packet.
242 */
243 uint_reg_t ce : 1;
244 /**
245 * Cut Through.
246 * Written by the iDMA hardware. Asserted if packet was not completely
247 * received before being sent to classifier. L2_Size will indicate
248 * number of bytes received so far.
249 */
250 uint_reg_t ct : 1;
251 /**
252 * Written by the classification program. Used by the load balancer to
253 * select the ring into which this packet descriptor is written.
254 */
255 uint_reg_t bucket_id : 13;
256 /** Reserved. */
257 uint_reg_t __reserved_1 : 3;
258 /**
259 * Checksum.
260 * Written by classification program. When 1, the checksum engine will
261 * perform checksum based on the CSUM_SEED, CSUM_START, and CSUM_BYTES
262 * fields. The result will be placed in CSUM_VAL.
263 */
264 uint_reg_t cs : 1;
265 /**
266 * Notification Ring Select.
267 * Written by the classification program. When 1, the NotifRingIDX is
268 * set by classification program rather than being set by load balancer.
269 */
270 uint_reg_t nr : 1;
271 /**
272 * Written by classification program. Indicates whether packet and
273 * descriptor should both be dropped, both be delivered, or only the
274 * descriptor should be delivered.
275 */
276 uint_reg_t dest : 2;
277 /**
278 * General Purpose Sequence Number Enable.
279 * Written by the classification program. When 1, the GP_SQN_SEL field
280 * contains the sequence number selector and the GP_SQN field will be
281 * replaced with the associated sequence number. When clear, the GP_SQN
282 * field is left intact and be used as "Custom" bytes.
283 */
284 uint_reg_t sq : 1;
285 /**
286 * TimeStamp Enable.
287 * Enable TimeStamp insertion. When clear, timestamp field may be filled
288 * with custom data by classifier. When set, hardware inserts the
289 * timestamp when the start of packet is received from the MAC.
290 */
291 uint_reg_t ts : 1;
292 /**
293 * Packet Sequence Number Enable.
294 * Enable PacketSQN insertion. When clear, PacketSQN field may be filled
295 * with custom data by classifier. When set, hardware inserts the packet
296 * sequence number when the packet descriptor is written to a
297 * notification ring.
298 */
299 uint_reg_t ps : 1;
300 /**
301 * Buffer Error.
302 * Written by the iDMA hardware. Asserted if iDMA ran out of buffers
303 * while writing the packet. Software must still return any buffer
304 * descriptors whose C field indicates a valid descriptor was consumed.
305 */
306 uint_reg_t be : 1;
307 /**
308 * Written by the classification program. The associated counter is
309 * incremented when the packet is sent.
310 */
311 uint_reg_t ctr0 : 5;
312 /** Reserved. */
313 uint_reg_t __reserved_2 : 3;
314#else /* __BIG_ENDIAN__ */
315 uint_reg_t __reserved_2 : 3;
316 uint_reg_t ctr0 : 5;
317 uint_reg_t be : 1;
318 uint_reg_t ps : 1;
319 uint_reg_t ts : 1;
320 uint_reg_t sq : 1;
321 uint_reg_t dest : 2;
322 uint_reg_t nr : 1;
323 uint_reg_t cs : 1;
324 uint_reg_t __reserved_1 : 3;
325 uint_reg_t bucket_id : 13;
326 uint_reg_t ct : 1;
327 uint_reg_t ce : 1;
328 uint_reg_t l2_size : 14;
329 uint_reg_t tr : 1;
330 uint_reg_t me : 1;
331 uint_reg_t __reserved_0 : 1;
332 uint_reg_t channel : 5;
333 uint_reg_t notif_ring : 8;
334#endif
335
336 /* Word 1 */
337
338#ifndef __BIG_ENDIAN__
339 /**
340 * Written by the classification program. The associated counter is
341 * incremented when the packet is sent.
342 */
343 uint_reg_t ctr1 : 5;
344 /** Reserved. */
345 uint_reg_t __reserved_3 : 3;
346 /**
347 * Written by classification program. Indicates the start byte for
348 * checksum. Relative to 1st byte received from MAC.
349 */
350 uint_reg_t csum_start : 8;
351 /**
352 * Checksum seed written by classification program. Overwritten with
353 * resultant checksum if CS bit is asserted. The endianness of the CSUM
354 * value bits when viewed by Tile software match the packet byte order.
355 * That is, bits[7:0] of the resulting checksum value correspond to
356 * earlier (more significant) bytes in the packet. To avoid classifier
357 * software from having to byte swap the CSUM_SEED, the iDMA checksum
358 * engine byte swaps the classifier's result before seeding the checksum
359 * calculation. Thus, the CSUM_START byte of packet data is added to
360 * bits[15:8] of the CSUM_SEED field generated by the classifier. This
361 * byte swap will be visible to Tile software if the CS bit is clear.
362 */
363 uint_reg_t csum_seed_val : 16;
364 /**
365 * Written by the classification program. Not interpreted by mPIPE
366 * hardware.
367 */
368 uint_reg_t custom0 : 32;
369#else /* __BIG_ENDIAN__ */
370 uint_reg_t custom0 : 32;
371 uint_reg_t csum_seed_val : 16;
372 uint_reg_t csum_start : 8;
373 uint_reg_t __reserved_3 : 3;
374 uint_reg_t ctr1 : 5;
375#endif
376
377 /* Word 2 */
378
379#ifndef __BIG_ENDIAN__
380 /**
381 * Written by the classification program. Not interpreted by mPIPE
382 * hardware.
383 */
384 uint_reg_t custom1 : 64;
385#else /* __BIG_ENDIAN__ */
386 uint_reg_t custom1 : 64;
387#endif
388
389 /* Word 3 */
390
391#ifndef __BIG_ENDIAN__
392 /**
393 * Written by the classification program. Not interpreted by mPIPE
394 * hardware.
395 */
396 uint_reg_t custom2 : 64;
397#else /* __BIG_ENDIAN__ */
398 uint_reg_t custom2 : 64;
399#endif
400
401 /* Word 4 */
402
403#ifndef __BIG_ENDIAN__
404 /**
405 * Written by the classification program. Not interpreted by mPIPE
406 * hardware.
407 */
408 uint_reg_t custom3 : 64;
409#else /* __BIG_ENDIAN__ */
410 uint_reg_t custom3 : 64;
411#endif
412
413 /* Word 5 */
414
415#ifndef __BIG_ENDIAN__
416 /**
417 * Sequence number applied when packet is distributed. Classifier
418 * selects which sequence number is to be applied by writing the 13-bit
419 * SQN-selector into this field. For devices that support EXT_SQN (as
420 * indicated in IDMA_INFO.EXT_SQN_SUPPORT), the GP_SQN can be extended to
421 * 32-bits via the IDMA_CTL.EXT_SQN register. In this case the
422 * PACKET_SQN will be reduced to 32 bits.
423 */
424 uint_reg_t gp_sqn : 16;
425 /**
426 * Written by notification hardware. The packet sequence number is
427 * incremented for each packet that wasn't dropped.
428 */
429 uint_reg_t packet_sqn : 48;
430#else /* __BIG_ENDIAN__ */
431 uint_reg_t packet_sqn : 48;
432 uint_reg_t gp_sqn : 16;
433#endif
434
435 /* Word 6 */
436
437#ifndef __BIG_ENDIAN__
438 /**
439 * Written by hardware when the start-of-packet is received by the mPIPE
440 * from the MAC. This is the nanoseconds part of the packet timestamp.
441 */
442 uint_reg_t time_stamp_ns : 32;
443 /**
444 * Written by hardware when the start-of-packet is received by the mPIPE
445 * from the MAC. This is the seconds part of the packet timestamp.
446 */
447 uint_reg_t time_stamp_sec : 32;
448#else /* __BIG_ENDIAN__ */
449 uint_reg_t time_stamp_sec : 32;
450 uint_reg_t time_stamp_ns : 32;
451#endif
452
453 /* Word 7 */
454
455#ifndef __BIG_ENDIAN__
456 /** Virtual address. Must be sign extended by consumer. */
457 int_reg_t va : 42;
458 /** Reserved. */
459 uint_reg_t __reserved_4 : 6;
460 /** Index of the buffer stack to which this buffer belongs. */
461 uint_reg_t stack_idx : 5;
462 /** Reserved. */
463 uint_reg_t __reserved_5 : 3;
464 /**
465 * Instance ID. For devices that support automatic buffer return between
466 * mPIPE instances, this field indicates the buffer owner. If the INST
467 * field does not match the mPIPE's instance number when a packet is
468 * egressed, buffers with HWB set will be returned to the other mPIPE
469 * instance. Note that not all devices support multi-mPIPE buffer
470 * return. The MPIPE_EDMA_INFO.REMOTE_BUFF_RTN_SUPPORT bit indicates
471 * whether the INST field in the buffer descriptor is populated by iDMA
472 * hardware.
473 */
474 uint_reg_t inst : 2;
475 /**
476 * Always set to one by hardware in iDMA packet descriptors. For eDMA,
477 * indicates whether the buffer will be released to the buffer stack
478 * manager. When 0, software is responsible for releasing the buffer.
479 */
480 uint_reg_t hwb : 1;
481 /**
482 * Encoded size of buffer. Set by the ingress hardware for iDMA packet
483 * descriptors. For eDMA descriptors, indicates the buffer size if .c
484 * indicates a chained packet. If an eDMA descriptor is not chained and
485 * the .hwb bit is not set, this field is ignored and the size is
486 * specified by the .xfer_size field.
487 * 0 = 128 bytes
488 * 1 = 256 bytes
489 * 2 = 512 bytes
490 * 3 = 1024 bytes
491 * 4 = 1664 bytes
492 * 5 = 4096 bytes
493 * 6 = 10368 bytes
494 * 7 = 16384 bytes
495 */
496 uint_reg_t size : 3;
497 /**
498 * Chaining configuration for the buffer. Indicates that an ingress
499 * packet or egress command is chained across multiple buffers, with each
500 * buffer's size indicated by the .size field.
501 */
502 uint_reg_t c : 2;
503#else /* __BIG_ENDIAN__ */
504 uint_reg_t c : 2;
505 uint_reg_t size : 3;
506 uint_reg_t hwb : 1;
507 uint_reg_t inst : 2;
508 uint_reg_t __reserved_5 : 3;
509 uint_reg_t stack_idx : 5;
510 uint_reg_t __reserved_4 : 6;
511 int_reg_t va : 42;
512#endif
513
514 };
515
516 /** Word access */
517 uint_reg_t words[8];
518} MPIPE_PDESC_t;
519#endif /* !defined(__ASSEMBLER__) */
520
521#endif /* !defined(__ARCH_MPIPE_SHM_H__) */
diff --git a/arch/tile/include/arch/mpipe_shm_def.h b/arch/tile/include/arch/mpipe_shm_def.h
deleted file mode 100644
index 6124d39c8318..000000000000
--- a/arch/tile/include/arch/mpipe_shm_def.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_MPIPE_SHM_DEF_H__
18#define __ARCH_MPIPE_SHM_DEF_H__
19#define MPIPE_EDMA_DESC_WORD1__C_VAL_UNCHAINED 0x0
20#define MPIPE_EDMA_DESC_WORD1__C_VAL_CHAINED 0x1
21#define MPIPE_EDMA_DESC_WORD1__C_VAL_NOT_RDY 0x2
22#define MPIPE_EDMA_DESC_WORD1__C_VAL_INVALID 0x3
23#endif /* !defined(__ARCH_MPIPE_SHM_DEF_H__) */
diff --git a/arch/tile/include/arch/spr_def.h b/arch/tile/include/arch/spr_def.h
deleted file mode 100644
index 2de83e7aff3e..000000000000
--- a/arch/tile/include/arch/spr_def.h
+++ /dev/null
@@ -1,109 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14#ifndef __ARCH_SPR_DEF_H__
15#define __ARCH_SPR_DEF_H__
16
17#include <uapi/arch/spr_def.h>
18
19
20/*
21 * In addition to including the proper base SPR definition file, depending
22 * on machine architecture, this file defines several macros which allow
23 * kernel code to use protection-level dependent SPRs without worrying
24 * about which PL it's running at. In these macros, the PL that the SPR
25 * or interrupt number applies to is replaced by K.
26 */
27
28#if CONFIG_KERNEL_PL != 1 && CONFIG_KERNEL_PL != 2
29#error CONFIG_KERNEL_PL must be 1 or 2
30#endif
31
32/* Concatenate 4 strings. */
33#define __concat4(a, b, c, d) a ## b ## c ## d
34#define _concat4(a, b, c, d) __concat4(a, b, c, d)
35
36#ifdef __tilegx__
37
38/* TILE-Gx dependent, protection-level dependent SPRs. */
39
40#define SPR_INTERRUPT_MASK_K \
41 _concat4(SPR_INTERRUPT_MASK_, CONFIG_KERNEL_PL,,)
42#define SPR_INTERRUPT_MASK_SET_K \
43 _concat4(SPR_INTERRUPT_MASK_SET_, CONFIG_KERNEL_PL,,)
44#define SPR_INTERRUPT_MASK_RESET_K \
45 _concat4(SPR_INTERRUPT_MASK_RESET_, CONFIG_KERNEL_PL,,)
46#define SPR_INTERRUPT_VECTOR_BASE_K \
47 _concat4(SPR_INTERRUPT_VECTOR_BASE_, CONFIG_KERNEL_PL,,)
48
49#define SPR_IPI_MASK_K \
50 _concat4(SPR_IPI_MASK_, CONFIG_KERNEL_PL,,)
51#define SPR_IPI_MASK_RESET_K \
52 _concat4(SPR_IPI_MASK_RESET_, CONFIG_KERNEL_PL,,)
53#define SPR_IPI_MASK_SET_K \
54 _concat4(SPR_IPI_MASK_SET_, CONFIG_KERNEL_PL,,)
55#define SPR_IPI_EVENT_K \
56 _concat4(SPR_IPI_EVENT_, CONFIG_KERNEL_PL,,)
57#define SPR_IPI_EVENT_RESET_K \
58 _concat4(SPR_IPI_EVENT_RESET_, CONFIG_KERNEL_PL,,)
59#define SPR_IPI_EVENT_SET_K \
60 _concat4(SPR_IPI_EVENT_SET_, CONFIG_KERNEL_PL,,)
61#define INT_IPI_K \
62 _concat4(INT_IPI_, CONFIG_KERNEL_PL,,)
63
64#define SPR_SINGLE_STEP_CONTROL_K \
65 _concat4(SPR_SINGLE_STEP_CONTROL_, CONFIG_KERNEL_PL,,)
66#define SPR_SINGLE_STEP_EN_K_K \
67 _concat4(SPR_SINGLE_STEP_EN_, CONFIG_KERNEL_PL, _, CONFIG_KERNEL_PL)
68#define INT_SINGLE_STEP_K \
69 _concat4(INT_SINGLE_STEP_, CONFIG_KERNEL_PL,,)
70
71#else
72
73/* TILEPro dependent, protection-level dependent SPRs. */
74
75#define SPR_INTERRUPT_MASK_K_0 \
76 _concat4(SPR_INTERRUPT_MASK_, CONFIG_KERNEL_PL, _0,)
77#define SPR_INTERRUPT_MASK_K_1 \
78 _concat4(SPR_INTERRUPT_MASK_, CONFIG_KERNEL_PL, _1,)
79#define SPR_INTERRUPT_MASK_SET_K_0 \
80 _concat4(SPR_INTERRUPT_MASK_SET_, CONFIG_KERNEL_PL, _0,)
81#define SPR_INTERRUPT_MASK_SET_K_1 \
82 _concat4(SPR_INTERRUPT_MASK_SET_, CONFIG_KERNEL_PL, _1,)
83#define SPR_INTERRUPT_MASK_RESET_K_0 \
84 _concat4(SPR_INTERRUPT_MASK_RESET_, CONFIG_KERNEL_PL, _0,)
85#define SPR_INTERRUPT_MASK_RESET_K_1 \
86 _concat4(SPR_INTERRUPT_MASK_RESET_, CONFIG_KERNEL_PL, _1,)
87
88#endif
89
90/* Generic protection-level dependent SPRs. */
91
92#define SPR_SYSTEM_SAVE_K_0 \
93 _concat4(SPR_SYSTEM_SAVE_, CONFIG_KERNEL_PL, _0,)
94#define SPR_SYSTEM_SAVE_K_1 \
95 _concat4(SPR_SYSTEM_SAVE_, CONFIG_KERNEL_PL, _1,)
96#define SPR_SYSTEM_SAVE_K_2 \
97 _concat4(SPR_SYSTEM_SAVE_, CONFIG_KERNEL_PL, _2,)
98#define SPR_SYSTEM_SAVE_K_3 \
99 _concat4(SPR_SYSTEM_SAVE_, CONFIG_KERNEL_PL, _3,)
100#define SPR_EX_CONTEXT_K_0 \
101 _concat4(SPR_EX_CONTEXT_, CONFIG_KERNEL_PL, _0,)
102#define SPR_EX_CONTEXT_K_1 \
103 _concat4(SPR_EX_CONTEXT_, CONFIG_KERNEL_PL, _1,)
104#define SPR_INTCTRL_K_STATUS \
105 _concat4(SPR_INTCTRL_, CONFIG_KERNEL_PL, _STATUS,)
106#define INT_INTCTRL_K \
107 _concat4(INT_INTCTRL_, CONFIG_KERNEL_PL,,)
108
109#endif /* __ARCH_SPR_DEF_H__ */
diff --git a/arch/tile/include/arch/trio.h b/arch/tile/include/arch/trio.h
deleted file mode 100644
index c0ddedcae085..000000000000
--- a/arch/tile/include/arch/trio.h
+++ /dev/null
@@ -1,111 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_TRIO_H__
18#define __ARCH_TRIO_H__
19
20#include <arch/abi.h>
21#include <arch/trio_def.h>
22
23#ifndef __ASSEMBLER__
24
25/*
26 * Map SQ Doorbell Format.
27 * This describes the format of the write-only doorbell register that exists
28 * in the last 8-bytes of the MAP_SQ_BASE/LIM range. This register is only
29 * writable from PCIe space. Writes to this register will not be written to
30 * Tile memory space and thus no IO VA translation is required if the last
31 * page of the BASE/LIM range is not otherwise written.
32 */
33
34__extension__
35typedef union
36{
37 struct
38 {
39#ifndef __BIG_ENDIAN__
40 /*
41 * When written with a 1, the associated MAP_SQ region's doorbell
42 * interrupt will be triggered once all previous writes are visible to
43 * Tile software.
44 */
45 uint_reg_t doorbell : 1;
46 /*
47 * When written with a 1, the descriptor at the head of the associated
48 * MAP_SQ's FIFO will be dequeued.
49 */
50 uint_reg_t pop : 1;
51 /* Reserved. */
52 uint_reg_t __reserved : 62;
53#else /* __BIG_ENDIAN__ */
54 uint_reg_t __reserved : 62;
55 uint_reg_t pop : 1;
56 uint_reg_t doorbell : 1;
57#endif
58 };
59
60 uint_reg_t word;
61} TRIO_MAP_SQ_DOORBELL_FMT_t;
62
63
64/*
65 * Tile PIO Region Configuration - CFG Address Format.
66 * This register describes the address format for PIO accesses when the
67 * associated region is setup with TYPE=CFG.
68 */
69
70__extension__
71typedef union
72{
73 struct
74 {
75#ifndef __BIG_ENDIAN__
76 /* Register Address (full byte address). */
77 uint_reg_t reg_addr : 12;
78 /* Function Number */
79 uint_reg_t fn : 3;
80 /* Device Number */
81 uint_reg_t dev : 5;
82 /* BUS Number */
83 uint_reg_t bus : 8;
84 /* Config Type: 0 for access to directly-attached device. 1 otherwise. */
85 uint_reg_t type : 1;
86 /* Reserved. */
87 uint_reg_t __reserved_0 : 1;
88 /*
89 * MAC select. This must match the configuration in
90 * TILE_PIO_REGION_SETUP.MAC.
91 */
92 uint_reg_t mac : 2;
93 /* Reserved. */
94 uint_reg_t __reserved_1 : 32;
95#else /* __BIG_ENDIAN__ */
96 uint_reg_t __reserved_1 : 32;
97 uint_reg_t mac : 2;
98 uint_reg_t __reserved_0 : 1;
99 uint_reg_t type : 1;
100 uint_reg_t bus : 8;
101 uint_reg_t dev : 5;
102 uint_reg_t fn : 3;
103 uint_reg_t reg_addr : 12;
104#endif
105 };
106
107 uint_reg_t word;
108} TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR_t;
109#endif /* !defined(__ASSEMBLER__) */
110
111#endif /* !defined(__ARCH_TRIO_H__) */
diff --git a/arch/tile/include/arch/trio_constants.h b/arch/tile/include/arch/trio_constants.h
deleted file mode 100644
index 85647e91a458..000000000000
--- a/arch/tile/include/arch/trio_constants.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15
16#ifndef __ARCH_TRIO_CONSTANTS_H__
17#define __ARCH_TRIO_CONSTANTS_H__
18
19#define TRIO_NUM_ASIDS 32
20#define TRIO_NUM_TLBS_PER_ASID 16
21
22#define TRIO_NUM_TPIO_REGIONS 8
23#define TRIO_LOG2_NUM_TPIO_REGIONS 3
24
25#define TRIO_NUM_MAP_MEM_REGIONS 32
26#define TRIO_LOG2_NUM_MAP_MEM_REGIONS 5
27#define TRIO_NUM_MAP_SQ_REGIONS 8
28#define TRIO_LOG2_NUM_MAP_SQ_REGIONS 3
29
30#define TRIO_LOG2_NUM_SQ_FIFO_ENTRIES 6
31
32#define TRIO_NUM_PUSH_DMA_RINGS 64
33
34#define TRIO_NUM_PULL_DMA_RINGS 64
35
36#endif /* __ARCH_TRIO_CONSTANTS_H__ */
diff --git a/arch/tile/include/arch/trio_def.h b/arch/tile/include/arch/trio_def.h
deleted file mode 100644
index e80500317dc4..000000000000
--- a/arch/tile/include/arch/trio_def.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_TRIO_DEF_H__
18#define __ARCH_TRIO_DEF_H__
19#define TRIO_CFG_REGION_ADDR__REG_SHIFT 0
20#define TRIO_CFG_REGION_ADDR__INTFC_SHIFT 16
21#define TRIO_CFG_REGION_ADDR__INTFC_VAL_TRIO 0x0
22#define TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE 0x1
23#define TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD 0x2
24#define TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_PROTECTED 0x3
25#define TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT 18
26#define TRIO_CFG_REGION_ADDR__PROT_SHIFT 20
27#define TRIO_PIO_REGIONS_ADDR__REGION_SHIFT 32
28#define TRIO_MAP_MEM_REG_INT0 0x1000000000
29#define TRIO_MAP_MEM_REG_INT1 0x1000000008
30#define TRIO_MAP_MEM_REG_INT2 0x1000000010
31#define TRIO_MAP_MEM_REG_INT3 0x1000000018
32#define TRIO_MAP_MEM_REG_INT4 0x1000000020
33#define TRIO_MAP_MEM_REG_INT5 0x1000000028
34#define TRIO_MAP_MEM_REG_INT6 0x1000000030
35#define TRIO_MAP_MEM_REG_INT7 0x1000000038
36#define TRIO_MAP_MEM_LIM__ADDR_SHIFT 12
37#define TRIO_MAP_MEM_SETUP__ORDER_MODE_VAL_UNORDERED 0x0
38#define TRIO_MAP_MEM_SETUP__ORDER_MODE_VAL_STRICT 0x1
39#define TRIO_MAP_MEM_SETUP__ORDER_MODE_VAL_REL_ORD 0x2
40#define TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR__MAC_SHIFT 30
41#endif /* !defined(__ARCH_TRIO_DEF_H__) */
diff --git a/arch/tile/include/arch/trio_pcie_intfc.h b/arch/tile/include/arch/trio_pcie_intfc.h
deleted file mode 100644
index 0487fdb9d581..000000000000
--- a/arch/tile/include/arch/trio_pcie_intfc.h
+++ /dev/null
@@ -1,229 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_TRIO_PCIE_INTFC_H__
18#define __ARCH_TRIO_PCIE_INTFC_H__
19
20#include <arch/abi.h>
21#include <arch/trio_pcie_intfc_def.h>
22
23#ifndef __ASSEMBLER__
24
25/*
26 * Port Configuration.
27 * Configuration of the PCIe Port
28 */
29
30__extension__
31typedef union
32{
33 struct
34 {
35#ifndef __BIG_ENDIAN__
36 /* Provides the state of the strapping pins for this port. */
37 uint_reg_t strap_state : 3;
38 /* Reserved. */
39 uint_reg_t __reserved_0 : 1;
40 /*
41 * When 1, the device type will be overridden using OVD_DEV_TYPE_VAL.
42 * When 0, the device type is determined based on the STRAP_STATE.
43 */
44 uint_reg_t ovd_dev_type : 1;
45 /* Provides the device type when OVD_DEV_TYPE is 1. */
46 uint_reg_t ovd_dev_type_val : 4;
47 /* Determines how link is trained. */
48 uint_reg_t train_mode : 2;
49 /* Reserved. */
50 uint_reg_t __reserved_1 : 1;
51 /*
52 * For PCIe, used to flip physical RX lanes that were not properly wired.
53 * This is not the same as lane reversal which is handled automatically
54 * during link training. When 0, RX Lane0 must be wired to the link
55 * partner (either to its Lane0 or it's LaneN). When RX_LANE_FLIP is 1,
56 * the highest numbered lane for this port becomes Lane0 and Lane0 does
57 * NOT have to be wired to the link partner.
58 */
59 uint_reg_t rx_lane_flip : 1;
60 /*
61 * For PCIe, used to flip physical TX lanes that were not properly wired.
62 * This is not the same as lane reversal which is handled automatically
63 * during link training. When 0, TX Lane0 must be wired to the link
64 * partner (either to its Lane0 or it's LaneN). When TX_LANE_FLIP is 1,
65 * the highest numbered lane for this port becomes Lane0 and Lane0 does
66 * NOT have to be wired to the link partner.
67 */
68 uint_reg_t tx_lane_flip : 1;
69 /*
70 * For StreamIO port, configures the width of the port when TRAIN_MODE is
71 * not STRAP.
72 */
73 uint_reg_t stream_width : 2;
74 /*
75 * For StreamIO port, configures the rate of the port when TRAIN_MODE is
76 * not STRAP.
77 */
78 uint_reg_t stream_rate : 2;
79 /* Reserved. */
80 uint_reg_t __reserved_2 : 46;
81#else /* __BIG_ENDIAN__ */
82 uint_reg_t __reserved_2 : 46;
83 uint_reg_t stream_rate : 2;
84 uint_reg_t stream_width : 2;
85 uint_reg_t tx_lane_flip : 1;
86 uint_reg_t rx_lane_flip : 1;
87 uint_reg_t __reserved_1 : 1;
88 uint_reg_t train_mode : 2;
89 uint_reg_t ovd_dev_type_val : 4;
90 uint_reg_t ovd_dev_type : 1;
91 uint_reg_t __reserved_0 : 1;
92 uint_reg_t strap_state : 3;
93#endif
94 };
95
96 uint_reg_t word;
97} TRIO_PCIE_INTFC_PORT_CONFIG_t;
98
99/*
100 * Port Status.
101 * Status of the PCIe Port. This register applies to the StreamIO port when
102 * StreamIO is enabled.
103 */
104
105__extension__
106typedef union
107{
108 struct
109 {
110#ifndef __BIG_ENDIAN__
111 /*
112 * Indicates the DL state of the port. When 1, the port is up and ready
113 * to receive traffic.
114 */
115 uint_reg_t dl_up : 1;
116 /*
117 * Indicates the number of times the link has gone down. Clears on read.
118 */
119 uint_reg_t dl_down_cnt : 7;
120 /* Indicates the SERDES PLL has spun up and is providing a valid clock. */
121 uint_reg_t clock_ready : 1;
122 /* Reserved. */
123 uint_reg_t __reserved_0 : 7;
124 /* Device revision ID. */
125 uint_reg_t device_rev : 8;
126 /* Link state (PCIe). */
127 uint_reg_t ltssm_state : 6;
128 /* Link power management state (PCIe). */
129 uint_reg_t pm_state : 3;
130 /* Reserved. */
131 uint_reg_t __reserved_1 : 31;
132#else /* __BIG_ENDIAN__ */
133 uint_reg_t __reserved_1 : 31;
134 uint_reg_t pm_state : 3;
135 uint_reg_t ltssm_state : 6;
136 uint_reg_t device_rev : 8;
137 uint_reg_t __reserved_0 : 7;
138 uint_reg_t clock_ready : 1;
139 uint_reg_t dl_down_cnt : 7;
140 uint_reg_t dl_up : 1;
141#endif
142 };
143
144 uint_reg_t word;
145} TRIO_PCIE_INTFC_PORT_STATUS_t;
146
147/*
148 * Transmit FIFO Control.
149 * Contains TX FIFO thresholds. These registers are for diagnostics purposes
150 * only. Changing these values causes undefined behavior.
151 */
152
153__extension__
154typedef union
155{
156 struct
157 {
158#ifndef __BIG_ENDIAN__
159 /*
160 * Almost-Empty level for TX0 data. Typically set to at least
161 * roundup(38.0*M/N) where N=tclk frequency and M=MAC symbol rate in MHz
162 * for a x4 port (250MHz).
163 */
164 uint_reg_t tx0_data_ae_lvl : 7;
165 /* Reserved. */
166 uint_reg_t __reserved_0 : 1;
167 /* Almost-Empty level for TX1 data. */
168 uint_reg_t tx1_data_ae_lvl : 7;
169 /* Reserved. */
170 uint_reg_t __reserved_1 : 1;
171 /* Almost-Full level for TX0 data. */
172 uint_reg_t tx0_data_af_lvl : 7;
173 /* Reserved. */
174 uint_reg_t __reserved_2 : 1;
175 /* Almost-Full level for TX1 data. */
176 uint_reg_t tx1_data_af_lvl : 7;
177 /* Reserved. */
178 uint_reg_t __reserved_3 : 1;
179 /* Almost-Full level for TX0 info. */
180 uint_reg_t tx0_info_af_lvl : 5;
181 /* Reserved. */
182 uint_reg_t __reserved_4 : 3;
183 /* Almost-Full level for TX1 info. */
184 uint_reg_t tx1_info_af_lvl : 5;
185 /* Reserved. */
186 uint_reg_t __reserved_5 : 3;
187 /*
188 * This register provides performance adjustment for high bandwidth
189 * flows. The MAC will assert almost-full to TRIO if non-posted credits
190 * fall below this level. Note that setting this larger than the initial
191 * PORT_CREDIT.NPH value will cause READS to never be sent. If the
192 * initial credit value from the link partner is smaller than this value
193 * when the link comes up, the value will be reset to the initial credit
194 * value to prevent lockup.
195 */
196 uint_reg_t min_np_credits : 8;
197 /*
198 * This register provides performance adjustment for high bandwidth
199 * flows. The MAC will assert almost-full to TRIO if posted credits fall
200 * below this level. Note that setting this larger than the initial
201 * PORT_CREDIT.PH value will cause WRITES to never be sent. If the
202 * initial credit value from the link partner is smaller than this value
203 * when the link comes up, the value will be reset to the initial credit
204 * value to prevent lockup.
205 */
206 uint_reg_t min_p_credits : 8;
207#else /* __BIG_ENDIAN__ */
208 uint_reg_t min_p_credits : 8;
209 uint_reg_t min_np_credits : 8;
210 uint_reg_t __reserved_5 : 3;
211 uint_reg_t tx1_info_af_lvl : 5;
212 uint_reg_t __reserved_4 : 3;
213 uint_reg_t tx0_info_af_lvl : 5;
214 uint_reg_t __reserved_3 : 1;
215 uint_reg_t tx1_data_af_lvl : 7;
216 uint_reg_t __reserved_2 : 1;
217 uint_reg_t tx0_data_af_lvl : 7;
218 uint_reg_t __reserved_1 : 1;
219 uint_reg_t tx1_data_ae_lvl : 7;
220 uint_reg_t __reserved_0 : 1;
221 uint_reg_t tx0_data_ae_lvl : 7;
222#endif
223 };
224
225 uint_reg_t word;
226} TRIO_PCIE_INTFC_TX_FIFO_CTL_t;
227#endif /* !defined(__ASSEMBLER__) */
228
229#endif /* !defined(__ARCH_TRIO_PCIE_INTFC_H__) */
diff --git a/arch/tile/include/arch/trio_pcie_intfc_def.h b/arch/tile/include/arch/trio_pcie_intfc_def.h
deleted file mode 100644
index d3fd6781fb24..000000000000
--- a/arch/tile/include/arch/trio_pcie_intfc_def.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_TRIO_PCIE_INTFC_DEF_H__
18#define __ARCH_TRIO_PCIE_INTFC_DEF_H__
19#define TRIO_PCIE_INTFC_MAC_INT_STS 0x0000
20#define TRIO_PCIE_INTFC_MAC_INT_STS__INT_LEVEL_MASK 0xf000
21#define TRIO_PCIE_INTFC_PORT_CONFIG 0x0018
22#define TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_DISABLED 0x0
23#define TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_ENDPOINT 0x1
24#define TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_RC 0x2
25#define TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_ENDPOINT_G1 0x3
26#define TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_RC_G1 0x4
27#define TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_XLINK 0x5
28#define TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_STREAM_X1 0x6
29#define TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_STREAM_X4 0x7
30#define TRIO_PCIE_INTFC_PORT_STATUS 0x0020
31#define TRIO_PCIE_INTFC_TX_FIFO_CTL 0x0050
32#endif /* !defined(__ARCH_TRIO_PCIE_INTFC_DEF_H__) */
diff --git a/arch/tile/include/arch/trio_pcie_rc.h b/arch/tile/include/arch/trio_pcie_rc.h
deleted file mode 100644
index 6a25d0aca857..000000000000
--- a/arch/tile/include/arch/trio_pcie_rc.h
+++ /dev/null
@@ -1,156 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_TRIO_PCIE_RC_H__
18#define __ARCH_TRIO_PCIE_RC_H__
19
20#include <arch/abi.h>
21#include <arch/trio_pcie_rc_def.h>
22
23#ifndef __ASSEMBLER__
24
25/* Device Capabilities Register. */
26
27__extension__
28typedef union
29{
30 struct
31 {
32#ifndef __BIG_ENDIAN__
33 /*
34 * Max_Payload_Size Supported, writablethrough the MAC_STANDARD interface
35 */
36 uint_reg_t mps_sup : 3;
37 /*
38 * This field is writable through the MAC_STANDARD interface. However,
39 * Phantom Function is not supported. Therefore, the application must
40 * not write any value other than 0x0 to this field.
41 */
42 uint_reg_t phantom_function_supported : 2;
43 /* This bit is writable through the MAC_STANDARD interface. */
44 uint_reg_t ext_tag_field_supported : 1;
45 /* Reserved. */
46 uint_reg_t __reserved_0 : 3;
47 /* Endpoint L1 Acceptable Latency Must be 0x0 for non-Endpoint devices. */
48 uint_reg_t l1_lat : 3;
49 /*
50 * Undefined since PCI Express 1.1 (Was Attention Button Present for PCI
51 * Express 1.0a)
52 */
53 uint_reg_t r1 : 1;
54 /*
55 * Undefined since PCI Express 1.1 (Was Attention Indicator Present for
56 * PCI Express 1.0a)
57 */
58 uint_reg_t r2 : 1;
59 /*
60 * Undefined since PCI Express 1.1 (Was Power Indicator Present for PCI
61 * Express 1.0a)
62 */
63 uint_reg_t r3 : 1;
64 /*
65 * Role-Based Error Reporting, writable through the MAC_STANDARD
66 * interface. Required to be set for device compliant to 1.1 spec and
67 * later.
68 */
69 uint_reg_t rer : 1;
70 /* Reserved. */
71 uint_reg_t __reserved_1 : 2;
72 /* Captured Slot Power Limit Value Upstream port only. */
73 uint_reg_t slot_pwr_lim : 8;
74 /* Captured Slot Power Limit Scale Upstream port only. */
75 uint_reg_t slot_pwr_scale : 2;
76 /* Reserved. */
77 uint_reg_t __reserved_2 : 4;
78 /* Endpoint L0s Acceptable LatencyMust be 0x0 for non-Endpoint devices. */
79 uint_reg_t l0s_lat : 1;
80 /* Reserved. */
81 uint_reg_t __reserved_3 : 31;
82#else /* __BIG_ENDIAN__ */
83 uint_reg_t __reserved_3 : 31;
84 uint_reg_t l0s_lat : 1;
85 uint_reg_t __reserved_2 : 4;
86 uint_reg_t slot_pwr_scale : 2;
87 uint_reg_t slot_pwr_lim : 8;
88 uint_reg_t __reserved_1 : 2;
89 uint_reg_t rer : 1;
90 uint_reg_t r3 : 1;
91 uint_reg_t r2 : 1;
92 uint_reg_t r1 : 1;
93 uint_reg_t l1_lat : 3;
94 uint_reg_t __reserved_0 : 3;
95 uint_reg_t ext_tag_field_supported : 1;
96 uint_reg_t phantom_function_supported : 2;
97 uint_reg_t mps_sup : 3;
98#endif
99 };
100
101 uint_reg_t word;
102} TRIO_PCIE_RC_DEVICE_CAP_t;
103
104/* Device Control Register. */
105
106__extension__
107typedef union
108{
109 struct
110 {
111#ifndef __BIG_ENDIAN__
112 /* Correctable Error Reporting Enable */
113 uint_reg_t cor_err_ena : 1;
114 /* Non-Fatal Error Reporting Enable */
115 uint_reg_t nf_err_ena : 1;
116 /* Fatal Error Reporting Enable */
117 uint_reg_t fatal_err_ena : 1;
118 /* Unsupported Request Reporting Enable */
119 uint_reg_t ur_ena : 1;
120 /* Relaxed orderring enable */
121 uint_reg_t ro_ena : 1;
122 /* Max Payload Size */
123 uint_reg_t max_payload_size : 3;
124 /* Extended Tag Field Enable */
125 uint_reg_t ext_tag : 1;
126 /* Phantom Function Enable */
127 uint_reg_t ph_fn_ena : 1;
128 /* AUX Power PM Enable */
129 uint_reg_t aux_pm_ena : 1;
130 /* Enable NoSnoop */
131 uint_reg_t no_snoop : 1;
132 /* Max read request size */
133 uint_reg_t max_read_req_sz : 3;
134 /* Reserved. */
135 uint_reg_t __reserved : 49;
136#else /* __BIG_ENDIAN__ */
137 uint_reg_t __reserved : 49;
138 uint_reg_t max_read_req_sz : 3;
139 uint_reg_t no_snoop : 1;
140 uint_reg_t aux_pm_ena : 1;
141 uint_reg_t ph_fn_ena : 1;
142 uint_reg_t ext_tag : 1;
143 uint_reg_t max_payload_size : 3;
144 uint_reg_t ro_ena : 1;
145 uint_reg_t ur_ena : 1;
146 uint_reg_t fatal_err_ena : 1;
147 uint_reg_t nf_err_ena : 1;
148 uint_reg_t cor_err_ena : 1;
149#endif
150 };
151
152 uint_reg_t word;
153} TRIO_PCIE_RC_DEVICE_CONTROL_t;
154#endif /* !defined(__ASSEMBLER__) */
155
156#endif /* !defined(__ARCH_TRIO_PCIE_RC_H__) */
diff --git a/arch/tile/include/arch/trio_pcie_rc_def.h b/arch/tile/include/arch/trio_pcie_rc_def.h
deleted file mode 100644
index 74081a65b6f2..000000000000
--- a/arch/tile/include/arch/trio_pcie_rc_def.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_TRIO_PCIE_RC_DEF_H__
18#define __ARCH_TRIO_PCIE_RC_DEF_H__
19#define TRIO_PCIE_RC_DEVICE_CAP 0x0074
20#define TRIO_PCIE_RC_DEVICE_CONTROL 0x0078
21#define TRIO_PCIE_RC_DEVICE_ID_VEN_ID 0x0000
22#define TRIO_PCIE_RC_DEVICE_ID_VEN_ID__DEV_ID_SHIFT 16
23#define TRIO_PCIE_RC_REVISION_ID 0x0008
24#endif /* !defined(__ARCH_TRIO_PCIE_RC_DEF_H__) */
diff --git a/arch/tile/include/arch/trio_shm.h b/arch/tile/include/arch/trio_shm.h
deleted file mode 100644
index 3382e38245af..000000000000
--- a/arch/tile/include/arch/trio_shm.h
+++ /dev/null
@@ -1,125 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17
18#ifndef __ARCH_TRIO_SHM_H__
19#define __ARCH_TRIO_SHM_H__
20
21#include <arch/abi.h>
22#include <arch/trio_shm_def.h>
23
24#ifndef __ASSEMBLER__
25/**
26 * TRIO DMA Descriptor.
27 * The TRIO DMA descriptor is written by software and consumed by hardware.
28 * It is used to specify the location of transaction data in the IO and Tile
29 * domains.
30 */
31
32__extension__
33typedef union
34{
35 struct
36 {
37 /* Word 0 */
38
39#ifndef __BIG_ENDIAN__
40 /** Tile side virtual address. */
41 int_reg_t va : 42;
42 /**
43 * Encoded size of buffer used on push DMA when C=1:
44 * 0 = 128 bytes
45 * 1 = 256 bytes
46 * 2 = 512 bytes
47 * 3 = 1024 bytes
48 * 4 = 1664 bytes
49 * 5 = 4096 bytes
50 * 6 = 10368 bytes
51 * 7 = 16384 bytes
52 */
53 uint_reg_t bsz : 3;
54 /**
55 * Chaining designation. Always zero for pull DMA
56 * 0 : Unchained buffer pointer
57 * 1 : Chained buffer pointer. Next buffer descriptor (e.g. VA) stored
58 * in 1st 8-bytes in buffer. For chained buffers, first 8-bytes of each
59 * buffer contain the next buffer descriptor formatted exactly like a PDE
60 * buffer descriptor. This allows a chained PDE buffer to be sent using
61 * push DMA.
62 */
63 uint_reg_t c : 1;
64 /**
65 * Notification interrupt will be delivered when the transaction has
66 * completed (all data has been read from or written to the Tile-side
67 * buffer).
68 */
69 uint_reg_t notif : 1;
70 /**
71 * When 0, the XSIZE field specifies the total byte count for the
72 * transaction. When 1, the XSIZE field is encoded as 2^(N+14) for N in
73 * {0..6}:
74 * 0 = 16KB
75 * 1 = 32KB
76 * 2 = 64KB
77 * 3 = 128KB
78 * 4 = 256KB
79 * 5 = 512KB
80 * 6 = 1MB
81 * All other encodings of the XSIZE field are reserved when SMOD=1
82 */
83 uint_reg_t smod : 1;
84 /**
85 * Total number of bytes to move for this transaction. When SMOD=1,
86 * this field is encoded - see SMOD description.
87 */
88 uint_reg_t xsize : 14;
89 /** Reserved. */
90 uint_reg_t __reserved_0 : 1;
91 /**
92 * Generation number. Used to indicate a valid descriptor in ring. When
93 * a new descriptor is written into the ring, software must toggle this
94 * bit. The net effect is that the GEN bit being written into new
95 * descriptors toggles each time the ring tail pointer wraps.
96 */
97 uint_reg_t gen : 1;
98#else /* __BIG_ENDIAN__ */
99 uint_reg_t gen : 1;
100 uint_reg_t __reserved_0 : 1;
101 uint_reg_t xsize : 14;
102 uint_reg_t smod : 1;
103 uint_reg_t notif : 1;
104 uint_reg_t c : 1;
105 uint_reg_t bsz : 3;
106 int_reg_t va : 42;
107#endif
108
109 /* Word 1 */
110
111#ifndef __BIG_ENDIAN__
112 /** IO-side address */
113 uint_reg_t io_address : 64;
114#else /* __BIG_ENDIAN__ */
115 uint_reg_t io_address : 64;
116#endif
117
118 };
119
120 /** Word access */
121 uint_reg_t words[2];
122} TRIO_DMA_DESC_t;
123#endif /* !defined(__ASSEMBLER__) */
124
125#endif /* !defined(__ARCH_TRIO_SHM_H__) */
diff --git a/arch/tile/include/arch/trio_shm_def.h b/arch/tile/include/arch/trio_shm_def.h
deleted file mode 100644
index 72a59c88b06a..000000000000
--- a/arch/tile/include/arch/trio_shm_def.h
+++ /dev/null
@@ -1,19 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_TRIO_SHM_DEF_H__
18#define __ARCH_TRIO_SHM_DEF_H__
19#endif /* !defined(__ARCH_TRIO_SHM_DEF_H__) */
diff --git a/arch/tile/include/arch/uart.h b/arch/tile/include/arch/uart.h
deleted file mode 100644
index 07966970adad..000000000000
--- a/arch/tile/include/arch/uart.h
+++ /dev/null
@@ -1,300 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_UART_H__
18#define __ARCH_UART_H__
19
20#include <arch/abi.h>
21#include <arch/uart_def.h>
22
23#ifndef __ASSEMBLER__
24
25/* Divisor. */
26
27__extension__
28typedef union
29{
30 struct
31 {
32#ifndef __BIG_ENDIAN__
33 /*
34 * Baud Rate Divisor. Desired_baud_rate = REF_CLK frequency / (baud *
35 * 16).
36 * Note: REF_CLK is always 125 MHz, the default
37 * divisor = 68, baud rate = 125M/(68*16) = 115200 baud.
38 */
39 uint_reg_t divisor : 12;
40 /* Reserved. */
41 uint_reg_t __reserved : 52;
42#else /* __BIG_ENDIAN__ */
43 uint_reg_t __reserved : 52;
44 uint_reg_t divisor : 12;
45#endif
46 };
47
48 uint_reg_t word;
49} UART_DIVISOR_t;
50
51/* FIFO Count. */
52
53__extension__
54typedef union
55{
56 struct
57 {
58#ifndef __BIG_ENDIAN__
59 /*
60 * n: n active entries in the receive FIFO (max is 2**8). Each entry has
61 * 8 bits.
62 * 0: no active entry in the receive FIFO (that is empty).
63 */
64 uint_reg_t rfifo_count : 9;
65 /* Reserved. */
66 uint_reg_t __reserved_0 : 7;
67 /*
68 * n: n active entries in the transmit FIFO (max is 2**8). Each entry has
69 * 8 bits.
70 * 0: no active entry in the transmit FIFO (that is empty).
71 */
72 uint_reg_t tfifo_count : 9;
73 /* Reserved. */
74 uint_reg_t __reserved_1 : 7;
75 /*
76 * n: n active entries in the write FIFO (max is 2**2). Each entry has 8
77 * bits.
78 * 0: no active entry in the write FIFO (that is empty).
79 */
80 uint_reg_t wfifo_count : 3;
81 /* Reserved. */
82 uint_reg_t __reserved_2 : 29;
83#else /* __BIG_ENDIAN__ */
84 uint_reg_t __reserved_2 : 29;
85 uint_reg_t wfifo_count : 3;
86 uint_reg_t __reserved_1 : 7;
87 uint_reg_t tfifo_count : 9;
88 uint_reg_t __reserved_0 : 7;
89 uint_reg_t rfifo_count : 9;
90#endif
91 };
92
93 uint_reg_t word;
94} UART_FIFO_COUNT_t;
95
96/* FLAG. */
97
98__extension__
99typedef union
100{
101 struct
102 {
103#ifndef __BIG_ENDIAN__
104 /* Reserved. */
105 uint_reg_t __reserved_0 : 1;
106 /* 1: receive FIFO is empty */
107 uint_reg_t rfifo_empty : 1;
108 /* 1: write FIFO is empty. */
109 uint_reg_t wfifo_empty : 1;
110 /* 1: transmit FIFO is empty. */
111 uint_reg_t tfifo_empty : 1;
112 /* 1: receive FIFO is full. */
113 uint_reg_t rfifo_full : 1;
114 /* 1: write FIFO is full. */
115 uint_reg_t wfifo_full : 1;
116 /* 1: transmit FIFO is full. */
117 uint_reg_t tfifo_full : 1;
118 /* Reserved. */
119 uint_reg_t __reserved_1 : 57;
120#else /* __BIG_ENDIAN__ */
121 uint_reg_t __reserved_1 : 57;
122 uint_reg_t tfifo_full : 1;
123 uint_reg_t wfifo_full : 1;
124 uint_reg_t rfifo_full : 1;
125 uint_reg_t tfifo_empty : 1;
126 uint_reg_t wfifo_empty : 1;
127 uint_reg_t rfifo_empty : 1;
128 uint_reg_t __reserved_0 : 1;
129#endif
130 };
131
132 uint_reg_t word;
133} UART_FLAG_t;
134
135/*
136 * Interrupt Vector Mask.
137 * Each bit in this register corresponds to a specific interrupt. When set,
138 * the associated interrupt will not be dispatched.
139 */
140
141__extension__
142typedef union
143{
144 struct
145 {
146#ifndef __BIG_ENDIAN__
147 /* Read data FIFO read and no data available */
148 uint_reg_t rdat_err : 1;
149 /* Write FIFO was written but it was full */
150 uint_reg_t wdat_err : 1;
151 /* Stop bit not found when current data was received */
152 uint_reg_t frame_err : 1;
153 /* Parity error was detected when current data was received */
154 uint_reg_t parity_err : 1;
155 /* Data was received but the receive FIFO was full */
156 uint_reg_t rfifo_overflow : 1;
157 /*
158 * An almost full event is reached when data is to be written to the
159 * receive FIFO, and the receive FIFO has more than or equal to
160 * BUFFER_THRESHOLD.RFIFO_AFULL bytes.
161 */
162 uint_reg_t rfifo_afull : 1;
163 /* Reserved. */
164 uint_reg_t __reserved_0 : 1;
165 /* An entry in the transmit FIFO was popped */
166 uint_reg_t tfifo_re : 1;
167 /* An entry has been pushed into the receive FIFO */
168 uint_reg_t rfifo_we : 1;
169 /* An entry of the write FIFO has been popped */
170 uint_reg_t wfifo_re : 1;
171 /* Rshim read receive FIFO in protocol mode */
172 uint_reg_t rfifo_err : 1;
173 /*
174 * An almost empty event is reached when data is to be read from the
175 * transmit FIFO, and the transmit FIFO has less than or equal to
176 * BUFFER_THRESHOLD.TFIFO_AEMPTY bytes.
177 */
178 uint_reg_t tfifo_aempty : 1;
179 /* Reserved. */
180 uint_reg_t __reserved_1 : 52;
181#else /* __BIG_ENDIAN__ */
182 uint_reg_t __reserved_1 : 52;
183 uint_reg_t tfifo_aempty : 1;
184 uint_reg_t rfifo_err : 1;
185 uint_reg_t wfifo_re : 1;
186 uint_reg_t rfifo_we : 1;
187 uint_reg_t tfifo_re : 1;
188 uint_reg_t __reserved_0 : 1;
189 uint_reg_t rfifo_afull : 1;
190 uint_reg_t rfifo_overflow : 1;
191 uint_reg_t parity_err : 1;
192 uint_reg_t frame_err : 1;
193 uint_reg_t wdat_err : 1;
194 uint_reg_t rdat_err : 1;
195#endif
196 };
197
198 uint_reg_t word;
199} UART_INTERRUPT_MASK_t;
200
201/*
202 * Interrupt vector, write-one-to-clear.
203 * Each bit in this register corresponds to a specific interrupt. Hardware
204 * sets the bit when the associated condition has occurred. Writing a 1
205 * clears the status bit.
206 */
207
208__extension__
209typedef union
210{
211 struct
212 {
213#ifndef __BIG_ENDIAN__
214 /* Read data FIFO read and no data available */
215 uint_reg_t rdat_err : 1;
216 /* Write FIFO was written but it was full */
217 uint_reg_t wdat_err : 1;
218 /* Stop bit not found when current data was received */
219 uint_reg_t frame_err : 1;
220 /* Parity error was detected when current data was received */
221 uint_reg_t parity_err : 1;
222 /* Data was received but the receive FIFO was full */
223 uint_reg_t rfifo_overflow : 1;
224 /*
225 * Data was received and the receive FIFO is now almost full (more than
226 * BUFFER_THRESHOLD.RFIFO_AFULL bytes in it)
227 */
228 uint_reg_t rfifo_afull : 1;
229 /* Reserved. */
230 uint_reg_t __reserved_0 : 1;
231 /* An entry in the transmit FIFO was popped */
232 uint_reg_t tfifo_re : 1;
233 /* An entry has been pushed into the receive FIFO */
234 uint_reg_t rfifo_we : 1;
235 /* An entry of the write FIFO has been popped */
236 uint_reg_t wfifo_re : 1;
237 /* Rshim read receive FIFO in protocol mode */
238 uint_reg_t rfifo_err : 1;
239 /*
240 * Data was read from the transmit FIFO and now it is almost empty (less
241 * than or equal to BUFFER_THRESHOLD.TFIFO_AEMPTY bytes in it).
242 */
243 uint_reg_t tfifo_aempty : 1;
244 /* Reserved. */
245 uint_reg_t __reserved_1 : 52;
246#else /* __BIG_ENDIAN__ */
247 uint_reg_t __reserved_1 : 52;
248 uint_reg_t tfifo_aempty : 1;
249 uint_reg_t rfifo_err : 1;
250 uint_reg_t wfifo_re : 1;
251 uint_reg_t rfifo_we : 1;
252 uint_reg_t tfifo_re : 1;
253 uint_reg_t __reserved_0 : 1;
254 uint_reg_t rfifo_afull : 1;
255 uint_reg_t rfifo_overflow : 1;
256 uint_reg_t parity_err : 1;
257 uint_reg_t frame_err : 1;
258 uint_reg_t wdat_err : 1;
259 uint_reg_t rdat_err : 1;
260#endif
261 };
262
263 uint_reg_t word;
264} UART_INTERRUPT_STATUS_t;
265
266/* Type. */
267
268__extension__
269typedef union
270{
271 struct
272 {
273#ifndef __BIG_ENDIAN__
274 /* Number of stop bits, rx and tx */
275 uint_reg_t sbits : 1;
276 /* Reserved. */
277 uint_reg_t __reserved_0 : 1;
278 /* Data word size, rx and tx */
279 uint_reg_t dbits : 1;
280 /* Reserved. */
281 uint_reg_t __reserved_1 : 1;
282 /* Parity selection, rx and tx */
283 uint_reg_t ptype : 3;
284 /* Reserved. */
285 uint_reg_t __reserved_2 : 57;
286#else /* __BIG_ENDIAN__ */
287 uint_reg_t __reserved_2 : 57;
288 uint_reg_t ptype : 3;
289 uint_reg_t __reserved_1 : 1;
290 uint_reg_t dbits : 1;
291 uint_reg_t __reserved_0 : 1;
292 uint_reg_t sbits : 1;
293#endif
294 };
295
296 uint_reg_t word;
297} UART_TYPE_t;
298#endif /* !defined(__ASSEMBLER__) */
299
300#endif /* !defined(__ARCH_UART_H__) */
diff --git a/arch/tile/include/arch/uart_def.h b/arch/tile/include/arch/uart_def.h
deleted file mode 100644
index 42bcaf535379..000000000000
--- a/arch/tile/include/arch/uart_def.h
+++ /dev/null
@@ -1,120 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_UART_DEF_H__
18#define __ARCH_UART_DEF_H__
19#define UART_DIVISOR 0x0158
20#define UART_FIFO_COUNT 0x0110
21#define UART_FLAG 0x0108
22#define UART_INTERRUPT_MASK 0x0208
23#define UART_INTERRUPT_MASK__RDAT_ERR_SHIFT 0
24#define UART_INTERRUPT_MASK__RDAT_ERR_WIDTH 1
25#define UART_INTERRUPT_MASK__RDAT_ERR_RESET_VAL 1
26#define UART_INTERRUPT_MASK__RDAT_ERR_RMASK 0x1
27#define UART_INTERRUPT_MASK__RDAT_ERR_MASK 0x1
28#define UART_INTERRUPT_MASK__RDAT_ERR_FIELD 0,0
29#define UART_INTERRUPT_MASK__WDAT_ERR_SHIFT 1
30#define UART_INTERRUPT_MASK__WDAT_ERR_WIDTH 1
31#define UART_INTERRUPT_MASK__WDAT_ERR_RESET_VAL 1
32#define UART_INTERRUPT_MASK__WDAT_ERR_RMASK 0x1
33#define UART_INTERRUPT_MASK__WDAT_ERR_MASK 0x2
34#define UART_INTERRUPT_MASK__WDAT_ERR_FIELD 1,1
35#define UART_INTERRUPT_MASK__FRAME_ERR_SHIFT 2
36#define UART_INTERRUPT_MASK__FRAME_ERR_WIDTH 1
37#define UART_INTERRUPT_MASK__FRAME_ERR_RESET_VAL 1
38#define UART_INTERRUPT_MASK__FRAME_ERR_RMASK 0x1
39#define UART_INTERRUPT_MASK__FRAME_ERR_MASK 0x4
40#define UART_INTERRUPT_MASK__FRAME_ERR_FIELD 2,2
41#define UART_INTERRUPT_MASK__PARITY_ERR_SHIFT 3
42#define UART_INTERRUPT_MASK__PARITY_ERR_WIDTH 1
43#define UART_INTERRUPT_MASK__PARITY_ERR_RESET_VAL 1
44#define UART_INTERRUPT_MASK__PARITY_ERR_RMASK 0x1
45#define UART_INTERRUPT_MASK__PARITY_ERR_MASK 0x8
46#define UART_INTERRUPT_MASK__PARITY_ERR_FIELD 3,3
47#define UART_INTERRUPT_MASK__RFIFO_OVERFLOW_SHIFT 4
48#define UART_INTERRUPT_MASK__RFIFO_OVERFLOW_WIDTH 1
49#define UART_INTERRUPT_MASK__RFIFO_OVERFLOW_RESET_VAL 1
50#define UART_INTERRUPT_MASK__RFIFO_OVERFLOW_RMASK 0x1
51#define UART_INTERRUPT_MASK__RFIFO_OVERFLOW_MASK 0x10
52#define UART_INTERRUPT_MASK__RFIFO_OVERFLOW_FIELD 4,4
53#define UART_INTERRUPT_MASK__RFIFO_AFULL_SHIFT 5
54#define UART_INTERRUPT_MASK__RFIFO_AFULL_WIDTH 1
55#define UART_INTERRUPT_MASK__RFIFO_AFULL_RESET_VAL 1
56#define UART_INTERRUPT_MASK__RFIFO_AFULL_RMASK 0x1
57#define UART_INTERRUPT_MASK__RFIFO_AFULL_MASK 0x20
58#define UART_INTERRUPT_MASK__RFIFO_AFULL_FIELD 5,5
59#define UART_INTERRUPT_MASK__TFIFO_RE_SHIFT 7
60#define UART_INTERRUPT_MASK__TFIFO_RE_WIDTH 1
61#define UART_INTERRUPT_MASK__TFIFO_RE_RESET_VAL 1
62#define UART_INTERRUPT_MASK__TFIFO_RE_RMASK 0x1
63#define UART_INTERRUPT_MASK__TFIFO_RE_MASK 0x80
64#define UART_INTERRUPT_MASK__TFIFO_RE_FIELD 7,7
65#define UART_INTERRUPT_MASK__RFIFO_WE_SHIFT 8
66#define UART_INTERRUPT_MASK__RFIFO_WE_WIDTH 1
67#define UART_INTERRUPT_MASK__RFIFO_WE_RESET_VAL 1
68#define UART_INTERRUPT_MASK__RFIFO_WE_RMASK 0x1
69#define UART_INTERRUPT_MASK__RFIFO_WE_MASK 0x100
70#define UART_INTERRUPT_MASK__RFIFO_WE_FIELD 8,8
71#define UART_INTERRUPT_MASK__WFIFO_RE_SHIFT 9
72#define UART_INTERRUPT_MASK__WFIFO_RE_WIDTH 1
73#define UART_INTERRUPT_MASK__WFIFO_RE_RESET_VAL 1
74#define UART_INTERRUPT_MASK__WFIFO_RE_RMASK 0x1
75#define UART_INTERRUPT_MASK__WFIFO_RE_MASK 0x200
76#define UART_INTERRUPT_MASK__WFIFO_RE_FIELD 9,9
77#define UART_INTERRUPT_MASK__RFIFO_ERR_SHIFT 10
78#define UART_INTERRUPT_MASK__RFIFO_ERR_WIDTH 1
79#define UART_INTERRUPT_MASK__RFIFO_ERR_RESET_VAL 1
80#define UART_INTERRUPT_MASK__RFIFO_ERR_RMASK 0x1
81#define UART_INTERRUPT_MASK__RFIFO_ERR_MASK 0x400
82#define UART_INTERRUPT_MASK__RFIFO_ERR_FIELD 10,10
83#define UART_INTERRUPT_MASK__TFIFO_AEMPTY_SHIFT 11
84#define UART_INTERRUPT_MASK__TFIFO_AEMPTY_WIDTH 1
85#define UART_INTERRUPT_MASK__TFIFO_AEMPTY_RESET_VAL 1
86#define UART_INTERRUPT_MASK__TFIFO_AEMPTY_RMASK 0x1
87#define UART_INTERRUPT_MASK__TFIFO_AEMPTY_MASK 0x800
88#define UART_INTERRUPT_MASK__TFIFO_AEMPTY_FIELD 11,11
89#define UART_INTERRUPT_STATUS 0x0200
90#define UART_RECEIVE_DATA 0x0148
91#define UART_TRANSMIT_DATA 0x0140
92#define UART_TYPE 0x0160
93#define UART_TYPE__SBITS_SHIFT 0
94#define UART_TYPE__SBITS_WIDTH 1
95#define UART_TYPE__SBITS_RESET_VAL 1
96#define UART_TYPE__SBITS_RMASK 0x1
97#define UART_TYPE__SBITS_MASK 0x1
98#define UART_TYPE__SBITS_FIELD 0,0
99#define UART_TYPE__SBITS_VAL_ONE_SBITS 0x0
100#define UART_TYPE__SBITS_VAL_TWO_SBITS 0x1
101#define UART_TYPE__DBITS_SHIFT 2
102#define UART_TYPE__DBITS_WIDTH 1
103#define UART_TYPE__DBITS_RESET_VAL 0
104#define UART_TYPE__DBITS_RMASK 0x1
105#define UART_TYPE__DBITS_MASK 0x4
106#define UART_TYPE__DBITS_FIELD 2,2
107#define UART_TYPE__DBITS_VAL_EIGHT_DBITS 0x0
108#define UART_TYPE__DBITS_VAL_SEVEN_DBITS 0x1
109#define UART_TYPE__PTYPE_SHIFT 4
110#define UART_TYPE__PTYPE_WIDTH 3
111#define UART_TYPE__PTYPE_RESET_VAL 3
112#define UART_TYPE__PTYPE_RMASK 0x7
113#define UART_TYPE__PTYPE_MASK 0x70
114#define UART_TYPE__PTYPE_FIELD 4,6
115#define UART_TYPE__PTYPE_VAL_NONE 0x0
116#define UART_TYPE__PTYPE_VAL_MARK 0x1
117#define UART_TYPE__PTYPE_VAL_SPACE 0x2
118#define UART_TYPE__PTYPE_VAL_EVEN 0x3
119#define UART_TYPE__PTYPE_VAL_ODD 0x4
120#endif /* !defined(__ARCH_UART_DEF_H__) */
diff --git a/arch/tile/include/arch/usb_host.h b/arch/tile/include/arch/usb_host.h
deleted file mode 100644
index d09f32683962..000000000000
--- a/arch/tile/include/arch/usb_host.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_USB_HOST_H__
18#define __ARCH_USB_HOST_H__
19
20#include <arch/abi.h>
21#include <arch/usb_host_def.h>
22
23#ifndef __ASSEMBLER__
24#endif /* !defined(__ASSEMBLER__) */
25
26#endif /* !defined(__ARCH_USB_HOST_H__) */
diff --git a/arch/tile/include/arch/usb_host_def.h b/arch/tile/include/arch/usb_host_def.h
deleted file mode 100644
index aeed7753e8e1..000000000000
--- a/arch/tile/include/arch/usb_host_def.h
+++ /dev/null
@@ -1,19 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Machine-generated file; do not edit. */
16
17#ifndef __ARCH_USB_HOST_DEF_H__
18#define __ARCH_USB_HOST_DEF_H__
19#endif /* !defined(__ARCH_USB_HOST_DEF_H__) */
diff --git a/arch/tile/include/asm/Kbuild b/arch/tile/include/asm/Kbuild
deleted file mode 100644
index 414dfc3a1808..000000000000
--- a/arch/tile/include/asm/Kbuild
+++ /dev/null
@@ -1,18 +0,0 @@
1generic-y += bug.h
2generic-y += bugs.h
3generic-y += emergency-restart.h
4generic-y += exec.h
5generic-y += extable.h
6generic-y += fb.h
7generic-y += hw_irq.h
8generic-y += irq_regs.h
9generic-y += local.h
10generic-y += local64.h
11generic-y += mcs_spinlock.h
12generic-y += mm-arch-hooks.h
13generic-y += parport.h
14generic-y += preempt.h
15generic-y += seccomp.h
16generic-y += serial.h
17generic-y += trace_clock.h
18generic-y += xor.h
diff --git a/arch/tile/include/asm/asm-offsets.h b/arch/tile/include/asm/asm-offsets.h
deleted file mode 100644
index d370ee36a182..000000000000
--- a/arch/tile/include/asm/asm-offsets.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <generated/asm-offsets.h>
diff --git a/arch/tile/include/asm/atomic.h b/arch/tile/include/asm/atomic.h
deleted file mode 100644
index 8dda3c8ff5ab..000000000000
--- a/arch/tile/include/asm/atomic.h
+++ /dev/null
@@ -1,210 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Atomic primitives.
15 */
16
17#ifndef _ASM_TILE_ATOMIC_H
18#define _ASM_TILE_ATOMIC_H
19
20#include <asm/cmpxchg.h>
21
22#ifndef __ASSEMBLY__
23
24#include <linux/compiler.h>
25#include <linux/types.h>
26
27#define ATOMIC_INIT(i) { (i) }
28
29/**
30 * atomic_read - read atomic variable
31 * @v: pointer of type atomic_t
32 *
33 * Atomically reads the value of @v.
34 */
35static inline int atomic_read(const atomic_t *v)
36{
37 return READ_ONCE(v->counter);
38}
39
40/**
41 * atomic_sub_return - subtract integer and return
42 * @v: pointer of type atomic_t
43 * @i: integer value to subtract
44 *
45 * Atomically subtracts @i from @v and returns @v - @i
46 */
47#define atomic_sub_return(i, v) atomic_add_return((int)(-(i)), (v))
48
49#define atomic_fetch_sub(i, v) atomic_fetch_add(-(int)(i), (v))
50
51/**
52 * atomic_sub - subtract integer from atomic variable
53 * @i: integer value to subtract
54 * @v: pointer of type atomic_t
55 *
56 * Atomically subtracts @i from @v.
57 */
58#define atomic_sub(i, v) atomic_add((int)(-(i)), (v))
59
60/**
61 * atomic_sub_and_test - subtract value from variable and test result
62 * @i: integer value to subtract
63 * @v: pointer of type atomic_t
64 *
65 * Atomically subtracts @i from @v and returns true if the result is
66 * zero, or false for all other cases.
67 */
68#define atomic_sub_and_test(i, v) (atomic_sub_return((i), (v)) == 0)
69
70/**
71 * atomic_inc_return - increment memory and return
72 * @v: pointer of type atomic_t
73 *
74 * Atomically increments @v by 1 and returns the new value.
75 */
76#define atomic_inc_return(v) atomic_add_return(1, (v))
77
78/**
79 * atomic_dec_return - decrement memory and return
80 * @v: pointer of type atomic_t
81 *
82 * Atomically decrements @v by 1 and returns the new value.
83 */
84#define atomic_dec_return(v) atomic_sub_return(1, (v))
85
86/**
87 * atomic_inc - increment atomic variable
88 * @v: pointer of type atomic_t
89 *
90 * Atomically increments @v by 1.
91 */
92#define atomic_inc(v) atomic_add(1, (v))
93
94/**
95 * atomic_dec - decrement atomic variable
96 * @v: pointer of type atomic_t
97 *
98 * Atomically decrements @v by 1.
99 */
100#define atomic_dec(v) atomic_sub(1, (v))
101
102/**
103 * atomic_dec_and_test - decrement and test
104 * @v: pointer of type atomic_t
105 *
106 * Atomically decrements @v by 1 and returns true if the result is 0.
107 */
108#define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
109
110/**
111 * atomic_inc_and_test - increment and test
112 * @v: pointer of type atomic_t
113 *
114 * Atomically increments @v by 1 and returns true if the result is 0.
115 */
116#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
117
118/**
119 * atomic_xchg - atomically exchange contents of memory with a new value
120 * @v: pointer of type atomic_t
121 * @i: integer value to store in memory
122 *
123 * Atomically sets @v to @i and returns old @v
124 */
125static inline int atomic_xchg(atomic_t *v, int n)
126{
127 return xchg(&v->counter, n);
128}
129
130/**
131 * atomic_cmpxchg - atomically exchange contents of memory if it matches
132 * @v: pointer of type atomic_t
133 * @o: old value that memory should have
134 * @n: new value to write to memory if it matches
135 *
136 * Atomically checks if @v holds @o and replaces it with @n if so.
137 * Returns the old value at @v.
138 */
139static inline int atomic_cmpxchg(atomic_t *v, int o, int n)
140{
141 return cmpxchg(&v->counter, o, n);
142}
143
144/**
145 * atomic_add_negative - add and test if negative
146 * @v: pointer of type atomic_t
147 * @i: integer value to add
148 *
149 * Atomically adds @i to @v and returns true if the result is
150 * negative, or false when result is greater than or equal to zero.
151 */
152#define atomic_add_negative(i, v) (atomic_add_return((i), (v)) < 0)
153
154#endif /* __ASSEMBLY__ */
155
156#ifndef __tilegx__
157#include <asm/atomic_32.h>
158#else
159#include <asm/atomic_64.h>
160#endif
161
162#ifndef __ASSEMBLY__
163
164/**
165 * atomic64_xchg - atomically exchange contents of memory with a new value
166 * @v: pointer of type atomic64_t
167 * @i: integer value to store in memory
168 *
169 * Atomically sets @v to @i and returns old @v
170 */
171static inline long long atomic64_xchg(atomic64_t *v, long long n)
172{
173 return xchg64(&v->counter, n);
174}
175
176/**
177 * atomic64_cmpxchg - atomically exchange contents of memory if it matches
178 * @v: pointer of type atomic64_t
179 * @o: old value that memory should have
180 * @n: new value to write to memory if it matches
181 *
182 * Atomically checks if @v holds @o and replaces it with @n if so.
183 * Returns the old value at @v.
184 */
185static inline long long atomic64_cmpxchg(atomic64_t *v, long long o,
186 long long n)
187{
188 return cmpxchg64(&v->counter, o, n);
189}
190
191static inline long long atomic64_dec_if_positive(atomic64_t *v)
192{
193 long long c, old, dec;
194
195 c = atomic64_read(v);
196 for (;;) {
197 dec = c - 1;
198 if (unlikely(dec < 0))
199 break;
200 old = atomic64_cmpxchg((v), c, dec);
201 if (likely(old == c))
202 break;
203 c = old;
204 }
205 return dec;
206}
207
208#endif /* __ASSEMBLY__ */
209
210#endif /* _ASM_TILE_ATOMIC_H */
diff --git a/arch/tile/include/asm/atomic_32.h b/arch/tile/include/asm/atomic_32.h
deleted file mode 100644
index 53a423e7cb92..000000000000
--- a/arch/tile/include/asm/atomic_32.h
+++ /dev/null
@@ -1,297 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Do not include directly; use <linux/atomic.h>.
15 */
16
17#ifndef _ASM_TILE_ATOMIC_32_H
18#define _ASM_TILE_ATOMIC_32_H
19
20#include <asm/barrier.h>
21#include <arch/chip.h>
22
23#ifndef __ASSEMBLY__
24
25/**
26 * atomic_add - add integer to atomic variable
27 * @i: integer value to add
28 * @v: pointer of type atomic_t
29 *
30 * Atomically adds @i to @v.
31 */
32static inline void atomic_add(int i, atomic_t *v)
33{
34 _atomic_xchg_add(&v->counter, i);
35}
36
37#define ATOMIC_OPS(op) \
38unsigned long _atomic_fetch_##op(volatile unsigned long *p, unsigned long mask); \
39static inline void atomic_##op(int i, atomic_t *v) \
40{ \
41 _atomic_fetch_##op((unsigned long *)&v->counter, i); \
42} \
43static inline int atomic_fetch_##op(int i, atomic_t *v) \
44{ \
45 smp_mb(); \
46 return _atomic_fetch_##op((unsigned long *)&v->counter, i); \
47}
48
49ATOMIC_OPS(and)
50ATOMIC_OPS(or)
51ATOMIC_OPS(xor)
52
53#undef ATOMIC_OPS
54
55static inline int atomic_fetch_add(int i, atomic_t *v)
56{
57 smp_mb();
58 return _atomic_xchg_add(&v->counter, i);
59}
60
61/**
62 * atomic_add_return - add integer and return
63 * @v: pointer of type atomic_t
64 * @i: integer value to add
65 *
66 * Atomically adds @i to @v and returns @i + @v
67 */
68static inline int atomic_add_return(int i, atomic_t *v)
69{
70 smp_mb(); /* barrier for proper semantics */
71 return _atomic_xchg_add(&v->counter, i) + i;
72}
73
74/**
75 * __atomic_add_unless - add unless the number is already a given value
76 * @v: pointer of type atomic_t
77 * @a: the amount to add to v...
78 * @u: ...unless v is equal to u.
79 *
80 * Atomically adds @a to @v, so long as @v was not already @u.
81 * Returns the old value of @v.
82 */
83static inline int __atomic_add_unless(atomic_t *v, int a, int u)
84{
85 smp_mb(); /* barrier for proper semantics */
86 return _atomic_xchg_add_unless(&v->counter, a, u);
87}
88
89/**
90 * atomic_set - set atomic variable
91 * @v: pointer of type atomic_t
92 * @i: required value
93 *
94 * Atomically sets the value of @v to @i.
95 *
96 * atomic_set() can't be just a raw store, since it would be lost if it
97 * fell between the load and store of one of the other atomic ops.
98 */
99static inline void atomic_set(atomic_t *v, int n)
100{
101 _atomic_xchg(&v->counter, n);
102}
103
104#define atomic_set_release(v, i) atomic_set((v), (i))
105
106/* A 64bit atomic type */
107
108typedef struct {
109 long long counter;
110} atomic64_t;
111
112#define ATOMIC64_INIT(val) { (val) }
113
114/**
115 * atomic64_read - read atomic variable
116 * @v: pointer of type atomic64_t
117 *
118 * Atomically reads the value of @v.
119 */
120static inline long long atomic64_read(const atomic64_t *v)
121{
122 /*
123 * Requires an atomic op to read both 32-bit parts consistently.
124 * Casting away const is safe since the atomic support routines
125 * do not write to memory if the value has not been modified.
126 */
127 return _atomic64_xchg_add((long long *)&v->counter, 0);
128}
129
130/**
131 * atomic64_add - add integer to atomic variable
132 * @i: integer value to add
133 * @v: pointer of type atomic64_t
134 *
135 * Atomically adds @i to @v.
136 */
137static inline void atomic64_add(long long i, atomic64_t *v)
138{
139 _atomic64_xchg_add(&v->counter, i);
140}
141
142#define ATOMIC64_OPS(op) \
143long long _atomic64_fetch_##op(long long *v, long long n); \
144static inline void atomic64_##op(long long i, atomic64_t *v) \
145{ \
146 _atomic64_fetch_##op(&v->counter, i); \
147} \
148static inline long long atomic64_fetch_##op(long long i, atomic64_t *v) \
149{ \
150 smp_mb(); \
151 return _atomic64_fetch_##op(&v->counter, i); \
152}
153
154ATOMIC64_OPS(and)
155ATOMIC64_OPS(or)
156ATOMIC64_OPS(xor)
157
158#undef ATOMIC64_OPS
159
160static inline long long atomic64_fetch_add(long long i, atomic64_t *v)
161{
162 smp_mb();
163 return _atomic64_xchg_add(&v->counter, i);
164}
165
166/**
167 * atomic64_add_return - add integer and return
168 * @v: pointer of type atomic64_t
169 * @i: integer value to add
170 *
171 * Atomically adds @i to @v and returns @i + @v
172 */
173static inline long long atomic64_add_return(long long i, atomic64_t *v)
174{
175 smp_mb(); /* barrier for proper semantics */
176 return _atomic64_xchg_add(&v->counter, i) + i;
177}
178
179/**
180 * atomic64_add_unless - add unless the number is already a given value
181 * @v: pointer of type atomic64_t
182 * @a: the amount to add to v...
183 * @u: ...unless v is equal to u.
184 *
185 * Atomically adds @a to @v, so long as @v was not already @u.
186 * Returns non-zero if @v was not @u, and zero otherwise.
187 */
188static inline long long atomic64_add_unless(atomic64_t *v, long long a,
189 long long u)
190{
191 smp_mb(); /* barrier for proper semantics */
192 return _atomic64_xchg_add_unless(&v->counter, a, u) != u;
193}
194
195/**
196 * atomic64_set - set atomic variable
197 * @v: pointer of type atomic64_t
198 * @i: required value
199 *
200 * Atomically sets the value of @v to @i.
201 *
202 * atomic64_set() can't be just a raw store, since it would be lost if it
203 * fell between the load and store of one of the other atomic ops.
204 */
205static inline void atomic64_set(atomic64_t *v, long long n)
206{
207 _atomic64_xchg(&v->counter, n);
208}
209
210#define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
211#define atomic64_inc(v) atomic64_add(1LL, (v))
212#define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
213#define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
214#define atomic64_sub_return(i, v) atomic64_add_return(-(i), (v))
215#define atomic64_fetch_sub(i, v) atomic64_fetch_add(-(i), (v))
216#define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
217#define atomic64_sub(i, v) atomic64_add(-(i), (v))
218#define atomic64_dec(v) atomic64_sub(1LL, (v))
219#define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
220#define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
221#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
222
223#endif /* !__ASSEMBLY__ */
224
225/*
226 * Internal definitions only beyond this point.
227 */
228
229/*
230 * Number of atomic locks in atomic_locks[]. Must be a power of two.
231 * There is no reason for more than PAGE_SIZE / 8 entries, since that
232 * is the maximum number of pointer bits we can use to index this.
233 * And we cannot have more than PAGE_SIZE / 4, since this has to
234 * fit on a single page and each entry takes 4 bytes.
235 */
236#define ATOMIC_HASH_SHIFT (PAGE_SHIFT - 3)
237#define ATOMIC_HASH_SIZE (1 << ATOMIC_HASH_SHIFT)
238
239#ifndef __ASSEMBLY__
240extern int atomic_locks[];
241#endif
242
243/*
244 * All the code that may fault while holding an atomic lock must
245 * place the pointer to the lock in ATOMIC_LOCK_REG so the fault code
246 * can correctly release and reacquire the lock. Note that we
247 * mention the register number in a comment in "lib/atomic_asm.S" to help
248 * assembly coders from using this register by mistake, so if it
249 * is changed here, change that comment as well.
250 */
251#define ATOMIC_LOCK_REG 20
252#define ATOMIC_LOCK_REG_NAME r20
253
254#ifndef __ASSEMBLY__
255/* Called from setup to initialize a hash table to point to per_cpu locks. */
256void __init_atomic_per_cpu(void);
257
258#ifdef CONFIG_SMP
259/* Support releasing the atomic lock in do_page_fault_ics(). */
260void __atomic_fault_unlock(int *lock_ptr);
261#endif
262
263/* Return a pointer to the lock for the given address. */
264int *__atomic_hashed_lock(volatile void *v);
265
266/* Private helper routines in lib/atomic_asm_32.S */
267struct __get_user {
268 unsigned long val;
269 int err;
270};
271extern struct __get_user __atomic32_cmpxchg(volatile int *p,
272 int *lock, int o, int n);
273extern struct __get_user __atomic32_xchg(volatile int *p, int *lock, int n);
274extern struct __get_user __atomic32_xchg_add(volatile int *p, int *lock, int n);
275extern struct __get_user __atomic32_xchg_add_unless(volatile int *p,
276 int *lock, int o, int n);
277extern struct __get_user __atomic32_fetch_or(volatile int *p, int *lock, int n);
278extern struct __get_user __atomic32_fetch_and(volatile int *p, int *lock, int n);
279extern struct __get_user __atomic32_fetch_andn(volatile int *p, int *lock, int n);
280extern struct __get_user __atomic32_fetch_xor(volatile int *p, int *lock, int n);
281extern long long __atomic64_cmpxchg(volatile long long *p, int *lock,
282 long long o, long long n);
283extern long long __atomic64_xchg(volatile long long *p, int *lock, long long n);
284extern long long __atomic64_xchg_add(volatile long long *p, int *lock,
285 long long n);
286extern long long __atomic64_xchg_add_unless(volatile long long *p,
287 int *lock, long long o, long long n);
288extern long long __atomic64_fetch_and(volatile long long *p, int *lock, long long n);
289extern long long __atomic64_fetch_or(volatile long long *p, int *lock, long long n);
290extern long long __atomic64_fetch_xor(volatile long long *p, int *lock, long long n);
291
292/* Return failure from the atomic wrappers. */
293struct __get_user __atomic_bad_address(int __user *addr);
294
295#endif /* !__ASSEMBLY__ */
296
297#endif /* _ASM_TILE_ATOMIC_32_H */
diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
deleted file mode 100644
index 4cefa0c9fd81..000000000000
--- a/arch/tile/include/asm/atomic_64.h
+++ /dev/null
@@ -1,200 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Do not include directly; use <linux/atomic.h>.
15 */
16
17#ifndef _ASM_TILE_ATOMIC_64_H
18#define _ASM_TILE_ATOMIC_64_H
19
20#ifndef __ASSEMBLY__
21
22#include <asm/barrier.h>
23#include <arch/spr_def.h>
24
25/* First, the 32-bit atomic ops that are "real" on our 64-bit platform. */
26
27#define atomic_set(v, i) WRITE_ONCE((v)->counter, (i))
28
29/*
30 * The smp_mb() operations throughout are to support the fact that
31 * Linux requires memory barriers before and after the operation,
32 * on any routine which updates memory and returns a value.
33 */
34
35/*
36 * Note a subtlety of the locking here. We are required to provide a
37 * full memory barrier before and after the operation. However, we
38 * only provide an explicit mb before the operation. After the
39 * operation, we use barrier() to get a full mb for free, because:
40 *
41 * (1) The barrier directive to the compiler prohibits any instructions
42 * being statically hoisted before the barrier;
43 * (2) the microarchitecture will not issue any further instructions
44 * until the fetchadd result is available for the "+ i" add instruction;
45 * (3) the smb_mb before the fetchadd ensures that no other memory
46 * operations are in flight at this point.
47 */
48static inline int atomic_add_return(int i, atomic_t *v)
49{
50 int val;
51 smp_mb(); /* barrier for proper semantics */
52 val = __insn_fetchadd4((void *)&v->counter, i) + i;
53 barrier(); /* equivalent to smp_mb(); see block comment above */
54 return val;
55}
56
57#define ATOMIC_OPS(op) \
58static inline int atomic_fetch_##op(int i, atomic_t *v) \
59{ \
60 int val; \
61 smp_mb(); \
62 val = __insn_fetch##op##4((void *)&v->counter, i); \
63 smp_mb(); \
64 return val; \
65} \
66static inline void atomic_##op(int i, atomic_t *v) \
67{ \
68 __insn_fetch##op##4((void *)&v->counter, i); \
69}
70
71ATOMIC_OPS(add)
72ATOMIC_OPS(and)
73ATOMIC_OPS(or)
74
75#undef ATOMIC_OPS
76
77static inline int atomic_fetch_xor(int i, atomic_t *v)
78{
79 int guess, oldval = v->counter;
80 smp_mb();
81 do {
82 guess = oldval;
83 __insn_mtspr(SPR_CMPEXCH_VALUE, guess);
84 oldval = __insn_cmpexch4(&v->counter, guess ^ i);
85 } while (guess != oldval);
86 smp_mb();
87 return oldval;
88}
89
90static inline void atomic_xor(int i, atomic_t *v)
91{
92 int guess, oldval = v->counter;
93 do {
94 guess = oldval;
95 __insn_mtspr(SPR_CMPEXCH_VALUE, guess);
96 oldval = __insn_cmpexch4(&v->counter, guess ^ i);
97 } while (guess != oldval);
98}
99
100static inline int __atomic_add_unless(atomic_t *v, int a, int u)
101{
102 int guess, oldval = v->counter;
103 do {
104 if (oldval == u)
105 break;
106 guess = oldval;
107 oldval = cmpxchg(&v->counter, guess, guess + a);
108 } while (guess != oldval);
109 return oldval;
110}
111
112/* Now the true 64-bit operations. */
113
114#define ATOMIC64_INIT(i) { (i) }
115
116#define atomic64_read(v) READ_ONCE((v)->counter)
117#define atomic64_set(v, i) WRITE_ONCE((v)->counter, (i))
118
119static inline long atomic64_add_return(long i, atomic64_t *v)
120{
121 int val;
122 smp_mb(); /* barrier for proper semantics */
123 val = __insn_fetchadd((void *)&v->counter, i) + i;
124 barrier(); /* equivalent to smp_mb; see atomic_add_return() */
125 return val;
126}
127
128#define ATOMIC64_OPS(op) \
129static inline long atomic64_fetch_##op(long i, atomic64_t *v) \
130{ \
131 long val; \
132 smp_mb(); \
133 val = __insn_fetch##op((void *)&v->counter, i); \
134 smp_mb(); \
135 return val; \
136} \
137static inline void atomic64_##op(long i, atomic64_t *v) \
138{ \
139 __insn_fetch##op((void *)&v->counter, i); \
140}
141
142ATOMIC64_OPS(add)
143ATOMIC64_OPS(and)
144ATOMIC64_OPS(or)
145
146#undef ATOMIC64_OPS
147
148static inline long atomic64_fetch_xor(long i, atomic64_t *v)
149{
150 long guess, oldval = v->counter;
151 smp_mb();
152 do {
153 guess = oldval;
154 __insn_mtspr(SPR_CMPEXCH_VALUE, guess);
155 oldval = __insn_cmpexch(&v->counter, guess ^ i);
156 } while (guess != oldval);
157 smp_mb();
158 return oldval;
159}
160
161static inline void atomic64_xor(long i, atomic64_t *v)
162{
163 long guess, oldval = v->counter;
164 do {
165 guess = oldval;
166 __insn_mtspr(SPR_CMPEXCH_VALUE, guess);
167 oldval = __insn_cmpexch(&v->counter, guess ^ i);
168 } while (guess != oldval);
169}
170
171static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
172{
173 long guess, oldval = v->counter;
174 do {
175 if (oldval == u)
176 break;
177 guess = oldval;
178 oldval = cmpxchg(&v->counter, guess, guess + a);
179 } while (guess != oldval);
180 return oldval != u;
181}
182
183#define atomic64_sub_return(i, v) atomic64_add_return(-(i), (v))
184#define atomic64_fetch_sub(i, v) atomic64_fetch_add(-(i), (v))
185#define atomic64_sub(i, v) atomic64_add(-(i), (v))
186#define atomic64_inc_return(v) atomic64_add_return(1, (v))
187#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
188#define atomic64_inc(v) atomic64_add(1, (v))
189#define atomic64_dec(v) atomic64_sub(1, (v))
190
191#define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
192#define atomic64_dec_and_test(v) (atomic64_dec_return(v) == 0)
193#define atomic64_sub_and_test(i, v) (atomic64_sub_return((i), (v)) == 0)
194#define atomic64_add_negative(i, v) (atomic64_add_return((i), (v)) < 0)
195
196#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
197
198#endif /* !__ASSEMBLY__ */
199
200#endif /* _ASM_TILE_ATOMIC_64_H */
diff --git a/arch/tile/include/asm/backtrace.h b/arch/tile/include/asm/backtrace.h
deleted file mode 100644
index bd5399a69edf..000000000000
--- a/arch/tile/include/asm/backtrace.h
+++ /dev/null
@@ -1,162 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_BACKTRACE_H
16#define _ASM_TILE_BACKTRACE_H
17
18#include <linux/types.h>
19
20/* Reads 'size' bytes from 'address' and writes the data to 'result'.
21 * Returns true if successful, else false (e.g. memory not readable).
22 */
23typedef bool (*BacktraceMemoryReader)(void *result,
24 unsigned long address,
25 unsigned int size,
26 void *extra);
27
28typedef struct {
29 /* Current PC. */
30 unsigned long pc;
31
32 /* Current stack pointer value. */
33 unsigned long sp;
34
35 /* Current frame pointer value (i.e. caller's stack pointer) */
36 unsigned long fp;
37
38 /* Internal use only: caller's PC for first frame. */
39 unsigned long initial_frame_caller_pc;
40
41 /* Internal use only: callback to read memory. */
42 BacktraceMemoryReader read_memory_func;
43
44 /* Internal use only: arbitrary argument to read_memory_func. */
45 void *read_memory_func_extra;
46
47} BacktraceIterator;
48
49
50typedef enum {
51
52 /* We have no idea what the caller's pc is. */
53 PC_LOC_UNKNOWN,
54
55 /* The caller's pc is currently in lr. */
56 PC_LOC_IN_LR,
57
58 /* The caller's pc can be found by dereferencing the caller's sp. */
59 PC_LOC_ON_STACK
60
61} CallerPCLocation;
62
63
64typedef enum {
65
66 /* We have no idea what the caller's sp is. */
67 SP_LOC_UNKNOWN,
68
69 /* The caller's sp is currently in r52. */
70 SP_LOC_IN_R52,
71
72 /* The caller's sp can be found by adding a certain constant
73 * to the current value of sp.
74 */
75 SP_LOC_OFFSET
76
77} CallerSPLocation;
78
79
80/* Bit values ORed into CALLER_* values for info ops. */
81enum {
82 /* Setting the low bit on any of these values means the info op
83 * applies only to one bundle ago.
84 */
85 ONE_BUNDLE_AGO_FLAG = 1,
86
87 /* Setting this bit on a CALLER_SP_* value means the PC is in LR.
88 * If not set, PC is on the stack.
89 */
90 PC_IN_LR_FLAG = 2,
91
92 /* This many of the low bits of a CALLER_SP_* value are for the
93 * flag bits above.
94 */
95 NUM_INFO_OP_FLAGS = 2,
96
97 /* We cannot have one in the memory pipe so this is the maximum. */
98 MAX_INFO_OPS_PER_BUNDLE = 2
99};
100
101
102/* Internal constants used to define 'info' operands. */
103enum {
104 /* 0 and 1 are reserved, as are all negative numbers. */
105
106 CALLER_UNKNOWN_BASE = 2,
107
108 CALLER_SP_IN_R52_BASE = 4,
109
110 CALLER_SP_OFFSET_BASE = 8,
111};
112
113
114/* Current backtracer state describing where it thinks the caller is. */
115typedef struct {
116 /*
117 * Public fields
118 */
119
120 /* How do we find the caller's PC? */
121 CallerPCLocation pc_location : 8;
122
123 /* How do we find the caller's SP? */
124 CallerSPLocation sp_location : 8;
125
126 /* If sp_location == SP_LOC_OFFSET, then caller_sp == sp +
127 * loc->sp_offset. Else this field is undefined.
128 */
129 uint16_t sp_offset;
130
131 /* In the most recently visited bundle a terminating bundle? */
132 bool at_terminating_bundle;
133
134 /*
135 * Private fields
136 */
137
138 /* Will the forward scanner see someone clobbering sp
139 * (i.e. changing it with something other than addi sp, sp, N?)
140 */
141 bool sp_clobber_follows;
142
143 /* Operand to next "visible" info op (no more than one bundle past
144 * the next terminating bundle), or -32768 if none.
145 */
146 int16_t next_info_operand;
147
148 /* Is the info of in next_info_op in the very next bundle? */
149 bool is_next_info_operand_adjacent;
150
151} CallerLocation;
152
153extern void backtrace_init(BacktraceIterator *state,
154 BacktraceMemoryReader read_memory_func,
155 void *read_memory_func_extra,
156 unsigned long pc, unsigned long lr,
157 unsigned long sp, unsigned long r52);
158
159
160extern bool backtrace_next(BacktraceIterator *state);
161
162#endif /* _ASM_TILE_BACKTRACE_H */
diff --git a/arch/tile/include/asm/barrier.h b/arch/tile/include/asm/barrier.h
deleted file mode 100644
index 4c419ab95ab7..000000000000
--- a/arch/tile/include/asm/barrier.h
+++ /dev/null
@@ -1,100 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_BARRIER_H
16#define _ASM_TILE_BARRIER_H
17
18#ifndef __ASSEMBLY__
19
20#include <linux/types.h>
21#include <arch/chip.h>
22#include <arch/spr_def.h>
23#include <asm/timex.h>
24
25#define __sync() __insn_mf()
26
27#include <hv/syscall_public.h>
28/*
29 * Issue an uncacheable load to each memory controller, then
30 * wait until those loads have completed.
31 */
32static inline void __mb_incoherent(void)
33{
34 long clobber_r10;
35 asm volatile("swint2"
36 : "=R10" (clobber_r10)
37 : "R10" (HV_SYS_fence_incoherent)
38 : "r0", "r1", "r2", "r3", "r4",
39 "r5", "r6", "r7", "r8", "r9",
40 "r11", "r12", "r13", "r14",
41 "r15", "r16", "r17", "r18", "r19",
42 "r20", "r21", "r22", "r23", "r24",
43 "r25", "r26", "r27", "r28", "r29");
44}
45
46/* Fence to guarantee visibility of stores to incoherent memory. */
47static inline void
48mb_incoherent(void)
49{
50 __insn_mf();
51
52 {
53#if CHIP_HAS_TILE_WRITE_PENDING()
54 const unsigned long WRITE_TIMEOUT_CYCLES = 400;
55 unsigned long start = get_cycles_low();
56 do {
57 if (__insn_mfspr(SPR_TILE_WRITE_PENDING) == 0)
58 return;
59 } while ((get_cycles_low() - start) < WRITE_TIMEOUT_CYCLES);
60#endif /* CHIP_HAS_TILE_WRITE_PENDING() */
61 (void) __mb_incoherent();
62 }
63}
64
65#define fast_wmb() __sync()
66#define fast_rmb() __sync()
67#define fast_mb() __sync()
68#define fast_iob() mb_incoherent()
69
70#define wmb() fast_wmb()
71#define rmb() fast_rmb()
72#define mb() fast_mb()
73#define iob() fast_iob()
74
75#ifndef __tilegx__ /* 32 bit */
76/*
77 * We need to barrier before modifying the word, since the _atomic_xxx()
78 * routines just tns the lock and then read/modify/write of the word.
79 * But after the word is updated, the routine issues an "mf" before returning,
80 * and since it's a function call, we don't even need a compiler barrier.
81 */
82#define __smp_mb__before_atomic() __smp_mb()
83#define __smp_mb__after_atomic() do { } while (0)
84#define smp_mb__after_atomic() __smp_mb__after_atomic()
85#else /* 64 bit */
86#define __smp_mb__before_atomic() __smp_mb()
87#define __smp_mb__after_atomic() __smp_mb()
88#endif
89
90/*
91 * The TILE architecture does not do speculative reads; this ensures
92 * that a control dependency also orders against loads and already provides
93 * a LOAD->{LOAD,STORE} order and can forgo the additional RMB.
94 */
95#define smp_acquire__after_ctrl_dep() barrier()
96
97#include <asm-generic/barrier.h>
98
99#endif /* !__ASSEMBLY__ */
100#endif /* _ASM_TILE_BARRIER_H */
diff --git a/arch/tile/include/asm/bitops.h b/arch/tile/include/asm/bitops.h
deleted file mode 100644
index 20caa346ac06..000000000000
--- a/arch/tile/include/asm/bitops.h
+++ /dev/null
@@ -1,94 +0,0 @@
1/*
2 * Copyright 1992, Linus Torvalds.
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_BITOPS_H
17#define _ASM_TILE_BITOPS_H
18
19#include <linux/types.h>
20#include <asm/barrier.h>
21
22#ifndef _LINUX_BITOPS_H
23#error only <linux/bitops.h> can be included directly
24#endif
25
26#ifdef __tilegx__
27#include <asm/bitops_64.h>
28#else
29#include <asm/bitops_32.h>
30#endif
31
32/**
33 * ffz - find first zero bit in word
34 * @word: The word to search
35 *
36 * Undefined if no zero exists, so code should check against ~0UL first.
37 */
38static inline unsigned long ffz(unsigned long word)
39{
40 return __builtin_ctzl(~word);
41}
42
43static inline int fls64(__u64 w)
44{
45 return (sizeof(__u64) * 8) - __builtin_clzll(w);
46}
47
48/**
49 * fls - find last set bit in word
50 * @x: the word to search
51 *
52 * This is defined in a similar way as the libc and compiler builtin
53 * ffs, but returns the position of the most significant set bit.
54 *
55 * fls(value) returns 0 if value is 0 or the position of the last
56 * set bit if value is nonzero. The last (most significant) bit is
57 * at position 32.
58 */
59static inline int fls(int x)
60{
61 return fls64((unsigned int) x);
62}
63
64static inline unsigned int __arch_hweight32(unsigned int w)
65{
66 return __builtin_popcount(w);
67}
68
69static inline unsigned int __arch_hweight16(unsigned int w)
70{
71 return __builtin_popcount(w & 0xffff);
72}
73
74static inline unsigned int __arch_hweight8(unsigned int w)
75{
76 return __builtin_popcount(w & 0xff);
77}
78
79static inline unsigned long __arch_hweight64(__u64 w)
80{
81 return __builtin_popcountll(w);
82}
83
84#include <asm-generic/bitops/builtin-__ffs.h>
85#include <asm-generic/bitops/builtin-__fls.h>
86#include <asm-generic/bitops/builtin-ffs.h>
87#include <asm-generic/bitops/const_hweight.h>
88#include <asm-generic/bitops/lock.h>
89#include <asm-generic/bitops/find.h>
90#include <asm-generic/bitops/sched.h>
91#include <asm-generic/bitops/non-atomic.h>
92#include <asm-generic/bitops/le.h>
93
94#endif /* _ASM_TILE_BITOPS_H */
diff --git a/arch/tile/include/asm/bitops_32.h b/arch/tile/include/asm/bitops_32.h
deleted file mode 100644
index d1406a95f6b7..000000000000
--- a/arch/tile/include/asm/bitops_32.h
+++ /dev/null
@@ -1,126 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_BITOPS_32_H
16#define _ASM_TILE_BITOPS_32_H
17
18#include <linux/compiler.h>
19#include <asm/barrier.h>
20
21/* Tile-specific routines to support <asm/bitops.h>. */
22unsigned long _atomic_fetch_or(volatile unsigned long *p, unsigned long mask);
23unsigned long _atomic_fetch_andn(volatile unsigned long *p, unsigned long mask);
24unsigned long _atomic_fetch_xor(volatile unsigned long *p, unsigned long mask);
25
26/**
27 * set_bit - Atomically set a bit in memory
28 * @nr: the bit to set
29 * @addr: the address to start counting from
30 *
31 * This function is atomic and may not be reordered.
32 * See __set_bit() if you do not require the atomic guarantees.
33 * Note that @nr may be almost arbitrarily large; this function is not
34 * restricted to acting on a single-word quantity.
35 */
36static inline void set_bit(unsigned nr, volatile unsigned long *addr)
37{
38 _atomic_fetch_or(addr + BIT_WORD(nr), BIT_MASK(nr));
39}
40
41/**
42 * clear_bit - Clears a bit in memory
43 * @nr: Bit to clear
44 * @addr: Address to start counting from
45 *
46 * clear_bit() is atomic and may not be reordered.
47 * See __clear_bit() if you do not require the atomic guarantees.
48 * Note that @nr may be almost arbitrarily large; this function is not
49 * restricted to acting on a single-word quantity.
50 *
51 * clear_bit() may not contain a memory barrier, so if it is used for
52 * locking purposes, you should call smp_mb__before_atomic() and/or
53 * smp_mb__after_atomic() to ensure changes are visible on other cpus.
54 */
55static inline void clear_bit(unsigned nr, volatile unsigned long *addr)
56{
57 _atomic_fetch_andn(addr + BIT_WORD(nr), BIT_MASK(nr));
58}
59
60/**
61 * change_bit - Toggle a bit in memory
62 * @nr: Bit to change
63 * @addr: Address to start counting from
64 *
65 * change_bit() is atomic and may not be reordered.
66 * See __change_bit() if you do not require the atomic guarantees.
67 * Note that @nr may be almost arbitrarily large; this function is not
68 * restricted to acting on a single-word quantity.
69 */
70static inline void change_bit(unsigned nr, volatile unsigned long *addr)
71{
72 _atomic_fetch_xor(addr + BIT_WORD(nr), BIT_MASK(nr));
73}
74
75/**
76 * test_and_set_bit - Set a bit and return its old value
77 * @nr: Bit to set
78 * @addr: Address to count from
79 *
80 * This operation is atomic and cannot be reordered.
81 * It also implies a memory barrier.
82 */
83static inline int test_and_set_bit(unsigned nr, volatile unsigned long *addr)
84{
85 unsigned long mask = BIT_MASK(nr);
86 addr += BIT_WORD(nr);
87 smp_mb(); /* barrier for proper semantics */
88 return (_atomic_fetch_or(addr, mask) & mask) != 0;
89}
90
91/**
92 * test_and_clear_bit - Clear a bit and return its old value
93 * @nr: Bit to clear
94 * @addr: Address to count from
95 *
96 * This operation is atomic and cannot be reordered.
97 * It also implies a memory barrier.
98 */
99static inline int test_and_clear_bit(unsigned nr, volatile unsigned long *addr)
100{
101 unsigned long mask = BIT_MASK(nr);
102 addr += BIT_WORD(nr);
103 smp_mb(); /* barrier for proper semantics */
104 return (_atomic_fetch_andn(addr, mask) & mask) != 0;
105}
106
107/**
108 * test_and_change_bit - Change a bit and return its old value
109 * @nr: Bit to change
110 * @addr: Address to count from
111 *
112 * This operation is atomic and cannot be reordered.
113 * It also implies a memory barrier.
114 */
115static inline int test_and_change_bit(unsigned nr,
116 volatile unsigned long *addr)
117{
118 unsigned long mask = BIT_MASK(nr);
119 addr += BIT_WORD(nr);
120 smp_mb(); /* barrier for proper semantics */
121 return (_atomic_fetch_xor(addr, mask) & mask) != 0;
122}
123
124#include <asm-generic/bitops/ext2-atomic.h>
125
126#endif /* _ASM_TILE_BITOPS_32_H */
diff --git a/arch/tile/include/asm/bitops_64.h b/arch/tile/include/asm/bitops_64.h
deleted file mode 100644
index bb1a29221fcd..000000000000
--- a/arch/tile/include/asm/bitops_64.h
+++ /dev/null
@@ -1,95 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_BITOPS_64_H
16#define _ASM_TILE_BITOPS_64_H
17
18#include <linux/compiler.h>
19#include <asm/cmpxchg.h>
20
21/* See <asm/bitops.h> for API comments. */
22
23static inline void set_bit(unsigned nr, volatile unsigned long *addr)
24{
25 unsigned long mask = (1UL << (nr % BITS_PER_LONG));
26 __insn_fetchor((void *)(addr + nr / BITS_PER_LONG), mask);
27}
28
29static inline void clear_bit(unsigned nr, volatile unsigned long *addr)
30{
31 unsigned long mask = (1UL << (nr % BITS_PER_LONG));
32 __insn_fetchand((void *)(addr + nr / BITS_PER_LONG), ~mask);
33}
34
35static inline void change_bit(unsigned nr, volatile unsigned long *addr)
36{
37 unsigned long mask = (1UL << (nr % BITS_PER_LONG));
38 unsigned long guess, oldval;
39 addr += nr / BITS_PER_LONG;
40 oldval = *addr;
41 do {
42 guess = oldval;
43 oldval = cmpxchg(addr, guess, guess ^ mask);
44 } while (guess != oldval);
45}
46
47
48/*
49 * The test_and_xxx_bit() routines require a memory fence before we
50 * start the operation, and after the operation completes. We use
51 * smp_mb() before, and rely on the "!= 0" comparison, plus a compiler
52 * barrier(), to block until the atomic op is complete.
53 */
54
55static inline int test_and_set_bit(unsigned nr, volatile unsigned long *addr)
56{
57 int val;
58 unsigned long mask = (1UL << (nr % BITS_PER_LONG));
59 smp_mb(); /* barrier for proper semantics */
60 val = (__insn_fetchor((void *)(addr + nr / BITS_PER_LONG), mask)
61 & mask) != 0;
62 barrier();
63 return val;
64}
65
66
67static inline int test_and_clear_bit(unsigned nr, volatile unsigned long *addr)
68{
69 int val;
70 unsigned long mask = (1UL << (nr % BITS_PER_LONG));
71 smp_mb(); /* barrier for proper semantics */
72 val = (__insn_fetchand((void *)(addr + nr / BITS_PER_LONG), ~mask)
73 & mask) != 0;
74 barrier();
75 return val;
76}
77
78
79static inline int test_and_change_bit(unsigned nr,
80 volatile unsigned long *addr)
81{
82 unsigned long mask = (1UL << (nr % BITS_PER_LONG));
83 unsigned long guess, oldval;
84 addr += nr / BITS_PER_LONG;
85 oldval = *addr;
86 do {
87 guess = oldval;
88 oldval = cmpxchg(addr, guess, guess ^ mask);
89 } while (guess != oldval);
90 return (oldval & mask) != 0;
91}
92
93#include <asm-generic/bitops/ext2-atomic-setbit.h>
94
95#endif /* _ASM_TILE_BITOPS_64_H */
diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
deleted file mode 100644
index 7d6aaa128e8b..000000000000
--- a/arch/tile/include/asm/cache.h
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_CACHE_H
16#define _ASM_TILE_CACHE_H
17
18#include <arch/chip.h>
19
20/* bytes per L1 data cache line */
21#define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
22#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
23
24/* bytes per L2 cache line */
25#define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
26#define L2_CACHE_BYTES (1 << L2_CACHE_SHIFT)
27#define L2_CACHE_ALIGN(x) (((x)+(L2_CACHE_BYTES-1)) & -L2_CACHE_BYTES)
28
29/*
30 * TILEPro I/O is not always coherent (networking typically uses coherent
31 * I/O, but PCI traffic does not) and setting ARCH_DMA_MINALIGN to the
32 * L2 cacheline size helps ensure that kernel heap allocations are aligned.
33 * TILE-Gx I/O is always coherent when used on hash-for-home pages.
34 *
35 * However, it's possible at runtime to request not to use hash-for-home
36 * for the kernel heap, in which case the kernel will use flush-and-inval
37 * to manage coherence. As a result, we use L2_CACHE_BYTES for the
38 * DMA minimum alignment to avoid false sharing in the kernel heap.
39 */
40#define ARCH_DMA_MINALIGN L2_CACHE_BYTES
41
42/* use the cache line size for the L2, which is where it counts */
43#define SMP_CACHE_BYTES_SHIFT L2_CACHE_SHIFT
44#define SMP_CACHE_BYTES L2_CACHE_BYTES
45#define INTERNODE_CACHE_SHIFT L2_CACHE_SHIFT
46#define INTERNODE_CACHE_BYTES L2_CACHE_BYTES
47
48/* Group together read-mostly things to avoid cache false sharing */
49#define __read_mostly __attribute__((__section__(".data..read_mostly")))
50
51/*
52 * Originally we used small TLB pages for kernel data and grouped some
53 * things together as ro-after-init, enforcing the property at the end
54 * of initialization by making those pages read-only and non-coherent.
55 * This allowed better cache utilization since cache inclusion did not
56 * need to be maintained. However, to do this requires an extra TLB
57 * entry, which on balance is more of a performance hit than the
58 * non-coherence is a performance gain, so we now just make "read
59 * mostly" and "ro-after-init" be synonyms. We keep the attribute
60 * separate in case we change our minds at a future date.
61 */
62#define __ro_after_init __read_mostly
63
64#endif /* _ASM_TILE_CACHE_H */
diff --git a/arch/tile/include/asm/cacheflush.h b/arch/tile/include/asm/cacheflush.h
deleted file mode 100644
index 92ee4c8a4f76..000000000000
--- a/arch/tile/include/asm/cacheflush.h
+++ /dev/null
@@ -1,160 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_CACHEFLUSH_H
16#define _ASM_TILE_CACHEFLUSH_H
17
18#include <arch/chip.h>
19
20/* Keep includes the same across arches. */
21#include <linux/mm.h>
22#include <linux/cache.h>
23#include <arch/icache.h>
24
25/* Caches are physically-indexed and so don't need special treatment */
26#define flush_cache_all() do { } while (0)
27#define flush_cache_mm(mm) do { } while (0)
28#define flush_cache_dup_mm(mm) do { } while (0)
29#define flush_cache_range(vma, start, end) do { } while (0)
30#define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
31#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
32#define flush_dcache_page(page) do { } while (0)
33#define flush_dcache_mmap_lock(mapping) do { } while (0)
34#define flush_dcache_mmap_unlock(mapping) do { } while (0)
35#define flush_cache_vmap(start, end) do { } while (0)
36#define flush_cache_vunmap(start, end) do { } while (0)
37#define flush_icache_page(vma, pg) do { } while (0)
38#define flush_icache_user_range(vma, pg, adr, len) do { } while (0)
39
40/* Flush the icache just on this cpu */
41extern void __flush_icache_range(unsigned long start, unsigned long end);
42
43/* Flush the entire icache on this cpu. */
44#define __flush_icache() __flush_icache_range(0, CHIP_L1I_CACHE_SIZE())
45
46#ifdef CONFIG_SMP
47/*
48 * When the kernel writes to its own text we need to do an SMP
49 * broadcast to make the L1I coherent everywhere. This includes
50 * module load and single step.
51 */
52extern void flush_icache_range(unsigned long start, unsigned long end);
53#else
54#define flush_icache_range __flush_icache_range
55#endif
56
57/*
58 * An update to an executable user page requires icache flushing.
59 * We could carefully update only tiles that are running this process,
60 * and rely on the fact that we flush the icache on every context
61 * switch to avoid doing extra work here. But for now, I'll be
62 * conservative and just do a global icache flush.
63 */
64static inline void copy_to_user_page(struct vm_area_struct *vma,
65 struct page *page, unsigned long vaddr,
66 void *dst, void *src, int len)
67{
68 memcpy(dst, src, len);
69 if (vma->vm_flags & VM_EXEC) {
70 flush_icache_range((unsigned long) dst,
71 (unsigned long) dst + len);
72 }
73}
74
75#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
76 memcpy((dst), (src), (len))
77
78/* Flush a VA range; pads to L2 cacheline boundaries. */
79static inline void __flush_buffer(void *buffer, size_t size)
80{
81 char *next = (char *)((long)buffer & -L2_CACHE_BYTES);
82 char *finish = (char *)L2_CACHE_ALIGN((long)buffer + size);
83 while (next < finish) {
84 __insn_flush(next);
85 next += CHIP_FLUSH_STRIDE();
86 }
87}
88
89/* Flush & invalidate a VA range; pads to L2 cacheline boundaries. */
90static inline void __finv_buffer(void *buffer, size_t size)
91{
92 char *next = (char *)((long)buffer & -L2_CACHE_BYTES);
93 char *finish = (char *)L2_CACHE_ALIGN((long)buffer + size);
94 while (next < finish) {
95 __insn_finv(next);
96 next += CHIP_FINV_STRIDE();
97 }
98}
99
100
101/*
102 * Flush a locally-homecached VA range and wait for the evicted
103 * cachelines to hit memory.
104 */
105static inline void flush_buffer_local(void *buffer, size_t size)
106{
107 __flush_buffer(buffer, size);
108 mb_incoherent();
109}
110
111/*
112 * Flush and invalidate a locally-homecached VA range and wait for the
113 * evicted cachelines to hit memory.
114 */
115static inline void finv_buffer_local(void *buffer, size_t size)
116{
117 __finv_buffer(buffer, size);
118 mb_incoherent();
119}
120
121#ifdef __tilepro__
122/* Invalidate a VA range; pads to L2 cacheline boundaries. */
123static inline void __inv_buffer(void *buffer, size_t size)
124{
125 char *next = (char *)((long)buffer & -L2_CACHE_BYTES);
126 char *finish = (char *)L2_CACHE_ALIGN((long)buffer + size);
127 while (next < finish) {
128 __insn_inv(next);
129 next += CHIP_INV_STRIDE();
130 }
131}
132
133/* Invalidate a VA range and wait for it to be complete. */
134static inline void inv_buffer(void *buffer, size_t size)
135{
136 __inv_buffer(buffer, size);
137 mb();
138}
139#endif
140
141/*
142 * Flush and invalidate a VA range that is homed remotely, waiting
143 * until the memory controller holds the flushed values. If "hfh" is
144 * true, we will do a more expensive flush involving additional loads
145 * to make sure we have touched all the possible home cpus of a buffer
146 * that is homed with "hash for home".
147 */
148void finv_buffer_remote(void *buffer, size_t size, int hfh);
149
150/*
151 * On SMP systems, when the scheduler does migration-cost autodetection,
152 * it needs a way to flush as much of the CPU's caches as possible:
153 *
154 * TODO: fill this in!
155 */
156static inline void sched_cacheflush(void)
157{
158}
159
160#endif /* _ASM_TILE_CACHEFLUSH_H */
diff --git a/arch/tile/include/asm/checksum.h b/arch/tile/include/asm/checksum.h
deleted file mode 100644
index b21a2fdec9f7..000000000000
--- a/arch/tile/include/asm/checksum.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_CHECKSUM_H
16#define _ASM_TILE_CHECKSUM_H
17
18#include <asm-generic/checksum.h>
19
20/* Allow us to provide a more optimized do_csum(). */
21__wsum do_csum(const unsigned char *buff, int len);
22#define do_csum do_csum
23
24/*
25 * Return the sum of all the 16-bit subwords in a long.
26 * This sums two subwords on a 32-bit machine, and four on 64 bits.
27 * The implementation does two vector adds to capture any overflow.
28 */
29static inline unsigned int csum_long(unsigned long x)
30{
31 unsigned long ret;
32#ifdef __tilegx__
33 ret = __insn_v2sadu(x, 0);
34 ret = __insn_v2sadu(ret, 0);
35#else
36 ret = __insn_sadh_u(x, 0);
37 ret = __insn_sadh_u(ret, 0);
38#endif
39 return ret;
40}
41
42#endif /* _ASM_TILE_CHECKSUM_H */
diff --git a/arch/tile/include/asm/cmpxchg.h b/arch/tile/include/asm/cmpxchg.h
deleted file mode 100644
index 25d5899497be..000000000000
--- a/arch/tile/include/asm/cmpxchg.h
+++ /dev/null
@@ -1,132 +0,0 @@
1/*
2 * cmpxchg.h -- forked from asm/atomic.h with this copyright:
3 *
4 * Copyright 2010 Tilera Corporation. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for
14 * more details.
15 *
16 */
17
18#ifndef _ASM_TILE_CMPXCHG_H
19#define _ASM_TILE_CMPXCHG_H
20
21#ifndef __ASSEMBLY__
22
23#include <asm/barrier.h>
24
25/* Nonexistent functions intended to cause compile errors. */
26extern void __xchg_called_with_bad_pointer(void)
27 __compiletime_error("Bad argument size for xchg");
28extern void __cmpxchg_called_with_bad_pointer(void)
29 __compiletime_error("Bad argument size for cmpxchg");
30
31#ifndef __tilegx__
32
33/* Note the _atomic_xxx() routines include a final mb(). */
34int _atomic_xchg(int *ptr, int n);
35int _atomic_xchg_add(int *v, int i);
36int _atomic_xchg_add_unless(int *v, int a, int u);
37int _atomic_cmpxchg(int *ptr, int o, int n);
38long long _atomic64_xchg(long long *v, long long n);
39long long _atomic64_xchg_add(long long *v, long long i);
40long long _atomic64_xchg_add_unless(long long *v, long long a, long long u);
41long long _atomic64_cmpxchg(long long *v, long long o, long long n);
42
43#define xchg(ptr, n) \
44 ({ \
45 if (sizeof(*(ptr)) != 4) \
46 __xchg_called_with_bad_pointer(); \
47 smp_mb(); \
48 (typeof(*(ptr)))_atomic_xchg((int *)(ptr), (int)(n)); \
49 })
50
51#define cmpxchg(ptr, o, n) \
52 ({ \
53 if (sizeof(*(ptr)) != 4) \
54 __cmpxchg_called_with_bad_pointer(); \
55 smp_mb(); \
56 (typeof(*(ptr)))_atomic_cmpxchg((int *)ptr, (int)o, \
57 (int)n); \
58 })
59
60#define xchg64(ptr, n) \
61 ({ \
62 if (sizeof(*(ptr)) != 8) \
63 __xchg_called_with_bad_pointer(); \
64 smp_mb(); \
65 (typeof(*(ptr)))_atomic64_xchg((long long *)(ptr), \
66 (long long)(n)); \
67 })
68
69#define cmpxchg64(ptr, o, n) \
70 ({ \
71 if (sizeof(*(ptr)) != 8) \
72 __cmpxchg_called_with_bad_pointer(); \
73 smp_mb(); \
74 (typeof(*(ptr)))_atomic64_cmpxchg((long long *)ptr, \
75 (long long)o, (long long)n); \
76 })
77
78#else
79
80#define xchg(ptr, n) \
81 ({ \
82 typeof(*(ptr)) __x; \
83 smp_mb(); \
84 switch (sizeof(*(ptr))) { \
85 case 4: \
86 __x = (typeof(__x))(unsigned long) \
87 __insn_exch4((ptr), \
88 (u32)(unsigned long)(n)); \
89 break; \
90 case 8: \
91 __x = (typeof(__x)) \
92 __insn_exch((ptr), (unsigned long)(n)); \
93 break; \
94 default: \
95 __xchg_called_with_bad_pointer(); \
96 break; \
97 } \
98 smp_mb(); \
99 __x; \
100 })
101
102#define cmpxchg(ptr, o, n) \
103 ({ \
104 typeof(*(ptr)) __x; \
105 __insn_mtspr(SPR_CMPEXCH_VALUE, (unsigned long)(o)); \
106 smp_mb(); \
107 switch (sizeof(*(ptr))) { \
108 case 4: \
109 __x = (typeof(__x))(unsigned long) \
110 __insn_cmpexch4((ptr), \
111 (u32)(unsigned long)(n)); \
112 break; \
113 case 8: \
114 __x = (typeof(__x))__insn_cmpexch((ptr), \
115 (long long)(n)); \
116 break; \
117 default: \
118 __cmpxchg_called_with_bad_pointer(); \
119 break; \
120 } \
121 smp_mb(); \
122 __x; \
123 })
124
125#define xchg64 xchg
126#define cmpxchg64 cmpxchg
127
128#endif
129
130#endif /* __ASSEMBLY__ */
131
132#endif /* _ASM_TILE_CMPXCHG_H */
diff --git a/arch/tile/include/asm/compat.h b/arch/tile/include/asm/compat.h
deleted file mode 100644
index 769ff6ac0bf5..000000000000
--- a/arch/tile/include/asm/compat.h
+++ /dev/null
@@ -1,233 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_COMPAT_H
16#define _ASM_TILE_COMPAT_H
17
18/*
19 * Architecture specific compatibility types
20 */
21#include <linux/types.h>
22#include <linux/sched.h>
23
24#define COMPAT_USER_HZ 100
25
26/* "long" and pointer-based types are different. */
27typedef s32 compat_long_t;
28typedef u32 compat_ulong_t;
29typedef u32 compat_size_t;
30typedef s32 compat_ssize_t;
31typedef s32 compat_off_t;
32typedef s32 compat_time_t;
33typedef s32 compat_clock_t;
34typedef u32 compat_ino_t;
35typedef u32 compat_caddr_t;
36typedef u32 compat_uptr_t;
37
38/* Many types are "int" or otherwise the same. */
39typedef __kernel_pid_t compat_pid_t;
40typedef __kernel_uid_t __compat_uid_t;
41typedef __kernel_gid_t __compat_gid_t;
42typedef __kernel_uid32_t __compat_uid32_t;
43typedef __kernel_uid32_t __compat_gid32_t;
44typedef __kernel_mode_t compat_mode_t;
45typedef __kernel_dev_t compat_dev_t;
46typedef __kernel_loff_t compat_loff_t;
47typedef __kernel_ipc_pid_t compat_ipc_pid_t;
48typedef __kernel_daddr_t compat_daddr_t;
49typedef __kernel_fsid_t compat_fsid_t;
50typedef __kernel_timer_t compat_timer_t;
51typedef __kernel_key_t compat_key_t;
52typedef int compat_int_t;
53typedef s64 compat_s64;
54typedef uint compat_uint_t;
55typedef u64 compat_u64;
56
57/* We use the same register dump format in 32-bit images. */
58typedef unsigned long compat_elf_greg_t;
59#define COMPAT_ELF_NGREG (sizeof(struct pt_regs) / sizeof(compat_elf_greg_t))
60typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
61
62struct compat_timespec {
63 compat_time_t tv_sec;
64 s32 tv_nsec;
65};
66
67struct compat_timeval {
68 compat_time_t tv_sec;
69 s32 tv_usec;
70};
71
72#define compat_stat stat
73#define compat_statfs statfs
74
75struct compat_sysctl {
76 unsigned int name;
77 int nlen;
78 unsigned int oldval;
79 unsigned int oldlenp;
80 unsigned int newval;
81 unsigned int newlen;
82 unsigned int __unused[4];
83};
84
85
86struct compat_flock {
87 short l_type;
88 short l_whence;
89 compat_off_t l_start;
90 compat_off_t l_len;
91 compat_pid_t l_pid;
92};
93
94#define F_GETLK64 12 /* using 'struct flock64' */
95#define F_SETLK64 13
96#define F_SETLKW64 14
97
98struct compat_flock64 {
99 short l_type;
100 short l_whence;
101 compat_loff_t l_start;
102 compat_loff_t l_len;
103 compat_pid_t l_pid;
104};
105
106#define COMPAT_RLIM_INFINITY 0xffffffff
107
108#define _COMPAT_NSIG 64
109#define _COMPAT_NSIG_BPW 32
110
111typedef u32 compat_sigset_word;
112
113#define COMPAT_OFF_T_MAX 0x7fffffff
114
115struct compat_ipc64_perm {
116 compat_key_t key;
117 __compat_uid32_t uid;
118 __compat_gid32_t gid;
119 __compat_uid32_t cuid;
120 __compat_gid32_t cgid;
121 unsigned short mode;
122 unsigned short __pad1;
123 unsigned short seq;
124 unsigned short __pad2;
125 compat_ulong_t unused1;
126 compat_ulong_t unused2;
127};
128
129struct compat_semid64_ds {
130 struct compat_ipc64_perm sem_perm;
131 compat_time_t sem_otime;
132 compat_ulong_t __unused1;
133 compat_time_t sem_ctime;
134 compat_ulong_t __unused2;
135 compat_ulong_t sem_nsems;
136 compat_ulong_t __unused3;
137 compat_ulong_t __unused4;
138};
139
140struct compat_msqid64_ds {
141 struct compat_ipc64_perm msg_perm;
142 compat_time_t msg_stime;
143 compat_ulong_t __unused1;
144 compat_time_t msg_rtime;
145 compat_ulong_t __unused2;
146 compat_time_t msg_ctime;
147 compat_ulong_t __unused3;
148 compat_ulong_t msg_cbytes;
149 compat_ulong_t msg_qnum;
150 compat_ulong_t msg_qbytes;
151 compat_pid_t msg_lspid;
152 compat_pid_t msg_lrpid;
153 compat_ulong_t __unused4;
154 compat_ulong_t __unused5;
155};
156
157struct compat_shmid64_ds {
158 struct compat_ipc64_perm shm_perm;
159 compat_size_t shm_segsz;
160 compat_time_t shm_atime;
161 compat_ulong_t __unused1;
162 compat_time_t shm_dtime;
163 compat_ulong_t __unused2;
164 compat_time_t shm_ctime;
165 compat_ulong_t __unused3;
166 compat_pid_t shm_cpid;
167 compat_pid_t shm_lpid;
168 compat_ulong_t shm_nattch;
169 compat_ulong_t __unused4;
170 compat_ulong_t __unused5;
171};
172
173/*
174 * A pointer passed in from user mode. This should not
175 * be used for syscall parameters, just declare them
176 * as pointers because the syscall entry code will have
177 * appropriately converted them already.
178 */
179
180static inline void __user *compat_ptr(compat_uptr_t uptr)
181{
182 return (void __user *)(long)(s32)uptr;
183}
184
185static inline compat_uptr_t ptr_to_compat(void __user *uptr)
186{
187 return (u32)(unsigned long)uptr;
188}
189
190/* Sign-extend when storing a kernel pointer to a user's ptregs. */
191static inline unsigned long ptr_to_compat_reg(void __user *uptr)
192{
193 return (long)(int)(long __force)uptr;
194}
195
196static inline void __user *arch_compat_alloc_user_space(long len)
197{
198 struct pt_regs *regs = task_pt_regs(current);
199 return (void __user *)regs->sp - len;
200}
201
202static inline int is_compat_task(void)
203{
204 return current_thread_info()->status & TS_COMPAT;
205}
206
207extern int compat_setup_rt_frame(struct ksignal *ksig, sigset_t *set,
208 struct pt_regs *regs);
209
210/* Compat syscalls. */
211struct compat_siginfo;
212struct compat_sigaltstack;
213long compat_sys_rt_sigreturn(void);
214long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high);
215long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high);
216long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count,
217 u32 dummy, u32 low, u32 high);
218long compat_sys_pwrite64(unsigned int fd, char __user *ubuf, size_t count,
219 u32 dummy, u32 low, u32 high);
220long compat_sys_sync_file_range2(int fd, unsigned int flags,
221 u32 offset_lo, u32 offset_hi,
222 u32 nbytes_lo, u32 nbytes_hi);
223long compat_sys_fallocate(int fd, int mode,
224 u32 offset_lo, u32 offset_hi,
225 u32 len_lo, u32 len_hi);
226long compat_sys_llseek(unsigned int fd, unsigned int offset_high,
227 unsigned int offset_low, loff_t __user * result,
228 unsigned int origin);
229
230/* Assembly trampoline to avoid clobbering r0. */
231long _compat_sys_rt_sigreturn(void);
232
233#endif /* _ASM_TILE_COMPAT_H */
diff --git a/arch/tile/include/asm/current.h b/arch/tile/include/asm/current.h
deleted file mode 100644
index da21acf020d3..000000000000
--- a/arch/tile/include/asm/current.h
+++ /dev/null
@@ -1,31 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_CURRENT_H
16#define _ASM_TILE_CURRENT_H
17
18#include <linux/thread_info.h>
19
20struct task_struct;
21
22static inline struct task_struct *get_current(void)
23{
24 return current_thread_info()->task;
25}
26#define current get_current()
27
28/* Return a usable "task_struct" pointer even if the real one is corrupt. */
29struct task_struct *validate_current(void);
30
31#endif /* _ASM_TILE_CURRENT_H */
diff --git a/arch/tile/include/asm/delay.h b/arch/tile/include/asm/delay.h
deleted file mode 100644
index 97b0e69e704e..000000000000
--- a/arch/tile/include/asm/delay.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_DELAY_H
16#define _ASM_TILE_DELAY_H
17
18/* Undefined functions to get compile-time errors. */
19extern void __bad_udelay(void);
20extern void __bad_ndelay(void);
21
22extern void __udelay(unsigned long usecs);
23extern void __ndelay(unsigned long nsecs);
24extern void __delay(unsigned long loops);
25
26#define udelay(n) (__builtin_constant_p(n) ? \
27 ((n) > 20000 ? __bad_udelay() : __ndelay((n) * 1000)) : \
28 __udelay(n))
29
30#define ndelay(n) (__builtin_constant_p(n) ? \
31 ((n) > 20000 ? __bad_ndelay() : __ndelay(n)) : \
32 __ndelay(n))
33
34#endif /* _ASM_TILE_DELAY_H */
diff --git a/arch/tile/include/asm/device.h b/arch/tile/include/asm/device.h
deleted file mode 100644
index 1cf45422a0df..000000000000
--- a/arch/tile/include/asm/device.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 * Arch specific extensions to struct device
14 */
15
16#ifndef _ASM_TILE_DEVICE_H
17#define _ASM_TILE_DEVICE_H
18
19struct dev_archdata {
20 /* Offset of the DMA address from the PA. */
21 dma_addr_t dma_offset;
22
23 /*
24 * Highest DMA address that can be generated by devices that
25 * have limited DMA capability, i.e. non 64-bit capable.
26 */
27 dma_addr_t max_direct_dma_addr;
28};
29
30struct pdev_archdata {
31};
32
33#endif /* _ASM_TILE_DEVICE_H */
diff --git a/arch/tile/include/asm/div64.h b/arch/tile/include/asm/div64.h
deleted file mode 100644
index a0a798344d5f..000000000000
--- a/arch/tile/include/asm/div64.h
+++ /dev/null
@@ -1,17 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_TILE_DIV64_H
3#define _ASM_TILE_DIV64_H
4
5#include <linux/types.h>
6
7#ifdef __tilegx__
8static inline u64 mul_u32_u32(u32 a, u32 b)
9{
10 return __insn_mul_lu_lu(a, b);
11}
12#define mul_u32_u32 mul_u32_u32
13#endif
14
15#include <asm-generic/div64.h>
16
17#endif /* _ASM_TILE_DIV64_H */
diff --git a/arch/tile/include/asm/dma-mapping.h b/arch/tile/include/asm/dma-mapping.h
deleted file mode 100644
index d25fce101fc0..000000000000
--- a/arch/tile/include/asm/dma-mapping.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_DMA_MAPPING_H
16#define _ASM_TILE_DMA_MAPPING_H
17
18#include <linux/mm.h>
19#include <linux/scatterlist.h>
20#include <linux/cache.h>
21#include <linux/io.h>
22
23#ifdef __tilegx__
24#define ARCH_HAS_DMA_GET_REQUIRED_MASK
25#endif
26
27extern const struct dma_map_ops *tile_dma_map_ops;
28extern const struct dma_map_ops *gx_pci_dma_map_ops;
29extern const struct dma_map_ops *gx_legacy_pci_dma_map_ops;
30extern const struct dma_map_ops *gx_hybrid_pci_dma_map_ops;
31
32static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
33{
34 return tile_dma_map_ops;
35}
36
37static inline dma_addr_t get_dma_offset(struct device *dev)
38{
39 return dev->archdata.dma_offset;
40}
41
42static inline void set_dma_offset(struct device *dev, dma_addr_t off)
43{
44 dev->archdata.dma_offset = off;
45}
46
47#define HAVE_ARCH_DMA_SET_MASK 1
48int dma_set_mask(struct device *dev, u64 mask);
49
50#endif /* _ASM_TILE_DMA_MAPPING_H */
diff --git a/arch/tile/include/asm/dma.h b/arch/tile/include/asm/dma.h
deleted file mode 100644
index 12a7ca16d164..000000000000
--- a/arch/tile/include/asm/dma.h
+++ /dev/null
@@ -1,25 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_DMA_H
16#define _ASM_TILE_DMA_H
17
18#include <asm-generic/dma.h>
19
20/* Needed by drivers/pci/quirks.c */
21#ifdef CONFIG_PCI
22extern int isa_dma_bridge_buggy;
23#endif
24
25#endif /* _ASM_TILE_DMA_H */
diff --git a/arch/tile/include/asm/elf.h b/arch/tile/include/asm/elf.h
deleted file mode 100644
index e9d54a06736f..000000000000
--- a/arch/tile/include/asm/elf.h
+++ /dev/null
@@ -1,182 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_ELF_H
16#define _ASM_TILE_ELF_H
17
18/*
19 * ELF register definitions.
20 */
21
22#include <arch/chip.h>
23
24#include <linux/ptrace.h>
25#include <linux/elf-em.h>
26#include <asm/byteorder.h>
27#include <asm/page.h>
28
29typedef unsigned long elf_greg_t;
30
31#define ELF_NGREG (sizeof(struct pt_regs) / sizeof(elf_greg_t))
32typedef elf_greg_t elf_gregset_t[ELF_NGREG];
33
34/* Provide a nominal data structure. */
35#define ELF_NFPREG 0
36typedef double elf_fpreg_t;
37typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
38
39#ifdef __tilegx__
40#define ELF_CLASS ELFCLASS64
41#else
42#define ELF_CLASS ELFCLASS32
43#endif
44#ifdef __BIG_ENDIAN__
45#define ELF_DATA ELFDATA2MSB
46#else
47#define ELF_DATA ELFDATA2LSB
48#endif
49
50/*
51 * There seems to be a bug in how compat_binfmt_elf.c works: it
52 * #undefs ELF_ARCH, but it is then used in binfmt_elf.c for fill_note_info().
53 * Hack around this by providing an enum value of ELF_ARCH.
54 */
55enum { ELF_ARCH = CHIP_ELF_TYPE() };
56#define ELF_ARCH ELF_ARCH
57
58/*
59 * This is used to ensure we don't load something for the wrong architecture.
60 */
61#define elf_check_arch(x) \
62 ((x)->e_ident[EI_CLASS] == ELF_CLASS && \
63 (x)->e_ident[EI_DATA] == ELF_DATA && \
64 (x)->e_machine == CHIP_ELF_TYPE())
65
66/* The module loader only handles a few relocation types. */
67#ifndef __tilegx__
68#define R_TILE_32 1
69#define R_TILE_JOFFLONG_X1 15
70#define R_TILE_IMM16_X0_LO 25
71#define R_TILE_IMM16_X1_LO 26
72#define R_TILE_IMM16_X0_HA 29
73#define R_TILE_IMM16_X1_HA 30
74#else
75#define R_TILEGX_64 1
76#define R_TILEGX_JUMPOFF_X1 21
77#define R_TILEGX_IMM16_X0_HW0 36
78#define R_TILEGX_IMM16_X1_HW0 37
79#define R_TILEGX_IMM16_X0_HW1 38
80#define R_TILEGX_IMM16_X1_HW1 39
81#define R_TILEGX_IMM16_X0_HW2_LAST 48
82#define R_TILEGX_IMM16_X1_HW2_LAST 49
83#endif
84
85/* Use standard page size for core dumps. */
86#define ELF_EXEC_PAGESIZE PAGE_SIZE
87
88/*
89 * This is the location that an ET_DYN program is loaded if exec'ed. Typical
90 * use of this is to invoke "./ld.so someprog" to test out a new version of
91 * the loader. We need to make sure that it is out of the way of the program
92 * that it will "exec", and that there is sufficient room for the brk.
93 */
94#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
95
96#define ELF_CORE_COPY_REGS(_dest, _regs) \
97 memcpy((char *) &_dest, (char *) _regs, \
98 sizeof(struct pt_regs));
99
100/* No additional FP registers to copy. */
101#define ELF_CORE_COPY_FPREGS(t, fpu) 0
102
103/*
104 * This yields a mask that user programs can use to figure out what
105 * instruction set this CPU supports. This could be done in user space,
106 * but it's not easy, and we've already done it here.
107 */
108#define ELF_HWCAP (0)
109
110/*
111 * This yields a string that ld.so will use to load implementation
112 * specific libraries for optimization. This is more specific in
113 * intent than poking at uname or /proc/cpuinfo.
114 */
115#define ELF_PLATFORM (NULL)
116
117extern void elf_plat_init(struct pt_regs *regs, unsigned long load_addr);
118
119#define ELF_PLAT_INIT(_r, load_addr) elf_plat_init(_r, load_addr)
120
121extern int dump_task_regs(struct task_struct *, elf_gregset_t *);
122#define ELF_CORE_COPY_TASK_REGS(tsk, elf_regs) dump_task_regs(tsk, elf_regs)
123
124/* Tilera Linux has no personalities currently, so no need to do anything. */
125#define SET_PERSONALITY(ex) do { } while (0)
126
127#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
128/* Support auto-mapping of the user interrupt vectors. */
129struct linux_binprm;
130extern int arch_setup_additional_pages(struct linux_binprm *bprm,
131 int executable_stack);
132/* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
133#define ARCH_DLINFO \
134do { \
135 NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE); \
136} while (0)
137
138struct mm_struct;
139extern unsigned long arch_randomize_brk(struct mm_struct *mm);
140#define arch_randomize_brk arch_randomize_brk
141
142#ifdef CONFIG_COMPAT
143
144#define COMPAT_ELF_PLATFORM "tilegx-m32"
145
146/*
147 * "Compat" binaries have the same machine type, but 32-bit class,
148 * since they're not a separate machine type, but just a 32-bit
149 * variant of the standard 64-bit architecture.
150 */
151#define compat_elf_check_arch(x) \
152 ((x)->e_ident[EI_CLASS] == ELFCLASS32 && \
153 (x)->e_machine == CHIP_ELF_TYPE())
154
155#define compat_start_thread(regs, ip, usp) do { \
156 regs->pc = ptr_to_compat_reg((void *)(ip)); \
157 regs->sp = ptr_to_compat_reg((void *)(usp)); \
158 single_step_execve(); \
159 } while (0)
160
161/*
162 * Use SET_PERSONALITY to indicate compatibility via TS_COMPAT.
163 */
164#undef SET_PERSONALITY
165#define SET_PERSONALITY(ex) \
166do { \
167 set_personality(PER_LINUX | (current->personality & (~PER_MASK))); \
168 current_thread_info()->status &= ~TS_COMPAT; \
169} while (0)
170#define COMPAT_SET_PERSONALITY(ex) \
171do { \
172 set_personality(PER_LINUX | (current->personality & (~PER_MASK))); \
173 current_thread_info()->status |= TS_COMPAT; \
174} while (0)
175
176#define COMPAT_ELF_ET_DYN_BASE (0xffffffff / 3 * 2)
177
178#endif /* CONFIG_COMPAT */
179
180#define CORE_DUMP_USE_REGSET
181
182#endif /* _ASM_TILE_ELF_H */
diff --git a/arch/tile/include/asm/fixmap.h b/arch/tile/include/asm/fixmap.h
deleted file mode 100644
index ffe2637aeb31..000000000000
--- a/arch/tile/include/asm/fixmap.h
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * Copyright (C) 1998 Ingo Molnar
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_FIXMAP_H
17#define _ASM_TILE_FIXMAP_H
18
19#include <asm/page.h>
20
21#ifndef __ASSEMBLY__
22#include <linux/kernel.h>
23#ifdef CONFIG_HIGHMEM
24#include <linux/threads.h>
25#include <asm/kmap_types.h>
26#endif
27
28/*
29 * Here we define all the compile-time 'special' virtual
30 * addresses. The point is to have a constant address at
31 * compile time, but to set the physical address only
32 * in the boot process. We allocate these special addresses
33 * from the end of supervisor virtual memory backwards.
34 * Also this lets us do fail-safe vmalloc(), we
35 * can guarantee that these special addresses and
36 * vmalloc()-ed addresses never overlap.
37 *
38 * these 'compile-time allocated' memory buffers are
39 * fixed-size 4k pages. (or larger if used with an increment
40 * higher than 1) use fixmap_set(idx,phys) to associate
41 * physical memory with fixmap indices.
42 *
43 * TLB entries of such buffers will not be flushed across
44 * task switches.
45 */
46enum fixed_addresses {
47#ifdef __tilegx__
48 /*
49 * TILEPro has unmapped memory above so the hole isn't needed,
50 * and in any case the hole pushes us over a single 16MB pmd.
51 */
52 FIX_HOLE,
53#endif
54#ifdef CONFIG_HIGHMEM
55 FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
56 FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
57#endif
58#ifdef __tilegx__ /* see homecache.c */
59 FIX_HOMECACHE_BEGIN,
60 FIX_HOMECACHE_END = FIX_HOMECACHE_BEGIN+(NR_CPUS)-1,
61#endif
62 __end_of_permanent_fixed_addresses,
63
64 /*
65 * Temporary boot-time mappings, used before ioremap() is functional.
66 * Not currently needed by the Tile architecture.
67 */
68#define NR_FIX_BTMAPS 0
69#if NR_FIX_BTMAPS
70 FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
71 FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS - 1,
72 __end_of_fixed_addresses
73#else
74 __end_of_fixed_addresses = __end_of_permanent_fixed_addresses
75#endif
76};
77
78#define __FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT)
79#define __FIXADDR_BOOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
80#define FIXADDR_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_SIZE)
81#define FIXADDR_BOOT_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_BOOT_SIZE)
82
83#include <asm-generic/fixmap.h>
84
85#endif /* !__ASSEMBLY__ */
86
87#endif /* _ASM_TILE_FIXMAP_H */
diff --git a/arch/tile/include/asm/ftrace.h b/arch/tile/include/asm/ftrace.h
deleted file mode 100644
index 738d239b792f..000000000000
--- a/arch/tile/include/asm/ftrace.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_FTRACE_H
16#define _ASM_TILE_FTRACE_H
17
18#ifdef CONFIG_FUNCTION_TRACER
19
20#define MCOUNT_ADDR ((unsigned long)(__mcount))
21#define MCOUNT_INSN_SIZE 8 /* sizeof mcount call */
22
23#ifndef __ASSEMBLY__
24extern void __mcount(void);
25
26#define ARCH_SUPPORTS_FTRACE_OPS 1
27
28#ifdef CONFIG_DYNAMIC_FTRACE
29static inline unsigned long ftrace_call_adjust(unsigned long addr)
30{
31 return addr;
32}
33
34struct dyn_arch_ftrace {
35};
36#endif /* CONFIG_DYNAMIC_FTRACE */
37
38#endif /* __ASSEMBLY__ */
39
40#endif /* CONFIG_FUNCTION_TRACER */
41
42#endif /* _ASM_TILE_FTRACE_H */
diff --git a/arch/tile/include/asm/futex.h b/arch/tile/include/asm/futex.h
deleted file mode 100644
index 83c1e639b411..000000000000
--- a/arch/tile/include/asm/futex.h
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * These routines make two important assumptions:
15 *
16 * 1. atomic_t is really an int and can be freely cast back and forth
17 * (validated in __init_atomic_per_cpu).
18 *
19 * 2. userspace uses sys_cmpxchg() for all atomic operations, thus using
20 * the same locking convention that all the kernel atomic routines use.
21 */
22
23#ifndef _ASM_TILE_FUTEX_H
24#define _ASM_TILE_FUTEX_H
25
26#ifndef __ASSEMBLY__
27
28#include <linux/futex.h>
29#include <linux/uaccess.h>
30#include <linux/errno.h>
31#include <asm/atomic.h>
32
33/*
34 * Support macros for futex operations. Do not use these macros directly.
35 * They assume "ret", "val", "oparg", and "uaddr" in the lexical context.
36 * __futex_cmpxchg() additionally assumes "oldval".
37 */
38
39#ifdef __tilegx__
40
41#define __futex_asm(OP) \
42 asm("1: {" #OP " %1, %3, %4; movei %0, 0 }\n" \
43 ".pushsection .fixup,\"ax\"\n" \
44 "0: { movei %0, %5; j 9f }\n" \
45 ".section __ex_table,\"a\"\n" \
46 ".align 8\n" \
47 ".quad 1b, 0b\n" \
48 ".popsection\n" \
49 "9:" \
50 : "=r" (ret), "=r" (val), "+m" (*(uaddr)) \
51 : "r" (uaddr), "r" (oparg), "i" (-EFAULT))
52
53#define __futex_set() __futex_asm(exch4)
54#define __futex_add() __futex_asm(fetchadd4)
55#define __futex_or() __futex_asm(fetchor4)
56#define __futex_andn() ({ oparg = ~oparg; __futex_asm(fetchand4); })
57#define __futex_cmpxchg() \
58 ({ __insn_mtspr(SPR_CMPEXCH_VALUE, oldval); __futex_asm(cmpexch4); })
59
60#define __futex_xor() \
61 ({ \
62 u32 oldval, n = oparg; \
63 if ((ret = __get_user(oldval, uaddr)) == 0) { \
64 do { \
65 oparg = oldval ^ n; \
66 __futex_cmpxchg(); \
67 } while (ret == 0 && oldval != val); \
68 } \
69 })
70
71/* No need to prefetch, since the atomic ops go to the home cache anyway. */
72#define __futex_prolog()
73
74#else
75
76#define __futex_call(FN) \
77 { \
78 struct __get_user gu = FN((u32 __force *)uaddr, lock, oparg); \
79 val = gu.val; \
80 ret = gu.err; \
81 }
82
83#define __futex_set() __futex_call(__atomic32_xchg)
84#define __futex_add() __futex_call(__atomic32_xchg_add)
85#define __futex_or() __futex_call(__atomic32_fetch_or)
86#define __futex_andn() __futex_call(__atomic32_fetch_andn)
87#define __futex_xor() __futex_call(__atomic32_fetch_xor)
88
89#define __futex_cmpxchg() \
90 { \
91 struct __get_user gu = __atomic32_cmpxchg((u32 __force *)uaddr, \
92 lock, oldval, oparg); \
93 val = gu.val; \
94 ret = gu.err; \
95 }
96
97/*
98 * Find the lock pointer for the atomic calls to use, and issue a
99 * prefetch to the user address to bring it into cache. Similar to
100 * __atomic_setup(), but we can't do a read into the L1 since it might
101 * fault; instead we do a prefetch into the L2.
102 */
103#define __futex_prolog() \
104 int *lock; \
105 __insn_prefetch(uaddr); \
106 lock = __atomic_hashed_lock((int __force *)uaddr)
107#endif
108
109static inline int arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval,
110 u32 __user *uaddr)
111{
112 int uninitialized_var(val), ret;
113
114 __futex_prolog();
115
116 /* The 32-bit futex code makes this assumption, so validate it here. */
117 BUILD_BUG_ON(sizeof(atomic_t) != sizeof(int));
118
119 pagefault_disable();
120 switch (op) {
121 case FUTEX_OP_SET:
122 __futex_set();
123 break;
124 case FUTEX_OP_ADD:
125 __futex_add();
126 break;
127 case FUTEX_OP_OR:
128 __futex_or();
129 break;
130 case FUTEX_OP_ANDN:
131 __futex_andn();
132 break;
133 case FUTEX_OP_XOR:
134 __futex_xor();
135 break;
136 default:
137 ret = -ENOSYS;
138 break;
139 }
140 pagefault_enable();
141
142 if (!ret)
143 *oval = val;
144
145 return ret;
146}
147
148static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
149 u32 oldval, u32 oparg)
150{
151 int ret, val;
152
153 __futex_prolog();
154
155 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
156 return -EFAULT;
157
158 __futex_cmpxchg();
159
160 *uval = val;
161 return ret;
162}
163
164#endif /* !__ASSEMBLY__ */
165
166#endif /* _ASM_TILE_FUTEX_H */
diff --git a/arch/tile/include/asm/hardirq.h b/arch/tile/include/asm/hardirq.h
deleted file mode 100644
index 54110af23985..000000000000
--- a/arch/tile/include/asm/hardirq.h
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_HARDIRQ_H
16#define _ASM_TILE_HARDIRQ_H
17
18#include <linux/threads.h>
19#include <linux/cache.h>
20
21#include <asm/irq.h>
22
23typedef struct {
24 unsigned int __softirq_pending;
25 long idle_timestamp;
26
27 /* Hard interrupt statistics. */
28 unsigned int irq_timer_count;
29 unsigned int irq_syscall_count;
30 unsigned int irq_resched_count;
31 unsigned int irq_hv_flush_count;
32 unsigned int irq_call_count;
33 unsigned int irq_hv_msg_count;
34 unsigned int irq_dev_intr_count;
35
36} ____cacheline_aligned irq_cpustat_t;
37
38DECLARE_PER_CPU(irq_cpustat_t, irq_stat);
39
40#define __ARCH_IRQ_STAT
41#define __IRQ_STAT(cpu, member) (per_cpu(irq_stat, cpu).member)
42
43#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
44
45#endif /* _ASM_TILE_HARDIRQ_H */
diff --git a/arch/tile/include/asm/hardwall.h b/arch/tile/include/asm/hardwall.h
deleted file mode 100644
index 44d2765bde2b..000000000000
--- a/arch/tile/include/asm/hardwall.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Provide methods for access control of per-cpu resources like
15 * UDN, IDN, or IPI.
16 */
17#ifndef _ASM_TILE_HARDWALL_H
18#define _ASM_TILE_HARDWALL_H
19
20#include <uapi/asm/hardwall.h>
21
22/* /proc hooks for hardwall. */
23struct proc_dir_entry;
24#ifdef CONFIG_HARDWALL
25void proc_tile_hardwall_init(struct proc_dir_entry *root);
26int proc_pid_hardwall(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task);
27#else
28static inline void proc_tile_hardwall_init(struct proc_dir_entry *root) {}
29#endif
30#endif /* _ASM_TILE_HARDWALL_H */
diff --git a/arch/tile/include/asm/highmem.h b/arch/tile/include/asm/highmem.h
deleted file mode 100644
index 979579b38e57..000000000000
--- a/arch/tile/include/asm/highmem.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * Copyright (C) 1999 Gerhard Wichert, Siemens AG
3 * Gerhard.Wichert@pdb.siemens.de
4 * Copyright 2010 Tilera Corporation. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for
14 * more details.
15 *
16 * Used in CONFIG_HIGHMEM systems for memory pages which
17 * are not addressable by direct kernel virtual addresses.
18 *
19 */
20
21#ifndef _ASM_TILE_HIGHMEM_H
22#define _ASM_TILE_HIGHMEM_H
23
24#include <linux/interrupt.h>
25#include <linux/threads.h>
26#include <asm/tlbflush.h>
27#include <asm/homecache.h>
28
29/* declarations for highmem.c */
30extern unsigned long highstart_pfn, highend_pfn;
31
32extern pte_t *pkmap_page_table;
33
34/*
35 * Ordering is:
36 *
37 * FIXADDR_TOP
38 * fixed_addresses
39 * FIXADDR_START
40 * temp fixed addresses
41 * FIXADDR_BOOT_START
42 * Persistent kmap area
43 * PKMAP_BASE
44 * VMALLOC_END
45 * Vmalloc area
46 * VMALLOC_START
47 * high_memory
48 */
49#define LAST_PKMAP_MASK (LAST_PKMAP-1)
50#define PKMAP_NR(virt) ((virt-PKMAP_BASE) >> PAGE_SHIFT)
51#define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT))
52
53void *kmap_high(struct page *page);
54void kunmap_high(struct page *page);
55void *kmap(struct page *page);
56void kunmap(struct page *page);
57void *kmap_fix_kpte(struct page *page, int finished);
58
59/* This macro is used only in map_new_virtual() to map "page". */
60#define kmap_prot page_to_kpgprot(page)
61
62void *kmap_atomic(struct page *page);
63void __kunmap_atomic(void *kvaddr);
64void *kmap_atomic_pfn(unsigned long pfn);
65void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot);
66void *kmap_atomic_prot(struct page *page, pgprot_t prot);
67void kmap_atomic_fix_kpte(struct page *page, int finished);
68
69#define flush_cache_kmaps() do { } while (0)
70
71#endif /* _ASM_TILE_HIGHMEM_H */
diff --git a/arch/tile/include/asm/homecache.h b/arch/tile/include/asm/homecache.h
deleted file mode 100644
index 7ddd1b8d6910..000000000000
--- a/arch/tile/include/asm/homecache.h
+++ /dev/null
@@ -1,123 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Handle issues around the Tile "home cache" model of coherence.
15 */
16
17#ifndef _ASM_TILE_HOMECACHE_H
18#define _ASM_TILE_HOMECACHE_H
19
20#include <asm/page.h>
21#include <linux/cpumask.h>
22
23struct page;
24struct task_struct;
25struct vm_area_struct;
26struct zone;
27
28/*
29 * Coherence point for the page is its memory controller.
30 * It is not present in any cache (L1 or L2).
31 */
32#define PAGE_HOME_UNCACHED -1
33
34/*
35 * Is this page immutable (unwritable) and thus able to be cached more
36 * widely than would otherwise be possible? This means we have "nc" set.
37 */
38#define PAGE_HOME_IMMUTABLE -2
39
40/*
41 * Each cpu considers its own cache to be the home for the page,
42 * which makes it incoherent.
43 */
44#define PAGE_HOME_INCOHERENT -3
45
46/* Home for the page is distributed via hash-for-home. */
47#define PAGE_HOME_HASH -4
48
49/* Support wrapper to use instead of explicit hv_flush_remote(). */
50extern void flush_remote(unsigned long cache_pfn, unsigned long cache_length,
51 const struct cpumask *cache_cpumask,
52 HV_VirtAddr tlb_va, unsigned long tlb_length,
53 unsigned long tlb_pgsize,
54 const struct cpumask *tlb_cpumask,
55 HV_Remote_ASID *asids, int asidcount);
56
57/* Set homing-related bits in a PTE (can also pass a pgprot_t). */
58extern pte_t pte_set_home(pte_t pte, int home);
59
60/* Do a cache eviction on the specified cpus. */
61extern void homecache_evict(const struct cpumask *mask);
62
63/*
64 * Change a kernel page's homecache. It must not be mapped in user space.
65 * If !CONFIG_HOMECACHE, only usable on LOWMEM, and can only be called when
66 * no other cpu can reference the page, and causes a full-chip cache/TLB flush.
67 */
68extern void homecache_change_page_home(struct page *, int order, int home);
69
70/*
71 * Flush a page out of whatever cache(s) it is in.
72 * This is more than just finv, since it properly handles waiting
73 * for the data to reach memory, but it can be quite
74 * heavyweight, particularly on incoherent or immutable memory.
75 */
76extern void homecache_finv_page(struct page *);
77
78/*
79 * Flush a page out of the specified home cache.
80 * Note that the specified home need not be the actual home of the page,
81 * as for example might be the case when coordinating with I/O devices.
82 */
83extern void homecache_finv_map_page(struct page *, int home);
84
85/*
86 * Allocate a page with the given GFP flags, home, and optionally
87 * node. These routines are actually just wrappers around the normal
88 * alloc_pages() / alloc_pages_node() functions, which set and clear
89 * a per-cpu variable to communicate with homecache_new_kernel_page().
90 * If !CONFIG_HOMECACHE, uses homecache_change_page_home().
91 */
92extern struct page *homecache_alloc_pages(gfp_t gfp_mask,
93 unsigned int order, int home);
94extern struct page *homecache_alloc_pages_node(int nid, gfp_t gfp_mask,
95 unsigned int order, int home);
96#define homecache_alloc_page(gfp_mask, home) \
97 homecache_alloc_pages(gfp_mask, 0, home)
98
99/*
100 * These routines are just pass-throughs to free_pages() when
101 * we support full homecaching. If !CONFIG_HOMECACHE, then these
102 * routines use homecache_change_page_home() to reset the home
103 * back to the default before returning the page to the allocator.
104 */
105void __homecache_free_pages(struct page *, unsigned int order);
106void homecache_free_pages(unsigned long addr, unsigned int order);
107#define __homecache_free_page(page) __homecache_free_pages((page), 0)
108#define homecache_free_page(page) homecache_free_pages((page), 0)
109
110
111/*
112 * Report the page home for LOWMEM pages by examining their kernel PTE,
113 * or for highmem pages as the default home.
114 */
115extern int page_home(struct page *);
116
117#define homecache_migrate_kthread() do {} while (0)
118
119#define homecache_kpte_lock() 0
120#define homecache_kpte_unlock(flags) do {} while (0)
121
122
123#endif /* _ASM_TILE_HOMECACHE_H */
diff --git a/arch/tile/include/asm/hugetlb.h b/arch/tile/include/asm/hugetlb.h
deleted file mode 100644
index 2fac5be4de26..000000000000
--- a/arch/tile/include/asm/hugetlb.h
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_HUGETLB_H
16#define _ASM_TILE_HUGETLB_H
17
18#include <asm/page.h>
19#include <asm-generic/hugetlb.h>
20
21
22static inline int is_hugepage_only_range(struct mm_struct *mm,
23 unsigned long addr,
24 unsigned long len) {
25 return 0;
26}
27
28/*
29 * If the arch doesn't supply something else, assume that hugepage
30 * size aligned regions are ok without further preparation.
31 */
32static inline int prepare_hugepage_range(struct file *file,
33 unsigned long addr, unsigned long len)
34{
35 struct hstate *h = hstate_file(file);
36 if (len & ~huge_page_mask(h))
37 return -EINVAL;
38 if (addr & ~huge_page_mask(h))
39 return -EINVAL;
40 return 0;
41}
42
43static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
44 unsigned long addr, unsigned long end,
45 unsigned long floor,
46 unsigned long ceiling)
47{
48 free_pgd_range(tlb, addr, end, floor, ceiling);
49}
50
51static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
52 pte_t *ptep, pte_t pte)
53{
54 set_pte(ptep, pte);
55}
56
57static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
58 unsigned long addr, pte_t *ptep)
59{
60 return ptep_get_and_clear(mm, addr, ptep);
61}
62
63static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
64 unsigned long addr, pte_t *ptep)
65{
66 ptep_clear_flush(vma, addr, ptep);
67}
68
69static inline int huge_pte_none(pte_t pte)
70{
71 return pte_none(pte);
72}
73
74static inline pte_t huge_pte_wrprotect(pte_t pte)
75{
76 return pte_wrprotect(pte);
77}
78
79static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
80 unsigned long addr, pte_t *ptep)
81{
82 ptep_set_wrprotect(mm, addr, ptep);
83}
84
85static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
86 unsigned long addr, pte_t *ptep,
87 pte_t pte, int dirty)
88{
89 return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
90}
91
92static inline pte_t huge_ptep_get(pte_t *ptep)
93{
94 return *ptep;
95}
96
97static inline void arch_clear_hugepage_flags(struct page *page)
98{
99}
100
101#ifdef CONFIG_HUGETLB_SUPER_PAGES
102static inline pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
103 struct page *page, int writable)
104{
105 size_t pagesize = huge_page_size(hstate_vma(vma));
106 if (pagesize != PUD_SIZE && pagesize != PMD_SIZE)
107 entry = pte_mksuper(entry);
108 return entry;
109}
110#define arch_make_huge_pte arch_make_huge_pte
111
112/* Sizes to scale up page size for PTEs with HV_PTE_SUPER bit. */
113enum {
114 HUGE_SHIFT_PGDIR = 0,
115 HUGE_SHIFT_PMD = 1,
116 HUGE_SHIFT_PAGE = 2,
117 HUGE_SHIFT_ENTRIES
118};
119extern int huge_shift[HUGE_SHIFT_ENTRIES];
120#endif
121
122#endif /* _ASM_TILE_HUGETLB_H */
diff --git a/arch/tile/include/asm/hv_driver.h b/arch/tile/include/asm/hv_driver.h
deleted file mode 100644
index ad614de899b3..000000000000
--- a/arch/tile/include/asm/hv_driver.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * This header defines a wrapper interface for managing hypervisor
15 * device calls that will result in an interrupt at some later time.
16 * In particular, this provides wrappers for hv_preada() and
17 * hv_pwritea().
18 */
19
20#ifndef _ASM_TILE_HV_DRIVER_H
21#define _ASM_TILE_HV_DRIVER_H
22
23#include <hv/hypervisor.h>
24
25struct hv_driver_cb;
26
27/* A callback to be invoked when an operation completes. */
28typedef void hv_driver_callback_t(struct hv_driver_cb *cb, __hv32 result);
29
30/*
31 * A structure to hold information about an outstanding call.
32 * The driver must allocate a separate structure for each call.
33 */
34struct hv_driver_cb {
35 hv_driver_callback_t *callback; /* Function to call on interrupt. */
36 void *dev; /* Driver-specific state variable. */
37};
38
39/* Wrapper for invoking hv_dev_preada(). */
40static inline int
41tile_hv_dev_preada(int devhdl, __hv32 flags, __hv32 sgl_len,
42 HV_SGL sgl[/* sgl_len */], __hv64 offset,
43 struct hv_driver_cb *callback)
44{
45 return hv_dev_preada(devhdl, flags, sgl_len, sgl,
46 offset, (HV_IntArg)callback);
47}
48
49/* Wrapper for invoking hv_dev_pwritea(). */
50static inline int
51tile_hv_dev_pwritea(int devhdl, __hv32 flags, __hv32 sgl_len,
52 HV_SGL sgl[/* sgl_len */], __hv64 offset,
53 struct hv_driver_cb *callback)
54{
55 return hv_dev_pwritea(devhdl, flags, sgl_len, sgl,
56 offset, (HV_IntArg)callback);
57}
58
59
60#endif /* _ASM_TILE_HV_DRIVER_H */
diff --git a/arch/tile/include/asm/ide.h b/arch/tile/include/asm/ide.h
deleted file mode 100644
index 3c6f2ed894ce..000000000000
--- a/arch/tile/include/asm/ide.h
+++ /dev/null
@@ -1,25 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_IDE_H
16#define _ASM_TILE_IDE_H
17
18/* For IDE on PCI */
19#define MAX_HWIFS 10
20
21#define ide_default_io_ctl(base) (0)
22
23#include <asm-generic/ide_iops.h>
24
25#endif /* _ASM_TILE_IDE_H */
diff --git a/arch/tile/include/asm/insn.h b/arch/tile/include/asm/insn.h
deleted file mode 100644
index f78ba5c16722..000000000000
--- a/arch/tile/include/asm/insn.h
+++ /dev/null
@@ -1,59 +0,0 @@
1/*
2 * Copyright 2015 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14#ifndef __ASM_TILE_INSN_H
15#define __ASM_TILE_INSN_H
16
17#include <arch/opcode.h>
18
19static inline tilegx_bundle_bits NOP(void)
20{
21 return create_UnaryOpcodeExtension_X0(FNOP_UNARY_OPCODE_X0) |
22 create_RRROpcodeExtension_X0(UNARY_RRR_0_OPCODE_X0) |
23 create_Opcode_X0(RRR_0_OPCODE_X0) |
24 create_UnaryOpcodeExtension_X1(NOP_UNARY_OPCODE_X1) |
25 create_RRROpcodeExtension_X1(UNARY_RRR_0_OPCODE_X1) |
26 create_Opcode_X1(RRR_0_OPCODE_X1);
27}
28
29static inline tilegx_bundle_bits tilegx_gen_branch(unsigned long pc,
30 unsigned long addr,
31 bool link)
32{
33 tilegx_bundle_bits opcode_x0, opcode_x1;
34 long pcrel_by_instr = (addr - pc) >> TILEGX_LOG2_BUNDLE_SIZE_IN_BYTES;
35
36 if (link) {
37 /* opcode: jal addr */
38 opcode_x1 =
39 create_Opcode_X1(JUMP_OPCODE_X1) |
40 create_JumpOpcodeExtension_X1(JAL_JUMP_OPCODE_X1) |
41 create_JumpOff_X1(pcrel_by_instr);
42 } else {
43 /* opcode: j addr */
44 opcode_x1 =
45 create_Opcode_X1(JUMP_OPCODE_X1) |
46 create_JumpOpcodeExtension_X1(J_JUMP_OPCODE_X1) |
47 create_JumpOff_X1(pcrel_by_instr);
48 }
49
50 /* opcode: fnop */
51 opcode_x0 =
52 create_UnaryOpcodeExtension_X0(FNOP_UNARY_OPCODE_X0) |
53 create_RRROpcodeExtension_X0(UNARY_RRR_0_OPCODE_X0) |
54 create_Opcode_X0(RRR_0_OPCODE_X0);
55
56 return opcode_x1 | opcode_x0;
57}
58
59#endif /* __ASM_TILE_INSN_H */
diff --git a/arch/tile/include/asm/io.h b/arch/tile/include/asm/io.h
deleted file mode 100644
index 30f4a210d148..000000000000
--- a/arch/tile/include/asm/io.h
+++ /dev/null
@@ -1,509 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_IO_H
16#define _ASM_TILE_IO_H
17
18#include <linux/kernel.h>
19#include <linux/bug.h>
20#include <asm/page.h>
21
22/* Maximum PCI I/O space address supported. */
23#define IO_SPACE_LIMIT 0xffffffff
24
25/*
26 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
27 * access.
28 */
29#define xlate_dev_mem_ptr(p) __va(p)
30
31/*
32 * Convert a virtual cached pointer to an uncached pointer.
33 */
34#define xlate_dev_kmem_ptr(p) p
35
36/*
37 * Change "struct page" to physical address.
38 */
39#define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
40
41/*
42 * Some places try to pass in an loff_t for PHYSADDR (?!), so we cast it to
43 * long before casting it to a pointer to avoid compiler warnings.
44 */
45#if CHIP_HAS_MMIO()
46extern void __iomem *ioremap(resource_size_t offset, unsigned long size);
47extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size,
48 pgprot_t pgprot);
49extern void iounmap(volatile void __iomem *addr);
50#else
51#define ioremap(physaddr, size) ((void __iomem *)(unsigned long)(physaddr))
52#define iounmap(addr) ((void)0)
53#endif
54
55#define ioremap_nocache(physaddr, size) ioremap(physaddr, size)
56#define ioremap_wc(physaddr, size) ioremap(physaddr, size)
57#define ioremap_wt(physaddr, size) ioremap(physaddr, size)
58#define ioremap_uc(physaddr, size) ioremap(physaddr, size)
59#define ioremap_fullcache(physaddr, size) ioremap(physaddr, size)
60
61#define mmiowb()
62
63/* Conversion between virtual and physical mappings. */
64#define mm_ptov(addr) ((void *)phys_to_virt(addr))
65#define mm_vtop(addr) ((unsigned long)virt_to_phys(addr))
66
67#if CHIP_HAS_MMIO()
68
69/*
70 * We use inline assembly to guarantee that the compiler does not
71 * split an access into multiple byte-sized accesses as it might
72 * sometimes do if a register data structure is marked "packed".
73 * Obviously on tile we can't tolerate such an access being
74 * actually unaligned, but we want to avoid the case where the
75 * compiler conservatively would generate multiple accesses even
76 * for an aligned read or write.
77 */
78
79static inline u8 __raw_readb(const volatile void __iomem *addr)
80{
81 return *(const volatile u8 __force *)addr;
82}
83
84static inline u16 __raw_readw(const volatile void __iomem *addr)
85{
86 u16 ret;
87 asm volatile("ld2u %0, %1" : "=r" (ret) : "r" (addr));
88 barrier();
89 return le16_to_cpu(ret);
90}
91
92static inline u32 __raw_readl(const volatile void __iomem *addr)
93{
94 u32 ret;
95 /* Sign-extend to conform to u32 ABI sign-extension convention. */
96 asm volatile("ld4s %0, %1" : "=r" (ret) : "r" (addr));
97 barrier();
98 return le32_to_cpu(ret);
99}
100
101static inline u64 __raw_readq(const volatile void __iomem *addr)
102{
103 u64 ret;
104 asm volatile("ld %0, %1" : "=r" (ret) : "r" (addr));
105 barrier();
106 return le64_to_cpu(ret);
107}
108
109static inline void __raw_writeb(u8 val, volatile void __iomem *addr)
110{
111 *(volatile u8 __force *)addr = val;
112}
113
114static inline void __raw_writew(u16 val, volatile void __iomem *addr)
115{
116 asm volatile("st2 %0, %1" :: "r" (addr), "r" (cpu_to_le16(val)));
117}
118
119static inline void __raw_writel(u32 val, volatile void __iomem *addr)
120{
121 asm volatile("st4 %0, %1" :: "r" (addr), "r" (cpu_to_le32(val)));
122}
123
124static inline void __raw_writeq(u64 val, volatile void __iomem *addr)
125{
126 asm volatile("st %0, %1" :: "r" (addr), "r" (cpu_to_le64(val)));
127}
128
129/*
130 * The on-chip I/O hardware on tilegx is configured with VA=PA for the
131 * kernel's PA range. The low-level APIs and field names use "va" and
132 * "void *" nomenclature, to be consistent with the general notion
133 * that the addresses in question are virtualizable, but in the kernel
134 * context we are actually manipulating PA values. (In other contexts,
135 * e.g. access from user space, we do in fact use real virtual addresses
136 * in the va fields.) To allow readers of the code to understand what's
137 * happening, we direct their attention to this comment by using the
138 * following two functions that just duplicate __va() and __pa().
139 */
140typedef unsigned long tile_io_addr_t;
141static inline tile_io_addr_t va_to_tile_io_addr(void *va)
142{
143 BUILD_BUG_ON(sizeof(phys_addr_t) != sizeof(tile_io_addr_t));
144 return __pa(va);
145}
146static inline void *tile_io_addr_to_va(tile_io_addr_t tile_io_addr)
147{
148 return __va(tile_io_addr);
149}
150
151#else /* CHIP_HAS_MMIO() */
152
153#ifdef CONFIG_PCI
154
155extern u8 _tile_readb(unsigned long addr);
156extern u16 _tile_readw(unsigned long addr);
157extern u32 _tile_readl(unsigned long addr);
158extern u64 _tile_readq(unsigned long addr);
159extern void _tile_writeb(u8 val, unsigned long addr);
160extern void _tile_writew(u16 val, unsigned long addr);
161extern void _tile_writel(u32 val, unsigned long addr);
162extern void _tile_writeq(u64 val, unsigned long addr);
163
164#define __raw_readb(addr) _tile_readb((unsigned long)(addr))
165#define __raw_readw(addr) _tile_readw((unsigned long)(addr))
166#define __raw_readl(addr) _tile_readl((unsigned long)(addr))
167#define __raw_readq(addr) _tile_readq((unsigned long)(addr))
168#define __raw_writeb(val, addr) _tile_writeb(val, (unsigned long)(addr))
169#define __raw_writew(val, addr) _tile_writew(val, (unsigned long)(addr))
170#define __raw_writel(val, addr) _tile_writel(val, (unsigned long)(addr))
171#define __raw_writeq(val, addr) _tile_writeq(val, (unsigned long)(addr))
172
173#else /* CONFIG_PCI */
174
175/*
176 * The tilepro architecture does not support IOMEM unless PCI is enabled.
177 * Unfortunately we can't yet simply not declare these methods,
178 * since some generic code that compiles into the kernel, but
179 * we never run, uses them unconditionally.
180 */
181
182static inline int iomem_panic(void)
183{
184 panic("readb/writeb and friends do not exist on tile without PCI");
185 return 0;
186}
187
188static inline u8 readb(unsigned long addr)
189{
190 return iomem_panic();
191}
192
193static inline u16 _readw(unsigned long addr)
194{
195 return iomem_panic();
196}
197
198static inline u32 readl(unsigned long addr)
199{
200 return iomem_panic();
201}
202
203static inline u64 readq(unsigned long addr)
204{
205 return iomem_panic();
206}
207
208static inline void writeb(u8 val, unsigned long addr)
209{
210 iomem_panic();
211}
212
213static inline void writew(u16 val, unsigned long addr)
214{
215 iomem_panic();
216}
217
218static inline void writel(u32 val, unsigned long addr)
219{
220 iomem_panic();
221}
222
223static inline void writeq(u64 val, unsigned long addr)
224{
225 iomem_panic();
226}
227
228#endif /* CONFIG_PCI */
229
230#endif /* CHIP_HAS_MMIO() */
231
232#define readb __raw_readb
233#define readw __raw_readw
234#define readl __raw_readl
235#define readq __raw_readq
236#define writeb __raw_writeb
237#define writew __raw_writew
238#define writel __raw_writel
239#define writeq __raw_writeq
240
241#define readb_relaxed readb
242#define readw_relaxed readw
243#define readl_relaxed readl
244#define readq_relaxed readq
245#define writeb_relaxed writeb
246#define writew_relaxed writew
247#define writel_relaxed writel
248#define writeq_relaxed writeq
249
250#define ioread8 readb
251#define ioread16 readw
252#define ioread32 readl
253#define ioread64 readq
254#define iowrite8 writeb
255#define iowrite16 writew
256#define iowrite32 writel
257#define iowrite64 writeq
258
259#if CHIP_HAS_MMIO() || defined(CONFIG_PCI)
260
261static inline void memset_io(volatile void *dst, int val, size_t len)
262{
263 size_t x;
264 BUG_ON((unsigned long)dst & 0x3);
265 val = (val & 0xff) * 0x01010101;
266 for (x = 0; x < len; x += 4)
267 writel(val, dst + x);
268}
269
270static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
271 size_t len)
272{
273 size_t x;
274 BUG_ON((unsigned long)src & 0x3);
275 for (x = 0; x < len; x += 4)
276 *(u32 *)(dst + x) = readl(src + x);
277}
278
279static inline void memcpy_toio(volatile void __iomem *dst, const void *src,
280 size_t len)
281{
282 size_t x;
283 BUG_ON((unsigned long)dst & 0x3);
284 for (x = 0; x < len; x += 4)
285 writel(*(u32 *)(src + x), dst + x);
286}
287
288#endif
289
290#if CHIP_HAS_MMIO() && defined(CONFIG_TILE_PCI_IO)
291
292static inline u8 inb(unsigned long addr)
293{
294 return readb((volatile void __iomem *) addr);
295}
296
297static inline u16 inw(unsigned long addr)
298{
299 return readw((volatile void __iomem *) addr);
300}
301
302static inline u32 inl(unsigned long addr)
303{
304 return readl((volatile void __iomem *) addr);
305}
306
307static inline void outb(u8 b, unsigned long addr)
308{
309 writeb(b, (volatile void __iomem *) addr);
310}
311
312static inline void outw(u16 b, unsigned long addr)
313{
314 writew(b, (volatile void __iomem *) addr);
315}
316
317static inline void outl(u32 b, unsigned long addr)
318{
319 writel(b, (volatile void __iomem *) addr);
320}
321
322static inline void insb(unsigned long addr, void *buffer, int count)
323{
324 if (count) {
325 u8 *buf = buffer;
326 do {
327 u8 x = inb(addr);
328 *buf++ = x;
329 } while (--count);
330 }
331}
332
333static inline void insw(unsigned long addr, void *buffer, int count)
334{
335 if (count) {
336 u16 *buf = buffer;
337 do {
338 u16 x = inw(addr);
339 *buf++ = x;
340 } while (--count);
341 }
342}
343
344static inline void insl(unsigned long addr, void *buffer, int count)
345{
346 if (count) {
347 u32 *buf = buffer;
348 do {
349 u32 x = inl(addr);
350 *buf++ = x;
351 } while (--count);
352 }
353}
354
355static inline void outsb(unsigned long addr, const void *buffer, int count)
356{
357 if (count) {
358 const u8 *buf = buffer;
359 do {
360 outb(*buf++, addr);
361 } while (--count);
362 }
363}
364
365static inline void outsw(unsigned long addr, const void *buffer, int count)
366{
367 if (count) {
368 const u16 *buf = buffer;
369 do {
370 outw(*buf++, addr);
371 } while (--count);
372 }
373}
374
375static inline void outsl(unsigned long addr, const void *buffer, int count)
376{
377 if (count) {
378 const u32 *buf = buffer;
379 do {
380 outl(*buf++, addr);
381 } while (--count);
382 }
383}
384
385extern void __iomem *ioport_map(unsigned long port, unsigned int len);
386extern void ioport_unmap(void __iomem *addr);
387
388#else
389
390/*
391 * The TilePro architecture does not support IOPORT, even with PCI.
392 * Unfortunately we can't yet simply not declare these methods,
393 * since some generic code that compiles into the kernel, but
394 * we never run, uses them unconditionally.
395 */
396
397static inline long ioport_panic(void)
398{
399#ifdef __tilegx__
400 panic("PCI IO space support is disabled. Configure the kernel with CONFIG_TILE_PCI_IO to enable it");
401#else
402 panic("inb/outb and friends do not exist on tile");
403#endif
404 return 0;
405}
406
407static inline void __iomem *ioport_map(unsigned long port, unsigned int len)
408{
409 pr_info("ioport_map: mapping IO resources is unsupported on tile\n");
410 return NULL;
411}
412
413static inline void ioport_unmap(void __iomem *addr)
414{
415 ioport_panic();
416}
417
418static inline u8 inb(unsigned long addr)
419{
420 return ioport_panic();
421}
422
423static inline u16 inw(unsigned long addr)
424{
425 return ioport_panic();
426}
427
428static inline u32 inl(unsigned long addr)
429{
430 return ioport_panic();
431}
432
433static inline void outb(u8 b, unsigned long addr)
434{
435 ioport_panic();
436}
437
438static inline void outw(u16 b, unsigned long addr)
439{
440 ioport_panic();
441}
442
443static inline void outl(u32 b, unsigned long addr)
444{
445 ioport_panic();
446}
447
448static inline void insb(unsigned long addr, void *buffer, int count)
449{
450 ioport_panic();
451}
452
453static inline void insw(unsigned long addr, void *buffer, int count)
454{
455 ioport_panic();
456}
457
458static inline void insl(unsigned long addr, void *buffer, int count)
459{
460 ioport_panic();
461}
462
463static inline void outsb(unsigned long addr, const void *buffer, int count)
464{
465 ioport_panic();
466}
467
468static inline void outsw(unsigned long addr, const void *buffer, int count)
469{
470 ioport_panic();
471}
472
473static inline void outsl(unsigned long addr, const void *buffer, int count)
474{
475 ioport_panic();
476}
477
478#endif /* CHIP_HAS_MMIO() && defined(CONFIG_TILE_PCI_IO) */
479
480#define inb_p(addr) inb(addr)
481#define inw_p(addr) inw(addr)
482#define inl_p(addr) inl(addr)
483#define outb_p(x, addr) outb((x), (addr))
484#define outw_p(x, addr) outw((x), (addr))
485#define outl_p(x, addr) outl((x), (addr))
486
487#define ioread16be(addr) be16_to_cpu(ioread16(addr))
488#define ioread32be(addr) be32_to_cpu(ioread32(addr))
489#define iowrite16be(v, addr) iowrite16(be16_to_cpu(v), (addr))
490#define iowrite32be(v, addr) iowrite32(be32_to_cpu(v), (addr))
491
492#define ioread8_rep(p, dst, count) \
493 insb((unsigned long) (p), (dst), (count))
494#define ioread16_rep(p, dst, count) \
495 insw((unsigned long) (p), (dst), (count))
496#define ioread32_rep(p, dst, count) \
497 insl((unsigned long) (p), (dst), (count))
498
499#define iowrite8_rep(p, src, count) \
500 outsb((unsigned long) (p), (src), (count))
501#define iowrite16_rep(p, src, count) \
502 outsw((unsigned long) (p), (src), (count))
503#define iowrite32_rep(p, src, count) \
504 outsl((unsigned long) (p), (src), (count))
505
506#define virt_to_bus virt_to_phys
507#define bus_to_virt phys_to_virt
508
509#endif /* _ASM_TILE_IO_H */
diff --git a/arch/tile/include/asm/irq.h b/arch/tile/include/asm/irq.h
deleted file mode 100644
index 1fa1f2544ff9..000000000000
--- a/arch/tile/include/asm/irq.h
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_IRQ_H
16#define _ASM_TILE_IRQ_H
17
18#include <linux/hardirq.h>
19
20/* The hypervisor interface provides 32 IRQs. */
21#define NR_IRQS 32
22
23/* IRQ numbers used for linux IPIs. */
24#define IRQ_RESCHEDULE 0
25/* Interrupts for dynamic allocation start at 1. Let the core allocate irq0 */
26#define NR_IRQS_LEGACY 1
27
28#define irq_canonicalize(irq) (irq)
29
30void ack_bad_irq(unsigned int irq);
31
32/*
33 * Different ways of handling interrupts. Tile interrupts are always
34 * per-cpu; there is no global interrupt controller to implement
35 * enable/disable. Most onboard devices can send their interrupts to
36 * many tiles at the same time, and Tile-specific drivers know how to
37 * deal with this.
38 *
39 * However, generic devices (usually PCIE based, sometimes GPIO)
40 * expect that interrupts will fire on a single core at a time and
41 * that the irq can be enabled or disabled from any core at any time.
42 * We implement this by directing such interrupts to a single core.
43 *
44 * One added wrinkle is that PCI interrupts can be either
45 * hardware-cleared (legacy interrupts) or software cleared (MSI).
46 * Other generic device systems (GPIO) are always software-cleared.
47 *
48 * The enums below are used by drivers for onboard devices, including
49 * the internals of PCI root complex and GPIO. They allow the driver
50 * to tell the generic irq code what kind of interrupt is mapped to a
51 * particular IRQ number.
52 */
53enum {
54 /* per-cpu interrupt; use enable/disable_percpu_irq() to mask */
55 TILE_IRQ_PERCPU,
56 /* global interrupt, hardware responsible for clearing. */
57 TILE_IRQ_HW_CLEAR,
58 /* global interrupt, software responsible for clearing. */
59 TILE_IRQ_SW_CLEAR,
60};
61
62
63/*
64 * Paravirtualized drivers should call this when they dynamically
65 * allocate a new IRQ or discover an IRQ that was pre-allocated by the
66 * hypervisor for use with their particular device. This gives the
67 * IRQ subsystem an opportunity to do interrupt-type-specific
68 * initialization.
69 *
70 * ISSUE: We should modify this API so that registering anything
71 * except percpu interrupts also requires providing callback methods
72 * for enabling and disabling the interrupt. This would allow the
73 * generic IRQ code to proxy enable/disable_irq() calls back into the
74 * PCI subsystem, which in turn could enable or disable the interrupt
75 * at the PCI shim.
76 */
77void tile_irq_activate(unsigned int irq, int tile_irq_type);
78
79void setup_irq_regs(void);
80
81#ifdef __tilegx__
82void arch_trigger_cpumask_backtrace(const struct cpumask *mask,
83 bool exclude_self);
84#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace
85#endif
86
87#endif /* _ASM_TILE_IRQ_H */
diff --git a/arch/tile/include/asm/irq_work.h b/arch/tile/include/asm/irq_work.h
deleted file mode 100644
index 78d3b6a7b27a..000000000000
--- a/arch/tile/include/asm/irq_work.h
+++ /dev/null
@@ -1,15 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __ASM_IRQ_WORK_H
3#define __ASM_IRQ_WORK_H
4
5static inline bool arch_irq_work_has_interrupt(void)
6{
7#ifdef CONFIG_SMP
8 extern bool self_interrupt_ok;
9 return self_interrupt_ok;
10#else
11 return false;
12#endif
13}
14
15#endif /* __ASM_IRQ_WORK_H */
diff --git a/arch/tile/include/asm/irqflags.h b/arch/tile/include/asm/irqflags.h
deleted file mode 100644
index 60d62a292fce..000000000000
--- a/arch/tile/include/asm/irqflags.h
+++ /dev/null
@@ -1,311 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_IRQFLAGS_H
16#define _ASM_TILE_IRQFLAGS_H
17
18#include <arch/interrupts.h>
19#include <arch/chip.h>
20
21/*
22 * The set of interrupts we want to allow when interrupts are nominally
23 * disabled. The remainder are effectively "NMI" interrupts from
24 * the point of view of the generic Linux code. Note that synchronous
25 * interrupts (aka "non-queued") are not blocked by the mask in any case.
26 */
27#define LINUX_MASKABLE_INTERRUPTS \
28 (~((_AC(1,ULL) << INT_PERF_COUNT) | (_AC(1,ULL) << INT_AUX_PERF_COUNT)))
29
30#if CHIP_HAS_SPLIT_INTR_MASK()
31/* The same macro, but for the two 32-bit SPRs separately. */
32#define LINUX_MASKABLE_INTERRUPTS_LO (-1)
33#define LINUX_MASKABLE_INTERRUPTS_HI \
34 (~((1 << (INT_PERF_COUNT - 32)) | (1 << (INT_AUX_PERF_COUNT - 32))))
35#endif
36
37#ifndef __ASSEMBLY__
38
39/* NOTE: we can't include <linux/percpu.h> due to #include dependencies. */
40#include <asm/percpu.h>
41#include <arch/spr_def.h>
42
43/*
44 * Set and clear kernel interrupt masks.
45 *
46 * NOTE: __insn_mtspr() is a compiler builtin marked as a memory
47 * clobber. We rely on it being equivalent to a compiler barrier in
48 * this code since arch_local_irq_save() and friends must act as
49 * compiler barriers. This compiler semantic is baked into enough
50 * places that the compiler will maintain it going forward.
51 */
52#if CHIP_HAS_SPLIT_INTR_MASK()
53#if INT_PERF_COUNT < 32 || INT_AUX_PERF_COUNT < 32 || INT_MEM_ERROR >= 32
54# error Fix assumptions about which word various interrupts are in
55#endif
56#define interrupt_mask_set(n) do { \
57 int __n = (n); \
58 int __mask = 1 << (__n & 0x1f); \
59 if (__n < 32) \
60 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K_0, __mask); \
61 else \
62 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K_1, __mask); \
63} while (0)
64#define interrupt_mask_reset(n) do { \
65 int __n = (n); \
66 int __mask = 1 << (__n & 0x1f); \
67 if (__n < 32) \
68 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_0, __mask); \
69 else \
70 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_1, __mask); \
71} while (0)
72#define interrupt_mask_check(n) ({ \
73 int __n = (n); \
74 (((__n < 32) ? \
75 __insn_mfspr(SPR_INTERRUPT_MASK_K_0) : \
76 __insn_mfspr(SPR_INTERRUPT_MASK_K_1)) \
77 >> (__n & 0x1f)) & 1; \
78})
79#define interrupt_mask_set_mask(mask) do { \
80 unsigned long long __m = (mask); \
81 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K_0, (unsigned long)(__m)); \
82 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K_1, (unsigned long)(__m>>32)); \
83} while (0)
84#define interrupt_mask_reset_mask(mask) do { \
85 unsigned long long __m = (mask); \
86 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_0, (unsigned long)(__m)); \
87 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K_1, (unsigned long)(__m>>32)); \
88} while (0)
89#define interrupt_mask_save_mask() \
90 (__insn_mfspr(SPR_INTERRUPT_MASK_SET_K_0) | \
91 (((unsigned long long)__insn_mfspr(SPR_INTERRUPT_MASK_SET_K_1))<<32))
92#define interrupt_mask_restore_mask(mask) do { \
93 unsigned long long __m = (mask); \
94 __insn_mtspr(SPR_INTERRUPT_MASK_K_0, (unsigned long)(__m)); \
95 __insn_mtspr(SPR_INTERRUPT_MASK_K_1, (unsigned long)(__m>>32)); \
96} while (0)
97#else
98#define interrupt_mask_set(n) \
99 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K, (1UL << (n)))
100#define interrupt_mask_reset(n) \
101 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K, (1UL << (n)))
102#define interrupt_mask_check(n) \
103 ((__insn_mfspr(SPR_INTERRUPT_MASK_K) >> (n)) & 1)
104#define interrupt_mask_set_mask(mask) \
105 __insn_mtspr(SPR_INTERRUPT_MASK_SET_K, (mask))
106#define interrupt_mask_reset_mask(mask) \
107 __insn_mtspr(SPR_INTERRUPT_MASK_RESET_K, (mask))
108#define interrupt_mask_save_mask() \
109 __insn_mfspr(SPR_INTERRUPT_MASK_K)
110#define interrupt_mask_restore_mask(mask) \
111 __insn_mtspr(SPR_INTERRUPT_MASK_K, (mask))
112#endif
113
114/*
115 * The set of interrupts we want active if irqs are enabled.
116 * Note that in particular, the tile timer interrupt comes and goes
117 * from this set, since we have no other way to turn off the timer.
118 * Likewise, INTCTRL_K is removed and re-added during device
119 * interrupts, as is the the hardwall UDN_FIREWALL interrupt.
120 * We use a low bit (MEM_ERROR) as our sentinel value and make sure it
121 * is always claimed as an "active interrupt" so we can query that bit
122 * to know our current state.
123 */
124DECLARE_PER_CPU(unsigned long long, interrupts_enabled_mask);
125#define INITIAL_INTERRUPTS_ENABLED (1ULL << INT_MEM_ERROR)
126
127#ifdef CONFIG_DEBUG_PREEMPT
128/* Due to inclusion issues, we can't rely on <linux/smp.h> here. */
129extern unsigned int debug_smp_processor_id(void);
130# define smp_processor_id() debug_smp_processor_id()
131#endif
132
133/* Disable interrupts. */
134#define arch_local_irq_disable() \
135 interrupt_mask_set_mask(LINUX_MASKABLE_INTERRUPTS)
136
137/* Disable all interrupts, including NMIs. */
138#define arch_local_irq_disable_all() \
139 interrupt_mask_set_mask(-1ULL)
140
141/*
142 * Read the set of maskable interrupts.
143 * We avoid the preemption warning here via raw_cpu_ptr since even
144 * if irqs are already enabled, it's harmless to read the wrong cpu's
145 * enabled mask.
146 */
147#define arch_local_irqs_enabled() \
148 (*raw_cpu_ptr(&interrupts_enabled_mask))
149
150/* Re-enable all maskable interrupts. */
151#define arch_local_irq_enable() \
152 interrupt_mask_reset_mask(arch_local_irqs_enabled())
153
154/* Disable or enable interrupts based on flag argument. */
155#define arch_local_irq_restore(disabled) do { \
156 if (disabled) \
157 arch_local_irq_disable(); \
158 else \
159 arch_local_irq_enable(); \
160} while (0)
161
162/* Return true if "flags" argument means interrupts are disabled. */
163#define arch_irqs_disabled_flags(flags) ((flags) != 0)
164
165/* Return true if interrupts are currently disabled. */
166#define arch_irqs_disabled() interrupt_mask_check(INT_MEM_ERROR)
167
168/* Save whether interrupts are currently disabled. */
169#define arch_local_save_flags() arch_irqs_disabled()
170
171/* Save whether interrupts are currently disabled, then disable them. */
172#define arch_local_irq_save() ({ \
173 unsigned long __flags = arch_local_save_flags(); \
174 arch_local_irq_disable(); \
175 __flags; })
176
177/* Prevent the given interrupt from being enabled next time we enable irqs. */
178#define arch_local_irq_mask(interrupt) \
179 this_cpu_and(interrupts_enabled_mask, ~(1ULL << (interrupt)))
180
181/* Prevent the given interrupt from being enabled immediately. */
182#define arch_local_irq_mask_now(interrupt) do { \
183 arch_local_irq_mask(interrupt); \
184 interrupt_mask_set(interrupt); \
185} while (0)
186
187/* Allow the given interrupt to be enabled next time we enable irqs. */
188#define arch_local_irq_unmask(interrupt) \
189 this_cpu_or(interrupts_enabled_mask, (1ULL << (interrupt)))
190
191/* Allow the given interrupt to be enabled immediately, if !irqs_disabled. */
192#define arch_local_irq_unmask_now(interrupt) do { \
193 arch_local_irq_unmask(interrupt); \
194 if (!irqs_disabled()) \
195 interrupt_mask_reset(interrupt); \
196} while (0)
197
198#else /* __ASSEMBLY__ */
199
200/* We provide a somewhat more restricted set for assembly. */
201
202#ifdef __tilegx__
203
204#if INT_MEM_ERROR != 0
205# error Fix IRQS_DISABLED() macro
206#endif
207
208/* Return 0 or 1 to indicate whether interrupts are currently disabled. */
209#define IRQS_DISABLED(tmp) \
210 mfspr tmp, SPR_INTERRUPT_MASK_K; \
211 andi tmp, tmp, 1
212
213/* Load up a pointer to &interrupts_enabled_mask. */
214#define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
215 moveli reg, hw2_last(interrupts_enabled_mask); \
216 shl16insli reg, reg, hw1(interrupts_enabled_mask); \
217 shl16insli reg, reg, hw0(interrupts_enabled_mask); \
218 add reg, reg, tp
219
220/* Disable interrupts. */
221#define IRQ_DISABLE(tmp0, tmp1) \
222 moveli tmp0, hw2_last(LINUX_MASKABLE_INTERRUPTS); \
223 shl16insli tmp0, tmp0, hw1(LINUX_MASKABLE_INTERRUPTS); \
224 shl16insli tmp0, tmp0, hw0(LINUX_MASKABLE_INTERRUPTS); \
225 mtspr SPR_INTERRUPT_MASK_SET_K, tmp0
226
227/* Disable ALL synchronous interrupts (used by NMI entry). */
228#define IRQ_DISABLE_ALL(tmp) \
229 movei tmp, -1; \
230 mtspr SPR_INTERRUPT_MASK_SET_K, tmp
231
232/* Enable interrupts. */
233#define IRQ_ENABLE_LOAD(tmp0, tmp1) \
234 GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
235 ld tmp0, tmp0
236#define IRQ_ENABLE_APPLY(tmp0, tmp1) \
237 mtspr SPR_INTERRUPT_MASK_RESET_K, tmp0
238
239#else /* !__tilegx__ */
240
241/*
242 * Return 0 or 1 to indicate whether interrupts are currently disabled.
243 * Note that it's important that we use a bit from the "low" mask word,
244 * since when we are enabling, that is the word we write first, so if we
245 * are interrupted after only writing half of the mask, the interrupt
246 * handler will correctly observe that we have interrupts enabled, and
247 * will enable interrupts itself on return from the interrupt handler
248 * (making the original code's write of the "high" mask word idempotent).
249 */
250#define IRQS_DISABLED(tmp) \
251 mfspr tmp, SPR_INTERRUPT_MASK_K_0; \
252 shri tmp, tmp, INT_MEM_ERROR; \
253 andi tmp, tmp, 1
254
255/* Load up a pointer to &interrupts_enabled_mask. */
256#define GET_INTERRUPTS_ENABLED_MASK_PTR(reg) \
257 moveli reg, lo16(interrupts_enabled_mask); \
258 auli reg, reg, ha16(interrupts_enabled_mask); \
259 add reg, reg, tp
260
261/* Disable interrupts. */
262#define IRQ_DISABLE(tmp0, tmp1) \
263 { \
264 movei tmp0, LINUX_MASKABLE_INTERRUPTS_LO; \
265 moveli tmp1, lo16(LINUX_MASKABLE_INTERRUPTS_HI) \
266 }; \
267 { \
268 mtspr SPR_INTERRUPT_MASK_SET_K_0, tmp0; \
269 auli tmp1, tmp1, ha16(LINUX_MASKABLE_INTERRUPTS_HI) \
270 }; \
271 mtspr SPR_INTERRUPT_MASK_SET_K_1, tmp1
272
273/* Disable ALL synchronous interrupts (used by NMI entry). */
274#define IRQ_DISABLE_ALL(tmp) \
275 movei tmp, -1; \
276 mtspr SPR_INTERRUPT_MASK_SET_K_0, tmp; \
277 mtspr SPR_INTERRUPT_MASK_SET_K_1, tmp
278
279/* Enable interrupts. */
280#define IRQ_ENABLE_LOAD(tmp0, tmp1) \
281 GET_INTERRUPTS_ENABLED_MASK_PTR(tmp0); \
282 { \
283 lw tmp0, tmp0; \
284 addi tmp1, tmp0, 4 \
285 }; \
286 lw tmp1, tmp1
287#define IRQ_ENABLE_APPLY(tmp0, tmp1) \
288 mtspr SPR_INTERRUPT_MASK_RESET_K_0, tmp0; \
289 mtspr SPR_INTERRUPT_MASK_RESET_K_1, tmp1
290#endif
291
292#define IRQ_ENABLE(tmp0, tmp1) \
293 IRQ_ENABLE_LOAD(tmp0, tmp1); \
294 IRQ_ENABLE_APPLY(tmp0, tmp1)
295
296/*
297 * Do the CPU's IRQ-state tracing from assembly code. We call a
298 * C function, but almost everywhere we do, we don't mind clobbering
299 * all the caller-saved registers.
300 */
301#ifdef CONFIG_TRACE_IRQFLAGS
302# define TRACE_IRQS_ON jal trace_hardirqs_on
303# define TRACE_IRQS_OFF jal trace_hardirqs_off
304#else
305# define TRACE_IRQS_ON
306# define TRACE_IRQS_OFF
307#endif
308
309#endif /* __ASSEMBLY__ */
310
311#endif /* _ASM_TILE_IRQFLAGS_H */
diff --git a/arch/tile/include/asm/jump_label.h b/arch/tile/include/asm/jump_label.h
deleted file mode 100644
index cde7573f397b..000000000000
--- a/arch/tile/include/asm/jump_label.h
+++ /dev/null
@@ -1,58 +0,0 @@
1/*
2 * Copyright 2015 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_JUMP_LABEL_H
16#define _ASM_TILE_JUMP_LABEL_H
17
18#include <arch/opcode.h>
19
20#define JUMP_LABEL_NOP_SIZE TILE_BUNDLE_SIZE_IN_BYTES
21
22static __always_inline bool arch_static_branch(struct static_key *key,
23 bool branch)
24{
25 asm_volatile_goto("1:\n\t"
26 "nop" "\n\t"
27 ".pushsection __jump_table, \"aw\"\n\t"
28 ".quad 1b, %l[l_yes], %0 + %1 \n\t"
29 ".popsection\n\t"
30 : : "i" (key), "i" (branch) : : l_yes);
31 return false;
32l_yes:
33 return true;
34}
35
36static __always_inline bool arch_static_branch_jump(struct static_key *key,
37 bool branch)
38{
39 asm_volatile_goto("1:\n\t"
40 "j %l[l_yes]" "\n\t"
41 ".pushsection __jump_table, \"aw\"\n\t"
42 ".quad 1b, %l[l_yes], %0 + %1 \n\t"
43 ".popsection\n\t"
44 : : "i" (key), "i" (branch) : : l_yes);
45 return false;
46l_yes:
47 return true;
48}
49
50typedef u64 jump_label_t;
51
52struct jump_entry {
53 jump_label_t code;
54 jump_label_t target;
55 jump_label_t key;
56};
57
58#endif /* _ASM_TILE_JUMP_LABEL_H */
diff --git a/arch/tile/include/asm/kdebug.h b/arch/tile/include/asm/kdebug.h
deleted file mode 100644
index 5bbbfa904c2d..000000000000
--- a/arch/tile/include/asm/kdebug.h
+++ /dev/null
@@ -1,28 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_KDEBUG_H
16#define _ASM_TILE_KDEBUG_H
17
18#include <linux/notifier.h>
19
20enum die_val {
21 DIE_OOPS = 1,
22 DIE_BREAK,
23 DIE_SSTEPBP,
24 DIE_PAGE_FAULT,
25 DIE_COMPILED_BPT
26};
27
28#endif /* _ASM_TILE_KDEBUG_H */
diff --git a/arch/tile/include/asm/kexec.h b/arch/tile/include/asm/kexec.h
deleted file mode 100644
index fc98ccfc98ac..000000000000
--- a/arch/tile/include/asm/kexec.h
+++ /dev/null
@@ -1,65 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * based on kexec.h from other architectures in linux-2.6.18
15 */
16
17#ifndef _ASM_TILE_KEXEC_H
18#define _ASM_TILE_KEXEC_H
19
20#include <asm/page.h>
21
22#ifndef __tilegx__
23/* Maximum physical address we can use pages from. */
24#define KEXEC_SOURCE_MEMORY_LIMIT TASK_SIZE
25/* Maximum address we can reach in physical address mode. */
26#define KEXEC_DESTINATION_MEMORY_LIMIT TASK_SIZE
27/* Maximum address we can use for the control code buffer. */
28#define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
29#else
30/* We need to limit the memory below PGDIR_SIZE since
31 * we only setup page table for [0, PGDIR_SIZE) before final kexec.
32 */
33/* Maximum physical address we can use pages from. */
34#define KEXEC_SOURCE_MEMORY_LIMIT PGDIR_SIZE
35/* Maximum address we can reach in physical address mode. */
36#define KEXEC_DESTINATION_MEMORY_LIMIT PGDIR_SIZE
37/* Maximum address we can use for the control code buffer. */
38#define KEXEC_CONTROL_MEMORY_LIMIT PGDIR_SIZE
39#endif
40
41#define KEXEC_CONTROL_PAGE_SIZE PAGE_SIZE
42
43/*
44 * We don't bother to provide a unique identifier, since we can only
45 * reboot with a single type of kernel image anyway.
46 */
47#define KEXEC_ARCH KEXEC_ARCH_DEFAULT
48
49/* Use the tile override for the page allocator. */
50struct page *kimage_alloc_pages_arch(gfp_t gfp_mask, unsigned int order);
51#define kimage_alloc_pages_arch kimage_alloc_pages_arch
52
53#define MAX_NOTE_BYTES 1024
54
55/* Defined in arch/tile/kernel/relocate_kernel.S */
56extern const unsigned char relocate_new_kernel[];
57extern const unsigned long relocate_new_kernel_size;
58extern void relocate_new_kernel_end(void);
59
60/* Provide a dummy definition to avoid build failures. */
61static inline void crash_setup_regs(struct pt_regs *n, struct pt_regs *o)
62{
63}
64
65#endif /* _ASM_TILE_KEXEC_H */
diff --git a/arch/tile/include/asm/kgdb.h b/arch/tile/include/asm/kgdb.h
deleted file mode 100644
index 280c181cf0db..000000000000
--- a/arch/tile/include/asm/kgdb.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE-Gx KGDB support.
15 */
16
17#ifndef __TILE_KGDB_H__
18#define __TILE_KGDB_H__
19
20#include <linux/kdebug.h>
21#include <arch/opcode.h>
22
23#define GDB_SIZEOF_REG sizeof(unsigned long)
24
25/*
26 * TILE-Gx gdb is expecting the following register layout:
27 * 56 GPRs(R0 - R52, TP, SP, LR), 8 special GPRs(networks and ZERO),
28 * plus the PC and the faultnum.
29 *
30 * Even though kernel not use the 8 special GPRs, they need to be present
31 * in the registers sent for correct processing in the host-side gdb.
32 *
33 */
34#define DBG_MAX_REG_NUM (56+8+2)
35#define NUMREGBYTES (DBG_MAX_REG_NUM * GDB_SIZEOF_REG)
36
37/*
38 * BUFMAX defines the maximum number of characters in inbound/outbound
39 * buffers at least NUMREGBYTES*2 are needed for register packets,
40 * Longer buffer is needed to list all threads.
41 */
42#define BUFMAX 2048
43
44#define BREAK_INSTR_SIZE TILEGX_BUNDLE_SIZE_IN_BYTES
45
46/*
47 * Require cache flush for set/clear a software breakpoint or write memory.
48 */
49#define CACHE_FLUSH_IS_SAFE 1
50
51/*
52 * The compiled-in breakpoint instruction can be used to "break" into
53 * the debugger via magic system request key (sysrq-G).
54 */
55static tile_bundle_bits compiled_bpt = TILEGX_BPT_BUNDLE | DIE_COMPILED_BPT;
56
57enum tilegx_regnum {
58 TILEGX_PC_REGNUM = TREG_LAST_GPR + 9,
59 TILEGX_FAULTNUM_REGNUM,
60};
61
62/*
63 * Generate a breakpoint exception to "break" into the debugger.
64 */
65static inline void arch_kgdb_breakpoint(void)
66{
67 asm volatile (".quad %0\n\t"
68 ::""(compiled_bpt));
69}
70
71#endif /* __TILE_KGDB_H__ */
diff --git a/arch/tile/include/asm/kmap_types.h b/arch/tile/include/asm/kmap_types.h
deleted file mode 100644
index 92b28e3e9972..000000000000
--- a/arch/tile/include/asm/kmap_types.h
+++ /dev/null
@@ -1,28 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_KMAP_TYPES_H
16#define _ASM_TILE_KMAP_TYPES_H
17
18/*
19 * In 32-bit TILE Linux we have to balance the desire to have a lot of
20 * nested atomic mappings with the fact that large page sizes and many
21 * processors chew up address space quickly. In a typical
22 * 64-processor, 64KB-page layout build, making KM_TYPE_NR one larger
23 * adds 4MB of required address-space. For now we leave KM_TYPE_NR
24 * set to depth 8.
25 */
26#define KM_TYPE_NR 8
27
28#endif /* _ASM_TILE_KMAP_TYPES_H */
diff --git a/arch/tile/include/asm/kprobes.h b/arch/tile/include/asm/kprobes.h
deleted file mode 100644
index 4a8b1cadca24..000000000000
--- a/arch/tile/include/asm/kprobes.h
+++ /dev/null
@@ -1,83 +0,0 @@
1/*
2 * arch/tile/include/asm/kprobes.h
3 *
4 * Copyright 2012 Tilera Corporation. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for
14 * more details.
15 */
16
17#ifndef _ASM_TILE_KPROBES_H
18#define _ASM_TILE_KPROBES_H
19
20#include <asm-generic/kprobes.h>
21
22#ifdef CONFIG_KPROBES
23
24#include <linux/types.h>
25#include <linux/ptrace.h>
26#include <linux/percpu.h>
27#include <arch/opcode.h>
28
29#define __ARCH_WANT_KPROBES_INSN_SLOT
30#define MAX_INSN_SIZE 2
31
32#define kretprobe_blacklist_size 0
33
34typedef tile_bundle_bits kprobe_opcode_t;
35
36#define flush_insn_slot(p) \
37 flush_icache_range((unsigned long)p->addr, \
38 (unsigned long)p->addr + \
39 (MAX_INSN_SIZE * sizeof(kprobe_opcode_t)))
40
41struct kprobe;
42
43/* Architecture specific copy of original instruction. */
44struct arch_specific_insn {
45 kprobe_opcode_t *insn;
46};
47
48struct prev_kprobe {
49 struct kprobe *kp;
50 unsigned long status;
51 unsigned long saved_pc;
52};
53
54#define MAX_JPROBES_STACK_SIZE 128
55#define MAX_JPROBES_STACK_ADDR \
56 (((unsigned long)current_thread_info()) + THREAD_SIZE - 32 \
57 - sizeof(struct pt_regs))
58
59#define MIN_JPROBES_STACK_SIZE(ADDR) \
60 ((((ADDR) + MAX_JPROBES_STACK_SIZE) > MAX_JPROBES_STACK_ADDR) \
61 ? MAX_JPROBES_STACK_ADDR - (ADDR) \
62 : MAX_JPROBES_STACK_SIZE)
63
64/* per-cpu kprobe control block. */
65struct kprobe_ctlblk {
66 unsigned long kprobe_status;
67 unsigned long kprobe_saved_pc;
68 unsigned long jprobe_saved_sp;
69 struct prev_kprobe prev_kprobe;
70 struct pt_regs jprobe_saved_regs;
71 char jprobes_stack[MAX_JPROBES_STACK_SIZE];
72};
73
74extern tile_bundle_bits breakpoint2_insn;
75extern tile_bundle_bits breakpoint_insn;
76
77void arch_remove_kprobe(struct kprobe *);
78
79extern int kprobe_exceptions_notify(struct notifier_block *self,
80 unsigned long val, void *data);
81
82#endif /* CONFIG_KPROBES */
83#endif /* _ASM_TILE_KPROBES_H */
diff --git a/arch/tile/include/asm/linkage.h b/arch/tile/include/asm/linkage.h
deleted file mode 100644
index e121c39751a7..000000000000
--- a/arch/tile/include/asm/linkage.h
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_LINKAGE_H
16#define _ASM_TILE_LINKAGE_H
17
18#include <feedback.h>
19
20#define __ALIGN .align 8
21
22/*
23 * The STD_ENTRY and STD_ENDPROC macros put the function in a
24 * self-named .text.foo section, and if linker feedback collection
25 * is enabled, add a suitable call to the feedback collection code.
26 * STD_ENTRY_SECTION lets you specify a non-standard section name.
27 */
28
29#define STD_ENTRY(name) \
30 .pushsection .text.##name, "ax"; \
31 ENTRY(name); \
32 FEEDBACK_ENTER(name)
33
34#define STD_ENTRY_SECTION(name, section) \
35 .pushsection section, "ax"; \
36 ENTRY(name); \
37 FEEDBACK_ENTER_EXPLICIT(name, section, .Lend_##name - name)
38
39#define STD_ENDPROC(name) \
40 ENDPROC(name); \
41 .Lend_##name:; \
42 .popsection
43
44/* Create a file-static function entry set up for feedback gathering. */
45#define STD_ENTRY_LOCAL(name) \
46 .pushsection .text.##name, "ax"; \
47 ALIGN; \
48 name:; \
49 FEEDBACK_ENTER(name)
50
51#endif /* _ASM_TILE_LINKAGE_H */
diff --git a/arch/tile/include/asm/mmu.h b/arch/tile/include/asm/mmu.h
deleted file mode 100644
index 0cab1182bde1..000000000000
--- a/arch/tile/include/asm/mmu.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_MMU_H
16#define _ASM_TILE_MMU_H
17
18/* Capture any arch- and mm-specific information. */
19struct mm_context {
20 /*
21 * Written under the mmap_sem semaphore; read without the
22 * semaphore but atomically, but it is conservatively set.
23 */
24 unsigned long priority_cached;
25 unsigned long vdso_base;
26};
27
28typedef struct mm_context mm_context_t;
29
30void leave_mm(int cpu);
31
32#endif /* _ASM_TILE_MMU_H */
diff --git a/arch/tile/include/asm/mmu_context.h b/arch/tile/include/asm/mmu_context.h
deleted file mode 100644
index 45a4b4c424cf..000000000000
--- a/arch/tile/include/asm/mmu_context.h
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_MMU_CONTEXT_H
16#define _ASM_TILE_MMU_CONTEXT_H
17
18#include <linux/smp.h>
19#include <linux/mm_types.h>
20
21#include <asm/setup.h>
22#include <asm/page.h>
23#include <asm/pgalloc.h>
24#include <asm/pgtable.h>
25#include <asm/tlbflush.h>
26#include <asm/homecache.h>
27#include <asm-generic/mm_hooks.h>
28
29static inline int
30init_new_context(struct task_struct *tsk, struct mm_struct *mm)
31{
32 return 0;
33}
34
35/*
36 * Note that arch/tile/kernel/head_NN.S and arch/tile/mm/migrate_NN.S
37 * also call hv_install_context().
38 */
39static inline void __install_page_table(pgd_t *pgdir, int asid, pgprot_t prot)
40{
41 /* FIXME: DIRECTIO should not always be set. FIXME. */
42 int rc = hv_install_context(__pa(pgdir), prot, asid,
43 HV_CTX_DIRECTIO | CTX_PAGE_FLAG);
44 if (rc < 0)
45 panic("hv_install_context failed: %d", rc);
46}
47
48static inline void install_page_table(pgd_t *pgdir, int asid)
49{
50 pte_t *ptep = virt_to_kpte((unsigned long)pgdir);
51 __install_page_table(pgdir, asid, *ptep);
52}
53
54/*
55 * "Lazy" TLB mode is entered when we are switching to a kernel task,
56 * which borrows the mm of the previous task. The goal of this
57 * optimization is to avoid having to install a new page table. On
58 * early x86 machines (where the concept originated) you couldn't do
59 * anything short of a full page table install for invalidation, so
60 * handling a remote TLB invalidate required doing a page table
61 * re-install. Someone clearly decided that it was silly to keep
62 * doing this while in "lazy" TLB mode, so the optimization involves
63 * installing the swapper page table instead the first time one
64 * occurs, and clearing the cpu out of cpu_vm_mask, so the cpu running
65 * the kernel task doesn't need to take any more interrupts. At that
66 * point it's then necessary to explicitly reinstall it when context
67 * switching back to the original mm.
68 *
69 * On Tile, we have to do a page-table install whenever DMA is enabled,
70 * so in that case lazy mode doesn't help anyway. And more generally,
71 * we have efficient per-page TLB shootdown, and don't expect to spend
72 * that much time in kernel tasks in general, so just leaving the
73 * kernel task borrowing the old page table, but handling TLB
74 * shootdowns, is a reasonable thing to do. And importantly, this
75 * lets us use the hypervisor's internal APIs for TLB shootdown, which
76 * means we don't have to worry about having TLB shootdowns blocked
77 * when Linux is disabling interrupts; see the page migration code for
78 * an example of where it's important for TLB shootdowns to complete
79 * even when interrupts are disabled at the Linux level.
80 */
81static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *t)
82{
83#if CHIP_HAS_TILE_DMA()
84 /*
85 * We have to do an "identity" page table switch in order to
86 * clear any pending DMA interrupts.
87 */
88 if (current->thread.tile_dma_state.enabled)
89 install_page_table(mm->pgd, __this_cpu_read(current_asid));
90#endif
91}
92
93static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
94 struct task_struct *tsk)
95{
96 if (likely(prev != next)) {
97
98 int cpu = smp_processor_id();
99
100 /* Pick new ASID. */
101 int asid = __this_cpu_read(current_asid) + 1;
102 if (asid > max_asid) {
103 asid = min_asid;
104 local_flush_tlb();
105 }
106 __this_cpu_write(current_asid, asid);
107
108 /* Clear cpu from the old mm, and set it in the new one. */
109 cpumask_clear_cpu(cpu, mm_cpumask(prev));
110 cpumask_set_cpu(cpu, mm_cpumask(next));
111
112 /* Re-load page tables */
113 install_page_table(next->pgd, asid);
114
115 /* See how we should set the red/black cache info */
116 check_mm_caching(prev, next);
117
118 /*
119 * Since we're changing to a new mm, we have to flush
120 * the icache in case some physical page now being mapped
121 * has subsequently been repurposed and has new code.
122 */
123 __flush_icache();
124
125 }
126}
127
128static inline void activate_mm(struct mm_struct *prev_mm,
129 struct mm_struct *next_mm)
130{
131 switch_mm(prev_mm, next_mm, NULL);
132}
133
134#define destroy_context(mm) do { } while (0)
135#define deactivate_mm(tsk, mm) do { } while (0)
136
137#endif /* _ASM_TILE_MMU_CONTEXT_H */
diff --git a/arch/tile/include/asm/mmzone.h b/arch/tile/include/asm/mmzone.h
deleted file mode 100644
index 804f1098b6cd..000000000000
--- a/arch/tile/include/asm/mmzone.h
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_MMZONE_H
16#define _ASM_TILE_MMZONE_H
17
18extern struct pglist_data node_data[];
19#define NODE_DATA(nid) (&node_data[nid])
20
21extern void get_memcfg_numa(void);
22
23#ifdef CONFIG_DISCONTIGMEM
24
25#include <asm/page.h>
26
27/*
28 * Generally, memory ranges are always doled out by the hypervisor in
29 * fixed-size, power-of-two increments. That would make computing the node
30 * very easy. We could just take a couple high bits of the PA, which
31 * denote the memory shim, and we'd be done. However, when we're doing
32 * memory striping, this may not be true; PAs with different high bit
33 * values might be in the same node. Thus, we keep a lookup table to
34 * translate the high bits of the PFN to the node number.
35 */
36extern int highbits_to_node[];
37
38static inline int pfn_to_nid(unsigned long pfn)
39{
40 return highbits_to_node[__pfn_to_highbits(pfn)];
41}
42
43#define kern_addr_valid(kaddr) virt_addr_valid((void *)kaddr)
44
45static inline int pfn_valid(unsigned long pfn)
46{
47 int nid = pfn_to_nid(pfn);
48
49 if (nid >= 0)
50 return (pfn < node_end_pfn(nid));
51 return 0;
52}
53
54/* Information on the NUMA nodes that we compute early */
55extern unsigned long node_start_pfn[];
56extern unsigned long node_end_pfn[];
57extern unsigned long node_memmap_pfn[];
58extern unsigned long node_percpu_pfn[];
59extern unsigned long node_free_pfn[];
60#ifdef CONFIG_HIGHMEM
61extern unsigned long node_lowmem_end_pfn[];
62#endif
63#ifdef CONFIG_PCI
64extern unsigned long pci_reserve_start_pfn;
65extern unsigned long pci_reserve_end_pfn;
66#endif
67
68#endif /* CONFIG_DISCONTIGMEM */
69
70#endif /* _ASM_TILE_MMZONE_H */
diff --git a/arch/tile/include/asm/module.h b/arch/tile/include/asm/module.h
deleted file mode 100644
index 44ed07ccd3d2..000000000000
--- a/arch/tile/include/asm/module.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_MODULE_H
16#define _ASM_TILE_MODULE_H
17
18#include <arch/chip.h>
19
20#include <asm-generic/module.h>
21
22/* We can't use modules built with different page sizes. */
23#if defined(CONFIG_PAGE_SIZE_16KB)
24# define MODULE_PGSZ " 16KB"
25#elif defined(CONFIG_PAGE_SIZE_64KB)
26# define MODULE_PGSZ " 64KB"
27#else
28# define MODULE_PGSZ ""
29#endif
30
31/* We don't really support no-SMP so tag if someone tries. */
32#ifdef CONFIG_SMP
33#define MODULE_NOSMP ""
34#else
35#define MODULE_NOSMP " nosmp"
36#endif
37
38#define MODULE_ARCH_VERMAGIC CHIP_ARCH_NAME MODULE_PGSZ MODULE_NOSMP
39
40#endif /* _ASM_TILE_MODULE_H */
diff --git a/arch/tile/include/asm/page.h b/arch/tile/include/asm/page.h
deleted file mode 100644
index 498a5f71245d..000000000000
--- a/arch/tile/include/asm/page.h
+++ /dev/null
@@ -1,345 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_PAGE_H
16#define _ASM_TILE_PAGE_H
17
18#include <linux/const.h>
19#include <hv/hypervisor.h>
20#include <arch/chip.h>
21
22/* PAGE_SHIFT and HPAGE_SHIFT determine the page sizes. */
23#if defined(CONFIG_PAGE_SIZE_4KB) /* tilepro only */
24#define PAGE_SHIFT 12
25#define CTX_PAGE_FLAG HV_CTX_PG_SM_4K
26#elif defined(CONFIG_PAGE_SIZE_16KB)
27#define PAGE_SHIFT 14
28#define CTX_PAGE_FLAG HV_CTX_PG_SM_16K
29#elif defined(CONFIG_PAGE_SIZE_64KB)
30#define PAGE_SHIFT 16
31#define CTX_PAGE_FLAG HV_CTX_PG_SM_64K
32#else
33#error Page size not specified in Kconfig
34#endif
35#define HPAGE_SHIFT HV_LOG2_DEFAULT_PAGE_SIZE_LARGE
36
37#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
38#define HPAGE_SIZE (_AC(1, UL) << HPAGE_SHIFT)
39
40#define PAGE_MASK (~(PAGE_SIZE - 1))
41#define HPAGE_MASK (~(HPAGE_SIZE - 1))
42
43/*
44 * If the Kconfig doesn't specify, set a maximum zone order that
45 * is enough so that we can create huge pages from small pages given
46 * the respective sizes of the two page types. See <linux/mmzone.h>.
47 */
48#ifndef CONFIG_FORCE_MAX_ZONEORDER
49#define CONFIG_FORCE_MAX_ZONEORDER (HPAGE_SHIFT - PAGE_SHIFT + 1)
50#endif
51
52#ifndef __ASSEMBLY__
53
54#include <linux/types.h>
55#include <linux/string.h>
56
57struct page;
58
59static inline void clear_page(void *page)
60{
61 memset(page, 0, PAGE_SIZE);
62}
63
64static inline void copy_page(void *to, void *from)
65{
66 memcpy(to, from, PAGE_SIZE);
67}
68
69static inline void clear_user_page(void *page, unsigned long vaddr,
70 struct page *pg)
71{
72 clear_page(page);
73}
74
75static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
76 struct page *topage)
77{
78 copy_page(to, from);
79}
80
81/*
82 * Hypervisor page tables are made of the same basic structure.
83 */
84
85typedef HV_PTE pte_t;
86typedef HV_PTE pgd_t;
87typedef HV_PTE pgprot_t;
88
89/*
90 * User L2 page tables are managed as one L2 page table per page,
91 * because we use the page allocator for them. This keeps the allocation
92 * simple, but it's also inefficient, since L2 page tables are much smaller
93 * than pages (currently 2KB vs 64KB). So we should revisit this.
94 */
95typedef struct page *pgtable_t;
96
97/* Must be a macro since it is used to create constants. */
98#define __pgprot(val) hv_pte(val)
99
100/* Rarely-used initializers, typically with a "zero" value. */
101#define __pte(x) hv_pte(x)
102#define __pgd(x) hv_pte(x)
103
104static inline u64 pgprot_val(pgprot_t pgprot)
105{
106 return hv_pte_val(pgprot);
107}
108
109static inline u64 pte_val(pte_t pte)
110{
111 return hv_pte_val(pte);
112}
113
114static inline u64 pgd_val(pgd_t pgd)
115{
116 return hv_pte_val(pgd);
117}
118
119#ifdef __tilegx__
120
121typedef HV_PTE pmd_t;
122
123#define __pmd(x) hv_pte(x)
124
125static inline u64 pmd_val(pmd_t pmd)
126{
127 return hv_pte_val(pmd);
128}
129
130#endif
131
132static inline __attribute_const__ int get_order(unsigned long size)
133{
134 return BITS_PER_LONG - __builtin_clzl((size - 1) >> PAGE_SHIFT);
135}
136
137#endif /* !__ASSEMBLY__ */
138
139#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
140
141#define HUGE_MAX_HSTATE 6
142
143#ifdef CONFIG_HUGETLB_PAGE
144#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
145#endif
146
147/* Allow overriding how much VA or PA the kernel will use. */
148#define MAX_PA_WIDTH CHIP_PA_WIDTH()
149#define MAX_VA_WIDTH CHIP_VA_WIDTH()
150
151/* Each memory controller has PAs distinct in their high bits. */
152#define NR_PA_HIGHBIT_SHIFT (MAX_PA_WIDTH - CHIP_LOG_NUM_MSHIMS())
153#define NR_PA_HIGHBIT_VALUES (1 << CHIP_LOG_NUM_MSHIMS())
154#define __pa_to_highbits(pa) ((phys_addr_t)(pa) >> NR_PA_HIGHBIT_SHIFT)
155#define __pfn_to_highbits(pfn) ((pfn) >> (NR_PA_HIGHBIT_SHIFT - PAGE_SHIFT))
156
157#ifdef __tilegx__
158
159/*
160 * We reserve the lower half of memory for user-space programs, and the
161 * upper half for system code. We re-map all of physical memory in the
162 * upper half, which takes a quarter of our VA space. Then we have
163 * the vmalloc regions. The supervisor code lives at the highest address,
164 * with the hypervisor above that.
165 *
166 * Loadable kernel modules are placed immediately after the static
167 * supervisor code, with each being allocated a 256MB region of
168 * address space, so we don't have to worry about the range of "jal"
169 * and other branch instructions.
170 *
171 * For now we keep life simple and just allocate one pmd (4GB) for vmalloc.
172 * Similarly, for now we don't play any struct page mapping games.
173 */
174
175#if MAX_PA_WIDTH + 2 > MAX_VA_WIDTH
176# error Too much PA to map with the VA available!
177#endif
178
179#define PAGE_OFFSET (-(_AC(1, UL) << (MAX_VA_WIDTH - 1)))
180#define KERNEL_HIGH_VADDR _AC(0xfffffff800000000, UL) /* high 32GB */
181#define FIXADDR_BASE (KERNEL_HIGH_VADDR - 0x300000000) /* 4 GB */
182#define FIXADDR_TOP (KERNEL_HIGH_VADDR - 0x200000000) /* 4 GB */
183#define _VMALLOC_START FIXADDR_TOP
184#define MEM_SV_START (KERNEL_HIGH_VADDR - 0x100000000) /* 256 MB */
185#define MEM_MODULE_START (MEM_SV_START + (256*1024*1024)) /* 256 MB */
186#define MEM_MODULE_END (MEM_MODULE_START + (256*1024*1024))
187
188#else /* !__tilegx__ */
189
190/*
191 * A PAGE_OFFSET of 0xC0000000 means that the kernel has
192 * a virtual address space of one gigabyte, which limits the
193 * amount of physical memory you can use to about 768MB.
194 * If you want more physical memory than this then see the CONFIG_HIGHMEM
195 * option in the kernel configuration.
196 *
197 * The top 16MB chunk in the table below is unavailable to Linux. Since
198 * the kernel interrupt vectors must live at ether 0xfe000000 or 0xfd000000
199 * (depending on whether the kernel is at PL2 or Pl1), we map all of the
200 * bottom of RAM at this address with a huge page table entry to minimize
201 * its ITLB footprint (as well as at PAGE_OFFSET). The last architected
202 * requirement is that user interrupt vectors live at 0xfc000000, so we
203 * make that range of memory available to user processes. The remaining
204 * regions are sized as shown; the first four addresses use the PL 1
205 * values, and after that, we show "typical" values, since the actual
206 * addresses depend on kernel #defines.
207 *
208 * MEM_HV_START 0xfe000000
209 * MEM_SV_START (kernel code) 0xfd000000
210 * MEM_USER_INTRPT (user vector) 0xfc000000
211 * FIX_KMAP_xxx 0xfa000000 (via NR_CPUS * KM_TYPE_NR)
212 * PKMAP_BASE 0xf9000000 (via LAST_PKMAP)
213 * VMALLOC_START 0xf7000000 (via VMALLOC_RESERVE)
214 * mapped LOWMEM 0xc0000000
215 */
216
217#define MEM_USER_INTRPT _AC(0xfc000000, UL)
218#define MEM_SV_START _AC(0xfd000000, UL)
219#define MEM_HV_START _AC(0xfe000000, UL)
220
221#define INTRPT_SIZE 0x4000
222
223/* Tolerate page size larger than the architecture interrupt region size. */
224#if PAGE_SIZE > INTRPT_SIZE
225#undef INTRPT_SIZE
226#define INTRPT_SIZE PAGE_SIZE
227#endif
228
229#define KERNEL_HIGH_VADDR MEM_USER_INTRPT
230#define FIXADDR_TOP (KERNEL_HIGH_VADDR - PAGE_SIZE)
231
232#define PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
233
234/* On 32-bit architectures we mix kernel modules in with other vmaps. */
235#define MEM_MODULE_START VMALLOC_START
236#define MEM_MODULE_END VMALLOC_END
237
238#endif /* __tilegx__ */
239
240#if !defined(__ASSEMBLY__) && !defined(VDSO_BUILD)
241
242#ifdef CONFIG_HIGHMEM
243
244/* Map kernel virtual addresses to page frames, in HPAGE_SIZE chunks. */
245extern unsigned long pbase_map[];
246extern void *vbase_map[];
247
248static inline unsigned long kaddr_to_pfn(const volatile void *_kaddr)
249{
250 unsigned long kaddr = (unsigned long)_kaddr;
251 return pbase_map[kaddr >> HPAGE_SHIFT] +
252 ((kaddr & (HPAGE_SIZE - 1)) >> PAGE_SHIFT);
253}
254
255static inline void *pfn_to_kaddr(unsigned long pfn)
256{
257 return vbase_map[__pfn_to_highbits(pfn)] + (pfn << PAGE_SHIFT);
258}
259
260static inline phys_addr_t virt_to_phys(const volatile void *kaddr)
261{
262 unsigned long pfn = kaddr_to_pfn(kaddr);
263 return ((phys_addr_t)pfn << PAGE_SHIFT) +
264 ((unsigned long)kaddr & (PAGE_SIZE-1));
265}
266
267static inline void *phys_to_virt(phys_addr_t paddr)
268{
269 return pfn_to_kaddr(paddr >> PAGE_SHIFT) + (paddr & (PAGE_SIZE-1));
270}
271
272/* With HIGHMEM, we pack PAGE_OFFSET through high_memory with all valid VAs. */
273static inline int virt_addr_valid(const volatile void *kaddr)
274{
275 extern void *high_memory; /* copied from <linux/mm.h> */
276 return ((unsigned long)kaddr >= PAGE_OFFSET && kaddr < high_memory);
277}
278
279#else /* !CONFIG_HIGHMEM */
280
281static inline unsigned long kaddr_to_pfn(const volatile void *kaddr)
282{
283 return ((unsigned long)kaddr - PAGE_OFFSET) >> PAGE_SHIFT;
284}
285
286static inline void *pfn_to_kaddr(unsigned long pfn)
287{
288 return (void *)((pfn << PAGE_SHIFT) + PAGE_OFFSET);
289}
290
291static inline phys_addr_t virt_to_phys(const volatile void *kaddr)
292{
293 return (phys_addr_t)((unsigned long)kaddr - PAGE_OFFSET);
294}
295
296static inline void *phys_to_virt(phys_addr_t paddr)
297{
298 return (void *)((unsigned long)paddr + PAGE_OFFSET);
299}
300
301/* Check that the given address is within some mapped range of PAs. */
302#define virt_addr_valid(kaddr) pfn_valid(kaddr_to_pfn(kaddr))
303
304#endif /* !CONFIG_HIGHMEM */
305
306/* All callers are not consistent in how they call these functions. */
307#define __pa(kaddr) virt_to_phys((void *)(unsigned long)(kaddr))
308#define __va(paddr) phys_to_virt((phys_addr_t)(paddr))
309
310extern int devmem_is_allowed(unsigned long pagenr);
311
312#ifdef CONFIG_FLATMEM
313static inline int pfn_valid(unsigned long pfn)
314{
315 return pfn < max_mapnr;
316}
317#endif
318
319/* Provide as macros since these require some other headers included. */
320#define page_to_pa(page) ((phys_addr_t)(page_to_pfn(page)) << PAGE_SHIFT)
321#define virt_to_page(kaddr) pfn_to_page(kaddr_to_pfn((void *)(kaddr)))
322#define page_to_virt(page) pfn_to_kaddr(page_to_pfn(page))
323
324/*
325 * The kernel text is mapped at MEM_SV_START as read-only. To allow
326 * modifying kernel text, it is also mapped at PAGE_OFFSET as read-write.
327 * This macro converts a kernel address to its writable kernel text mapping,
328 * which is used to modify the text code on a running kernel by kgdb,
329 * ftrace, kprobe, jump label, etc.
330 */
331#define ktext_writable_addr(kaddr) \
332 ((unsigned long)(kaddr) - MEM_SV_START + PAGE_OFFSET)
333
334struct mm_struct;
335extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr);
336extern pte_t *virt_to_kpte(unsigned long kaddr);
337
338#endif /* !__ASSEMBLY__ */
339
340#define VM_DATA_DEFAULT_FLAGS \
341 (VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
342
343#include <asm-generic/memory_model.h>
344
345#endif /* _ASM_TILE_PAGE_H */
diff --git a/arch/tile/include/asm/pci.h b/arch/tile/include/asm/pci.h
deleted file mode 100644
index fe3de505b024..000000000000
--- a/arch/tile/include/asm/pci.h
+++ /dev/null
@@ -1,229 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_PCI_H
16#define _ASM_TILE_PCI_H
17
18#include <linux/dma-mapping.h>
19#include <linux/pci.h>
20#include <asm-generic/pci_iomap.h>
21
22#ifndef __tilegx__
23
24/*
25 * Structure of a PCI controller (host bridge)
26 */
27struct pci_controller {
28 int index; /* PCI domain number */
29 struct pci_bus *root_bus;
30
31 int last_busno;
32
33 int hv_cfg_fd[2]; /* config{0,1} fds for this PCIe controller */
34 int hv_mem_fd; /* fd to Hypervisor for MMIO operations */
35
36 struct pci_ops *ops;
37
38 int irq_base; /* Base IRQ from the Hypervisor */
39 int plx_gen1; /* flag for PLX Gen 1 configuration */
40
41 /* Address ranges that are routed to this controller/bridge. */
42 struct resource mem_resources[3];
43};
44
45/*
46 * This flag tells if the platform is TILEmpower that needs
47 * special configuration for the PLX switch chip.
48 */
49extern int tile_plx_gen1;
50
51static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) {}
52
53#define TILE_NUM_PCIE 2
54
55/*
56 * The hypervisor maps the entirety of CPA-space as bus addresses, so
57 * bus addresses are physical addresses. The networking and block
58 * device layers use this boolean for bounce buffer decisions.
59 */
60#define PCI_DMA_BUS_IS_PHYS 1
61
62/* generic pci stuff */
63#include <asm-generic/pci.h>
64
65#else
66
67#include <asm/page.h>
68#include <gxio/trio.h>
69
70/**
71 * We reserve the hugepage-size address range at the top of the 64-bit address
72 * space to serve as the PCI window, emulating the BAR0 space of an endpoint
73 * device. This window is used by the chip-to-chip applications running on
74 * the RC node. The reason for carving out this window is that Mem-Maps that
75 * back up this window will not overlap with those that map the real physical
76 * memory.
77 */
78#define PCIE_HOST_BAR0_SIZE HPAGE_SIZE
79#define PCIE_HOST_BAR0_START HPAGE_MASK
80
81/**
82 * The first PAGE_SIZE of the above "BAR" window is mapped to the
83 * gxpci_host_regs structure.
84 */
85#define PCIE_HOST_REGS_SIZE PAGE_SIZE
86
87/*
88 * This is the PCI address where the Mem-Map interrupt regions start.
89 * We use the 2nd to the last huge page of the 64-bit address space.
90 * The last huge page is used for the rootcomplex "bar", for C2C purpose.
91 */
92#define MEM_MAP_INTR_REGIONS_BASE (HPAGE_MASK - HPAGE_SIZE)
93
94/*
95 * Each Mem-Map interrupt region occupies 4KB.
96 */
97#define MEM_MAP_INTR_REGION_SIZE (1 << TRIO_MAP_MEM_LIM__ADDR_SHIFT)
98
99/*
100 * Allocate the PCI BAR window right below 4GB.
101 */
102#define TILE_PCI_BAR_WINDOW_TOP (1ULL << 32)
103
104/*
105 * Allocate 1GB for the PCI BAR window.
106 */
107#define TILE_PCI_BAR_WINDOW_SIZE (1 << 30)
108
109/*
110 * This is the highest bus address targeting the host memory that
111 * can be generated by legacy PCI devices with 32-bit or less
112 * DMA capability, dictated by the BAR window size and location.
113 */
114#define TILE_PCI_MAX_DIRECT_DMA_ADDRESS \
115 (TILE_PCI_BAR_WINDOW_TOP - TILE_PCI_BAR_WINDOW_SIZE - 1)
116
117/*
118 * We shift the PCI bus range for all the physical memory up by the whole PA
119 * range. The corresponding CPA of an incoming PCI request will be the PCI
120 * address minus TILE_PCI_MEM_MAP_BASE_OFFSET. This also implies
121 * that the 64-bit capable devices will be given DMA addresses as
122 * the CPA plus TILE_PCI_MEM_MAP_BASE_OFFSET. To support 32-bit
123 * devices, we create a separate map region that handles the low
124 * 4GB.
125 *
126 * This design lets us avoid the "PCI hole" problem where the host bridge
127 * won't pass DMA traffic with target addresses that happen to fall within the
128 * BAR space. This enables us to use all the physical memory for DMA, instead
129 * of wasting the same amount of physical memory as the BAR window size.
130 */
131#define TILE_PCI_MEM_MAP_BASE_OFFSET (1ULL << CHIP_PA_WIDTH())
132
133/*
134 * Start of the PCI memory resource, which starts at the end of the
135 * maximum system physical RAM address.
136 */
137#define TILE_PCI_MEM_START (1ULL << CHIP_PA_WIDTH())
138
139/*
140 * Structure of a PCI controller (host bridge) on Gx.
141 */
142struct pci_controller {
143
144 /* Pointer back to the TRIO that this PCIe port is connected to. */
145 gxio_trio_context_t *trio;
146 int mac; /* PCIe mac index on the TRIO shim */
147 int trio_index; /* Index of TRIO shim that contains the MAC. */
148
149 int pio_mem_index; /* PIO region index for memory access */
150
151#ifdef CONFIG_TILE_PCI_IO
152 int pio_io_index; /* PIO region index for I/O space access */
153#endif
154
155 /*
156 * Mem-Map regions for all the memory controllers so that Linux can
157 * map all of its physical memory space to the PCI bus.
158 */
159 int mem_maps[MAX_NUMNODES];
160
161 int index; /* PCI domain number */
162 struct pci_bus *root_bus;
163
164 /* PCI I/O space resource for this controller. */
165 struct resource io_space;
166 char io_space_name[32];
167
168 /* PCI memory space resource for this controller. */
169 struct resource mem_space;
170 char mem_space_name[32];
171
172 uint64_t mem_offset; /* cpu->bus memory mapping offset. */
173
174 int first_busno;
175
176 struct pci_ops *ops;
177
178 /* Table that maps the INTx numbers to Linux irq numbers. */
179 int irq_intx_table[4];
180};
181
182extern struct pci_controller pci_controllers[TILEGX_NUM_TRIO * TILEGX_TRIO_PCIES];
183extern gxio_trio_context_t trio_contexts[TILEGX_NUM_TRIO];
184extern int num_trio_shims;
185
186extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
187
188/*
189 * The PCI address space does not equal the physical memory address
190 * space (we have an IOMMU). The IDE and SCSI device layers use this
191 * boolean for bounce buffer decisions.
192 */
193#define PCI_DMA_BUS_IS_PHYS 0
194
195#endif /* __tilegx__ */
196
197int __init tile_pci_init(void);
198int __init pcibios_init(void);
199
200void pcibios_fixup_bus(struct pci_bus *bus);
201
202#define pci_domain_nr(bus) (((struct pci_controller *)(bus)->sysdata)->index)
203
204/*
205 * This decides whether to display the domain number in /proc.
206 */
207static inline int pci_proc_domain(struct pci_bus *bus)
208{
209 return 1;
210}
211
212/*
213 * pcibios_assign_all_busses() tells whether or not the bus numbers
214 * should be reassigned, in case the BIOS didn't do it correctly, or
215 * in case we don't have a BIOS and we want to let Linux do it.
216 */
217static inline int pcibios_assign_all_busses(void)
218{
219 return 1;
220}
221
222#define PCIBIOS_MIN_MEM 0
223/* Minimum PCI I/O address, starting at the page boundary. */
224#define PCIBIOS_MIN_IO PAGE_SIZE
225
226/* Use any cpu for PCI. */
227#define cpumask_of_pcibus(bus) cpu_online_mask
228
229#endif /* _ASM_TILE_PCI_H */
diff --git a/arch/tile/include/asm/percpu.h b/arch/tile/include/asm/percpu.h
deleted file mode 100644
index 4f7ae39fa202..000000000000
--- a/arch/tile/include/asm/percpu.h
+++ /dev/null
@@ -1,52 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_PERCPU_H
16#define _ASM_TILE_PERCPU_H
17
18register unsigned long my_cpu_offset_reg asm("tp");
19
20#ifdef CONFIG_PREEMPT
21/*
22 * For full preemption, we can't just use the register variable
23 * directly, since we need barrier() to hazard against it, causing the
24 * compiler to reload anything computed from a previous "tp" value.
25 * But we also don't want to use volatile asm, since we'd like the
26 * compiler to be able to cache the value across multiple percpu reads.
27 * So we use a fake stack read as a hazard against barrier().
28 * The 'U' constraint is like 'm' but disallows postincrement.
29 */
30static inline unsigned long __my_cpu_offset(void)
31{
32 unsigned long tp;
33 register unsigned long *sp asm("sp");
34 asm("move %0, tp" : "=r" (tp) : "U" (*sp));
35 return tp;
36}
37#define __my_cpu_offset __my_cpu_offset()
38#else
39/*
40 * We don't need to hazard against barrier() since "tp" doesn't ever
41 * change with PREEMPT_NONE, and with PREEMPT_VOLUNTARY it only
42 * changes at function call points, at which we are already re-reading
43 * the value of "tp" due to "my_cpu_offset_reg" being a global variable.
44 */
45#define __my_cpu_offset my_cpu_offset_reg
46#endif
47
48#define set_my_cpu_offset(tp) (my_cpu_offset_reg = (tp))
49
50#include <asm-generic/percpu.h>
51
52#endif /* _ASM_TILE_PERCPU_H */
diff --git a/arch/tile/include/asm/perf_event.h b/arch/tile/include/asm/perf_event.h
deleted file mode 100644
index 59c5b164e5b6..000000000000
--- a/arch/tile/include/asm/perf_event.h
+++ /dev/null
@@ -1,22 +0,0 @@
1/*
2 * Copyright 2014 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_PERF_EVENT_H
16#define _ASM_TILE_PERF_EVENT_H
17
18#include <linux/percpu.h>
19DECLARE_PER_CPU(u64, perf_irqs);
20
21unsigned long handle_syscall_link_address(void);
22#endif /* _ASM_TILE_PERF_EVENT_H */
diff --git a/arch/tile/include/asm/pgalloc.h b/arch/tile/include/asm/pgalloc.h
deleted file mode 100644
index 1b902508b664..000000000000
--- a/arch/tile/include/asm/pgalloc.h
+++ /dev/null
@@ -1,164 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_PGALLOC_H
16#define _ASM_TILE_PGALLOC_H
17
18#include <linux/threads.h>
19#include <linux/mm.h>
20#include <linux/mmzone.h>
21#include <asm/fixmap.h>
22#include <asm/page.h>
23#include <hv/hypervisor.h>
24
25/* Bits for the size of the second-level page table. */
26#define L2_KERNEL_PGTABLE_SHIFT _HV_LOG2_L2_SIZE(HPAGE_SHIFT, PAGE_SHIFT)
27
28/* How big is a kernel L2 page table? */
29#define L2_KERNEL_PGTABLE_SIZE (1UL << L2_KERNEL_PGTABLE_SHIFT)
30
31/* We currently allocate user L2 page tables by page (unlike kernel L2s). */
32#if L2_KERNEL_PGTABLE_SHIFT < PAGE_SHIFT
33#define L2_USER_PGTABLE_SHIFT PAGE_SHIFT
34#else
35#define L2_USER_PGTABLE_SHIFT L2_KERNEL_PGTABLE_SHIFT
36#endif
37
38/* How many pages do we need, as an "order", for a user L2 page table? */
39#define L2_USER_PGTABLE_ORDER (L2_USER_PGTABLE_SHIFT - PAGE_SHIFT)
40
41static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
42{
43#ifdef CONFIG_64BIT
44 set_pte(pmdp, pmd);
45#else
46 set_pte(&pmdp->pud.pgd, pmd.pud.pgd);
47#endif
48}
49
50static inline void pmd_populate_kernel(struct mm_struct *mm,
51 pmd_t *pmd, pte_t *ptep)
52{
53 set_pmd(pmd, ptfn_pmd(HV_CPA_TO_PTFN(__pa(ptep)),
54 __pgprot(_PAGE_PRESENT)));
55}
56
57static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
58 pgtable_t page)
59{
60 set_pmd(pmd, ptfn_pmd(HV_CPA_TO_PTFN(PFN_PHYS(page_to_pfn(page))),
61 __pgprot(_PAGE_PRESENT)));
62}
63
64/*
65 * Allocate and free page tables.
66 */
67
68extern pgd_t *pgd_alloc(struct mm_struct *mm);
69extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
70
71extern pgtable_t pgtable_alloc_one(struct mm_struct *mm, unsigned long address,
72 int order);
73extern void pgtable_free(struct mm_struct *mm, struct page *pte, int order);
74
75static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
76 unsigned long address)
77{
78 return pgtable_alloc_one(mm, address, L2_USER_PGTABLE_ORDER);
79}
80
81static inline void pte_free(struct mm_struct *mm, struct page *pte)
82{
83 pgtable_free(mm, pte, L2_USER_PGTABLE_ORDER);
84}
85
86#define pmd_pgtable(pmd) pmd_page(pmd)
87
88static inline pte_t *
89pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
90{
91 return pfn_to_kaddr(page_to_pfn(pte_alloc_one(mm, address)));
92}
93
94static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
95{
96 BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
97 pte_free(mm, virt_to_page(pte));
98}
99
100extern void __pgtable_free_tlb(struct mmu_gather *tlb, struct page *pte,
101 unsigned long address, int order);
102static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte,
103 unsigned long address)
104{
105 __pgtable_free_tlb(tlb, pte, address, L2_USER_PGTABLE_ORDER);
106}
107
108#define check_pgt_cache() do { } while (0)
109
110/*
111 * Get the small-page pte_t lowmem entry for a given pfn.
112 * This may or may not be in use, depending on whether the initial
113 * huge-page entry for the page has already been shattered.
114 */
115pte_t *get_prealloc_pte(unsigned long pfn);
116
117/* During init, we can shatter kernel huge pages if needed. */
118void shatter_pmd(pmd_t *pmd);
119
120/* After init, a more complex technique is required. */
121void shatter_huge_page(unsigned long addr);
122
123#ifdef __tilegx__
124
125#define pud_populate(mm, pud, pmd) \
126 pmd_populate_kernel((mm), (pmd_t *)(pud), (pte_t *)(pmd))
127
128/* Bits for the size of the L1 (intermediate) page table. */
129#define L1_KERNEL_PGTABLE_SHIFT _HV_LOG2_L1_SIZE(HPAGE_SHIFT)
130
131/* How big is a kernel L2 page table? */
132#define L1_KERNEL_PGTABLE_SIZE (1UL << L1_KERNEL_PGTABLE_SHIFT)
133
134/* We currently allocate L1 page tables by page. */
135#if L1_KERNEL_PGTABLE_SHIFT < PAGE_SHIFT
136#define L1_USER_PGTABLE_SHIFT PAGE_SHIFT
137#else
138#define L1_USER_PGTABLE_SHIFT L1_KERNEL_PGTABLE_SHIFT
139#endif
140
141/* How many pages do we need, as an "order", for an L1 page table? */
142#define L1_USER_PGTABLE_ORDER (L1_USER_PGTABLE_SHIFT - PAGE_SHIFT)
143
144static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
145{
146 struct page *p = pgtable_alloc_one(mm, address, L1_USER_PGTABLE_ORDER);
147 return (pmd_t *)page_to_virt(p);
148}
149
150static inline void pmd_free(struct mm_struct *mm, pmd_t *pmdp)
151{
152 pgtable_free(mm, virt_to_page(pmdp), L1_USER_PGTABLE_ORDER);
153}
154
155static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
156 unsigned long address)
157{
158 __pgtable_free_tlb(tlb, virt_to_page(pmdp), address,
159 L1_USER_PGTABLE_ORDER);
160}
161
162#endif /* __tilegx__ */
163
164#endif /* _ASM_TILE_PGALLOC_H */
diff --git a/arch/tile/include/asm/pgtable.h b/arch/tile/include/asm/pgtable.h
deleted file mode 100644
index adfa21b18488..000000000000
--- a/arch/tile/include/asm/pgtable.h
+++ /dev/null
@@ -1,518 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * This file contains the functions and defines necessary to modify and use
15 * the TILE page table tree.
16 */
17
18#ifndef _ASM_TILE_PGTABLE_H
19#define _ASM_TILE_PGTABLE_H
20
21#include <hv/hypervisor.h>
22
23#ifndef __ASSEMBLY__
24
25#include <linux/bitops.h>
26#include <linux/threads.h>
27#include <linux/slab.h>
28#include <linux/list.h>
29#include <linux/spinlock.h>
30#include <linux/pfn.h>
31#include <asm/processor.h>
32#include <asm/fixmap.h>
33#include <asm/page.h>
34
35struct mm_struct;
36struct vm_area_struct;
37
38/*
39 * ZERO_PAGE is a global shared page that is always zero: used
40 * for zero-mapped memory areas etc..
41 */
42extern unsigned long empty_zero_page[PAGE_SIZE/sizeof(unsigned long)];
43#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
44
45extern pgd_t swapper_pg_dir[];
46extern pgprot_t swapper_pgprot;
47extern struct kmem_cache *pgd_cache;
48extern spinlock_t pgd_lock;
49extern struct list_head pgd_list;
50
51/*
52 * The very last slots in the pgd_t are for addresses unusable by Linux
53 * (pgd_addr_invalid() returns true). So we use them for the list structure.
54 * The x86 code we are modelled on uses the page->private/index fields
55 * (older 2.6 kernels) or the lru list (newer 2.6 kernels), but since
56 * our pgds are so much smaller than a page, it seems a waste to
57 * spend a whole page on each pgd.
58 */
59#define PGD_LIST_OFFSET \
60 ((PTRS_PER_PGD * sizeof(pgd_t)) - sizeof(struct list_head))
61#define pgd_to_list(pgd) \
62 ((struct list_head *)((char *)(pgd) + PGD_LIST_OFFSET))
63#define list_to_pgd(list) \
64 ((pgd_t *)((char *)(list) - PGD_LIST_OFFSET))
65
66extern void pgtable_cache_init(void);
67extern void paging_init(void);
68extern void set_page_homes(void);
69
70#define FIRST_USER_ADDRESS 0UL
71
72#define _PAGE_PRESENT HV_PTE_PRESENT
73#define _PAGE_HUGE_PAGE HV_PTE_PAGE
74#define _PAGE_SUPER_PAGE HV_PTE_SUPER
75#define _PAGE_READABLE HV_PTE_READABLE
76#define _PAGE_WRITABLE HV_PTE_WRITABLE
77#define _PAGE_EXECUTABLE HV_PTE_EXECUTABLE
78#define _PAGE_ACCESSED HV_PTE_ACCESSED
79#define _PAGE_DIRTY HV_PTE_DIRTY
80#define _PAGE_GLOBAL HV_PTE_GLOBAL
81#define _PAGE_USER HV_PTE_USER
82
83/*
84 * All the "standard" bits. Cache-control bits are managed elsewhere.
85 * This is used to test for valid level-2 page table pointers by checking
86 * all the bits, and to mask away the cache control bits for mprotect.
87 */
88#define _PAGE_ALL (\
89 _PAGE_PRESENT | \
90 _PAGE_HUGE_PAGE | \
91 _PAGE_SUPER_PAGE | \
92 _PAGE_READABLE | \
93 _PAGE_WRITABLE | \
94 _PAGE_EXECUTABLE | \
95 _PAGE_ACCESSED | \
96 _PAGE_DIRTY | \
97 _PAGE_GLOBAL | \
98 _PAGE_USER \
99)
100
101#define PAGE_NONE \
102 __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
103#define PAGE_SHARED \
104 __pgprot(_PAGE_PRESENT | _PAGE_READABLE | _PAGE_WRITABLE | \
105 _PAGE_USER | _PAGE_ACCESSED)
106
107#define PAGE_SHARED_EXEC \
108 __pgprot(_PAGE_PRESENT | _PAGE_READABLE | _PAGE_WRITABLE | \
109 _PAGE_EXECUTABLE | _PAGE_USER | _PAGE_ACCESSED)
110#define PAGE_COPY_NOEXEC \
111 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_READABLE)
112#define PAGE_COPY_EXEC \
113 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | \
114 _PAGE_READABLE | _PAGE_EXECUTABLE)
115#define PAGE_COPY \
116 PAGE_COPY_NOEXEC
117#define PAGE_READONLY \
118 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | _PAGE_READABLE)
119#define PAGE_READONLY_EXEC \
120 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED | \
121 _PAGE_READABLE | _PAGE_EXECUTABLE)
122
123#define _PAGE_KERNEL_RO \
124 (_PAGE_PRESENT | _PAGE_GLOBAL | _PAGE_READABLE | _PAGE_ACCESSED)
125#define _PAGE_KERNEL \
126 (_PAGE_KERNEL_RO | _PAGE_WRITABLE | _PAGE_DIRTY)
127#define _PAGE_KERNEL_EXEC (_PAGE_KERNEL_RO | _PAGE_EXECUTABLE)
128
129#define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
130#define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL_RO)
131#define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
132
133#define page_to_kpgprot(p) PAGE_KERNEL
134
135/*
136 * We could tighten these up, but for now writable or executable
137 * implies readable.
138 */
139#define __P000 PAGE_NONE
140#define __P001 PAGE_READONLY
141#define __P010 PAGE_COPY /* this is write-only, which we won't support */
142#define __P011 PAGE_COPY
143#define __P100 PAGE_READONLY_EXEC
144#define __P101 PAGE_READONLY_EXEC
145#define __P110 PAGE_COPY_EXEC
146#define __P111 PAGE_COPY_EXEC
147
148#define __S000 PAGE_NONE
149#define __S001 PAGE_READONLY
150#define __S010 PAGE_SHARED
151#define __S011 PAGE_SHARED
152#define __S100 PAGE_READONLY_EXEC
153#define __S101 PAGE_READONLY_EXEC
154#define __S110 PAGE_SHARED_EXEC
155#define __S111 PAGE_SHARED_EXEC
156
157/*
158 * All the normal _PAGE_ALL bits are ignored for PMDs, except PAGE_PRESENT
159 * and PAGE_HUGE_PAGE, which must be one and zero, respectively.
160 * We set the ignored bits to zero.
161 */
162#define _PAGE_TABLE _PAGE_PRESENT
163
164/* Inherit the caching flags from the old protection bits. */
165#define pgprot_modify(oldprot, newprot) \
166 (pgprot_t) { ((oldprot).val & ~_PAGE_ALL) | (newprot).val }
167
168/* Just setting the PFN to zero suffices. */
169#define pte_pgprot(x) hv_pte_set_pa((x), 0)
170
171/*
172 * For PTEs and PDEs, we must clear the Present bit first when
173 * clearing a page table entry, so clear the bottom half first and
174 * enforce ordering with a barrier.
175 */
176static inline void __pte_clear(pte_t *ptep)
177{
178#ifdef __tilegx__
179 ptep->val = 0;
180#else
181 u32 *tmp = (u32 *)ptep;
182 tmp[0] = 0;
183 barrier();
184 tmp[1] = 0;
185#endif
186}
187#define pte_clear(mm, addr, ptep) __pte_clear(ptep)
188
189/*
190 * The following only work if pte_present() is true.
191 * Undefined behaviour if not..
192 */
193#define pte_present hv_pte_get_present
194#define pte_mknotpresent hv_pte_clear_present
195#define pte_user hv_pte_get_user
196#define pte_read hv_pte_get_readable
197#define pte_dirty hv_pte_get_dirty
198#define pte_young hv_pte_get_accessed
199#define pte_write hv_pte_get_writable
200#define pte_exec hv_pte_get_executable
201#define pte_huge hv_pte_get_page
202#define pte_super hv_pte_get_super
203#define pte_rdprotect hv_pte_clear_readable
204#define pte_exprotect hv_pte_clear_executable
205#define pte_mkclean hv_pte_clear_dirty
206#define pte_mkold hv_pte_clear_accessed
207#define pte_wrprotect hv_pte_clear_writable
208#define pte_mksmall hv_pte_clear_page
209#define pte_mkread hv_pte_set_readable
210#define pte_mkexec hv_pte_set_executable
211#define pte_mkdirty hv_pte_set_dirty
212#define pte_mkyoung hv_pte_set_accessed
213#define pte_mkwrite hv_pte_set_writable
214#define pte_mkhuge hv_pte_set_page
215#define pte_mksuper hv_pte_set_super
216
217#define pte_special(pte) 0
218#define pte_mkspecial(pte) (pte)
219
220/*
221 * Use some spare bits in the PTE for user-caching tags.
222 */
223#define pte_set_forcecache hv_pte_set_client0
224#define pte_get_forcecache hv_pte_get_client0
225#define pte_clear_forcecache hv_pte_clear_client0
226#define pte_set_anyhome hv_pte_set_client1
227#define pte_get_anyhome hv_pte_get_client1
228#define pte_clear_anyhome hv_pte_clear_client1
229
230/*
231 * A migrating PTE has PAGE_PRESENT clear but all the other bits preserved.
232 */
233#define pte_migrating hv_pte_get_migrating
234#define pte_mkmigrate(x) hv_pte_set_migrating(hv_pte_clear_present(x))
235#define pte_donemigrate(x) hv_pte_set_present(hv_pte_clear_migrating(x))
236
237#define pte_ERROR(e) \
238 pr_err("%s:%d: bad pte 0x%016llx\n", __FILE__, __LINE__, pte_val(e))
239#define pgd_ERROR(e) \
240 pr_err("%s:%d: bad pgd 0x%016llx\n", __FILE__, __LINE__, pgd_val(e))
241
242/* Return PA and protection info for a given kernel VA. */
243int va_to_cpa_and_pte(void *va, phys_addr_t *cpa, pte_t *pte);
244
245/*
246 * __set_pte() ensures we write the 64-bit PTE with 32-bit words in
247 * the right order on 32-bit platforms and also allows us to write
248 * hooks to check valid PTEs, etc., if we want.
249 */
250void __set_pte(pte_t *ptep, pte_t pte);
251
252/*
253 * set_pte() sets the given PTE and also sanity-checks the
254 * requested PTE against the page homecaching. Unspecified parts
255 * of the PTE are filled in when it is written to memory, i.e. all
256 * caching attributes if "!forcecache", or the home cpu if "anyhome".
257 */
258extern void set_pte(pte_t *ptep, pte_t pte);
259#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval)
260#define set_pte_atomic(pteptr, pteval) set_pte(pteptr, pteval)
261
262#define pte_page(x) pfn_to_page(pte_pfn(x))
263
264static inline int pte_none(pte_t pte)
265{
266 return !pte.val;
267}
268
269static inline unsigned long pte_pfn(pte_t pte)
270{
271 return PFN_DOWN(hv_pte_get_pa(pte));
272}
273
274/* Set or get the remote cache cpu in a pgprot with remote caching. */
275extern pgprot_t set_remote_cache_cpu(pgprot_t prot, int cpu);
276extern int get_remote_cache_cpu(pgprot_t prot);
277
278static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
279{
280 return hv_pte_set_pa(prot, PFN_PHYS(pfn));
281}
282
283/* Support for priority mappings. */
284extern void start_mm_caching(struct mm_struct *mm);
285extern void check_mm_caching(struct mm_struct *prev, struct mm_struct *next);
286
287/*
288 * Encode and de-code a swap entry (see <linux/swapops.h>).
289 * We put the swap file type+offset in the 32 high bits;
290 * I believe we can just leave the low bits clear.
291 */
292#define __swp_type(swp) ((swp).val & 0x1f)
293#define __swp_offset(swp) ((swp).val >> 5)
294#define __swp_entry(type, off) ((swp_entry_t) { (type) | ((off) << 5) })
295#define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).val >> 32 })
296#define __swp_entry_to_pte(swp) ((pte_t) { (((long long) ((swp).val)) << 32) })
297
298/*
299 * Conversion functions: convert a page and protection to a page entry,
300 * and a page entry and page directory to the page they refer to.
301 */
302
303#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
304
305/*
306 * If we are doing an mprotect(), just accept the new vma->vm_page_prot
307 * value and combine it with the PFN from the old PTE to get a new PTE.
308 */
309static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
310{
311 return pfn_pte(pte_pfn(pte), newprot);
312}
313
314/*
315 * The pgd page can be thought of an array like this: pgd_t[PTRS_PER_PGD]
316 *
317 * This macro returns the index of the entry in the pgd page which would
318 * control the given virtual address.
319 */
320#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
321
322/*
323 * pgd_offset() returns a (pgd_t *)
324 * pgd_index() is used get the offset into the pgd page's array of pgd_t's.
325 */
326#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
327
328/*
329 * A shortcut which implies the use of the kernel's pgd, instead
330 * of a process's.
331 */
332#define pgd_offset_k(address) pgd_offset(&init_mm, address)
333
334#define pte_offset_map(dir, address) pte_offset_kernel(dir, address)
335#define pte_unmap(pte) do { } while (0)
336
337/* Clear a non-executable kernel PTE and flush it from the TLB. */
338#define kpte_clear_flush(ptep, vaddr) \
339do { \
340 pte_clear(&init_mm, (vaddr), (ptep)); \
341 local_flush_tlb_page(FLUSH_NONEXEC, (vaddr), PAGE_SIZE); \
342} while (0)
343
344/*
345 * The kernel page tables contain what we need, and we flush when we
346 * change specific page table entries.
347 */
348#define update_mmu_cache(vma, address, pte) do { } while (0)
349
350#ifdef CONFIG_FLATMEM
351#define kern_addr_valid(addr) (1)
352#endif /* CONFIG_FLATMEM */
353
354extern void vmalloc_sync_all(void);
355
356#endif /* !__ASSEMBLY__ */
357
358#ifdef __tilegx__
359#include <asm/pgtable_64.h>
360#else
361#include <asm/pgtable_32.h>
362#endif
363
364#ifndef __ASSEMBLY__
365
366static inline int pmd_none(pmd_t pmd)
367{
368 /*
369 * Only check low word on 32-bit platforms, since it might be
370 * out of sync with upper half.
371 */
372 return (unsigned long)pmd_val(pmd) == 0;
373}
374
375static inline int pmd_present(pmd_t pmd)
376{
377 return pmd_val(pmd) & _PAGE_PRESENT;
378}
379
380static inline int pmd_bad(pmd_t pmd)
381{
382 return ((pmd_val(pmd) & _PAGE_ALL) != _PAGE_TABLE);
383}
384
385static inline unsigned long pages_to_mb(unsigned long npg)
386{
387 return npg >> (20 - PAGE_SHIFT);
388}
389
390/*
391 * The pmd can be thought of an array like this: pmd_t[PTRS_PER_PMD]
392 *
393 * This function returns the index of the entry in the pmd which would
394 * control the given virtual address.
395 */
396static inline unsigned long pmd_index(unsigned long address)
397{
398 return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1);
399}
400
401#define __HAVE_ARCH_PMDP_TEST_AND_CLEAR_YOUNG
402static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
403 unsigned long address,
404 pmd_t *pmdp)
405{
406 return ptep_test_and_clear_young(vma, address, pmdp_ptep(pmdp));
407}
408
409#define __HAVE_ARCH_PMDP_SET_WRPROTECT
410static inline void pmdp_set_wrprotect(struct mm_struct *mm,
411 unsigned long address, pmd_t *pmdp)
412{
413 ptep_set_wrprotect(mm, address, pmdp_ptep(pmdp));
414}
415
416
417#define __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
418static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
419 unsigned long address,
420 pmd_t *pmdp)
421{
422 return pte_pmd(ptep_get_and_clear(mm, address, pmdp_ptep(pmdp)));
423}
424
425static inline void __set_pmd(pmd_t *pmdp, pmd_t pmdval)
426{
427 set_pte(pmdp_ptep(pmdp), pmd_pte(pmdval));
428}
429
430#define set_pmd_at(mm, addr, pmdp, pmdval) __set_pmd(pmdp, pmdval)
431
432/* Create a pmd from a PTFN. */
433static inline pmd_t ptfn_pmd(unsigned long ptfn, pgprot_t prot)
434{
435 return pte_pmd(hv_pte_set_ptfn(prot, ptfn));
436}
437
438/* Return the page-table frame number (ptfn) that a pmd_t points at. */
439#define pmd_ptfn(pmd) hv_pte_get_ptfn(pmd_pte(pmd))
440
441/*
442 * A given kernel pmd_t maps to a specific virtual address (either a
443 * kernel huge page or a kernel pte_t table). Since kernel pte_t
444 * tables can be aligned at sub-page granularity, this function can
445 * return non-page-aligned pointers, despite its name.
446 */
447static inline unsigned long pmd_page_vaddr(pmd_t pmd)
448{
449 phys_addr_t pa =
450 (phys_addr_t)pmd_ptfn(pmd) << HV_LOG2_PAGE_TABLE_ALIGN;
451 return (unsigned long)__va(pa);
452}
453
454/*
455 * A pmd_t points to the base of a huge page or to a pte_t array.
456 * If a pte_t array, since we can have multiple per page, we don't
457 * have a one-to-one mapping of pmd_t's to pages. However, this is
458 * OK for pte_lockptr(), since we just end up with potentially one
459 * lock being used for several pte_t arrays.
460 */
461#define pmd_page(pmd) pfn_to_page(PFN_DOWN(HV_PTFN_TO_CPA(pmd_ptfn(pmd))))
462
463static inline void pmd_clear(pmd_t *pmdp)
464{
465 __pte_clear(pmdp_ptep(pmdp));
466}
467
468#define pmd_mknotpresent(pmd) pte_pmd(pte_mknotpresent(pmd_pte(pmd)))
469#define pmd_young(pmd) pte_young(pmd_pte(pmd))
470#define pmd_mkyoung(pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd)))
471#define pmd_mkold(pmd) pte_pmd(pte_mkold(pmd_pte(pmd)))
472#define pmd_mkwrite(pmd) pte_pmd(pte_mkwrite(pmd_pte(pmd)))
473#define pmd_write(pmd) pte_write(pmd_pte(pmd))
474#define pmd_wrprotect(pmd) pte_pmd(pte_wrprotect(pmd_pte(pmd)))
475#define pmd_mkdirty(pmd) pte_pmd(pte_mkdirty(pmd_pte(pmd)))
476#define pmd_huge_page(pmd) pte_huge(pmd_pte(pmd))
477#define pmd_mkhuge(pmd) pte_pmd(pte_mkhuge(pmd_pte(pmd)))
478
479#define pfn_pmd(pfn, pgprot) pte_pmd(pfn_pte((pfn), (pgprot)))
480#define pmd_pfn(pmd) pte_pfn(pmd_pte(pmd))
481#define mk_pmd(page, pgprot) pfn_pmd(page_to_pfn(page), (pgprot))
482
483static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
484{
485 return pfn_pmd(pmd_pfn(pmd), newprot);
486}
487
488#ifdef CONFIG_TRANSPARENT_HUGEPAGE
489#define pmd_trans_huge pmd_huge_page
490#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
491
492/*
493 * The pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]
494 *
495 * This macro returns the index of the entry in the pte page which would
496 * control the given virtual address.
497 */
498static inline unsigned long pte_index(unsigned long address)
499{
500 return (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
501}
502
503static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long address)
504{
505 return (pte_t *)pmd_page_vaddr(*pmd) + pte_index(address);
506}
507
508#include <asm-generic/pgtable.h>
509
510/* Support /proc/NN/pgtable API. */
511struct seq_file;
512int arch_proc_pgtable_show(struct seq_file *m, struct mm_struct *mm,
513 unsigned long vaddr, unsigned long pagesize,
514 pte_t *ptep, void **datap);
515
516#endif /* !__ASSEMBLY__ */
517
518#endif /* _ASM_TILE_PGTABLE_H */
diff --git a/arch/tile/include/asm/pgtable_32.h b/arch/tile/include/asm/pgtable_32.h
deleted file mode 100644
index 5f8c615cb5e9..000000000000
--- a/arch/tile/include/asm/pgtable_32.h
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#ifndef _ASM_TILE_PGTABLE_32_H
17#define _ASM_TILE_PGTABLE_32_H
18
19/*
20 * The level-1 index is defined by the huge page size. A PGD is composed
21 * of PTRS_PER_PGD pgd_t's and is the top level of the page table.
22 */
23#define PGDIR_SHIFT HPAGE_SHIFT
24#define PGDIR_SIZE HPAGE_SIZE
25#define PGDIR_MASK (~(PGDIR_SIZE-1))
26#define PTRS_PER_PGD _HV_L1_ENTRIES(HPAGE_SHIFT)
27#define PGD_INDEX(va) _HV_L1_INDEX(va, HPAGE_SHIFT)
28#define SIZEOF_PGD _HV_L1_SIZE(HPAGE_SHIFT)
29
30/*
31 * The level-2 index is defined by the difference between the huge
32 * page size and the normal page size. A PTE is composed of
33 * PTRS_PER_PTE pte_t's and is the bottom level of the page table.
34 * Note that the hypervisor docs use PTE for what we call pte_t, so
35 * this nomenclature is somewhat confusing.
36 */
37#define PTRS_PER_PTE _HV_L2_ENTRIES(HPAGE_SHIFT, PAGE_SHIFT)
38#define PTE_INDEX(va) _HV_L2_INDEX(va, HPAGE_SHIFT, PAGE_SHIFT)
39#define SIZEOF_PTE _HV_L2_SIZE(HPAGE_SHIFT, PAGE_SHIFT)
40
41#ifndef __ASSEMBLY__
42
43/*
44 * Right now we initialize only a single pte table. It can be extended
45 * easily, subsequent pte tables have to be allocated in one physical
46 * chunk of RAM.
47 *
48 * HOWEVER, if we are using an allocation scheme with slop after the
49 * end of the page table (e.g. where our L2 page tables are 2KB but
50 * our pages are 64KB and we are allocating via the page allocator)
51 * we can't extend it easily.
52 */
53#define LAST_PKMAP PTRS_PER_PTE
54
55#define PKMAP_BASE ((FIXADDR_BOOT_START - PAGE_SIZE*LAST_PKMAP) & PGDIR_MASK)
56
57#ifdef CONFIG_HIGHMEM
58# define _VMALLOC_END (PKMAP_BASE & ~(HPAGE_SIZE-1))
59#else
60# define _VMALLOC_END (FIXADDR_START & ~(HPAGE_SIZE-1))
61#endif
62
63/*
64 * Align the vmalloc area to an L2 page table, and leave a guard page
65 * at the beginning and end. The vmalloc code also puts in an internal
66 * guard page between each allocation.
67 */
68#define VMALLOC_END (_VMALLOC_END - PAGE_SIZE)
69extern unsigned long VMALLOC_RESERVE /* = CONFIG_VMALLOC_RESERVE */;
70#define _VMALLOC_START (_VMALLOC_END - VMALLOC_RESERVE)
71#define VMALLOC_START (_VMALLOC_START + PAGE_SIZE)
72
73/* This is the maximum possible amount of lowmem. */
74#define MAXMEM (_VMALLOC_START - PAGE_OFFSET)
75
76/* We have no pmd or pud since we are strictly a two-level page table */
77#define __ARCH_USE_5LEVEL_HACK
78#include <asm-generic/pgtable-nopmd.h>
79
80static inline int pud_huge_page(pud_t pud) { return 0; }
81
82/* We don't define any pgds for these addresses. */
83static inline int pgd_addr_invalid(unsigned long addr)
84{
85 return addr >= MEM_HV_START;
86}
87
88/*
89 * Provide versions of these routines that can be used safely when
90 * the hypervisor may be asynchronously modifying dirty/accessed bits.
91 * ptep_get_and_clear() matches the generic one but we provide it to
92 * be parallel with the 64-bit code.
93 */
94#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
95#define __HAVE_ARCH_PTEP_SET_WRPROTECT
96
97extern int ptep_test_and_clear_young(struct vm_area_struct *,
98 unsigned long addr, pte_t *);
99extern void ptep_set_wrprotect(struct mm_struct *,
100 unsigned long addr, pte_t *);
101
102#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
103static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
104 unsigned long addr, pte_t *ptep)
105{
106 pte_t pte = *ptep;
107 pte_clear(_mm, addr, ptep);
108 return pte;
109}
110
111/*
112 * pmds are wrappers around pgds, which are the same as ptes.
113 * It's often convenient to "cast" back and forth and use the pte methods,
114 * which are the methods supplied by the hypervisor.
115 */
116#define pmd_pte(pmd) ((pmd).pud.pgd)
117#define pmdp_ptep(pmdp) (&(pmdp)->pud.pgd)
118#define pte_pmd(pte) ((pmd_t){ { (pte) } })
119
120#endif /* __ASSEMBLY__ */
121
122#endif /* _ASM_TILE_PGTABLE_32_H */
diff --git a/arch/tile/include/asm/pgtable_64.h b/arch/tile/include/asm/pgtable_64.h
deleted file mode 100644
index 96fe58b45118..000000000000
--- a/arch/tile/include/asm/pgtable_64.h
+++ /dev/null
@@ -1,172 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#ifndef _ASM_TILE_PGTABLE_64_H
17#define _ASM_TILE_PGTABLE_64_H
18
19/* The level-0 page table breaks the address space into 32-bit chunks. */
20#define PGDIR_SHIFT HV_LOG2_L1_SPAN
21#define PGDIR_SIZE HV_L1_SPAN
22#define PGDIR_MASK (~(PGDIR_SIZE-1))
23#define PTRS_PER_PGD HV_L0_ENTRIES
24#define PGD_INDEX(va) HV_L0_INDEX(va)
25#define SIZEOF_PGD HV_L0_SIZE
26
27/*
28 * The level-1 index is defined by the huge page size. A PMD is composed
29 * of PTRS_PER_PMD pgd_t's and is the middle level of the page table.
30 */
31#define PMD_SHIFT HPAGE_SHIFT
32#define PMD_SIZE HPAGE_SIZE
33#define PMD_MASK (~(PMD_SIZE-1))
34#define PTRS_PER_PMD _HV_L1_ENTRIES(HPAGE_SHIFT)
35#define PMD_INDEX(va) _HV_L1_INDEX(va, HPAGE_SHIFT)
36#define SIZEOF_PMD _HV_L1_SIZE(HPAGE_SHIFT)
37
38/*
39 * The level-2 index is defined by the difference between the huge
40 * page size and the normal page size. A PTE is composed of
41 * PTRS_PER_PTE pte_t's and is the bottom level of the page table.
42 * Note that the hypervisor docs use PTE for what we call pte_t, so
43 * this nomenclature is somewhat confusing.
44 */
45#define PTRS_PER_PTE _HV_L2_ENTRIES(HPAGE_SHIFT, PAGE_SHIFT)
46#define PTE_INDEX(va) _HV_L2_INDEX(va, HPAGE_SHIFT, PAGE_SHIFT)
47#define SIZEOF_PTE _HV_L2_SIZE(HPAGE_SHIFT, PAGE_SHIFT)
48
49/*
50 * Align the vmalloc area to an L2 page table. Omit guard pages at
51 * the beginning and end for simplicity (particularly in the per-cpu
52 * memory allocation code). The vmalloc code puts in an internal
53 * guard page between each allocation.
54 */
55#define _VMALLOC_END MEM_SV_START
56#define VMALLOC_END _VMALLOC_END
57#define VMALLOC_START _VMALLOC_START
58
59#ifndef __ASSEMBLY__
60
61/* We have no pud since we are a three-level page table. */
62#define __ARCH_USE_5LEVEL_HACK
63#include <asm-generic/pgtable-nopud.h>
64
65/*
66 * pmds are the same as pgds and ptes, so converting is a no-op.
67 */
68#define pmd_pte(pmd) (pmd)
69#define pmdp_ptep(pmdp) (pmdp)
70#define pte_pmd(pte) (pte)
71
72#define pud_pte(pud) ((pud).pgd)
73
74static inline int pud_none(pud_t pud)
75{
76 return pud_val(pud) == 0;
77}
78
79static inline int pud_present(pud_t pud)
80{
81 return pud_val(pud) & _PAGE_PRESENT;
82}
83
84static inline int pud_huge_page(pud_t pud)
85{
86 return pud_val(pud) & _PAGE_HUGE_PAGE;
87}
88
89#define pmd_ERROR(e) \
90 pr_err("%s:%d: bad pmd 0x%016llx\n", __FILE__, __LINE__, pmd_val(e))
91
92static inline void pud_clear(pud_t *pudp)
93{
94 __pte_clear(&pudp->pgd);
95}
96
97static inline int pud_bad(pud_t pud)
98{
99 return ((pud_val(pud) & _PAGE_ALL) != _PAGE_TABLE);
100}
101
102/* Return the page-table frame number (ptfn) that a pud_t points at. */
103#define pud_ptfn(pud) hv_pte_get_ptfn((pud).pgd)
104
105/* Return the page frame number (pfn) that a pud_t points at. */
106#define pud_pfn(pud) pte_pfn(pud_pte(pud))
107
108/*
109 * A given kernel pud_t maps to a kernel pmd_t table at a specific
110 * virtual address. Since kernel pmd_t tables can be aligned at
111 * sub-page granularity, this macro can return non-page-aligned
112 * pointers, despite its name.
113 */
114#define pud_page_vaddr(pud) \
115 (__va((phys_addr_t)pud_ptfn(pud) << HV_LOG2_PAGE_TABLE_ALIGN))
116
117/*
118 * A pud_t points to a pmd_t array. Since we can have multiple per
119 * page, we don't have a one-to-one mapping of pud_t's to pages.
120 */
121#define pud_page(pud) pfn_to_page(PFN_DOWN(HV_PTFN_TO_CPA(pud_ptfn(pud))))
122
123static inline unsigned long pud_index(unsigned long address)
124{
125 return (address >> PUD_SHIFT) & (PTRS_PER_PUD - 1);
126}
127
128#define pmd_offset(pud, address) \
129 ((pmd_t *)pud_page_vaddr(*(pud)) + pmd_index(address))
130
131/* Normalize an address to having the correct high bits set. */
132#define pgd_addr_normalize pgd_addr_normalize
133static inline unsigned long pgd_addr_normalize(unsigned long addr)
134{
135 return ((long)addr << (CHIP_WORD_SIZE() - CHIP_VA_WIDTH())) >>
136 (CHIP_WORD_SIZE() - CHIP_VA_WIDTH());
137}
138
139/* We don't define any pgds for these addresses. */
140static inline int pgd_addr_invalid(unsigned long addr)
141{
142 return addr >= KERNEL_HIGH_VADDR || addr != pgd_addr_normalize(addr);
143}
144
145/*
146 * Use atomic instructions to provide atomicity against the hypervisor.
147 */
148#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
149static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
150 unsigned long addr, pte_t *ptep)
151{
152 return (__insn_fetchand(&ptep->val, ~HV_PTE_ACCESSED) >>
153 HV_PTE_INDEX_ACCESSED) & 0x1;
154}
155
156#define __HAVE_ARCH_PTEP_SET_WRPROTECT
157static inline void ptep_set_wrprotect(struct mm_struct *mm,
158 unsigned long addr, pte_t *ptep)
159{
160 __insn_fetchand(&ptep->val, ~HV_PTE_WRITABLE);
161}
162
163#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
164static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
165 unsigned long addr, pte_t *ptep)
166{
167 return hv_pte(__insn_exch(&ptep->val, 0UL));
168}
169
170#endif /* __ASSEMBLY__ */
171
172#endif /* _ASM_TILE_PGTABLE_64_H */
diff --git a/arch/tile/include/asm/pmc.h b/arch/tile/include/asm/pmc.h
deleted file mode 100644
index 7ae3956d9008..000000000000
--- a/arch/tile/include/asm/pmc.h
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright 2014 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_PMC_H
16#define _ASM_TILE_PMC_H
17
18#include <linux/ptrace.h>
19
20#define TILE_BASE_COUNTERS 2
21
22/* Bitfields below are derived from SPR PERF_COUNT_CTL*/
23#ifndef __tilegx__
24/* PERF_COUNT_CTL on TILEPro */
25#define TILE_CTL_EXCL_USER (1 << 7) /* exclude user level */
26#define TILE_CTL_EXCL_KERNEL (1 << 8) /* exclude kernel level */
27#define TILE_CTL_EXCL_HV (1 << 9) /* exclude hypervisor level */
28
29#define TILE_SEL_MASK 0x7f /* 7 bits for event SEL,
30 COUNT_0_SEL */
31#define TILE_PLM_MASK 0x780 /* 4 bits priv level msks,
32 COUNT_0_MASK*/
33#define TILE_EVENT_MASK (TILE_SEL_MASK | TILE_PLM_MASK)
34
35#else /* __tilegx__*/
36/* PERF_COUNT_CTL on TILEGx*/
37#define TILE_CTL_EXCL_USER (1 << 10) /* exclude user level */
38#define TILE_CTL_EXCL_KERNEL (1 << 11) /* exclude kernel level */
39#define TILE_CTL_EXCL_HV (1 << 12) /* exclude hypervisor level */
40
41#define TILE_SEL_MASK 0x3f /* 6 bits for event SEL,
42 COUNT_0_SEL*/
43#define TILE_BOX_MASK 0x1c0 /* 3 bits box msks,
44 COUNT_0_BOX */
45#define TILE_PLM_MASK 0x3c00 /* 4 bits priv level msks,
46 COUNT_0_MASK */
47#define TILE_EVENT_MASK (TILE_SEL_MASK | TILE_BOX_MASK | TILE_PLM_MASK)
48#endif /* __tilegx__*/
49
50/* Takes register and fault number. Returns error to disable the interrupt. */
51typedef int (*perf_irq_t)(struct pt_regs *, int);
52
53int userspace_perf_handler(struct pt_regs *regs, int fault);
54
55perf_irq_t reserve_pmc_hardware(perf_irq_t new_perf_irq);
56void release_pmc_hardware(void);
57
58unsigned long pmc_get_overflow(void);
59void pmc_ack_overflow(unsigned long status);
60
61void unmask_pmc_interrupts(void);
62void mask_pmc_interrupts(void);
63
64#endif /* _ASM_TILE_PMC_H */
diff --git a/arch/tile/include/asm/processor.h b/arch/tile/include/asm/processor.h
deleted file mode 100644
index f71e5206650b..000000000000
--- a/arch/tile/include/asm/processor.h
+++ /dev/null
@@ -1,368 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_PROCESSOR_H
16#define _ASM_TILE_PROCESSOR_H
17
18#include <arch/chip.h>
19
20#ifndef __ASSEMBLY__
21
22/*
23 * NOTE: we don't include <linux/ptrace.h> or <linux/percpu.h> as one
24 * normally would, due to #include dependencies.
25 */
26#include <linux/types.h>
27#include <asm/ptrace.h>
28#include <asm/percpu.h>
29
30#include <arch/spr_def.h>
31
32struct task_struct;
33struct thread_struct;
34
35typedef struct {
36 unsigned long seg;
37} mm_segment_t;
38
39/*
40 * Default implementation of macro that returns current
41 * instruction pointer ("program counter").
42 */
43void *current_text_addr(void);
44
45#if CHIP_HAS_TILE_DMA()
46/* Capture the state of a suspended DMA. */
47struct tile_dma_state {
48 int enabled;
49 unsigned long src;
50 unsigned long dest;
51 unsigned long strides;
52 unsigned long chunk_size;
53 unsigned long src_chunk;
54 unsigned long dest_chunk;
55 unsigned long byte;
56 unsigned long status;
57};
58
59/*
60 * A mask of the DMA status register for selecting only the 'running'
61 * and 'done' bits.
62 */
63#define DMA_STATUS_MASK \
64 (SPR_DMA_STATUS__RUNNING_MASK | SPR_DMA_STATUS__DONE_MASK)
65#endif
66
67/*
68 * Track asynchronous TLB events (faults and access violations)
69 * that occur while we are in kernel mode from DMA or the SN processor.
70 */
71struct async_tlb {
72 short fault_num; /* original fault number; 0 if none */
73 char is_fault; /* was it a fault (vs an access violation) */
74 char is_write; /* for fault: was it caused by a write? */
75 unsigned long address; /* what address faulted? */
76};
77
78#ifdef CONFIG_HARDWALL
79struct hardwall_info;
80struct hardwall_task {
81 /* Which hardwall is this task tied to? (or NULL if none) */
82 struct hardwall_info *info;
83 /* Chains this task into the list at info->task_head. */
84 struct list_head list;
85};
86#ifdef __tilepro__
87#define HARDWALL_TYPES 1 /* udn */
88#else
89#define HARDWALL_TYPES 3 /* udn, idn, and ipi */
90#endif
91#endif
92
93struct thread_struct {
94 /* kernel stack pointer */
95 unsigned long ksp;
96 /* kernel PC */
97 unsigned long pc;
98 /* starting user stack pointer (for page migration) */
99 unsigned long usp0;
100 /* pid of process that created this one */
101 pid_t creator_pid;
102#if CHIP_HAS_TILE_DMA()
103 /* DMA info for suspended threads (byte == 0 means no DMA state) */
104 struct tile_dma_state tile_dma_state;
105#endif
106 /* User EX_CONTEXT registers */
107 unsigned long ex_context[2];
108 /* User SYSTEM_SAVE registers */
109 unsigned long system_save[4];
110 /* User interrupt mask */
111 unsigned long long interrupt_mask;
112 /* User interrupt-control 0 state */
113 unsigned long intctrl_0;
114 /* Any other miscellaneous processor state bits */
115 unsigned long proc_status;
116#if !CHIP_HAS_FIXED_INTVEC_BASE()
117 /* Interrupt base for PL0 interrupts */
118 unsigned long interrupt_vector_base;
119#endif
120 /* Tile cache retry fifo high-water mark */
121 unsigned long tile_rtf_hwm;
122#if CHIP_HAS_DSTREAM_PF()
123 /* Data stream prefetch control */
124 unsigned long dstream_pf;
125#endif
126#ifdef CONFIG_HARDWALL
127 /* Hardwall information for various resources. */
128 struct hardwall_task hardwall[HARDWALL_TYPES];
129#endif
130#if CHIP_HAS_TILE_DMA()
131 /* Async DMA TLB fault information */
132 struct async_tlb dma_async_tlb;
133#endif
134};
135
136#endif /* !__ASSEMBLY__ */
137
138/*
139 * Start with "sp" this many bytes below the top of the kernel stack.
140 * This allows us to be cache-aware when handling the initial save
141 * of the pt_regs value to the stack.
142 */
143#define STACK_TOP_DELTA 64
144
145/*
146 * When entering the kernel via a fault, start with the top of the
147 * pt_regs structure this many bytes below the top of the page.
148 * This aligns the pt_regs structure optimally for cache-line access.
149 */
150#ifdef __tilegx__
151#define KSTK_PTREGS_GAP 48
152#else
153#define KSTK_PTREGS_GAP 56
154#endif
155
156#ifndef __ASSEMBLY__
157
158#ifdef __tilegx__
159#define TASK_SIZE_MAX (_AC(1, UL) << (MAX_VA_WIDTH - 1))
160#else
161#define TASK_SIZE_MAX PAGE_OFFSET
162#endif
163
164/* TASK_SIZE and related variables are always checked in "current" context. */
165#ifdef CONFIG_COMPAT
166#define COMPAT_TASK_SIZE (1UL << 31)
167#define TASK_SIZE ((current_thread_info()->status & TS_COMPAT) ?\
168 COMPAT_TASK_SIZE : TASK_SIZE_MAX)
169#else
170#define TASK_SIZE TASK_SIZE_MAX
171#endif
172
173#define VDSO_BASE ((unsigned long)current->active_mm->context.vdso_base)
174#define VDSO_SYM(x) (VDSO_BASE + (unsigned long)(x))
175
176#define STACK_TOP TASK_SIZE
177
178/* STACK_TOP_MAX is used temporarily in execve and should not check COMPAT. */
179#define STACK_TOP_MAX TASK_SIZE_MAX
180
181/*
182 * This decides where the kernel will search for a free chunk of vm
183 * space during mmap's, if it is using bottom-up mapping.
184 */
185#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
186
187#define HAVE_ARCH_PICK_MMAP_LAYOUT
188
189#define INIT_THREAD { \
190 .ksp = (unsigned long)init_stack + THREAD_SIZE - STACK_TOP_DELTA, \
191 .interrupt_mask = -1ULL \
192}
193
194/* Kernel stack top for the task that first boots on this cpu. */
195DECLARE_PER_CPU(unsigned long, boot_sp);
196
197/* PC to boot from on this cpu. */
198DECLARE_PER_CPU(unsigned long, boot_pc);
199
200/* Do necessary setup to start up a newly executed thread. */
201static inline void start_thread(struct pt_regs *regs,
202 unsigned long pc, unsigned long usp)
203{
204 regs->pc = pc;
205 regs->sp = usp;
206 single_step_execve();
207}
208
209/* Free all resources held by a thread. */
210static inline void release_thread(struct task_struct *dead_task)
211{
212 /* Nothing for now */
213}
214
215extern void prepare_exit_to_usermode(struct pt_regs *regs, u32 flags);
216
217unsigned long get_wchan(struct task_struct *p);
218
219/* Return initial ksp value for given task. */
220#define task_ksp0(task) \
221 ((unsigned long)(task)->stack + THREAD_SIZE - STACK_TOP_DELTA)
222
223/* Return some info about the user process TASK. */
224#define task_pt_regs(task) \
225 ((struct pt_regs *)(task_ksp0(task) - KSTK_PTREGS_GAP) - 1)
226#define current_pt_regs() \
227 ((struct pt_regs *)((stack_pointer | (THREAD_SIZE - 1)) - \
228 STACK_TOP_DELTA - (KSTK_PTREGS_GAP - 1)) - 1)
229#define task_sp(task) (task_pt_regs(task)->sp)
230#define task_pc(task) (task_pt_regs(task)->pc)
231/* Aliases for pc and sp (used in fs/proc/array.c) */
232#define KSTK_EIP(task) task_pc(task)
233#define KSTK_ESP(task) task_sp(task)
234
235/* Fine-grained unaligned JIT support */
236#define GET_UNALIGN_CTL(tsk, adr) get_unalign_ctl((tsk), (adr))
237#define SET_UNALIGN_CTL(tsk, val) set_unalign_ctl((tsk), (val))
238
239extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
240extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
241
242/* Standard format for printing registers and other word-size data. */
243#ifdef __tilegx__
244# define REGFMT "0x%016lx"
245#else
246# define REGFMT "0x%08lx"
247#endif
248
249/*
250 * Do some slow action (e.g. read a slow SPR).
251 * Note that this must also have compiler-barrier semantics since
252 * it may be used in a busy loop reading memory.
253 */
254static inline void cpu_relax(void)
255{
256 __insn_mfspr(SPR_PASS);
257 barrier();
258}
259
260/* Info on this processor (see fs/proc/cpuinfo.c) */
261struct seq_operations;
262extern const struct seq_operations cpuinfo_op;
263
264/* Provide information about the chip model. */
265extern char chip_model[64];
266
267/* Data on which physical memory controller corresponds to which NUMA node. */
268extern int node_controller[];
269
270/* Does the heap allocator return hash-for-home pages by default? */
271extern int hash_default;
272
273/* Should kernel stack pages be hash-for-home? */
274extern int kstack_hash;
275
276/* Does MAP_ANONYMOUS return hash-for-home pages by default? */
277#define uheap_hash hash_default
278
279
280/* Are we using huge pages in the TLB for kernel data? */
281extern int kdata_huge;
282
283/* Support standard Linux prefetching. */
284#define ARCH_HAS_PREFETCH
285#define prefetch(x) __builtin_prefetch(x)
286#define PREFETCH_STRIDE CHIP_L2_LINE_SIZE()
287
288/* Bring a value into the L1D, faulting the TLB if necessary. */
289#ifdef __tilegx__
290#define prefetch_L1(x) __insn_prefetch_l1_fault((void *)(x))
291#else
292#define prefetch_L1(x) __insn_prefetch_L1((void *)(x))
293#endif
294
295#else /* __ASSEMBLY__ */
296
297/* Do some slow action (e.g. read a slow SPR). */
298#define CPU_RELAX mfspr zero, SPR_PASS
299
300#endif /* !__ASSEMBLY__ */
301
302/* Assembly code assumes that the PL is in the low bits. */
303#if SPR_EX_CONTEXT_1_1__PL_SHIFT != 0
304# error Fix assembly assumptions about PL
305#endif
306
307/* We sometimes use these macros for EX_CONTEXT_0_1 as well. */
308#if SPR_EX_CONTEXT_1_1__PL_SHIFT != SPR_EX_CONTEXT_0_1__PL_SHIFT || \
309 SPR_EX_CONTEXT_1_1__PL_RMASK != SPR_EX_CONTEXT_0_1__PL_RMASK || \
310 SPR_EX_CONTEXT_1_1__ICS_SHIFT != SPR_EX_CONTEXT_0_1__ICS_SHIFT || \
311 SPR_EX_CONTEXT_1_1__ICS_RMASK != SPR_EX_CONTEXT_0_1__ICS_RMASK
312# error Fix assumptions that EX1 macros work for both PL0 and PL1
313#endif
314
315/* Allow pulling apart and recombining the PL and ICS bits in EX_CONTEXT. */
316#define EX1_PL(ex1) \
317 (((ex1) >> SPR_EX_CONTEXT_1_1__PL_SHIFT) & SPR_EX_CONTEXT_1_1__PL_RMASK)
318#define EX1_ICS(ex1) \
319 (((ex1) >> SPR_EX_CONTEXT_1_1__ICS_SHIFT) & SPR_EX_CONTEXT_1_1__ICS_RMASK)
320#define PL_ICS_EX1(pl, ics) \
321 (((pl) << SPR_EX_CONTEXT_1_1__PL_SHIFT) | \
322 ((ics) << SPR_EX_CONTEXT_1_1__ICS_SHIFT))
323
324/*
325 * Provide symbolic constants for PLs.
326 */
327#define USER_PL 0
328#if CONFIG_KERNEL_PL == 2
329#define GUEST_PL 1
330#endif
331#define KERNEL_PL CONFIG_KERNEL_PL
332
333/* SYSTEM_SAVE_K_0 holds the current cpu number ORed with ksp0. */
334#ifdef __tilegx__
335#define CPU_SHIFT 48
336#if CHIP_VA_WIDTH() > CPU_SHIFT
337# error Too many VA bits!
338#endif
339#define MAX_CPU_ID ((1 << (64 - CPU_SHIFT)) - 1)
340#define raw_smp_processor_id() \
341 ((int)(__insn_mfspr(SPR_SYSTEM_SAVE_K_0) >> CPU_SHIFT))
342#define get_current_ksp0() \
343 ((unsigned long)(((long)__insn_mfspr(SPR_SYSTEM_SAVE_K_0) << \
344 (64 - CPU_SHIFT)) >> (64 - CPU_SHIFT)))
345#define next_current_ksp0(task) ({ \
346 unsigned long __ksp0 = task_ksp0(task) & ((1UL << CPU_SHIFT) - 1); \
347 unsigned long __cpu = (long)raw_smp_processor_id() << CPU_SHIFT; \
348 __ksp0 | __cpu; \
349})
350#else
351#define LOG2_NR_CPU_IDS 6
352#define MAX_CPU_ID ((1 << LOG2_NR_CPU_IDS) - 1)
353#define raw_smp_processor_id() \
354 ((int)__insn_mfspr(SPR_SYSTEM_SAVE_K_0) & MAX_CPU_ID)
355#define get_current_ksp0() \
356 (__insn_mfspr(SPR_SYSTEM_SAVE_K_0) & ~MAX_CPU_ID)
357#define next_current_ksp0(task) ({ \
358 unsigned long __ksp0 = task_ksp0(task); \
359 int __cpu = raw_smp_processor_id(); \
360 BUG_ON(__ksp0 & MAX_CPU_ID); \
361 __ksp0 | __cpu; \
362})
363#endif
364#if CONFIG_NR_CPUS > (MAX_CPU_ID + 1)
365# error Too many cpus!
366#endif
367
368#endif /* _ASM_TILE_PROCESSOR_H */
diff --git a/arch/tile/include/asm/ptrace.h b/arch/tile/include/asm/ptrace.h
deleted file mode 100644
index b9620c077abc..000000000000
--- a/arch/tile/include/asm/ptrace.h
+++ /dev/null
@@ -1,97 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14#ifndef _ASM_TILE_PTRACE_H
15#define _ASM_TILE_PTRACE_H
16
17#include <linux/compiler.h>
18
19#ifndef __ASSEMBLY__
20/* Benefit from consistent use of "long" on all chips. */
21typedef unsigned long pt_reg_t;
22#endif
23
24#include <uapi/asm/ptrace.h>
25
26#define PTRACE_O_MASK_TILE (PTRACE_O_TRACEMIGRATE)
27#define PT_TRACE_MIGRATE PT_EVENT_FLAG(PTRACE_EVENT_MIGRATE)
28
29/* Flag bits in pt_regs.flags */
30#define PT_FLAGS_DISABLE_IRQ 1 /* on return to kernel, disable irqs */
31#define PT_FLAGS_CALLER_SAVES 2 /* caller-save registers are valid */
32#define PT_FLAGS_RESTORE_REGS 4 /* restore callee-save regs on return */
33
34#ifndef __ASSEMBLY__
35
36#define regs_return_value(regs) ((regs)->regs[0])
37#define instruction_pointer(regs) ((regs)->pc)
38#define profile_pc(regs) instruction_pointer(regs)
39#define user_stack_pointer(regs) ((regs)->sp)
40
41/* Does the process account for user or for system time? */
42#define user_mode(regs) (EX1_PL((regs)->ex1) < KERNEL_PL)
43
44/* Fill in a struct pt_regs with the current kernel registers. */
45struct pt_regs *get_pt_regs(struct pt_regs *);
46
47/* Trace the current syscall. */
48extern int do_syscall_trace_enter(struct pt_regs *regs);
49extern void do_syscall_trace_exit(struct pt_regs *regs);
50
51#define arch_has_single_step() (1)
52
53/*
54 * A structure for all single-stepper state.
55 *
56 * Also update defines in assembler section if it changes
57 */
58struct single_step_state {
59 /* the page to which we will write hacked-up bundles */
60 void __user *buffer;
61
62 union {
63 int flags;
64 struct {
65 unsigned long is_enabled:1, update:1, update_reg:6;
66 };
67 };
68
69 unsigned long orig_pc; /* the original PC */
70 unsigned long next_pc; /* return PC if no branch (PC + 1) */
71 unsigned long branch_next_pc; /* return PC if we did branch/jump */
72 unsigned long update_value; /* value to restore to update_target */
73};
74
75/* Single-step the instruction at regs->pc */
76extern void single_step_once(struct pt_regs *regs);
77
78/* Clean up after execve(). */
79extern void single_step_execve(void);
80
81struct task_struct;
82
83extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs);
84
85#ifdef __tilegx__
86/* We need this since sigval_t has a user pointer in it, for GETSIGINFO etc. */
87#define __ARCH_WANT_COMPAT_SYS_PTRACE
88#endif
89
90#endif /* !__ASSEMBLY__ */
91
92#define SINGLESTEP_STATE_MASK_IS_ENABLED 0x1
93#define SINGLESTEP_STATE_MASK_UPDATE 0x2
94#define SINGLESTEP_STATE_TARGET_LB 2
95#define SINGLESTEP_STATE_TARGET_UB 7
96
97#endif /* _ASM_TILE_PTRACE_H */
diff --git a/arch/tile/include/asm/sections.h b/arch/tile/include/asm/sections.h
deleted file mode 100644
index 50343bfe7936..000000000000
--- a/arch/tile/include/asm/sections.h
+++ /dev/null
@@ -1,44 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_SECTIONS_H
16#define _ASM_TILE_SECTIONS_H
17
18#define arch_is_kernel_data arch_is_kernel_data
19
20#include <asm-generic/sections.h>
21
22extern char vdso_start[], vdso_end[];
23#ifdef CONFIG_COMPAT
24extern char vdso32_start[], vdso32_end[];
25#endif
26
27/* Not exactly sections, but PC comparison points in the code. */
28extern char __rt_sigreturn[], __rt_sigreturn_end[];
29#ifdef __tilegx__
30extern char __start_unalign_asm_code[], __end_unalign_asm_code[];
31#else
32extern char sys_cmpxchg[], __sys_cmpxchg_end[];
33extern char __sys_cmpxchg_grab_lock[];
34extern char __start_atomic_asm_code[], __end_atomic_asm_code[];
35#endif
36
37/* Handle the discontiguity between _sdata and _text. */
38static inline int arch_is_kernel_data(unsigned long addr)
39{
40 return addr >= (unsigned long)_sdata &&
41 addr < (unsigned long)_end;
42}
43
44#endif /* _ASM_TILE_SECTIONS_H */
diff --git a/arch/tile/include/asm/setup.h b/arch/tile/include/asm/setup.h
deleted file mode 100644
index 2a0347af0702..000000000000
--- a/arch/tile/include/asm/setup.h
+++ /dev/null
@@ -1,57 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14#ifndef _ASM_TILE_SETUP_H
15#define _ASM_TILE_SETUP_H
16
17
18#include <linux/pfn.h>
19#include <linux/init.h>
20#include <uapi/asm/setup.h>
21
22/*
23 * Reserved space for vmalloc and iomap - defined in asm/page.h
24 */
25#define MAXMEM_PFN PFN_DOWN(MAXMEM)
26
27int tile_console_write(const char *buf, int count);
28
29#ifdef CONFIG_EARLY_PRINTK
30void early_panic(const char *fmt, ...);
31#else
32#define early_panic panic
33#endif
34
35/* Init-time routine to do tile-specific per-cpu setup. */
36void setup_cpu(int boot);
37
38/* User-level DMA management functions */
39void grant_dma_mpls(void);
40void restrict_dma_mpls(void);
41
42#ifdef CONFIG_HARDWALL
43/* User-level network management functions */
44void reset_network_state(void);
45struct task_struct;
46void hardwall_switch_tasks(struct task_struct *prev, struct task_struct *next);
47void hardwall_deactivate_all(struct task_struct *task);
48int hardwall_ipi_valid(int cpu);
49
50/* Hook hardwall code into changes in affinity. */
51#define arch_set_cpus_allowed(p, new_mask) do { \
52 if (!cpumask_equal(&p->cpus_allowed, new_mask)) \
53 hardwall_deactivate_all(p); \
54} while (0)
55#endif
56
57#endif /* _ASM_TILE_SETUP_H */
diff --git a/arch/tile/include/asm/sigframe.h b/arch/tile/include/asm/sigframe.h
deleted file mode 100644
index 994d3d30205f..000000000000
--- a/arch/tile/include/asm/sigframe.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_SIGFRAME_H
16#define _ASM_TILE_SIGFRAME_H
17
18/* Indicate that syscall return should not examine r0 */
19#define INT_SWINT_1_SIGRETURN (~0)
20
21#ifndef __ASSEMBLY__
22
23#include <arch/abi.h>
24
25struct rt_sigframe {
26 unsigned char save_area[C_ABI_SAVE_AREA_SIZE]; /* caller save area */
27 struct siginfo info;
28 struct ucontext uc;
29};
30
31#endif /* !__ASSEMBLY__ */
32
33#endif /* _ASM_TILE_SIGFRAME_H */
diff --git a/arch/tile/include/asm/signal.h b/arch/tile/include/asm/signal.h
deleted file mode 100644
index 10e183de96d3..000000000000
--- a/arch/tile/include/asm/signal.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14#ifndef _ASM_TILE_SIGNAL_H
15#define _ASM_TILE_SIGNAL_H
16
17#include <uapi/asm/signal.h>
18
19#if !defined(__ASSEMBLY__)
20struct pt_regs;
21int restore_sigcontext(struct pt_regs *, struct sigcontext __user *);
22int setup_sigcontext(struct sigcontext __user *, struct pt_regs *);
23void do_signal(struct pt_regs *regs);
24void signal_fault(const char *type, struct pt_regs *,
25 void __user *frame, int sig);
26void trace_unhandled_signal(const char *type, struct pt_regs *regs,
27 unsigned long address, int signo);
28#endif
29#endif /* _ASM_TILE_SIGNAL_H */
diff --git a/arch/tile/include/asm/smp.h b/arch/tile/include/asm/smp.h
deleted file mode 100644
index 735e7f144733..000000000000
--- a/arch/tile/include/asm/smp.h
+++ /dev/null
@@ -1,139 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_SMP_H
16#define _ASM_TILE_SMP_H
17
18#ifdef CONFIG_SMP
19
20#include <asm/processor.h>
21#include <linux/cpumask.h>
22#include <linux/irqreturn.h>
23#include <hv/hypervisor.h>
24
25/* Set up this tile to support receiving hypervisor messages */
26void init_messaging(void);
27
28/* Set up this tile to support receiving device interrupts and IPIs. */
29void init_per_tile_IRQs(void);
30
31/* Send a message to processors specified in mask */
32void send_IPI_many(const struct cpumask *mask, int tag);
33
34/* Send a message to all but the sending processor */
35void send_IPI_allbutself(int tag);
36
37/* Send a message to a specific processor */
38void send_IPI_single(int dest, int tag);
39
40/* Process an IPI message */
41void evaluate_message(int tag);
42
43/* Boot a secondary cpu */
44void online_secondary(void);
45
46/* Topology of the supervisor tile grid, and coordinates of boot processor */
47extern HV_Topology smp_topology;
48
49/* Accessors for grid size */
50#define smp_height (smp_topology.height)
51#define smp_width (smp_topology.width)
52
53/* Convenience functions for converting cpu <-> coords. */
54static inline int cpu_x(int cpu)
55{
56 return cpu % smp_width;
57}
58static inline int cpu_y(int cpu)
59{
60 return cpu / smp_width;
61}
62static inline int xy_to_cpu(int x, int y)
63{
64 return y * smp_width + x;
65}
66
67/* Hypervisor message tags sent via the tile send_IPI*() routines. */
68#define MSG_TAG_START_CPU 1
69#define MSG_TAG_STOP_CPU 2
70#define MSG_TAG_CALL_FUNCTION_MANY 3
71#define MSG_TAG_CALL_FUNCTION_SINGLE 4
72#define MSG_TAG_IRQ_WORK 5
73
74/* Hook for the generic smp_call_function_many() routine. */
75static inline void arch_send_call_function_ipi_mask(struct cpumask *mask)
76{
77 send_IPI_many(mask, MSG_TAG_CALL_FUNCTION_MANY);
78}
79
80/* Hook for the generic smp_call_function_single() routine. */
81static inline void arch_send_call_function_single_ipi(int cpu)
82{
83 send_IPI_single(cpu, MSG_TAG_CALL_FUNCTION_SINGLE);
84}
85
86/* Print out the boot string describing which cpus were disabled. */
87void print_disabled_cpus(void);
88
89#else /* !CONFIG_SMP */
90
91#define smp_master_cpu 0
92#define smp_height 1
93#define smp_width 1
94#define cpu_x(cpu) 0
95#define cpu_y(cpu) 0
96#define xy_to_cpu(x, y) 0
97
98#endif /* !CONFIG_SMP */
99
100
101/* Which cpus may be used as the lotar in a page table entry. */
102extern struct cpumask cpu_lotar_map;
103#define cpu_is_valid_lotar(cpu) cpumask_test_cpu((cpu), &cpu_lotar_map)
104
105/* Which processors are used for hash-for-home mapping */
106extern struct cpumask hash_for_home_map;
107
108/* Which cpus can have their cache flushed by hv_flush_remote(). */
109extern struct cpumask cpu_cacheable_map;
110#define cpu_cacheable(cpu) cpumask_test_cpu((cpu), &cpu_cacheable_map)
111
112/* Convert an HV_LOTAR value into a cpu. */
113static inline int hv_lotar_to_cpu(HV_LOTAR lotar)
114{
115 return HV_LOTAR_X(lotar) + (HV_LOTAR_Y(lotar) * smp_width);
116}
117
118/*
119 * Extension of <linux/cpumask.h> functionality when you just want
120 * to express a mask or suppression or inclusion region without
121 * being too concerned about exactly which cpus are valid in that region.
122 */
123int bitmap_parselist_crop(const char *bp, unsigned long *maskp, int nmaskbits);
124
125#define cpulist_parse_crop(buf, dst) \
126 __cpulist_parse_crop((buf), (dst), NR_CPUS)
127static inline int __cpulist_parse_crop(const char *buf, struct cpumask *dstp,
128 int nbits)
129{
130 return bitmap_parselist_crop(buf, cpumask_bits(dstp), nbits);
131}
132
133/* Initialize the IPI subsystem. */
134void ipi_init(void);
135
136/* Function for start-cpu message to cause us to jump to. */
137extern unsigned long start_cpu_function_addr;
138
139#endif /* _ASM_TILE_SMP_H */
diff --git a/arch/tile/include/asm/spinlock.h b/arch/tile/include/asm/spinlock.h
deleted file mode 100644
index 1a8bd4740c28..000000000000
--- a/arch/tile/include/asm/spinlock.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_SPINLOCK_H
16#define _ASM_TILE_SPINLOCK_H
17
18#ifdef __tilegx__
19#include <asm/spinlock_64.h>
20#else
21#include <asm/spinlock_32.h>
22#endif
23
24#endif /* _ASM_TILE_SPINLOCK_H */
diff --git a/arch/tile/include/asm/spinlock_32.h b/arch/tile/include/asm/spinlock_32.h
deleted file mode 100644
index fb5313d77315..000000000000
--- a/arch/tile/include/asm/spinlock_32.h
+++ /dev/null
@@ -1,109 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * 32-bit SMP spinlocks.
15 */
16
17#ifndef _ASM_TILE_SPINLOCK_32_H
18#define _ASM_TILE_SPINLOCK_32_H
19
20#include <linux/atomic.h>
21#include <asm/page.h>
22#include <linux/compiler.h>
23
24/*
25 * We only use even ticket numbers so the '1' inserted by a tns is
26 * an unambiguous "ticket is busy" flag.
27 */
28#define TICKET_QUANTUM 2
29
30
31/*
32 * SMP ticket spinlocks, allowing only a single CPU anywhere
33 *
34 * (the type definitions are in asm/spinlock_types.h)
35 */
36static inline int arch_spin_is_locked(arch_spinlock_t *lock)
37{
38 /*
39 * Note that even if a new ticket is in the process of being
40 * acquired, so lock->next_ticket is 1, it's still reasonable
41 * to claim the lock is held, since it will be momentarily
42 * if not already. There's no need to wait for a "valid"
43 * lock->next_ticket to become available.
44 * Use READ_ONCE() to ensure that calling this in a loop is OK.
45 */
46 int curr = READ_ONCE(lock->current_ticket);
47 int next = READ_ONCE(lock->next_ticket);
48
49 return next != curr;
50}
51
52void arch_spin_lock(arch_spinlock_t *lock);
53
54int arch_spin_trylock(arch_spinlock_t *lock);
55
56static inline void arch_spin_unlock(arch_spinlock_t *lock)
57{
58 /* For efficiency, overlap fetching the old ticket with the wmb(). */
59 int old_ticket = lock->current_ticket;
60 wmb(); /* guarantee anything modified under the lock is visible */
61 lock->current_ticket = old_ticket + TICKET_QUANTUM;
62}
63
64/*
65 * Read-write spinlocks, allowing multiple readers
66 * but only one writer.
67 *
68 * We use a "tns/store-back" technique on a single word to manage
69 * the lock state, looping around to retry if the tns returns 1.
70 */
71
72/* Internal layout of the word; do not use. */
73#define _WR_NEXT_SHIFT 8
74#define _WR_CURR_SHIFT 16
75#define _WR_WIDTH 8
76#define _RD_COUNT_SHIFT 24
77#define _RD_COUNT_WIDTH 8
78
79/**
80 * arch_read_lock() - acquire a read lock.
81 */
82void arch_read_lock(arch_rwlock_t *rwlock);
83
84/**
85 * arch_write_lock() - acquire a write lock.
86 */
87void arch_write_lock(arch_rwlock_t *rwlock);
88
89/**
90 * arch_read_trylock() - try to acquire a read lock.
91 */
92int arch_read_trylock(arch_rwlock_t *rwlock);
93
94/**
95 * arch_write_trylock() - try to acquire a write lock.
96 */
97int arch_write_trylock(arch_rwlock_t *rwlock);
98
99/**
100 * arch_read_unlock() - release a read lock.
101 */
102void arch_read_unlock(arch_rwlock_t *rwlock);
103
104/**
105 * arch_write_unlock() - release a write lock.
106 */
107void arch_write_unlock(arch_rwlock_t *rwlock);
108
109#endif /* _ASM_TILE_SPINLOCK_32_H */
diff --git a/arch/tile/include/asm/spinlock_64.h b/arch/tile/include/asm/spinlock_64.h
deleted file mode 100644
index 5b616ef642a8..000000000000
--- a/arch/tile/include/asm/spinlock_64.h
+++ /dev/null
@@ -1,138 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * 64-bit SMP ticket spinlocks, allowing only a single CPU anywhere
15 * (the type definitions are in asm/spinlock_types.h)
16 */
17
18#ifndef _ASM_TILE_SPINLOCK_64_H
19#define _ASM_TILE_SPINLOCK_64_H
20
21#include <linux/compiler.h>
22
23/* Shifts and masks for the various fields in "lock". */
24#define __ARCH_SPIN_CURRENT_SHIFT 17
25#define __ARCH_SPIN_NEXT_MASK 0x7fff
26#define __ARCH_SPIN_NEXT_OVERFLOW 0x8000
27
28/*
29 * Return the "current" portion of a ticket lock value,
30 * i.e. the number that currently owns the lock.
31 */
32static inline u32 arch_spin_current(u32 val)
33{
34 return val >> __ARCH_SPIN_CURRENT_SHIFT;
35}
36
37/*
38 * Return the "next" portion of a ticket lock value,
39 * i.e. the number that the next task to try to acquire the lock will get.
40 */
41static inline u32 arch_spin_next(u32 val)
42{
43 return val & __ARCH_SPIN_NEXT_MASK;
44}
45
46/* The lock is locked if a task would have to wait to get it. */
47static inline int arch_spin_is_locked(arch_spinlock_t *lock)
48{
49 /* Use READ_ONCE() to ensure that calling this in a loop is OK. */
50 u32 val = READ_ONCE(lock->lock);
51 return arch_spin_current(val) != arch_spin_next(val);
52}
53
54/* Bump the current ticket so the next task owns the lock. */
55static inline void arch_spin_unlock(arch_spinlock_t *lock)
56{
57 wmb(); /* guarantee anything modified under the lock is visible */
58 __insn_fetchadd4(&lock->lock, 1U << __ARCH_SPIN_CURRENT_SHIFT);
59}
60
61void arch_spin_lock_slow(arch_spinlock_t *lock, u32 val);
62
63/* Grab the "next" ticket number and bump it atomically.
64 * If the current ticket is not ours, go to the slow path.
65 * We also take the slow path if the "next" value overflows.
66 */
67static inline void arch_spin_lock(arch_spinlock_t *lock)
68{
69 u32 val = __insn_fetchadd4(&lock->lock, 1);
70 u32 ticket = val & (__ARCH_SPIN_NEXT_MASK | __ARCH_SPIN_NEXT_OVERFLOW);
71 if (unlikely(arch_spin_current(val) != ticket))
72 arch_spin_lock_slow(lock, ticket);
73}
74
75/* Try to get the lock, and return whether we succeeded. */
76int arch_spin_trylock(arch_spinlock_t *lock);
77
78/*
79 * Read-write spinlocks, allowing multiple readers
80 * but only one writer.
81 *
82 * We use fetchadd() for readers, and fetchor() with the sign bit
83 * for writers.
84 */
85
86#define __WRITE_LOCK_BIT (1 << 31)
87
88static inline int arch_write_val_locked(int val)
89{
90 return val < 0; /* Optimize "val & __WRITE_LOCK_BIT". */
91}
92
93extern void __read_lock_failed(arch_rwlock_t *rw);
94
95static inline void arch_read_lock(arch_rwlock_t *rw)
96{
97 u32 val = __insn_fetchaddgez4(&rw->lock, 1);
98 if (unlikely(arch_write_val_locked(val)))
99 __read_lock_failed(rw);
100}
101
102extern void __write_lock_failed(arch_rwlock_t *rw, u32 val);
103
104static inline void arch_write_lock(arch_rwlock_t *rw)
105{
106 u32 val = __insn_fetchor4(&rw->lock, __WRITE_LOCK_BIT);
107 if (unlikely(val != 0))
108 __write_lock_failed(rw, val);
109}
110
111static inline void arch_read_unlock(arch_rwlock_t *rw)
112{
113 __insn_mf();
114 __insn_fetchadd4(&rw->lock, -1);
115}
116
117static inline void arch_write_unlock(arch_rwlock_t *rw)
118{
119 __insn_mf();
120 __insn_exch4(&rw->lock, 0); /* Avoid waiting in the write buffer. */
121}
122
123static inline int arch_read_trylock(arch_rwlock_t *rw)
124{
125 return !arch_write_val_locked(__insn_fetchaddgez4(&rw->lock, 1));
126}
127
128static inline int arch_write_trylock(arch_rwlock_t *rw)
129{
130 u32 val = __insn_fetchor4(&rw->lock, __WRITE_LOCK_BIT);
131 if (likely(val == 0))
132 return 1;
133 if (!arch_write_val_locked(val))
134 __insn_fetchand4(&rw->lock, ~__WRITE_LOCK_BIT);
135 return 0;
136}
137
138#endif /* _ASM_TILE_SPINLOCK_64_H */
diff --git a/arch/tile/include/asm/spinlock_types.h b/arch/tile/include/asm/spinlock_types.h
deleted file mode 100644
index a71f59b49c50..000000000000
--- a/arch/tile/include/asm/spinlock_types.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_SPINLOCK_TYPES_H
16#define _ASM_TILE_SPINLOCK_TYPES_H
17
18#ifndef __LINUX_SPINLOCK_TYPES_H
19# error "please don't include this file directly"
20#endif
21
22#ifdef __tilegx__
23
24/* Low 15 bits are "next"; high 15 bits are "current". */
25typedef struct arch_spinlock {
26 unsigned int lock;
27} arch_spinlock_t;
28
29#define __ARCH_SPIN_LOCK_UNLOCKED { 0 }
30
31/* High bit is "writer owns"; low 31 bits are a count of readers. */
32typedef struct arch_rwlock {
33 unsigned int lock;
34} arch_rwlock_t;
35
36#define __ARCH_RW_LOCK_UNLOCKED { 0 }
37
38#else
39
40typedef struct arch_spinlock {
41 /* Next ticket number to hand out. */
42 int next_ticket;
43 /* The ticket number that currently owns this lock. */
44 int current_ticket;
45} arch_spinlock_t;
46
47#define __ARCH_SPIN_LOCK_UNLOCKED { 0, 0 }
48
49/*
50 * Byte 0 for tns (only the low bit is used), byte 1 for ticket-lock "next",
51 * byte 2 for ticket-lock "current", byte 3 for reader count.
52 */
53typedef struct arch_rwlock {
54 unsigned int lock;
55} arch_rwlock_t;
56
57#define __ARCH_RW_LOCK_UNLOCKED { 0 }
58
59#endif
60#endif /* _ASM_TILE_SPINLOCK_TYPES_H */
diff --git a/arch/tile/include/asm/stack.h b/arch/tile/include/asm/stack.h
deleted file mode 100644
index 3573325e340b..000000000000
--- a/arch/tile/include/asm/stack.h
+++ /dev/null
@@ -1,73 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_STACK_H
16#define _ASM_TILE_STACK_H
17
18#include <linux/types.h>
19#include <linux/sched.h>
20#include <linux/sched/debug.h>
21
22#include <asm/backtrace.h>
23#include <asm/page.h>
24#include <hv/hypervisor.h>
25
26/* Everything we need to keep track of a backtrace iteration */
27struct KBacktraceIterator {
28 BacktraceIterator it;
29 struct task_struct *task; /* task we are backtracing */
30 int end; /* iteration complete. */
31 int new_context; /* new context is starting */
32 int profile; /* profiling, so stop on async intrpt */
33 int verbose; /* printk extra info (don't want to
34 * do this for profiling) */
35 int is_current; /* backtracing current task */
36};
37
38/* Iteration methods for kernel backtraces */
39
40/*
41 * Initialize a KBacktraceIterator from a task_struct, and optionally from
42 * a set of registers. If the registers are omitted, the process is
43 * assumed to be descheduled, and registers are read from the process's
44 * thread_struct and stack. "verbose" means to printk some additional
45 * information about fault handlers as we pass them on the stack.
46 */
47extern void KBacktraceIterator_init(struct KBacktraceIterator *kbt,
48 struct task_struct *, struct pt_regs *);
49
50/* Initialize iterator based on current stack. */
51extern void KBacktraceIterator_init_current(struct KBacktraceIterator *kbt);
52
53/* Helper method for above. */
54extern void _KBacktraceIterator_init_current(struct KBacktraceIterator *kbt,
55 ulong pc, ulong lr, ulong sp, ulong r52);
56
57/* No more frames? */
58extern int KBacktraceIterator_end(struct KBacktraceIterator *kbt);
59
60/* Advance to the next frame. */
61extern void KBacktraceIterator_next(struct KBacktraceIterator *kbt);
62
63/* Dump just the contents of the pt_regs structure. */
64extern void tile_show_regs(struct pt_regs *);
65
66/*
67 * Dump stack given complete register info. Use only from the
68 * architecture-specific code; show_stack()
69 * and dump_stack() are architecture-independent entry points.
70 */
71extern void tile_show_stack(struct KBacktraceIterator *);
72
73#endif /* _ASM_TILE_STACK_H */
diff --git a/arch/tile/include/asm/string.h b/arch/tile/include/asm/string.h
deleted file mode 100644
index 92b271bd9ebd..000000000000
--- a/arch/tile/include/asm/string.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_STRING_H
16#define _ASM_TILE_STRING_H
17
18#define __HAVE_ARCH_MEMCHR
19#define __HAVE_ARCH_MEMSET
20#define __HAVE_ARCH_MEMCPY
21#define __HAVE_ARCH_MEMMOVE
22#define __HAVE_ARCH_STRCHR
23#define __HAVE_ARCH_STRLEN
24#define __HAVE_ARCH_STRNLEN
25
26extern __kernel_size_t strlen(const char *);
27extern __kernel_size_t strnlen(const char *, __kernel_size_t);
28extern char *strchr(const char *s, int c);
29extern void *memchr(const void *s, int c, size_t n);
30extern void *memset(void *, int, __kernel_size_t);
31extern void *memcpy(void *, const void *, __kernel_size_t);
32extern void *memmove(void *, const void *, __kernel_size_t);
33
34#endif /* _ASM_TILE_STRING_H */
diff --git a/arch/tile/include/asm/switch_to.h b/arch/tile/include/asm/switch_to.h
deleted file mode 100644
index 34ee72705521..000000000000
--- a/arch/tile/include/asm/switch_to.h
+++ /dev/null
@@ -1,77 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_SWITCH_TO_H
16#define _ASM_TILE_SWITCH_TO_H
17
18#include <arch/sim_def.h>
19
20/*
21 * switch_to(n) should switch tasks to task nr n, first
22 * checking that n isn't the current task, in which case it does nothing.
23 * The number of callee-saved registers saved on the kernel stack
24 * is defined here for use in copy_thread() and must agree with __switch_to().
25 */
26#define CALLEE_SAVED_FIRST_REG 30
27#define CALLEE_SAVED_REGS_COUNT 24 /* r30 to r52, plus an empty to align */
28
29#ifndef __ASSEMBLY__
30
31struct task_struct;
32
33/*
34 * Pause the DMA engine and static network before task switching.
35 */
36#define prepare_arch_switch(next) _prepare_arch_switch(next)
37void _prepare_arch_switch(struct task_struct *next);
38
39struct task_struct;
40#define switch_to(prev, next, last) ((last) = _switch_to((prev), (next)))
41extern struct task_struct *_switch_to(struct task_struct *prev,
42 struct task_struct *next);
43
44/* Helper function for _switch_to(). */
45extern struct task_struct *__switch_to(struct task_struct *prev,
46 struct task_struct *next,
47 unsigned long new_system_save_k_0);
48
49/* Address that switched-away from tasks are at. */
50extern unsigned long get_switch_to_pc(void);
51
52/*
53 * Kernel threads can check to see if they need to migrate their
54 * stack whenever they return from a context switch; for user
55 * threads, we defer until they are returning to user-space.
56 * We defer homecache migration until the runqueue lock is released.
57 */
58#define finish_arch_post_lock_switch() do { \
59 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_SWITCH | \
60 (current->pid << _SIM_CONTROL_OPERATOR_BITS)); \
61 if (current->mm == NULL && !kstack_hash && \
62 current_thread_info()->homecache_cpu != raw_smp_processor_id()) \
63 homecache_migrate_kthread(); \
64} while (0)
65
66/* Support function for forking a new task. */
67void ret_from_fork(void);
68
69/* Support function for forking a new kernel thread. */
70void ret_from_kernel_thread(void *fn, void *arg);
71
72/* Called from ret_from_xxx() when a new process starts up. */
73struct task_struct *sim_notify_fork(struct task_struct *prev);
74
75#endif /* !__ASSEMBLY__ */
76
77#endif /* _ASM_TILE_SWITCH_TO_H */
diff --git a/arch/tile/include/asm/syscall.h b/arch/tile/include/asm/syscall.h
deleted file mode 100644
index 373d73064ea1..000000000000
--- a/arch/tile/include/asm/syscall.h
+++ /dev/null
@@ -1,111 +0,0 @@
1/*
2 * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 *
15 * See asm-generic/syscall.h for descriptions of what we must do here.
16 */
17
18#ifndef _ASM_TILE_SYSCALL_H
19#define _ASM_TILE_SYSCALL_H
20
21#include <linux/sched.h>
22#include <linux/err.h>
23#include <linux/audit.h>
24#include <linux/compat.h>
25#include <arch/abi.h>
26
27/* The array of function pointers for syscalls. */
28extern void *sys_call_table[];
29#ifdef CONFIG_COMPAT
30extern void *compat_sys_call_table[];
31#endif
32
33/*
34 * Only the low 32 bits of orig_r0 are meaningful, so we return int.
35 * This importantly ignores the high bits on 64-bit, so comparisons
36 * sign-extend the low 32 bits.
37 */
38static inline int syscall_get_nr(struct task_struct *t, struct pt_regs *regs)
39{
40 return regs->regs[TREG_SYSCALL_NR];
41}
42
43static inline void syscall_rollback(struct task_struct *task,
44 struct pt_regs *regs)
45{
46 regs->regs[0] = regs->orig_r0;
47}
48
49static inline long syscall_get_error(struct task_struct *task,
50 struct pt_regs *regs)
51{
52 unsigned long error = regs->regs[0];
53 return IS_ERR_VALUE(error) ? error : 0;
54}
55
56static inline long syscall_get_return_value(struct task_struct *task,
57 struct pt_regs *regs)
58{
59 return regs->regs[0];
60}
61
62static inline void syscall_set_return_value(struct task_struct *task,
63 struct pt_regs *regs,
64 int error, long val)
65{
66 if (error) {
67 /* R0 is the passed-in negative error, R1 is positive. */
68 regs->regs[0] = error;
69 regs->regs[1] = -error;
70 } else {
71 /* R1 set to zero to indicate no error. */
72 regs->regs[0] = val;
73 regs->regs[1] = 0;
74 }
75}
76
77static inline void syscall_get_arguments(struct task_struct *task,
78 struct pt_regs *regs,
79 unsigned int i, unsigned int n,
80 unsigned long *args)
81{
82 BUG_ON(i + n > 6);
83 memcpy(args, &regs[i], n * sizeof(args[0]));
84}
85
86static inline void syscall_set_arguments(struct task_struct *task,
87 struct pt_regs *regs,
88 unsigned int i, unsigned int n,
89 const unsigned long *args)
90{
91 BUG_ON(i + n > 6);
92 memcpy(&regs[i], args, n * sizeof(args[0]));
93}
94
95/*
96 * We don't care about endianness (__AUDIT_ARCH_LE bit) here because
97 * tile has the same system calls both on little- and big- endian.
98 */
99static inline int syscall_get_arch(void)
100{
101 if (is_compat_task())
102 return AUDIT_ARCH_TILEGX32;
103
104#ifdef CONFIG_TILEGX
105 return AUDIT_ARCH_TILEGX;
106#else
107 return AUDIT_ARCH_TILEPRO;
108#endif
109}
110
111#endif /* _ASM_TILE_SYSCALL_H */
diff --git a/arch/tile/include/asm/syscalls.h b/arch/tile/include/asm/syscalls.h
deleted file mode 100644
index 07b298450ef2..000000000000
--- a/arch/tile/include/asm/syscalls.h
+++ /dev/null
@@ -1,70 +0,0 @@
1/*
2 * syscalls.h - Linux syscall interfaces (arch-specific)
3 *
4 * Copyright (c) 2008 Jaswinder Singh Rajput
5 * Copyright 2010 Tilera Corporation. All Rights Reserved.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, version 2.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for
15 * more details.
16 */
17
18#ifndef _ASM_TILE_SYSCALLS_H
19#define _ASM_TILE_SYSCALLS_H
20
21#include <linux/compiler.h>
22#include <linux/linkage.h>
23#include <linux/signal.h>
24#include <linux/types.h>
25#include <linux/compat.h>
26
27/*
28 * Note that by convention, any syscall which requires the current
29 * register set takes an additional "struct pt_regs *" pointer; a
30 * _sys_xxx() trampoline in intvec*.S just sets up the pointer and
31 * jumps to sys_xxx().
32 */
33
34/* kernel/sys.c */
35ssize_t sys32_readahead(int fd, u32 offset_lo, u32 offset_hi, u32 count);
36long sys32_fadvise64(int fd, u32 offset_lo, u32 offset_hi,
37 u32 len, int advice);
38int sys32_fadvise64_64(int fd, u32 offset_lo, u32 offset_hi,
39 u32 len_lo, u32 len_hi, int advice);
40long sys_cacheflush(unsigned long addr, unsigned long len,
41 unsigned long flags);
42#ifndef __tilegx__ /* No mmap() in the 32-bit kernel. */
43#define sys_mmap sys_mmap
44#endif
45
46#ifndef __tilegx__
47/* mm/fault.c */
48long sys_cmpxchg_badaddr(unsigned long address);
49#endif
50
51#ifdef CONFIG_COMPAT
52/* These four are not defined for 64-bit, but serve as "compat" syscalls. */
53long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg);
54long sys_fstat64(unsigned long fd, struct stat64 __user *statbuf);
55long sys_truncate64(const char __user *path, loff_t length);
56long sys_ftruncate64(unsigned int fd, loff_t length);
57#endif
58
59/* Provide versions of standard syscalls that use current_pt_regs(). */
60long sys_rt_sigreturn(void);
61#define sys_rt_sigreturn sys_rt_sigreturn
62
63/* These are the intvec*.S trampolines. */
64long _sys_rt_sigreturn(void);
65long _sys_clone(unsigned long clone_flags, unsigned long newsp,
66 void __user *parent_tid, void __user *child_tid);
67
68#include <asm-generic/syscalls.h>
69
70#endif /* _ASM_TILE_SYSCALLS_H */
diff --git a/arch/tile/include/asm/thread_info.h b/arch/tile/include/asm/thread_info.h
deleted file mode 100644
index 2adcacd85749..000000000000
--- a/arch/tile/include/asm/thread_info.h
+++ /dev/null
@@ -1,167 +0,0 @@
1/*
2 * Copyright (C) 2002 David Howells (dhowells@redhat.com)
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_THREAD_INFO_H
17#define _ASM_TILE_THREAD_INFO_H
18
19#include <asm/processor.h>
20#include <asm/page.h>
21#ifndef __ASSEMBLY__
22
23/*
24 * Low level task data that assembly code needs immediate access to.
25 * The structure is placed at the bottom of the supervisor stack.
26 */
27struct thread_info {
28 struct task_struct *task; /* main task structure */
29 unsigned long flags; /* low level flags */
30 unsigned long status; /* thread-synchronous flags */
31 __u32 homecache_cpu; /* CPU we are homecached on */
32 __u32 cpu; /* current CPU */
33 int preempt_count; /* 0 => preemptable,
34 <0 => BUG */
35
36 mm_segment_t addr_limit; /* thread address space
37 (KERNEL_DS or USER_DS) */
38 struct single_step_state *step_state; /* single step state
39 (if non-zero) */
40 int align_ctl; /* controls unaligned access */
41#ifdef __tilegx__
42 unsigned long unalign_jit_tmp[4]; /* temp r0..r3 storage */
43 void __user *unalign_jit_base; /* unalign fixup JIT base */
44#endif
45 bool in_backtrace; /* currently doing backtrace? */
46};
47
48/*
49 * macros/functions for gaining access to the thread information structure.
50 */
51#define INIT_THREAD_INFO(tsk) \
52{ \
53 .task = &tsk, \
54 .flags = 0, \
55 .cpu = 0, \
56 .preempt_count = INIT_PREEMPT_COUNT, \
57 .addr_limit = KERNEL_DS, \
58 .step_state = NULL, \
59 .align_ctl = 0, \
60}
61
62#endif /* !__ASSEMBLY__ */
63
64#if PAGE_SIZE < 8192
65#define THREAD_SIZE_ORDER (13 - PAGE_SHIFT)
66#else
67#define THREAD_SIZE_ORDER (0)
68#endif
69#define THREAD_SIZE_PAGES (1 << THREAD_SIZE_ORDER)
70
71#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
72#define LOG2_THREAD_SIZE (PAGE_SHIFT + THREAD_SIZE_ORDER)
73
74#define STACK_WARN (THREAD_SIZE/8)
75
76#ifndef __ASSEMBLY__
77
78void arch_release_thread_stack(unsigned long *stack);
79
80/* How to get the thread information struct from C. */
81register unsigned long stack_pointer __asm__("sp");
82
83#define current_thread_info() \
84 ((struct thread_info *)(stack_pointer & -THREAD_SIZE))
85
86/* Sit on a nap instruction until interrupted. */
87extern void smp_nap(void);
88
89/* Enable interrupts racelessly and nap forever: helper for arch_cpu_idle(). */
90extern void _cpu_idle(void);
91
92#else /* __ASSEMBLY__ */
93
94/*
95 * How to get the thread information struct from assembly.
96 * Note that we use different macros since different architectures
97 * have different semantics in their "mm" instruction and we would
98 * like to guarantee that the macro expands to exactly one instruction.
99 */
100#ifdef __tilegx__
101#define EXTRACT_THREAD_INFO(reg) mm reg, zero, LOG2_THREAD_SIZE, 63
102#else
103#define GET_THREAD_INFO(reg) mm reg, sp, zero, LOG2_THREAD_SIZE, 31
104#endif
105
106#endif /* !__ASSEMBLY__ */
107
108/*
109 * Thread information flags that various assembly files may need to access.
110 * Keep flags accessed frequently in low bits, particular since it makes
111 * it easier to build constants in assembly.
112 */
113#define TIF_SIGPENDING 0 /* signal pending */
114#define TIF_NEED_RESCHED 1 /* rescheduling necessary */
115#define TIF_SINGLESTEP 2 /* restore singlestep on return to
116 user mode */
117#define TIF_ASYNC_TLB 3 /* got an async TLB fault in kernel */
118#define TIF_SYSCALL_TRACE 4 /* syscall trace active */
119#define TIF_SYSCALL_AUDIT 5 /* syscall auditing active */
120#define TIF_SECCOMP 6 /* secure computing */
121#define TIF_MEMDIE 7 /* OOM killer at work */
122#define TIF_NOTIFY_RESUME 8 /* callback before returning to user */
123#define TIF_SYSCALL_TRACEPOINT 9 /* syscall tracepoint instrumentation */
124#define TIF_POLLING_NRFLAG 10 /* idle is polling for TIF_NEED_RESCHED */
125#define TIF_NOHZ 11 /* in adaptive nohz mode */
126
127#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
128#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
129#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
130#define _TIF_ASYNC_TLB (1<<TIF_ASYNC_TLB)
131#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
132#define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
133#define _TIF_SECCOMP (1<<TIF_SECCOMP)
134#define _TIF_MEMDIE (1<<TIF_MEMDIE)
135#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
136#define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
137#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
138#define _TIF_NOHZ (1<<TIF_NOHZ)
139
140/* Work to do as we loop to exit to user space. */
141#define _TIF_WORK_MASK \
142 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
143 _TIF_ASYNC_TLB | _TIF_NOTIFY_RESUME)
144
145/* Work to do on any return to user space. */
146#define _TIF_ALLWORK_MASK \
147 (_TIF_WORK_MASK | _TIF_SINGLESTEP | _TIF_NOHZ)
148
149/* Work to do at syscall entry. */
150#define _TIF_SYSCALL_ENTRY_WORK \
151 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
152
153/* Work to do at syscall exit. */
154#define _TIF_SYSCALL_EXIT_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT)
155
156/*
157 * Thread-synchronous status.
158 *
159 * This is different from the flags in that nobody else
160 * ever touches our thread-synchronous status, so we don't
161 * have to worry about atomic accesses.
162 */
163#ifdef __tilegx__
164#define TS_COMPAT 0x0001 /* 32-bit compatibility mode */
165#endif
166
167#endif /* _ASM_TILE_THREAD_INFO_H */
diff --git a/arch/tile/include/asm/tile-desc.h b/arch/tile/include/asm/tile-desc.h
deleted file mode 100644
index 43849bf79dcb..000000000000
--- a/arch/tile/include/asm/tile-desc.h
+++ /dev/null
@@ -1,19 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef __tilegx__
16#include <asm/tile-desc_32.h>
17#else
18#include <asm/tile-desc_64.h>
19#endif
diff --git a/arch/tile/include/asm/tile-desc_32.h b/arch/tile/include/asm/tile-desc_32.h
deleted file mode 100644
index f09c5c43b0b2..000000000000
--- a/arch/tile/include/asm/tile-desc_32.h
+++ /dev/null
@@ -1,553 +0,0 @@
1/* TILEPro opcode information.
2 *
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 *
15 *
16 *
17 *
18 *
19 */
20
21#ifndef opcode_tilepro_h
22#define opcode_tilepro_h
23
24#include <arch/opcode.h>
25
26
27enum
28{
29 TILEPRO_MAX_OPERANDS = 5 /* mm */
30};
31
32typedef enum
33{
34 TILEPRO_OPC_BPT,
35 TILEPRO_OPC_INFO,
36 TILEPRO_OPC_INFOL,
37 TILEPRO_OPC_J,
38 TILEPRO_OPC_JAL,
39 TILEPRO_OPC_MOVE,
40 TILEPRO_OPC_MOVE_SN,
41 TILEPRO_OPC_MOVEI,
42 TILEPRO_OPC_MOVEI_SN,
43 TILEPRO_OPC_MOVELI,
44 TILEPRO_OPC_MOVELI_SN,
45 TILEPRO_OPC_MOVELIS,
46 TILEPRO_OPC_PREFETCH,
47 TILEPRO_OPC_RAISE,
48 TILEPRO_OPC_ADD,
49 TILEPRO_OPC_ADD_SN,
50 TILEPRO_OPC_ADDB,
51 TILEPRO_OPC_ADDB_SN,
52 TILEPRO_OPC_ADDBS_U,
53 TILEPRO_OPC_ADDBS_U_SN,
54 TILEPRO_OPC_ADDH,
55 TILEPRO_OPC_ADDH_SN,
56 TILEPRO_OPC_ADDHS,
57 TILEPRO_OPC_ADDHS_SN,
58 TILEPRO_OPC_ADDI,
59 TILEPRO_OPC_ADDI_SN,
60 TILEPRO_OPC_ADDIB,
61 TILEPRO_OPC_ADDIB_SN,
62 TILEPRO_OPC_ADDIH,
63 TILEPRO_OPC_ADDIH_SN,
64 TILEPRO_OPC_ADDLI,
65 TILEPRO_OPC_ADDLI_SN,
66 TILEPRO_OPC_ADDLIS,
67 TILEPRO_OPC_ADDS,
68 TILEPRO_OPC_ADDS_SN,
69 TILEPRO_OPC_ADIFFB_U,
70 TILEPRO_OPC_ADIFFB_U_SN,
71 TILEPRO_OPC_ADIFFH,
72 TILEPRO_OPC_ADIFFH_SN,
73 TILEPRO_OPC_AND,
74 TILEPRO_OPC_AND_SN,
75 TILEPRO_OPC_ANDI,
76 TILEPRO_OPC_ANDI_SN,
77 TILEPRO_OPC_AULI,
78 TILEPRO_OPC_AVGB_U,
79 TILEPRO_OPC_AVGB_U_SN,
80 TILEPRO_OPC_AVGH,
81 TILEPRO_OPC_AVGH_SN,
82 TILEPRO_OPC_BBNS,
83 TILEPRO_OPC_BBNS_SN,
84 TILEPRO_OPC_BBNST,
85 TILEPRO_OPC_BBNST_SN,
86 TILEPRO_OPC_BBS,
87 TILEPRO_OPC_BBS_SN,
88 TILEPRO_OPC_BBST,
89 TILEPRO_OPC_BBST_SN,
90 TILEPRO_OPC_BGEZ,
91 TILEPRO_OPC_BGEZ_SN,
92 TILEPRO_OPC_BGEZT,
93 TILEPRO_OPC_BGEZT_SN,
94 TILEPRO_OPC_BGZ,
95 TILEPRO_OPC_BGZ_SN,
96 TILEPRO_OPC_BGZT,
97 TILEPRO_OPC_BGZT_SN,
98 TILEPRO_OPC_BITX,
99 TILEPRO_OPC_BITX_SN,
100 TILEPRO_OPC_BLEZ,
101 TILEPRO_OPC_BLEZ_SN,
102 TILEPRO_OPC_BLEZT,
103 TILEPRO_OPC_BLEZT_SN,
104 TILEPRO_OPC_BLZ,
105 TILEPRO_OPC_BLZ_SN,
106 TILEPRO_OPC_BLZT,
107 TILEPRO_OPC_BLZT_SN,
108 TILEPRO_OPC_BNZ,
109 TILEPRO_OPC_BNZ_SN,
110 TILEPRO_OPC_BNZT,
111 TILEPRO_OPC_BNZT_SN,
112 TILEPRO_OPC_BYTEX,
113 TILEPRO_OPC_BYTEX_SN,
114 TILEPRO_OPC_BZ,
115 TILEPRO_OPC_BZ_SN,
116 TILEPRO_OPC_BZT,
117 TILEPRO_OPC_BZT_SN,
118 TILEPRO_OPC_CLZ,
119 TILEPRO_OPC_CLZ_SN,
120 TILEPRO_OPC_CRC32_32,
121 TILEPRO_OPC_CRC32_32_SN,
122 TILEPRO_OPC_CRC32_8,
123 TILEPRO_OPC_CRC32_8_SN,
124 TILEPRO_OPC_CTZ,
125 TILEPRO_OPC_CTZ_SN,
126 TILEPRO_OPC_DRAIN,
127 TILEPRO_OPC_DTLBPR,
128 TILEPRO_OPC_DWORD_ALIGN,
129 TILEPRO_OPC_DWORD_ALIGN_SN,
130 TILEPRO_OPC_FINV,
131 TILEPRO_OPC_FLUSH,
132 TILEPRO_OPC_FNOP,
133 TILEPRO_OPC_ICOH,
134 TILEPRO_OPC_ILL,
135 TILEPRO_OPC_INTHB,
136 TILEPRO_OPC_INTHB_SN,
137 TILEPRO_OPC_INTHH,
138 TILEPRO_OPC_INTHH_SN,
139 TILEPRO_OPC_INTLB,
140 TILEPRO_OPC_INTLB_SN,
141 TILEPRO_OPC_INTLH,
142 TILEPRO_OPC_INTLH_SN,
143 TILEPRO_OPC_INV,
144 TILEPRO_OPC_IRET,
145 TILEPRO_OPC_JALB,
146 TILEPRO_OPC_JALF,
147 TILEPRO_OPC_JALR,
148 TILEPRO_OPC_JALRP,
149 TILEPRO_OPC_JB,
150 TILEPRO_OPC_JF,
151 TILEPRO_OPC_JR,
152 TILEPRO_OPC_JRP,
153 TILEPRO_OPC_LB,
154 TILEPRO_OPC_LB_SN,
155 TILEPRO_OPC_LB_U,
156 TILEPRO_OPC_LB_U_SN,
157 TILEPRO_OPC_LBADD,
158 TILEPRO_OPC_LBADD_SN,
159 TILEPRO_OPC_LBADD_U,
160 TILEPRO_OPC_LBADD_U_SN,
161 TILEPRO_OPC_LH,
162 TILEPRO_OPC_LH_SN,
163 TILEPRO_OPC_LH_U,
164 TILEPRO_OPC_LH_U_SN,
165 TILEPRO_OPC_LHADD,
166 TILEPRO_OPC_LHADD_SN,
167 TILEPRO_OPC_LHADD_U,
168 TILEPRO_OPC_LHADD_U_SN,
169 TILEPRO_OPC_LNK,
170 TILEPRO_OPC_LNK_SN,
171 TILEPRO_OPC_LW,
172 TILEPRO_OPC_LW_SN,
173 TILEPRO_OPC_LW_NA,
174 TILEPRO_OPC_LW_NA_SN,
175 TILEPRO_OPC_LWADD,
176 TILEPRO_OPC_LWADD_SN,
177 TILEPRO_OPC_LWADD_NA,
178 TILEPRO_OPC_LWADD_NA_SN,
179 TILEPRO_OPC_MAXB_U,
180 TILEPRO_OPC_MAXB_U_SN,
181 TILEPRO_OPC_MAXH,
182 TILEPRO_OPC_MAXH_SN,
183 TILEPRO_OPC_MAXIB_U,
184 TILEPRO_OPC_MAXIB_U_SN,
185 TILEPRO_OPC_MAXIH,
186 TILEPRO_OPC_MAXIH_SN,
187 TILEPRO_OPC_MF,
188 TILEPRO_OPC_MFSPR,
189 TILEPRO_OPC_MINB_U,
190 TILEPRO_OPC_MINB_U_SN,
191 TILEPRO_OPC_MINH,
192 TILEPRO_OPC_MINH_SN,
193 TILEPRO_OPC_MINIB_U,
194 TILEPRO_OPC_MINIB_U_SN,
195 TILEPRO_OPC_MINIH,
196 TILEPRO_OPC_MINIH_SN,
197 TILEPRO_OPC_MM,
198 TILEPRO_OPC_MNZ,
199 TILEPRO_OPC_MNZ_SN,
200 TILEPRO_OPC_MNZB,
201 TILEPRO_OPC_MNZB_SN,
202 TILEPRO_OPC_MNZH,
203 TILEPRO_OPC_MNZH_SN,
204 TILEPRO_OPC_MTSPR,
205 TILEPRO_OPC_MULHH_SS,
206 TILEPRO_OPC_MULHH_SS_SN,
207 TILEPRO_OPC_MULHH_SU,
208 TILEPRO_OPC_MULHH_SU_SN,
209 TILEPRO_OPC_MULHH_UU,
210 TILEPRO_OPC_MULHH_UU_SN,
211 TILEPRO_OPC_MULHHA_SS,
212 TILEPRO_OPC_MULHHA_SS_SN,
213 TILEPRO_OPC_MULHHA_SU,
214 TILEPRO_OPC_MULHHA_SU_SN,
215 TILEPRO_OPC_MULHHA_UU,
216 TILEPRO_OPC_MULHHA_UU_SN,
217 TILEPRO_OPC_MULHHSA_UU,
218 TILEPRO_OPC_MULHHSA_UU_SN,
219 TILEPRO_OPC_MULHL_SS,
220 TILEPRO_OPC_MULHL_SS_SN,
221 TILEPRO_OPC_MULHL_SU,
222 TILEPRO_OPC_MULHL_SU_SN,
223 TILEPRO_OPC_MULHL_US,
224 TILEPRO_OPC_MULHL_US_SN,
225 TILEPRO_OPC_MULHL_UU,
226 TILEPRO_OPC_MULHL_UU_SN,
227 TILEPRO_OPC_MULHLA_SS,
228 TILEPRO_OPC_MULHLA_SS_SN,
229 TILEPRO_OPC_MULHLA_SU,
230 TILEPRO_OPC_MULHLA_SU_SN,
231 TILEPRO_OPC_MULHLA_US,
232 TILEPRO_OPC_MULHLA_US_SN,
233 TILEPRO_OPC_MULHLA_UU,
234 TILEPRO_OPC_MULHLA_UU_SN,
235 TILEPRO_OPC_MULHLSA_UU,
236 TILEPRO_OPC_MULHLSA_UU_SN,
237 TILEPRO_OPC_MULLL_SS,
238 TILEPRO_OPC_MULLL_SS_SN,
239 TILEPRO_OPC_MULLL_SU,
240 TILEPRO_OPC_MULLL_SU_SN,
241 TILEPRO_OPC_MULLL_UU,
242 TILEPRO_OPC_MULLL_UU_SN,
243 TILEPRO_OPC_MULLLA_SS,
244 TILEPRO_OPC_MULLLA_SS_SN,
245 TILEPRO_OPC_MULLLA_SU,
246 TILEPRO_OPC_MULLLA_SU_SN,
247 TILEPRO_OPC_MULLLA_UU,
248 TILEPRO_OPC_MULLLA_UU_SN,
249 TILEPRO_OPC_MULLLSA_UU,
250 TILEPRO_OPC_MULLLSA_UU_SN,
251 TILEPRO_OPC_MVNZ,
252 TILEPRO_OPC_MVNZ_SN,
253 TILEPRO_OPC_MVZ,
254 TILEPRO_OPC_MVZ_SN,
255 TILEPRO_OPC_MZ,
256 TILEPRO_OPC_MZ_SN,
257 TILEPRO_OPC_MZB,
258 TILEPRO_OPC_MZB_SN,
259 TILEPRO_OPC_MZH,
260 TILEPRO_OPC_MZH_SN,
261 TILEPRO_OPC_NAP,
262 TILEPRO_OPC_NOP,
263 TILEPRO_OPC_NOR,
264 TILEPRO_OPC_NOR_SN,
265 TILEPRO_OPC_OR,
266 TILEPRO_OPC_OR_SN,
267 TILEPRO_OPC_ORI,
268 TILEPRO_OPC_ORI_SN,
269 TILEPRO_OPC_PACKBS_U,
270 TILEPRO_OPC_PACKBS_U_SN,
271 TILEPRO_OPC_PACKHB,
272 TILEPRO_OPC_PACKHB_SN,
273 TILEPRO_OPC_PACKHS,
274 TILEPRO_OPC_PACKHS_SN,
275 TILEPRO_OPC_PACKLB,
276 TILEPRO_OPC_PACKLB_SN,
277 TILEPRO_OPC_PCNT,
278 TILEPRO_OPC_PCNT_SN,
279 TILEPRO_OPC_RL,
280 TILEPRO_OPC_RL_SN,
281 TILEPRO_OPC_RLI,
282 TILEPRO_OPC_RLI_SN,
283 TILEPRO_OPC_S1A,
284 TILEPRO_OPC_S1A_SN,
285 TILEPRO_OPC_S2A,
286 TILEPRO_OPC_S2A_SN,
287 TILEPRO_OPC_S3A,
288 TILEPRO_OPC_S3A_SN,
289 TILEPRO_OPC_SADAB_U,
290 TILEPRO_OPC_SADAB_U_SN,
291 TILEPRO_OPC_SADAH,
292 TILEPRO_OPC_SADAH_SN,
293 TILEPRO_OPC_SADAH_U,
294 TILEPRO_OPC_SADAH_U_SN,
295 TILEPRO_OPC_SADB_U,
296 TILEPRO_OPC_SADB_U_SN,
297 TILEPRO_OPC_SADH,
298 TILEPRO_OPC_SADH_SN,
299 TILEPRO_OPC_SADH_U,
300 TILEPRO_OPC_SADH_U_SN,
301 TILEPRO_OPC_SB,
302 TILEPRO_OPC_SBADD,
303 TILEPRO_OPC_SEQ,
304 TILEPRO_OPC_SEQ_SN,
305 TILEPRO_OPC_SEQB,
306 TILEPRO_OPC_SEQB_SN,
307 TILEPRO_OPC_SEQH,
308 TILEPRO_OPC_SEQH_SN,
309 TILEPRO_OPC_SEQI,
310 TILEPRO_OPC_SEQI_SN,
311 TILEPRO_OPC_SEQIB,
312 TILEPRO_OPC_SEQIB_SN,
313 TILEPRO_OPC_SEQIH,
314 TILEPRO_OPC_SEQIH_SN,
315 TILEPRO_OPC_SH,
316 TILEPRO_OPC_SHADD,
317 TILEPRO_OPC_SHL,
318 TILEPRO_OPC_SHL_SN,
319 TILEPRO_OPC_SHLB,
320 TILEPRO_OPC_SHLB_SN,
321 TILEPRO_OPC_SHLH,
322 TILEPRO_OPC_SHLH_SN,
323 TILEPRO_OPC_SHLI,
324 TILEPRO_OPC_SHLI_SN,
325 TILEPRO_OPC_SHLIB,
326 TILEPRO_OPC_SHLIB_SN,
327 TILEPRO_OPC_SHLIH,
328 TILEPRO_OPC_SHLIH_SN,
329 TILEPRO_OPC_SHR,
330 TILEPRO_OPC_SHR_SN,
331 TILEPRO_OPC_SHRB,
332 TILEPRO_OPC_SHRB_SN,
333 TILEPRO_OPC_SHRH,
334 TILEPRO_OPC_SHRH_SN,
335 TILEPRO_OPC_SHRI,
336 TILEPRO_OPC_SHRI_SN,
337 TILEPRO_OPC_SHRIB,
338 TILEPRO_OPC_SHRIB_SN,
339 TILEPRO_OPC_SHRIH,
340 TILEPRO_OPC_SHRIH_SN,
341 TILEPRO_OPC_SLT,
342 TILEPRO_OPC_SLT_SN,
343 TILEPRO_OPC_SLT_U,
344 TILEPRO_OPC_SLT_U_SN,
345 TILEPRO_OPC_SLTB,
346 TILEPRO_OPC_SLTB_SN,
347 TILEPRO_OPC_SLTB_U,
348 TILEPRO_OPC_SLTB_U_SN,
349 TILEPRO_OPC_SLTE,
350 TILEPRO_OPC_SLTE_SN,
351 TILEPRO_OPC_SLTE_U,
352 TILEPRO_OPC_SLTE_U_SN,
353 TILEPRO_OPC_SLTEB,
354 TILEPRO_OPC_SLTEB_SN,
355 TILEPRO_OPC_SLTEB_U,
356 TILEPRO_OPC_SLTEB_U_SN,
357 TILEPRO_OPC_SLTEH,
358 TILEPRO_OPC_SLTEH_SN,
359 TILEPRO_OPC_SLTEH_U,
360 TILEPRO_OPC_SLTEH_U_SN,
361 TILEPRO_OPC_SLTH,
362 TILEPRO_OPC_SLTH_SN,
363 TILEPRO_OPC_SLTH_U,
364 TILEPRO_OPC_SLTH_U_SN,
365 TILEPRO_OPC_SLTI,
366 TILEPRO_OPC_SLTI_SN,
367 TILEPRO_OPC_SLTI_U,
368 TILEPRO_OPC_SLTI_U_SN,
369 TILEPRO_OPC_SLTIB,
370 TILEPRO_OPC_SLTIB_SN,
371 TILEPRO_OPC_SLTIB_U,
372 TILEPRO_OPC_SLTIB_U_SN,
373 TILEPRO_OPC_SLTIH,
374 TILEPRO_OPC_SLTIH_SN,
375 TILEPRO_OPC_SLTIH_U,
376 TILEPRO_OPC_SLTIH_U_SN,
377 TILEPRO_OPC_SNE,
378 TILEPRO_OPC_SNE_SN,
379 TILEPRO_OPC_SNEB,
380 TILEPRO_OPC_SNEB_SN,
381 TILEPRO_OPC_SNEH,
382 TILEPRO_OPC_SNEH_SN,
383 TILEPRO_OPC_SRA,
384 TILEPRO_OPC_SRA_SN,
385 TILEPRO_OPC_SRAB,
386 TILEPRO_OPC_SRAB_SN,
387 TILEPRO_OPC_SRAH,
388 TILEPRO_OPC_SRAH_SN,
389 TILEPRO_OPC_SRAI,
390 TILEPRO_OPC_SRAI_SN,
391 TILEPRO_OPC_SRAIB,
392 TILEPRO_OPC_SRAIB_SN,
393 TILEPRO_OPC_SRAIH,
394 TILEPRO_OPC_SRAIH_SN,
395 TILEPRO_OPC_SUB,
396 TILEPRO_OPC_SUB_SN,
397 TILEPRO_OPC_SUBB,
398 TILEPRO_OPC_SUBB_SN,
399 TILEPRO_OPC_SUBBS_U,
400 TILEPRO_OPC_SUBBS_U_SN,
401 TILEPRO_OPC_SUBH,
402 TILEPRO_OPC_SUBH_SN,
403 TILEPRO_OPC_SUBHS,
404 TILEPRO_OPC_SUBHS_SN,
405 TILEPRO_OPC_SUBS,
406 TILEPRO_OPC_SUBS_SN,
407 TILEPRO_OPC_SW,
408 TILEPRO_OPC_SWADD,
409 TILEPRO_OPC_SWINT0,
410 TILEPRO_OPC_SWINT1,
411 TILEPRO_OPC_SWINT2,
412 TILEPRO_OPC_SWINT3,
413 TILEPRO_OPC_TBLIDXB0,
414 TILEPRO_OPC_TBLIDXB0_SN,
415 TILEPRO_OPC_TBLIDXB1,
416 TILEPRO_OPC_TBLIDXB1_SN,
417 TILEPRO_OPC_TBLIDXB2,
418 TILEPRO_OPC_TBLIDXB2_SN,
419 TILEPRO_OPC_TBLIDXB3,
420 TILEPRO_OPC_TBLIDXB3_SN,
421 TILEPRO_OPC_TNS,
422 TILEPRO_OPC_TNS_SN,
423 TILEPRO_OPC_WH64,
424 TILEPRO_OPC_XOR,
425 TILEPRO_OPC_XOR_SN,
426 TILEPRO_OPC_XORI,
427 TILEPRO_OPC_XORI_SN,
428 TILEPRO_OPC_NONE
429} tilepro_mnemonic;
430
431
432
433
434typedef enum
435{
436 TILEPRO_PIPELINE_X0,
437 TILEPRO_PIPELINE_X1,
438 TILEPRO_PIPELINE_Y0,
439 TILEPRO_PIPELINE_Y1,
440 TILEPRO_PIPELINE_Y2,
441} tilepro_pipeline;
442
443#define tilepro_is_x_pipeline(p) ((int)(p) <= (int)TILEPRO_PIPELINE_X1)
444
445typedef enum
446{
447 TILEPRO_OP_TYPE_REGISTER,
448 TILEPRO_OP_TYPE_IMMEDIATE,
449 TILEPRO_OP_TYPE_ADDRESS,
450 TILEPRO_OP_TYPE_SPR
451} tilepro_operand_type;
452
453struct tilepro_operand
454{
455 /* Is this operand a register, immediate or address? */
456 tilepro_operand_type type;
457
458 /* The default relocation type for this operand. */
459 signed int default_reloc : 16;
460
461 /* How many bits is this value? (used for range checking) */
462 unsigned int num_bits : 5;
463
464 /* Is the value signed? (used for range checking) */
465 unsigned int is_signed : 1;
466
467 /* Is this operand a source register? */
468 unsigned int is_src_reg : 1;
469
470 /* Is this operand written? (i.e. is it a destination register) */
471 unsigned int is_dest_reg : 1;
472
473 /* Is this operand PC-relative? */
474 unsigned int is_pc_relative : 1;
475
476 /* By how many bits do we right shift the value before inserting? */
477 unsigned int rightshift : 2;
478
479 /* Return the bits for this operand to be ORed into an existing bundle. */
480 tilepro_bundle_bits (*insert) (int op);
481
482 /* Extract this operand and return it. */
483 unsigned int (*extract) (tilepro_bundle_bits bundle);
484};
485
486
487extern const struct tilepro_operand tilepro_operands[];
488
489/* One finite-state machine per pipe for rapid instruction decoding. */
490extern const unsigned short * const
491tilepro_bundle_decoder_fsms[TILEPRO_NUM_PIPELINE_ENCODINGS];
492
493
494struct tilepro_opcode
495{
496 /* The opcode mnemonic, e.g. "add" */
497 const char *name;
498
499 /* The enum value for this mnemonic. */
500 tilepro_mnemonic mnemonic;
501
502 /* A bit mask of which of the five pipes this instruction
503 is compatible with:
504 X0 0x01
505 X1 0x02
506 Y0 0x04
507 Y1 0x08
508 Y2 0x10 */
509 unsigned char pipes;
510
511 /* How many operands are there? */
512 unsigned char num_operands;
513
514 /* Which register does this write implicitly, or TREG_ZERO if none? */
515 unsigned char implicitly_written_register;
516
517 /* Can this be bundled with other instructions (almost always true). */
518 unsigned char can_bundle;
519
520 /* The description of the operands. Each of these is an
521 * index into the tilepro_operands[] table. */
522 unsigned char operands[TILEPRO_NUM_PIPELINE_ENCODINGS][TILEPRO_MAX_OPERANDS];
523
524};
525
526extern const struct tilepro_opcode tilepro_opcodes[];
527
528
529/* Used for non-textual disassembly into structs. */
530struct tilepro_decoded_instruction
531{
532 const struct tilepro_opcode *opcode;
533 const struct tilepro_operand *operands[TILEPRO_MAX_OPERANDS];
534 int operand_values[TILEPRO_MAX_OPERANDS];
535};
536
537
538/* Disassemble a bundle into a struct for machine processing. */
539extern int parse_insn_tilepro(tilepro_bundle_bits bits,
540 unsigned int pc,
541 struct tilepro_decoded_instruction
542 decoded[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE]);
543
544
545/* Given a set of bundle bits and a specific pipe, returns which
546 * instruction the bundle contains in that pipe.
547 */
548extern const struct tilepro_opcode *
549find_opcode(tilepro_bundle_bits bits, tilepro_pipeline pipe);
550
551
552
553#endif /* opcode_tilepro_h */
diff --git a/arch/tile/include/asm/tile-desc_64.h b/arch/tile/include/asm/tile-desc_64.h
deleted file mode 100644
index 1819efcba54d..000000000000
--- a/arch/tile/include/asm/tile-desc_64.h
+++ /dev/null
@@ -1,483 +0,0 @@
1/* TILE-Gx opcode information.
2 *
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 *
15 *
16 *
17 *
18 *
19 */
20
21#ifndef opcode_tile_h
22#define opcode_tile_h
23
24#include <arch/opcode.h>
25
26
27enum
28{
29 TILEGX_MAX_OPERANDS = 4 /* bfexts */
30};
31
32typedef enum
33{
34 TILEGX_OPC_BPT,
35 TILEGX_OPC_INFO,
36 TILEGX_OPC_INFOL,
37 TILEGX_OPC_MOVE,
38 TILEGX_OPC_MOVEI,
39 TILEGX_OPC_MOVELI,
40 TILEGX_OPC_PREFETCH,
41 TILEGX_OPC_PREFETCH_ADD_L1,
42 TILEGX_OPC_PREFETCH_ADD_L1_FAULT,
43 TILEGX_OPC_PREFETCH_ADD_L2,
44 TILEGX_OPC_PREFETCH_ADD_L2_FAULT,
45 TILEGX_OPC_PREFETCH_ADD_L3,
46 TILEGX_OPC_PREFETCH_ADD_L3_FAULT,
47 TILEGX_OPC_PREFETCH_L1,
48 TILEGX_OPC_PREFETCH_L1_FAULT,
49 TILEGX_OPC_PREFETCH_L2,
50 TILEGX_OPC_PREFETCH_L2_FAULT,
51 TILEGX_OPC_PREFETCH_L3,
52 TILEGX_OPC_PREFETCH_L3_FAULT,
53 TILEGX_OPC_RAISE,
54 TILEGX_OPC_ADD,
55 TILEGX_OPC_ADDI,
56 TILEGX_OPC_ADDLI,
57 TILEGX_OPC_ADDX,
58 TILEGX_OPC_ADDXI,
59 TILEGX_OPC_ADDXLI,
60 TILEGX_OPC_ADDXSC,
61 TILEGX_OPC_AND,
62 TILEGX_OPC_ANDI,
63 TILEGX_OPC_BEQZ,
64 TILEGX_OPC_BEQZT,
65 TILEGX_OPC_BFEXTS,
66 TILEGX_OPC_BFEXTU,
67 TILEGX_OPC_BFINS,
68 TILEGX_OPC_BGEZ,
69 TILEGX_OPC_BGEZT,
70 TILEGX_OPC_BGTZ,
71 TILEGX_OPC_BGTZT,
72 TILEGX_OPC_BLBC,
73 TILEGX_OPC_BLBCT,
74 TILEGX_OPC_BLBS,
75 TILEGX_OPC_BLBST,
76 TILEGX_OPC_BLEZ,
77 TILEGX_OPC_BLEZT,
78 TILEGX_OPC_BLTZ,
79 TILEGX_OPC_BLTZT,
80 TILEGX_OPC_BNEZ,
81 TILEGX_OPC_BNEZT,
82 TILEGX_OPC_CLZ,
83 TILEGX_OPC_CMOVEQZ,
84 TILEGX_OPC_CMOVNEZ,
85 TILEGX_OPC_CMPEQ,
86 TILEGX_OPC_CMPEQI,
87 TILEGX_OPC_CMPEXCH,
88 TILEGX_OPC_CMPEXCH4,
89 TILEGX_OPC_CMPLES,
90 TILEGX_OPC_CMPLEU,
91 TILEGX_OPC_CMPLTS,
92 TILEGX_OPC_CMPLTSI,
93 TILEGX_OPC_CMPLTU,
94 TILEGX_OPC_CMPLTUI,
95 TILEGX_OPC_CMPNE,
96 TILEGX_OPC_CMUL,
97 TILEGX_OPC_CMULA,
98 TILEGX_OPC_CMULAF,
99 TILEGX_OPC_CMULF,
100 TILEGX_OPC_CMULFR,
101 TILEGX_OPC_CMULH,
102 TILEGX_OPC_CMULHR,
103 TILEGX_OPC_CRC32_32,
104 TILEGX_OPC_CRC32_8,
105 TILEGX_OPC_CTZ,
106 TILEGX_OPC_DBLALIGN,
107 TILEGX_OPC_DBLALIGN2,
108 TILEGX_OPC_DBLALIGN4,
109 TILEGX_OPC_DBLALIGN6,
110 TILEGX_OPC_DRAIN,
111 TILEGX_OPC_DTLBPR,
112 TILEGX_OPC_EXCH,
113 TILEGX_OPC_EXCH4,
114 TILEGX_OPC_FDOUBLE_ADD_FLAGS,
115 TILEGX_OPC_FDOUBLE_ADDSUB,
116 TILEGX_OPC_FDOUBLE_MUL_FLAGS,
117 TILEGX_OPC_FDOUBLE_PACK1,
118 TILEGX_OPC_FDOUBLE_PACK2,
119 TILEGX_OPC_FDOUBLE_SUB_FLAGS,
120 TILEGX_OPC_FDOUBLE_UNPACK_MAX,
121 TILEGX_OPC_FDOUBLE_UNPACK_MIN,
122 TILEGX_OPC_FETCHADD,
123 TILEGX_OPC_FETCHADD4,
124 TILEGX_OPC_FETCHADDGEZ,
125 TILEGX_OPC_FETCHADDGEZ4,
126 TILEGX_OPC_FETCHAND,
127 TILEGX_OPC_FETCHAND4,
128 TILEGX_OPC_FETCHOR,
129 TILEGX_OPC_FETCHOR4,
130 TILEGX_OPC_FINV,
131 TILEGX_OPC_FLUSH,
132 TILEGX_OPC_FLUSHWB,
133 TILEGX_OPC_FNOP,
134 TILEGX_OPC_FSINGLE_ADD1,
135 TILEGX_OPC_FSINGLE_ADDSUB2,
136 TILEGX_OPC_FSINGLE_MUL1,
137 TILEGX_OPC_FSINGLE_MUL2,
138 TILEGX_OPC_FSINGLE_PACK1,
139 TILEGX_OPC_FSINGLE_PACK2,
140 TILEGX_OPC_FSINGLE_SUB1,
141 TILEGX_OPC_ICOH,
142 TILEGX_OPC_ILL,
143 TILEGX_OPC_INV,
144 TILEGX_OPC_IRET,
145 TILEGX_OPC_J,
146 TILEGX_OPC_JAL,
147 TILEGX_OPC_JALR,
148 TILEGX_OPC_JALRP,
149 TILEGX_OPC_JR,
150 TILEGX_OPC_JRP,
151 TILEGX_OPC_LD,
152 TILEGX_OPC_LD1S,
153 TILEGX_OPC_LD1S_ADD,
154 TILEGX_OPC_LD1U,
155 TILEGX_OPC_LD1U_ADD,
156 TILEGX_OPC_LD2S,
157 TILEGX_OPC_LD2S_ADD,
158 TILEGX_OPC_LD2U,
159 TILEGX_OPC_LD2U_ADD,
160 TILEGX_OPC_LD4S,
161 TILEGX_OPC_LD4S_ADD,
162 TILEGX_OPC_LD4U,
163 TILEGX_OPC_LD4U_ADD,
164 TILEGX_OPC_LD_ADD,
165 TILEGX_OPC_LDNA,
166 TILEGX_OPC_LDNA_ADD,
167 TILEGX_OPC_LDNT,
168 TILEGX_OPC_LDNT1S,
169 TILEGX_OPC_LDNT1S_ADD,
170 TILEGX_OPC_LDNT1U,
171 TILEGX_OPC_LDNT1U_ADD,
172 TILEGX_OPC_LDNT2S,
173 TILEGX_OPC_LDNT2S_ADD,
174 TILEGX_OPC_LDNT2U,
175 TILEGX_OPC_LDNT2U_ADD,
176 TILEGX_OPC_LDNT4S,
177 TILEGX_OPC_LDNT4S_ADD,
178 TILEGX_OPC_LDNT4U,
179 TILEGX_OPC_LDNT4U_ADD,
180 TILEGX_OPC_LDNT_ADD,
181 TILEGX_OPC_LNK,
182 TILEGX_OPC_MF,
183 TILEGX_OPC_MFSPR,
184 TILEGX_OPC_MM,
185 TILEGX_OPC_MNZ,
186 TILEGX_OPC_MTSPR,
187 TILEGX_OPC_MUL_HS_HS,
188 TILEGX_OPC_MUL_HS_HU,
189 TILEGX_OPC_MUL_HS_LS,
190 TILEGX_OPC_MUL_HS_LU,
191 TILEGX_OPC_MUL_HU_HU,
192 TILEGX_OPC_MUL_HU_LS,
193 TILEGX_OPC_MUL_HU_LU,
194 TILEGX_OPC_MUL_LS_LS,
195 TILEGX_OPC_MUL_LS_LU,
196 TILEGX_OPC_MUL_LU_LU,
197 TILEGX_OPC_MULA_HS_HS,
198 TILEGX_OPC_MULA_HS_HU,
199 TILEGX_OPC_MULA_HS_LS,
200 TILEGX_OPC_MULA_HS_LU,
201 TILEGX_OPC_MULA_HU_HU,
202 TILEGX_OPC_MULA_HU_LS,
203 TILEGX_OPC_MULA_HU_LU,
204 TILEGX_OPC_MULA_LS_LS,
205 TILEGX_OPC_MULA_LS_LU,
206 TILEGX_OPC_MULA_LU_LU,
207 TILEGX_OPC_MULAX,
208 TILEGX_OPC_MULX,
209 TILEGX_OPC_MZ,
210 TILEGX_OPC_NAP,
211 TILEGX_OPC_NOP,
212 TILEGX_OPC_NOR,
213 TILEGX_OPC_OR,
214 TILEGX_OPC_ORI,
215 TILEGX_OPC_PCNT,
216 TILEGX_OPC_REVBITS,
217 TILEGX_OPC_REVBYTES,
218 TILEGX_OPC_ROTL,
219 TILEGX_OPC_ROTLI,
220 TILEGX_OPC_SHL,
221 TILEGX_OPC_SHL16INSLI,
222 TILEGX_OPC_SHL1ADD,
223 TILEGX_OPC_SHL1ADDX,
224 TILEGX_OPC_SHL2ADD,
225 TILEGX_OPC_SHL2ADDX,
226 TILEGX_OPC_SHL3ADD,
227 TILEGX_OPC_SHL3ADDX,
228 TILEGX_OPC_SHLI,
229 TILEGX_OPC_SHLX,
230 TILEGX_OPC_SHLXI,
231 TILEGX_OPC_SHRS,
232 TILEGX_OPC_SHRSI,
233 TILEGX_OPC_SHRU,
234 TILEGX_OPC_SHRUI,
235 TILEGX_OPC_SHRUX,
236 TILEGX_OPC_SHRUXI,
237 TILEGX_OPC_SHUFFLEBYTES,
238 TILEGX_OPC_ST,
239 TILEGX_OPC_ST1,
240 TILEGX_OPC_ST1_ADD,
241 TILEGX_OPC_ST2,
242 TILEGX_OPC_ST2_ADD,
243 TILEGX_OPC_ST4,
244 TILEGX_OPC_ST4_ADD,
245 TILEGX_OPC_ST_ADD,
246 TILEGX_OPC_STNT,
247 TILEGX_OPC_STNT1,
248 TILEGX_OPC_STNT1_ADD,
249 TILEGX_OPC_STNT2,
250 TILEGX_OPC_STNT2_ADD,
251 TILEGX_OPC_STNT4,
252 TILEGX_OPC_STNT4_ADD,
253 TILEGX_OPC_STNT_ADD,
254 TILEGX_OPC_SUB,
255 TILEGX_OPC_SUBX,
256 TILEGX_OPC_SUBXSC,
257 TILEGX_OPC_SWINT0,
258 TILEGX_OPC_SWINT1,
259 TILEGX_OPC_SWINT2,
260 TILEGX_OPC_SWINT3,
261 TILEGX_OPC_TBLIDXB0,
262 TILEGX_OPC_TBLIDXB1,
263 TILEGX_OPC_TBLIDXB2,
264 TILEGX_OPC_TBLIDXB3,
265 TILEGX_OPC_V1ADD,
266 TILEGX_OPC_V1ADDI,
267 TILEGX_OPC_V1ADDUC,
268 TILEGX_OPC_V1ADIFFU,
269 TILEGX_OPC_V1AVGU,
270 TILEGX_OPC_V1CMPEQ,
271 TILEGX_OPC_V1CMPEQI,
272 TILEGX_OPC_V1CMPLES,
273 TILEGX_OPC_V1CMPLEU,
274 TILEGX_OPC_V1CMPLTS,
275 TILEGX_OPC_V1CMPLTSI,
276 TILEGX_OPC_V1CMPLTU,
277 TILEGX_OPC_V1CMPLTUI,
278 TILEGX_OPC_V1CMPNE,
279 TILEGX_OPC_V1DDOTPU,
280 TILEGX_OPC_V1DDOTPUA,
281 TILEGX_OPC_V1DDOTPUS,
282 TILEGX_OPC_V1DDOTPUSA,
283 TILEGX_OPC_V1DOTP,
284 TILEGX_OPC_V1DOTPA,
285 TILEGX_OPC_V1DOTPU,
286 TILEGX_OPC_V1DOTPUA,
287 TILEGX_OPC_V1DOTPUS,
288 TILEGX_OPC_V1DOTPUSA,
289 TILEGX_OPC_V1INT_H,
290 TILEGX_OPC_V1INT_L,
291 TILEGX_OPC_V1MAXU,
292 TILEGX_OPC_V1MAXUI,
293 TILEGX_OPC_V1MINU,
294 TILEGX_OPC_V1MINUI,
295 TILEGX_OPC_V1MNZ,
296 TILEGX_OPC_V1MULTU,
297 TILEGX_OPC_V1MULU,
298 TILEGX_OPC_V1MULUS,
299 TILEGX_OPC_V1MZ,
300 TILEGX_OPC_V1SADAU,
301 TILEGX_OPC_V1SADU,
302 TILEGX_OPC_V1SHL,
303 TILEGX_OPC_V1SHLI,
304 TILEGX_OPC_V1SHRS,
305 TILEGX_OPC_V1SHRSI,
306 TILEGX_OPC_V1SHRU,
307 TILEGX_OPC_V1SHRUI,
308 TILEGX_OPC_V1SUB,
309 TILEGX_OPC_V1SUBUC,
310 TILEGX_OPC_V2ADD,
311 TILEGX_OPC_V2ADDI,
312 TILEGX_OPC_V2ADDSC,
313 TILEGX_OPC_V2ADIFFS,
314 TILEGX_OPC_V2AVGS,
315 TILEGX_OPC_V2CMPEQ,
316 TILEGX_OPC_V2CMPEQI,
317 TILEGX_OPC_V2CMPLES,
318 TILEGX_OPC_V2CMPLEU,
319 TILEGX_OPC_V2CMPLTS,
320 TILEGX_OPC_V2CMPLTSI,
321 TILEGX_OPC_V2CMPLTU,
322 TILEGX_OPC_V2CMPLTUI,
323 TILEGX_OPC_V2CMPNE,
324 TILEGX_OPC_V2DOTP,
325 TILEGX_OPC_V2DOTPA,
326 TILEGX_OPC_V2INT_H,
327 TILEGX_OPC_V2INT_L,
328 TILEGX_OPC_V2MAXS,
329 TILEGX_OPC_V2MAXSI,
330 TILEGX_OPC_V2MINS,
331 TILEGX_OPC_V2MINSI,
332 TILEGX_OPC_V2MNZ,
333 TILEGX_OPC_V2MULFSC,
334 TILEGX_OPC_V2MULS,
335 TILEGX_OPC_V2MULTS,
336 TILEGX_OPC_V2MZ,
337 TILEGX_OPC_V2PACKH,
338 TILEGX_OPC_V2PACKL,
339 TILEGX_OPC_V2PACKUC,
340 TILEGX_OPC_V2SADAS,
341 TILEGX_OPC_V2SADAU,
342 TILEGX_OPC_V2SADS,
343 TILEGX_OPC_V2SADU,
344 TILEGX_OPC_V2SHL,
345 TILEGX_OPC_V2SHLI,
346 TILEGX_OPC_V2SHLSC,
347 TILEGX_OPC_V2SHRS,
348 TILEGX_OPC_V2SHRSI,
349 TILEGX_OPC_V2SHRU,
350 TILEGX_OPC_V2SHRUI,
351 TILEGX_OPC_V2SUB,
352 TILEGX_OPC_V2SUBSC,
353 TILEGX_OPC_V4ADD,
354 TILEGX_OPC_V4ADDSC,
355 TILEGX_OPC_V4INT_H,
356 TILEGX_OPC_V4INT_L,
357 TILEGX_OPC_V4PACKSC,
358 TILEGX_OPC_V4SHL,
359 TILEGX_OPC_V4SHLSC,
360 TILEGX_OPC_V4SHRS,
361 TILEGX_OPC_V4SHRU,
362 TILEGX_OPC_V4SUB,
363 TILEGX_OPC_V4SUBSC,
364 TILEGX_OPC_WH64,
365 TILEGX_OPC_XOR,
366 TILEGX_OPC_XORI,
367 TILEGX_OPC_NONE
368} tilegx_mnemonic;
369
370
371
372typedef enum
373{
374 TILEGX_PIPELINE_X0,
375 TILEGX_PIPELINE_X1,
376 TILEGX_PIPELINE_Y0,
377 TILEGX_PIPELINE_Y1,
378 TILEGX_PIPELINE_Y2,
379} tilegx_pipeline;
380
381#define tilegx_is_x_pipeline(p) ((int)(p) <= (int)TILEGX_PIPELINE_X1)
382
383typedef enum
384{
385 TILEGX_OP_TYPE_REGISTER,
386 TILEGX_OP_TYPE_IMMEDIATE,
387 TILEGX_OP_TYPE_ADDRESS,
388 TILEGX_OP_TYPE_SPR
389} tilegx_operand_type;
390
391struct tilegx_operand
392{
393 /* Is this operand a register, immediate or address? */
394 tilegx_operand_type type;
395
396 /* The default relocation type for this operand. */
397 signed int default_reloc : 16;
398
399 /* How many bits is this value? (used for range checking) */
400 unsigned int num_bits : 5;
401
402 /* Is the value signed? (used for range checking) */
403 unsigned int is_signed : 1;
404
405 /* Is this operand a source register? */
406 unsigned int is_src_reg : 1;
407
408 /* Is this operand written? (i.e. is it a destination register) */
409 unsigned int is_dest_reg : 1;
410
411 /* Is this operand PC-relative? */
412 unsigned int is_pc_relative : 1;
413
414 /* By how many bits do we right shift the value before inserting? */
415 unsigned int rightshift : 2;
416
417 /* Return the bits for this operand to be ORed into an existing bundle. */
418 tilegx_bundle_bits (*insert) (int op);
419
420 /* Extract this operand and return it. */
421 unsigned int (*extract) (tilegx_bundle_bits bundle);
422};
423
424
425extern const struct tilegx_operand tilegx_operands[];
426
427/* One finite-state machine per pipe for rapid instruction decoding. */
428extern const unsigned short * const
429tilegx_bundle_decoder_fsms[TILEGX_NUM_PIPELINE_ENCODINGS];
430
431
432struct tilegx_opcode
433{
434 /* The opcode mnemonic, e.g. "add" */
435 const char *name;
436
437 /* The enum value for this mnemonic. */
438 tilegx_mnemonic mnemonic;
439
440 /* A bit mask of which of the five pipes this instruction
441 is compatible with:
442 X0 0x01
443 X1 0x02
444 Y0 0x04
445 Y1 0x08
446 Y2 0x10 */
447 unsigned char pipes;
448
449 /* How many operands are there? */
450 unsigned char num_operands;
451
452 /* Which register does this write implicitly, or TREG_ZERO if none? */
453 unsigned char implicitly_written_register;
454
455 /* Can this be bundled with other instructions (almost always true). */
456 unsigned char can_bundle;
457
458 /* The description of the operands. Each of these is an
459 * index into the tilegx_operands[] table. */
460 unsigned char operands[TILEGX_NUM_PIPELINE_ENCODINGS][TILEGX_MAX_OPERANDS];
461
462};
463
464extern const struct tilegx_opcode tilegx_opcodes[];
465
466/* Used for non-textual disassembly into structs. */
467struct tilegx_decoded_instruction
468{
469 const struct tilegx_opcode *opcode;
470 const struct tilegx_operand *operands[TILEGX_MAX_OPERANDS];
471 long long operand_values[TILEGX_MAX_OPERANDS];
472};
473
474
475/* Disassemble a bundle into a struct for machine processing. */
476extern int parse_insn_tilegx(tilegx_bundle_bits bits,
477 unsigned long long pc,
478 struct tilegx_decoded_instruction
479 decoded[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE]);
480
481
482
483#endif /* opcode_tilegx_h */
diff --git a/arch/tile/include/asm/timex.h b/arch/tile/include/asm/timex.h
deleted file mode 100644
index dc987d53e2a9..000000000000
--- a/arch/tile/include/asm/timex.h
+++ /dev/null
@@ -1,52 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_TIMEX_H
16#define _ASM_TILE_TIMEX_H
17
18/*
19 * This rate should be a multiple of the possible HZ values (100, 250, 1000)
20 * and a fraction of the possible hardware timer frequencies. Our timer
21 * frequency is highly tunable but also quite precise, so for the primary use
22 * of this value (setting ACT_HZ from HZ) we just pick a value that causes
23 * ACT_HZ to be set to HZ. We make the value somewhat large just to be
24 * more robust in case someone tries out a new value of HZ.
25 */
26#define CLOCK_TICK_RATE 1000000
27
28typedef unsigned long long cycles_t;
29
30#if CHIP_HAS_SPLIT_CYCLE()
31cycles_t get_cycles(void);
32#define get_cycles_low() __insn_mfspr(SPR_CYCLE_LOW)
33#else
34static inline cycles_t get_cycles(void)
35{
36 return __insn_mfspr(SPR_CYCLE);
37}
38#define get_cycles_low() __insn_mfspr(SPR_CYCLE) /* just get all 64 bits */
39#endif
40
41cycles_t get_clock_rate(void);
42
43/* Convert nanoseconds to core clock cycles. */
44cycles_t ns2cycles(unsigned long nsecs);
45
46/* Called at cpu initialization to set some low-level constants. */
47void setup_clock(void);
48
49/* Called at cpu initialization to start the tile-timer clock device. */
50void setup_tile_timer(void);
51
52#endif /* _ASM_TILE_TIMEX_H */
diff --git a/arch/tile/include/asm/tlb.h b/arch/tile/include/asm/tlb.h
deleted file mode 100644
index 4a891a1a8df3..000000000000
--- a/arch/tile/include/asm/tlb.h
+++ /dev/null
@@ -1,25 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_TLB_H
16#define _ASM_TILE_TLB_H
17
18#define tlb_start_vma(tlb, vma) do { } while (0)
19#define tlb_end_vma(tlb, vma) do { } while (0)
20#define __tlb_remove_tlb_entry(tlb, ptep, address) do { } while (0)
21#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)
22
23#include <asm-generic/tlb.h>
24
25#endif /* _ASM_TILE_TLB_H */
diff --git a/arch/tile/include/asm/tlbflush.h b/arch/tile/include/asm/tlbflush.h
deleted file mode 100644
index dcf91b25a1e5..000000000000
--- a/arch/tile/include/asm/tlbflush.h
+++ /dev/null
@@ -1,123 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_TLBFLUSH_H
16#define _ASM_TILE_TLBFLUSH_H
17
18#include <linux/mm.h>
19#include <linux/sched.h>
20#include <linux/smp.h>
21#include <asm/cacheflush.h>
22#include <asm/page.h>
23#include <hv/hypervisor.h>
24
25/*
26 * Rather than associating each mm with its own ASID, we just use
27 * ASIDs to allow us to lazily flush the TLB when we switch mms.
28 * This way we only have to do an actual TLB flush on mm switch
29 * every time we wrap ASIDs, not every single time we switch.
30 *
31 * FIXME: We might improve performance by keeping ASIDs around
32 * properly, though since the hypervisor direct-maps VAs to TSB
33 * entries, we're likely to have lost at least the executable page
34 * mappings by the time we switch back to the original mm.
35 */
36DECLARE_PER_CPU(int, current_asid);
37
38/* The hypervisor tells us what ASIDs are available to us. */
39extern int min_asid, max_asid;
40
41/* Pass as vma pointer for non-executable mapping, if no vma available. */
42#define FLUSH_NONEXEC ((struct vm_area_struct *)-1UL)
43
44/* Flush a single user page on this cpu. */
45static inline void local_flush_tlb_page(struct vm_area_struct *vma,
46 unsigned long addr,
47 unsigned long page_size)
48{
49 int rc = hv_flush_page(addr, page_size);
50 if (rc < 0)
51 panic("hv_flush_page(%#lx,%#lx) failed: %d",
52 addr, page_size, rc);
53 if (!vma || (vma != FLUSH_NONEXEC && (vma->vm_flags & VM_EXEC)))
54 __flush_icache();
55}
56
57/* Flush range of user pages on this cpu. */
58static inline void local_flush_tlb_pages(struct vm_area_struct *vma,
59 unsigned long addr,
60 unsigned long page_size,
61 unsigned long len)
62{
63 int rc = hv_flush_pages(addr, page_size, len);
64 if (rc < 0)
65 panic("hv_flush_pages(%#lx,%#lx,%#lx) failed: %d",
66 addr, page_size, len, rc);
67 if (!vma || (vma != FLUSH_NONEXEC && (vma->vm_flags & VM_EXEC)))
68 __flush_icache();
69}
70
71/* Flush all user pages on this cpu. */
72static inline void local_flush_tlb(void)
73{
74 int rc = hv_flush_all(1); /* preserve global mappings */
75 if (rc < 0)
76 panic("hv_flush_all(1) failed: %d", rc);
77 __flush_icache();
78}
79
80/*
81 * Global pages have to be flushed a bit differently. Not a real
82 * performance problem because this does not happen often.
83 */
84static inline void local_flush_tlb_all(void)
85{
86 int i;
87 for (i = 0; ; ++i) {
88 HV_VirtAddrRange r = hv_inquire_virtual(i);
89 if (r.size == 0)
90 break;
91 local_flush_tlb_pages(NULL, r.start, PAGE_SIZE, r.size);
92 local_flush_tlb_pages(NULL, r.start, HPAGE_SIZE, r.size);
93 }
94}
95
96/*
97 * TLB flushing:
98 *
99 * - flush_tlb() flushes the current mm struct TLBs
100 * - flush_tlb_all() flushes all processes TLBs
101 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
102 * - flush_tlb_page(vma, vmaddr) flushes one page
103 * - flush_tlb_range(vma, start, end) flushes a range of pages
104 * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
105 * - flush_tlb_others(cpumask, mm, va) flushes TLBs on other cpus
106 *
107 * Here (as in vm_area_struct), "end" means the first byte after
108 * our end address.
109 */
110
111extern void flush_tlb_all(void);
112extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
113extern void flush_tlb_current_task(void);
114extern void flush_tlb_mm(struct mm_struct *);
115extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
116extern void flush_tlb_page_mm(struct vm_area_struct *,
117 struct mm_struct *, unsigned long);
118extern void flush_tlb_range(struct vm_area_struct *,
119 unsigned long start, unsigned long end);
120
121#define flush_tlb() flush_tlb_current_task()
122
123#endif /* _ASM_TILE_TLBFLUSH_H */
diff --git a/arch/tile/include/asm/topology.h b/arch/tile/include/asm/topology.h
deleted file mode 100644
index 635a0a4596f0..000000000000
--- a/arch/tile/include/asm/topology.h
+++ /dev/null
@@ -1,52 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_TOPOLOGY_H
16#define _ASM_TILE_TOPOLOGY_H
17
18#ifdef CONFIG_NUMA
19
20#include <linux/cpumask.h>
21
22/* Mappings between logical cpu number and node number. */
23extern struct cpumask node_2_cpu_mask[];
24extern char cpu_2_node[];
25
26/* Returns the number of the node containing CPU 'cpu'. */
27static inline int cpu_to_node(int cpu)
28{
29 return cpu_2_node[cpu];
30}
31
32/* Returns a bitmask of CPUs on Node 'node'. */
33static inline const struct cpumask *cpumask_of_node(int node)
34{
35 return &node_2_cpu_mask[node];
36}
37
38/* For now, use numa node -1 for global allocation. */
39#define pcibus_to_node(bus) ((void)(bus), -1)
40
41#endif /* CONFIG_NUMA */
42
43#include <asm-generic/topology.h>
44
45#ifdef CONFIG_SMP
46#define topology_physical_package_id(cpu) ((void)(cpu), 0)
47#define topology_core_id(cpu) (cpu)
48#define topology_core_cpumask(cpu) ((void)(cpu), cpu_online_mask)
49#define topology_sibling_cpumask(cpu) cpumask_of(cpu)
50#endif
51
52#endif /* _ASM_TILE_TOPOLOGY_H */
diff --git a/arch/tile/include/asm/traps.h b/arch/tile/include/asm/traps.h
deleted file mode 100644
index 11c82270c1f5..000000000000
--- a/arch/tile/include/asm/traps.h
+++ /dev/null
@@ -1,93 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_TRAPS_H
16#define _ASM_TILE_TRAPS_H
17
18#ifndef __ASSEMBLY__
19#include <arch/chip.h>
20
21/* mm/fault.c */
22void do_page_fault(struct pt_regs *, int fault_num,
23 unsigned long address, unsigned long write);
24#if CHIP_HAS_TILE_DMA()
25void do_async_page_fault(struct pt_regs *);
26#endif
27
28#ifndef __tilegx__
29/*
30 * We return this structure in registers to avoid having to write
31 * additional save/restore code in the intvec.S caller.
32 */
33struct intvec_state {
34 void *handler;
35 unsigned long vecnum;
36 unsigned long fault_num;
37 unsigned long info;
38 unsigned long retval;
39};
40struct intvec_state do_page_fault_ics(struct pt_regs *regs, int fault_num,
41 unsigned long address,
42 unsigned long info);
43#endif
44
45/* kernel/traps.c */
46void do_trap(struct pt_regs *, int fault_num, unsigned long reason);
47void kernel_double_fault(int dummy, ulong pc, ulong lr, ulong sp, ulong r52);
48
49/* kernel/time.c */
50void do_timer_interrupt(struct pt_regs *, int fault_num);
51
52/* kernel/messaging.c */
53void hv_message_intr(struct pt_regs *, int intnum);
54
55#define TILE_NMI_DUMP_STACK 1 /* Dump stack for sysrq+'l' */
56
57/* kernel/process.c */
58void do_nmi_dump_stack(struct pt_regs *regs);
59
60/* kernel/traps.c */
61void do_nmi(struct pt_regs *, int fault_num, unsigned long reason);
62
63/* kernel/irq.c */
64void tile_dev_intr(struct pt_regs *, int intnum);
65
66#ifdef CONFIG_HARDWALL
67/* kernel/hardwall.c */
68void do_hardwall_trap(struct pt_regs *, int fault_num);
69#endif
70
71/* kernel/ptrace.c */
72void do_breakpoint(struct pt_regs *, int fault_num);
73
74
75#ifdef __tilegx__
76/* kernel/single_step.c */
77void gx_singlestep_handle(struct pt_regs *, int fault_num);
78
79/* kernel/intvec_64.S */
80void fill_ra_stack(void);
81
82/* Handle unalign data fixup. */
83extern void do_unaligned(struct pt_regs *regs, int vecnum);
84#endif
85
86#endif /* __ASSEMBLY__ */
87
88#ifdef __tilegx__
89/* 128 byte JIT per unalign fixup. */
90#define UNALIGN_JIT_SHIFT 7
91#endif
92
93#endif /* _ASM_TILE_TRAPS_H */
diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
deleted file mode 100644
index cb4fbe7e4f88..000000000000
--- a/arch/tile/include/asm/uaccess.h
+++ /dev/null
@@ -1,411 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_UACCESS_H
16#define _ASM_TILE_UACCESS_H
17
18/*
19 * User space memory access functions
20 */
21#include <linux/mm.h>
22#include <asm/processor.h>
23#include <asm/page.h>
24
25/*
26 * The fs value determines whether argument validity checking should be
27 * performed or not. If get_fs() == USER_DS, checking is performed, with
28 * get_fs() == KERNEL_DS, checking is bypassed.
29 *
30 * For historical reasons, these macros are grossly misnamed.
31 */
32#define MAKE_MM_SEG(a) ((mm_segment_t) { (a) })
33
34#define KERNEL_DS MAKE_MM_SEG(-1UL)
35#define USER_DS MAKE_MM_SEG(PAGE_OFFSET)
36
37#define get_ds() (KERNEL_DS)
38#define get_fs() (current_thread_info()->addr_limit)
39#define set_fs(x) (current_thread_info()->addr_limit = (x))
40
41#define segment_eq(a, b) ((a).seg == (b).seg)
42
43#ifndef __tilegx__
44/*
45 * We could allow mapping all 16 MB at 0xfc000000, but we set up a
46 * special hack in arch_setup_additional_pages() to auto-create a mapping
47 * for the first 16 KB, and it would seem strange to have different
48 * user-accessible semantics for memory at 0xfc000000 and above 0xfc004000.
49 */
50static inline int is_arch_mappable_range(unsigned long addr,
51 unsigned long size)
52{
53 return (addr >= MEM_USER_INTRPT &&
54 addr < (MEM_USER_INTRPT + INTRPT_SIZE) &&
55 size <= (MEM_USER_INTRPT + INTRPT_SIZE) - addr);
56}
57#define is_arch_mappable_range is_arch_mappable_range
58#else
59#define is_arch_mappable_range(addr, size) 0
60#endif
61
62/*
63 * Note that using this definition ignores is_arch_mappable_range(),
64 * so on tilepro code that uses user_addr_max() is constrained not
65 * to reference the tilepro user-interrupt region.
66 */
67#define user_addr_max() (current_thread_info()->addr_limit.seg)
68
69/*
70 * Test whether a block of memory is a valid user space address.
71 * Returns 0 if the range is valid, nonzero otherwise.
72 */
73int __range_ok(unsigned long addr, unsigned long size);
74
75/**
76 * access_ok: - Checks if a user space pointer is valid
77 * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that
78 * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
79 * to write to a block, it is always safe to read from it.
80 * @addr: User space pointer to start of block to check
81 * @size: Size of block to check
82 *
83 * Context: User context only. This function may sleep if pagefaults are
84 * enabled.
85 *
86 * Checks if a pointer to a block of memory in user space is valid.
87 *
88 * Returns true (nonzero) if the memory block may be valid, false (zero)
89 * if it is definitely invalid.
90 *
91 * Note that, depending on architecture, this function probably just
92 * checks that the pointer is in the user space range - after calling
93 * this function, memory access functions may still return -EFAULT.
94 */
95#define access_ok(type, addr, size) ({ \
96 __chk_user_ptr(addr); \
97 likely(__range_ok((unsigned long)(addr), (size)) == 0); \
98})
99
100#include <asm/extable.h>
101
102/*
103 * This is a type: either unsigned long, if the argument fits into
104 * that type, or otherwise unsigned long long.
105 */
106#define __inttype(x) \
107 __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
108
109/*
110 * Support macros for __get_user().
111 * Note that __get_user() and __put_user() assume proper alignment.
112 */
113
114#ifdef __LP64__
115#define _ASM_PTR ".quad"
116#define _ASM_ALIGN ".align 8"
117#else
118#define _ASM_PTR ".long"
119#define _ASM_ALIGN ".align 4"
120#endif
121
122#define __get_user_asm(OP, x, ptr, ret) \
123 asm volatile("1: {" #OP " %1, %2; movei %0, 0 }\n" \
124 ".pushsection .fixup,\"ax\"\n" \
125 "0: { movei %1, 0; movei %0, %3 }\n" \
126 "j 9f\n" \
127 ".section __ex_table,\"a\"\n" \
128 _ASM_ALIGN "\n" \
129 _ASM_PTR " 1b, 0b\n" \
130 ".popsection\n" \
131 "9:" \
132 : "=r" (ret), "=r" (x) \
133 : "r" (ptr), "i" (-EFAULT))
134
135#ifdef __tilegx__
136#define __get_user_1(x, ptr, ret) __get_user_asm(ld1u, x, ptr, ret)
137#define __get_user_2(x, ptr, ret) __get_user_asm(ld2u, x, ptr, ret)
138#define __get_user_4(x, ptr, ret) __get_user_asm(ld4s, x, ptr, ret)
139#define __get_user_8(x, ptr, ret) __get_user_asm(ld, x, ptr, ret)
140#else
141#define __get_user_1(x, ptr, ret) __get_user_asm(lb_u, x, ptr, ret)
142#define __get_user_2(x, ptr, ret) __get_user_asm(lh_u, x, ptr, ret)
143#define __get_user_4(x, ptr, ret) __get_user_asm(lw, x, ptr, ret)
144#ifdef __LITTLE_ENDIAN
145#define __lo32(a, b) a
146#define __hi32(a, b) b
147#else
148#define __lo32(a, b) b
149#define __hi32(a, b) a
150#endif
151#define __get_user_8(x, ptr, ret) \
152 ({ \
153 unsigned int __a, __b; \
154 asm volatile("1: { lw %1, %3; addi %2, %3, 4 }\n" \
155 "2: { lw %2, %2; movei %0, 0 }\n" \
156 ".pushsection .fixup,\"ax\"\n" \
157 "0: { movei %1, 0; movei %2, 0 }\n" \
158 "{ movei %0, %4; j 9f }\n" \
159 ".section __ex_table,\"a\"\n" \
160 ".align 4\n" \
161 ".word 1b, 0b\n" \
162 ".word 2b, 0b\n" \
163 ".popsection\n" \
164 "9:" \
165 : "=r" (ret), "=r" (__a), "=&r" (__b) \
166 : "r" (ptr), "i" (-EFAULT)); \
167 (x) = (__force __typeof(x))(__inttype(x)) \
168 (((u64)__hi32(__a, __b) << 32) | \
169 __lo32(__a, __b)); \
170 })
171#endif
172
173extern int __get_user_bad(void)
174 __attribute__((warning("sizeof __get_user argument not 1, 2, 4 or 8")));
175
176/**
177 * __get_user: - Get a simple variable from user space, with less checking.
178 * @x: Variable to store result.
179 * @ptr: Source address, in user space.
180 *
181 * Context: User context only. This function may sleep if pagefaults are
182 * enabled.
183 *
184 * This macro copies a single simple variable from user space to kernel
185 * space. It supports simple types like char and int, but not larger
186 * data types like structures or arrays.
187 *
188 * @ptr must have pointer-to-simple-variable type, and the result of
189 * dereferencing @ptr must be assignable to @x without a cast.
190 *
191 * Returns zero on success, or -EFAULT on error.
192 * On error, the variable @x is set to zero.
193 *
194 * Caller must check the pointer with access_ok() before calling this
195 * function.
196 */
197#define __get_user(x, ptr) \
198 ({ \
199 int __ret; \
200 typeof(x) _x; \
201 __chk_user_ptr(ptr); \
202 switch (sizeof(*(ptr))) { \
203 case 1: __get_user_1(_x, ptr, __ret); break; \
204 case 2: __get_user_2(_x, ptr, __ret); break; \
205 case 4: __get_user_4(_x, ptr, __ret); break; \
206 case 8: __get_user_8(_x, ptr, __ret); break; \
207 default: __ret = __get_user_bad(); break; \
208 } \
209 (x) = (typeof(*(ptr))) _x; \
210 __ret; \
211 })
212
213/* Support macros for __put_user(). */
214
215#define __put_user_asm(OP, x, ptr, ret) \
216 asm volatile("1: {" #OP " %1, %2; movei %0, 0 }\n" \
217 ".pushsection .fixup,\"ax\"\n" \
218 "0: { movei %0, %3; j 9f }\n" \
219 ".section __ex_table,\"a\"\n" \
220 _ASM_ALIGN "\n" \
221 _ASM_PTR " 1b, 0b\n" \
222 ".popsection\n" \
223 "9:" \
224 : "=r" (ret) \
225 : "r" (ptr), "r" (x), "i" (-EFAULT))
226
227#ifdef __tilegx__
228#define __put_user_1(x, ptr, ret) __put_user_asm(st1, x, ptr, ret)
229#define __put_user_2(x, ptr, ret) __put_user_asm(st2, x, ptr, ret)
230#define __put_user_4(x, ptr, ret) __put_user_asm(st4, x, ptr, ret)
231#define __put_user_8(x, ptr, ret) __put_user_asm(st, x, ptr, ret)
232#else
233#define __put_user_1(x, ptr, ret) __put_user_asm(sb, x, ptr, ret)
234#define __put_user_2(x, ptr, ret) __put_user_asm(sh, x, ptr, ret)
235#define __put_user_4(x, ptr, ret) __put_user_asm(sw, x, ptr, ret)
236#define __put_user_8(x, ptr, ret) \
237 ({ \
238 u64 __x = (__force __inttype(x))(x); \
239 int __lo = (int) __x, __hi = (int) (__x >> 32); \
240 asm volatile("1: { sw %1, %2; addi %0, %1, 4 }\n" \
241 "2: { sw %0, %3; movei %0, 0 }\n" \
242 ".pushsection .fixup,\"ax\"\n" \
243 "0: { movei %0, %4; j 9f }\n" \
244 ".section __ex_table,\"a\"\n" \
245 ".align 4\n" \
246 ".word 1b, 0b\n" \
247 ".word 2b, 0b\n" \
248 ".popsection\n" \
249 "9:" \
250 : "=&r" (ret) \
251 : "r" (ptr), "r" (__lo32(__lo, __hi)), \
252 "r" (__hi32(__lo, __hi)), "i" (-EFAULT)); \
253 })
254#endif
255
256extern int __put_user_bad(void)
257 __attribute__((warning("sizeof __put_user argument not 1, 2, 4 or 8")));
258
259/**
260 * __put_user: - Write a simple value into user space, with less checking.
261 * @x: Value to copy to user space.
262 * @ptr: Destination address, in user space.
263 *
264 * Context: User context only. This function may sleep if pagefaults are
265 * enabled.
266 *
267 * This macro copies a single simple value from kernel space to user
268 * space. It supports simple types like char and int, but not larger
269 * data types like structures or arrays.
270 *
271 * @ptr must have pointer-to-simple-variable type, and @x must be assignable
272 * to the result of dereferencing @ptr.
273 *
274 * Caller must check the pointer with access_ok() before calling this
275 * function.
276 *
277 * Returns zero on success, or -EFAULT on error.
278 */
279#define __put_user(x, ptr) \
280({ \
281 int __ret; \
282 typeof(*(ptr)) _x = (x); \
283 __chk_user_ptr(ptr); \
284 switch (sizeof(*(ptr))) { \
285 case 1: __put_user_1(_x, ptr, __ret); break; \
286 case 2: __put_user_2(_x, ptr, __ret); break; \
287 case 4: __put_user_4(_x, ptr, __ret); break; \
288 case 8: __put_user_8(_x, ptr, __ret); break; \
289 default: __ret = __put_user_bad(); break; \
290 } \
291 __ret; \
292})
293
294/*
295 * The versions of get_user and put_user without initial underscores
296 * check the address of their arguments to make sure they are not
297 * in kernel space.
298 */
299#define put_user(x, ptr) \
300({ \
301 __typeof__(*(ptr)) __user *__Pu_addr = (ptr); \
302 access_ok(VERIFY_WRITE, (__Pu_addr), sizeof(*(__Pu_addr))) ? \
303 __put_user((x), (__Pu_addr)) : \
304 -EFAULT; \
305})
306
307#define get_user(x, ptr) \
308({ \
309 __typeof__(*(ptr)) const __user *__Gu_addr = (ptr); \
310 access_ok(VERIFY_READ, (__Gu_addr), sizeof(*(__Gu_addr))) ? \
311 __get_user((x), (__Gu_addr)) : \
312 ((x) = 0, -EFAULT); \
313})
314
315extern unsigned long __must_check
316raw_copy_to_user(void __user *to, const void *from, unsigned long n);
317extern unsigned long __must_check
318raw_copy_from_user(void *to, const void __user *from, unsigned long n);
319#define INLINE_COPY_FROM_USER
320#define INLINE_COPY_TO_USER
321
322#ifdef __tilegx__
323extern unsigned long raw_copy_in_user(
324 void __user *to, const void __user *from, unsigned long n);
325#endif
326
327
328extern long strnlen_user(const char __user *str, long n);
329extern long strncpy_from_user(char *dst, const char __user *src, long);
330
331/**
332 * clear_user: - Zero a block of memory in user space.
333 * @mem: Destination address, in user space.
334 * @len: Number of bytes to zero.
335 *
336 * Zero a block of memory in user space.
337 *
338 * Returns number of bytes that could not be cleared.
339 * On success, this will be zero.
340 */
341extern unsigned long clear_user_asm(void __user *mem, unsigned long len);
342static inline unsigned long __must_check __clear_user(
343 void __user *mem, unsigned long len)
344{
345 might_fault();
346 return clear_user_asm(mem, len);
347}
348static inline unsigned long __must_check clear_user(
349 void __user *mem, unsigned long len)
350{
351 if (access_ok(VERIFY_WRITE, mem, len))
352 return __clear_user(mem, len);
353 return len;
354}
355
356/**
357 * flush_user: - Flush a block of memory in user space from cache.
358 * @mem: Destination address, in user space.
359 * @len: Number of bytes to flush.
360 *
361 * Returns number of bytes that could not be flushed.
362 * On success, this will be zero.
363 */
364extern unsigned long flush_user_asm(void __user *mem, unsigned long len);
365static inline unsigned long __must_check __flush_user(
366 void __user *mem, unsigned long len)
367{
368 int retval;
369
370 might_fault();
371 retval = flush_user_asm(mem, len);
372 mb_incoherent();
373 return retval;
374}
375
376static inline unsigned long __must_check flush_user(
377 void __user *mem, unsigned long len)
378{
379 if (access_ok(VERIFY_WRITE, mem, len))
380 return __flush_user(mem, len);
381 return len;
382}
383
384/**
385 * finv_user: - Flush-inval a block of memory in user space from cache.
386 * @mem: Destination address, in user space.
387 * @len: Number of bytes to invalidate.
388 *
389 * Returns number of bytes that could not be flush-invalidated.
390 * On success, this will be zero.
391 */
392extern unsigned long finv_user_asm(void __user *mem, unsigned long len);
393static inline unsigned long __must_check __finv_user(
394 void __user *mem, unsigned long len)
395{
396 int retval;
397
398 might_fault();
399 retval = finv_user_asm(mem, len);
400 mb_incoherent();
401 return retval;
402}
403static inline unsigned long __must_check finv_user(
404 void __user *mem, unsigned long len)
405{
406 if (access_ok(VERIFY_WRITE, mem, len))
407 return __finv_user(mem, len);
408 return len;
409}
410
411#endif /* _ASM_TILE_UACCESS_H */
diff --git a/arch/tile/include/asm/unaligned.h b/arch/tile/include/asm/unaligned.h
deleted file mode 100644
index 5a58a0d11449..000000000000
--- a/arch/tile/include/asm/unaligned.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _ASM_TILE_UNALIGNED_H
16#define _ASM_TILE_UNALIGNED_H
17
18/*
19 * We could implement faster get_unaligned_[be/le]64 using the ldna
20 * instruction on tilegx; however, we need to either copy all of the
21 * other generic functions to here (which is pretty ugly) or else
22 * modify both the generic code and other arch code to allow arch
23 * specific unaligned data access functions. Given these functions
24 * are not often called, we'll stick with the generic version.
25 */
26#include <asm-generic/unaligned.h>
27
28/*
29 * Is the kernel doing fixups of unaligned accesses? If <0, no kernel
30 * intervention occurs and SIGBUS is delivered with no data address
31 * info. If 0, the kernel single-steps the instruction to discover
32 * the data address to provide with the SIGBUS. If 1, the kernel does
33 * a fixup.
34 */
35extern int unaligned_fixup;
36
37/* Is the kernel printing on each unaligned fixup? */
38extern int unaligned_printk;
39
40/* Number of unaligned fixups performed */
41extern unsigned int unaligned_fixup_count;
42
43#endif /* _ASM_TILE_UNALIGNED_H */
diff --git a/arch/tile/include/asm/unistd.h b/arch/tile/include/asm/unistd.h
deleted file mode 100644
index 940831fe9e94..000000000000
--- a/arch/tile/include/asm/unistd.h
+++ /dev/null
@@ -1,20 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14/* In compat mode, we use sys_llseek() for compat_sys_llseek(). */
15#ifdef CONFIG_COMPAT
16#define __ARCH_WANT_SYS_LLSEEK
17#endif
18#define __ARCH_WANT_SYS_NEWFSTATAT
19#define __ARCH_WANT_SYS_CLONE
20#include <uapi/asm/unistd.h>
diff --git a/arch/tile/include/asm/user.h b/arch/tile/include/asm/user.h
deleted file mode 100644
index cbc8b4d5a5ce..000000000000
--- a/arch/tile/include/asm/user.h
+++ /dev/null
@@ -1,21 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#ifndef _ASM_TILE_USER_H
17#define _ASM_TILE_USER_H
18
19/* This header is for a.out file formats, which TILE does not support. */
20
21#endif /* _ASM_TILE_USER_H */
diff --git a/arch/tile/include/asm/vdso.h b/arch/tile/include/asm/vdso.h
deleted file mode 100644
index 9b069692153f..000000000000
--- a/arch/tile/include/asm/vdso.h
+++ /dev/null
@@ -1,55 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef __TILE_VDSO_H__
16#define __TILE_VDSO_H__
17
18#include <linux/seqlock.h>
19#include <linux/types.h>
20
21/*
22 * Note about the vdso_data structure:
23 *
24 * NEVER USE THEM IN USERSPACE CODE DIRECTLY. The layout of the
25 * structure is supposed to be known only to the function in the vdso
26 * itself and may change without notice.
27 */
28
29struct vdso_data {
30 seqcount_t tz_seq; /* Timezone seqlock */
31 seqcount_t tb_seq; /* Timebase seqlock */
32 __u64 cycle_last; /* TOD clock for xtime */
33 __u64 mask; /* Cycle mask */
34 __u32 mult; /* Cycle to nanosecond multiplier */
35 __u32 shift; /* Cycle to nanosecond divisor (power of two) */
36 __u64 wall_time_sec;
37 __u64 wall_time_snsec;
38 __u64 monotonic_time_sec;
39 __u64 monotonic_time_snsec;
40 __u64 wall_time_coarse_sec;
41 __u64 wall_time_coarse_nsec;
42 __u64 monotonic_time_coarse_sec;
43 __u64 monotonic_time_coarse_nsec;
44 __u32 tz_minuteswest; /* Minutes west of Greenwich */
45 __u32 tz_dsttime; /* Type of dst correction */
46};
47
48extern struct vdso_data *vdso_data;
49
50/* __vdso_rt_sigreturn is defined with the addresses in the vdso page. */
51extern void __vdso_rt_sigreturn(void);
52
53extern int setup_vdso_pages(void);
54
55#endif /* __TILE_VDSO_H__ */
diff --git a/arch/tile/include/asm/vga.h b/arch/tile/include/asm/vga.h
deleted file mode 100644
index 7b46e754d611..000000000000
--- a/arch/tile/include/asm/vga.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Access to VGA videoram.
15 */
16
17#ifndef _ASM_TILE_VGA_H
18#define _ASM_TILE_VGA_H
19
20#include <asm/io.h>
21
22#define VT_BUF_HAVE_RW
23
24static inline void scr_writew(u16 val, volatile u16 *addr)
25{
26 __raw_writew(val, (volatile u16 __iomem *) addr);
27}
28
29static inline u16 scr_readw(volatile const u16 *addr)
30{
31 return __raw_readw((volatile const u16 __iomem *) addr);
32}
33
34#define vga_readb(a) readb((u8 __iomem *)(a))
35#define vga_writeb(v,a) writeb(v, (u8 __iomem *)(a))
36
37#define VGA_MAP_MEM(x,s) ((unsigned long) ioremap(x, s))
38
39#endif
diff --git a/arch/tile/include/asm/word-at-a-time.h b/arch/tile/include/asm/word-at-a-time.h
deleted file mode 100644
index 2f2515867760..000000000000
--- a/arch/tile/include/asm/word-at-a-time.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_WORD_AT_A_TIME_H
3#define _ASM_WORD_AT_A_TIME_H
4
5#include <asm/byteorder.h>
6
7struct word_at_a_time { /* unused */ };
8#define WORD_AT_A_TIME_CONSTANTS {}
9
10/* Generate 0x01 byte values for zero bytes using a SIMD instruction. */
11static inline unsigned long has_zero(unsigned long val, unsigned long *data,
12 const struct word_at_a_time *c)
13{
14#ifdef __tilegx__
15 unsigned long mask = __insn_v1cmpeqi(val, 0);
16#else /* tilepro */
17 unsigned long mask = __insn_seqib(val, 0);
18#endif
19 *data = mask;
20 return mask;
21}
22
23/* These operations are both nops. */
24#define prep_zero_mask(val, data, c) (data)
25#define create_zero_mask(data) (data)
26
27/* And this operation just depends on endianness. */
28static inline long find_zero(unsigned long mask)
29{
30#ifdef __BIG_ENDIAN
31 return __builtin_clzl(mask) >> 3;
32#else
33 return __builtin_ctzl(mask) >> 3;
34#endif
35}
36
37#ifdef __BIG_ENDIAN
38#define zero_bytemask(mask) (~1ul << (63 - __builtin_clzl(mask)))
39#else
40#define zero_bytemask(mask) ((2ul << __builtin_ctzl(mask)) - 1)
41#endif
42
43#endif /* _ASM_WORD_AT_A_TIME_H */
diff --git a/arch/tile/include/gxio/common.h b/arch/tile/include/gxio/common.h
deleted file mode 100644
index 724595a24d04..000000000000
--- a/arch/tile/include/gxio/common.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _GXIO_COMMON_H_
16#define _GXIO_COMMON_H_
17
18/*
19 * Routines shared between the various GXIO device components.
20 */
21
22#include <hv/iorpc.h>
23
24#include <linux/types.h>
25#include <linux/compiler.h>
26#include <linux/io.h>
27
28/* Define the standard gxio MMIO functions using kernel functions. */
29#define __gxio_mmio_read8(addr) readb(addr)
30#define __gxio_mmio_read16(addr) readw(addr)
31#define __gxio_mmio_read32(addr) readl(addr)
32#define __gxio_mmio_read64(addr) readq(addr)
33#define __gxio_mmio_write8(addr, val) writeb((val), (addr))
34#define __gxio_mmio_write16(addr, val) writew((val), (addr))
35#define __gxio_mmio_write32(addr, val) writel((val), (addr))
36#define __gxio_mmio_write64(addr, val) writeq((val), (addr))
37#define __gxio_mmio_read(addr) __gxio_mmio_read64(addr)
38#define __gxio_mmio_write(addr, val) __gxio_mmio_write64((addr), (val))
39
40#endif /* !_GXIO_COMMON_H_ */
diff --git a/arch/tile/include/gxio/dma_queue.h b/arch/tile/include/gxio/dma_queue.h
deleted file mode 100644
index c8fd47edba30..000000000000
--- a/arch/tile/include/gxio/dma_queue.h
+++ /dev/null
@@ -1,161 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _GXIO_DMA_QUEUE_H_
16#define _GXIO_DMA_QUEUE_H_
17
18/*
19 * DMA queue management APIs shared between TRIO and mPIPE.
20 */
21
22#include <gxio/common.h>
23
24/* The credit counter lives in the high 32 bits. */
25#define DMA_QUEUE_CREDIT_SHIFT 32
26
27/*
28 * State object that tracks a DMA queue's head and tail indices, as
29 * well as the number of commands posted and completed. The
30 * structure is accessed via a thread-safe, lock-free algorithm.
31 */
32typedef struct {
33 /*
34 * Address of a MPIPE_EDMA_POST_REGION_VAL_t,
35 * TRIO_PUSH_DMA_REGION_VAL_t, or TRIO_PULL_DMA_REGION_VAL_t
36 * register. These register have identical encodings and provide
37 * information about how many commands have been processed.
38 */
39 void *post_region_addr;
40
41 /*
42 * A lazily-updated count of how many edescs the hardware has
43 * completed.
44 */
45 uint64_t hw_complete_count __attribute__ ((aligned(64)));
46
47 /*
48 * High 32 bits are a count of available egress command credits,
49 * low 24 bits are the next egress "slot".
50 */
51 int64_t credits_and_next_index;
52
53} __gxio_dma_queue_t;
54
55/* Initialize a dma queue. */
56extern void __gxio_dma_queue_init(__gxio_dma_queue_t *dma_queue,
57 void *post_region_addr,
58 unsigned int num_entries);
59
60/*
61 * Update the "credits_and_next_index" and "hw_complete_count" fields
62 * based on pending hardware completions. Note that some other thread
63 * may have already done this and, importantly, may still be in the
64 * process of updating "credits_and_next_index".
65 */
66extern void __gxio_dma_queue_update_credits(__gxio_dma_queue_t *dma_queue);
67
68/* Wait for credits to become available. */
69extern int64_t __gxio_dma_queue_wait_for_credits(__gxio_dma_queue_t *dma_queue,
70 int64_t modifier);
71
72/* Reserve slots in the queue, optionally waiting for slots to become
73 * available, and optionally returning a "completion_slot" suitable for
74 * direct comparison to "hw_complete_count".
75 */
76static inline int64_t __gxio_dma_queue_reserve(__gxio_dma_queue_t *dma_queue,
77 unsigned int num, bool wait,
78 bool completion)
79{
80 uint64_t slot;
81
82 /*
83 * Try to reserve 'num' egress command slots. We do this by
84 * constructing a constant that subtracts N credits and adds N to
85 * the index, and using fetchaddgez to only apply it if the credits
86 * count doesn't go negative.
87 */
88 int64_t modifier = (((int64_t)(-num)) << DMA_QUEUE_CREDIT_SHIFT) | num;
89 int64_t old =
90 __insn_fetchaddgez(&dma_queue->credits_and_next_index,
91 modifier);
92
93 if (unlikely(old + modifier < 0)) {
94 /*
95 * We're out of credits. Try once to get more by checking for
96 * completed egress commands. If that fails, wait or fail.
97 */
98 __gxio_dma_queue_update_credits(dma_queue);
99 old = __insn_fetchaddgez(&dma_queue->credits_and_next_index,
100 modifier);
101 if (old + modifier < 0) {
102 if (wait)
103 old = __gxio_dma_queue_wait_for_credits
104 (dma_queue, modifier);
105 else
106 return GXIO_ERR_DMA_CREDITS;
107 }
108 }
109
110 /* The bottom 24 bits of old encode the "slot". */
111 slot = (old & 0xffffff);
112
113 if (completion) {
114 /*
115 * A "completion_slot" is a "slot" which can be compared to
116 * "hw_complete_count" at any time in the future. To convert
117 * "slot" into a "completion_slot", we access "hw_complete_count"
118 * once (knowing that we have reserved a slot, and thus, it will
119 * be "basically" accurate), and combine its high 40 bits with
120 * the 24 bit "slot", and handle "wrapping" by adding "1 << 24"
121 * if the result is LESS than "hw_complete_count".
122 */
123 uint64_t complete;
124 complete = READ_ONCE(dma_queue->hw_complete_count);
125 slot |= (complete & 0xffffffffff000000);
126 if (slot < complete)
127 slot += 0x1000000;
128 }
129
130 /*
131 * If any of our slots mod 256 were equivalent to 0, go ahead and
132 * collect some egress credits, and update "hw_complete_count", and
133 * make sure the index doesn't overflow into the credits.
134 */
135 if (unlikely(((old + num) & 0xff) < num)) {
136 __gxio_dma_queue_update_credits(dma_queue);
137
138 /* Make sure the index doesn't overflow into the credits. */
139#ifdef __BIG_ENDIAN__
140 *(((uint8_t *)&dma_queue->credits_and_next_index) + 4) = 0;
141#else
142 *(((uint8_t *)&dma_queue->credits_and_next_index) + 3) = 0;
143#endif
144 }
145
146 return slot;
147}
148
149/* Non-inlinable "__gxio_dma_queue_reserve(..., true)". */
150extern int64_t __gxio_dma_queue_reserve_aux(__gxio_dma_queue_t *dma_queue,
151 unsigned int num, int wait);
152
153/* Check whether a particular "completion slot" has completed.
154 *
155 * Note that this function requires a "completion slot", and thus
156 * cannot be used with the result of any "reserve_fast" function.
157 */
158extern int __gxio_dma_queue_is_complete(__gxio_dma_queue_t *dma_queue,
159 int64_t completion_slot, int update);
160
161#endif /* !_GXIO_DMA_QUEUE_H_ */
diff --git a/arch/tile/include/gxio/iorpc_globals.h b/arch/tile/include/gxio/iorpc_globals.h
deleted file mode 100644
index 52c721f8dad9..000000000000
--- a/arch/tile/include/gxio/iorpc_globals.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#ifndef __IORPC_LINUX_RPC_H__
17#define __IORPC_LINUX_RPC_H__
18
19#include <hv/iorpc.h>
20
21#include <linux/string.h>
22#include <linux/module.h>
23#include <asm/pgtable.h>
24
25#define IORPC_OP_ARM_POLLFD IORPC_OPCODE(IORPC_FORMAT_KERNEL_POLLFD, 0x9000)
26#define IORPC_OP_CLOSE_POLLFD IORPC_OPCODE(IORPC_FORMAT_KERNEL_POLLFD, 0x9001)
27#define IORPC_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000)
28#define IORPC_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001)
29
30int __iorpc_arm_pollfd(int fd, int pollfd_cookie);
31
32int __iorpc_close_pollfd(int fd, int pollfd_cookie);
33
34int __iorpc_get_mmio_base(int fd, HV_PTE *base);
35
36int __iorpc_check_mmio_offset(int fd, unsigned long offset, unsigned long size);
37
38#endif /* !__IORPC_LINUX_RPC_H__ */
diff --git a/arch/tile/include/gxio/iorpc_mpipe.h b/arch/tile/include/gxio/iorpc_mpipe.h
deleted file mode 100644
index 4cda03de734f..000000000000
--- a/arch/tile/include/gxio/iorpc_mpipe.h
+++ /dev/null
@@ -1,144 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#ifndef __GXIO_MPIPE_LINUX_RPC_H__
17#define __GXIO_MPIPE_LINUX_RPC_H__
18
19#include <hv/iorpc.h>
20
21#include <hv/drv_mpipe_intf.h>
22#include <asm/page.h>
23#include <gxio/kiorpc.h>
24#include <gxio/mpipe.h>
25#include <linux/string.h>
26#include <linux/module.h>
27#include <asm/pgtable.h>
28
29#define GXIO_MPIPE_OP_ALLOC_BUFFER_STACKS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1200)
30#define GXIO_MPIPE_OP_INIT_BUFFER_STACK_AUX IORPC_OPCODE(IORPC_FORMAT_KERNEL_MEM, 0x1201)
31
32#define GXIO_MPIPE_OP_ALLOC_NOTIF_RINGS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1203)
33#define GXIO_MPIPE_OP_INIT_NOTIF_RING_AUX IORPC_OPCODE(IORPC_FORMAT_KERNEL_MEM, 0x1204)
34#define GXIO_MPIPE_OP_REQUEST_NOTIF_RING_INTERRUPT IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x1205)
35#define GXIO_MPIPE_OP_ENABLE_NOTIF_RING_INTERRUPT IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1206)
36#define GXIO_MPIPE_OP_ALLOC_NOTIF_GROUPS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1207)
37#define GXIO_MPIPE_OP_INIT_NOTIF_GROUP IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1208)
38#define GXIO_MPIPE_OP_ALLOC_BUCKETS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1209)
39#define GXIO_MPIPE_OP_INIT_BUCKET IORPC_OPCODE(IORPC_FORMAT_NONE, 0x120a)
40#define GXIO_MPIPE_OP_ALLOC_EDMA_RINGS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x120b)
41#define GXIO_MPIPE_OP_INIT_EDMA_RING_AUX IORPC_OPCODE(IORPC_FORMAT_KERNEL_MEM, 0x120c)
42
43#define GXIO_MPIPE_OP_COMMIT_RULES IORPC_OPCODE(IORPC_FORMAT_NONE, 0x120f)
44#define GXIO_MPIPE_OP_REGISTER_CLIENT_MEMORY IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1210)
45#define GXIO_MPIPE_OP_LINK_OPEN_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1211)
46#define GXIO_MPIPE_OP_LINK_CLOSE_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1212)
47#define GXIO_MPIPE_OP_LINK_SET_ATTR_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1213)
48
49#define GXIO_MPIPE_OP_GET_TIMESTAMP_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x121e)
50#define GXIO_MPIPE_OP_SET_TIMESTAMP_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x121f)
51#define GXIO_MPIPE_OP_ADJUST_TIMESTAMP_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1220)
52#define GXIO_MPIPE_OP_CONFIG_EDMA_RING_BLKS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1221)
53#define GXIO_MPIPE_OP_ADJUST_TIMESTAMP_FREQ IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1222)
54#define GXIO_MPIPE_OP_ARM_POLLFD IORPC_OPCODE(IORPC_FORMAT_KERNEL_POLLFD, 0x9000)
55#define GXIO_MPIPE_OP_CLOSE_POLLFD IORPC_OPCODE(IORPC_FORMAT_KERNEL_POLLFD, 0x9001)
56#define GXIO_MPIPE_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000)
57#define GXIO_MPIPE_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001)
58
59int gxio_mpipe_alloc_buffer_stacks(gxio_mpipe_context_t *context,
60 unsigned int count, unsigned int first,
61 unsigned int flags);
62
63int gxio_mpipe_init_buffer_stack_aux(gxio_mpipe_context_t *context,
64 void *mem_va, size_t mem_size,
65 unsigned int mem_flags, unsigned int stack,
66 unsigned int buffer_size_enum);
67
68
69int gxio_mpipe_alloc_notif_rings(gxio_mpipe_context_t *context,
70 unsigned int count, unsigned int first,
71 unsigned int flags);
72
73int gxio_mpipe_init_notif_ring_aux(gxio_mpipe_context_t *context, void *mem_va,
74 size_t mem_size, unsigned int mem_flags,
75 unsigned int ring);
76
77int gxio_mpipe_request_notif_ring_interrupt(gxio_mpipe_context_t *context,
78 int inter_x, int inter_y,
79 int inter_ipi, int inter_event,
80 unsigned int ring);
81
82int gxio_mpipe_enable_notif_ring_interrupt(gxio_mpipe_context_t *context,
83 unsigned int ring);
84
85int gxio_mpipe_alloc_notif_groups(gxio_mpipe_context_t *context,
86 unsigned int count, unsigned int first,
87 unsigned int flags);
88
89int gxio_mpipe_init_notif_group(gxio_mpipe_context_t *context,
90 unsigned int group,
91 gxio_mpipe_notif_group_bits_t bits);
92
93int gxio_mpipe_alloc_buckets(gxio_mpipe_context_t *context, unsigned int count,
94 unsigned int first, unsigned int flags);
95
96int gxio_mpipe_init_bucket(gxio_mpipe_context_t *context, unsigned int bucket,
97 MPIPE_LBL_INIT_DAT_BSTS_TBL_t bucket_info);
98
99int gxio_mpipe_alloc_edma_rings(gxio_mpipe_context_t *context,
100 unsigned int count, unsigned int first,
101 unsigned int flags);
102
103int gxio_mpipe_init_edma_ring_aux(gxio_mpipe_context_t *context, void *mem_va,
104 size_t mem_size, unsigned int mem_flags,
105 unsigned int ring, unsigned int channel);
106
107
108int gxio_mpipe_commit_rules(gxio_mpipe_context_t *context, const void *blob,
109 size_t blob_size);
110
111int gxio_mpipe_register_client_memory(gxio_mpipe_context_t *context,
112 unsigned int iotlb, HV_PTE pte,
113 unsigned int flags);
114
115int gxio_mpipe_link_open_aux(gxio_mpipe_context_t *context,
116 _gxio_mpipe_link_name_t name, unsigned int flags);
117
118int gxio_mpipe_link_close_aux(gxio_mpipe_context_t *context, int mac);
119
120int gxio_mpipe_link_set_attr_aux(gxio_mpipe_context_t *context, int mac,
121 uint32_t attr, int64_t val);
122
123int gxio_mpipe_get_timestamp_aux(gxio_mpipe_context_t *context, uint64_t *sec,
124 uint64_t *nsec, uint64_t *cycles);
125
126int gxio_mpipe_set_timestamp_aux(gxio_mpipe_context_t *context, uint64_t sec,
127 uint64_t nsec, uint64_t cycles);
128
129int gxio_mpipe_adjust_timestamp_aux(gxio_mpipe_context_t *context,
130 int64_t nsec);
131
132int gxio_mpipe_adjust_timestamp_freq(gxio_mpipe_context_t *context,
133 int32_t ppb);
134
135int gxio_mpipe_arm_pollfd(gxio_mpipe_context_t *context, int pollfd_cookie);
136
137int gxio_mpipe_close_pollfd(gxio_mpipe_context_t *context, int pollfd_cookie);
138
139int gxio_mpipe_get_mmio_base(gxio_mpipe_context_t *context, HV_PTE *base);
140
141int gxio_mpipe_check_mmio_offset(gxio_mpipe_context_t *context,
142 unsigned long offset, unsigned long size);
143
144#endif /* !__GXIO_MPIPE_LINUX_RPC_H__ */
diff --git a/arch/tile/include/gxio/iorpc_mpipe_info.h b/arch/tile/include/gxio/iorpc_mpipe_info.h
deleted file mode 100644
index f0b04284468b..000000000000
--- a/arch/tile/include/gxio/iorpc_mpipe_info.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#ifndef __GXIO_MPIPE_INFO_LINUX_RPC_H__
17#define __GXIO_MPIPE_INFO_LINUX_RPC_H__
18
19#include <hv/iorpc.h>
20
21#include <hv/drv_mpipe_intf.h>
22#include <asm/page.h>
23#include <gxio/kiorpc.h>
24#include <gxio/mpipe.h>
25#include <linux/string.h>
26#include <linux/module.h>
27#include <asm/pgtable.h>
28
29
30#define GXIO_MPIPE_INFO_OP_INSTANCE_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1250)
31#define GXIO_MPIPE_INFO_OP_ENUMERATE_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1251)
32#define GXIO_MPIPE_INFO_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000)
33#define GXIO_MPIPE_INFO_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001)
34
35
36int gxio_mpipe_info_instance_aux(gxio_mpipe_info_context_t *context,
37 _gxio_mpipe_link_name_t name);
38
39int gxio_mpipe_info_enumerate_aux(gxio_mpipe_info_context_t *context,
40 unsigned int idx,
41 _gxio_mpipe_link_name_t *name,
42 _gxio_mpipe_link_mac_t *mac);
43
44int gxio_mpipe_info_get_mmio_base(gxio_mpipe_info_context_t *context,
45 HV_PTE *base);
46
47int gxio_mpipe_info_check_mmio_offset(gxio_mpipe_info_context_t *context,
48 unsigned long offset, unsigned long size);
49
50#endif /* !__GXIO_MPIPE_INFO_LINUX_RPC_H__ */
diff --git a/arch/tile/include/gxio/iorpc_trio.h b/arch/tile/include/gxio/iorpc_trio.h
deleted file mode 100644
index 376a4f771167..000000000000
--- a/arch/tile/include/gxio/iorpc_trio.h
+++ /dev/null
@@ -1,104 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#ifndef __GXIO_TRIO_LINUX_RPC_H__
17#define __GXIO_TRIO_LINUX_RPC_H__
18
19#include <hv/iorpc.h>
20
21#include <hv/drv_trio_intf.h>
22#include <gxio/trio.h>
23#include <gxio/kiorpc.h>
24#include <linux/string.h>
25#include <linux/module.h>
26#include <asm/pgtable.h>
27
28#define GXIO_TRIO_OP_DEALLOC_ASID IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1400)
29#define GXIO_TRIO_OP_ALLOC_ASIDS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1401)
30
31#define GXIO_TRIO_OP_ALLOC_MEMORY_MAPS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1404)
32
33#define GXIO_TRIO_OP_ALLOC_SCATTER_QUEUES IORPC_OPCODE(IORPC_FORMAT_NONE, 0x140e)
34#define GXIO_TRIO_OP_ALLOC_PIO_REGIONS IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1412)
35
36#define GXIO_TRIO_OP_INIT_PIO_REGION_AUX IORPC_OPCODE(IORPC_FORMAT_NONE, 0x1414)
37
38#define GXIO_TRIO_OP_INIT_MEMORY_MAP_MMU_AUX IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x141e)
39#define GXIO_TRIO_OP_GET_PORT_PROPERTY IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x141f)
40#define GXIO_TRIO_OP_CONFIG_LEGACY_INTR IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x1420)
41#define GXIO_TRIO_OP_CONFIG_MSI_INTR IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x1421)
42
43#define GXIO_TRIO_OP_SET_MPS_MRS IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1423)
44#define GXIO_TRIO_OP_FORCE_RC_LINK_UP IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1424)
45#define GXIO_TRIO_OP_FORCE_EP_LINK_UP IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1425)
46#define GXIO_TRIO_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000)
47#define GXIO_TRIO_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001)
48
49int gxio_trio_alloc_asids(gxio_trio_context_t *context, unsigned int count,
50 unsigned int first, unsigned int flags);
51
52
53int gxio_trio_alloc_memory_maps(gxio_trio_context_t *context,
54 unsigned int count, unsigned int first,
55 unsigned int flags);
56
57
58int gxio_trio_alloc_scatter_queues(gxio_trio_context_t *context,
59 unsigned int count, unsigned int first,
60 unsigned int flags);
61
62int gxio_trio_alloc_pio_regions(gxio_trio_context_t *context,
63 unsigned int count, unsigned int first,
64 unsigned int flags);
65
66int gxio_trio_init_pio_region_aux(gxio_trio_context_t *context,
67 unsigned int pio_region, unsigned int mac,
68 uint32_t bus_address_hi, unsigned int flags);
69
70
71int gxio_trio_init_memory_map_mmu_aux(gxio_trio_context_t *context,
72 unsigned int map, unsigned long va,
73 uint64_t size, unsigned int asid,
74 unsigned int mac, uint64_t bus_address,
75 unsigned int node,
76 unsigned int order_mode);
77
78int gxio_trio_get_port_property(gxio_trio_context_t *context,
79 struct pcie_trio_ports_property *trio_ports);
80
81int gxio_trio_config_legacy_intr(gxio_trio_context_t *context, int inter_x,
82 int inter_y, int inter_ipi, int inter_event,
83 unsigned int mac, unsigned int intx);
84
85int gxio_trio_config_msi_intr(gxio_trio_context_t *context, int inter_x,
86 int inter_y, int inter_ipi, int inter_event,
87 unsigned int mac, unsigned int mem_map,
88 uint64_t mem_map_base, uint64_t mem_map_limit,
89 unsigned int asid);
90
91
92int gxio_trio_set_mps_mrs(gxio_trio_context_t *context, uint16_t mps,
93 uint16_t mrs, unsigned int mac);
94
95int gxio_trio_force_rc_link_up(gxio_trio_context_t *context, unsigned int mac);
96
97int gxio_trio_force_ep_link_up(gxio_trio_context_t *context, unsigned int mac);
98
99int gxio_trio_get_mmio_base(gxio_trio_context_t *context, HV_PTE *base);
100
101int gxio_trio_check_mmio_offset(gxio_trio_context_t *context,
102 unsigned long offset, unsigned long size);
103
104#endif /* !__GXIO_TRIO_LINUX_RPC_H__ */
diff --git a/arch/tile/include/gxio/iorpc_uart.h b/arch/tile/include/gxio/iorpc_uart.h
deleted file mode 100644
index 55429d48ea56..000000000000
--- a/arch/tile/include/gxio/iorpc_uart.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#ifndef __GXIO_UART_LINUX_RPC_H__
17#define __GXIO_UART_LINUX_RPC_H__
18
19#include <hv/iorpc.h>
20
21#include <hv/drv_uart_intf.h>
22#include <gxio/uart.h>
23#include <gxio/kiorpc.h>
24#include <linux/string.h>
25#include <linux/module.h>
26#include <asm/pgtable.h>
27
28#define GXIO_UART_OP_CFG_INTERRUPT IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x1900)
29#define GXIO_UART_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000)
30#define GXIO_UART_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001)
31
32int gxio_uart_cfg_interrupt(gxio_uart_context_t *context, int inter_x,
33 int inter_y, int inter_ipi, int inter_event);
34
35int gxio_uart_get_mmio_base(gxio_uart_context_t *context, HV_PTE *base);
36
37int gxio_uart_check_mmio_offset(gxio_uart_context_t *context,
38 unsigned long offset, unsigned long size);
39
40#endif /* !__GXIO_UART_LINUX_RPC_H__ */
diff --git a/arch/tile/include/gxio/iorpc_usb_host.h b/arch/tile/include/gxio/iorpc_usb_host.h
deleted file mode 100644
index 79962a97de8e..000000000000
--- a/arch/tile/include/gxio/iorpc_usb_host.h
+++ /dev/null
@@ -1,46 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* This file is machine-generated; DO NOT EDIT! */
16#ifndef __GXIO_USB_HOST_LINUX_RPC_H__
17#define __GXIO_USB_HOST_LINUX_RPC_H__
18
19#include <hv/iorpc.h>
20
21#include <hv/drv_usb_host_intf.h>
22#include <asm/page.h>
23#include <gxio/kiorpc.h>
24#include <gxio/usb_host.h>
25#include <linux/string.h>
26#include <linux/module.h>
27#include <asm/pgtable.h>
28
29#define GXIO_USB_HOST_OP_CFG_INTERRUPT IORPC_OPCODE(IORPC_FORMAT_KERNEL_INTERRUPT, 0x1800)
30#define GXIO_USB_HOST_OP_REGISTER_CLIENT_MEMORY IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x1801)
31#define GXIO_USB_HOST_OP_GET_MMIO_BASE IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8000)
32#define GXIO_USB_HOST_OP_CHECK_MMIO_OFFSET IORPC_OPCODE(IORPC_FORMAT_NONE_NOUSER, 0x8001)
33
34int gxio_usb_host_cfg_interrupt(gxio_usb_host_context_t *context, int inter_x,
35 int inter_y, int inter_ipi, int inter_event);
36
37int gxio_usb_host_register_client_memory(gxio_usb_host_context_t *context,
38 HV_PTE pte, unsigned int flags);
39
40int gxio_usb_host_get_mmio_base(gxio_usb_host_context_t *context,
41 HV_PTE *base);
42
43int gxio_usb_host_check_mmio_offset(gxio_usb_host_context_t *context,
44 unsigned long offset, unsigned long size);
45
46#endif /* !__GXIO_USB_HOST_LINUX_RPC_H__ */
diff --git a/arch/tile/include/gxio/kiorpc.h b/arch/tile/include/gxio/kiorpc.h
deleted file mode 100644
index ee5820979ff3..000000000000
--- a/arch/tile/include/gxio/kiorpc.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Support routines for kernel IORPC drivers.
15 */
16
17#ifndef _GXIO_KIORPC_H
18#define _GXIO_KIORPC_H
19
20#include <linux/types.h>
21#include <asm/page.h>
22#include <arch/chip.h>
23
24#if CHIP_HAS_MMIO()
25void __iomem *iorpc_ioremap(int hv_fd, resource_size_t offset,
26 unsigned long size);
27#endif
28
29#endif /* _GXIO_KIORPC_H */
diff --git a/arch/tile/include/gxio/mpipe.h b/arch/tile/include/gxio/mpipe.h
deleted file mode 100644
index 73e83a187866..000000000000
--- a/arch/tile/include/gxio/mpipe.h
+++ /dev/null
@@ -1,1871 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _GXIO_MPIPE_H_
16#define _GXIO_MPIPE_H_
17
18/*
19 *
20 * An API for allocating, configuring, and manipulating mPIPE hardware
21 * resources.
22 */
23
24#include <gxio/common.h>
25#include <gxio/dma_queue.h>
26
27#include <linux/time.h>
28
29#include <arch/mpipe_def.h>
30#include <arch/mpipe_shm.h>
31
32#include <hv/drv_mpipe_intf.h>
33#include <hv/iorpc.h>
34
35/*
36 *
37 * The TILE-Gx mPIPE&tm; shim provides Ethernet connectivity, packet
38 * classification, and packet load balancing services. The
39 * gxio_mpipe_ API, declared in <gxio/mpipe.h>, allows applications to
40 * allocate mPIPE IO channels, configure packet distribution
41 * parameters, and send and receive Ethernet packets. The API is
42 * designed to be a minimal wrapper around the mPIPE hardware, making
43 * system calls only where necessary to preserve inter-process
44 * protection guarantees.
45 *
46 * The APIs described below allow the programmer to allocate and
47 * configure mPIPE resources. As described below, the mPIPE is a
48 * single shared hardware device that provides partitionable resources
49 * that are shared between all applications in the system. The
50 * gxio_mpipe_ API allows userspace code to make resource request
51 * calls to the hypervisor, which in turns keeps track of the
52 * resources in use by all applications, maintains protection
53 * guarantees, and resets resources upon application shutdown.
54 *
55 * We strongly recommend reading the mPIPE section of the IO Device
56 * Guide (UG404) before working with this API. Most functions in the
57 * gxio_mpipe_ API are directly analogous to hardware interfaces and
58 * the documentation assumes that the reader understands those
59 * hardware interfaces.
60 *
61 * @section mpipe__ingress mPIPE Ingress Hardware Resources
62 *
63 * The mPIPE ingress hardware provides extensive hardware offload for
64 * tasks like packet header parsing, load balancing, and memory
65 * management. This section provides a brief introduction to the
66 * hardware components and the gxio_mpipe_ calls used to manage them;
67 * see the IO Device Guide for a much more detailed description of the
68 * mPIPE's capabilities.
69 *
70 * When a packet arrives at one of the mPIPE's Ethernet MACs, it is
71 * assigned a channel number indicating which MAC received it. It
72 * then proceeds through the following hardware pipeline:
73 *
74 * @subsection mpipe__classification Classification
75 *
76 * A set of classification processors run header parsing code on each
77 * incoming packet, extracting information including the destination
78 * MAC address, VLAN, Ethernet type, and five-tuple hash. Some of
79 * this information is then used to choose which buffer stack will be
80 * used to hold the packet, and which bucket will be used by the load
81 * balancer to determine which application will receive the packet.
82 *
83 * The rules by which the buffer stack and bucket are chosen can be
84 * configured via the @ref gxio_mpipe_classifier API. A given app can
85 * specify multiple rules, each one specifying a bucket range, and a
86 * set of buffer stacks, to be used for packets matching the rule.
87 * Each rule can optionally specify a restricted set of channels,
88 * VLANs, and/or dMACs, in which it is interested. By default, a
89 * given rule starts out matching all channels associated with the
90 * mPIPE context's set of open links; all VLANs; and all dMACs.
91 * Subsequent restrictions can then be added.
92 *
93 * @subsection mpipe__load_balancing Load Balancing
94 *
95 * The mPIPE load balancer is responsible for choosing the NotifRing
96 * to which the packet will be delivered. This decision is based on
97 * the bucket number indicated by the classification program. In
98 * general, the bucket number is based on some number of low bits of
99 * the packet's flow hash (applications that aren't interested in flow
100 * hashing use a single bucket). Each load balancer bucket keeps a
101 * record of the NotifRing to which packets directed to that bucket
102 * are currently being delivered. Based on the bucket's load
103 * balancing mode (@ref gxio_mpipe_bucket_mode_t), the load balancer
104 * either forwards the packet to the previously assigned NotifRing or
105 * decides to choose a new NotifRing. If a new NotifRing is required,
106 * the load balancer chooses the least loaded ring in the NotifGroup
107 * associated with the bucket.
108 *
109 * The load balancer is a shared resource. Each application needs to
110 * explicitly allocate NotifRings, NotifGroups, and buckets, using
111 * gxio_mpipe_alloc_notif_rings(), gxio_mpipe_alloc_notif_groups(),
112 * and gxio_mpipe_alloc_buckets(). Then the application needs to
113 * configure them using gxio_mpipe_init_notif_ring() and
114 * gxio_mpipe_init_notif_group_and_buckets().
115 *
116 * @subsection mpipe__buffers Buffer Selection and Packet Delivery
117 *
118 * Once the load balancer has chosen the destination NotifRing, the
119 * mPIPE DMA engine pops at least one buffer off of the 'buffer stack'
120 * chosen by the classification program and DMAs the packet data into
121 * that buffer. Each buffer stack provides a hardware-accelerated
122 * stack of data buffers with the same size. If the packet data is
123 * larger than the buffers provided by the chosen buffer stack, the
124 * mPIPE hardware pops off multiple buffers and chains the packet data
125 * through a multi-buffer linked list. Once the packet data is
126 * delivered to the buffer(s), the mPIPE hardware writes the
127 * ::gxio_mpipe_idesc_t metadata object (calculated by the classifier)
128 * into the NotifRing and increments the number of packets delivered
129 * to that ring.
130 *
131 * Applications can push buffers onto a buffer stack by calling
132 * gxio_mpipe_push_buffer() or by egressing a packet with the
133 * ::gxio_mpipe_edesc_t::hwb bit set, indicating that the egressed
134 * buffers should be returned to the stack.
135 *
136 * Applications can allocate and initialize buffer stacks with the
137 * gxio_mpipe_alloc_buffer_stacks() and gxio_mpipe_init_buffer_stack()
138 * APIs.
139 *
140 * The application must also register the memory pages that will hold
141 * packets. This requires calling gxio_mpipe_register_page() for each
142 * memory page that will hold packets allocated by the application for
143 * a given buffer stack. Since each buffer stack is limited to 16
144 * registered pages, it may be necessary to use huge pages, or even
145 * extremely huge pages, to hold all the buffers.
146 *
147 * @subsection mpipe__iqueue NotifRings
148 *
149 * Each NotifRing is a region of shared memory, allocated by the
150 * application, to which the mPIPE delivers packet descriptors
151 * (::gxio_mpipe_idesc_t). The application can allocate them via
152 * gxio_mpipe_alloc_notif_rings(). The application can then either
153 * explicitly initialize them with gxio_mpipe_init_notif_ring() and
154 * then read from them manually, or can make use of the convenience
155 * wrappers provided by @ref gxio_mpipe_wrappers.
156 *
157 * @section mpipe__egress mPIPE Egress Hardware
158 *
159 * Applications use eDMA rings to queue packets for egress. The
160 * application can allocate them via gxio_mpipe_alloc_edma_rings().
161 * The application can then either explicitly initialize them with
162 * gxio_mpipe_init_edma_ring() and then write to them manually, or
163 * can make use of the convenience wrappers provided by
164 * @ref gxio_mpipe_wrappers.
165 *
166 * @section gxio__shortcomings Plans for Future API Revisions
167 *
168 * The API defined here is only an initial version of the mPIPE API.
169 * Future plans include:
170 *
171 * - Higher level wrapper functions to provide common initialization
172 * patterns. This should help users start writing mPIPE programs
173 * without having to learn the details of the hardware.
174 *
175 * - Support for reset and deallocation of resources, including
176 * cleanup upon application shutdown.
177 *
178 * - Support for calling these APIs in the BME.
179 *
180 * - Support for IO interrupts.
181 *
182 * - Clearer definitions of thread safety guarantees.
183 *
184 * @section gxio__mpipe_examples Examples
185 *
186 * See the following mPIPE example programs for more information about
187 * allocating mPIPE resources and using them in real applications:
188 *
189 * - @ref mpipe/ingress/app.c : Receiving packets.
190 *
191 * - @ref mpipe/forward/app.c : Forwarding packets.
192 *
193 * Note that there are several more examples.
194 */
195
196/* Flags that can be passed to resource allocation functions. */
197enum gxio_mpipe_alloc_flags_e {
198 /* Require an allocation to start at a specified resource index. */
199 GXIO_MPIPE_ALLOC_FIXED = HV_MPIPE_ALLOC_FIXED,
200};
201
202/* Flags that can be passed to memory registration functions. */
203enum gxio_mpipe_mem_flags_e {
204 /* Do not fill L3 when writing, and invalidate lines upon egress. */
205 GXIO_MPIPE_MEM_FLAG_NT_HINT = IORPC_MEM_BUFFER_FLAG_NT_HINT,
206
207 /* L3 cache fills should only populate IO cache ways. */
208 GXIO_MPIPE_MEM_FLAG_IO_PIN = IORPC_MEM_BUFFER_FLAG_IO_PIN,
209};
210
211/* An ingress packet descriptor. When a packet arrives, the mPIPE
212 * hardware generates this structure and writes it into a NotifRing.
213 */
214typedef MPIPE_PDESC_t gxio_mpipe_idesc_t;
215
216/* An egress command descriptor. Applications write this structure
217 * into eDMA rings and the hardware performs the indicated operation
218 * (normally involving egressing some bytes). Note that egressing a
219 * single packet may involve multiple egress command descriptors.
220 */
221typedef MPIPE_EDMA_DESC_t gxio_mpipe_edesc_t;
222
223/*
224 * Max # of mpipe instances. 2 currently.
225 */
226#define GXIO_MPIPE_INSTANCE_MAX HV_MPIPE_INSTANCE_MAX
227
228#define NR_MPIPE_MAX GXIO_MPIPE_INSTANCE_MAX
229
230/* Get the "va" field from an "idesc".
231 *
232 * This is the address at which the ingress hardware copied the first
233 * byte of the packet.
234 *
235 * If the classifier detected a custom header, then this will point to
236 * the custom header, and gxio_mpipe_idesc_get_l2_start() will point
237 * to the actual L2 header.
238 *
239 * Note that this value may be misleading if "idesc->be" is set.
240 *
241 * @param idesc An ingress packet descriptor.
242 */
243static inline unsigned char *gxio_mpipe_idesc_get_va(gxio_mpipe_idesc_t *idesc)
244{
245 return (unsigned char *)(long)idesc->va;
246}
247
248/* Get the "xfer_size" from an "idesc".
249 *
250 * This is the actual number of packet bytes transferred into memory
251 * by the hardware.
252 *
253 * Note that this value may be misleading if "idesc->be" is set.
254 *
255 * @param idesc An ingress packet descriptor.
256 *
257 * ISSUE: Is this the best name for this?
258 * FIXME: Add more docs about chaining, clipping, etc.
259 */
260static inline unsigned int gxio_mpipe_idesc_get_xfer_size(gxio_mpipe_idesc_t
261 *idesc)
262{
263 return idesc->l2_size;
264}
265
266/* Get the "l2_offset" from an "idesc".
267 *
268 * Extremely customized classifiers might not support this function.
269 *
270 * This is the number of bytes between the "va" and the L2 header.
271 *
272 * The L2 header consists of a destination mac address, a source mac
273 * address, and an initial ethertype. Various initial ethertypes
274 * allow encoding extra information in the L2 header, often including
275 * a vlan, and/or a new ethertype.
276 *
277 * Note that the "l2_offset" will be non-zero if (and only if) the
278 * classifier processed a custom header for the packet.
279 *
280 * @param idesc An ingress packet descriptor.
281 */
282static inline uint8_t gxio_mpipe_idesc_get_l2_offset(gxio_mpipe_idesc_t *idesc)
283{
284 return (idesc->custom1 >> 32) & 0xFF;
285}
286
287/* Get the "l2_start" from an "idesc".
288 *
289 * This is simply gxio_mpipe_idesc_get_va() plus
290 * gxio_mpipe_idesc_get_l2_offset().
291 *
292 * @param idesc An ingress packet descriptor.
293 */
294static inline unsigned char *gxio_mpipe_idesc_get_l2_start(gxio_mpipe_idesc_t
295 *idesc)
296{
297 unsigned char *va = gxio_mpipe_idesc_get_va(idesc);
298 return va + gxio_mpipe_idesc_get_l2_offset(idesc);
299}
300
301/* Get the "l2_length" from an "idesc".
302 *
303 * This is simply gxio_mpipe_idesc_get_xfer_size() minus
304 * gxio_mpipe_idesc_get_l2_offset().
305 *
306 * @param idesc An ingress packet descriptor.
307 */
308static inline unsigned int gxio_mpipe_idesc_get_l2_length(gxio_mpipe_idesc_t
309 *idesc)
310{
311 unsigned int xfer_size = idesc->l2_size;
312 return xfer_size - gxio_mpipe_idesc_get_l2_offset(idesc);
313}
314
315/* A context object used to manage mPIPE hardware resources. */
316typedef struct {
317
318 /* File descriptor for calling up to Linux (and thus the HV). */
319 int fd;
320
321 /* Corresponding mpipe instance #. */
322 int instance;
323
324 /* The VA at which configuration registers are mapped. */
325 char *mmio_cfg_base;
326
327 /* The VA at which IDMA, EDMA, and buffer manager are mapped. */
328 char *mmio_fast_base;
329
330 /* The "initialized" buffer stacks. */
331 gxio_mpipe_rules_stacks_t __stacks;
332
333} gxio_mpipe_context_t;
334
335/* This is only used internally, but it's most easily made visible here. */
336typedef gxio_mpipe_context_t gxio_mpipe_info_context_t;
337
338/* Initialize an mPIPE context.
339 *
340 * This function allocates an mPIPE "service domain" and maps the MMIO
341 * registers into the caller's VA space.
342 *
343 * @param context Context object to be initialized.
344 * @param mpipe_instance Instance number of mPIPE shim to be controlled via
345 * context.
346 */
347extern int gxio_mpipe_init(gxio_mpipe_context_t *context,
348 unsigned int mpipe_instance);
349
350/* Destroy an mPIPE context.
351 *
352 * This function frees the mPIPE "service domain" and unmaps the MMIO
353 * registers from the caller's VA space.
354 *
355 * If a user process exits without calling this routine, the kernel
356 * will destroy the mPIPE context as part of process teardown.
357 *
358 * @param context Context object to be destroyed.
359 */
360extern int gxio_mpipe_destroy(gxio_mpipe_context_t *context);
361
362/*****************************************************************
363 * Buffer Stacks *
364 ******************************************************************/
365
366/* Allocate a set of buffer stacks.
367 *
368 * The return value is NOT interesting if count is zero.
369 *
370 * @param context An initialized mPIPE context.
371 * @param count Number of stacks required.
372 * @param first Index of first stack if ::GXIO_MPIPE_ALLOC_FIXED flag is set,
373 * otherwise ignored.
374 * @param flags Flag bits from ::gxio_mpipe_alloc_flags_e.
375 * @return Index of first allocated buffer stack, or
376 * ::GXIO_MPIPE_ERR_NO_BUFFER_STACK if allocation failed.
377 */
378extern int gxio_mpipe_alloc_buffer_stacks(gxio_mpipe_context_t *context,
379 unsigned int count,
380 unsigned int first,
381 unsigned int flags);
382
383/* Enum codes for buffer sizes supported by mPIPE. */
384typedef enum {
385 /* 128 byte packet data buffer. */
386 GXIO_MPIPE_BUFFER_SIZE_128 = MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_128,
387 /* 256 byte packet data buffer. */
388 GXIO_MPIPE_BUFFER_SIZE_256 = MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_256,
389 /* 512 byte packet data buffer. */
390 GXIO_MPIPE_BUFFER_SIZE_512 = MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_512,
391 /* 1024 byte packet data buffer. */
392 GXIO_MPIPE_BUFFER_SIZE_1024 = MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_1024,
393 /* 1664 byte packet data buffer. */
394 GXIO_MPIPE_BUFFER_SIZE_1664 = MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_1664,
395 /* 4096 byte packet data buffer. */
396 GXIO_MPIPE_BUFFER_SIZE_4096 = MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_4096,
397 /* 10368 byte packet data buffer. */
398 GXIO_MPIPE_BUFFER_SIZE_10368 =
399 MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_10368,
400 /* 16384 byte packet data buffer. */
401 GXIO_MPIPE_BUFFER_SIZE_16384 = MPIPE_BSM_INIT_DAT_1__SIZE_VAL_BSZ_16384
402} gxio_mpipe_buffer_size_enum_t;
403
404/* Convert a buffer size in bytes into a buffer size enum. */
405extern gxio_mpipe_buffer_size_enum_t
406gxio_mpipe_buffer_size_to_buffer_size_enum(size_t size);
407
408/* Convert a buffer size enum into a buffer size in bytes. */
409extern size_t
410gxio_mpipe_buffer_size_enum_to_buffer_size(gxio_mpipe_buffer_size_enum_t
411 buffer_size_enum);
412
413/* Calculate the number of bytes required to store a given number of
414 * buffers in the memory registered with a buffer stack via
415 * gxio_mpipe_init_buffer_stack().
416 */
417extern size_t gxio_mpipe_calc_buffer_stack_bytes(unsigned long buffers);
418
419/* Initialize a buffer stack. This function binds a region of memory
420 * to be used by the hardware for storing buffer addresses pushed via
421 * gxio_mpipe_push_buffer() or as the result of sending a buffer out
422 * the egress with the 'push to stack when done' bit set. Once this
423 * function returns, the memory region's contents may be arbitrarily
424 * modified by the hardware at any time and software should not access
425 * the memory region again.
426 *
427 * @param context An initialized mPIPE context.
428 * @param stack The buffer stack index.
429 * @param buffer_size_enum The size of each buffer in the buffer stack,
430 * as an enum.
431 * @param mem The address of the buffer stack. This memory must be
432 * physically contiguous and aligned to a 64kB boundary.
433 * @param mem_size The size of the buffer stack, in bytes.
434 * @param mem_flags ::gxio_mpipe_mem_flags_e memory flags.
435 * @return Zero on success, ::GXIO_MPIPE_ERR_INVAL_BUFFER_SIZE if
436 * buffer_size_enum is invalid, ::GXIO_MPIPE_ERR_BAD_BUFFER_STACK if
437 * stack has not been allocated.
438 */
439extern int gxio_mpipe_init_buffer_stack(gxio_mpipe_context_t *context,
440 unsigned int stack,
441 gxio_mpipe_buffer_size_enum_t
442 buffer_size_enum, void *mem,
443 size_t mem_size,
444 unsigned int mem_flags);
445
446/* Push a buffer onto a previously initialized buffer stack.
447 *
448 * The size of the buffer being pushed must match the size that was
449 * registered with gxio_mpipe_init_buffer_stack(). All packet buffer
450 * addresses are 128-byte aligned; the low 7 bits of the specified
451 * buffer address will be ignored.
452 *
453 * @param context An initialized mPIPE context.
454 * @param stack The buffer stack index.
455 * @param buffer The buffer (the low seven bits are ignored).
456 */
457static inline void gxio_mpipe_push_buffer(gxio_mpipe_context_t *context,
458 unsigned int stack, void *buffer)
459{
460 MPIPE_BSM_REGION_ADDR_t offset = { {0} };
461 MPIPE_BSM_REGION_VAL_t val = { {0} };
462
463 /*
464 * The mmio_fast_base region starts at the IDMA region, so subtract
465 * off that initial offset.
466 */
467 offset.region =
468 MPIPE_MMIO_ADDR__REGION_VAL_BSM -
469 MPIPE_MMIO_ADDR__REGION_VAL_IDMA;
470 offset.stack = stack;
471
472#if __SIZEOF_POINTER__ == 4
473 val.va = ((ulong) buffer) >> MPIPE_BSM_REGION_VAL__VA_SHIFT;
474#else
475 val.va = ((long)buffer) >> MPIPE_BSM_REGION_VAL__VA_SHIFT;
476#endif
477
478 __gxio_mmio_write(context->mmio_fast_base + offset.word, val.word);
479}
480
481/* Pop a buffer off of a previously initialized buffer stack.
482 *
483 * @param context An initialized mPIPE context.
484 * @param stack The buffer stack index.
485 * @return The buffer, or NULL if the stack is empty.
486 */
487static inline void *gxio_mpipe_pop_buffer(gxio_mpipe_context_t *context,
488 unsigned int stack)
489{
490 MPIPE_BSM_REGION_ADDR_t offset = { {0} };
491
492 /*
493 * The mmio_fast_base region starts at the IDMA region, so subtract
494 * off that initial offset.
495 */
496 offset.region =
497 MPIPE_MMIO_ADDR__REGION_VAL_BSM -
498 MPIPE_MMIO_ADDR__REGION_VAL_IDMA;
499 offset.stack = stack;
500
501 while (1) {
502 /*
503 * Case 1: val.c == ..._UNCHAINED, va is non-zero.
504 * Case 2: val.c == ..._INVALID, va is zero.
505 * Case 3: val.c == ..._NOT_RDY, va is zero.
506 */
507 MPIPE_BSM_REGION_VAL_t val;
508 val.word =
509 __gxio_mmio_read(context->mmio_fast_base +
510 offset.word);
511
512 /*
513 * Handle case 1 and 2 by returning the buffer (or NULL).
514 * Handle case 3 by waiting for the prefetch buffer to refill.
515 */
516 if (val.c != MPIPE_EDMA_DESC_WORD1__C_VAL_NOT_RDY)
517 return (void *)((unsigned long)val.
518 va << MPIPE_BSM_REGION_VAL__VA_SHIFT);
519 }
520}
521
522/*****************************************************************
523 * NotifRings *
524 ******************************************************************/
525
526/* Allocate a set of NotifRings.
527 *
528 * The return value is NOT interesting if count is zero.
529 *
530 * Note that NotifRings are allocated in chunks, so allocating one at
531 * a time is much less efficient than allocating several at once.
532 *
533 * @param context An initialized mPIPE context.
534 * @param count Number of NotifRings required.
535 * @param first Index of first NotifRing if ::GXIO_MPIPE_ALLOC_FIXED flag
536 * is set, otherwise ignored.
537 * @param flags Flag bits from ::gxio_mpipe_alloc_flags_e.
538 * @return Index of first allocated buffer NotifRing, or
539 * ::GXIO_MPIPE_ERR_NO_NOTIF_RING if allocation failed.
540 */
541extern int gxio_mpipe_alloc_notif_rings(gxio_mpipe_context_t *context,
542 unsigned int count, unsigned int first,
543 unsigned int flags);
544
545/* Initialize a NotifRing, using the given memory and size.
546 *
547 * @param context An initialized mPIPE context.
548 * @param ring The NotifRing index.
549 * @param mem A physically contiguous region of memory to be filled
550 * with a ring of ::gxio_mpipe_idesc_t structures.
551 * @param mem_size Number of bytes in the ring. Must be 128, 512,
552 * 2048, or 65536 * sizeof(gxio_mpipe_idesc_t).
553 * @param mem_flags ::gxio_mpipe_mem_flags_e memory flags.
554 *
555 * @return 0 on success, ::GXIO_MPIPE_ERR_BAD_NOTIF_RING or
556 * ::GXIO_ERR_INVAL_MEMORY_SIZE on failure.
557 */
558extern int gxio_mpipe_init_notif_ring(gxio_mpipe_context_t *context,
559 unsigned int ring,
560 void *mem, size_t mem_size,
561 unsigned int mem_flags);
562
563/* Configure an interrupt to be sent to a tile on incoming NotifRing
564 * traffic. Once an interrupt is sent for a particular ring, no more
565 * will be sent until gxio_mica_enable_notif_ring_interrupt() is called.
566 *
567 * @param context An initialized mPIPE context.
568 * @param x X coordinate of interrupt target tile.
569 * @param y Y coordinate of interrupt target tile.
570 * @param i Index of the IPI register which will receive the interrupt.
571 * @param e Specific event which will be set in the target IPI register when
572 * the interrupt occurs.
573 * @param ring The NotifRing index.
574 * @return Zero on success, GXIO_ERR_INVAL if params are out of range.
575 */
576extern int gxio_mpipe_request_notif_ring_interrupt(gxio_mpipe_context_t
577 *context, int x, int y,
578 int i, int e,
579 unsigned int ring);
580
581/* Enable an interrupt on incoming NotifRing traffic.
582 *
583 * @param context An initialized mPIPE context.
584 * @param ring The NotifRing index.
585 * @return Zero on success, GXIO_ERR_INVAL if params are out of range.
586 */
587extern int gxio_mpipe_enable_notif_ring_interrupt(gxio_mpipe_context_t
588 *context, unsigned int ring);
589
590/* Map all of a client's memory via the given IOTLB.
591 * @param context An initialized mPIPE context.
592 * @param iotlb IOTLB index.
593 * @param pte Page table entry.
594 * @param flags Flags.
595 * @return Zero on success, or a negative error code.
596 */
597extern int gxio_mpipe_register_client_memory(gxio_mpipe_context_t *context,
598 unsigned int iotlb, HV_PTE pte,
599 unsigned int flags);
600
601/*****************************************************************
602 * Notif Groups *
603 ******************************************************************/
604
605/* Allocate a set of NotifGroups.
606 *
607 * The return value is NOT interesting if count is zero.
608 *
609 * @param context An initialized mPIPE context.
610 * @param count Number of NotifGroups required.
611 * @param first Index of first NotifGroup if ::GXIO_MPIPE_ALLOC_FIXED flag
612 * is set, otherwise ignored.
613 * @param flags Flag bits from ::gxio_mpipe_alloc_flags_e.
614 * @return Index of first allocated buffer NotifGroup, or
615 * ::GXIO_MPIPE_ERR_NO_NOTIF_GROUP if allocation failed.
616 */
617extern int gxio_mpipe_alloc_notif_groups(gxio_mpipe_context_t *context,
618 unsigned int count,
619 unsigned int first,
620 unsigned int flags);
621
622/* Add a NotifRing to a NotifGroup. This only sets a bit in the
623 * application's 'group' object; the hardware NotifGroup can be
624 * initialized by passing 'group' to gxio_mpipe_init_notif_group() or
625 * gxio_mpipe_init_notif_group_and_buckets().
626 */
627static inline void
628gxio_mpipe_notif_group_add_ring(gxio_mpipe_notif_group_bits_t *bits, int ring)
629{
630 bits->ring_mask[ring / 64] |= (1ull << (ring % 64));
631}
632
633/* Set a particular NotifGroup bitmask. Since the load balancer
634 * makes decisions based on both bucket and NotifGroup state, most
635 * applications should use gxio_mpipe_init_notif_group_and_buckets()
636 * rather than using this function to configure just a NotifGroup.
637 */
638extern int gxio_mpipe_init_notif_group(gxio_mpipe_context_t *context,
639 unsigned int group,
640 gxio_mpipe_notif_group_bits_t bits);
641
642/*****************************************************************
643 * Load Balancer *
644 ******************************************************************/
645
646/* Allocate a set of load balancer buckets.
647 *
648 * The return value is NOT interesting if count is zero.
649 *
650 * Note that buckets are allocated in chunks, so allocating one at
651 * a time is much less efficient than allocating several at once.
652 *
653 * Note that the buckets are actually divided into two sub-ranges, of
654 * different sizes, and different chunk sizes, and the range you get
655 * by default is determined by the size of the request. Allocations
656 * cannot span the two sub-ranges.
657 *
658 * @param context An initialized mPIPE context.
659 * @param count Number of buckets required.
660 * @param first Index of first bucket if ::GXIO_MPIPE_ALLOC_FIXED flag is set,
661 * otherwise ignored.
662 * @param flags Flag bits from ::gxio_mpipe_alloc_flags_e.
663 * @return Index of first allocated buffer bucket, or
664 * ::GXIO_MPIPE_ERR_NO_BUCKET if allocation failed.
665 */
666extern int gxio_mpipe_alloc_buckets(gxio_mpipe_context_t *context,
667 unsigned int count, unsigned int first,
668 unsigned int flags);
669
670/* The legal modes for gxio_mpipe_bucket_info_t and
671 * gxio_mpipe_init_notif_group_and_buckets().
672 *
673 * All modes except ::GXIO_MPIPE_BUCKET_ROUND_ROBIN expect that the user
674 * will allocate a power-of-two number of buckets and initialize them
675 * to the same mode. The classifier program then uses the appropriate
676 * number of low bits from the incoming packet's flow hash to choose a
677 * load balancer bucket. Based on that bucket's load balancing mode,
678 * reference count, and currently active NotifRing, the load balancer
679 * chooses the NotifRing to which the packet will be delivered.
680 */
681typedef enum {
682 /* All packets for a bucket go to the same NotifRing unless the
683 * NotifRing gets full, in which case packets will be dropped. If
684 * the bucket reference count ever reaches zero, a new NotifRing may
685 * be chosen.
686 */
687 GXIO_MPIPE_BUCKET_DYNAMIC_FLOW_AFFINITY =
688 MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_DFA,
689
690 /* All packets for a bucket always go to the same NotifRing.
691 */
692 GXIO_MPIPE_BUCKET_STATIC_FLOW_AFFINITY =
693 MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_FIXED,
694
695 /* All packets for a bucket go to the least full NotifRing in the
696 * group, providing load balancing round robin behavior.
697 */
698 GXIO_MPIPE_BUCKET_ROUND_ROBIN =
699 MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_ALWAYS_PICK,
700
701 /* All packets for a bucket go to the same NotifRing unless the
702 * NotifRing gets full, at which point the bucket starts using the
703 * least full NotifRing in the group. If all NotifRings in the
704 * group are full, packets will be dropped.
705 */
706 GXIO_MPIPE_BUCKET_STICKY_FLOW_LOCALITY =
707 MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_STICKY,
708
709 /* All packets for a bucket go to the same NotifRing unless the
710 * NotifRing gets full, or a random timer fires, at which point the
711 * bucket starts using the least full NotifRing in the group. If
712 * all NotifRings in the group are full, packets will be dropped.
713 * WARNING: This mode is BROKEN on chips with fewer than 64 tiles.
714 */
715 GXIO_MPIPE_BUCKET_PREFER_FLOW_LOCALITY =
716 MPIPE_LBL_INIT_DAT_BSTS_TBL__MODE_VAL_STICKY_RAND,
717
718} gxio_mpipe_bucket_mode_t;
719
720/* Copy a set of bucket initialization values into the mPIPE
721 * hardware. Since the load balancer makes decisions based on both
722 * bucket and NotifGroup state, most applications should use
723 * gxio_mpipe_init_notif_group_and_buckets() rather than using this
724 * function to configure a single bucket.
725 *
726 * @param context An initialized mPIPE context.
727 * @param bucket Bucket index to be initialized.
728 * @param bucket_info Initial reference count, NotifRing index, and mode.
729 * @return 0 on success, ::GXIO_MPIPE_ERR_BAD_BUCKET on failure.
730 */
731extern int gxio_mpipe_init_bucket(gxio_mpipe_context_t *context,
732 unsigned int bucket,
733 gxio_mpipe_bucket_info_t bucket_info);
734
735/* Initializes a group and range of buckets and range of rings such
736 * that the load balancer runs a particular load balancing function.
737 *
738 * First, the group is initialized with the given rings.
739 *
740 * Second, each bucket is initialized with the mode and group, and a
741 * ring chosen round-robin from the given rings.
742 *
743 * Normally, the classifier picks a bucket, and then the load balancer
744 * picks a ring, based on the bucket's mode, group, and current ring,
745 * possibly updating the bucket's ring.
746 *
747 * @param context An initialized mPIPE context.
748 * @param group The group.
749 * @param ring The first ring.
750 * @param num_rings The number of rings.
751 * @param bucket The first bucket.
752 * @param num_buckets The number of buckets.
753 * @param mode The load balancing mode.
754 *
755 * @return 0 on success, ::GXIO_MPIPE_ERR_BAD_BUCKET,
756 * ::GXIO_MPIPE_ERR_BAD_NOTIF_GROUP, or
757 * ::GXIO_MPIPE_ERR_BAD_NOTIF_RING on failure.
758 */
759extern int gxio_mpipe_init_notif_group_and_buckets(gxio_mpipe_context_t
760 *context,
761 unsigned int group,
762 unsigned int ring,
763 unsigned int num_rings,
764 unsigned int bucket,
765 unsigned int num_buckets,
766 gxio_mpipe_bucket_mode_t
767 mode);
768
769/* Return credits to a NotifRing and/or bucket.
770 *
771 * @param context An initialized mPIPE context.
772 * @param ring The NotifRing index, or -1.
773 * @param bucket The bucket, or -1.
774 * @param count The number of credits to return.
775 */
776static inline void gxio_mpipe_credit(gxio_mpipe_context_t *context,
777 int ring, int bucket, unsigned int count)
778{
779 /* NOTE: Fancy struct initialization would break "C89" header test. */
780
781 MPIPE_IDMA_RELEASE_REGION_ADDR_t offset = { {0} };
782 MPIPE_IDMA_RELEASE_REGION_VAL_t val = { {0} };
783
784 /*
785 * The mmio_fast_base region starts at the IDMA region, so subtract
786 * off that initial offset.
787 */
788 offset.region =
789 MPIPE_MMIO_ADDR__REGION_VAL_IDMA -
790 MPIPE_MMIO_ADDR__REGION_VAL_IDMA;
791 offset.ring = ring;
792 offset.bucket = bucket;
793 offset.ring_enable = (ring >= 0);
794 offset.bucket_enable = (bucket >= 0);
795 val.count = count;
796
797 __gxio_mmio_write(context->mmio_fast_base + offset.word, val.word);
798}
799
800/*****************************************************************
801 * Egress Rings *
802 ******************************************************************/
803
804/* Allocate a set of eDMA rings.
805 *
806 * The return value is NOT interesting if count is zero.
807 *
808 * @param context An initialized mPIPE context.
809 * @param count Number of eDMA rings required.
810 * @param first Index of first eDMA ring if ::GXIO_MPIPE_ALLOC_FIXED flag
811 * is set, otherwise ignored.
812 * @param flags Flag bits from ::gxio_mpipe_alloc_flags_e.
813 * @return Index of first allocated buffer eDMA ring, or
814 * ::GXIO_MPIPE_ERR_NO_EDMA_RING if allocation failed.
815 */
816extern int gxio_mpipe_alloc_edma_rings(gxio_mpipe_context_t *context,
817 unsigned int count, unsigned int first,
818 unsigned int flags);
819
820/* Initialize an eDMA ring, using the given memory and size.
821 *
822 * @param context An initialized mPIPE context.
823 * @param ering The eDMA ring index.
824 * @param channel The channel to use. This must be one of the channels
825 * associated with the context's set of open links.
826 * @param mem A physically contiguous region of memory to be filled
827 * with a ring of ::gxio_mpipe_edesc_t structures.
828 * @param mem_size Number of bytes in the ring. Must be 512, 2048,
829 * 8192 or 65536, times 16 (i.e. sizeof(gxio_mpipe_edesc_t)).
830 * @param mem_flags ::gxio_mpipe_mem_flags_e memory flags.
831 *
832 * @return 0 on success, ::GXIO_MPIPE_ERR_BAD_EDMA_RING or
833 * ::GXIO_ERR_INVAL_MEMORY_SIZE on failure.
834 */
835extern int gxio_mpipe_init_edma_ring(gxio_mpipe_context_t *context,
836 unsigned int ering, unsigned int channel,
837 void *mem, size_t mem_size,
838 unsigned int mem_flags);
839
840/* Set the "max_blks", "min_snf_blks", and "db" fields of
841 * ::MPIPE_EDMA_RG_INIT_DAT_THRESH_t for a given edma ring.
842 *
843 * The global pool of dynamic blocks will be automatically adjusted.
844 *
845 * This function should not be called after any egress has been done
846 * on the edma ring.
847 *
848 * Most applications should just use gxio_mpipe_equeue_set_snf_size().
849 *
850 * @param context An initialized mPIPE context.
851 * @param ering The eDMA ring index.
852 * @param max_blks The number of blocks to dedicate to the ring
853 * (normally min_snf_blks + 1). Must be greater than min_snf_blocks.
854 * @param min_snf_blks The number of blocks which must be stored
855 * prior to starting to send the packet (normally 12).
856 * @param db Whether to allow use of dynamic blocks by the ring
857 * (normally 1).
858 *
859 * @return 0 on success, negative on error.
860 */
861extern int gxio_mpipe_config_edma_ring_blks(gxio_mpipe_context_t *context,
862 unsigned int ering,
863 unsigned int max_blks,
864 unsigned int min_snf_blks,
865 unsigned int db);
866
867/*****************************************************************
868 * Classifier Program *
869 ******************************************************************/
870
871/*
872 *
873 * Functions for loading or configuring the mPIPE classifier program.
874 *
875 * The mPIPE classification processors all run a special "classifier"
876 * program which, for each incoming packet, parses the packet headers,
877 * encodes some packet metadata in the "idesc", and either drops the
878 * packet, or picks a notif ring to handle the packet, and a buffer
879 * stack to contain the packet, usually based on the channel, VLAN,
880 * dMAC, flow hash, and packet size, under the guidance of the "rules"
881 * API described below.
882 *
883 * @section gxio_mpipe_classifier_default Default Classifier
884 *
885 * The MDE provides a simple "default" classifier program. It is
886 * shipped as source in "$TILERA_ROOT/src/sys/mpipe/classifier.c",
887 * which serves as its official documentation. It is shipped as a
888 * binary program in "$TILERA_ROOT/tile/boot/classifier", which is
889 * automatically included in bootroms created by "tile-monitor", and
890 * is automatically loaded by the hypervisor at boot time.
891 *
892 * The L2 analysis handles LLC packets, SNAP packets, and "VLAN
893 * wrappers" (keeping the outer VLAN).
894 *
895 * The L3 analysis handles IPv4 and IPv6, dropping packets with bad
896 * IPv4 header checksums, requesting computation of a TCP/UDP checksum
897 * if appropriate, and hashing the dest and src IP addresses, plus the
898 * ports for TCP/UDP packets, into the flow hash. No special analysis
899 * is done for "fragmented" packets or "tunneling" protocols. Thus,
900 * the first fragment of a fragmented TCP/UDP packet is hashed using
901 * src/dest IP address and ports and all subsequent fragments are only
902 * hashed according to src/dest IP address.
903 *
904 * The L3 analysis handles other packets too, hashing the dMAC
905 * smac into a flow hash.
906 *
907 * The channel, VLAN, and dMAC used to pick a "rule" (see the
908 * "rules" APIs below), which in turn is used to pick a buffer stack
909 * (based on the packet size) and a bucket (based on the flow hash).
910 *
911 * To receive traffic matching a particular (channel/VLAN/dMAC
912 * pattern, an application should allocate its own buffer stacks and
913 * load balancer buckets, and map traffic to those stacks and buckets,
914 * as decribed by the "rules" API below.
915 *
916 * Various packet metadata is encoded in the idesc. The flow hash is
917 * four bytes at 0x0C. The VLAN is two bytes at 0x10. The ethtype is
918 * two bytes at 0x12. The l3 start is one byte at 0x14. The l4 start
919 * is one byte at 0x15 for IPv4 and IPv6 packets, and otherwise zero.
920 * The protocol is one byte at 0x16 for IPv4 and IPv6 packets, and
921 * otherwise zero.
922 *
923 * @section gxio_mpipe_classifier_custom Custom Classifiers.
924 *
925 * A custom classifier may be created using "tile-mpipe-cc" with a
926 * customized version of the default classifier sources.
927 *
928 * The custom classifier may be included in bootroms using the
929 * "--classifier" option to "tile-monitor", or loaded dynamically
930 * using gxio_mpipe_classifier_load_from_file().
931 *
932 * Be aware that "extreme" customizations may break the assumptions of
933 * the "rules" APIs described below, but simple customizations, such
934 * as adding new packet metadata, should be fine.
935 */
936
937/* A set of classifier rules, plus a context. */
938typedef struct {
939
940 /* The context. */
941 gxio_mpipe_context_t *context;
942
943 /* The actual rules. */
944 gxio_mpipe_rules_list_t list;
945
946} gxio_mpipe_rules_t;
947
948/* Initialize a classifier program rules list.
949 *
950 * This function can be called on a previously initialized rules list
951 * to discard any previously added rules.
952 *
953 * @param rules Rules list to initialize.
954 * @param context An initialized mPIPE context.
955 */
956extern void gxio_mpipe_rules_init(gxio_mpipe_rules_t *rules,
957 gxio_mpipe_context_t *context);
958
959/* Begin a new rule on the indicated rules list.
960 *
961 * Note that an empty rule matches all packets, but an empty rule list
962 * matches no packets.
963 *
964 * @param rules Rules list to which new rule is appended.
965 * @param bucket First load balancer bucket to which packets will be
966 * delivered.
967 * @param num_buckets Number of buckets (must be a power of two) across
968 * which packets will be distributed based on the "flow hash".
969 * @param stacks Either NULL, to assign each packet to the smallest
970 * initialized buffer stack which does not induce chaining (and to
971 * drop packets which exceed the largest initialized buffer stack
972 * buffer size), or an array, with each entry indicating which buffer
973 * stack should be used for packets up to that size (with 255
974 * indicating that those packets should be dropped).
975 * @return 0 on success, or a negative error code on failure.
976 */
977extern int gxio_mpipe_rules_begin(gxio_mpipe_rules_t *rules,
978 unsigned int bucket,
979 unsigned int num_buckets,
980 gxio_mpipe_rules_stacks_t *stacks);
981
982/* Set the headroom of the current rule.
983 *
984 * @param rules Rules list whose current rule will be modified.
985 * @param headroom The headroom.
986 * @return 0 on success, or a negative error code on failure.
987 */
988extern int gxio_mpipe_rules_set_headroom(gxio_mpipe_rules_t *rules,
989 uint8_t headroom);
990
991/* Indicate that packets from a particular channel can be delivered
992 * to the buckets and buffer stacks associated with the current rule.
993 *
994 * Channels added must be associated with links opened by the mPIPE context
995 * used in gxio_mpipe_rules_init(). A rule with no channels is equivalent
996 * to a rule naming all such associated channels.
997 *
998 * @param rules Rules list whose current rule will be modified.
999 * @param channel The channel to add.
1000 * @return 0 on success, or a negative error code on failure.
1001 */
1002extern int gxio_mpipe_rules_add_channel(gxio_mpipe_rules_t *rules,
1003 unsigned int channel);
1004
1005/* Commit rules.
1006 *
1007 * The rules are sent to the hypervisor, where they are combined with
1008 * the rules from other apps, and used to program the hardware classifier.
1009 *
1010 * Note that if this function returns an error, then the rules will NOT
1011 * have been committed, even if the error is due to interactions with
1012 * rules from another app.
1013 *
1014 * @param rules Rules list to commit.
1015 * @return 0 on success, or a negative error code on failure.
1016 */
1017extern int gxio_mpipe_rules_commit(gxio_mpipe_rules_t *rules);
1018
1019/*****************************************************************
1020 * Ingress Queue Wrapper *
1021 ******************************************************************/
1022
1023/*
1024 *
1025 * Convenience functions for receiving packets from a NotifRing and
1026 * sending packets via an eDMA ring.
1027 *
1028 * The mpipe ingress and egress hardware uses shared memory packet
1029 * descriptors to describe packets that have arrived on ingress or
1030 * are destined for egress. These descriptors are stored in shared
1031 * memory ring buffers and written or read by hardware as necessary.
1032 * The gxio library provides wrapper functions that manage the head and
1033 * tail pointers for these rings, allowing the user to easily read or
1034 * write packet descriptors.
1035 *
1036 * The initialization interface for ingress and egress rings is quite
1037 * similar. For example, to create an ingress queue, the user passes
1038 * a ::gxio_mpipe_iqueue_t state object, a ring number from
1039 * gxio_mpipe_alloc_notif_rings(), and the address of memory to hold a
1040 * ring buffer to the gxio_mpipe_iqueue_init() function. The function
1041 * returns success when the state object has been initialized and the
1042 * hardware configured to deliver packets to the specified ring
1043 * buffer. Similarly, gxio_mpipe_equeue_init() takes a
1044 * ::gxio_mpipe_equeue_t state object, a ring number from
1045 * gxio_mpipe_alloc_edma_rings(), and a shared memory buffer.
1046 *
1047 * @section gxio_mpipe_iqueue Working with Ingress Queues
1048 *
1049 * Once initialized, the gxio_mpipe_iqueue_t API provides two flows
1050 * for getting the ::gxio_mpipe_idesc_t packet descriptor associated
1051 * with incoming packets. The simplest is to call
1052 * gxio_mpipe_iqueue_get() or gxio_mpipe_iqueue_try_get(). These
1053 * functions copy the oldest packet descriptor out of the NotifRing and
1054 * into a descriptor provided by the caller. They also immediately
1055 * inform the hardware that a descriptor has been processed.
1056 *
1057 * For applications with stringent performance requirements, higher
1058 * efficiency can be achieved by avoiding the packet descriptor copy
1059 * and processing multiple descriptors at once. The
1060 * gxio_mpipe_iqueue_peek() and gxio_mpipe_iqueue_try_peek() functions
1061 * allow such optimizations. These functions provide a pointer to the
1062 * next valid ingress descriptor in the NotifRing's shared memory ring
1063 * buffer, and a count of how many contiguous descriptors are ready to
1064 * be processed. The application can then process any number of those
1065 * descriptors in place, calling gxio_mpipe_iqueue_consume() to inform
1066 * the hardware after each one has been processed.
1067 *
1068 * @section gxio_mpipe_equeue Working with Egress Queues
1069 *
1070 * Similarly, the egress queue API provides a high-performance
1071 * interface plus a simple wrapper for use in posting
1072 * ::gxio_mpipe_edesc_t egress packet descriptors. The simple
1073 * version, gxio_mpipe_equeue_put(), allows the programmer to wait for
1074 * an eDMA ring slot to become available and write a single descriptor
1075 * into the ring.
1076 *
1077 * Alternatively, you can reserve slots in the eDMA ring using
1078 * gxio_mpipe_equeue_reserve() or gxio_mpipe_equeue_try_reserve(), and
1079 * then fill in each slot using gxio_mpipe_equeue_put_at(). This
1080 * capability can be used to amortize the cost of reserving slots
1081 * across several packets. It also allows gather operations to be
1082 * performed on a shared equeue, by ensuring that the edescs for all
1083 * the fragments are all contiguous in the eDMA ring.
1084 *
1085 * The gxio_mpipe_equeue_reserve() and gxio_mpipe_equeue_try_reserve()
1086 * functions return a 63-bit "completion slot", which is actually a
1087 * sequence number, the low bits of which indicate the ring buffer
1088 * index and the high bits the number of times the application has
1089 * gone around the egress ring buffer. The extra bits allow an
1090 * application to check for egress completion by calling
1091 * gxio_mpipe_equeue_is_complete() to see whether a particular 'slot'
1092 * number has finished. Given the maximum packet rates of the Gx
1093 * processor, the 63-bit slot number will never wrap.
1094 *
1095 * In practice, most applications use the ::gxio_mpipe_edesc_t::hwb
1096 * bit to indicate that the buffers containing egress packet data
1097 * should be pushed onto a buffer stack when egress is complete. Such
1098 * applications generally do not need to know when an egress operation
1099 * completes (since there is no need to free a buffer post-egress),
1100 * and thus can use the optimized gxio_mpipe_equeue_reserve_fast() or
1101 * gxio_mpipe_equeue_try_reserve_fast() functions, which return a 24
1102 * bit "slot", instead of a 63-bit "completion slot".
1103 *
1104 * Once a slot has been "reserved", it MUST be filled. If the
1105 * application reserves a slot and then decides that it does not
1106 * actually need it, it can set the ::gxio_mpipe_edesc_t::ns (no send)
1107 * bit on the descriptor passed to gxio_mpipe_equeue_put_at() to
1108 * indicate that no data should be sent. This technique can also be
1109 * used to drop an incoming packet, instead of forwarding it, since
1110 * any buffer will still be pushed onto the buffer stack when the
1111 * egress descriptor is processed.
1112 */
1113
1114/* A convenient interface to a NotifRing, for use by a single thread.
1115 */
1116typedef struct {
1117
1118 /* The context. */
1119 gxio_mpipe_context_t *context;
1120
1121 /* The actual NotifRing. */
1122 gxio_mpipe_idesc_t *idescs;
1123
1124 /* The number of entries. */
1125 unsigned long num_entries;
1126
1127 /* The number of entries minus one. */
1128 unsigned long mask_num_entries;
1129
1130 /* The log2() of the number of entries. */
1131 unsigned long log2_num_entries;
1132
1133 /* The next entry. */
1134 unsigned int head;
1135
1136 /* The NotifRing id. */
1137 unsigned int ring;
1138
1139#ifdef __BIG_ENDIAN__
1140 /* The number of byteswapped entries. */
1141 unsigned int swapped;
1142#endif
1143
1144} gxio_mpipe_iqueue_t;
1145
1146/* Initialize an "iqueue".
1147 *
1148 * Takes the iqueue plus the same args as gxio_mpipe_init_notif_ring().
1149 */
1150extern int gxio_mpipe_iqueue_init(gxio_mpipe_iqueue_t *iqueue,
1151 gxio_mpipe_context_t *context,
1152 unsigned int ring,
1153 void *mem, size_t mem_size,
1154 unsigned int mem_flags);
1155
1156/* Advance over some old entries in an iqueue.
1157 *
1158 * Please see the documentation for gxio_mpipe_iqueue_consume().
1159 *
1160 * @param iqueue An ingress queue initialized via gxio_mpipe_iqueue_init().
1161 * @param count The number of entries to advance over.
1162 */
1163static inline void gxio_mpipe_iqueue_advance(gxio_mpipe_iqueue_t *iqueue,
1164 int count)
1165{
1166 /* Advance with proper wrap. */
1167 int head = iqueue->head + count;
1168 iqueue->head =
1169 (head & iqueue->mask_num_entries) +
1170 (head >> iqueue->log2_num_entries);
1171
1172#ifdef __BIG_ENDIAN__
1173 /* HACK: Track swapped entries. */
1174 iqueue->swapped -= count;
1175#endif
1176}
1177
1178/* Release the ring and bucket for an old entry in an iqueue.
1179 *
1180 * Releasing the ring allows more packets to be delivered to the ring.
1181 *
1182 * Releasing the bucket allows flows using the bucket to be moved to a
1183 * new ring when using GXIO_MPIPE_BUCKET_DYNAMIC_FLOW_AFFINITY.
1184 *
1185 * This function is shorthand for "gxio_mpipe_credit(iqueue->context,
1186 * iqueue->ring, idesc->bucket_id, 1)", and it may be more convenient
1187 * to make that underlying call, using those values, instead of
1188 * tracking the entire "idesc".
1189 *
1190 * If packet processing is deferred, optimal performance requires that
1191 * the releasing be deferred as well.
1192 *
1193 * Please see the documentation for gxio_mpipe_iqueue_consume().
1194 *
1195 * @param iqueue An ingress queue initialized via gxio_mpipe_iqueue_init().
1196 * @param idesc The descriptor which was processed.
1197 */
1198static inline void gxio_mpipe_iqueue_release(gxio_mpipe_iqueue_t *iqueue,
1199 gxio_mpipe_idesc_t *idesc)
1200{
1201 gxio_mpipe_credit(iqueue->context, iqueue->ring, idesc->bucket_id, 1);
1202}
1203
1204/* Consume a packet from an "iqueue".
1205 *
1206 * After processing packets peeked at via gxio_mpipe_iqueue_peek()
1207 * or gxio_mpipe_iqueue_try_peek(), you must call this function, or
1208 * gxio_mpipe_iqueue_advance() plus gxio_mpipe_iqueue_release(), to
1209 * advance over those entries, and release their rings and buckets.
1210 *
1211 * You may call this function as each packet is processed, or you can
1212 * wait until several packets have been processed.
1213 *
1214 * Note that if you are using a single bucket, and you are handling
1215 * batches of N packets, then you can replace several calls to this
1216 * function with calls to "gxio_mpipe_iqueue_advance(iqueue, N)" and
1217 * "gxio_mpipe_credit(iqueue->context, iqueue->ring, bucket, N)".
1218 *
1219 * Note that if your classifier sets "idesc->nr", then you should
1220 * explicitly call "gxio_mpipe_iqueue_advance(iqueue, idesc)" plus
1221 * "gxio_mpipe_credit(iqueue->context, iqueue->ring, -1, 1)", to
1222 * avoid incorrectly crediting the (unused) bucket.
1223 *
1224 * @param iqueue An ingress queue initialized via gxio_mpipe_iqueue_init().
1225 * @param idesc The descriptor which was processed.
1226 */
1227static inline void gxio_mpipe_iqueue_consume(gxio_mpipe_iqueue_t *iqueue,
1228 gxio_mpipe_idesc_t *idesc)
1229{
1230 gxio_mpipe_iqueue_advance(iqueue, 1);
1231 gxio_mpipe_iqueue_release(iqueue, idesc);
1232}
1233
1234/* Peek at the next packet(s) in an "iqueue", without waiting.
1235 *
1236 * If no packets are available, fills idesc_ref with NULL, and then
1237 * returns ::GXIO_MPIPE_ERR_IQUEUE_EMPTY. Otherwise, fills idesc_ref
1238 * with the address of the next valid packet descriptor, and returns
1239 * the maximum number of valid descriptors which can be processed.
1240 * You may process fewer descriptors if desired.
1241 *
1242 * Call gxio_mpipe_iqueue_consume() on each packet once it has been
1243 * processed (or dropped), to allow more packets to be delivered.
1244 *
1245 * @param iqueue An ingress queue initialized via gxio_mpipe_iqueue_init().
1246 * @param idesc_ref A pointer to a packet descriptor pointer.
1247 * @return The (positive) number of packets which can be processed,
1248 * or ::GXIO_MPIPE_ERR_IQUEUE_EMPTY if no packets are available.
1249 */
1250static inline int gxio_mpipe_iqueue_try_peek(gxio_mpipe_iqueue_t *iqueue,
1251 gxio_mpipe_idesc_t **idesc_ref)
1252{
1253 gxio_mpipe_idesc_t *next;
1254
1255 uint64_t head = iqueue->head;
1256 uint64_t tail = __gxio_mmio_read(iqueue->idescs);
1257
1258 /* Available entries. */
1259 uint64_t avail =
1260 (tail >= head) ? (tail - head) : (iqueue->num_entries - head);
1261
1262 if (avail == 0) {
1263 *idesc_ref = NULL;
1264 return GXIO_MPIPE_ERR_IQUEUE_EMPTY;
1265 }
1266
1267 next = &iqueue->idescs[head];
1268
1269 /* ISSUE: Is this helpful? */
1270 __insn_prefetch(next);
1271
1272#ifdef __BIG_ENDIAN__
1273 /* HACK: Swap new entries directly in memory. */
1274 {
1275 int i, j;
1276 for (i = iqueue->swapped; i < avail; i++) {
1277 for (j = 0; j < 8; j++)
1278 next[i].words[j] =
1279 __builtin_bswap64(next[i].words[j]);
1280 }
1281 iqueue->swapped = avail;
1282 }
1283#endif
1284
1285 *idesc_ref = next;
1286
1287 return avail;
1288}
1289
1290/* Drop a packet by pushing its buffer (if appropriate).
1291 *
1292 * NOTE: The caller must still call gxio_mpipe_iqueue_consume() if idesc
1293 * came from gxio_mpipe_iqueue_try_peek() or gxio_mpipe_iqueue_peek().
1294 *
1295 * @param iqueue An ingress queue initialized via gxio_mpipe_iqueue_init().
1296 * @param idesc A packet descriptor.
1297 */
1298static inline void gxio_mpipe_iqueue_drop(gxio_mpipe_iqueue_t *iqueue,
1299 gxio_mpipe_idesc_t *idesc)
1300{
1301 /* FIXME: Handle "chaining" properly. */
1302
1303 if (!idesc->be) {
1304 unsigned char *va = gxio_mpipe_idesc_get_va(idesc);
1305 gxio_mpipe_push_buffer(iqueue->context, idesc->stack_idx, va);
1306 }
1307}
1308
1309/*****************************************************************
1310 * Egress Queue Wrapper *
1311 ******************************************************************/
1312
1313/* A convenient, thread-safe interface to an eDMA ring. */
1314typedef struct {
1315
1316 /* State object for tracking head and tail pointers. */
1317 __gxio_dma_queue_t dma_queue;
1318
1319 /* The ring entries. */
1320 gxio_mpipe_edesc_t *edescs;
1321
1322 /* The number of entries minus one. */
1323 unsigned long mask_num_entries;
1324
1325 /* The log2() of the number of entries. */
1326 unsigned long log2_num_entries;
1327
1328 /* The context. */
1329 gxio_mpipe_context_t *context;
1330
1331 /* The ering. */
1332 unsigned int ering;
1333
1334 /* The channel. */
1335 unsigned int channel;
1336
1337} gxio_mpipe_equeue_t;
1338
1339/* Initialize an "equeue".
1340 *
1341 * This function uses gxio_mpipe_init_edma_ring() to initialize the
1342 * underlying edma_ring using the provided arguments.
1343 *
1344 * @param equeue An egress queue to be initialized.
1345 * @param context An initialized mPIPE context.
1346 * @param ering The eDMA ring index.
1347 * @param channel The channel to use. This must be one of the channels
1348 * associated with the context's set of open links.
1349 * @param mem A physically contiguous region of memory to be filled
1350 * with a ring of ::gxio_mpipe_edesc_t structures.
1351 * @param mem_size Number of bytes in the ring. Must be 512, 2048,
1352 * 8192 or 65536, times 16 (i.e. sizeof(gxio_mpipe_edesc_t)).
1353 * @param mem_flags ::gxio_mpipe_mem_flags_e memory flags.
1354 *
1355 * @return 0 on success, ::GXIO_MPIPE_ERR_BAD_EDMA_RING or
1356 * ::GXIO_ERR_INVAL_MEMORY_SIZE on failure.
1357 */
1358extern int gxio_mpipe_equeue_init(gxio_mpipe_equeue_t *equeue,
1359 gxio_mpipe_context_t *context,
1360 unsigned int ering,
1361 unsigned int channel,
1362 void *mem, unsigned int mem_size,
1363 unsigned int mem_flags);
1364
1365/* Reserve completion slots for edescs.
1366 *
1367 * Use gxio_mpipe_equeue_put_at() to actually populate the slots.
1368 *
1369 * This function is slower than gxio_mpipe_equeue_reserve_fast(), but
1370 * returns a full 64 bit completion slot, which can be used with
1371 * gxio_mpipe_equeue_is_complete().
1372 *
1373 * @param equeue An egress queue initialized via gxio_mpipe_equeue_init().
1374 * @param num Number of slots to reserve (must be non-zero).
1375 * @return The first reserved completion slot, or a negative error code.
1376 */
1377static inline int64_t gxio_mpipe_equeue_reserve(gxio_mpipe_equeue_t *equeue,
1378 unsigned int num)
1379{
1380 return __gxio_dma_queue_reserve_aux(&equeue->dma_queue, num, true);
1381}
1382
1383/* Reserve completion slots for edescs, if possible.
1384 *
1385 * Use gxio_mpipe_equeue_put_at() to actually populate the slots.
1386 *
1387 * This function is slower than gxio_mpipe_equeue_try_reserve_fast(),
1388 * but returns a full 64 bit completion slot, which can be used with
1389 * gxio_mpipe_equeue_is_complete().
1390 *
1391 * @param equeue An egress queue initialized via gxio_mpipe_equeue_init().
1392 * @param num Number of slots to reserve (must be non-zero).
1393 * @return The first reserved completion slot, or a negative error code.
1394 */
1395static inline int64_t gxio_mpipe_equeue_try_reserve(gxio_mpipe_equeue_t
1396 *equeue, unsigned int num)
1397{
1398 return __gxio_dma_queue_reserve_aux(&equeue->dma_queue, num, false);
1399}
1400
1401/* Reserve slots for edescs.
1402 *
1403 * Use gxio_mpipe_equeue_put_at() to actually populate the slots.
1404 *
1405 * This function is faster than gxio_mpipe_equeue_reserve(), but
1406 * returns a 24 bit slot (instead of a 64 bit completion slot), which
1407 * thus cannot be used with gxio_mpipe_equeue_is_complete().
1408 *
1409 * @param equeue An egress queue initialized via gxio_mpipe_equeue_init().
1410 * @param num Number of slots to reserve (should be non-zero).
1411 * @return The first reserved slot, or a negative error code.
1412 */
1413static inline int64_t gxio_mpipe_equeue_reserve_fast(gxio_mpipe_equeue_t
1414 *equeue, unsigned int num)
1415{
1416 return __gxio_dma_queue_reserve(&equeue->dma_queue, num, true, false);
1417}
1418
1419/* Reserve slots for edescs, if possible.
1420 *
1421 * Use gxio_mpipe_equeue_put_at() to actually populate the slots.
1422 *
1423 * This function is faster than gxio_mpipe_equeue_try_reserve(), but
1424 * returns a 24 bit slot (instead of a 64 bit completion slot), which
1425 * thus cannot be used with gxio_mpipe_equeue_is_complete().
1426 *
1427 * @param equeue An egress queue initialized via gxio_mpipe_equeue_init().
1428 * @param num Number of slots to reserve (should be non-zero).
1429 * @return The first reserved slot, or a negative error code.
1430 */
1431static inline int64_t gxio_mpipe_equeue_try_reserve_fast(gxio_mpipe_equeue_t
1432 *equeue,
1433 unsigned int num)
1434{
1435 return __gxio_dma_queue_reserve(&equeue->dma_queue, num, false, false);
1436}
1437
1438/*
1439 * HACK: This helper function tricks gcc 4.6 into avoiding saving
1440 * a copy of "edesc->words[0]" on the stack for no obvious reason.
1441 */
1442
1443static inline void gxio_mpipe_equeue_put_at_aux(gxio_mpipe_equeue_t *equeue,
1444 uint_reg_t ew[2],
1445 unsigned long slot)
1446{
1447 unsigned long edma_slot = slot & equeue->mask_num_entries;
1448 gxio_mpipe_edesc_t *edesc_p = &equeue->edescs[edma_slot];
1449
1450 /*
1451 * ISSUE: Could set eDMA ring to be on generation 1 at start, which
1452 * would avoid the negation here, perhaps allowing "__insn_bfins()".
1453 */
1454 ew[0] |= !((slot >> equeue->log2_num_entries) & 1);
1455
1456 /*
1457 * NOTE: We use "__gxio_mpipe_write()", plus the fact that the eDMA
1458 * queue alignment restrictions ensure that these two words are on
1459 * the same cacheline, to force proper ordering between the stores.
1460 */
1461 __gxio_mmio_write64(&edesc_p->words[1], ew[1]);
1462 __gxio_mmio_write64(&edesc_p->words[0], ew[0]);
1463}
1464
1465/* Post an edesc to a given slot in an equeue.
1466 *
1467 * This function copies the supplied edesc into entry "slot mod N" in
1468 * the underlying ring, setting the "gen" bit to the appropriate value
1469 * based on "(slot mod N*2)", where "N" is the size of the ring. Note
1470 * that the higher bits of slot are unused, and thus, this function
1471 * can handle "slots" as well as "completion slots".
1472 *
1473 * Normally this function is used to fill in slots reserved by
1474 * gxio_mpipe_equeue_try_reserve(), gxio_mpipe_equeue_reserve(),
1475 * gxio_mpipe_equeue_try_reserve_fast(), or
1476 * gxio_mpipe_equeue_reserve_fast(),
1477 *
1478 * This function can also be used without "reserving" slots, if the
1479 * application KNOWS that the ring can never overflow, for example, by
1480 * pushing fewer buffers into the buffer stacks than there are total
1481 * slots in the equeue, but this is NOT recommended.
1482 *
1483 * @param equeue An egress queue initialized via gxio_mpipe_equeue_init().
1484 * @param edesc The egress descriptor to be posted.
1485 * @param slot An egress slot (only the low bits are actually used).
1486 */
1487static inline void gxio_mpipe_equeue_put_at(gxio_mpipe_equeue_t *equeue,
1488 gxio_mpipe_edesc_t edesc,
1489 unsigned long slot)
1490{
1491 gxio_mpipe_equeue_put_at_aux(equeue, edesc.words, slot);
1492}
1493
1494/* Post an edesc to the next slot in an equeue.
1495 *
1496 * This is a convenience wrapper around
1497 * gxio_mpipe_equeue_reserve_fast() and gxio_mpipe_equeue_put_at().
1498 *
1499 * @param equeue An egress queue initialized via gxio_mpipe_equeue_init().
1500 * @param edesc The egress descriptor to be posted.
1501 * @return 0 on success.
1502 */
1503static inline int gxio_mpipe_equeue_put(gxio_mpipe_equeue_t *equeue,
1504 gxio_mpipe_edesc_t edesc)
1505{
1506 int64_t slot = gxio_mpipe_equeue_reserve_fast(equeue, 1);
1507 if (slot < 0)
1508 return (int)slot;
1509
1510 gxio_mpipe_equeue_put_at(equeue, edesc, slot);
1511
1512 return 0;
1513}
1514
1515/* Ask the mPIPE hardware to egress outstanding packets immediately.
1516 *
1517 * This call is not necessary, but may slightly reduce overall latency.
1518 *
1519 * Technically, you should flush all gxio_mpipe_equeue_put_at() writes
1520 * to memory before calling this function, to ensure the descriptors
1521 * are visible in memory before the mPIPE hardware actually looks for
1522 * them. But this should be very rare, and the only side effect would
1523 * be increased latency, so it is up to the caller to decide whether
1524 * or not to flush memory.
1525 *
1526 * @param equeue An egress queue initialized via gxio_mpipe_equeue_init().
1527 */
1528static inline void gxio_mpipe_equeue_flush(gxio_mpipe_equeue_t *equeue)
1529{
1530 /* Use "ring_idx = 0" and "count = 0" to "wake up" the eDMA ring. */
1531 MPIPE_EDMA_POST_REGION_VAL_t val = { {0} };
1532 /* Flush the write buffers. */
1533 __insn_flushwb();
1534 __gxio_mmio_write(equeue->dma_queue.post_region_addr, val.word);
1535}
1536
1537/* Determine if a given edesc has been completed.
1538 *
1539 * Note that this function requires a "completion slot", and thus may
1540 * NOT be used with a "slot" from gxio_mpipe_equeue_reserve_fast() or
1541 * gxio_mpipe_equeue_try_reserve_fast().
1542 *
1543 * @param equeue An egress queue initialized via gxio_mpipe_equeue_init().
1544 * @param completion_slot The completion slot used by the edesc.
1545 * @param update If true, and the desc does not appear to have completed
1546 * yet, then update any software cache of the hardware completion counter,
1547 * and check again. This should normally be true.
1548 * @return True iff the given edesc has been completed.
1549 */
1550static inline int gxio_mpipe_equeue_is_complete(gxio_mpipe_equeue_t *equeue,
1551 int64_t completion_slot,
1552 int update)
1553{
1554 return __gxio_dma_queue_is_complete(&equeue->dma_queue,
1555 completion_slot, update);
1556}
1557
1558/* Set the snf (store and forward) size for an equeue.
1559 *
1560 * The snf size for an equeue defaults to 1536, and encodes the size
1561 * of the largest packet for which egress is guaranteed to avoid
1562 * transmission underruns and/or corrupt checksums under heavy load.
1563 *
1564 * The snf size affects a global resource pool which cannot support,
1565 * for example, all 24 equeues each requesting an snf size of 8K.
1566 *
1567 * To ensure that jumbo packets can be egressed properly, the snf size
1568 * should be set to the size of the largest possible packet, which
1569 * will usually be limited by the size of the app's largest buffer.
1570 *
1571 * This is a convenience wrapper around
1572 * gxio_mpipe_config_edma_ring_blks().
1573 *
1574 * This function should not be called after any egress has been done
1575 * on the equeue.
1576 *
1577 * @param equeue An egress queue initialized via gxio_mpipe_equeue_init().
1578 * @param size The snf size, in bytes.
1579 * @return Zero on success, negative error otherwise.
1580 */
1581static inline int gxio_mpipe_equeue_set_snf_size(gxio_mpipe_equeue_t *equeue,
1582 size_t size)
1583{
1584 int blks = (size + 127) / 128;
1585 return gxio_mpipe_config_edma_ring_blks(equeue->context, equeue->ering,
1586 blks + 1, blks, 1);
1587}
1588
1589/*****************************************************************
1590 * Link Management *
1591 ******************************************************************/
1592
1593/*
1594 *
1595 * Functions for manipulating and sensing the state and configuration
1596 * of physical network links.
1597 *
1598 * @section gxio_mpipe_link_perm Link Permissions
1599 *
1600 * Opening a link (with gxio_mpipe_link_open()) requests a set of link
1601 * permissions, which control what may be done with the link, and potentially
1602 * what permissions may be granted to other processes.
1603 *
1604 * Data permission allows the process to receive packets from the link by
1605 * specifying the link's channel number in mPIPE packet distribution rules,
1606 * and to send packets to the link by using the link's channel number as
1607 * the target for an eDMA ring.
1608 *
1609 * Stats permission allows the process to retrieve link attributes (such as
1610 * the speeds it is capable of running at, or whether it is currently up), and
1611 * to read and write certain statistics-related registers in the link's MAC.
1612 *
1613 * Control permission allows the process to retrieve and modify link attributes
1614 * (so that it may, for example, bring the link up and take it down), and
1615 * read and write many registers in the link's MAC and PHY.
1616 *
1617 * Any permission may be requested as shared, which allows other processes
1618 * to also request shared permission, or exclusive, which prevents other
1619 * processes from requesting it. In keeping with GXIO's typical usage in
1620 * an embedded environment, the defaults for all permissions are shared.
1621 *
1622 * Permissions are granted on a first-come, first-served basis, so if two
1623 * applications request an exclusive permission on the same link, the one
1624 * to run first will win. Note, however, that some system components, like
1625 * the kernel Ethernet driver, may get an opportunity to open links before
1626 * any applications run.
1627 *
1628 * @section gxio_mpipe_link_names Link Names
1629 *
1630 * Link names are of the form gbe<em>number</em> (for Gigabit Ethernet),
1631 * xgbe<em>number</em> (for 10 Gigabit Ethernet), loop<em>number</em> (for
1632 * internal mPIPE loopback), or ilk<em>number</em>/<em>channel</em>
1633 * (for Interlaken links); for instance, gbe0, xgbe1, loop3, and
1634 * ilk0/12 are all possible link names. The correspondence between
1635 * the link name and an mPIPE instance number or mPIPE channel number is
1636 * system-dependent; all links will not exist on all systems, and the set
1637 * of numbers used for a particular link type may not start at zero and may
1638 * not be contiguous. Use gxio_mpipe_link_enumerate() to retrieve the set of
1639 * links which exist on a system, and always use gxio_mpipe_link_instance()
1640 * to determine which mPIPE controls a particular link.
1641 *
1642 * Note that in some cases, links may share hardware, such as PHYs, or
1643 * internal mPIPE buffers; in these cases, only one of the links may be
1644 * opened at a time. This is especially common with xgbe and gbe ports,
1645 * since each xgbe port uses 4 SERDES lanes, each of which may also be
1646 * configured as one gbe port.
1647 *
1648 * @section gxio_mpipe_link_states Link States
1649 *
1650 * The mPIPE link management model revolves around three different states,
1651 * which are maintained for each link:
1652 *
1653 * 1. The <em>current</em> link state: is the link up now, and if so, at
1654 * what speed?
1655 *
1656 * 2. The <em>desired</em> link state: what do we want the link state to be?
1657 * The system is always working to make this state the current state;
1658 * thus, if the desired state is up, and the link is down, we'll be
1659 * constantly trying to bring it up, automatically.
1660 *
1661 * 3. The <em>possible</em> link state: what speeds are valid for this
1662 * particular link? Or, in other words, what are the capabilities of
1663 * the link hardware?
1664 *
1665 * These link states are not, strictly speaking, related to application
1666 * state; they may be manipulated at any time, whether or not the link
1667 * is currently being used for data transfer. However, for convenience,
1668 * gxio_mpipe_link_open() and gxio_mpipe_link_close() (or application exit)
1669 * can affect the link state. These implicit link management operations
1670 * may be modified or disabled by the use of link open flags.
1671 *
1672 * From an application, you can use gxio_mpipe_link_get_attr()
1673 * and gxio_mpipe_link_set_attr() to manipulate the link states.
1674 * gxio_mpipe_link_get_attr() with ::GXIO_MPIPE_LINK_POSSIBLE_STATE
1675 * gets you the possible link state. gxio_mpipe_link_get_attr() with
1676 * ::GXIO_MPIPE_LINK_CURRENT_STATE gets you the current link state.
1677 * Finally, gxio_mpipe_link_set_attr() and gxio_mpipe_link_get_attr()
1678 * with ::GXIO_MPIPE_LINK_DESIRED_STATE allow you to modify or retrieve
1679 * the desired link state.
1680 *
1681 * If you want to manage a link from a part of your application which isn't
1682 * involved in packet processing, you can use the ::GXIO_MPIPE_LINK_NO_DATA
1683 * flags on a gxio_mpipe_link_open() call. This opens the link, but does
1684 * not request data permission, so it does not conflict with any exclusive
1685 * permissions which may be held by other processes. You can then can use
1686 * gxio_mpipe_link_get_attr() and gxio_mpipe_link_set_attr() on this link
1687 * object to bring up or take down the link.
1688 *
1689 * Some links support link state bits which support various loopback
1690 * modes. ::GXIO_MPIPE_LINK_LOOP_MAC tests datapaths within the Tile
1691 * Processor itself; ::GXIO_MPIPE_LINK_LOOP_PHY tests the datapath between
1692 * the Tile Processor and the external physical layer interface chip; and
1693 * ::GXIO_MPIPE_LINK_LOOP_EXT tests the entire network datapath with the
1694 * aid of an external loopback connector. In addition to enabling hardware
1695 * testing, such configuration can be useful for software testing, as well.
1696 *
1697 * When LOOP_MAC or LOOP_PHY is enabled, packets transmitted on a channel
1698 * will be received by that channel, instead of being emitted on the
1699 * physical link, and packets received on the physical link will be ignored.
1700 * Other than that, all standard GXIO operations work as you might expect.
1701 * Note that loopback operation requires that the link be brought up using
1702 * one or more of the GXIO_MPIPE_LINK_SPEED_xxx link state bits.
1703 *
1704 * Those familiar with previous versions of the MDE on TILEPro hardware
1705 * will notice significant similarities between the NetIO link management
1706 * model and the mPIPE link management model. However, the NetIO model
1707 * was developed in stages, and some of its features -- for instance,
1708 * the default setting of certain flags -- were shaped by the need to be
1709 * compatible with previous versions of NetIO. Since the features provided
1710 * by the mPIPE hardware and the mPIPE GXIO library are significantly
1711 * different than those provided by NetIO, in some cases, we have made
1712 * different choices in the mPIPE link management API. Thus, please read
1713 * this documentation carefully before assuming that mPIPE link management
1714 * operations are exactly equivalent to their NetIO counterparts.
1715 */
1716
1717/* An object used to manage mPIPE link state and resources. */
1718typedef struct {
1719 /* The overall mPIPE context. */
1720 gxio_mpipe_context_t *context;
1721
1722 /* The channel number used by this link. */
1723 uint8_t channel;
1724
1725 /* The MAC index used by this link. */
1726 uint8_t mac;
1727} gxio_mpipe_link_t;
1728
1729/* Translate a link name to the instance number of the mPIPE shim which is
1730 * connected to that link. This call does not verify whether the link is
1731 * currently available, and does not reserve any link resources;
1732 * gxio_mpipe_link_open() must be called to perform those functions.
1733 *
1734 * Typically applications will call this function to translate a link name
1735 * to an mPIPE instance number; call gxio_mpipe_init(), passing it that
1736 * instance number, to initialize the mPIPE shim; and then call
1737 * gxio_mpipe_link_open(), passing it the same link name plus the mPIPE
1738 * context, to configure the link.
1739 *
1740 * @param link_name Name of the link; see @ref gxio_mpipe_link_names.
1741 * @return The mPIPE instance number which is associated with the named
1742 * link, or a negative error code (::GXIO_ERR_NO_DEVICE) if the link does
1743 * not exist.
1744 */
1745extern int gxio_mpipe_link_instance(const char *link_name);
1746
1747/* Retrieve one of this system's legal link names, and its MAC address.
1748 *
1749 * @param index Link name index. If a system supports N legal link names,
1750 * then indices between 0 and N - 1, inclusive, each correspond to one of
1751 * those names. Thus, to retrieve all of a system's legal link names,
1752 * call this function in a loop, starting with an index of zero, and
1753 * incrementing it once per iteration until -1 is returned.
1754 * @param link_name Pointer to the buffer which will receive the retrieved
1755 * link name. The buffer should contain space for at least
1756 * ::GXIO_MPIPE_LINK_NAME_LEN bytes; the returned name, including the
1757 * terminating null byte, will be no longer than that.
1758 * @param link_name Pointer to the buffer which will receive the retrieved
1759 * MAC address. The buffer should contain space for at least 6 bytes.
1760 * @return Zero if a link name was successfully retrieved; -1 if one was
1761 * not.
1762 */
1763extern int gxio_mpipe_link_enumerate_mac(int index, char *link_name,
1764 uint8_t *mac_addr);
1765
1766/* Open an mPIPE link.
1767 *
1768 * A link must be opened before it may be used to send or receive packets,
1769 * and before its state may be examined or changed. Depending up on the
1770 * link's intended use, one or more link permissions may be requested via
1771 * the flags parameter; see @ref gxio_mpipe_link_perm. In addition, flags
1772 * may request that the link's state be modified at open time. See @ref
1773 * gxio_mpipe_link_states and @ref gxio_mpipe_link_open_flags for more detail.
1774 *
1775 * @param link A link state object, which will be initialized if this
1776 * function completes successfully.
1777 * @param context An initialized mPIPE context.
1778 * @param link_name Name of the link.
1779 * @param flags Zero or more @ref gxio_mpipe_link_open_flags, ORed together.
1780 * @return 0 if the link was successfully opened, or a negative error code.
1781 *
1782 */
1783extern int gxio_mpipe_link_open(gxio_mpipe_link_t *link,
1784 gxio_mpipe_context_t *context,
1785 const char *link_name, unsigned int flags);
1786
1787/* Close an mPIPE link.
1788 *
1789 * Closing a link makes it available for use by other processes. Once
1790 * a link has been closed, packets may no longer be sent on or received
1791 * from the link, and its state may not be examined or changed.
1792 *
1793 * @param link A link state object, which will no longer be initialized
1794 * if this function completes successfully.
1795 * @return 0 if the link was successfully closed, or a negative error code.
1796 *
1797 */
1798extern int gxio_mpipe_link_close(gxio_mpipe_link_t *link);
1799
1800/* Return a link's channel number.
1801 *
1802 * @param link A properly initialized link state object.
1803 * @return The channel number for the link.
1804 */
1805static inline int gxio_mpipe_link_channel(gxio_mpipe_link_t *link)
1806{
1807 return link->channel;
1808}
1809
1810/* Set a link attribute.
1811 *
1812 * @param link A properly initialized link state object.
1813 * @param attr An attribute from the set of @ref gxio_mpipe_link_attrs.
1814 * @param val New value of the attribute.
1815 * @return 0 if the attribute was successfully set, or a negative error
1816 * code.
1817 */
1818extern int gxio_mpipe_link_set_attr(gxio_mpipe_link_t *link, uint32_t attr,
1819 int64_t val);
1820
1821///////////////////////////////////////////////////////////////////
1822// Timestamp //
1823///////////////////////////////////////////////////////////////////
1824
1825/* Get the timestamp of mPIPE when this routine is called.
1826 *
1827 * @param context An initialized mPIPE context.
1828 * @param ts A timespec structure to store the current clock.
1829 * @return If the call was successful, zero; otherwise, a negative error
1830 * code.
1831 */
1832extern int gxio_mpipe_get_timestamp(gxio_mpipe_context_t *context,
1833 struct timespec64 *ts);
1834
1835/* Set the timestamp of mPIPE.
1836 *
1837 * @param context An initialized mPIPE context.
1838 * @param ts A timespec structure to store the requested clock.
1839 * @return If the call was successful, zero; otherwise, a negative error
1840 * code.
1841 */
1842extern int gxio_mpipe_set_timestamp(gxio_mpipe_context_t *context,
1843 const struct timespec64 *ts);
1844
1845/* Adjust the timestamp of mPIPE.
1846 *
1847 * @param context An initialized mPIPE context.
1848 * @param delta A signed time offset to adjust, in nanoseconds.
1849 * The absolute value of this parameter must be less than or
1850 * equal to 1000000000.
1851 * @return If the call was successful, zero; otherwise, a negative error
1852 * code.
1853 */
1854extern int gxio_mpipe_adjust_timestamp(gxio_mpipe_context_t *context,
1855 int64_t delta);
1856
1857/** Adjust the mPIPE timestamp clock frequency.
1858 *
1859 * @param context An initialized mPIPE context.
1860 * @param ppb A 32-bit signed PPB (Parts Per Billion) value to adjust.
1861 * The absolute value of ppb must be less than or equal to 1000000000.
1862 * Values less than about 30000 will generally cause a GXIO_ERR_INVAL
1863 * return due to the granularity of the hardware that converts reference
1864 * clock cycles into seconds and nanoseconds.
1865 * @return If the call was successful, zero; otherwise, a negative error
1866 * code.
1867 */
1868extern int gxio_mpipe_adjust_timestamp_freq(gxio_mpipe_context_t* context,
1869 int32_t ppb);
1870
1871#endif /* !_GXIO_MPIPE_H_ */
diff --git a/arch/tile/include/gxio/trio.h b/arch/tile/include/gxio/trio.h
deleted file mode 100644
index df10a662cc25..000000000000
--- a/arch/tile/include/gxio/trio.h
+++ /dev/null
@@ -1,298 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/*
16 *
17 * An API for allocating, configuring, and manipulating TRIO hardware
18 * resources
19 */
20
21/*
22 *
23 * The TILE-Gx TRIO shim provides connections to external devices via
24 * PCIe or other transaction IO standards. The gxio_trio_ API,
25 * declared in <gxio/trio.h>, allows applications to allocate and
26 * configure TRIO IO resources like DMA command rings, memory map
27 * windows, and device interrupts. The following sections introduce
28 * the various components of the API. We strongly recommend reading
29 * the TRIO section of the IO Device Guide (UG404) before working with
30 * this API.
31 *
32 * @section trio__ingress TRIO Ingress Hardware Resources
33 *
34 * The TRIO ingress hardware is responsible for examining incoming
35 * PCIe or StreamIO packets and choosing a processing mechanism based
36 * on the packets' bus address. The gxio_trio_ API can be used to
37 * configure different handlers for different ranges of bus address
38 * space. The user can configure "mapped memory" and "scatter queue"
39 * regions to match incoming packets within 4kB-aligned ranges of bus
40 * addresses. Each range specifies a different set of mapping
41 * parameters to be applied when handling the ingress packet. The
42 * following sections describe how to work with MapMem and scatter
43 * queue regions.
44 *
45 * @subsection trio__mapmem TRIO MapMem Regions
46 *
47 * TRIO mapped memory (or MapMem) regions allow the user to map
48 * incoming read and write requests directly to the application's
49 * memory space. MapMem regions are allocated via
50 * gxio_trio_alloc_memory_maps(). Given an integer MapMem number,
51 * applications can use gxio_trio_init_memory_map() to specify the
52 * range of bus addresses that will match the region and the range of
53 * virtual addresses to which those packets will be applied.
54 *
55 * As with many other gxio APIs, the programmer must be sure to
56 * register memory pages that will be used with MapMem regions. Pages
57 * can be registered with TRIO by allocating an ASID (address space
58 * identifier) and then using gxio_trio_register_page() to register up to
59 * 16 pages with the hardware. The initialization functions for
60 * resources that require registered memory (MapMem, scatter queues,
61 * push DMA, and pull DMA) then take an 'asid' parameter in order to
62 * configure which set of registered pages is used by each resource.
63 *
64 * @subsection trio__scatter_queue TRIO Scatter Queues
65 *
66 * The TRIO shim's scatter queue regions allow users to dynamically
67 * map buffers from a large address space into a small range of bus
68 * addresses. This is particularly helpful for PCIe endpoint devices,
69 * where the host generally limits the size of BARs to tens of
70 * megabytes.
71 *
72 * Each scatter queue consists of a memory map region, a queue of
73 * tile-side buffer VAs to be mapped to that region, and a bus-mapped
74 * "doorbell" register that the remote endpoint can write to trigger a
75 * dequeue of the current buffer VA, thus swapping in a new buffer.
76 * The VAs pushed onto a scatter queue must be 4kB aligned, so
77 * applications may need to use higher-level protocols to inform
78 * remote entities that they should apply some additional, sub-4kB
79 * offset when reading or writing the scatter queue region. For more
80 * information, see the IO Device Guide (UG404).
81 *
82 * @section trio__egress TRIO Egress Hardware Resources
83 *
84 * The TRIO shim supports two mechanisms for egress packet generation:
85 * programmed IO (PIO) and push/pull DMA. PIO allows applications to
86 * create MMIO mappings for PCIe or StreamIO address space, such that
87 * the application can generate word-sized read or write transactions
88 * by issuing load or store instructions. Push and pull DMA are tuned
89 * for larger transactions; they use specialized hardware engines to
90 * transfer large blocks of data at line rate.
91 *
92 * @subsection trio__pio TRIO Programmed IO
93 *
94 * Programmed IO allows applications to create MMIO mappings for PCIe
95 * or StreamIO address space. The hardware PIO regions support access
96 * to PCIe configuration, IO, and memory space, but the gxio_trio API
97 * only supports memory space accesses. PIO regions are allocated
98 * with gxio_trio_alloc_pio_regions() and initialized via
99 * gxio_trio_init_pio_region(). Once a region is bound to a range of
100 * bus address via the initialization function, the application can
101 * use gxio_trio_map_pio_region() to create MMIO mappings from its VA
102 * space onto the range of bus addresses supported by the PIO region.
103 *
104 * @subsection trio_dma TRIO Push and Pull DMA
105 *
106 * The TRIO push and pull DMA engines allow users to copy blocks of
107 * data between application memory and the bus. Push DMA generates
108 * write packets that copy from application memory to the bus and pull
109 * DMA generates read packets that copy from the bus into application
110 * memory. The DMA engines are managed via an API that is very
111 * similar to the mPIPE eDMA interface. For a detailed explanation of
112 * the eDMA queue API, see @ref gxio_mpipe_wrappers.
113 *
114 * Push and pull DMA queues are allocated via
115 * gxio_trio_alloc_push_dma_ring() / gxio_trio_alloc_pull_dma_ring().
116 * Once allocated, users generally use a ::gxio_trio_dma_queue_t
117 * object to manage the queue, providing easy wrappers for reserving
118 * command slots in the DMA command ring, filling those slots, and
119 * waiting for commands to complete. DMA queues can be initialized
120 * via gxio_trio_init_push_dma_queue() or
121 * gxio_trio_init_pull_dma_queue().
122 *
123 * See @ref trio/push_dma/app.c for an example of how to use push DMA.
124 *
125 * @section trio_shortcomings Plans for Future API Revisions
126 *
127 * The simulation framework is incomplete. Future features include:
128 *
129 * - Support for reset and deallocation of resources.
130 *
131 * - Support for pull DMA.
132 *
133 * - Support for interrupt regions and user-space interrupt delivery.
134 *
135 * - Support for getting BAR mappings and reserving regions of BAR
136 * address space.
137 */
138#ifndef _GXIO_TRIO_H_
139#define _GXIO_TRIO_H_
140
141#include <linux/types.h>
142
143#include <gxio/common.h>
144#include <gxio/dma_queue.h>
145
146#include <arch/trio_constants.h>
147#include <arch/trio.h>
148#include <arch/trio_pcie_intfc.h>
149#include <arch/trio_pcie_rc.h>
150#include <arch/trio_shm.h>
151#include <hv/drv_trio_intf.h>
152#include <hv/iorpc.h>
153
154/* A context object used to manage TRIO hardware resources. */
155typedef struct {
156
157 /* File descriptor for calling up to Linux (and thus the HV). */
158 int fd;
159
160 /* The VA at which the MAC MMIO registers are mapped. */
161 char *mmio_base_mac;
162
163 /* The VA at which the PIO config space are mapped for each PCIe MAC.
164 Gx36 has max 3 PCIe MACs per TRIO shim. */
165 char *mmio_base_pio_cfg[TILEGX_TRIO_PCIES];
166
167#ifdef USE_SHARED_PCIE_CONFIG_REGION
168 /* Index of the shared PIO region for PCI config access. */
169 int pio_cfg_index;
170#else
171 /* Index of the PIO region for PCI config access per MAC. */
172 int pio_cfg_index[TILEGX_TRIO_PCIES];
173#endif
174
175 /* The VA at which the push DMA MMIO registers are mapped. */
176 char *mmio_push_dma[TRIO_NUM_PUSH_DMA_RINGS];
177
178 /* The VA at which the pull DMA MMIO registers are mapped. */
179 char *mmio_pull_dma[TRIO_NUM_PUSH_DMA_RINGS];
180
181 /* Application space ID. */
182 unsigned int asid;
183
184} gxio_trio_context_t;
185
186/* Command descriptor for push or pull DMA. */
187typedef TRIO_DMA_DESC_t gxio_trio_dma_desc_t;
188
189/* A convenient, thread-safe interface to an eDMA ring. */
190typedef struct {
191
192 /* State object for tracking head and tail pointers. */
193 __gxio_dma_queue_t dma_queue;
194
195 /* The ring entries. */
196 gxio_trio_dma_desc_t *dma_descs;
197
198 /* The number of entries minus one. */
199 unsigned long mask_num_entries;
200
201 /* The log2() of the number of entries. */
202 unsigned int log2_num_entries;
203
204} gxio_trio_dma_queue_t;
205
206/* Initialize a TRIO context.
207 *
208 * This function allocates a TRIO "service domain" and maps the MMIO
209 * registers into the the caller's VA space.
210 *
211 * @param trio_index Which TRIO shim; Gx36 must pass 0.
212 * @param context Context object to be initialized.
213 */
214extern int gxio_trio_init(gxio_trio_context_t *context,
215 unsigned int trio_index);
216
217/* This indicates that an ASID hasn't been allocated. */
218#define GXIO_ASID_NULL -1
219
220/* Ordering modes for map memory regions and scatter queue regions. */
221typedef enum gxio_trio_order_mode_e {
222 /* Writes are not ordered. Reads always wait for previous writes. */
223 GXIO_TRIO_ORDER_MODE_UNORDERED =
224 TRIO_MAP_MEM_SETUP__ORDER_MODE_VAL_UNORDERED,
225 /* Both writes and reads wait for previous transactions to complete. */
226 GXIO_TRIO_ORDER_MODE_STRICT =
227 TRIO_MAP_MEM_SETUP__ORDER_MODE_VAL_STRICT,
228 /* Writes are ordered unless the incoming packet has the
229 relaxed-ordering attributes set. */
230 GXIO_TRIO_ORDER_MODE_OBEY_PACKET =
231 TRIO_MAP_MEM_SETUP__ORDER_MODE_VAL_REL_ORD
232} gxio_trio_order_mode_t;
233
234/* Initialize a memory mapping region.
235 *
236 * @param context An initialized TRIO context.
237 * @param map A Memory map region allocated by gxio_trio_alloc_memory_map().
238 * @param target_mem VA of backing memory, should be registered via
239 * gxio_trio_register_page() and aligned to 4kB.
240 * @param target_size Length of the memory mapping, must be a multiple
241 * of 4kB.
242 * @param asid ASID to be used for Tile-side address translation.
243 * @param mac MAC number.
244 * @param bus_address Bus address at which the mapping starts.
245 * @param order_mode Memory ordering mode for this mapping.
246 * @return Zero on success, else ::GXIO_TRIO_ERR_BAD_MEMORY_MAP,
247 * GXIO_TRIO_ERR_BAD_ASID, or ::GXIO_TRIO_ERR_BAD_BUS_RANGE.
248 */
249extern int gxio_trio_init_memory_map(gxio_trio_context_t *context,
250 unsigned int map, void *target_mem,
251 size_t target_size, unsigned int asid,
252 unsigned int mac, uint64_t bus_address,
253 gxio_trio_order_mode_t order_mode);
254
255/* Flags that can be passed to resource allocation functions. */
256enum gxio_trio_alloc_flags_e {
257 GXIO_TRIO_ALLOC_FIXED = HV_TRIO_ALLOC_FIXED,
258};
259
260/* Flags that can be passed to memory registration functions. */
261enum gxio_trio_mem_flags_e {
262 /* Do not fill L3 when writing, and invalidate lines upon egress. */
263 GXIO_TRIO_MEM_FLAG_NT_HINT = IORPC_MEM_BUFFER_FLAG_NT_HINT,
264
265 /* L3 cache fills should only populate IO cache ways. */
266 GXIO_TRIO_MEM_FLAG_IO_PIN = IORPC_MEM_BUFFER_FLAG_IO_PIN,
267};
268
269/* Flag indicating a request generator uses a special traffic
270 class. */
271#define GXIO_TRIO_FLAG_TRAFFIC_CLASS(N) HV_TRIO_FLAG_TC(N)
272
273/* Flag indicating a request generator uses a virtual function
274 number. */
275#define GXIO_TRIO_FLAG_VFUNC(N) HV_TRIO_FLAG_VFUNC(N)
276
277/*****************************************************************
278 * Memory Registration *
279 ******************************************************************/
280
281/* Allocate Application Space Identifiers (ASIDs). Each ASID can
282 * register up to 16 page translations. ASIDs are used by memory map
283 * regions, scatter queues, and DMA queues to translate application
284 * VAs into memory system PAs.
285 *
286 * @param context An initialized TRIO context.
287 * @param count Number of ASIDs required.
288 * @param first Index of first ASID if ::GXIO_TRIO_ALLOC_FIXED flag
289 * is set, otherwise ignored.
290 * @param flags Flag bits, including bits from ::gxio_trio_alloc_flags_e.
291 * @return Index of first ASID, or ::GXIO_TRIO_ERR_NO_ASID if allocation
292 * failed.
293 */
294extern int gxio_trio_alloc_asids(gxio_trio_context_t *context,
295 unsigned int count, unsigned int first,
296 unsigned int flags);
297
298#endif /* ! _GXIO_TRIO_H_ */
diff --git a/arch/tile/include/gxio/uart.h b/arch/tile/include/gxio/uart.h
deleted file mode 100644
index 438ee7e46c7b..000000000000
--- a/arch/tile/include/gxio/uart.h
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#ifndef _GXIO_UART_H_
16#define _GXIO_UART_H_
17
18#include "common.h"
19
20#include <hv/drv_uart_intf.h>
21#include <hv/iorpc.h>
22
23/*
24 *
25 * An API for manipulating UART interface.
26 */
27
28/*
29 *
30 * The Rshim allows access to the processor's UART interface.
31 */
32
33/* A context object used to manage UART resources. */
34typedef struct {
35
36 /* File descriptor for calling up to the hypervisor. */
37 int fd;
38
39 /* The VA at which our MMIO registers are mapped. */
40 char *mmio_base;
41
42} gxio_uart_context_t;
43
44/* Request UART interrupts.
45 *
46 * Request that interrupts be delivered to a tile when the UART's
47 * Receive FIFO is written, or the Write FIFO is read.
48 *
49 * @param context Pointer to a properly initialized gxio_uart_context_t.
50 * @param bind_cpu_x X coordinate of CPU to which interrupt will be delivered.
51 * @param bind_cpu_y Y coordinate of CPU to which interrupt will be delivered.
52 * @param bind_interrupt IPI interrupt number.
53 * @param bind_event Sub-interrupt event bit number; a negative value can
54 * disable the interrupt.
55 * @return Zero if all of the requested UART events were successfully
56 * configured to interrupt.
57 */
58extern int gxio_uart_cfg_interrupt(gxio_uart_context_t *context,
59 int bind_cpu_x,
60 int bind_cpu_y,
61 int bind_interrupt, int bind_event);
62
63/* Initialize a UART context.
64 *
65 * A properly initialized context must be obtained before any of the other
66 * gxio_uart routines may be used.
67 *
68 * @param context Pointer to a gxio_uart_context_t, which will be initialized
69 * by this routine, if it succeeds.
70 * @param uart_index Index of the UART to use.
71 * @return Zero if the context was successfully initialized, else a
72 * GXIO_ERR_xxx error code.
73 */
74extern int gxio_uart_init(gxio_uart_context_t *context, int uart_index);
75
76/* Destroy a UART context.
77 *
78 * Once destroyed, a context may not be used with any gxio_uart routines
79 * other than gxio_uart_init(). After this routine returns, no further
80 * interrupts requested on this context will be delivered. The state and
81 * configuration of the pins which had been attached to this context are
82 * unchanged by this operation.
83 *
84 * @param context Pointer to a gxio_uart_context_t.
85 * @return Zero if the context was successfully destroyed, else a
86 * GXIO_ERR_xxx error code.
87 */
88extern int gxio_uart_destroy(gxio_uart_context_t *context);
89
90/* Write UART register.
91 * @param context Pointer to a gxio_uart_context_t.
92 * @param offset UART register offset.
93 * @param word Data will be wrote to UART reigister.
94 */
95extern void gxio_uart_write(gxio_uart_context_t *context, uint64_t offset,
96 uint64_t word);
97
98/* Read UART register.
99 * @param context Pointer to a gxio_uart_context_t.
100 * @param offset UART register offset.
101 * @return Data read from UART register.
102 */
103extern uint64_t gxio_uart_read(gxio_uart_context_t *context, uint64_t offset);
104
105#endif /* _GXIO_UART_H_ */
diff --git a/arch/tile/include/gxio/usb_host.h b/arch/tile/include/gxio/usb_host.h
deleted file mode 100644
index 93c9636d2dd7..000000000000
--- a/arch/tile/include/gxio/usb_host.h
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14#ifndef _GXIO_USB_H_
15#define _GXIO_USB_H_
16
17#include <gxio/common.h>
18
19#include <hv/drv_usb_host_intf.h>
20#include <hv/iorpc.h>
21
22/*
23 *
24 * An API for manipulating general-purpose I/O pins.
25 */
26
27/*
28 *
29 * The USB shim allows access to the processor's Universal Serial Bus
30 * connections.
31 */
32
33/* A context object used to manage USB hardware resources. */
34typedef struct {
35
36 /* File descriptor for calling up to the hypervisor. */
37 int fd;
38
39 /* The VA at which our MMIO registers are mapped. */
40 char *mmio_base;
41} gxio_usb_host_context_t;
42
43/* Initialize a USB context.
44 *
45 * A properly initialized context must be obtained before any of the other
46 * gxio_usb_host routines may be used.
47 *
48 * @param context Pointer to a gxio_usb_host_context_t, which will be
49 * initialized by this routine, if it succeeds.
50 * @param usb_index Index of the USB shim to use.
51 * @param is_ehci Nonzero to use the EHCI interface; zero to use the OHCI
52 * intereface.
53 * @return Zero if the context was successfully initialized, else a
54 * GXIO_ERR_xxx error code.
55 */
56extern int gxio_usb_host_init(gxio_usb_host_context_t *context, int usb_index,
57 int is_ehci);
58
59/* Destroy a USB context.
60 *
61 * Once destroyed, a context may not be used with any gxio_usb_host routines
62 * other than gxio_usb_host_init(). After this routine returns, no further
63 * interrupts or signals requested on this context will be delivered. The
64 * state and configuration of the pins which had been attached to this
65 * context are unchanged by this operation.
66 *
67 * @param context Pointer to a gxio_usb_host_context_t.
68 * @return Zero if the context was successfully destroyed, else a
69 * GXIO_ERR_xxx error code.
70 */
71extern int gxio_usb_host_destroy(gxio_usb_host_context_t *context);
72
73/* Retrieve the address of the shim's MMIO registers.
74 *
75 * @param context Pointer to a properly initialized gxio_usb_host_context_t.
76 * @return The address of the shim's MMIO registers.
77 */
78extern void *gxio_usb_host_get_reg_start(gxio_usb_host_context_t *context);
79
80/* Retrieve the length of the shim's MMIO registers.
81 *
82 * @param context Pointer to a properly initialized gxio_usb_host_context_t.
83 * @return The length of the shim's MMIO registers.
84 */
85extern size_t gxio_usb_host_get_reg_len(gxio_usb_host_context_t *context);
86
87#endif /* _GXIO_USB_H_ */
diff --git a/arch/tile/include/hv/drv_mpipe_intf.h b/arch/tile/include/hv/drv_mpipe_intf.h
deleted file mode 100644
index ff7f50f970a5..000000000000
--- a/arch/tile/include/hv/drv_mpipe_intf.h
+++ /dev/null
@@ -1,605 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * Interface definitions for the mpipe driver.
17 */
18
19#ifndef _SYS_HV_DRV_MPIPE_INTF_H
20#define _SYS_HV_DRV_MPIPE_INTF_H
21
22#include <arch/mpipe.h>
23#include <arch/mpipe_constants.h>
24
25
26/** Number of mPIPE instances supported */
27#define HV_MPIPE_INSTANCE_MAX (2)
28
29/** Number of buffer stacks (32). */
30#define HV_MPIPE_NUM_BUFFER_STACKS \
31 (MPIPE_MMIO_INIT_DAT_GX36_1__BUFFER_STACK_MASK_WIDTH)
32
33/** Number of NotifRings (256). */
34#define HV_MPIPE_NUM_NOTIF_RINGS (MPIPE_NUM_NOTIF_RINGS)
35
36/** Number of NotifGroups (32). */
37#define HV_MPIPE_NUM_NOTIF_GROUPS (MPIPE_NUM_NOTIF_GROUPS)
38
39/** Number of buckets (4160). */
40#define HV_MPIPE_NUM_BUCKETS (MPIPE_NUM_BUCKETS)
41
42/** Number of "lo" buckets (4096). */
43#define HV_MPIPE_NUM_LO_BUCKETS 4096
44
45/** Number of "hi" buckets (64). */
46#define HV_MPIPE_NUM_HI_BUCKETS \
47 (HV_MPIPE_NUM_BUCKETS - HV_MPIPE_NUM_LO_BUCKETS)
48
49/** Number of edma rings (24). */
50#define HV_MPIPE_NUM_EDMA_RINGS \
51 (MPIPE_MMIO_INIT_DAT_GX36_1__EDMA_POST_MASK_WIDTH)
52
53
54
55
56/** A flag bit indicating a fixed resource allocation. */
57#define HV_MPIPE_ALLOC_FIXED 0x01
58
59/** Offset for the config register MMIO region. */
60#define HV_MPIPE_CONFIG_MMIO_OFFSET \
61 (MPIPE_MMIO_ADDR__REGION_VAL_CFG << MPIPE_MMIO_ADDR__REGION_SHIFT)
62
63/** Size of the config register MMIO region. */
64#define HV_MPIPE_CONFIG_MMIO_SIZE (64 * 1024)
65
66/** Offset for the config register MMIO region. */
67#define HV_MPIPE_FAST_MMIO_OFFSET \
68 (MPIPE_MMIO_ADDR__REGION_VAL_IDMA << MPIPE_MMIO_ADDR__REGION_SHIFT)
69
70/** Size of the fast register MMIO region (IDMA, EDMA, buffer stack). */
71#define HV_MPIPE_FAST_MMIO_SIZE \
72 ((MPIPE_MMIO_ADDR__REGION_VAL_BSM + 1 - MPIPE_MMIO_ADDR__REGION_VAL_IDMA) \
73 << MPIPE_MMIO_ADDR__REGION_SHIFT)
74
75
76/*
77 * Each type of resource allocation comes in quantized chunks, where
78 * XXX_BITS is the number of chunks, and XXX_RES_PER_BIT is the number
79 * of resources in each chunk.
80 */
81
82/** Number of buffer stack chunks available (32). */
83#define HV_MPIPE_ALLOC_BUFFER_STACKS_BITS \
84 MPIPE_MMIO_INIT_DAT_GX36_1__BUFFER_STACK_MASK_WIDTH
85
86/** Granularity of buffer stack allocation (1). */
87#define HV_MPIPE_ALLOC_BUFFER_STACKS_RES_PER_BIT \
88 (HV_MPIPE_NUM_BUFFER_STACKS / HV_MPIPE_ALLOC_BUFFER_STACKS_BITS)
89
90/** Number of NotifRing chunks available (32). */
91#define HV_MPIPE_ALLOC_NOTIF_RINGS_BITS \
92 MPIPE_MMIO_INIT_DAT_GX36_0__NOTIF_RING_MASK_WIDTH
93
94/** Granularity of NotifRing allocation (8). */
95#define HV_MPIPE_ALLOC_NOTIF_RINGS_RES_PER_BIT \
96 (HV_MPIPE_NUM_NOTIF_RINGS / HV_MPIPE_ALLOC_NOTIF_RINGS_BITS)
97
98/** Number of NotifGroup chunks available (32). */
99#define HV_MPIPE_ALLOC_NOTIF_GROUPS_BITS \
100 HV_MPIPE_NUM_NOTIF_GROUPS
101
102/** Granularity of NotifGroup allocation (1). */
103#define HV_MPIPE_ALLOC_NOTIF_GROUPS_RES_PER_BIT \
104 (HV_MPIPE_NUM_NOTIF_GROUPS / HV_MPIPE_ALLOC_NOTIF_GROUPS_BITS)
105
106/** Number of lo bucket chunks available (16). */
107#define HV_MPIPE_ALLOC_LO_BUCKETS_BITS \
108 MPIPE_MMIO_INIT_DAT_GX36_0__BUCKET_RELEASE_MASK_LO_WIDTH
109
110/** Granularity of lo bucket allocation (256). */
111#define HV_MPIPE_ALLOC_LO_BUCKETS_RES_PER_BIT \
112 (HV_MPIPE_NUM_LO_BUCKETS / HV_MPIPE_ALLOC_LO_BUCKETS_BITS)
113
114/** Number of hi bucket chunks available (16). */
115#define HV_MPIPE_ALLOC_HI_BUCKETS_BITS \
116 MPIPE_MMIO_INIT_DAT_GX36_0__BUCKET_RELEASE_MASK_HI_WIDTH
117
118/** Granularity of hi bucket allocation (4). */
119#define HV_MPIPE_ALLOC_HI_BUCKETS_RES_PER_BIT \
120 (HV_MPIPE_NUM_HI_BUCKETS / HV_MPIPE_ALLOC_HI_BUCKETS_BITS)
121
122/** Number of eDMA ring chunks available (24). */
123#define HV_MPIPE_ALLOC_EDMA_RINGS_BITS \
124 MPIPE_MMIO_INIT_DAT_GX36_1__EDMA_POST_MASK_WIDTH
125
126/** Granularity of eDMA ring allocation (1). */
127#define HV_MPIPE_ALLOC_EDMA_RINGS_RES_PER_BIT \
128 (HV_MPIPE_NUM_EDMA_RINGS / HV_MPIPE_ALLOC_EDMA_RINGS_BITS)
129
130
131
132
133/** Bit vector encoding which NotifRings are in a NotifGroup. */
134typedef struct
135{
136 /** The actual bits. */
137 uint64_t ring_mask[4];
138
139} gxio_mpipe_notif_group_bits_t;
140
141
142/** Another name for MPIPE_LBL_INIT_DAT_BSTS_TBL_t. */
143typedef MPIPE_LBL_INIT_DAT_BSTS_TBL_t gxio_mpipe_bucket_info_t;
144
145
146
147/** Eight buffer stack ids. */
148typedef struct
149{
150 /** The stacks. */
151 uint8_t stacks[8];
152
153} gxio_mpipe_rules_stacks_t;
154
155
156/** A destination mac address. */
157typedef struct
158{
159 /** The octets. */
160 uint8_t octets[6];
161
162} gxio_mpipe_rules_dmac_t;
163
164
165/** A vlan. */
166typedef uint16_t gxio_mpipe_rules_vlan_t;
167
168
169
170/** Maximum number of characters in a link name. */
171#define GXIO_MPIPE_LINK_NAME_LEN 32
172
173
174/** Structure holding a link name. Only needed, and only typedef'ed,
175 * because the IORPC stub generator only handles types which are single
176 * words coming before the parameter name. */
177typedef struct
178{
179 /** The name itself. */
180 char name[GXIO_MPIPE_LINK_NAME_LEN];
181}
182_gxio_mpipe_link_name_t;
183
184/** Maximum number of characters in a symbol name. */
185#define GXIO_MPIPE_SYMBOL_NAME_LEN 128
186
187
188/** Structure holding a symbol name. Only needed, and only typedef'ed,
189 * because the IORPC stub generator only handles types which are single
190 * words coming before the parameter name. */
191typedef struct
192{
193 /** The name itself. */
194 char name[GXIO_MPIPE_SYMBOL_NAME_LEN];
195}
196_gxio_mpipe_symbol_name_t;
197
198
199/** Structure holding a MAC address. */
200typedef struct
201{
202 /** The address. */
203 uint8_t mac[6];
204}
205_gxio_mpipe_link_mac_t;
206
207
208
209/** Request shared data permission -- that is, the ability to send and
210 * receive packets -- on the specified link. Other processes may also
211 * request shared data permission on the same link.
212 *
213 * No more than one of ::GXIO_MPIPE_LINK_DATA, ::GXIO_MPIPE_LINK_NO_DATA,
214 * or ::GXIO_MPIPE_LINK_EXCL_DATA may be specified in a gxio_mpipe_link_open()
215 * call. If none are specified, ::GXIO_MPIPE_LINK_DATA is assumed.
216 */
217#define GXIO_MPIPE_LINK_DATA 0x00000001UL
218
219/** Do not request data permission on the specified link.
220 *
221 * No more than one of ::GXIO_MPIPE_LINK_DATA, ::GXIO_MPIPE_LINK_NO_DATA,
222 * or ::GXIO_MPIPE_LINK_EXCL_DATA may be specified in a gxio_mpipe_link_open()
223 * call. If none are specified, ::GXIO_MPIPE_LINK_DATA is assumed.
224 */
225#define GXIO_MPIPE_LINK_NO_DATA 0x00000002UL
226
227/** Request exclusive data permission -- that is, the ability to send and
228 * receive packets -- on the specified link. No other processes may
229 * request data permission on this link, and if any process already has
230 * data permission on it, this open will fail.
231 *
232 * No more than one of ::GXIO_MPIPE_LINK_DATA, ::GXIO_MPIPE_LINK_NO_DATA,
233 * or ::GXIO_MPIPE_LINK_EXCL_DATA may be specified in a gxio_mpipe_link_open()
234 * call. If none are specified, ::GXIO_MPIPE_LINK_DATA is assumed.
235 */
236#define GXIO_MPIPE_LINK_EXCL_DATA 0x00000004UL
237
238/** Request shared stats permission -- that is, the ability to read and write
239 * registers which contain link statistics, and to get link attributes --
240 * on the specified link. Other processes may also request shared stats
241 * permission on the same link.
242 *
243 * No more than one of ::GXIO_MPIPE_LINK_STATS, ::GXIO_MPIPE_LINK_NO_STATS,
244 * or ::GXIO_MPIPE_LINK_EXCL_STATS may be specified in a gxio_mpipe_link_open()
245 * call. If none are specified, ::GXIO_MPIPE_LINK_STATS is assumed.
246 */
247#define GXIO_MPIPE_LINK_STATS 0x00000008UL
248
249/** Do not request stats permission on the specified link.
250 *
251 * No more than one of ::GXIO_MPIPE_LINK_STATS, ::GXIO_MPIPE_LINK_NO_STATS,
252 * or ::GXIO_MPIPE_LINK_EXCL_STATS may be specified in a gxio_mpipe_link_open()
253 * call. If none are specified, ::GXIO_MPIPE_LINK_STATS is assumed.
254 */
255#define GXIO_MPIPE_LINK_NO_STATS 0x00000010UL
256
257/** Request exclusive stats permission -- that is, the ability to read and
258 * write registers which contain link statistics, and to get link
259 * attributes -- on the specified link. No other processes may request
260 * stats permission on this link, and if any process already
261 * has stats permission on it, this open will fail.
262 *
263 * Requesting exclusive stats permission is normally a very bad idea, since
264 * it prevents programs like mpipe-stat from providing information on this
265 * link. Applications should only do this if they use MAC statistics
266 * registers, and cannot tolerate any of the clear-on-read registers being
267 * reset by other statistics programs.
268 *
269 * No more than one of ::GXIO_MPIPE_LINK_STATS, ::GXIO_MPIPE_LINK_NO_STATS,
270 * or ::GXIO_MPIPE_LINK_EXCL_STATS may be specified in a gxio_mpipe_link_open()
271 * call. If none are specified, ::GXIO_MPIPE_LINK_STATS is assumed.
272 */
273#define GXIO_MPIPE_LINK_EXCL_STATS 0x00000020UL
274
275/** Request shared control permission -- that is, the ability to modify link
276 * attributes, and read and write MAC and MDIO registers -- on the
277 * specified link. Other processes may also request shared control
278 * permission on the same link.
279 *
280 * No more than one of ::GXIO_MPIPE_LINK_CTL, ::GXIO_MPIPE_LINK_NO_CTL,
281 * or ::GXIO_MPIPE_LINK_EXCL_CTL may be specified in a gxio_mpipe_link_open()
282 * call. If none are specified, ::GXIO_MPIPE_LINK_CTL is assumed.
283 */
284#define GXIO_MPIPE_LINK_CTL 0x00000040UL
285
286/** Do not request control permission on the specified link.
287 *
288 * No more than one of ::GXIO_MPIPE_LINK_CTL, ::GXIO_MPIPE_LINK_NO_CTL,
289 * or ::GXIO_MPIPE_LINK_EXCL_CTL may be specified in a gxio_mpipe_link_open()
290 * call. If none are specified, ::GXIO_MPIPE_LINK_CTL is assumed.
291 */
292#define GXIO_MPIPE_LINK_NO_CTL 0x00000080UL
293
294/** Request exclusive control permission -- that is, the ability to modify
295 * link attributes, and read and write MAC and MDIO registers -- on the
296 * specified link. No other processes may request control permission on
297 * this link, and if any process already has control permission on it,
298 * this open will fail.
299 *
300 * Requesting exclusive control permission is not always a good idea, since
301 * it prevents programs like mpipe-link from configuring the link.
302 *
303 * No more than one of ::GXIO_MPIPE_LINK_CTL, ::GXIO_MPIPE_LINK_NO_CTL,
304 * or ::GXIO_MPIPE_LINK_EXCL_CTL may be specified in a gxio_mpipe_link_open()
305 * call. If none are specified, ::GXIO_MPIPE_LINK_CTL is assumed.
306 */
307#define GXIO_MPIPE_LINK_EXCL_CTL 0x00000100UL
308
309/** Set the desired state of the link to up, allowing any speeds which are
310 * supported by the link hardware, as part of this open operation; do not
311 * change the desired state of the link when it is closed or the process
312 * exits. No more than one of ::GXIO_MPIPE_LINK_AUTO_UP,
313 * ::GXIO_MPIPE_LINK_AUTO_UPDOWN, ::GXIO_MPIPE_LINK_AUTO_DOWN, or
314 * ::GXIO_MPIPE_LINK_AUTO_NONE may be specified in a gxio_mpipe_link_open()
315 * call. If none are specified, ::GXIO_MPIPE_LINK_AUTO_UPDOWN is assumed.
316 */
317#define GXIO_MPIPE_LINK_AUTO_UP 0x00000200UL
318
319/** Set the desired state of the link to up, allowing any speeds which are
320 * supported by the link hardware, as part of this open operation; when the
321 * link is closed or this process exits, if no other process has the link
322 * open, set the desired state of the link to down. No more than one of
323 * ::GXIO_MPIPE_LINK_AUTO_UP, ::GXIO_MPIPE_LINK_AUTO_UPDOWN,
324 * ::GXIO_MPIPE_LINK_AUTO_DOWN, or ::GXIO_MPIPE_LINK_AUTO_NONE may be
325 * specified in a gxio_mpipe_link_open() call. If none are specified,
326 * ::GXIO_MPIPE_LINK_AUTO_UPDOWN is assumed.
327 */
328#define GXIO_MPIPE_LINK_AUTO_UPDOWN 0x00000400UL
329
330/** Do not change the desired state of the link as part of the open
331 * operation; when the link is closed or this process exits, if no other
332 * process has the link open, set the desired state of the link to down.
333 * No more than one of ::GXIO_MPIPE_LINK_AUTO_UP,
334 * ::GXIO_MPIPE_LINK_AUTO_UPDOWN, ::GXIO_MPIPE_LINK_AUTO_DOWN, or
335 * ::GXIO_MPIPE_LINK_AUTO_NONE may be specified in a gxio_mpipe_link_open()
336 * call. If none are specified, ::GXIO_MPIPE_LINK_AUTO_UPDOWN is assumed.
337 */
338#define GXIO_MPIPE_LINK_AUTO_DOWN 0x00000800UL
339
340/** Do not change the desired state of the link as part of the open
341 * operation; do not change the desired state of the link when it is
342 * closed or the process exits. No more than one of
343 * ::GXIO_MPIPE_LINK_AUTO_UP, ::GXIO_MPIPE_LINK_AUTO_UPDOWN,
344 * ::GXIO_MPIPE_LINK_AUTO_DOWN, or ::GXIO_MPIPE_LINK_AUTO_NONE may be
345 * specified in a gxio_mpipe_link_open() call. If none are specified,
346 * ::GXIO_MPIPE_LINK_AUTO_UPDOWN is assumed.
347 */
348#define GXIO_MPIPE_LINK_AUTO_NONE 0x00001000UL
349
350/** Request that this open call not complete until the network link is up.
351 * The process will wait as long as necessary for this to happen;
352 * applications which wish to abandon waiting for the link after a
353 * specific time period should not specify this flag when opening a link,
354 * but should instead call gxio_mpipe_link_wait() afterward. The link
355 * must be opened with stats permission. Note that this flag by itself
356 * does not change the desired link state; if other open flags or previous
357 * link state changes have not requested a desired state of up, the open
358 * call will never complete. This flag is not available to kernel
359 * clients.
360 */
361#define GXIO_MPIPE_LINK_WAIT 0x00002000UL
362
363
364/*
365 * Note: link attributes must fit in 24 bits, since we use the top 8 bits
366 * of the IORPC offset word for the channel number.
367 */
368
369/** Determine whether jumbo frames may be received. If this attribute's
370 * value value is nonzero, the MAC will accept frames of up to 10240 bytes.
371 * If the value is zero, the MAC will only accept frames of up to 1544
372 * bytes. The default value is zero. */
373#define GXIO_MPIPE_LINK_RECEIVE_JUMBO 0x010000
374
375/** Determine whether to send pause frames on this link if the mPIPE packet
376 * FIFO is nearly full. If the value is zero, pause frames are not sent.
377 * If the value is nonzero, it is the delay value which will be sent in any
378 * pause frames which are output, in units of 512 bit times.
379 *
380 * Bear in mind that in almost all circumstances, the mPIPE packet FIFO
381 * will never fill up, since mPIPE will empty it as fast as or faster than
382 * the incoming data rate, by either delivering or dropping packets. The
383 * only situation in which this is not true is if the memory and cache
384 * subsystem is extremely heavily loaded, and mPIPE cannot perform DMA of
385 * packet data to memory in a timely fashion. In particular, pause frames
386 * will <em>not</em> be sent if packets cannot be delivered because
387 * NotifRings are full, buckets are full, or buffers are not available in
388 * a buffer stack. */
389#define GXIO_MPIPE_LINK_SEND_PAUSE 0x020000
390
391/** Determine whether to suspend output on the receipt of pause frames.
392 * If the value is nonzero, mPIPE shim will suspend output on the link's
393 * channel when a pause frame is received. If the value is zero, pause
394 * frames will be ignored. The default value is zero. */
395#define GXIO_MPIPE_LINK_RECEIVE_PAUSE 0x030000
396
397/** Interface MAC address. The value is a 6-byte MAC address, in the least
398 * significant 48 bits of the value; in other words, an address which would
399 * be printed as '12:34:56:78:90:AB' in IEEE 802 canonical format would
400 * be returned as 0x12345678ab.
401 *
402 * Depending upon the overall system design, a MAC address may or may not
403 * be available for each interface. Note that the interface's MAC address
404 * does not limit the packets received on its channel, although the
405 * classifier's rules could be configured to do that. Similarly, the MAC
406 * address is not used when transmitting packets, although applications
407 * could certainly decide to use the assigned address as a source MAC
408 * address when doing so. This attribute may only be retrieved with
409 * gxio_mpipe_link_get_attr(); it may not be modified.
410 */
411#define GXIO_MPIPE_LINK_MAC 0x040000
412
413/** Determine whether to discard egress packets on link down. If this value
414 * is nonzero, packets sent on this link while the link is down will be
415 * discarded. If this value is zero, no packets will be sent on this link
416 * while it is down. The default value is one. */
417#define GXIO_MPIPE_LINK_DISCARD_IF_DOWN 0x050000
418
419/** Possible link state. The value is a combination of link state flags,
420 * ORed together, that indicate link modes which are actually supported by
421 * the hardware. This attribute may only be retrieved with
422 * gxio_mpipe_link_get_attr(); it may not be modified. */
423#define GXIO_MPIPE_LINK_POSSIBLE_STATE 0x060000
424
425/** Current link state. The value is a combination of link state flags,
426 * ORed together, that indicate the current state of the hardware. If the
427 * link is down, the value ANDed with ::GXIO_MPIPE_LINK_SPEED will be zero;
428 * if the link is up, the value ANDed with ::GXIO_MPIPE_LINK_SPEED will
429 * result in exactly one of the speed values, indicating the current speed.
430 * This attribute may only be retrieved with gxio_mpipe_link_get_attr(); it
431 * may not be modified. */
432#define GXIO_MPIPE_LINK_CURRENT_STATE 0x070000
433
434/** Desired link state. The value is a conbination of flags, which specify
435 * the desired state for the link. With gxio_mpipe_link_set_attr(), this
436 * will, in the background, attempt to bring up the link using whichever of
437 * the requested flags are reasonable, or take down the link if the flags
438 * are zero. The actual link up or down operation may happen after this
439 * call completes. If the link state changes in the future, the system
440 * will continue to try to get back to the desired link state; for
441 * instance, if the link is brought up successfully, and then the network
442 * cable is disconnected, the link will go down. However, the desired
443 * state of the link is still up, so if the cable is reconnected, the link
444 * will be brought up again.
445 *
446 * With gxio_mpipe_link_set_attr(), this will indicate the desired state
447 * for the link, as set with a previous gxio_mpipe_link_set_attr() call,
448 * or implicitly by a gxio_mpipe_link_open() or link close operation.
449 * This may not reflect the current state of the link; to get that, use
450 * ::GXIO_MPIPE_LINK_CURRENT_STATE.
451 */
452#define GXIO_MPIPE_LINK_DESIRED_STATE 0x080000
453
454
455
456/** Link can run, should run, or is running at 10 Mbps. */
457#define GXIO_MPIPE_LINK_10M 0x0000000000000001UL
458
459/** Link can run, should run, or is running at 100 Mbps. */
460#define GXIO_MPIPE_LINK_100M 0x0000000000000002UL
461
462/** Link can run, should run, or is running at 1 Gbps. */
463#define GXIO_MPIPE_LINK_1G 0x0000000000000004UL
464
465/** Link can run, should run, or is running at 10 Gbps. */
466#define GXIO_MPIPE_LINK_10G 0x0000000000000008UL
467
468/** Link can run, should run, or is running at 20 Gbps. */
469#define GXIO_MPIPE_LINK_20G 0x0000000000000010UL
470
471/** Link can run, should run, or is running at 25 Gbps. */
472#define GXIO_MPIPE_LINK_25G 0x0000000000000020UL
473
474/** Link can run, should run, or is running at 50 Gbps. */
475#define GXIO_MPIPE_LINK_50G 0x0000000000000040UL
476
477/** Link should run at the highest speed supported by the link and by
478 * the device connected to the link. Only usable as a value for
479 * the link's desired state; never returned as a value for the current
480 * or possible states. */
481#define GXIO_MPIPE_LINK_ANYSPEED 0x0000000000000800UL
482
483/** All legal link speeds. This value is provided for use in extracting
484 * the speed-related subset of the link state flags; it is not intended
485 * to be set directly as a value for one of the GXIO_MPIPE_LINK_xxx_STATE
486 * attributes. A link is up or is requested to be up if its current or
487 * desired state, respectively, ANDED with this value, is nonzero. */
488#define GXIO_MPIPE_LINK_SPEED_MASK 0x0000000000000FFFUL
489
490/** Link can run, should run, or is running in MAC loopback mode. This
491 * loops transmitted packets back to the receiver, inside the Tile
492 * Processor. */
493#define GXIO_MPIPE_LINK_LOOP_MAC 0x0000000000001000UL
494
495/** Link can run, should run, or is running in PHY loopback mode. This
496 * loops transmitted packets back to the receiver, inside the external
497 * PHY chip. */
498#define GXIO_MPIPE_LINK_LOOP_PHY 0x0000000000002000UL
499
500/** Link can run, should run, or is running in external loopback mode.
501 * This requires that an external loopback plug be installed on the
502 * Ethernet port. Note that only some links require that this be
503 * configured via the gxio_mpipe_link routines; other links can do
504 * external loopack with the plug and no special configuration. */
505#define GXIO_MPIPE_LINK_LOOP_EXT 0x0000000000004000UL
506
507/** All legal loopback types. */
508#define GXIO_MPIPE_LINK_LOOP_MASK 0x000000000000F000UL
509
510/** Link can run, should run, or is running in full-duplex mode.
511 * If neither ::GXIO_MPIPE_LINK_FDX nor ::GXIO_MPIPE_LINK_HDX are
512 * specified in a set of desired state flags, both are assumed. */
513#define GXIO_MPIPE_LINK_FDX 0x0000000000010000UL
514
515/** Link can run, should run, or is running in half-duplex mode.
516 * If neither ::GXIO_MPIPE_LINK_FDX nor ::GXIO_MPIPE_LINK_HDX are
517 * specified in a set of desired state flags, both are assumed. */
518#define GXIO_MPIPE_LINK_HDX 0x0000000000020000UL
519
520
521/** An individual rule. */
522typedef struct
523{
524 /** The total size. */
525 uint16_t size;
526
527 /** The priority. */
528 int16_t priority;
529
530 /** The "headroom" in each buffer. */
531 uint8_t headroom;
532
533 /** The "tailroom" in each buffer. */
534 uint8_t tailroom;
535
536 /** The "capacity" of the largest buffer. */
537 uint16_t capacity;
538
539 /** The mask for converting a flow hash into a bucket. */
540 uint16_t bucket_mask;
541
542 /** The offset for converting a flow hash into a bucket. */
543 uint16_t bucket_first;
544
545 /** The buffer stack ids. */
546 gxio_mpipe_rules_stacks_t stacks;
547
548 /** The actual channels. */
549 uint32_t channel_bits;
550
551 /** The number of dmacs. */
552 uint16_t num_dmacs;
553
554 /** The number of vlans. */
555 uint16_t num_vlans;
556
557 /** The actual dmacs and vlans. */
558 uint8_t dmacs_and_vlans[];
559
560} gxio_mpipe_rules_rule_t;
561
562
563/** A list of classifier rules. */
564typedef struct
565{
566 /** The offset to the end of the current rule. */
567 uint16_t tail;
568
569 /** The offset to the start of the current rule. */
570 uint16_t head;
571
572 /** The actual rules. */
573 uint8_t rules[4096 - 4];
574
575} gxio_mpipe_rules_list_t;
576
577
578
579
580/** mPIPE statistics structure. These counters include all relevant
581 * events occurring on all links within the mPIPE shim. */
582typedef struct
583{
584 /** Number of ingress packets dropped for any reason. */
585 uint64_t ingress_drops;
586 /** Number of ingress packets dropped because a buffer stack was empty. */
587 uint64_t ingress_drops_no_buf;
588 /** Number of ingress packets dropped or truncated due to lack of space in
589 * the iPkt buffer. */
590 uint64_t ingress_drops_ipkt;
591 /** Number of ingress packets dropped by the classifier or load balancer */
592 uint64_t ingress_drops_cls_lb;
593 /** Total number of ingress packets. */
594 uint64_t ingress_packets;
595 /** Total number of egress packets. */
596 uint64_t egress_packets;
597 /** Total number of ingress bytes. */
598 uint64_t ingress_bytes;
599 /** Total number of egress bytes. */
600 uint64_t egress_bytes;
601}
602gxio_mpipe_stats_t;
603
604
605#endif /* _SYS_HV_DRV_MPIPE_INTF_H */
diff --git a/arch/tile/include/hv/drv_mshim_intf.h b/arch/tile/include/hv/drv_mshim_intf.h
deleted file mode 100644
index c6ef3bdc55cf..000000000000
--- a/arch/tile/include/hv/drv_mshim_intf.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * @file drv_mshim_intf.h
17 * Interface definitions for the Linux EDAC memory controller driver.
18 */
19
20#ifndef _SYS_HV_INCLUDE_DRV_MSHIM_INTF_H
21#define _SYS_HV_INCLUDE_DRV_MSHIM_INTF_H
22
23/** Number of memory controllers in the public API. */
24#define TILE_MAX_MSHIMS 4
25
26/** Memory info under each memory controller. */
27struct mshim_mem_info
28{
29 uint64_t mem_size; /**< Total memory size in bytes. */
30 uint8_t mem_type; /**< Memory type, DDR2 or DDR3. */
31 uint8_t mem_ecc; /**< Memory supports ECC. */
32};
33
34/**
35 * DIMM error structure.
36 * For now, only correctable errors are counted and the mshim doesn't record
37 * the error PA. HV takes panic upon uncorrectable errors.
38 */
39struct mshim_mem_error
40{
41 uint32_t sbe_count; /**< Number of single-bit errors. */
42};
43
44/** Read this offset to get the memory info per mshim. */
45#define MSHIM_MEM_INFO_OFF 0x100
46
47/** Read this offset to check DIMM error. */
48#define MSHIM_MEM_ERROR_OFF 0x200
49
50#endif /* _SYS_HV_INCLUDE_DRV_MSHIM_INTF_H */
diff --git a/arch/tile/include/hv/drv_pcie_rc_intf.h b/arch/tile/include/hv/drv_pcie_rc_intf.h
deleted file mode 100644
index 9bd2243bece0..000000000000
--- a/arch/tile/include/hv/drv_pcie_rc_intf.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * @file drv_pcie_rc_intf.h
17 * Interface definitions for the PCIE Root Complex.
18 */
19
20#ifndef _SYS_HV_DRV_PCIE_RC_INTF_H
21#define _SYS_HV_DRV_PCIE_RC_INTF_H
22
23/** File offset for reading the interrupt base number used for PCIE legacy
24 interrupts and PLX Gen 1 requirement flag */
25#define PCIE_RC_CONFIG_MASK_OFF 0
26
27
28/**
29 * Structure used for obtaining PCIe config information, read from the PCIE
30 * subsystem /ctl file at initialization
31 */
32typedef struct pcie_rc_config
33{
34 int intr; /**< interrupt number used for downcall */
35 int plx_gen1; /**< flag for PLX Gen 1 configuration */
36} pcie_rc_config_t;
37
38#endif /* _SYS_HV_DRV_PCIE_RC_INTF_H */
diff --git a/arch/tile/include/hv/drv_srom_intf.h b/arch/tile/include/hv/drv_srom_intf.h
deleted file mode 100644
index 6395faa6d9e6..000000000000
--- a/arch/tile/include/hv/drv_srom_intf.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * @file drv_srom_intf.h
17 * Interface definitions for the SPI Flash ROM driver.
18 */
19
20#ifndef _SYS_HV_INCLUDE_DRV_SROM_INTF_H
21#define _SYS_HV_INCLUDE_DRV_SROM_INTF_H
22
23/** Read this offset to get the total device size. */
24#define SROM_TOTAL_SIZE_OFF 0xF0000000
25
26/** Read this offset to get the device sector size. */
27#define SROM_SECTOR_SIZE_OFF 0xF0000004
28
29/** Read this offset to get the device page size. */
30#define SROM_PAGE_SIZE_OFF 0xF0000008
31
32/** Write this offset to flush any pending writes. */
33#define SROM_FLUSH_OFF 0xF1000000
34
35/** Write this offset, plus the byte offset of the start of a sector, to
36 * erase a sector. Any write data is ignored, but there must be at least
37 * one byte of write data. Only applies when the driver is in MTD mode.
38 */
39#define SROM_ERASE_OFF 0xF2000000
40
41#endif /* _SYS_HV_INCLUDE_DRV_SROM_INTF_H */
diff --git a/arch/tile/include/hv/drv_trio_intf.h b/arch/tile/include/hv/drv_trio_intf.h
deleted file mode 100644
index 237e04dee66c..000000000000
--- a/arch/tile/include/hv/drv_trio_intf.h
+++ /dev/null
@@ -1,199 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * Interface definitions for the trio driver.
17 */
18
19#ifndef _SYS_HV_DRV_TRIO_INTF_H
20#define _SYS_HV_DRV_TRIO_INTF_H
21
22#include <arch/trio.h>
23
24/** The vendor ID for all Tilera processors. */
25#define TILERA_VENDOR_ID 0x1a41
26
27/** The device ID for the Gx36 processor. */
28#define TILERA_GX36_DEV_ID 0x0200
29
30/** Device ID for our internal bridge when running as RC. */
31#define TILERA_GX36_RC_DEV_ID 0x2000
32
33/** Maximum number of TRIO interfaces. */
34#define TILEGX_NUM_TRIO 2
35
36/** Gx36 has max 3 PCIe MACs per TRIO interface. */
37#define TILEGX_TRIO_PCIES 3
38
39/** Specify port properties for a PCIe MAC. */
40struct pcie_port_property
41{
42 /** If true, the link can be configured in PCIe root complex mode. */
43 uint8_t allow_rc: 1;
44
45 /** If true, the link can be configured in PCIe endpoint mode. */
46 uint8_t allow_ep: 1;
47
48 /** If true, the link can be configured in StreamIO mode. */
49 uint8_t allow_sio: 1;
50
51 /** If true, the link is allowed to support 1-lane operation. Software
52 * will not consider it an error if the link comes up as a x1 link. */
53 uint8_t allow_x1: 1;
54
55 /** If true, the link is allowed to support 2-lane operation. Software
56 * will not consider it an error if the link comes up as a x2 link. */
57 uint8_t allow_x2: 1;
58
59 /** If true, the link is allowed to support 4-lane operation. Software
60 * will not consider it an error if the link comes up as a x4 link. */
61 uint8_t allow_x4: 1;
62
63 /** If true, the link is allowed to support 8-lane operation. Software
64 * will not consider it an error if the link comes up as a x8 link. */
65 uint8_t allow_x8: 1;
66
67 /** If true, this link is connected to a device which may or may not
68 * be present. */
69 uint8_t removable: 1;
70
71};
72
73/** Configurations can be issued to configure a char stream interrupt. */
74typedef enum pcie_stream_intr_config_sel_e
75{
76 /** Interrupt configuration for memory map regions. */
77 MEM_MAP_SEL,
78
79 /** Interrupt configuration for push DMAs. */
80 PUSH_DMA_SEL,
81
82 /** Interrupt configuration for pull DMAs. */
83 PULL_DMA_SEL,
84}
85pcie_stream_intr_config_sel_t;
86
87
88/** The mmap file offset (PA) of the TRIO config region. */
89#define HV_TRIO_CONFIG_OFFSET \
90 ((unsigned long long)TRIO_MMIO_ADDRESS_SPACE__REGION_VAL_CFG << \
91 TRIO_MMIO_ADDRESS_SPACE__REGION_SHIFT)
92
93/** The maximum size of the TRIO config region. */
94#define HV_TRIO_CONFIG_SIZE \
95 (1ULL << TRIO_CFG_REGION_ADDR__REGION_SHIFT)
96
97/** Size of the config region mapped into client. We can't use
98 * TRIO_MMIO_ADDRESS_SPACE__OFFSET_WIDTH because it
99 * will require the kernel to allocate 4GB VA space
100 * from the VMALLOC region which has a total range
101 * of 4GB.
102 */
103#define HV_TRIO_CONFIG_IOREMAP_SIZE \
104 ((uint64_t) 1 << TRIO_CFG_REGION_ADDR__PROT_SHIFT)
105
106/** The mmap file offset (PA) of a scatter queue region. */
107#define HV_TRIO_SQ_OFFSET(queue) \
108 (((unsigned long long)TRIO_MMIO_ADDRESS_SPACE__REGION_VAL_MAP_SQ << \
109 TRIO_MMIO_ADDRESS_SPACE__REGION_SHIFT) | \
110 ((queue) << TRIO_MAP_SQ_REGION_ADDR__SQ_SEL_SHIFT))
111
112/** The maximum size of a scatter queue region. */
113#define HV_TRIO_SQ_SIZE \
114 (1ULL << TRIO_MAP_SQ_REGION_ADDR__SQ_SEL_SHIFT)
115
116
117/** The "hardware MMIO region" of the first PIO region. */
118#define HV_TRIO_FIRST_PIO_REGION 8
119
120/** The mmap file offset (PA) of a PIO region. */
121#define HV_TRIO_PIO_OFFSET(region) \
122 (((unsigned long long)(region) + HV_TRIO_FIRST_PIO_REGION) \
123 << TRIO_PIO_REGIONS_ADDR__REGION_SHIFT)
124
125/** The maximum size of a PIO region. */
126#define HV_TRIO_PIO_SIZE (1ULL << TRIO_PIO_REGIONS_ADDR__ADDR_WIDTH)
127
128
129/** The mmap file offset (PA) of a push DMA region. */
130#define HV_TRIO_PUSH_DMA_OFFSET(ring) \
131 (((unsigned long long)TRIO_MMIO_ADDRESS_SPACE__REGION_VAL_PUSH_DMA << \
132 TRIO_MMIO_ADDRESS_SPACE__REGION_SHIFT) | \
133 ((ring) << TRIO_PUSH_DMA_REGION_ADDR__RING_SEL_SHIFT))
134
135/** The mmap file offset (PA) of a pull DMA region. */
136#define HV_TRIO_PULL_DMA_OFFSET(ring) \
137 (((unsigned long long)TRIO_MMIO_ADDRESS_SPACE__REGION_VAL_PULL_DMA << \
138 TRIO_MMIO_ADDRESS_SPACE__REGION_SHIFT) | \
139 ((ring) << TRIO_PULL_DMA_REGION_ADDR__RING_SEL_SHIFT))
140
141/** The maximum size of a DMA region. */
142#define HV_TRIO_DMA_REGION_SIZE \
143 (1ULL << TRIO_PUSH_DMA_REGION_ADDR__RING_SEL_SHIFT)
144
145
146/** The mmap file offset (PA) of a Mem-Map interrupt region. */
147#define HV_TRIO_MEM_MAP_INTR_OFFSET(map) \
148 (((unsigned long long)TRIO_MMIO_ADDRESS_SPACE__REGION_VAL_MAP_MEM << \
149 TRIO_MMIO_ADDRESS_SPACE__REGION_SHIFT) | \
150 ((map) << TRIO_MAP_MEM_REGION_ADDR__MAP_SEL_SHIFT))
151
152/** The maximum size of a Mem-Map interrupt region. */
153#define HV_TRIO_MEM_MAP_INTR_SIZE \
154 (1ULL << TRIO_MAP_MEM_REGION_ADDR__MAP_SEL_SHIFT)
155
156
157/** A flag bit indicating a fixed resource allocation. */
158#define HV_TRIO_ALLOC_FIXED 0x01
159
160/** TRIO requires that all mappings have 4kB aligned start addresses. */
161#define HV_TRIO_PAGE_SHIFT 12
162
163/** TRIO requires that all mappings have 4kB aligned start addresses. */
164#define HV_TRIO_PAGE_SIZE (1ull << HV_TRIO_PAGE_SHIFT)
165
166
167/* Specify all PCIe port properties for a TRIO. */
168struct pcie_trio_ports_property
169{
170 struct pcie_port_property ports[TILEGX_TRIO_PCIES];
171
172 /** Set if this TRIO belongs to a Gx72 device. */
173 uint8_t is_gx72;
174};
175
176/* Flags indicating traffic class. */
177#define HV_TRIO_FLAG_TC_SHIFT 4
178#define HV_TRIO_FLAG_TC_RMASK 0xf
179#define HV_TRIO_FLAG_TC(N) \
180 ((((N) & HV_TRIO_FLAG_TC_RMASK) + 1) << HV_TRIO_FLAG_TC_SHIFT)
181
182/* Flags indicating virtual functions. */
183#define HV_TRIO_FLAG_VFUNC_SHIFT 8
184#define HV_TRIO_FLAG_VFUNC_RMASK 0xff
185#define HV_TRIO_FLAG_VFUNC(N) \
186 ((((N) & HV_TRIO_FLAG_VFUNC_RMASK) + 1) << HV_TRIO_FLAG_VFUNC_SHIFT)
187
188
189/* Flag indicating an ordered PIO region. */
190#define HV_TRIO_PIO_FLAG_ORDERED (1 << 16)
191
192/* Flags indicating special types of PIO regions. */
193#define HV_TRIO_PIO_FLAG_SPACE_SHIFT 17
194#define HV_TRIO_PIO_FLAG_SPACE_MASK (0x3 << HV_TRIO_PIO_FLAG_SPACE_SHIFT)
195#define HV_TRIO_PIO_FLAG_CONFIG_SPACE (0x1 << HV_TRIO_PIO_FLAG_SPACE_SHIFT)
196#define HV_TRIO_PIO_FLAG_IO_SPACE (0x2 << HV_TRIO_PIO_FLAG_SPACE_SHIFT)
197
198
199#endif /* _SYS_HV_DRV_TRIO_INTF_H */
diff --git a/arch/tile/include/hv/drv_uart_intf.h b/arch/tile/include/hv/drv_uart_intf.h
deleted file mode 100644
index f5379e2404fd..000000000000
--- a/arch/tile/include/hv/drv_uart_intf.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * Interface definitions for the UART driver.
17 */
18
19#ifndef _SYS_HV_DRV_UART_INTF_H
20#define _SYS_HV_DRV_UART_INTF_H
21
22#include <arch/uart.h>
23
24/** Number of UART ports supported. */
25#define TILEGX_UART_NR 2
26
27/** The mmap file offset (PA) of the UART MMIO region. */
28#define HV_UART_MMIO_OFFSET 0
29
30/** The maximum size of the UARTs MMIO region (64K Bytes). */
31#define HV_UART_MMIO_SIZE (1UL << 16)
32
33#endif /* _SYS_HV_DRV_UART_INTF_H */
diff --git a/arch/tile/include/hv/drv_usb_host_intf.h b/arch/tile/include/hv/drv_usb_host_intf.h
deleted file mode 100644
index 24ce774a3f1d..000000000000
--- a/arch/tile/include/hv/drv_usb_host_intf.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * Interface definitions for the USB host driver.
17 */
18
19#ifndef _SYS_HV_DRV_USB_HOST_INTF_H
20#define _SYS_HV_DRV_USB_HOST_INTF_H
21
22#include <arch/usb_host.h>
23
24
25/** Offset for the EHCI register MMIO region. */
26#define HV_USB_HOST_MMIO_OFFSET_EHCI ((uint64_t) USB_HOST_HCCAPBASE_REG)
27
28/** Offset for the OHCI register MMIO region. */
29#define HV_USB_HOST_MMIO_OFFSET_OHCI ((uint64_t) USB_HOST_OHCD_HC_REVISION_REG)
30
31/** Size of the register MMIO region. This turns out to be the same for
32 * both EHCI and OHCI. */
33#define HV_USB_HOST_MMIO_SIZE ((uint64_t) 0x1000)
34
35/** The number of service domains supported by the USB host shim. */
36#define HV_USB_HOST_NUM_SVC_DOM 1
37
38
39#endif /* _SYS_HV_DRV_USB_HOST_INTF_H */
diff --git a/arch/tile/include/hv/drv_xgbe_impl.h b/arch/tile/include/hv/drv_xgbe_impl.h
deleted file mode 100644
index 3a73b2b44913..000000000000
--- a/arch/tile/include/hv/drv_xgbe_impl.h
+++ /dev/null
@@ -1,300 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * @file drivers/xgbe/impl.h
17 * Implementation details for the NetIO library.
18 */
19
20#ifndef __DRV_XGBE_IMPL_H__
21#define __DRV_XGBE_IMPL_H__
22
23#include <hv/netio_errors.h>
24#include <hv/netio_intf.h>
25#include <hv/drv_xgbe_intf.h>
26
27
28/** How many groups we have (log2). */
29#define LOG2_NUM_GROUPS (12)
30/** How many groups we have. */
31#define NUM_GROUPS (1 << LOG2_NUM_GROUPS)
32
33/** Number of output requests we'll buffer per tile. */
34#define EPP_REQS_PER_TILE (32)
35
36/** Words used in an eDMA command without checksum acceleration. */
37#define EDMA_WDS_NO_CSUM 8
38/** Words used in an eDMA command with checksum acceleration. */
39#define EDMA_WDS_CSUM 10
40/** Total available words in the eDMA command FIFO. */
41#define EDMA_WDS_TOTAL 128
42
43
44/*
45 * FIXME: These definitions are internal and should have underscores!
46 * NOTE: The actual numeric values here are intentional and allow us to
47 * optimize the concept "if small ... else if large ... else ...", by
48 * checking for the low bit being set, and then for non-zero.
49 * These are used as array indices, so they must have the values (0, 1, 2)
50 * in some order.
51 */
52#define SIZE_SMALL (1) /**< Small packet queue. */
53#define SIZE_LARGE (2) /**< Large packet queue. */
54#define SIZE_JUMBO (0) /**< Jumbo packet queue. */
55
56/** The number of "SIZE_xxx" values. */
57#define NETIO_NUM_SIZES 3
58
59
60/*
61 * Default numbers of packets for IPP drivers. These values are chosen
62 * such that CIPP1 will not overflow its L2 cache.
63 */
64
65/** The default number of small packets. */
66#define NETIO_DEFAULT_SMALL_PACKETS 2750
67/** The default number of large packets. */
68#define NETIO_DEFAULT_LARGE_PACKETS 2500
69/** The default number of jumbo packets. */
70#define NETIO_DEFAULT_JUMBO_PACKETS 250
71
72
73/** Log2 of the size of a memory arena. */
74#define NETIO_ARENA_SHIFT 24 /* 16 MB */
75/** Size of a memory arena. */
76#define NETIO_ARENA_SIZE (1 << NETIO_ARENA_SHIFT)
77
78
79/** A queue of packets.
80 *
81 * This structure partially defines a queue of packets waiting to be
82 * processed. The queue as a whole is written to by an interrupt handler and
83 * read by non-interrupt code; this data structure is what's touched by the
84 * interrupt handler. The other part of the queue state, the read offset, is
85 * kept in user space, not in hypervisor space, so it is in a separate data
86 * structure.
87 *
88 * The read offset (__packet_receive_read in the user part of the queue
89 * structure) points to the next packet to be read. When the read offset is
90 * equal to the write offset, the queue is empty; therefore the queue must
91 * contain one more slot than the required maximum queue size.
92 *
93 * Here's an example of all 3 state variables and what they mean. All
94 * pointers move left to right.
95 *
96 * @code
97 * I I V V V V I I I I
98 * 0 1 2 3 4 5 6 7 8 9 10
99 * ^ ^ ^ ^
100 * | | |
101 * | | __last_packet_plus_one
102 * | __buffer_write
103 * __packet_receive_read
104 * @endcode
105 *
106 * This queue has 10 slots, and thus can hold 9 packets (_last_packet_plus_one
107 * = 10). The read pointer is at 2, and the write pointer is at 6; thus,
108 * there are valid, unread packets in slots 2, 3, 4, and 5. The remaining
109 * slots are invalid (do not contain a packet).
110 */
111typedef struct {
112 /** Byte offset of the next notify packet to be written: zero for the first
113 * packet on the queue, sizeof (netio_pkt_t) for the second packet on the
114 * queue, etc. */
115 volatile uint32_t __packet_write;
116
117 /** Offset of the packet after the last valid packet (i.e., when any
118 * pointer is incremented to this value, it wraps back to zero). */
119 uint32_t __last_packet_plus_one;
120}
121__netio_packet_queue_t;
122
123
124/** A queue of buffers.
125 *
126 * This structure partially defines a queue of empty buffers which have been
127 * obtained via requests to the IPP. (The elements of the queue are packet
128 * handles, which are transformed into a full netio_pkt_t when the buffer is
129 * retrieved.) The queue as a whole is written to by an interrupt handler and
130 * read by non-interrupt code; this data structure is what's touched by the
131 * interrupt handler. The other parts of the queue state, the read offset and
132 * requested write offset, are kept in user space, not in hypervisor space, so
133 * they are in a separate data structure.
134 *
135 * The read offset (__buffer_read in the user part of the queue structure)
136 * points to the next buffer to be read. When the read offset is equal to the
137 * write offset, the queue is empty; therefore the queue must contain one more
138 * slot than the required maximum queue size.
139 *
140 * The requested write offset (__buffer_requested_write in the user part of
141 * the queue structure) points to the slot which will hold the next buffer we
142 * request from the IPP, once we get around to sending such a request. When
143 * the requested write offset is equal to the write offset, no requests for
144 * new buffers are outstanding; when the requested write offset is one greater
145 * than the read offset, no more requests may be sent.
146 *
147 * Note that, unlike the packet_queue, the buffer_queue places incoming
148 * buffers at decreasing addresses. This makes the check for "is it time to
149 * wrap the buffer pointer" cheaper in the assembly code which receives new
150 * buffers, and means that the value which defines the queue size,
151 * __last_buffer, is different than in the packet queue. Also, the offset
152 * used in the packet_queue is already scaled by the size of a packet; here we
153 * use unscaled slot indices for the offsets. (These differences are
154 * historical, and in the future it's possible that the packet_queue will look
155 * more like this queue.)
156 *
157 * @code
158 * Here's an example of all 4 state variables and what they mean. Remember:
159 * all pointers move right to left.
160 *
161 * V V V I I R R V V V
162 * 0 1 2 3 4 5 6 7 8 9
163 * ^ ^ ^ ^
164 * | | | |
165 * | | | __last_buffer
166 * | | __buffer_write
167 * | __buffer_requested_write
168 * __buffer_read
169 * @endcode
170 *
171 * This queue has 10 slots, and thus can hold 9 buffers (_last_buffer = 9).
172 * The read pointer is at 2, and the write pointer is at 6; thus, there are
173 * valid, unread buffers in slots 2, 1, 0, 9, 8, and 7. The requested write
174 * pointer is at 4; thus, requests have been made to the IPP for buffers which
175 * will be placed in slots 6 and 5 when they arrive. Finally, the remaining
176 * slots are invalid (do not contain a buffer).
177 */
178typedef struct
179{
180 /** Ordinal number of the next buffer to be written: 0 for the first slot in
181 * the queue, 1 for the second slot in the queue, etc. */
182 volatile uint32_t __buffer_write;
183
184 /** Ordinal number of the last buffer (i.e., when any pointer is decremented
185 * below zero, it is reloaded with this value). */
186 uint32_t __last_buffer;
187}
188__netio_buffer_queue_t;
189
190
191/**
192 * An object for providing Ethernet packets to a process.
193 */
194typedef struct __netio_queue_impl_t
195{
196 /** The queue of packets waiting to be received. */
197 __netio_packet_queue_t __packet_receive_queue;
198 /** The intr bit mask that IDs this device. */
199 unsigned int __intr_id;
200 /** Offset to queues of empty buffers, one per size. */
201 uint32_t __buffer_queue[NETIO_NUM_SIZES];
202 /** The address of the first EPP tile, or -1 if no EPP. */
203 /* ISSUE: Actually this is always "0" or "~0". */
204 uint32_t __epp_location;
205 /** The queue ID that this queue represents. */
206 unsigned int __queue_id;
207 /** Number of acknowledgements received. */
208 volatile uint32_t __acks_received;
209 /** Last completion number received for packet_sendv. */
210 volatile uint32_t __last_completion_rcv;
211 /** Number of packets allowed to be outstanding. */
212 uint32_t __max_outstanding;
213 /** First VA available for packets. */
214 void* __va_0;
215 /** First VA in second range available for packets. */
216 void* __va_1;
217 /** Padding to align the "__packets" field to the size of a netio_pkt_t. */
218 uint32_t __padding[3];
219 /** The packets themselves. */
220 netio_pkt_t __packets[0];
221}
222netio_queue_impl_t;
223
224
225/**
226 * An object for managing the user end of a NetIO queue.
227 */
228typedef struct __netio_queue_user_impl_t
229{
230 /** The next incoming packet to be read. */
231 uint32_t __packet_receive_read;
232 /** The next empty buffers to be read, one index per size. */
233 uint8_t __buffer_read[NETIO_NUM_SIZES];
234 /** Where the empty buffer we next request from the IPP will go, one index
235 * per size. */
236 uint8_t __buffer_requested_write[NETIO_NUM_SIZES];
237 /** PCIe interface flag. */
238 uint8_t __pcie;
239 /** Number of packets left to be received before we send a credit update. */
240 uint32_t __receive_credit_remaining;
241 /** Value placed in __receive_credit_remaining when it reaches zero. */
242 uint32_t __receive_credit_interval;
243 /** First fast I/O routine index. */
244 uint32_t __fastio_index;
245 /** Number of acknowledgements expected. */
246 uint32_t __acks_outstanding;
247 /** Last completion number requested. */
248 uint32_t __last_completion_req;
249 /** File descriptor for driver. */
250 int __fd;
251}
252netio_queue_user_impl_t;
253
254
255#define NETIO_GROUP_CHUNK_SIZE 64 /**< Max # groups in one IPP request */
256#define NETIO_BUCKET_CHUNK_SIZE 64 /**< Max # buckets in one IPP request */
257
258
259/** Internal structure used to convey packet send information to the
260 * hypervisor. FIXME: Actually, it's not used for that anymore, but
261 * netio_packet_send() still uses it internally.
262 */
263typedef struct
264{
265 uint16_t flags; /**< Packet flags (__NETIO_SEND_FLG_xxx) */
266 uint16_t transfer_size; /**< Size of packet */
267 uint32_t va; /**< VA of start of packet */
268 __netio_pkt_handle_t handle; /**< Packet handle */
269 uint32_t csum0; /**< First checksum word */
270 uint32_t csum1; /**< Second checksum word */
271}
272__netio_send_cmd_t;
273
274
275/** Flags used in two contexts:
276 * - As the "flags" member in the __netio_send_cmd_t, above; used only
277 * for netio_pkt_send_{prepare,commit}.
278 * - As part of the flags passed to the various send packet fast I/O calls.
279 */
280
281/** Need acknowledgement on this packet. Note that some code in the
282 * normal send_pkt fast I/O handler assumes that this is equal to 1. */
283#define __NETIO_SEND_FLG_ACK 0x1
284
285/** Do checksum on this packet. (Only used with the __netio_send_cmd_t;
286 * normal packet sends use a special fast I/O index to denote checksumming,
287 * and multi-segment sends test the checksum descriptor.) */
288#define __NETIO_SEND_FLG_CSUM 0x2
289
290/** Get a completion on this packet. Only used with multi-segment sends. */
291#define __NETIO_SEND_FLG_COMPLETION 0x4
292
293/** Position of the number-of-extra-segments value in the flags word.
294 Only used with multi-segment sends. */
295#define __NETIO_SEND_FLG_XSEG_SHIFT 3
296
297/** Width of the number-of-extra-segments value in the flags word. */
298#define __NETIO_SEND_FLG_XSEG_WIDTH 2
299
300#endif /* __DRV_XGBE_IMPL_H__ */
diff --git a/arch/tile/include/hv/drv_xgbe_intf.h b/arch/tile/include/hv/drv_xgbe_intf.h
deleted file mode 100644
index 2a20b266d944..000000000000
--- a/arch/tile/include/hv/drv_xgbe_intf.h
+++ /dev/null
@@ -1,615 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * @file drv_xgbe_intf.h
17 * Interface to the hypervisor XGBE driver.
18 */
19
20#ifndef __DRV_XGBE_INTF_H__
21#define __DRV_XGBE_INTF_H__
22
23/**
24 * An object for forwarding VAs and PAs to the hypervisor.
25 * @ingroup types
26 *
27 * This allows the supervisor to specify a number of areas of memory to
28 * store packet buffers.
29 */
30typedef struct
31{
32 /** The physical address of the memory. */
33 HV_PhysAddr pa;
34 /** Page table entry for the memory. This is only used to derive the
35 * memory's caching mode; the PA bits are ignored. */
36 HV_PTE pte;
37 /** The virtual address of the memory. */
38 HV_VirtAddr va;
39 /** Size (in bytes) of the memory area. */
40 int size;
41
42}
43netio_ipp_address_t;
44
45/** The various pread/pwrite offsets into the hypervisor-level driver.
46 * @ingroup types
47 */
48typedef enum
49{
50 /** Inform the Linux driver of the address of the NetIO arena memory.
51 * This offset is actually only used to convey information from netio
52 * to the Linux driver; it never makes it from there to the hypervisor.
53 * Write-only; takes a uint32_t specifying the VA address. */
54 NETIO_FIXED_ADDR = 0x5000000000000000ULL,
55
56 /** Inform the Linux driver of the size of the NetIO arena memory.
57 * This offset is actually only used to convey information from netio
58 * to the Linux driver; it never makes it from there to the hypervisor.
59 * Write-only; takes a uint32_t specifying the VA size. */
60 NETIO_FIXED_SIZE = 0x5100000000000000ULL,
61
62 /** Register current tile with IPP. Write then read: write, takes a
63 * netio_input_config_t, read returns a pointer to a netio_queue_impl_t. */
64 NETIO_IPP_INPUT_REGISTER_OFF = 0x6000000000000000ULL,
65
66 /** Unregister current tile from IPP. Write-only, takes a dummy argument. */
67 NETIO_IPP_INPUT_UNREGISTER_OFF = 0x6100000000000000ULL,
68
69 /** Start packets flowing. Write-only, takes a dummy argument. */
70 NETIO_IPP_INPUT_INIT_OFF = 0x6200000000000000ULL,
71
72 /** Stop packets flowing. Write-only, takes a dummy argument. */
73 NETIO_IPP_INPUT_UNINIT_OFF = 0x6300000000000000ULL,
74
75 /** Configure group (typically we group on VLAN). Write-only: takes an
76 * array of netio_group_t's, low 24 bits of the offset is the base group
77 * number times the size of a netio_group_t. */
78 NETIO_IPP_INPUT_GROUP_CFG_OFF = 0x6400000000000000ULL,
79
80 /** Configure bucket. Write-only: takes an array of netio_bucket_t's, low
81 * 24 bits of the offset is the base bucket number times the size of a
82 * netio_bucket_t. */
83 NETIO_IPP_INPUT_BUCKET_CFG_OFF = 0x6500000000000000ULL,
84
85 /** Get/set a parameter. Read or write: read or write data is the parameter
86 * value, low 32 bits of the offset is a __netio_getset_offset_t. */
87 NETIO_IPP_PARAM_OFF = 0x6600000000000000ULL,
88
89 /** Get fast I/O index. Read-only; returns a 4-byte base index value. */
90 NETIO_IPP_GET_FASTIO_OFF = 0x6700000000000000ULL,
91
92 /** Configure hijack IP address. Packets with this IPv4 dest address
93 * go to bucket NETIO_NUM_BUCKETS - 1. Write-only: takes an IP address
94 * in some standard form. FIXME: Define the form! */
95 NETIO_IPP_INPUT_HIJACK_CFG_OFF = 0x6800000000000000ULL,
96
97 /**
98 * Offsets beyond this point are reserved for the supervisor (although that
99 * enforcement must be done by the supervisor driver itself).
100 */
101 NETIO_IPP_USER_MAX_OFF = 0x6FFFFFFFFFFFFFFFULL,
102
103 /** Register I/O memory. Write-only, takes a netio_ipp_address_t. */
104 NETIO_IPP_IOMEM_REGISTER_OFF = 0x7000000000000000ULL,
105
106 /** Unregister I/O memory. Write-only, takes a netio_ipp_address_t. */
107 NETIO_IPP_IOMEM_UNREGISTER_OFF = 0x7100000000000000ULL,
108
109 /* Offsets greater than 0x7FFFFFFF can't be used directly from Linux
110 * userspace code due to limitations in the pread/pwrite syscalls. */
111
112 /** Drain LIPP buffers. */
113 NETIO_IPP_DRAIN_OFF = 0xFA00000000000000ULL,
114
115 /** Supply a netio_ipp_address_t to be used as shared memory for the
116 * LEPP command queue. */
117 NETIO_EPP_SHM_OFF = 0xFB00000000000000ULL,
118
119 /* 0xFC... is currently unused. */
120
121 /** Stop IPP/EPP tiles. Write-only, takes a dummy argument. */
122 NETIO_IPP_STOP_SHIM_OFF = 0xFD00000000000000ULL,
123
124 /** Start IPP/EPP tiles. Write-only, takes a dummy argument. */
125 NETIO_IPP_START_SHIM_OFF = 0xFE00000000000000ULL,
126
127 /** Supply packet arena. Write-only, takes an array of
128 * netio_ipp_address_t values. */
129 NETIO_IPP_ADDRESS_OFF = 0xFF00000000000000ULL,
130} netio_hv_offset_t;
131
132/** Extract the base offset from an offset */
133#define NETIO_BASE_OFFSET(off) ((off) & 0xFF00000000000000ULL)
134/** Extract the local offset from an offset */
135#define NETIO_LOCAL_OFFSET(off) ((off) & 0x00FFFFFFFFFFFFFFULL)
136
137
138/**
139 * Get/set offset.
140 */
141typedef union
142{
143 struct
144 {
145 uint64_t addr:48; /**< Class-specific address */
146 unsigned int class:8; /**< Class (e.g., NETIO_PARAM) */
147 unsigned int opcode:8; /**< High 8 bits of NETIO_IPP_PARAM_OFF */
148 }
149 bits; /**< Bitfields */
150 uint64_t word; /**< Aggregated value to use as the offset */
151}
152__netio_getset_offset_t;
153
154/**
155 * Fast I/O index offsets (must be contiguous).
156 */
157typedef enum
158{
159 NETIO_FASTIO_ALLOCATE = 0, /**< Get empty packet buffer */
160 NETIO_FASTIO_FREE_BUFFER = 1, /**< Give buffer back to IPP */
161 NETIO_FASTIO_RETURN_CREDITS = 2, /**< Give credits to IPP */
162 NETIO_FASTIO_SEND_PKT_NOCK = 3, /**< Send a packet, no checksum */
163 NETIO_FASTIO_SEND_PKT_CK = 4, /**< Send a packet, with checksum */
164 NETIO_FASTIO_SEND_PKT_VEC = 5, /**< Send a vector of packets */
165 NETIO_FASTIO_SENDV_PKT = 6, /**< Sendv one packet */
166 NETIO_FASTIO_NUM_INDEX = 7, /**< Total number of fast I/O indices */
167} netio_fastio_index_t;
168
169/** 3-word return type for Fast I/O call. */
170typedef struct
171{
172 int err; /**< Error code. */
173 uint32_t val0; /**< Value. Meaning depends upon the specific call. */
174 uint32_t val1; /**< Value. Meaning depends upon the specific call. */
175} netio_fastio_rv3_t;
176
177/** 0-argument fast I/O call */
178int __netio_fastio0(uint32_t fastio_index);
179/** 1-argument fast I/O call */
180int __netio_fastio1(uint32_t fastio_index, uint32_t arg0);
181/** 3-argument fast I/O call, 2-word return value */
182netio_fastio_rv3_t __netio_fastio3_rv3(uint32_t fastio_index, uint32_t arg0,
183 uint32_t arg1, uint32_t arg2);
184/** 4-argument fast I/O call */
185int __netio_fastio4(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
186 uint32_t arg2, uint32_t arg3);
187/** 6-argument fast I/O call */
188int __netio_fastio6(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
189 uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5);
190/** 9-argument fast I/O call */
191int __netio_fastio9(uint32_t fastio_index, uint32_t arg0, uint32_t arg1,
192 uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5,
193 uint32_t arg6, uint32_t arg7, uint32_t arg8);
194
195/** Allocate an empty packet.
196 * @param fastio_index Fast I/O index.
197 * @param size Size of the packet to allocate.
198 */
199#define __netio_fastio_allocate(fastio_index, size) \
200 __netio_fastio1((fastio_index) + NETIO_FASTIO_ALLOCATE, size)
201
202/** Free a buffer.
203 * @param fastio_index Fast I/O index.
204 * @param handle Handle for the packet to free.
205 */
206#define __netio_fastio_free_buffer(fastio_index, handle) \
207 __netio_fastio1((fastio_index) + NETIO_FASTIO_FREE_BUFFER, handle)
208
209/** Increment our receive credits.
210 * @param fastio_index Fast I/O index.
211 * @param credits Number of credits to add.
212 */
213#define __netio_fastio_return_credits(fastio_index, credits) \
214 __netio_fastio1((fastio_index) + NETIO_FASTIO_RETURN_CREDITS, credits)
215
216/** Send packet, no checksum.
217 * @param fastio_index Fast I/O index.
218 * @param ackflag Nonzero if we want an ack.
219 * @param size Size of the packet.
220 * @param va Virtual address of start of packet.
221 * @param handle Packet handle.
222 */
223#define __netio_fastio_send_pkt_nock(fastio_index, ackflag, size, va, handle) \
224 __netio_fastio4((fastio_index) + NETIO_FASTIO_SEND_PKT_NOCK, ackflag, \
225 size, va, handle)
226
227/** Send packet, calculate checksum.
228 * @param fastio_index Fast I/O index.
229 * @param ackflag Nonzero if we want an ack.
230 * @param size Size of the packet.
231 * @param va Virtual address of start of packet.
232 * @param handle Packet handle.
233 * @param csum0 Shim checksum header.
234 * @param csum1 Checksum seed.
235 */
236#define __netio_fastio_send_pkt_ck(fastio_index, ackflag, size, va, handle, \
237 csum0, csum1) \
238 __netio_fastio6((fastio_index) + NETIO_FASTIO_SEND_PKT_CK, ackflag, \
239 size, va, handle, csum0, csum1)
240
241
242/** Format for the "csum0" argument to the __netio_fastio_send routines
243 * and LEPP. Note that this is currently exactly identical to the
244 * ShimProtocolOffloadHeader.
245 */
246typedef union
247{
248 struct
249 {
250 unsigned int start_byte:7; /**< The first byte to be checksummed */
251 unsigned int count:14; /**< Number of bytes to be checksummed. */
252 unsigned int destination_byte:7; /**< The byte to write the checksum to. */
253 unsigned int reserved:4; /**< Reserved. */
254 } bits; /**< Decomposed method of access. */
255 unsigned int word; /**< To send out the IDN. */
256} __netio_checksum_header_t;
257
258
259/** Sendv packet with 1 or 2 segments.
260 * @param fastio_index Fast I/O index.
261 * @param flags Ack/csum/notify flags in low 3 bits; number of segments minus
262 * 1 in next 2 bits; expected checksum in high 16 bits.
263 * @param confno Confirmation number to request, if notify flag set.
264 * @param csum0 Checksum descriptor; if zero, no checksum.
265 * @param va_F Virtual address of first segment.
266 * @param va_L Virtual address of last segment, if 2 segments.
267 * @param len_F_L Length of first segment in low 16 bits; length of last
268 * segment, if 2 segments, in high 16 bits.
269 */
270#define __netio_fastio_sendv_pkt_1_2(fastio_index, flags, confno, csum0, \
271 va_F, va_L, len_F_L) \
272 __netio_fastio6((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \
273 csum0, va_F, va_L, len_F_L)
274
275/** Send packet on PCIe interface.
276 * @param fastio_index Fast I/O index.
277 * @param flags Ack/csum/notify flags in low 3 bits.
278 * @param confno Confirmation number to request, if notify flag set.
279 * @param csum0 Checksum descriptor; Hard wired 0, not needed for PCIe.
280 * @param va_F Virtual address of the packet buffer.
281 * @param va_L Virtual address of last segment, if 2 segments. Hard wired 0.
282 * @param len_F_L Length of the packet buffer in low 16 bits.
283 */
284#define __netio_fastio_send_pcie_pkt(fastio_index, flags, confno, csum0, \
285 va_F, va_L, len_F_L) \
286 __netio_fastio6((fastio_index) + PCIE_FASTIO_SENDV_PKT, flags, confno, \
287 csum0, va_F, va_L, len_F_L)
288
289/** Sendv packet with 3 or 4 segments.
290 * @param fastio_index Fast I/O index.
291 * @param flags Ack/csum/notify flags in low 3 bits; number of segments minus
292 * 1 in next 2 bits; expected checksum in high 16 bits.
293 * @param confno Confirmation number to request, if notify flag set.
294 * @param csum0 Checksum descriptor; if zero, no checksum.
295 * @param va_F Virtual address of first segment.
296 * @param va_L Virtual address of last segment (third segment if 3 segments,
297 * fourth segment if 4 segments).
298 * @param len_F_L Length of first segment in low 16 bits; length of last
299 * segment in high 16 bits.
300 * @param va_M0 Virtual address of "middle 0" segment; this segment is sent
301 * second when there are three segments, and third if there are four.
302 * @param va_M1 Virtual address of "middle 1" segment; this segment is sent
303 * second when there are four segments.
304 * @param len_M0_M1 Length of middle 0 segment in low 16 bits; length of middle
305 * 1 segment, if 4 segments, in high 16 bits.
306 */
307#define __netio_fastio_sendv_pkt_3_4(fastio_index, flags, confno, csum0, va_F, \
308 va_L, len_F_L, va_M0, va_M1, len_M0_M1) \
309 __netio_fastio9((fastio_index) + NETIO_FASTIO_SENDV_PKT, flags, confno, \
310 csum0, va_F, va_L, len_F_L, va_M0, va_M1, len_M0_M1)
311
312/** Send vector of packets.
313 * @param fastio_index Fast I/O index.
314 * @param seqno Number of packets transmitted so far on this interface;
315 * used to decide which packets should be acknowledged.
316 * @param nentries Number of entries in vector.
317 * @param va Virtual address of start of vector entry array.
318 * @return 3-word netio_fastio_rv3_t structure. The structure's err member
319 * is an error code, or zero if no error. The val0 member is the
320 * updated value of seqno; it has been incremented by 1 for each
321 * packet sent. That increment may be less than nentries if an
322 * error occurred, or if some of the entries in the vector contain
323 * handles equal to NETIO_PKT_HANDLE_NONE. The val1 member is the
324 * updated value of nentries; it has been decremented by 1 for each
325 * vector entry processed. Again, that decrement may be less than
326 * nentries (leaving the returned value positive) if an error
327 * occurred.
328 */
329#define __netio_fastio_send_pkt_vec(fastio_index, seqno, nentries, va) \
330 __netio_fastio3_rv3((fastio_index) + NETIO_FASTIO_SEND_PKT_VEC, seqno, \
331 nentries, va)
332
333
334/** An egress DMA command for LEPP. */
335typedef struct
336{
337 /** Is this a TSO transfer?
338 *
339 * NOTE: This field is always 0, to distinguish it from
340 * lepp_tso_cmd_t. It must come first!
341 */
342 uint8_t tso : 1;
343
344 /** Unused padding bits. */
345 uint8_t _unused : 3;
346
347 /** Should this packet be sent directly from caches instead of DRAM,
348 * using hash-for-home to locate the packet data?
349 */
350 uint8_t hash_for_home : 1;
351
352 /** Should we compute a checksum? */
353 uint8_t compute_checksum : 1;
354
355 /** Is this the final buffer for this packet?
356 *
357 * A single packet can be split over several input buffers (a "gather"
358 * operation). This flag indicates that this is the last buffer
359 * in a packet.
360 */
361 uint8_t end_of_packet : 1;
362
363 /** Should LEPP advance 'comp_busy' when this DMA is fully finished? */
364 uint8_t send_completion : 1;
365
366 /** High bits of Client Physical Address of the start of the buffer
367 * to be egressed.
368 *
369 * NOTE: Only 6 bits are actually needed here, as CPAs are
370 * currently 38 bits. So two bits could be scavenged from this.
371 */
372 uint8_t cpa_hi;
373
374 /** The number of bytes to be egressed. */
375 uint16_t length;
376
377 /** Low 32 bits of Client Physical Address of the start of the buffer
378 * to be egressed.
379 */
380 uint32_t cpa_lo;
381
382 /** Checksum information (only used if 'compute_checksum'). */
383 __netio_checksum_header_t checksum_data;
384
385} lepp_cmd_t;
386
387
388/** A chunk of physical memory for a TSO egress. */
389typedef struct
390{
391 /** The low bits of the CPA. */
392 uint32_t cpa_lo;
393 /** The high bits of the CPA. */
394 uint16_t cpa_hi : 15;
395 /** Should this packet be sent directly from caches instead of DRAM,
396 * using hash-for-home to locate the packet data?
397 */
398 uint16_t hash_for_home : 1;
399 /** The length in bytes. */
400 uint16_t length;
401} lepp_frag_t;
402
403
404/** An LEPP command that handles TSO. */
405typedef struct
406{
407 /** Is this a TSO transfer?
408 *
409 * NOTE: This field is always 1, to distinguish it from
410 * lepp_cmd_t. It must come first!
411 */
412 uint8_t tso : 1;
413
414 /** Unused padding bits. */
415 uint8_t _unused : 7;
416
417 /** Size of the header[] array in bytes. It must be in the range
418 * [40, 127], which are the smallest header for a TCP packet over
419 * Ethernet and the maximum possible prepend size supported by
420 * hardware, respectively. Note that the array storage must be
421 * padded out to a multiple of four bytes so that the following
422 * LEPP command is aligned properly.
423 */
424 uint8_t header_size;
425
426 /** Byte offset of the IP header in header[]. */
427 uint8_t ip_offset;
428
429 /** Byte offset of the TCP header in header[]. */
430 uint8_t tcp_offset;
431
432 /** The number of bytes to use for the payload of each packet,
433 * except of course the last one, which may not have enough bytes.
434 * This means that each Ethernet packet except the last will have a
435 * size of header_size + payload_size.
436 */
437 uint16_t payload_size;
438
439 /** The length of the 'frags' array that follows this struct. */
440 uint16_t num_frags;
441
442 /** The actual frags. */
443 lepp_frag_t frags[0 /* Variable-sized; num_frags entries. */];
444
445 /*
446 * The packet header template logically follows frags[],
447 * but you can't declare that in C.
448 *
449 * uint32_t header[header_size_in_words_rounded_up];
450 */
451
452} lepp_tso_cmd_t;
453
454
455/** An LEPP completion ring entry. */
456typedef void* lepp_comp_t;
457
458
459/** Maximum number of frags for one TSO command. This is adapted from
460 * linux's "MAX_SKB_FRAGS", and presumably over-estimates by one, for
461 * our page size of exactly 65536. We add one for a "body" fragment.
462 */
463#define LEPP_MAX_FRAGS (65536 / HV_DEFAULT_PAGE_SIZE_SMALL + 2 + 1)
464
465/** Total number of bytes needed for an lepp_tso_cmd_t. */
466#define LEPP_TSO_CMD_SIZE(num_frags, header_size) \
467 (sizeof(lepp_tso_cmd_t) + \
468 (num_frags) * sizeof(lepp_frag_t) + \
469 (((header_size) + 3) & -4))
470
471/** The size of the lepp "cmd" queue. */
472#define LEPP_CMD_QUEUE_BYTES \
473 (((CHIP_L2_CACHE_SIZE() - 2 * CHIP_L2_LINE_SIZE()) / \
474 (sizeof(lepp_cmd_t) + sizeof(lepp_comp_t))) * sizeof(lepp_cmd_t))
475
476/** The largest possible command that can go in lepp_queue_t::cmds[]. */
477#define LEPP_MAX_CMD_SIZE LEPP_TSO_CMD_SIZE(LEPP_MAX_FRAGS, 128)
478
479/** The largest possible value of lepp_queue_t::cmd_{head, tail} (inclusive).
480 */
481#define LEPP_CMD_LIMIT \
482 (LEPP_CMD_QUEUE_BYTES - LEPP_MAX_CMD_SIZE)
483
484/** The maximum number of completions in an LEPP queue. */
485#define LEPP_COMP_QUEUE_SIZE \
486 ((LEPP_CMD_LIMIT + sizeof(lepp_cmd_t) - 1) / sizeof(lepp_cmd_t))
487
488/** Increment an index modulo the queue size. */
489#define LEPP_QINC(var) \
490 (var = __insn_mnz(var - (LEPP_COMP_QUEUE_SIZE - 1), var + 1))
491
492/** A queue used to convey egress commands from the client to LEPP. */
493typedef struct
494{
495 /** Index of first completion not yet processed by user code.
496 * If this is equal to comp_busy, there are no such completions.
497 *
498 * NOTE: This is only read/written by the user.
499 */
500 unsigned int comp_head;
501
502 /** Index of first completion record not yet completed.
503 * If this is equal to comp_tail, there are no such completions.
504 * This index gets advanced (modulo LEPP_QUEUE_SIZE) whenever
505 * a command with the 'completion' bit set is finished.
506 *
507 * NOTE: This is only written by LEPP, only read by the user.
508 */
509 volatile unsigned int comp_busy;
510
511 /** Index of the first empty slot in the completion ring.
512 * Entries from this up to but not including comp_head (in ring order)
513 * can be filled in with completion data.
514 *
515 * NOTE: This is only read/written by the user.
516 */
517 unsigned int comp_tail;
518
519 /** Byte index of first command enqueued for LEPP but not yet processed.
520 *
521 * This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.
522 *
523 * NOTE: LEPP advances this counter as soon as it no longer needs
524 * the cmds[] storage for this entry, but the transfer is not actually
525 * complete (i.e. the buffer pointed to by the command is no longer
526 * needed) until comp_busy advances.
527 *
528 * If this is equal to cmd_tail, the ring is empty.
529 *
530 * NOTE: This is only written by LEPP, only read by the user.
531 */
532 volatile unsigned int cmd_head;
533
534 /** Byte index of first empty slot in the command ring. This field can
535 * be incremented up to but not equal to cmd_head (because that would
536 * mean the ring is empty).
537 *
538 * This is always divisible by sizeof(void*) and always <= LEPP_CMD_LIMIT.
539 *
540 * NOTE: This is read/written by the user, only read by LEPP.
541 */
542 volatile unsigned int cmd_tail;
543
544 /** A ring of variable-sized egress DMA commands.
545 *
546 * NOTE: Only written by the user, only read by LEPP.
547 */
548 char cmds[LEPP_CMD_QUEUE_BYTES]
549 __attribute__((aligned(CHIP_L2_LINE_SIZE())));
550
551 /** A ring of user completion data.
552 * NOTE: Only read/written by the user.
553 */
554 lepp_comp_t comps[LEPP_COMP_QUEUE_SIZE]
555 __attribute__((aligned(CHIP_L2_LINE_SIZE())));
556} lepp_queue_t;
557
558
559/** An internal helper function for determining the number of entries
560 * available in a ring buffer, given that there is one sentinel.
561 */
562static inline unsigned int
563_lepp_num_free_slots(unsigned int head, unsigned int tail)
564{
565 /*
566 * One entry is reserved for use as a sentinel, to distinguish
567 * "empty" from "full". So we compute
568 * (head - tail - 1) % LEPP_QUEUE_SIZE, but without using a slow % operation.
569 */
570 return (head - tail - 1) + ((head <= tail) ? LEPP_COMP_QUEUE_SIZE : 0);
571}
572
573
574/** Returns how many new comp entries can be enqueued. */
575static inline unsigned int
576lepp_num_free_comp_slots(const lepp_queue_t* q)
577{
578 return _lepp_num_free_slots(q->comp_head, q->comp_tail);
579}
580
581static inline int
582lepp_qsub(int v1, int v2)
583{
584 int delta = v1 - v2;
585 return delta + ((delta >> 31) & LEPP_COMP_QUEUE_SIZE);
586}
587
588
589/** FIXME: Check this from linux, via a new "pwrite()" call. */
590#define LIPP_VERSION 1
591
592
593/** We use exactly two bytes of alignment padding. */
594#define LIPP_PACKET_PADDING 2
595
596/** The minimum size of a "small" buffer (including the padding). */
597#define LIPP_SMALL_PACKET_SIZE 128
598
599/*
600 * NOTE: The following two values should total to less than around
601 * 13582, to keep the total size used for "lipp_state_t" below 64K.
602 */
603
604/** The maximum number of "small" buffers.
605 * This is enough for 53 network cpus with 128 credits. Note that
606 * if these are exhausted, we will fall back to using large buffers.
607 */
608#define LIPP_SMALL_BUFFERS 6785
609
610/** The maximum number of "large" buffers.
611 * This is enough for 53 network cpus with 128 credits.
612 */
613#define LIPP_LARGE_BUFFERS 6785
614
615#endif /* __DRV_XGBE_INTF_H__ */
diff --git a/arch/tile/include/hv/hypervisor.h b/arch/tile/include/hv/hypervisor.h
deleted file mode 100644
index f10b332b3b65..000000000000
--- a/arch/tile/include/hv/hypervisor.h
+++ /dev/null
@@ -1,2656 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * @file hypervisor.h
17 * The hypervisor's public API.
18 */
19
20#ifndef _HV_HV_H
21#define _HV_HV_H
22
23#include <arch/chip.h>
24
25/* Linux builds want unsigned long constants, but assembler wants numbers */
26#ifdef __ASSEMBLER__
27/** One, for assembler */
28#define __HV_SIZE_ONE 1
29#elif !defined(__tile__) && CHIP_VA_WIDTH() > 32
30/** One, for 64-bit on host */
31#define __HV_SIZE_ONE 1ULL
32#else
33/** One, for Linux */
34#define __HV_SIZE_ONE 1UL
35#endif
36
37/** The log2 of the span of a level-1 page table, in bytes.
38 */
39#define HV_LOG2_L1_SPAN 32
40
41/** The span of a level-1 page table, in bytes.
42 */
43#define HV_L1_SPAN (__HV_SIZE_ONE << HV_LOG2_L1_SPAN)
44
45/** The log2 of the initial size of small pages, in bytes.
46 * See HV_DEFAULT_PAGE_SIZE_SMALL.
47 */
48#define HV_LOG2_DEFAULT_PAGE_SIZE_SMALL 16
49
50/** The initial size of small pages, in bytes. This value should be verified
51 * at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL).
52 * It may also be modified when installing a new context.
53 */
54#define HV_DEFAULT_PAGE_SIZE_SMALL \
55 (__HV_SIZE_ONE << HV_LOG2_DEFAULT_PAGE_SIZE_SMALL)
56
57/** The log2 of the initial size of large pages, in bytes.
58 * See HV_DEFAULT_PAGE_SIZE_LARGE.
59 */
60#define HV_LOG2_DEFAULT_PAGE_SIZE_LARGE 24
61
62/** The initial size of large pages, in bytes. This value should be verified
63 * at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE).
64 * It may also be modified when installing a new context.
65 */
66#define HV_DEFAULT_PAGE_SIZE_LARGE \
67 (__HV_SIZE_ONE << HV_LOG2_DEFAULT_PAGE_SIZE_LARGE)
68
69#if CHIP_VA_WIDTH() > 32
70
71/** The log2 of the initial size of jumbo pages, in bytes.
72 * See HV_DEFAULT_PAGE_SIZE_JUMBO.
73 */
74#define HV_LOG2_DEFAULT_PAGE_SIZE_JUMBO 32
75
76/** The initial size of jumbo pages, in bytes. This value should
77 * be verified at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_JUMBO).
78 * It may also be modified when installing a new context.
79 */
80#define HV_DEFAULT_PAGE_SIZE_JUMBO \
81 (__HV_SIZE_ONE << HV_LOG2_DEFAULT_PAGE_SIZE_JUMBO)
82
83#endif
84
85/** The log2 of the granularity at which page tables must be aligned;
86 * in other words, the CPA for a page table must have this many zero
87 * bits at the bottom of the address.
88 */
89#define HV_LOG2_PAGE_TABLE_ALIGN 11
90
91/** The granularity at which page tables must be aligned.
92 */
93#define HV_PAGE_TABLE_ALIGN (__HV_SIZE_ONE << HV_LOG2_PAGE_TABLE_ALIGN)
94
95/** Normal start of hypervisor glue in client physical memory. */
96#define HV_GLUE_START_CPA 0x10000
97
98/** This much space is reserved at HV_GLUE_START_CPA
99 * for the hypervisor glue. The client program must start at
100 * some address higher than this, and in particular the address of
101 * its text section should be equal to zero modulo HV_PAGE_SIZE_LARGE
102 * so that relative offsets to the HV glue are correct.
103 */
104#define HV_GLUE_RESERVED_SIZE 0x10000
105
106/** Each entry in the hv dispatch array takes this many bytes. */
107#define HV_DISPATCH_ENTRY_SIZE 32
108
109/** Version of the hypervisor interface defined by this file */
110#define _HV_VERSION 13
111
112/** Last version of the hypervisor interface with old hv_init() ABI.
113 *
114 * The change from version 12 to version 13 corresponds to launching
115 * the client by default at PL2 instead of PL1 (corresponding to the
116 * hv itself running at PL3 instead of PL2). To make this explicit,
117 * the hv_init() API was also extended so the client can report its
118 * desired PL, resulting in a more helpful failure diagnostic. If you
119 * call hv_init() with _HV_VERSION_OLD_HV_INIT and omit the client_pl
120 * argument, the hypervisor will assume client_pl = 1.
121 *
122 * Note that this is a deprecated solution and we do not expect to
123 * support clients of the Tilera hypervisor running at PL1 indefinitely.
124 */
125#define _HV_VERSION_OLD_HV_INIT 12
126
127/* Index into hypervisor interface dispatch code blocks.
128 *
129 * Hypervisor calls are invoked from user space by calling code
130 * at an address HV_BASE_ADDRESS + (index) * HV_DISPATCH_ENTRY_SIZE,
131 * where index is one of these enum values.
132 *
133 * Normally a supervisor is expected to produce a set of symbols
134 * starting at HV_BASE_ADDRESS that obey this convention, but a user
135 * program could call directly through function pointers if desired.
136 *
137 * These numbers are part of the binary API and will not be changed
138 * without updating HV_VERSION, which should be a rare event.
139 */
140
141/** reserved. */
142#define _HV_DISPATCH_RESERVED 0
143
144/** hv_init */
145#define HV_DISPATCH_INIT 1
146
147/** hv_install_context */
148#define HV_DISPATCH_INSTALL_CONTEXT 2
149
150/** hv_sysconf */
151#define HV_DISPATCH_SYSCONF 3
152
153/** hv_get_rtc */
154#define HV_DISPATCH_GET_RTC 4
155
156/** hv_set_rtc */
157#define HV_DISPATCH_SET_RTC 5
158
159/** hv_flush_asid */
160#define HV_DISPATCH_FLUSH_ASID 6
161
162/** hv_flush_page */
163#define HV_DISPATCH_FLUSH_PAGE 7
164
165/** hv_flush_pages */
166#define HV_DISPATCH_FLUSH_PAGES 8
167
168/** hv_restart */
169#define HV_DISPATCH_RESTART 9
170
171/** hv_halt */
172#define HV_DISPATCH_HALT 10
173
174/** hv_power_off */
175#define HV_DISPATCH_POWER_OFF 11
176
177/** hv_inquire_physical */
178#define HV_DISPATCH_INQUIRE_PHYSICAL 12
179
180/** hv_inquire_memory_controller */
181#define HV_DISPATCH_INQUIRE_MEMORY_CONTROLLER 13
182
183/** hv_inquire_virtual */
184#define HV_DISPATCH_INQUIRE_VIRTUAL 14
185
186/** hv_inquire_asid */
187#define HV_DISPATCH_INQUIRE_ASID 15
188
189/** hv_nanosleep */
190#define HV_DISPATCH_NANOSLEEP 16
191
192/** hv_console_read_if_ready */
193#define HV_DISPATCH_CONSOLE_READ_IF_READY 17
194
195/** hv_console_write */
196#define HV_DISPATCH_CONSOLE_WRITE 18
197
198/** hv_downcall_dispatch */
199#define HV_DISPATCH_DOWNCALL_DISPATCH 19
200
201/** hv_inquire_topology */
202#define HV_DISPATCH_INQUIRE_TOPOLOGY 20
203
204/** hv_fs_findfile */
205#define HV_DISPATCH_FS_FINDFILE 21
206
207/** hv_fs_fstat */
208#define HV_DISPATCH_FS_FSTAT 22
209
210/** hv_fs_pread */
211#define HV_DISPATCH_FS_PREAD 23
212
213/** hv_physaddr_read64 */
214#define HV_DISPATCH_PHYSADDR_READ64 24
215
216/** hv_physaddr_write64 */
217#define HV_DISPATCH_PHYSADDR_WRITE64 25
218
219/** hv_get_command_line */
220#define HV_DISPATCH_GET_COMMAND_LINE 26
221
222/** hv_set_caching */
223#define HV_DISPATCH_SET_CACHING 27
224
225/** hv_bzero_page */
226#define HV_DISPATCH_BZERO_PAGE 28
227
228/** hv_register_message_state */
229#define HV_DISPATCH_REGISTER_MESSAGE_STATE 29
230
231/** hv_send_message */
232#define HV_DISPATCH_SEND_MESSAGE 30
233
234/** hv_receive_message */
235#define HV_DISPATCH_RECEIVE_MESSAGE 31
236
237/** hv_inquire_context */
238#define HV_DISPATCH_INQUIRE_CONTEXT 32
239
240/** hv_start_all_tiles */
241#define HV_DISPATCH_START_ALL_TILES 33
242
243/** hv_dev_open */
244#define HV_DISPATCH_DEV_OPEN 34
245
246/** hv_dev_close */
247#define HV_DISPATCH_DEV_CLOSE 35
248
249/** hv_dev_pread */
250#define HV_DISPATCH_DEV_PREAD 36
251
252/** hv_dev_pwrite */
253#define HV_DISPATCH_DEV_PWRITE 37
254
255/** hv_dev_poll */
256#define HV_DISPATCH_DEV_POLL 38
257
258/** hv_dev_poll_cancel */
259#define HV_DISPATCH_DEV_POLL_CANCEL 39
260
261/** hv_dev_preada */
262#define HV_DISPATCH_DEV_PREADA 40
263
264/** hv_dev_pwritea */
265#define HV_DISPATCH_DEV_PWRITEA 41
266
267/** hv_flush_remote */
268#define HV_DISPATCH_FLUSH_REMOTE 42
269
270/** hv_console_putc */
271#define HV_DISPATCH_CONSOLE_PUTC 43
272
273/** hv_inquire_tiles */
274#define HV_DISPATCH_INQUIRE_TILES 44
275
276/** hv_confstr */
277#define HV_DISPATCH_CONFSTR 45
278
279/** hv_reexec */
280#define HV_DISPATCH_REEXEC 46
281
282/** hv_set_command_line */
283#define HV_DISPATCH_SET_COMMAND_LINE 47
284
285#if !CHIP_HAS_IPI()
286
287/** hv_clear_intr */
288#define HV_DISPATCH_CLEAR_INTR 48
289
290/** hv_enable_intr */
291#define HV_DISPATCH_ENABLE_INTR 49
292
293/** hv_disable_intr */
294#define HV_DISPATCH_DISABLE_INTR 50
295
296/** hv_raise_intr */
297#define HV_DISPATCH_RAISE_INTR 51
298
299/** hv_trigger_ipi */
300#define HV_DISPATCH_TRIGGER_IPI 52
301
302#endif /* !CHIP_HAS_IPI() */
303
304/** hv_store_mapping */
305#define HV_DISPATCH_STORE_MAPPING 53
306
307/** hv_inquire_realpa */
308#define HV_DISPATCH_INQUIRE_REALPA 54
309
310/** hv_flush_all */
311#define HV_DISPATCH_FLUSH_ALL 55
312
313#if CHIP_HAS_IPI()
314/** hv_get_ipi_pte */
315#define HV_DISPATCH_GET_IPI_PTE 56
316#endif
317
318/** hv_set_pte_super_shift */
319#define HV_DISPATCH_SET_PTE_SUPER_SHIFT 57
320
321/** hv_console_set_ipi */
322#define HV_DISPATCH_CONSOLE_SET_IPI 63
323
324/** hv_send_nmi */
325#define HV_DISPATCH_SEND_NMI 65
326
327/** One more than the largest dispatch value */
328#define _HV_DISPATCH_END 66
329
330
331#ifndef __ASSEMBLER__
332
333#ifdef __KERNEL__
334#include <asm/types.h>
335typedef u32 __hv32; /**< 32-bit value */
336typedef u64 __hv64; /**< 64-bit value */
337#else
338#include <stdint.h>
339typedef uint32_t __hv32; /**< 32-bit value */
340typedef uint64_t __hv64; /**< 64-bit value */
341#endif
342
343
344/** Hypervisor physical address. */
345typedef __hv64 HV_PhysAddr;
346
347#if CHIP_VA_WIDTH() > 32
348/** Hypervisor virtual address. */
349typedef __hv64 HV_VirtAddr;
350#else
351/** Hypervisor virtual address. */
352typedef __hv32 HV_VirtAddr;
353#endif /* CHIP_VA_WIDTH() > 32 */
354
355/** Hypervisor ASID. */
356typedef unsigned int HV_ASID;
357
358/** Hypervisor tile location for a memory access
359 * ("location overridden target").
360 */
361typedef unsigned int HV_LOTAR;
362
363/** Hypervisor size of a page. */
364typedef unsigned long HV_PageSize;
365
366/** A page table entry.
367 */
368typedef struct
369{
370 __hv64 val; /**< Value of PTE */
371} HV_PTE;
372
373/** Hypervisor error code. */
374typedef int HV_Errno;
375
376#endif /* !__ASSEMBLER__ */
377
378#define HV_OK 0 /**< No error */
379#define HV_EINVAL -801 /**< Invalid argument */
380#define HV_ENODEV -802 /**< No such device */
381#define HV_ENOENT -803 /**< No such file or directory */
382#define HV_EBADF -804 /**< Bad file number */
383#define HV_EFAULT -805 /**< Bad address */
384#define HV_ERECIP -806 /**< Bad recipients */
385#define HV_E2BIG -807 /**< Message too big */
386#define HV_ENOTSUP -808 /**< Service not supported */
387#define HV_EBUSY -809 /**< Device busy */
388#define HV_ENOSYS -810 /**< Invalid syscall */
389#define HV_EPERM -811 /**< No permission */
390#define HV_ENOTREADY -812 /**< Device not ready */
391#define HV_EIO -813 /**< I/O error */
392#define HV_ENOMEM -814 /**< Out of memory */
393#define HV_EAGAIN -815 /**< Try again */
394
395#define HV_ERR_MAX -801 /**< Largest HV error code */
396#define HV_ERR_MIN -815 /**< Smallest HV error code */
397
398#ifndef __ASSEMBLER__
399
400/** Pass HV_VERSION to hv_init to request this version of the interface. */
401typedef enum {
402 HV_VERSION = _HV_VERSION,
403 HV_VERSION_OLD_HV_INIT = _HV_VERSION_OLD_HV_INIT,
404
405} HV_VersionNumber;
406
407/** Initializes the hypervisor.
408 *
409 * @param interface_version_number The version of the hypervisor interface
410 * that this program expects, typically HV_VERSION.
411 * @param chip_num Architecture number of the chip the client was built for.
412 * @param chip_rev_num Revision number of the chip the client was built for.
413 * @param client_pl Privilege level the client is built for
414 * (not required if interface_version_number == HV_VERSION_OLD_HV_INIT).
415 */
416void hv_init(HV_VersionNumber interface_version_number,
417 int chip_num, int chip_rev_num, int client_pl);
418
419
420/** Queries we can make for hv_sysconf().
421 *
422 * These numbers are part of the binary API and guaranteed not to change.
423 */
424typedef enum {
425 /** An invalid value; do not use. */
426 _HV_SYSCONF_RESERVED = 0,
427
428 /** The length of the glue section containing the hv_ procs, in bytes. */
429 HV_SYSCONF_GLUE_SIZE = 1,
430
431 /** The size of small pages, in bytes. */
432 HV_SYSCONF_PAGE_SIZE_SMALL = 2,
433
434 /** The size of large pages, in bytes. */
435 HV_SYSCONF_PAGE_SIZE_LARGE = 3,
436
437 /** Processor clock speed, in hertz. */
438 HV_SYSCONF_CPU_SPEED = 4,
439
440 /** Processor temperature, in degrees Kelvin. The value
441 * HV_SYSCONF_TEMP_KTOC may be subtracted from this to get degrees
442 * Celsius. If that Celsius value is HV_SYSCONF_OVERTEMP, this indicates
443 * that the temperature has hit an upper limit and is no longer being
444 * accurately tracked.
445 */
446 HV_SYSCONF_CPU_TEMP = 5,
447
448 /** Board temperature, in degrees Kelvin. The value
449 * HV_SYSCONF_TEMP_KTOC may be subtracted from this to get degrees
450 * Celsius. If that Celsius value is HV_SYSCONF_OVERTEMP, this indicates
451 * that the temperature has hit an upper limit and is no longer being
452 * accurately tracked.
453 */
454 HV_SYSCONF_BOARD_TEMP = 6,
455
456 /** Legal page size bitmask for hv_install_context().
457 * For example, if 16KB and 64KB small pages are supported,
458 * it would return "HV_CTX_PG_SM_16K | HV_CTX_PG_SM_64K".
459 */
460 HV_SYSCONF_VALID_PAGE_SIZES = 7,
461
462 /** The size of jumbo pages, in bytes.
463 * If no jumbo pages are available, zero will be returned.
464 */
465 HV_SYSCONF_PAGE_SIZE_JUMBO = 8,
466
467} HV_SysconfQuery;
468
469/** Offset to subtract from returned Kelvin temperature to get degrees
470 Celsius. */
471#define HV_SYSCONF_TEMP_KTOC 273
472
473/** Pseudo-temperature value indicating that the temperature has
474 * pegged at its upper limit and is no longer accurate; note that this is
475 * the value after subtracting HV_SYSCONF_TEMP_KTOC. */
476#define HV_SYSCONF_OVERTEMP 999
477
478/** Query a configuration value from the hypervisor.
479 * @param query Which value is requested (HV_SYSCONF_xxx).
480 * @return The requested value, or -1 the requested value is illegal or
481 * unavailable.
482 */
483long hv_sysconf(HV_SysconfQuery query);
484
485
486/** Queries we can make for hv_confstr().
487 *
488 * These numbers are part of the binary API and guaranteed not to change.
489 */
490typedef enum {
491 /** An invalid value; do not use. */
492 _HV_CONFSTR_RESERVED = 0,
493
494 /** Board part number. */
495 HV_CONFSTR_BOARD_PART_NUM = 1,
496
497 /** Board serial number. */
498 HV_CONFSTR_BOARD_SERIAL_NUM = 2,
499
500 /** Chip serial number. */
501 HV_CONFSTR_CHIP_SERIAL_NUM = 3,
502
503 /** Board revision level. */
504 HV_CONFSTR_BOARD_REV = 4,
505
506 /** Hypervisor software version. */
507 HV_CONFSTR_HV_SW_VER = 5,
508
509 /** The name for this chip model. */
510 HV_CONFSTR_CHIP_MODEL = 6,
511
512 /** Human-readable board description. */
513 HV_CONFSTR_BOARD_DESC = 7,
514
515 /** Human-readable description of the hypervisor configuration. */
516 HV_CONFSTR_HV_CONFIG = 8,
517
518 /** Human-readable version string for the boot image (for instance,
519 * who built it and when, what configuration file was used). */
520 HV_CONFSTR_HV_CONFIG_VER = 9,
521
522 /** Mezzanine part number. */
523 HV_CONFSTR_MEZZ_PART_NUM = 10,
524
525 /** Mezzanine serial number. */
526 HV_CONFSTR_MEZZ_SERIAL_NUM = 11,
527
528 /** Mezzanine revision level. */
529 HV_CONFSTR_MEZZ_REV = 12,
530
531 /** Human-readable mezzanine description. */
532 HV_CONFSTR_MEZZ_DESC = 13,
533
534 /** Control path for the onboard network switch. */
535 HV_CONFSTR_SWITCH_CONTROL = 14,
536
537 /** Chip revision level. */
538 HV_CONFSTR_CHIP_REV = 15,
539
540 /** CPU module part number. */
541 HV_CONFSTR_CPUMOD_PART_NUM = 16,
542
543 /** CPU module serial number. */
544 HV_CONFSTR_CPUMOD_SERIAL_NUM = 17,
545
546 /** CPU module revision level. */
547 HV_CONFSTR_CPUMOD_REV = 18,
548
549 /** Human-readable CPU module description. */
550 HV_CONFSTR_CPUMOD_DESC = 19,
551
552 /** Per-tile hypervisor statistics. When this identifier is specified,
553 * the hv_confstr call takes two extra arguments. The first is the
554 * HV_XY_TO_LOTAR of the target tile's coordinates. The second is
555 * a flag word. The only current flag is the lowest bit, which means
556 * "zero out the stats instead of retrieving them"; in this case the
557 * buffer and buffer length are ignored. */
558 HV_CONFSTR_HV_STATS = 20
559
560} HV_ConfstrQuery;
561
562/** Query a configuration string from the hypervisor.
563 *
564 * @param query Identifier for the specific string to be retrieved
565 * (HV_CONFSTR_xxx). Some strings may require or permit extra
566 * arguments to be appended which select specific objects to be
567 * described; see the string descriptions above.
568 * @param buf Buffer in which to place the string.
569 * @param len Length of the buffer.
570 * @return If query is valid, then the length of the corresponding string,
571 * including the trailing null; if this is greater than len, the string
572 * was truncated. If query is invalid, HV_EINVAL. If the specified
573 * buffer is not writable by the client, HV_EFAULT.
574 */
575int hv_confstr(HV_ConfstrQuery query, HV_VirtAddr buf, int len, ...);
576
577/** Tile coordinate */
578typedef struct
579{
580 /** X coordinate, relative to supervisor's top-left coordinate */
581 int x;
582
583 /** Y coordinate, relative to supervisor's top-left coordinate */
584 int y;
585} HV_Coord;
586
587
588#if CHIP_HAS_IPI()
589
590/** Get the PTE for sending an IPI to a particular tile.
591 *
592 * @param tile Tile which will receive the IPI.
593 * @param pl Indicates which IPI registers: 0 = IPI_0, 1 = IPI_1.
594 * @param pte Filled with resulting PTE.
595 * @result Zero if no error, non-zero for invalid parameters.
596 */
597int hv_get_ipi_pte(HV_Coord tile, int pl, HV_PTE* pte);
598
599/** Configure the console interrupt.
600 *
601 * When the console client interrupt is enabled, the hypervisor will
602 * deliver the specified IPI to the client in the following situations:
603 *
604 * - The console has at least one character available for input.
605 *
606 * - The console can accept new characters for output, and the last call
607 * to hv_console_write() did not write all of the characters requested
608 * by the client.
609 *
610 * Note that in some system configurations, console interrupt will not
611 * be available; clients should be prepared for this routine to fail and
612 * to fall back to periodic console polling in that case.
613 *
614 * @param ipi Index of the IPI register which will receive the interrupt.
615 * @param event IPI event number for console interrupt. If less than 0,
616 * disable the console IPI interrupt.
617 * @param coord Tile to be targeted for console interrupt.
618 * @return 0 on success, otherwise, HV_EINVAL if illegal parameter,
619 * HV_ENOTSUP if console interrupt are not available.
620 */
621int hv_console_set_ipi(int ipi, int event, HV_Coord coord);
622
623#else /* !CHIP_HAS_IPI() */
624
625/** A set of interrupts. */
626typedef __hv32 HV_IntrMask;
627
628/** The low interrupt numbers are reserved for use by the client in
629 * delivering IPIs. Any interrupt numbers higher than this value are
630 * reserved for use by HV device drivers. */
631#define HV_MAX_IPI_INTERRUPT 7
632
633/** Enable a set of device interrupts.
634 *
635 * @param enab_mask Bitmap of interrupts to enable.
636 */
637void hv_enable_intr(HV_IntrMask enab_mask);
638
639/** Disable a set of device interrupts.
640 *
641 * @param disab_mask Bitmap of interrupts to disable.
642 */
643void hv_disable_intr(HV_IntrMask disab_mask);
644
645/** Clear a set of device interrupts.
646 *
647 * @param clear_mask Bitmap of interrupts to clear.
648 */
649void hv_clear_intr(HV_IntrMask clear_mask);
650
651/** Raise a set of device interrupts.
652 *
653 * @param raise_mask Bitmap of interrupts to raise.
654 */
655void hv_raise_intr(HV_IntrMask raise_mask);
656
657/** Trigger a one-shot interrupt on some tile
658 *
659 * @param tile Which tile to interrupt.
660 * @param interrupt Interrupt number to trigger; must be between 0 and
661 * HV_MAX_IPI_INTERRUPT.
662 * @return HV_OK on success, or a hypervisor error code.
663 */
664HV_Errno hv_trigger_ipi(HV_Coord tile, int interrupt);
665
666#endif /* !CHIP_HAS_IPI() */
667
668/** Store memory mapping in debug memory so that external debugger can read it.
669 * A maximum of 16 entries can be stored.
670 *
671 * @param va VA of memory that is mapped.
672 * @param len Length of mapped memory.
673 * @param pa PA of memory that is mapped.
674 * @return 0 on success, -1 if the maximum number of mappings is exceeded.
675 */
676int hv_store_mapping(HV_VirtAddr va, unsigned int len, HV_PhysAddr pa);
677
678/** Given a client PA and a length, return its real (HV) PA.
679 *
680 * @param cpa Client physical address.
681 * @param len Length of mapped memory.
682 * @return physical address, or -1 if cpa or len is not valid.
683 */
684HV_PhysAddr hv_inquire_realpa(HV_PhysAddr cpa, unsigned int len);
685
686/** RTC return flag for no RTC chip present.
687 */
688#define HV_RTC_NO_CHIP 0x1
689
690/** RTC return flag for low-voltage condition, indicating that battery had
691 * died and time read is unreliable.
692 */
693#define HV_RTC_LOW_VOLTAGE 0x2
694
695/** Date/Time of day */
696typedef struct {
697#if CHIP_WORD_SIZE() > 32
698 __hv64 tm_sec; /**< Seconds, 0-59 */
699 __hv64 tm_min; /**< Minutes, 0-59 */
700 __hv64 tm_hour; /**< Hours, 0-23 */
701 __hv64 tm_mday; /**< Day of month, 0-30 */
702 __hv64 tm_mon; /**< Month, 0-11 */
703 __hv64 tm_year; /**< Years since 1900, 0-199 */
704 __hv64 flags; /**< Return flags, 0 if no error */
705#else
706 __hv32 tm_sec; /**< Seconds, 0-59 */
707 __hv32 tm_min; /**< Minutes, 0-59 */
708 __hv32 tm_hour; /**< Hours, 0-23 */
709 __hv32 tm_mday; /**< Day of month, 0-30 */
710 __hv32 tm_mon; /**< Month, 0-11 */
711 __hv32 tm_year; /**< Years since 1900, 0-199 */
712 __hv32 flags; /**< Return flags, 0 if no error */
713#endif
714} HV_RTCTime;
715
716/** Read the current time-of-day clock.
717 * @return HV_RTCTime of current time (GMT).
718 */
719HV_RTCTime hv_get_rtc(void);
720
721
722/** Set the current time-of-day clock.
723 * @param time time to reset time-of-day to (GMT).
724 */
725void hv_set_rtc(HV_RTCTime time);
726
727/** Installs a context, comprising a page table and other attributes.
728 *
729 * Once this service completes, page_table will be used to translate
730 * subsequent virtual address references to physical memory.
731 *
732 * Installing a context does not cause an implicit TLB flush. Before
733 * reusing an ASID value for a different address space, the client is
734 * expected to flush old references from the TLB with hv_flush_asid().
735 * (Alternately, hv_flush_all() may be used to flush many ASIDs at once.)
736 * After invalidating a page table entry, changing its attributes, or
737 * changing its target CPA, the client is expected to flush old references
738 * from the TLB with hv_flush_page() or hv_flush_pages(). Making a
739 * previously invalid page valid does not require a flush.
740 *
741 * Specifying an invalid ASID, or an invalid CPA (client physical address)
742 * (either as page_table_pointer, or within the referenced table),
743 * or another page table data item documented as above as illegal may
744 * lead to client termination; since the validation of the table is
745 * done as needed, this may happen before the service returns, or at
746 * some later time, or never, depending upon the client's pattern of
747 * memory references. Page table entries which supply translations for
748 * invalid virtual addresses may result in client termination, or may
749 * be silently ignored. "Invalid" in this context means a value which
750 * was not provided to the client via the appropriate hv_inquire_* routine.
751 *
752 * To support changing the instruction VAs at the same time as
753 * installing the new page table, this call explicitly supports
754 * setting the "lr" register to a different address and then jumping
755 * directly to the hv_install_context() routine. In this case, the
756 * new page table does not need to contain any mapping for the
757 * hv_install_context address itself.
758 *
759 * At most one HV_CTX_PG_SM_* flag may be specified in "flags";
760 * if multiple flags are specified, HV_EINVAL is returned.
761 * Specifying none of the flags results in using the default page size.
762 * All cores participating in a given client must request the same
763 * page size, or the results are undefined.
764 *
765 * @param page_table Root of the page table.
766 * @param access PTE providing info on how to read the page table. This
767 * value must be consistent between multiple tiles sharing a page table,
768 * and must also be consistent with any virtual mappings the client
769 * may be using to access the page table.
770 * @param asid HV_ASID the page table is to be used for.
771 * @param flags Context flags, denoting attributes or privileges of the
772 * current context (HV_CTX_xxx).
773 * @return Zero on success, or a hypervisor error code on failure.
774 */
775int hv_install_context(HV_PhysAddr page_table, HV_PTE access, HV_ASID asid,
776 __hv32 flags);
777
778#endif /* !__ASSEMBLER__ */
779
780#define HV_CTX_DIRECTIO 0x1 /**< Direct I/O requests are accepted from
781 PL0. */
782
783#define HV_CTX_PG_SM_4K 0x10 /**< Use 4K small pages, if available. */
784#define HV_CTX_PG_SM_16K 0x20 /**< Use 16K small pages, if available. */
785#define HV_CTX_PG_SM_64K 0x40 /**< Use 64K small pages, if available. */
786#define HV_CTX_PG_SM_MASK 0xf0 /**< Mask of all possible small pages. */
787
788#ifndef __ASSEMBLER__
789
790
791/** Set the number of pages ganged together by HV_PTE_SUPER at a
792 * particular level of the page table.
793 *
794 * The current TILE-Gx hardware only supports powers of four
795 * (i.e. log2_count must be a multiple of two), and the requested
796 * "super" page size must be less than the span of the next level in
797 * the page table. The largest size that can be requested is 64GB.
798 *
799 * The shift value is initially "0" for all page table levels,
800 * indicating that the HV_PTE_SUPER bit is effectively ignored.
801 *
802 * If you change the count from one non-zero value to another, the
803 * hypervisor will flush the entire TLB and TSB to avoid confusion.
804 *
805 * @param level Page table level (0, 1, or 2)
806 * @param log2_count Base-2 log of the number of pages to gang together,
807 * i.e. how much to shift left the base page size for the super page size.
808 * @return Zero on success, or a hypervisor error code on failure.
809 */
810int hv_set_pte_super_shift(int level, int log2_count);
811
812
813/** Value returned from hv_inquire_context(). */
814typedef struct
815{
816 /** Physical address of page table */
817 HV_PhysAddr page_table;
818
819 /** PTE which defines access method for top of page table */
820 HV_PTE access;
821
822 /** ASID associated with this page table */
823 HV_ASID asid;
824
825 /** Context flags */
826 __hv32 flags;
827} HV_Context;
828
829/** Retrieve information about the currently installed context.
830 * @return The data passed to the last successful hv_install_context call.
831 */
832HV_Context hv_inquire_context(void);
833
834
835/** Flushes all translations associated with the named address space
836 * identifier from the TLB and any other hypervisor data structures.
837 * Translations installed with the "global" bit are not flushed.
838 *
839 * Specifying an invalid ASID may lead to client termination. "Invalid"
840 * in this context means a value which was not provided to the client
841 * via <tt>hv_inquire_asid()</tt>.
842 *
843 * @param asid HV_ASID whose entries are to be flushed.
844 * @return Zero on success, or a hypervisor error code on failure.
845*/
846int hv_flush_asid(HV_ASID asid);
847
848
849/** Flushes all translations associated with the named virtual address
850 * and page size from the TLB and other hypervisor data structures. Only
851 * pages visible to the current ASID are affected; note that this includes
852 * global pages in addition to pages specific to the current ASID.
853 *
854 * The supplied VA need not be aligned; it may be anywhere in the
855 * subject page.
856 *
857 * Specifying an invalid virtual address may lead to client termination,
858 * or may silently succeed. "Invalid" in this context means a value
859 * which was not provided to the client via hv_inquire_virtual.
860 *
861 * @param address Address of the page to flush.
862 * @param page_size Size of pages to assume.
863 * @return Zero on success, or a hypervisor error code on failure.
864 */
865int hv_flush_page(HV_VirtAddr address, HV_PageSize page_size);
866
867
868/** Flushes all translations associated with the named virtual address range
869 * and page size from the TLB and other hypervisor data structures. Only
870 * pages visible to the current ASID are affected; note that this includes
871 * global pages in addition to pages specific to the current ASID.
872 *
873 * The supplied VA need not be aligned; it may be anywhere in the
874 * subject page.
875 *
876 * Specifying an invalid virtual address may lead to client termination,
877 * or may silently succeed. "Invalid" in this context means a value
878 * which was not provided to the client via hv_inquire_virtual.
879 *
880 * @param start Address to flush.
881 * @param page_size Size of pages to assume.
882 * @param size The number of bytes to flush. Any page in the range
883 * [start, start + size) will be flushed from the TLB.
884 * @return Zero on success, or a hypervisor error code on failure.
885 */
886int hv_flush_pages(HV_VirtAddr start, HV_PageSize page_size,
887 unsigned long size);
888
889
890/** Flushes all non-global translations (if preserve_global is true),
891 * or absolutely all translations (if preserve_global is false).
892 *
893 * @param preserve_global Non-zero if we want to preserve "global" mappings.
894 * @return Zero on success, or a hypervisor error code on failure.
895*/
896int hv_flush_all(int preserve_global);
897
898
899/** Restart machine with optional restart command and optional args.
900 * @param cmd Const pointer to command to restart with, or NULL
901 * @param args Const pointer to argument string to restart with, or NULL
902 */
903void hv_restart(HV_VirtAddr cmd, HV_VirtAddr args);
904
905
906/** Halt machine. */
907void hv_halt(void);
908
909
910/** Power off machine. */
911void hv_power_off(void);
912
913
914/** Re-enter virtual-is-physical memory translation mode and restart
915 * execution at a given address.
916 * @param entry Client physical address at which to begin execution.
917 * @return A hypervisor error code on failure; if the operation is
918 * successful the call does not return.
919 */
920int hv_reexec(HV_PhysAddr entry);
921
922
923/** Chip topology */
924typedef struct
925{
926 /** Relative coordinates of the querying tile */
927 HV_Coord coord;
928
929 /** Width of the querying supervisor's tile rectangle. */
930 int width;
931
932 /** Height of the querying supervisor's tile rectangle. */
933 int height;
934
935} HV_Topology;
936
937/** Returns information about the tile coordinate system.
938 *
939 * Each supervisor is given a rectangle of tiles it potentially controls.
940 * These tiles are labeled using a relative coordinate system with (0,0) as
941 * the upper left tile regardless of their physical location on the chip.
942 *
943 * This call returns both the size of that rectangle and the position
944 * within that rectangle of the querying tile.
945 *
946 * Not all tiles within that rectangle may be available to the supervisor;
947 * to get the precise set of available tiles, you must also call
948 * hv_inquire_tiles(HV_INQ_TILES_AVAIL, ...).
949 **/
950HV_Topology hv_inquire_topology(void);
951
952/** Sets of tiles we can retrieve with hv_inquire_tiles().
953 *
954 * These numbers are part of the binary API and guaranteed not to change.
955 */
956typedef enum {
957 /** An invalid value; do not use. */
958 _HV_INQ_TILES_RESERVED = 0,
959
960 /** All available tiles within the supervisor's tile rectangle. */
961 HV_INQ_TILES_AVAIL = 1,
962
963 /** The set of tiles used for hash-for-home caching. */
964 HV_INQ_TILES_HFH_CACHE = 2,
965
966 /** The set of tiles that can be legally used as a LOTAR for a PTE. */
967 HV_INQ_TILES_LOTAR = 3,
968
969 /** The set of "shared" driver tiles that the hypervisor may
970 * periodically interrupt. */
971 HV_INQ_TILES_SHARED = 4
972} HV_InqTileSet;
973
974/** Returns specific information about various sets of tiles within the
975 * supervisor's tile rectangle.
976 *
977 * @param set Which set of tiles to retrieve.
978 * @param cpumask Pointer to a returned bitmask (in row-major order,
979 * supervisor-relative) of tiles. The low bit of the first word
980 * corresponds to the tile at the upper left-hand corner of the
981 * supervisor's rectangle. In order for the supervisor to know the
982 * buffer length to supply, it should first call hv_inquire_topology.
983 * @param length Number of bytes available for the returned bitmask.
984 **/
985HV_Errno hv_inquire_tiles(HV_InqTileSet set, HV_VirtAddr cpumask, int length);
986
987
988/** An identifier for a memory controller. Multiple memory controllers
989 * may be connected to one chip, and this uniquely identifies each one.
990 */
991typedef int HV_MemoryController;
992
993/** A range of physical memory. */
994typedef struct
995{
996 HV_PhysAddr start; /**< Starting address. */
997 __hv64 size; /**< Size in bytes. */
998 HV_MemoryController controller; /**< Which memory controller owns this. */
999} HV_PhysAddrRange;
1000
1001/** Returns information about a range of physical memory.
1002 *
1003 * hv_inquire_physical() returns one of the ranges of client
1004 * physical addresses which are available to this client.
1005 *
1006 * The first range is retrieved by specifying an idx of 0, and
1007 * successive ranges are returned with subsequent idx values. Ranges
1008 * are ordered by increasing start address (i.e., as idx increases,
1009 * so does start), do not overlap, and do not touch (i.e., the
1010 * available memory is described with the fewest possible ranges).
1011 *
1012 * If an out-of-range idx value is specified, the returned size will be zero.
1013 * A client can count the number of ranges by increasing idx until the
1014 * returned size is zero. There will always be at least one valid range.
1015 *
1016 * Some clients might not be prepared to deal with more than one
1017 * physical address range; they still ought to call this routine and
1018 * issue a warning message if they're given more than one range, on the
1019 * theory that whoever configured the hypervisor to provide that memory
1020 * should know that it's being wasted.
1021 */
1022HV_PhysAddrRange hv_inquire_physical(int idx);
1023
1024/** Possible DIMM types. */
1025typedef enum
1026{
1027 NO_DIMM = 0, /**< No DIMM */
1028 DDR2 = 1, /**< DDR2 */
1029 DDR3 = 2 /**< DDR3 */
1030} HV_DIMM_Type;
1031
1032#ifdef __tilegx__
1033
1034/** Log2 of minimum DIMM bytes supported by the memory controller. */
1035#define HV_MSH_MIN_DIMM_SIZE_SHIFT 29
1036
1037/** Max number of DIMMs contained by one memory controller. */
1038#define HV_MSH_MAX_DIMMS 8
1039
1040#else
1041
1042/** Log2 of minimum DIMM bytes supported by the memory controller. */
1043#define HV_MSH_MIN_DIMM_SIZE_SHIFT 26
1044
1045/** Max number of DIMMs contained by one memory controller. */
1046#define HV_MSH_MAX_DIMMS 2
1047
1048#endif
1049
1050/** Number of bits to right-shift to get the DIMM type. */
1051#define HV_DIMM_TYPE_SHIFT 0
1052
1053/** Bits to mask to get the DIMM type. */
1054#define HV_DIMM_TYPE_MASK 0xf
1055
1056/** Number of bits to right-shift to get the DIMM size. */
1057#define HV_DIMM_SIZE_SHIFT 4
1058
1059/** Bits to mask to get the DIMM size. */
1060#define HV_DIMM_SIZE_MASK 0xf
1061
1062/** Memory controller information. */
1063typedef struct
1064{
1065 HV_Coord coord; /**< Relative tile coordinates of the port used by a
1066 specified tile to communicate with this controller. */
1067 __hv64 speed; /**< Speed of this controller in bytes per second. */
1068} HV_MemoryControllerInfo;
1069
1070/** Returns information about a particular memory controller.
1071 *
1072 * hv_inquire_memory_controller(coord,idx) returns information about a
1073 * particular controller. Two pieces of information are returned:
1074 * - The relative coordinates of the port on the controller that the specified
1075 * tile would use to contact it. The relative coordinates may lie
1076 * outside the supervisor's rectangle, i.e. the controller may not
1077 * be attached to a node managed by the querying node's supervisor.
1078 * In particular note that x or y may be negative.
1079 * - The speed of the memory controller. (This is a not-to-exceed value
1080 * based on the raw hardware data rate, and may not be achievable in
1081 * practice; it is provided to give clients information on the relative
1082 * performance of the available controllers.)
1083 *
1084 * Clients should avoid calling this interface with invalid values.
1085 * A client who does may be terminated.
1086 * @param coord Tile for which to calculate the relative port position.
1087 * @param controller Index of the controller; identical to value returned
1088 * from other routines like hv_inquire_physical.
1089 * @return Information about the controller.
1090 */
1091HV_MemoryControllerInfo hv_inquire_memory_controller(HV_Coord coord,
1092 int controller);
1093
1094
1095/** A range of virtual memory. */
1096typedef struct
1097{
1098 HV_VirtAddr start; /**< Starting address. */
1099 __hv64 size; /**< Size in bytes. */
1100} HV_VirtAddrRange;
1101
1102/** Returns information about a range of virtual memory.
1103 *
1104 * hv_inquire_virtual() returns one of the ranges of client
1105 * virtual addresses which are available to this client.
1106 *
1107 * The first range is retrieved by specifying an idx of 0, and
1108 * successive ranges are returned with subsequent idx values. Ranges
1109 * are ordered by increasing start address (i.e., as idx increases,
1110 * so does start), do not overlap, and do not touch (i.e., the
1111 * available memory is described with the fewest possible ranges).
1112 *
1113 * If an out-of-range idx value is specified, the returned size will be zero.
1114 * A client can count the number of ranges by increasing idx until the
1115 * returned size is zero. There will always be at least one valid range.
1116 *
1117 * Some clients may well have various virtual addresses hardwired
1118 * into themselves; for instance, their instruction stream may
1119 * have been compiled expecting to live at a particular address.
1120 * Such clients should use this interface to verify they've been
1121 * given the virtual address space they expect, and issue a (potentially
1122 * fatal) warning message otherwise.
1123 *
1124 * Note that the returned size is a __hv64, not a __hv32, so it is
1125 * possible to express a single range spanning the entire 32-bit
1126 * address space.
1127 */
1128HV_VirtAddrRange hv_inquire_virtual(int idx);
1129
1130
1131/** A range of ASID values. */
1132typedef struct
1133{
1134 HV_ASID start; /**< First ASID in the range. */
1135 unsigned int size; /**< Number of ASIDs. Zero for an invalid range. */
1136} HV_ASIDRange;
1137
1138/** Returns information about a range of ASIDs.
1139 *
1140 * hv_inquire_asid() returns one of the ranges of address
1141 * space identifiers which are available to this client.
1142 *
1143 * The first range is retrieved by specifying an idx of 0, and
1144 * successive ranges are returned with subsequent idx values. Ranges
1145 * are ordered by increasing start value (i.e., as idx increases,
1146 * so does start), do not overlap, and do not touch (i.e., the
1147 * available ASIDs are described with the fewest possible ranges).
1148 *
1149 * If an out-of-range idx value is specified, the returned size will be zero.
1150 * A client can count the number of ranges by increasing idx until the
1151 * returned size is zero. There will always be at least one valid range.
1152 */
1153HV_ASIDRange hv_inquire_asid(int idx);
1154
1155
1156/** Waits for at least the specified number of nanoseconds then returns.
1157 *
1158 * NOTE: this deprecated function currently assumes a 750 MHz clock,
1159 * and is thus not generally suitable for use. New code should call
1160 * hv_sysconf(HV_SYSCONF_CPU_SPEED), compute a cycle count to wait for,
1161 * and delay by looping while checking the cycle counter SPR.
1162 *
1163 * @param nanosecs The number of nanoseconds to sleep.
1164 */
1165void hv_nanosleep(int nanosecs);
1166
1167
1168/** Reads a character from the console without blocking.
1169 *
1170 * @return A value from 0-255 indicates the value successfully read.
1171 * A negative value means no value was ready.
1172 */
1173int hv_console_read_if_ready(void);
1174
1175
1176/** Writes a character to the console, blocking if the console is busy.
1177 *
1178 * This call cannot fail. If the console is broken for some reason,
1179 * output will simply vanish.
1180 * @param byte Character to write.
1181 */
1182void hv_console_putc(int byte);
1183
1184
1185/** Writes a string to the console, blocking if the console is busy.
1186 * @param bytes Pointer to characters to write.
1187 * @param len Number of characters to write.
1188 * @return Number of characters written, or HV_EFAULT if the buffer is invalid.
1189 */
1190int hv_console_write(HV_VirtAddr bytes, int len);
1191
1192
1193/** Dispatch the next interrupt from the client downcall mechanism.
1194 *
1195 * The hypervisor uses downcalls to notify the client of asynchronous
1196 * events. Some of these events are hypervisor-created (like incoming
1197 * messages). Some are regular interrupts which initially occur in
1198 * the hypervisor, and are normally handled directly by the client;
1199 * when these occur in a client's interrupt critical section, they must
1200 * be delivered through the downcall mechanism.
1201 *
1202 * A downcall is initially delivered to the client as an INTCTRL_CL
1203 * interrupt, where CL is the client's PL. Upon entry to the INTCTRL_CL
1204 * vector, the client must immediately invoke the hv_downcall_dispatch
1205 * service. This service will not return; instead it will cause one of
1206 * the client's actual downcall-handling interrupt vectors to be entered.
1207 * The EX_CONTEXT registers in the client will be set so that when the
1208 * client irets, it will return to the code which was interrupted by the
1209 * INTCTRL_CL interrupt.
1210 *
1211 * Under some circumstances, the firing of INTCTRL_CL can race with
1212 * the lowering of a device interrupt. In such a case, the
1213 * hv_downcall_dispatch service may issue an iret instruction instead
1214 * of entering one of the client's actual downcall-handling interrupt
1215 * vectors. This will return execution to the location that was
1216 * interrupted by INTCTRL_CL.
1217 *
1218 * Any saving of registers should be done by the actual handling
1219 * vectors; no registers should be changed by the INTCTRL_CL handler.
1220 * In particular, the client should not use a jal instruction to invoke
1221 * the hv_downcall_dispatch service, as that would overwrite the client's
1222 * lr register. Note that the hv_downcall_dispatch service may overwrite
1223 * one or more of the client's system save registers.
1224 *
1225 * The client must not modify the INTCTRL_CL_STATUS SPR. The hypervisor
1226 * will set this register to cause a downcall to happen, and will clear
1227 * it when no further downcalls are pending.
1228 *
1229 * When a downcall vector is entered, the INTCTRL_CL interrupt will be
1230 * masked. When the client is done processing a downcall, and is ready
1231 * to accept another, it must unmask this interrupt; if more downcalls
1232 * are pending, this will cause the INTCTRL_CL vector to be reentered.
1233 * Currently the following interrupt vectors can be entered through a
1234 * downcall:
1235 *
1236 * INT_MESSAGE_RCV_DWNCL (hypervisor message available)
1237 * INT_DEV_INTR_DWNCL (device interrupt)
1238 * INT_DMATLB_MISS_DWNCL (DMA TLB miss)
1239 * INT_SNITLB_MISS_DWNCL (SNI TLB miss)
1240 * INT_DMATLB_ACCESS_DWNCL (DMA TLB access violation)
1241 */
1242void hv_downcall_dispatch(void);
1243
1244#endif /* !__ASSEMBLER__ */
1245
1246/** We use actual interrupt vectors which never occur (they're only there
1247 * to allow setting MPLs for related SPRs) for our downcall vectors.
1248 */
1249/** Message receive downcall interrupt vector */
1250#define INT_MESSAGE_RCV_DWNCL INT_BOOT_ACCESS
1251/** DMA TLB miss downcall interrupt vector */
1252#define INT_DMATLB_MISS_DWNCL INT_DMA_ASID
1253/** Static nework processor instruction TLB miss interrupt vector */
1254#define INT_SNITLB_MISS_DWNCL INT_SNI_ASID
1255/** DMA TLB access violation downcall interrupt vector */
1256#define INT_DMATLB_ACCESS_DWNCL INT_DMA_CPL
1257/** Device interrupt downcall interrupt vector */
1258#define INT_DEV_INTR_DWNCL INT_WORLD_ACCESS
1259/** NMI downcall interrupt vector */
1260#define INT_NMI_DWNCL 64
1261
1262#define HV_NMI_FLAG_FORCE 0x1 /**< Force an NMI downcall regardless of
1263 the ICS bit of the client. */
1264
1265#ifndef __ASSEMBLER__
1266
1267/** Requests the inode for a specific full pathname.
1268 *
1269 * Performs a lookup in the hypervisor filesystem for a given filename.
1270 * Multiple calls with the same filename will always return the same inode.
1271 * If there is no such filename, HV_ENOENT is returned.
1272 * A bad filename pointer may result in HV_EFAULT instead.
1273 *
1274 * @param filename Constant pointer to name of requested file
1275 * @return Inode of requested file
1276 */
1277int hv_fs_findfile(HV_VirtAddr filename);
1278
1279
1280/** Data returned from an fstat request.
1281 * Note that this structure should be no more than 40 bytes in size so
1282 * that it can always be returned completely in registers.
1283 */
1284typedef struct
1285{
1286 int size; /**< Size of file (or HV_Errno on error) */
1287 unsigned int flags; /**< Flags (see HV_FS_FSTAT_FLAGS) */
1288} HV_FS_StatInfo;
1289
1290/** Bitmask flags for fstat request */
1291typedef enum
1292{
1293 HV_FS_ISDIR = 0x0001 /**< Is the entry a directory? */
1294} HV_FS_FSTAT_FLAGS;
1295
1296/** Get stat information on a given file inode.
1297 *
1298 * Return information on the file with the given inode.
1299 *
1300 * IF the HV_FS_ISDIR bit is set, the "file" is a directory. Reading
1301 * it will return NUL-separated filenames (no directory part) relative
1302 * to the path to the inode of the directory "file". These can be
1303 * appended to the path to the directory "file" after a forward slash
1304 * to create additional filenames. Note that it is not required
1305 * that all valid paths be decomposable into valid parent directories;
1306 * a filesystem may validly have just a few files, none of which have
1307 * HV_FS_ISDIR set. However, if clients may wish to enumerate the
1308 * files in the filesystem, it is recommended to include all the
1309 * appropriate parent directory "files" to give a consistent view.
1310 *
1311 * An invalid file inode will cause an HV_EBADF error to be returned.
1312 *
1313 * @param inode The inode number of the query
1314 * @return An HV_FS_StatInfo structure
1315 */
1316HV_FS_StatInfo hv_fs_fstat(int inode);
1317
1318
1319/** Read data from a specific hypervisor file.
1320 * On error, may return HV_EBADF for a bad inode or HV_EFAULT for a bad buf.
1321 * Reads near the end of the file will return fewer bytes than requested.
1322 * Reads at or beyond the end of a file will return zero.
1323 *
1324 * @param inode the hypervisor file to read
1325 * @param buf the buffer to read data into
1326 * @param length the number of bytes of data to read
1327 * @param offset the offset into the file to read the data from
1328 * @return number of bytes successfully read, or an HV_Errno code
1329 */
1330int hv_fs_pread(int inode, HV_VirtAddr buf, int length, int offset);
1331
1332
1333/** Read a 64-bit word from the specified physical address.
1334 * The address must be 8-byte aligned.
1335 * Specifying an invalid physical address will lead to client termination.
1336 * @param addr The physical address to read
1337 * @param access The PTE describing how to read the memory
1338 * @return The 64-bit value read from the given address
1339 */
1340unsigned long long hv_physaddr_read64(HV_PhysAddr addr, HV_PTE access);
1341
1342
1343/** Write a 64-bit word to the specified physical address.
1344 * The address must be 8-byte aligned.
1345 * Specifying an invalid physical address will lead to client termination.
1346 * @param addr The physical address to write
1347 * @param access The PTE that says how to write the memory
1348 * @param val The 64-bit value to write to the given address
1349 */
1350void hv_physaddr_write64(HV_PhysAddr addr, HV_PTE access,
1351 unsigned long long val);
1352
1353
1354/** Get the value of the command-line for the supervisor, if any.
1355 * This will not include the filename of the booted supervisor, but may
1356 * include configured-in boot arguments or the hv_restart() arguments.
1357 * If the buffer is not long enough the hypervisor will NUL the first
1358 * character of the buffer but not write any other data.
1359 * @param buf The virtual address to write the command-line string to.
1360 * @param length The length of buf, in characters.
1361 * @return The actual length of the command line, including the trailing NUL
1362 * (may be larger than "length").
1363 */
1364int hv_get_command_line(HV_VirtAddr buf, int length);
1365
1366
1367/** Set a new value for the command-line for the supervisor, which will
1368 * be returned from subsequent invocations of hv_get_command_line() on
1369 * this tile.
1370 * @param buf The virtual address to read the command-line string from.
1371 * @param length The length of buf, in characters; must be no more than
1372 * HV_COMMAND_LINE_LEN.
1373 * @return Zero if successful, or a hypervisor error code.
1374 */
1375HV_Errno hv_set_command_line(HV_VirtAddr buf, int length);
1376
1377/** Maximum size of a command line passed to hv_set_command_line(); note
1378 * that a line returned from hv_get_command_line() could be larger than
1379 * this.*/
1380#define HV_COMMAND_LINE_LEN 256
1381
1382/** Tell the hypervisor how to cache non-priority pages
1383 * (its own as well as pages explicitly represented in page tables).
1384 * Normally these will be represented as red/black pages, but
1385 * when the supervisor starts to allocate "priority" pages in the PTE
1386 * the hypervisor will need to start marking those pages as (e.g.) "red"
1387 * and non-priority pages as either "black" (if they cache-alias
1388 * with the existing priority pages) or "red/black" (if they don't).
1389 * The bitmask provides information on which parts of the cache
1390 * have been used for pinned pages so far on this tile; if (1 << N)
1391 * appears in the bitmask, that indicates that a 4KB region of the
1392 * cache starting at (N * 4KB) is in use by a "priority" page.
1393 * The portion of cache used by a particular page can be computed
1394 * by taking the page's PA, modulo CHIP_L2_CACHE_SIZE(), and setting
1395 * all the "4KB" bits corresponding to the actual page size.
1396 * @param bitmask A bitmap of priority page set values
1397 */
1398void hv_set_caching(unsigned long bitmask);
1399
1400
1401/** Zero out a specified number of pages.
1402 * The va and size must both be multiples of 4096.
1403 * Caches are bypassed and memory is directly set to zero.
1404 * This API is implemented only in the magic hypervisor and is intended
1405 * to provide a performance boost to the minimal supervisor by
1406 * giving it a fast way to zero memory pages when allocating them.
1407 * @param va Virtual address where the page has been mapped
1408 * @param size Number of bytes (must be a page size multiple)
1409 */
1410void hv_bzero_page(HV_VirtAddr va, unsigned int size);
1411
1412
1413/** State object for the hypervisor messaging subsystem. */
1414typedef struct
1415{
1416#if CHIP_VA_WIDTH() > 32
1417 __hv64 opaque[2]; /**< No user-serviceable parts inside */
1418#else
1419 __hv32 opaque[2]; /**< No user-serviceable parts inside */
1420#endif
1421}
1422HV_MsgState;
1423
1424/** Register to receive incoming messages.
1425 *
1426 * This routine configures the current tile so that it can receive
1427 * incoming messages. It must be called before the client can receive
1428 * messages with the hv_receive_message routine, and must be called on
1429 * each tile which will receive messages.
1430 *
1431 * msgstate is the virtual address of a state object of type HV_MsgState.
1432 * Once the state is registered, the client must not read or write the
1433 * state object; doing so will cause undefined results.
1434 *
1435 * If this routine is called with msgstate set to 0, the client's message
1436 * state will be freed and it will no longer be able to receive messages.
1437 * Note that this may cause the loss of any as-yet-undelivered messages
1438 * for the client.
1439 *
1440 * If another client attempts to send a message to a client which has
1441 * not yet called hv_register_message_state, or which has freed its
1442 * message state, the message will not be delivered, as if the client
1443 * had insufficient buffering.
1444 *
1445 * This routine returns HV_OK if the registration was successful, and
1446 * HV_EINVAL if the supplied state object is unsuitable. Note that some
1447 * errors may not be detected during this routine, but might be detected
1448 * during a subsequent message delivery.
1449 * @param msgstate State object.
1450 **/
1451HV_Errno hv_register_message_state(HV_MsgState* msgstate);
1452
1453/** Possible message recipient states. */
1454typedef enum
1455{
1456 HV_TO_BE_SENT, /**< Not sent (not attempted, or recipient not ready) */
1457 HV_SENT, /**< Successfully sent */
1458 HV_BAD_RECIP /**< Bad recipient coordinates (permanent error) */
1459} HV_Recip_State;
1460
1461/** Message recipient. */
1462typedef struct
1463{
1464 /** X coordinate, relative to supervisor's top-left coordinate */
1465 unsigned int x:11;
1466
1467 /** Y coordinate, relative to supervisor's top-left coordinate */
1468 unsigned int y:11;
1469
1470 /** Status of this recipient */
1471 HV_Recip_State state:10;
1472} HV_Recipient;
1473
1474/** Send a message to a set of recipients.
1475 *
1476 * This routine sends a message to a set of recipients.
1477 *
1478 * recips is an array of HV_Recipient structures. Each specifies a tile,
1479 * and a message state; initially, it is expected that the state will
1480 * be set to HV_TO_BE_SENT. nrecip specifies the number of recipients
1481 * in the recips array.
1482 *
1483 * For each recipient whose state is HV_TO_BE_SENT, the hypervisor attempts
1484 * to send that tile the specified message. In order to successfully
1485 * receive the message, the receiver must be a valid tile to which the
1486 * sender has access, must not be the sending tile itself, and must have
1487 * sufficient free buffer space. (The hypervisor guarantees that each
1488 * tile which has called hv_register_message_state() will be able to
1489 * buffer one message from every other tile which can legally send to it;
1490 * more space may be provided but is not guaranteed.) If an invalid tile
1491 * is specified, the recipient's state is set to HV_BAD_RECIP; this is a
1492 * permanent delivery error. If the message is successfully delivered
1493 * to the recipient's buffer, the recipient's state is set to HV_SENT.
1494 * Otherwise, the recipient's state is unchanged. Message delivery is
1495 * synchronous; all attempts to send messages are completed before this
1496 * routine returns.
1497 *
1498 * If no permanent delivery errors were encountered, the routine returns
1499 * the number of messages successfully sent: that is, the number of
1500 * recipients whose states changed from HV_TO_BE_SENT to HV_SENT during
1501 * this operation. If any permanent delivery errors were encountered,
1502 * the routine returns HV_ERECIP. In the event of permanent delivery
1503 * errors, it may be the case that delivery was not attempted to all
1504 * recipients; if any messages were successfully delivered, however,
1505 * recipients' state values will be updated appropriately.
1506 *
1507 * It is explicitly legal to specify a recipient structure whose state
1508 * is not HV_TO_BE_SENT; such a recipient is ignored. One suggested way
1509 * of using hv_send_message to send a message to multiple tiles is to set
1510 * up a list of recipients, and then call the routine repeatedly with the
1511 * same list, each time accumulating the number of messages successfully
1512 * sent, until all messages are sent, a permanent error is encountered,
1513 * or the desired number of attempts have been made. When used in this
1514 * way, the routine will deliver each message no more than once to each
1515 * recipient.
1516 *
1517 * Note that a message being successfully delivered to the recipient's
1518 * buffer space does not guarantee that it is received by the recipient,
1519 * either immediately or at any time in the future; the recipient might
1520 * never call hv_receive_message, or could register a different state
1521 * buffer, losing the message.
1522 *
1523 * Specifying the same recipient more than once in the recipient list
1524 * is an error, which will not result in an error return but which may
1525 * or may not result in more than one message being delivered to the
1526 * recipient tile.
1527 *
1528 * buf and buflen specify the message to be sent. buf is a virtual address
1529 * which must be currently mapped in the client's page table; if not, the
1530 * routine returns HV_EFAULT. buflen must be greater than zero and less
1531 * than or equal to HV_MAX_MESSAGE_SIZE, and nrecip must be less than the
1532 * number of tiles to which the sender has access; if not, the routine
1533 * returns HV_EINVAL.
1534 * @param recips List of recipients.
1535 * @param nrecip Number of recipients.
1536 * @param buf Address of message data.
1537 * @param buflen Length of message data.
1538 **/
1539int hv_send_message(HV_Recipient *recips, int nrecip,
1540 HV_VirtAddr buf, int buflen);
1541
1542/** Maximum hypervisor message size, in bytes */
1543#define HV_MAX_MESSAGE_SIZE 28
1544
1545
1546/** Return value from hv_receive_message() */
1547typedef struct
1548{
1549 int msglen; /**< Message length in bytes, or an error code */
1550 __hv32 source; /**< Code identifying message sender (HV_MSG_xxx) */
1551} HV_RcvMsgInfo;
1552
1553#define HV_MSG_TILE 0x0 /**< Message source is another tile */
1554#define HV_MSG_INTR 0x1 /**< Message source is a driver interrupt */
1555
1556/** Receive a message.
1557 *
1558 * This routine retrieves a message from the client's incoming message
1559 * buffer.
1560 *
1561 * Multiple messages sent from a particular sending tile to a particular
1562 * receiving tile are received in the order that they were sent; however,
1563 * no ordering is guaranteed between messages sent by different tiles.
1564 *
1565 * Whenever the a client's message buffer is empty, the first message
1566 * subsequently received will cause the client's MESSAGE_RCV_DWNCL
1567 * interrupt vector to be invoked through the interrupt downcall mechanism
1568 * (see the description of the hv_downcall_dispatch() routine for details
1569 * on downcalls).
1570 *
1571 * Another message-available downcall will not occur until a call to
1572 * this routine is made when the message buffer is empty, and a message
1573 * subsequently arrives. Note that such a downcall could occur while
1574 * this routine is executing. If the calling code does not wish this
1575 * to happen, it is recommended that this routine be called with the
1576 * INTCTRL_1 interrupt masked, or inside an interrupt critical section.
1577 *
1578 * msgstate is the value previously passed to hv_register_message_state().
1579 * buf is the virtual address of the buffer into which the message will
1580 * be written; buflen is the length of the buffer.
1581 *
1582 * This routine returns an HV_RcvMsgInfo structure. The msglen member
1583 * of that structure is the length of the message received, zero if no
1584 * message is available, or HV_E2BIG if the message is too large for the
1585 * specified buffer. If the message is too large, it is not consumed,
1586 * and may be retrieved by a subsequent call to this routine specifying
1587 * a sufficiently large buffer. A buffer which is HV_MAX_MESSAGE_SIZE
1588 * bytes long is guaranteed to be able to receive any possible message.
1589 *
1590 * The source member of the HV_RcvMsgInfo structure describes the sender
1591 * of the message. For messages sent by another client tile via an
1592 * hv_send_message() call, this value is HV_MSG_TILE; for messages sent
1593 * as a result of a device interrupt, this value is HV_MSG_INTR.
1594 */
1595
1596HV_RcvMsgInfo hv_receive_message(HV_MsgState msgstate, HV_VirtAddr buf,
1597 int buflen);
1598
1599
1600/** Start remaining tiles owned by this supervisor. Initially, only one tile
1601 * executes the client program; after it calls this service, the other tiles
1602 * are started. This allows the initial tile to do one-time configuration
1603 * of shared data structures without having to lock them against simultaneous
1604 * access.
1605 */
1606void hv_start_all_tiles(void);
1607
1608
1609/** Open a hypervisor device.
1610 *
1611 * This service initializes an I/O device and its hypervisor driver software,
1612 * and makes it available for use. The open operation is per-device per-chip;
1613 * once it has been performed, the device handle returned may be used in other
1614 * device services calls made by any tile.
1615 *
1616 * @param name Name of the device. A base device name is just a text string
1617 * (say, "pcie"). If there is more than one instance of a device, the
1618 * base name is followed by a slash and a device number (say, "pcie/0").
1619 * Some devices may support further structure beneath those components;
1620 * most notably, devices which require control operations do so by
1621 * supporting reads and/or writes to a control device whose name
1622 * includes a trailing "/ctl" (say, "pcie/0/ctl").
1623 * @param flags Flags (HV_DEV_xxx).
1624 * @return A positive integer device handle, or a negative error code.
1625 */
1626int hv_dev_open(HV_VirtAddr name, __hv32 flags);
1627
1628
1629/** Close a hypervisor device.
1630 *
1631 * This service uninitializes an I/O device and its hypervisor driver
1632 * software, and makes it unavailable for use. The close operation is
1633 * per-device per-chip; once it has been performed, the device is no longer
1634 * available. Normally there is no need to ever call the close service.
1635 *
1636 * @param devhdl Device handle of the device to be closed.
1637 * @return Zero if the close is successful, otherwise, a negative error code.
1638 */
1639int hv_dev_close(int devhdl);
1640
1641
1642/** Read data from a hypervisor device synchronously.
1643 *
1644 * This service transfers data from a hypervisor device to a memory buffer.
1645 * When the service returns, the data has been written from the memory buffer,
1646 * and the buffer will not be further modified by the driver.
1647 *
1648 * No ordering is guaranteed between requests issued from different tiles.
1649 *
1650 * Devices may choose to support both the synchronous and asynchronous read
1651 * operations, only one of them, or neither of them.
1652 *
1653 * @param devhdl Device handle of the device to be read from.
1654 * @param flags Flags (HV_DEV_xxx).
1655 * @param va Virtual address of the target data buffer. This buffer must
1656 * be mapped in the currently installed page table; if not, HV_EFAULT
1657 * may be returned.
1658 * @param len Number of bytes to be transferred.
1659 * @param offset Driver-dependent offset. For a random-access device, this is
1660 * often a byte offset from the beginning of the device; in other cases,
1661 * like on a control device, it may have a different meaning.
1662 * @return A non-negative value if the read was at least partially successful;
1663 * otherwise, a negative error code. The precise interpretation of
1664 * the return value is driver-dependent, but many drivers will return
1665 * the number of bytes successfully transferred.
1666 */
1667int hv_dev_pread(int devhdl, __hv32 flags, HV_VirtAddr va, __hv32 len,
1668 __hv64 offset);
1669
1670#define HV_DEV_NB_EMPTY 0x1 /**< Don't block when no bytes of data can
1671 be transferred. */
1672#define HV_DEV_NB_PARTIAL 0x2 /**< Don't block when some bytes, but not all
1673 of the requested bytes, can be
1674 transferred. */
1675#define HV_DEV_NOCACHE 0x4 /**< The caller warrants that none of the
1676 cache lines which might contain data
1677 from the requested buffer are valid.
1678 Useful with asynchronous operations
1679 only. */
1680
1681#define HV_DEV_ALLFLAGS (HV_DEV_NB_EMPTY | HV_DEV_NB_PARTIAL | \
1682 HV_DEV_NOCACHE) /**< All HV_DEV_xxx flags */
1683
1684/** Write data to a hypervisor device synchronously.
1685 *
1686 * This service transfers data from a memory buffer to a hypervisor device.
1687 * When the service returns, the data has been read from the memory buffer,
1688 * and the buffer may be overwritten by the client; the data may not
1689 * necessarily have been conveyed to the actual hardware I/O interface.
1690 *
1691 * No ordering is guaranteed between requests issued from different tiles.
1692 *
1693 * Devices may choose to support both the synchronous and asynchronous write
1694 * operations, only one of them, or neither of them.
1695 *
1696 * @param devhdl Device handle of the device to be written to.
1697 * @param flags Flags (HV_DEV_xxx).
1698 * @param va Virtual address of the source data buffer. This buffer must
1699 * be mapped in the currently installed page table; if not, HV_EFAULT
1700 * may be returned.
1701 * @param len Number of bytes to be transferred.
1702 * @param offset Driver-dependent offset. For a random-access device, this is
1703 * often a byte offset from the beginning of the device; in other cases,
1704 * like on a control device, it may have a different meaning.
1705 * @return A non-negative value if the write was at least partially successful;
1706 * otherwise, a negative error code. The precise interpretation of
1707 * the return value is driver-dependent, but many drivers will return
1708 * the number of bytes successfully transferred.
1709 */
1710int hv_dev_pwrite(int devhdl, __hv32 flags, HV_VirtAddr va, __hv32 len,
1711 __hv64 offset);
1712
1713
1714/** Interrupt arguments, used in the asynchronous I/O interfaces. */
1715#if CHIP_VA_WIDTH() > 32
1716typedef __hv64 HV_IntArg;
1717#else
1718typedef __hv32 HV_IntArg;
1719#endif
1720
1721/** Interrupt messages are delivered via the mechanism as normal messages,
1722 * but have a message source of HV_DEV_INTR. The message is formatted
1723 * as an HV_IntrMsg structure.
1724 */
1725
1726typedef struct
1727{
1728 HV_IntArg intarg; /**< Interrupt argument, passed to the poll/preada/pwritea
1729 services */
1730 HV_IntArg intdata; /**< Interrupt-specific interrupt data */
1731} HV_IntrMsg;
1732
1733/** Request an interrupt message when a device condition is satisfied.
1734 *
1735 * This service requests that an interrupt message be delivered to the
1736 * requesting tile when a device becomes readable or writable, or when any
1737 * data queued to the device via previous write operations from this tile
1738 * has been actually sent out on the hardware I/O interface. Devices may
1739 * choose to support any, all, or none of the available conditions.
1740 *
1741 * If multiple conditions are specified, only one message will be
1742 * delivered. If the event mask delivered to that interrupt handler
1743 * indicates that some of the conditions have not yet occurred, the
1744 * client must issue another poll() call if it wishes to wait for those
1745 * conditions.
1746 *
1747 * Only one poll may be outstanding per device handle per tile. If more than
1748 * one tile is polling on the same device and condition, they will all be
1749 * notified when it happens. Because of this, clients may not assume that
1750 * the condition signaled is necessarily still true when they request a
1751 * subsequent service; for instance, the readable data which caused the
1752 * poll call to interrupt may have been read by another tile in the interim.
1753 *
1754 * The notification interrupt message could come directly, or via the
1755 * downcall (intctrl1) method, depending on what the tile is doing
1756 * when the condition is satisfied. Note that it is possible for the
1757 * requested interrupt to be delivered after this service is called but
1758 * before it returns.
1759 *
1760 * @param devhdl Device handle of the device to be polled.
1761 * @param events Flags denoting the events which will cause the interrupt to
1762 * be delivered (HV_DEVPOLL_xxx).
1763 * @param intarg Value which will be delivered as the intarg member of the
1764 * eventual interrupt message; the intdata member will be set to a
1765 * mask of HV_DEVPOLL_xxx values indicating which conditions have been
1766 * satisifed.
1767 * @return Zero if the interrupt was successfully scheduled; otherwise, a
1768 * negative error code.
1769 */
1770int hv_dev_poll(int devhdl, __hv32 events, HV_IntArg intarg);
1771
1772#define HV_DEVPOLL_READ 0x1 /**< Test device for readability */
1773#define HV_DEVPOLL_WRITE 0x2 /**< Test device for writability */
1774#define HV_DEVPOLL_FLUSH 0x4 /**< Test device for output drained */
1775
1776
1777/** Cancel a request for an interrupt when a device event occurs.
1778 *
1779 * This service requests that no interrupt be delivered when the events
1780 * noted in the last-issued poll() call happen. Once this service returns,
1781 * the interrupt has been canceled; however, it is possible for the interrupt
1782 * to be delivered after this service is called but before it returns.
1783 *
1784 * @param devhdl Device handle of the device on which to cancel polling.
1785 * @return Zero if the poll was successfully canceled; otherwise, a negative
1786 * error code.
1787 */
1788int hv_dev_poll_cancel(int devhdl);
1789
1790
1791/** NMI information */
1792typedef struct
1793{
1794 /** Result: negative error, or HV_NMI_RESULT_xxx. */
1795 int result;
1796
1797 /** PC from interrupted remote core (if result != HV_NMI_RESULT_FAIL_HV). */
1798 HV_VirtAddr pc;
1799
1800} HV_NMI_Info;
1801
1802/** NMI issued successfully. */
1803#define HV_NMI_RESULT_OK 0
1804
1805/** NMI not issued: remote tile running at client PL with ICS set. */
1806#define HV_NMI_RESULT_FAIL_ICS 1
1807
1808/** NMI not issued: remote tile waiting in hypervisor. */
1809#define HV_NMI_RESULT_FAIL_HV 2
1810
1811/** Force an NMI downcall regardless of the ICS bit of the client. */
1812#define HV_NMI_FLAG_FORCE 0x1
1813
1814/** Send an NMI interrupt request to a particular tile.
1815 *
1816 * This will cause the NMI to be issued on the remote tile regardless
1817 * of the state of the client interrupt mask. However, if the remote
1818 * tile is in the hypervisor, it will not execute the NMI, and
1819 * HV_NMI_RESULT_FAIL_HV will be returned. Similarly, if the remote
1820 * tile is in a client interrupt critical section at the time of the
1821 * NMI, it will not execute the NMI, and HV_NMI_RESULT_FAIL_ICS will
1822 * be returned. In this second case, however, if HV_NMI_FLAG_FORCE
1823 * is set in flags, then the remote tile will enter its NMI interrupt
1824 * vector regardless. Forcing the NMI vector during an interrupt
1825 * critical section will mean that the client can not safely continue
1826 * execution after handling the interrupt.
1827 *
1828 * @param tile Tile to which the NMI request is sent.
1829 * @param info NMI information which is defined by and interpreted by the
1830 * supervisor, is passed to the specified tile, and is
1831 * stored in the SPR register SYSTEM_SAVE_{CLIENT_PL}_2 on the
1832 * specified tile when entering the NMI handler routine.
1833 * Typically, this parameter stores the NMI type, or an aligned
1834 * VA plus some special bits, etc.
1835 * @param flags Flags (HV_NMI_FLAG_xxx).
1836 * @return Information about the requested NMI.
1837 */
1838HV_NMI_Info hv_send_nmi(HV_Coord tile, unsigned long info, __hv64 flags);
1839
1840
1841/** Scatter-gather list for preada/pwritea calls. */
1842typedef struct
1843#if CHIP_VA_WIDTH() <= 32
1844__attribute__ ((packed, aligned(4)))
1845#endif
1846{
1847 HV_PhysAddr pa; /**< Client physical address of the buffer segment. */
1848 HV_PTE pte; /**< Page table entry describing the caching and location
1849 override characteristics of the buffer segment. Some
1850 drivers ignore this element and will require that
1851 the NOCACHE flag be set on their requests. */
1852 __hv32 len; /**< Length of the buffer segment. */
1853} HV_SGL;
1854
1855#define HV_SGL_MAXLEN 16 /**< Maximum number of entries in a scatter-gather
1856 list */
1857
1858/** Read data from a hypervisor device asynchronously.
1859 *
1860 * This service transfers data from a hypervisor device to a memory buffer.
1861 * When the service returns, the read has been scheduled. When the read
1862 * completes, an interrupt message will be delivered, and the buffer will
1863 * not be further modified by the driver.
1864 *
1865 * The number of possible outstanding asynchronous requests is defined by
1866 * each driver, but it is recommended that it be at least two requests
1867 * per tile per device.
1868 *
1869 * No ordering is guaranteed between synchronous and asynchronous requests,
1870 * even those issued on the same tile.
1871 *
1872 * The completion interrupt message could come directly, or via the downcall
1873 * (intctrl1) method, depending on what the tile is doing when the read
1874 * completes. Interrupts do not coalesce; one is delivered for each
1875 * asynchronous I/O request. Note that it is possible for the requested
1876 * interrupt to be delivered after this service is called but before it
1877 * returns.
1878 *
1879 * Devices may choose to support both the synchronous and asynchronous read
1880 * operations, only one of them, or neither of them.
1881 *
1882 * @param devhdl Device handle of the device to be read from.
1883 * @param flags Flags (HV_DEV_xxx).
1884 * @param sgl_len Number of elements in the scatter-gather list.
1885 * @param sgl Scatter-gather list describing the memory to which data will be
1886 * written.
1887 * @param offset Driver-dependent offset. For a random-access device, this is
1888 * often a byte offset from the beginning of the device; in other cases,
1889 * like on a control device, it may have a different meaning.
1890 * @param intarg Value which will be delivered as the intarg member of the
1891 * eventual interrupt message; the intdata member will be set to the
1892 * normal return value from the read request.
1893 * @return Zero if the read was successfully scheduled; otherwise, a negative
1894 * error code. Note that some drivers may choose to pre-validate
1895 * their arguments, and may thus detect certain device error
1896 * conditions at this time rather than when the completion notification
1897 * occurs, but this is not required.
1898 */
1899int hv_dev_preada(int devhdl, __hv32 flags, __hv32 sgl_len,
1900 HV_SGL sgl[/* sgl_len */], __hv64 offset, HV_IntArg intarg);
1901
1902
1903/** Write data to a hypervisor device asynchronously.
1904 *
1905 * This service transfers data from a memory buffer to a hypervisor
1906 * device. When the service returns, the write has been scheduled.
1907 * When the write completes, an interrupt message will be delivered,
1908 * and the buffer may be overwritten by the client; the data may not
1909 * necessarily have been conveyed to the actual hardware I/O interface.
1910 *
1911 * The number of possible outstanding asynchronous requests is defined by
1912 * each driver, but it is recommended that it be at least two requests
1913 * per tile per device.
1914 *
1915 * No ordering is guaranteed between synchronous and asynchronous requests,
1916 * even those issued on the same tile.
1917 *
1918 * The completion interrupt message could come directly, or via the downcall
1919 * (intctrl1) method, depending on what the tile is doing when the read
1920 * completes. Interrupts do not coalesce; one is delivered for each
1921 * asynchronous I/O request. Note that it is possible for the requested
1922 * interrupt to be delivered after this service is called but before it
1923 * returns.
1924 *
1925 * Devices may choose to support both the synchronous and asynchronous write
1926 * operations, only one of them, or neither of them.
1927 *
1928 * @param devhdl Device handle of the device to be read from.
1929 * @param flags Flags (HV_DEV_xxx).
1930 * @param sgl_len Number of elements in the scatter-gather list.
1931 * @param sgl Scatter-gather list describing the memory from which data will be
1932 * read.
1933 * @param offset Driver-dependent offset. For a random-access device, this is
1934 * often a byte offset from the beginning of the device; in other cases,
1935 * like on a control device, it may have a different meaning.
1936 * @param intarg Value which will be delivered as the intarg member of the
1937 * eventual interrupt message; the intdata member will be set to the
1938 * normal return value from the write request.
1939 * @return Zero if the write was successfully scheduled; otherwise, a negative
1940 * error code. Note that some drivers may choose to pre-validate
1941 * their arguments, and may thus detect certain device error
1942 * conditions at this time rather than when the completion notification
1943 * occurs, but this is not required.
1944 */
1945int hv_dev_pwritea(int devhdl, __hv32 flags, __hv32 sgl_len,
1946 HV_SGL sgl[/* sgl_len */], __hv64 offset, HV_IntArg intarg);
1947
1948
1949/** Define a pair of tile and ASID to identify a user process context. */
1950typedef struct
1951{
1952 /** X coordinate, relative to supervisor's top-left coordinate */
1953 unsigned int x:11;
1954
1955 /** Y coordinate, relative to supervisor's top-left coordinate */
1956 unsigned int y:11;
1957
1958 /** ASID of the process on this x,y tile */
1959 HV_ASID asid:10;
1960} HV_Remote_ASID;
1961
1962/** Flush cache and/or TLB state on remote tiles.
1963 *
1964 * @param cache_pa Client physical address to flush from cache (ignored if
1965 * the length encoded in cache_control is zero, or if
1966 * HV_FLUSH_EVICT_L2 is set, or if cache_cpumask is NULL).
1967 * @param cache_control This argument allows you to specify a length of
1968 * physical address space to flush (maximum HV_FLUSH_MAX_CACHE_LEN).
1969 * You can "or" in HV_FLUSH_EVICT_L2 to flush the whole L2 cache.
1970 * You can "or" in HV_FLUSH_EVICT_L1I to flush the whole L1I cache.
1971 * HV_FLUSH_ALL flushes all caches.
1972 * @param cache_cpumask Bitmask (in row-major order, supervisor-relative) of
1973 * tile indices to perform cache flush on. The low bit of the first
1974 * word corresponds to the tile at the upper left-hand corner of the
1975 * supervisor's rectangle. If passed as a NULL pointer, equivalent
1976 * to an empty bitmask. On chips which support hash-for-home caching,
1977 * if passed as -1, equivalent to a mask containing tiles which could
1978 * be doing hash-for-home caching.
1979 * @param tlb_va Virtual address to flush from TLB (ignored if
1980 * tlb_length is zero or tlb_cpumask is NULL).
1981 * @param tlb_length Number of bytes of data to flush from the TLB.
1982 * @param tlb_pgsize Page size to use for TLB flushes.
1983 * tlb_va and tlb_length need not be aligned to this size.
1984 * @param tlb_cpumask Bitmask for tlb flush, like cache_cpumask.
1985 * If passed as a NULL pointer, equivalent to an empty bitmask.
1986 * @param asids Pointer to an HV_Remote_ASID array of tile/ASID pairs to flush.
1987 * @param asidcount Number of HV_Remote_ASID entries in asids[].
1988 * @return Zero for success, or else HV_EINVAL or HV_EFAULT for errors that
1989 * are detected while parsing the arguments.
1990 */
1991int hv_flush_remote(HV_PhysAddr cache_pa, unsigned long cache_control,
1992 unsigned long* cache_cpumask,
1993 HV_VirtAddr tlb_va, unsigned long tlb_length,
1994 unsigned long tlb_pgsize, unsigned long* tlb_cpumask,
1995 HV_Remote_ASID* asids, int asidcount);
1996
1997/** Include in cache_control to ensure a flush of the entire L2. */
1998#define HV_FLUSH_EVICT_L2 (1UL << 31)
1999
2000/** Include in cache_control to ensure a flush of the entire L1I. */
2001#define HV_FLUSH_EVICT_L1I (1UL << 30)
2002
2003/** Maximum legal size to use for the "length" component of cache_control. */
2004#define HV_FLUSH_MAX_CACHE_LEN ((1UL << 30) - 1)
2005
2006/** Use for cache_control to ensure a flush of all caches. */
2007#define HV_FLUSH_ALL -1UL
2008
2009#else /* __ASSEMBLER__ */
2010
2011/** Include in cache_control to ensure a flush of the entire L2. */
2012#define HV_FLUSH_EVICT_L2 (1 << 31)
2013
2014/** Include in cache_control to ensure a flush of the entire L1I. */
2015#define HV_FLUSH_EVICT_L1I (1 << 30)
2016
2017/** Maximum legal size to use for the "length" component of cache_control. */
2018#define HV_FLUSH_MAX_CACHE_LEN ((1 << 30) - 1)
2019
2020/** Use for cache_control to ensure a flush of all caches. */
2021#define HV_FLUSH_ALL -1
2022
2023#endif /* __ASSEMBLER__ */
2024
2025#ifndef __ASSEMBLER__
2026
2027/** Return a 64-bit value corresponding to the PTE if needed */
2028#define hv_pte_val(pte) ((pte).val)
2029
2030/** Cast a 64-bit value to an HV_PTE */
2031#define hv_pte(val) ((HV_PTE) { val })
2032
2033#endif /* !__ASSEMBLER__ */
2034
2035
2036/** Bits in the size of an HV_PTE */
2037#define HV_LOG2_PTE_SIZE 3
2038
2039/** Size of an HV_PTE */
2040#define HV_PTE_SIZE (1 << HV_LOG2_PTE_SIZE)
2041
2042
2043/* Bits in HV_PTE's low word. */
2044#define HV_PTE_INDEX_PRESENT 0 /**< PTE is valid */
2045#define HV_PTE_INDEX_MIGRATING 1 /**< Page is migrating */
2046#define HV_PTE_INDEX_CLIENT0 2 /**< Page client state 0 */
2047#define HV_PTE_INDEX_CLIENT1 3 /**< Page client state 1 */
2048#define HV_PTE_INDEX_NC 4 /**< L1$/L2$ incoherent with L3$ */
2049#define HV_PTE_INDEX_NO_ALLOC_L1 5 /**< Page is uncached in local L1$ */
2050#define HV_PTE_INDEX_NO_ALLOC_L2 6 /**< Page is uncached in local L2$ */
2051#define HV_PTE_INDEX_CACHED_PRIORITY 7 /**< Page is priority cached */
2052#define HV_PTE_INDEX_PAGE 8 /**< PTE describes a page */
2053#define HV_PTE_INDEX_GLOBAL 9 /**< Page is global */
2054#define HV_PTE_INDEX_USER 10 /**< Page is user-accessible */
2055#define HV_PTE_INDEX_ACCESSED 11 /**< Page has been accessed */
2056#define HV_PTE_INDEX_DIRTY 12 /**< Page has been written */
2057 /* Bits 13-14 are reserved for
2058 future use. */
2059#define HV_PTE_INDEX_SUPER 15 /**< Pages ganged together for TLB */
2060#define HV_PTE_INDEX_MODE 16 /**< Page mode; see HV_PTE_MODE_xxx */
2061#define HV_PTE_MODE_BITS 3 /**< Number of bits in mode */
2062#define HV_PTE_INDEX_CLIENT2 19 /**< Page client state 2 */
2063#define HV_PTE_INDEX_LOTAR 20 /**< Page's LOTAR; must be high bits
2064 of word */
2065#define HV_PTE_LOTAR_BITS 12 /**< Number of bits in a LOTAR */
2066
2067/* Bits in HV_PTE's high word. */
2068#define HV_PTE_INDEX_READABLE 32 /**< Page is readable */
2069#define HV_PTE_INDEX_WRITABLE 33 /**< Page is writable */
2070#define HV_PTE_INDEX_EXECUTABLE 34 /**< Page is executable */
2071#define HV_PTE_INDEX_PTFN 35 /**< Page's PTFN; must be high bits
2072 of word */
2073#define HV_PTE_PTFN_BITS 29 /**< Number of bits in a PTFN */
2074
2075/*
2076 * Legal values for the PTE's mode field
2077 */
2078/** Data is not resident in any caches; loads and stores access memory
2079 * directly.
2080 */
2081#define HV_PTE_MODE_UNCACHED 1
2082
2083/** Data is resident in the tile's local L1 and/or L2 caches; if a load
2084 * or store misses there, it goes to memory.
2085 *
2086 * The copy in the local L1$/L2$ is not invalidated when the copy in
2087 * memory is changed.
2088 */
2089#define HV_PTE_MODE_CACHE_NO_L3 2
2090
2091/** Data is resident in the tile's local L1 and/or L2 caches. If a load
2092 * or store misses there, it goes to an L3 cache in a designated tile;
2093 * if it misses there, it goes to memory.
2094 *
2095 * If the NC bit is not set, the copy in the local L1$/L2$ is invalidated
2096 * when the copy in the remote L3$ is changed. Otherwise, such
2097 * invalidation will not occur.
2098 *
2099 * Chips for which CHIP_HAS_COHERENT_LOCAL_CACHE() is 0 do not support
2100 * invalidation from an L3$ to another tile's L1$/L2$. If the NC bit is
2101 * clear on such a chip, no copy is kept in the local L1$/L2$ in this mode.
2102 */
2103#define HV_PTE_MODE_CACHE_TILE_L3 3
2104
2105/** Data is resident in the tile's local L1 and/or L2 caches. If a load
2106 * or store misses there, it goes to an L3 cache in one of a set of
2107 * designated tiles; if it misses there, it goes to memory. Which tile
2108 * is chosen from the set depends upon a hash function applied to the
2109 * physical address. This mode is not supported on chips for which
2110 * CHIP_HAS_CBOX_HOME_MAP() is 0.
2111 *
2112 * If the NC bit is not set, the copy in the local L1$/L2$ is invalidated
2113 * when the copy in the remote L3$ is changed. Otherwise, such
2114 * invalidation will not occur.
2115 *
2116 * Chips for which CHIP_HAS_COHERENT_LOCAL_CACHE() is 0 do not support
2117 * invalidation from an L3$ to another tile's L1$/L2$. If the NC bit is
2118 * clear on such a chip, no copy is kept in the local L1$/L2$ in this mode.
2119 */
2120#define HV_PTE_MODE_CACHE_HASH_L3 4
2121
2122/** Data is not resident in memory; accesses are instead made to an I/O
2123 * device, whose tile coordinates are given by the PTE's LOTAR field.
2124 * This mode is only supported on chips for which CHIP_HAS_MMIO() is 1.
2125 * The EXECUTABLE bit may not be set in an MMIO PTE.
2126 */
2127#define HV_PTE_MODE_MMIO 5
2128
2129
2130/* C wants 1ULL so it is typed as __hv64, but the assembler needs just numbers.
2131 * The assembler can't handle shifts greater than 31, but treats them
2132 * as shifts mod 32, so assembler code must be aware of which word
2133 * the bit belongs in when using these macros.
2134 */
2135#ifdef __ASSEMBLER__
2136#define __HV_PTE_ONE 1 /**< One, for assembler */
2137#else
2138#define __HV_PTE_ONE 1ULL /**< One, for C */
2139#endif
2140
2141/** Is this PTE present?
2142 *
2143 * If this bit is set, this PTE represents a valid translation or level-2
2144 * page table pointer. Otherwise, the page table does not contain a
2145 * translation for the subject virtual pages.
2146 *
2147 * If this bit is not set, the other bits in the PTE are not
2148 * interpreted by the hypervisor, and may contain any value.
2149 */
2150#define HV_PTE_PRESENT (__HV_PTE_ONE << HV_PTE_INDEX_PRESENT)
2151
2152/** Does this PTE map a page?
2153 *
2154 * If this bit is set in a level-0 page table, the entry should be
2155 * interpreted as a level-2 page table entry mapping a jumbo page.
2156 *
2157 * If this bit is set in a level-1 page table, the entry should be
2158 * interpreted as a level-2 page table entry mapping a large page.
2159 *
2160 * This bit should not be modified by the client while PRESENT is set, as
2161 * doing so may race with the hypervisor's update of ACCESSED and DIRTY bits.
2162 *
2163 * In a level-2 page table, this bit is ignored and must be zero.
2164 */
2165#define HV_PTE_PAGE (__HV_PTE_ONE << HV_PTE_INDEX_PAGE)
2166
2167/** Does this PTE implicitly reference multiple pages?
2168 *
2169 * If this bit is set in the page table (either in the level-2 page table,
2170 * or in a higher level page table in conjunction with the PAGE bit)
2171 * then the PTE specifies a range of contiguous pages, not a single page.
2172 * The hv_set_pte_super_shift() allows you to specify the count for
2173 * each level of the page table.
2174 *
2175 * Note: this bit is not supported on TILEPro systems.
2176 */
2177#define HV_PTE_SUPER (__HV_PTE_ONE << HV_PTE_INDEX_SUPER)
2178
2179/** Is this a global (non-ASID) mapping?
2180 *
2181 * If this bit is set, the translations established by this PTE will
2182 * not be flushed from the TLB by the hv_flush_asid() service; they
2183 * will be flushed by the hv_flush_page() or hv_flush_pages() services.
2184 *
2185 * Setting this bit for translations which are identical in all page
2186 * tables (for instance, code and data belonging to a client OS) can
2187 * be very beneficial, as it will reduce the number of TLB misses.
2188 * Note that, while it is not an error which will be detected by the
2189 * hypervisor, it is an extremely bad idea to set this bit for
2190 * translations which are _not_ identical in all page tables.
2191 *
2192 * This bit should not be modified by the client while PRESENT is set, as
2193 * doing so may race with the hypervisor's update of ACCESSED and DIRTY bits.
2194 *
2195 * This bit is ignored in level-1 PTEs unless the Page bit is set.
2196 */
2197#define HV_PTE_GLOBAL (__HV_PTE_ONE << HV_PTE_INDEX_GLOBAL)
2198
2199/** Is this mapping accessible to users?
2200 *
2201 * If this bit is set, code running at any PL will be permitted to
2202 * access the virtual addresses mapped by this PTE. Otherwise, only
2203 * code running at PL 1 or above will be allowed to do so.
2204 *
2205 * This bit should not be modified by the client while PRESENT is set, as
2206 * doing so may race with the hypervisor's update of ACCESSED and DIRTY bits.
2207 *
2208 * This bit is ignored in level-1 PTEs unless the Page bit is set.
2209 */
2210#define HV_PTE_USER (__HV_PTE_ONE << HV_PTE_INDEX_USER)
2211
2212/** Has this mapping been accessed?
2213 *
2214 * This bit is set by the hypervisor when the memory described by the
2215 * translation is accessed for the first time. It is never cleared by
2216 * the hypervisor, but may be cleared by the client. After the bit
2217 * has been cleared, subsequent references are not guaranteed to set
2218 * it again until the translation has been flushed from the TLB.
2219 *
2220 * This bit is ignored in level-1 PTEs unless the Page bit is set.
2221 */
2222#define HV_PTE_ACCESSED (__HV_PTE_ONE << HV_PTE_INDEX_ACCESSED)
2223
2224/** Is this mapping dirty?
2225 *
2226 * This bit is set by the hypervisor when the memory described by the
2227 * translation is written for the first time. It is never cleared by
2228 * the hypervisor, but may be cleared by the client. After the bit
2229 * has been cleared, subsequent references are not guaranteed to set
2230 * it again until the translation has been flushed from the TLB.
2231 *
2232 * This bit is ignored in level-1 PTEs unless the Page bit is set.
2233 */
2234#define HV_PTE_DIRTY (__HV_PTE_ONE << HV_PTE_INDEX_DIRTY)
2235
2236/** Migrating bit in PTE.
2237 *
2238 * This bit is guaranteed not to be inspected or modified by the
2239 * hypervisor. The name is indicative of the suggested use by the client
2240 * to tag pages whose L3 cache is being migrated from one cpu to another.
2241 */
2242#define HV_PTE_MIGRATING (__HV_PTE_ONE << HV_PTE_INDEX_MIGRATING)
2243
2244/** Client-private bit in PTE.
2245 *
2246 * This bit is guaranteed not to be inspected or modified by the
2247 * hypervisor.
2248 */
2249#define HV_PTE_CLIENT0 (__HV_PTE_ONE << HV_PTE_INDEX_CLIENT0)
2250
2251/** Client-private bit in PTE.
2252 *
2253 * This bit is guaranteed not to be inspected or modified by the
2254 * hypervisor.
2255 */
2256#define HV_PTE_CLIENT1 (__HV_PTE_ONE << HV_PTE_INDEX_CLIENT1)
2257
2258/** Client-private bit in PTE.
2259 *
2260 * This bit is guaranteed not to be inspected or modified by the
2261 * hypervisor.
2262 */
2263#define HV_PTE_CLIENT2 (__HV_PTE_ONE << HV_PTE_INDEX_CLIENT2)
2264
2265/** Non-coherent (NC) bit in PTE.
2266 *
2267 * If this bit is set, the mapping that is set up will be non-coherent
2268 * (also known as non-inclusive). This means that changes to the L3
2269 * cache will not cause a local copy to be invalidated. It is generally
2270 * recommended only for read-only mappings.
2271 *
2272 * In level-1 PTEs, if the Page bit is clear, this bit determines how the
2273 * level-2 page table is accessed.
2274 */
2275#define HV_PTE_NC (__HV_PTE_ONE << HV_PTE_INDEX_NC)
2276
2277/** Is this page prevented from filling the L1$?
2278 *
2279 * If this bit is set, the page described by the PTE will not be cached
2280 * the local cpu's L1 cache.
2281 *
2282 * If CHIP_HAS_NC_AND_NOALLOC_BITS() is not true in <chip.h> for this chip,
2283 * it is illegal to use this attribute, and may cause client termination.
2284 *
2285 * In level-1 PTEs, if the Page bit is clear, this bit
2286 * determines how the level-2 page table is accessed.
2287 */
2288#define HV_PTE_NO_ALLOC_L1 (__HV_PTE_ONE << HV_PTE_INDEX_NO_ALLOC_L1)
2289
2290/** Is this page prevented from filling the L2$?
2291 *
2292 * If this bit is set, the page described by the PTE will not be cached
2293 * the local cpu's L2 cache.
2294 *
2295 * If CHIP_HAS_NC_AND_NOALLOC_BITS() is not true in <chip.h> for this chip,
2296 * it is illegal to use this attribute, and may cause client termination.
2297 *
2298 * In level-1 PTEs, if the Page bit is clear, this bit determines how the
2299 * level-2 page table is accessed.
2300 */
2301#define HV_PTE_NO_ALLOC_L2 (__HV_PTE_ONE << HV_PTE_INDEX_NO_ALLOC_L2)
2302
2303/** Is this a priority page?
2304 *
2305 * If this bit is set, the page described by the PTE will be given
2306 * priority in the cache. Normally this translates into allowing the
2307 * page to use only the "red" half of the cache. The client may wish to
2308 * then use the hv_set_caching service to specify that other pages which
2309 * alias this page will use only the "black" half of the cache.
2310 *
2311 * If the Cached Priority bit is clear, the hypervisor uses the
2312 * current hv_set_caching() value to choose how to cache the page.
2313 *
2314 * It is illegal to set the Cached Priority bit if the Non-Cached bit
2315 * is set and the Cached Remotely bit is clear, i.e. if requests to
2316 * the page map directly to memory.
2317 *
2318 * This bit is ignored in level-1 PTEs unless the Page bit is set.
2319 */
2320#define HV_PTE_CACHED_PRIORITY (__HV_PTE_ONE << \
2321 HV_PTE_INDEX_CACHED_PRIORITY)
2322
2323/** Is this a readable mapping?
2324 *
2325 * If this bit is set, code will be permitted to read from (e.g.,
2326 * issue load instructions against) the virtual addresses mapped by
2327 * this PTE.
2328 *
2329 * It is illegal for this bit to be clear if the Writable bit is set.
2330 *
2331 * This bit is ignored in level-1 PTEs unless the Page bit is set.
2332 */
2333#define HV_PTE_READABLE (__HV_PTE_ONE << HV_PTE_INDEX_READABLE)
2334
2335/** Is this a writable mapping?
2336 *
2337 * If this bit is set, code will be permitted to write to (e.g., issue
2338 * store instructions against) the virtual addresses mapped by this
2339 * PTE.
2340 *
2341 * This bit is ignored in level-1 PTEs unless the Page bit is set.
2342 */
2343#define HV_PTE_WRITABLE (__HV_PTE_ONE << HV_PTE_INDEX_WRITABLE)
2344
2345/** Is this an executable mapping?
2346 *
2347 * If this bit is set, code will be permitted to execute from
2348 * (e.g., jump to) the virtual addresses mapped by this PTE.
2349 *
2350 * This bit applies to any processor on the tile, if there are more
2351 * than one.
2352 *
2353 * This bit is ignored in level-1 PTEs unless the Page bit is set.
2354 */
2355#define HV_PTE_EXECUTABLE (__HV_PTE_ONE << HV_PTE_INDEX_EXECUTABLE)
2356
2357/** The width of a LOTAR's x or y bitfield. */
2358#define HV_LOTAR_WIDTH 11
2359
2360/** Converts an x,y pair to a LOTAR value. */
2361#define HV_XY_TO_LOTAR(x, y) ((HV_LOTAR)(((x) << HV_LOTAR_WIDTH) | (y)))
2362
2363/** Extracts the X component of a lotar. */
2364#define HV_LOTAR_X(lotar) ((lotar) >> HV_LOTAR_WIDTH)
2365
2366/** Extracts the Y component of a lotar. */
2367#define HV_LOTAR_Y(lotar) ((lotar) & ((1 << HV_LOTAR_WIDTH) - 1))
2368
2369#ifndef __ASSEMBLER__
2370
2371/** Define accessor functions for a PTE bit. */
2372#define _HV_BIT(name, bit) \
2373static __inline int \
2374hv_pte_get_##name(HV_PTE pte) \
2375{ \
2376 return (pte.val >> HV_PTE_INDEX_##bit) & 1; \
2377} \
2378 \
2379static __inline HV_PTE \
2380hv_pte_set_##name(HV_PTE pte) \
2381{ \
2382 pte.val |= 1ULL << HV_PTE_INDEX_##bit; \
2383 return pte; \
2384} \
2385 \
2386static __inline HV_PTE \
2387hv_pte_clear_##name(HV_PTE pte) \
2388{ \
2389 pte.val &= ~(1ULL << HV_PTE_INDEX_##bit); \
2390 return pte; \
2391}
2392
2393/* Generate accessors to get, set, and clear various PTE flags.
2394 */
2395_HV_BIT(present, PRESENT)
2396_HV_BIT(page, PAGE)
2397_HV_BIT(super, SUPER)
2398_HV_BIT(client0, CLIENT0)
2399_HV_BIT(client1, CLIENT1)
2400_HV_BIT(client2, CLIENT2)
2401_HV_BIT(migrating, MIGRATING)
2402_HV_BIT(nc, NC)
2403_HV_BIT(readable, READABLE)
2404_HV_BIT(writable, WRITABLE)
2405_HV_BIT(executable, EXECUTABLE)
2406_HV_BIT(accessed, ACCESSED)
2407_HV_BIT(dirty, DIRTY)
2408_HV_BIT(no_alloc_l1, NO_ALLOC_L1)
2409_HV_BIT(no_alloc_l2, NO_ALLOC_L2)
2410_HV_BIT(cached_priority, CACHED_PRIORITY)
2411_HV_BIT(global, GLOBAL)
2412_HV_BIT(user, USER)
2413
2414#undef _HV_BIT
2415
2416/** Get the page mode from the PTE.
2417 *
2418 * This field generally determines whether and how accesses to the page
2419 * are cached; the HV_PTE_MODE_xxx symbols define the legal values for the
2420 * page mode. The NC, NO_ALLOC_L1, and NO_ALLOC_L2 bits modify this
2421 * general policy.
2422 */
2423static __inline unsigned int
2424hv_pte_get_mode(const HV_PTE pte)
2425{
2426 return (((__hv32) pte.val) >> HV_PTE_INDEX_MODE) &
2427 ((1 << HV_PTE_MODE_BITS) - 1);
2428}
2429
2430/** Set the page mode into a PTE. See hv_pte_get_mode. */
2431static __inline HV_PTE
2432hv_pte_set_mode(HV_PTE pte, unsigned int val)
2433{
2434 pte.val &= ~(((1ULL << HV_PTE_MODE_BITS) - 1) << HV_PTE_INDEX_MODE);
2435 pte.val |= val << HV_PTE_INDEX_MODE;
2436 return pte;
2437}
2438
2439/** Get the page frame number from the PTE.
2440 *
2441 * This field contains the upper bits of the CPA (client physical
2442 * address) of the target page; the complete CPA is this field with
2443 * HV_LOG2_PAGE_TABLE_ALIGN zero bits appended to it.
2444 *
2445 * For all PTEs in the lowest-level page table, and for all PTEs with
2446 * the Page bit set in all page tables, the CPA must be aligned modulo
2447 * the relevant page size.
2448 */
2449static __inline unsigned long
2450hv_pte_get_ptfn(const HV_PTE pte)
2451{
2452 return pte.val >> HV_PTE_INDEX_PTFN;
2453}
2454
2455/** Set the page table frame number into a PTE. See hv_pte_get_ptfn. */
2456static __inline HV_PTE
2457hv_pte_set_ptfn(HV_PTE pte, unsigned long val)
2458{
2459 pte.val &= ~(((1ULL << HV_PTE_PTFN_BITS)-1) << HV_PTE_INDEX_PTFN);
2460 pte.val |= (__hv64) val << HV_PTE_INDEX_PTFN;
2461 return pte;
2462}
2463
2464/** Get the client physical address from the PTE. See hv_pte_set_ptfn. */
2465static __inline HV_PhysAddr
2466hv_pte_get_pa(const HV_PTE pte)
2467{
2468 return (__hv64) hv_pte_get_ptfn(pte) << HV_LOG2_PAGE_TABLE_ALIGN;
2469}
2470
2471/** Set the client physical address into a PTE. See hv_pte_get_ptfn. */
2472static __inline HV_PTE
2473hv_pte_set_pa(HV_PTE pte, HV_PhysAddr pa)
2474{
2475 return hv_pte_set_ptfn(pte, pa >> HV_LOG2_PAGE_TABLE_ALIGN);
2476}
2477
2478
2479/** Get the remote tile caching this page.
2480 *
2481 * Specifies the remote tile which is providing the L3 cache for this page.
2482 *
2483 * This field is ignored unless the page mode is HV_PTE_MODE_CACHE_TILE_L3.
2484 *
2485 * In level-1 PTEs, if the Page bit is clear, this field determines how the
2486 * level-2 page table is accessed.
2487 */
2488static __inline unsigned int
2489hv_pte_get_lotar(const HV_PTE pte)
2490{
2491 unsigned int lotar = ((__hv32) pte.val) >> HV_PTE_INDEX_LOTAR;
2492
2493 return HV_XY_TO_LOTAR( (lotar >> (HV_PTE_LOTAR_BITS / 2)),
2494 (lotar & ((1 << (HV_PTE_LOTAR_BITS / 2)) - 1)) );
2495}
2496
2497
2498/** Set the remote tile caching a page into a PTE. See hv_pte_get_lotar. */
2499static __inline HV_PTE
2500hv_pte_set_lotar(HV_PTE pte, unsigned int val)
2501{
2502 unsigned int x = HV_LOTAR_X(val);
2503 unsigned int y = HV_LOTAR_Y(val);
2504
2505 pte.val &= ~(((1ULL << HV_PTE_LOTAR_BITS)-1) << HV_PTE_INDEX_LOTAR);
2506 pte.val |= (x << (HV_PTE_INDEX_LOTAR + HV_PTE_LOTAR_BITS / 2)) |
2507 (y << HV_PTE_INDEX_LOTAR);
2508 return pte;
2509}
2510
2511#endif /* !__ASSEMBLER__ */
2512
2513/** Converts a client physical address to a ptfn. */
2514#define HV_CPA_TO_PTFN(p) ((p) >> HV_LOG2_PAGE_TABLE_ALIGN)
2515
2516/** Converts a ptfn to a client physical address. */
2517#define HV_PTFN_TO_CPA(p) (((HV_PhysAddr)(p)) << HV_LOG2_PAGE_TABLE_ALIGN)
2518
2519#if CHIP_VA_WIDTH() > 32
2520
2521/*
2522 * Note that we currently do not allow customizing the page size
2523 * of the L0 pages, but fix them at 4GB, so we do not use the
2524 * "_HV_xxx" nomenclature for the L0 macros.
2525 */
2526
2527/** Log number of HV_PTE entries in L0 page table */
2528#define HV_LOG2_L0_ENTRIES (CHIP_VA_WIDTH() - HV_LOG2_L1_SPAN)
2529
2530/** Number of HV_PTE entries in L0 page table */
2531#define HV_L0_ENTRIES (1 << HV_LOG2_L0_ENTRIES)
2532
2533/** Log size of L0 page table in bytes */
2534#define HV_LOG2_L0_SIZE (HV_LOG2_PTE_SIZE + HV_LOG2_L0_ENTRIES)
2535
2536/** Size of L0 page table in bytes */
2537#define HV_L0_SIZE (1 << HV_LOG2_L0_SIZE)
2538
2539#ifdef __ASSEMBLER__
2540
2541/** Index in L0 for a specific VA */
2542#define HV_L0_INDEX(va) \
2543 (((va) >> HV_LOG2_L1_SPAN) & (HV_L0_ENTRIES - 1))
2544
2545#else
2546
2547/** Index in L1 for a specific VA */
2548#define HV_L0_INDEX(va) \
2549 (((HV_VirtAddr)(va) >> HV_LOG2_L1_SPAN) & (HV_L0_ENTRIES - 1))
2550
2551#endif
2552
2553#endif /* CHIP_VA_WIDTH() > 32 */
2554
2555/** Log number of HV_PTE entries in L1 page table */
2556#define _HV_LOG2_L1_ENTRIES(log2_page_size_large) \
2557 (HV_LOG2_L1_SPAN - log2_page_size_large)
2558
2559/** Number of HV_PTE entries in L1 page table */
2560#define _HV_L1_ENTRIES(log2_page_size_large) \
2561 (1 << _HV_LOG2_L1_ENTRIES(log2_page_size_large))
2562
2563/** Log size of L1 page table in bytes */
2564#define _HV_LOG2_L1_SIZE(log2_page_size_large) \
2565 (HV_LOG2_PTE_SIZE + _HV_LOG2_L1_ENTRIES(log2_page_size_large))
2566
2567/** Size of L1 page table in bytes */
2568#define _HV_L1_SIZE(log2_page_size_large) \
2569 (1 << _HV_LOG2_L1_SIZE(log2_page_size_large))
2570
2571/** Log number of HV_PTE entries in level-2 page table */
2572#define _HV_LOG2_L2_ENTRIES(log2_page_size_large, log2_page_size_small) \
2573 (log2_page_size_large - log2_page_size_small)
2574
2575/** Number of HV_PTE entries in level-2 page table */
2576#define _HV_L2_ENTRIES(log2_page_size_large, log2_page_size_small) \
2577 (1 << _HV_LOG2_L2_ENTRIES(log2_page_size_large, log2_page_size_small))
2578
2579/** Log size of level-2 page table in bytes */
2580#define _HV_LOG2_L2_SIZE(log2_page_size_large, log2_page_size_small) \
2581 (HV_LOG2_PTE_SIZE + \
2582 _HV_LOG2_L2_ENTRIES(log2_page_size_large, log2_page_size_small))
2583
2584/** Size of level-2 page table in bytes */
2585#define _HV_L2_SIZE(log2_page_size_large, log2_page_size_small) \
2586 (1 << _HV_LOG2_L2_SIZE(log2_page_size_large, log2_page_size_small))
2587
2588#ifdef __ASSEMBLER__
2589
2590#if CHIP_VA_WIDTH() > 32
2591
2592/** Index in L1 for a specific VA */
2593#define _HV_L1_INDEX(va, log2_page_size_large) \
2594 (((va) >> log2_page_size_large) & (_HV_L1_ENTRIES(log2_page_size_large) - 1))
2595
2596#else /* CHIP_VA_WIDTH() > 32 */
2597
2598/** Index in L1 for a specific VA */
2599#define _HV_L1_INDEX(va, log2_page_size_large) \
2600 (((va) >> log2_page_size_large))
2601
2602#endif /* CHIP_VA_WIDTH() > 32 */
2603
2604/** Index in level-2 page table for a specific VA */
2605#define _HV_L2_INDEX(va, log2_page_size_large, log2_page_size_small) \
2606 (((va) >> log2_page_size_small) & \
2607 (_HV_L2_ENTRIES(log2_page_size_large, log2_page_size_small) - 1))
2608
2609#else /* __ASSEMBLER __ */
2610
2611#if CHIP_VA_WIDTH() > 32
2612
2613/** Index in L1 for a specific VA */
2614#define _HV_L1_INDEX(va, log2_page_size_large) \
2615 (((HV_VirtAddr)(va) >> log2_page_size_large) & \
2616 (_HV_L1_ENTRIES(log2_page_size_large) - 1))
2617
2618#else /* CHIP_VA_WIDTH() > 32 */
2619
2620/** Index in L1 for a specific VA */
2621#define _HV_L1_INDEX(va, log2_page_size_large) \
2622 (((HV_VirtAddr)(va) >> log2_page_size_large))
2623
2624#endif /* CHIP_VA_WIDTH() > 32 */
2625
2626/** Index in level-2 page table for a specific VA */
2627#define _HV_L2_INDEX(va, log2_page_size_large, log2_page_size_small) \
2628 (((HV_VirtAddr)(va) >> log2_page_size_small) & \
2629 (_HV_L2_ENTRIES(log2_page_size_large, log2_page_size_small) - 1))
2630
2631#endif /* __ASSEMBLER __ */
2632
2633/** Position of the PFN field within the PTE (subset of the PTFN). */
2634#define _HV_PTE_INDEX_PFN(log2_page_size) \
2635 (HV_PTE_INDEX_PTFN + (log2_page_size - HV_LOG2_PAGE_TABLE_ALIGN))
2636
2637/** Length of the PFN field within the PTE (subset of the PTFN). */
2638#define _HV_PTE_INDEX_PFN_BITS(log2_page_size) \
2639 (HV_PTE_INDEX_PTFN_BITS - (log2_page_size - HV_LOG2_PAGE_TABLE_ALIGN))
2640
2641/** Converts a client physical address to a pfn. */
2642#define _HV_CPA_TO_PFN(p, log2_page_size) ((p) >> log2_page_size)
2643
2644/** Converts a pfn to a client physical address. */
2645#define _HV_PFN_TO_CPA(p, log2_page_size) \
2646 (((HV_PhysAddr)(p)) << log2_page_size)
2647
2648/** Converts a ptfn to a pfn. */
2649#define _HV_PTFN_TO_PFN(p, log2_page_size) \
2650 ((p) >> (log2_page_size - HV_LOG2_PAGE_TABLE_ALIGN))
2651
2652/** Converts a pfn to a ptfn. */
2653#define _HV_PFN_TO_PTFN(p, log2_page_size) \
2654 ((p) << (log2_page_size - HV_LOG2_PAGE_TABLE_ALIGN))
2655
2656#endif /* _HV_HV_H */
diff --git a/arch/tile/include/hv/iorpc.h b/arch/tile/include/hv/iorpc.h
deleted file mode 100644
index ddf1604482b3..000000000000
--- a/arch/tile/include/hv/iorpc.h
+++ /dev/null
@@ -1,714 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14#ifndef _HV_IORPC_H_
15#define _HV_IORPC_H_
16
17/**
18 *
19 * Error codes and struct definitions for the IO RPC library.
20 *
21 * The hypervisor's IO RPC component provides a convenient way for
22 * driver authors to proxy system calls between user space, linux, and
23 * the hypervisor driver. The core of the system is a set of Python
24 * files that take ".idl" files as input and generates the following
25 * source code:
26 *
27 * - _rpc_call() routines for use in userspace IO libraries. These
28 * routines take an argument list specified in the .idl file, pack the
29 * arguments in to a buffer, and read or write that buffer via the
30 * Linux iorpc driver.
31 *
32 * - dispatch_read() and dispatch_write() routines that hypervisor
33 * drivers can use to implement most of their dev_pread() and
34 * dev_pwrite() methods. These routines decode the incoming parameter
35 * blob, permission check and translate parameters where appropriate,
36 * and then invoke a callback routine for whichever RPC call has
37 * arrived. The driver simply implements the set of callback
38 * routines.
39 *
40 * The IO RPC system also includes the Linux 'iorpc' driver, which
41 * proxies calls between the userspace library and the hypervisor
42 * driver. The Linux driver is almost entirely device agnostic; it
43 * watches for special flags indicating cases where a memory buffer
44 * address might need to be translated, etc. As a result, driver
45 * writers can avoid many of the problem cases related to registering
46 * hardware resources like memory pages or interrupts. However, the
47 * drivers must be careful to obey the conventions documented below in
48 * order to work properly with the generic Linux iorpc driver.
49 *
50 * @section iorpc_domains Service Domains
51 *
52 * All iorpc-based drivers must support a notion of service domains.
53 * A service domain is basically an application context - state
54 * indicating resources that are allocated to that particular app
55 * which it may access and (perhaps) other applications may not
56 * access. Drivers can support any number of service domains they
57 * choose. In some cases the design is limited by a number of service
58 * domains supported by the IO hardware; in other cases the service
59 * domains are a purely software concept and the driver chooses a
60 * maximum number of domains based on how much state memory it is
61 * willing to preallocate.
62 *
63 * For example, the mPIPE driver only supports as many service domains
64 * as are supported by the mPIPE hardware. This limitation is
65 * required because the hardware implements its own MMIO protection
66 * scheme to allow large MMIO mappings while still protecting small
67 * register ranges within the page that should only be accessed by the
68 * hypervisor.
69 *
70 * In contrast, drivers with no hardware service domain limitations
71 * (for instance the TRIO shim) can implement an arbitrary number of
72 * service domains. In these cases, each service domain is limited to
73 * a carefully restricted set of legal MMIO addresses if necessary to
74 * keep one application from corrupting another application's state.
75 *
76 * @section iorpc_conventions System Call Conventions
77 *
78 * The driver's open routine is responsible for allocating a new
79 * service domain for each hv_dev_open() call. By convention, the
80 * return value from open() should be the service domain number on
81 * success, or GXIO_ERR_NO_SVC_DOM if no more service domains are
82 * available.
83 *
84 * The implementations of hv_dev_pread() and hv_dev_pwrite() are
85 * responsible for validating the devhdl value passed up by the
86 * client. Since the device handle returned by hv_dev_open() should
87 * embed the positive service domain number, drivers should make sure
88 * that DRV_HDL2BITS(devhdl) is a legal service domain. If the client
89 * passes an illegal service domain number, the routine should return
90 * GXIO_ERR_INVAL_SVC_DOM. Once the service domain number has been
91 * validated, the driver can copy to/from the client buffer and call
92 * the dispatch_read() or dispatch_write() methods created by the RPC
93 * generator.
94 *
95 * The hv_dev_close() implementation should reset all service domain
96 * state and put the service domain back on a free list for
97 * reallocation by a future application. In most cases, this will
98 * require executing a hardware reset or drain flow and denying any
99 * MMIO regions that were created for the service domain.
100 *
101 * @section iorpc_data Special Data Types
102 *
103 * The .idl file syntax allows the creation of syscalls with special
104 * parameters that require permission checks or translations as part
105 * of the system call path. Because of limitations in the code
106 * generator, APIs are generally limited to just one of these special
107 * parameters per system call, and they are sometimes required to be
108 * the first or last parameter to the call. Special parameters
109 * include:
110 *
111 * @subsection iorpc_mem_buffer MEM_BUFFER
112 *
113 * The MEM_BUFFER() datatype allows user space to "register" memory
114 * buffers with a device. Registering memory accomplishes two tasks:
115 * Linux keeps track of all buffers that might be modified by a
116 * hardware device, and the hardware device drivers bind registered
117 * buffers to particular hardware resources like ingress NotifRings.
118 * The MEM_BUFFER() idl syntax can take extra flags like ALIGN_64KB,
119 * ALIGN_SELF_SIZE, and FLAGS indicating that memory buffers must have
120 * certain alignment or that the user should be able to pass a "memory
121 * flags" word specifying attributes like nt_hint or IO cache pinning.
122 * The parser will accept multiple MEM_BUFFER() flags.
123 *
124 * Implementations must obey the following conventions when
125 * registering memory buffers via the iorpc flow. These rules are a
126 * result of the Linux driver implementation, which needs to keep
127 * track of how many times a particular page has been registered with
128 * the hardware so that it can release the page when all those
129 * registrations are cleared.
130 *
131 * - Memory registrations that refer to a resource which has already
132 * been bound must return GXIO_ERR_ALREADY_INIT. Thus, it is an
133 * error to register memory twice without resetting (i.e. closing) the
134 * resource in between. This convention keeps the Linux driver from
135 * having to track which particular devices a page is bound to.
136 *
137 * - At present, a memory registration is only cleared when the
138 * service domain is reset. In this case, the Linux driver simply
139 * closes the HV device file handle and then decrements the reference
140 * counts of all pages that were previously registered with the
141 * device.
142 *
143 * - In the future, we may add a mechanism for unregistering memory.
144 * One possible implementation would require that the user specify
145 * which buffer is currently registered. The HV would then verify
146 * that that page was actually the one currently mapped and return
147 * success or failure to Linux, which would then only decrement the
148 * page reference count if the addresses were mapped. Another scheme
149 * might allow Linux to pass a token to the HV to be returned when the
150 * resource is unmapped.
151 *
152 * @subsection iorpc_interrupt INTERRUPT
153 *
154 * The INTERRUPT .idl datatype allows the client to bind hardware
155 * interrupts to a particular combination of IPI parameters - CPU, IPI
156 * PL, and event bit number. This data is passed via a special
157 * datatype so that the Linux driver can validate the CPU and PL and
158 * the HV generic iorpc code can translate client CPUs to real CPUs.
159 *
160 * @subsection iorpc_pollfd_setup POLLFD_SETUP
161 *
162 * The POLLFD_SETUP .idl datatype allows the client to set up hardware
163 * interrupt bindings which are received by Linux but which are made
164 * visible to user processes as state transitions on a file descriptor;
165 * this allows user processes to use Linux primitives, such as poll(), to
166 * await particular hardware events. This data is passed via a special
167 * datatype so that the Linux driver may recognize the pollable file
168 * descriptor and translate it to a set of interrupt target information,
169 * and so that the HV generic iorpc code can translate client CPUs to real
170 * CPUs.
171 *
172 * @subsection iorpc_pollfd POLLFD
173 *
174 * The POLLFD .idl datatype allows manipulation of hardware interrupt
175 * bindings set up via the POLLFD_SETUP datatype; common operations are
176 * resetting the state of the requested interrupt events, and unbinding any
177 * bound interrupts. This data is passed via a special datatype so that
178 * the Linux driver may recognize the pollable file descriptor and
179 * translate it to an interrupt identifier previously supplied by the
180 * hypervisor as the result of an earlier pollfd_setup operation.
181 *
182 * @subsection iorpc_blob BLOB
183 *
184 * The BLOB .idl datatype allows the client to write an arbitrary
185 * length string of bytes up to the hypervisor driver. This can be
186 * useful for passing up large, arbitrarily structured data like
187 * classifier programs. The iorpc stack takes care of validating the
188 * buffer VA and CPA as the data passes up to the hypervisor. Unlike
189 * MEM_BUFFER(), the buffer is not registered - Linux does not bump
190 * page refcounts and the HV driver should not reuse the buffer once
191 * the system call is complete.
192 *
193 * @section iorpc_translation Translating User Space Calls
194 *
195 * The ::iorpc_offset structure describes the formatting of the offset
196 * that is passed to pread() or pwrite() as part of the generated RPC code.
197 * When the user calls up to Linux, the rpc code fills in all the fields of
198 * the offset, including a 16-bit opcode, a 16 bit format indicator, and 32
199 * bits of user-specified "sub-offset". The opcode indicates which syscall
200 * is being requested. The format indicates whether there is a "prefix
201 * struct" at the start of the memory buffer passed to pwrite(), and if so
202 * what data is in that prefix struct. These prefix structs are used to
203 * implement special datatypes like MEM_BUFFER() and INTERRUPT - we arrange
204 * to put data that needs translation and permission checks at the start of
205 * the buffer so that the Linux driver and generic portions of the HV iorpc
206 * code can easily access the data. The 32 bits of user-specified
207 * "sub-offset" are most useful for pread() calls where the user needs to
208 * also pass in a few bits indicating which register to read, etc.
209 *
210 * The Linux iorpc driver watches for system calls that contain prefix
211 * structs so that it can translate parameters and bump reference
212 * counts as appropriate. It does not (currently) have any knowledge
213 * of the per-device opcodes - it doesn't care what operation you're
214 * doing to mPIPE, so long as it can do all the generic book-keeping.
215 * The hv/iorpc.h header file defines all of the generic encoding bits
216 * needed to translate iorpc calls without knowing which particular
217 * opcode is being issued.
218 *
219 * @section iorpc_globals Global iorpc Calls
220 *
221 * Implementing mmap() required adding some special iorpc syscalls
222 * that are only called by the Linux driver, never by userspace.
223 * These include get_mmio_base() and check_mmio_offset(). These
224 * routines are described in globals.idl and must be included in every
225 * iorpc driver. By providing these routines in every driver, Linux's
226 * mmap implementation can easily get the PTE bits it needs and
227 * validate the PA offset without needing to know the per-device
228 * opcodes to perform those tasks.
229 *
230 * @section iorpc_kernel Supporting gxio APIs in the Kernel
231 *
232 * The iorpc code generator also supports generation of kernel code
233 * implementing the gxio APIs. This capability is currently used by
234 * the mPIPE network driver, and will likely be used by the TRIO root
235 * complex and endpoint drivers and perhaps an in-kernel crypto
236 * driver. Each driver that wants to instantiate iorpc calls in the
237 * kernel needs to generate a kernel version of the generate rpc code
238 * and (probably) copy any related gxio source files into the kernel.
239 * The mPIPE driver provides a good example of this pattern.
240 */
241
242#ifdef __KERNEL__
243#include <linux/stddef.h>
244#else
245#include <stddef.h>
246#endif
247
248#if defined(__HV__)
249#include <hv/hypervisor.h>
250#elif defined(__KERNEL__)
251#include <hv/hypervisor.h>
252#include <linux/types.h>
253#else
254#include <stdint.h>
255#endif
256
257
258/** Code indicating translation services required within the RPC path.
259 * These indicate whether there is a translatable struct at the start
260 * of the RPC buffer and what information that struct contains.
261 */
262enum iorpc_format_e
263{
264 /** No translation required, no prefix struct. */
265 IORPC_FORMAT_NONE,
266
267 /** No translation required, no prefix struct, no access to this
268 * operation from user space. */
269 IORPC_FORMAT_NONE_NOUSER,
270
271 /** Prefix struct contains user VA and size. */
272 IORPC_FORMAT_USER_MEM,
273
274 /** Prefix struct contains CPA, size, and homing bits. */
275 IORPC_FORMAT_KERNEL_MEM,
276
277 /** Prefix struct contains interrupt. */
278 IORPC_FORMAT_KERNEL_INTERRUPT,
279
280 /** Prefix struct contains user-level interrupt. */
281 IORPC_FORMAT_USER_INTERRUPT,
282
283 /** Prefix struct contains pollfd_setup (interrupt information). */
284 IORPC_FORMAT_KERNEL_POLLFD_SETUP,
285
286 /** Prefix struct contains user-level pollfd_setup (file descriptor). */
287 IORPC_FORMAT_USER_POLLFD_SETUP,
288
289 /** Prefix struct contains pollfd (interrupt cookie). */
290 IORPC_FORMAT_KERNEL_POLLFD,
291
292 /** Prefix struct contains user-level pollfd (file descriptor). */
293 IORPC_FORMAT_USER_POLLFD,
294};
295
296
297/** Generate an opcode given format and code. */
298#define IORPC_OPCODE(FORMAT, CODE) (((FORMAT) << 16) | (CODE))
299
300/** The offset passed through the read() and write() system calls
301 combines an opcode with 32 bits of user-specified offset. */
302union iorpc_offset
303{
304#ifndef __BIG_ENDIAN__
305 uint64_t offset; /**< All bits. */
306
307 struct
308 {
309 uint16_t code; /**< RPC code. */
310 uint16_t format; /**< iorpc_format_e */
311 uint32_t sub_offset; /**< caller-specified offset. */
312 };
313
314 uint32_t opcode; /**< Opcode combines code & format. */
315#else
316 uint64_t offset; /**< All bits. */
317
318 struct
319 {
320 uint32_t sub_offset; /**< caller-specified offset. */
321 uint16_t format; /**< iorpc_format_e */
322 uint16_t code; /**< RPC code. */
323 };
324
325 struct
326 {
327 uint32_t padding;
328 uint32_t opcode; /**< Opcode combines code & format. */
329 };
330#endif
331};
332
333
334/** Homing and cache hinting bits that can be used by IO devices. */
335struct iorpc_mem_attr
336{
337 unsigned int lotar_x:4; /**< lotar X bits (or Gx page_mask). */
338 unsigned int lotar_y:4; /**< lotar Y bits (or Gx page_offset). */
339 unsigned int hfh:1; /**< Uses hash-for-home. */
340 unsigned int nt_hint:1; /**< Non-temporal hint. */
341 unsigned int io_pin:1; /**< Only fill 'IO' cache ways. */
342};
343
344/** Set the nt_hint bit. */
345#define IORPC_MEM_BUFFER_FLAG_NT_HINT (1 << 0)
346
347/** Set the IO pin bit. */
348#define IORPC_MEM_BUFFER_FLAG_IO_PIN (1 << 1)
349
350
351/** A structure used to describe memory registration. Different
352 protection levels describe memory differently, so this union
353 contains all the different possible descriptions. As a request
354 moves up the call chain, each layer translates from one
355 description format to the next. In particular, the Linux iorpc
356 driver translates user VAs into CPAs and homing parameters. */
357union iorpc_mem_buffer
358{
359 struct
360 {
361 uint64_t va; /**< User virtual address. */
362 uint64_t size; /**< Buffer size. */
363 unsigned int flags; /**< nt_hint, IO pin. */
364 }
365 user; /**< Buffer as described by user apps. */
366
367 struct
368 {
369 unsigned long long cpa; /**< Client physical address. */
370#if defined(__KERNEL__) || defined(__HV__)
371 size_t size; /**< Buffer size. */
372 HV_PTE pte; /**< PTE describing memory homing. */
373#else
374 uint64_t size;
375 uint64_t pte;
376#endif
377 unsigned int flags; /**< nt_hint, IO pin. */
378 }
379 kernel; /**< Buffer as described by kernel. */
380
381 struct
382 {
383 unsigned long long pa; /**< Physical address. */
384 size_t size; /**< Buffer size. */
385 struct iorpc_mem_attr attr; /**< Homing and locality hint bits. */
386 }
387 hv; /**< Buffer parameters for HV driver. */
388};
389
390
391/** A structure used to describe interrupts. The format differs slightly
392 * for user and kernel interrupts. As with the mem_buffer_t, translation
393 * between the formats is done at each level. */
394union iorpc_interrupt
395{
396 struct
397 {
398 int cpu; /**< CPU. */
399 int event; /**< evt_num */
400 }
401 user; /**< Interrupt as described by user applications. */
402
403 struct
404 {
405 int x; /**< X coord. */
406 int y; /**< Y coord. */
407 int ipi; /**< int_num */
408 int event; /**< evt_num */
409 }
410 kernel; /**< Interrupt as described by the kernel. */
411
412};
413
414
415/** A structure used to describe interrupts used with poll(). The format
416 * differs significantly for requests from user to kernel, and kernel to
417 * hypervisor. As with the mem_buffer_t, translation between the formats
418 * is done at each level. */
419union iorpc_pollfd_setup
420{
421 struct
422 {
423 int fd; /**< Pollable file descriptor. */
424 }
425 user; /**< pollfd_setup as described by user applications. */
426
427 struct
428 {
429 int x; /**< X coord. */
430 int y; /**< Y coord. */
431 int ipi; /**< int_num */
432 int event; /**< evt_num */
433 }
434 kernel; /**< pollfd_setup as described by the kernel. */
435
436};
437
438
439/** A structure used to describe previously set up interrupts used with
440 * poll(). The format differs significantly for requests from user to
441 * kernel, and kernel to hypervisor. As with the mem_buffer_t, translation
442 * between the formats is done at each level. */
443union iorpc_pollfd
444{
445 struct
446 {
447 int fd; /**< Pollable file descriptor. */
448 }
449 user; /**< pollfd as described by user applications. */
450
451 struct
452 {
453 int cookie; /**< hv cookie returned by the pollfd_setup operation. */
454 }
455 kernel; /**< pollfd as described by the kernel. */
456
457};
458
459
460/** The various iorpc devices use error codes from -1100 to -1299.
461 *
462 * This range is distinct from netio (-700 to -799), the hypervisor
463 * (-800 to -899), tilepci (-900 to -999), ilib (-1000 to -1099),
464 * gxcr (-1300 to -1399) and gxpci (-1400 to -1499).
465 */
466enum gxio_err_e {
467
468 /** Largest iorpc error number. */
469 GXIO_ERR_MAX = -1101,
470
471
472 /********************************************************/
473 /* Generic Error Codes */
474 /********************************************************/
475
476 /** Bad RPC opcode - possible version incompatibility. */
477 GXIO_ERR_OPCODE = -1101,
478
479 /** Invalid parameter. */
480 GXIO_ERR_INVAL = -1102,
481
482 /** Memory buffer did not meet alignment requirements. */
483 GXIO_ERR_ALIGNMENT = -1103,
484
485 /** Memory buffers must be coherent and cacheable. */
486 GXIO_ERR_COHERENCE = -1104,
487
488 /** Resource already initialized. */
489 GXIO_ERR_ALREADY_INIT = -1105,
490
491 /** No service domains available. */
492 GXIO_ERR_NO_SVC_DOM = -1106,
493
494 /** Illegal service domain number. */
495 GXIO_ERR_INVAL_SVC_DOM = -1107,
496
497 /** Illegal MMIO address. */
498 GXIO_ERR_MMIO_ADDRESS = -1108,
499
500 /** Illegal interrupt binding. */
501 GXIO_ERR_INTERRUPT = -1109,
502
503 /** Unreasonable client memory. */
504 GXIO_ERR_CLIENT_MEMORY = -1110,
505
506 /** No more IOTLB entries. */
507 GXIO_ERR_IOTLB_ENTRY = -1111,
508
509 /** Invalid memory size. */
510 GXIO_ERR_INVAL_MEMORY_SIZE = -1112,
511
512 /** Unsupported operation. */
513 GXIO_ERR_UNSUPPORTED_OP = -1113,
514
515 /** Insufficient DMA credits. */
516 GXIO_ERR_DMA_CREDITS = -1114,
517
518 /** Operation timed out. */
519 GXIO_ERR_TIMEOUT = -1115,
520
521 /** No such device or object. */
522 GXIO_ERR_NO_DEVICE = -1116,
523
524 /** Device or resource busy. */
525 GXIO_ERR_BUSY = -1117,
526
527 /** I/O error. */
528 GXIO_ERR_IO = -1118,
529
530 /** Permissions error. */
531 GXIO_ERR_PERM = -1119,
532
533
534
535 /********************************************************/
536 /* Test Device Error Codes */
537 /********************************************************/
538
539 /** Illegal register number. */
540 GXIO_TEST_ERR_REG_NUMBER = -1120,
541
542 /** Illegal buffer slot. */
543 GXIO_TEST_ERR_BUFFER_SLOT = -1121,
544
545
546 /********************************************************/
547 /* MPIPE Error Codes */
548 /********************************************************/
549
550
551 /** Invalid buffer size. */
552 GXIO_MPIPE_ERR_INVAL_BUFFER_SIZE = -1131,
553
554 /** Cannot allocate buffer stack. */
555 GXIO_MPIPE_ERR_NO_BUFFER_STACK = -1140,
556
557 /** Invalid buffer stack number. */
558 GXIO_MPIPE_ERR_BAD_BUFFER_STACK = -1141,
559
560 /** Cannot allocate NotifRing. */
561 GXIO_MPIPE_ERR_NO_NOTIF_RING = -1142,
562
563 /** Invalid NotifRing number. */
564 GXIO_MPIPE_ERR_BAD_NOTIF_RING = -1143,
565
566 /** Cannot allocate NotifGroup. */
567 GXIO_MPIPE_ERR_NO_NOTIF_GROUP = -1144,
568
569 /** Invalid NotifGroup number. */
570 GXIO_MPIPE_ERR_BAD_NOTIF_GROUP = -1145,
571
572 /** Cannot allocate bucket. */
573 GXIO_MPIPE_ERR_NO_BUCKET = -1146,
574
575 /** Invalid bucket number. */
576 GXIO_MPIPE_ERR_BAD_BUCKET = -1147,
577
578 /** Cannot allocate eDMA ring. */
579 GXIO_MPIPE_ERR_NO_EDMA_RING = -1148,
580
581 /** Invalid eDMA ring number. */
582 GXIO_MPIPE_ERR_BAD_EDMA_RING = -1149,
583
584 /** Invalid channel number. */
585 GXIO_MPIPE_ERR_BAD_CHANNEL = -1150,
586
587 /** Bad configuration. */
588 GXIO_MPIPE_ERR_BAD_CONFIG = -1151,
589
590 /** Empty iqueue. */
591 GXIO_MPIPE_ERR_IQUEUE_EMPTY = -1152,
592
593 /** Empty rules. */
594 GXIO_MPIPE_ERR_RULES_EMPTY = -1160,
595
596 /** Full rules. */
597 GXIO_MPIPE_ERR_RULES_FULL = -1161,
598
599 /** Corrupt rules. */
600 GXIO_MPIPE_ERR_RULES_CORRUPT = -1162,
601
602 /** Invalid rules. */
603 GXIO_MPIPE_ERR_RULES_INVALID = -1163,
604
605 /** Classifier is too big. */
606 GXIO_MPIPE_ERR_CLASSIFIER_TOO_BIG = -1170,
607
608 /** Classifier is too complex. */
609 GXIO_MPIPE_ERR_CLASSIFIER_TOO_COMPLEX = -1171,
610
611 /** Classifier has bad header. */
612 GXIO_MPIPE_ERR_CLASSIFIER_BAD_HEADER = -1172,
613
614 /** Classifier has bad contents. */
615 GXIO_MPIPE_ERR_CLASSIFIER_BAD_CONTENTS = -1173,
616
617 /** Classifier encountered invalid symbol. */
618 GXIO_MPIPE_ERR_CLASSIFIER_INVAL_SYMBOL = -1174,
619
620 /** Classifier encountered invalid bounds. */
621 GXIO_MPIPE_ERR_CLASSIFIER_INVAL_BOUNDS = -1175,
622
623 /** Classifier encountered invalid relocation. */
624 GXIO_MPIPE_ERR_CLASSIFIER_INVAL_RELOCATION = -1176,
625
626 /** Classifier encountered undefined symbol. */
627 GXIO_MPIPE_ERR_CLASSIFIER_UNDEF_SYMBOL = -1177,
628
629
630 /********************************************************/
631 /* TRIO Error Codes */
632 /********************************************************/
633
634 /** Cannot allocate memory map region. */
635 GXIO_TRIO_ERR_NO_MEMORY_MAP = -1180,
636
637 /** Invalid memory map region number. */
638 GXIO_TRIO_ERR_BAD_MEMORY_MAP = -1181,
639
640 /** Cannot allocate scatter queue. */
641 GXIO_TRIO_ERR_NO_SCATTER_QUEUE = -1182,
642
643 /** Invalid scatter queue number. */
644 GXIO_TRIO_ERR_BAD_SCATTER_QUEUE = -1183,
645
646 /** Cannot allocate push DMA ring. */
647 GXIO_TRIO_ERR_NO_PUSH_DMA_RING = -1184,
648
649 /** Invalid push DMA ring index. */
650 GXIO_TRIO_ERR_BAD_PUSH_DMA_RING = -1185,
651
652 /** Cannot allocate pull DMA ring. */
653 GXIO_TRIO_ERR_NO_PULL_DMA_RING = -1186,
654
655 /** Invalid pull DMA ring index. */
656 GXIO_TRIO_ERR_BAD_PULL_DMA_RING = -1187,
657
658 /** Cannot allocate PIO region. */
659 GXIO_TRIO_ERR_NO_PIO = -1188,
660
661 /** Invalid PIO region index. */
662 GXIO_TRIO_ERR_BAD_PIO = -1189,
663
664 /** Cannot allocate ASID. */
665 GXIO_TRIO_ERR_NO_ASID = -1190,
666
667 /** Invalid ASID. */
668 GXIO_TRIO_ERR_BAD_ASID = -1191,
669
670
671 /********************************************************/
672 /* MICA Error Codes */
673 /********************************************************/
674
675 /** No such accelerator type. */
676 GXIO_MICA_ERR_BAD_ACCEL_TYPE = -1220,
677
678 /** Cannot allocate context. */
679 GXIO_MICA_ERR_NO_CONTEXT = -1221,
680
681 /** PKA command queue is full, can't add another command. */
682 GXIO_MICA_ERR_PKA_CMD_QUEUE_FULL = -1222,
683
684 /** PKA result queue is empty, can't get a result from the queue. */
685 GXIO_MICA_ERR_PKA_RESULT_QUEUE_EMPTY = -1223,
686
687 /********************************************************/
688 /* GPIO Error Codes */
689 /********************************************************/
690
691 /** Pin not available. Either the physical pin does not exist, or
692 * it is reserved by the hypervisor for system usage. */
693 GXIO_GPIO_ERR_PIN_UNAVAILABLE = -1240,
694
695 /** Pin busy. The pin exists, and is available for use via GXIO, but
696 * it has been attached by some other process or driver. */
697 GXIO_GPIO_ERR_PIN_BUSY = -1241,
698
699 /** Cannot access unattached pin. One or more of the pins being
700 * manipulated by this call are not attached to the requesting
701 * context. */
702 GXIO_GPIO_ERR_PIN_UNATTACHED = -1242,
703
704 /** Invalid I/O mode for pin. The wiring of the pin in the system
705 * is such that the I/O mode or electrical control parameters
706 * requested could cause damage. */
707 GXIO_GPIO_ERR_PIN_INVALID_MODE = -1243,
708
709 /** Smallest iorpc error number. */
710 GXIO_ERR_MIN = -1299
711};
712
713
714#endif /* !_HV_IORPC_H_ */
diff --git a/arch/tile/include/hv/netio_errors.h b/arch/tile/include/hv/netio_errors.h
deleted file mode 100644
index e1591bff61b5..000000000000
--- a/arch/tile/include/hv/netio_errors.h
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * Error codes returned from NetIO routines.
17 */
18
19#ifndef __NETIO_ERRORS_H__
20#define __NETIO_ERRORS_H__
21
22/**
23 * @addtogroup error
24 *
25 * @brief The error codes returned by NetIO functions.
26 *
27 * NetIO functions return 0 (defined as ::NETIO_NO_ERROR) on success, and
28 * a negative value if an error occurs.
29 *
30 * In cases where a NetIO function failed due to a error reported by
31 * system libraries, the error code will be the negation of the
32 * system errno at the time of failure. The @ref netio_strerror()
33 * function will deliver error strings for both NetIO and system error
34 * codes.
35 *
36 * @{
37 */
38
39/** The set of all NetIO errors. */
40typedef enum
41{
42 /** Operation successfully completed. */
43 NETIO_NO_ERROR = 0,
44
45 /** A packet was successfully retrieved from an input queue. */
46 NETIO_PKT = 0,
47
48 /** Largest NetIO error number. */
49 NETIO_ERR_MAX = -701,
50
51 /** The tile is not registered with the IPP. */
52 NETIO_NOT_REGISTERED = -701,
53
54 /** No packet was available to retrieve from the input queue. */
55 NETIO_NOPKT = -702,
56
57 /** The requested function is not implemented. */
58 NETIO_NOT_IMPLEMENTED = -703,
59
60 /** On a registration operation, the target queue already has the maximum
61 * number of tiles registered for it, and no more may be added. On a
62 * packet send operation, the output queue is full and nothing more can
63 * be queued until some of the queued packets are actually transmitted. */
64 NETIO_QUEUE_FULL = -704,
65
66 /** The calling process or thread is not bound to exactly one CPU. */
67 NETIO_BAD_AFFINITY = -705,
68
69 /** Cannot allocate memory on requested controllers. */
70 NETIO_CANNOT_HOME = -706,
71
72 /** On a registration operation, the IPP specified is not configured
73 * to support the options requested; for instance, the application
74 * wants a specific type of tagged headers which the configured IPP
75 * doesn't support. Or, the supplied configuration information is
76 * not self-consistent, or is out of range; for instance, specifying
77 * both NETIO_RECV and NETIO_NO_RECV, or asking for more than
78 * NETIO_MAX_SEND_BUFFERS to be preallocated. On a VLAN or bucket
79 * configure operation, the number of items, or the base item, was
80 * out of range.
81 */
82 NETIO_BAD_CONFIG = -707,
83
84 /** Too many tiles have registered to transmit packets. */
85 NETIO_TOOMANY_XMIT = -708,
86
87 /** Packet transmission was attempted on a queue which was registered
88 with transmit disabled. */
89 NETIO_UNREG_XMIT = -709,
90
91 /** This tile is already registered with the IPP. */
92 NETIO_ALREADY_REGISTERED = -710,
93
94 /** The Ethernet link is down. The application should try again later. */
95 NETIO_LINK_DOWN = -711,
96
97 /** An invalid memory buffer has been specified. This may be an unmapped
98 * virtual address, or one which does not meet alignment requirements.
99 * For netio_input_register(), this error may be returned when multiple
100 * processes specify different memory regions to be used for NetIO
101 * buffers. That can happen if these processes specify explicit memory
102 * regions with the ::NETIO_FIXED_BUFFER_VA flag, or if tmc_cmem_init()
103 * has not been called by a common ancestor of the processes.
104 */
105 NETIO_FAULT = -712,
106
107 /** Cannot combine user-managed shared memory and cache coherence. */
108 NETIO_BAD_CACHE_CONFIG = -713,
109
110 /** Smallest NetIO error number. */
111 NETIO_ERR_MIN = -713,
112
113#ifndef __DOXYGEN__
114 /** Used internally to mean that no response is needed; never returned to
115 * an application. */
116 NETIO_NO_RESPONSE = 1
117#endif
118} netio_error_t;
119
120/** @} */
121
122#endif /* __NETIO_ERRORS_H__ */
diff --git a/arch/tile/include/hv/netio_intf.h b/arch/tile/include/hv/netio_intf.h
deleted file mode 100644
index 8d20972aba2c..000000000000
--- a/arch/tile/include/hv/netio_intf.h
+++ /dev/null
@@ -1,2975 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * NetIO interface structures and macros.
17 */
18
19#ifndef __NETIO_INTF_H__
20#define __NETIO_INTF_H__
21
22#include <hv/netio_errors.h>
23
24#ifdef __KERNEL__
25#include <linux/types.h>
26#else
27#include <stdint.h>
28#endif
29
30#if !defined(__HV__) && !defined(__BOGUX__) && !defined(__KERNEL__)
31#include <assert.h>
32#define netio_assert assert /**< Enable assertions from macros */
33#else
34#define netio_assert(...) ((void)(0)) /**< Disable assertions from macros */
35#endif
36
37/*
38 * If none of these symbols are defined, we're building libnetio in an
39 * environment where we have pthreads, so we'll enable locking.
40 */
41#if !defined(__HV__) && !defined(__BOGUX__) && !defined(__KERNEL__) && \
42 !defined(__NEWLIB__)
43#define _NETIO_PTHREAD /**< Include a mutex in netio_queue_t below */
44
45/*
46 * If NETIO_UNLOCKED is defined, we don't do use per-cpu locks on
47 * per-packet NetIO operations. We still do pthread locking on things
48 * like netio_input_register, though. This is used for building
49 * libnetio_unlocked.
50 */
51#ifndef NETIO_UNLOCKED
52
53/* Avoid PLT overhead by using our own inlined per-cpu lock. */
54#include <sched.h>
55typedef int _netio_percpu_mutex_t;
56
57static __inline int
58_netio_percpu_mutex_init(_netio_percpu_mutex_t* lock)
59{
60 *lock = 0;
61 return 0;
62}
63
64static __inline int
65_netio_percpu_mutex_lock(_netio_percpu_mutex_t* lock)
66{
67 while (__builtin_expect(__insn_tns(lock), 0))
68 sched_yield();
69 return 0;
70}
71
72static __inline int
73_netio_percpu_mutex_unlock(_netio_percpu_mutex_t* lock)
74{
75 *lock = 0;
76 return 0;
77}
78
79#else /* NETIO_UNLOCKED */
80
81/* Don't do any locking for per-packet NetIO operations. */
82typedef int _netio_percpu_mutex_t;
83#define _netio_percpu_mutex_init(L)
84#define _netio_percpu_mutex_lock(L)
85#define _netio_percpu_mutex_unlock(L)
86
87#endif /* NETIO_UNLOCKED */
88#endif /* !__HV__, !__BOGUX, !__KERNEL__, !__NEWLIB__ */
89
90/** How many tiles can register for a given queue.
91 * @ingroup setup */
92#define NETIO_MAX_TILES_PER_QUEUE 64
93
94
95/** Largest permissible queue identifier.
96 * @ingroup setup */
97#define NETIO_MAX_QUEUE_ID 255
98
99
100#ifndef __DOXYGEN__
101
102/* Metadata packet checksum/ethertype flags. */
103
104/** The L4 checksum has not been calculated. */
105#define _NETIO_PKT_NO_L4_CSUM_SHIFT 0
106#define _NETIO_PKT_NO_L4_CSUM_RMASK 1
107#define _NETIO_PKT_NO_L4_CSUM_MASK \
108 (_NETIO_PKT_NO_L4_CSUM_RMASK << _NETIO_PKT_NO_L4_CSUM_SHIFT)
109
110/** The L3 checksum has not been calculated. */
111#define _NETIO_PKT_NO_L3_CSUM_SHIFT 1
112#define _NETIO_PKT_NO_L3_CSUM_RMASK 1
113#define _NETIO_PKT_NO_L3_CSUM_MASK \
114 (_NETIO_PKT_NO_L3_CSUM_RMASK << _NETIO_PKT_NO_L3_CSUM_SHIFT)
115
116/** The L3 checksum is incorrect (or perhaps has not been calculated). */
117#define _NETIO_PKT_BAD_L3_CSUM_SHIFT 2
118#define _NETIO_PKT_BAD_L3_CSUM_RMASK 1
119#define _NETIO_PKT_BAD_L3_CSUM_MASK \
120 (_NETIO_PKT_BAD_L3_CSUM_RMASK << _NETIO_PKT_BAD_L3_CSUM_SHIFT)
121
122/** The Ethernet packet type is unrecognized. */
123#define _NETIO_PKT_TYPE_UNRECOGNIZED_SHIFT 3
124#define _NETIO_PKT_TYPE_UNRECOGNIZED_RMASK 1
125#define _NETIO_PKT_TYPE_UNRECOGNIZED_MASK \
126 (_NETIO_PKT_TYPE_UNRECOGNIZED_RMASK << \
127 _NETIO_PKT_TYPE_UNRECOGNIZED_SHIFT)
128
129/* Metadata packet type flags. */
130
131/** Where the packet type bits are; this field is the index into
132 * _netio_pkt_info. */
133#define _NETIO_PKT_TYPE_SHIFT 4
134#define _NETIO_PKT_TYPE_RMASK 0x3F
135
136/** How many VLAN tags the packet has, and, if we have two, which one we
137 * actually grouped on. A VLAN within a proprietary (Marvell or Broadcom)
138 * tag is counted here. */
139#define _NETIO_PKT_VLAN_SHIFT 4
140#define _NETIO_PKT_VLAN_RMASK 0x3
141#define _NETIO_PKT_VLAN_MASK \
142 (_NETIO_PKT_VLAN_RMASK << _NETIO_PKT_VLAN_SHIFT)
143#define _NETIO_PKT_VLAN_NONE 0 /* No VLAN tag. */
144#define _NETIO_PKT_VLAN_ONE 1 /* One VLAN tag. */
145#define _NETIO_PKT_VLAN_TWO_OUTER 2 /* Two VLAN tags, outer one used. */
146#define _NETIO_PKT_VLAN_TWO_INNER 3 /* Two VLAN tags, inner one used. */
147
148/** Which proprietary tags the packet has. */
149#define _NETIO_PKT_TAG_SHIFT 6
150#define _NETIO_PKT_TAG_RMASK 0x3
151#define _NETIO_PKT_TAG_MASK \
152 (_NETIO_PKT_TAG_RMASK << _NETIO_PKT_TAG_SHIFT)
153#define _NETIO_PKT_TAG_NONE 0 /* No proprietary tags. */
154#define _NETIO_PKT_TAG_MRVL 1 /* Marvell HyperG.Stack tags. */
155#define _NETIO_PKT_TAG_MRVL_EXT 2 /* HyperG.Stack extended tags. */
156#define _NETIO_PKT_TAG_BRCM 3 /* Broadcom HiGig tags. */
157
158/** Whether a packet has an LLC + SNAP header. */
159#define _NETIO_PKT_SNAP_SHIFT 8
160#define _NETIO_PKT_SNAP_RMASK 0x1
161#define _NETIO_PKT_SNAP_MASK \
162 (_NETIO_PKT_SNAP_RMASK << _NETIO_PKT_SNAP_SHIFT)
163
164/* NOTE: Bits 9 and 10 are unused. */
165
166/** Length of any custom data before the L2 header, in words. */
167#define _NETIO_PKT_CUSTOM_LEN_SHIFT 11
168#define _NETIO_PKT_CUSTOM_LEN_RMASK 0x1F
169#define _NETIO_PKT_CUSTOM_LEN_MASK \
170 (_NETIO_PKT_CUSTOM_LEN_RMASK << _NETIO_PKT_CUSTOM_LEN_SHIFT)
171
172/** The L4 checksum is incorrect (or perhaps has not been calculated). */
173#define _NETIO_PKT_BAD_L4_CSUM_SHIFT 16
174#define _NETIO_PKT_BAD_L4_CSUM_RMASK 0x1
175#define _NETIO_PKT_BAD_L4_CSUM_MASK \
176 (_NETIO_PKT_BAD_L4_CSUM_RMASK << _NETIO_PKT_BAD_L4_CSUM_SHIFT)
177
178/** Length of the L2 header, in words. */
179#define _NETIO_PKT_L2_LEN_SHIFT 17
180#define _NETIO_PKT_L2_LEN_RMASK 0x1F
181#define _NETIO_PKT_L2_LEN_MASK \
182 (_NETIO_PKT_L2_LEN_RMASK << _NETIO_PKT_L2_LEN_SHIFT)
183
184
185/* Flags in minimal packet metadata. */
186
187/** We need an eDMA checksum on this packet. */
188#define _NETIO_PKT_NEED_EDMA_CSUM_SHIFT 0
189#define _NETIO_PKT_NEED_EDMA_CSUM_RMASK 1
190#define _NETIO_PKT_NEED_EDMA_CSUM_MASK \
191 (_NETIO_PKT_NEED_EDMA_CSUM_RMASK << _NETIO_PKT_NEED_EDMA_CSUM_SHIFT)
192
193/* Data within the packet information table. */
194
195/* Note that, for efficiency, code which uses these fields assumes that none
196 * of the shift values below are zero. See uses below for an explanation. */
197
198/** Offset within the L2 header of the innermost ethertype (in halfwords). */
199#define _NETIO_PKT_INFO_ETYPE_SHIFT 6
200#define _NETIO_PKT_INFO_ETYPE_RMASK 0x1F
201
202/** Offset within the L2 header of the VLAN tag (in halfwords). */
203#define _NETIO_PKT_INFO_VLAN_SHIFT 11
204#define _NETIO_PKT_INFO_VLAN_RMASK 0x1F
205
206#endif
207
208
209/** The size of a memory buffer representing a small packet.
210 * @ingroup egress */
211#define SMALL_PACKET_SIZE 256
212
213/** The size of a memory buffer representing a large packet.
214 * @ingroup egress */
215#define LARGE_PACKET_SIZE 2048
216
217/** The size of a memory buffer representing a jumbo packet.
218 * @ingroup egress */
219#define JUMBO_PACKET_SIZE (12 * 1024)
220
221
222/* Common ethertypes.
223 * @ingroup ingress */
224/** @{ */
225/** The ethertype of IPv4. */
226#define ETHERTYPE_IPv4 (0x0800)
227/** The ethertype of ARP. */
228#define ETHERTYPE_ARP (0x0806)
229/** The ethertype of VLANs. */
230#define ETHERTYPE_VLAN (0x8100)
231/** The ethertype of a Q-in-Q header. */
232#define ETHERTYPE_Q_IN_Q (0x9100)
233/** The ethertype of IPv6. */
234#define ETHERTYPE_IPv6 (0x86DD)
235/** The ethertype of MPLS. */
236#define ETHERTYPE_MPLS (0x8847)
237/** @} */
238
239
240/** The possible return values of NETIO_PKT_STATUS.
241 * @ingroup ingress
242 */
243typedef enum
244{
245 /** No problems were detected with this packet. */
246 NETIO_PKT_STATUS_OK,
247 /** The packet is undersized; this is expected behavior if the packet's
248 * ethertype is unrecognized, but otherwise the packet is likely corrupt. */
249 NETIO_PKT_STATUS_UNDERSIZE,
250 /** The packet is oversized and some trailing bytes have been discarded.
251 This is expected behavior for short packets, since it's impossible to
252 precisely determine the amount of padding which may have been added to
253 them to make them meet the minimum Ethernet packet size. */
254 NETIO_PKT_STATUS_OVERSIZE,
255 /** The packet was judged to be corrupt by hardware (for instance, it had
256 a bad CRC, or part of it was discarded due to lack of buffer space in
257 the I/O shim) and should be discarded. */
258 NETIO_PKT_STATUS_BAD
259} netio_pkt_status_t;
260
261
262/** Log2 of how many buckets we have. */
263#define NETIO_LOG2_NUM_BUCKETS (10)
264
265/** How many buckets we have.
266 * @ingroup ingress */
267#define NETIO_NUM_BUCKETS (1 << NETIO_LOG2_NUM_BUCKETS)
268
269
270/**
271 * @brief A group-to-bucket identifier.
272 *
273 * @ingroup setup
274 *
275 * This tells us what to do with a given group.
276 */
277typedef union {
278 /** The header broken down into bits. */
279 struct {
280 /** Whether we should balance on L4, if available */
281 unsigned int __balance_on_l4:1;
282 /** Whether we should balance on L3, if available */
283 unsigned int __balance_on_l3:1;
284 /** Whether we should balance on L2, if available */
285 unsigned int __balance_on_l2:1;
286 /** Reserved for future use */
287 unsigned int __reserved:1;
288 /** The base bucket to use to send traffic */
289 unsigned int __bucket_base:NETIO_LOG2_NUM_BUCKETS;
290 /** The mask to apply to the balancing value. This must be one less
291 * than a power of two, e.g. 0x3 or 0xFF.
292 */
293 unsigned int __bucket_mask:NETIO_LOG2_NUM_BUCKETS;
294 /** Pad to 32 bits */
295 unsigned int __padding:(32 - 4 - 2 * NETIO_LOG2_NUM_BUCKETS);
296 } bits;
297 /** To send out the IDN. */
298 unsigned int word;
299}
300netio_group_t;
301
302
303/**
304 * @brief A VLAN-to-bucket identifier.
305 *
306 * @ingroup setup
307 *
308 * This tells us what to do with a given VLAN.
309 */
310typedef netio_group_t netio_vlan_t;
311
312
313/**
314 * A bucket-to-queue mapping.
315 * @ingroup setup
316 */
317typedef unsigned char netio_bucket_t;
318
319
320/**
321 * A packet size can always fit in a netio_size_t.
322 * @ingroup setup
323 */
324typedef unsigned int netio_size_t;
325
326
327/**
328 * @brief Ethernet standard (ingress) packet metadata.
329 *
330 * @ingroup ingress
331 *
332 * This is additional data associated with each packet.
333 * This structure is opaque and accessed through the @ref ingress.
334 *
335 * Also, the buffer population operation currently assumes that standard
336 * metadata is at least as large as minimal metadata, and will need to be
337 * modified if that is no longer the case.
338 */
339typedef struct
340{
341#ifdef __DOXYGEN__
342 /** This structure is opaque. */
343 unsigned char opaque[24];
344#else
345 /** The overall ordinal of the packet */
346 unsigned int __packet_ordinal;
347 /** The ordinal of the packet within the group */
348 unsigned int __group_ordinal;
349 /** The best flow hash IPP could compute. */
350 unsigned int __flow_hash;
351 /** Flags pertaining to checksum calculation, packet type, etc. */
352 unsigned int __flags;
353 /** The first word of "user data". */
354 unsigned int __user_data_0;
355 /** The second word of "user data". */
356 unsigned int __user_data_1;
357#endif
358}
359netio_pkt_metadata_t;
360
361
362/** To ensure that the L3 header is aligned mod 4, the L2 header should be
363 * aligned mod 4 plus 2, since every supported L2 header is 4n + 2 bytes
364 * long. The standard way to do this is to simply add 2 bytes of padding
365 * before the L2 header.
366 */
367#define NETIO_PACKET_PADDING 2
368
369
370
371/**
372 * @brief Ethernet minimal (egress) packet metadata.
373 *
374 * @ingroup egress
375 *
376 * This structure represents information about packets which have
377 * been processed by @ref netio_populate_buffer() or
378 * @ref netio_populate_prepend_buffer(). This structure is opaque
379 * and accessed through the @ref egress.
380 *
381 * @internal This structure is actually copied into the memory used by
382 * standard metadata, which is assumed to be large enough.
383 */
384typedef struct
385{
386#ifdef __DOXYGEN__
387 /** This structure is opaque. */
388 unsigned char opaque[14];
389#else
390 /** The offset of the L2 header from the start of the packet data. */
391 unsigned short l2_offset;
392 /** The offset of the L3 header from the start of the packet data. */
393 unsigned short l3_offset;
394 /** Where to write the checksum. */
395 unsigned char csum_location;
396 /** Where to start checksumming from. */
397 unsigned char csum_start;
398 /** Flags pertaining to checksum calculation etc. */
399 unsigned short flags;
400 /** The L2 length of the packet. */
401 unsigned short l2_length;
402 /** The checksum with which to seed the checksum generator. */
403 unsigned short csum_seed;
404 /** How much to checksum. */
405 unsigned short csum_length;
406#endif
407}
408netio_pkt_minimal_metadata_t;
409
410
411#ifndef __DOXYGEN__
412
413/**
414 * @brief An I/O notification header.
415 *
416 * This is the first word of data received from an I/O shim in a notification
417 * packet. It contains framing and status information.
418 */
419typedef union
420{
421 unsigned int word; /**< The whole word. */
422 /** The various fields. */
423 struct
424 {
425 unsigned int __channel:7; /**< Resource channel. */
426 unsigned int __type:4; /**< Type. */
427 unsigned int __ack:1; /**< Whether an acknowledgement is needed. */
428 unsigned int __reserved:1; /**< Reserved. */
429 unsigned int __protocol:1; /**< A protocol-specific word is added. */
430 unsigned int __status:2; /**< Status of the transfer. */
431 unsigned int __framing:2; /**< Framing of the transfer. */
432 unsigned int __transfer_size:14; /**< Transfer size in bytes (total). */
433 } bits;
434}
435__netio_pkt_notif_t;
436
437
438/**
439 * Returns the base address of the packet.
440 */
441#define _NETIO_PKT_HANDLE_BASE(p) \
442 ((unsigned char*)((p).word & 0xFFFFFFC0))
443
444/**
445 * Returns the base address of the packet.
446 */
447#define _NETIO_PKT_BASE(p) \
448 _NETIO_PKT_HANDLE_BASE(p->__packet)
449
450/**
451 * @brief An I/O notification packet (second word)
452 *
453 * This is the second word of data received from an I/O shim in a notification
454 * packet. This is the virtual address of the packet buffer, plus some flag
455 * bits. (The virtual address of the packet is always 256-byte aligned so we
456 * have room for 8 bits' worth of flags in the low 8 bits.)
457 *
458 * @internal
459 * NOTE: The low two bits must contain "__queue", so the "packet size"
460 * (SIZE_SMALL, SIZE_LARGE, or SIZE_JUMBO) can be determined quickly.
461 *
462 * If __addr or __offset are moved, _NETIO_PKT_BASE
463 * (defined right below this) must be changed.
464 */
465typedef union
466{
467 unsigned int word; /**< The whole word. */
468 /** The various fields. */
469 struct
470 {
471 /** Which queue the packet will be returned to once it is sent back to
472 the IPP. This is one of the SIZE_xxx values. */
473 unsigned int __queue:2;
474
475 /** The IPP handle of the sending IPP. */
476 unsigned int __ipp_handle:2;
477
478 /** Reserved for future use. */
479 unsigned int __reserved:1;
480
481 /** If 1, this packet has minimal (egress) metadata; otherwise, it
482 has standard (ingress) metadata. */
483 unsigned int __minimal:1;
484
485 /** Offset of the metadata within the packet. This value is multiplied
486 * by 64 and added to the base packet address to get the metadata
487 * address. Note that this field is aligned within the word such that
488 * you can easily extract the metadata address with a 26-bit mask. */
489 unsigned int __offset:2;
490
491 /** The top 24 bits of the packet's virtual address. */
492 unsigned int __addr:24;
493 } bits;
494}
495__netio_pkt_handle_t;
496
497#endif /* !__DOXYGEN__ */
498
499
500/**
501 * @brief A handle for an I/O packet's storage.
502 * @ingroup ingress
503 *
504 * netio_pkt_handle_t encodes the concept of a ::netio_pkt_t with its
505 * packet metadata removed. It is a much smaller type that exists to
506 * facilitate applications where the full ::netio_pkt_t type is too
507 * large, such as those that cache enormous numbers of packets or wish
508 * to transmit packet descriptors over the UDN.
509 *
510 * Because there is no metadata, most ::netio_pkt_t operations cannot be
511 * performed on a netio_pkt_handle_t. It supports only
512 * netio_free_handle() (to free the buffer) and
513 * NETIO_PKT_CUSTOM_DATA_H() (to access a pointer to its contents).
514 * The application must acquire any additional metadata it wants from the
515 * original ::netio_pkt_t and record it separately.
516 *
517 * A netio_pkt_handle_t can be extracted from a ::netio_pkt_t by calling
518 * NETIO_PKT_HANDLE(). An invalid handle (analogous to NULL) can be
519 * created by assigning the value ::NETIO_PKT_HANDLE_NONE. A handle can
520 * be tested for validity with NETIO_PKT_HANDLE_IS_VALID().
521 */
522typedef struct
523{
524 unsigned int word; /**< Opaque bits. */
525} netio_pkt_handle_t;
526
527/**
528 * @brief A packet descriptor.
529 *
530 * @ingroup ingress
531 * @ingroup egress
532 *
533 * This data structure represents a packet. The structure is manipulated
534 * through the @ref ingress and the @ref egress.
535 *
536 * While the contents of a netio_pkt_t are opaque, the structure itself is
537 * portable. This means that it may be shared between all tiles which have
538 * done a netio_input_register() call for the interface on which the pkt_t
539 * was initially received (via netio_get_packet()) or retrieved (via
540 * netio_get_buffer()). The contents of a netio_pkt_t can be transmitted to
541 * another tile via shared memory, or via a UDN message, or by other means.
542 * The destination tile may then use the pkt_t as if it had originally been
543 * received locally; it may read or write the packet's data, read its
544 * metadata, free the packet, send the packet, transfer the netio_pkt_t to
545 * yet another tile, and so forth.
546 *
547 * Once a netio_pkt_t has been transferred to a second tile, the first tile
548 * should not reference the original copy; in particular, if more than one
549 * tile frees or sends the same netio_pkt_t, the IPP's packet free lists will
550 * become corrupted. Note also that each tile which reads or modifies
551 * packet data must obey the memory coherency rules outlined in @ref input.
552 */
553typedef struct
554{
555#ifdef __DOXYGEN__
556 /** This structure is opaque. */
557 unsigned char opaque[32];
558#else
559 /** For an ingress packet (one with standard metadata), this is the
560 * notification header we got from the I/O shim. For an egress packet
561 * (one with minimal metadata), this word is zero if the packet has not
562 * been populated, and nonzero if it has. */
563 __netio_pkt_notif_t __notif_header;
564
565 /** Virtual address of the packet buffer, plus state flags. */
566 __netio_pkt_handle_t __packet;
567
568 /** Metadata associated with the packet. */
569 netio_pkt_metadata_t __metadata;
570#endif
571}
572netio_pkt_t;
573
574
575#ifndef __DOXYGEN__
576
577#define __NETIO_PKT_NOTIF_HEADER(pkt) ((pkt)->__notif_header)
578#define __NETIO_PKT_IPP_HANDLE(pkt) ((pkt)->__packet.bits.__ipp_handle)
579#define __NETIO_PKT_QUEUE(pkt) ((pkt)->__packet.bits.__queue)
580#define __NETIO_PKT_NOTIF_HEADER_M(mda, pkt) ((pkt)->__notif_header)
581#define __NETIO_PKT_IPP_HANDLE_M(mda, pkt) ((pkt)->__packet.bits.__ipp_handle)
582#define __NETIO_PKT_MINIMAL(pkt) ((pkt)->__packet.bits.__minimal)
583#define __NETIO_PKT_QUEUE_M(mda, pkt) ((pkt)->__packet.bits.__queue)
584#define __NETIO_PKT_FLAGS_M(mda, pkt) ((mda)->__flags)
585
586/* Packet information table, used by the attribute access functions below. */
587extern const uint16_t _netio_pkt_info[];
588
589#endif /* __DOXYGEN__ */
590
591
592#ifndef __DOXYGEN__
593/* These macros are deprecated and will disappear in a future MDE release. */
594#define NETIO_PKT_GOOD_CHECKSUM(pkt) \
595 NETIO_PKT_L4_CSUM_CORRECT(pkt)
596#define NETIO_PKT_GOOD_CHECKSUM_M(mda, pkt) \
597 NETIO_PKT_L4_CSUM_CORRECT_M(mda, pkt)
598#endif /* __DOXYGEN__ */
599
600
601/* Packet attribute access functions. */
602
603/** Return a pointer to the metadata for a packet.
604 * @ingroup ingress
605 *
606 * Calling this function once and passing the result to other retrieval
607 * functions with a "_M" suffix usually improves performance. This
608 * function must be called on an 'ingress' packet (i.e. one retrieved
609 * by @ref netio_get_packet(), on which @ref netio_populate_buffer() or
610 * @ref netio_populate_prepend_buffer have not been called). Use of this
611 * function on an 'egress' packet will cause an assertion failure.
612 *
613 * @param[in] pkt Packet on which to operate.
614 * @return A pointer to the packet's standard metadata.
615 */
616static __inline netio_pkt_metadata_t*
617NETIO_PKT_METADATA(netio_pkt_t* pkt)
618{
619 netio_assert(!pkt->__packet.bits.__minimal);
620 return &pkt->__metadata;
621}
622
623
624/** Return a pointer to the minimal metadata for a packet.
625 * @ingroup egress
626 *
627 * Calling this function once and passing the result to other retrieval
628 * functions with a "_MM" suffix usually improves performance. This
629 * function must be called on an 'egress' packet (i.e. one on which
630 * @ref netio_populate_buffer() or @ref netio_populate_prepend_buffer()
631 * have been called, or one retrieved by @ref netio_get_buffer()). Use of
632 * this function on an 'ingress' packet will cause an assertion failure.
633 *
634 * @param[in] pkt Packet on which to operate.
635 * @return A pointer to the packet's standard metadata.
636 */
637static __inline netio_pkt_minimal_metadata_t*
638NETIO_PKT_MINIMAL_METADATA(netio_pkt_t* pkt)
639{
640 netio_assert(pkt->__packet.bits.__minimal);
641 return (netio_pkt_minimal_metadata_t*) &pkt->__metadata;
642}
643
644
645/** Determine whether a packet has 'minimal' metadata.
646 * @ingroup pktfuncs
647 *
648 * This function will return nonzero if the packet is an 'egress'
649 * packet (i.e. one on which @ref netio_populate_buffer() or
650 * @ref netio_populate_prepend_buffer() have been called, or one
651 * retrieved by @ref netio_get_buffer()), and zero if the packet
652 * is an 'ingress' packet (i.e. one retrieved by @ref netio_get_packet(),
653 * which has not been converted into an 'egress' packet).
654 *
655 * @param[in] pkt Packet on which to operate.
656 * @return Nonzero if the packet has minimal metadata.
657 */
658static __inline unsigned int
659NETIO_PKT_IS_MINIMAL(netio_pkt_t* pkt)
660{
661 return pkt->__packet.bits.__minimal;
662}
663
664
665/** Return a handle for a packet's storage.
666 * @ingroup pktfuncs
667 *
668 * @param[in] pkt Packet on which to operate.
669 * @return A handle for the packet's storage.
670 */
671static __inline netio_pkt_handle_t
672NETIO_PKT_HANDLE(netio_pkt_t* pkt)
673{
674 netio_pkt_handle_t h;
675 h.word = pkt->__packet.word;
676 return h;
677}
678
679
680/** A special reserved value indicating the absence of a packet handle.
681 *
682 * @ingroup pktfuncs
683 */
684#define NETIO_PKT_HANDLE_NONE ((netio_pkt_handle_t) { 0 })
685
686
687/** Test whether a packet handle is valid.
688 *
689 * Applications may wish to use the reserved value NETIO_PKT_HANDLE_NONE
690 * to indicate no packet at all. This function tests to see if a packet
691 * handle is a real handle, not this special reserved value.
692 *
693 * @ingroup pktfuncs
694 *
695 * @param[in] handle Handle on which to operate.
696 * @return One if the packet handle is valid, else zero.
697 */
698static __inline unsigned int
699NETIO_PKT_HANDLE_IS_VALID(netio_pkt_handle_t handle)
700{
701 return handle.word != 0;
702}
703
704
705
706/** Return a pointer to the start of the packet's custom header.
707 * A custom header may or may not be present, depending upon the IPP; its
708 * contents and alignment are also IPP-dependent. Currently, none of the
709 * standard IPPs supplied by Tilera produce a custom header. If present,
710 * the custom header precedes the L2 header in the packet buffer.
711 * @ingroup ingress
712 *
713 * @param[in] handle Handle on which to operate.
714 * @return A pointer to start of the packet.
715 */
716static __inline unsigned char*
717NETIO_PKT_CUSTOM_DATA_H(netio_pkt_handle_t handle)
718{
719 return _NETIO_PKT_HANDLE_BASE(handle) + NETIO_PACKET_PADDING;
720}
721
722
723/** Return the length of the packet's custom header.
724 * A custom header may or may not be present, depending upon the IPP; its
725 * contents and alignment are also IPP-dependent. Currently, none of the
726 * standard IPPs supplied by Tilera produce a custom header. If present,
727 * the custom header precedes the L2 header in the packet buffer.
728 *
729 * @ingroup ingress
730 *
731 * @param[in] mda Pointer to packet's standard metadata.
732 * @param[in] pkt Packet on which to operate.
733 * @return The length of the packet's custom header, in bytes.
734 */
735static __inline netio_size_t
736NETIO_PKT_CUSTOM_HEADER_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
737{
738 /*
739 * Note that we effectively need to extract a quantity from the flags word
740 * which is measured in words, and then turn it into bytes by shifting
741 * it left by 2. We do this all at once by just shifting right two less
742 * bits, and shifting the mask up two bits.
743 */
744 return ((mda->__flags >> (_NETIO_PKT_CUSTOM_LEN_SHIFT - 2)) &
745 (_NETIO_PKT_CUSTOM_LEN_RMASK << 2));
746}
747
748
749/** Return the length of the packet, starting with the custom header.
750 * A custom header may or may not be present, depending upon the IPP; its
751 * contents and alignment are also IPP-dependent. Currently, none of the
752 * standard IPPs supplied by Tilera produce a custom header. If present,
753 * the custom header precedes the L2 header in the packet buffer.
754 * @ingroup ingress
755 *
756 * @param[in] mda Pointer to packet's standard metadata.
757 * @param[in] pkt Packet on which to operate.
758 * @return The length of the packet, in bytes.
759 */
760static __inline netio_size_t
761NETIO_PKT_CUSTOM_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
762{
763 return (__NETIO_PKT_NOTIF_HEADER(pkt).bits.__transfer_size -
764 NETIO_PACKET_PADDING);
765}
766
767
768/** Return a pointer to the start of the packet's custom header.
769 * A custom header may or may not be present, depending upon the IPP; its
770 * contents and alignment are also IPP-dependent. Currently, none of the
771 * standard IPPs supplied by Tilera produce a custom header. If present,
772 * the custom header precedes the L2 header in the packet buffer.
773 * @ingroup ingress
774 *
775 * @param[in] mda Pointer to packet's standard metadata.
776 * @param[in] pkt Packet on which to operate.
777 * @return A pointer to start of the packet.
778 */
779static __inline unsigned char*
780NETIO_PKT_CUSTOM_DATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
781{
782 return NETIO_PKT_CUSTOM_DATA_H(NETIO_PKT_HANDLE(pkt));
783}
784
785
786/** Return the length of the packet's L2 (Ethernet plus VLAN or SNAP) header.
787 * @ingroup ingress
788 *
789 * @param[in] mda Pointer to packet's standard metadata.
790 * @param[in] pkt Packet on which to operate.
791 * @return The length of the packet's L2 header, in bytes.
792 */
793static __inline netio_size_t
794NETIO_PKT_L2_HEADER_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
795{
796 /*
797 * Note that we effectively need to extract a quantity from the flags word
798 * which is measured in words, and then turn it into bytes by shifting
799 * it left by 2. We do this all at once by just shifting right two less
800 * bits, and shifting the mask up two bits. We then add two bytes.
801 */
802 return ((mda->__flags >> (_NETIO_PKT_L2_LEN_SHIFT - 2)) &
803 (_NETIO_PKT_L2_LEN_RMASK << 2)) + 2;
804}
805
806
807/** Return the length of the packet, starting with the L2 (Ethernet) header.
808 * @ingroup ingress
809 *
810 * @param[in] mda Pointer to packet's standard metadata.
811 * @param[in] pkt Packet on which to operate.
812 * @return The length of the packet, in bytes.
813 */
814static __inline netio_size_t
815NETIO_PKT_L2_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
816{
817 return (NETIO_PKT_CUSTOM_LENGTH_M(mda, pkt) -
818 NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda,pkt));
819}
820
821
822/** Return a pointer to the start of the packet's L2 (Ethernet) header.
823 * @ingroup ingress
824 *
825 * @param[in] mda Pointer to packet's standard metadata.
826 * @param[in] pkt Packet on which to operate.
827 * @return A pointer to start of the packet.
828 */
829static __inline unsigned char*
830NETIO_PKT_L2_DATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
831{
832 return (NETIO_PKT_CUSTOM_DATA_M(mda, pkt) +
833 NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda, pkt));
834}
835
836
837/** Retrieve the length of the packet, starting with the L3 (generally,
838 * the IP) header.
839 * @ingroup ingress
840 *
841 * @param[in] mda Pointer to packet's standard metadata.
842 * @param[in] pkt Packet on which to operate.
843 * @return Length of the packet's L3 header and data, in bytes.
844 */
845static __inline netio_size_t
846NETIO_PKT_L3_LENGTH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
847{
848 return (NETIO_PKT_L2_LENGTH_M(mda, pkt) -
849 NETIO_PKT_L2_HEADER_LENGTH_M(mda,pkt));
850}
851
852
853/** Return a pointer to the packet's L3 (generally, the IP) header.
854 * @ingroup ingress
855 *
856 * Note that we guarantee word alignment of the L3 header.
857 *
858 * @param[in] mda Pointer to packet's standard metadata.
859 * @param[in] pkt Packet on which to operate.
860 * @return A pointer to the packet's L3 header.
861 */
862static __inline unsigned char*
863NETIO_PKT_L3_DATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
864{
865 return (NETIO_PKT_L2_DATA_M(mda, pkt) +
866 NETIO_PKT_L2_HEADER_LENGTH_M(mda, pkt));
867}
868
869
870/** Return the ordinal of the packet.
871 * @ingroup ingress
872 *
873 * Each packet is given an ordinal number when it is delivered by the IPP.
874 * In the medium term, the ordinal is unique and monotonically increasing,
875 * being incremented by 1 for each packet; the ordinal of the first packet
876 * delivered after the IPP starts is zero. (Since the ordinal is of finite
877 * size, given enough input packets, it will eventually wrap around to zero;
878 * in the long term, therefore, ordinals are not unique.) The ordinals
879 * handed out by different IPPs are not disjoint, so two packets from
880 * different IPPs may have identical ordinals. Packets dropped by the
881 * IPP or by the I/O shim are not assigned ordinals.
882 *
883 * @param[in] mda Pointer to packet's standard metadata.
884 * @param[in] pkt Packet on which to operate.
885 * @return The packet's per-IPP packet ordinal.
886 */
887static __inline unsigned int
888NETIO_PKT_ORDINAL_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
889{
890 return mda->__packet_ordinal;
891}
892
893
894/** Return the per-group ordinal of the packet.
895 * @ingroup ingress
896 *
897 * Each packet is given a per-group ordinal number when it is
898 * delivered by the IPP. By default, the group is the packet's VLAN,
899 * although IPP can be recompiled to use different values. In
900 * the medium term, the ordinal is unique and monotonically
901 * increasing, being incremented by 1 for each packet; the ordinal of
902 * the first packet distributed to a particular group is zero.
903 * (Since the ordinal is of finite size, given enough input packets,
904 * it will eventually wrap around to zero; in the long term,
905 * therefore, ordinals are not unique.) The ordinals handed out by
906 * different IPPs are not disjoint, so two packets from different IPPs
907 * may have identical ordinals; similarly, packets distributed to
908 * different groups may have identical ordinals. Packets dropped by
909 * the IPP or by the I/O shim are not assigned ordinals.
910 *
911 * @param[in] mda Pointer to packet's standard metadata.
912 * @param[in] pkt Packet on which to operate.
913 * @return The packet's per-IPP, per-group ordinal.
914 */
915static __inline unsigned int
916NETIO_PKT_GROUP_ORDINAL_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
917{
918 return mda->__group_ordinal;
919}
920
921
922/** Return the VLAN ID assigned to the packet.
923 * @ingroup ingress
924 *
925 * This value is usually contained within the packet header.
926 *
927 * This value will be zero if the packet does not have a VLAN tag, or if
928 * this value was not extracted from the packet.
929 *
930 * @param[in] mda Pointer to packet's standard metadata.
931 * @param[in] pkt Packet on which to operate.
932 * @return The packet's VLAN ID.
933 */
934static __inline unsigned short
935NETIO_PKT_VLAN_ID_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
936{
937 int vl = (mda->__flags >> _NETIO_PKT_VLAN_SHIFT) & _NETIO_PKT_VLAN_RMASK;
938 unsigned short* pkt_p;
939 int index;
940 unsigned short val;
941
942 if (vl == _NETIO_PKT_VLAN_NONE)
943 return 0;
944
945 pkt_p = (unsigned short*) NETIO_PKT_L2_DATA_M(mda, pkt);
946 index = (mda->__flags >> _NETIO_PKT_TYPE_SHIFT) & _NETIO_PKT_TYPE_RMASK;
947
948 val = pkt_p[(_netio_pkt_info[index] >> _NETIO_PKT_INFO_VLAN_SHIFT) &
949 _NETIO_PKT_INFO_VLAN_RMASK];
950
951#ifdef __TILECC__
952 return (__insn_bytex(val) >> 16) & 0xFFF;
953#else
954 return (__builtin_bswap32(val) >> 16) & 0xFFF;
955#endif
956}
957
958
959/** Return the ethertype of the packet.
960 * @ingroup ingress
961 *
962 * This value is usually contained within the packet header.
963 *
964 * This value is reliable if @ref NETIO_PKT_ETHERTYPE_RECOGNIZED_M()
965 * returns true, and otherwise, may not be well defined.
966 *
967 * @param[in] mda Pointer to packet's standard metadata.
968 * @param[in] pkt Packet on which to operate.
969 * @return The packet's ethertype.
970 */
971static __inline unsigned short
972NETIO_PKT_ETHERTYPE_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
973{
974 unsigned short* pkt_p = (unsigned short*) NETIO_PKT_L2_DATA_M(mda, pkt);
975 int index = (mda->__flags >> _NETIO_PKT_TYPE_SHIFT) & _NETIO_PKT_TYPE_RMASK;
976
977 unsigned short val =
978 pkt_p[(_netio_pkt_info[index] >> _NETIO_PKT_INFO_ETYPE_SHIFT) &
979 _NETIO_PKT_INFO_ETYPE_RMASK];
980
981 return __builtin_bswap32(val) >> 16;
982}
983
984
985/** Return the flow hash computed on the packet.
986 * @ingroup ingress
987 *
988 * For TCP and UDP packets, this hash is calculated by hashing together
989 * the "5-tuple" values, specifically the source IP address, destination
990 * IP address, protocol type, source port and destination port.
991 * The hash value is intended to be helpful for millions of distinct
992 * flows.
993 *
994 * For IPv4 or IPv6 packets which are neither TCP nor UDP, the flow hash is
995 * derived by hashing together the source and destination IP addresses.
996 *
997 * For MPLS-encapsulated packets, the flow hash is derived by hashing
998 * the first MPLS label.
999 *
1000 * For all other packets the flow hash is computed from the source
1001 * and destination Ethernet addresses.
1002 *
1003 * The hash is symmetric, meaning it produces the same value if the
1004 * source and destination are swapped. The only exceptions are
1005 * tunneling protocols 0x04 (IP in IP Encapsulation), 0x29 (Simple
1006 * Internet Protocol), 0x2F (General Routing Encapsulation) and 0x32
1007 * (Encap Security Payload), which use only the destination address
1008 * since the source address is not meaningful.
1009 *
1010 * @param[in] mda Pointer to packet's standard metadata.
1011 * @param[in] pkt Packet on which to operate.
1012 * @return The packet's 32-bit flow hash.
1013 */
1014static __inline unsigned int
1015NETIO_PKT_FLOW_HASH_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1016{
1017 return mda->__flow_hash;
1018}
1019
1020
1021/** Return the first word of "user data" for the packet.
1022 *
1023 * The contents of the user data words depend on the IPP.
1024 *
1025 * When using the standard ipp1, ipp2, or ipp4 sub-drivers, the first
1026 * word of user data contains the least significant bits of the 64-bit
1027 * arrival cycle count (see @c get_cycle_count_low()).
1028 *
1029 * See the <em>System Programmer's Guide</em> for details.
1030 *
1031 * @ingroup ingress
1032 *
1033 * @param[in] mda Pointer to packet's standard metadata.
1034 * @param[in] pkt Packet on which to operate.
1035 * @return The packet's first word of "user data".
1036 */
1037static __inline unsigned int
1038NETIO_PKT_USER_DATA_0_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1039{
1040 return mda->__user_data_0;
1041}
1042
1043
1044/** Return the second word of "user data" for the packet.
1045 *
1046 * The contents of the user data words depend on the IPP.
1047 *
1048 * When using the standard ipp1, ipp2, or ipp4 sub-drivers, the second
1049 * word of user data contains the most significant bits of the 64-bit
1050 * arrival cycle count (see @c get_cycle_count_high()).
1051 *
1052 * See the <em>System Programmer's Guide</em> for details.
1053 *
1054 * @ingroup ingress
1055 *
1056 * @param[in] mda Pointer to packet's standard metadata.
1057 * @param[in] pkt Packet on which to operate.
1058 * @return The packet's second word of "user data".
1059 */
1060static __inline unsigned int
1061NETIO_PKT_USER_DATA_1_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1062{
1063 return mda->__user_data_1;
1064}
1065
1066
1067/** Determine whether the L4 (TCP/UDP) checksum was calculated.
1068 * @ingroup ingress
1069 *
1070 * @param[in] mda Pointer to packet's standard metadata.
1071 * @param[in] pkt Packet on which to operate.
1072 * @return Nonzero if the L4 checksum was calculated.
1073 */
1074static __inline unsigned int
1075NETIO_PKT_L4_CSUM_CALCULATED_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1076{
1077 return !(mda->__flags & _NETIO_PKT_NO_L4_CSUM_MASK);
1078}
1079
1080
1081/** Determine whether the L4 (TCP/UDP) checksum was calculated and found to
1082 * be correct.
1083 * @ingroup ingress
1084 *
1085 * @param[in] mda Pointer to packet's standard metadata.
1086 * @param[in] pkt Packet on which to operate.
1087 * @return Nonzero if the checksum was calculated and is correct.
1088 */
1089static __inline unsigned int
1090NETIO_PKT_L4_CSUM_CORRECT_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1091{
1092 return !(mda->__flags &
1093 (_NETIO_PKT_BAD_L4_CSUM_MASK | _NETIO_PKT_NO_L4_CSUM_MASK));
1094}
1095
1096
1097/** Determine whether the L3 (IP) checksum was calculated.
1098 * @ingroup ingress
1099 *
1100 * @param[in] mda Pointer to packet's standard metadata.
1101 * @param[in] pkt Packet on which to operate.
1102 * @return Nonzero if the L3 (IP) checksum was calculated.
1103*/
1104static __inline unsigned int
1105NETIO_PKT_L3_CSUM_CALCULATED_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1106{
1107 return !(mda->__flags & _NETIO_PKT_NO_L3_CSUM_MASK);
1108}
1109
1110
1111/** Determine whether the L3 (IP) checksum was calculated and found to be
1112 * correct.
1113 * @ingroup ingress
1114 *
1115 * @param[in] mda Pointer to packet's standard metadata.
1116 * @param[in] pkt Packet on which to operate.
1117 * @return Nonzero if the checksum was calculated and is correct.
1118 */
1119static __inline unsigned int
1120NETIO_PKT_L3_CSUM_CORRECT_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1121{
1122 return !(mda->__flags &
1123 (_NETIO_PKT_BAD_L3_CSUM_MASK | _NETIO_PKT_NO_L3_CSUM_MASK));
1124}
1125
1126
1127/** Determine whether the ethertype was recognized and L3 packet data was
1128 * processed.
1129 * @ingroup ingress
1130 *
1131 * @param[in] mda Pointer to packet's standard metadata.
1132 * @param[in] pkt Packet on which to operate.
1133 * @return Nonzero if the ethertype was recognized and L3 packet data was
1134 * processed.
1135 */
1136static __inline unsigned int
1137NETIO_PKT_ETHERTYPE_RECOGNIZED_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1138{
1139 return !(mda->__flags & _NETIO_PKT_TYPE_UNRECOGNIZED_MASK);
1140}
1141
1142
1143/** Retrieve the status of a packet and any errors that may have occurred
1144 * during ingress processing (length mismatches, CRC errors, etc.).
1145 * @ingroup ingress
1146 *
1147 * Note that packets for which @ref NETIO_PKT_ETHERTYPE_RECOGNIZED()
1148 * returns zero are always reported as underlength, as there is no a priori
1149 * means to determine their length. Normally, applications should use
1150 * @ref NETIO_PKT_BAD_M() instead of explicitly checking status with this
1151 * function.
1152 *
1153 * @param[in] mda Pointer to packet's standard metadata.
1154 * @param[in] pkt Packet on which to operate.
1155 * @return The packet's status.
1156 */
1157static __inline netio_pkt_status_t
1158NETIO_PKT_STATUS_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1159{
1160 return (netio_pkt_status_t) __NETIO_PKT_NOTIF_HEADER(pkt).bits.__status;
1161}
1162
1163
1164/** Report whether a packet is bad (i.e., was shorter than expected based on
1165 * its headers, or had a bad CRC).
1166 * @ingroup ingress
1167 *
1168 * Note that this function does not verify L3 or L4 checksums.
1169 *
1170 * @param[in] mda Pointer to packet's standard metadata.
1171 * @param[in] pkt Packet on which to operate.
1172 * @return Nonzero if the packet is bad and should be discarded.
1173 */
1174static __inline unsigned int
1175NETIO_PKT_BAD_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1176{
1177 return ((NETIO_PKT_STATUS_M(mda, pkt) & 1) &&
1178 (NETIO_PKT_ETHERTYPE_RECOGNIZED_M(mda, pkt) ||
1179 NETIO_PKT_STATUS_M(mda, pkt) == NETIO_PKT_STATUS_BAD));
1180}
1181
1182
1183/** Return the length of the packet, starting with the L2 (Ethernet) header.
1184 * @ingroup egress
1185 *
1186 * @param[in] mmd Pointer to packet's minimal metadata.
1187 * @param[in] pkt Packet on which to operate.
1188 * @return The length of the packet, in bytes.
1189 */
1190static __inline netio_size_t
1191NETIO_PKT_L2_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1192{
1193 return mmd->l2_length;
1194}
1195
1196
1197/** Return the length of the L2 (Ethernet) header.
1198 * @ingroup egress
1199 *
1200 * @param[in] mmd Pointer to packet's minimal metadata.
1201 * @param[in] pkt Packet on which to operate.
1202 * @return The length of the packet's L2 header, in bytes.
1203 */
1204static __inline netio_size_t
1205NETIO_PKT_L2_HEADER_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd,
1206 netio_pkt_t* pkt)
1207{
1208 return mmd->l3_offset - mmd->l2_offset;
1209}
1210
1211
1212/** Return the length of the packet, starting with the L3 (IP) header.
1213 * @ingroup egress
1214 *
1215 * @param[in] mmd Pointer to packet's minimal metadata.
1216 * @param[in] pkt Packet on which to operate.
1217 * @return Length of the packet's L3 header and data, in bytes.
1218 */
1219static __inline netio_size_t
1220NETIO_PKT_L3_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1221{
1222 return (NETIO_PKT_L2_LENGTH_MM(mmd, pkt) -
1223 NETIO_PKT_L2_HEADER_LENGTH_MM(mmd, pkt));
1224}
1225
1226
1227/** Return a pointer to the packet's L3 (generally, the IP) header.
1228 * @ingroup egress
1229 *
1230 * Note that we guarantee word alignment of the L3 header.
1231 *
1232 * @param[in] mmd Pointer to packet's minimal metadata.
1233 * @param[in] pkt Packet on which to operate.
1234 * @return A pointer to the packet's L3 header.
1235 */
1236static __inline unsigned char*
1237NETIO_PKT_L3_DATA_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1238{
1239 return _NETIO_PKT_BASE(pkt) + mmd->l3_offset;
1240}
1241
1242
1243/** Return a pointer to the packet's L2 (Ethernet) header.
1244 * @ingroup egress
1245 *
1246 * @param[in] mmd Pointer to packet's minimal metadata.
1247 * @param[in] pkt Packet on which to operate.
1248 * @return A pointer to start of the packet.
1249 */
1250static __inline unsigned char*
1251NETIO_PKT_L2_DATA_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1252{
1253 return _NETIO_PKT_BASE(pkt) + mmd->l2_offset;
1254}
1255
1256
1257/** Retrieve the status of a packet and any errors that may have occurred
1258 * during ingress processing (length mismatches, CRC errors, etc.).
1259 * @ingroup ingress
1260 *
1261 * Note that packets for which @ref NETIO_PKT_ETHERTYPE_RECOGNIZED()
1262 * returns zero are always reported as underlength, as there is no a priori
1263 * means to determine their length. Normally, applications should use
1264 * @ref NETIO_PKT_BAD() instead of explicitly checking status with this
1265 * function.
1266 *
1267 * @param[in] pkt Packet on which to operate.
1268 * @return The packet's status.
1269 */
1270static __inline netio_pkt_status_t
1271NETIO_PKT_STATUS(netio_pkt_t* pkt)
1272{
1273 netio_assert(!pkt->__packet.bits.__minimal);
1274
1275 return (netio_pkt_status_t) __NETIO_PKT_NOTIF_HEADER(pkt).bits.__status;
1276}
1277
1278
1279/** Report whether a packet is bad (i.e., was shorter than expected based on
1280 * its headers, or had a bad CRC).
1281 * @ingroup ingress
1282 *
1283 * Note that this function does not verify L3 or L4 checksums.
1284 *
1285 * @param[in] pkt Packet on which to operate.
1286 * @return Nonzero if the packet is bad and should be discarded.
1287 */
1288static __inline unsigned int
1289NETIO_PKT_BAD(netio_pkt_t* pkt)
1290{
1291 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1292
1293 return NETIO_PKT_BAD_M(mda, pkt);
1294}
1295
1296
1297/** Return the length of the packet's custom header.
1298 * A custom header may or may not be present, depending upon the IPP; its
1299 * contents and alignment are also IPP-dependent. Currently, none of the
1300 * standard IPPs supplied by Tilera produce a custom header. If present,
1301 * the custom header precedes the L2 header in the packet buffer.
1302 * @ingroup pktfuncs
1303 *
1304 * @param[in] pkt Packet on which to operate.
1305 * @return The length of the packet's custom header, in bytes.
1306 */
1307static __inline netio_size_t
1308NETIO_PKT_CUSTOM_HEADER_LENGTH(netio_pkt_t* pkt)
1309{
1310 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1311
1312 return NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda, pkt);
1313}
1314
1315
1316/** Return the length of the packet, starting with the custom header.
1317 * A custom header may or may not be present, depending upon the IPP; its
1318 * contents and alignment are also IPP-dependent. Currently, none of the
1319 * standard IPPs supplied by Tilera produce a custom header. If present,
1320 * the custom header precedes the L2 header in the packet buffer.
1321 * @ingroup pktfuncs
1322 *
1323 * @param[in] pkt Packet on which to operate.
1324 * @return The length of the packet, in bytes.
1325 */
1326static __inline netio_size_t
1327NETIO_PKT_CUSTOM_LENGTH(netio_pkt_t* pkt)
1328{
1329 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1330
1331 return NETIO_PKT_CUSTOM_LENGTH_M(mda, pkt);
1332}
1333
1334
1335/** Return a pointer to the packet's custom header.
1336 * A custom header may or may not be present, depending upon the IPP; its
1337 * contents and alignment are also IPP-dependent. Currently, none of the
1338 * standard IPPs supplied by Tilera produce a custom header. If present,
1339 * the custom header precedes the L2 header in the packet buffer.
1340 * @ingroup pktfuncs
1341 *
1342 * @param[in] pkt Packet on which to operate.
1343 * @return A pointer to start of the packet.
1344 */
1345static __inline unsigned char*
1346NETIO_PKT_CUSTOM_DATA(netio_pkt_t* pkt)
1347{
1348 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1349
1350 return NETIO_PKT_CUSTOM_DATA_M(mda, pkt);
1351}
1352
1353
1354/** Return the length of the packet's L2 (Ethernet plus VLAN or SNAP) header.
1355 * @ingroup pktfuncs
1356 *
1357 * @param[in] pkt Packet on which to operate.
1358 * @return The length of the packet's L2 header, in bytes.
1359 */
1360static __inline netio_size_t
1361NETIO_PKT_L2_HEADER_LENGTH(netio_pkt_t* pkt)
1362{
1363 if (NETIO_PKT_IS_MINIMAL(pkt))
1364 {
1365 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1366
1367 return NETIO_PKT_L2_HEADER_LENGTH_MM(mmd, pkt);
1368 }
1369 else
1370 {
1371 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1372
1373 return NETIO_PKT_L2_HEADER_LENGTH_M(mda, pkt);
1374 }
1375}
1376
1377
1378/** Return the length of the packet, starting with the L2 (Ethernet) header.
1379 * @ingroup pktfuncs
1380 *
1381 * @param[in] pkt Packet on which to operate.
1382 * @return The length of the packet, in bytes.
1383 */
1384static __inline netio_size_t
1385NETIO_PKT_L2_LENGTH(netio_pkt_t* pkt)
1386{
1387 if (NETIO_PKT_IS_MINIMAL(pkt))
1388 {
1389 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1390
1391 return NETIO_PKT_L2_LENGTH_MM(mmd, pkt);
1392 }
1393 else
1394 {
1395 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1396
1397 return NETIO_PKT_L2_LENGTH_M(mda, pkt);
1398 }
1399}
1400
1401
1402/** Return a pointer to the packet's L2 (Ethernet) header.
1403 * @ingroup pktfuncs
1404 *
1405 * @param[in] pkt Packet on which to operate.
1406 * @return A pointer to start of the packet.
1407 */
1408static __inline unsigned char*
1409NETIO_PKT_L2_DATA(netio_pkt_t* pkt)
1410{
1411 if (NETIO_PKT_IS_MINIMAL(pkt))
1412 {
1413 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1414
1415 return NETIO_PKT_L2_DATA_MM(mmd, pkt);
1416 }
1417 else
1418 {
1419 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1420
1421 return NETIO_PKT_L2_DATA_M(mda, pkt);
1422 }
1423}
1424
1425
1426/** Retrieve the length of the packet, starting with the L3 (generally, the IP)
1427 * header.
1428 * @ingroup pktfuncs
1429 *
1430 * @param[in] pkt Packet on which to operate.
1431 * @return Length of the packet's L3 header and data, in bytes.
1432 */
1433static __inline netio_size_t
1434NETIO_PKT_L3_LENGTH(netio_pkt_t* pkt)
1435{
1436 if (NETIO_PKT_IS_MINIMAL(pkt))
1437 {
1438 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1439
1440 return NETIO_PKT_L3_LENGTH_MM(mmd, pkt);
1441 }
1442 else
1443 {
1444 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1445
1446 return NETIO_PKT_L3_LENGTH_M(mda, pkt);
1447 }
1448}
1449
1450
1451/** Return a pointer to the packet's L3 (generally, the IP) header.
1452 * @ingroup pktfuncs
1453 *
1454 * Note that we guarantee word alignment of the L3 header.
1455 *
1456 * @param[in] pkt Packet on which to operate.
1457 * @return A pointer to the packet's L3 header.
1458 */
1459static __inline unsigned char*
1460NETIO_PKT_L3_DATA(netio_pkt_t* pkt)
1461{
1462 if (NETIO_PKT_IS_MINIMAL(pkt))
1463 {
1464 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1465
1466 return NETIO_PKT_L3_DATA_MM(mmd, pkt);
1467 }
1468 else
1469 {
1470 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1471
1472 return NETIO_PKT_L3_DATA_M(mda, pkt);
1473 }
1474}
1475
1476
1477/** Return the ordinal of the packet.
1478 * @ingroup ingress
1479 *
1480 * Each packet is given an ordinal number when it is delivered by the IPP.
1481 * In the medium term, the ordinal is unique and monotonically increasing,
1482 * being incremented by 1 for each packet; the ordinal of the first packet
1483 * delivered after the IPP starts is zero. (Since the ordinal is of finite
1484 * size, given enough input packets, it will eventually wrap around to zero;
1485 * in the long term, therefore, ordinals are not unique.) The ordinals
1486 * handed out by different IPPs are not disjoint, so two packets from
1487 * different IPPs may have identical ordinals. Packets dropped by the
1488 * IPP or by the I/O shim are not assigned ordinals.
1489 *
1490 *
1491 * @param[in] pkt Packet on which to operate.
1492 * @return The packet's per-IPP packet ordinal.
1493 */
1494static __inline unsigned int
1495NETIO_PKT_ORDINAL(netio_pkt_t* pkt)
1496{
1497 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1498
1499 return NETIO_PKT_ORDINAL_M(mda, pkt);
1500}
1501
1502
1503/** Return the per-group ordinal of the packet.
1504 * @ingroup ingress
1505 *
1506 * Each packet is given a per-group ordinal number when it is
1507 * delivered by the IPP. By default, the group is the packet's VLAN,
1508 * although IPP can be recompiled to use different values. In
1509 * the medium term, the ordinal is unique and monotonically
1510 * increasing, being incremented by 1 for each packet; the ordinal of
1511 * the first packet distributed to a particular group is zero.
1512 * (Since the ordinal is of finite size, given enough input packets,
1513 * it will eventually wrap around to zero; in the long term,
1514 * therefore, ordinals are not unique.) The ordinals handed out by
1515 * different IPPs are not disjoint, so two packets from different IPPs
1516 * may have identical ordinals; similarly, packets distributed to
1517 * different groups may have identical ordinals. Packets dropped by
1518 * the IPP or by the I/O shim are not assigned ordinals.
1519 *
1520 * @param[in] pkt Packet on which to operate.
1521 * @return The packet's per-IPP, per-group ordinal.
1522 */
1523static __inline unsigned int
1524NETIO_PKT_GROUP_ORDINAL(netio_pkt_t* pkt)
1525{
1526 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1527
1528 return NETIO_PKT_GROUP_ORDINAL_M(mda, pkt);
1529}
1530
1531
1532/** Return the VLAN ID assigned to the packet.
1533 * @ingroup ingress
1534 *
1535 * This is usually also contained within the packet header. If the packet
1536 * does not have a VLAN tag, the VLAN ID returned by this function is zero.
1537 *
1538 * @param[in] pkt Packet on which to operate.
1539 * @return The packet's VLAN ID.
1540 */
1541static __inline unsigned short
1542NETIO_PKT_VLAN_ID(netio_pkt_t* pkt)
1543{
1544 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1545
1546 return NETIO_PKT_VLAN_ID_M(mda, pkt);
1547}
1548
1549
1550/** Return the ethertype of the packet.
1551 * @ingroup ingress
1552 *
1553 * This value is reliable if @ref NETIO_PKT_ETHERTYPE_RECOGNIZED()
1554 * returns true, and otherwise, may not be well defined.
1555 *
1556 * @param[in] pkt Packet on which to operate.
1557 * @return The packet's ethertype.
1558 */
1559static __inline unsigned short
1560NETIO_PKT_ETHERTYPE(netio_pkt_t* pkt)
1561{
1562 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1563
1564 return NETIO_PKT_ETHERTYPE_M(mda, pkt);
1565}
1566
1567
1568/** Return the flow hash computed on the packet.
1569 * @ingroup ingress
1570 *
1571 * For TCP and UDP packets, this hash is calculated by hashing together
1572 * the "5-tuple" values, specifically the source IP address, destination
1573 * IP address, protocol type, source port and destination port.
1574 * The hash value is intended to be helpful for millions of distinct
1575 * flows.
1576 *
1577 * For IPv4 or IPv6 packets which are neither TCP nor UDP, the flow hash is
1578 * derived by hashing together the source and destination IP addresses.
1579 *
1580 * For MPLS-encapsulated packets, the flow hash is derived by hashing
1581 * the first MPLS label.
1582 *
1583 * For all other packets the flow hash is computed from the source
1584 * and destination Ethernet addresses.
1585 *
1586 * The hash is symmetric, meaning it produces the same value if the
1587 * source and destination are swapped. The only exceptions are
1588 * tunneling protocols 0x04 (IP in IP Encapsulation), 0x29 (Simple
1589 * Internet Protocol), 0x2F (General Routing Encapsulation) and 0x32
1590 * (Encap Security Payload), which use only the destination address
1591 * since the source address is not meaningful.
1592 *
1593 * @param[in] pkt Packet on which to operate.
1594 * @return The packet's 32-bit flow hash.
1595 */
1596static __inline unsigned int
1597NETIO_PKT_FLOW_HASH(netio_pkt_t* pkt)
1598{
1599 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1600
1601 return NETIO_PKT_FLOW_HASH_M(mda, pkt);
1602}
1603
1604
1605/** Return the first word of "user data" for the packet.
1606 *
1607 * The contents of the user data words depend on the IPP.
1608 *
1609 * When using the standard ipp1, ipp2, or ipp4 sub-drivers, the first
1610 * word of user data contains the least significant bits of the 64-bit
1611 * arrival cycle count (see @c get_cycle_count_low()).
1612 *
1613 * See the <em>System Programmer's Guide</em> for details.
1614 *
1615 * @ingroup ingress
1616 *
1617 * @param[in] pkt Packet on which to operate.
1618 * @return The packet's first word of "user data".
1619 */
1620static __inline unsigned int
1621NETIO_PKT_USER_DATA_0(netio_pkt_t* pkt)
1622{
1623 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1624
1625 return NETIO_PKT_USER_DATA_0_M(mda, pkt);
1626}
1627
1628
1629/** Return the second word of "user data" for the packet.
1630 *
1631 * The contents of the user data words depend on the IPP.
1632 *
1633 * When using the standard ipp1, ipp2, or ipp4 sub-drivers, the second
1634 * word of user data contains the most significant bits of the 64-bit
1635 * arrival cycle count (see @c get_cycle_count_high()).
1636 *
1637 * See the <em>System Programmer's Guide</em> for details.
1638 *
1639 * @ingroup ingress
1640 *
1641 * @param[in] pkt Packet on which to operate.
1642 * @return The packet's second word of "user data".
1643 */
1644static __inline unsigned int
1645NETIO_PKT_USER_DATA_1(netio_pkt_t* pkt)
1646{
1647 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1648
1649 return NETIO_PKT_USER_DATA_1_M(mda, pkt);
1650}
1651
1652
1653/** Determine whether the L4 (TCP/UDP) checksum was calculated.
1654 * @ingroup ingress
1655 *
1656 * @param[in] pkt Packet on which to operate.
1657 * @return Nonzero if the L4 checksum was calculated.
1658 */
1659static __inline unsigned int
1660NETIO_PKT_L4_CSUM_CALCULATED(netio_pkt_t* pkt)
1661{
1662 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1663
1664 return NETIO_PKT_L4_CSUM_CALCULATED_M(mda, pkt);
1665}
1666
1667
1668/** Determine whether the L4 (TCP/UDP) checksum was calculated and found to
1669 * be correct.
1670 * @ingroup ingress
1671 *
1672 * @param[in] pkt Packet on which to operate.
1673 * @return Nonzero if the checksum was calculated and is correct.
1674 */
1675static __inline unsigned int
1676NETIO_PKT_L4_CSUM_CORRECT(netio_pkt_t* pkt)
1677{
1678 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1679
1680 return NETIO_PKT_L4_CSUM_CORRECT_M(mda, pkt);
1681}
1682
1683
1684/** Determine whether the L3 (IP) checksum was calculated.
1685 * @ingroup ingress
1686 *
1687 * @param[in] pkt Packet on which to operate.
1688 * @return Nonzero if the L3 (IP) checksum was calculated.
1689*/
1690static __inline unsigned int
1691NETIO_PKT_L3_CSUM_CALCULATED(netio_pkt_t* pkt)
1692{
1693 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1694
1695 return NETIO_PKT_L3_CSUM_CALCULATED_M(mda, pkt);
1696}
1697
1698
1699/** Determine whether the L3 (IP) checksum was calculated and found to be
1700 * correct.
1701 * @ingroup ingress
1702 *
1703 * @param[in] pkt Packet on which to operate.
1704 * @return Nonzero if the checksum was calculated and is correct.
1705 */
1706static __inline unsigned int
1707NETIO_PKT_L3_CSUM_CORRECT(netio_pkt_t* pkt)
1708{
1709 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1710
1711 return NETIO_PKT_L3_CSUM_CORRECT_M(mda, pkt);
1712}
1713
1714
1715/** Determine whether the Ethertype was recognized and L3 packet data was
1716 * processed.
1717 * @ingroup ingress
1718 *
1719 * @param[in] pkt Packet on which to operate.
1720 * @return Nonzero if the Ethertype was recognized and L3 packet data was
1721 * processed.
1722 */
1723static __inline unsigned int
1724NETIO_PKT_ETHERTYPE_RECOGNIZED(netio_pkt_t* pkt)
1725{
1726 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1727
1728 return NETIO_PKT_ETHERTYPE_RECOGNIZED_M(mda, pkt);
1729}
1730
1731
1732/** Set an egress packet's L2 length, using a metadata pointer to speed the
1733 * computation.
1734 * @ingroup egress
1735 *
1736 * @param[in,out] mmd Pointer to packet's minimal metadata.
1737 * @param[in] pkt Packet on which to operate.
1738 * @param[in] len Packet L2 length, in bytes.
1739 */
1740static __inline void
1741NETIO_PKT_SET_L2_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt,
1742 int len)
1743{
1744 mmd->l2_length = len;
1745}
1746
1747
1748/** Set an egress packet's L2 length.
1749 * @ingroup egress
1750 *
1751 * @param[in,out] pkt Packet on which to operate.
1752 * @param[in] len Packet L2 length, in bytes.
1753 */
1754static __inline void
1755NETIO_PKT_SET_L2_LENGTH(netio_pkt_t* pkt, int len)
1756{
1757 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1758
1759 NETIO_PKT_SET_L2_LENGTH_MM(mmd, pkt, len);
1760}
1761
1762
1763/** Set an egress packet's L2 header length, using a metadata pointer to
1764 * speed the computation.
1765 * @ingroup egress
1766 *
1767 * It is not normally necessary to call this routine; only the L2 length,
1768 * not the header length, is needed to transmit a packet. It may be useful if
1769 * the egress packet will later be processed by code which expects to use
1770 * functions like @ref NETIO_PKT_L3_DATA() to get a pointer to the L3 payload.
1771 *
1772 * @param[in,out] mmd Pointer to packet's minimal metadata.
1773 * @param[in] pkt Packet on which to operate.
1774 * @param[in] len Packet L2 header length, in bytes.
1775 */
1776static __inline void
1777NETIO_PKT_SET_L2_HEADER_LENGTH_MM(netio_pkt_minimal_metadata_t* mmd,
1778 netio_pkt_t* pkt, int len)
1779{
1780 mmd->l3_offset = mmd->l2_offset + len;
1781}
1782
1783
1784/** Set an egress packet's L2 header length.
1785 * @ingroup egress
1786 *
1787 * It is not normally necessary to call this routine; only the L2 length,
1788 * not the header length, is needed to transmit a packet. It may be useful if
1789 * the egress packet will later be processed by code which expects to use
1790 * functions like @ref NETIO_PKT_L3_DATA() to get a pointer to the L3 payload.
1791 *
1792 * @param[in,out] pkt Packet on which to operate.
1793 * @param[in] len Packet L2 header length, in bytes.
1794 */
1795static __inline void
1796NETIO_PKT_SET_L2_HEADER_LENGTH(netio_pkt_t* pkt, int len)
1797{
1798 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1799
1800 NETIO_PKT_SET_L2_HEADER_LENGTH_MM(mmd, pkt, len);
1801}
1802
1803
1804/** Set up an egress packet for hardware checksum computation, using a
1805 * metadata pointer to speed the operation.
1806 * @ingroup egress
1807 *
1808 * NetIO provides the ability to automatically calculate a standard
1809 * 16-bit Internet checksum on transmitted packets. The application
1810 * may specify the point in the packet where the checksum starts, the
1811 * number of bytes to be checksummed, and the two bytes in the packet
1812 * which will be replaced with the completed checksum. (If the range
1813 * of bytes to be checksummed includes the bytes to be replaced, the
1814 * initial values of those bytes will be included in the checksum.)
1815 *
1816 * For some protocols, the packet checksum covers data which is not present
1817 * in the packet, or is at least not contiguous to the main data payload.
1818 * For instance, the TCP checksum includes a "pseudo-header" which includes
1819 * the source and destination IP addresses of the packet. To accommodate
1820 * this, the checksum engine may be "seeded" with an initial value, which
1821 * the application would need to compute based on the specific protocol's
1822 * requirements. Note that the seed is given in host byte order (little-
1823 * endian), not network byte order (big-endian); code written to compute a
1824 * pseudo-header checksum in network byte order will need to byte-swap it
1825 * before use as the seed.
1826 *
1827 * Note that the checksum is computed as part of the transmission process,
1828 * so it will not be present in the packet upon completion of this routine.
1829 *
1830 * @param[in,out] mmd Pointer to packet's minimal metadata.
1831 * @param[in] pkt Packet on which to operate.
1832 * @param[in] start Offset within L2 packet of the first byte to include in
1833 * the checksum.
1834 * @param[in] length Number of bytes to include in the checksum.
1835 * the checksum.
1836 * @param[in] location Offset within L2 packet of the first of the two bytes
1837 * to be replaced with the calculated checksum.
1838 * @param[in] seed Initial value of the running checksum before any of the
1839 * packet data is added.
1840 */
1841static __inline void
1842NETIO_PKT_DO_EGRESS_CSUM_MM(netio_pkt_minimal_metadata_t* mmd,
1843 netio_pkt_t* pkt, int start, int length,
1844 int location, uint16_t seed)
1845{
1846 mmd->csum_start = start;
1847 mmd->csum_length = length;
1848 mmd->csum_location = location;
1849 mmd->csum_seed = seed;
1850 mmd->flags |= _NETIO_PKT_NEED_EDMA_CSUM_MASK;
1851}
1852
1853
1854/** Set up an egress packet for hardware checksum computation.
1855 * @ingroup egress
1856 *
1857 * NetIO provides the ability to automatically calculate a standard
1858 * 16-bit Internet checksum on transmitted packets. The application
1859 * may specify the point in the packet where the checksum starts, the
1860 * number of bytes to be checksummed, and the two bytes in the packet
1861 * which will be replaced with the completed checksum. (If the range
1862 * of bytes to be checksummed includes the bytes to be replaced, the
1863 * initial values of those bytes will be included in the checksum.)
1864 *
1865 * For some protocols, the packet checksum covers data which is not present
1866 * in the packet, or is at least not contiguous to the main data payload.
1867 * For instance, the TCP checksum includes a "pseudo-header" which includes
1868 * the source and destination IP addresses of the packet. To accommodate
1869 * this, the checksum engine may be "seeded" with an initial value, which
1870 * the application would need to compute based on the specific protocol's
1871 * requirements. Note that the seed is given in host byte order (little-
1872 * endian), not network byte order (big-endian); code written to compute a
1873 * pseudo-header checksum in network byte order will need to byte-swap it
1874 * before use as the seed.
1875 *
1876 * Note that the checksum is computed as part of the transmission process,
1877 * so it will not be present in the packet upon completion of this routine.
1878 *
1879 * @param[in,out] pkt Packet on which to operate.
1880 * @param[in] start Offset within L2 packet of the first byte to include in
1881 * the checksum.
1882 * @param[in] length Number of bytes to include in the checksum.
1883 * the checksum.
1884 * @param[in] location Offset within L2 packet of the first of the two bytes
1885 * to be replaced with the calculated checksum.
1886 * @param[in] seed Initial value of the running checksum before any of the
1887 * packet data is added.
1888 */
1889static __inline void
1890NETIO_PKT_DO_EGRESS_CSUM(netio_pkt_t* pkt, int start, int length,
1891 int location, uint16_t seed)
1892{
1893 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1894
1895 NETIO_PKT_DO_EGRESS_CSUM_MM(mmd, pkt, start, length, location, seed);
1896}
1897
1898
1899/** Return the number of bytes which could be prepended to a packet, using a
1900 * metadata pointer to speed the operation.
1901 * See @ref netio_populate_prepend_buffer() to get a full description of
1902 * prepending.
1903 *
1904 * @param[in,out] mda Pointer to packet's standard metadata.
1905 * @param[in] pkt Packet on which to operate.
1906 */
1907static __inline int
1908NETIO_PKT_PREPEND_AVAIL_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
1909{
1910 return (pkt->__packet.bits.__offset << 6) +
1911 NETIO_PKT_CUSTOM_HEADER_LENGTH_M(mda, pkt);
1912}
1913
1914
1915/** Return the number of bytes which could be prepended to a packet, using a
1916 * metadata pointer to speed the operation.
1917 * See @ref netio_populate_prepend_buffer() to get a full description of
1918 * prepending.
1919 * @ingroup egress
1920 *
1921 * @param[in,out] mmd Pointer to packet's minimal metadata.
1922 * @param[in] pkt Packet on which to operate.
1923 */
1924static __inline int
1925NETIO_PKT_PREPEND_AVAIL_MM(netio_pkt_minimal_metadata_t* mmd, netio_pkt_t* pkt)
1926{
1927 return (pkt->__packet.bits.__offset << 6) + mmd->l2_offset;
1928}
1929
1930
1931/** Return the number of bytes which could be prepended to a packet.
1932 * See @ref netio_populate_prepend_buffer() to get a full description of
1933 * prepending.
1934 * @ingroup egress
1935 *
1936 * @param[in] pkt Packet on which to operate.
1937 */
1938static __inline int
1939NETIO_PKT_PREPEND_AVAIL(netio_pkt_t* pkt)
1940{
1941 if (NETIO_PKT_IS_MINIMAL(pkt))
1942 {
1943 netio_pkt_minimal_metadata_t* mmd = NETIO_PKT_MINIMAL_METADATA(pkt);
1944
1945 return NETIO_PKT_PREPEND_AVAIL_MM(mmd, pkt);
1946 }
1947 else
1948 {
1949 netio_pkt_metadata_t* mda = NETIO_PKT_METADATA(pkt);
1950
1951 return NETIO_PKT_PREPEND_AVAIL_M(mda, pkt);
1952 }
1953}
1954
1955
1956/** Flush a packet's minimal metadata from the cache, using a metadata pointer
1957 * to speed the operation.
1958 * @ingroup egress
1959 *
1960 * @param[in] mmd Pointer to packet's minimal metadata.
1961 * @param[in] pkt Packet on which to operate.
1962 */
1963static __inline void
1964NETIO_PKT_FLUSH_MINIMAL_METADATA_MM(netio_pkt_minimal_metadata_t* mmd,
1965 netio_pkt_t* pkt)
1966{
1967}
1968
1969
1970/** Invalidate a packet's minimal metadata from the cache, using a metadata
1971 * pointer to speed the operation.
1972 * @ingroup egress
1973 *
1974 * @param[in] mmd Pointer to packet's minimal metadata.
1975 * @param[in] pkt Packet on which to operate.
1976 */
1977static __inline void
1978NETIO_PKT_INV_MINIMAL_METADATA_MM(netio_pkt_minimal_metadata_t* mmd,
1979 netio_pkt_t* pkt)
1980{
1981}
1982
1983
1984/** Flush and then invalidate a packet's minimal metadata from the cache,
1985 * using a metadata pointer to speed the operation.
1986 * @ingroup egress
1987 *
1988 * @param[in] mmd Pointer to packet's minimal metadata.
1989 * @param[in] pkt Packet on which to operate.
1990 */
1991static __inline void
1992NETIO_PKT_FLUSH_INV_MINIMAL_METADATA_MM(netio_pkt_minimal_metadata_t* mmd,
1993 netio_pkt_t* pkt)
1994{
1995}
1996
1997
1998/** Flush a packet's metadata from the cache, using a metadata pointer
1999 * to speed the operation.
2000 * @ingroup ingress
2001 *
2002 * @param[in] mda Pointer to packet's minimal metadata.
2003 * @param[in] pkt Packet on which to operate.
2004 */
2005static __inline void
2006NETIO_PKT_FLUSH_METADATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
2007{
2008}
2009
2010
2011/** Invalidate a packet's metadata from the cache, using a metadata
2012 * pointer to speed the operation.
2013 * @ingroup ingress
2014 *
2015 * @param[in] mda Pointer to packet's metadata.
2016 * @param[in] pkt Packet on which to operate.
2017 */
2018static __inline void
2019NETIO_PKT_INV_METADATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
2020{
2021}
2022
2023
2024/** Flush and then invalidate a packet's metadata from the cache,
2025 * using a metadata pointer to speed the operation.
2026 * @ingroup ingress
2027 *
2028 * @param[in] mda Pointer to packet's metadata.
2029 * @param[in] pkt Packet on which to operate.
2030 */
2031static __inline void
2032NETIO_PKT_FLUSH_INV_METADATA_M(netio_pkt_metadata_t* mda, netio_pkt_t* pkt)
2033{
2034}
2035
2036
2037/** Flush a packet's minimal metadata from the cache.
2038 * @ingroup egress
2039 *
2040 * @param[in] pkt Packet on which to operate.
2041 */
2042static __inline void
2043NETIO_PKT_FLUSH_MINIMAL_METADATA(netio_pkt_t* pkt)
2044{
2045}
2046
2047
2048/** Invalidate a packet's minimal metadata from the cache.
2049 * @ingroup egress
2050 *
2051 * @param[in] pkt Packet on which to operate.
2052 */
2053static __inline void
2054NETIO_PKT_INV_MINIMAL_METADATA(netio_pkt_t* pkt)
2055{
2056}
2057
2058
2059/** Flush and then invalidate a packet's minimal metadata from the cache.
2060 * @ingroup egress
2061 *
2062 * @param[in] pkt Packet on which to operate.
2063 */
2064static __inline void
2065NETIO_PKT_FLUSH_INV_MINIMAL_METADATA(netio_pkt_t* pkt)
2066{
2067}
2068
2069
2070/** Flush a packet's metadata from the cache.
2071 * @ingroup ingress
2072 *
2073 * @param[in] pkt Packet on which to operate.
2074 */
2075static __inline void
2076NETIO_PKT_FLUSH_METADATA(netio_pkt_t* pkt)
2077{
2078}
2079
2080
2081/** Invalidate a packet's metadata from the cache.
2082 * @ingroup ingress
2083 *
2084 * @param[in] pkt Packet on which to operate.
2085 */
2086static __inline void
2087NETIO_PKT_INV_METADATA(netio_pkt_t* pkt)
2088{
2089}
2090
2091
2092/** Flush and then invalidate a packet's metadata from the cache.
2093 * @ingroup ingress
2094 *
2095 * @param[in] pkt Packet on which to operate.
2096 */
2097static __inline void
2098NETIO_PKT_FLUSH_INV_METADATA(netio_pkt_t* pkt)
2099{
2100}
2101
2102/** Number of NUMA nodes we can distribute buffers to.
2103 * @ingroup setup */
2104#define NETIO_NUM_NODE_WEIGHTS 16
2105
2106/**
2107 * @brief An object for specifying the characteristics of NetIO communication
2108 * endpoint.
2109 *
2110 * @ingroup setup
2111 *
2112 * The @ref netio_input_register() function uses this structure to define
2113 * how an application tile will communicate with an IPP.
2114 *
2115 *
2116 * Future updates to NetIO may add new members to this structure,
2117 * which can affect the success of the registration operation. Thus,
2118 * if dynamically initializing the structure, applications are urged to
2119 * zero it out first, for example:
2120 *
2121 * @code
2122 * netio_input_config_t config;
2123 * memset(&config, 0, sizeof (config));
2124 * config.flags = NETIO_RECV | NETIO_XMIT_CSUM | NETIO_TAG_NONE;
2125 * config.num_receive_packets = NETIO_MAX_RECEIVE_PKTS;
2126 * config.queue_id = 0;
2127 * .
2128 * .
2129 * .
2130 * @endcode
2131 *
2132 * since that guarantees that any unused structure members, including
2133 * members which did not exist when the application was first developed,
2134 * will not have unexpected values.
2135 *
2136 * If statically initializing the structure, we strongly recommend use of
2137 * C99-style named initializers, for example:
2138 *
2139 * @code
2140 * netio_input_config_t config = {
2141 * .flags = NETIO_RECV | NETIO_XMIT_CSUM | NETIO_TAG_NONE,
2142 * .num_receive_packets = NETIO_MAX_RECEIVE_PKTS,
2143 * .queue_id = 0,
2144 * },
2145 * @endcode
2146 *
2147 * instead of the old-style structure initialization:
2148 *
2149 * @code
2150 * // Bad example! Currently equivalent to the above, but don't do this.
2151 * netio_input_config_t config = {
2152 * NETIO_RECV | NETIO_XMIT_CSUM | NETIO_TAG_NONE, NETIO_MAX_RECEIVE_PKTS, 0
2153 * },
2154 * @endcode
2155 *
2156 * since the C99 style requires no changes to the code if elements of the
2157 * config structure are rearranged. (It also makes the initialization much
2158 * easier to understand.)
2159 *
2160 * Except for items which address a particular tile's transmit or receive
2161 * characteristics, such as the ::NETIO_RECV flag, applications are advised
2162 * to specify the same set of configuration data on all registrations.
2163 * This prevents differing results if multiple tiles happen to do their
2164 * registration operations in a different order on different invocations of
2165 * the application. This is particularly important for things like link
2166 * management flags, and buffer size and homing specifications.
2167 *
2168 * Unless the ::NETIO_FIXED_BUFFER_VA flag is specified in flags, the NetIO
2169 * buffer pool is automatically created and mapped into the application's
2170 * virtual address space at an address chosen by the operating system,
2171 * using the common memory (cmem) facility in the Tilera Multicore
2172 * Components library. The cmem facility allows multiple processes to gain
2173 * access to shared memory which is mapped into each process at an
2174 * identical virtual address. In order for this to work, the processes
2175 * must have a common ancestor, which must create the common memory using
2176 * tmc_cmem_init().
2177 *
2178 * In programs using the iLib process creation API, or in programs which use
2179 * only one process (which include programs using the pthreads library),
2180 * tmc_cmem_init() is called automatically. All other applications
2181 * must call it explicitly, before any child processes which might call
2182 * netio_input_register() are created.
2183 */
2184typedef struct
2185{
2186 /** Registration characteristics.
2187
2188 This value determines several characteristics of the registration;
2189 flags for different types of behavior are ORed together to make the
2190 final flag value. Generally applications should specify exactly
2191 one flag from each of the following categories:
2192
2193 - Whether the application will be receiving packets on this queue
2194 (::NETIO_RECV or ::NETIO_NO_RECV).
2195
2196 - Whether the application will be transmitting packets on this queue,
2197 and if so, whether it will request egress checksum calculation
2198 (::NETIO_XMIT, ::NETIO_XMIT_CSUM, or ::NETIO_NO_XMIT). It is
2199 legal to call netio_get_buffer() without one of the XMIT flags,
2200 as long as ::NETIO_RECV is specified; in this case, the retrieved
2201 buffers must be passed to another tile for transmission.
2202
2203 - Whether the application expects any vendor-specific tags in
2204 its packets' L2 headers (::NETIO_TAG_NONE, ::NETIO_TAG_BRCM,
2205 or ::NETIO_TAG_MRVL). This must match the configuration of the
2206 target IPP.
2207
2208 To accommodate applications written to previous versions of the NetIO
2209 interface, none of the flags above are currently required; if omitted,
2210 NetIO behaves more or less as if ::NETIO_RECV | ::NETIO_XMIT_CSUM |
2211 ::NETIO_TAG_NONE were used. However, explicit specification of
2212 the relevant flags allows NetIO to do a better job of resource
2213 allocation, allows earlier detection of certain configuration errors,
2214 and may enable advanced features or higher performance in the future,
2215 so their use is strongly recommended.
2216
2217 Note that specifying ::NETIO_NO_RECV along with ::NETIO_NO_XMIT
2218 is a special case, intended primarily for use by programs which
2219 retrieve network statistics or do link management operations.
2220 When these flags are both specified, the resulting queue may not
2221 be used with NetIO routines other than netio_get(), netio_set(),
2222 and netio_input_unregister(). See @ref link for more information
2223 on link management.
2224
2225 Other flags are optional; their use is described below.
2226 */
2227 int flags;
2228
2229 /** Interface name. This is a string which identifies the specific
2230 Ethernet controller hardware to be used. The format of the string
2231 is a device type and a device index, separated by a slash; so,
2232 the first 10 Gigabit Ethernet controller is named "xgbe/0", while
2233 the second 10/100/1000 Megabit Ethernet controller is named "gbe/1".
2234 */
2235 const char* interface;
2236
2237 /** Receive packet queue size. This specifies the maximum number
2238 of ingress packets that can be received on this queue without
2239 being retrieved by @ref netio_get_packet(). If the IPP's distribution
2240 algorithm calls for a packet to be sent to this queue, and this
2241 number of packets are already pending there, the new packet
2242 will either be discarded, or sent to another tile registered
2243 for the same queue_id (see @ref drops). This value must
2244 be at least ::NETIO_MIN_RECEIVE_PKTS, can always be at least
2245 ::NETIO_MAX_RECEIVE_PKTS, and may be larger than that on certain
2246 interfaces.
2247 */
2248 int num_receive_packets;
2249
2250 /** The queue ID being requested. Legal values for this range from 0
2251 to ::NETIO_MAX_QUEUE_ID, inclusive. ::NETIO_MAX_QUEUE_ID is always
2252 greater than or equal to the number of tiles; this allows one queue
2253 for each tile, plus at least one additional queue. Some applications
2254 may wish to use the additional queue as a destination for unwanted
2255 packets, since packets delivered to queues for which no tiles have
2256 registered are discarded.
2257 */
2258 unsigned int queue_id;
2259
2260 /** Maximum number of small send buffers to be held in the local empty
2261 buffer cache. This specifies the size of the area which holds
2262 empty small egress buffers requested from the IPP but not yet
2263 retrieved via @ref netio_get_buffer(). This value must be greater
2264 than zero if the application will ever use @ref netio_get_buffer()
2265 to allocate empty small egress buffers; it may be no larger than
2266 ::NETIO_MAX_SEND_BUFFERS. See @ref epp for more details on empty
2267 buffer caching.
2268 */
2269 int num_send_buffers_small_total;
2270
2271 /** Number of small send buffers to be preallocated at registration.
2272 If this value is nonzero, the specified number of empty small egress
2273 buffers will be requested from the IPP during the netio_input_register
2274 operation; this may speed the execution of @ref netio_get_buffer().
2275 This may be no larger than @ref num_send_buffers_small_total. See @ref
2276 epp for more details on empty buffer caching.
2277 */
2278 int num_send_buffers_small_prealloc;
2279
2280 /** Maximum number of large send buffers to be held in the local empty
2281 buffer cache. This specifies the size of the area which holds empty
2282 large egress buffers requested from the IPP but not yet retrieved via
2283 @ref netio_get_buffer(). This value must be greater than zero if the
2284 application will ever use @ref netio_get_buffer() to allocate empty
2285 large egress buffers; it may be no larger than ::NETIO_MAX_SEND_BUFFERS.
2286 See @ref epp for more details on empty buffer caching.
2287 */
2288 int num_send_buffers_large_total;
2289
2290 /** Number of large send buffers to be preallocated at registration.
2291 If this value is nonzero, the specified number of empty large egress
2292 buffers will be requested from the IPP during the netio_input_register
2293 operation; this may speed the execution of @ref netio_get_buffer().
2294 This may be no larger than @ref num_send_buffers_large_total. See @ref
2295 epp for more details on empty buffer caching.
2296 */
2297 int num_send_buffers_large_prealloc;
2298
2299 /** Maximum number of jumbo send buffers to be held in the local empty
2300 buffer cache. This specifies the size of the area which holds empty
2301 jumbo egress buffers requested from the IPP but not yet retrieved via
2302 @ref netio_get_buffer(). This value must be greater than zero if the
2303 application will ever use @ref netio_get_buffer() to allocate empty
2304 jumbo egress buffers; it may be no larger than ::NETIO_MAX_SEND_BUFFERS.
2305 See @ref epp for more details on empty buffer caching.
2306 */
2307 int num_send_buffers_jumbo_total;
2308
2309 /** Number of jumbo send buffers to be preallocated at registration.
2310 If this value is nonzero, the specified number of empty jumbo egress
2311 buffers will be requested from the IPP during the netio_input_register
2312 operation; this may speed the execution of @ref netio_get_buffer().
2313 This may be no larger than @ref num_send_buffers_jumbo_total. See @ref
2314 epp for more details on empty buffer caching.
2315 */
2316 int num_send_buffers_jumbo_prealloc;
2317
2318 /** Total packet buffer size. This determines the total size, in bytes,
2319 of the NetIO buffer pool. Note that the maximum number of available
2320 buffers of each size is determined during hypervisor configuration
2321 (see the <em>System Programmer's Guide</em> for details); this just
2322 influences how much host memory is allocated for those buffers.
2323
2324 The buffer pool is allocated from common memory, which will be
2325 automatically initialized if needed. If your buffer pool is larger
2326 than 240 MB, you might need to explicitly call @c tmc_cmem_init(),
2327 as described in the Application Libraries Reference Manual (UG227).
2328
2329 Packet buffers are currently allocated in chunks of 16 MB; this
2330 value will be rounded up to the next larger multiple of 16 MB.
2331 If this value is zero, a default of 32 MB will be used; this was
2332 the value used by previous versions of NetIO. Note that taking this
2333 default also affects the placement of buffers on Linux NUMA nodes.
2334 See @ref buffer_node_weights for an explanation of buffer placement.
2335
2336 In order to successfully allocate packet buffers, Linux must have
2337 available huge pages on the relevant Linux NUMA nodes. See the
2338 <em>System Programmer's Guide</em> for information on configuring
2339 huge page support in Linux.
2340 */
2341 uint64_t total_buffer_size;
2342
2343 /** Buffer placement weighting factors.
2344
2345 This array specifies the relative amount of buffering to place
2346 on each of the available Linux NUMA nodes. This array is
2347 indexed by the NUMA node, and the values in the array are
2348 proportional to the amount of buffer space to allocate on that
2349 node.
2350
2351 If memory striping is enabled in the Hypervisor, then there is
2352 only one logical NUMA node (node 0). In that case, NetIO will by
2353 default ignore the suggested buffer node weights, and buffers
2354 will be striped across the physical memory controllers. See
2355 UG209 System Programmer's Guide for a description of the
2356 hypervisor option that controls memory striping.
2357
2358 If memory striping is disabled, then there are up to four NUMA
2359 nodes, corresponding to the four DDRAM controllers in the TILE
2360 processor architecture. See UG100 Tile Processor Architecture
2361 Overview for a diagram showing the location of each of the DDRAM
2362 controllers relative to the tile array.
2363
2364 For instance, if memory striping is disabled, the following
2365 configuration strucure:
2366
2367 @code
2368 netio_input_config_t config = {
2369 .
2370 .
2371 .
2372 .total_buffer_size = 4 * 16 * 1024 * 1024;
2373 .buffer_node_weights = { 1, 0, 1, 0 },
2374 },
2375 @endcode
2376
2377 would result in 32 MB of buffers being placed on controller 0, and
2378 32 MB on controller 2. (Since buffers are allocated in units of
2379 16 MB, some sets of weights will not be able to be matched exactly.)
2380
2381 For the weights to be effective, @ref total_buffer_size must be
2382 nonzero. If @ref total_buffer_size is zero, causing the default
2383 32 MB of buffer space to be used, then any specified weights will
2384 be ignored, and buffers will positioned as they were in previous
2385 versions of NetIO:
2386
2387 - For xgbe/0 and gbe/0, 16 MB of buffers will be placed on controller 1,
2388 and the other 16 MB will be placed on controller 2.
2389
2390 - For xgbe/1 and gbe/1, 16 MB of buffers will be placed on controller 2,
2391 and the other 16 MB will be placed on controller 3.
2392
2393 If @ref total_buffer_size is nonzero, but all weights are zero,
2394 then all buffer space will be allocated on Linux NUMA node zero.
2395
2396 By default, the specified buffer placement is treated as a hint;
2397 if sufficient free memory is not available on the specified
2398 controllers, the buffers will be allocated elsewhere. However,
2399 if the ::NETIO_STRICT_HOMING flag is specified in @ref flags, then a
2400 failure to allocate buffer space exactly as requested will cause the
2401 registration operation to fail with an error of ::NETIO_CANNOT_HOME.
2402
2403 Note that maximal network performance cannot be achieved with
2404 only one memory controller.
2405 */
2406 uint8_t buffer_node_weights[NETIO_NUM_NODE_WEIGHTS];
2407
2408 /** Fixed virtual address for packet buffers. Only valid when
2409 ::NETIO_FIXED_BUFFER_VA is specified in @ref flags; see the
2410 description of that flag for details.
2411 */
2412 void* fixed_buffer_va;
2413
2414 /**
2415 Maximum number of outstanding send packet requests. This value is
2416 only relevant when an EPP is in use; it determines the number of
2417 slots in the EPP's outgoing packet queue which this tile is allowed
2418 to consume, and thus the number of packets which may be sent before
2419 the sending tile must wait for an acknowledgment from the EPP.
2420 Modifying this value is generally only helpful when using @ref
2421 netio_send_packet_vector(), where it can help improve performance by
2422 allowing a single vector send operation to process more packets.
2423 Typically it is not specified, and the default, which divides the
2424 outgoing packet slots evenly between all tiles on the chip, is used.
2425
2426 If a registration asks for more outgoing packet queue slots than are
2427 available, ::NETIO_TOOMANY_XMIT will be returned. The total number
2428 of packet queue slots which are available for all tiles for each EPP
2429 is subject to change, but is currently ::NETIO_TOTAL_SENDS_OUTSTANDING.
2430
2431
2432 This value is ignored if ::NETIO_XMIT is not specified in flags.
2433 If you want to specify a large value here for a specific tile, you are
2434 advised to specify NETIO_NO_XMIT on other, non-transmitting tiles so
2435 that they do not consume a default number of packet slots. Any tile
2436 transmitting is required to have at least ::NETIO_MIN_SENDS_OUTSTANDING
2437 slots allocated to it; values less than that will be silently
2438 increased by the NetIO library.
2439 */
2440 int num_sends_outstanding;
2441}
2442netio_input_config_t;
2443
2444
2445/** Registration flags; used in the @ref netio_input_config_t structure.
2446 * @addtogroup setup
2447 */
2448/** @{ */
2449
2450/** Fail a registration request if we can't put packet buffers
2451 on the specified memory controllers. */
2452#define NETIO_STRICT_HOMING 0x00000002
2453
2454/** This application expects no tags on its L2 headers. */
2455#define NETIO_TAG_NONE 0x00000004
2456
2457/** This application expects Marvell extended tags on its L2 headers. */
2458#define NETIO_TAG_MRVL 0x00000008
2459
2460/** This application expects Broadcom tags on its L2 headers. */
2461#define NETIO_TAG_BRCM 0x00000010
2462
2463/** This registration may call routines which receive packets. */
2464#define NETIO_RECV 0x00000020
2465
2466/** This registration may not call routines which receive packets. */
2467#define NETIO_NO_RECV 0x00000040
2468
2469/** This registration may call routines which transmit packets. */
2470#define NETIO_XMIT 0x00000080
2471
2472/** This registration may call routines which transmit packets with
2473 checksum acceleration. */
2474#define NETIO_XMIT_CSUM 0x00000100
2475
2476/** This registration may not call routines which transmit packets. */
2477#define NETIO_NO_XMIT 0x00000200
2478
2479/** This registration wants NetIO buffers mapped at an application-specified
2480 virtual address.
2481
2482 NetIO buffers are by default created by the TMC common memory facility,
2483 which must be configured by a common ancestor of all processes sharing
2484 a network interface. When this flag is specified, NetIO buffers are
2485 instead mapped at an address chosen by the application (and specified
2486 in @ref netio_input_config_t::fixed_buffer_va). This allows multiple
2487 unrelated but cooperating processes to share a NetIO interface.
2488 All processes sharing the same interface must specify this flag,
2489 and all must specify the same fixed virtual address.
2490
2491 @ref netio_input_config_t::fixed_buffer_va must be a
2492 multiple of 16 MB, and the packet buffers will occupy @ref
2493 netio_input_config_t::total_buffer_size bytes of virtual address
2494 space, beginning at that address. If any of those virtual addresses
2495 are currently occupied by other memory objects, like application or
2496 shared library code or data, @ref netio_input_register() will return
2497 ::NETIO_FAULT. While it is impossible to provide a fixed_buffer_va
2498 which will work for all applications, a good first guess might be to
2499 use 0xb0000000 minus @ref netio_input_config_t::total_buffer_size.
2500 If that fails, it might be helpful to consult the running application's
2501 virtual address description file (/proc/<em>pid</em>/maps) to see
2502 which regions of virtual address space are available.
2503 */
2504#define NETIO_FIXED_BUFFER_VA 0x00000400
2505
2506/** This registration call will not complete unless the network link
2507 is up. The process will wait several seconds for this to happen (the
2508 precise interval is link-dependent), but if the link does not come up,
2509 ::NETIO_LINK_DOWN will be returned. This flag is the default if
2510 ::NETIO_NOREQUIRE_LINK_UP is not specified. Note that this flag by
2511 itself does not request that the link be brought up; that can be done
2512 with the ::NETIO_AUTO_LINK_UPDN or ::NETIO_AUTO_LINK_UP flags (the
2513 latter is the default if no NETIO_AUTO_LINK_xxx flags are specified),
2514 or by explicitly setting the link's desired state via netio_set().
2515 If the link is not brought up by one of those methods, and this flag
2516 is specified, the registration operation will return ::NETIO_LINK_DOWN.
2517 This flag is ignored if it is specified along with ::NETIO_NO_XMIT and
2518 ::NETIO_NO_RECV. See @ref link for more information on link
2519 management.
2520 */
2521#define NETIO_REQUIRE_LINK_UP 0x00000800
2522
2523/** This registration call will complete even if the network link is not up.
2524 Whenever the link is not up, packets will not be sent or received:
2525 netio_get_packet() will return ::NETIO_NOPKT once all queued packets
2526 have been drained, and netio_send_packet() and similar routines will
2527 return NETIO_QUEUE_FULL once the outgoing packet queue in the EPP
2528 or the I/O shim is full. See @ref link for more information on link
2529 management.
2530 */
2531#define NETIO_NOREQUIRE_LINK_UP 0x00001000
2532
2533#ifndef __DOXYGEN__
2534/*
2535 * These are part of the implementation of the NETIO_AUTO_LINK_xxx flags,
2536 * but should not be used directly by applications, and are thus not
2537 * documented.
2538 */
2539#define _NETIO_AUTO_UP 0x00002000
2540#define _NETIO_AUTO_DN 0x00004000
2541#define _NETIO_AUTO_PRESENT 0x00008000
2542#endif
2543
2544/** Set the desired state of the link to up, allowing any speeds which are
2545 supported by the link hardware, as part of this registration operation.
2546 Do not take down the link automatically. This is the default if
2547 no other NETIO_AUTO_LINK_xxx flags are specified. This flag is ignored
2548 if it is specified along with ::NETIO_NO_XMIT and ::NETIO_NO_RECV.
2549 See @ref link for more information on link management.
2550 */
2551#define NETIO_AUTO_LINK_UP (_NETIO_AUTO_PRESENT | _NETIO_AUTO_UP)
2552
2553/** Set the desired state of the link to up, allowing any speeds which are
2554 supported by the link hardware, as part of this registration operation.
2555 Set the desired state of the link to down the next time no tiles are
2556 registered for packet reception or transmission. This flag is ignored
2557 if it is specified along with ::NETIO_NO_XMIT and ::NETIO_NO_RECV.
2558 See @ref link for more information on link management.
2559 */
2560#define NETIO_AUTO_LINK_UPDN (_NETIO_AUTO_PRESENT | _NETIO_AUTO_UP | \
2561 _NETIO_AUTO_DN)
2562
2563/** Set the desired state of the link to down the next time no tiles are
2564 registered for packet reception or transmission. This flag is ignored
2565 if it is specified along with ::NETIO_NO_XMIT and ::NETIO_NO_RECV.
2566 See @ref link for more information on link management.
2567 */
2568#define NETIO_AUTO_LINK_DN (_NETIO_AUTO_PRESENT | _NETIO_AUTO_DN)
2569
2570/** Do not bring up the link automatically as part of this registration
2571 operation. Do not take down the link automatically. This flag
2572 is ignored if it is specified along with ::NETIO_NO_XMIT and
2573 ::NETIO_NO_RECV. See @ref link for more information on link management.
2574 */
2575#define NETIO_AUTO_LINK_NONE _NETIO_AUTO_PRESENT
2576
2577
2578/** Minimum number of receive packets. */
2579#define NETIO_MIN_RECEIVE_PKTS 16
2580
2581/** Lower bound on the maximum number of receive packets; may be higher
2582 than this on some interfaces. */
2583#define NETIO_MAX_RECEIVE_PKTS 128
2584
2585/** Maximum number of send buffers, per packet size. */
2586#define NETIO_MAX_SEND_BUFFERS 16
2587
2588/** Number of EPP queue slots, and thus outstanding sends, per EPP. */
2589#define NETIO_TOTAL_SENDS_OUTSTANDING 2015
2590
2591/** Minimum number of EPP queue slots, and thus outstanding sends, per
2592 * transmitting tile. */
2593#define NETIO_MIN_SENDS_OUTSTANDING 16
2594
2595
2596/**@}*/
2597
2598#ifndef __DOXYGEN__
2599
2600/**
2601 * An object for providing Ethernet packets to a process.
2602 */
2603struct __netio_queue_impl_t;
2604
2605/**
2606 * An object for managing the user end of a NetIO queue.
2607 */
2608struct __netio_queue_user_impl_t;
2609
2610#endif /* !__DOXYGEN__ */
2611
2612
2613/** A netio_queue_t describes a NetIO communications endpoint.
2614 * @ingroup setup
2615 */
2616typedef struct
2617{
2618#ifdef __DOXYGEN__
2619 uint8_t opaque[8]; /**< This is an opaque structure. */
2620#else
2621 struct __netio_queue_impl_t* __system_part; /**< The system part. */
2622 struct __netio_queue_user_impl_t* __user_part; /**< The user part. */
2623#ifdef _NETIO_PTHREAD
2624 _netio_percpu_mutex_t lock; /**< Queue lock. */
2625#endif
2626#endif
2627}
2628netio_queue_t;
2629
2630
2631/**
2632 * @brief Packet send context.
2633 *
2634 * @ingroup egress
2635 *
2636 * Packet send context for use with netio_send_packet_prepare and _commit.
2637 */
2638typedef struct
2639{
2640#ifdef __DOXYGEN__
2641 uint8_t opaque[44]; /**< This is an opaque structure. */
2642#else
2643 uint8_t flags; /**< Defined below */
2644 uint8_t datalen; /**< Number of valid words pointed to by data. */
2645 uint32_t request[9]; /**< Request to be sent to the EPP or shim. Note
2646 that this is smaller than the 11-word maximum
2647 request size, since some constant values are
2648 not saved in the context. */
2649 uint32_t *data; /**< Data to be sent to the EPP or shim via IDN. */
2650#endif
2651}
2652netio_send_pkt_context_t;
2653
2654
2655#ifndef __DOXYGEN__
2656#define SEND_PKT_CTX_USE_EPP 1 /**< We're sending to an EPP. */
2657#define SEND_PKT_CTX_SEND_CSUM 2 /**< Request includes a checksum. */
2658#endif
2659
2660/**
2661 * @brief Packet vector entry.
2662 *
2663 * @ingroup egress
2664 *
2665 * This data structure is used with netio_send_packet_vector() to send multiple
2666 * packets with one NetIO call. The structure should be initialized by
2667 * calling netio_pkt_vector_set(), rather than by setting the fields
2668 * directly.
2669 *
2670 * This structure is guaranteed to be a power of two in size, no
2671 * bigger than one L2 cache line, and to be aligned modulo its size.
2672 */
2673typedef struct
2674#ifndef __DOXYGEN__
2675__attribute__((aligned(8)))
2676#endif
2677{
2678 /** Reserved for use by the user application. When initialized with
2679 * the netio_set_pkt_vector_entry() function, this field is guaranteed
2680 * to be visible to readers only after all other fields are already
2681 * visible. This way it can be used as a valid flag or generation
2682 * counter. */
2683 uint8_t user_data;
2684
2685 /* Structure members below this point should not be accessed directly by
2686 * applications, as they may change in the future. */
2687
2688 /** Low 8 bits of the packet address to send. The high bits are
2689 * acquired from the 'handle' field. */
2690 uint8_t buffer_address_low;
2691
2692 /** Number of bytes to transmit. */
2693 uint16_t size;
2694
2695 /** The raw handle from a netio_pkt_t. If this is NETIO_PKT_HANDLE_NONE,
2696 * this vector entry will be skipped and no packet will be transmitted. */
2697 netio_pkt_handle_t handle;
2698}
2699netio_pkt_vector_entry_t;
2700
2701
2702/**
2703 * @brief Initialize fields in a packet vector entry.
2704 *
2705 * @ingroup egress
2706 *
2707 * @param[out] v Pointer to the vector entry to be initialized.
2708 * @param[in] pkt Packet to be transmitted when the vector entry is passed to
2709 * netio_send_packet_vector(). Note that the packet's attributes
2710 * (e.g., its L2 offset and length) are captured at the time this
2711 * routine is called; subsequent changes in those attributes will not
2712 * be reflected in the packet which is actually transmitted.
2713 * Changes in the packet's contents, however, will be so reflected.
2714 * If this is NULL, no packet will be transmitted.
2715 * @param[in] user_data User data to be set in the vector entry.
2716 * This function guarantees that the "user_data" field will become
2717 * visible to a reader only after all other fields have become visible.
2718 * This allows a structure in a ring buffer to be written and read
2719 * by a polling reader without any locks or other synchronization.
2720 */
2721static __inline void
2722netio_pkt_vector_set(volatile netio_pkt_vector_entry_t* v, netio_pkt_t* pkt,
2723 uint8_t user_data)
2724{
2725 if (pkt)
2726 {
2727 if (NETIO_PKT_IS_MINIMAL(pkt))
2728 {
2729 netio_pkt_minimal_metadata_t* mmd =
2730 (netio_pkt_minimal_metadata_t*) &pkt->__metadata;
2731 v->buffer_address_low = (uintptr_t) NETIO_PKT_L2_DATA_MM(mmd, pkt) & 0xFF;
2732 v->size = NETIO_PKT_L2_LENGTH_MM(mmd, pkt);
2733 }
2734 else
2735 {
2736 netio_pkt_metadata_t* mda = &pkt->__metadata;
2737 v->buffer_address_low = (uintptr_t) NETIO_PKT_L2_DATA_M(mda, pkt) & 0xFF;
2738 v->size = NETIO_PKT_L2_LENGTH_M(mda, pkt);
2739 }
2740 v->handle.word = pkt->__packet.word;
2741 }
2742 else
2743 {
2744 v->handle.word = 0; /* Set handle to NETIO_PKT_HANDLE_NONE. */
2745 }
2746
2747 __asm__("" : : : "memory");
2748
2749 v->user_data = user_data;
2750}
2751
2752
2753/**
2754 * Flags and structures for @ref netio_get() and @ref netio_set().
2755 * @ingroup config
2756 */
2757
2758/** @{ */
2759/** Parameter class; addr is a NETIO_PARAM_xxx value. */
2760#define NETIO_PARAM 0
2761/** Interface MAC address. This address is only valid with @ref netio_get().
2762 * The value is a 6-byte MAC address. Depending upon the overall system
2763 * design, a MAC address may or may not be available for each interface. */
2764#define NETIO_PARAM_MAC 0
2765
2766/** Determine whether to suspend output on the receipt of pause frames.
2767 * If the value is nonzero, the I/O shim will suspend output when a pause
2768 * frame is received. If the value is zero, pause frames will be ignored. */
2769#define NETIO_PARAM_PAUSE_IN 1
2770
2771/** Determine whether to send pause frames if the I/O shim packet FIFOs are
2772 * nearly full. If the value is zero, pause frames are not sent. If
2773 * the value is nonzero, it is the delay value which will be sent in any
2774 * pause frames which are output, in units of 512 bit times. */
2775#define NETIO_PARAM_PAUSE_OUT 2
2776
2777/** Jumbo frame support. The value is a 4-byte integer. If the value is
2778 * nonzero, the MAC will accept frames of up to 10240 bytes. If the value
2779 * is zero, the MAC will only accept frames of up to 1544 bytes. */
2780#define NETIO_PARAM_JUMBO 3
2781
2782/** I/O shim's overflow statistics register. The value is two 16-bit integers.
2783 * The first 16-bit value (or the low 16 bits, if the value is treated as a
2784 * 32-bit number) is the count of packets which were completely dropped and
2785 * not delivered by the shim. The second 16-bit value (or the high 16 bits,
2786 * if the value is treated as a 32-bit number) is the count of packets
2787 * which were truncated and thus only partially delivered by the shim. This
2788 * register is automatically reset to zero after it has been read.
2789 */
2790#define NETIO_PARAM_OVERFLOW 4
2791
2792/** IPP statistics. This address is only valid with @ref netio_get(). The
2793 * value is a netio_stat_t structure. Unlike the I/O shim statistics, the
2794 * IPP statistics are not all reset to zero on read; see the description
2795 * of the netio_stat_t for details. */
2796#define NETIO_PARAM_STAT 5
2797
2798/** Possible link state. The value is a combination of "NETIO_LINK_xxx"
2799 * flags. With @ref netio_get(), this will indicate which flags are
2800 * actually supported by the hardware.
2801 *
2802 * For historical reasons, specifying this value to netio_set() will have
2803 * the same behavior as using ::NETIO_PARAM_LINK_CONFIG, but this usage is
2804 * discouraged.
2805 */
2806#define NETIO_PARAM_LINK_POSSIBLE_STATE 6
2807
2808/** Link configuration. The value is a combination of "NETIO_LINK_xxx" flags.
2809 * With @ref netio_set(), this will attempt to immediately bring up the
2810 * link using whichever of the requested flags are supported by the
2811 * hardware, or take down the link if the flags are zero; if this is
2812 * not possible, an error will be returned. Many programs will want
2813 * to use ::NETIO_PARAM_LINK_DESIRED_STATE instead.
2814 *
2815 * For historical reasons, specifying this value to netio_get() will
2816 * have the same behavior as using ::NETIO_PARAM_LINK_POSSIBLE_STATE,
2817 * but this usage is discouraged.
2818 */
2819#define NETIO_PARAM_LINK_CONFIG NETIO_PARAM_LINK_POSSIBLE_STATE
2820
2821/** Current link state. This address is only valid with @ref netio_get().
2822 * The value is zero or more of the "NETIO_LINK_xxx" flags, ORed together.
2823 * If the link is down, the value ANDed with NETIO_LINK_SPEED will be
2824 * zero; if the link is up, the value ANDed with NETIO_LINK_SPEED will
2825 * result in exactly one of the NETIO_LINK_xxx values, indicating the
2826 * current speed. */
2827#define NETIO_PARAM_LINK_CURRENT_STATE 7
2828
2829/** Variant symbol for current state, retained for compatibility with
2830 * pre-MDE-2.1 programs. */
2831#define NETIO_PARAM_LINK_STATUS NETIO_PARAM_LINK_CURRENT_STATE
2832
2833/** Packet Coherence protocol. This address is only valid with @ref netio_get().
2834 * The value is nonzero if the interface is configured for cache-coherent DMA.
2835 */
2836#define NETIO_PARAM_COHERENT 8
2837
2838/** Desired link state. The value is a conbination of "NETIO_LINK_xxx"
2839 * flags, which specify the desired state for the link. With @ref
2840 * netio_set(), this will, in the background, attempt to bring up the link
2841 * using whichever of the requested flags are reasonable, or take down the
2842 * link if the flags are zero. The actual link up or down operation may
2843 * happen after this call completes. If the link state changes in the
2844 * future, the system will continue to try to get back to the desired link
2845 * state; for instance, if the link is brought up successfully, and then
2846 * the network cable is disconnected, the link will go down. However, the
2847 * desired state of the link is still up, so if the cable is reconnected,
2848 * the link will be brought up again.
2849 *
2850 * With @ref netio_get(), this will indicate the desired state for the
2851 * link, as set with a previous netio_set() call, or implicitly by a
2852 * netio_input_register() or netio_input_unregister() operation. This may
2853 * not reflect the current state of the link; to get that, use
2854 * ::NETIO_PARAM_LINK_CURRENT_STATE. */
2855#define NETIO_PARAM_LINK_DESIRED_STATE 9
2856
2857/** NetIO statistics structure. Retrieved using the ::NETIO_PARAM_STAT
2858 * address passed to @ref netio_get(). */
2859typedef struct
2860{
2861 /** Number of packets which have been received by the IPP and forwarded
2862 * to a tile's receive queue for processing. This value wraps at its
2863 * maximum, and is not cleared upon read. */
2864 uint32_t packets_received;
2865
2866 /** Number of packets which have been dropped by the IPP, because they could
2867 * not be received, or could not be forwarded to a tile. The former happens
2868 * when the IPP does not have a free packet buffer of suitable size for an
2869 * incoming frame. The latter happens when all potential destination tiles
2870 * for a packet, as defined by the group, bucket, and queue configuration,
2871 * have full receive queues. This value wraps at its maximum, and is not
2872 * cleared upon read. */
2873 uint32_t packets_dropped;
2874
2875 /*
2876 * Note: the #defines after each of the following four one-byte values
2877 * denote their location within the third word of the netio_stat_t. They
2878 * are intended for use only by the IPP implementation and are thus omitted
2879 * from the Doxygen output.
2880 */
2881
2882 /** Number of packets dropped because no worker was able to accept a new
2883 * packet. This value saturates at its maximum, and is cleared upon
2884 * read. */
2885 uint8_t drops_no_worker;
2886#ifndef __DOXYGEN__
2887#define NETIO_STAT_DROPS_NO_WORKER 0
2888#endif
2889
2890 /** Number of packets dropped because no small buffers were available.
2891 * This value saturates at its maximum, and is cleared upon read. */
2892 uint8_t drops_no_smallbuf;
2893#ifndef __DOXYGEN__
2894#define NETIO_STAT_DROPS_NO_SMALLBUF 1
2895#endif
2896
2897 /** Number of packets dropped because no large buffers were available.
2898 * This value saturates at its maximum, and is cleared upon read. */
2899 uint8_t drops_no_largebuf;
2900#ifndef __DOXYGEN__
2901#define NETIO_STAT_DROPS_NO_LARGEBUF 2
2902#endif
2903
2904 /** Number of packets dropped because no jumbo buffers were available.
2905 * This value saturates at its maximum, and is cleared upon read. */
2906 uint8_t drops_no_jumbobuf;
2907#ifndef __DOXYGEN__
2908#define NETIO_STAT_DROPS_NO_JUMBOBUF 3
2909#endif
2910}
2911netio_stat_t;
2912
2913
2914/** Link can run, should run, or is running at 10 Mbps. */
2915#define NETIO_LINK_10M 0x01
2916
2917/** Link can run, should run, or is running at 100 Mbps. */
2918#define NETIO_LINK_100M 0x02
2919
2920/** Link can run, should run, or is running at 1 Gbps. */
2921#define NETIO_LINK_1G 0x04
2922
2923/** Link can run, should run, or is running at 10 Gbps. */
2924#define NETIO_LINK_10G 0x08
2925
2926/** Link should run at the highest speed supported by the link and by
2927 * the device connected to the link. Only usable as a value for
2928 * the link's desired state; never returned as a value for the current
2929 * or possible states. */
2930#define NETIO_LINK_ANYSPEED 0x10
2931
2932/** All legal link speeds. */
2933#define NETIO_LINK_SPEED (NETIO_LINK_10M | \
2934 NETIO_LINK_100M | \
2935 NETIO_LINK_1G | \
2936 NETIO_LINK_10G | \
2937 NETIO_LINK_ANYSPEED)
2938
2939
2940/** MAC register class. Addr is a register offset within the MAC.
2941 * Registers within the XGbE and GbE MACs are documented in the Tile
2942 * Processor I/O Device Guide (UG104). MAC registers start at address
2943 * 0x4000, and do not include the MAC_INTERFACE registers. */
2944#define NETIO_MAC 1
2945
2946/** MDIO register class (IEEE 802.3 clause 22 format). Addr is the "addr"
2947 * member of a netio_mdio_addr_t structure. */
2948#define NETIO_MDIO 2
2949
2950/** MDIO register class (IEEE 802.3 clause 45 format). Addr is the "addr"
2951 * member of a netio_mdio_addr_t structure. */
2952#define NETIO_MDIO_CLAUSE45 3
2953
2954/** NetIO MDIO address type. Retrieved or provided using the ::NETIO_MDIO
2955 * address passed to @ref netio_get() or @ref netio_set(). */
2956typedef union
2957{
2958 struct
2959 {
2960 unsigned int reg:16; /**< MDIO register offset. For clause 22 access,
2961 must be less than 32. */
2962 unsigned int phy:5; /**< Which MDIO PHY to access. */
2963 unsigned int dev:5; /**< Which MDIO device to access within that PHY.
2964 Applicable for clause 45 access only; ignored
2965 for clause 22 access. */
2966 }
2967 bits; /**< Container for bitfields. */
2968 uint64_t addr; /**< Value to pass to @ref netio_get() or
2969 * @ref netio_set(). */
2970}
2971netio_mdio_addr_t;
2972
2973/** @} */
2974
2975#endif /* __NETIO_INTF_H__ */
diff --git a/arch/tile/include/hv/syscall_public.h b/arch/tile/include/hv/syscall_public.h
deleted file mode 100644
index 9cc0837e69fd..000000000000
--- a/arch/tile/include/hv/syscall_public.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/**
16 * @file syscall.h
17 * Indices for the hypervisor system calls that are intended to be called
18 * directly, rather than only through hypervisor-generated "glue" code.
19 */
20
21#ifndef _SYS_HV_INCLUDE_SYSCALL_PUBLIC_H
22#define _SYS_HV_INCLUDE_SYSCALL_PUBLIC_H
23
24/** Fast syscall flag bit location. When this bit is set, the hypervisor
25 * handles the syscall specially.
26 */
27#define HV_SYS_FAST_SHIFT 14
28
29/** Fast syscall flag bit mask. */
30#define HV_SYS_FAST_MASK (1 << HV_SYS_FAST_SHIFT)
31
32/** Bit location for flagging fast syscalls that can be called from PL0. */
33#define HV_SYS_FAST_PLO_SHIFT 13
34
35/** Fast syscall allowing PL0 bit mask. */
36#define HV_SYS_FAST_PL0_MASK (1 << HV_SYS_FAST_PLO_SHIFT)
37
38/** Perform an MF that waits for all victims to reach DRAM. */
39#define HV_SYS_fence_incoherent (51 | HV_SYS_FAST_MASK \
40 | HV_SYS_FAST_PL0_MASK)
41
42#endif /* !_SYS_HV_INCLUDE_SYSCALL_PUBLIC_H */
diff --git a/arch/tile/include/uapi/arch/abi.h b/arch/tile/include/uapi/arch/abi.h
deleted file mode 100644
index df161a484730..000000000000
--- a/arch/tile/include/uapi/arch/abi.h
+++ /dev/null
@@ -1,101 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16/**
17 * @file
18 *
19 * ABI-related register definitions.
20 */
21
22#ifndef __ARCH_ABI_H__
23
24#ifndef __tile__ /* support uncommon use of arch headers in non-tile builds */
25# include <arch/chip.h>
26# define __INT_REG_BITS CHIP_WORD_SIZE()
27#endif
28
29#include <arch/intreg.h>
30
31/* __need_int_reg_t is deprecated: just include <arch/intreg.h> */
32#ifndef __need_int_reg_t
33
34#define __ARCH_ABI_H__
35
36#ifndef __ASSEMBLER__
37/** Unsigned type that can hold a register. */
38typedef __uint_reg_t uint_reg_t;
39
40/** Signed type that can hold a register. */
41typedef __int_reg_t int_reg_t;
42#endif
43
44/** String prefix to use for printf(). */
45#define INT_REG_FMT __INT_REG_FMT
46
47/** Number of bits in a register. */
48#define INT_REG_BITS __INT_REG_BITS
49
50
51/* Registers 0 - 55 are "normal", but some perform special roles. */
52
53#define TREG_FP 52 /**< Frame pointer. */
54#define TREG_TP 53 /**< Thread pointer. */
55#define TREG_SP 54 /**< Stack pointer. */
56#define TREG_LR 55 /**< Link to calling function PC. */
57
58/** Index of last normal general-purpose register. */
59#define TREG_LAST_GPR 55
60
61/* Registers 56 - 62 are "special" network registers. */
62
63#define TREG_SN 56 /**< Static network access. */
64#define TREG_IDN0 57 /**< IDN demux 0 access. */
65#define TREG_IDN1 58 /**< IDN demux 1 access. */
66#define TREG_UDN0 59 /**< UDN demux 0 access. */
67#define TREG_UDN1 60 /**< UDN demux 1 access. */
68#define TREG_UDN2 61 /**< UDN demux 2 access. */
69#define TREG_UDN3 62 /**< UDN demux 3 access. */
70
71/* Register 63 is the "special" zero register. */
72
73#define TREG_ZERO 63 /**< "Zero" register; always reads as "0". */
74
75
76/** By convention, this register is used to hold the syscall number. */
77#define TREG_SYSCALL_NR 10
78
79/** Name of register that holds the syscall number, for use in assembly. */
80#define TREG_SYSCALL_NR_NAME r10
81
82
83/**
84 * The ABI requires callers to allocate a caller state save area of
85 * this many bytes at the bottom of each stack frame.
86 */
87#define C_ABI_SAVE_AREA_SIZE (2 * (INT_REG_BITS / 8))
88
89/**
90 * The operand to an 'info' opcode directing the backtracer to not
91 * try to find the calling frame.
92 */
93#define INFO_OP_CANNOT_BACKTRACE 2
94
95
96#endif /* !__need_int_reg_t */
97
98/* Make sure we later can get all the definitions and declarations. */
99#undef __need_int_reg_t
100
101#endif /* !__ARCH_ABI_H__ */
diff --git a/arch/tile/include/uapi/arch/chip.h b/arch/tile/include/uapi/arch/chip.h
deleted file mode 100644
index 7f55c6856c89..000000000000
--- a/arch/tile/include/uapi/arch/chip.h
+++ /dev/null
@@ -1,22 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#if __tile_chip__ == 1
17#include <arch/chip_tilepro.h>
18#elif defined(__tilegx__)
19#include <arch/chip_tilegx.h>
20#else
21#error Unexpected Tilera chip type
22#endif
diff --git a/arch/tile/include/uapi/arch/chip_tilegx.h b/arch/tile/include/uapi/arch/chip_tilegx.h
deleted file mode 100644
index c2a71a43b21c..000000000000
--- a/arch/tile/include/uapi/arch/chip_tilegx.h
+++ /dev/null
@@ -1,259 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16/*
17 * @file
18 * Global header file.
19 * This header file specifies defines for TILE-Gx.
20 */
21
22#ifndef __ARCH_CHIP_H__
23#define __ARCH_CHIP_H__
24
25/** Specify chip version.
26 * When possible, prefer the CHIP_xxx symbols below for future-proofing.
27 * This is intended for cross-compiling; native compilation should
28 * use the predefined __tile_chip__ symbol.
29 */
30#define TILE_CHIP 10
31
32/** Specify chip revision.
33 * This provides for the case of a respin of a particular chip type;
34 * the normal value for this symbol is "0".
35 * This is intended for cross-compiling; native compilation should
36 * use the predefined __tile_chip_rev__ symbol.
37 */
38#define TILE_CHIP_REV 0
39
40/** The name of this architecture. */
41#define CHIP_ARCH_NAME "tilegx"
42
43/** The ELF e_machine type for binaries for this chip. */
44#define CHIP_ELF_TYPE() EM_TILEGX
45
46/** The alternate ELF e_machine type for binaries for this chip. */
47#define CHIP_COMPAT_ELF_TYPE() 0x2597
48
49/** What is the native word size of the machine? */
50#define CHIP_WORD_SIZE() 64
51
52/** How many bits of a virtual address are used. Extra bits must be
53 * the sign extension of the low bits.
54 */
55#define CHIP_VA_WIDTH() 42
56
57/** How many bits are in a physical address? */
58#define CHIP_PA_WIDTH() 40
59
60/** Size of the L2 cache, in bytes. */
61#define CHIP_L2_CACHE_SIZE() 262144
62
63/** Log size of an L2 cache line in bytes. */
64#define CHIP_L2_LOG_LINE_SIZE() 6
65
66/** Size of an L2 cache line, in bytes. */
67#define CHIP_L2_LINE_SIZE() (1 << CHIP_L2_LOG_LINE_SIZE())
68
69/** Associativity of the L2 cache. */
70#define CHIP_L2_ASSOC() 8
71
72/** Size of the L1 data cache, in bytes. */
73#define CHIP_L1D_CACHE_SIZE() 32768
74
75/** Log size of an L1 data cache line in bytes. */
76#define CHIP_L1D_LOG_LINE_SIZE() 6
77
78/** Size of an L1 data cache line, in bytes. */
79#define CHIP_L1D_LINE_SIZE() (1 << CHIP_L1D_LOG_LINE_SIZE())
80
81/** Associativity of the L1 data cache. */
82#define CHIP_L1D_ASSOC() 2
83
84/** Size of the L1 instruction cache, in bytes. */
85#define CHIP_L1I_CACHE_SIZE() 32768
86
87/** Log size of an L1 instruction cache line in bytes. */
88#define CHIP_L1I_LOG_LINE_SIZE() 6
89
90/** Size of an L1 instruction cache line, in bytes. */
91#define CHIP_L1I_LINE_SIZE() (1 << CHIP_L1I_LOG_LINE_SIZE())
92
93/** Associativity of the L1 instruction cache. */
94#define CHIP_L1I_ASSOC() 2
95
96/** Stride with which flush instructions must be issued. */
97#define CHIP_FLUSH_STRIDE() CHIP_L2_LINE_SIZE()
98
99/** Stride with which inv instructions must be issued. */
100#define CHIP_INV_STRIDE() CHIP_L2_LINE_SIZE()
101
102/** Stride with which finv instructions must be issued. */
103#define CHIP_FINV_STRIDE() CHIP_L2_LINE_SIZE()
104
105/** Can the local cache coherently cache data that is homed elsewhere? */
106#define CHIP_HAS_COHERENT_LOCAL_CACHE() 1
107
108/** How many simultaneous outstanding victims can the L2 cache have? */
109#define CHIP_MAX_OUTSTANDING_VICTIMS() 128
110
111/** Does the TLB support the NC and NOALLOC bits? */
112#define CHIP_HAS_NC_AND_NOALLOC_BITS() 1
113
114/** Does the chip support hash-for-home caching? */
115#define CHIP_HAS_CBOX_HOME_MAP() 1
116
117/** Number of entries in the chip's home map tables. */
118#define CHIP_CBOX_HOME_MAP_SIZE() 128
119
120/** Do uncacheable requests miss in the cache regardless of whether
121 * there is matching data? */
122#define CHIP_HAS_ENFORCED_UNCACHEABLE_REQUESTS() 1
123
124/** Does the mf instruction wait for victims? */
125#define CHIP_HAS_MF_WAITS_FOR_VICTIMS() 0
126
127/** Does the chip have an "inv" instruction that doesn't also flush? */
128#define CHIP_HAS_INV() 1
129
130/** Does the chip have a "wh64" instruction? */
131#define CHIP_HAS_WH64() 1
132
133/** Does this chip have a 'dword_align' instruction? */
134#define CHIP_HAS_DWORD_ALIGN() 0
135
136/** Number of performance counters. */
137#define CHIP_PERFORMANCE_COUNTERS() 4
138
139/** Does this chip have auxiliary performance counters? */
140#define CHIP_HAS_AUX_PERF_COUNTERS() 1
141
142/** Is the CBOX_MSR1 SPR supported? */
143#define CHIP_HAS_CBOX_MSR1() 0
144
145/** Is the TILE_RTF_HWM SPR supported? */
146#define CHIP_HAS_TILE_RTF_HWM() 1
147
148/** Is the TILE_WRITE_PENDING SPR supported? */
149#define CHIP_HAS_TILE_WRITE_PENDING() 0
150
151/** Is the PROC_STATUS SPR supported? */
152#define CHIP_HAS_PROC_STATUS_SPR() 1
153
154/** Is the DSTREAM_PF SPR supported? */
155#define CHIP_HAS_DSTREAM_PF() 1
156
157/** Log of the number of mshims we have. */
158#define CHIP_LOG_NUM_MSHIMS() 2
159
160/** Are the bases of the interrupt vector areas fixed? */
161#define CHIP_HAS_FIXED_INTVEC_BASE() 0
162
163/** Are the interrupt masks split up into 2 SPRs? */
164#define CHIP_HAS_SPLIT_INTR_MASK() 0
165
166/** Is the cycle count split up into 2 SPRs? */
167#define CHIP_HAS_SPLIT_CYCLE() 0
168
169/** Does the chip have a static network? */
170#define CHIP_HAS_SN() 0
171
172/** Does the chip have a static network processor? */
173#define CHIP_HAS_SN_PROC() 0
174
175/** Size of the L1 static network processor instruction cache, in bytes. */
176/* #define CHIP_L1SNI_CACHE_SIZE() -- does not apply to chip 10 */
177
178/** Does the chip have DMA support in each tile? */
179#define CHIP_HAS_TILE_DMA() 0
180
181/** Does the chip have the second revision of the directly accessible
182 * dynamic networks? This encapsulates a number of characteristics,
183 * including the absence of the catch-all, the absence of inline message
184 * tags, the absence of support for network context-switching, and so on.
185 */
186#define CHIP_HAS_REV1_XDN() 1
187
188/** Does the chip have cmpexch and similar (fetchadd, exch, etc.)? */
189#define CHIP_HAS_CMPEXCH() 1
190
191/** Does the chip have memory-mapped I/O support? */
192#define CHIP_HAS_MMIO() 1
193
194/** Does the chip have post-completion interrupts? */
195#define CHIP_HAS_POST_COMPLETION_INTERRUPTS() 1
196
197/** Does the chip have native single step support? */
198#define CHIP_HAS_SINGLE_STEP() 1
199
200#ifndef __OPEN_SOURCE__ /* features only relevant to hypervisor-level code */
201
202/** How many entries are present in the instruction TLB? */
203#define CHIP_ITLB_ENTRIES() 16
204
205/** How many entries are present in the data TLB? */
206#define CHIP_DTLB_ENTRIES() 32
207
208/** How many MAF entries does the XAUI shim have? */
209#define CHIP_XAUI_MAF_ENTRIES() 32
210
211/** Does the memory shim have a source-id table? */
212#define CHIP_HAS_MSHIM_SRCID_TABLE() 0
213
214/** Does the L1 instruction cache clear on reset? */
215#define CHIP_HAS_L1I_CLEAR_ON_RESET() 1
216
217/** Does the chip come out of reset with valid coordinates on all tiles?
218 * Note that if defined, this also implies that the upper left is 1,1.
219 */
220#define CHIP_HAS_VALID_TILE_COORD_RESET() 1
221
222/** Does the chip have unified packet formats? */
223#define CHIP_HAS_UNIFIED_PACKET_FORMATS() 1
224
225/** Does the chip support write reordering? */
226#define CHIP_HAS_WRITE_REORDERING() 1
227
228/** Does the chip support Y-X routing as well as X-Y? */
229#define CHIP_HAS_Y_X_ROUTING() 1
230
231/** Is INTCTRL_3 managed with the correct MPL? */
232#define CHIP_HAS_INTCTRL_3_STATUS_FIX() 1
233
234/** Is it possible to configure the chip to be big-endian? */
235#define CHIP_HAS_BIG_ENDIAN_CONFIG() 1
236
237/** Is the CACHE_RED_WAY_OVERRIDDEN SPR supported? */
238#define CHIP_HAS_CACHE_RED_WAY_OVERRIDDEN() 0
239
240/** Is the DIAG_TRACE_WAY SPR supported? */
241#define CHIP_HAS_DIAG_TRACE_WAY() 0
242
243/** Is the MEM_STRIPE_CONFIG SPR supported? */
244#define CHIP_HAS_MEM_STRIPE_CONFIG() 1
245
246/** Are the TLB_PERF SPRs supported? */
247#define CHIP_HAS_TLB_PERF() 1
248
249/** Is the VDN_SNOOP_SHIM_CTL SPR supported? */
250#define CHIP_HAS_VDN_SNOOP_SHIM_CTL() 0
251
252/** Does the chip support rev1 DMA packets? */
253#define CHIP_HAS_REV1_DMA_PACKETS() 1
254
255/** Does the chip have an IPI shim? */
256#define CHIP_HAS_IPI() 1
257
258#endif /* !__OPEN_SOURCE__ */
259#endif /* __ARCH_CHIP_H__ */
diff --git a/arch/tile/include/uapi/arch/chip_tilepro.h b/arch/tile/include/uapi/arch/chip_tilepro.h
deleted file mode 100644
index a8a3ed144dfe..000000000000
--- a/arch/tile/include/uapi/arch/chip_tilepro.h
+++ /dev/null
@@ -1,259 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16/*
17 * @file
18 * Global header file.
19 * This header file specifies defines for TILEPro.
20 */
21
22#ifndef __ARCH_CHIP_H__
23#define __ARCH_CHIP_H__
24
25/** Specify chip version.
26 * When possible, prefer the CHIP_xxx symbols below for future-proofing.
27 * This is intended for cross-compiling; native compilation should
28 * use the predefined __tile_chip__ symbol.
29 */
30#define TILE_CHIP 1
31
32/** Specify chip revision.
33 * This provides for the case of a respin of a particular chip type;
34 * the normal value for this symbol is "0".
35 * This is intended for cross-compiling; native compilation should
36 * use the predefined __tile_chip_rev__ symbol.
37 */
38#define TILE_CHIP_REV 0
39
40/** The name of this architecture. */
41#define CHIP_ARCH_NAME "tilepro"
42
43/** The ELF e_machine type for binaries for this chip. */
44#define CHIP_ELF_TYPE() EM_TILEPRO
45
46/** The alternate ELF e_machine type for binaries for this chip. */
47#define CHIP_COMPAT_ELF_TYPE() 0x2507
48
49/** What is the native word size of the machine? */
50#define CHIP_WORD_SIZE() 32
51
52/** How many bits of a virtual address are used. Extra bits must be
53 * the sign extension of the low bits.
54 */
55#define CHIP_VA_WIDTH() 32
56
57/** How many bits are in a physical address? */
58#define CHIP_PA_WIDTH() 36
59
60/** Size of the L2 cache, in bytes. */
61#define CHIP_L2_CACHE_SIZE() 65536
62
63/** Log size of an L2 cache line in bytes. */
64#define CHIP_L2_LOG_LINE_SIZE() 6
65
66/** Size of an L2 cache line, in bytes. */
67#define CHIP_L2_LINE_SIZE() (1 << CHIP_L2_LOG_LINE_SIZE())
68
69/** Associativity of the L2 cache. */
70#define CHIP_L2_ASSOC() 4
71
72/** Size of the L1 data cache, in bytes. */
73#define CHIP_L1D_CACHE_SIZE() 8192
74
75/** Log size of an L1 data cache line in bytes. */
76#define CHIP_L1D_LOG_LINE_SIZE() 4
77
78/** Size of an L1 data cache line, in bytes. */
79#define CHIP_L1D_LINE_SIZE() (1 << CHIP_L1D_LOG_LINE_SIZE())
80
81/** Associativity of the L1 data cache. */
82#define CHIP_L1D_ASSOC() 2
83
84/** Size of the L1 instruction cache, in bytes. */
85#define CHIP_L1I_CACHE_SIZE() 16384
86
87/** Log size of an L1 instruction cache line in bytes. */
88#define CHIP_L1I_LOG_LINE_SIZE() 6
89
90/** Size of an L1 instruction cache line, in bytes. */
91#define CHIP_L1I_LINE_SIZE() (1 << CHIP_L1I_LOG_LINE_SIZE())
92
93/** Associativity of the L1 instruction cache. */
94#define CHIP_L1I_ASSOC() 1
95
96/** Stride with which flush instructions must be issued. */
97#define CHIP_FLUSH_STRIDE() CHIP_L2_LINE_SIZE()
98
99/** Stride with which inv instructions must be issued. */
100#define CHIP_INV_STRIDE() CHIP_L2_LINE_SIZE()
101
102/** Stride with which finv instructions must be issued. */
103#define CHIP_FINV_STRIDE() CHIP_L2_LINE_SIZE()
104
105/** Can the local cache coherently cache data that is homed elsewhere? */
106#define CHIP_HAS_COHERENT_LOCAL_CACHE() 1
107
108/** How many simultaneous outstanding victims can the L2 cache have? */
109#define CHIP_MAX_OUTSTANDING_VICTIMS() 4
110
111/** Does the TLB support the NC and NOALLOC bits? */
112#define CHIP_HAS_NC_AND_NOALLOC_BITS() 1
113
114/** Does the chip support hash-for-home caching? */
115#define CHIP_HAS_CBOX_HOME_MAP() 1
116
117/** Number of entries in the chip's home map tables. */
118#define CHIP_CBOX_HOME_MAP_SIZE() 64
119
120/** Do uncacheable requests miss in the cache regardless of whether
121 * there is matching data? */
122#define CHIP_HAS_ENFORCED_UNCACHEABLE_REQUESTS() 1
123
124/** Does the mf instruction wait for victims? */
125#define CHIP_HAS_MF_WAITS_FOR_VICTIMS() 0
126
127/** Does the chip have an "inv" instruction that doesn't also flush? */
128#define CHIP_HAS_INV() 1
129
130/** Does the chip have a "wh64" instruction? */
131#define CHIP_HAS_WH64() 1
132
133/** Does this chip have a 'dword_align' instruction? */
134#define CHIP_HAS_DWORD_ALIGN() 1
135
136/** Number of performance counters. */
137#define CHIP_PERFORMANCE_COUNTERS() 4
138
139/** Does this chip have auxiliary performance counters? */
140#define CHIP_HAS_AUX_PERF_COUNTERS() 1
141
142/** Is the CBOX_MSR1 SPR supported? */
143#define CHIP_HAS_CBOX_MSR1() 1
144
145/** Is the TILE_RTF_HWM SPR supported? */
146#define CHIP_HAS_TILE_RTF_HWM() 1
147
148/** Is the TILE_WRITE_PENDING SPR supported? */
149#define CHIP_HAS_TILE_WRITE_PENDING() 1
150
151/** Is the PROC_STATUS SPR supported? */
152#define CHIP_HAS_PROC_STATUS_SPR() 1
153
154/** Is the DSTREAM_PF SPR supported? */
155#define CHIP_HAS_DSTREAM_PF() 0
156
157/** Log of the number of mshims we have. */
158#define CHIP_LOG_NUM_MSHIMS() 2
159
160/** Are the bases of the interrupt vector areas fixed? */
161#define CHIP_HAS_FIXED_INTVEC_BASE() 1
162
163/** Are the interrupt masks split up into 2 SPRs? */
164#define CHIP_HAS_SPLIT_INTR_MASK() 1
165
166/** Is the cycle count split up into 2 SPRs? */
167#define CHIP_HAS_SPLIT_CYCLE() 1
168
169/** Does the chip have a static network? */
170#define CHIP_HAS_SN() 1
171
172/** Does the chip have a static network processor? */
173#define CHIP_HAS_SN_PROC() 0
174
175/** Size of the L1 static network processor instruction cache, in bytes. */
176/* #define CHIP_L1SNI_CACHE_SIZE() -- does not apply to chip 1 */
177
178/** Does the chip have DMA support in each tile? */
179#define CHIP_HAS_TILE_DMA() 1
180
181/** Does the chip have the second revision of the directly accessible
182 * dynamic networks? This encapsulates a number of characteristics,
183 * including the absence of the catch-all, the absence of inline message
184 * tags, the absence of support for network context-switching, and so on.
185 */
186#define CHIP_HAS_REV1_XDN() 0
187
188/** Does the chip have cmpexch and similar (fetchadd, exch, etc.)? */
189#define CHIP_HAS_CMPEXCH() 0
190
191/** Does the chip have memory-mapped I/O support? */
192#define CHIP_HAS_MMIO() 0
193
194/** Does the chip have post-completion interrupts? */
195#define CHIP_HAS_POST_COMPLETION_INTERRUPTS() 0
196
197/** Does the chip have native single step support? */
198#define CHIP_HAS_SINGLE_STEP() 0
199
200#ifndef __OPEN_SOURCE__ /* features only relevant to hypervisor-level code */
201
202/** How many entries are present in the instruction TLB? */
203#define CHIP_ITLB_ENTRIES() 16
204
205/** How many entries are present in the data TLB? */
206#define CHIP_DTLB_ENTRIES() 16
207
208/** How many MAF entries does the XAUI shim have? */
209#define CHIP_XAUI_MAF_ENTRIES() 32
210
211/** Does the memory shim have a source-id table? */
212#define CHIP_HAS_MSHIM_SRCID_TABLE() 0
213
214/** Does the L1 instruction cache clear on reset? */
215#define CHIP_HAS_L1I_CLEAR_ON_RESET() 1
216
217/** Does the chip come out of reset with valid coordinates on all tiles?
218 * Note that if defined, this also implies that the upper left is 1,1.
219 */
220#define CHIP_HAS_VALID_TILE_COORD_RESET() 1
221
222/** Does the chip have unified packet formats? */
223#define CHIP_HAS_UNIFIED_PACKET_FORMATS() 1
224
225/** Does the chip support write reordering? */
226#define CHIP_HAS_WRITE_REORDERING() 1
227
228/** Does the chip support Y-X routing as well as X-Y? */
229#define CHIP_HAS_Y_X_ROUTING() 1
230
231/** Is INTCTRL_3 managed with the correct MPL? */
232#define CHIP_HAS_INTCTRL_3_STATUS_FIX() 1
233
234/** Is it possible to configure the chip to be big-endian? */
235#define CHIP_HAS_BIG_ENDIAN_CONFIG() 1
236
237/** Is the CACHE_RED_WAY_OVERRIDDEN SPR supported? */
238#define CHIP_HAS_CACHE_RED_WAY_OVERRIDDEN() 1
239
240/** Is the DIAG_TRACE_WAY SPR supported? */
241#define CHIP_HAS_DIAG_TRACE_WAY() 1
242
243/** Is the MEM_STRIPE_CONFIG SPR supported? */
244#define CHIP_HAS_MEM_STRIPE_CONFIG() 1
245
246/** Are the TLB_PERF SPRs supported? */
247#define CHIP_HAS_TLB_PERF() 1
248
249/** Is the VDN_SNOOP_SHIM_CTL SPR supported? */
250#define CHIP_HAS_VDN_SNOOP_SHIM_CTL() 1
251
252/** Does the chip support rev1 DMA packets? */
253#define CHIP_HAS_REV1_DMA_PACKETS() 1
254
255/** Does the chip have an IPI shim? */
256#define CHIP_HAS_IPI() 0
257
258#endif /* !__OPEN_SOURCE__ */
259#endif /* __ARCH_CHIP_H__ */
diff --git a/arch/tile/include/uapi/arch/icache.h b/arch/tile/include/uapi/arch/icache.h
deleted file mode 100644
index ff85a5d77f16..000000000000
--- a/arch/tile/include/uapi/arch/icache.h
+++ /dev/null
@@ -1,94 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 *
15 */
16
17/**
18 * @file
19 *
20 * Support for invalidating bytes in the instruction cache.
21 */
22
23#ifndef __ARCH_ICACHE_H__
24#define __ARCH_ICACHE_H__
25
26#include <arch/chip.h>
27
28
29/**
30 * Invalidate the instruction cache for the given range of memory.
31 *
32 * @param addr The start of memory to be invalidated.
33 * @param size The number of bytes to be invalidated.
34 * @param page_size The system's page size, e.g. getpagesize() in userspace.
35 * This value must be a power of two no larger than the page containing
36 * the code to be invalidated. If the value is smaller than the actual page
37 * size, this function will still work, but may run slower than necessary.
38 */
39static __inline void
40invalidate_icache(const void* addr, unsigned long size,
41 unsigned long page_size)
42{
43 const unsigned long cache_way_size =
44 CHIP_L1I_CACHE_SIZE() / CHIP_L1I_ASSOC();
45 unsigned long max_useful_size;
46 const char* start, *end;
47 long num_passes;
48
49 if (__builtin_expect(size == 0, 0))
50 return;
51
52#ifdef __tilegx__
53 /* Limit the number of bytes visited to avoid redundant iterations. */
54 max_useful_size = (page_size < cache_way_size) ? page_size : cache_way_size;
55
56 /* No PA aliasing is possible, so one pass always suffices. */
57 num_passes = 1;
58#else
59 /* Limit the number of bytes visited to avoid redundant iterations. */
60 max_useful_size = cache_way_size;
61
62 /*
63 * Compute how many passes we need (we'll treat 0 as if it were 1).
64 * This works because we know the page size is a power of two.
65 */
66 num_passes = cache_way_size >> __builtin_ctzl(page_size);
67#endif
68
69 if (__builtin_expect(size > max_useful_size, 0))
70 size = max_useful_size;
71
72 /* Locate the first and last bytes to be invalidated. */
73 start = (const char *)((unsigned long)addr & -CHIP_L1I_LINE_SIZE());
74 end = (const char*)addr + size - 1;
75
76 __insn_mf();
77
78 do
79 {
80 const char* p;
81
82 for (p = start; p <= end; p += CHIP_L1I_LINE_SIZE())
83 __insn_icoh(p);
84
85 start += page_size;
86 end += page_size;
87 }
88 while (--num_passes > 0);
89
90 __insn_drain();
91}
92
93
94#endif /* __ARCH_ICACHE_H__ */
diff --git a/arch/tile/include/uapi/arch/interrupts.h b/arch/tile/include/uapi/arch/interrupts.h
deleted file mode 100644
index c288b5d82b4d..000000000000
--- a/arch/tile/include/uapi/arch/interrupts.h
+++ /dev/null
@@ -1,20 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifdef __tilegx__
17#include <arch/interrupts_64.h>
18#else
19#include <arch/interrupts_32.h>
20#endif
diff --git a/arch/tile/include/uapi/arch/interrupts_32.h b/arch/tile/include/uapi/arch/interrupts_32.h
deleted file mode 100644
index a748752cec16..000000000000
--- a/arch/tile/include/uapi/arch/interrupts_32.h
+++ /dev/null
@@ -1,310 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef __ARCH_INTERRUPTS_H__
17#define __ARCH_INTERRUPTS_H__
18
19#ifndef __KERNEL__
20/** Mask for an interrupt. */
21/* Note: must handle breaking interrupts into high and low words manually. */
22#define INT_MASK_LO(intno) (1 << (intno))
23#define INT_MASK_HI(intno) (1 << ((intno) - 32))
24
25#ifndef __ASSEMBLER__
26#define INT_MASK(intno) (1ULL << (intno))
27#endif
28#endif
29
30
31/** Where a given interrupt executes */
32#define INTERRUPT_VECTOR(i, pl) (0xFC000000 + ((pl) << 24) + ((i) << 8))
33
34/** Where to store a vector for a given interrupt. */
35#define USER_INTERRUPT_VECTOR(i) INTERRUPT_VECTOR(i, 0)
36
37/** The base address of user-level interrupts. */
38#define USER_INTERRUPT_VECTOR_BASE INTERRUPT_VECTOR(0, 0)
39
40
41/** Additional synthetic interrupt. */
42#define INT_BREAKPOINT (63)
43
44#define INT_ITLB_MISS 0
45#define INT_MEM_ERROR 1
46#define INT_ILL 2
47#define INT_GPV 3
48#define INT_SN_ACCESS 4
49#define INT_IDN_ACCESS 5
50#define INT_UDN_ACCESS 6
51#define INT_IDN_REFILL 7
52#define INT_UDN_REFILL 8
53#define INT_IDN_COMPLETE 9
54#define INT_UDN_COMPLETE 10
55#define INT_SWINT_3 11
56#define INT_SWINT_2 12
57#define INT_SWINT_1 13
58#define INT_SWINT_0 14
59#define INT_UNALIGN_DATA 15
60#define INT_DTLB_MISS 16
61#define INT_DTLB_ACCESS 17
62#define INT_DMATLB_MISS 18
63#define INT_DMATLB_ACCESS 19
64#define INT_SNITLB_MISS 20
65#define INT_SN_NOTIFY 21
66#define INT_SN_FIREWALL 22
67#define INT_IDN_FIREWALL 23
68#define INT_UDN_FIREWALL 24
69#define INT_TILE_TIMER 25
70#define INT_IDN_TIMER 26
71#define INT_UDN_TIMER 27
72#define INT_DMA_NOTIFY 28
73#define INT_IDN_CA 29
74#define INT_UDN_CA 30
75#define INT_IDN_AVAIL 31
76#define INT_UDN_AVAIL 32
77#define INT_PERF_COUNT 33
78#define INT_INTCTRL_3 34
79#define INT_INTCTRL_2 35
80#define INT_INTCTRL_1 36
81#define INT_INTCTRL_0 37
82#define INT_BOOT_ACCESS 38
83#define INT_WORLD_ACCESS 39
84#define INT_I_ASID 40
85#define INT_D_ASID 41
86#define INT_DMA_ASID 42
87#define INT_SNI_ASID 43
88#define INT_DMA_CPL 44
89#define INT_SN_CPL 45
90#define INT_DOUBLE_FAULT 46
91#define INT_SN_STATIC_ACCESS 47
92#define INT_AUX_PERF_COUNT 48
93
94#define NUM_INTERRUPTS 49
95
96#ifndef __ASSEMBLER__
97#define QUEUED_INTERRUPTS ( \
98 (1ULL << INT_MEM_ERROR) | \
99 (1ULL << INT_DMATLB_MISS) | \
100 (1ULL << INT_DMATLB_ACCESS) | \
101 (1ULL << INT_SNITLB_MISS) | \
102 (1ULL << INT_SN_NOTIFY) | \
103 (1ULL << INT_SN_FIREWALL) | \
104 (1ULL << INT_IDN_FIREWALL) | \
105 (1ULL << INT_UDN_FIREWALL) | \
106 (1ULL << INT_TILE_TIMER) | \
107 (1ULL << INT_IDN_TIMER) | \
108 (1ULL << INT_UDN_TIMER) | \
109 (1ULL << INT_DMA_NOTIFY) | \
110 (1ULL << INT_IDN_CA) | \
111 (1ULL << INT_UDN_CA) | \
112 (1ULL << INT_IDN_AVAIL) | \
113 (1ULL << INT_UDN_AVAIL) | \
114 (1ULL << INT_PERF_COUNT) | \
115 (1ULL << INT_INTCTRL_3) | \
116 (1ULL << INT_INTCTRL_2) | \
117 (1ULL << INT_INTCTRL_1) | \
118 (1ULL << INT_INTCTRL_0) | \
119 (1ULL << INT_BOOT_ACCESS) | \
120 (1ULL << INT_WORLD_ACCESS) | \
121 (1ULL << INT_I_ASID) | \
122 (1ULL << INT_D_ASID) | \
123 (1ULL << INT_DMA_ASID) | \
124 (1ULL << INT_SNI_ASID) | \
125 (1ULL << INT_DMA_CPL) | \
126 (1ULL << INT_SN_CPL) | \
127 (1ULL << INT_DOUBLE_FAULT) | \
128 (1ULL << INT_AUX_PERF_COUNT) | \
129 0)
130#define NONQUEUED_INTERRUPTS ( \
131 (1ULL << INT_ITLB_MISS) | \
132 (1ULL << INT_ILL) | \
133 (1ULL << INT_GPV) | \
134 (1ULL << INT_SN_ACCESS) | \
135 (1ULL << INT_IDN_ACCESS) | \
136 (1ULL << INT_UDN_ACCESS) | \
137 (1ULL << INT_IDN_REFILL) | \
138 (1ULL << INT_UDN_REFILL) | \
139 (1ULL << INT_IDN_COMPLETE) | \
140 (1ULL << INT_UDN_COMPLETE) | \
141 (1ULL << INT_SWINT_3) | \
142 (1ULL << INT_SWINT_2) | \
143 (1ULL << INT_SWINT_1) | \
144 (1ULL << INT_SWINT_0) | \
145 (1ULL << INT_UNALIGN_DATA) | \
146 (1ULL << INT_DTLB_MISS) | \
147 (1ULL << INT_DTLB_ACCESS) | \
148 (1ULL << INT_SN_STATIC_ACCESS) | \
149 0)
150#define CRITICAL_MASKED_INTERRUPTS ( \
151 (1ULL << INT_MEM_ERROR) | \
152 (1ULL << INT_DMATLB_MISS) | \
153 (1ULL << INT_DMATLB_ACCESS) | \
154 (1ULL << INT_SNITLB_MISS) | \
155 (1ULL << INT_SN_NOTIFY) | \
156 (1ULL << INT_SN_FIREWALL) | \
157 (1ULL << INT_IDN_FIREWALL) | \
158 (1ULL << INT_UDN_FIREWALL) | \
159 (1ULL << INT_TILE_TIMER) | \
160 (1ULL << INT_IDN_TIMER) | \
161 (1ULL << INT_UDN_TIMER) | \
162 (1ULL << INT_DMA_NOTIFY) | \
163 (1ULL << INT_IDN_CA) | \
164 (1ULL << INT_UDN_CA) | \
165 (1ULL << INT_IDN_AVAIL) | \
166 (1ULL << INT_UDN_AVAIL) | \
167 (1ULL << INT_PERF_COUNT) | \
168 (1ULL << INT_INTCTRL_3) | \
169 (1ULL << INT_INTCTRL_2) | \
170 (1ULL << INT_INTCTRL_1) | \
171 (1ULL << INT_INTCTRL_0) | \
172 (1ULL << INT_AUX_PERF_COUNT) | \
173 0)
174#define CRITICAL_UNMASKED_INTERRUPTS ( \
175 (1ULL << INT_ITLB_MISS) | \
176 (1ULL << INT_ILL) | \
177 (1ULL << INT_GPV) | \
178 (1ULL << INT_SN_ACCESS) | \
179 (1ULL << INT_IDN_ACCESS) | \
180 (1ULL << INT_UDN_ACCESS) | \
181 (1ULL << INT_IDN_REFILL) | \
182 (1ULL << INT_UDN_REFILL) | \
183 (1ULL << INT_IDN_COMPLETE) | \
184 (1ULL << INT_UDN_COMPLETE) | \
185 (1ULL << INT_SWINT_3) | \
186 (1ULL << INT_SWINT_2) | \
187 (1ULL << INT_SWINT_1) | \
188 (1ULL << INT_SWINT_0) | \
189 (1ULL << INT_UNALIGN_DATA) | \
190 (1ULL << INT_DTLB_MISS) | \
191 (1ULL << INT_DTLB_ACCESS) | \
192 (1ULL << INT_BOOT_ACCESS) | \
193 (1ULL << INT_WORLD_ACCESS) | \
194 (1ULL << INT_I_ASID) | \
195 (1ULL << INT_D_ASID) | \
196 (1ULL << INT_DMA_ASID) | \
197 (1ULL << INT_SNI_ASID) | \
198 (1ULL << INT_DMA_CPL) | \
199 (1ULL << INT_SN_CPL) | \
200 (1ULL << INT_DOUBLE_FAULT) | \
201 (1ULL << INT_SN_STATIC_ACCESS) | \
202 0)
203#define MASKABLE_INTERRUPTS ( \
204 (1ULL << INT_MEM_ERROR) | \
205 (1ULL << INT_IDN_REFILL) | \
206 (1ULL << INT_UDN_REFILL) | \
207 (1ULL << INT_IDN_COMPLETE) | \
208 (1ULL << INT_UDN_COMPLETE) | \
209 (1ULL << INT_DMATLB_MISS) | \
210 (1ULL << INT_DMATLB_ACCESS) | \
211 (1ULL << INT_SNITLB_MISS) | \
212 (1ULL << INT_SN_NOTIFY) | \
213 (1ULL << INT_SN_FIREWALL) | \
214 (1ULL << INT_IDN_FIREWALL) | \
215 (1ULL << INT_UDN_FIREWALL) | \
216 (1ULL << INT_TILE_TIMER) | \
217 (1ULL << INT_IDN_TIMER) | \
218 (1ULL << INT_UDN_TIMER) | \
219 (1ULL << INT_DMA_NOTIFY) | \
220 (1ULL << INT_IDN_CA) | \
221 (1ULL << INT_UDN_CA) | \
222 (1ULL << INT_IDN_AVAIL) | \
223 (1ULL << INT_UDN_AVAIL) | \
224 (1ULL << INT_PERF_COUNT) | \
225 (1ULL << INT_INTCTRL_3) | \
226 (1ULL << INT_INTCTRL_2) | \
227 (1ULL << INT_INTCTRL_1) | \
228 (1ULL << INT_INTCTRL_0) | \
229 (1ULL << INT_AUX_PERF_COUNT) | \
230 0)
231#define UNMASKABLE_INTERRUPTS ( \
232 (1ULL << INT_ITLB_MISS) | \
233 (1ULL << INT_ILL) | \
234 (1ULL << INT_GPV) | \
235 (1ULL << INT_SN_ACCESS) | \
236 (1ULL << INT_IDN_ACCESS) | \
237 (1ULL << INT_UDN_ACCESS) | \
238 (1ULL << INT_SWINT_3) | \
239 (1ULL << INT_SWINT_2) | \
240 (1ULL << INT_SWINT_1) | \
241 (1ULL << INT_SWINT_0) | \
242 (1ULL << INT_UNALIGN_DATA) | \
243 (1ULL << INT_DTLB_MISS) | \
244 (1ULL << INT_DTLB_ACCESS) | \
245 (1ULL << INT_BOOT_ACCESS) | \
246 (1ULL << INT_WORLD_ACCESS) | \
247 (1ULL << INT_I_ASID) | \
248 (1ULL << INT_D_ASID) | \
249 (1ULL << INT_DMA_ASID) | \
250 (1ULL << INT_SNI_ASID) | \
251 (1ULL << INT_DMA_CPL) | \
252 (1ULL << INT_SN_CPL) | \
253 (1ULL << INT_DOUBLE_FAULT) | \
254 (1ULL << INT_SN_STATIC_ACCESS) | \
255 0)
256#define SYNC_INTERRUPTS ( \
257 (1ULL << INT_ITLB_MISS) | \
258 (1ULL << INT_ILL) | \
259 (1ULL << INT_GPV) | \
260 (1ULL << INT_SN_ACCESS) | \
261 (1ULL << INT_IDN_ACCESS) | \
262 (1ULL << INT_UDN_ACCESS) | \
263 (1ULL << INT_IDN_REFILL) | \
264 (1ULL << INT_UDN_REFILL) | \
265 (1ULL << INT_IDN_COMPLETE) | \
266 (1ULL << INT_UDN_COMPLETE) | \
267 (1ULL << INT_SWINT_3) | \
268 (1ULL << INT_SWINT_2) | \
269 (1ULL << INT_SWINT_1) | \
270 (1ULL << INT_SWINT_0) | \
271 (1ULL << INT_UNALIGN_DATA) | \
272 (1ULL << INT_DTLB_MISS) | \
273 (1ULL << INT_DTLB_ACCESS) | \
274 (1ULL << INT_SN_STATIC_ACCESS) | \
275 0)
276#define NON_SYNC_INTERRUPTS ( \
277 (1ULL << INT_MEM_ERROR) | \
278 (1ULL << INT_DMATLB_MISS) | \
279 (1ULL << INT_DMATLB_ACCESS) | \
280 (1ULL << INT_SNITLB_MISS) | \
281 (1ULL << INT_SN_NOTIFY) | \
282 (1ULL << INT_SN_FIREWALL) | \
283 (1ULL << INT_IDN_FIREWALL) | \
284 (1ULL << INT_UDN_FIREWALL) | \
285 (1ULL << INT_TILE_TIMER) | \
286 (1ULL << INT_IDN_TIMER) | \
287 (1ULL << INT_UDN_TIMER) | \
288 (1ULL << INT_DMA_NOTIFY) | \
289 (1ULL << INT_IDN_CA) | \
290 (1ULL << INT_UDN_CA) | \
291 (1ULL << INT_IDN_AVAIL) | \
292 (1ULL << INT_UDN_AVAIL) | \
293 (1ULL << INT_PERF_COUNT) | \
294 (1ULL << INT_INTCTRL_3) | \
295 (1ULL << INT_INTCTRL_2) | \
296 (1ULL << INT_INTCTRL_1) | \
297 (1ULL << INT_INTCTRL_0) | \
298 (1ULL << INT_BOOT_ACCESS) | \
299 (1ULL << INT_WORLD_ACCESS) | \
300 (1ULL << INT_I_ASID) | \
301 (1ULL << INT_D_ASID) | \
302 (1ULL << INT_DMA_ASID) | \
303 (1ULL << INT_SNI_ASID) | \
304 (1ULL << INT_DMA_CPL) | \
305 (1ULL << INT_SN_CPL) | \
306 (1ULL << INT_DOUBLE_FAULT) | \
307 (1ULL << INT_AUX_PERF_COUNT) | \
308 0)
309#endif /* !__ASSEMBLER__ */
310#endif /* !__ARCH_INTERRUPTS_H__ */
diff --git a/arch/tile/include/uapi/arch/interrupts_64.h b/arch/tile/include/uapi/arch/interrupts_64.h
deleted file mode 100644
index 142eaff3c244..000000000000
--- a/arch/tile/include/uapi/arch/interrupts_64.h
+++ /dev/null
@@ -1,279 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef __ARCH_INTERRUPTS_H__
17#define __ARCH_INTERRUPTS_H__
18
19#ifndef __KERNEL__
20/** Mask for an interrupt. */
21#ifdef __ASSEMBLER__
22/* Note: must handle breaking interrupts into high and low words manually. */
23#define INT_MASK(intno) (1 << (intno))
24#else
25#define INT_MASK(intno) (1ULL << (intno))
26#endif
27#endif
28
29
30/** Where a given interrupt executes */
31#define INTERRUPT_VECTOR(i, pl) (0xFC000000 + ((pl) << 24) + ((i) << 8))
32
33/** Where to store a vector for a given interrupt. */
34#define USER_INTERRUPT_VECTOR(i) INTERRUPT_VECTOR(i, 0)
35
36/** The base address of user-level interrupts. */
37#define USER_INTERRUPT_VECTOR_BASE INTERRUPT_VECTOR(0, 0)
38
39
40/** Additional synthetic interrupt. */
41#define INT_BREAKPOINT (63)
42
43#define INT_MEM_ERROR 0
44#define INT_SINGLE_STEP_3 1
45#define INT_SINGLE_STEP_2 2
46#define INT_SINGLE_STEP_1 3
47#define INT_SINGLE_STEP_0 4
48#define INT_IDN_COMPLETE 5
49#define INT_UDN_COMPLETE 6
50#define INT_ITLB_MISS 7
51#define INT_ILL 8
52#define INT_GPV 9
53#define INT_IDN_ACCESS 10
54#define INT_UDN_ACCESS 11
55#define INT_SWINT_3 12
56#define INT_SWINT_2 13
57#define INT_SWINT_1 14
58#define INT_SWINT_0 15
59#define INT_ILL_TRANS 16
60#define INT_UNALIGN_DATA 17
61#define INT_DTLB_MISS 18
62#define INT_DTLB_ACCESS 19
63#define INT_IDN_FIREWALL 20
64#define INT_UDN_FIREWALL 21
65#define INT_TILE_TIMER 22
66#define INT_AUX_TILE_TIMER 23
67#define INT_IDN_TIMER 24
68#define INT_UDN_TIMER 25
69#define INT_IDN_AVAIL 26
70#define INT_UDN_AVAIL 27
71#define INT_IPI_3 28
72#define INT_IPI_2 29
73#define INT_IPI_1 30
74#define INT_IPI_0 31
75#define INT_PERF_COUNT 32
76#define INT_AUX_PERF_COUNT 33
77#define INT_INTCTRL_3 34
78#define INT_INTCTRL_2 35
79#define INT_INTCTRL_1 36
80#define INT_INTCTRL_0 37
81#define INT_BOOT_ACCESS 38
82#define INT_WORLD_ACCESS 39
83#define INT_I_ASID 40
84#define INT_D_ASID 41
85#define INT_DOUBLE_FAULT 42
86
87#define NUM_INTERRUPTS 43
88
89#ifndef __ASSEMBLER__
90#define QUEUED_INTERRUPTS ( \
91 (1ULL << INT_MEM_ERROR) | \
92 (1ULL << INT_IDN_COMPLETE) | \
93 (1ULL << INT_UDN_COMPLETE) | \
94 (1ULL << INT_IDN_FIREWALL) | \
95 (1ULL << INT_UDN_FIREWALL) | \
96 (1ULL << INT_TILE_TIMER) | \
97 (1ULL << INT_AUX_TILE_TIMER) | \
98 (1ULL << INT_IDN_TIMER) | \
99 (1ULL << INT_UDN_TIMER) | \
100 (1ULL << INT_IDN_AVAIL) | \
101 (1ULL << INT_UDN_AVAIL) | \
102 (1ULL << INT_IPI_3) | \
103 (1ULL << INT_IPI_2) | \
104 (1ULL << INT_IPI_1) | \
105 (1ULL << INT_IPI_0) | \
106 (1ULL << INT_PERF_COUNT) | \
107 (1ULL << INT_AUX_PERF_COUNT) | \
108 (1ULL << INT_INTCTRL_3) | \
109 (1ULL << INT_INTCTRL_2) | \
110 (1ULL << INT_INTCTRL_1) | \
111 (1ULL << INT_INTCTRL_0) | \
112 (1ULL << INT_BOOT_ACCESS) | \
113 (1ULL << INT_WORLD_ACCESS) | \
114 (1ULL << INT_I_ASID) | \
115 (1ULL << INT_D_ASID) | \
116 (1ULL << INT_DOUBLE_FAULT) | \
117 0)
118#define NONQUEUED_INTERRUPTS ( \
119 (1ULL << INT_SINGLE_STEP_3) | \
120 (1ULL << INT_SINGLE_STEP_2) | \
121 (1ULL << INT_SINGLE_STEP_1) | \
122 (1ULL << INT_SINGLE_STEP_0) | \
123 (1ULL << INT_ITLB_MISS) | \
124 (1ULL << INT_ILL) | \
125 (1ULL << INT_GPV) | \
126 (1ULL << INT_IDN_ACCESS) | \
127 (1ULL << INT_UDN_ACCESS) | \
128 (1ULL << INT_SWINT_3) | \
129 (1ULL << INT_SWINT_2) | \
130 (1ULL << INT_SWINT_1) | \
131 (1ULL << INT_SWINT_0) | \
132 (1ULL << INT_ILL_TRANS) | \
133 (1ULL << INT_UNALIGN_DATA) | \
134 (1ULL << INT_DTLB_MISS) | \
135 (1ULL << INT_DTLB_ACCESS) | \
136 0)
137#define CRITICAL_MASKED_INTERRUPTS ( \
138 (1ULL << INT_MEM_ERROR) | \
139 (1ULL << INT_SINGLE_STEP_3) | \
140 (1ULL << INT_SINGLE_STEP_2) | \
141 (1ULL << INT_SINGLE_STEP_1) | \
142 (1ULL << INT_SINGLE_STEP_0) | \
143 (1ULL << INT_IDN_COMPLETE) | \
144 (1ULL << INT_UDN_COMPLETE) | \
145 (1ULL << INT_IDN_FIREWALL) | \
146 (1ULL << INT_UDN_FIREWALL) | \
147 (1ULL << INT_TILE_TIMER) | \
148 (1ULL << INT_AUX_TILE_TIMER) | \
149 (1ULL << INT_IDN_TIMER) | \
150 (1ULL << INT_UDN_TIMER) | \
151 (1ULL << INT_IDN_AVAIL) | \
152 (1ULL << INT_UDN_AVAIL) | \
153 (1ULL << INT_IPI_3) | \
154 (1ULL << INT_IPI_2) | \
155 (1ULL << INT_IPI_1) | \
156 (1ULL << INT_IPI_0) | \
157 (1ULL << INT_PERF_COUNT) | \
158 (1ULL << INT_AUX_PERF_COUNT) | \
159 (1ULL << INT_INTCTRL_3) | \
160 (1ULL << INT_INTCTRL_2) | \
161 (1ULL << INT_INTCTRL_1) | \
162 (1ULL << INT_INTCTRL_0) | \
163 0)
164#define CRITICAL_UNMASKED_INTERRUPTS ( \
165 (1ULL << INT_ITLB_MISS) | \
166 (1ULL << INT_ILL) | \
167 (1ULL << INT_GPV) | \
168 (1ULL << INT_IDN_ACCESS) | \
169 (1ULL << INT_UDN_ACCESS) | \
170 (1ULL << INT_SWINT_3) | \
171 (1ULL << INT_SWINT_2) | \
172 (1ULL << INT_SWINT_1) | \
173 (1ULL << INT_SWINT_0) | \
174 (1ULL << INT_ILL_TRANS) | \
175 (1ULL << INT_UNALIGN_DATA) | \
176 (1ULL << INT_DTLB_MISS) | \
177 (1ULL << INT_DTLB_ACCESS) | \
178 (1ULL << INT_BOOT_ACCESS) | \
179 (1ULL << INT_WORLD_ACCESS) | \
180 (1ULL << INT_I_ASID) | \
181 (1ULL << INT_D_ASID) | \
182 (1ULL << INT_DOUBLE_FAULT) | \
183 0)
184#define MASKABLE_INTERRUPTS ( \
185 (1ULL << INT_MEM_ERROR) | \
186 (1ULL << INT_SINGLE_STEP_3) | \
187 (1ULL << INT_SINGLE_STEP_2) | \
188 (1ULL << INT_SINGLE_STEP_1) | \
189 (1ULL << INT_SINGLE_STEP_0) | \
190 (1ULL << INT_IDN_COMPLETE) | \
191 (1ULL << INT_UDN_COMPLETE) | \
192 (1ULL << INT_IDN_FIREWALL) | \
193 (1ULL << INT_UDN_FIREWALL) | \
194 (1ULL << INT_TILE_TIMER) | \
195 (1ULL << INT_AUX_TILE_TIMER) | \
196 (1ULL << INT_IDN_TIMER) | \
197 (1ULL << INT_UDN_TIMER) | \
198 (1ULL << INT_IDN_AVAIL) | \
199 (1ULL << INT_UDN_AVAIL) | \
200 (1ULL << INT_IPI_3) | \
201 (1ULL << INT_IPI_2) | \
202 (1ULL << INT_IPI_1) | \
203 (1ULL << INT_IPI_0) | \
204 (1ULL << INT_PERF_COUNT) | \
205 (1ULL << INT_AUX_PERF_COUNT) | \
206 (1ULL << INT_INTCTRL_3) | \
207 (1ULL << INT_INTCTRL_2) | \
208 (1ULL << INT_INTCTRL_1) | \
209 (1ULL << INT_INTCTRL_0) | \
210 0)
211#define UNMASKABLE_INTERRUPTS ( \
212 (1ULL << INT_ITLB_MISS) | \
213 (1ULL << INT_ILL) | \
214 (1ULL << INT_GPV) | \
215 (1ULL << INT_IDN_ACCESS) | \
216 (1ULL << INT_UDN_ACCESS) | \
217 (1ULL << INT_SWINT_3) | \
218 (1ULL << INT_SWINT_2) | \
219 (1ULL << INT_SWINT_1) | \
220 (1ULL << INT_SWINT_0) | \
221 (1ULL << INT_ILL_TRANS) | \
222 (1ULL << INT_UNALIGN_DATA) | \
223 (1ULL << INT_DTLB_MISS) | \
224 (1ULL << INT_DTLB_ACCESS) | \
225 (1ULL << INT_BOOT_ACCESS) | \
226 (1ULL << INT_WORLD_ACCESS) | \
227 (1ULL << INT_I_ASID) | \
228 (1ULL << INT_D_ASID) | \
229 (1ULL << INT_DOUBLE_FAULT) | \
230 0)
231#define SYNC_INTERRUPTS ( \
232 (1ULL << INT_SINGLE_STEP_3) | \
233 (1ULL << INT_SINGLE_STEP_2) | \
234 (1ULL << INT_SINGLE_STEP_1) | \
235 (1ULL << INT_SINGLE_STEP_0) | \
236 (1ULL << INT_IDN_COMPLETE) | \
237 (1ULL << INT_UDN_COMPLETE) | \
238 (1ULL << INT_ITLB_MISS) | \
239 (1ULL << INT_ILL) | \
240 (1ULL << INT_GPV) | \
241 (1ULL << INT_IDN_ACCESS) | \
242 (1ULL << INT_UDN_ACCESS) | \
243 (1ULL << INT_SWINT_3) | \
244 (1ULL << INT_SWINT_2) | \
245 (1ULL << INT_SWINT_1) | \
246 (1ULL << INT_SWINT_0) | \
247 (1ULL << INT_ILL_TRANS) | \
248 (1ULL << INT_UNALIGN_DATA) | \
249 (1ULL << INT_DTLB_MISS) | \
250 (1ULL << INT_DTLB_ACCESS) | \
251 0)
252#define NON_SYNC_INTERRUPTS ( \
253 (1ULL << INT_MEM_ERROR) | \
254 (1ULL << INT_IDN_FIREWALL) | \
255 (1ULL << INT_UDN_FIREWALL) | \
256 (1ULL << INT_TILE_TIMER) | \
257 (1ULL << INT_AUX_TILE_TIMER) | \
258 (1ULL << INT_IDN_TIMER) | \
259 (1ULL << INT_UDN_TIMER) | \
260 (1ULL << INT_IDN_AVAIL) | \
261 (1ULL << INT_UDN_AVAIL) | \
262 (1ULL << INT_IPI_3) | \
263 (1ULL << INT_IPI_2) | \
264 (1ULL << INT_IPI_1) | \
265 (1ULL << INT_IPI_0) | \
266 (1ULL << INT_PERF_COUNT) | \
267 (1ULL << INT_AUX_PERF_COUNT) | \
268 (1ULL << INT_INTCTRL_3) | \
269 (1ULL << INT_INTCTRL_2) | \
270 (1ULL << INT_INTCTRL_1) | \
271 (1ULL << INT_INTCTRL_0) | \
272 (1ULL << INT_BOOT_ACCESS) | \
273 (1ULL << INT_WORLD_ACCESS) | \
274 (1ULL << INT_I_ASID) | \
275 (1ULL << INT_D_ASID) | \
276 (1ULL << INT_DOUBLE_FAULT) | \
277 0)
278#endif /* !__ASSEMBLER__ */
279#endif /* !__ARCH_INTERRUPTS_H__ */
diff --git a/arch/tile/include/uapi/arch/intreg.h b/arch/tile/include/uapi/arch/intreg.h
deleted file mode 100644
index 5387fb645bb8..000000000000
--- a/arch/tile/include/uapi/arch/intreg.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2017 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16/**
17 * @file
18 *
19 * Provide types and defines for the type that can hold a register,
20 * in the implementation namespace.
21 */
22
23#ifndef __ARCH_INTREG_H__
24#define __ARCH_INTREG_H__
25
26/*
27 * Get number of bits in a register. __INT_REG_BITS may be defined
28 * prior to including this header to force a particular bit width.
29 */
30
31#ifndef __INT_REG_BITS
32# if defined __tilegx__
33# define __INT_REG_BITS 64
34# elif defined __tilepro__
35# define __INT_REG_BITS 32
36# else
37# error Unrecognized architecture
38# endif
39#endif
40
41#if __INT_REG_BITS == 64
42
43# ifndef __ASSEMBLER__
44/** Unsigned type that can hold a register. */
45typedef unsigned long long __uint_reg_t;
46
47/** Signed type that can hold a register. */
48typedef long long __int_reg_t;
49# endif
50
51/** String prefix to use for printf(). */
52# define __INT_REG_FMT "ll"
53
54#elif __INT_REG_BITS == 32
55
56# ifndef __ASSEMBLER__
57/** Unsigned type that can hold a register. */
58typedef unsigned long __uint_reg_t;
59
60/** Signed type that can hold a register. */
61typedef long __int_reg_t;
62# endif
63
64/** String prefix to use for printf(). */
65# define __INT_REG_FMT "l"
66
67#else
68# error Unrecognized value of __INT_REG_BITS
69#endif
70
71#endif /* !__ARCH_INTREG_H__ */
diff --git a/arch/tile/include/uapi/arch/opcode.h b/arch/tile/include/uapi/arch/opcode.h
deleted file mode 100644
index a9ce5961a028..000000000000
--- a/arch/tile/include/uapi/arch/opcode.h
+++ /dev/null
@@ -1,22 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#if defined(__tilepro__)
17#include <arch/opcode_tilepro.h>
18#elif defined(__tilegx__)
19#include <arch/opcode_tilegx.h>
20#else
21#error Unexpected Tilera chip type
22#endif
diff --git a/arch/tile/include/uapi/arch/opcode_tilegx.h b/arch/tile/include/uapi/arch/opcode_tilegx.h
deleted file mode 100644
index 948ea544567f..000000000000
--- a/arch/tile/include/uapi/arch/opcode_tilegx.h
+++ /dev/null
@@ -1,1407 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/* TILE-Gx opcode information.
3 *
4 * Copyright 2011 Tilera Corporation. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for
14 * more details.
15 *
16 *
17 *
18 *
19 *
20 */
21
22#ifndef __ARCH_OPCODE_H__
23#define __ARCH_OPCODE_H__
24
25#ifndef __ASSEMBLER__
26
27typedef unsigned long long tilegx_bundle_bits;
28
29/* These are the bits that determine if a bundle is in the X encoding. */
30#define TILEGX_BUNDLE_MODE_MASK ((tilegx_bundle_bits)3 << 62)
31
32enum
33{
34 /* Maximum number of instructions in a bundle (2 for X, 3 for Y). */
35 TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE = 3,
36
37 /* How many different pipeline encodings are there? X0, X1, Y0, Y1, Y2. */
38 TILEGX_NUM_PIPELINE_ENCODINGS = 5,
39
40 /* Log base 2 of TILEGX_BUNDLE_SIZE_IN_BYTES. */
41 TILEGX_LOG2_BUNDLE_SIZE_IN_BYTES = 3,
42
43 /* Instructions take this many bytes. */
44 TILEGX_BUNDLE_SIZE_IN_BYTES = 1 << TILEGX_LOG2_BUNDLE_SIZE_IN_BYTES,
45
46 /* Log base 2 of TILEGX_BUNDLE_ALIGNMENT_IN_BYTES. */
47 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES = 3,
48
49 /* Bundles should be aligned modulo this number of bytes. */
50 TILEGX_BUNDLE_ALIGNMENT_IN_BYTES =
51 (1 << TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES),
52
53 /* Number of registers (some are magic, such as network I/O). */
54 TILEGX_NUM_REGISTERS = 64,
55};
56
57/* Make a few "tile_" variables to simplify common code between
58 architectures. */
59
60typedef tilegx_bundle_bits tile_bundle_bits;
61#define TILE_BUNDLE_SIZE_IN_BYTES TILEGX_BUNDLE_SIZE_IN_BYTES
62#define TILE_BUNDLE_ALIGNMENT_IN_BYTES TILEGX_BUNDLE_ALIGNMENT_IN_BYTES
63#define TILE_LOG2_BUNDLE_ALIGNMENT_IN_BYTES \
64 TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
65#define TILE_BPT_BUNDLE TILEGX_BPT_BUNDLE
66
67/* 64-bit pattern for a { bpt ; nop } bundle. */
68#define TILEGX_BPT_BUNDLE 0x286a44ae51485000ULL
69
70static __inline unsigned int
71get_BFEnd_X0(tilegx_bundle_bits num)
72{
73 const unsigned int n = (unsigned int)num;
74 return (((n >> 12)) & 0x3f);
75}
76
77static __inline unsigned int
78get_BFOpcodeExtension_X0(tilegx_bundle_bits num)
79{
80 const unsigned int n = (unsigned int)num;
81 return (((n >> 24)) & 0xf);
82}
83
84static __inline unsigned int
85get_BFStart_X0(tilegx_bundle_bits num)
86{
87 const unsigned int n = (unsigned int)num;
88 return (((n >> 18)) & 0x3f);
89}
90
91static __inline unsigned int
92get_BrOff_X1(tilegx_bundle_bits n)
93{
94 return (((unsigned int)(n >> 31)) & 0x0000003f) |
95 (((unsigned int)(n >> 37)) & 0x0001ffc0);
96}
97
98static __inline unsigned int
99get_BrType_X1(tilegx_bundle_bits n)
100{
101 return (((unsigned int)(n >> 54)) & 0x1f);
102}
103
104static __inline unsigned int
105get_Dest_Imm8_X1(tilegx_bundle_bits n)
106{
107 return (((unsigned int)(n >> 31)) & 0x0000003f) |
108 (((unsigned int)(n >> 43)) & 0x000000c0);
109}
110
111static __inline unsigned int
112get_Dest_X0(tilegx_bundle_bits num)
113{
114 const unsigned int n = (unsigned int)num;
115 return (((n >> 0)) & 0x3f);
116}
117
118static __inline unsigned int
119get_Dest_X1(tilegx_bundle_bits n)
120{
121 return (((unsigned int)(n >> 31)) & 0x3f);
122}
123
124static __inline unsigned int
125get_Dest_Y0(tilegx_bundle_bits num)
126{
127 const unsigned int n = (unsigned int)num;
128 return (((n >> 0)) & 0x3f);
129}
130
131static __inline unsigned int
132get_Dest_Y1(tilegx_bundle_bits n)
133{
134 return (((unsigned int)(n >> 31)) & 0x3f);
135}
136
137static __inline unsigned int
138get_Imm16_X0(tilegx_bundle_bits num)
139{
140 const unsigned int n = (unsigned int)num;
141 return (((n >> 12)) & 0xffff);
142}
143
144static __inline unsigned int
145get_Imm16_X1(tilegx_bundle_bits n)
146{
147 return (((unsigned int)(n >> 43)) & 0xffff);
148}
149
150static __inline unsigned int
151get_Imm8OpcodeExtension_X0(tilegx_bundle_bits num)
152{
153 const unsigned int n = (unsigned int)num;
154 return (((n >> 20)) & 0xff);
155}
156
157static __inline unsigned int
158get_Imm8OpcodeExtension_X1(tilegx_bundle_bits n)
159{
160 return (((unsigned int)(n >> 51)) & 0xff);
161}
162
163static __inline unsigned int
164get_Imm8_X0(tilegx_bundle_bits num)
165{
166 const unsigned int n = (unsigned int)num;
167 return (((n >> 12)) & 0xff);
168}
169
170static __inline unsigned int
171get_Imm8_X1(tilegx_bundle_bits n)
172{
173 return (((unsigned int)(n >> 43)) & 0xff);
174}
175
176static __inline unsigned int
177get_Imm8_Y0(tilegx_bundle_bits num)
178{
179 const unsigned int n = (unsigned int)num;
180 return (((n >> 12)) & 0xff);
181}
182
183static __inline unsigned int
184get_Imm8_Y1(tilegx_bundle_bits n)
185{
186 return (((unsigned int)(n >> 43)) & 0xff);
187}
188
189static __inline unsigned int
190get_JumpOff_X1(tilegx_bundle_bits n)
191{
192 return (((unsigned int)(n >> 31)) & 0x7ffffff);
193}
194
195static __inline unsigned int
196get_JumpOpcodeExtension_X1(tilegx_bundle_bits n)
197{
198 return (((unsigned int)(n >> 58)) & 0x1);
199}
200
201static __inline unsigned int
202get_MF_Imm14_X1(tilegx_bundle_bits n)
203{
204 return (((unsigned int)(n >> 37)) & 0x3fff);
205}
206
207static __inline unsigned int
208get_MT_Imm14_X1(tilegx_bundle_bits n)
209{
210 return (((unsigned int)(n >> 31)) & 0x0000003f) |
211 (((unsigned int)(n >> 37)) & 0x00003fc0);
212}
213
214static __inline unsigned int
215get_Mode(tilegx_bundle_bits n)
216{
217 return (((unsigned int)(n >> 62)) & 0x3);
218}
219
220static __inline unsigned int
221get_Opcode_X0(tilegx_bundle_bits num)
222{
223 const unsigned int n = (unsigned int)num;
224 return (((n >> 28)) & 0x7);
225}
226
227static __inline unsigned int
228get_Opcode_X1(tilegx_bundle_bits n)
229{
230 return (((unsigned int)(n >> 59)) & 0x7);
231}
232
233static __inline unsigned int
234get_Opcode_Y0(tilegx_bundle_bits num)
235{
236 const unsigned int n = (unsigned int)num;
237 return (((n >> 27)) & 0xf);
238}
239
240static __inline unsigned int
241get_Opcode_Y1(tilegx_bundle_bits n)
242{
243 return (((unsigned int)(n >> 58)) & 0xf);
244}
245
246static __inline unsigned int
247get_Opcode_Y2(tilegx_bundle_bits n)
248{
249 return (((n >> 26)) & 0x00000001) |
250 (((unsigned int)(n >> 56)) & 0x00000002);
251}
252
253static __inline unsigned int
254get_RRROpcodeExtension_X0(tilegx_bundle_bits num)
255{
256 const unsigned int n = (unsigned int)num;
257 return (((n >> 18)) & 0x3ff);
258}
259
260static __inline unsigned int
261get_RRROpcodeExtension_X1(tilegx_bundle_bits n)
262{
263 return (((unsigned int)(n >> 49)) & 0x3ff);
264}
265
266static __inline unsigned int
267get_RRROpcodeExtension_Y0(tilegx_bundle_bits num)
268{
269 const unsigned int n = (unsigned int)num;
270 return (((n >> 18)) & 0x3);
271}
272
273static __inline unsigned int
274get_RRROpcodeExtension_Y1(tilegx_bundle_bits n)
275{
276 return (((unsigned int)(n >> 49)) & 0x3);
277}
278
279static __inline unsigned int
280get_ShAmt_X0(tilegx_bundle_bits num)
281{
282 const unsigned int n = (unsigned int)num;
283 return (((n >> 12)) & 0x3f);
284}
285
286static __inline unsigned int
287get_ShAmt_X1(tilegx_bundle_bits n)
288{
289 return (((unsigned int)(n >> 43)) & 0x3f);
290}
291
292static __inline unsigned int
293get_ShAmt_Y0(tilegx_bundle_bits num)
294{
295 const unsigned int n = (unsigned int)num;
296 return (((n >> 12)) & 0x3f);
297}
298
299static __inline unsigned int
300get_ShAmt_Y1(tilegx_bundle_bits n)
301{
302 return (((unsigned int)(n >> 43)) & 0x3f);
303}
304
305static __inline unsigned int
306get_ShiftOpcodeExtension_X0(tilegx_bundle_bits num)
307{
308 const unsigned int n = (unsigned int)num;
309 return (((n >> 18)) & 0x3ff);
310}
311
312static __inline unsigned int
313get_ShiftOpcodeExtension_X1(tilegx_bundle_bits n)
314{
315 return (((unsigned int)(n >> 49)) & 0x3ff);
316}
317
318static __inline unsigned int
319get_ShiftOpcodeExtension_Y0(tilegx_bundle_bits num)
320{
321 const unsigned int n = (unsigned int)num;
322 return (((n >> 18)) & 0x3);
323}
324
325static __inline unsigned int
326get_ShiftOpcodeExtension_Y1(tilegx_bundle_bits n)
327{
328 return (((unsigned int)(n >> 49)) & 0x3);
329}
330
331static __inline unsigned int
332get_SrcA_X0(tilegx_bundle_bits num)
333{
334 const unsigned int n = (unsigned int)num;
335 return (((n >> 6)) & 0x3f);
336}
337
338static __inline unsigned int
339get_SrcA_X1(tilegx_bundle_bits n)
340{
341 return (((unsigned int)(n >> 37)) & 0x3f);
342}
343
344static __inline unsigned int
345get_SrcA_Y0(tilegx_bundle_bits num)
346{
347 const unsigned int n = (unsigned int)num;
348 return (((n >> 6)) & 0x3f);
349}
350
351static __inline unsigned int
352get_SrcA_Y1(tilegx_bundle_bits n)
353{
354 return (((unsigned int)(n >> 37)) & 0x3f);
355}
356
357static __inline unsigned int
358get_SrcA_Y2(tilegx_bundle_bits num)
359{
360 const unsigned int n = (unsigned int)num;
361 return (((n >> 20)) & 0x3f);
362}
363
364static __inline unsigned int
365get_SrcBDest_Y2(tilegx_bundle_bits n)
366{
367 return (((unsigned int)(n >> 51)) & 0x3f);
368}
369
370static __inline unsigned int
371get_SrcB_X0(tilegx_bundle_bits num)
372{
373 const unsigned int n = (unsigned int)num;
374 return (((n >> 12)) & 0x3f);
375}
376
377static __inline unsigned int
378get_SrcB_X1(tilegx_bundle_bits n)
379{
380 return (((unsigned int)(n >> 43)) & 0x3f);
381}
382
383static __inline unsigned int
384get_SrcB_Y0(tilegx_bundle_bits num)
385{
386 const unsigned int n = (unsigned int)num;
387 return (((n >> 12)) & 0x3f);
388}
389
390static __inline unsigned int
391get_SrcB_Y1(tilegx_bundle_bits n)
392{
393 return (((unsigned int)(n >> 43)) & 0x3f);
394}
395
396static __inline unsigned int
397get_UnaryOpcodeExtension_X0(tilegx_bundle_bits num)
398{
399 const unsigned int n = (unsigned int)num;
400 return (((n >> 12)) & 0x3f);
401}
402
403static __inline unsigned int
404get_UnaryOpcodeExtension_X1(tilegx_bundle_bits n)
405{
406 return (((unsigned int)(n >> 43)) & 0x3f);
407}
408
409static __inline unsigned int
410get_UnaryOpcodeExtension_Y0(tilegx_bundle_bits num)
411{
412 const unsigned int n = (unsigned int)num;
413 return (((n >> 12)) & 0x3f);
414}
415
416static __inline unsigned int
417get_UnaryOpcodeExtension_Y1(tilegx_bundle_bits n)
418{
419 return (((unsigned int)(n >> 43)) & 0x3f);
420}
421
422
423static __inline int
424sign_extend(int n, int num_bits)
425{
426 int shift = (int)(sizeof(int) * 8 - num_bits);
427 return (n << shift) >> shift;
428}
429
430
431
432static __inline tilegx_bundle_bits
433create_BFEnd_X0(int num)
434{
435 const unsigned int n = (unsigned int)num;
436 return ((n & 0x3f) << 12);
437}
438
439static __inline tilegx_bundle_bits
440create_BFOpcodeExtension_X0(int num)
441{
442 const unsigned int n = (unsigned int)num;
443 return ((n & 0xf) << 24);
444}
445
446static __inline tilegx_bundle_bits
447create_BFStart_X0(int num)
448{
449 const unsigned int n = (unsigned int)num;
450 return ((n & 0x3f) << 18);
451}
452
453static __inline tilegx_bundle_bits
454create_BrOff_X1(int num)
455{
456 const unsigned int n = (unsigned int)num;
457 return (((tilegx_bundle_bits)(n & 0x0000003f)) << 31) |
458 (((tilegx_bundle_bits)(n & 0x0001ffc0)) << 37);
459}
460
461static __inline tilegx_bundle_bits
462create_BrType_X1(int num)
463{
464 const unsigned int n = (unsigned int)num;
465 return (((tilegx_bundle_bits)(n & 0x1f)) << 54);
466}
467
468static __inline tilegx_bundle_bits
469create_Dest_Imm8_X1(int num)
470{
471 const unsigned int n = (unsigned int)num;
472 return (((tilegx_bundle_bits)(n & 0x0000003f)) << 31) |
473 (((tilegx_bundle_bits)(n & 0x000000c0)) << 43);
474}
475
476static __inline tilegx_bundle_bits
477create_Dest_X0(int num)
478{
479 const unsigned int n = (unsigned int)num;
480 return ((n & 0x3f) << 0);
481}
482
483static __inline tilegx_bundle_bits
484create_Dest_X1(int num)
485{
486 const unsigned int n = (unsigned int)num;
487 return (((tilegx_bundle_bits)(n & 0x3f)) << 31);
488}
489
490static __inline tilegx_bundle_bits
491create_Dest_Y0(int num)
492{
493 const unsigned int n = (unsigned int)num;
494 return ((n & 0x3f) << 0);
495}
496
497static __inline tilegx_bundle_bits
498create_Dest_Y1(int num)
499{
500 const unsigned int n = (unsigned int)num;
501 return (((tilegx_bundle_bits)(n & 0x3f)) << 31);
502}
503
504static __inline tilegx_bundle_bits
505create_Imm16_X0(int num)
506{
507 const unsigned int n = (unsigned int)num;
508 return ((n & 0xffff) << 12);
509}
510
511static __inline tilegx_bundle_bits
512create_Imm16_X1(int num)
513{
514 const unsigned int n = (unsigned int)num;
515 return (((tilegx_bundle_bits)(n & 0xffff)) << 43);
516}
517
518static __inline tilegx_bundle_bits
519create_Imm8OpcodeExtension_X0(int num)
520{
521 const unsigned int n = (unsigned int)num;
522 return ((n & 0xff) << 20);
523}
524
525static __inline tilegx_bundle_bits
526create_Imm8OpcodeExtension_X1(int num)
527{
528 const unsigned int n = (unsigned int)num;
529 return (((tilegx_bundle_bits)(n & 0xff)) << 51);
530}
531
532static __inline tilegx_bundle_bits
533create_Imm8_X0(int num)
534{
535 const unsigned int n = (unsigned int)num;
536 return ((n & 0xff) << 12);
537}
538
539static __inline tilegx_bundle_bits
540create_Imm8_X1(int num)
541{
542 const unsigned int n = (unsigned int)num;
543 return (((tilegx_bundle_bits)(n & 0xff)) << 43);
544}
545
546static __inline tilegx_bundle_bits
547create_Imm8_Y0(int num)
548{
549 const unsigned int n = (unsigned int)num;
550 return ((n & 0xff) << 12);
551}
552
553static __inline tilegx_bundle_bits
554create_Imm8_Y1(int num)
555{
556 const unsigned int n = (unsigned int)num;
557 return (((tilegx_bundle_bits)(n & 0xff)) << 43);
558}
559
560static __inline tilegx_bundle_bits
561create_JumpOff_X1(int num)
562{
563 const unsigned int n = (unsigned int)num;
564 return (((tilegx_bundle_bits)(n & 0x7ffffff)) << 31);
565}
566
567static __inline tilegx_bundle_bits
568create_JumpOpcodeExtension_X1(int num)
569{
570 const unsigned int n = (unsigned int)num;
571 return (((tilegx_bundle_bits)(n & 0x1)) << 58);
572}
573
574static __inline tilegx_bundle_bits
575create_MF_Imm14_X1(int num)
576{
577 const unsigned int n = (unsigned int)num;
578 return (((tilegx_bundle_bits)(n & 0x3fff)) << 37);
579}
580
581static __inline tilegx_bundle_bits
582create_MT_Imm14_X1(int num)
583{
584 const unsigned int n = (unsigned int)num;
585 return (((tilegx_bundle_bits)(n & 0x0000003f)) << 31) |
586 (((tilegx_bundle_bits)(n & 0x00003fc0)) << 37);
587}
588
589static __inline tilegx_bundle_bits
590create_Mode(int num)
591{
592 const unsigned int n = (unsigned int)num;
593 return (((tilegx_bundle_bits)(n & 0x3)) << 62);
594}
595
596static __inline tilegx_bundle_bits
597create_Opcode_X0(int num)
598{
599 const unsigned int n = (unsigned int)num;
600 return ((n & 0x7) << 28);
601}
602
603static __inline tilegx_bundle_bits
604create_Opcode_X1(int num)
605{
606 const unsigned int n = (unsigned int)num;
607 return (((tilegx_bundle_bits)(n & 0x7)) << 59);
608}
609
610static __inline tilegx_bundle_bits
611create_Opcode_Y0(int num)
612{
613 const unsigned int n = (unsigned int)num;
614 return ((n & 0xf) << 27);
615}
616
617static __inline tilegx_bundle_bits
618create_Opcode_Y1(int num)
619{
620 const unsigned int n = (unsigned int)num;
621 return (((tilegx_bundle_bits)(n & 0xf)) << 58);
622}
623
624static __inline tilegx_bundle_bits
625create_Opcode_Y2(int num)
626{
627 const unsigned int n = (unsigned int)num;
628 return ((n & 0x00000001) << 26) |
629 (((tilegx_bundle_bits)(n & 0x00000002)) << 56);
630}
631
632static __inline tilegx_bundle_bits
633create_RRROpcodeExtension_X0(int num)
634{
635 const unsigned int n = (unsigned int)num;
636 return ((n & 0x3ff) << 18);
637}
638
639static __inline tilegx_bundle_bits
640create_RRROpcodeExtension_X1(int num)
641{
642 const unsigned int n = (unsigned int)num;
643 return (((tilegx_bundle_bits)(n & 0x3ff)) << 49);
644}
645
646static __inline tilegx_bundle_bits
647create_RRROpcodeExtension_Y0(int num)
648{
649 const unsigned int n = (unsigned int)num;
650 return ((n & 0x3) << 18);
651}
652
653static __inline tilegx_bundle_bits
654create_RRROpcodeExtension_Y1(int num)
655{
656 const unsigned int n = (unsigned int)num;
657 return (((tilegx_bundle_bits)(n & 0x3)) << 49);
658}
659
660static __inline tilegx_bundle_bits
661create_ShAmt_X0(int num)
662{
663 const unsigned int n = (unsigned int)num;
664 return ((n & 0x3f) << 12);
665}
666
667static __inline tilegx_bundle_bits
668create_ShAmt_X1(int num)
669{
670 const unsigned int n = (unsigned int)num;
671 return (((tilegx_bundle_bits)(n & 0x3f)) << 43);
672}
673
674static __inline tilegx_bundle_bits
675create_ShAmt_Y0(int num)
676{
677 const unsigned int n = (unsigned int)num;
678 return ((n & 0x3f) << 12);
679}
680
681static __inline tilegx_bundle_bits
682create_ShAmt_Y1(int num)
683{
684 const unsigned int n = (unsigned int)num;
685 return (((tilegx_bundle_bits)(n & 0x3f)) << 43);
686}
687
688static __inline tilegx_bundle_bits
689create_ShiftOpcodeExtension_X0(int num)
690{
691 const unsigned int n = (unsigned int)num;
692 return ((n & 0x3ff) << 18);
693}
694
695static __inline tilegx_bundle_bits
696create_ShiftOpcodeExtension_X1(int num)
697{
698 const unsigned int n = (unsigned int)num;
699 return (((tilegx_bundle_bits)(n & 0x3ff)) << 49);
700}
701
702static __inline tilegx_bundle_bits
703create_ShiftOpcodeExtension_Y0(int num)
704{
705 const unsigned int n = (unsigned int)num;
706 return ((n & 0x3) << 18);
707}
708
709static __inline tilegx_bundle_bits
710create_ShiftOpcodeExtension_Y1(int num)
711{
712 const unsigned int n = (unsigned int)num;
713 return (((tilegx_bundle_bits)(n & 0x3)) << 49);
714}
715
716static __inline tilegx_bundle_bits
717create_SrcA_X0(int num)
718{
719 const unsigned int n = (unsigned int)num;
720 return ((n & 0x3f) << 6);
721}
722
723static __inline tilegx_bundle_bits
724create_SrcA_X1(int num)
725{
726 const unsigned int n = (unsigned int)num;
727 return (((tilegx_bundle_bits)(n & 0x3f)) << 37);
728}
729
730static __inline tilegx_bundle_bits
731create_SrcA_Y0(int num)
732{
733 const unsigned int n = (unsigned int)num;
734 return ((n & 0x3f) << 6);
735}
736
737static __inline tilegx_bundle_bits
738create_SrcA_Y1(int num)
739{
740 const unsigned int n = (unsigned int)num;
741 return (((tilegx_bundle_bits)(n & 0x3f)) << 37);
742}
743
744static __inline tilegx_bundle_bits
745create_SrcA_Y2(int num)
746{
747 const unsigned int n = (unsigned int)num;
748 return ((n & 0x3f) << 20);
749}
750
751static __inline tilegx_bundle_bits
752create_SrcBDest_Y2(int num)
753{
754 const unsigned int n = (unsigned int)num;
755 return (((tilegx_bundle_bits)(n & 0x3f)) << 51);
756}
757
758static __inline tilegx_bundle_bits
759create_SrcB_X0(int num)
760{
761 const unsigned int n = (unsigned int)num;
762 return ((n & 0x3f) << 12);
763}
764
765static __inline tilegx_bundle_bits
766create_SrcB_X1(int num)
767{
768 const unsigned int n = (unsigned int)num;
769 return (((tilegx_bundle_bits)(n & 0x3f)) << 43);
770}
771
772static __inline tilegx_bundle_bits
773create_SrcB_Y0(int num)
774{
775 const unsigned int n = (unsigned int)num;
776 return ((n & 0x3f) << 12);
777}
778
779static __inline tilegx_bundle_bits
780create_SrcB_Y1(int num)
781{
782 const unsigned int n = (unsigned int)num;
783 return (((tilegx_bundle_bits)(n & 0x3f)) << 43);
784}
785
786static __inline tilegx_bundle_bits
787create_UnaryOpcodeExtension_X0(int num)
788{
789 const unsigned int n = (unsigned int)num;
790 return ((n & 0x3f) << 12);
791}
792
793static __inline tilegx_bundle_bits
794create_UnaryOpcodeExtension_X1(int num)
795{
796 const unsigned int n = (unsigned int)num;
797 return (((tilegx_bundle_bits)(n & 0x3f)) << 43);
798}
799
800static __inline tilegx_bundle_bits
801create_UnaryOpcodeExtension_Y0(int num)
802{
803 const unsigned int n = (unsigned int)num;
804 return ((n & 0x3f) << 12);
805}
806
807static __inline tilegx_bundle_bits
808create_UnaryOpcodeExtension_Y1(int num)
809{
810 const unsigned int n = (unsigned int)num;
811 return (((tilegx_bundle_bits)(n & 0x3f)) << 43);
812}
813
814
815enum
816{
817 ADDI_IMM8_OPCODE_X0 = 1,
818 ADDI_IMM8_OPCODE_X1 = 1,
819 ADDI_OPCODE_Y0 = 0,
820 ADDI_OPCODE_Y1 = 1,
821 ADDLI_OPCODE_X0 = 1,
822 ADDLI_OPCODE_X1 = 0,
823 ADDXI_IMM8_OPCODE_X0 = 2,
824 ADDXI_IMM8_OPCODE_X1 = 2,
825 ADDXI_OPCODE_Y0 = 1,
826 ADDXI_OPCODE_Y1 = 2,
827 ADDXLI_OPCODE_X0 = 2,
828 ADDXLI_OPCODE_X1 = 1,
829 ADDXSC_RRR_0_OPCODE_X0 = 1,
830 ADDXSC_RRR_0_OPCODE_X1 = 1,
831 ADDX_RRR_0_OPCODE_X0 = 2,
832 ADDX_RRR_0_OPCODE_X1 = 2,
833 ADDX_RRR_0_OPCODE_Y0 = 0,
834 ADDX_RRR_0_OPCODE_Y1 = 0,
835 ADD_RRR_0_OPCODE_X0 = 3,
836 ADD_RRR_0_OPCODE_X1 = 3,
837 ADD_RRR_0_OPCODE_Y0 = 1,
838 ADD_RRR_0_OPCODE_Y1 = 1,
839 ANDI_IMM8_OPCODE_X0 = 3,
840 ANDI_IMM8_OPCODE_X1 = 3,
841 ANDI_OPCODE_Y0 = 2,
842 ANDI_OPCODE_Y1 = 3,
843 AND_RRR_0_OPCODE_X0 = 4,
844 AND_RRR_0_OPCODE_X1 = 4,
845 AND_RRR_5_OPCODE_Y0 = 0,
846 AND_RRR_5_OPCODE_Y1 = 0,
847 BEQZT_BRANCH_OPCODE_X1 = 16,
848 BEQZ_BRANCH_OPCODE_X1 = 17,
849 BFEXTS_BF_OPCODE_X0 = 4,
850 BFEXTU_BF_OPCODE_X0 = 5,
851 BFINS_BF_OPCODE_X0 = 6,
852 BF_OPCODE_X0 = 3,
853 BGEZT_BRANCH_OPCODE_X1 = 18,
854 BGEZ_BRANCH_OPCODE_X1 = 19,
855 BGTZT_BRANCH_OPCODE_X1 = 20,
856 BGTZ_BRANCH_OPCODE_X1 = 21,
857 BLBCT_BRANCH_OPCODE_X1 = 22,
858 BLBC_BRANCH_OPCODE_X1 = 23,
859 BLBST_BRANCH_OPCODE_X1 = 24,
860 BLBS_BRANCH_OPCODE_X1 = 25,
861 BLEZT_BRANCH_OPCODE_X1 = 26,
862 BLEZ_BRANCH_OPCODE_X1 = 27,
863 BLTZT_BRANCH_OPCODE_X1 = 28,
864 BLTZ_BRANCH_OPCODE_X1 = 29,
865 BNEZT_BRANCH_OPCODE_X1 = 30,
866 BNEZ_BRANCH_OPCODE_X1 = 31,
867 BRANCH_OPCODE_X1 = 2,
868 CMOVEQZ_RRR_0_OPCODE_X0 = 5,
869 CMOVEQZ_RRR_4_OPCODE_Y0 = 0,
870 CMOVNEZ_RRR_0_OPCODE_X0 = 6,
871 CMOVNEZ_RRR_4_OPCODE_Y0 = 1,
872 CMPEQI_IMM8_OPCODE_X0 = 4,
873 CMPEQI_IMM8_OPCODE_X1 = 4,
874 CMPEQI_OPCODE_Y0 = 3,
875 CMPEQI_OPCODE_Y1 = 4,
876 CMPEQ_RRR_0_OPCODE_X0 = 7,
877 CMPEQ_RRR_0_OPCODE_X1 = 5,
878 CMPEQ_RRR_3_OPCODE_Y0 = 0,
879 CMPEQ_RRR_3_OPCODE_Y1 = 2,
880 CMPEXCH4_RRR_0_OPCODE_X1 = 6,
881 CMPEXCH_RRR_0_OPCODE_X1 = 7,
882 CMPLES_RRR_0_OPCODE_X0 = 8,
883 CMPLES_RRR_0_OPCODE_X1 = 8,
884 CMPLES_RRR_2_OPCODE_Y0 = 0,
885 CMPLES_RRR_2_OPCODE_Y1 = 0,
886 CMPLEU_RRR_0_OPCODE_X0 = 9,
887 CMPLEU_RRR_0_OPCODE_X1 = 9,
888 CMPLEU_RRR_2_OPCODE_Y0 = 1,
889 CMPLEU_RRR_2_OPCODE_Y1 = 1,
890 CMPLTSI_IMM8_OPCODE_X0 = 5,
891 CMPLTSI_IMM8_OPCODE_X1 = 5,
892 CMPLTSI_OPCODE_Y0 = 4,
893 CMPLTSI_OPCODE_Y1 = 5,
894 CMPLTS_RRR_0_OPCODE_X0 = 10,
895 CMPLTS_RRR_0_OPCODE_X1 = 10,
896 CMPLTS_RRR_2_OPCODE_Y0 = 2,
897 CMPLTS_RRR_2_OPCODE_Y1 = 2,
898 CMPLTUI_IMM8_OPCODE_X0 = 6,
899 CMPLTUI_IMM8_OPCODE_X1 = 6,
900 CMPLTU_RRR_0_OPCODE_X0 = 11,
901 CMPLTU_RRR_0_OPCODE_X1 = 11,
902 CMPLTU_RRR_2_OPCODE_Y0 = 3,
903 CMPLTU_RRR_2_OPCODE_Y1 = 3,
904 CMPNE_RRR_0_OPCODE_X0 = 12,
905 CMPNE_RRR_0_OPCODE_X1 = 12,
906 CMPNE_RRR_3_OPCODE_Y0 = 1,
907 CMPNE_RRR_3_OPCODE_Y1 = 3,
908 CMULAF_RRR_0_OPCODE_X0 = 13,
909 CMULA_RRR_0_OPCODE_X0 = 14,
910 CMULFR_RRR_0_OPCODE_X0 = 15,
911 CMULF_RRR_0_OPCODE_X0 = 16,
912 CMULHR_RRR_0_OPCODE_X0 = 17,
913 CMULH_RRR_0_OPCODE_X0 = 18,
914 CMUL_RRR_0_OPCODE_X0 = 19,
915 CNTLZ_UNARY_OPCODE_X0 = 1,
916 CNTLZ_UNARY_OPCODE_Y0 = 1,
917 CNTTZ_UNARY_OPCODE_X0 = 2,
918 CNTTZ_UNARY_OPCODE_Y0 = 2,
919 CRC32_32_RRR_0_OPCODE_X0 = 20,
920 CRC32_8_RRR_0_OPCODE_X0 = 21,
921 DBLALIGN2_RRR_0_OPCODE_X0 = 22,
922 DBLALIGN2_RRR_0_OPCODE_X1 = 13,
923 DBLALIGN4_RRR_0_OPCODE_X0 = 23,
924 DBLALIGN4_RRR_0_OPCODE_X1 = 14,
925 DBLALIGN6_RRR_0_OPCODE_X0 = 24,
926 DBLALIGN6_RRR_0_OPCODE_X1 = 15,
927 DBLALIGN_RRR_0_OPCODE_X0 = 25,
928 DRAIN_UNARY_OPCODE_X1 = 1,
929 DTLBPR_UNARY_OPCODE_X1 = 2,
930 EXCH4_RRR_0_OPCODE_X1 = 16,
931 EXCH_RRR_0_OPCODE_X1 = 17,
932 FDOUBLE_ADDSUB_RRR_0_OPCODE_X0 = 26,
933 FDOUBLE_ADD_FLAGS_RRR_0_OPCODE_X0 = 27,
934 FDOUBLE_MUL_FLAGS_RRR_0_OPCODE_X0 = 28,
935 FDOUBLE_PACK1_RRR_0_OPCODE_X0 = 29,
936 FDOUBLE_PACK2_RRR_0_OPCODE_X0 = 30,
937 FDOUBLE_SUB_FLAGS_RRR_0_OPCODE_X0 = 31,
938 FDOUBLE_UNPACK_MAX_RRR_0_OPCODE_X0 = 32,
939 FDOUBLE_UNPACK_MIN_RRR_0_OPCODE_X0 = 33,
940 FETCHADD4_RRR_0_OPCODE_X1 = 18,
941 FETCHADDGEZ4_RRR_0_OPCODE_X1 = 19,
942 FETCHADDGEZ_RRR_0_OPCODE_X1 = 20,
943 FETCHADD_RRR_0_OPCODE_X1 = 21,
944 FETCHAND4_RRR_0_OPCODE_X1 = 22,
945 FETCHAND_RRR_0_OPCODE_X1 = 23,
946 FETCHOR4_RRR_0_OPCODE_X1 = 24,
947 FETCHOR_RRR_0_OPCODE_X1 = 25,
948 FINV_UNARY_OPCODE_X1 = 3,
949 FLUSHWB_UNARY_OPCODE_X1 = 4,
950 FLUSH_UNARY_OPCODE_X1 = 5,
951 FNOP_UNARY_OPCODE_X0 = 3,
952 FNOP_UNARY_OPCODE_X1 = 6,
953 FNOP_UNARY_OPCODE_Y0 = 3,
954 FNOP_UNARY_OPCODE_Y1 = 8,
955 FSINGLE_ADD1_RRR_0_OPCODE_X0 = 34,
956 FSINGLE_ADDSUB2_RRR_0_OPCODE_X0 = 35,
957 FSINGLE_MUL1_RRR_0_OPCODE_X0 = 36,
958 FSINGLE_MUL2_RRR_0_OPCODE_X0 = 37,
959 FSINGLE_PACK1_UNARY_OPCODE_X0 = 4,
960 FSINGLE_PACK1_UNARY_OPCODE_Y0 = 4,
961 FSINGLE_PACK2_RRR_0_OPCODE_X0 = 38,
962 FSINGLE_SUB1_RRR_0_OPCODE_X0 = 39,
963 ICOH_UNARY_OPCODE_X1 = 7,
964 ILL_UNARY_OPCODE_X1 = 8,
965 ILL_UNARY_OPCODE_Y1 = 9,
966 IMM8_OPCODE_X0 = 4,
967 IMM8_OPCODE_X1 = 3,
968 INV_UNARY_OPCODE_X1 = 9,
969 IRET_UNARY_OPCODE_X1 = 10,
970 JALRP_UNARY_OPCODE_X1 = 11,
971 JALRP_UNARY_OPCODE_Y1 = 10,
972 JALR_UNARY_OPCODE_X1 = 12,
973 JALR_UNARY_OPCODE_Y1 = 11,
974 JAL_JUMP_OPCODE_X1 = 0,
975 JRP_UNARY_OPCODE_X1 = 13,
976 JRP_UNARY_OPCODE_Y1 = 12,
977 JR_UNARY_OPCODE_X1 = 14,
978 JR_UNARY_OPCODE_Y1 = 13,
979 JUMP_OPCODE_X1 = 4,
980 J_JUMP_OPCODE_X1 = 1,
981 LD1S_ADD_IMM8_OPCODE_X1 = 7,
982 LD1S_OPCODE_Y2 = 0,
983 LD1S_UNARY_OPCODE_X1 = 15,
984 LD1U_ADD_IMM8_OPCODE_X1 = 8,
985 LD1U_OPCODE_Y2 = 1,
986 LD1U_UNARY_OPCODE_X1 = 16,
987 LD2S_ADD_IMM8_OPCODE_X1 = 9,
988 LD2S_OPCODE_Y2 = 2,
989 LD2S_UNARY_OPCODE_X1 = 17,
990 LD2U_ADD_IMM8_OPCODE_X1 = 10,
991 LD2U_OPCODE_Y2 = 3,
992 LD2U_UNARY_OPCODE_X1 = 18,
993 LD4S_ADD_IMM8_OPCODE_X1 = 11,
994 LD4S_OPCODE_Y2 = 1,
995 LD4S_UNARY_OPCODE_X1 = 19,
996 LD4U_ADD_IMM8_OPCODE_X1 = 12,
997 LD4U_OPCODE_Y2 = 2,
998 LD4U_UNARY_OPCODE_X1 = 20,
999 LDNA_ADD_IMM8_OPCODE_X1 = 21,
1000 LDNA_UNARY_OPCODE_X1 = 21,
1001 LDNT1S_ADD_IMM8_OPCODE_X1 = 13,
1002 LDNT1S_UNARY_OPCODE_X1 = 22,
1003 LDNT1U_ADD_IMM8_OPCODE_X1 = 14,
1004 LDNT1U_UNARY_OPCODE_X1 = 23,
1005 LDNT2S_ADD_IMM8_OPCODE_X1 = 15,
1006 LDNT2S_UNARY_OPCODE_X1 = 24,
1007 LDNT2U_ADD_IMM8_OPCODE_X1 = 16,
1008 LDNT2U_UNARY_OPCODE_X1 = 25,
1009 LDNT4S_ADD_IMM8_OPCODE_X1 = 17,
1010 LDNT4S_UNARY_OPCODE_X1 = 26,
1011 LDNT4U_ADD_IMM8_OPCODE_X1 = 18,
1012 LDNT4U_UNARY_OPCODE_X1 = 27,
1013 LDNT_ADD_IMM8_OPCODE_X1 = 19,
1014 LDNT_UNARY_OPCODE_X1 = 28,
1015 LD_ADD_IMM8_OPCODE_X1 = 20,
1016 LD_OPCODE_Y2 = 3,
1017 LD_UNARY_OPCODE_X1 = 29,
1018 LNK_UNARY_OPCODE_X1 = 30,
1019 LNK_UNARY_OPCODE_Y1 = 14,
1020 MFSPR_IMM8_OPCODE_X1 = 22,
1021 MF_UNARY_OPCODE_X1 = 31,
1022 MM_BF_OPCODE_X0 = 7,
1023 MNZ_RRR_0_OPCODE_X0 = 40,
1024 MNZ_RRR_0_OPCODE_X1 = 26,
1025 MNZ_RRR_4_OPCODE_Y0 = 2,
1026 MNZ_RRR_4_OPCODE_Y1 = 2,
1027 MODE_OPCODE_YA2 = 1,
1028 MODE_OPCODE_YB2 = 2,
1029 MODE_OPCODE_YC2 = 3,
1030 MTSPR_IMM8_OPCODE_X1 = 23,
1031 MULAX_RRR_0_OPCODE_X0 = 41,
1032 MULAX_RRR_3_OPCODE_Y0 = 2,
1033 MULA_HS_HS_RRR_0_OPCODE_X0 = 42,
1034 MULA_HS_HS_RRR_9_OPCODE_Y0 = 0,
1035 MULA_HS_HU_RRR_0_OPCODE_X0 = 43,
1036 MULA_HS_LS_RRR_0_OPCODE_X0 = 44,
1037 MULA_HS_LU_RRR_0_OPCODE_X0 = 45,
1038 MULA_HU_HU_RRR_0_OPCODE_X0 = 46,
1039 MULA_HU_HU_RRR_9_OPCODE_Y0 = 1,
1040 MULA_HU_LS_RRR_0_OPCODE_X0 = 47,
1041 MULA_HU_LU_RRR_0_OPCODE_X0 = 48,
1042 MULA_LS_LS_RRR_0_OPCODE_X0 = 49,
1043 MULA_LS_LS_RRR_9_OPCODE_Y0 = 2,
1044 MULA_LS_LU_RRR_0_OPCODE_X0 = 50,
1045 MULA_LU_LU_RRR_0_OPCODE_X0 = 51,
1046 MULA_LU_LU_RRR_9_OPCODE_Y0 = 3,
1047 MULX_RRR_0_OPCODE_X0 = 52,
1048 MULX_RRR_3_OPCODE_Y0 = 3,
1049 MUL_HS_HS_RRR_0_OPCODE_X0 = 53,
1050 MUL_HS_HS_RRR_8_OPCODE_Y0 = 0,
1051 MUL_HS_HU_RRR_0_OPCODE_X0 = 54,
1052 MUL_HS_LS_RRR_0_OPCODE_X0 = 55,
1053 MUL_HS_LU_RRR_0_OPCODE_X0 = 56,
1054 MUL_HU_HU_RRR_0_OPCODE_X0 = 57,
1055 MUL_HU_HU_RRR_8_OPCODE_Y0 = 1,
1056 MUL_HU_LS_RRR_0_OPCODE_X0 = 58,
1057 MUL_HU_LU_RRR_0_OPCODE_X0 = 59,
1058 MUL_LS_LS_RRR_0_OPCODE_X0 = 60,
1059 MUL_LS_LS_RRR_8_OPCODE_Y0 = 2,
1060 MUL_LS_LU_RRR_0_OPCODE_X0 = 61,
1061 MUL_LU_LU_RRR_0_OPCODE_X0 = 62,
1062 MUL_LU_LU_RRR_8_OPCODE_Y0 = 3,
1063 MZ_RRR_0_OPCODE_X0 = 63,
1064 MZ_RRR_0_OPCODE_X1 = 27,
1065 MZ_RRR_4_OPCODE_Y0 = 3,
1066 MZ_RRR_4_OPCODE_Y1 = 3,
1067 NAP_UNARY_OPCODE_X1 = 32,
1068 NOP_UNARY_OPCODE_X0 = 5,
1069 NOP_UNARY_OPCODE_X1 = 33,
1070 NOP_UNARY_OPCODE_Y0 = 5,
1071 NOP_UNARY_OPCODE_Y1 = 15,
1072 NOR_RRR_0_OPCODE_X0 = 64,
1073 NOR_RRR_0_OPCODE_X1 = 28,
1074 NOR_RRR_5_OPCODE_Y0 = 1,
1075 NOR_RRR_5_OPCODE_Y1 = 1,
1076 ORI_IMM8_OPCODE_X0 = 7,
1077 ORI_IMM8_OPCODE_X1 = 24,
1078 OR_RRR_0_OPCODE_X0 = 65,
1079 OR_RRR_0_OPCODE_X1 = 29,
1080 OR_RRR_5_OPCODE_Y0 = 2,
1081 OR_RRR_5_OPCODE_Y1 = 2,
1082 PCNT_UNARY_OPCODE_X0 = 6,
1083 PCNT_UNARY_OPCODE_Y0 = 6,
1084 REVBITS_UNARY_OPCODE_X0 = 7,
1085 REVBITS_UNARY_OPCODE_Y0 = 7,
1086 REVBYTES_UNARY_OPCODE_X0 = 8,
1087 REVBYTES_UNARY_OPCODE_Y0 = 8,
1088 ROTLI_SHIFT_OPCODE_X0 = 1,
1089 ROTLI_SHIFT_OPCODE_X1 = 1,
1090 ROTLI_SHIFT_OPCODE_Y0 = 0,
1091 ROTLI_SHIFT_OPCODE_Y1 = 0,
1092 ROTL_RRR_0_OPCODE_X0 = 66,
1093 ROTL_RRR_0_OPCODE_X1 = 30,
1094 ROTL_RRR_6_OPCODE_Y0 = 0,
1095 ROTL_RRR_6_OPCODE_Y1 = 0,
1096 RRR_0_OPCODE_X0 = 5,
1097 RRR_0_OPCODE_X1 = 5,
1098 RRR_0_OPCODE_Y0 = 5,
1099 RRR_0_OPCODE_Y1 = 6,
1100 RRR_1_OPCODE_Y0 = 6,
1101 RRR_1_OPCODE_Y1 = 7,
1102 RRR_2_OPCODE_Y0 = 7,
1103 RRR_2_OPCODE_Y1 = 8,
1104 RRR_3_OPCODE_Y0 = 8,
1105 RRR_3_OPCODE_Y1 = 9,
1106 RRR_4_OPCODE_Y0 = 9,
1107 RRR_4_OPCODE_Y1 = 10,
1108 RRR_5_OPCODE_Y0 = 10,
1109 RRR_5_OPCODE_Y1 = 11,
1110 RRR_6_OPCODE_Y0 = 11,
1111 RRR_6_OPCODE_Y1 = 12,
1112 RRR_7_OPCODE_Y0 = 12,
1113 RRR_7_OPCODE_Y1 = 13,
1114 RRR_8_OPCODE_Y0 = 13,
1115 RRR_9_OPCODE_Y0 = 14,
1116 SHIFT_OPCODE_X0 = 6,
1117 SHIFT_OPCODE_X1 = 6,
1118 SHIFT_OPCODE_Y0 = 15,
1119 SHIFT_OPCODE_Y1 = 14,
1120 SHL16INSLI_OPCODE_X0 = 7,
1121 SHL16INSLI_OPCODE_X1 = 7,
1122 SHL1ADDX_RRR_0_OPCODE_X0 = 67,
1123 SHL1ADDX_RRR_0_OPCODE_X1 = 31,
1124 SHL1ADDX_RRR_7_OPCODE_Y0 = 1,
1125 SHL1ADDX_RRR_7_OPCODE_Y1 = 1,
1126 SHL1ADD_RRR_0_OPCODE_X0 = 68,
1127 SHL1ADD_RRR_0_OPCODE_X1 = 32,
1128 SHL1ADD_RRR_1_OPCODE_Y0 = 0,
1129 SHL1ADD_RRR_1_OPCODE_Y1 = 0,
1130 SHL2ADDX_RRR_0_OPCODE_X0 = 69,
1131 SHL2ADDX_RRR_0_OPCODE_X1 = 33,
1132 SHL2ADDX_RRR_7_OPCODE_Y0 = 2,
1133 SHL2ADDX_RRR_7_OPCODE_Y1 = 2,
1134 SHL2ADD_RRR_0_OPCODE_X0 = 70,
1135 SHL2ADD_RRR_0_OPCODE_X1 = 34,
1136 SHL2ADD_RRR_1_OPCODE_Y0 = 1,
1137 SHL2ADD_RRR_1_OPCODE_Y1 = 1,
1138 SHL3ADDX_RRR_0_OPCODE_X0 = 71,
1139 SHL3ADDX_RRR_0_OPCODE_X1 = 35,
1140 SHL3ADDX_RRR_7_OPCODE_Y0 = 3,
1141 SHL3ADDX_RRR_7_OPCODE_Y1 = 3,
1142 SHL3ADD_RRR_0_OPCODE_X0 = 72,
1143 SHL3ADD_RRR_0_OPCODE_X1 = 36,
1144 SHL3ADD_RRR_1_OPCODE_Y0 = 2,
1145 SHL3ADD_RRR_1_OPCODE_Y1 = 2,
1146 SHLI_SHIFT_OPCODE_X0 = 2,
1147 SHLI_SHIFT_OPCODE_X1 = 2,
1148 SHLI_SHIFT_OPCODE_Y0 = 1,
1149 SHLI_SHIFT_OPCODE_Y1 = 1,
1150 SHLXI_SHIFT_OPCODE_X0 = 3,
1151 SHLXI_SHIFT_OPCODE_X1 = 3,
1152 SHLX_RRR_0_OPCODE_X0 = 73,
1153 SHLX_RRR_0_OPCODE_X1 = 37,
1154 SHL_RRR_0_OPCODE_X0 = 74,
1155 SHL_RRR_0_OPCODE_X1 = 38,
1156 SHL_RRR_6_OPCODE_Y0 = 1,
1157 SHL_RRR_6_OPCODE_Y1 = 1,
1158 SHRSI_SHIFT_OPCODE_X0 = 4,
1159 SHRSI_SHIFT_OPCODE_X1 = 4,
1160 SHRSI_SHIFT_OPCODE_Y0 = 2,
1161 SHRSI_SHIFT_OPCODE_Y1 = 2,
1162 SHRS_RRR_0_OPCODE_X0 = 75,
1163 SHRS_RRR_0_OPCODE_X1 = 39,
1164 SHRS_RRR_6_OPCODE_Y0 = 2,
1165 SHRS_RRR_6_OPCODE_Y1 = 2,
1166 SHRUI_SHIFT_OPCODE_X0 = 5,
1167 SHRUI_SHIFT_OPCODE_X1 = 5,
1168 SHRUI_SHIFT_OPCODE_Y0 = 3,
1169 SHRUI_SHIFT_OPCODE_Y1 = 3,
1170 SHRUXI_SHIFT_OPCODE_X0 = 6,
1171 SHRUXI_SHIFT_OPCODE_X1 = 6,
1172 SHRUX_RRR_0_OPCODE_X0 = 76,
1173 SHRUX_RRR_0_OPCODE_X1 = 40,
1174 SHRU_RRR_0_OPCODE_X0 = 77,
1175 SHRU_RRR_0_OPCODE_X1 = 41,
1176 SHRU_RRR_6_OPCODE_Y0 = 3,
1177 SHRU_RRR_6_OPCODE_Y1 = 3,
1178 SHUFFLEBYTES_RRR_0_OPCODE_X0 = 78,
1179 ST1_ADD_IMM8_OPCODE_X1 = 25,
1180 ST1_OPCODE_Y2 = 0,
1181 ST1_RRR_0_OPCODE_X1 = 42,
1182 ST2_ADD_IMM8_OPCODE_X1 = 26,
1183 ST2_OPCODE_Y2 = 1,
1184 ST2_RRR_0_OPCODE_X1 = 43,
1185 ST4_ADD_IMM8_OPCODE_X1 = 27,
1186 ST4_OPCODE_Y2 = 2,
1187 ST4_RRR_0_OPCODE_X1 = 44,
1188 STNT1_ADD_IMM8_OPCODE_X1 = 28,
1189 STNT1_RRR_0_OPCODE_X1 = 45,
1190 STNT2_ADD_IMM8_OPCODE_X1 = 29,
1191 STNT2_RRR_0_OPCODE_X1 = 46,
1192 STNT4_ADD_IMM8_OPCODE_X1 = 30,
1193 STNT4_RRR_0_OPCODE_X1 = 47,
1194 STNT_ADD_IMM8_OPCODE_X1 = 31,
1195 STNT_RRR_0_OPCODE_X1 = 48,
1196 ST_ADD_IMM8_OPCODE_X1 = 32,
1197 ST_OPCODE_Y2 = 3,
1198 ST_RRR_0_OPCODE_X1 = 49,
1199 SUBXSC_RRR_0_OPCODE_X0 = 79,
1200 SUBXSC_RRR_0_OPCODE_X1 = 50,
1201 SUBX_RRR_0_OPCODE_X0 = 80,
1202 SUBX_RRR_0_OPCODE_X1 = 51,
1203 SUBX_RRR_0_OPCODE_Y0 = 2,
1204 SUBX_RRR_0_OPCODE_Y1 = 2,
1205 SUB_RRR_0_OPCODE_X0 = 81,
1206 SUB_RRR_0_OPCODE_X1 = 52,
1207 SUB_RRR_0_OPCODE_Y0 = 3,
1208 SUB_RRR_0_OPCODE_Y1 = 3,
1209 SWINT0_UNARY_OPCODE_X1 = 34,
1210 SWINT1_UNARY_OPCODE_X1 = 35,
1211 SWINT2_UNARY_OPCODE_X1 = 36,
1212 SWINT3_UNARY_OPCODE_X1 = 37,
1213 TBLIDXB0_UNARY_OPCODE_X0 = 9,
1214 TBLIDXB0_UNARY_OPCODE_Y0 = 9,
1215 TBLIDXB1_UNARY_OPCODE_X0 = 10,
1216 TBLIDXB1_UNARY_OPCODE_Y0 = 10,
1217 TBLIDXB2_UNARY_OPCODE_X0 = 11,
1218 TBLIDXB2_UNARY_OPCODE_Y0 = 11,
1219 TBLIDXB3_UNARY_OPCODE_X0 = 12,
1220 TBLIDXB3_UNARY_OPCODE_Y0 = 12,
1221 UNARY_RRR_0_OPCODE_X0 = 82,
1222 UNARY_RRR_0_OPCODE_X1 = 53,
1223 UNARY_RRR_1_OPCODE_Y0 = 3,
1224 UNARY_RRR_1_OPCODE_Y1 = 3,
1225 V1ADDI_IMM8_OPCODE_X0 = 8,
1226 V1ADDI_IMM8_OPCODE_X1 = 33,
1227 V1ADDUC_RRR_0_OPCODE_X0 = 83,
1228 V1ADDUC_RRR_0_OPCODE_X1 = 54,
1229 V1ADD_RRR_0_OPCODE_X0 = 84,
1230 V1ADD_RRR_0_OPCODE_X1 = 55,
1231 V1ADIFFU_RRR_0_OPCODE_X0 = 85,
1232 V1AVGU_RRR_0_OPCODE_X0 = 86,
1233 V1CMPEQI_IMM8_OPCODE_X0 = 9,
1234 V1CMPEQI_IMM8_OPCODE_X1 = 34,
1235 V1CMPEQ_RRR_0_OPCODE_X0 = 87,
1236 V1CMPEQ_RRR_0_OPCODE_X1 = 56,
1237 V1CMPLES_RRR_0_OPCODE_X0 = 88,
1238 V1CMPLES_RRR_0_OPCODE_X1 = 57,
1239 V1CMPLEU_RRR_0_OPCODE_X0 = 89,
1240 V1CMPLEU_RRR_0_OPCODE_X1 = 58,
1241 V1CMPLTSI_IMM8_OPCODE_X0 = 10,
1242 V1CMPLTSI_IMM8_OPCODE_X1 = 35,
1243 V1CMPLTS_RRR_0_OPCODE_X0 = 90,
1244 V1CMPLTS_RRR_0_OPCODE_X1 = 59,
1245 V1CMPLTUI_IMM8_OPCODE_X0 = 11,
1246 V1CMPLTUI_IMM8_OPCODE_X1 = 36,
1247 V1CMPLTU_RRR_0_OPCODE_X0 = 91,
1248 V1CMPLTU_RRR_0_OPCODE_X1 = 60,
1249 V1CMPNE_RRR_0_OPCODE_X0 = 92,
1250 V1CMPNE_RRR_0_OPCODE_X1 = 61,
1251 V1DDOTPUA_RRR_0_OPCODE_X0 = 161,
1252 V1DDOTPUSA_RRR_0_OPCODE_X0 = 93,
1253 V1DDOTPUS_RRR_0_OPCODE_X0 = 94,
1254 V1DDOTPU_RRR_0_OPCODE_X0 = 162,
1255 V1DOTPA_RRR_0_OPCODE_X0 = 95,
1256 V1DOTPUA_RRR_0_OPCODE_X0 = 163,
1257 V1DOTPUSA_RRR_0_OPCODE_X0 = 96,
1258 V1DOTPUS_RRR_0_OPCODE_X0 = 97,
1259 V1DOTPU_RRR_0_OPCODE_X0 = 164,
1260 V1DOTP_RRR_0_OPCODE_X0 = 98,
1261 V1INT_H_RRR_0_OPCODE_X0 = 99,
1262 V1INT_H_RRR_0_OPCODE_X1 = 62,
1263 V1INT_L_RRR_0_OPCODE_X0 = 100,
1264 V1INT_L_RRR_0_OPCODE_X1 = 63,
1265 V1MAXUI_IMM8_OPCODE_X0 = 12,
1266 V1MAXUI_IMM8_OPCODE_X1 = 37,
1267 V1MAXU_RRR_0_OPCODE_X0 = 101,
1268 V1MAXU_RRR_0_OPCODE_X1 = 64,
1269 V1MINUI_IMM8_OPCODE_X0 = 13,
1270 V1MINUI_IMM8_OPCODE_X1 = 38,
1271 V1MINU_RRR_0_OPCODE_X0 = 102,
1272 V1MINU_RRR_0_OPCODE_X1 = 65,
1273 V1MNZ_RRR_0_OPCODE_X0 = 103,
1274 V1MNZ_RRR_0_OPCODE_X1 = 66,
1275 V1MULTU_RRR_0_OPCODE_X0 = 104,
1276 V1MULUS_RRR_0_OPCODE_X0 = 105,
1277 V1MULU_RRR_0_OPCODE_X0 = 106,
1278 V1MZ_RRR_0_OPCODE_X0 = 107,
1279 V1MZ_RRR_0_OPCODE_X1 = 67,
1280 V1SADAU_RRR_0_OPCODE_X0 = 108,
1281 V1SADU_RRR_0_OPCODE_X0 = 109,
1282 V1SHLI_SHIFT_OPCODE_X0 = 7,
1283 V1SHLI_SHIFT_OPCODE_X1 = 7,
1284 V1SHL_RRR_0_OPCODE_X0 = 110,
1285 V1SHL_RRR_0_OPCODE_X1 = 68,
1286 V1SHRSI_SHIFT_OPCODE_X0 = 8,
1287 V1SHRSI_SHIFT_OPCODE_X1 = 8,
1288 V1SHRS_RRR_0_OPCODE_X0 = 111,
1289 V1SHRS_RRR_0_OPCODE_X1 = 69,
1290 V1SHRUI_SHIFT_OPCODE_X0 = 9,
1291 V1SHRUI_SHIFT_OPCODE_X1 = 9,
1292 V1SHRU_RRR_0_OPCODE_X0 = 112,
1293 V1SHRU_RRR_0_OPCODE_X1 = 70,
1294 V1SUBUC_RRR_0_OPCODE_X0 = 113,
1295 V1SUBUC_RRR_0_OPCODE_X1 = 71,
1296 V1SUB_RRR_0_OPCODE_X0 = 114,
1297 V1SUB_RRR_0_OPCODE_X1 = 72,
1298 V2ADDI_IMM8_OPCODE_X0 = 14,
1299 V2ADDI_IMM8_OPCODE_X1 = 39,
1300 V2ADDSC_RRR_0_OPCODE_X0 = 115,
1301 V2ADDSC_RRR_0_OPCODE_X1 = 73,
1302 V2ADD_RRR_0_OPCODE_X0 = 116,
1303 V2ADD_RRR_0_OPCODE_X1 = 74,
1304 V2ADIFFS_RRR_0_OPCODE_X0 = 117,
1305 V2AVGS_RRR_0_OPCODE_X0 = 118,
1306 V2CMPEQI_IMM8_OPCODE_X0 = 15,
1307 V2CMPEQI_IMM8_OPCODE_X1 = 40,
1308 V2CMPEQ_RRR_0_OPCODE_X0 = 119,
1309 V2CMPEQ_RRR_0_OPCODE_X1 = 75,
1310 V2CMPLES_RRR_0_OPCODE_X0 = 120,
1311 V2CMPLES_RRR_0_OPCODE_X1 = 76,
1312 V2CMPLEU_RRR_0_OPCODE_X0 = 121,
1313 V2CMPLEU_RRR_0_OPCODE_X1 = 77,
1314 V2CMPLTSI_IMM8_OPCODE_X0 = 16,
1315 V2CMPLTSI_IMM8_OPCODE_X1 = 41,
1316 V2CMPLTS_RRR_0_OPCODE_X0 = 122,
1317 V2CMPLTS_RRR_0_OPCODE_X1 = 78,
1318 V2CMPLTUI_IMM8_OPCODE_X0 = 17,
1319 V2CMPLTUI_IMM8_OPCODE_X1 = 42,
1320 V2CMPLTU_RRR_0_OPCODE_X0 = 123,
1321 V2CMPLTU_RRR_0_OPCODE_X1 = 79,
1322 V2CMPNE_RRR_0_OPCODE_X0 = 124,
1323 V2CMPNE_RRR_0_OPCODE_X1 = 80,
1324 V2DOTPA_RRR_0_OPCODE_X0 = 125,
1325 V2DOTP_RRR_0_OPCODE_X0 = 126,
1326 V2INT_H_RRR_0_OPCODE_X0 = 127,
1327 V2INT_H_RRR_0_OPCODE_X1 = 81,
1328 V2INT_L_RRR_0_OPCODE_X0 = 128,
1329 V2INT_L_RRR_0_OPCODE_X1 = 82,
1330 V2MAXSI_IMM8_OPCODE_X0 = 18,
1331 V2MAXSI_IMM8_OPCODE_X1 = 43,
1332 V2MAXS_RRR_0_OPCODE_X0 = 129,
1333 V2MAXS_RRR_0_OPCODE_X1 = 83,
1334 V2MINSI_IMM8_OPCODE_X0 = 19,
1335 V2MINSI_IMM8_OPCODE_X1 = 44,
1336 V2MINS_RRR_0_OPCODE_X0 = 130,
1337 V2MINS_RRR_0_OPCODE_X1 = 84,
1338 V2MNZ_RRR_0_OPCODE_X0 = 131,
1339 V2MNZ_RRR_0_OPCODE_X1 = 85,
1340 V2MULFSC_RRR_0_OPCODE_X0 = 132,
1341 V2MULS_RRR_0_OPCODE_X0 = 133,
1342 V2MULTS_RRR_0_OPCODE_X0 = 134,
1343 V2MZ_RRR_0_OPCODE_X0 = 135,
1344 V2MZ_RRR_0_OPCODE_X1 = 86,
1345 V2PACKH_RRR_0_OPCODE_X0 = 136,
1346 V2PACKH_RRR_0_OPCODE_X1 = 87,
1347 V2PACKL_RRR_0_OPCODE_X0 = 137,
1348 V2PACKL_RRR_0_OPCODE_X1 = 88,
1349 V2PACKUC_RRR_0_OPCODE_X0 = 138,
1350 V2PACKUC_RRR_0_OPCODE_X1 = 89,
1351 V2SADAS_RRR_0_OPCODE_X0 = 139,
1352 V2SADAU_RRR_0_OPCODE_X0 = 140,
1353 V2SADS_RRR_0_OPCODE_X0 = 141,
1354 V2SADU_RRR_0_OPCODE_X0 = 142,
1355 V2SHLI_SHIFT_OPCODE_X0 = 10,
1356 V2SHLI_SHIFT_OPCODE_X1 = 10,
1357 V2SHLSC_RRR_0_OPCODE_X0 = 143,
1358 V2SHLSC_RRR_0_OPCODE_X1 = 90,
1359 V2SHL_RRR_0_OPCODE_X0 = 144,
1360 V2SHL_RRR_0_OPCODE_X1 = 91,
1361 V2SHRSI_SHIFT_OPCODE_X0 = 11,
1362 V2SHRSI_SHIFT_OPCODE_X1 = 11,
1363 V2SHRS_RRR_0_OPCODE_X0 = 145,
1364 V2SHRS_RRR_0_OPCODE_X1 = 92,
1365 V2SHRUI_SHIFT_OPCODE_X0 = 12,
1366 V2SHRUI_SHIFT_OPCODE_X1 = 12,
1367 V2SHRU_RRR_0_OPCODE_X0 = 146,
1368 V2SHRU_RRR_0_OPCODE_X1 = 93,
1369 V2SUBSC_RRR_0_OPCODE_X0 = 147,
1370 V2SUBSC_RRR_0_OPCODE_X1 = 94,
1371 V2SUB_RRR_0_OPCODE_X0 = 148,
1372 V2SUB_RRR_0_OPCODE_X1 = 95,
1373 V4ADDSC_RRR_0_OPCODE_X0 = 149,
1374 V4ADDSC_RRR_0_OPCODE_X1 = 96,
1375 V4ADD_RRR_0_OPCODE_X0 = 150,
1376 V4ADD_RRR_0_OPCODE_X1 = 97,
1377 V4INT_H_RRR_0_OPCODE_X0 = 151,
1378 V4INT_H_RRR_0_OPCODE_X1 = 98,
1379 V4INT_L_RRR_0_OPCODE_X0 = 152,
1380 V4INT_L_RRR_0_OPCODE_X1 = 99,
1381 V4PACKSC_RRR_0_OPCODE_X0 = 153,
1382 V4PACKSC_RRR_0_OPCODE_X1 = 100,
1383 V4SHLSC_RRR_0_OPCODE_X0 = 154,
1384 V4SHLSC_RRR_0_OPCODE_X1 = 101,
1385 V4SHL_RRR_0_OPCODE_X0 = 155,
1386 V4SHL_RRR_0_OPCODE_X1 = 102,
1387 V4SHRS_RRR_0_OPCODE_X0 = 156,
1388 V4SHRS_RRR_0_OPCODE_X1 = 103,
1389 V4SHRU_RRR_0_OPCODE_X0 = 157,
1390 V4SHRU_RRR_0_OPCODE_X1 = 104,
1391 V4SUBSC_RRR_0_OPCODE_X0 = 158,
1392 V4SUBSC_RRR_0_OPCODE_X1 = 105,
1393 V4SUB_RRR_0_OPCODE_X0 = 159,
1394 V4SUB_RRR_0_OPCODE_X1 = 106,
1395 WH64_UNARY_OPCODE_X1 = 38,
1396 XORI_IMM8_OPCODE_X0 = 20,
1397 XORI_IMM8_OPCODE_X1 = 45,
1398 XOR_RRR_0_OPCODE_X0 = 160,
1399 XOR_RRR_0_OPCODE_X1 = 107,
1400 XOR_RRR_5_OPCODE_Y0 = 3,
1401 XOR_RRR_5_OPCODE_Y1 = 3
1402};
1403
1404
1405#endif /* __ASSEMBLER__ */
1406
1407#endif /* __ARCH_OPCODE_H__ */
diff --git a/arch/tile/include/uapi/arch/opcode_tilepro.h b/arch/tile/include/uapi/arch/opcode_tilepro.h
deleted file mode 100644
index 0d633688de63..000000000000
--- a/arch/tile/include/uapi/arch/opcode_tilepro.h
+++ /dev/null
@@ -1,1473 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/* TILEPro opcode information.
3 *
4 * Copyright 2011 Tilera Corporation. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for
14 * more details.
15 *
16 *
17 *
18 *
19 *
20 */
21
22#ifndef __ARCH_OPCODE_H__
23#define __ARCH_OPCODE_H__
24
25#ifndef __ASSEMBLER__
26
27typedef unsigned long long tilepro_bundle_bits;
28
29/* This is the bit that determines if a bundle is in the Y encoding. */
30#define TILEPRO_BUNDLE_Y_ENCODING_MASK ((tilepro_bundle_bits)1 << 63)
31
32enum
33{
34 /* Maximum number of instructions in a bundle (2 for X, 3 for Y). */
35 TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE = 3,
36
37 /* How many different pipeline encodings are there? X0, X1, Y0, Y1, Y2. */
38 TILEPRO_NUM_PIPELINE_ENCODINGS = 5,
39
40 /* Log base 2 of TILEPRO_BUNDLE_SIZE_IN_BYTES. */
41 TILEPRO_LOG2_BUNDLE_SIZE_IN_BYTES = 3,
42
43 /* Instructions take this many bytes. */
44 TILEPRO_BUNDLE_SIZE_IN_BYTES = 1 << TILEPRO_LOG2_BUNDLE_SIZE_IN_BYTES,
45
46 /* Log base 2 of TILEPRO_BUNDLE_ALIGNMENT_IN_BYTES. */
47 TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES = 3,
48
49 /* Bundles should be aligned modulo this number of bytes. */
50 TILEPRO_BUNDLE_ALIGNMENT_IN_BYTES =
51 (1 << TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES),
52
53 /* Log base 2 of TILEPRO_SN_INSTRUCTION_SIZE_IN_BYTES. */
54 TILEPRO_LOG2_SN_INSTRUCTION_SIZE_IN_BYTES = 1,
55
56 /* Static network instructions take this many bytes. */
57 TILEPRO_SN_INSTRUCTION_SIZE_IN_BYTES =
58 (1 << TILEPRO_LOG2_SN_INSTRUCTION_SIZE_IN_BYTES),
59
60 /* Number of registers (some are magic, such as network I/O). */
61 TILEPRO_NUM_REGISTERS = 64,
62
63 /* Number of static network registers. */
64 TILEPRO_NUM_SN_REGISTERS = 4
65};
66
67/* Make a few "tile_" variables to simplify common code between
68 architectures. */
69
70typedef tilepro_bundle_bits tile_bundle_bits;
71#define TILE_BUNDLE_SIZE_IN_BYTES TILEPRO_BUNDLE_SIZE_IN_BYTES
72#define TILE_BUNDLE_ALIGNMENT_IN_BYTES TILEPRO_BUNDLE_ALIGNMENT_IN_BYTES
73#define TILE_LOG2_BUNDLE_ALIGNMENT_IN_BYTES \
74 TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES
75#define TILE_BPT_BUNDLE TILEPRO_BPT_BUNDLE
76
77/* 64-bit pattern for a { bpt ; nop } bundle. */
78#define TILEPRO_BPT_BUNDLE 0x400b3cae70166000ULL
79
80static __inline unsigned int
81get_BrOff_SN(tilepro_bundle_bits num)
82{
83 const unsigned int n = (unsigned int)num;
84 return (((n >> 0)) & 0x3ff);
85}
86
87static __inline unsigned int
88get_BrOff_X1(tilepro_bundle_bits n)
89{
90 return (((unsigned int)(n >> 43)) & 0x00007fff) |
91 (((unsigned int)(n >> 20)) & 0x00018000);
92}
93
94static __inline unsigned int
95get_BrType_X1(tilepro_bundle_bits n)
96{
97 return (((unsigned int)(n >> 31)) & 0xf);
98}
99
100static __inline unsigned int
101get_Dest_Imm8_X1(tilepro_bundle_bits n)
102{
103 return (((unsigned int)(n >> 31)) & 0x0000003f) |
104 (((unsigned int)(n >> 43)) & 0x000000c0);
105}
106
107static __inline unsigned int
108get_Dest_SN(tilepro_bundle_bits num)
109{
110 const unsigned int n = (unsigned int)num;
111 return (((n >> 2)) & 0x3);
112}
113
114static __inline unsigned int
115get_Dest_X0(tilepro_bundle_bits num)
116{
117 const unsigned int n = (unsigned int)num;
118 return (((n >> 0)) & 0x3f);
119}
120
121static __inline unsigned int
122get_Dest_X1(tilepro_bundle_bits n)
123{
124 return (((unsigned int)(n >> 31)) & 0x3f);
125}
126
127static __inline unsigned int
128get_Dest_Y0(tilepro_bundle_bits num)
129{
130 const unsigned int n = (unsigned int)num;
131 return (((n >> 0)) & 0x3f);
132}
133
134static __inline unsigned int
135get_Dest_Y1(tilepro_bundle_bits n)
136{
137 return (((unsigned int)(n >> 31)) & 0x3f);
138}
139
140static __inline unsigned int
141get_Imm16_X0(tilepro_bundle_bits num)
142{
143 const unsigned int n = (unsigned int)num;
144 return (((n >> 12)) & 0xffff);
145}
146
147static __inline unsigned int
148get_Imm16_X1(tilepro_bundle_bits n)
149{
150 return (((unsigned int)(n >> 43)) & 0xffff);
151}
152
153static __inline unsigned int
154get_Imm8_SN(tilepro_bundle_bits num)
155{
156 const unsigned int n = (unsigned int)num;
157 return (((n >> 0)) & 0xff);
158}
159
160static __inline unsigned int
161get_Imm8_X0(tilepro_bundle_bits num)
162{
163 const unsigned int n = (unsigned int)num;
164 return (((n >> 12)) & 0xff);
165}
166
167static __inline unsigned int
168get_Imm8_X1(tilepro_bundle_bits n)
169{
170 return (((unsigned int)(n >> 43)) & 0xff);
171}
172
173static __inline unsigned int
174get_Imm8_Y0(tilepro_bundle_bits num)
175{
176 const unsigned int n = (unsigned int)num;
177 return (((n >> 12)) & 0xff);
178}
179
180static __inline unsigned int
181get_Imm8_Y1(tilepro_bundle_bits n)
182{
183 return (((unsigned int)(n >> 43)) & 0xff);
184}
185
186static __inline unsigned int
187get_ImmOpcodeExtension_X0(tilepro_bundle_bits num)
188{
189 const unsigned int n = (unsigned int)num;
190 return (((n >> 20)) & 0x7f);
191}
192
193static __inline unsigned int
194get_ImmOpcodeExtension_X1(tilepro_bundle_bits n)
195{
196 return (((unsigned int)(n >> 51)) & 0x7f);
197}
198
199static __inline unsigned int
200get_ImmRROpcodeExtension_SN(tilepro_bundle_bits num)
201{
202 const unsigned int n = (unsigned int)num;
203 return (((n >> 8)) & 0x3);
204}
205
206static __inline unsigned int
207get_JOffLong_X1(tilepro_bundle_bits n)
208{
209 return (((unsigned int)(n >> 43)) & 0x00007fff) |
210 (((unsigned int)(n >> 20)) & 0x00018000) |
211 (((unsigned int)(n >> 14)) & 0x001e0000) |
212 (((unsigned int)(n >> 16)) & 0x07e00000) |
213 (((unsigned int)(n >> 31)) & 0x18000000);
214}
215
216static __inline unsigned int
217get_JOff_X1(tilepro_bundle_bits n)
218{
219 return (((unsigned int)(n >> 43)) & 0x00007fff) |
220 (((unsigned int)(n >> 20)) & 0x00018000) |
221 (((unsigned int)(n >> 14)) & 0x001e0000) |
222 (((unsigned int)(n >> 16)) & 0x07e00000) |
223 (((unsigned int)(n >> 31)) & 0x08000000);
224}
225
226static __inline unsigned int
227get_MF_Imm15_X1(tilepro_bundle_bits n)
228{
229 return (((unsigned int)(n >> 37)) & 0x00003fff) |
230 (((unsigned int)(n >> 44)) & 0x00004000);
231}
232
233static __inline unsigned int
234get_MMEnd_X0(tilepro_bundle_bits num)
235{
236 const unsigned int n = (unsigned int)num;
237 return (((n >> 18)) & 0x1f);
238}
239
240static __inline unsigned int
241get_MMEnd_X1(tilepro_bundle_bits n)
242{
243 return (((unsigned int)(n >> 49)) & 0x1f);
244}
245
246static __inline unsigned int
247get_MMStart_X0(tilepro_bundle_bits num)
248{
249 const unsigned int n = (unsigned int)num;
250 return (((n >> 23)) & 0x1f);
251}
252
253static __inline unsigned int
254get_MMStart_X1(tilepro_bundle_bits n)
255{
256 return (((unsigned int)(n >> 54)) & 0x1f);
257}
258
259static __inline unsigned int
260get_MT_Imm15_X1(tilepro_bundle_bits n)
261{
262 return (((unsigned int)(n >> 31)) & 0x0000003f) |
263 (((unsigned int)(n >> 37)) & 0x00003fc0) |
264 (((unsigned int)(n >> 44)) & 0x00004000);
265}
266
267static __inline unsigned int
268get_Mode(tilepro_bundle_bits n)
269{
270 return (((unsigned int)(n >> 63)) & 0x1);
271}
272
273static __inline unsigned int
274get_NoRegOpcodeExtension_SN(tilepro_bundle_bits num)
275{
276 const unsigned int n = (unsigned int)num;
277 return (((n >> 0)) & 0xf);
278}
279
280static __inline unsigned int
281get_Opcode_SN(tilepro_bundle_bits num)
282{
283 const unsigned int n = (unsigned int)num;
284 return (((n >> 10)) & 0x3f);
285}
286
287static __inline unsigned int
288get_Opcode_X0(tilepro_bundle_bits num)
289{
290 const unsigned int n = (unsigned int)num;
291 return (((n >> 28)) & 0x7);
292}
293
294static __inline unsigned int
295get_Opcode_X1(tilepro_bundle_bits n)
296{
297 return (((unsigned int)(n >> 59)) & 0xf);
298}
299
300static __inline unsigned int
301get_Opcode_Y0(tilepro_bundle_bits num)
302{
303 const unsigned int n = (unsigned int)num;
304 return (((n >> 27)) & 0xf);
305}
306
307static __inline unsigned int
308get_Opcode_Y1(tilepro_bundle_bits n)
309{
310 return (((unsigned int)(n >> 59)) & 0xf);
311}
312
313static __inline unsigned int
314get_Opcode_Y2(tilepro_bundle_bits n)
315{
316 return (((unsigned int)(n >> 56)) & 0x7);
317}
318
319static __inline unsigned int
320get_RROpcodeExtension_SN(tilepro_bundle_bits num)
321{
322 const unsigned int n = (unsigned int)num;
323 return (((n >> 4)) & 0xf);
324}
325
326static __inline unsigned int
327get_RRROpcodeExtension_X0(tilepro_bundle_bits num)
328{
329 const unsigned int n = (unsigned int)num;
330 return (((n >> 18)) & 0x1ff);
331}
332
333static __inline unsigned int
334get_RRROpcodeExtension_X1(tilepro_bundle_bits n)
335{
336 return (((unsigned int)(n >> 49)) & 0x1ff);
337}
338
339static __inline unsigned int
340get_RRROpcodeExtension_Y0(tilepro_bundle_bits num)
341{
342 const unsigned int n = (unsigned int)num;
343 return (((n >> 18)) & 0x3);
344}
345
346static __inline unsigned int
347get_RRROpcodeExtension_Y1(tilepro_bundle_bits n)
348{
349 return (((unsigned int)(n >> 49)) & 0x3);
350}
351
352static __inline unsigned int
353get_RouteOpcodeExtension_SN(tilepro_bundle_bits num)
354{
355 const unsigned int n = (unsigned int)num;
356 return (((n >> 0)) & 0x3ff);
357}
358
359static __inline unsigned int
360get_S_X0(tilepro_bundle_bits num)
361{
362 const unsigned int n = (unsigned int)num;
363 return (((n >> 27)) & 0x1);
364}
365
366static __inline unsigned int
367get_S_X1(tilepro_bundle_bits n)
368{
369 return (((unsigned int)(n >> 58)) & 0x1);
370}
371
372static __inline unsigned int
373get_ShAmt_X0(tilepro_bundle_bits num)
374{
375 const unsigned int n = (unsigned int)num;
376 return (((n >> 12)) & 0x1f);
377}
378
379static __inline unsigned int
380get_ShAmt_X1(tilepro_bundle_bits n)
381{
382 return (((unsigned int)(n >> 43)) & 0x1f);
383}
384
385static __inline unsigned int
386get_ShAmt_Y0(tilepro_bundle_bits num)
387{
388 const unsigned int n = (unsigned int)num;
389 return (((n >> 12)) & 0x1f);
390}
391
392static __inline unsigned int
393get_ShAmt_Y1(tilepro_bundle_bits n)
394{
395 return (((unsigned int)(n >> 43)) & 0x1f);
396}
397
398static __inline unsigned int
399get_SrcA_X0(tilepro_bundle_bits num)
400{
401 const unsigned int n = (unsigned int)num;
402 return (((n >> 6)) & 0x3f);
403}
404
405static __inline unsigned int
406get_SrcA_X1(tilepro_bundle_bits n)
407{
408 return (((unsigned int)(n >> 37)) & 0x3f);
409}
410
411static __inline unsigned int
412get_SrcA_Y0(tilepro_bundle_bits num)
413{
414 const unsigned int n = (unsigned int)num;
415 return (((n >> 6)) & 0x3f);
416}
417
418static __inline unsigned int
419get_SrcA_Y1(tilepro_bundle_bits n)
420{
421 return (((unsigned int)(n >> 37)) & 0x3f);
422}
423
424static __inline unsigned int
425get_SrcA_Y2(tilepro_bundle_bits n)
426{
427 return (((n >> 26)) & 0x00000001) |
428 (((unsigned int)(n >> 50)) & 0x0000003e);
429}
430
431static __inline unsigned int
432get_SrcBDest_Y2(tilepro_bundle_bits num)
433{
434 const unsigned int n = (unsigned int)num;
435 return (((n >> 20)) & 0x3f);
436}
437
438static __inline unsigned int
439get_SrcB_X0(tilepro_bundle_bits num)
440{
441 const unsigned int n = (unsigned int)num;
442 return (((n >> 12)) & 0x3f);
443}
444
445static __inline unsigned int
446get_SrcB_X1(tilepro_bundle_bits n)
447{
448 return (((unsigned int)(n >> 43)) & 0x3f);
449}
450
451static __inline unsigned int
452get_SrcB_Y0(tilepro_bundle_bits num)
453{
454 const unsigned int n = (unsigned int)num;
455 return (((n >> 12)) & 0x3f);
456}
457
458static __inline unsigned int
459get_SrcB_Y1(tilepro_bundle_bits n)
460{
461 return (((unsigned int)(n >> 43)) & 0x3f);
462}
463
464static __inline unsigned int
465get_Src_SN(tilepro_bundle_bits num)
466{
467 const unsigned int n = (unsigned int)num;
468 return (((n >> 0)) & 0x3);
469}
470
471static __inline unsigned int
472get_UnOpcodeExtension_X0(tilepro_bundle_bits num)
473{
474 const unsigned int n = (unsigned int)num;
475 return (((n >> 12)) & 0x1f);
476}
477
478static __inline unsigned int
479get_UnOpcodeExtension_X1(tilepro_bundle_bits n)
480{
481 return (((unsigned int)(n >> 43)) & 0x1f);
482}
483
484static __inline unsigned int
485get_UnOpcodeExtension_Y0(tilepro_bundle_bits num)
486{
487 const unsigned int n = (unsigned int)num;
488 return (((n >> 12)) & 0x1f);
489}
490
491static __inline unsigned int
492get_UnOpcodeExtension_Y1(tilepro_bundle_bits n)
493{
494 return (((unsigned int)(n >> 43)) & 0x1f);
495}
496
497static __inline unsigned int
498get_UnShOpcodeExtension_X0(tilepro_bundle_bits num)
499{
500 const unsigned int n = (unsigned int)num;
501 return (((n >> 17)) & 0x3ff);
502}
503
504static __inline unsigned int
505get_UnShOpcodeExtension_X1(tilepro_bundle_bits n)
506{
507 return (((unsigned int)(n >> 48)) & 0x3ff);
508}
509
510static __inline unsigned int
511get_UnShOpcodeExtension_Y0(tilepro_bundle_bits num)
512{
513 const unsigned int n = (unsigned int)num;
514 return (((n >> 17)) & 0x7);
515}
516
517static __inline unsigned int
518get_UnShOpcodeExtension_Y1(tilepro_bundle_bits n)
519{
520 return (((unsigned int)(n >> 48)) & 0x7);
521}
522
523
524static __inline int
525sign_extend(int n, int num_bits)
526{
527 int shift = (int)(sizeof(int) * 8 - num_bits);
528 return (n << shift) >> shift;
529}
530
531
532
533static __inline tilepro_bundle_bits
534create_BrOff_SN(int num)
535{
536 const unsigned int n = (unsigned int)num;
537 return ((n & 0x3ff) << 0);
538}
539
540static __inline tilepro_bundle_bits
541create_BrOff_X1(int num)
542{
543 const unsigned int n = (unsigned int)num;
544 return (((tilepro_bundle_bits)(n & 0x00007fff)) << 43) |
545 (((tilepro_bundle_bits)(n & 0x00018000)) << 20);
546}
547
548static __inline tilepro_bundle_bits
549create_BrType_X1(int num)
550{
551 const unsigned int n = (unsigned int)num;
552 return (((tilepro_bundle_bits)(n & 0xf)) << 31);
553}
554
555static __inline tilepro_bundle_bits
556create_Dest_Imm8_X1(int num)
557{
558 const unsigned int n = (unsigned int)num;
559 return (((tilepro_bundle_bits)(n & 0x0000003f)) << 31) |
560 (((tilepro_bundle_bits)(n & 0x000000c0)) << 43);
561}
562
563static __inline tilepro_bundle_bits
564create_Dest_SN(int num)
565{
566 const unsigned int n = (unsigned int)num;
567 return ((n & 0x3) << 2);
568}
569
570static __inline tilepro_bundle_bits
571create_Dest_X0(int num)
572{
573 const unsigned int n = (unsigned int)num;
574 return ((n & 0x3f) << 0);
575}
576
577static __inline tilepro_bundle_bits
578create_Dest_X1(int num)
579{
580 const unsigned int n = (unsigned int)num;
581 return (((tilepro_bundle_bits)(n & 0x3f)) << 31);
582}
583
584static __inline tilepro_bundle_bits
585create_Dest_Y0(int num)
586{
587 const unsigned int n = (unsigned int)num;
588 return ((n & 0x3f) << 0);
589}
590
591static __inline tilepro_bundle_bits
592create_Dest_Y1(int num)
593{
594 const unsigned int n = (unsigned int)num;
595 return (((tilepro_bundle_bits)(n & 0x3f)) << 31);
596}
597
598static __inline tilepro_bundle_bits
599create_Imm16_X0(int num)
600{
601 const unsigned int n = (unsigned int)num;
602 return ((n & 0xffff) << 12);
603}
604
605static __inline tilepro_bundle_bits
606create_Imm16_X1(int num)
607{
608 const unsigned int n = (unsigned int)num;
609 return (((tilepro_bundle_bits)(n & 0xffff)) << 43);
610}
611
612static __inline tilepro_bundle_bits
613create_Imm8_SN(int num)
614{
615 const unsigned int n = (unsigned int)num;
616 return ((n & 0xff) << 0);
617}
618
619static __inline tilepro_bundle_bits
620create_Imm8_X0(int num)
621{
622 const unsigned int n = (unsigned int)num;
623 return ((n & 0xff) << 12);
624}
625
626static __inline tilepro_bundle_bits
627create_Imm8_X1(int num)
628{
629 const unsigned int n = (unsigned int)num;
630 return (((tilepro_bundle_bits)(n & 0xff)) << 43);
631}
632
633static __inline tilepro_bundle_bits
634create_Imm8_Y0(int num)
635{
636 const unsigned int n = (unsigned int)num;
637 return ((n & 0xff) << 12);
638}
639
640static __inline tilepro_bundle_bits
641create_Imm8_Y1(int num)
642{
643 const unsigned int n = (unsigned int)num;
644 return (((tilepro_bundle_bits)(n & 0xff)) << 43);
645}
646
647static __inline tilepro_bundle_bits
648create_ImmOpcodeExtension_X0(int num)
649{
650 const unsigned int n = (unsigned int)num;
651 return ((n & 0x7f) << 20);
652}
653
654static __inline tilepro_bundle_bits
655create_ImmOpcodeExtension_X1(int num)
656{
657 const unsigned int n = (unsigned int)num;
658 return (((tilepro_bundle_bits)(n & 0x7f)) << 51);
659}
660
661static __inline tilepro_bundle_bits
662create_ImmRROpcodeExtension_SN(int num)
663{
664 const unsigned int n = (unsigned int)num;
665 return ((n & 0x3) << 8);
666}
667
668static __inline tilepro_bundle_bits
669create_JOffLong_X1(int num)
670{
671 const unsigned int n = (unsigned int)num;
672 return (((tilepro_bundle_bits)(n & 0x00007fff)) << 43) |
673 (((tilepro_bundle_bits)(n & 0x00018000)) << 20) |
674 (((tilepro_bundle_bits)(n & 0x001e0000)) << 14) |
675 (((tilepro_bundle_bits)(n & 0x07e00000)) << 16) |
676 (((tilepro_bundle_bits)(n & 0x18000000)) << 31);
677}
678
679static __inline tilepro_bundle_bits
680create_JOff_X1(int num)
681{
682 const unsigned int n = (unsigned int)num;
683 return (((tilepro_bundle_bits)(n & 0x00007fff)) << 43) |
684 (((tilepro_bundle_bits)(n & 0x00018000)) << 20) |
685 (((tilepro_bundle_bits)(n & 0x001e0000)) << 14) |
686 (((tilepro_bundle_bits)(n & 0x07e00000)) << 16) |
687 (((tilepro_bundle_bits)(n & 0x08000000)) << 31);
688}
689
690static __inline tilepro_bundle_bits
691create_MF_Imm15_X1(int num)
692{
693 const unsigned int n = (unsigned int)num;
694 return (((tilepro_bundle_bits)(n & 0x00003fff)) << 37) |
695 (((tilepro_bundle_bits)(n & 0x00004000)) << 44);
696}
697
698static __inline tilepro_bundle_bits
699create_MMEnd_X0(int num)
700{
701 const unsigned int n = (unsigned int)num;
702 return ((n & 0x1f) << 18);
703}
704
705static __inline tilepro_bundle_bits
706create_MMEnd_X1(int num)
707{
708 const unsigned int n = (unsigned int)num;
709 return (((tilepro_bundle_bits)(n & 0x1f)) << 49);
710}
711
712static __inline tilepro_bundle_bits
713create_MMStart_X0(int num)
714{
715 const unsigned int n = (unsigned int)num;
716 return ((n & 0x1f) << 23);
717}
718
719static __inline tilepro_bundle_bits
720create_MMStart_X1(int num)
721{
722 const unsigned int n = (unsigned int)num;
723 return (((tilepro_bundle_bits)(n & 0x1f)) << 54);
724}
725
726static __inline tilepro_bundle_bits
727create_MT_Imm15_X1(int num)
728{
729 const unsigned int n = (unsigned int)num;
730 return (((tilepro_bundle_bits)(n & 0x0000003f)) << 31) |
731 (((tilepro_bundle_bits)(n & 0x00003fc0)) << 37) |
732 (((tilepro_bundle_bits)(n & 0x00004000)) << 44);
733}
734
735static __inline tilepro_bundle_bits
736create_Mode(int num)
737{
738 const unsigned int n = (unsigned int)num;
739 return (((tilepro_bundle_bits)(n & 0x1)) << 63);
740}
741
742static __inline tilepro_bundle_bits
743create_NoRegOpcodeExtension_SN(int num)
744{
745 const unsigned int n = (unsigned int)num;
746 return ((n & 0xf) << 0);
747}
748
749static __inline tilepro_bundle_bits
750create_Opcode_SN(int num)
751{
752 const unsigned int n = (unsigned int)num;
753 return ((n & 0x3f) << 10);
754}
755
756static __inline tilepro_bundle_bits
757create_Opcode_X0(int num)
758{
759 const unsigned int n = (unsigned int)num;
760 return ((n & 0x7) << 28);
761}
762
763static __inline tilepro_bundle_bits
764create_Opcode_X1(int num)
765{
766 const unsigned int n = (unsigned int)num;
767 return (((tilepro_bundle_bits)(n & 0xf)) << 59);
768}
769
770static __inline tilepro_bundle_bits
771create_Opcode_Y0(int num)
772{
773 const unsigned int n = (unsigned int)num;
774 return ((n & 0xf) << 27);
775}
776
777static __inline tilepro_bundle_bits
778create_Opcode_Y1(int num)
779{
780 const unsigned int n = (unsigned int)num;
781 return (((tilepro_bundle_bits)(n & 0xf)) << 59);
782}
783
784static __inline tilepro_bundle_bits
785create_Opcode_Y2(int num)
786{
787 const unsigned int n = (unsigned int)num;
788 return (((tilepro_bundle_bits)(n & 0x7)) << 56);
789}
790
791static __inline tilepro_bundle_bits
792create_RROpcodeExtension_SN(int num)
793{
794 const unsigned int n = (unsigned int)num;
795 return ((n & 0xf) << 4);
796}
797
798static __inline tilepro_bundle_bits
799create_RRROpcodeExtension_X0(int num)
800{
801 const unsigned int n = (unsigned int)num;
802 return ((n & 0x1ff) << 18);
803}
804
805static __inline tilepro_bundle_bits
806create_RRROpcodeExtension_X1(int num)
807{
808 const unsigned int n = (unsigned int)num;
809 return (((tilepro_bundle_bits)(n & 0x1ff)) << 49);
810}
811
812static __inline tilepro_bundle_bits
813create_RRROpcodeExtension_Y0(int num)
814{
815 const unsigned int n = (unsigned int)num;
816 return ((n & 0x3) << 18);
817}
818
819static __inline tilepro_bundle_bits
820create_RRROpcodeExtension_Y1(int num)
821{
822 const unsigned int n = (unsigned int)num;
823 return (((tilepro_bundle_bits)(n & 0x3)) << 49);
824}
825
826static __inline tilepro_bundle_bits
827create_RouteOpcodeExtension_SN(int num)
828{
829 const unsigned int n = (unsigned int)num;
830 return ((n & 0x3ff) << 0);
831}
832
833static __inline tilepro_bundle_bits
834create_S_X0(int num)
835{
836 const unsigned int n = (unsigned int)num;
837 return ((n & 0x1) << 27);
838}
839
840static __inline tilepro_bundle_bits
841create_S_X1(int num)
842{
843 const unsigned int n = (unsigned int)num;
844 return (((tilepro_bundle_bits)(n & 0x1)) << 58);
845}
846
847static __inline tilepro_bundle_bits
848create_ShAmt_X0(int num)
849{
850 const unsigned int n = (unsigned int)num;
851 return ((n & 0x1f) << 12);
852}
853
854static __inline tilepro_bundle_bits
855create_ShAmt_X1(int num)
856{
857 const unsigned int n = (unsigned int)num;
858 return (((tilepro_bundle_bits)(n & 0x1f)) << 43);
859}
860
861static __inline tilepro_bundle_bits
862create_ShAmt_Y0(int num)
863{
864 const unsigned int n = (unsigned int)num;
865 return ((n & 0x1f) << 12);
866}
867
868static __inline tilepro_bundle_bits
869create_ShAmt_Y1(int num)
870{
871 const unsigned int n = (unsigned int)num;
872 return (((tilepro_bundle_bits)(n & 0x1f)) << 43);
873}
874
875static __inline tilepro_bundle_bits
876create_SrcA_X0(int num)
877{
878 const unsigned int n = (unsigned int)num;
879 return ((n & 0x3f) << 6);
880}
881
882static __inline tilepro_bundle_bits
883create_SrcA_X1(int num)
884{
885 const unsigned int n = (unsigned int)num;
886 return (((tilepro_bundle_bits)(n & 0x3f)) << 37);
887}
888
889static __inline tilepro_bundle_bits
890create_SrcA_Y0(int num)
891{
892 const unsigned int n = (unsigned int)num;
893 return ((n & 0x3f) << 6);
894}
895
896static __inline tilepro_bundle_bits
897create_SrcA_Y1(int num)
898{
899 const unsigned int n = (unsigned int)num;
900 return (((tilepro_bundle_bits)(n & 0x3f)) << 37);
901}
902
903static __inline tilepro_bundle_bits
904create_SrcA_Y2(int num)
905{
906 const unsigned int n = (unsigned int)num;
907 return ((n & 0x00000001) << 26) |
908 (((tilepro_bundle_bits)(n & 0x0000003e)) << 50);
909}
910
911static __inline tilepro_bundle_bits
912create_SrcBDest_Y2(int num)
913{
914 const unsigned int n = (unsigned int)num;
915 return ((n & 0x3f) << 20);
916}
917
918static __inline tilepro_bundle_bits
919create_SrcB_X0(int num)
920{
921 const unsigned int n = (unsigned int)num;
922 return ((n & 0x3f) << 12);
923}
924
925static __inline tilepro_bundle_bits
926create_SrcB_X1(int num)
927{
928 const unsigned int n = (unsigned int)num;
929 return (((tilepro_bundle_bits)(n & 0x3f)) << 43);
930}
931
932static __inline tilepro_bundle_bits
933create_SrcB_Y0(int num)
934{
935 const unsigned int n = (unsigned int)num;
936 return ((n & 0x3f) << 12);
937}
938
939static __inline tilepro_bundle_bits
940create_SrcB_Y1(int num)
941{
942 const unsigned int n = (unsigned int)num;
943 return (((tilepro_bundle_bits)(n & 0x3f)) << 43);
944}
945
946static __inline tilepro_bundle_bits
947create_Src_SN(int num)
948{
949 const unsigned int n = (unsigned int)num;
950 return ((n & 0x3) << 0);
951}
952
953static __inline tilepro_bundle_bits
954create_UnOpcodeExtension_X0(int num)
955{
956 const unsigned int n = (unsigned int)num;
957 return ((n & 0x1f) << 12);
958}
959
960static __inline tilepro_bundle_bits
961create_UnOpcodeExtension_X1(int num)
962{
963 const unsigned int n = (unsigned int)num;
964 return (((tilepro_bundle_bits)(n & 0x1f)) << 43);
965}
966
967static __inline tilepro_bundle_bits
968create_UnOpcodeExtension_Y0(int num)
969{
970 const unsigned int n = (unsigned int)num;
971 return ((n & 0x1f) << 12);
972}
973
974static __inline tilepro_bundle_bits
975create_UnOpcodeExtension_Y1(int num)
976{
977 const unsigned int n = (unsigned int)num;
978 return (((tilepro_bundle_bits)(n & 0x1f)) << 43);
979}
980
981static __inline tilepro_bundle_bits
982create_UnShOpcodeExtension_X0(int num)
983{
984 const unsigned int n = (unsigned int)num;
985 return ((n & 0x3ff) << 17);
986}
987
988static __inline tilepro_bundle_bits
989create_UnShOpcodeExtension_X1(int num)
990{
991 const unsigned int n = (unsigned int)num;
992 return (((tilepro_bundle_bits)(n & 0x3ff)) << 48);
993}
994
995static __inline tilepro_bundle_bits
996create_UnShOpcodeExtension_Y0(int num)
997{
998 const unsigned int n = (unsigned int)num;
999 return ((n & 0x7) << 17);
1000}
1001
1002static __inline tilepro_bundle_bits
1003create_UnShOpcodeExtension_Y1(int num)
1004{
1005 const unsigned int n = (unsigned int)num;
1006 return (((tilepro_bundle_bits)(n & 0x7)) << 48);
1007}
1008
1009
1010enum
1011{
1012 ADDBS_U_SPECIAL_0_OPCODE_X0 = 98,
1013 ADDBS_U_SPECIAL_0_OPCODE_X1 = 68,
1014 ADDB_SPECIAL_0_OPCODE_X0 = 1,
1015 ADDB_SPECIAL_0_OPCODE_X1 = 1,
1016 ADDHS_SPECIAL_0_OPCODE_X0 = 99,
1017 ADDHS_SPECIAL_0_OPCODE_X1 = 69,
1018 ADDH_SPECIAL_0_OPCODE_X0 = 2,
1019 ADDH_SPECIAL_0_OPCODE_X1 = 2,
1020 ADDIB_IMM_0_OPCODE_X0 = 1,
1021 ADDIB_IMM_0_OPCODE_X1 = 1,
1022 ADDIH_IMM_0_OPCODE_X0 = 2,
1023 ADDIH_IMM_0_OPCODE_X1 = 2,
1024 ADDI_IMM_0_OPCODE_X0 = 3,
1025 ADDI_IMM_0_OPCODE_X1 = 3,
1026 ADDI_IMM_1_OPCODE_SN = 1,
1027 ADDI_OPCODE_Y0 = 9,
1028 ADDI_OPCODE_Y1 = 7,
1029 ADDLIS_OPCODE_X0 = 1,
1030 ADDLIS_OPCODE_X1 = 2,
1031 ADDLI_OPCODE_X0 = 2,
1032 ADDLI_OPCODE_X1 = 3,
1033 ADDS_SPECIAL_0_OPCODE_X0 = 96,
1034 ADDS_SPECIAL_0_OPCODE_X1 = 66,
1035 ADD_SPECIAL_0_OPCODE_X0 = 3,
1036 ADD_SPECIAL_0_OPCODE_X1 = 3,
1037 ADD_SPECIAL_0_OPCODE_Y0 = 0,
1038 ADD_SPECIAL_0_OPCODE_Y1 = 0,
1039 ADIFFB_U_SPECIAL_0_OPCODE_X0 = 4,
1040 ADIFFH_SPECIAL_0_OPCODE_X0 = 5,
1041 ANDI_IMM_0_OPCODE_X0 = 1,
1042 ANDI_IMM_0_OPCODE_X1 = 4,
1043 ANDI_OPCODE_Y0 = 10,
1044 ANDI_OPCODE_Y1 = 8,
1045 AND_SPECIAL_0_OPCODE_X0 = 6,
1046 AND_SPECIAL_0_OPCODE_X1 = 4,
1047 AND_SPECIAL_2_OPCODE_Y0 = 0,
1048 AND_SPECIAL_2_OPCODE_Y1 = 0,
1049 AULI_OPCODE_X0 = 3,
1050 AULI_OPCODE_X1 = 4,
1051 AVGB_U_SPECIAL_0_OPCODE_X0 = 7,
1052 AVGH_SPECIAL_0_OPCODE_X0 = 8,
1053 BBNST_BRANCH_OPCODE_X1 = 15,
1054 BBNS_BRANCH_OPCODE_X1 = 14,
1055 BBNS_OPCODE_SN = 63,
1056 BBST_BRANCH_OPCODE_X1 = 13,
1057 BBS_BRANCH_OPCODE_X1 = 12,
1058 BBS_OPCODE_SN = 62,
1059 BGEZT_BRANCH_OPCODE_X1 = 7,
1060 BGEZ_BRANCH_OPCODE_X1 = 6,
1061 BGEZ_OPCODE_SN = 61,
1062 BGZT_BRANCH_OPCODE_X1 = 5,
1063 BGZ_BRANCH_OPCODE_X1 = 4,
1064 BGZ_OPCODE_SN = 58,
1065 BITX_UN_0_SHUN_0_OPCODE_X0 = 1,
1066 BITX_UN_0_SHUN_0_OPCODE_Y0 = 1,
1067 BLEZT_BRANCH_OPCODE_X1 = 11,
1068 BLEZ_BRANCH_OPCODE_X1 = 10,
1069 BLEZ_OPCODE_SN = 59,
1070 BLZT_BRANCH_OPCODE_X1 = 9,
1071 BLZ_BRANCH_OPCODE_X1 = 8,
1072 BLZ_OPCODE_SN = 60,
1073 BNZT_BRANCH_OPCODE_X1 = 3,
1074 BNZ_BRANCH_OPCODE_X1 = 2,
1075 BNZ_OPCODE_SN = 57,
1076 BPT_NOREG_RR_IMM_0_OPCODE_SN = 1,
1077 BRANCH_OPCODE_X1 = 5,
1078 BYTEX_UN_0_SHUN_0_OPCODE_X0 = 2,
1079 BYTEX_UN_0_SHUN_0_OPCODE_Y0 = 2,
1080 BZT_BRANCH_OPCODE_X1 = 1,
1081 BZ_BRANCH_OPCODE_X1 = 0,
1082 BZ_OPCODE_SN = 56,
1083 CLZ_UN_0_SHUN_0_OPCODE_X0 = 3,
1084 CLZ_UN_0_SHUN_0_OPCODE_Y0 = 3,
1085 CRC32_32_SPECIAL_0_OPCODE_X0 = 9,
1086 CRC32_8_SPECIAL_0_OPCODE_X0 = 10,
1087 CTZ_UN_0_SHUN_0_OPCODE_X0 = 4,
1088 CTZ_UN_0_SHUN_0_OPCODE_Y0 = 4,
1089 DRAIN_UN_0_SHUN_0_OPCODE_X1 = 1,
1090 DTLBPR_UN_0_SHUN_0_OPCODE_X1 = 2,
1091 DWORD_ALIGN_SPECIAL_0_OPCODE_X0 = 95,
1092 FINV_UN_0_SHUN_0_OPCODE_X1 = 3,
1093 FLUSH_UN_0_SHUN_0_OPCODE_X1 = 4,
1094 FNOP_NOREG_RR_IMM_0_OPCODE_SN = 3,
1095 FNOP_UN_0_SHUN_0_OPCODE_X0 = 5,
1096 FNOP_UN_0_SHUN_0_OPCODE_X1 = 5,
1097 FNOP_UN_0_SHUN_0_OPCODE_Y0 = 5,
1098 FNOP_UN_0_SHUN_0_OPCODE_Y1 = 1,
1099 HALT_NOREG_RR_IMM_0_OPCODE_SN = 0,
1100 ICOH_UN_0_SHUN_0_OPCODE_X1 = 6,
1101 ILL_UN_0_SHUN_0_OPCODE_X1 = 7,
1102 ILL_UN_0_SHUN_0_OPCODE_Y1 = 2,
1103 IMM_0_OPCODE_SN = 0,
1104 IMM_0_OPCODE_X0 = 4,
1105 IMM_0_OPCODE_X1 = 6,
1106 IMM_1_OPCODE_SN = 1,
1107 IMM_OPCODE_0_X0 = 5,
1108 INTHB_SPECIAL_0_OPCODE_X0 = 11,
1109 INTHB_SPECIAL_0_OPCODE_X1 = 5,
1110 INTHH_SPECIAL_0_OPCODE_X0 = 12,
1111 INTHH_SPECIAL_0_OPCODE_X1 = 6,
1112 INTLB_SPECIAL_0_OPCODE_X0 = 13,
1113 INTLB_SPECIAL_0_OPCODE_X1 = 7,
1114 INTLH_SPECIAL_0_OPCODE_X0 = 14,
1115 INTLH_SPECIAL_0_OPCODE_X1 = 8,
1116 INV_UN_0_SHUN_0_OPCODE_X1 = 8,
1117 IRET_UN_0_SHUN_0_OPCODE_X1 = 9,
1118 JALB_OPCODE_X1 = 13,
1119 JALF_OPCODE_X1 = 12,
1120 JALRP_SPECIAL_0_OPCODE_X1 = 9,
1121 JALRR_IMM_1_OPCODE_SN = 3,
1122 JALR_RR_IMM_0_OPCODE_SN = 5,
1123 JALR_SPECIAL_0_OPCODE_X1 = 10,
1124 JB_OPCODE_X1 = 11,
1125 JF_OPCODE_X1 = 10,
1126 JRP_SPECIAL_0_OPCODE_X1 = 11,
1127 JRR_IMM_1_OPCODE_SN = 2,
1128 JR_RR_IMM_0_OPCODE_SN = 4,
1129 JR_SPECIAL_0_OPCODE_X1 = 12,
1130 LBADD_IMM_0_OPCODE_X1 = 22,
1131 LBADD_U_IMM_0_OPCODE_X1 = 23,
1132 LB_OPCODE_Y2 = 0,
1133 LB_UN_0_SHUN_0_OPCODE_X1 = 10,
1134 LB_U_OPCODE_Y2 = 1,
1135 LB_U_UN_0_SHUN_0_OPCODE_X1 = 11,
1136 LHADD_IMM_0_OPCODE_X1 = 24,
1137 LHADD_U_IMM_0_OPCODE_X1 = 25,
1138 LH_OPCODE_Y2 = 2,
1139 LH_UN_0_SHUN_0_OPCODE_X1 = 12,
1140 LH_U_OPCODE_Y2 = 3,
1141 LH_U_UN_0_SHUN_0_OPCODE_X1 = 13,
1142 LNK_SPECIAL_0_OPCODE_X1 = 13,
1143 LWADD_IMM_0_OPCODE_X1 = 26,
1144 LWADD_NA_IMM_0_OPCODE_X1 = 27,
1145 LW_NA_UN_0_SHUN_0_OPCODE_X1 = 24,
1146 LW_OPCODE_Y2 = 4,
1147 LW_UN_0_SHUN_0_OPCODE_X1 = 14,
1148 MAXB_U_SPECIAL_0_OPCODE_X0 = 15,
1149 MAXB_U_SPECIAL_0_OPCODE_X1 = 14,
1150 MAXH_SPECIAL_0_OPCODE_X0 = 16,
1151 MAXH_SPECIAL_0_OPCODE_X1 = 15,
1152 MAXIB_U_IMM_0_OPCODE_X0 = 4,
1153 MAXIB_U_IMM_0_OPCODE_X1 = 5,
1154 MAXIH_IMM_0_OPCODE_X0 = 5,
1155 MAXIH_IMM_0_OPCODE_X1 = 6,
1156 MFSPR_IMM_0_OPCODE_X1 = 7,
1157 MF_UN_0_SHUN_0_OPCODE_X1 = 15,
1158 MINB_U_SPECIAL_0_OPCODE_X0 = 17,
1159 MINB_U_SPECIAL_0_OPCODE_X1 = 16,
1160 MINH_SPECIAL_0_OPCODE_X0 = 18,
1161 MINH_SPECIAL_0_OPCODE_X1 = 17,
1162 MINIB_U_IMM_0_OPCODE_X0 = 6,
1163 MINIB_U_IMM_0_OPCODE_X1 = 8,
1164 MINIH_IMM_0_OPCODE_X0 = 7,
1165 MINIH_IMM_0_OPCODE_X1 = 9,
1166 MM_OPCODE_X0 = 6,
1167 MM_OPCODE_X1 = 7,
1168 MNZB_SPECIAL_0_OPCODE_X0 = 19,
1169 MNZB_SPECIAL_0_OPCODE_X1 = 18,
1170 MNZH_SPECIAL_0_OPCODE_X0 = 20,
1171 MNZH_SPECIAL_0_OPCODE_X1 = 19,
1172 MNZ_SPECIAL_0_OPCODE_X0 = 21,
1173 MNZ_SPECIAL_0_OPCODE_X1 = 20,
1174 MNZ_SPECIAL_1_OPCODE_Y0 = 0,
1175 MNZ_SPECIAL_1_OPCODE_Y1 = 1,
1176 MOVEI_IMM_1_OPCODE_SN = 0,
1177 MOVE_RR_IMM_0_OPCODE_SN = 8,
1178 MTSPR_IMM_0_OPCODE_X1 = 10,
1179 MULHHA_SS_SPECIAL_0_OPCODE_X0 = 22,
1180 MULHHA_SS_SPECIAL_7_OPCODE_Y0 = 0,
1181 MULHHA_SU_SPECIAL_0_OPCODE_X0 = 23,
1182 MULHHA_UU_SPECIAL_0_OPCODE_X0 = 24,
1183 MULHHA_UU_SPECIAL_7_OPCODE_Y0 = 1,
1184 MULHHSA_UU_SPECIAL_0_OPCODE_X0 = 25,
1185 MULHH_SS_SPECIAL_0_OPCODE_X0 = 26,
1186 MULHH_SS_SPECIAL_6_OPCODE_Y0 = 0,
1187 MULHH_SU_SPECIAL_0_OPCODE_X0 = 27,
1188 MULHH_UU_SPECIAL_0_OPCODE_X0 = 28,
1189 MULHH_UU_SPECIAL_6_OPCODE_Y0 = 1,
1190 MULHLA_SS_SPECIAL_0_OPCODE_X0 = 29,
1191 MULHLA_SU_SPECIAL_0_OPCODE_X0 = 30,
1192 MULHLA_US_SPECIAL_0_OPCODE_X0 = 31,
1193 MULHLA_UU_SPECIAL_0_OPCODE_X0 = 32,
1194 MULHLSA_UU_SPECIAL_0_OPCODE_X0 = 33,
1195 MULHLSA_UU_SPECIAL_5_OPCODE_Y0 = 0,
1196 MULHL_SS_SPECIAL_0_OPCODE_X0 = 34,
1197 MULHL_SU_SPECIAL_0_OPCODE_X0 = 35,
1198 MULHL_US_SPECIAL_0_OPCODE_X0 = 36,
1199 MULHL_UU_SPECIAL_0_OPCODE_X0 = 37,
1200 MULLLA_SS_SPECIAL_0_OPCODE_X0 = 38,
1201 MULLLA_SS_SPECIAL_7_OPCODE_Y0 = 2,
1202 MULLLA_SU_SPECIAL_0_OPCODE_X0 = 39,
1203 MULLLA_UU_SPECIAL_0_OPCODE_X0 = 40,
1204 MULLLA_UU_SPECIAL_7_OPCODE_Y0 = 3,
1205 MULLLSA_UU_SPECIAL_0_OPCODE_X0 = 41,
1206 MULLL_SS_SPECIAL_0_OPCODE_X0 = 42,
1207 MULLL_SS_SPECIAL_6_OPCODE_Y0 = 2,
1208 MULLL_SU_SPECIAL_0_OPCODE_X0 = 43,
1209 MULLL_UU_SPECIAL_0_OPCODE_X0 = 44,
1210 MULLL_UU_SPECIAL_6_OPCODE_Y0 = 3,
1211 MVNZ_SPECIAL_0_OPCODE_X0 = 45,
1212 MVNZ_SPECIAL_1_OPCODE_Y0 = 1,
1213 MVZ_SPECIAL_0_OPCODE_X0 = 46,
1214 MVZ_SPECIAL_1_OPCODE_Y0 = 2,
1215 MZB_SPECIAL_0_OPCODE_X0 = 47,
1216 MZB_SPECIAL_0_OPCODE_X1 = 21,
1217 MZH_SPECIAL_0_OPCODE_X0 = 48,
1218 MZH_SPECIAL_0_OPCODE_X1 = 22,
1219 MZ_SPECIAL_0_OPCODE_X0 = 49,
1220 MZ_SPECIAL_0_OPCODE_X1 = 23,
1221 MZ_SPECIAL_1_OPCODE_Y0 = 3,
1222 MZ_SPECIAL_1_OPCODE_Y1 = 2,
1223 NAP_UN_0_SHUN_0_OPCODE_X1 = 16,
1224 NOP_NOREG_RR_IMM_0_OPCODE_SN = 2,
1225 NOP_UN_0_SHUN_0_OPCODE_X0 = 6,
1226 NOP_UN_0_SHUN_0_OPCODE_X1 = 17,
1227 NOP_UN_0_SHUN_0_OPCODE_Y0 = 6,
1228 NOP_UN_0_SHUN_0_OPCODE_Y1 = 3,
1229 NOREG_RR_IMM_0_OPCODE_SN = 0,
1230 NOR_SPECIAL_0_OPCODE_X0 = 50,
1231 NOR_SPECIAL_0_OPCODE_X1 = 24,
1232 NOR_SPECIAL_2_OPCODE_Y0 = 1,
1233 NOR_SPECIAL_2_OPCODE_Y1 = 1,
1234 ORI_IMM_0_OPCODE_X0 = 8,
1235 ORI_IMM_0_OPCODE_X1 = 11,
1236 ORI_OPCODE_Y0 = 11,
1237 ORI_OPCODE_Y1 = 9,
1238 OR_SPECIAL_0_OPCODE_X0 = 51,
1239 OR_SPECIAL_0_OPCODE_X1 = 25,
1240 OR_SPECIAL_2_OPCODE_Y0 = 2,
1241 OR_SPECIAL_2_OPCODE_Y1 = 2,
1242 PACKBS_U_SPECIAL_0_OPCODE_X0 = 103,
1243 PACKBS_U_SPECIAL_0_OPCODE_X1 = 73,
1244 PACKHB_SPECIAL_0_OPCODE_X0 = 52,
1245 PACKHB_SPECIAL_0_OPCODE_X1 = 26,
1246 PACKHS_SPECIAL_0_OPCODE_X0 = 102,
1247 PACKHS_SPECIAL_0_OPCODE_X1 = 72,
1248 PACKLB_SPECIAL_0_OPCODE_X0 = 53,
1249 PACKLB_SPECIAL_0_OPCODE_X1 = 27,
1250 PCNT_UN_0_SHUN_0_OPCODE_X0 = 7,
1251 PCNT_UN_0_SHUN_0_OPCODE_Y0 = 7,
1252 RLI_SHUN_0_OPCODE_X0 = 1,
1253 RLI_SHUN_0_OPCODE_X1 = 1,
1254 RLI_SHUN_0_OPCODE_Y0 = 1,
1255 RLI_SHUN_0_OPCODE_Y1 = 1,
1256 RL_SPECIAL_0_OPCODE_X0 = 54,
1257 RL_SPECIAL_0_OPCODE_X1 = 28,
1258 RL_SPECIAL_3_OPCODE_Y0 = 0,
1259 RL_SPECIAL_3_OPCODE_Y1 = 0,
1260 RR_IMM_0_OPCODE_SN = 0,
1261 S1A_SPECIAL_0_OPCODE_X0 = 55,
1262 S1A_SPECIAL_0_OPCODE_X1 = 29,
1263 S1A_SPECIAL_0_OPCODE_Y0 = 1,
1264 S1A_SPECIAL_0_OPCODE_Y1 = 1,
1265 S2A_SPECIAL_0_OPCODE_X0 = 56,
1266 S2A_SPECIAL_0_OPCODE_X1 = 30,
1267 S2A_SPECIAL_0_OPCODE_Y0 = 2,
1268 S2A_SPECIAL_0_OPCODE_Y1 = 2,
1269 S3A_SPECIAL_0_OPCODE_X0 = 57,
1270 S3A_SPECIAL_0_OPCODE_X1 = 31,
1271 S3A_SPECIAL_5_OPCODE_Y0 = 1,
1272 S3A_SPECIAL_5_OPCODE_Y1 = 1,
1273 SADAB_U_SPECIAL_0_OPCODE_X0 = 58,
1274 SADAH_SPECIAL_0_OPCODE_X0 = 59,
1275 SADAH_U_SPECIAL_0_OPCODE_X0 = 60,
1276 SADB_U_SPECIAL_0_OPCODE_X0 = 61,
1277 SADH_SPECIAL_0_OPCODE_X0 = 62,
1278 SADH_U_SPECIAL_0_OPCODE_X0 = 63,
1279 SBADD_IMM_0_OPCODE_X1 = 28,
1280 SB_OPCODE_Y2 = 5,
1281 SB_SPECIAL_0_OPCODE_X1 = 32,
1282 SEQB_SPECIAL_0_OPCODE_X0 = 64,
1283 SEQB_SPECIAL_0_OPCODE_X1 = 33,
1284 SEQH_SPECIAL_0_OPCODE_X0 = 65,
1285 SEQH_SPECIAL_0_OPCODE_X1 = 34,
1286 SEQIB_IMM_0_OPCODE_X0 = 9,
1287 SEQIB_IMM_0_OPCODE_X1 = 12,
1288 SEQIH_IMM_0_OPCODE_X0 = 10,
1289 SEQIH_IMM_0_OPCODE_X1 = 13,
1290 SEQI_IMM_0_OPCODE_X0 = 11,
1291 SEQI_IMM_0_OPCODE_X1 = 14,
1292 SEQI_OPCODE_Y0 = 12,
1293 SEQI_OPCODE_Y1 = 10,
1294 SEQ_SPECIAL_0_OPCODE_X0 = 66,
1295 SEQ_SPECIAL_0_OPCODE_X1 = 35,
1296 SEQ_SPECIAL_5_OPCODE_Y0 = 2,
1297 SEQ_SPECIAL_5_OPCODE_Y1 = 2,
1298 SHADD_IMM_0_OPCODE_X1 = 29,
1299 SHL8II_IMM_0_OPCODE_SN = 3,
1300 SHLB_SPECIAL_0_OPCODE_X0 = 67,
1301 SHLB_SPECIAL_0_OPCODE_X1 = 36,
1302 SHLH_SPECIAL_0_OPCODE_X0 = 68,
1303 SHLH_SPECIAL_0_OPCODE_X1 = 37,
1304 SHLIB_SHUN_0_OPCODE_X0 = 2,
1305 SHLIB_SHUN_0_OPCODE_X1 = 2,
1306 SHLIH_SHUN_0_OPCODE_X0 = 3,
1307 SHLIH_SHUN_0_OPCODE_X1 = 3,
1308 SHLI_SHUN_0_OPCODE_X0 = 4,
1309 SHLI_SHUN_0_OPCODE_X1 = 4,
1310 SHLI_SHUN_0_OPCODE_Y0 = 2,
1311 SHLI_SHUN_0_OPCODE_Y1 = 2,
1312 SHL_SPECIAL_0_OPCODE_X0 = 69,
1313 SHL_SPECIAL_0_OPCODE_X1 = 38,
1314 SHL_SPECIAL_3_OPCODE_Y0 = 1,
1315 SHL_SPECIAL_3_OPCODE_Y1 = 1,
1316 SHR1_RR_IMM_0_OPCODE_SN = 9,
1317 SHRB_SPECIAL_0_OPCODE_X0 = 70,
1318 SHRB_SPECIAL_0_OPCODE_X1 = 39,
1319 SHRH_SPECIAL_0_OPCODE_X0 = 71,
1320 SHRH_SPECIAL_0_OPCODE_X1 = 40,
1321 SHRIB_SHUN_0_OPCODE_X0 = 5,
1322 SHRIB_SHUN_0_OPCODE_X1 = 5,
1323 SHRIH_SHUN_0_OPCODE_X0 = 6,
1324 SHRIH_SHUN_0_OPCODE_X1 = 6,
1325 SHRI_SHUN_0_OPCODE_X0 = 7,
1326 SHRI_SHUN_0_OPCODE_X1 = 7,
1327 SHRI_SHUN_0_OPCODE_Y0 = 3,
1328 SHRI_SHUN_0_OPCODE_Y1 = 3,
1329 SHR_SPECIAL_0_OPCODE_X0 = 72,
1330 SHR_SPECIAL_0_OPCODE_X1 = 41,
1331 SHR_SPECIAL_3_OPCODE_Y0 = 2,
1332 SHR_SPECIAL_3_OPCODE_Y1 = 2,
1333 SHUN_0_OPCODE_X0 = 7,
1334 SHUN_0_OPCODE_X1 = 8,
1335 SHUN_0_OPCODE_Y0 = 13,
1336 SHUN_0_OPCODE_Y1 = 11,
1337 SH_OPCODE_Y2 = 6,
1338 SH_SPECIAL_0_OPCODE_X1 = 42,
1339 SLTB_SPECIAL_0_OPCODE_X0 = 73,
1340 SLTB_SPECIAL_0_OPCODE_X1 = 43,
1341 SLTB_U_SPECIAL_0_OPCODE_X0 = 74,
1342 SLTB_U_SPECIAL_0_OPCODE_X1 = 44,
1343 SLTEB_SPECIAL_0_OPCODE_X0 = 75,
1344 SLTEB_SPECIAL_0_OPCODE_X1 = 45,
1345 SLTEB_U_SPECIAL_0_OPCODE_X0 = 76,
1346 SLTEB_U_SPECIAL_0_OPCODE_X1 = 46,
1347 SLTEH_SPECIAL_0_OPCODE_X0 = 77,
1348 SLTEH_SPECIAL_0_OPCODE_X1 = 47,
1349 SLTEH_U_SPECIAL_0_OPCODE_X0 = 78,
1350 SLTEH_U_SPECIAL_0_OPCODE_X1 = 48,
1351 SLTE_SPECIAL_0_OPCODE_X0 = 79,
1352 SLTE_SPECIAL_0_OPCODE_X1 = 49,
1353 SLTE_SPECIAL_4_OPCODE_Y0 = 0,
1354 SLTE_SPECIAL_4_OPCODE_Y1 = 0,
1355 SLTE_U_SPECIAL_0_OPCODE_X0 = 80,
1356 SLTE_U_SPECIAL_0_OPCODE_X1 = 50,
1357 SLTE_U_SPECIAL_4_OPCODE_Y0 = 1,
1358 SLTE_U_SPECIAL_4_OPCODE_Y1 = 1,
1359 SLTH_SPECIAL_0_OPCODE_X0 = 81,
1360 SLTH_SPECIAL_0_OPCODE_X1 = 51,
1361 SLTH_U_SPECIAL_0_OPCODE_X0 = 82,
1362 SLTH_U_SPECIAL_0_OPCODE_X1 = 52,
1363 SLTIB_IMM_0_OPCODE_X0 = 12,
1364 SLTIB_IMM_0_OPCODE_X1 = 15,
1365 SLTIB_U_IMM_0_OPCODE_X0 = 13,
1366 SLTIB_U_IMM_0_OPCODE_X1 = 16,
1367 SLTIH_IMM_0_OPCODE_X0 = 14,
1368 SLTIH_IMM_0_OPCODE_X1 = 17,
1369 SLTIH_U_IMM_0_OPCODE_X0 = 15,
1370 SLTIH_U_IMM_0_OPCODE_X1 = 18,
1371 SLTI_IMM_0_OPCODE_X0 = 16,
1372 SLTI_IMM_0_OPCODE_X1 = 19,
1373 SLTI_OPCODE_Y0 = 14,
1374 SLTI_OPCODE_Y1 = 12,
1375 SLTI_U_IMM_0_OPCODE_X0 = 17,
1376 SLTI_U_IMM_0_OPCODE_X1 = 20,
1377 SLTI_U_OPCODE_Y0 = 15,
1378 SLTI_U_OPCODE_Y1 = 13,
1379 SLT_SPECIAL_0_OPCODE_X0 = 83,
1380 SLT_SPECIAL_0_OPCODE_X1 = 53,
1381 SLT_SPECIAL_4_OPCODE_Y0 = 2,
1382 SLT_SPECIAL_4_OPCODE_Y1 = 2,
1383 SLT_U_SPECIAL_0_OPCODE_X0 = 84,
1384 SLT_U_SPECIAL_0_OPCODE_X1 = 54,
1385 SLT_U_SPECIAL_4_OPCODE_Y0 = 3,
1386 SLT_U_SPECIAL_4_OPCODE_Y1 = 3,
1387 SNEB_SPECIAL_0_OPCODE_X0 = 85,
1388 SNEB_SPECIAL_0_OPCODE_X1 = 55,
1389 SNEH_SPECIAL_0_OPCODE_X0 = 86,
1390 SNEH_SPECIAL_0_OPCODE_X1 = 56,
1391 SNE_SPECIAL_0_OPCODE_X0 = 87,
1392 SNE_SPECIAL_0_OPCODE_X1 = 57,
1393 SNE_SPECIAL_5_OPCODE_Y0 = 3,
1394 SNE_SPECIAL_5_OPCODE_Y1 = 3,
1395 SPECIAL_0_OPCODE_X0 = 0,
1396 SPECIAL_0_OPCODE_X1 = 1,
1397 SPECIAL_0_OPCODE_Y0 = 1,
1398 SPECIAL_0_OPCODE_Y1 = 1,
1399 SPECIAL_1_OPCODE_Y0 = 2,
1400 SPECIAL_1_OPCODE_Y1 = 2,
1401 SPECIAL_2_OPCODE_Y0 = 3,
1402 SPECIAL_2_OPCODE_Y1 = 3,
1403 SPECIAL_3_OPCODE_Y0 = 4,
1404 SPECIAL_3_OPCODE_Y1 = 4,
1405 SPECIAL_4_OPCODE_Y0 = 5,
1406 SPECIAL_4_OPCODE_Y1 = 5,
1407 SPECIAL_5_OPCODE_Y0 = 6,
1408 SPECIAL_5_OPCODE_Y1 = 6,
1409 SPECIAL_6_OPCODE_Y0 = 7,
1410 SPECIAL_7_OPCODE_Y0 = 8,
1411 SRAB_SPECIAL_0_OPCODE_X0 = 88,
1412 SRAB_SPECIAL_0_OPCODE_X1 = 58,
1413 SRAH_SPECIAL_0_OPCODE_X0 = 89,
1414 SRAH_SPECIAL_0_OPCODE_X1 = 59,
1415 SRAIB_SHUN_0_OPCODE_X0 = 8,
1416 SRAIB_SHUN_0_OPCODE_X1 = 8,
1417 SRAIH_SHUN_0_OPCODE_X0 = 9,
1418 SRAIH_SHUN_0_OPCODE_X1 = 9,
1419 SRAI_SHUN_0_OPCODE_X0 = 10,
1420 SRAI_SHUN_0_OPCODE_X1 = 10,
1421 SRAI_SHUN_0_OPCODE_Y0 = 4,
1422 SRAI_SHUN_0_OPCODE_Y1 = 4,
1423 SRA_SPECIAL_0_OPCODE_X0 = 90,
1424 SRA_SPECIAL_0_OPCODE_X1 = 60,
1425 SRA_SPECIAL_3_OPCODE_Y0 = 3,
1426 SRA_SPECIAL_3_OPCODE_Y1 = 3,
1427 SUBBS_U_SPECIAL_0_OPCODE_X0 = 100,
1428 SUBBS_U_SPECIAL_0_OPCODE_X1 = 70,
1429 SUBB_SPECIAL_0_OPCODE_X0 = 91,
1430 SUBB_SPECIAL_0_OPCODE_X1 = 61,
1431 SUBHS_SPECIAL_0_OPCODE_X0 = 101,
1432 SUBHS_SPECIAL_0_OPCODE_X1 = 71,
1433 SUBH_SPECIAL_0_OPCODE_X0 = 92,
1434 SUBH_SPECIAL_0_OPCODE_X1 = 62,
1435 SUBS_SPECIAL_0_OPCODE_X0 = 97,
1436 SUBS_SPECIAL_0_OPCODE_X1 = 67,
1437 SUB_SPECIAL_0_OPCODE_X0 = 93,
1438 SUB_SPECIAL_0_OPCODE_X1 = 63,
1439 SUB_SPECIAL_0_OPCODE_Y0 = 3,
1440 SUB_SPECIAL_0_OPCODE_Y1 = 3,
1441 SWADD_IMM_0_OPCODE_X1 = 30,
1442 SWINT0_UN_0_SHUN_0_OPCODE_X1 = 18,
1443 SWINT1_UN_0_SHUN_0_OPCODE_X1 = 19,
1444 SWINT2_UN_0_SHUN_0_OPCODE_X1 = 20,
1445 SWINT3_UN_0_SHUN_0_OPCODE_X1 = 21,
1446 SW_OPCODE_Y2 = 7,
1447 SW_SPECIAL_0_OPCODE_X1 = 64,
1448 TBLIDXB0_UN_0_SHUN_0_OPCODE_X0 = 8,
1449 TBLIDXB0_UN_0_SHUN_0_OPCODE_Y0 = 8,
1450 TBLIDXB1_UN_0_SHUN_0_OPCODE_X0 = 9,
1451 TBLIDXB1_UN_0_SHUN_0_OPCODE_Y0 = 9,
1452 TBLIDXB2_UN_0_SHUN_0_OPCODE_X0 = 10,
1453 TBLIDXB2_UN_0_SHUN_0_OPCODE_Y0 = 10,
1454 TBLIDXB3_UN_0_SHUN_0_OPCODE_X0 = 11,
1455 TBLIDXB3_UN_0_SHUN_0_OPCODE_Y0 = 11,
1456 TNS_UN_0_SHUN_0_OPCODE_X1 = 22,
1457 UN_0_SHUN_0_OPCODE_X0 = 11,
1458 UN_0_SHUN_0_OPCODE_X1 = 11,
1459 UN_0_SHUN_0_OPCODE_Y0 = 5,
1460 UN_0_SHUN_0_OPCODE_Y1 = 5,
1461 WH64_UN_0_SHUN_0_OPCODE_X1 = 23,
1462 XORI_IMM_0_OPCODE_X0 = 2,
1463 XORI_IMM_0_OPCODE_X1 = 21,
1464 XOR_SPECIAL_0_OPCODE_X0 = 94,
1465 XOR_SPECIAL_0_OPCODE_X1 = 65,
1466 XOR_SPECIAL_2_OPCODE_Y0 = 3,
1467 XOR_SPECIAL_2_OPCODE_Y1 = 3
1468};
1469
1470
1471#endif /* __ASSEMBLER__ */
1472
1473#endif /* __ARCH_OPCODE_H__ */
diff --git a/arch/tile/include/uapi/arch/sim.h b/arch/tile/include/uapi/arch/sim.h
deleted file mode 100644
index c4183dcd2ea7..000000000000
--- a/arch/tile/include/uapi/arch/sim.h
+++ /dev/null
@@ -1,644 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16/**
17 * @file
18 *
19 * Provides an API for controlling the simulator at runtime.
20 */
21
22/**
23 * @addtogroup arch_sim
24 * @{
25 *
26 * An API for controlling the simulator at runtime.
27 *
28 * The simulator's behavior can be modified while it is running.
29 * For example, human-readable trace output can be enabled and disabled
30 * around code of interest.
31 *
32 * There are two ways to modify simulator behavior:
33 * programmatically, by calling various sim_* functions, and
34 * interactively, by entering commands like "sim set functional true"
35 * at the tile-monitor prompt. Typing "sim help" at that prompt provides
36 * a list of interactive commands.
37 *
38 * All interactive commands can also be executed programmatically by
39 * passing a string to the sim_command function.
40 */
41
42#ifndef __ARCH_SIM_H__
43#define __ARCH_SIM_H__
44
45#include <arch/sim_def.h>
46#include <arch/abi.h>
47
48#ifndef __ASSEMBLER__
49
50#include <arch/spr_def.h>
51
52
53/**
54 * Return true if the current program is running under a simulator,
55 * rather than on real hardware. If running on hardware, other "sim_xxx()"
56 * calls have no useful effect.
57 */
58static inline int
59sim_is_simulator(void)
60{
61 return __insn_mfspr(SPR_SIM_CONTROL) != 0;
62}
63
64
65/**
66 * Checkpoint the simulator state to a checkpoint file.
67 *
68 * The checkpoint file name is either the default or the name specified
69 * on the command line with "--checkpoint-file".
70 */
71static __inline void
72sim_checkpoint(void)
73{
74 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_CHECKPOINT);
75}
76
77
78/**
79 * Report whether or not various kinds of simulator tracing are enabled.
80 *
81 * @return The bitwise OR of these values:
82 *
83 * SIM_TRACE_CYCLES (--trace-cycles),
84 * SIM_TRACE_ROUTER (--trace-router),
85 * SIM_TRACE_REGISTER_WRITES (--trace-register-writes),
86 * SIM_TRACE_DISASM (--trace-disasm),
87 * SIM_TRACE_STALL_INFO (--trace-stall-info)
88 * SIM_TRACE_MEMORY_CONTROLLER (--trace-memory-controller)
89 * SIM_TRACE_L2_CACHE (--trace-l2)
90 * SIM_TRACE_LINES (--trace-lines)
91 */
92static __inline unsigned int
93sim_get_tracing(void)
94{
95 return __insn_mfspr(SPR_SIM_CONTROL) & SIM_TRACE_FLAG_MASK;
96}
97
98
99/**
100 * Turn on or off different kinds of simulator tracing.
101 *
102 * @param mask Either one of these special values:
103 *
104 * SIM_TRACE_NONE (turns off tracing),
105 * SIM_TRACE_ALL (turns on all possible tracing).
106 *
107 * or the bitwise OR of these values:
108 *
109 * SIM_TRACE_CYCLES (--trace-cycles),
110 * SIM_TRACE_ROUTER (--trace-router),
111 * SIM_TRACE_REGISTER_WRITES (--trace-register-writes),
112 * SIM_TRACE_DISASM (--trace-disasm),
113 * SIM_TRACE_STALL_INFO (--trace-stall-info)
114 * SIM_TRACE_MEMORY_CONTROLLER (--trace-memory-controller)
115 * SIM_TRACE_L2_CACHE (--trace-l2)
116 * SIM_TRACE_LINES (--trace-lines)
117 */
118static __inline void
119sim_set_tracing(unsigned int mask)
120{
121 __insn_mtspr(SPR_SIM_CONTROL, SIM_TRACE_SPR_ARG(mask));
122}
123
124
125/**
126 * Request dumping of different kinds of simulator state.
127 *
128 * @param mask Either this special value:
129 *
130 * SIM_DUMP_ALL (dump all known state)
131 *
132 * or the bitwise OR of these values:
133 *
134 * SIM_DUMP_REGS (the register file),
135 * SIM_DUMP_SPRS (the SPRs),
136 * SIM_DUMP_ITLB (the iTLB),
137 * SIM_DUMP_DTLB (the dTLB),
138 * SIM_DUMP_L1I (the L1 I-cache),
139 * SIM_DUMP_L1D (the L1 D-cache),
140 * SIM_DUMP_L2 (the L2 cache),
141 * SIM_DUMP_SNREGS (the switch register file),
142 * SIM_DUMP_SNITLB (the switch iTLB),
143 * SIM_DUMP_SNL1I (the switch L1 I-cache),
144 * SIM_DUMP_BACKTRACE (the current backtrace)
145 */
146static __inline void
147sim_dump(unsigned int mask)
148{
149 __insn_mtspr(SPR_SIM_CONTROL, SIM_DUMP_SPR_ARG(mask));
150}
151
152
153/**
154 * Print a string to the simulator stdout.
155 *
156 * @param str The string to be written.
157 */
158static __inline void
159sim_print(const char* str)
160{
161 for ( ; *str != '\0'; str++)
162 {
163 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
164 (*str << _SIM_CONTROL_OPERATOR_BITS));
165 }
166 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
167 (SIM_PUTC_FLUSH_BINARY << _SIM_CONTROL_OPERATOR_BITS));
168}
169
170
171/**
172 * Print a string to the simulator stdout.
173 *
174 * @param str The string to be written (a newline is automatically added).
175 */
176static __inline void
177sim_print_string(const char* str)
178{
179 for ( ; *str != '\0'; str++)
180 {
181 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
182 (*str << _SIM_CONTROL_OPERATOR_BITS));
183 }
184 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
185 (SIM_PUTC_FLUSH_STRING << _SIM_CONTROL_OPERATOR_BITS));
186}
187
188
189/**
190 * Execute a simulator command string.
191 *
192 * Type 'sim help' at the tile-monitor prompt to learn what commands
193 * are available. Note the use of the tile-monitor "sim" command to
194 * pass commands to the simulator.
195 *
196 * The argument to sim_command() does not include the leading "sim"
197 * prefix used at the tile-monitor prompt; for example, you might call
198 * sim_command("trace disasm").
199 */
200static __inline void
201sim_command(const char* str)
202{
203 int c;
204 do
205 {
206 c = *str++;
207 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_COMMAND |
208 (c << _SIM_CONTROL_OPERATOR_BITS));
209 }
210 while (c);
211}
212
213
214
215#ifndef __DOXYGEN__
216
217/**
218 * The underlying implementation of "_sim_syscall()".
219 *
220 * We use extra "and" instructions to ensure that all the values
221 * we are passing to the simulator are actually valid in the registers
222 * (i.e. returned from memory) prior to the SIM_CONTROL spr.
223 */
224static __inline long _sim_syscall0(int val)
225{
226 long result;
227 __asm__ __volatile__ ("mtspr SIM_CONTROL, r0"
228 : "=R00" (result) : "R00" (val));
229 return result;
230}
231
232static __inline long _sim_syscall1(int val, long arg1)
233{
234 long result;
235 __asm__ __volatile__ ("{ and zero, r1, r1; mtspr SIM_CONTROL, r0 }"
236 : "=R00" (result) : "R00" (val), "R01" (arg1));
237 return result;
238}
239
240static __inline long _sim_syscall2(int val, long arg1, long arg2)
241{
242 long result;
243 __asm__ __volatile__ ("{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }"
244 : "=R00" (result)
245 : "R00" (val), "R01" (arg1), "R02" (arg2));
246 return result;
247}
248
249/* Note that _sim_syscall3() and higher are technically at risk of
250 receiving an interrupt right before the mtspr bundle, in which case
251 the register values for arguments 3 and up may still be in flight
252 to the core from a stack frame reload. */
253
254static __inline long _sim_syscall3(int val, long arg1, long arg2, long arg3)
255{
256 long result;
257 __asm__ __volatile__ ("{ and zero, r3, r3 };"
258 "{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }"
259 : "=R00" (result)
260 : "R00" (val), "R01" (arg1), "R02" (arg2),
261 "R03" (arg3));
262 return result;
263}
264
265static __inline long _sim_syscall4(int val, long arg1, long arg2, long arg3,
266 long arg4)
267{
268 long result;
269 __asm__ __volatile__ ("{ and zero, r3, r4 };"
270 "{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }"
271 : "=R00" (result)
272 : "R00" (val), "R01" (arg1), "R02" (arg2),
273 "R03" (arg3), "R04" (arg4));
274 return result;
275}
276
277static __inline long _sim_syscall5(int val, long arg1, long arg2, long arg3,
278 long arg4, long arg5)
279{
280 long result;
281 __asm__ __volatile__ ("{ and zero, r3, r4; and zero, r5, r5 };"
282 "{ and zero, r1, r2; mtspr SIM_CONTROL, r0 }"
283 : "=R00" (result)
284 : "R00" (val), "R01" (arg1), "R02" (arg2),
285 "R03" (arg3), "R04" (arg4), "R05" (arg5));
286 return result;
287}
288
289/**
290 * Make a special syscall to the simulator itself, if running under
291 * simulation. This is used as the implementation of other functions
292 * and should not be used outside this file.
293 *
294 * @param syscall_num The simulator syscall number.
295 * @param nr The number of additional arguments provided.
296 *
297 * @return Varies by syscall.
298 */
299#define _sim_syscall(syscall_num, nr, args...) \
300 _sim_syscall##nr( \
301 ((syscall_num) << _SIM_CONTROL_OPERATOR_BITS) | SIM_CONTROL_SYSCALL, \
302 ##args)
303
304
305/* Values for the "access_mask" parameters below. */
306#define SIM_WATCHPOINT_READ 1
307#define SIM_WATCHPOINT_WRITE 2
308#define SIM_WATCHPOINT_EXECUTE 4
309
310
311static __inline int
312sim_add_watchpoint(unsigned int process_id,
313 unsigned long address,
314 unsigned long size,
315 unsigned int access_mask,
316 unsigned long user_data)
317{
318 return _sim_syscall(SIM_SYSCALL_ADD_WATCHPOINT, 5, process_id,
319 address, size, access_mask, user_data);
320}
321
322
323static __inline int
324sim_remove_watchpoint(unsigned int process_id,
325 unsigned long address,
326 unsigned long size,
327 unsigned int access_mask,
328 unsigned long user_data)
329{
330 return _sim_syscall(SIM_SYSCALL_REMOVE_WATCHPOINT, 5, process_id,
331 address, size, access_mask, user_data);
332}
333
334
335/**
336 * Return value from sim_query_watchpoint.
337 */
338struct SimQueryWatchpointStatus
339{
340 /**
341 * 0 if a watchpoint fired, 1 if no watchpoint fired, or -1 for
342 * error (meaning a bad process_id).
343 */
344 int syscall_status;
345
346 /**
347 * The address of the watchpoint that fired (this is the address
348 * passed to sim_add_watchpoint, not an address within that range
349 * that actually triggered the watchpoint).
350 */
351 unsigned long address;
352
353 /** The arbitrary user_data installed by sim_add_watchpoint. */
354 unsigned long user_data;
355};
356
357
358static __inline struct SimQueryWatchpointStatus
359sim_query_watchpoint(unsigned int process_id)
360{
361 struct SimQueryWatchpointStatus status;
362 long val = SIM_CONTROL_SYSCALL |
363 (SIM_SYSCALL_QUERY_WATCHPOINT << _SIM_CONTROL_OPERATOR_BITS);
364 __asm__ __volatile__ ("{ and zero, r1, r1; mtspr SIM_CONTROL, r0 }"
365 : "=R00" (status.syscall_status),
366 "=R01" (status.address),
367 "=R02" (status.user_data)
368 : "R00" (val), "R01" (process_id));
369 return status;
370}
371
372
373/* On the simulator, confirm lines have been evicted everywhere. */
374static __inline void
375sim_validate_lines_evicted(unsigned long long pa, unsigned long length)
376{
377#ifdef __LP64__
378 _sim_syscall(SIM_SYSCALL_VALIDATE_LINES_EVICTED, 2, pa, length);
379#else
380 _sim_syscall(SIM_SYSCALL_VALIDATE_LINES_EVICTED, 4,
381 0 /* dummy */, (long)(pa), (long)(pa >> 32), length);
382#endif
383}
384
385
386/* Return the current CPU speed in cycles per second. */
387static __inline long
388sim_query_cpu_speed(void)
389{
390 return _sim_syscall(SIM_SYSCALL_QUERY_CPU_SPEED, 0);
391}
392
393#endif /* !__DOXYGEN__ */
394
395
396
397
398/**
399 * Modify the shaping parameters of a shim.
400 *
401 * @param shim The shim to modify. One of:
402 * SIM_CONTROL_SHAPING_GBE_0
403 * SIM_CONTROL_SHAPING_GBE_1
404 * SIM_CONTROL_SHAPING_GBE_2
405 * SIM_CONTROL_SHAPING_GBE_3
406 * SIM_CONTROL_SHAPING_XGBE_0
407 * SIM_CONTROL_SHAPING_XGBE_1
408 *
409 * @param type The type of shaping. This should be the same type of
410 * shaping that is already in place on the shim. One of:
411 * SIM_CONTROL_SHAPING_MULTIPLIER
412 * SIM_CONTROL_SHAPING_PPS
413 * SIM_CONTROL_SHAPING_BPS
414 *
415 * @param units The magnitude of the rate. One of:
416 * SIM_CONTROL_SHAPING_UNITS_SINGLE
417 * SIM_CONTROL_SHAPING_UNITS_KILO
418 * SIM_CONTROL_SHAPING_UNITS_MEGA
419 * SIM_CONTROL_SHAPING_UNITS_GIGA
420 *
421 * @param rate The rate to which to change it. This must fit in
422 * SIM_CONTROL_SHAPING_RATE_BITS bits or a warning is issued and
423 * the shaping is not changed.
424 *
425 * @return 0 if no problems were detected in the arguments to sim_set_shaping
426 * or 1 if problems were detected (for example, rate does not fit in 17 bits).
427 */
428static __inline int
429sim_set_shaping(unsigned shim,
430 unsigned type,
431 unsigned units,
432 unsigned rate)
433{
434 if ((rate & ~((1 << SIM_CONTROL_SHAPING_RATE_BITS) - 1)) != 0)
435 return 1;
436
437 __insn_mtspr(SPR_SIM_CONTROL, SIM_SHAPING_SPR_ARG(shim, type, units, rate));
438 return 0;
439}
440
441#ifdef __tilegx__
442
443/** Enable a set of mPIPE links. Pass a -1 link_mask to enable all links. */
444static __inline void
445sim_enable_mpipe_links(unsigned mpipe, unsigned long link_mask)
446{
447 __insn_mtspr(SPR_SIM_CONTROL,
448 (SIM_CONTROL_ENABLE_MPIPE_LINK_MAGIC_BYTE |
449 (mpipe << 8) | (1 << 16) | ((uint_reg_t)link_mask << 32)));
450}
451
452/** Disable a set of mPIPE links. Pass a -1 link_mask to disable all links. */
453static __inline void
454sim_disable_mpipe_links(unsigned mpipe, unsigned long link_mask)
455{
456 __insn_mtspr(SPR_SIM_CONTROL,
457 (SIM_CONTROL_ENABLE_MPIPE_LINK_MAGIC_BYTE |
458 (mpipe << 8) | (0 << 16) | ((uint_reg_t)link_mask << 32)));
459}
460
461#endif /* __tilegx__ */
462
463
464/*
465 * An API for changing "functional" mode.
466 */
467
468#ifndef __DOXYGEN__
469
470#define sim_enable_functional() \
471 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_ENABLE_FUNCTIONAL)
472
473#define sim_disable_functional() \
474 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_DISABLE_FUNCTIONAL)
475
476#endif /* __DOXYGEN__ */
477
478
479/*
480 * Profiler support.
481 */
482
483/**
484 * Turn profiling on for the current task.
485 *
486 * Note that this has no effect if run in an environment without
487 * profiling support (thus, the proper flags to the simulator must
488 * be supplied).
489 */
490static __inline void
491sim_profiler_enable(void)
492{
493 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PROFILER_ENABLE);
494}
495
496
497/** Turn profiling off for the current task. */
498static __inline void
499sim_profiler_disable(void)
500{
501 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PROFILER_DISABLE);
502}
503
504
505/**
506 * Turn profiling on or off for the current task.
507 *
508 * @param enabled If true, turns on profiling. If false, turns it off.
509 *
510 * Note that this has no effect if run in an environment without
511 * profiling support (thus, the proper flags to the simulator must
512 * be supplied).
513 */
514static __inline void
515sim_profiler_set_enabled(int enabled)
516{
517 int val =
518 enabled ? SIM_CONTROL_PROFILER_ENABLE : SIM_CONTROL_PROFILER_DISABLE;
519 __insn_mtspr(SPR_SIM_CONTROL, val);
520}
521
522
523/**
524 * Return true if and only if profiling is currently enabled
525 * for the current task.
526 *
527 * This returns false even if sim_profiler_enable() was called
528 * if the current execution environment does not support profiling.
529 */
530static __inline int
531sim_profiler_is_enabled(void)
532{
533 return ((__insn_mfspr(SPR_SIM_CONTROL) & SIM_PROFILER_ENABLED_MASK) != 0);
534}
535
536
537/**
538 * Reset profiling counters to zero for the current task.
539 *
540 * Resetting can be done while profiling is enabled. It does not affect
541 * the chip-wide profiling counters.
542 */
543static __inline void
544sim_profiler_clear(void)
545{
546 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PROFILER_CLEAR);
547}
548
549
550/**
551 * Enable specified chip-level profiling counters.
552 *
553 * Does not affect the per-task profiling counters.
554 *
555 * @param mask Either this special value:
556 *
557 * SIM_CHIP_ALL (enables all chip-level components).
558 *
559 * or the bitwise OR of these values:
560 *
561 * SIM_CHIP_MEMCTL (enable all memory controllers)
562 * SIM_CHIP_XAUI (enable all XAUI controllers)
563 * SIM_CHIP_MPIPE (enable all MPIPE controllers)
564 */
565static __inline void
566sim_profiler_chip_enable(unsigned int mask)
567{
568 __insn_mtspr(SPR_SIM_CONTROL, SIM_PROFILER_CHIP_ENABLE_SPR_ARG(mask));
569}
570
571
572/**
573 * Disable specified chip-level profiling counters.
574 *
575 * Does not affect the per-task profiling counters.
576 *
577 * @param mask Either this special value:
578 *
579 * SIM_CHIP_ALL (disables all chip-level components).
580 *
581 * or the bitwise OR of these values:
582 *
583 * SIM_CHIP_MEMCTL (disable all memory controllers)
584 * SIM_CHIP_XAUI (disable all XAUI controllers)
585 * SIM_CHIP_MPIPE (disable all MPIPE controllers)
586 */
587static __inline void
588sim_profiler_chip_disable(unsigned int mask)
589{
590 __insn_mtspr(SPR_SIM_CONTROL, SIM_PROFILER_CHIP_DISABLE_SPR_ARG(mask));
591}
592
593
594/**
595 * Reset specified chip-level profiling counters to zero.
596 *
597 * Does not affect the per-task profiling counters.
598 *
599 * @param mask Either this special value:
600 *
601 * SIM_CHIP_ALL (clears all chip-level components).
602 *
603 * or the bitwise OR of these values:
604 *
605 * SIM_CHIP_MEMCTL (clear all memory controllers)
606 * SIM_CHIP_XAUI (clear all XAUI controllers)
607 * SIM_CHIP_MPIPE (clear all MPIPE controllers)
608 */
609static __inline void
610sim_profiler_chip_clear(unsigned int mask)
611{
612 __insn_mtspr(SPR_SIM_CONTROL, SIM_PROFILER_CHIP_CLEAR_SPR_ARG(mask));
613}
614
615
616/*
617 * Event support.
618 */
619
620#ifndef __DOXYGEN__
621
622static __inline void
623sim_event_begin(unsigned int x)
624{
625#if defined(__tile__) && !defined(__NO_EVENT_SPR__)
626 __insn_mtspr(SPR_EVENT_BEGIN, x);
627#endif
628}
629
630static __inline void
631sim_event_end(unsigned int x)
632{
633#if defined(__tile__) && !defined(__NO_EVENT_SPR__)
634 __insn_mtspr(SPR_EVENT_END, x);
635#endif
636}
637
638#endif /* !__DOXYGEN__ */
639
640#endif /* !__ASSEMBLER__ */
641
642#endif /* !__ARCH_SIM_H__ */
643
644/** @} */
diff --git a/arch/tile/include/uapi/arch/sim_def.h b/arch/tile/include/uapi/arch/sim_def.h
deleted file mode 100644
index f74f9943770d..000000000000
--- a/arch/tile/include/uapi/arch/sim_def.h
+++ /dev/null
@@ -1,506 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16/**
17 * @file
18 *
19 * Some low-level simulator definitions.
20 */
21
22#ifndef __ARCH_SIM_DEF_H__
23#define __ARCH_SIM_DEF_H__
24
25
26/**
27 * Internal: the low bits of the SIM_CONTROL_* SPR values specify
28 * the operation to perform, and the remaining bits are
29 * an operation-specific parameter (often unused).
30 */
31#define _SIM_CONTROL_OPERATOR_BITS 8
32
33
34/*
35 * Values which can be written to SPR_SIM_CONTROL.
36 */
37
38/** If written to SPR_SIM_CONTROL, stops profiling. */
39#define SIM_CONTROL_PROFILER_DISABLE 0
40
41/** If written to SPR_SIM_CONTROL, starts profiling. */
42#define SIM_CONTROL_PROFILER_ENABLE 1
43
44/** If written to SPR_SIM_CONTROL, clears profiling counters. */
45#define SIM_CONTROL_PROFILER_CLEAR 2
46
47/** If written to SPR_SIM_CONTROL, checkpoints the simulator. */
48#define SIM_CONTROL_CHECKPOINT 3
49
50/**
51 * If written to SPR_SIM_CONTROL, combined with a mask (shifted by 8),
52 * sets the tracing mask to the given mask. See "sim_set_tracing()".
53 */
54#define SIM_CONTROL_SET_TRACING 4
55
56/**
57 * If written to SPR_SIM_CONTROL, combined with a mask (shifted by 8),
58 * dumps the requested items of machine state to the log.
59 */
60#define SIM_CONTROL_DUMP 5
61
62/** If written to SPR_SIM_CONTROL, clears chip-level profiling counters. */
63#define SIM_CONTROL_PROFILER_CHIP_CLEAR 6
64
65/** If written to SPR_SIM_CONTROL, disables chip-level profiling. */
66#define SIM_CONTROL_PROFILER_CHIP_DISABLE 7
67
68/** If written to SPR_SIM_CONTROL, enables chip-level profiling. */
69#define SIM_CONTROL_PROFILER_CHIP_ENABLE 8
70
71/** If written to SPR_SIM_CONTROL, enables chip-level functional mode */
72#define SIM_CONTROL_ENABLE_FUNCTIONAL 9
73
74/** If written to SPR_SIM_CONTROL, disables chip-level functional mode. */
75#define SIM_CONTROL_DISABLE_FUNCTIONAL 10
76
77/**
78 * If written to SPR_SIM_CONTROL, enables chip-level functional mode.
79 * All tiles must perform this write for functional mode to be enabled.
80 * Ignored in naked boot mode unless --functional is specified.
81 * WARNING: Only the hypervisor startup code should use this!
82 */
83#define SIM_CONTROL_ENABLE_FUNCTIONAL_BARRIER 11
84
85/**
86 * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
87 * writes a string directly to the simulator output. Written to once for
88 * each character in the string, plus a final NUL. Instead of NUL,
89 * you can also use "SIM_PUTC_FLUSH_STRING" or "SIM_PUTC_FLUSH_BINARY".
90 */
91/* ISSUE: Document the meaning of "newline", and the handling of NUL. */
92#define SIM_CONTROL_PUTC 12
93
94/**
95 * If written to SPR_SIM_CONTROL, clears the --grind-coherence state for
96 * this core. This is intended to be used before a loop that will
97 * invalidate the cache by loading new data and evicting all current data.
98 * Generally speaking, this API should only be used by system code.
99 */
100#define SIM_CONTROL_GRINDER_CLEAR 13
101
102/** If written to SPR_SIM_CONTROL, shuts down the simulator. */
103#define SIM_CONTROL_SHUTDOWN 14
104
105/**
106 * If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
107 * indicates that a fork syscall just created the given process.
108 */
109#define SIM_CONTROL_OS_FORK 15
110
111/**
112 * If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
113 * indicates that an exit syscall was just executed by the given process.
114 */
115#define SIM_CONTROL_OS_EXIT 16
116
117/**
118 * If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
119 * indicates that the OS just switched to the given process.
120 */
121#define SIM_CONTROL_OS_SWITCH 17
122
123/**
124 * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
125 * indicates that an exec syscall was just executed. Written to once for
126 * each character in the executable name, plus a final NUL.
127 */
128#define SIM_CONTROL_OS_EXEC 18
129
130/**
131 * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
132 * indicates that an interpreter (PT_INTERP) was loaded. Written to once
133 * for each character in "ADDR:PATH", plus a final NUL, where "ADDR" is a
134 * hex load address starting with "0x", and "PATH" is the executable name.
135 */
136#define SIM_CONTROL_OS_INTERP 19
137
138/**
139 * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
140 * indicates that a dll was loaded. Written to once for each character
141 * in "ADDR:PATH", plus a final NUL, where "ADDR" is a hexadecimal load
142 * address starting with "0x", and "PATH" is the executable name.
143 */
144#define SIM_CONTROL_DLOPEN 20
145
146/**
147 * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
148 * indicates that a dll was unloaded. Written to once for each character
149 * in "ADDR", plus a final NUL, where "ADDR" is a hexadecimal load
150 * address starting with "0x".
151 */
152#define SIM_CONTROL_DLCLOSE 21
153
154/**
155 * If written to SPR_SIM_CONTROL, combined with a flag (shifted by 8),
156 * indicates whether to allow data reads to remotely-cached
157 * dirty cache lines to be cached locally without grinder warnings or
158 * assertions (used by Linux kernel fast memcpy).
159 */
160#define SIM_CONTROL_ALLOW_MULTIPLE_CACHING 22
161
162/** If written to SPR_SIM_CONTROL, enables memory tracing. */
163#define SIM_CONTROL_ENABLE_MEM_LOGGING 23
164
165/** If written to SPR_SIM_CONTROL, disables memory tracing. */
166#define SIM_CONTROL_DISABLE_MEM_LOGGING 24
167
168/**
169 * If written to SPR_SIM_CONTROL, changes the shaping parameters of one of
170 * the gbe or xgbe shims. Must specify the shim id, the type, the units, and
171 * the rate, as defined in SIM_SHAPING_SPR_ARG.
172 */
173#define SIM_CONTROL_SHAPING 25
174
175/**
176 * If written to SPR_SIM_CONTROL, combined with character (shifted by 8),
177 * requests that a simulator command be executed. Written to once for each
178 * character in the command, plus a final NUL.
179 */
180#define SIM_CONTROL_COMMAND 26
181
182/**
183 * If written to SPR_SIM_CONTROL, indicates that the simulated system
184 * is panicking, to allow debugging via --debug-on-panic.
185 */
186#define SIM_CONTROL_PANIC 27
187
188/**
189 * If written to SPR_SIM_CONTROL, triggers a simulator syscall.
190 * See "sim_syscall()" for more info.
191 */
192#define SIM_CONTROL_SYSCALL 32
193
194/**
195 * If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
196 * provides the pid that subsequent SIM_CONTROL_OS_FORK writes should
197 * use as the pid, rather than the default previous SIM_CONTROL_OS_SWITCH.
198 */
199#define SIM_CONTROL_OS_FORK_PARENT 33
200
201/**
202 * If written to SPR_SIM_CONTROL, combined with a mPIPE shim number
203 * (shifted by 8), clears the pending magic data section. The cleared
204 * pending magic data section and any subsequently appended magic bytes
205 * will only take effect when the classifier blast programmer is run.
206 */
207#define SIM_CONTROL_CLEAR_MPIPE_MAGIC_BYTES 34
208
209/**
210 * If written to SPR_SIM_CONTROL, combined with a mPIPE shim number
211 * (shifted by 8) and a byte of data (shifted by 16), appends that byte
212 * to the shim's pending magic data section. The pending magic data
213 * section takes effect when the classifier blast programmer is run.
214 */
215#define SIM_CONTROL_APPEND_MPIPE_MAGIC_BYTE 35
216
217/**
218 * If written to SPR_SIM_CONTROL, combined with a mPIPE shim number
219 * (shifted by 8), an enable=1/disable=0 bit (shifted by 16), and a
220 * mask of links (shifted by 32), enable or disable the corresponding
221 * mPIPE links.
222 */
223#define SIM_CONTROL_ENABLE_MPIPE_LINK_MAGIC_BYTE 36
224
225
226/*
227 * Syscall numbers for use with "sim_syscall()".
228 */
229
230/** Syscall number for sim_add_watchpoint(). */
231#define SIM_SYSCALL_ADD_WATCHPOINT 2
232
233/** Syscall number for sim_remove_watchpoint(). */
234#define SIM_SYSCALL_REMOVE_WATCHPOINT 3
235
236/** Syscall number for sim_query_watchpoint(). */
237#define SIM_SYSCALL_QUERY_WATCHPOINT 4
238
239/**
240 * Syscall number that asserts that the cache lines whose 64-bit PA
241 * is passed as the second argument to sim_syscall(), and over a
242 * range passed as the third argument, are no longer in cache.
243 * The simulator raises an error if this is not the case.
244 */
245#define SIM_SYSCALL_VALIDATE_LINES_EVICTED 5
246
247/** Syscall number for sim_query_cpu_speed(). */
248#define SIM_SYSCALL_QUERY_CPU_SPEED 6
249
250
251/*
252 * Bit masks which can be shifted by 8, combined with
253 * SIM_CONTROL_SET_TRACING, and written to SPR_SIM_CONTROL.
254 */
255
256/**
257 * @addtogroup arch_sim
258 * @{
259 */
260
261/** Enable --trace-cycle when passed to simulator_set_tracing(). */
262#define SIM_TRACE_CYCLES 0x01
263
264/** Enable --trace-router when passed to simulator_set_tracing(). */
265#define SIM_TRACE_ROUTER 0x02
266
267/** Enable --trace-register-writes when passed to simulator_set_tracing(). */
268#define SIM_TRACE_REGISTER_WRITES 0x04
269
270/** Enable --trace-disasm when passed to simulator_set_tracing(). */
271#define SIM_TRACE_DISASM 0x08
272
273/** Enable --trace-stall-info when passed to simulator_set_tracing(). */
274#define SIM_TRACE_STALL_INFO 0x10
275
276/** Enable --trace-memory-controller when passed to simulator_set_tracing(). */
277#define SIM_TRACE_MEMORY_CONTROLLER 0x20
278
279/** Enable --trace-l2 when passed to simulator_set_tracing(). */
280#define SIM_TRACE_L2_CACHE 0x40
281
282/** Enable --trace-lines when passed to simulator_set_tracing(). */
283#define SIM_TRACE_LINES 0x80
284
285/** Turn off all tracing when passed to simulator_set_tracing(). */
286#define SIM_TRACE_NONE 0
287
288/** Turn on all tracing when passed to simulator_set_tracing(). */
289#define SIM_TRACE_ALL (-1)
290
291/** @} */
292
293/** Computes the value to write to SPR_SIM_CONTROL to set tracing flags. */
294#define SIM_TRACE_SPR_ARG(mask) \
295 (SIM_CONTROL_SET_TRACING | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
296
297
298/*
299 * Bit masks which can be shifted by 8, combined with
300 * SIM_CONTROL_DUMP, and written to SPR_SIM_CONTROL.
301 */
302
303/**
304 * @addtogroup arch_sim
305 * @{
306 */
307
308/** Dump the general-purpose registers. */
309#define SIM_DUMP_REGS 0x001
310
311/** Dump the SPRs. */
312#define SIM_DUMP_SPRS 0x002
313
314/** Dump the ITLB. */
315#define SIM_DUMP_ITLB 0x004
316
317/** Dump the DTLB. */
318#define SIM_DUMP_DTLB 0x008
319
320/** Dump the L1 I-cache. */
321#define SIM_DUMP_L1I 0x010
322
323/** Dump the L1 D-cache. */
324#define SIM_DUMP_L1D 0x020
325
326/** Dump the L2 cache. */
327#define SIM_DUMP_L2 0x040
328
329/** Dump the switch registers. */
330#define SIM_DUMP_SNREGS 0x080
331
332/** Dump the switch ITLB. */
333#define SIM_DUMP_SNITLB 0x100
334
335/** Dump the switch L1 I-cache. */
336#define SIM_DUMP_SNL1I 0x200
337
338/** Dump the current backtrace. */
339#define SIM_DUMP_BACKTRACE 0x400
340
341/** Only dump valid lines in caches. */
342#define SIM_DUMP_VALID_LINES 0x800
343
344/** Dump everything that is dumpable. */
345#define SIM_DUMP_ALL (-1 & ~SIM_DUMP_VALID_LINES)
346
347/** @} */
348
349/** Computes the value to write to SPR_SIM_CONTROL to dump machine state. */
350#define SIM_DUMP_SPR_ARG(mask) \
351 (SIM_CONTROL_DUMP | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
352
353
354/*
355 * Bit masks which can be shifted by 8, combined with
356 * SIM_CONTROL_PROFILER_CHIP_xxx, and written to SPR_SIM_CONTROL.
357 */
358
359/**
360 * @addtogroup arch_sim
361 * @{
362 */
363
364/** Use with SIM_PROFILER_CHIP_xxx to control the memory controllers. */
365#define SIM_CHIP_MEMCTL 0x001
366
367/** Use with SIM_PROFILER_CHIP_xxx to control the XAUI interface. */
368#define SIM_CHIP_XAUI 0x002
369
370/** Use with SIM_PROFILER_CHIP_xxx to control the PCIe interface. */
371#define SIM_CHIP_PCIE 0x004
372
373/** Use with SIM_PROFILER_CHIP_xxx to control the MPIPE interface. */
374#define SIM_CHIP_MPIPE 0x008
375
376/** Use with SIM_PROFILER_CHIP_xxx to control the TRIO interface. */
377#define SIM_CHIP_TRIO 0x010
378
379/** Reference all chip devices. */
380#define SIM_CHIP_ALL (-1)
381
382/** @} */
383
384/** Computes the value to write to SPR_SIM_CONTROL to clear chip statistics. */
385#define SIM_PROFILER_CHIP_CLEAR_SPR_ARG(mask) \
386 (SIM_CONTROL_PROFILER_CHIP_CLEAR | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
387
388/** Computes the value to write to SPR_SIM_CONTROL to disable chip statistics.*/
389#define SIM_PROFILER_CHIP_DISABLE_SPR_ARG(mask) \
390 (SIM_CONTROL_PROFILER_CHIP_DISABLE | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
391
392/** Computes the value to write to SPR_SIM_CONTROL to enable chip statistics. */
393#define SIM_PROFILER_CHIP_ENABLE_SPR_ARG(mask) \
394 (SIM_CONTROL_PROFILER_CHIP_ENABLE | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
395
396
397
398/* Shim bitrate controls. */
399
400/** The number of bits used to store the shim id. */
401#define SIM_CONTROL_SHAPING_SHIM_ID_BITS 3
402
403/**
404 * @addtogroup arch_sim
405 * @{
406 */
407
408/** Change the gbe 0 bitrate. */
409#define SIM_CONTROL_SHAPING_GBE_0 0x0
410
411/** Change the gbe 1 bitrate. */
412#define SIM_CONTROL_SHAPING_GBE_1 0x1
413
414/** Change the gbe 2 bitrate. */
415#define SIM_CONTROL_SHAPING_GBE_2 0x2
416
417/** Change the gbe 3 bitrate. */
418#define SIM_CONTROL_SHAPING_GBE_3 0x3
419
420/** Change the xgbe 0 bitrate. */
421#define SIM_CONTROL_SHAPING_XGBE_0 0x4
422
423/** Change the xgbe 1 bitrate. */
424#define SIM_CONTROL_SHAPING_XGBE_1 0x5
425
426/** The type of shaping to do. */
427#define SIM_CONTROL_SHAPING_TYPE_BITS 2
428
429/** Control the multiplier. */
430#define SIM_CONTROL_SHAPING_MULTIPLIER 0
431
432/** Control the PPS. */
433#define SIM_CONTROL_SHAPING_PPS 1
434
435/** Control the BPS. */
436#define SIM_CONTROL_SHAPING_BPS 2
437
438/** The number of bits for the units for the shaping parameter. */
439#define SIM_CONTROL_SHAPING_UNITS_BITS 2
440
441/** Provide a number in single units. */
442#define SIM_CONTROL_SHAPING_UNITS_SINGLE 0
443
444/** Provide a number in kilo units. */
445#define SIM_CONTROL_SHAPING_UNITS_KILO 1
446
447/** Provide a number in mega units. */
448#define SIM_CONTROL_SHAPING_UNITS_MEGA 2
449
450/** Provide a number in giga units. */
451#define SIM_CONTROL_SHAPING_UNITS_GIGA 3
452
453/** @} */
454
455/** How many bits are available for the rate. */
456#define SIM_CONTROL_SHAPING_RATE_BITS \
457 (32 - (_SIM_CONTROL_OPERATOR_BITS + \
458 SIM_CONTROL_SHAPING_SHIM_ID_BITS + \
459 SIM_CONTROL_SHAPING_TYPE_BITS + \
460 SIM_CONTROL_SHAPING_UNITS_BITS))
461
462/** Computes the value to write to SPR_SIM_CONTROL to change a bitrate. */
463#define SIM_SHAPING_SPR_ARG(shim, type, units, rate) \
464 (SIM_CONTROL_SHAPING | \
465 ((shim) | \
466 ((type) << (SIM_CONTROL_SHAPING_SHIM_ID_BITS)) | \
467 ((units) << (SIM_CONTROL_SHAPING_SHIM_ID_BITS + \
468 SIM_CONTROL_SHAPING_TYPE_BITS)) | \
469 ((rate) << (SIM_CONTROL_SHAPING_SHIM_ID_BITS + \
470 SIM_CONTROL_SHAPING_TYPE_BITS + \
471 SIM_CONTROL_SHAPING_UNITS_BITS))) << _SIM_CONTROL_OPERATOR_BITS)
472
473
474/*
475 * Values returned when reading SPR_SIM_CONTROL.
476 * ISSUE: These names should share a longer common prefix.
477 */
478
479/**
480 * When reading SPR_SIM_CONTROL, the mask of simulator tracing bits
481 * (SIM_TRACE_xxx values).
482 */
483#define SIM_TRACE_FLAG_MASK 0xFFFF
484
485/** When reading SPR_SIM_CONTROL, the mask for whether profiling is enabled. */
486#define SIM_PROFILER_ENABLED_MASK 0x10000
487
488
489/*
490 * Special arguments for "SIM_CONTROL_PUTC".
491 */
492
493/**
494 * Flag value for forcing a PUTC string-flush, including
495 * coordinate/cycle prefix and newline.
496 */
497#define SIM_PUTC_FLUSH_STRING 0x100
498
499/**
500 * Flag value for forcing a PUTC binary-data-flush, which skips the
501 * prefix and does not append a newline.
502 */
503#define SIM_PUTC_FLUSH_BINARY 0x101
504
505
506#endif /* __ARCH_SIM_DEF_H__ */
diff --git a/arch/tile/include/uapi/arch/spr_def.h b/arch/tile/include/uapi/arch/spr_def.h
deleted file mode 100644
index 743428615cda..000000000000
--- a/arch/tile/include/uapi/arch/spr_def.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _UAPI__ARCH_SPR_DEF_H__
17#define _UAPI__ARCH_SPR_DEF_H__
18
19/* Include the proper base SPR definition file. */
20#ifdef __tilegx__
21#include <arch/spr_def_64.h>
22#else
23#include <arch/spr_def_32.h>
24#endif
25
26
27#endif /* _UAPI__ARCH_SPR_DEF_H__ */
diff --git a/arch/tile/include/uapi/arch/spr_def_32.h b/arch/tile/include/uapi/arch/spr_def_32.h
deleted file mode 100644
index 64122d6160e1..000000000000
--- a/arch/tile/include/uapi/arch/spr_def_32.h
+++ /dev/null
@@ -1,256 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef __DOXYGEN__
17
18#ifndef __ARCH_SPR_DEF_32_H__
19#define __ARCH_SPR_DEF_32_H__
20
21#define SPR_AUX_PERF_COUNT_0 0x6005
22#define SPR_AUX_PERF_COUNT_1 0x6006
23#define SPR_AUX_PERF_COUNT_CTL 0x6007
24#define SPR_AUX_PERF_COUNT_STS 0x6008
25#define SPR_CYCLE_HIGH 0x4e06
26#define SPR_CYCLE_LOW 0x4e07
27#define SPR_DMA_BYTE 0x3900
28#define SPR_DMA_CHUNK_SIZE 0x3901
29#define SPR_DMA_CTR 0x3902
30#define SPR_DMA_CTR__REQUEST_MASK 0x1
31#define SPR_DMA_CTR__SUSPEND_MASK 0x2
32#define SPR_DMA_DST_ADDR 0x3903
33#define SPR_DMA_DST_CHUNK_ADDR 0x3904
34#define SPR_DMA_SRC_ADDR 0x3905
35#define SPR_DMA_SRC_CHUNK_ADDR 0x3906
36#define SPR_DMA_STATUS__DONE_MASK 0x1
37#define SPR_DMA_STATUS__BUSY_MASK 0x2
38#define SPR_DMA_STATUS__RUNNING_MASK 0x10
39#define SPR_DMA_STRIDE 0x3907
40#define SPR_DMA_USER_STATUS 0x3908
41#define SPR_DONE 0x4e08
42#define SPR_EVENT_BEGIN 0x4e0d
43#define SPR_EVENT_END 0x4e0e
44#define SPR_EX_CONTEXT_0_0 0x4a05
45#define SPR_EX_CONTEXT_0_1 0x4a06
46#define SPR_EX_CONTEXT_0_1__PL_SHIFT 0
47#define SPR_EX_CONTEXT_0_1__PL_RMASK 0x3
48#define SPR_EX_CONTEXT_0_1__PL_MASK 0x3
49#define SPR_EX_CONTEXT_0_1__ICS_SHIFT 2
50#define SPR_EX_CONTEXT_0_1__ICS_RMASK 0x1
51#define SPR_EX_CONTEXT_0_1__ICS_MASK 0x4
52#define SPR_EX_CONTEXT_1_0 0x4805
53#define SPR_EX_CONTEXT_1_1 0x4806
54#define SPR_EX_CONTEXT_1_1__PL_SHIFT 0
55#define SPR_EX_CONTEXT_1_1__PL_RMASK 0x3
56#define SPR_EX_CONTEXT_1_1__PL_MASK 0x3
57#define SPR_EX_CONTEXT_1_1__ICS_SHIFT 2
58#define SPR_EX_CONTEXT_1_1__ICS_RMASK 0x1
59#define SPR_EX_CONTEXT_1_1__ICS_MASK 0x4
60#define SPR_EX_CONTEXT_2_0 0x4605
61#define SPR_EX_CONTEXT_2_1 0x4606
62#define SPR_EX_CONTEXT_2_1__PL_SHIFT 0
63#define SPR_EX_CONTEXT_2_1__PL_RMASK 0x3
64#define SPR_EX_CONTEXT_2_1__PL_MASK 0x3
65#define SPR_EX_CONTEXT_2_1__ICS_SHIFT 2
66#define SPR_EX_CONTEXT_2_1__ICS_RMASK 0x1
67#define SPR_EX_CONTEXT_2_1__ICS_MASK 0x4
68#define SPR_FAIL 0x4e09
69#define SPR_IDN_AVAIL_EN 0x3e05
70#define SPR_IDN_CA_DATA 0x0b00
71#define SPR_IDN_DATA_AVAIL 0x0b03
72#define SPR_IDN_DEADLOCK_TIMEOUT 0x3406
73#define SPR_IDN_DEMUX_CA_COUNT 0x0a05
74#define SPR_IDN_DEMUX_COUNT_0 0x0a06
75#define SPR_IDN_DEMUX_COUNT_1 0x0a07
76#define SPR_IDN_DEMUX_CTL 0x0a08
77#define SPR_IDN_DEMUX_QUEUE_SEL 0x0a0a
78#define SPR_IDN_DEMUX_STATUS 0x0a0b
79#define SPR_IDN_DEMUX_WRITE_FIFO 0x0a0c
80#define SPR_IDN_DIRECTION_PROTECT 0x2e05
81#define SPR_IDN_PENDING 0x0a0e
82#define SPR_IDN_REFILL_EN 0x0e05
83#define SPR_IDN_SP_FIFO_DATA 0x0a0f
84#define SPR_IDN_SP_FIFO_SEL 0x0a10
85#define SPR_IDN_SP_FREEZE 0x0a11
86#define SPR_IDN_SP_FREEZE__SP_FRZ_MASK 0x1
87#define SPR_IDN_SP_FREEZE__DEMUX_FRZ_MASK 0x2
88#define SPR_IDN_SP_FREEZE__NON_DEST_EXT_MASK 0x4
89#define SPR_IDN_SP_STATE 0x0a12
90#define SPR_IDN_TAG_0 0x0a13
91#define SPR_IDN_TAG_1 0x0a14
92#define SPR_IDN_TAG_VALID 0x0a15
93#define SPR_IDN_TILE_COORD 0x0a16
94#define SPR_INTCTRL_0_STATUS 0x4a07
95#define SPR_INTCTRL_1_STATUS 0x4807
96#define SPR_INTCTRL_2_STATUS 0x4607
97#define SPR_INTERRUPT_CRITICAL_SECTION 0x4e0a
98#define SPR_INTERRUPT_MASK_0_0 0x4a08
99#define SPR_INTERRUPT_MASK_0_1 0x4a09
100#define SPR_INTERRUPT_MASK_1_0 0x4809
101#define SPR_INTERRUPT_MASK_1_1 0x480a
102#define SPR_INTERRUPT_MASK_2_0 0x4608
103#define SPR_INTERRUPT_MASK_2_1 0x4609
104#define SPR_INTERRUPT_MASK_RESET_0_0 0x4a0a
105#define SPR_INTERRUPT_MASK_RESET_0_1 0x4a0b
106#define SPR_INTERRUPT_MASK_RESET_1_0 0x480b
107#define SPR_INTERRUPT_MASK_RESET_1_1 0x480c
108#define SPR_INTERRUPT_MASK_RESET_2_0 0x460a
109#define SPR_INTERRUPT_MASK_RESET_2_1 0x460b
110#define SPR_INTERRUPT_MASK_SET_0_0 0x4a0c
111#define SPR_INTERRUPT_MASK_SET_0_1 0x4a0d
112#define SPR_INTERRUPT_MASK_SET_1_0 0x480d
113#define SPR_INTERRUPT_MASK_SET_1_1 0x480e
114#define SPR_INTERRUPT_MASK_SET_2_0 0x460c
115#define SPR_INTERRUPT_MASK_SET_2_1 0x460d
116#define SPR_MPL_AUX_PERF_COUNT_SET_0 0x6000
117#define SPR_MPL_AUX_PERF_COUNT_SET_1 0x6001
118#define SPR_MPL_AUX_PERF_COUNT_SET_2 0x6002
119#define SPR_MPL_DMA_CPL_SET_0 0x5800
120#define SPR_MPL_DMA_CPL_SET_1 0x5801
121#define SPR_MPL_DMA_CPL_SET_2 0x5802
122#define SPR_MPL_DMA_NOTIFY_SET_0 0x3800
123#define SPR_MPL_DMA_NOTIFY_SET_1 0x3801
124#define SPR_MPL_DMA_NOTIFY_SET_2 0x3802
125#define SPR_MPL_IDN_ACCESS_SET_0 0x0a00
126#define SPR_MPL_IDN_ACCESS_SET_1 0x0a01
127#define SPR_MPL_IDN_ACCESS_SET_2 0x0a02
128#define SPR_MPL_IDN_AVAIL_SET_0 0x3e00
129#define SPR_MPL_IDN_AVAIL_SET_1 0x3e01
130#define SPR_MPL_IDN_AVAIL_SET_2 0x3e02
131#define SPR_MPL_IDN_CA_SET_0 0x3a00
132#define SPR_MPL_IDN_CA_SET_1 0x3a01
133#define SPR_MPL_IDN_CA_SET_2 0x3a02
134#define SPR_MPL_IDN_COMPLETE_SET_0 0x1200
135#define SPR_MPL_IDN_COMPLETE_SET_1 0x1201
136#define SPR_MPL_IDN_COMPLETE_SET_2 0x1202
137#define SPR_MPL_IDN_FIREWALL_SET_0 0x2e00
138#define SPR_MPL_IDN_FIREWALL_SET_1 0x2e01
139#define SPR_MPL_IDN_FIREWALL_SET_2 0x2e02
140#define SPR_MPL_IDN_REFILL_SET_0 0x0e00
141#define SPR_MPL_IDN_REFILL_SET_1 0x0e01
142#define SPR_MPL_IDN_REFILL_SET_2 0x0e02
143#define SPR_MPL_IDN_TIMER_SET_0 0x3400
144#define SPR_MPL_IDN_TIMER_SET_1 0x3401
145#define SPR_MPL_IDN_TIMER_SET_2 0x3402
146#define SPR_MPL_INTCTRL_0_SET_0 0x4a00
147#define SPR_MPL_INTCTRL_0_SET_1 0x4a01
148#define SPR_MPL_INTCTRL_0_SET_2 0x4a02
149#define SPR_MPL_INTCTRL_1_SET_0 0x4800
150#define SPR_MPL_INTCTRL_1_SET_1 0x4801
151#define SPR_MPL_INTCTRL_1_SET_2 0x4802
152#define SPR_MPL_INTCTRL_2_SET_0 0x4600
153#define SPR_MPL_INTCTRL_2_SET_1 0x4601
154#define SPR_MPL_INTCTRL_2_SET_2 0x4602
155#define SPR_MPL_PERF_COUNT_SET_0 0x4200
156#define SPR_MPL_PERF_COUNT_SET_1 0x4201
157#define SPR_MPL_PERF_COUNT_SET_2 0x4202
158#define SPR_MPL_SN_ACCESS_SET_0 0x0800
159#define SPR_MPL_SN_ACCESS_SET_1 0x0801
160#define SPR_MPL_SN_ACCESS_SET_2 0x0802
161#define SPR_MPL_SN_CPL_SET_0 0x5a00
162#define SPR_MPL_SN_CPL_SET_1 0x5a01
163#define SPR_MPL_SN_CPL_SET_2 0x5a02
164#define SPR_MPL_SN_FIREWALL_SET_0 0x2c00
165#define SPR_MPL_SN_FIREWALL_SET_1 0x2c01
166#define SPR_MPL_SN_FIREWALL_SET_2 0x2c02
167#define SPR_MPL_SN_NOTIFY_SET_0 0x2a00
168#define SPR_MPL_SN_NOTIFY_SET_1 0x2a01
169#define SPR_MPL_SN_NOTIFY_SET_2 0x2a02
170#define SPR_MPL_UDN_ACCESS_SET_0 0x0c00
171#define SPR_MPL_UDN_ACCESS_SET_1 0x0c01
172#define SPR_MPL_UDN_ACCESS_SET_2 0x0c02
173#define SPR_MPL_UDN_AVAIL_SET_0 0x4000
174#define SPR_MPL_UDN_AVAIL_SET_1 0x4001
175#define SPR_MPL_UDN_AVAIL_SET_2 0x4002
176#define SPR_MPL_UDN_CA_SET_0 0x3c00
177#define SPR_MPL_UDN_CA_SET_1 0x3c01
178#define SPR_MPL_UDN_CA_SET_2 0x3c02
179#define SPR_MPL_UDN_COMPLETE_SET_0 0x1400
180#define SPR_MPL_UDN_COMPLETE_SET_1 0x1401
181#define SPR_MPL_UDN_COMPLETE_SET_2 0x1402
182#define SPR_MPL_UDN_FIREWALL_SET_0 0x3000
183#define SPR_MPL_UDN_FIREWALL_SET_1 0x3001
184#define SPR_MPL_UDN_FIREWALL_SET_2 0x3002
185#define SPR_MPL_UDN_REFILL_SET_0 0x1000
186#define SPR_MPL_UDN_REFILL_SET_1 0x1001
187#define SPR_MPL_UDN_REFILL_SET_2 0x1002
188#define SPR_MPL_UDN_TIMER_SET_0 0x3600
189#define SPR_MPL_UDN_TIMER_SET_1 0x3601
190#define SPR_MPL_UDN_TIMER_SET_2 0x3602
191#define SPR_MPL_WORLD_ACCESS_SET_0 0x4e00
192#define SPR_MPL_WORLD_ACCESS_SET_1 0x4e01
193#define SPR_MPL_WORLD_ACCESS_SET_2 0x4e02
194#define SPR_PASS 0x4e0b
195#define SPR_PERF_COUNT_0 0x4205
196#define SPR_PERF_COUNT_1 0x4206
197#define SPR_PERF_COUNT_CTL 0x4207
198#define SPR_PERF_COUNT_DN_CTL 0x4210
199#define SPR_PERF_COUNT_STS 0x4208
200#define SPR_PROC_STATUS 0x4f00
201#define SPR_SIM_CONTROL 0x4e0c
202#define SPR_SNCTL 0x0805
203#define SPR_SNCTL__FRZFABRIC_MASK 0x1
204#define SPR_SNSTATIC 0x080c
205#define SPR_SYSTEM_SAVE_0_0 0x4b00
206#define SPR_SYSTEM_SAVE_0_1 0x4b01
207#define SPR_SYSTEM_SAVE_0_2 0x4b02
208#define SPR_SYSTEM_SAVE_0_3 0x4b03
209#define SPR_SYSTEM_SAVE_1_0 0x4900
210#define SPR_SYSTEM_SAVE_1_1 0x4901
211#define SPR_SYSTEM_SAVE_1_2 0x4902
212#define SPR_SYSTEM_SAVE_1_3 0x4903
213#define SPR_SYSTEM_SAVE_2_0 0x4700
214#define SPR_SYSTEM_SAVE_2_1 0x4701
215#define SPR_SYSTEM_SAVE_2_2 0x4702
216#define SPR_SYSTEM_SAVE_2_3 0x4703
217#define SPR_TILE_COORD 0x4c17
218#define SPR_TILE_RTF_HWM 0x4e10
219#define SPR_TILE_TIMER_CONTROL 0x3205
220#define SPR_TILE_WRITE_PENDING 0x4e0f
221#define SPR_UDN_AVAIL_EN 0x4005
222#define SPR_UDN_CA_DATA 0x0d00
223#define SPR_UDN_DATA_AVAIL 0x0d03
224#define SPR_UDN_DEADLOCK_TIMEOUT 0x3606
225#define SPR_UDN_DEMUX_CA_COUNT 0x0c05
226#define SPR_UDN_DEMUX_COUNT_0 0x0c06
227#define SPR_UDN_DEMUX_COUNT_1 0x0c07
228#define SPR_UDN_DEMUX_COUNT_2 0x0c08
229#define SPR_UDN_DEMUX_COUNT_3 0x0c09
230#define SPR_UDN_DEMUX_CTL 0x0c0a
231#define SPR_UDN_DEMUX_QUEUE_SEL 0x0c0c
232#define SPR_UDN_DEMUX_STATUS 0x0c0d
233#define SPR_UDN_DEMUX_WRITE_FIFO 0x0c0e
234#define SPR_UDN_DIRECTION_PROTECT 0x3005
235#define SPR_UDN_PENDING 0x0c10
236#define SPR_UDN_REFILL_EN 0x1005
237#define SPR_UDN_SP_FIFO_DATA 0x0c11
238#define SPR_UDN_SP_FIFO_SEL 0x0c12
239#define SPR_UDN_SP_FREEZE 0x0c13
240#define SPR_UDN_SP_FREEZE__SP_FRZ_MASK 0x1
241#define SPR_UDN_SP_FREEZE__DEMUX_FRZ_MASK 0x2
242#define SPR_UDN_SP_FREEZE__NON_DEST_EXT_MASK 0x4
243#define SPR_UDN_SP_STATE 0x0c14
244#define SPR_UDN_TAG_0 0x0c15
245#define SPR_UDN_TAG_1 0x0c16
246#define SPR_UDN_TAG_2 0x0c17
247#define SPR_UDN_TAG_3 0x0c18
248#define SPR_UDN_TAG_VALID 0x0c19
249#define SPR_UDN_TILE_COORD 0x0c1a
250#define SPR_WATCH_CTL 0x4209
251#define SPR_WATCH_MASK 0x420a
252#define SPR_WATCH_VAL 0x420b
253
254#endif /* !defined(__ARCH_SPR_DEF_32_H__) */
255
256#endif /* !defined(__DOXYGEN__) */
diff --git a/arch/tile/include/uapi/arch/spr_def_64.h b/arch/tile/include/uapi/arch/spr_def_64.h
deleted file mode 100644
index d183cbb31aa7..000000000000
--- a/arch/tile/include/uapi/arch/spr_def_64.h
+++ /dev/null
@@ -1,217 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef __DOXYGEN__
17
18#ifndef __ARCH_SPR_DEF_64_H__
19#define __ARCH_SPR_DEF_64_H__
20
21#define SPR_AUX_PERF_COUNT_0 0x2105
22#define SPR_AUX_PERF_COUNT_1 0x2106
23#define SPR_AUX_PERF_COUNT_CTL 0x2107
24#define SPR_AUX_PERF_COUNT_STS 0x2108
25#define SPR_CMPEXCH_VALUE 0x2780
26#define SPR_CYCLE 0x2781
27#define SPR_DONE 0x2705
28#define SPR_DSTREAM_PF 0x2706
29#define SPR_EVENT_BEGIN 0x2782
30#define SPR_EVENT_END 0x2783
31#define SPR_EX_CONTEXT_0_0 0x2580
32#define SPR_EX_CONTEXT_0_1 0x2581
33#define SPR_EX_CONTEXT_0_1__PL_SHIFT 0
34#define SPR_EX_CONTEXT_0_1__PL_RMASK 0x3
35#define SPR_EX_CONTEXT_0_1__PL_MASK 0x3
36#define SPR_EX_CONTEXT_0_1__ICS_SHIFT 2
37#define SPR_EX_CONTEXT_0_1__ICS_RMASK 0x1
38#define SPR_EX_CONTEXT_0_1__ICS_MASK 0x4
39#define SPR_EX_CONTEXT_1_0 0x2480
40#define SPR_EX_CONTEXT_1_1 0x2481
41#define SPR_EX_CONTEXT_1_1__PL_SHIFT 0
42#define SPR_EX_CONTEXT_1_1__PL_RMASK 0x3
43#define SPR_EX_CONTEXT_1_1__PL_MASK 0x3
44#define SPR_EX_CONTEXT_1_1__ICS_SHIFT 2
45#define SPR_EX_CONTEXT_1_1__ICS_RMASK 0x1
46#define SPR_EX_CONTEXT_1_1__ICS_MASK 0x4
47#define SPR_EX_CONTEXT_2_0 0x2380
48#define SPR_EX_CONTEXT_2_1 0x2381
49#define SPR_EX_CONTEXT_2_1__PL_SHIFT 0
50#define SPR_EX_CONTEXT_2_1__PL_RMASK 0x3
51#define SPR_EX_CONTEXT_2_1__PL_MASK 0x3
52#define SPR_EX_CONTEXT_2_1__ICS_SHIFT 2
53#define SPR_EX_CONTEXT_2_1__ICS_RMASK 0x1
54#define SPR_EX_CONTEXT_2_1__ICS_MASK 0x4
55#define SPR_FAIL 0x2707
56#define SPR_IDN_AVAIL_EN 0x1a05
57#define SPR_IDN_DATA_AVAIL 0x0a80
58#define SPR_IDN_DEADLOCK_TIMEOUT 0x1806
59#define SPR_IDN_DEMUX_COUNT_0 0x0a05
60#define SPR_IDN_DEMUX_COUNT_1 0x0a06
61#define SPR_IDN_DIRECTION_PROTECT 0x1405
62#define SPR_IDN_PENDING 0x0a08
63#define SPR_ILL_TRANS_REASON__I_STREAM_VA_RMASK 0x1
64#define SPR_INTCTRL_0_STATUS 0x2505
65#define SPR_INTCTRL_1_STATUS 0x2405
66#define SPR_INTCTRL_2_STATUS 0x2305
67#define SPR_INTERRUPT_CRITICAL_SECTION 0x2708
68#define SPR_INTERRUPT_MASK_0 0x2506
69#define SPR_INTERRUPT_MASK_1 0x2406
70#define SPR_INTERRUPT_MASK_2 0x2306
71#define SPR_INTERRUPT_MASK_RESET_0 0x2507
72#define SPR_INTERRUPT_MASK_RESET_1 0x2407
73#define SPR_INTERRUPT_MASK_RESET_2 0x2307
74#define SPR_INTERRUPT_MASK_SET_0 0x2508
75#define SPR_INTERRUPT_MASK_SET_1 0x2408
76#define SPR_INTERRUPT_MASK_SET_2 0x2308
77#define SPR_INTERRUPT_VECTOR_BASE_0 0x2509
78#define SPR_INTERRUPT_VECTOR_BASE_1 0x2409
79#define SPR_INTERRUPT_VECTOR_BASE_2 0x2309
80#define SPR_INTERRUPT_VECTOR_BASE_3 0x2209
81#define SPR_IPI_EVENT_0 0x1f05
82#define SPR_IPI_EVENT_1 0x1e05
83#define SPR_IPI_EVENT_2 0x1d05
84#define SPR_IPI_EVENT_RESET_0 0x1f06
85#define SPR_IPI_EVENT_RESET_1 0x1e06
86#define SPR_IPI_EVENT_RESET_2 0x1d06
87#define SPR_IPI_EVENT_SET_0 0x1f07
88#define SPR_IPI_EVENT_SET_1 0x1e07
89#define SPR_IPI_EVENT_SET_2 0x1d07
90#define SPR_IPI_MASK_0 0x1f08
91#define SPR_IPI_MASK_1 0x1e08
92#define SPR_IPI_MASK_2 0x1d08
93#define SPR_IPI_MASK_RESET_0 0x1f09
94#define SPR_IPI_MASK_RESET_1 0x1e09
95#define SPR_IPI_MASK_RESET_2 0x1d09
96#define SPR_IPI_MASK_SET_0 0x1f0a
97#define SPR_IPI_MASK_SET_1 0x1e0a
98#define SPR_IPI_MASK_SET_2 0x1d0a
99#define SPR_MPL_AUX_PERF_COUNT_SET_0 0x2100
100#define SPR_MPL_AUX_PERF_COUNT_SET_1 0x2101
101#define SPR_MPL_AUX_PERF_COUNT_SET_2 0x2102
102#define SPR_MPL_AUX_TILE_TIMER_SET_0 0x1700
103#define SPR_MPL_AUX_TILE_TIMER_SET_1 0x1701
104#define SPR_MPL_AUX_TILE_TIMER_SET_2 0x1702
105#define SPR_MPL_IDN_ACCESS_SET_0 0x0a00
106#define SPR_MPL_IDN_ACCESS_SET_1 0x0a01
107#define SPR_MPL_IDN_ACCESS_SET_2 0x0a02
108#define SPR_MPL_IDN_AVAIL_SET_0 0x1a00
109#define SPR_MPL_IDN_AVAIL_SET_1 0x1a01
110#define SPR_MPL_IDN_AVAIL_SET_2 0x1a02
111#define SPR_MPL_IDN_COMPLETE_SET_0 0x0500
112#define SPR_MPL_IDN_COMPLETE_SET_1 0x0501
113#define SPR_MPL_IDN_COMPLETE_SET_2 0x0502
114#define SPR_MPL_IDN_FIREWALL_SET_0 0x1400
115#define SPR_MPL_IDN_FIREWALL_SET_1 0x1401
116#define SPR_MPL_IDN_FIREWALL_SET_2 0x1402
117#define SPR_MPL_IDN_TIMER_SET_0 0x1800
118#define SPR_MPL_IDN_TIMER_SET_1 0x1801
119#define SPR_MPL_IDN_TIMER_SET_2 0x1802
120#define SPR_MPL_INTCTRL_0_SET_0 0x2500
121#define SPR_MPL_INTCTRL_0_SET_1 0x2501
122#define SPR_MPL_INTCTRL_0_SET_2 0x2502
123#define SPR_MPL_INTCTRL_1_SET_0 0x2400
124#define SPR_MPL_INTCTRL_1_SET_1 0x2401
125#define SPR_MPL_INTCTRL_1_SET_2 0x2402
126#define SPR_MPL_INTCTRL_2_SET_0 0x2300
127#define SPR_MPL_INTCTRL_2_SET_1 0x2301
128#define SPR_MPL_INTCTRL_2_SET_2 0x2302
129#define SPR_MPL_IPI_0 0x1f04
130#define SPR_MPL_IPI_0_SET_0 0x1f00
131#define SPR_MPL_IPI_0_SET_1 0x1f01
132#define SPR_MPL_IPI_0_SET_2 0x1f02
133#define SPR_MPL_IPI_1 0x1e04
134#define SPR_MPL_IPI_1_SET_0 0x1e00
135#define SPR_MPL_IPI_1_SET_1 0x1e01
136#define SPR_MPL_IPI_1_SET_2 0x1e02
137#define SPR_MPL_IPI_2 0x1d04
138#define SPR_MPL_IPI_2_SET_0 0x1d00
139#define SPR_MPL_IPI_2_SET_1 0x1d01
140#define SPR_MPL_IPI_2_SET_2 0x1d02
141#define SPR_MPL_PERF_COUNT_SET_0 0x2000
142#define SPR_MPL_PERF_COUNT_SET_1 0x2001
143#define SPR_MPL_PERF_COUNT_SET_2 0x2002
144#define SPR_MPL_UDN_ACCESS_SET_0 0x0b00
145#define SPR_MPL_UDN_ACCESS_SET_1 0x0b01
146#define SPR_MPL_UDN_ACCESS_SET_2 0x0b02
147#define SPR_MPL_UDN_AVAIL_SET_0 0x1b00
148#define SPR_MPL_UDN_AVAIL_SET_1 0x1b01
149#define SPR_MPL_UDN_AVAIL_SET_2 0x1b02
150#define SPR_MPL_UDN_COMPLETE_SET_0 0x0600
151#define SPR_MPL_UDN_COMPLETE_SET_1 0x0601
152#define SPR_MPL_UDN_COMPLETE_SET_2 0x0602
153#define SPR_MPL_UDN_FIREWALL_SET_0 0x1500
154#define SPR_MPL_UDN_FIREWALL_SET_1 0x1501
155#define SPR_MPL_UDN_FIREWALL_SET_2 0x1502
156#define SPR_MPL_UDN_TIMER_SET_0 0x1900
157#define SPR_MPL_UDN_TIMER_SET_1 0x1901
158#define SPR_MPL_UDN_TIMER_SET_2 0x1902
159#define SPR_MPL_WORLD_ACCESS_SET_0 0x2700
160#define SPR_MPL_WORLD_ACCESS_SET_1 0x2701
161#define SPR_MPL_WORLD_ACCESS_SET_2 0x2702
162#define SPR_PASS 0x2709
163#define SPR_PERF_COUNT_0 0x2005
164#define SPR_PERF_COUNT_1 0x2006
165#define SPR_PERF_COUNT_CTL 0x2007
166#define SPR_PERF_COUNT_DN_CTL 0x2008
167#define SPR_PERF_COUNT_STS 0x2009
168#define SPR_PROC_STATUS 0x2784
169#define SPR_SIM_CONTROL 0x2785
170#define SPR_SINGLE_STEP_CONTROL_0 0x0405
171#define SPR_SINGLE_STEP_CONTROL_0__CANCELED_MASK 0x1
172#define SPR_SINGLE_STEP_CONTROL_0__INHIBIT_MASK 0x2
173#define SPR_SINGLE_STEP_CONTROL_1 0x0305
174#define SPR_SINGLE_STEP_CONTROL_1__CANCELED_MASK 0x1
175#define SPR_SINGLE_STEP_CONTROL_1__INHIBIT_MASK 0x2
176#define SPR_SINGLE_STEP_CONTROL_2 0x0205
177#define SPR_SINGLE_STEP_CONTROL_2__CANCELED_MASK 0x1
178#define SPR_SINGLE_STEP_CONTROL_2__INHIBIT_MASK 0x2
179#define SPR_SINGLE_STEP_EN_0_0 0x250a
180#define SPR_SINGLE_STEP_EN_0_1 0x240a
181#define SPR_SINGLE_STEP_EN_0_2 0x230a
182#define SPR_SINGLE_STEP_EN_1_0 0x250b
183#define SPR_SINGLE_STEP_EN_1_1 0x240b
184#define SPR_SINGLE_STEP_EN_1_2 0x230b
185#define SPR_SINGLE_STEP_EN_2_0 0x250c
186#define SPR_SINGLE_STEP_EN_2_1 0x240c
187#define SPR_SINGLE_STEP_EN_2_2 0x230c
188#define SPR_SYSTEM_SAVE_0_0 0x2582
189#define SPR_SYSTEM_SAVE_0_1 0x2583
190#define SPR_SYSTEM_SAVE_0_2 0x2584
191#define SPR_SYSTEM_SAVE_0_3 0x2585
192#define SPR_SYSTEM_SAVE_1_0 0x2482
193#define SPR_SYSTEM_SAVE_1_1 0x2483
194#define SPR_SYSTEM_SAVE_1_2 0x2484
195#define SPR_SYSTEM_SAVE_1_3 0x2485
196#define SPR_SYSTEM_SAVE_2_0 0x2382
197#define SPR_SYSTEM_SAVE_2_1 0x2383
198#define SPR_SYSTEM_SAVE_2_2 0x2384
199#define SPR_SYSTEM_SAVE_2_3 0x2385
200#define SPR_TILE_COORD 0x270b
201#define SPR_TILE_RTF_HWM 0x270c
202#define SPR_TILE_TIMER_CONTROL 0x1605
203#define SPR_UDN_AVAIL_EN 0x1b05
204#define SPR_UDN_DATA_AVAIL 0x0b80
205#define SPR_UDN_DEADLOCK_TIMEOUT 0x1906
206#define SPR_UDN_DEMUX_COUNT_0 0x0b05
207#define SPR_UDN_DEMUX_COUNT_1 0x0b06
208#define SPR_UDN_DEMUX_COUNT_2 0x0b07
209#define SPR_UDN_DEMUX_COUNT_3 0x0b08
210#define SPR_UDN_DIRECTION_PROTECT 0x1505
211#define SPR_UDN_PENDING 0x0b0a
212#define SPR_WATCH_MASK 0x200a
213#define SPR_WATCH_VAL 0x200b
214
215#endif /* !defined(__ARCH_SPR_DEF_64_H__) */
216
217#endif /* !defined(__DOXYGEN__) */
diff --git a/arch/tile/include/uapi/asm/Kbuild b/arch/tile/include/uapi/asm/Kbuild
deleted file mode 100644
index cc439612bcd5..000000000000
--- a/arch/tile/include/uapi/asm/Kbuild
+++ /dev/null
@@ -1,24 +0,0 @@
1# UAPI Header export list
2include include/uapi/asm-generic/Kbuild.asm
3
4generic-y += bpf_perf_event.h
5generic-y += errno.h
6generic-y += fcntl.h
7generic-y += ioctl.h
8generic-y += ioctls.h
9generic-y += ipcbuf.h
10generic-y += msgbuf.h
11generic-y += param.h
12generic-y += poll.h
13generic-y += posix_types.h
14generic-y += resource.h
15generic-y += sembuf.h
16generic-y += shmbuf.h
17generic-y += shmparam.h
18generic-y += socket.h
19generic-y += sockios.h
20generic-y += statfs.h
21generic-y += termbits.h
22generic-y += termios.h
23generic-y += types.h
24generic-y += ucontext.h
diff --git a/arch/tile/include/uapi/asm/auxvec.h b/arch/tile/include/uapi/asm/auxvec.h
deleted file mode 100644
index 922383ce8f4f..000000000000
--- a/arch/tile/include/uapi/asm/auxvec.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_AUXVEC_H
17#define _ASM_TILE_AUXVEC_H
18
19/* The vDSO location. */
20#define AT_SYSINFO_EHDR 33
21
22#define AT_VECTOR_SIZE_ARCH 1 /* entries in ARCH_DLINFO */
23
24#endif /* _ASM_TILE_AUXVEC_H */
diff --git a/arch/tile/include/uapi/asm/bitsperlong.h b/arch/tile/include/uapi/asm/bitsperlong.h
deleted file mode 100644
index 57cca78c0fbb..000000000000
--- a/arch/tile/include/uapi/asm/bitsperlong.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_BITSPERLONG_H
17#define _ASM_TILE_BITSPERLONG_H
18
19#ifdef __LP64__
20# define __BITS_PER_LONG 64
21#else
22# define __BITS_PER_LONG 32
23#endif
24
25#include <asm-generic/bitsperlong.h>
26
27#endif /* _ASM_TILE_BITSPERLONG_H */
diff --git a/arch/tile/include/uapi/asm/byteorder.h b/arch/tile/include/uapi/asm/byteorder.h
deleted file mode 100644
index d508e61c1e56..000000000000
--- a/arch/tile/include/uapi/asm/byteorder.h
+++ /dev/null
@@ -1,20 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#if defined (__BIG_ENDIAN__)
17#include <linux/byteorder/big_endian.h>
18#else
19#include <linux/byteorder/little_endian.h>
20#endif
diff --git a/arch/tile/include/uapi/asm/cachectl.h b/arch/tile/include/uapi/asm/cachectl.h
deleted file mode 100644
index ed8bac28a1b9..000000000000
--- a/arch/tile/include/uapi/asm/cachectl.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_CACHECTL_H
17#define _ASM_TILE_CACHECTL_H
18
19/*
20 * Options for cacheflush system call.
21 *
22 * The ICACHE flush is performed on all cores currently running the
23 * current process's address space. The intent is for user
24 * applications to be able to modify code, invoke the system call,
25 * then allow arbitrary other threads in the same address space to see
26 * the newly-modified code. Passing a length of CHIP_L1I_CACHE_SIZE()
27 * or more invalidates the entire icache on all cores in the address
28 * spaces. (Note: currently this option invalidates the entire icache
29 * regardless of the requested address and length, but we may choose
30 * to honor the arguments at some point.)
31 *
32 * Flush and invalidation of memory can normally be performed with the
33 * __insn_flush() and __insn_finv() instructions from userspace.
34 * The DCACHE option to the system call allows userspace
35 * to flush the entire L1+L2 data cache from the core. In this case,
36 * the address and length arguments are not used. The DCACHE flush is
37 * restricted to the current core, not all cores in the address space.
38 */
39#define ICACHE (1<<0) /* invalidate L1 instruction cache */
40#define DCACHE (1<<1) /* flush and invalidate data cache */
41#define BCACHE (ICACHE|DCACHE) /* flush both caches */
42
43#endif /* _ASM_TILE_CACHECTL_H */
diff --git a/arch/tile/include/uapi/asm/hardwall.h b/arch/tile/include/uapi/asm/hardwall.h
deleted file mode 100644
index f02e9132ae71..000000000000
--- a/arch/tile/include/uapi/asm/hardwall.h
+++ /dev/null
@@ -1,52 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 *
15 * Provide methods for access control of per-cpu resources like
16 * UDN, IDN, or IPI.
17 */
18
19#ifndef _UAPI_ASM_TILE_HARDWALL_H
20#define _UAPI_ASM_TILE_HARDWALL_H
21
22#include <arch/chip.h>
23#include <linux/ioctl.h>
24
25#define HARDWALL_IOCTL_BASE 0xa2
26
27/*
28 * The HARDWALL_CREATE() ioctl is a macro with a "size" argument.
29 * The resulting ioctl value is passed to the kernel in conjunction
30 * with a pointer to a standard kernel bitmask of cpus.
31 * For network resources (UDN or IDN) the bitmask must physically
32 * represent a rectangular configuration on the chip.
33 * The "size" is the number of bytes of cpu mask data.
34 */
35#define _HARDWALL_CREATE 1
36#define HARDWALL_CREATE(size) \
37 _IOC(_IOC_READ, HARDWALL_IOCTL_BASE, _HARDWALL_CREATE, (size))
38
39#define _HARDWALL_ACTIVATE 2
40#define HARDWALL_ACTIVATE \
41 _IO(HARDWALL_IOCTL_BASE, _HARDWALL_ACTIVATE)
42
43#define _HARDWALL_DEACTIVATE 3
44#define HARDWALL_DEACTIVATE \
45 _IO(HARDWALL_IOCTL_BASE, _HARDWALL_DEACTIVATE)
46
47#define _HARDWALL_GET_ID 4
48#define HARDWALL_GET_ID \
49 _IO(HARDWALL_IOCTL_BASE, _HARDWALL_GET_ID)
50
51
52#endif /* _UAPI_ASM_TILE_HARDWALL_H */
diff --git a/arch/tile/include/uapi/asm/kvm_para.h b/arch/tile/include/uapi/asm/kvm_para.h
deleted file mode 100644
index baacc4996d18..000000000000
--- a/arch/tile/include/uapi/asm/kvm_para.h
+++ /dev/null
@@ -1,2 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2#include <asm-generic/kvm_para.h>
diff --git a/arch/tile/include/uapi/asm/mman.h b/arch/tile/include/uapi/asm/mman.h
deleted file mode 100644
index 9b7add95926b..000000000000
--- a/arch/tile/include/uapi/asm/mman.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_MMAN_H
17#define _ASM_TILE_MMAN_H
18
19#include <asm-generic/mman-common.h>
20#include <arch/chip.h>
21
22/* Standard Linux flags */
23
24#define MAP_POPULATE 0x0040 /* populate (prefault) pagetables */
25#define MAP_NONBLOCK 0x0080 /* do not block on IO */
26#define MAP_GROWSDOWN 0x0100 /* stack-like segment */
27#define MAP_STACK MAP_GROWSDOWN /* provide convenience alias */
28#define MAP_LOCKED 0x0200 /* pages are locked */
29#define MAP_NORESERVE 0x0400 /* don't check for reservations */
30#define MAP_DENYWRITE 0x0800 /* ETXTBSY */
31#define MAP_EXECUTABLE 0x1000 /* mark it as an executable */
32#define MAP_HUGETLB 0x4000 /* create a huge page mapping */
33
34
35/*
36 * Flags for mlockall
37 */
38#define MCL_CURRENT 1 /* lock all current mappings */
39#define MCL_FUTURE 2 /* lock all future mappings */
40#define MCL_ONFAULT 4 /* lock all pages that are faulted in */
41
42
43#endif /* _ASM_TILE_MMAN_H */
diff --git a/arch/tile/include/uapi/asm/ptrace.h b/arch/tile/include/uapi/asm/ptrace.h
deleted file mode 100644
index 667ed742f4dd..000000000000
--- a/arch/tile/include/uapi/asm/ptrace.h
+++ /dev/null
@@ -1,99 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _UAPI_ASM_TILE_PTRACE_H
17#define _UAPI_ASM_TILE_PTRACE_H
18
19#include <arch/chip.h>
20#include <arch/abi.h>
21
22/* These must match struct pt_regs, below. */
23#if CHIP_WORD_SIZE() == 32
24#define PTREGS_OFFSET_REG(n) ((n)*4)
25#else
26#define PTREGS_OFFSET_REG(n) ((n)*8)
27#endif
28#define PTREGS_OFFSET_BASE 0
29#define PTREGS_OFFSET_TP PTREGS_OFFSET_REG(53)
30#define PTREGS_OFFSET_SP PTREGS_OFFSET_REG(54)
31#define PTREGS_OFFSET_LR PTREGS_OFFSET_REG(55)
32#define PTREGS_NR_GPRS 56
33#define PTREGS_OFFSET_PC PTREGS_OFFSET_REG(56)
34#define PTREGS_OFFSET_EX1 PTREGS_OFFSET_REG(57)
35#define PTREGS_OFFSET_FAULTNUM PTREGS_OFFSET_REG(58)
36#define PTREGS_OFFSET_ORIG_R0 PTREGS_OFFSET_REG(59)
37#define PTREGS_OFFSET_FLAGS PTREGS_OFFSET_REG(60)
38#if CHIP_HAS_CMPEXCH()
39#define PTREGS_OFFSET_CMPEXCH PTREGS_OFFSET_REG(61)
40#endif
41#define PTREGS_SIZE PTREGS_OFFSET_REG(64)
42
43
44#ifndef __ASSEMBLY__
45
46#ifndef __KERNEL__
47/* Provide appropriate length type to userspace regardless of -m32/-m64. */
48typedef uint_reg_t pt_reg_t;
49#endif
50
51/*
52 * This struct defines the way the registers are stored on the stack during a
53 * system call or exception. "struct sigcontext" has the same shape.
54 */
55struct pt_regs {
56 union {
57 /* Saved main processor registers; 56..63 are special. */
58 pt_reg_t regs[56];
59 struct {
60 pt_reg_t __regs[53];
61 pt_reg_t tp; /* aliases regs[TREG_TP] */
62 pt_reg_t sp; /* aliases regs[TREG_SP] */
63 pt_reg_t lr; /* aliases regs[TREG_LR] */
64 };
65 };
66
67 /* Saved special registers. */
68 pt_reg_t pc; /* stored in EX_CONTEXT_K_0 */
69 pt_reg_t ex1; /* stored in EX_CONTEXT_K_1 (PL and ICS bit) */
70 pt_reg_t faultnum; /* fault number (INT_SWINT_1 for syscall) */
71 pt_reg_t orig_r0; /* r0 at syscall entry, else zero */
72 pt_reg_t flags; /* flags (see below) */
73#if !CHIP_HAS_CMPEXCH()
74 pt_reg_t pad[3];
75#else
76 pt_reg_t cmpexch; /* value of CMPEXCH_VALUE SPR at interrupt */
77 pt_reg_t pad[2];
78#endif
79};
80
81#endif /* __ASSEMBLY__ */
82
83#define PTRACE_GETREGS 12
84#define PTRACE_SETREGS 13
85#define PTRACE_GETFPREGS 14
86#define PTRACE_SETFPREGS 15
87
88/* Support TILE-specific ptrace options, with events starting at 16. */
89#define PTRACE_EVENT_MIGRATE 16
90#define PTRACE_O_TRACEMIGRATE (1 << PTRACE_EVENT_MIGRATE)
91
92/*
93 * Flag bits in pt_regs.flags that are part of the ptrace API.
94 * We start our numbering higher up to avoid confusion with the
95 * non-ABI kernel-internal values that use the low 16 bits.
96 */
97#define PT_FLAGS_COMPAT 0x10000 /* process is an -m32 compat process */
98
99#endif /* _UAPI_ASM_TILE_PTRACE_H */
diff --git a/arch/tile/include/uapi/asm/setup.h b/arch/tile/include/uapi/asm/setup.h
deleted file mode 100644
index 6d1dfdddad6c..000000000000
--- a/arch/tile/include/uapi/asm/setup.h
+++ /dev/null
@@ -1,22 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _UAPI_ASM_TILE_SETUP_H
17#define _UAPI_ASM_TILE_SETUP_H
18
19#define COMMAND_LINE_SIZE 2048
20
21
22#endif /* _UAPI_ASM_TILE_SETUP_H */
diff --git a/arch/tile/include/uapi/asm/sigcontext.h b/arch/tile/include/uapi/asm/sigcontext.h
deleted file mode 100644
index 4003d5cc9202..000000000000
--- a/arch/tile/include/uapi/asm/sigcontext.h
+++ /dev/null
@@ -1,44 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_SIGCONTEXT_H
17#define _ASM_TILE_SIGCONTEXT_H
18
19/* Don't pollute the namespace since <signal.h> includes this file. */
20#define __need_int_reg_t
21#include <arch/abi.h>
22
23/*
24 * struct sigcontext has the same shape as struct pt_regs,
25 * but is simplified since we know the fault is from userspace.
26 */
27struct sigcontext {
28 __extension__ union {
29 /* General-purpose registers. */
30 __uint_reg_t gregs[56];
31 __extension__ struct {
32 __uint_reg_t __gregs[53];
33 __uint_reg_t tp; /* Aliases gregs[TREG_TP]. */
34 __uint_reg_t sp; /* Aliases gregs[TREG_SP]. */
35 __uint_reg_t lr; /* Aliases gregs[TREG_LR]. */
36 };
37 };
38 __uint_reg_t pc; /* Program counter. */
39 __uint_reg_t ics; /* In Interrupt Critical Section? */
40 __uint_reg_t faultnum; /* Fault number. */
41 __uint_reg_t pad[5];
42};
43
44#endif /* _ASM_TILE_SIGCONTEXT_H */
diff --git a/arch/tile/include/uapi/asm/siginfo.h b/arch/tile/include/uapi/asm/siginfo.h
deleted file mode 100644
index a812fcbf4267..000000000000
--- a/arch/tile/include/uapi/asm/siginfo.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_SIGINFO_H
17#define _ASM_TILE_SIGINFO_H
18
19#define __ARCH_SI_TRAPNO
20
21#ifdef __LP64__
22# define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
23#endif
24
25#include <asm-generic/siginfo.h>
26
27#endif /* _ASM_TILE_SIGINFO_H */
diff --git a/arch/tile/include/uapi/asm/signal.h b/arch/tile/include/uapi/asm/signal.h
deleted file mode 100644
index 7b3c814e00f0..000000000000
--- a/arch/tile/include/uapi/asm/signal.h
+++ /dev/null
@@ -1,28 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _UAPI_ASM_TILE_SIGNAL_H
17#define _UAPI_ASM_TILE_SIGNAL_H
18
19/* Do not notify a ptracer when this signal is handled. */
20#define SA_NOPTRACE 0x02000000u
21
22/* Used in earlier Tilera releases, so keeping for binary compatibility. */
23#define SA_RESTORER 0x04000000u
24
25#include <asm-generic/signal.h>
26
27
28#endif /* _UAPI_ASM_TILE_SIGNAL_H */
diff --git a/arch/tile/include/uapi/asm/stat.h b/arch/tile/include/uapi/asm/stat.h
deleted file mode 100644
index ea03de7d67aa..000000000000
--- a/arch/tile/include/uapi/asm/stat.h
+++ /dev/null
@@ -1,5 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
3#define __ARCH_WANT_STAT64 /* Used for compat_sys_stat64() etc. */
4#endif
5#include <asm-generic/stat.h>
diff --git a/arch/tile/include/uapi/asm/swab.h b/arch/tile/include/uapi/asm/swab.h
deleted file mode 100644
index 36952353a31d..000000000000
--- a/arch/tile/include/uapi/asm/swab.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_SWAB_H
17#define _ASM_TILE_SWAB_H
18
19/* Tile gcc is always >= 4.3.0, so we use __builtin_bswap. */
20#define __arch_swab32(x) __builtin_bswap32(x)
21#define __arch_swab64(x) __builtin_bswap64(x)
22#define __arch_swab16(x) (__builtin_bswap32(x) >> 16)
23
24#endif /* _ASM_TILE_SWAB_H */
diff --git a/arch/tile/include/uapi/asm/unistd.h b/arch/tile/include/uapi/asm/unistd.h
deleted file mode 100644
index 1a169ec92ef8..000000000000
--- a/arch/tile/include/uapi/asm/unistd.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#define __ARCH_WANT_RENAMEAT
17#if !defined(__LP64__) || defined(__SYSCALL_COMPAT)
18/* Use the flavor of this syscall that matches the 32-bit API better. */
19#define __ARCH_WANT_SYNC_FILE_RANGE2
20#endif
21
22/* Use the standard ABI for syscalls. */
23#include <asm-generic/unistd.h>
24
25#define NR_syscalls __NR_syscalls
26
27/* Additional Tilera-specific syscalls. */
28#define __NR_cacheflush (__NR_arch_specific_syscall + 1)
29__SYSCALL(__NR_cacheflush, sys_cacheflush)
30
31#ifndef __tilegx__
32/* "Fast" syscalls provide atomic support for 32-bit chips. */
33#define __NR_FAST_cmpxchg -1
34#define __NR_FAST_atomic_update -2
35#define __NR_FAST_cmpxchg64 -3
36#define __NR_cmpxchg_badaddr (__NR_arch_specific_syscall + 0)
37__SYSCALL(__NR_cmpxchg_badaddr, sys_cmpxchg_badaddr)
38#endif
diff --git a/arch/tile/kernel/Makefile b/arch/tile/kernel/Makefile
deleted file mode 100644
index 3e43d78731a8..000000000000
--- a/arch/tile/kernel/Makefile
+++ /dev/null
@@ -1,38 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2#
3# Makefile for the Linux/TILE kernel.
4#
5
6extra-y := vmlinux.lds head_$(BITS).o
7obj-y := backtrace.o entry.o hvglue.o irq.o messaging.o \
8 pci-dma.o proc.o process.o ptrace.o reboot.o \
9 setup.o signal.o single_step.o stack.o sys.o \
10 sysfs.o time.o traps.o unaligned.o vdso.o \
11 intvec_$(BITS).o regs_$(BITS).o tile-desc_$(BITS).o
12
13ifdef CONFIG_FUNCTION_TRACER
14CFLAGS_REMOVE_ftrace.o = -pg
15CFLAGS_REMOVE_early_printk.o = -pg
16endif
17
18obj-$(CONFIG_HARDWALL) += hardwall.o
19obj-$(CONFIG_COMPAT) += compat.o compat_signal.o
20obj-$(CONFIG_SMP) += smpboot.o smp.o tlb.o
21obj-$(CONFIG_MODULES) += module.o
22obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
23obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel_$(BITS).o
24ifdef CONFIG_TILEGX
25obj-$(CONFIG_PCI) += pci_gx.o
26else
27obj-$(CONFIG_PCI) += pci.o
28endif
29obj-$(CONFIG_PERF_EVENTS) += perf_event.o
30obj-$(CONFIG_USE_PMC) += pmc.o
31obj-$(CONFIG_TILE_USB) += usb.o
32obj-$(CONFIG_TILE_HVGLUE_TRACE) += hvglue_trace.o
33obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o mcount_64.o
34obj-$(CONFIG_KPROBES) += kprobes.o
35obj-$(CONFIG_KGDB) += kgdb.o
36obj-$(CONFIG_JUMP_LABEL) += jump_label.o
37
38obj-y += vdso/
diff --git a/arch/tile/kernel/asm-offsets.c b/arch/tile/kernel/asm-offsets.c
deleted file mode 100644
index 375e7c321eef..000000000000
--- a/arch/tile/kernel/asm-offsets.c
+++ /dev/null
@@ -1,84 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Generates definitions from c-type structures used by assembly sources.
15 */
16
17/* Check for compatible compiler early in the build. */
18#ifdef CONFIG_TILEGX
19# ifndef __tilegx__
20# error Can only build TILE-Gx configurations with tilegx compiler
21# endif
22# ifndef __LP64__
23# error Must not specify -m32 when building the TILE-Gx kernel
24# endif
25#else
26# ifdef __tilegx__
27# error Can not build TILEPro configurations with tilegx compiler
28# endif
29#endif
30
31#include <linux/kbuild.h>
32#include <linux/thread_info.h>
33#include <linux/sched.h>
34#include <linux/hardirq.h>
35#include <linux/ptrace.h>
36#include <hv/hypervisor.h>
37
38void foo(void)
39{
40 DEFINE(SINGLESTEP_STATE_BUFFER_OFFSET,
41 offsetof(struct single_step_state, buffer));
42 DEFINE(SINGLESTEP_STATE_FLAGS_OFFSET,
43 offsetof(struct single_step_state, flags));
44 DEFINE(SINGLESTEP_STATE_ORIG_PC_OFFSET,
45 offsetof(struct single_step_state, orig_pc));
46 DEFINE(SINGLESTEP_STATE_NEXT_PC_OFFSET,
47 offsetof(struct single_step_state, next_pc));
48 DEFINE(SINGLESTEP_STATE_BRANCH_NEXT_PC_OFFSET,
49 offsetof(struct single_step_state, branch_next_pc));
50 DEFINE(SINGLESTEP_STATE_UPDATE_VALUE_OFFSET,
51 offsetof(struct single_step_state, update_value));
52
53 DEFINE(THREAD_INFO_TASK_OFFSET,
54 offsetof(struct thread_info, task));
55 DEFINE(THREAD_INFO_FLAGS_OFFSET,
56 offsetof(struct thread_info, flags));
57 DEFINE(THREAD_INFO_STATUS_OFFSET,
58 offsetof(struct thread_info, status));
59 DEFINE(THREAD_INFO_HOMECACHE_CPU_OFFSET,
60 offsetof(struct thread_info, homecache_cpu));
61 DEFINE(THREAD_INFO_PREEMPT_COUNT_OFFSET,
62 offsetof(struct thread_info, preempt_count));
63 DEFINE(THREAD_INFO_STEP_STATE_OFFSET,
64 offsetof(struct thread_info, step_state));
65#ifdef __tilegx__
66 DEFINE(THREAD_INFO_UNALIGN_JIT_BASE_OFFSET,
67 offsetof(struct thread_info, unalign_jit_base));
68 DEFINE(THREAD_INFO_UNALIGN_JIT_TMP_OFFSET,
69 offsetof(struct thread_info, unalign_jit_tmp));
70#endif
71
72 DEFINE(TASK_STRUCT_THREAD_KSP_OFFSET,
73 offsetof(struct task_struct, thread.ksp));
74 DEFINE(TASK_STRUCT_THREAD_PC_OFFSET,
75 offsetof(struct task_struct, thread.pc));
76
77 DEFINE(HV_TOPOLOGY_WIDTH_OFFSET,
78 offsetof(HV_Topology, width));
79 DEFINE(HV_TOPOLOGY_HEIGHT_OFFSET,
80 offsetof(HV_Topology, height));
81
82 DEFINE(IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET,
83 offsetof(irq_cpustat_t, irq_syscall_count));
84}
diff --git a/arch/tile/kernel/backtrace.c b/arch/tile/kernel/backtrace.c
deleted file mode 100644
index f8b74ca83b92..000000000000
--- a/arch/tile/kernel/backtrace.c
+++ /dev/null
@@ -1,683 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/kernel.h>
16#include <linux/string.h>
17#include <asm/byteorder.h>
18#include <asm/backtrace.h>
19#include <asm/tile-desc.h>
20#include <arch/abi.h>
21
22#ifdef __tilegx__
23#define TILE_MAX_INSTRUCTIONS_PER_BUNDLE TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE
24#define tile_decoded_instruction tilegx_decoded_instruction
25#define tile_mnemonic tilegx_mnemonic
26#define parse_insn_tile parse_insn_tilegx
27#define TILE_OPC_IRET TILEGX_OPC_IRET
28#define TILE_OPC_ADDI TILEGX_OPC_ADDI
29#define TILE_OPC_ADDLI TILEGX_OPC_ADDLI
30#define TILE_OPC_INFO TILEGX_OPC_INFO
31#define TILE_OPC_INFOL TILEGX_OPC_INFOL
32#define TILE_OPC_JRP TILEGX_OPC_JRP
33#define TILE_OPC_MOVE TILEGX_OPC_MOVE
34#define OPCODE_STORE TILEGX_OPC_ST
35typedef long long bt_int_reg_t;
36#else
37#define TILE_MAX_INSTRUCTIONS_PER_BUNDLE TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE
38#define tile_decoded_instruction tilepro_decoded_instruction
39#define tile_mnemonic tilepro_mnemonic
40#define parse_insn_tile parse_insn_tilepro
41#define TILE_OPC_IRET TILEPRO_OPC_IRET
42#define TILE_OPC_ADDI TILEPRO_OPC_ADDI
43#define TILE_OPC_ADDLI TILEPRO_OPC_ADDLI
44#define TILE_OPC_INFO TILEPRO_OPC_INFO
45#define TILE_OPC_INFOL TILEPRO_OPC_INFOL
46#define TILE_OPC_JRP TILEPRO_OPC_JRP
47#define TILE_OPC_MOVE TILEPRO_OPC_MOVE
48#define OPCODE_STORE TILEPRO_OPC_SW
49typedef int bt_int_reg_t;
50#endif
51
52/* A decoded bundle used for backtracer analysis. */
53struct BacktraceBundle {
54 tile_bundle_bits bits;
55 int num_insns;
56 struct tile_decoded_instruction
57 insns[TILE_MAX_INSTRUCTIONS_PER_BUNDLE];
58};
59
60
61/* Locates an instruction inside the given bundle that
62 * has the specified mnemonic, and whose first 'num_operands_to_match'
63 * operands exactly match those in 'operand_values'.
64 */
65static const struct tile_decoded_instruction *find_matching_insn(
66 const struct BacktraceBundle *bundle,
67 tile_mnemonic mnemonic,
68 const int *operand_values,
69 int num_operands_to_match)
70{
71 int i, j;
72 bool match;
73
74 for (i = 0; i < bundle->num_insns; i++) {
75 const struct tile_decoded_instruction *insn =
76 &bundle->insns[i];
77
78 if (insn->opcode->mnemonic != mnemonic)
79 continue;
80
81 match = true;
82 for (j = 0; j < num_operands_to_match; j++) {
83 if (operand_values[j] != insn->operand_values[j]) {
84 match = false;
85 break;
86 }
87 }
88
89 if (match)
90 return insn;
91 }
92
93 return NULL;
94}
95
96/* Does this bundle contain an 'iret' instruction? */
97static inline bool bt_has_iret(const struct BacktraceBundle *bundle)
98{
99 return find_matching_insn(bundle, TILE_OPC_IRET, NULL, 0) != NULL;
100}
101
102/* Does this bundle contain an 'addi sp, sp, OFFSET' or
103 * 'addli sp, sp, OFFSET' instruction, and if so, what is OFFSET?
104 */
105static bool bt_has_addi_sp(const struct BacktraceBundle *bundle, int *adjust)
106{
107 static const int vals[2] = { TREG_SP, TREG_SP };
108
109 const struct tile_decoded_instruction *insn =
110 find_matching_insn(bundle, TILE_OPC_ADDI, vals, 2);
111 if (insn == NULL)
112 insn = find_matching_insn(bundle, TILE_OPC_ADDLI, vals, 2);
113#ifdef __tilegx__
114 if (insn == NULL)
115 insn = find_matching_insn(bundle, TILEGX_OPC_ADDXLI, vals, 2);
116 if (insn == NULL)
117 insn = find_matching_insn(bundle, TILEGX_OPC_ADDXI, vals, 2);
118#endif
119 if (insn == NULL)
120 return false;
121
122 *adjust = insn->operand_values[2];
123 return true;
124}
125
126/* Does this bundle contain any 'info OP' or 'infol OP'
127 * instruction, and if so, what are their OP? Note that OP is interpreted
128 * as an unsigned value by this code since that's what the caller wants.
129 * Returns the number of info ops found.
130 */
131static int bt_get_info_ops(const struct BacktraceBundle *bundle,
132 int operands[MAX_INFO_OPS_PER_BUNDLE])
133{
134 int num_ops = 0;
135 int i;
136
137 for (i = 0; i < bundle->num_insns; i++) {
138 const struct tile_decoded_instruction *insn =
139 &bundle->insns[i];
140
141 if (insn->opcode->mnemonic == TILE_OPC_INFO ||
142 insn->opcode->mnemonic == TILE_OPC_INFOL) {
143 operands[num_ops++] = insn->operand_values[0];
144 }
145 }
146
147 return num_ops;
148}
149
150/* Does this bundle contain a jrp instruction, and if so, to which
151 * register is it jumping?
152 */
153static bool bt_has_jrp(const struct BacktraceBundle *bundle, int *target_reg)
154{
155 const struct tile_decoded_instruction *insn =
156 find_matching_insn(bundle, TILE_OPC_JRP, NULL, 0);
157 if (insn == NULL)
158 return false;
159
160 *target_reg = insn->operand_values[0];
161 return true;
162}
163
164/* Does this bundle modify the specified register in any way? */
165static bool bt_modifies_reg(const struct BacktraceBundle *bundle, int reg)
166{
167 int i, j;
168 for (i = 0; i < bundle->num_insns; i++) {
169 const struct tile_decoded_instruction *insn =
170 &bundle->insns[i];
171
172 if (insn->opcode->implicitly_written_register == reg)
173 return true;
174
175 for (j = 0; j < insn->opcode->num_operands; j++)
176 if (insn->operands[j]->is_dest_reg &&
177 insn->operand_values[j] == reg)
178 return true;
179 }
180
181 return false;
182}
183
184/* Does this bundle modify sp? */
185static inline bool bt_modifies_sp(const struct BacktraceBundle *bundle)
186{
187 return bt_modifies_reg(bundle, TREG_SP);
188}
189
190/* Does this bundle modify lr? */
191static inline bool bt_modifies_lr(const struct BacktraceBundle *bundle)
192{
193 return bt_modifies_reg(bundle, TREG_LR);
194}
195
196/* Does this bundle contain the instruction 'move fp, sp'? */
197static inline bool bt_has_move_r52_sp(const struct BacktraceBundle *bundle)
198{
199 static const int vals[2] = { 52, TREG_SP };
200 return find_matching_insn(bundle, TILE_OPC_MOVE, vals, 2) != NULL;
201}
202
203/* Does this bundle contain a store of lr to sp? */
204static inline bool bt_has_sw_sp_lr(const struct BacktraceBundle *bundle)
205{
206 static const int vals[2] = { TREG_SP, TREG_LR };
207 return find_matching_insn(bundle, OPCODE_STORE, vals, 2) != NULL;
208}
209
210#ifdef __tilegx__
211/* Track moveli values placed into registers. */
212static inline void bt_update_moveli(const struct BacktraceBundle *bundle,
213 int moveli_args[])
214{
215 int i;
216 for (i = 0; i < bundle->num_insns; i++) {
217 const struct tile_decoded_instruction *insn =
218 &bundle->insns[i];
219
220 if (insn->opcode->mnemonic == TILEGX_OPC_MOVELI) {
221 int reg = insn->operand_values[0];
222 moveli_args[reg] = insn->operand_values[1];
223 }
224 }
225}
226
227/* Does this bundle contain an 'add sp, sp, reg' instruction
228 * from a register that we saw a moveli into, and if so, what
229 * is the value in the register?
230 */
231static bool bt_has_add_sp(const struct BacktraceBundle *bundle, int *adjust,
232 int moveli_args[])
233{
234 static const int vals[2] = { TREG_SP, TREG_SP };
235
236 const struct tile_decoded_instruction *insn =
237 find_matching_insn(bundle, TILEGX_OPC_ADDX, vals, 2);
238 if (insn) {
239 int reg = insn->operand_values[2];
240 if (moveli_args[reg]) {
241 *adjust = moveli_args[reg];
242 return true;
243 }
244 }
245 return false;
246}
247#endif
248
249/* Locates the caller's PC and SP for a program starting at the
250 * given address.
251 */
252static void find_caller_pc_and_caller_sp(CallerLocation *location,
253 const unsigned long start_pc,
254 BacktraceMemoryReader read_memory_func,
255 void *read_memory_func_extra)
256{
257 /* Have we explicitly decided what the sp is,
258 * rather than just the default?
259 */
260 bool sp_determined = false;
261
262 /* Has any bundle seen so far modified lr? */
263 bool lr_modified = false;
264
265 /* Have we seen a move from sp to fp? */
266 bool sp_moved_to_r52 = false;
267
268 /* Have we seen a terminating bundle? */
269 bool seen_terminating_bundle = false;
270
271 /* Cut down on round-trip reading overhead by reading several
272 * bundles at a time.
273 */
274 tile_bundle_bits prefetched_bundles[32];
275 int num_bundles_prefetched = 0;
276 int next_bundle = 0;
277 unsigned long pc;
278
279#ifdef __tilegx__
280 /* Naively try to track moveli values to support addx for -m32. */
281 int moveli_args[TILEGX_NUM_REGISTERS] = { 0 };
282#endif
283
284 /* Default to assuming that the caller's sp is the current sp.
285 * This is necessary to handle the case where we start backtracing
286 * right at the end of the epilog.
287 */
288 location->sp_location = SP_LOC_OFFSET;
289 location->sp_offset = 0;
290
291 /* Default to having no idea where the caller PC is. */
292 location->pc_location = PC_LOC_UNKNOWN;
293
294 /* Don't even try if the PC is not aligned. */
295 if (start_pc % TILE_BUNDLE_ALIGNMENT_IN_BYTES != 0)
296 return;
297
298 for (pc = start_pc;; pc += sizeof(tile_bundle_bits)) {
299
300 struct BacktraceBundle bundle;
301 int num_info_ops, info_operands[MAX_INFO_OPS_PER_BUNDLE];
302 int one_ago, jrp_reg;
303 bool has_jrp;
304
305 if (next_bundle >= num_bundles_prefetched) {
306 /* Prefetch some bytes, but don't cross a page
307 * boundary since that might cause a read failure we
308 * don't care about if we only need the first few
309 * bytes. Note: we don't care what the actual page
310 * size is; using the minimum possible page size will
311 * prevent any problems.
312 */
313 unsigned int bytes_to_prefetch = 4096 - (pc & 4095);
314 if (bytes_to_prefetch > sizeof prefetched_bundles)
315 bytes_to_prefetch = sizeof prefetched_bundles;
316
317 if (!read_memory_func(prefetched_bundles, pc,
318 bytes_to_prefetch,
319 read_memory_func_extra)) {
320 if (pc == start_pc) {
321 /* The program probably called a bad
322 * address, such as a NULL pointer.
323 * So treat this as if we are at the
324 * start of the function prolog so the
325 * backtrace will show how we got here.
326 */
327 location->pc_location = PC_LOC_IN_LR;
328 return;
329 }
330
331 /* Unreadable address. Give up. */
332 break;
333 }
334
335 next_bundle = 0;
336 num_bundles_prefetched =
337 bytes_to_prefetch / sizeof(tile_bundle_bits);
338 }
339
340 /*
341 * Decode the next bundle.
342 * TILE always stores instruction bundles in little-endian
343 * mode, even when the chip is running in big-endian mode.
344 */
345 bundle.bits = le64_to_cpu(prefetched_bundles[next_bundle++]);
346 bundle.num_insns =
347 parse_insn_tile(bundle.bits, pc, bundle.insns);
348 num_info_ops = bt_get_info_ops(&bundle, info_operands);
349
350 /* First look at any one_ago info ops if they are interesting,
351 * since they should shadow any non-one-ago info ops.
352 */
353 for (one_ago = (pc != start_pc) ? 1 : 0;
354 one_ago >= 0; one_ago--) {
355 int i;
356 for (i = 0; i < num_info_ops; i++) {
357 int info_operand = info_operands[i];
358 if (info_operand < CALLER_UNKNOWN_BASE) {
359 /* Weird; reserved value, ignore it. */
360 continue;
361 }
362
363 /* Skip info ops which are not in the
364 * "one_ago" mode we want right now.
365 */
366 if (((info_operand & ONE_BUNDLE_AGO_FLAG) != 0)
367 != (one_ago != 0))
368 continue;
369
370 /* Clear the flag to make later checking
371 * easier. */
372 info_operand &= ~ONE_BUNDLE_AGO_FLAG;
373
374 /* Default to looking at PC_IN_LR_FLAG. */
375 if (info_operand & PC_IN_LR_FLAG)
376 location->pc_location =
377 PC_LOC_IN_LR;
378 else
379 location->pc_location =
380 PC_LOC_ON_STACK;
381
382 switch (info_operand) {
383 case CALLER_UNKNOWN_BASE:
384 location->pc_location = PC_LOC_UNKNOWN;
385 location->sp_location = SP_LOC_UNKNOWN;
386 return;
387
388 case CALLER_SP_IN_R52_BASE:
389 case CALLER_SP_IN_R52_BASE | PC_IN_LR_FLAG:
390 location->sp_location = SP_LOC_IN_R52;
391 return;
392
393 default:
394 {
395 const unsigned int val = info_operand
396 - CALLER_SP_OFFSET_BASE;
397 const unsigned int sp_offset =
398 (val >> NUM_INFO_OP_FLAGS) * 8;
399 if (sp_offset < 32768) {
400 /* This is a properly encoded
401 * SP offset. */
402 location->sp_location =
403 SP_LOC_OFFSET;
404 location->sp_offset =
405 sp_offset;
406 return;
407 } else {
408 /* This looked like an SP
409 * offset, but it's outside
410 * the legal range, so this
411 * must be an unrecognized
412 * info operand. Ignore it.
413 */
414 }
415 }
416 break;
417 }
418 }
419 }
420
421 if (seen_terminating_bundle) {
422 /* We saw a terminating bundle during the previous
423 * iteration, so we were only looking for an info op.
424 */
425 break;
426 }
427
428 if (bundle.bits == 0) {
429 /* Wacky terminating bundle. Stop looping, and hope
430 * we've already seen enough to find the caller.
431 */
432 break;
433 }
434
435 /*
436 * Try to determine caller's SP.
437 */
438
439 if (!sp_determined) {
440 int adjust;
441 if (bt_has_addi_sp(&bundle, &adjust)
442#ifdef __tilegx__
443 || bt_has_add_sp(&bundle, &adjust, moveli_args)
444#endif
445 ) {
446 location->sp_location = SP_LOC_OFFSET;
447
448 if (adjust <= 0) {
449 /* We are in prolog about to adjust
450 * SP. */
451 location->sp_offset = 0;
452 } else {
453 /* We are in epilog restoring SP. */
454 location->sp_offset = adjust;
455 }
456
457 sp_determined = true;
458 } else {
459 if (bt_has_move_r52_sp(&bundle)) {
460 /* Maybe in prolog, creating an
461 * alloca-style frame. But maybe in
462 * the middle of a fixed-size frame
463 * clobbering r52 with SP.
464 */
465 sp_moved_to_r52 = true;
466 }
467
468 if (bt_modifies_sp(&bundle)) {
469 if (sp_moved_to_r52) {
470 /* We saw SP get saved into
471 * r52 earlier (or now), which
472 * must have been in the
473 * prolog, so we now know that
474 * SP is still holding the
475 * caller's sp value.
476 */
477 location->sp_location =
478 SP_LOC_OFFSET;
479 location->sp_offset = 0;
480 } else {
481 /* Someone must have saved
482 * aside the caller's SP value
483 * into r52, so r52 holds the
484 * current value.
485 */
486 location->sp_location =
487 SP_LOC_IN_R52;
488 }
489 sp_determined = true;
490 }
491 }
492
493#ifdef __tilegx__
494 /* Track moveli arguments for -m32 mode. */
495 bt_update_moveli(&bundle, moveli_args);
496#endif
497 }
498
499 if (bt_has_iret(&bundle)) {
500 /* This is a terminating bundle. */
501 seen_terminating_bundle = true;
502 continue;
503 }
504
505 /*
506 * Try to determine caller's PC.
507 */
508
509 jrp_reg = -1;
510 has_jrp = bt_has_jrp(&bundle, &jrp_reg);
511 if (has_jrp)
512 seen_terminating_bundle = true;
513
514 if (location->pc_location == PC_LOC_UNKNOWN) {
515 if (has_jrp) {
516 if (jrp_reg == TREG_LR && !lr_modified) {
517 /* Looks like a leaf function, or else
518 * lr is already restored. */
519 location->pc_location =
520 PC_LOC_IN_LR;
521 } else {
522 location->pc_location =
523 PC_LOC_ON_STACK;
524 }
525 } else if (bt_has_sw_sp_lr(&bundle)) {
526 /* In prolog, spilling initial lr to stack. */
527 location->pc_location = PC_LOC_IN_LR;
528 } else if (bt_modifies_lr(&bundle)) {
529 lr_modified = true;
530 }
531 }
532 }
533}
534
535/* Initializes a backtracer to start from the given location.
536 *
537 * If the frame pointer cannot be determined it is set to -1.
538 *
539 * state: The state to be filled in.
540 * read_memory_func: A callback that reads memory.
541 * read_memory_func_extra: An arbitrary argument to read_memory_func.
542 * pc: The current PC.
543 * lr: The current value of the 'lr' register.
544 * sp: The current value of the 'sp' register.
545 * r52: The current value of the 'r52' register.
546 */
547void backtrace_init(BacktraceIterator *state,
548 BacktraceMemoryReader read_memory_func,
549 void *read_memory_func_extra,
550 unsigned long pc, unsigned long lr,
551 unsigned long sp, unsigned long r52)
552{
553 CallerLocation location;
554 unsigned long fp, initial_frame_caller_pc;
555
556 /* Find out where we are in the initial frame. */
557 find_caller_pc_and_caller_sp(&location, pc,
558 read_memory_func, read_memory_func_extra);
559
560 switch (location.sp_location) {
561 case SP_LOC_UNKNOWN:
562 /* Give up. */
563 fp = -1;
564 break;
565
566 case SP_LOC_IN_R52:
567 fp = r52;
568 break;
569
570 case SP_LOC_OFFSET:
571 fp = sp + location.sp_offset;
572 break;
573
574 default:
575 /* Give up. */
576 fp = -1;
577 break;
578 }
579
580 /* If the frame pointer is not aligned to the basic word size
581 * something terrible happened and we should mark it as invalid.
582 */
583 if (fp % sizeof(bt_int_reg_t) != 0)
584 fp = -1;
585
586 /* -1 means "don't know initial_frame_caller_pc". */
587 initial_frame_caller_pc = -1;
588
589 switch (location.pc_location) {
590 case PC_LOC_UNKNOWN:
591 /* Give up. */
592 fp = -1;
593 break;
594
595 case PC_LOC_IN_LR:
596 if (lr == 0 || lr % TILE_BUNDLE_ALIGNMENT_IN_BYTES != 0) {
597 /* Give up. */
598 fp = -1;
599 } else {
600 initial_frame_caller_pc = lr;
601 }
602 break;
603
604 case PC_LOC_ON_STACK:
605 /* Leave initial_frame_caller_pc as -1,
606 * meaning check the stack.
607 */
608 break;
609
610 default:
611 /* Give up. */
612 fp = -1;
613 break;
614 }
615
616 state->pc = pc;
617 state->sp = sp;
618 state->fp = fp;
619 state->initial_frame_caller_pc = initial_frame_caller_pc;
620 state->read_memory_func = read_memory_func;
621 state->read_memory_func_extra = read_memory_func_extra;
622}
623
624/* Handle the case where the register holds more bits than the VA. */
625static bool valid_addr_reg(bt_int_reg_t reg)
626{
627 return ((unsigned long)reg == reg);
628}
629
630/* Advances the backtracing state to the calling frame, returning
631 * true iff successful.
632 */
633bool backtrace_next(BacktraceIterator *state)
634{
635 unsigned long next_fp, next_pc;
636 bt_int_reg_t next_frame[2];
637
638 if (state->fp == -1) {
639 /* No parent frame. */
640 return false;
641 }
642
643 /* Try to read the frame linkage data chaining to the next function. */
644 if (!state->read_memory_func(&next_frame, state->fp, sizeof next_frame,
645 state->read_memory_func_extra)) {
646 return false;
647 }
648
649 next_fp = next_frame[1];
650 if (!valid_addr_reg(next_frame[1]) ||
651 next_fp % sizeof(bt_int_reg_t) != 0) {
652 /* Caller's frame pointer is suspect, so give up. */
653 return false;
654 }
655
656 if (state->initial_frame_caller_pc != -1) {
657 /* We must be in the initial stack frame and already know the
658 * caller PC.
659 */
660 next_pc = state->initial_frame_caller_pc;
661
662 /* Force reading stack next time, in case we were in the
663 * initial frame. We don't do this above just to paranoidly
664 * avoid changing the struct at all when we return false.
665 */
666 state->initial_frame_caller_pc = -1;
667 } else {
668 /* Get the caller PC from the frame linkage area. */
669 next_pc = next_frame[0];
670 if (!valid_addr_reg(next_frame[0]) || next_pc == 0 ||
671 next_pc % TILE_BUNDLE_ALIGNMENT_IN_BYTES != 0) {
672 /* The PC is suspect, so give up. */
673 return false;
674 }
675 }
676
677 /* Update state to become the caller's stack frame. */
678 state->pc = next_pc;
679 state->sp = state->fp;
680 state->fp = next_fp;
681
682 return true;
683}
diff --git a/arch/tile/kernel/compat.c b/arch/tile/kernel/compat.c
deleted file mode 100644
index bdaf71d31a4a..000000000000
--- a/arch/tile/kernel/compat.c
+++ /dev/null
@@ -1,117 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/* Adjust unistd.h to provide 32-bit numbers and functions. */
16#define __SYSCALL_COMPAT
17
18#include <linux/compat.h>
19#include <linux/syscalls.h>
20#include <linux/kdev_t.h>
21#include <linux/fs.h>
22#include <linux/fcntl.h>
23#include <linux/uaccess.h>
24#include <linux/signal.h>
25#include <asm/syscalls.h>
26#include <asm/byteorder.h>
27
28/*
29 * Syscalls that take 64-bit numbers traditionally take them in 32-bit
30 * "high" and "low" value parts on 32-bit architectures.
31 * In principle, one could imagine passing some register arguments as
32 * fully 64-bit on TILE-Gx in 32-bit mode, but it seems easier to
33 * adopt the usual convention.
34 */
35
36#ifdef __BIG_ENDIAN
37#define SYSCALL_PAIR(name) u32, name ## _hi, u32, name ## _lo
38#else
39#define SYSCALL_PAIR(name) u32, name ## _lo, u32, name ## _hi
40#endif
41
42COMPAT_SYSCALL_DEFINE4(truncate64, char __user *, filename, u32, dummy,
43 SYSCALL_PAIR(length))
44{
45 return sys_truncate(filename, ((loff_t)length_hi << 32) | length_lo);
46}
47
48COMPAT_SYSCALL_DEFINE4(ftruncate64, unsigned int, fd, u32, dummy,
49 SYSCALL_PAIR(length))
50{
51 return sys_ftruncate(fd, ((loff_t)length_hi << 32) | length_lo);
52}
53
54COMPAT_SYSCALL_DEFINE6(pread64, unsigned int, fd, char __user *, ubuf,
55 size_t, count, u32, dummy, SYSCALL_PAIR(offset))
56{
57 return sys_pread64(fd, ubuf, count,
58 ((loff_t)offset_hi << 32) | offset_lo);
59}
60
61COMPAT_SYSCALL_DEFINE6(pwrite64, unsigned int, fd, char __user *, ubuf,
62 size_t, count, u32, dummy, SYSCALL_PAIR(offset))
63{
64 return sys_pwrite64(fd, ubuf, count,
65 ((loff_t)offset_hi << 32) | offset_lo);
66}
67
68COMPAT_SYSCALL_DEFINE6(sync_file_range2, int, fd, unsigned int, flags,
69 SYSCALL_PAIR(offset), SYSCALL_PAIR(nbytes))
70{
71 return sys_sync_file_range(fd, ((loff_t)offset_hi << 32) | offset_lo,
72 ((loff_t)nbytes_hi << 32) | nbytes_lo,
73 flags);
74}
75
76COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode,
77 SYSCALL_PAIR(offset), SYSCALL_PAIR(len))
78{
79 return sys_fallocate(fd, mode, ((loff_t)offset_hi << 32) | offset_lo,
80 ((loff_t)len_hi << 32) | len_lo);
81}
82
83/*
84 * Avoid bug in generic sys_llseek() that specifies offset_high and
85 * offset_low as "unsigned long", thus making it possible to pass
86 * a sign-extended high 32 bits in offset_low.
87 * Note that we do not use SYSCALL_PAIR here since glibc passes the
88 * high and low parts explicitly in that order.
89 */
90COMPAT_SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned int, offset_high,
91 unsigned int, offset_low, loff_t __user *, result,
92 unsigned int, origin)
93{
94 return sys_llseek(fd, offset_high, offset_low, result, origin);
95}
96
97/* Provide the compat syscall number to call mapping. */
98#undef __SYSCALL
99#define __SYSCALL(nr, call) [nr] = (call),
100
101/* See comments in sys.c */
102#define compat_sys_fadvise64_64 sys32_fadvise64_64
103#define compat_sys_readahead sys32_readahead
104#define sys_llseek compat_sys_llseek
105
106/* Call the assembly trampolines where necessary. */
107#define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn
108#define sys_clone _sys_clone
109
110/*
111 * Note that we can't include <linux/unistd.h> here since the header
112 * guard will defeat us; <asm/unistd.h> checks for __SYSCALL as well.
113 */
114void *compat_sys_call_table[__NR_syscalls] = {
115 [0 ... __NR_syscalls-1] = sys_ni_syscall,
116#include <asm/unistd.h>
117};
diff --git a/arch/tile/kernel/compat_signal.c b/arch/tile/kernel/compat_signal.c
deleted file mode 100644
index a703bd0e0488..000000000000
--- a/arch/tile/kernel/compat_signal.c
+++ /dev/null
@@ -1,172 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/sched.h>
16#include <linux/sched/task_stack.h>
17#include <linux/mm.h>
18#include <linux/smp.h>
19#include <linux/kernel.h>
20#include <linux/signal.h>
21#include <linux/errno.h>
22#include <linux/wait.h>
23#include <linux/unistd.h>
24#include <linux/stddef.h>
25#include <linux/personality.h>
26#include <linux/suspend.h>
27#include <linux/ptrace.h>
28#include <linux/elf.h>
29#include <linux/compat.h>
30#include <linux/syscalls.h>
31#include <linux/uaccess.h>
32#include <asm/processor.h>
33#include <asm/ucontext.h>
34#include <asm/sigframe.h>
35#include <asm/syscalls.h>
36#include <asm/vdso.h>
37#include <arch/interrupts.h>
38
39struct compat_ucontext {
40 compat_ulong_t uc_flags;
41 compat_uptr_t uc_link;
42 struct compat_sigaltstack uc_stack;
43 struct sigcontext uc_mcontext;
44 sigset_t uc_sigmask; /* mask last for extensibility */
45};
46
47struct compat_rt_sigframe {
48 unsigned char save_area[C_ABI_SAVE_AREA_SIZE]; /* caller save area */
49 struct compat_siginfo info;
50 struct compat_ucontext uc;
51};
52
53/* The assembly shim for this function arranges to ignore the return value. */
54long compat_sys_rt_sigreturn(void)
55{
56 struct pt_regs *regs = current_pt_regs();
57 struct compat_rt_sigframe __user *frame =
58 (struct compat_rt_sigframe __user *) compat_ptr(regs->sp);
59 sigset_t set;
60
61 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
62 goto badframe;
63 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
64 goto badframe;
65
66 set_current_blocked(&set);
67
68 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
69 goto badframe;
70
71 if (compat_restore_altstack(&frame->uc.uc_stack))
72 goto badframe;
73
74 return 0;
75
76badframe:
77 signal_fault("bad sigreturn frame", regs, frame, 0);
78 return 0;
79}
80
81/*
82 * Determine which stack to use..
83 */
84static inline void __user *compat_get_sigframe(struct k_sigaction *ka,
85 struct pt_regs *regs,
86 size_t frame_size)
87{
88 unsigned long sp;
89
90 /* Default to using normal stack */
91 sp = (unsigned long)compat_ptr(regs->sp);
92
93 /*
94 * If we are on the alternate signal stack and would overflow
95 * it, don't. Return an always-bogus address instead so we
96 * will die with SIGSEGV.
97 */
98 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
99 return (void __user __force *)-1UL;
100
101 /* This is the X/Open sanctioned signal stack switching. */
102 if (ka->sa.sa_flags & SA_ONSTACK) {
103 if (sas_ss_flags(sp) == 0)
104 sp = current->sas_ss_sp + current->sas_ss_size;
105 }
106
107 sp -= frame_size;
108 /*
109 * Align the stack pointer according to the TILE ABI,
110 * i.e. so that on function entry (sp & 15) == 0.
111 */
112 sp &= -16UL;
113 return (void __user *) sp;
114}
115
116int compat_setup_rt_frame(struct ksignal *ksig, sigset_t *set,
117 struct pt_regs *regs)
118{
119 unsigned long restorer;
120 struct compat_rt_sigframe __user *frame;
121 int err = 0, sig = ksig->sig;
122
123 frame = compat_get_sigframe(&ksig->ka, regs, sizeof(*frame));
124
125 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
126 goto err;
127
128 /* Always write at least the signal number for the stack backtracer. */
129 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
130 /* At sigreturn time, restore the callee-save registers too. */
131 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
132 regs->flags |= PT_FLAGS_RESTORE_REGS;
133 } else {
134 err |= __put_user(ksig->info.si_signo, &frame->info.si_signo);
135 }
136
137 /* Create the ucontext. */
138 err |= __clear_user(&frame->save_area, sizeof(frame->save_area));
139 err |= __put_user(0, &frame->uc.uc_flags);
140 err |= __put_user(0, &frame->uc.uc_link);
141 err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
142 err |= setup_sigcontext(&frame->uc.uc_mcontext, regs);
143 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
144 if (err)
145 goto err;
146
147 restorer = VDSO_SYM(&__vdso_rt_sigreturn);
148 if (ksig->ka.sa.sa_flags & SA_RESTORER)
149 restorer = ptr_to_compat_reg(ksig->ka.sa.sa_restorer);
150
151 /*
152 * Set up registers for signal handler.
153 * Registers that we don't modify keep the value they had from
154 * user-space at the time we took the signal.
155 * We always pass siginfo and mcontext, regardless of SA_SIGINFO,
156 * since some things rely on this (e.g. glibc's debug/segfault.c).
157 */
158 regs->pc = ptr_to_compat_reg(ksig->ka.sa.sa_handler);
159 regs->ex1 = PL_ICS_EX1(USER_PL, 1); /* set crit sec in handler */
160 regs->sp = ptr_to_compat_reg(frame);
161 regs->lr = restorer;
162 regs->regs[0] = (unsigned long) sig;
163 regs->regs[1] = ptr_to_compat_reg(&frame->info);
164 regs->regs[2] = ptr_to_compat_reg(&frame->uc);
165 regs->flags |= PT_FLAGS_CALLER_SAVES;
166 return 0;
167
168err:
169 trace_unhandled_signal("bad sigreturn frame", regs,
170 (unsigned long)frame, SIGSEGV);
171 return -EFAULT;
172}
diff --git a/arch/tile/kernel/early_printk.c b/arch/tile/kernel/early_printk.c
deleted file mode 100644
index aefb2c086726..000000000000
--- a/arch/tile/kernel/early_printk.c
+++ /dev/null
@@ -1,75 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/console.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/string.h>
19#include <linux/irqflags.h>
20#include <linux/printk.h>
21#include <asm/setup.h>
22#include <hv/hypervisor.h>
23
24static void early_hv_write(struct console *con, const char *s, unsigned n)
25{
26 tile_console_write(s, n);
27
28 /*
29 * Convert NL to NLCR (close enough to CRNL) during early boot.
30 * We assume newlines are at the ends of strings, which turns out
31 * to be good enough for early boot console output.
32 */
33 if (n && s[n-1] == '\n')
34 tile_console_write("\r", 1);
35}
36
37static struct console early_hv_console = {
38 .name = "earlyhv",
39 .write = early_hv_write,
40 .flags = CON_PRINTBUFFER | CON_BOOT,
41 .index = -1,
42};
43
44void early_panic(const char *fmt, ...)
45{
46 struct va_format vaf;
47 va_list args;
48
49 arch_local_irq_disable_all();
50
51 va_start(args, fmt);
52
53 vaf.fmt = fmt;
54 vaf.va = &args;
55
56 early_printk("Kernel panic - not syncing: %pV", &vaf);
57
58 va_end(args);
59
60 dump_stack();
61 hv_halt();
62}
63
64static int __init setup_early_printk(char *str)
65{
66 if (early_console)
67 return 1;
68
69 early_console = &early_hv_console;
70 register_console(early_console);
71
72 return 0;
73}
74
75early_param("earlyprintk", setup_early_printk);
diff --git a/arch/tile/kernel/entry.S b/arch/tile/kernel/entry.S
deleted file mode 100644
index 101de132e363..000000000000
--- a/arch/tile/kernel/entry.S
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/linkage.h>
16#include <linux/unistd.h>
17#include <asm/irqflags.h>
18#include <asm/processor.h>
19#include <arch/abi.h>
20#include <arch/spr_def.h>
21
22#ifdef __tilegx__
23#define bnzt bnezt
24#endif
25
26STD_ENTRY(current_text_addr)
27 { move r0, lr; jrp lr }
28 STD_ENDPROC(current_text_addr)
29
30STD_ENTRY(KBacktraceIterator_init_current)
31 { move r2, lr; lnk r1 }
32 { move r4, r52; addli r1, r1, KBacktraceIterator_init_current - . }
33 { move r3, sp; j _KBacktraceIterator_init_current }
34 jrp lr /* keep backtracer happy */
35 STD_ENDPROC(KBacktraceIterator_init_current)
36
37/* Loop forever on a nap during SMP boot. */
38STD_ENTRY(smp_nap)
39 nap
40 nop /* avoid provoking the icache prefetch with a jump */
41 j smp_nap /* we are not architecturally guaranteed not to exit nap */
42 jrp lr /* clue in the backtracer */
43 STD_ENDPROC(smp_nap)
44
45/*
46 * Enable interrupts racelessly and then nap until interrupted.
47 * Architecturally, we are guaranteed that enabling interrupts via
48 * mtspr to INTERRUPT_CRITICAL_SECTION only interrupts at the next PC.
49 * This function's _cpu_idle_nap address is special; see intvec.S.
50 * When interrupted at _cpu_idle_nap, we bump the PC forward 8, and
51 * as a result return to the function that called _cpu_idle().
52 */
53STD_ENTRY_SECTION(_cpu_idle, .cpuidle.text)
54 movei r1, 1
55 IRQ_ENABLE_LOAD(r2, r3)
56 mtspr INTERRUPT_CRITICAL_SECTION, r1
57 IRQ_ENABLE_APPLY(r2, r3) /* unmask, but still with ICS set */
58 mtspr INTERRUPT_CRITICAL_SECTION, zero
59 .global _cpu_idle_nap
60_cpu_idle_nap:
61 nap
62 nop /* avoid provoking the icache prefetch with a jump */
63 jrp lr
64 STD_ENDPROC(_cpu_idle)
diff --git a/arch/tile/kernel/ftrace.c b/arch/tile/kernel/ftrace.c
deleted file mode 100644
index b827a418b155..000000000000
--- a/arch/tile/kernel/ftrace.c
+++ /dev/null
@@ -1,239 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE-Gx specific ftrace support
15 */
16
17#include <linux/ftrace.h>
18#include <linux/uaccess.h>
19
20#include <asm/cacheflush.h>
21#include <asm/ftrace.h>
22#include <asm/sections.h>
23#include <asm/insn.h>
24
25#include <arch/opcode.h>
26
27#ifdef CONFIG_DYNAMIC_FTRACE
28
29static int machine_stopped __read_mostly;
30
31int ftrace_arch_code_modify_prepare(void)
32{
33 machine_stopped = 1;
34 return 0;
35}
36
37int ftrace_arch_code_modify_post_process(void)
38{
39 flush_icache_range(0, CHIP_L1I_CACHE_SIZE());
40 machine_stopped = 0;
41 return 0;
42}
43
44/*
45 * Put { move r10, lr; jal ftrace_caller } in a bundle, this lets dynamic
46 * tracer just add one cycle overhead to every kernel function when disabled.
47 */
48static unsigned long ftrace_gen_branch(unsigned long pc, unsigned long addr,
49 bool link)
50{
51 tilegx_bundle_bits opcode_x0, opcode_x1;
52 long pcrel_by_instr = (addr - pc) >> TILEGX_LOG2_BUNDLE_SIZE_IN_BYTES;
53
54 if (link) {
55 /* opcode: jal addr */
56 opcode_x1 =
57 create_Opcode_X1(JUMP_OPCODE_X1) |
58 create_JumpOpcodeExtension_X1(JAL_JUMP_OPCODE_X1) |
59 create_JumpOff_X1(pcrel_by_instr);
60 } else {
61 /* opcode: j addr */
62 opcode_x1 =
63 create_Opcode_X1(JUMP_OPCODE_X1) |
64 create_JumpOpcodeExtension_X1(J_JUMP_OPCODE_X1) |
65 create_JumpOff_X1(pcrel_by_instr);
66 }
67
68 /*
69 * Also put { move r10, lr; jal ftrace_stub } in a bundle, which
70 * is used to replace the instruction in address ftrace_call.
71 */
72 if (addr == FTRACE_ADDR || addr == (unsigned long)ftrace_stub) {
73 /* opcode: or r10, lr, zero */
74 opcode_x0 =
75 create_Dest_X0(10) |
76 create_SrcA_X0(TREG_LR) |
77 create_SrcB_X0(TREG_ZERO) |
78 create_RRROpcodeExtension_X0(OR_RRR_0_OPCODE_X0) |
79 create_Opcode_X0(RRR_0_OPCODE_X0);
80 } else {
81 /* opcode: fnop */
82 opcode_x0 =
83 create_UnaryOpcodeExtension_X0(FNOP_UNARY_OPCODE_X0) |
84 create_RRROpcodeExtension_X0(UNARY_RRR_0_OPCODE_X0) |
85 create_Opcode_X0(RRR_0_OPCODE_X0);
86 }
87
88 return opcode_x1 | opcode_x0;
89}
90
91static unsigned long ftrace_nop_replace(struct dyn_ftrace *rec)
92{
93 return NOP();
94}
95
96static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr)
97{
98 return ftrace_gen_branch(pc, addr, true);
99}
100
101static int ftrace_modify_code(unsigned long pc, unsigned long old,
102 unsigned long new)
103{
104 unsigned long pc_wr;
105
106 /* Check if the address is in kernel text space and module space. */
107 if (!kernel_text_address(pc))
108 return -EINVAL;
109
110 /* Operate on writable kernel text mapping. */
111 pc_wr = ktext_writable_addr(pc);
112
113 if (probe_kernel_write((void *)pc_wr, &new, MCOUNT_INSN_SIZE))
114 return -EPERM;
115
116 smp_wmb();
117
118 if (!machine_stopped && num_online_cpus() > 1)
119 flush_icache_range(pc, pc + MCOUNT_INSN_SIZE);
120
121 return 0;
122}
123
124int ftrace_update_ftrace_func(ftrace_func_t func)
125{
126 unsigned long pc, old;
127 unsigned long new;
128 int ret;
129
130 pc = (unsigned long)&ftrace_call;
131 memcpy(&old, &ftrace_call, MCOUNT_INSN_SIZE);
132 new = ftrace_call_replace(pc, (unsigned long)func);
133
134 ret = ftrace_modify_code(pc, old, new);
135
136 return ret;
137}
138
139int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
140{
141 unsigned long new, old;
142 unsigned long ip = rec->ip;
143
144 old = ftrace_nop_replace(rec);
145 new = ftrace_call_replace(ip, addr);
146
147 return ftrace_modify_code(rec->ip, old, new);
148}
149
150int ftrace_make_nop(struct module *mod,
151 struct dyn_ftrace *rec, unsigned long addr)
152{
153 unsigned long ip = rec->ip;
154 unsigned long old;
155 unsigned long new;
156 int ret;
157
158 old = ftrace_call_replace(ip, addr);
159 new = ftrace_nop_replace(rec);
160 ret = ftrace_modify_code(ip, old, new);
161
162 return ret;
163}
164
165int __init ftrace_dyn_arch_init(void)
166{
167 return 0;
168}
169#endif /* CONFIG_DYNAMIC_FTRACE */
170
171#ifdef CONFIG_FUNCTION_GRAPH_TRACER
172void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
173 unsigned long frame_pointer)
174{
175 unsigned long return_hooker = (unsigned long) &return_to_handler;
176 struct ftrace_graph_ent trace;
177 unsigned long old;
178 int err;
179
180 if (unlikely(atomic_read(&current->tracing_graph_pause)))
181 return;
182
183 old = *parent;
184 *parent = return_hooker;
185
186 err = ftrace_push_return_trace(old, self_addr, &trace.depth,
187 frame_pointer, NULL);
188 if (err == -EBUSY) {
189 *parent = old;
190 return;
191 }
192
193 trace.func = self_addr;
194
195 /* Only trace if the calling function expects to */
196 if (!ftrace_graph_entry(&trace)) {
197 current->curr_ret_stack--;
198 *parent = old;
199 }
200}
201
202#ifdef CONFIG_DYNAMIC_FTRACE
203extern unsigned long ftrace_graph_call;
204
205static int __ftrace_modify_caller(unsigned long *callsite,
206 void (*func) (void), bool enable)
207{
208 unsigned long caller_fn = (unsigned long) func;
209 unsigned long pc = (unsigned long) callsite;
210 unsigned long branch = ftrace_gen_branch(pc, caller_fn, false);
211 unsigned long nop = NOP();
212 unsigned long old = enable ? nop : branch;
213 unsigned long new = enable ? branch : nop;
214
215 return ftrace_modify_code(pc, old, new);
216}
217
218static int ftrace_modify_graph_caller(bool enable)
219{
220 int ret;
221
222 ret = __ftrace_modify_caller(&ftrace_graph_call,
223 ftrace_graph_caller,
224 enable);
225
226 return ret;
227}
228
229int ftrace_enable_ftrace_graph_caller(void)
230{
231 return ftrace_modify_graph_caller(true);
232}
233
234int ftrace_disable_ftrace_graph_caller(void)
235{
236 return ftrace_modify_graph_caller(false);
237}
238#endif /* CONFIG_DYNAMIC_FTRACE */
239#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
diff --git a/arch/tile/kernel/hardwall.c b/arch/tile/kernel/hardwall.c
deleted file mode 100644
index 2fd1694ac1d0..000000000000
--- a/arch/tile/kernel/hardwall.c
+++ /dev/null
@@ -1,1096 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/fs.h>
16#include <linux/proc_fs.h>
17#include <linux/seq_file.h>
18#include <linux/rwsem.h>
19#include <linux/kprobes.h>
20#include <linux/sched.h>
21#include <linux/hardirq.h>
22#include <linux/uaccess.h>
23#include <linux/smp.h>
24#include <linux/cdev.h>
25#include <linux/compat.h>
26#include <asm/hardwall.h>
27#include <asm/traps.h>
28#include <asm/siginfo.h>
29#include <asm/irq_regs.h>
30
31#include <arch/interrupts.h>
32#include <arch/spr_def.h>
33
34
35/*
36 * Implement a per-cpu "hardwall" resource class such as UDN or IPI.
37 * We use "hardwall" nomenclature throughout for historical reasons.
38 * The lock here controls access to the list data structure as well as
39 * to the items on the list.
40 */
41struct hardwall_type {
42 int index;
43 int is_xdn;
44 int is_idn;
45 int disabled;
46 const char *name;
47 struct list_head list;
48 spinlock_t lock;
49 struct proc_dir_entry *proc_dir;
50};
51
52enum hardwall_index {
53 HARDWALL_UDN = 0,
54#ifndef __tilepro__
55 HARDWALL_IDN = 1,
56 HARDWALL_IPI = 2,
57#endif
58 _HARDWALL_TYPES
59};
60
61static struct hardwall_type hardwall_types[] = {
62 { /* user-space access to UDN */
63 0,
64 1,
65 0,
66 0,
67 "udn",
68 LIST_HEAD_INIT(hardwall_types[HARDWALL_UDN].list),
69 __SPIN_LOCK_UNLOCKED(hardwall_types[HARDWALL_UDN].lock),
70 NULL
71 },
72#ifndef __tilepro__
73 { /* user-space access to IDN */
74 1,
75 1,
76 1,
77 1, /* disabled pending hypervisor support */
78 "idn",
79 LIST_HEAD_INIT(hardwall_types[HARDWALL_IDN].list),
80 __SPIN_LOCK_UNLOCKED(hardwall_types[HARDWALL_IDN].lock),
81 NULL
82 },
83 { /* access to user-space IPI */
84 2,
85 0,
86 0,
87 0,
88 "ipi",
89 LIST_HEAD_INIT(hardwall_types[HARDWALL_IPI].list),
90 __SPIN_LOCK_UNLOCKED(hardwall_types[HARDWALL_IPI].lock),
91 NULL
92 },
93#endif
94};
95
96/*
97 * This data structure tracks the cpu data, etc., associated
98 * one-to-one with a "struct file *" from opening a hardwall device file.
99 * Note that the file's private data points back to this structure.
100 */
101struct hardwall_info {
102 struct list_head list; /* for hardwall_types.list */
103 struct list_head task_head; /* head of tasks in this hardwall */
104 struct hardwall_type *type; /* type of this resource */
105 struct cpumask cpumask; /* cpus reserved */
106 int id; /* integer id for this hardwall */
107 int teardown_in_progress; /* are we tearing this one down? */
108
109 /* Remaining fields only valid for user-network resources. */
110 int ulhc_x; /* upper left hand corner x coord */
111 int ulhc_y; /* upper left hand corner y coord */
112 int width; /* rectangle width */
113 int height; /* rectangle height */
114#if CHIP_HAS_REV1_XDN()
115 atomic_t xdn_pending_count; /* cores in phase 1 of drain */
116#endif
117};
118
119
120/* /proc/tile/hardwall */
121static struct proc_dir_entry *hardwall_proc_dir;
122
123/* Functions to manage files in /proc/tile/hardwall. */
124static void hardwall_add_proc(struct hardwall_info *);
125static void hardwall_remove_proc(struct hardwall_info *);
126
127/* Allow disabling UDN access. */
128static int __init noudn(char *str)
129{
130 pr_info("User-space UDN access is disabled\n");
131 hardwall_types[HARDWALL_UDN].disabled = 1;
132 return 0;
133}
134early_param("noudn", noudn);
135
136#ifndef __tilepro__
137/* Allow disabling IDN access. */
138static int __init noidn(char *str)
139{
140 pr_info("User-space IDN access is disabled\n");
141 hardwall_types[HARDWALL_IDN].disabled = 1;
142 return 0;
143}
144early_param("noidn", noidn);
145
146/* Allow disabling IPI access. */
147static int __init noipi(char *str)
148{
149 pr_info("User-space IPI access is disabled\n");
150 hardwall_types[HARDWALL_IPI].disabled = 1;
151 return 0;
152}
153early_param("noipi", noipi);
154#endif
155
156
157/*
158 * Low-level primitives for UDN/IDN
159 */
160
161#ifdef __tilepro__
162#define mtspr_XDN(hwt, name, val) \
163 do { (void)(hwt); __insn_mtspr(SPR_UDN_##name, (val)); } while (0)
164#define mtspr_MPL_XDN(hwt, name, val) \
165 do { (void)(hwt); __insn_mtspr(SPR_MPL_UDN_##name, (val)); } while (0)
166#define mfspr_XDN(hwt, name) \
167 ((void)(hwt), __insn_mfspr(SPR_UDN_##name))
168#else
169#define mtspr_XDN(hwt, name, val) \
170 do { \
171 if ((hwt)->is_idn) \
172 __insn_mtspr(SPR_IDN_##name, (val)); \
173 else \
174 __insn_mtspr(SPR_UDN_##name, (val)); \
175 } while (0)
176#define mtspr_MPL_XDN(hwt, name, val) \
177 do { \
178 if ((hwt)->is_idn) \
179 __insn_mtspr(SPR_MPL_IDN_##name, (val)); \
180 else \
181 __insn_mtspr(SPR_MPL_UDN_##name, (val)); \
182 } while (0)
183#define mfspr_XDN(hwt, name) \
184 ((hwt)->is_idn ? __insn_mfspr(SPR_IDN_##name) : __insn_mfspr(SPR_UDN_##name))
185#endif
186
187/* Set a CPU bit if the CPU is online. */
188#define cpu_online_set(cpu, dst) do { \
189 if (cpu_online(cpu)) \
190 cpumask_set_cpu(cpu, dst); \
191} while (0)
192
193
194/* Does the given rectangle contain the given x,y coordinate? */
195static int contains(struct hardwall_info *r, int x, int y)
196{
197 return (x >= r->ulhc_x && x < r->ulhc_x + r->width) &&
198 (y >= r->ulhc_y && y < r->ulhc_y + r->height);
199}
200
201/* Compute the rectangle parameters and validate the cpumask. */
202static int check_rectangle(struct hardwall_info *r, struct cpumask *mask)
203{
204 int x, y, cpu, ulhc, lrhc;
205
206 /* The first cpu is the ULHC, the last the LRHC. */
207 ulhc = find_first_bit(cpumask_bits(mask), nr_cpumask_bits);
208 lrhc = find_last_bit(cpumask_bits(mask), nr_cpumask_bits);
209
210 /* Compute the rectangle attributes from the cpus. */
211 r->ulhc_x = cpu_x(ulhc);
212 r->ulhc_y = cpu_y(ulhc);
213 r->width = cpu_x(lrhc) - r->ulhc_x + 1;
214 r->height = cpu_y(lrhc) - r->ulhc_y + 1;
215
216 /* Width and height must be positive */
217 if (r->width <= 0 || r->height <= 0)
218 return -EINVAL;
219
220 /* Confirm that the cpumask is exactly the rectangle. */
221 for (y = 0, cpu = 0; y < smp_height; ++y)
222 for (x = 0; x < smp_width; ++x, ++cpu)
223 if (cpumask_test_cpu(cpu, mask) != contains(r, x, y))
224 return -EINVAL;
225
226 /*
227 * Note that offline cpus can't be drained when this user network
228 * rectangle eventually closes. We used to detect this
229 * situation and print a warning, but it annoyed users and
230 * they ignored it anyway, so now we just return without a
231 * warning.
232 */
233 return 0;
234}
235
236/*
237 * Hardware management of hardwall setup, teardown, trapping,
238 * and enabling/disabling PL0 access to the networks.
239 */
240
241/* Bit field values to mask together for writes to SPR_XDN_DIRECTION_PROTECT */
242enum direction_protect {
243 N_PROTECT = (1 << 0),
244 E_PROTECT = (1 << 1),
245 S_PROTECT = (1 << 2),
246 W_PROTECT = (1 << 3),
247 C_PROTECT = (1 << 4),
248};
249
250static inline int xdn_which_interrupt(struct hardwall_type *hwt)
251{
252#ifndef __tilepro__
253 if (hwt->is_idn)
254 return INT_IDN_FIREWALL;
255#endif
256 return INT_UDN_FIREWALL;
257}
258
259static void enable_firewall_interrupts(struct hardwall_type *hwt)
260{
261 arch_local_irq_unmask_now(xdn_which_interrupt(hwt));
262}
263
264static void disable_firewall_interrupts(struct hardwall_type *hwt)
265{
266 arch_local_irq_mask_now(xdn_which_interrupt(hwt));
267}
268
269/* Set up hardwall on this cpu based on the passed hardwall_info. */
270static void hardwall_setup_func(void *info)
271{
272 struct hardwall_info *r = info;
273 struct hardwall_type *hwt = r->type;
274
275 int cpu = smp_processor_id(); /* on_each_cpu disables preemption */
276 int x = cpu_x(cpu);
277 int y = cpu_y(cpu);
278 int bits = 0;
279 if (x == r->ulhc_x)
280 bits |= W_PROTECT;
281 if (x == r->ulhc_x + r->width - 1)
282 bits |= E_PROTECT;
283 if (y == r->ulhc_y)
284 bits |= N_PROTECT;
285 if (y == r->ulhc_y + r->height - 1)
286 bits |= S_PROTECT;
287 BUG_ON(bits == 0);
288 mtspr_XDN(hwt, DIRECTION_PROTECT, bits);
289 enable_firewall_interrupts(hwt);
290}
291
292/* Set up all cpus on edge of rectangle to enable/disable hardwall SPRs. */
293static void hardwall_protect_rectangle(struct hardwall_info *r)
294{
295 int x, y, cpu, delta;
296 struct cpumask rect_cpus;
297
298 cpumask_clear(&rect_cpus);
299
300 /* First include the top and bottom edges */
301 cpu = r->ulhc_y * smp_width + r->ulhc_x;
302 delta = (r->height - 1) * smp_width;
303 for (x = 0; x < r->width; ++x, ++cpu) {
304 cpu_online_set(cpu, &rect_cpus);
305 cpu_online_set(cpu + delta, &rect_cpus);
306 }
307
308 /* Then the left and right edges */
309 cpu -= r->width;
310 delta = r->width - 1;
311 for (y = 0; y < r->height; ++y, cpu += smp_width) {
312 cpu_online_set(cpu, &rect_cpus);
313 cpu_online_set(cpu + delta, &rect_cpus);
314 }
315
316 /* Then tell all the cpus to set up their protection SPR */
317 on_each_cpu_mask(&rect_cpus, hardwall_setup_func, r, 1);
318}
319
320/* Entered from INT_xDN_FIREWALL interrupt vector with irqs disabled. */
321void __kprobes do_hardwall_trap(struct pt_regs* regs, int fault_num)
322{
323 struct hardwall_info *rect;
324 struct hardwall_type *hwt;
325 struct task_struct *p;
326 struct siginfo info;
327 int cpu = smp_processor_id();
328 int found_processes;
329 struct pt_regs *old_regs = set_irq_regs(regs);
330
331 irq_enter();
332
333 /* Figure out which network trapped. */
334 switch (fault_num) {
335#ifndef __tilepro__
336 case INT_IDN_FIREWALL:
337 hwt = &hardwall_types[HARDWALL_IDN];
338 break;
339#endif
340 case INT_UDN_FIREWALL:
341 hwt = &hardwall_types[HARDWALL_UDN];
342 break;
343 default:
344 BUG();
345 }
346 BUG_ON(hwt->disabled);
347
348 /* This tile trapped a network access; find the rectangle. */
349 spin_lock(&hwt->lock);
350 list_for_each_entry(rect, &hwt->list, list) {
351 if (cpumask_test_cpu(cpu, &rect->cpumask))
352 break;
353 }
354
355 /*
356 * It shouldn't be possible not to find this cpu on the
357 * rectangle list, since only cpus in rectangles get hardwalled.
358 * The hardwall is only removed after the user network is drained.
359 */
360 BUG_ON(&rect->list == &hwt->list);
361
362 /*
363 * If we already started teardown on this hardwall, don't worry;
364 * the abort signal has been sent and we are just waiting for things
365 * to quiesce.
366 */
367 if (rect->teardown_in_progress) {
368 pr_notice("cpu %d: detected %s hardwall violation %#lx while teardown already in progress\n",
369 cpu, hwt->name,
370 (long)mfspr_XDN(hwt, DIRECTION_PROTECT));
371 goto done;
372 }
373
374 /*
375 * Kill off any process that is activated in this rectangle.
376 * We bypass security to deliver the signal, since it must be
377 * one of the activated processes that generated the user network
378 * message that caused this trap, and all the activated
379 * processes shared a single open file so are pretty tightly
380 * bound together from a security point of view to begin with.
381 */
382 rect->teardown_in_progress = 1;
383 wmb(); /* Ensure visibility of rectangle before notifying processes. */
384 pr_notice("cpu %d: detected %s hardwall violation %#lx...\n",
385 cpu, hwt->name, (long)mfspr_XDN(hwt, DIRECTION_PROTECT));
386 info.si_signo = SIGILL;
387 info.si_errno = 0;
388 info.si_code = ILL_HARDWALL;
389 found_processes = 0;
390 list_for_each_entry(p, &rect->task_head,
391 thread.hardwall[hwt->index].list) {
392 BUG_ON(p->thread.hardwall[hwt->index].info != rect);
393 if (!(p->flags & PF_EXITING)) {
394 found_processes = 1;
395 pr_notice("hardwall: killing %d\n", p->pid);
396 do_send_sig_info(info.si_signo, &info, p, false);
397 }
398 }
399 if (!found_processes)
400 pr_notice("hardwall: no associated processes!\n");
401
402 done:
403 spin_unlock(&hwt->lock);
404
405 /*
406 * We have to disable firewall interrupts now, or else when we
407 * return from this handler, we will simply re-interrupt back to
408 * it. However, we can't clear the protection bits, since we
409 * haven't yet drained the network, and that would allow packets
410 * to cross out of the hardwall region.
411 */
412 disable_firewall_interrupts(hwt);
413
414 irq_exit();
415 set_irq_regs(old_regs);
416}
417
418/* Allow access from user space to the user network. */
419void grant_hardwall_mpls(struct hardwall_type *hwt)
420{
421#ifndef __tilepro__
422 if (!hwt->is_xdn) {
423 __insn_mtspr(SPR_MPL_IPI_0_SET_0, 1);
424 return;
425 }
426#endif
427 mtspr_MPL_XDN(hwt, ACCESS_SET_0, 1);
428 mtspr_MPL_XDN(hwt, AVAIL_SET_0, 1);
429 mtspr_MPL_XDN(hwt, COMPLETE_SET_0, 1);
430 mtspr_MPL_XDN(hwt, TIMER_SET_0, 1);
431#if !CHIP_HAS_REV1_XDN()
432 mtspr_MPL_XDN(hwt, REFILL_SET_0, 1);
433 mtspr_MPL_XDN(hwt, CA_SET_0, 1);
434#endif
435}
436
437/* Deny access from user space to the user network. */
438void restrict_hardwall_mpls(struct hardwall_type *hwt)
439{
440#ifndef __tilepro__
441 if (!hwt->is_xdn) {
442 __insn_mtspr(SPR_MPL_IPI_0_SET_1, 1);
443 return;
444 }
445#endif
446 mtspr_MPL_XDN(hwt, ACCESS_SET_1, 1);
447 mtspr_MPL_XDN(hwt, AVAIL_SET_1, 1);
448 mtspr_MPL_XDN(hwt, COMPLETE_SET_1, 1);
449 mtspr_MPL_XDN(hwt, TIMER_SET_1, 1);
450#if !CHIP_HAS_REV1_XDN()
451 mtspr_MPL_XDN(hwt, REFILL_SET_1, 1);
452 mtspr_MPL_XDN(hwt, CA_SET_1, 1);
453#endif
454}
455
456/* Restrict or deny as necessary for the task we're switching to. */
457void hardwall_switch_tasks(struct task_struct *prev,
458 struct task_struct *next)
459{
460 int i;
461 for (i = 0; i < HARDWALL_TYPES; ++i) {
462 if (prev->thread.hardwall[i].info != NULL) {
463 if (next->thread.hardwall[i].info == NULL)
464 restrict_hardwall_mpls(&hardwall_types[i]);
465 } else if (next->thread.hardwall[i].info != NULL) {
466 grant_hardwall_mpls(&hardwall_types[i]);
467 }
468 }
469}
470
471/* Does this task have the right to IPI the given cpu? */
472int hardwall_ipi_valid(int cpu)
473{
474#ifdef __tilegx__
475 struct hardwall_info *info =
476 current->thread.hardwall[HARDWALL_IPI].info;
477 return info && cpumask_test_cpu(cpu, &info->cpumask);
478#else
479 return 0;
480#endif
481}
482
483/*
484 * Code to create, activate, deactivate, and destroy hardwall resources.
485 */
486
487/* Create a hardwall for the given resource */
488static struct hardwall_info *hardwall_create(struct hardwall_type *hwt,
489 size_t size,
490 const unsigned char __user *bits)
491{
492 struct hardwall_info *iter, *info;
493 struct cpumask mask;
494 unsigned long flags;
495 int rc;
496
497 /* Reject crazy sizes out of hand, a la sys_mbind(). */
498 if (size > PAGE_SIZE)
499 return ERR_PTR(-EINVAL);
500
501 /* Copy whatever fits into a cpumask. */
502 if (copy_from_user(&mask, bits, min(sizeof(struct cpumask), size)))
503 return ERR_PTR(-EFAULT);
504
505 /*
506 * If the size was short, clear the rest of the mask;
507 * otherwise validate that the rest of the user mask was zero
508 * (we don't try hard to be efficient when validating huge masks).
509 */
510 if (size < sizeof(struct cpumask)) {
511 memset((char *)&mask + size, 0, sizeof(struct cpumask) - size);
512 } else if (size > sizeof(struct cpumask)) {
513 size_t i;
514 for (i = sizeof(struct cpumask); i < size; ++i) {
515 char c;
516 if (get_user(c, &bits[i]))
517 return ERR_PTR(-EFAULT);
518 if (c)
519 return ERR_PTR(-EINVAL);
520 }
521 }
522
523 /* Allocate a new hardwall_info optimistically. */
524 info = kmalloc(sizeof(struct hardwall_info),
525 GFP_KERNEL | __GFP_ZERO);
526 if (info == NULL)
527 return ERR_PTR(-ENOMEM);
528 INIT_LIST_HEAD(&info->task_head);
529 info->type = hwt;
530
531 /* Compute the rectangle size and validate that it's plausible. */
532 cpumask_copy(&info->cpumask, &mask);
533 info->id = find_first_bit(cpumask_bits(&mask), nr_cpumask_bits);
534 if (hwt->is_xdn) {
535 rc = check_rectangle(info, &mask);
536 if (rc != 0) {
537 kfree(info);
538 return ERR_PTR(rc);
539 }
540 }
541
542 /*
543 * Eliminate cpus that are not part of this Linux client.
544 * Note that this allows for configurations that we might not want to
545 * support, such as one client on every even cpu, another client on
546 * every odd cpu.
547 */
548 cpumask_and(&info->cpumask, &info->cpumask, cpu_online_mask);
549
550 /* Confirm it doesn't overlap and add it to the list. */
551 spin_lock_irqsave(&hwt->lock, flags);
552 list_for_each_entry(iter, &hwt->list, list) {
553 if (cpumask_intersects(&iter->cpumask, &info->cpumask)) {
554 spin_unlock_irqrestore(&hwt->lock, flags);
555 kfree(info);
556 return ERR_PTR(-EBUSY);
557 }
558 }
559 list_add_tail(&info->list, &hwt->list);
560 spin_unlock_irqrestore(&hwt->lock, flags);
561
562 /* Set up appropriate hardwalling on all affected cpus. */
563 if (hwt->is_xdn)
564 hardwall_protect_rectangle(info);
565
566 /* Create a /proc/tile/hardwall entry. */
567 hardwall_add_proc(info);
568
569 return info;
570}
571
572/* Activate a given hardwall on this cpu for this process. */
573static int hardwall_activate(struct hardwall_info *info)
574{
575 int cpu;
576 unsigned long flags;
577 struct task_struct *p = current;
578 struct thread_struct *ts = &p->thread;
579 struct hardwall_type *hwt;
580
581 /* Require a hardwall. */
582 if (info == NULL)
583 return -ENODATA;
584
585 /* Not allowed to activate a hardwall that is being torn down. */
586 if (info->teardown_in_progress)
587 return -EINVAL;
588
589 /*
590 * Get our affinity; if we're not bound to this tile uniquely,
591 * we can't access the network registers.
592 */
593 if (cpumask_weight(&p->cpus_allowed) != 1)
594 return -EPERM;
595
596 /* Make sure we are bound to a cpu assigned to this resource. */
597 cpu = smp_processor_id();
598 BUG_ON(cpumask_first(&p->cpus_allowed) != cpu);
599 if (!cpumask_test_cpu(cpu, &info->cpumask))
600 return -EINVAL;
601
602 /* If we are already bound to this hardwall, it's a no-op. */
603 hwt = info->type;
604 if (ts->hardwall[hwt->index].info) {
605 BUG_ON(ts->hardwall[hwt->index].info != info);
606 return 0;
607 }
608
609 /* Success! This process gets to use the resource on this cpu. */
610 ts->hardwall[hwt->index].info = info;
611 spin_lock_irqsave(&hwt->lock, flags);
612 list_add(&ts->hardwall[hwt->index].list, &info->task_head);
613 spin_unlock_irqrestore(&hwt->lock, flags);
614 grant_hardwall_mpls(hwt);
615 printk(KERN_DEBUG "Pid %d (%s) activated for %s hardwall: cpu %d\n",
616 p->pid, p->comm, hwt->name, cpu);
617 return 0;
618}
619
620/*
621 * Deactivate a task's hardwall. Must hold lock for hardwall_type.
622 * This method may be called from exit_thread(), so we don't want to
623 * rely on too many fields of struct task_struct still being valid.
624 * We assume the cpus_allowed, pid, and comm fields are still valid.
625 */
626static void _hardwall_deactivate(struct hardwall_type *hwt,
627 struct task_struct *task)
628{
629 struct thread_struct *ts = &task->thread;
630
631 if (cpumask_weight(&task->cpus_allowed) != 1) {
632 pr_err("pid %d (%s) releasing %s hardwall with an affinity mask containing %d cpus!\n",
633 task->pid, task->comm, hwt->name,
634 cpumask_weight(&task->cpus_allowed));
635 BUG();
636 }
637
638 BUG_ON(ts->hardwall[hwt->index].info == NULL);
639 ts->hardwall[hwt->index].info = NULL;
640 list_del(&ts->hardwall[hwt->index].list);
641 if (task == current)
642 restrict_hardwall_mpls(hwt);
643}
644
645/* Deactivate a task's hardwall. */
646static int hardwall_deactivate(struct hardwall_type *hwt,
647 struct task_struct *task)
648{
649 unsigned long flags;
650 int activated;
651
652 spin_lock_irqsave(&hwt->lock, flags);
653 activated = (task->thread.hardwall[hwt->index].info != NULL);
654 if (activated)
655 _hardwall_deactivate(hwt, task);
656 spin_unlock_irqrestore(&hwt->lock, flags);
657
658 if (!activated)
659 return -EINVAL;
660
661 printk(KERN_DEBUG "Pid %d (%s) deactivated for %s hardwall: cpu %d\n",
662 task->pid, task->comm, hwt->name, raw_smp_processor_id());
663 return 0;
664}
665
666void hardwall_deactivate_all(struct task_struct *task)
667{
668 int i;
669 for (i = 0; i < HARDWALL_TYPES; ++i)
670 if (task->thread.hardwall[i].info)
671 hardwall_deactivate(&hardwall_types[i], task);
672}
673
674/* Stop the switch before draining the network. */
675static void stop_xdn_switch(void *arg)
676{
677#if !CHIP_HAS_REV1_XDN()
678 /* Freeze the switch and the demux. */
679 __insn_mtspr(SPR_UDN_SP_FREEZE,
680 SPR_UDN_SP_FREEZE__SP_FRZ_MASK |
681 SPR_UDN_SP_FREEZE__DEMUX_FRZ_MASK |
682 SPR_UDN_SP_FREEZE__NON_DEST_EXT_MASK);
683#else
684 /*
685 * Drop all packets bound for the core or off the edge.
686 * We rely on the normal hardwall protection setup code
687 * to have set the low four bits to trigger firewall interrupts,
688 * and shift those bits up to trigger "drop on send" semantics,
689 * plus adding "drop on send to core" for all switches.
690 * In practice it seems the switches latch the DIRECTION_PROTECT
691 * SPR so they won't start dropping if they're already
692 * delivering the last message to the core, but it doesn't
693 * hurt to enable it here.
694 */
695 struct hardwall_type *hwt = arg;
696 unsigned long protect = mfspr_XDN(hwt, DIRECTION_PROTECT);
697 mtspr_XDN(hwt, DIRECTION_PROTECT, (protect | C_PROTECT) << 5);
698#endif
699}
700
701static void empty_xdn_demuxes(struct hardwall_type *hwt)
702{
703#ifndef __tilepro__
704 if (hwt->is_idn) {
705 while (__insn_mfspr(SPR_IDN_DATA_AVAIL) & (1 << 0))
706 (void) __tile_idn0_receive();
707 while (__insn_mfspr(SPR_IDN_DATA_AVAIL) & (1 << 1))
708 (void) __tile_idn1_receive();
709 return;
710 }
711#endif
712 while (__insn_mfspr(SPR_UDN_DATA_AVAIL) & (1 << 0))
713 (void) __tile_udn0_receive();
714 while (__insn_mfspr(SPR_UDN_DATA_AVAIL) & (1 << 1))
715 (void) __tile_udn1_receive();
716 while (__insn_mfspr(SPR_UDN_DATA_AVAIL) & (1 << 2))
717 (void) __tile_udn2_receive();
718 while (__insn_mfspr(SPR_UDN_DATA_AVAIL) & (1 << 3))
719 (void) __tile_udn3_receive();
720}
721
722/* Drain all the state from a stopped switch. */
723static void drain_xdn_switch(void *arg)
724{
725 struct hardwall_info *info = arg;
726 struct hardwall_type *hwt = info->type;
727
728#if CHIP_HAS_REV1_XDN()
729 /*
730 * The switches have been configured to drop any messages
731 * destined for cores (or off the edge of the rectangle).
732 * But the current message may continue to be delivered,
733 * so we wait until all the cores have finished any pending
734 * messages before we stop draining.
735 */
736 int pending = mfspr_XDN(hwt, PENDING);
737 while (pending--) {
738 empty_xdn_demuxes(hwt);
739 if (hwt->is_idn)
740 __tile_idn_send(0);
741 else
742 __tile_udn_send(0);
743 }
744 atomic_dec(&info->xdn_pending_count);
745 while (atomic_read(&info->xdn_pending_count))
746 empty_xdn_demuxes(hwt);
747#else
748 int i;
749 int from_tile_words, ca_count;
750
751 /* Empty out the 5 switch point fifos. */
752 for (i = 0; i < 5; i++) {
753 int words, j;
754 __insn_mtspr(SPR_UDN_SP_FIFO_SEL, i);
755 words = __insn_mfspr(SPR_UDN_SP_STATE) & 0xF;
756 for (j = 0; j < words; j++)
757 (void) __insn_mfspr(SPR_UDN_SP_FIFO_DATA);
758 BUG_ON((__insn_mfspr(SPR_UDN_SP_STATE) & 0xF) != 0);
759 }
760
761 /* Dump out the 3 word fifo at top. */
762 from_tile_words = (__insn_mfspr(SPR_UDN_DEMUX_STATUS) >> 10) & 0x3;
763 for (i = 0; i < from_tile_words; i++)
764 (void) __insn_mfspr(SPR_UDN_DEMUX_WRITE_FIFO);
765
766 /* Empty out demuxes. */
767 empty_xdn_demuxes(hwt);
768
769 /* Empty out catch all. */
770 ca_count = __insn_mfspr(SPR_UDN_DEMUX_CA_COUNT);
771 for (i = 0; i < ca_count; i++)
772 (void) __insn_mfspr(SPR_UDN_CA_DATA);
773 BUG_ON(__insn_mfspr(SPR_UDN_DEMUX_CA_COUNT) != 0);
774
775 /* Clear demux logic. */
776 __insn_mtspr(SPR_UDN_DEMUX_CTL, 1);
777
778 /*
779 * Write switch state; experimentation indicates that 0xc3000
780 * is an idle switch point.
781 */
782 for (i = 0; i < 5; i++) {
783 __insn_mtspr(SPR_UDN_SP_FIFO_SEL, i);
784 __insn_mtspr(SPR_UDN_SP_STATE, 0xc3000);
785 }
786#endif
787}
788
789/* Reset random XDN state registers at boot up and during hardwall teardown. */
790static void reset_xdn_network_state(struct hardwall_type *hwt)
791{
792 if (hwt->disabled)
793 return;
794
795 /* Clear out other random registers so we have a clean slate. */
796 mtspr_XDN(hwt, DIRECTION_PROTECT, 0);
797 mtspr_XDN(hwt, AVAIL_EN, 0);
798 mtspr_XDN(hwt, DEADLOCK_TIMEOUT, 0);
799
800#if !CHIP_HAS_REV1_XDN()
801 /* Reset UDN coordinates to their standard value */
802 {
803 unsigned int cpu = smp_processor_id();
804 unsigned int x = cpu_x(cpu);
805 unsigned int y = cpu_y(cpu);
806 __insn_mtspr(SPR_UDN_TILE_COORD, (x << 18) | (y << 7));
807 }
808
809 /* Set demux tags to predefined values and enable them. */
810 __insn_mtspr(SPR_UDN_TAG_VALID, 0xf);
811 __insn_mtspr(SPR_UDN_TAG_0, (1 << 0));
812 __insn_mtspr(SPR_UDN_TAG_1, (1 << 1));
813 __insn_mtspr(SPR_UDN_TAG_2, (1 << 2));
814 __insn_mtspr(SPR_UDN_TAG_3, (1 << 3));
815
816 /* Set other rev0 random registers to a clean state. */
817 __insn_mtspr(SPR_UDN_REFILL_EN, 0);
818 __insn_mtspr(SPR_UDN_DEMUX_QUEUE_SEL, 0);
819 __insn_mtspr(SPR_UDN_SP_FIFO_SEL, 0);
820
821 /* Start the switch and demux. */
822 __insn_mtspr(SPR_UDN_SP_FREEZE, 0);
823#endif
824}
825
826void reset_network_state(void)
827{
828 reset_xdn_network_state(&hardwall_types[HARDWALL_UDN]);
829#ifndef __tilepro__
830 reset_xdn_network_state(&hardwall_types[HARDWALL_IDN]);
831#endif
832}
833
834/* Restart an XDN switch after draining. */
835static void restart_xdn_switch(void *arg)
836{
837 struct hardwall_type *hwt = arg;
838
839#if CHIP_HAS_REV1_XDN()
840 /* One last drain step to avoid races with injection and draining. */
841 empty_xdn_demuxes(hwt);
842#endif
843
844 reset_xdn_network_state(hwt);
845
846 /* Disable firewall interrupts. */
847 disable_firewall_interrupts(hwt);
848}
849
850/* Last reference to a hardwall is gone, so clear the network. */
851static void hardwall_destroy(struct hardwall_info *info)
852{
853 struct task_struct *task;
854 struct hardwall_type *hwt;
855 unsigned long flags;
856
857 /* Make sure this file actually represents a hardwall. */
858 if (info == NULL)
859 return;
860
861 /*
862 * Deactivate any remaining tasks. It's possible to race with
863 * some other thread that is exiting and hasn't yet called
864 * deactivate (when freeing its thread_info), so we carefully
865 * deactivate any remaining tasks before freeing the
866 * hardwall_info object itself.
867 */
868 hwt = info->type;
869 info->teardown_in_progress = 1;
870 spin_lock_irqsave(&hwt->lock, flags);
871 list_for_each_entry(task, &info->task_head,
872 thread.hardwall[hwt->index].list)
873 _hardwall_deactivate(hwt, task);
874 spin_unlock_irqrestore(&hwt->lock, flags);
875
876 if (hwt->is_xdn) {
877 /* Configure the switches for draining the user network. */
878 printk(KERN_DEBUG
879 "Clearing %s hardwall rectangle %dx%d %d,%d\n",
880 hwt->name, info->width, info->height,
881 info->ulhc_x, info->ulhc_y);
882 on_each_cpu_mask(&info->cpumask, stop_xdn_switch, hwt, 1);
883
884 /* Drain the network. */
885#if CHIP_HAS_REV1_XDN()
886 atomic_set(&info->xdn_pending_count,
887 cpumask_weight(&info->cpumask));
888 on_each_cpu_mask(&info->cpumask, drain_xdn_switch, info, 0);
889#else
890 on_each_cpu_mask(&info->cpumask, drain_xdn_switch, info, 1);
891#endif
892
893 /* Restart switch and disable firewall. */
894 on_each_cpu_mask(&info->cpumask, restart_xdn_switch, hwt, 1);
895 }
896
897 /* Remove the /proc/tile/hardwall entry. */
898 hardwall_remove_proc(info);
899
900 /* Now free the hardwall from the list. */
901 spin_lock_irqsave(&hwt->lock, flags);
902 BUG_ON(!list_empty(&info->task_head));
903 list_del(&info->list);
904 spin_unlock_irqrestore(&hwt->lock, flags);
905 kfree(info);
906}
907
908
909static int hardwall_proc_show(struct seq_file *sf, void *v)
910{
911 struct hardwall_info *info = sf->private;
912
913 seq_printf(sf, "%*pbl\n", cpumask_pr_args(&info->cpumask));
914 return 0;
915}
916
917static int hardwall_proc_open(struct inode *inode,
918 struct file *file)
919{
920 return single_open(file, hardwall_proc_show, PDE_DATA(inode));
921}
922
923static const struct file_operations hardwall_proc_fops = {
924 .open = hardwall_proc_open,
925 .read = seq_read,
926 .llseek = seq_lseek,
927 .release = single_release,
928};
929
930static void hardwall_add_proc(struct hardwall_info *info)
931{
932 char buf[64];
933 snprintf(buf, sizeof(buf), "%d", info->id);
934 proc_create_data(buf, 0444, info->type->proc_dir,
935 &hardwall_proc_fops, info);
936}
937
938static void hardwall_remove_proc(struct hardwall_info *info)
939{
940 char buf[64];
941 snprintf(buf, sizeof(buf), "%d", info->id);
942 remove_proc_entry(buf, info->type->proc_dir);
943}
944
945int proc_pid_hardwall(struct seq_file *m, struct pid_namespace *ns,
946 struct pid *pid, struct task_struct *task)
947{
948 int i;
949 int n = 0;
950 for (i = 0; i < HARDWALL_TYPES; ++i) {
951 struct hardwall_info *info = task->thread.hardwall[i].info;
952 if (info)
953 seq_printf(m, "%s: %d\n", info->type->name, info->id);
954 }
955 return n;
956}
957
958void proc_tile_hardwall_init(struct proc_dir_entry *root)
959{
960 int i;
961 for (i = 0; i < HARDWALL_TYPES; ++i) {
962 struct hardwall_type *hwt = &hardwall_types[i];
963 if (hwt->disabled)
964 continue;
965 if (hardwall_proc_dir == NULL)
966 hardwall_proc_dir = proc_mkdir("hardwall", root);
967 hwt->proc_dir = proc_mkdir(hwt->name, hardwall_proc_dir);
968 }
969}
970
971
972/*
973 * Character device support via ioctl/close.
974 */
975
976static long hardwall_ioctl(struct file *file, unsigned int a, unsigned long b)
977{
978 struct hardwall_info *info = file->private_data;
979 int minor = iminor(file->f_mapping->host);
980 struct hardwall_type* hwt;
981
982 if (_IOC_TYPE(a) != HARDWALL_IOCTL_BASE)
983 return -EINVAL;
984
985 BUILD_BUG_ON(HARDWALL_TYPES != _HARDWALL_TYPES);
986 BUILD_BUG_ON(HARDWALL_TYPES !=
987 sizeof(hardwall_types)/sizeof(hardwall_types[0]));
988
989 if (minor < 0 || minor >= HARDWALL_TYPES)
990 return -EINVAL;
991 hwt = &hardwall_types[minor];
992 WARN_ON(info && hwt != info->type);
993
994 switch (_IOC_NR(a)) {
995 case _HARDWALL_CREATE:
996 if (hwt->disabled)
997 return -ENOSYS;
998 if (info != NULL)
999 return -EALREADY;
1000 info = hardwall_create(hwt, _IOC_SIZE(a),
1001 (const unsigned char __user *)b);
1002 if (IS_ERR(info))
1003 return PTR_ERR(info);
1004 file->private_data = info;
1005 return 0;
1006
1007 case _HARDWALL_ACTIVATE:
1008 return hardwall_activate(info);
1009
1010 case _HARDWALL_DEACTIVATE:
1011 if (current->thread.hardwall[hwt->index].info != info)
1012 return -EINVAL;
1013 return hardwall_deactivate(hwt, current);
1014
1015 case _HARDWALL_GET_ID:
1016 return info ? info->id : -EINVAL;
1017
1018 default:
1019 return -EINVAL;
1020 }
1021}
1022
1023#ifdef CONFIG_COMPAT
1024static long hardwall_compat_ioctl(struct file *file,
1025 unsigned int a, unsigned long b)
1026{
1027 /* Sign-extend the argument so it can be used as a pointer. */
1028 return hardwall_ioctl(file, a, (unsigned long)compat_ptr(b));
1029}
1030#endif
1031
1032/* The user process closed the file; revoke access to user networks. */
1033static int hardwall_flush(struct file *file, fl_owner_t owner)
1034{
1035 struct hardwall_info *info = file->private_data;
1036 struct task_struct *task, *tmp;
1037 unsigned long flags;
1038
1039 if (info) {
1040 /*
1041 * NOTE: if multiple threads are activated on this hardwall
1042 * file, the other threads will continue having access to the
1043 * user network until they are context-switched out and back
1044 * in again.
1045 *
1046 * NOTE: A NULL files pointer means the task is being torn
1047 * down, so in that case we also deactivate it.
1048 */
1049 struct hardwall_type *hwt = info->type;
1050 spin_lock_irqsave(&hwt->lock, flags);
1051 list_for_each_entry_safe(task, tmp, &info->task_head,
1052 thread.hardwall[hwt->index].list) {
1053 if (task->files == owner || task->files == NULL)
1054 _hardwall_deactivate(hwt, task);
1055 }
1056 spin_unlock_irqrestore(&hwt->lock, flags);
1057 }
1058
1059 return 0;
1060}
1061
1062/* This hardwall is gone, so destroy it. */
1063static int hardwall_release(struct inode *inode, struct file *file)
1064{
1065 hardwall_destroy(file->private_data);
1066 return 0;
1067}
1068
1069static const struct file_operations dev_hardwall_fops = {
1070 .open = nonseekable_open,
1071 .unlocked_ioctl = hardwall_ioctl,
1072#ifdef CONFIG_COMPAT
1073 .compat_ioctl = hardwall_compat_ioctl,
1074#endif
1075 .flush = hardwall_flush,
1076 .release = hardwall_release,
1077};
1078
1079static struct cdev hardwall_dev;
1080
1081static int __init dev_hardwall_init(void)
1082{
1083 int rc;
1084 dev_t dev;
1085
1086 rc = alloc_chrdev_region(&dev, 0, HARDWALL_TYPES, "hardwall");
1087 if (rc < 0)
1088 return rc;
1089 cdev_init(&hardwall_dev, &dev_hardwall_fops);
1090 rc = cdev_add(&hardwall_dev, dev, HARDWALL_TYPES);
1091 if (rc < 0)
1092 return rc;
1093
1094 return 0;
1095}
1096late_initcall(dev_hardwall_init);
diff --git a/arch/tile/kernel/head_32.S b/arch/tile/kernel/head_32.S
deleted file mode 100644
index 8d5b40ff2922..000000000000
--- a/arch/tile/kernel/head_32.S
+++ /dev/null
@@ -1,183 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE startup code.
15 */
16
17#include <linux/linkage.h>
18#include <linux/init.h>
19#include <asm/page.h>
20#include <asm/pgtable.h>
21#include <asm/thread_info.h>
22#include <asm/processor.h>
23#include <asm/asm-offsets.h>
24#include <hv/hypervisor.h>
25#include <arch/chip.h>
26#include <arch/spr_def.h>
27
28/*
29 * This module contains the entry code for kernel images. It performs the
30 * minimal setup needed to call the generic C routines.
31 */
32
33 __HEAD
34ENTRY(_start)
35 /* Notify the hypervisor of what version of the API we want */
36 {
37 movei r1, TILE_CHIP
38 movei r2, TILE_CHIP_REV
39 }
40 {
41 moveli r0, _HV_VERSION_OLD_HV_INIT
42 jal _hv_init
43 }
44 /* Get a reasonable default ASID in r0 */
45 {
46 move r0, zero
47 jal _hv_inquire_asid
48 }
49 /* Install the default page table */
50 {
51 moveli r6, lo16(swapper_pgprot - PAGE_OFFSET)
52 move r4, r0 /* use starting ASID of range for this page table */
53 }
54 {
55 moveli r0, lo16(swapper_pg_dir - PAGE_OFFSET)
56 auli r6, r6, ha16(swapper_pgprot - PAGE_OFFSET)
57 }
58 {
59 lw r2, r6
60 addi r6, r6, 4
61 }
62 {
63 lw r3, r6
64 auli r0, r0, ha16(swapper_pg_dir - PAGE_OFFSET)
65 }
66 {
67 finv r6
68 move r1, zero /* high 32 bits of CPA is zero */
69 }
70 {
71 moveli lr, lo16(1f)
72 moveli r5, CTX_PAGE_FLAG
73 }
74 {
75 auli lr, lr, ha16(1f)
76 j _hv_install_context
77 }
781:
79
80 /* Get our processor number and save it away in SAVE_K_0. */
81 jal _hv_inquire_topology
82 mulll_uu r4, r1, r2 /* r1 == y, r2 == width */
83 add r4, r4, r0 /* r0 == x, so r4 == cpu == y*width + x */
84
85#ifdef CONFIG_SMP
86 /*
87 * Load up our per-cpu offset. When the first (master) tile
88 * boots, this value is still zero, so we will load boot_pc
89 * with start_kernel, and boot_sp at the top of init_stack.
90 * The master tile initializes the per-cpu offset array, so that
91 * when subsequent (secondary) tiles boot, they will instead load
92 * from their per-cpu versions of boot_sp and boot_pc.
93 */
94 moveli r5, lo16(__per_cpu_offset)
95 auli r5, r5, ha16(__per_cpu_offset)
96 s2a r5, r4, r5
97 lw r5, r5
98 bnz r5, 1f
99
100 /*
101 * Save the width and height to the smp_topology variable
102 * for later use.
103 */
104 moveli r0, lo16(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
105 auli r0, r0, ha16(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
106 {
107 sw r0, r2
108 addi r0, r0, (HV_TOPOLOGY_HEIGHT_OFFSET - HV_TOPOLOGY_WIDTH_OFFSET)
109 }
110 sw r0, r3
1111:
112#else
113 move r5, zero
114#endif
115
116 /* Load and go with the correct pc and sp. */
117 {
118 addli r1, r5, lo16(boot_sp)
119 addli r0, r5, lo16(boot_pc)
120 }
121 {
122 auli r1, r1, ha16(boot_sp)
123 auli r0, r0, ha16(boot_pc)
124 }
125 lw r0, r0
126 lw sp, r1
127 or r4, sp, r4
128 mtspr SPR_SYSTEM_SAVE_K_0, r4 /* save ksp0 + cpu */
129 {
130 move lr, zero /* stop backtraces in the called function */
131 jr r0
132 }
133 ENDPROC(_start)
134
135__PAGE_ALIGNED_BSS
136 .align PAGE_SIZE
137ENTRY(empty_zero_page)
138 .fill PAGE_SIZE,1,0
139 END(empty_zero_page)
140
141 .macro PTE va, cpa, bits1, no_org=0
142 .ifeq \no_org
143 .org swapper_pg_dir + PGD_INDEX(\va) * HV_PTE_SIZE
144 .endif
145 .word HV_PTE_PAGE | HV_PTE_DIRTY | HV_PTE_PRESENT | HV_PTE_ACCESSED | \
146 (HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE)
147 .word (\bits1) | (HV_CPA_TO_PTFN(\cpa) << (HV_PTE_INDEX_PTFN - 32))
148 .endm
149
150__PAGE_ALIGNED_DATA
151 .align PAGE_SIZE
152ENTRY(swapper_pg_dir)
153 /*
154 * All data pages from PAGE_OFFSET to MEM_USER_INTRPT are mapped as
155 * VA = PA + PAGE_OFFSET. We remap things with more precise access
156 * permissions and more respect for size of RAM later.
157 */
158 .set addr, 0
159 .rept (MEM_USER_INTRPT - PAGE_OFFSET) >> PGDIR_SHIFT
160 PTE addr + PAGE_OFFSET, addr, (1 << (HV_PTE_INDEX_READABLE - 32)) | \
161 (1 << (HV_PTE_INDEX_WRITABLE - 32))
162 .set addr, addr + PGDIR_SIZE
163 .endr
164
165 /* The true text VAs are mapped as VA = PA + MEM_SV_START */
166 PTE MEM_SV_START, 0, (1 << (HV_PTE_INDEX_READABLE - 32)) | \
167 (1 << (HV_PTE_INDEX_EXECUTABLE - 32))
168 .org swapper_pg_dir + PGDIR_SIZE
169 END(swapper_pg_dir)
170
171 /*
172 * Isolate swapper_pgprot to its own cache line, since each cpu
173 * starting up will read it using VA-is-PA and local homing.
174 * This would otherwise likely conflict with other data on the cache
175 * line, once we have set its permanent home in the page tables.
176 */
177 __INITDATA
178 .align CHIP_L2_LINE_SIZE()
179ENTRY(swapper_pgprot)
180 PTE 0, 0, (1 << (HV_PTE_INDEX_READABLE - 32)) | \
181 (1 << (HV_PTE_INDEX_WRITABLE - 32)), 1
182 .align CHIP_L2_LINE_SIZE()
183 END(swapper_pgprot)
diff --git a/arch/tile/kernel/head_64.S b/arch/tile/kernel/head_64.S
deleted file mode 100644
index bd0e12f283f3..000000000000
--- a/arch/tile/kernel/head_64.S
+++ /dev/null
@@ -1,279 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE startup code.
15 */
16
17#include <linux/linkage.h>
18#include <linux/init.h>
19#include <asm/page.h>
20#include <asm/pgtable.h>
21#include <asm/thread_info.h>
22#include <asm/processor.h>
23#include <asm/asm-offsets.h>
24#include <hv/hypervisor.h>
25#include <arch/chip.h>
26#include <arch/spr_def.h>
27
28/* Extract two 32-bit bit values that were read into one register. */
29#ifdef __BIG_ENDIAN__
30#define GET_FIRST_INT(rd, rs) shrsi rd, rs, 32
31#define GET_SECOND_INT(rd, rs) addxi rd, rs, 0
32#else
33#define GET_FIRST_INT(rd, rs) addxi rd, rs, 0
34#define GET_SECOND_INT(rd, rs) shrsi rd, rs, 32
35#endif
36
37/*
38 * This module contains the entry code for kernel images. It performs the
39 * minimal setup needed to call the generic C routines.
40 */
41
42 __HEAD
43ENTRY(_start)
44 /* Notify the hypervisor of what version of the API we want */
45 {
46#if KERNEL_PL == 1 && _HV_VERSION == 13
47 /* Support older hypervisors by asking for API version 12. */
48 movei r0, _HV_VERSION_OLD_HV_INIT
49#else
50 movei r0, _HV_VERSION
51#endif
52 movei r1, TILE_CHIP
53 }
54 {
55 movei r2, TILE_CHIP_REV
56 movei r3, KERNEL_PL
57 }
58 jal _hv_init
59 /* Get a reasonable default ASID in r0 */
60 {
61 move r0, zero
62 jal _hv_inquire_asid
63 }
64
65 /*
66 * Install the default page table. The relocation required to
67 * statically define the table is a bit too complex, so we have
68 * to plug in the pointer from the L0 to the L1 table by hand.
69 * We only do this on the first cpu to boot, though, since the
70 * other CPUs should see a properly-constructed page table.
71 */
72 {
73 GET_FIRST_INT(r2, r0) /* ASID for hv_install_context */
74 moveli r4, hw1_last(swapper_pgprot - PAGE_OFFSET)
75 }
76 {
77 shl16insli r4, r4, hw0(swapper_pgprot - PAGE_OFFSET)
78 }
79 {
80 ld r1, r4 /* access_pte for hv_install_context */
81 }
82 {
83 moveli r0, hw1_last(.Lsv_data_pmd - PAGE_OFFSET)
84 moveli r6, hw1_last(temp_data_pmd - PAGE_OFFSET)
85 }
86 {
87 /* After initializing swapper_pgprot, HV_PTE_GLOBAL is set. */
88 bfextu r7, r1, HV_PTE_INDEX_GLOBAL, HV_PTE_INDEX_GLOBAL
89 finv r4
90 }
91 bnez r7, .Lno_write
92 {
93 shl16insli r0, r0, hw0(.Lsv_data_pmd - PAGE_OFFSET)
94 shl16insli r6, r6, hw0(temp_data_pmd - PAGE_OFFSET)
95 }
96 {
97 /* Cut off the low bits of the PT address. */
98 shrui r6, r6, HV_LOG2_PAGE_TABLE_ALIGN
99 /* Start with our access pte. */
100 move r5, r1
101 }
102 {
103 /* Stuff the address into the page table pointer slot of the PTE. */
104 bfins r5, r6, HV_PTE_INDEX_PTFN, \
105 HV_PTE_INDEX_PTFN + HV_PTE_PTFN_BITS - 1
106 }
107 {
108 /* Store the L0 data PTE. */
109 st r0, r5
110 addli r6, r6, (temp_code_pmd - temp_data_pmd) >> \
111 HV_LOG2_PAGE_TABLE_ALIGN
112 }
113 {
114 addli r0, r0, .Lsv_code_pmd - .Lsv_data_pmd
115 bfins r5, r6, HV_PTE_INDEX_PTFN, \
116 HV_PTE_INDEX_PTFN + HV_PTE_PTFN_BITS - 1
117 }
118 /* Store the L0 code PTE. */
119 st r0, r5
120
121.Lno_write:
122 moveli lr, hw2_last(1f)
123 {
124 shl16insli lr, lr, hw1(1f)
125 moveli r0, hw1_last(swapper_pg_dir - PAGE_OFFSET)
126 }
127 {
128 shl16insli lr, lr, hw0(1f)
129 shl16insli r0, r0, hw0(swapper_pg_dir - PAGE_OFFSET)
130 }
131 {
132 moveli r3, CTX_PAGE_FLAG
133 j _hv_install_context
134 }
1351:
136
137 /* Install the interrupt base. */
138 moveli r0, hw2_last(intrpt_start)
139 shl16insli r0, r0, hw1(intrpt_start)
140 shl16insli r0, r0, hw0(intrpt_start)
141 mtspr SPR_INTERRUPT_VECTOR_BASE_K, r0
142
143 /* Get our processor number and save it away in SAVE_K_0. */
144 jal _hv_inquire_topology
145 {
146 GET_FIRST_INT(r5, r1) /* r5 = width */
147 GET_SECOND_INT(r4, r0) /* r4 = y */
148 }
149 {
150 GET_FIRST_INT(r6, r0) /* r6 = x */
151 mul_lu_lu r4, r4, r5
152 }
153 {
154 add r4, r4, r6 /* r4 == cpu == y*width + x */
155 }
156
157#ifdef CONFIG_SMP
158 /*
159 * Load up our per-cpu offset. When the first (master) tile
160 * boots, this value is still zero, so we will load boot_pc
161 * with start_kernel, and boot_sp with at the top of init_stack.
162 * The master tile initializes the per-cpu offset array, so that
163 * when subsequent (secondary) tiles boot, they will instead load
164 * from their per-cpu versions of boot_sp and boot_pc.
165 */
166 moveli r5, hw2_last(__per_cpu_offset)
167 shl16insli r5, r5, hw1(__per_cpu_offset)
168 shl16insli r5, r5, hw0(__per_cpu_offset)
169 shl3add r5, r4, r5
170 ld r5, r5
171 bnez r5, 1f
172
173 /*
174 * Save the width and height to the smp_topology variable
175 * for later use.
176 */
177 moveli r0, hw2_last(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
178 shl16insli r0, r0, hw1(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
179 shl16insli r0, r0, hw0(smp_topology + HV_TOPOLOGY_WIDTH_OFFSET)
180 st r0, r1
1811:
182#else
183 move r5, zero
184#endif
185
186 /* Load and go with the correct pc and sp. */
187 {
188 moveli r1, hw2_last(boot_sp)
189 moveli r0, hw2_last(boot_pc)
190 }
191 {
192 shl16insli r1, r1, hw1(boot_sp)
193 shl16insli r0, r0, hw1(boot_pc)
194 }
195 {
196 shl16insli r1, r1, hw0(boot_sp)
197 shl16insli r0, r0, hw0(boot_pc)
198 }
199 {
200 add r1, r1, r5
201 add r0, r0, r5
202 }
203 ld r0, r0
204 ld sp, r1
205 shli r4, r4, CPU_SHIFT
206 bfins r4, sp, 0, CPU_SHIFT-1
207 mtspr SPR_SYSTEM_SAVE_K_0, r4 /* save ksp0 + cpu */
208 {
209 move lr, zero /* stop backtraces in the called function */
210 jr r0
211 }
212 ENDPROC(_start)
213
214__PAGE_ALIGNED_BSS
215 .align PAGE_SIZE
216ENTRY(empty_zero_page)
217 .fill PAGE_SIZE,1,0
218 END(empty_zero_page)
219
220 .macro PTE cpa, bits1
221 .quad HV_PTE_PAGE | HV_PTE_DIRTY | HV_PTE_PRESENT | HV_PTE_ACCESSED |\
222 HV_PTE_GLOBAL | (HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE) |\
223 (\bits1) | (HV_CPA_TO_PTFN(\cpa) << HV_PTE_INDEX_PTFN)
224 .endm
225
226__PAGE_ALIGNED_DATA
227 .align PAGE_SIZE
228ENTRY(swapper_pg_dir)
229 .org swapper_pg_dir + PGD_INDEX(PAGE_OFFSET) * HV_PTE_SIZE
230.Lsv_data_pmd:
231 .quad 0 /* PTE temp_data_pmd - PAGE_OFFSET, 0 */
232 .org swapper_pg_dir + PGD_INDEX(MEM_SV_START) * HV_PTE_SIZE
233.Lsv_code_pmd:
234 .quad 0 /* PTE temp_code_pmd - PAGE_OFFSET, 0 */
235 .org swapper_pg_dir + SIZEOF_PGD
236 END(swapper_pg_dir)
237
238 .align HV_PAGE_TABLE_ALIGN
239ENTRY(temp_data_pmd)
240 /*
241 * We fill the PAGE_OFFSET pmd with huge pages with
242 * VA = PA + PAGE_OFFSET. We remap things with more precise access
243 * permissions later.
244 */
245 .set addr, 0
246 .rept PTRS_PER_PMD
247 PTE addr, HV_PTE_READABLE | HV_PTE_WRITABLE
248 .set addr, addr + HPAGE_SIZE
249 .endr
250 .org temp_data_pmd + SIZEOF_PMD
251 END(temp_data_pmd)
252
253 .align HV_PAGE_TABLE_ALIGN
254ENTRY(temp_code_pmd)
255 /*
256 * We fill the MEM_SV_START pmd with huge pages with
257 * VA = PA + PAGE_OFFSET. We remap things with more precise access
258 * permissions later.
259 */
260 .set addr, 0
261 .rept PTRS_PER_PMD
262 PTE addr, HV_PTE_READABLE | HV_PTE_EXECUTABLE
263 .set addr, addr + HPAGE_SIZE
264 .endr
265 .org temp_code_pmd + SIZEOF_PMD
266 END(temp_code_pmd)
267
268 /*
269 * Isolate swapper_pgprot to its own cache line, since each cpu
270 * starting up will read it using VA-is-PA and local homing.
271 * This would otherwise likely conflict with other data on the cache
272 * line, once we have set its permanent home in the page tables.
273 */
274 __INITDATA
275 .align CHIP_L2_LINE_SIZE()
276ENTRY(swapper_pgprot)
277 .quad HV_PTE_PRESENT | (HV_PTE_MODE_CACHE_NO_L3 << HV_PTE_INDEX_MODE)
278 .align CHIP_L2_LINE_SIZE()
279 END(swapper_pgprot)
diff --git a/arch/tile/kernel/hvglue.S b/arch/tile/kernel/hvglue.S
deleted file mode 100644
index 70c661448638..000000000000
--- a/arch/tile/kernel/hvglue.S
+++ /dev/null
@@ -1,76 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Hypervisor call vector addresses; see <hv/hypervisor.h> */
3.macro gensym sym, val, size
4.org \val
5.global _\sym
6.type _\sym,function
7_\sym:
8.size _\sym,\size
9#ifndef CONFIG_TILE_HVGLUE_TRACE
10.globl \sym
11.set \sym,_\sym
12#endif
13.endm
14
15.section .hvglue,"x",@nobits
16.align 8
17gensym hv_init, 0x20, 32
18gensym hv_install_context, 0x40, 32
19gensym hv_sysconf, 0x60, 32
20gensym hv_get_rtc, 0x80, 32
21gensym hv_set_rtc, 0xa0, 32
22gensym hv_flush_asid, 0xc0, 32
23gensym hv_flush_page, 0xe0, 32
24gensym hv_flush_pages, 0x100, 32
25gensym hv_restart, 0x120, 32
26gensym hv_halt, 0x140, 32
27gensym hv_power_off, 0x160, 32
28gensym hv_inquire_physical, 0x180, 32
29gensym hv_inquire_memory_controller, 0x1a0, 32
30gensym hv_inquire_virtual, 0x1c0, 32
31gensym hv_inquire_asid, 0x1e0, 32
32gensym hv_nanosleep, 0x200, 32
33gensym hv_console_read_if_ready, 0x220, 32
34gensym hv_console_write, 0x240, 32
35gensym hv_downcall_dispatch, 0x260, 32
36gensym hv_inquire_topology, 0x280, 32
37gensym hv_fs_findfile, 0x2a0, 32
38gensym hv_fs_fstat, 0x2c0, 32
39gensym hv_fs_pread, 0x2e0, 32
40gensym hv_physaddr_read64, 0x300, 32
41gensym hv_physaddr_write64, 0x320, 32
42gensym hv_get_command_line, 0x340, 32
43gensym hv_set_caching, 0x360, 32
44gensym hv_bzero_page, 0x380, 32
45gensym hv_register_message_state, 0x3a0, 32
46gensym hv_send_message, 0x3c0, 32
47gensym hv_receive_message, 0x3e0, 32
48gensym hv_inquire_context, 0x400, 32
49gensym hv_start_all_tiles, 0x420, 32
50gensym hv_dev_open, 0x440, 32
51gensym hv_dev_close, 0x460, 32
52gensym hv_dev_pread, 0x480, 32
53gensym hv_dev_pwrite, 0x4a0, 32
54gensym hv_dev_poll, 0x4c0, 32
55gensym hv_dev_poll_cancel, 0x4e0, 32
56gensym hv_dev_preada, 0x500, 32
57gensym hv_dev_pwritea, 0x520, 32
58gensym hv_flush_remote, 0x540, 32
59gensym hv_console_putc, 0x560, 32
60gensym hv_inquire_tiles, 0x580, 32
61gensym hv_confstr, 0x5a0, 32
62gensym hv_reexec, 0x5c0, 32
63gensym hv_set_command_line, 0x5e0, 32
64gensym hv_clear_intr, 0x600, 32
65gensym hv_enable_intr, 0x620, 32
66gensym hv_disable_intr, 0x640, 32
67gensym hv_raise_intr, 0x660, 32
68gensym hv_trigger_ipi, 0x680, 32
69gensym hv_store_mapping, 0x6a0, 32
70gensym hv_inquire_realpa, 0x6c0, 32
71gensym hv_flush_all, 0x6e0, 32
72gensym hv_get_ipi_pte, 0x700, 32
73gensym hv_set_pte_super_shift, 0x720, 32
74gensym hv_console_set_ipi, 0x7e0, 32
75gensym hv_send_nmi, 0x820, 32
76gensym hv_glue_internals, 0x820, 30688
diff --git a/arch/tile/kernel/hvglue_trace.c b/arch/tile/kernel/hvglue_trace.c
deleted file mode 100644
index add0d71395c6..000000000000
--- a/arch/tile/kernel/hvglue_trace.c
+++ /dev/null
@@ -1,270 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15/*
16 * Pull in the hypervisor header so we declare all the ABI functions
17 * with the underscore versions, then undef the names so that we can
18 * provide our own wrapper versions.
19 */
20#define hv_init _hv_init
21#define hv_install_context _hv_install_context
22#define hv_sysconf _hv_sysconf
23#define hv_get_rtc _hv_get_rtc
24#define hv_set_rtc _hv_set_rtc
25#define hv_flush_asid _hv_flush_asid
26#define hv_flush_page _hv_flush_page
27#define hv_flush_pages _hv_flush_pages
28#define hv_restart _hv_restart
29#define hv_halt _hv_halt
30#define hv_power_off _hv_power_off
31#define hv_inquire_physical _hv_inquire_physical
32#define hv_inquire_memory_controller _hv_inquire_memory_controller
33#define hv_inquire_virtual _hv_inquire_virtual
34#define hv_inquire_asid _hv_inquire_asid
35#define hv_nanosleep _hv_nanosleep
36#define hv_console_read_if_ready _hv_console_read_if_ready
37#define hv_console_write _hv_console_write
38#define hv_downcall_dispatch _hv_downcall_dispatch
39#define hv_inquire_topology _hv_inquire_topology
40#define hv_fs_findfile _hv_fs_findfile
41#define hv_fs_fstat _hv_fs_fstat
42#define hv_fs_pread _hv_fs_pread
43#define hv_physaddr_read64 _hv_physaddr_read64
44#define hv_physaddr_write64 _hv_physaddr_write64
45#define hv_get_command_line _hv_get_command_line
46#define hv_set_caching _hv_set_caching
47#define hv_bzero_page _hv_bzero_page
48#define hv_register_message_state _hv_register_message_state
49#define hv_send_message _hv_send_message
50#define hv_receive_message _hv_receive_message
51#define hv_inquire_context _hv_inquire_context
52#define hv_start_all_tiles _hv_start_all_tiles
53#define hv_dev_open _hv_dev_open
54#define hv_dev_close _hv_dev_close
55#define hv_dev_pread _hv_dev_pread
56#define hv_dev_pwrite _hv_dev_pwrite
57#define hv_dev_poll _hv_dev_poll
58#define hv_dev_poll_cancel _hv_dev_poll_cancel
59#define hv_dev_preada _hv_dev_preada
60#define hv_dev_pwritea _hv_dev_pwritea
61#define hv_flush_remote _hv_flush_remote
62#define hv_console_putc _hv_console_putc
63#define hv_inquire_tiles _hv_inquire_tiles
64#define hv_confstr _hv_confstr
65#define hv_reexec _hv_reexec
66#define hv_set_command_line _hv_set_command_line
67#define hv_clear_intr _hv_clear_intr
68#define hv_enable_intr _hv_enable_intr
69#define hv_disable_intr _hv_disable_intr
70#define hv_raise_intr _hv_raise_intr
71#define hv_trigger_ipi _hv_trigger_ipi
72#define hv_store_mapping _hv_store_mapping
73#define hv_inquire_realpa _hv_inquire_realpa
74#define hv_flush_all _hv_flush_all
75#define hv_get_ipi_pte _hv_get_ipi_pte
76#define hv_set_pte_super_shift _hv_set_pte_super_shift
77#define hv_console_set_ipi _hv_console_set_ipi
78#define hv_send_nmi _hv_send_nmi
79#include <hv/hypervisor.h>
80#undef hv_init
81#undef hv_install_context
82#undef hv_sysconf
83#undef hv_get_rtc
84#undef hv_set_rtc
85#undef hv_flush_asid
86#undef hv_flush_page
87#undef hv_flush_pages
88#undef hv_restart
89#undef hv_halt
90#undef hv_power_off
91#undef hv_inquire_physical
92#undef hv_inquire_memory_controller
93#undef hv_inquire_virtual
94#undef hv_inquire_asid
95#undef hv_nanosleep
96#undef hv_console_read_if_ready
97#undef hv_console_write
98#undef hv_downcall_dispatch
99#undef hv_inquire_topology
100#undef hv_fs_findfile
101#undef hv_fs_fstat
102#undef hv_fs_pread
103#undef hv_physaddr_read64
104#undef hv_physaddr_write64
105#undef hv_get_command_line
106#undef hv_set_caching
107#undef hv_bzero_page
108#undef hv_register_message_state
109#undef hv_send_message
110#undef hv_receive_message
111#undef hv_inquire_context
112#undef hv_start_all_tiles
113#undef hv_dev_open
114#undef hv_dev_close
115#undef hv_dev_pread
116#undef hv_dev_pwrite
117#undef hv_dev_poll
118#undef hv_dev_poll_cancel
119#undef hv_dev_preada
120#undef hv_dev_pwritea
121#undef hv_flush_remote
122#undef hv_console_putc
123#undef hv_inquire_tiles
124#undef hv_confstr
125#undef hv_reexec
126#undef hv_set_command_line
127#undef hv_clear_intr
128#undef hv_enable_intr
129#undef hv_disable_intr
130#undef hv_raise_intr
131#undef hv_trigger_ipi
132#undef hv_store_mapping
133#undef hv_inquire_realpa
134#undef hv_flush_all
135#undef hv_get_ipi_pte
136#undef hv_set_pte_super_shift
137#undef hv_console_set_ipi
138#undef hv_send_nmi
139
140/*
141 * Provide macros based on <linux/syscalls.h> to provide a wrapper
142 * function that invokes the same function with an underscore prefix.
143 * We can't use the existing __SC_xxx macros because we need to
144 * support up to nine arguments rather than up to six, and also this
145 * way the file stands alone from possible changes in the
146 * implementation of <linux/syscalls.h>.
147 */
148#define HV_WRAP0(type, name) \
149 type name(void); \
150 type name(void) \
151 { \
152 return _##name(); \
153 }
154#define __HV_DECL1(t1, a1) t1 a1
155#define __HV_DECL2(t2, a2, ...) t2 a2, __HV_DECL1(__VA_ARGS__)
156#define __HV_DECL3(t3, a3, ...) t3 a3, __HV_DECL2(__VA_ARGS__)
157#define __HV_DECL4(t4, a4, ...) t4 a4, __HV_DECL3(__VA_ARGS__)
158#define __HV_DECL5(t5, a5, ...) t5 a5, __HV_DECL4(__VA_ARGS__)
159#define __HV_DECL6(t6, a6, ...) t6 a6, __HV_DECL5(__VA_ARGS__)
160#define __HV_DECL7(t7, a7, ...) t7 a7, __HV_DECL6(__VA_ARGS__)
161#define __HV_DECL8(t8, a8, ...) t8 a8, __HV_DECL7(__VA_ARGS__)
162#define __HV_DECL9(t9, a9, ...) t9 a9, __HV_DECL8(__VA_ARGS__)
163#define __HV_PASS1(t1, a1) a1
164#define __HV_PASS2(t2, a2, ...) a2, __HV_PASS1(__VA_ARGS__)
165#define __HV_PASS3(t3, a3, ...) a3, __HV_PASS2(__VA_ARGS__)
166#define __HV_PASS4(t4, a4, ...) a4, __HV_PASS3(__VA_ARGS__)
167#define __HV_PASS5(t5, a5, ...) a5, __HV_PASS4(__VA_ARGS__)
168#define __HV_PASS6(t6, a6, ...) a6, __HV_PASS5(__VA_ARGS__)
169#define __HV_PASS7(t7, a7, ...) a7, __HV_PASS6(__VA_ARGS__)
170#define __HV_PASS8(t8, a8, ...) a8, __HV_PASS7(__VA_ARGS__)
171#define __HV_PASS9(t9, a9, ...) a9, __HV_PASS8(__VA_ARGS__)
172#define HV_WRAPx(x, type, name, ...) \
173 type name(__HV_DECL##x(__VA_ARGS__)); \
174 type name(__HV_DECL##x(__VA_ARGS__)) \
175 { \
176 return _##name(__HV_PASS##x(__VA_ARGS__)); \
177 }
178#define HV_WRAP1(type, name, ...) HV_WRAPx(1, type, name, __VA_ARGS__)
179#define HV_WRAP2(type, name, ...) HV_WRAPx(2, type, name, __VA_ARGS__)
180#define HV_WRAP3(type, name, ...) HV_WRAPx(3, type, name, __VA_ARGS__)
181#define HV_WRAP4(type, name, ...) HV_WRAPx(4, type, name, __VA_ARGS__)
182#define HV_WRAP5(type, name, ...) HV_WRAPx(5, type, name, __VA_ARGS__)
183#define HV_WRAP6(type, name, ...) HV_WRAPx(6, type, name, __VA_ARGS__)
184#define HV_WRAP7(type, name, ...) HV_WRAPx(7, type, name, __VA_ARGS__)
185#define HV_WRAP8(type, name, ...) HV_WRAPx(8, type, name, __VA_ARGS__)
186#define HV_WRAP9(type, name, ...) HV_WRAPx(9, type, name, __VA_ARGS__)
187
188/* List all the hypervisor API functions. */
189HV_WRAP4(void, hv_init, HV_VersionNumber, interface_version_number,
190 int, chip_num, int, chip_rev_num, int, client_pl)
191HV_WRAP1(long, hv_sysconf, HV_SysconfQuery, query)
192HV_WRAP3(int, hv_confstr, HV_ConfstrQuery, query, HV_VirtAddr, buf, int, len)
193#if CHIP_HAS_IPI()
194HV_WRAP3(int, hv_get_ipi_pte, HV_Coord, tile, int, pl, HV_PTE*, pte)
195HV_WRAP3(int, hv_console_set_ipi, int, ipi, int, event, HV_Coord, coord);
196#else
197HV_WRAP1(void, hv_enable_intr, HV_IntrMask, enab_mask)
198HV_WRAP1(void, hv_disable_intr, HV_IntrMask, disab_mask)
199HV_WRAP1(void, hv_clear_intr, HV_IntrMask, clear_mask)
200HV_WRAP1(void, hv_raise_intr, HV_IntrMask, raise_mask)
201HV_WRAP2(HV_Errno, hv_trigger_ipi, HV_Coord, tile, int, interrupt)
202#endif /* !CHIP_HAS_IPI() */
203HV_WRAP3(int, hv_store_mapping, HV_VirtAddr, va, unsigned int, len,
204 HV_PhysAddr, pa)
205HV_WRAP2(HV_PhysAddr, hv_inquire_realpa, HV_PhysAddr, cpa, unsigned int, len)
206HV_WRAP0(HV_RTCTime, hv_get_rtc)
207HV_WRAP1(void, hv_set_rtc, HV_RTCTime, time)
208HV_WRAP4(int, hv_install_context, HV_PhysAddr, page_table, HV_PTE, access,
209 HV_ASID, asid, __hv32, flags)
210HV_WRAP2(int, hv_set_pte_super_shift, int, level, int, log2_count)
211HV_WRAP0(HV_Context, hv_inquire_context)
212HV_WRAP1(int, hv_flush_asid, HV_ASID, asid)
213HV_WRAP2(int, hv_flush_page, HV_VirtAddr, address, HV_PageSize, page_size)
214HV_WRAP3(int, hv_flush_pages, HV_VirtAddr, start, HV_PageSize, page_size,
215 unsigned long, size)
216HV_WRAP1(int, hv_flush_all, int, preserve_global)
217HV_WRAP2(void, hv_restart, HV_VirtAddr, cmd, HV_VirtAddr, args)
218HV_WRAP0(void, hv_halt)
219HV_WRAP0(void, hv_power_off)
220HV_WRAP1(int, hv_reexec, HV_PhysAddr, entry)
221HV_WRAP0(HV_Topology, hv_inquire_topology)
222HV_WRAP3(HV_Errno, hv_inquire_tiles, HV_InqTileSet, set, HV_VirtAddr, cpumask,
223 int, length)
224HV_WRAP1(HV_PhysAddrRange, hv_inquire_physical, int, idx)
225HV_WRAP2(HV_MemoryControllerInfo, hv_inquire_memory_controller, HV_Coord, coord,
226 int, controller)
227HV_WRAP1(HV_VirtAddrRange, hv_inquire_virtual, int, idx)
228HV_WRAP1(HV_ASIDRange, hv_inquire_asid, int, idx)
229HV_WRAP1(void, hv_nanosleep, int, nanosecs)
230HV_WRAP0(int, hv_console_read_if_ready)
231HV_WRAP1(void, hv_console_putc, int, byte)
232HV_WRAP2(int, hv_console_write, HV_VirtAddr, bytes, int, len)
233HV_WRAP0(void, hv_downcall_dispatch)
234HV_WRAP1(int, hv_fs_findfile, HV_VirtAddr, filename)
235HV_WRAP1(HV_FS_StatInfo, hv_fs_fstat, int, inode)
236HV_WRAP4(int, hv_fs_pread, int, inode, HV_VirtAddr, buf,
237 int, length, int, offset)
238HV_WRAP2(unsigned long long, hv_physaddr_read64, HV_PhysAddr, addr,
239 HV_PTE, access)
240HV_WRAP3(void, hv_physaddr_write64, HV_PhysAddr, addr, HV_PTE, access,
241 unsigned long long, val)
242HV_WRAP2(int, hv_get_command_line, HV_VirtAddr, buf, int, length)
243HV_WRAP2(HV_Errno, hv_set_command_line, HV_VirtAddr, buf, int, length)
244HV_WRAP1(void, hv_set_caching, unsigned long, bitmask)
245HV_WRAP2(void, hv_bzero_page, HV_VirtAddr, va, unsigned int, size)
246HV_WRAP1(HV_Errno, hv_register_message_state, HV_MsgState*, msgstate)
247HV_WRAP4(int, hv_send_message, HV_Recipient *, recips, int, nrecip,
248 HV_VirtAddr, buf, int, buflen)
249HV_WRAP3(HV_RcvMsgInfo, hv_receive_message, HV_MsgState, msgstate,
250 HV_VirtAddr, buf, int, buflen)
251HV_WRAP0(void, hv_start_all_tiles)
252HV_WRAP2(int, hv_dev_open, HV_VirtAddr, name, __hv32, flags)
253HV_WRAP1(int, hv_dev_close, int, devhdl)
254HV_WRAP5(int, hv_dev_pread, int, devhdl, __hv32, flags, HV_VirtAddr, va,
255 __hv32, len, __hv64, offset)
256HV_WRAP5(int, hv_dev_pwrite, int, devhdl, __hv32, flags, HV_VirtAddr, va,
257 __hv32, len, __hv64, offset)
258HV_WRAP3(int, hv_dev_poll, int, devhdl, __hv32, events, HV_IntArg, intarg)
259HV_WRAP1(int, hv_dev_poll_cancel, int, devhdl)
260HV_WRAP6(int, hv_dev_preada, int, devhdl, __hv32, flags, __hv32, sgl_len,
261 HV_SGL *, sglp, __hv64, offset, HV_IntArg, intarg)
262HV_WRAP6(int, hv_dev_pwritea, int, devhdl, __hv32, flags, __hv32, sgl_len,
263 HV_SGL *, sglp, __hv64, offset, HV_IntArg, intarg)
264HV_WRAP9(int, hv_flush_remote, HV_PhysAddr, cache_pa,
265 unsigned long, cache_control, unsigned long*, cache_cpumask,
266 HV_VirtAddr, tlb_va, unsigned long, tlb_length,
267 unsigned long, tlb_pgsize, unsigned long*, tlb_cpumask,
268 HV_Remote_ASID*, asids, int, asidcount)
269HV_WRAP3(HV_NMI_Info, hv_send_nmi, HV_Coord, tile, unsigned long, info,
270 __hv64, flags)
diff --git a/arch/tile/kernel/intvec_32.S b/arch/tile/kernel/intvec_32.S
deleted file mode 100644
index 9ff75e3a318a..000000000000
--- a/arch/tile/kernel/intvec_32.S
+++ /dev/null
@@ -1,1906 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Linux interrupt vectors.
15 */
16
17#include <linux/linkage.h>
18#include <linux/errno.h>
19#include <linux/init.h>
20#include <linux/unistd.h>
21#include <asm/ptrace.h>
22#include <asm/thread_info.h>
23#include <asm/irqflags.h>
24#include <asm/atomic_32.h>
25#include <asm/asm-offsets.h>
26#include <hv/hypervisor.h>
27#include <arch/abi.h>
28#include <arch/interrupts.h>
29#include <arch/spr_def.h>
30
31#define PTREGS_PTR(reg, ptreg) addli reg, sp, C_ABI_SAVE_AREA_SIZE + (ptreg)
32
33#define PTREGS_OFFSET_SYSCALL PTREGS_OFFSET_REG(TREG_SYSCALL_NR)
34
35 .macro push_reg reg, ptr=sp, delta=-4
36 {
37 sw \ptr, \reg
38 addli \ptr, \ptr, \delta
39 }
40 .endm
41
42 .macro pop_reg reg, ptr=sp, delta=4
43 {
44 lw \reg, \ptr
45 addli \ptr, \ptr, \delta
46 }
47 .endm
48
49 .macro pop_reg_zero reg, zreg, ptr=sp, delta=4
50 {
51 move \zreg, zero
52 lw \reg, \ptr
53 addi \ptr, \ptr, \delta
54 }
55 .endm
56
57 .macro push_extra_callee_saves reg
58 PTREGS_PTR(\reg, PTREGS_OFFSET_REG(51))
59 push_reg r51, \reg
60 push_reg r50, \reg
61 push_reg r49, \reg
62 push_reg r48, \reg
63 push_reg r47, \reg
64 push_reg r46, \reg
65 push_reg r45, \reg
66 push_reg r44, \reg
67 push_reg r43, \reg
68 push_reg r42, \reg
69 push_reg r41, \reg
70 push_reg r40, \reg
71 push_reg r39, \reg
72 push_reg r38, \reg
73 push_reg r37, \reg
74 push_reg r36, \reg
75 push_reg r35, \reg
76 push_reg r34, \reg, PTREGS_OFFSET_BASE - PTREGS_OFFSET_REG(34)
77 .endm
78
79 .macro panic str
80 .pushsection .rodata, "a"
811:
82 .asciz "\str"
83 .popsection
84 {
85 moveli r0, lo16(1b)
86 }
87 {
88 auli r0, r0, ha16(1b)
89 jal panic
90 }
91 .endm
92
93#ifdef __COLLECT_LINKER_FEEDBACK__
94 .pushsection .text.intvec_feedback,"ax"
95intvec_feedback:
96 .popsection
97#endif
98
99 /*
100 * Default interrupt handler.
101 *
102 * vecnum is where we'll put this code.
103 * c_routine is the C routine we'll call.
104 *
105 * The C routine is passed two arguments:
106 * - A pointer to the pt_regs state.
107 * - The interrupt vector number.
108 *
109 * The "processing" argument specifies the code for processing
110 * the interrupt. Defaults to "handle_interrupt".
111 */
112 .macro int_hand vecnum, vecname, c_routine, processing=handle_interrupt
113 .org (\vecnum << 8)
114intvec_\vecname:
115 .ifc \vecnum, INT_SWINT_1
116 blz TREG_SYSCALL_NR_NAME, sys_cmpxchg
117 .endif
118
119 /* Temporarily save a register so we have somewhere to work. */
120
121 mtspr SPR_SYSTEM_SAVE_K_1, r0
122 mfspr r0, SPR_EX_CONTEXT_K_1
123
124 /* The cmpxchg code clears sp to force us to reset it here on fault. */
125 {
126 bz sp, 2f
127 andi r0, r0, SPR_EX_CONTEXT_1_1__PL_MASK /* mask off ICS */
128 }
129
130 .ifc \vecnum, INT_DOUBLE_FAULT
131 /*
132 * For double-faults from user-space, fall through to the normal
133 * register save and stack setup path. Otherwise, it's the
134 * hypervisor giving us one last chance to dump diagnostics, and we
135 * branch to the kernel_double_fault routine to do so.
136 */
137 bz r0, 1f
138 j _kernel_double_fault
1391:
140 .else
141 /*
142 * If we're coming from user-space, then set sp to the top of
143 * the kernel stack. Otherwise, assume sp is already valid.
144 */
145 {
146 bnz r0, 0f
147 move r0, sp
148 }
149 .endif
150
151 .ifc \c_routine, do_page_fault
152 /*
153 * The page_fault handler may be downcalled directly by the
154 * hypervisor even when Linux is running and has ICS set.
155 *
156 * In this case the contents of EX_CONTEXT_K_1 reflect the
157 * previous fault and can't be relied on to choose whether or
158 * not to reinitialize the stack pointer. So we add a test
159 * to see whether SYSTEM_SAVE_K_2 has the high bit set,
160 * and if so we don't reinitialize sp, since we must be coming
161 * from Linux. (In fact the precise case is !(val & ~1),
162 * but any Linux PC has to have the high bit set.)
163 *
164 * Note that the hypervisor *always* sets SYSTEM_SAVE_K_2 for
165 * any path that turns into a downcall to one of our TLB handlers.
166 */
167 mfspr r0, SPR_SYSTEM_SAVE_K_2
168 {
169 blz r0, 0f /* high bit in S_S_1_2 is for a PC to use */
170 move r0, sp
171 }
172 .endif
173
1742:
175 /*
176 * SYSTEM_SAVE_K_0 holds the cpu number in the low bits, and
177 * the current stack top in the higher bits. So we recover
178 * our stack top by just masking off the low bits, then
179 * point sp at the top aligned address on the actual stack page.
180 */
181 mfspr r0, SPR_SYSTEM_SAVE_K_0
182 mm r0, r0, zero, LOG2_NR_CPU_IDS, 31
183
1840:
185 /*
186 * Align the stack mod 64 so we can properly predict what
187 * cache lines we need to write-hint to reduce memory fetch
188 * latency as we enter the kernel. The layout of memory is
189 * as follows, with cache line 0 at the lowest VA, and cache
190 * line 4 just below the r0 value this "andi" computes.
191 * Note that we never write to cache line 4, and we skip
192 * cache line 1 for syscalls.
193 *
194 * cache line 4: ptregs padding (two words)
195 * cache line 3: r46...lr, pc, ex1, faultnum, orig_r0, flags, pad
196 * cache line 2: r30...r45
197 * cache line 1: r14...r29
198 * cache line 0: 2 x frame, r0..r13
199 */
200#if STACK_TOP_DELTA != 64
201#error STACK_TOP_DELTA must be 64 for assumptions here and in task_pt_regs()
202#endif
203 andi r0, r0, -64
204
205 /*
206 * Push the first four registers on the stack, so that we can set
207 * them to vector-unique values before we jump to the common code.
208 *
209 * Registers are pushed on the stack as a struct pt_regs,
210 * with the sp initially just above the struct, and when we're
211 * done, sp points to the base of the struct, minus
212 * C_ABI_SAVE_AREA_SIZE, so we can directly jal to C code.
213 *
214 * This routine saves just the first four registers, plus the
215 * stack context so we can do proper backtracing right away,
216 * and defers to handle_interrupt to save the rest.
217 * The backtracer needs pc, ex1, lr, sp, r52, and faultnum.
218 */
219 addli r0, r0, PTREGS_OFFSET_LR - (PTREGS_SIZE + KSTK_PTREGS_GAP)
220 wh64 r0 /* cache line 3 */
221 {
222 sw r0, lr
223 addli r0, r0, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR
224 }
225 {
226 sw r0, sp
227 addli sp, r0, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_SP
228 }
229 {
230 sw sp, r52
231 addli sp, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(52)
232 }
233 wh64 sp /* cache line 0 */
234 {
235 sw sp, r1
236 addli sp, sp, PTREGS_OFFSET_REG(2) - PTREGS_OFFSET_REG(1)
237 }
238 {
239 sw sp, r2
240 addli sp, sp, PTREGS_OFFSET_REG(3) - PTREGS_OFFSET_REG(2)
241 }
242 {
243 sw sp, r3
244 addli sp, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_REG(3)
245 }
246 mfspr r0, SPR_EX_CONTEXT_K_0
247 .ifc \processing,handle_syscall
248 /*
249 * Bump the saved PC by one bundle so that when we return, we won't
250 * execute the same swint instruction again. We need to do this while
251 * we're in the critical section.
252 */
253 addi r0, r0, 8
254 .endif
255 {
256 sw sp, r0
257 addli sp, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_PC
258 }
259 mfspr r0, SPR_EX_CONTEXT_K_1
260 {
261 sw sp, r0
262 addi sp, sp, PTREGS_OFFSET_FAULTNUM - PTREGS_OFFSET_EX1
263 /*
264 * Use r0 for syscalls so it's a temporary; use r1 for interrupts
265 * so that it gets passed through unchanged to the handler routine.
266 * Note that the .if conditional confusingly spans bundles.
267 */
268 .ifc \processing,handle_syscall
269 movei r0, \vecnum
270 }
271 {
272 sw sp, r0
273 .else
274 movei r1, \vecnum
275 }
276 {
277 sw sp, r1
278 .endif
279 addli sp, sp, PTREGS_OFFSET_REG(0) - PTREGS_OFFSET_FAULTNUM
280 }
281 mfspr r0, SPR_SYSTEM_SAVE_K_1 /* Original r0 */
282 {
283 sw sp, r0
284 addi sp, sp, -PTREGS_OFFSET_REG(0) - 4
285 }
286 {
287 sw sp, zero /* write zero into "Next SP" frame pointer */
288 addi sp, sp, -4 /* leave SP pointing at bottom of frame */
289 }
290 .ifc \processing,handle_syscall
291 j handle_syscall
292 .else
293 /*
294 * Capture per-interrupt SPR context to registers.
295 * We overload the meaning of r3 on this path such that if its bit 31
296 * is set, we have to mask all interrupts including NMIs before
297 * clearing the interrupt critical section bit.
298 * See discussion below at "finish_interrupt_save".
299 */
300 .ifc \c_routine, do_page_fault
301 mfspr r2, SPR_SYSTEM_SAVE_K_3 /* address of page fault */
302 mfspr r3, SPR_SYSTEM_SAVE_K_2 /* info about page fault */
303 .else
304 .ifc \vecnum, INT_DOUBLE_FAULT
305 {
306 mfspr r2, SPR_SYSTEM_SAVE_K_2 /* double fault info from HV */
307 movei r3, 0
308 }
309 .else
310 .ifc \c_routine, do_trap
311 {
312 mfspr r2, GPV_REASON
313 movei r3, 0
314 }
315 .else
316 .ifc \c_routine, handle_perf_interrupt
317 {
318 mfspr r2, PERF_COUNT_STS
319 movei r3, -1 /* not used, but set for consistency */
320 }
321 .else
322 .ifc \c_routine, handle_perf_interrupt
323 {
324 mfspr r2, AUX_PERF_COUNT_STS
325 movei r3, -1 /* not used, but set for consistency */
326 }
327 .else
328 movei r3, 0
329 .endif
330 .endif
331 .endif
332 .endif
333 .endif
334 /* Put function pointer in r0 */
335 moveli r0, lo16(\c_routine)
336 {
337 auli r0, r0, ha16(\c_routine)
338 j \processing
339 }
340 .endif
341 ENDPROC(intvec_\vecname)
342
343#ifdef __COLLECT_LINKER_FEEDBACK__
344 .pushsection .text.intvec_feedback,"ax"
345 .org (\vecnum << 5)
346 FEEDBACK_ENTER_EXPLICIT(intvec_\vecname, .intrpt, 1 << 8)
347 jrp lr
348 .popsection
349#endif
350
351 .endm
352
353
354 /*
355 * Save the rest of the registers that we didn't save in the actual
356 * vector itself. We can't use r0-r10 inclusive here.
357 */
358 .macro finish_interrupt_save, function
359
360 /* If it's a syscall, save a proper orig_r0, otherwise just zero. */
361 PTREGS_PTR(r52, PTREGS_OFFSET_ORIG_R0)
362 {
363 .ifc \function,handle_syscall
364 sw r52, r0
365 .else
366 sw r52, zero
367 .endif
368 PTREGS_PTR(r52, PTREGS_OFFSET_TP)
369 }
370
371 /*
372 * For ordinary syscalls, we save neither caller- nor callee-
373 * save registers, since the syscall invoker doesn't expect the
374 * caller-saves to be saved, and the called kernel functions will
375 * take care of saving the callee-saves for us.
376 *
377 * For interrupts we save just the caller-save registers. Saving
378 * them is required (since the "caller" can't save them). Again,
379 * the called kernel functions will restore the callee-save
380 * registers for us appropriately.
381 *
382 * On return, we normally restore nothing special for syscalls,
383 * and just the caller-save registers for interrupts.
384 *
385 * However, there are some important caveats to all this:
386 *
387 * - We always save a few callee-save registers to give us
388 * some scratchpad registers to carry across function calls.
389 *
390 * - fork/vfork/etc require us to save all the callee-save
391 * registers, which we do in PTREGS_SYSCALL_ALL_REGS, below.
392 *
393 * - We always save r0..r5 and r10 for syscalls, since we need
394 * to reload them a bit later for the actual kernel call, and
395 * since we might need them for -ERESTARTNOINTR, etc.
396 *
397 * - Before invoking a signal handler, we save the unsaved
398 * callee-save registers so they are visible to the
399 * signal handler or any ptracer.
400 *
401 * - If the unsaved callee-save registers are modified, we set
402 * a bit in pt_regs so we know to reload them from pt_regs
403 * and not just rely on the kernel function unwinding.
404 * (Done for ptrace register writes and SA_SIGINFO handler.)
405 */
406 {
407 sw r52, tp
408 PTREGS_PTR(r52, PTREGS_OFFSET_REG(33))
409 }
410 wh64 r52 /* cache line 2 */
411 push_reg r33, r52
412 push_reg r32, r52
413 push_reg r31, r52
414 .ifc \function,handle_syscall
415 push_reg r30, r52, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(30)
416 push_reg TREG_SYSCALL_NR_NAME, r52, \
417 PTREGS_OFFSET_REG(5) - PTREGS_OFFSET_SYSCALL
418 .else
419
420 push_reg r30, r52, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(30)
421 wh64 r52 /* cache line 1 */
422 push_reg r29, r52
423 push_reg r28, r52
424 push_reg r27, r52
425 push_reg r26, r52
426 push_reg r25, r52
427 push_reg r24, r52
428 push_reg r23, r52
429 push_reg r22, r52
430 push_reg r21, r52
431 push_reg r20, r52
432 push_reg r19, r52
433 push_reg r18, r52
434 push_reg r17, r52
435 push_reg r16, r52
436 push_reg r15, r52
437 push_reg r14, r52
438 push_reg r13, r52
439 push_reg r12, r52
440 push_reg r11, r52
441 push_reg r10, r52
442 push_reg r9, r52
443 push_reg r8, r52
444 push_reg r7, r52
445 push_reg r6, r52
446
447 .endif
448
449 push_reg r5, r52
450 sw r52, r4
451
452 /* Load tp with our per-cpu offset. */
453#ifdef CONFIG_SMP
454 {
455 mfspr r20, SPR_SYSTEM_SAVE_K_0
456 moveli r21, lo16(__per_cpu_offset)
457 }
458 {
459 auli r21, r21, ha16(__per_cpu_offset)
460 mm r20, r20, zero, 0, LOG2_NR_CPU_IDS-1
461 }
462 s2a r20, r20, r21
463 lw tp, r20
464#else
465 move tp, zero
466#endif
467
468 /*
469 * If we will be returning to the kernel, we will need to
470 * reset the interrupt masks to the state they had before.
471 * Set DISABLE_IRQ in flags iff we came from PL1 with irqs disabled.
472 * We load flags in r32 here so we can jump to .Lrestore_regs
473 * directly after do_page_fault_ics() if necessary.
474 */
475 mfspr r32, SPR_EX_CONTEXT_K_1
476 {
477 andi r32, r32, SPR_EX_CONTEXT_1_1__PL_MASK /* mask off ICS */
478 PTREGS_PTR(r21, PTREGS_OFFSET_FLAGS)
479 }
480 bzt r32, 1f /* zero if from user space */
481 IRQS_DISABLED(r32) /* zero if irqs enabled */
482#if PT_FLAGS_DISABLE_IRQ != 1
483# error Value of IRQS_DISABLED used to set PT_FLAGS_DISABLE_IRQ; fix
484#endif
4851:
486 .ifnc \function,handle_syscall
487 /* Record the fact that we saved the caller-save registers above. */
488 ori r32, r32, PT_FLAGS_CALLER_SAVES
489 .endif
490 sw r21, r32
491
492#ifdef __COLLECT_LINKER_FEEDBACK__
493 /*
494 * Notify the feedback routines that we were in the
495 * appropriate fixed interrupt vector area. Note that we
496 * still have ICS set at this point, so we can't invoke any
497 * atomic operations or we will panic. The feedback
498 * routines internally preserve r0..r10 and r30 up.
499 */
500 .ifnc \function,handle_syscall
501 shli r20, r1, 5
502 .else
503 moveli r20, INT_SWINT_1 << 5
504 .endif
505 addli r20, r20, lo16(intvec_feedback)
506 auli r20, r20, ha16(intvec_feedback)
507 jalr r20
508
509 /* And now notify the feedback routines that we are here. */
510 FEEDBACK_ENTER(\function)
511#endif
512
513 /*
514 * we've captured enough state to the stack (including in
515 * particular our EX_CONTEXT state) that we can now release
516 * the interrupt critical section and replace it with our
517 * standard "interrupts disabled" mask value. This allows
518 * synchronous interrupts (and profile interrupts) to punch
519 * through from this point onwards.
520 *
521 * If bit 31 of r3 is set during a non-NMI interrupt, we know we
522 * are on the path where the hypervisor has punched through our
523 * ICS with a page fault, so we call out to do_page_fault_ics()
524 * to figure out what to do with it. If the fault was in
525 * an atomic op, we unlock the atomic lock, adjust the
526 * saved register state a little, and return "zero" in r4,
527 * falling through into the normal page-fault interrupt code.
528 * If the fault was in a kernel-space atomic operation, then
529 * do_page_fault_ics() resolves it itself, returns "one" in r4,
530 * and as a result goes directly to restoring registers and iret,
531 * without trying to adjust the interrupt masks at all.
532 * The do_page_fault_ics() API involves passing and returning
533 * a five-word struct (in registers) to avoid writing the
534 * save and restore code here.
535 */
536 .ifc \function,handle_nmi
537 IRQ_DISABLE_ALL(r20)
538 .else
539 .ifnc \function,handle_syscall
540 bgezt r3, 1f
541 {
542 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
543 jal do_page_fault_ics
544 }
545 FEEDBACK_REENTER(\function)
546 bzt r4, 1f
547 j .Lrestore_regs
5481:
549 .endif
550 IRQ_DISABLE(r20, r21)
551 .endif
552 mtspr INTERRUPT_CRITICAL_SECTION, zero
553
554 /*
555 * Prepare the first 256 stack bytes to be rapidly accessible
556 * without having to fetch the background data. We don't really
557 * know how far to write-hint, but kernel stacks generally
558 * aren't that big, and write-hinting here does take some time.
559 */
560 addi r52, sp, -64
561 {
562 wh64 r52
563 addi r52, r52, -64
564 }
565 {
566 wh64 r52
567 addi r52, r52, -64
568 }
569 {
570 wh64 r52
571 addi r52, r52, -64
572 }
573 wh64 r52
574
575#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
576 .ifnc \function,handle_nmi
577 /*
578 * We finally have enough state set up to notify the irq
579 * tracing code that irqs were disabled on entry to the handler.
580 * The TRACE_IRQS_OFF call clobbers registers r0-r29.
581 * For syscalls, we already have the register state saved away
582 * on the stack, so we don't bother to do any register saves here,
583 * and later we pop the registers back off the kernel stack.
584 * For interrupt handlers, save r0-r3 in callee-saved registers.
585 */
586 .ifnc \function,handle_syscall
587 { move r30, r0; move r31, r1 }
588 { move r32, r2; move r33, r3 }
589 .endif
590 TRACE_IRQS_OFF
591#ifdef CONFIG_CONTEXT_TRACKING
592 jal context_tracking_user_exit
593#endif
594 .ifnc \function,handle_syscall
595 { move r0, r30; move r1, r31 }
596 { move r2, r32; move r3, r33 }
597 .endif
598 .endif
599#endif
600
601 .endm
602
603 .macro check_single_stepping, kind, not_single_stepping
604 /*
605 * Check for single stepping in user-level priv
606 * kind can be "normal", "ill", or "syscall"
607 * At end, if fall-thru
608 * r29: thread_info->step_state
609 * r28: &pt_regs->pc
610 * r27: pt_regs->pc
611 * r26: thread_info->step_state->buffer
612 */
613
614 /* Check for single stepping */
615 GET_THREAD_INFO(r29)
616 {
617 /* Get pointer to field holding step state */
618 addi r29, r29, THREAD_INFO_STEP_STATE_OFFSET
619
620 /* Get pointer to EX1 in register state */
621 PTREGS_PTR(r27, PTREGS_OFFSET_EX1)
622 }
623 {
624 /* Get pointer to field holding PC */
625 PTREGS_PTR(r28, PTREGS_OFFSET_PC)
626
627 /* Load the pointer to the step state */
628 lw r29, r29
629 }
630 /* Load EX1 */
631 lw r27, r27
632 {
633 /* Points to flags */
634 addi r23, r29, SINGLESTEP_STATE_FLAGS_OFFSET
635
636 /* No single stepping if there is no step state structure */
637 bzt r29, \not_single_stepping
638 }
639 {
640 /* mask off ICS and any other high bits */
641 andi r27, r27, SPR_EX_CONTEXT_1_1__PL_MASK
642
643 /* Load pointer to single step instruction buffer */
644 lw r26, r29
645 }
646 /* Check priv state */
647 bnz r27, \not_single_stepping
648
649 /* Get flags */
650 lw r22, r23
651 {
652 /* Branch if single-step mode not enabled */
653 bbnst r22, \not_single_stepping
654
655 /* Clear enabled flag */
656 andi r22, r22, ~SINGLESTEP_STATE_MASK_IS_ENABLED
657 }
658 .ifc \kind,normal
659 {
660 /* Load PC */
661 lw r27, r28
662
663 /* Point to the entry containing the original PC */
664 addi r24, r29, SINGLESTEP_STATE_ORIG_PC_OFFSET
665 }
666 {
667 /* Disable single stepping flag */
668 sw r23, r22
669 }
670 {
671 /* Get the original pc */
672 lw r24, r24
673
674 /* See if the PC is at the start of the single step buffer */
675 seq r25, r26, r27
676 }
677 /*
678 * NOTE: it is really expected that the PC be in the single step buffer
679 * at this point
680 */
681 bzt r25, \not_single_stepping
682
683 /* Restore the original PC */
684 sw r28, r24
685 .else
686 .ifc \kind,syscall
687 {
688 /* Load PC */
689 lw r27, r28
690
691 /* Point to the entry containing the next PC */
692 addi r24, r29, SINGLESTEP_STATE_NEXT_PC_OFFSET
693 }
694 {
695 /* Increment the stopped PC by the bundle size */
696 addi r26, r26, 8
697
698 /* Disable single stepping flag */
699 sw r23, r22
700 }
701 {
702 /* Get the next pc */
703 lw r24, r24
704
705 /*
706 * See if the PC is one bundle past the start of the
707 * single step buffer
708 */
709 seq r25, r26, r27
710 }
711 {
712 /*
713 * NOTE: it is really expected that the PC be in the
714 * single step buffer at this point
715 */
716 bzt r25, \not_single_stepping
717 }
718 /* Set to the next PC */
719 sw r28, r24
720 .else
721 {
722 /* Point to 3rd bundle in buffer */
723 addi r25, r26, 16
724
725 /* Load PC */
726 lw r27, r28
727 }
728 {
729 /* Disable single stepping flag */
730 sw r23, r22
731
732 /* See if the PC is in the single step buffer */
733 slte_u r24, r26, r27
734 }
735 {
736 slte_u r25, r27, r25
737
738 /*
739 * NOTE: it is really expected that the PC be in the
740 * single step buffer at this point
741 */
742 bzt r24, \not_single_stepping
743 }
744 bzt r25, \not_single_stepping
745 .endif
746 .endif
747 .endm
748
749 /*
750 * Redispatch a downcall.
751 */
752 .macro dc_dispatch vecnum, vecname
753 .org (\vecnum << 8)
754intvec_\vecname:
755 j _hv_downcall_dispatch
756 ENDPROC(intvec_\vecname)
757 .endm
758
759 /*
760 * Common code for most interrupts. The C function we're eventually
761 * going to is in r0, and the faultnum is in r1; the original
762 * values for those registers are on the stack.
763 */
764 .pushsection .text.handle_interrupt,"ax"
765handle_interrupt:
766 finish_interrupt_save handle_interrupt
767
768 /*
769 * Check for if we are single stepping in user level. If so, then
770 * we need to restore the PC.
771 */
772
773 check_single_stepping normal, .Ldispatch_interrupt
774.Ldispatch_interrupt:
775
776 /* Jump to the C routine; it should enable irqs as soon as possible. */
777 {
778 jalr r0
779 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
780 }
781 FEEDBACK_REENTER(handle_interrupt)
782 {
783 movei r30, 0 /* not an NMI */
784 j interrupt_return
785 }
786 STD_ENDPROC(handle_interrupt)
787
788/*
789 * This routine takes a boolean in r30 indicating if this is an NMI.
790 * If so, we also expect a boolean in r31 indicating whether to
791 * re-enable the oprofile interrupts.
792 *
793 * Note that .Lresume_userspace is jumped to directly in several
794 * places, and we need to make sure r30 is set correctly in those
795 * callers as well.
796 */
797STD_ENTRY(interrupt_return)
798 /* If we're resuming to kernel space, don't check thread flags. */
799 {
800 bnz r30, .Lrestore_all /* NMIs don't special-case user-space */
801 PTREGS_PTR(r29, PTREGS_OFFSET_EX1)
802 }
803 lw r29, r29
804 andi r29, r29, SPR_EX_CONTEXT_1_1__PL_MASK /* mask off ICS */
805 bzt r29, .Lresume_userspace
806
807#ifdef CONFIG_PREEMPT
808 /* Returning to kernel space. Check if we need preemption. */
809 GET_THREAD_INFO(r29)
810 addli r28, r29, THREAD_INFO_FLAGS_OFFSET
811 {
812 lw r28, r28
813 addli r29, r29, THREAD_INFO_PREEMPT_COUNT_OFFSET
814 }
815 {
816 andi r28, r28, _TIF_NEED_RESCHED
817 lw r29, r29
818 }
819 bzt r28, 1f
820 bnz r29, 1f
821 /* Disable interrupts explicitly for preemption. */
822 IRQ_DISABLE(r20,r21)
823 TRACE_IRQS_OFF
824 jal preempt_schedule_irq
825 FEEDBACK_REENTER(interrupt_return)
8261:
827#endif
828
829 /* If we're resuming to _cpu_idle_nap, bump PC forward by 8. */
830 {
831 PTREGS_PTR(r29, PTREGS_OFFSET_PC)
832 moveli r27, lo16(_cpu_idle_nap)
833 }
834 {
835 lw r28, r29
836 auli r27, r27, ha16(_cpu_idle_nap)
837 }
838 {
839 seq r27, r27, r28
840 }
841 {
842 bbns r27, .Lrestore_all
843 addi r28, r28, 8
844 }
845 sw r29, r28
846 j .Lrestore_all
847
848.Lresume_userspace:
849 FEEDBACK_REENTER(interrupt_return)
850
851 /*
852 * Disable interrupts so as to make sure we don't
853 * miss an interrupt that sets any of the thread flags (like
854 * need_resched or sigpending) between sampling and the iret.
855 * Routines like schedule() or do_signal() may re-enable
856 * interrupts before returning.
857 */
858 IRQ_DISABLE(r20, r21)
859 TRACE_IRQS_OFF /* Note: clobbers registers r0-r29 */
860
861 /*
862 * See if there are any work items (including single-shot items)
863 * to do. If so, save the callee-save registers to pt_regs
864 * and then dispatch to C code.
865 */
866 GET_THREAD_INFO(r21)
867 {
868 addi r22, r21, THREAD_INFO_FLAGS_OFFSET
869 moveli r20, lo16(_TIF_ALLWORK_MASK)
870 }
871 {
872 lw r22, r22
873 auli r20, r20, ha16(_TIF_ALLWORK_MASK)
874 }
875 and r1, r22, r20
876 {
877 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
878 bzt r1, .Lrestore_all
879 }
880 push_extra_callee_saves r0
881 jal prepare_exit_to_usermode
882
883 /*
884 * In the NMI case we
885 * omit the call to single_process_check_nohz, which normally checks
886 * to see if we should start or stop the scheduler tick, because
887 * we can't call arbitrary Linux code from an NMI context.
888 * We always call the homecache TLB deferral code to re-trigger
889 * the deferral mechanism.
890 *
891 * The other chunk of responsibility this code has is to reset the
892 * interrupt masks appropriately to reset irqs and NMIs. We have
893 * to call TRACE_IRQS_OFF and TRACE_IRQS_ON to support all the
894 * lockdep-type stuff, but we can't set ICS until afterwards, since
895 * ICS can only be used in very tight chunks of code to avoid
896 * tripping over various assertions that it is off.
897 *
898 * (There is what looks like a window of vulnerability here since
899 * we might take a profile interrupt between the two SPR writes
900 * that set the mask, but since we write the low SPR word first,
901 * and our interrupt entry code checks the low SPR word, any
902 * profile interrupt will actually disable interrupts in both SPRs
903 * before returning, which is OK.)
904 */
905.Lrestore_all:
906 PTREGS_PTR(r0, PTREGS_OFFSET_EX1)
907 {
908 lw r0, r0
909 PTREGS_PTR(r32, PTREGS_OFFSET_FLAGS)
910 }
911 {
912 andi r0, r0, SPR_EX_CONTEXT_1_1__PL_MASK
913 lw r32, r32
914 }
915 bnz r0, 1f
916 j 2f
917#if PT_FLAGS_DISABLE_IRQ != 1
918# error Assuming PT_FLAGS_DISABLE_IRQ == 1 so we can use bbnst below
919#endif
9201: bbnst r32, 2f
921 IRQ_DISABLE(r20,r21)
922 TRACE_IRQS_OFF
923 movei r0, 1
924 mtspr INTERRUPT_CRITICAL_SECTION, r0
925 bzt r30, .Lrestore_regs
926 j 3f
9272: TRACE_IRQS_ON
928 movei r0, 1
929 mtspr INTERRUPT_CRITICAL_SECTION, r0
930 IRQ_ENABLE(r20, r21)
931 bzt r30, .Lrestore_regs
9323:
933
934 /* We are relying on INT_PERF_COUNT at 33, and AUX_PERF_COUNT at 48 */
935 {
936 moveli r0, lo16(1 << (INT_PERF_COUNT - 32))
937 bz r31, .Lrestore_regs
938 }
939 auli r0, r0, ha16(1 << (INT_AUX_PERF_COUNT - 32))
940 mtspr SPR_INTERRUPT_MASK_RESET_K_1, r0
941
942 /*
943 * We now commit to returning from this interrupt, since we will be
944 * doing things like setting EX_CONTEXT SPRs and unwinding the stack
945 * frame. No calls should be made to any other code after this point.
946 * This code should only be entered with ICS set.
947 * r32 must still be set to ptregs.flags.
948 * We launch loads to each cache line separately first, so we can
949 * get some parallelism out of the memory subsystem.
950 * We start zeroing caller-saved registers throughout, since
951 * that will save some cycles if this turns out to be a syscall.
952 */
953.Lrestore_regs:
954 FEEDBACK_REENTER(interrupt_return) /* called from elsewhere */
955
956 /*
957 * Rotate so we have one high bit and one low bit to test.
958 * - low bit says whether to restore all the callee-saved registers,
959 * or just r30-r33, and r52 up.
960 * - high bit (i.e. sign bit) says whether to restore all the
961 * caller-saved registers, or just r0.
962 */
963#if PT_FLAGS_CALLER_SAVES != 2 || PT_FLAGS_RESTORE_REGS != 4
964# error Rotate trick does not work :-)
965#endif
966 {
967 rli r20, r32, 30
968 PTREGS_PTR(sp, PTREGS_OFFSET_REG(0))
969 }
970
971 /*
972 * Load cache lines 0, 2, and 3 in that order, then use
973 * the last loaded value, which makes it likely that the other
974 * cache lines have also loaded, at which point we should be
975 * able to safely read all the remaining words on those cache
976 * lines without waiting for the memory subsystem.
977 */
978 pop_reg_zero r0, r28, sp, PTREGS_OFFSET_REG(30) - PTREGS_OFFSET_REG(0)
979 pop_reg_zero r30, r2, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_REG(30)
980 pop_reg_zero r21, r3, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_PC
981 pop_reg_zero lr, r4, sp, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_EX1
982 {
983 mtspr SPR_EX_CONTEXT_K_0, r21
984 move r5, zero
985 }
986 {
987 mtspr SPR_EX_CONTEXT_K_1, lr
988 andi lr, lr, SPR_EX_CONTEXT_1_1__PL_MASK /* mask off ICS */
989 }
990
991 /* Restore callee-saveds that we actually use. */
992 pop_reg_zero r52, r6, sp, PTREGS_OFFSET_REG(31) - PTREGS_OFFSET_REG(52)
993 pop_reg_zero r31, r7
994 pop_reg_zero r32, r8
995 pop_reg_zero r33, r9, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(33)
996
997 /*
998 * If we modified other callee-saveds, restore them now.
999 * This is rare, but could be via ptrace or signal handler.
1000 */
1001 {
1002 move r10, zero
1003 bbs r20, .Lrestore_callees
1004 }
1005.Lcontinue_restore_regs:
1006
1007 /* Check if we're returning from a syscall. */
1008 {
1009 move r11, zero
1010 blzt r20, 1f /* no, so go restore callee-save registers */
1011 }
1012
1013 /*
1014 * Check if we're returning to userspace.
1015 * Note that if we're not, we don't worry about zeroing everything.
1016 */
1017 {
1018 addli sp, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(29)
1019 bnz lr, .Lkernel_return
1020 }
1021
1022 /*
1023 * On return from syscall, we've restored r0 from pt_regs, but we
1024 * clear the remainder of the caller-saved registers. We could
1025 * restore the syscall arguments, but there's not much point,
1026 * and it ensures user programs aren't trying to use the
1027 * caller-saves if we clear them, as well as avoiding leaking
1028 * kernel pointers into userspace.
1029 */
1030 pop_reg_zero lr, r12, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
1031 pop_reg_zero tp, r13, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
1032 {
1033 lw sp, sp
1034 move r14, zero
1035 move r15, zero
1036 }
1037 { move r16, zero; move r17, zero }
1038 { move r18, zero; move r19, zero }
1039 { move r20, zero; move r21, zero }
1040 { move r22, zero; move r23, zero }
1041 { move r24, zero; move r25, zero }
1042 { move r26, zero; move r27, zero }
1043
1044 /* Set r1 to errno if we are returning an error, otherwise zero. */
1045 {
1046 moveli r29, 4096
1047 sub r1, zero, r0
1048 }
1049 slt_u r29, r1, r29
1050 {
1051 mnz r1, r29, r1
1052 move r29, zero
1053 }
1054 iret
1055
1056 /*
1057 * Not a syscall, so restore caller-saved registers.
1058 * First kick off a load for cache line 1, which we're touching
1059 * for the first time here.
1060 */
1061 .align 64
10621: pop_reg r29, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(29)
1063 pop_reg r1
1064 pop_reg r2
1065 pop_reg r3
1066 pop_reg r4
1067 pop_reg r5
1068 pop_reg r6
1069 pop_reg r7
1070 pop_reg r8
1071 pop_reg r9
1072 pop_reg r10
1073 pop_reg r11
1074 pop_reg r12
1075 pop_reg r13
1076 pop_reg r14
1077 pop_reg r15
1078 pop_reg r16
1079 pop_reg r17
1080 pop_reg r18
1081 pop_reg r19
1082 pop_reg r20
1083 pop_reg r21
1084 pop_reg r22
1085 pop_reg r23
1086 pop_reg r24
1087 pop_reg r25
1088 pop_reg r26
1089 pop_reg r27
1090 pop_reg r28, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(28)
1091 /* r29 already restored above */
1092 bnz lr, .Lkernel_return
1093 pop_reg lr, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
1094 pop_reg tp, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
1095 lw sp, sp
1096 iret
1097
1098 /*
1099 * We can't restore tp when in kernel mode, since a thread might
1100 * have migrated from another cpu and brought a stale tp value.
1101 */
1102.Lkernel_return:
1103 pop_reg lr, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR
1104 lw sp, sp
1105 iret
1106
1107 /* Restore callee-saved registers from r34 to r51. */
1108.Lrestore_callees:
1109 addli sp, sp, PTREGS_OFFSET_REG(34) - PTREGS_OFFSET_REG(29)
1110 pop_reg r34
1111 pop_reg r35
1112 pop_reg r36
1113 pop_reg r37
1114 pop_reg r38
1115 pop_reg r39
1116 pop_reg r40
1117 pop_reg r41
1118 pop_reg r42
1119 pop_reg r43
1120 pop_reg r44
1121 pop_reg r45
1122 pop_reg r46
1123 pop_reg r47
1124 pop_reg r48
1125 pop_reg r49
1126 pop_reg r50
1127 pop_reg r51, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(51)
1128 j .Lcontinue_restore_regs
1129 STD_ENDPROC(interrupt_return)
1130
1131 /*
1132 * Some interrupts don't check for single stepping
1133 */
1134 .pushsection .text.handle_interrupt_no_single_step,"ax"
1135handle_interrupt_no_single_step:
1136 finish_interrupt_save handle_interrupt_no_single_step
1137 {
1138 jalr r0
1139 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
1140 }
1141 FEEDBACK_REENTER(handle_interrupt_no_single_step)
1142 {
1143 movei r30, 0 /* not an NMI */
1144 j interrupt_return
1145 }
1146 STD_ENDPROC(handle_interrupt_no_single_step)
1147
1148 /*
1149 * "NMI" interrupts mask ALL interrupts before calling the
1150 * handler, and don't check thread flags, etc., on the way
1151 * back out. In general, the only things we do here for NMIs
1152 * are the register save/restore, fixing the PC if we were
1153 * doing single step, and the dataplane kernel-TLB management.
1154 * We don't (for example) deal with start/stop of the sched tick.
1155 */
1156 .pushsection .text.handle_nmi,"ax"
1157handle_nmi:
1158 finish_interrupt_save handle_nmi
1159 check_single_stepping normal, .Ldispatch_nmi
1160.Ldispatch_nmi:
1161 {
1162 jalr r0
1163 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
1164 }
1165 FEEDBACK_REENTER(handle_nmi)
1166 {
1167 movei r30, 1
1168 seq r31, r0, zero
1169 }
1170 j interrupt_return
1171 STD_ENDPROC(handle_nmi)
1172
1173 /*
1174 * Parallel code for syscalls to handle_interrupt.
1175 */
1176 .pushsection .text.handle_syscall,"ax"
1177handle_syscall:
1178 finish_interrupt_save handle_syscall
1179
1180 /*
1181 * Check for if we are single stepping in user level. If so, then
1182 * we need to restore the PC.
1183 */
1184 check_single_stepping syscall, .Ldispatch_syscall
1185.Ldispatch_syscall:
1186
1187 /* Enable irqs. */
1188 TRACE_IRQS_ON
1189 IRQ_ENABLE(r20, r21)
1190
1191 /* Bump the counter for syscalls made on this tile. */
1192 moveli r20, lo16(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
1193 auli r20, r20, ha16(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
1194 add r20, r20, tp
1195 lw r21, r20
1196 addi r21, r21, 1
1197 {
1198 sw r20, r21
1199 GET_THREAD_INFO(r31)
1200 }
1201
1202 /* Trace syscalls, if requested. */
1203 addi r31, r31, THREAD_INFO_FLAGS_OFFSET
1204 lw r30, r31
1205 andi r30, r30, _TIF_SYSCALL_TRACE
1206 bzt r30, .Lrestore_syscall_regs
1207 {
1208 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
1209 jal do_syscall_trace_enter
1210 }
1211 FEEDBACK_REENTER(handle_syscall)
1212 blz r0, .Lsyscall_sigreturn_skip
1213
1214 /*
1215 * We always reload our registers from the stack at this
1216 * point. They might be valid, if we didn't build with
1217 * TRACE_IRQFLAGS, and this isn't a dataplane tile, and we're not
1218 * doing syscall tracing, but there are enough cases now that it
1219 * seems simplest just to do the reload unconditionally.
1220 */
1221.Lrestore_syscall_regs:
1222 PTREGS_PTR(r11, PTREGS_OFFSET_REG(0))
1223 pop_reg r0, r11
1224 pop_reg r1, r11
1225 pop_reg r2, r11
1226 pop_reg r3, r11
1227 pop_reg r4, r11
1228 pop_reg r5, r11, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(5)
1229 pop_reg TREG_SYSCALL_NR_NAME, r11
1230
1231 /* Ensure that the syscall number is within the legal range. */
1232 moveli r21, __NR_syscalls
1233 {
1234 slt_u r21, TREG_SYSCALL_NR_NAME, r21
1235 moveli r20, lo16(sys_call_table)
1236 }
1237 {
1238 bbns r21, .Linvalid_syscall
1239 auli r20, r20, ha16(sys_call_table)
1240 }
1241 s2a r20, TREG_SYSCALL_NR_NAME, r20
1242 lw r20, r20
1243
1244 /* Jump to syscall handler. */
1245 jalr r20
1246.Lhandle_syscall_link: /* value of "lr" after "jalr r20" above */
1247
1248 /*
1249 * Write our r0 onto the stack so it gets restored instead
1250 * of whatever the user had there before.
1251 */
1252 PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
1253 sw r29, r0
1254
1255.Lsyscall_sigreturn_skip:
1256 FEEDBACK_REENTER(handle_syscall)
1257
1258 /* Do syscall trace again, if requested. */
1259 lw r30, r31
1260 andi r30, r30, _TIF_SYSCALL_TRACE
1261 bzt r30, 1f
1262 {
1263 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
1264 jal do_syscall_trace_exit
1265 }
1266 FEEDBACK_REENTER(handle_syscall)
12671: {
1268 movei r30, 0 /* not an NMI */
1269 j .Lresume_userspace /* jump into middle of interrupt_return */
1270 }
1271
1272.Linvalid_syscall:
1273 /* Report an invalid syscall back to the user program */
1274 {
1275 PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
1276 movei r28, -ENOSYS
1277 }
1278 sw r29, r28
1279 {
1280 movei r30, 0 /* not an NMI */
1281 j .Lresume_userspace /* jump into middle of interrupt_return */
1282 }
1283 STD_ENDPROC(handle_syscall)
1284
1285 /* Return the address for oprofile to suppress in backtraces. */
1286STD_ENTRY_SECTION(handle_syscall_link_address, .text.handle_syscall)
1287 lnk r0
1288 {
1289 addli r0, r0, .Lhandle_syscall_link - .
1290 jrp lr
1291 }
1292 STD_ENDPROC(handle_syscall_link_address)
1293
1294STD_ENTRY(ret_from_fork)
1295 jal sim_notify_fork
1296 jal schedule_tail
1297 FEEDBACK_REENTER(ret_from_fork)
1298 {
1299 movei r30, 0 /* not an NMI */
1300 j .Lresume_userspace /* jump into middle of interrupt_return */
1301 }
1302 STD_ENDPROC(ret_from_fork)
1303
1304STD_ENTRY(ret_from_kernel_thread)
1305 jal sim_notify_fork
1306 jal schedule_tail
1307 FEEDBACK_REENTER(ret_from_fork)
1308 {
1309 move r0, r31
1310 jalr r30
1311 }
1312 FEEDBACK_REENTER(ret_from_kernel_thread)
1313 {
1314 movei r30, 0 /* not an NMI */
1315 j interrupt_return
1316 }
1317 STD_ENDPROC(ret_from_kernel_thread)
1318
1319 /*
1320 * Code for ill interrupt.
1321 */
1322 .pushsection .text.handle_ill,"ax"
1323handle_ill:
1324 finish_interrupt_save handle_ill
1325
1326 /*
1327 * Check for if we are single stepping in user level. If so, then
1328 * we need to restore the PC.
1329 */
1330 check_single_stepping ill, .Ldispatch_normal_ill
1331
1332 {
1333 /* See if the PC is the 1st bundle in the buffer */
1334 seq r25, r27, r26
1335
1336 /* Point to the 2nd bundle in the buffer */
1337 addi r26, r26, 8
1338 }
1339 {
1340 /* Point to the original pc */
1341 addi r24, r29, SINGLESTEP_STATE_ORIG_PC_OFFSET
1342
1343 /* Branch if the PC is the 1st bundle in the buffer */
1344 bnz r25, 3f
1345 }
1346 {
1347 /* See if the PC is the 2nd bundle of the buffer */
1348 seq r25, r27, r26
1349
1350 /* Set PC to next instruction */
1351 addi r24, r29, SINGLESTEP_STATE_NEXT_PC_OFFSET
1352 }
1353 {
1354 /* Point to flags */
1355 addi r25, r29, SINGLESTEP_STATE_FLAGS_OFFSET
1356
1357 /* Branch if PC is in the second bundle */
1358 bz r25, 2f
1359 }
1360 /* Load flags */
1361 lw r25, r25
1362 {
1363 /*
1364 * Get the offset for the register to restore
1365 * Note: the lower bound is 2, so we have implicit scaling by 4.
1366 * No multiplication of the register number by the size of a register
1367 * is needed.
1368 */
1369 mm r27, r25, zero, SINGLESTEP_STATE_TARGET_LB, \
1370 SINGLESTEP_STATE_TARGET_UB
1371
1372 /* Mask Rewrite_LR */
1373 andi r25, r25, SINGLESTEP_STATE_MASK_UPDATE
1374 }
1375 {
1376 addi r29, r29, SINGLESTEP_STATE_UPDATE_VALUE_OFFSET
1377
1378 /* Don't rewrite temp register */
1379 bz r25, 3f
1380 }
1381 {
1382 /* Get the temp value */
1383 lw r29, r29
1384
1385 /* Point to where the register is stored */
1386 add r27, r27, sp
1387 }
1388
1389 /* Add in the C ABI save area size to the register offset */
1390 addi r27, r27, C_ABI_SAVE_AREA_SIZE
1391
1392 /* Restore the user's register with the temp value */
1393 sw r27, r29
1394 j 3f
1395
13962:
1397 /* Must be in the third bundle */
1398 addi r24, r29, SINGLESTEP_STATE_BRANCH_NEXT_PC_OFFSET
1399
14003:
1401 /* set PC and continue */
1402 lw r26, r24
1403 {
1404 sw r28, r26
1405 GET_THREAD_INFO(r0)
1406 }
1407
1408 /*
1409 * Clear TIF_SINGLESTEP to prevent recursion if we execute an ill.
1410 * The normal non-arch flow redundantly clears TIF_SINGLESTEP, but we
1411 * need to clear it here and can't really impose on all other arches.
1412 * So what's another write between friends?
1413 */
1414
1415 addi r1, r0, THREAD_INFO_FLAGS_OFFSET
1416 {
1417 lw r2, r1
1418 addi r0, r0, THREAD_INFO_TASK_OFFSET /* currently a no-op */
1419 }
1420 andi r2, r2, ~_TIF_SINGLESTEP
1421 sw r1, r2
1422
1423 /* Issue a sigtrap */
1424 {
1425 lw r0, r0 /* indirect thru thread_info to get task_info*/
1426 addi r1, sp, C_ABI_SAVE_AREA_SIZE /* put ptregs pointer into r1 */
1427 }
1428
1429 jal send_sigtrap /* issue a SIGTRAP */
1430 FEEDBACK_REENTER(handle_ill)
1431 {
1432 movei r30, 0 /* not an NMI */
1433 j .Lresume_userspace /* jump into middle of interrupt_return */
1434 }
1435
1436.Ldispatch_normal_ill:
1437 {
1438 jalr r0
1439 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
1440 }
1441 FEEDBACK_REENTER(handle_ill)
1442 {
1443 movei r30, 0 /* not an NMI */
1444 j interrupt_return
1445 }
1446 STD_ENDPROC(handle_ill)
1447
1448/* Various stub interrupt handlers and syscall handlers */
1449
1450STD_ENTRY_LOCAL(_kernel_double_fault)
1451 mfspr r1, SPR_EX_CONTEXT_K_0
1452 move r2, lr
1453 move r3, sp
1454 move r4, r52
1455 addi sp, sp, -C_ABI_SAVE_AREA_SIZE
1456 j kernel_double_fault
1457 STD_ENDPROC(_kernel_double_fault)
1458
1459STD_ENTRY_LOCAL(bad_intr)
1460 mfspr r2, SPR_EX_CONTEXT_K_0
1461 panic "Unhandled interrupt %#x: PC %#lx"
1462 STD_ENDPROC(bad_intr)
1463
1464/*
1465 * Special-case sigreturn to not write r0 to the stack on return.
1466 * This is technically more efficient, but it also avoids difficulties
1467 * in the 64-bit OS when handling 32-bit compat code, since we must not
1468 * sign-extend r0 for the sigreturn return-value case.
1469 */
1470#define PTREGS_SYSCALL_SIGRETURN(x, reg) \
1471 STD_ENTRY(_##x); \
1472 addli lr, lr, .Lsyscall_sigreturn_skip - .Lhandle_syscall_link; \
1473 { \
1474 PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \
1475 j x \
1476 }; \
1477 STD_ENDPROC(_##x)
1478
1479PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0)
1480
1481/* Save additional callee-saves to pt_regs and jump to standard function. */
1482STD_ENTRY(_sys_clone)
1483 push_extra_callee_saves r4
1484 j sys_clone
1485 STD_ENDPROC(_sys_clone)
1486
1487/*
1488 * This entrypoint is taken for the cmpxchg and atomic_update fast
1489 * swints. We may wish to generalize it to other fast swints at some
1490 * point, but for now there are just two very similar ones, which
1491 * makes it faster.
1492 *
1493 * The fast swint code is designed to have a small footprint. It does
1494 * not save or restore any GPRs, counting on the caller-save registers
1495 * to be available to it on entry. It does not modify any callee-save
1496 * registers (including "lr"). It does not check what PL it is being
1497 * called at, so you'd better not call it other than at PL0.
1498 * The <atomic.h> wrapper assumes it only clobbers r20-r29, so if
1499 * it ever is necessary to use more registers, be aware.
1500 *
1501 * It does not use the stack, but since it might be re-interrupted by
1502 * a page fault which would assume the stack was valid, it does
1503 * save/restore the stack pointer and zero it out to make sure it gets reset.
1504 * Since we always keep interrupts disabled, the hypervisor won't
1505 * clobber our EX_CONTEXT_K_x registers, so we don't save/restore them
1506 * (other than to advance the PC on return).
1507 *
1508 * We have to manually validate the user vs kernel address range
1509 * (since at PL1 we can read/write both), and for performance reasons
1510 * we don't allow cmpxchg on the fc000000 memory region, since we only
1511 * validate that the user address is below PAGE_OFFSET.
1512 *
1513 * We place it in the __HEAD section to ensure it is relatively
1514 * near to the intvec_SWINT_1 code (reachable by a conditional branch).
1515 *
1516 * Our use of ATOMIC_LOCK_REG here must match do_page_fault_ics().
1517 *
1518 * As we do in lib/atomic_asm_32.S, we bypass a store if the value we
1519 * would store is the same as the value we just loaded.
1520 */
1521 __HEAD
1522 .align 64
1523 /* Align much later jump on the start of a cache line. */
1524 nop
1525#if PAGE_SIZE >= 0x10000
1526 nop
1527#endif
1528ENTRY(sys_cmpxchg)
1529
1530 /*
1531 * Save "sp" and set it zero for any possible page fault.
1532 *
1533 * HACK: We want to both zero sp and check r0's alignment,
1534 * so we do both at once. If "sp" becomes nonzero we
1535 * know r0 is unaligned and branch to the error handler that
1536 * restores sp, so this is OK.
1537 *
1538 * ICS is disabled right now so having a garbage but nonzero
1539 * sp is OK, since we won't execute any faulting instructions
1540 * when it is nonzero.
1541 */
1542 {
1543 move r27, sp
1544 andi sp, r0, 3
1545 }
1546
1547 /*
1548 * Get the lock address in ATOMIC_LOCK_REG, and also validate that the
1549 * address is less than PAGE_OFFSET, since that won't trap at PL1.
1550 * We only use bits less than PAGE_SHIFT to avoid having to worry
1551 * about aliasing among multiple mappings of the same physical page,
1552 * and we ignore the low 3 bits so we have one lock that covers
1553 * both a cmpxchg64() and a cmpxchg() on either its low or high word.
1554 * NOTE: this must match __atomic_hashed_lock() in lib/atomic_32.c.
1555 */
1556
1557#if (PAGE_OFFSET & 0xffff) != 0
1558# error Code here assumes PAGE_OFFSET can be loaded with just hi16()
1559#endif
1560
1561 {
1562 /* Check for unaligned input. */
1563 bnz sp, .Lcmpxchg_badaddr
1564 auli r23, zero, hi16(PAGE_OFFSET) /* hugepage-aligned */
1565 }
1566 {
1567 /*
1568 * Slide bits into position for 'mm'. We want to ignore
1569 * the low 3 bits of r0, and consider only the next
1570 * ATOMIC_HASH_SHIFT bits.
1571 * Because of C pointer arithmetic, we want to compute this:
1572 *
1573 * ((char*)atomic_locks +
1574 * (((r0 >> 3) & ((1 << ATOMIC_HASH_SHIFT) - 1)) << 2))
1575 *
1576 * Instead of two shifts we just ">> 1", and use 'mm'
1577 * to ignore the low and high bits we don't want.
1578 */
1579 shri r25, r0, 1
1580
1581 slt_u r23, r0, r23
1582
1583 /*
1584 * Ensure that the TLB is loaded before we take out the lock.
1585 * This will start fetching the value all the way into our L1
1586 * as well (and if it gets modified before we grab the lock,
1587 * it will be invalidated from our cache before we reload it).
1588 */
1589 lw r26, r0
1590 }
1591 {
1592 auli r21, zero, ha16(atomic_locks)
1593
1594 bbns r23, .Lcmpxchg_badaddr
1595 }
1596#if PAGE_SIZE < 0x10000
1597 /* atomic_locks is page-aligned so for big pages we don't need this. */
1598 addli r21, r21, lo16(atomic_locks)
1599#endif
1600 {
1601 /*
1602 * Insert the hash bits into the page-aligned pointer.
1603 * ATOMIC_HASH_SHIFT is so big that we don't actually hash
1604 * the unmasked address bits, as that may cause unnecessary
1605 * collisions.
1606 */
1607 mm ATOMIC_LOCK_REG_NAME, r25, r21, 2, (ATOMIC_HASH_SHIFT + 2) - 1
1608
1609 seqi r23, TREG_SYSCALL_NR_NAME, __NR_FAST_cmpxchg64
1610 }
1611 {
1612 /* Branch away at this point if we're doing a 64-bit cmpxchg. */
1613 bbs r23, .Lcmpxchg64
1614 andi r23, r0, 7 /* Precompute alignment for cmpxchg64. */
1615 }
1616 {
1617 /*
1618 * We very carefully align the code that actually runs with
1619 * the lock held (twelve bundles) so that we know it is all in
1620 * the icache when we start. This instruction (the jump) is
1621 * at the start of the first cache line, address zero mod 64;
1622 * we jump to the very end of the second cache line to get that
1623 * line loaded in the icache, then fall through to issue the tns
1624 * in the third cache line, at which point it's all cached.
1625 * Note that is for performance, not correctness.
1626 */
1627 j .Lcmpxchg32_tns
1628 }
1629
1630/* Symbol for do_page_fault_ics() to use to compare against the PC. */
1631.global __sys_cmpxchg_grab_lock
1632__sys_cmpxchg_grab_lock:
1633
1634 /*
1635 * Perform the actual cmpxchg or atomic_update.
1636 */
1637.Ldo_cmpxchg32:
1638 {
1639 lw r21, r0
1640 seqi r23, TREG_SYSCALL_NR_NAME, __NR_FAST_atomic_update
1641 move r24, r2
1642 }
1643 {
1644 seq r22, r21, r1 /* See if cmpxchg matches. */
1645 and r25, r21, r1 /* If atomic_update, compute (*mem & mask) */
1646 }
1647 {
1648 or r22, r22, r23 /* Skip compare branch for atomic_update. */
1649 add r25, r25, r2 /* Compute (*mem & mask) + addend. */
1650 }
1651 {
1652 mvnz r24, r23, r25 /* Use atomic_update value if appropriate. */
1653 bbns r22, .Lcmpxchg32_nostore
1654 }
1655 seq r22, r24, r21 /* Are we storing the value we loaded? */
1656 bbs r22, .Lcmpxchg32_nostore
1657 sw r0, r24
1658
1659 /* The following instruction is the start of the second cache line. */
1660 /* Do slow mtspr here so the following "mf" waits less. */
1661 {
1662 move sp, r27
1663 mtspr SPR_EX_CONTEXT_K_0, r28
1664 }
1665 mf
1666
1667 {
1668 move r0, r21
1669 sw ATOMIC_LOCK_REG_NAME, zero
1670 }
1671 iret
1672
1673 /* Duplicated code here in the case where we don't overlap "mf" */
1674.Lcmpxchg32_nostore:
1675 {
1676 move r0, r21
1677 sw ATOMIC_LOCK_REG_NAME, zero
1678 }
1679 {
1680 move sp, r27
1681 mtspr SPR_EX_CONTEXT_K_0, r28
1682 }
1683 iret
1684
1685 /*
1686 * The locking code is the same for 32-bit cmpxchg/atomic_update,
1687 * and for 64-bit cmpxchg. We provide it as a macro and put
1688 * it into both versions. We can't share the code literally
1689 * since it depends on having the right branch-back address.
1690 */
1691 .macro cmpxchg_lock, bitwidth
1692
1693 /* Lock; if we succeed, jump back up to the read-modify-write. */
1694#ifdef CONFIG_SMP
1695 tns r21, ATOMIC_LOCK_REG_NAME
1696#else
1697 /*
1698 * Non-SMP preserves all the lock infrastructure, to keep the
1699 * code simpler for the interesting (SMP) case. However, we do
1700 * one small optimization here and in atomic_asm.S, which is
1701 * to fake out acquiring the actual lock in the atomic_lock table.
1702 */
1703 movei r21, 0
1704#endif
1705
1706 /* Issue the slow SPR here while the tns result is in flight. */
1707 mfspr r28, SPR_EX_CONTEXT_K_0
1708
1709 {
1710 addi r28, r28, 8 /* return to the instruction after the swint1 */
1711 bzt r21, .Ldo_cmpxchg\bitwidth
1712 }
1713 /*
1714 * The preceding instruction is the last thing that must be
1715 * hot in the icache before we do the "tns" above.
1716 */
1717
1718#ifdef CONFIG_SMP
1719 /*
1720 * We failed to acquire the tns lock on our first try. Now use
1721 * bounded exponential backoff to retry, like __atomic_spinlock().
1722 */
1723 {
1724 moveli r23, 2048 /* maximum backoff time in cycles */
1725 moveli r25, 32 /* starting backoff time in cycles */
1726 }
17271: mfspr r26, CYCLE_LOW /* get start point for this backoff */
17282: mfspr r22, CYCLE_LOW /* test to see if we've backed off enough */
1729 sub r22, r22, r26
1730 slt r22, r22, r25
1731 bbst r22, 2b
1732 {
1733 shli r25, r25, 1 /* double the backoff; retry the tns */
1734 tns r21, ATOMIC_LOCK_REG_NAME
1735 }
1736 slt r26, r23, r25 /* is the proposed backoff too big? */
1737 {
1738 mvnz r25, r26, r23
1739 bzt r21, .Ldo_cmpxchg\bitwidth
1740 }
1741 j 1b
1742#endif /* CONFIG_SMP */
1743 .endm
1744
1745.Lcmpxchg32_tns:
1746 /*
1747 * This is the last instruction on the second cache line.
1748 * The nop here loads the second line, then we fall through
1749 * to the tns to load the third line before we take the lock.
1750 */
1751 nop
1752 cmpxchg_lock 32
1753
1754 /*
1755 * This code is invoked from sys_cmpxchg after most of the
1756 * preconditions have been checked. We still need to check
1757 * that r0 is 8-byte aligned, since if it's not we won't
1758 * actually be atomic. However, ATOMIC_LOCK_REG has the atomic
1759 * lock pointer and r27/r28 have the saved SP/PC.
1760 * r23 is holding "r0 & 7" so we can test for alignment.
1761 * The compare value is in r2/r3; the new value is in r4/r5.
1762 * On return, we must put the old value in r0/r1.
1763 */
1764 .align 64
1765.Lcmpxchg64:
1766 {
1767 bzt r23, .Lcmpxchg64_tns
1768 }
1769 j .Lcmpxchg_badaddr
1770
1771.Ldo_cmpxchg64:
1772 {
1773 lw r21, r0
1774 addi r25, r0, 4
1775 }
1776 {
1777 lw r1, r25
1778 }
1779 seq r26, r21, r2
1780 {
1781 bz r26, .Lcmpxchg64_mismatch
1782 seq r26, r1, r3
1783 }
1784 {
1785 bz r26, .Lcmpxchg64_mismatch
1786 }
1787 sw r0, r4
1788 sw r25, r5
1789
1790 /*
1791 * The 32-bit path provides optimized "match" and "mismatch"
1792 * iret paths, but we don't have enough bundles in this cache line
1793 * to do that, so we just make even the "mismatch" path do an "mf".
1794 */
1795.Lcmpxchg64_mismatch:
1796 {
1797 move sp, r27
1798 mtspr SPR_EX_CONTEXT_K_0, r28
1799 }
1800 mf
1801 {
1802 move r0, r21
1803 sw ATOMIC_LOCK_REG_NAME, zero
1804 }
1805 iret
1806
1807.Lcmpxchg64_tns:
1808 cmpxchg_lock 64
1809
1810
1811 /*
1812 * Reset sp and revector to sys_cmpxchg_badaddr(), which will
1813 * just raise the appropriate signal and exit. Doing it this
1814 * way means we don't have to duplicate the code in intvec.S's
1815 * int_hand macro that locates the top of the stack.
1816 */
1817.Lcmpxchg_badaddr:
1818 {
1819 moveli TREG_SYSCALL_NR_NAME, __NR_cmpxchg_badaddr
1820 move sp, r27
1821 }
1822 j intvec_SWINT_1
1823 ENDPROC(sys_cmpxchg)
1824 ENTRY(__sys_cmpxchg_end)
1825
1826
1827/* The single-step support may need to read all the registers. */
1828int_unalign:
1829 push_extra_callee_saves r0
1830 j do_trap
1831
1832/* Include .intrpt array of interrupt vectors */
1833 .section ".intrpt", "ax"
1834
1835#ifndef CONFIG_USE_PMC
1836#define handle_perf_interrupt bad_intr
1837#endif
1838
1839#ifndef CONFIG_HARDWALL
1840#define do_hardwall_trap bad_intr
1841#endif
1842
1843 int_hand INT_ITLB_MISS, ITLB_MISS, \
1844 do_page_fault, handle_interrupt_no_single_step
1845 int_hand INT_MEM_ERROR, MEM_ERROR, bad_intr
1846 int_hand INT_ILL, ILL, do_trap, handle_ill
1847 int_hand INT_GPV, GPV, do_trap
1848 int_hand INT_SN_ACCESS, SN_ACCESS, do_trap
1849 int_hand INT_IDN_ACCESS, IDN_ACCESS, do_trap
1850 int_hand INT_UDN_ACCESS, UDN_ACCESS, do_trap
1851 int_hand INT_IDN_REFILL, IDN_REFILL, bad_intr
1852 int_hand INT_UDN_REFILL, UDN_REFILL, bad_intr
1853 int_hand INT_IDN_COMPLETE, IDN_COMPLETE, bad_intr
1854 int_hand INT_UDN_COMPLETE, UDN_COMPLETE, bad_intr
1855 int_hand INT_SWINT_3, SWINT_3, do_trap
1856 int_hand INT_SWINT_2, SWINT_2, do_trap
1857 int_hand INT_SWINT_1, SWINT_1, SYSCALL, handle_syscall
1858 int_hand INT_SWINT_0, SWINT_0, do_trap
1859 int_hand INT_UNALIGN_DATA, UNALIGN_DATA, int_unalign
1860 int_hand INT_DTLB_MISS, DTLB_MISS, do_page_fault
1861 int_hand INT_DTLB_ACCESS, DTLB_ACCESS, do_page_fault
1862 int_hand INT_DMATLB_MISS, DMATLB_MISS, do_page_fault
1863 int_hand INT_DMATLB_ACCESS, DMATLB_ACCESS, do_page_fault
1864 int_hand INT_SNITLB_MISS, SNITLB_MISS, do_page_fault
1865 int_hand INT_SN_NOTIFY, SN_NOTIFY, bad_intr
1866 int_hand INT_SN_FIREWALL, SN_FIREWALL, do_hardwall_trap
1867 int_hand INT_IDN_FIREWALL, IDN_FIREWALL, bad_intr
1868 int_hand INT_UDN_FIREWALL, UDN_FIREWALL, do_hardwall_trap
1869 int_hand INT_TILE_TIMER, TILE_TIMER, do_timer_interrupt
1870 int_hand INT_IDN_TIMER, IDN_TIMER, bad_intr
1871 int_hand INT_UDN_TIMER, UDN_TIMER, bad_intr
1872 int_hand INT_DMA_NOTIFY, DMA_NOTIFY, bad_intr
1873 int_hand INT_IDN_CA, IDN_CA, bad_intr
1874 int_hand INT_UDN_CA, UDN_CA, bad_intr
1875 int_hand INT_IDN_AVAIL, IDN_AVAIL, bad_intr
1876 int_hand INT_UDN_AVAIL, UDN_AVAIL, bad_intr
1877 int_hand INT_PERF_COUNT, PERF_COUNT, \
1878 handle_perf_interrupt, handle_nmi
1879 int_hand INT_INTCTRL_3, INTCTRL_3, bad_intr
1880#if CONFIG_KERNEL_PL == 2
1881 dc_dispatch INT_INTCTRL_2, INTCTRL_2
1882 int_hand INT_INTCTRL_1, INTCTRL_1, bad_intr
1883#else
1884 int_hand INT_INTCTRL_2, INTCTRL_2, bad_intr
1885 dc_dispatch INT_INTCTRL_1, INTCTRL_1
1886#endif
1887 int_hand INT_INTCTRL_0, INTCTRL_0, bad_intr
1888 int_hand INT_MESSAGE_RCV_DWNCL, MESSAGE_RCV_DWNCL, \
1889 hv_message_intr
1890 int_hand INT_DEV_INTR_DWNCL, DEV_INTR_DWNCL, \
1891 tile_dev_intr
1892 int_hand INT_I_ASID, I_ASID, bad_intr
1893 int_hand INT_D_ASID, D_ASID, bad_intr
1894 int_hand INT_DMATLB_MISS_DWNCL, DMATLB_MISS_DWNCL, \
1895 do_page_fault
1896 int_hand INT_SNITLB_MISS_DWNCL, SNITLB_MISS_DWNCL, \
1897 do_page_fault
1898 int_hand INT_DMATLB_ACCESS_DWNCL, DMATLB_ACCESS_DWNCL, \
1899 do_page_fault
1900 int_hand INT_SN_CPL, SN_CPL, bad_intr
1901 int_hand INT_DOUBLE_FAULT, DOUBLE_FAULT, do_trap
1902 int_hand INT_AUX_PERF_COUNT, AUX_PERF_COUNT, \
1903 handle_perf_interrupt, handle_nmi
1904
1905 /* Synthetic interrupt delivered only by the simulator */
1906 int_hand INT_BREAKPOINT, BREAKPOINT, do_breakpoint
diff --git a/arch/tile/kernel/intvec_64.S b/arch/tile/kernel/intvec_64.S
deleted file mode 100644
index 3b51bdf37d11..000000000000
--- a/arch/tile/kernel/intvec_64.S
+++ /dev/null
@@ -1,1564 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Linux interrupt vectors.
15 */
16
17#include <linux/linkage.h>
18#include <linux/errno.h>
19#include <linux/unistd.h>
20#include <linux/init.h>
21#include <asm/ptrace.h>
22#include <asm/thread_info.h>
23#include <asm/irqflags.h>
24#include <asm/asm-offsets.h>
25#include <asm/types.h>
26#include <asm/traps.h>
27#include <asm/signal.h>
28#include <hv/hypervisor.h>
29#include <arch/abi.h>
30#include <arch/interrupts.h>
31#include <arch/spr_def.h>
32
33#define PTREGS_PTR(reg, ptreg) addli reg, sp, C_ABI_SAVE_AREA_SIZE + (ptreg)
34
35#define PTREGS_OFFSET_SYSCALL PTREGS_OFFSET_REG(TREG_SYSCALL_NR)
36
37#if CONFIG_KERNEL_PL == 1 || CONFIG_KERNEL_PL == 2
38/*
39 * Set "result" non-zero if ex1 holds the PL of the kernel
40 * (with or without ICS being set). Note this works only
41 * because we never find the PL at level 3.
42 */
43# define IS_KERNEL_EX1(result, ex1) andi result, ex1, CONFIG_KERNEL_PL
44#else
45# error Recode IS_KERNEL_EX1 for CONFIG_KERNEL_PL
46#endif
47
48 .macro push_reg reg, ptr=sp, delta=-8
49 {
50 st \ptr, \reg
51 addli \ptr, \ptr, \delta
52 }
53 .endm
54
55 .macro pop_reg reg, ptr=sp, delta=8
56 {
57 ld \reg, \ptr
58 addli \ptr, \ptr, \delta
59 }
60 .endm
61
62 .macro pop_reg_zero reg, zreg, ptr=sp, delta=8
63 {
64 move \zreg, zero
65 ld \reg, \ptr
66 addi \ptr, \ptr, \delta
67 }
68 .endm
69
70 .macro push_extra_callee_saves reg
71 PTREGS_PTR(\reg, PTREGS_OFFSET_REG(51))
72 push_reg r51, \reg
73 push_reg r50, \reg
74 push_reg r49, \reg
75 push_reg r48, \reg
76 push_reg r47, \reg
77 push_reg r46, \reg
78 push_reg r45, \reg
79 push_reg r44, \reg
80 push_reg r43, \reg
81 push_reg r42, \reg
82 push_reg r41, \reg
83 push_reg r40, \reg
84 push_reg r39, \reg
85 push_reg r38, \reg
86 push_reg r37, \reg
87 push_reg r36, \reg
88 push_reg r35, \reg
89 push_reg r34, \reg, PTREGS_OFFSET_BASE - PTREGS_OFFSET_REG(34)
90 .endm
91
92 .macro panic str
93 .pushsection .rodata, "a"
941:
95 .asciz "\str"
96 .popsection
97 {
98 moveli r0, hw2_last(1b)
99 }
100 {
101 shl16insli r0, r0, hw1(1b)
102 }
103 {
104 shl16insli r0, r0, hw0(1b)
105 jal panic
106 }
107 .endm
108
109 /*
110 * Unalign data exception fast handling: In order to handle
111 * unaligned data access, a fast JIT version is generated and stored
112 * in a specific area in user space. We first need to do a quick poke
113 * to see if the JIT is available. We use certain bits in the fault
114 * PC (3 to 9 is used for 16KB page size) as index to address the JIT
115 * code area. The first 64bit word is the fault PC, and the 2nd one is
116 * the fault bundle itself. If these 2 words both match, then we
117 * directly "iret" to JIT code. If not, a slow path is invoked to
118 * generate new JIT code. Note: the current JIT code WILL be
119 * overwritten if it existed. So, ideally we can handle 128 unalign
120 * fixups via JIT. For lookup efficiency and to effectively support
121 * tight loops with multiple unaligned reference, a simple
122 * direct-mapped cache is used.
123 *
124 * SPR_EX_CONTEXT_K_0 is modified to return to JIT code.
125 * SPR_EX_CONTEXT_K_1 has ICS set.
126 * SPR_EX_CONTEXT_0_0 is setup to user program's next PC.
127 * SPR_EX_CONTEXT_0_1 = 0.
128 */
129 .macro int_hand_unalign_fast vecnum, vecname
130 .org (\vecnum << 8)
131intvec_\vecname:
132 /* Put r3 in SPR_SYSTEM_SAVE_K_1. */
133 mtspr SPR_SYSTEM_SAVE_K_1, r3
134
135 mfspr r3, SPR_EX_CONTEXT_K_1
136 /*
137 * Examine if exception comes from user without ICS set.
138 * If not, just go directly to the slow path.
139 */
140 bnez r3, hand_unalign_slow_nonuser
141
142 mfspr r3, SPR_SYSTEM_SAVE_K_0
143
144 /* Get &thread_info->unalign_jit_tmp[0] in r3. */
145 bfexts r3, r3, 0, CPU_SHIFT-1
146 mm r3, zero, LOG2_THREAD_SIZE, 63
147 addli r3, r3, THREAD_INFO_UNALIGN_JIT_TMP_OFFSET
148
149 /*
150 * Save r0, r1, r2 into thread_info array r3 points to
151 * from low to high memory in order.
152 */
153 st_add r3, r0, 8
154 st_add r3, r1, 8
155 {
156 st_add r3, r2, 8
157 andi r2, sp, 7
158 }
159
160 /* Save stored r3 value so we can revert it on a page fault. */
161 mfspr r1, SPR_SYSTEM_SAVE_K_1
162 st r3, r1
163
164 {
165 /* Generate a SIGBUS if sp is not 8-byte aligned. */
166 bnez r2, hand_unalign_slow_badsp
167 }
168
169 /*
170 * Get the thread_info in r0; load r1 with pc. Set the low bit of sp
171 * as an indicator to the page fault code in case we fault.
172 */
173 {
174 ori sp, sp, 1
175 mfspr r1, SPR_EX_CONTEXT_K_0
176 }
177
178 /* Add the jit_info offset in thread_info; extract r1 [3:9] into r2. */
179 {
180 addli r0, r3, THREAD_INFO_UNALIGN_JIT_BASE_OFFSET - \
181 (THREAD_INFO_UNALIGN_JIT_TMP_OFFSET + (3 * 8))
182 bfextu r2, r1, 3, (2 + PAGE_SHIFT - UNALIGN_JIT_SHIFT)
183 }
184
185 /* Load the jit_info; multiply r2 by 128. */
186 {
187 ld r0, r0
188 shli r2, r2, UNALIGN_JIT_SHIFT
189 }
190
191 /*
192 * If r0 is NULL, the JIT page is not mapped, so go to slow path;
193 * add offset r2 to r0 at the same time.
194 */
195 {
196 beqz r0, hand_unalign_slow
197 add r2, r0, r2
198 }
199
200 /*
201 * We are loading from userspace (both the JIT info PC and
202 * instruction word, and the instruction word we executed)
203 * and since either could fault while holding the interrupt
204 * critical section, we must tag this region and check it in
205 * do_page_fault() to handle it properly.
206 */
207ENTRY(__start_unalign_asm_code)
208
209 /* Load first word of JIT in r0 and increment r2 by 8. */
210 ld_add r0, r2, 8
211
212 /*
213 * Compare the PC with the 1st word in JIT; load the fault bundle
214 * into r1.
215 */
216 {
217 cmpeq r0, r0, r1
218 ld r1, r1
219 }
220
221 /* Go to slow path if PC doesn't match. */
222 beqz r0, hand_unalign_slow
223
224 /*
225 * Load the 2nd word of JIT, which is supposed to be the fault
226 * bundle for a cache hit. Increment r2; after this bundle r2 will
227 * point to the potential start of the JIT code we want to run.
228 */
229 ld_add r0, r2, 8
230
231 /* No further accesses to userspace are done after this point. */
232ENTRY(__end_unalign_asm_code)
233
234 /* Compare the real bundle with what is saved in the JIT area. */
235 {
236 cmpeq r0, r1, r0
237 mtspr SPR_EX_CONTEXT_0_1, zero
238 }
239
240 /* Go to slow path if the fault bundle does not match. */
241 beqz r0, hand_unalign_slow
242
243 /*
244 * A cache hit is found.
245 * r2 points to start of JIT code (3rd word).
246 * r0 is the fault pc.
247 * r1 is the fault bundle.
248 * Reset the low bit of sp.
249 */
250 {
251 mfspr r0, SPR_EX_CONTEXT_K_0
252 andi sp, sp, ~1
253 }
254
255 /* Write r2 into EX_CONTEXT_K_0 and increment PC. */
256 {
257 mtspr SPR_EX_CONTEXT_K_0, r2
258 addi r0, r0, 8
259 }
260
261 /*
262 * Set ICS on kernel EX_CONTEXT_K_1 in order to "iret" to
263 * user with ICS set. This way, if the JIT fixup causes another
264 * unalign exception (which shouldn't be possible) the user
265 * process will be terminated with SIGBUS. Also, our fixup will
266 * run without interleaving with external interrupts.
267 * Each fixup is at most 14 bundles, so it won't hold ICS for long.
268 */
269 {
270 movei r1, PL_ICS_EX1(USER_PL, 1)
271 mtspr SPR_EX_CONTEXT_0_0, r0
272 }
273
274 {
275 mtspr SPR_EX_CONTEXT_K_1, r1
276 addi r3, r3, -(3 * 8)
277 }
278
279 /* Restore r0..r3. */
280 ld_add r0, r3, 8
281 ld_add r1, r3, 8
282 ld_add r2, r3, 8
283 ld r3, r3
284
285 iret
286 ENDPROC(intvec_\vecname)
287 .endm
288
289#ifdef __COLLECT_LINKER_FEEDBACK__
290 .pushsection .text.intvec_feedback,"ax"
291intvec_feedback:
292 .popsection
293#endif
294
295 /*
296 * Default interrupt handler.
297 *
298 * vecnum is where we'll put this code.
299 * c_routine is the C routine we'll call.
300 *
301 * The C routine is passed two arguments:
302 * - A pointer to the pt_regs state.
303 * - The interrupt vector number.
304 *
305 * The "processing" argument specifies the code for processing
306 * the interrupt. Defaults to "handle_interrupt".
307 */
308 .macro __int_hand vecnum, vecname, c_routine,processing=handle_interrupt
309intvec_\vecname:
310 /* Temporarily save a register so we have somewhere to work. */
311
312 mtspr SPR_SYSTEM_SAVE_K_1, r0
313 mfspr r0, SPR_EX_CONTEXT_K_1
314
315 /*
316 * The unalign data fastpath code sets the low bit in sp to
317 * force us to reset it here on fault.
318 */
319 {
320 blbs sp, 2f
321 IS_KERNEL_EX1(r0, r0)
322 }
323
324 .ifc \vecnum, INT_DOUBLE_FAULT
325 /*
326 * For double-faults from user-space, fall through to the normal
327 * register save and stack setup path. Otherwise, it's the
328 * hypervisor giving us one last chance to dump diagnostics, and we
329 * branch to the kernel_double_fault routine to do so.
330 */
331 beqz r0, 1f
332 j _kernel_double_fault
3331:
334 .else
335 /*
336 * If we're coming from user-space, then set sp to the top of
337 * the kernel stack. Otherwise, assume sp is already valid.
338 */
339 {
340 bnez r0, 0f
341 move r0, sp
342 }
343 .endif
344
345 .ifc \c_routine, do_page_fault
346 /*
347 * The page_fault handler may be downcalled directly by the
348 * hypervisor even when Linux is running and has ICS set.
349 *
350 * In this case the contents of EX_CONTEXT_K_1 reflect the
351 * previous fault and can't be relied on to choose whether or
352 * not to reinitialize the stack pointer. So we add a test
353 * to see whether SYSTEM_SAVE_K_2 has the high bit set,
354 * and if so we don't reinitialize sp, since we must be coming
355 * from Linux. (In fact the precise case is !(val & ~1),
356 * but any Linux PC has to have the high bit set.)
357 *
358 * Note that the hypervisor *always* sets SYSTEM_SAVE_K_2 for
359 * any path that turns into a downcall to one of our TLB handlers.
360 *
361 * FIXME: if we end up never using this path, perhaps we should
362 * prevent the hypervisor from generating downcalls in this case.
363 * The advantage of getting a downcall is we can panic in Linux.
364 */
365 mfspr r0, SPR_SYSTEM_SAVE_K_2
366 {
367 bltz r0, 0f /* high bit in S_S_1_2 is for a PC to use */
368 move r0, sp
369 }
370 .endif
371
3722:
373 /*
374 * SYSTEM_SAVE_K_0 holds the cpu number in the high bits, and
375 * the current stack top in the lower bits. So we recover
376 * our starting stack value by sign-extending the low bits, then
377 * point sp at the top aligned address on the actual stack page.
378 */
379 mfspr r0, SPR_SYSTEM_SAVE_K_0
380 bfexts r0, r0, 0, CPU_SHIFT-1
381
3820:
383 /*
384 * Align the stack mod 64 so we can properly predict what
385 * cache lines we need to write-hint to reduce memory fetch
386 * latency as we enter the kernel. The layout of memory is
387 * as follows, with cache line 0 at the lowest VA, and cache
388 * line 8 just below the r0 value this "andi" computes.
389 * Note that we never write to cache line 8, and we skip
390 * cache lines 1-3 for syscalls.
391 *
392 * cache line 8: ptregs padding (two words)
393 * cache line 7: sp, lr, pc, ex1, faultnum, orig_r0, flags, cmpexch
394 * cache line 6: r46...r53 (tp)
395 * cache line 5: r38...r45
396 * cache line 4: r30...r37
397 * cache line 3: r22...r29
398 * cache line 2: r14...r21
399 * cache line 1: r6...r13
400 * cache line 0: 2 x frame, r0..r5
401 */
402#if STACK_TOP_DELTA != 64
403#error STACK_TOP_DELTA must be 64 for assumptions here and in task_pt_regs()
404#endif
405 andi r0, r0, -64
406
407 /*
408 * Push the first four registers on the stack, so that we can set
409 * them to vector-unique values before we jump to the common code.
410 *
411 * Registers are pushed on the stack as a struct pt_regs,
412 * with the sp initially just above the struct, and when we're
413 * done, sp points to the base of the struct, minus
414 * C_ABI_SAVE_AREA_SIZE, so we can directly jal to C code.
415 *
416 * This routine saves just the first four registers, plus the
417 * stack context so we can do proper backtracing right away,
418 * and defers to handle_interrupt to save the rest.
419 * The backtracer needs pc, ex1, lr, sp, r52, and faultnum,
420 * and needs sp set to its final location at the bottom of
421 * the stack frame.
422 */
423 addli r0, r0, PTREGS_OFFSET_LR - (PTREGS_SIZE + KSTK_PTREGS_GAP)
424 wh64 r0 /* cache line 7 */
425 {
426 st r0, lr
427 addli r0, r0, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR
428 }
429 {
430 st r0, sp
431 addli sp, r0, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_SP
432 }
433 wh64 sp /* cache line 6 */
434 {
435 st sp, r52
436 addli sp, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(52)
437 }
438 wh64 sp /* cache line 0 */
439 {
440 st sp, r1
441 addli sp, sp, PTREGS_OFFSET_REG(2) - PTREGS_OFFSET_REG(1)
442 }
443 {
444 st sp, r2
445 addli sp, sp, PTREGS_OFFSET_REG(3) - PTREGS_OFFSET_REG(2)
446 }
447 {
448 st sp, r3
449 addli sp, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_REG(3)
450 }
451 mfspr r0, SPR_EX_CONTEXT_K_0
452 .ifc \processing,handle_syscall
453 /*
454 * Bump the saved PC by one bundle so that when we return, we won't
455 * execute the same swint instruction again. We need to do this while
456 * we're in the critical section.
457 */
458 addi r0, r0, 8
459 .endif
460 {
461 st sp, r0
462 addli sp, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_PC
463 }
464 mfspr r0, SPR_EX_CONTEXT_K_1
465 {
466 st sp, r0
467 addi sp, sp, PTREGS_OFFSET_FAULTNUM - PTREGS_OFFSET_EX1
468 /*
469 * Use r0 for syscalls so it's a temporary; use r1 for interrupts
470 * so that it gets passed through unchanged to the handler routine.
471 * Note that the .if conditional confusingly spans bundles.
472 */
473 .ifc \processing,handle_syscall
474 movei r0, \vecnum
475 }
476 {
477 st sp, r0
478 .else
479 movei r1, \vecnum
480 }
481 {
482 st sp, r1
483 .endif
484 addli sp, sp, PTREGS_OFFSET_REG(0) - PTREGS_OFFSET_FAULTNUM
485 }
486 mfspr r0, SPR_SYSTEM_SAVE_K_1 /* Original r0 */
487 {
488 st sp, r0
489 addi sp, sp, -PTREGS_OFFSET_REG(0) - 8
490 }
491 {
492 st sp, zero /* write zero into "Next SP" frame pointer */
493 addi sp, sp, -8 /* leave SP pointing at bottom of frame */
494 }
495 .ifc \processing,handle_syscall
496 j handle_syscall
497 .else
498 /* Capture per-interrupt SPR context to registers. */
499 .ifc \c_routine, do_page_fault
500 mfspr r2, SPR_SYSTEM_SAVE_K_3 /* address of page fault */
501 mfspr r3, SPR_SYSTEM_SAVE_K_2 /* info about page fault */
502 .else
503 .ifc \vecnum, INT_ILL_TRANS
504 mfspr r2, ILL_VA_PC
505 .else
506 .ifc \vecnum, INT_DOUBLE_FAULT
507 mfspr r2, SPR_SYSTEM_SAVE_K_2 /* double fault info from HV */
508 .else
509 .ifc \c_routine, do_trap
510 mfspr r2, GPV_REASON
511 .else
512 .ifc \c_routine, handle_perf_interrupt
513 mfspr r2, PERF_COUNT_STS
514 .else
515 .ifc \c_routine, handle_perf_interrupt
516 mfspr r2, AUX_PERF_COUNT_STS
517 .endif
518 .ifc \c_routine, do_nmi
519 mfspr r2, SPR_SYSTEM_SAVE_K_2 /* nmi type */
520 .else
521 .endif
522 .endif
523 .endif
524 .endif
525 .endif
526 .endif
527 /* Put function pointer in r0 */
528 moveli r0, hw2_last(\c_routine)
529 shl16insli r0, r0, hw1(\c_routine)
530 {
531 shl16insli r0, r0, hw0(\c_routine)
532 j \processing
533 }
534 .endif
535 ENDPROC(intvec_\vecname)
536
537#ifdef __COLLECT_LINKER_FEEDBACK__
538 .pushsection .text.intvec_feedback,"ax"
539 .org (\vecnum << 5)
540 FEEDBACK_ENTER_EXPLICIT(intvec_\vecname, .intrpt, 1 << 8)
541 jrp lr
542 .popsection
543#endif
544
545 .endm
546
547
548 /*
549 * Save the rest of the registers that we didn't save in the actual
550 * vector itself. We can't use r0-r10 inclusive here.
551 */
552 .macro finish_interrupt_save, function
553
554 /* If it's a syscall, save a proper orig_r0, otherwise just zero. */
555 PTREGS_PTR(r52, PTREGS_OFFSET_ORIG_R0)
556 {
557 .ifc \function,handle_syscall
558 st r52, r0
559 .else
560 st r52, zero
561 .endif
562 PTREGS_PTR(r52, PTREGS_OFFSET_TP)
563 }
564 st r52, tp
565 {
566 mfspr tp, CMPEXCH_VALUE
567 PTREGS_PTR(r52, PTREGS_OFFSET_CMPEXCH)
568 }
569
570 /*
571 * For ordinary syscalls, we save neither caller- nor callee-
572 * save registers, since the syscall invoker doesn't expect the
573 * caller-saves to be saved, and the called kernel functions will
574 * take care of saving the callee-saves for us.
575 *
576 * For interrupts we save just the caller-save registers. Saving
577 * them is required (since the "caller" can't save them). Again,
578 * the called kernel functions will restore the callee-save
579 * registers for us appropriately.
580 *
581 * On return, we normally restore nothing special for syscalls,
582 * and just the caller-save registers for interrupts.
583 *
584 * However, there are some important caveats to all this:
585 *
586 * - We always save a few callee-save registers to give us
587 * some scratchpad registers to carry across function calls.
588 *
589 * - fork/vfork/etc require us to save all the callee-save
590 * registers, which we do in PTREGS_SYSCALL_ALL_REGS, below.
591 *
592 * - We always save r0..r5 and r10 for syscalls, since we need
593 * to reload them a bit later for the actual kernel call, and
594 * since we might need them for -ERESTARTNOINTR, etc.
595 *
596 * - Before invoking a signal handler, we save the unsaved
597 * callee-save registers so they are visible to the
598 * signal handler or any ptracer.
599 *
600 * - If the unsaved callee-save registers are modified, we set
601 * a bit in pt_regs so we know to reload them from pt_regs
602 * and not just rely on the kernel function unwinding.
603 * (Done for ptrace register writes and SA_SIGINFO handler.)
604 */
605 {
606 st r52, tp
607 PTREGS_PTR(r52, PTREGS_OFFSET_REG(33))
608 }
609 wh64 r52 /* cache line 4 */
610 push_reg r33, r52
611 push_reg r32, r52
612 push_reg r31, r52
613 .ifc \function,handle_syscall
614 push_reg r30, r52, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(30)
615 push_reg TREG_SYSCALL_NR_NAME, r52, \
616 PTREGS_OFFSET_REG(5) - PTREGS_OFFSET_SYSCALL
617 .else
618
619 push_reg r30, r52, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(30)
620 wh64 r52 /* cache line 3 */
621 push_reg r29, r52
622 push_reg r28, r52
623 push_reg r27, r52
624 push_reg r26, r52
625 push_reg r25, r52
626 push_reg r24, r52
627 push_reg r23, r52
628 push_reg r22, r52
629 wh64 r52 /* cache line 2 */
630 push_reg r21, r52
631 push_reg r20, r52
632 push_reg r19, r52
633 push_reg r18, r52
634 push_reg r17, r52
635 push_reg r16, r52
636 push_reg r15, r52
637 push_reg r14, r52
638 wh64 r52 /* cache line 1 */
639 push_reg r13, r52
640 push_reg r12, r52
641 push_reg r11, r52
642 push_reg r10, r52
643 push_reg r9, r52
644 push_reg r8, r52
645 push_reg r7, r52
646 push_reg r6, r52
647
648 .endif
649
650 push_reg r5, r52
651 st r52, r4
652
653 /*
654 * If we will be returning to the kernel, we will need to
655 * reset the interrupt masks to the state they had before.
656 * Set DISABLE_IRQ in flags iff we came from kernel pl with
657 * irqs disabled.
658 */
659 mfspr r32, SPR_EX_CONTEXT_K_1
660 {
661 IS_KERNEL_EX1(r32, r32)
662 PTREGS_PTR(r21, PTREGS_OFFSET_FLAGS)
663 }
664 beqzt r32, 1f /* zero if from user space */
665 IRQS_DISABLED(r32) /* zero if irqs enabled */
666#if PT_FLAGS_DISABLE_IRQ != 1
667# error Value of IRQS_DISABLED used to set PT_FLAGS_DISABLE_IRQ; fix
668#endif
6691:
670 .ifnc \function,handle_syscall
671 /* Record the fact that we saved the caller-save registers above. */
672 ori r32, r32, PT_FLAGS_CALLER_SAVES
673 .endif
674 st r21, r32
675
676 /*
677 * we've captured enough state to the stack (including in
678 * particular our EX_CONTEXT state) that we can now release
679 * the interrupt critical section and replace it with our
680 * standard "interrupts disabled" mask value. This allows
681 * synchronous interrupts (and profile interrupts) to punch
682 * through from this point onwards.
683 *
684 * It's important that no code before this point touch memory
685 * other than our own stack (to keep the invariant that this
686 * is all that gets touched under ICS), and that no code after
687 * this point reference any interrupt-specific SPR, in particular
688 * the EX_CONTEXT_K_ values.
689 */
690 .ifc \function,handle_nmi
691 IRQ_DISABLE_ALL(r20)
692 .else
693 IRQ_DISABLE(r20, r21)
694 .endif
695 mtspr INTERRUPT_CRITICAL_SECTION, zero
696
697 /* Load tp with our per-cpu offset. */
698#ifdef CONFIG_SMP
699 {
700 mfspr r20, SPR_SYSTEM_SAVE_K_0
701 moveli r21, hw2_last(__per_cpu_offset)
702 }
703 {
704 shl16insli r21, r21, hw1(__per_cpu_offset)
705 bfextu r20, r20, CPU_SHIFT, 63
706 }
707 shl16insli r21, r21, hw0(__per_cpu_offset)
708 shl3add r20, r20, r21
709 ld tp, r20
710#else
711 move tp, zero
712#endif
713
714#ifdef __COLLECT_LINKER_FEEDBACK__
715 /*
716 * Notify the feedback routines that we were in the
717 * appropriate fixed interrupt vector area. Note that we
718 * still have ICS set at this point, so we can't invoke any
719 * atomic operations or we will panic. The feedback
720 * routines internally preserve r0..r10 and r30 up.
721 */
722 .ifnc \function,handle_syscall
723 shli r20, r1, 5
724 .else
725 moveli r20, INT_SWINT_1 << 5
726 .endif
727 moveli r21, hw2_last(intvec_feedback)
728 shl16insli r21, r21, hw1(intvec_feedback)
729 shl16insli r21, r21, hw0(intvec_feedback)
730 add r20, r20, r21
731 jalr r20
732
733 /* And now notify the feedback routines that we are here. */
734 FEEDBACK_ENTER(\function)
735#endif
736
737 /*
738 * Prepare the first 256 stack bytes to be rapidly accessible
739 * without having to fetch the background data.
740 */
741 addi r52, sp, -64
742 {
743 wh64 r52
744 addi r52, r52, -64
745 }
746 {
747 wh64 r52
748 addi r52, r52, -64
749 }
750 {
751 wh64 r52
752 addi r52, r52, -64
753 }
754 wh64 r52
755
756#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
757 .ifnc \function,handle_nmi
758 /*
759 * We finally have enough state set up to notify the irq
760 * tracing code that irqs were disabled on entry to the handler.
761 * The TRACE_IRQS_OFF call clobbers registers r0-r29.
762 * For syscalls, we already have the register state saved away
763 * on the stack, so we don't bother to do any register saves here,
764 * and later we pop the registers back off the kernel stack.
765 * For interrupt handlers, save r0-r3 in callee-saved registers.
766 */
767 .ifnc \function,handle_syscall
768 { move r30, r0; move r31, r1 }
769 { move r32, r2; move r33, r3 }
770 .endif
771 TRACE_IRQS_OFF
772#ifdef CONFIG_CONTEXT_TRACKING
773 jal context_tracking_user_exit
774#endif
775 .ifnc \function,handle_syscall
776 { move r0, r30; move r1, r31 }
777 { move r2, r32; move r3, r33 }
778 .endif
779 .endif
780#endif
781
782 .endm
783
784 /*
785 * Redispatch a downcall.
786 */
787 .macro dc_dispatch vecnum, vecname
788 .org (\vecnum << 8)
789intvec_\vecname:
790 j _hv_downcall_dispatch
791 ENDPROC(intvec_\vecname)
792 .endm
793
794 /*
795 * Common code for most interrupts. The C function we're eventually
796 * going to is in r0, and the faultnum is in r1; the original
797 * values for those registers are on the stack.
798 */
799 .pushsection .text.handle_interrupt,"ax"
800handle_interrupt:
801 finish_interrupt_save handle_interrupt
802
803 /* Jump to the C routine; it should enable irqs as soon as possible. */
804 {
805 jalr r0
806 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
807 }
808 FEEDBACK_REENTER(handle_interrupt)
809 {
810 movei r30, 0 /* not an NMI */
811 j interrupt_return
812 }
813 STD_ENDPROC(handle_interrupt)
814
815/*
816 * This routine takes a boolean in r30 indicating if this is an NMI.
817 * If so, we also expect a boolean in r31 indicating whether to
818 * re-enable the oprofile interrupts.
819 *
820 * Note that .Lresume_userspace is jumped to directly in several
821 * places, and we need to make sure r30 is set correctly in those
822 * callers as well.
823 */
824STD_ENTRY(interrupt_return)
825 /* If we're resuming to kernel space, don't check thread flags. */
826 {
827 bnez r30, .Lrestore_all /* NMIs don't special-case user-space */
828 PTREGS_PTR(r29, PTREGS_OFFSET_EX1)
829 }
830 ld r29, r29
831 IS_KERNEL_EX1(r29, r29)
832 {
833 beqzt r29, .Lresume_userspace
834 move r29, sp
835 }
836
837#ifdef CONFIG_PREEMPT
838 /* Returning to kernel space. Check if we need preemption. */
839 EXTRACT_THREAD_INFO(r29)
840 addli r28, r29, THREAD_INFO_FLAGS_OFFSET
841 {
842 ld r28, r28
843 addli r29, r29, THREAD_INFO_PREEMPT_COUNT_OFFSET
844 }
845 {
846 andi r28, r28, _TIF_NEED_RESCHED
847 ld4s r29, r29
848 }
849 beqzt r28, 1f
850 bnez r29, 1f
851 /* Disable interrupts explicitly for preemption. */
852 IRQ_DISABLE(r20,r21)
853 TRACE_IRQS_OFF
854 jal preempt_schedule_irq
855 FEEDBACK_REENTER(interrupt_return)
8561:
857#endif
858
859 /* If we're resuming to _cpu_idle_nap, bump PC forward by 8. */
860 {
861 moveli r27, hw2_last(_cpu_idle_nap)
862 PTREGS_PTR(r29, PTREGS_OFFSET_PC)
863 }
864 {
865 ld r28, r29
866 shl16insli r27, r27, hw1(_cpu_idle_nap)
867 }
868 {
869 shl16insli r27, r27, hw0(_cpu_idle_nap)
870 }
871 {
872 cmpeq r27, r27, r28
873 }
874 {
875 blbc r27, .Lrestore_all
876 addi r28, r28, 8
877 }
878 st r29, r28
879 j .Lrestore_all
880
881.Lresume_userspace:
882 FEEDBACK_REENTER(interrupt_return)
883
884 /*
885 * Disable interrupts so as to make sure we don't
886 * miss an interrupt that sets any of the thread flags (like
887 * need_resched or sigpending) between sampling and the iret.
888 * Routines like schedule() or do_signal() may re-enable
889 * interrupts before returning.
890 */
891 IRQ_DISABLE(r20, r21)
892 TRACE_IRQS_OFF /* Note: clobbers registers r0-r29 */
893
894 /*
895 * See if there are any work items (including single-shot items)
896 * to do. If so, save the callee-save registers to pt_regs
897 * and then dispatch to C code.
898 */
899 move r21, sp
900 EXTRACT_THREAD_INFO(r21)
901 {
902 addi r22, r21, THREAD_INFO_FLAGS_OFFSET
903 moveli r20, hw1_last(_TIF_ALLWORK_MASK)
904 }
905 {
906 ld r22, r22
907 shl16insli r20, r20, hw0(_TIF_ALLWORK_MASK)
908 }
909 and r1, r22, r20
910 {
911 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
912 beqzt r1, .Lrestore_all
913 }
914 push_extra_callee_saves r0
915 jal prepare_exit_to_usermode
916
917 /*
918 * In the NMI case we
919 * omit the call to single_process_check_nohz, which normally checks
920 * to see if we should start or stop the scheduler tick, because
921 * we can't call arbitrary Linux code from an NMI context.
922 * We always call the homecache TLB deferral code to re-trigger
923 * the deferral mechanism.
924 *
925 * The other chunk of responsibility this code has is to reset the
926 * interrupt masks appropriately to reset irqs and NMIs. We have
927 * to call TRACE_IRQS_OFF and TRACE_IRQS_ON to support all the
928 * lockdep-type stuff, but we can't set ICS until afterwards, since
929 * ICS can only be used in very tight chunks of code to avoid
930 * tripping over various assertions that it is off.
931 */
932.Lrestore_all:
933 PTREGS_PTR(r0, PTREGS_OFFSET_EX1)
934 {
935 ld r0, r0
936 PTREGS_PTR(r32, PTREGS_OFFSET_FLAGS)
937 }
938 {
939 IS_KERNEL_EX1(r0, r0)
940 ld r32, r32
941 }
942 bnez r0, 1f
943 j 2f
944#if PT_FLAGS_DISABLE_IRQ != 1
945# error Assuming PT_FLAGS_DISABLE_IRQ == 1 so we can use blbct below
946#endif
9471: blbct r32, 2f
948 IRQ_DISABLE(r20,r21)
949 TRACE_IRQS_OFF
950 movei r0, 1
951 mtspr INTERRUPT_CRITICAL_SECTION, r0
952 beqzt r30, .Lrestore_regs
953 j 3f
9542: TRACE_IRQS_ON
955 IRQ_ENABLE_LOAD(r20, r21)
956 movei r0, 1
957 mtspr INTERRUPT_CRITICAL_SECTION, r0
958 IRQ_ENABLE_APPLY(r20, r21)
959 beqzt r30, .Lrestore_regs
9603:
961
962#if INT_PERF_COUNT + 1 != INT_AUX_PERF_COUNT
963# error Bad interrupt assumption
964#endif
965 {
966 movei r0, 3 /* two adjacent bits for the PERF_COUNT mask */
967 beqz r31, .Lrestore_regs
968 }
969 shli r0, r0, INT_PERF_COUNT
970 mtspr SPR_INTERRUPT_MASK_RESET_K, r0
971
972 /*
973 * We now commit to returning from this interrupt, since we will be
974 * doing things like setting EX_CONTEXT SPRs and unwinding the stack
975 * frame. No calls should be made to any other code after this point.
976 * This code should only be entered with ICS set.
977 * r32 must still be set to ptregs.flags.
978 * We launch loads to each cache line separately first, so we can
979 * get some parallelism out of the memory subsystem.
980 * We start zeroing caller-saved registers throughout, since
981 * that will save some cycles if this turns out to be a syscall.
982 */
983.Lrestore_regs:
984
985 /*
986 * Rotate so we have one high bit and one low bit to test.
987 * - low bit says whether to restore all the callee-saved registers,
988 * or just r30-r33, and r52 up.
989 * - high bit (i.e. sign bit) says whether to restore all the
990 * caller-saved registers, or just r0.
991 */
992#if PT_FLAGS_CALLER_SAVES != 2 || PT_FLAGS_RESTORE_REGS != 4
993# error Rotate trick does not work :-)
994#endif
995 {
996 rotli r20, r32, 62
997 PTREGS_PTR(sp, PTREGS_OFFSET_REG(0))
998 }
999
1000 /*
1001 * Load cache lines 0, 4, 6 and 7, in that order, then use
1002 * the last loaded value, which makes it likely that the other
1003 * cache lines have also loaded, at which point we should be
1004 * able to safely read all the remaining words on those cache
1005 * lines without waiting for the memory subsystem.
1006 */
1007 pop_reg r0, sp, PTREGS_OFFSET_REG(30) - PTREGS_OFFSET_REG(0)
1008 pop_reg r30, sp, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_REG(30)
1009 pop_reg_zero r52, r3, sp, PTREGS_OFFSET_CMPEXCH - PTREGS_OFFSET_REG(52)
1010 pop_reg_zero r21, r27, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_CMPEXCH
1011 pop_reg_zero lr, r2, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_EX1
1012 {
1013 mtspr CMPEXCH_VALUE, r21
1014 move r4, zero
1015 }
1016 pop_reg r21, sp, PTREGS_OFFSET_REG(31) - PTREGS_OFFSET_PC
1017 {
1018 mtspr SPR_EX_CONTEXT_K_1, lr
1019 IS_KERNEL_EX1(lr, lr)
1020 }
1021 {
1022 mtspr SPR_EX_CONTEXT_K_0, r21
1023 move r5, zero
1024 }
1025
1026 /* Restore callee-saveds that we actually use. */
1027 pop_reg_zero r31, r6
1028 pop_reg_zero r32, r7
1029 pop_reg_zero r33, r8, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(33)
1030
1031 /*
1032 * If we modified other callee-saveds, restore them now.
1033 * This is rare, but could be via ptrace or signal handler.
1034 */
1035 {
1036 move r9, zero
1037 blbs r20, .Lrestore_callees
1038 }
1039.Lcontinue_restore_regs:
1040
1041 /* Check if we're returning from a syscall. */
1042 {
1043 move r10, zero
1044 bltzt r20, 1f /* no, so go restore callee-save registers */
1045 }
1046
1047 /*
1048 * Check if we're returning to userspace.
1049 * Note that if we're not, we don't worry about zeroing everything.
1050 */
1051 {
1052 addli sp, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(29)
1053 bnez lr, .Lkernel_return
1054 }
1055
1056 /*
1057 * On return from syscall, we've restored r0 from pt_regs, but we
1058 * clear the remainder of the caller-saved registers. We could
1059 * restore the syscall arguments, but there's not much point,
1060 * and it ensures user programs aren't trying to use the
1061 * caller-saves if we clear them, as well as avoiding leaking
1062 * kernel pointers into userspace.
1063 */
1064 pop_reg_zero lr, r11, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
1065 pop_reg_zero tp, r12, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
1066 {
1067 ld sp, sp
1068 move r13, zero
1069 move r14, zero
1070 }
1071 { move r15, zero; move r16, zero }
1072 { move r17, zero; move r18, zero }
1073 { move r19, zero; move r20, zero }
1074 { move r21, zero; move r22, zero }
1075 { move r23, zero; move r24, zero }
1076 { move r25, zero; move r26, zero }
1077
1078 /* Set r1 to errno if we are returning an error, otherwise zero. */
1079 {
1080 moveli r29, 4096
1081 sub r1, zero, r0
1082 }
1083 {
1084 move r28, zero
1085 cmpltu r29, r1, r29
1086 }
1087 {
1088 mnz r1, r29, r1
1089 move r29, zero
1090 }
1091 iret
1092
1093 /*
1094 * Not a syscall, so restore caller-saved registers.
1095 * First kick off loads for cache lines 1-3, which we're touching
1096 * for the first time here.
1097 */
1098 .align 64
10991: pop_reg r29, sp, PTREGS_OFFSET_REG(21) - PTREGS_OFFSET_REG(29)
1100 pop_reg r21, sp, PTREGS_OFFSET_REG(13) - PTREGS_OFFSET_REG(21)
1101 pop_reg r13, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(13)
1102 pop_reg r1
1103 pop_reg r2
1104 pop_reg r3
1105 pop_reg r4
1106 pop_reg r5
1107 pop_reg r6
1108 pop_reg r7
1109 pop_reg r8
1110 pop_reg r9
1111 pop_reg r10
1112 pop_reg r11
1113 pop_reg r12, sp, 16
1114 /* r13 already restored above */
1115 pop_reg r14
1116 pop_reg r15
1117 pop_reg r16
1118 pop_reg r17
1119 pop_reg r18
1120 pop_reg r19
1121 pop_reg r20, sp, 16
1122 /* r21 already restored above */
1123 pop_reg r22
1124 pop_reg r23
1125 pop_reg r24
1126 pop_reg r25
1127 pop_reg r26
1128 pop_reg r27
1129 pop_reg r28, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(28)
1130 /* r29 already restored above */
1131 bnez lr, .Lkernel_return
1132 pop_reg lr, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
1133 pop_reg tp, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
1134 ld sp, sp
1135 iret
1136
1137 /*
1138 * We can't restore tp when in kernel mode, since a thread might
1139 * have migrated from another cpu and brought a stale tp value.
1140 */
1141.Lkernel_return:
1142 pop_reg lr, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR
1143 ld sp, sp
1144 iret
1145
1146 /* Restore callee-saved registers from r34 to r51. */
1147.Lrestore_callees:
1148 addli sp, sp, PTREGS_OFFSET_REG(34) - PTREGS_OFFSET_REG(29)
1149 pop_reg r34
1150 pop_reg r35
1151 pop_reg r36
1152 pop_reg r37
1153 pop_reg r38
1154 pop_reg r39
1155 pop_reg r40
1156 pop_reg r41
1157 pop_reg r42
1158 pop_reg r43
1159 pop_reg r44
1160 pop_reg r45
1161 pop_reg r46
1162 pop_reg r47
1163 pop_reg r48
1164 pop_reg r49
1165 pop_reg r50
1166 pop_reg r51, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(51)
1167 j .Lcontinue_restore_regs
1168 STD_ENDPROC(interrupt_return)
1169
1170 /*
1171 * "NMI" interrupts mask ALL interrupts before calling the
1172 * handler, and don't check thread flags, etc., on the way
1173 * back out. In general, the only things we do here for NMIs
1174 * are register save/restore and dataplane kernel-TLB management.
1175 * We don't (for example) deal with start/stop of the sched tick.
1176 */
1177 .pushsection .text.handle_nmi,"ax"
1178handle_nmi:
1179 finish_interrupt_save handle_nmi
1180 {
1181 jalr r0
1182 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
1183 }
1184 FEEDBACK_REENTER(handle_nmi)
1185 {
1186 movei r30, 1
1187 cmpeq r31, r0, zero
1188 }
1189 j interrupt_return
1190 STD_ENDPROC(handle_nmi)
1191
1192 /*
1193 * Parallel code for syscalls to handle_interrupt.
1194 */
1195 .pushsection .text.handle_syscall,"ax"
1196handle_syscall:
1197 finish_interrupt_save handle_syscall
1198
1199 /* Enable irqs. */
1200 TRACE_IRQS_ON
1201 IRQ_ENABLE(r20, r21)
1202
1203 /* Bump the counter for syscalls made on this tile. */
1204 moveli r20, hw2_last(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
1205 shl16insli r20, r20, hw1(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
1206 shl16insli r20, r20, hw0(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
1207 add r20, r20, tp
1208 ld4s r21, r20
1209 {
1210 addi r21, r21, 1
1211 move r31, sp
1212 }
1213 {
1214 st4 r20, r21
1215 EXTRACT_THREAD_INFO(r31)
1216 }
1217
1218 /* Trace syscalls, if requested. */
1219 addi r31, r31, THREAD_INFO_FLAGS_OFFSET
1220 {
1221 ld r30, r31
1222 moveli r32, _TIF_SYSCALL_ENTRY_WORK
1223 }
1224 and r30, r30, r32
1225 {
1226 addi r30, r31, THREAD_INFO_STATUS_OFFSET - THREAD_INFO_FLAGS_OFFSET
1227 beqzt r30, .Lrestore_syscall_regs
1228 }
1229 {
1230 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
1231 jal do_syscall_trace_enter
1232 }
1233 FEEDBACK_REENTER(handle_syscall)
1234 bltz r0, .Lsyscall_sigreturn_skip
1235
1236 /*
1237 * We always reload our registers from the stack at this
1238 * point. They might be valid, if we didn't build with
1239 * TRACE_IRQFLAGS, and this isn't a dataplane tile, and we're not
1240 * doing syscall tracing, but there are enough cases now that it
1241 * seems simplest just to do the reload unconditionally.
1242 */
1243.Lrestore_syscall_regs:
1244 {
1245 ld r30, r30
1246 PTREGS_PTR(r11, PTREGS_OFFSET_REG(0))
1247 }
1248 pop_reg r0, r11
1249 pop_reg r1, r11
1250 pop_reg r2, r11
1251 pop_reg r3, r11
1252 pop_reg r4, r11
1253 pop_reg r5, r11, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(5)
1254 {
1255 ld TREG_SYSCALL_NR_NAME, r11
1256 moveli r21, __NR_syscalls
1257 }
1258
1259 /* Ensure that the syscall number is within the legal range. */
1260 {
1261 moveli r20, hw2(sys_call_table)
1262#ifdef CONFIG_COMPAT
1263 blbs r30, .Lcompat_syscall
1264#endif
1265 }
1266 {
1267 cmpltu r21, TREG_SYSCALL_NR_NAME, r21
1268 shl16insli r20, r20, hw1(sys_call_table)
1269 }
1270 {
1271 blbc r21, .Linvalid_syscall
1272 shl16insli r20, r20, hw0(sys_call_table)
1273 }
1274.Lload_syscall_pointer:
1275 shl3add r20, TREG_SYSCALL_NR_NAME, r20
1276 ld r20, r20
1277
1278 /* Jump to syscall handler. */
1279 jalr r20
1280.Lhandle_syscall_link: /* value of "lr" after "jalr r20" above */
1281
1282 /*
1283 * Write our r0 onto the stack so it gets restored instead
1284 * of whatever the user had there before.
1285 * In compat mode, sign-extend r0 before storing it.
1286 */
1287 {
1288 PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
1289 blbct r30, 1f
1290 }
1291 addxi r0, r0, 0
12921: st r29, r0
1293
1294.Lsyscall_sigreturn_skip:
1295 FEEDBACK_REENTER(handle_syscall)
1296
1297 /* Do syscall trace again, if requested. */
1298 {
1299 ld r30, r31
1300 moveli r32, _TIF_SYSCALL_EXIT_WORK
1301 }
1302 and r0, r30, r32
1303 {
1304 andi r0, r30, _TIF_SINGLESTEP
1305 beqzt r0, 1f
1306 }
1307 {
1308 PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
1309 jal do_syscall_trace_exit
1310 }
1311 FEEDBACK_REENTER(handle_syscall)
1312 andi r0, r30, _TIF_SINGLESTEP
1313
13141: beqzt r0, 2f
1315
1316 /* Single stepping -- notify ptrace. */
1317 {
1318 movei r0, SIGTRAP
1319 jal ptrace_notify
1320 }
1321 FEEDBACK_REENTER(handle_syscall)
1322
13232: {
1324 movei r30, 0 /* not an NMI */
1325 j .Lresume_userspace /* jump into middle of interrupt_return */
1326 }
1327
1328#ifdef CONFIG_COMPAT
1329.Lcompat_syscall:
1330 /*
1331 * Load the base of the compat syscall table in r20, and
1332 * range-check the syscall number (duplicated from 64-bit path).
1333 * Sign-extend all the user's passed arguments to make them consistent.
1334 * Also save the original "r(n)" values away in "r(11+n)" in
1335 * case the syscall table entry wants to validate them.
1336 */
1337 moveli r20, hw2(compat_sys_call_table)
1338 {
1339 cmpltu r21, TREG_SYSCALL_NR_NAME, r21
1340 shl16insli r20, r20, hw1(compat_sys_call_table)
1341 }
1342 {
1343 blbc r21, .Linvalid_syscall
1344 shl16insli r20, r20, hw0(compat_sys_call_table)
1345 }
1346 { move r11, r0; addxi r0, r0, 0 }
1347 { move r12, r1; addxi r1, r1, 0 }
1348 { move r13, r2; addxi r2, r2, 0 }
1349 { move r14, r3; addxi r3, r3, 0 }
1350 { move r15, r4; addxi r4, r4, 0 }
1351 { move r16, r5; addxi r5, r5, 0 }
1352 j .Lload_syscall_pointer
1353#endif
1354
1355.Linvalid_syscall:
1356 /* Report an invalid syscall back to the user program */
1357 {
1358 PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
1359 movei r28, -ENOSYS
1360 }
1361 st r29, r28
1362 {
1363 movei r30, 0 /* not an NMI */
1364 j .Lresume_userspace /* jump into middle of interrupt_return */
1365 }
1366 STD_ENDPROC(handle_syscall)
1367
1368 /* Return the address for oprofile to suppress in backtraces. */
1369STD_ENTRY_SECTION(handle_syscall_link_address, .text.handle_syscall)
1370 lnk r0
1371 {
1372 addli r0, r0, .Lhandle_syscall_link - .
1373 jrp lr
1374 }
1375 STD_ENDPROC(handle_syscall_link_address)
1376
1377STD_ENTRY(ret_from_fork)
1378 jal sim_notify_fork
1379 jal schedule_tail
1380 FEEDBACK_REENTER(ret_from_fork)
1381 {
1382 movei r30, 0 /* not an NMI */
1383 j .Lresume_userspace /* jump into middle of interrupt_return */
1384 }
1385 STD_ENDPROC(ret_from_fork)
1386
1387STD_ENTRY(ret_from_kernel_thread)
1388 jal sim_notify_fork
1389 jal schedule_tail
1390 FEEDBACK_REENTER(ret_from_fork)
1391 {
1392 move r0, r31
1393 jalr r30
1394 }
1395 FEEDBACK_REENTER(ret_from_kernel_thread)
1396 {
1397 movei r30, 0 /* not an NMI */
1398 j interrupt_return
1399 }
1400 STD_ENDPROC(ret_from_kernel_thread)
1401
1402/* Various stub interrupt handlers and syscall handlers */
1403
1404STD_ENTRY_LOCAL(_kernel_double_fault)
1405 mfspr r1, SPR_EX_CONTEXT_K_0
1406 move r2, lr
1407 move r3, sp
1408 move r4, r52
1409 addi sp, sp, -C_ABI_SAVE_AREA_SIZE
1410 j kernel_double_fault
1411 STD_ENDPROC(_kernel_double_fault)
1412
1413STD_ENTRY_LOCAL(bad_intr)
1414 mfspr r2, SPR_EX_CONTEXT_K_0
1415 panic "Unhandled interrupt %#x: PC %#lx"
1416 STD_ENDPROC(bad_intr)
1417
1418/*
1419 * Special-case sigreturn to not write r0 to the stack on return.
1420 * This is technically more efficient, but it also avoids difficulties
1421 * in the 64-bit OS when handling 32-bit compat code, since we must not
1422 * sign-extend r0 for the sigreturn return-value case.
1423 */
1424#define PTREGS_SYSCALL_SIGRETURN(x, reg) \
1425 STD_ENTRY(_##x); \
1426 addli lr, lr, .Lsyscall_sigreturn_skip - .Lhandle_syscall_link; \
1427 { \
1428 PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \
1429 j x \
1430 }; \
1431 STD_ENDPROC(_##x)
1432
1433PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0)
1434#ifdef CONFIG_COMPAT
1435PTREGS_SYSCALL_SIGRETURN(compat_sys_rt_sigreturn, r0)
1436#endif
1437
1438/* Save additional callee-saves to pt_regs and jump to standard function. */
1439STD_ENTRY(_sys_clone)
1440 push_extra_callee_saves r4
1441 j sys_clone
1442 STD_ENDPROC(_sys_clone)
1443
1444 /*
1445 * Recover r3, r2, r1 and r0 here saved by unalign fast vector.
1446 * The vector area limit is 32 bundles, so we handle the reload here.
1447 * r0, r1, r2 are in thread_info from low to high memory in order.
1448 * r3 points to location the original r3 was saved.
1449 * We put this code in the __HEAD section so it can be reached
1450 * via a conditional branch from the fast path.
1451 */
1452 __HEAD
1453hand_unalign_slow:
1454 andi sp, sp, ~1
1455hand_unalign_slow_badsp:
1456 addi r3, r3, -(3 * 8)
1457 ld_add r0, r3, 8
1458 ld_add r1, r3, 8
1459 ld r2, r3
1460hand_unalign_slow_nonuser:
1461 mfspr r3, SPR_SYSTEM_SAVE_K_1
1462 __int_hand INT_UNALIGN_DATA, UNALIGN_DATA_SLOW, int_unalign
1463
1464/* The unaligned data support needs to read all the registers. */
1465int_unalign:
1466 push_extra_callee_saves r0
1467 j do_unaligned
1468ENDPROC(hand_unalign_slow)
1469
1470/* Fill the return address stack with nonzero entries. */
1471STD_ENTRY(fill_ra_stack)
1472 {
1473 move r0, lr
1474 jal 1f
1475 }
14761: jal 2f
14772: jal 3f
14783: jal 4f
14794: jrp r0
1480 STD_ENDPROC(fill_ra_stack)
1481
1482 .macro int_hand vecnum, vecname, c_routine, processing=handle_interrupt
1483 .org (\vecnum << 8)
1484 __int_hand \vecnum, \vecname, \c_routine, \processing
1485 .endm
1486
1487/* Include .intrpt array of interrupt vectors */
1488 .section ".intrpt", "ax"
1489 .global intrpt_start
1490intrpt_start:
1491
1492#ifndef CONFIG_USE_PMC
1493#define handle_perf_interrupt bad_intr
1494#endif
1495
1496#ifndef CONFIG_HARDWALL
1497#define do_hardwall_trap bad_intr
1498#endif
1499
1500 int_hand INT_MEM_ERROR, MEM_ERROR, do_trap
1501 int_hand INT_SINGLE_STEP_3, SINGLE_STEP_3, bad_intr
1502#if CONFIG_KERNEL_PL == 2
1503 int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, gx_singlestep_handle
1504 int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, bad_intr
1505#else
1506 int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, bad_intr
1507 int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, gx_singlestep_handle
1508#endif
1509 int_hand INT_SINGLE_STEP_0, SINGLE_STEP_0, bad_intr
1510 int_hand INT_IDN_COMPLETE, IDN_COMPLETE, bad_intr
1511 int_hand INT_UDN_COMPLETE, UDN_COMPLETE, bad_intr
1512 int_hand INT_ITLB_MISS, ITLB_MISS, do_page_fault
1513 int_hand INT_ILL, ILL, do_trap
1514 int_hand INT_GPV, GPV, do_trap
1515 int_hand INT_IDN_ACCESS, IDN_ACCESS, do_trap
1516 int_hand INT_UDN_ACCESS, UDN_ACCESS, do_trap
1517 int_hand INT_SWINT_3, SWINT_3, do_trap
1518 int_hand INT_SWINT_2, SWINT_2, do_trap
1519 int_hand INT_SWINT_1, SWINT_1, SYSCALL, handle_syscall
1520 int_hand INT_SWINT_0, SWINT_0, do_trap
1521 int_hand INT_ILL_TRANS, ILL_TRANS, do_trap
1522 int_hand_unalign_fast INT_UNALIGN_DATA, UNALIGN_DATA
1523 int_hand INT_DTLB_MISS, DTLB_MISS, do_page_fault
1524 int_hand INT_DTLB_ACCESS, DTLB_ACCESS, do_page_fault
1525 int_hand INT_IDN_FIREWALL, IDN_FIREWALL, do_hardwall_trap
1526 int_hand INT_UDN_FIREWALL, UDN_FIREWALL, do_hardwall_trap
1527 int_hand INT_TILE_TIMER, TILE_TIMER, do_timer_interrupt
1528 int_hand INT_IDN_TIMER, IDN_TIMER, bad_intr
1529 int_hand INT_UDN_TIMER, UDN_TIMER, bad_intr
1530 int_hand INT_IDN_AVAIL, IDN_AVAIL, bad_intr
1531 int_hand INT_UDN_AVAIL, UDN_AVAIL, bad_intr
1532 int_hand INT_IPI_3, IPI_3, bad_intr
1533#if CONFIG_KERNEL_PL == 2
1534 int_hand INT_IPI_2, IPI_2, tile_dev_intr
1535 int_hand INT_IPI_1, IPI_1, bad_intr
1536#else
1537 int_hand INT_IPI_2, IPI_2, bad_intr
1538 int_hand INT_IPI_1, IPI_1, tile_dev_intr
1539#endif
1540 int_hand INT_IPI_0, IPI_0, bad_intr
1541 int_hand INT_PERF_COUNT, PERF_COUNT, \
1542 handle_perf_interrupt, handle_nmi
1543 int_hand INT_AUX_PERF_COUNT, AUX_PERF_COUNT, \
1544 handle_perf_interrupt, handle_nmi
1545 int_hand INT_INTCTRL_3, INTCTRL_3, bad_intr
1546#if CONFIG_KERNEL_PL == 2
1547 dc_dispatch INT_INTCTRL_2, INTCTRL_2
1548 int_hand INT_INTCTRL_1, INTCTRL_1, bad_intr
1549#else
1550 int_hand INT_INTCTRL_2, INTCTRL_2, bad_intr
1551 dc_dispatch INT_INTCTRL_1, INTCTRL_1
1552#endif
1553 int_hand INT_INTCTRL_0, INTCTRL_0, bad_intr
1554 int_hand INT_MESSAGE_RCV_DWNCL, MESSAGE_RCV_DWNCL, \
1555 hv_message_intr
1556 int_hand INT_DEV_INTR_DWNCL, DEV_INTR_DWNCL, bad_intr
1557 int_hand INT_I_ASID, I_ASID, bad_intr
1558 int_hand INT_D_ASID, D_ASID, bad_intr
1559 int_hand INT_DOUBLE_FAULT, DOUBLE_FAULT, do_trap
1560
1561 /* Synthetic interrupt delivered only by the simulator */
1562 int_hand INT_BREAKPOINT, BREAKPOINT, do_breakpoint
1563 /* Synthetic interrupt delivered by hv */
1564 int_hand INT_NMI_DWNCL, NMI_DWNCL, do_nmi, handle_nmi
diff --git a/arch/tile/kernel/irq.c b/arch/tile/kernel/irq.c
deleted file mode 100644
index 22044fc691ef..000000000000
--- a/arch/tile/kernel/irq.c
+++ /dev/null
@@ -1,280 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/module.h>
16#include <linux/seq_file.h>
17#include <linux/interrupt.h>
18#include <linux/irq.h>
19#include <linux/kernel_stat.h>
20#include <linux/uaccess.h>
21#include <hv/drv_pcie_rc_intf.h>
22#include <arch/spr_def.h>
23#include <asm/traps.h>
24#include <linux/perf_event.h>
25
26/* Bit-flag stored in irq_desc->chip_data to indicate HW-cleared irqs. */
27#define IS_HW_CLEARED 1
28
29/*
30 * The set of interrupts we enable for arch_local_irq_enable().
31 * This is initialized to have just a single interrupt that the kernel
32 * doesn't actually use as a sentinel. During kernel init,
33 * interrupts are added as the kernel gets prepared to support them.
34 * NOTE: we could probably initialize them all statically up front.
35 */
36DEFINE_PER_CPU(unsigned long long, interrupts_enabled_mask) =
37 INITIAL_INTERRUPTS_ENABLED;
38EXPORT_PER_CPU_SYMBOL(interrupts_enabled_mask);
39
40/* Define per-tile device interrupt statistics state. */
41DEFINE_PER_CPU(irq_cpustat_t, irq_stat) ____cacheline_internodealigned_in_smp;
42EXPORT_PER_CPU_SYMBOL(irq_stat);
43
44/*
45 * Define per-tile irq disable mask; the hardware/HV only has a single
46 * mask that we use to implement both masking and disabling.
47 */
48static DEFINE_PER_CPU(unsigned long, irq_disable_mask)
49 ____cacheline_internodealigned_in_smp;
50
51/*
52 * Per-tile IRQ nesting depth. Used to make sure we enable newly
53 * enabled IRQs before exiting the outermost interrupt.
54 */
55static DEFINE_PER_CPU(int, irq_depth);
56
57#if CHIP_HAS_IPI()
58/* Use SPRs to manipulate device interrupts. */
59#define mask_irqs(irq_mask) __insn_mtspr(SPR_IPI_MASK_SET_K, irq_mask)
60#define unmask_irqs(irq_mask) __insn_mtspr(SPR_IPI_MASK_RESET_K, irq_mask)
61#define clear_irqs(irq_mask) __insn_mtspr(SPR_IPI_EVENT_RESET_K, irq_mask)
62#else
63/* Use HV to manipulate device interrupts. */
64#define mask_irqs(irq_mask) hv_disable_intr(irq_mask)
65#define unmask_irqs(irq_mask) hv_enable_intr(irq_mask)
66#define clear_irqs(irq_mask) hv_clear_intr(irq_mask)
67#endif
68
69/*
70 * The interrupt handling path, implemented in terms of HV interrupt
71 * emulation on TILEPro, and IPI hardware on TILE-Gx.
72 * Entered with interrupts disabled.
73 */
74void tile_dev_intr(struct pt_regs *regs, int intnum)
75{
76 int depth = __this_cpu_inc_return(irq_depth);
77 unsigned long original_irqs;
78 unsigned long remaining_irqs;
79 struct pt_regs *old_regs;
80
81#if CHIP_HAS_IPI()
82 /*
83 * Pending interrupts are listed in an SPR. We might be
84 * nested, so be sure to only handle irqs that weren't already
85 * masked by a previous interrupt. Then, mask out the ones
86 * we're going to handle.
87 */
88 unsigned long masked = __insn_mfspr(SPR_IPI_MASK_K);
89 original_irqs = __insn_mfspr(SPR_IPI_EVENT_K) & ~masked;
90 __insn_mtspr(SPR_IPI_MASK_SET_K, original_irqs);
91#else
92 /*
93 * Hypervisor performs the equivalent of the Gx code above and
94 * then puts the pending interrupt mask into a system save reg
95 * for us to find.
96 */
97 original_irqs = __insn_mfspr(SPR_SYSTEM_SAVE_K_3);
98#endif
99 remaining_irqs = original_irqs;
100
101 /* Track time spent here in an interrupt context. */
102 old_regs = set_irq_regs(regs);
103 irq_enter();
104
105#ifdef CONFIG_DEBUG_STACKOVERFLOW
106 /* Debugging check for stack overflow: less than 1/8th stack free? */
107 {
108 long sp = stack_pointer - (long) current_thread_info();
109 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
110 pr_emerg("%s: stack overflow: %ld\n",
111 __func__, sp - sizeof(struct thread_info));
112 dump_stack();
113 }
114 }
115#endif
116 while (remaining_irqs) {
117 unsigned long irq = __ffs(remaining_irqs);
118 remaining_irqs &= ~(1UL << irq);
119
120 /* Count device irqs; Linux IPIs are counted elsewhere. */
121 if (irq != IRQ_RESCHEDULE)
122 __this_cpu_inc(irq_stat.irq_dev_intr_count);
123
124 generic_handle_irq(irq);
125 }
126
127 /*
128 * If we weren't nested, turn on all enabled interrupts,
129 * including any that were reenabled during interrupt
130 * handling.
131 */
132 if (depth == 1)
133 unmask_irqs(~__this_cpu_read(irq_disable_mask));
134
135 __this_cpu_dec(irq_depth);
136
137 /*
138 * Track time spent against the current process again and
139 * process any softirqs if they are waiting.
140 */
141 irq_exit();
142 set_irq_regs(old_regs);
143}
144
145
146/*
147 * Remove an irq from the disabled mask. If we're in an interrupt
148 * context, defer enabling the HW interrupt until we leave.
149 */
150static void tile_irq_chip_enable(struct irq_data *d)
151{
152 get_cpu_var(irq_disable_mask) &= ~(1UL << d->irq);
153 if (__this_cpu_read(irq_depth) == 0)
154 unmask_irqs(1UL << d->irq);
155 put_cpu_var(irq_disable_mask);
156}
157
158/*
159 * Add an irq to the disabled mask. We disable the HW interrupt
160 * immediately so that there's no possibility of it firing. If we're
161 * in an interrupt context, the return path is careful to avoid
162 * unmasking a newly disabled interrupt.
163 */
164static void tile_irq_chip_disable(struct irq_data *d)
165{
166 get_cpu_var(irq_disable_mask) |= (1UL << d->irq);
167 mask_irqs(1UL << d->irq);
168 put_cpu_var(irq_disable_mask);
169}
170
171/* Mask an interrupt. */
172static void tile_irq_chip_mask(struct irq_data *d)
173{
174 mask_irqs(1UL << d->irq);
175}
176
177/* Unmask an interrupt. */
178static void tile_irq_chip_unmask(struct irq_data *d)
179{
180 unmask_irqs(1UL << d->irq);
181}
182
183/*
184 * Clear an interrupt before processing it so that any new assertions
185 * will trigger another irq.
186 */
187static void tile_irq_chip_ack(struct irq_data *d)
188{
189 if ((unsigned long)irq_data_get_irq_chip_data(d) != IS_HW_CLEARED)
190 clear_irqs(1UL << d->irq);
191}
192
193/*
194 * For per-cpu interrupts, we need to avoid unmasking any interrupts
195 * that we disabled via disable_percpu_irq().
196 */
197static void tile_irq_chip_eoi(struct irq_data *d)
198{
199 if (!(__this_cpu_read(irq_disable_mask) & (1UL << d->irq)))
200 unmask_irqs(1UL << d->irq);
201}
202
203static struct irq_chip tile_irq_chip = {
204 .name = "tile_irq_chip",
205 .irq_enable = tile_irq_chip_enable,
206 .irq_disable = tile_irq_chip_disable,
207 .irq_ack = tile_irq_chip_ack,
208 .irq_eoi = tile_irq_chip_eoi,
209 .irq_mask = tile_irq_chip_mask,
210 .irq_unmask = tile_irq_chip_unmask,
211};
212
213void __init init_IRQ(void)
214{
215 ipi_init();
216}
217
218void setup_irq_regs(void)
219{
220 /* Enable interrupt delivery. */
221 unmask_irqs(~0UL);
222#if CHIP_HAS_IPI()
223 arch_local_irq_unmask(INT_IPI_K);
224#endif
225}
226
227void tile_irq_activate(unsigned int irq, int tile_irq_type)
228{
229 /*
230 * We use handle_level_irq() by default because the pending
231 * interrupt vector (whether modeled by the HV on
232 * TILEPro or implemented in hardware on TILE-Gx) has
233 * level-style semantics for each bit. An interrupt fires
234 * whenever a bit is high, not just at edges.
235 */
236 irq_flow_handler_t handle = handle_level_irq;
237 if (tile_irq_type == TILE_IRQ_PERCPU)
238 handle = handle_percpu_irq;
239 irq_set_chip_and_handler(irq, &tile_irq_chip, handle);
240
241 /*
242 * Flag interrupts that are hardware-cleared so that ack()
243 * won't clear them.
244 */
245 if (tile_irq_type == TILE_IRQ_HW_CLEAR)
246 irq_set_chip_data(irq, (void *)IS_HW_CLEARED);
247}
248EXPORT_SYMBOL(tile_irq_activate);
249
250
251void ack_bad_irq(unsigned int irq)
252{
253 pr_err("unexpected IRQ trap at vector %02x\n", irq);
254}
255
256/*
257 * /proc/interrupts printing:
258 */
259int arch_show_interrupts(struct seq_file *p, int prec)
260{
261#ifdef CONFIG_PERF_EVENTS
262 int i;
263
264 seq_printf(p, "%*s: ", prec, "PMI");
265
266 for_each_online_cpu(i)
267 seq_printf(p, "%10llu ", per_cpu(perf_irqs, i));
268 seq_puts(p, " perf_events\n");
269#endif
270 return 0;
271}
272
273#if CHIP_HAS_IPI()
274int arch_setup_hwirq(unsigned int irq, int node)
275{
276 return irq >= NR_IRQS ? -EINVAL : 0;
277}
278
279void arch_teardown_hwirq(unsigned int irq) { }
280#endif
diff --git a/arch/tile/kernel/jump_label.c b/arch/tile/kernel/jump_label.c
deleted file mode 100644
index 93931a46625b..000000000000
--- a/arch/tile/kernel/jump_label.c
+++ /dev/null
@@ -1,62 +0,0 @@
1/*
2 * Copyright 2015 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * jump label TILE-Gx support
15 */
16
17#include <linux/jump_label.h>
18#include <linux/memory.h>
19#include <linux/module.h>
20#include <linux/mutex.h>
21#include <linux/cpu.h>
22
23#include <asm/cacheflush.h>
24#include <asm/insn.h>
25
26#ifdef HAVE_JUMP_LABEL
27
28static void __jump_label_transform(struct jump_entry *e,
29 enum jump_label_type type)
30{
31 tilegx_bundle_bits opcode;
32 /* Operate on writable kernel text mapping. */
33 unsigned long pc_wr = ktext_writable_addr(e->code);
34
35 if (type == JUMP_LABEL_JMP)
36 opcode = tilegx_gen_branch(e->code, e->target, false);
37 else
38 opcode = NOP();
39
40 *(tilegx_bundle_bits *)pc_wr = opcode;
41 /* Make sure that above mem writes were issued towards the memory. */
42 smp_wmb();
43}
44
45void arch_jump_label_transform(struct jump_entry *e,
46 enum jump_label_type type)
47{
48 mutex_lock(&text_mutex);
49
50 __jump_label_transform(e, type);
51 flush_icache_range(e->code, e->code + sizeof(tilegx_bundle_bits));
52
53 mutex_unlock(&text_mutex);
54}
55
56__init_or_module void arch_jump_label_transform_static(struct jump_entry *e,
57 enum jump_label_type type)
58{
59 __jump_label_transform(e, type);
60}
61
62#endif /* HAVE_JUMP_LABEL */
diff --git a/arch/tile/kernel/kgdb.c b/arch/tile/kernel/kgdb.c
deleted file mode 100644
index d4eb5fb2df9d..000000000000
--- a/arch/tile/kernel/kgdb.c
+++ /dev/null
@@ -1,497 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE-Gx KGDB support.
15 */
16
17#include <linux/ptrace.h>
18#include <linux/kgdb.h>
19#include <linux/kdebug.h>
20#include <linux/uaccess.h>
21#include <linux/module.h>
22#include <linux/sched/task_stack.h>
23
24#include <asm/cacheflush.h>
25
26static tile_bundle_bits singlestep_insn = TILEGX_BPT_BUNDLE | DIE_SSTEPBP;
27static unsigned long stepped_addr;
28static tile_bundle_bits stepped_instr;
29
30struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
31 { "r0", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[0])},
32 { "r1", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[1])},
33 { "r2", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[2])},
34 { "r3", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[3])},
35 { "r4", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[4])},
36 { "r5", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[5])},
37 { "r6", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[6])},
38 { "r7", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[7])},
39 { "r8", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[8])},
40 { "r9", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[9])},
41 { "r10", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[10])},
42 { "r11", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[11])},
43 { "r12", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[12])},
44 { "r13", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[13])},
45 { "r14", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[14])},
46 { "r15", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[15])},
47 { "r16", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[16])},
48 { "r17", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[17])},
49 { "r18", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[18])},
50 { "r19", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[19])},
51 { "r20", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[20])},
52 { "r21", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[21])},
53 { "r22", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[22])},
54 { "r23", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[23])},
55 { "r24", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[24])},
56 { "r25", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[25])},
57 { "r26", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[26])},
58 { "r27", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[27])},
59 { "r28", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[28])},
60 { "r29", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[29])},
61 { "r30", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[30])},
62 { "r31", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[31])},
63 { "r32", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[32])},
64 { "r33", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[33])},
65 { "r34", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[34])},
66 { "r35", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[35])},
67 { "r36", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[36])},
68 { "r37", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[37])},
69 { "r38", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[38])},
70 { "r39", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[39])},
71 { "r40", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[40])},
72 { "r41", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[41])},
73 { "r42", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[42])},
74 { "r43", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[43])},
75 { "r44", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[44])},
76 { "r45", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[45])},
77 { "r46", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[46])},
78 { "r47", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[47])},
79 { "r48", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[48])},
80 { "r49", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[49])},
81 { "r50", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[50])},
82 { "r51", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[51])},
83 { "r52", GDB_SIZEOF_REG, offsetof(struct pt_regs, regs[52])},
84 { "tp", GDB_SIZEOF_REG, offsetof(struct pt_regs, tp)},
85 { "sp", GDB_SIZEOF_REG, offsetof(struct pt_regs, sp)},
86 { "lr", GDB_SIZEOF_REG, offsetof(struct pt_regs, lr)},
87 { "sn", GDB_SIZEOF_REG, -1},
88 { "idn0", GDB_SIZEOF_REG, -1},
89 { "idn1", GDB_SIZEOF_REG, -1},
90 { "udn0", GDB_SIZEOF_REG, -1},
91 { "udn1", GDB_SIZEOF_REG, -1},
92 { "udn2", GDB_SIZEOF_REG, -1},
93 { "udn3", GDB_SIZEOF_REG, -1},
94 { "zero", GDB_SIZEOF_REG, -1},
95 { "pc", GDB_SIZEOF_REG, offsetof(struct pt_regs, pc)},
96 { "faultnum", GDB_SIZEOF_REG, offsetof(struct pt_regs, faultnum)},
97};
98
99char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
100{
101 if (regno >= DBG_MAX_REG_NUM || regno < 0)
102 return NULL;
103
104 if (dbg_reg_def[regno].offset != -1)
105 memcpy(mem, (void *)regs + dbg_reg_def[regno].offset,
106 dbg_reg_def[regno].size);
107 else
108 memset(mem, 0, dbg_reg_def[regno].size);
109 return dbg_reg_def[regno].name;
110}
111
112int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
113{
114 if (regno >= DBG_MAX_REG_NUM || regno < 0)
115 return -EINVAL;
116
117 if (dbg_reg_def[regno].offset != -1)
118 memcpy((void *)regs + dbg_reg_def[regno].offset, mem,
119 dbg_reg_def[regno].size);
120 return 0;
121}
122
123/*
124 * Similar to pt_regs_to_gdb_regs() except that process is sleeping and so
125 * we may not be able to get all the info.
126 */
127void
128sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
129{
130 struct pt_regs *thread_regs;
131 const int NGPRS = TREG_LAST_GPR + 1;
132
133 if (task == NULL)
134 return;
135
136 thread_regs = task_pt_regs(task);
137 memcpy(gdb_regs, thread_regs, NGPRS * sizeof(unsigned long));
138 memset(&gdb_regs[NGPRS], 0,
139 (TILEGX_PC_REGNUM - NGPRS) * sizeof(unsigned long));
140 gdb_regs[TILEGX_PC_REGNUM] = thread_regs->pc;
141 gdb_regs[TILEGX_FAULTNUM_REGNUM] = thread_regs->faultnum;
142}
143
144void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
145{
146 regs->pc = pc;
147}
148
149static void kgdb_call_nmi_hook(void *ignored)
150{
151 kgdb_nmicallback(raw_smp_processor_id(), NULL);
152}
153
154void kgdb_roundup_cpus(unsigned long flags)
155{
156 local_irq_enable();
157 smp_call_function(kgdb_call_nmi_hook, NULL, 0);
158 local_irq_disable();
159}
160
161/*
162 * Convert a kernel address to the writable kernel text mapping.
163 */
164static unsigned long writable_address(unsigned long addr)
165{
166 unsigned long ret = 0;
167
168 if (core_kernel_text(addr))
169 ret = ktext_writable_addr(addr);
170 else if (is_module_text_address(addr))
171 ret = addr;
172 else
173 pr_err("Unknown virtual address 0x%lx\n", addr);
174
175 return ret;
176}
177
178/*
179 * Calculate the new address for after a step.
180 */
181static unsigned long get_step_address(struct pt_regs *regs)
182{
183 int src_reg;
184 int jump_off;
185 int br_off;
186 unsigned long addr;
187 unsigned int opcode;
188 tile_bundle_bits bundle;
189
190 /* Move to the next instruction by default. */
191 addr = regs->pc + TILEGX_BUNDLE_SIZE_IN_BYTES;
192 bundle = *(unsigned long *)instruction_pointer(regs);
193
194 /* 0: X mode, Otherwise: Y mode. */
195 if (bundle & TILEGX_BUNDLE_MODE_MASK) {
196 if (get_Opcode_Y1(bundle) == RRR_1_OPCODE_Y1 &&
197 get_RRROpcodeExtension_Y1(bundle) ==
198 UNARY_RRR_1_OPCODE_Y1) {
199 opcode = get_UnaryOpcodeExtension_Y1(bundle);
200
201 switch (opcode) {
202 case JALR_UNARY_OPCODE_Y1:
203 case JALRP_UNARY_OPCODE_Y1:
204 case JR_UNARY_OPCODE_Y1:
205 case JRP_UNARY_OPCODE_Y1:
206 src_reg = get_SrcA_Y1(bundle);
207 dbg_get_reg(src_reg, &addr, regs);
208 break;
209 }
210 }
211 } else if (get_Opcode_X1(bundle) == RRR_0_OPCODE_X1) {
212 if (get_RRROpcodeExtension_X1(bundle) ==
213 UNARY_RRR_0_OPCODE_X1) {
214 opcode = get_UnaryOpcodeExtension_X1(bundle);
215
216 switch (opcode) {
217 case JALR_UNARY_OPCODE_X1:
218 case JALRP_UNARY_OPCODE_X1:
219 case JR_UNARY_OPCODE_X1:
220 case JRP_UNARY_OPCODE_X1:
221 src_reg = get_SrcA_X1(bundle);
222 dbg_get_reg(src_reg, &addr, regs);
223 break;
224 }
225 }
226 } else if (get_Opcode_X1(bundle) == JUMP_OPCODE_X1) {
227 opcode = get_JumpOpcodeExtension_X1(bundle);
228
229 switch (opcode) {
230 case JAL_JUMP_OPCODE_X1:
231 case J_JUMP_OPCODE_X1:
232 jump_off = sign_extend(get_JumpOff_X1(bundle), 27);
233 addr = regs->pc +
234 (jump_off << TILEGX_LOG2_BUNDLE_SIZE_IN_BYTES);
235 break;
236 }
237 } else if (get_Opcode_X1(bundle) == BRANCH_OPCODE_X1) {
238 br_off = 0;
239 opcode = get_BrType_X1(bundle);
240
241 switch (opcode) {
242 case BEQZT_BRANCH_OPCODE_X1:
243 case BEQZ_BRANCH_OPCODE_X1:
244 if (get_SrcA_X1(bundle) == 0)
245 br_off = get_BrOff_X1(bundle);
246 break;
247 case BGEZT_BRANCH_OPCODE_X1:
248 case BGEZ_BRANCH_OPCODE_X1:
249 if (get_SrcA_X1(bundle) >= 0)
250 br_off = get_BrOff_X1(bundle);
251 break;
252 case BGTZT_BRANCH_OPCODE_X1:
253 case BGTZ_BRANCH_OPCODE_X1:
254 if (get_SrcA_X1(bundle) > 0)
255 br_off = get_BrOff_X1(bundle);
256 break;
257 case BLBCT_BRANCH_OPCODE_X1:
258 case BLBC_BRANCH_OPCODE_X1:
259 if (!(get_SrcA_X1(bundle) & 1))
260 br_off = get_BrOff_X1(bundle);
261 break;
262 case BLBST_BRANCH_OPCODE_X1:
263 case BLBS_BRANCH_OPCODE_X1:
264 if (get_SrcA_X1(bundle) & 1)
265 br_off = get_BrOff_X1(bundle);
266 break;
267 case BLEZT_BRANCH_OPCODE_X1:
268 case BLEZ_BRANCH_OPCODE_X1:
269 if (get_SrcA_X1(bundle) <= 0)
270 br_off = get_BrOff_X1(bundle);
271 break;
272 case BLTZT_BRANCH_OPCODE_X1:
273 case BLTZ_BRANCH_OPCODE_X1:
274 if (get_SrcA_X1(bundle) < 0)
275 br_off = get_BrOff_X1(bundle);
276 break;
277 case BNEZT_BRANCH_OPCODE_X1:
278 case BNEZ_BRANCH_OPCODE_X1:
279 if (get_SrcA_X1(bundle) != 0)
280 br_off = get_BrOff_X1(bundle);
281 break;
282 }
283
284 if (br_off != 0) {
285 br_off = sign_extend(br_off, 17);
286 addr = regs->pc +
287 (br_off << TILEGX_LOG2_BUNDLE_SIZE_IN_BYTES);
288 }
289 }
290
291 return addr;
292}
293
294/*
295 * Replace the next instruction after the current instruction with a
296 * breakpoint instruction.
297 */
298static void do_single_step(struct pt_regs *regs)
299{
300 unsigned long addr_wr;
301
302 /* Determine where the target instruction will send us to. */
303 stepped_addr = get_step_address(regs);
304 probe_kernel_read((char *)&stepped_instr, (char *)stepped_addr,
305 BREAK_INSTR_SIZE);
306
307 addr_wr = writable_address(stepped_addr);
308 probe_kernel_write((char *)addr_wr, (char *)&singlestep_insn,
309 BREAK_INSTR_SIZE);
310 smp_wmb();
311 flush_icache_range(stepped_addr, stepped_addr + BREAK_INSTR_SIZE);
312}
313
314static void undo_single_step(struct pt_regs *regs)
315{
316 unsigned long addr_wr;
317
318 if (stepped_instr == 0)
319 return;
320
321 addr_wr = writable_address(stepped_addr);
322 probe_kernel_write((char *)addr_wr, (char *)&stepped_instr,
323 BREAK_INSTR_SIZE);
324 stepped_instr = 0;
325 smp_wmb();
326 flush_icache_range(stepped_addr, stepped_addr + BREAK_INSTR_SIZE);
327}
328
329/*
330 * Calls linux_debug_hook before the kernel dies. If KGDB is enabled,
331 * then try to fall into the debugger.
332 */
333static int
334kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
335{
336 int ret;
337 unsigned long flags;
338 struct die_args *args = (struct die_args *)ptr;
339 struct pt_regs *regs = args->regs;
340
341#ifdef CONFIG_KPROBES
342 /*
343 * Return immediately if the kprobes fault notifier has set
344 * DIE_PAGE_FAULT.
345 */
346 if (cmd == DIE_PAGE_FAULT)
347 return NOTIFY_DONE;
348#endif /* CONFIG_KPROBES */
349
350 switch (cmd) {
351 case DIE_BREAK:
352 case DIE_COMPILED_BPT:
353 break;
354 case DIE_SSTEPBP:
355 local_irq_save(flags);
356 kgdb_handle_exception(0, SIGTRAP, 0, regs);
357 local_irq_restore(flags);
358 return NOTIFY_STOP;
359 default:
360 /* Userspace events, ignore. */
361 if (user_mode(regs))
362 return NOTIFY_DONE;
363 }
364
365 local_irq_save(flags);
366 ret = kgdb_handle_exception(args->trapnr, args->signr, args->err, regs);
367 local_irq_restore(flags);
368 if (ret)
369 return NOTIFY_DONE;
370
371 return NOTIFY_STOP;
372}
373
374static struct notifier_block kgdb_notifier = {
375 .notifier_call = kgdb_notify,
376};
377
378/*
379 * kgdb_arch_handle_exception - Handle architecture specific GDB packets.
380 * @vector: The error vector of the exception that happened.
381 * @signo: The signal number of the exception that happened.
382 * @err_code: The error code of the exception that happened.
383 * @remcom_in_buffer: The buffer of the packet we have read.
384 * @remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
385 * @regs: The &struct pt_regs of the current process.
386 *
387 * This function MUST handle the 'c' and 's' command packets,
388 * as well packets to set / remove a hardware breakpoint, if used.
389 * If there are additional packets which the hardware needs to handle,
390 * they are handled here. The code should return -1 if it wants to
391 * process more packets, and a %0 or %1 if it wants to exit from the
392 * kgdb callback.
393 */
394int kgdb_arch_handle_exception(int vector, int signo, int err_code,
395 char *remcom_in_buffer, char *remcom_out_buffer,
396 struct pt_regs *regs)
397{
398 char *ptr;
399 unsigned long address;
400
401 /* Undo any stepping we may have done. */
402 undo_single_step(regs);
403
404 switch (remcom_in_buffer[0]) {
405 case 'c':
406 case 's':
407 case 'D':
408 case 'k':
409 /*
410 * Try to read optional parameter, pc unchanged if no parm.
411 * If this was a compiled-in breakpoint, we need to move
412 * to the next instruction or we will just breakpoint
413 * over and over again.
414 */
415 ptr = &remcom_in_buffer[1];
416 if (kgdb_hex2long(&ptr, &address))
417 regs->pc = address;
418 else if (*(unsigned long *)regs->pc == compiled_bpt)
419 regs->pc += BREAK_INSTR_SIZE;
420
421 if (remcom_in_buffer[0] == 's') {
422 do_single_step(regs);
423 kgdb_single_step = 1;
424 atomic_set(&kgdb_cpu_doing_single_step,
425 raw_smp_processor_id());
426 } else
427 atomic_set(&kgdb_cpu_doing_single_step, -1);
428
429 return 0;
430 }
431
432 return -1; /* this means that we do not want to exit from the handler */
433}
434
435struct kgdb_arch arch_kgdb_ops;
436
437/*
438 * kgdb_arch_init - Perform any architecture specific initialization.
439 *
440 * This function will handle the initialization of any architecture
441 * specific callbacks.
442 */
443int kgdb_arch_init(void)
444{
445 tile_bundle_bits bundle = TILEGX_BPT_BUNDLE;
446
447 memcpy(arch_kgdb_ops.gdb_bpt_instr, &bundle, BREAK_INSTR_SIZE);
448 return register_die_notifier(&kgdb_notifier);
449}
450
451/*
452 * kgdb_arch_exit - Perform any architecture specific uninitialization.
453 *
454 * This function will handle the uninitialization of any architecture
455 * specific callbacks, for dynamic registration and unregistration.
456 */
457void kgdb_arch_exit(void)
458{
459 unregister_die_notifier(&kgdb_notifier);
460}
461
462int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
463{
464 int err;
465 unsigned long addr_wr = writable_address(bpt->bpt_addr);
466
467 if (addr_wr == 0)
468 return -1;
469
470 err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
471 BREAK_INSTR_SIZE);
472 if (err)
473 return err;
474
475 err = probe_kernel_write((char *)addr_wr, arch_kgdb_ops.gdb_bpt_instr,
476 BREAK_INSTR_SIZE);
477 smp_wmb();
478 flush_icache_range((unsigned long)bpt->bpt_addr,
479 (unsigned long)bpt->bpt_addr + BREAK_INSTR_SIZE);
480 return err;
481}
482
483int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
484{
485 int err;
486 unsigned long addr_wr = writable_address(bpt->bpt_addr);
487
488 if (addr_wr == 0)
489 return -1;
490
491 err = probe_kernel_write((char *)addr_wr, (char *)bpt->saved_instr,
492 BREAK_INSTR_SIZE);
493 smp_wmb();
494 flush_icache_range((unsigned long)bpt->bpt_addr,
495 (unsigned long)bpt->bpt_addr + BREAK_INSTR_SIZE);
496 return err;
497}
diff --git a/arch/tile/kernel/kprobes.c b/arch/tile/kernel/kprobes.c
deleted file mode 100644
index c68694bb1ad2..000000000000
--- a/arch/tile/kernel/kprobes.c
+++ /dev/null
@@ -1,527 +0,0 @@
1/*
2 * arch/tile/kernel/kprobes.c
3 * Kprobes on TILE-Gx
4 *
5 * Some portions copied from the MIPS version.
6 *
7 * Copyright (C) IBM Corporation, 2002, 2004
8 * Copyright 2006 Sony Corp.
9 * Copyright 2010 Cavium Networks
10 *
11 * Copyright 2012 Tilera Corporation. All Rights Reserved.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation, version 2.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
20 * NON INFRINGEMENT. See the GNU General Public License for
21 * more details.
22 */
23
24#include <linux/kprobes.h>
25#include <linux/kdebug.h>
26#include <linux/module.h>
27#include <linux/slab.h>
28#include <linux/uaccess.h>
29#include <asm/cacheflush.h>
30
31#include <arch/opcode.h>
32
33DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
34DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
35
36tile_bundle_bits breakpoint_insn = TILEGX_BPT_BUNDLE;
37tile_bundle_bits breakpoint2_insn = TILEGX_BPT_BUNDLE | DIE_SSTEPBP;
38
39/*
40 * Check whether instruction is branch or jump, or if executing it
41 * has different results depending on where it is executed (e.g. lnk).
42 */
43static int __kprobes insn_has_control(kprobe_opcode_t insn)
44{
45 if (get_Mode(insn) != 0) { /* Y-format bundle */
46 if (get_Opcode_Y1(insn) != RRR_1_OPCODE_Y1 ||
47 get_RRROpcodeExtension_Y1(insn) != UNARY_RRR_1_OPCODE_Y1)
48 return 0;
49
50 switch (get_UnaryOpcodeExtension_Y1(insn)) {
51 case JALRP_UNARY_OPCODE_Y1:
52 case JALR_UNARY_OPCODE_Y1:
53 case JRP_UNARY_OPCODE_Y1:
54 case JR_UNARY_OPCODE_Y1:
55 case LNK_UNARY_OPCODE_Y1:
56 return 1;
57 default:
58 return 0;
59 }
60 }
61
62 switch (get_Opcode_X1(insn)) {
63 case BRANCH_OPCODE_X1: /* branch instructions */
64 case JUMP_OPCODE_X1: /* jump instructions: j and jal */
65 return 1;
66
67 case RRR_0_OPCODE_X1: /* other jump instructions */
68 if (get_RRROpcodeExtension_X1(insn) != UNARY_RRR_0_OPCODE_X1)
69 return 0;
70 switch (get_UnaryOpcodeExtension_X1(insn)) {
71 case JALRP_UNARY_OPCODE_X1:
72 case JALR_UNARY_OPCODE_X1:
73 case JRP_UNARY_OPCODE_X1:
74 case JR_UNARY_OPCODE_X1:
75 case LNK_UNARY_OPCODE_X1:
76 return 1;
77 default:
78 return 0;
79 }
80 default:
81 return 0;
82 }
83}
84
85int __kprobes arch_prepare_kprobe(struct kprobe *p)
86{
87 unsigned long addr = (unsigned long)p->addr;
88
89 if (addr & (sizeof(kprobe_opcode_t) - 1))
90 return -EINVAL;
91
92 if (insn_has_control(*p->addr)) {
93 pr_notice("Kprobes for control instructions are not supported\n");
94 return -EINVAL;
95 }
96
97 /* insn: must be on special executable page on tile. */
98 p->ainsn.insn = get_insn_slot();
99 if (!p->ainsn.insn)
100 return -ENOMEM;
101
102 /*
103 * In the kprobe->ainsn.insn[] array we store the original
104 * instruction at index zero and a break trap instruction at
105 * index one.
106 */
107 memcpy(&p->ainsn.insn[0], p->addr, sizeof(kprobe_opcode_t));
108 p->ainsn.insn[1] = breakpoint2_insn;
109 p->opcode = *p->addr;
110
111 return 0;
112}
113
114void __kprobes arch_arm_kprobe(struct kprobe *p)
115{
116 unsigned long addr_wr;
117
118 /* Operate on writable kernel text mapping. */
119 addr_wr = ktext_writable_addr(p->addr);
120
121 if (probe_kernel_write((void *)addr_wr, &breakpoint_insn,
122 sizeof(breakpoint_insn)))
123 pr_err("%s: failed to enable kprobe\n", __func__);
124
125 smp_wmb();
126 flush_insn_slot(p);
127}
128
129void __kprobes arch_disarm_kprobe(struct kprobe *kp)
130{
131 unsigned long addr_wr;
132
133 /* Operate on writable kernel text mapping. */
134 addr_wr = ktext_writable_addr(kp->addr);
135
136 if (probe_kernel_write((void *)addr_wr, &kp->opcode,
137 sizeof(kp->opcode)))
138 pr_err("%s: failed to enable kprobe\n", __func__);
139
140 smp_wmb();
141 flush_insn_slot(kp);
142}
143
144void __kprobes arch_remove_kprobe(struct kprobe *p)
145{
146 if (p->ainsn.insn) {
147 free_insn_slot(p->ainsn.insn, 0);
148 p->ainsn.insn = NULL;
149 }
150}
151
152static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
153{
154 kcb->prev_kprobe.kp = kprobe_running();
155 kcb->prev_kprobe.status = kcb->kprobe_status;
156 kcb->prev_kprobe.saved_pc = kcb->kprobe_saved_pc;
157}
158
159static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
160{
161 __this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
162 kcb->kprobe_status = kcb->prev_kprobe.status;
163 kcb->kprobe_saved_pc = kcb->prev_kprobe.saved_pc;
164}
165
166static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
167 struct kprobe_ctlblk *kcb)
168{
169 __this_cpu_write(current_kprobe, p);
170 kcb->kprobe_saved_pc = regs->pc;
171}
172
173static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
174{
175 /* Single step inline if the instruction is a break. */
176 if (p->opcode == breakpoint_insn ||
177 p->opcode == breakpoint2_insn)
178 regs->pc = (unsigned long)p->addr;
179 else
180 regs->pc = (unsigned long)&p->ainsn.insn[0];
181}
182
183static int __kprobes kprobe_handler(struct pt_regs *regs)
184{
185 struct kprobe *p;
186 int ret = 0;
187 kprobe_opcode_t *addr;
188 struct kprobe_ctlblk *kcb;
189
190 addr = (kprobe_opcode_t *)regs->pc;
191
192 /*
193 * We don't want to be preempted for the entire
194 * duration of kprobe processing.
195 */
196 preempt_disable();
197 kcb = get_kprobe_ctlblk();
198
199 /* Check we're not actually recursing. */
200 if (kprobe_running()) {
201 p = get_kprobe(addr);
202 if (p) {
203 if (kcb->kprobe_status == KPROBE_HIT_SS &&
204 p->ainsn.insn[0] == breakpoint_insn) {
205 goto no_kprobe;
206 }
207 /*
208 * We have reentered the kprobe_handler(), since
209 * another probe was hit while within the handler.
210 * We here save the original kprobes variables and
211 * just single step on the instruction of the new probe
212 * without calling any user handlers.
213 */
214 save_previous_kprobe(kcb);
215 set_current_kprobe(p, regs, kcb);
216 kprobes_inc_nmissed_count(p);
217 prepare_singlestep(p, regs);
218 kcb->kprobe_status = KPROBE_REENTER;
219 return 1;
220 } else {
221 if (*addr != breakpoint_insn) {
222 /*
223 * The breakpoint instruction was removed by
224 * another cpu right after we hit, no further
225 * handling of this interrupt is appropriate.
226 */
227 ret = 1;
228 goto no_kprobe;
229 }
230 p = __this_cpu_read(current_kprobe);
231 if (p->break_handler && p->break_handler(p, regs))
232 goto ss_probe;
233 }
234 goto no_kprobe;
235 }
236
237 p = get_kprobe(addr);
238 if (!p) {
239 if (*addr != breakpoint_insn) {
240 /*
241 * The breakpoint instruction was removed right
242 * after we hit it. Another cpu has removed
243 * either a probepoint or a debugger breakpoint
244 * at this address. In either case, no further
245 * handling of this interrupt is appropriate.
246 */
247 ret = 1;
248 }
249 /* Not one of ours: let kernel handle it. */
250 goto no_kprobe;
251 }
252
253 set_current_kprobe(p, regs, kcb);
254 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
255
256 if (p->pre_handler && p->pre_handler(p, regs)) {
257 /* Handler has already set things up, so skip ss setup. */
258 return 1;
259 }
260
261ss_probe:
262 prepare_singlestep(p, regs);
263 kcb->kprobe_status = KPROBE_HIT_SS;
264 return 1;
265
266no_kprobe:
267 preempt_enable_no_resched();
268 return ret;
269}
270
271/*
272 * Called after single-stepping. p->addr is the address of the
273 * instruction that has been replaced by the breakpoint. To avoid the
274 * SMP problems that can occur when we temporarily put back the
275 * original opcode to single-step, we single-stepped a copy of the
276 * instruction. The address of this copy is p->ainsn.insn.
277 *
278 * This function prepares to return from the post-single-step
279 * breakpoint trap.
280 */
281static void __kprobes resume_execution(struct kprobe *p,
282 struct pt_regs *regs,
283 struct kprobe_ctlblk *kcb)
284{
285 unsigned long orig_pc = kcb->kprobe_saved_pc;
286 regs->pc = orig_pc + 8;
287}
288
289static inline int post_kprobe_handler(struct pt_regs *regs)
290{
291 struct kprobe *cur = kprobe_running();
292 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
293
294 if (!cur)
295 return 0;
296
297 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
298 kcb->kprobe_status = KPROBE_HIT_SSDONE;
299 cur->post_handler(cur, regs, 0);
300 }
301
302 resume_execution(cur, regs, kcb);
303
304 /* Restore back the original saved kprobes variables and continue. */
305 if (kcb->kprobe_status == KPROBE_REENTER) {
306 restore_previous_kprobe(kcb);
307 goto out;
308 }
309 reset_current_kprobe();
310out:
311 preempt_enable_no_resched();
312
313 return 1;
314}
315
316static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
317{
318 struct kprobe *cur = kprobe_running();
319 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
320
321 if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
322 return 1;
323
324 if (kcb->kprobe_status & KPROBE_HIT_SS) {
325 /*
326 * We are here because the instruction being single
327 * stepped caused a page fault. We reset the current
328 * kprobe and the ip points back to the probe address
329 * and allow the page fault handler to continue as a
330 * normal page fault.
331 */
332 resume_execution(cur, regs, kcb);
333 reset_current_kprobe();
334 preempt_enable_no_resched();
335 }
336 return 0;
337}
338
339/*
340 * Wrapper routine for handling exceptions.
341 */
342int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
343 unsigned long val, void *data)
344{
345 struct die_args *args = (struct die_args *)data;
346 int ret = NOTIFY_DONE;
347
348 switch (val) {
349 case DIE_BREAK:
350 if (kprobe_handler(args->regs))
351 ret = NOTIFY_STOP;
352 break;
353 case DIE_SSTEPBP:
354 if (post_kprobe_handler(args->regs))
355 ret = NOTIFY_STOP;
356 break;
357 case DIE_PAGE_FAULT:
358 /* kprobe_running() needs smp_processor_id(). */
359 preempt_disable();
360
361 if (kprobe_running()
362 && kprobe_fault_handler(args->regs, args->trapnr))
363 ret = NOTIFY_STOP;
364 preempt_enable();
365 break;
366 default:
367 break;
368 }
369 return ret;
370}
371
372int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
373{
374 struct jprobe *jp = container_of(p, struct jprobe, kp);
375 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
376
377 kcb->jprobe_saved_regs = *regs;
378 kcb->jprobe_saved_sp = regs->sp;
379
380 memcpy(kcb->jprobes_stack, (void *)kcb->jprobe_saved_sp,
381 MIN_JPROBES_STACK_SIZE(kcb->jprobe_saved_sp));
382
383 regs->pc = (unsigned long)(jp->entry);
384
385 return 1;
386}
387
388/* Defined in the inline asm below. */
389void jprobe_return_end(void);
390
391void __kprobes jprobe_return(void)
392{
393 asm volatile(
394 "bpt\n\t"
395 ".globl jprobe_return_end\n"
396 "jprobe_return_end:\n");
397}
398
399int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
400{
401 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
402
403 if (regs->pc >= (unsigned long)jprobe_return &&
404 regs->pc <= (unsigned long)jprobe_return_end) {
405 *regs = kcb->jprobe_saved_regs;
406 memcpy((void *)kcb->jprobe_saved_sp, kcb->jprobes_stack,
407 MIN_JPROBES_STACK_SIZE(kcb->jprobe_saved_sp));
408 preempt_enable_no_resched();
409
410 return 1;
411 }
412 return 0;
413}
414
415/*
416 * Function return probe trampoline:
417 * - init_kprobes() establishes a probepoint here
418 * - When the probed function returns, this probe causes the
419 * handlers to fire
420 */
421static void __used kretprobe_trampoline_holder(void)
422{
423 asm volatile(
424 "nop\n\t"
425 ".global kretprobe_trampoline\n"
426 "kretprobe_trampoline:\n\t"
427 "nop\n\t"
428 : : : "memory");
429}
430
431void kretprobe_trampoline(void);
432
433void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
434 struct pt_regs *regs)
435{
436 ri->ret_addr = (kprobe_opcode_t *) regs->lr;
437
438 /* Replace the return addr with trampoline addr */
439 regs->lr = (unsigned long)kretprobe_trampoline;
440}
441
442/*
443 * Called when the probe at kretprobe trampoline is hit.
444 */
445static int __kprobes trampoline_probe_handler(struct kprobe *p,
446 struct pt_regs *regs)
447{
448 struct kretprobe_instance *ri = NULL;
449 struct hlist_head *head, empty_rp;
450 struct hlist_node *tmp;
451 unsigned long flags, orig_ret_address = 0;
452 unsigned long trampoline_address = (unsigned long)kretprobe_trampoline;
453
454 INIT_HLIST_HEAD(&empty_rp);
455 kretprobe_hash_lock(current, &head, &flags);
456
457 /*
458 * It is possible to have multiple instances associated with a given
459 * task either because multiple functions in the call path have
460 * a return probe installed on them, and/or more than one return
461 * return probe was registered for a target function.
462 *
463 * We can handle this because:
464 * - instances are always inserted at the head of the list
465 * - when multiple return probes are registered for the same
466 * function, the first instance's ret_addr will point to the
467 * real return address, and all the rest will point to
468 * kretprobe_trampoline
469 */
470 hlist_for_each_entry_safe(ri, tmp, head, hlist) {
471 if (ri->task != current)
472 /* another task is sharing our hash bucket */
473 continue;
474
475 if (ri->rp && ri->rp->handler)
476 ri->rp->handler(ri, regs);
477
478 orig_ret_address = (unsigned long)ri->ret_addr;
479 recycle_rp_inst(ri, &empty_rp);
480
481 if (orig_ret_address != trampoline_address) {
482 /*
483 * This is the real return address. Any other
484 * instances associated with this task are for
485 * other calls deeper on the call stack
486 */
487 break;
488 }
489 }
490
491 kretprobe_assert(ri, orig_ret_address, trampoline_address);
492 instruction_pointer(regs) = orig_ret_address;
493
494 reset_current_kprobe();
495 kretprobe_hash_unlock(current, &flags);
496 preempt_enable_no_resched();
497
498 hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
499 hlist_del(&ri->hlist);
500 kfree(ri);
501 }
502 /*
503 * By returning a non-zero value, we are telling
504 * kprobe_handler() that we don't want the post_handler
505 * to run (and have re-enabled preemption)
506 */
507 return 1;
508}
509
510int __kprobes arch_trampoline_kprobe(struct kprobe *p)
511{
512 if (p->addr == (kprobe_opcode_t *)kretprobe_trampoline)
513 return 1;
514
515 return 0;
516}
517
518static struct kprobe trampoline_p = {
519 .addr = (kprobe_opcode_t *)kretprobe_trampoline,
520 .pre_handler = trampoline_probe_handler
521};
522
523int __init arch_init_kprobes(void)
524{
525 register_kprobe(&trampoline_p);
526 return 0;
527}
diff --git a/arch/tile/kernel/machine_kexec.c b/arch/tile/kernel/machine_kexec.c
deleted file mode 100644
index 008aa2faef55..000000000000
--- a/arch/tile/kernel/machine_kexec.c
+++ /dev/null
@@ -1,298 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * based on machine_kexec.c from other architectures in linux-2.6.18
15 */
16
17#include <linux/mm.h>
18#include <linux/kexec.h>
19#include <linux/delay.h>
20#include <linux/reboot.h>
21#include <linux/errno.h>
22#include <linux/vmalloc.h>
23#include <linux/cpumask.h>
24#include <linux/kernel.h>
25#include <linux/elf.h>
26#include <linux/highmem.h>
27#include <linux/mmu_context.h>
28#include <linux/io.h>
29#include <linux/timex.h>
30#include <asm/pgtable.h>
31#include <asm/pgalloc.h>
32#include <asm/cacheflush.h>
33#include <asm/checksum.h>
34#include <asm/tlbflush.h>
35#include <asm/homecache.h>
36#include <hv/hypervisor.h>
37
38
39/*
40 * This stuff is not in elf.h and is not in any other kernel include.
41 * This stuff is needed below in the little boot notes parser to
42 * extract the command line so we can pass it to the hypervisor.
43 */
44struct Elf32_Bhdr {
45 Elf32_Word b_signature;
46 Elf32_Word b_size;
47 Elf32_Half b_checksum;
48 Elf32_Half b_records;
49};
50#define ELF_BOOT_MAGIC 0x0E1FB007
51#define EBN_COMMAND_LINE 0x00000004
52#define roundupsz(X) (((X) + 3) & ~3)
53
54/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
55
56
57void machine_shutdown(void)
58{
59 /*
60 * Normally we would stop all the other processors here, but
61 * the check in machine_kexec_prepare below ensures we'll only
62 * get this far if we've been booted with "nosmp" on the
63 * command line or without CONFIG_SMP so there's nothing to do
64 * here (for now).
65 */
66}
67
68void machine_crash_shutdown(struct pt_regs *regs)
69{
70 /*
71 * Cannot happen. This type of kexec is disabled on this
72 * architecture (and enforced in machine_kexec_prepare below).
73 */
74}
75
76
77int machine_kexec_prepare(struct kimage *image)
78{
79 if (num_online_cpus() > 1) {
80 pr_warn("%s: detected attempt to kexec with num_online_cpus() > 1\n",
81 __func__);
82 return -ENOSYS;
83 }
84 if (image->type != KEXEC_TYPE_DEFAULT) {
85 pr_warn("%s: detected attempt to kexec with unsupported type: %d\n",
86 __func__, image->type);
87 return -ENOSYS;
88 }
89 return 0;
90}
91
92void machine_kexec_cleanup(struct kimage *image)
93{
94 /*
95 * We did nothing in machine_kexec_prepare,
96 * so we have nothing to do here.
97 */
98}
99
100/*
101 * If we can find elf boot notes on this page, return the command
102 * line. Otherwise, silently return null. Somewhat kludgy, but no
103 * good way to do this without significantly rearchitecting the
104 * architecture-independent kexec code.
105 */
106
107static unsigned char *kexec_bn2cl(void *pg)
108{
109 struct Elf32_Bhdr *bhdrp;
110 Elf32_Nhdr *nhdrp;
111 unsigned char *desc;
112 unsigned char *command_line;
113 __sum16 csum;
114
115 bhdrp = (struct Elf32_Bhdr *) pg;
116
117 /*
118 * This routine is invoked for every source page, so make
119 * sure to quietly ignore every impossible page.
120 */
121 if (bhdrp->b_signature != ELF_BOOT_MAGIC ||
122 bhdrp->b_size > PAGE_SIZE)
123 return 0;
124
125 /*
126 * If we get a checksum mismatch, warn with the checksum
127 * so we can diagnose better.
128 */
129 csum = ip_compute_csum(pg, bhdrp->b_size);
130 if (csum != 0) {
131 pr_warn("%s: bad checksum %#x (size %d)\n",
132 __func__, csum, bhdrp->b_size);
133 return 0;
134 }
135
136 nhdrp = (Elf32_Nhdr *) (bhdrp + 1);
137
138 while (nhdrp->n_type != EBN_COMMAND_LINE) {
139
140 desc = (unsigned char *) (nhdrp + 1);
141 desc += roundupsz(nhdrp->n_descsz);
142
143 nhdrp = (Elf32_Nhdr *) desc;
144
145 /* still in bounds? */
146 if ((unsigned char *) (nhdrp + 1) >
147 ((unsigned char *) pg) + bhdrp->b_size) {
148
149 pr_info("%s: out of bounds\n", __func__);
150 return 0;
151 }
152 }
153
154 command_line = (unsigned char *) (nhdrp + 1);
155 desc = command_line;
156
157 while (*desc != '\0') {
158 desc++;
159 if (((unsigned long)desc & PAGE_MASK) != (unsigned long)pg) {
160 pr_info("%s: ran off end of page\n", __func__);
161 return 0;
162 }
163 }
164
165 return command_line;
166}
167
168static void kexec_find_and_set_command_line(struct kimage *image)
169{
170 kimage_entry_t *ptr, entry;
171
172 unsigned char *command_line = 0;
173 unsigned char *r;
174 HV_Errno hverr;
175
176 for (ptr = &image->head;
177 (entry = *ptr) && !(entry & IND_DONE);
178 ptr = (entry & IND_INDIRECTION) ?
179 phys_to_virt((entry & PAGE_MASK)) : ptr + 1) {
180
181 if ((entry & IND_SOURCE)) {
182 void *va =
183 kmap_atomic_pfn(entry >> PAGE_SHIFT);
184 r = kexec_bn2cl(va);
185 if (r) {
186 command_line = r;
187 break;
188 }
189 kunmap_atomic(va);
190 }
191 }
192
193 if (command_line != 0) {
194 pr_info("setting new command line to \"%s\"\n", command_line);
195
196 hverr = hv_set_command_line(
197 (HV_VirtAddr) command_line, strlen(command_line));
198 kunmap_atomic(command_line);
199 } else {
200 pr_info("%s: no command line found; making empty\n", __func__);
201 hverr = hv_set_command_line((HV_VirtAddr) command_line, 0);
202 }
203 if (hverr)
204 pr_warn("%s: hv_set_command_line returned error: %d\n",
205 __func__, hverr);
206}
207
208/*
209 * The kexec code range-checks all its PAs, so to avoid having it run
210 * amok and allocate memory and then sequester it from every other
211 * controller, we force it to come from controller zero. We also
212 * disable the oom-killer since if we do end up running out of memory,
213 * that almost certainly won't help.
214 */
215struct page *kimage_alloc_pages_arch(gfp_t gfp_mask, unsigned int order)
216{
217 gfp_mask |= __GFP_THISNODE | __GFP_NORETRY;
218 return alloc_pages_node(0, gfp_mask, order);
219}
220
221/*
222 * Address range in which pa=va mapping is set in setup_quasi_va_is_pa().
223 * For tilepro, PAGE_OFFSET is used since this is the largest possbile value
224 * for tilepro, while for tilegx, we limit it to entire middle level page
225 * table which we assume has been allocated and is undoubtedly large enough.
226 */
227#ifndef __tilegx__
228#define QUASI_VA_IS_PA_ADDR_RANGE PAGE_OFFSET
229#else
230#define QUASI_VA_IS_PA_ADDR_RANGE PGDIR_SIZE
231#endif
232
233static void setup_quasi_va_is_pa(void)
234{
235 HV_PTE pte;
236 unsigned long i;
237
238 /*
239 * Flush our TLB to prevent conflicts between the previous contents
240 * and the new stuff we're about to add.
241 */
242 local_flush_tlb_all();
243
244 /*
245 * setup VA is PA, at least up to QUASI_VA_IS_PA_ADDR_RANGE.
246 * Note here we assume that level-1 page table is defined by
247 * HPAGE_SIZE.
248 */
249 pte = hv_pte(_PAGE_KERNEL | _PAGE_HUGE_PAGE);
250 pte = hv_pte_set_mode(pte, HV_PTE_MODE_CACHE_NO_L3);
251 for (i = 0; i < (QUASI_VA_IS_PA_ADDR_RANGE >> HPAGE_SHIFT); i++) {
252 unsigned long vaddr = i << HPAGE_SHIFT;
253 pgd_t *pgd = pgd_offset(current->mm, vaddr);
254 pud_t *pud = pud_offset(pgd, vaddr);
255 pte_t *ptep = (pte_t *) pmd_offset(pud, vaddr);
256 unsigned long pfn = i << (HPAGE_SHIFT - PAGE_SHIFT);
257
258 if (pfn_valid(pfn))
259 __set_pte(ptep, pfn_pte(pfn, pte));
260 }
261}
262
263
264void machine_kexec(struct kimage *image)
265{
266 void *reboot_code_buffer;
267 pte_t *ptep;
268 void (*rnk)(unsigned long, void *, unsigned long)
269 __noreturn;
270
271 /* Mask all interrupts before starting to reboot. */
272 interrupt_mask_set_mask(~0ULL);
273
274 kexec_find_and_set_command_line(image);
275
276 /*
277 * Adjust the home caching of the control page to be cached on
278 * this cpu, and copy the assembly helper into the control
279 * code page, which we map in the vmalloc area.
280 */
281 homecache_change_page_home(image->control_code_page, 0,
282 smp_processor_id());
283 reboot_code_buffer = page_address(image->control_code_page);
284 BUG_ON(reboot_code_buffer == NULL);
285 ptep = virt_to_pte(NULL, (unsigned long)reboot_code_buffer);
286 __set_pte(ptep, pte_mkexec(*ptep));
287 memcpy(reboot_code_buffer, relocate_new_kernel,
288 relocate_new_kernel_size);
289 __flush_icache_range(
290 (unsigned long) reboot_code_buffer,
291 (unsigned long) reboot_code_buffer + relocate_new_kernel_size);
292
293 setup_quasi_va_is_pa();
294
295 /* now call it */
296 rnk = reboot_code_buffer;
297 (*rnk)(image->head, reboot_code_buffer, image->start);
298}
diff --git a/arch/tile/kernel/mcount_64.S b/arch/tile/kernel/mcount_64.S
deleted file mode 100644
index 6c6702451962..000000000000
--- a/arch/tile/kernel/mcount_64.S
+++ /dev/null
@@ -1,211 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE-Gx specific __mcount support
15 */
16
17#include <linux/linkage.h>
18#include <asm/ftrace.h>
19
20#define REGSIZE 8
21
22 .text
23 .global __mcount
24
25 .macro MCOUNT_SAVE_REGS
26 addli sp, sp, -REGSIZE
27 {
28 st sp, lr
29 addli r29, sp, - (12 * REGSIZE)
30 }
31 {
32 addli sp, sp, - (13 * REGSIZE)
33 st r29, sp
34 }
35 addli r29, r29, REGSIZE
36 { st r29, r0; addli r29, r29, REGSIZE }
37 { st r29, r1; addli r29, r29, REGSIZE }
38 { st r29, r2; addli r29, r29, REGSIZE }
39 { st r29, r3; addli r29, r29, REGSIZE }
40 { st r29, r4; addli r29, r29, REGSIZE }
41 { st r29, r5; addli r29, r29, REGSIZE }
42 { st r29, r6; addli r29, r29, REGSIZE }
43 { st r29, r7; addli r29, r29, REGSIZE }
44 { st r29, r8; addli r29, r29, REGSIZE }
45 { st r29, r9; addli r29, r29, REGSIZE }
46 { st r29, r10; addli r29, r29, REGSIZE }
47 .endm
48
49 .macro MCOUNT_RESTORE_REGS
50 addli r29, sp, (2 * REGSIZE)
51 { ld r0, r29; addli r29, r29, REGSIZE }
52 { ld r1, r29; addli r29, r29, REGSIZE }
53 { ld r2, r29; addli r29, r29, REGSIZE }
54 { ld r3, r29; addli r29, r29, REGSIZE }
55 { ld r4, r29; addli r29, r29, REGSIZE }
56 { ld r5, r29; addli r29, r29, REGSIZE }
57 { ld r6, r29; addli r29, r29, REGSIZE }
58 { ld r7, r29; addli r29, r29, REGSIZE }
59 { ld r8, r29; addli r29, r29, REGSIZE }
60 { ld r9, r29; addli r29, r29, REGSIZE }
61 { ld r10, r29; addli lr, sp, (13 * REGSIZE) }
62 { ld lr, lr; addli sp, sp, (14 * REGSIZE) }
63 .endm
64
65 .macro RETURN_BACK
66 { move r12, lr; move lr, r10 }
67 jrp r12
68 .endm
69
70#ifdef CONFIG_DYNAMIC_FTRACE
71
72 .align 64
73STD_ENTRY(__mcount)
74__mcount:
75 j ftrace_stub
76STD_ENDPROC(__mcount)
77
78 .align 64
79STD_ENTRY(ftrace_caller)
80 MCOUNT_SAVE_REGS
81
82 /* arg1: self return address */
83 /* arg2: parent's return address */
84 /* arg3: ftrace_ops */
85 /* arg4: regs (but make it NULL) */
86 { move r0, lr; moveli r2, hw2_last(function_trace_op) }
87 { move r1, r10; shl16insli r2, r2, hw1(function_trace_op) }
88 { movei r3, 0; shl16insli r2, r2, hw0(function_trace_op) }
89 ld r2,r2
90
91 .global ftrace_call
92ftrace_call:
93 /*
94 * a placeholder for the call to a real tracing function, i.e.
95 * ftrace_trace_function()
96 */
97 nop
98
99#ifdef CONFIG_FUNCTION_GRAPH_TRACER
100 .global ftrace_graph_call
101ftrace_graph_call:
102 /*
103 * a placeholder for the call to a real tracing function, i.e.
104 * ftrace_graph_caller()
105 */
106 nop
107#endif
108 MCOUNT_RESTORE_REGS
109 .global ftrace_stub
110ftrace_stub:
111 RETURN_BACK
112STD_ENDPROC(ftrace_caller)
113
114#else /* ! CONFIG_DYNAMIC_FTRACE */
115
116 .align 64
117STD_ENTRY(__mcount)
118 {
119 moveli r11, hw2_last(ftrace_trace_function)
120 moveli r13, hw2_last(ftrace_stub)
121 }
122 {
123 shl16insli r11, r11, hw1(ftrace_trace_function)
124 shl16insli r13, r13, hw1(ftrace_stub)
125 }
126 {
127 shl16insli r11, r11, hw0(ftrace_trace_function)
128 shl16insli r13, r13, hw0(ftrace_stub)
129 }
130
131 ld r11, r11
132 sub r14, r13, r11
133 bnez r14, static_trace
134
135#ifdef CONFIG_FUNCTION_GRAPH_TRACER
136 moveli r15, hw2_last(ftrace_graph_return)
137 shl16insli r15, r15, hw1(ftrace_graph_return)
138 shl16insli r15, r15, hw0(ftrace_graph_return)
139 ld r15, r15
140 sub r15, r15, r13
141 bnez r15, ftrace_graph_caller
142
143 {
144 moveli r16, hw2_last(ftrace_graph_entry)
145 moveli r17, hw2_last(ftrace_graph_entry_stub)
146 }
147 {
148 shl16insli r16, r16, hw1(ftrace_graph_entry)
149 shl16insli r17, r17, hw1(ftrace_graph_entry_stub)
150 }
151 {
152 shl16insli r16, r16, hw0(ftrace_graph_entry)
153 shl16insli r17, r17, hw0(ftrace_graph_entry_stub)
154 }
155 ld r16, r16
156 sub r17, r16, r17
157 bnez r17, ftrace_graph_caller
158
159#endif
160 RETURN_BACK
161
162static_trace:
163 MCOUNT_SAVE_REGS
164
165 /* arg1: self return address */
166 /* arg2: parent's return address */
167 { move r0, lr; move r1, r10 }
168
169 /* call ftrace_trace_function() */
170 jalr r11
171
172 MCOUNT_RESTORE_REGS
173
174 .global ftrace_stub
175ftrace_stub:
176 RETURN_BACK
177STD_ENDPROC(__mcount)
178
179#endif /* ! CONFIG_DYNAMIC_FTRACE */
180
181#ifdef CONFIG_FUNCTION_GRAPH_TRACER
182
183STD_ENTRY(ftrace_graph_caller)
184ftrace_graph_caller:
185#ifndef CONFIG_DYNAMIC_FTRACE
186 MCOUNT_SAVE_REGS
187#endif
188
189 /* arg1: Get the location of the parent's return address */
190 addi r0, sp, 12 * REGSIZE
191 /* arg2: Get self return address */
192 move r1, lr
193
194 jal prepare_ftrace_return
195
196 MCOUNT_RESTORE_REGS
197 RETURN_BACK
198STD_ENDPROC(ftrace_graph_caller)
199
200 .global return_to_handler
201return_to_handler:
202 MCOUNT_SAVE_REGS
203
204 jal ftrace_return_to_handler
205 /* restore the real parent address */
206 move r11, r0
207
208 MCOUNT_RESTORE_REGS
209 jr r11
210
211#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
diff --git a/arch/tile/kernel/messaging.c b/arch/tile/kernel/messaging.c
deleted file mode 100644
index 7475af3aacec..000000000000
--- a/arch/tile/kernel/messaging.c
+++ /dev/null
@@ -1,115 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/percpu.h>
16#include <linux/smp.h>
17#include <linux/hardirq.h>
18#include <linux/ptrace.h>
19#include <asm/hv_driver.h>
20#include <asm/irq_regs.h>
21#include <asm/traps.h>
22#include <hv/hypervisor.h>
23#include <arch/interrupts.h>
24
25/* All messages are stored here */
26static DEFINE_PER_CPU(HV_MsgState, msg_state);
27
28void init_messaging(void)
29{
30 /* Allocate storage for messages in kernel space */
31 HV_MsgState *state = this_cpu_ptr(&msg_state);
32 int rc = hv_register_message_state(state);
33 if (rc != HV_OK)
34 panic("hv_register_message_state: error %d", rc);
35
36 /* Make sure downcall interrupts will be enabled. */
37 arch_local_irq_unmask(INT_INTCTRL_K);
38}
39
40void hv_message_intr(struct pt_regs *regs, int intnum)
41{
42 /*
43 * We enter with interrupts disabled and leave them disabled,
44 * to match expectations of called functions (e.g.
45 * do_ccupdate_local() in mm/slab.c). This is also consistent
46 * with normal call entry for device interrupts.
47 */
48
49 int message[HV_MAX_MESSAGE_SIZE/sizeof(int)];
50 HV_RcvMsgInfo rmi;
51 int nmsgs = 0;
52
53 /* Track time spent here in an interrupt context */
54 struct pt_regs *old_regs = set_irq_regs(regs);
55 irq_enter();
56
57#ifdef CONFIG_DEBUG_STACKOVERFLOW
58 /* Debugging check for stack overflow: less than 1/8th stack free? */
59 {
60 long sp = stack_pointer - (long) current_thread_info();
61 if (unlikely(sp < (sizeof(struct thread_info) + STACK_WARN))) {
62 pr_emerg("%s: stack overflow: %ld\n",
63 __func__, sp - sizeof(struct thread_info));
64 dump_stack();
65 }
66 }
67#endif
68
69 while (1) {
70 HV_MsgState *state = this_cpu_ptr(&msg_state);
71 rmi = hv_receive_message(*state, (HV_VirtAddr) message,
72 sizeof(message));
73 if (rmi.msglen == 0)
74 break;
75
76 if (rmi.msglen < 0)
77 panic("hv_receive_message failed: %d", rmi.msglen);
78
79 ++nmsgs;
80
81 if (rmi.source == HV_MSG_TILE) {
82 int tag;
83
84 /* we just send tags for now */
85 BUG_ON(rmi.msglen != sizeof(int));
86
87 tag = message[0];
88#ifdef CONFIG_SMP
89 evaluate_message(message[0]);
90#else
91 panic("Received IPI message %d in UP mode", tag);
92#endif
93 } else if (rmi.source == HV_MSG_INTR) {
94 HV_IntrMsg *him = (HV_IntrMsg *)message;
95 struct hv_driver_cb *cb =
96 (struct hv_driver_cb *)him->intarg;
97 cb->callback(cb, him->intdata);
98 __this_cpu_inc(irq_stat.irq_hv_msg_count);
99 }
100 }
101
102 /*
103 * We shouldn't have gotten a message downcall with no
104 * messages available.
105 */
106 if (nmsgs == 0)
107 panic("Message downcall invoked with no messages!");
108
109 /*
110 * Track time spent against the current process again and
111 * process any softirqs if they are waiting.
112 */
113 irq_exit();
114 set_irq_regs(old_regs);
115}
diff --git a/arch/tile/kernel/module.c b/arch/tile/kernel/module.c
deleted file mode 100644
index 09233fbe7801..000000000000
--- a/arch/tile/kernel/module.c
+++ /dev/null
@@ -1,231 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Based on i386 version, copyright (C) 2001 Rusty Russell.
15 */
16
17#include <linux/moduleloader.h>
18#include <linux/elf.h>
19#include <linux/vmalloc.h>
20#include <linux/fs.h>
21#include <linux/string.h>
22#include <linux/kernel.h>
23#include <asm/pgtable.h>
24#include <asm/homecache.h>
25#include <arch/opcode.h>
26
27#ifdef MODULE_DEBUG
28#define DEBUGP printk
29#else
30#define DEBUGP(fmt...)
31#endif
32
33/*
34 * Allocate some address space in the range MEM_MODULE_START to
35 * MEM_MODULE_END and populate it with memory.
36 */
37void *module_alloc(unsigned long size)
38{
39 struct page **pages;
40 pgprot_t prot_rwx = __pgprot(_PAGE_KERNEL | _PAGE_KERNEL_EXEC);
41 struct vm_struct *area;
42 int i = 0;
43 int npages;
44
45 npages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
46 pages = kmalloc_array(npages, sizeof(*pages), GFP_KERNEL);
47 if (pages == NULL)
48 return NULL;
49 for (; i < npages; ++i) {
50 pages[i] = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
51 if (!pages[i])
52 goto free_pages;
53 }
54
55 area = __get_vm_area(size, VM_ALLOC, MEM_MODULE_START, MEM_MODULE_END);
56 if (!area)
57 goto free_pages;
58 area->nr_pages = npages;
59 area->pages = pages;
60
61 if (map_vm_area(area, prot_rwx, pages)) {
62 vunmap(area->addr);
63 goto free_pages;
64 }
65
66 return area->addr;
67 free_pages:
68 while (--i >= 0)
69 __free_page(pages[i]);
70 kfree(pages);
71 return NULL;
72}
73
74
75/* Free memory returned from module_alloc */
76void module_memfree(void *module_region)
77{
78 vfree(module_region);
79
80 /* Globally flush the L1 icache. */
81 flush_remote(0, HV_FLUSH_EVICT_L1I, cpu_online_mask,
82 0, 0, 0, NULL, NULL, 0);
83
84 /*
85 * FIXME: Add module_arch_freeing_init to trim exception
86 * table entries.
87 */
88}
89
90#ifdef __tilegx__
91/*
92 * Validate that the high 16 bits of "value" is just the sign-extension of
93 * the low 48 bits.
94 */
95static int validate_hw2_last(long value, struct module *me)
96{
97 if (((value << 16) >> 16) != value) {
98 pr_warn("module %s: Out of range HW2_LAST value %#lx\n",
99 me->name, value);
100 return 0;
101 }
102 return 1;
103}
104
105/*
106 * Validate that "value" isn't too big to hold in a JumpOff relocation.
107 */
108static int validate_jumpoff(long value)
109{
110 /* Determine size of jump offset. */
111 int shift = __builtin_clzl(get_JumpOff_X1(create_JumpOff_X1(-1)));
112
113 /* Check to see if it fits into the relocation slot. */
114 long f = get_JumpOff_X1(create_JumpOff_X1(value));
115 f = (f << shift) >> shift;
116
117 return f == value;
118}
119#endif
120
121int apply_relocate_add(Elf_Shdr *sechdrs,
122 const char *strtab,
123 unsigned int symindex,
124 unsigned int relsec,
125 struct module *me)
126{
127 unsigned int i;
128 Elf_Rela *rel = (void *)sechdrs[relsec].sh_addr;
129 Elf_Sym *sym;
130 u64 *location;
131 unsigned long value;
132
133 DEBUGP("Applying relocate section %u to %u\n", relsec,
134 sechdrs[relsec].sh_info);
135 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
136 /* This is where to make the change */
137 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
138 + rel[i].r_offset;
139 /*
140 * This is the symbol it is referring to.
141 * Note that all undefined symbols have been resolved.
142 */
143 sym = (Elf_Sym *)sechdrs[symindex].sh_addr
144 + ELF_R_SYM(rel[i].r_info);
145 value = sym->st_value + rel[i].r_addend;
146
147 switch (ELF_R_TYPE(rel[i].r_info)) {
148
149#ifdef __LITTLE_ENDIAN
150# define MUNGE(func) \
151 (*location = ((*location & ~func(-1)) | func(value)))
152#else
153/*
154 * Instructions are always little-endian, so when we read them as data,
155 * we have to swap them around before and after modifying them.
156 */
157# define MUNGE(func) \
158 (*location = swab64((swab64(*location) & ~func(-1)) | func(value)))
159#endif
160
161#ifndef __tilegx__
162 case R_TILE_32:
163 *(uint32_t *)location = value;
164 break;
165 case R_TILE_IMM16_X0_HA:
166 value = (value + 0x8000) >> 16;
167 /*FALLTHROUGH*/
168 case R_TILE_IMM16_X0_LO:
169 MUNGE(create_Imm16_X0);
170 break;
171 case R_TILE_IMM16_X1_HA:
172 value = (value + 0x8000) >> 16;
173 /*FALLTHROUGH*/
174 case R_TILE_IMM16_X1_LO:
175 MUNGE(create_Imm16_X1);
176 break;
177 case R_TILE_JOFFLONG_X1:
178 value -= (unsigned long) location; /* pc-relative */
179 value = (long) value >> 3; /* count by instrs */
180 MUNGE(create_JOffLong_X1);
181 break;
182#else
183 case R_TILEGX_64:
184 *location = value;
185 break;
186 case R_TILEGX_IMM16_X0_HW2_LAST:
187 if (!validate_hw2_last(value, me))
188 return -ENOEXEC;
189 value >>= 16;
190 /*FALLTHROUGH*/
191 case R_TILEGX_IMM16_X0_HW1:
192 value >>= 16;
193 /*FALLTHROUGH*/
194 case R_TILEGX_IMM16_X0_HW0:
195 MUNGE(create_Imm16_X0);
196 break;
197 case R_TILEGX_IMM16_X1_HW2_LAST:
198 if (!validate_hw2_last(value, me))
199 return -ENOEXEC;
200 value >>= 16;
201 /*FALLTHROUGH*/
202 case R_TILEGX_IMM16_X1_HW1:
203 value >>= 16;
204 /*FALLTHROUGH*/
205 case R_TILEGX_IMM16_X1_HW0:
206 MUNGE(create_Imm16_X1);
207 break;
208 case R_TILEGX_JUMPOFF_X1:
209 value -= (unsigned long) location; /* pc-relative */
210 value = (long) value >> 3; /* count by instrs */
211 if (!validate_jumpoff(value)) {
212 pr_warn("module %s: Out of range jump to %#llx at %#llx (%p)\n",
213 me->name,
214 sym->st_value + rel[i].r_addend,
215 rel[i].r_offset, location);
216 return -ENOEXEC;
217 }
218 MUNGE(create_JumpOff_X1);
219 break;
220#endif
221
222#undef MUNGE
223
224 default:
225 pr_err("module %s: Unknown relocation: %d\n",
226 me->name, (int) ELF_R_TYPE(rel[i].r_info));
227 return -ENOEXEC;
228 }
229 }
230 return 0;
231}
diff --git a/arch/tile/kernel/pci-dma.c b/arch/tile/kernel/pci-dma.c
deleted file mode 100644
index 6a1efe5543fa..000000000000
--- a/arch/tile/kernel/pci-dma.c
+++ /dev/null
@@ -1,607 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/mm.h>
16#include <linux/dma-mapping.h>
17#include <linux/swiotlb.h>
18#include <linux/vmalloc.h>
19#include <linux/export.h>
20#include <asm/tlbflush.h>
21#include <asm/homecache.h>
22
23/* Generic DMA mapping functions: */
24
25/*
26 * Allocate what Linux calls "coherent" memory. On TILEPro this is
27 * uncached memory; on TILE-Gx it is hash-for-home memory.
28 */
29#ifdef __tilepro__
30#define PAGE_HOME_DMA PAGE_HOME_UNCACHED
31#else
32#define PAGE_HOME_DMA PAGE_HOME_HASH
33#endif
34
35static void *tile_dma_alloc_coherent(struct device *dev, size_t size,
36 dma_addr_t *dma_handle, gfp_t gfp,
37 unsigned long attrs)
38{
39 u64 dma_mask = (dev && dev->coherent_dma_mask) ?
40 dev->coherent_dma_mask : DMA_BIT_MASK(32);
41 int node = dev ? dev_to_node(dev) : 0;
42 int order = get_order(size);
43 struct page *pg;
44 dma_addr_t addr;
45
46 gfp |= __GFP_ZERO;
47
48 /*
49 * If the mask specifies that the memory be in the first 4 GB, then
50 * we force the allocation to come from the DMA zone. We also
51 * force the node to 0 since that's the only node where the DMA
52 * zone isn't empty. If the mask size is smaller than 32 bits, we
53 * may still not be able to guarantee a suitable memory address, in
54 * which case we will return NULL. But such devices are uncommon.
55 */
56 if (dma_mask <= DMA_BIT_MASK(32)) {
57 gfp |= GFP_DMA32;
58 node = 0;
59 }
60
61 pg = homecache_alloc_pages_node(node, gfp, order, PAGE_HOME_DMA);
62 if (pg == NULL)
63 return NULL;
64
65 addr = page_to_phys(pg);
66 if (addr + size > dma_mask) {
67 __homecache_free_pages(pg, order);
68 return NULL;
69 }
70
71 *dma_handle = addr;
72
73 return page_address(pg);
74}
75
76/*
77 * Free memory that was allocated with tile_dma_alloc_coherent.
78 */
79static void tile_dma_free_coherent(struct device *dev, size_t size,
80 void *vaddr, dma_addr_t dma_handle,
81 unsigned long attrs)
82{
83 homecache_free_pages((unsigned long)vaddr, get_order(size));
84}
85
86/*
87 * The map routines "map" the specified address range for DMA
88 * accesses. The memory belongs to the device after this call is
89 * issued, until it is unmapped with dma_unmap_single.
90 *
91 * We don't need to do any mapping, we just flush the address range
92 * out of the cache and return a DMA address.
93 *
94 * The unmap routines do whatever is necessary before the processor
95 * accesses the memory again, and must be called before the driver
96 * touches the memory. We can get away with a cache invalidate if we
97 * can count on nothing having been touched.
98 */
99
100/* Set up a single page for DMA access. */
101static void __dma_prep_page(struct page *page, unsigned long offset,
102 size_t size, enum dma_data_direction direction)
103{
104 /*
105 * Flush the page from cache if necessary.
106 * On tilegx, data is delivered to hash-for-home L3; on tilepro,
107 * data is delivered direct to memory.
108 *
109 * NOTE: If we were just doing DMA_TO_DEVICE we could optimize
110 * this to be a "flush" not a "finv" and keep some of the
111 * state in cache across the DMA operation, but it doesn't seem
112 * worth creating the necessary flush_buffer_xxx() infrastructure.
113 */
114 int home = page_home(page);
115 switch (home) {
116 case PAGE_HOME_HASH:
117#ifdef __tilegx__
118 return;
119#endif
120 break;
121 case PAGE_HOME_UNCACHED:
122#ifdef __tilepro__
123 return;
124#endif
125 break;
126 case PAGE_HOME_IMMUTABLE:
127 /* Should be going to the device only. */
128 BUG_ON(direction == DMA_FROM_DEVICE ||
129 direction == DMA_BIDIRECTIONAL);
130 return;
131 case PAGE_HOME_INCOHERENT:
132 /* Incoherent anyway, so no need to work hard here. */
133 return;
134 default:
135 BUG_ON(home < 0 || home >= NR_CPUS);
136 break;
137 }
138 homecache_finv_page(page);
139
140#ifdef DEBUG_ALIGNMENT
141 /* Warn if the region isn't cacheline aligned. */
142 if (offset & (L2_CACHE_BYTES - 1) || (size & (L2_CACHE_BYTES - 1)))
143 pr_warn("Unaligned DMA to non-hfh memory: PA %#llx/%#lx\n",
144 PFN_PHYS(page_to_pfn(page)) + offset, size);
145#endif
146}
147
148/* Make the page ready to be read by the core. */
149static void __dma_complete_page(struct page *page, unsigned long offset,
150 size_t size, enum dma_data_direction direction)
151{
152#ifdef __tilegx__
153 switch (page_home(page)) {
154 case PAGE_HOME_HASH:
155 /* I/O device delivered data the way the cpu wanted it. */
156 break;
157 case PAGE_HOME_INCOHERENT:
158 /* Incoherent anyway, so no need to work hard here. */
159 break;
160 case PAGE_HOME_IMMUTABLE:
161 /* Extra read-only copies are not a problem. */
162 break;
163 default:
164 /* Flush the bogus hash-for-home I/O entries to memory. */
165 homecache_finv_map_page(page, PAGE_HOME_HASH);
166 break;
167 }
168#endif
169}
170
171static void __dma_prep_pa_range(dma_addr_t dma_addr, size_t size,
172 enum dma_data_direction direction)
173{
174 struct page *page = pfn_to_page(PFN_DOWN(dma_addr));
175 unsigned long offset = dma_addr & (PAGE_SIZE - 1);
176 size_t bytes = min(size, (size_t)(PAGE_SIZE - offset));
177
178 while (size != 0) {
179 __dma_prep_page(page, offset, bytes, direction);
180 size -= bytes;
181 ++page;
182 offset = 0;
183 bytes = min((size_t)PAGE_SIZE, size);
184 }
185}
186
187static void __dma_complete_pa_range(dma_addr_t dma_addr, size_t size,
188 enum dma_data_direction direction)
189{
190 struct page *page = pfn_to_page(PFN_DOWN(dma_addr));
191 unsigned long offset = dma_addr & (PAGE_SIZE - 1);
192 size_t bytes = min(size, (size_t)(PAGE_SIZE - offset));
193
194 while (size != 0) {
195 __dma_complete_page(page, offset, bytes, direction);
196 size -= bytes;
197 ++page;
198 offset = 0;
199 bytes = min((size_t)PAGE_SIZE, size);
200 }
201}
202
203static int tile_dma_map_sg(struct device *dev, struct scatterlist *sglist,
204 int nents, enum dma_data_direction direction,
205 unsigned long attrs)
206{
207 struct scatterlist *sg;
208 int i;
209
210 BUG_ON(!valid_dma_direction(direction));
211
212 WARN_ON(nents == 0 || sglist->length == 0);
213
214 for_each_sg(sglist, sg, nents, i) {
215 sg->dma_address = sg_phys(sg);
216#ifdef CONFIG_NEED_SG_DMA_LENGTH
217 sg->dma_length = sg->length;
218#endif
219 if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
220 continue;
221 __dma_prep_pa_range(sg->dma_address, sg->length, direction);
222 }
223
224 return nents;
225}
226
227static void tile_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
228 int nents, enum dma_data_direction direction,
229 unsigned long attrs)
230{
231 struct scatterlist *sg;
232 int i;
233
234 BUG_ON(!valid_dma_direction(direction));
235 for_each_sg(sglist, sg, nents, i) {
236 sg->dma_address = sg_phys(sg);
237 if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
238 continue;
239 __dma_complete_pa_range(sg->dma_address, sg->length,
240 direction);
241 }
242}
243
244static dma_addr_t tile_dma_map_page(struct device *dev, struct page *page,
245 unsigned long offset, size_t size,
246 enum dma_data_direction direction,
247 unsigned long attrs)
248{
249 BUG_ON(!valid_dma_direction(direction));
250
251 BUG_ON(offset + size > PAGE_SIZE);
252 if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
253 __dma_prep_page(page, offset, size, direction);
254
255 return page_to_pa(page) + offset;
256}
257
258static void tile_dma_unmap_page(struct device *dev, dma_addr_t dma_address,
259 size_t size, enum dma_data_direction direction,
260 unsigned long attrs)
261{
262 BUG_ON(!valid_dma_direction(direction));
263
264 if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
265 return;
266
267 __dma_complete_page(pfn_to_page(PFN_DOWN(dma_address)),
268 dma_address & (PAGE_SIZE - 1), size, direction);
269}
270
271static void tile_dma_sync_single_for_cpu(struct device *dev,
272 dma_addr_t dma_handle,
273 size_t size,
274 enum dma_data_direction direction)
275{
276 BUG_ON(!valid_dma_direction(direction));
277
278 __dma_complete_pa_range(dma_handle, size, direction);
279}
280
281static void tile_dma_sync_single_for_device(struct device *dev,
282 dma_addr_t dma_handle, size_t size,
283 enum dma_data_direction direction)
284{
285 __dma_prep_pa_range(dma_handle, size, direction);
286}
287
288static void tile_dma_sync_sg_for_cpu(struct device *dev,
289 struct scatterlist *sglist, int nelems,
290 enum dma_data_direction direction)
291{
292 struct scatterlist *sg;
293 int i;
294
295 BUG_ON(!valid_dma_direction(direction));
296 WARN_ON(nelems == 0 || sglist->length == 0);
297
298 for_each_sg(sglist, sg, nelems, i) {
299 dma_sync_single_for_cpu(dev, sg->dma_address,
300 sg_dma_len(sg), direction);
301 }
302}
303
304static void tile_dma_sync_sg_for_device(struct device *dev,
305 struct scatterlist *sglist, int nelems,
306 enum dma_data_direction direction)
307{
308 struct scatterlist *sg;
309 int i;
310
311 BUG_ON(!valid_dma_direction(direction));
312 WARN_ON(nelems == 0 || sglist->length == 0);
313
314 for_each_sg(sglist, sg, nelems, i) {
315 dma_sync_single_for_device(dev, sg->dma_address,
316 sg_dma_len(sg), direction);
317 }
318}
319
320static const struct dma_map_ops tile_default_dma_map_ops = {
321 .alloc = tile_dma_alloc_coherent,
322 .free = tile_dma_free_coherent,
323 .map_page = tile_dma_map_page,
324 .unmap_page = tile_dma_unmap_page,
325 .map_sg = tile_dma_map_sg,
326 .unmap_sg = tile_dma_unmap_sg,
327 .sync_single_for_cpu = tile_dma_sync_single_for_cpu,
328 .sync_single_for_device = tile_dma_sync_single_for_device,
329 .sync_sg_for_cpu = tile_dma_sync_sg_for_cpu,
330 .sync_sg_for_device = tile_dma_sync_sg_for_device,
331};
332
333const struct dma_map_ops *tile_dma_map_ops = &tile_default_dma_map_ops;
334EXPORT_SYMBOL(tile_dma_map_ops);
335
336/* Generic PCI DMA mapping functions */
337
338static void *tile_pci_dma_alloc_coherent(struct device *dev, size_t size,
339 dma_addr_t *dma_handle, gfp_t gfp,
340 unsigned long attrs)
341{
342 int node = dev_to_node(dev);
343 int order = get_order(size);
344 struct page *pg;
345 dma_addr_t addr;
346
347 gfp |= __GFP_ZERO;
348
349 pg = homecache_alloc_pages_node(node, gfp, order, PAGE_HOME_DMA);
350 if (pg == NULL)
351 return NULL;
352
353 addr = page_to_phys(pg);
354
355 *dma_handle = addr + get_dma_offset(dev);
356
357 return page_address(pg);
358}
359
360/*
361 * Free memory that was allocated with tile_pci_dma_alloc_coherent.
362 */
363static void tile_pci_dma_free_coherent(struct device *dev, size_t size,
364 void *vaddr, dma_addr_t dma_handle,
365 unsigned long attrs)
366{
367 homecache_free_pages((unsigned long)vaddr, get_order(size));
368}
369
370static int tile_pci_dma_map_sg(struct device *dev, struct scatterlist *sglist,
371 int nents, enum dma_data_direction direction,
372 unsigned long attrs)
373{
374 struct scatterlist *sg;
375 int i;
376
377 BUG_ON(!valid_dma_direction(direction));
378
379 WARN_ON(nents == 0 || sglist->length == 0);
380
381 for_each_sg(sglist, sg, nents, i) {
382 sg->dma_address = sg_phys(sg);
383 __dma_prep_pa_range(sg->dma_address, sg->length, direction);
384
385 sg->dma_address = sg->dma_address + get_dma_offset(dev);
386#ifdef CONFIG_NEED_SG_DMA_LENGTH
387 sg->dma_length = sg->length;
388#endif
389 }
390
391 return nents;
392}
393
394static void tile_pci_dma_unmap_sg(struct device *dev,
395 struct scatterlist *sglist, int nents,
396 enum dma_data_direction direction,
397 unsigned long attrs)
398{
399 struct scatterlist *sg;
400 int i;
401
402 BUG_ON(!valid_dma_direction(direction));
403 for_each_sg(sglist, sg, nents, i) {
404 sg->dma_address = sg_phys(sg);
405 __dma_complete_pa_range(sg->dma_address, sg->length,
406 direction);
407 }
408}
409
410static dma_addr_t tile_pci_dma_map_page(struct device *dev, struct page *page,
411 unsigned long offset, size_t size,
412 enum dma_data_direction direction,
413 unsigned long attrs)
414{
415 BUG_ON(!valid_dma_direction(direction));
416
417 BUG_ON(offset + size > PAGE_SIZE);
418 __dma_prep_page(page, offset, size, direction);
419
420 return page_to_pa(page) + offset + get_dma_offset(dev);
421}
422
423static void tile_pci_dma_unmap_page(struct device *dev, dma_addr_t dma_address,
424 size_t size,
425 enum dma_data_direction direction,
426 unsigned long attrs)
427{
428 BUG_ON(!valid_dma_direction(direction));
429
430 dma_address -= get_dma_offset(dev);
431
432 __dma_complete_page(pfn_to_page(PFN_DOWN(dma_address)),
433 dma_address & (PAGE_SIZE - 1), size, direction);
434}
435
436static void tile_pci_dma_sync_single_for_cpu(struct device *dev,
437 dma_addr_t dma_handle,
438 size_t size,
439 enum dma_data_direction direction)
440{
441 BUG_ON(!valid_dma_direction(direction));
442
443 dma_handle -= get_dma_offset(dev);
444
445 __dma_complete_pa_range(dma_handle, size, direction);
446}
447
448static void tile_pci_dma_sync_single_for_device(struct device *dev,
449 dma_addr_t dma_handle,
450 size_t size,
451 enum dma_data_direction
452 direction)
453{
454 dma_handle -= get_dma_offset(dev);
455
456 __dma_prep_pa_range(dma_handle, size, direction);
457}
458
459static void tile_pci_dma_sync_sg_for_cpu(struct device *dev,
460 struct scatterlist *sglist,
461 int nelems,
462 enum dma_data_direction direction)
463{
464 struct scatterlist *sg;
465 int i;
466
467 BUG_ON(!valid_dma_direction(direction));
468 WARN_ON(nelems == 0 || sglist->length == 0);
469
470 for_each_sg(sglist, sg, nelems, i) {
471 dma_sync_single_for_cpu(dev, sg->dma_address,
472 sg_dma_len(sg), direction);
473 }
474}
475
476static void tile_pci_dma_sync_sg_for_device(struct device *dev,
477 struct scatterlist *sglist,
478 int nelems,
479 enum dma_data_direction direction)
480{
481 struct scatterlist *sg;
482 int i;
483
484 BUG_ON(!valid_dma_direction(direction));
485 WARN_ON(nelems == 0 || sglist->length == 0);
486
487 for_each_sg(sglist, sg, nelems, i) {
488 dma_sync_single_for_device(dev, sg->dma_address,
489 sg_dma_len(sg), direction);
490 }
491}
492
493static const struct dma_map_ops tile_pci_default_dma_map_ops = {
494 .alloc = tile_pci_dma_alloc_coherent,
495 .free = tile_pci_dma_free_coherent,
496 .map_page = tile_pci_dma_map_page,
497 .unmap_page = tile_pci_dma_unmap_page,
498 .map_sg = tile_pci_dma_map_sg,
499 .unmap_sg = tile_pci_dma_unmap_sg,
500 .sync_single_for_cpu = tile_pci_dma_sync_single_for_cpu,
501 .sync_single_for_device = tile_pci_dma_sync_single_for_device,
502 .sync_sg_for_cpu = tile_pci_dma_sync_sg_for_cpu,
503 .sync_sg_for_device = tile_pci_dma_sync_sg_for_device,
504};
505
506const struct dma_map_ops *gx_pci_dma_map_ops = &tile_pci_default_dma_map_ops;
507EXPORT_SYMBOL(gx_pci_dma_map_ops);
508
509/* PCI DMA mapping functions for legacy PCI devices */
510
511#ifdef CONFIG_SWIOTLB
512static const struct dma_map_ops pci_hybrid_dma_ops = {
513 .alloc = swiotlb_alloc,
514 .free = swiotlb_free,
515 .map_page = tile_pci_dma_map_page,
516 .unmap_page = tile_pci_dma_unmap_page,
517 .map_sg = tile_pci_dma_map_sg,
518 .unmap_sg = tile_pci_dma_unmap_sg,
519 .sync_single_for_cpu = tile_pci_dma_sync_single_for_cpu,
520 .sync_single_for_device = tile_pci_dma_sync_single_for_device,
521 .sync_sg_for_cpu = tile_pci_dma_sync_sg_for_cpu,
522 .sync_sg_for_device = tile_pci_dma_sync_sg_for_device,
523};
524
525const struct dma_map_ops *gx_legacy_pci_dma_map_ops = &swiotlb_dma_ops;
526const struct dma_map_ops *gx_hybrid_pci_dma_map_ops = &pci_hybrid_dma_ops;
527#else
528const struct dma_map_ops *gx_legacy_pci_dma_map_ops;
529const struct dma_map_ops *gx_hybrid_pci_dma_map_ops;
530#endif
531EXPORT_SYMBOL(gx_legacy_pci_dma_map_ops);
532EXPORT_SYMBOL(gx_hybrid_pci_dma_map_ops);
533
534int dma_set_mask(struct device *dev, u64 mask)
535{
536 const struct dma_map_ops *dma_ops = get_dma_ops(dev);
537
538 /*
539 * For PCI devices with 64-bit DMA addressing capability, promote
540 * the dma_ops to hybrid, with the consistent memory DMA space limited
541 * to 32-bit. For 32-bit capable devices, limit the streaming DMA
542 * address range to max_direct_dma_addr.
543 */
544 if (dma_ops == gx_pci_dma_map_ops ||
545 dma_ops == gx_hybrid_pci_dma_map_ops ||
546 dma_ops == gx_legacy_pci_dma_map_ops) {
547 if (mask == DMA_BIT_MASK(64) &&
548 dma_ops == gx_legacy_pci_dma_map_ops)
549 set_dma_ops(dev, gx_hybrid_pci_dma_map_ops);
550 else if (mask > dev->archdata.max_direct_dma_addr)
551 mask = dev->archdata.max_direct_dma_addr;
552 }
553
554 if (!dev->dma_mask || !dma_supported(dev, mask))
555 return -EIO;
556
557 *dev->dma_mask = mask;
558
559 return 0;
560}
561EXPORT_SYMBOL(dma_set_mask);
562
563#ifdef CONFIG_ARCH_HAS_DMA_SET_COHERENT_MASK
564int dma_set_coherent_mask(struct device *dev, u64 mask)
565{
566 const struct dma_map_ops *dma_ops = get_dma_ops(dev);
567
568 /*
569 * For PCI devices with 64-bit DMA addressing capability, promote
570 * the dma_ops to full capability for both streams and consistent
571 * memory access. For 32-bit capable devices, limit the consistent
572 * memory DMA range to max_direct_dma_addr.
573 */
574 if (dma_ops == gx_pci_dma_map_ops ||
575 dma_ops == gx_hybrid_pci_dma_map_ops ||
576 dma_ops == gx_legacy_pci_dma_map_ops) {
577 if (mask == DMA_BIT_MASK(64))
578 set_dma_ops(dev, gx_pci_dma_map_ops);
579 else if (mask > dev->archdata.max_direct_dma_addr)
580 mask = dev->archdata.max_direct_dma_addr;
581 }
582
583 if (!dma_supported(dev, mask))
584 return -EIO;
585 dev->coherent_dma_mask = mask;
586 return 0;
587}
588EXPORT_SYMBOL(dma_set_coherent_mask);
589#endif
590
591#ifdef ARCH_HAS_DMA_GET_REQUIRED_MASK
592/*
593 * The generic dma_get_required_mask() uses the highest physical address
594 * (max_pfn) to provide the hint to the PCI drivers regarding 32-bit or
595 * 64-bit DMA configuration. Since TILEGx has I/O TLB/MMU, allowing the
596 * DMAs to use the full 64-bit PCI address space and not limited by
597 * the physical memory space, we always let the PCI devices use
598 * 64-bit DMA if they have that capability, by returning the 64-bit
599 * DMA mask here. The device driver has the option to use 32-bit DMA if
600 * the device is not capable of 64-bit DMA.
601 */
602u64 dma_get_required_mask(struct device *dev)
603{
604 return DMA_BIT_MASK(64);
605}
606EXPORT_SYMBOL_GPL(dma_get_required_mask);
607#endif
diff --git a/arch/tile/kernel/pci.c b/arch/tile/kernel/pci.c
deleted file mode 100644
index bbf81579b1f8..000000000000
--- a/arch/tile/kernel/pci.c
+++ /dev/null
@@ -1,592 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/kernel.h>
16#include <linux/pci.h>
17#include <linux/delay.h>
18#include <linux/string.h>
19#include <linux/init.h>
20#include <linux/capability.h>
21#include <linux/sched.h>
22#include <linux/errno.h>
23#include <linux/irq.h>
24#include <linux/io.h>
25#include <linux/uaccess.h>
26#include <linux/export.h>
27
28#include <asm/processor.h>
29#include <asm/sections.h>
30#include <asm/byteorder.h>
31#include <asm/hv_driver.h>
32#include <hv/drv_pcie_rc_intf.h>
33
34
35/*
36 * Initialization flow and process
37 * -------------------------------
38 *
39 * This files contains the routines to search for PCI buses,
40 * enumerate the buses, and configure any attached devices.
41 *
42 * There are two entry points here:
43 * 1) tile_pci_init
44 * This sets up the pci_controller structs, and opens the
45 * FDs to the hypervisor. This is called from setup_arch() early
46 * in the boot process.
47 * 2) pcibios_init
48 * This probes the PCI bus(es) for any attached hardware. It's
49 * called by subsys_initcall. All of the real work is done by the
50 * generic Linux PCI layer.
51 *
52 */
53
54static int pci_probe = 1;
55
56/*
57 * This flag tells if the platform is TILEmpower that needs
58 * special configuration for the PLX switch chip.
59 */
60int __ro_after_init tile_plx_gen1;
61
62static struct pci_controller controllers[TILE_NUM_PCIE];
63static int num_controllers;
64static int pci_scan_flags[TILE_NUM_PCIE];
65
66static struct pci_ops tile_cfg_ops;
67
68
69/*
70 * Open a FD to the hypervisor PCI device.
71 *
72 * controller_id is the controller number, config type is 0 or 1 for
73 * config0 or config1 operations.
74 */
75static int tile_pcie_open(int controller_id, int config_type)
76{
77 char filename[32];
78 int fd;
79
80 sprintf(filename, "pcie/%d/config%d", controller_id, config_type);
81
82 fd = hv_dev_open((HV_VirtAddr)filename, 0);
83
84 return fd;
85}
86
87
88/*
89 * Get the IRQ numbers from the HV and set up the handlers for them.
90 */
91static int tile_init_irqs(int controller_id, struct pci_controller *controller)
92{
93 char filename[32];
94 int fd;
95 int ret;
96 int x;
97 struct pcie_rc_config rc_config;
98
99 sprintf(filename, "pcie/%d/ctl", controller_id);
100 fd = hv_dev_open((HV_VirtAddr)filename, 0);
101 if (fd < 0) {
102 pr_err("PCI: hv_dev_open(%s) failed\n", filename);
103 return -1;
104 }
105 ret = hv_dev_pread(fd, 0, (HV_VirtAddr)(&rc_config),
106 sizeof(rc_config), PCIE_RC_CONFIG_MASK_OFF);
107 hv_dev_close(fd);
108 if (ret != sizeof(rc_config)) {
109 pr_err("PCI: wanted %zd bytes, got %d\n",
110 sizeof(rc_config), ret);
111 return -1;
112 }
113 /* Record irq_base so that we can map INTx to IRQ # later. */
114 controller->irq_base = rc_config.intr;
115
116 for (x = 0; x < 4; x++)
117 tile_irq_activate(rc_config.intr + x,
118 TILE_IRQ_HW_CLEAR);
119
120 if (rc_config.plx_gen1)
121 controller->plx_gen1 = 1;
122
123 return 0;
124}
125
126/*
127 * First initialization entry point, called from setup_arch().
128 *
129 * Find valid controllers and fill in pci_controller structs for each
130 * of them.
131 *
132 * Returns the number of controllers discovered.
133 */
134int __init tile_pci_init(void)
135{
136 int i;
137
138 if (!pci_probe) {
139 pr_info("PCI: disabled by boot argument\n");
140 return 0;
141 }
142
143 pr_info("PCI: Searching for controllers...\n");
144
145 /* Re-init number of PCIe controllers to support hot-plug feature. */
146 num_controllers = 0;
147
148 /* Do any configuration we need before using the PCIe */
149
150 for (i = 0; i < TILE_NUM_PCIE; i++) {
151 /*
152 * To see whether we need a real config op based on
153 * the results of pcibios_init(), to support PCIe hot-plug.
154 */
155 if (pci_scan_flags[i] == 0) {
156 int hv_cfg_fd0 = -1;
157 int hv_cfg_fd1 = -1;
158 int hv_mem_fd = -1;
159 char name[32];
160 struct pci_controller *controller;
161
162 /*
163 * Open the fd to the HV. If it fails then this
164 * device doesn't exist.
165 */
166 hv_cfg_fd0 = tile_pcie_open(i, 0);
167 if (hv_cfg_fd0 < 0)
168 continue;
169 hv_cfg_fd1 = tile_pcie_open(i, 1);
170 if (hv_cfg_fd1 < 0) {
171 pr_err("PCI: Couldn't open config fd to HV for controller %d\n",
172 i);
173 goto err_cont;
174 }
175
176 sprintf(name, "pcie/%d/mem", i);
177 hv_mem_fd = hv_dev_open((HV_VirtAddr)name, 0);
178 if (hv_mem_fd < 0) {
179 pr_err("PCI: Could not open mem fd to HV!\n");
180 goto err_cont;
181 }
182
183 pr_info("PCI: Found PCI controller #%d\n", i);
184
185 controller = &controllers[i];
186
187 controller->index = i;
188 controller->hv_cfg_fd[0] = hv_cfg_fd0;
189 controller->hv_cfg_fd[1] = hv_cfg_fd1;
190 controller->hv_mem_fd = hv_mem_fd;
191 controller->last_busno = 0xff;
192 controller->ops = &tile_cfg_ops;
193
194 num_controllers++;
195 continue;
196
197err_cont:
198 if (hv_cfg_fd0 >= 0)
199 hv_dev_close(hv_cfg_fd0);
200 if (hv_cfg_fd1 >= 0)
201 hv_dev_close(hv_cfg_fd1);
202 if (hv_mem_fd >= 0)
203 hv_dev_close(hv_mem_fd);
204 continue;
205 }
206 }
207
208 /*
209 * Before using the PCIe, see if we need to do any platform-specific
210 * configuration, such as the PLX switch Gen 1 issue on TILEmpower.
211 */
212 for (i = 0; i < num_controllers; i++) {
213 struct pci_controller *controller = &controllers[i];
214
215 if (controller->plx_gen1)
216 tile_plx_gen1 = 1;
217 }
218
219 return num_controllers;
220}
221
222/*
223 * (pin - 1) converts from the PCI standard's [1:4] convention to
224 * a normal [0:3] range.
225 */
226static int tile_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
227{
228 struct pci_controller *controller =
229 (struct pci_controller *)dev->sysdata;
230 return (pin - 1) + controller->irq_base;
231}
232
233
234static void fixup_read_and_payload_sizes(void)
235{
236 struct pci_dev *dev = NULL;
237 int smallest_max_payload = 0x1; /* Tile maxes out at 256 bytes. */
238 int max_read_size = PCI_EXP_DEVCTL_READRQ_512B;
239 u16 new_values;
240
241 /* Scan for the smallest maximum payload size. */
242 for_each_pci_dev(dev) {
243 if (!pci_is_pcie(dev))
244 continue;
245
246 if (dev->pcie_mpss < smallest_max_payload)
247 smallest_max_payload = dev->pcie_mpss;
248 }
249
250 /* Now, set the max_payload_size for all devices to that value. */
251 new_values = max_read_size | (smallest_max_payload << 5);
252 for_each_pci_dev(dev)
253 pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
254 PCI_EXP_DEVCTL_PAYLOAD | PCI_EXP_DEVCTL_READRQ,
255 new_values);
256}
257
258
259/*
260 * Second PCI initialization entry point, called by subsys_initcall.
261 *
262 * The controllers have been set up by the time we get here, by a call to
263 * tile_pci_init.
264 */
265int __init pcibios_init(void)
266{
267 struct pci_host_bridge *bridge;
268 int i;
269
270 pr_info("PCI: Probing PCI hardware\n");
271
272 /*
273 * Delay a bit in case devices aren't ready. Some devices are
274 * known to require at least 20ms here, but we use a more
275 * conservative value.
276 */
277 msleep(250);
278
279 /* Scan all of the recorded PCI controllers. */
280 for (i = 0; i < TILE_NUM_PCIE; i++) {
281 /*
282 * Do real pcibios init ops if the controller is initialized
283 * by tile_pci_init() successfully and not initialized by
284 * pcibios_init() yet to support PCIe hot-plug.
285 */
286 if (pci_scan_flags[i] == 0 && controllers[i].ops != NULL) {
287 struct pci_controller *controller = &controllers[i];
288 struct pci_bus *bus;
289 LIST_HEAD(resources);
290
291 if (tile_init_irqs(i, controller)) {
292 pr_err("PCI: Could not initialize IRQs\n");
293 continue;
294 }
295
296 pr_info("PCI: initializing controller #%d\n", i);
297
298 pci_add_resource(&resources, &ioport_resource);
299 pci_add_resource(&resources, &iomem_resource);
300
301 bridge = pci_alloc_host_bridge(0);
302 if (!bridge)
303 break;
304
305 list_splice_init(&resources, &bridge->windows);
306 bridge->dev.parent = NULL;
307 bridge->sysdata = controller;
308 bridge->busnr = 0;
309 bridge->ops = controller->ops;
310 bridge->swizzle_irq = pci_common_swizzle;
311 bridge->map_irq = tile_map_irq;
312
313 pci_scan_root_bus_bridge(bridge);
314 bus = bridge->bus;
315 controller->root_bus = bus;
316 controller->last_busno = bus->busn_res.end;
317 }
318 }
319
320 /*
321 * This comes from the generic Linux PCI driver.
322 *
323 * It allocates all of the resources (I/O memory, etc)
324 * associated with the devices read in above.
325 */
326 pci_assign_unassigned_resources();
327
328 /* Configure the max_read_size and max_payload_size values. */
329 fixup_read_and_payload_sizes();
330
331 /* Record the I/O resources in the PCI controller structure. */
332 for (i = 0; i < TILE_NUM_PCIE; i++) {
333 /*
334 * Do real pcibios init ops if the controller is initialized
335 * by tile_pci_init() successfully and not initialized by
336 * pcibios_init() yet to support PCIe hot-plug.
337 */
338 if (pci_scan_flags[i] == 0 && controllers[i].ops != NULL) {
339 struct pci_bus *root_bus = controllers[i].root_bus;
340 struct pci_bus *next_bus;
341 struct pci_dev *dev;
342
343 pci_bus_add_devices(root_bus);
344
345 list_for_each_entry(dev, &root_bus->devices, bus_list) {
346 /*
347 * Find the PCI host controller, ie. the 1st
348 * bridge.
349 */
350 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI &&
351 (PCI_SLOT(dev->devfn) == 0)) {
352 next_bus = dev->subordinate;
353 controllers[i].mem_resources[0] =
354 *next_bus->resource[0];
355 controllers[i].mem_resources[1] =
356 *next_bus->resource[1];
357 controllers[i].mem_resources[2] =
358 *next_bus->resource[2];
359
360 /* Setup flags. */
361 pci_scan_flags[i] = 1;
362
363 break;
364 }
365 }
366 }
367 }
368
369 return 0;
370}
371subsys_initcall(pcibios_init);
372
373void pcibios_set_master(struct pci_dev *dev)
374{
375 /* No special bus mastering setup handling. */
376}
377
378/* Process any "pci=" kernel boot arguments. */
379char *__init pcibios_setup(char *str)
380{
381 if (!strcmp(str, "off")) {
382 pci_probe = 0;
383 return NULL;
384 }
385 return str;
386}
387
388/*
389 * Enable memory and/or address decoding, as appropriate, for the
390 * device described by the 'dev' struct.
391 *
392 * This is called from the generic PCI layer, and can be called
393 * for bridges or endpoints.
394 */
395int pcibios_enable_device(struct pci_dev *dev, int mask)
396{
397 u16 cmd, old_cmd;
398 u8 header_type;
399 int i;
400 struct resource *r;
401
402 pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
403
404 pci_read_config_word(dev, PCI_COMMAND, &cmd);
405 old_cmd = cmd;
406 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
407 /*
408 * For bridges, we enable both memory and I/O decoding
409 * in call cases.
410 */
411 cmd |= PCI_COMMAND_IO;
412 cmd |= PCI_COMMAND_MEMORY;
413 } else {
414 /*
415 * For endpoints, we enable memory and/or I/O decoding
416 * only if they have a memory resource of that type.
417 */
418 for (i = 0; i < 6; i++) {
419 r = &dev->resource[i];
420 if (r->flags & IORESOURCE_UNSET) {
421 pr_err("PCI: Device %s not available because of resource collisions\n",
422 pci_name(dev));
423 return -EINVAL;
424 }
425 if (r->flags & IORESOURCE_IO)
426 cmd |= PCI_COMMAND_IO;
427 if (r->flags & IORESOURCE_MEM)
428 cmd |= PCI_COMMAND_MEMORY;
429 }
430 }
431
432 /*
433 * We only write the command if it changed.
434 */
435 if (cmd != old_cmd)
436 pci_write_config_word(dev, PCI_COMMAND, cmd);
437 return 0;
438}
439
440/****************************************************************
441 *
442 * Tile PCI config space read/write routines
443 *
444 ****************************************************************/
445
446/*
447 * These are the normal read and write ops
448 * These are expanded with macros from pci_bus_read_config_byte() etc.
449 *
450 * devfn is the combined PCI slot & function.
451 *
452 * offset is in bytes, from the start of config space for the
453 * specified bus & slot.
454 */
455
456static int tile_cfg_read(struct pci_bus *bus, unsigned int devfn, int offset,
457 int size, u32 *val)
458{
459 struct pci_controller *controller = bus->sysdata;
460 int busnum = bus->number & 0xff;
461 int slot = (devfn >> 3) & 0x1f;
462 int function = devfn & 0x7;
463 u32 addr;
464 int config_mode = 1;
465
466 /*
467 * There is no bridge between the Tile and bus 0, so we
468 * use config0 to talk to bus 0.
469 *
470 * If we're talking to a bus other than zero then we
471 * must have found a bridge.
472 */
473 if (busnum == 0) {
474 /*
475 * We fake an empty slot for (busnum == 0) && (slot > 0),
476 * since there is only one slot on bus 0.
477 */
478 if (slot) {
479 *val = 0xFFFFFFFF;
480 return 0;
481 }
482 config_mode = 0;
483 }
484
485 addr = busnum << 20; /* Bus in 27:20 */
486 addr |= slot << 15; /* Slot (device) in 19:15 */
487 addr |= function << 12; /* Function is in 14:12 */
488 addr |= (offset & 0xFFF); /* byte address in 0:11 */
489
490 return hv_dev_pread(controller->hv_cfg_fd[config_mode], 0,
491 (HV_VirtAddr)(val), size, addr);
492}
493
494
495/*
496 * See tile_cfg_read() for relevant comments.
497 * Note that "val" is the value to write, not a pointer to that value.
498 */
499static int tile_cfg_write(struct pci_bus *bus, unsigned int devfn, int offset,
500 int size, u32 val)
501{
502 struct pci_controller *controller = bus->sysdata;
503 int busnum = bus->number & 0xff;
504 int slot = (devfn >> 3) & 0x1f;
505 int function = devfn & 0x7;
506 u32 addr;
507 int config_mode = 1;
508 HV_VirtAddr valp = (HV_VirtAddr)&val;
509
510 /*
511 * For bus 0 slot 0 we use config 0 accesses.
512 */
513 if (busnum == 0) {
514 /*
515 * We fake an empty slot for (busnum == 0) && (slot > 0),
516 * since there is only one slot on bus 0.
517 */
518 if (slot)
519 return 0;
520 config_mode = 0;
521 }
522
523 addr = busnum << 20; /* Bus in 27:20 */
524 addr |= slot << 15; /* Slot (device) in 19:15 */
525 addr |= function << 12; /* Function is in 14:12 */
526 addr |= (offset & 0xFFF); /* byte address in 0:11 */
527
528#ifdef __BIG_ENDIAN
529 /* Point to the correct part of the 32-bit "val". */
530 valp += 4 - size;
531#endif
532
533 return hv_dev_pwrite(controller->hv_cfg_fd[config_mode], 0,
534 valp, size, addr);
535}
536
537
538static struct pci_ops tile_cfg_ops = {
539 .read = tile_cfg_read,
540 .write = tile_cfg_write,
541};
542
543
544/*
545 * In the following, each PCI controller's mem_resources[1]
546 * represents its (non-prefetchable) PCI memory resource.
547 * mem_resources[0] and mem_resources[2] refer to its PCI I/O and
548 * prefetchable PCI memory resources, respectively.
549 * For more details, see pci_setup_bridge() in setup-bus.c.
550 * By comparing the target PCI memory address against the
551 * end address of controller 0, we can determine the controller
552 * that should accept the PCI memory access.
553 */
554#define TILE_READ(size, type) \
555type _tile_read##size(unsigned long addr) \
556{ \
557 type val; \
558 int idx = 0; \
559 if (addr > controllers[0].mem_resources[1].end && \
560 addr > controllers[0].mem_resources[2].end) \
561 idx = 1; \
562 if (hv_dev_pread(controllers[idx].hv_mem_fd, 0, \
563 (HV_VirtAddr)(&val), sizeof(type), addr)) \
564 pr_err("PCI: read %zd bytes at 0x%lX failed\n", \
565 sizeof(type), addr); \
566 return val; \
567} \
568EXPORT_SYMBOL(_tile_read##size)
569
570TILE_READ(b, u8);
571TILE_READ(w, u16);
572TILE_READ(l, u32);
573TILE_READ(q, u64);
574
575#define TILE_WRITE(size, type) \
576void _tile_write##size(type val, unsigned long addr) \
577{ \
578 int idx = 0; \
579 if (addr > controllers[0].mem_resources[1].end && \
580 addr > controllers[0].mem_resources[2].end) \
581 idx = 1; \
582 if (hv_dev_pwrite(controllers[idx].hv_mem_fd, 0, \
583 (HV_VirtAddr)(&val), sizeof(type), addr)) \
584 pr_err("PCI: write %zd bytes at 0x%lX failed\n", \
585 sizeof(type), addr); \
586} \
587EXPORT_SYMBOL(_tile_write##size)
588
589TILE_WRITE(b, u8);
590TILE_WRITE(w, u16);
591TILE_WRITE(l, u32);
592TILE_WRITE(q, u64);
diff --git a/arch/tile/kernel/pci_gx.c b/arch/tile/kernel/pci_gx.c
deleted file mode 100644
index 9aa238ac7b35..000000000000
--- a/arch/tile/kernel/pci_gx.c
+++ /dev/null
@@ -1,1592 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/kernel.h>
16#include <linux/mmzone.h>
17#include <linux/pci.h>
18#include <linux/delay.h>
19#include <linux/string.h>
20#include <linux/init.h>
21#include <linux/capability.h>
22#include <linux/sched.h>
23#include <linux/errno.h>
24#include <linux/irq.h>
25#include <linux/msi.h>
26#include <linux/io.h>
27#include <linux/uaccess.h>
28#include <linux/ctype.h>
29
30#include <asm/processor.h>
31#include <asm/sections.h>
32#include <asm/byteorder.h>
33
34#include <gxio/iorpc_globals.h>
35#include <gxio/kiorpc.h>
36#include <gxio/trio.h>
37#include <gxio/iorpc_trio.h>
38#include <hv/drv_trio_intf.h>
39
40#include <arch/sim.h>
41
42/*
43 * This file contains the routines to search for PCI buses,
44 * enumerate the buses, and configure any attached devices.
45 */
46
47#define DEBUG_PCI_CFG 0
48
49#if DEBUG_PCI_CFG
50#define TRACE_CFG_WR(size, val, bus, dev, func, offset) \
51 pr_info("CFG WR %d-byte VAL %#x to bus %d dev %d func %d addr %u\n", \
52 size, val, bus, dev, func, offset & 0xFFF);
53#define TRACE_CFG_RD(size, val, bus, dev, func, offset) \
54 pr_info("CFG RD %d-byte VAL %#x from bus %d dev %d func %d addr %u\n", \
55 size, val, bus, dev, func, offset & 0xFFF);
56#else
57#define TRACE_CFG_WR(...)
58#define TRACE_CFG_RD(...)
59#endif
60
61static int pci_probe = 1;
62
63/* Information on the PCIe RC ports configuration. */
64static int pcie_rc[TILEGX_NUM_TRIO][TILEGX_TRIO_PCIES];
65
66/*
67 * On some platforms with one or more Gx endpoint ports, we need to
68 * delay the PCIe RC port probe for a few seconds to work around
69 * a HW PCIe link-training bug. The exact delay is specified with
70 * a kernel boot argument in the form of "pcie_rc_delay=T,P,S",
71 * where T is the TRIO instance number, P is the port number and S is
72 * the delay in seconds. If the argument is specified, but the delay is
73 * not provided, the value will be DEFAULT_RC_DELAY.
74 */
75static int rc_delay[TILEGX_NUM_TRIO][TILEGX_TRIO_PCIES];
76
77/* Default number of seconds that the PCIe RC port probe can be delayed. */
78#define DEFAULT_RC_DELAY 10
79
80/* The PCI I/O space size in each PCI domain. */
81#define IO_SPACE_SIZE 0x10000
82
83/* Provide shorter versions of some very long constant names. */
84#define AUTO_CONFIG_RC \
85 TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_RC
86#define AUTO_CONFIG_RC_G1 \
87 TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_RC_G1
88#define AUTO_CONFIG_EP \
89 TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_ENDPOINT
90#define AUTO_CONFIG_EP_G1 \
91 TRIO_PCIE_INTFC_PORT_CONFIG__STRAP_STATE_VAL_AUTO_CONFIG_ENDPOINT_G1
92
93/* Array of the PCIe ports configuration info obtained from the BIB. */
94struct pcie_trio_ports_property pcie_ports[TILEGX_NUM_TRIO];
95
96/* Number of configured TRIO instances. */
97int num_trio_shims;
98
99/* All drivers share the TRIO contexts defined here. */
100gxio_trio_context_t trio_contexts[TILEGX_NUM_TRIO];
101
102/* Pointer to an array of PCIe RC controllers. */
103struct pci_controller pci_controllers[TILEGX_NUM_TRIO * TILEGX_TRIO_PCIES];
104int num_rc_controllers;
105
106static struct pci_ops tile_cfg_ops;
107
108/* Mask of CPUs that should receive PCIe interrupts. */
109static struct cpumask intr_cpus_map;
110
111/*
112 * Pick a CPU to receive and handle the PCIe interrupts, based on the IRQ #.
113 * For now, we simply send interrupts to non-dataplane CPUs.
114 * We may implement methods to allow user to specify the target CPUs,
115 * e.g. via boot arguments.
116 */
117static int tile_irq_cpu(int irq)
118{
119 unsigned int count;
120 int i = 0;
121 int cpu;
122
123 count = cpumask_weight(&intr_cpus_map);
124 if (unlikely(count == 0)) {
125 pr_warn("intr_cpus_map empty, interrupts will be delivered to dataplane tiles\n");
126 return irq % (smp_height * smp_width);
127 }
128
129 count = irq % count;
130 for_each_cpu(cpu, &intr_cpus_map) {
131 if (i++ == count)
132 break;
133 }
134 return cpu;
135}
136
137/* Open a file descriptor to the TRIO shim. */
138static int tile_pcie_open(int trio_index)
139{
140 gxio_trio_context_t *context = &trio_contexts[trio_index];
141 int ret;
142 int mac;
143
144 /* This opens a file descriptor to the TRIO shim. */
145 ret = gxio_trio_init(context, trio_index);
146 if (ret < 0)
147 goto gxio_trio_init_failure;
148
149 /* Allocate an ASID for the kernel. */
150 ret = gxio_trio_alloc_asids(context, 1, 0, 0);
151 if (ret < 0) {
152 pr_err("PCI: ASID alloc failure on TRIO %d, give up\n",
153 trio_index);
154 goto asid_alloc_failure;
155 }
156
157 context->asid = ret;
158
159#ifdef USE_SHARED_PCIE_CONFIG_REGION
160 /*
161 * Alloc a PIO region for config access, shared by all MACs per TRIO.
162 * This shouldn't fail since the kernel is supposed to the first
163 * client of the TRIO's PIO regions.
164 */
165 ret = gxio_trio_alloc_pio_regions(context, 1, 0, 0);
166 if (ret < 0) {
167 pr_err("PCI: CFG PIO alloc failure on TRIO %d, give up\n",
168 trio_index);
169 goto pio_alloc_failure;
170 }
171
172 context->pio_cfg_index = ret;
173
174 /*
175 * For PIO CFG, the bus_address_hi parameter is 0. The mac parameter
176 * is also 0 because it is specified in PIO_REGION_SETUP_CFG_ADDR.
177 */
178 ret = gxio_trio_init_pio_region_aux(context, context->pio_cfg_index,
179 0, 0, HV_TRIO_PIO_FLAG_CONFIG_SPACE);
180 if (ret < 0) {
181 pr_err("PCI: CFG PIO init failure on TRIO %d, give up\n",
182 trio_index);
183 goto pio_alloc_failure;
184 }
185#endif
186
187 /* Get the properties of the PCIe ports on this TRIO instance. */
188 ret = gxio_trio_get_port_property(context, &pcie_ports[trio_index]);
189 if (ret < 0) {
190 pr_err("PCI: PCIE_GET_PORT_PROPERTY failure, error %d, on TRIO %d\n",
191 ret, trio_index);
192 goto get_port_property_failure;
193 }
194
195 context->mmio_base_mac =
196 iorpc_ioremap(context->fd, 0, HV_TRIO_CONFIG_IOREMAP_SIZE);
197 if (context->mmio_base_mac == NULL) {
198 pr_err("PCI: TRIO config space mapping failure, error %d, on TRIO %d\n",
199 ret, trio_index);
200 ret = -ENOMEM;
201
202 goto trio_mmio_mapping_failure;
203 }
204
205 /* Check the port strap state which will override the BIB setting. */
206 for (mac = 0; mac < TILEGX_TRIO_PCIES; mac++) {
207 TRIO_PCIE_INTFC_PORT_CONFIG_t port_config;
208 unsigned int reg_offset;
209
210 /* Ignore ports that are not specified in the BIB. */
211 if (!pcie_ports[trio_index].ports[mac].allow_rc &&
212 !pcie_ports[trio_index].ports[mac].allow_ep)
213 continue;
214
215 reg_offset =
216 (TRIO_PCIE_INTFC_PORT_CONFIG <<
217 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
218 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE <<
219 TRIO_CFG_REGION_ADDR__INTFC_SHIFT) |
220 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
221
222 port_config.word =
223 __gxio_mmio_read(context->mmio_base_mac + reg_offset);
224
225 if (port_config.strap_state != AUTO_CONFIG_RC &&
226 port_config.strap_state != AUTO_CONFIG_RC_G1) {
227 /*
228 * If this is really intended to be an EP port, record
229 * it so that the endpoint driver will know about it.
230 */
231 if (port_config.strap_state == AUTO_CONFIG_EP ||
232 port_config.strap_state == AUTO_CONFIG_EP_G1)
233 pcie_ports[trio_index].ports[mac].allow_ep = 1;
234 }
235 }
236
237 return ret;
238
239trio_mmio_mapping_failure:
240get_port_property_failure:
241asid_alloc_failure:
242#ifdef USE_SHARED_PCIE_CONFIG_REGION
243pio_alloc_failure:
244#endif
245 hv_dev_close(context->fd);
246gxio_trio_init_failure:
247 context->fd = -1;
248
249 return ret;
250}
251
252static int __init tile_trio_init(void)
253{
254 int i;
255
256 /* We loop over all the TRIO shims. */
257 for (i = 0; i < TILEGX_NUM_TRIO; i++) {
258 if (tile_pcie_open(i) < 0)
259 continue;
260 num_trio_shims++;
261 }
262
263 return 0;
264}
265postcore_initcall(tile_trio_init);
266
267static void tilegx_legacy_irq_ack(struct irq_data *d)
268{
269 __insn_mtspr(SPR_IPI_EVENT_RESET_K, 1UL << d->irq);
270}
271
272static void tilegx_legacy_irq_mask(struct irq_data *d)
273{
274 __insn_mtspr(SPR_IPI_MASK_SET_K, 1UL << d->irq);
275}
276
277static void tilegx_legacy_irq_unmask(struct irq_data *d)
278{
279 __insn_mtspr(SPR_IPI_MASK_RESET_K, 1UL << d->irq);
280}
281
282static struct irq_chip tilegx_legacy_irq_chip = {
283 .name = "tilegx_legacy_irq",
284 .irq_ack = tilegx_legacy_irq_ack,
285 .irq_mask = tilegx_legacy_irq_mask,
286 .irq_unmask = tilegx_legacy_irq_unmask,
287
288 /* TBD: support set_affinity. */
289};
290
291/*
292 * This is a wrapper function of the kernel level-trigger interrupt
293 * handler handle_level_irq() for PCI legacy interrupts. The TRIO
294 * is configured such that only INTx Assert interrupts are proxied
295 * to Linux which just calls handle_level_irq() after clearing the
296 * MAC INTx Assert status bit associated with this interrupt.
297 */
298static void trio_handle_level_irq(struct irq_desc *desc)
299{
300 struct pci_controller *controller = irq_desc_get_handler_data(desc);
301 gxio_trio_context_t *trio_context = controller->trio;
302 uint64_t intx = (uint64_t)irq_desc_get_chip_data(desc);
303 int mac = controller->mac;
304 unsigned int reg_offset;
305 uint64_t level_mask;
306
307 handle_level_irq(desc);
308
309 /*
310 * Clear the INTx Level status, otherwise future interrupts are
311 * not sent.
312 */
313 reg_offset = (TRIO_PCIE_INTFC_MAC_INT_STS <<
314 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
315 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE <<
316 TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) |
317 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
318
319 level_mask = TRIO_PCIE_INTFC_MAC_INT_STS__INT_LEVEL_MASK << intx;
320
321 __gxio_mmio_write(trio_context->mmio_base_mac + reg_offset, level_mask);
322}
323
324/*
325 * Create kernel irqs and set up the handlers for the legacy interrupts.
326 * Also some minimum initialization for the MSI support.
327 */
328static int tile_init_irqs(struct pci_controller *controller)
329{
330 int i;
331 int j;
332 int irq;
333 int result;
334
335 cpumask_copy(&intr_cpus_map, cpu_online_mask);
336
337
338 for (i = 0; i < 4; i++) {
339 gxio_trio_context_t *context = controller->trio;
340 int cpu;
341
342 /* Ask the kernel to allocate an IRQ. */
343 irq = irq_alloc_hwirq(-1);
344 if (!irq) {
345 pr_err("PCI: no free irq vectors, failed for %d\n", i);
346 goto free_irqs;
347 }
348 controller->irq_intx_table[i] = irq;
349
350 /* Distribute the 4 IRQs to different tiles. */
351 cpu = tile_irq_cpu(irq);
352
353 /* Configure the TRIO intr binding for this IRQ. */
354 result = gxio_trio_config_legacy_intr(context, cpu_x(cpu),
355 cpu_y(cpu), KERNEL_PL,
356 irq, controller->mac, i);
357 if (result < 0) {
358 pr_err("PCI: MAC intx config failed for %d\n", i);
359
360 goto free_irqs;
361 }
362
363 /* Register the IRQ handler with the kernel. */
364 irq_set_chip_and_handler(irq, &tilegx_legacy_irq_chip,
365 trio_handle_level_irq);
366 irq_set_chip_data(irq, (void *)(uint64_t)i);
367 irq_set_handler_data(irq, controller);
368 }
369
370 return 0;
371
372free_irqs:
373 for (j = 0; j < i; j++)
374 irq_free_hwirq(controller->irq_intx_table[j]);
375
376 return -1;
377}
378
379/*
380 * Return 1 if the port is strapped to operate in RC mode.
381 */
382static int
383strapped_for_rc(gxio_trio_context_t *trio_context, int mac)
384{
385 TRIO_PCIE_INTFC_PORT_CONFIG_t port_config;
386 unsigned int reg_offset;
387
388 /* Check the port configuration. */
389 reg_offset =
390 (TRIO_PCIE_INTFC_PORT_CONFIG <<
391 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
392 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE <<
393 TRIO_CFG_REGION_ADDR__INTFC_SHIFT) |
394 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
395 port_config.word =
396 __gxio_mmio_read(trio_context->mmio_base_mac + reg_offset);
397
398 if (port_config.strap_state == AUTO_CONFIG_RC ||
399 port_config.strap_state == AUTO_CONFIG_RC_G1)
400 return 1;
401 else
402 return 0;
403}
404
405/*
406 * Find valid controllers and fill in pci_controller structs for each
407 * of them.
408 *
409 * Return the number of controllers discovered.
410 */
411int __init tile_pci_init(void)
412{
413 int ctl_index = 0;
414 int i, j;
415
416 if (!pci_probe) {
417 pr_info("PCI: disabled by boot argument\n");
418 return 0;
419 }
420
421 pr_info("PCI: Searching for controllers...\n");
422
423 if (num_trio_shims == 0 || sim_is_simulator())
424 return 0;
425
426 /*
427 * Now determine which PCIe ports are configured to operate in RC
428 * mode. There is a difference in the port configuration capability
429 * between the Gx36 and Gx72 devices.
430 *
431 * The Gx36 has configuration capability for each of the 3 PCIe
432 * interfaces (disable, auto endpoint, auto RC, etc.).
433 * On the Gx72, you can only select one of the 3 PCIe interfaces per
434 * TRIO to train automatically. Further, the allowable training modes
435 * are reduced to four options (auto endpoint, auto RC, stream x1,
436 * stream x4).
437 *
438 * For Gx36 ports, it must be allowed to be in RC mode by the
439 * Board Information Block, and the hardware strapping pins must be
440 * set to RC mode.
441 *
442 * For Gx72 ports, the port will operate in RC mode if either of the
443 * following is true:
444 * 1. It is allowed to be in RC mode by the Board Information Block,
445 * and the BIB doesn't allow the EP mode.
446 * 2. It is allowed to be in either the RC or the EP mode by the BIB,
447 * and the hardware strapping pin is set to RC mode.
448 */
449 for (i = 0; i < TILEGX_NUM_TRIO; i++) {
450 gxio_trio_context_t *context = &trio_contexts[i];
451
452 if (context->fd < 0)
453 continue;
454
455 for (j = 0; j < TILEGX_TRIO_PCIES; j++) {
456 int is_rc = 0;
457
458 if (pcie_ports[i].is_gx72 &&
459 pcie_ports[i].ports[j].allow_rc) {
460 if (!pcie_ports[i].ports[j].allow_ep ||
461 strapped_for_rc(context, j))
462 is_rc = 1;
463 } else if (pcie_ports[i].ports[j].allow_rc &&
464 strapped_for_rc(context, j)) {
465 is_rc = 1;
466 }
467 if (is_rc) {
468 pcie_rc[i][j] = 1;
469 num_rc_controllers++;
470 }
471 }
472 }
473
474 /* Return if no PCIe ports are configured to operate in RC mode. */
475 if (num_rc_controllers == 0)
476 return 0;
477
478 /* Set the TRIO pointer and MAC index for each PCIe RC port. */
479 for (i = 0; i < TILEGX_NUM_TRIO; i++) {
480 for (j = 0; j < TILEGX_TRIO_PCIES; j++) {
481 if (pcie_rc[i][j]) {
482 pci_controllers[ctl_index].trio =
483 &trio_contexts[i];
484 pci_controllers[ctl_index].mac = j;
485 pci_controllers[ctl_index].trio_index = i;
486 ctl_index++;
487 if (ctl_index == num_rc_controllers)
488 goto out;
489 }
490 }
491 }
492
493out:
494 /* Configure each PCIe RC port. */
495 for (i = 0; i < num_rc_controllers; i++) {
496
497 /* Configure the PCIe MAC to run in RC mode. */
498 struct pci_controller *controller = &pci_controllers[i];
499
500 controller->index = i;
501 controller->ops = &tile_cfg_ops;
502
503 controller->io_space.start = PCIBIOS_MIN_IO +
504 (i * IO_SPACE_SIZE);
505 controller->io_space.end = controller->io_space.start +
506 IO_SPACE_SIZE - 1;
507 BUG_ON(controller->io_space.end > IO_SPACE_LIMIT);
508 controller->io_space.flags = IORESOURCE_IO;
509 snprintf(controller->io_space_name,
510 sizeof(controller->io_space_name),
511 "PCI I/O domain %d", i);
512 controller->io_space.name = controller->io_space_name;
513
514 /*
515 * The PCI memory resource is located above the PA space.
516 * For every host bridge, the BAR window or the MMIO aperture
517 * is in range [3GB, 4GB - 1] of a 4GB space beyond the
518 * PA space.
519 */
520 controller->mem_offset = TILE_PCI_MEM_START +
521 (i * TILE_PCI_BAR_WINDOW_TOP);
522 controller->mem_space.start = controller->mem_offset +
523 TILE_PCI_BAR_WINDOW_TOP - TILE_PCI_BAR_WINDOW_SIZE;
524 controller->mem_space.end = controller->mem_offset +
525 TILE_PCI_BAR_WINDOW_TOP - 1;
526 controller->mem_space.flags = IORESOURCE_MEM;
527 snprintf(controller->mem_space_name,
528 sizeof(controller->mem_space_name),
529 "PCI mem domain %d", i);
530 controller->mem_space.name = controller->mem_space_name;
531 }
532
533 return num_rc_controllers;
534}
535
536/*
537 * (pin - 1) converts from the PCI standard's [1:4] convention to
538 * a normal [0:3] range.
539 */
540static int tile_map_irq(const struct pci_dev *dev, u8 device, u8 pin)
541{
542 struct pci_controller *controller =
543 (struct pci_controller *)dev->sysdata;
544 return controller->irq_intx_table[pin - 1];
545}
546
547static void fixup_read_and_payload_sizes(struct pci_controller *controller)
548{
549 gxio_trio_context_t *trio_context = controller->trio;
550 struct pci_bus *root_bus = controller->root_bus;
551 TRIO_PCIE_RC_DEVICE_CONTROL_t dev_control;
552 TRIO_PCIE_RC_DEVICE_CAP_t rc_dev_cap;
553 unsigned int reg_offset;
554 struct pci_bus *child;
555 int mac;
556 int err;
557
558 mac = controller->mac;
559
560 /* Set our max read request size to be 4KB. */
561 reg_offset =
562 (TRIO_PCIE_RC_DEVICE_CONTROL <<
563 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
564 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD <<
565 TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) |
566 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
567
568 dev_control.word = __gxio_mmio_read32(trio_context->mmio_base_mac +
569 reg_offset);
570 dev_control.max_read_req_sz = 5;
571 __gxio_mmio_write32(trio_context->mmio_base_mac + reg_offset,
572 dev_control.word);
573
574 /*
575 * Set the max payload size supported by this Gx PCIe MAC.
576 * Though Gx PCIe supports Max Payload Size of up to 1024 bytes,
577 * experiments have shown that setting MPS to 256 yields the
578 * best performance.
579 */
580 reg_offset =
581 (TRIO_PCIE_RC_DEVICE_CAP <<
582 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
583 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD <<
584 TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) |
585 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
586
587 rc_dev_cap.word = __gxio_mmio_read32(trio_context->mmio_base_mac +
588 reg_offset);
589 rc_dev_cap.mps_sup = 1;
590 __gxio_mmio_write32(trio_context->mmio_base_mac + reg_offset,
591 rc_dev_cap.word);
592
593 /* Configure PCI Express MPS setting. */
594 list_for_each_entry(child, &root_bus->children, node)
595 pcie_bus_configure_settings(child);
596
597 /*
598 * Set the mac_config register in trio based on the MPS/MRS of the link.
599 */
600 reg_offset =
601 (TRIO_PCIE_RC_DEVICE_CONTROL <<
602 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
603 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD <<
604 TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) |
605 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
606
607 dev_control.word = __gxio_mmio_read32(trio_context->mmio_base_mac +
608 reg_offset);
609
610 err = gxio_trio_set_mps_mrs(trio_context,
611 dev_control.max_payload_size,
612 dev_control.max_read_req_sz,
613 mac);
614 if (err < 0) {
615 pr_err("PCI: PCIE_CONFIGURE_MAC_MPS_MRS failure, MAC %d on TRIO %d\n",
616 mac, controller->trio_index);
617 }
618}
619
620static int setup_pcie_rc_delay(char *str)
621{
622 unsigned long delay = 0;
623 unsigned long trio_index;
624 unsigned long mac;
625
626 if (str == NULL || !isdigit(*str))
627 return -EINVAL;
628 trio_index = simple_strtoul(str, (char **)&str, 10);
629 if (trio_index >= TILEGX_NUM_TRIO)
630 return -EINVAL;
631
632 if (*str != ',')
633 return -EINVAL;
634
635 str++;
636 if (!isdigit(*str))
637 return -EINVAL;
638 mac = simple_strtoul(str, (char **)&str, 10);
639 if (mac >= TILEGX_TRIO_PCIES)
640 return -EINVAL;
641
642 if (*str != '\0') {
643 if (*str != ',')
644 return -EINVAL;
645
646 str++;
647 if (!isdigit(*str))
648 return -EINVAL;
649 delay = simple_strtoul(str, (char **)&str, 10);
650 }
651
652 rc_delay[trio_index][mac] = delay ? : DEFAULT_RC_DELAY;
653 return 0;
654}
655early_param("pcie_rc_delay", setup_pcie_rc_delay);
656
657/* PCI initialization entry point, called by subsys_initcall. */
658int __init pcibios_init(void)
659{
660 resource_size_t offset;
661 LIST_HEAD(resources);
662 int next_busno;
663 struct pci_host_bridge *bridge;
664 int i;
665
666 tile_pci_init();
667
668 if (num_rc_controllers == 0)
669 return 0;
670
671 /*
672 * Delay a bit in case devices aren't ready. Some devices are
673 * known to require at least 20ms here, but we use a more
674 * conservative value.
675 */
676 msleep(250);
677
678 /* Scan all of the recorded PCI controllers. */
679 for (next_busno = 0, i = 0; i < num_rc_controllers; i++) {
680 struct pci_controller *controller = &pci_controllers[i];
681 gxio_trio_context_t *trio_context = controller->trio;
682 TRIO_PCIE_INTFC_PORT_STATUS_t port_status;
683 TRIO_PCIE_INTFC_TX_FIFO_CTL_t tx_fifo_ctl;
684 struct pci_bus *bus;
685 unsigned int reg_offset;
686 unsigned int class_code_revision;
687 int trio_index;
688 int mac;
689 int ret;
690
691 if (trio_context->fd < 0)
692 continue;
693
694 trio_index = controller->trio_index;
695 mac = controller->mac;
696
697 /*
698 * Check for PCIe link-up status to decide if we need
699 * to force the link to come up.
700 */
701 reg_offset =
702 (TRIO_PCIE_INTFC_PORT_STATUS <<
703 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
704 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE <<
705 TRIO_CFG_REGION_ADDR__INTFC_SHIFT) |
706 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
707
708 port_status.word =
709 __gxio_mmio_read(trio_context->mmio_base_mac +
710 reg_offset);
711 if (!port_status.dl_up) {
712 if (rc_delay[trio_index][mac]) {
713 pr_info("Delaying PCIe RC TRIO init %d sec on MAC %d on TRIO %d\n",
714 rc_delay[trio_index][mac], mac,
715 trio_index);
716 msleep(rc_delay[trio_index][mac] * 1000);
717 }
718 ret = gxio_trio_force_rc_link_up(trio_context, mac);
719 if (ret < 0)
720 pr_err("PCI: PCIE_FORCE_LINK_UP failure, MAC %d on TRIO %d\n",
721 mac, trio_index);
722 }
723
724 pr_info("PCI: Found PCI controller #%d on TRIO %d MAC %d\n",
725 i, trio_index, controller->mac);
726
727 /* Delay the bus probe if needed. */
728 if (rc_delay[trio_index][mac]) {
729 pr_info("Delaying PCIe RC bus enumerating %d sec on MAC %d on TRIO %d\n",
730 rc_delay[trio_index][mac], mac, trio_index);
731 msleep(rc_delay[trio_index][mac] * 1000);
732 } else {
733 /*
734 * Wait a bit here because some EP devices
735 * take longer to come up.
736 */
737 msleep(1000);
738 }
739
740 /* Check for PCIe link-up status again. */
741 port_status.word =
742 __gxio_mmio_read(trio_context->mmio_base_mac +
743 reg_offset);
744 if (!port_status.dl_up) {
745 if (pcie_ports[trio_index].ports[mac].removable) {
746 pr_info("PCI: link is down, MAC %d on TRIO %d\n",
747 mac, trio_index);
748 pr_info("This is expected if no PCIe card is connected to this link\n");
749 } else
750 pr_err("PCI: link is down, MAC %d on TRIO %d\n",
751 mac, trio_index);
752 continue;
753 }
754
755 /*
756 * Ensure that the link can come out of L1 power down state.
757 * Strictly speaking, this is needed only in the case of
758 * heavy RC-initiated DMAs.
759 */
760 reg_offset =
761 (TRIO_PCIE_INTFC_TX_FIFO_CTL <<
762 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
763 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_INTERFACE <<
764 TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) |
765 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
766 tx_fifo_ctl.word =
767 __gxio_mmio_read(trio_context->mmio_base_mac +
768 reg_offset);
769 tx_fifo_ctl.min_p_credits = 0;
770 __gxio_mmio_write(trio_context->mmio_base_mac + reg_offset,
771 tx_fifo_ctl.word);
772
773 /*
774 * Change the device ID so that Linux bus crawl doesn't confuse
775 * the internal bridge with any Tilera endpoints.
776 */
777 reg_offset =
778 (TRIO_PCIE_RC_DEVICE_ID_VEN_ID <<
779 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
780 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD <<
781 TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) |
782 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
783
784 __gxio_mmio_write32(trio_context->mmio_base_mac + reg_offset,
785 (TILERA_GX36_RC_DEV_ID <<
786 TRIO_PCIE_RC_DEVICE_ID_VEN_ID__DEV_ID_SHIFT) |
787 TILERA_VENDOR_ID);
788
789 /* Set the internal P2P bridge class code. */
790 reg_offset =
791 (TRIO_PCIE_RC_REVISION_ID <<
792 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
793 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_STANDARD <<
794 TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) |
795 (mac << TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
796
797 class_code_revision =
798 __gxio_mmio_read32(trio_context->mmio_base_mac +
799 reg_offset);
800 class_code_revision = (class_code_revision & 0xff) |
801 (PCI_CLASS_BRIDGE_PCI << 16);
802
803 __gxio_mmio_write32(trio_context->mmio_base_mac +
804 reg_offset, class_code_revision);
805
806#ifdef USE_SHARED_PCIE_CONFIG_REGION
807
808 /* Map in the MMIO space for the PIO region. */
809 offset = HV_TRIO_PIO_OFFSET(trio_context->pio_cfg_index) |
810 (((unsigned long long)mac) <<
811 TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR__MAC_SHIFT);
812
813#else
814
815 /* Alloc a PIO region for PCI config access per MAC. */
816 ret = gxio_trio_alloc_pio_regions(trio_context, 1, 0, 0);
817 if (ret < 0) {
818 pr_err("PCI: PCI CFG PIO alloc failure for mac %d on TRIO %d, give up\n",
819 mac, trio_index);
820
821 continue;
822 }
823
824 trio_context->pio_cfg_index[mac] = ret;
825
826 /* For PIO CFG, the bus_address_hi parameter is 0. */
827 ret = gxio_trio_init_pio_region_aux(trio_context,
828 trio_context->pio_cfg_index[mac],
829 mac, 0, HV_TRIO_PIO_FLAG_CONFIG_SPACE);
830 if (ret < 0) {
831 pr_err("PCI: PCI CFG PIO init failure for mac %d on TRIO %d, give up\n",
832 mac, trio_index);
833
834 continue;
835 }
836
837 offset = HV_TRIO_PIO_OFFSET(trio_context->pio_cfg_index[mac]) |
838 (((unsigned long long)mac) <<
839 TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR__MAC_SHIFT);
840
841#endif
842
843 /*
844 * To save VMALLOC space, we take advantage of the fact that
845 * bit 29 in the PIO CFG address format is reserved 0. With
846 * TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR__MAC_SHIFT being 30,
847 * this cuts VMALLOC space usage from 1GB to 512MB per mac.
848 */
849 trio_context->mmio_base_pio_cfg[mac] =
850 iorpc_ioremap(trio_context->fd, offset, (1UL <<
851 (TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR__MAC_SHIFT - 1)));
852 if (trio_context->mmio_base_pio_cfg[mac] == NULL) {
853 pr_err("PCI: PIO map failure for mac %d on TRIO %d\n",
854 mac, trio_index);
855
856 continue;
857 }
858
859 /* Initialize the PCIe interrupts. */
860 if (tile_init_irqs(controller)) {
861 pr_err("PCI: IRQs init failure for mac %d on TRIO %d\n",
862 mac, trio_index);
863
864 continue;
865 }
866
867 /*
868 * The PCI memory resource is located above the PA space.
869 * The memory range for the PCI root bus should not overlap
870 * with the physical RAM.
871 */
872 pci_add_resource_offset(&resources, &controller->mem_space,
873 controller->mem_offset);
874 pci_add_resource(&resources, &controller->io_space);
875 controller->first_busno = next_busno;
876
877 bridge = pci_alloc_host_bridge(0);
878 if (!bridge)
879 break;
880
881 list_splice_init(&resources, &bridge->windows);
882 bridge->dev.parent = NULL;
883 bridge->sysdata = controller;
884 bridge->busnr = next_busno;
885 bridge->ops = controller->ops;
886 bridge->swizzle_irq = pci_common_swizzle;
887 bridge->map_irq = tile_map_irq;
888
889 pci_scan_root_bus_bridge(bridge);
890 bus = bridge->bus;
891 controller->root_bus = bus;
892 next_busno = bus->busn_res.end + 1;
893 }
894
895 /*
896 * This comes from the generic Linux PCI driver.
897 *
898 * It allocates all of the resources (I/O memory, etc)
899 * associated with the devices read in above.
900 */
901 pci_assign_unassigned_resources();
902
903 /* Record the I/O resources in the PCI controller structure. */
904 for (i = 0; i < num_rc_controllers; i++) {
905 struct pci_controller *controller = &pci_controllers[i];
906 gxio_trio_context_t *trio_context = controller->trio;
907 struct pci_bus *root_bus = pci_controllers[i].root_bus;
908 int ret;
909 int j;
910
911 /*
912 * Skip controllers that are not properly initialized or
913 * have down links.
914 */
915 if (root_bus == NULL)
916 continue;
917
918 /* Configure the max_payload_size values for this domain. */
919 fixup_read_and_payload_sizes(controller);
920
921 /* Alloc a PIO region for PCI memory access for each RC port. */
922 ret = gxio_trio_alloc_pio_regions(trio_context, 1, 0, 0);
923 if (ret < 0) {
924 pr_err("PCI: MEM PIO alloc failure on TRIO %d mac %d, give up\n",
925 controller->trio_index, controller->mac);
926
927 continue;
928 }
929
930 controller->pio_mem_index = ret;
931
932 /*
933 * For PIO MEM, the bus_address_hi parameter is hard-coded 0
934 * because we always assign 32-bit PCI bus BAR ranges.
935 */
936 ret = gxio_trio_init_pio_region_aux(trio_context,
937 controller->pio_mem_index,
938 controller->mac,
939 0,
940 0);
941 if (ret < 0) {
942 pr_err("PCI: MEM PIO init failure on TRIO %d mac %d, give up\n",
943 controller->trio_index, controller->mac);
944
945 continue;
946 }
947
948#ifdef CONFIG_TILE_PCI_IO
949 /*
950 * Alloc a PIO region for PCI I/O space access for each RC port.
951 */
952 ret = gxio_trio_alloc_pio_regions(trio_context, 1, 0, 0);
953 if (ret < 0) {
954 pr_err("PCI: I/O PIO alloc failure on TRIO %d mac %d, give up\n",
955 controller->trio_index, controller->mac);
956
957 continue;
958 }
959
960 controller->pio_io_index = ret;
961
962 /*
963 * For PIO IO, the bus_address_hi parameter is hard-coded 0
964 * because PCI I/O address space is 32-bit.
965 */
966 ret = gxio_trio_init_pio_region_aux(trio_context,
967 controller->pio_io_index,
968 controller->mac,
969 0,
970 HV_TRIO_PIO_FLAG_IO_SPACE);
971 if (ret < 0) {
972 pr_err("PCI: I/O PIO init failure on TRIO %d mac %d, give up\n",
973 controller->trio_index, controller->mac);
974
975 continue;
976 }
977#endif
978
979 /*
980 * Configure a Mem-Map region for each memory controller so
981 * that Linux can map all of its PA space to the PCI bus.
982 * Use the IOMMU to handle hash-for-home memory.
983 */
984 for_each_online_node(j) {
985 unsigned long start_pfn = node_start_pfn[j];
986 unsigned long end_pfn = node_end_pfn[j];
987 unsigned long nr_pages = end_pfn - start_pfn;
988
989 ret = gxio_trio_alloc_memory_maps(trio_context, 1, 0,
990 0);
991 if (ret < 0) {
992 pr_err("PCI: Mem-Map alloc failure on TRIO %d mac %d for MC %d, give up\n",
993 controller->trio_index, controller->mac,
994 j);
995
996 goto alloc_mem_map_failed;
997 }
998
999 controller->mem_maps[j] = ret;
1000
1001 /*
1002 * Initialize the Mem-Map and the I/O MMU so that all
1003 * the physical memory can be accessed by the endpoint
1004 * devices. The base bus address is set to the base CPA
1005 * of this memory controller plus an offset (see pci.h).
1006 * The region's base VA is set to the base CPA. The
1007 * I/O MMU table essentially translates the CPA to
1008 * the real PA. Implicitly, for node 0, we create
1009 * a separate Mem-Map region that serves as the inbound
1010 * window for legacy 32-bit devices. This is a direct
1011 * map of the low 4GB CPA space.
1012 */
1013 ret = gxio_trio_init_memory_map_mmu_aux(trio_context,
1014 controller->mem_maps[j],
1015 start_pfn << PAGE_SHIFT,
1016 nr_pages << PAGE_SHIFT,
1017 trio_context->asid,
1018 controller->mac,
1019 (start_pfn << PAGE_SHIFT) +
1020 TILE_PCI_MEM_MAP_BASE_OFFSET,
1021 j,
1022 GXIO_TRIO_ORDER_MODE_UNORDERED);
1023 if (ret < 0) {
1024 pr_err("PCI: Mem-Map init failure on TRIO %d mac %d for MC %d, give up\n",
1025 controller->trio_index, controller->mac,
1026 j);
1027
1028 goto alloc_mem_map_failed;
1029 }
1030 continue;
1031
1032alloc_mem_map_failed:
1033 break;
1034 }
1035
1036 pci_bus_add_devices(root_bus);
1037 }
1038
1039 return 0;
1040}
1041subsys_initcall(pcibios_init);
1042
1043/* Process any "pci=" kernel boot arguments. */
1044char *__init pcibios_setup(char *str)
1045{
1046 if (!strcmp(str, "off")) {
1047 pci_probe = 0;
1048 return NULL;
1049 }
1050 return str;
1051}
1052
1053/*
1054 * Called for each device after PCI setup is done.
1055 * We initialize the PCI device capabilities conservatively, assuming that
1056 * all devices can only address the 32-bit DMA space. The exception here is
1057 * that the device dma_offset is set to the value that matches the 64-bit
1058 * capable devices. This is OK because dma_offset is not used by legacy
1059 * dma_ops, nor by the hybrid dma_ops's streaming DMAs, which are 64-bit ops.
1060 * This implementation matches the kernel design of setting PCI devices'
1061 * coherent_dma_mask to 0xffffffffull by default, allowing the device drivers
1062 * to skip calling pci_set_consistent_dma_mask(DMA_BIT_MASK(32)).
1063 */
1064static void pcibios_fixup_final(struct pci_dev *pdev)
1065{
1066 set_dma_ops(&pdev->dev, gx_legacy_pci_dma_map_ops);
1067 set_dma_offset(&pdev->dev, TILE_PCI_MEM_MAP_BASE_OFFSET);
1068 pdev->dev.archdata.max_direct_dma_addr =
1069 TILE_PCI_MAX_DIRECT_DMA_ADDRESS;
1070 pdev->dev.coherent_dma_mask = TILE_PCI_MAX_DIRECT_DMA_ADDRESS;
1071}
1072DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_final);
1073
1074/* Map a PCI MMIO bus address into VA space. */
1075void __iomem *ioremap(resource_size_t phys_addr, unsigned long size)
1076{
1077 struct pci_controller *controller = NULL;
1078 resource_size_t bar_start;
1079 resource_size_t bar_end;
1080 resource_size_t offset;
1081 resource_size_t start;
1082 resource_size_t end;
1083 int trio_fd;
1084 int i;
1085
1086 start = phys_addr;
1087 end = phys_addr + size - 1;
1088
1089 /*
1090 * By searching phys_addr in each controller's mem_space, we can
1091 * determine the controller that should accept the PCI memory access.
1092 */
1093 for (i = 0; i < num_rc_controllers; i++) {
1094 /*
1095 * Skip controllers that are not properly initialized or
1096 * have down links.
1097 */
1098 if (pci_controllers[i].root_bus == NULL)
1099 continue;
1100
1101 bar_start = pci_controllers[i].mem_space.start;
1102 bar_end = pci_controllers[i].mem_space.end;
1103
1104 if ((start >= bar_start) && (end <= bar_end)) {
1105 controller = &pci_controllers[i];
1106 break;
1107 }
1108 }
1109
1110 if (controller == NULL)
1111 return NULL;
1112
1113 trio_fd = controller->trio->fd;
1114
1115 /* Convert the resource start to the bus address offset. */
1116 start = phys_addr - controller->mem_offset;
1117
1118 offset = HV_TRIO_PIO_OFFSET(controller->pio_mem_index) + start;
1119
1120 /* We need to keep the PCI bus address's in-page offset in the VA. */
1121 return iorpc_ioremap(trio_fd, offset, size) +
1122 (start & (PAGE_SIZE - 1));
1123}
1124EXPORT_SYMBOL(ioremap);
1125
1126#ifdef CONFIG_TILE_PCI_IO
1127/* Map a PCI I/O address into VA space. */
1128void __iomem *ioport_map(unsigned long port, unsigned int size)
1129{
1130 struct pci_controller *controller = NULL;
1131 resource_size_t bar_start;
1132 resource_size_t bar_end;
1133 resource_size_t offset;
1134 resource_size_t start;
1135 resource_size_t end;
1136 int trio_fd;
1137 int i;
1138
1139 start = port;
1140 end = port + size - 1;
1141
1142 /*
1143 * By searching the port in each controller's io_space, we can
1144 * determine the controller that should accept the PCI I/O access.
1145 */
1146 for (i = 0; i < num_rc_controllers; i++) {
1147 /*
1148 * Skip controllers that are not properly initialized or
1149 * have down links.
1150 */
1151 if (pci_controllers[i].root_bus == NULL)
1152 continue;
1153
1154 bar_start = pci_controllers[i].io_space.start;
1155 bar_end = pci_controllers[i].io_space.end;
1156
1157 if ((start >= bar_start) && (end <= bar_end)) {
1158 controller = &pci_controllers[i];
1159 break;
1160 }
1161 }
1162
1163 if (controller == NULL)
1164 return NULL;
1165
1166 trio_fd = controller->trio->fd;
1167
1168 /* Convert the resource start to the bus address offset. */
1169 port -= controller->io_space.start;
1170
1171 offset = HV_TRIO_PIO_OFFSET(controller->pio_io_index) + port;
1172
1173 /* We need to keep the PCI bus address's in-page offset in the VA. */
1174 return iorpc_ioremap(trio_fd, offset, size) + (port & (PAGE_SIZE - 1));
1175}
1176EXPORT_SYMBOL(ioport_map);
1177
1178void ioport_unmap(void __iomem *addr)
1179{
1180 iounmap(addr);
1181}
1182EXPORT_SYMBOL(ioport_unmap);
1183#endif
1184
1185void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
1186{
1187 iounmap(addr);
1188}
1189EXPORT_SYMBOL(pci_iounmap);
1190
1191/****************************************************************
1192 *
1193 * Tile PCI config space read/write routines
1194 *
1195 ****************************************************************/
1196
1197/*
1198 * These are the normal read and write ops
1199 * These are expanded with macros from pci_bus_read_config_byte() etc.
1200 *
1201 * devfn is the combined PCI device & function.
1202 *
1203 * offset is in bytes, from the start of config space for the
1204 * specified bus & device.
1205 */
1206static int tile_cfg_read(struct pci_bus *bus, unsigned int devfn, int offset,
1207 int size, u32 *val)
1208{
1209 struct pci_controller *controller = bus->sysdata;
1210 gxio_trio_context_t *trio_context = controller->trio;
1211 int busnum = bus->number & 0xff;
1212 int device = PCI_SLOT(devfn);
1213 int function = PCI_FUNC(devfn);
1214 int config_type = 1;
1215 TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR_t cfg_addr;
1216 void *mmio_addr;
1217
1218 /*
1219 * Map all accesses to the local device on root bus into the
1220 * MMIO space of the MAC. Accesses to the downstream devices
1221 * go to the PIO space.
1222 */
1223 if (pci_is_root_bus(bus)) {
1224 if (device == 0) {
1225 /*
1226 * This is the internal downstream P2P bridge,
1227 * access directly.
1228 */
1229 unsigned int reg_offset;
1230
1231 reg_offset = ((offset & 0xFFF) <<
1232 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
1233 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_PROTECTED
1234 << TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) |
1235 (controller->mac <<
1236 TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
1237
1238 mmio_addr = trio_context->mmio_base_mac + reg_offset;
1239
1240 goto valid_device;
1241
1242 } else {
1243 /*
1244 * We fake an empty device for (device > 0),
1245 * since there is only one device on bus 0.
1246 */
1247 goto invalid_device;
1248 }
1249 }
1250
1251 /*
1252 * Accesses to the directly attached device have to be
1253 * sent as type-0 configs.
1254 */
1255 if (busnum == (controller->first_busno + 1)) {
1256 /*
1257 * There is only one device off of our built-in P2P bridge.
1258 */
1259 if (device != 0)
1260 goto invalid_device;
1261
1262 config_type = 0;
1263 }
1264
1265 cfg_addr.word = 0;
1266 cfg_addr.reg_addr = (offset & 0xFFF);
1267 cfg_addr.fn = function;
1268 cfg_addr.dev = device;
1269 cfg_addr.bus = busnum;
1270 cfg_addr.type = config_type;
1271
1272 /*
1273 * Note that we don't set the mac field in cfg_addr because the
1274 * mapping is per port.
1275 */
1276 mmio_addr = trio_context->mmio_base_pio_cfg[controller->mac] +
1277 cfg_addr.word;
1278
1279valid_device:
1280
1281 switch (size) {
1282 case 4:
1283 *val = __gxio_mmio_read32(mmio_addr);
1284 break;
1285
1286 case 2:
1287 *val = __gxio_mmio_read16(mmio_addr);
1288 break;
1289
1290 case 1:
1291 *val = __gxio_mmio_read8(mmio_addr);
1292 break;
1293
1294 default:
1295 return PCIBIOS_FUNC_NOT_SUPPORTED;
1296 }
1297
1298 TRACE_CFG_RD(size, *val, busnum, device, function, offset);
1299
1300 return 0;
1301
1302invalid_device:
1303
1304 switch (size) {
1305 case 4:
1306 *val = 0xFFFFFFFF;
1307 break;
1308
1309 case 2:
1310 *val = 0xFFFF;
1311 break;
1312
1313 case 1:
1314 *val = 0xFF;
1315 break;
1316
1317 default:
1318 return PCIBIOS_FUNC_NOT_SUPPORTED;
1319 }
1320
1321 return 0;
1322}
1323
1324
1325/*
1326 * See tile_cfg_read() for relevant comments.
1327 * Note that "val" is the value to write, not a pointer to that value.
1328 */
1329static int tile_cfg_write(struct pci_bus *bus, unsigned int devfn, int offset,
1330 int size, u32 val)
1331{
1332 struct pci_controller *controller = bus->sysdata;
1333 gxio_trio_context_t *trio_context = controller->trio;
1334 int busnum = bus->number & 0xff;
1335 int device = PCI_SLOT(devfn);
1336 int function = PCI_FUNC(devfn);
1337 int config_type = 1;
1338 TRIO_TILE_PIO_REGION_SETUP_CFG_ADDR_t cfg_addr;
1339 void *mmio_addr;
1340 u32 val_32 = (u32)val;
1341 u16 val_16 = (u16)val;
1342 u8 val_8 = (u8)val;
1343
1344 /*
1345 * Map all accesses to the local device on root bus into the
1346 * MMIO space of the MAC. Accesses to the downstream devices
1347 * go to the PIO space.
1348 */
1349 if (pci_is_root_bus(bus)) {
1350 if (device == 0) {
1351 /*
1352 * This is the internal downstream P2P bridge,
1353 * access directly.
1354 */
1355 unsigned int reg_offset;
1356
1357 reg_offset = ((offset & 0xFFF) <<
1358 TRIO_CFG_REGION_ADDR__REG_SHIFT) |
1359 (TRIO_CFG_REGION_ADDR__INTFC_VAL_MAC_PROTECTED
1360 << TRIO_CFG_REGION_ADDR__INTFC_SHIFT ) |
1361 (controller->mac <<
1362 TRIO_CFG_REGION_ADDR__MAC_SEL_SHIFT);
1363
1364 mmio_addr = trio_context->mmio_base_mac + reg_offset;
1365
1366 goto valid_device;
1367
1368 } else {
1369 /*
1370 * We fake an empty device for (device > 0),
1371 * since there is only one device on bus 0.
1372 */
1373 goto invalid_device;
1374 }
1375 }
1376
1377 /*
1378 * Accesses to the directly attached device have to be
1379 * sent as type-0 configs.
1380 */
1381 if (busnum == (controller->first_busno + 1)) {
1382 /*
1383 * There is only one device off of our built-in P2P bridge.
1384 */
1385 if (device != 0)
1386 goto invalid_device;
1387
1388 config_type = 0;
1389 }
1390
1391 cfg_addr.word = 0;
1392 cfg_addr.reg_addr = (offset & 0xFFF);
1393 cfg_addr.fn = function;
1394 cfg_addr.dev = device;
1395 cfg_addr.bus = busnum;
1396 cfg_addr.type = config_type;
1397
1398 /*
1399 * Note that we don't set the mac field in cfg_addr because the
1400 * mapping is per port.
1401 */
1402 mmio_addr = trio_context->mmio_base_pio_cfg[controller->mac] +
1403 cfg_addr.word;
1404
1405valid_device:
1406
1407 switch (size) {
1408 case 4:
1409 __gxio_mmio_write32(mmio_addr, val_32);
1410 TRACE_CFG_WR(size, val_32, busnum, device, function, offset);
1411 break;
1412
1413 case 2:
1414 __gxio_mmio_write16(mmio_addr, val_16);
1415 TRACE_CFG_WR(size, val_16, busnum, device, function, offset);
1416 break;
1417
1418 case 1:
1419 __gxio_mmio_write8(mmio_addr, val_8);
1420 TRACE_CFG_WR(size, val_8, busnum, device, function, offset);
1421 break;
1422
1423 default:
1424 return PCIBIOS_FUNC_NOT_SUPPORTED;
1425 }
1426
1427invalid_device:
1428
1429 return 0;
1430}
1431
1432
1433static struct pci_ops tile_cfg_ops = {
1434 .read = tile_cfg_read,
1435 .write = tile_cfg_write,
1436};
1437
1438
1439/* MSI support starts here. */
1440static unsigned int tilegx_msi_startup(struct irq_data *d)
1441{
1442 if (irq_data_get_msi_desc(d))
1443 pci_msi_unmask_irq(d);
1444
1445 return 0;
1446}
1447
1448static void tilegx_msi_ack(struct irq_data *d)
1449{
1450 __insn_mtspr(SPR_IPI_EVENT_RESET_K, 1UL << d->irq);
1451}
1452
1453static void tilegx_msi_mask(struct irq_data *d)
1454{
1455 pci_msi_mask_irq(d);
1456 __insn_mtspr(SPR_IPI_MASK_SET_K, 1UL << d->irq);
1457}
1458
1459static void tilegx_msi_unmask(struct irq_data *d)
1460{
1461 __insn_mtspr(SPR_IPI_MASK_RESET_K, 1UL << d->irq);
1462 pci_msi_unmask_irq(d);
1463}
1464
1465static struct irq_chip tilegx_msi_chip = {
1466 .name = "tilegx_msi",
1467 .irq_startup = tilegx_msi_startup,
1468 .irq_ack = tilegx_msi_ack,
1469 .irq_mask = tilegx_msi_mask,
1470 .irq_unmask = tilegx_msi_unmask,
1471
1472 /* TBD: support set_affinity. */
1473};
1474
1475int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
1476{
1477 struct pci_controller *controller;
1478 gxio_trio_context_t *trio_context;
1479 struct msi_msg msg;
1480 int default_irq;
1481 uint64_t mem_map_base;
1482 uint64_t mem_map_limit;
1483 u64 msi_addr;
1484 int mem_map;
1485 int cpu;
1486 int irq;
1487 int ret;
1488
1489 irq = irq_alloc_hwirq(-1);
1490 if (!irq)
1491 return -ENOSPC;
1492
1493 /*
1494 * Since we use a 64-bit Mem-Map to accept the MSI write, we fail
1495 * devices that are not capable of generating a 64-bit message address.
1496 * These devices will fall back to using the legacy interrupts.
1497 * Most PCIe endpoint devices do support 64-bit message addressing.
1498 */
1499 if (desc->msi_attrib.is_64 == 0) {
1500 dev_info(&pdev->dev, "64-bit MSI message address not supported, falling back to legacy interrupts\n");
1501
1502 ret = -ENOMEM;
1503 goto is_64_failure;
1504 }
1505
1506 default_irq = desc->msi_attrib.default_irq;
1507 controller = irq_get_handler_data(default_irq);
1508
1509 BUG_ON(!controller);
1510
1511 trio_context = controller->trio;
1512
1513 /*
1514 * Allocate a scatter-queue that will accept the MSI write and
1515 * trigger the TILE-side interrupts. We use the scatter-queue regions
1516 * before the mem map regions, because the latter are needed by more
1517 * applications.
1518 */
1519 mem_map = gxio_trio_alloc_scatter_queues(trio_context, 1, 0, 0);
1520 if (mem_map >= 0) {
1521 TRIO_MAP_SQ_DOORBELL_FMT_t doorbell_template = {{
1522 .pop = 0,
1523 .doorbell = 1,
1524 }};
1525
1526 mem_map += TRIO_NUM_MAP_MEM_REGIONS;
1527 mem_map_base = MEM_MAP_INTR_REGIONS_BASE +
1528 mem_map * MEM_MAP_INTR_REGION_SIZE;
1529 mem_map_limit = mem_map_base + MEM_MAP_INTR_REGION_SIZE - 1;
1530
1531 msi_addr = mem_map_base + MEM_MAP_INTR_REGION_SIZE - 8;
1532 msg.data = (unsigned int)doorbell_template.word;
1533 } else {
1534 /* SQ regions are out, allocate from map mem regions. */
1535 mem_map = gxio_trio_alloc_memory_maps(trio_context, 1, 0, 0);
1536 if (mem_map < 0) {
1537 dev_info(&pdev->dev, "%s Mem-Map alloc failure - failed to initialize MSI interrupts - falling back to legacy interrupts\n",
1538 desc->msi_attrib.is_msix ? "MSI-X" : "MSI");
1539 ret = -ENOMEM;
1540 goto msi_mem_map_alloc_failure;
1541 }
1542
1543 mem_map_base = MEM_MAP_INTR_REGIONS_BASE +
1544 mem_map * MEM_MAP_INTR_REGION_SIZE;
1545 mem_map_limit = mem_map_base + MEM_MAP_INTR_REGION_SIZE - 1;
1546
1547 msi_addr = mem_map_base + TRIO_MAP_MEM_REG_INT3 -
1548 TRIO_MAP_MEM_REG_INT0;
1549
1550 msg.data = mem_map;
1551 }
1552
1553 /* We try to distribute different IRQs to different tiles. */
1554 cpu = tile_irq_cpu(irq);
1555
1556 /*
1557 * Now call up to the HV to configure the MSI interrupt and
1558 * set up the IPI binding.
1559 */
1560 ret = gxio_trio_config_msi_intr(trio_context, cpu_x(cpu), cpu_y(cpu),
1561 KERNEL_PL, irq, controller->mac,
1562 mem_map, mem_map_base, mem_map_limit,
1563 trio_context->asid);
1564 if (ret < 0) {
1565 dev_info(&pdev->dev, "HV MSI config failed\n");
1566
1567 goto hv_msi_config_failure;
1568 }
1569
1570 irq_set_msi_desc(irq, desc);
1571
1572 msg.address_hi = msi_addr >> 32;
1573 msg.address_lo = msi_addr & 0xffffffff;
1574
1575 pci_write_msi_msg(irq, &msg);
1576 irq_set_chip_and_handler(irq, &tilegx_msi_chip, handle_level_irq);
1577 irq_set_handler_data(irq, controller);
1578
1579 return 0;
1580
1581hv_msi_config_failure:
1582 /* Free mem-map */
1583msi_mem_map_alloc_failure:
1584is_64_failure:
1585 irq_free_hwirq(irq);
1586 return ret;
1587}
1588
1589void arch_teardown_msi_irq(unsigned int irq)
1590{
1591 irq_free_hwirq(irq);
1592}
diff --git a/arch/tile/kernel/perf_event.c b/arch/tile/kernel/perf_event.c
deleted file mode 100644
index 6394c1ccb68e..000000000000
--- a/arch/tile/kernel/perf_event.c
+++ /dev/null
@@ -1,1005 +0,0 @@
1/*
2 * Copyright 2014 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 *
15 * Perf_events support for Tile processor.
16 *
17 * This code is based upon the x86 perf event
18 * code, which is:
19 *
20 * Copyright (C) 2008 Thomas Gleixner <tglx@linutronix.de>
21 * Copyright (C) 2008-2009 Red Hat, Inc., Ingo Molnar
22 * Copyright (C) 2009 Jaswinder Singh Rajput
23 * Copyright (C) 2009 Advanced Micro Devices, Inc., Robert Richter
24 * Copyright (C) 2008-2009 Red Hat, Inc., Peter Zijlstra
25 * Copyright (C) 2009 Intel Corporation, <markus.t.metzger@intel.com>
26 * Copyright (C) 2009 Google, Inc., Stephane Eranian
27 */
28
29#include <linux/kprobes.h>
30#include <linux/kernel.h>
31#include <linux/kdebug.h>
32#include <linux/mutex.h>
33#include <linux/bitmap.h>
34#include <linux/irq.h>
35#include <linux/interrupt.h>
36#include <linux/perf_event.h>
37#include <linux/atomic.h>
38#include <asm/traps.h>
39#include <asm/stack.h>
40#include <asm/pmc.h>
41#include <hv/hypervisor.h>
42
43#define TILE_MAX_COUNTERS 4
44
45#define PERF_COUNT_0_IDX 0
46#define PERF_COUNT_1_IDX 1
47#define AUX_PERF_COUNT_0_IDX 2
48#define AUX_PERF_COUNT_1_IDX 3
49
50struct cpu_hw_events {
51 int n_events;
52 struct perf_event *events[TILE_MAX_COUNTERS]; /* counter order */
53 struct perf_event *event_list[TILE_MAX_COUNTERS]; /* enabled
54 order */
55 int assign[TILE_MAX_COUNTERS];
56 unsigned long active_mask[BITS_TO_LONGS(TILE_MAX_COUNTERS)];
57 unsigned long used_mask;
58};
59
60/* TILE arch specific performance monitor unit */
61struct tile_pmu {
62 const char *name;
63 int version;
64 const int *hw_events; /* generic hw events table */
65 /* generic hw cache events table */
66 const int (*cache_events)[PERF_COUNT_HW_CACHE_MAX]
67 [PERF_COUNT_HW_CACHE_OP_MAX]
68 [PERF_COUNT_HW_CACHE_RESULT_MAX];
69 int (*map_hw_event)(u64); /*method used to map
70 hw events */
71 int (*map_cache_event)(u64); /*method used to map
72 cache events */
73
74 u64 max_period; /* max sampling period */
75 u64 cntval_mask; /* counter width mask */
76 int cntval_bits; /* counter width */
77 int max_events; /* max generic hw events
78 in map */
79 int num_counters; /* number base + aux counters */
80 int num_base_counters; /* number base counters */
81};
82
83DEFINE_PER_CPU(u64, perf_irqs);
84static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events);
85
86#define TILE_OP_UNSUPP (-1)
87
88#ifndef __tilegx__
89/* TILEPro hardware events map */
90static const int tile_hw_event_map[] = {
91 [PERF_COUNT_HW_CPU_CYCLES] = 0x01, /* ONE */
92 [PERF_COUNT_HW_INSTRUCTIONS] = 0x06, /* MP_BUNDLE_RETIRED */
93 [PERF_COUNT_HW_CACHE_REFERENCES] = TILE_OP_UNSUPP,
94 [PERF_COUNT_HW_CACHE_MISSES] = TILE_OP_UNSUPP,
95 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x16, /*
96 MP_CONDITIONAL_BRANCH_ISSUED */
97 [PERF_COUNT_HW_BRANCH_MISSES] = 0x14, /*
98 MP_CONDITIONAL_BRANCH_MISSPREDICT */
99 [PERF_COUNT_HW_BUS_CYCLES] = TILE_OP_UNSUPP,
100};
101#else
102/* TILEGx hardware events map */
103static const int tile_hw_event_map[] = {
104 [PERF_COUNT_HW_CPU_CYCLES] = 0x181, /* ONE */
105 [PERF_COUNT_HW_INSTRUCTIONS] = 0xdb, /* INSTRUCTION_BUNDLE */
106 [PERF_COUNT_HW_CACHE_REFERENCES] = TILE_OP_UNSUPP,
107 [PERF_COUNT_HW_CACHE_MISSES] = TILE_OP_UNSUPP,
108 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0xd9, /*
109 COND_BRANCH_PRED_CORRECT */
110 [PERF_COUNT_HW_BRANCH_MISSES] = 0xda, /*
111 COND_BRANCH_PRED_INCORRECT */
112 [PERF_COUNT_HW_BUS_CYCLES] = TILE_OP_UNSUPP,
113};
114#endif
115
116#define C(x) PERF_COUNT_HW_CACHE_##x
117
118/*
119 * Generalized hw caching related hw_event table, filled
120 * in on a per model basis. A value of -1 means
121 * 'not supported', any other value means the
122 * raw hw_event ID.
123 */
124#ifndef __tilegx__
125/* TILEPro hardware cache event map */
126static const int tile_cache_event_map[PERF_COUNT_HW_CACHE_MAX]
127 [PERF_COUNT_HW_CACHE_OP_MAX]
128 [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
129[C(L1D)] = {
130 [C(OP_READ)] = {
131 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
132 [C(RESULT_MISS)] = 0x21, /* RD_MISS */
133 },
134 [C(OP_WRITE)] = {
135 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
136 [C(RESULT_MISS)] = 0x22, /* WR_MISS */
137 },
138 [C(OP_PREFETCH)] = {
139 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
140 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
141 },
142},
143[C(L1I)] = {
144 [C(OP_READ)] = {
145 [C(RESULT_ACCESS)] = 0x12, /* MP_ICACHE_HIT_ISSUED */
146 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
147 },
148 [C(OP_WRITE)] = {
149 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
150 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
151 },
152 [C(OP_PREFETCH)] = {
153 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
154 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
155 },
156},
157[C(LL)] = {
158 [C(OP_READ)] = {
159 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
160 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
161 },
162 [C(OP_WRITE)] = {
163 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
164 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
165 },
166 [C(OP_PREFETCH)] = {
167 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
168 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
169 },
170},
171[C(DTLB)] = {
172 [C(OP_READ)] = {
173 [C(RESULT_ACCESS)] = 0x1d, /* TLB_CNT */
174 [C(RESULT_MISS)] = 0x20, /* TLB_EXCEPTION */
175 },
176 [C(OP_WRITE)] = {
177 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
178 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
179 },
180 [C(OP_PREFETCH)] = {
181 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
182 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
183 },
184},
185[C(ITLB)] = {
186 [C(OP_READ)] = {
187 [C(RESULT_ACCESS)] = 0x13, /* MP_ITLB_HIT_ISSUED */
188 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
189 },
190 [C(OP_WRITE)] = {
191 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
192 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
193 },
194 [C(OP_PREFETCH)] = {
195 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
196 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
197 },
198},
199[C(BPU)] = {
200 [C(OP_READ)] = {
201 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
202 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
203 },
204 [C(OP_WRITE)] = {
205 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
206 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
207 },
208 [C(OP_PREFETCH)] = {
209 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
210 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
211 },
212},
213};
214#else
215/* TILEGx hardware events map */
216static const int tile_cache_event_map[PERF_COUNT_HW_CACHE_MAX]
217 [PERF_COUNT_HW_CACHE_OP_MAX]
218 [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
219[C(L1D)] = {
220 /*
221 * Like some other architectures (e.g. ARM), the performance
222 * counters don't differentiate between read and write
223 * accesses/misses, so this isn't strictly correct, but it's the
224 * best we can do. Writes and reads get combined.
225 */
226 [C(OP_READ)] = {
227 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
228 [C(RESULT_MISS)] = 0x44, /* RD_MISS */
229 },
230 [C(OP_WRITE)] = {
231 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
232 [C(RESULT_MISS)] = 0x45, /* WR_MISS */
233 },
234 [C(OP_PREFETCH)] = {
235 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
236 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
237 },
238},
239[C(L1I)] = {
240 [C(OP_READ)] = {
241 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
242 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
243 },
244 [C(OP_WRITE)] = {
245 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
246 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
247 },
248 [C(OP_PREFETCH)] = {
249 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
250 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
251 },
252},
253[C(LL)] = {
254 [C(OP_READ)] = {
255 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
256 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
257 },
258 [C(OP_WRITE)] = {
259 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
260 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
261 },
262 [C(OP_PREFETCH)] = {
263 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
264 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
265 },
266},
267[C(DTLB)] = {
268 [C(OP_READ)] = {
269 [C(RESULT_ACCESS)] = 0x40, /* TLB_CNT */
270 [C(RESULT_MISS)] = 0x43, /* TLB_EXCEPTION */
271 },
272 [C(OP_WRITE)] = {
273 [C(RESULT_ACCESS)] = 0x40, /* TLB_CNT */
274 [C(RESULT_MISS)] = 0x43, /* TLB_EXCEPTION */
275 },
276 [C(OP_PREFETCH)] = {
277 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
278 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
279 },
280},
281[C(ITLB)] = {
282 [C(OP_READ)] = {
283 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
284 [C(RESULT_MISS)] = 0xd4, /* ITLB_MISS_INT */
285 },
286 [C(OP_WRITE)] = {
287 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
288 [C(RESULT_MISS)] = 0xd4, /* ITLB_MISS_INT */
289 },
290 [C(OP_PREFETCH)] = {
291 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
292 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
293 },
294},
295[C(BPU)] = {
296 [C(OP_READ)] = {
297 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
298 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
299 },
300 [C(OP_WRITE)] = {
301 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
302 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
303 },
304 [C(OP_PREFETCH)] = {
305 [C(RESULT_ACCESS)] = TILE_OP_UNSUPP,
306 [C(RESULT_MISS)] = TILE_OP_UNSUPP,
307 },
308},
309};
310#endif
311
312static atomic_t tile_active_events;
313static DEFINE_MUTEX(perf_intr_reserve_mutex);
314
315static int tile_map_hw_event(u64 config);
316static int tile_map_cache_event(u64 config);
317
318static int tile_pmu_handle_irq(struct pt_regs *regs, int fault);
319
320/*
321 * To avoid new_raw_count getting larger then pre_raw_count
322 * in tile_perf_event_update(), we limit the value of max_period to 2^31 - 1.
323 */
324static const struct tile_pmu tilepmu = {
325#ifndef __tilegx__
326 .name = "tilepro",
327#else
328 .name = "tilegx",
329#endif
330 .max_events = ARRAY_SIZE(tile_hw_event_map),
331 .map_hw_event = tile_map_hw_event,
332 .hw_events = tile_hw_event_map,
333 .map_cache_event = tile_map_cache_event,
334 .cache_events = &tile_cache_event_map,
335 .cntval_bits = 32,
336 .cntval_mask = (1ULL << 32) - 1,
337 .max_period = (1ULL << 31) - 1,
338 .num_counters = TILE_MAX_COUNTERS,
339 .num_base_counters = TILE_BASE_COUNTERS,
340};
341
342static const struct tile_pmu *tile_pmu __read_mostly;
343
344/*
345 * Check whether perf event is enabled.
346 */
347int tile_perf_enabled(void)
348{
349 return atomic_read(&tile_active_events) != 0;
350}
351
352/*
353 * Read Performance Counters.
354 */
355static inline u64 read_counter(int idx)
356{
357 u64 val = 0;
358
359 /* __insn_mfspr() only takes an immediate argument */
360 switch (idx) {
361 case PERF_COUNT_0_IDX:
362 val = __insn_mfspr(SPR_PERF_COUNT_0);
363 break;
364 case PERF_COUNT_1_IDX:
365 val = __insn_mfspr(SPR_PERF_COUNT_1);
366 break;
367 case AUX_PERF_COUNT_0_IDX:
368 val = __insn_mfspr(SPR_AUX_PERF_COUNT_0);
369 break;
370 case AUX_PERF_COUNT_1_IDX:
371 val = __insn_mfspr(SPR_AUX_PERF_COUNT_1);
372 break;
373 default:
374 WARN_ON_ONCE(idx > AUX_PERF_COUNT_1_IDX ||
375 idx < PERF_COUNT_0_IDX);
376 }
377
378 return val;
379}
380
381/*
382 * Write Performance Counters.
383 */
384static inline void write_counter(int idx, u64 value)
385{
386 /* __insn_mtspr() only takes an immediate argument */
387 switch (idx) {
388 case PERF_COUNT_0_IDX:
389 __insn_mtspr(SPR_PERF_COUNT_0, value);
390 break;
391 case PERF_COUNT_1_IDX:
392 __insn_mtspr(SPR_PERF_COUNT_1, value);
393 break;
394 case AUX_PERF_COUNT_0_IDX:
395 __insn_mtspr(SPR_AUX_PERF_COUNT_0, value);
396 break;
397 case AUX_PERF_COUNT_1_IDX:
398 __insn_mtspr(SPR_AUX_PERF_COUNT_1, value);
399 break;
400 default:
401 WARN_ON_ONCE(idx > AUX_PERF_COUNT_1_IDX ||
402 idx < PERF_COUNT_0_IDX);
403 }
404}
405
406/*
407 * Enable performance event by setting
408 * Performance Counter Control registers.
409 */
410static inline void tile_pmu_enable_event(struct perf_event *event)
411{
412 struct hw_perf_event *hwc = &event->hw;
413 unsigned long cfg, mask;
414 int shift, idx = hwc->idx;
415
416 /*
417 * prevent early activation from tile_pmu_start() in hw_perf_enable
418 */
419
420 if (WARN_ON_ONCE(idx == -1))
421 return;
422
423 if (idx < tile_pmu->num_base_counters)
424 cfg = __insn_mfspr(SPR_PERF_COUNT_CTL);
425 else
426 cfg = __insn_mfspr(SPR_AUX_PERF_COUNT_CTL);
427
428 switch (idx) {
429 case PERF_COUNT_0_IDX:
430 case AUX_PERF_COUNT_0_IDX:
431 mask = TILE_EVENT_MASK;
432 shift = 0;
433 break;
434 case PERF_COUNT_1_IDX:
435 case AUX_PERF_COUNT_1_IDX:
436 mask = TILE_EVENT_MASK << 16;
437 shift = 16;
438 break;
439 default:
440 WARN_ON_ONCE(idx < PERF_COUNT_0_IDX ||
441 idx > AUX_PERF_COUNT_1_IDX);
442 return;
443 }
444
445 /* Clear mask bits to enable the event. */
446 cfg &= ~mask;
447 cfg |= hwc->config << shift;
448
449 if (idx < tile_pmu->num_base_counters)
450 __insn_mtspr(SPR_PERF_COUNT_CTL, cfg);
451 else
452 __insn_mtspr(SPR_AUX_PERF_COUNT_CTL, cfg);
453}
454
455/*
456 * Disable performance event by clearing
457 * Performance Counter Control registers.
458 */
459static inline void tile_pmu_disable_event(struct perf_event *event)
460{
461 struct hw_perf_event *hwc = &event->hw;
462 unsigned long cfg, mask;
463 int idx = hwc->idx;
464
465 if (idx == -1)
466 return;
467
468 if (idx < tile_pmu->num_base_counters)
469 cfg = __insn_mfspr(SPR_PERF_COUNT_CTL);
470 else
471 cfg = __insn_mfspr(SPR_AUX_PERF_COUNT_CTL);
472
473 switch (idx) {
474 case PERF_COUNT_0_IDX:
475 case AUX_PERF_COUNT_0_IDX:
476 mask = TILE_PLM_MASK;
477 break;
478 case PERF_COUNT_1_IDX:
479 case AUX_PERF_COUNT_1_IDX:
480 mask = TILE_PLM_MASK << 16;
481 break;
482 default:
483 WARN_ON_ONCE(idx < PERF_COUNT_0_IDX ||
484 idx > AUX_PERF_COUNT_1_IDX);
485 return;
486 }
487
488 /* Set mask bits to disable the event. */
489 cfg |= mask;
490
491 if (idx < tile_pmu->num_base_counters)
492 __insn_mtspr(SPR_PERF_COUNT_CTL, cfg);
493 else
494 __insn_mtspr(SPR_AUX_PERF_COUNT_CTL, cfg);
495}
496
497/*
498 * Propagate event elapsed time into the generic event.
499 * Can only be executed on the CPU where the event is active.
500 * Returns the delta events processed.
501 */
502static u64 tile_perf_event_update(struct perf_event *event)
503{
504 struct hw_perf_event *hwc = &event->hw;
505 int shift = 64 - tile_pmu->cntval_bits;
506 u64 prev_raw_count, new_raw_count;
507 u64 oldval;
508 int idx = hwc->idx;
509 u64 delta;
510
511 /*
512 * Careful: an NMI might modify the previous event value.
513 *
514 * Our tactic to handle this is to first atomically read and
515 * exchange a new raw count - then add that new-prev delta
516 * count to the generic event atomically:
517 */
518again:
519 prev_raw_count = local64_read(&hwc->prev_count);
520 new_raw_count = read_counter(idx);
521
522 oldval = local64_cmpxchg(&hwc->prev_count, prev_raw_count,
523 new_raw_count);
524 if (oldval != prev_raw_count)
525 goto again;
526
527 /*
528 * Now we have the new raw value and have updated the prev
529 * timestamp already. We can now calculate the elapsed delta
530 * (event-)time and add that to the generic event.
531 *
532 * Careful, not all hw sign-extends above the physical width
533 * of the count.
534 */
535 delta = (new_raw_count << shift) - (prev_raw_count << shift);
536 delta >>= shift;
537
538 local64_add(delta, &event->count);
539 local64_sub(delta, &hwc->period_left);
540
541 return new_raw_count;
542}
543
544/*
545 * Set the next IRQ period, based on the hwc->period_left value.
546 * To be called with the event disabled in hw:
547 */
548static int tile_event_set_period(struct perf_event *event)
549{
550 struct hw_perf_event *hwc = &event->hw;
551 int idx = hwc->idx;
552 s64 left = local64_read(&hwc->period_left);
553 s64 period = hwc->sample_period;
554 int ret = 0;
555
556 /*
557 * If we are way outside a reasonable range then just skip forward:
558 */
559 if (unlikely(left <= -period)) {
560 left = period;
561 local64_set(&hwc->period_left, left);
562 hwc->last_period = period;
563 ret = 1;
564 }
565
566 if (unlikely(left <= 0)) {
567 left += period;
568 local64_set(&hwc->period_left, left);
569 hwc->last_period = period;
570 ret = 1;
571 }
572 if (left > tile_pmu->max_period)
573 left = tile_pmu->max_period;
574
575 /*
576 * The hw event starts counting from this event offset,
577 * mark it to be able to extra future deltas:
578 */
579 local64_set(&hwc->prev_count, (u64)-left);
580
581 write_counter(idx, (u64)(-left) & tile_pmu->cntval_mask);
582
583 perf_event_update_userpage(event);
584
585 return ret;
586}
587
588/*
589 * Stop the event but do not release the PMU counter
590 */
591static void tile_pmu_stop(struct perf_event *event, int flags)
592{
593 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
594 struct hw_perf_event *hwc = &event->hw;
595 int idx = hwc->idx;
596
597 if (__test_and_clear_bit(idx, cpuc->active_mask)) {
598 tile_pmu_disable_event(event);
599 cpuc->events[hwc->idx] = NULL;
600 WARN_ON_ONCE(hwc->state & PERF_HES_STOPPED);
601 hwc->state |= PERF_HES_STOPPED;
602 }
603
604 if ((flags & PERF_EF_UPDATE) && !(hwc->state & PERF_HES_UPTODATE)) {
605 /*
606 * Drain the remaining delta count out of a event
607 * that we are disabling:
608 */
609 tile_perf_event_update(event);
610 hwc->state |= PERF_HES_UPTODATE;
611 }
612}
613
614/*
615 * Start an event (without re-assigning counter)
616 */
617static void tile_pmu_start(struct perf_event *event, int flags)
618{
619 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
620 int idx = event->hw.idx;
621
622 if (WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED)))
623 return;
624
625 if (WARN_ON_ONCE(idx == -1))
626 return;
627
628 if (flags & PERF_EF_RELOAD) {
629 WARN_ON_ONCE(!(event->hw.state & PERF_HES_UPTODATE));
630 tile_event_set_period(event);
631 }
632
633 event->hw.state = 0;
634
635 cpuc->events[idx] = event;
636 __set_bit(idx, cpuc->active_mask);
637
638 unmask_pmc_interrupts();
639
640 tile_pmu_enable_event(event);
641
642 perf_event_update_userpage(event);
643}
644
645/*
646 * Add a single event to the PMU.
647 *
648 * The event is added to the group of enabled events
649 * but only if it can be scehduled with existing events.
650 */
651static int tile_pmu_add(struct perf_event *event, int flags)
652{
653 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
654 struct hw_perf_event *hwc;
655 unsigned long mask;
656 int b, max_cnt;
657
658 hwc = &event->hw;
659
660 /*
661 * We are full.
662 */
663 if (cpuc->n_events == tile_pmu->num_counters)
664 return -ENOSPC;
665
666 cpuc->event_list[cpuc->n_events] = event;
667 cpuc->n_events++;
668
669 hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
670 if (!(flags & PERF_EF_START))
671 hwc->state |= PERF_HES_ARCH;
672
673 /*
674 * Find first empty counter.
675 */
676 max_cnt = tile_pmu->num_counters;
677 mask = ~cpuc->used_mask;
678
679 /* Find next free counter. */
680 b = find_next_bit(&mask, max_cnt, 0);
681
682 /* Should not happen. */
683 if (WARN_ON_ONCE(b == max_cnt))
684 return -ENOSPC;
685
686 /*
687 * Assign counter to event.
688 */
689 event->hw.idx = b;
690 __set_bit(b, &cpuc->used_mask);
691
692 /*
693 * Start if requested.
694 */
695 if (flags & PERF_EF_START)
696 tile_pmu_start(event, PERF_EF_RELOAD);
697
698 return 0;
699}
700
701/*
702 * Delete a single event from the PMU.
703 *
704 * The event is deleted from the group of enabled events.
705 * If it is the last event, disable PMU interrupt.
706 */
707static void tile_pmu_del(struct perf_event *event, int flags)
708{
709 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
710 int i;
711
712 /*
713 * Remove event from list, compact list if necessary.
714 */
715 for (i = 0; i < cpuc->n_events; i++) {
716 if (cpuc->event_list[i] == event) {
717 while (++i < cpuc->n_events)
718 cpuc->event_list[i-1] = cpuc->event_list[i];
719 --cpuc->n_events;
720 cpuc->events[event->hw.idx] = NULL;
721 __clear_bit(event->hw.idx, &cpuc->used_mask);
722 tile_pmu_stop(event, PERF_EF_UPDATE);
723 break;
724 }
725 }
726 /*
727 * If there are no events left, then mask PMU interrupt.
728 */
729 if (cpuc->n_events == 0)
730 mask_pmc_interrupts();
731 perf_event_update_userpage(event);
732}
733
734/*
735 * Propagate event elapsed time into the event.
736 */
737static inline void tile_pmu_read(struct perf_event *event)
738{
739 tile_perf_event_update(event);
740}
741
742/*
743 * Map generic events to Tile PMU.
744 */
745static int tile_map_hw_event(u64 config)
746{
747 if (config >= tile_pmu->max_events)
748 return -EINVAL;
749 return tile_pmu->hw_events[config];
750}
751
752/*
753 * Map generic hardware cache events to Tile PMU.
754 */
755static int tile_map_cache_event(u64 config)
756{
757 unsigned int cache_type, cache_op, cache_result;
758 int code;
759
760 if (!tile_pmu->cache_events)
761 return -ENOENT;
762
763 cache_type = (config >> 0) & 0xff;
764 if (cache_type >= PERF_COUNT_HW_CACHE_MAX)
765 return -EINVAL;
766
767 cache_op = (config >> 8) & 0xff;
768 if (cache_op >= PERF_COUNT_HW_CACHE_OP_MAX)
769 return -EINVAL;
770
771 cache_result = (config >> 16) & 0xff;
772 if (cache_result >= PERF_COUNT_HW_CACHE_RESULT_MAX)
773 return -EINVAL;
774
775 code = (*tile_pmu->cache_events)[cache_type][cache_op][cache_result];
776 if (code == TILE_OP_UNSUPP)
777 return -EINVAL;
778
779 return code;
780}
781
782static void tile_event_destroy(struct perf_event *event)
783{
784 if (atomic_dec_return(&tile_active_events) == 0)
785 release_pmc_hardware();
786}
787
788static int __tile_event_init(struct perf_event *event)
789{
790 struct perf_event_attr *attr = &event->attr;
791 struct hw_perf_event *hwc = &event->hw;
792 int code;
793
794 switch (attr->type) {
795 case PERF_TYPE_HARDWARE:
796 code = tile_pmu->map_hw_event(attr->config);
797 break;
798 case PERF_TYPE_HW_CACHE:
799 code = tile_pmu->map_cache_event(attr->config);
800 break;
801 case PERF_TYPE_RAW:
802 code = attr->config & TILE_EVENT_MASK;
803 break;
804 default:
805 /* Should not happen. */
806 return -EOPNOTSUPP;
807 }
808
809 if (code < 0)
810 return code;
811
812 hwc->config = code;
813 hwc->idx = -1;
814
815 if (attr->exclude_user)
816 hwc->config |= TILE_CTL_EXCL_USER;
817
818 if (attr->exclude_kernel)
819 hwc->config |= TILE_CTL_EXCL_KERNEL;
820
821 if (attr->exclude_hv)
822 hwc->config |= TILE_CTL_EXCL_HV;
823
824 if (!hwc->sample_period) {
825 hwc->sample_period = tile_pmu->max_period;
826 hwc->last_period = hwc->sample_period;
827 local64_set(&hwc->period_left, hwc->sample_period);
828 }
829 event->destroy = tile_event_destroy;
830 return 0;
831}
832
833static int tile_event_init(struct perf_event *event)
834{
835 int err = 0;
836 perf_irq_t old_irq_handler = NULL;
837
838 if (atomic_inc_return(&tile_active_events) == 1)
839 old_irq_handler = reserve_pmc_hardware(tile_pmu_handle_irq);
840
841 if (old_irq_handler) {
842 pr_warn("PMC hardware busy (reserved by oprofile)\n");
843
844 atomic_dec(&tile_active_events);
845 return -EBUSY;
846 }
847
848 switch (event->attr.type) {
849 case PERF_TYPE_RAW:
850 case PERF_TYPE_HARDWARE:
851 case PERF_TYPE_HW_CACHE:
852 break;
853
854 default:
855 return -ENOENT;
856 }
857
858 err = __tile_event_init(event);
859 if (err) {
860 if (event->destroy)
861 event->destroy(event);
862 }
863 return err;
864}
865
866static struct pmu tilera_pmu = {
867 .event_init = tile_event_init,
868 .add = tile_pmu_add,
869 .del = tile_pmu_del,
870
871 .start = tile_pmu_start,
872 .stop = tile_pmu_stop,
873
874 .read = tile_pmu_read,
875};
876
877/*
878 * PMU's IRQ handler, PMU has 2 interrupts, they share the same handler.
879 */
880int tile_pmu_handle_irq(struct pt_regs *regs, int fault)
881{
882 struct perf_sample_data data;
883 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
884 struct perf_event *event;
885 struct hw_perf_event *hwc;
886 u64 val;
887 unsigned long status;
888 int bit;
889
890 __this_cpu_inc(perf_irqs);
891
892 if (!atomic_read(&tile_active_events))
893 return 0;
894
895 status = pmc_get_overflow();
896 pmc_ack_overflow(status);
897
898 for_each_set_bit(bit, &status, tile_pmu->num_counters) {
899
900 event = cpuc->events[bit];
901
902 if (!event)
903 continue;
904
905 if (!test_bit(bit, cpuc->active_mask))
906 continue;
907
908 hwc = &event->hw;
909
910 val = tile_perf_event_update(event);
911 if (val & (1ULL << (tile_pmu->cntval_bits - 1)))
912 continue;
913
914 perf_sample_data_init(&data, 0, event->hw.last_period);
915 if (!tile_event_set_period(event))
916 continue;
917
918 if (perf_event_overflow(event, &data, regs))
919 tile_pmu_stop(event, 0);
920 }
921
922 return 0;
923}
924
925static bool __init supported_pmu(void)
926{
927 tile_pmu = &tilepmu;
928 return true;
929}
930
931int __init init_hw_perf_events(void)
932{
933 supported_pmu();
934 perf_pmu_register(&tilera_pmu, "cpu", PERF_TYPE_RAW);
935 return 0;
936}
937arch_initcall(init_hw_perf_events);
938
939/* Callchain handling code. */
940
941/*
942 * Tile specific backtracing code for perf_events.
943 */
944static inline void perf_callchain(struct perf_callchain_entry_ctx *entry,
945 struct pt_regs *regs)
946{
947 struct KBacktraceIterator kbt;
948 unsigned int i;
949
950 /*
951 * Get the address just after the "jalr" instruction that
952 * jumps to the handler for a syscall. When we find this
953 * address in a backtrace, we silently ignore it, which gives
954 * us a one-step backtrace connection from the sys_xxx()
955 * function in the kernel to the xxx() function in libc.
956 * Otherwise, we lose the ability to properly attribute time
957 * from the libc calls to the kernel implementations, since
958 * oprofile only considers PCs from backtraces a pair at a time.
959 */
960 unsigned long handle_syscall_pc = handle_syscall_link_address();
961
962 KBacktraceIterator_init(&kbt, NULL, regs);
963 kbt.profile = 1;
964
965 /*
966 * The sample for the pc is already recorded. Now we are adding the
967 * address of the callsites on the stack. Our iterator starts
968 * with the frame of the (already sampled) call site. If our
969 * iterator contained a "return address" field, we could have just
970 * used it and wouldn't have needed to skip the first
971 * frame. That's in effect what the arm and x86 versions do.
972 * Instead we peel off the first iteration to get the equivalent
973 * behavior.
974 */
975
976 if (KBacktraceIterator_end(&kbt))
977 return;
978 KBacktraceIterator_next(&kbt);
979
980 /*
981 * Set stack depth to 16 for user and kernel space respectively, that
982 * is, total 32 stack frames.
983 */
984 for (i = 0; i < 16; ++i) {
985 unsigned long pc;
986 if (KBacktraceIterator_end(&kbt))
987 break;
988 pc = kbt.it.pc;
989 if (pc != handle_syscall_pc)
990 perf_callchain_store(entry, pc);
991 KBacktraceIterator_next(&kbt);
992 }
993}
994
995void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
996 struct pt_regs *regs)
997{
998 perf_callchain(entry, regs);
999}
1000
1001void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
1002 struct pt_regs *regs)
1003{
1004 perf_callchain(entry, regs);
1005}
diff --git a/arch/tile/kernel/pmc.c b/arch/tile/kernel/pmc.c
deleted file mode 100644
index 81cf8743a3f3..000000000000
--- a/arch/tile/kernel/pmc.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/*
2 * Copyright 2014 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/errno.h>
16#include <linux/spinlock.h>
17#include <linux/module.h>
18#include <linux/atomic.h>
19
20#include <asm/processor.h>
21#include <asm/pmc.h>
22
23perf_irq_t perf_irq = NULL;
24int handle_perf_interrupt(struct pt_regs *regs, int fault)
25{
26 int retval;
27
28 if (!perf_irq)
29 panic("Unexpected PERF_COUNT interrupt %d\n", fault);
30
31 retval = perf_irq(regs, fault);
32 return retval;
33}
34
35/* Reserve PMC hardware if it is available. */
36perf_irq_t reserve_pmc_hardware(perf_irq_t new_perf_irq)
37{
38 return cmpxchg(&perf_irq, NULL, new_perf_irq);
39}
40EXPORT_SYMBOL(reserve_pmc_hardware);
41
42/* Release PMC hardware. */
43void release_pmc_hardware(void)
44{
45 perf_irq = NULL;
46}
47EXPORT_SYMBOL(release_pmc_hardware);
48
49
50/*
51 * Get current overflow status of each performance counter,
52 * and auxiliary performance counter.
53 */
54unsigned long
55pmc_get_overflow(void)
56{
57 unsigned long status;
58
59 /*
60 * merge base+aux into a single vector
61 */
62 status = __insn_mfspr(SPR_PERF_COUNT_STS);
63 status |= __insn_mfspr(SPR_AUX_PERF_COUNT_STS) << TILE_BASE_COUNTERS;
64 return status;
65}
66
67/*
68 * Clear the status bit for the corresponding counter, if written
69 * with a one.
70 */
71void
72pmc_ack_overflow(unsigned long status)
73{
74 /*
75 * clear overflow status by writing ones
76 */
77 __insn_mtspr(SPR_PERF_COUNT_STS, status);
78 __insn_mtspr(SPR_AUX_PERF_COUNT_STS, status >> TILE_BASE_COUNTERS);
79}
80
81/*
82 * The perf count interrupts are masked and unmasked explicitly,
83 * and only here. The normal irq_enable() does not enable them,
84 * and irq_disable() does not disable them. That lets these
85 * routines drive the perf count interrupts orthogonally.
86 *
87 * We also mask the perf count interrupts on entry to the perf count
88 * interrupt handler in assembly code, and by default unmask them
89 * again (with interrupt critical section protection) just before
90 * returning from the interrupt. If the perf count handler returns
91 * a non-zero error code, then we don't re-enable them before returning.
92 *
93 * For Pro, we rely on both interrupts being in the same word to update
94 * them atomically so we never have one enabled and one disabled.
95 */
96
97#if CHIP_HAS_SPLIT_INTR_MASK()
98# if INT_PERF_COUNT < 32 || INT_AUX_PERF_COUNT < 32
99# error Fix assumptions about which word PERF_COUNT interrupts are in
100# endif
101#endif
102
103static inline unsigned long long pmc_mask(void)
104{
105 unsigned long long mask = 1ULL << INT_PERF_COUNT;
106 mask |= 1ULL << INT_AUX_PERF_COUNT;
107 return mask;
108}
109
110void unmask_pmc_interrupts(void)
111{
112 interrupt_mask_reset_mask(pmc_mask());
113}
114
115void mask_pmc_interrupts(void)
116{
117 interrupt_mask_set_mask(pmc_mask());
118}
diff --git a/arch/tile/kernel/proc.c b/arch/tile/kernel/proc.c
deleted file mode 100644
index 7983e9868df6..000000000000
--- a/arch/tile/kernel/proc.c
+++ /dev/null
@@ -1,160 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/smp.h>
16#include <linux/seq_file.h>
17#include <linux/threads.h>
18#include <linux/cpumask.h>
19#include <linux/timex.h>
20#include <linux/delay.h>
21#include <linux/fs.h>
22#include <linux/proc_fs.h>
23#include <linux/sysctl.h>
24#include <linux/hardirq.h>
25#include <linux/hugetlb.h>
26#include <linux/mman.h>
27#include <asm/unaligned.h>
28#include <asm/pgtable.h>
29#include <asm/processor.h>
30#include <asm/sections.h>
31#include <asm/homecache.h>
32#include <asm/hardwall.h>
33#include <arch/chip.h>
34
35
36/*
37 * Support /proc/cpuinfo
38 */
39
40#define cpu_to_ptr(n) ((void *)((long)(n)+1))
41#define ptr_to_cpu(p) ((long)(p) - 1)
42
43static int show_cpuinfo(struct seq_file *m, void *v)
44{
45 int n = ptr_to_cpu(v);
46
47 if (n == 0) {
48 seq_printf(m, "cpu count\t: %d\n", num_online_cpus());
49 seq_printf(m, "cpu list\t: %*pbl\n",
50 cpumask_pr_args(cpu_online_mask));
51 seq_printf(m, "model name\t: %s\n", chip_model);
52 seq_printf(m, "flags\t\t:\n"); /* nothing for now */
53 seq_printf(m, "cpu MHz\t\t: %llu.%06llu\n",
54 get_clock_rate() / 1000000,
55 (get_clock_rate() % 1000000));
56 seq_printf(m, "bogomips\t: %lu.%02lu\n\n",
57 loops_per_jiffy/(500000/HZ),
58 (loops_per_jiffy/(5000/HZ)) % 100);
59 }
60
61#ifdef CONFIG_SMP
62 if (!cpu_online(n))
63 return 0;
64#endif
65
66 seq_printf(m, "processor\t: %d\n", n);
67
68 /* Print only num_online_cpus() blank lines total. */
69 if (cpumask_next(n, cpu_online_mask) < nr_cpu_ids)
70 seq_printf(m, "\n");
71
72 return 0;
73}
74
75static void *c_start(struct seq_file *m, loff_t *pos)
76{
77 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
78}
79static void *c_next(struct seq_file *m, void *v, loff_t *pos)
80{
81 ++*pos;
82 return c_start(m, pos);
83}
84static void c_stop(struct seq_file *m, void *v)
85{
86}
87const struct seq_operations cpuinfo_op = {
88 .start = c_start,
89 .next = c_next,
90 .stop = c_stop,
91 .show = show_cpuinfo,
92};
93
94/*
95 * Support /proc/tile directory
96 */
97
98static int __init proc_tile_init(void)
99{
100 struct proc_dir_entry *root = proc_mkdir("tile", NULL);
101 if (root == NULL)
102 return 0;
103
104 proc_tile_hardwall_init(root);
105
106 return 0;
107}
108
109arch_initcall(proc_tile_init);
110
111/*
112 * Support /proc/sys/tile directory
113 */
114
115static struct ctl_table unaligned_subtable[] = {
116 {
117 .procname = "enabled",
118 .data = &unaligned_fixup,
119 .maxlen = sizeof(int),
120 .mode = 0644,
121 .proc_handler = &proc_dointvec
122 },
123 {
124 .procname = "printk",
125 .data = &unaligned_printk,
126 .maxlen = sizeof(int),
127 .mode = 0644,
128 .proc_handler = &proc_dointvec
129 },
130 {
131 .procname = "count",
132 .data = &unaligned_fixup_count,
133 .maxlen = sizeof(int),
134 .mode = 0644,
135 .proc_handler = &proc_dointvec
136 },
137 {}
138};
139
140static struct ctl_table unaligned_table[] = {
141 {
142 .procname = "unaligned_fixup",
143 .mode = 0555,
144 .child = unaligned_subtable
145 },
146 {}
147};
148
149static struct ctl_path tile_path[] = {
150 { .procname = "tile" },
151 { }
152};
153
154static int __init proc_sys_tile_init(void)
155{
156 register_sysctl_paths(tile_path, unaligned_table);
157 return 0;
158}
159
160arch_initcall(proc_sys_tile_init);
diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c
deleted file mode 100644
index f0a0e18e4dfb..000000000000
--- a/arch/tile/kernel/process.c
+++ /dev/null
@@ -1,659 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/sched.h>
16#include <linux/sched/debug.h>
17#include <linux/sched/task.h>
18#include <linux/sched/task_stack.h>
19#include <linux/preempt.h>
20#include <linux/module.h>
21#include <linux/fs.h>
22#include <linux/kprobes.h>
23#include <linux/elfcore.h>
24#include <linux/tick.h>
25#include <linux/init.h>
26#include <linux/mm.h>
27#include <linux/compat.h>
28#include <linux/nmi.h>
29#include <linux/syscalls.h>
30#include <linux/kernel.h>
31#include <linux/tracehook.h>
32#include <linux/signal.h>
33#include <linux/delay.h>
34#include <linux/context_tracking.h>
35#include <asm/stack.h>
36#include <asm/switch_to.h>
37#include <asm/homecache.h>
38#include <asm/syscalls.h>
39#include <asm/traps.h>
40#include <asm/setup.h>
41#include <linux/uaccess.h>
42#ifdef CONFIG_HARDWALL
43#include <asm/hardwall.h>
44#endif
45#include <arch/chip.h>
46#include <arch/abi.h>
47#include <arch/sim_def.h>
48
49/*
50 * Use the (x86) "idle=poll" option to prefer low latency when leaving the
51 * idle loop over low power while in the idle loop, e.g. if we have
52 * one thread per core and we want to get threads out of futex waits fast.
53 */
54static int __init idle_setup(char *str)
55{
56 if (!str)
57 return -EINVAL;
58
59 if (!strcmp(str, "poll")) {
60 pr_info("using polling idle threads\n");
61 cpu_idle_poll_ctrl(true);
62 return 0;
63 } else if (!strcmp(str, "halt")) {
64 return 0;
65 }
66 return -1;
67}
68early_param("idle", idle_setup);
69
70void arch_cpu_idle(void)
71{
72 __this_cpu_write(irq_stat.idle_timestamp, jiffies);
73 _cpu_idle();
74}
75
76/*
77 * Release a thread_info structure
78 */
79void arch_release_thread_stack(unsigned long *stack)
80{
81 struct thread_info *info = (void *)stack;
82 struct single_step_state *step_state = info->step_state;
83
84 if (step_state) {
85
86 /*
87 * FIXME: we don't munmap step_state->buffer
88 * because the mm_struct for this process (info->task->mm)
89 * has already been zeroed in exit_mm(). Keeping a
90 * reference to it here seems like a bad move, so this
91 * means we can't munmap() the buffer, and therefore if we
92 * ptrace multiple threads in a process, we will slowly
93 * leak user memory. (Note that as soon as the last
94 * thread in a process dies, we will reclaim all user
95 * memory including single-step buffers in the usual way.)
96 * We should either assign a kernel VA to this buffer
97 * somehow, or we should associate the buffer(s) with the
98 * mm itself so we can clean them up that way.
99 */
100 kfree(step_state);
101 }
102}
103
104static void save_arch_state(struct thread_struct *t);
105
106int copy_thread(unsigned long clone_flags, unsigned long sp,
107 unsigned long arg, struct task_struct *p)
108{
109 struct pt_regs *childregs = task_pt_regs(p);
110 unsigned long ksp;
111 unsigned long *callee_regs;
112
113 /*
114 * Set up the stack and stack pointer appropriately for the
115 * new child to find itself woken up in __switch_to().
116 * The callee-saved registers must be on the stack to be read;
117 * the new task will then jump to assembly support to handle
118 * calling schedule_tail(), etc., and (for userspace tasks)
119 * returning to the context set up in the pt_regs.
120 */
121 ksp = (unsigned long) childregs;
122 ksp -= C_ABI_SAVE_AREA_SIZE; /* interrupt-entry save area */
123 ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
124 ksp -= CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long);
125 callee_regs = (unsigned long *)ksp;
126 ksp -= C_ABI_SAVE_AREA_SIZE; /* __switch_to() save area */
127 ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
128 p->thread.ksp = ksp;
129
130 /* Record the pid of the task that created this one. */
131 p->thread.creator_pid = current->pid;
132
133 if (unlikely(p->flags & PF_KTHREAD)) {
134 /* kernel thread */
135 memset(childregs, 0, sizeof(struct pt_regs));
136 memset(&callee_regs[2], 0,
137 (CALLEE_SAVED_REGS_COUNT - 2) * sizeof(unsigned long));
138 callee_regs[0] = sp; /* r30 = function */
139 callee_regs[1] = arg; /* r31 = arg */
140 p->thread.pc = (unsigned long) ret_from_kernel_thread;
141 return 0;
142 }
143
144 /*
145 * Start new thread in ret_from_fork so it schedules properly
146 * and then return from interrupt like the parent.
147 */
148 p->thread.pc = (unsigned long) ret_from_fork;
149
150 /*
151 * Do not clone step state from the parent; each thread
152 * must make its own lazily.
153 */
154 task_thread_info(p)->step_state = NULL;
155
156#ifdef __tilegx__
157 /*
158 * Do not clone unalign jit fixup from the parent; each thread
159 * must allocate its own on demand.
160 */
161 task_thread_info(p)->unalign_jit_base = NULL;
162#endif
163
164 /*
165 * Copy the registers onto the kernel stack so the
166 * return-from-interrupt code will reload it into registers.
167 */
168 *childregs = *current_pt_regs();
169 childregs->regs[0] = 0; /* return value is zero */
170 if (sp)
171 childregs->sp = sp; /* override with new user stack pointer */
172 memcpy(callee_regs, &childregs->regs[CALLEE_SAVED_FIRST_REG],
173 CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long));
174
175 /* Save user stack top pointer so we can ID the stack vm area later. */
176 p->thread.usp0 = childregs->sp;
177
178 /*
179 * If CLONE_SETTLS is set, set "tp" in the new task to "r4",
180 * which is passed in as arg #5 to sys_clone().
181 */
182 if (clone_flags & CLONE_SETTLS)
183 childregs->tp = childregs->regs[4];
184
185
186#if CHIP_HAS_TILE_DMA()
187 /*
188 * No DMA in the new thread. We model this on the fact that
189 * fork() clears the pending signals, alarms, and aio for the child.
190 */
191 memset(&p->thread.tile_dma_state, 0, sizeof(struct tile_dma_state));
192 memset(&p->thread.dma_async_tlb, 0, sizeof(struct async_tlb));
193#endif
194
195 /* New thread has its miscellaneous processor state bits clear. */
196 p->thread.proc_status = 0;
197
198#ifdef CONFIG_HARDWALL
199 /* New thread does not own any networks. */
200 memset(&p->thread.hardwall[0], 0,
201 sizeof(struct hardwall_task) * HARDWALL_TYPES);
202#endif
203
204
205 /*
206 * Start the new thread with the current architecture state
207 * (user interrupt masks, etc.).
208 */
209 save_arch_state(&p->thread);
210
211 return 0;
212}
213
214int set_unalign_ctl(struct task_struct *tsk, unsigned int val)
215{
216 task_thread_info(tsk)->align_ctl = val;
217 return 0;
218}
219
220int get_unalign_ctl(struct task_struct *tsk, unsigned long adr)
221{
222 return put_user(task_thread_info(tsk)->align_ctl,
223 (unsigned int __user *)adr);
224}
225
226static struct task_struct corrupt_current = { .comm = "<corrupt>" };
227
228/*
229 * Return "current" if it looks plausible, or else a pointer to a dummy.
230 * This can be helpful if we are just trying to emit a clean panic.
231 */
232struct task_struct *validate_current(void)
233{
234 struct task_struct *tsk = current;
235 if (unlikely((unsigned long)tsk < PAGE_OFFSET ||
236 (high_memory && (void *)tsk > high_memory) ||
237 ((unsigned long)tsk & (__alignof__(*tsk) - 1)) != 0)) {
238 pr_err("Corrupt 'current' %p (sp %#lx)\n", tsk, stack_pointer);
239 tsk = &corrupt_current;
240 }
241 return tsk;
242}
243
244/* Take and return the pointer to the previous task, for schedule_tail(). */
245struct task_struct *sim_notify_fork(struct task_struct *prev)
246{
247 struct task_struct *tsk = current;
248 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_FORK_PARENT |
249 (tsk->thread.creator_pid << _SIM_CONTROL_OPERATOR_BITS));
250 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_FORK |
251 (tsk->pid << _SIM_CONTROL_OPERATOR_BITS));
252 return prev;
253}
254
255int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
256{
257 struct pt_regs *ptregs = task_pt_regs(tsk);
258 elf_core_copy_regs(regs, ptregs);
259 return 1;
260}
261
262#if CHIP_HAS_TILE_DMA()
263
264/* Allow user processes to access the DMA SPRs */
265void grant_dma_mpls(void)
266{
267#if CONFIG_KERNEL_PL == 2
268 __insn_mtspr(SPR_MPL_DMA_CPL_SET_1, 1);
269 __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_1, 1);
270#else
271 __insn_mtspr(SPR_MPL_DMA_CPL_SET_0, 1);
272 __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_0, 1);
273#endif
274}
275
276/* Forbid user processes from accessing the DMA SPRs */
277void restrict_dma_mpls(void)
278{
279#if CONFIG_KERNEL_PL == 2
280 __insn_mtspr(SPR_MPL_DMA_CPL_SET_2, 1);
281 __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_2, 1);
282#else
283 __insn_mtspr(SPR_MPL_DMA_CPL_SET_1, 1);
284 __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_1, 1);
285#endif
286}
287
288/* Pause the DMA engine, then save off its state registers. */
289static void save_tile_dma_state(struct tile_dma_state *dma)
290{
291 unsigned long state = __insn_mfspr(SPR_DMA_USER_STATUS);
292 unsigned long post_suspend_state;
293
294 /* If we're running, suspend the engine. */
295 if ((state & DMA_STATUS_MASK) == SPR_DMA_STATUS__RUNNING_MASK)
296 __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__SUSPEND_MASK);
297
298 /*
299 * Wait for the engine to idle, then save regs. Note that we
300 * want to record the "running" bit from before suspension,
301 * and the "done" bit from after, so that we can properly
302 * distinguish a case where the user suspended the engine from
303 * the case where the kernel suspended as part of the context
304 * swap.
305 */
306 do {
307 post_suspend_state = __insn_mfspr(SPR_DMA_USER_STATUS);
308 } while (post_suspend_state & SPR_DMA_STATUS__BUSY_MASK);
309
310 dma->src = __insn_mfspr(SPR_DMA_SRC_ADDR);
311 dma->src_chunk = __insn_mfspr(SPR_DMA_SRC_CHUNK_ADDR);
312 dma->dest = __insn_mfspr(SPR_DMA_DST_ADDR);
313 dma->dest_chunk = __insn_mfspr(SPR_DMA_DST_CHUNK_ADDR);
314 dma->strides = __insn_mfspr(SPR_DMA_STRIDE);
315 dma->chunk_size = __insn_mfspr(SPR_DMA_CHUNK_SIZE);
316 dma->byte = __insn_mfspr(SPR_DMA_BYTE);
317 dma->status = (state & SPR_DMA_STATUS__RUNNING_MASK) |
318 (post_suspend_state & SPR_DMA_STATUS__DONE_MASK);
319}
320
321/* Restart a DMA that was running before we were context-switched out. */
322static void restore_tile_dma_state(struct thread_struct *t)
323{
324 const struct tile_dma_state *dma = &t->tile_dma_state;
325
326 /*
327 * The only way to restore the done bit is to run a zero
328 * length transaction.
329 */
330 if ((dma->status & SPR_DMA_STATUS__DONE_MASK) &&
331 !(__insn_mfspr(SPR_DMA_USER_STATUS) & SPR_DMA_STATUS__DONE_MASK)) {
332 __insn_mtspr(SPR_DMA_BYTE, 0);
333 __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);
334 while (__insn_mfspr(SPR_DMA_USER_STATUS) &
335 SPR_DMA_STATUS__BUSY_MASK)
336 ;
337 }
338
339 __insn_mtspr(SPR_DMA_SRC_ADDR, dma->src);
340 __insn_mtspr(SPR_DMA_SRC_CHUNK_ADDR, dma->src_chunk);
341 __insn_mtspr(SPR_DMA_DST_ADDR, dma->dest);
342 __insn_mtspr(SPR_DMA_DST_CHUNK_ADDR, dma->dest_chunk);
343 __insn_mtspr(SPR_DMA_STRIDE, dma->strides);
344 __insn_mtspr(SPR_DMA_CHUNK_SIZE, dma->chunk_size);
345 __insn_mtspr(SPR_DMA_BYTE, dma->byte);
346
347 /*
348 * Restart the engine if we were running and not done.
349 * Clear a pending async DMA fault that we were waiting on return
350 * to user space to execute, since we expect the DMA engine
351 * to regenerate those faults for us now. Note that we don't
352 * try to clear the TIF_ASYNC_TLB flag, since it's relatively
353 * harmless if set, and it covers both DMA and the SN processor.
354 */
355 if ((dma->status & DMA_STATUS_MASK) == SPR_DMA_STATUS__RUNNING_MASK) {
356 t->dma_async_tlb.fault_num = 0;
357 __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);
358 }
359}
360
361#endif
362
363static void save_arch_state(struct thread_struct *t)
364{
365#if CHIP_HAS_SPLIT_INTR_MASK()
366 t->interrupt_mask = __insn_mfspr(SPR_INTERRUPT_MASK_0_0) |
367 ((u64)__insn_mfspr(SPR_INTERRUPT_MASK_0_1) << 32);
368#else
369 t->interrupt_mask = __insn_mfspr(SPR_INTERRUPT_MASK_0);
370#endif
371 t->ex_context[0] = __insn_mfspr(SPR_EX_CONTEXT_0_0);
372 t->ex_context[1] = __insn_mfspr(SPR_EX_CONTEXT_0_1);
373 t->system_save[0] = __insn_mfspr(SPR_SYSTEM_SAVE_0_0);
374 t->system_save[1] = __insn_mfspr(SPR_SYSTEM_SAVE_0_1);
375 t->system_save[2] = __insn_mfspr(SPR_SYSTEM_SAVE_0_2);
376 t->system_save[3] = __insn_mfspr(SPR_SYSTEM_SAVE_0_3);
377 t->intctrl_0 = __insn_mfspr(SPR_INTCTRL_0_STATUS);
378 t->proc_status = __insn_mfspr(SPR_PROC_STATUS);
379#if !CHIP_HAS_FIXED_INTVEC_BASE()
380 t->interrupt_vector_base = __insn_mfspr(SPR_INTERRUPT_VECTOR_BASE_0);
381#endif
382 t->tile_rtf_hwm = __insn_mfspr(SPR_TILE_RTF_HWM);
383#if CHIP_HAS_DSTREAM_PF()
384 t->dstream_pf = __insn_mfspr(SPR_DSTREAM_PF);
385#endif
386}
387
388static void restore_arch_state(const struct thread_struct *t)
389{
390#if CHIP_HAS_SPLIT_INTR_MASK()
391 __insn_mtspr(SPR_INTERRUPT_MASK_0_0, (u32) t->interrupt_mask);
392 __insn_mtspr(SPR_INTERRUPT_MASK_0_1, t->interrupt_mask >> 32);
393#else
394 __insn_mtspr(SPR_INTERRUPT_MASK_0, t->interrupt_mask);
395#endif
396 __insn_mtspr(SPR_EX_CONTEXT_0_0, t->ex_context[0]);
397 __insn_mtspr(SPR_EX_CONTEXT_0_1, t->ex_context[1]);
398 __insn_mtspr(SPR_SYSTEM_SAVE_0_0, t->system_save[0]);
399 __insn_mtspr(SPR_SYSTEM_SAVE_0_1, t->system_save[1]);
400 __insn_mtspr(SPR_SYSTEM_SAVE_0_2, t->system_save[2]);
401 __insn_mtspr(SPR_SYSTEM_SAVE_0_3, t->system_save[3]);
402 __insn_mtspr(SPR_INTCTRL_0_STATUS, t->intctrl_0);
403 __insn_mtspr(SPR_PROC_STATUS, t->proc_status);
404#if !CHIP_HAS_FIXED_INTVEC_BASE()
405 __insn_mtspr(SPR_INTERRUPT_VECTOR_BASE_0, t->interrupt_vector_base);
406#endif
407 __insn_mtspr(SPR_TILE_RTF_HWM, t->tile_rtf_hwm);
408#if CHIP_HAS_DSTREAM_PF()
409 __insn_mtspr(SPR_DSTREAM_PF, t->dstream_pf);
410#endif
411}
412
413
414void _prepare_arch_switch(struct task_struct *next)
415{
416#if CHIP_HAS_TILE_DMA()
417 struct tile_dma_state *dma = &current->thread.tile_dma_state;
418 if (dma->enabled)
419 save_tile_dma_state(dma);
420#endif
421}
422
423
424struct task_struct *__sched _switch_to(struct task_struct *prev,
425 struct task_struct *next)
426{
427 /* DMA state is already saved; save off other arch state. */
428 save_arch_state(&prev->thread);
429
430#if CHIP_HAS_TILE_DMA()
431 /*
432 * Restore DMA in new task if desired.
433 * Note that it is only safe to restart here since interrupts
434 * are disabled, so we can't take any DMATLB miss or access
435 * interrupts before we have finished switching stacks.
436 */
437 if (next->thread.tile_dma_state.enabled) {
438 restore_tile_dma_state(&next->thread);
439 grant_dma_mpls();
440 } else {
441 restrict_dma_mpls();
442 }
443#endif
444
445 /* Restore other arch state. */
446 restore_arch_state(&next->thread);
447
448#ifdef CONFIG_HARDWALL
449 /* Enable or disable access to the network registers appropriately. */
450 hardwall_switch_tasks(prev, next);
451#endif
452
453 /* Notify the simulator of task exit. */
454 if (unlikely(prev->state == TASK_DEAD))
455 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_EXIT |
456 (prev->pid << _SIM_CONTROL_OPERATOR_BITS));
457
458 /*
459 * Switch kernel SP, PC, and callee-saved registers.
460 * In the context of the new task, return the old task pointer
461 * (i.e. the task that actually called __switch_to).
462 * Pass the value to use for SYSTEM_SAVE_K_0 when we reset our sp.
463 */
464 return __switch_to(prev, next, next_current_ksp0(next));
465}
466
467/*
468 * This routine is called on return from interrupt if any of the
469 * TIF_ALLWORK_MASK flags are set in thread_info->flags. It is
470 * entered with interrupts disabled so we don't miss an event that
471 * modified the thread_info flags. We loop until all the tested flags
472 * are clear. Note that the function is called on certain conditions
473 * that are not listed in the loop condition here (e.g. SINGLESTEP)
474 * which guarantees we will do those things once, and redo them if any
475 * of the other work items is re-done, but won't continue looping if
476 * all the other work is done.
477 */
478void prepare_exit_to_usermode(struct pt_regs *regs, u32 thread_info_flags)
479{
480 if (WARN_ON(!user_mode(regs)))
481 return;
482
483 do {
484 local_irq_enable();
485
486 if (thread_info_flags & _TIF_NEED_RESCHED)
487 schedule();
488
489#if CHIP_HAS_TILE_DMA()
490 if (thread_info_flags & _TIF_ASYNC_TLB)
491 do_async_page_fault(regs);
492#endif
493
494 if (thread_info_flags & _TIF_SIGPENDING)
495 do_signal(regs);
496
497 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
498 clear_thread_flag(TIF_NOTIFY_RESUME);
499 tracehook_notify_resume(regs);
500 }
501
502 local_irq_disable();
503 thread_info_flags = READ_ONCE(current_thread_info()->flags);
504
505 } while (thread_info_flags & _TIF_WORK_MASK);
506
507 if (thread_info_flags & _TIF_SINGLESTEP) {
508 single_step_once(regs);
509#ifndef __tilegx__
510 /*
511 * FIXME: on tilepro, since we enable interrupts in
512 * this routine, it's possible that we miss a signal
513 * or other asynchronous event.
514 */
515 local_irq_disable();
516#endif
517 }
518
519 user_enter();
520}
521
522unsigned long get_wchan(struct task_struct *p)
523{
524 struct KBacktraceIterator kbt;
525
526 if (!p || p == current || p->state == TASK_RUNNING)
527 return 0;
528
529 for (KBacktraceIterator_init(&kbt, p, NULL);
530 !KBacktraceIterator_end(&kbt);
531 KBacktraceIterator_next(&kbt)) {
532 if (!in_sched_functions(kbt.it.pc))
533 return kbt.it.pc;
534 }
535
536 return 0;
537}
538
539/* Flush thread state. */
540void flush_thread(void)
541{
542 /* Nothing */
543}
544
545/*
546 * Free current thread data structures etc..
547 */
548void exit_thread(struct task_struct *tsk)
549{
550#ifdef CONFIG_HARDWALL
551 /*
552 * Remove the task from the list of tasks that are associated
553 * with any live hardwalls. (If the task that is exiting held
554 * the last reference to a hardwall fd, it would already have
555 * been released and deactivated at this point.)
556 */
557 hardwall_deactivate_all(tsk);
558#endif
559}
560
561void tile_show_regs(struct pt_regs *regs)
562{
563 int i;
564#ifdef __tilegx__
565 for (i = 0; i < 17; i++)
566 pr_err(" r%-2d: "REGFMT" r%-2d: "REGFMT" r%-2d: "REGFMT"\n",
567 i, regs->regs[i], i+18, regs->regs[i+18],
568 i+36, regs->regs[i+36]);
569 pr_err(" r17: "REGFMT" r35: "REGFMT" tp : "REGFMT"\n",
570 regs->regs[17], regs->regs[35], regs->tp);
571 pr_err(" sp : "REGFMT" lr : "REGFMT"\n", regs->sp, regs->lr);
572#else
573 for (i = 0; i < 13; i++)
574 pr_err(" r%-2d: "REGFMT" r%-2d: "REGFMT
575 " r%-2d: "REGFMT" r%-2d: "REGFMT"\n",
576 i, regs->regs[i], i+14, regs->regs[i+14],
577 i+27, regs->regs[i+27], i+40, regs->regs[i+40]);
578 pr_err(" r13: "REGFMT" tp : "REGFMT" sp : "REGFMT" lr : "REGFMT"\n",
579 regs->regs[13], regs->tp, regs->sp, regs->lr);
580#endif
581 pr_err(" pc : "REGFMT" ex1: %ld faultnum: %ld flags:%s%s%s%s\n",
582 regs->pc, regs->ex1, regs->faultnum,
583 is_compat_task() ? " compat" : "",
584 (regs->flags & PT_FLAGS_DISABLE_IRQ) ? " noirq" : "",
585 !(regs->flags & PT_FLAGS_CALLER_SAVES) ? " nocallersave" : "",
586 (regs->flags & PT_FLAGS_RESTORE_REGS) ? " restoreregs" : "");
587}
588
589void show_regs(struct pt_regs *regs)
590{
591 struct KBacktraceIterator kbt;
592
593 show_regs_print_info(KERN_DEFAULT);
594 tile_show_regs(regs);
595
596 KBacktraceIterator_init(&kbt, NULL, regs);
597 tile_show_stack(&kbt);
598}
599
600#ifdef __tilegx__
601void nmi_raise_cpu_backtrace(struct cpumask *in_mask)
602{
603 struct cpumask mask;
604 HV_Coord tile;
605 unsigned int timeout;
606 int cpu;
607 HV_NMI_Info info[NR_CPUS];
608
609 /* Tentatively dump stack on remote tiles via NMI. */
610 timeout = 100;
611 cpumask_copy(&mask, in_mask);
612 while (!cpumask_empty(&mask) && timeout) {
613 for_each_cpu(cpu, &mask) {
614 tile.x = cpu_x(cpu);
615 tile.y = cpu_y(cpu);
616 info[cpu] = hv_send_nmi(tile, TILE_NMI_DUMP_STACK, 0);
617 if (info[cpu].result == HV_NMI_RESULT_OK)
618 cpumask_clear_cpu(cpu, &mask);
619 }
620
621 mdelay(10);
622 touch_softlockup_watchdog();
623 timeout--;
624 }
625
626 /* Warn about cpus stuck in ICS. */
627 if (!cpumask_empty(&mask)) {
628 for_each_cpu(cpu, &mask) {
629
630 /* Clear the bit as if nmi_cpu_backtrace() ran. */
631 cpumask_clear_cpu(cpu, in_mask);
632
633 switch (info[cpu].result) {
634 case HV_NMI_RESULT_FAIL_ICS:
635 pr_warn("Skipping stack dump of cpu %d in ICS at pc %#llx\n",
636 cpu, info[cpu].pc);
637 break;
638 case HV_NMI_RESULT_FAIL_HV:
639 pr_warn("Skipping stack dump of cpu %d in hypervisor\n",
640 cpu);
641 break;
642 case HV_ENOSYS:
643 WARN_ONCE(1, "Hypervisor too old to allow remote stack dumps.\n");
644 break;
645 default: /* should not happen */
646 pr_warn("Skipping stack dump of cpu %d [%d,%#llx]\n",
647 cpu, info[cpu].result, info[cpu].pc);
648 break;
649 }
650 }
651 }
652}
653
654void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)
655{
656 nmi_trigger_cpumask_backtrace(mask, exclude_self,
657 nmi_raise_cpu_backtrace);
658}
659#endif /* __tilegx_ */
diff --git a/arch/tile/kernel/ptrace.c b/arch/tile/kernel/ptrace.c
deleted file mode 100644
index d516d61751c2..000000000000
--- a/arch/tile/kernel/ptrace.c
+++ /dev/null
@@ -1,316 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Copied from i386: Ross Biro 1/23/92
15 */
16
17#include <linux/kernel.h>
18#include <linux/ptrace.h>
19#include <linux/kprobes.h>
20#include <linux/compat.h>
21#include <linux/uaccess.h>
22#include <linux/regset.h>
23#include <linux/elf.h>
24#include <linux/tracehook.h>
25#include <linux/context_tracking.h>
26#include <linux/sched/task_stack.h>
27
28#include <asm/traps.h>
29#include <arch/chip.h>
30
31#define CREATE_TRACE_POINTS
32#include <trace/events/syscalls.h>
33
34void user_enable_single_step(struct task_struct *child)
35{
36 set_tsk_thread_flag(child, TIF_SINGLESTEP);
37}
38
39void user_disable_single_step(struct task_struct *child)
40{
41 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
42}
43
44/*
45 * Called by kernel/ptrace.c when detaching..
46 */
47void ptrace_disable(struct task_struct *child)
48{
49 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
50
51 /*
52 * These two are currently unused, but will be set by arch_ptrace()
53 * and used in the syscall assembly when we do support them.
54 */
55 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
56}
57
58/*
59 * Get registers from task and ready the result for userspace.
60 * Note that we localize the API issues to getregs() and putregs() at
61 * some cost in performance, e.g. we need a full pt_regs copy for
62 * PEEKUSR, and two copies for POKEUSR. But in general we expect
63 * GETREGS/PUTREGS to be the API of choice anyway.
64 */
65static char *getregs(struct task_struct *child, struct pt_regs *uregs)
66{
67 *uregs = *task_pt_regs(child);
68
69 /* Set up flags ABI bits. */
70 uregs->flags = 0;
71#ifdef CONFIG_COMPAT
72 if (task_thread_info(child)->status & TS_COMPAT)
73 uregs->flags |= PT_FLAGS_COMPAT;
74#endif
75
76 return (char *)uregs;
77}
78
79/* Put registers back to task. */
80static void putregs(struct task_struct *child, struct pt_regs *uregs)
81{
82 struct pt_regs *regs = task_pt_regs(child);
83
84 /* Don't allow overwriting the kernel-internal flags word. */
85 uregs->flags = regs->flags;
86
87 /* Only allow setting the ICS bit in the ex1 word. */
88 uregs->ex1 = PL_ICS_EX1(USER_PL, EX1_ICS(uregs->ex1));
89
90 *regs = *uregs;
91}
92
93enum tile_regset {
94 REGSET_GPR,
95};
96
97static int tile_gpr_get(struct task_struct *target,
98 const struct user_regset *regset,
99 unsigned int pos, unsigned int count,
100 void *kbuf, void __user *ubuf)
101{
102 struct pt_regs regs;
103
104 getregs(target, &regs);
105
106 return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &regs, 0,
107 sizeof(regs));
108}
109
110static int tile_gpr_set(struct task_struct *target,
111 const struct user_regset *regset,
112 unsigned int pos, unsigned int count,
113 const void *kbuf, const void __user *ubuf)
114{
115 int ret;
116 struct pt_regs regs = *task_pt_regs(target);
117
118 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &regs, 0,
119 sizeof(regs));
120 if (ret)
121 return ret;
122
123 putregs(target, &regs);
124
125 return 0;
126}
127
128static const struct user_regset tile_user_regset[] = {
129 [REGSET_GPR] = {
130 .core_note_type = NT_PRSTATUS,
131 .n = ELF_NGREG,
132 .size = sizeof(elf_greg_t),
133 .align = sizeof(elf_greg_t),
134 .get = tile_gpr_get,
135 .set = tile_gpr_set,
136 },
137};
138
139static const struct user_regset_view tile_user_regset_view = {
140 .name = CHIP_ARCH_NAME,
141 .e_machine = ELF_ARCH,
142 .ei_osabi = ELF_OSABI,
143 .regsets = tile_user_regset,
144 .n = ARRAY_SIZE(tile_user_regset),
145};
146
147const struct user_regset_view *task_user_regset_view(struct task_struct *task)
148{
149 return &tile_user_regset_view;
150}
151
152long arch_ptrace(struct task_struct *child, long request,
153 unsigned long addr, unsigned long data)
154{
155 unsigned long __user *datap = (long __user __force *)data;
156 unsigned long tmp;
157 long ret = -EIO;
158 char *childreg;
159 struct pt_regs copyregs;
160
161 switch (request) {
162
163 case PTRACE_PEEKUSR: /* Read register from pt_regs. */
164 if (addr >= PTREGS_SIZE)
165 break;
166 childreg = getregs(child, &copyregs) + addr;
167#ifdef CONFIG_COMPAT
168 if (is_compat_task()) {
169 if (addr & (sizeof(compat_long_t)-1))
170 break;
171 ret = put_user(*(compat_long_t *)childreg,
172 (compat_long_t __user *)datap);
173 } else
174#endif
175 {
176 if (addr & (sizeof(long)-1))
177 break;
178 ret = put_user(*(long *)childreg, datap);
179 }
180 break;
181
182 case PTRACE_POKEUSR: /* Write register in pt_regs. */
183 if (addr >= PTREGS_SIZE)
184 break;
185 childreg = getregs(child, &copyregs) + addr;
186#ifdef CONFIG_COMPAT
187 if (is_compat_task()) {
188 if (addr & (sizeof(compat_long_t)-1))
189 break;
190 *(compat_long_t *)childreg = data;
191 } else
192#endif
193 {
194 if (addr & (sizeof(long)-1))
195 break;
196 *(long *)childreg = data;
197 }
198 putregs(child, &copyregs);
199 ret = 0;
200 break;
201
202 case PTRACE_GETREGS: /* Get all registers from the child. */
203 ret = copy_regset_to_user(child, &tile_user_regset_view,
204 REGSET_GPR, 0,
205 sizeof(struct pt_regs), datap);
206 break;
207
208 case PTRACE_SETREGS: /* Set all registers in the child. */
209 ret = copy_regset_from_user(child, &tile_user_regset_view,
210 REGSET_GPR, 0,
211 sizeof(struct pt_regs), datap);
212 break;
213
214 case PTRACE_GETFPREGS: /* Get the child FPU state. */
215 case PTRACE_SETFPREGS: /* Set the child FPU state. */
216 break;
217
218 case PTRACE_SETOPTIONS:
219 /* Support TILE-specific ptrace options. */
220 BUILD_BUG_ON(PTRACE_O_MASK_TILE & PTRACE_O_MASK);
221 tmp = data & PTRACE_O_MASK_TILE;
222 data &= ~PTRACE_O_MASK_TILE;
223 ret = ptrace_request(child, request, addr, data);
224 if (ret == 0) {
225 unsigned int flags = child->ptrace;
226 flags &= ~(PTRACE_O_MASK_TILE << PT_OPT_FLAG_SHIFT);
227 flags |= (tmp << PT_OPT_FLAG_SHIFT);
228 child->ptrace = flags;
229 }
230 break;
231
232 default:
233#ifdef CONFIG_COMPAT
234 if (task_thread_info(current)->status & TS_COMPAT) {
235 ret = compat_ptrace_request(child, request,
236 addr, data);
237 break;
238 }
239#endif
240 ret = ptrace_request(child, request, addr, data);
241 break;
242 }
243
244 return ret;
245}
246
247#ifdef CONFIG_COMPAT
248/* Not used; we handle compat issues in arch_ptrace() directly. */
249long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
250 compat_ulong_t addr, compat_ulong_t data)
251{
252 BUG();
253}
254#endif
255
256int do_syscall_trace_enter(struct pt_regs *regs)
257{
258 u32 work = READ_ONCE(current_thread_info()->flags);
259
260 if ((work & _TIF_SYSCALL_TRACE) &&
261 tracehook_report_syscall_entry(regs)) {
262 regs->regs[TREG_SYSCALL_NR] = -1;
263 return -1;
264 }
265
266 if (secure_computing(NULL) == -1)
267 return -1;
268
269 if (work & _TIF_SYSCALL_TRACEPOINT)
270 trace_sys_enter(regs, regs->regs[TREG_SYSCALL_NR]);
271
272 return regs->regs[TREG_SYSCALL_NR];
273}
274
275void do_syscall_trace_exit(struct pt_regs *regs)
276{
277 long errno;
278
279 /*
280 * The standard tile calling convention returns the value (or negative
281 * errno) in r0, and zero (or positive errno) in r1.
282 * It saves a couple of cycles on the hot path to do this work in
283 * registers only as we return, rather than updating the in-memory
284 * struct ptregs.
285 */
286 errno = (long) regs->regs[0];
287 if (errno < 0 && errno > -4096)
288 regs->regs[1] = -errno;
289 else
290 regs->regs[1] = 0;
291
292 if (test_thread_flag(TIF_SYSCALL_TRACE))
293 tracehook_report_syscall_exit(regs, 0);
294
295 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
296 trace_sys_exit(regs, regs->regs[0]);
297}
298
299void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs)
300{
301 struct siginfo info;
302
303 memset(&info, 0, sizeof(info));
304 info.si_signo = SIGTRAP;
305 info.si_code = TRAP_BRKPT;
306 info.si_addr = (void __user *) regs->pc;
307
308 /* Send us the fakey SIGTRAP */
309 force_sig_info(SIGTRAP, &info, tsk);
310}
311
312/* Handle synthetic interrupt delivered only by the simulator. */
313void __kprobes do_breakpoint(struct pt_regs* regs, int fault_num)
314{
315 send_sigtrap(current, regs);
316}
diff --git a/arch/tile/kernel/reboot.c b/arch/tile/kernel/reboot.c
deleted file mode 100644
index 6c5d2c070a12..000000000000
--- a/arch/tile/kernel/reboot.c
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/stddef.h>
16#include <linux/reboot.h>
17#include <linux/smp.h>
18#include <linux/pm.h>
19#include <linux/export.h>
20#include <asm/page.h>
21#include <asm/setup.h>
22#include <hv/hypervisor.h>
23
24#ifndef CONFIG_SMP
25#define smp_send_stop()
26#endif
27
28void machine_halt(void)
29{
30 arch_local_irq_disable_all();
31 smp_send_stop();
32 hv_halt();
33}
34
35void machine_power_off(void)
36{
37 arch_local_irq_disable_all();
38 smp_send_stop();
39 hv_power_off();
40}
41
42void machine_restart(char *cmd)
43{
44 arch_local_irq_disable_all();
45 smp_send_stop();
46 hv_restart((HV_VirtAddr) "vmlinux", (HV_VirtAddr) cmd);
47}
48
49/* No interesting distinction to be made here. */
50void (*pm_power_off)(void) = NULL;
51EXPORT_SYMBOL(pm_power_off);
diff --git a/arch/tile/kernel/regs_32.S b/arch/tile/kernel/regs_32.S
deleted file mode 100644
index 542cae17a93a..000000000000
--- a/arch/tile/kernel/regs_32.S
+++ /dev/null
@@ -1,145 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/linkage.h>
16#include <asm/ptrace.h>
17#include <asm/asm-offsets.h>
18#include <arch/spr_def.h>
19#include <asm/processor.h>
20#include <asm/switch_to.h>
21
22/*
23 * See <asm/switch_to.h>; called with prev and next task_struct pointers.
24 * "prev" is returned in r0 for _switch_to and also for ret_from_fork.
25 *
26 * We want to save pc/sp in "prev", and get the new pc/sp from "next".
27 * We also need to save all the callee-saved registers on the stack.
28 *
29 * Intel enables/disables access to the hardware cycle counter in
30 * seccomp (secure computing) environments if necessary, based on
31 * has_secure_computing(). We might want to do this at some point,
32 * though it would require virtualizing the other SPRs under WORLD_ACCESS.
33 *
34 * Since we're saving to the stack, we omit sp from this list.
35 * And for parallels with other architectures, we save lr separately,
36 * in the thread_struct itself (as the "pc" field).
37 *
38 * This code also needs to be aligned with process.c copy_thread()
39 */
40
41#if CALLEE_SAVED_REGS_COUNT != 24
42# error Mismatch between <asm/switch_to.h> and kernel/entry.S
43#endif
44#define FRAME_SIZE ((2 + CALLEE_SAVED_REGS_COUNT) * 4)
45
46#define SAVE_REG(r) { sw r12, r; addi r12, r12, 4 }
47#define LOAD_REG(r) { lw r, r12; addi r12, r12, 4 }
48#define FOR_EACH_CALLEE_SAVED_REG(f) \
49 f(r30); f(r31); \
50 f(r32); f(r33); f(r34); f(r35); f(r36); f(r37); f(r38); f(r39); \
51 f(r40); f(r41); f(r42); f(r43); f(r44); f(r45); f(r46); f(r47); \
52 f(r48); f(r49); f(r50); f(r51); f(r52);
53
54STD_ENTRY_SECTION(__switch_to, .sched.text)
55 {
56 move r10, sp
57 sw sp, lr
58 addi sp, sp, -FRAME_SIZE
59 }
60 {
61 addi r11, sp, 4
62 addi r12, sp, 8
63 }
64 {
65 sw r11, r10
66 addli r4, r1, TASK_STRUCT_THREAD_KSP_OFFSET
67 }
68 {
69 lw r13, r4 /* Load new sp to a temp register early. */
70 addli r3, r0, TASK_STRUCT_THREAD_KSP_OFFSET
71 }
72 FOR_EACH_CALLEE_SAVED_REG(SAVE_REG)
73 {
74 sw r3, sp
75 addli r3, r0, TASK_STRUCT_THREAD_PC_OFFSET
76 }
77 {
78 sw r3, lr
79 addli r4, r1, TASK_STRUCT_THREAD_PC_OFFSET
80 }
81 {
82 lw lr, r4
83 addi r12, r13, 8
84 }
85 {
86 /* Update sp and ksp0 simultaneously to avoid backtracer warnings. */
87 move sp, r13
88 mtspr SPR_SYSTEM_SAVE_K_0, r2
89 }
90 FOR_EACH_CALLEE_SAVED_REG(LOAD_REG)
91.L__switch_to_pc:
92 {
93 addi sp, sp, FRAME_SIZE
94 jrp lr /* r0 is still valid here, so return it */
95 }
96 STD_ENDPROC(__switch_to)
97
98/* Return a suitable address for the backtracer for suspended threads */
99STD_ENTRY_SECTION(get_switch_to_pc, .sched.text)
100 lnk r0
101 {
102 addli r0, r0, .L__switch_to_pc - .
103 jrp lr
104 }
105 STD_ENDPROC(get_switch_to_pc)
106
107STD_ENTRY(get_pt_regs)
108 .irp reg, r0, r1, r2, r3, r4, r5, r6, r7, \
109 r8, r9, r10, r11, r12, r13, r14, r15, \
110 r16, r17, r18, r19, r20, r21, r22, r23, \
111 r24, r25, r26, r27, r28, r29, r30, r31, \
112 r32, r33, r34, r35, r36, r37, r38, r39, \
113 r40, r41, r42, r43, r44, r45, r46, r47, \
114 r48, r49, r50, r51, r52, tp, sp
115 {
116 sw r0, \reg
117 addi r0, r0, 4
118 }
119 .endr
120 {
121 sw r0, lr
122 addi r0, r0, PTREGS_OFFSET_PC - PTREGS_OFFSET_LR
123 }
124 lnk r1
125 {
126 sw r0, r1
127 addi r0, r0, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_PC
128 }
129 mfspr r1, INTERRUPT_CRITICAL_SECTION
130 shli r1, r1, SPR_EX_CONTEXT_1_1__ICS_SHIFT
131 ori r1, r1, KERNEL_PL
132 {
133 sw r0, r1
134 addi r0, r0, PTREGS_OFFSET_FAULTNUM - PTREGS_OFFSET_EX1
135 }
136 {
137 sw r0, zero /* clear faultnum */
138 addi r0, r0, PTREGS_OFFSET_ORIG_R0 - PTREGS_OFFSET_FAULTNUM
139 }
140 {
141 sw r0, zero /* clear orig_r0 */
142 addli r0, r0, -PTREGS_OFFSET_ORIG_R0 /* restore r0 to base */
143 }
144 jrp lr
145 STD_ENDPROC(get_pt_regs)
diff --git a/arch/tile/kernel/regs_64.S b/arch/tile/kernel/regs_64.S
deleted file mode 100644
index bbffcc6f340f..000000000000
--- a/arch/tile/kernel/regs_64.S
+++ /dev/null
@@ -1,145 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/linkage.h>
16#include <asm/ptrace.h>
17#include <asm/asm-offsets.h>
18#include <arch/spr_def.h>
19#include <asm/processor.h>
20#include <asm/switch_to.h>
21
22/*
23 * See <asm/switch_to.h>; called with prev and next task_struct pointers.
24 * "prev" is returned in r0 for _switch_to and also for ret_from_fork.
25 *
26 * We want to save pc/sp in "prev", and get the new pc/sp from "next".
27 * We also need to save all the callee-saved registers on the stack.
28 *
29 * Intel enables/disables access to the hardware cycle counter in
30 * seccomp (secure computing) environments if necessary, based on
31 * has_secure_computing(). We might want to do this at some point,
32 * though it would require virtualizing the other SPRs under WORLD_ACCESS.
33 *
34 * Since we're saving to the stack, we omit sp from this list.
35 * And for parallels with other architectures, we save lr separately,
36 * in the thread_struct itself (as the "pc" field).
37 *
38 * This code also needs to be aligned with process.c copy_thread()
39 */
40
41#if CALLEE_SAVED_REGS_COUNT != 24
42# error Mismatch between <asm/switch_to.h> and kernel/entry.S
43#endif
44#define FRAME_SIZE ((2 + CALLEE_SAVED_REGS_COUNT) * 8)
45
46#define SAVE_REG(r) { st r12, r; addi r12, r12, 8 }
47#define LOAD_REG(r) { ld r, r12; addi r12, r12, 8 }
48#define FOR_EACH_CALLEE_SAVED_REG(f) \
49 f(r30); f(r31); \
50 f(r32); f(r33); f(r34); f(r35); f(r36); f(r37); f(r38); f(r39); \
51 f(r40); f(r41); f(r42); f(r43); f(r44); f(r45); f(r46); f(r47); \
52 f(r48); f(r49); f(r50); f(r51); f(r52);
53
54STD_ENTRY_SECTION(__switch_to, .sched.text)
55 {
56 move r10, sp
57 st sp, lr
58 }
59 {
60 addli r11, sp, -FRAME_SIZE + 8
61 addli sp, sp, -FRAME_SIZE
62 }
63 {
64 st r11, r10
65 addli r4, r1, TASK_STRUCT_THREAD_KSP_OFFSET
66 }
67 {
68 ld r13, r4 /* Load new sp to a temp register early. */
69 addi r12, sp, 16
70 }
71 FOR_EACH_CALLEE_SAVED_REG(SAVE_REG)
72 addli r3, r0, TASK_STRUCT_THREAD_KSP_OFFSET
73 {
74 st r3, sp
75 addli r3, r0, TASK_STRUCT_THREAD_PC_OFFSET
76 }
77 {
78 st r3, lr
79 addli r4, r1, TASK_STRUCT_THREAD_PC_OFFSET
80 }
81 {
82 ld lr, r4
83 addi r12, r13, 16
84 }
85 {
86 /* Update sp and ksp0 simultaneously to avoid backtracer warnings. */
87 move sp, r13
88 mtspr SPR_SYSTEM_SAVE_K_0, r2
89 }
90 FOR_EACH_CALLEE_SAVED_REG(LOAD_REG)
91.L__switch_to_pc:
92 {
93 addli sp, sp, FRAME_SIZE
94 jrp lr /* r0 is still valid here, so return it */
95 }
96 STD_ENDPROC(__switch_to)
97
98/* Return a suitable address for the backtracer for suspended threads */
99STD_ENTRY_SECTION(get_switch_to_pc, .sched.text)
100 lnk r0
101 {
102 addli r0, r0, .L__switch_to_pc - .
103 jrp lr
104 }
105 STD_ENDPROC(get_switch_to_pc)
106
107STD_ENTRY(get_pt_regs)
108 .irp reg, r0, r1, r2, r3, r4, r5, r6, r7, \
109 r8, r9, r10, r11, r12, r13, r14, r15, \
110 r16, r17, r18, r19, r20, r21, r22, r23, \
111 r24, r25, r26, r27, r28, r29, r30, r31, \
112 r32, r33, r34, r35, r36, r37, r38, r39, \
113 r40, r41, r42, r43, r44, r45, r46, r47, \
114 r48, r49, r50, r51, r52, tp, sp
115 {
116 st r0, \reg
117 addi r0, r0, 8
118 }
119 .endr
120 {
121 st r0, lr
122 addi r0, r0, PTREGS_OFFSET_PC - PTREGS_OFFSET_LR
123 }
124 lnk r1
125 {
126 st r0, r1
127 addi r0, r0, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_PC
128 }
129 mfspr r1, INTERRUPT_CRITICAL_SECTION
130 shli r1, r1, SPR_EX_CONTEXT_1_1__ICS_SHIFT
131 ori r1, r1, KERNEL_PL
132 {
133 st r0, r1
134 addi r0, r0, PTREGS_OFFSET_FAULTNUM - PTREGS_OFFSET_EX1
135 }
136 {
137 st r0, zero /* clear faultnum */
138 addi r0, r0, PTREGS_OFFSET_ORIG_R0 - PTREGS_OFFSET_FAULTNUM
139 }
140 {
141 st r0, zero /* clear orig_r0 */
142 addli r0, r0, -PTREGS_OFFSET_ORIG_R0 /* restore r0 to base */
143 }
144 jrp lr
145 STD_ENDPROC(get_pt_regs)
diff --git a/arch/tile/kernel/relocate_kernel_32.S b/arch/tile/kernel/relocate_kernel_32.S
deleted file mode 100644
index e44fbcf8cbd5..000000000000
--- a/arch/tile/kernel/relocate_kernel_32.S
+++ /dev/null
@@ -1,269 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * copy new kernel into place and then call hv_reexec
15 *
16 */
17
18#include <linux/linkage.h>
19#include <arch/chip.h>
20#include <asm/page.h>
21#include <hv/hypervisor.h>
22
23#undef RELOCATE_NEW_KERNEL_VERBOSE
24
25STD_ENTRY(relocate_new_kernel)
26
27 move r30, r0 /* page list */
28 move r31, r1 /* address of page we are on */
29 move r32, r2 /* start address of new kernel */
30
31 shri r1, r1, PAGE_SHIFT
32 addi r1, r1, 1
33 shli sp, r1, PAGE_SHIFT
34 addi sp, sp, -8
35 /* we now have a stack (whether we need one or not) */
36
37 moveli r40, lo16(hv_console_putc)
38 auli r40, r40, ha16(hv_console_putc)
39
40#ifdef RELOCATE_NEW_KERNEL_VERBOSE
41 moveli r0, 'r'
42 jalr r40
43
44 moveli r0, '_'
45 jalr r40
46
47 moveli r0, 'n'
48 jalr r40
49
50 moveli r0, '_'
51 jalr r40
52
53 moveli r0, 'k'
54 jalr r40
55
56 moveli r0, '\n'
57 jalr r40
58#endif
59
60 /*
61 * Throughout this code r30 is pointer to the element of page
62 * list we are working on.
63 *
64 * Normally we get to the next element of the page list by
65 * incrementing r30 by four. The exception is if the element
66 * on the page list is an IND_INDIRECTION in which case we use
67 * the element with the low bits masked off as the new value
68 * of r30.
69 *
70 * To get this started, we need the value passed to us (which
71 * will always be an IND_INDIRECTION) in memory somewhere with
72 * r30 pointing at it. To do that, we push the value passed
73 * to us on the stack and make r30 point to it.
74 */
75
76 sw sp, r30
77 move r30, sp
78 addi sp, sp, -8
79
80 /*
81 * On TILEPro, we need to flush all tiles' caches, since we may
82 * have been doing hash-for-home caching there. Note that we
83 * must do this _after_ we're completely done modifying any memory
84 * other than our output buffer (which we know is locally cached).
85 * We want the caches to be fully clean when we do the reexec,
86 * because the hypervisor is going to do this flush again at that
87 * point, and we don't want that second flush to overwrite any memory.
88 */
89 {
90 move r0, zero /* cache_pa */
91 move r1, zero
92 }
93 {
94 auli r2, zero, ha16(HV_FLUSH_EVICT_L2) /* cache_control */
95 movei r3, -1 /* cache_cpumask; -1 means all client tiles */
96 }
97 {
98 move r4, zero /* tlb_va */
99 move r5, zero /* tlb_length */
100 }
101 {
102 move r6, zero /* tlb_pgsize */
103 move r7, zero /* tlb_cpumask */
104 }
105 {
106 move r8, zero /* asids */
107 moveli r20, lo16(hv_flush_remote)
108 }
109 {
110 move r9, zero /* asidcount */
111 auli r20, r20, ha16(hv_flush_remote)
112 }
113
114 jalr r20
115
116 /* r33 is destination pointer, default to zero */
117
118 moveli r33, 0
119
120.Lloop: lw r10, r30
121
122 andi r9, r10, 0xf /* low 4 bits tell us what type it is */
123 xor r10, r10, r9 /* r10 is now value with low 4 bits stripped */
124
125 seqi r0, r9, 0x1 /* IND_DESTINATION */
126 bzt r0, .Ltry2
127
128 move r33, r10
129
130#ifdef RELOCATE_NEW_KERNEL_VERBOSE
131 moveli r0, 'd'
132 jalr r40
133#endif
134
135 addi r30, r30, 4
136 j .Lloop
137
138.Ltry2:
139 seqi r0, r9, 0x2 /* IND_INDIRECTION */
140 bzt r0, .Ltry4
141
142 move r30, r10
143
144#ifdef RELOCATE_NEW_KERNEL_VERBOSE
145 moveli r0, 'i'
146 jalr r40
147#endif
148
149 j .Lloop
150
151.Ltry4:
152 seqi r0, r9, 0x4 /* IND_DONE */
153 bzt r0, .Ltry8
154
155 mf
156
157#ifdef RELOCATE_NEW_KERNEL_VERBOSE
158 moveli r0, 'D'
159 jalr r40
160 moveli r0, '\n'
161 jalr r40
162#endif
163
164 move r0, r32
165 moveli r1, 0 /* arg to hv_reexec is 64 bits */
166
167 moveli r41, lo16(hv_reexec)
168 auli r41, r41, ha16(hv_reexec)
169
170 jalr r41
171
172 /* we should not get here */
173
174 moveli r0, '?'
175 jalr r40
176 moveli r0, '\n'
177 jalr r40
178
179 j .Lhalt
180
181.Ltry8: seqi r0, r9, 0x8 /* IND_SOURCE */
182 bz r0, .Lerr /* unknown type */
183
184 /* copy page at r10 to page at r33 */
185
186 move r11, r33
187
188 moveli r0, lo16(PAGE_SIZE)
189 auli r0, r0, ha16(PAGE_SIZE)
190 add r33, r33, r0
191
192 /* copy word at r10 to word at r11 until r11 equals r33 */
193
194 /* We know page size must be multiple of 16, so we can unroll
195 * 16 times safely without any edge case checking.
196 *
197 * Issue a flush of the destination every 16 words to avoid
198 * incoherence when starting the new kernel. (Now this is
199 * just good paranoia because the hv_reexec call will also
200 * take care of this.)
201 */
202
2031:
204 { lw r0, r10; addi r10, r10, 4 }
205 { sw r11, r0; addi r11, r11, 4 }
206 { lw r0, r10; addi r10, r10, 4 }
207 { sw r11, r0; addi r11, r11, 4 }
208 { lw r0, r10; addi r10, r10, 4 }
209 { sw r11, r0; addi r11, r11, 4 }
210 { lw r0, r10; addi r10, r10, 4 }
211 { sw r11, r0; addi r11, r11, 4 }
212 { lw r0, r10; addi r10, r10, 4 }
213 { sw r11, r0; addi r11, r11, 4 }
214 { lw r0, r10; addi r10, r10, 4 }
215 { sw r11, r0; addi r11, r11, 4 }
216 { lw r0, r10; addi r10, r10, 4 }
217 { sw r11, r0; addi r11, r11, 4 }
218 { lw r0, r10; addi r10, r10, 4 }
219 { sw r11, r0; addi r11, r11, 4 }
220 { lw r0, r10; addi r10, r10, 4 }
221 { sw r11, r0; addi r11, r11, 4 }
222 { lw r0, r10; addi r10, r10, 4 }
223 { sw r11, r0; addi r11, r11, 4 }
224 { lw r0, r10; addi r10, r10, 4 }
225 { sw r11, r0; addi r11, r11, 4 }
226 { lw r0, r10; addi r10, r10, 4 }
227 { sw r11, r0; addi r11, r11, 4 }
228 { lw r0, r10; addi r10, r10, 4 }
229 { sw r11, r0; addi r11, r11, 4 }
230 { lw r0, r10; addi r10, r10, 4 }
231 { sw r11, r0; addi r11, r11, 4 }
232 { lw r0, r10; addi r10, r10, 4 }
233 { sw r11, r0; addi r11, r11, 4 }
234 { lw r0, r10; addi r10, r10, 4 }
235 { sw r11, r0 }
236 { flush r11 ; addi r11, r11, 4 }
237
238 seq r0, r33, r11
239 bzt r0, 1b
240
241#ifdef RELOCATE_NEW_KERNEL_VERBOSE
242 moveli r0, 's'
243 jalr r40
244#endif
245
246 addi r30, r30, 4
247 j .Lloop
248
249
250.Lerr: moveli r0, 'e'
251 jalr r40
252 moveli r0, 'r'
253 jalr r40
254 moveli r0, 'r'
255 jalr r40
256 moveli r0, '\n'
257 jalr r40
258.Lhalt:
259 moveli r41, lo16(hv_halt)
260 auli r41, r41, ha16(hv_halt)
261
262 jalr r41
263 STD_ENDPROC(relocate_new_kernel)
264
265 .section .rodata,"a"
266
267 .globl relocate_new_kernel_size
268relocate_new_kernel_size:
269 .long .Lend_relocate_new_kernel - relocate_new_kernel
diff --git a/arch/tile/kernel/relocate_kernel_64.S b/arch/tile/kernel/relocate_kernel_64.S
deleted file mode 100644
index d9d8cf6176e8..000000000000
--- a/arch/tile/kernel/relocate_kernel_64.S
+++ /dev/null
@@ -1,263 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * copy new kernel into place and then call hv_reexec
15 *
16 */
17
18#include <linux/linkage.h>
19#include <arch/chip.h>
20#include <asm/page.h>
21#include <hv/hypervisor.h>
22
23#undef RELOCATE_NEW_KERNEL_VERBOSE
24
25STD_ENTRY(relocate_new_kernel)
26
27 move r30, r0 /* page list */
28 move r31, r1 /* address of page we are on */
29 move r32, r2 /* start address of new kernel */
30
31 shrui r1, r1, PAGE_SHIFT
32 addi r1, r1, 1
33 shli sp, r1, PAGE_SHIFT
34 addi sp, sp, -8
35 /* we now have a stack (whether we need one or not) */
36
37#ifdef RELOCATE_NEW_KERNEL_VERBOSE
38 moveli r40, hw2_last(hv_console_putc)
39 shl16insli r40, r40, hw1(hv_console_putc)
40 shl16insli r40, r40, hw0(hv_console_putc)
41
42 moveli r0, 'r'
43 jalr r40
44
45 moveli r0, '_'
46 jalr r40
47
48 moveli r0, 'n'
49 jalr r40
50
51 moveli r0, '_'
52 jalr r40
53
54 moveli r0, 'k'
55 jalr r40
56
57 moveli r0, '\n'
58 jalr r40
59#endif
60
61 /*
62 * Throughout this code r30 is pointer to the element of page
63 * list we are working on.
64 *
65 * Normally we get to the next element of the page list by
66 * incrementing r30 by eight. The exception is if the element
67 * on the page list is an IND_INDIRECTION in which case we use
68 * the element with the low bits masked off as the new value
69 * of r30.
70 *
71 * To get this started, we need the value passed to us (which
72 * will always be an IND_INDIRECTION) in memory somewhere with
73 * r30 pointing at it. To do that, we push the value passed
74 * to us on the stack and make r30 point to it.
75 */
76
77 st sp, r30
78 move r30, sp
79 addi sp, sp, -16
80
81 /*
82 * On TILE-GX, we need to flush all tiles' caches, since we may
83 * have been doing hash-for-home caching there. Note that we
84 * must do this _after_ we're completely done modifying any memory
85 * other than our output buffer (which we know is locally cached).
86 * We want the caches to be fully clean when we do the reexec,
87 * because the hypervisor is going to do this flush again at that
88 * point, and we don't want that second flush to overwrite any memory.
89 */
90 {
91 move r0, zero /* cache_pa */
92 moveli r1, hw2_last(HV_FLUSH_EVICT_L2)
93 }
94 {
95 shl16insli r1, r1, hw1(HV_FLUSH_EVICT_L2)
96 movei r2, -1 /* cache_cpumask; -1 means all client tiles */
97 }
98 {
99 shl16insli r1, r1, hw0(HV_FLUSH_EVICT_L2) /* cache_control */
100 move r3, zero /* tlb_va */
101 }
102 {
103 move r4, zero /* tlb_length */
104 move r5, zero /* tlb_pgsize */
105 }
106 {
107 move r6, zero /* tlb_cpumask */
108 move r7, zero /* asids */
109 }
110 {
111 moveli r20, hw2_last(hv_flush_remote)
112 move r8, zero /* asidcount */
113 }
114 shl16insli r20, r20, hw1(hv_flush_remote)
115 shl16insli r20, r20, hw0(hv_flush_remote)
116
117 jalr r20
118
119 /* r33 is destination pointer, default to zero */
120
121 moveli r33, 0
122
123.Lloop: ld r10, r30
124
125 andi r9, r10, 0xf /* low 4 bits tell us what type it is */
126 xor r10, r10, r9 /* r10 is now value with low 4 bits stripped */
127
128 cmpeqi r0, r9, 0x1 /* IND_DESTINATION */
129 beqzt r0, .Ltry2
130
131 move r33, r10
132
133#ifdef RELOCATE_NEW_KERNEL_VERBOSE
134 moveli r0, 'd'
135 jalr r40
136#endif
137
138 addi r30, r30, 8
139 j .Lloop
140
141.Ltry2:
142 cmpeqi r0, r9, 0x2 /* IND_INDIRECTION */
143 beqzt r0, .Ltry4
144
145 move r30, r10
146
147#ifdef RELOCATE_NEW_KERNEL_VERBOSE
148 moveli r0, 'i'
149 jalr r40
150#endif
151
152 j .Lloop
153
154.Ltry4:
155 cmpeqi r0, r9, 0x4 /* IND_DONE */
156 beqzt r0, .Ltry8
157
158 mf
159
160#ifdef RELOCATE_NEW_KERNEL_VERBOSE
161 moveli r0, 'D'
162 jalr r40
163 moveli r0, '\n'
164 jalr r40
165#endif
166
167 move r0, r32
168
169 moveli r41, hw2_last(hv_reexec)
170 shl16insli r41, r41, hw1(hv_reexec)
171 shl16insli r41, r41, hw0(hv_reexec)
172
173 jalr r41
174
175 /* we should not get here */
176
177#ifdef RELOCATE_NEW_KERNEL_VERBOSE
178 moveli r0, '?'
179 jalr r40
180 moveli r0, '\n'
181 jalr r40
182#endif
183
184 j .Lhalt
185
186.Ltry8: cmpeqi r0, r9, 0x8 /* IND_SOURCE */
187 beqz r0, .Lerr /* unknown type */
188
189 /* copy page at r10 to page at r33 */
190
191 move r11, r33
192
193 moveli r0, hw2_last(PAGE_SIZE)
194 shl16insli r0, r0, hw1(PAGE_SIZE)
195 shl16insli r0, r0, hw0(PAGE_SIZE)
196 add r33, r33, r0
197
198 /* copy word at r10 to word at r11 until r11 equals r33 */
199
200 /* We know page size must be multiple of 8, so we can unroll
201 * 8 times safely without any edge case checking.
202 *
203 * Issue a flush of the destination every 8 words to avoid
204 * incoherence when starting the new kernel. (Now this is
205 * just good paranoia because the hv_reexec call will also
206 * take care of this.)
207 */
208
2091:
210 { ld r0, r10; addi r10, r10, 8 }
211 { st r11, r0; addi r11, r11, 8 }
212 { ld r0, r10; addi r10, r10, 8 }
213 { st r11, r0; addi r11, r11, 8 }
214 { ld r0, r10; addi r10, r10, 8 }
215 { st r11, r0; addi r11, r11, 8 }
216 { ld r0, r10; addi r10, r10, 8 }
217 { st r11, r0; addi r11, r11, 8 }
218 { ld r0, r10; addi r10, r10, 8 }
219 { st r11, r0; addi r11, r11, 8 }
220 { ld r0, r10; addi r10, r10, 8 }
221 { st r11, r0; addi r11, r11, 8 }
222 { ld r0, r10; addi r10, r10, 8 }
223 { st r11, r0; addi r11, r11, 8 }
224 { ld r0, r10; addi r10, r10, 8 }
225 { st r11, r0 }
226 { flush r11 ; addi r11, r11, 8 }
227
228 cmpeq r0, r33, r11
229 beqzt r0, 1b
230
231#ifdef RELOCATE_NEW_KERNEL_VERBOSE
232 moveli r0, 's'
233 jalr r40
234#endif
235
236 addi r30, r30, 8
237 j .Lloop
238
239
240.Lerr:
241#ifdef RELOCATE_NEW_KERNEL_VERBOSE
242 moveli r0, 'e'
243 jalr r40
244 moveli r0, 'r'
245 jalr r40
246 moveli r0, 'r'
247 jalr r40
248 moveli r0, '\n'
249 jalr r40
250#endif
251.Lhalt:
252 moveli r41, hw2_last(hv_halt)
253 shl16insli r41, r41, hw1(hv_halt)
254 shl16insli r41, r41, hw0(hv_halt)
255
256 jalr r41
257 STD_ENDPROC(relocate_new_kernel)
258
259 .section .rodata,"a"
260
261 .globl relocate_new_kernel_size
262relocate_new_kernel_size:
263 .long .Lend_relocate_new_kernel - relocate_new_kernel
diff --git a/arch/tile/kernel/setup.c b/arch/tile/kernel/setup.c
deleted file mode 100644
index eb4e198f6f93..000000000000
--- a/arch/tile/kernel/setup.c
+++ /dev/null
@@ -1,1743 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/sched.h>
16#include <linux/kernel.h>
17#include <linux/mmzone.h>
18#include <linux/bootmem.h>
19#include <linux/module.h>
20#include <linux/node.h>
21#include <linux/cpu.h>
22#include <linux/ioport.h>
23#include <linux/irq.h>
24#include <linux/kexec.h>
25#include <linux/pci.h>
26#include <linux/swiotlb.h>
27#include <linux/initrd.h>
28#include <linux/io.h>
29#include <linux/highmem.h>
30#include <linux/smp.h>
31#include <linux/timex.h>
32#include <linux/hugetlb.h>
33#include <linux/start_kernel.h>
34#include <linux/screen_info.h>
35#include <linux/tick.h>
36#include <asm/setup.h>
37#include <asm/sections.h>
38#include <asm/cacheflush.h>
39#include <asm/pgalloc.h>
40#include <asm/mmu_context.h>
41#include <hv/hypervisor.h>
42#include <arch/interrupts.h>
43
44/* <linux/smp.h> doesn't provide this definition. */
45#ifndef CONFIG_SMP
46#define setup_max_cpus 1
47#endif
48
49static inline int ABS(int x) { return x >= 0 ? x : -x; }
50
51/* Chip information */
52char chip_model[64] __ro_after_init;
53
54#ifdef CONFIG_VT
55struct screen_info screen_info;
56#endif
57
58struct pglist_data node_data[MAX_NUMNODES] __read_mostly;
59EXPORT_SYMBOL(node_data);
60
61/* Information on the NUMA nodes that we compute early */
62unsigned long node_start_pfn[MAX_NUMNODES];
63unsigned long node_end_pfn[MAX_NUMNODES];
64unsigned long __initdata node_memmap_pfn[MAX_NUMNODES];
65unsigned long __initdata node_percpu_pfn[MAX_NUMNODES];
66unsigned long __initdata node_free_pfn[MAX_NUMNODES];
67
68static unsigned long __initdata node_percpu[MAX_NUMNODES];
69
70/*
71 * per-CPU stack and boot info.
72 */
73DEFINE_PER_CPU(unsigned long, boot_sp) =
74 (unsigned long)init_stack + THREAD_SIZE - STACK_TOP_DELTA;
75
76#ifdef CONFIG_SMP
77DEFINE_PER_CPU(unsigned long, boot_pc) = (unsigned long)start_kernel;
78#else
79/*
80 * The variable must be __initdata since it references __init code.
81 * With CONFIG_SMP it is per-cpu data, which is exempt from validation.
82 */
83unsigned long __initdata boot_pc = (unsigned long)start_kernel;
84#endif
85
86#ifdef CONFIG_HIGHMEM
87/* Page frame index of end of lowmem on each controller. */
88unsigned long node_lowmem_end_pfn[MAX_NUMNODES];
89
90/* Number of pages that can be mapped into lowmem. */
91static unsigned long __initdata mappable_physpages;
92#endif
93
94/* Data on which physical memory controller corresponds to which NUMA node */
95int node_controller[MAX_NUMNODES] = { [0 ... MAX_NUMNODES-1] = -1 };
96
97#ifdef CONFIG_HIGHMEM
98/* Map information from VAs to PAs */
99unsigned long pbase_map[1 << (32 - HPAGE_SHIFT)]
100 __ro_after_init __attribute__((aligned(L2_CACHE_BYTES)));
101EXPORT_SYMBOL(pbase_map);
102
103/* Map information from PAs to VAs */
104void *vbase_map[NR_PA_HIGHBIT_VALUES]
105 __ro_after_init __attribute__((aligned(L2_CACHE_BYTES)));
106EXPORT_SYMBOL(vbase_map);
107#endif
108
109/* Node number as a function of the high PA bits */
110int highbits_to_node[NR_PA_HIGHBIT_VALUES] __ro_after_init;
111EXPORT_SYMBOL(highbits_to_node);
112
113static unsigned int __initdata maxmem_pfn = -1U;
114static unsigned int __initdata maxnodemem_pfn[MAX_NUMNODES] = {
115 [0 ... MAX_NUMNODES-1] = -1U
116};
117static nodemask_t __initdata isolnodes;
118
119#if defined(CONFIG_PCI) && !defined(__tilegx__)
120enum { DEFAULT_PCI_RESERVE_MB = 64 };
121static unsigned int __initdata pci_reserve_mb = DEFAULT_PCI_RESERVE_MB;
122unsigned long __initdata pci_reserve_start_pfn = -1U;
123unsigned long __initdata pci_reserve_end_pfn = -1U;
124#endif
125
126static int __init setup_maxmem(char *str)
127{
128 unsigned long long maxmem;
129 if (str == NULL || (maxmem = memparse(str, NULL)) == 0)
130 return -EINVAL;
131
132 maxmem_pfn = (maxmem >> HPAGE_SHIFT) << (HPAGE_SHIFT - PAGE_SHIFT);
133 pr_info("Forcing RAM used to no more than %dMB\n",
134 maxmem_pfn >> (20 - PAGE_SHIFT));
135 return 0;
136}
137early_param("maxmem", setup_maxmem);
138
139static int __init setup_maxnodemem(char *str)
140{
141 char *endp;
142 unsigned long long maxnodemem;
143 unsigned long node;
144
145 node = str ? simple_strtoul(str, &endp, 0) : INT_MAX;
146 if (node >= MAX_NUMNODES || *endp != ':')
147 return -EINVAL;
148
149 maxnodemem = memparse(endp+1, NULL);
150 maxnodemem_pfn[node] = (maxnodemem >> HPAGE_SHIFT) <<
151 (HPAGE_SHIFT - PAGE_SHIFT);
152 pr_info("Forcing RAM used on node %ld to no more than %dMB\n",
153 node, maxnodemem_pfn[node] >> (20 - PAGE_SHIFT));
154 return 0;
155}
156early_param("maxnodemem", setup_maxnodemem);
157
158struct memmap_entry {
159 u64 addr; /* start of memory segment */
160 u64 size; /* size of memory segment */
161};
162static struct memmap_entry memmap_map[64];
163static int memmap_nr;
164
165static void add_memmap_region(u64 addr, u64 size)
166{
167 if (memmap_nr >= ARRAY_SIZE(memmap_map)) {
168 pr_err("Ooops! Too many entries in the memory map!\n");
169 return;
170 }
171 memmap_map[memmap_nr].addr = addr;
172 memmap_map[memmap_nr].size = size;
173 memmap_nr++;
174}
175
176static int __init setup_memmap(char *p)
177{
178 char *oldp;
179 u64 start_at, mem_size;
180
181 if (!p)
182 return -EINVAL;
183
184 if (!strncmp(p, "exactmap", 8)) {
185 pr_err("\"memmap=exactmap\" not valid on tile\n");
186 return 0;
187 }
188
189 oldp = p;
190 mem_size = memparse(p, &p);
191 if (p == oldp)
192 return -EINVAL;
193
194 if (*p == '@') {
195 pr_err("\"memmap=nn@ss\" (force RAM) invalid on tile\n");
196 } else if (*p == '#') {
197 pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on tile\n");
198 } else if (*p == '$') {
199 start_at = memparse(p+1, &p);
200 add_memmap_region(start_at, mem_size);
201 } else {
202 if (mem_size == 0)
203 return -EINVAL;
204 maxmem_pfn = (mem_size >> HPAGE_SHIFT) <<
205 (HPAGE_SHIFT - PAGE_SHIFT);
206 }
207 return *p == '\0' ? 0 : -EINVAL;
208}
209early_param("memmap", setup_memmap);
210
211static int __init setup_mem(char *str)
212{
213 return setup_maxmem(str);
214}
215early_param("mem", setup_mem); /* compatibility with x86 */
216
217static int __init setup_isolnodes(char *str)
218{
219 if (str == NULL || nodelist_parse(str, isolnodes) != 0)
220 return -EINVAL;
221
222 pr_info("Set isolnodes value to '%*pbl'\n",
223 nodemask_pr_args(&isolnodes));
224 return 0;
225}
226early_param("isolnodes", setup_isolnodes);
227
228#if defined(CONFIG_PCI) && !defined(__tilegx__)
229static int __init setup_pci_reserve(char* str)
230{
231 if (str == NULL || kstrtouint(str, 0, &pci_reserve_mb) != 0 ||
232 pci_reserve_mb > 3 * 1024)
233 return -EINVAL;
234
235 pr_info("Reserving %dMB for PCIE root complex mappings\n",
236 pci_reserve_mb);
237 return 0;
238}
239early_param("pci_reserve", setup_pci_reserve);
240#endif
241
242#ifndef __tilegx__
243/*
244 * vmalloc=size forces the vmalloc area to be exactly 'size' bytes.
245 * This can be used to increase (or decrease) the vmalloc area.
246 */
247static int __init parse_vmalloc(char *arg)
248{
249 if (!arg)
250 return -EINVAL;
251
252 VMALLOC_RESERVE = (memparse(arg, &arg) + PGDIR_SIZE - 1) & PGDIR_MASK;
253
254 /* See validate_va() for more on this test. */
255 if ((long)_VMALLOC_START >= 0)
256 early_panic("\"vmalloc=%#lx\" value too large: maximum %#lx\n",
257 VMALLOC_RESERVE, _VMALLOC_END - 0x80000000UL);
258
259 return 0;
260}
261early_param("vmalloc", parse_vmalloc);
262#endif
263
264#ifdef CONFIG_HIGHMEM
265/*
266 * Determine for each controller where its lowmem is mapped and how much of
267 * it is mapped there. On controller zero, the first few megabytes are
268 * already mapped in as code at MEM_SV_START, so in principle we could
269 * start our data mappings higher up, but for now we don't bother, to avoid
270 * additional confusion.
271 *
272 * One question is whether, on systems with more than 768 Mb and
273 * controllers of different sizes, to map in a proportionate amount of
274 * each one, or to try to map the same amount from each controller.
275 * (E.g. if we have three controllers with 256MB, 1GB, and 256MB
276 * respectively, do we map 256MB from each, or do we map 128 MB, 512
277 * MB, and 128 MB respectively?) For now we use a proportionate
278 * solution like the latter.
279 *
280 * The VA/PA mapping demands that we align our decisions at 16 MB
281 * boundaries so that we can rapidly convert VA to PA.
282 */
283static void *__init setup_pa_va_mapping(void)
284{
285 unsigned long curr_pages = 0;
286 unsigned long vaddr = PAGE_OFFSET;
287 nodemask_t highonlynodes = isolnodes;
288 int i, j;
289
290 memset(pbase_map, -1, sizeof(pbase_map));
291 memset(vbase_map, -1, sizeof(vbase_map));
292
293 /* Node zero cannot be isolated for LOWMEM purposes. */
294 node_clear(0, highonlynodes);
295
296 /* Count up the number of pages on non-highonlynodes controllers. */
297 mappable_physpages = 0;
298 for_each_online_node(i) {
299 if (!node_isset(i, highonlynodes))
300 mappable_physpages +=
301 node_end_pfn[i] - node_start_pfn[i];
302 }
303
304 for_each_online_node(i) {
305 unsigned long start = node_start_pfn[i];
306 unsigned long end = node_end_pfn[i];
307 unsigned long size = end - start;
308 unsigned long vaddr_end;
309
310 if (node_isset(i, highonlynodes)) {
311 /* Mark this controller as having no lowmem. */
312 node_lowmem_end_pfn[i] = start;
313 continue;
314 }
315
316 curr_pages += size;
317 if (mappable_physpages > MAXMEM_PFN) {
318 vaddr_end = PAGE_OFFSET +
319 (((u64)curr_pages * MAXMEM_PFN /
320 mappable_physpages)
321 << PAGE_SHIFT);
322 } else {
323 vaddr_end = PAGE_OFFSET + (curr_pages << PAGE_SHIFT);
324 }
325 for (j = 0; vaddr < vaddr_end; vaddr += HPAGE_SIZE, ++j) {
326 unsigned long this_pfn =
327 start + (j << HUGETLB_PAGE_ORDER);
328 pbase_map[vaddr >> HPAGE_SHIFT] = this_pfn;
329 if (vbase_map[__pfn_to_highbits(this_pfn)] ==
330 (void *)-1)
331 vbase_map[__pfn_to_highbits(this_pfn)] =
332 (void *)(vaddr & HPAGE_MASK);
333 }
334 node_lowmem_end_pfn[i] = start + (j << HUGETLB_PAGE_ORDER);
335 BUG_ON(node_lowmem_end_pfn[i] > end);
336 }
337
338 /* Return highest address of any mapped memory. */
339 return (void *)vaddr;
340}
341#endif /* CONFIG_HIGHMEM */
342
343/*
344 * Register our most important memory mappings with the debug stub.
345 *
346 * This is up to 4 mappings for lowmem, one mapping per memory
347 * controller, plus one for our text segment.
348 */
349static void store_permanent_mappings(void)
350{
351 int i;
352
353 for_each_online_node(i) {
354 HV_PhysAddr pa = ((HV_PhysAddr)node_start_pfn[i]) << PAGE_SHIFT;
355#ifdef CONFIG_HIGHMEM
356 HV_PhysAddr high_mapped_pa = node_lowmem_end_pfn[i];
357#else
358 HV_PhysAddr high_mapped_pa = node_end_pfn[i];
359#endif
360
361 unsigned long pages = high_mapped_pa - node_start_pfn[i];
362 HV_VirtAddr addr = (HV_VirtAddr) __va(pa);
363 hv_store_mapping(addr, pages << PAGE_SHIFT, pa);
364 }
365
366 hv_store_mapping((HV_VirtAddr)_text,
367 (uint32_t)(_einittext - _text), 0);
368}
369
370/*
371 * Use hv_inquire_physical() to populate node_{start,end}_pfn[]
372 * and node_online_map, doing suitable sanity-checking.
373 * Also set min_low_pfn, max_low_pfn, and max_pfn.
374 */
375static void __init setup_memory(void)
376{
377 int i, j;
378 int highbits_seen[NR_PA_HIGHBIT_VALUES] = { 0 };
379#ifdef CONFIG_HIGHMEM
380 long highmem_pages;
381#endif
382#ifndef __tilegx__
383 int cap;
384#endif
385#if defined(CONFIG_HIGHMEM) || defined(__tilegx__)
386 long lowmem_pages;
387#endif
388 unsigned long physpages = 0;
389
390 /* We are using a char to hold the cpu_2_node[] mapping */
391 BUILD_BUG_ON(MAX_NUMNODES > 127);
392
393 /* Discover the ranges of memory available to us */
394 for (i = 0; ; ++i) {
395 unsigned long start, size, end, highbits;
396 HV_PhysAddrRange range = hv_inquire_physical(i);
397 if (range.size == 0)
398 break;
399#ifdef CONFIG_FLATMEM
400 if (i > 0) {
401 pr_err("Can't use discontiguous PAs: %#llx..%#llx\n",
402 range.size, range.start + range.size);
403 continue;
404 }
405#endif
406#ifndef __tilegx__
407 if ((unsigned long)range.start) {
408 pr_err("Range not at 4GB multiple: %#llx..%#llx\n",
409 range.start, range.start + range.size);
410 continue;
411 }
412#endif
413 if ((range.start & (HPAGE_SIZE-1)) != 0 ||
414 (range.size & (HPAGE_SIZE-1)) != 0) {
415 unsigned long long start_pa = range.start;
416 unsigned long long orig_size = range.size;
417 range.start = (start_pa + HPAGE_SIZE - 1) & HPAGE_MASK;
418 range.size -= (range.start - start_pa);
419 range.size &= HPAGE_MASK;
420 pr_err("Range not hugepage-aligned: %#llx..%#llx: now %#llx-%#llx\n",
421 start_pa, start_pa + orig_size,
422 range.start, range.start + range.size);
423 }
424 highbits = __pa_to_highbits(range.start);
425 if (highbits >= NR_PA_HIGHBIT_VALUES) {
426 pr_err("PA high bits too high: %#llx..%#llx\n",
427 range.start, range.start + range.size);
428 continue;
429 }
430 if (highbits_seen[highbits]) {
431 pr_err("Range overlaps in high bits: %#llx..%#llx\n",
432 range.start, range.start + range.size);
433 continue;
434 }
435 highbits_seen[highbits] = 1;
436 if (PFN_DOWN(range.size) > maxnodemem_pfn[i]) {
437 int max_size = maxnodemem_pfn[i];
438 if (max_size > 0) {
439 pr_err("Maxnodemem reduced node %d to %d pages\n",
440 i, max_size);
441 range.size = PFN_PHYS(max_size);
442 } else {
443 pr_err("Maxnodemem disabled node %d\n", i);
444 continue;
445 }
446 }
447 if (physpages + PFN_DOWN(range.size) > maxmem_pfn) {
448 int max_size = maxmem_pfn - physpages;
449 if (max_size > 0) {
450 pr_err("Maxmem reduced node %d to %d pages\n",
451 i, max_size);
452 range.size = PFN_PHYS(max_size);
453 } else {
454 pr_err("Maxmem disabled node %d\n", i);
455 continue;
456 }
457 }
458 if (i >= MAX_NUMNODES) {
459 pr_err("Too many PA nodes (#%d): %#llx...%#llx\n",
460 i, range.size, range.size + range.start);
461 continue;
462 }
463
464 start = range.start >> PAGE_SHIFT;
465 size = range.size >> PAGE_SHIFT;
466 end = start + size;
467
468#ifndef __tilegx__
469 if (((HV_PhysAddr)end << PAGE_SHIFT) !=
470 (range.start + range.size)) {
471 pr_err("PAs too high to represent: %#llx..%#llx\n",
472 range.start, range.start + range.size);
473 continue;
474 }
475#endif
476#if defined(CONFIG_PCI) && !defined(__tilegx__)
477 /*
478 * Blocks that overlap the pci reserved region must
479 * have enough space to hold the maximum percpu data
480 * region at the top of the range. If there isn't
481 * enough space above the reserved region, just
482 * truncate the node.
483 */
484 if (start <= pci_reserve_start_pfn &&
485 end > pci_reserve_start_pfn) {
486 unsigned int per_cpu_size =
487 __per_cpu_end - __per_cpu_start;
488 unsigned int percpu_pages =
489 NR_CPUS * (PFN_UP(per_cpu_size) >> PAGE_SHIFT);
490 if (end < pci_reserve_end_pfn + percpu_pages) {
491 end = pci_reserve_start_pfn;
492 pr_err("PCI mapping region reduced node %d to %ld pages\n",
493 i, end - start);
494 }
495 }
496#endif
497
498 for (j = __pfn_to_highbits(start);
499 j <= __pfn_to_highbits(end - 1); j++)
500 highbits_to_node[j] = i;
501
502 node_start_pfn[i] = start;
503 node_end_pfn[i] = end;
504 node_controller[i] = range.controller;
505 physpages += size;
506 max_pfn = end;
507
508 /* Mark node as online */
509 node_set(i, node_online_map);
510 node_set(i, node_possible_map);
511 }
512
513#ifndef __tilegx__
514 /*
515 * For 4KB pages, mem_map "struct page" data is 1% of the size
516 * of the physical memory, so can be quite big (640 MB for
517 * four 16G zones). These structures must be mapped in
518 * lowmem, and since we currently cap out at about 768 MB,
519 * it's impractical to try to use this much address space.
520 * For now, arbitrarily cap the amount of physical memory
521 * we're willing to use at 8 million pages (32GB of 4KB pages).
522 */
523 cap = 8 * 1024 * 1024; /* 8 million pages */
524 if (physpages > cap) {
525 int num_nodes = num_online_nodes();
526 int cap_each = cap / num_nodes;
527 unsigned long dropped_pages = 0;
528 for (i = 0; i < num_nodes; ++i) {
529 int size = node_end_pfn[i] - node_start_pfn[i];
530 if (size > cap_each) {
531 dropped_pages += (size - cap_each);
532 node_end_pfn[i] = node_start_pfn[i] + cap_each;
533 }
534 }
535 physpages -= dropped_pages;
536 pr_warn("Only using %ldMB memory - ignoring %ldMB\n",
537 physpages >> (20 - PAGE_SHIFT),
538 dropped_pages >> (20 - PAGE_SHIFT));
539 pr_warn("Consider using a larger page size\n");
540 }
541#endif
542
543 /* Heap starts just above the last loaded address. */
544 min_low_pfn = PFN_UP((unsigned long)_end - PAGE_OFFSET);
545
546#ifdef CONFIG_HIGHMEM
547 /* Find where we map lowmem from each controller. */
548 high_memory = setup_pa_va_mapping();
549
550 /* Set max_low_pfn based on what node 0 can directly address. */
551 max_low_pfn = node_lowmem_end_pfn[0];
552
553 lowmem_pages = (mappable_physpages > MAXMEM_PFN) ?
554 MAXMEM_PFN : mappable_physpages;
555 highmem_pages = (long) (physpages - lowmem_pages);
556
557 pr_notice("%ldMB HIGHMEM available\n",
558 pages_to_mb(highmem_pages > 0 ? highmem_pages : 0));
559 pr_notice("%ldMB LOWMEM available\n", pages_to_mb(lowmem_pages));
560#else
561 /* Set max_low_pfn based on what node 0 can directly address. */
562 max_low_pfn = node_end_pfn[0];
563
564#ifndef __tilegx__
565 if (node_end_pfn[0] > MAXMEM_PFN) {
566 pr_warn("Only using %ldMB LOWMEM\n", MAXMEM >> 20);
567 pr_warn("Use a HIGHMEM enabled kernel\n");
568 max_low_pfn = MAXMEM_PFN;
569 max_pfn = MAXMEM_PFN;
570 node_end_pfn[0] = MAXMEM_PFN;
571 } else {
572 pr_notice("%ldMB memory available\n",
573 pages_to_mb(node_end_pfn[0]));
574 }
575 for (i = 1; i < MAX_NUMNODES; ++i) {
576 node_start_pfn[i] = 0;
577 node_end_pfn[i] = 0;
578 }
579 high_memory = __va(node_end_pfn[0]);
580#else
581 lowmem_pages = 0;
582 for (i = 0; i < MAX_NUMNODES; ++i) {
583 int pages = node_end_pfn[i] - node_start_pfn[i];
584 lowmem_pages += pages;
585 if (pages)
586 high_memory = pfn_to_kaddr(node_end_pfn[i]);
587 }
588 pr_notice("%ldMB memory available\n", pages_to_mb(lowmem_pages));
589#endif
590#endif
591}
592
593/*
594 * On 32-bit machines, we only put bootmem on the low controller,
595 * since PAs > 4GB can't be used in bootmem. In principle one could
596 * imagine, e.g., multiple 1 GB controllers all of which could support
597 * bootmem, but in practice using controllers this small isn't a
598 * particularly interesting scenario, so we just keep it simple and
599 * use only the first controller for bootmem on 32-bit machines.
600 */
601static inline int node_has_bootmem(int nid)
602{
603#ifdef CONFIG_64BIT
604 return 1;
605#else
606 return nid == 0;
607#endif
608}
609
610static inline unsigned long alloc_bootmem_pfn(int nid,
611 unsigned long size,
612 unsigned long goal)
613{
614 void *kva = __alloc_bootmem_node(NODE_DATA(nid), size,
615 PAGE_SIZE, goal);
616 unsigned long pfn = kaddr_to_pfn(kva);
617 BUG_ON(goal && PFN_PHYS(pfn) != goal);
618 return pfn;
619}
620
621static void __init setup_bootmem_allocator_node(int i)
622{
623 unsigned long start, end, mapsize, mapstart;
624
625 if (node_has_bootmem(i)) {
626 NODE_DATA(i)->bdata = &bootmem_node_data[i];
627 } else {
628 /* Share controller zero's bdata for now. */
629 NODE_DATA(i)->bdata = &bootmem_node_data[0];
630 return;
631 }
632
633 /* Skip up to after the bss in node 0. */
634 start = (i == 0) ? min_low_pfn : node_start_pfn[i];
635
636 /* Only lowmem, if we're a HIGHMEM build. */
637#ifdef CONFIG_HIGHMEM
638 end = node_lowmem_end_pfn[i];
639#else
640 end = node_end_pfn[i];
641#endif
642
643 /* No memory here. */
644 if (end == start)
645 return;
646
647 /* Figure out where the bootmem bitmap is located. */
648 mapsize = bootmem_bootmap_pages(end - start);
649 if (i == 0) {
650 /* Use some space right before the heap on node 0. */
651 mapstart = start;
652 start += mapsize;
653 } else {
654 /* Allocate bitmap on node 0 to avoid page table issues. */
655 mapstart = alloc_bootmem_pfn(0, PFN_PHYS(mapsize), 0);
656 }
657
658 /* Initialize a node. */
659 init_bootmem_node(NODE_DATA(i), mapstart, start, end);
660
661 /* Free all the space back into the allocator. */
662 free_bootmem(PFN_PHYS(start), PFN_PHYS(end - start));
663
664#if defined(CONFIG_PCI) && !defined(__tilegx__)
665 /*
666 * Throw away any memory aliased by the PCI region.
667 */
668 if (pci_reserve_start_pfn < end && pci_reserve_end_pfn > start) {
669 start = max(pci_reserve_start_pfn, start);
670 end = min(pci_reserve_end_pfn, end);
671 reserve_bootmem(PFN_PHYS(start), PFN_PHYS(end - start),
672 BOOTMEM_EXCLUSIVE);
673 }
674#endif
675}
676
677static void __init setup_bootmem_allocator(void)
678{
679 int i;
680 for (i = 0; i < MAX_NUMNODES; ++i)
681 setup_bootmem_allocator_node(i);
682
683 /* Reserve any memory excluded by "memmap" arguments. */
684 for (i = 0; i < memmap_nr; ++i) {
685 struct memmap_entry *m = &memmap_map[i];
686 reserve_bootmem(m->addr, m->size, BOOTMEM_DEFAULT);
687 }
688
689#ifdef CONFIG_BLK_DEV_INITRD
690 if (initrd_start) {
691 /* Make sure the initrd memory region is not modified. */
692 if (reserve_bootmem(initrd_start, initrd_end - initrd_start,
693 BOOTMEM_EXCLUSIVE)) {
694 pr_crit("The initrd memory region has been polluted. Disabling it.\n");
695 initrd_start = 0;
696 initrd_end = 0;
697 } else {
698 /*
699 * Translate initrd_start & initrd_end from PA to VA for
700 * future access.
701 */
702 initrd_start += PAGE_OFFSET;
703 initrd_end += PAGE_OFFSET;
704 }
705 }
706#endif
707
708#ifdef CONFIG_KEXEC
709 if (crashk_res.start != crashk_res.end)
710 reserve_bootmem(crashk_res.start, resource_size(&crashk_res),
711 BOOTMEM_DEFAULT);
712#endif
713}
714
715void *__init alloc_remap(int nid, unsigned long size)
716{
717 int pages = node_end_pfn[nid] - node_start_pfn[nid];
718 void *map = pfn_to_kaddr(node_memmap_pfn[nid]);
719 BUG_ON(size != pages * sizeof(struct page));
720 memset(map, 0, size);
721 return map;
722}
723
724static int __init percpu_size(void)
725{
726 int size = __per_cpu_end - __per_cpu_start;
727 size += PERCPU_MODULE_RESERVE;
728 size += PERCPU_DYNAMIC_EARLY_SIZE;
729 if (size < PCPU_MIN_UNIT_SIZE)
730 size = PCPU_MIN_UNIT_SIZE;
731 size = roundup(size, PAGE_SIZE);
732
733 /* In several places we assume the per-cpu data fits on a huge page. */
734 BUG_ON(kdata_huge && size > HPAGE_SIZE);
735 return size;
736}
737
738static void __init zone_sizes_init(void)
739{
740 unsigned long zones_size[MAX_NR_ZONES] = { 0 };
741 int size = percpu_size();
742 int num_cpus = smp_height * smp_width;
743 const unsigned long dma_end = (1UL << (32 - PAGE_SHIFT));
744
745 int i;
746
747 for (i = 0; i < num_cpus; ++i)
748 node_percpu[cpu_to_node(i)] += size;
749
750 for_each_online_node(i) {
751 unsigned long start = node_start_pfn[i];
752 unsigned long end = node_end_pfn[i];
753#ifdef CONFIG_HIGHMEM
754 unsigned long lowmem_end = node_lowmem_end_pfn[i];
755#else
756 unsigned long lowmem_end = end;
757#endif
758 int memmap_size = (end - start) * sizeof(struct page);
759 node_free_pfn[i] = start;
760
761 /*
762 * Set aside pages for per-cpu data and the mem_map array.
763 *
764 * Since the per-cpu data requires special homecaching,
765 * if we are in kdata_huge mode, we put it at the end of
766 * the lowmem region. If we're not in kdata_huge mode,
767 * we take the per-cpu pages from the bottom of the
768 * controller, since that avoids fragmenting a huge page
769 * that users might want. We always take the memmap
770 * from the bottom of the controller, since with
771 * kdata_huge that lets it be under a huge TLB entry.
772 *
773 * If the user has requested isolnodes for a controller,
774 * though, there'll be no lowmem, so we just alloc_bootmem
775 * the memmap. There will be no percpu memory either.
776 */
777 if (i != 0 && node_isset(i, isolnodes)) {
778 node_memmap_pfn[i] =
779 alloc_bootmem_pfn(0, memmap_size, 0);
780 BUG_ON(node_percpu[i] != 0);
781 } else if (node_has_bootmem(start)) {
782 unsigned long goal = 0;
783 node_memmap_pfn[i] =
784 alloc_bootmem_pfn(i, memmap_size, 0);
785 if (kdata_huge)
786 goal = PFN_PHYS(lowmem_end) - node_percpu[i];
787 if (node_percpu[i])
788 node_percpu_pfn[i] =
789 alloc_bootmem_pfn(i, node_percpu[i],
790 goal);
791 } else {
792 /* In non-bootmem zones, just reserve some pages. */
793 node_memmap_pfn[i] = node_free_pfn[i];
794 node_free_pfn[i] += PFN_UP(memmap_size);
795 if (!kdata_huge) {
796 node_percpu_pfn[i] = node_free_pfn[i];
797 node_free_pfn[i] += PFN_UP(node_percpu[i]);
798 } else {
799 node_percpu_pfn[i] =
800 lowmem_end - PFN_UP(node_percpu[i]);
801 }
802 }
803
804#ifdef CONFIG_HIGHMEM
805 if (start > lowmem_end) {
806 zones_size[ZONE_NORMAL] = 0;
807 zones_size[ZONE_HIGHMEM] = end - start;
808 } else {
809 zones_size[ZONE_NORMAL] = lowmem_end - start;
810 zones_size[ZONE_HIGHMEM] = end - lowmem_end;
811 }
812#else
813 zones_size[ZONE_NORMAL] = end - start;
814#endif
815
816 if (start < dma_end) {
817 zones_size[ZONE_DMA32] = min(zones_size[ZONE_NORMAL],
818 dma_end - start);
819 zones_size[ZONE_NORMAL] -= zones_size[ZONE_DMA32];
820 } else {
821 zones_size[ZONE_DMA32] = 0;
822 }
823
824 /* Take zone metadata from controller 0 if we're isolnode. */
825 if (node_isset(i, isolnodes))
826 NODE_DATA(i)->bdata = &bootmem_node_data[0];
827
828 free_area_init_node(i, zones_size, start, NULL);
829 printk(KERN_DEBUG " Normal zone: %ld per-cpu pages\n",
830 PFN_UP(node_percpu[i]));
831
832 /* Track the type of memory on each node */
833 if (zones_size[ZONE_NORMAL] || zones_size[ZONE_DMA32])
834 node_set_state(i, N_NORMAL_MEMORY);
835#ifdef CONFIG_HIGHMEM
836 if (end != start)
837 node_set_state(i, N_HIGH_MEMORY);
838#endif
839
840 node_set_online(i);
841 }
842}
843
844#ifdef CONFIG_NUMA
845
846/* which logical CPUs are on which nodes */
847struct cpumask node_2_cpu_mask[MAX_NUMNODES] __ro_after_init;
848EXPORT_SYMBOL(node_2_cpu_mask);
849
850/* which node each logical CPU is on */
851char cpu_2_node[NR_CPUS] __ro_after_init __attribute__((aligned(L2_CACHE_BYTES)));
852EXPORT_SYMBOL(cpu_2_node);
853
854/* Return cpu_to_node() except for cpus not yet assigned, which return -1 */
855static int __init cpu_to_bound_node(int cpu, struct cpumask* unbound_cpus)
856{
857 if (!cpu_possible(cpu) || cpumask_test_cpu(cpu, unbound_cpus))
858 return -1;
859 else
860 return cpu_to_node(cpu);
861}
862
863/* Return number of immediately-adjacent tiles sharing the same NUMA node. */
864static int __init node_neighbors(int node, int cpu,
865 struct cpumask *unbound_cpus)
866{
867 int neighbors = 0;
868 int w = smp_width;
869 int h = smp_height;
870 int x = cpu % w;
871 int y = cpu / w;
872 if (x > 0 && cpu_to_bound_node(cpu-1, unbound_cpus) == node)
873 ++neighbors;
874 if (x < w-1 && cpu_to_bound_node(cpu+1, unbound_cpus) == node)
875 ++neighbors;
876 if (y > 0 && cpu_to_bound_node(cpu-w, unbound_cpus) == node)
877 ++neighbors;
878 if (y < h-1 && cpu_to_bound_node(cpu+w, unbound_cpus) == node)
879 ++neighbors;
880 return neighbors;
881}
882
883static void __init setup_numa_mapping(void)
884{
885 u8 distance[MAX_NUMNODES][NR_CPUS];
886 HV_Coord coord;
887 int cpu, node, cpus, i, x, y;
888 int num_nodes = num_online_nodes();
889 struct cpumask unbound_cpus;
890 nodemask_t default_nodes;
891
892 cpumask_clear(&unbound_cpus);
893
894 /* Get set of nodes we will use for defaults */
895 nodes_andnot(default_nodes, node_online_map, isolnodes);
896 if (nodes_empty(default_nodes)) {
897 BUG_ON(!node_isset(0, node_online_map));
898 pr_err("Forcing NUMA node zero available as a default node\n");
899 node_set(0, default_nodes);
900 }
901
902 /* Populate the distance[] array */
903 memset(distance, -1, sizeof(distance));
904 cpu = 0;
905 for (coord.y = 0; coord.y < smp_height; ++coord.y) {
906 for (coord.x = 0; coord.x < smp_width;
907 ++coord.x, ++cpu) {
908 BUG_ON(cpu >= nr_cpu_ids);
909 if (!cpu_possible(cpu)) {
910 cpu_2_node[cpu] = -1;
911 continue;
912 }
913 for_each_node_mask(node, default_nodes) {
914 HV_MemoryControllerInfo info =
915 hv_inquire_memory_controller(
916 coord, node_controller[node]);
917 distance[node][cpu] =
918 ABS(info.coord.x) + ABS(info.coord.y);
919 }
920 cpumask_set_cpu(cpu, &unbound_cpus);
921 }
922 }
923 cpus = cpu;
924
925 /*
926 * Round-robin through the NUMA nodes until all the cpus are
927 * assigned. We could be more clever here (e.g. create four
928 * sorted linked lists on the same set of cpu nodes, and pull
929 * off them in round-robin sequence, removing from all four
930 * lists each time) but given the relatively small numbers
931 * involved, O(n^2) seem OK for a one-time cost.
932 */
933 node = first_node(default_nodes);
934 while (!cpumask_empty(&unbound_cpus)) {
935 int best_cpu = -1;
936 int best_distance = INT_MAX;
937 for (cpu = 0; cpu < cpus; ++cpu) {
938 if (cpumask_test_cpu(cpu, &unbound_cpus)) {
939 /*
940 * Compute metric, which is how much
941 * closer the cpu is to this memory
942 * controller than the others, shifted
943 * up, and then the number of
944 * neighbors already in the node as an
945 * epsilon adjustment to try to keep
946 * the nodes compact.
947 */
948 int d = distance[node][cpu] * num_nodes;
949 for_each_node_mask(i, default_nodes) {
950 if (i != node)
951 d -= distance[i][cpu];
952 }
953 d *= 8; /* allow space for epsilon */
954 d -= node_neighbors(node, cpu, &unbound_cpus);
955 if (d < best_distance) {
956 best_cpu = cpu;
957 best_distance = d;
958 }
959 }
960 }
961 BUG_ON(best_cpu < 0);
962 cpumask_set_cpu(best_cpu, &node_2_cpu_mask[node]);
963 cpu_2_node[best_cpu] = node;
964 cpumask_clear_cpu(best_cpu, &unbound_cpus);
965 node = next_node_in(node, default_nodes);
966 }
967
968 /* Print out node assignments and set defaults for disabled cpus */
969 cpu = 0;
970 for (y = 0; y < smp_height; ++y) {
971 printk(KERN_DEBUG "NUMA cpu-to-node row %d:", y);
972 for (x = 0; x < smp_width; ++x, ++cpu) {
973 if (cpu_to_node(cpu) < 0) {
974 pr_cont(" -");
975 cpu_2_node[cpu] = first_node(default_nodes);
976 } else {
977 pr_cont(" %d", cpu_to_node(cpu));
978 }
979 }
980 pr_cont("\n");
981 }
982}
983
984static struct cpu cpu_devices[NR_CPUS];
985
986static int __init topology_init(void)
987{
988 int i;
989
990 for_each_online_node(i)
991 register_one_node(i);
992
993 for (i = 0; i < smp_height * smp_width; ++i)
994 register_cpu(&cpu_devices[i], i);
995
996 return 0;
997}
998
999subsys_initcall(topology_init);
1000
1001#else /* !CONFIG_NUMA */
1002
1003#define setup_numa_mapping() do { } while (0)
1004
1005#endif /* CONFIG_NUMA */
1006
1007/*
1008 * Initialize hugepage support on this cpu. We do this on all cores
1009 * early in boot: before argument parsing for the boot cpu, and after
1010 * argument parsing but before the init functions run on the secondaries.
1011 * So the values we set up here in the hypervisor may be overridden on
1012 * the boot cpu as arguments are parsed.
1013 */
1014static void init_super_pages(void)
1015{
1016#ifdef CONFIG_HUGETLB_SUPER_PAGES
1017 int i;
1018 for (i = 0; i < HUGE_SHIFT_ENTRIES; ++i)
1019 hv_set_pte_super_shift(i, huge_shift[i]);
1020#endif
1021}
1022
1023/**
1024 * setup_cpu() - Do all necessary per-cpu, tile-specific initialization.
1025 * @boot: Is this the boot cpu?
1026 *
1027 * Called from setup_arch() on the boot cpu, or online_secondary().
1028 */
1029void setup_cpu(int boot)
1030{
1031 /* The boot cpu sets up its permanent mappings much earlier. */
1032 if (!boot)
1033 store_permanent_mappings();
1034
1035 /* Allow asynchronous TLB interrupts. */
1036#if CHIP_HAS_TILE_DMA()
1037 arch_local_irq_unmask(INT_DMATLB_MISS);
1038 arch_local_irq_unmask(INT_DMATLB_ACCESS);
1039#endif
1040#ifdef __tilegx__
1041 arch_local_irq_unmask(INT_SINGLE_STEP_K);
1042#endif
1043
1044 /*
1045 * Allow user access to many generic SPRs, like the cycle
1046 * counter, PASS/FAIL/DONE, INTERRUPT_CRITICAL_SECTION, etc.
1047 */
1048 __insn_mtspr(SPR_MPL_WORLD_ACCESS_SET_0, 1);
1049
1050#if CHIP_HAS_SN()
1051 /* Static network is not restricted. */
1052 __insn_mtspr(SPR_MPL_SN_ACCESS_SET_0, 1);
1053#endif
1054
1055 /*
1056 * Set the MPL for interrupt control 0 & 1 to the corresponding
1057 * values. This includes access to the SYSTEM_SAVE and EX_CONTEXT
1058 * SPRs, as well as the interrupt mask.
1059 */
1060 __insn_mtspr(SPR_MPL_INTCTRL_0_SET_0, 1);
1061 __insn_mtspr(SPR_MPL_INTCTRL_1_SET_1, 1);
1062
1063 /* Initialize IRQ support for this cpu. */
1064 setup_irq_regs();
1065
1066#ifdef CONFIG_HARDWALL
1067 /* Reset the network state on this cpu. */
1068 reset_network_state();
1069#endif
1070
1071 init_super_pages();
1072}
1073
1074#ifdef CONFIG_BLK_DEV_INITRD
1075
1076static int __initdata set_initramfs_file;
1077static char __initdata initramfs_file[128] = "initramfs";
1078
1079static int __init setup_initramfs_file(char *str)
1080{
1081 if (str == NULL)
1082 return -EINVAL;
1083 strncpy(initramfs_file, str, sizeof(initramfs_file) - 1);
1084 set_initramfs_file = 1;
1085
1086 return 0;
1087}
1088early_param("initramfs_file", setup_initramfs_file);
1089
1090/*
1091 * We look for a file called "initramfs" in the hvfs. If there is one, we
1092 * allocate some memory for it and it will be unpacked to the initramfs.
1093 * If it's compressed, the initd code will uncompress it first.
1094 */
1095static void __init load_hv_initrd(void)
1096{
1097 HV_FS_StatInfo stat;
1098 int fd, rc;
1099 void *initrd;
1100
1101 /* If initrd has already been set, skip initramfs file in hvfs. */
1102 if (initrd_start)
1103 return;
1104
1105 fd = hv_fs_findfile((HV_VirtAddr) initramfs_file);
1106 if (fd == HV_ENOENT) {
1107 if (set_initramfs_file) {
1108 pr_warn("No such hvfs initramfs file '%s'\n",
1109 initramfs_file);
1110 return;
1111 } else {
1112 /* Try old backwards-compatible name. */
1113 fd = hv_fs_findfile((HV_VirtAddr)"initramfs.cpio.gz");
1114 if (fd == HV_ENOENT)
1115 return;
1116 }
1117 }
1118 BUG_ON(fd < 0);
1119 stat = hv_fs_fstat(fd);
1120 BUG_ON(stat.size < 0);
1121 if (stat.flags & HV_FS_ISDIR) {
1122 pr_warn("Ignoring hvfs file '%s': it's a directory\n",
1123 initramfs_file);
1124 return;
1125 }
1126 initrd = alloc_bootmem_pages(stat.size);
1127 rc = hv_fs_pread(fd, (HV_VirtAddr) initrd, stat.size, 0);
1128 if (rc != stat.size) {
1129 pr_err("Error reading %d bytes from hvfs file '%s': %d\n",
1130 stat.size, initramfs_file, rc);
1131 free_initrd_mem((unsigned long) initrd, stat.size);
1132 return;
1133 }
1134 initrd_start = (unsigned long) initrd;
1135 initrd_end = initrd_start + stat.size;
1136}
1137
1138void __init free_initrd_mem(unsigned long begin, unsigned long end)
1139{
1140 free_bootmem_late(__pa(begin), end - begin);
1141}
1142
1143static int __init setup_initrd(char *str)
1144{
1145 char *endp;
1146 unsigned long initrd_size;
1147
1148 initrd_size = str ? simple_strtoul(str, &endp, 0) : 0;
1149 if (initrd_size == 0 || *endp != '@')
1150 return -EINVAL;
1151
1152 initrd_start = simple_strtoul(endp+1, &endp, 0);
1153 if (initrd_start == 0)
1154 return -EINVAL;
1155
1156 initrd_end = initrd_start + initrd_size;
1157
1158 return 0;
1159}
1160early_param("initrd", setup_initrd);
1161
1162#else
1163static inline void load_hv_initrd(void) {}
1164#endif /* CONFIG_BLK_DEV_INITRD */
1165
1166static void __init validate_hv(void)
1167{
1168 /*
1169 * It may already be too late, but let's check our built-in
1170 * configuration against what the hypervisor is providing.
1171 */
1172 unsigned long glue_size = hv_sysconf(HV_SYSCONF_GLUE_SIZE);
1173 int hv_page_size = hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL);
1174 int hv_hpage_size = hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE);
1175 HV_ASIDRange asid_range;
1176
1177#ifndef CONFIG_SMP
1178 HV_Topology topology = hv_inquire_topology();
1179 BUG_ON(topology.coord.x != 0 || topology.coord.y != 0);
1180 if (topology.width != 1 || topology.height != 1) {
1181 pr_warn("Warning: booting UP kernel on %dx%d grid; will ignore all but first tile\n",
1182 topology.width, topology.height);
1183 }
1184#endif
1185
1186 if (PAGE_OFFSET + HV_GLUE_START_CPA + glue_size > (unsigned long)_text)
1187 early_panic("Hypervisor glue size %ld is too big!\n",
1188 glue_size);
1189 if (hv_page_size != PAGE_SIZE)
1190 early_panic("Hypervisor page size %#x != our %#lx\n",
1191 hv_page_size, PAGE_SIZE);
1192 if (hv_hpage_size != HPAGE_SIZE)
1193 early_panic("Hypervisor huge page size %#x != our %#lx\n",
1194 hv_hpage_size, HPAGE_SIZE);
1195
1196#ifdef CONFIG_SMP
1197 /*
1198 * Some hypervisor APIs take a pointer to a bitmap array
1199 * whose size is at least the number of cpus on the chip.
1200 * We use a struct cpumask for this, so it must be big enough.
1201 */
1202 if ((smp_height * smp_width) > nr_cpu_ids)
1203 early_panic("Hypervisor %d x %d grid too big for Linux NR_CPUS %u\n",
1204 smp_height, smp_width, nr_cpu_ids);
1205#endif
1206
1207 /*
1208 * Check that we're using allowed ASIDs, and initialize the
1209 * various asid variables to their appropriate initial states.
1210 */
1211 asid_range = hv_inquire_asid(0);
1212 min_asid = asid_range.start;
1213 __this_cpu_write(current_asid, min_asid);
1214 max_asid = asid_range.start + asid_range.size - 1;
1215
1216 if (hv_confstr(HV_CONFSTR_CHIP_MODEL, (HV_VirtAddr)chip_model,
1217 sizeof(chip_model)) < 0) {
1218 pr_err("Warning: HV_CONFSTR_CHIP_MODEL not available\n");
1219 strlcpy(chip_model, "unknown", sizeof(chip_model));
1220 }
1221}
1222
1223static void __init validate_va(void)
1224{
1225#ifndef __tilegx__ /* FIXME: GX: probably some validation relevant here */
1226 /*
1227 * Similarly, make sure we're only using allowed VAs.
1228 * We assume we can contiguously use MEM_USER_INTRPT .. MEM_HV_START,
1229 * and 0 .. KERNEL_HIGH_VADDR.
1230 * In addition, make sure we CAN'T use the end of memory, since
1231 * we use the last chunk of each pgd for the pgd_list.
1232 */
1233 int i, user_kernel_ok = 0;
1234 unsigned long max_va = 0;
1235 unsigned long list_va =
1236 ((PGD_LIST_OFFSET / sizeof(pgd_t)) << PGDIR_SHIFT);
1237
1238 for (i = 0; ; ++i) {
1239 HV_VirtAddrRange range = hv_inquire_virtual(i);
1240 if (range.size == 0)
1241 break;
1242 if (range.start <= MEM_USER_INTRPT &&
1243 range.start + range.size >= MEM_HV_START)
1244 user_kernel_ok = 1;
1245 if (range.start == 0)
1246 max_va = range.size;
1247 BUG_ON(range.start + range.size > list_va);
1248 }
1249 if (!user_kernel_ok)
1250 early_panic("Hypervisor not configured for user/kernel VAs\n");
1251 if (max_va == 0)
1252 early_panic("Hypervisor not configured for low VAs\n");
1253 if (max_va < KERNEL_HIGH_VADDR)
1254 early_panic("Hypervisor max VA %#lx smaller than %#lx\n",
1255 max_va, KERNEL_HIGH_VADDR);
1256
1257 /* Kernel PCs must have their high bit set; see intvec.S. */
1258 if ((long)VMALLOC_START >= 0)
1259 early_panic("Linux VMALLOC region below the 2GB line (%#lx)!\n"
1260 "Reconfigure the kernel with smaller VMALLOC_RESERVE\n",
1261 VMALLOC_START);
1262#endif
1263}
1264
1265/*
1266 * cpu_lotar_map lists all the cpus that are valid for the supervisor
1267 * to cache data on at a page level, i.e. what cpus can be placed in
1268 * the LOTAR field of a PTE. It is equivalent to the set of possible
1269 * cpus plus any other cpus that are willing to share their cache.
1270 * It is set by hv_inquire_tiles(HV_INQ_TILES_LOTAR).
1271 */
1272struct cpumask __ro_after_init cpu_lotar_map;
1273EXPORT_SYMBOL(cpu_lotar_map);
1274
1275/*
1276 * hash_for_home_map lists all the tiles that hash-for-home data
1277 * will be cached on. Note that this may includes tiles that are not
1278 * valid for this supervisor to use otherwise (e.g. if a hypervisor
1279 * device is being shared between multiple supervisors).
1280 * It is set by hv_inquire_tiles(HV_INQ_TILES_HFH_CACHE).
1281 */
1282struct cpumask hash_for_home_map;
1283EXPORT_SYMBOL(hash_for_home_map);
1284
1285/*
1286 * cpu_cacheable_map lists all the cpus whose caches the hypervisor can
1287 * flush on our behalf. It is set to cpu_possible_mask OR'ed with
1288 * hash_for_home_map, and it is what should be passed to
1289 * hv_flush_remote() to flush all caches. Note that if there are
1290 * dedicated hypervisor driver tiles that have authorized use of their
1291 * cache, those tiles will only appear in cpu_lotar_map, NOT in
1292 * cpu_cacheable_map, as they are a special case.
1293 */
1294struct cpumask __ro_after_init cpu_cacheable_map;
1295EXPORT_SYMBOL(cpu_cacheable_map);
1296
1297static __initdata struct cpumask disabled_map;
1298
1299static int __init disabled_cpus(char *str)
1300{
1301 int boot_cpu = smp_processor_id();
1302
1303 if (str == NULL || cpulist_parse_crop(str, &disabled_map) != 0)
1304 return -EINVAL;
1305 if (cpumask_test_cpu(boot_cpu, &disabled_map)) {
1306 pr_err("disabled_cpus: can't disable boot cpu %d\n", boot_cpu);
1307 cpumask_clear_cpu(boot_cpu, &disabled_map);
1308 }
1309 return 0;
1310}
1311
1312early_param("disabled_cpus", disabled_cpus);
1313
1314void __init print_disabled_cpus(void)
1315{
1316 if (!cpumask_empty(&disabled_map))
1317 pr_info("CPUs not available for Linux: %*pbl\n",
1318 cpumask_pr_args(&disabled_map));
1319}
1320
1321static void __init setup_cpu_maps(void)
1322{
1323 struct cpumask hv_disabled_map, cpu_possible_init;
1324 int boot_cpu = smp_processor_id();
1325 int cpus, i, rc;
1326
1327 /* Learn which cpus are allowed by the hypervisor. */
1328 rc = hv_inquire_tiles(HV_INQ_TILES_AVAIL,
1329 (HV_VirtAddr) cpumask_bits(&cpu_possible_init),
1330 sizeof(cpu_cacheable_map));
1331 if (rc < 0)
1332 early_panic("hv_inquire_tiles(AVAIL) failed: rc %d\n", rc);
1333 if (!cpumask_test_cpu(boot_cpu, &cpu_possible_init))
1334 early_panic("Boot CPU %d disabled by hypervisor!\n", boot_cpu);
1335
1336 /* Compute the cpus disabled by the hvconfig file. */
1337 cpumask_complement(&hv_disabled_map, &cpu_possible_init);
1338
1339 /* Include them with the cpus disabled by "disabled_cpus". */
1340 cpumask_or(&disabled_map, &disabled_map, &hv_disabled_map);
1341
1342 /*
1343 * Disable every cpu after "setup_max_cpus". But don't mark
1344 * as disabled the cpus that are outside of our initial rectangle,
1345 * since that turns out to be confusing.
1346 */
1347 cpus = 1; /* this cpu */
1348 cpumask_set_cpu(boot_cpu, &disabled_map); /* ignore this cpu */
1349 for (i = 0; cpus < setup_max_cpus; ++i)
1350 if (!cpumask_test_cpu(i, &disabled_map))
1351 ++cpus;
1352 for (; i < smp_height * smp_width; ++i)
1353 cpumask_set_cpu(i, &disabled_map);
1354 cpumask_clear_cpu(boot_cpu, &disabled_map); /* reset this cpu */
1355 for (i = smp_height * smp_width; i < NR_CPUS; ++i)
1356 cpumask_clear_cpu(i, &disabled_map);
1357
1358 /*
1359 * Setup cpu_possible map as every cpu allocated to us, minus
1360 * the results of any "disabled_cpus" settings.
1361 */
1362 cpumask_andnot(&cpu_possible_init, &cpu_possible_init, &disabled_map);
1363 init_cpu_possible(&cpu_possible_init);
1364
1365 /* Learn which cpus are valid for LOTAR caching. */
1366 rc = hv_inquire_tiles(HV_INQ_TILES_LOTAR,
1367 (HV_VirtAddr) cpumask_bits(&cpu_lotar_map),
1368 sizeof(cpu_lotar_map));
1369 if (rc < 0) {
1370 pr_err("warning: no HV_INQ_TILES_LOTAR; using AVAIL\n");
1371 cpu_lotar_map = *cpu_possible_mask;
1372 }
1373
1374 /* Retrieve set of CPUs used for hash-for-home caching */
1375 rc = hv_inquire_tiles(HV_INQ_TILES_HFH_CACHE,
1376 (HV_VirtAddr) hash_for_home_map.bits,
1377 sizeof(hash_for_home_map));
1378 if (rc < 0)
1379 early_panic("hv_inquire_tiles(HFH_CACHE) failed: rc %d\n", rc);
1380 cpumask_or(&cpu_cacheable_map, cpu_possible_mask, &hash_for_home_map);
1381}
1382
1383
1384static int __init dataplane(char *str)
1385{
1386 pr_warn("WARNING: dataplane support disabled in this kernel\n");
1387 return 0;
1388}
1389
1390early_param("dataplane", dataplane);
1391
1392#ifdef CONFIG_NO_HZ_FULL
1393/* Warn if hypervisor shared cpus are marked as nohz_full. */
1394static int __init check_nohz_full_cpus(void)
1395{
1396 struct cpumask shared;
1397 int cpu;
1398
1399 if (hv_inquire_tiles(HV_INQ_TILES_SHARED,
1400 (HV_VirtAddr) shared.bits, sizeof(shared)) < 0) {
1401 pr_warn("WARNING: No support for inquiring hv shared tiles\n");
1402 return 0;
1403 }
1404 for_each_cpu(cpu, &shared) {
1405 if (tick_nohz_full_cpu(cpu))
1406 pr_warn("WARNING: nohz_full cpu %d receives hypervisor interrupts!\n",
1407 cpu);
1408 }
1409 return 0;
1410}
1411arch_initcall(check_nohz_full_cpus);
1412#endif
1413
1414#ifdef CONFIG_CMDLINE_BOOL
1415static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
1416#endif
1417
1418void __init setup_arch(char **cmdline_p)
1419{
1420 int len;
1421
1422#if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
1423 len = hv_get_command_line((HV_VirtAddr) boot_command_line,
1424 COMMAND_LINE_SIZE);
1425 if (boot_command_line[0])
1426 pr_warn("WARNING: ignoring dynamic command line \"%s\"\n",
1427 boot_command_line);
1428 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
1429#else
1430 char *hv_cmdline;
1431#if defined(CONFIG_CMDLINE_BOOL)
1432 if (builtin_cmdline[0]) {
1433 int builtin_len = strlcpy(boot_command_line, builtin_cmdline,
1434 COMMAND_LINE_SIZE);
1435 if (builtin_len < COMMAND_LINE_SIZE-1)
1436 boot_command_line[builtin_len++] = ' ';
1437 hv_cmdline = &boot_command_line[builtin_len];
1438 len = COMMAND_LINE_SIZE - builtin_len;
1439 } else
1440#endif
1441 {
1442 hv_cmdline = boot_command_line;
1443 len = COMMAND_LINE_SIZE;
1444 }
1445 len = hv_get_command_line((HV_VirtAddr) hv_cmdline, len);
1446 if (len < 0 || len > COMMAND_LINE_SIZE)
1447 early_panic("hv_get_command_line failed: %d\n", len);
1448#endif
1449
1450 *cmdline_p = boot_command_line;
1451
1452 /* Set disabled_map and setup_max_cpus very early */
1453 parse_early_param();
1454
1455 /* Make sure the kernel is compatible with the hypervisor. */
1456 validate_hv();
1457 validate_va();
1458
1459 setup_cpu_maps();
1460
1461
1462#if defined(CONFIG_PCI) && !defined(__tilegx__)
1463 /*
1464 * Initialize the PCI structures. This is done before memory
1465 * setup so that we know whether or not a pci_reserve region
1466 * is necessary.
1467 */
1468 if (tile_pci_init() == 0)
1469 pci_reserve_mb = 0;
1470
1471 /* PCI systems reserve a region just below 4GB for mapping iomem. */
1472 pci_reserve_end_pfn = (1 << (32 - PAGE_SHIFT));
1473 pci_reserve_start_pfn = pci_reserve_end_pfn -
1474 (pci_reserve_mb << (20 - PAGE_SHIFT));
1475#endif
1476
1477 init_mm.start_code = (unsigned long) _text;
1478 init_mm.end_code = (unsigned long) _etext;
1479 init_mm.end_data = (unsigned long) _edata;
1480 init_mm.brk = (unsigned long) _end;
1481
1482 setup_memory();
1483 store_permanent_mappings();
1484 setup_bootmem_allocator();
1485
1486 /*
1487 * NOTE: before this point _nobody_ is allowed to allocate
1488 * any memory using the bootmem allocator.
1489 */
1490
1491#ifdef CONFIG_SWIOTLB
1492 swiotlb_init(0);
1493#endif
1494
1495 paging_init();
1496 setup_numa_mapping();
1497 zone_sizes_init();
1498 set_page_homes();
1499 setup_cpu(1);
1500 setup_clock();
1501 load_hv_initrd();
1502}
1503
1504
1505/*
1506 * Set up per-cpu memory.
1507 */
1508
1509unsigned long __per_cpu_offset[NR_CPUS] __ro_after_init;
1510EXPORT_SYMBOL(__per_cpu_offset);
1511
1512static size_t __initdata pfn_offset[MAX_NUMNODES] = { 0 };
1513static unsigned long __initdata percpu_pfn[NR_CPUS] = { 0 };
1514
1515/*
1516 * As the percpu code allocates pages, we return the pages from the
1517 * end of the node for the specified cpu.
1518 */
1519static void *__init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
1520{
1521 int nid = cpu_to_node(cpu);
1522 unsigned long pfn = node_percpu_pfn[nid] + pfn_offset[nid];
1523
1524 BUG_ON(size % PAGE_SIZE != 0);
1525 pfn_offset[nid] += size / PAGE_SIZE;
1526 BUG_ON(node_percpu[nid] < size);
1527 node_percpu[nid] -= size;
1528 if (percpu_pfn[cpu] == 0)
1529 percpu_pfn[cpu] = pfn;
1530 return pfn_to_kaddr(pfn);
1531}
1532
1533/*
1534 * Pages reserved for percpu memory are not freeable, and in any case we are
1535 * on a short path to panic() in setup_per_cpu_area() at this point anyway.
1536 */
1537static void __init pcpu_fc_free(void *ptr, size_t size)
1538{
1539}
1540
1541/*
1542 * Set up vmalloc page tables using bootmem for the percpu code.
1543 */
1544static void __init pcpu_fc_populate_pte(unsigned long addr)
1545{
1546 pgd_t *pgd;
1547 pud_t *pud;
1548 pmd_t *pmd;
1549 pte_t *pte;
1550
1551 BUG_ON(pgd_addr_invalid(addr));
1552 if (addr < VMALLOC_START || addr >= VMALLOC_END)
1553 panic("PCPU addr %#lx outside vmalloc range %#lx..%#lx; try increasing CONFIG_VMALLOC_RESERVE\n",
1554 addr, VMALLOC_START, VMALLOC_END);
1555
1556 pgd = swapper_pg_dir + pgd_index(addr);
1557 pud = pud_offset(pgd, addr);
1558 BUG_ON(!pud_present(*pud));
1559 pmd = pmd_offset(pud, addr);
1560 if (pmd_present(*pmd)) {
1561 BUG_ON(pmd_huge_page(*pmd));
1562 } else {
1563 pte = __alloc_bootmem(L2_KERNEL_PGTABLE_SIZE,
1564 HV_PAGE_TABLE_ALIGN, 0);
1565 pmd_populate_kernel(&init_mm, pmd, pte);
1566 }
1567}
1568
1569void __init setup_per_cpu_areas(void)
1570{
1571 struct page *pg;
1572 unsigned long delta, pfn, lowmem_va;
1573 unsigned long size = percpu_size();
1574 char *ptr;
1575 int rc, cpu, i;
1576
1577 rc = pcpu_page_first_chunk(PERCPU_MODULE_RESERVE, pcpu_fc_alloc,
1578 pcpu_fc_free, pcpu_fc_populate_pte);
1579 if (rc < 0)
1580 panic("Cannot initialize percpu area (err=%d)", rc);
1581
1582 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
1583 for_each_possible_cpu(cpu) {
1584 __per_cpu_offset[cpu] = delta + pcpu_unit_offsets[cpu];
1585
1586 /* finv the copy out of cache so we can change homecache */
1587 ptr = pcpu_base_addr + pcpu_unit_offsets[cpu];
1588 __finv_buffer(ptr, size);
1589 pfn = percpu_pfn[cpu];
1590
1591 /* Rewrite the page tables to cache on that cpu */
1592 pg = pfn_to_page(pfn);
1593 for (i = 0; i < size; i += PAGE_SIZE, ++pfn, ++pg) {
1594
1595 /* Update the vmalloc mapping and page home. */
1596 unsigned long addr = (unsigned long)ptr + i;
1597 pte_t *ptep = virt_to_kpte(addr);
1598 pte_t pte = *ptep;
1599 BUG_ON(pfn != pte_pfn(pte));
1600 pte = hv_pte_set_mode(pte, HV_PTE_MODE_CACHE_TILE_L3);
1601 pte = set_remote_cache_cpu(pte, cpu);
1602 set_pte_at(&init_mm, addr, ptep, pte);
1603
1604 /* Update the lowmem mapping for consistency. */
1605 lowmem_va = (unsigned long)pfn_to_kaddr(pfn);
1606 ptep = virt_to_kpte(lowmem_va);
1607 if (pte_huge(*ptep)) {
1608 printk(KERN_DEBUG "early shatter of huge page at %#lx\n",
1609 lowmem_va);
1610 shatter_pmd((pmd_t *)ptep);
1611 ptep = virt_to_kpte(lowmem_va);
1612 BUG_ON(pte_huge(*ptep));
1613 }
1614 BUG_ON(pfn != pte_pfn(*ptep));
1615 set_pte_at(&init_mm, lowmem_va, ptep, pte);
1616 }
1617 }
1618
1619 /* Set our thread pointer appropriately. */
1620 set_my_cpu_offset(__per_cpu_offset[smp_processor_id()]);
1621
1622 /* Make sure the finv's have completed. */
1623 mb_incoherent();
1624
1625 /* Flush the TLB so we reference it properly from here on out. */
1626 local_flush_tlb_all();
1627}
1628
1629static struct resource data_resource = {
1630 .name = "Kernel data",
1631 .start = 0,
1632 .end = 0,
1633 .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
1634};
1635
1636static struct resource code_resource = {
1637 .name = "Kernel code",
1638 .start = 0,
1639 .end = 0,
1640 .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM
1641};
1642
1643/*
1644 * On Pro, we reserve all resources above 4GB so that PCI won't try to put
1645 * mappings above 4GB.
1646 */
1647#if defined(CONFIG_PCI) && !defined(__tilegx__)
1648static struct resource* __init
1649insert_non_bus_resource(void)
1650{
1651 struct resource *res =
1652 kzalloc(sizeof(struct resource), GFP_ATOMIC);
1653 if (!res)
1654 return NULL;
1655 res->name = "Non-Bus Physical Address Space";
1656 res->start = (1ULL << 32);
1657 res->end = -1LL;
1658 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
1659 if (insert_resource(&iomem_resource, res)) {
1660 kfree(res);
1661 return NULL;
1662 }
1663 return res;
1664}
1665#endif
1666
1667static struct resource* __init
1668insert_ram_resource(u64 start_pfn, u64 end_pfn, bool reserved)
1669{
1670 struct resource *res =
1671 kzalloc(sizeof(struct resource), GFP_ATOMIC);
1672 if (!res)
1673 return NULL;
1674 res->start = start_pfn << PAGE_SHIFT;
1675 res->end = (end_pfn << PAGE_SHIFT) - 1;
1676 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
1677 if (reserved) {
1678 res->name = "Reserved";
1679 } else {
1680 res->name = "System RAM";
1681 res->flags |= IORESOURCE_SYSRAM;
1682 }
1683 if (insert_resource(&iomem_resource, res)) {
1684 kfree(res);
1685 return NULL;
1686 }
1687 return res;
1688}
1689
1690/*
1691 * Request address space for all standard resources
1692 *
1693 * If the system includes PCI root complex drivers, we need to create
1694 * a window just below 4GB where PCI BARs can be mapped.
1695 */
1696static int __init request_standard_resources(void)
1697{
1698 int i;
1699 enum { CODE_DELTA = MEM_SV_START - PAGE_OFFSET };
1700
1701#if defined(CONFIG_PCI) && !defined(__tilegx__)
1702 insert_non_bus_resource();
1703#endif
1704
1705 for_each_online_node(i) {
1706 u64 start_pfn = node_start_pfn[i];
1707 u64 end_pfn = node_end_pfn[i];
1708
1709#if defined(CONFIG_PCI) && !defined(__tilegx__)
1710 if (start_pfn <= pci_reserve_start_pfn &&
1711 end_pfn > pci_reserve_start_pfn) {
1712 if (end_pfn > pci_reserve_end_pfn)
1713 insert_ram_resource(pci_reserve_end_pfn,
1714 end_pfn, 0);
1715 end_pfn = pci_reserve_start_pfn;
1716 }
1717#endif
1718 insert_ram_resource(start_pfn, end_pfn, 0);
1719 }
1720
1721 code_resource.start = __pa(_text - CODE_DELTA);
1722 code_resource.end = __pa(_etext - CODE_DELTA)-1;
1723 data_resource.start = __pa(_sdata);
1724 data_resource.end = __pa(_end)-1;
1725
1726 insert_resource(&iomem_resource, &code_resource);
1727 insert_resource(&iomem_resource, &data_resource);
1728
1729 /* Mark any "memmap" regions busy for the resource manager. */
1730 for (i = 0; i < memmap_nr; ++i) {
1731 struct memmap_entry *m = &memmap_map[i];
1732 insert_ram_resource(PFN_DOWN(m->addr),
1733 PFN_UP(m->addr + m->size - 1), 1);
1734 }
1735
1736#ifdef CONFIG_KEXEC
1737 insert_resource(&iomem_resource, &crashk_res);
1738#endif
1739
1740 return 0;
1741}
1742
1743subsys_initcall(request_standard_resources);
diff --git a/arch/tile/kernel/signal.c b/arch/tile/kernel/signal.c
deleted file mode 100644
index f2bf557bb005..000000000000
--- a/arch/tile/kernel/signal.c
+++ /dev/null
@@ -1,411 +0,0 @@
1/*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#include <linux/sched.h>
17#include <linux/sched/debug.h>
18#include <linux/sched/task_stack.h>
19#include <linux/mm.h>
20#include <linux/smp.h>
21#include <linux/kernel.h>
22#include <linux/signal.h>
23#include <linux/errno.h>
24#include <linux/wait.h>
25#include <linux/unistd.h>
26#include <linux/stddef.h>
27#include <linux/personality.h>
28#include <linux/suspend.h>
29#include <linux/ptrace.h>
30#include <linux/elf.h>
31#include <linux/compat.h>
32#include <linux/syscalls.h>
33#include <linux/uaccess.h>
34#include <asm/processor.h>
35#include <asm/ucontext.h>
36#include <asm/sigframe.h>
37#include <asm/syscalls.h>
38#include <asm/vdso.h>
39#include <arch/interrupts.h>
40
41#define DEBUG_SIG 0
42
43/*
44 * Do a signal return; undo the signal stack.
45 */
46
47int restore_sigcontext(struct pt_regs *regs,
48 struct sigcontext __user *sc)
49{
50 int err;
51
52 /* Always make any pending restarted system calls return -EINTR */
53 current->restart_block.fn = do_no_restart_syscall;
54
55 /*
56 * Enforce that sigcontext is like pt_regs, and doesn't mess
57 * up our stack alignment rules.
58 */
59 BUILD_BUG_ON(sizeof(struct sigcontext) != sizeof(struct pt_regs));
60 BUILD_BUG_ON(sizeof(struct sigcontext) % 8 != 0);
61 err = __copy_from_user(regs, sc, sizeof(*regs));
62
63 /* Ensure that the PL is always set to USER_PL. */
64 regs->ex1 = PL_ICS_EX1(USER_PL, EX1_ICS(regs->ex1));
65
66 regs->faultnum = INT_SWINT_1_SIGRETURN;
67
68 return err;
69}
70
71void signal_fault(const char *type, struct pt_regs *regs,
72 void __user *frame, int sig)
73{
74 trace_unhandled_signal(type, regs, (unsigned long)frame, SIGSEGV);
75 force_sigsegv(sig, current);
76}
77
78/* The assembly shim for this function arranges to ignore the return value. */
79SYSCALL_DEFINE0(rt_sigreturn)
80{
81 struct pt_regs *regs = current_pt_regs();
82 struct rt_sigframe __user *frame =
83 (struct rt_sigframe __user *)(regs->sp);
84 sigset_t set;
85
86 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
87 goto badframe;
88 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
89 goto badframe;
90
91 set_current_blocked(&set);
92
93 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
94 goto badframe;
95
96 if (restore_altstack(&frame->uc.uc_stack))
97 goto badframe;
98
99 return 0;
100
101badframe:
102 signal_fault("bad sigreturn frame", regs, frame, 0);
103 return 0;
104}
105
106/*
107 * Set up a signal frame.
108 */
109
110int setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs)
111{
112 return __copy_to_user(sc, regs, sizeof(*regs));
113}
114
115/*
116 * Determine which stack to use..
117 */
118static inline void __user *get_sigframe(struct k_sigaction *ka,
119 struct pt_regs *regs,
120 size_t frame_size)
121{
122 unsigned long sp;
123
124 /* Default to using normal stack */
125 sp = regs->sp;
126
127 /*
128 * If we are on the alternate signal stack and would overflow
129 * it, don't. Return an always-bogus address instead so we
130 * will die with SIGSEGV.
131 */
132 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
133 return (void __user __force *)-1UL;
134
135 /* This is the X/Open sanctioned signal stack switching. */
136 if (ka->sa.sa_flags & SA_ONSTACK) {
137 if (sas_ss_flags(sp) == 0)
138 sp = current->sas_ss_sp + current->sas_ss_size;
139 }
140
141 sp -= frame_size;
142 /*
143 * Align the stack pointer according to the TILE ABI,
144 * i.e. so that on function entry (sp & 15) == 0.
145 */
146 sp &= -16UL;
147 return (void __user *) sp;
148}
149
150static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
151 struct pt_regs *regs)
152{
153 unsigned long restorer;
154 struct rt_sigframe __user *frame;
155 int err = 0, sig = ksig->sig;
156
157 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame));
158
159 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
160 goto err;
161
162 /* Always write at least the signal number for the stack backtracer. */
163 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
164 /* At sigreturn time, restore the callee-save registers too. */
165 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
166 regs->flags |= PT_FLAGS_RESTORE_REGS;
167 } else {
168 err |= __put_user(ksig->info.si_signo, &frame->info.si_signo);
169 }
170
171 /* Create the ucontext. */
172 err |= __clear_user(&frame->save_area, sizeof(frame->save_area));
173 err |= __put_user(0, &frame->uc.uc_flags);
174 err |= __put_user(NULL, &frame->uc.uc_link);
175 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
176 err |= setup_sigcontext(&frame->uc.uc_mcontext, regs);
177 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
178 if (err)
179 goto err;
180
181 restorer = VDSO_SYM(&__vdso_rt_sigreturn);
182 if (ksig->ka.sa.sa_flags & SA_RESTORER)
183 restorer = (unsigned long) ksig->ka.sa.sa_restorer;
184
185 /*
186 * Set up registers for signal handler.
187 * Registers that we don't modify keep the value they had from
188 * user-space at the time we took the signal.
189 * We always pass siginfo and mcontext, regardless of SA_SIGINFO,
190 * since some things rely on this (e.g. glibc's debug/segfault.c).
191 */
192 regs->pc = (unsigned long) ksig->ka.sa.sa_handler;
193 regs->ex1 = PL_ICS_EX1(USER_PL, 1); /* set crit sec in handler */
194 regs->sp = (unsigned long) frame;
195 regs->lr = restorer;
196 regs->regs[0] = (unsigned long) sig;
197 regs->regs[1] = (unsigned long) &frame->info;
198 regs->regs[2] = (unsigned long) &frame->uc;
199 regs->flags |= PT_FLAGS_CALLER_SAVES;
200 return 0;
201
202err:
203 trace_unhandled_signal("bad sigreturn frame", regs,
204 (unsigned long)frame, SIGSEGV);
205 return -EFAULT;
206}
207
208/*
209 * OK, we're invoking a handler
210 */
211
212static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
213{
214 sigset_t *oldset = sigmask_to_save();
215 int ret;
216
217 /* Are we from a system call? */
218 if (regs->faultnum == INT_SWINT_1) {
219 /* If so, check system call restarting.. */
220 switch (regs->regs[0]) {
221 case -ERESTART_RESTARTBLOCK:
222 case -ERESTARTNOHAND:
223 regs->regs[0] = -EINTR;
224 break;
225
226 case -ERESTARTSYS:
227 if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
228 regs->regs[0] = -EINTR;
229 break;
230 }
231 /* fallthrough */
232 case -ERESTARTNOINTR:
233 /* Reload caller-saves to restore r0..r5 and r10. */
234 regs->flags |= PT_FLAGS_CALLER_SAVES;
235 regs->regs[0] = regs->orig_r0;
236 regs->pc -= 8;
237 }
238 }
239
240 /* Set up the stack frame */
241#ifdef CONFIG_COMPAT
242 if (is_compat_task())
243 ret = compat_setup_rt_frame(ksig, oldset, regs);
244 else
245#endif
246 ret = setup_rt_frame(ksig, oldset, regs);
247
248 signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP));
249}
250
251/*
252 * Note that 'init' is a special process: it doesn't get signals it doesn't
253 * want to handle. Thus you cannot kill init even with a SIGKILL even by
254 * mistake.
255 */
256void do_signal(struct pt_regs *regs)
257{
258 struct ksignal ksig;
259
260 /*
261 * i386 will check if we're coming from kernel mode and bail out
262 * here. In my experience this just turns weird crashes into
263 * weird spin-hangs. But if we find a case where this seems
264 * helpful, we can reinstate the check on "!user_mode(regs)".
265 */
266
267 if (get_signal(&ksig)) {
268 /* Whee! Actually deliver the signal. */
269 handle_signal(&ksig, regs);
270 goto done;
271 }
272
273 /* Did we come from a system call? */
274 if (regs->faultnum == INT_SWINT_1) {
275 /* Restart the system call - no handlers present */
276 switch (regs->regs[0]) {
277 case -ERESTARTNOHAND:
278 case -ERESTARTSYS:
279 case -ERESTARTNOINTR:
280 regs->flags |= PT_FLAGS_CALLER_SAVES;
281 regs->regs[0] = regs->orig_r0;
282 regs->pc -= 8;
283 break;
284
285 case -ERESTART_RESTARTBLOCK:
286 regs->flags |= PT_FLAGS_CALLER_SAVES;
287 regs->regs[TREG_SYSCALL_NR] = __NR_restart_syscall;
288 regs->pc -= 8;
289 break;
290 }
291 }
292
293 /* If there's no signal to deliver, just put the saved sigmask back. */
294 restore_saved_sigmask();
295
296done:
297 /* Avoid double syscall restart if there are nested signals. */
298 regs->faultnum = INT_SWINT_1_SIGRETURN;
299}
300
301int show_unhandled_signals = 1;
302
303static int __init crashinfo(char *str)
304{
305 const char *word;
306
307 if (*str == '\0')
308 show_unhandled_signals = 2;
309 else if (*str != '=' || kstrtoint(++str, 0, &show_unhandled_signals) != 0)
310 return 0;
311
312 switch (show_unhandled_signals) {
313 case 0:
314 word = "No";
315 break;
316 case 1:
317 word = "One-line";
318 break;
319 default:
320 word = "Detailed";
321 break;
322 }
323 pr_info("%s crash reports will be generated on the console\n", word);
324 return 1;
325}
326__setup("crashinfo", crashinfo);
327
328static void dump_mem(void __user *address)
329{
330 void __user *addr;
331 enum { region_size = 256, bytes_per_line = 16 };
332 int i, j, k;
333 int found_readable_mem = 0;
334
335 if (!access_ok(VERIFY_READ, address, 1)) {
336 pr_err("Not dumping at address 0x%lx (kernel address)\n",
337 (unsigned long)address);
338 return;
339 }
340
341 addr = (void __user *)
342 (((unsigned long)address & -bytes_per_line) - region_size/2);
343 if (addr > address)
344 addr = NULL;
345 for (i = 0; i < region_size;
346 addr += bytes_per_line, i += bytes_per_line) {
347 unsigned char buf[bytes_per_line];
348 char line[100];
349 if (copy_from_user(buf, addr, bytes_per_line))
350 continue;
351 if (!found_readable_mem) {
352 pr_err("Dumping memory around address 0x%lx:\n",
353 (unsigned long)address);
354 found_readable_mem = 1;
355 }
356 j = sprintf(line, REGFMT ":", (unsigned long)addr);
357 for (k = 0; k < bytes_per_line; ++k)
358 j += sprintf(&line[j], " %02x", buf[k]);
359 pr_err("%s\n", line);
360 }
361 if (!found_readable_mem)
362 pr_err("No readable memory around address 0x%lx\n",
363 (unsigned long)address);
364}
365
366void trace_unhandled_signal(const char *type, struct pt_regs *regs,
367 unsigned long address, int sig)
368{
369 struct task_struct *tsk = current;
370
371 if (show_unhandled_signals == 0)
372 return;
373
374 /* If the signal is handled, don't show it here. */
375 if (!is_global_init(tsk)) {
376 void __user *handler =
377 tsk->sighand->action[sig-1].sa.sa_handler;
378 if (handler != SIG_IGN && handler != SIG_DFL)
379 return;
380 }
381
382 /* Rate-limit the one-line output, not the detailed output. */
383 if (show_unhandled_signals <= 1 && !printk_ratelimit())
384 return;
385
386 printk("%s%s[%d]: %s at %lx pc "REGFMT" signal %d",
387 task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG,
388 tsk->comm, task_pid_nr(tsk), type, address, regs->pc, sig);
389
390 print_vma_addr(KERN_CONT " in ", regs->pc);
391
392 printk(KERN_CONT "\n");
393
394 if (show_unhandled_signals > 1) {
395 switch (sig) {
396 case SIGILL:
397 case SIGFPE:
398 case SIGSEGV:
399 case SIGBUS:
400 pr_err("User crash: signal %d, trap %ld, address 0x%lx\n",
401 sig, regs->faultnum, address);
402 show_regs(regs);
403 dump_mem((void __user *)address);
404 break;
405 default:
406 pr_err("User crash: signal %d, trap %ld\n",
407 sig, regs->faultnum);
408 break;
409 }
410 }
411}
diff --git a/arch/tile/kernel/single_step.c b/arch/tile/kernel/single_step.c
deleted file mode 100644
index 479d8033a801..000000000000
--- a/arch/tile/kernel/single_step.c
+++ /dev/null
@@ -1,786 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * A code-rewriter that enables instruction single-stepping.
15 */
16
17#include <linux/smp.h>
18#include <linux/ptrace.h>
19#include <linux/slab.h>
20#include <linux/thread_info.h>
21#include <linux/uaccess.h>
22#include <linux/mman.h>
23#include <linux/types.h>
24#include <linux/err.h>
25#include <linux/prctl.h>
26#include <asm/cacheflush.h>
27#include <asm/traps.h>
28#include <linux/uaccess.h>
29#include <asm/unaligned.h>
30#include <arch/abi.h>
31#include <arch/spr_def.h>
32#include <arch/opcode.h>
33
34
35#ifndef __tilegx__ /* Hardware support for single step unavailable. */
36
37#define signExtend17(val) sign_extend((val), 17)
38#define TILE_X1_MASK (0xffffffffULL << 31)
39
40enum mem_op {
41 MEMOP_NONE,
42 MEMOP_LOAD,
43 MEMOP_STORE,
44 MEMOP_LOAD_POSTINCR,
45 MEMOP_STORE_POSTINCR
46};
47
48static inline tilepro_bundle_bits set_BrOff_X1(tilepro_bundle_bits n,
49 s32 offset)
50{
51 tilepro_bundle_bits result;
52
53 /* mask out the old offset */
54 tilepro_bundle_bits mask = create_BrOff_X1(-1);
55 result = n & (~mask);
56
57 /* or in the new offset */
58 result |= create_BrOff_X1(offset);
59
60 return result;
61}
62
63static inline tilepro_bundle_bits move_X1(tilepro_bundle_bits n, int dest,
64 int src)
65{
66 tilepro_bundle_bits result;
67 tilepro_bundle_bits op;
68
69 result = n & (~TILE_X1_MASK);
70
71 op = create_Opcode_X1(SPECIAL_0_OPCODE_X1) |
72 create_RRROpcodeExtension_X1(OR_SPECIAL_0_OPCODE_X1) |
73 create_Dest_X1(dest) |
74 create_SrcB_X1(TREG_ZERO) |
75 create_SrcA_X1(src) ;
76
77 result |= op;
78 return result;
79}
80
81static inline tilepro_bundle_bits nop_X1(tilepro_bundle_bits n)
82{
83 return move_X1(n, TREG_ZERO, TREG_ZERO);
84}
85
86static inline tilepro_bundle_bits addi_X1(
87 tilepro_bundle_bits n, int dest, int src, int imm)
88{
89 n &= ~TILE_X1_MASK;
90
91 n |= (create_SrcA_X1(src) |
92 create_Dest_X1(dest) |
93 create_Imm8_X1(imm) |
94 create_S_X1(0) |
95 create_Opcode_X1(IMM_0_OPCODE_X1) |
96 create_ImmOpcodeExtension_X1(ADDI_IMM_0_OPCODE_X1));
97
98 return n;
99}
100
101static tilepro_bundle_bits rewrite_load_store_unaligned(
102 struct single_step_state *state,
103 tilepro_bundle_bits bundle,
104 struct pt_regs *regs,
105 enum mem_op mem_op,
106 int size, int sign_ext)
107{
108 unsigned char __user *addr;
109 int val_reg, addr_reg, err, val;
110 int align_ctl;
111
112 align_ctl = unaligned_fixup;
113 switch (task_thread_info(current)->align_ctl) {
114 case PR_UNALIGN_NOPRINT:
115 align_ctl = 1;
116 break;
117 case PR_UNALIGN_SIGBUS:
118 align_ctl = 0;
119 break;
120 }
121
122 /* Get address and value registers */
123 if (bundle & TILEPRO_BUNDLE_Y_ENCODING_MASK) {
124 addr_reg = get_SrcA_Y2(bundle);
125 val_reg = get_SrcBDest_Y2(bundle);
126 } else if (mem_op == MEMOP_LOAD || mem_op == MEMOP_LOAD_POSTINCR) {
127 addr_reg = get_SrcA_X1(bundle);
128 val_reg = get_Dest_X1(bundle);
129 } else {
130 addr_reg = get_SrcA_X1(bundle);
131 val_reg = get_SrcB_X1(bundle);
132 }
133
134 /*
135 * If registers are not GPRs, don't try to handle it.
136 *
137 * FIXME: we could handle non-GPR loads by getting the real value
138 * from memory, writing it to the single step buffer, using a
139 * temp_reg to hold a pointer to that memory, then executing that
140 * instruction and resetting temp_reg. For non-GPR stores, it's a
141 * little trickier; we could use the single step buffer for that
142 * too, but we'd have to add some more state bits so that we could
143 * call back in here to copy that value to the real target. For
144 * now, we just handle the simple case.
145 */
146 if ((val_reg >= PTREGS_NR_GPRS &&
147 (val_reg != TREG_ZERO ||
148 mem_op == MEMOP_LOAD ||
149 mem_op == MEMOP_LOAD_POSTINCR)) ||
150 addr_reg >= PTREGS_NR_GPRS)
151 return bundle;
152
153 /* If it's aligned, don't handle it specially */
154 addr = (void __user *)regs->regs[addr_reg];
155 if (((unsigned long)addr % size) == 0)
156 return bundle;
157
158 /*
159 * Return SIGBUS with the unaligned address, if requested.
160 * Note that we return SIGBUS even for completely invalid addresses
161 * as long as they are in fact unaligned; this matches what the
162 * tilepro hardware would be doing, if it could provide us with the
163 * actual bad address in an SPR, which it doesn't.
164 */
165 if (align_ctl == 0) {
166 siginfo_t info;
167
168 clear_siginfo(&info);
169 info.si_signo = SIGBUS;
170 info.si_code = BUS_ADRALN;
171 info.si_addr = addr;
172
173 trace_unhandled_signal("unaligned trap", regs,
174 (unsigned long)addr, SIGBUS);
175 force_sig_info(info.si_signo, &info, current);
176 return (tilepro_bundle_bits) 0;
177 }
178
179 /* Handle unaligned load/store */
180 if (mem_op == MEMOP_LOAD || mem_op == MEMOP_LOAD_POSTINCR) {
181 unsigned short val_16;
182 switch (size) {
183 case 2:
184 err = copy_from_user(&val_16, addr, sizeof(val_16));
185 val = sign_ext ? ((short)val_16) : val_16;
186 break;
187 case 4:
188 err = copy_from_user(&val, addr, sizeof(val));
189 break;
190 default:
191 BUG();
192 }
193 if (err == 0) {
194 state->update_reg = val_reg;
195 state->update_value = val;
196 state->update = 1;
197 }
198 } else {
199 unsigned short val_16;
200 val = (val_reg == TREG_ZERO) ? 0 : regs->regs[val_reg];
201 switch (size) {
202 case 2:
203 val_16 = val;
204 err = copy_to_user(addr, &val_16, sizeof(val_16));
205 break;
206 case 4:
207 err = copy_to_user(addr, &val, sizeof(val));
208 break;
209 default:
210 BUG();
211 }
212 }
213
214 if (err) {
215 siginfo_t info;
216
217 clear_siginfo(&info);
218 info.si_signo = SIGBUS;
219 info.si_code = BUS_ADRALN;
220 info.si_addr = addr;
221
222 trace_unhandled_signal("bad address for unaligned fixup", regs,
223 (unsigned long)addr, SIGBUS);
224 force_sig_info(info.si_signo, &info, current);
225 return (tilepro_bundle_bits) 0;
226 }
227
228 if (unaligned_printk || unaligned_fixup_count == 0) {
229 pr_info("Process %d/%s: PC %#lx: Fixup of unaligned %s at %#lx\n",
230 current->pid, current->comm, regs->pc,
231 mem_op == MEMOP_LOAD || mem_op == MEMOP_LOAD_POSTINCR ?
232 "load" : "store",
233 (unsigned long)addr);
234 if (!unaligned_printk) {
235#define P pr_info
236P("\n");
237P("Unaligned fixups in the kernel will slow your application considerably.\n");
238P("To find them, write a \"1\" to /proc/sys/tile/unaligned_fixup/printk,\n");
239P("which requests the kernel show all unaligned fixups, or write a \"0\"\n");
240P("to /proc/sys/tile/unaligned_fixup/enabled, in which case each unaligned\n");
241P("access will become a SIGBUS you can debug. No further warnings will be\n");
242P("shown so as to avoid additional slowdown, but you can track the number\n");
243P("of fixups performed via /proc/sys/tile/unaligned_fixup/count.\n");
244P("Use the tile-addr2line command (see \"info addr2line\") to decode PCs.\n");
245P("\n");
246#undef P
247 }
248 }
249 ++unaligned_fixup_count;
250
251 if (bundle & TILEPRO_BUNDLE_Y_ENCODING_MASK) {
252 /* Convert the Y2 instruction to a prefetch. */
253 bundle &= ~(create_SrcBDest_Y2(-1) |
254 create_Opcode_Y2(-1));
255 bundle |= (create_SrcBDest_Y2(TREG_ZERO) |
256 create_Opcode_Y2(LW_OPCODE_Y2));
257 /* Replace the load postincr with an addi */
258 } else if (mem_op == MEMOP_LOAD_POSTINCR) {
259 bundle = addi_X1(bundle, addr_reg, addr_reg,
260 get_Imm8_X1(bundle));
261 /* Replace the store postincr with an addi */
262 } else if (mem_op == MEMOP_STORE_POSTINCR) {
263 bundle = addi_X1(bundle, addr_reg, addr_reg,
264 get_Dest_Imm8_X1(bundle));
265 } else {
266 /* Convert the X1 instruction to a nop. */
267 bundle &= ~(create_Opcode_X1(-1) |
268 create_UnShOpcodeExtension_X1(-1) |
269 create_UnOpcodeExtension_X1(-1));
270 bundle |= (create_Opcode_X1(SHUN_0_OPCODE_X1) |
271 create_UnShOpcodeExtension_X1(
272 UN_0_SHUN_0_OPCODE_X1) |
273 create_UnOpcodeExtension_X1(
274 NOP_UN_0_SHUN_0_OPCODE_X1));
275 }
276
277 return bundle;
278}
279
280/*
281 * Called after execve() has started the new image. This allows us
282 * to reset the info state. Note that the the mmap'ed memory, if there
283 * was any, has already been unmapped by the exec.
284 */
285void single_step_execve(void)
286{
287 struct thread_info *ti = current_thread_info();
288 kfree(ti->step_state);
289 ti->step_state = NULL;
290}
291
292/*
293 * single_step_once() - entry point when single stepping has been triggered.
294 * @regs: The machine register state
295 *
296 * When we arrive at this routine via a trampoline, the single step
297 * engine copies the executing bundle to the single step buffer.
298 * If the instruction is a condition branch, then the target is
299 * reset to one past the next instruction. If the instruction
300 * sets the lr, then that is noted. If the instruction is a jump
301 * or call, then the new target pc is preserved and the current
302 * bundle instruction set to null.
303 *
304 * The necessary post-single-step rewriting information is stored in
305 * single_step_state-> We use data segment values because the
306 * stack will be rewound when we run the rewritten single-stepped
307 * instruction.
308 */
309void single_step_once(struct pt_regs *regs)
310{
311 extern tilepro_bundle_bits __single_step_ill_insn;
312 extern tilepro_bundle_bits __single_step_j_insn;
313 extern tilepro_bundle_bits __single_step_addli_insn;
314 extern tilepro_bundle_bits __single_step_auli_insn;
315 struct thread_info *info = (void *)current_thread_info();
316 struct single_step_state *state = info->step_state;
317 int is_single_step = test_ti_thread_flag(info, TIF_SINGLESTEP);
318 tilepro_bundle_bits __user *buffer, *pc;
319 tilepro_bundle_bits bundle;
320 int temp_reg;
321 int target_reg = TREG_LR;
322 int err;
323 enum mem_op mem_op = MEMOP_NONE;
324 int size = 0, sign_ext = 0; /* happy compiler */
325 int align_ctl;
326
327 align_ctl = unaligned_fixup;
328 switch (task_thread_info(current)->align_ctl) {
329 case PR_UNALIGN_NOPRINT:
330 align_ctl = 1;
331 break;
332 case PR_UNALIGN_SIGBUS:
333 align_ctl = 0;
334 break;
335 }
336
337 asm(
338" .pushsection .rodata.single_step\n"
339" .align 8\n"
340" .globl __single_step_ill_insn\n"
341"__single_step_ill_insn:\n"
342" ill\n"
343" .globl __single_step_addli_insn\n"
344"__single_step_addli_insn:\n"
345" { nop; addli r0, zero, 0 }\n"
346" .globl __single_step_auli_insn\n"
347"__single_step_auli_insn:\n"
348" { nop; auli r0, r0, 0 }\n"
349" .globl __single_step_j_insn\n"
350"__single_step_j_insn:\n"
351" j .\n"
352" .popsection\n"
353 );
354
355 /*
356 * Enable interrupts here to allow touching userspace and the like.
357 * The callers expect this: do_trap() already has interrupts
358 * enabled, and do_work_pending() handles functions that enable
359 * interrupts internally.
360 */
361 local_irq_enable();
362
363 if (state == NULL) {
364 /* allocate a page of writable, executable memory */
365 state = kmalloc(sizeof(struct single_step_state), GFP_KERNEL);
366 if (state == NULL) {
367 pr_err("Out of kernel memory trying to single-step\n");
368 return;
369 }
370
371 /* allocate a cache line of writable, executable memory */
372 buffer = (void __user *) vm_mmap(NULL, 0, 64,
373 PROT_EXEC | PROT_READ | PROT_WRITE,
374 MAP_PRIVATE | MAP_ANONYMOUS,
375 0);
376
377 if (IS_ERR((void __force *)buffer)) {
378 kfree(state);
379 pr_err("Out of kernel pages trying to single-step\n");
380 return;
381 }
382
383 state->buffer = buffer;
384 state->is_enabled = 0;
385
386 info->step_state = state;
387
388 /* Validate our stored instruction patterns */
389 BUG_ON(get_Opcode_X1(__single_step_addli_insn) !=
390 ADDLI_OPCODE_X1);
391 BUG_ON(get_Opcode_X1(__single_step_auli_insn) !=
392 AULI_OPCODE_X1);
393 BUG_ON(get_SrcA_X1(__single_step_addli_insn) != TREG_ZERO);
394 BUG_ON(get_Dest_X1(__single_step_addli_insn) != 0);
395 BUG_ON(get_JOffLong_X1(__single_step_j_insn) != 0);
396 }
397
398 /*
399 * If we are returning from a syscall, we still haven't hit the
400 * "ill" for the swint1 instruction. So back the PC up to be
401 * pointing at the swint1, but we'll actually return directly
402 * back to the "ill" so we come back in via SIGILL as if we
403 * had "executed" the swint1 without ever being in kernel space.
404 */
405 if (regs->faultnum == INT_SWINT_1)
406 regs->pc -= 8;
407
408 pc = (tilepro_bundle_bits __user *)(regs->pc);
409 if (get_user(bundle, pc) != 0) {
410 pr_err("Couldn't read instruction at %p trying to step\n", pc);
411 return;
412 }
413
414 /* We'll follow the instruction with 2 ill op bundles */
415 state->orig_pc = (unsigned long)pc;
416 state->next_pc = (unsigned long)(pc + 1);
417 state->branch_next_pc = 0;
418 state->update = 0;
419
420 if (!(bundle & TILEPRO_BUNDLE_Y_ENCODING_MASK)) {
421 /* two wide, check for control flow */
422 int opcode = get_Opcode_X1(bundle);
423
424 switch (opcode) {
425 /* branches */
426 case BRANCH_OPCODE_X1:
427 {
428 s32 offset = signExtend17(get_BrOff_X1(bundle));
429
430 /*
431 * For branches, we use a rewriting trick to let the
432 * hardware evaluate whether the branch is taken or
433 * untaken. We record the target offset and then
434 * rewrite the branch instruction to target 1 insn
435 * ahead if the branch is taken. We then follow the
436 * rewritten branch with two bundles, each containing
437 * an "ill" instruction. The supervisor examines the
438 * pc after the single step code is executed, and if
439 * the pc is the first ill instruction, then the
440 * branch (if any) was not taken. If the pc is the
441 * second ill instruction, then the branch was
442 * taken. The new pc is computed for these cases, and
443 * inserted into the registers for the thread. If
444 * the pc is the start of the single step code, then
445 * an exception or interrupt was taken before the
446 * code started processing, and the same "original"
447 * pc is restored. This change, different from the
448 * original implementation, has the advantage of
449 * executing a single user instruction.
450 */
451 state->branch_next_pc = (unsigned long)(pc + offset);
452
453 /* rewrite branch offset to go forward one bundle */
454 bundle = set_BrOff_X1(bundle, 2);
455 }
456 break;
457
458 /* jumps */
459 case JALB_OPCODE_X1:
460 case JALF_OPCODE_X1:
461 state->update = 1;
462 state->next_pc =
463 (unsigned long) (pc + get_JOffLong_X1(bundle));
464 break;
465
466 case JB_OPCODE_X1:
467 case JF_OPCODE_X1:
468 state->next_pc =
469 (unsigned long) (pc + get_JOffLong_X1(bundle));
470 bundle = nop_X1(bundle);
471 break;
472
473 case SPECIAL_0_OPCODE_X1:
474 switch (get_RRROpcodeExtension_X1(bundle)) {
475 /* jump-register */
476 case JALRP_SPECIAL_0_OPCODE_X1:
477 case JALR_SPECIAL_0_OPCODE_X1:
478 state->update = 1;
479 state->next_pc =
480 regs->regs[get_SrcA_X1(bundle)];
481 break;
482
483 case JRP_SPECIAL_0_OPCODE_X1:
484 case JR_SPECIAL_0_OPCODE_X1:
485 state->next_pc =
486 regs->regs[get_SrcA_X1(bundle)];
487 bundle = nop_X1(bundle);
488 break;
489
490 case LNK_SPECIAL_0_OPCODE_X1:
491 state->update = 1;
492 target_reg = get_Dest_X1(bundle);
493 break;
494
495 /* stores */
496 case SH_SPECIAL_0_OPCODE_X1:
497 mem_op = MEMOP_STORE;
498 size = 2;
499 break;
500
501 case SW_SPECIAL_0_OPCODE_X1:
502 mem_op = MEMOP_STORE;
503 size = 4;
504 break;
505 }
506 break;
507
508 /* loads and iret */
509 case SHUN_0_OPCODE_X1:
510 if (get_UnShOpcodeExtension_X1(bundle) ==
511 UN_0_SHUN_0_OPCODE_X1) {
512 switch (get_UnOpcodeExtension_X1(bundle)) {
513 case LH_UN_0_SHUN_0_OPCODE_X1:
514 mem_op = MEMOP_LOAD;
515 size = 2;
516 sign_ext = 1;
517 break;
518
519 case LH_U_UN_0_SHUN_0_OPCODE_X1:
520 mem_op = MEMOP_LOAD;
521 size = 2;
522 sign_ext = 0;
523 break;
524
525 case LW_UN_0_SHUN_0_OPCODE_X1:
526 mem_op = MEMOP_LOAD;
527 size = 4;
528 break;
529
530 case IRET_UN_0_SHUN_0_OPCODE_X1:
531 {
532 unsigned long ex0_0 = __insn_mfspr(
533 SPR_EX_CONTEXT_0_0);
534 unsigned long ex0_1 = __insn_mfspr(
535 SPR_EX_CONTEXT_0_1);
536 /*
537 * Special-case it if we're iret'ing
538 * to PL0 again. Otherwise just let
539 * it run and it will generate SIGILL.
540 */
541 if (EX1_PL(ex0_1) == USER_PL) {
542 state->next_pc = ex0_0;
543 regs->ex1 = ex0_1;
544 bundle = nop_X1(bundle);
545 }
546 }
547 }
548 }
549 break;
550
551 /* postincrement operations */
552 case IMM_0_OPCODE_X1:
553 switch (get_ImmOpcodeExtension_X1(bundle)) {
554 case LWADD_IMM_0_OPCODE_X1:
555 mem_op = MEMOP_LOAD_POSTINCR;
556 size = 4;
557 break;
558
559 case LHADD_IMM_0_OPCODE_X1:
560 mem_op = MEMOP_LOAD_POSTINCR;
561 size = 2;
562 sign_ext = 1;
563 break;
564
565 case LHADD_U_IMM_0_OPCODE_X1:
566 mem_op = MEMOP_LOAD_POSTINCR;
567 size = 2;
568 sign_ext = 0;
569 break;
570
571 case SWADD_IMM_0_OPCODE_X1:
572 mem_op = MEMOP_STORE_POSTINCR;
573 size = 4;
574 break;
575
576 case SHADD_IMM_0_OPCODE_X1:
577 mem_op = MEMOP_STORE_POSTINCR;
578 size = 2;
579 break;
580
581 default:
582 break;
583 }
584 break;
585 }
586
587 if (state->update) {
588 /*
589 * Get an available register. We start with a
590 * bitmask with 1's for available registers.
591 * We truncate to the low 32 registers since
592 * we are guaranteed to have set bits in the
593 * low 32 bits, then use ctz to pick the first.
594 */
595 u32 mask = (u32) ~((1ULL << get_Dest_X0(bundle)) |
596 (1ULL << get_SrcA_X0(bundle)) |
597 (1ULL << get_SrcB_X0(bundle)) |
598 (1ULL << target_reg));
599 temp_reg = __builtin_ctz(mask);
600 state->update_reg = temp_reg;
601 state->update_value = regs->regs[temp_reg];
602 regs->regs[temp_reg] = (unsigned long) (pc+1);
603 regs->flags |= PT_FLAGS_RESTORE_REGS;
604 bundle = move_X1(bundle, target_reg, temp_reg);
605 }
606 } else {
607 int opcode = get_Opcode_Y2(bundle);
608
609 switch (opcode) {
610 /* loads */
611 case LH_OPCODE_Y2:
612 mem_op = MEMOP_LOAD;
613 size = 2;
614 sign_ext = 1;
615 break;
616
617 case LH_U_OPCODE_Y2:
618 mem_op = MEMOP_LOAD;
619 size = 2;
620 sign_ext = 0;
621 break;
622
623 case LW_OPCODE_Y2:
624 mem_op = MEMOP_LOAD;
625 size = 4;
626 break;
627
628 /* stores */
629 case SH_OPCODE_Y2:
630 mem_op = MEMOP_STORE;
631 size = 2;
632 break;
633
634 case SW_OPCODE_Y2:
635 mem_op = MEMOP_STORE;
636 size = 4;
637 break;
638 }
639 }
640
641 /*
642 * Check if we need to rewrite an unaligned load/store.
643 * Returning zero is a special value meaning we generated a signal.
644 */
645 if (mem_op != MEMOP_NONE && align_ctl >= 0) {
646 bundle = rewrite_load_store_unaligned(state, bundle, regs,
647 mem_op, size, sign_ext);
648 if (bundle == 0)
649 return;
650 }
651
652 /* write the bundle to our execution area */
653 buffer = state->buffer;
654 err = __put_user(bundle, buffer++);
655
656 /*
657 * If we're really single-stepping, we take an INT_ILL after.
658 * If we're just handling an unaligned access, we can just
659 * jump directly back to where we were in user code.
660 */
661 if (is_single_step) {
662 err |= __put_user(__single_step_ill_insn, buffer++);
663 err |= __put_user(__single_step_ill_insn, buffer++);
664 } else {
665 long delta;
666
667 if (state->update) {
668 /* We have some state to update; do it inline */
669 int ha16;
670 bundle = __single_step_addli_insn;
671 bundle |= create_Dest_X1(state->update_reg);
672 bundle |= create_Imm16_X1(state->update_value);
673 err |= __put_user(bundle, buffer++);
674 bundle = __single_step_auli_insn;
675 bundle |= create_Dest_X1(state->update_reg);
676 bundle |= create_SrcA_X1(state->update_reg);
677 ha16 = (state->update_value + 0x8000) >> 16;
678 bundle |= create_Imm16_X1(ha16);
679 err |= __put_user(bundle, buffer++);
680 state->update = 0;
681 }
682
683 /* End with a jump back to the next instruction */
684 delta = ((regs->pc + TILEPRO_BUNDLE_SIZE_IN_BYTES) -
685 (unsigned long)buffer) >>
686 TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES;
687 bundle = __single_step_j_insn;
688 bundle |= create_JOffLong_X1(delta);
689 err |= __put_user(bundle, buffer++);
690 }
691
692 if (err) {
693 pr_err("Fault when writing to single-step buffer\n");
694 return;
695 }
696
697 /*
698 * Flush the buffer.
699 * We do a local flush only, since this is a thread-specific buffer.
700 */
701 __flush_icache_range((unsigned long)state->buffer,
702 (unsigned long)buffer);
703
704 /* Indicate enabled */
705 state->is_enabled = is_single_step;
706 regs->pc = (unsigned long)state->buffer;
707
708 /* Fault immediately if we are coming back from a syscall. */
709 if (regs->faultnum == INT_SWINT_1)
710 regs->pc += 8;
711}
712
713#else
714
715static DEFINE_PER_CPU(unsigned long, ss_saved_pc);
716
717
718/*
719 * Called directly on the occasion of an interrupt.
720 *
721 * If the process doesn't have single step set, then we use this as an
722 * opportunity to turn single step off.
723 *
724 * It has been mentioned that we could conditionally turn off single stepping
725 * on each entry into the kernel and rely on single_step_once to turn it
726 * on for the processes that matter (as we already do), but this
727 * implementation is somewhat more efficient in that we muck with registers
728 * once on a bum interrupt rather than on every entry into the kernel.
729 *
730 * If SINGLE_STEP_CONTROL_K has CANCELED set, then an interrupt occurred,
731 * so we have to run through this process again before we can say that an
732 * instruction has executed.
733 *
734 * swint will set CANCELED, but it's a legitimate instruction. Fortunately
735 * it changes the PC. If it hasn't changed, then we know that the interrupt
736 * wasn't generated by swint and we'll need to run this process again before
737 * we can say an instruction has executed.
738 *
739 * If either CANCELED == 0 or the PC's changed, we send out SIGTRAPs and get
740 * on with our lives.
741 */
742
743void gx_singlestep_handle(struct pt_regs *regs, int fault_num)
744{
745 unsigned long *ss_pc = this_cpu_ptr(&ss_saved_pc);
746 struct thread_info *info = (void *)current_thread_info();
747 int is_single_step = test_ti_thread_flag(info, TIF_SINGLESTEP);
748 unsigned long control = __insn_mfspr(SPR_SINGLE_STEP_CONTROL_K);
749
750 if (is_single_step == 0) {
751 __insn_mtspr(SPR_SINGLE_STEP_EN_K_K, 0);
752
753 } else if ((*ss_pc != regs->pc) ||
754 (!(control & SPR_SINGLE_STEP_CONTROL_1__CANCELED_MASK))) {
755
756 control |= SPR_SINGLE_STEP_CONTROL_1__CANCELED_MASK;
757 control |= SPR_SINGLE_STEP_CONTROL_1__INHIBIT_MASK;
758 __insn_mtspr(SPR_SINGLE_STEP_CONTROL_K, control);
759 send_sigtrap(current, regs);
760 }
761}
762
763
764/*
765 * Called from need_singlestep. Set up the control registers and the enable
766 * register, then return back.
767 */
768
769void single_step_once(struct pt_regs *regs)
770{
771 unsigned long *ss_pc = this_cpu_ptr(&ss_saved_pc);
772 unsigned long control = __insn_mfspr(SPR_SINGLE_STEP_CONTROL_K);
773
774 *ss_pc = regs->pc;
775 control |= SPR_SINGLE_STEP_CONTROL_1__CANCELED_MASK;
776 control |= SPR_SINGLE_STEP_CONTROL_1__INHIBIT_MASK;
777 __insn_mtspr(SPR_SINGLE_STEP_CONTROL_K, control);
778 __insn_mtspr(SPR_SINGLE_STEP_EN_K_K, 1 << USER_PL);
779}
780
781void single_step_execve(void)
782{
783 /* Nothing */
784}
785
786#endif /* !__tilegx__ */
diff --git a/arch/tile/kernel/smp.c b/arch/tile/kernel/smp.c
deleted file mode 100644
index 94a62e1197ce..000000000000
--- a/arch/tile/kernel/smp.c
+++ /dev/null
@@ -1,287 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE SMP support routines.
15 */
16
17#include <linux/smp.h>
18#include <linux/interrupt.h>
19#include <linux/io.h>
20#include <linux/irq.h>
21#include <linux/irq_work.h>
22#include <linux/module.h>
23#include <asm/cacheflush.h>
24#include <asm/homecache.h>
25
26/*
27 * We write to width and height with a single store in head_NN.S,
28 * so make the variable aligned to "long".
29 */
30HV_Topology smp_topology __ro_after_init __aligned(sizeof(long));
31EXPORT_SYMBOL(smp_topology);
32
33#if CHIP_HAS_IPI()
34static unsigned long __iomem *ipi_mappings[NR_CPUS];
35#endif
36
37/* Does messaging work correctly to the local cpu? */
38bool self_interrupt_ok;
39
40/*
41 * Top-level send_IPI*() functions to send messages to other cpus.
42 */
43
44/* Set by smp_send_stop() to avoid recursive panics. */
45static int stopping_cpus;
46
47static void __send_IPI_many(HV_Recipient *recip, int nrecip, int tag)
48{
49 int sent = 0;
50 while (sent < nrecip) {
51 int rc = hv_send_message(recip, nrecip,
52 (HV_VirtAddr)&tag, sizeof(tag));
53 if (rc < 0) {
54 if (!stopping_cpus) /* avoid recursive panic */
55 panic("hv_send_message returned %d", rc);
56 break;
57 }
58 WARN_ONCE(rc == 0, "hv_send_message() returned zero\n");
59 sent += rc;
60 }
61}
62
63void send_IPI_single(int cpu, int tag)
64{
65 HV_Recipient recip = {
66 .y = cpu / smp_width,
67 .x = cpu % smp_width,
68 .state = HV_TO_BE_SENT
69 };
70 __send_IPI_many(&recip, 1, tag);
71}
72
73void send_IPI_many(const struct cpumask *mask, int tag)
74{
75 HV_Recipient recip[NR_CPUS];
76 int cpu;
77 int nrecip = 0;
78 int my_cpu = smp_processor_id();
79 for_each_cpu(cpu, mask) {
80 HV_Recipient *r;
81 BUG_ON(cpu == my_cpu);
82 r = &recip[nrecip++];
83 r->y = cpu / smp_width;
84 r->x = cpu % smp_width;
85 r->state = HV_TO_BE_SENT;
86 }
87 __send_IPI_many(recip, nrecip, tag);
88}
89
90void send_IPI_allbutself(int tag)
91{
92 struct cpumask mask;
93 cpumask_copy(&mask, cpu_online_mask);
94 cpumask_clear_cpu(smp_processor_id(), &mask);
95 send_IPI_many(&mask, tag);
96}
97
98/*
99 * Functions related to starting/stopping cpus.
100 */
101
102/* Handler to start the current cpu. */
103static void smp_start_cpu_interrupt(void)
104{
105 get_irq_regs()->pc = start_cpu_function_addr;
106}
107
108/* Handler to stop the current cpu. */
109static void smp_stop_cpu_interrupt(void)
110{
111 arch_local_irq_disable_all();
112 set_cpu_online(smp_processor_id(), 0);
113 for (;;)
114 asm("nap; nop");
115}
116
117/* This function calls the 'stop' function on all other CPUs in the system. */
118void smp_send_stop(void)
119{
120 stopping_cpus = 1;
121 send_IPI_allbutself(MSG_TAG_STOP_CPU);
122}
123
124/* On panic, just wait; we may get an smp_send_stop() later on. */
125void panic_smp_self_stop(void)
126{
127 while (1)
128 asm("nap; nop");
129}
130
131/*
132 * Dispatch code called from hv_message_intr() for HV_MSG_TILE hv messages.
133 */
134void evaluate_message(int tag)
135{
136 switch (tag) {
137 case MSG_TAG_START_CPU: /* Start up a cpu */
138 smp_start_cpu_interrupt();
139 break;
140
141 case MSG_TAG_STOP_CPU: /* Sent to shut down slave CPU's */
142 smp_stop_cpu_interrupt();
143 break;
144
145 case MSG_TAG_CALL_FUNCTION_MANY: /* Call function on cpumask */
146 generic_smp_call_function_interrupt();
147 break;
148
149 case MSG_TAG_CALL_FUNCTION_SINGLE: /* Call function on one other CPU */
150 generic_smp_call_function_single_interrupt();
151 break;
152
153 case MSG_TAG_IRQ_WORK: /* Invoke IRQ work */
154 irq_work_run();
155 break;
156
157 default:
158 panic("Unknown IPI message tag %d", tag);
159 break;
160 }
161}
162
163
164/*
165 * flush_icache_range() code uses smp_call_function().
166 */
167
168struct ipi_flush {
169 unsigned long start;
170 unsigned long end;
171};
172
173static void ipi_flush_icache_range(void *info)
174{
175 struct ipi_flush *flush = (struct ipi_flush *) info;
176 __flush_icache_range(flush->start, flush->end);
177}
178
179void flush_icache_range(unsigned long start, unsigned long end)
180{
181 struct ipi_flush flush = { start, end };
182
183 /* If invoked with irqs disabled, we can not issue IPIs. */
184 if (irqs_disabled())
185 flush_remote(0, HV_FLUSH_EVICT_L1I, NULL, 0, 0, 0,
186 NULL, NULL, 0);
187 else {
188 preempt_disable();
189 on_each_cpu(ipi_flush_icache_range, &flush, 1);
190 preempt_enable();
191 }
192}
193EXPORT_SYMBOL(flush_icache_range);
194
195
196#ifdef CONFIG_IRQ_WORK
197void arch_irq_work_raise(void)
198{
199 if (arch_irq_work_has_interrupt())
200 send_IPI_single(smp_processor_id(), MSG_TAG_IRQ_WORK);
201}
202#endif
203
204
205/* Called when smp_send_reschedule() triggers IRQ_RESCHEDULE. */
206static irqreturn_t handle_reschedule_ipi(int irq, void *token)
207{
208 __this_cpu_inc(irq_stat.irq_resched_count);
209 scheduler_ipi();
210
211 return IRQ_HANDLED;
212}
213
214static struct irqaction resched_action = {
215 .handler = handle_reschedule_ipi,
216 .name = "resched",
217 .dev_id = handle_reschedule_ipi /* unique token */,
218};
219
220void __init ipi_init(void)
221{
222 int cpu = smp_processor_id();
223 HV_Recipient recip = { .y = cpu_y(cpu), .x = cpu_x(cpu),
224 .state = HV_TO_BE_SENT };
225 int tag = MSG_TAG_CALL_FUNCTION_SINGLE;
226
227 /*
228 * Test if we can message ourselves for arch_irq_work_raise.
229 * This functionality is only available in the Tilera hypervisor
230 * in versions 4.3.4 and following.
231 */
232 if (hv_send_message(&recip, 1, (HV_VirtAddr)&tag, sizeof(tag)) == 1)
233 self_interrupt_ok = true;
234 else
235 pr_warn("Older hypervisor: disabling fast irq_work_raise\n");
236
237#if CHIP_HAS_IPI()
238 /* Map IPI trigger MMIO addresses. */
239 for_each_possible_cpu(cpu) {
240 HV_Coord tile;
241 HV_PTE pte;
242 unsigned long offset;
243
244 tile.x = cpu_x(cpu);
245 tile.y = cpu_y(cpu);
246 if (hv_get_ipi_pte(tile, KERNEL_PL, &pte) != 0)
247 panic("Failed to initialize IPI for cpu %d\n", cpu);
248
249 offset = PFN_PHYS(pte_pfn(pte));
250 ipi_mappings[cpu] = ioremap_prot(offset, PAGE_SIZE, pte);
251 }
252#endif
253
254 /* Bind handle_reschedule_ipi() to IRQ_RESCHEDULE. */
255 tile_irq_activate(IRQ_RESCHEDULE, TILE_IRQ_PERCPU);
256 BUG_ON(setup_irq(IRQ_RESCHEDULE, &resched_action));
257}
258
259#if CHIP_HAS_IPI()
260
261void smp_send_reschedule(int cpu)
262{
263 WARN_ON(cpu_is_offline(cpu));
264
265 /*
266 * We just want to do an MMIO store. The traditional writeq()
267 * functions aren't really correct here, since they're always
268 * directed at the PCI shim. For now, just do a raw store,
269 * casting away the __iomem attribute.
270 */
271 ((unsigned long __force *)ipi_mappings[cpu])[IRQ_RESCHEDULE] = 0;
272}
273
274#else
275
276void smp_send_reschedule(int cpu)
277{
278 HV_Coord coord;
279
280 WARN_ON(cpu_is_offline(cpu));
281
282 coord.y = cpu_y(cpu);
283 coord.x = cpu_x(cpu);
284 hv_trigger_ipi(coord, IRQ_RESCHEDULE);
285}
286
287#endif /* CHIP_HAS_IPI() */
diff --git a/arch/tile/kernel/smpboot.c b/arch/tile/kernel/smpboot.c
deleted file mode 100644
index 869c22e57561..000000000000
--- a/arch/tile/kernel/smpboot.c
+++ /dev/null
@@ -1,269 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/sched/mm.h>
20#include <linux/sched/task.h>
21#include <linux/kernel_stat.h>
22#include <linux/bootmem.h>
23#include <linux/notifier.h>
24#include <linux/cpu.h>
25#include <linux/percpu.h>
26#include <linux/delay.h>
27#include <linux/err.h>
28#include <linux/irq.h>
29#include <asm/mmu_context.h>
30#include <asm/tlbflush.h>
31#include <asm/sections.h>
32
33/* State of each CPU. */
34static DEFINE_PER_CPU(int, cpu_state) = { 0 };
35
36/* The messaging code jumps to this pointer during boot-up */
37unsigned long start_cpu_function_addr;
38
39/* Called very early during startup to mark boot cpu as online */
40void __init smp_prepare_boot_cpu(void)
41{
42 int cpu = smp_processor_id();
43 set_cpu_online(cpu, 1);
44 set_cpu_present(cpu, 1);
45 __this_cpu_write(cpu_state, CPU_ONLINE);
46
47 init_messaging();
48}
49
50static void start_secondary(void);
51
52/*
53 * Called at the top of init() to launch all the other CPUs.
54 * They run free to complete their initialization and then wait
55 * until they get an IPI from the boot cpu to come online.
56 */
57void __init smp_prepare_cpus(unsigned int max_cpus)
58{
59 long rc;
60 int cpu, cpu_count;
61 int boot_cpu = smp_processor_id();
62
63 current_thread_info()->cpu = boot_cpu;
64
65 /*
66 * Pin this task to the boot CPU while we bring up the others,
67 * just to make sure we don't uselessly migrate as they come up.
68 */
69 rc = sched_setaffinity(current->pid, cpumask_of(boot_cpu));
70 if (rc != 0)
71 pr_err("Couldn't set init affinity to boot cpu (%ld)\n", rc);
72
73 /* Print information about disabled and dataplane cpus. */
74 print_disabled_cpus();
75
76 /*
77 * Tell the messaging subsystem how to respond to the
78 * startup message. We use a level of indirection to avoid
79 * confusing the linker with the fact that the messaging
80 * subsystem is calling __init code.
81 */
82 start_cpu_function_addr = (unsigned long) &online_secondary;
83
84 /* Set up thread context for all new processors. */
85 cpu_count = 1;
86 for (cpu = 0; cpu < NR_CPUS; ++cpu) {
87 struct task_struct *idle;
88
89 if (cpu == boot_cpu)
90 continue;
91
92 if (!cpu_possible(cpu)) {
93 /*
94 * Make this processor do nothing on boot.
95 * Note that we don't give the boot_pc function
96 * a stack, so it has to be assembly code.
97 */
98 per_cpu(boot_sp, cpu) = 0;
99 per_cpu(boot_pc, cpu) = (unsigned long) smp_nap;
100 continue;
101 }
102
103 /* Create a new idle thread to run start_secondary() */
104 idle = fork_idle(cpu);
105 if (IS_ERR(idle))
106 panic("failed fork for CPU %d", cpu);
107 idle->thread.pc = (unsigned long) start_secondary;
108
109 /* Make this thread the boot thread for this processor */
110 per_cpu(boot_sp, cpu) = task_ksp0(idle);
111 per_cpu(boot_pc, cpu) = idle->thread.pc;
112
113 ++cpu_count;
114 }
115 BUG_ON(cpu_count > (max_cpus ? max_cpus : 1));
116
117 /* Fire up the other tiles, if any */
118 init_cpu_present(cpu_possible_mask);
119 if (cpumask_weight(cpu_present_mask) > 1) {
120 mb(); /* make sure all data is visible to new processors */
121 hv_start_all_tiles();
122 }
123}
124
125static __initdata struct cpumask init_affinity;
126
127static __init int reset_init_affinity(void)
128{
129 long rc = sched_setaffinity(current->pid, &init_affinity);
130 if (rc != 0)
131 pr_warn("couldn't reset init affinity (%ld)\n", rc);
132 return 0;
133}
134late_initcall(reset_init_affinity);
135
136static struct cpumask cpu_started;
137
138/*
139 * Activate a secondary processor. Very minimal; don't add anything
140 * to this path without knowing what you're doing, since SMP booting
141 * is pretty fragile.
142 */
143static void start_secondary(void)
144{
145 int cpuid;
146
147 preempt_disable();
148
149 cpuid = smp_processor_id();
150
151 /* Set our thread pointer appropriately. */
152 set_my_cpu_offset(__per_cpu_offset[cpuid]);
153
154 /*
155 * In large machines even this will slow us down, since we
156 * will be contending for for the printk spinlock.
157 */
158 /* printk(KERN_DEBUG "Initializing CPU#%d\n", cpuid); */
159
160 /* Initialize the current asid for our first page table. */
161 __this_cpu_write(current_asid, min_asid);
162
163 /* Set up this thread as another owner of the init_mm */
164 mmgrab(&init_mm);
165 current->active_mm = &init_mm;
166 if (current->mm)
167 BUG();
168 enter_lazy_tlb(&init_mm, current);
169
170 /* Allow hypervisor messages to be received */
171 init_messaging();
172 local_irq_enable();
173
174 /* Indicate that we're ready to come up. */
175 /* Must not do this before we're ready to receive messages */
176 if (cpumask_test_and_set_cpu(cpuid, &cpu_started)) {
177 pr_warn("CPU#%d already started!\n", cpuid);
178 for (;;)
179 local_irq_enable();
180 }
181
182 smp_nap();
183}
184
185/*
186 * Bring a secondary processor online.
187 */
188void online_secondary(void)
189{
190 /*
191 * low-memory mappings have been cleared, flush them from
192 * the local TLBs too.
193 */
194 local_flush_tlb();
195
196 BUG_ON(in_interrupt());
197
198 /* This must be done before setting cpu_online_mask */
199 wmb();
200
201 notify_cpu_starting(smp_processor_id());
202
203 set_cpu_online(smp_processor_id(), 1);
204 __this_cpu_write(cpu_state, CPU_ONLINE);
205
206 /* Set up tile-specific state for this cpu. */
207 setup_cpu(0);
208
209 /* Set up tile-timer clock-event device on this cpu */
210 setup_tile_timer();
211
212 cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
213}
214
215int __cpu_up(unsigned int cpu, struct task_struct *tidle)
216{
217 /* Wait 5s total for all CPUs for them to come online */
218 static int timeout;
219 for (; !cpumask_test_cpu(cpu, &cpu_started); timeout++) {
220 if (timeout >= 50000) {
221 pr_info("skipping unresponsive cpu%d\n", cpu);
222 local_irq_enable();
223 return -EIO;
224 }
225 udelay(100);
226 }
227
228 local_irq_enable();
229 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
230
231 /* Unleash the CPU! */
232 send_IPI_single(cpu, MSG_TAG_START_CPU);
233 while (!cpumask_test_cpu(cpu, cpu_online_mask))
234 cpu_relax();
235 return 0;
236}
237
238static void panic_start_cpu(void)
239{
240 panic("Received a MSG_START_CPU IPI after boot finished.");
241}
242
243void __init smp_cpus_done(unsigned int max_cpus)
244{
245 int cpu, next, rc;
246
247 /* Reset the response to a (now illegal) MSG_START_CPU IPI. */
248 start_cpu_function_addr = (unsigned long) &panic_start_cpu;
249
250 cpumask_copy(&init_affinity, cpu_online_mask);
251
252 /*
253 * Pin ourselves to a single cpu in the initial affinity set
254 * so that kernel mappings for the rootfs are not in the dataplane,
255 * if set, and to avoid unnecessary migrating during bringup.
256 * Use the last cpu just in case the whole chip has been
257 * isolated from the scheduler, to keep init away from likely
258 * more useful user code. This also ensures that work scheduled
259 * via schedule_delayed_work() in the init routines will land
260 * on this cpu.
261 */
262 for (cpu = cpumask_first(&init_affinity);
263 (next = cpumask_next(cpu, &init_affinity)) < nr_cpu_ids;
264 cpu = next)
265 ;
266 rc = sched_setaffinity(current->pid, cpumask_of(cpu));
267 if (rc != 0)
268 pr_err("Couldn't set init affinity to cpu %d (%d)\n", cpu, rc);
269}
diff --git a/arch/tile/kernel/stack.c b/arch/tile/kernel/stack.c
deleted file mode 100644
index 94ecbc6676e5..000000000000
--- a/arch/tile/kernel/stack.c
+++ /dev/null
@@ -1,539 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/sched.h>
16#include <linux/sched/debug.h>
17#include <linux/sched/task_stack.h>
18#include <linux/kernel.h>
19#include <linux/kprobes.h>
20#include <linux/module.h>
21#include <linux/pfn.h>
22#include <linux/kallsyms.h>
23#include <linux/stacktrace.h>
24#include <linux/uaccess.h>
25#include <linux/mmzone.h>
26#include <linux/dcache.h>
27#include <linux/fs.h>
28#include <linux/hardirq.h>
29#include <linux/string.h>
30#include <asm/backtrace.h>
31#include <asm/page.h>
32#include <asm/ucontext.h>
33#include <asm/switch_to.h>
34#include <asm/sigframe.h>
35#include <asm/stack.h>
36#include <asm/vdso.h>
37#include <arch/abi.h>
38#include <arch/interrupts.h>
39
40#define KBT_ONGOING 0 /* Backtrace still ongoing */
41#define KBT_DONE 1 /* Backtrace cleanly completed */
42#define KBT_RUNNING 2 /* Can't run backtrace on a running task */
43#define KBT_LOOP 3 /* Backtrace entered a loop */
44
45/* Is address on the specified kernel stack? */
46static int in_kernel_stack(struct KBacktraceIterator *kbt, unsigned long sp)
47{
48 ulong kstack_base = (ulong) kbt->task->stack;
49 if (kstack_base == 0) /* corrupt task pointer; just follow stack... */
50 return sp >= PAGE_OFFSET && sp < (unsigned long)high_memory;
51 return sp >= kstack_base && sp < kstack_base + THREAD_SIZE;
52}
53
54/* Callback for backtracer; basically a glorified memcpy */
55static bool read_memory_func(void *result, unsigned long address,
56 unsigned int size, void *vkbt)
57{
58 int retval;
59 struct KBacktraceIterator *kbt = (struct KBacktraceIterator *)vkbt;
60
61 if (address == 0)
62 return 0;
63 if (__kernel_text_address(address)) {
64 /* OK to read kernel code. */
65 } else if (address >= PAGE_OFFSET) {
66 /* We only tolerate kernel-space reads of this task's stack */
67 if (!in_kernel_stack(kbt, address))
68 return 0;
69 } else if (!kbt->is_current) {
70 return 0; /* can't read from other user address spaces */
71 }
72 pagefault_disable();
73 retval = __copy_from_user_inatomic(result,
74 (void __user __force *)address,
75 size);
76 pagefault_enable();
77 return (retval == 0);
78}
79
80/* Return a pt_regs pointer for a valid fault handler frame */
81static struct pt_regs *valid_fault_handler(struct KBacktraceIterator* kbt)
82{
83 char fault[64];
84 unsigned long sp = kbt->it.sp;
85 struct pt_regs *p;
86
87 if (sp % sizeof(long) != 0)
88 return NULL;
89 if (!in_kernel_stack(kbt, sp))
90 return NULL;
91 if (!in_kernel_stack(kbt, sp + C_ABI_SAVE_AREA_SIZE + PTREGS_SIZE-1))
92 return NULL;
93 p = (struct pt_regs *)(sp + C_ABI_SAVE_AREA_SIZE);
94 if (kbt->verbose) { /* else we aren't going to use it */
95 if (p->faultnum == INT_SWINT_1 ||
96 p->faultnum == INT_SWINT_1_SIGRETURN)
97 snprintf(fault, sizeof(fault),
98 "syscall %ld", p->regs[TREG_SYSCALL_NR]);
99 else
100 snprintf(fault, sizeof(fault),
101 "interrupt %ld", p->faultnum);
102 }
103 if (EX1_PL(p->ex1) == KERNEL_PL &&
104 __kernel_text_address(p->pc) &&
105 in_kernel_stack(kbt, p->sp) &&
106 p->sp >= sp) {
107 if (kbt->verbose)
108 pr_err(" <%s while in kernel mode>\n", fault);
109 } else if (user_mode(p) &&
110 p->sp < PAGE_OFFSET && p->sp != 0) {
111 if (kbt->verbose)
112 pr_err(" <%s while in user mode>\n", fault);
113 } else {
114 if (kbt->verbose && (p->pc != 0 || p->sp != 0 || p->ex1 != 0))
115 pr_err(" (odd fault: pc %#lx, sp %#lx, ex1 %#lx?)\n",
116 p->pc, p->sp, p->ex1);
117 return NULL;
118 }
119 if (kbt->profile && ((1ULL << p->faultnum) & QUEUED_INTERRUPTS) != 0)
120 return NULL;
121 return p;
122}
123
124/* Is the iterator pointing to a sigreturn trampoline? */
125static int is_sigreturn(struct KBacktraceIterator *kbt)
126{
127 return kbt->task->mm &&
128 (kbt->it.pc == ((ulong)kbt->task->mm->context.vdso_base +
129 (ulong)&__vdso_rt_sigreturn));
130}
131
132/* Return a pt_regs pointer for a valid signal handler frame */
133static struct pt_regs *valid_sigframe(struct KBacktraceIterator* kbt,
134 struct rt_sigframe* kframe)
135{
136 BacktraceIterator *b = &kbt->it;
137
138 if (is_sigreturn(kbt) && b->sp < PAGE_OFFSET &&
139 b->sp % sizeof(long) == 0) {
140 int retval;
141 pagefault_disable();
142 retval = __copy_from_user_inatomic(
143 kframe, (void __user __force *)b->sp,
144 sizeof(*kframe));
145 pagefault_enable();
146 if (retval != 0 ||
147 (unsigned int)(kframe->info.si_signo) >= _NSIG)
148 return NULL;
149 if (kbt->verbose) {
150 pr_err(" <received signal %d>\n",
151 kframe->info.si_signo);
152 }
153 return (struct pt_regs *)&kframe->uc.uc_mcontext;
154 }
155 return NULL;
156}
157
158static int KBacktraceIterator_restart(struct KBacktraceIterator *kbt)
159{
160 struct pt_regs *p;
161 struct rt_sigframe kframe;
162
163 p = valid_fault_handler(kbt);
164 if (p == NULL)
165 p = valid_sigframe(kbt, &kframe);
166 if (p == NULL)
167 return 0;
168 backtrace_init(&kbt->it, read_memory_func, kbt,
169 p->pc, p->lr, p->sp, p->regs[52]);
170 kbt->new_context = 1;
171 return 1;
172}
173
174/* Find a frame that isn't a sigreturn, if there is one. */
175static int KBacktraceIterator_next_item_inclusive(
176 struct KBacktraceIterator *kbt)
177{
178 for (;;) {
179 do {
180 if (!is_sigreturn(kbt))
181 return KBT_ONGOING;
182 } while (backtrace_next(&kbt->it));
183
184 if (!KBacktraceIterator_restart(kbt))
185 return KBT_DONE;
186 }
187}
188
189/*
190 * If the current sp is on a page different than what we recorded
191 * as the top-of-kernel-stack last time we context switched, we have
192 * probably blown the stack, and nothing is going to work out well.
193 * If we can at least get out a warning, that may help the debug,
194 * though we probably won't be able to backtrace into the code that
195 * actually did the recursive damage.
196 */
197static void validate_stack(struct pt_regs *regs)
198{
199 int cpu = raw_smp_processor_id();
200 unsigned long ksp0 = get_current_ksp0();
201 unsigned long ksp0_base = ksp0 & -THREAD_SIZE;
202 unsigned long sp = stack_pointer;
203
204 if (EX1_PL(regs->ex1) == KERNEL_PL && regs->sp >= ksp0) {
205 pr_err("WARNING: cpu %d: kernel stack %#lx..%#lx underrun!\n"
206 " sp %#lx (%#lx in caller), caller pc %#lx, lr %#lx\n",
207 cpu, ksp0_base, ksp0, sp, regs->sp, regs->pc, regs->lr);
208 }
209
210 else if (sp < ksp0_base + sizeof(struct thread_info)) {
211 pr_err("WARNING: cpu %d: kernel stack %#lx..%#lx overrun!\n"
212 " sp %#lx (%#lx in caller), caller pc %#lx, lr %#lx\n",
213 cpu, ksp0_base, ksp0, sp, regs->sp, regs->pc, regs->lr);
214 }
215}
216
217void KBacktraceIterator_init(struct KBacktraceIterator *kbt,
218 struct task_struct *t, struct pt_regs *regs)
219{
220 unsigned long pc, lr, sp, r52;
221 int is_current;
222
223 /*
224 * Set up callback information. We grab the kernel stack base
225 * so we will allow reads of that address range.
226 */
227 is_current = (t == NULL || t == current);
228 kbt->is_current = is_current;
229 if (is_current)
230 t = validate_current();
231 kbt->task = t;
232 kbt->verbose = 0; /* override in caller if desired */
233 kbt->profile = 0; /* override in caller if desired */
234 kbt->end = KBT_ONGOING;
235 kbt->new_context = 1;
236 if (is_current)
237 validate_stack(regs);
238
239 if (regs == NULL) {
240 if (is_current || t->state == TASK_RUNNING) {
241 /* Can't do this; we need registers */
242 kbt->end = KBT_RUNNING;
243 return;
244 }
245 pc = get_switch_to_pc();
246 lr = t->thread.pc;
247 sp = t->thread.ksp;
248 r52 = 0;
249 } else {
250 pc = regs->pc;
251 lr = regs->lr;
252 sp = regs->sp;
253 r52 = regs->regs[52];
254 }
255
256 backtrace_init(&kbt->it, read_memory_func, kbt, pc, lr, sp, r52);
257 kbt->end = KBacktraceIterator_next_item_inclusive(kbt);
258}
259EXPORT_SYMBOL(KBacktraceIterator_init);
260
261int KBacktraceIterator_end(struct KBacktraceIterator *kbt)
262{
263 return kbt->end != KBT_ONGOING;
264}
265EXPORT_SYMBOL(KBacktraceIterator_end);
266
267void KBacktraceIterator_next(struct KBacktraceIterator *kbt)
268{
269 unsigned long old_pc = kbt->it.pc, old_sp = kbt->it.sp;
270 kbt->new_context = 0;
271 if (!backtrace_next(&kbt->it) && !KBacktraceIterator_restart(kbt)) {
272 kbt->end = KBT_DONE;
273 return;
274 }
275 kbt->end = KBacktraceIterator_next_item_inclusive(kbt);
276 if (old_pc == kbt->it.pc && old_sp == kbt->it.sp) {
277 /* Trapped in a loop; give up. */
278 kbt->end = KBT_LOOP;
279 }
280}
281EXPORT_SYMBOL(KBacktraceIterator_next);
282
283static void describe_addr(struct KBacktraceIterator *kbt,
284 unsigned long address,
285 int have_mmap_sem, char *buf, size_t bufsize)
286{
287 struct vm_area_struct *vma;
288 size_t namelen, remaining;
289 unsigned long size, offset, adjust;
290 char *p, *modname;
291 const char *name;
292 int rc;
293
294 /*
295 * Look one byte back for every caller frame (i.e. those that
296 * aren't a new context) so we look up symbol data for the
297 * call itself, not the following instruction, which may be on
298 * a different line (or in a different function).
299 */
300 adjust = !kbt->new_context;
301 address -= adjust;
302
303 if (address >= PAGE_OFFSET) {
304 /* Handle kernel symbols. */
305 BUG_ON(bufsize < KSYM_NAME_LEN);
306 name = kallsyms_lookup(address, &size, &offset,
307 &modname, buf);
308 if (name == NULL) {
309 buf[0] = '\0';
310 return;
311 }
312 namelen = strlen(buf);
313 remaining = (bufsize - 1) - namelen;
314 p = buf + namelen;
315 rc = snprintf(p, remaining, "+%#lx/%#lx ",
316 offset + adjust, size);
317 if (modname && rc < remaining)
318 snprintf(p + rc, remaining - rc, "[%s] ", modname);
319 buf[bufsize-1] = '\0';
320 return;
321 }
322
323 /* If we don't have the mmap_sem, we can't show any more info. */
324 buf[0] = '\0';
325 if (!have_mmap_sem)
326 return;
327
328 /* Find vma info. */
329 vma = find_vma(kbt->task->mm, address);
330 if (vma == NULL || address < vma->vm_start) {
331 snprintf(buf, bufsize, "[unmapped address] ");
332 return;
333 }
334
335 if (vma->vm_file) {
336 p = file_path(vma->vm_file, buf, bufsize);
337 if (IS_ERR(p))
338 p = "?";
339 name = kbasename(p);
340 } else {
341 name = "anon";
342 }
343
344 /* Generate a string description of the vma info. */
345 namelen = strlen(name);
346 remaining = (bufsize - 1) - namelen;
347 memmove(buf, name, namelen);
348 snprintf(buf + namelen, remaining, "[%lx+%lx] ",
349 vma->vm_start, vma->vm_end - vma->vm_start);
350}
351
352/*
353 * Avoid possible crash recursion during backtrace. If it happens, it
354 * makes it easy to lose the actual root cause of the failure, so we
355 * put a simple guard on all the backtrace loops.
356 */
357static bool start_backtrace(void)
358{
359 if (current_thread_info()->in_backtrace) {
360 pr_err("Backtrace requested while in backtrace!\n");
361 return false;
362 }
363 current_thread_info()->in_backtrace = true;
364 return true;
365}
366
367static void end_backtrace(void)
368{
369 current_thread_info()->in_backtrace = false;
370}
371
372/*
373 * This method wraps the backtracer's more generic support.
374 * It is only invoked from the architecture-specific code; show_stack()
375 * and dump_stack() are architecture-independent entry points.
376 */
377void tile_show_stack(struct KBacktraceIterator *kbt)
378{
379 int i;
380 int have_mmap_sem = 0;
381
382 if (!start_backtrace())
383 return;
384 kbt->verbose = 1;
385 i = 0;
386 for (; !KBacktraceIterator_end(kbt); KBacktraceIterator_next(kbt)) {
387 char namebuf[KSYM_NAME_LEN+100];
388 unsigned long address = kbt->it.pc;
389
390 /*
391 * Try to acquire the mmap_sem as we pass into userspace.
392 * If we're in an interrupt context, don't even try, since
393 * it's not safe to call e.g. d_path() from an interrupt,
394 * since it uses spin locks without disabling interrupts.
395 * Note we test "kbt->task == current", not "kbt->is_current",
396 * since we're checking that "current" will work in d_path().
397 */
398 if (kbt->task == current && address < PAGE_OFFSET &&
399 !have_mmap_sem && kbt->task->mm && !in_interrupt()) {
400 have_mmap_sem =
401 down_read_trylock(&kbt->task->mm->mmap_sem);
402 }
403
404 describe_addr(kbt, address, have_mmap_sem,
405 namebuf, sizeof(namebuf));
406
407 pr_err(" frame %d: 0x%lx %s(sp 0x%lx)\n",
408 i++, address, namebuf, (unsigned long)(kbt->it.sp));
409
410 if (i >= 100) {
411 pr_err("Stack dump truncated (%d frames)\n", i);
412 break;
413 }
414 }
415 if (kbt->end == KBT_LOOP)
416 pr_err("Stack dump stopped; next frame identical to this one\n");
417 if (have_mmap_sem)
418 up_read(&kbt->task->mm->mmap_sem);
419 end_backtrace();
420}
421EXPORT_SYMBOL(tile_show_stack);
422
423static struct pt_regs *regs_to_pt_regs(struct pt_regs *regs,
424 ulong pc, ulong lr, ulong sp, ulong r52)
425{
426 memset(regs, 0, sizeof(struct pt_regs));
427 regs->pc = pc;
428 regs->lr = lr;
429 regs->sp = sp;
430 regs->regs[52] = r52;
431 return regs;
432}
433
434/* Deprecated function currently only used by kernel_double_fault(). */
435void _dump_stack(int dummy, ulong pc, ulong lr, ulong sp, ulong r52)
436{
437 struct KBacktraceIterator kbt;
438 struct pt_regs regs;
439
440 regs_to_pt_regs(&regs, pc, lr, sp, r52);
441 KBacktraceIterator_init(&kbt, NULL, &regs);
442 tile_show_stack(&kbt);
443}
444
445/* This is called from KBacktraceIterator_init_current() */
446void _KBacktraceIterator_init_current(struct KBacktraceIterator *kbt, ulong pc,
447 ulong lr, ulong sp, ulong r52)
448{
449 struct pt_regs regs;
450 KBacktraceIterator_init(kbt, NULL,
451 regs_to_pt_regs(&regs, pc, lr, sp, r52));
452}
453
454/*
455 * Called from sched_show_task() with task != NULL, or dump_stack()
456 * with task == NULL. The esp argument is always NULL.
457 */
458void show_stack(struct task_struct *task, unsigned long *esp)
459{
460 struct KBacktraceIterator kbt;
461 if (task == NULL || task == current) {
462 KBacktraceIterator_init_current(&kbt);
463 KBacktraceIterator_next(&kbt); /* don't show first frame */
464 } else {
465 KBacktraceIterator_init(&kbt, task, NULL);
466 }
467 tile_show_stack(&kbt);
468}
469
470#ifdef CONFIG_STACKTRACE
471
472/* Support generic Linux stack API too */
473
474static void save_stack_trace_common(struct task_struct *task,
475 struct pt_regs *regs,
476 bool user,
477 struct stack_trace *trace)
478{
479 struct KBacktraceIterator kbt;
480 int skip = trace->skip;
481 int i = 0;
482
483 if (!start_backtrace())
484 goto done;
485 if (regs != NULL) {
486 KBacktraceIterator_init(&kbt, NULL, regs);
487 } else if (task == NULL || task == current) {
488 KBacktraceIterator_init_current(&kbt);
489 skip++; /* don't show KBacktraceIterator_init_current */
490 } else {
491 KBacktraceIterator_init(&kbt, task, NULL);
492 }
493 for (; !KBacktraceIterator_end(&kbt); KBacktraceIterator_next(&kbt)) {
494 if (skip) {
495 --skip;
496 continue;
497 }
498 if (i >= trace->max_entries ||
499 (!user && kbt.it.pc < PAGE_OFFSET))
500 break;
501 trace->entries[i++] = kbt.it.pc;
502 }
503 end_backtrace();
504done:
505 if (i < trace->max_entries)
506 trace->entries[i++] = ULONG_MAX;
507 trace->nr_entries = i;
508}
509
510void save_stack_trace_tsk(struct task_struct *task, struct stack_trace *trace)
511{
512 save_stack_trace_common(task, NULL, false, trace);
513}
514EXPORT_SYMBOL(save_stack_trace_tsk);
515
516void save_stack_trace(struct stack_trace *trace)
517{
518 save_stack_trace_common(NULL, NULL, false, trace);
519}
520EXPORT_SYMBOL_GPL(save_stack_trace);
521
522void save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
523{
524 save_stack_trace_common(NULL, regs, false, trace);
525}
526
527void save_stack_trace_user(struct stack_trace *trace)
528{
529 /* Trace user stack if we are not a kernel thread. */
530 if (current->mm)
531 save_stack_trace_common(NULL, task_pt_regs(current),
532 true, trace);
533 else if (trace->nr_entries < trace->max_entries)
534 trace->entries[trace->nr_entries++] = ULONG_MAX;
535}
536#endif
537
538/* In entry.S */
539EXPORT_SYMBOL(KBacktraceIterator_init_current);
diff --git a/arch/tile/kernel/sys.c b/arch/tile/kernel/sys.c
deleted file mode 100644
index c7418dcbbb08..000000000000
--- a/arch/tile/kernel/sys.c
+++ /dev/null
@@ -1,130 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * This file contains various random system calls that
15 * have a non-standard calling sequence on the Linux/TILE
16 * platform.
17 */
18
19#include <linux/errno.h>
20#include <linux/sched.h>
21#include <linux/mm.h>
22#include <linux/smp.h>
23#include <linux/syscalls.h>
24#include <linux/mman.h>
25#include <linux/file.h>
26#include <linux/mempolicy.h>
27#include <linux/binfmts.h>
28#include <linux/fs.h>
29#include <linux/compat.h>
30#include <linux/uaccess.h>
31#include <linux/signal.h>
32#include <asm/syscalls.h>
33#include <asm/pgtable.h>
34#include <asm/homecache.h>
35#include <asm/cachectl.h>
36#include <asm/byteorder.h>
37#include <arch/chip.h>
38
39SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, len,
40 unsigned long, flags)
41{
42 /* DCACHE is not particularly effective if not bound to one cpu. */
43 if (flags & DCACHE)
44 homecache_evict(cpumask_of(raw_smp_processor_id()));
45
46 if (flags & ICACHE)
47 flush_remote(0, HV_FLUSH_EVICT_L1I, mm_cpumask(current->mm),
48 0, 0, 0, NULL, NULL, 0);
49 return 0;
50}
51
52/*
53 * Syscalls that pass 64-bit values on 32-bit systems normally
54 * pass them as (low,high) word packed into the immediately adjacent
55 * registers. If the low word naturally falls on an even register,
56 * our ABI makes it work correctly; if not, we adjust it here.
57 * Handling it here means we don't have to fix uclibc AND glibc AND
58 * any other standard libcs we want to support.
59 */
60
61#if !defined(__tilegx__) || defined(CONFIG_COMPAT)
62
63#ifdef __BIG_ENDIAN
64#define SYSCALL_PAIR(name) u32 name ## _hi, u32 name ## _lo
65#else
66#define SYSCALL_PAIR(name) u32 name ## _lo, u32 name ## _hi
67#endif
68
69ssize_t sys32_readahead(int fd, SYSCALL_PAIR(offset), u32 count)
70{
71 return sys_readahead(fd, ((loff_t)offset_hi << 32) | offset_lo, count);
72}
73
74int sys32_fadvise64_64(int fd, SYSCALL_PAIR(offset),
75 SYSCALL_PAIR(len), int advice)
76{
77 return sys_fadvise64_64(fd, ((loff_t)offset_hi << 32) | offset_lo,
78 ((loff_t)len_hi << 32) | len_lo, advice);
79}
80
81#endif /* 32-bit syscall wrappers */
82
83/* Note: used by the compat code even in 64-bit Linux. */
84SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
85 unsigned long, prot, unsigned long, flags,
86 unsigned long, fd, unsigned long, off_4k)
87{
88#define PAGE_ADJUST (PAGE_SHIFT - 12)
89 if (off_4k & ((1 << PAGE_ADJUST) - 1))
90 return -EINVAL;
91 return sys_mmap_pgoff(addr, len, prot, flags, fd,
92 off_4k >> PAGE_ADJUST);
93}
94
95#ifdef __tilegx__
96SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
97 unsigned long, prot, unsigned long, flags,
98 unsigned long, fd, off_t, offset)
99{
100 if (offset & ((1 << PAGE_SHIFT) - 1))
101 return -EINVAL;
102 return sys_mmap_pgoff(addr, len, prot, flags, fd,
103 offset >> PAGE_SHIFT);
104}
105#endif
106
107
108/* Provide the actual syscall number to call mapping. */
109#undef __SYSCALL
110#define __SYSCALL(nr, call) [nr] = (call),
111
112#ifndef __tilegx__
113/* See comments at the top of the file. */
114#define sys_fadvise64_64 sys32_fadvise64_64
115#define sys_readahead sys32_readahead
116#endif
117
118/* Call the assembly trampolines where necessary. */
119#undef sys_rt_sigreturn
120#define sys_rt_sigreturn _sys_rt_sigreturn
121#define sys_clone _sys_clone
122
123/*
124 * Note that we can't include <linux/unistd.h> here since the header
125 * guard will defeat us; <asm/unistd.h> checks for __SYSCALL as well.
126 */
127void *sys_call_table[__NR_syscalls] = {
128 [0 ... __NR_syscalls-1] = sys_ni_syscall,
129#include <asm/unistd.h>
130};
diff --git a/arch/tile/kernel/sysfs.c b/arch/tile/kernel/sysfs.c
deleted file mode 100644
index b09456a3d77a..000000000000
--- a/arch/tile/kernel/sysfs.c
+++ /dev/null
@@ -1,266 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * /sys entry support.
15 */
16
17#include <linux/device.h>
18#include <linux/cpu.h>
19#include <linux/slab.h>
20#include <linux/smp.h>
21#include <linux/stat.h>
22#include <hv/hypervisor.h>
23
24/* Return a string queried from the hypervisor, truncated to page size. */
25static ssize_t get_hv_confstr(char *page, int query)
26{
27 ssize_t n = hv_confstr(query, (unsigned long)page, PAGE_SIZE - 1);
28 n = n < 0 ? 0 : min(n, (ssize_t)PAGE_SIZE - 1) - 1;
29 if (n)
30 page[n++] = '\n';
31 page[n] = '\0';
32 return n;
33}
34
35static ssize_t chip_width_show(struct device *dev,
36 struct device_attribute *attr,
37 char *page)
38{
39 return sprintf(page, "%u\n", smp_width);
40}
41static DEVICE_ATTR_RO(chip_width);
42
43static ssize_t chip_height_show(struct device *dev,
44 struct device_attribute *attr,
45 char *page)
46{
47 return sprintf(page, "%u\n", smp_height);
48}
49static DEVICE_ATTR_RO(chip_height);
50
51static ssize_t chip_serial_show(struct device *dev,
52 struct device_attribute *attr,
53 char *page)
54{
55 return get_hv_confstr(page, HV_CONFSTR_CHIP_SERIAL_NUM);
56}
57static DEVICE_ATTR_RO(chip_serial);
58
59static ssize_t chip_revision_show(struct device *dev,
60 struct device_attribute *attr,
61 char *page)
62{
63 return get_hv_confstr(page, HV_CONFSTR_CHIP_REV);
64}
65static DEVICE_ATTR_RO(chip_revision);
66
67
68static ssize_t type_show(struct device *dev,
69 struct device_attribute *attr,
70 char *page)
71{
72 return sprintf(page, "tilera\n");
73}
74static DEVICE_ATTR_RO(type);
75
76#define HV_CONF_ATTR(name, conf) \
77 static ssize_t name ## _show(struct device *dev, \
78 struct device_attribute *attr, \
79 char *page) \
80 { \
81 return get_hv_confstr(page, conf); \
82 } \
83 static DEVICE_ATTR(name, 0444, name ## _show, NULL);
84
85HV_CONF_ATTR(version, HV_CONFSTR_HV_SW_VER)
86HV_CONF_ATTR(config_version, HV_CONFSTR_HV_CONFIG_VER)
87
88HV_CONF_ATTR(board_part, HV_CONFSTR_BOARD_PART_NUM)
89HV_CONF_ATTR(board_serial, HV_CONFSTR_BOARD_SERIAL_NUM)
90HV_CONF_ATTR(board_revision, HV_CONFSTR_BOARD_REV)
91HV_CONF_ATTR(board_description, HV_CONFSTR_BOARD_DESC)
92HV_CONF_ATTR(mezz_part, HV_CONFSTR_MEZZ_PART_NUM)
93HV_CONF_ATTR(mezz_serial, HV_CONFSTR_MEZZ_SERIAL_NUM)
94HV_CONF_ATTR(mezz_revision, HV_CONFSTR_MEZZ_REV)
95HV_CONF_ATTR(mezz_description, HV_CONFSTR_MEZZ_DESC)
96HV_CONF_ATTR(cpumod_part, HV_CONFSTR_CPUMOD_PART_NUM)
97HV_CONF_ATTR(cpumod_serial, HV_CONFSTR_CPUMOD_SERIAL_NUM)
98HV_CONF_ATTR(cpumod_revision, HV_CONFSTR_CPUMOD_REV)
99HV_CONF_ATTR(cpumod_description,HV_CONFSTR_CPUMOD_DESC)
100HV_CONF_ATTR(switch_control, HV_CONFSTR_SWITCH_CONTROL)
101
102static struct attribute *board_attrs[] = {
103 &dev_attr_board_part.attr,
104 &dev_attr_board_serial.attr,
105 &dev_attr_board_revision.attr,
106 &dev_attr_board_description.attr,
107 &dev_attr_mezz_part.attr,
108 &dev_attr_mezz_serial.attr,
109 &dev_attr_mezz_revision.attr,
110 &dev_attr_mezz_description.attr,
111 &dev_attr_cpumod_part.attr,
112 &dev_attr_cpumod_serial.attr,
113 &dev_attr_cpumod_revision.attr,
114 &dev_attr_cpumod_description.attr,
115 &dev_attr_switch_control.attr,
116 NULL
117};
118
119static struct attribute_group board_attr_group = {
120 .name = "board",
121 .attrs = board_attrs,
122};
123
124
125static struct bin_attribute hvconfig_bin;
126
127static ssize_t
128hvconfig_bin_read(struct file *filp, struct kobject *kobj,
129 struct bin_attribute *bin_attr,
130 char *buf, loff_t off, size_t count)
131{
132 static size_t size;
133
134 /* Lazily learn the true size (minus the trailing NUL). */
135 if (size == 0)
136 size = hv_confstr(HV_CONFSTR_HV_CONFIG, 0, 0) - 1;
137
138 /* Check and adjust input parameters. */
139 if (off > size)
140 return -EINVAL;
141 if (count > size - off)
142 count = size - off;
143
144 if (count) {
145 /* Get a copy of the hvc and copy out the relevant portion. */
146 char *hvc;
147
148 size = off + count;
149 hvc = kmalloc(size, GFP_KERNEL);
150 if (hvc == NULL)
151 return -ENOMEM;
152 hv_confstr(HV_CONFSTR_HV_CONFIG, (unsigned long)hvc, size);
153 memcpy(buf, hvc + off, count);
154 kfree(hvc);
155 }
156
157 return count;
158}
159
160static ssize_t hv_stats_show(struct device *dev,
161 struct device_attribute *attr,
162 char *page)
163{
164 int cpu = dev->id;
165 long lotar = HV_XY_TO_LOTAR(cpu_x(cpu), cpu_y(cpu));
166
167 ssize_t n = hv_confstr(HV_CONFSTR_HV_STATS,
168 (unsigned long)page, PAGE_SIZE - 1,
169 lotar, 0);
170 n = n < 0 ? 0 : min(n, (ssize_t)PAGE_SIZE - 1);
171 page[n] = '\0';
172 return n;
173}
174
175static ssize_t hv_stats_store(struct device *dev,
176 struct device_attribute *attr,
177 const char *page,
178 size_t count)
179{
180 int cpu = dev->id;
181 long lotar = HV_XY_TO_LOTAR(cpu_x(cpu), cpu_y(cpu));
182
183 ssize_t n = hv_confstr(HV_CONFSTR_HV_STATS, 0, 0, lotar, 1);
184 return n < 0 ? n : count;
185}
186
187static DEVICE_ATTR_RW(hv_stats);
188
189static int hv_stats_device_add(struct device *dev, struct subsys_interface *sif)
190{
191 int err, cpu = dev->id;
192
193 if (!cpu_online(cpu))
194 return 0;
195
196 err = sysfs_create_file(&dev->kobj, &dev_attr_hv_stats.attr);
197
198 return err;
199}
200
201static void hv_stats_device_remove(struct device *dev,
202 struct subsys_interface *sif)
203{
204 int cpu = dev->id;
205
206 if (cpu_online(cpu))
207 sysfs_remove_file(&dev->kobj, &dev_attr_hv_stats.attr);
208}
209
210
211static struct subsys_interface hv_stats_interface = {
212 .name = "hv_stats",
213 .subsys = &cpu_subsys,
214 .add_dev = hv_stats_device_add,
215 .remove_dev = hv_stats_device_remove,
216};
217
218static int __init create_sysfs_entries(void)
219{
220 int err = 0;
221
222#define create_cpu_attr(name) \
223 if (!err) \
224 err = device_create_file(cpu_subsys.dev_root, &dev_attr_##name);
225 create_cpu_attr(chip_width);
226 create_cpu_attr(chip_height);
227 create_cpu_attr(chip_serial);
228 create_cpu_attr(chip_revision);
229
230#define create_hv_attr(name) \
231 if (!err) \
232 err = sysfs_create_file(hypervisor_kobj, &dev_attr_##name.attr);
233 create_hv_attr(type);
234 create_hv_attr(version);
235 create_hv_attr(config_version);
236
237 if (!err)
238 err = sysfs_create_group(hypervisor_kobj, &board_attr_group);
239
240 if (!err) {
241 sysfs_bin_attr_init(&hvconfig_bin);
242 hvconfig_bin.attr.name = "hvconfig";
243 hvconfig_bin.attr.mode = S_IRUGO;
244 hvconfig_bin.read = hvconfig_bin_read;
245 hvconfig_bin.size = PAGE_SIZE;
246 err = sysfs_create_bin_file(hypervisor_kobj, &hvconfig_bin);
247 }
248
249 if (!err) {
250 /*
251 * Don't bother adding the hv_stats files on each CPU if
252 * our hypervisor doesn't supply statistics.
253 */
254 int cpu = raw_smp_processor_id();
255 long lotar = HV_XY_TO_LOTAR(cpu_x(cpu), cpu_y(cpu));
256 char dummy;
257 ssize_t n = hv_confstr(HV_CONFSTR_HV_STATS,
258 (unsigned long) &dummy, 1,
259 lotar, 0);
260 if (n >= 0)
261 err = subsys_interface_register(&hv_stats_interface);
262 }
263
264 return err;
265}
266subsys_initcall(create_sysfs_entries);
diff --git a/arch/tile/kernel/tile-desc_32.c b/arch/tile/kernel/tile-desc_32.c
deleted file mode 100644
index dd7bd1d8563c..000000000000
--- a/arch/tile/kernel/tile-desc_32.c
+++ /dev/null
@@ -1,2605 +0,0 @@
1/* TILEPro opcode information.
2 *
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 *
15 *
16 *
17 *
18 *
19 */
20
21/* This define is BFD_RELOC_##x for real bfd, or -1 for everyone else. */
22#define BFD_RELOC(x) -1
23
24/* Special registers. */
25#define TREG_LR 55
26#define TREG_SN 56
27#define TREG_ZERO 63
28
29#include <linux/stddef.h>
30#include <asm/tile-desc.h>
31
32const struct tilepro_opcode tilepro_opcodes[395] =
33{
34 { "bpt", TILEPRO_OPC_BPT, 0x2, 0, TREG_ZERO, 0,
35 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
36 },
37 { "info", TILEPRO_OPC_INFO, 0xf, 1, TREG_ZERO, 1,
38 { { 0 }, { 1 }, { 2 }, { 3 }, { 0, } },
39 },
40 { "infol", TILEPRO_OPC_INFOL, 0x3, 1, TREG_ZERO, 1,
41 { { 4 }, { 5 }, { 0, }, { 0, }, { 0, } },
42 },
43 { "j", TILEPRO_OPC_J, 0x2, 1, TREG_ZERO, 1,
44 { { 0, }, { 6 }, { 0, }, { 0, }, { 0, } },
45 },
46 { "jal", TILEPRO_OPC_JAL, 0x2, 1, TREG_LR, 1,
47 { { 0, }, { 6 }, { 0, }, { 0, }, { 0, } },
48 },
49 { "move", TILEPRO_OPC_MOVE, 0xf, 2, TREG_ZERO, 1,
50 { { 7, 8 }, { 9, 10 }, { 11, 12 }, { 13, 14 }, { 0, } },
51 },
52 { "move.sn", TILEPRO_OPC_MOVE_SN, 0x3, 2, TREG_SN, 1,
53 { { 7, 8 }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
54 },
55 { "movei", TILEPRO_OPC_MOVEI, 0xf, 2, TREG_ZERO, 1,
56 { { 7, 0 }, { 9, 1 }, { 11, 2 }, { 13, 3 }, { 0, } },
57 },
58 { "movei.sn", TILEPRO_OPC_MOVEI_SN, 0x3, 2, TREG_SN, 1,
59 { { 7, 0 }, { 9, 1 }, { 0, }, { 0, }, { 0, } },
60 },
61 { "moveli", TILEPRO_OPC_MOVELI, 0x3, 2, TREG_ZERO, 1,
62 { { 7, 4 }, { 9, 5 }, { 0, }, { 0, }, { 0, } },
63 },
64 { "moveli.sn", TILEPRO_OPC_MOVELI_SN, 0x3, 2, TREG_SN, 1,
65 { { 7, 4 }, { 9, 5 }, { 0, }, { 0, }, { 0, } },
66 },
67 { "movelis", TILEPRO_OPC_MOVELIS, 0x3, 2, TREG_SN, 1,
68 { { 7, 4 }, { 9, 5 }, { 0, }, { 0, }, { 0, } },
69 },
70 { "prefetch", TILEPRO_OPC_PREFETCH, 0x12, 1, TREG_ZERO, 1,
71 { { 0, }, { 10 }, { 0, }, { 0, }, { 15 } },
72 },
73 { "raise", TILEPRO_OPC_RAISE, 0x2, 0, TREG_ZERO, 1,
74 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
75 },
76 { "add", TILEPRO_OPC_ADD, 0xf, 3, TREG_ZERO, 1,
77 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
78 },
79 { "add.sn", TILEPRO_OPC_ADD_SN, 0x3, 3, TREG_SN, 1,
80 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
81 },
82 { "addb", TILEPRO_OPC_ADDB, 0x3, 3, TREG_ZERO, 1,
83 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
84 },
85 { "addb.sn", TILEPRO_OPC_ADDB_SN, 0x3, 3, TREG_SN, 1,
86 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
87 },
88 { "addbs_u", TILEPRO_OPC_ADDBS_U, 0x3, 3, TREG_ZERO, 1,
89 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
90 },
91 { "addbs_u.sn", TILEPRO_OPC_ADDBS_U_SN, 0x3, 3, TREG_SN, 1,
92 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
93 },
94 { "addh", TILEPRO_OPC_ADDH, 0x3, 3, TREG_ZERO, 1,
95 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
96 },
97 { "addh.sn", TILEPRO_OPC_ADDH_SN, 0x3, 3, TREG_SN, 1,
98 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
99 },
100 { "addhs", TILEPRO_OPC_ADDHS, 0x3, 3, TREG_ZERO, 1,
101 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
102 },
103 { "addhs.sn", TILEPRO_OPC_ADDHS_SN, 0x3, 3, TREG_SN, 1,
104 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
105 },
106 { "addi", TILEPRO_OPC_ADDI, 0xf, 3, TREG_ZERO, 1,
107 { { 7, 8, 0 }, { 9, 10, 1 }, { 11, 12, 2 }, { 13, 14, 3 }, { 0, } },
108 },
109 { "addi.sn", TILEPRO_OPC_ADDI_SN, 0x3, 3, TREG_SN, 1,
110 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
111 },
112 { "addib", TILEPRO_OPC_ADDIB, 0x3, 3, TREG_ZERO, 1,
113 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
114 },
115 { "addib.sn", TILEPRO_OPC_ADDIB_SN, 0x3, 3, TREG_SN, 1,
116 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
117 },
118 { "addih", TILEPRO_OPC_ADDIH, 0x3, 3, TREG_ZERO, 1,
119 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
120 },
121 { "addih.sn", TILEPRO_OPC_ADDIH_SN, 0x3, 3, TREG_SN, 1,
122 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
123 },
124 { "addli", TILEPRO_OPC_ADDLI, 0x3, 3, TREG_ZERO, 1,
125 { { 7, 8, 4 }, { 9, 10, 5 }, { 0, }, { 0, }, { 0, } },
126 },
127 { "addli.sn", TILEPRO_OPC_ADDLI_SN, 0x3, 3, TREG_SN, 1,
128 { { 7, 8, 4 }, { 9, 10, 5 }, { 0, }, { 0, }, { 0, } },
129 },
130 { "addlis", TILEPRO_OPC_ADDLIS, 0x3, 3, TREG_SN, 1,
131 { { 7, 8, 4 }, { 9, 10, 5 }, { 0, }, { 0, }, { 0, } },
132 },
133 { "adds", TILEPRO_OPC_ADDS, 0x3, 3, TREG_ZERO, 1,
134 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
135 },
136 { "adds.sn", TILEPRO_OPC_ADDS_SN, 0x3, 3, TREG_SN, 1,
137 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
138 },
139 { "adiffb_u", TILEPRO_OPC_ADIFFB_U, 0x1, 3, TREG_ZERO, 1,
140 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
141 },
142 { "adiffb_u.sn", TILEPRO_OPC_ADIFFB_U_SN, 0x1, 3, TREG_SN, 1,
143 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
144 },
145 { "adiffh", TILEPRO_OPC_ADIFFH, 0x1, 3, TREG_ZERO, 1,
146 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
147 },
148 { "adiffh.sn", TILEPRO_OPC_ADIFFH_SN, 0x1, 3, TREG_SN, 1,
149 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
150 },
151 { "and", TILEPRO_OPC_AND, 0xf, 3, TREG_ZERO, 1,
152 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
153 },
154 { "and.sn", TILEPRO_OPC_AND_SN, 0x3, 3, TREG_SN, 1,
155 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
156 },
157 { "andi", TILEPRO_OPC_ANDI, 0xf, 3, TREG_ZERO, 1,
158 { { 7, 8, 0 }, { 9, 10, 1 }, { 11, 12, 2 }, { 13, 14, 3 }, { 0, } },
159 },
160 { "andi.sn", TILEPRO_OPC_ANDI_SN, 0x3, 3, TREG_SN, 1,
161 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
162 },
163 { "auli", TILEPRO_OPC_AULI, 0x3, 3, TREG_ZERO, 1,
164 { { 7, 8, 4 }, { 9, 10, 5 }, { 0, }, { 0, }, { 0, } },
165 },
166 { "avgb_u", TILEPRO_OPC_AVGB_U, 0x1, 3, TREG_ZERO, 1,
167 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
168 },
169 { "avgb_u.sn", TILEPRO_OPC_AVGB_U_SN, 0x1, 3, TREG_SN, 1,
170 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
171 },
172 { "avgh", TILEPRO_OPC_AVGH, 0x1, 3, TREG_ZERO, 1,
173 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
174 },
175 { "avgh.sn", TILEPRO_OPC_AVGH_SN, 0x1, 3, TREG_SN, 1,
176 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
177 },
178 { "bbns", TILEPRO_OPC_BBNS, 0x2, 2, TREG_ZERO, 1,
179 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
180 },
181 { "bbns.sn", TILEPRO_OPC_BBNS_SN, 0x2, 2, TREG_SN, 1,
182 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
183 },
184 { "bbnst", TILEPRO_OPC_BBNST, 0x2, 2, TREG_ZERO, 1,
185 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
186 },
187 { "bbnst.sn", TILEPRO_OPC_BBNST_SN, 0x2, 2, TREG_SN, 1,
188 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
189 },
190 { "bbs", TILEPRO_OPC_BBS, 0x2, 2, TREG_ZERO, 1,
191 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
192 },
193 { "bbs.sn", TILEPRO_OPC_BBS_SN, 0x2, 2, TREG_SN, 1,
194 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
195 },
196 { "bbst", TILEPRO_OPC_BBST, 0x2, 2, TREG_ZERO, 1,
197 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
198 },
199 { "bbst.sn", TILEPRO_OPC_BBST_SN, 0x2, 2, TREG_SN, 1,
200 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
201 },
202 { "bgez", TILEPRO_OPC_BGEZ, 0x2, 2, TREG_ZERO, 1,
203 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
204 },
205 { "bgez.sn", TILEPRO_OPC_BGEZ_SN, 0x2, 2, TREG_SN, 1,
206 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
207 },
208 { "bgezt", TILEPRO_OPC_BGEZT, 0x2, 2, TREG_ZERO, 1,
209 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
210 },
211 { "bgezt.sn", TILEPRO_OPC_BGEZT_SN, 0x2, 2, TREG_SN, 1,
212 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
213 },
214 { "bgz", TILEPRO_OPC_BGZ, 0x2, 2, TREG_ZERO, 1,
215 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
216 },
217 { "bgz.sn", TILEPRO_OPC_BGZ_SN, 0x2, 2, TREG_SN, 1,
218 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
219 },
220 { "bgzt", TILEPRO_OPC_BGZT, 0x2, 2, TREG_ZERO, 1,
221 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
222 },
223 { "bgzt.sn", TILEPRO_OPC_BGZT_SN, 0x2, 2, TREG_SN, 1,
224 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
225 },
226 { "bitx", TILEPRO_OPC_BITX, 0x5, 2, TREG_ZERO, 1,
227 { { 7, 8 }, { 0, }, { 11, 12 }, { 0, }, { 0, } },
228 },
229 { "bitx.sn", TILEPRO_OPC_BITX_SN, 0x1, 2, TREG_SN, 1,
230 { { 7, 8 }, { 0, }, { 0, }, { 0, }, { 0, } },
231 },
232 { "blez", TILEPRO_OPC_BLEZ, 0x2, 2, TREG_ZERO, 1,
233 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
234 },
235 { "blez.sn", TILEPRO_OPC_BLEZ_SN, 0x2, 2, TREG_SN, 1,
236 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
237 },
238 { "blezt", TILEPRO_OPC_BLEZT, 0x2, 2, TREG_ZERO, 1,
239 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
240 },
241 { "blezt.sn", TILEPRO_OPC_BLEZT_SN, 0x2, 2, TREG_SN, 1,
242 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
243 },
244 { "blz", TILEPRO_OPC_BLZ, 0x2, 2, TREG_ZERO, 1,
245 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
246 },
247 { "blz.sn", TILEPRO_OPC_BLZ_SN, 0x2, 2, TREG_SN, 1,
248 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
249 },
250 { "blzt", TILEPRO_OPC_BLZT, 0x2, 2, TREG_ZERO, 1,
251 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
252 },
253 { "blzt.sn", TILEPRO_OPC_BLZT_SN, 0x2, 2, TREG_SN, 1,
254 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
255 },
256 { "bnz", TILEPRO_OPC_BNZ, 0x2, 2, TREG_ZERO, 1,
257 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
258 },
259 { "bnz.sn", TILEPRO_OPC_BNZ_SN, 0x2, 2, TREG_SN, 1,
260 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
261 },
262 { "bnzt", TILEPRO_OPC_BNZT, 0x2, 2, TREG_ZERO, 1,
263 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
264 },
265 { "bnzt.sn", TILEPRO_OPC_BNZT_SN, 0x2, 2, TREG_SN, 1,
266 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
267 },
268 { "bytex", TILEPRO_OPC_BYTEX, 0x5, 2, TREG_ZERO, 1,
269 { { 7, 8 }, { 0, }, { 11, 12 }, { 0, }, { 0, } },
270 },
271 { "bytex.sn", TILEPRO_OPC_BYTEX_SN, 0x1, 2, TREG_SN, 1,
272 { { 7, 8 }, { 0, }, { 0, }, { 0, }, { 0, } },
273 },
274 { "bz", TILEPRO_OPC_BZ, 0x2, 2, TREG_ZERO, 1,
275 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
276 },
277 { "bz.sn", TILEPRO_OPC_BZ_SN, 0x2, 2, TREG_SN, 1,
278 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
279 },
280 { "bzt", TILEPRO_OPC_BZT, 0x2, 2, TREG_ZERO, 1,
281 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
282 },
283 { "bzt.sn", TILEPRO_OPC_BZT_SN, 0x2, 2, TREG_SN, 1,
284 { { 0, }, { 10, 20 }, { 0, }, { 0, }, { 0, } },
285 },
286 { "clz", TILEPRO_OPC_CLZ, 0x5, 2, TREG_ZERO, 1,
287 { { 7, 8 }, { 0, }, { 11, 12 }, { 0, }, { 0, } },
288 },
289 { "clz.sn", TILEPRO_OPC_CLZ_SN, 0x1, 2, TREG_SN, 1,
290 { { 7, 8 }, { 0, }, { 0, }, { 0, }, { 0, } },
291 },
292 { "crc32_32", TILEPRO_OPC_CRC32_32, 0x1, 3, TREG_ZERO, 1,
293 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
294 },
295 { "crc32_32.sn", TILEPRO_OPC_CRC32_32_SN, 0x1, 3, TREG_SN, 1,
296 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
297 },
298 { "crc32_8", TILEPRO_OPC_CRC32_8, 0x1, 3, TREG_ZERO, 1,
299 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
300 },
301 { "crc32_8.sn", TILEPRO_OPC_CRC32_8_SN, 0x1, 3, TREG_SN, 1,
302 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
303 },
304 { "ctz", TILEPRO_OPC_CTZ, 0x5, 2, TREG_ZERO, 1,
305 { { 7, 8 }, { 0, }, { 11, 12 }, { 0, }, { 0, } },
306 },
307 { "ctz.sn", TILEPRO_OPC_CTZ_SN, 0x1, 2, TREG_SN, 1,
308 { { 7, 8 }, { 0, }, { 0, }, { 0, }, { 0, } },
309 },
310 { "drain", TILEPRO_OPC_DRAIN, 0x2, 0, TREG_ZERO, 0,
311 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
312 },
313 { "dtlbpr", TILEPRO_OPC_DTLBPR, 0x2, 1, TREG_ZERO, 1,
314 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
315 },
316 { "dword_align", TILEPRO_OPC_DWORD_ALIGN, 0x1, 3, TREG_ZERO, 1,
317 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
318 },
319 { "dword_align.sn", TILEPRO_OPC_DWORD_ALIGN_SN, 0x1, 3, TREG_SN, 1,
320 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
321 },
322 { "finv", TILEPRO_OPC_FINV, 0x2, 1, TREG_ZERO, 1,
323 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
324 },
325 { "flush", TILEPRO_OPC_FLUSH, 0x2, 1, TREG_ZERO, 1,
326 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
327 },
328 { "fnop", TILEPRO_OPC_FNOP, 0xf, 0, TREG_ZERO, 1,
329 { { }, { }, { }, { }, { 0, } },
330 },
331 { "icoh", TILEPRO_OPC_ICOH, 0x2, 1, TREG_ZERO, 1,
332 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
333 },
334 { "ill", TILEPRO_OPC_ILL, 0xa, 0, TREG_ZERO, 1,
335 { { 0, }, { }, { 0, }, { }, { 0, } },
336 },
337 { "inthb", TILEPRO_OPC_INTHB, 0x3, 3, TREG_ZERO, 1,
338 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
339 },
340 { "inthb.sn", TILEPRO_OPC_INTHB_SN, 0x3, 3, TREG_SN, 1,
341 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
342 },
343 { "inthh", TILEPRO_OPC_INTHH, 0x3, 3, TREG_ZERO, 1,
344 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
345 },
346 { "inthh.sn", TILEPRO_OPC_INTHH_SN, 0x3, 3, TREG_SN, 1,
347 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
348 },
349 { "intlb", TILEPRO_OPC_INTLB, 0x3, 3, TREG_ZERO, 1,
350 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
351 },
352 { "intlb.sn", TILEPRO_OPC_INTLB_SN, 0x3, 3, TREG_SN, 1,
353 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
354 },
355 { "intlh", TILEPRO_OPC_INTLH, 0x3, 3, TREG_ZERO, 1,
356 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
357 },
358 { "intlh.sn", TILEPRO_OPC_INTLH_SN, 0x3, 3, TREG_SN, 1,
359 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
360 },
361 { "inv", TILEPRO_OPC_INV, 0x2, 1, TREG_ZERO, 1,
362 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
363 },
364 { "iret", TILEPRO_OPC_IRET, 0x2, 0, TREG_ZERO, 1,
365 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
366 },
367 { "jalb", TILEPRO_OPC_JALB, 0x2, 1, TREG_LR, 1,
368 { { 0, }, { 22 }, { 0, }, { 0, }, { 0, } },
369 },
370 { "jalf", TILEPRO_OPC_JALF, 0x2, 1, TREG_LR, 1,
371 { { 0, }, { 22 }, { 0, }, { 0, }, { 0, } },
372 },
373 { "jalr", TILEPRO_OPC_JALR, 0x2, 1, TREG_LR, 1,
374 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
375 },
376 { "jalrp", TILEPRO_OPC_JALRP, 0x2, 1, TREG_LR, 1,
377 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
378 },
379 { "jb", TILEPRO_OPC_JB, 0x2, 1, TREG_ZERO, 1,
380 { { 0, }, { 22 }, { 0, }, { 0, }, { 0, } },
381 },
382 { "jf", TILEPRO_OPC_JF, 0x2, 1, TREG_ZERO, 1,
383 { { 0, }, { 22 }, { 0, }, { 0, }, { 0, } },
384 },
385 { "jr", TILEPRO_OPC_JR, 0x2, 1, TREG_ZERO, 1,
386 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
387 },
388 { "jrp", TILEPRO_OPC_JRP, 0x2, 1, TREG_ZERO, 1,
389 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
390 },
391 { "lb", TILEPRO_OPC_LB, 0x12, 2, TREG_ZERO, 1,
392 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 23, 15 } },
393 },
394 { "lb.sn", TILEPRO_OPC_LB_SN, 0x2, 2, TREG_SN, 1,
395 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
396 },
397 { "lb_u", TILEPRO_OPC_LB_U, 0x12, 2, TREG_ZERO, 1,
398 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 23, 15 } },
399 },
400 { "lb_u.sn", TILEPRO_OPC_LB_U_SN, 0x2, 2, TREG_SN, 1,
401 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
402 },
403 { "lbadd", TILEPRO_OPC_LBADD, 0x2, 3, TREG_ZERO, 1,
404 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
405 },
406 { "lbadd.sn", TILEPRO_OPC_LBADD_SN, 0x2, 3, TREG_SN, 1,
407 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
408 },
409 { "lbadd_u", TILEPRO_OPC_LBADD_U, 0x2, 3, TREG_ZERO, 1,
410 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
411 },
412 { "lbadd_u.sn", TILEPRO_OPC_LBADD_U_SN, 0x2, 3, TREG_SN, 1,
413 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
414 },
415 { "lh", TILEPRO_OPC_LH, 0x12, 2, TREG_ZERO, 1,
416 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 23, 15 } },
417 },
418 { "lh.sn", TILEPRO_OPC_LH_SN, 0x2, 2, TREG_SN, 1,
419 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
420 },
421 { "lh_u", TILEPRO_OPC_LH_U, 0x12, 2, TREG_ZERO, 1,
422 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 23, 15 } },
423 },
424 { "lh_u.sn", TILEPRO_OPC_LH_U_SN, 0x2, 2, TREG_SN, 1,
425 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
426 },
427 { "lhadd", TILEPRO_OPC_LHADD, 0x2, 3, TREG_ZERO, 1,
428 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
429 },
430 { "lhadd.sn", TILEPRO_OPC_LHADD_SN, 0x2, 3, TREG_SN, 1,
431 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
432 },
433 { "lhadd_u", TILEPRO_OPC_LHADD_U, 0x2, 3, TREG_ZERO, 1,
434 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
435 },
436 { "lhadd_u.sn", TILEPRO_OPC_LHADD_U_SN, 0x2, 3, TREG_SN, 1,
437 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
438 },
439 { "lnk", TILEPRO_OPC_LNK, 0x2, 1, TREG_ZERO, 1,
440 { { 0, }, { 9 }, { 0, }, { 0, }, { 0, } },
441 },
442 { "lnk.sn", TILEPRO_OPC_LNK_SN, 0x2, 1, TREG_SN, 1,
443 { { 0, }, { 9 }, { 0, }, { 0, }, { 0, } },
444 },
445 { "lw", TILEPRO_OPC_LW, 0x12, 2, TREG_ZERO, 1,
446 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 23, 15 } },
447 },
448 { "lw.sn", TILEPRO_OPC_LW_SN, 0x2, 2, TREG_SN, 1,
449 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
450 },
451 { "lw_na", TILEPRO_OPC_LW_NA, 0x2, 2, TREG_ZERO, 1,
452 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
453 },
454 { "lw_na.sn", TILEPRO_OPC_LW_NA_SN, 0x2, 2, TREG_SN, 1,
455 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
456 },
457 { "lwadd", TILEPRO_OPC_LWADD, 0x2, 3, TREG_ZERO, 1,
458 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
459 },
460 { "lwadd.sn", TILEPRO_OPC_LWADD_SN, 0x2, 3, TREG_SN, 1,
461 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
462 },
463 { "lwadd_na", TILEPRO_OPC_LWADD_NA, 0x2, 3, TREG_ZERO, 1,
464 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
465 },
466 { "lwadd_na.sn", TILEPRO_OPC_LWADD_NA_SN, 0x2, 3, TREG_SN, 1,
467 { { 0, }, { 9, 24, 1 }, { 0, }, { 0, }, { 0, } },
468 },
469 { "maxb_u", TILEPRO_OPC_MAXB_U, 0x3, 3, TREG_ZERO, 1,
470 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
471 },
472 { "maxb_u.sn", TILEPRO_OPC_MAXB_U_SN, 0x3, 3, TREG_SN, 1,
473 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
474 },
475 { "maxh", TILEPRO_OPC_MAXH, 0x3, 3, TREG_ZERO, 1,
476 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
477 },
478 { "maxh.sn", TILEPRO_OPC_MAXH_SN, 0x3, 3, TREG_SN, 1,
479 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
480 },
481 { "maxib_u", TILEPRO_OPC_MAXIB_U, 0x3, 3, TREG_ZERO, 1,
482 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
483 },
484 { "maxib_u.sn", TILEPRO_OPC_MAXIB_U_SN, 0x3, 3, TREG_SN, 1,
485 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
486 },
487 { "maxih", TILEPRO_OPC_MAXIH, 0x3, 3, TREG_ZERO, 1,
488 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
489 },
490 { "maxih.sn", TILEPRO_OPC_MAXIH_SN, 0x3, 3, TREG_SN, 1,
491 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
492 },
493 { "mf", TILEPRO_OPC_MF, 0x2, 0, TREG_ZERO, 1,
494 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
495 },
496 { "mfspr", TILEPRO_OPC_MFSPR, 0x2, 2, TREG_ZERO, 1,
497 { { 0, }, { 9, 25 }, { 0, }, { 0, }, { 0, } },
498 },
499 { "minb_u", TILEPRO_OPC_MINB_U, 0x3, 3, TREG_ZERO, 1,
500 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
501 },
502 { "minb_u.sn", TILEPRO_OPC_MINB_U_SN, 0x3, 3, TREG_SN, 1,
503 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
504 },
505 { "minh", TILEPRO_OPC_MINH, 0x3, 3, TREG_ZERO, 1,
506 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
507 },
508 { "minh.sn", TILEPRO_OPC_MINH_SN, 0x3, 3, TREG_SN, 1,
509 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
510 },
511 { "minib_u", TILEPRO_OPC_MINIB_U, 0x3, 3, TREG_ZERO, 1,
512 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
513 },
514 { "minib_u.sn", TILEPRO_OPC_MINIB_U_SN, 0x3, 3, TREG_SN, 1,
515 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
516 },
517 { "minih", TILEPRO_OPC_MINIH, 0x3, 3, TREG_ZERO, 1,
518 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
519 },
520 { "minih.sn", TILEPRO_OPC_MINIH_SN, 0x3, 3, TREG_SN, 1,
521 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
522 },
523 { "mm", TILEPRO_OPC_MM, 0x3, 5, TREG_ZERO, 1,
524 { { 7, 8, 16, 26, 27 }, { 9, 10, 17, 28, 29 }, { 0, }, { 0, }, { 0, } },
525 },
526 { "mnz", TILEPRO_OPC_MNZ, 0xf, 3, TREG_ZERO, 1,
527 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
528 },
529 { "mnz.sn", TILEPRO_OPC_MNZ_SN, 0x3, 3, TREG_SN, 1,
530 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
531 },
532 { "mnzb", TILEPRO_OPC_MNZB, 0x3, 3, TREG_ZERO, 1,
533 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
534 },
535 { "mnzb.sn", TILEPRO_OPC_MNZB_SN, 0x3, 3, TREG_SN, 1,
536 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
537 },
538 { "mnzh", TILEPRO_OPC_MNZH, 0x3, 3, TREG_ZERO, 1,
539 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
540 },
541 { "mnzh.sn", TILEPRO_OPC_MNZH_SN, 0x3, 3, TREG_SN, 1,
542 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
543 },
544 { "mtspr", TILEPRO_OPC_MTSPR, 0x2, 2, TREG_ZERO, 1,
545 { { 0, }, { 30, 10 }, { 0, }, { 0, }, { 0, } },
546 },
547 { "mulhh_ss", TILEPRO_OPC_MULHH_SS, 0x5, 3, TREG_ZERO, 1,
548 { { 7, 8, 16 }, { 0, }, { 11, 12, 18 }, { 0, }, { 0, } },
549 },
550 { "mulhh_ss.sn", TILEPRO_OPC_MULHH_SS_SN, 0x1, 3, TREG_SN, 1,
551 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
552 },
553 { "mulhh_su", TILEPRO_OPC_MULHH_SU, 0x1, 3, TREG_ZERO, 1,
554 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
555 },
556 { "mulhh_su.sn", TILEPRO_OPC_MULHH_SU_SN, 0x1, 3, TREG_SN, 1,
557 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
558 },
559 { "mulhh_uu", TILEPRO_OPC_MULHH_UU, 0x5, 3, TREG_ZERO, 1,
560 { { 7, 8, 16 }, { 0, }, { 11, 12, 18 }, { 0, }, { 0, } },
561 },
562 { "mulhh_uu.sn", TILEPRO_OPC_MULHH_UU_SN, 0x1, 3, TREG_SN, 1,
563 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
564 },
565 { "mulhha_ss", TILEPRO_OPC_MULHHA_SS, 0x5, 3, TREG_ZERO, 1,
566 { { 21, 8, 16 }, { 0, }, { 31, 12, 18 }, { 0, }, { 0, } },
567 },
568 { "mulhha_ss.sn", TILEPRO_OPC_MULHHA_SS_SN, 0x1, 3, TREG_SN, 1,
569 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
570 },
571 { "mulhha_su", TILEPRO_OPC_MULHHA_SU, 0x1, 3, TREG_ZERO, 1,
572 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
573 },
574 { "mulhha_su.sn", TILEPRO_OPC_MULHHA_SU_SN, 0x1, 3, TREG_SN, 1,
575 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
576 },
577 { "mulhha_uu", TILEPRO_OPC_MULHHA_UU, 0x5, 3, TREG_ZERO, 1,
578 { { 21, 8, 16 }, { 0, }, { 31, 12, 18 }, { 0, }, { 0, } },
579 },
580 { "mulhha_uu.sn", TILEPRO_OPC_MULHHA_UU_SN, 0x1, 3, TREG_SN, 1,
581 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
582 },
583 { "mulhhsa_uu", TILEPRO_OPC_MULHHSA_UU, 0x1, 3, TREG_ZERO, 1,
584 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
585 },
586 { "mulhhsa_uu.sn", TILEPRO_OPC_MULHHSA_UU_SN, 0x1, 3, TREG_SN, 1,
587 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
588 },
589 { "mulhl_ss", TILEPRO_OPC_MULHL_SS, 0x1, 3, TREG_ZERO, 1,
590 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
591 },
592 { "mulhl_ss.sn", TILEPRO_OPC_MULHL_SS_SN, 0x1, 3, TREG_SN, 1,
593 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
594 },
595 { "mulhl_su", TILEPRO_OPC_MULHL_SU, 0x1, 3, TREG_ZERO, 1,
596 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
597 },
598 { "mulhl_su.sn", TILEPRO_OPC_MULHL_SU_SN, 0x1, 3, TREG_SN, 1,
599 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
600 },
601 { "mulhl_us", TILEPRO_OPC_MULHL_US, 0x1, 3, TREG_ZERO, 1,
602 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
603 },
604 { "mulhl_us.sn", TILEPRO_OPC_MULHL_US_SN, 0x1, 3, TREG_SN, 1,
605 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
606 },
607 { "mulhl_uu", TILEPRO_OPC_MULHL_UU, 0x1, 3, TREG_ZERO, 1,
608 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
609 },
610 { "mulhl_uu.sn", TILEPRO_OPC_MULHL_UU_SN, 0x1, 3, TREG_SN, 1,
611 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
612 },
613 { "mulhla_ss", TILEPRO_OPC_MULHLA_SS, 0x1, 3, TREG_ZERO, 1,
614 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
615 },
616 { "mulhla_ss.sn", TILEPRO_OPC_MULHLA_SS_SN, 0x1, 3, TREG_SN, 1,
617 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
618 },
619 { "mulhla_su", TILEPRO_OPC_MULHLA_SU, 0x1, 3, TREG_ZERO, 1,
620 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
621 },
622 { "mulhla_su.sn", TILEPRO_OPC_MULHLA_SU_SN, 0x1, 3, TREG_SN, 1,
623 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
624 },
625 { "mulhla_us", TILEPRO_OPC_MULHLA_US, 0x1, 3, TREG_ZERO, 1,
626 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
627 },
628 { "mulhla_us.sn", TILEPRO_OPC_MULHLA_US_SN, 0x1, 3, TREG_SN, 1,
629 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
630 },
631 { "mulhla_uu", TILEPRO_OPC_MULHLA_UU, 0x1, 3, TREG_ZERO, 1,
632 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
633 },
634 { "mulhla_uu.sn", TILEPRO_OPC_MULHLA_UU_SN, 0x1, 3, TREG_SN, 1,
635 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
636 },
637 { "mulhlsa_uu", TILEPRO_OPC_MULHLSA_UU, 0x5, 3, TREG_ZERO, 1,
638 { { 21, 8, 16 }, { 0, }, { 31, 12, 18 }, { 0, }, { 0, } },
639 },
640 { "mulhlsa_uu.sn", TILEPRO_OPC_MULHLSA_UU_SN, 0x1, 3, TREG_SN, 1,
641 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
642 },
643 { "mulll_ss", TILEPRO_OPC_MULLL_SS, 0x5, 3, TREG_ZERO, 1,
644 { { 7, 8, 16 }, { 0, }, { 11, 12, 18 }, { 0, }, { 0, } },
645 },
646 { "mulll_ss.sn", TILEPRO_OPC_MULLL_SS_SN, 0x1, 3, TREG_SN, 1,
647 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
648 },
649 { "mulll_su", TILEPRO_OPC_MULLL_SU, 0x1, 3, TREG_ZERO, 1,
650 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
651 },
652 { "mulll_su.sn", TILEPRO_OPC_MULLL_SU_SN, 0x1, 3, TREG_SN, 1,
653 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
654 },
655 { "mulll_uu", TILEPRO_OPC_MULLL_UU, 0x5, 3, TREG_ZERO, 1,
656 { { 7, 8, 16 }, { 0, }, { 11, 12, 18 }, { 0, }, { 0, } },
657 },
658 { "mulll_uu.sn", TILEPRO_OPC_MULLL_UU_SN, 0x1, 3, TREG_SN, 1,
659 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
660 },
661 { "mullla_ss", TILEPRO_OPC_MULLLA_SS, 0x5, 3, TREG_ZERO, 1,
662 { { 21, 8, 16 }, { 0, }, { 31, 12, 18 }, { 0, }, { 0, } },
663 },
664 { "mullla_ss.sn", TILEPRO_OPC_MULLLA_SS_SN, 0x1, 3, TREG_SN, 1,
665 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
666 },
667 { "mullla_su", TILEPRO_OPC_MULLLA_SU, 0x1, 3, TREG_ZERO, 1,
668 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
669 },
670 { "mullla_su.sn", TILEPRO_OPC_MULLLA_SU_SN, 0x1, 3, TREG_SN, 1,
671 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
672 },
673 { "mullla_uu", TILEPRO_OPC_MULLLA_UU, 0x5, 3, TREG_ZERO, 1,
674 { { 21, 8, 16 }, { 0, }, { 31, 12, 18 }, { 0, }, { 0, } },
675 },
676 { "mullla_uu.sn", TILEPRO_OPC_MULLLA_UU_SN, 0x1, 3, TREG_SN, 1,
677 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
678 },
679 { "mulllsa_uu", TILEPRO_OPC_MULLLSA_UU, 0x1, 3, TREG_ZERO, 1,
680 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
681 },
682 { "mulllsa_uu.sn", TILEPRO_OPC_MULLLSA_UU_SN, 0x1, 3, TREG_SN, 1,
683 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
684 },
685 { "mvnz", TILEPRO_OPC_MVNZ, 0x5, 3, TREG_ZERO, 1,
686 { { 21, 8, 16 }, { 0, }, { 31, 12, 18 }, { 0, }, { 0, } },
687 },
688 { "mvnz.sn", TILEPRO_OPC_MVNZ_SN, 0x1, 3, TREG_SN, 1,
689 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
690 },
691 { "mvz", TILEPRO_OPC_MVZ, 0x5, 3, TREG_ZERO, 1,
692 { { 21, 8, 16 }, { 0, }, { 31, 12, 18 }, { 0, }, { 0, } },
693 },
694 { "mvz.sn", TILEPRO_OPC_MVZ_SN, 0x1, 3, TREG_SN, 1,
695 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
696 },
697 { "mz", TILEPRO_OPC_MZ, 0xf, 3, TREG_ZERO, 1,
698 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
699 },
700 { "mz.sn", TILEPRO_OPC_MZ_SN, 0x3, 3, TREG_SN, 1,
701 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
702 },
703 { "mzb", TILEPRO_OPC_MZB, 0x3, 3, TREG_ZERO, 1,
704 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
705 },
706 { "mzb.sn", TILEPRO_OPC_MZB_SN, 0x3, 3, TREG_SN, 1,
707 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
708 },
709 { "mzh", TILEPRO_OPC_MZH, 0x3, 3, TREG_ZERO, 1,
710 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
711 },
712 { "mzh.sn", TILEPRO_OPC_MZH_SN, 0x3, 3, TREG_SN, 1,
713 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
714 },
715 { "nap", TILEPRO_OPC_NAP, 0x2, 0, TREG_ZERO, 0,
716 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
717 },
718 { "nop", TILEPRO_OPC_NOP, 0xf, 0, TREG_ZERO, 1,
719 { { }, { }, { }, { }, { 0, } },
720 },
721 { "nor", TILEPRO_OPC_NOR, 0xf, 3, TREG_ZERO, 1,
722 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
723 },
724 { "nor.sn", TILEPRO_OPC_NOR_SN, 0x3, 3, TREG_SN, 1,
725 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
726 },
727 { "or", TILEPRO_OPC_OR, 0xf, 3, TREG_ZERO, 1,
728 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
729 },
730 { "or.sn", TILEPRO_OPC_OR_SN, 0x3, 3, TREG_SN, 1,
731 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
732 },
733 { "ori", TILEPRO_OPC_ORI, 0xf, 3, TREG_ZERO, 1,
734 { { 7, 8, 0 }, { 9, 10, 1 }, { 11, 12, 2 }, { 13, 14, 3 }, { 0, } },
735 },
736 { "ori.sn", TILEPRO_OPC_ORI_SN, 0x3, 3, TREG_SN, 1,
737 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
738 },
739 { "packbs_u", TILEPRO_OPC_PACKBS_U, 0x3, 3, TREG_ZERO, 1,
740 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
741 },
742 { "packbs_u.sn", TILEPRO_OPC_PACKBS_U_SN, 0x3, 3, TREG_SN, 1,
743 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
744 },
745 { "packhb", TILEPRO_OPC_PACKHB, 0x3, 3, TREG_ZERO, 1,
746 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
747 },
748 { "packhb.sn", TILEPRO_OPC_PACKHB_SN, 0x3, 3, TREG_SN, 1,
749 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
750 },
751 { "packhs", TILEPRO_OPC_PACKHS, 0x3, 3, TREG_ZERO, 1,
752 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
753 },
754 { "packhs.sn", TILEPRO_OPC_PACKHS_SN, 0x3, 3, TREG_SN, 1,
755 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
756 },
757 { "packlb", TILEPRO_OPC_PACKLB, 0x3, 3, TREG_ZERO, 1,
758 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
759 },
760 { "packlb.sn", TILEPRO_OPC_PACKLB_SN, 0x3, 3, TREG_SN, 1,
761 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
762 },
763 { "pcnt", TILEPRO_OPC_PCNT, 0x5, 2, TREG_ZERO, 1,
764 { { 7, 8 }, { 0, }, { 11, 12 }, { 0, }, { 0, } },
765 },
766 { "pcnt.sn", TILEPRO_OPC_PCNT_SN, 0x1, 2, TREG_SN, 1,
767 { { 7, 8 }, { 0, }, { 0, }, { 0, }, { 0, } },
768 },
769 { "rl", TILEPRO_OPC_RL, 0xf, 3, TREG_ZERO, 1,
770 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
771 },
772 { "rl.sn", TILEPRO_OPC_RL_SN, 0x3, 3, TREG_SN, 1,
773 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
774 },
775 { "rli", TILEPRO_OPC_RLI, 0xf, 3, TREG_ZERO, 1,
776 { { 7, 8, 32 }, { 9, 10, 33 }, { 11, 12, 34 }, { 13, 14, 35 }, { 0, } },
777 },
778 { "rli.sn", TILEPRO_OPC_RLI_SN, 0x3, 3, TREG_SN, 1,
779 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
780 },
781 { "s1a", TILEPRO_OPC_S1A, 0xf, 3, TREG_ZERO, 1,
782 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
783 },
784 { "s1a.sn", TILEPRO_OPC_S1A_SN, 0x3, 3, TREG_SN, 1,
785 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
786 },
787 { "s2a", TILEPRO_OPC_S2A, 0xf, 3, TREG_ZERO, 1,
788 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
789 },
790 { "s2a.sn", TILEPRO_OPC_S2A_SN, 0x3, 3, TREG_SN, 1,
791 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
792 },
793 { "s3a", TILEPRO_OPC_S3A, 0xf, 3, TREG_ZERO, 1,
794 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
795 },
796 { "s3a.sn", TILEPRO_OPC_S3A_SN, 0x3, 3, TREG_SN, 1,
797 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
798 },
799 { "sadab_u", TILEPRO_OPC_SADAB_U, 0x1, 3, TREG_ZERO, 1,
800 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
801 },
802 { "sadab_u.sn", TILEPRO_OPC_SADAB_U_SN, 0x1, 3, TREG_SN, 1,
803 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
804 },
805 { "sadah", TILEPRO_OPC_SADAH, 0x1, 3, TREG_ZERO, 1,
806 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
807 },
808 { "sadah.sn", TILEPRO_OPC_SADAH_SN, 0x1, 3, TREG_SN, 1,
809 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
810 },
811 { "sadah_u", TILEPRO_OPC_SADAH_U, 0x1, 3, TREG_ZERO, 1,
812 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
813 },
814 { "sadah_u.sn", TILEPRO_OPC_SADAH_U_SN, 0x1, 3, TREG_SN, 1,
815 { { 21, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
816 },
817 { "sadb_u", TILEPRO_OPC_SADB_U, 0x1, 3, TREG_ZERO, 1,
818 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
819 },
820 { "sadb_u.sn", TILEPRO_OPC_SADB_U_SN, 0x1, 3, TREG_SN, 1,
821 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
822 },
823 { "sadh", TILEPRO_OPC_SADH, 0x1, 3, TREG_ZERO, 1,
824 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
825 },
826 { "sadh.sn", TILEPRO_OPC_SADH_SN, 0x1, 3, TREG_SN, 1,
827 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
828 },
829 { "sadh_u", TILEPRO_OPC_SADH_U, 0x1, 3, TREG_ZERO, 1,
830 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
831 },
832 { "sadh_u.sn", TILEPRO_OPC_SADH_U_SN, 0x1, 3, TREG_SN, 1,
833 { { 7, 8, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
834 },
835 { "sb", TILEPRO_OPC_SB, 0x12, 2, TREG_ZERO, 1,
836 { { 0, }, { 10, 17 }, { 0, }, { 0, }, { 15, 36 } },
837 },
838 { "sbadd", TILEPRO_OPC_SBADD, 0x2, 3, TREG_ZERO, 1,
839 { { 0, }, { 24, 17, 37 }, { 0, }, { 0, }, { 0, } },
840 },
841 { "seq", TILEPRO_OPC_SEQ, 0xf, 3, TREG_ZERO, 1,
842 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
843 },
844 { "seq.sn", TILEPRO_OPC_SEQ_SN, 0x3, 3, TREG_SN, 1,
845 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
846 },
847 { "seqb", TILEPRO_OPC_SEQB, 0x3, 3, TREG_ZERO, 1,
848 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
849 },
850 { "seqb.sn", TILEPRO_OPC_SEQB_SN, 0x3, 3, TREG_SN, 1,
851 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
852 },
853 { "seqh", TILEPRO_OPC_SEQH, 0x3, 3, TREG_ZERO, 1,
854 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
855 },
856 { "seqh.sn", TILEPRO_OPC_SEQH_SN, 0x3, 3, TREG_SN, 1,
857 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
858 },
859 { "seqi", TILEPRO_OPC_SEQI, 0xf, 3, TREG_ZERO, 1,
860 { { 7, 8, 0 }, { 9, 10, 1 }, { 11, 12, 2 }, { 13, 14, 3 }, { 0, } },
861 },
862 { "seqi.sn", TILEPRO_OPC_SEQI_SN, 0x3, 3, TREG_SN, 1,
863 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
864 },
865 { "seqib", TILEPRO_OPC_SEQIB, 0x3, 3, TREG_ZERO, 1,
866 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
867 },
868 { "seqib.sn", TILEPRO_OPC_SEQIB_SN, 0x3, 3, TREG_SN, 1,
869 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
870 },
871 { "seqih", TILEPRO_OPC_SEQIH, 0x3, 3, TREG_ZERO, 1,
872 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
873 },
874 { "seqih.sn", TILEPRO_OPC_SEQIH_SN, 0x3, 3, TREG_SN, 1,
875 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
876 },
877 { "sh", TILEPRO_OPC_SH, 0x12, 2, TREG_ZERO, 1,
878 { { 0, }, { 10, 17 }, { 0, }, { 0, }, { 15, 36 } },
879 },
880 { "shadd", TILEPRO_OPC_SHADD, 0x2, 3, TREG_ZERO, 1,
881 { { 0, }, { 24, 17, 37 }, { 0, }, { 0, }, { 0, } },
882 },
883 { "shl", TILEPRO_OPC_SHL, 0xf, 3, TREG_ZERO, 1,
884 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
885 },
886 { "shl.sn", TILEPRO_OPC_SHL_SN, 0x3, 3, TREG_SN, 1,
887 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
888 },
889 { "shlb", TILEPRO_OPC_SHLB, 0x3, 3, TREG_ZERO, 1,
890 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
891 },
892 { "shlb.sn", TILEPRO_OPC_SHLB_SN, 0x3, 3, TREG_SN, 1,
893 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
894 },
895 { "shlh", TILEPRO_OPC_SHLH, 0x3, 3, TREG_ZERO, 1,
896 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
897 },
898 { "shlh.sn", TILEPRO_OPC_SHLH_SN, 0x3, 3, TREG_SN, 1,
899 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
900 },
901 { "shli", TILEPRO_OPC_SHLI, 0xf, 3, TREG_ZERO, 1,
902 { { 7, 8, 32 }, { 9, 10, 33 }, { 11, 12, 34 }, { 13, 14, 35 }, { 0, } },
903 },
904 { "shli.sn", TILEPRO_OPC_SHLI_SN, 0x3, 3, TREG_SN, 1,
905 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
906 },
907 { "shlib", TILEPRO_OPC_SHLIB, 0x3, 3, TREG_ZERO, 1,
908 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
909 },
910 { "shlib.sn", TILEPRO_OPC_SHLIB_SN, 0x3, 3, TREG_SN, 1,
911 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
912 },
913 { "shlih", TILEPRO_OPC_SHLIH, 0x3, 3, TREG_ZERO, 1,
914 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
915 },
916 { "shlih.sn", TILEPRO_OPC_SHLIH_SN, 0x3, 3, TREG_SN, 1,
917 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
918 },
919 { "shr", TILEPRO_OPC_SHR, 0xf, 3, TREG_ZERO, 1,
920 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
921 },
922 { "shr.sn", TILEPRO_OPC_SHR_SN, 0x3, 3, TREG_SN, 1,
923 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
924 },
925 { "shrb", TILEPRO_OPC_SHRB, 0x3, 3, TREG_ZERO, 1,
926 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
927 },
928 { "shrb.sn", TILEPRO_OPC_SHRB_SN, 0x3, 3, TREG_SN, 1,
929 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
930 },
931 { "shrh", TILEPRO_OPC_SHRH, 0x3, 3, TREG_ZERO, 1,
932 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
933 },
934 { "shrh.sn", TILEPRO_OPC_SHRH_SN, 0x3, 3, TREG_SN, 1,
935 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
936 },
937 { "shri", TILEPRO_OPC_SHRI, 0xf, 3, TREG_ZERO, 1,
938 { { 7, 8, 32 }, { 9, 10, 33 }, { 11, 12, 34 }, { 13, 14, 35 }, { 0, } },
939 },
940 { "shri.sn", TILEPRO_OPC_SHRI_SN, 0x3, 3, TREG_SN, 1,
941 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
942 },
943 { "shrib", TILEPRO_OPC_SHRIB, 0x3, 3, TREG_ZERO, 1,
944 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
945 },
946 { "shrib.sn", TILEPRO_OPC_SHRIB_SN, 0x3, 3, TREG_SN, 1,
947 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
948 },
949 { "shrih", TILEPRO_OPC_SHRIH, 0x3, 3, TREG_ZERO, 1,
950 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
951 },
952 { "shrih.sn", TILEPRO_OPC_SHRIH_SN, 0x3, 3, TREG_SN, 1,
953 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
954 },
955 { "slt", TILEPRO_OPC_SLT, 0xf, 3, TREG_ZERO, 1,
956 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
957 },
958 { "slt.sn", TILEPRO_OPC_SLT_SN, 0x3, 3, TREG_SN, 1,
959 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
960 },
961 { "slt_u", TILEPRO_OPC_SLT_U, 0xf, 3, TREG_ZERO, 1,
962 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
963 },
964 { "slt_u.sn", TILEPRO_OPC_SLT_U_SN, 0x3, 3, TREG_SN, 1,
965 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
966 },
967 { "sltb", TILEPRO_OPC_SLTB, 0x3, 3, TREG_ZERO, 1,
968 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
969 },
970 { "sltb.sn", TILEPRO_OPC_SLTB_SN, 0x3, 3, TREG_SN, 1,
971 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
972 },
973 { "sltb_u", TILEPRO_OPC_SLTB_U, 0x3, 3, TREG_ZERO, 1,
974 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
975 },
976 { "sltb_u.sn", TILEPRO_OPC_SLTB_U_SN, 0x3, 3, TREG_SN, 1,
977 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
978 },
979 { "slte", TILEPRO_OPC_SLTE, 0xf, 3, TREG_ZERO, 1,
980 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
981 },
982 { "slte.sn", TILEPRO_OPC_SLTE_SN, 0x3, 3, TREG_SN, 1,
983 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
984 },
985 { "slte_u", TILEPRO_OPC_SLTE_U, 0xf, 3, TREG_ZERO, 1,
986 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
987 },
988 { "slte_u.sn", TILEPRO_OPC_SLTE_U_SN, 0x3, 3, TREG_SN, 1,
989 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
990 },
991 { "slteb", TILEPRO_OPC_SLTEB, 0x3, 3, TREG_ZERO, 1,
992 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
993 },
994 { "slteb.sn", TILEPRO_OPC_SLTEB_SN, 0x3, 3, TREG_SN, 1,
995 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
996 },
997 { "slteb_u", TILEPRO_OPC_SLTEB_U, 0x3, 3, TREG_ZERO, 1,
998 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
999 },
1000 { "slteb_u.sn", TILEPRO_OPC_SLTEB_U_SN, 0x3, 3, TREG_SN, 1,
1001 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1002 },
1003 { "slteh", TILEPRO_OPC_SLTEH, 0x3, 3, TREG_ZERO, 1,
1004 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1005 },
1006 { "slteh.sn", TILEPRO_OPC_SLTEH_SN, 0x3, 3, TREG_SN, 1,
1007 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1008 },
1009 { "slteh_u", TILEPRO_OPC_SLTEH_U, 0x3, 3, TREG_ZERO, 1,
1010 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1011 },
1012 { "slteh_u.sn", TILEPRO_OPC_SLTEH_U_SN, 0x3, 3, TREG_SN, 1,
1013 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1014 },
1015 { "slth", TILEPRO_OPC_SLTH, 0x3, 3, TREG_ZERO, 1,
1016 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1017 },
1018 { "slth.sn", TILEPRO_OPC_SLTH_SN, 0x3, 3, TREG_SN, 1,
1019 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1020 },
1021 { "slth_u", TILEPRO_OPC_SLTH_U, 0x3, 3, TREG_ZERO, 1,
1022 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1023 },
1024 { "slth_u.sn", TILEPRO_OPC_SLTH_U_SN, 0x3, 3, TREG_SN, 1,
1025 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1026 },
1027 { "slti", TILEPRO_OPC_SLTI, 0xf, 3, TREG_ZERO, 1,
1028 { { 7, 8, 0 }, { 9, 10, 1 }, { 11, 12, 2 }, { 13, 14, 3 }, { 0, } },
1029 },
1030 { "slti.sn", TILEPRO_OPC_SLTI_SN, 0x3, 3, TREG_SN, 1,
1031 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1032 },
1033 { "slti_u", TILEPRO_OPC_SLTI_U, 0xf, 3, TREG_ZERO, 1,
1034 { { 7, 8, 0 }, { 9, 10, 1 }, { 11, 12, 2 }, { 13, 14, 3 }, { 0, } },
1035 },
1036 { "slti_u.sn", TILEPRO_OPC_SLTI_U_SN, 0x3, 3, TREG_SN, 1,
1037 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1038 },
1039 { "sltib", TILEPRO_OPC_SLTIB, 0x3, 3, TREG_ZERO, 1,
1040 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1041 },
1042 { "sltib.sn", TILEPRO_OPC_SLTIB_SN, 0x3, 3, TREG_SN, 1,
1043 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1044 },
1045 { "sltib_u", TILEPRO_OPC_SLTIB_U, 0x3, 3, TREG_ZERO, 1,
1046 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1047 },
1048 { "sltib_u.sn", TILEPRO_OPC_SLTIB_U_SN, 0x3, 3, TREG_SN, 1,
1049 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1050 },
1051 { "sltih", TILEPRO_OPC_SLTIH, 0x3, 3, TREG_ZERO, 1,
1052 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1053 },
1054 { "sltih.sn", TILEPRO_OPC_SLTIH_SN, 0x3, 3, TREG_SN, 1,
1055 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1056 },
1057 { "sltih_u", TILEPRO_OPC_SLTIH_U, 0x3, 3, TREG_ZERO, 1,
1058 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1059 },
1060 { "sltih_u.sn", TILEPRO_OPC_SLTIH_U_SN, 0x3, 3, TREG_SN, 1,
1061 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1062 },
1063 { "sne", TILEPRO_OPC_SNE, 0xf, 3, TREG_ZERO, 1,
1064 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
1065 },
1066 { "sne.sn", TILEPRO_OPC_SNE_SN, 0x3, 3, TREG_SN, 1,
1067 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1068 },
1069 { "sneb", TILEPRO_OPC_SNEB, 0x3, 3, TREG_ZERO, 1,
1070 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1071 },
1072 { "sneb.sn", TILEPRO_OPC_SNEB_SN, 0x3, 3, TREG_SN, 1,
1073 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1074 },
1075 { "sneh", TILEPRO_OPC_SNEH, 0x3, 3, TREG_ZERO, 1,
1076 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1077 },
1078 { "sneh.sn", TILEPRO_OPC_SNEH_SN, 0x3, 3, TREG_SN, 1,
1079 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1080 },
1081 { "sra", TILEPRO_OPC_SRA, 0xf, 3, TREG_ZERO, 1,
1082 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
1083 },
1084 { "sra.sn", TILEPRO_OPC_SRA_SN, 0x3, 3, TREG_SN, 1,
1085 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1086 },
1087 { "srab", TILEPRO_OPC_SRAB, 0x3, 3, TREG_ZERO, 1,
1088 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1089 },
1090 { "srab.sn", TILEPRO_OPC_SRAB_SN, 0x3, 3, TREG_SN, 1,
1091 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1092 },
1093 { "srah", TILEPRO_OPC_SRAH, 0x3, 3, TREG_ZERO, 1,
1094 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1095 },
1096 { "srah.sn", TILEPRO_OPC_SRAH_SN, 0x3, 3, TREG_SN, 1,
1097 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1098 },
1099 { "srai", TILEPRO_OPC_SRAI, 0xf, 3, TREG_ZERO, 1,
1100 { { 7, 8, 32 }, { 9, 10, 33 }, { 11, 12, 34 }, { 13, 14, 35 }, { 0, } },
1101 },
1102 { "srai.sn", TILEPRO_OPC_SRAI_SN, 0x3, 3, TREG_SN, 1,
1103 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
1104 },
1105 { "sraib", TILEPRO_OPC_SRAIB, 0x3, 3, TREG_ZERO, 1,
1106 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
1107 },
1108 { "sraib.sn", TILEPRO_OPC_SRAIB_SN, 0x3, 3, TREG_SN, 1,
1109 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
1110 },
1111 { "sraih", TILEPRO_OPC_SRAIH, 0x3, 3, TREG_ZERO, 1,
1112 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
1113 },
1114 { "sraih.sn", TILEPRO_OPC_SRAIH_SN, 0x3, 3, TREG_SN, 1,
1115 { { 7, 8, 32 }, { 9, 10, 33 }, { 0, }, { 0, }, { 0, } },
1116 },
1117 { "sub", TILEPRO_OPC_SUB, 0xf, 3, TREG_ZERO, 1,
1118 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
1119 },
1120 { "sub.sn", TILEPRO_OPC_SUB_SN, 0x3, 3, TREG_SN, 1,
1121 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1122 },
1123 { "subb", TILEPRO_OPC_SUBB, 0x3, 3, TREG_ZERO, 1,
1124 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1125 },
1126 { "subb.sn", TILEPRO_OPC_SUBB_SN, 0x3, 3, TREG_SN, 1,
1127 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1128 },
1129 { "subbs_u", TILEPRO_OPC_SUBBS_U, 0x3, 3, TREG_ZERO, 1,
1130 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1131 },
1132 { "subbs_u.sn", TILEPRO_OPC_SUBBS_U_SN, 0x3, 3, TREG_SN, 1,
1133 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1134 },
1135 { "subh", TILEPRO_OPC_SUBH, 0x3, 3, TREG_ZERO, 1,
1136 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1137 },
1138 { "subh.sn", TILEPRO_OPC_SUBH_SN, 0x3, 3, TREG_SN, 1,
1139 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1140 },
1141 { "subhs", TILEPRO_OPC_SUBHS, 0x3, 3, TREG_ZERO, 1,
1142 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1143 },
1144 { "subhs.sn", TILEPRO_OPC_SUBHS_SN, 0x3, 3, TREG_SN, 1,
1145 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1146 },
1147 { "subs", TILEPRO_OPC_SUBS, 0x3, 3, TREG_ZERO, 1,
1148 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1149 },
1150 { "subs.sn", TILEPRO_OPC_SUBS_SN, 0x3, 3, TREG_SN, 1,
1151 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1152 },
1153 { "sw", TILEPRO_OPC_SW, 0x12, 2, TREG_ZERO, 1,
1154 { { 0, }, { 10, 17 }, { 0, }, { 0, }, { 15, 36 } },
1155 },
1156 { "swadd", TILEPRO_OPC_SWADD, 0x2, 3, TREG_ZERO, 1,
1157 { { 0, }, { 24, 17, 37 }, { 0, }, { 0, }, { 0, } },
1158 },
1159 { "swint0", TILEPRO_OPC_SWINT0, 0x2, 0, TREG_ZERO, 0,
1160 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
1161 },
1162 { "swint1", TILEPRO_OPC_SWINT1, 0x2, 0, TREG_ZERO, 0,
1163 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
1164 },
1165 { "swint2", TILEPRO_OPC_SWINT2, 0x2, 0, TREG_ZERO, 0,
1166 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
1167 },
1168 { "swint3", TILEPRO_OPC_SWINT3, 0x2, 0, TREG_ZERO, 0,
1169 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
1170 },
1171 { "tblidxb0", TILEPRO_OPC_TBLIDXB0, 0x5, 2, TREG_ZERO, 1,
1172 { { 21, 8 }, { 0, }, { 31, 12 }, { 0, }, { 0, } },
1173 },
1174 { "tblidxb0.sn", TILEPRO_OPC_TBLIDXB0_SN, 0x1, 2, TREG_SN, 1,
1175 { { 21, 8 }, { 0, }, { 0, }, { 0, }, { 0, } },
1176 },
1177 { "tblidxb1", TILEPRO_OPC_TBLIDXB1, 0x5, 2, TREG_ZERO, 1,
1178 { { 21, 8 }, { 0, }, { 31, 12 }, { 0, }, { 0, } },
1179 },
1180 { "tblidxb1.sn", TILEPRO_OPC_TBLIDXB1_SN, 0x1, 2, TREG_SN, 1,
1181 { { 21, 8 }, { 0, }, { 0, }, { 0, }, { 0, } },
1182 },
1183 { "tblidxb2", TILEPRO_OPC_TBLIDXB2, 0x5, 2, TREG_ZERO, 1,
1184 { { 21, 8 }, { 0, }, { 31, 12 }, { 0, }, { 0, } },
1185 },
1186 { "tblidxb2.sn", TILEPRO_OPC_TBLIDXB2_SN, 0x1, 2, TREG_SN, 1,
1187 { { 21, 8 }, { 0, }, { 0, }, { 0, }, { 0, } },
1188 },
1189 { "tblidxb3", TILEPRO_OPC_TBLIDXB3, 0x5, 2, TREG_ZERO, 1,
1190 { { 21, 8 }, { 0, }, { 31, 12 }, { 0, }, { 0, } },
1191 },
1192 { "tblidxb3.sn", TILEPRO_OPC_TBLIDXB3_SN, 0x1, 2, TREG_SN, 1,
1193 { { 21, 8 }, { 0, }, { 0, }, { 0, }, { 0, } },
1194 },
1195 { "tns", TILEPRO_OPC_TNS, 0x2, 2, TREG_ZERO, 1,
1196 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
1197 },
1198 { "tns.sn", TILEPRO_OPC_TNS_SN, 0x2, 2, TREG_SN, 1,
1199 { { 0, }, { 9, 10 }, { 0, }, { 0, }, { 0, } },
1200 },
1201 { "wh64", TILEPRO_OPC_WH64, 0x2, 1, TREG_ZERO, 1,
1202 { { 0, }, { 10 }, { 0, }, { 0, }, { 0, } },
1203 },
1204 { "xor", TILEPRO_OPC_XOR, 0xf, 3, TREG_ZERO, 1,
1205 { { 7, 8, 16 }, { 9, 10, 17 }, { 11, 12, 18 }, { 13, 14, 19 }, { 0, } },
1206 },
1207 { "xor.sn", TILEPRO_OPC_XOR_SN, 0x3, 3, TREG_SN, 1,
1208 { { 7, 8, 16 }, { 9, 10, 17 }, { 0, }, { 0, }, { 0, } },
1209 },
1210 { "xori", TILEPRO_OPC_XORI, 0x3, 3, TREG_ZERO, 1,
1211 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1212 },
1213 { "xori.sn", TILEPRO_OPC_XORI_SN, 0x3, 3, TREG_SN, 1,
1214 { { 7, 8, 0 }, { 9, 10, 1 }, { 0, }, { 0, }, { 0, } },
1215 },
1216 { NULL, TILEPRO_OPC_NONE, 0, 0, TREG_ZERO, 0, { { 0, } },
1217 }
1218};
1219#define BITFIELD(start, size) ((start) | (((1 << (size)) - 1) << 6))
1220#define CHILD(array_index) (TILEPRO_OPC_NONE + (array_index))
1221
1222static const unsigned short decode_X0_fsm[1153] =
1223{
1224 BITFIELD(22, 9) /* index 0 */,
1225 CHILD(513), CHILD(530), CHILD(547), CHILD(564), CHILD(596), CHILD(613),
1226 CHILD(630), TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1227 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1228 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1229 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1230 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1231 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1232 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, CHILD(663), CHILD(680), CHILD(697),
1233 CHILD(714), CHILD(746), CHILD(763), CHILD(780), TILEPRO_OPC_NONE,
1234 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1235 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1236 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1237 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1238 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1239 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1240 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1241 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1242 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1243 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1244 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1245 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1246 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1247 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1248 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1249 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(813),
1250 CHILD(813), CHILD(813), CHILD(813), CHILD(813), CHILD(828), CHILD(828),
1251 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1252 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1253 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1254 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1255 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1256 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1257 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1258 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1259 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1260 CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828), CHILD(828),
1261 CHILD(828), CHILD(828), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1262 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1263 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1264 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1265 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1266 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1267 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1268 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1269 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1270 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1271 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1272 CHILD(873), CHILD(878), CHILD(883), CHILD(903), CHILD(908),
1273 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1274 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1275 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1276 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1277 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1278 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1279 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, CHILD(913),
1280 CHILD(918), CHILD(923), CHILD(943), CHILD(948), TILEPRO_OPC_NONE,
1281 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1282 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1283 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1284 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1285 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1286 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1287 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, CHILD(953), TILEPRO_OPC_NONE,
1288 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1289 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1290 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1291 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1292 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1293 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1294 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1295 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, CHILD(988), TILEPRO_OPC_NONE,
1296 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1297 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1298 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1299 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1300 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1301 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1302 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1303 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1304 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1305 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1306 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1307 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1308 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1309 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1310 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1311 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1312 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1313 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1314 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1315 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1316 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1317 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1318 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1319 TILEPRO_OPC_MM, TILEPRO_OPC_MM, CHILD(993), TILEPRO_OPC_NONE,
1320 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1321 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1322 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1323 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1324 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1325 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1326 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1327 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, CHILD(1076), TILEPRO_OPC_NONE,
1328 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1329 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1330 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1331 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1332 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1333 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1334 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1335 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1336 BITFIELD(18, 4) /* index 513 */,
1337 TILEPRO_OPC_NONE, TILEPRO_OPC_ADDB, TILEPRO_OPC_ADDH, TILEPRO_OPC_ADD,
1338 TILEPRO_OPC_ADIFFB_U, TILEPRO_OPC_ADIFFH, TILEPRO_OPC_AND,
1339 TILEPRO_OPC_AVGB_U, TILEPRO_OPC_AVGH, TILEPRO_OPC_CRC32_32,
1340 TILEPRO_OPC_CRC32_8, TILEPRO_OPC_INTHB, TILEPRO_OPC_INTHH,
1341 TILEPRO_OPC_INTLB, TILEPRO_OPC_INTLH, TILEPRO_OPC_MAXB_U,
1342 BITFIELD(18, 4) /* index 530 */,
1343 TILEPRO_OPC_MAXH, TILEPRO_OPC_MINB_U, TILEPRO_OPC_MINH, TILEPRO_OPC_MNZB,
1344 TILEPRO_OPC_MNZH, TILEPRO_OPC_MNZ, TILEPRO_OPC_MULHHA_SS,
1345 TILEPRO_OPC_MULHHA_SU, TILEPRO_OPC_MULHHA_UU, TILEPRO_OPC_MULHHSA_UU,
1346 TILEPRO_OPC_MULHH_SS, TILEPRO_OPC_MULHH_SU, TILEPRO_OPC_MULHH_UU,
1347 TILEPRO_OPC_MULHLA_SS, TILEPRO_OPC_MULHLA_SU, TILEPRO_OPC_MULHLA_US,
1348 BITFIELD(18, 4) /* index 547 */,
1349 TILEPRO_OPC_MULHLA_UU, TILEPRO_OPC_MULHLSA_UU, TILEPRO_OPC_MULHL_SS,
1350 TILEPRO_OPC_MULHL_SU, TILEPRO_OPC_MULHL_US, TILEPRO_OPC_MULHL_UU,
1351 TILEPRO_OPC_MULLLA_SS, TILEPRO_OPC_MULLLA_SU, TILEPRO_OPC_MULLLA_UU,
1352 TILEPRO_OPC_MULLLSA_UU, TILEPRO_OPC_MULLL_SS, TILEPRO_OPC_MULLL_SU,
1353 TILEPRO_OPC_MULLL_UU, TILEPRO_OPC_MVNZ, TILEPRO_OPC_MVZ, TILEPRO_OPC_MZB,
1354 BITFIELD(18, 4) /* index 564 */,
1355 TILEPRO_OPC_MZH, TILEPRO_OPC_MZ, TILEPRO_OPC_NOR, CHILD(581),
1356 TILEPRO_OPC_PACKHB, TILEPRO_OPC_PACKLB, TILEPRO_OPC_RL, TILEPRO_OPC_S1A,
1357 TILEPRO_OPC_S2A, TILEPRO_OPC_S3A, TILEPRO_OPC_SADAB_U, TILEPRO_OPC_SADAH,
1358 TILEPRO_OPC_SADAH_U, TILEPRO_OPC_SADB_U, TILEPRO_OPC_SADH,
1359 TILEPRO_OPC_SADH_U,
1360 BITFIELD(12, 2) /* index 581 */,
1361 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, CHILD(586),
1362 BITFIELD(14, 2) /* index 586 */,
1363 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, CHILD(591),
1364 BITFIELD(16, 2) /* index 591 */,
1365 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_MOVE,
1366 BITFIELD(18, 4) /* index 596 */,
1367 TILEPRO_OPC_SEQB, TILEPRO_OPC_SEQH, TILEPRO_OPC_SEQ, TILEPRO_OPC_SHLB,
1368 TILEPRO_OPC_SHLH, TILEPRO_OPC_SHL, TILEPRO_OPC_SHRB, TILEPRO_OPC_SHRH,
1369 TILEPRO_OPC_SHR, TILEPRO_OPC_SLTB, TILEPRO_OPC_SLTB_U, TILEPRO_OPC_SLTEB,
1370 TILEPRO_OPC_SLTEB_U, TILEPRO_OPC_SLTEH, TILEPRO_OPC_SLTEH_U,
1371 TILEPRO_OPC_SLTE,
1372 BITFIELD(18, 4) /* index 613 */,
1373 TILEPRO_OPC_SLTE_U, TILEPRO_OPC_SLTH, TILEPRO_OPC_SLTH_U, TILEPRO_OPC_SLT,
1374 TILEPRO_OPC_SLT_U, TILEPRO_OPC_SNEB, TILEPRO_OPC_SNEH, TILEPRO_OPC_SNE,
1375 TILEPRO_OPC_SRAB, TILEPRO_OPC_SRAH, TILEPRO_OPC_SRA, TILEPRO_OPC_SUBB,
1376 TILEPRO_OPC_SUBH, TILEPRO_OPC_SUB, TILEPRO_OPC_XOR, TILEPRO_OPC_DWORD_ALIGN,
1377 BITFIELD(18, 3) /* index 630 */,
1378 CHILD(639), CHILD(642), CHILD(645), CHILD(648), CHILD(651), CHILD(654),
1379 CHILD(657), CHILD(660),
1380 BITFIELD(21, 1) /* index 639 */,
1381 TILEPRO_OPC_ADDS, TILEPRO_OPC_NONE,
1382 BITFIELD(21, 1) /* index 642 */,
1383 TILEPRO_OPC_SUBS, TILEPRO_OPC_NONE,
1384 BITFIELD(21, 1) /* index 645 */,
1385 TILEPRO_OPC_ADDBS_U, TILEPRO_OPC_NONE,
1386 BITFIELD(21, 1) /* index 648 */,
1387 TILEPRO_OPC_ADDHS, TILEPRO_OPC_NONE,
1388 BITFIELD(21, 1) /* index 651 */,
1389 TILEPRO_OPC_SUBBS_U, TILEPRO_OPC_NONE,
1390 BITFIELD(21, 1) /* index 654 */,
1391 TILEPRO_OPC_SUBHS, TILEPRO_OPC_NONE,
1392 BITFIELD(21, 1) /* index 657 */,
1393 TILEPRO_OPC_PACKHS, TILEPRO_OPC_NONE,
1394 BITFIELD(21, 1) /* index 660 */,
1395 TILEPRO_OPC_PACKBS_U, TILEPRO_OPC_NONE,
1396 BITFIELD(18, 4) /* index 663 */,
1397 TILEPRO_OPC_NONE, TILEPRO_OPC_ADDB_SN, TILEPRO_OPC_ADDH_SN,
1398 TILEPRO_OPC_ADD_SN, TILEPRO_OPC_ADIFFB_U_SN, TILEPRO_OPC_ADIFFH_SN,
1399 TILEPRO_OPC_AND_SN, TILEPRO_OPC_AVGB_U_SN, TILEPRO_OPC_AVGH_SN,
1400 TILEPRO_OPC_CRC32_32_SN, TILEPRO_OPC_CRC32_8_SN, TILEPRO_OPC_INTHB_SN,
1401 TILEPRO_OPC_INTHH_SN, TILEPRO_OPC_INTLB_SN, TILEPRO_OPC_INTLH_SN,
1402 TILEPRO_OPC_MAXB_U_SN,
1403 BITFIELD(18, 4) /* index 680 */,
1404 TILEPRO_OPC_MAXH_SN, TILEPRO_OPC_MINB_U_SN, TILEPRO_OPC_MINH_SN,
1405 TILEPRO_OPC_MNZB_SN, TILEPRO_OPC_MNZH_SN, TILEPRO_OPC_MNZ_SN,
1406 TILEPRO_OPC_MULHHA_SS_SN, TILEPRO_OPC_MULHHA_SU_SN,
1407 TILEPRO_OPC_MULHHA_UU_SN, TILEPRO_OPC_MULHHSA_UU_SN,
1408 TILEPRO_OPC_MULHH_SS_SN, TILEPRO_OPC_MULHH_SU_SN, TILEPRO_OPC_MULHH_UU_SN,
1409 TILEPRO_OPC_MULHLA_SS_SN, TILEPRO_OPC_MULHLA_SU_SN,
1410 TILEPRO_OPC_MULHLA_US_SN,
1411 BITFIELD(18, 4) /* index 697 */,
1412 TILEPRO_OPC_MULHLA_UU_SN, TILEPRO_OPC_MULHLSA_UU_SN,
1413 TILEPRO_OPC_MULHL_SS_SN, TILEPRO_OPC_MULHL_SU_SN, TILEPRO_OPC_MULHL_US_SN,
1414 TILEPRO_OPC_MULHL_UU_SN, TILEPRO_OPC_MULLLA_SS_SN, TILEPRO_OPC_MULLLA_SU_SN,
1415 TILEPRO_OPC_MULLLA_UU_SN, TILEPRO_OPC_MULLLSA_UU_SN,
1416 TILEPRO_OPC_MULLL_SS_SN, TILEPRO_OPC_MULLL_SU_SN, TILEPRO_OPC_MULLL_UU_SN,
1417 TILEPRO_OPC_MVNZ_SN, TILEPRO_OPC_MVZ_SN, TILEPRO_OPC_MZB_SN,
1418 BITFIELD(18, 4) /* index 714 */,
1419 TILEPRO_OPC_MZH_SN, TILEPRO_OPC_MZ_SN, TILEPRO_OPC_NOR_SN, CHILD(731),
1420 TILEPRO_OPC_PACKHB_SN, TILEPRO_OPC_PACKLB_SN, TILEPRO_OPC_RL_SN,
1421 TILEPRO_OPC_S1A_SN, TILEPRO_OPC_S2A_SN, TILEPRO_OPC_S3A_SN,
1422 TILEPRO_OPC_SADAB_U_SN, TILEPRO_OPC_SADAH_SN, TILEPRO_OPC_SADAH_U_SN,
1423 TILEPRO_OPC_SADB_U_SN, TILEPRO_OPC_SADH_SN, TILEPRO_OPC_SADH_U_SN,
1424 BITFIELD(12, 2) /* index 731 */,
1425 TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, CHILD(736),
1426 BITFIELD(14, 2) /* index 736 */,
1427 TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, CHILD(741),
1428 BITFIELD(16, 2) /* index 741 */,
1429 TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN,
1430 TILEPRO_OPC_MOVE_SN,
1431 BITFIELD(18, 4) /* index 746 */,
1432 TILEPRO_OPC_SEQB_SN, TILEPRO_OPC_SEQH_SN, TILEPRO_OPC_SEQ_SN,
1433 TILEPRO_OPC_SHLB_SN, TILEPRO_OPC_SHLH_SN, TILEPRO_OPC_SHL_SN,
1434 TILEPRO_OPC_SHRB_SN, TILEPRO_OPC_SHRH_SN, TILEPRO_OPC_SHR_SN,
1435 TILEPRO_OPC_SLTB_SN, TILEPRO_OPC_SLTB_U_SN, TILEPRO_OPC_SLTEB_SN,
1436 TILEPRO_OPC_SLTEB_U_SN, TILEPRO_OPC_SLTEH_SN, TILEPRO_OPC_SLTEH_U_SN,
1437 TILEPRO_OPC_SLTE_SN,
1438 BITFIELD(18, 4) /* index 763 */,
1439 TILEPRO_OPC_SLTE_U_SN, TILEPRO_OPC_SLTH_SN, TILEPRO_OPC_SLTH_U_SN,
1440 TILEPRO_OPC_SLT_SN, TILEPRO_OPC_SLT_U_SN, TILEPRO_OPC_SNEB_SN,
1441 TILEPRO_OPC_SNEH_SN, TILEPRO_OPC_SNE_SN, TILEPRO_OPC_SRAB_SN,
1442 TILEPRO_OPC_SRAH_SN, TILEPRO_OPC_SRA_SN, TILEPRO_OPC_SUBB_SN,
1443 TILEPRO_OPC_SUBH_SN, TILEPRO_OPC_SUB_SN, TILEPRO_OPC_XOR_SN,
1444 TILEPRO_OPC_DWORD_ALIGN_SN,
1445 BITFIELD(18, 3) /* index 780 */,
1446 CHILD(789), CHILD(792), CHILD(795), CHILD(798), CHILD(801), CHILD(804),
1447 CHILD(807), CHILD(810),
1448 BITFIELD(21, 1) /* index 789 */,
1449 TILEPRO_OPC_ADDS_SN, TILEPRO_OPC_NONE,
1450 BITFIELD(21, 1) /* index 792 */,
1451 TILEPRO_OPC_SUBS_SN, TILEPRO_OPC_NONE,
1452 BITFIELD(21, 1) /* index 795 */,
1453 TILEPRO_OPC_ADDBS_U_SN, TILEPRO_OPC_NONE,
1454 BITFIELD(21, 1) /* index 798 */,
1455 TILEPRO_OPC_ADDHS_SN, TILEPRO_OPC_NONE,
1456 BITFIELD(21, 1) /* index 801 */,
1457 TILEPRO_OPC_SUBBS_U_SN, TILEPRO_OPC_NONE,
1458 BITFIELD(21, 1) /* index 804 */,
1459 TILEPRO_OPC_SUBHS_SN, TILEPRO_OPC_NONE,
1460 BITFIELD(21, 1) /* index 807 */,
1461 TILEPRO_OPC_PACKHS_SN, TILEPRO_OPC_NONE,
1462 BITFIELD(21, 1) /* index 810 */,
1463 TILEPRO_OPC_PACKBS_U_SN, TILEPRO_OPC_NONE,
1464 BITFIELD(6, 2) /* index 813 */,
1465 TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN,
1466 CHILD(818),
1467 BITFIELD(8, 2) /* index 818 */,
1468 TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN,
1469 CHILD(823),
1470 BITFIELD(10, 2) /* index 823 */,
1471 TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN,
1472 TILEPRO_OPC_MOVELI_SN,
1473 BITFIELD(6, 2) /* index 828 */,
1474 TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, CHILD(833),
1475 BITFIELD(8, 2) /* index 833 */,
1476 TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, CHILD(838),
1477 BITFIELD(10, 2) /* index 838 */,
1478 TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, TILEPRO_OPC_MOVELI,
1479 BITFIELD(0, 2) /* index 843 */,
1480 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(848),
1481 BITFIELD(2, 2) /* index 848 */,
1482 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(853),
1483 BITFIELD(4, 2) /* index 853 */,
1484 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(858),
1485 BITFIELD(6, 2) /* index 858 */,
1486 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(863),
1487 BITFIELD(8, 2) /* index 863 */,
1488 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(868),
1489 BITFIELD(10, 2) /* index 868 */,
1490 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_INFOL,
1491 BITFIELD(20, 2) /* index 873 */,
1492 TILEPRO_OPC_NONE, TILEPRO_OPC_ADDIB, TILEPRO_OPC_ADDIH, TILEPRO_OPC_ADDI,
1493 BITFIELD(20, 2) /* index 878 */,
1494 TILEPRO_OPC_MAXIB_U, TILEPRO_OPC_MAXIH, TILEPRO_OPC_MINIB_U,
1495 TILEPRO_OPC_MINIH,
1496 BITFIELD(20, 2) /* index 883 */,
1497 CHILD(888), TILEPRO_OPC_SEQIB, TILEPRO_OPC_SEQIH, TILEPRO_OPC_SEQI,
1498 BITFIELD(6, 2) /* index 888 */,
1499 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, CHILD(893),
1500 BITFIELD(8, 2) /* index 893 */,
1501 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, CHILD(898),
1502 BITFIELD(10, 2) /* index 898 */,
1503 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_MOVEI,
1504 BITFIELD(20, 2) /* index 903 */,
1505 TILEPRO_OPC_SLTIB, TILEPRO_OPC_SLTIB_U, TILEPRO_OPC_SLTIH,
1506 TILEPRO_OPC_SLTIH_U,
1507 BITFIELD(20, 2) /* index 908 */,
1508 TILEPRO_OPC_SLTI, TILEPRO_OPC_SLTI_U, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1509 BITFIELD(20, 2) /* index 913 */,
1510 TILEPRO_OPC_NONE, TILEPRO_OPC_ADDIB_SN, TILEPRO_OPC_ADDIH_SN,
1511 TILEPRO_OPC_ADDI_SN,
1512 BITFIELD(20, 2) /* index 918 */,
1513 TILEPRO_OPC_MAXIB_U_SN, TILEPRO_OPC_MAXIH_SN, TILEPRO_OPC_MINIB_U_SN,
1514 TILEPRO_OPC_MINIH_SN,
1515 BITFIELD(20, 2) /* index 923 */,
1516 CHILD(928), TILEPRO_OPC_SEQIB_SN, TILEPRO_OPC_SEQIH_SN, TILEPRO_OPC_SEQI_SN,
1517 BITFIELD(6, 2) /* index 928 */,
1518 TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, CHILD(933),
1519 BITFIELD(8, 2) /* index 933 */,
1520 TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, CHILD(938),
1521 BITFIELD(10, 2) /* index 938 */,
1522 TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN,
1523 TILEPRO_OPC_MOVEI_SN,
1524 BITFIELD(20, 2) /* index 943 */,
1525 TILEPRO_OPC_SLTIB_SN, TILEPRO_OPC_SLTIB_U_SN, TILEPRO_OPC_SLTIH_SN,
1526 TILEPRO_OPC_SLTIH_U_SN,
1527 BITFIELD(20, 2) /* index 948 */,
1528 TILEPRO_OPC_SLTI_SN, TILEPRO_OPC_SLTI_U_SN, TILEPRO_OPC_NONE,
1529 TILEPRO_OPC_NONE,
1530 BITFIELD(20, 2) /* index 953 */,
1531 TILEPRO_OPC_NONE, CHILD(958), TILEPRO_OPC_XORI, TILEPRO_OPC_NONE,
1532 BITFIELD(0, 2) /* index 958 */,
1533 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(963),
1534 BITFIELD(2, 2) /* index 963 */,
1535 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(968),
1536 BITFIELD(4, 2) /* index 968 */,
1537 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(973),
1538 BITFIELD(6, 2) /* index 973 */,
1539 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(978),
1540 BITFIELD(8, 2) /* index 978 */,
1541 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(983),
1542 BITFIELD(10, 2) /* index 983 */,
1543 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_INFO,
1544 BITFIELD(20, 2) /* index 988 */,
1545 TILEPRO_OPC_NONE, TILEPRO_OPC_ANDI_SN, TILEPRO_OPC_XORI_SN,
1546 TILEPRO_OPC_NONE,
1547 BITFIELD(17, 5) /* index 993 */,
1548 TILEPRO_OPC_NONE, TILEPRO_OPC_RLI, TILEPRO_OPC_SHLIB, TILEPRO_OPC_SHLIH,
1549 TILEPRO_OPC_SHLI, TILEPRO_OPC_SHRIB, TILEPRO_OPC_SHRIH, TILEPRO_OPC_SHRI,
1550 TILEPRO_OPC_SRAIB, TILEPRO_OPC_SRAIH, TILEPRO_OPC_SRAI, CHILD(1026),
1551 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1552 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1553 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1554 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1555 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1556 BITFIELD(12, 4) /* index 1026 */,
1557 TILEPRO_OPC_NONE, CHILD(1043), CHILD(1046), CHILD(1049), CHILD(1052),
1558 CHILD(1055), CHILD(1058), CHILD(1061), CHILD(1064), CHILD(1067),
1559 CHILD(1070), CHILD(1073), TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1560 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1561 BITFIELD(16, 1) /* index 1043 */,
1562 TILEPRO_OPC_BITX, TILEPRO_OPC_NONE,
1563 BITFIELD(16, 1) /* index 1046 */,
1564 TILEPRO_OPC_BYTEX, TILEPRO_OPC_NONE,
1565 BITFIELD(16, 1) /* index 1049 */,
1566 TILEPRO_OPC_CLZ, TILEPRO_OPC_NONE,
1567 BITFIELD(16, 1) /* index 1052 */,
1568 TILEPRO_OPC_CTZ, TILEPRO_OPC_NONE,
1569 BITFIELD(16, 1) /* index 1055 */,
1570 TILEPRO_OPC_FNOP, TILEPRO_OPC_NONE,
1571 BITFIELD(16, 1) /* index 1058 */,
1572 TILEPRO_OPC_NOP, TILEPRO_OPC_NONE,
1573 BITFIELD(16, 1) /* index 1061 */,
1574 TILEPRO_OPC_PCNT, TILEPRO_OPC_NONE,
1575 BITFIELD(16, 1) /* index 1064 */,
1576 TILEPRO_OPC_TBLIDXB0, TILEPRO_OPC_NONE,
1577 BITFIELD(16, 1) /* index 1067 */,
1578 TILEPRO_OPC_TBLIDXB1, TILEPRO_OPC_NONE,
1579 BITFIELD(16, 1) /* index 1070 */,
1580 TILEPRO_OPC_TBLIDXB2, TILEPRO_OPC_NONE,
1581 BITFIELD(16, 1) /* index 1073 */,
1582 TILEPRO_OPC_TBLIDXB3, TILEPRO_OPC_NONE,
1583 BITFIELD(17, 5) /* index 1076 */,
1584 TILEPRO_OPC_NONE, TILEPRO_OPC_RLI_SN, TILEPRO_OPC_SHLIB_SN,
1585 TILEPRO_OPC_SHLIH_SN, TILEPRO_OPC_SHLI_SN, TILEPRO_OPC_SHRIB_SN,
1586 TILEPRO_OPC_SHRIH_SN, TILEPRO_OPC_SHRI_SN, TILEPRO_OPC_SRAIB_SN,
1587 TILEPRO_OPC_SRAIH_SN, TILEPRO_OPC_SRAI_SN, CHILD(1109), TILEPRO_OPC_NONE,
1588 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1589 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1590 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1591 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1592 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1593 BITFIELD(12, 4) /* index 1109 */,
1594 TILEPRO_OPC_NONE, CHILD(1126), CHILD(1129), CHILD(1132), CHILD(1135),
1595 CHILD(1055), CHILD(1058), CHILD(1138), CHILD(1141), CHILD(1144),
1596 CHILD(1147), CHILD(1150), TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1597 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1598 BITFIELD(16, 1) /* index 1126 */,
1599 TILEPRO_OPC_BITX_SN, TILEPRO_OPC_NONE,
1600 BITFIELD(16, 1) /* index 1129 */,
1601 TILEPRO_OPC_BYTEX_SN, TILEPRO_OPC_NONE,
1602 BITFIELD(16, 1) /* index 1132 */,
1603 TILEPRO_OPC_CLZ_SN, TILEPRO_OPC_NONE,
1604 BITFIELD(16, 1) /* index 1135 */,
1605 TILEPRO_OPC_CTZ_SN, TILEPRO_OPC_NONE,
1606 BITFIELD(16, 1) /* index 1138 */,
1607 TILEPRO_OPC_PCNT_SN, TILEPRO_OPC_NONE,
1608 BITFIELD(16, 1) /* index 1141 */,
1609 TILEPRO_OPC_TBLIDXB0_SN, TILEPRO_OPC_NONE,
1610 BITFIELD(16, 1) /* index 1144 */,
1611 TILEPRO_OPC_TBLIDXB1_SN, TILEPRO_OPC_NONE,
1612 BITFIELD(16, 1) /* index 1147 */,
1613 TILEPRO_OPC_TBLIDXB2_SN, TILEPRO_OPC_NONE,
1614 BITFIELD(16, 1) /* index 1150 */,
1615 TILEPRO_OPC_TBLIDXB3_SN, TILEPRO_OPC_NONE,
1616};
1617
1618static const unsigned short decode_X1_fsm[1540] =
1619{
1620 BITFIELD(54, 9) /* index 0 */,
1621 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1622 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1623 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1624 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1625 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1626 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1627 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1628 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1629 CHILD(513), CHILD(561), CHILD(594), TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1630 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1631 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1632 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, CHILD(641),
1633 CHILD(689), CHILD(722), TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1634 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1635 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1636 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, CHILD(766),
1637 CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766),
1638 CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766),
1639 CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766),
1640 CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766),
1641 CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766), CHILD(766),
1642 CHILD(766), CHILD(781), CHILD(781), CHILD(781), CHILD(781), CHILD(781),
1643 CHILD(781), CHILD(781), CHILD(781), CHILD(781), CHILD(781), CHILD(781),
1644 CHILD(781), CHILD(781), CHILD(781), CHILD(781), CHILD(781), CHILD(781),
1645 CHILD(781), CHILD(781), CHILD(781), CHILD(781), CHILD(781), CHILD(781),
1646 CHILD(781), CHILD(781), CHILD(781), CHILD(781), CHILD(781), CHILD(781),
1647 CHILD(781), CHILD(781), CHILD(781), CHILD(796), CHILD(796), CHILD(796),
1648 CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(796),
1649 CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(796),
1650 CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(796),
1651 CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(796),
1652 CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(796), CHILD(826),
1653 CHILD(826), CHILD(826), CHILD(826), CHILD(826), CHILD(826), CHILD(826),
1654 CHILD(826), CHILD(826), CHILD(826), CHILD(826), CHILD(826), CHILD(826),
1655 CHILD(826), CHILD(826), CHILD(826), CHILD(843), CHILD(843), CHILD(843),
1656 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1657 CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843), CHILD(843),
1658 CHILD(843), CHILD(860), CHILD(899), CHILD(923), CHILD(932),
1659 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1660 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1661 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1662 CHILD(941), CHILD(950), CHILD(974), CHILD(983), TILEPRO_OPC_NONE,
1663 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1664 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1665 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_MM,
1666 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1667 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1668 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1669 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1670 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1671 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1672 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM,
1673 TILEPRO_OPC_MM, TILEPRO_OPC_MM, TILEPRO_OPC_MM, CHILD(992),
1674 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1675 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1676 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1677 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, CHILD(1334),
1678 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1679 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1680 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1681 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1682 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1683 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1684 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1685 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1686 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1687 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1688 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1689 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_J,
1690 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1691 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1692 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1693 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1694 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1695 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1696 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1697 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1698 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1699 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1700 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1701 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J,
1702 TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_J, TILEPRO_OPC_JAL,
1703 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1704 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1705 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1706 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1707 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1708 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1709 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1710 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1711 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1712 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1713 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1714 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1715 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1716 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1717 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL,
1718 TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_JAL, TILEPRO_OPC_NONE,
1719 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1720 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1721 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1722 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1723 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1724 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1725 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1726 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1727 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1728 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1729 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1730 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1731 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1732 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1733 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1734 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1735 BITFIELD(49, 5) /* index 513 */,
1736 TILEPRO_OPC_NONE, TILEPRO_OPC_ADDB, TILEPRO_OPC_ADDH, TILEPRO_OPC_ADD,
1737 TILEPRO_OPC_AND, TILEPRO_OPC_INTHB, TILEPRO_OPC_INTHH, TILEPRO_OPC_INTLB,
1738 TILEPRO_OPC_INTLH, TILEPRO_OPC_JALRP, TILEPRO_OPC_JALR, TILEPRO_OPC_JRP,
1739 TILEPRO_OPC_JR, TILEPRO_OPC_LNK, TILEPRO_OPC_MAXB_U, TILEPRO_OPC_MAXH,
1740 TILEPRO_OPC_MINB_U, TILEPRO_OPC_MINH, TILEPRO_OPC_MNZB, TILEPRO_OPC_MNZH,
1741 TILEPRO_OPC_MNZ, TILEPRO_OPC_MZB, TILEPRO_OPC_MZH, TILEPRO_OPC_MZ,
1742 TILEPRO_OPC_NOR, CHILD(546), TILEPRO_OPC_PACKHB, TILEPRO_OPC_PACKLB,
1743 TILEPRO_OPC_RL, TILEPRO_OPC_S1A, TILEPRO_OPC_S2A, TILEPRO_OPC_S3A,
1744 BITFIELD(43, 2) /* index 546 */,
1745 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, CHILD(551),
1746 BITFIELD(45, 2) /* index 551 */,
1747 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, CHILD(556),
1748 BITFIELD(47, 2) /* index 556 */,
1749 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_MOVE,
1750 BITFIELD(49, 5) /* index 561 */,
1751 TILEPRO_OPC_SB, TILEPRO_OPC_SEQB, TILEPRO_OPC_SEQH, TILEPRO_OPC_SEQ,
1752 TILEPRO_OPC_SHLB, TILEPRO_OPC_SHLH, TILEPRO_OPC_SHL, TILEPRO_OPC_SHRB,
1753 TILEPRO_OPC_SHRH, TILEPRO_OPC_SHR, TILEPRO_OPC_SH, TILEPRO_OPC_SLTB,
1754 TILEPRO_OPC_SLTB_U, TILEPRO_OPC_SLTEB, TILEPRO_OPC_SLTEB_U,
1755 TILEPRO_OPC_SLTEH, TILEPRO_OPC_SLTEH_U, TILEPRO_OPC_SLTE,
1756 TILEPRO_OPC_SLTE_U, TILEPRO_OPC_SLTH, TILEPRO_OPC_SLTH_U, TILEPRO_OPC_SLT,
1757 TILEPRO_OPC_SLT_U, TILEPRO_OPC_SNEB, TILEPRO_OPC_SNEH, TILEPRO_OPC_SNE,
1758 TILEPRO_OPC_SRAB, TILEPRO_OPC_SRAH, TILEPRO_OPC_SRA, TILEPRO_OPC_SUBB,
1759 TILEPRO_OPC_SUBH, TILEPRO_OPC_SUB,
1760 BITFIELD(49, 4) /* index 594 */,
1761 CHILD(611), CHILD(614), CHILD(617), CHILD(620), CHILD(623), CHILD(626),
1762 CHILD(629), CHILD(632), CHILD(635), CHILD(638), TILEPRO_OPC_NONE,
1763 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1764 TILEPRO_OPC_NONE,
1765 BITFIELD(53, 1) /* index 611 */,
1766 TILEPRO_OPC_SW, TILEPRO_OPC_NONE,
1767 BITFIELD(53, 1) /* index 614 */,
1768 TILEPRO_OPC_XOR, TILEPRO_OPC_NONE,
1769 BITFIELD(53, 1) /* index 617 */,
1770 TILEPRO_OPC_ADDS, TILEPRO_OPC_NONE,
1771 BITFIELD(53, 1) /* index 620 */,
1772 TILEPRO_OPC_SUBS, TILEPRO_OPC_NONE,
1773 BITFIELD(53, 1) /* index 623 */,
1774 TILEPRO_OPC_ADDBS_U, TILEPRO_OPC_NONE,
1775 BITFIELD(53, 1) /* index 626 */,
1776 TILEPRO_OPC_ADDHS, TILEPRO_OPC_NONE,
1777 BITFIELD(53, 1) /* index 629 */,
1778 TILEPRO_OPC_SUBBS_U, TILEPRO_OPC_NONE,
1779 BITFIELD(53, 1) /* index 632 */,
1780 TILEPRO_OPC_SUBHS, TILEPRO_OPC_NONE,
1781 BITFIELD(53, 1) /* index 635 */,
1782 TILEPRO_OPC_PACKHS, TILEPRO_OPC_NONE,
1783 BITFIELD(53, 1) /* index 638 */,
1784 TILEPRO_OPC_PACKBS_U, TILEPRO_OPC_NONE,
1785 BITFIELD(49, 5) /* index 641 */,
1786 TILEPRO_OPC_NONE, TILEPRO_OPC_ADDB_SN, TILEPRO_OPC_ADDH_SN,
1787 TILEPRO_OPC_ADD_SN, TILEPRO_OPC_AND_SN, TILEPRO_OPC_INTHB_SN,
1788 TILEPRO_OPC_INTHH_SN, TILEPRO_OPC_INTLB_SN, TILEPRO_OPC_INTLH_SN,
1789 TILEPRO_OPC_JALRP, TILEPRO_OPC_JALR, TILEPRO_OPC_JRP, TILEPRO_OPC_JR,
1790 TILEPRO_OPC_LNK_SN, TILEPRO_OPC_MAXB_U_SN, TILEPRO_OPC_MAXH_SN,
1791 TILEPRO_OPC_MINB_U_SN, TILEPRO_OPC_MINH_SN, TILEPRO_OPC_MNZB_SN,
1792 TILEPRO_OPC_MNZH_SN, TILEPRO_OPC_MNZ_SN, TILEPRO_OPC_MZB_SN,
1793 TILEPRO_OPC_MZH_SN, TILEPRO_OPC_MZ_SN, TILEPRO_OPC_NOR_SN, CHILD(674),
1794 TILEPRO_OPC_PACKHB_SN, TILEPRO_OPC_PACKLB_SN, TILEPRO_OPC_RL_SN,
1795 TILEPRO_OPC_S1A_SN, TILEPRO_OPC_S2A_SN, TILEPRO_OPC_S3A_SN,
1796 BITFIELD(43, 2) /* index 674 */,
1797 TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, CHILD(679),
1798 BITFIELD(45, 2) /* index 679 */,
1799 TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, CHILD(684),
1800 BITFIELD(47, 2) /* index 684 */,
1801 TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN, TILEPRO_OPC_OR_SN,
1802 TILEPRO_OPC_MOVE_SN,
1803 BITFIELD(49, 5) /* index 689 */,
1804 TILEPRO_OPC_SB, TILEPRO_OPC_SEQB_SN, TILEPRO_OPC_SEQH_SN,
1805 TILEPRO_OPC_SEQ_SN, TILEPRO_OPC_SHLB_SN, TILEPRO_OPC_SHLH_SN,
1806 TILEPRO_OPC_SHL_SN, TILEPRO_OPC_SHRB_SN, TILEPRO_OPC_SHRH_SN,
1807 TILEPRO_OPC_SHR_SN, TILEPRO_OPC_SH, TILEPRO_OPC_SLTB_SN,
1808 TILEPRO_OPC_SLTB_U_SN, TILEPRO_OPC_SLTEB_SN, TILEPRO_OPC_SLTEB_U_SN,
1809 TILEPRO_OPC_SLTEH_SN, TILEPRO_OPC_SLTEH_U_SN, TILEPRO_OPC_SLTE_SN,
1810 TILEPRO_OPC_SLTE_U_SN, TILEPRO_OPC_SLTH_SN, TILEPRO_OPC_SLTH_U_SN,
1811 TILEPRO_OPC_SLT_SN, TILEPRO_OPC_SLT_U_SN, TILEPRO_OPC_SNEB_SN,
1812 TILEPRO_OPC_SNEH_SN, TILEPRO_OPC_SNE_SN, TILEPRO_OPC_SRAB_SN,
1813 TILEPRO_OPC_SRAH_SN, TILEPRO_OPC_SRA_SN, TILEPRO_OPC_SUBB_SN,
1814 TILEPRO_OPC_SUBH_SN, TILEPRO_OPC_SUB_SN,
1815 BITFIELD(49, 4) /* index 722 */,
1816 CHILD(611), CHILD(739), CHILD(742), CHILD(745), CHILD(748), CHILD(751),
1817 CHILD(754), CHILD(757), CHILD(760), CHILD(763), TILEPRO_OPC_NONE,
1818 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1819 TILEPRO_OPC_NONE,
1820 BITFIELD(53, 1) /* index 739 */,
1821 TILEPRO_OPC_XOR_SN, TILEPRO_OPC_NONE,
1822 BITFIELD(53, 1) /* index 742 */,
1823 TILEPRO_OPC_ADDS_SN, TILEPRO_OPC_NONE,
1824 BITFIELD(53, 1) /* index 745 */,
1825 TILEPRO_OPC_SUBS_SN, TILEPRO_OPC_NONE,
1826 BITFIELD(53, 1) /* index 748 */,
1827 TILEPRO_OPC_ADDBS_U_SN, TILEPRO_OPC_NONE,
1828 BITFIELD(53, 1) /* index 751 */,
1829 TILEPRO_OPC_ADDHS_SN, TILEPRO_OPC_NONE,
1830 BITFIELD(53, 1) /* index 754 */,
1831 TILEPRO_OPC_SUBBS_U_SN, TILEPRO_OPC_NONE,
1832 BITFIELD(53, 1) /* index 757 */,
1833 TILEPRO_OPC_SUBHS_SN, TILEPRO_OPC_NONE,
1834 BITFIELD(53, 1) /* index 760 */,
1835 TILEPRO_OPC_PACKHS_SN, TILEPRO_OPC_NONE,
1836 BITFIELD(53, 1) /* index 763 */,
1837 TILEPRO_OPC_PACKBS_U_SN, TILEPRO_OPC_NONE,
1838 BITFIELD(37, 2) /* index 766 */,
1839 TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN,
1840 CHILD(771),
1841 BITFIELD(39, 2) /* index 771 */,
1842 TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN,
1843 CHILD(776),
1844 BITFIELD(41, 2) /* index 776 */,
1845 TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN, TILEPRO_OPC_ADDLI_SN,
1846 TILEPRO_OPC_MOVELI_SN,
1847 BITFIELD(37, 2) /* index 781 */,
1848 TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, CHILD(786),
1849 BITFIELD(39, 2) /* index 786 */,
1850 TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, CHILD(791),
1851 BITFIELD(41, 2) /* index 791 */,
1852 TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, TILEPRO_OPC_ADDLI, TILEPRO_OPC_MOVELI,
1853 BITFIELD(31, 2) /* index 796 */,
1854 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(801),
1855 BITFIELD(33, 2) /* index 801 */,
1856 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(806),
1857 BITFIELD(35, 2) /* index 806 */,
1858 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(811),
1859 BITFIELD(37, 2) /* index 811 */,
1860 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(816),
1861 BITFIELD(39, 2) /* index 816 */,
1862 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, CHILD(821),
1863 BITFIELD(41, 2) /* index 821 */,
1864 TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_AULI, TILEPRO_OPC_INFOL,
1865 BITFIELD(31, 4) /* index 826 */,
1866 TILEPRO_OPC_BZ, TILEPRO_OPC_BZT, TILEPRO_OPC_BNZ, TILEPRO_OPC_BNZT,
1867 TILEPRO_OPC_BGZ, TILEPRO_OPC_BGZT, TILEPRO_OPC_BGEZ, TILEPRO_OPC_BGEZT,
1868 TILEPRO_OPC_BLZ, TILEPRO_OPC_BLZT, TILEPRO_OPC_BLEZ, TILEPRO_OPC_BLEZT,
1869 TILEPRO_OPC_BBS, TILEPRO_OPC_BBST, TILEPRO_OPC_BBNS, TILEPRO_OPC_BBNST,
1870 BITFIELD(31, 4) /* index 843 */,
1871 TILEPRO_OPC_BZ_SN, TILEPRO_OPC_BZT_SN, TILEPRO_OPC_BNZ_SN,
1872 TILEPRO_OPC_BNZT_SN, TILEPRO_OPC_BGZ_SN, TILEPRO_OPC_BGZT_SN,
1873 TILEPRO_OPC_BGEZ_SN, TILEPRO_OPC_BGEZT_SN, TILEPRO_OPC_BLZ_SN,
1874 TILEPRO_OPC_BLZT_SN, TILEPRO_OPC_BLEZ_SN, TILEPRO_OPC_BLEZT_SN,
1875 TILEPRO_OPC_BBS_SN, TILEPRO_OPC_BBST_SN, TILEPRO_OPC_BBNS_SN,
1876 TILEPRO_OPC_BBNST_SN,
1877 BITFIELD(51, 3) /* index 860 */,
1878 TILEPRO_OPC_NONE, TILEPRO_OPC_ADDIB, TILEPRO_OPC_ADDIH, TILEPRO_OPC_ADDI,
1879 CHILD(869), TILEPRO_OPC_MAXIB_U, TILEPRO_OPC_MAXIH, TILEPRO_OPC_MFSPR,
1880 BITFIELD(31, 2) /* index 869 */,
1881 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(874),
1882 BITFIELD(33, 2) /* index 874 */,
1883 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(879),
1884 BITFIELD(35, 2) /* index 879 */,
1885 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(884),
1886 BITFIELD(37, 2) /* index 884 */,
1887 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(889),
1888 BITFIELD(39, 2) /* index 889 */,
1889 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(894),
1890 BITFIELD(41, 2) /* index 894 */,
1891 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_INFO,
1892 BITFIELD(51, 3) /* index 899 */,
1893 TILEPRO_OPC_MINIB_U, TILEPRO_OPC_MINIH, TILEPRO_OPC_MTSPR, CHILD(908),
1894 TILEPRO_OPC_SEQIB, TILEPRO_OPC_SEQIH, TILEPRO_OPC_SEQI, TILEPRO_OPC_SLTIB,
1895 BITFIELD(37, 2) /* index 908 */,
1896 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, CHILD(913),
1897 BITFIELD(39, 2) /* index 913 */,
1898 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, CHILD(918),
1899 BITFIELD(41, 2) /* index 918 */,
1900 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_MOVEI,
1901 BITFIELD(51, 3) /* index 923 */,
1902 TILEPRO_OPC_SLTIB_U, TILEPRO_OPC_SLTIH, TILEPRO_OPC_SLTIH_U,
1903 TILEPRO_OPC_SLTI, TILEPRO_OPC_SLTI_U, TILEPRO_OPC_XORI, TILEPRO_OPC_LBADD,
1904 TILEPRO_OPC_LBADD_U,
1905 BITFIELD(51, 3) /* index 932 */,
1906 TILEPRO_OPC_LHADD, TILEPRO_OPC_LHADD_U, TILEPRO_OPC_LWADD,
1907 TILEPRO_OPC_LWADD_NA, TILEPRO_OPC_SBADD, TILEPRO_OPC_SHADD,
1908 TILEPRO_OPC_SWADD, TILEPRO_OPC_NONE,
1909 BITFIELD(51, 3) /* index 941 */,
1910 TILEPRO_OPC_NONE, TILEPRO_OPC_ADDIB_SN, TILEPRO_OPC_ADDIH_SN,
1911 TILEPRO_OPC_ADDI_SN, TILEPRO_OPC_ANDI_SN, TILEPRO_OPC_MAXIB_U_SN,
1912 TILEPRO_OPC_MAXIH_SN, TILEPRO_OPC_MFSPR,
1913 BITFIELD(51, 3) /* index 950 */,
1914 TILEPRO_OPC_MINIB_U_SN, TILEPRO_OPC_MINIH_SN, TILEPRO_OPC_MTSPR, CHILD(959),
1915 TILEPRO_OPC_SEQIB_SN, TILEPRO_OPC_SEQIH_SN, TILEPRO_OPC_SEQI_SN,
1916 TILEPRO_OPC_SLTIB_SN,
1917 BITFIELD(37, 2) /* index 959 */,
1918 TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, CHILD(964),
1919 BITFIELD(39, 2) /* index 964 */,
1920 TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, CHILD(969),
1921 BITFIELD(41, 2) /* index 969 */,
1922 TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN, TILEPRO_OPC_ORI_SN,
1923 TILEPRO_OPC_MOVEI_SN,
1924 BITFIELD(51, 3) /* index 974 */,
1925 TILEPRO_OPC_SLTIB_U_SN, TILEPRO_OPC_SLTIH_SN, TILEPRO_OPC_SLTIH_U_SN,
1926 TILEPRO_OPC_SLTI_SN, TILEPRO_OPC_SLTI_U_SN, TILEPRO_OPC_XORI_SN,
1927 TILEPRO_OPC_LBADD_SN, TILEPRO_OPC_LBADD_U_SN,
1928 BITFIELD(51, 3) /* index 983 */,
1929 TILEPRO_OPC_LHADD_SN, TILEPRO_OPC_LHADD_U_SN, TILEPRO_OPC_LWADD_SN,
1930 TILEPRO_OPC_LWADD_NA_SN, TILEPRO_OPC_SBADD, TILEPRO_OPC_SHADD,
1931 TILEPRO_OPC_SWADD, TILEPRO_OPC_NONE,
1932 BITFIELD(46, 7) /* index 992 */,
1933 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1934 CHILD(1121), CHILD(1121), CHILD(1121), CHILD(1121), CHILD(1124),
1935 CHILD(1124), CHILD(1124), CHILD(1124), CHILD(1127), CHILD(1127),
1936 CHILD(1127), CHILD(1127), CHILD(1130), CHILD(1130), CHILD(1130),
1937 CHILD(1130), CHILD(1133), CHILD(1133), CHILD(1133), CHILD(1133),
1938 CHILD(1136), CHILD(1136), CHILD(1136), CHILD(1136), CHILD(1139),
1939 CHILD(1139), CHILD(1139), CHILD(1139), CHILD(1142), CHILD(1142),
1940 CHILD(1142), CHILD(1142), CHILD(1145), CHILD(1145), CHILD(1145),
1941 CHILD(1145), CHILD(1148), CHILD(1148), CHILD(1148), CHILD(1148),
1942 CHILD(1151), CHILD(1242), CHILD(1290), CHILD(1323), TILEPRO_OPC_NONE,
1943 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1944 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1945 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1946 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1947 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1948 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1949 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1950 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1951 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1952 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1953 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1954 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1955 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1956 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1957 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1958 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1959 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1960 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1961 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1962 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
1963 BITFIELD(53, 1) /* index 1121 */,
1964 TILEPRO_OPC_RLI, TILEPRO_OPC_NONE,
1965 BITFIELD(53, 1) /* index 1124 */,
1966 TILEPRO_OPC_SHLIB, TILEPRO_OPC_NONE,
1967 BITFIELD(53, 1) /* index 1127 */,
1968 TILEPRO_OPC_SHLIH, TILEPRO_OPC_NONE,
1969 BITFIELD(53, 1) /* index 1130 */,
1970 TILEPRO_OPC_SHLI, TILEPRO_OPC_NONE,
1971 BITFIELD(53, 1) /* index 1133 */,
1972 TILEPRO_OPC_SHRIB, TILEPRO_OPC_NONE,
1973 BITFIELD(53, 1) /* index 1136 */,
1974 TILEPRO_OPC_SHRIH, TILEPRO_OPC_NONE,
1975 BITFIELD(53, 1) /* index 1139 */,
1976 TILEPRO_OPC_SHRI, TILEPRO_OPC_NONE,
1977 BITFIELD(53, 1) /* index 1142 */,
1978 TILEPRO_OPC_SRAIB, TILEPRO_OPC_NONE,
1979 BITFIELD(53, 1) /* index 1145 */,
1980 TILEPRO_OPC_SRAIH, TILEPRO_OPC_NONE,
1981 BITFIELD(53, 1) /* index 1148 */,
1982 TILEPRO_OPC_SRAI, TILEPRO_OPC_NONE,
1983 BITFIELD(43, 3) /* index 1151 */,
1984 TILEPRO_OPC_NONE, CHILD(1160), CHILD(1163), CHILD(1166), CHILD(1169),
1985 CHILD(1172), CHILD(1175), CHILD(1178),
1986 BITFIELD(53, 1) /* index 1160 */,
1987 TILEPRO_OPC_DRAIN, TILEPRO_OPC_NONE,
1988 BITFIELD(53, 1) /* index 1163 */,
1989 TILEPRO_OPC_DTLBPR, TILEPRO_OPC_NONE,
1990 BITFIELD(53, 1) /* index 1166 */,
1991 TILEPRO_OPC_FINV, TILEPRO_OPC_NONE,
1992 BITFIELD(53, 1) /* index 1169 */,
1993 TILEPRO_OPC_FLUSH, TILEPRO_OPC_NONE,
1994 BITFIELD(53, 1) /* index 1172 */,
1995 TILEPRO_OPC_FNOP, TILEPRO_OPC_NONE,
1996 BITFIELD(53, 1) /* index 1175 */,
1997 TILEPRO_OPC_ICOH, TILEPRO_OPC_NONE,
1998 BITFIELD(31, 2) /* index 1178 */,
1999 CHILD(1183), CHILD(1211), CHILD(1239), CHILD(1239),
2000 BITFIELD(53, 1) /* index 1183 */,
2001 CHILD(1186), TILEPRO_OPC_NONE,
2002 BITFIELD(33, 2) /* index 1186 */,
2003 TILEPRO_OPC_ILL, TILEPRO_OPC_ILL, TILEPRO_OPC_ILL, CHILD(1191),
2004 BITFIELD(35, 2) /* index 1191 */,
2005 TILEPRO_OPC_ILL, CHILD(1196), TILEPRO_OPC_ILL, TILEPRO_OPC_ILL,
2006 BITFIELD(37, 2) /* index 1196 */,
2007 TILEPRO_OPC_ILL, CHILD(1201), TILEPRO_OPC_ILL, TILEPRO_OPC_ILL,
2008 BITFIELD(39, 2) /* index 1201 */,
2009 TILEPRO_OPC_ILL, CHILD(1206), TILEPRO_OPC_ILL, TILEPRO_OPC_ILL,
2010 BITFIELD(41, 2) /* index 1206 */,
2011 TILEPRO_OPC_ILL, TILEPRO_OPC_ILL, TILEPRO_OPC_BPT, TILEPRO_OPC_ILL,
2012 BITFIELD(53, 1) /* index 1211 */,
2013 CHILD(1214), TILEPRO_OPC_NONE,
2014 BITFIELD(33, 2) /* index 1214 */,
2015 TILEPRO_OPC_ILL, TILEPRO_OPC_ILL, TILEPRO_OPC_ILL, CHILD(1219),
2016 BITFIELD(35, 2) /* index 1219 */,
2017 TILEPRO_OPC_ILL, CHILD(1224), TILEPRO_OPC_ILL, TILEPRO_OPC_ILL,
2018 BITFIELD(37, 2) /* index 1224 */,
2019 TILEPRO_OPC_ILL, CHILD(1229), TILEPRO_OPC_ILL, TILEPRO_OPC_ILL,
2020 BITFIELD(39, 2) /* index 1229 */,
2021 TILEPRO_OPC_ILL, CHILD(1234), TILEPRO_OPC_ILL, TILEPRO_OPC_ILL,
2022 BITFIELD(41, 2) /* index 1234 */,
2023 TILEPRO_OPC_ILL, TILEPRO_OPC_ILL, TILEPRO_OPC_RAISE, TILEPRO_OPC_ILL,
2024 BITFIELD(53, 1) /* index 1239 */,
2025 TILEPRO_OPC_ILL, TILEPRO_OPC_NONE,
2026 BITFIELD(43, 3) /* index 1242 */,
2027 CHILD(1251), CHILD(1254), CHILD(1257), CHILD(1275), CHILD(1278),
2028 CHILD(1281), CHILD(1284), CHILD(1287),
2029 BITFIELD(53, 1) /* index 1251 */,
2030 TILEPRO_OPC_INV, TILEPRO_OPC_NONE,
2031 BITFIELD(53, 1) /* index 1254 */,
2032 TILEPRO_OPC_IRET, TILEPRO_OPC_NONE,
2033 BITFIELD(53, 1) /* index 1257 */,
2034 CHILD(1260), TILEPRO_OPC_NONE,
2035 BITFIELD(31, 2) /* index 1260 */,
2036 TILEPRO_OPC_LB, TILEPRO_OPC_LB, TILEPRO_OPC_LB, CHILD(1265),
2037 BITFIELD(33, 2) /* index 1265 */,
2038 TILEPRO_OPC_LB, TILEPRO_OPC_LB, TILEPRO_OPC_LB, CHILD(1270),
2039 BITFIELD(35, 2) /* index 1270 */,
2040 TILEPRO_OPC_LB, TILEPRO_OPC_LB, TILEPRO_OPC_LB, TILEPRO_OPC_PREFETCH,
2041 BITFIELD(53, 1) /* index 1275 */,
2042 TILEPRO_OPC_LB_U, TILEPRO_OPC_NONE,
2043 BITFIELD(53, 1) /* index 1278 */,
2044 TILEPRO_OPC_LH, TILEPRO_OPC_NONE,
2045 BITFIELD(53, 1) /* index 1281 */,
2046 TILEPRO_OPC_LH_U, TILEPRO_OPC_NONE,
2047 BITFIELD(53, 1) /* index 1284 */,
2048 TILEPRO_OPC_LW, TILEPRO_OPC_NONE,
2049 BITFIELD(53, 1) /* index 1287 */,
2050 TILEPRO_OPC_MF, TILEPRO_OPC_NONE,
2051 BITFIELD(43, 3) /* index 1290 */,
2052 CHILD(1299), CHILD(1302), CHILD(1305), CHILD(1308), CHILD(1311),
2053 CHILD(1314), CHILD(1317), CHILD(1320),
2054 BITFIELD(53, 1) /* index 1299 */,
2055 TILEPRO_OPC_NAP, TILEPRO_OPC_NONE,
2056 BITFIELD(53, 1) /* index 1302 */,
2057 TILEPRO_OPC_NOP, TILEPRO_OPC_NONE,
2058 BITFIELD(53, 1) /* index 1305 */,
2059 TILEPRO_OPC_SWINT0, TILEPRO_OPC_NONE,
2060 BITFIELD(53, 1) /* index 1308 */,
2061 TILEPRO_OPC_SWINT1, TILEPRO_OPC_NONE,
2062 BITFIELD(53, 1) /* index 1311 */,
2063 TILEPRO_OPC_SWINT2, TILEPRO_OPC_NONE,
2064 BITFIELD(53, 1) /* index 1314 */,
2065 TILEPRO_OPC_SWINT3, TILEPRO_OPC_NONE,
2066 BITFIELD(53, 1) /* index 1317 */,
2067 TILEPRO_OPC_TNS, TILEPRO_OPC_NONE,
2068 BITFIELD(53, 1) /* index 1320 */,
2069 TILEPRO_OPC_WH64, TILEPRO_OPC_NONE,
2070 BITFIELD(43, 2) /* index 1323 */,
2071 CHILD(1328), TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2072 BITFIELD(45, 1) /* index 1328 */,
2073 CHILD(1331), TILEPRO_OPC_NONE,
2074 BITFIELD(53, 1) /* index 1331 */,
2075 TILEPRO_OPC_LW_NA, TILEPRO_OPC_NONE,
2076 BITFIELD(46, 7) /* index 1334 */,
2077 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2078 CHILD(1463), CHILD(1463), CHILD(1463), CHILD(1463), CHILD(1466),
2079 CHILD(1466), CHILD(1466), CHILD(1466), CHILD(1469), CHILD(1469),
2080 CHILD(1469), CHILD(1469), CHILD(1472), CHILD(1472), CHILD(1472),
2081 CHILD(1472), CHILD(1475), CHILD(1475), CHILD(1475), CHILD(1475),
2082 CHILD(1478), CHILD(1478), CHILD(1478), CHILD(1478), CHILD(1481),
2083 CHILD(1481), CHILD(1481), CHILD(1481), CHILD(1484), CHILD(1484),
2084 CHILD(1484), CHILD(1484), CHILD(1487), CHILD(1487), CHILD(1487),
2085 CHILD(1487), CHILD(1490), CHILD(1490), CHILD(1490), CHILD(1490),
2086 CHILD(1151), CHILD(1493), CHILD(1517), CHILD(1529), TILEPRO_OPC_NONE,
2087 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2088 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2089 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2090 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2091 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2092 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2093 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2094 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2095 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2096 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2097 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2098 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2099 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2100 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2101 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2102 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2103 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2104 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2105 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2106 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2107 BITFIELD(53, 1) /* index 1463 */,
2108 TILEPRO_OPC_RLI_SN, TILEPRO_OPC_NONE,
2109 BITFIELD(53, 1) /* index 1466 */,
2110 TILEPRO_OPC_SHLIB_SN, TILEPRO_OPC_NONE,
2111 BITFIELD(53, 1) /* index 1469 */,
2112 TILEPRO_OPC_SHLIH_SN, TILEPRO_OPC_NONE,
2113 BITFIELD(53, 1) /* index 1472 */,
2114 TILEPRO_OPC_SHLI_SN, TILEPRO_OPC_NONE,
2115 BITFIELD(53, 1) /* index 1475 */,
2116 TILEPRO_OPC_SHRIB_SN, TILEPRO_OPC_NONE,
2117 BITFIELD(53, 1) /* index 1478 */,
2118 TILEPRO_OPC_SHRIH_SN, TILEPRO_OPC_NONE,
2119 BITFIELD(53, 1) /* index 1481 */,
2120 TILEPRO_OPC_SHRI_SN, TILEPRO_OPC_NONE,
2121 BITFIELD(53, 1) /* index 1484 */,
2122 TILEPRO_OPC_SRAIB_SN, TILEPRO_OPC_NONE,
2123 BITFIELD(53, 1) /* index 1487 */,
2124 TILEPRO_OPC_SRAIH_SN, TILEPRO_OPC_NONE,
2125 BITFIELD(53, 1) /* index 1490 */,
2126 TILEPRO_OPC_SRAI_SN, TILEPRO_OPC_NONE,
2127 BITFIELD(43, 3) /* index 1493 */,
2128 CHILD(1251), CHILD(1254), CHILD(1502), CHILD(1505), CHILD(1508),
2129 CHILD(1511), CHILD(1514), CHILD(1287),
2130 BITFIELD(53, 1) /* index 1502 */,
2131 TILEPRO_OPC_LB_SN, TILEPRO_OPC_NONE,
2132 BITFIELD(53, 1) /* index 1505 */,
2133 TILEPRO_OPC_LB_U_SN, TILEPRO_OPC_NONE,
2134 BITFIELD(53, 1) /* index 1508 */,
2135 TILEPRO_OPC_LH_SN, TILEPRO_OPC_NONE,
2136 BITFIELD(53, 1) /* index 1511 */,
2137 TILEPRO_OPC_LH_U_SN, TILEPRO_OPC_NONE,
2138 BITFIELD(53, 1) /* index 1514 */,
2139 TILEPRO_OPC_LW_SN, TILEPRO_OPC_NONE,
2140 BITFIELD(43, 3) /* index 1517 */,
2141 CHILD(1299), CHILD(1302), CHILD(1305), CHILD(1308), CHILD(1311),
2142 CHILD(1314), CHILD(1526), CHILD(1320),
2143 BITFIELD(53, 1) /* index 1526 */,
2144 TILEPRO_OPC_TNS_SN, TILEPRO_OPC_NONE,
2145 BITFIELD(43, 2) /* index 1529 */,
2146 CHILD(1534), TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2147 BITFIELD(45, 1) /* index 1534 */,
2148 CHILD(1537), TILEPRO_OPC_NONE,
2149 BITFIELD(53, 1) /* index 1537 */,
2150 TILEPRO_OPC_LW_NA_SN, TILEPRO_OPC_NONE,
2151};
2152
2153static const unsigned short decode_Y0_fsm[168] =
2154{
2155 BITFIELD(27, 4) /* index 0 */,
2156 TILEPRO_OPC_NONE, CHILD(17), CHILD(22), CHILD(27), CHILD(47), CHILD(52),
2157 CHILD(57), CHILD(62), CHILD(67), TILEPRO_OPC_ADDI, CHILD(72), CHILD(102),
2158 TILEPRO_OPC_SEQI, CHILD(117), TILEPRO_OPC_SLTI, TILEPRO_OPC_SLTI_U,
2159 BITFIELD(18, 2) /* index 17 */,
2160 TILEPRO_OPC_ADD, TILEPRO_OPC_S1A, TILEPRO_OPC_S2A, TILEPRO_OPC_SUB,
2161 BITFIELD(18, 2) /* index 22 */,
2162 TILEPRO_OPC_MNZ, TILEPRO_OPC_MVNZ, TILEPRO_OPC_MVZ, TILEPRO_OPC_MZ,
2163 BITFIELD(18, 2) /* index 27 */,
2164 TILEPRO_OPC_AND, TILEPRO_OPC_NOR, CHILD(32), TILEPRO_OPC_XOR,
2165 BITFIELD(12, 2) /* index 32 */,
2166 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, CHILD(37),
2167 BITFIELD(14, 2) /* index 37 */,
2168 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, CHILD(42),
2169 BITFIELD(16, 2) /* index 42 */,
2170 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_MOVE,
2171 BITFIELD(18, 2) /* index 47 */,
2172 TILEPRO_OPC_RL, TILEPRO_OPC_SHL, TILEPRO_OPC_SHR, TILEPRO_OPC_SRA,
2173 BITFIELD(18, 2) /* index 52 */,
2174 TILEPRO_OPC_SLTE, TILEPRO_OPC_SLTE_U, TILEPRO_OPC_SLT, TILEPRO_OPC_SLT_U,
2175 BITFIELD(18, 2) /* index 57 */,
2176 TILEPRO_OPC_MULHLSA_UU, TILEPRO_OPC_S3A, TILEPRO_OPC_SEQ, TILEPRO_OPC_SNE,
2177 BITFIELD(18, 2) /* index 62 */,
2178 TILEPRO_OPC_MULHH_SS, TILEPRO_OPC_MULHH_UU, TILEPRO_OPC_MULLL_SS,
2179 TILEPRO_OPC_MULLL_UU,
2180 BITFIELD(18, 2) /* index 67 */,
2181 TILEPRO_OPC_MULHHA_SS, TILEPRO_OPC_MULHHA_UU, TILEPRO_OPC_MULLLA_SS,
2182 TILEPRO_OPC_MULLLA_UU,
2183 BITFIELD(0, 2) /* index 72 */,
2184 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(77),
2185 BITFIELD(2, 2) /* index 77 */,
2186 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(82),
2187 BITFIELD(4, 2) /* index 82 */,
2188 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(87),
2189 BITFIELD(6, 2) /* index 87 */,
2190 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(92),
2191 BITFIELD(8, 2) /* index 92 */,
2192 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(97),
2193 BITFIELD(10, 2) /* index 97 */,
2194 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_INFO,
2195 BITFIELD(6, 2) /* index 102 */,
2196 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, CHILD(107),
2197 BITFIELD(8, 2) /* index 107 */,
2198 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, CHILD(112),
2199 BITFIELD(10, 2) /* index 112 */,
2200 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_MOVEI,
2201 BITFIELD(15, 5) /* index 117 */,
2202 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2203 TILEPRO_OPC_RLI, TILEPRO_OPC_RLI, TILEPRO_OPC_RLI, TILEPRO_OPC_RLI,
2204 TILEPRO_OPC_SHLI, TILEPRO_OPC_SHLI, TILEPRO_OPC_SHLI, TILEPRO_OPC_SHLI,
2205 TILEPRO_OPC_SHRI, TILEPRO_OPC_SHRI, TILEPRO_OPC_SHRI, TILEPRO_OPC_SHRI,
2206 TILEPRO_OPC_SRAI, TILEPRO_OPC_SRAI, TILEPRO_OPC_SRAI, TILEPRO_OPC_SRAI,
2207 CHILD(150), CHILD(159), TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2208 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2209 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2210 BITFIELD(12, 3) /* index 150 */,
2211 TILEPRO_OPC_NONE, TILEPRO_OPC_BITX, TILEPRO_OPC_BYTEX, TILEPRO_OPC_CLZ,
2212 TILEPRO_OPC_CTZ, TILEPRO_OPC_FNOP, TILEPRO_OPC_NOP, TILEPRO_OPC_PCNT,
2213 BITFIELD(12, 3) /* index 159 */,
2214 TILEPRO_OPC_TBLIDXB0, TILEPRO_OPC_TBLIDXB1, TILEPRO_OPC_TBLIDXB2,
2215 TILEPRO_OPC_TBLIDXB3, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2216 TILEPRO_OPC_NONE,
2217};
2218
2219static const unsigned short decode_Y1_fsm[140] =
2220{
2221 BITFIELD(59, 4) /* index 0 */,
2222 TILEPRO_OPC_NONE, CHILD(17), CHILD(22), CHILD(27), CHILD(47), CHILD(52),
2223 CHILD(57), TILEPRO_OPC_ADDI, CHILD(62), CHILD(92), TILEPRO_OPC_SEQI,
2224 CHILD(107), TILEPRO_OPC_SLTI, TILEPRO_OPC_SLTI_U, TILEPRO_OPC_NONE,
2225 TILEPRO_OPC_NONE,
2226 BITFIELD(49, 2) /* index 17 */,
2227 TILEPRO_OPC_ADD, TILEPRO_OPC_S1A, TILEPRO_OPC_S2A, TILEPRO_OPC_SUB,
2228 BITFIELD(49, 2) /* index 22 */,
2229 TILEPRO_OPC_NONE, TILEPRO_OPC_MNZ, TILEPRO_OPC_MZ, TILEPRO_OPC_NONE,
2230 BITFIELD(49, 2) /* index 27 */,
2231 TILEPRO_OPC_AND, TILEPRO_OPC_NOR, CHILD(32), TILEPRO_OPC_XOR,
2232 BITFIELD(43, 2) /* index 32 */,
2233 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, CHILD(37),
2234 BITFIELD(45, 2) /* index 37 */,
2235 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, CHILD(42),
2236 BITFIELD(47, 2) /* index 42 */,
2237 TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_OR, TILEPRO_OPC_MOVE,
2238 BITFIELD(49, 2) /* index 47 */,
2239 TILEPRO_OPC_RL, TILEPRO_OPC_SHL, TILEPRO_OPC_SHR, TILEPRO_OPC_SRA,
2240 BITFIELD(49, 2) /* index 52 */,
2241 TILEPRO_OPC_SLTE, TILEPRO_OPC_SLTE_U, TILEPRO_OPC_SLT, TILEPRO_OPC_SLT_U,
2242 BITFIELD(49, 2) /* index 57 */,
2243 TILEPRO_OPC_NONE, TILEPRO_OPC_S3A, TILEPRO_OPC_SEQ, TILEPRO_OPC_SNE,
2244 BITFIELD(31, 2) /* index 62 */,
2245 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(67),
2246 BITFIELD(33, 2) /* index 67 */,
2247 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(72),
2248 BITFIELD(35, 2) /* index 72 */,
2249 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(77),
2250 BITFIELD(37, 2) /* index 77 */,
2251 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(82),
2252 BITFIELD(39, 2) /* index 82 */,
2253 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, CHILD(87),
2254 BITFIELD(41, 2) /* index 87 */,
2255 TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_ANDI, TILEPRO_OPC_INFO,
2256 BITFIELD(37, 2) /* index 92 */,
2257 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, CHILD(97),
2258 BITFIELD(39, 2) /* index 97 */,
2259 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, CHILD(102),
2260 BITFIELD(41, 2) /* index 102 */,
2261 TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_ORI, TILEPRO_OPC_MOVEI,
2262 BITFIELD(48, 3) /* index 107 */,
2263 TILEPRO_OPC_NONE, TILEPRO_OPC_RLI, TILEPRO_OPC_SHLI, TILEPRO_OPC_SHRI,
2264 TILEPRO_OPC_SRAI, CHILD(116), TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2265 BITFIELD(43, 3) /* index 116 */,
2266 TILEPRO_OPC_NONE, CHILD(125), CHILD(130), CHILD(135), TILEPRO_OPC_NONE,
2267 TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2268 BITFIELD(46, 2) /* index 125 */,
2269 TILEPRO_OPC_FNOP, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2270 BITFIELD(46, 2) /* index 130 */,
2271 TILEPRO_OPC_ILL, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2272 BITFIELD(46, 2) /* index 135 */,
2273 TILEPRO_OPC_NOP, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE, TILEPRO_OPC_NONE,
2274};
2275
2276static const unsigned short decode_Y2_fsm[24] =
2277{
2278 BITFIELD(56, 3) /* index 0 */,
2279 CHILD(9), TILEPRO_OPC_LB_U, TILEPRO_OPC_LH, TILEPRO_OPC_LH_U,
2280 TILEPRO_OPC_LW, TILEPRO_OPC_SB, TILEPRO_OPC_SH, TILEPRO_OPC_SW,
2281 BITFIELD(20, 2) /* index 9 */,
2282 TILEPRO_OPC_LB, TILEPRO_OPC_LB, TILEPRO_OPC_LB, CHILD(14),
2283 BITFIELD(22, 2) /* index 14 */,
2284 TILEPRO_OPC_LB, TILEPRO_OPC_LB, TILEPRO_OPC_LB, CHILD(19),
2285 BITFIELD(24, 2) /* index 19 */,
2286 TILEPRO_OPC_LB, TILEPRO_OPC_LB, TILEPRO_OPC_LB, TILEPRO_OPC_PREFETCH,
2287};
2288
2289#undef BITFIELD
2290#undef CHILD
2291const unsigned short * const
2292tilepro_bundle_decoder_fsms[TILEPRO_NUM_PIPELINE_ENCODINGS] =
2293{
2294 decode_X0_fsm,
2295 decode_X1_fsm,
2296 decode_Y0_fsm,
2297 decode_Y1_fsm,
2298 decode_Y2_fsm
2299};
2300const struct tilepro_operand tilepro_operands[43] =
2301{
2302 {
2303 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_IMM8_X0),
2304 8, 1, 0, 0, 0, 0,
2305 create_Imm8_X0, get_Imm8_X0
2306 },
2307 {
2308 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_IMM8_X1),
2309 8, 1, 0, 0, 0, 0,
2310 create_Imm8_X1, get_Imm8_X1
2311 },
2312 {
2313 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_IMM8_Y0),
2314 8, 1, 0, 0, 0, 0,
2315 create_Imm8_Y0, get_Imm8_Y0
2316 },
2317 {
2318 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_IMM8_Y1),
2319 8, 1, 0, 0, 0, 0,
2320 create_Imm8_Y1, get_Imm8_Y1
2321 },
2322 {
2323 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_IMM16_X0),
2324 16, 1, 0, 0, 0, 0,
2325 create_Imm16_X0, get_Imm16_X0
2326 },
2327 {
2328 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_IMM16_X1),
2329 16, 1, 0, 0, 0, 0,
2330 create_Imm16_X1, get_Imm16_X1
2331 },
2332 {
2333 TILEPRO_OP_TYPE_ADDRESS, BFD_RELOC(TILEPRO_JOFFLONG_X1),
2334 29, 1, 0, 0, 1, TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES,
2335 create_JOffLong_X1, get_JOffLong_X1
2336 },
2337 {
2338 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2339 6, 0, 0, 1, 0, 0,
2340 create_Dest_X0, get_Dest_X0
2341 },
2342 {
2343 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2344 6, 0, 1, 0, 0, 0,
2345 create_SrcA_X0, get_SrcA_X0
2346 },
2347 {
2348 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2349 6, 0, 0, 1, 0, 0,
2350 create_Dest_X1, get_Dest_X1
2351 },
2352 {
2353 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2354 6, 0, 1, 0, 0, 0,
2355 create_SrcA_X1, get_SrcA_X1
2356 },
2357 {
2358 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2359 6, 0, 0, 1, 0, 0,
2360 create_Dest_Y0, get_Dest_Y0
2361 },
2362 {
2363 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2364 6, 0, 1, 0, 0, 0,
2365 create_SrcA_Y0, get_SrcA_Y0
2366 },
2367 {
2368 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2369 6, 0, 0, 1, 0, 0,
2370 create_Dest_Y1, get_Dest_Y1
2371 },
2372 {
2373 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2374 6, 0, 1, 0, 0, 0,
2375 create_SrcA_Y1, get_SrcA_Y1
2376 },
2377 {
2378 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2379 6, 0, 1, 0, 0, 0,
2380 create_SrcA_Y2, get_SrcA_Y2
2381 },
2382 {
2383 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2384 6, 0, 1, 0, 0, 0,
2385 create_SrcB_X0, get_SrcB_X0
2386 },
2387 {
2388 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2389 6, 0, 1, 0, 0, 0,
2390 create_SrcB_X1, get_SrcB_X1
2391 },
2392 {
2393 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2394 6, 0, 1, 0, 0, 0,
2395 create_SrcB_Y0, get_SrcB_Y0
2396 },
2397 {
2398 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2399 6, 0, 1, 0, 0, 0,
2400 create_SrcB_Y1, get_SrcB_Y1
2401 },
2402 {
2403 TILEPRO_OP_TYPE_ADDRESS, BFD_RELOC(TILEPRO_BROFF_X1),
2404 17, 1, 0, 0, 1, TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES,
2405 create_BrOff_X1, get_BrOff_X1
2406 },
2407 {
2408 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2409 6, 0, 1, 1, 0, 0,
2410 create_Dest_X0, get_Dest_X0
2411 },
2412 {
2413 TILEPRO_OP_TYPE_ADDRESS, BFD_RELOC(NONE),
2414 28, 1, 0, 0, 1, TILEPRO_LOG2_BUNDLE_ALIGNMENT_IN_BYTES,
2415 create_JOff_X1, get_JOff_X1
2416 },
2417 {
2418 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2419 6, 0, 0, 1, 0, 0,
2420 create_SrcBDest_Y2, get_SrcBDest_Y2
2421 },
2422 {
2423 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2424 6, 0, 1, 1, 0, 0,
2425 create_SrcA_X1, get_SrcA_X1
2426 },
2427 {
2428 TILEPRO_OP_TYPE_SPR, BFD_RELOC(TILEPRO_MF_IMM15_X1),
2429 15, 0, 0, 0, 0, 0,
2430 create_MF_Imm15_X1, get_MF_Imm15_X1
2431 },
2432 {
2433 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_MMSTART_X0),
2434 5, 0, 0, 0, 0, 0,
2435 create_MMStart_X0, get_MMStart_X0
2436 },
2437 {
2438 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_MMEND_X0),
2439 5, 0, 0, 0, 0, 0,
2440 create_MMEnd_X0, get_MMEnd_X0
2441 },
2442 {
2443 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_MMSTART_X1),
2444 5, 0, 0, 0, 0, 0,
2445 create_MMStart_X1, get_MMStart_X1
2446 },
2447 {
2448 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_MMEND_X1),
2449 5, 0, 0, 0, 0, 0,
2450 create_MMEnd_X1, get_MMEnd_X1
2451 },
2452 {
2453 TILEPRO_OP_TYPE_SPR, BFD_RELOC(TILEPRO_MT_IMM15_X1),
2454 15, 0, 0, 0, 0, 0,
2455 create_MT_Imm15_X1, get_MT_Imm15_X1
2456 },
2457 {
2458 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2459 6, 0, 1, 1, 0, 0,
2460 create_Dest_Y0, get_Dest_Y0
2461 },
2462 {
2463 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_SHAMT_X0),
2464 5, 0, 0, 0, 0, 0,
2465 create_ShAmt_X0, get_ShAmt_X0
2466 },
2467 {
2468 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_SHAMT_X1),
2469 5, 0, 0, 0, 0, 0,
2470 create_ShAmt_X1, get_ShAmt_X1
2471 },
2472 {
2473 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_SHAMT_Y0),
2474 5, 0, 0, 0, 0, 0,
2475 create_ShAmt_Y0, get_ShAmt_Y0
2476 },
2477 {
2478 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_SHAMT_Y1),
2479 5, 0, 0, 0, 0, 0,
2480 create_ShAmt_Y1, get_ShAmt_Y1
2481 },
2482 {
2483 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2484 6, 0, 1, 0, 0, 0,
2485 create_SrcBDest_Y2, get_SrcBDest_Y2
2486 },
2487 {
2488 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEPRO_DEST_IMM8_X1),
2489 8, 1, 0, 0, 0, 0,
2490 create_Dest_Imm8_X1, get_Dest_Imm8_X1
2491 },
2492 {
2493 TILEPRO_OP_TYPE_ADDRESS, BFD_RELOC(NONE),
2494 10, 1, 0, 0, 1, TILEPRO_LOG2_SN_INSTRUCTION_SIZE_IN_BYTES,
2495 create_BrOff_SN, get_BrOff_SN
2496 },
2497 {
2498 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(NONE),
2499 8, 0, 0, 0, 0, 0,
2500 create_Imm8_SN, get_Imm8_SN
2501 },
2502 {
2503 TILEPRO_OP_TYPE_IMMEDIATE, BFD_RELOC(NONE),
2504 8, 1, 0, 0, 0, 0,
2505 create_Imm8_SN, get_Imm8_SN
2506 },
2507 {
2508 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2509 2, 0, 0, 1, 0, 0,
2510 create_Dest_SN, get_Dest_SN
2511 },
2512 {
2513 TILEPRO_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2514 2, 0, 1, 0, 0, 0,
2515 create_Src_SN, get_Src_SN
2516 }
2517};
2518
2519
2520
2521
2522/* Given a set of bundle bits and a specific pipe, returns which
2523 * instruction the bundle contains in that pipe.
2524 */
2525const struct tilepro_opcode *
2526find_opcode(tilepro_bundle_bits bits, tilepro_pipeline pipe)
2527{
2528 const unsigned short *table = tilepro_bundle_decoder_fsms[pipe];
2529 int index = 0;
2530
2531 while (1)
2532 {
2533 unsigned short bitspec = table[index];
2534 unsigned int bitfield =
2535 ((unsigned int)(bits >> (bitspec & 63))) & (bitspec >> 6);
2536
2537 unsigned short next = table[index + 1 + bitfield];
2538 if (next <= TILEPRO_OPC_NONE)
2539 return &tilepro_opcodes[next];
2540
2541 index = next - TILEPRO_OPC_NONE;
2542 }
2543}
2544
2545
2546int
2547parse_insn_tilepro(tilepro_bundle_bits bits,
2548 unsigned int pc,
2549 struct tilepro_decoded_instruction
2550 decoded[TILEPRO_MAX_INSTRUCTIONS_PER_BUNDLE])
2551{
2552 int num_instructions = 0;
2553 int pipe;
2554
2555 int min_pipe, max_pipe;
2556 if ((bits & TILEPRO_BUNDLE_Y_ENCODING_MASK) == 0)
2557 {
2558 min_pipe = TILEPRO_PIPELINE_X0;
2559 max_pipe = TILEPRO_PIPELINE_X1;
2560 }
2561 else
2562 {
2563 min_pipe = TILEPRO_PIPELINE_Y0;
2564 max_pipe = TILEPRO_PIPELINE_Y2;
2565 }
2566
2567 /* For each pipe, find an instruction that fits. */
2568 for (pipe = min_pipe; pipe <= max_pipe; pipe++)
2569 {
2570 const struct tilepro_opcode *opc;
2571 struct tilepro_decoded_instruction *d;
2572 int i;
2573
2574 d = &decoded[num_instructions++];
2575 opc = find_opcode (bits, (tilepro_pipeline)pipe);
2576 d->opcode = opc;
2577
2578 /* Decode each operand, sign extending, etc. as appropriate. */
2579 for (i = 0; i < opc->num_operands; i++)
2580 {
2581 const struct tilepro_operand *op =
2582 &tilepro_operands[opc->operands[pipe][i]];
2583 int opval = op->extract (bits);
2584 if (op->is_signed)
2585 {
2586 /* Sign-extend the operand. */
2587 int shift = (int)((sizeof(int) * 8) - op->num_bits);
2588 opval = (opval << shift) >> shift;
2589 }
2590
2591 /* Adjust PC-relative scaled branch offsets. */
2592 if (op->type == TILEPRO_OP_TYPE_ADDRESS)
2593 {
2594 opval *= TILEPRO_BUNDLE_SIZE_IN_BYTES;
2595 opval += (int)pc;
2596 }
2597
2598 /* Record the final value. */
2599 d->operands[i] = op;
2600 d->operand_values[i] = opval;
2601 }
2602 }
2603
2604 return num_instructions;
2605}
diff --git a/arch/tile/kernel/tile-desc_64.c b/arch/tile/kernel/tile-desc_64.c
deleted file mode 100644
index 65b5f8aca706..000000000000
--- a/arch/tile/kernel/tile-desc_64.c
+++ /dev/null
@@ -1,2218 +0,0 @@
1/* TILE-Gx opcode information.
2 *
3 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 *
15 *
16 *
17 *
18 *
19 */
20
21/* This define is BFD_RELOC_##x for real bfd, or -1 for everyone else. */
22#define BFD_RELOC(x) -1
23
24/* Special registers. */
25#define TREG_LR 55
26#define TREG_SN 56
27#define TREG_ZERO 63
28
29#include <linux/stddef.h>
30#include <asm/tile-desc.h>
31
32const struct tilegx_opcode tilegx_opcodes[334] =
33{
34 { "bpt", TILEGX_OPC_BPT, 0x2, 0, TREG_ZERO, 0,
35 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
36 },
37 { "info", TILEGX_OPC_INFO, 0xf, 1, TREG_ZERO, 1,
38 { { 0 }, { 1 }, { 2 }, { 3 }, { 0, } },
39 },
40 { "infol", TILEGX_OPC_INFOL, 0x3, 1, TREG_ZERO, 1,
41 { { 4 }, { 5 }, { 0, }, { 0, }, { 0, } },
42 },
43 { "move", TILEGX_OPC_MOVE, 0xf, 2, TREG_ZERO, 1,
44 { { 6, 7 }, { 8, 9 }, { 10, 11 }, { 12, 13 }, { 0, } },
45 },
46 { "movei", TILEGX_OPC_MOVEI, 0xf, 2, TREG_ZERO, 1,
47 { { 6, 0 }, { 8, 1 }, { 10, 2 }, { 12, 3 }, { 0, } },
48 },
49 { "moveli", TILEGX_OPC_MOVELI, 0x3, 2, TREG_ZERO, 1,
50 { { 6, 4 }, { 8, 5 }, { 0, }, { 0, }, { 0, } },
51 },
52 { "prefetch", TILEGX_OPC_PREFETCH, 0x12, 1, TREG_ZERO, 1,
53 { { 0, }, { 9 }, { 0, }, { 0, }, { 14 } },
54 },
55 { "prefetch_add_l1", TILEGX_OPC_PREFETCH_ADD_L1, 0x2, 2, TREG_ZERO, 1,
56 { { 0, }, { 15, 1 }, { 0, }, { 0, }, { 0, } },
57 },
58 { "prefetch_add_l1_fault", TILEGX_OPC_PREFETCH_ADD_L1_FAULT, 0x2, 2, TREG_ZERO, 1,
59 { { 0, }, { 15, 1 }, { 0, }, { 0, }, { 0, } },
60 },
61 { "prefetch_add_l2", TILEGX_OPC_PREFETCH_ADD_L2, 0x2, 2, TREG_ZERO, 1,
62 { { 0, }, { 15, 1 }, { 0, }, { 0, }, { 0, } },
63 },
64 { "prefetch_add_l2_fault", TILEGX_OPC_PREFETCH_ADD_L2_FAULT, 0x2, 2, TREG_ZERO, 1,
65 { { 0, }, { 15, 1 }, { 0, }, { 0, }, { 0, } },
66 },
67 { "prefetch_add_l3", TILEGX_OPC_PREFETCH_ADD_L3, 0x2, 2, TREG_ZERO, 1,
68 { { 0, }, { 15, 1 }, { 0, }, { 0, }, { 0, } },
69 },
70 { "prefetch_add_l3_fault", TILEGX_OPC_PREFETCH_ADD_L3_FAULT, 0x2, 2, TREG_ZERO, 1,
71 { { 0, }, { 15, 1 }, { 0, }, { 0, }, { 0, } },
72 },
73 { "prefetch_l1", TILEGX_OPC_PREFETCH_L1, 0x12, 1, TREG_ZERO, 1,
74 { { 0, }, { 9 }, { 0, }, { 0, }, { 14 } },
75 },
76 { "prefetch_l1_fault", TILEGX_OPC_PREFETCH_L1_FAULT, 0x12, 1, TREG_ZERO, 1,
77 { { 0, }, { 9 }, { 0, }, { 0, }, { 14 } },
78 },
79 { "prefetch_l2", TILEGX_OPC_PREFETCH_L2, 0x12, 1, TREG_ZERO, 1,
80 { { 0, }, { 9 }, { 0, }, { 0, }, { 14 } },
81 },
82 { "prefetch_l2_fault", TILEGX_OPC_PREFETCH_L2_FAULT, 0x12, 1, TREG_ZERO, 1,
83 { { 0, }, { 9 }, { 0, }, { 0, }, { 14 } },
84 },
85 { "prefetch_l3", TILEGX_OPC_PREFETCH_L3, 0x12, 1, TREG_ZERO, 1,
86 { { 0, }, { 9 }, { 0, }, { 0, }, { 14 } },
87 },
88 { "prefetch_l3_fault", TILEGX_OPC_PREFETCH_L3_FAULT, 0x12, 1, TREG_ZERO, 1,
89 { { 0, }, { 9 }, { 0, }, { 0, }, { 14 } },
90 },
91 { "raise", TILEGX_OPC_RAISE, 0x2, 0, TREG_ZERO, 1,
92 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
93 },
94 { "add", TILEGX_OPC_ADD, 0xf, 3, TREG_ZERO, 1,
95 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
96 },
97 { "addi", TILEGX_OPC_ADDI, 0xf, 3, TREG_ZERO, 1,
98 { { 6, 7, 0 }, { 8, 9, 1 }, { 10, 11, 2 }, { 12, 13, 3 }, { 0, } },
99 },
100 { "addli", TILEGX_OPC_ADDLI, 0x3, 3, TREG_ZERO, 1,
101 { { 6, 7, 4 }, { 8, 9, 5 }, { 0, }, { 0, }, { 0, } },
102 },
103 { "addx", TILEGX_OPC_ADDX, 0xf, 3, TREG_ZERO, 1,
104 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
105 },
106 { "addxi", TILEGX_OPC_ADDXI, 0xf, 3, TREG_ZERO, 1,
107 { { 6, 7, 0 }, { 8, 9, 1 }, { 10, 11, 2 }, { 12, 13, 3 }, { 0, } },
108 },
109 { "addxli", TILEGX_OPC_ADDXLI, 0x3, 3, TREG_ZERO, 1,
110 { { 6, 7, 4 }, { 8, 9, 5 }, { 0, }, { 0, }, { 0, } },
111 },
112 { "addxsc", TILEGX_OPC_ADDXSC, 0x3, 3, TREG_ZERO, 1,
113 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
114 },
115 { "and", TILEGX_OPC_AND, 0xf, 3, TREG_ZERO, 1,
116 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
117 },
118 { "andi", TILEGX_OPC_ANDI, 0xf, 3, TREG_ZERO, 1,
119 { { 6, 7, 0 }, { 8, 9, 1 }, { 10, 11, 2 }, { 12, 13, 3 }, { 0, } },
120 },
121 { "beqz", TILEGX_OPC_BEQZ, 0x2, 2, TREG_ZERO, 1,
122 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
123 },
124 { "beqzt", TILEGX_OPC_BEQZT, 0x2, 2, TREG_ZERO, 1,
125 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
126 },
127 { "bfexts", TILEGX_OPC_BFEXTS, 0x1, 4, TREG_ZERO, 1,
128 { { 6, 7, 21, 22 }, { 0, }, { 0, }, { 0, }, { 0, } },
129 },
130 { "bfextu", TILEGX_OPC_BFEXTU, 0x1, 4, TREG_ZERO, 1,
131 { { 6, 7, 21, 22 }, { 0, }, { 0, }, { 0, }, { 0, } },
132 },
133 { "bfins", TILEGX_OPC_BFINS, 0x1, 4, TREG_ZERO, 1,
134 { { 23, 7, 21, 22 }, { 0, }, { 0, }, { 0, }, { 0, } },
135 },
136 { "bgez", TILEGX_OPC_BGEZ, 0x2, 2, TREG_ZERO, 1,
137 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
138 },
139 { "bgezt", TILEGX_OPC_BGEZT, 0x2, 2, TREG_ZERO, 1,
140 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
141 },
142 { "bgtz", TILEGX_OPC_BGTZ, 0x2, 2, TREG_ZERO, 1,
143 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
144 },
145 { "bgtzt", TILEGX_OPC_BGTZT, 0x2, 2, TREG_ZERO, 1,
146 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
147 },
148 { "blbc", TILEGX_OPC_BLBC, 0x2, 2, TREG_ZERO, 1,
149 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
150 },
151 { "blbct", TILEGX_OPC_BLBCT, 0x2, 2, TREG_ZERO, 1,
152 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
153 },
154 { "blbs", TILEGX_OPC_BLBS, 0x2, 2, TREG_ZERO, 1,
155 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
156 },
157 { "blbst", TILEGX_OPC_BLBST, 0x2, 2, TREG_ZERO, 1,
158 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
159 },
160 { "blez", TILEGX_OPC_BLEZ, 0x2, 2, TREG_ZERO, 1,
161 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
162 },
163 { "blezt", TILEGX_OPC_BLEZT, 0x2, 2, TREG_ZERO, 1,
164 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
165 },
166 { "bltz", TILEGX_OPC_BLTZ, 0x2, 2, TREG_ZERO, 1,
167 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
168 },
169 { "bltzt", TILEGX_OPC_BLTZT, 0x2, 2, TREG_ZERO, 1,
170 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
171 },
172 { "bnez", TILEGX_OPC_BNEZ, 0x2, 2, TREG_ZERO, 1,
173 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
174 },
175 { "bnezt", TILEGX_OPC_BNEZT, 0x2, 2, TREG_ZERO, 1,
176 { { 0, }, { 9, 20 }, { 0, }, { 0, }, { 0, } },
177 },
178 { "clz", TILEGX_OPC_CLZ, 0x5, 2, TREG_ZERO, 1,
179 { { 6, 7 }, { 0, }, { 10, 11 }, { 0, }, { 0, } },
180 },
181 { "cmoveqz", TILEGX_OPC_CMOVEQZ, 0x5, 3, TREG_ZERO, 1,
182 { { 23, 7, 16 }, { 0, }, { 24, 11, 18 }, { 0, }, { 0, } },
183 },
184 { "cmovnez", TILEGX_OPC_CMOVNEZ, 0x5, 3, TREG_ZERO, 1,
185 { { 23, 7, 16 }, { 0, }, { 24, 11, 18 }, { 0, }, { 0, } },
186 },
187 { "cmpeq", TILEGX_OPC_CMPEQ, 0xf, 3, TREG_ZERO, 1,
188 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
189 },
190 { "cmpeqi", TILEGX_OPC_CMPEQI, 0xf, 3, TREG_ZERO, 1,
191 { { 6, 7, 0 }, { 8, 9, 1 }, { 10, 11, 2 }, { 12, 13, 3 }, { 0, } },
192 },
193 { "cmpexch", TILEGX_OPC_CMPEXCH, 0x2, 3, TREG_ZERO, 1,
194 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
195 },
196 { "cmpexch4", TILEGX_OPC_CMPEXCH4, 0x2, 3, TREG_ZERO, 1,
197 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
198 },
199 { "cmples", TILEGX_OPC_CMPLES, 0xf, 3, TREG_ZERO, 1,
200 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
201 },
202 { "cmpleu", TILEGX_OPC_CMPLEU, 0xf, 3, TREG_ZERO, 1,
203 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
204 },
205 { "cmplts", TILEGX_OPC_CMPLTS, 0xf, 3, TREG_ZERO, 1,
206 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
207 },
208 { "cmpltsi", TILEGX_OPC_CMPLTSI, 0xf, 3, TREG_ZERO, 1,
209 { { 6, 7, 0 }, { 8, 9, 1 }, { 10, 11, 2 }, { 12, 13, 3 }, { 0, } },
210 },
211 { "cmpltu", TILEGX_OPC_CMPLTU, 0xf, 3, TREG_ZERO, 1,
212 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
213 },
214 { "cmpltui", TILEGX_OPC_CMPLTUI, 0x3, 3, TREG_ZERO, 1,
215 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
216 },
217 { "cmpne", TILEGX_OPC_CMPNE, 0xf, 3, TREG_ZERO, 1,
218 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
219 },
220 { "cmul", TILEGX_OPC_CMUL, 0x1, 3, TREG_ZERO, 1,
221 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
222 },
223 { "cmula", TILEGX_OPC_CMULA, 0x1, 3, TREG_ZERO, 1,
224 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
225 },
226 { "cmulaf", TILEGX_OPC_CMULAF, 0x1, 3, TREG_ZERO, 1,
227 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
228 },
229 { "cmulf", TILEGX_OPC_CMULF, 0x1, 3, TREG_ZERO, 1,
230 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
231 },
232 { "cmulfr", TILEGX_OPC_CMULFR, 0x1, 3, TREG_ZERO, 1,
233 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
234 },
235 { "cmulh", TILEGX_OPC_CMULH, 0x1, 3, TREG_ZERO, 1,
236 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
237 },
238 { "cmulhr", TILEGX_OPC_CMULHR, 0x1, 3, TREG_ZERO, 1,
239 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
240 },
241 { "crc32_32", TILEGX_OPC_CRC32_32, 0x1, 3, TREG_ZERO, 1,
242 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
243 },
244 { "crc32_8", TILEGX_OPC_CRC32_8, 0x1, 3, TREG_ZERO, 1,
245 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
246 },
247 { "ctz", TILEGX_OPC_CTZ, 0x5, 2, TREG_ZERO, 1,
248 { { 6, 7 }, { 0, }, { 10, 11 }, { 0, }, { 0, } },
249 },
250 { "dblalign", TILEGX_OPC_DBLALIGN, 0x1, 3, TREG_ZERO, 1,
251 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
252 },
253 { "dblalign2", TILEGX_OPC_DBLALIGN2, 0x3, 3, TREG_ZERO, 1,
254 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
255 },
256 { "dblalign4", TILEGX_OPC_DBLALIGN4, 0x3, 3, TREG_ZERO, 1,
257 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
258 },
259 { "dblalign6", TILEGX_OPC_DBLALIGN6, 0x3, 3, TREG_ZERO, 1,
260 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
261 },
262 { "drain", TILEGX_OPC_DRAIN, 0x2, 0, TREG_ZERO, 0,
263 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
264 },
265 { "dtlbpr", TILEGX_OPC_DTLBPR, 0x2, 1, TREG_ZERO, 1,
266 { { 0, }, { 9 }, { 0, }, { 0, }, { 0, } },
267 },
268 { "exch", TILEGX_OPC_EXCH, 0x2, 3, TREG_ZERO, 1,
269 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
270 },
271 { "exch4", TILEGX_OPC_EXCH4, 0x2, 3, TREG_ZERO, 1,
272 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
273 },
274 { "fdouble_add_flags", TILEGX_OPC_FDOUBLE_ADD_FLAGS, 0x1, 3, TREG_ZERO, 1,
275 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
276 },
277 { "fdouble_addsub", TILEGX_OPC_FDOUBLE_ADDSUB, 0x1, 3, TREG_ZERO, 1,
278 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
279 },
280 { "fdouble_mul_flags", TILEGX_OPC_FDOUBLE_MUL_FLAGS, 0x1, 3, TREG_ZERO, 1,
281 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
282 },
283 { "fdouble_pack1", TILEGX_OPC_FDOUBLE_PACK1, 0x1, 3, TREG_ZERO, 1,
284 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
285 },
286 { "fdouble_pack2", TILEGX_OPC_FDOUBLE_PACK2, 0x1, 3, TREG_ZERO, 1,
287 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
288 },
289 { "fdouble_sub_flags", TILEGX_OPC_FDOUBLE_SUB_FLAGS, 0x1, 3, TREG_ZERO, 1,
290 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
291 },
292 { "fdouble_unpack_max", TILEGX_OPC_FDOUBLE_UNPACK_MAX, 0x1, 3, TREG_ZERO, 1,
293 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
294 },
295 { "fdouble_unpack_min", TILEGX_OPC_FDOUBLE_UNPACK_MIN, 0x1, 3, TREG_ZERO, 1,
296 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
297 },
298 { "fetchadd", TILEGX_OPC_FETCHADD, 0x2, 3, TREG_ZERO, 1,
299 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
300 },
301 { "fetchadd4", TILEGX_OPC_FETCHADD4, 0x2, 3, TREG_ZERO, 1,
302 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
303 },
304 { "fetchaddgez", TILEGX_OPC_FETCHADDGEZ, 0x2, 3, TREG_ZERO, 1,
305 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
306 },
307 { "fetchaddgez4", TILEGX_OPC_FETCHADDGEZ4, 0x2, 3, TREG_ZERO, 1,
308 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
309 },
310 { "fetchand", TILEGX_OPC_FETCHAND, 0x2, 3, TREG_ZERO, 1,
311 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
312 },
313 { "fetchand4", TILEGX_OPC_FETCHAND4, 0x2, 3, TREG_ZERO, 1,
314 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
315 },
316 { "fetchor", TILEGX_OPC_FETCHOR, 0x2, 3, TREG_ZERO, 1,
317 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
318 },
319 { "fetchor4", TILEGX_OPC_FETCHOR4, 0x2, 3, TREG_ZERO, 1,
320 { { 0, }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
321 },
322 { "finv", TILEGX_OPC_FINV, 0x2, 1, TREG_ZERO, 1,
323 { { 0, }, { 9 }, { 0, }, { 0, }, { 0, } },
324 },
325 { "flush", TILEGX_OPC_FLUSH, 0x2, 1, TREG_ZERO, 1,
326 { { 0, }, { 9 }, { 0, }, { 0, }, { 0, } },
327 },
328 { "flushwb", TILEGX_OPC_FLUSHWB, 0x2, 0, TREG_ZERO, 1,
329 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
330 },
331 { "fnop", TILEGX_OPC_FNOP, 0xf, 0, TREG_ZERO, 1,
332 { { }, { }, { }, { }, { 0, } },
333 },
334 { "fsingle_add1", TILEGX_OPC_FSINGLE_ADD1, 0x1, 3, TREG_ZERO, 1,
335 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
336 },
337 { "fsingle_addsub2", TILEGX_OPC_FSINGLE_ADDSUB2, 0x1, 3, TREG_ZERO, 1,
338 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
339 },
340 { "fsingle_mul1", TILEGX_OPC_FSINGLE_MUL1, 0x1, 3, TREG_ZERO, 1,
341 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
342 },
343 { "fsingle_mul2", TILEGX_OPC_FSINGLE_MUL2, 0x1, 3, TREG_ZERO, 1,
344 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
345 },
346 { "fsingle_pack1", TILEGX_OPC_FSINGLE_PACK1, 0x5, 2, TREG_ZERO, 1,
347 { { 6, 7 }, { 0, }, { 10, 11 }, { 0, }, { 0, } },
348 },
349 { "fsingle_pack2", TILEGX_OPC_FSINGLE_PACK2, 0x1, 3, TREG_ZERO, 1,
350 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
351 },
352 { "fsingle_sub1", TILEGX_OPC_FSINGLE_SUB1, 0x1, 3, TREG_ZERO, 1,
353 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
354 },
355 { "icoh", TILEGX_OPC_ICOH, 0x2, 1, TREG_ZERO, 1,
356 { { 0, }, { 9 }, { 0, }, { 0, }, { 0, } },
357 },
358 { "ill", TILEGX_OPC_ILL, 0xa, 0, TREG_ZERO, 1,
359 { { 0, }, { }, { 0, }, { }, { 0, } },
360 },
361 { "inv", TILEGX_OPC_INV, 0x2, 1, TREG_ZERO, 1,
362 { { 0, }, { 9 }, { 0, }, { 0, }, { 0, } },
363 },
364 { "iret", TILEGX_OPC_IRET, 0x2, 0, TREG_ZERO, 1,
365 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
366 },
367 { "j", TILEGX_OPC_J, 0x2, 1, TREG_ZERO, 1,
368 { { 0, }, { 25 }, { 0, }, { 0, }, { 0, } },
369 },
370 { "jal", TILEGX_OPC_JAL, 0x2, 1, TREG_LR, 1,
371 { { 0, }, { 25 }, { 0, }, { 0, }, { 0, } },
372 },
373 { "jalr", TILEGX_OPC_JALR, 0xa, 1, TREG_LR, 1,
374 { { 0, }, { 9 }, { 0, }, { 13 }, { 0, } },
375 },
376 { "jalrp", TILEGX_OPC_JALRP, 0xa, 1, TREG_LR, 1,
377 { { 0, }, { 9 }, { 0, }, { 13 }, { 0, } },
378 },
379 { "jr", TILEGX_OPC_JR, 0xa, 1, TREG_ZERO, 1,
380 { { 0, }, { 9 }, { 0, }, { 13 }, { 0, } },
381 },
382 { "jrp", TILEGX_OPC_JRP, 0xa, 1, TREG_ZERO, 1,
383 { { 0, }, { 9 }, { 0, }, { 13 }, { 0, } },
384 },
385 { "ld", TILEGX_OPC_LD, 0x12, 2, TREG_ZERO, 1,
386 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 26, 14 } },
387 },
388 { "ld1s", TILEGX_OPC_LD1S, 0x12, 2, TREG_ZERO, 1,
389 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 26, 14 } },
390 },
391 { "ld1s_add", TILEGX_OPC_LD1S_ADD, 0x2, 3, TREG_ZERO, 1,
392 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
393 },
394 { "ld1u", TILEGX_OPC_LD1U, 0x12, 2, TREG_ZERO, 1,
395 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 26, 14 } },
396 },
397 { "ld1u_add", TILEGX_OPC_LD1U_ADD, 0x2, 3, TREG_ZERO, 1,
398 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
399 },
400 { "ld2s", TILEGX_OPC_LD2S, 0x12, 2, TREG_ZERO, 1,
401 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 26, 14 } },
402 },
403 { "ld2s_add", TILEGX_OPC_LD2S_ADD, 0x2, 3, TREG_ZERO, 1,
404 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
405 },
406 { "ld2u", TILEGX_OPC_LD2U, 0x12, 2, TREG_ZERO, 1,
407 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 26, 14 } },
408 },
409 { "ld2u_add", TILEGX_OPC_LD2U_ADD, 0x2, 3, TREG_ZERO, 1,
410 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
411 },
412 { "ld4s", TILEGX_OPC_LD4S, 0x12, 2, TREG_ZERO, 1,
413 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 26, 14 } },
414 },
415 { "ld4s_add", TILEGX_OPC_LD4S_ADD, 0x2, 3, TREG_ZERO, 1,
416 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
417 },
418 { "ld4u", TILEGX_OPC_LD4U, 0x12, 2, TREG_ZERO, 1,
419 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 26, 14 } },
420 },
421 { "ld4u_add", TILEGX_OPC_LD4U_ADD, 0x2, 3, TREG_ZERO, 1,
422 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
423 },
424 { "ld_add", TILEGX_OPC_LD_ADD, 0x2, 3, TREG_ZERO, 1,
425 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
426 },
427 { "ldna", TILEGX_OPC_LDNA, 0x2, 2, TREG_ZERO, 1,
428 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 0, } },
429 },
430 { "ldna_add", TILEGX_OPC_LDNA_ADD, 0x2, 3, TREG_ZERO, 1,
431 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
432 },
433 { "ldnt", TILEGX_OPC_LDNT, 0x2, 2, TREG_ZERO, 1,
434 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 0, } },
435 },
436 { "ldnt1s", TILEGX_OPC_LDNT1S, 0x2, 2, TREG_ZERO, 1,
437 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 0, } },
438 },
439 { "ldnt1s_add", TILEGX_OPC_LDNT1S_ADD, 0x2, 3, TREG_ZERO, 1,
440 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
441 },
442 { "ldnt1u", TILEGX_OPC_LDNT1U, 0x2, 2, TREG_ZERO, 1,
443 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 0, } },
444 },
445 { "ldnt1u_add", TILEGX_OPC_LDNT1U_ADD, 0x2, 3, TREG_ZERO, 1,
446 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
447 },
448 { "ldnt2s", TILEGX_OPC_LDNT2S, 0x2, 2, TREG_ZERO, 1,
449 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 0, } },
450 },
451 { "ldnt2s_add", TILEGX_OPC_LDNT2S_ADD, 0x2, 3, TREG_ZERO, 1,
452 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
453 },
454 { "ldnt2u", TILEGX_OPC_LDNT2U, 0x2, 2, TREG_ZERO, 1,
455 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 0, } },
456 },
457 { "ldnt2u_add", TILEGX_OPC_LDNT2U_ADD, 0x2, 3, TREG_ZERO, 1,
458 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
459 },
460 { "ldnt4s", TILEGX_OPC_LDNT4S, 0x2, 2, TREG_ZERO, 1,
461 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 0, } },
462 },
463 { "ldnt4s_add", TILEGX_OPC_LDNT4S_ADD, 0x2, 3, TREG_ZERO, 1,
464 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
465 },
466 { "ldnt4u", TILEGX_OPC_LDNT4U, 0x2, 2, TREG_ZERO, 1,
467 { { 0, }, { 8, 9 }, { 0, }, { 0, }, { 0, } },
468 },
469 { "ldnt4u_add", TILEGX_OPC_LDNT4U_ADD, 0x2, 3, TREG_ZERO, 1,
470 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
471 },
472 { "ldnt_add", TILEGX_OPC_LDNT_ADD, 0x2, 3, TREG_ZERO, 1,
473 { { 0, }, { 8, 15, 1 }, { 0, }, { 0, }, { 0, } },
474 },
475 { "lnk", TILEGX_OPC_LNK, 0xa, 1, TREG_ZERO, 1,
476 { { 0, }, { 8 }, { 0, }, { 12 }, { 0, } },
477 },
478 { "mf", TILEGX_OPC_MF, 0x2, 0, TREG_ZERO, 1,
479 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
480 },
481 { "mfspr", TILEGX_OPC_MFSPR, 0x2, 2, TREG_ZERO, 1,
482 { { 0, }, { 8, 27 }, { 0, }, { 0, }, { 0, } },
483 },
484 { "mm", TILEGX_OPC_MM, 0x1, 4, TREG_ZERO, 1,
485 { { 23, 7, 21, 22 }, { 0, }, { 0, }, { 0, }, { 0, } },
486 },
487 { "mnz", TILEGX_OPC_MNZ, 0xf, 3, TREG_ZERO, 1,
488 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
489 },
490 { "mtspr", TILEGX_OPC_MTSPR, 0x2, 2, TREG_ZERO, 1,
491 { { 0, }, { 28, 9 }, { 0, }, { 0, }, { 0, } },
492 },
493 { "mul_hs_hs", TILEGX_OPC_MUL_HS_HS, 0x5, 3, TREG_ZERO, 1,
494 { { 6, 7, 16 }, { 0, }, { 10, 11, 18 }, { 0, }, { 0, } },
495 },
496 { "mul_hs_hu", TILEGX_OPC_MUL_HS_HU, 0x1, 3, TREG_ZERO, 1,
497 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
498 },
499 { "mul_hs_ls", TILEGX_OPC_MUL_HS_LS, 0x1, 3, TREG_ZERO, 1,
500 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
501 },
502 { "mul_hs_lu", TILEGX_OPC_MUL_HS_LU, 0x1, 3, TREG_ZERO, 1,
503 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
504 },
505 { "mul_hu_hu", TILEGX_OPC_MUL_HU_HU, 0x5, 3, TREG_ZERO, 1,
506 { { 6, 7, 16 }, { 0, }, { 10, 11, 18 }, { 0, }, { 0, } },
507 },
508 { "mul_hu_ls", TILEGX_OPC_MUL_HU_LS, 0x1, 3, TREG_ZERO, 1,
509 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
510 },
511 { "mul_hu_lu", TILEGX_OPC_MUL_HU_LU, 0x1, 3, TREG_ZERO, 1,
512 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
513 },
514 { "mul_ls_ls", TILEGX_OPC_MUL_LS_LS, 0x5, 3, TREG_ZERO, 1,
515 { { 6, 7, 16 }, { 0, }, { 10, 11, 18 }, { 0, }, { 0, } },
516 },
517 { "mul_ls_lu", TILEGX_OPC_MUL_LS_LU, 0x1, 3, TREG_ZERO, 1,
518 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
519 },
520 { "mul_lu_lu", TILEGX_OPC_MUL_LU_LU, 0x5, 3, TREG_ZERO, 1,
521 { { 6, 7, 16 }, { 0, }, { 10, 11, 18 }, { 0, }, { 0, } },
522 },
523 { "mula_hs_hs", TILEGX_OPC_MULA_HS_HS, 0x5, 3, TREG_ZERO, 1,
524 { { 23, 7, 16 }, { 0, }, { 24, 11, 18 }, { 0, }, { 0, } },
525 },
526 { "mula_hs_hu", TILEGX_OPC_MULA_HS_HU, 0x1, 3, TREG_ZERO, 1,
527 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
528 },
529 { "mula_hs_ls", TILEGX_OPC_MULA_HS_LS, 0x1, 3, TREG_ZERO, 1,
530 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
531 },
532 { "mula_hs_lu", TILEGX_OPC_MULA_HS_LU, 0x1, 3, TREG_ZERO, 1,
533 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
534 },
535 { "mula_hu_hu", TILEGX_OPC_MULA_HU_HU, 0x5, 3, TREG_ZERO, 1,
536 { { 23, 7, 16 }, { 0, }, { 24, 11, 18 }, { 0, }, { 0, } },
537 },
538 { "mula_hu_ls", TILEGX_OPC_MULA_HU_LS, 0x1, 3, TREG_ZERO, 1,
539 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
540 },
541 { "mula_hu_lu", TILEGX_OPC_MULA_HU_LU, 0x1, 3, TREG_ZERO, 1,
542 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
543 },
544 { "mula_ls_ls", TILEGX_OPC_MULA_LS_LS, 0x5, 3, TREG_ZERO, 1,
545 { { 23, 7, 16 }, { 0, }, { 24, 11, 18 }, { 0, }, { 0, } },
546 },
547 { "mula_ls_lu", TILEGX_OPC_MULA_LS_LU, 0x1, 3, TREG_ZERO, 1,
548 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
549 },
550 { "mula_lu_lu", TILEGX_OPC_MULA_LU_LU, 0x5, 3, TREG_ZERO, 1,
551 { { 23, 7, 16 }, { 0, }, { 24, 11, 18 }, { 0, }, { 0, } },
552 },
553 { "mulax", TILEGX_OPC_MULAX, 0x5, 3, TREG_ZERO, 1,
554 { { 23, 7, 16 }, { 0, }, { 24, 11, 18 }, { 0, }, { 0, } },
555 },
556 { "mulx", TILEGX_OPC_MULX, 0x5, 3, TREG_ZERO, 1,
557 { { 6, 7, 16 }, { 0, }, { 10, 11, 18 }, { 0, }, { 0, } },
558 },
559 { "mz", TILEGX_OPC_MZ, 0xf, 3, TREG_ZERO, 1,
560 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
561 },
562 { "nap", TILEGX_OPC_NAP, 0x2, 0, TREG_ZERO, 0,
563 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
564 },
565 { "nop", TILEGX_OPC_NOP, 0xf, 0, TREG_ZERO, 1,
566 { { }, { }, { }, { }, { 0, } },
567 },
568 { "nor", TILEGX_OPC_NOR, 0xf, 3, TREG_ZERO, 1,
569 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
570 },
571 { "or", TILEGX_OPC_OR, 0xf, 3, TREG_ZERO, 1,
572 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
573 },
574 { "ori", TILEGX_OPC_ORI, 0x3, 3, TREG_ZERO, 1,
575 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
576 },
577 { "pcnt", TILEGX_OPC_PCNT, 0x5, 2, TREG_ZERO, 1,
578 { { 6, 7 }, { 0, }, { 10, 11 }, { 0, }, { 0, } },
579 },
580 { "revbits", TILEGX_OPC_REVBITS, 0x5, 2, TREG_ZERO, 1,
581 { { 6, 7 }, { 0, }, { 10, 11 }, { 0, }, { 0, } },
582 },
583 { "revbytes", TILEGX_OPC_REVBYTES, 0x5, 2, TREG_ZERO, 1,
584 { { 6, 7 }, { 0, }, { 10, 11 }, { 0, }, { 0, } },
585 },
586 { "rotl", TILEGX_OPC_ROTL, 0xf, 3, TREG_ZERO, 1,
587 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
588 },
589 { "rotli", TILEGX_OPC_ROTLI, 0xf, 3, TREG_ZERO, 1,
590 { { 6, 7, 29 }, { 8, 9, 30 }, { 10, 11, 31 }, { 12, 13, 32 }, { 0, } },
591 },
592 { "shl", TILEGX_OPC_SHL, 0xf, 3, TREG_ZERO, 1,
593 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
594 },
595 { "shl16insli", TILEGX_OPC_SHL16INSLI, 0x3, 3, TREG_ZERO, 1,
596 { { 6, 7, 4 }, { 8, 9, 5 }, { 0, }, { 0, }, { 0, } },
597 },
598 { "shl1add", TILEGX_OPC_SHL1ADD, 0xf, 3, TREG_ZERO, 1,
599 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
600 },
601 { "shl1addx", TILEGX_OPC_SHL1ADDX, 0xf, 3, TREG_ZERO, 1,
602 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
603 },
604 { "shl2add", TILEGX_OPC_SHL2ADD, 0xf, 3, TREG_ZERO, 1,
605 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
606 },
607 { "shl2addx", TILEGX_OPC_SHL2ADDX, 0xf, 3, TREG_ZERO, 1,
608 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
609 },
610 { "shl3add", TILEGX_OPC_SHL3ADD, 0xf, 3, TREG_ZERO, 1,
611 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
612 },
613 { "shl3addx", TILEGX_OPC_SHL3ADDX, 0xf, 3, TREG_ZERO, 1,
614 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
615 },
616 { "shli", TILEGX_OPC_SHLI, 0xf, 3, TREG_ZERO, 1,
617 { { 6, 7, 29 }, { 8, 9, 30 }, { 10, 11, 31 }, { 12, 13, 32 }, { 0, } },
618 },
619 { "shlx", TILEGX_OPC_SHLX, 0x3, 3, TREG_ZERO, 1,
620 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
621 },
622 { "shlxi", TILEGX_OPC_SHLXI, 0x3, 3, TREG_ZERO, 1,
623 { { 6, 7, 29 }, { 8, 9, 30 }, { 0, }, { 0, }, { 0, } },
624 },
625 { "shrs", TILEGX_OPC_SHRS, 0xf, 3, TREG_ZERO, 1,
626 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
627 },
628 { "shrsi", TILEGX_OPC_SHRSI, 0xf, 3, TREG_ZERO, 1,
629 { { 6, 7, 29 }, { 8, 9, 30 }, { 10, 11, 31 }, { 12, 13, 32 }, { 0, } },
630 },
631 { "shru", TILEGX_OPC_SHRU, 0xf, 3, TREG_ZERO, 1,
632 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
633 },
634 { "shrui", TILEGX_OPC_SHRUI, 0xf, 3, TREG_ZERO, 1,
635 { { 6, 7, 29 }, { 8, 9, 30 }, { 10, 11, 31 }, { 12, 13, 32 }, { 0, } },
636 },
637 { "shrux", TILEGX_OPC_SHRUX, 0x3, 3, TREG_ZERO, 1,
638 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
639 },
640 { "shruxi", TILEGX_OPC_SHRUXI, 0x3, 3, TREG_ZERO, 1,
641 { { 6, 7, 29 }, { 8, 9, 30 }, { 0, }, { 0, }, { 0, } },
642 },
643 { "shufflebytes", TILEGX_OPC_SHUFFLEBYTES, 0x1, 3, TREG_ZERO, 1,
644 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
645 },
646 { "st", TILEGX_OPC_ST, 0x12, 2, TREG_ZERO, 1,
647 { { 0, }, { 9, 17 }, { 0, }, { 0, }, { 14, 33 } },
648 },
649 { "st1", TILEGX_OPC_ST1, 0x12, 2, TREG_ZERO, 1,
650 { { 0, }, { 9, 17 }, { 0, }, { 0, }, { 14, 33 } },
651 },
652 { "st1_add", TILEGX_OPC_ST1_ADD, 0x2, 3, TREG_ZERO, 1,
653 { { 0, }, { 15, 17, 34 }, { 0, }, { 0, }, { 0, } },
654 },
655 { "st2", TILEGX_OPC_ST2, 0x12, 2, TREG_ZERO, 1,
656 { { 0, }, { 9, 17 }, { 0, }, { 0, }, { 14, 33 } },
657 },
658 { "st2_add", TILEGX_OPC_ST2_ADD, 0x2, 3, TREG_ZERO, 1,
659 { { 0, }, { 15, 17, 34 }, { 0, }, { 0, }, { 0, } },
660 },
661 { "st4", TILEGX_OPC_ST4, 0x12, 2, TREG_ZERO, 1,
662 { { 0, }, { 9, 17 }, { 0, }, { 0, }, { 14, 33 } },
663 },
664 { "st4_add", TILEGX_OPC_ST4_ADD, 0x2, 3, TREG_ZERO, 1,
665 { { 0, }, { 15, 17, 34 }, { 0, }, { 0, }, { 0, } },
666 },
667 { "st_add", TILEGX_OPC_ST_ADD, 0x2, 3, TREG_ZERO, 1,
668 { { 0, }, { 15, 17, 34 }, { 0, }, { 0, }, { 0, } },
669 },
670 { "stnt", TILEGX_OPC_STNT, 0x2, 2, TREG_ZERO, 1,
671 { { 0, }, { 9, 17 }, { 0, }, { 0, }, { 0, } },
672 },
673 { "stnt1", TILEGX_OPC_STNT1, 0x2, 2, TREG_ZERO, 1,
674 { { 0, }, { 9, 17 }, { 0, }, { 0, }, { 0, } },
675 },
676 { "stnt1_add", TILEGX_OPC_STNT1_ADD, 0x2, 3, TREG_ZERO, 1,
677 { { 0, }, { 15, 17, 34 }, { 0, }, { 0, }, { 0, } },
678 },
679 { "stnt2", TILEGX_OPC_STNT2, 0x2, 2, TREG_ZERO, 1,
680 { { 0, }, { 9, 17 }, { 0, }, { 0, }, { 0, } },
681 },
682 { "stnt2_add", TILEGX_OPC_STNT2_ADD, 0x2, 3, TREG_ZERO, 1,
683 { { 0, }, { 15, 17, 34 }, { 0, }, { 0, }, { 0, } },
684 },
685 { "stnt4", TILEGX_OPC_STNT4, 0x2, 2, TREG_ZERO, 1,
686 { { 0, }, { 9, 17 }, { 0, }, { 0, }, { 0, } },
687 },
688 { "stnt4_add", TILEGX_OPC_STNT4_ADD, 0x2, 3, TREG_ZERO, 1,
689 { { 0, }, { 15, 17, 34 }, { 0, }, { 0, }, { 0, } },
690 },
691 { "stnt_add", TILEGX_OPC_STNT_ADD, 0x2, 3, TREG_ZERO, 1,
692 { { 0, }, { 15, 17, 34 }, { 0, }, { 0, }, { 0, } },
693 },
694 { "sub", TILEGX_OPC_SUB, 0xf, 3, TREG_ZERO, 1,
695 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
696 },
697 { "subx", TILEGX_OPC_SUBX, 0xf, 3, TREG_ZERO, 1,
698 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
699 },
700 { "subxsc", TILEGX_OPC_SUBXSC, 0x3, 3, TREG_ZERO, 1,
701 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
702 },
703 { "swint0", TILEGX_OPC_SWINT0, 0x2, 0, TREG_ZERO, 0,
704 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
705 },
706 { "swint1", TILEGX_OPC_SWINT1, 0x2, 0, TREG_ZERO, 0,
707 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
708 },
709 { "swint2", TILEGX_OPC_SWINT2, 0x2, 0, TREG_ZERO, 0,
710 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
711 },
712 { "swint3", TILEGX_OPC_SWINT3, 0x2, 0, TREG_ZERO, 0,
713 { { 0, }, { }, { 0, }, { 0, }, { 0, } },
714 },
715 { "tblidxb0", TILEGX_OPC_TBLIDXB0, 0x5, 2, TREG_ZERO, 1,
716 { { 23, 7 }, { 0, }, { 24, 11 }, { 0, }, { 0, } },
717 },
718 { "tblidxb1", TILEGX_OPC_TBLIDXB1, 0x5, 2, TREG_ZERO, 1,
719 { { 23, 7 }, { 0, }, { 24, 11 }, { 0, }, { 0, } },
720 },
721 { "tblidxb2", TILEGX_OPC_TBLIDXB2, 0x5, 2, TREG_ZERO, 1,
722 { { 23, 7 }, { 0, }, { 24, 11 }, { 0, }, { 0, } },
723 },
724 { "tblidxb3", TILEGX_OPC_TBLIDXB3, 0x5, 2, TREG_ZERO, 1,
725 { { 23, 7 }, { 0, }, { 24, 11 }, { 0, }, { 0, } },
726 },
727 { "v1add", TILEGX_OPC_V1ADD, 0x3, 3, TREG_ZERO, 1,
728 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
729 },
730 { "v1addi", TILEGX_OPC_V1ADDI, 0x3, 3, TREG_ZERO, 1,
731 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
732 },
733 { "v1adduc", TILEGX_OPC_V1ADDUC, 0x3, 3, TREG_ZERO, 1,
734 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
735 },
736 { "v1adiffu", TILEGX_OPC_V1ADIFFU, 0x1, 3, TREG_ZERO, 1,
737 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
738 },
739 { "v1avgu", TILEGX_OPC_V1AVGU, 0x1, 3, TREG_ZERO, 1,
740 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
741 },
742 { "v1cmpeq", TILEGX_OPC_V1CMPEQ, 0x3, 3, TREG_ZERO, 1,
743 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
744 },
745 { "v1cmpeqi", TILEGX_OPC_V1CMPEQI, 0x3, 3, TREG_ZERO, 1,
746 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
747 },
748 { "v1cmples", TILEGX_OPC_V1CMPLES, 0x3, 3, TREG_ZERO, 1,
749 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
750 },
751 { "v1cmpleu", TILEGX_OPC_V1CMPLEU, 0x3, 3, TREG_ZERO, 1,
752 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
753 },
754 { "v1cmplts", TILEGX_OPC_V1CMPLTS, 0x3, 3, TREG_ZERO, 1,
755 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
756 },
757 { "v1cmpltsi", TILEGX_OPC_V1CMPLTSI, 0x3, 3, TREG_ZERO, 1,
758 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
759 },
760 { "v1cmpltu", TILEGX_OPC_V1CMPLTU, 0x3, 3, TREG_ZERO, 1,
761 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
762 },
763 { "v1cmpltui", TILEGX_OPC_V1CMPLTUI, 0x3, 3, TREG_ZERO, 1,
764 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
765 },
766 { "v1cmpne", TILEGX_OPC_V1CMPNE, 0x3, 3, TREG_ZERO, 1,
767 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
768 },
769 { "v1ddotpu", TILEGX_OPC_V1DDOTPU, 0x1, 3, TREG_ZERO, 1,
770 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
771 },
772 { "v1ddotpua", TILEGX_OPC_V1DDOTPUA, 0x1, 3, TREG_ZERO, 1,
773 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
774 },
775 { "v1ddotpus", TILEGX_OPC_V1DDOTPUS, 0x1, 3, TREG_ZERO, 1,
776 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
777 },
778 { "v1ddotpusa", TILEGX_OPC_V1DDOTPUSA, 0x1, 3, TREG_ZERO, 1,
779 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
780 },
781 { "v1dotp", TILEGX_OPC_V1DOTP, 0x1, 3, TREG_ZERO, 1,
782 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
783 },
784 { "v1dotpa", TILEGX_OPC_V1DOTPA, 0x1, 3, TREG_ZERO, 1,
785 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
786 },
787 { "v1dotpu", TILEGX_OPC_V1DOTPU, 0x1, 3, TREG_ZERO, 1,
788 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
789 },
790 { "v1dotpua", TILEGX_OPC_V1DOTPUA, 0x1, 3, TREG_ZERO, 1,
791 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
792 },
793 { "v1dotpus", TILEGX_OPC_V1DOTPUS, 0x1, 3, TREG_ZERO, 1,
794 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
795 },
796 { "v1dotpusa", TILEGX_OPC_V1DOTPUSA, 0x1, 3, TREG_ZERO, 1,
797 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
798 },
799 { "v1int_h", TILEGX_OPC_V1INT_H, 0x3, 3, TREG_ZERO, 1,
800 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
801 },
802 { "v1int_l", TILEGX_OPC_V1INT_L, 0x3, 3, TREG_ZERO, 1,
803 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
804 },
805 { "v1maxu", TILEGX_OPC_V1MAXU, 0x3, 3, TREG_ZERO, 1,
806 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
807 },
808 { "v1maxui", TILEGX_OPC_V1MAXUI, 0x3, 3, TREG_ZERO, 1,
809 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
810 },
811 { "v1minu", TILEGX_OPC_V1MINU, 0x3, 3, TREG_ZERO, 1,
812 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
813 },
814 { "v1minui", TILEGX_OPC_V1MINUI, 0x3, 3, TREG_ZERO, 1,
815 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
816 },
817 { "v1mnz", TILEGX_OPC_V1MNZ, 0x3, 3, TREG_ZERO, 1,
818 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
819 },
820 { "v1multu", TILEGX_OPC_V1MULTU, 0x1, 3, TREG_ZERO, 1,
821 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
822 },
823 { "v1mulu", TILEGX_OPC_V1MULU, 0x1, 3, TREG_ZERO, 1,
824 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
825 },
826 { "v1mulus", TILEGX_OPC_V1MULUS, 0x1, 3, TREG_ZERO, 1,
827 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
828 },
829 { "v1mz", TILEGX_OPC_V1MZ, 0x3, 3, TREG_ZERO, 1,
830 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
831 },
832 { "v1sadau", TILEGX_OPC_V1SADAU, 0x1, 3, TREG_ZERO, 1,
833 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
834 },
835 { "v1sadu", TILEGX_OPC_V1SADU, 0x1, 3, TREG_ZERO, 1,
836 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
837 },
838 { "v1shl", TILEGX_OPC_V1SHL, 0x3, 3, TREG_ZERO, 1,
839 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
840 },
841 { "v1shli", TILEGX_OPC_V1SHLI, 0x3, 3, TREG_ZERO, 1,
842 { { 6, 7, 29 }, { 8, 9, 30 }, { 0, }, { 0, }, { 0, } },
843 },
844 { "v1shrs", TILEGX_OPC_V1SHRS, 0x3, 3, TREG_ZERO, 1,
845 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
846 },
847 { "v1shrsi", TILEGX_OPC_V1SHRSI, 0x3, 3, TREG_ZERO, 1,
848 { { 6, 7, 29 }, { 8, 9, 30 }, { 0, }, { 0, }, { 0, } },
849 },
850 { "v1shru", TILEGX_OPC_V1SHRU, 0x3, 3, TREG_ZERO, 1,
851 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
852 },
853 { "v1shrui", TILEGX_OPC_V1SHRUI, 0x3, 3, TREG_ZERO, 1,
854 { { 6, 7, 29 }, { 8, 9, 30 }, { 0, }, { 0, }, { 0, } },
855 },
856 { "v1sub", TILEGX_OPC_V1SUB, 0x3, 3, TREG_ZERO, 1,
857 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
858 },
859 { "v1subuc", TILEGX_OPC_V1SUBUC, 0x3, 3, TREG_ZERO, 1,
860 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
861 },
862 { "v2add", TILEGX_OPC_V2ADD, 0x3, 3, TREG_ZERO, 1,
863 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
864 },
865 { "v2addi", TILEGX_OPC_V2ADDI, 0x3, 3, TREG_ZERO, 1,
866 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
867 },
868 { "v2addsc", TILEGX_OPC_V2ADDSC, 0x3, 3, TREG_ZERO, 1,
869 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
870 },
871 { "v2adiffs", TILEGX_OPC_V2ADIFFS, 0x1, 3, TREG_ZERO, 1,
872 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
873 },
874 { "v2avgs", TILEGX_OPC_V2AVGS, 0x1, 3, TREG_ZERO, 1,
875 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
876 },
877 { "v2cmpeq", TILEGX_OPC_V2CMPEQ, 0x3, 3, TREG_ZERO, 1,
878 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
879 },
880 { "v2cmpeqi", TILEGX_OPC_V2CMPEQI, 0x3, 3, TREG_ZERO, 1,
881 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
882 },
883 { "v2cmples", TILEGX_OPC_V2CMPLES, 0x3, 3, TREG_ZERO, 1,
884 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
885 },
886 { "v2cmpleu", TILEGX_OPC_V2CMPLEU, 0x3, 3, TREG_ZERO, 1,
887 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
888 },
889 { "v2cmplts", TILEGX_OPC_V2CMPLTS, 0x3, 3, TREG_ZERO, 1,
890 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
891 },
892 { "v2cmpltsi", TILEGX_OPC_V2CMPLTSI, 0x3, 3, TREG_ZERO, 1,
893 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
894 },
895 { "v2cmpltu", TILEGX_OPC_V2CMPLTU, 0x3, 3, TREG_ZERO, 1,
896 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
897 },
898 { "v2cmpltui", TILEGX_OPC_V2CMPLTUI, 0x3, 3, TREG_ZERO, 1,
899 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
900 },
901 { "v2cmpne", TILEGX_OPC_V2CMPNE, 0x3, 3, TREG_ZERO, 1,
902 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
903 },
904 { "v2dotp", TILEGX_OPC_V2DOTP, 0x1, 3, TREG_ZERO, 1,
905 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
906 },
907 { "v2dotpa", TILEGX_OPC_V2DOTPA, 0x1, 3, TREG_ZERO, 1,
908 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
909 },
910 { "v2int_h", TILEGX_OPC_V2INT_H, 0x3, 3, TREG_ZERO, 1,
911 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
912 },
913 { "v2int_l", TILEGX_OPC_V2INT_L, 0x3, 3, TREG_ZERO, 1,
914 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
915 },
916 { "v2maxs", TILEGX_OPC_V2MAXS, 0x3, 3, TREG_ZERO, 1,
917 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
918 },
919 { "v2maxsi", TILEGX_OPC_V2MAXSI, 0x3, 3, TREG_ZERO, 1,
920 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
921 },
922 { "v2mins", TILEGX_OPC_V2MINS, 0x3, 3, TREG_ZERO, 1,
923 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
924 },
925 { "v2minsi", TILEGX_OPC_V2MINSI, 0x3, 3, TREG_ZERO, 1,
926 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
927 },
928 { "v2mnz", TILEGX_OPC_V2MNZ, 0x3, 3, TREG_ZERO, 1,
929 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
930 },
931 { "v2mulfsc", TILEGX_OPC_V2MULFSC, 0x1, 3, TREG_ZERO, 1,
932 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
933 },
934 { "v2muls", TILEGX_OPC_V2MULS, 0x1, 3, TREG_ZERO, 1,
935 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
936 },
937 { "v2mults", TILEGX_OPC_V2MULTS, 0x1, 3, TREG_ZERO, 1,
938 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
939 },
940 { "v2mz", TILEGX_OPC_V2MZ, 0x3, 3, TREG_ZERO, 1,
941 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
942 },
943 { "v2packh", TILEGX_OPC_V2PACKH, 0x3, 3, TREG_ZERO, 1,
944 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
945 },
946 { "v2packl", TILEGX_OPC_V2PACKL, 0x3, 3, TREG_ZERO, 1,
947 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
948 },
949 { "v2packuc", TILEGX_OPC_V2PACKUC, 0x3, 3, TREG_ZERO, 1,
950 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
951 },
952 { "v2sadas", TILEGX_OPC_V2SADAS, 0x1, 3, TREG_ZERO, 1,
953 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
954 },
955 { "v2sadau", TILEGX_OPC_V2SADAU, 0x1, 3, TREG_ZERO, 1,
956 { { 23, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
957 },
958 { "v2sads", TILEGX_OPC_V2SADS, 0x1, 3, TREG_ZERO, 1,
959 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
960 },
961 { "v2sadu", TILEGX_OPC_V2SADU, 0x1, 3, TREG_ZERO, 1,
962 { { 6, 7, 16 }, { 0, }, { 0, }, { 0, }, { 0, } },
963 },
964 { "v2shl", TILEGX_OPC_V2SHL, 0x3, 3, TREG_ZERO, 1,
965 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
966 },
967 { "v2shli", TILEGX_OPC_V2SHLI, 0x3, 3, TREG_ZERO, 1,
968 { { 6, 7, 29 }, { 8, 9, 30 }, { 0, }, { 0, }, { 0, } },
969 },
970 { "v2shlsc", TILEGX_OPC_V2SHLSC, 0x3, 3, TREG_ZERO, 1,
971 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
972 },
973 { "v2shrs", TILEGX_OPC_V2SHRS, 0x3, 3, TREG_ZERO, 1,
974 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
975 },
976 { "v2shrsi", TILEGX_OPC_V2SHRSI, 0x3, 3, TREG_ZERO, 1,
977 { { 6, 7, 29 }, { 8, 9, 30 }, { 0, }, { 0, }, { 0, } },
978 },
979 { "v2shru", TILEGX_OPC_V2SHRU, 0x3, 3, TREG_ZERO, 1,
980 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
981 },
982 { "v2shrui", TILEGX_OPC_V2SHRUI, 0x3, 3, TREG_ZERO, 1,
983 { { 6, 7, 29 }, { 8, 9, 30 }, { 0, }, { 0, }, { 0, } },
984 },
985 { "v2sub", TILEGX_OPC_V2SUB, 0x3, 3, TREG_ZERO, 1,
986 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
987 },
988 { "v2subsc", TILEGX_OPC_V2SUBSC, 0x3, 3, TREG_ZERO, 1,
989 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
990 },
991 { "v4add", TILEGX_OPC_V4ADD, 0x3, 3, TREG_ZERO, 1,
992 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
993 },
994 { "v4addsc", TILEGX_OPC_V4ADDSC, 0x3, 3, TREG_ZERO, 1,
995 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
996 },
997 { "v4int_h", TILEGX_OPC_V4INT_H, 0x3, 3, TREG_ZERO, 1,
998 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
999 },
1000 { "v4int_l", TILEGX_OPC_V4INT_L, 0x3, 3, TREG_ZERO, 1,
1001 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
1002 },
1003 { "v4packsc", TILEGX_OPC_V4PACKSC, 0x3, 3, TREG_ZERO, 1,
1004 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
1005 },
1006 { "v4shl", TILEGX_OPC_V4SHL, 0x3, 3, TREG_ZERO, 1,
1007 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
1008 },
1009 { "v4shlsc", TILEGX_OPC_V4SHLSC, 0x3, 3, TREG_ZERO, 1,
1010 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
1011 },
1012 { "v4shrs", TILEGX_OPC_V4SHRS, 0x3, 3, TREG_ZERO, 1,
1013 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
1014 },
1015 { "v4shru", TILEGX_OPC_V4SHRU, 0x3, 3, TREG_ZERO, 1,
1016 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
1017 },
1018 { "v4sub", TILEGX_OPC_V4SUB, 0x3, 3, TREG_ZERO, 1,
1019 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
1020 },
1021 { "v4subsc", TILEGX_OPC_V4SUBSC, 0x3, 3, TREG_ZERO, 1,
1022 { { 6, 7, 16 }, { 8, 9, 17 }, { 0, }, { 0, }, { 0, } },
1023 },
1024 { "wh64", TILEGX_OPC_WH64, 0x2, 1, TREG_ZERO, 1,
1025 { { 0, }, { 9 }, { 0, }, { 0, }, { 0, } },
1026 },
1027 { "xor", TILEGX_OPC_XOR, 0xf, 3, TREG_ZERO, 1,
1028 { { 6, 7, 16 }, { 8, 9, 17 }, { 10, 11, 18 }, { 12, 13, 19 }, { 0, } },
1029 },
1030 { "xori", TILEGX_OPC_XORI, 0x3, 3, TREG_ZERO, 1,
1031 { { 6, 7, 0 }, { 8, 9, 1 }, { 0, }, { 0, }, { 0, } },
1032 },
1033 { NULL, TILEGX_OPC_NONE, 0, 0, TREG_ZERO, 0, { { 0, } },
1034 }
1035};
1036#define BITFIELD(start, size) ((start) | (((1 << (size)) - 1) << 6))
1037#define CHILD(array_index) (TILEGX_OPC_NONE + (array_index))
1038
1039static const unsigned short decode_X0_fsm[936] =
1040{
1041 BITFIELD(22, 9) /* index 0 */,
1042 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1043 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1044 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1045 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1046 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1047 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1048 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1049 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1050 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1051 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1052 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1053 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1054 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1055 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1056 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1057 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1058 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1059 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1060 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1061 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1062 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1063 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1064 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1065 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1066 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1067 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1068 CHILD(513), CHILD(513), CHILD(513), CHILD(513), TILEGX_OPC_ADDXLI,
1069 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1070 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1071 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1072 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1073 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1074 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1075 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1076 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1077 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1078 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1079 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1080 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1081 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1082 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1083 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1084 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_NONE,
1085 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1086 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1087 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1088 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_BFEXTS,
1089 TILEGX_OPC_BFEXTS, TILEGX_OPC_BFEXTS, TILEGX_OPC_BFEXTS, TILEGX_OPC_BFEXTU,
1090 TILEGX_OPC_BFEXTU, TILEGX_OPC_BFEXTU, TILEGX_OPC_BFEXTU, TILEGX_OPC_BFINS,
1091 TILEGX_OPC_BFINS, TILEGX_OPC_BFINS, TILEGX_OPC_BFINS, TILEGX_OPC_MM,
1092 TILEGX_OPC_MM, TILEGX_OPC_MM, TILEGX_OPC_MM, TILEGX_OPC_NONE,
1093 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1094 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1095 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1096 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1097 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1098 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1099 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1100 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, CHILD(528), CHILD(578),
1101 CHILD(583), CHILD(588), CHILD(593), CHILD(598), TILEGX_OPC_NONE,
1102 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1103 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1104 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1105 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1106 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1107 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1108 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1109 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1110 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1111 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1112 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1113 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1114 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1115 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1116 TILEGX_OPC_NONE, CHILD(603), CHILD(620), CHILD(637), CHILD(654), CHILD(671),
1117 CHILD(703), CHILD(797), CHILD(814), CHILD(831), CHILD(848), CHILD(865),
1118 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1119 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1120 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1121 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1122 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1123 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1124 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1125 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1126 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1127 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1128 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1129 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1130 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1131 TILEGX_OPC_NONE, CHILD(889), TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1132 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1133 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1134 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1135 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1136 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1137 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1138 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1139 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1140 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1141 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1142 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1143 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1144 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1145 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1146 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1147 TILEGX_OPC_NONE, CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1148 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1149 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1150 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1151 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1152 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1153 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1154 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1155 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1156 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1157 CHILD(906), CHILD(906), CHILD(906), CHILD(906), CHILD(906),
1158 BITFIELD(6, 2) /* index 513 */,
1159 TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, CHILD(518),
1160 BITFIELD(8, 2) /* index 518 */,
1161 TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, CHILD(523),
1162 BITFIELD(10, 2) /* index 523 */,
1163 TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, TILEGX_OPC_MOVELI,
1164 BITFIELD(20, 2) /* index 528 */,
1165 TILEGX_OPC_NONE, CHILD(533), TILEGX_OPC_ADDXI, CHILD(548),
1166 BITFIELD(6, 2) /* index 533 */,
1167 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, CHILD(538),
1168 BITFIELD(8, 2) /* index 538 */,
1169 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, CHILD(543),
1170 BITFIELD(10, 2) /* index 543 */,
1171 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_MOVEI,
1172 BITFIELD(0, 2) /* index 548 */,
1173 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(553),
1174 BITFIELD(2, 2) /* index 553 */,
1175 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(558),
1176 BITFIELD(4, 2) /* index 558 */,
1177 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(563),
1178 BITFIELD(6, 2) /* index 563 */,
1179 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(568),
1180 BITFIELD(8, 2) /* index 568 */,
1181 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(573),
1182 BITFIELD(10, 2) /* index 573 */,
1183 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_INFO,
1184 BITFIELD(20, 2) /* index 578 */,
1185 TILEGX_OPC_CMPEQI, TILEGX_OPC_CMPLTSI, TILEGX_OPC_CMPLTUI, TILEGX_OPC_ORI,
1186 BITFIELD(20, 2) /* index 583 */,
1187 TILEGX_OPC_V1ADDI, TILEGX_OPC_V1CMPEQI, TILEGX_OPC_V1CMPLTSI,
1188 TILEGX_OPC_V1CMPLTUI,
1189 BITFIELD(20, 2) /* index 588 */,
1190 TILEGX_OPC_V1MAXUI, TILEGX_OPC_V1MINUI, TILEGX_OPC_V2ADDI,
1191 TILEGX_OPC_V2CMPEQI,
1192 BITFIELD(20, 2) /* index 593 */,
1193 TILEGX_OPC_V2CMPLTSI, TILEGX_OPC_V2CMPLTUI, TILEGX_OPC_V2MAXSI,
1194 TILEGX_OPC_V2MINSI,
1195 BITFIELD(20, 2) /* index 598 */,
1196 TILEGX_OPC_XORI, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1197 BITFIELD(18, 4) /* index 603 */,
1198 TILEGX_OPC_NONE, TILEGX_OPC_ADDXSC, TILEGX_OPC_ADDX, TILEGX_OPC_ADD,
1199 TILEGX_OPC_AND, TILEGX_OPC_CMOVEQZ, TILEGX_OPC_CMOVNEZ, TILEGX_OPC_CMPEQ,
1200 TILEGX_OPC_CMPLES, TILEGX_OPC_CMPLEU, TILEGX_OPC_CMPLTS, TILEGX_OPC_CMPLTU,
1201 TILEGX_OPC_CMPNE, TILEGX_OPC_CMULAF, TILEGX_OPC_CMULA, TILEGX_OPC_CMULFR,
1202 BITFIELD(18, 4) /* index 620 */,
1203 TILEGX_OPC_CMULF, TILEGX_OPC_CMULHR, TILEGX_OPC_CMULH, TILEGX_OPC_CMUL,
1204 TILEGX_OPC_CRC32_32, TILEGX_OPC_CRC32_8, TILEGX_OPC_DBLALIGN2,
1205 TILEGX_OPC_DBLALIGN4, TILEGX_OPC_DBLALIGN6, TILEGX_OPC_DBLALIGN,
1206 TILEGX_OPC_FDOUBLE_ADDSUB, TILEGX_OPC_FDOUBLE_ADD_FLAGS,
1207 TILEGX_OPC_FDOUBLE_MUL_FLAGS, TILEGX_OPC_FDOUBLE_PACK1,
1208 TILEGX_OPC_FDOUBLE_PACK2, TILEGX_OPC_FDOUBLE_SUB_FLAGS,
1209 BITFIELD(18, 4) /* index 637 */,
1210 TILEGX_OPC_FDOUBLE_UNPACK_MAX, TILEGX_OPC_FDOUBLE_UNPACK_MIN,
1211 TILEGX_OPC_FSINGLE_ADD1, TILEGX_OPC_FSINGLE_ADDSUB2,
1212 TILEGX_OPC_FSINGLE_MUL1, TILEGX_OPC_FSINGLE_MUL2, TILEGX_OPC_FSINGLE_PACK2,
1213 TILEGX_OPC_FSINGLE_SUB1, TILEGX_OPC_MNZ, TILEGX_OPC_MULAX,
1214 TILEGX_OPC_MULA_HS_HS, TILEGX_OPC_MULA_HS_HU, TILEGX_OPC_MULA_HS_LS,
1215 TILEGX_OPC_MULA_HS_LU, TILEGX_OPC_MULA_HU_HU, TILEGX_OPC_MULA_HU_LS,
1216 BITFIELD(18, 4) /* index 654 */,
1217 TILEGX_OPC_MULA_HU_LU, TILEGX_OPC_MULA_LS_LS, TILEGX_OPC_MULA_LS_LU,
1218 TILEGX_OPC_MULA_LU_LU, TILEGX_OPC_MULX, TILEGX_OPC_MUL_HS_HS,
1219 TILEGX_OPC_MUL_HS_HU, TILEGX_OPC_MUL_HS_LS, TILEGX_OPC_MUL_HS_LU,
1220 TILEGX_OPC_MUL_HU_HU, TILEGX_OPC_MUL_HU_LS, TILEGX_OPC_MUL_HU_LU,
1221 TILEGX_OPC_MUL_LS_LS, TILEGX_OPC_MUL_LS_LU, TILEGX_OPC_MUL_LU_LU,
1222 TILEGX_OPC_MZ,
1223 BITFIELD(18, 4) /* index 671 */,
1224 TILEGX_OPC_NOR, CHILD(688), TILEGX_OPC_ROTL, TILEGX_OPC_SHL1ADDX,
1225 TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL2ADDX, TILEGX_OPC_SHL2ADD,
1226 TILEGX_OPC_SHL3ADDX, TILEGX_OPC_SHL3ADD, TILEGX_OPC_SHLX, TILEGX_OPC_SHL,
1227 TILEGX_OPC_SHRS, TILEGX_OPC_SHRUX, TILEGX_OPC_SHRU, TILEGX_OPC_SHUFFLEBYTES,
1228 TILEGX_OPC_SUBXSC,
1229 BITFIELD(12, 2) /* index 688 */,
1230 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, CHILD(693),
1231 BITFIELD(14, 2) /* index 693 */,
1232 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, CHILD(698),
1233 BITFIELD(16, 2) /* index 698 */,
1234 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_MOVE,
1235 BITFIELD(18, 4) /* index 703 */,
1236 TILEGX_OPC_SUBX, TILEGX_OPC_SUB, CHILD(720), TILEGX_OPC_V1ADDUC,
1237 TILEGX_OPC_V1ADD, TILEGX_OPC_V1ADIFFU, TILEGX_OPC_V1AVGU,
1238 TILEGX_OPC_V1CMPEQ, TILEGX_OPC_V1CMPLES, TILEGX_OPC_V1CMPLEU,
1239 TILEGX_OPC_V1CMPLTS, TILEGX_OPC_V1CMPLTU, TILEGX_OPC_V1CMPNE,
1240 TILEGX_OPC_V1DDOTPUSA, TILEGX_OPC_V1DDOTPUS, TILEGX_OPC_V1DOTPA,
1241 BITFIELD(12, 4) /* index 720 */,
1242 TILEGX_OPC_NONE, CHILD(737), CHILD(742), CHILD(747), CHILD(752), CHILD(757),
1243 CHILD(762), CHILD(767), CHILD(772), CHILD(777), CHILD(782), CHILD(787),
1244 CHILD(792), TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1245 BITFIELD(16, 2) /* index 737 */,
1246 TILEGX_OPC_CLZ, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1247 BITFIELD(16, 2) /* index 742 */,
1248 TILEGX_OPC_CTZ, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1249 BITFIELD(16, 2) /* index 747 */,
1250 TILEGX_OPC_FNOP, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1251 BITFIELD(16, 2) /* index 752 */,
1252 TILEGX_OPC_FSINGLE_PACK1, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1253 BITFIELD(16, 2) /* index 757 */,
1254 TILEGX_OPC_NOP, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1255 BITFIELD(16, 2) /* index 762 */,
1256 TILEGX_OPC_PCNT, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1257 BITFIELD(16, 2) /* index 767 */,
1258 TILEGX_OPC_REVBITS, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1259 BITFIELD(16, 2) /* index 772 */,
1260 TILEGX_OPC_REVBYTES, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1261 BITFIELD(16, 2) /* index 777 */,
1262 TILEGX_OPC_TBLIDXB0, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1263 BITFIELD(16, 2) /* index 782 */,
1264 TILEGX_OPC_TBLIDXB1, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1265 BITFIELD(16, 2) /* index 787 */,
1266 TILEGX_OPC_TBLIDXB2, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1267 BITFIELD(16, 2) /* index 792 */,
1268 TILEGX_OPC_TBLIDXB3, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1269 BITFIELD(18, 4) /* index 797 */,
1270 TILEGX_OPC_V1DOTPUSA, TILEGX_OPC_V1DOTPUS, TILEGX_OPC_V1DOTP,
1271 TILEGX_OPC_V1INT_H, TILEGX_OPC_V1INT_L, TILEGX_OPC_V1MAXU,
1272 TILEGX_OPC_V1MINU, TILEGX_OPC_V1MNZ, TILEGX_OPC_V1MULTU, TILEGX_OPC_V1MULUS,
1273 TILEGX_OPC_V1MULU, TILEGX_OPC_V1MZ, TILEGX_OPC_V1SADAU, TILEGX_OPC_V1SADU,
1274 TILEGX_OPC_V1SHL, TILEGX_OPC_V1SHRS,
1275 BITFIELD(18, 4) /* index 814 */,
1276 TILEGX_OPC_V1SHRU, TILEGX_OPC_V1SUBUC, TILEGX_OPC_V1SUB, TILEGX_OPC_V2ADDSC,
1277 TILEGX_OPC_V2ADD, TILEGX_OPC_V2ADIFFS, TILEGX_OPC_V2AVGS,
1278 TILEGX_OPC_V2CMPEQ, TILEGX_OPC_V2CMPLES, TILEGX_OPC_V2CMPLEU,
1279 TILEGX_OPC_V2CMPLTS, TILEGX_OPC_V2CMPLTU, TILEGX_OPC_V2CMPNE,
1280 TILEGX_OPC_V2DOTPA, TILEGX_OPC_V2DOTP, TILEGX_OPC_V2INT_H,
1281 BITFIELD(18, 4) /* index 831 */,
1282 TILEGX_OPC_V2INT_L, TILEGX_OPC_V2MAXS, TILEGX_OPC_V2MINS, TILEGX_OPC_V2MNZ,
1283 TILEGX_OPC_V2MULFSC, TILEGX_OPC_V2MULS, TILEGX_OPC_V2MULTS, TILEGX_OPC_V2MZ,
1284 TILEGX_OPC_V2PACKH, TILEGX_OPC_V2PACKL, TILEGX_OPC_V2PACKUC,
1285 TILEGX_OPC_V2SADAS, TILEGX_OPC_V2SADAU, TILEGX_OPC_V2SADS,
1286 TILEGX_OPC_V2SADU, TILEGX_OPC_V2SHLSC,
1287 BITFIELD(18, 4) /* index 848 */,
1288 TILEGX_OPC_V2SHL, TILEGX_OPC_V2SHRS, TILEGX_OPC_V2SHRU, TILEGX_OPC_V2SUBSC,
1289 TILEGX_OPC_V2SUB, TILEGX_OPC_V4ADDSC, TILEGX_OPC_V4ADD, TILEGX_OPC_V4INT_H,
1290 TILEGX_OPC_V4INT_L, TILEGX_OPC_V4PACKSC, TILEGX_OPC_V4SHLSC,
1291 TILEGX_OPC_V4SHL, TILEGX_OPC_V4SHRS, TILEGX_OPC_V4SHRU, TILEGX_OPC_V4SUBSC,
1292 TILEGX_OPC_V4SUB,
1293 BITFIELD(18, 3) /* index 865 */,
1294 CHILD(874), CHILD(877), CHILD(880), CHILD(883), CHILD(886), TILEGX_OPC_NONE,
1295 TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1296 BITFIELD(21, 1) /* index 874 */,
1297 TILEGX_OPC_XOR, TILEGX_OPC_NONE,
1298 BITFIELD(21, 1) /* index 877 */,
1299 TILEGX_OPC_V1DDOTPUA, TILEGX_OPC_NONE,
1300 BITFIELD(21, 1) /* index 880 */,
1301 TILEGX_OPC_V1DDOTPU, TILEGX_OPC_NONE,
1302 BITFIELD(21, 1) /* index 883 */,
1303 TILEGX_OPC_V1DOTPUA, TILEGX_OPC_NONE,
1304 BITFIELD(21, 1) /* index 886 */,
1305 TILEGX_OPC_V1DOTPU, TILEGX_OPC_NONE,
1306 BITFIELD(18, 4) /* index 889 */,
1307 TILEGX_OPC_NONE, TILEGX_OPC_ROTLI, TILEGX_OPC_SHLI, TILEGX_OPC_SHLXI,
1308 TILEGX_OPC_SHRSI, TILEGX_OPC_SHRUI, TILEGX_OPC_SHRUXI, TILEGX_OPC_V1SHLI,
1309 TILEGX_OPC_V1SHRSI, TILEGX_OPC_V1SHRUI, TILEGX_OPC_V2SHLI,
1310 TILEGX_OPC_V2SHRSI, TILEGX_OPC_V2SHRUI, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1311 TILEGX_OPC_NONE,
1312 BITFIELD(0, 2) /* index 906 */,
1313 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1314 CHILD(911),
1315 BITFIELD(2, 2) /* index 911 */,
1316 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1317 CHILD(916),
1318 BITFIELD(4, 2) /* index 916 */,
1319 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1320 CHILD(921),
1321 BITFIELD(6, 2) /* index 921 */,
1322 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1323 CHILD(926),
1324 BITFIELD(8, 2) /* index 926 */,
1325 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1326 CHILD(931),
1327 BITFIELD(10, 2) /* index 931 */,
1328 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1329 TILEGX_OPC_INFOL,
1330};
1331
1332static const unsigned short decode_X1_fsm[1206] =
1333{
1334 BITFIELD(53, 9) /* index 0 */,
1335 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1336 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1337 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1338 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1339 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1340 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1341 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1342 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1343 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1344 CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513), CHILD(513),
1345 CHILD(513), CHILD(513), CHILD(513), CHILD(513), TILEGX_OPC_ADDXLI,
1346 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1347 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1348 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1349 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1350 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1351 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1352 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1353 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1354 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1355 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1356 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1357 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1358 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1359 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1360 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI,
1361 TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_ADDXLI, TILEGX_OPC_NONE,
1362 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1363 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1364 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1365 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1366 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1367 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1368 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1369 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_BEQZT,
1370 TILEGX_OPC_BEQZT, TILEGX_OPC_BEQZ, TILEGX_OPC_BEQZ, TILEGX_OPC_BGEZT,
1371 TILEGX_OPC_BGEZT, TILEGX_OPC_BGEZ, TILEGX_OPC_BGEZ, TILEGX_OPC_BGTZT,
1372 TILEGX_OPC_BGTZT, TILEGX_OPC_BGTZ, TILEGX_OPC_BGTZ, TILEGX_OPC_BLBCT,
1373 TILEGX_OPC_BLBCT, TILEGX_OPC_BLBC, TILEGX_OPC_BLBC, TILEGX_OPC_BLBST,
1374 TILEGX_OPC_BLBST, TILEGX_OPC_BLBS, TILEGX_OPC_BLBS, TILEGX_OPC_BLEZT,
1375 TILEGX_OPC_BLEZT, TILEGX_OPC_BLEZ, TILEGX_OPC_BLEZ, TILEGX_OPC_BLTZT,
1376 TILEGX_OPC_BLTZT, TILEGX_OPC_BLTZ, TILEGX_OPC_BLTZ, TILEGX_OPC_BNEZT,
1377 TILEGX_OPC_BNEZT, TILEGX_OPC_BNEZ, TILEGX_OPC_BNEZ, CHILD(528), CHILD(578),
1378 CHILD(598), CHILD(663), CHILD(683), CHILD(688), CHILD(693), CHILD(698),
1379 CHILD(703), CHILD(708), CHILD(713), CHILD(718), TILEGX_OPC_NONE,
1380 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1381 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1382 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1383 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1384 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1385 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1386 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1387 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1388 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1389 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1390 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1391 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1392 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_JAL,
1393 TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL,
1394 TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL,
1395 TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL,
1396 TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL,
1397 TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL,
1398 TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL,
1399 TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL,
1400 TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_JAL, TILEGX_OPC_J, TILEGX_OPC_J,
1401 TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J,
1402 TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J,
1403 TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J,
1404 TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J,
1405 TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J,
1406 TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J, TILEGX_OPC_J,
1407 CHILD(723), CHILD(740), CHILD(772), CHILD(789), CHILD(1108), CHILD(1125),
1408 CHILD(1142), TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1409 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1410 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1411 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1412 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1413 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1414 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1415 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1416 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1417 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1418 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1419 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1420 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1421 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1422 TILEGX_OPC_NONE, TILEGX_OPC_NONE, CHILD(1159), TILEGX_OPC_NONE,
1423 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1424 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1425 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1426 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1427 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1428 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1429 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1430 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1431 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1432 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1433 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1434 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1435 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1436 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1437 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1438 TILEGX_OPC_NONE, TILEGX_OPC_NONE, CHILD(1176), CHILD(1176), CHILD(1176),
1439 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1440 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1441 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1442 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1443 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1444 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1445 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1446 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1447 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1448 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1449 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1450 CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176), CHILD(1176),
1451 CHILD(1176),
1452 BITFIELD(37, 2) /* index 513 */,
1453 TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, CHILD(518),
1454 BITFIELD(39, 2) /* index 518 */,
1455 TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, CHILD(523),
1456 BITFIELD(41, 2) /* index 523 */,
1457 TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, TILEGX_OPC_ADDLI, TILEGX_OPC_MOVELI,
1458 BITFIELD(51, 2) /* index 528 */,
1459 TILEGX_OPC_NONE, CHILD(533), TILEGX_OPC_ADDXI, CHILD(548),
1460 BITFIELD(37, 2) /* index 533 */,
1461 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, CHILD(538),
1462 BITFIELD(39, 2) /* index 538 */,
1463 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, CHILD(543),
1464 BITFIELD(41, 2) /* index 543 */,
1465 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_MOVEI,
1466 BITFIELD(31, 2) /* index 548 */,
1467 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(553),
1468 BITFIELD(33, 2) /* index 553 */,
1469 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(558),
1470 BITFIELD(35, 2) /* index 558 */,
1471 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(563),
1472 BITFIELD(37, 2) /* index 563 */,
1473 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(568),
1474 BITFIELD(39, 2) /* index 568 */,
1475 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(573),
1476 BITFIELD(41, 2) /* index 573 */,
1477 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_INFO,
1478 BITFIELD(51, 2) /* index 578 */,
1479 TILEGX_OPC_CMPEQI, TILEGX_OPC_CMPLTSI, TILEGX_OPC_CMPLTUI, CHILD(583),
1480 BITFIELD(31, 2) /* index 583 */,
1481 TILEGX_OPC_LD1S_ADD, TILEGX_OPC_LD1S_ADD, TILEGX_OPC_LD1S_ADD, CHILD(588),
1482 BITFIELD(33, 2) /* index 588 */,
1483 TILEGX_OPC_LD1S_ADD, TILEGX_OPC_LD1S_ADD, TILEGX_OPC_LD1S_ADD, CHILD(593),
1484 BITFIELD(35, 2) /* index 593 */,
1485 TILEGX_OPC_LD1S_ADD, TILEGX_OPC_LD1S_ADD, TILEGX_OPC_LD1S_ADD,
1486 TILEGX_OPC_PREFETCH_ADD_L1_FAULT,
1487 BITFIELD(51, 2) /* index 598 */,
1488 CHILD(603), CHILD(618), CHILD(633), CHILD(648),
1489 BITFIELD(31, 2) /* index 603 */,
1490 TILEGX_OPC_LD1U_ADD, TILEGX_OPC_LD1U_ADD, TILEGX_OPC_LD1U_ADD, CHILD(608),
1491 BITFIELD(33, 2) /* index 608 */,
1492 TILEGX_OPC_LD1U_ADD, TILEGX_OPC_LD1U_ADD, TILEGX_OPC_LD1U_ADD, CHILD(613),
1493 BITFIELD(35, 2) /* index 613 */,
1494 TILEGX_OPC_LD1U_ADD, TILEGX_OPC_LD1U_ADD, TILEGX_OPC_LD1U_ADD,
1495 TILEGX_OPC_PREFETCH_ADD_L1,
1496 BITFIELD(31, 2) /* index 618 */,
1497 TILEGX_OPC_LD2S_ADD, TILEGX_OPC_LD2S_ADD, TILEGX_OPC_LD2S_ADD, CHILD(623),
1498 BITFIELD(33, 2) /* index 623 */,
1499 TILEGX_OPC_LD2S_ADD, TILEGX_OPC_LD2S_ADD, TILEGX_OPC_LD2S_ADD, CHILD(628),
1500 BITFIELD(35, 2) /* index 628 */,
1501 TILEGX_OPC_LD2S_ADD, TILEGX_OPC_LD2S_ADD, TILEGX_OPC_LD2S_ADD,
1502 TILEGX_OPC_PREFETCH_ADD_L2_FAULT,
1503 BITFIELD(31, 2) /* index 633 */,
1504 TILEGX_OPC_LD2U_ADD, TILEGX_OPC_LD2U_ADD, TILEGX_OPC_LD2U_ADD, CHILD(638),
1505 BITFIELD(33, 2) /* index 638 */,
1506 TILEGX_OPC_LD2U_ADD, TILEGX_OPC_LD2U_ADD, TILEGX_OPC_LD2U_ADD, CHILD(643),
1507 BITFIELD(35, 2) /* index 643 */,
1508 TILEGX_OPC_LD2U_ADD, TILEGX_OPC_LD2U_ADD, TILEGX_OPC_LD2U_ADD,
1509 TILEGX_OPC_PREFETCH_ADD_L2,
1510 BITFIELD(31, 2) /* index 648 */,
1511 TILEGX_OPC_LD4S_ADD, TILEGX_OPC_LD4S_ADD, TILEGX_OPC_LD4S_ADD, CHILD(653),
1512 BITFIELD(33, 2) /* index 653 */,
1513 TILEGX_OPC_LD4S_ADD, TILEGX_OPC_LD4S_ADD, TILEGX_OPC_LD4S_ADD, CHILD(658),
1514 BITFIELD(35, 2) /* index 658 */,
1515 TILEGX_OPC_LD4S_ADD, TILEGX_OPC_LD4S_ADD, TILEGX_OPC_LD4S_ADD,
1516 TILEGX_OPC_PREFETCH_ADD_L3_FAULT,
1517 BITFIELD(51, 2) /* index 663 */,
1518 CHILD(668), TILEGX_OPC_LDNT1S_ADD, TILEGX_OPC_LDNT1U_ADD,
1519 TILEGX_OPC_LDNT2S_ADD,
1520 BITFIELD(31, 2) /* index 668 */,
1521 TILEGX_OPC_LD4U_ADD, TILEGX_OPC_LD4U_ADD, TILEGX_OPC_LD4U_ADD, CHILD(673),
1522 BITFIELD(33, 2) /* index 673 */,
1523 TILEGX_OPC_LD4U_ADD, TILEGX_OPC_LD4U_ADD, TILEGX_OPC_LD4U_ADD, CHILD(678),
1524 BITFIELD(35, 2) /* index 678 */,
1525 TILEGX_OPC_LD4U_ADD, TILEGX_OPC_LD4U_ADD, TILEGX_OPC_LD4U_ADD,
1526 TILEGX_OPC_PREFETCH_ADD_L3,
1527 BITFIELD(51, 2) /* index 683 */,
1528 TILEGX_OPC_LDNT2U_ADD, TILEGX_OPC_LDNT4S_ADD, TILEGX_OPC_LDNT4U_ADD,
1529 TILEGX_OPC_LDNT_ADD,
1530 BITFIELD(51, 2) /* index 688 */,
1531 TILEGX_OPC_LD_ADD, TILEGX_OPC_LDNA_ADD, TILEGX_OPC_MFSPR, TILEGX_OPC_MTSPR,
1532 BITFIELD(51, 2) /* index 693 */,
1533 TILEGX_OPC_ORI, TILEGX_OPC_ST1_ADD, TILEGX_OPC_ST2_ADD, TILEGX_OPC_ST4_ADD,
1534 BITFIELD(51, 2) /* index 698 */,
1535 TILEGX_OPC_STNT1_ADD, TILEGX_OPC_STNT2_ADD, TILEGX_OPC_STNT4_ADD,
1536 TILEGX_OPC_STNT_ADD,
1537 BITFIELD(51, 2) /* index 703 */,
1538 TILEGX_OPC_ST_ADD, TILEGX_OPC_V1ADDI, TILEGX_OPC_V1CMPEQI,
1539 TILEGX_OPC_V1CMPLTSI,
1540 BITFIELD(51, 2) /* index 708 */,
1541 TILEGX_OPC_V1CMPLTUI, TILEGX_OPC_V1MAXUI, TILEGX_OPC_V1MINUI,
1542 TILEGX_OPC_V2ADDI,
1543 BITFIELD(51, 2) /* index 713 */,
1544 TILEGX_OPC_V2CMPEQI, TILEGX_OPC_V2CMPLTSI, TILEGX_OPC_V2CMPLTUI,
1545 TILEGX_OPC_V2MAXSI,
1546 BITFIELD(51, 2) /* index 718 */,
1547 TILEGX_OPC_V2MINSI, TILEGX_OPC_XORI, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1548 BITFIELD(49, 4) /* index 723 */,
1549 TILEGX_OPC_NONE, TILEGX_OPC_ADDXSC, TILEGX_OPC_ADDX, TILEGX_OPC_ADD,
1550 TILEGX_OPC_AND, TILEGX_OPC_CMPEQ, TILEGX_OPC_CMPEXCH4, TILEGX_OPC_CMPEXCH,
1551 TILEGX_OPC_CMPLES, TILEGX_OPC_CMPLEU, TILEGX_OPC_CMPLTS, TILEGX_OPC_CMPLTU,
1552 TILEGX_OPC_CMPNE, TILEGX_OPC_DBLALIGN2, TILEGX_OPC_DBLALIGN4,
1553 TILEGX_OPC_DBLALIGN6,
1554 BITFIELD(49, 4) /* index 740 */,
1555 TILEGX_OPC_EXCH4, TILEGX_OPC_EXCH, TILEGX_OPC_FETCHADD4,
1556 TILEGX_OPC_FETCHADDGEZ4, TILEGX_OPC_FETCHADDGEZ, TILEGX_OPC_FETCHADD,
1557 TILEGX_OPC_FETCHAND4, TILEGX_OPC_FETCHAND, TILEGX_OPC_FETCHOR4,
1558 TILEGX_OPC_FETCHOR, TILEGX_OPC_MNZ, TILEGX_OPC_MZ, TILEGX_OPC_NOR,
1559 CHILD(757), TILEGX_OPC_ROTL, TILEGX_OPC_SHL1ADDX,
1560 BITFIELD(43, 2) /* index 757 */,
1561 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, CHILD(762),
1562 BITFIELD(45, 2) /* index 762 */,
1563 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, CHILD(767),
1564 BITFIELD(47, 2) /* index 767 */,
1565 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_MOVE,
1566 BITFIELD(49, 4) /* index 772 */,
1567 TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL2ADDX, TILEGX_OPC_SHL2ADD,
1568 TILEGX_OPC_SHL3ADDX, TILEGX_OPC_SHL3ADD, TILEGX_OPC_SHLX, TILEGX_OPC_SHL,
1569 TILEGX_OPC_SHRS, TILEGX_OPC_SHRUX, TILEGX_OPC_SHRU, TILEGX_OPC_ST1,
1570 TILEGX_OPC_ST2, TILEGX_OPC_ST4, TILEGX_OPC_STNT1, TILEGX_OPC_STNT2,
1571 TILEGX_OPC_STNT4,
1572 BITFIELD(46, 7) /* index 789 */,
1573 TILEGX_OPC_STNT, TILEGX_OPC_STNT, TILEGX_OPC_STNT, TILEGX_OPC_STNT,
1574 TILEGX_OPC_STNT, TILEGX_OPC_STNT, TILEGX_OPC_STNT, TILEGX_OPC_STNT,
1575 TILEGX_OPC_ST, TILEGX_OPC_ST, TILEGX_OPC_ST, TILEGX_OPC_ST, TILEGX_OPC_ST,
1576 TILEGX_OPC_ST, TILEGX_OPC_ST, TILEGX_OPC_ST, TILEGX_OPC_SUBXSC,
1577 TILEGX_OPC_SUBXSC, TILEGX_OPC_SUBXSC, TILEGX_OPC_SUBXSC, TILEGX_OPC_SUBXSC,
1578 TILEGX_OPC_SUBXSC, TILEGX_OPC_SUBXSC, TILEGX_OPC_SUBXSC, TILEGX_OPC_SUBX,
1579 TILEGX_OPC_SUBX, TILEGX_OPC_SUBX, TILEGX_OPC_SUBX, TILEGX_OPC_SUBX,
1580 TILEGX_OPC_SUBX, TILEGX_OPC_SUBX, TILEGX_OPC_SUBX, TILEGX_OPC_SUB,
1581 TILEGX_OPC_SUB, TILEGX_OPC_SUB, TILEGX_OPC_SUB, TILEGX_OPC_SUB,
1582 TILEGX_OPC_SUB, TILEGX_OPC_SUB, TILEGX_OPC_SUB, CHILD(918), CHILD(927),
1583 CHILD(1006), CHILD(1090), CHILD(1099), TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1584 TILEGX_OPC_NONE, TILEGX_OPC_V1ADDUC, TILEGX_OPC_V1ADDUC, TILEGX_OPC_V1ADDUC,
1585 TILEGX_OPC_V1ADDUC, TILEGX_OPC_V1ADDUC, TILEGX_OPC_V1ADDUC,
1586 TILEGX_OPC_V1ADDUC, TILEGX_OPC_V1ADDUC, TILEGX_OPC_V1ADD, TILEGX_OPC_V1ADD,
1587 TILEGX_OPC_V1ADD, TILEGX_OPC_V1ADD, TILEGX_OPC_V1ADD, TILEGX_OPC_V1ADD,
1588 TILEGX_OPC_V1ADD, TILEGX_OPC_V1ADD, TILEGX_OPC_V1CMPEQ, TILEGX_OPC_V1CMPEQ,
1589 TILEGX_OPC_V1CMPEQ, TILEGX_OPC_V1CMPEQ, TILEGX_OPC_V1CMPEQ,
1590 TILEGX_OPC_V1CMPEQ, TILEGX_OPC_V1CMPEQ, TILEGX_OPC_V1CMPEQ,
1591 TILEGX_OPC_V1CMPLES, TILEGX_OPC_V1CMPLES, TILEGX_OPC_V1CMPLES,
1592 TILEGX_OPC_V1CMPLES, TILEGX_OPC_V1CMPLES, TILEGX_OPC_V1CMPLES,
1593 TILEGX_OPC_V1CMPLES, TILEGX_OPC_V1CMPLES, TILEGX_OPC_V1CMPLEU,
1594 TILEGX_OPC_V1CMPLEU, TILEGX_OPC_V1CMPLEU, TILEGX_OPC_V1CMPLEU,
1595 TILEGX_OPC_V1CMPLEU, TILEGX_OPC_V1CMPLEU, TILEGX_OPC_V1CMPLEU,
1596 TILEGX_OPC_V1CMPLEU, TILEGX_OPC_V1CMPLTS, TILEGX_OPC_V1CMPLTS,
1597 TILEGX_OPC_V1CMPLTS, TILEGX_OPC_V1CMPLTS, TILEGX_OPC_V1CMPLTS,
1598 TILEGX_OPC_V1CMPLTS, TILEGX_OPC_V1CMPLTS, TILEGX_OPC_V1CMPLTS,
1599 TILEGX_OPC_V1CMPLTU, TILEGX_OPC_V1CMPLTU, TILEGX_OPC_V1CMPLTU,
1600 TILEGX_OPC_V1CMPLTU, TILEGX_OPC_V1CMPLTU, TILEGX_OPC_V1CMPLTU,
1601 TILEGX_OPC_V1CMPLTU, TILEGX_OPC_V1CMPLTU, TILEGX_OPC_V1CMPNE,
1602 TILEGX_OPC_V1CMPNE, TILEGX_OPC_V1CMPNE, TILEGX_OPC_V1CMPNE,
1603 TILEGX_OPC_V1CMPNE, TILEGX_OPC_V1CMPNE, TILEGX_OPC_V1CMPNE,
1604 TILEGX_OPC_V1CMPNE, TILEGX_OPC_V1INT_H, TILEGX_OPC_V1INT_H,
1605 TILEGX_OPC_V1INT_H, TILEGX_OPC_V1INT_H, TILEGX_OPC_V1INT_H,
1606 TILEGX_OPC_V1INT_H, TILEGX_OPC_V1INT_H, TILEGX_OPC_V1INT_H,
1607 TILEGX_OPC_V1INT_L, TILEGX_OPC_V1INT_L, TILEGX_OPC_V1INT_L,
1608 TILEGX_OPC_V1INT_L, TILEGX_OPC_V1INT_L, TILEGX_OPC_V1INT_L,
1609 TILEGX_OPC_V1INT_L, TILEGX_OPC_V1INT_L,
1610 BITFIELD(43, 3) /* index 918 */,
1611 TILEGX_OPC_NONE, TILEGX_OPC_DRAIN, TILEGX_OPC_DTLBPR, TILEGX_OPC_FINV,
1612 TILEGX_OPC_FLUSHWB, TILEGX_OPC_FLUSH, TILEGX_OPC_FNOP, TILEGX_OPC_ICOH,
1613 BITFIELD(43, 3) /* index 927 */,
1614 CHILD(936), TILEGX_OPC_INV, TILEGX_OPC_IRET, TILEGX_OPC_JALRP,
1615 TILEGX_OPC_JALR, TILEGX_OPC_JRP, TILEGX_OPC_JR, CHILD(991),
1616 BITFIELD(31, 2) /* index 936 */,
1617 CHILD(941), CHILD(966), TILEGX_OPC_ILL, TILEGX_OPC_ILL,
1618 BITFIELD(33, 2) /* index 941 */,
1619 TILEGX_OPC_ILL, TILEGX_OPC_ILL, TILEGX_OPC_ILL, CHILD(946),
1620 BITFIELD(35, 2) /* index 946 */,
1621 TILEGX_OPC_ILL, CHILD(951), TILEGX_OPC_ILL, TILEGX_OPC_ILL,
1622 BITFIELD(37, 2) /* index 951 */,
1623 TILEGX_OPC_ILL, CHILD(956), TILEGX_OPC_ILL, TILEGX_OPC_ILL,
1624 BITFIELD(39, 2) /* index 956 */,
1625 TILEGX_OPC_ILL, CHILD(961), TILEGX_OPC_ILL, TILEGX_OPC_ILL,
1626 BITFIELD(41, 2) /* index 961 */,
1627 TILEGX_OPC_ILL, TILEGX_OPC_ILL, TILEGX_OPC_BPT, TILEGX_OPC_ILL,
1628 BITFIELD(33, 2) /* index 966 */,
1629 TILEGX_OPC_ILL, TILEGX_OPC_ILL, TILEGX_OPC_ILL, CHILD(971),
1630 BITFIELD(35, 2) /* index 971 */,
1631 TILEGX_OPC_ILL, CHILD(976), TILEGX_OPC_ILL, TILEGX_OPC_ILL,
1632 BITFIELD(37, 2) /* index 976 */,
1633 TILEGX_OPC_ILL, CHILD(981), TILEGX_OPC_ILL, TILEGX_OPC_ILL,
1634 BITFIELD(39, 2) /* index 981 */,
1635 TILEGX_OPC_ILL, CHILD(986), TILEGX_OPC_ILL, TILEGX_OPC_ILL,
1636 BITFIELD(41, 2) /* index 986 */,
1637 TILEGX_OPC_ILL, TILEGX_OPC_ILL, TILEGX_OPC_RAISE, TILEGX_OPC_ILL,
1638 BITFIELD(31, 2) /* index 991 */,
1639 TILEGX_OPC_LD1S, TILEGX_OPC_LD1S, TILEGX_OPC_LD1S, CHILD(996),
1640 BITFIELD(33, 2) /* index 996 */,
1641 TILEGX_OPC_LD1S, TILEGX_OPC_LD1S, TILEGX_OPC_LD1S, CHILD(1001),
1642 BITFIELD(35, 2) /* index 1001 */,
1643 TILEGX_OPC_LD1S, TILEGX_OPC_LD1S, TILEGX_OPC_LD1S,
1644 TILEGX_OPC_PREFETCH_L1_FAULT,
1645 BITFIELD(43, 3) /* index 1006 */,
1646 CHILD(1015), CHILD(1030), CHILD(1045), CHILD(1060), CHILD(1075),
1647 TILEGX_OPC_LDNA, TILEGX_OPC_LDNT1S, TILEGX_OPC_LDNT1U,
1648 BITFIELD(31, 2) /* index 1015 */,
1649 TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, CHILD(1020),
1650 BITFIELD(33, 2) /* index 1020 */,
1651 TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, CHILD(1025),
1652 BITFIELD(35, 2) /* index 1025 */,
1653 TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, TILEGX_OPC_PREFETCH,
1654 BITFIELD(31, 2) /* index 1030 */,
1655 TILEGX_OPC_LD2S, TILEGX_OPC_LD2S, TILEGX_OPC_LD2S, CHILD(1035),
1656 BITFIELD(33, 2) /* index 1035 */,
1657 TILEGX_OPC_LD2S, TILEGX_OPC_LD2S, TILEGX_OPC_LD2S, CHILD(1040),
1658 BITFIELD(35, 2) /* index 1040 */,
1659 TILEGX_OPC_LD2S, TILEGX_OPC_LD2S, TILEGX_OPC_LD2S,
1660 TILEGX_OPC_PREFETCH_L2_FAULT,
1661 BITFIELD(31, 2) /* index 1045 */,
1662 TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, CHILD(1050),
1663 BITFIELD(33, 2) /* index 1050 */,
1664 TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, CHILD(1055),
1665 BITFIELD(35, 2) /* index 1055 */,
1666 TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, TILEGX_OPC_PREFETCH_L2,
1667 BITFIELD(31, 2) /* index 1060 */,
1668 TILEGX_OPC_LD4S, TILEGX_OPC_LD4S, TILEGX_OPC_LD4S, CHILD(1065),
1669 BITFIELD(33, 2) /* index 1065 */,
1670 TILEGX_OPC_LD4S, TILEGX_OPC_LD4S, TILEGX_OPC_LD4S, CHILD(1070),
1671 BITFIELD(35, 2) /* index 1070 */,
1672 TILEGX_OPC_LD4S, TILEGX_OPC_LD4S, TILEGX_OPC_LD4S,
1673 TILEGX_OPC_PREFETCH_L3_FAULT,
1674 BITFIELD(31, 2) /* index 1075 */,
1675 TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, CHILD(1080),
1676 BITFIELD(33, 2) /* index 1080 */,
1677 TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, CHILD(1085),
1678 BITFIELD(35, 2) /* index 1085 */,
1679 TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, TILEGX_OPC_PREFETCH_L3,
1680 BITFIELD(43, 3) /* index 1090 */,
1681 TILEGX_OPC_LDNT2S, TILEGX_OPC_LDNT2U, TILEGX_OPC_LDNT4S, TILEGX_OPC_LDNT4U,
1682 TILEGX_OPC_LDNT, TILEGX_OPC_LD, TILEGX_OPC_LNK, TILEGX_OPC_MF,
1683 BITFIELD(43, 3) /* index 1099 */,
1684 TILEGX_OPC_NAP, TILEGX_OPC_NOP, TILEGX_OPC_SWINT0, TILEGX_OPC_SWINT1,
1685 TILEGX_OPC_SWINT2, TILEGX_OPC_SWINT3, TILEGX_OPC_WH64, TILEGX_OPC_NONE,
1686 BITFIELD(49, 4) /* index 1108 */,
1687 TILEGX_OPC_V1MAXU, TILEGX_OPC_V1MINU, TILEGX_OPC_V1MNZ, TILEGX_OPC_V1MZ,
1688 TILEGX_OPC_V1SHL, TILEGX_OPC_V1SHRS, TILEGX_OPC_V1SHRU, TILEGX_OPC_V1SUBUC,
1689 TILEGX_OPC_V1SUB, TILEGX_OPC_V2ADDSC, TILEGX_OPC_V2ADD, TILEGX_OPC_V2CMPEQ,
1690 TILEGX_OPC_V2CMPLES, TILEGX_OPC_V2CMPLEU, TILEGX_OPC_V2CMPLTS,
1691 TILEGX_OPC_V2CMPLTU,
1692 BITFIELD(49, 4) /* index 1125 */,
1693 TILEGX_OPC_V2CMPNE, TILEGX_OPC_V2INT_H, TILEGX_OPC_V2INT_L,
1694 TILEGX_OPC_V2MAXS, TILEGX_OPC_V2MINS, TILEGX_OPC_V2MNZ, TILEGX_OPC_V2MZ,
1695 TILEGX_OPC_V2PACKH, TILEGX_OPC_V2PACKL, TILEGX_OPC_V2PACKUC,
1696 TILEGX_OPC_V2SHLSC, TILEGX_OPC_V2SHL, TILEGX_OPC_V2SHRS, TILEGX_OPC_V2SHRU,
1697 TILEGX_OPC_V2SUBSC, TILEGX_OPC_V2SUB,
1698 BITFIELD(49, 4) /* index 1142 */,
1699 TILEGX_OPC_V4ADDSC, TILEGX_OPC_V4ADD, TILEGX_OPC_V4INT_H,
1700 TILEGX_OPC_V4INT_L, TILEGX_OPC_V4PACKSC, TILEGX_OPC_V4SHLSC,
1701 TILEGX_OPC_V4SHL, TILEGX_OPC_V4SHRS, TILEGX_OPC_V4SHRU, TILEGX_OPC_V4SUBSC,
1702 TILEGX_OPC_V4SUB, TILEGX_OPC_XOR, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1703 TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1704 BITFIELD(49, 4) /* index 1159 */,
1705 TILEGX_OPC_NONE, TILEGX_OPC_ROTLI, TILEGX_OPC_SHLI, TILEGX_OPC_SHLXI,
1706 TILEGX_OPC_SHRSI, TILEGX_OPC_SHRUI, TILEGX_OPC_SHRUXI, TILEGX_OPC_V1SHLI,
1707 TILEGX_OPC_V1SHRSI, TILEGX_OPC_V1SHRUI, TILEGX_OPC_V2SHLI,
1708 TILEGX_OPC_V2SHRSI, TILEGX_OPC_V2SHRUI, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1709 TILEGX_OPC_NONE,
1710 BITFIELD(31, 2) /* index 1176 */,
1711 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1712 CHILD(1181),
1713 BITFIELD(33, 2) /* index 1181 */,
1714 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1715 CHILD(1186),
1716 BITFIELD(35, 2) /* index 1186 */,
1717 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1718 CHILD(1191),
1719 BITFIELD(37, 2) /* index 1191 */,
1720 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1721 CHILD(1196),
1722 BITFIELD(39, 2) /* index 1196 */,
1723 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1724 CHILD(1201),
1725 BITFIELD(41, 2) /* index 1201 */,
1726 TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI, TILEGX_OPC_SHL16INSLI,
1727 TILEGX_OPC_INFOL,
1728};
1729
1730static const unsigned short decode_Y0_fsm[178] =
1731{
1732 BITFIELD(27, 4) /* index 0 */,
1733 CHILD(17), TILEGX_OPC_ADDXI, CHILD(32), TILEGX_OPC_CMPEQI,
1734 TILEGX_OPC_CMPLTSI, CHILD(62), CHILD(67), CHILD(118), CHILD(123),
1735 CHILD(128), CHILD(133), CHILD(153), CHILD(158), CHILD(163), CHILD(168),
1736 CHILD(173),
1737 BITFIELD(6, 2) /* index 17 */,
1738 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, CHILD(22),
1739 BITFIELD(8, 2) /* index 22 */,
1740 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, CHILD(27),
1741 BITFIELD(10, 2) /* index 27 */,
1742 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_MOVEI,
1743 BITFIELD(0, 2) /* index 32 */,
1744 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(37),
1745 BITFIELD(2, 2) /* index 37 */,
1746 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(42),
1747 BITFIELD(4, 2) /* index 42 */,
1748 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(47),
1749 BITFIELD(6, 2) /* index 47 */,
1750 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(52),
1751 BITFIELD(8, 2) /* index 52 */,
1752 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(57),
1753 BITFIELD(10, 2) /* index 57 */,
1754 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_INFO,
1755 BITFIELD(18, 2) /* index 62 */,
1756 TILEGX_OPC_ADDX, TILEGX_OPC_ADD, TILEGX_OPC_SUBX, TILEGX_OPC_SUB,
1757 BITFIELD(15, 5) /* index 67 */,
1758 TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL1ADD,
1759 TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL1ADD,
1760 TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL2ADD,
1761 TILEGX_OPC_SHL2ADD, TILEGX_OPC_SHL2ADD, TILEGX_OPC_SHL2ADD,
1762 TILEGX_OPC_SHL2ADD, TILEGX_OPC_SHL2ADD, TILEGX_OPC_SHL2ADD,
1763 TILEGX_OPC_SHL2ADD, TILEGX_OPC_SHL3ADD, TILEGX_OPC_SHL3ADD,
1764 TILEGX_OPC_SHL3ADD, TILEGX_OPC_SHL3ADD, TILEGX_OPC_SHL3ADD,
1765 TILEGX_OPC_SHL3ADD, TILEGX_OPC_SHL3ADD, TILEGX_OPC_SHL3ADD, CHILD(100),
1766 CHILD(109), TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1767 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1768 BITFIELD(12, 3) /* index 100 */,
1769 TILEGX_OPC_NONE, TILEGX_OPC_CLZ, TILEGX_OPC_CTZ, TILEGX_OPC_FNOP,
1770 TILEGX_OPC_FSINGLE_PACK1, TILEGX_OPC_NOP, TILEGX_OPC_PCNT,
1771 TILEGX_OPC_REVBITS,
1772 BITFIELD(12, 3) /* index 109 */,
1773 TILEGX_OPC_REVBYTES, TILEGX_OPC_TBLIDXB0, TILEGX_OPC_TBLIDXB1,
1774 TILEGX_OPC_TBLIDXB2, TILEGX_OPC_TBLIDXB3, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1775 TILEGX_OPC_NONE,
1776 BITFIELD(18, 2) /* index 118 */,
1777 TILEGX_OPC_CMPLES, TILEGX_OPC_CMPLEU, TILEGX_OPC_CMPLTS, TILEGX_OPC_CMPLTU,
1778 BITFIELD(18, 2) /* index 123 */,
1779 TILEGX_OPC_CMPEQ, TILEGX_OPC_CMPNE, TILEGX_OPC_MULAX, TILEGX_OPC_MULX,
1780 BITFIELD(18, 2) /* index 128 */,
1781 TILEGX_OPC_CMOVEQZ, TILEGX_OPC_CMOVNEZ, TILEGX_OPC_MNZ, TILEGX_OPC_MZ,
1782 BITFIELD(18, 2) /* index 133 */,
1783 TILEGX_OPC_AND, TILEGX_OPC_NOR, CHILD(138), TILEGX_OPC_XOR,
1784 BITFIELD(12, 2) /* index 138 */,
1785 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, CHILD(143),
1786 BITFIELD(14, 2) /* index 143 */,
1787 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, CHILD(148),
1788 BITFIELD(16, 2) /* index 148 */,
1789 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_MOVE,
1790 BITFIELD(18, 2) /* index 153 */,
1791 TILEGX_OPC_ROTL, TILEGX_OPC_SHL, TILEGX_OPC_SHRS, TILEGX_OPC_SHRU,
1792 BITFIELD(18, 2) /* index 158 */,
1793 TILEGX_OPC_NONE, TILEGX_OPC_SHL1ADDX, TILEGX_OPC_SHL2ADDX,
1794 TILEGX_OPC_SHL3ADDX,
1795 BITFIELD(18, 2) /* index 163 */,
1796 TILEGX_OPC_MUL_HS_HS, TILEGX_OPC_MUL_HU_HU, TILEGX_OPC_MUL_LS_LS,
1797 TILEGX_OPC_MUL_LU_LU,
1798 BITFIELD(18, 2) /* index 168 */,
1799 TILEGX_OPC_MULA_HS_HS, TILEGX_OPC_MULA_HU_HU, TILEGX_OPC_MULA_LS_LS,
1800 TILEGX_OPC_MULA_LU_LU,
1801 BITFIELD(18, 2) /* index 173 */,
1802 TILEGX_OPC_ROTLI, TILEGX_OPC_SHLI, TILEGX_OPC_SHRSI, TILEGX_OPC_SHRUI,
1803};
1804
1805static const unsigned short decode_Y1_fsm[167] =
1806{
1807 BITFIELD(58, 4) /* index 0 */,
1808 TILEGX_OPC_NONE, CHILD(17), TILEGX_OPC_ADDXI, CHILD(32), TILEGX_OPC_CMPEQI,
1809 TILEGX_OPC_CMPLTSI, CHILD(62), CHILD(67), CHILD(117), CHILD(122),
1810 CHILD(127), CHILD(132), CHILD(152), CHILD(157), CHILD(162), TILEGX_OPC_NONE,
1811 BITFIELD(37, 2) /* index 17 */,
1812 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, CHILD(22),
1813 BITFIELD(39, 2) /* index 22 */,
1814 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, CHILD(27),
1815 BITFIELD(41, 2) /* index 27 */,
1816 TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_ADDI, TILEGX_OPC_MOVEI,
1817 BITFIELD(31, 2) /* index 32 */,
1818 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(37),
1819 BITFIELD(33, 2) /* index 37 */,
1820 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(42),
1821 BITFIELD(35, 2) /* index 42 */,
1822 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(47),
1823 BITFIELD(37, 2) /* index 47 */,
1824 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(52),
1825 BITFIELD(39, 2) /* index 52 */,
1826 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, CHILD(57),
1827 BITFIELD(41, 2) /* index 57 */,
1828 TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_ANDI, TILEGX_OPC_INFO,
1829 BITFIELD(49, 2) /* index 62 */,
1830 TILEGX_OPC_ADDX, TILEGX_OPC_ADD, TILEGX_OPC_SUBX, TILEGX_OPC_SUB,
1831 BITFIELD(47, 4) /* index 67 */,
1832 TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL1ADD,
1833 TILEGX_OPC_SHL1ADD, TILEGX_OPC_SHL2ADD, TILEGX_OPC_SHL2ADD,
1834 TILEGX_OPC_SHL2ADD, TILEGX_OPC_SHL2ADD, TILEGX_OPC_SHL3ADD,
1835 TILEGX_OPC_SHL3ADD, TILEGX_OPC_SHL3ADD, TILEGX_OPC_SHL3ADD, CHILD(84),
1836 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_NONE,
1837 BITFIELD(43, 3) /* index 84 */,
1838 CHILD(93), CHILD(96), CHILD(99), CHILD(102), CHILD(105), CHILD(108),
1839 CHILD(111), CHILD(114),
1840 BITFIELD(46, 1) /* index 93 */,
1841 TILEGX_OPC_NONE, TILEGX_OPC_FNOP,
1842 BITFIELD(46, 1) /* index 96 */,
1843 TILEGX_OPC_NONE, TILEGX_OPC_ILL,
1844 BITFIELD(46, 1) /* index 99 */,
1845 TILEGX_OPC_NONE, TILEGX_OPC_JALRP,
1846 BITFIELD(46, 1) /* index 102 */,
1847 TILEGX_OPC_NONE, TILEGX_OPC_JALR,
1848 BITFIELD(46, 1) /* index 105 */,
1849 TILEGX_OPC_NONE, TILEGX_OPC_JRP,
1850 BITFIELD(46, 1) /* index 108 */,
1851 TILEGX_OPC_NONE, TILEGX_OPC_JR,
1852 BITFIELD(46, 1) /* index 111 */,
1853 TILEGX_OPC_NONE, TILEGX_OPC_LNK,
1854 BITFIELD(46, 1) /* index 114 */,
1855 TILEGX_OPC_NONE, TILEGX_OPC_NOP,
1856 BITFIELD(49, 2) /* index 117 */,
1857 TILEGX_OPC_CMPLES, TILEGX_OPC_CMPLEU, TILEGX_OPC_CMPLTS, TILEGX_OPC_CMPLTU,
1858 BITFIELD(49, 2) /* index 122 */,
1859 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_CMPEQ, TILEGX_OPC_CMPNE,
1860 BITFIELD(49, 2) /* index 127 */,
1861 TILEGX_OPC_NONE, TILEGX_OPC_NONE, TILEGX_OPC_MNZ, TILEGX_OPC_MZ,
1862 BITFIELD(49, 2) /* index 132 */,
1863 TILEGX_OPC_AND, TILEGX_OPC_NOR, CHILD(137), TILEGX_OPC_XOR,
1864 BITFIELD(43, 2) /* index 137 */,
1865 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, CHILD(142),
1866 BITFIELD(45, 2) /* index 142 */,
1867 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, CHILD(147),
1868 BITFIELD(47, 2) /* index 147 */,
1869 TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_OR, TILEGX_OPC_MOVE,
1870 BITFIELD(49, 2) /* index 152 */,
1871 TILEGX_OPC_ROTL, TILEGX_OPC_SHL, TILEGX_OPC_SHRS, TILEGX_OPC_SHRU,
1872 BITFIELD(49, 2) /* index 157 */,
1873 TILEGX_OPC_NONE, TILEGX_OPC_SHL1ADDX, TILEGX_OPC_SHL2ADDX,
1874 TILEGX_OPC_SHL3ADDX,
1875 BITFIELD(49, 2) /* index 162 */,
1876 TILEGX_OPC_ROTLI, TILEGX_OPC_SHLI, TILEGX_OPC_SHRSI, TILEGX_OPC_SHRUI,
1877};
1878
1879static const unsigned short decode_Y2_fsm[118] =
1880{
1881 BITFIELD(62, 2) /* index 0 */,
1882 TILEGX_OPC_NONE, CHILD(5), CHILD(66), CHILD(109),
1883 BITFIELD(55, 3) /* index 5 */,
1884 CHILD(14), CHILD(14), CHILD(14), CHILD(17), CHILD(40), CHILD(40), CHILD(40),
1885 CHILD(43),
1886 BITFIELD(26, 1) /* index 14 */,
1887 TILEGX_OPC_LD1S, TILEGX_OPC_LD1U,
1888 BITFIELD(26, 1) /* index 17 */,
1889 CHILD(20), CHILD(30),
1890 BITFIELD(51, 2) /* index 20 */,
1891 TILEGX_OPC_LD1S, TILEGX_OPC_LD1S, TILEGX_OPC_LD1S, CHILD(25),
1892 BITFIELD(53, 2) /* index 25 */,
1893 TILEGX_OPC_LD1S, TILEGX_OPC_LD1S, TILEGX_OPC_LD1S,
1894 TILEGX_OPC_PREFETCH_L1_FAULT,
1895 BITFIELD(51, 2) /* index 30 */,
1896 TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, CHILD(35),
1897 BITFIELD(53, 2) /* index 35 */,
1898 TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, TILEGX_OPC_LD1U, TILEGX_OPC_PREFETCH,
1899 BITFIELD(26, 1) /* index 40 */,
1900 TILEGX_OPC_LD2S, TILEGX_OPC_LD2U,
1901 BITFIELD(26, 1) /* index 43 */,
1902 CHILD(46), CHILD(56),
1903 BITFIELD(51, 2) /* index 46 */,
1904 TILEGX_OPC_LD2S, TILEGX_OPC_LD2S, TILEGX_OPC_LD2S, CHILD(51),
1905 BITFIELD(53, 2) /* index 51 */,
1906 TILEGX_OPC_LD2S, TILEGX_OPC_LD2S, TILEGX_OPC_LD2S,
1907 TILEGX_OPC_PREFETCH_L2_FAULT,
1908 BITFIELD(51, 2) /* index 56 */,
1909 TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, CHILD(61),
1910 BITFIELD(53, 2) /* index 61 */,
1911 TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, TILEGX_OPC_LD2U, TILEGX_OPC_PREFETCH_L2,
1912 BITFIELD(56, 2) /* index 66 */,
1913 CHILD(71), CHILD(74), CHILD(90), CHILD(93),
1914 BITFIELD(26, 1) /* index 71 */,
1915 TILEGX_OPC_NONE, TILEGX_OPC_LD4S,
1916 BITFIELD(26, 1) /* index 74 */,
1917 TILEGX_OPC_NONE, CHILD(77),
1918 BITFIELD(51, 2) /* index 77 */,
1919 TILEGX_OPC_LD4S, TILEGX_OPC_LD4S, TILEGX_OPC_LD4S, CHILD(82),
1920 BITFIELD(53, 2) /* index 82 */,
1921 TILEGX_OPC_LD4S, TILEGX_OPC_LD4S, TILEGX_OPC_LD4S, CHILD(87),
1922 BITFIELD(55, 1) /* index 87 */,
1923 TILEGX_OPC_LD4S, TILEGX_OPC_PREFETCH_L3_FAULT,
1924 BITFIELD(26, 1) /* index 90 */,
1925 TILEGX_OPC_LD4U, TILEGX_OPC_LD,
1926 BITFIELD(26, 1) /* index 93 */,
1927 CHILD(96), TILEGX_OPC_LD,
1928 BITFIELD(51, 2) /* index 96 */,
1929 TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, CHILD(101),
1930 BITFIELD(53, 2) /* index 101 */,
1931 TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, TILEGX_OPC_LD4U, CHILD(106),
1932 BITFIELD(55, 1) /* index 106 */,
1933 TILEGX_OPC_LD4U, TILEGX_OPC_PREFETCH_L3,
1934 BITFIELD(26, 1) /* index 109 */,
1935 CHILD(112), CHILD(115),
1936 BITFIELD(57, 1) /* index 112 */,
1937 TILEGX_OPC_ST1, TILEGX_OPC_ST4,
1938 BITFIELD(57, 1) /* index 115 */,
1939 TILEGX_OPC_ST2, TILEGX_OPC_ST,
1940};
1941
1942#undef BITFIELD
1943#undef CHILD
1944const unsigned short * const
1945tilegx_bundle_decoder_fsms[TILEGX_NUM_PIPELINE_ENCODINGS] =
1946{
1947 decode_X0_fsm,
1948 decode_X1_fsm,
1949 decode_Y0_fsm,
1950 decode_Y1_fsm,
1951 decode_Y2_fsm
1952};
1953const struct tilegx_operand tilegx_operands[35] =
1954{
1955 {
1956 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_IMM8_X0),
1957 8, 1, 0, 0, 0, 0,
1958 create_Imm8_X0, get_Imm8_X0
1959 },
1960 {
1961 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_IMM8_X1),
1962 8, 1, 0, 0, 0, 0,
1963 create_Imm8_X1, get_Imm8_X1
1964 },
1965 {
1966 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_IMM8_Y0),
1967 8, 1, 0, 0, 0, 0,
1968 create_Imm8_Y0, get_Imm8_Y0
1969 },
1970 {
1971 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_IMM8_Y1),
1972 8, 1, 0, 0, 0, 0,
1973 create_Imm8_Y1, get_Imm8_Y1
1974 },
1975 {
1976 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_IMM16_X0_HW0_LAST),
1977 16, 1, 0, 0, 0, 0,
1978 create_Imm16_X0, get_Imm16_X0
1979 },
1980 {
1981 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_IMM16_X1_HW0_LAST),
1982 16, 1, 0, 0, 0, 0,
1983 create_Imm16_X1, get_Imm16_X1
1984 },
1985 {
1986 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
1987 6, 0, 0, 1, 0, 0,
1988 create_Dest_X0, get_Dest_X0
1989 },
1990 {
1991 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
1992 6, 0, 1, 0, 0, 0,
1993 create_SrcA_X0, get_SrcA_X0
1994 },
1995 {
1996 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
1997 6, 0, 0, 1, 0, 0,
1998 create_Dest_X1, get_Dest_X1
1999 },
2000 {
2001 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2002 6, 0, 1, 0, 0, 0,
2003 create_SrcA_X1, get_SrcA_X1
2004 },
2005 {
2006 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2007 6, 0, 0, 1, 0, 0,
2008 create_Dest_Y0, get_Dest_Y0
2009 },
2010 {
2011 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2012 6, 0, 1, 0, 0, 0,
2013 create_SrcA_Y0, get_SrcA_Y0
2014 },
2015 {
2016 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2017 6, 0, 0, 1, 0, 0,
2018 create_Dest_Y1, get_Dest_Y1
2019 },
2020 {
2021 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2022 6, 0, 1, 0, 0, 0,
2023 create_SrcA_Y1, get_SrcA_Y1
2024 },
2025 {
2026 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2027 6, 0, 1, 0, 0, 0,
2028 create_SrcA_Y2, get_SrcA_Y2
2029 },
2030 {
2031 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2032 6, 0, 1, 1, 0, 0,
2033 create_SrcA_X1, get_SrcA_X1
2034 },
2035 {
2036 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2037 6, 0, 1, 0, 0, 0,
2038 create_SrcB_X0, get_SrcB_X0
2039 },
2040 {
2041 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2042 6, 0, 1, 0, 0, 0,
2043 create_SrcB_X1, get_SrcB_X1
2044 },
2045 {
2046 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2047 6, 0, 1, 0, 0, 0,
2048 create_SrcB_Y0, get_SrcB_Y0
2049 },
2050 {
2051 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2052 6, 0, 1, 0, 0, 0,
2053 create_SrcB_Y1, get_SrcB_Y1
2054 },
2055 {
2056 TILEGX_OP_TYPE_ADDRESS, BFD_RELOC(TILEGX_BROFF_X1),
2057 17, 1, 0, 0, 1, TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES,
2058 create_BrOff_X1, get_BrOff_X1
2059 },
2060 {
2061 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_MMSTART_X0),
2062 6, 0, 0, 0, 0, 0,
2063 create_BFStart_X0, get_BFStart_X0
2064 },
2065 {
2066 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_MMEND_X0),
2067 6, 0, 0, 0, 0, 0,
2068 create_BFEnd_X0, get_BFEnd_X0
2069 },
2070 {
2071 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2072 6, 0, 1, 1, 0, 0,
2073 create_Dest_X0, get_Dest_X0
2074 },
2075 {
2076 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2077 6, 0, 1, 1, 0, 0,
2078 create_Dest_Y0, get_Dest_Y0
2079 },
2080 {
2081 TILEGX_OP_TYPE_ADDRESS, BFD_RELOC(TILEGX_JUMPOFF_X1),
2082 27, 1, 0, 0, 1, TILEGX_LOG2_BUNDLE_ALIGNMENT_IN_BYTES,
2083 create_JumpOff_X1, get_JumpOff_X1
2084 },
2085 {
2086 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2087 6, 0, 0, 1, 0, 0,
2088 create_SrcBDest_Y2, get_SrcBDest_Y2
2089 },
2090 {
2091 TILEGX_OP_TYPE_SPR, BFD_RELOC(TILEGX_MF_IMM14_X1),
2092 14, 0, 0, 0, 0, 0,
2093 create_MF_Imm14_X1, get_MF_Imm14_X1
2094 },
2095 {
2096 TILEGX_OP_TYPE_SPR, BFD_RELOC(TILEGX_MT_IMM14_X1),
2097 14, 0, 0, 0, 0, 0,
2098 create_MT_Imm14_X1, get_MT_Imm14_X1
2099 },
2100 {
2101 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_SHAMT_X0),
2102 6, 0, 0, 0, 0, 0,
2103 create_ShAmt_X0, get_ShAmt_X0
2104 },
2105 {
2106 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_SHAMT_X1),
2107 6, 0, 0, 0, 0, 0,
2108 create_ShAmt_X1, get_ShAmt_X1
2109 },
2110 {
2111 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_SHAMT_Y0),
2112 6, 0, 0, 0, 0, 0,
2113 create_ShAmt_Y0, get_ShAmt_Y0
2114 },
2115 {
2116 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_SHAMT_Y1),
2117 6, 0, 0, 0, 0, 0,
2118 create_ShAmt_Y1, get_ShAmt_Y1
2119 },
2120 {
2121 TILEGX_OP_TYPE_REGISTER, BFD_RELOC(NONE),
2122 6, 0, 1, 0, 0, 0,
2123 create_SrcBDest_Y2, get_SrcBDest_Y2
2124 },
2125 {
2126 TILEGX_OP_TYPE_IMMEDIATE, BFD_RELOC(TILEGX_DEST_IMM8_X1),
2127 8, 1, 0, 0, 0, 0,
2128 create_Dest_Imm8_X1, get_Dest_Imm8_X1
2129 }
2130};
2131
2132
2133
2134
2135/* Given a set of bundle bits and the lookup FSM for a specific pipe,
2136 * returns which instruction the bundle contains in that pipe.
2137 */
2138static const struct tilegx_opcode *
2139find_opcode(tilegx_bundle_bits bits, const unsigned short *table)
2140{
2141 int index = 0;
2142
2143 while (1)
2144 {
2145 unsigned short bitspec = table[index];
2146 unsigned int bitfield =
2147 ((unsigned int)(bits >> (bitspec & 63))) & (bitspec >> 6);
2148
2149 unsigned short next = table[index + 1 + bitfield];
2150 if (next <= TILEGX_OPC_NONE)
2151 return &tilegx_opcodes[next];
2152
2153 index = next - TILEGX_OPC_NONE;
2154 }
2155}
2156
2157
2158int
2159parse_insn_tilegx(tilegx_bundle_bits bits,
2160 unsigned long long pc,
2161 struct tilegx_decoded_instruction
2162 decoded[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE])
2163{
2164 int num_instructions = 0;
2165 int pipe;
2166
2167 int min_pipe, max_pipe;
2168 if ((bits & TILEGX_BUNDLE_MODE_MASK) == 0)
2169 {
2170 min_pipe = TILEGX_PIPELINE_X0;
2171 max_pipe = TILEGX_PIPELINE_X1;
2172 }
2173 else
2174 {
2175 min_pipe = TILEGX_PIPELINE_Y0;
2176 max_pipe = TILEGX_PIPELINE_Y2;
2177 }
2178
2179 /* For each pipe, find an instruction that fits. */
2180 for (pipe = min_pipe; pipe <= max_pipe; pipe++)
2181 {
2182 const struct tilegx_opcode *opc;
2183 struct tilegx_decoded_instruction *d;
2184 int i;
2185
2186 d = &decoded[num_instructions++];
2187 opc = find_opcode (bits, tilegx_bundle_decoder_fsms[pipe]);
2188 d->opcode = opc;
2189
2190 /* Decode each operand, sign extending, etc. as appropriate. */
2191 for (i = 0; i < opc->num_operands; i++)
2192 {
2193 const struct tilegx_operand *op =
2194 &tilegx_operands[opc->operands[pipe][i]];
2195 int raw_opval = op->extract (bits);
2196 long long opval;
2197
2198 if (op->is_signed)
2199 {
2200 /* Sign-extend the operand. */
2201 int shift = (int)((sizeof(int) * 8) - op->num_bits);
2202 raw_opval = (raw_opval << shift) >> shift;
2203 }
2204
2205 /* Adjust PC-relative scaled branch offsets. */
2206 if (op->type == TILEGX_OP_TYPE_ADDRESS)
2207 opval = (raw_opval * TILEGX_BUNDLE_SIZE_IN_BYTES) + pc;
2208 else
2209 opval = raw_opval;
2210
2211 /* Record the final value. */
2212 d->operands[i] = op;
2213 d->operand_values[i] = opval;
2214 }
2215 }
2216
2217 return num_instructions;
2218}
diff --git a/arch/tile/kernel/time.c b/arch/tile/kernel/time.c
deleted file mode 100644
index f95d65f3162b..000000000000
--- a/arch/tile/kernel/time.c
+++ /dev/null
@@ -1,306 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Support the cycle counter clocksource and tile timer clock event device.
15 */
16
17#include <linux/time.h>
18#include <linux/timex.h>
19#include <linux/clocksource.h>
20#include <linux/clockchips.h>
21#include <linux/hardirq.h>
22#include <linux/sched.h>
23#include <linux/sched/clock.h>
24#include <linux/smp.h>
25#include <linux/delay.h>
26#include <linux/module.h>
27#include <linux/timekeeper_internal.h>
28#include <asm/irq_regs.h>
29#include <asm/traps.h>
30#include <asm/vdso.h>
31#include <hv/hypervisor.h>
32#include <arch/interrupts.h>
33#include <arch/spr_def.h>
34
35
36/*
37 * Define the cycle counter clock source.
38 */
39
40/* How many cycles per second we are running at. */
41static cycles_t cycles_per_sec __ro_after_init;
42
43cycles_t get_clock_rate(void)
44{
45 return cycles_per_sec;
46}
47
48#if CHIP_HAS_SPLIT_CYCLE()
49cycles_t get_cycles(void)
50{
51 unsigned int high = __insn_mfspr(SPR_CYCLE_HIGH);
52 unsigned int low = __insn_mfspr(SPR_CYCLE_LOW);
53 unsigned int high2 = __insn_mfspr(SPR_CYCLE_HIGH);
54
55 while (unlikely(high != high2)) {
56 low = __insn_mfspr(SPR_CYCLE_LOW);
57 high = high2;
58 high2 = __insn_mfspr(SPR_CYCLE_HIGH);
59 }
60
61 return (((cycles_t)high) << 32) | low;
62}
63EXPORT_SYMBOL(get_cycles);
64#endif
65
66/*
67 * We use a relatively small shift value so that sched_clock()
68 * won't wrap around very often.
69 */
70#define SCHED_CLOCK_SHIFT 10
71
72static unsigned long sched_clock_mult __ro_after_init;
73
74static cycles_t clocksource_get_cycles(struct clocksource *cs)
75{
76 return get_cycles();
77}
78
79static struct clocksource cycle_counter_cs = {
80 .name = "cycle counter",
81 .rating = 300,
82 .read = clocksource_get_cycles,
83 .mask = CLOCKSOURCE_MASK(64),
84 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
85};
86
87/*
88 * Called very early from setup_arch() to set cycles_per_sec.
89 * We initialize it early so we can use it to set up loops_per_jiffy.
90 */
91void __init setup_clock(void)
92{
93 cycles_per_sec = hv_sysconf(HV_SYSCONF_CPU_SPEED);
94 sched_clock_mult =
95 clocksource_hz2mult(cycles_per_sec, SCHED_CLOCK_SHIFT);
96}
97
98void __init calibrate_delay(void)
99{
100 loops_per_jiffy = get_clock_rate() / HZ;
101 pr_info("Clock rate yields %lu.%02lu BogoMIPS (lpj=%lu)\n",
102 loops_per_jiffy / (500000 / HZ),
103 (loops_per_jiffy / (5000 / HZ)) % 100, loops_per_jiffy);
104}
105
106/* Called fairly late in init/main.c, but before we go smp. */
107void __init time_init(void)
108{
109 /* Initialize and register the clock source. */
110 clocksource_register_hz(&cycle_counter_cs, cycles_per_sec);
111
112 /* Start up the tile-timer interrupt source on the boot cpu. */
113 setup_tile_timer();
114}
115
116/*
117 * Define the tile timer clock event device. The timer is driven by
118 * the TILE_TIMER_CONTROL register, which consists of a 31-bit down
119 * counter, plus bit 31, which signifies that the counter has wrapped
120 * from zero to (2**31) - 1. The INT_TILE_TIMER interrupt will be
121 * raised as long as bit 31 is set.
122 *
123 * The TILE_MINSEC value represents the largest range of real-time
124 * we can possibly cover with the timer, based on MAX_TICK combined
125 * with the slowest reasonable clock rate we might run at.
126 */
127
128#define MAX_TICK 0x7fffffff /* we have 31 bits of countdown timer */
129#define TILE_MINSEC 5 /* timer covers no more than 5 seconds */
130
131static int tile_timer_set_next_event(unsigned long ticks,
132 struct clock_event_device *evt)
133{
134 BUG_ON(ticks > MAX_TICK);
135 __insn_mtspr(SPR_TILE_TIMER_CONTROL, ticks);
136 arch_local_irq_unmask_now(INT_TILE_TIMER);
137 return 0;
138}
139
140/*
141 * Whenever anyone tries to change modes, we just mask interrupts
142 * and wait for the next event to get set.
143 */
144static int tile_timer_shutdown(struct clock_event_device *evt)
145{
146 arch_local_irq_mask_now(INT_TILE_TIMER);
147 return 0;
148}
149
150/*
151 * Set min_delta_ns to 1 microsecond, since it takes about
152 * that long to fire the interrupt.
153 */
154static DEFINE_PER_CPU(struct clock_event_device, tile_timer) = {
155 .name = "tile timer",
156 .features = CLOCK_EVT_FEAT_ONESHOT,
157 .min_delta_ns = 1000,
158 .min_delta_ticks = 1,
159 .max_delta_ticks = MAX_TICK,
160 .rating = 100,
161 .irq = -1,
162 .set_next_event = tile_timer_set_next_event,
163 .set_state_shutdown = tile_timer_shutdown,
164 .set_state_oneshot = tile_timer_shutdown,
165 .set_state_oneshot_stopped = tile_timer_shutdown,
166 .tick_resume = tile_timer_shutdown,
167};
168
169void setup_tile_timer(void)
170{
171 struct clock_event_device *evt = this_cpu_ptr(&tile_timer);
172
173 /* Fill in fields that are speed-specific. */
174 clockevents_calc_mult_shift(evt, cycles_per_sec, TILE_MINSEC);
175 evt->max_delta_ns = clockevent_delta2ns(MAX_TICK, evt);
176
177 /* Mark as being for this cpu only. */
178 evt->cpumask = cpumask_of(smp_processor_id());
179
180 /* Start out with timer not firing. */
181 arch_local_irq_mask_now(INT_TILE_TIMER);
182
183 /* Register tile timer. */
184 clockevents_register_device(evt);
185}
186
187/* Called from the interrupt vector. */
188void do_timer_interrupt(struct pt_regs *regs, int fault_num)
189{
190 struct pt_regs *old_regs = set_irq_regs(regs);
191 struct clock_event_device *evt = this_cpu_ptr(&tile_timer);
192
193 /*
194 * Mask the timer interrupt here, since we are a oneshot timer
195 * and there are now by definition no events pending.
196 */
197 arch_local_irq_mask(INT_TILE_TIMER);
198
199 /* Track time spent here in an interrupt context */
200 irq_enter();
201
202 /* Track interrupt count. */
203 __this_cpu_inc(irq_stat.irq_timer_count);
204
205 /* Call the generic timer handler */
206 evt->event_handler(evt);
207
208 /*
209 * Track time spent against the current process again and
210 * process any softirqs if they are waiting.
211 */
212 irq_exit();
213
214 set_irq_regs(old_regs);
215}
216
217/*
218 * Scheduler clock - returns current time in nanosec units.
219 * Note that with LOCKDEP, this is called during lockdep_init(), and
220 * we will claim that sched_clock() is zero for a little while, until
221 * we run setup_clock(), above.
222 */
223unsigned long long sched_clock(void)
224{
225 return mult_frac(get_cycles(),
226 sched_clock_mult, 1ULL << SCHED_CLOCK_SHIFT);
227}
228
229int setup_profiling_timer(unsigned int multiplier)
230{
231 return -EINVAL;
232}
233
234/*
235 * Use the tile timer to convert nsecs to core clock cycles, relying
236 * on it having the same frequency as SPR_CYCLE.
237 */
238cycles_t ns2cycles(unsigned long nsecs)
239{
240 /*
241 * We do not have to disable preemption here as each core has the same
242 * clock frequency.
243 */
244 struct clock_event_device *dev = raw_cpu_ptr(&tile_timer);
245
246 /*
247 * as in clocksource.h and x86's timer.h, we split the calculation
248 * into 2 parts to avoid unecessary overflow of the intermediate
249 * value. This will not lead to any loss of precision.
250 */
251 u64 quot = (u64)nsecs >> dev->shift;
252 u64 rem = (u64)nsecs & ((1ULL << dev->shift) - 1);
253 return quot * dev->mult + ((rem * dev->mult) >> dev->shift);
254}
255
256void update_vsyscall_tz(void)
257{
258 write_seqcount_begin(&vdso_data->tz_seq);
259 vdso_data->tz_minuteswest = sys_tz.tz_minuteswest;
260 vdso_data->tz_dsttime = sys_tz.tz_dsttime;
261 write_seqcount_end(&vdso_data->tz_seq);
262}
263
264void update_vsyscall(struct timekeeper *tk)
265{
266 if (tk->tkr_mono.clock != &cycle_counter_cs)
267 return;
268
269 write_seqcount_begin(&vdso_data->tb_seq);
270
271 vdso_data->cycle_last = tk->tkr_mono.cycle_last;
272 vdso_data->mask = tk->tkr_mono.mask;
273 vdso_data->mult = tk->tkr_mono.mult;
274 vdso_data->shift = tk->tkr_mono.shift;
275
276 vdso_data->wall_time_sec = tk->xtime_sec;
277 vdso_data->wall_time_snsec = tk->tkr_mono.xtime_nsec;
278
279 vdso_data->monotonic_time_sec = tk->xtime_sec
280 + tk->wall_to_monotonic.tv_sec;
281 vdso_data->monotonic_time_snsec = tk->tkr_mono.xtime_nsec
282 + ((u64)tk->wall_to_monotonic.tv_nsec
283 << tk->tkr_mono.shift);
284 while (vdso_data->monotonic_time_snsec >=
285 (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
286 vdso_data->monotonic_time_snsec -=
287 ((u64)NSEC_PER_SEC) << tk->tkr_mono.shift;
288 vdso_data->monotonic_time_sec++;
289 }
290
291 vdso_data->wall_time_coarse_sec = tk->xtime_sec;
292 vdso_data->wall_time_coarse_nsec = (long)(tk->tkr_mono.xtime_nsec >>
293 tk->tkr_mono.shift);
294
295 vdso_data->monotonic_time_coarse_sec =
296 vdso_data->wall_time_coarse_sec + tk->wall_to_monotonic.tv_sec;
297 vdso_data->monotonic_time_coarse_nsec =
298 vdso_data->wall_time_coarse_nsec + tk->wall_to_monotonic.tv_nsec;
299
300 while (vdso_data->monotonic_time_coarse_nsec >= NSEC_PER_SEC) {
301 vdso_data->monotonic_time_coarse_nsec -= NSEC_PER_SEC;
302 vdso_data->monotonic_time_coarse_sec++;
303 }
304
305 write_seqcount_end(&vdso_data->tb_seq);
306}
diff --git a/arch/tile/kernel/tlb.c b/arch/tile/kernel/tlb.c
deleted file mode 100644
index f23b53515671..000000000000
--- a/arch/tile/kernel/tlb.c
+++ /dev/null
@@ -1,104 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 */
15
16#include <linux/cpumask.h>
17#include <linux/module.h>
18#include <linux/hugetlb.h>
19#include <asm/tlbflush.h>
20#include <asm/homecache.h>
21#include <hv/hypervisor.h>
22
23/* From tlbflush.h */
24DEFINE_PER_CPU(int, current_asid);
25int min_asid, max_asid;
26
27/*
28 * Note that we flush the L1I (for VM_EXEC pages) as well as the TLB
29 * so that when we are unmapping an executable page, we also flush it.
30 * Combined with flushing the L1I at context switch time, this means
31 * we don't have to do any other icache flushes.
32 */
33
34void flush_tlb_mm(struct mm_struct *mm)
35{
36 HV_Remote_ASID asids[NR_CPUS];
37 int i = 0, cpu;
38 for_each_cpu(cpu, mm_cpumask(mm)) {
39 HV_Remote_ASID *asid = &asids[i++];
40 asid->y = cpu / smp_topology.width;
41 asid->x = cpu % smp_topology.width;
42 asid->asid = per_cpu(current_asid, cpu);
43 }
44 flush_remote(0, HV_FLUSH_EVICT_L1I, mm_cpumask(mm),
45 0, 0, 0, NULL, asids, i);
46}
47
48void flush_tlb_current_task(void)
49{
50 flush_tlb_mm(current->mm);
51}
52
53void flush_tlb_page_mm(struct vm_area_struct *vma, struct mm_struct *mm,
54 unsigned long va)
55{
56 unsigned long size = vma_kernel_pagesize(vma);
57 int cache = (vma->vm_flags & VM_EXEC) ? HV_FLUSH_EVICT_L1I : 0;
58 flush_remote(0, cache, mm_cpumask(mm),
59 va, size, size, mm_cpumask(mm), NULL, 0);
60}
61
62void flush_tlb_page(struct vm_area_struct *vma, unsigned long va)
63{
64 flush_tlb_page_mm(vma, vma->vm_mm, va);
65}
66EXPORT_SYMBOL(flush_tlb_page);
67
68void flush_tlb_range(struct vm_area_struct *vma,
69 unsigned long start, unsigned long end)
70{
71 unsigned long size = vma_kernel_pagesize(vma);
72 struct mm_struct *mm = vma->vm_mm;
73 int cache = (vma->vm_flags & VM_EXEC) ? HV_FLUSH_EVICT_L1I : 0;
74 flush_remote(0, cache, mm_cpumask(mm), start, end - start, size,
75 mm_cpumask(mm), NULL, 0);
76}
77
78void flush_tlb_all(void)
79{
80 int i;
81 for (i = 0; ; ++i) {
82 HV_VirtAddrRange r = hv_inquire_virtual(i);
83 if (r.size == 0)
84 break;
85 flush_remote(0, HV_FLUSH_EVICT_L1I, cpu_online_mask,
86 r.start, r.size, PAGE_SIZE, cpu_online_mask,
87 NULL, 0);
88 flush_remote(0, 0, NULL,
89 r.start, r.size, HPAGE_SIZE, cpu_online_mask,
90 NULL, 0);
91 }
92}
93
94/*
95 * Callers need to flush the L1I themselves if necessary, e.g. for
96 * kernel module unload. Otherwise we assume callers are not using
97 * executable pgprot_t's. Using EVICT_L1I means that dataplane cpus
98 * will get an unnecessary interrupt otherwise.
99 */
100void flush_tlb_kernel_range(unsigned long start, unsigned long end)
101{
102 flush_remote(0, 0, NULL,
103 start, end - start, PAGE_SIZE, cpu_online_mask, NULL, 0);
104}
diff --git a/arch/tile/kernel/traps.c b/arch/tile/kernel/traps.c
deleted file mode 100644
index 83a7186198d7..000000000000
--- a/arch/tile/kernel/traps.c
+++ /dev/null
@@ -1,421 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/sched.h>
16#include <linux/sched/debug.h>
17#include <linux/kernel.h>
18#include <linux/kprobes.h>
19#include <linux/kdebug.h>
20#include <linux/module.h>
21#include <linux/reboot.h>
22#include <linux/uaccess.h>
23#include <linux/ptrace.h>
24#include <linux/hardirq.h>
25#include <linux/nmi.h>
26#include <asm/stack.h>
27#include <asm/traps.h>
28#include <asm/setup.h>
29
30#include <arch/interrupts.h>
31#include <arch/spr_def.h>
32#include <arch/opcode.h>
33
34void __init trap_init(void)
35{
36 /* Nothing needed here since we link code at .intrpt */
37}
38
39int unaligned_fixup = 1;
40
41static int __init setup_unaligned_fixup(char *str)
42{
43 /*
44 * Say "=-1" to completely disable it. If you just do "=0", we
45 * will still parse the instruction, then fire a SIGBUS with
46 * the correct address from inside the single_step code.
47 */
48 if (kstrtoint(str, 0, &unaligned_fixup) != 0)
49 return 0;
50
51 pr_info("Fixups for unaligned data accesses are %s\n",
52 unaligned_fixup >= 0 ?
53 (unaligned_fixup ? "enabled" : "disabled") :
54 "completely disabled");
55 return 1;
56}
57__setup("unaligned_fixup=", setup_unaligned_fixup);
58
59#if CHIP_HAS_TILE_DMA()
60
61static int dma_disabled;
62
63static int __init nodma(char *str)
64{
65 pr_info("User-space DMA is disabled\n");
66 dma_disabled = 1;
67 return 1;
68}
69__setup("nodma", nodma);
70
71/* How to decode SPR_GPV_REASON */
72#define IRET_ERROR (1U << 31)
73#define MT_ERROR (1U << 30)
74#define MF_ERROR (1U << 29)
75#define SPR_INDEX ((1U << 15) - 1)
76#define SPR_MPL_SHIFT 9 /* starting bit position for MPL encoded in SPR */
77
78/*
79 * See if this GPV is just to notify the kernel of SPR use and we can
80 * retry the user instruction after adjusting some MPLs suitably.
81 */
82static int retry_gpv(unsigned int gpv_reason)
83{
84 int mpl;
85
86 if (gpv_reason & IRET_ERROR)
87 return 0;
88
89 BUG_ON((gpv_reason & (MT_ERROR|MF_ERROR)) == 0);
90 mpl = (gpv_reason & SPR_INDEX) >> SPR_MPL_SHIFT;
91 if (mpl == INT_DMA_NOTIFY && !dma_disabled) {
92 /* User is turning on DMA. Allow it and retry. */
93 printk(KERN_DEBUG "Process %d/%s is now enabled for DMA\n",
94 current->pid, current->comm);
95 BUG_ON(current->thread.tile_dma_state.enabled);
96 current->thread.tile_dma_state.enabled = 1;
97 grant_dma_mpls();
98 return 1;
99 }
100
101 return 0;
102}
103
104#endif /* CHIP_HAS_TILE_DMA() */
105
106extern tile_bundle_bits bpt_code;
107
108asm(".pushsection .rodata.bpt_code,\"a\";"
109 ".align 8;"
110 "bpt_code: bpt;"
111 ".size bpt_code,.-bpt_code;"
112 ".popsection");
113
114static int special_ill(tile_bundle_bits bundle, int *sigp, int *codep)
115{
116 int sig, code, maxcode;
117
118 if (bundle == bpt_code) {
119 *sigp = SIGTRAP;
120 *codep = TRAP_BRKPT;
121 return 1;
122 }
123
124 /* If it's a "raise" bundle, then "ill" must be in pipe X1. */
125#ifdef __tilegx__
126 if ((bundle & TILEGX_BUNDLE_MODE_MASK) != 0)
127 return 0;
128 if (get_Opcode_X1(bundle) != RRR_0_OPCODE_X1)
129 return 0;
130 if (get_RRROpcodeExtension_X1(bundle) != UNARY_RRR_0_OPCODE_X1)
131 return 0;
132 if (get_UnaryOpcodeExtension_X1(bundle) != ILL_UNARY_OPCODE_X1)
133 return 0;
134#else
135 if (bundle & TILEPRO_BUNDLE_Y_ENCODING_MASK)
136 return 0;
137 if (get_Opcode_X1(bundle) != SHUN_0_OPCODE_X1)
138 return 0;
139 if (get_UnShOpcodeExtension_X1(bundle) != UN_0_SHUN_0_OPCODE_X1)
140 return 0;
141 if (get_UnOpcodeExtension_X1(bundle) != ILL_UN_0_SHUN_0_OPCODE_X1)
142 return 0;
143#endif
144
145 /* Check that the magic distinguishers are set to mean "raise". */
146 if (get_Dest_X1(bundle) != 29 || get_SrcA_X1(bundle) != 37)
147 return 0;
148
149 /* There must be an "addli zero, zero, VAL" in X0. */
150 if (get_Opcode_X0(bundle) != ADDLI_OPCODE_X0)
151 return 0;
152 if (get_Dest_X0(bundle) != TREG_ZERO)
153 return 0;
154 if (get_SrcA_X0(bundle) != TREG_ZERO)
155 return 0;
156
157 /*
158 * Validate the proposed signal number and si_code value.
159 * Note that we embed these in the static instruction itself
160 * so that we perturb the register state as little as possible
161 * at the time of the actual fault; it's unlikely you'd ever
162 * need to dynamically choose which kind of fault to raise
163 * from user space.
164 */
165 sig = get_Imm16_X0(bundle) & 0x3f;
166 switch (sig) {
167 case SIGILL:
168 maxcode = NSIGILL;
169 break;
170 case SIGFPE:
171 maxcode = NSIGFPE;
172 break;
173 case SIGSEGV:
174 maxcode = NSIGSEGV;
175 break;
176 case SIGBUS:
177 maxcode = NSIGBUS;
178 break;
179 case SIGTRAP:
180 maxcode = NSIGTRAP;
181 break;
182 default:
183 return 0;
184 }
185 code = (get_Imm16_X0(bundle) >> 6) & 0xf;
186 if (code <= 0 || code > maxcode)
187 return 0;
188
189 /* Make it the requested signal. */
190 *sigp = sig;
191 *codep = code;
192 return 1;
193}
194
195static const char *const int_name[] = {
196 [INT_MEM_ERROR] = "Memory error",
197 [INT_ILL] = "Illegal instruction",
198 [INT_GPV] = "General protection violation",
199 [INT_UDN_ACCESS] = "UDN access",
200 [INT_IDN_ACCESS] = "IDN access",
201#if CHIP_HAS_SN()
202 [INT_SN_ACCESS] = "SN access",
203#endif
204 [INT_SWINT_3] = "Software interrupt 3",
205 [INT_SWINT_2] = "Software interrupt 2",
206 [INT_SWINT_0] = "Software interrupt 0",
207 [INT_UNALIGN_DATA] = "Unaligned data",
208 [INT_DOUBLE_FAULT] = "Double fault",
209#ifdef __tilegx__
210 [INT_ILL_TRANS] = "Illegal virtual address",
211#endif
212};
213
214static int do_bpt(struct pt_regs *regs)
215{
216 unsigned long bundle, bcode, bpt;
217
218 bundle = *(unsigned long *)instruction_pointer(regs);
219
220 /*
221 * bpt shoule be { bpt; nop }, which is 0x286a44ae51485000ULL.
222 * we encode the unused least significant bits for other purpose.
223 */
224 bpt = bundle & ~((1ULL << 12) - 1);
225 if (bpt != TILE_BPT_BUNDLE)
226 return 0;
227
228 bcode = bundle & ((1ULL << 12) - 1);
229 /*
230 * notify the kprobe handlers, if instruction is likely to
231 * pertain to them.
232 */
233 switch (bcode) {
234 /* breakpoint_insn */
235 case 0:
236 notify_die(DIE_BREAK, "debug", regs, bundle,
237 INT_ILL, SIGTRAP);
238 break;
239 /* compiled_bpt */
240 case DIE_COMPILED_BPT:
241 notify_die(DIE_COMPILED_BPT, "debug", regs, bundle,
242 INT_ILL, SIGTRAP);
243 break;
244 /* breakpoint2_insn */
245 case DIE_SSTEPBP:
246 notify_die(DIE_SSTEPBP, "single_step", regs, bundle,
247 INT_ILL, SIGTRAP);
248 break;
249 default:
250 return 0;
251 }
252
253 return 1;
254}
255
256void __kprobes do_trap(struct pt_regs *regs, int fault_num,
257 unsigned long reason)
258{
259 siginfo_t info;
260 int signo, code;
261 unsigned long address = 0;
262 tile_bundle_bits instr;
263 int is_kernel = !user_mode(regs);
264
265 clear_siginfo(&info);
266
267 /* Handle breakpoints, etc. */
268 if (is_kernel && fault_num == INT_ILL && do_bpt(regs))
269 return;
270
271 /* Re-enable interrupts, if they were previously enabled. */
272 if (!(regs->flags & PT_FLAGS_DISABLE_IRQ))
273 local_irq_enable();
274
275 /*
276 * If it hits in kernel mode and we can't fix it up, just exit the
277 * current process and hope for the best.
278 */
279 if (is_kernel) {
280 const char *name;
281 char buf[100];
282 if (fixup_exception(regs)) /* ILL_TRANS or UNALIGN_DATA */
283 return;
284 if (fault_num >= 0 &&
285 fault_num < ARRAY_SIZE(int_name) &&
286 int_name[fault_num] != NULL)
287 name = int_name[fault_num];
288 else
289 name = "Unknown interrupt";
290 if (fault_num == INT_GPV)
291 snprintf(buf, sizeof(buf), "; GPV_REASON %#lx", reason);
292#ifdef __tilegx__
293 else if (fault_num == INT_ILL_TRANS)
294 snprintf(buf, sizeof(buf), "; address %#lx", reason);
295#endif
296 else
297 buf[0] = '\0';
298 pr_alert("Kernel took bad trap %d (%s) at PC %#lx%s\n",
299 fault_num, name, regs->pc, buf);
300 show_regs(regs);
301 do_exit(SIGKILL); /* FIXME: implement i386 die() */
302 }
303
304 switch (fault_num) {
305 case INT_MEM_ERROR:
306 signo = SIGBUS;
307 code = BUS_OBJERR;
308 break;
309 case INT_ILL:
310 if (copy_from_user(&instr, (void __user *)regs->pc,
311 sizeof(instr))) {
312 pr_err("Unreadable instruction for INT_ILL: %#lx\n",
313 regs->pc);
314 do_exit(SIGKILL);
315 }
316 if (!special_ill(instr, &signo, &code)) {
317 signo = SIGILL;
318 code = ILL_ILLOPC;
319 }
320 address = regs->pc;
321 break;
322 case INT_GPV:
323#if CHIP_HAS_TILE_DMA()
324 if (retry_gpv(reason))
325 return;
326#endif
327 /*FALLTHROUGH*/
328 case INT_UDN_ACCESS:
329 case INT_IDN_ACCESS:
330#if CHIP_HAS_SN()
331 case INT_SN_ACCESS:
332#endif
333 signo = SIGILL;
334 code = ILL_PRVREG;
335 address = regs->pc;
336 break;
337 case INT_SWINT_3:
338 case INT_SWINT_2:
339 case INT_SWINT_0:
340 signo = SIGILL;
341 code = ILL_ILLTRP;
342 address = regs->pc;
343 break;
344 case INT_UNALIGN_DATA:
345#ifndef __tilegx__ /* Emulated support for single step debugging */
346 if (unaligned_fixup >= 0) {
347 struct single_step_state *state =
348 current_thread_info()->step_state;
349 if (!state ||
350 (void __user *)(regs->pc) != state->buffer) {
351 single_step_once(regs);
352 return;
353 }
354 }
355#endif
356 signo = SIGBUS;
357 code = BUS_ADRALN;
358 address = 0;
359 break;
360 case INT_DOUBLE_FAULT:
361 /*
362 * For double fault, "reason" is actually passed as
363 * SYSTEM_SAVE_K_2, the hypervisor's double-fault info, so
364 * we can provide the original fault number rather than
365 * the uninteresting "INT_DOUBLE_FAULT" so the user can
366 * learn what actually struck while PL0 ICS was set.
367 */
368 fault_num = reason;
369 signo = SIGILL;
370 code = ILL_DBLFLT;
371 address = regs->pc;
372 break;
373#ifdef __tilegx__
374 case INT_ILL_TRANS: {
375 /* Avoid a hardware erratum with the return address stack. */
376 fill_ra_stack();
377
378 signo = SIGSEGV;
379 address = reason;
380 code = SEGV_MAPERR;
381 break;
382 }
383#endif
384 default:
385 panic("Unexpected do_trap interrupt number %d", fault_num);
386 }
387
388 info.si_signo = signo;
389 info.si_code = code;
390 info.si_addr = (void __user *)address;
391 if (signo == SIGILL)
392 info.si_trapno = fault_num;
393 if (signo != SIGTRAP)
394 trace_unhandled_signal("trap", regs, address, signo);
395 force_sig_info(signo, &info, current);
396}
397
398void do_nmi(struct pt_regs *regs, int fault_num, unsigned long reason)
399{
400 nmi_enter();
401 switch (reason) {
402#ifdef arch_trigger_cpumask_backtrace
403 case TILE_NMI_DUMP_STACK:
404 nmi_cpu_backtrace(regs);
405 break;
406#endif
407 default:
408 panic("Unexpected do_nmi type %ld", reason);
409 }
410 nmi_exit();
411}
412
413/* Deprecated function currently only used here. */
414extern void _dump_stack(int dummy, ulong pc, ulong lr, ulong sp, ulong r52);
415
416void kernel_double_fault(int dummy, ulong pc, ulong lr, ulong sp, ulong r52)
417{
418 _dump_stack(dummy, pc, lr, sp, r52);
419 pr_emerg("Double fault: exiting\n");
420 machine_halt();
421}
diff --git a/arch/tile/kernel/unaligned.c b/arch/tile/kernel/unaligned.c
deleted file mode 100644
index 77a0b6b6a2a1..000000000000
--- a/arch/tile/kernel/unaligned.c
+++ /dev/null
@@ -1,1603 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * A code-rewriter that handles unaligned exception.
15 */
16
17#include <linux/smp.h>
18#include <linux/ptrace.h>
19#include <linux/slab.h>
20#include <linux/sched/debug.h>
21#include <linux/sched/task.h>
22#include <linux/thread_info.h>
23#include <linux/uaccess.h>
24#include <linux/mman.h>
25#include <linux/types.h>
26#include <linux/err.h>
27#include <linux/extable.h>
28#include <linux/compat.h>
29#include <linux/prctl.h>
30#include <asm/cacheflush.h>
31#include <asm/traps.h>
32#include <linux/uaccess.h>
33#include <asm/unaligned.h>
34#include <arch/abi.h>
35#include <arch/spr_def.h>
36#include <arch/opcode.h>
37
38
39/*
40 * This file handles unaligned exception for tile-Gx. The tilepro's unaligned
41 * exception is supported out of single_step.c
42 */
43
44int unaligned_printk;
45
46static int __init setup_unaligned_printk(char *str)
47{
48 long val;
49 if (kstrtol(str, 0, &val) != 0)
50 return 0;
51 unaligned_printk = val;
52 pr_info("Printk for each unaligned data accesses is %s\n",
53 unaligned_printk ? "enabled" : "disabled");
54 return 1;
55}
56__setup("unaligned_printk=", setup_unaligned_printk);
57
58unsigned int unaligned_fixup_count;
59
60#ifdef __tilegx__
61
62/*
63 * Unalign data jit fixup code fragement. Reserved space is 128 bytes.
64 * The 1st 64-bit word saves fault PC address, 2nd word is the fault
65 * instruction bundle followed by 14 JIT bundles.
66 */
67
68struct unaligned_jit_fragment {
69 unsigned long pc;
70 tilegx_bundle_bits bundle;
71 tilegx_bundle_bits insn[14];
72};
73
74/*
75 * Check if a nop or fnop at bundle's pipeline X0.
76 */
77
78static bool is_bundle_x0_nop(tilegx_bundle_bits bundle)
79{
80 return (((get_UnaryOpcodeExtension_X0(bundle) ==
81 NOP_UNARY_OPCODE_X0) &&
82 (get_RRROpcodeExtension_X0(bundle) ==
83 UNARY_RRR_0_OPCODE_X0) &&
84 (get_Opcode_X0(bundle) ==
85 RRR_0_OPCODE_X0)) ||
86 ((get_UnaryOpcodeExtension_X0(bundle) ==
87 FNOP_UNARY_OPCODE_X0) &&
88 (get_RRROpcodeExtension_X0(bundle) ==
89 UNARY_RRR_0_OPCODE_X0) &&
90 (get_Opcode_X0(bundle) ==
91 RRR_0_OPCODE_X0)));
92}
93
94/*
95 * Check if nop or fnop at bundle's pipeline X1.
96 */
97
98static bool is_bundle_x1_nop(tilegx_bundle_bits bundle)
99{
100 return (((get_UnaryOpcodeExtension_X1(bundle) ==
101 NOP_UNARY_OPCODE_X1) &&
102 (get_RRROpcodeExtension_X1(bundle) ==
103 UNARY_RRR_0_OPCODE_X1) &&
104 (get_Opcode_X1(bundle) ==
105 RRR_0_OPCODE_X1)) ||
106 ((get_UnaryOpcodeExtension_X1(bundle) ==
107 FNOP_UNARY_OPCODE_X1) &&
108 (get_RRROpcodeExtension_X1(bundle) ==
109 UNARY_RRR_0_OPCODE_X1) &&
110 (get_Opcode_X1(bundle) ==
111 RRR_0_OPCODE_X1)));
112}
113
114/*
115 * Check if nop or fnop at bundle's Y0 pipeline.
116 */
117
118static bool is_bundle_y0_nop(tilegx_bundle_bits bundle)
119{
120 return (((get_UnaryOpcodeExtension_Y0(bundle) ==
121 NOP_UNARY_OPCODE_Y0) &&
122 (get_RRROpcodeExtension_Y0(bundle) ==
123 UNARY_RRR_1_OPCODE_Y0) &&
124 (get_Opcode_Y0(bundle) ==
125 RRR_1_OPCODE_Y0)) ||
126 ((get_UnaryOpcodeExtension_Y0(bundle) ==
127 FNOP_UNARY_OPCODE_Y0) &&
128 (get_RRROpcodeExtension_Y0(bundle) ==
129 UNARY_RRR_1_OPCODE_Y0) &&
130 (get_Opcode_Y0(bundle) ==
131 RRR_1_OPCODE_Y0)));
132}
133
134/*
135 * Check if nop or fnop at bundle's pipeline Y1.
136 */
137
138static bool is_bundle_y1_nop(tilegx_bundle_bits bundle)
139{
140 return (((get_UnaryOpcodeExtension_Y1(bundle) ==
141 NOP_UNARY_OPCODE_Y1) &&
142 (get_RRROpcodeExtension_Y1(bundle) ==
143 UNARY_RRR_1_OPCODE_Y1) &&
144 (get_Opcode_Y1(bundle) ==
145 RRR_1_OPCODE_Y1)) ||
146 ((get_UnaryOpcodeExtension_Y1(bundle) ==
147 FNOP_UNARY_OPCODE_Y1) &&
148 (get_RRROpcodeExtension_Y1(bundle) ==
149 UNARY_RRR_1_OPCODE_Y1) &&
150 (get_Opcode_Y1(bundle) ==
151 RRR_1_OPCODE_Y1)));
152}
153
154/*
155 * Test if a bundle's y0 and y1 pipelines are both nop or fnop.
156 */
157
158static bool is_y0_y1_nop(tilegx_bundle_bits bundle)
159{
160 return is_bundle_y0_nop(bundle) && is_bundle_y1_nop(bundle);
161}
162
163/*
164 * Test if a bundle's x0 and x1 pipelines are both nop or fnop.
165 */
166
167static bool is_x0_x1_nop(tilegx_bundle_bits bundle)
168{
169 return is_bundle_x0_nop(bundle) && is_bundle_x1_nop(bundle);
170}
171
172/*
173 * Find the destination, source registers of fault unalign access instruction
174 * at X1 or Y2. Also, allocate up to 3 scratch registers clob1, clob2 and
175 * clob3, which are guaranteed different from any register used in the fault
176 * bundle. r_alias is used to return if the other instructions other than the
177 * unalign load/store shares same register with ra, rb and rd.
178 */
179
180static void find_regs(tilegx_bundle_bits bundle, uint64_t *rd, uint64_t *ra,
181 uint64_t *rb, uint64_t *clob1, uint64_t *clob2,
182 uint64_t *clob3, bool *r_alias)
183{
184 int i;
185 uint64_t reg;
186 uint64_t reg_map = 0, alias_reg_map = 0, map;
187 bool alias = false;
188
189 /*
190 * Parse fault bundle, find potential used registers and mark
191 * corresponding bits in reg_map and alias_map. These 2 bit maps
192 * are used to find the scratch registers and determine if there
193 * is register alias.
194 */
195 if (bundle & TILEGX_BUNDLE_MODE_MASK) { /* Y Mode Bundle. */
196
197 reg = get_SrcA_Y2(bundle);
198 reg_map |= 1ULL << reg;
199 *ra = reg;
200 reg = get_SrcBDest_Y2(bundle);
201 reg_map |= 1ULL << reg;
202
203 if (rd) {
204 /* Load. */
205 *rd = reg;
206 alias_reg_map = (1ULL << *rd) | (1ULL << *ra);
207 } else {
208 /* Store. */
209 *rb = reg;
210 alias_reg_map = (1ULL << *ra) | (1ULL << *rb);
211 }
212
213 if (!is_bundle_y1_nop(bundle)) {
214 reg = get_SrcA_Y1(bundle);
215 reg_map |= (1ULL << reg);
216 map = (1ULL << reg);
217
218 reg = get_SrcB_Y1(bundle);
219 reg_map |= (1ULL << reg);
220 map |= (1ULL << reg);
221
222 reg = get_Dest_Y1(bundle);
223 reg_map |= (1ULL << reg);
224 map |= (1ULL << reg);
225
226 if (map & alias_reg_map)
227 alias = true;
228 }
229
230 if (!is_bundle_y0_nop(bundle)) {
231 reg = get_SrcA_Y0(bundle);
232 reg_map |= (1ULL << reg);
233 map = (1ULL << reg);
234
235 reg = get_SrcB_Y0(bundle);
236 reg_map |= (1ULL << reg);
237 map |= (1ULL << reg);
238
239 reg = get_Dest_Y0(bundle);
240 reg_map |= (1ULL << reg);
241 map |= (1ULL << reg);
242
243 if (map & alias_reg_map)
244 alias = true;
245 }
246 } else { /* X Mode Bundle. */
247
248 reg = get_SrcA_X1(bundle);
249 reg_map |= (1ULL << reg);
250 *ra = reg;
251 if (rd) {
252 /* Load. */
253 reg = get_Dest_X1(bundle);
254 reg_map |= (1ULL << reg);
255 *rd = reg;
256 alias_reg_map = (1ULL << *rd) | (1ULL << *ra);
257 } else {
258 /* Store. */
259 reg = get_SrcB_X1(bundle);
260 reg_map |= (1ULL << reg);
261 *rb = reg;
262 alias_reg_map = (1ULL << *ra) | (1ULL << *rb);
263 }
264
265 if (!is_bundle_x0_nop(bundle)) {
266 reg = get_SrcA_X0(bundle);
267 reg_map |= (1ULL << reg);
268 map = (1ULL << reg);
269
270 reg = get_SrcB_X0(bundle);
271 reg_map |= (1ULL << reg);
272 map |= (1ULL << reg);
273
274 reg = get_Dest_X0(bundle);
275 reg_map |= (1ULL << reg);
276 map |= (1ULL << reg);
277
278 if (map & alias_reg_map)
279 alias = true;
280 }
281 }
282
283 /*
284 * "alias" indicates if the unalign access registers have collision
285 * with others in the same bundle. We jsut simply test all register
286 * operands case (RRR), ignored the case with immidate. If a bundle
287 * has no register alias, we may do fixup in a simple or fast manner.
288 * So if an immidata field happens to hit with a register, we may end
289 * up fall back to the generic handling.
290 */
291
292 *r_alias = alias;
293
294 /* Flip bits on reg_map. */
295 reg_map ^= -1ULL;
296
297 /* Scan reg_map lower 54(TREG_SP) bits to find 3 set bits. */
298 for (i = 0; i < TREG_SP; i++) {
299 if (reg_map & (0x1ULL << i)) {
300 if (*clob1 == -1) {
301 *clob1 = i;
302 } else if (*clob2 == -1) {
303 *clob2 = i;
304 } else if (*clob3 == -1) {
305 *clob3 = i;
306 return;
307 }
308 }
309 }
310}
311
312/*
313 * Sanity check for register ra, rb, rd, clob1/2/3. Return true if any of them
314 * is unexpected.
315 */
316
317static bool check_regs(uint64_t rd, uint64_t ra, uint64_t rb,
318 uint64_t clob1, uint64_t clob2, uint64_t clob3)
319{
320 bool unexpected = false;
321 if ((ra >= 56) && (ra != TREG_ZERO))
322 unexpected = true;
323
324 if ((clob1 >= 56) || (clob2 >= 56) || (clob3 >= 56))
325 unexpected = true;
326
327 if (rd != -1) {
328 if ((rd >= 56) && (rd != TREG_ZERO))
329 unexpected = true;
330 } else {
331 if ((rb >= 56) && (rb != TREG_ZERO))
332 unexpected = true;
333 }
334 return unexpected;
335}
336
337
338#define GX_INSN_X0_MASK ((1ULL << 31) - 1)
339#define GX_INSN_X1_MASK (((1ULL << 31) - 1) << 31)
340#define GX_INSN_Y0_MASK ((0xFULL << 27) | (0xFFFFFULL))
341#define GX_INSN_Y1_MASK (GX_INSN_Y0_MASK << 31)
342#define GX_INSN_Y2_MASK ((0x7FULL << 51) | (0x7FULL << 20))
343
344#ifdef __LITTLE_ENDIAN
345#define GX_INSN_BSWAP(_bundle_) (_bundle_)
346#else
347#define GX_INSN_BSWAP(_bundle_) swab64(_bundle_)
348#endif /* __LITTLE_ENDIAN */
349
350/*
351 * __JIT_CODE(.) creates template bundles in .rodata.unalign_data section.
352 * The corresponding static function jix_x#_###(.) generates partial or
353 * whole bundle based on the template and given arguments.
354 */
355
356#define __JIT_CODE(_X_) \
357 asm (".pushsection .rodata.unalign_data, \"a\"\n" \
358 _X_"\n" \
359 ".popsection\n")
360
361__JIT_CODE("__unalign_jit_x1_mtspr: {mtspr 0, r0}");
362static tilegx_bundle_bits jit_x1_mtspr(int spr, int reg)
363{
364 extern tilegx_bundle_bits __unalign_jit_x1_mtspr;
365 return (GX_INSN_BSWAP(__unalign_jit_x1_mtspr) & GX_INSN_X1_MASK) |
366 create_MT_Imm14_X1(spr) | create_SrcA_X1(reg);
367}
368
369__JIT_CODE("__unalign_jit_x1_mfspr: {mfspr r0, 0}");
370static tilegx_bundle_bits jit_x1_mfspr(int reg, int spr)
371{
372 extern tilegx_bundle_bits __unalign_jit_x1_mfspr;
373 return (GX_INSN_BSWAP(__unalign_jit_x1_mfspr) & GX_INSN_X1_MASK) |
374 create_MF_Imm14_X1(spr) | create_Dest_X1(reg);
375}
376
377__JIT_CODE("__unalign_jit_x0_addi: {addi r0, r0, 0; iret}");
378static tilegx_bundle_bits jit_x0_addi(int rd, int ra, int imm8)
379{
380 extern tilegx_bundle_bits __unalign_jit_x0_addi;
381 return (GX_INSN_BSWAP(__unalign_jit_x0_addi) & GX_INSN_X0_MASK) |
382 create_Dest_X0(rd) | create_SrcA_X0(ra) |
383 create_Imm8_X0(imm8);
384}
385
386__JIT_CODE("__unalign_jit_x1_ldna: {ldna r0, r0}");
387static tilegx_bundle_bits jit_x1_ldna(int rd, int ra)
388{
389 extern tilegx_bundle_bits __unalign_jit_x1_ldna;
390 return (GX_INSN_BSWAP(__unalign_jit_x1_ldna) & GX_INSN_X1_MASK) |
391 create_Dest_X1(rd) | create_SrcA_X1(ra);
392}
393
394__JIT_CODE("__unalign_jit_x0_dblalign: {dblalign r0, r0 ,r0}");
395static tilegx_bundle_bits jit_x0_dblalign(int rd, int ra, int rb)
396{
397 extern tilegx_bundle_bits __unalign_jit_x0_dblalign;
398 return (GX_INSN_BSWAP(__unalign_jit_x0_dblalign) & GX_INSN_X0_MASK) |
399 create_Dest_X0(rd) | create_SrcA_X0(ra) |
400 create_SrcB_X0(rb);
401}
402
403__JIT_CODE("__unalign_jit_x1_iret: {iret}");
404static tilegx_bundle_bits jit_x1_iret(void)
405{
406 extern tilegx_bundle_bits __unalign_jit_x1_iret;
407 return GX_INSN_BSWAP(__unalign_jit_x1_iret) & GX_INSN_X1_MASK;
408}
409
410__JIT_CODE("__unalign_jit_x01_fnop: {fnop;fnop}");
411static tilegx_bundle_bits jit_x0_fnop(void)
412{
413 extern tilegx_bundle_bits __unalign_jit_x01_fnop;
414 return GX_INSN_BSWAP(__unalign_jit_x01_fnop) & GX_INSN_X0_MASK;
415}
416
417static tilegx_bundle_bits jit_x1_fnop(void)
418{
419 extern tilegx_bundle_bits __unalign_jit_x01_fnop;
420 return GX_INSN_BSWAP(__unalign_jit_x01_fnop) & GX_INSN_X1_MASK;
421}
422
423__JIT_CODE("__unalign_jit_y2_dummy: {fnop; fnop; ld zero, sp}");
424static tilegx_bundle_bits jit_y2_dummy(void)
425{
426 extern tilegx_bundle_bits __unalign_jit_y2_dummy;
427 return GX_INSN_BSWAP(__unalign_jit_y2_dummy) & GX_INSN_Y2_MASK;
428}
429
430static tilegx_bundle_bits jit_y1_fnop(void)
431{
432 extern tilegx_bundle_bits __unalign_jit_y2_dummy;
433 return GX_INSN_BSWAP(__unalign_jit_y2_dummy) & GX_INSN_Y1_MASK;
434}
435
436__JIT_CODE("__unalign_jit_x1_st1_add: {st1_add r1, r0, 0}");
437static tilegx_bundle_bits jit_x1_st1_add(int ra, int rb, int imm8)
438{
439 extern tilegx_bundle_bits __unalign_jit_x1_st1_add;
440 return (GX_INSN_BSWAP(__unalign_jit_x1_st1_add) &
441 (~create_SrcA_X1(-1)) &
442 GX_INSN_X1_MASK) | create_SrcA_X1(ra) |
443 create_SrcB_X1(rb) | create_Dest_Imm8_X1(imm8);
444}
445
446__JIT_CODE("__unalign_jit_x1_st: {crc32_8 r1, r0, r0; st r0, r0}");
447static tilegx_bundle_bits jit_x1_st(int ra, int rb)
448{
449 extern tilegx_bundle_bits __unalign_jit_x1_st;
450 return (GX_INSN_BSWAP(__unalign_jit_x1_st) & GX_INSN_X1_MASK) |
451 create_SrcA_X1(ra) | create_SrcB_X1(rb);
452}
453
454__JIT_CODE("__unalign_jit_x1_st_add: {st_add r1, r0, 0}");
455static tilegx_bundle_bits jit_x1_st_add(int ra, int rb, int imm8)
456{
457 extern tilegx_bundle_bits __unalign_jit_x1_st_add;
458 return (GX_INSN_BSWAP(__unalign_jit_x1_st_add) &
459 (~create_SrcA_X1(-1)) &
460 GX_INSN_X1_MASK) | create_SrcA_X1(ra) |
461 create_SrcB_X1(rb) | create_Dest_Imm8_X1(imm8);
462}
463
464__JIT_CODE("__unalign_jit_x1_ld: {crc32_8 r1, r0, r0; ld r0, r0}");
465static tilegx_bundle_bits jit_x1_ld(int rd, int ra)
466{
467 extern tilegx_bundle_bits __unalign_jit_x1_ld;
468 return (GX_INSN_BSWAP(__unalign_jit_x1_ld) & GX_INSN_X1_MASK) |
469 create_Dest_X1(rd) | create_SrcA_X1(ra);
470}
471
472__JIT_CODE("__unalign_jit_x1_ld_add: {ld_add r1, r0, 0}");
473static tilegx_bundle_bits jit_x1_ld_add(int rd, int ra, int imm8)
474{
475 extern tilegx_bundle_bits __unalign_jit_x1_ld_add;
476 return (GX_INSN_BSWAP(__unalign_jit_x1_ld_add) &
477 (~create_Dest_X1(-1)) &
478 GX_INSN_X1_MASK) | create_Dest_X1(rd) |
479 create_SrcA_X1(ra) | create_Imm8_X1(imm8);
480}
481
482__JIT_CODE("__unalign_jit_x0_bfexts: {bfexts r0, r0, 0, 0}");
483static tilegx_bundle_bits jit_x0_bfexts(int rd, int ra, int bfs, int bfe)
484{
485 extern tilegx_bundle_bits __unalign_jit_x0_bfexts;
486 return (GX_INSN_BSWAP(__unalign_jit_x0_bfexts) &
487 GX_INSN_X0_MASK) |
488 create_Dest_X0(rd) | create_SrcA_X0(ra) |
489 create_BFStart_X0(bfs) | create_BFEnd_X0(bfe);
490}
491
492__JIT_CODE("__unalign_jit_x0_bfextu: {bfextu r0, r0, 0, 0}");
493static tilegx_bundle_bits jit_x0_bfextu(int rd, int ra, int bfs, int bfe)
494{
495 extern tilegx_bundle_bits __unalign_jit_x0_bfextu;
496 return (GX_INSN_BSWAP(__unalign_jit_x0_bfextu) &
497 GX_INSN_X0_MASK) |
498 create_Dest_X0(rd) | create_SrcA_X0(ra) |
499 create_BFStart_X0(bfs) | create_BFEnd_X0(bfe);
500}
501
502__JIT_CODE("__unalign_jit_x1_addi: {bfextu r1, r1, 0, 0; addi r0, r0, 0}");
503static tilegx_bundle_bits jit_x1_addi(int rd, int ra, int imm8)
504{
505 extern tilegx_bundle_bits __unalign_jit_x1_addi;
506 return (GX_INSN_BSWAP(__unalign_jit_x1_addi) & GX_INSN_X1_MASK) |
507 create_Dest_X1(rd) | create_SrcA_X1(ra) |
508 create_Imm8_X1(imm8);
509}
510
511__JIT_CODE("__unalign_jit_x0_shrui: {shrui r0, r0, 0; iret}");
512static tilegx_bundle_bits jit_x0_shrui(int rd, int ra, int imm6)
513{
514 extern tilegx_bundle_bits __unalign_jit_x0_shrui;
515 return (GX_INSN_BSWAP(__unalign_jit_x0_shrui) &
516 GX_INSN_X0_MASK) |
517 create_Dest_X0(rd) | create_SrcA_X0(ra) |
518 create_ShAmt_X0(imm6);
519}
520
521__JIT_CODE("__unalign_jit_x0_rotli: {rotli r0, r0, 0; iret}");
522static tilegx_bundle_bits jit_x0_rotli(int rd, int ra, int imm6)
523{
524 extern tilegx_bundle_bits __unalign_jit_x0_rotli;
525 return (GX_INSN_BSWAP(__unalign_jit_x0_rotli) &
526 GX_INSN_X0_MASK) |
527 create_Dest_X0(rd) | create_SrcA_X0(ra) |
528 create_ShAmt_X0(imm6);
529}
530
531__JIT_CODE("__unalign_jit_x1_bnezt: {bnezt r0, __unalign_jit_x1_bnezt}");
532static tilegx_bundle_bits jit_x1_bnezt(int ra, int broff)
533{
534 extern tilegx_bundle_bits __unalign_jit_x1_bnezt;
535 return (GX_INSN_BSWAP(__unalign_jit_x1_bnezt) &
536 GX_INSN_X1_MASK) |
537 create_SrcA_X1(ra) | create_BrOff_X1(broff);
538}
539
540#undef __JIT_CODE
541
542/*
543 * This function generates unalign fixup JIT.
544 *
545 * We first find unalign load/store instruction's destination, source
546 * registers: ra, rb and rd. and 3 scratch registers by calling
547 * find_regs(...). 3 scratch clobbers should not alias with any register
548 * used in the fault bundle. Then analyze the fault bundle to determine
549 * if it's a load or store, operand width, branch or address increment etc.
550 * At last generated JIT is copied into JIT code area in user space.
551 */
552
553static
554void jit_bundle_gen(struct pt_regs *regs, tilegx_bundle_bits bundle,
555 int align_ctl)
556{
557 struct thread_info *info = current_thread_info();
558 struct unaligned_jit_fragment frag;
559 struct unaligned_jit_fragment *jit_code_area;
560 tilegx_bundle_bits bundle_2 = 0;
561 /* If bundle_2_enable = false, bundle_2 is fnop/nop operation. */
562 bool bundle_2_enable = true;
563 uint64_t ra = -1, rb = -1, rd = -1, clob1 = -1, clob2 = -1, clob3 = -1;
564 /*
565 * Indicate if the unalign access
566 * instruction's registers hit with
567 * others in the same bundle.
568 */
569 bool alias = false;
570 bool load_n_store = true;
571 bool load_store_signed = false;
572 unsigned int load_store_size = 8;
573 bool y1_br = false; /* True, for a branch in same bundle at Y1.*/
574 int y1_br_reg = 0;
575 /* True for link operation. i.e. jalr or lnk at Y1 */
576 bool y1_lr = false;
577 int y1_lr_reg = 0;
578 bool x1_add = false;/* True, for load/store ADD instruction at X1*/
579 int x1_add_imm8 = 0;
580 bool unexpected = false;
581 int n = 0, k;
582
583 jit_code_area =
584 (struct unaligned_jit_fragment *)(info->unalign_jit_base);
585
586 memset((void *)&frag, 0, sizeof(frag));
587
588 /* 0: X mode, Otherwise: Y mode. */
589 if (bundle & TILEGX_BUNDLE_MODE_MASK) {
590 unsigned int mod, opcode;
591
592 if (get_Opcode_Y1(bundle) == RRR_1_OPCODE_Y1 &&
593 get_RRROpcodeExtension_Y1(bundle) ==
594 UNARY_RRR_1_OPCODE_Y1) {
595
596 opcode = get_UnaryOpcodeExtension_Y1(bundle);
597
598 /*
599 * Test "jalr", "jalrp", "jr", "jrp" instruction at Y1
600 * pipeline.
601 */
602 switch (opcode) {
603 case JALR_UNARY_OPCODE_Y1:
604 case JALRP_UNARY_OPCODE_Y1:
605 y1_lr = true;
606 y1_lr_reg = 55; /* Link register. */
607 /* FALLTHROUGH */
608 case JR_UNARY_OPCODE_Y1:
609 case JRP_UNARY_OPCODE_Y1:
610 y1_br = true;
611 y1_br_reg = get_SrcA_Y1(bundle);
612 break;
613 case LNK_UNARY_OPCODE_Y1:
614 /* "lnk" at Y1 pipeline. */
615 y1_lr = true;
616 y1_lr_reg = get_Dest_Y1(bundle);
617 break;
618 }
619 }
620
621 opcode = get_Opcode_Y2(bundle);
622 mod = get_Mode(bundle);
623
624 /*
625 * bundle_2 is bundle after making Y2 as a dummy operation
626 * - ld zero, sp
627 */
628 bundle_2 = (bundle & (~GX_INSN_Y2_MASK)) | jit_y2_dummy();
629
630 /* Make Y1 as fnop if Y1 is a branch or lnk operation. */
631 if (y1_br || y1_lr) {
632 bundle_2 &= ~(GX_INSN_Y1_MASK);
633 bundle_2 |= jit_y1_fnop();
634 }
635
636 if (is_y0_y1_nop(bundle_2))
637 bundle_2_enable = false;
638
639 if (mod == MODE_OPCODE_YC2) {
640 /* Store. */
641 load_n_store = false;
642 load_store_size = 1 << opcode;
643 load_store_signed = false;
644 find_regs(bundle, 0, &ra, &rb, &clob1, &clob2,
645 &clob3, &alias);
646 if (load_store_size > 8)
647 unexpected = true;
648 } else {
649 /* Load. */
650 load_n_store = true;
651 if (mod == MODE_OPCODE_YB2) {
652 switch (opcode) {
653 case LD_OPCODE_Y2:
654 load_store_signed = false;
655 load_store_size = 8;
656 break;
657 case LD4S_OPCODE_Y2:
658 load_store_signed = true;
659 load_store_size = 4;
660 break;
661 case LD4U_OPCODE_Y2:
662 load_store_signed = false;
663 load_store_size = 4;
664 break;
665 default:
666 unexpected = true;
667 }
668 } else if (mod == MODE_OPCODE_YA2) {
669 if (opcode == LD2S_OPCODE_Y2) {
670 load_store_signed = true;
671 load_store_size = 2;
672 } else if (opcode == LD2U_OPCODE_Y2) {
673 load_store_signed = false;
674 load_store_size = 2;
675 } else
676 unexpected = true;
677 } else
678 unexpected = true;
679 find_regs(bundle, &rd, &ra, &rb, &clob1, &clob2,
680 &clob3, &alias);
681 }
682 } else {
683 unsigned int opcode;
684
685 /* bundle_2 is bundle after making X1 as "fnop". */
686 bundle_2 = (bundle & (~GX_INSN_X1_MASK)) | jit_x1_fnop();
687
688 if (is_x0_x1_nop(bundle_2))
689 bundle_2_enable = false;
690
691 if (get_Opcode_X1(bundle) == RRR_0_OPCODE_X1) {
692 opcode = get_UnaryOpcodeExtension_X1(bundle);
693
694 if (get_RRROpcodeExtension_X1(bundle) ==
695 UNARY_RRR_0_OPCODE_X1) {
696 load_n_store = true;
697 find_regs(bundle, &rd, &ra, &rb, &clob1,
698 &clob2, &clob3, &alias);
699
700 switch (opcode) {
701 case LD_UNARY_OPCODE_X1:
702 load_store_signed = false;
703 load_store_size = 8;
704 break;
705 case LD4S_UNARY_OPCODE_X1:
706 load_store_signed = true;
707 /* FALLTHROUGH */
708 case LD4U_UNARY_OPCODE_X1:
709 load_store_size = 4;
710 break;
711
712 case LD2S_UNARY_OPCODE_X1:
713 load_store_signed = true;
714 /* FALLTHROUGH */
715 case LD2U_UNARY_OPCODE_X1:
716 load_store_size = 2;
717 break;
718 default:
719 unexpected = true;
720 }
721 } else {
722 load_n_store = false;
723 load_store_signed = false;
724 find_regs(bundle, 0, &ra, &rb,
725 &clob1, &clob2, &clob3,
726 &alias);
727
728 opcode = get_RRROpcodeExtension_X1(bundle);
729 switch (opcode) {
730 case ST_RRR_0_OPCODE_X1:
731 load_store_size = 8;
732 break;
733 case ST4_RRR_0_OPCODE_X1:
734 load_store_size = 4;
735 break;
736 case ST2_RRR_0_OPCODE_X1:
737 load_store_size = 2;
738 break;
739 default:
740 unexpected = true;
741 }
742 }
743 } else if (get_Opcode_X1(bundle) == IMM8_OPCODE_X1) {
744 load_n_store = true;
745 opcode = get_Imm8OpcodeExtension_X1(bundle);
746 switch (opcode) {
747 case LD_ADD_IMM8_OPCODE_X1:
748 load_store_size = 8;
749 break;
750
751 case LD4S_ADD_IMM8_OPCODE_X1:
752 load_store_signed = true;
753 /* FALLTHROUGH */
754 case LD4U_ADD_IMM8_OPCODE_X1:
755 load_store_size = 4;
756 break;
757
758 case LD2S_ADD_IMM8_OPCODE_X1:
759 load_store_signed = true;
760 /* FALLTHROUGH */
761 case LD2U_ADD_IMM8_OPCODE_X1:
762 load_store_size = 2;
763 break;
764
765 case ST_ADD_IMM8_OPCODE_X1:
766 load_n_store = false;
767 load_store_size = 8;
768 break;
769 case ST4_ADD_IMM8_OPCODE_X1:
770 load_n_store = false;
771 load_store_size = 4;
772 break;
773 case ST2_ADD_IMM8_OPCODE_X1:
774 load_n_store = false;
775 load_store_size = 2;
776 break;
777 default:
778 unexpected = true;
779 }
780
781 if (!unexpected) {
782 x1_add = true;
783 if (load_n_store)
784 x1_add_imm8 = get_Imm8_X1(bundle);
785 else
786 x1_add_imm8 = get_Dest_Imm8_X1(bundle);
787 }
788
789 find_regs(bundle, load_n_store ? (&rd) : NULL,
790 &ra, &rb, &clob1, &clob2, &clob3, &alias);
791 } else
792 unexpected = true;
793 }
794
795 /*
796 * Some sanity check for register numbers extracted from fault bundle.
797 */
798 if (check_regs(rd, ra, rb, clob1, clob2, clob3) == true)
799 unexpected = true;
800
801 /* Give warning if register ra has an aligned address. */
802 if (!unexpected)
803 WARN_ON(!((load_store_size - 1) & (regs->regs[ra])));
804
805
806 /*
807 * Fault came from kernel space, here we only need take care of
808 * unaligned "get_user/put_user" macros defined in "uaccess.h".
809 * Basically, we will handle bundle like this:
810 * {ld/2u/4s rd, ra; movei rx, 0} or {st/2/4 ra, rb; movei rx, 0}
811 * (Refer to file "arch/tile/include/asm/uaccess.h" for details).
812 * For either load or store, byte-wise operation is performed by calling
813 * get_user() or put_user(). If the macro returns non-zero value,
814 * set the value to rx, otherwise set zero to rx. Finally make pc point
815 * to next bundle and return.
816 */
817
818 if (EX1_PL(regs->ex1) != USER_PL) {
819
820 unsigned long rx = 0;
821 unsigned long x = 0, ret = 0;
822
823 if (y1_br || y1_lr || x1_add ||
824 (load_store_signed !=
825 (load_n_store && load_store_size == 4))) {
826 /* No branch, link, wrong sign-ext or load/store add. */
827 unexpected = true;
828 } else if (!unexpected) {
829 if (bundle & TILEGX_BUNDLE_MODE_MASK) {
830 /*
831 * Fault bundle is Y mode.
832 * Check if the Y1 and Y0 is the form of
833 * { movei rx, 0; nop/fnop }, if yes,
834 * find the rx.
835 */
836
837 if ((get_Opcode_Y1(bundle) == ADDI_OPCODE_Y1)
838 && (get_SrcA_Y1(bundle) == TREG_ZERO) &&
839 (get_Imm8_Y1(bundle) == 0) &&
840 is_bundle_y0_nop(bundle)) {
841 rx = get_Dest_Y1(bundle);
842 } else if ((get_Opcode_Y0(bundle) ==
843 ADDI_OPCODE_Y0) &&
844 (get_SrcA_Y0(bundle) == TREG_ZERO) &&
845 (get_Imm8_Y0(bundle) == 0) &&
846 is_bundle_y1_nop(bundle)) {
847 rx = get_Dest_Y0(bundle);
848 } else {
849 unexpected = true;
850 }
851 } else {
852 /*
853 * Fault bundle is X mode.
854 * Check if the X0 is 'movei rx, 0',
855 * if yes, find the rx.
856 */
857
858 if ((get_Opcode_X0(bundle) == IMM8_OPCODE_X0)
859 && (get_Imm8OpcodeExtension_X0(bundle) ==
860 ADDI_IMM8_OPCODE_X0) &&
861 (get_SrcA_X0(bundle) == TREG_ZERO) &&
862 (get_Imm8_X0(bundle) == 0)) {
863 rx = get_Dest_X0(bundle);
864 } else {
865 unexpected = true;
866 }
867 }
868
869 /* rx should be less than 56. */
870 if (!unexpected && (rx >= 56))
871 unexpected = true;
872 }
873
874 if (!search_exception_tables(regs->pc)) {
875 /* No fixup in the exception tables for the pc. */
876 unexpected = true;
877 }
878
879 if (unexpected) {
880 /* Unexpected unalign kernel fault. */
881 struct task_struct *tsk = validate_current();
882
883 bust_spinlocks(1);
884
885 show_regs(regs);
886
887 if (unlikely(tsk->pid < 2)) {
888 panic("Kernel unalign fault running %s!",
889 tsk->pid ? "init" : "the idle task");
890 }
891#ifdef SUPPORT_DIE
892 die("Oops", regs);
893#endif
894 bust_spinlocks(1);
895
896 do_group_exit(SIGKILL);
897
898 } else {
899 unsigned long i, b = 0;
900 unsigned char *ptr =
901 (unsigned char *)regs->regs[ra];
902 if (load_n_store) {
903 /* handle get_user(x, ptr) */
904 for (i = 0; i < load_store_size; i++) {
905 ret = get_user(b, ptr++);
906 if (!ret) {
907 /* Success! update x. */
908#ifdef __LITTLE_ENDIAN
909 x |= (b << (8 * i));
910#else
911 x <<= 8;
912 x |= b;
913#endif /* __LITTLE_ENDIAN */
914 } else {
915 x = 0;
916 break;
917 }
918 }
919
920 /* Sign-extend 4-byte loads. */
921 if (load_store_size == 4)
922 x = (long)(int)x;
923
924 /* Set register rd. */
925 regs->regs[rd] = x;
926
927 /* Set register rx. */
928 regs->regs[rx] = ret;
929
930 /* Bump pc. */
931 regs->pc += 8;
932
933 } else {
934 /* Handle put_user(x, ptr) */
935 x = regs->regs[rb];
936#ifdef __LITTLE_ENDIAN
937 b = x;
938#else
939 /*
940 * Swap x in order to store x from low
941 * to high memory same as the
942 * little-endian case.
943 */
944 switch (load_store_size) {
945 case 8:
946 b = swab64(x);
947 break;
948 case 4:
949 b = swab32(x);
950 break;
951 case 2:
952 b = swab16(x);
953 break;
954 }
955#endif /* __LITTLE_ENDIAN */
956 for (i = 0; i < load_store_size; i++) {
957 ret = put_user(b, ptr++);
958 if (ret)
959 break;
960 /* Success! shift 1 byte. */
961 b >>= 8;
962 }
963 /* Set register rx. */
964 regs->regs[rx] = ret;
965
966 /* Bump pc. */
967 regs->pc += 8;
968 }
969 }
970
971 unaligned_fixup_count++;
972
973 if (unaligned_printk) {
974 pr_info("%s/%d - Unalign fixup for kernel access to userspace %lx\n",
975 current->comm, current->pid, regs->regs[ra]);
976 }
977
978 /* Done! Return to the exception handler. */
979 return;
980 }
981
982 if ((align_ctl == 0) || unexpected) {
983 siginfo_t info;
984
985 clear_siginfo(&info);
986 info.si_signo = SIGBUS;
987 info.si_code = BUS_ADRALN;
988 info.si_addr = (unsigned char __user *)0;
989
990 if (unaligned_printk)
991 pr_info("Unalign bundle: unexp @%llx, %llx\n",
992 (unsigned long long)regs->pc,
993 (unsigned long long)bundle);
994
995 if (ra < 56) {
996 unsigned long uaa = (unsigned long)regs->regs[ra];
997 /* Set bus Address. */
998 info.si_addr = (unsigned char __user *)uaa;
999 }
1000
1001 unaligned_fixup_count++;
1002
1003 trace_unhandled_signal("unaligned fixup trap", regs,
1004 (unsigned long)info.si_addr, SIGBUS);
1005 force_sig_info(info.si_signo, &info, current);
1006 return;
1007 }
1008
1009#ifdef __LITTLE_ENDIAN
1010#define UA_FIXUP_ADDR_DELTA 1
1011#define UA_FIXUP_BFEXT_START(_B_) 0
1012#define UA_FIXUP_BFEXT_END(_B_) (8 * (_B_) - 1)
1013#else /* __BIG_ENDIAN */
1014#define UA_FIXUP_ADDR_DELTA -1
1015#define UA_FIXUP_BFEXT_START(_B_) (64 - 8 * (_B_))
1016#define UA_FIXUP_BFEXT_END(_B_) 63
1017#endif /* __LITTLE_ENDIAN */
1018
1019
1020
1021 if ((ra != rb) && (rd != TREG_SP) && !alias &&
1022 !y1_br && !y1_lr && !x1_add) {
1023 /*
1024 * Simple case: ra != rb and no register alias found,
1025 * and no branch or link. This will be the majority.
1026 * We can do a little better for simplae case than the
1027 * generic scheme below.
1028 */
1029 if (!load_n_store) {
1030 /*
1031 * Simple store: ra != rb, no need for scratch register.
1032 * Just store and rotate to right bytewise.
1033 */
1034#ifdef __BIG_ENDIAN
1035 frag.insn[n++] =
1036 jit_x0_addi(ra, ra, load_store_size - 1) |
1037 jit_x1_fnop();
1038#endif /* __BIG_ENDIAN */
1039 for (k = 0; k < load_store_size; k++) {
1040 /* Store a byte. */
1041 frag.insn[n++] =
1042 jit_x0_rotli(rb, rb, 56) |
1043 jit_x1_st1_add(ra, rb,
1044 UA_FIXUP_ADDR_DELTA);
1045 }
1046#ifdef __BIG_ENDIAN
1047 frag.insn[n] = jit_x1_addi(ra, ra, 1);
1048#else
1049 frag.insn[n] = jit_x1_addi(ra, ra,
1050 -1 * load_store_size);
1051#endif /* __LITTLE_ENDIAN */
1052
1053 if (load_store_size == 8) {
1054 frag.insn[n] |= jit_x0_fnop();
1055 } else if (load_store_size == 4) {
1056 frag.insn[n] |= jit_x0_rotli(rb, rb, 32);
1057 } else { /* = 2 */
1058 frag.insn[n] |= jit_x0_rotli(rb, rb, 16);
1059 }
1060 n++;
1061 if (bundle_2_enable)
1062 frag.insn[n++] = bundle_2;
1063 frag.insn[n++] = jit_x0_fnop() | jit_x1_iret();
1064 } else {
1065 if (rd == ra) {
1066 /* Use two clobber registers: clob1/2. */
1067 frag.insn[n++] =
1068 jit_x0_addi(TREG_SP, TREG_SP, -16) |
1069 jit_x1_fnop();
1070 frag.insn[n++] =
1071 jit_x0_addi(clob1, ra, 7) |
1072 jit_x1_st_add(TREG_SP, clob1, -8);
1073 frag.insn[n++] =
1074 jit_x0_addi(clob2, ra, 0) |
1075 jit_x1_st(TREG_SP, clob2);
1076 frag.insn[n++] =
1077 jit_x0_fnop() |
1078 jit_x1_ldna(rd, ra);
1079 frag.insn[n++] =
1080 jit_x0_fnop() |
1081 jit_x1_ldna(clob1, clob1);
1082 /*
1083 * Note: we must make sure that rd must not
1084 * be sp. Recover clob1/2 from stack.
1085 */
1086 frag.insn[n++] =
1087 jit_x0_dblalign(rd, clob1, clob2) |
1088 jit_x1_ld_add(clob2, TREG_SP, 8);
1089 frag.insn[n++] =
1090 jit_x0_fnop() |
1091 jit_x1_ld_add(clob1, TREG_SP, 16);
1092 } else {
1093 /* Use one clobber register: clob1 only. */
1094 frag.insn[n++] =
1095 jit_x0_addi(TREG_SP, TREG_SP, -16) |
1096 jit_x1_fnop();
1097 frag.insn[n++] =
1098 jit_x0_addi(clob1, ra, 7) |
1099 jit_x1_st(TREG_SP, clob1);
1100 frag.insn[n++] =
1101 jit_x0_fnop() |
1102 jit_x1_ldna(rd, ra);
1103 frag.insn[n++] =
1104 jit_x0_fnop() |
1105 jit_x1_ldna(clob1, clob1);
1106 /*
1107 * Note: we must make sure that rd must not
1108 * be sp. Recover clob1 from stack.
1109 */
1110 frag.insn[n++] =
1111 jit_x0_dblalign(rd, clob1, ra) |
1112 jit_x1_ld_add(clob1, TREG_SP, 16);
1113 }
1114
1115 if (bundle_2_enable)
1116 frag.insn[n++] = bundle_2;
1117 /*
1118 * For non 8-byte load, extract corresponding bytes and
1119 * signed extension.
1120 */
1121 if (load_store_size == 4) {
1122 if (load_store_signed)
1123 frag.insn[n++] =
1124 jit_x0_bfexts(
1125 rd, rd,
1126 UA_FIXUP_BFEXT_START(4),
1127 UA_FIXUP_BFEXT_END(4)) |
1128 jit_x1_fnop();
1129 else
1130 frag.insn[n++] =
1131 jit_x0_bfextu(
1132 rd, rd,
1133 UA_FIXUP_BFEXT_START(4),
1134 UA_FIXUP_BFEXT_END(4)) |
1135 jit_x1_fnop();
1136 } else if (load_store_size == 2) {
1137 if (load_store_signed)
1138 frag.insn[n++] =
1139 jit_x0_bfexts(
1140 rd, rd,
1141 UA_FIXUP_BFEXT_START(2),
1142 UA_FIXUP_BFEXT_END(2)) |
1143 jit_x1_fnop();
1144 else
1145 frag.insn[n++] =
1146 jit_x0_bfextu(
1147 rd, rd,
1148 UA_FIXUP_BFEXT_START(2),
1149 UA_FIXUP_BFEXT_END(2)) |
1150 jit_x1_fnop();
1151 }
1152
1153 frag.insn[n++] =
1154 jit_x0_fnop() |
1155 jit_x1_iret();
1156 }
1157 } else if (!load_n_store) {
1158
1159 /*
1160 * Generic memory store cases: use 3 clobber registers.
1161 *
1162 * Alloc space for saveing clob2,1,3 on user's stack.
1163 * register clob3 points to where clob2 saved, followed by
1164 * clob1 and 3 from high to low memory.
1165 */
1166 frag.insn[n++] =
1167 jit_x0_addi(TREG_SP, TREG_SP, -32) |
1168 jit_x1_fnop();
1169 frag.insn[n++] =
1170 jit_x0_addi(clob3, TREG_SP, 16) |
1171 jit_x1_st_add(TREG_SP, clob3, 8);
1172#ifdef __LITTLE_ENDIAN
1173 frag.insn[n++] =
1174 jit_x0_addi(clob1, ra, 0) |
1175 jit_x1_st_add(TREG_SP, clob1, 8);
1176#else
1177 frag.insn[n++] =
1178 jit_x0_addi(clob1, ra, load_store_size - 1) |
1179 jit_x1_st_add(TREG_SP, clob1, 8);
1180#endif
1181 if (load_store_size == 8) {
1182 /*
1183 * We save one byte a time, not for fast, but compact
1184 * code. After each store, data source register shift
1185 * right one byte. unchanged after 8 stores.
1186 */
1187 frag.insn[n++] =
1188 jit_x0_addi(clob2, TREG_ZERO, 7) |
1189 jit_x1_st_add(TREG_SP, clob2, 16);
1190 frag.insn[n++] =
1191 jit_x0_rotli(rb, rb, 56) |
1192 jit_x1_st1_add(clob1, rb, UA_FIXUP_ADDR_DELTA);
1193 frag.insn[n++] =
1194 jit_x0_addi(clob2, clob2, -1) |
1195 jit_x1_bnezt(clob2, -1);
1196 frag.insn[n++] =
1197 jit_x0_fnop() |
1198 jit_x1_addi(clob2, y1_br_reg, 0);
1199 } else if (load_store_size == 4) {
1200 frag.insn[n++] =
1201 jit_x0_addi(clob2, TREG_ZERO, 3) |
1202 jit_x1_st_add(TREG_SP, clob2, 16);
1203 frag.insn[n++] =
1204 jit_x0_rotli(rb, rb, 56) |
1205 jit_x1_st1_add(clob1, rb, UA_FIXUP_ADDR_DELTA);
1206 frag.insn[n++] =
1207 jit_x0_addi(clob2, clob2, -1) |
1208 jit_x1_bnezt(clob2, -1);
1209 /*
1210 * same as 8-byte case, but need shift another 4
1211 * byte to recover rb for 4-byte store.
1212 */
1213 frag.insn[n++] = jit_x0_rotli(rb, rb, 32) |
1214 jit_x1_addi(clob2, y1_br_reg, 0);
1215 } else { /* =2 */
1216 frag.insn[n++] =
1217 jit_x0_addi(clob2, rb, 0) |
1218 jit_x1_st_add(TREG_SP, clob2, 16);
1219 for (k = 0; k < 2; k++) {
1220 frag.insn[n++] =
1221 jit_x0_shrui(rb, rb, 8) |
1222 jit_x1_st1_add(clob1, rb,
1223 UA_FIXUP_ADDR_DELTA);
1224 }
1225 frag.insn[n++] =
1226 jit_x0_addi(rb, clob2, 0) |
1227 jit_x1_addi(clob2, y1_br_reg, 0);
1228 }
1229
1230 if (bundle_2_enable)
1231 frag.insn[n++] = bundle_2;
1232
1233 if (y1_lr) {
1234 frag.insn[n++] =
1235 jit_x0_fnop() |
1236 jit_x1_mfspr(y1_lr_reg,
1237 SPR_EX_CONTEXT_0_0);
1238 }
1239 if (y1_br) {
1240 frag.insn[n++] =
1241 jit_x0_fnop() |
1242 jit_x1_mtspr(SPR_EX_CONTEXT_0_0,
1243 clob2);
1244 }
1245 if (x1_add) {
1246 frag.insn[n++] =
1247 jit_x0_addi(ra, ra, x1_add_imm8) |
1248 jit_x1_ld_add(clob2, clob3, -8);
1249 } else {
1250 frag.insn[n++] =
1251 jit_x0_fnop() |
1252 jit_x1_ld_add(clob2, clob3, -8);
1253 }
1254 frag.insn[n++] =
1255 jit_x0_fnop() |
1256 jit_x1_ld_add(clob1, clob3, -8);
1257 frag.insn[n++] = jit_x0_fnop() | jit_x1_ld(clob3, clob3);
1258 frag.insn[n++] = jit_x0_fnop() | jit_x1_iret();
1259
1260 } else {
1261 /*
1262 * Generic memory load cases.
1263 *
1264 * Alloc space for saveing clob1,2,3 on user's stack.
1265 * register clob3 points to where clob1 saved, followed
1266 * by clob2 and 3 from high to low memory.
1267 */
1268
1269 frag.insn[n++] =
1270 jit_x0_addi(TREG_SP, TREG_SP, -32) |
1271 jit_x1_fnop();
1272 frag.insn[n++] =
1273 jit_x0_addi(clob3, TREG_SP, 16) |
1274 jit_x1_st_add(TREG_SP, clob3, 8);
1275 frag.insn[n++] =
1276 jit_x0_addi(clob2, ra, 0) |
1277 jit_x1_st_add(TREG_SP, clob2, 8);
1278
1279 if (y1_br) {
1280 frag.insn[n++] =
1281 jit_x0_addi(clob1, y1_br_reg, 0) |
1282 jit_x1_st_add(TREG_SP, clob1, 16);
1283 } else {
1284 frag.insn[n++] =
1285 jit_x0_fnop() |
1286 jit_x1_st_add(TREG_SP, clob1, 16);
1287 }
1288
1289 if (bundle_2_enable)
1290 frag.insn[n++] = bundle_2;
1291
1292 if (y1_lr) {
1293 frag.insn[n++] =
1294 jit_x0_fnop() |
1295 jit_x1_mfspr(y1_lr_reg,
1296 SPR_EX_CONTEXT_0_0);
1297 }
1298
1299 if (y1_br) {
1300 frag.insn[n++] =
1301 jit_x0_fnop() |
1302 jit_x1_mtspr(SPR_EX_CONTEXT_0_0,
1303 clob1);
1304 }
1305
1306 frag.insn[n++] =
1307 jit_x0_addi(clob1, clob2, 7) |
1308 jit_x1_ldna(rd, clob2);
1309 frag.insn[n++] =
1310 jit_x0_fnop() |
1311 jit_x1_ldna(clob1, clob1);
1312 frag.insn[n++] =
1313 jit_x0_dblalign(rd, clob1, clob2) |
1314 jit_x1_ld_add(clob1, clob3, -8);
1315 if (x1_add) {
1316 frag.insn[n++] =
1317 jit_x0_addi(ra, ra, x1_add_imm8) |
1318 jit_x1_ld_add(clob2, clob3, -8);
1319 } else {
1320 frag.insn[n++] =
1321 jit_x0_fnop() |
1322 jit_x1_ld_add(clob2, clob3, -8);
1323 }
1324
1325 frag.insn[n++] =
1326 jit_x0_fnop() |
1327 jit_x1_ld(clob3, clob3);
1328
1329 if (load_store_size == 4) {
1330 if (load_store_signed)
1331 frag.insn[n++] =
1332 jit_x0_bfexts(
1333 rd, rd,
1334 UA_FIXUP_BFEXT_START(4),
1335 UA_FIXUP_BFEXT_END(4)) |
1336 jit_x1_fnop();
1337 else
1338 frag.insn[n++] =
1339 jit_x0_bfextu(
1340 rd, rd,
1341 UA_FIXUP_BFEXT_START(4),
1342 UA_FIXUP_BFEXT_END(4)) |
1343 jit_x1_fnop();
1344 } else if (load_store_size == 2) {
1345 if (load_store_signed)
1346 frag.insn[n++] =
1347 jit_x0_bfexts(
1348 rd, rd,
1349 UA_FIXUP_BFEXT_START(2),
1350 UA_FIXUP_BFEXT_END(2)) |
1351 jit_x1_fnop();
1352 else
1353 frag.insn[n++] =
1354 jit_x0_bfextu(
1355 rd, rd,
1356 UA_FIXUP_BFEXT_START(2),
1357 UA_FIXUP_BFEXT_END(2)) |
1358 jit_x1_fnop();
1359 }
1360
1361 frag.insn[n++] = jit_x0_fnop() | jit_x1_iret();
1362 }
1363
1364 /* Max JIT bundle count is 14. */
1365 WARN_ON(n > 14);
1366
1367 if (!unexpected) {
1368 int status = 0;
1369 int idx = (regs->pc >> 3) &
1370 ((1ULL << (PAGE_SHIFT - UNALIGN_JIT_SHIFT)) - 1);
1371
1372 frag.pc = regs->pc;
1373 frag.bundle = bundle;
1374
1375 if (unaligned_printk) {
1376 pr_info("%s/%d, Unalign fixup: pc=%lx bundle=%lx %d %d %d %d %d %d %d %d\n",
1377 current->comm, current->pid,
1378 (unsigned long)frag.pc,
1379 (unsigned long)frag.bundle,
1380 (int)alias, (int)rd, (int)ra,
1381 (int)rb, (int)bundle_2_enable,
1382 (int)y1_lr, (int)y1_br, (int)x1_add);
1383
1384 for (k = 0; k < n; k += 2)
1385 pr_info("[%d] %016llx %016llx\n",
1386 k, (unsigned long long)frag.insn[k],
1387 (unsigned long long)frag.insn[k+1]);
1388 }
1389
1390 /* Swap bundle byte order for big endian sys. */
1391#ifdef __BIG_ENDIAN
1392 frag.bundle = GX_INSN_BSWAP(frag.bundle);
1393 for (k = 0; k < n; k++)
1394 frag.insn[k] = GX_INSN_BSWAP(frag.insn[k]);
1395#endif /* __BIG_ENDIAN */
1396
1397 status = copy_to_user((void __user *)&jit_code_area[idx],
1398 &frag, sizeof(frag));
1399 if (status) {
1400 /* Fail to copy JIT into user land. send SIGSEGV. */
1401 siginfo_t info;
1402
1403 clear_siginfo(&info);
1404 info.si_signo = SIGSEGV;
1405 info.si_code = SEGV_MAPERR;
1406 info.si_addr = (void __user *)&jit_code_area[idx];
1407
1408 pr_warn("Unalign fixup: pid=%d %s jit_code_area=%llx\n",
1409 current->pid, current->comm,
1410 (unsigned long long)&jit_code_area[idx]);
1411
1412 trace_unhandled_signal("segfault in unalign fixup",
1413 regs,
1414 (unsigned long)info.si_addr,
1415 SIGSEGV);
1416 force_sig_info(info.si_signo, &info, current);
1417 return;
1418 }
1419
1420
1421 /* Do a cheaper increment, not accurate. */
1422 unaligned_fixup_count++;
1423 __flush_icache_range((unsigned long)&jit_code_area[idx],
1424 (unsigned long)&jit_code_area[idx] +
1425 sizeof(frag));
1426
1427 /* Setup SPR_EX_CONTEXT_0_0/1 for returning to user program.*/
1428 __insn_mtspr(SPR_EX_CONTEXT_0_0, regs->pc + 8);
1429 __insn_mtspr(SPR_EX_CONTEXT_0_1, PL_ICS_EX1(USER_PL, 0));
1430
1431 /* Modify pc at the start of new JIT. */
1432 regs->pc = (unsigned long)&jit_code_area[idx].insn[0];
1433 /* Set ICS in SPR_EX_CONTEXT_K_1. */
1434 regs->ex1 = PL_ICS_EX1(USER_PL, 1);
1435 }
1436}
1437
1438
1439/*
1440 * C function to generate unalign data JIT. Called from unalign data
1441 * interrupt handler.
1442 *
1443 * First check if unalign fix is disabled or exception did not not come from
1444 * user space or sp register points to unalign address, if true, generate a
1445 * SIGBUS. Then map a page into user space as JIT area if it is not mapped
1446 * yet. Genenerate JIT code by calling jit_bundle_gen(). After that return
1447 * back to exception handler.
1448 *
1449 * The exception handler will "iret" to new generated JIT code after
1450 * restoring caller saved registers. In theory, the JIT code will perform
1451 * another "iret" to resume user's program.
1452 */
1453
1454void do_unaligned(struct pt_regs *regs, int vecnum)
1455{
1456 tilegx_bundle_bits __user *pc;
1457 tilegx_bundle_bits bundle;
1458 struct thread_info *info = current_thread_info();
1459 int align_ctl;
1460
1461 /* Checks the per-process unaligned JIT flags */
1462 align_ctl = unaligned_fixup;
1463 switch (task_thread_info(current)->align_ctl) {
1464 case PR_UNALIGN_NOPRINT:
1465 align_ctl = 1;
1466 break;
1467 case PR_UNALIGN_SIGBUS:
1468 align_ctl = 0;
1469 break;
1470 }
1471
1472 /* Enable iterrupt in order to access user land. */
1473 local_irq_enable();
1474
1475 /*
1476 * The fault came from kernel space. Two choices:
1477 * (a) unaligned_fixup < 1, we will first call get/put_user fixup
1478 * to return -EFAULT. If no fixup, simply panic the kernel.
1479 * (b) unaligned_fixup >=1, we will try to fix the unaligned access
1480 * if it was triggered by get_user/put_user() macros. Panic the
1481 * kernel if it is not fixable.
1482 */
1483
1484 if (EX1_PL(regs->ex1) != USER_PL) {
1485
1486 if (align_ctl < 1) {
1487 unaligned_fixup_count++;
1488 /* If exception came from kernel, try fix it up. */
1489 if (fixup_exception(regs)) {
1490 if (unaligned_printk)
1491 pr_info("Unalign fixup: %d %llx @%llx\n",
1492 (int)unaligned_fixup,
1493 (unsigned long long)regs->ex1,
1494 (unsigned long long)regs->pc);
1495 } else {
1496 /* Not fixable. Go panic. */
1497 panic("Unalign exception in Kernel. pc=%lx",
1498 regs->pc);
1499 }
1500 } else {
1501 /*
1502 * Try to fix the exception. If we can't, panic the
1503 * kernel.
1504 */
1505 bundle = GX_INSN_BSWAP(
1506 *((tilegx_bundle_bits *)(regs->pc)));
1507 jit_bundle_gen(regs, bundle, align_ctl);
1508 }
1509 return;
1510 }
1511
1512 /*
1513 * Fault came from user with ICS or stack is not aligned.
1514 * If so, we will trigger SIGBUS.
1515 */
1516 if ((regs->sp & 0x7) || (regs->ex1) || (align_ctl < 0)) {
1517 siginfo_t info;
1518
1519 clear_siginfo(&info);
1520 info.si_signo = SIGBUS;
1521 info.si_code = BUS_ADRALN;
1522 info.si_addr = (unsigned char __user *)0;
1523
1524 if (unaligned_printk)
1525 pr_info("Unalign fixup: %d %llx @%llx\n",
1526 (int)unaligned_fixup,
1527 (unsigned long long)regs->ex1,
1528 (unsigned long long)regs->pc);
1529
1530 unaligned_fixup_count++;
1531
1532 trace_unhandled_signal("unaligned fixup trap", regs, 0, SIGBUS);
1533 force_sig_info(info.si_signo, &info, current);
1534 return;
1535 }
1536
1537
1538 /* Read the bundle caused the exception! */
1539 pc = (tilegx_bundle_bits __user *)(regs->pc);
1540 if (get_user(bundle, pc) != 0) {
1541 /* Probably never be here since pc is valid user address.*/
1542 siginfo_t info;
1543
1544 clear_siginfo(&info);
1545 info.si_signo = SIGSEGV;
1546 info.si_code = SEGV_MAPERR;
1547 info.si_addr = (void __user *)pc;
1548
1549 pr_err("Couldn't read instruction at %p trying to step\n", pc);
1550 trace_unhandled_signal("segfault in unalign fixup", regs,
1551 (unsigned long)info.si_addr, SIGSEGV);
1552 force_sig_info(info.si_signo, &info, current);
1553 return;
1554 }
1555
1556 if (!info->unalign_jit_base) {
1557 void __user *user_page;
1558
1559 /*
1560 * Allocate a page in userland.
1561 * For 64-bit processes we try to place the mapping far
1562 * from anything else that might be going on (specifically
1563 * 64 GB below the top of the user address space). If it
1564 * happens not to be possible to put it there, it's OK;
1565 * the kernel will choose another location and we'll
1566 * remember it for later.
1567 */
1568 if (is_compat_task())
1569 user_page = NULL;
1570 else
1571 user_page = (void __user *)(TASK_SIZE - (1UL << 36)) +
1572 (current->pid << PAGE_SHIFT);
1573
1574 user_page = (void __user *) vm_mmap(NULL,
1575 (unsigned long)user_page,
1576 PAGE_SIZE,
1577 PROT_EXEC | PROT_READ |
1578 PROT_WRITE,
1579#ifdef CONFIG_HOMECACHE
1580 MAP_CACHE_HOME_TASK |
1581#endif
1582 MAP_PRIVATE |
1583 MAP_ANONYMOUS,
1584 0);
1585
1586 if (IS_ERR((void __force *)user_page)) {
1587 pr_err("Out of kernel pages trying do_mmap\n");
1588 return;
1589 }
1590
1591 /* Save the address in the thread_info struct */
1592 info->unalign_jit_base = user_page;
1593 if (unaligned_printk)
1594 pr_info("Unalign bundle: %d:%d, allocate page @%llx\n",
1595 raw_smp_processor_id(), current->pid,
1596 (unsigned long long)user_page);
1597 }
1598
1599 /* Generate unalign JIT */
1600 jit_bundle_gen(regs, GX_INSN_BSWAP(bundle), align_ctl);
1601}
1602
1603#endif /* __tilegx__ */
diff --git a/arch/tile/kernel/usb.c b/arch/tile/kernel/usb.c
deleted file mode 100644
index 9f1e05e12255..000000000000
--- a/arch/tile/kernel/usb.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Register the Tile-Gx USB interfaces as platform devices.
15 *
16 * The actual USB driver is just some glue (in
17 * drivers/usb/host/[eo]hci-tilegx.c) which makes the registers available
18 * to the standard kernel EHCI and OHCI drivers.
19 */
20
21#include <linux/dma-mapping.h>
22#include <linux/platform_device.h>
23#include <linux/usb/tilegx.h>
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/types.h>
27
28static u64 ehci_dmamask = DMA_BIT_MASK(32);
29
30#define USB_HOST_DEF(unit, type, dmamask) \
31 static struct \
32 tilegx_usb_platform_data tilegx_usb_platform_data_ ## type ## \
33 hci ## unit = { \
34 .dev_index = unit, \
35 }; \
36 \
37 static struct platform_device tilegx_usb_ ## type ## hci ## unit = { \
38 .name = "tilegx-" #type "hci", \
39 .id = unit, \
40 .dev = { \
41 .dma_mask = dmamask, \
42 .coherent_dma_mask = DMA_BIT_MASK(32), \
43 .platform_data = \
44 &tilegx_usb_platform_data_ ## type ## hci ## \
45 unit, \
46 }, \
47 };
48
49USB_HOST_DEF(0, e, &ehci_dmamask)
50USB_HOST_DEF(0, o, NULL)
51USB_HOST_DEF(1, e, &ehci_dmamask)
52USB_HOST_DEF(1, o, NULL)
53
54#undef USB_HOST_DEF
55
56static struct platform_device *tilegx_usb_devices[] __initdata = {
57 &tilegx_usb_ehci0,
58 &tilegx_usb_ehci1,
59 &tilegx_usb_ohci0,
60 &tilegx_usb_ohci1,
61};
62
63/** Add our set of possible USB devices. */
64static int __init tilegx_usb_init(void)
65{
66 platform_add_devices(tilegx_usb_devices,
67 ARRAY_SIZE(tilegx_usb_devices));
68
69 return 0;
70}
71arch_initcall(tilegx_usb_init);
diff --git a/arch/tile/kernel/vdso.c b/arch/tile/kernel/vdso.c
deleted file mode 100644
index 5bc51d7dfdcb..000000000000
--- a/arch/tile/kernel/vdso.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/binfmts.h>
16#include <linux/compat.h>
17#include <linux/elf.h>
18#include <linux/mm.h>
19#include <linux/pagemap.h>
20
21#include <asm/vdso.h>
22#include <asm/mman.h>
23#include <asm/sections.h>
24
25#include <arch/sim.h>
26
27/* The alignment of the vDSO. */
28#define VDSO_ALIGNMENT PAGE_SIZE
29
30
31static unsigned int vdso_pages;
32static struct page **vdso_pagelist;
33
34#ifdef CONFIG_COMPAT
35static unsigned int vdso32_pages;
36static struct page **vdso32_pagelist;
37#endif
38static int vdso_ready;
39
40/*
41 * The vdso data page.
42 */
43static union {
44 struct vdso_data data;
45 u8 page[PAGE_SIZE];
46} vdso_data_store __page_aligned_data;
47
48struct vdso_data *vdso_data = &vdso_data_store.data;
49
50static unsigned int __read_mostly vdso_enabled = 1;
51
52static struct page **vdso_setup(void *vdso_kbase, unsigned int pages)
53{
54 int i;
55 struct page **pagelist;
56
57 pagelist = kzalloc(sizeof(struct page *) * (pages + 1), GFP_KERNEL);
58 BUG_ON(pagelist == NULL);
59 for (i = 0; i < pages - 1; i++) {
60 struct page *pg = virt_to_page(vdso_kbase + i*PAGE_SIZE);
61 ClearPageReserved(pg);
62 pagelist[i] = pg;
63 }
64 pagelist[pages - 1] = virt_to_page(vdso_data);
65 pagelist[pages] = NULL;
66
67 return pagelist;
68}
69
70static int __init vdso_init(void)
71{
72 int data_pages = sizeof(vdso_data_store) >> PAGE_SHIFT;
73
74 /*
75 * We can disable vDSO support generally, but we need to retain
76 * one page to support the two-bundle (16-byte) rt_sigreturn path.
77 */
78 if (!vdso_enabled) {
79 size_t offset = (unsigned long)&__vdso_rt_sigreturn;
80 static struct page *sigret_page;
81 sigret_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
82 BUG_ON(sigret_page == NULL);
83 vdso_pagelist = &sigret_page;
84 vdso_pages = 1;
85 BUG_ON(offset >= PAGE_SIZE);
86 memcpy(page_address(sigret_page) + offset,
87 vdso_start + offset, 16);
88#ifdef CONFIG_COMPAT
89 vdso32_pages = vdso_pages;
90 vdso32_pagelist = vdso_pagelist;
91#endif
92 vdso_ready = 1;
93 return 0;
94 }
95
96 vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
97 vdso_pages += data_pages;
98 vdso_pagelist = vdso_setup(vdso_start, vdso_pages);
99
100#ifdef CONFIG_COMPAT
101 vdso32_pages = (vdso32_end - vdso32_start) >> PAGE_SHIFT;
102 vdso32_pages += data_pages;
103 vdso32_pagelist = vdso_setup(vdso32_start, vdso32_pages);
104#endif
105
106 smp_wmb();
107 vdso_ready = 1;
108
109 return 0;
110}
111arch_initcall(vdso_init);
112
113const char *arch_vma_name(struct vm_area_struct *vma)
114{
115 if (vma->vm_mm && vma->vm_start == VDSO_BASE)
116 return "[vdso]";
117#ifndef __tilegx__
118 if (vma->vm_start == MEM_USER_INTRPT)
119 return "[intrpt]";
120#endif
121 return NULL;
122}
123
124int setup_vdso_pages(void)
125{
126 struct page **pagelist;
127 unsigned long pages;
128 struct mm_struct *mm = current->mm;
129 unsigned long vdso_base = 0;
130 int retval = 0;
131
132 if (!vdso_ready)
133 return 0;
134
135 mm->context.vdso_base = 0;
136
137 pagelist = vdso_pagelist;
138 pages = vdso_pages;
139#ifdef CONFIG_COMPAT
140 if (is_compat_task()) {
141 pagelist = vdso32_pagelist;
142 pages = vdso32_pages;
143 }
144#endif
145
146 /*
147 * vDSO has a problem and was disabled, just don't "enable" it for the
148 * process.
149 */
150 if (pages == 0)
151 return 0;
152
153 vdso_base = get_unmapped_area(NULL, vdso_base,
154 (pages << PAGE_SHIFT) +
155 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
156 0, 0);
157 if (IS_ERR_VALUE(vdso_base)) {
158 retval = vdso_base;
159 return retval;
160 }
161
162 /* Add required alignment. */
163 vdso_base = ALIGN(vdso_base, VDSO_ALIGNMENT);
164
165 /*
166 * Put vDSO base into mm struct. We need to do this before calling
167 * install_special_mapping or the perf counter mmap tracking code
168 * will fail to recognise it as a vDSO (since arch_vma_name fails).
169 */
170 mm->context.vdso_base = vdso_base;
171
172 /*
173 * our vma flags don't have VM_WRITE so by default, the process isn't
174 * allowed to write those pages.
175 * gdb can break that with ptrace interface, and thus trigger COW on
176 * those pages but it's then your responsibility to never do that on
177 * the "data" page of the vDSO or you'll stop getting kernel updates
178 * and your nice userland gettimeofday will be totally dead.
179 * It's fine to use that for setting breakpoints in the vDSO code
180 * pages though
181 */
182 retval = install_special_mapping(mm, vdso_base,
183 pages << PAGE_SHIFT,
184 VM_READ|VM_EXEC |
185 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
186 pagelist);
187 if (retval)
188 mm->context.vdso_base = 0;
189
190 return retval;
191}
192
193static __init int vdso_func(char *s)
194{
195 return kstrtouint(s, 0, &vdso_enabled);
196}
197__setup("vdso=", vdso_func);
diff --git a/arch/tile/kernel/vdso/Makefile b/arch/tile/kernel/vdso/Makefile
deleted file mode 100644
index b596a7396382..000000000000
--- a/arch/tile/kernel/vdso/Makefile
+++ /dev/null
@@ -1,117 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2# Symbols present in the vdso
3vdso-syms = rt_sigreturn gettimeofday
4
5# Files to link into the vdso
6obj-vdso = $(patsubst %, v%.o, $(vdso-syms))
7
8# Build rules
9targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds vdso-dummy.o
10obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
11
12# vdso32 is only for tilegx -m32 compat task.
13VDSO32-$(CONFIG_COMPAT) := y
14
15obj-y += vdso.o vdso-syms.o
16obj-$(VDSO32-y) += vdso32.o
17CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
18
19# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
20CFLAGS_REMOVE_vdso.o = -pg
21CFLAGS_REMOVE_vdso32.o = -pg
22CFLAGS_REMOVE_vrt_sigreturn.o = -pg
23CFLAGS_REMOVE_vrt_sigreturn32.o = -pg
24CFLAGS_REMOVE_vgettimeofday.o = -pg
25CFLAGS_REMOVE_vgettimeofday32.o = -pg
26
27ifdef CONFIG_FEEDBACK_COLLECT
28# vDSO code runs in userspace, not collecting feedback data.
29CFLAGS_REMOVE_vdso.o = -ffeedback-generate
30CFLAGS_REMOVE_vdso32.o = -ffeedback-generate
31CFLAGS_REMOVE_vrt_sigreturn.o = -ffeedback-generate
32CFLAGS_REMOVE_vrt_sigreturn32.o = -ffeedback-generate
33CFLAGS_REMOVE_vgettimeofday.o = -ffeedback-generate
34CFLAGS_REMOVE_vgettimeofday32.o = -ffeedback-generate
35endif
36
37# Disable gcov profiling for VDSO code
38GCOV_PROFILE := n
39
40# Force dependency
41$(obj)/vdso.o: $(obj)/vdso.so
42
43# link rule for the .so file, .lds has to be first
44SYSCFLAGS_vdso.so.dbg = $(c_flags)
45$(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso) FORCE
46 $(call if_changed,vdsold)
47
48# We also create a special relocatable object that should mirror the symbol
49# table and layout of the linked DSO. With ld -R we can then refer to
50# these symbols in the kernel code rather than hand-coded addresses.
51
52SYSCFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
53 $(call cc-ldoption, -Wl$(comma)--hash-style=both)
54SYSCFLAGS_vdso_dummy.o = -r
55$(obj)/vdso-dummy.o: $(src)/vdso.lds $(obj)/vrt_sigreturn.o FORCE
56 $(call if_changed,vdsold)
57
58LDFLAGS_vdso-syms.o := -r -R
59$(obj)/vdso-syms.o: $(obj)/vdso-dummy.o FORCE
60 $(call if_changed,ld)
61
62# strip rule for the .so file
63$(obj)/%.so: OBJCOPYFLAGS := -S
64$(obj)/%.so: $(obj)/%.so.dbg FORCE
65 $(call if_changed,objcopy)
66
67# actual build commands
68# The DSO images are built using a special linker script
69# Add -lgcc so tilepro gets static muldi3 and lshrdi3 definitions.
70# Make sure only to export the intended __vdso_xxx symbol offsets.
71quiet_cmd_vdsold = VDSOLD $@
72 cmd_vdsold = $(CC) $(KCFLAGS) -nostdlib $(SYSCFLAGS_$(@F)) \
73 -Wl,-T,$(filter-out FORCE,$^) -o $@.tmp -lgcc && \
74 $(CROSS_COMPILE)objcopy \
75 $(patsubst %, -G __vdso_%, $(vdso-syms)) $@.tmp $@
76
77# install commands for the unstripped file
78quiet_cmd_vdso_install = INSTALL $@
79 cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
80
81vdso.so: $(obj)/vdso.so.dbg
82 @mkdir -p $(MODLIB)/vdso
83 $(call cmd,vdso_install)
84
85vdso32.so: $(obj)/vdso32.so.dbg
86 $(call cmd,vdso_install)
87
88vdso_install: vdso.so
89vdso32_install: vdso32.so
90
91
92KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS))
93KBUILD_AFLAGS_32 += -m32 -s
94KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS))
95KBUILD_CFLAGS_32 += -m32 -fPIC -shared
96
97obj-vdso32 = $(patsubst %, v%32.o, $(vdso-syms))
98
99targets += $(obj-vdso32) vdso32.so vdso32.so.dbg
100obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32))
101
102$(obj-vdso32:%=%): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
103$(obj-vdso32:%=%): KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
104
105$(obj)/vgettimeofday32.o: $(obj)/vgettimeofday.c FORCE
106 $(call if_changed_rule,cc_o_c)
107
108$(obj)/vrt_sigreturn32.o: $(obj)/vrt_sigreturn.S FORCE
109 $(call if_changed,as_o_S)
110
111# Force dependency
112$(obj)/vdso32.o: $(obj)/vdso32.so
113
114SYSCFLAGS_vdso32.so.dbg = -m32 -shared -s -Wl,-soname=linux-vdso32.so.1 \
115 $(call cc-ldoption, -Wl$(comma)--hash-style=both)
116$(obj)/vdso32.so.dbg: $(src)/vdso.lds $(obj-vdso32) FORCE
117 $(call if_changed,vdsold)
diff --git a/arch/tile/kernel/vdso/vdso.S b/arch/tile/kernel/vdso/vdso.S
deleted file mode 100644
index 3467adb41630..000000000000
--- a/arch/tile/kernel/vdso/vdso.S
+++ /dev/null
@@ -1,28 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/init.h>
16#include <linux/linkage.h>
17#include <asm/page.h>
18
19 __PAGE_ALIGNED_DATA
20
21 .global vdso_start, vdso_end
22 .align PAGE_SIZE
23vdso_start:
24 .incbin "arch/tile/kernel/vdso/vdso.so"
25 .align PAGE_SIZE
26vdso_end:
27
28 .previous
diff --git a/arch/tile/kernel/vdso/vdso.lds.S b/arch/tile/kernel/vdso/vdso.lds.S
deleted file mode 100644
index 731529f3f06f..000000000000
--- a/arch/tile/kernel/vdso/vdso.lds.S
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#define VDSO_VERSION_STRING LINUX_2.6
16
17
18OUTPUT_ARCH(tile)
19
20/* The ELF entry point can be used to set the AT_SYSINFO value. */
21ENTRY(__vdso_rt_sigreturn);
22
23
24SECTIONS
25{
26 . = SIZEOF_HEADERS;
27
28 .hash : { *(.hash) } :text
29 .gnu.hash : { *(.gnu.hash) }
30 .dynsym : { *(.dynsym) }
31 .dynstr : { *(.dynstr) }
32 .gnu.version : { *(.gnu.version) }
33 .gnu.version_d : { *(.gnu.version_d) }
34 .gnu.version_r : { *(.gnu.version_r) }
35
36 .note : { *(.note.*) } :text :note
37 .dynamic : { *(.dynamic) } :text :dynamic
38
39 .eh_frame_hdr : { *(.eh_frame_hdr) } :text :eh_frame_hdr
40 .eh_frame : { KEEP (*(.eh_frame)) } :text
41
42 .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
43
44 /*
45 * This linker script is used both with -r and with -shared.
46 * For the layouts to match, we need to skip more than enough
47 * space for the dynamic symbol table et al. If this amount
48 * is insufficient, ld -shared will barf. Just increase it here.
49 */
50 . = 0x1000;
51 .text : { *(.text .text.*) } :text
52
53 .data : {
54 *(.got.plt) *(.got)
55 *(.data .data.* .gnu.linkonce.d.*)
56 *(.dynbss)
57 *(.bss .bss.* .gnu.linkonce.b.*)
58 }
59}
60
61
62/*
63 * We must supply the ELF program headers explicitly to get just one
64 * PT_LOAD segment, and set the flags explicitly to make segments read-only.
65 */
66PHDRS
67{
68 text PT_LOAD FLAGS(5) FILEHDR PHDRS; /* PF_R|PF_X */
69 dynamic PT_DYNAMIC FLAGS(4); /* PF_R */
70 note PT_NOTE FLAGS(4); /* PF_R */
71 eh_frame_hdr PT_GNU_EH_FRAME;
72}
73
74
75/*
76 * This controls what userland symbols we export from the vDSO.
77 */
78VERSION
79{
80 VDSO_VERSION_STRING {
81 global:
82 __vdso_rt_sigreturn;
83 __vdso_gettimeofday;
84 gettimeofday;
85 __vdso_clock_gettime;
86 clock_gettime;
87 local:*;
88 };
89}
diff --git a/arch/tile/kernel/vdso/vdso32.S b/arch/tile/kernel/vdso/vdso32.S
deleted file mode 100644
index 1d1ac3257e11..000000000000
--- a/arch/tile/kernel/vdso/vdso32.S
+++ /dev/null
@@ -1,28 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/init.h>
16#include <linux/linkage.h>
17#include <asm/page.h>
18
19 __PAGE_ALIGNED_DATA
20
21 .global vdso32_start, vdso32_end
22 .align PAGE_SIZE
23vdso32_start:
24 .incbin "arch/tile/kernel/vdso/vdso32.so"
25 .align PAGE_SIZE
26vdso32_end:
27
28 .previous
diff --git a/arch/tile/kernel/vdso/vgettimeofday.c b/arch/tile/kernel/vdso/vgettimeofday.c
deleted file mode 100644
index e63310c49742..000000000000
--- a/arch/tile/kernel/vdso/vgettimeofday.c
+++ /dev/null
@@ -1,198 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#define VDSO_BUILD /* avoid some shift warnings for -m32 in <asm/page.h> */
16#include <linux/time.h>
17#include <asm/timex.h>
18#include <asm/unistd.h>
19#include <asm/vdso.h>
20
21#if CHIP_HAS_SPLIT_CYCLE()
22static inline cycles_t get_cycles_inline(void)
23{
24 unsigned int high = __insn_mfspr(SPR_CYCLE_HIGH);
25 unsigned int low = __insn_mfspr(SPR_CYCLE_LOW);
26 unsigned int high2 = __insn_mfspr(SPR_CYCLE_HIGH);
27
28 while (unlikely(high != high2)) {
29 low = __insn_mfspr(SPR_CYCLE_LOW);
30 high = high2;
31 high2 = __insn_mfspr(SPR_CYCLE_HIGH);
32 }
33
34 return (((cycles_t)high) << 32) | low;
35}
36#define get_cycles get_cycles_inline
37#endif
38
39struct syscall_return_value {
40 long value;
41 long error;
42};
43
44/*
45 * Find out the vDSO data page address in the process address space.
46 */
47inline unsigned long get_datapage(void)
48{
49 unsigned long ret;
50
51 /* vdso data page located in the 2nd vDSO page. */
52 asm volatile ("lnk %0" : "=r"(ret));
53 ret &= ~(PAGE_SIZE - 1);
54 ret += PAGE_SIZE;
55
56 return ret;
57}
58
59static inline u64 vgetsns(struct vdso_data *vdso)
60{
61 return ((get_cycles() - vdso->cycle_last) & vdso->mask) * vdso->mult;
62}
63
64static inline int do_realtime(struct vdso_data *vdso, struct timespec *ts)
65{
66 unsigned count;
67 u64 ns;
68
69 do {
70 count = raw_read_seqcount_begin(&vdso->tb_seq);
71 ts->tv_sec = vdso->wall_time_sec;
72 ns = vdso->wall_time_snsec;
73 ns += vgetsns(vdso);
74 ns >>= vdso->shift;
75 } while (unlikely(read_seqcount_retry(&vdso->tb_seq, count)));
76
77 ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns);
78 ts->tv_nsec = ns;
79
80 return 0;
81}
82
83static inline int do_monotonic(struct vdso_data *vdso, struct timespec *ts)
84{
85 unsigned count;
86 u64 ns;
87
88 do {
89 count = raw_read_seqcount_begin(&vdso->tb_seq);
90 ts->tv_sec = vdso->monotonic_time_sec;
91 ns = vdso->monotonic_time_snsec;
92 ns += vgetsns(vdso);
93 ns >>= vdso->shift;
94 } while (unlikely(read_seqcount_retry(&vdso->tb_seq, count)));
95
96 ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns);
97 ts->tv_nsec = ns;
98
99 return 0;
100}
101
102static inline int do_realtime_coarse(struct vdso_data *vdso,
103 struct timespec *ts)
104{
105 unsigned count;
106
107 do {
108 count = raw_read_seqcount_begin(&vdso->tb_seq);
109 ts->tv_sec = vdso->wall_time_coarse_sec;
110 ts->tv_nsec = vdso->wall_time_coarse_nsec;
111 } while (unlikely(read_seqcount_retry(&vdso->tb_seq, count)));
112
113 return 0;
114}
115
116static inline int do_monotonic_coarse(struct vdso_data *vdso,
117 struct timespec *ts)
118{
119 unsigned count;
120
121 do {
122 count = raw_read_seqcount_begin(&vdso->tb_seq);
123 ts->tv_sec = vdso->monotonic_time_coarse_sec;
124 ts->tv_nsec = vdso->monotonic_time_coarse_nsec;
125 } while (unlikely(read_seqcount_retry(&vdso->tb_seq, count)));
126
127 return 0;
128}
129
130struct syscall_return_value __vdso_gettimeofday(struct timeval *tv,
131 struct timezone *tz)
132{
133 struct syscall_return_value ret = { 0, 0 };
134 unsigned count;
135 struct vdso_data *vdso = (struct vdso_data *)get_datapage();
136
137 /* The use of the timezone is obsolete, normally tz is NULL. */
138 if (unlikely(tz != NULL)) {
139 do {
140 count = raw_read_seqcount_begin(&vdso->tz_seq);
141 tz->tz_minuteswest = vdso->tz_minuteswest;
142 tz->tz_dsttime = vdso->tz_dsttime;
143 } while (unlikely(read_seqcount_retry(&vdso->tz_seq, count)));
144 }
145
146 if (unlikely(tv == NULL))
147 return ret;
148
149 do_realtime(vdso, (struct timespec *)tv);
150 tv->tv_usec /= 1000;
151
152 return ret;
153}
154
155int gettimeofday(struct timeval *tv, struct timezone *tz)
156 __attribute__((weak, alias("__vdso_gettimeofday")));
157
158static struct syscall_return_value vdso_fallback_gettime(long clock,
159 struct timespec *ts)
160{
161 struct syscall_return_value ret;
162 __asm__ __volatile__ (
163 "swint1"
164 : "=R00" (ret.value), "=R01" (ret.error)
165 : "R10" (__NR_clock_gettime), "R00" (clock), "R01" (ts)
166 : "r2", "r3", "r4", "r5", "r6", "r7",
167 "r8", "r9", "r11", "r12", "r13", "r14", "r15",
168 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
169 "r24", "r25", "r26", "r27", "r28", "r29", "memory");
170 return ret;
171}
172
173struct syscall_return_value __vdso_clock_gettime(clockid_t clock,
174 struct timespec *ts)
175{
176 struct vdso_data *vdso = (struct vdso_data *)get_datapage();
177 struct syscall_return_value ret = { 0, 0 };
178
179 switch (clock) {
180 case CLOCK_REALTIME:
181 do_realtime(vdso, ts);
182 return ret;
183 case CLOCK_MONOTONIC:
184 do_monotonic(vdso, ts);
185 return ret;
186 case CLOCK_REALTIME_COARSE:
187 do_realtime_coarse(vdso, ts);
188 return ret;
189 case CLOCK_MONOTONIC_COARSE:
190 do_monotonic_coarse(vdso, ts);
191 return ret;
192 default:
193 return vdso_fallback_gettime(clock, ts);
194 }
195}
196
197int clock_gettime(clockid_t clock, struct timespec *ts)
198 __attribute__((weak, alias("__vdso_clock_gettime")));
diff --git a/arch/tile/kernel/vdso/vrt_sigreturn.S b/arch/tile/kernel/vdso/vrt_sigreturn.S
deleted file mode 100644
index 6326caf4a039..000000000000
--- a/arch/tile/kernel/vdso/vrt_sigreturn.S
+++ /dev/null
@@ -1,30 +0,0 @@
1/*
2 * Copyright 2012 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/linkage.h>
16#include <arch/abi.h>
17#include <asm/unistd.h>
18
19/*
20 * Note that libc has a copy of this function that it uses to compare
21 * against the PC when a stack backtrace ends, so if this code is
22 * changed, the libc implementation(s) should also be updated.
23 */
24ENTRY(__vdso_rt_sigreturn)
25 moveli TREG_SYSCALL_NR_NAME, __NR_rt_sigreturn
26 swint1
27 /* We don't use ENDPROC to avoid tagging this symbol as FUNC,
28 * which confuses the perf tool.
29 */
30 END(__vdso_rt_sigreturn)
diff --git a/arch/tile/kernel/vmlinux.lds.S b/arch/tile/kernel/vmlinux.lds.S
deleted file mode 100644
index 3558d981e336..000000000000
--- a/arch/tile/kernel/vmlinux.lds.S
+++ /dev/null
@@ -1,105 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <asm-generic/vmlinux.lds.h>
3#include <asm/page.h>
4#include <asm/cache.h>
5#include <asm/thread_info.h>
6#include <hv/hypervisor.h>
7
8/* Text loads starting from the supervisor interrupt vector address. */
9#define TEXT_OFFSET MEM_SV_START
10
11OUTPUT_ARCH(tile)
12ENTRY(_start)
13jiffies = jiffies_64;
14
15PHDRS
16{
17 intrpt PT_LOAD ;
18 text PT_LOAD ;
19 data PT_LOAD ;
20}
21SECTIONS
22{
23 /* Text is loaded with a different VA than data; start with text. */
24 #undef LOAD_OFFSET
25 #define LOAD_OFFSET TEXT_OFFSET
26
27 /* Interrupt vectors */
28 .intrpt (LOAD_OFFSET) : AT ( 0 ) /* put at the start of physical memory */
29 {
30 _text = .;
31 *(.intrpt)
32 } :intrpt =0
33
34 /* Hypervisor call vectors */
35 . = ALIGN(0x10000);
36 .hvglue : AT (ADDR(.hvglue) - LOAD_OFFSET) {
37 *(.hvglue)
38 } :NONE
39
40 /* Now the real code */
41 . = ALIGN(0x20000);
42 _stext = .;
43 .text : AT (ADDR(.text) - LOAD_OFFSET) {
44 HEAD_TEXT
45 SCHED_TEXT
46 CPUIDLE_TEXT
47 LOCK_TEXT
48 KPROBES_TEXT
49 IRQENTRY_TEXT
50 SOFTIRQENTRY_TEXT
51 __fix_text_end = .; /* tile-cpack won't rearrange before this */
52 ALIGN_FUNCTION();
53 *(.hottext*)
54 TEXT_TEXT
55 *(.text.*)
56 *(.coldtext*)
57 *(.fixup)
58 *(.gnu.warning)
59 } :text =0
60 _etext = .;
61
62 /* "Init" is divided into two areas with very different virtual addresses. */
63 INIT_TEXT_SECTION(PAGE_SIZE)
64
65 /*
66 * Some things, like the __jump_table, may contain symbol references
67 * to __exit text, so include such text in the final image if so.
68 * In that case we also override the _einittext from INIT_TEXT_SECTION.
69 */
70#ifdef CONFIG_JUMP_LABEL
71 .exit.text : {
72 EXIT_TEXT
73 _einittext = .;
74 }
75#endif
76
77 /* Now we skip back to PAGE_OFFSET for the data. */
78 . = (. - TEXT_OFFSET + PAGE_OFFSET);
79 #undef LOAD_OFFSET
80 #define LOAD_OFFSET PAGE_OFFSET
81
82 . = ALIGN(PAGE_SIZE);
83 __init_begin = .;
84 INIT_DATA_SECTION(16) :data =0
85 PERCPU_SECTION(L2_CACHE_BYTES)
86 . = ALIGN(PAGE_SIZE);
87 __init_end = .;
88
89 _sdata = .; /* Start of data section */
90 RO_DATA_SECTION(PAGE_SIZE)
91 RW_DATA_SECTION(L2_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
92 _edata = .;
93
94 EXCEPTION_TABLE(L2_CACHE_BYTES)
95 NOTES
96
97
98 BSS_SECTION(8, PAGE_SIZE, 1)
99 _end = . ;
100
101 STABS_DEBUG
102 DWARF_DEBUG
103
104 DISCARDS
105}
diff --git a/arch/tile/kvm/Kconfig b/arch/tile/kvm/Kconfig
deleted file mode 100644
index efce89a8473b..000000000000
--- a/arch/tile/kvm/Kconfig
+++ /dev/null
@@ -1,39 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2#
3# KVM configuration
4#
5
6source "virt/kvm/Kconfig"
7
8menuconfig VIRTUALIZATION
9 bool "Virtualization"
10 ---help---
11 Say Y here to get to see options for using your Linux host to run
12 other operating systems inside virtual machines (guests).
13 This option alone does not add any kernel code.
14
15 If you say N, all options in this submenu will be skipped and
16 disabled.
17
18if VIRTUALIZATION
19
20config KVM
21 tristate "Kernel-based Virtual Machine (KVM) support"
22 depends on HAVE_KVM && MODULES
23 select PREEMPT_NOTIFIERS
24 select ANON_INODES
25 select SRCU
26 ---help---
27 Support hosting paravirtualized guest machines.
28
29 This module provides access to the hardware capabilities through
30 a character device node named /dev/kvm.
31
32 To compile this as a module, choose M here: the module
33 will be called kvm.
34
35 If unsure, say N.
36
37source drivers/vhost/Kconfig
38
39endif # VIRTUALIZATION
diff --git a/arch/tile/lib/Makefile b/arch/tile/lib/Makefile
deleted file mode 100644
index 815a1fdeb2e4..000000000000
--- a/arch/tile/lib/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2#
3# Makefile for TILE-specific library files..
4#
5
6lib-y = cacheflush.o checksum.o cpumask.o delay.o uaccess.o \
7 memmove.o memcpy_$(BITS).o memchr_$(BITS).o memset_$(BITS).o \
8 strchr_$(BITS).o strlen_$(BITS).o strnlen_$(BITS).o
9
10lib-$(CONFIG_TILEGX) += memcpy_user_64.o
11lib-$(CONFIG_TILEPRO) += atomic_32.o atomic_asm_32.o
12lib-$(CONFIG_SMP) += spinlock_$(BITS).o usercopy_$(BITS).o
13
14obj-$(CONFIG_MODULES) += exports.o
15
16# The finv_buffer_remote() and copy_{to,from}_user() routines can't
17# have -pg added, since they both rely on being leaf functions.
18CFLAGS_REMOVE_cacheflush.o = -pg
19CFLAGS_REMOVE_memcpy_user_64.o = -pg
diff --git a/arch/tile/lib/atomic_32.c b/arch/tile/lib/atomic_32.c
deleted file mode 100644
index f8128800dbf5..000000000000
--- a/arch/tile/lib/atomic_32.c
+++ /dev/null
@@ -1,206 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/cache.h>
16#include <linux/delay.h>
17#include <linux/uaccess.h>
18#include <linux/module.h>
19#include <linux/mm.h>
20#include <linux/atomic.h>
21#include <arch/chip.h>
22
23/* This page is remapped on startup to be hash-for-home. */
24int atomic_locks[PAGE_SIZE / sizeof(int)] __page_aligned_bss;
25
26int *__atomic_hashed_lock(volatile void *v)
27{
28 /* NOTE: this code must match "sys_cmpxchg" in kernel/intvec_32.S */
29 /*
30 * Use bits [3, 3 + ATOMIC_HASH_SHIFT) as the lock index.
31 * Using mm works here because atomic_locks is page aligned.
32 */
33 unsigned long ptr = __insn_mm((unsigned long)v >> 1,
34 (unsigned long)atomic_locks,
35 2, (ATOMIC_HASH_SHIFT + 2) - 1);
36 return (int *)ptr;
37}
38
39#ifdef CONFIG_SMP
40/* Return whether the passed pointer is a valid atomic lock pointer. */
41static int is_atomic_lock(int *p)
42{
43 return p >= &atomic_locks[0] && p < &atomic_locks[ATOMIC_HASH_SIZE];
44}
45
46void __atomic_fault_unlock(int *irqlock_word)
47{
48 BUG_ON(!is_atomic_lock(irqlock_word));
49 BUG_ON(*irqlock_word != 1);
50 *irqlock_word = 0;
51}
52
53#endif /* CONFIG_SMP */
54
55static inline int *__atomic_setup(volatile void *v)
56{
57 /* Issue a load to the target to bring it into cache. */
58 *(volatile int *)v;
59 return __atomic_hashed_lock(v);
60}
61
62int _atomic_xchg(int *v, int n)
63{
64 return __atomic32_xchg(v, __atomic_setup(v), n).val;
65}
66EXPORT_SYMBOL(_atomic_xchg);
67
68int _atomic_xchg_add(int *v, int i)
69{
70 return __atomic32_xchg_add(v, __atomic_setup(v), i).val;
71}
72EXPORT_SYMBOL(_atomic_xchg_add);
73
74int _atomic_xchg_add_unless(int *v, int a, int u)
75{
76 /*
77 * Note: argument order is switched here since it is easier
78 * to use the first argument consistently as the "old value"
79 * in the assembly, as is done for _atomic_cmpxchg().
80 */
81 return __atomic32_xchg_add_unless(v, __atomic_setup(v), u, a).val;
82}
83EXPORT_SYMBOL(_atomic_xchg_add_unless);
84
85int _atomic_cmpxchg(int *v, int o, int n)
86{
87 return __atomic32_cmpxchg(v, __atomic_setup(v), o, n).val;
88}
89EXPORT_SYMBOL(_atomic_cmpxchg);
90
91unsigned long _atomic_fetch_or(volatile unsigned long *p, unsigned long mask)
92{
93 return __atomic32_fetch_or((int *)p, __atomic_setup(p), mask).val;
94}
95EXPORT_SYMBOL(_atomic_fetch_or);
96
97unsigned long _atomic_fetch_and(volatile unsigned long *p, unsigned long mask)
98{
99 return __atomic32_fetch_and((int *)p, __atomic_setup(p), mask).val;
100}
101EXPORT_SYMBOL(_atomic_fetch_and);
102
103unsigned long _atomic_fetch_andn(volatile unsigned long *p, unsigned long mask)
104{
105 return __atomic32_fetch_andn((int *)p, __atomic_setup(p), mask).val;
106}
107EXPORT_SYMBOL(_atomic_fetch_andn);
108
109unsigned long _atomic_fetch_xor(volatile unsigned long *p, unsigned long mask)
110{
111 return __atomic32_fetch_xor((int *)p, __atomic_setup(p), mask).val;
112}
113EXPORT_SYMBOL(_atomic_fetch_xor);
114
115
116long long _atomic64_xchg(long long *v, long long n)
117{
118 return __atomic64_xchg(v, __atomic_setup(v), n);
119}
120EXPORT_SYMBOL(_atomic64_xchg);
121
122long long _atomic64_xchg_add(long long *v, long long i)
123{
124 return __atomic64_xchg_add(v, __atomic_setup(v), i);
125}
126EXPORT_SYMBOL(_atomic64_xchg_add);
127
128long long _atomic64_xchg_add_unless(long long *v, long long a, long long u)
129{
130 /*
131 * Note: argument order is switched here since it is easier
132 * to use the first argument consistently as the "old value"
133 * in the assembly, as is done for _atomic_cmpxchg().
134 */
135 return __atomic64_xchg_add_unless(v, __atomic_setup(v), u, a);
136}
137EXPORT_SYMBOL(_atomic64_xchg_add_unless);
138
139long long _atomic64_cmpxchg(long long *v, long long o, long long n)
140{
141 return __atomic64_cmpxchg(v, __atomic_setup(v), o, n);
142}
143EXPORT_SYMBOL(_atomic64_cmpxchg);
144
145long long _atomic64_fetch_and(long long *v, long long n)
146{
147 return __atomic64_fetch_and(v, __atomic_setup(v), n);
148}
149EXPORT_SYMBOL(_atomic64_fetch_and);
150
151long long _atomic64_fetch_or(long long *v, long long n)
152{
153 return __atomic64_fetch_or(v, __atomic_setup(v), n);
154}
155EXPORT_SYMBOL(_atomic64_fetch_or);
156
157long long _atomic64_fetch_xor(long long *v, long long n)
158{
159 return __atomic64_fetch_xor(v, __atomic_setup(v), n);
160}
161EXPORT_SYMBOL(_atomic64_fetch_xor);
162
163/*
164 * If any of the atomic or futex routines hit a bad address (not in
165 * the page tables at kernel PL) this routine is called. The futex
166 * routines are never used on kernel space, and the normal atomics and
167 * bitops are never used on user space. So a fault on kernel space
168 * must be fatal, but a fault on userspace is a futex fault and we
169 * need to return -EFAULT. Note that the context this routine is
170 * invoked in is the context of the "_atomic_xxx()" routines called
171 * by the functions in this file.
172 */
173struct __get_user __atomic_bad_address(int __user *addr)
174{
175 if (unlikely(!access_ok(VERIFY_WRITE, addr, sizeof(int))))
176 panic("Bad address used for kernel atomic op: %p\n", addr);
177 return (struct __get_user) { .err = -EFAULT };
178}
179
180
181void __init __init_atomic_per_cpu(void)
182{
183 /* Validate power-of-two and "bigger than cpus" assumption */
184 BUILD_BUG_ON(ATOMIC_HASH_SIZE & (ATOMIC_HASH_SIZE-1));
185 BUG_ON(ATOMIC_HASH_SIZE < nr_cpu_ids);
186
187 /*
188 * On TILEPro we prefer to use a single hash-for-home
189 * page, since this means atomic operations are less
190 * likely to encounter a TLB fault and thus should
191 * in general perform faster. You may wish to disable
192 * this in situations where few hash-for-home tiles
193 * are configured.
194 */
195 BUG_ON((unsigned long)atomic_locks % PAGE_SIZE != 0);
196
197 /* The locks must all fit on one page. */
198 BUILD_BUG_ON(ATOMIC_HASH_SIZE * sizeof(int) > PAGE_SIZE);
199
200 /*
201 * We use the page offset of the atomic value's address as
202 * an index into atomic_locks, excluding the low 3 bits.
203 * That should not produce more indices than ATOMIC_HASH_SIZE.
204 */
205 BUILD_BUG_ON((PAGE_SIZE >> 3) > ATOMIC_HASH_SIZE);
206}
diff --git a/arch/tile/lib/atomic_asm_32.S b/arch/tile/lib/atomic_asm_32.S
deleted file mode 100644
index 94709ab41ed8..000000000000
--- a/arch/tile/lib/atomic_asm_32.S
+++ /dev/null
@@ -1,205 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Support routines for atomic operations. Each function takes:
15 *
16 * r0: address to manipulate
17 * r1: pointer to atomic lock guarding this operation (for ATOMIC_LOCK_REG)
18 * r2: new value to write, or for cmpxchg/add_unless, value to compare against
19 * r3: (cmpxchg/xchg_add_unless) new value to write or add;
20 * (atomic64 ops) high word of value to write
21 * r4/r5: (cmpxchg64/add_unless64) new value to write or add
22 *
23 * The 32-bit routines return a "struct __get_user" so that the futex code
24 * has an opportunity to return -EFAULT to the user if needed.
25 * The 64-bit routines just return a "long long" with the value,
26 * since they are only used from kernel space and don't expect to fault.
27 * Support for 16-bit ops is included in the framework but we don't provide any.
28 *
29 * Note that the caller is advised to issue a suitable L1 or L2
30 * prefetch on the address being manipulated to avoid extra stalls.
31 * In addition, the hot path is on two icache lines, and we start with
32 * a jump to the second line to make sure they are both in cache so
33 * that we never stall waiting on icache fill while holding the lock.
34 * (This doesn't work out with most 64-bit ops, since they consume
35 * too many bundles, so may take an extra i-cache stall.)
36 *
37 * These routines set the INTERRUPT_CRITICAL_SECTION bit, just
38 * like sys_cmpxchg(), so that NMIs like PERF_COUNT will not interrupt
39 * the code, just page faults.
40 *
41 * If the load or store faults in a way that can be directly fixed in
42 * the do_page_fault_ics() handler (e.g. a vmalloc reference) we fix it
43 * directly, return to the instruction that faulted, and retry it.
44 *
45 * If the load or store faults in a way that potentially requires us
46 * to release the atomic lock, then retry (e.g. a migrating PTE), we
47 * reset the PC in do_page_fault_ics() to the "tns" instruction so
48 * that on return we will reacquire the lock and restart the op. We
49 * are somewhat overloading the exception_table_entry notion by doing
50 * this, since those entries are not normally used for migrating PTEs.
51 *
52 * If the main page fault handler discovers a bad address, it will see
53 * the PC pointing to the "tns" instruction (due to the earlier
54 * exception_table_entry processing in do_page_fault_ics), and
55 * re-reset the PC to the fault handler, atomic_bad_address(), which
56 * effectively takes over from the atomic op and can either return a
57 * bad "struct __get_user" (for user addresses) or can just panic (for
58 * bad kernel addresses).
59 *
60 * Note that if the value we would store is the same as what we
61 * loaded, we bypass the store. Other platforms with true atomics can
62 * make the guarantee that a non-atomic __clear_bit(), for example,
63 * can safely race with an atomic test_and_set_bit(); this example is
64 * from bit_spinlock.h in slub_lock() / slub_unlock(). We can't do
65 * that on Tile since the "atomic" op is really just a
66 * read/modify/write, and can race with the non-atomic
67 * read/modify/write. However, if we can short-circuit the write when
68 * it is not needed, in the atomic case, we avoid the race.
69 */
70
71#include <linux/linkage.h>
72#include <asm/atomic_32.h>
73#include <asm/page.h>
74#include <asm/processor.h>
75
76 .section .text.atomic,"ax"
77ENTRY(__start_atomic_asm_code)
78
79 .macro atomic_op, name, bitwidth, body
80 .align 64
81STD_ENTRY_SECTION(__atomic\name, .text.atomic)
82 {
83 movei r24, 1
84 j 4f /* branch to second cache line */
85 }
861: {
87 .ifc \bitwidth,16
88 lh r22, r0
89 .else
90 lw r22, r0
91 addi r28, r0, 4
92 .endif
93 }
94 .ifc \bitwidth,64
95 lw r23, r28
96 .endif
97 \body /* set r24, and r25 if 64-bit */
98 {
99 seq r26, r22, r24
100 seq r27, r23, r25
101 }
102 .ifc \bitwidth,64
103 bbnst r27, 2f
104 .endif
105 bbs r26, 3f /* skip write-back if it's the same value */
1062: {
107 .ifc \bitwidth,16
108 sh r0, r24
109 .else
110 sw r0, r24
111 .endif
112 }
113 .ifc \bitwidth,64
114 sw r28, r25
115 .endif
116 mf
1173: {
118 move r0, r22
119 .ifc \bitwidth,64
120 move r1, r23
121 .else
122 move r1, zero
123 .endif
124 sw ATOMIC_LOCK_REG_NAME, zero
125 }
126 mtspr INTERRUPT_CRITICAL_SECTION, zero
127 jrp lr
1284: {
129 move ATOMIC_LOCK_REG_NAME, r1
130 mtspr INTERRUPT_CRITICAL_SECTION, r24
131 }
132#ifndef CONFIG_SMP
133 j 1b /* no atomic locks */
134#else
135 {
136 tns r21, ATOMIC_LOCK_REG_NAME
137 moveli r23, 2048 /* maximum backoff time in cycles */
138 }
139 {
140 bzt r21, 1b /* branch if lock acquired */
141 moveli r25, 32 /* starting backoff time in cycles */
142 }
1435: mtspr INTERRUPT_CRITICAL_SECTION, zero
144 mfspr r26, CYCLE_LOW /* get start point for this backoff */
1456: mfspr r22, CYCLE_LOW /* test to see if we've backed off enough */
146 sub r22, r22, r26
147 slt r22, r22, r25
148 bbst r22, 6b
149 {
150 mtspr INTERRUPT_CRITICAL_SECTION, r24
151 shli r25, r25, 1 /* double the backoff; retry the tns */
152 }
153 {
154 tns r21, ATOMIC_LOCK_REG_NAME
155 slt r26, r23, r25 /* is the proposed backoff too big? */
156 }
157 {
158 bzt r21, 1b /* branch if lock acquired */
159 mvnz r25, r26, r23
160 }
161 j 5b
162#endif
163 STD_ENDPROC(__atomic\name)
164 .ifc \bitwidth,32
165 .pushsection __ex_table,"a"
166 .align 4
167 .word 1b, __atomic\name
168 .word 2b, __atomic\name
169 .word __atomic\name, __atomic_bad_address
170 .popsection
171 .endif
172 .endm
173
174
175/*
176 * Use __atomic32 prefix to avoid collisions with GCC builtin __atomic functions.
177 */
178
179atomic_op 32_cmpxchg, 32, "seq r26, r22, r2; { bbns r26, 3f; move r24, r3 }"
180atomic_op 32_xchg, 32, "move r24, r2"
181atomic_op 32_xchg_add, 32, "add r24, r22, r2"
182atomic_op 32_xchg_add_unless, 32, \
183 "sne r26, r22, r2; { bbns r26, 3f; add r24, r22, r3 }"
184atomic_op 32_fetch_or, 32, "or r24, r22, r2"
185atomic_op 32_fetch_and, 32, "and r24, r22, r2"
186atomic_op 32_fetch_andn, 32, "nor r2, r2, zero; and r24, r22, r2"
187atomic_op 32_fetch_xor, 32, "xor r24, r22, r2"
188
189atomic_op 64_cmpxchg, 64, "{ seq r26, r22, r2; seq r27, r23, r3 }; \
190 { bbns r26, 3f; move r24, r4 }; { bbns r27, 3f; move r25, r5 }"
191atomic_op 64_xchg, 64, "{ move r24, r2; move r25, r3 }"
192atomic_op 64_xchg_add, 64, "{ add r24, r22, r2; add r25, r23, r3 }; \
193 slt_u r26, r24, r22; add r25, r25, r26"
194atomic_op 64_xchg_add_unless, 64, \
195 "{ sne r26, r22, r2; sne r27, r23, r3 }; \
196 { bbns r26, 3f; add r24, r22, r4 }; \
197 { bbns r27, 3f; add r25, r23, r5 }; \
198 slt_u r26, r24, r22; add r25, r25, r26"
199atomic_op 64_fetch_or, 64, "{ or r24, r22, r2; or r25, r23, r3 }"
200atomic_op 64_fetch_and, 64, "{ and r24, r22, r2; and r25, r23, r3 }"
201atomic_op 64_fetch_xor, 64, "{ xor r24, r22, r2; xor r25, r23, r3 }"
202
203 jrp lr /* happy backtracer */
204
205ENTRY(__end_atomic_asm_code)
diff --git a/arch/tile/lib/cacheflush.c b/arch/tile/lib/cacheflush.c
deleted file mode 100644
index c1ebc1065fc1..000000000000
--- a/arch/tile/lib/cacheflush.c
+++ /dev/null
@@ -1,167 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/export.h>
16#include <asm/page.h>
17#include <asm/cacheflush.h>
18#include <arch/icache.h>
19#include <arch/spr_def.h>
20
21
22void __flush_icache_range(unsigned long start, unsigned long end)
23{
24 invalidate_icache((const void *)start, end - start, PAGE_SIZE);
25}
26
27
28/* Force a load instruction to issue. */
29static inline void force_load(char *p)
30{
31 *(volatile char *)p;
32}
33
34/*
35 * Flush and invalidate a VA range that is homed remotely on a single
36 * core (if "!hfh") or homed via hash-for-home (if "hfh"), waiting
37 * until the memory controller holds the flushed values.
38 */
39void __attribute__((optimize("omit-frame-pointer")))
40finv_buffer_remote(void *buffer, size_t size, int hfh)
41{
42 char *p, *base;
43 size_t step_size, load_count;
44
45 /*
46 * On TILEPro the striping granularity is a fixed 8KB; on
47 * TILE-Gx it is configurable, and we rely on the fact that
48 * the hypervisor always configures maximum striping, so that
49 * bits 9 and 10 of the PA are part of the stripe function, so
50 * every 512 bytes we hit a striping boundary.
51 *
52 */
53#ifdef __tilegx__
54 const unsigned long STRIPE_WIDTH = 512;
55#else
56 const unsigned long STRIPE_WIDTH = 8192;
57#endif
58
59#ifdef __tilegx__
60 /*
61 * On TILE-Gx, we must disable the dstream prefetcher before doing
62 * a cache flush; otherwise, we could end up with data in the cache
63 * that we don't want there. Note that normally we'd do an mf
64 * after the SPR write to disabling the prefetcher, but we do one
65 * below, before any further loads, so there's no need to do it
66 * here.
67 */
68 uint_reg_t old_dstream_pf = __insn_mfspr(SPR_DSTREAM_PF);
69 __insn_mtspr(SPR_DSTREAM_PF, 0);
70#endif
71
72 /*
73 * Flush and invalidate the buffer out of the local L1/L2
74 * and request the home cache to flush and invalidate as well.
75 */
76 __finv_buffer(buffer, size);
77
78 /*
79 * Wait for the home cache to acknowledge that it has processed
80 * all the flush-and-invalidate requests. This does not mean
81 * that the flushed data has reached the memory controller yet,
82 * but it does mean the home cache is processing the flushes.
83 */
84 __insn_mf();
85
86 /*
87 * Issue a load to the last cache line, which can't complete
88 * until all the previously-issued flushes to the same memory
89 * controller have also completed. If we weren't striping
90 * memory, that one load would be sufficient, but since we may
91 * be, we also need to back up to the last load issued to
92 * another memory controller, which would be the point where
93 * we crossed a "striping" boundary (the granularity of striping
94 * across memory controllers). Keep backing up and doing this
95 * until we are before the beginning of the buffer, or have
96 * hit all the controllers.
97 *
98 * If we are flushing a hash-for-home buffer, it's even worse.
99 * Each line may be homed on a different tile, and each tile
100 * may have up to four lines that are on different
101 * controllers. So as we walk backwards, we have to touch
102 * enough cache lines to satisfy these constraints. In
103 * practice this ends up being close enough to "load from
104 * every cache line on a full memory stripe on each
105 * controller" that we simply do that, to simplify the logic.
106 *
107 * On TILE-Gx the hash-for-home function is much more complex,
108 * with the upshot being we can't readily guarantee we have
109 * hit both entries in the 128-entry AMT that were hit by any
110 * load in the entire range, so we just re-load them all.
111 * With larger buffers, we may want to consider using a hypervisor
112 * trap to issue loads directly to each hash-for-home tile for
113 * each controller (doing it from Linux would trash the TLB).
114 */
115 if (hfh) {
116 step_size = L2_CACHE_BYTES;
117#ifdef __tilegx__
118 load_count = (size + L2_CACHE_BYTES - 1) / L2_CACHE_BYTES;
119#else
120 load_count = (STRIPE_WIDTH / L2_CACHE_BYTES) *
121 (1 << CHIP_LOG_NUM_MSHIMS());
122#endif
123 } else {
124 step_size = STRIPE_WIDTH;
125 load_count = (1 << CHIP_LOG_NUM_MSHIMS());
126 }
127
128 /* Load the last byte of the buffer. */
129 p = (char *)buffer + size - 1;
130 force_load(p);
131
132 /* Bump down to the end of the previous stripe or cache line. */
133 p -= step_size;
134 p = (char *)((unsigned long)p | (step_size - 1));
135
136 /* Figure out how far back we need to go. */
137 base = p - (step_size * (load_count - 2));
138 if ((unsigned long)base < (unsigned long)buffer)
139 base = buffer;
140
141 /* Fire all the loads we need. */
142 for (; p >= base; p -= step_size)
143 force_load(p);
144
145 /*
146 * Repeat, but with finv's instead of loads, to get rid of the
147 * data we just loaded into our own cache and the old home L3.
148 * The finv's are guaranteed not to actually flush the data in
149 * the buffer back to their home, since we just read it, so the
150 * lines are clean in cache; we will only invalidate those lines.
151 */
152 p = (char *)buffer + size - 1;
153 __insn_finv(p);
154 p -= step_size;
155 p = (char *)((unsigned long)p | (step_size - 1));
156 for (; p >= base; p -= step_size)
157 __insn_finv(p);
158
159 /* Wait for these finv's (and thus the first finvs) to be done. */
160 __insn_mf();
161
162#ifdef __tilegx__
163 /* Reenable the prefetcher. */
164 __insn_mtspr(SPR_DSTREAM_PF, old_dstream_pf);
165#endif
166}
167EXPORT_SYMBOL_GPL(finv_buffer_remote);
diff --git a/arch/tile/lib/checksum.c b/arch/tile/lib/checksum.c
deleted file mode 100644
index c3ca3e64d9d9..000000000000
--- a/arch/tile/lib/checksum.c
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 * Support code for the main lib/checksum.c.
14 */
15
16#include <net/checksum.h>
17#include <linux/module.h>
18
19__wsum do_csum(const unsigned char *buff, int len)
20{
21 int odd, count;
22 unsigned long result = 0;
23
24 if (len <= 0)
25 goto out;
26 odd = 1 & (unsigned long) buff;
27 if (odd) {
28 result = (*buff << 8);
29 len--;
30 buff++;
31 }
32 count = len >> 1; /* nr of 16-bit words.. */
33 if (count) {
34 if (2 & (unsigned long) buff) {
35 result += *(const unsigned short *)buff;
36 count--;
37 len -= 2;
38 buff += 2;
39 }
40 count >>= 1; /* nr of 32-bit words.. */
41 if (count) {
42#ifdef __tilegx__
43 if (4 & (unsigned long) buff) {
44 unsigned int w = *(const unsigned int *)buff;
45 result = __insn_v2sadau(result, w, 0);
46 count--;
47 len -= 4;
48 buff += 4;
49 }
50 count >>= 1; /* nr of 64-bit words.. */
51#endif
52
53 /*
54 * This algorithm could wrap around for very
55 * large buffers, but those should be impossible.
56 */
57 BUG_ON(count >= 65530);
58
59 while (count) {
60 unsigned long w = *(const unsigned long *)buff;
61 count--;
62 buff += sizeof(w);
63#ifdef __tilegx__
64 result = __insn_v2sadau(result, w, 0);
65#else
66 result = __insn_sadah_u(result, w, 0);
67#endif
68 }
69#ifdef __tilegx__
70 if (len & 4) {
71 unsigned int w = *(const unsigned int *)buff;
72 result = __insn_v2sadau(result, w, 0);
73 buff += 4;
74 }
75#endif
76 }
77 if (len & 2) {
78 result += *(const unsigned short *) buff;
79 buff += 2;
80 }
81 }
82 if (len & 1)
83 result += *buff;
84 result = csum_long(result);
85 if (odd)
86 result = swab16(result);
87out:
88 return result;
89}
diff --git a/arch/tile/lib/cpumask.c b/arch/tile/lib/cpumask.c
deleted file mode 100644
index 75947edccb26..000000000000
--- a/arch/tile/lib/cpumask.c
+++ /dev/null
@@ -1,54 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/cpumask.h>
16#include <linux/ctype.h>
17#include <linux/errno.h>
18#include <linux/smp.h>
19#include <linux/export.h>
20
21/*
22 * Allow cropping out bits beyond the end of the array.
23 * Move to "lib" directory if more clients want to use this routine.
24 */
25int bitmap_parselist_crop(const char *bp, unsigned long *maskp, int nmaskbits)
26{
27 unsigned a, b;
28
29 bitmap_zero(maskp, nmaskbits);
30 do {
31 if (!isdigit(*bp))
32 return -EINVAL;
33 a = simple_strtoul(bp, (char **)&bp, 10);
34 b = a;
35 if (*bp == '-') {
36 bp++;
37 if (!isdigit(*bp))
38 return -EINVAL;
39 b = simple_strtoul(bp, (char **)&bp, 10);
40 }
41 if (!(a <= b))
42 return -EINVAL;
43 if (b >= nmaskbits)
44 b = nmaskbits-1;
45 while (a <= b) {
46 set_bit(a, maskp);
47 a++;
48 }
49 if (*bp == ',')
50 bp++;
51 } while (*bp != '\0' && *bp != '\n');
52 return 0;
53}
54EXPORT_SYMBOL(bitmap_parselist_crop);
diff --git a/arch/tile/lib/delay.c b/arch/tile/lib/delay.c
deleted file mode 100644
index cdacdd11d360..000000000000
--- a/arch/tile/lib/delay.c
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/module.h>
16#include <linux/delay.h>
17#include <linux/thread_info.h>
18#include <asm/timex.h>
19
20void __udelay(unsigned long usecs)
21{
22 if (usecs > ULONG_MAX / 1000) {
23 WARN_ON_ONCE(usecs > ULONG_MAX / 1000);
24 usecs = ULONG_MAX / 1000;
25 }
26 __ndelay(usecs * 1000);
27}
28EXPORT_SYMBOL(__udelay);
29
30void __ndelay(unsigned long nsecs)
31{
32 cycles_t target = get_cycles();
33 target += ns2cycles(nsecs);
34 while (get_cycles() < target)
35 cpu_relax();
36}
37EXPORT_SYMBOL(__ndelay);
38
39void __delay(unsigned long cycles)
40{
41 cycles_t target = get_cycles() + cycles;
42 while (get_cycles() < target)
43 cpu_relax();
44}
45EXPORT_SYMBOL(__delay);
diff --git a/arch/tile/lib/exports.c b/arch/tile/lib/exports.c
deleted file mode 100644
index ecce8e177e3f..000000000000
--- a/arch/tile/lib/exports.c
+++ /dev/null
@@ -1,94 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Exports from assembler code and from libtile-cc.
15 */
16
17#include <linux/module.h>
18
19/* arch/tile/lib/usercopy.S */
20#include <linux/uaccess.h>
21EXPORT_SYMBOL(clear_user_asm);
22EXPORT_SYMBOL(flush_user_asm);
23EXPORT_SYMBOL(finv_user_asm);
24
25/* arch/tile/kernel/entry.S */
26#include <linux/kernel.h>
27#include <asm/processor.h>
28EXPORT_SYMBOL(current_text_addr);
29
30/* arch/tile/kernel/head.S */
31EXPORT_SYMBOL(empty_zero_page);
32
33#ifdef CONFIG_FUNCTION_TRACER
34/* arch/tile/kernel/mcount_64.S */
35#include <asm/ftrace.h>
36EXPORT_SYMBOL(__mcount);
37#endif /* CONFIG_FUNCTION_TRACER */
38
39/* arch/tile/lib/, various memcpy files */
40EXPORT_SYMBOL(memcpy);
41EXPORT_SYMBOL(raw_copy_to_user);
42EXPORT_SYMBOL(raw_copy_from_user);
43#ifdef __tilegx__
44EXPORT_SYMBOL(raw_copy_in_user);
45#endif
46
47/* hypervisor glue */
48#include <hv/hypervisor.h>
49EXPORT_SYMBOL(hv_dev_open);
50EXPORT_SYMBOL(hv_dev_pread);
51EXPORT_SYMBOL(hv_dev_pwrite);
52EXPORT_SYMBOL(hv_dev_preada);
53EXPORT_SYMBOL(hv_dev_pwritea);
54EXPORT_SYMBOL(hv_dev_poll);
55EXPORT_SYMBOL(hv_dev_poll_cancel);
56EXPORT_SYMBOL(hv_dev_close);
57EXPORT_SYMBOL(hv_sysconf);
58EXPORT_SYMBOL(hv_confstr);
59EXPORT_SYMBOL(hv_get_rtc);
60EXPORT_SYMBOL(hv_set_rtc);
61
62/* libgcc.a */
63uint32_t __udivsi3(uint32_t dividend, uint32_t divisor);
64EXPORT_SYMBOL(__udivsi3);
65int32_t __divsi3(int32_t dividend, int32_t divisor);
66EXPORT_SYMBOL(__divsi3);
67uint64_t __udivdi3(uint64_t dividend, uint64_t divisor);
68EXPORT_SYMBOL(__udivdi3);
69int64_t __divdi3(int64_t dividend, int64_t divisor);
70EXPORT_SYMBOL(__divdi3);
71uint32_t __umodsi3(uint32_t dividend, uint32_t divisor);
72EXPORT_SYMBOL(__umodsi3);
73int32_t __modsi3(int32_t dividend, int32_t divisor);
74EXPORT_SYMBOL(__modsi3);
75uint64_t __umoddi3(uint64_t dividend, uint64_t divisor);
76EXPORT_SYMBOL(__umoddi3);
77int64_t __moddi3(int64_t dividend, int64_t divisor);
78EXPORT_SYMBOL(__moddi3);
79#ifdef __tilegx__
80typedef int TItype __attribute__((mode(TI)));
81TItype __multi3(TItype a, TItype b);
82EXPORT_SYMBOL(__multi3); /* required for gcc 7 and later */
83#else
84int64_t __muldi3(int64_t, int64_t);
85EXPORT_SYMBOL(__muldi3);
86uint64_t __lshrdi3(uint64_t, unsigned int);
87EXPORT_SYMBOL(__lshrdi3);
88uint64_t __ashrdi3(uint64_t, unsigned int);
89EXPORT_SYMBOL(__ashrdi3);
90uint64_t __ashldi3(uint64_t, unsigned int);
91EXPORT_SYMBOL(__ashldi3);
92int __ffsdi2(uint64_t);
93EXPORT_SYMBOL(__ffsdi2);
94#endif
diff --git a/arch/tile/lib/memchr_32.c b/arch/tile/lib/memchr_32.c
deleted file mode 100644
index cc3d9badf030..000000000000
--- a/arch/tile/lib/memchr_32.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18
19void *memchr(const void *s, int c, size_t n)
20{
21 const uint32_t *last_word_ptr;
22 const uint32_t *p;
23 const char *last_byte_ptr;
24 uintptr_t s_int;
25 uint32_t goal, before_mask, v, bits;
26 char *ret;
27
28 if (__builtin_expect(n == 0, 0)) {
29 /* Don't dereference any memory if the array is empty. */
30 return NULL;
31 }
32
33 /* Get an aligned pointer. */
34 s_int = (uintptr_t) s;
35 p = (const uint32_t *)(s_int & -4);
36
37 /* Create four copies of the byte for which we are looking. */
38 goal = 0x01010101 * (uint8_t) c;
39
40 /* Read the first word, but munge it so that bytes before the array
41 * will not match goal.
42 *
43 * Note that this shift count expression works because we know
44 * shift counts are taken mod 32.
45 */
46 before_mask = (1 << (s_int << 3)) - 1;
47 v = (*p | before_mask) ^ (goal & before_mask);
48
49 /* Compute the address of the last byte. */
50 last_byte_ptr = (const char *)s + n - 1;
51
52 /* Compute the address of the word containing the last byte. */
53 last_word_ptr = (const uint32_t *)((uintptr_t) last_byte_ptr & -4);
54
55 while ((bits = __insn_seqb(v, goal)) == 0) {
56 if (__builtin_expect(p == last_word_ptr, 0)) {
57 /* We already read the last word in the array,
58 * so give up.
59 */
60 return NULL;
61 }
62 v = *++p;
63 }
64
65 /* We found a match, but it might be in a byte past the end
66 * of the array.
67 */
68 ret = ((char *)p) + (__insn_ctz(bits) >> 3);
69 return (ret <= last_byte_ptr) ? ret : NULL;
70}
71EXPORT_SYMBOL(memchr);
diff --git a/arch/tile/lib/memchr_64.c b/arch/tile/lib/memchr_64.c
deleted file mode 100644
index f8196b3a950e..000000000000
--- a/arch/tile/lib/memchr_64.c
+++ /dev/null
@@ -1,69 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18#include "string-endian.h"
19
20void *memchr(const void *s, int c, size_t n)
21{
22 const uint64_t *last_word_ptr;
23 const uint64_t *p;
24 const char *last_byte_ptr;
25 uintptr_t s_int;
26 uint64_t goal, before_mask, v, bits;
27 char *ret;
28
29 if (__builtin_expect(n == 0, 0)) {
30 /* Don't dereference any memory if the array is empty. */
31 return NULL;
32 }
33
34 /* Get an aligned pointer. */
35 s_int = (uintptr_t) s;
36 p = (const uint64_t *)(s_int & -8);
37
38 /* Create eight copies of the byte for which we are looking. */
39 goal = copy_byte(c);
40
41 /* Read the first word, but munge it so that bytes before the array
42 * will not match goal.
43 */
44 before_mask = MASK(s_int);
45 v = (*p | before_mask) ^ (goal & before_mask);
46
47 /* Compute the address of the last byte. */
48 last_byte_ptr = (const char *)s + n - 1;
49
50 /* Compute the address of the word containing the last byte. */
51 last_word_ptr = (const uint64_t *)((uintptr_t) last_byte_ptr & -8);
52
53 while ((bits = __insn_v1cmpeq(v, goal)) == 0) {
54 if (__builtin_expect(p == last_word_ptr, 0)) {
55 /* We already read the last word in the array,
56 * so give up.
57 */
58 return NULL;
59 }
60 v = *++p;
61 }
62
63 /* We found a match, but it might be in a byte past the end
64 * of the array.
65 */
66 ret = ((char *)p) + (CFZ(bits) >> 3);
67 return (ret <= last_byte_ptr) ? ret : NULL;
68}
69EXPORT_SYMBOL(memchr);
diff --git a/arch/tile/lib/memcpy_32.S b/arch/tile/lib/memcpy_32.S
deleted file mode 100644
index 270f1267cd18..000000000000
--- a/arch/tile/lib/memcpy_32.S
+++ /dev/null
@@ -1,544 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <arch/chip.h>
16
17
18/*
19 * This file shares the implementation of the userspace memcpy and
20 * the kernel's memcpy, copy_to_user and copy_from_user.
21 */
22
23#include <linux/linkage.h>
24
25#define IS_MEMCPY 0
26#define IS_COPY_FROM_USER 1
27#define IS_COPY_TO_USER -1
28
29 .section .text.memcpy_common, "ax"
30 .align 64
31
32/* Use this to preface each bundle that can cause an exception so
33 * the kernel can clean up properly. The special cleanup code should
34 * not use these, since it knows what it is doing.
35 */
36#define EX \
37 .pushsection __ex_table, "a"; \
38 .align 4; \
39 .word 9f, memcpy_common_fixup; \
40 .popsection; \
41 9
42
43
44/* raw_copy_from_user takes the kernel target address in r0,
45 * the user source in r1, and the bytes to copy in r2.
46 * It returns the number of uncopiable bytes (hopefully zero) in r0.
47 */
48ENTRY(raw_copy_from_user)
49.type raw_copy_from_user, @function
50 FEEDBACK_ENTER_EXPLICIT(raw_copy_from_user, \
51 .text.memcpy_common, \
52 .Lend_memcpy_common - raw_copy_from_user)
53 { movei r29, IS_COPY_FROM_USER; j memcpy_common }
54 .size raw_copy_from_user, . - raw_copy_from_user
55
56/* raw_copy_to_user takes the user target address in r0,
57 * the kernel source in r1, and the bytes to copy in r2.
58 * It returns the number of uncopiable bytes (hopefully zero) in r0.
59 */
60ENTRY(raw_copy_to_user)
61.type raw_copy_to_user, @function
62 FEEDBACK_REENTER(raw_copy_from_user)
63 { movei r29, IS_COPY_TO_USER; j memcpy_common }
64 .size raw_copy_to_user, . - raw_copy_to_user
65
66ENTRY(memcpy)
67.type memcpy, @function
68 FEEDBACK_REENTER(raw_copy_from_user)
69 { movei r29, IS_MEMCPY }
70 .size memcpy, . - memcpy
71 /* Fall through */
72
73 .type memcpy_common, @function
74memcpy_common:
75 /* On entry, r29 holds one of the IS_* macro values from above. */
76
77
78 /* r0 is the dest, r1 is the source, r2 is the size. */
79
80 /* Save aside original dest so we can return it at the end. */
81 { sw sp, lr; move r23, r0; or r4, r0, r1 }
82
83 /* Check for an empty size. */
84 { bz r2, .Ldone; andi r4, r4, 3 }
85
86 /* Save aside original values in case of a fault. */
87 { move r24, r1; move r25, r2 }
88 move r27, lr
89
90 /* Check for an unaligned source or dest. */
91 { bnz r4, .Lcopy_unaligned_maybe_many; addli r4, r2, -256 }
92
93.Lcheck_aligned_copy_size:
94 /* If we are copying < 256 bytes, branch to simple case. */
95 { blzt r4, .Lcopy_8_check; slti_u r8, r2, 8 }
96
97 /* Copying >= 256 bytes, so jump to complex prefetching loop. */
98 { andi r6, r1, 63; j .Lcopy_many }
99
100/*
101 *
102 * Aligned 4 byte at a time copy loop
103 *
104 */
105
106.Lcopy_8_loop:
107 /* Copy two words at a time to hide load latency. */
108EX: { lw r3, r1; addi r1, r1, 4; slti_u r8, r2, 16 }
109EX: { lw r4, r1; addi r1, r1, 4 }
110EX: { sw r0, r3; addi r0, r0, 4; addi r2, r2, -4 }
111EX: { sw r0, r4; addi r0, r0, 4; addi r2, r2, -4 }
112.Lcopy_8_check:
113 { bzt r8, .Lcopy_8_loop; slti_u r4, r2, 4 }
114
115 /* Copy odd leftover word, if any. */
116 { bnzt r4, .Lcheck_odd_stragglers }
117EX: { lw r3, r1; addi r1, r1, 4 }
118EX: { sw r0, r3; addi r0, r0, 4; addi r2, r2, -4 }
119
120.Lcheck_odd_stragglers:
121 { bnz r2, .Lcopy_unaligned_few }
122
123.Ldone:
124 /* For memcpy return original dest address, else zero. */
125 { mz r0, r29, r23; jrp lr }
126
127
128/*
129 *
130 * Prefetching multiple cache line copy handler (for large transfers).
131 *
132 */
133
134 /* Copy words until r1 is cache-line-aligned. */
135.Lalign_loop:
136EX: { lw r3, r1; addi r1, r1, 4 }
137 { andi r6, r1, 63 }
138EX: { sw r0, r3; addi r0, r0, 4; addi r2, r2, -4 }
139.Lcopy_many:
140 { bnzt r6, .Lalign_loop; addi r9, r0, 63 }
141
142 { addi r3, r1, 60; andi r9, r9, -64 }
143
144 /* No need to prefetch dst, we'll just do the wh64
145 * right before we copy a line.
146 */
147EX: { lw r5, r3; addi r3, r3, 64; movei r4, 1 }
148 /* Intentionally stall for a few cycles to leave L2 cache alone. */
149 { bnzt zero, .; move r27, lr }
150EX: { lw r6, r3; addi r3, r3, 64 }
151 /* Intentionally stall for a few cycles to leave L2 cache alone. */
152 { bnzt zero, . }
153EX: { lw r7, r3; addi r3, r3, 64 }
154 /* Intentionally stall for a few cycles to leave L2 cache alone. */
155 { bz zero, .Lbig_loop2 }
156
157 /* On entry to this loop:
158 * - r0 points to the start of dst line 0
159 * - r1 points to start of src line 0
160 * - r2 >= (256 - 60), only the first time the loop trips.
161 * - r3 contains r1 + 128 + 60 [pointer to end of source line 2]
162 * This is our prefetch address. When we get near the end
163 * rather than prefetching off the end this is changed to point
164 * to some "safe" recently loaded address.
165 * - r5 contains *(r1 + 60) [i.e. last word of source line 0]
166 * - r6 contains *(r1 + 64 + 60) [i.e. last word of source line 1]
167 * - r9 contains ((r0 + 63) & -64)
168 * [start of next dst cache line.]
169 */
170
171.Lbig_loop:
172 { jal .Lcopy_line2; add r15, r1, r2 }
173
174.Lbig_loop2:
175 /* Copy line 0, first stalling until r5 is ready. */
176EX: { move r12, r5; lw r16, r1 }
177 { bz r4, .Lcopy_8_check; slti_u r8, r2, 8 }
178 /* Prefetch several lines ahead. */
179EX: { lw r5, r3; addi r3, r3, 64 }
180 { jal .Lcopy_line }
181
182 /* Copy line 1, first stalling until r6 is ready. */
183EX: { move r12, r6; lw r16, r1 }
184 { bz r4, .Lcopy_8_check; slti_u r8, r2, 8 }
185 /* Prefetch several lines ahead. */
186EX: { lw r6, r3; addi r3, r3, 64 }
187 { jal .Lcopy_line }
188
189 /* Copy line 2, first stalling until r7 is ready. */
190EX: { move r12, r7; lw r16, r1 }
191 { bz r4, .Lcopy_8_check; slti_u r8, r2, 8 }
192 /* Prefetch several lines ahead. */
193EX: { lw r7, r3; addi r3, r3, 64 }
194 /* Use up a caches-busy cycle by jumping back to the top of the
195 * loop. Might as well get it out of the way now.
196 */
197 { j .Lbig_loop }
198
199
200 /* On entry:
201 * - r0 points to the destination line.
202 * - r1 points to the source line.
203 * - r3 is the next prefetch address.
204 * - r9 holds the last address used for wh64.
205 * - r12 = WORD_15
206 * - r16 = WORD_0.
207 * - r17 == r1 + 16.
208 * - r27 holds saved lr to restore.
209 *
210 * On exit:
211 * - r0 is incremented by 64.
212 * - r1 is incremented by 64, unless that would point to a word
213 * beyond the end of the source array, in which case it is redirected
214 * to point to an arbitrary word already in the cache.
215 * - r2 is decremented by 64.
216 * - r3 is unchanged, unless it points to a word beyond the
217 * end of the source array, in which case it is redirected
218 * to point to an arbitrary word already in the cache.
219 * Redirecting is OK since if we are that close to the end
220 * of the array we will not come back to this subroutine
221 * and use the contents of the prefetched address.
222 * - r4 is nonzero iff r2 >= 64.
223 * - r9 is incremented by 64, unless it points beyond the
224 * end of the last full destination cache line, in which
225 * case it is redirected to a "safe address" that can be
226 * clobbered (sp - 64)
227 * - lr contains the value in r27.
228 */
229
230/* r26 unused */
231
232.Lcopy_line:
233 /* TODO: when r3 goes past the end, we would like to redirect it
234 * to prefetch the last partial cache line (if any) just once, for the
235 * benefit of the final cleanup loop. But we don't want to
236 * prefetch that line more than once, or subsequent prefetches
237 * will go into the RTF. But then .Lbig_loop should unconditionally
238 * branch to top of loop to execute final prefetch, and its
239 * nop should become a conditional branch.
240 */
241
242 /* We need two non-memory cycles here to cover the resources
243 * used by the loads initiated by the caller.
244 */
245 { add r15, r1, r2 }
246.Lcopy_line2:
247 { slt_u r13, r3, r15; addi r17, r1, 16 }
248
249 /* NOTE: this will stall for one cycle as L1 is busy. */
250
251 /* Fill second L1D line. */
252EX: { lw r17, r17; addi r1, r1, 48; mvz r3, r13, r1 } /* r17 = WORD_4 */
253
254 /* Prepare destination line for writing. */
255EX: { wh64 r9; addi r9, r9, 64 }
256 /* Load seven words that are L1D hits to cover wh64 L2 usage. */
257
258 /* Load the three remaining words from the last L1D line, which
259 * we know has already filled the L1D.
260 */
261EX: { lw r4, r1; addi r1, r1, 4; addi r20, r1, 16 } /* r4 = WORD_12 */
262EX: { lw r8, r1; addi r1, r1, 4; slt_u r13, r20, r15 }/* r8 = WORD_13 */
263EX: { lw r11, r1; addi r1, r1, -52; mvz r20, r13, r1 } /* r11 = WORD_14 */
264
265 /* Load the three remaining words from the first L1D line, first
266 * stalling until it has filled by "looking at" r16.
267 */
268EX: { lw r13, r1; addi r1, r1, 4; move zero, r16 } /* r13 = WORD_1 */
269EX: { lw r14, r1; addi r1, r1, 4 } /* r14 = WORD_2 */
270EX: { lw r15, r1; addi r1, r1, 8; addi r10, r0, 60 } /* r15 = WORD_3 */
271
272 /* Load second word from the second L1D line, first
273 * stalling until it has filled by "looking at" r17.
274 */
275EX: { lw r19, r1; addi r1, r1, 4; move zero, r17 } /* r19 = WORD_5 */
276
277 /* Store last word to the destination line, potentially dirtying it
278 * for the first time, which keeps the L2 busy for two cycles.
279 */
280EX: { sw r10, r12 } /* store(WORD_15) */
281
282 /* Use two L1D hits to cover the sw L2 access above. */
283EX: { lw r10, r1; addi r1, r1, 4 } /* r10 = WORD_6 */
284EX: { lw r12, r1; addi r1, r1, 4 } /* r12 = WORD_7 */
285
286 /* Fill third L1D line. */
287EX: { lw r18, r1; addi r1, r1, 4 } /* r18 = WORD_8 */
288
289 /* Store first L1D line. */
290EX: { sw r0, r16; addi r0, r0, 4; add r16, r0, r2 } /* store(WORD_0) */
291EX: { sw r0, r13; addi r0, r0, 4; andi r16, r16, -64 } /* store(WORD_1) */
292EX: { sw r0, r14; addi r0, r0, 4; slt_u r16, r9, r16 } /* store(WORD_2) */
293EX: { sw r0, r15; addi r0, r0, 4; addi r13, sp, -64 } /* store(WORD_3) */
294 /* Store second L1D line. */
295EX: { sw r0, r17; addi r0, r0, 4; mvz r9, r16, r13 }/* store(WORD_4) */
296EX: { sw r0, r19; addi r0, r0, 4 } /* store(WORD_5) */
297EX: { sw r0, r10; addi r0, r0, 4 } /* store(WORD_6) */
298EX: { sw r0, r12; addi r0, r0, 4 } /* store(WORD_7) */
299
300EX: { lw r13, r1; addi r1, r1, 4; move zero, r18 } /* r13 = WORD_9 */
301EX: { lw r14, r1; addi r1, r1, 4 } /* r14 = WORD_10 */
302EX: { lw r15, r1; move r1, r20 } /* r15 = WORD_11 */
303
304 /* Store third L1D line. */
305EX: { sw r0, r18; addi r0, r0, 4 } /* store(WORD_8) */
306EX: { sw r0, r13; addi r0, r0, 4 } /* store(WORD_9) */
307EX: { sw r0, r14; addi r0, r0, 4 } /* store(WORD_10) */
308EX: { sw r0, r15; addi r0, r0, 4 } /* store(WORD_11) */
309
310 /* Store rest of fourth L1D line. */
311EX: { sw r0, r4; addi r0, r0, 4 } /* store(WORD_12) */
312 {
313EX: sw r0, r8 /* store(WORD_13) */
314 addi r0, r0, 4
315 /* Will r2 be > 64 after we subtract 64 below? */
316 shri r4, r2, 7
317 }
318 {
319EX: sw r0, r11 /* store(WORD_14) */
320 addi r0, r0, 8
321 /* Record 64 bytes successfully copied. */
322 addi r2, r2, -64
323 }
324
325 { jrp lr; move lr, r27 }
326
327 /* Convey to the backtrace library that the stack frame is size
328 * zero, and the real return address is on the stack rather than
329 * in 'lr'.
330 */
331 { info 8 }
332
333 .align 64
334.Lcopy_unaligned_maybe_many:
335 /* Skip the setup overhead if we aren't copying many bytes. */
336 { slti_u r8, r2, 20; sub r4, zero, r0 }
337 { bnzt r8, .Lcopy_unaligned_few; andi r4, r4, 3 }
338 { bz r4, .Ldest_is_word_aligned; add r18, r1, r2 }
339
340/*
341 *
342 * unaligned 4 byte at a time copy handler.
343 *
344 */
345
346 /* Copy single bytes until r0 == 0 mod 4, so we can store words. */
347.Lalign_dest_loop:
348EX: { lb_u r3, r1; addi r1, r1, 1; addi r4, r4, -1 }
349EX: { sb r0, r3; addi r0, r0, 1; addi r2, r2, -1 }
350 { bnzt r4, .Lalign_dest_loop; andi r3, r1, 3 }
351
352 /* If source and dest are now *both* aligned, do an aligned copy. */
353 { bz r3, .Lcheck_aligned_copy_size; addli r4, r2, -256 }
354
355.Ldest_is_word_aligned:
356
357EX: { andi r8, r0, 63; lwadd_na r6, r1, 4}
358 { slti_u r9, r2, 64; bz r8, .Ldest_is_L2_line_aligned }
359
360 /* This copies unaligned words until either there are fewer
361 * than 4 bytes left to copy, or until the destination pointer
362 * is cache-aligned, whichever comes first.
363 *
364 * On entry:
365 * - r0 is the next store address.
366 * - r1 points 4 bytes past the load address corresponding to r0.
367 * - r2 >= 4
368 * - r6 is the next aligned word loaded.
369 */
370.Lcopy_unaligned_src_words:
371EX: { lwadd_na r7, r1, 4; slti_u r8, r2, 4 + 4 }
372 /* stall */
373 { dword_align r6, r7, r1; slti_u r9, r2, 64 + 4 }
374EX: { swadd r0, r6, 4; addi r2, r2, -4 }
375 { bnz r8, .Lcleanup_unaligned_words; andi r8, r0, 63 }
376 { bnzt r8, .Lcopy_unaligned_src_words; move r6, r7 }
377
378 /* On entry:
379 * - r0 is the next store address.
380 * - r1 points 4 bytes past the load address corresponding to r0.
381 * - r2 >= 4 (# of bytes left to store).
382 * - r6 is the next aligned src word value.
383 * - r9 = (r2 < 64U).
384 * - r18 points one byte past the end of source memory.
385 */
386.Ldest_is_L2_line_aligned:
387
388 {
389 /* Not a full cache line remains. */
390 bnz r9, .Lcleanup_unaligned_words
391 move r7, r6
392 }
393
394 /* r2 >= 64 */
395
396 /* Kick off two prefetches, but don't go past the end. */
397 { addi r3, r1, 63 - 4; addi r8, r1, 64 + 63 - 4 }
398 { prefetch r3; move r3, r8; slt_u r8, r8, r18 }
399 { mvz r3, r8, r1; addi r8, r3, 64 }
400 { prefetch r3; move r3, r8; slt_u r8, r8, r18 }
401 { mvz r3, r8, r1; movei r17, 0 }
402
403.Lcopy_unaligned_line:
404 /* Prefetch another line. */
405 { prefetch r3; addi r15, r1, 60; addi r3, r3, 64 }
406 /* Fire off a load of the last word we are about to copy. */
407EX: { lw_na r15, r15; slt_u r8, r3, r18 }
408
409EX: { mvz r3, r8, r1; wh64 r0 }
410
411 /* This loop runs twice.
412 *
413 * On entry:
414 * - r17 is even before the first iteration, and odd before
415 * the second. It is incremented inside the loop. Encountering
416 * an even value at the end of the loop makes it stop.
417 */
418.Lcopy_half_an_unaligned_line:
419EX: {
420 /* Stall until the last byte is ready. In the steady state this
421 * guarantees all words to load below will be in the L2 cache, which
422 * avoids shunting the loads to the RTF.
423 */
424 move zero, r15
425 lwadd_na r7, r1, 16
426 }
427EX: { lwadd_na r11, r1, 12 }
428EX: { lwadd_na r14, r1, -24 }
429EX: { lwadd_na r8, r1, 4 }
430EX: { lwadd_na r9, r1, 4 }
431EX: {
432 lwadd_na r10, r1, 8
433 /* r16 = (r2 < 64), after we subtract 32 from r2 below. */
434 slti_u r16, r2, 64 + 32
435 }
436EX: { lwadd_na r12, r1, 4; addi r17, r17, 1 }
437EX: { lwadd_na r13, r1, 8; dword_align r6, r7, r1 }
438EX: { swadd r0, r6, 4; dword_align r7, r8, r1 }
439EX: { swadd r0, r7, 4; dword_align r8, r9, r1 }
440EX: { swadd r0, r8, 4; dword_align r9, r10, r1 }
441EX: { swadd r0, r9, 4; dword_align r10, r11, r1 }
442EX: { swadd r0, r10, 4; dword_align r11, r12, r1 }
443EX: { swadd r0, r11, 4; dword_align r12, r13, r1 }
444EX: { swadd r0, r12, 4; dword_align r13, r14, r1 }
445EX: { swadd r0, r13, 4; addi r2, r2, -32 }
446 { move r6, r14; bbst r17, .Lcopy_half_an_unaligned_line }
447
448 { bzt r16, .Lcopy_unaligned_line; move r7, r6 }
449
450 /* On entry:
451 * - r0 is the next store address.
452 * - r1 points 4 bytes past the load address corresponding to r0.
453 * - r2 >= 0 (# of bytes left to store).
454 * - r7 is the next aligned src word value.
455 */
456.Lcleanup_unaligned_words:
457 /* Handle any trailing bytes. */
458 { bz r2, .Lcopy_unaligned_done; slti_u r8, r2, 4 }
459 { bzt r8, .Lcopy_unaligned_src_words; move r6, r7 }
460
461 /* Move r1 back to the point where it corresponds to r0. */
462 { addi r1, r1, -4 }
463
464 /* Fall through */
465
466/*
467 *
468 * 1 byte at a time copy handler.
469 *
470 */
471
472.Lcopy_unaligned_few:
473EX: { lb_u r3, r1; addi r1, r1, 1 }
474EX: { sb r0, r3; addi r0, r0, 1; addi r2, r2, -1 }
475 { bnzt r2, .Lcopy_unaligned_few }
476
477.Lcopy_unaligned_done:
478
479 /* For memcpy return original dest address, else zero. */
480 { mz r0, r29, r23; jrp lr }
481
482.Lend_memcpy_common:
483 .size memcpy_common, .Lend_memcpy_common - memcpy_common
484
485 .section .fixup,"ax"
486memcpy_common_fixup:
487 .type memcpy_common_fixup, @function
488
489 /* Skip any bytes we already successfully copied.
490 * r2 (num remaining) is correct, but r0 (dst) and r1 (src)
491 * may not be quite right because of unrolling and prefetching.
492 * So we need to recompute their values as the address just
493 * after the last byte we are sure was successfully loaded and
494 * then stored.
495 */
496
497 /* Determine how many bytes we successfully copied. */
498 { sub r3, r25, r2 }
499
500 /* Add this to the original r0 and r1 to get their new values. */
501 { add r0, r23, r3; add r1, r24, r3 }
502
503 { bzt r29, memcpy_fixup_loop }
504 { blzt r29, copy_to_user_fixup_loop }
505
506copy_from_user_fixup_loop:
507 /* Try copying the rest one byte at a time, expecting a load fault. */
508.Lcfu: { lb_u r3, r1; addi r1, r1, 1 }
509 { sb r0, r3; addi r0, r0, 1; addi r2, r2, -1 }
510 { bnzt r2, copy_from_user_fixup_loop }
511
512.Lcopy_from_user_fixup_zero_remainder:
513 move lr, r27
514 { move r0, r2; jrp lr }
515
516copy_to_user_fixup_loop:
517 /* Try copying the rest one byte at a time, expecting a store fault. */
518 { lb_u r3, r1; addi r1, r1, 1 }
519.Lctu: { sb r0, r3; addi r0, r0, 1; addi r2, r2, -1 }
520 { bnzt r2, copy_to_user_fixup_loop }
521.Lcopy_to_user_fixup_done:
522 move lr, r27
523 { move r0, r2; jrp lr }
524
525memcpy_fixup_loop:
526 /* Try copying the rest one byte at a time. We expect a disastrous
527 * fault to happen since we are in fixup code, but let it happen.
528 */
529 { lb_u r3, r1; addi r1, r1, 1 }
530 { sb r0, r3; addi r0, r0, 1; addi r2, r2, -1 }
531 { bnzt r2, memcpy_fixup_loop }
532 /* This should be unreachable, we should have faulted again.
533 * But be paranoid and handle it in case some interrupt changed
534 * the TLB or something.
535 */
536 move lr, r27
537 { move r0, r23; jrp lr }
538
539 .size memcpy_common_fixup, . - memcpy_common_fixup
540
541 .section __ex_table,"a"
542 .align 4
543 .word .Lcfu, .Lcopy_from_user_fixup_zero_remainder
544 .word .Lctu, .Lcopy_to_user_fixup_done
diff --git a/arch/tile/lib/memcpy_64.c b/arch/tile/lib/memcpy_64.c
deleted file mode 100644
index 4815354b8cd2..000000000000
--- a/arch/tile/lib/memcpy_64.c
+++ /dev/null
@@ -1,367 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18/* EXPORT_SYMBOL() is in arch/tile/lib/exports.c since this should be asm. */
19
20/* Must be 8 bytes in size. */
21#define op_t uint64_t
22
23/* Threshold value for when to enter the unrolled loops. */
24#define OP_T_THRES 16
25
26#if CHIP_L2_LINE_SIZE() != 64
27#error "Assumes 64 byte line size"
28#endif
29
30/* How many cache lines ahead should we prefetch? */
31#define PREFETCH_LINES_AHEAD 4
32
33/*
34 * Provide "base versions" of load and store for the normal code path.
35 * The kernel provides other versions for userspace copies.
36 */
37#define ST(p, v) (*(p) = (v))
38#define LD(p) (*(p))
39
40#ifndef USERCOPY_FUNC
41#define ST1 ST
42#define ST2 ST
43#define ST4 ST
44#define ST8 ST
45#define LD1 LD
46#define LD2 LD
47#define LD4 LD
48#define LD8 LD
49#define RETVAL dstv
50void *memcpy(void *__restrict dstv, const void *__restrict srcv, size_t n)
51#else
52/*
53 * Special kernel version will provide implementation of the LDn/STn
54 * macros to return a count of uncopied bytes due to mm fault.
55 */
56#define RETVAL 0
57int __attribute__((optimize("omit-frame-pointer")))
58USERCOPY_FUNC(void *__restrict dstv, const void *__restrict srcv, size_t n)
59#endif
60{
61 char *__restrict dst1 = (char *)dstv;
62 const char *__restrict src1 = (const char *)srcv;
63 const char *__restrict src1_end;
64 const char *__restrict prefetch;
65 op_t *__restrict dst8; /* 8-byte pointer to destination memory. */
66 op_t final; /* Final bytes to write to trailing word, if any */
67 long i;
68
69 if (n < 16) {
70 for (; n; n--)
71 ST1(dst1++, LD1(src1++));
72 return RETVAL;
73 }
74
75 /*
76 * Locate the end of source memory we will copy. Don't
77 * prefetch past this.
78 */
79 src1_end = src1 + n - 1;
80
81 /* Prefetch ahead a few cache lines, but not past the end. */
82 prefetch = src1;
83 for (i = 0; i < PREFETCH_LINES_AHEAD; i++) {
84 __insn_prefetch(prefetch);
85 prefetch += CHIP_L2_LINE_SIZE();
86 prefetch = (prefetch < src1_end) ? prefetch : src1;
87 }
88
89 /* Copy bytes until dst is word-aligned. */
90 for (; (uintptr_t)dst1 & (sizeof(op_t) - 1); n--)
91 ST1(dst1++, LD1(src1++));
92
93 /* 8-byte pointer to destination memory. */
94 dst8 = (op_t *)dst1;
95
96 if (__builtin_expect((uintptr_t)src1 & (sizeof(op_t) - 1), 0)) {
97 /* Unaligned copy. */
98
99 op_t tmp0 = 0, tmp1 = 0, tmp2, tmp3;
100 const op_t *src8 = (const op_t *) ((uintptr_t)src1 &
101 -sizeof(op_t));
102 const void *srci = (void *)src1;
103 int m;
104
105 m = (CHIP_L2_LINE_SIZE() << 2) -
106 (((uintptr_t)dst8) & ((CHIP_L2_LINE_SIZE() << 2) - 1));
107 m = (n < m) ? n : m;
108 m /= sizeof(op_t);
109
110 /* Copy until 'dst' is cache-line-aligned. */
111 n -= (sizeof(op_t) * m);
112
113 switch (m % 4) {
114 case 0:
115 if (__builtin_expect(!m, 0))
116 goto _M0;
117 tmp1 = LD8(src8++);
118 tmp2 = LD8(src8++);
119 goto _8B3;
120 case 2:
121 m += 2;
122 tmp3 = LD8(src8++);
123 tmp0 = LD8(src8++);
124 goto _8B1;
125 case 3:
126 m += 1;
127 tmp2 = LD8(src8++);
128 tmp3 = LD8(src8++);
129 goto _8B2;
130 case 1:
131 m--;
132 tmp0 = LD8(src8++);
133 tmp1 = LD8(src8++);
134 if (__builtin_expect(!m, 0))
135 goto _8B0;
136 }
137
138 do {
139 tmp2 = LD8(src8++);
140 tmp0 = __insn_dblalign(tmp0, tmp1, srci);
141 ST8(dst8++, tmp0);
142_8B3:
143 tmp3 = LD8(src8++);
144 tmp1 = __insn_dblalign(tmp1, tmp2, srci);
145 ST8(dst8++, tmp1);
146_8B2:
147 tmp0 = LD8(src8++);
148 tmp2 = __insn_dblalign(tmp2, tmp3, srci);
149 ST8(dst8++, tmp2);
150_8B1:
151 tmp1 = LD8(src8++);
152 tmp3 = __insn_dblalign(tmp3, tmp0, srci);
153 ST8(dst8++, tmp3);
154 m -= 4;
155 } while (m);
156
157_8B0:
158 tmp0 = __insn_dblalign(tmp0, tmp1, srci);
159 ST8(dst8++, tmp0);
160 src8--;
161
162_M0:
163 if (__builtin_expect(n >= CHIP_L2_LINE_SIZE(), 0)) {
164 op_t tmp4, tmp5, tmp6, tmp7, tmp8;
165
166 prefetch = ((const char *)src8) +
167 CHIP_L2_LINE_SIZE() * PREFETCH_LINES_AHEAD;
168
169 for (tmp0 = LD8(src8++); n >= CHIP_L2_LINE_SIZE();
170 n -= CHIP_L2_LINE_SIZE()) {
171 /* Prefetch and advance to next line to
172 prefetch, but don't go past the end. */
173 __insn_prefetch(prefetch);
174
175 /* Make sure prefetch got scheduled
176 earlier. */
177 __asm__ ("" : : : "memory");
178
179 prefetch += CHIP_L2_LINE_SIZE();
180 prefetch = (prefetch < src1_end) ? prefetch :
181 (const char *) src8;
182
183 tmp1 = LD8(src8++);
184 tmp2 = LD8(src8++);
185 tmp3 = LD8(src8++);
186 tmp4 = LD8(src8++);
187 tmp5 = LD8(src8++);
188 tmp6 = LD8(src8++);
189 tmp7 = LD8(src8++);
190 tmp8 = LD8(src8++);
191
192 tmp0 = __insn_dblalign(tmp0, tmp1, srci);
193 tmp1 = __insn_dblalign(tmp1, tmp2, srci);
194 tmp2 = __insn_dblalign(tmp2, tmp3, srci);
195 tmp3 = __insn_dblalign(tmp3, tmp4, srci);
196 tmp4 = __insn_dblalign(tmp4, tmp5, srci);
197 tmp5 = __insn_dblalign(tmp5, tmp6, srci);
198 tmp6 = __insn_dblalign(tmp6, tmp7, srci);
199 tmp7 = __insn_dblalign(tmp7, tmp8, srci);
200
201 __insn_wh64(dst8);
202
203 ST8(dst8++, tmp0);
204 ST8(dst8++, tmp1);
205 ST8(dst8++, tmp2);
206 ST8(dst8++, tmp3);
207 ST8(dst8++, tmp4);
208 ST8(dst8++, tmp5);
209 ST8(dst8++, tmp6);
210 ST8(dst8++, tmp7);
211
212 tmp0 = tmp8;
213 }
214 src8--;
215 }
216
217 /* Copy the rest 8-byte chunks. */
218 if (n >= sizeof(op_t)) {
219 tmp0 = LD8(src8++);
220 for (; n >= sizeof(op_t); n -= sizeof(op_t)) {
221 tmp1 = LD8(src8++);
222 tmp0 = __insn_dblalign(tmp0, tmp1, srci);
223 ST8(dst8++, tmp0);
224 tmp0 = tmp1;
225 }
226 src8--;
227 }
228
229 if (n == 0)
230 return RETVAL;
231
232 tmp0 = LD8(src8++);
233 tmp1 = ((const char *)src8 <= src1_end)
234 ? LD8((op_t *)src8) : 0;
235 final = __insn_dblalign(tmp0, tmp1, srci);
236
237 } else {
238 /* Aligned copy. */
239
240 const op_t *__restrict src8 = (const op_t *)src1;
241
242 /* src8 and dst8 are both word-aligned. */
243 if (n >= CHIP_L2_LINE_SIZE()) {
244 /* Copy until 'dst' is cache-line-aligned. */
245 for (; (uintptr_t)dst8 & (CHIP_L2_LINE_SIZE() - 1);
246 n -= sizeof(op_t))
247 ST8(dst8++, LD8(src8++));
248
249 for (; n >= CHIP_L2_LINE_SIZE(); ) {
250 op_t tmp0, tmp1, tmp2, tmp3;
251 op_t tmp4, tmp5, tmp6, tmp7;
252
253 /*
254 * Prefetch and advance to next line
255 * to prefetch, but don't go past the
256 * end.
257 */
258 __insn_prefetch(prefetch);
259
260 /* Make sure prefetch got scheduled
261 earlier. */
262 __asm__ ("" : : : "memory");
263
264 prefetch += CHIP_L2_LINE_SIZE();
265 prefetch = (prefetch < src1_end) ? prefetch :
266 (const char *)src8;
267
268 /*
269 * Do all the loads before wh64. This
270 * is necessary if [src8, src8+7] and
271 * [dst8, dst8+7] share the same cache
272 * line and dst8 <= src8, as can be
273 * the case when called from memmove,
274 * or with code tested on x86 whose
275 * memcpy always works with forward
276 * copies.
277 */
278 tmp0 = LD8(src8++);
279 tmp1 = LD8(src8++);
280 tmp2 = LD8(src8++);
281 tmp3 = LD8(src8++);
282 tmp4 = LD8(src8++);
283 tmp5 = LD8(src8++);
284 tmp6 = LD8(src8++);
285 tmp7 = LD8(src8++);
286
287 /* wh64 and wait for tmp7 load completion. */
288 __asm__ ("move %0, %0; wh64 %1\n"
289 : : "r"(tmp7), "r"(dst8));
290
291 ST8(dst8++, tmp0);
292 ST8(dst8++, tmp1);
293 ST8(dst8++, tmp2);
294 ST8(dst8++, tmp3);
295 ST8(dst8++, tmp4);
296 ST8(dst8++, tmp5);
297 ST8(dst8++, tmp6);
298 ST8(dst8++, tmp7);
299
300 n -= CHIP_L2_LINE_SIZE();
301 }
302#if CHIP_L2_LINE_SIZE() != 64
303# error "Fix code that assumes particular L2 cache line size."
304#endif
305 }
306
307 for (; n >= sizeof(op_t); n -= sizeof(op_t))
308 ST8(dst8++, LD8(src8++));
309
310 if (__builtin_expect(n == 0, 1))
311 return RETVAL;
312
313 final = LD8(src8);
314 }
315
316 /* n != 0 if we get here. Write out any trailing bytes. */
317 dst1 = (char *)dst8;
318#ifndef __BIG_ENDIAN__
319 if (n & 4) {
320 ST4((uint32_t *)dst1, final);
321 dst1 += 4;
322 final >>= 32;
323 n &= 3;
324 }
325 if (n & 2) {
326 ST2((uint16_t *)dst1, final);
327 dst1 += 2;
328 final >>= 16;
329 n &= 1;
330 }
331 if (n)
332 ST1((uint8_t *)dst1, final);
333#else
334 if (n & 4) {
335 ST4((uint32_t *)dst1, final >> 32);
336 dst1 += 4;
337 }
338 else
339 {
340 final >>= 32;
341 }
342 if (n & 2) {
343 ST2((uint16_t *)dst1, final >> 16);
344 dst1 += 2;
345 }
346 else
347 {
348 final >>= 16;
349 }
350 if (n & 1)
351 ST1((uint8_t *)dst1, final >> 8);
352#endif
353
354 return RETVAL;
355}
356
357#ifdef USERCOPY_FUNC
358#undef ST1
359#undef ST2
360#undef ST4
361#undef ST8
362#undef LD1
363#undef LD2
364#undef LD4
365#undef LD8
366#undef USERCOPY_FUNC
367#endif
diff --git a/arch/tile/lib/memcpy_user_64.c b/arch/tile/lib/memcpy_user_64.c
deleted file mode 100644
index a3fea9fd973e..000000000000
--- a/arch/tile/lib/memcpy_user_64.c
+++ /dev/null
@@ -1,85 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Do memcpy(), but trap and return "n" when a load or store faults.
15 *
16 * Note: this idiom only works when memcpy() compiles to a leaf function.
17 * Here leaf function not only means it does not have calls, but also
18 * requires no stack operations (sp, stack frame pointer) and no
19 * use of callee-saved registers, else "jrp lr" will be incorrect since
20 * unwinding stack frame is bypassed. Since memcpy() is not complex so
21 * these conditions are satisfied here, but we need to be careful when
22 * modifying this file. This is not a clean solution but is the best
23 * one so far.
24 *
25 * Also note that we are capturing "n" from the containing scope here.
26 */
27
28#define _ST(p, inst, v) \
29 ({ \
30 asm("1: " #inst " %0, %1;" \
31 ".pushsection .coldtext,\"ax\";" \
32 "2: { move r0, %2; jrp lr };" \
33 ".section __ex_table,\"a\";" \
34 ".align 8;" \
35 ".quad 1b, 2b;" \
36 ".popsection" \
37 : "=m" (*(p)) : "r" (v), "r" (n)); \
38 })
39
40#define _LD(p, inst) \
41 ({ \
42 unsigned long __v; \
43 asm("1: " #inst " %0, %1;" \
44 ".pushsection .coldtext,\"ax\";" \
45 "2: { move r0, %2; jrp lr };" \
46 ".section __ex_table,\"a\";" \
47 ".align 8;" \
48 ".quad 1b, 2b;" \
49 ".popsection" \
50 : "=r" (__v) : "m" (*(p)), "r" (n)); \
51 __v; \
52 })
53
54#define USERCOPY_FUNC raw_copy_to_user
55#define ST1(p, v) _ST((p), st1, (v))
56#define ST2(p, v) _ST((p), st2, (v))
57#define ST4(p, v) _ST((p), st4, (v))
58#define ST8(p, v) _ST((p), st, (v))
59#define LD1 LD
60#define LD2 LD
61#define LD4 LD
62#define LD8 LD
63#include "memcpy_64.c"
64
65#define USERCOPY_FUNC raw_copy_from_user
66#define ST1 ST
67#define ST2 ST
68#define ST4 ST
69#define ST8 ST
70#define LD1(p) _LD((p), ld1u)
71#define LD2(p) _LD((p), ld2u)
72#define LD4(p) _LD((p), ld4u)
73#define LD8(p) _LD((p), ld)
74#include "memcpy_64.c"
75
76#define USERCOPY_FUNC raw_copy_in_user
77#define ST1(p, v) _ST((p), st1, (v))
78#define ST2(p, v) _ST((p), st2, (v))
79#define ST4(p, v) _ST((p), st4, (v))
80#define ST8(p, v) _ST((p), st, (v))
81#define LD1(p) _LD((p), ld1u)
82#define LD2(p) _LD((p), ld2u)
83#define LD4(p) _LD((p), ld4u)
84#define LD8(p) _LD((p), ld)
85#include "memcpy_64.c"
diff --git a/arch/tile/lib/memmove.c b/arch/tile/lib/memmove.c
deleted file mode 100644
index fd615ae6ade7..000000000000
--- a/arch/tile/lib/memmove.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18
19void *memmove(void *dest, const void *src, size_t n)
20{
21 if ((const char *)src >= (char *)dest + n
22 || (char *)dest >= (const char *)src + n) {
23 /* We found no overlap, so let memcpy do all the heavy
24 * lifting (prefetching, etc.)
25 */
26 return memcpy(dest, src, n);
27 }
28
29 if (n != 0) {
30 const uint8_t *in;
31 uint8_t x;
32 uint8_t *out;
33 int stride;
34
35 if (src < dest) {
36 /* copy backwards */
37 in = (const uint8_t *)src + n - 1;
38 out = (uint8_t *)dest + n - 1;
39 stride = -1;
40 } else {
41 /* copy forwards */
42 in = (const uint8_t *)src;
43 out = (uint8_t *)dest;
44 stride = 1;
45 }
46
47 /* Manually software-pipeline this loop. */
48 x = *in;
49 in += stride;
50
51 while (--n != 0) {
52 *out = x;
53 out += stride;
54 x = *in;
55 in += stride;
56 }
57
58 *out = x;
59 }
60
61 return dest;
62}
63EXPORT_SYMBOL(memmove);
diff --git a/arch/tile/lib/memset_32.c b/arch/tile/lib/memset_32.c
deleted file mode 100644
index 2042bfe6595f..000000000000
--- a/arch/tile/lib/memset_32.c
+++ /dev/null
@@ -1,143 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18#include <arch/chip.h>
19
20void *memset(void *s, int c, size_t n)
21{
22 uint32_t *out32;
23 int n32;
24 uint32_t v16, v32;
25 uint8_t *out8 = s;
26 int to_align32;
27
28 /* Experimentation shows that a trivial tight loop is a win up until
29 * around a size of 20, where writing a word at a time starts to win.
30 */
31#define BYTE_CUTOFF 20
32
33#if BYTE_CUTOFF < 3
34 /* This must be at least at least this big, or some code later
35 * on doesn't work.
36 */
37#error "BYTE_CUTOFF is too small"
38#endif
39
40 if (n < BYTE_CUTOFF) {
41 /* Strangely, this turns out to be the tightest way to
42 * write this loop.
43 */
44 if (n != 0) {
45 do {
46 /* Strangely, combining these into one line
47 * performs worse.
48 */
49 *out8 = c;
50 out8++;
51 } while (--n != 0);
52 }
53
54 return s;
55 }
56
57 /* Align 'out8'. We know n >= 3 so this won't write past the end. */
58 while (((uintptr_t) out8 & 3) != 0) {
59 *out8++ = c;
60 --n;
61 }
62
63 /* Align 'n'. */
64 while (n & 3)
65 out8[--n] = c;
66
67 out32 = (uint32_t *) out8;
68 n32 = n >> 2;
69
70 /* Tile input byte out to 32 bits. */
71 v16 = __insn_intlb(c, c);
72 v32 = __insn_intlh(v16, v16);
73
74 /* This must be at least 8 or the following loop doesn't work. */
75#define CACHE_LINE_SIZE_IN_WORDS (CHIP_L2_LINE_SIZE() / 4)
76
77 /* Determine how many words we need to emit before the 'out32'
78 * pointer becomes aligned modulo the cache line size.
79 */
80 to_align32 =
81 (-((uintptr_t)out32 >> 2)) & (CACHE_LINE_SIZE_IN_WORDS - 1);
82
83 /* Only bother aligning and using wh64 if there is at least
84 * one full cache line to process. This check also prevents
85 * overrunning the end of the buffer with alignment words.
86 */
87 if (to_align32 <= n32 - CACHE_LINE_SIZE_IN_WORDS) {
88 int lines_left;
89
90 /* Align out32 mod the cache line size so we can use wh64. */
91 n32 -= to_align32;
92 for (; to_align32 != 0; to_align32--) {
93 *out32 = v32;
94 out32++;
95 }
96
97 /* Use unsigned divide to turn this into a right shift. */
98 lines_left = (unsigned)n32 / CACHE_LINE_SIZE_IN_WORDS;
99
100 do {
101 /* Only wh64 a few lines at a time, so we don't
102 * exceed the maximum number of victim lines.
103 */
104 int x = ((lines_left < CHIP_MAX_OUTSTANDING_VICTIMS())
105 ? lines_left
106 : CHIP_MAX_OUTSTANDING_VICTIMS());
107 uint32_t *wh = out32;
108 int i = x;
109 int j;
110
111 lines_left -= x;
112
113 do {
114 __insn_wh64(wh);
115 wh += CACHE_LINE_SIZE_IN_WORDS;
116 } while (--i);
117
118 for (j = x * (CACHE_LINE_SIZE_IN_WORDS / 4);
119 j != 0; j--) {
120 *out32++ = v32;
121 *out32++ = v32;
122 *out32++ = v32;
123 *out32++ = v32;
124 }
125 } while (lines_left != 0);
126
127 /* We processed all full lines above, so only this many
128 * words remain to be processed.
129 */
130 n32 &= CACHE_LINE_SIZE_IN_WORDS - 1;
131 }
132
133 /* Now handle any leftover values. */
134 if (n32 != 0) {
135 do {
136 *out32 = v32;
137 out32++;
138 } while (--n32 != 0);
139 }
140
141 return s;
142}
143EXPORT_SYMBOL(memset);
diff --git a/arch/tile/lib/memset_64.c b/arch/tile/lib/memset_64.c
deleted file mode 100644
index 03ef69cd73de..000000000000
--- a/arch/tile/lib/memset_64.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18#include <arch/chip.h>
19#include "string-endian.h"
20
21void *memset(void *s, int c, size_t n)
22{
23 uint64_t *out64;
24 int n64, to_align64;
25 uint64_t v64;
26 uint8_t *out8 = s;
27
28 /* Experimentation shows that a trivial tight loop is a win up until
29 * around a size of 20, where writing a word at a time starts to win.
30 */
31#define BYTE_CUTOFF 20
32
33#if BYTE_CUTOFF < 7
34 /* This must be at least at least this big, or some code later
35 * on doesn't work.
36 */
37#error "BYTE_CUTOFF is too small"
38#endif
39
40 if (n < BYTE_CUTOFF) {
41 /* Strangely, this turns out to be the tightest way to
42 * write this loop.
43 */
44 if (n != 0) {
45 do {
46 /* Strangely, combining these into one line
47 * performs worse.
48 */
49 *out8 = c;
50 out8++;
51 } while (--n != 0);
52 }
53
54 return s;
55 }
56
57 /* Align 'out8'. We know n >= 7 so this won't write past the end. */
58 while (((uintptr_t) out8 & 7) != 0) {
59 *out8++ = c;
60 --n;
61 }
62
63 /* Align 'n'. */
64 while (n & 7)
65 out8[--n] = c;
66
67 out64 = (uint64_t *) out8;
68 n64 = n >> 3;
69
70 /* Tile input byte out to 64 bits. */
71 v64 = copy_byte(c);
72
73 /* This must be at least 8 or the following loop doesn't work. */
74#define CACHE_LINE_SIZE_IN_DOUBLEWORDS (CHIP_L2_LINE_SIZE() / 8)
75
76 /* Determine how many words we need to emit before the 'out32'
77 * pointer becomes aligned modulo the cache line size.
78 */
79 to_align64 = (-((uintptr_t)out64 >> 3)) &
80 (CACHE_LINE_SIZE_IN_DOUBLEWORDS - 1);
81
82 /* Only bother aligning and using wh64 if there is at least
83 * one full cache line to process. This check also prevents
84 * overrunning the end of the buffer with alignment words.
85 */
86 if (to_align64 <= n64 - CACHE_LINE_SIZE_IN_DOUBLEWORDS) {
87 int lines_left;
88
89 /* Align out64 mod the cache line size so we can use wh64. */
90 n64 -= to_align64;
91 for (; to_align64 != 0; to_align64--) {
92 *out64 = v64;
93 out64++;
94 }
95
96 /* Use unsigned divide to turn this into a right shift. */
97 lines_left = (unsigned)n64 / CACHE_LINE_SIZE_IN_DOUBLEWORDS;
98
99 do {
100 /* Only wh64 a few lines at a time, so we don't
101 * exceed the maximum number of victim lines.
102 */
103 int x = ((lines_left < CHIP_MAX_OUTSTANDING_VICTIMS())
104 ? lines_left
105 : CHIP_MAX_OUTSTANDING_VICTIMS());
106 uint64_t *wh = out64;
107 int i = x;
108 int j;
109
110 lines_left -= x;
111
112 do {
113 __insn_wh64(wh);
114 wh += CACHE_LINE_SIZE_IN_DOUBLEWORDS;
115 } while (--i);
116
117 for (j = x * (CACHE_LINE_SIZE_IN_DOUBLEWORDS / 4);
118 j != 0; j--) {
119 *out64++ = v64;
120 *out64++ = v64;
121 *out64++ = v64;
122 *out64++ = v64;
123 }
124 } while (lines_left != 0);
125
126 /* We processed all full lines above, so only this many
127 * words remain to be processed.
128 */
129 n64 &= CACHE_LINE_SIZE_IN_DOUBLEWORDS - 1;
130 }
131
132 /* Now handle any leftover values. */
133 if (n64 != 0) {
134 do {
135 *out64 = v64;
136 out64++;
137 } while (--n64 != 0);
138 }
139
140 return s;
141}
142EXPORT_SYMBOL(memset);
diff --git a/arch/tile/lib/spinlock_32.c b/arch/tile/lib/spinlock_32.c
deleted file mode 100644
index db9333f2447c..000000000000
--- a/arch/tile/lib/spinlock_32.c
+++ /dev/null
@@ -1,251 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/spinlock.h>
16#include <linux/module.h>
17#include <asm/processor.h>
18#include <arch/spr_def.h>
19
20#include "spinlock_common.h"
21
22void arch_spin_lock(arch_spinlock_t *lock)
23{
24 int my_ticket;
25 int iterations = 0;
26 int delta;
27
28 while ((my_ticket = __insn_tns((void *)&lock->next_ticket)) & 1)
29 delay_backoff(iterations++);
30
31 /* Increment the next ticket number, implicitly releasing tns lock. */
32 lock->next_ticket = my_ticket + TICKET_QUANTUM;
33
34 /* Wait until it's our turn. */
35 while ((delta = my_ticket - lock->current_ticket) != 0)
36 relax((128 / CYCLES_PER_RELAX_LOOP) * delta);
37}
38EXPORT_SYMBOL(arch_spin_lock);
39
40int arch_spin_trylock(arch_spinlock_t *lock)
41{
42 /*
43 * Grab a ticket; no need to retry if it's busy, we'll just
44 * treat that the same as "locked", since someone else
45 * will lock it momentarily anyway.
46 */
47 int my_ticket = __insn_tns((void *)&lock->next_ticket);
48
49 if (my_ticket == lock->current_ticket) {
50 /* Not currently locked, so lock it by keeping this ticket. */
51 lock->next_ticket = my_ticket + TICKET_QUANTUM;
52 /* Success! */
53 return 1;
54 }
55
56 if (!(my_ticket & 1)) {
57 /* Release next_ticket. */
58 lock->next_ticket = my_ticket;
59 }
60
61 return 0;
62}
63EXPORT_SYMBOL(arch_spin_trylock);
64
65/*
66 * The low byte is always reserved to be the marker for a "tns" operation
67 * since the low bit is set to "1" by a tns. The next seven bits are
68 * zeroes. The next byte holds the "next" writer value, i.e. the ticket
69 * available for the next task that wants to write. The third byte holds
70 * the current writer value, i.e. the writer who holds the current ticket.
71 * If current == next == 0, there are no interested writers.
72 */
73#define WR_NEXT_SHIFT _WR_NEXT_SHIFT
74#define WR_CURR_SHIFT _WR_CURR_SHIFT
75#define WR_WIDTH _WR_WIDTH
76#define WR_MASK ((1 << WR_WIDTH) - 1)
77
78/*
79 * The last eight bits hold the active reader count. This has to be
80 * zero before a writer can start to write.
81 */
82#define RD_COUNT_SHIFT _RD_COUNT_SHIFT
83#define RD_COUNT_WIDTH _RD_COUNT_WIDTH
84#define RD_COUNT_MASK ((1 << RD_COUNT_WIDTH) - 1)
85
86
87/*
88 * We can get the read lock if everything but the reader bits (which
89 * are in the high part of the word) is zero, i.e. no active or
90 * waiting writers, no tns.
91 *
92 * We guard the tns/store-back with an interrupt critical section to
93 * preserve the semantic that the same read lock can be acquired in an
94 * interrupt context.
95 */
96int arch_read_trylock(arch_rwlock_t *rwlock)
97{
98 u32 val;
99 __insn_mtspr(SPR_INTERRUPT_CRITICAL_SECTION, 1);
100 val = __insn_tns((int *)&rwlock->lock);
101 if (likely((val << _RD_COUNT_WIDTH) == 0)) {
102 val += 1 << RD_COUNT_SHIFT;
103 rwlock->lock = val;
104 __insn_mtspr(SPR_INTERRUPT_CRITICAL_SECTION, 0);
105 BUG_ON(val == 0); /* we don't expect wraparound */
106 return 1;
107 }
108 if ((val & 1) == 0)
109 rwlock->lock = val;
110 __insn_mtspr(SPR_INTERRUPT_CRITICAL_SECTION, 0);
111 return 0;
112}
113EXPORT_SYMBOL(arch_read_trylock);
114
115/*
116 * Spin doing arch_read_trylock() until we acquire the lock.
117 * ISSUE: This approach can permanently starve readers. A reader who sees
118 * a writer could instead take a ticket lock (just like a writer would),
119 * and atomically enter read mode (with 1 reader) when it gets the ticket.
120 * This way both readers and writers would always make forward progress
121 * in a finite time.
122 */
123void arch_read_lock(arch_rwlock_t *rwlock)
124{
125 u32 iterations = 0;
126 while (unlikely(!arch_read_trylock(rwlock)))
127 delay_backoff(iterations++);
128}
129EXPORT_SYMBOL(arch_read_lock);
130
131void arch_read_unlock(arch_rwlock_t *rwlock)
132{
133 u32 val, iterations = 0;
134
135 mb(); /* guarantee anything modified under the lock is visible */
136 for (;;) {
137 __insn_mtspr(SPR_INTERRUPT_CRITICAL_SECTION, 1);
138 val = __insn_tns((int *)&rwlock->lock);
139 if (likely((val & 1) == 0)) {
140 rwlock->lock = val - (1 << _RD_COUNT_SHIFT);
141 __insn_mtspr(SPR_INTERRUPT_CRITICAL_SECTION, 0);
142 break;
143 }
144 __insn_mtspr(SPR_INTERRUPT_CRITICAL_SECTION, 0);
145 delay_backoff(iterations++);
146 }
147}
148EXPORT_SYMBOL(arch_read_unlock);
149
150/*
151 * We don't need an interrupt critical section here (unlike for
152 * arch_read_lock) since we should never use a bare write lock where
153 * it could be interrupted by code that could try to re-acquire it.
154 */
155void arch_write_lock(arch_rwlock_t *rwlock)
156{
157 /*
158 * The trailing underscore on this variable (and curr_ below)
159 * reminds us that the high bits are garbage; we mask them out
160 * when we compare them.
161 */
162 u32 my_ticket_;
163 u32 iterations = 0;
164 u32 val = __insn_tns((int *)&rwlock->lock);
165
166 if (likely(val == 0)) {
167 rwlock->lock = 1 << _WR_NEXT_SHIFT;
168 return;
169 }
170
171 /*
172 * Wait until there are no readers, then bump up the next
173 * field and capture the ticket value.
174 */
175 for (;;) {
176 if (!(val & 1)) {
177 if ((val >> RD_COUNT_SHIFT) == 0)
178 break;
179 rwlock->lock = val;
180 }
181 delay_backoff(iterations++);
182 val = __insn_tns((int *)&rwlock->lock);
183 }
184
185 /* Take out the next ticket and extract my ticket value. */
186 rwlock->lock = __insn_addb(val, 1 << WR_NEXT_SHIFT);
187 my_ticket_ = val >> WR_NEXT_SHIFT;
188
189 /* Wait until the "current" field matches our ticket. */
190 for (;;) {
191 u32 curr_ = val >> WR_CURR_SHIFT;
192 u32 delta = ((my_ticket_ - curr_) & WR_MASK);
193 if (likely(delta == 0))
194 break;
195
196 /* Delay based on how many lock-holders are still out there. */
197 relax((256 / CYCLES_PER_RELAX_LOOP) * delta);
198
199 /*
200 * Get a non-tns value to check; we don't need to tns
201 * it ourselves. Since we're not tns'ing, we retry
202 * more rapidly to get a valid value.
203 */
204 while ((val = rwlock->lock) & 1)
205 relax(4);
206 }
207}
208EXPORT_SYMBOL(arch_write_lock);
209
210int arch_write_trylock(arch_rwlock_t *rwlock)
211{
212 u32 val = __insn_tns((int *)&rwlock->lock);
213
214 /*
215 * If a tns is in progress, or there's a waiting or active locker,
216 * or active readers, we can't take the lock, so give up.
217 */
218 if (unlikely(val != 0)) {
219 if (!(val & 1))
220 rwlock->lock = val;
221 return 0;
222 }
223
224 /* Set the "next" field to mark it locked. */
225 rwlock->lock = 1 << _WR_NEXT_SHIFT;
226 return 1;
227}
228EXPORT_SYMBOL(arch_write_trylock);
229
230void arch_write_unlock(arch_rwlock_t *rwlock)
231{
232 u32 val, eq, mask;
233
234 mb(); /* guarantee anything modified under the lock is visible */
235 val = __insn_tns((int *)&rwlock->lock);
236 if (likely(val == (1 << _WR_NEXT_SHIFT))) {
237 rwlock->lock = 0;
238 return;
239 }
240 while (unlikely(val & 1)) {
241 /* Limited backoff since we are the highest-priority task. */
242 relax(4);
243 val = __insn_tns((int *)&rwlock->lock);
244 }
245 mask = 1 << WR_CURR_SHIFT;
246 val = __insn_addb(val, mask);
247 eq = __insn_seqb(val, val << (WR_CURR_SHIFT - WR_NEXT_SHIFT));
248 val = __insn_mz(eq & mask, val);
249 rwlock->lock = val;
250}
251EXPORT_SYMBOL(arch_write_unlock);
diff --git a/arch/tile/lib/spinlock_64.c b/arch/tile/lib/spinlock_64.c
deleted file mode 100644
index de414c22892f..000000000000
--- a/arch/tile/lib/spinlock_64.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/spinlock.h>
16#include <linux/module.h>
17#include <asm/processor.h>
18
19#include "spinlock_common.h"
20
21/*
22 * Read the spinlock value without allocating in our cache and without
23 * causing an invalidation to another cpu with a copy of the cacheline.
24 * This is important when we are spinning waiting for the lock.
25 */
26static inline u32 arch_spin_read_noalloc(void *lock)
27{
28 return atomic_cmpxchg((atomic_t *)lock, -1, -1);
29}
30
31/*
32 * Wait until the high bits (current) match my ticket.
33 * If we notice the overflow bit set on entry, we clear it.
34 */
35void arch_spin_lock_slow(arch_spinlock_t *lock, u32 my_ticket)
36{
37 if (unlikely(my_ticket & __ARCH_SPIN_NEXT_OVERFLOW)) {
38 __insn_fetchand4(&lock->lock, ~__ARCH_SPIN_NEXT_OVERFLOW);
39 my_ticket &= ~__ARCH_SPIN_NEXT_OVERFLOW;
40 }
41
42 for (;;) {
43 u32 val = arch_spin_read_noalloc(lock);
44 u32 delta = my_ticket - arch_spin_current(val);
45 if (delta == 0)
46 return;
47 relax((128 / CYCLES_PER_RELAX_LOOP) * delta);
48 }
49}
50EXPORT_SYMBOL(arch_spin_lock_slow);
51
52/*
53 * Check the lock to see if it is plausible, and try to get it with cmpxchg().
54 */
55int arch_spin_trylock(arch_spinlock_t *lock)
56{
57 u32 val = arch_spin_read_noalloc(lock);
58 if (unlikely(arch_spin_current(val) != arch_spin_next(val)))
59 return 0;
60 return cmpxchg(&lock->lock, val, (val + 1) & ~__ARCH_SPIN_NEXT_OVERFLOW)
61 == val;
62}
63EXPORT_SYMBOL(arch_spin_trylock);
64
65
66/*
67 * If the read lock fails due to a writer, we retry periodically
68 * until the value is positive and we write our incremented reader count.
69 */
70void __read_lock_failed(arch_rwlock_t *rw)
71{
72 u32 val;
73 int iterations = 0;
74 do {
75 delay_backoff(iterations++);
76 val = __insn_fetchaddgez4(&rw->lock, 1);
77 } while (unlikely(arch_write_val_locked(val)));
78}
79EXPORT_SYMBOL(__read_lock_failed);
80
81/*
82 * If we failed because there were readers, clear the "writer" bit
83 * so we don't block additional readers. Otherwise, there was another
84 * writer anyway, so our "fetchor" made no difference. Then wait,
85 * issuing periodic fetchor instructions, till we get the lock.
86 */
87void __write_lock_failed(arch_rwlock_t *rw, u32 val)
88{
89 int iterations = 0;
90 do {
91 if (!arch_write_val_locked(val))
92 val = __insn_fetchand4(&rw->lock, ~__WRITE_LOCK_BIT);
93 delay_backoff(iterations++);
94 val = __insn_fetchor4(&rw->lock, __WRITE_LOCK_BIT);
95 } while (val != 0);
96}
97EXPORT_SYMBOL(__write_lock_failed);
diff --git a/arch/tile/lib/spinlock_common.h b/arch/tile/lib/spinlock_common.h
deleted file mode 100644
index 6ac37509faca..000000000000
--- a/arch/tile/lib/spinlock_common.h
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 * This file is included into spinlock_32.c or _64.c.
14 */
15
16/*
17 * The mfspr in __spinlock_relax() is 5 or 6 cycles plus 2 for loop
18 * overhead.
19 */
20#ifdef __tilegx__
21#define CYCLES_PER_RELAX_LOOP 7
22#else
23#define CYCLES_PER_RELAX_LOOP 8
24#endif
25
26/*
27 * Idle the core for CYCLES_PER_RELAX_LOOP * iterations cycles.
28 */
29static inline void
30relax(int iterations)
31{
32 for (/*above*/; iterations > 0; iterations--)
33 __insn_mfspr(SPR_PASS);
34 barrier();
35}
36
37/* Perform bounded exponential backoff.*/
38static void delay_backoff(int iterations)
39{
40 u32 exponent, loops;
41
42 /*
43 * 2^exponent is how many times we go around the loop,
44 * which takes 8 cycles. We want to start with a 16- to 31-cycle
45 * loop, so we need to go around minimum 2 = 2^1 times, so we
46 * bias the original value up by 1.
47 */
48 exponent = iterations + 1;
49
50 /*
51 * Don't allow exponent to exceed 7, so we have 128 loops,
52 * or 1,024 (to 2,047) cycles, as our maximum.
53 */
54 if (exponent > 8)
55 exponent = 8;
56
57 loops = 1 << exponent;
58
59 /* Add a randomness factor so two cpus never get in lock step. */
60 loops += __insn_crc32_32(stack_pointer, get_cycles_low()) &
61 (loops - 1);
62
63 relax(loops);
64}
diff --git a/arch/tile/lib/strchr_32.c b/arch/tile/lib/strchr_32.c
deleted file mode 100644
index 841fe6963019..000000000000
--- a/arch/tile/lib/strchr_32.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18
19char *strchr(const char *s, int c)
20{
21 int z, g;
22
23 /* Get an aligned pointer. */
24 const uintptr_t s_int = (uintptr_t) s;
25 const uint32_t *p = (const uint32_t *)(s_int & -4);
26
27 /* Create four copies of the byte for which we are looking. */
28 const uint32_t goal = 0x01010101 * (uint8_t) c;
29
30 /* Read the first aligned word, but force bytes before the string to
31 * match neither zero nor goal (we make sure the high bit of each
32 * byte is 1, and the low 7 bits are all the opposite of the goal
33 * byte).
34 *
35 * Note that this shift count expression works because we know shift
36 * counts are taken mod 32.
37 */
38 const uint32_t before_mask = (1 << (s_int << 3)) - 1;
39 uint32_t v = (*p | before_mask) ^ (goal & __insn_shrib(before_mask, 1));
40
41 uint32_t zero_matches, goal_matches;
42 while (1) {
43 /* Look for a terminating '\0'. */
44 zero_matches = __insn_seqb(v, 0);
45
46 /* Look for the goal byte. */
47 goal_matches = __insn_seqb(v, goal);
48
49 if (__builtin_expect(zero_matches | goal_matches, 0))
50 break;
51
52 v = *++p;
53 }
54
55 z = __insn_ctz(zero_matches);
56 g = __insn_ctz(goal_matches);
57
58 /* If we found c before '\0' we got a match. Note that if c == '\0'
59 * then g == z, and we correctly return the address of the '\0'
60 * rather than NULL.
61 */
62 return (g <= z) ? ((char *)p) + (g >> 3) : NULL;
63}
64EXPORT_SYMBOL(strchr);
diff --git a/arch/tile/lib/strchr_64.c b/arch/tile/lib/strchr_64.c
deleted file mode 100644
index fe6e31c06f8d..000000000000
--- a/arch/tile/lib/strchr_64.c
+++ /dev/null
@@ -1,62 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18#include "string-endian.h"
19
20char *strchr(const char *s, int c)
21{
22 int z, g;
23
24 /* Get an aligned pointer. */
25 const uintptr_t s_int = (uintptr_t) s;
26 const uint64_t *p = (const uint64_t *)(s_int & -8);
27
28 /* Create eight copies of the byte for which we are looking. */
29 const uint64_t goal = copy_byte(c);
30
31 /* Read the first aligned word, but force bytes before the string to
32 * match neither zero nor goal (we make sure the high bit of each
33 * byte is 1, and the low 7 bits are all the opposite of the goal
34 * byte).
35 */
36 const uint64_t before_mask = MASK(s_int);
37 uint64_t v = (*p | before_mask) ^ (goal & __insn_v1shrui(before_mask, 1));
38
39 uint64_t zero_matches, goal_matches;
40 while (1) {
41 /* Look for a terminating '\0'. */
42 zero_matches = __insn_v1cmpeqi(v, 0);
43
44 /* Look for the goal byte. */
45 goal_matches = __insn_v1cmpeq(v, goal);
46
47 if (__builtin_expect((zero_matches | goal_matches) != 0, 0))
48 break;
49
50 v = *++p;
51 }
52
53 z = CFZ(zero_matches);
54 g = CFZ(goal_matches);
55
56 /* If we found c before '\0' we got a match. Note that if c == '\0'
57 * then g == z, and we correctly return the address of the '\0'
58 * rather than NULL.
59 */
60 return (g <= z) ? ((char *)p) + (g >> 3) : NULL;
61}
62EXPORT_SYMBOL(strchr);
diff --git a/arch/tile/lib/string-endian.h b/arch/tile/lib/string-endian.h
deleted file mode 100644
index 2e49cbfe9371..000000000000
--- a/arch/tile/lib/string-endian.h
+++ /dev/null
@@ -1,44 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Provide a mask based on the pointer alignment that
15 * sets up non-zero bytes before the beginning of the string.
16 * The MASK expression works because shift counts are taken mod 64.
17 * Also, specify how to count "first" and "last" bits
18 * when the bits have been read as a word.
19 */
20
21#include <asm/byteorder.h>
22
23#ifdef __LITTLE_ENDIAN
24#define MASK(x) (__insn_shl(1ULL, (x << 3)) - 1)
25#define NULMASK(x) ((2ULL << x) - 1)
26#define CFZ(x) __insn_ctz(x)
27#define REVCZ(x) __insn_clz(x)
28#else
29#define MASK(x) (__insn_shl(-2LL, ((-x << 3) - 1)))
30#define NULMASK(x) (-2LL << (63 - x))
31#define CFZ(x) __insn_clz(x)
32#define REVCZ(x) __insn_ctz(x)
33#endif
34
35/*
36 * Create eight copies of the byte in a uint64_t. Byte Shuffle uses
37 * the bytes of srcB as the index into the dest vector to select a
38 * byte. With all indices of zero, the first byte is copied into all
39 * the other bytes.
40 */
41static inline uint64_t copy_byte(uint8_t byte)
42{
43 return __insn_shufflebytes(byte, 0, 0);
44}
diff --git a/arch/tile/lib/strlen_32.c b/arch/tile/lib/strlen_32.c
deleted file mode 100644
index f26f88e11e4a..000000000000
--- a/arch/tile/lib/strlen_32.c
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18
19size_t strlen(const char *s)
20{
21 /* Get an aligned pointer. */
22 const uintptr_t s_int = (uintptr_t) s;
23 const uint32_t *p = (const uint32_t *)(s_int & -4);
24
25 /* Read the first word, but force bytes before the string to be nonzero.
26 * This expression works because we know shift counts are taken mod 32.
27 */
28 uint32_t v = *p | ((1 << (s_int << 3)) - 1);
29
30 uint32_t bits;
31 while ((bits = __insn_seqb(v, 0)) == 0)
32 v = *++p;
33
34 return ((const char *)p) + (__insn_ctz(bits) >> 3) - s;
35}
36EXPORT_SYMBOL(strlen);
diff --git a/arch/tile/lib/strlen_64.c b/arch/tile/lib/strlen_64.c
deleted file mode 100644
index 9583fc3361fa..000000000000
--- a/arch/tile/lib/strlen_64.c
+++ /dev/null
@@ -1,35 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18#include "string-endian.h"
19
20size_t strlen(const char *s)
21{
22 /* Get an aligned pointer. */
23 const uintptr_t s_int = (uintptr_t) s;
24 const uint64_t *p = (const uint64_t *)(s_int & -8);
25
26 /* Read and MASK the first word. */
27 uint64_t v = *p | MASK(s_int);
28
29 uint64_t bits;
30 while ((bits = __insn_v1cmpeqi(v, 0)) == 0)
31 v = *++p;
32
33 return ((const char *)p) + (CFZ(bits) >> 3) - s;
34}
35EXPORT_SYMBOL(strlen);
diff --git a/arch/tile/lib/strnlen_32.c b/arch/tile/lib/strnlen_32.c
deleted file mode 100644
index 1434141d9e01..000000000000
--- a/arch/tile/lib/strnlen_32.c
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18
19size_t strnlen(const char *s, size_t count)
20{
21 /* Get an aligned pointer. */
22 const uintptr_t s_int = (uintptr_t) s;
23 const uint32_t *p = (const uint32_t *)(s_int & -4);
24 size_t bytes_read = sizeof(*p) - (s_int & (sizeof(*p) - 1));
25 size_t len;
26 uint32_t v, bits;
27
28 /* Avoid page fault risk by not reading any bytes when count is 0. */
29 if (count == 0)
30 return 0;
31
32 /* Read first word, but force bytes before the string to be nonzero. */
33 v = *p | ((1 << ((s_int << 3) & 31)) - 1);
34
35 while ((bits = __insn_seqb(v, 0)) == 0) {
36 if (bytes_read >= count) {
37 /* Read COUNT bytes and didn't find the terminator. */
38 return count;
39 }
40 v = *++p;
41 bytes_read += sizeof(v);
42 }
43
44 len = ((const char *) p) + (__insn_ctz(bits) >> 3) - s;
45 return (len < count ? len : count);
46}
47EXPORT_SYMBOL(strnlen);
diff --git a/arch/tile/lib/strnlen_64.c b/arch/tile/lib/strnlen_64.c
deleted file mode 100644
index 2e8de6a5136f..000000000000
--- a/arch/tile/lib/strnlen_64.c
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2 * Copyright 2013 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/types.h>
16#include <linux/string.h>
17#include <linux/module.h>
18#include "string-endian.h"
19
20size_t strnlen(const char *s, size_t count)
21{
22 /* Get an aligned pointer. */
23 const uintptr_t s_int = (uintptr_t) s;
24 const uint64_t *p = (const uint64_t *)(s_int & -8);
25 size_t bytes_read = sizeof(*p) - (s_int & (sizeof(*p) - 1));
26 size_t len;
27 uint64_t v, bits;
28
29 /* Avoid page fault risk by not reading any bytes when count is 0. */
30 if (count == 0)
31 return 0;
32
33 /* Read and MASK the first word. */
34 v = *p | MASK(s_int);
35
36 while ((bits = __insn_v1cmpeqi(v, 0)) == 0) {
37 if (bytes_read >= count) {
38 /* Read COUNT bytes and didn't find the terminator. */
39 return count;
40 }
41 v = *++p;
42 bytes_read += sizeof(v);
43 }
44
45 len = ((const char *) p) + (CFZ(bits) >> 3) - s;
46 return (len < count ? len : count);
47}
48EXPORT_SYMBOL(strnlen);
diff --git a/arch/tile/lib/uaccess.c b/arch/tile/lib/uaccess.c
deleted file mode 100644
index 030abe3ee4f1..000000000000
--- a/arch/tile/lib/uaccess.c
+++ /dev/null
@@ -1,24 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/uaccess.h>
16#include <linux/module.h>
17
18int __range_ok(unsigned long addr, unsigned long size)
19{
20 unsigned long limit = current_thread_info()->addr_limit.seg;
21 return !((addr < limit && size <= limit - addr) ||
22 is_arch_mappable_range(addr, size));
23}
24EXPORT_SYMBOL(__range_ok);
diff --git a/arch/tile/lib/usercopy_32.S b/arch/tile/lib/usercopy_32.S
deleted file mode 100644
index db93ad5fae25..000000000000
--- a/arch/tile/lib/usercopy_32.S
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/linkage.h>
16#include <asm/errno.h>
17#include <asm/cache.h>
18#include <arch/chip.h>
19
20/* Access user memory, but use MMU to avoid propagating kernel exceptions. */
21
22/*
23 * clear_user_asm takes the user target address in r0 and the
24 * number of bytes to zero in r1.
25 * It returns the number of uncopiable bytes (hopefully zero) in r0.
26 * Note that we don't use a separate .fixup section here since we fall
27 * through into the "fixup" code as the last straight-line bundle anyway.
28 */
29STD_ENTRY(clear_user_asm)
30 { bz r1, 2f; or r2, r0, r1 }
31 andi r2, r2, 3
32 bzt r2, .Lclear_aligned_user_asm
331: { sb r0, zero; addi r0, r0, 1; addi r1, r1, -1 }
34 bnzt r1, 1b
352: { move r0, r1; jrp lr }
36 .pushsection __ex_table,"a"
37 .align 4
38 .word 1b, 2b
39 .popsection
40
41.Lclear_aligned_user_asm:
421: { sw r0, zero; addi r0, r0, 4; addi r1, r1, -4 }
43 bnzt r1, 1b
442: { move r0, r1; jrp lr }
45 STD_ENDPROC(clear_user_asm)
46 .pushsection __ex_table,"a"
47 .align 4
48 .word 1b, 2b
49 .popsection
50
51/*
52 * flush_user_asm takes the user target address in r0 and the
53 * number of bytes to flush in r1.
54 * It returns the number of unflushable bytes (hopefully zero) in r0.
55 */
56STD_ENTRY(flush_user_asm)
57 bz r1, 2f
58 { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
59 { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
60 { and r0, r0, r2; and r1, r1, r2 }
61 { sub r1, r1, r0 }
621: { flush r0; addi r1, r1, -CHIP_FLUSH_STRIDE() }
63 { addi r0, r0, CHIP_FLUSH_STRIDE(); bnzt r1, 1b }
642: { move r0, r1; jrp lr }
65 STD_ENDPROC(flush_user_asm)
66 .pushsection __ex_table,"a"
67 .align 4
68 .word 1b, 2b
69 .popsection
70
71/*
72 * finv_user_asm takes the user target address in r0 and the
73 * number of bytes to flush-invalidate in r1.
74 * It returns the number of not finv'able bytes (hopefully zero) in r0.
75 */
76STD_ENTRY(finv_user_asm)
77 bz r1, 2f
78 { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
79 { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
80 { and r0, r0, r2; and r1, r1, r2 }
81 { sub r1, r1, r0 }
821: { finv r0; addi r1, r1, -CHIP_FINV_STRIDE() }
83 { addi r0, r0, CHIP_FINV_STRIDE(); bnzt r1, 1b }
842: { move r0, r1; jrp lr }
85 STD_ENDPROC(finv_user_asm)
86 .pushsection __ex_table,"a"
87 .align 4
88 .word 1b, 2b
89 .popsection
diff --git a/arch/tile/lib/usercopy_64.S b/arch/tile/lib/usercopy_64.S
deleted file mode 100644
index 9322dc551e91..000000000000
--- a/arch/tile/lib/usercopy_64.S
+++ /dev/null
@@ -1,89 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/linkage.h>
16#include <asm/errno.h>
17#include <asm/cache.h>
18#include <arch/chip.h>
19
20/* Access user memory, but use MMU to avoid propagating kernel exceptions. */
21
22/*
23 * clear_user_asm takes the user target address in r0 and the
24 * number of bytes to zero in r1.
25 * It returns the number of uncopiable bytes (hopefully zero) in r0.
26 * Note that we don't use a separate .fixup section here since we fall
27 * through into the "fixup" code as the last straight-line bundle anyway.
28 */
29STD_ENTRY(clear_user_asm)
30 { beqz r1, 2f; or r2, r0, r1 }
31 andi r2, r2, 7
32 beqzt r2, .Lclear_aligned_user_asm
331: { st1 r0, zero; addi r0, r0, 1; addi r1, r1, -1 }
34 bnezt r1, 1b
352: { move r0, r1; jrp lr }
36 .pushsection __ex_table,"a"
37 .align 8
38 .quad 1b, 2b
39 .popsection
40
41.Lclear_aligned_user_asm:
421: { st r0, zero; addi r0, r0, 8; addi r1, r1, -8 }
43 bnezt r1, 1b
442: { move r0, r1; jrp lr }
45 STD_ENDPROC(clear_user_asm)
46 .pushsection __ex_table,"a"
47 .align 8
48 .quad 1b, 2b
49 .popsection
50
51/*
52 * flush_user_asm takes the user target address in r0 and the
53 * number of bytes to flush in r1.
54 * It returns the number of unflushable bytes (hopefully zero) in r0.
55 */
56STD_ENTRY(flush_user_asm)
57 beqz r1, 2f
58 { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
59 { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
60 { and r0, r0, r2; and r1, r1, r2 }
61 { sub r1, r1, r0 }
621: { flush r0; addi r1, r1, -CHIP_FLUSH_STRIDE() }
63 { addi r0, r0, CHIP_FLUSH_STRIDE(); bnezt r1, 1b }
642: { move r0, r1; jrp lr }
65 STD_ENDPROC(flush_user_asm)
66 .pushsection __ex_table,"a"
67 .align 8
68 .quad 1b, 2b
69 .popsection
70
71/*
72 * finv_user_asm takes the user target address in r0 and the
73 * number of bytes to flush-invalidate in r1.
74 * It returns the number of not finv'able bytes (hopefully zero) in r0.
75 */
76STD_ENTRY(finv_user_asm)
77 beqz r1, 2f
78 { movei r2, L2_CACHE_BYTES; add r1, r0, r1 }
79 { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 }
80 { and r0, r0, r2; and r1, r1, r2 }
81 { sub r1, r1, r0 }
821: { finv r0; addi r1, r1, -CHIP_FINV_STRIDE() }
83 { addi r0, r0, CHIP_FINV_STRIDE(); bnezt r1, 1b }
842: { move r0, r1; jrp lr }
85 STD_ENDPROC(finv_user_asm)
86 .pushsection __ex_table,"a"
87 .align 8
88 .quad 1b, 2b
89 .popsection
diff --git a/arch/tile/mm/Makefile b/arch/tile/mm/Makefile
deleted file mode 100644
index e252aeddc17d..000000000000
--- a/arch/tile/mm/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
1#
2# Makefile for the linux tile-specific parts of the memory manager.
3#
4
5obj-y := init.o pgtable.o fault.o extable.o elf.o \
6 mmap.o homecache.o migrate_$(BITS).o
7
8obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
9obj-$(CONFIG_HIGHMEM) += highmem.o
diff --git a/arch/tile/mm/elf.c b/arch/tile/mm/elf.c
deleted file mode 100644
index 889901824400..000000000000
--- a/arch/tile/mm/elf.c
+++ /dev/null
@@ -1,165 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/mm.h>
16#include <linux/pagemap.h>
17#include <linux/binfmts.h>
18#include <linux/compat.h>
19#include <linux/mman.h>
20#include <linux/file.h>
21#include <linux/elf.h>
22#include <asm/pgtable.h>
23#include <asm/pgalloc.h>
24#include <asm/sections.h>
25#include <asm/vdso.h>
26#include <arch/sim.h>
27
28/* Notify a running simulator, if any, that an exec just occurred. */
29static void sim_notify_exec(const char *binary_name)
30{
31 unsigned char c;
32 do {
33 c = *binary_name++;
34 __insn_mtspr(SPR_SIM_CONTROL,
35 (SIM_CONTROL_OS_EXEC
36 | (c << _SIM_CONTROL_OPERATOR_BITS)));
37
38 } while (c);
39}
40
41static int notify_exec(struct mm_struct *mm)
42{
43 int ret = 0;
44 char *buf, *path;
45 struct vm_area_struct *vma;
46 struct file *exe_file;
47
48 if (!sim_is_simulator())
49 return 1;
50
51 buf = (char *) __get_free_page(GFP_KERNEL);
52 if (buf == NULL)
53 return 0;
54
55 exe_file = get_mm_exe_file(mm);
56 if (exe_file == NULL)
57 goto done_free;
58
59 path = file_path(exe_file, buf, PAGE_SIZE);
60 if (IS_ERR(path))
61 goto done_put;
62
63 down_read(&mm->mmap_sem);
64 for (vma = current->mm->mmap; ; vma = vma->vm_next) {
65 if (vma == NULL) {
66 up_read(&mm->mmap_sem);
67 goto done_put;
68 }
69 if (vma->vm_file == exe_file)
70 break;
71 }
72
73 /*
74 * Notify simulator of an ET_DYN object so we know the load address.
75 * The somewhat cryptic overuse of SIM_CONTROL_DLOPEN allows us
76 * to be backward-compatible with older simulator releases.
77 */
78 if (vma->vm_start == (ELF_ET_DYN_BASE & PAGE_MASK)) {
79 char buf[64];
80 int i;
81
82 snprintf(buf, sizeof(buf), "0x%lx:@", vma->vm_start);
83 for (i = 0; ; ++i) {
84 char c = buf[i];
85 __insn_mtspr(SPR_SIM_CONTROL,
86 (SIM_CONTROL_DLOPEN
87 | (c << _SIM_CONTROL_OPERATOR_BITS)));
88 if (c == '\0') {
89 ret = 1; /* success */
90 break;
91 }
92 }
93 }
94 up_read(&mm->mmap_sem);
95
96 sim_notify_exec(path);
97done_put:
98 fput(exe_file);
99done_free:
100 free_page((unsigned long)buf);
101 return ret;
102}
103
104/* Notify a running simulator, if any, that we loaded an interpreter. */
105static void sim_notify_interp(unsigned long load_addr)
106{
107 size_t i;
108 for (i = 0; i < sizeof(load_addr); i++) {
109 unsigned char c = load_addr >> (i * 8);
110 __insn_mtspr(SPR_SIM_CONTROL,
111 (SIM_CONTROL_OS_INTERP
112 | (c << _SIM_CONTROL_OPERATOR_BITS)));
113 }
114}
115
116
117int arch_setup_additional_pages(struct linux_binprm *bprm,
118 int executable_stack)
119{
120 struct mm_struct *mm = current->mm;
121 int retval = 0;
122
123 /*
124 * Notify the simulator that an exec just occurred.
125 * If we can't find the filename of the mapping, just use
126 * whatever was passed as the linux_binprm filename.
127 */
128 if (!notify_exec(mm))
129 sim_notify_exec(bprm->filename);
130
131 down_write(&mm->mmap_sem);
132
133 retval = setup_vdso_pages();
134
135#ifndef __tilegx__
136 /*
137 * Set up a user-interrupt mapping here; the user can't
138 * create one themselves since it is above TASK_SIZE.
139 * We make it unwritable by default, so the model for adding
140 * interrupt vectors always involves an mprotect.
141 */
142 if (!retval) {
143 unsigned long addr = MEM_USER_INTRPT;
144 addr = mmap_region(NULL, addr, INTRPT_SIZE,
145 VM_READ|VM_EXEC|
146 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC, 0, NULL);
147 if (addr > (unsigned long) -PAGE_SIZE)
148 retval = (int) addr;
149 }
150#endif
151
152 up_write(&mm->mmap_sem);
153
154 return retval;
155}
156
157
158void elf_plat_init(struct pt_regs *regs, unsigned long load_addr)
159{
160 /* Zero all registers. */
161 memset(regs, 0, sizeof(*regs));
162
163 /* Report the interpreter's load address. */
164 sim_notify_interp(load_addr);
165}
diff --git a/arch/tile/mm/extable.c b/arch/tile/mm/extable.c
deleted file mode 100644
index aeaf20c7aaa4..000000000000
--- a/arch/tile/mm/extable.c
+++ /dev/null
@@ -1,30 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/extable.h>
16#include <linux/spinlock.h>
17#include <linux/uaccess.h>
18
19int fixup_exception(struct pt_regs *regs)
20{
21 const struct exception_table_entry *fixup;
22
23 fixup = search_exception_tables(regs->pc);
24 if (fixup) {
25 regs->pc = fixup->fixup;
26 return 1;
27 }
28
29 return 0;
30}
diff --git a/arch/tile/mm/fault.c b/arch/tile/mm/fault.c
deleted file mode 100644
index f58fa06a2214..000000000000
--- a/arch/tile/mm/fault.c
+++ /dev/null
@@ -1,924 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * From i386 code copyright (C) 1995 Linus Torvalds
15 */
16
17#include <linux/signal.h>
18#include <linux/sched.h>
19#include <linux/sched/debug.h>
20#include <linux/sched/task.h>
21#include <linux/sched/task_stack.h>
22#include <linux/kernel.h>
23#include <linux/errno.h>
24#include <linux/string.h>
25#include <linux/types.h>
26#include <linux/ptrace.h>
27#include <linux/mman.h>
28#include <linux/mm.h>
29#include <linux/smp.h>
30#include <linux/interrupt.h>
31#include <linux/init.h>
32#include <linux/tty.h>
33#include <linux/vt_kern.h> /* For unblank_screen() */
34#include <linux/highmem.h>
35#include <linux/extable.h>
36#include <linux/kprobes.h>
37#include <linux/hugetlb.h>
38#include <linux/syscalls.h>
39#include <linux/uaccess.h>
40#include <linux/kdebug.h>
41
42#include <asm/pgalloc.h>
43#include <asm/sections.h>
44#include <asm/traps.h>
45#include <asm/syscalls.h>
46
47#include <arch/interrupts.h>
48
49static noinline void force_sig_info_fault(const char *type, int si_signo,
50 int si_code, unsigned long address,
51 int fault_num,
52 struct task_struct *tsk,
53 struct pt_regs *regs)
54{
55 siginfo_t info;
56
57 if (unlikely(tsk->pid < 2)) {
58 panic("Signal %d (code %d) at %#lx sent to %s!",
59 si_signo, si_code & 0xffff, address,
60 is_idle_task(tsk) ? "the idle task" : "init");
61 }
62
63 info.si_signo = si_signo;
64 info.si_errno = 0;
65 info.si_code = si_code;
66 info.si_addr = (void __user *)address;
67 info.si_trapno = fault_num;
68 trace_unhandled_signal(type, regs, address, si_signo);
69 force_sig_info(si_signo, &info, tsk);
70}
71
72#ifndef __tilegx__
73/*
74 * Synthesize the fault a PL0 process would get by doing a word-load of
75 * an unaligned address or a high kernel address.
76 */
77SYSCALL_DEFINE1(cmpxchg_badaddr, unsigned long, address)
78{
79 struct pt_regs *regs = current_pt_regs();
80
81 if (address >= PAGE_OFFSET)
82 force_sig_info_fault("atomic segfault", SIGSEGV, SEGV_MAPERR,
83 address, INT_DTLB_MISS, current, regs);
84 else
85 force_sig_info_fault("atomic alignment fault", SIGBUS,
86 BUS_ADRALN, address,
87 INT_UNALIGN_DATA, current, regs);
88
89 /*
90 * Adjust pc to point at the actual instruction, which is unusual
91 * for syscalls normally, but is appropriate when we are claiming
92 * that a syscall swint1 caused a page fault or bus error.
93 */
94 regs->pc -= 8;
95
96 /*
97 * Mark this as a caller-save interrupt, like a normal page fault,
98 * so that when we go through the signal handler path we will
99 * properly restore r0, r1, and r2 for the signal handler arguments.
100 */
101 regs->flags |= PT_FLAGS_CALLER_SAVES;
102
103 return 0;
104}
105#endif
106
107static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
108{
109 unsigned index = pgd_index(address);
110 pgd_t *pgd_k;
111 pud_t *pud, *pud_k;
112 pmd_t *pmd, *pmd_k;
113
114 pgd += index;
115 pgd_k = init_mm.pgd + index;
116
117 if (!pgd_present(*pgd_k))
118 return NULL;
119
120 pud = pud_offset(pgd, address);
121 pud_k = pud_offset(pgd_k, address);
122 if (!pud_present(*pud_k))
123 return NULL;
124
125 pmd = pmd_offset(pud, address);
126 pmd_k = pmd_offset(pud_k, address);
127 if (!pmd_present(*pmd_k))
128 return NULL;
129 if (!pmd_present(*pmd))
130 set_pmd(pmd, *pmd_k);
131 else
132 BUG_ON(pmd_ptfn(*pmd) != pmd_ptfn(*pmd_k));
133 return pmd_k;
134}
135
136/*
137 * Handle a fault on the vmalloc area.
138 */
139static inline int vmalloc_fault(pgd_t *pgd, unsigned long address)
140{
141 pmd_t *pmd_k;
142 pte_t *pte_k;
143
144 /* Make sure we are in vmalloc area */
145 if (!(address >= VMALLOC_START && address < VMALLOC_END))
146 return -1;
147
148 /*
149 * Synchronize this task's top level page-table
150 * with the 'reference' page table.
151 */
152 pmd_k = vmalloc_sync_one(pgd, address);
153 if (!pmd_k)
154 return -1;
155 pte_k = pte_offset_kernel(pmd_k, address);
156 if (!pte_present(*pte_k))
157 return -1;
158 return 0;
159}
160
161/* Wait until this PTE has completed migration. */
162static void wait_for_migration(pte_t *pte)
163{
164 if (pte_migrating(*pte)) {
165 /*
166 * Wait until the migrater fixes up this pte.
167 * We scale the loop count by the clock rate so we'll wait for
168 * a few seconds here.
169 */
170 int retries = 0;
171 int bound = get_clock_rate();
172 while (pte_migrating(*pte)) {
173 barrier();
174 if (++retries > bound)
175 panic("Hit migrating PTE (%#llx) and page PFN %#lx still migrating",
176 pte->val, pte_pfn(*pte));
177 }
178 }
179}
180
181/*
182 * It's not generally safe to use "current" to get the page table pointer,
183 * since we might be running an oprofile interrupt in the middle of a
184 * task switch.
185 */
186static pgd_t *get_current_pgd(void)
187{
188 HV_Context ctx = hv_inquire_context();
189 unsigned long pgd_pfn = ctx.page_table >> PAGE_SHIFT;
190 struct page *pgd_page = pfn_to_page(pgd_pfn);
191 BUG_ON(PageHighMem(pgd_page));
192 return (pgd_t *) __va(ctx.page_table);
193}
194
195/*
196 * We can receive a page fault from a migrating PTE at any time.
197 * Handle it by just waiting until the fault resolves.
198 *
199 * It's also possible to get a migrating kernel PTE that resolves
200 * itself during the downcall from hypervisor to Linux. We just check
201 * here to see if the PTE seems valid, and if so we retry it.
202 *
203 * NOTE! We MUST NOT take any locks for this case. We may be in an
204 * interrupt or a critical region, and must do as little as possible.
205 * Similarly, we can't use atomic ops here, since we may be handling a
206 * fault caused by an atomic op access.
207 *
208 * If we find a migrating PTE while we're in an NMI context, and we're
209 * at a PC that has a registered exception handler, we don't wait,
210 * since this thread may (e.g.) have been interrupted while migrating
211 * its own stack, which would then cause us to self-deadlock.
212 */
213static int handle_migrating_pte(pgd_t *pgd, int fault_num,
214 unsigned long address, unsigned long pc,
215 int is_kernel_mode, int write)
216{
217 pud_t *pud;
218 pmd_t *pmd;
219 pte_t *pte;
220 pte_t pteval;
221
222 if (pgd_addr_invalid(address))
223 return 0;
224
225 pgd += pgd_index(address);
226 pud = pud_offset(pgd, address);
227 if (!pud || !pud_present(*pud))
228 return 0;
229 pmd = pmd_offset(pud, address);
230 if (!pmd || !pmd_present(*pmd))
231 return 0;
232 pte = pmd_huge_page(*pmd) ? ((pte_t *)pmd) :
233 pte_offset_kernel(pmd, address);
234 pteval = *pte;
235 if (pte_migrating(pteval)) {
236 if (in_nmi() && search_exception_tables(pc))
237 return 0;
238 wait_for_migration(pte);
239 return 1;
240 }
241
242 if (!is_kernel_mode || !pte_present(pteval))
243 return 0;
244 if (fault_num == INT_ITLB_MISS) {
245 if (pte_exec(pteval))
246 return 1;
247 } else if (write) {
248 if (pte_write(pteval))
249 return 1;
250 } else {
251 if (pte_read(pteval))
252 return 1;
253 }
254
255 return 0;
256}
257
258/*
259 * This routine is responsible for faulting in user pages.
260 * It passes the work off to one of the appropriate routines.
261 * It returns true if the fault was successfully handled.
262 */
263static int handle_page_fault(struct pt_regs *regs,
264 int fault_num,
265 int is_page_fault,
266 unsigned long address,
267 int write)
268{
269 struct task_struct *tsk;
270 struct mm_struct *mm;
271 struct vm_area_struct *vma;
272 unsigned long stack_offset;
273 int fault;
274 int si_code;
275 int is_kernel_mode;
276 pgd_t *pgd;
277 unsigned int flags;
278
279 /* on TILE, protection faults are always writes */
280 if (!is_page_fault)
281 write = 1;
282
283 flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
284
285 is_kernel_mode = !user_mode(regs);
286
287 tsk = validate_current();
288
289 /*
290 * Check to see if we might be overwriting the stack, and bail
291 * out if so. The page fault code is a relatively likely
292 * place to get trapped in an infinite regress, and once we
293 * overwrite the whole stack, it becomes very hard to recover.
294 */
295 stack_offset = stack_pointer & (THREAD_SIZE-1);
296 if (stack_offset < THREAD_SIZE / 8) {
297 pr_alert("Potential stack overrun: sp %#lx\n", stack_pointer);
298 show_regs(regs);
299 pr_alert("Killing current process %d/%s\n",
300 tsk->pid, tsk->comm);
301 do_group_exit(SIGKILL);
302 }
303
304 /*
305 * Early on, we need to check for migrating PTE entries;
306 * see homecache.c. If we find a migrating PTE, we wait until
307 * the backing page claims to be done migrating, then we proceed.
308 * For kernel PTEs, we rewrite the PTE and return and retry.
309 * Otherwise, we treat the fault like a normal "no PTE" fault,
310 * rather than trying to patch up the existing PTE.
311 */
312 pgd = get_current_pgd();
313 if (handle_migrating_pte(pgd, fault_num, address, regs->pc,
314 is_kernel_mode, write))
315 return 1;
316
317 si_code = SEGV_MAPERR;
318
319 /*
320 * We fault-in kernel-space virtual memory on-demand. The
321 * 'reference' page table is init_mm.pgd.
322 *
323 * NOTE! We MUST NOT take any locks for this case. We may
324 * be in an interrupt or a critical region, and should
325 * only copy the information from the master page table,
326 * nothing more.
327 *
328 * This verifies that the fault happens in kernel space
329 * and that the fault was not a protection fault.
330 */
331 if (unlikely(address >= TASK_SIZE &&
332 !is_arch_mappable_range(address, 0))) {
333 if (is_kernel_mode && is_page_fault &&
334 vmalloc_fault(pgd, address) >= 0)
335 return 1;
336 /*
337 * Don't take the mm semaphore here. If we fixup a prefetch
338 * fault we could otherwise deadlock.
339 */
340 mm = NULL; /* happy compiler */
341 vma = NULL;
342 goto bad_area_nosemaphore;
343 }
344
345 /*
346 * If we're trying to touch user-space addresses, we must
347 * be either at PL0, or else with interrupts enabled in the
348 * kernel, so either way we can re-enable interrupts here
349 * unless we are doing atomic access to user space with
350 * interrupts disabled.
351 */
352 if (!(regs->flags & PT_FLAGS_DISABLE_IRQ))
353 local_irq_enable();
354
355 mm = tsk->mm;
356
357 /*
358 * If we're in an interrupt, have no user context or are running in an
359 * region with pagefaults disabled then we must not take the fault.
360 */
361 if (pagefault_disabled() || !mm) {
362 vma = NULL; /* happy compiler */
363 goto bad_area_nosemaphore;
364 }
365
366 if (!is_kernel_mode)
367 flags |= FAULT_FLAG_USER;
368
369 /*
370 * When running in the kernel we expect faults to occur only to
371 * addresses in user space. All other faults represent errors in the
372 * kernel and should generate an OOPS. Unfortunately, in the case of an
373 * erroneous fault occurring in a code path which already holds mmap_sem
374 * we will deadlock attempting to validate the fault against the
375 * address space. Luckily the kernel only validly references user
376 * space from well defined areas of code, which are listed in the
377 * exceptions table.
378 *
379 * As the vast majority of faults will be valid we will only perform
380 * the source reference check when there is a possibility of a deadlock.
381 * Attempt to lock the address space, if we cannot we then validate the
382 * source. If this is invalid we can skip the address space check,
383 * thus avoiding the deadlock.
384 */
385 if (!down_read_trylock(&mm->mmap_sem)) {
386 if (is_kernel_mode &&
387 !search_exception_tables(regs->pc)) {
388 vma = NULL; /* happy compiler */
389 goto bad_area_nosemaphore;
390 }
391
392retry:
393 down_read(&mm->mmap_sem);
394 }
395
396 vma = find_vma(mm, address);
397 if (!vma)
398 goto bad_area;
399 if (vma->vm_start <= address)
400 goto good_area;
401 if (!(vma->vm_flags & VM_GROWSDOWN))
402 goto bad_area;
403 if (regs->sp < PAGE_OFFSET) {
404 /*
405 * accessing the stack below sp is always a bug.
406 */
407 if (address < regs->sp)
408 goto bad_area;
409 }
410 if (expand_stack(vma, address))
411 goto bad_area;
412
413/*
414 * Ok, we have a good vm_area for this memory access, so
415 * we can handle it..
416 */
417good_area:
418 si_code = SEGV_ACCERR;
419 if (fault_num == INT_ITLB_MISS) {
420 if (!(vma->vm_flags & VM_EXEC))
421 goto bad_area;
422 } else if (write) {
423#ifdef TEST_VERIFY_AREA
424 if (!is_page_fault && regs->cs == KERNEL_CS)
425 pr_err("WP fault at " REGFMT "\n", regs->eip);
426#endif
427 if (!(vma->vm_flags & VM_WRITE))
428 goto bad_area;
429 flags |= FAULT_FLAG_WRITE;
430 } else {
431 if (!is_page_fault || !(vma->vm_flags & VM_READ))
432 goto bad_area;
433 }
434
435 /*
436 * If for any reason at all we couldn't handle the fault,
437 * make sure we exit gracefully rather than endlessly redo
438 * the fault.
439 */
440 fault = handle_mm_fault(vma, address, flags);
441
442 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
443 return 0;
444
445 if (unlikely(fault & VM_FAULT_ERROR)) {
446 if (fault & VM_FAULT_OOM)
447 goto out_of_memory;
448 else if (fault & VM_FAULT_SIGSEGV)
449 goto bad_area;
450 else if (fault & VM_FAULT_SIGBUS)
451 goto do_sigbus;
452 BUG();
453 }
454 if (flags & FAULT_FLAG_ALLOW_RETRY) {
455 if (fault & VM_FAULT_MAJOR)
456 tsk->maj_flt++;
457 else
458 tsk->min_flt++;
459 if (fault & VM_FAULT_RETRY) {
460 flags &= ~FAULT_FLAG_ALLOW_RETRY;
461 flags |= FAULT_FLAG_TRIED;
462
463 /*
464 * No need to up_read(&mm->mmap_sem) as we would
465 * have already released it in __lock_page_or_retry
466 * in mm/filemap.c.
467 */
468 goto retry;
469 }
470 }
471
472#if CHIP_HAS_TILE_DMA()
473 /* If this was a DMA TLB fault, restart the DMA engine. */
474 switch (fault_num) {
475 case INT_DMATLB_MISS:
476 case INT_DMATLB_MISS_DWNCL:
477 case INT_DMATLB_ACCESS:
478 case INT_DMATLB_ACCESS_DWNCL:
479 __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);
480 break;
481 }
482#endif
483
484 up_read(&mm->mmap_sem);
485 return 1;
486
487/*
488 * Something tried to access memory that isn't in our memory map..
489 * Fix it, but check if it's kernel or user first..
490 */
491bad_area:
492 up_read(&mm->mmap_sem);
493
494bad_area_nosemaphore:
495 /* User mode accesses just cause a SIGSEGV */
496 if (!is_kernel_mode) {
497 /*
498 * It's possible to have interrupts off here.
499 */
500 local_irq_enable();
501
502 force_sig_info_fault("segfault", SIGSEGV, si_code, address,
503 fault_num, tsk, regs);
504 return 0;
505 }
506
507no_context:
508 /* Are we prepared to handle this kernel fault? */
509 if (fixup_exception(regs))
510 return 0;
511
512/*
513 * Oops. The kernel tried to access some bad page. We'll have to
514 * terminate things with extreme prejudice.
515 */
516
517 bust_spinlocks(1);
518
519 /* FIXME: no lookup_address() yet */
520#ifdef SUPPORT_LOOKUP_ADDRESS
521 if (fault_num == INT_ITLB_MISS) {
522 pte_t *pte = lookup_address(address);
523
524 if (pte && pte_present(*pte) && !pte_exec_kernel(*pte))
525 pr_crit("kernel tried to execute non-executable page - exploit attempt? (uid: %d)\n",
526 current->uid);
527 }
528#endif
529 if (address < PAGE_SIZE)
530 pr_alert("Unable to handle kernel NULL pointer dereference\n");
531 else
532 pr_alert("Unable to handle kernel paging request\n");
533 pr_alert(" at virtual address " REGFMT ", pc " REGFMT "\n",
534 address, regs->pc);
535
536 show_regs(regs);
537
538 if (unlikely(tsk->pid < 2)) {
539 panic("Kernel page fault running %s!",
540 is_idle_task(tsk) ? "the idle task" : "init");
541 }
542
543 /*
544 * More FIXME: we should probably copy the i386 here and
545 * implement a generic die() routine. Not today.
546 */
547#ifdef SUPPORT_DIE
548 die("Oops", regs);
549#endif
550 bust_spinlocks(1);
551
552 do_group_exit(SIGKILL);
553
554/*
555 * We ran out of memory, or some other thing happened to us that made
556 * us unable to handle the page fault gracefully.
557 */
558out_of_memory:
559 up_read(&mm->mmap_sem);
560 if (is_kernel_mode)
561 goto no_context;
562 pagefault_out_of_memory();
563 return 0;
564
565do_sigbus:
566 up_read(&mm->mmap_sem);
567
568 /* Kernel mode? Handle exceptions or die */
569 if (is_kernel_mode)
570 goto no_context;
571
572 force_sig_info_fault("bus error", SIGBUS, BUS_ADRERR, address,
573 fault_num, tsk, regs);
574 return 0;
575}
576
577#ifndef __tilegx__
578
579/* We must release ICS before panicking or we won't get anywhere. */
580#define ics_panic(fmt, ...) \
581do { \
582 __insn_mtspr(SPR_INTERRUPT_CRITICAL_SECTION, 0); \
583 panic(fmt, ##__VA_ARGS__); \
584} while (0)
585
586/*
587 * When we take an ITLB or DTLB fault or access violation in the
588 * supervisor while the critical section bit is set, the hypervisor is
589 * reluctant to write new values into the EX_CONTEXT_K_x registers,
590 * since that might indicate we have not yet squirreled the SPR
591 * contents away and can thus safely take a recursive interrupt.
592 * Accordingly, the hypervisor passes us the PC via SYSTEM_SAVE_K_2.
593 *
594 * Note that this routine is called before homecache_tlb_defer_enter(),
595 * which means that we can properly unlock any atomics that might
596 * be used there (good), but also means we must be very sensitive
597 * to not touch any data structures that might be located in memory
598 * that could migrate, as we could be entering the kernel on a dataplane
599 * cpu that has been deferring kernel TLB updates. This means, for
600 * example, that we can't migrate init_mm or its pgd.
601 */
602struct intvec_state do_page_fault_ics(struct pt_regs *regs, int fault_num,
603 unsigned long address,
604 unsigned long info)
605{
606 unsigned long pc = info & ~1;
607 int write = info & 1;
608 pgd_t *pgd = get_current_pgd();
609
610 /* Retval is 1 at first since we will handle the fault fully. */
611 struct intvec_state state = {
612 do_page_fault, fault_num, address, write, 1
613 };
614
615 /* Validate that we are plausibly in the right routine. */
616 if ((pc & 0x7) != 0 || pc < PAGE_OFFSET ||
617 (fault_num != INT_DTLB_MISS &&
618 fault_num != INT_DTLB_ACCESS)) {
619 unsigned long old_pc = regs->pc;
620 regs->pc = pc;
621 ics_panic("Bad ICS page fault args: old PC %#lx, fault %d/%d at %#lx",
622 old_pc, fault_num, write, address);
623 }
624
625 /* We might be faulting on a vmalloc page, so check that first. */
626 if (fault_num != INT_DTLB_ACCESS && vmalloc_fault(pgd, address) >= 0)
627 return state;
628
629 /*
630 * If we faulted with ICS set in sys_cmpxchg, we are providing
631 * a user syscall service that should generate a signal on
632 * fault. We didn't set up a kernel stack on initial entry to
633 * sys_cmpxchg, but instead had one set up by the fault, which
634 * (because sys_cmpxchg never releases ICS) came to us via the
635 * SYSTEM_SAVE_K_2 mechanism, and thus EX_CONTEXT_K_[01] are
636 * still referencing the original user code. We release the
637 * atomic lock and rewrite pt_regs so that it appears that we
638 * came from user-space directly, and after we finish the
639 * fault we'll go back to user space and re-issue the swint.
640 * This way the backtrace information is correct if we need to
641 * emit a stack dump at any point while handling this.
642 *
643 * Must match register use in sys_cmpxchg().
644 */
645 if (pc >= (unsigned long) sys_cmpxchg &&
646 pc < (unsigned long) __sys_cmpxchg_end) {
647#ifdef CONFIG_SMP
648 /* Don't unlock before we could have locked. */
649 if (pc >= (unsigned long)__sys_cmpxchg_grab_lock) {
650 int *lock_ptr = (int *)(regs->regs[ATOMIC_LOCK_REG]);
651 __atomic_fault_unlock(lock_ptr);
652 }
653#endif
654 regs->sp = regs->regs[27];
655 }
656
657 /*
658 * We can also fault in the atomic assembly, in which
659 * case we use the exception table to do the first-level fixup.
660 * We may re-fixup again in the real fault handler if it
661 * turns out the faulting address is just bad, and not,
662 * for example, migrating.
663 */
664 else if (pc >= (unsigned long) __start_atomic_asm_code &&
665 pc < (unsigned long) __end_atomic_asm_code) {
666 const struct exception_table_entry *fixup;
667#ifdef CONFIG_SMP
668 /* Unlock the atomic lock. */
669 int *lock_ptr = (int *)(regs->regs[ATOMIC_LOCK_REG]);
670 __atomic_fault_unlock(lock_ptr);
671#endif
672 fixup = search_exception_tables(pc);
673 if (!fixup)
674 ics_panic("ICS atomic fault not in table: PC %#lx, fault %d",
675 pc, fault_num);
676 regs->pc = fixup->fixup;
677 regs->ex1 = PL_ICS_EX1(KERNEL_PL, 0);
678 }
679
680 /*
681 * Now that we have released the atomic lock (if necessary),
682 * it's safe to spin if the PTE that caused the fault was migrating.
683 */
684 if (fault_num == INT_DTLB_ACCESS)
685 write = 1;
686 if (handle_migrating_pte(pgd, fault_num, address, pc, 1, write))
687 return state;
688
689 /* Return zero so that we continue on with normal fault handling. */
690 state.retval = 0;
691 return state;
692}
693
694#endif /* !__tilegx__ */
695
696/*
697 * This routine handles page faults. It determines the address, and the
698 * problem, and then passes it handle_page_fault() for normal DTLB and
699 * ITLB issues, and for DMA or SN processor faults when we are in user
700 * space. For the latter, if we're in kernel mode, we just save the
701 * interrupt away appropriately and return immediately. We can't do
702 * page faults for user code while in kernel mode.
703 */
704static inline void __do_page_fault(struct pt_regs *regs, int fault_num,
705 unsigned long address, unsigned long write)
706{
707 int is_page_fault;
708
709#ifdef CONFIG_KPROBES
710 /*
711 * This is to notify the fault handler of the kprobes. The
712 * exception code is redundant as it is also carried in REGS,
713 * but we pass it anyhow.
714 */
715 if (notify_die(DIE_PAGE_FAULT, "page fault", regs, -1,
716 regs->faultnum, SIGSEGV) == NOTIFY_STOP)
717 return;
718#endif
719
720#ifdef __tilegx__
721 /*
722 * We don't need early do_page_fault_ics() support, since unlike
723 * Pro we don't need to worry about unlocking the atomic locks.
724 * There is only one current case in GX where we touch any memory
725 * under ICS other than our own kernel stack, and we handle that
726 * here. (If we crash due to trying to touch our own stack,
727 * we're in too much trouble for C code to help out anyway.)
728 */
729 if (write & ~1) {
730 unsigned long pc = write & ~1;
731 if (pc >= (unsigned long) __start_unalign_asm_code &&
732 pc < (unsigned long) __end_unalign_asm_code) {
733 struct thread_info *ti = current_thread_info();
734 /*
735 * Our EX_CONTEXT is still what it was from the
736 * initial unalign exception, but now we've faulted
737 * on the JIT page. We would like to complete the
738 * page fault however is appropriate, and then retry
739 * the instruction that caused the unalign exception.
740 * Our state has been "corrupted" by setting the low
741 * bit in "sp", and stashing r0..r3 in the
742 * thread_info area, so we revert all of that, then
743 * continue as if this were a normal page fault.
744 */
745 regs->sp &= ~1UL;
746 regs->regs[0] = ti->unalign_jit_tmp[0];
747 regs->regs[1] = ti->unalign_jit_tmp[1];
748 regs->regs[2] = ti->unalign_jit_tmp[2];
749 regs->regs[3] = ti->unalign_jit_tmp[3];
750 write &= 1;
751 } else {
752 pr_alert("%s/%d: ICS set at page fault at %#lx: %#lx\n",
753 current->comm, current->pid, pc, address);
754 show_regs(regs);
755 do_group_exit(SIGKILL);
756 }
757 }
758#else
759 /* This case should have been handled by do_page_fault_ics(). */
760 BUG_ON(write & ~1);
761#endif
762
763#if CHIP_HAS_TILE_DMA()
764 /*
765 * If it's a DMA fault, suspend the transfer while we're
766 * handling the miss; we'll restart after it's handled. If we
767 * don't suspend, it's possible that this process could swap
768 * out and back in, and restart the engine since the DMA is
769 * still 'running'.
770 */
771 if (fault_num == INT_DMATLB_MISS ||
772 fault_num == INT_DMATLB_ACCESS ||
773 fault_num == INT_DMATLB_MISS_DWNCL ||
774 fault_num == INT_DMATLB_ACCESS_DWNCL) {
775 __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__SUSPEND_MASK);
776 while (__insn_mfspr(SPR_DMA_USER_STATUS) &
777 SPR_DMA_STATUS__BUSY_MASK)
778 ;
779 }
780#endif
781
782 /* Validate fault num and decide if this is a first-time page fault. */
783 switch (fault_num) {
784 case INT_ITLB_MISS:
785 case INT_DTLB_MISS:
786#if CHIP_HAS_TILE_DMA()
787 case INT_DMATLB_MISS:
788 case INT_DMATLB_MISS_DWNCL:
789#endif
790 is_page_fault = 1;
791 break;
792
793 case INT_DTLB_ACCESS:
794#if CHIP_HAS_TILE_DMA()
795 case INT_DMATLB_ACCESS:
796 case INT_DMATLB_ACCESS_DWNCL:
797#endif
798 is_page_fault = 0;
799 break;
800
801 default:
802 panic("Bad fault number %d in do_page_fault", fault_num);
803 }
804
805#if CHIP_HAS_TILE_DMA()
806 if (!user_mode(regs)) {
807 struct async_tlb *async;
808 switch (fault_num) {
809#if CHIP_HAS_TILE_DMA()
810 case INT_DMATLB_MISS:
811 case INT_DMATLB_ACCESS:
812 case INT_DMATLB_MISS_DWNCL:
813 case INT_DMATLB_ACCESS_DWNCL:
814 async = &current->thread.dma_async_tlb;
815 break;
816#endif
817 default:
818 async = NULL;
819 }
820 if (async) {
821
822 /*
823 * No vmalloc check required, so we can allow
824 * interrupts immediately at this point.
825 */
826 local_irq_enable();
827
828 set_thread_flag(TIF_ASYNC_TLB);
829 if (async->fault_num != 0) {
830 panic("Second async fault %d; old fault was %d (%#lx/%ld)",
831 fault_num, async->fault_num,
832 address, write);
833 }
834 BUG_ON(fault_num == 0);
835 async->fault_num = fault_num;
836 async->is_fault = is_page_fault;
837 async->is_write = write;
838 async->address = address;
839 return;
840 }
841 }
842#endif
843
844 handle_page_fault(regs, fault_num, is_page_fault, address, write);
845}
846
847void do_page_fault(struct pt_regs *regs, int fault_num,
848 unsigned long address, unsigned long write)
849{
850 __do_page_fault(regs, fault_num, address, write);
851}
852
853#if CHIP_HAS_TILE_DMA()
854/*
855 * This routine effectively re-issues asynchronous page faults
856 * when we are returning to user space.
857 */
858void do_async_page_fault(struct pt_regs *regs)
859{
860 struct async_tlb *async = &current->thread.dma_async_tlb;
861
862 /*
863 * Clear thread flag early. If we re-interrupt while processing
864 * code here, we will reset it and recall this routine before
865 * returning to user space.
866 */
867 clear_thread_flag(TIF_ASYNC_TLB);
868
869 if (async->fault_num) {
870 /*
871 * Clear async->fault_num before calling the page-fault
872 * handler so that if we re-interrupt before returning
873 * from the function we have somewhere to put the
874 * information from the new interrupt.
875 */
876 int fault_num = async->fault_num;
877 async->fault_num = 0;
878 handle_page_fault(regs, fault_num, async->is_fault,
879 async->address, async->is_write);
880 }
881}
882#endif /* CHIP_HAS_TILE_DMA() */
883
884
885void vmalloc_sync_all(void)
886{
887#ifdef __tilegx__
888 /* Currently all L1 kernel pmd's are static and shared. */
889 BUILD_BUG_ON(pgd_index(VMALLOC_END - PAGE_SIZE) !=
890 pgd_index(VMALLOC_START));
891#else
892 /*
893 * Note that races in the updates of insync and start aren't
894 * problematic: insync can only get set bits added, and updates to
895 * start are only improving performance (without affecting correctness
896 * if undone).
897 */
898 static DECLARE_BITMAP(insync, PTRS_PER_PGD);
899 static unsigned long start = PAGE_OFFSET;
900 unsigned long address;
901
902 BUILD_BUG_ON(PAGE_OFFSET & ~PGDIR_MASK);
903 for (address = start; address >= PAGE_OFFSET; address += PGDIR_SIZE) {
904 if (!test_bit(pgd_index(address), insync)) {
905 unsigned long flags;
906 struct list_head *pos;
907
908 spin_lock_irqsave(&pgd_lock, flags);
909 list_for_each(pos, &pgd_list)
910 if (!vmalloc_sync_one(list_to_pgd(pos),
911 address)) {
912 /* Must be at first entry in list. */
913 BUG_ON(pos != pgd_list.next);
914 break;
915 }
916 spin_unlock_irqrestore(&pgd_lock, flags);
917 if (pos != pgd_list.next)
918 set_bit(pgd_index(address), insync);
919 }
920 if (address == start && test_bit(pgd_index(address), insync))
921 start = address + PGDIR_SIZE;
922 }
923#endif
924}
diff --git a/arch/tile/mm/highmem.c b/arch/tile/mm/highmem.c
deleted file mode 100644
index eca28551b22d..000000000000
--- a/arch/tile/mm/highmem.c
+++ /dev/null
@@ -1,277 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/highmem.h>
16#include <linux/module.h>
17#include <linux/pagemap.h>
18#include <asm/homecache.h>
19
20#define kmap_get_pte(vaddr) \
21 pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), (vaddr)),\
22 (vaddr)), (vaddr))
23
24
25void *kmap(struct page *page)
26{
27 void *kva;
28 unsigned long flags;
29 pte_t *ptep;
30
31 might_sleep();
32 if (!PageHighMem(page))
33 return page_address(page);
34 kva = kmap_high(page);
35
36 /*
37 * Rewrite the PTE under the lock. This ensures that the page
38 * is not currently migrating.
39 */
40 ptep = kmap_get_pte((unsigned long)kva);
41 flags = homecache_kpte_lock();
42 set_pte_at(&init_mm, kva, ptep, mk_pte(page, page_to_kpgprot(page)));
43 homecache_kpte_unlock(flags);
44
45 return kva;
46}
47EXPORT_SYMBOL(kmap);
48
49void kunmap(struct page *page)
50{
51 if (in_interrupt())
52 BUG();
53 if (!PageHighMem(page))
54 return;
55 kunmap_high(page);
56}
57EXPORT_SYMBOL(kunmap);
58
59/*
60 * Describe a single atomic mapping of a page on a given cpu at a
61 * given address, and allow it to be linked into a list.
62 */
63struct atomic_mapped_page {
64 struct list_head list;
65 struct page *page;
66 int cpu;
67 unsigned long va;
68};
69
70static spinlock_t amp_lock = __SPIN_LOCK_UNLOCKED(&amp_lock);
71static struct list_head amp_list = LIST_HEAD_INIT(amp_list);
72
73/*
74 * Combining this structure with a per-cpu declaration lets us give
75 * each cpu an atomic_mapped_page structure per type.
76 */
77struct kmap_amps {
78 struct atomic_mapped_page per_type[KM_TYPE_NR];
79};
80static DEFINE_PER_CPU(struct kmap_amps, amps);
81
82/*
83 * Add a page and va, on this cpu, to the list of kmap_atomic pages,
84 * and write the new pte to memory. Writing the new PTE under the
85 * lock guarantees that it is either on the list before migration starts
86 * (if we won the race), or set_pte() sets the migrating bit in the PTE
87 * (if we lost the race). And doing it under the lock guarantees
88 * that when kmap_atomic_fix_one_pte() comes along, it finds a valid
89 * PTE in memory, iff the mapping is still on the amp_list.
90 *
91 * Finally, doing it under the lock lets us safely examine the page
92 * to see if it is immutable or not, for the generic kmap_atomic() case.
93 * If we examine it earlier we are exposed to a race where it looks
94 * writable earlier, but becomes immutable before we write the PTE.
95 */
96static void kmap_atomic_register(struct page *page, int type,
97 unsigned long va, pte_t *ptep, pte_t pteval)
98{
99 unsigned long flags;
100 struct atomic_mapped_page *amp;
101
102 flags = homecache_kpte_lock();
103 spin_lock(&amp_lock);
104
105 /* With interrupts disabled, now fill in the per-cpu info. */
106 amp = this_cpu_ptr(&amps.per_type[type]);
107 amp->page = page;
108 amp->cpu = smp_processor_id();
109 amp->va = va;
110
111 /* For generic kmap_atomic(), choose the PTE writability now. */
112 if (!pte_read(pteval))
113 pteval = mk_pte(page, page_to_kpgprot(page));
114
115 list_add(&amp->list, &amp_list);
116 set_pte(ptep, pteval);
117
118 spin_unlock(&amp_lock);
119 homecache_kpte_unlock(flags);
120}
121
122/*
123 * Remove a page and va, on this cpu, from the list of kmap_atomic pages.
124 * Linear-time search, but we count on the lists being short.
125 * We don't need to adjust the PTE under the lock (as opposed to the
126 * kmap_atomic_register() case), since we're just unconditionally
127 * zeroing the PTE after it's off the list.
128 */
129static void kmap_atomic_unregister(struct page *page, unsigned long va)
130{
131 unsigned long flags;
132 struct atomic_mapped_page *amp;
133 int cpu = smp_processor_id();
134 spin_lock_irqsave(&amp_lock, flags);
135 list_for_each_entry(amp, &amp_list, list) {
136 if (amp->page == page && amp->cpu == cpu && amp->va == va)
137 break;
138 }
139 BUG_ON(&amp->list == &amp_list);
140 list_del(&amp->list);
141 spin_unlock_irqrestore(&amp_lock, flags);
142}
143
144/* Helper routine for kmap_atomic_fix_kpte(), below. */
145static void kmap_atomic_fix_one_kpte(struct atomic_mapped_page *amp,
146 int finished)
147{
148 pte_t *ptep = kmap_get_pte(amp->va);
149 if (!finished) {
150 set_pte(ptep, pte_mkmigrate(*ptep));
151 flush_remote(0, 0, NULL, amp->va, PAGE_SIZE, PAGE_SIZE,
152 cpumask_of(amp->cpu), NULL, 0);
153 } else {
154 /*
155 * Rewrite a default kernel PTE for this page.
156 * We rely on the fact that set_pte() writes the
157 * present+migrating bits last.
158 */
159 pte_t pte = mk_pte(amp->page, page_to_kpgprot(amp->page));
160 set_pte(ptep, pte);
161 }
162}
163
164/*
165 * This routine is a helper function for homecache_fix_kpte(); see
166 * its comments for more information on the "finished" argument here.
167 *
168 * Note that we hold the lock while doing the remote flushes, which
169 * will stall any unrelated cpus trying to do kmap_atomic operations.
170 * We could just update the PTEs under the lock, and save away copies
171 * of the structs (or just the va+cpu), then flush them after we
172 * release the lock, but it seems easier just to do it all under the lock.
173 */
174void kmap_atomic_fix_kpte(struct page *page, int finished)
175{
176 struct atomic_mapped_page *amp;
177 unsigned long flags;
178 spin_lock_irqsave(&amp_lock, flags);
179 list_for_each_entry(amp, &amp_list, list) {
180 if (amp->page == page)
181 kmap_atomic_fix_one_kpte(amp, finished);
182 }
183 spin_unlock_irqrestore(&amp_lock, flags);
184}
185
186/*
187 * kmap_atomic/kunmap_atomic is significantly faster than kmap/kunmap
188 * because the kmap code must perform a global TLB invalidation when
189 * the kmap pool wraps.
190 *
191 * Note that they may be slower than on x86 (etc.) because unlike on
192 * those platforms, we do have to take a global lock to map and unmap
193 * pages on Tile (see above).
194 *
195 * When holding an atomic kmap is is not legal to sleep, so atomic
196 * kmaps are appropriate for short, tight code paths only.
197 */
198void *kmap_atomic_prot(struct page *page, pgprot_t prot)
199{
200 unsigned long vaddr;
201 int idx, type;
202 pte_t *pte;
203
204 preempt_disable();
205 pagefault_disable();
206
207 /* Avoid icache flushes by disallowing atomic executable mappings. */
208 BUG_ON(pte_exec(prot));
209
210 if (!PageHighMem(page))
211 return page_address(page);
212
213 type = kmap_atomic_idx_push();
214 idx = type + KM_TYPE_NR*smp_processor_id();
215 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
216 pte = kmap_get_pte(vaddr);
217 BUG_ON(!pte_none(*pte));
218
219 /* Register that this page is mapped atomically on this cpu. */
220 kmap_atomic_register(page, type, vaddr, pte, mk_pte(page, prot));
221
222 return (void *)vaddr;
223}
224EXPORT_SYMBOL(kmap_atomic_prot);
225
226void *kmap_atomic(struct page *page)
227{
228 /* PAGE_NONE is a magic value that tells us to check immutability. */
229 return kmap_atomic_prot(page, PAGE_NONE);
230}
231EXPORT_SYMBOL(kmap_atomic);
232
233void __kunmap_atomic(void *kvaddr)
234{
235 unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
236
237 if (vaddr >= __fix_to_virt(FIX_KMAP_END) &&
238 vaddr <= __fix_to_virt(FIX_KMAP_BEGIN)) {
239 pte_t *pte = kmap_get_pte(vaddr);
240 pte_t pteval = *pte;
241 int idx, type;
242
243 type = kmap_atomic_idx();
244 idx = type + KM_TYPE_NR*smp_processor_id();
245
246 /*
247 * Force other mappings to Oops if they try to access this pte
248 * without first remapping it. Keeping stale mappings around
249 * is a bad idea.
250 */
251 BUG_ON(!pte_present(pteval) && !pte_migrating(pteval));
252 kmap_atomic_unregister(pte_page(pteval), vaddr);
253 kpte_clear_flush(pte, vaddr);
254 kmap_atomic_idx_pop();
255 } else {
256 /* Must be a lowmem page */
257 BUG_ON(vaddr < PAGE_OFFSET);
258 BUG_ON(vaddr >= (unsigned long)high_memory);
259 }
260
261 pagefault_enable();
262 preempt_enable();
263}
264EXPORT_SYMBOL(__kunmap_atomic);
265
266/*
267 * This API is supposed to allow us to map memory without a "struct page".
268 * Currently we don't support this, though this may change in the future.
269 */
270void *kmap_atomic_pfn(unsigned long pfn)
271{
272 return kmap_atomic(pfn_to_page(pfn));
273}
274void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
275{
276 return kmap_atomic_prot(pfn_to_page(pfn), prot);
277}
diff --git a/arch/tile/mm/homecache.c b/arch/tile/mm/homecache.c
deleted file mode 100644
index 4432f31e8479..000000000000
--- a/arch/tile/mm/homecache.c
+++ /dev/null
@@ -1,428 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * This code maintains the "home" for each page in the system.
15 */
16
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/spinlock.h>
20#include <linux/list.h>
21#include <linux/bootmem.h>
22#include <linux/rmap.h>
23#include <linux/pagemap.h>
24#include <linux/mutex.h>
25#include <linux/interrupt.h>
26#include <linux/sysctl.h>
27#include <linux/pagevec.h>
28#include <linux/ptrace.h>
29#include <linux/timex.h>
30#include <linux/cache.h>
31#include <linux/smp.h>
32#include <linux/module.h>
33#include <linux/hugetlb.h>
34
35#include <asm/page.h>
36#include <asm/sections.h>
37#include <asm/tlbflush.h>
38#include <asm/pgalloc.h>
39#include <asm/homecache.h>
40
41#include <arch/sim.h>
42
43#include "migrate.h"
44
45
46/*
47 * The noallocl2 option suppresses all use of the L2 cache to cache
48 * locally from a remote home.
49 */
50static int __ro_after_init noallocl2;
51static int __init set_noallocl2(char *str)
52{
53 noallocl2 = 1;
54 return 0;
55}
56early_param("noallocl2", set_noallocl2);
57
58
59/*
60 * Update the irq_stat for cpus that we are going to interrupt
61 * with TLB or cache flushes. Also handle removing dataplane cpus
62 * from the TLB flush set, and setting dataplane_tlb_state instead.
63 */
64static void hv_flush_update(const struct cpumask *cache_cpumask,
65 struct cpumask *tlb_cpumask,
66 unsigned long tlb_va, unsigned long tlb_length,
67 HV_Remote_ASID *asids, int asidcount)
68{
69 struct cpumask mask;
70 int i, cpu;
71
72 cpumask_clear(&mask);
73 if (cache_cpumask)
74 cpumask_or(&mask, &mask, cache_cpumask);
75 if (tlb_cpumask && tlb_length) {
76 cpumask_or(&mask, &mask, tlb_cpumask);
77 }
78
79 for (i = 0; i < asidcount; ++i)
80 cpumask_set_cpu(asids[i].y * smp_width + asids[i].x, &mask);
81
82 /*
83 * Don't bother to update atomically; losing a count
84 * here is not that critical.
85 */
86 for_each_cpu(cpu, &mask)
87 ++per_cpu(irq_stat, cpu).irq_hv_flush_count;
88}
89
90/*
91 * This wrapper function around hv_flush_remote() does several things:
92 *
93 * - Provides a return value error-checking panic path, since
94 * there's never any good reason for hv_flush_remote() to fail.
95 * - Accepts a 32-bit PFN rather than a 64-bit PA, which generally
96 * is the type that Linux wants to pass around anyway.
97 * - Canonicalizes that lengths of zero make cpumasks NULL.
98 * - Handles deferring TLB flushes for dataplane tiles.
99 * - Tracks remote interrupts in the per-cpu irq_cpustat_t.
100 *
101 * Note that we have to wait until the cache flush completes before
102 * updating the per-cpu last_cache_flush word, since otherwise another
103 * concurrent flush can race, conclude the flush has already
104 * completed, and start to use the page while it's still dirty
105 * remotely (running concurrently with the actual evict, presumably).
106 */
107void flush_remote(unsigned long cache_pfn, unsigned long cache_control,
108 const struct cpumask *cache_cpumask_orig,
109 HV_VirtAddr tlb_va, unsigned long tlb_length,
110 unsigned long tlb_pgsize,
111 const struct cpumask *tlb_cpumask_orig,
112 HV_Remote_ASID *asids, int asidcount)
113{
114 int rc;
115 struct cpumask cache_cpumask_copy, tlb_cpumask_copy;
116 struct cpumask *cache_cpumask, *tlb_cpumask;
117 HV_PhysAddr cache_pa;
118
119 mb(); /* provided just to simplify "magic hypervisor" mode */
120
121 /*
122 * Canonicalize and copy the cpumasks.
123 */
124 if (cache_cpumask_orig && cache_control) {
125 cpumask_copy(&cache_cpumask_copy, cache_cpumask_orig);
126 cache_cpumask = &cache_cpumask_copy;
127 } else {
128 cpumask_clear(&cache_cpumask_copy);
129 cache_cpumask = NULL;
130 }
131 if (cache_cpumask == NULL)
132 cache_control = 0;
133 if (tlb_cpumask_orig && tlb_length) {
134 cpumask_copy(&tlb_cpumask_copy, tlb_cpumask_orig);
135 tlb_cpumask = &tlb_cpumask_copy;
136 } else {
137 cpumask_clear(&tlb_cpumask_copy);
138 tlb_cpumask = NULL;
139 }
140
141 hv_flush_update(cache_cpumask, tlb_cpumask, tlb_va, tlb_length,
142 asids, asidcount);
143 cache_pa = (HV_PhysAddr)cache_pfn << PAGE_SHIFT;
144 rc = hv_flush_remote(cache_pa, cache_control,
145 cpumask_bits(cache_cpumask),
146 tlb_va, tlb_length, tlb_pgsize,
147 cpumask_bits(tlb_cpumask),
148 asids, asidcount);
149 if (rc == 0)
150 return;
151
152 pr_err("hv_flush_remote(%#llx, %#lx, %p [%*pb], %#lx, %#lx, %#lx, %p [%*pb], %p, %d) = %d\n",
153 cache_pa, cache_control, cache_cpumask,
154 cpumask_pr_args(&cache_cpumask_copy),
155 (unsigned long)tlb_va, tlb_length, tlb_pgsize, tlb_cpumask,
156 cpumask_pr_args(&tlb_cpumask_copy), asids, asidcount, rc);
157 panic("Unsafe to continue.");
158}
159
160static void homecache_finv_page_va(void* va, int home)
161{
162 int cpu = get_cpu();
163 if (home == cpu) {
164 finv_buffer_local(va, PAGE_SIZE);
165 } else if (home == PAGE_HOME_HASH) {
166 finv_buffer_remote(va, PAGE_SIZE, 1);
167 } else {
168 BUG_ON(home < 0 || home >= NR_CPUS);
169 finv_buffer_remote(va, PAGE_SIZE, 0);
170 }
171 put_cpu();
172}
173
174void homecache_finv_map_page(struct page *page, int home)
175{
176 unsigned long flags;
177 unsigned long va;
178 pte_t *ptep;
179 pte_t pte;
180
181 if (home == PAGE_HOME_UNCACHED)
182 return;
183 local_irq_save(flags);
184#ifdef CONFIG_HIGHMEM
185 va = __fix_to_virt(FIX_KMAP_BEGIN + kmap_atomic_idx_push() +
186 (KM_TYPE_NR * smp_processor_id()));
187#else
188 va = __fix_to_virt(FIX_HOMECACHE_BEGIN + smp_processor_id());
189#endif
190 ptep = virt_to_kpte(va);
191 pte = pfn_pte(page_to_pfn(page), PAGE_KERNEL);
192 __set_pte(ptep, pte_set_home(pte, home));
193 homecache_finv_page_va((void *)va, home);
194 __pte_clear(ptep);
195 hv_flush_page(va, PAGE_SIZE);
196#ifdef CONFIG_HIGHMEM
197 kmap_atomic_idx_pop();
198#endif
199 local_irq_restore(flags);
200}
201
202static void homecache_finv_page_home(struct page *page, int home)
203{
204 if (!PageHighMem(page) && home == page_home(page))
205 homecache_finv_page_va(page_address(page), home);
206 else
207 homecache_finv_map_page(page, home);
208}
209
210static inline bool incoherent_home(int home)
211{
212 return home == PAGE_HOME_IMMUTABLE || home == PAGE_HOME_INCOHERENT;
213}
214
215static void homecache_finv_page_internal(struct page *page, int force_map)
216{
217 int home = page_home(page);
218 if (home == PAGE_HOME_UNCACHED)
219 return;
220 if (incoherent_home(home)) {
221 int cpu;
222 for_each_cpu(cpu, &cpu_cacheable_map)
223 homecache_finv_map_page(page, cpu);
224 } else if (force_map) {
225 /* Force if, e.g., the normal mapping is migrating. */
226 homecache_finv_map_page(page, home);
227 } else {
228 homecache_finv_page_home(page, home);
229 }
230 sim_validate_lines_evicted(PFN_PHYS(page_to_pfn(page)), PAGE_SIZE);
231}
232
233void homecache_finv_page(struct page *page)
234{
235 homecache_finv_page_internal(page, 0);
236}
237
238void homecache_evict(const struct cpumask *mask)
239{
240 flush_remote(0, HV_FLUSH_EVICT_L2, mask, 0, 0, 0, NULL, NULL, 0);
241}
242
243/* Report the home corresponding to a given PTE. */
244static int pte_to_home(pte_t pte)
245{
246 if (hv_pte_get_nc(pte))
247 return PAGE_HOME_IMMUTABLE;
248 switch (hv_pte_get_mode(pte)) {
249 case HV_PTE_MODE_CACHE_TILE_L3:
250 return get_remote_cache_cpu(pte);
251 case HV_PTE_MODE_CACHE_NO_L3:
252 return PAGE_HOME_INCOHERENT;
253 case HV_PTE_MODE_UNCACHED:
254 return PAGE_HOME_UNCACHED;
255 case HV_PTE_MODE_CACHE_HASH_L3:
256 return PAGE_HOME_HASH;
257 }
258 panic("Bad PTE %#llx\n", pte.val);
259}
260
261/* Update the home of a PTE if necessary (can also be used for a pgprot_t). */
262pte_t pte_set_home(pte_t pte, int home)
263{
264#if CHIP_HAS_MMIO()
265 /* Check for MMIO mappings and pass them through. */
266 if (hv_pte_get_mode(pte) == HV_PTE_MODE_MMIO)
267 return pte;
268#endif
269
270
271 /*
272 * Only immutable pages get NC mappings. If we have a
273 * non-coherent PTE, but the underlying page is not
274 * immutable, it's likely the result of a forced
275 * caching setting running up against ptrace setting
276 * the page to be writable underneath. In this case,
277 * just keep the PTE coherent.
278 */
279 if (hv_pte_get_nc(pte) && home != PAGE_HOME_IMMUTABLE) {
280 pte = hv_pte_clear_nc(pte);
281 pr_err("non-immutable page incoherently referenced: %#llx\n",
282 pte.val);
283 }
284
285 switch (home) {
286
287 case PAGE_HOME_UNCACHED:
288 pte = hv_pte_set_mode(pte, HV_PTE_MODE_UNCACHED);
289 break;
290
291 case PAGE_HOME_INCOHERENT:
292 pte = hv_pte_set_mode(pte, HV_PTE_MODE_CACHE_NO_L3);
293 break;
294
295 case PAGE_HOME_IMMUTABLE:
296 /*
297 * We could home this page anywhere, since it's immutable,
298 * but by default just home it to follow "hash_default".
299 */
300 BUG_ON(hv_pte_get_writable(pte));
301 if (pte_get_forcecache(pte)) {
302 /* Upgrade "force any cpu" to "No L3" for immutable. */
303 if (hv_pte_get_mode(pte) == HV_PTE_MODE_CACHE_TILE_L3
304 && pte_get_anyhome(pte)) {
305 pte = hv_pte_set_mode(pte,
306 HV_PTE_MODE_CACHE_NO_L3);
307 }
308 } else
309 if (hash_default)
310 pte = hv_pte_set_mode(pte, HV_PTE_MODE_CACHE_HASH_L3);
311 else
312 pte = hv_pte_set_mode(pte, HV_PTE_MODE_CACHE_NO_L3);
313 pte = hv_pte_set_nc(pte);
314 break;
315
316 case PAGE_HOME_HASH:
317 pte = hv_pte_set_mode(pte, HV_PTE_MODE_CACHE_HASH_L3);
318 break;
319
320 default:
321 BUG_ON(home < 0 || home >= NR_CPUS ||
322 !cpu_is_valid_lotar(home));
323 pte = hv_pte_set_mode(pte, HV_PTE_MODE_CACHE_TILE_L3);
324 pte = set_remote_cache_cpu(pte, home);
325 break;
326 }
327
328 if (noallocl2)
329 pte = hv_pte_set_no_alloc_l2(pte);
330
331 /* Simplify "no local and no l3" to "uncached" */
332 if (hv_pte_get_no_alloc_l2(pte) && hv_pte_get_no_alloc_l1(pte) &&
333 hv_pte_get_mode(pte) == HV_PTE_MODE_CACHE_NO_L3) {
334 pte = hv_pte_set_mode(pte, HV_PTE_MODE_UNCACHED);
335 }
336
337 /* Checking this case here gives a better panic than from the hv. */
338 BUG_ON(hv_pte_get_mode(pte) == 0);
339
340 return pte;
341}
342EXPORT_SYMBOL(pte_set_home);
343
344/*
345 * The routines in this section are the "static" versions of the normal
346 * dynamic homecaching routines; they just set the home cache
347 * of a kernel page once, and require a full-chip cache/TLB flush,
348 * so they're not suitable for anything but infrequent use.
349 */
350
351int page_home(struct page *page)
352{
353 if (PageHighMem(page)) {
354 return PAGE_HOME_HASH;
355 } else {
356 unsigned long kva = (unsigned long)page_address(page);
357 return pte_to_home(*virt_to_kpte(kva));
358 }
359}
360EXPORT_SYMBOL(page_home);
361
362void homecache_change_page_home(struct page *page, int order, int home)
363{
364 int i, pages = (1 << order);
365 unsigned long kva;
366
367 BUG_ON(PageHighMem(page));
368 BUG_ON(page_count(page) > 1);
369 BUG_ON(page_mapcount(page) != 0);
370 kva = (unsigned long) page_address(page);
371 flush_remote(0, HV_FLUSH_EVICT_L2, &cpu_cacheable_map,
372 kva, pages * PAGE_SIZE, PAGE_SIZE, cpu_online_mask,
373 NULL, 0);
374
375 for (i = 0; i < pages; ++i, kva += PAGE_SIZE) {
376 pte_t *ptep = virt_to_kpte(kva);
377 pte_t pteval = *ptep;
378 BUG_ON(!pte_present(pteval) || pte_huge(pteval));
379 __set_pte(ptep, pte_set_home(pteval, home));
380 }
381}
382EXPORT_SYMBOL(homecache_change_page_home);
383
384struct page *homecache_alloc_pages(gfp_t gfp_mask,
385 unsigned int order, int home)
386{
387 struct page *page;
388 BUG_ON(gfp_mask & __GFP_HIGHMEM); /* must be lowmem */
389 page = alloc_pages(gfp_mask, order);
390 if (page)
391 homecache_change_page_home(page, order, home);
392 return page;
393}
394EXPORT_SYMBOL(homecache_alloc_pages);
395
396struct page *homecache_alloc_pages_node(int nid, gfp_t gfp_mask,
397 unsigned int order, int home)
398{
399 struct page *page;
400 BUG_ON(gfp_mask & __GFP_HIGHMEM); /* must be lowmem */
401 page = alloc_pages_node(nid, gfp_mask, order);
402 if (page)
403 homecache_change_page_home(page, order, home);
404 return page;
405}
406
407void __homecache_free_pages(struct page *page, unsigned int order)
408{
409 if (put_page_testzero(page)) {
410 homecache_change_page_home(page, order, PAGE_HOME_HASH);
411 if (order == 0) {
412 free_unref_page(page);
413 } else {
414 init_page_count(page);
415 __free_pages(page, order);
416 }
417 }
418}
419EXPORT_SYMBOL(__homecache_free_pages);
420
421void homecache_free_pages(unsigned long addr, unsigned int order)
422{
423 if (addr != 0) {
424 VM_BUG_ON(!virt_addr_valid((void *)addr));
425 __homecache_free_pages(virt_to_page((void *)addr), order);
426 }
427}
428EXPORT_SYMBOL(homecache_free_pages);
diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
deleted file mode 100644
index 0986d426a413..000000000000
--- a/arch/tile/mm/hugetlbpage.c
+++ /dev/null
@@ -1,348 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * TILE Huge TLB Page Support for Kernel.
15 * Taken from i386 hugetlb implementation:
16 * Copyright (C) 2002, Rohit Seth <rohit.seth@intel.com>
17 */
18
19#include <linux/init.h>
20#include <linux/fs.h>
21#include <linux/mm.h>
22#include <linux/sched/mm.h>
23#include <linux/hugetlb.h>
24#include <linux/pagemap.h>
25#include <linux/slab.h>
26#include <linux/err.h>
27#include <linux/sysctl.h>
28#include <linux/mman.h>
29#include <asm/tlb.h>
30#include <asm/tlbflush.h>
31#include <asm/setup.h>
32
33#ifdef CONFIG_HUGETLB_SUPER_PAGES
34
35/*
36 * Provide an additional huge page size (in addition to the regular default
37 * huge page size) if no "hugepagesz" arguments are specified.
38 * Note that it must be smaller than the default huge page size so
39 * that it's possible to allocate them on demand from the buddy allocator.
40 * You can change this to 64K (on a 16K build), 256K, 1M, or 4M,
41 * or not define it at all.
42 */
43#define ADDITIONAL_HUGE_SIZE (1024 * 1024UL)
44
45/* "Extra" page-size multipliers, one per level of the page table. */
46int huge_shift[HUGE_SHIFT_ENTRIES] = {
47#ifdef ADDITIONAL_HUGE_SIZE
48#define ADDITIONAL_HUGE_SHIFT __builtin_ctzl(ADDITIONAL_HUGE_SIZE / PAGE_SIZE)
49 [HUGE_SHIFT_PAGE] = ADDITIONAL_HUGE_SHIFT
50#endif
51};
52
53#endif
54
55pte_t *huge_pte_alloc(struct mm_struct *mm,
56 unsigned long addr, unsigned long sz)
57{
58 pgd_t *pgd;
59 pud_t *pud;
60
61 addr &= -sz; /* Mask off any low bits in the address. */
62
63 pgd = pgd_offset(mm, addr);
64 pud = pud_alloc(mm, pgd, addr);
65
66#ifdef CONFIG_HUGETLB_SUPER_PAGES
67 if (sz >= PGDIR_SIZE) {
68 BUG_ON(sz != PGDIR_SIZE &&
69 sz != PGDIR_SIZE << huge_shift[HUGE_SHIFT_PGDIR]);
70 return (pte_t *)pud;
71 } else {
72 pmd_t *pmd = pmd_alloc(mm, pud, addr);
73 if (sz >= PMD_SIZE) {
74 BUG_ON(sz != PMD_SIZE &&
75 sz != (PMD_SIZE << huge_shift[HUGE_SHIFT_PMD]));
76 return (pte_t *)pmd;
77 }
78 else {
79 if (sz != PAGE_SIZE << huge_shift[HUGE_SHIFT_PAGE])
80 panic("Unexpected page size %#lx\n", sz);
81 return pte_alloc_map(mm, pmd, addr);
82 }
83 }
84#else
85 BUG_ON(sz != PMD_SIZE);
86 return (pte_t *) pmd_alloc(mm, pud, addr);
87#endif
88}
89
90static pte_t *get_pte(pte_t *base, int index, int level)
91{
92 pte_t *ptep = base + index;
93#ifdef CONFIG_HUGETLB_SUPER_PAGES
94 if (!pte_present(*ptep) && huge_shift[level] != 0) {
95 unsigned long mask = -1UL << huge_shift[level];
96 pte_t *super_ptep = base + (index & mask);
97 pte_t pte = *super_ptep;
98 if (pte_present(pte) && pte_super(pte))
99 ptep = super_ptep;
100 }
101#endif
102 return ptep;
103}
104
105pte_t *huge_pte_offset(struct mm_struct *mm,
106 unsigned long addr, unsigned long sz)
107{
108 pgd_t *pgd;
109 pud_t *pud;
110 pmd_t *pmd;
111#ifdef CONFIG_HUGETLB_SUPER_PAGES
112 pte_t *pte;
113#endif
114
115 /* Get the top-level page table entry. */
116 pgd = (pgd_t *)get_pte((pte_t *)mm->pgd, pgd_index(addr), 0);
117
118 /* We don't have four levels. */
119 pud = pud_offset(pgd, addr);
120#ifndef __PAGETABLE_PUD_FOLDED
121# error support fourth page table level
122#endif
123 if (!pud_present(*pud))
124 return NULL;
125
126 /* Check for an L0 huge PTE, if we have three levels. */
127#ifndef __PAGETABLE_PMD_FOLDED
128 if (pud_huge(*pud))
129 return (pte_t *)pud;
130
131 pmd = (pmd_t *)get_pte((pte_t *)pud_page_vaddr(*pud),
132 pmd_index(addr), 1);
133 if (!pmd_present(*pmd))
134 return NULL;
135#else
136 pmd = pmd_offset(pud, addr);
137#endif
138
139 /* Check for an L1 huge PTE. */
140 if (pmd_huge(*pmd))
141 return (pte_t *)pmd;
142
143#ifdef CONFIG_HUGETLB_SUPER_PAGES
144 /* Check for an L2 huge PTE. */
145 pte = get_pte((pte_t *)pmd_page_vaddr(*pmd), pte_index(addr), 2);
146 if (!pte_present(*pte))
147 return NULL;
148 if (pte_super(*pte))
149 return pte;
150#endif
151
152 return NULL;
153}
154
155int pmd_huge(pmd_t pmd)
156{
157 return !!(pmd_val(pmd) & _PAGE_HUGE_PAGE);
158}
159
160int pud_huge(pud_t pud)
161{
162 return !!(pud_val(pud) & _PAGE_HUGE_PAGE);
163}
164
165#ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
166static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
167 unsigned long addr, unsigned long len,
168 unsigned long pgoff, unsigned long flags)
169{
170 struct hstate *h = hstate_file(file);
171 struct vm_unmapped_area_info info;
172
173 info.flags = 0;
174 info.length = len;
175 info.low_limit = TASK_UNMAPPED_BASE;
176 info.high_limit = TASK_SIZE;
177 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
178 info.align_offset = 0;
179 return vm_unmapped_area(&info);
180}
181
182static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
183 unsigned long addr0, unsigned long len,
184 unsigned long pgoff, unsigned long flags)
185{
186 struct hstate *h = hstate_file(file);
187 struct vm_unmapped_area_info info;
188 unsigned long addr;
189
190 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
191 info.length = len;
192 info.low_limit = PAGE_SIZE;
193 info.high_limit = current->mm->mmap_base;
194 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
195 info.align_offset = 0;
196 addr = vm_unmapped_area(&info);
197
198 /*
199 * A failed mmap() very likely causes application failure,
200 * so fall back to the bottom-up function here. This scenario
201 * can happen with large stack limits and large mmap()
202 * allocations.
203 */
204 if (addr & ~PAGE_MASK) {
205 VM_BUG_ON(addr != -ENOMEM);
206 info.flags = 0;
207 info.low_limit = TASK_UNMAPPED_BASE;
208 info.high_limit = TASK_SIZE;
209 addr = vm_unmapped_area(&info);
210 }
211
212 return addr;
213}
214
215unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
216 unsigned long len, unsigned long pgoff, unsigned long flags)
217{
218 struct hstate *h = hstate_file(file);
219 struct mm_struct *mm = current->mm;
220 struct vm_area_struct *vma;
221
222 if (len & ~huge_page_mask(h))
223 return -EINVAL;
224 if (len > TASK_SIZE)
225 return -ENOMEM;
226
227 if (flags & MAP_FIXED) {
228 if (prepare_hugepage_range(file, addr, len))
229 return -EINVAL;
230 return addr;
231 }
232
233 if (addr) {
234 addr = ALIGN(addr, huge_page_size(h));
235 vma = find_vma(mm, addr);
236 if (TASK_SIZE - len >= addr &&
237 (!vma || addr + len <= vm_start_gap(vma)))
238 return addr;
239 }
240 if (current->mm->get_unmapped_area == arch_get_unmapped_area)
241 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
242 pgoff, flags);
243 else
244 return hugetlb_get_unmapped_area_topdown(file, addr, len,
245 pgoff, flags);
246}
247#endif /* HAVE_ARCH_HUGETLB_UNMAPPED_AREA */
248
249#ifdef CONFIG_HUGETLB_SUPER_PAGES
250static __init int __setup_hugepagesz(unsigned long ps)
251{
252 int log_ps = __builtin_ctzl(ps);
253 int level, base_shift;
254
255 if ((1UL << log_ps) != ps || (log_ps & 1) != 0) {
256 pr_warn("Not enabling %ld byte huge pages; must be a power of four\n",
257 ps);
258 return -EINVAL;
259 }
260
261 if (ps > 64*1024*1024*1024UL) {
262 pr_warn("Not enabling %ld MB huge pages; largest legal value is 64 GB\n",
263 ps >> 20);
264 return -EINVAL;
265 } else if (ps >= PUD_SIZE) {
266 static long hv_jpage_size;
267 if (hv_jpage_size == 0)
268 hv_jpage_size = hv_sysconf(HV_SYSCONF_PAGE_SIZE_JUMBO);
269 if (hv_jpage_size != PUD_SIZE) {
270 pr_warn("Not enabling >= %ld MB huge pages: hypervisor reports size %ld\n",
271 PUD_SIZE >> 20, hv_jpage_size);
272 return -EINVAL;
273 }
274 level = 0;
275 base_shift = PUD_SHIFT;
276 } else if (ps >= PMD_SIZE) {
277 level = 1;
278 base_shift = PMD_SHIFT;
279 } else if (ps > PAGE_SIZE) {
280 level = 2;
281 base_shift = PAGE_SHIFT;
282 } else {
283 pr_err("hugepagesz: huge page size %ld too small\n", ps);
284 return -EINVAL;
285 }
286
287 if (log_ps != base_shift) {
288 int shift_val = log_ps - base_shift;
289 if (huge_shift[level] != 0) {
290 int old_shift = base_shift + huge_shift[level];
291 pr_warn("Not enabling %ld MB huge pages; already have size %ld MB\n",
292 ps >> 20, (1UL << old_shift) >> 20);
293 return -EINVAL;
294 }
295 if (hv_set_pte_super_shift(level, shift_val) != 0) {
296 pr_warn("Not enabling %ld MB huge pages; no hypervisor support\n",
297 ps >> 20);
298 return -EINVAL;
299 }
300 printk(KERN_DEBUG "Enabled %ld MB huge pages\n", ps >> 20);
301 huge_shift[level] = shift_val;
302 }
303
304 hugetlb_add_hstate(log_ps - PAGE_SHIFT);
305
306 return 0;
307}
308
309static bool saw_hugepagesz;
310
311static __init int setup_hugepagesz(char *opt)
312{
313 int rc;
314
315 if (!saw_hugepagesz) {
316 saw_hugepagesz = true;
317 memset(huge_shift, 0, sizeof(huge_shift));
318 }
319 rc = __setup_hugepagesz(memparse(opt, NULL));
320 if (rc)
321 hugetlb_bad_size();
322 return rc;
323}
324__setup("hugepagesz=", setup_hugepagesz);
325
326#ifdef ADDITIONAL_HUGE_SIZE
327/*
328 * Provide an additional huge page size if no "hugepagesz" args are given.
329 * In that case, all the cores have properly set up their hv super_shift
330 * already, but we need to notify the hugetlb code to enable the
331 * new huge page size from the Linux point of view.
332 */
333static __init int add_default_hugepagesz(void)
334{
335 if (!saw_hugepagesz) {
336 BUILD_BUG_ON(ADDITIONAL_HUGE_SIZE >= PMD_SIZE ||
337 ADDITIONAL_HUGE_SIZE <= PAGE_SIZE);
338 BUILD_BUG_ON((PAGE_SIZE << ADDITIONAL_HUGE_SHIFT) !=
339 ADDITIONAL_HUGE_SIZE);
340 BUILD_BUG_ON(ADDITIONAL_HUGE_SHIFT & 1);
341 hugetlb_add_hstate(ADDITIONAL_HUGE_SHIFT);
342 }
343 return 0;
344}
345arch_initcall(add_default_hugepagesz);
346#endif
347
348#endif /* CONFIG_HUGETLB_SUPER_PAGES */
diff --git a/arch/tile/mm/init.c b/arch/tile/mm/init.c
deleted file mode 100644
index 5f757e04bcd2..000000000000
--- a/arch/tile/mm/init.c
+++ /dev/null
@@ -1,956 +0,0 @@
1/*
2 * Copyright (C) 1995 Linus Torvalds
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#include <linux/module.h>
17#include <linux/signal.h>
18#include <linux/sched.h>
19#include <linux/kernel.h>
20#include <linux/errno.h>
21#include <linux/string.h>
22#include <linux/types.h>
23#include <linux/ptrace.h>
24#include <linux/mman.h>
25#include <linux/mm.h>
26#include <linux/hugetlb.h>
27#include <linux/swap.h>
28#include <linux/smp.h>
29#include <linux/init.h>
30#include <linux/highmem.h>
31#include <linux/pagemap.h>
32#include <linux/poison.h>
33#include <linux/bootmem.h>
34#include <linux/slab.h>
35#include <linux/proc_fs.h>
36#include <linux/efi.h>
37#include <linux/memory_hotplug.h>
38#include <linux/uaccess.h>
39#include <asm/mmu_context.h>
40#include <asm/processor.h>
41#include <asm/pgtable.h>
42#include <asm/pgalloc.h>
43#include <asm/dma.h>
44#include <asm/fixmap.h>
45#include <asm/tlb.h>
46#include <asm/tlbflush.h>
47#include <asm/sections.h>
48#include <asm/setup.h>
49#include <asm/homecache.h>
50#include <hv/hypervisor.h>
51#include <arch/chip.h>
52
53#include "migrate.h"
54
55#define clear_pgd(pmdptr) (*(pmdptr) = hv_pte(0))
56
57#ifndef __tilegx__
58unsigned long VMALLOC_RESERVE = CONFIG_VMALLOC_RESERVE;
59EXPORT_SYMBOL(VMALLOC_RESERVE);
60#endif
61
62/* Create an L2 page table */
63static pte_t * __init alloc_pte(void)
64{
65 return __alloc_bootmem(L2_KERNEL_PGTABLE_SIZE, HV_PAGE_TABLE_ALIGN, 0);
66}
67
68/*
69 * L2 page tables per controller. We allocate these all at once from
70 * the bootmem allocator and store them here. This saves on kernel L2
71 * page table memory, compared to allocating a full 64K page per L2
72 * page table, and also means that in cases where we use huge pages,
73 * we are guaranteed to later be able to shatter those huge pages and
74 * switch to using these page tables instead, without requiring
75 * further allocation. Each l2_ptes[] entry points to the first page
76 * table for the first hugepage-size piece of memory on the
77 * controller; other page tables are just indexed directly, i.e. the
78 * L2 page tables are contiguous in memory for each controller.
79 */
80static pte_t *l2_ptes[MAX_NUMNODES];
81static int num_l2_ptes[MAX_NUMNODES];
82
83static void init_prealloc_ptes(int node, int pages)
84{
85 BUG_ON(pages & (PTRS_PER_PTE - 1));
86 if (pages) {
87 num_l2_ptes[node] = pages;
88 l2_ptes[node] = __alloc_bootmem(pages * sizeof(pte_t),
89 HV_PAGE_TABLE_ALIGN, 0);
90 }
91}
92
93pte_t *get_prealloc_pte(unsigned long pfn)
94{
95 int node = pfn_to_nid(pfn);
96 pfn &= ~(-1UL << (NR_PA_HIGHBIT_SHIFT - PAGE_SHIFT));
97 BUG_ON(node >= MAX_NUMNODES);
98 BUG_ON(pfn >= num_l2_ptes[node]);
99 return &l2_ptes[node][pfn];
100}
101
102/*
103 * What caching do we expect pages from the heap to have when
104 * they are allocated during bootup? (Once we've installed the
105 * "real" swapper_pg_dir.)
106 */
107static int initial_heap_home(void)
108{
109 if (hash_default)
110 return PAGE_HOME_HASH;
111 return smp_processor_id();
112}
113
114/*
115 * Place a pointer to an L2 page table in a middle page
116 * directory entry.
117 */
118static void __init assign_pte(pmd_t *pmd, pte_t *page_table)
119{
120 phys_addr_t pa = __pa(page_table);
121 unsigned long l2_ptfn = pa >> HV_LOG2_PAGE_TABLE_ALIGN;
122 pte_t pteval = hv_pte_set_ptfn(__pgprot(_PAGE_TABLE), l2_ptfn);
123 BUG_ON((pa & (HV_PAGE_TABLE_ALIGN-1)) != 0);
124 pteval = pte_set_home(pteval, initial_heap_home());
125 *(pte_t *)pmd = pteval;
126 if (page_table != (pte_t *)pmd_page_vaddr(*pmd))
127 BUG();
128}
129
130#ifdef __tilegx__
131
132static inline pmd_t *alloc_pmd(void)
133{
134 return __alloc_bootmem(L1_KERNEL_PGTABLE_SIZE, HV_PAGE_TABLE_ALIGN, 0);
135}
136
137static inline void assign_pmd(pud_t *pud, pmd_t *pmd)
138{
139 assign_pte((pmd_t *)pud, (pte_t *)pmd);
140}
141
142#endif /* __tilegx__ */
143
144/* Replace the given pmd with a full PTE table. */
145void __init shatter_pmd(pmd_t *pmd)
146{
147 pte_t *pte = get_prealloc_pte(pte_pfn(*(pte_t *)pmd));
148 assign_pte(pmd, pte);
149}
150
151#ifdef __tilegx__
152static pmd_t *__init get_pmd(pgd_t pgtables[], unsigned long va)
153{
154 pud_t *pud = pud_offset(&pgtables[pgd_index(va)], va);
155 if (pud_none(*pud))
156 assign_pmd(pud, alloc_pmd());
157 return pmd_offset(pud, va);
158}
159#else
160static pmd_t *__init get_pmd(pgd_t pgtables[], unsigned long va)
161{
162 return pmd_offset(pud_offset(&pgtables[pgd_index(va)], va), va);
163}
164#endif
165
166/*
167 * This function initializes a certain range of kernel virtual memory
168 * with new bootmem page tables, everywhere page tables are missing in
169 * the given range.
170 */
171
172/*
173 * NOTE: The pagetables are allocated contiguous on the physical space
174 * so we can cache the place of the first one and move around without
175 * checking the pgd every time.
176 */
177static void __init page_table_range_init(unsigned long start,
178 unsigned long end, pgd_t *pgd)
179{
180 unsigned long vaddr;
181 start = round_down(start, PMD_SIZE);
182 end = round_up(end, PMD_SIZE);
183 for (vaddr = start; vaddr < end; vaddr += PMD_SIZE) {
184 pmd_t *pmd = get_pmd(pgd, vaddr);
185 if (pmd_none(*pmd))
186 assign_pte(pmd, alloc_pte());
187 }
188}
189
190
191static int __initdata ktext_hash = 1; /* .text pages */
192static int __initdata kdata_hash = 1; /* .data and .bss pages */
193int __ro_after_init hash_default = 1; /* kernel allocator pages */
194EXPORT_SYMBOL(hash_default);
195int __ro_after_init kstack_hash = 1; /* if no homecaching, use h4h */
196
197/*
198 * CPUs to use to for striping the pages of kernel data. If hash-for-home
199 * is available, this is only relevant if kcache_hash sets up the
200 * .data and .bss to be page-homed, and we don't want the default mode
201 * of using the full set of kernel cpus for the striping.
202 */
203static __initdata struct cpumask kdata_mask;
204static __initdata int kdata_arg_seen;
205
206int __ro_after_init kdata_huge; /* if no homecaching, small pages */
207
208
209/* Combine a generic pgprot_t with cache home to get a cache-aware pgprot. */
210static pgprot_t __init construct_pgprot(pgprot_t prot, int home)
211{
212 prot = pte_set_home(prot, home);
213 if (home == PAGE_HOME_IMMUTABLE) {
214 if (ktext_hash)
215 prot = hv_pte_set_mode(prot, HV_PTE_MODE_CACHE_HASH_L3);
216 else
217 prot = hv_pte_set_mode(prot, HV_PTE_MODE_CACHE_NO_L3);
218 }
219 return prot;
220}
221
222/*
223 * For a given kernel data VA, how should it be cached?
224 * We return the complete pgprot_t with caching bits set.
225 */
226static pgprot_t __init init_pgprot(ulong address)
227{
228 int cpu;
229 unsigned long page;
230 enum { CODE_DELTA = MEM_SV_START - PAGE_OFFSET };
231
232 /* For kdata=huge, everything is just hash-for-home. */
233 if (kdata_huge)
234 return construct_pgprot(PAGE_KERNEL, PAGE_HOME_HASH);
235
236 /*
237 * We map the aliased pages of permanent text so we can
238 * update them if necessary, for ftrace, etc.
239 */
240 if (address < (ulong) _sinittext - CODE_DELTA)
241 return construct_pgprot(PAGE_KERNEL, PAGE_HOME_HASH);
242
243 /* We map read-only data non-coherent for performance. */
244 if ((address >= (ulong) __start_rodata &&
245 address < (ulong) __end_rodata) ||
246 address == (ulong) empty_zero_page) {
247 return construct_pgprot(PAGE_KERNEL_RO, PAGE_HOME_IMMUTABLE);
248 }
249
250#ifndef __tilegx__
251 /* Force the atomic_locks[] array page to be hash-for-home. */
252 if (address == (ulong) atomic_locks)
253 return construct_pgprot(PAGE_KERNEL, PAGE_HOME_HASH);
254#endif
255
256 /*
257 * Everything else that isn't data or bss is heap, so mark it
258 * with the initial heap home (hash-for-home, or this cpu). This
259 * includes any addresses after the loaded image and any address before
260 * __init_end, since we already captured the case of text before
261 * _sinittext, and __pa(einittext) is approximately __pa(__init_begin).
262 *
263 * All the LOWMEM pages that we mark this way will get their
264 * struct page homecache properly marked later, in set_page_homes().
265 * The HIGHMEM pages we leave with a default zero for their
266 * homes, but with a zero free_time we don't have to actually
267 * do a flush action the first time we use them, either.
268 */
269 if (address >= (ulong) _end || address < (ulong) __init_end)
270 return construct_pgprot(PAGE_KERNEL, initial_heap_home());
271
272 /* Use hash-for-home if requested for data/bss. */
273 if (kdata_hash)
274 return construct_pgprot(PAGE_KERNEL, PAGE_HOME_HASH);
275
276 /*
277 * Otherwise we just hand out consecutive cpus. To avoid
278 * requiring this function to hold state, we just walk forward from
279 * __end_rodata by PAGE_SIZE, skipping the readonly and init data, to
280 * reach the requested address, while walking cpu home around
281 * kdata_mask. This is typically no more than a dozen or so iterations.
282 */
283 page = (((ulong)__end_rodata) + PAGE_SIZE - 1) & PAGE_MASK;
284 BUG_ON(address < page || address >= (ulong)_end);
285 cpu = cpumask_first(&kdata_mask);
286 for (; page < address; page += PAGE_SIZE) {
287 if (page >= (ulong)&init_thread_union &&
288 page < (ulong)&init_thread_union + THREAD_SIZE)
289 continue;
290 if (page == (ulong)empty_zero_page)
291 continue;
292#ifndef __tilegx__
293 if (page == (ulong)atomic_locks)
294 continue;
295#endif
296 cpu = cpumask_next(cpu, &kdata_mask);
297 if (cpu == NR_CPUS)
298 cpu = cpumask_first(&kdata_mask);
299 }
300 return construct_pgprot(PAGE_KERNEL, cpu);
301}
302
303/*
304 * This function sets up how we cache the kernel text. If we have
305 * hash-for-home support, normally that is used instead (see the
306 * kcache_hash boot flag for more information). But if we end up
307 * using a page-based caching technique, this option sets up the
308 * details of that. In addition, the "ktext=nocache" option may
309 * always be used to disable local caching of text pages, if desired.
310 */
311
312static int __initdata ktext_arg_seen;
313static int __initdata ktext_small;
314static int __initdata ktext_local;
315static int __initdata ktext_all;
316static int __initdata ktext_nondataplane;
317static int __initdata ktext_nocache;
318static struct cpumask __initdata ktext_mask;
319
320static int __init setup_ktext(char *str)
321{
322 if (str == NULL)
323 return -EINVAL;
324
325 /* If you have a leading "nocache", turn off ktext caching */
326 if (strncmp(str, "nocache", 7) == 0) {
327 ktext_nocache = 1;
328 pr_info("ktext: disabling local caching of kernel text\n");
329 str += 7;
330 if (*str == ',')
331 ++str;
332 if (*str == '\0')
333 return 0;
334 }
335
336 ktext_arg_seen = 1;
337
338 /* Default setting: use a huge page */
339 if (strcmp(str, "huge") == 0)
340 pr_info("ktext: using one huge locally cached page\n");
341
342 /* Pay TLB cost but get no cache benefit: cache small pages locally */
343 else if (strcmp(str, "local") == 0) {
344 ktext_small = 1;
345 ktext_local = 1;
346 pr_info("ktext: using small pages with local caching\n");
347 }
348
349 /* Neighborhood cache ktext pages on all cpus. */
350 else if (strcmp(str, "all") == 0) {
351 ktext_small = 1;
352 ktext_all = 1;
353 pr_info("ktext: using maximal caching neighborhood\n");
354 }
355
356
357 /* Neighborhood ktext pages on specified mask */
358 else if (cpulist_parse(str, &ktext_mask) == 0) {
359 if (cpumask_weight(&ktext_mask) > 1) {
360 ktext_small = 1;
361 pr_info("ktext: using caching neighborhood %*pbl with small pages\n",
362 cpumask_pr_args(&ktext_mask));
363 } else {
364 pr_info("ktext: caching on cpu %*pbl with one huge page\n",
365 cpumask_pr_args(&ktext_mask));
366 }
367 }
368
369 else if (*str)
370 return -EINVAL;
371
372 return 0;
373}
374
375early_param("ktext", setup_ktext);
376
377
378static inline pgprot_t ktext_set_nocache(pgprot_t prot)
379{
380 if (!ktext_nocache)
381 prot = hv_pte_set_nc(prot);
382 else
383 prot = hv_pte_set_no_alloc_l2(prot);
384 return prot;
385}
386
387/* Temporary page table we use for staging. */
388static pgd_t pgtables[PTRS_PER_PGD]
389 __attribute__((aligned(HV_PAGE_TABLE_ALIGN)));
390
391/*
392 * This maps the physical memory to kernel virtual address space, a total
393 * of max_low_pfn pages, by creating page tables starting from address
394 * PAGE_OFFSET.
395 *
396 * This routine transitions us from using a set of compiled-in large
397 * pages to using some more precise caching, including removing access
398 * to code pages mapped at PAGE_OFFSET (executed only at MEM_SV_START)
399 * marking read-only data as locally cacheable, striping the remaining
400 * .data and .bss across all the available tiles, and removing access
401 * to pages above the top of RAM (thus ensuring a page fault from a bad
402 * virtual address rather than a hypervisor shoot down for accessing
403 * memory outside the assigned limits).
404 */
405static void __init kernel_physical_mapping_init(pgd_t *pgd_base)
406{
407 unsigned long long irqmask;
408 unsigned long address, pfn;
409 pmd_t *pmd;
410 pte_t *pte;
411 int pte_ofs;
412 const struct cpumask *my_cpu_mask = cpumask_of(smp_processor_id());
413 struct cpumask kstripe_mask;
414 int rc, i;
415
416 if (ktext_arg_seen && ktext_hash) {
417 pr_warn("warning: \"ktext\" boot argument ignored if \"kcache_hash\" sets up text hash-for-home\n");
418 ktext_small = 0;
419 }
420
421 if (kdata_arg_seen && kdata_hash) {
422 pr_warn("warning: \"kdata\" boot argument ignored if \"kcache_hash\" sets up data hash-for-home\n");
423 }
424
425 if (kdata_huge && !hash_default) {
426 pr_warn("warning: disabling \"kdata=huge\"; requires kcache_hash=all or =allbutstack\n");
427 kdata_huge = 0;
428 }
429
430 /*
431 * Set up a mask for cpus to use for kernel striping.
432 * This is normally all cpus, but minus dataplane cpus if any.
433 * If the dataplane covers the whole chip, we stripe over
434 * the whole chip too.
435 */
436 cpumask_copy(&kstripe_mask, cpu_possible_mask);
437 if (!kdata_arg_seen)
438 kdata_mask = kstripe_mask;
439
440 /* Allocate and fill in L2 page tables */
441 for (i = 0; i < MAX_NUMNODES; ++i) {
442#ifdef CONFIG_HIGHMEM
443 unsigned long end_pfn = node_lowmem_end_pfn[i];
444#else
445 unsigned long end_pfn = node_end_pfn[i];
446#endif
447 unsigned long end_huge_pfn = 0;
448
449 /* Pre-shatter the last huge page to allow per-cpu pages. */
450 if (kdata_huge)
451 end_huge_pfn = end_pfn - (HPAGE_SIZE >> PAGE_SHIFT);
452
453 pfn = node_start_pfn[i];
454
455 /* Allocate enough memory to hold L2 page tables for node. */
456 init_prealloc_ptes(i, end_pfn - pfn);
457
458 address = (unsigned long) pfn_to_kaddr(pfn);
459 while (pfn < end_pfn) {
460 BUG_ON(address & (HPAGE_SIZE-1));
461 pmd = get_pmd(pgtables, address);
462 pte = get_prealloc_pte(pfn);
463 if (pfn < end_huge_pfn) {
464 pgprot_t prot = init_pgprot(address);
465 *(pte_t *)pmd = pte_mkhuge(pfn_pte(pfn, prot));
466 for (pte_ofs = 0; pte_ofs < PTRS_PER_PTE;
467 pfn++, pte_ofs++, address += PAGE_SIZE)
468 pte[pte_ofs] = pfn_pte(pfn, prot);
469 } else {
470 if (kdata_huge)
471 printk(KERN_DEBUG "pre-shattered huge page at %#lx\n",
472 address);
473 for (pte_ofs = 0; pte_ofs < PTRS_PER_PTE;
474 pfn++, pte_ofs++, address += PAGE_SIZE) {
475 pgprot_t prot = init_pgprot(address);
476 pte[pte_ofs] = pfn_pte(pfn, prot);
477 }
478 assign_pte(pmd, pte);
479 }
480 }
481 }
482
483 /*
484 * Set or check ktext_map now that we have cpu_possible_mask
485 * and kstripe_mask to work with.
486 */
487 if (ktext_all)
488 cpumask_copy(&ktext_mask, cpu_possible_mask);
489 else if (ktext_nondataplane)
490 ktext_mask = kstripe_mask;
491 else if (!cpumask_empty(&ktext_mask)) {
492 /* Sanity-check any mask that was requested */
493 struct cpumask bad;
494 cpumask_andnot(&bad, &ktext_mask, cpu_possible_mask);
495 cpumask_and(&ktext_mask, &ktext_mask, cpu_possible_mask);
496 if (!cpumask_empty(&bad))
497 pr_info("ktext: not using unavailable cpus %*pbl\n",
498 cpumask_pr_args(&bad));
499 if (cpumask_empty(&ktext_mask)) {
500 pr_warn("ktext: no valid cpus; caching on %d\n",
501 smp_processor_id());
502 cpumask_copy(&ktext_mask,
503 cpumask_of(smp_processor_id()));
504 }
505 }
506
507 address = MEM_SV_START;
508 pmd = get_pmd(pgtables, address);
509 pfn = 0; /* code starts at PA 0 */
510 if (ktext_small) {
511 /* Allocate an L2 PTE for the kernel text */
512 int cpu = 0;
513 pgprot_t prot = construct_pgprot(PAGE_KERNEL_EXEC,
514 PAGE_HOME_IMMUTABLE);
515
516 if (ktext_local) {
517 if (ktext_nocache)
518 prot = hv_pte_set_mode(prot,
519 HV_PTE_MODE_UNCACHED);
520 else
521 prot = hv_pte_set_mode(prot,
522 HV_PTE_MODE_CACHE_NO_L3);
523 } else {
524 prot = hv_pte_set_mode(prot,
525 HV_PTE_MODE_CACHE_TILE_L3);
526 cpu = cpumask_first(&ktext_mask);
527
528 prot = ktext_set_nocache(prot);
529 }
530
531 BUG_ON(address != (unsigned long)_text);
532 pte = NULL;
533 for (; address < (unsigned long)_einittext;
534 pfn++, address += PAGE_SIZE) {
535 pte_ofs = pte_index(address);
536 if (pte_ofs == 0) {
537 if (pte)
538 assign_pte(pmd++, pte);
539 pte = alloc_pte();
540 }
541 if (!ktext_local) {
542 prot = set_remote_cache_cpu(prot, cpu);
543 cpu = cpumask_next(cpu, &ktext_mask);
544 if (cpu == NR_CPUS)
545 cpu = cpumask_first(&ktext_mask);
546 }
547 pte[pte_ofs] = pfn_pte(pfn, prot);
548 }
549 if (pte)
550 assign_pte(pmd, pte);
551 } else {
552 pte_t pteval = pfn_pte(0, PAGE_KERNEL_EXEC);
553 pteval = pte_mkhuge(pteval);
554 if (ktext_hash) {
555 pteval = hv_pte_set_mode(pteval,
556 HV_PTE_MODE_CACHE_HASH_L3);
557 pteval = ktext_set_nocache(pteval);
558 } else
559 if (cpumask_weight(&ktext_mask) == 1) {
560 pteval = set_remote_cache_cpu(pteval,
561 cpumask_first(&ktext_mask));
562 pteval = hv_pte_set_mode(pteval,
563 HV_PTE_MODE_CACHE_TILE_L3);
564 pteval = ktext_set_nocache(pteval);
565 } else if (ktext_nocache)
566 pteval = hv_pte_set_mode(pteval,
567 HV_PTE_MODE_UNCACHED);
568 else
569 pteval = hv_pte_set_mode(pteval,
570 HV_PTE_MODE_CACHE_NO_L3);
571 for (; address < (unsigned long)_einittext;
572 pfn += PFN_DOWN(HPAGE_SIZE), address += HPAGE_SIZE)
573 *(pte_t *)(pmd++) = pfn_pte(pfn, pteval);
574 }
575
576 /* Set swapper_pgprot here so it is flushed to memory right away. */
577 swapper_pgprot = init_pgprot((unsigned long)swapper_pg_dir);
578
579 /*
580 * Since we may be changing the caching of the stack and page
581 * table itself, we invoke an assembly helper to do the
582 * following steps:
583 *
584 * - flush the cache so we start with an empty slate
585 * - install pgtables[] as the real page table
586 * - flush the TLB so the new page table takes effect
587 */
588 irqmask = interrupt_mask_save_mask();
589 interrupt_mask_set_mask(-1ULL);
590 rc = flush_and_install_context(__pa(pgtables),
591 init_pgprot((unsigned long)pgtables),
592 __this_cpu_read(current_asid),
593 cpumask_bits(my_cpu_mask));
594 interrupt_mask_restore_mask(irqmask);
595 BUG_ON(rc != 0);
596
597 /* Copy the page table back to the normal swapper_pg_dir. */
598 memcpy(pgd_base, pgtables, sizeof(pgtables));
599 __install_page_table(pgd_base, __this_cpu_read(current_asid),
600 swapper_pgprot);
601
602 /*
603 * We just read swapper_pgprot and thus brought it into the cache,
604 * with its new home & caching mode. When we start the other CPUs,
605 * they're going to reference swapper_pgprot via their initial fake
606 * VA-is-PA mappings, which cache everything locally. At that
607 * time, if it's in our cache with a conflicting home, the
608 * simulator's coherence checker will complain. So, flush it out
609 * of our cache; we're not going to ever use it again anyway.
610 */
611 __insn_finv(&swapper_pgprot);
612}
613
614/*
615 * devmem_is_allowed() checks to see if /dev/mem access to a certain address
616 * is valid. The argument is a physical page number.
617 *
618 * On Tile, the only valid things for which we can just hand out unchecked
619 * PTEs are the kernel code and data. Anything else might change its
620 * homing with time, and we wouldn't know to adjust the /dev/mem PTEs.
621 * Note that init_thread_union is released to heap soon after boot,
622 * so we include it in the init data.
623 *
624 * For TILE-Gx, we might want to consider allowing access to PA
625 * regions corresponding to PCI space, etc.
626 */
627int devmem_is_allowed(unsigned long pagenr)
628{
629 return pagenr < kaddr_to_pfn(_end) &&
630 !(pagenr >= kaddr_to_pfn(&init_thread_union) ||
631 pagenr < kaddr_to_pfn(__init_end)) &&
632 !(pagenr >= kaddr_to_pfn(_sinittext) ||
633 pagenr <= kaddr_to_pfn(_einittext-1));
634}
635
636#ifdef CONFIG_HIGHMEM
637static void __init permanent_kmaps_init(pgd_t *pgd_base)
638{
639 pgd_t *pgd;
640 pud_t *pud;
641 pmd_t *pmd;
642 pte_t *pte;
643 unsigned long vaddr;
644
645 vaddr = PKMAP_BASE;
646 page_table_range_init(vaddr, vaddr + PAGE_SIZE*LAST_PKMAP, pgd_base);
647
648 pgd = swapper_pg_dir + pgd_index(vaddr);
649 pud = pud_offset(pgd, vaddr);
650 pmd = pmd_offset(pud, vaddr);
651 pte = pte_offset_kernel(pmd, vaddr);
652 pkmap_page_table = pte;
653}
654#endif /* CONFIG_HIGHMEM */
655
656
657#ifndef CONFIG_64BIT
658static void __init init_free_pfn_range(unsigned long start, unsigned long end)
659{
660 unsigned long pfn;
661 struct page *page = pfn_to_page(start);
662
663 for (pfn = start; pfn < end; ) {
664 /* Optimize by freeing pages in large batches */
665 int order = __ffs(pfn);
666 int count, i;
667 struct page *p;
668
669 if (order >= MAX_ORDER)
670 order = MAX_ORDER-1;
671 count = 1 << order;
672 while (pfn + count > end) {
673 count >>= 1;
674 --order;
675 }
676 for (p = page, i = 0; i < count; ++i, ++p) {
677 __ClearPageReserved(p);
678 /*
679 * Hacky direct set to avoid unnecessary
680 * lock take/release for EVERY page here.
681 */
682 p->_refcount.counter = 0;
683 p->_mapcount.counter = -1;
684 }
685 init_page_count(page);
686 __free_pages(page, order);
687 adjust_managed_page_count(page, count);
688
689 page += count;
690 pfn += count;
691 }
692}
693
694static void __init set_non_bootmem_pages_init(void)
695{
696 struct zone *z;
697 for_each_zone(z) {
698 unsigned long start, end;
699 int nid = z->zone_pgdat->node_id;
700#ifdef CONFIG_HIGHMEM
701 int idx = zone_idx(z);
702#endif
703
704 start = z->zone_start_pfn;
705 end = start + z->spanned_pages;
706 start = max(start, node_free_pfn[nid]);
707 start = max(start, max_low_pfn);
708
709#ifdef CONFIG_HIGHMEM
710 if (idx == ZONE_HIGHMEM)
711 totalhigh_pages += z->spanned_pages;
712#endif
713 if (kdata_huge) {
714 unsigned long percpu_pfn = node_percpu_pfn[nid];
715 if (start < percpu_pfn && end > percpu_pfn)
716 end = percpu_pfn;
717 }
718#ifdef CONFIG_PCI
719 if (start <= pci_reserve_start_pfn &&
720 end > pci_reserve_start_pfn) {
721 if (end > pci_reserve_end_pfn)
722 init_free_pfn_range(pci_reserve_end_pfn, end);
723 end = pci_reserve_start_pfn;
724 }
725#endif
726 init_free_pfn_range(start, end);
727 }
728}
729#endif
730
731/*
732 * paging_init() sets up the page tables - note that all of lowmem is
733 * already mapped by head.S.
734 */
735void __init paging_init(void)
736{
737#ifdef __tilegx__
738 pud_t *pud;
739#endif
740 pgd_t *pgd_base = swapper_pg_dir;
741
742 kernel_physical_mapping_init(pgd_base);
743
744 /* Fixed mappings, only the page table structure has to be created. */
745 page_table_range_init(fix_to_virt(__end_of_fixed_addresses - 1),
746 FIXADDR_TOP, pgd_base);
747
748#ifdef CONFIG_HIGHMEM
749 permanent_kmaps_init(pgd_base);
750#endif
751
752#ifdef __tilegx__
753 /*
754 * Since GX allocates just one pmd_t array worth of vmalloc space,
755 * we go ahead and allocate it statically here, then share it
756 * globally. As a result we don't have to worry about any task
757 * changing init_mm once we get up and running, and there's no
758 * need for e.g. vmalloc_sync_all().
759 */
760 BUILD_BUG_ON(pgd_index(VMALLOC_START) != pgd_index(VMALLOC_END - 1));
761 pud = pud_offset(pgd_base + pgd_index(VMALLOC_START), VMALLOC_START);
762 assign_pmd(pud, alloc_pmd());
763#endif
764}
765
766
767/*
768 * Walk the kernel page tables and derive the page_home() from
769 * the PTEs, so that set_pte() can properly validate the caching
770 * of all PTEs it sees.
771 */
772void __init set_page_homes(void)
773{
774}
775
776static void __init set_max_mapnr_init(void)
777{
778#ifdef CONFIG_FLATMEM
779 max_mapnr = max_low_pfn;
780#endif
781}
782
783void __init mem_init(void)
784{
785 int i;
786#ifndef __tilegx__
787 void *last;
788#endif
789
790#ifdef CONFIG_FLATMEM
791 BUG_ON(!mem_map);
792#endif
793
794#ifdef CONFIG_HIGHMEM
795 /* check that fixmap and pkmap do not overlap */
796 if (PKMAP_ADDR(LAST_PKMAP-1) >= FIXADDR_START) {
797 pr_err("fixmap and kmap areas overlap - this will crash\n");
798 pr_err("pkstart: %lxh pkend: %lxh fixstart %lxh\n",
799 PKMAP_BASE, PKMAP_ADDR(LAST_PKMAP-1), FIXADDR_START);
800 BUG();
801 }
802#endif
803
804 set_max_mapnr_init();
805
806 /* this will put all bootmem onto the freelists */
807 free_all_bootmem();
808
809#ifndef CONFIG_64BIT
810 /* count all remaining LOWMEM and give all HIGHMEM to page allocator */
811 set_non_bootmem_pages_init();
812#endif
813
814 mem_init_print_info(NULL);
815
816 /*
817 * In debug mode, dump some interesting memory mappings.
818 */
819#ifdef CONFIG_HIGHMEM
820 printk(KERN_DEBUG " KMAP %#lx - %#lx\n",
821 FIXADDR_START, FIXADDR_TOP + PAGE_SIZE - 1);
822 printk(KERN_DEBUG " PKMAP %#lx - %#lx\n",
823 PKMAP_BASE, PKMAP_ADDR(LAST_PKMAP) - 1);
824#endif
825 printk(KERN_DEBUG " VMALLOC %#lx - %#lx\n",
826 _VMALLOC_START, _VMALLOC_END - 1);
827#ifdef __tilegx__
828 for (i = MAX_NUMNODES-1; i >= 0; --i) {
829 struct pglist_data *node = &node_data[i];
830 if (node->node_present_pages) {
831 unsigned long start = (unsigned long)
832 pfn_to_kaddr(node->node_start_pfn);
833 unsigned long end = start +
834 (node->node_present_pages << PAGE_SHIFT);
835 printk(KERN_DEBUG " MEM%d %#lx - %#lx\n",
836 i, start, end - 1);
837 }
838 }
839#else
840 last = high_memory;
841 for (i = MAX_NUMNODES-1; i >= 0; --i) {
842 if ((unsigned long)vbase_map[i] != -1UL) {
843 printk(KERN_DEBUG " LOWMEM%d %#lx - %#lx\n",
844 i, (unsigned long) (vbase_map[i]),
845 (unsigned long) (last-1));
846 last = vbase_map[i];
847 }
848 }
849#endif
850
851#ifndef __tilegx__
852 /*
853 * Convert from using one lock for all atomic operations to
854 * one per cpu.
855 */
856 __init_atomic_per_cpu();
857#endif
858}
859
860struct kmem_cache *pgd_cache;
861
862void __init pgtable_cache_init(void)
863{
864 pgd_cache = kmem_cache_create("pgd", SIZEOF_PGD, SIZEOF_PGD, 0, NULL);
865 if (!pgd_cache)
866 panic("pgtable_cache_init(): Cannot create pgd cache");
867}
868
869static long __ro_after_init initfree = 1;
870static bool __ro_after_init set_initfree_done;
871
872/* Select whether to free (1) or mark unusable (0) the __init pages. */
873static int __init set_initfree(char *str)
874{
875 long val;
876 if (kstrtol(str, 0, &val) == 0) {
877 set_initfree_done = true;
878 initfree = val;
879 pr_info("initfree: %s free init pages\n",
880 initfree ? "will" : "won't");
881 }
882 return 1;
883}
884__setup("initfree=", set_initfree);
885
886static void free_init_pages(char *what, unsigned long begin, unsigned long end)
887{
888 unsigned long addr = (unsigned long) begin;
889
890 /* Prefer user request first */
891 if (!set_initfree_done) {
892 if (debug_pagealloc_enabled())
893 initfree = 0;
894 }
895 if (kdata_huge && !initfree) {
896 pr_warn("Warning: ignoring initfree=0: incompatible with kdata=huge\n");
897 initfree = 1;
898 }
899 end = (end + PAGE_SIZE - 1) & PAGE_MASK;
900 local_flush_tlb_pages(NULL, begin, PAGE_SIZE, end - begin);
901 for (addr = begin; addr < end; addr += PAGE_SIZE) {
902 /*
903 * Note we just reset the home here directly in the
904 * page table. We know this is safe because our caller
905 * just flushed the caches on all the other cpus,
906 * and they won't be touching any of these pages.
907 */
908 int pfn = kaddr_to_pfn((void *)addr);
909 struct page *page = pfn_to_page(pfn);
910 pte_t *ptep = virt_to_kpte(addr);
911 if (!initfree) {
912 /*
913 * If debugging page accesses then do not free
914 * this memory but mark them not present - any
915 * buggy init-section access will create a
916 * kernel page fault:
917 */
918 pte_clear(&init_mm, addr, ptep);
919 continue;
920 }
921 if (pte_huge(*ptep))
922 BUG_ON(!kdata_huge);
923 else
924 set_pte_at(&init_mm, addr, ptep,
925 pfn_pte(pfn, PAGE_KERNEL));
926 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
927 free_reserved_page(page);
928 }
929 pr_info("Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
930}
931
932void free_initmem(void)
933{
934 const unsigned long text_delta = MEM_SV_START - PAGE_OFFSET;
935
936 /*
937 * Evict the cache on all cores to avoid incoherence.
938 * We are guaranteed that no one will touch the init pages any more.
939 */
940 homecache_evict(&cpu_cacheable_map);
941
942 /* Free the data pages that we won't use again after init. */
943 free_init_pages("unused kernel data",
944 (unsigned long)__init_begin,
945 (unsigned long)__init_end);
946
947 /*
948 * Free the pages mapped from 0xc0000000 that correspond to code
949 * pages from MEM_SV_START that we won't use again after init.
950 */
951 free_init_pages("unused kernel text",
952 (unsigned long)_sinittext - text_delta,
953 (unsigned long)_einittext - text_delta);
954 /* Do a global TLB flush so everyone sees the changes. */
955 flush_tlb_all();
956}
diff --git a/arch/tile/mm/migrate.h b/arch/tile/mm/migrate.h
deleted file mode 100644
index 91683d97917e..000000000000
--- a/arch/tile/mm/migrate.h
+++ /dev/null
@@ -1,56 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Structure definitions for migration, exposed here for use by
15 * arch/tile/kernel/asm-offsets.c.
16 */
17
18#ifndef MM_MIGRATE_H
19#define MM_MIGRATE_H
20
21#include <linux/cpumask.h>
22#include <hv/hypervisor.h>
23
24/*
25 * This function is used as a helper when setting up the initial
26 * page table (swapper_pg_dir).
27 *
28 * You must mask ALL interrupts prior to invoking this code, since
29 * you can't legally touch the stack during the cache flush.
30 */
31extern int flush_and_install_context(HV_PhysAddr page_table, HV_PTE access,
32 HV_ASID asid,
33 const unsigned long *cpumask);
34
35/*
36 * This function supports migration as a "helper" as follows:
37 *
38 * - Set the stack PTE itself to "migrating".
39 * - Do a global TLB flush for (va,length) and the specified ASIDs.
40 * - Do a cache-evict on all necessary cpus.
41 * - Write the new stack PTE.
42 *
43 * Note that any non-NULL pointers must not point to the page that
44 * is handled by the stack_pte itself.
45 *
46 * You must mask ALL interrupts prior to invoking this code, since
47 * you can't legally touch the stack during the cache flush.
48 */
49extern int homecache_migrate_stack_and_flush(pte_t stack_pte, unsigned long va,
50 size_t length, pte_t *stack_ptep,
51 const struct cpumask *cache_cpumask,
52 const struct cpumask *tlb_cpumask,
53 HV_Remote_ASID *asids,
54 int asidcount);
55
56#endif /* MM_MIGRATE_H */
diff --git a/arch/tile/mm/migrate_32.S b/arch/tile/mm/migrate_32.S
deleted file mode 100644
index 772085491bf9..000000000000
--- a/arch/tile/mm/migrate_32.S
+++ /dev/null
@@ -1,192 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * This routine is a helper for migrating the home of a set of pages to
15 * a new cpu. See the documentation in homecache.c for more information.
16 */
17
18#include <linux/linkage.h>
19#include <linux/threads.h>
20#include <asm/page.h>
21#include <asm/thread_info.h>
22#include <asm/types.h>
23#include <asm/asm-offsets.h>
24#include <hv/hypervisor.h>
25
26 .text
27
28/*
29 * First, some definitions that apply to all the code in the file.
30 */
31
32/* Locals (caller-save) */
33#define r_tmp r10
34#define r_save_sp r11
35
36/* What we save where in the stack frame; must include all callee-saves. */
37#define FRAME_SP 4
38#define FRAME_R30 8
39#define FRAME_R31 12
40#define FRAME_R32 16
41#define FRAME_R33 20
42#define FRAME_R34 24
43#define FRAME_SIZE 28
44
45
46
47
48/*
49 * On entry:
50 *
51 * r0 low word of the new context PA to install (moved to r_context_lo)
52 * r1 high word of the new context PA to install (moved to r_context_hi)
53 * r2 low word of PTE to use for context access (moved to r_access_lo)
54 * r3 high word of PTE to use for context access (moved to r_access_lo)
55 * r4 ASID to use for new context (moved to r_asid)
56 * r5 pointer to cpumask with just this cpu set in it (r_my_cpumask)
57 */
58
59/* Arguments (caller-save) */
60#define r_context_lo_in r0
61#define r_context_hi_in r1
62#define r_access_lo_in r2
63#define r_access_hi_in r3
64#define r_asid_in r4
65#define r_my_cpumask r5
66
67/* Locals (callee-save); must not be more than FRAME_xxx above. */
68#define r_context_lo r30
69#define r_context_hi r31
70#define r_access_lo r32
71#define r_access_hi r33
72#define r_asid r34
73
74STD_ENTRY(flush_and_install_context)
75 /*
76 * Create a stack frame; we can't touch it once we flush the
77 * cache until we install the new page table and flush the TLB.
78 */
79 {
80 move r_save_sp, sp
81 sw sp, lr
82 addi sp, sp, -FRAME_SIZE
83 }
84 addi r_tmp, sp, FRAME_SP
85 {
86 sw r_tmp, r_save_sp
87 addi r_tmp, sp, FRAME_R30
88 }
89 {
90 sw r_tmp, r30
91 addi r_tmp, sp, FRAME_R31
92 }
93 {
94 sw r_tmp, r31
95 addi r_tmp, sp, FRAME_R32
96 }
97 {
98 sw r_tmp, r32
99 addi r_tmp, sp, FRAME_R33
100 }
101 {
102 sw r_tmp, r33
103 addi r_tmp, sp, FRAME_R34
104 }
105 sw r_tmp, r34
106
107 /* Move some arguments to callee-save registers. */
108 {
109 move r_context_lo, r_context_lo_in
110 move r_context_hi, r_context_hi_in
111 }
112 {
113 move r_access_lo, r_access_lo_in
114 move r_access_hi, r_access_hi_in
115 }
116 move r_asid, r_asid_in
117
118 /* First, flush our L2 cache. */
119 {
120 move r0, zero /* cache_pa */
121 move r1, zero
122 }
123 {
124 auli r2, zero, ha16(HV_FLUSH_EVICT_L2) /* cache_control */
125 move r3, r_my_cpumask /* cache_cpumask */
126 }
127 {
128 move r4, zero /* tlb_va */
129 move r5, zero /* tlb_length */
130 }
131 {
132 move r6, zero /* tlb_pgsize */
133 move r7, zero /* tlb_cpumask */
134 }
135 {
136 move r8, zero /* asids */
137 move r9, zero /* asidcount */
138 }
139 jal _hv_flush_remote
140 bnz r0, .Ldone
141
142 /* Now install the new page table. */
143 {
144 move r0, r_context_lo
145 move r1, r_context_hi
146 }
147 {
148 move r2, r_access_lo
149 move r3, r_access_hi
150 }
151 {
152 move r4, r_asid
153 moveli r5, HV_CTX_DIRECTIO | CTX_PAGE_FLAG
154 }
155 jal _hv_install_context
156 bnz r0, .Ldone
157
158 /* Finally, flush the TLB. */
159 {
160 movei r0, 0 /* preserve_global */
161 jal hv_flush_all
162 }
163
164.Ldone:
165 /* Restore the callee-saved registers and return. */
166 addli lr, sp, FRAME_SIZE
167 {
168 lw lr, lr
169 addli r_tmp, sp, FRAME_R30
170 }
171 {
172 lw r30, r_tmp
173 addli r_tmp, sp, FRAME_R31
174 }
175 {
176 lw r31, r_tmp
177 addli r_tmp, sp, FRAME_R32
178 }
179 {
180 lw r32, r_tmp
181 addli r_tmp, sp, FRAME_R33
182 }
183 {
184 lw r33, r_tmp
185 addli r_tmp, sp, FRAME_R34
186 }
187 {
188 lw r34, r_tmp
189 addi sp, sp, FRAME_SIZE
190 }
191 jrp lr
192 STD_ENDPROC(flush_and_install_context)
diff --git a/arch/tile/mm/migrate_64.S b/arch/tile/mm/migrate_64.S
deleted file mode 100644
index a49eee38f872..000000000000
--- a/arch/tile/mm/migrate_64.S
+++ /dev/null
@@ -1,167 +0,0 @@
1/*
2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * This routine is a helper for migrating the home of a set of pages to
15 * a new cpu. See the documentation in homecache.c for more information.
16 */
17
18#include <linux/linkage.h>
19#include <linux/threads.h>
20#include <asm/page.h>
21#include <asm/thread_info.h>
22#include <asm/types.h>
23#include <asm/asm-offsets.h>
24#include <hv/hypervisor.h>
25
26 .text
27
28/*
29 * First, some definitions that apply to all the code in the file.
30 */
31
32/* Locals (caller-save) */
33#define r_tmp r10
34#define r_save_sp r11
35
36/* What we save where in the stack frame; must include all callee-saves. */
37#define FRAME_SP 8
38#define FRAME_R30 16
39#define FRAME_R31 24
40#define FRAME_R32 32
41#define FRAME_SIZE 40
42
43
44
45
46/*
47 * On entry:
48 *
49 * r0 the new context PA to install (moved to r_context)
50 * r1 PTE to use for context access (moved to r_access)
51 * r2 ASID to use for new context (moved to r_asid)
52 * r3 pointer to cpumask with just this cpu set in it (r_my_cpumask)
53 */
54
55/* Arguments (caller-save) */
56#define r_context_in r0
57#define r_access_in r1
58#define r_asid_in r2
59#define r_my_cpumask r3
60
61/* Locals (callee-save); must not be more than FRAME_xxx above. */
62#define r_context r30
63#define r_access r31
64#define r_asid r32
65
66/*
67 * Caller-save locals and frame constants are the same as
68 * for homecache_migrate_stack_and_flush.
69 */
70
71STD_ENTRY(flush_and_install_context)
72 /*
73 * Create a stack frame; we can't touch it once we flush the
74 * cache until we install the new page table and flush the TLB.
75 */
76 {
77 move r_save_sp, sp
78 st sp, lr
79 addi sp, sp, -FRAME_SIZE
80 }
81 addi r_tmp, sp, FRAME_SP
82 {
83 st r_tmp, r_save_sp
84 addi r_tmp, sp, FRAME_R30
85 }
86 {
87 st r_tmp, r30
88 addi r_tmp, sp, FRAME_R31
89 }
90 {
91 st r_tmp, r31
92 addi r_tmp, sp, FRAME_R32
93 }
94 st r_tmp, r32
95
96 /* Move some arguments to callee-save registers. */
97 {
98 move r_context, r_context_in
99 move r_access, r_access_in
100 }
101 move r_asid, r_asid_in
102
103 /* First, flush our L2 cache. */
104 {
105 move r0, zero /* cache_pa */
106 moveli r1, hw2_last(HV_FLUSH_EVICT_L2) /* cache_control */
107 }
108 {
109 shl16insli r1, r1, hw1(HV_FLUSH_EVICT_L2)
110 move r2, r_my_cpumask /* cache_cpumask */
111 }
112 {
113 shl16insli r1, r1, hw0(HV_FLUSH_EVICT_L2)
114 move r3, zero /* tlb_va */
115 }
116 {
117 move r4, zero /* tlb_length */
118 move r5, zero /* tlb_pgsize */
119 }
120 {
121 move r6, zero /* tlb_cpumask */
122 move r7, zero /* asids */
123 }
124 {
125 move r8, zero /* asidcount */
126 jal _hv_flush_remote
127 }
128 bnez r0, 1f
129
130 /* Now install the new page table. */
131 {
132 move r0, r_context
133 move r1, r_access
134 }
135 {
136 move r2, r_asid
137 moveli r3, HV_CTX_DIRECTIO | CTX_PAGE_FLAG
138 }
139 jal _hv_install_context
140 bnez r0, 1f
141
142 /* Finally, flush the TLB. */
143 {
144 movei r0, 0 /* preserve_global */
145 jal hv_flush_all
146 }
147
1481: /* Restore the callee-saved registers and return. */
149 addli lr, sp, FRAME_SIZE
150 {
151 ld lr, lr
152 addli r_tmp, sp, FRAME_R30
153 }
154 {
155 ld r30, r_tmp
156 addli r_tmp, sp, FRAME_R31
157 }
158 {
159 ld r31, r_tmp
160 addli r_tmp, sp, FRAME_R32
161 }
162 {
163 ld r32, r_tmp
164 addi sp, sp, FRAME_SIZE
165 }
166 jrp lr
167 STD_ENDPROC(flush_and_install_context)
diff --git a/arch/tile/mm/mmap.c b/arch/tile/mm/mmap.c
deleted file mode 100644
index 8ab28167c44b..000000000000
--- a/arch/tile/mm/mmap.c
+++ /dev/null
@@ -1,93 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 *
14 * Taken from the i386 architecture and simplified.
15 */
16
17#include <linux/mm.h>
18#include <linux/random.h>
19#include <linux/limits.h>
20#include <linux/sched/signal.h>
21#include <linux/sched/mm.h>
22#include <linux/mman.h>
23#include <linux/compat.h>
24
25/*
26 * Top of mmap area (just below the process stack).
27 *
28 * Leave an at least ~128 MB hole.
29 */
30#define MIN_GAP (128*1024*1024)
31#define MAX_GAP (TASK_SIZE/6*5)
32
33static inline unsigned long mmap_base(struct mm_struct *mm)
34{
35 unsigned long gap = rlimit(RLIMIT_STACK);
36 unsigned long random_factor = 0;
37
38 if (current->flags & PF_RANDOMIZE)
39 random_factor = get_random_int() % (1024*1024);
40
41 if (gap < MIN_GAP)
42 gap = MIN_GAP;
43 else if (gap > MAX_GAP)
44 gap = MAX_GAP;
45
46 return PAGE_ALIGN(TASK_SIZE - gap - random_factor);
47}
48
49/*
50 * This function, called very early during the creation of a new
51 * process VM image, sets up which VM layout function to use:
52 */
53void arch_pick_mmap_layout(struct mm_struct *mm)
54{
55#if !defined(__tilegx__)
56 int is_32bit = 1;
57#elif defined(CONFIG_COMPAT)
58 int is_32bit = is_compat_task();
59#else
60 int is_32bit = 0;
61#endif
62 unsigned long random_factor = 0UL;
63
64 /*
65 * 8 bits of randomness in 32bit mmaps, 24 address space bits
66 * 12 bits of randomness in 64bit mmaps, 28 address space bits
67 */
68 if (current->flags & PF_RANDOMIZE) {
69 if (is_32bit)
70 random_factor = get_random_int() % (1<<8);
71 else
72 random_factor = get_random_int() % (1<<12);
73
74 random_factor <<= PAGE_SHIFT;
75 }
76
77 /*
78 * Use standard layout if the expected stack growth is unlimited
79 * or we are running native 64 bits.
80 */
81 if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) {
82 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
83 mm->get_unmapped_area = arch_get_unmapped_area;
84 } else {
85 mm->mmap_base = mmap_base(mm);
86 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
87 }
88}
89
90unsigned long arch_randomize_brk(struct mm_struct *mm)
91{
92 return randomize_page(mm->brk, 0x02000000);
93}
diff --git a/arch/tile/mm/pgtable.c b/arch/tile/mm/pgtable.c
deleted file mode 100644
index ec5576fd3a86..000000000000
--- a/arch/tile/mm/pgtable.c
+++ /dev/null
@@ -1,550 +0,0 @@
1/*
2 * Copyright 2010 Tilera Corporation. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/sched.h>
16#include <linux/kernel.h>
17#include <linux/errno.h>
18#include <linux/mm.h>
19#include <linux/swap.h>
20#include <linux/highmem.h>
21#include <linux/slab.h>
22#include <linux/pagemap.h>
23#include <linux/spinlock.h>
24#include <linux/cpumask.h>
25#include <linux/module.h>
26#include <linux/io.h>
27#include <linux/vmalloc.h>
28#include <linux/smp.h>
29
30#include <asm/pgtable.h>
31#include <asm/pgalloc.h>
32#include <asm/fixmap.h>
33#include <asm/tlb.h>
34#include <asm/tlbflush.h>
35#include <asm/homecache.h>
36
37#define K(x) ((x) << (PAGE_SHIFT-10))
38
39/**
40 * shatter_huge_page() - ensure a given address is mapped by a small page.
41 *
42 * This function converts a huge PTE mapping kernel LOWMEM into a bunch
43 * of small PTEs with the same caching. No cache flush required, but we
44 * must do a global TLB flush.
45 *
46 * Any caller that wishes to modify a kernel mapping that might
47 * have been made with a huge page should call this function,
48 * since doing so properly avoids race conditions with installing the
49 * newly-shattered page and then flushing all the TLB entries.
50 *
51 * @addr: Address at which to shatter any existing huge page.
52 */
53void shatter_huge_page(unsigned long addr)
54{
55 pgd_t *pgd;
56 pud_t *pud;
57 pmd_t *pmd;
58 unsigned long flags = 0; /* happy compiler */
59#ifdef __PAGETABLE_PMD_FOLDED
60 struct list_head *pos;
61#endif
62
63 /* Get a pointer to the pmd entry that we need to change. */
64 addr &= HPAGE_MASK;
65 BUG_ON(pgd_addr_invalid(addr));
66 BUG_ON(addr < PAGE_OFFSET); /* only for kernel LOWMEM */
67 pgd = swapper_pg_dir + pgd_index(addr);
68 pud = pud_offset(pgd, addr);
69 BUG_ON(!pud_present(*pud));
70 pmd = pmd_offset(pud, addr);
71 BUG_ON(!pmd_present(*pmd));
72 if (!pmd_huge_page(*pmd))
73 return;
74
75 spin_lock_irqsave(&init_mm.page_table_lock, flags);
76 if (!pmd_huge_page(*pmd)) {
77 /* Lost the race to convert the huge page. */
78 spin_unlock_irqrestore(&init_mm.page_table_lock, flags);
79 return;
80 }
81
82 /* Shatter the huge page into the preallocated L2 page table. */
83 pmd_populate_kernel(&init_mm, pmd, get_prealloc_pte(pmd_pfn(*pmd)));
84
85#ifdef __PAGETABLE_PMD_FOLDED
86 /* Walk every pgd on the system and update the pmd there. */
87 spin_lock(&pgd_lock);
88 list_for_each(pos, &pgd_list) {
89 pmd_t *copy_pmd;
90 pgd = list_to_pgd(pos) + pgd_index(addr);
91 pud = pud_offset(pgd, addr);
92 copy_pmd = pmd_offset(pud, addr);
93 __set_pmd(copy_pmd, *pmd);
94 }
95 spin_unlock(&pgd_lock);
96#endif
97
98 /* Tell every cpu to notice the change. */
99 flush_remote(0, 0, NULL, addr, HPAGE_SIZE, HPAGE_SIZE,
100 cpu_possible_mask, NULL, 0);
101
102 /* Hold the lock until the TLB flush is finished to avoid races. */
103 spin_unlock_irqrestore(&init_mm.page_table_lock, flags);
104}
105
106/*
107 * List of all pgd's needed so it can invalidate entries in both cached
108 * and uncached pgd's. This is essentially codepath-based locking
109 * against pageattr.c; it is the unique case in which a valid change
110 * of kernel pagetables can't be lazily synchronized by vmalloc faults.
111 * vmalloc faults work because attached pagetables are never freed.
112 *
113 * The lock is always taken with interrupts disabled, unlike on x86
114 * and other platforms, because we need to take the lock in
115 * shatter_huge_page(), which may be called from an interrupt context.
116 * We are not at risk from the tlbflush IPI deadlock that was seen on
117 * x86, since we use the flush_remote() API to have the hypervisor do
118 * the TLB flushes regardless of irq disabling.
119 */
120DEFINE_SPINLOCK(pgd_lock);
121LIST_HEAD(pgd_list);
122
123static inline void pgd_list_add(pgd_t *pgd)
124{
125 list_add(pgd_to_list(pgd), &pgd_list);
126}
127
128static inline void pgd_list_del(pgd_t *pgd)
129{
130 list_del(pgd_to_list(pgd));
131}
132
133#define KERNEL_PGD_INDEX_START pgd_index(PAGE_OFFSET)
134#define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_INDEX_START)
135
136static void pgd_ctor(pgd_t *pgd)
137{
138 unsigned long flags;
139
140 memset(pgd, 0, KERNEL_PGD_INDEX_START*sizeof(pgd_t));
141 spin_lock_irqsave(&pgd_lock, flags);
142
143#ifndef __tilegx__
144 /*
145 * Check that the user interrupt vector has no L2.
146 * It never should for the swapper, and new page tables
147 * should always start with an empty user interrupt vector.
148 */
149 BUG_ON(((u64 *)swapper_pg_dir)[pgd_index(MEM_USER_INTRPT)] != 0);
150#endif
151
152 memcpy(pgd + KERNEL_PGD_INDEX_START,
153 swapper_pg_dir + KERNEL_PGD_INDEX_START,
154 KERNEL_PGD_PTRS * sizeof(pgd_t));
155
156 pgd_list_add(pgd);
157 spin_unlock_irqrestore(&pgd_lock, flags);
158}
159
160static void pgd_dtor(pgd_t *pgd)
161{
162 unsigned long flags; /* can be called from interrupt context */
163
164 spin_lock_irqsave(&pgd_lock, flags);
165 pgd_list_del(pgd);
166 spin_unlock_irqrestore(&pgd_lock, flags);
167}
168
169pgd_t *pgd_alloc(struct mm_struct *mm)
170{
171 pgd_t *pgd = kmem_cache_alloc(pgd_cache, GFP_KERNEL);
172 if (pgd)
173 pgd_ctor(pgd);
174 return pgd;
175}
176
177void pgd_free(struct mm_struct *mm, pgd_t *pgd)
178{
179 pgd_dtor(pgd);
180 kmem_cache_free(pgd_cache, pgd);
181}
182
183
184#define L2_USER_PGTABLE_PAGES (1 << L2_USER_PGTABLE_ORDER)
185
186struct page *pgtable_alloc_one(struct mm_struct *mm, unsigned long address,
187 int order)
188{
189 gfp_t flags = GFP_KERNEL|__GFP_ZERO;
190 struct page *p;
191 int i;
192
193 p = alloc_pages(flags, L2_USER_PGTABLE_ORDER);
194 if (p == NULL)
195 return NULL;
196
197 if (!pgtable_page_ctor(p)) {
198 __free_pages(p, L2_USER_PGTABLE_ORDER);
199 return NULL;
200 }
201
202 /*
203 * Make every page have a page_count() of one, not just the first.
204 * We don't use __GFP_COMP since it doesn't look like it works
205 * correctly with tlb_remove_page().
206 */
207 for (i = 1; i < order; ++i) {
208 init_page_count(p+i);
209 inc_zone_page_state(p+i, NR_PAGETABLE);
210 }
211
212 return p;
213}
214
215/*
216 * Free page immediately (used in __pte_alloc if we raced with another
217 * process). We have to correct whatever pte_alloc_one() did before
218 * returning the pages to the allocator.
219 */
220void pgtable_free(struct mm_struct *mm, struct page *p, int order)
221{
222 int i;
223
224 pgtable_page_dtor(p);
225 __free_page(p);
226
227 for (i = 1; i < order; ++i) {
228 __free_page(p+i);
229 dec_zone_page_state(p+i, NR_PAGETABLE);
230 }
231}
232
233void __pgtable_free_tlb(struct mmu_gather *tlb, struct page *pte,
234 unsigned long address, int order)
235{
236 int i;
237
238 pgtable_page_dtor(pte);
239 tlb_remove_page(tlb, pte);
240
241 for (i = 1; i < order; ++i) {
242 tlb_remove_page(tlb, pte + i);
243 dec_zone_page_state(pte + i, NR_PAGETABLE);
244 }
245}
246
247#ifndef __tilegx__
248
249/*
250 * FIXME: needs to be atomic vs hypervisor writes. For now we make the
251 * window of vulnerability a bit smaller by doing an unlocked 8-bit update.
252 */
253int ptep_test_and_clear_young(struct vm_area_struct *vma,
254 unsigned long addr, pte_t *ptep)
255{
256#if HV_PTE_INDEX_ACCESSED < 8 || HV_PTE_INDEX_ACCESSED >= 16
257# error Code assumes HV_PTE "accessed" bit in second byte
258#endif
259 u8 *tmp = (u8 *)ptep;
260 u8 second_byte = tmp[1];
261 if (!(second_byte & (1 << (HV_PTE_INDEX_ACCESSED - 8))))
262 return 0;
263 tmp[1] = second_byte & ~(1 << (HV_PTE_INDEX_ACCESSED - 8));
264 return 1;
265}
266
267/*
268 * This implementation is atomic vs hypervisor writes, since the hypervisor
269 * always writes the low word (where "accessed" and "dirty" are) and this
270 * routine only writes the high word.
271 */
272void ptep_set_wrprotect(struct mm_struct *mm,
273 unsigned long addr, pte_t *ptep)
274{
275#if HV_PTE_INDEX_WRITABLE < 32
276# error Code assumes HV_PTE "writable" bit in high word
277#endif
278 u32 *tmp = (u32 *)ptep;
279 tmp[1] = tmp[1] & ~(1 << (HV_PTE_INDEX_WRITABLE - 32));
280}
281
282#endif
283
284/*
285 * Return a pointer to the PTE that corresponds to the given
286 * address in the given page table. A NULL page table just uses
287 * the standard kernel page table; the preferred API in this case
288 * is virt_to_kpte().
289 *
290 * The returned pointer can point to a huge page in other levels
291 * of the page table than the bottom, if the huge page is present
292 * in the page table. For bottom-level PTEs, the returned pointer
293 * can point to a PTE that is either present or not.
294 */
295pte_t *virt_to_pte(struct mm_struct* mm, unsigned long addr)
296{
297 pgd_t *pgd;
298 pud_t *pud;
299 pmd_t *pmd;
300
301 if (pgd_addr_invalid(addr))
302 return NULL;
303
304 pgd = mm ? pgd_offset(mm, addr) : swapper_pg_dir + pgd_index(addr);
305 pud = pud_offset(pgd, addr);
306 if (!pud_present(*pud))
307 return NULL;
308 if (pud_huge_page(*pud))
309 return (pte_t *)pud;
310 pmd = pmd_offset(pud, addr);
311 if (!pmd_present(*pmd))
312 return NULL;
313 if (pmd_huge_page(*pmd))
314 return (pte_t *)pmd;
315 return pte_offset_kernel(pmd, addr);
316}
317EXPORT_SYMBOL(virt_to_pte);
318
319pte_t *virt_to_kpte(unsigned long kaddr)
320{
321 BUG_ON(kaddr < PAGE_OFFSET);
322 return virt_to_pte(NULL, kaddr);
323}
324EXPORT_SYMBOL(virt_to_kpte);
325
326pgprot_t set_remote_cache_cpu(pgprot_t prot, int cpu)
327{
328 unsigned int width = smp_width;
329 int x = cpu % width;
330 int y = cpu / width;
331 BUG_ON(y >= smp_height);
332 BUG_ON(hv_pte_get_mode(prot) != HV_PTE_MODE_CACHE_TILE_L3);
333 BUG_ON(cpu < 0 || cpu >= NR_CPUS);
334 BUG_ON(!cpu_is_valid_lotar(cpu));
335 return hv_pte_set_lotar(prot, HV_XY_TO_LOTAR(x, y));
336}
337
338int get_remote_cache_cpu(pgprot_t prot)
339{
340 HV_LOTAR lotar = hv_pte_get_lotar(prot);
341 int x = HV_LOTAR_X(lotar);
342 int y = HV_LOTAR_Y(lotar);
343 BUG_ON(hv_pte_get_mode(prot) != HV_PTE_MODE_CACHE_TILE_L3);
344 return x + y * smp_width;
345}
346
347/*
348 * Convert a kernel VA to a PA and homing information.
349 */
350int va_to_cpa_and_pte(void *va, unsigned long long *cpa, pte_t *pte)
351{
352 struct page *page = virt_to_page(va);
353 pte_t null_pte = { 0 };
354
355 *cpa = __pa(va);
356
357 /* Note that this is not writing a page table, just returning a pte. */
358 *pte = pte_set_home(null_pte, page_home(page));
359
360 return 0; /* return non-zero if not hfh? */
361}
362EXPORT_SYMBOL(va_to_cpa_and_pte);
363
364void __set_pte(pte_t *ptep, pte_t pte)
365{
366#ifdef __tilegx__
367 *ptep = pte;
368#else
369# if HV_PTE_INDEX_PRESENT >= 32 || HV_PTE_INDEX_MIGRATING >= 32
370# error Must write the present and migrating bits last
371# endif
372 if (pte_present(pte)) {
373 ((u32 *)ptep)[1] = (u32)(pte_val(pte) >> 32);
374 barrier();
375 ((u32 *)ptep)[0] = (u32)(pte_val(pte));
376 } else {
377 ((u32 *)ptep)[0] = (u32)(pte_val(pte));
378 barrier();
379 ((u32 *)ptep)[1] = (u32)(pte_val(pte) >> 32);
380 }
381#endif /* __tilegx__ */
382}
383
384void set_pte(pte_t *ptep, pte_t pte)
385{
386 if (pte_present(pte) &&
387 (!CHIP_HAS_MMIO() || hv_pte_get_mode(pte) != HV_PTE_MODE_MMIO)) {
388 /* The PTE actually references physical memory. */
389 unsigned long pfn = pte_pfn(pte);
390 if (pfn_valid(pfn)) {
391 /* Update the home of the PTE from the struct page. */
392 pte = pte_set_home(pte, page_home(pfn_to_page(pfn)));
393 } else if (hv_pte_get_mode(pte) == 0) {
394 /* remap_pfn_range(), etc, must supply PTE mode. */
395 panic("set_pte(): out-of-range PFN and mode 0\n");
396 }
397 }
398
399 __set_pte(ptep, pte);
400}
401
402/* Can this mm load a PTE with cached_priority set? */
403static inline int mm_is_priority_cached(struct mm_struct *mm)
404{
405 return mm->context.priority_cached != 0;
406}
407
408/*
409 * Add a priority mapping to an mm_context and
410 * notify the hypervisor if this is the first one.
411 */
412void start_mm_caching(struct mm_struct *mm)
413{
414 if (!mm_is_priority_cached(mm)) {
415 mm->context.priority_cached = -1UL;
416 hv_set_caching(-1UL);
417 }
418}
419
420/*
421 * Validate and return the priority_cached flag. We know if it's zero
422 * that we don't need to scan, since we immediately set it non-zero
423 * when we first consider a MAP_CACHE_PRIORITY mapping.
424 *
425 * We only _try_ to acquire the mmap_sem semaphore; if we can't acquire it,
426 * since we're in an interrupt context (servicing switch_mm) we don't
427 * worry about it and don't unset the "priority_cached" field.
428 * Presumably we'll come back later and have more luck and clear
429 * the value then; for now we'll just keep the cache marked for priority.
430 */
431static unsigned long update_priority_cached(struct mm_struct *mm)
432{
433 if (mm->context.priority_cached && down_write_trylock(&mm->mmap_sem)) {
434 struct vm_area_struct *vm;
435 for (vm = mm->mmap; vm; vm = vm->vm_next) {
436 if (hv_pte_get_cached_priority(vm->vm_page_prot))
437 break;
438 }
439 if (vm == NULL)
440 mm->context.priority_cached = 0;
441 up_write(&mm->mmap_sem);
442 }
443 return mm->context.priority_cached;
444}
445
446/* Set caching correctly for an mm that we are switching to. */
447void check_mm_caching(struct mm_struct *prev, struct mm_struct *next)
448{
449 if (!mm_is_priority_cached(next)) {
450 /*
451 * If the new mm doesn't use priority caching, just see if we
452 * need the hv_set_caching(), or can assume it's already zero.
453 */
454 if (mm_is_priority_cached(prev))
455 hv_set_caching(0);
456 } else {
457 hv_set_caching(update_priority_cached(next));
458 }
459}
460
461#if CHIP_HAS_MMIO()
462
463/* Map an arbitrary MMIO address, homed according to pgprot, into VA space. */
464void __iomem *ioremap_prot(resource_size_t phys_addr, unsigned long size,
465 pgprot_t home)
466{
467 void *addr;
468 struct vm_struct *area;
469 unsigned long offset, last_addr;
470 pgprot_t pgprot;
471
472 /* Don't allow wraparound or zero size */
473 last_addr = phys_addr + size - 1;
474 if (!size || last_addr < phys_addr)
475 return NULL;
476
477 /* Create a read/write, MMIO VA mapping homed at the requested shim. */
478 pgprot = PAGE_KERNEL;
479 pgprot = hv_pte_set_mode(pgprot, HV_PTE_MODE_MMIO);
480 pgprot = hv_pte_set_lotar(pgprot, hv_pte_get_lotar(home));
481
482 /*
483 * Mappings have to be page-aligned
484 */
485 offset = phys_addr & ~PAGE_MASK;
486 phys_addr &= PAGE_MASK;
487 size = PAGE_ALIGN(last_addr+1) - phys_addr;
488
489 /*
490 * Ok, go for it..
491 */
492 area = get_vm_area(size, VM_IOREMAP /* | other flags? */);
493 if (!area)
494 return NULL;
495 area->phys_addr = phys_addr;
496 addr = area->addr;
497 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
498 phys_addr, pgprot)) {
499 free_vm_area(area);
500 return NULL;
501 }
502 return (__force void __iomem *) (offset + (char *)addr);
503}
504EXPORT_SYMBOL(ioremap_prot);
505
506#if !defined(CONFIG_PCI) || !defined(CONFIG_TILEGX)
507/* ioremap is conditionally declared in pci_gx.c */
508
509void __iomem *ioremap(resource_size_t phys_addr, unsigned long size)
510{
511 return NULL;
512}
513EXPORT_SYMBOL(ioremap);
514
515#endif
516
517/* Unmap an MMIO VA mapping. */
518void iounmap(volatile void __iomem *addr_in)
519{
520 volatile void __iomem *addr = (volatile void __iomem *)
521 (PAGE_MASK & (unsigned long __force)addr_in);
522#if 1
523 vunmap((void * __force)addr);
524#else
525 /* x86 uses this complicated flow instead of vunmap(). Is
526 * there any particular reason we should do the same? */
527 struct vm_struct *p, *o;
528
529 /* Use the vm area unlocked, assuming the caller
530 ensures there isn't another iounmap for the same address
531 in parallel. Reuse of the virtual address is prevented by
532 leaving it in the global lists until we're done with it.
533 cpa takes care of the direct mappings. */
534 p = find_vm_area((void *)addr);
535
536 if (!p) {
537 pr_err("iounmap: bad address %p\n", addr);
538 dump_stack();
539 return;
540 }
541
542 /* Finally remove it */
543 o = remove_vm_area((void *)addr);
544 BUG_ON(p != o || o == NULL);
545 kfree(p);
546#endif
547}
548EXPORT_SYMBOL(iounmap);
549
550#endif /* CHIP_HAS_MMIO() */
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 8b14bd326d4a..5b997138e092 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -2319,25 +2319,6 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865_HB,
2319DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82875_HB, 2319DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82875_HB,
2320 quirk_unhide_mch_dev6); 2320 quirk_unhide_mch_dev6);
2321 2321
2322#ifdef CONFIG_TILEPRO
2323/*
2324 * The Tilera TILEmpower tilepro platform needs to set the link speed
2325 * to 2.5GT(Giga-Transfers)/s (Gen 1). The default link speed
2326 * setting is 5GT/s (Gen 2). 0x98 is the Link Control2 PCIe
2327 * capability register of the PEX8624 PCIe switch. The switch
2328 * supports link speed auto negotiation, but falsely sets
2329 * the link speed to 5GT/s.
2330 */
2331static void quirk_tile_plx_gen1(struct pci_dev *dev)
2332{
2333 if (tile_plx_gen1) {
2334 pci_write_config_dword(dev, 0x98, 0x1);
2335 mdelay(50);
2336 }
2337}
2338DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PLX, 0x8624, quirk_tile_plx_gen1);
2339#endif /* CONFIG_TILEPRO */
2340
2341#ifdef CONFIG_PCI_MSI 2322#ifdef CONFIG_PCI_MSI
2342/* Some chipsets do not support MSI. We cannot easily rely on setting 2323/* Some chipsets do not support MSI. We cannot easily rely on setting
2343 * PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually 2324 * PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually
diff --git a/samples/kprobes/kprobe_example.c b/samples/kprobes/kprobe_example.c
index 67de3b774bc9..02be8984c32f 100644
--- a/samples/kprobes/kprobe_example.c
+++ b/samples/kprobes/kprobe_example.c
@@ -38,10 +38,6 @@ static int handler_pre(struct kprobe *p, struct pt_regs *regs)
38 pr_info("<%s> pre_handler: p->addr = 0x%p, epc = 0x%lx, status = 0x%lx\n", 38 pr_info("<%s> pre_handler: p->addr = 0x%p, epc = 0x%lx, status = 0x%lx\n",
39 p->symbol_name, p->addr, regs->cp0_epc, regs->cp0_status); 39 p->symbol_name, p->addr, regs->cp0_epc, regs->cp0_status);
40#endif 40#endif
41#ifdef CONFIG_TILEGX
42 pr_info("<%s> pre_handler: p->addr = 0x%p, pc = 0x%lx, ex1 = 0x%lx\n",
43 p->symbol_name, p->addr, regs->pc, regs->ex1);
44#endif
45#ifdef CONFIG_ARM64 41#ifdef CONFIG_ARM64
46 pr_info("<%s> pre_handler: p->addr = 0x%p, pc = 0x%lx," 42 pr_info("<%s> pre_handler: p->addr = 0x%p, pc = 0x%lx,"
47 " pstate = 0x%lx\n", 43 " pstate = 0x%lx\n",
@@ -72,10 +68,6 @@ static void handler_post(struct kprobe *p, struct pt_regs *regs,
72 pr_info("<%s> post_handler: p->addr = 0x%p, status = 0x%lx\n", 68 pr_info("<%s> post_handler: p->addr = 0x%p, status = 0x%lx\n",
73 p->symbol_name, p->addr, regs->cp0_status); 69 p->symbol_name, p->addr, regs->cp0_status);
74#endif 70#endif
75#ifdef CONFIG_TILEGX
76 pr_info("<%s> post_handler: p->addr = 0x%p, ex1 = 0x%lx\n",
77 p->symbol_name, p->addr, regs->ex1);
78#endif
79#ifdef CONFIG_ARM64 71#ifdef CONFIG_ARM64
80 pr_info("<%s> post_handler: p->addr = 0x%p, pstate = 0x%lx\n", 72 pr_info("<%s> post_handler: p->addr = 0x%p, pstate = 0x%lx\n",
81 p->symbol_name, p->addr, (long)regs->pstate); 73 p->symbol_name, p->addr, (long)regs->pstate);
diff --git a/tools/arch/tile/include/asm/barrier.h b/tools/arch/tile/include/asm/barrier.h
deleted file mode 100644
index 7ad02a591b43..000000000000
--- a/tools/arch/tile/include/asm/barrier.h
+++ /dev/null
@@ -1,16 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _TOOLS_LINUX_ASM_TILE_BARRIER_H
3#define _TOOLS_LINUX_ASM_TILE_BARRIER_H
4/*
5 * FIXME: This came from tools/perf/perf-sys.h, where it was first introduced
6 * in 620830b6954913647b7c7f68920cf48eddf6ad92, more work needed to make it
7 * more closely follow the Linux kernel arch/tile/include/asm/barrier.h file.
8 * Probably when we continue work on tools/ Kconfig support to have all the
9 * CONFIG_ needed for properly doing that.
10 */
11
12#define mb() asm volatile ("mf" ::: "memory")
13#define wmb() mb()
14#define rmb() mb()
15
16#endif /* _TOOLS_LINUX_ASM_TILE_BARRIER_H */
diff --git a/tools/arch/tile/include/uapi/asm/bitsperlong.h b/tools/arch/tile/include/uapi/asm/bitsperlong.h
deleted file mode 100644
index 57cca78c0fbb..000000000000
--- a/tools/arch/tile/include/uapi/asm/bitsperlong.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for
13 * more details.
14 */
15
16#ifndef _ASM_TILE_BITSPERLONG_H
17#define _ASM_TILE_BITSPERLONG_H
18
19#ifdef __LP64__
20# define __BITS_PER_LONG 64
21#else
22# define __BITS_PER_LONG 32
23#endif
24
25#include <asm-generic/bitsperlong.h>
26
27#endif /* _ASM_TILE_BITSPERLONG_H */
diff --git a/tools/arch/tile/include/uapi/asm/mman.h b/tools/arch/tile/include/uapi/asm/mman.h
deleted file mode 100644
index 65ec92925c6c..000000000000
--- a/tools/arch/tile/include/uapi/asm/mman.h
+++ /dev/null
@@ -1,16 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2#ifndef TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
3#define TOOLS_ARCH_TILE_UAPI_ASM_MMAN_FIX_H
4#define MAP_DENYWRITE 0x0800
5#define MAP_EXECUTABLE 0x1000
6#define MAP_GROWSDOWN 0x0100
7#define MAP_HUGETLB 0x4000
8#define MAP_LOCKED 0x0200
9#define MAP_NONBLOCK 0x0080
10#define MAP_NORESERVE 0x0400
11#define MAP_POPULATE 0x0040
12#define MAP_STACK MAP_GROWSDOWN
13#include <uapi/asm-generic/mman-common.h>
14/* MAP_32BIT is undefined on tile, fix it for perf */
15#define MAP_32BIT 0
16#endif
diff --git a/tools/scripts/Makefile.arch b/tools/scripts/Makefile.arch
index 78d90a249e88..b10b7a27c33f 100644
--- a/tools/scripts/Makefile.arch
+++ b/tools/scripts/Makefile.arch
@@ -4,8 +4,7 @@ HOSTARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
4 -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \ 4 -e /arm64/!s/arm.*/arm/ -e s/sa110/arm/ \
5 -e s/s390x/s390/ -e s/parisc64/parisc/ \ 5 -e s/s390x/s390/ -e s/parisc64/parisc/ \
6 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ 6 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
7 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \ 7 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
8 -e s/tile.*/tile/ )
9 8
10ifndef ARCH 9ifndef ARCH
11ARCH := $(HOSTARCH) 10ARCH := $(HOSTARCH)
@@ -34,14 +33,6 @@ ifeq ($(ARCH),sh64)
34 SRCARCH := sh 33 SRCARCH := sh
35endif 34endif
36 35
37# Additional ARCH settings for tile
38ifeq ($(ARCH),tilepro)
39 SRCARCH := tile
40endif
41ifeq ($(ARCH),tilegx)
42 SRCARCH := tile
43endif
44
45LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) 36LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
46ifeq ($(LP64), 1) 37ifeq ($(LP64), 1)
47 IS_64_BIT := 1 38 IS_64_BIT := 1
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 0c8b61f8398e..8809f244bb7c 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -3683,8 +3683,6 @@ sub read_depends {
3683 # what directory to look at. 3683 # what directory to look at.
3684 if ($arch eq "i386" || $arch eq "x86_64") { 3684 if ($arch eq "i386" || $arch eq "x86_64") {
3685 $arch = "x86"; 3685 $arch = "x86";
3686 } elsif ($arch =~ /^tile/) {
3687 $arch = "tile";
3688 } 3686 }
3689 3687
3690 my $kconfig = "$builddir/arch/$arch/Kconfig"; 3688 my $kconfig = "$builddir/arch/$arch/Kconfig";