1 diff -Nur linux-4.6.2/arch/.gitignore linux-4.6.2.riscv/arch/.gitignore
2 --- linux-4.6.2/arch/.gitignore 2016-06-08 03:23:53.000000000 +0200
3 +++ linux-4.6.2.riscv/arch/.gitignore 2017-03-04 02:48:34.162887952 +0100
7 +# In ../, we ignored everything, so suppress that.
10 diff -Nur linux-4.6.2/arch/riscv/configs/riscv64_qemu linux-4.6.2.riscv/arch/riscv/configs/riscv64_qemu
11 --- linux-4.6.2/arch/riscv/configs/riscv64_qemu 1970-01-01 01:00:00.000000000 +0100
12 +++ linux-4.6.2.riscv/arch/riscv/configs/riscv64_qemu 2017-03-04 02:48:34.162887952 +0100
14 +# CONFIG_COMPACTION is not set
15 +# CONFIG_CROSS_MEMORY_ATTACH is not set
17 +CONFIG_CROSS_COMPILE="riscv64-unknown-linux-gnu-"
18 +CONFIG_DEFAULT_HOSTNAME="ucbvax"
21 +# CONFIG_BLK_DEV_BSG is not set
22 +CONFIG_PARTITION_ADVANCED=y
23 +# CONFIG_IOSCHED_DEADLINE is not set
28 +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
29 +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
30 +# CONFIG_INET_XFRM_MODE_BEET is not set
31 +# CONFIG_INET_LRO is not set
32 +# CONFIG_INET_DIAG is not set
33 +# CONFIG_IPV6 is not set
34 +# CONFIG_WIRELESS is not set
36 +CONFIG_DEVTMPFS_MOUNT=y
37 +# CONFIG_FIRMWARE_IN_KERNEL is not set
38 +# CONFIG_BLK_DEV is not set
44 +# CONFIG_ETHERNET is not set
45 +# CONFIG_WLAN is not set
46 +# CONFIG_INPUT_MOUSEDEV is not set
47 +# CONFIG_INPUT_KEYBOARD is not set
48 +# CONFIG_INPUT_MOUSE is not set
49 +# CONFIG_VT is not set
51 +# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
52 +CONFIG_SERIAL_8250_CONSOLE=y
53 +CONFIG_SERIAL_8250_NR_UARTS=1
54 +CONFIG_SERIAL_8250_RUNTIME_UARTS=1
55 +CONFIG_VIRTIO_CONSOLE=y
56 +# CONFIG_HW_RANDOM is not set
57 +# CONFIG_HWMON is not set
59 +# CONFIG_USB_SUPPORT is not set
61 +CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
62 +# CONFIG_IOMMU_SUPPORT is not set
64 +# CONFIG_FILE_LOCKING is not set
65 +# CONFIG_DNOTIFY is not set
66 +# CONFIG_INOTIFY_USER is not set
67 +# CONFIG_PROC_PAGE_MONITOR is not set
69 +# CONFIG_MISC_FILESYSTEMS is not set
70 +# CONFIG_NETWORK_FILESYSTEMS is not set
71 +CONFIG_CMDLINE_BOOL=y
72 +CONFIG_CMDLINE="virtio_mmio.device=0x200@0x400:1 virtio_mmio.device=0x200@0x600:2 virtio_mmio.device=0x200@0x800:3 lpj=100000"
73 +CONFIG_CMDLINE_OVERRIDE=y
75 +CONFIG_DEBUG_SECTION_MISMATCH=y
76 +# CONFIG_CRYPTO_ANSI_CPRNG is not set
77 +# CONFIG_CRYPTO_HW is not set
78 diff -Nur linux-4.6.2/arch/riscv/configs/riscv64_spike linux-4.6.2.riscv/arch/riscv/configs/riscv64_spike
79 --- linux-4.6.2/arch/riscv/configs/riscv64_spike 1970-01-01 01:00:00.000000000 +0100
80 +++ linux-4.6.2.riscv/arch/riscv/configs/riscv64_spike 2017-03-04 02:48:34.162887952 +0100
83 +# Automatically generated file; DO NOT EDIT.
84 +# Linux/riscv 3.14.29 Kernel Configuration
89 +CONFIG_STACKTRACE_SUPPORT=y
90 +CONFIG_RWSEM_GENERIC_SPINLOCK=y
92 +CONFIG_GENERIC_BUG_RELATIVE_POINTERS=y
93 +CONFIG_GENERIC_CALIBRATE_DELAY=y
94 +CONFIG_GENERIC_CSUM=y
95 +CONFIG_GENERIC_HWEIGHT=y
100 +CONFIG_CPU_RV_ROCKET=y
101 +# CONFIG_CPU_RV_GENERIC is not set
102 +CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
104 +# CONFIG_RV_SYSRISCV_ATOMIC is not set
105 +CONFIG_SBI_CONSOLE=y
112 +CONFIG_FLAT_NODE_MEM_MAP=y
113 +CONFIG_HAVE_MEMBLOCK=y
114 +CONFIG_HAVE_MEMBLOCK_NODE_MAP=y
115 +# CONFIG_HAVE_BOOTMEM_INFO_NODE is not set
116 +CONFIG_PAGEFLAGS_EXTENDED=y
117 +CONFIG_SPLIT_PTLOCK_CPUS=4
118 +# CONFIG_COMPACTION is not set
119 +CONFIG_PHYS_ADDR_T_64BIT=y
120 +CONFIG_ZONE_DMA_FLAG=0
121 +# CONFIG_KSM is not set
122 +CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
123 +# CONFIG_CROSS_MEMORY_ATTACH is not set
124 +CONFIG_NEED_PER_CPU_KM=y
125 +# CONFIG_CLEANCACHE is not set
126 +# CONFIG_FRONTSWAP is not set
127 +# CONFIG_CMA is not set
128 +# CONFIG_ZBUD is not set
129 +# CONFIG_ZSMALLOC is not set
130 +CONFIG_PREEMPT_NONE=y
131 +# CONFIG_PREEMPT_VOLUNTARY is not set
132 +# CONFIG_PREEMPT is not set
134 +# CONFIG_HZ_250 is not set
135 +# CONFIG_HZ_300 is not set
136 +# CONFIG_HZ_1000 is not set
138 +# CONFIG_SCHED_HRTICK is not set
139 +CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
145 +CONFIG_BROKEN_ON_SMP=y
146 +CONFIG_INIT_ENV_ARG_LIMIT=32
147 +CONFIG_CROSS_COMPILE="riscv64-unknown-linux-gnu-"
148 +# CONFIG_COMPILE_TEST is not set
149 +CONFIG_LOCALVERSION=""
150 +CONFIG_LOCALVERSION_AUTO=y
151 +CONFIG_DEFAULT_HOSTNAME="ucbvax"
153 +# CONFIG_SYSVIPC is not set
154 +# CONFIG_POSIX_MQUEUE is not set
155 +# CONFIG_FHANDLE is not set
156 +# CONFIG_AUDIT is not set
161 +CONFIG_GENERIC_IRQ_SHOW=y
162 +CONFIG_GENERIC_CLOCKEVENTS=y
163 +CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
168 +CONFIG_HZ_PERIODIC=y
169 +# CONFIG_NO_HZ_IDLE is not set
170 +# CONFIG_NO_HZ is not set
171 +# CONFIG_HIGH_RES_TIMERS is not set
174 +# CPU/Task time and stats accounting
176 +CONFIG_TICK_CPU_ACCOUNTING=y
177 +# CONFIG_BSD_PROCESS_ACCT is not set
178 +# CONFIG_TASKSTATS is not set
184 +# CONFIG_PREEMPT_RCU is not set
185 +# CONFIG_RCU_STALL_COMMON is not set
186 +# CONFIG_TREE_RCU_TRACE is not set
187 +# CONFIG_IKCONFIG is not set
188 +CONFIG_LOG_BUF_SHIFT=17
189 +# CONFIG_CGROUPS is not set
190 +# CONFIG_CHECKPOINT_RESTORE is not set
193 +# CONFIG_USER_NS is not set
196 +# CONFIG_SCHED_AUTOGROUP is not set
197 +# CONFIG_RELAY is not set
198 +# CONFIG_BLK_DEV_INITRD is not set
199 +# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
201 +CONFIG_ANON_INODES=y
202 +CONFIG_SYSCTL_EXCEPTION_TRACE=y
204 +# CONFIG_SYSCTL_SYSCALL is not set
206 +# CONFIG_KALLSYMS_ALL is not set
221 +# Kernel Performance Events And Counters
223 +CONFIG_VM_EVENT_COUNTERS=y
225 +# CONFIG_SLAB is not set
227 +# CONFIG_SLOB is not set
228 +# CONFIG_PROFILING is not set
229 +CONFIG_HAVE_64BIT_ALIGNED_ACCESS=y
230 +# CONFIG_CC_STACKPROTECTOR is not set
231 +CONFIG_HAVE_VIRT_CPU_ACCOUNTING_GEN=y
232 +CONFIG_CLONE_BACKWARDS=y
235 +# GCOV-based kernel profiling
237 +# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
240 +# CONFIG_MODULES is not set
242 +# CONFIG_BLK_DEV_BSG is not set
243 +# CONFIG_BLK_DEV_BSGLIB is not set
244 +# CONFIG_BLK_DEV_INTEGRITY is not set
245 +# CONFIG_BLK_CMDLINE_PARSER is not set
250 +CONFIG_PARTITION_ADVANCED=y
251 +# CONFIG_ACORN_PARTITION is not set
252 +# CONFIG_AIX_PARTITION is not set
253 +# CONFIG_OSF_PARTITION is not set
254 +# CONFIG_AMIGA_PARTITION is not set
255 +# CONFIG_ATARI_PARTITION is not set
256 +# CONFIG_MAC_PARTITION is not set
257 +CONFIG_MSDOS_PARTITION=y
258 +# CONFIG_BSD_DISKLABEL is not set
259 +# CONFIG_MINIX_SUBPARTITION is not set
260 +# CONFIG_SOLARIS_X86_PARTITION is not set
261 +# CONFIG_UNIXWARE_DISKLABEL is not set
262 +# CONFIG_LDM_PARTITION is not set
263 +# CONFIG_SGI_PARTITION is not set
264 +# CONFIG_ULTRIX_PARTITION is not set
265 +# CONFIG_SUN_PARTITION is not set
266 +# CONFIG_KARMA_PARTITION is not set
267 +# CONFIG_EFI_PARTITION is not set
268 +# CONFIG_SYSV68_PARTITION is not set
269 +# CONFIG_CMDLINE_PARTITION is not set
274 +CONFIG_IOSCHED_NOOP=y
275 +# CONFIG_IOSCHED_DEADLINE is not set
276 +CONFIG_IOSCHED_CFQ=y
277 +CONFIG_DEFAULT_CFQ=y
278 +# CONFIG_DEFAULT_NOOP is not set
279 +CONFIG_DEFAULT_IOSCHED="cfq"
280 +CONFIG_INLINE_SPIN_UNLOCK_IRQ=y
281 +CONFIG_INLINE_READ_UNLOCK=y
282 +CONFIG_INLINE_READ_UNLOCK_IRQ=y
283 +CONFIG_INLINE_WRITE_UNLOCK=y
284 +CONFIG_INLINE_WRITE_UNLOCK_IRQ=y
285 +# CONFIG_FREEZER is not set
288 +# Executable file formats
291 +CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
292 +CONFIG_BINFMT_SCRIPT=y
293 +# CONFIG_HAVE_AOUT is not set
294 +# CONFIG_BINFMT_MISC is not set
298 +# Power management options
300 +# CONFIG_PM_RUNTIME is not set
304 +# Networking options
306 +# CONFIG_PACKET is not set
308 +# CONFIG_UNIX_DIAG is not set
309 +# CONFIG_XFRM_USER is not set
310 +# CONFIG_NET_KEY is not set
312 +# CONFIG_IP_MULTICAST is not set
313 +# CONFIG_IP_ADVANCED_ROUTER is not set
314 +# CONFIG_IP_PNP is not set
315 +# CONFIG_NET_IPIP is not set
316 +# CONFIG_NET_IPGRE_DEMUX is not set
317 +# CONFIG_NET_IP_TUNNEL is not set
318 +# CONFIG_SYN_COOKIES is not set
319 +# CONFIG_INET_AH is not set
320 +# CONFIG_INET_ESP is not set
321 +# CONFIG_INET_IPCOMP is not set
322 +# CONFIG_INET_XFRM_TUNNEL is not set
323 +# CONFIG_INET_TUNNEL is not set
324 +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
325 +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
326 +# CONFIG_INET_XFRM_MODE_BEET is not set
327 +# CONFIG_INET_LRO is not set
328 +# CONFIG_INET_DIAG is not set
329 +# CONFIG_TCP_CONG_ADVANCED is not set
330 +CONFIG_TCP_CONG_CUBIC=y
331 +CONFIG_DEFAULT_TCP_CONG="cubic"
332 +# CONFIG_TCP_MD5SIG is not set
333 +# CONFIG_IPV6 is not set
334 +# CONFIG_NETWORK_SECMARK is not set
335 +# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
336 +# CONFIG_NETFILTER is not set
337 +# CONFIG_IP_DCCP is not set
338 +# CONFIG_IP_SCTP is not set
339 +# CONFIG_RDS is not set
340 +# CONFIG_TIPC is not set
341 +# CONFIG_ATM is not set
342 +# CONFIG_L2TP is not set
343 +# CONFIG_BRIDGE is not set
344 +# CONFIG_VLAN_8021Q is not set
345 +# CONFIG_DECNET is not set
346 +# CONFIG_LLC2 is not set
347 +# CONFIG_IPX is not set
348 +# CONFIG_ATALK is not set
349 +# CONFIG_X25 is not set
350 +# CONFIG_LAPB is not set
351 +# CONFIG_PHONET is not set
352 +# CONFIG_IEEE802154 is not set
353 +# CONFIG_NET_SCHED is not set
354 +# CONFIG_DCB is not set
355 +# CONFIG_BATMAN_ADV is not set
356 +# CONFIG_OPENVSWITCH is not set
357 +# CONFIG_VSOCKETS is not set
358 +# CONFIG_NETLINK_MMAP is not set
359 +# CONFIG_NETLINK_DIAG is not set
360 +# CONFIG_NET_MPLS_GSO is not set
361 +# CONFIG_HSR is not set
362 +CONFIG_NET_RX_BUSY_POLL=y
367 +# CONFIG_NET_PKTGEN is not set
368 +# CONFIG_HAMRADIO is not set
369 +# CONFIG_CAN is not set
370 +# CONFIG_IRDA is not set
371 +# CONFIG_BT is not set
372 +# CONFIG_AF_RXRPC is not set
373 +# CONFIG_WIRELESS is not set
374 +# CONFIG_WIMAX is not set
375 +# CONFIG_RFKILL is not set
376 +# CONFIG_NET_9P is not set
377 +# CONFIG_CAIF is not set
378 +# CONFIG_CEPH_LIB is not set
379 +# CONFIG_NFC is not set
386 +# Generic Driver Options
388 +CONFIG_UEVENT_HELPER_PATH=""
390 +CONFIG_DEVTMPFS_MOUNT=y
392 +CONFIG_PREVENT_FIRMWARE_BUILD=y
394 +# CONFIG_FIRMWARE_IN_KERNEL is not set
395 +CONFIG_EXTRA_FIRMWARE=""
396 +CONFIG_FW_LOADER_USER_HELPER=y
397 +# CONFIG_DEBUG_DRIVER is not set
398 +# CONFIG_DEBUG_DEVRES is not set
399 +# CONFIG_SYS_HYPERVISOR is not set
400 +CONFIG_GENERIC_CPU_DEVICES=y
401 +# CONFIG_DMA_SHARED_BUFFER is not set
406 +# CONFIG_CONNECTOR is not set
407 +# CONFIG_MTD is not set
408 +# CONFIG_PARPORT is not set
409 +# CONFIG_BLK_DEV is not set
414 +# CONFIG_SENSORS_LIS3LV02D is not set
415 +# CONFIG_DUMMY_IRQ is not set
416 +# CONFIG_ATMEL_SSC is not set
417 +# CONFIG_ENCLOSURE_SERVICES is not set
418 +# CONFIG_SRAM is not set
419 +# CONFIG_C2PORT is not set
424 +# CONFIG_EEPROM_93CX6 is not set
427 +# Texas Instruments shared transport line discipline
431 +# Altera FPGA firmware download module
435 +# Intel MIC Host Driver
439 +# Intel MIC Card Driver
443 +# SCSI device support
446 +# CONFIG_RAID_ATTRS is not set
447 +# CONFIG_SCSI is not set
448 +# CONFIG_SCSI_DMA is not set
449 +# CONFIG_SCSI_NETLINK is not set
450 +# CONFIG_ATA is not set
451 +# CONFIG_MD is not set
452 +# CONFIG_NETDEVICES is not set
455 +# Input device support
458 +# CONFIG_INPUT_FF_MEMLESS is not set
459 +# CONFIG_INPUT_POLLDEV is not set
460 +# CONFIG_INPUT_SPARSEKMAP is not set
461 +# CONFIG_INPUT_MATRIXKMAP is not set
464 +# Userland interfaces
466 +# CONFIG_INPUT_MOUSEDEV is not set
467 +# CONFIG_INPUT_JOYDEV is not set
468 +# CONFIG_INPUT_EVDEV is not set
469 +# CONFIG_INPUT_EVBUG is not set
472 +# Input Device Drivers
474 +# CONFIG_INPUT_KEYBOARD is not set
475 +# CONFIG_INPUT_MOUSE is not set
476 +# CONFIG_INPUT_JOYSTICK is not set
477 +# CONFIG_INPUT_TABLET is not set
478 +# CONFIG_INPUT_TOUCHSCREEN is not set
479 +# CONFIG_INPUT_MISC is not set
482 +# Hardware I/O ports
485 +CONFIG_SERIO_SERPORT=y
486 +# CONFIG_SERIO_LIBPS2 is not set
487 +# CONFIG_SERIO_RAW is not set
488 +# CONFIG_SERIO_ALTERA_PS2 is not set
489 +# CONFIG_SERIO_PS2MULT is not set
490 +# CONFIG_SERIO_ARC_PS2 is not set
491 +# CONFIG_GAMEPORT is not set
497 +# CONFIG_VT is not set
498 +CONFIG_UNIX98_PTYS=y
499 +# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
500 +CONFIG_LEGACY_PTYS=y
501 +CONFIG_LEGACY_PTY_COUNT=256
502 +# CONFIG_SERIAL_NONSTANDARD is not set
503 +# CONFIG_N_GSM is not set
504 +# CONFIG_TRACE_SINK is not set
510 +# CONFIG_SERIAL_8250 is not set
513 +# Non-8250 serial port support
515 +# CONFIG_SERIAL_SCCNXP is not set
516 +# CONFIG_SERIAL_TIMBERDALE is not set
517 +# CONFIG_SERIAL_ALTERA_JTAGUART is not set
518 +# CONFIG_SERIAL_ALTERA_UART is not set
519 +# CONFIG_SERIAL_ARC is not set
520 +# CONFIG_SERIAL_FSL_LPUART is not set
521 +# CONFIG_TTY_PRINTK is not set
522 +# CONFIG_IPMI_HANDLER is not set
523 +# CONFIG_HW_RANDOM is not set
524 +# CONFIG_RTC is not set
525 +# CONFIG_GEN_RTC is not set
526 +# CONFIG_R3964 is not set
529 +# PCMCIA character devices
531 +# CONFIG_RAW_DRIVER is not set
532 +# CONFIG_TCG_TPM is not set
533 +# CONFIG_I2C is not set
534 +# CONFIG_SPI is not set
535 +# CONFIG_HSI is not set
540 +# CONFIG_PPS is not set
543 +# PPS generators support
549 +# CONFIG_PTP_1588_CLOCK is not set
552 +# Enable PHYLIB and NETWORK_PHY_TIMESTAMPING to see the additional clocks.
554 +# CONFIG_W1 is not set
555 +# CONFIG_POWER_SUPPLY is not set
556 +# CONFIG_POWER_AVS is not set
557 +# CONFIG_HWMON is not set
558 +# CONFIG_THERMAL is not set
559 +# CONFIG_WATCHDOG is not set
562 +# Multifunction device drivers
564 +# CONFIG_MFD_CORE is not set
565 +# CONFIG_MFD_CROS_EC is not set
566 +# CONFIG_HTC_PASIC3 is not set
567 +# CONFIG_MFD_KEMPLD is not set
568 +# CONFIG_MFD_SM501 is not set
569 +# CONFIG_ABX500_CORE is not set
570 +# CONFIG_MFD_SYSCON is not set
571 +# CONFIG_MFD_TI_AM335X_TSCADC is not set
572 +# CONFIG_MFD_TMIO is not set
573 +# CONFIG_REGULATOR is not set
574 +# CONFIG_MEDIA_SUPPORT is not set
579 +# CONFIG_VGASTATE is not set
580 +# CONFIG_VIDEO_OUTPUT_CONTROL is not set
582 +# CONFIG_FIRMWARE_EDID is not set
583 +# CONFIG_FB_DDC is not set
584 +# CONFIG_FB_BOOT_VESA_SUPPORT is not set
585 +# CONFIG_FB_CFB_FILLRECT is not set
586 +# CONFIG_FB_CFB_COPYAREA is not set
587 +# CONFIG_FB_CFB_IMAGEBLIT is not set
588 +# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
589 +# CONFIG_FB_SYS_FILLRECT is not set
590 +# CONFIG_FB_SYS_COPYAREA is not set
591 +# CONFIG_FB_SYS_IMAGEBLIT is not set
592 +# CONFIG_FB_FOREIGN_ENDIAN is not set
593 +# CONFIG_FB_SYS_FOPS is not set
594 +# CONFIG_FB_SVGALIB is not set
595 +# CONFIG_FB_MACMODES is not set
596 +# CONFIG_FB_BACKLIGHT is not set
597 +# CONFIG_FB_MODE_HELPERS is not set
598 +# CONFIG_FB_TILEBLITTING is not set
601 +# Frame buffer hardware drivers
603 +# CONFIG_FB_OPENCORES is not set
604 +# CONFIG_FB_S1D13XXX is not set
605 +# CONFIG_FB_VIRTUAL is not set
606 +# CONFIG_FB_METRONOME is not set
607 +# CONFIG_FB_BROADSHEET is not set
608 +# CONFIG_FB_AUO_K190X is not set
609 +# CONFIG_FB_SIMPLE is not set
610 +# CONFIG_EXYNOS_VIDEO is not set
611 +# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
612 +# CONFIG_LOGO is not set
613 +# CONFIG_SOUND is not set
619 +# CONFIG_HIDRAW is not set
620 +# CONFIG_UHID is not set
621 +CONFIG_HID_GENERIC=y
624 +# Special HID drivers
626 +# CONFIG_HID_A4TECH is not set
627 +# CONFIG_HID_ACRUX is not set
628 +# CONFIG_HID_APPLE is not set
629 +# CONFIG_HID_AUREAL is not set
630 +# CONFIG_HID_BELKIN is not set
631 +# CONFIG_HID_CHERRY is not set
632 +# CONFIG_HID_CHICONY is not set
633 +# CONFIG_HID_CYPRESS is not set
634 +# CONFIG_HID_DRAGONRISE is not set
635 +# CONFIG_HID_EMS_FF is not set
636 +# CONFIG_HID_ELECOM is not set
637 +# CONFIG_HID_EZKEY is not set
638 +# CONFIG_HID_KEYTOUCH is not set
639 +# CONFIG_HID_KYE is not set
640 +# CONFIG_HID_UCLOGIC is not set
641 +# CONFIG_HID_WALTOP is not set
642 +# CONFIG_HID_GYRATION is not set
643 +# CONFIG_HID_ICADE is not set
644 +# CONFIG_HID_TWINHAN is not set
645 +# CONFIG_HID_KENSINGTON is not set
646 +# CONFIG_HID_LCPOWER is not set
647 +# CONFIG_HID_LENOVO_TPKBD is not set
648 +# CONFIG_HID_LOGITECH is not set
649 +# CONFIG_HID_MAGICMOUSE is not set
650 +# CONFIG_HID_MICROSOFT is not set
651 +# CONFIG_HID_MONTEREY is not set
652 +# CONFIG_HID_MULTITOUCH is not set
653 +# CONFIG_HID_ORTEK is not set
654 +# CONFIG_HID_PANTHERLORD is not set
655 +# CONFIG_HID_PETALYNX is not set
656 +# CONFIG_HID_PICOLCD is not set
657 +# CONFIG_HID_PRIMAX is not set
658 +# CONFIG_HID_SAITEK is not set
659 +# CONFIG_HID_SAMSUNG is not set
660 +# CONFIG_HID_SPEEDLINK is not set
661 +# CONFIG_HID_STEELSERIES is not set
662 +# CONFIG_HID_SUNPLUS is not set
663 +# CONFIG_HID_GREENASIA is not set
664 +# CONFIG_HID_SMARTJOYPLUS is not set
665 +# CONFIG_HID_TIVO is not set
666 +# CONFIG_HID_TOPSEED is not set
667 +# CONFIG_HID_THRUSTMASTER is not set
668 +# CONFIG_HID_XINMO is not set
669 +# CONFIG_HID_ZEROPLUS is not set
670 +# CONFIG_HID_ZYDACRON is not set
671 +# CONFIG_HID_SENSOR_HUB is not set
672 +CONFIG_USB_OHCI_LITTLE_ENDIAN=y
673 +# CONFIG_USB_SUPPORT is not set
674 +# CONFIG_MMC is not set
675 +# CONFIG_MEMSTICK is not set
676 +# CONFIG_NEW_LEDS is not set
677 +# CONFIG_ACCESSIBILITY is not set
678 +# CONFIG_RTC_CLASS is not set
679 +# CONFIG_AUXDISPLAY is not set
680 +# CONFIG_UIO is not set
681 +# CONFIG_VIRT_DRIVERS is not set
686 +# CONFIG_VIRTIO_MMIO is not set
689 +# Microsoft Hyper-V guest support
691 +# CONFIG_STAGING is not set
694 +# Hardware Spinlock drivers
696 +# CONFIG_MAILBOX is not set
697 +# CONFIG_IOMMU_SUPPORT is not set
700 +# Remoteproc drivers
706 +# CONFIG_PM_DEVFREQ is not set
707 +# CONFIG_EXTCON is not set
708 +# CONFIG_MEMORY is not set
709 +# CONFIG_IIO is not set
710 +# CONFIG_PWM is not set
711 +# CONFIG_IPACK_BUS is not set
712 +# CONFIG_RESET_CONTROLLER is not set
713 +# CONFIG_FMC is not set
718 +# CONFIG_GENERIC_PHY is not set
719 +# CONFIG_PHY_EXYNOS_MIPI_VIDEO is not set
720 +# CONFIG_POWERCAP is not set
726 +# CONFIG_EXT2_FS_XATTR is not set
727 +# CONFIG_EXT2_FS_XIP is not set
728 +# CONFIG_EXT3_FS is not set
729 +# CONFIG_EXT4_FS is not set
730 +# CONFIG_REISERFS_FS is not set
731 +# CONFIG_JFS_FS is not set
732 +# CONFIG_XFS_FS is not set
733 +# CONFIG_GFS2_FS is not set
734 +# CONFIG_BTRFS_FS is not set
735 +# CONFIG_NILFS2_FS is not set
736 +# CONFIG_FS_POSIX_ACL is not set
737 +# CONFIG_FILE_LOCKING is not set
738 +# CONFIG_FSNOTIFY is not set
739 +# CONFIG_DNOTIFY is not set
740 +# CONFIG_INOTIFY_USER is not set
741 +# CONFIG_FANOTIFY is not set
742 +# CONFIG_QUOTA is not set
743 +# CONFIG_QUOTACTL is not set
744 +# CONFIG_AUTOFS4_FS is not set
745 +# CONFIG_FUSE_FS is not set
750 +# CONFIG_FSCACHE is not set
753 +# CD-ROM/DVD Filesystems
755 +# CONFIG_ISO9660_FS is not set
756 +# CONFIG_UDF_FS is not set
759 +# DOS/FAT/NT Filesystems
761 +# CONFIG_MSDOS_FS is not set
762 +# CONFIG_VFAT_FS is not set
763 +# CONFIG_NTFS_FS is not set
766 +# Pseudo filesystems
769 +# CONFIG_PROC_KCORE is not set
770 +CONFIG_PROC_SYSCTL=y
771 +# CONFIG_PROC_PAGE_MONITOR is not set
772 +# CONFIG_SYSFS is not set
774 +# CONFIG_TMPFS_POSIX_ACL is not set
775 +# CONFIG_TMPFS_XATTR is not set
776 +# CONFIG_HUGETLB_PAGE is not set
777 +# CONFIG_CONFIGFS_FS is not set
778 +# CONFIG_MISC_FILESYSTEMS is not set
779 +# CONFIG_NETWORK_FILESYSTEMS is not set
780 +# CONFIG_NLS is not set
785 +# CONFIG_CMDLINE_BOOL is not set
786 +# CONFIG_EARLY_PRINTK is not set
789 +# printk and dmesg options
791 +CONFIG_PRINTK_TIME=y
792 +CONFIG_DEFAULT_MESSAGE_LOGLEVEL=4
793 +# CONFIG_BOOT_PRINTK_DELAY is not set
796 +# Compile-time checks and compiler options
798 +# CONFIG_DEBUG_INFO is not set
799 +CONFIG_ENABLE_WARN_DEPRECATED=y
800 +CONFIG_ENABLE_MUST_CHECK=y
801 +CONFIG_FRAME_WARN=2048
802 +# CONFIG_STRIP_ASM_SYMS is not set
803 +# CONFIG_READABLE_ASM is not set
804 +# CONFIG_UNUSED_SYMBOLS is not set
805 +# CONFIG_DEBUG_FS is not set
806 +# CONFIG_HEADERS_CHECK is not set
807 +CONFIG_DEBUG_SECTION_MISMATCH=y
808 +CONFIG_ARCH_WANT_FRAME_POINTERS=y
809 +# CONFIG_FRAME_POINTER is not set
810 +# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
811 +# CONFIG_MAGIC_SYSRQ is not set
812 +CONFIG_DEBUG_KERNEL=y
817 +# CONFIG_DEBUG_PAGEALLOC is not set
818 +# CONFIG_DEBUG_OBJECTS is not set
819 +# CONFIG_DEBUG_STACK_USAGE is not set
820 +# CONFIG_DEBUG_VM is not set
821 +# CONFIG_DEBUG_MEMORY_INIT is not set
822 +# CONFIG_DEBUG_SHIRQ is not set
825 +# Debug Lockups and Hangs
827 +# CONFIG_LOCKUP_DETECTOR is not set
828 +# CONFIG_DETECT_HUNG_TASK is not set
829 +# CONFIG_PANIC_ON_OOPS is not set
830 +CONFIG_PANIC_ON_OOPS_VALUE=0
831 +CONFIG_PANIC_TIMEOUT=0
832 +CONFIG_SCHED_DEBUG=y
833 +# CONFIG_SCHEDSTATS is not set
834 +# CONFIG_TIMER_STATS is not set
837 +# Lock Debugging (spinlocks, mutexes, etc...)
839 +# CONFIG_DEBUG_RT_MUTEXES is not set
840 +# CONFIG_RT_MUTEX_TESTER is not set
841 +# CONFIG_DEBUG_SPINLOCK is not set
842 +# CONFIG_DEBUG_MUTEXES is not set
843 +# CONFIG_DEBUG_ATOMIC_SLEEP is not set
844 +# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
845 +# CONFIG_DEBUG_KOBJECT is not set
846 +CONFIG_DEBUG_BUGVERBOSE=y
847 +# CONFIG_DEBUG_WRITECOUNT is not set
848 +# CONFIG_DEBUG_LIST is not set
849 +# CONFIG_DEBUG_SG is not set
850 +# CONFIG_DEBUG_NOTIFIERS is not set
851 +# CONFIG_DEBUG_CREDENTIALS is not set
856 +# CONFIG_SPARSE_RCU_POINTER is not set
857 +# CONFIG_RCU_TORTURE_TEST is not set
858 +# CONFIG_RCU_TRACE is not set
859 +# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
860 +# CONFIG_NOTIFIER_ERROR_INJECTION is not set
861 +# CONFIG_FAULT_INJECTION is not set
866 +# CONFIG_TEST_LIST_SORT is not set
867 +# CONFIG_BACKTRACE_SELF_TEST is not set
868 +# CONFIG_RBTREE_TEST is not set
869 +# CONFIG_ATOMIC64_SELFTEST is not set
870 +# CONFIG_TEST_STRING_HELPERS is not set
871 +# CONFIG_TEST_KSTRTOX is not set
872 +# CONFIG_SAMPLES is not set
877 +# CONFIG_KEYS is not set
878 +# CONFIG_SECURITY_DMESG_RESTRICT is not set
879 +# CONFIG_SECURITYFS is not set
880 +CONFIG_DEFAULT_SECURITY_DAC=y
881 +CONFIG_DEFAULT_SECURITY=""
885 +# Crypto core or helper
887 +CONFIG_CRYPTO_ALGAPI=y
888 +CONFIG_CRYPTO_ALGAPI2=y
889 +# CONFIG_CRYPTO_MANAGER is not set
890 +# CONFIG_CRYPTO_MANAGER2 is not set
891 +# CONFIG_CRYPTO_USER is not set
892 +# CONFIG_CRYPTO_GF128MUL is not set
893 +# CONFIG_CRYPTO_NULL is not set
894 +# CONFIG_CRYPTO_CRYPTD is not set
895 +# CONFIG_CRYPTO_AUTHENC is not set
898 +# Authenticated Encryption with Associated Data
900 +# CONFIG_CRYPTO_CCM is not set
901 +# CONFIG_CRYPTO_GCM is not set
902 +# CONFIG_CRYPTO_SEQIV is not set
907 +# CONFIG_CRYPTO_CBC is not set
908 +# CONFIG_CRYPTO_CTR is not set
909 +# CONFIG_CRYPTO_CTS is not set
910 +# CONFIG_CRYPTO_ECB is not set
911 +# CONFIG_CRYPTO_LRW is not set
912 +# CONFIG_CRYPTO_PCBC is not set
913 +# CONFIG_CRYPTO_XTS is not set
918 +# CONFIG_CRYPTO_CMAC is not set
919 +# CONFIG_CRYPTO_HMAC is not set
920 +# CONFIG_CRYPTO_XCBC is not set
921 +# CONFIG_CRYPTO_VMAC is not set
926 +# CONFIG_CRYPTO_CRC32C is not set
927 +# CONFIG_CRYPTO_CRC32 is not set
928 +# CONFIG_CRYPTO_CRCT10DIF is not set
929 +# CONFIG_CRYPTO_GHASH is not set
930 +# CONFIG_CRYPTO_MD4 is not set
931 +# CONFIG_CRYPTO_MD5 is not set
932 +# CONFIG_CRYPTO_MICHAEL_MIC is not set
933 +# CONFIG_CRYPTO_RMD128 is not set
934 +# CONFIG_CRYPTO_RMD160 is not set
935 +# CONFIG_CRYPTO_RMD256 is not set
936 +# CONFIG_CRYPTO_RMD320 is not set
937 +# CONFIG_CRYPTO_SHA1 is not set
938 +# CONFIG_CRYPTO_SHA256 is not set
939 +# CONFIG_CRYPTO_SHA512 is not set
940 +# CONFIG_CRYPTO_TGR192 is not set
941 +# CONFIG_CRYPTO_WP512 is not set
947 +# CONFIG_CRYPTO_ANUBIS is not set
948 +# CONFIG_CRYPTO_ARC4 is not set
949 +# CONFIG_CRYPTO_BLOWFISH is not set
950 +# CONFIG_CRYPTO_CAMELLIA is not set
951 +# CONFIG_CRYPTO_CAST5 is not set
952 +# CONFIG_CRYPTO_CAST6 is not set
953 +# CONFIG_CRYPTO_DES is not set
954 +# CONFIG_CRYPTO_FCRYPT is not set
955 +# CONFIG_CRYPTO_KHAZAD is not set
956 +# CONFIG_CRYPTO_SALSA20 is not set
957 +# CONFIG_CRYPTO_SEED is not set
958 +# CONFIG_CRYPTO_SERPENT is not set
959 +# CONFIG_CRYPTO_TEA is not set
960 +# CONFIG_CRYPTO_TWOFISH is not set
965 +# CONFIG_CRYPTO_DEFLATE is not set
966 +# CONFIG_CRYPTO_ZLIB is not set
967 +# CONFIG_CRYPTO_LZO is not set
968 +# CONFIG_CRYPTO_LZ4 is not set
969 +# CONFIG_CRYPTO_LZ4HC is not set
972 +# Random Number Generation
974 +# CONFIG_CRYPTO_ANSI_CPRNG is not set
975 +# CONFIG_CRYPTO_USER_API_HASH is not set
976 +# CONFIG_CRYPTO_USER_API_SKCIPHER is not set
977 +# CONFIG_CRYPTO_HW is not set
978 +# CONFIG_BINARY_PRINTF is not set
984 +CONFIG_GENERIC_STRNCPY_FROM_USER=y
985 +CONFIG_GENERIC_STRNLEN_USER=y
986 +CONFIG_GENERIC_NET_UTILS=y
988 +# CONFIG_CRC_CCITT is not set
989 +# CONFIG_CRC16 is not set
990 +# CONFIG_CRC_T10DIF is not set
991 +# CONFIG_CRC_ITU_T is not set
993 +# CONFIG_CRC32_SELFTEST is not set
994 +CONFIG_CRC32_SLICEBY8=y
995 +# CONFIG_CRC32_SLICEBY4 is not set
996 +# CONFIG_CRC32_SARWATE is not set
997 +# CONFIG_CRC32_BIT is not set
998 +# CONFIG_CRC7 is not set
999 +# CONFIG_LIBCRC32C is not set
1000 +# CONFIG_CRC8 is not set
1001 +# CONFIG_RANDOM32_SELFTEST is not set
1002 +# CONFIG_XZ_DEC is not set
1003 +# CONFIG_XZ_DEC_BCJ is not set
1005 +CONFIG_HAS_IOPORT=y
1007 +CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE=y
1008 +# CONFIG_AVERAGE is not set
1009 +# CONFIG_CORDIC is not set
1010 +# CONFIG_DDR is not set
1011 diff -Nur linux-4.6.2/arch/riscv/.gitignore linux-4.6.2.riscv/arch/riscv/.gitignore
1012 --- linux-4.6.2/arch/riscv/.gitignore 1970-01-01 01:00:00.000000000 +0100
1013 +++ linux-4.6.2.riscv/arch/riscv/.gitignore 2017-03-04 02:48:34.162887952 +0100
1015 +# Now un-ignore all files.
1018 +# But then re-ignore the files listed in the Linux .gitignore
1048 +# Then reinclude .gitignore.
1050 diff -Nur linux-4.6.2/arch/riscv/include/asm/asm.h linux-4.6.2.riscv/arch/riscv/include/asm/asm.h
1051 --- linux-4.6.2/arch/riscv/include/asm/asm.h 1970-01-01 01:00:00.000000000 +0100
1052 +++ linux-4.6.2.riscv/arch/riscv/include/asm/asm.h 2017-03-04 02:48:34.162887952 +0100
1054 +#ifndef _ASM_RISCV_ASM_H
1055 +#define _ASM_RISCV_ASM_H
1057 +#ifdef __ASSEMBLY__
1058 +#define __ASM_STR(x) x
1060 +#define __ASM_STR(x) #x
1063 +#if __riscv_xlen == 64
1064 +#define __REG_SEL(a,b) __ASM_STR(a)
1065 +#elif __riscv_xlen == 32
1066 +#define __REG_SEL(a,b) __ASM_STR(b)
1068 +#error "Unexpected __riscv_xlen"
1071 +#define REG_L __REG_SEL(ld, lw)
1072 +#define REG_S __REG_SEL(sd, sw)
1073 +#define SZREG __REG_SEL(8, 4)
1074 +#define LGREG __REG_SEL(3, 2)
1076 +#if __SIZEOF_POINTER__ == 8
1077 +#define __PTR_SEL(a,b) __ASM_STR(a)
1078 +#elif __SIZEOF_POINTER__ == 4
1079 +#define __PTR_SEL(a,b) __ASM_STR(b)
1081 +#error "Unexpected __SIZEOF_POINTER__"
1084 +#define PTR __PTR_SEL(.dword, .word)
1085 +#define SZPTR __PTR_SEL(8, 4)
1086 +#define LGPTR __PTR_SEL(3, 2)
1088 +#if (__SIZEOF_INT__ == 4)
1089 +#define INT __ASM_STR(.word)
1090 +#define SZINT __ASM_STR(4)
1091 +#define LGINT __ASM_STR(2)
1093 +#error "Unexpected __SIZEOF_INT__"
1096 +#if (__SIZEOF_SHORT__ == 2)
1097 +#define SHORT __ASM_STR(.half)
1098 +#define SZSHORT __ASM_STR(2)
1099 +#define LGSHORT __ASM_STR(1)
1101 +#error "Unexpected __SIZEOF_SHORT__"
1104 +#endif /* _ASM_RISCV_ASM_H */
1105 diff -Nur linux-4.6.2/arch/riscv/include/asm/asm-offsets.h linux-4.6.2.riscv/arch/riscv/include/asm/asm-offsets.h
1106 --- linux-4.6.2/arch/riscv/include/asm/asm-offsets.h 1970-01-01 01:00:00.000000000 +0100
1107 +++ linux-4.6.2.riscv/arch/riscv/include/asm/asm-offsets.h 2017-03-04 02:48:34.162887952 +0100
1109 +#include <generated/asm-offsets.h>
1110 diff -Nur linux-4.6.2/arch/riscv/include/asm/atomic64.h linux-4.6.2.riscv/arch/riscv/include/asm/atomic64.h
1111 --- linux-4.6.2/arch/riscv/include/asm/atomic64.h 1970-01-01 01:00:00.000000000 +0100
1112 +++ linux-4.6.2.riscv/arch/riscv/include/asm/atomic64.h 2017-03-04 02:48:34.166888015 +0100
1114 +#ifndef _ASM_RISCV_ATOMIC64_H
1115 +#define _ASM_RISCV_ATOMIC64_H
1117 +#ifdef CONFIG_GENERIC_ATOMIC64
1118 +#include <asm-generic/atomic64.h>
1119 +#else /* !CONFIG_GENERIC_ATOMIC64 */
1121 +#include <linux/types.h>
1123 +#define ATOMIC64_INIT(i) { (i) }
1126 + * atomic64_read - read atomic64 variable
1127 + * @v: pointer of type atomic64_t
1129 + * Atomically reads the value of @v.
1131 +static inline s64 atomic64_read(const atomic64_t *v)
1133 + return *((volatile long *)(&(v->counter)));
1137 + * atomic64_set - set atomic64 variable
1138 + * @v: pointer to type atomic64_t
1139 + * @i: required value
1141 + * Atomically sets the value of @v to @i.
1143 +static inline void atomic64_set(atomic64_t *v, s64 i)
1149 + * atomic64_add - add integer to atomic64 variable
1150 + * @i: integer value to add
1151 + * @v: pointer to type atomic64_t
1153 + * Atomically adds @i to @v.
1155 +static inline void atomic64_add(s64 a, atomic64_t *v)
1157 + __asm__ __volatile__ (
1158 + "amoadd.d zero, %1, %0"
1159 + : "+A" (v->counter)
1164 + * atomic64_sub - subtract the atomic64 variable
1165 + * @i: integer value to subtract
1166 + * @v: pointer to type atomic64_t
1168 + * Atomically subtracts @i from @v.
1170 +static inline void atomic64_sub(s64 a, atomic64_t *v)
1172 + atomic64_add(-a, v);
1176 + * atomic64_add_return - add and return
1177 + * @i: integer value to add
1178 + * @v: pointer to type atomic64_t
1180 + * Atomically adds @i to @v and returns @i + @v
1182 +static inline s64 atomic64_add_return(s64 a, atomic64_t *v)
1185 + __asm__ __volatile__ (
1186 + "amoadd.d %0, %2, %1"
1187 + : "=r" (c), "+A" (v->counter)
1192 +static inline s64 atomic64_sub_return(s64 a, atomic64_t *v)
1194 + return atomic64_add_return(-a, v);
1198 + * atomic64_inc - increment atomic64 variable
1199 + * @v: pointer to type atomic64_t
1201 + * Atomically increments @v by 1.
1203 +static inline void atomic64_inc(atomic64_t *v)
1205 + atomic64_add(1L, v);
1209 + * atomic64_dec - decrement atomic64 variable
1210 + * @v: pointer to type atomic64_t
1212 + * Atomically decrements @v by 1.
1214 +static inline void atomic64_dec(atomic64_t *v)
1216 + atomic64_add(-1L, v);
1219 +static inline s64 atomic64_inc_return(atomic64_t *v)
1221 + return atomic64_add_return(1L, v);
1224 +static inline s64 atomic64_dec_return(atomic64_t *v)
1226 + return atomic64_add_return(-1L, v);
1230 + * atomic64_inc_and_test - increment and test
1231 + * @v: pointer to type atomic64_t
1233 + * Atomically increments @v by 1
1234 + * and returns true if the result is zero, or false for all
1237 +static inline int atomic64_inc_and_test(atomic64_t *v)
1239 + return (atomic64_inc_return(v) == 0);
1243 + * atomic64_dec_and_test - decrement and test
1244 + * @v: pointer to type atomic64_t
1246 + * Atomically decrements @v by 1 and
1247 + * returns true if the result is 0, or false for all other
1250 +static inline int atomic64_dec_and_test(atomic64_t *v)
1252 + return (atomic64_dec_return(v) == 0);
1256 + * atomic64_sub_and_test - subtract value from variable and test result
1257 + * @a: integer value to subtract
1258 + * @v: pointer to type atomic64_t
1260 + * Atomically subtracts @a from @v and returns
1261 + * true if the result is zero, or false for all
1264 +static inline int atomic64_sub_and_test(s64 a, atomic64_t *v)
1266 + return (atomic64_sub_return(a, v) == 0);
1270 + * atomic64_add_negative - add and test if negative
1271 + * @a: integer value to add
1272 + * @v: pointer to type atomic64_t
1274 + * Atomically adds @a to @v and returns true
1275 + * if the result is negative, or false when
1276 + * result is greater than or equal to zero.
1278 +static inline int atomic64_add_negative(s64 a, atomic64_t *v)
1280 + return (atomic64_add_return(a, v) < 0);
1284 +static inline s64 atomic64_xchg(atomic64_t *v, s64 n)
1287 + __asm__ __volatile__ (
1288 + "amoswap.d %0, %2, %1"
1289 + : "=r" (c), "+A" (v->counter)
1294 +static inline s64 atomic64_cmpxchg(atomic64_t *v, s64 o, s64 n)
1296 + return cmpxchg(&(v->counter), o, n);
1300 + * atomic64_dec_if_positive - decrement by 1 if old value positive
1301 + * @v: pointer of type atomic_t
1303 + * The function returns the old value of *v minus 1, even if
1304 + * the atomic variable, v, was not decremented.
1306 +static inline s64 atomic64_dec_if_positive(atomic64_t *v)
1308 + register s64 prev, rc;
1309 + __asm__ __volatile__ (
1312 + "add %0, %0, -1\n"
1314 + "sc.w %1, %0, %2\n"
1317 + : "=&r" (prev), "=r" (rc), "+A" (v->counter));
1322 + * atomic64_add_unless - add unless the number is a given value
1323 + * @v: pointer of type atomic64_t
1324 + * @a: the amount to add to v...
1325 + * @u: ...unless v is equal to u.
1327 + * Atomically adds @a to @v, so long as it was not @u.
1328 + * Returns true if the addition occurred and false otherwise.
1330 +static inline int atomic64_add_unless(atomic64_t *v, s64 a, s64 u)
1333 + register int rc = 1;
1335 + __asm__ __volatile__ (
1338 + "beq %0, %z4, 1f\n"
1339 + "add %0, %0, %3\n"
1340 + "sc.d %1, %0, %2\n"
1343 + : "=&r" (tmp), "=&r" (rc), "+A" (v->counter)
1344 + : "rI" (a), "rJ" (u));
1348 +static inline int atomic64_inc_not_zero(atomic64_t *v)
1350 + return atomic64_add_unless(v, 1, 0);
1354 + * atomic64_and - Atomically clear bits in atomic variable
1355 + * @mask: Mask of the bits to be retained
1356 + * @v: pointer of type atomic_t
1358 + * Atomically retains the bits set in @mask from @v
1360 +static inline void atomic64_and(s64 mask, atomic64_t *v)
1362 + __asm__ __volatile__ (
1363 + "amoand.d zero, %1, %0"
1364 + : "+A" (v->counter)
1369 + * atomic64_or - Atomically set bits in atomic variable
1370 + * @mask: Mask of the bits to be set
1371 + * @v: pointer of type atomic_t
1373 + * Atomically sets the bits set in @mask in @v
1375 +static inline void atomic64_or(s64 mask, atomic64_t *v)
1377 + __asm__ __volatile__ (
1378 + "amoor.d zero, %1, %0"
1379 + : "+A" (v->counter)
1384 + * atomic64_xor - Atomically flips bits in atomic variable
1385 + * @mask: Mask of the bits to be flipped
1386 + * @v: pointer of type atomic_t
1388 + * Atomically flips the bits set in @mask in @v
1390 +static inline void atomic64_xor(s64 mask, atomic64_t *v)
1392 + __asm__ __volatile__ (
1393 + "amoxor.d zero, %1, %0"
1394 + : "+A" (v->counter)
1398 +#endif /* CONFIG_GENERIC_ATOMIC64 */
1400 +#endif /* _ASM_RISCV_ATOMIC64_H */
1401 diff -Nur linux-4.6.2/arch/riscv/include/asm/atomic.h linux-4.6.2.riscv/arch/riscv/include/asm/atomic.h
1402 --- linux-4.6.2/arch/riscv/include/asm/atomic.h 1970-01-01 01:00:00.000000000 +0100
1403 +++ linux-4.6.2.riscv/arch/riscv/include/asm/atomic.h 2017-03-04 02:48:34.166888015 +0100
1405 +#ifndef _ASM_RISCV_ATOMIC_H
1406 +#define _ASM_RISCV_ATOMIC_H
1408 +#ifdef CONFIG_RV_ATOMIC
1410 +#include <asm/cmpxchg.h>
1411 +#include <asm/barrier.h>
1413 +#define ATOMIC_INIT(i) { (i) }
1416 + * atomic_read - read atomic variable
1417 + * @v: pointer of type atomic_t
1419 + * Atomically reads the value of @v.
1421 +static inline int atomic_read(const atomic_t *v)
1423 + return *((volatile int *)(&(v->counter)));
1427 + * atomic_set - set atomic variable
1428 + * @v: pointer of type atomic_t
1429 + * @i: required value
1431 + * Atomically sets the value of @v to @i.
1433 +static inline void atomic_set(atomic_t *v, int i)
1439 + * atomic_add - add integer to atomic variable
1440 + * @i: integer value to add
1441 + * @v: pointer of type atomic_t
1443 + * Atomically adds @i to @v.
1445 +static inline void atomic_add(int i, atomic_t *v)
1447 + __asm__ __volatile__ (
1448 + "amoadd.w zero, %1, %0"
1449 + : "+A" (v->counter)
1454 + * atomic_sub - subtract integer from atomic variable
1455 + * @i: integer value to subtract
1456 + * @v: pointer of type atomic_t
1458 + * Atomically subtracts @i from @v.
1460 +static inline void atomic_sub(int i, atomic_t *v)
1462 + atomic_add(-i, v);
1466 + * atomic_add_return - add integer to atomic variable
1467 + * @i: integer value to add
1468 + * @v: pointer of type atomic_t
1470 + * Atomically adds @i to @v and returns the result
1472 +static inline int atomic_add_return(int i, atomic_t *v)
1475 + __asm__ __volatile__ (
1476 + "amoadd.w %0, %2, %1"
1477 + : "=r" (c), "+A" (v->counter)
1483 + * atomic_sub_return - subtract integer from atomic variable
1484 + * @i: integer value to subtract
1485 + * @v: pointer of type atomic_t
1487 + * Atomically subtracts @i from @v and returns the result
1489 +static inline int atomic_sub_return(int i, atomic_t *v)
1491 + return atomic_add_return(-i, v);
1495 + * atomic_inc - increment atomic variable
1496 + * @v: pointer of type atomic_t
1498 + * Atomically increments @v by 1.
1500 +static inline void atomic_inc(atomic_t *v)
1506 + * atomic_dec - decrement atomic variable
1507 + * @v: pointer of type atomic_t
1509 + * Atomically decrements @v by 1.
1511 +static inline void atomic_dec(atomic_t *v)
1513 + atomic_add(-1, v);
1516 +static inline int atomic_inc_return(atomic_t *v)
1518 + return atomic_add_return(1, v);
1521 +static inline int atomic_dec_return(atomic_t *v)
1523 + return atomic_sub_return(1, v);
1527 + * atomic_sub_and_test - subtract value from variable and test result
1528 + * @i: integer value to subtract
1529 + * @v: pointer of type atomic_t
1531 + * Atomically subtracts @i from @v and returns
1532 + * true if the result is zero, or false for all
1535 +static inline int atomic_sub_and_test(int i, atomic_t *v)
1537 + return (atomic_sub_return(i, v) == 0);
1541 + * atomic_inc_and_test - increment and test
1542 + * @v: pointer of type atomic_t
1544 + * Atomically increments @v by 1
1545 + * and returns true if the result is zero, or false for all
1548 +static inline int atomic_inc_and_test(atomic_t *v)
1550 + return (atomic_inc_return(v) == 0);
1554 + * atomic_dec_and_test - decrement and test
1555 + * @v: pointer of type atomic_t
1557 + * Atomically decrements @v by 1 and
1558 + * returns true if the result is 0, or false for all other
1561 +static inline int atomic_dec_and_test(atomic_t *v)
1563 + return (atomic_dec_return(v) == 0);
1567 + * atomic_add_negative - add and test if negative
1568 + * @i: integer value to add
1569 + * @v: pointer of type atomic_t
1571 + * Atomically adds @i to @v and returns true
1572 + * if the result is negative, or false when
1573 + * result is greater than or equal to zero.
1575 +static inline int atomic_add_negative(int i, atomic_t *v)
1577 + return (atomic_add_return(i, v) < 0);
1581 +static inline int atomic_xchg(atomic_t *v, int n)
1584 + __asm__ __volatile__ (
1585 + "amoswap.w %0, %2, %1"
1586 + : "=r" (c), "+A" (v->counter)
1591 +static inline int atomic_cmpxchg(atomic_t *v, int o, int n)
1593 + return cmpxchg(&(v->counter), o, n);
1597 + * __atomic_add_unless - add unless the number is already a given value
1598 + * @v: pointer of type atomic_t
1599 + * @a: the amount to add to v...
1600 + * @u: ...unless v is equal to u.
1602 + * Atomically adds @a to @v, so long as @v was not already @u.
1603 + * Returns the old value of @v.
1605 +static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1607 + register int prev, rc;
1608 + __asm__ __volatile__ (
1611 + "beq %0, %4, 1f\n"
1612 + "add %1, %0, %3\n"
1613 + "sc.w %1, %1, %2\n"
1616 + : "=&r" (prev), "=&r" (rc), "+A" (v->counter)
1617 + : "r" (a), "r" (u));
1622 + * atomic_and - Atomically clear bits in atomic variable
1623 + * @mask: Mask of the bits to be retained
1624 + * @v: pointer of type atomic_t
1626 + * Atomically retains the bits set in @mask from @v
1628 +static inline void atomic_and(unsigned int mask, atomic_t *v)
1630 + __asm__ __volatile__ (
1631 + "amoand.w zero, %1, %0"
1632 + : "+A" (v->counter)
1637 + * atomic_or - Atomically set bits in atomic variable
1638 + * @mask: Mask of the bits to be set
1639 + * @v: pointer of type atomic_t
1641 + * Atomically sets the bits set in @mask in @v
1643 +static inline void atomic_or(unsigned int mask, atomic_t *v)
1645 + __asm__ __volatile__ (
1646 + "amoor.w zero, %1, %0"
1647 + : "+A" (v->counter)
1652 + * atomic_xor - Atomically flips bits in atomic variable
1653 + * @mask: Mask of the bits to be flipped
1654 + * @v: pointer of type atomic_t
1656 + * Atomically flips the bits set in @mask in @v
1658 +static inline void atomic_xor(unsigned int mask, atomic_t *v)
1660 + __asm__ __volatile__ (
1661 + "amoxor.w zero, %1, %0"
1662 + : "+A" (v->counter)
1666 +/* Assume that atomic operations are already serializing */
1667 +#define smp_mb__before_atomic_dec() barrier()
1668 +#define smp_mb__after_atomic_dec() barrier()
1669 +#define smp_mb__before_atomic_inc() barrier()
1670 +#define smp_mb__after_atomic_inc() barrier()
1672 +#else /* !CONFIG_RV_ATOMIC */
1674 +#include <asm-generic/atomic.h>
1676 +#endif /* CONFIG_RV_ATOMIC */
1678 +#include <asm/atomic64.h>
1680 +#endif /* _ASM_RISCV_ATOMIC_H */
1681 diff -Nur linux-4.6.2/arch/riscv/include/asm/barrier.h linux-4.6.2.riscv/arch/riscv/include/asm/barrier.h
1682 --- linux-4.6.2/arch/riscv/include/asm/barrier.h 1970-01-01 01:00:00.000000000 +0100
1683 +++ linux-4.6.2.riscv/arch/riscv/include/asm/barrier.h 2017-03-04 02:48:34.166888015 +0100
1685 +#ifndef _ASM_RISCV_BARRIER_H
1686 +#define _ASM_RISCV_BARRIER_H
1688 +#ifndef __ASSEMBLY__
1690 +#define nop() __asm__ __volatile__ ("nop")
1692 +#define mb() __asm__ __volatile__ ("fence" : : : "memory")
1694 +#include <asm-generic/barrier.h>
1696 +#endif /* __ASSEMBLY__ */
1698 +#endif /* _ASM_RISCV_BARRIER_H */
1699 diff -Nur linux-4.6.2/arch/riscv/include/asm/bitops.h linux-4.6.2.riscv/arch/riscv/include/asm/bitops.h
1700 --- linux-4.6.2/arch/riscv/include/asm/bitops.h 1970-01-01 01:00:00.000000000 +0100
1701 +++ linux-4.6.2.riscv/arch/riscv/include/asm/bitops.h 2017-03-04 02:48:34.166888015 +0100
1703 +#ifndef _ASM_RISCV_BITOPS_H
1704 +#define _ASM_RISCV_BITOPS_H
1706 +#ifndef _LINUX_BITOPS_H
1707 +#error "Only <linux/bitops.h> can be included directly"
1708 +#endif /* _LINUX_BITOPS_H */
1712 +#include <linux/compiler.h>
1713 +#include <linux/irqflags.h>
1714 +#include <asm/barrier.h>
1715 +#include <asm/bitsperlong.h>
1717 +#ifdef CONFIG_RV_ATOMIC
1719 +#ifndef smp_mb__before_clear_bit
1720 +#define smp_mb__before_clear_bit() smp_mb()
1721 +#define smp_mb__after_clear_bit() smp_mb()
1722 +#endif /* smp_mb__before_clear_bit */
1725 + * __ffs - find first bit in word.
1726 + * @word: The word to search
1728 + * Undefined if no bit exists, so code should check against 0 first.
1731 +static __always_inline unsigned long __ffs(unsigned long word)
1736 +#include <asm-generic/bitops/__ffs.h>
1738 +#include <asm-generic/bitops/ffz.h>
1741 + * fls - find last (most-significant) bit set
1742 + * @x: the word to search
1744 + * This is defined the same way as ffs.
1745 + * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
1748 +static __always_inline int fls(int x)
1753 +#include <asm-generic/bitops/fls.h>
1756 + * __fls - find last (most-significant) set bit in a long word
1757 + * @word: the word to search
1759 + * Undefined if no set bit exists, so code should check against 0 first.
1762 +static __always_inline unsigned long __fls(unsigned long word)
1767 +#include <asm-generic/bitops/__fls.h>
1769 +#include <asm-generic/bitops/fls64.h>
1770 +#include <asm-generic/bitops/find.h>
1771 +#include <asm-generic/bitops/sched.h>
1774 + * ffs - find first bit set
1775 + * @x: the word to search
1777 + * This is defined the same way as
1778 + * the libc and compiler builtin ffs routines, therefore
1779 + * differs in spirit from the above ffz (man ffs).
1782 +static __always_inline int ffs(int x)
1787 +#include <asm-generic/bitops/ffs.h>
1789 +#include <asm-generic/bitops/hweight.h>
1791 +#if (BITS_PER_LONG == 64)
1792 +#define __AMO(op) "amo" #op ".d"
1793 +#elif (BITS_PER_LONG == 32)
1794 +#define __AMO(op) "amo" #op ".w"
1796 +#error "Unexpected BITS_PER_LONG"
1799 +#define __test_and_op_bit(op, mod, nr, addr) \
1801 + unsigned long __res, __mask; \
1802 + __mask = BIT_MASK(nr); \
1803 + __asm__ __volatile__ ( \
1804 + __AMO(op) " %0, %2, %1" \
1805 + : "=r" (__res), "+A" (addr[BIT_WORD(nr)]) \
1806 + : "r" (mod(__mask))); \
1807 + ((__res & __mask) != 0); \
1810 +#define __op_bit(op, mod, nr, addr) \
1811 + __asm__ __volatile__ ( \
1812 + __AMO(op) " zero, %1, %0" \
1813 + : "+A" (addr[BIT_WORD(nr)]) \
1814 + : "r" (mod(BIT_MASK(nr))))
1816 +/* Bitmask modifiers */
1817 +#define __NOP(x) (x)
1818 +#define __NOT(x) (~(x))
1821 + * test_and_set_bit - Set a bit and return its old value
1823 + * @addr: Address to count from
1825 + * This operation is atomic and cannot be reordered.
1826 + * It may be reordered on other architectures than x86.
1827 + * It also implies a memory barrier.
1829 +static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
1831 + return __test_and_op_bit(or, __NOP, nr, addr);
1835 + * test_and_clear_bit - Clear a bit and return its old value
1836 + * @nr: Bit to clear
1837 + * @addr: Address to count from
1839 + * This operation is atomic and cannot be reordered.
1840 + * It can be reordered on other architectures other than x86.
1841 + * It also implies a memory barrier.
1843 +static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
1845 + return __test_and_op_bit(and, __NOT, nr, addr);
1849 + * test_and_change_bit - Change a bit and return its old value
1850 + * @nr: Bit to change
1851 + * @addr: Address to count from
1853 + * This operation is atomic and cannot be reordered.
1854 + * It also implies a memory barrier.
1856 +static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
1858 + return __test_and_op_bit(xor, __NOP, nr, addr);
1862 + * set_bit - Atomically set a bit in memory
1863 + * @nr: the bit to set
1864 + * @addr: the address to start counting from
1866 + * This function is atomic and may not be reordered. See __set_bit()
1867 + * if you do not require the atomic guarantees.
1869 + * Note: there are no guarantees that this function will not be reordered
1870 + * on non x86 architectures, so if you are writing portable code,
1871 + * make sure not to rely on its reordering guarantees.
1873 + * Note that @nr may be almost arbitrarily large; this function is not
1874 + * restricted to acting on a single-word quantity.
1876 +static inline void set_bit(int nr, volatile unsigned long *addr)
1878 + __op_bit(or, __NOP, nr, addr);
1882 + * clear_bit - Clears a bit in memory
1883 + * @nr: Bit to clear
1884 + * @addr: Address to start counting from
1886 + * clear_bit() is atomic and may not be reordered. However, it does
1887 + * not contain a memory barrier, so if it is used for locking purposes,
1888 + * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
1889 + * in order to ensure changes are visible on other processors.
1891 +static inline void clear_bit(int nr, volatile unsigned long *addr)
1893 + __op_bit(and, __NOT, nr, addr);
1897 + * change_bit - Toggle a bit in memory
1898 + * @nr: Bit to change
1899 + * @addr: Address to start counting from
1901 + * change_bit() is atomic and may not be reordered. It may be
1902 + * reordered on other architectures than x86.
1903 + * Note that @nr may be almost arbitrarily large; this function is not
1904 + * restricted to acting on a single-word quantity.
1906 +static inline void change_bit(int nr, volatile unsigned long *addr)
1908 + __op_bit(xor, __NOP, nr, addr);
1912 + * test_and_set_bit_lock - Set a bit and return its old value, for lock
1914 + * @addr: Address to count from
1916 + * This operation is atomic and provides acquire barrier semantics.
1917 + * It can be used to implement bit locks.
1919 +static inline int test_and_set_bit_lock(
1920 + unsigned long nr, volatile unsigned long *addr)
1922 + return test_and_set_bit(nr, addr);
1926 + * clear_bit_unlock - Clear a bit in memory, for unlock
1927 + * @nr: the bit to set
1928 + * @addr: the address to start counting from
1930 + * This operation is atomic and provides release barrier semantics.
1932 +static inline void clear_bit_unlock(
1933 + unsigned long nr, volatile unsigned long *addr)
1935 + clear_bit(nr, addr);
1939 + * __clear_bit_unlock - Clear a bit in memory, for unlock
1940 + * @nr: the bit to set
1941 + * @addr: the address to start counting from
1943 + * This operation is like clear_bit_unlock, however it is not atomic.
1944 + * It does provide release barrier semantics so it can be used to unlock
1945 + * a bit lock, however it would only be used if no other CPU can modify
1946 + * any bits in the memory until the lock is released (a good example is
1947 + * if the bit lock itself protects access to the other bits in the word).
1949 +static inline void __clear_bit_unlock(
1950 + unsigned long nr, volatile unsigned long *addr)
1952 + clear_bit(nr, addr);
1955 +#undef __test_and_op_bit
1961 +#include <asm-generic/bitops/non-atomic.h>
1962 +#include <asm-generic/bitops/le.h>
1963 +#include <asm-generic/bitops/ext2-atomic.h>
1965 +#else /* !CONFIG_RV_ATOMIC */
1967 +#include <asm-generic/bitops.h>
1969 +#endif /* CONFIG_RV_ATOMIC */
1971 +#endif /* __KERNEL__ */
1973 +#endif /* _ASM_RISCV_BITOPS_H */
1974 diff -Nur linux-4.6.2/arch/riscv/include/asm/bug.h linux-4.6.2.riscv/arch/riscv/include/asm/bug.h
1975 --- linux-4.6.2/arch/riscv/include/asm/bug.h 1970-01-01 01:00:00.000000000 +0100
1976 +++ linux-4.6.2.riscv/arch/riscv/include/asm/bug.h 2017-03-04 02:48:34.166888015 +0100
1978 +#ifndef _ASM_RISCV_BUG_H
1979 +#define _ASM_RISCV_BUG_H
1981 +#include <linux/compiler.h>
1982 +#include <linux/const.h>
1983 +#include <linux/types.h>
1985 +#include <asm/asm.h>
1987 +#ifdef CONFIG_GENERIC_BUG
1988 +#define __BUG_INSN _AC(0x00100073,UL) /* sbreak */
1990 +#ifndef __ASSEMBLY__
1991 +typedef u32 bug_insn_t;
1993 +#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
1994 +#define __BUG_ENTRY_ADDR INT " 1b - 2b"
1995 +#define __BUG_ENTRY_FILE INT " %0 - 2b"
1997 +#define __BUG_ENTRY_ADDR PTR " 1b"
1998 +#define __BUG_ENTRY_FILE PTR " %0"
2001 +#ifdef CONFIG_DEBUG_BUGVERBOSE
2002 +#define __BUG_ENTRY \
2003 + __BUG_ENTRY_ADDR "\n\t" \
2004 + __BUG_ENTRY_FILE "\n\t" \
2007 +#define __BUG_ENTRY \
2013 + __asm__ __volatile__ ( \
2016 + ".pushsection __bug_table,\"a\"\n\t" \
2018 + __BUG_ENTRY "\n\t" \
2019 + ".org 2b + %2\n\t" \
2022 + : "i" (__FILE__), "i" (__LINE__), \
2023 + "i" (sizeof(struct bug_entry))); \
2027 +#define HAVE_ARCH_BUG
2028 +#endif /* !__ASSEMBLY__ */
2029 +#endif /* CONFIG_GENERIC_BUG */
2031 +#include <asm-generic/bug.h>
2033 +#ifndef __ASSEMBLY__
2036 +struct task_struct;
2038 +extern void die(struct pt_regs *regs, const char *str);
2039 +extern void do_trap(struct pt_regs *regs, int signo, int code,
2040 + unsigned long addr, struct task_struct *tsk);
2042 +#endif /* !__ASSEMBLY__ */
2044 +#endif /* _ASM_RISCV_BUG_H */
2045 diff -Nur linux-4.6.2/arch/riscv/include/asm/cacheflush.h linux-4.6.2.riscv/arch/riscv/include/asm/cacheflush.h
2046 --- linux-4.6.2/arch/riscv/include/asm/cacheflush.h 1970-01-01 01:00:00.000000000 +0100
2047 +++ linux-4.6.2.riscv/arch/riscv/include/asm/cacheflush.h 2017-03-04 02:48:34.166888015 +0100
2049 +#ifndef _ASM_RISCV_CACHEFLUSH_H
2050 +#define _ASM_RISCV_CACHEFLUSH_H
2052 +#include <asm-generic/cacheflush.h>
2054 +#undef flush_icache_range
2055 +#undef flush_icache_user_range
2057 +static inline void local_flush_icache_all(void)
2059 + asm volatile ("fence.i" ::: "memory");
2064 +#define flush_icache_range(start, end) local_flush_icache_all()
2065 +#define flush_icache_user_range(vma, pg, addr, len) local_flush_icache_all()
2067 +#else /* CONFIG_SMP */
2069 +#define flush_icache_range(start, end) sbi_remote_fence_i(0)
2070 +#define flush_icache_user_range(vma, pg, addr, len) sbi_remote_fence_i(0)
2072 +#endif /* CONFIG_SMP */
2074 +#endif /* _ASM_RISCV_CACHEFLUSH_H */
2075 diff -Nur linux-4.6.2/arch/riscv/include/asm/cache.h linux-4.6.2.riscv/arch/riscv/include/asm/cache.h
2076 --- linux-4.6.2/arch/riscv/include/asm/cache.h 1970-01-01 01:00:00.000000000 +0100
2077 +++ linux-4.6.2.riscv/arch/riscv/include/asm/cache.h 2017-03-04 02:48:34.166888015 +0100
2079 +#ifndef _ASM_RISCV_CACHE_H
2080 +#define _ASM_RISCV_CACHE_H
2082 +#if defined(CONFIG_CPU_RV_ROCKET)
2083 +#define L1_CACHE_SHIFT 6
2085 +#define L1_CACHE_SHIFT 5
2088 +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2090 +#endif /* _ASM_RISCV_CACHE_H */
2091 diff -Nur linux-4.6.2/arch/riscv/include/asm/cmpxchg.h linux-4.6.2.riscv/arch/riscv/include/asm/cmpxchg.h
2092 --- linux-4.6.2/arch/riscv/include/asm/cmpxchg.h 1970-01-01 01:00:00.000000000 +0100
2093 +++ linux-4.6.2.riscv/arch/riscv/include/asm/cmpxchg.h 2017-03-04 02:48:34.166888015 +0100
2095 +#ifndef _ASM_RISCV_CMPXCHG_H
2096 +#define _ASM_RISCV_CMPXCHG_H
2098 +#include <linux/bug.h>
2100 +#ifdef CONFIG_RV_ATOMIC
2102 +#include <asm/barrier.h>
2104 +#define __xchg(new, ptr, size) \
2106 + __typeof__(ptr) __ptr = (ptr); \
2107 + __typeof__(new) __new = (new); \
2108 + __typeof__(*(ptr)) __ret; \
2111 + __asm__ __volatile__ ( \
2112 + "amoswap.w %0, %2, %1" \
2113 + : "=r" (__ret), "+A" (*__ptr) \
2117 + __asm__ __volatile__ ( \
2118 + "amoswap.d %0, %2, %1" \
2119 + : "=r" (__ret), "+A" (*__ptr) \
2128 +#define xchg(ptr, x) (__xchg((x), (ptr), sizeof(*(ptr))))
2132 + * Atomic compare and exchange. Compare OLD with MEM, if identical,
2133 + * store NEW in MEM. Return the initial value in MEM. Success is
2134 + * indicated by comparing RETURN with OLD.
2136 +#define __cmpxchg(ptr, old, new, size) \
2138 + __typeof__(ptr) __ptr = (ptr); \
2139 + __typeof__(old) __old = (old); \
2140 + __typeof__(new) __new = (new); \
2141 + __typeof__(*(ptr)) __ret; \
2142 + register unsigned int __rc; \
2145 + __asm__ __volatile__ ( \
2148 + "bne %0, %z3, 1f\n" \
2149 + "sc.w %1, %z4, %2\n" \
2152 + : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
2153 + : "rJ" (__old), "rJ" (__new)); \
2156 + __asm__ __volatile__ ( \
2159 + "bne %0, %z3, 1f\n" \
2160 + "sc.d %1, %z4, %2\n" \
2163 + : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
2164 + : "rJ" (__old), "rJ" (__new)); \
2172 +#define __cmpxchg_mb(ptr, old, new, size) \
2174 + __typeof__(*(ptr)) __ret; \
2176 + __ret = __cmpxchg((ptr), (old), (new), (size)); \
2181 +#define cmpxchg(ptr, o, n) \
2182 + (__cmpxchg_mb((ptr), (o), (n), sizeof(*(ptr))))
2184 +#define cmpxchg_local(ptr, o, n) \
2185 + (__cmpxchg((ptr), (o), (n), sizeof(*(ptr))))
2187 +#define cmpxchg64(ptr, o, n) \
2189 + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
2190 + cmpxchg((ptr), (o), (n)); \
2193 +#define cmpxchg64_local(ptr, o, n) \
2195 + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
2196 + cmpxchg_local((ptr), (o), (n)); \
2199 +#else /* !CONFIG_RV_ATOMIC */
2201 +#include <asm-generic/cmpxchg.h>
2203 +#endif /* CONFIG_RV_ATOMIC */
2205 +#endif /* _ASM_RISCV_CMPXCHG_H */
2206 diff -Nur linux-4.6.2/arch/riscv/include/asm/csr.h linux-4.6.2.riscv/arch/riscv/include/asm/csr.h
2207 --- linux-4.6.2/arch/riscv/include/asm/csr.h 1970-01-01 01:00:00.000000000 +0100
2208 +++ linux-4.6.2.riscv/arch/riscv/include/asm/csr.h 2017-03-04 02:48:34.166888015 +0100
2210 +#ifndef _ASM_RISCV_CSR_H
2211 +#define _ASM_RISCV_CSR_H
2213 +#include <linux/const.h>
2215 +/* Status register flags */
2216 +#define SR_IE _AC(0x00000002,UL) /* Interrupt Enable */
2217 +#define SR_PIE _AC(0x00000020,UL) /* Previous IE */
2218 +#define SR_PS _AC(0x00000100,UL) /* Previously Supervisor */
2219 +#define SR_PUM _AC(0x00040000,UL) /* Protect User Memory */
2221 +#define SR_FS _AC(0x00006000,UL) /* Floating-point Status */
2222 +#define SR_FS_OFF _AC(0x00000000,UL)
2223 +#define SR_FS_INITIAL _AC(0x00002000,UL)
2224 +#define SR_FS_CLEAN _AC(0x00004000,UL)
2225 +#define SR_FS_DIRTY _AC(0x00006000,UL)
2227 +#define SR_XS _AC(0x00018000,UL) /* Extension Status */
2228 +#define SR_XS_OFF _AC(0x00000000,UL)
2229 +#define SR_XS_INITIAL _AC(0x00008000,UL)
2230 +#define SR_XS_CLEAN _AC(0x00010000,UL)
2231 +#define SR_XS_DIRTY _AC(0x00018000,UL)
2233 +#ifndef CONFIG_64BIT
2234 +#define SR_SD _AC(0x80000000,UL) /* FS/XS dirty */
2236 +#define SR_SD _AC(0x8000000000000000,UL) /* FS/XS dirty */
2239 +/* Interrupt Enable and Interrupt Pending flags */
2240 +#define SIE_SSIE _AC(0x00000002,UL) /* Software Interrupt Enable */
2241 +#define SIE_STIE _AC(0x00000020,UL) /* Timer Interrupt Enable */
2243 +#define EXC_INST_MISALIGNED 0
2244 +#define EXC_INST_ACCESS 1
2245 +#define EXC_BREAKPOINT 3
2246 +#define EXC_LOAD_ACCESS 5
2247 +#define EXC_STORE_ACCESS 7
2248 +#define EXC_SYSCALL 8
2250 +#ifndef __ASSEMBLY__
2252 +#define CSR_ZIMM(val) \
2253 + (__builtin_constant_p(val) && ((unsigned long)(val) < 0x20))
2255 +#define csr_swap(csr,val) \
2257 + unsigned long __v = (unsigned long)(val); \
2258 + if (CSR_ZIMM(__v)) { \
2259 + __asm__ __volatile__ ( \
2260 + "csrrw %0, " #csr ", %1" \
2261 + : "=r" (__v) : "i" (__v)); \
2263 + __asm__ __volatile__ ( \
2264 + "csrrw %0, " #csr ", %1" \
2265 + : "=r" (__v) : "r" (__v)); \
2270 +#define csr_read(csr) \
2272 + register unsigned long __v; \
2273 + __asm__ __volatile__ ( \
2274 + "csrr %0, " #csr : "=r" (__v)); \
2278 +#define csr_write(csr,val) \
2280 + unsigned long __v = (unsigned long)(val); \
2281 + if (CSR_ZIMM(__v)) { \
2282 + __asm__ __volatile__ ( \
2283 + "csrw " #csr ", %0" : : "i" (__v)); \
2285 + __asm__ __volatile__ ( \
2286 + "csrw " #csr ", %0" : : "r" (__v)); \
2290 +#define csr_read_set(csr,val) \
2292 + unsigned long __v = (unsigned long)(val); \
2293 + if (CSR_ZIMM(val)) { \
2294 + __asm__ __volatile__ ( \
2295 + "csrrs %0, " #csr ", %1" \
2296 + : "=r" (__v) : "i" (__v)); \
2298 + __asm__ __volatile__ ( \
2299 + "csrrs %0, " #csr ", %1" \
2300 + : "=r" (__v) : "r" (__v)); \
2305 +#define csr_set(csr,val) \
2307 + unsigned long __v = (unsigned long)(val); \
2308 + if (CSR_ZIMM(__v)) { \
2309 + __asm__ __volatile__ ( \
2310 + "csrs " #csr ", %0" : : "i" (__v)); \
2312 + __asm__ __volatile__ ( \
2313 + "csrs " #csr ", %0" : : "r" (__v)); \
2317 +#define csr_read_clear(csr,val) \
2319 + unsigned long __v = (unsigned long)(val); \
2320 + if (CSR_ZIMM(__v)) { \
2321 + __asm__ __volatile__ ( \
2322 + "csrrc %0, " #csr ", %1" \
2323 + : "=r" (__v) : "i" (__v)); \
2325 + __asm__ __volatile__ ( \
2326 + "csrrc %0, " #csr ", %1" \
2327 + : "=r" (__v) : "r" (__v)); \
2332 +#define csr_clear(csr,val) \
2334 + unsigned long __v = (unsigned long)(val); \
2335 + if (CSR_ZIMM(__v)) { \
2336 + __asm__ __volatile__ ( \
2337 + "csrc " #csr ", %0" : : "i" (__v)); \
2339 + __asm__ __volatile__ ( \
2340 + "csrc " #csr ", %0" : : "r" (__v)); \
2344 +#endif /* __ASSEMBLY__ */
2346 +#endif /* _ASM_RISCV_CSR_H */
2347 diff -Nur linux-4.6.2/arch/riscv/include/asm/current.h linux-4.6.2.riscv/arch/riscv/include/asm/current.h
2348 --- linux-4.6.2/arch/riscv/include/asm/current.h 1970-01-01 01:00:00.000000000 +0100
2349 +++ linux-4.6.2.riscv/arch/riscv/include/asm/current.h 2017-03-04 02:48:34.166888015 +0100
2351 +#ifndef _ASM_RISCV_CURRENT_H
2352 +#define _ASM_RISCV_CURRENT_H
2354 +#include <asm/csr.h>
2356 +struct task_struct;
2358 +static inline struct task_struct *get_current(void)
2360 + register struct task_struct * tp asm("tp");
2364 +#define current (get_current())
2366 +#endif /* _ASM_RISCV_CURRENT_H */
2367 diff -Nur linux-4.6.2/arch/riscv/include/asm/delay.h linux-4.6.2.riscv/arch/riscv/include/asm/delay.h
2368 --- linux-4.6.2/arch/riscv/include/asm/delay.h 1970-01-01 01:00:00.000000000 +0100
2369 +++ linux-4.6.2.riscv/arch/riscv/include/asm/delay.h 2017-03-04 02:48:34.166888015 +0100
2371 +#ifndef _ASM_RISCV_DELAY_H
2372 +#define _ASM_RISCV_DELAY_H
2374 +extern unsigned long timebase;
2376 +#define udelay udelay
2377 +extern void udelay(unsigned long usecs);
2379 +#define ndelay ndelay
2380 +extern void ndelay(unsigned long nsecs);
2382 +extern void __delay(unsigned long cycles);
2384 +#endif /* _ASM_RISCV_DELAY_H */
2385 diff -Nur linux-4.6.2/arch/riscv/include/asm/device.h linux-4.6.2.riscv/arch/riscv/include/asm/device.h
2386 --- linux-4.6.2/arch/riscv/include/asm/device.h 1970-01-01 01:00:00.000000000 +0100
2387 +++ linux-4.6.2.riscv/arch/riscv/include/asm/device.h 2017-03-04 02:48:34.166888015 +0100
2389 +#ifndef _ASM_RISCV_DEVICE_H
2390 +#define _ASM_RISCV_DEVICE_H
2392 +#include <linux/sysfs.h>
2394 +struct dev_archdata {
2395 + struct dma_map_ops *dma_ops;
2398 +struct pdev_archdata {
2401 +#endif /* _ASM_RISCV_DEVICE_H */
2402 diff -Nur linux-4.6.2/arch/riscv/include/asm/dma-mapping.h linux-4.6.2.riscv/arch/riscv/include/asm/dma-mapping.h
2403 --- linux-4.6.2/arch/riscv/include/asm/dma-mapping.h 1970-01-01 01:00:00.000000000 +0100
2404 +++ linux-4.6.2.riscv/arch/riscv/include/asm/dma-mapping.h 2017-03-04 02:48:34.166888015 +0100
2407 + * Copyright (C) 2003-2004 Hewlett-Packard Co
2408 + * David Mosberger-Tang <davidm@hpl.hp.com>
2409 + * Copyright (C) 2012 ARM Ltd.
2410 + * Copyright (C) 2016 SiFive, Inc.
2412 + * This program is free software; you can redistribute it and/or modify
2413 + * it under the terms of the GNU General Public License version 2 as
2414 + * published by the Free Software Foundation.
2416 + * This program is distributed in the hope that it will be useful,
2417 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2418 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2419 + * GNU General Public License for more details.
2421 + * You should have received a copy of the GNU General Public License
2422 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2424 +#ifndef __ASM_RISCV_DMA_MAPPING_H
2425 +#define __ASM_RISCV_DMA_MAPPING_H
2429 +/* Use ops->dma_mapping_error (if it exists) or assume success */
2430 +// #undef DMA_ERROR_CODE
2432 +static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2434 + if (unlikely(dev->archdata.dma_ops))
2435 + return dev->archdata.dma_ops;
2437 + return &dma_noop_ops;
2440 +static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
2442 + if (!dev->dma_mask)
2445 + return addr + size - 1 <= *dev->dma_mask;
2448 +static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
2450 + return (dma_addr_t)paddr;
2453 +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
2455 + return (phys_addr_t)dev_addr;
2458 +static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, enum dma_data_direction dir)
2461 + * RISC-V is cache-coherent, so this is mostly a no-op. However, we do need to
2462 + * ensure that dma_cache_sync() enforces order, hence the mb().
2467 +#endif /* __KERNEL__ */
2468 +#endif /* __ASM_RISCV_DMA_MAPPING_H */
2469 diff -Nur linux-4.6.2/arch/riscv/include/asm/elf.h linux-4.6.2.riscv/arch/riscv/include/asm/elf.h
2470 --- linux-4.6.2/arch/riscv/include/asm/elf.h 1970-01-01 01:00:00.000000000 +0100
2471 +++ linux-4.6.2.riscv/arch/riscv/include/asm/elf.h 2017-03-04 02:48:34.166888015 +0100
2473 +#ifndef _ASM_RISCV_ELF_H
2474 +#define _ASM_RISCV_ELF_H
2476 +#include <uapi/asm/elf.h>
2477 +#include <asm/auxvec.h>
2478 +#include <asm/byteorder.h>
2480 +/* TODO: Move definition into include/uapi/linux/elf-em.h */
2481 +#define EM_RISCV 0xF3
2484 + * These are used to set parameters in the core dumps.
2486 +#define ELF_ARCH EM_RISCV
2488 +#ifdef CONFIG_64BIT
2489 +#define ELF_CLASS ELFCLASS64
2491 +#define ELF_CLASS ELFCLASS32
2494 +#if defined(__LITTLE_ENDIAN)
2495 +#define ELF_DATA ELFDATA2LSB
2496 +#elif defined(__BIG_ENDIAN)
2497 +#define ELF_DATA ELFDATA2MSB
2499 +#error "Unknown endianness"
2503 + * This is used to ensure we don't load something for the wrong architecture.
2505 +#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
2507 +#define CORE_DUMP_USE_REGSET
2508 +#define ELF_EXEC_PAGESIZE (PAGE_SIZE)
2511 + * This is the location that an ET_DYN program is loaded if exec'ed. Typical
2512 + * use of this is to invoke "./ld.so someprog" to test out a new version of
2513 + * the loader. We need to make sure that it is out of the way of the program
2514 + * that it will "exec", and that there is sufficient room for the brk.
2516 +#define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2)
2519 + * This yields a mask that user programs can use to figure out what
2520 + * instruction set this CPU supports. This could be done in user space,
2521 + * but it's not easy, and we've already done it here.
2523 +#define ELF_HWCAP (0)
2526 + * This yields a string that ld.so will use to load implementation
2527 + * specific libraries for optimization. This is more specific in
2528 + * intent than poking at uname or /proc/cpuinfo.
2530 +#define ELF_PLATFORM (NULL)
2532 +#define ARCH_DLINFO \
2534 + NEW_AUX_ENT(AT_SYSINFO_EHDR, \
2535 + (elf_addr_t)current->mm->context.vdso); \
2539 +#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
2540 +struct linux_binprm;
2541 +extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2544 +#endif /* _ASM_RISCV_ELF_H */
2545 diff -Nur linux-4.6.2/arch/riscv/include/asm/io.h linux-4.6.2.riscv/arch/riscv/include/asm/io.h
2546 --- linux-4.6.2/arch/riscv/include/asm/io.h 1970-01-01 01:00:00.000000000 +0100
2547 +++ linux-4.6.2.riscv/arch/riscv/include/asm/io.h 2017-03-04 02:48:34.166888015 +0100
2549 +#ifndef _ASM_RISCV_IO_H
2550 +#define _ASM_RISCV_IO_H
2552 +#include <asm-generic/io.h>
2558 +extern void __iomem *ioremap(phys_addr_t offset, unsigned long size);
2561 + * ioremap_nocache - map bus memory into CPU space
2562 + * @offset: bus address of the memory
2563 + * @size: size of the resource to map
2565 + * ioremap_nocache performs a platform specific sequence of operations to
2566 + * make bus memory CPU accessible via the readb/readw/readl/writeb/
2567 + * writew/writel functions and the other mmio helpers. The returned
2568 + * address is not guaranteed to be usable directly as a virtual
2571 + * This version of ioremap ensures that the memory is marked uncachable
2572 + * on the CPU as well as honouring existing caching rules from things like
2573 + * the PCI bus. Note that there are other caches and buffers on many
2574 + * busses. In particular driver authors should read up on PCI writes.
2576 + * It's useful if some control registers are in such an area and
2577 + * write combining or read caching is not desirable.
2579 + * Must be freed with iounmap.
2581 +static inline void __iomem *ioremap_nocache(
2582 + phys_addr_t offset, unsigned long size)
2584 + return ioremap(offset, size);
2588 + * ioremap_wc - map memory into CPU space write combined
2589 + * @offset: bus address of the memory
2590 + * @size: size of the resource to map
2592 + * This version of ioremap ensures that the memory is marked write combining.
2593 + * Write combining allows faster writes to some hardware devices.
2595 + * Must be freed with iounmap.
2597 +static inline void __iomem *ioremap_wc(
2598 + phys_addr_t offset, unsigned long size)
2600 + return ioremap(offset, size);
2603 +#define ioremap_wt ioremap_nocache
2605 +extern void iounmap(void __iomem *addr);
2607 +#endif /* CONFIG_MMU */
2609 +#endif /* __KERNEL__ */
2611 +#endif /* _ASM_RISCV_IO_H */
2612 diff -Nur linux-4.6.2/arch/riscv/include/asm/irqflags.h linux-4.6.2.riscv/arch/riscv/include/asm/irqflags.h
2613 --- linux-4.6.2/arch/riscv/include/asm/irqflags.h 1970-01-01 01:00:00.000000000 +0100
2614 +++ linux-4.6.2.riscv/arch/riscv/include/asm/irqflags.h 2017-03-04 02:48:34.166888015 +0100
2616 +#ifndef _ASM_RISCV_IRQFLAGS_H
2617 +#define _ASM_RISCV_IRQFLAGS_H
2619 +#include <asm/processor.h>
2620 +#include <asm/csr.h>
2622 +/* read interrupt enabled status */
2623 +static inline unsigned long arch_local_save_flags(void)
2625 + return csr_read(sstatus);
2628 +/* unconditionally enable interrupts */
2629 +static inline void arch_local_irq_enable(void)
2631 + csr_set(sstatus, SR_IE);
2634 +/* unconditionally disable interrupts */
2635 +static inline void arch_local_irq_disable(void)
2637 + csr_clear(sstatus, SR_IE);
2640 +/* get status and disable interrupts */
2641 +static inline unsigned long arch_local_irq_save(void)
2643 + return csr_read_clear(sstatus, SR_IE);
2647 +static inline int arch_irqs_disabled_flags(unsigned long flags)
2649 + return !(flags & SR_IE);
2652 +/* test hardware interrupt enable bit */
2653 +static inline int arch_irqs_disabled(void)
2655 + return arch_irqs_disabled_flags(arch_local_save_flags());
2658 +/* set interrupt enabled status */
2659 +static inline void arch_local_irq_restore(unsigned long flags)
2661 + csr_set(sstatus, flags & SR_IE);
2664 +#endif /* _ASM_RISCV_IRQFLAGS_H */
2665 diff -Nur linux-4.6.2/arch/riscv/include/asm/irq.h linux-4.6.2.riscv/arch/riscv/include/asm/irq.h
2666 --- linux-4.6.2/arch/riscv/include/asm/irq.h 1970-01-01 01:00:00.000000000 +0100
2667 +++ linux-4.6.2.riscv/arch/riscv/include/asm/irq.h 2017-03-04 02:48:34.166888015 +0100
2669 +#ifndef _ASM_RISCV_IRQ_H
2670 +#define _ASM_RISCV_IRQ_H
2674 +#define INTERRUPT_CAUSE_SOFTWARE 1
2675 +#define INTERRUPT_CAUSE_TIMER 5
2676 +#define INTERRUPT_CAUSE_EXTERNAL 9
2678 +void riscv_timer_interrupt(void);
2680 +#include <asm-generic/irq.h>
2682 +#endif /* _ASM_RISCV_IRQ_H */
2683 diff -Nur linux-4.6.2/arch/riscv/include/asm/Kbuild linux-4.6.2.riscv/arch/riscv/include/asm/Kbuild
2684 --- linux-4.6.2/arch/riscv/include/asm/Kbuild 1970-01-01 01:00:00.000000000 +0100
2685 +++ linux-4.6.2.riscv/arch/riscv/include/asm/Kbuild 2017-03-04 02:48:34.162887952 +0100
2687 +generic-y += bugs.h
2688 +generic-y += cacheflush.h
2689 +generic-y += checksum.h
2690 +generic-y += clkdev.h
2691 +generic-y += cputime.h
2692 +generic-y += div64.h
2694 +generic-y += emergency-restart.h
2695 +generic-y += errno.h
2696 +generic-y += exec.h
2698 +generic-y += fcntl.h
2699 +generic-y += ftrace.h
2700 +generic-y += futex.h
2701 +generic-y += hardirq.h
2702 +generic-y += hash.h
2703 +generic-y += hw_irq.h
2704 +generic-y += ioctl.h
2705 +generic-y += ioctls.h
2706 +generic-y += ipcbuf.h
2707 +generic-y += irq_regs.h
2708 +generic-y += irq_work.h
2709 +generic-y += kdebug.h
2710 +generic-y += kmap_types.h
2711 +generic-y += kvm_para.h
2712 +generic-y += local.h
2713 +generic-y += mm-arch-hooks.h
2714 +generic-y += mman.h
2715 +generic-y += module.h
2716 +generic-y += msgbuf.h
2717 +generic-y += mutex.h
2718 +generic-y += param.h
2719 +generic-y += percpu.h
2720 +generic-y += poll.h
2721 +generic-y += posix_types.h
2722 +generic-y += preempt.h
2723 +generic-y += resource.h
2724 +generic-y += scatterlist.h
2725 +generic-y += sections.h
2726 +generic-y += sembuf.h
2727 +generic-y += shmbuf.h
2728 +generic-y += shmparam.h
2729 +generic-y += signal.h
2730 +generic-y += socket.h
2731 +generic-y += sockios.h
2732 +generic-y += stat.h
2733 +generic-y += statfs.h
2734 +generic-y += swab.h
2735 +generic-y += termbits.h
2736 +generic-y += termios.h
2737 +generic-y += topology.h
2738 +generic-y += trace_clock.h
2739 +generic-y += types.h
2740 +generic-y += ucontext.h
2741 +generic-y += unaligned.h
2742 +generic-y += user.h
2744 +generic-y += vmlinux.lds.h
2746 diff -Nur linux-4.6.2/arch/riscv/include/asm/linkage.h linux-4.6.2.riscv/arch/riscv/include/asm/linkage.h
2747 --- linux-4.6.2/arch/riscv/include/asm/linkage.h 1970-01-01 01:00:00.000000000 +0100
2748 +++ linux-4.6.2.riscv/arch/riscv/include/asm/linkage.h 2017-03-04 02:48:34.166888015 +0100
2750 +#ifndef _ASM_RISCV_LINKAGE_H
2751 +#define _ASM_RISCV_LINKAGE_H
2753 +#define __ALIGN .balign 4
2754 +#define __ALIGN_STR ".balign 4"
2756 +#endif /* _ASM_RISCV_LINKAGE_H */
2757 diff -Nur linux-4.6.2/arch/riscv/include/asm/mmu_context.h linux-4.6.2.riscv/arch/riscv/include/asm/mmu_context.h
2758 --- linux-4.6.2/arch/riscv/include/asm/mmu_context.h 1970-01-01 01:00:00.000000000 +0100
2759 +++ linux-4.6.2.riscv/arch/riscv/include/asm/mmu_context.h 2017-03-04 02:48:34.166888015 +0100
2761 +#ifndef _ASM_RISCV_MMU_CONTEXT_H
2762 +#define _ASM_RISCV_MMU_CONTEXT_H
2764 +#include <asm-generic/mm_hooks.h>
2766 +#include <linux/mm.h>
2767 +#include <linux/sched.h>
2768 +#include <asm/tlbflush.h>
2770 +static inline void enter_lazy_tlb(struct mm_struct *mm,
2771 + struct task_struct *task)
2775 +/* Initialize context-related info for a new mm_struct */
2776 +static inline int init_new_context(struct task_struct *task,
2777 + struct mm_struct *mm)
2782 +static inline void destroy_context(struct mm_struct *mm)
2786 +static inline void switch_mm(struct mm_struct *prev,
2787 + struct mm_struct *next, struct task_struct *task)
2789 + if (likely(prev != next)) {
2790 + csr_write(sptbr, virt_to_pfn(next->pgd));
2791 + local_flush_tlb_all();
2795 +static inline void activate_mm(struct mm_struct *prev,
2796 + struct mm_struct *next)
2798 + switch_mm(prev, next, NULL);
2801 +static inline void deactivate_mm(struct task_struct *task,
2802 + struct mm_struct *mm)
2806 +#endif /* _ASM_RISCV_MMU_CONTEXT_H */
2807 diff -Nur linux-4.6.2/arch/riscv/include/asm/mmu.h linux-4.6.2.riscv/arch/riscv/include/asm/mmu.h
2808 --- linux-4.6.2/arch/riscv/include/asm/mmu.h 1970-01-01 01:00:00.000000000 +0100
2809 +++ linux-4.6.2.riscv/arch/riscv/include/asm/mmu.h 2017-03-04 02:48:34.166888015 +0100
2811 +#ifndef _ASM_RISCV_MMU_H
2812 +#define _ASM_RISCV_MMU_H
2814 +#ifndef __ASSEMBLY__
2820 +#endif /* __ASSEMBLY__ */
2822 +#endif /* _ASM_RISCV_MMU_H */
2823 diff -Nur linux-4.6.2/arch/riscv/include/asm/page.h linux-4.6.2.riscv/arch/riscv/include/asm/page.h
2824 --- linux-4.6.2/arch/riscv/include/asm/page.h 1970-01-01 01:00:00.000000000 +0100
2825 +++ linux-4.6.2.riscv/arch/riscv/include/asm/page.h 2017-03-04 02:48:34.166888015 +0100
2827 +#ifndef _ASM_RISCV_PAGE_H
2828 +#define _ASM_RISCV_PAGE_H
2830 +#include <linux/pfn.h>
2831 +#include <linux/const.h>
2833 +#define PAGE_SHIFT (12)
2834 +#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
2835 +#define PAGE_MASK (~(PAGE_SIZE - 1))
2840 + * PAGE_OFFSET -- the first address of the first page of memory.
2841 + * When not using MMU this corresponds to the first free page in
2842 + * physical memory (aligned on a page boundary).
2844 +#ifdef CONFIG_64BIT
2845 +#define PAGE_OFFSET _AC(0xffffffff80000000,UL)
2847 +#define PAGE_OFFSET _AC(0xc0000000,UL)
2850 +#ifndef __ASSEMBLY__
2852 +#define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
2853 +#define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1)))
2855 +/* align addr on a size boundary - adjust address up/down if needed */
2856 +#define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1)))
2857 +#define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
2859 +/* align addr on a size boundary - adjust address up if needed */
2860 +#define _ALIGN(addr, size) _ALIGN_UP(addr, size)
2862 +#define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE)
2863 +#define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
2865 +#define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE)
2866 +#define copy_user_page(vto, vfrom, vaddr, topg) \
2867 + memcpy((vto), (vfrom), PAGE_SIZE)
2870 + * Use struct definitions to apply C type checking
2873 +/* Page Global Directory entry */
2875 + unsigned long pgd;
2878 +/* Page Table entry */
2880 + unsigned long pte;
2884 + unsigned long pgprot;
2887 +typedef struct page *pgtable_t;
2889 +#define pte_val(x) ((x).pte)
2890 +#define pgd_val(x) ((x).pgd)
2891 +#define pgprot_val(x) ((x).pgprot)
2893 +#define __pte(x) ((pte_t) { (x) })
2894 +#define __pgd(x) ((pgd_t) { (x) })
2895 +#define __pgprot(x) ((pgprot_t) { (x) })
2897 +#ifdef CONFIG_64BITS
2898 +#define PTE_FMT "%016lx"
2900 +#define PTE_FMT "%08lx"
2903 +extern unsigned long va_pa_offset;
2904 +extern unsigned long pfn_base;
2906 +extern unsigned long max_low_pfn;
2907 +extern unsigned long min_low_pfn;
2909 +#define __pa(x) ((unsigned long)(x) - va_pa_offset)
2910 +#define __va(x) ((void *)((unsigned long) (x) + va_pa_offset))
2912 +#define phys_to_pfn(phys) (PFN_DOWN(phys))
2913 +#define pfn_to_phys(pfn) (PFN_PHYS(pfn))
2915 +#define virt_to_pfn(vaddr) (phys_to_pfn(__pa(vaddr)))
2916 +#define pfn_to_virt(pfn) (__va(pfn_to_phys(pfn)))
2918 +#define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr)))
2919 +#define page_to_virt(page) (pfn_to_virt(page_to_pfn(page)))
2921 +#define page_to_phys(page) (pfn_to_phys(page_to_pfn(page)))
2922 +#define page_to_bus(page) (page_to_phys(page))
2923 +#define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr)))
2925 +#define pfn_valid(pfn) (((pfn) >= pfn_base) && (((pfn)-pfn_base) < max_mapnr))
2927 +#define ARCH_PFN_OFFSET (pfn_base)
2929 +#endif /* __ASSEMBLY__ */
2931 +#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))
2933 +#endif /* __KERNEL__ */
2935 +#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
2936 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2938 +#include <asm-generic/memory_model.h>
2939 +#include <asm-generic/getorder.h>
2942 +/* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */
2943 +#define __HAVE_ARCH_GATE_AREA
2945 +#endif /* _ASM_RISCV_PAGE_H */
2946 diff -Nur linux-4.6.2/arch/riscv/include/asm/pci.h linux-4.6.2.riscv/arch/riscv/include/asm/pci.h
2947 --- linux-4.6.2/arch/riscv/include/asm/pci.h 1970-01-01 01:00:00.000000000 +0100
2948 +++ linux-4.6.2.riscv/arch/riscv/include/asm/pci.h 2017-03-04 02:48:34.166888015 +0100
2950 +#ifndef __ASM_RISCV_PCI_H
2951 +#define __ASM_RISCV_PCI_H
2954 +#include <linux/types.h>
2955 +#include <linux/slab.h>
2956 +#include <linux/dma-mapping.h>
2958 +#include <asm/io.h>
2960 +#define PCIBIOS_MIN_IO 0x1000
2961 +#define PCIBIOS_MIN_MEM 0
2963 +/* RISC-V shim does not initialize PCI bus */
2964 +#define pcibios_assign_all_busses() 1
2966 +/* RISC-V TileLink and PCIe share the share address space */
2967 +#define PCI_DMA_BUS_IS_PHYS 1
2969 +extern int isa_dma_bridge_buggy;
2972 +static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
2974 + /* no legacy IRQ on risc-v */
2978 +static inline int pci_proc_domain(struct pci_bus *bus)
2980 + /* always show the domain in /proc */
2983 +#endif /* CONFIG_PCI */
2985 +#endif /* __KERNEL__ */
2986 +#endif /* __ASM_PCI_H */
2987 diff -Nur linux-4.6.2/arch/riscv/include/asm/pgalloc.h linux-4.6.2.riscv/arch/riscv/include/asm/pgalloc.h
2988 --- linux-4.6.2/arch/riscv/include/asm/pgalloc.h 1970-01-01 01:00:00.000000000 +0100
2989 +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgalloc.h 2017-03-04 02:48:34.166888015 +0100
2991 +#ifndef _ASM_RISCV_PGALLOC_H
2992 +#define _ASM_RISCV_PGALLOC_H
2994 +#include <linux/mm.h>
2995 +#include <asm/tlb.h>
2997 +static inline void pmd_populate_kernel(struct mm_struct *mm,
2998 + pmd_t *pmd, pte_t *pte)
3000 + unsigned long pfn = virt_to_pfn(pte);
3001 + set_pmd(pmd, __pmd((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE));
3004 +static inline void pmd_populate(struct mm_struct *mm,
3005 + pmd_t *pmd, pgtable_t pte)
3007 + unsigned long pfn = virt_to_pfn(page_address(pte));
3008 + set_pmd(pmd, __pmd((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE));
3011 +#ifndef __PAGETABLE_PMD_FOLDED
3012 +static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3014 + unsigned long pfn = virt_to_pfn(pmd);
3015 + set_pud(pud, __pud((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE));
3017 +#endif /* __PAGETABLE_PMD_FOLDED */
3019 +#define pmd_pgtable(pmd) pmd_page(pmd)
3021 +static inline pgd_t *pgd_alloc(struct mm_struct *mm)
3025 + pgd = (pgd_t *)__get_free_page(GFP_KERNEL);
3026 + if (likely(pgd != NULL)) {
3027 + memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
3028 + /* Copy kernel mappings */
3029 + memcpy(pgd + USER_PTRS_PER_PGD,
3030 + init_mm.pgd + USER_PTRS_PER_PGD,
3031 + (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
3036 +static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3038 + free_page((unsigned long)pgd);
3041 +#ifndef __PAGETABLE_PMD_FOLDED
3043 +static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3045 + return (pmd_t *)__get_free_page(
3046 + GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
3049 +static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3051 + free_page((unsigned long)pmd);
3054 +#define __pmd_free_tlb(tlb, pmd, addr) pmd_free((tlb)->mm, pmd)
3056 +#endif /* __PAGETABLE_PMD_FOLDED */
3058 +static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
3059 + unsigned long address)
3061 + return (pte_t *)__get_free_page(
3062 + GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
3065 +static inline struct page *pte_alloc_one(struct mm_struct *mm,
3066 + unsigned long address)
3069 + pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
3070 + if (likely(pte != NULL)) {
3071 + pgtable_page_ctor(pte);
3076 +static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
3078 + free_page((unsigned long)pte);
3081 +static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
3083 + pgtable_page_dtor(pte);
3087 +#define __pte_free_tlb(tlb, pte, buf) \
3089 + pgtable_page_dtor(pte); \
3090 + tlb_remove_page((tlb), pte); \
3093 +static inline void check_pgt_cache(void)
3097 +#endif /* _ASM_RISCV_PGALLOC_H */
3098 diff -Nur linux-4.6.2/arch/riscv/include/asm/pgtable-32.h linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-32.h
3099 --- linux-4.6.2/arch/riscv/include/asm/pgtable-32.h 1970-01-01 01:00:00.000000000 +0100
3100 +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-32.h 2017-03-04 02:48:34.166888015 +0100
3102 +#ifndef _ASM_RISCV_PGTABLE_32_H
3103 +#define _ASM_RISCV_PGTABLE_32_H
3105 +#include <asm-generic/pgtable-nopmd.h>
3106 +#include <linux/const.h>
3108 +/* Size of region mapped by a page global directory */
3109 +#define PGDIR_SHIFT 22
3110 +#define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
3111 +#define PGDIR_MASK (~(PGDIR_SIZE - 1))
3113 +#endif /* _ASM_RISCV_PGTABLE_32_H */
3114 diff -Nur linux-4.6.2/arch/riscv/include/asm/pgtable-64.h linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-64.h
3115 --- linux-4.6.2/arch/riscv/include/asm/pgtable-64.h 1970-01-01 01:00:00.000000000 +0100
3116 +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-64.h 2017-03-04 02:48:34.166888015 +0100
3118 +#ifndef _ASM_RISCV_PGTABLE_64_H
3119 +#define _ASM_RISCV_PGTABLE_64_H
3121 +#include <linux/const.h>
3123 +#define PGDIR_SHIFT 30
3124 +/* Size of region mapped by a page global directory */
3125 +#define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
3126 +#define PGDIR_MASK (~(PGDIR_SIZE - 1))
3128 +#define PMD_SHIFT 21
3129 +/* Size of region mapped by a page middle directory */
3130 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
3131 +#define PMD_MASK (~(PMD_SIZE - 1))
3133 +/* Page Middle Directory entry */
3135 + unsigned long pmd;
3138 +#define pmd_val(x) ((x).pmd)
3139 +#define __pmd(x) ((pmd_t) { (x) })
3141 +#define PTRS_PER_PMD (PAGE_SIZE / sizeof(pmd_t))
3143 +static inline int pud_present(pud_t pud)
3145 + return (pud_val(pud) & _PAGE_PRESENT);
3148 +static inline int pud_none(pud_t pud)
3150 + return (pud_val(pud) == 0);
3153 +static inline int pud_bad(pud_t pud)
3155 + return !pud_present(pud);
3158 +static inline void set_pud(pud_t *pudp, pud_t pud)
3163 +static inline void pud_clear(pud_t *pudp)
3165 + set_pud(pudp, __pud(0));
3168 +static inline unsigned long pud_page_vaddr(pud_t pud)
3170 + return (unsigned long)pfn_to_virt(pud_val(pud) >> _PAGE_PFN_SHIFT);
3173 +#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
3175 +static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)
3177 + return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(addr);
3180 +#define pmd_ERROR(e) \
3181 + pr_err("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
3183 +#endif /* _ASM_RISCV_PGTABLE_64_H */
3184 diff -Nur linux-4.6.2/arch/riscv/include/asm/pgtable-bits.h linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-bits.h
3185 --- linux-4.6.2/arch/riscv/include/asm/pgtable-bits.h 1970-01-01 01:00:00.000000000 +0100
3186 +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-bits.h 2017-03-04 02:48:34.166888015 +0100
3188 +#ifndef _ASM_RISCV_PGTABLE_BITS_H
3189 +#define _ASM_RISCV_PGTABLE_BITS_H
3192 + * RV32Sv32 page table entry:
3193 + * | 31 10 | 9 7 | 6 | 5 | 4 1 | 0
3194 + * PFN reserved for SW D R TYPE V
3196 + * RV64Sv39 / RV64Sv48 page table entry:
3197 + * | 63 48 | 47 10 | 9 7 | 6 | 5 | 4 1 | 0
3198 + * reserved for HW PFN reserved for SW D R TYPE V
3201 +#define _PAGE_PRESENT (1 << 0)
3202 +#define _PAGE_READ (1 << 1) /* Readable */
3203 +#define _PAGE_WRITE (1 << 2) /* Writable */
3204 +#define _PAGE_EXEC (1 << 3) /* Executable */
3205 +#define _PAGE_USER (1 << 4) /* User */
3206 +#define _PAGE_GLOBAL (1 << 5) /* Global */
3207 +#define _PAGE_ACCESSED (1 << 6) /* Set by hardware on any access */
3208 +#define _PAGE_DIRTY (1 << 7) /* Set by hardware on any write */
3209 +#define _PAGE_SOFT (1 << 8) /* Reserved for software */
3211 +#define _PAGE_SPECIAL _PAGE_SOFT
3212 +#define _PAGE_TABLE _PAGE_PRESENT
3214 +#define _PAGE_PFN_SHIFT 10
3216 +/* Set of bits to preserve across pte_modify() */
3217 +#define _PAGE_CHG_MASK (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ | \
3218 + _PAGE_WRITE | _PAGE_EXEC | \
3219 + _PAGE_USER | _PAGE_GLOBAL))
3221 +/* Advertise support for _PAGE_SPECIAL */
3222 +#define __HAVE_ARCH_PTE_SPECIAL
3224 +#endif /* _ASM_RISCV_PGTABLE_BITS_H */
3225 diff -Nur linux-4.6.2/arch/riscv/include/asm/pgtable.h linux-4.6.2.riscv/arch/riscv/include/asm/pgtable.h
3226 --- linux-4.6.2/arch/riscv/include/asm/pgtable.h 1970-01-01 01:00:00.000000000 +0100
3227 +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgtable.h 2017-03-04 02:48:34.166888015 +0100
3229 +#ifndef _ASM_RISCV_PGTABLE_H
3230 +#define _ASM_RISCV_PGTABLE_H
3232 +#include <linux/mmzone.h>
3234 +#include <asm/pgtable-bits.h>
3236 +#ifndef __ASSEMBLY__
3240 +/* Page Upper Directory not used in RISC-V */
3241 +#include <asm-generic/pgtable-nopud.h>
3242 +#include <asm/page.h>
3243 +#include <linux/mm_types.h>
3245 +#ifdef CONFIG_64BIT
3246 +#include <asm/pgtable-64.h>
3248 +#include <asm/pgtable-32.h>
3249 +#endif /* CONFIG_64BIT */
3251 +/* Number of entries in the page global directory */
3252 +#define PTRS_PER_PGD (PAGE_SIZE / sizeof(pgd_t))
3253 +/* Number of entries in the page table */
3254 +#define PTRS_PER_PTE (PAGE_SIZE / sizeof(pte_t))
3256 +/* Number of PGD entries that a user-mode program can use */
3257 +#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
3258 +#define FIRST_USER_ADDRESS 0
3260 +/* Page protection bits */
3261 +#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_USER)
3263 +#define PAGE_NONE __pgprot(0)
3264 +#define PAGE_READ __pgprot(_PAGE_BASE | _PAGE_READ)
3265 +#define PAGE_WRITE __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_WRITE)
3266 +#define PAGE_EXEC __pgprot(_PAGE_BASE | _PAGE_EXEC)
3267 +#define PAGE_READ_EXEC __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_EXEC)
3268 +#define PAGE_WRITE_EXEC __pgprot(_PAGE_BASE | _PAGE_READ | \
3269 + _PAGE_EXEC | _PAGE_WRITE)
3271 +#define PAGE_COPY PAGE_READ
3272 +#define PAGE_COPY_EXEC PAGE_EXEC
3273 +#define PAGE_COPY_READ_EXEC PAGE_READ_EXEC
3274 +#define PAGE_SHARED PAGE_WRITE
3275 +#define PAGE_SHARED_EXEC PAGE_WRITE_EXEC
3277 +#define PAGE_KERNEL __pgprot(_PAGE_READ | _PAGE_WRITE | \
3278 + _PAGE_PRESENT | _PAGE_ACCESSED)
3280 +#define swapper_pg_dir NULL
3282 +/* MAP_PRIVATE permissions: xwr (copy-on-write) */
3283 +#define __P000 PAGE_NONE
3284 +#define __P001 PAGE_READ
3285 +#define __P010 PAGE_COPY
3286 +#define __P011 PAGE_COPY
3287 +#define __P100 PAGE_EXEC
3288 +#define __P101 PAGE_READ_EXEC
3289 +#define __P110 PAGE_COPY_EXEC
3290 +#define __P111 PAGE_COPY_READ_EXEC
3292 +/* MAP_SHARED permissions: xwr */
3293 +#define __S000 PAGE_NONE
3294 +#define __S001 PAGE_READ
3295 +#define __S010 PAGE_SHARED
3296 +#define __S011 PAGE_SHARED
3297 +#define __S100 PAGE_EXEC
3298 +#define __S101 PAGE_READ_EXEC
3299 +#define __S110 PAGE_SHARED_EXEC
3300 +#define __S111 PAGE_SHARED_EXEC
3303 + * ZERO_PAGE is a global shared page that is always zero,
3304 + * used for zero-mapped memory areas, etc.
3306 +extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
3307 +#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
3309 +static inline int pmd_present(pmd_t pmd)
3311 + return (pmd_val(pmd) & _PAGE_PRESENT);
3314 +static inline int pmd_none(pmd_t pmd)
3316 + return (pmd_val(pmd) == 0);
3319 +static inline int pmd_bad(pmd_t pmd)
3321 + return !pmd_present(pmd);
3324 +static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
3329 +static inline void pmd_clear(pmd_t *pmdp)
3331 + set_pmd(pmdp, __pmd(0));
3335 +#define pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
3337 +/* Locate an entry in the page global directory */
3338 +static inline pgd_t *pgd_offset(const struct mm_struct *mm, unsigned long addr)
3340 + return mm->pgd + pgd_index(addr);
3342 +/* Locate an entry in the kernel page global directory */
3343 +#define pgd_offset_k(addr) pgd_offset(&init_mm, (addr))
3345 +static inline struct page *pmd_page(pmd_t pmd)
3347 + return pfn_to_page(pmd_val(pmd) >> _PAGE_PFN_SHIFT);
3350 +static inline unsigned long pmd_page_vaddr(pmd_t pmd)
3352 + return (unsigned long)pfn_to_virt(pmd_val(pmd) >> _PAGE_PFN_SHIFT);
3355 +/* Yields the page frame number (PFN) of a page table entry */
3356 +static inline unsigned long pte_pfn(pte_t pte)
3358 + return (pte_val(pte) >> _PAGE_PFN_SHIFT);
3361 +#define pte_page(x) pfn_to_page(pte_pfn(x))
3363 +/* Constructs a page table entry */
3364 +static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
3366 + return __pte((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot));
3369 +static inline pte_t mk_pte(struct page *page, pgprot_t prot)
3371 + return pfn_pte(page_to_pfn(page), prot);
3374 +#define pte_index(addr) (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
3376 +static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long addr)
3378 + return (pte_t *)pmd_page_vaddr(*pmd) + pte_index(addr);
3381 +#define pte_offset_map(dir, addr) pte_offset_kernel((dir), (addr))
3382 +#define pte_unmap(pte) ((void)(pte))
3385 + * Certain architectures need to do special things when PTEs within
3386 + * a page table are directly modified. Thus, the following hook is
3389 +static inline void set_pte(pte_t *ptep, pte_t pteval)
3394 +static inline void set_pte_at(struct mm_struct *mm,
3395 + unsigned long addr, pte_t *ptep, pte_t pteval)
3397 + set_pte(ptep, pteval);
3400 +static inline void pte_clear(struct mm_struct *mm,
3401 + unsigned long addr, pte_t *ptep)
3403 + set_pte_at(mm, addr, ptep, __pte(0));
3406 +static inline int pte_present(pte_t pte)
3408 + return (pte_val(pte) & _PAGE_PRESENT);
3411 +static inline int pte_none(pte_t pte)
3413 + return (pte_val(pte) == 0);
3416 +/* static inline int pte_read(pte_t pte) */
3418 +static inline int pte_write(pte_t pte)
3420 + return pte_val(pte) & _PAGE_WRITE;
3423 +static inline int pte_huge(pte_t pte)
3425 + return pte_present(pte)
3426 + && (pte_val(pte) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC));
3429 +/* static inline int pte_exec(pte_t pte) */
3431 +static inline int pte_dirty(pte_t pte)
3433 + return pte_val(pte) & _PAGE_DIRTY;
3436 +static inline int pte_young(pte_t pte)
3438 + return pte_val(pte) & _PAGE_ACCESSED;
3441 +static inline int pte_special(pte_t pte)
3443 + return pte_val(pte) & _PAGE_SPECIAL;
3446 +/* static inline pte_t pte_rdprotect(pte_t pte) */
3448 +static inline pte_t pte_wrprotect(pte_t pte)
3450 + return __pte(pte_val(pte) & ~(_PAGE_WRITE));
3453 +/* static inline pte_t pte_mkread(pte_t pte) */
3455 +static inline pte_t pte_mkwrite(pte_t pte)
3457 + return __pte(pte_val(pte) | _PAGE_WRITE);
3460 +/* static inline pte_t pte_mkexec(pte_t pte) */
3462 +static inline pte_t pte_mkdirty(pte_t pte)
3464 + return __pte(pte_val(pte) | _PAGE_DIRTY);
3467 +static inline pte_t pte_mkclean(pte_t pte)
3469 + return __pte(pte_val(pte) & ~(_PAGE_DIRTY));
3472 +static inline pte_t pte_mkyoung(pte_t pte)
3474 + return __pte(pte_val(pte) & ~(_PAGE_ACCESSED));
3477 +static inline pte_t pte_mkold(pte_t pte)
3479 + return __pte(pte_val(pte) | _PAGE_ACCESSED);
3482 +static inline pte_t pte_mkspecial(pte_t pte)
3484 + return __pte(pte_val(pte) | _PAGE_SPECIAL);
3487 +/* Modify page protection bits */
3488 +static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
3490 + return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
3493 +#define pgd_ERROR(e) \
3494 + pr_err("%s:%d: bad pgd " PTE_FMT ".\n", __FILE__, __LINE__, pgd_val(e))
3497 +/* Commit new configuration to MMU hardware */
3498 +static inline void update_mmu_cache(struct vm_area_struct *vma,
3499 + unsigned long address, pte_t *ptep)
3504 + * Encode and decode a swap entry
3506 + * Format of swap PTE:
3507 + * bit 0: _PAGE_PRESENT (zero)
3508 + * bit 1: reserved for future use (zero)
3509 + * bits 2 to 6: swap type
3510 + * bits 7 to XLEN-1: swap offset
3512 +#define __SWP_TYPE_SHIFT 2
3513 +#define __SWP_TYPE_BITS 5
3514 +#define __SWP_TYPE_MASK ((1UL << __SWP_TYPE_BITS) - 1)
3515 +#define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)
3517 +#define MAX_SWAPFILES_CHECK() \
3518 + BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS)
3520 +#define __swp_type(x) (((x).val >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK)
3521 +#define __swp_offset(x) ((x).val >> __SWP_OFFSET_SHIFT)
3522 +#define __swp_entry(type, offset) ((swp_entry_t) \
3523 + { ((type) << __SWP_TYPE_SHIFT) | ((offset) << __SWP_OFFSET_SHIFT) })
3525 +#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
3526 +#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
3528 +#ifdef CONFIG_FLATMEM
3529 +#define kern_addr_valid(addr) (1) /* FIXME */
3532 +extern void paging_init(void);
3534 +static inline void pgtable_cache_init(void)
3536 + /* No page table caches to initialize */
3539 +#endif /* CONFIG_MMU */
3541 +#define VMALLOC_SIZE _AC(0x8000000,UL)
3542 +#define VMALLOC_END (PAGE_OFFSET - 1)
3543 +#define VMALLOC_START (PAGE_OFFSET - VMALLOC_SIZE)
3545 +/* Task size is 0x40000000000 for RV64 or 0xb800000 for RV32.
3546 + Note that PGDIR_SIZE must evenly divide TASK_SIZE. */
3547 +#ifdef CONFIG_64BIT
3548 +#define TASK_SIZE (PGDIR_SIZE * PTRS_PER_PGD / 2)
3550 +#define TASK_SIZE VMALLOC_START
3553 +#include <asm-generic/pgtable.h>
3555 +#endif /* !__ASSEMBLY__ */
3557 +#endif /* _ASM_RISCV_PGTABLE_H */
3558 diff -Nur linux-4.6.2/arch/riscv/include/asm/processor.h linux-4.6.2.riscv/arch/riscv/include/asm/processor.h
3559 --- linux-4.6.2/arch/riscv/include/asm/processor.h 1970-01-01 01:00:00.000000000 +0100
3560 +++ linux-4.6.2.riscv/arch/riscv/include/asm/processor.h 2017-03-04 02:48:34.166888015 +0100
3562 +#ifndef _ASM_RISCV_PROCESSOR_H
3563 +#define _ASM_RISCV_PROCESSOR_H
3565 +#include <linux/const.h>
3567 +#include <asm/ptrace.h>
3570 + * This decides where the kernel will search for a free chunk of vm
3571 + * space during mmap's.
3573 +#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE >> 1)
3576 +#define STACK_TOP TASK_SIZE
3577 +#define STACK_TOP_MAX STACK_TOP
3578 +#endif /* __KERNEL__ */
3580 +#ifndef __ASSEMBLY__
3582 +struct task_struct;
3586 + * Default implementation of macro that returns current
3587 + * instruction pointer ("program counter").
3589 +#define current_text_addr() ({ __label__ _l; _l: &&_l;})
3591 +/* CPU-specific state of a task */
3592 +struct thread_struct {
3593 + /* Callee-saved registers */
3595 + unsigned long sp; /* Kernel mode stack */
3596 + unsigned long s[12]; /* s[0]: frame pointer */
3597 + struct user_fpregs_struct fstate;
3600 +#define INIT_THREAD { \
3601 + .sp = sizeof(init_stack) + (long)&init_stack, \
3604 +/* Return saved (kernel) PC of a blocked thread. */
3605 +#define thread_saved_pc(t) ((t)->thread.ra)
3606 +#define thread_saved_sp(t) ((t)->thread.sp)
3607 +#define thread_saved_fp(t) ((t)->thread.s[0])
3609 +#define task_pt_regs(tsk) \
3610 + ((struct pt_regs *)(task_stack_page(tsk) + THREAD_SIZE) - 1)
3612 +#define KSTK_EIP(tsk) (task_pt_regs(tsk)->sepc)
3613 +#define KSTK_ESP(tsk) (task_pt_regs(tsk)->sp)
3616 +/* Do necessary setup to start up a newly executed thread. */
3617 +extern void start_thread(struct pt_regs *regs,
3618 + unsigned long pc, unsigned long sp);
3620 +/* Free all resources held by a thread. */
3621 +static inline void release_thread(struct task_struct *dead_task)
3625 +/* Free current thread data structures, etc. */
3626 +static inline void exit_thread(void)
3630 +extern unsigned long get_wchan(struct task_struct *p);
3633 +static inline void cpu_relax(void)
3636 + /* In lieu of a halt instruction, induce a long-latency stall. */
3637 + __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy));
3641 +static inline void wait_for_interrupt(void)
3643 + __asm__ __volatile__ ("wfi");
3646 +#endif /* __ASSEMBLY__ */
3648 +#endif /* _ASM_RISCV_PROCESSOR_H */
3649 diff -Nur linux-4.6.2/arch/riscv/include/asm/ptrace.h linux-4.6.2.riscv/arch/riscv/include/asm/ptrace.h
3650 --- linux-4.6.2/arch/riscv/include/asm/ptrace.h 1970-01-01 01:00:00.000000000 +0100
3651 +++ linux-4.6.2.riscv/arch/riscv/include/asm/ptrace.h 2017-03-04 02:48:34.166888015 +0100
3653 +#ifndef _ASM_RISCV_PTRACE_H
3654 +#define _ASM_RISCV_PTRACE_H
3656 +#include <uapi/asm/ptrace.h>
3657 +#include <asm/csr.h>
3659 +#ifndef __ASSEMBLY__
3662 + unsigned long sepc;
3688 + unsigned long s10;
3689 + unsigned long s11;
3694 + /* Supervisor CSRs */
3695 + unsigned long sstatus;
3696 + unsigned long sbadaddr;
3697 + unsigned long scause;
3700 +#ifdef CONFIG_64BIT
3701 +#define REG_FMT "%016lx"
3703 +#define REG_FMT "%08lx"
3706 +#define user_mode(regs) (((regs)->sstatus & SR_PS) == 0)
3709 +/* Helpers for working with the instruction pointer */
3710 +#define GET_IP(regs) ((regs)->sepc)
3711 +#define SET_IP(regs, val) (GET_IP(regs) = (val))
3713 +static inline unsigned long instruction_pointer(struct pt_regs *regs)
3715 + return GET_IP(regs);
3717 +static inline void instruction_pointer_set(struct pt_regs *regs,
3718 + unsigned long val)
3720 + SET_IP(regs, val);
3723 +#define profile_pc(regs) instruction_pointer(regs)
3725 +/* Helpers for working with the user stack pointer */
3726 +#define GET_USP(regs) ((regs)->sp)
3727 +#define SET_USP(regs, val) (GET_USP(regs) = (val))
3729 +static inline unsigned long user_stack_pointer(struct pt_regs *regs)
3731 + return GET_USP(regs);
3733 +static inline void user_stack_pointer_set(struct pt_regs *regs,
3734 + unsigned long val)
3736 + SET_USP(regs, val);
3739 +/* Helpers for working with the frame pointer */
3740 +#define GET_FP(regs) ((regs)->s0)
3741 +#define SET_FP(regs, val) (GET_FP(regs) = (val))
3743 +static inline unsigned long frame_pointer(struct pt_regs *regs)
3745 + return GET_FP(regs);
3747 +static inline void frame_pointer_set(struct pt_regs *regs,
3748 + unsigned long val)
3750 + SET_FP(regs, val);
3753 +#endif /* __ASSEMBLY__ */
3755 +#endif /* _ASM_RISCV_PTRACE_H */
3756 diff -Nur linux-4.6.2/arch/riscv/include/asm/sbi-con.h linux-4.6.2.riscv/arch/riscv/include/asm/sbi-con.h
3757 --- linux-4.6.2/arch/riscv/include/asm/sbi-con.h 1970-01-01 01:00:00.000000000 +0100
3758 +++ linux-4.6.2.riscv/arch/riscv/include/asm/sbi-con.h 2017-03-04 02:48:34.166888015 +0100
3760 +#ifndef _ASM_RISCV_SBI_CON_H
3761 +#define _ASM_RISCV_SBI_CON_H
3763 +#include <linux/irqreturn.h>
3765 +irqreturn_t sbi_console_isr(void);
3767 +#endif /* _ASM_RISCV_SBI_CON_H */
3768 diff -Nur linux-4.6.2/arch/riscv/include/asm/sbi.h linux-4.6.2.riscv/arch/riscv/include/asm/sbi.h
3769 --- linux-4.6.2/arch/riscv/include/asm/sbi.h 1970-01-01 01:00:00.000000000 +0100
3770 +++ linux-4.6.2.riscv/arch/riscv/include/asm/sbi.h 2017-03-04 02:48:34.166888015 +0100
3772 +#ifndef _ASM_RISCV_SBI_H
3773 +#define _ASM_RISCV_SBI_H
3776 + unsigned long base;
3777 + unsigned long size;
3778 + unsigned long node_id;
3779 +} memory_block_info;
3781 +unsigned long sbi_query_memory(unsigned long id, memory_block_info *p);
3783 +unsigned long sbi_hart_id(void);
3784 +unsigned long sbi_num_harts(void);
3785 +unsigned long sbi_timebase(void);
3786 +void sbi_set_timer(unsigned long long stime_value);
3787 +void sbi_send_ipi(unsigned long hart_id);
3788 +unsigned long sbi_clear_ipi(void);
3789 +void sbi_shutdown(void);
3791 +void sbi_console_putchar(unsigned char ch);
3792 +int sbi_console_getchar(void);
3794 +void sbi_remote_sfence_vm(unsigned long hart_mask_ptr, unsigned long asid);
3795 +void sbi_remote_sfence_vm_range(unsigned long hart_mask_ptr, unsigned long asid, unsigned long start, unsigned long size);
3796 +void sbi_remote_fence_i(unsigned long hart_mask_ptr);
3798 +unsigned long sbi_mask_interrupt(unsigned long which);
3799 +unsigned long sbi_unmask_interrupt(unsigned long which);
3802 diff -Nur linux-4.6.2/arch/riscv/include/asm/serial.h linux-4.6.2.riscv/arch/riscv/include/asm/serial.h
3803 --- linux-4.6.2/arch/riscv/include/asm/serial.h 1970-01-01 01:00:00.000000000 +0100
3804 +++ linux-4.6.2.riscv/arch/riscv/include/asm/serial.h 2017-03-04 02:48:34.166888015 +0100
3806 +#ifndef _ASM_RISCV_SERIAL_H
3807 +#define _ASM_RISCV_SERIAL_H
3810 + * FIXME: interim serial support for riscv-qemu
3812 + * Currently requires that the emulator itself create a hole at addresses
3813 + * 0x3f8 - 0x3ff without looking through page tables.
3815 + * This assumes you have a 1.8432 MHz clock for your UART.
3817 +#define BASE_BAUD ( 1843200 / 16 )
3819 +/* Standard COM flags */
3820 +#ifdef CONFIG_SERIAL_DETECT_IRQ
3821 +#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ)
3823 +#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
3826 +#define SERIAL_PORT_DFNS \
3828 + .baud_base = BASE_BAUD, \
3831 + .flags = STD_COM_FLAGS, \
3834 +#endif /* _ASM_RISCV_SERIAL_H */
3835 diff -Nur linux-4.6.2/arch/riscv/include/asm/setup.h linux-4.6.2.riscv/arch/riscv/include/asm/setup.h
3836 --- linux-4.6.2/arch/riscv/include/asm/setup.h 1970-01-01 01:00:00.000000000 +0100
3837 +++ linux-4.6.2.riscv/arch/riscv/include/asm/setup.h 2017-03-04 02:48:34.166888015 +0100
3839 +#ifndef _ASM_RISCV_SETUP_H
3840 +#define _ASM_RISCV_SETUP_H
3842 +#include <asm-generic/setup.h>
3844 +#endif /* _ASM_RISCV_SETUP_H */
3845 diff -Nur linux-4.6.2/arch/riscv/include/asm/smp.h linux-4.6.2.riscv/arch/riscv/include/asm/smp.h
3846 --- linux-4.6.2/arch/riscv/include/asm/smp.h 1970-01-01 01:00:00.000000000 +0100
3847 +++ linux-4.6.2.riscv/arch/riscv/include/asm/smp.h 2017-03-04 02:48:34.166888015 +0100
3849 +#ifndef _ASM_RISCV_SMP_H
3850 +#define _ASM_RISCV_SMP_H
3852 +#include <linux/cpumask.h>
3853 +#include <linux/irqreturn.h>
3857 +/* SMP initialization hook for setup_arch */
3858 +void __init init_clockevent(void);
3860 +/* SMP initialization hook for setup_arch */
3861 +void __init setup_smp(void);
3863 +/* Hook for the generic smp_call_function_many() routine. */
3864 +void arch_send_call_function_ipi_mask(struct cpumask *mask);
3866 +/* Hook for the generic smp_call_function_single() routine. */
3867 +void arch_send_call_function_single_ipi(int cpu);
3869 +#define raw_smp_processor_id() (current_thread_info()->cpu)
3871 +/* Interprocessor interrupt handler */
3872 +irqreturn_t handle_ipi(void);
3874 +#endif /* CONFIG_SMP */
3876 +#endif /* _ASM_RISCV_SMP_H */
3877 diff -Nur linux-4.6.2/arch/riscv/include/asm/spinlock.h linux-4.6.2.riscv/arch/riscv/include/asm/spinlock.h
3878 --- linux-4.6.2/arch/riscv/include/asm/spinlock.h 1970-01-01 01:00:00.000000000 +0100
3879 +++ linux-4.6.2.riscv/arch/riscv/include/asm/spinlock.h 2017-03-04 02:48:34.166888015 +0100
3881 +#ifndef _ASM_RISCV_SPINLOCK_H
3882 +#define _ASM_RISCV_SPINLOCK_H
3884 +#include <linux/kernel.h>
3885 +#include <asm/current.h>
3888 + * Simple spin lock operations. These provide no fairness guarantees.
3891 +#define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
3892 +#define arch_spin_is_locked(x) ((x)->lock != 0)
3893 +#define arch_spin_unlock_wait(x) \
3894 + do { cpu_relax(); } while ((x)->lock)
3896 +static inline void arch_spin_unlock(arch_spinlock_t *lock)
3898 + __asm__ __volatile__ (
3899 + "amoswap.w.rl x0, x0, %0"
3900 + : "=A" (lock->lock)
3904 +static inline int arch_spin_trylock(arch_spinlock_t *lock)
3906 + int tmp = 1, busy;
3908 + __asm__ __volatile__ (
3909 + "amoswap.w.aq %0, %2, %1"
3910 + : "=r" (busy), "+A" (lock->lock)
3917 +static inline void arch_spin_lock(arch_spinlock_t *lock)
3920 + if (arch_spin_is_locked(lock))
3923 + if (arch_spin_trylock(lock))
3928 +/***********************************************************/
3930 +static inline int arch_read_can_lock(arch_rwlock_t *lock)
3932 + return lock->lock >= 0;
3935 +static inline int arch_write_can_lock(arch_rwlock_t *lock)
3937 + return lock->lock == 0;
3940 +static inline void arch_read_lock(arch_rwlock_t *lock)
3944 + __asm__ __volatile__(
3945 + "1: lr.w %1, %0\n"
3947 + " addi %1, %1, 1\n"
3948 + " sc.w.aq %1, %1, %0\n"
3950 + : "+A" (lock->lock), "=&r" (tmp)
3954 +static inline void arch_write_lock(arch_rwlock_t *lock)
3958 + __asm__ __volatile__(
3959 + "1: lr.w %1, %0\n"
3962 + " sc.w.aq %1, %1, %0\n"
3964 + : "+A" (lock->lock), "=&r" (tmp)
3968 +static inline int arch_read_trylock(arch_rwlock_t * lock)
3972 + __asm__ __volatile__(
3973 + "1: lr.w %1, %0\n"
3975 + " addi %1, %1, 1\n"
3976 + " sc.w.aq %1, %1, %0\n"
3979 + : "+A" (lock->lock), "=&r" (busy)
3985 +static inline int arch_write_trylock(arch_rwlock_t * lock)
3989 + __asm__ __volatile__(
3990 + "1: lr.w %1, %0\n"
3993 + " sc.w.aq %1, %1, %0\n"
3996 + : "+A" (lock->lock), "=&r" (busy)
4002 +static inline void arch_read_unlock(arch_rwlock_t * lock)
4004 + __asm__ __volatile__(
4005 + "amoadd.w.rl x0, %1, %0"
4006 + : "+A" (lock->lock)
4011 +static inline void arch_write_unlock(arch_rwlock_t * lock)
4013 + __asm__ __volatile__ (
4014 + "amoswap.w.rl x0, x0, %0"
4015 + : "=A" (lock->lock)
4019 +#define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
4020 +#define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
4022 +#endif /* _ASM_RISCV_SPINLOCK_H */
4023 diff -Nur linux-4.6.2/arch/riscv/include/asm/spinlock_types.h linux-4.6.2.riscv/arch/riscv/include/asm/spinlock_types.h
4024 --- linux-4.6.2/arch/riscv/include/asm/spinlock_types.h 1970-01-01 01:00:00.000000000 +0100
4025 +++ linux-4.6.2.riscv/arch/riscv/include/asm/spinlock_types.h 2017-03-04 02:48:34.166888015 +0100
4027 +#ifndef _ASM_RISCV_SPINLOCK_TYPES_H
4028 +#define _ASM_RISCV_SPINLOCK_TYPES_H
4030 +#ifndef __LINUX_SPINLOCK_TYPES_H
4031 +# error "please don't include this file directly"
4035 + volatile unsigned int lock;
4038 +#define __ARCH_SPIN_LOCK_UNLOCKED { 0 }
4041 + volatile unsigned int lock;
4044 +#define __ARCH_RW_LOCK_UNLOCKED { 0 }
4047 diff -Nur linux-4.6.2/arch/riscv/include/asm/string.h linux-4.6.2.riscv/arch/riscv/include/asm/string.h
4048 --- linux-4.6.2/arch/riscv/include/asm/string.h 1970-01-01 01:00:00.000000000 +0100
4049 +++ linux-4.6.2.riscv/arch/riscv/include/asm/string.h 2017-03-04 02:48:34.166888015 +0100
4051 +#ifndef _ASM_RISCV_STRING_H
4052 +#define _ASM_RISCV_STRING_H
4056 +#include <linux/types.h>
4057 +#include <linux/linkage.h>
4059 +#define __HAVE_ARCH_MEMSET
4060 +extern asmlinkage void *memset(void *, int, size_t);
4062 +#define __HAVE_ARCH_MEMCPY
4063 +extern asmlinkage void *memcpy(void *, const void *, size_t);
4065 +#endif /* __KERNEL__ */
4067 +#endif /* _ASM_RISCV_STRING_H */
4068 diff -Nur linux-4.6.2/arch/riscv/include/asm/switch_to.h linux-4.6.2.riscv/arch/riscv/include/asm/switch_to.h
4069 --- linux-4.6.2/arch/riscv/include/asm/switch_to.h 1970-01-01 01:00:00.000000000 +0100
4070 +++ linux-4.6.2.riscv/arch/riscv/include/asm/switch_to.h 2017-03-04 02:48:34.166888015 +0100
4072 +#ifndef _ASM_RISCV_SWITCH_TO_H
4073 +#define _ASM_RISCV_SWITCH_TO_H
4075 +#include <asm/processor.h>
4076 +#include <asm/ptrace.h>
4077 +#include <asm/csr.h>
4079 +extern void __fstate_save(struct task_struct *);
4080 +extern void __fstate_restore(struct task_struct *);
4082 +static inline void __fstate_clean(struct pt_regs *regs)
4084 + regs->sstatus |= (regs->sstatus & ~(SR_FS)) | SR_FS_CLEAN;
4087 +static inline void fstate_save(struct task_struct *task,
4088 + struct pt_regs *regs)
4090 + if ((regs->sstatus & SR_FS) == SR_FS_DIRTY) {
4091 + __fstate_save(task);
4092 + __fstate_clean(regs);
4096 +static inline void fstate_restore(struct task_struct *task,
4097 + struct pt_regs *regs)
4099 + if ((regs->sstatus & SR_FS) != SR_FS_OFF) {
4100 + __fstate_restore(task);
4101 + __fstate_clean(regs);
4105 +static inline void __switch_to_aux(struct task_struct *prev,
4106 + struct task_struct *next)
4108 + struct pt_regs *regs;
4110 + regs = task_pt_regs(prev);
4111 + if (unlikely(regs->sstatus & SR_SD)) {
4112 + fstate_save(prev, regs);
4114 + fstate_restore(next, task_pt_regs(next));
4117 +extern struct task_struct *__switch_to(struct task_struct *,
4118 + struct task_struct *);
4120 +#define switch_to(prev, next, last) \
4122 + struct task_struct *__prev = (prev); \
4123 + struct task_struct *__next = (next); \
4124 + __switch_to_aux(__prev, __next); \
4125 + ((last) = __switch_to(__prev, __next)); \
4128 +#endif /* _ASM_RISCV_SWITCH_TO_H */
4129 diff -Nur linux-4.6.2/arch/riscv/include/asm/syscall.h linux-4.6.2.riscv/arch/riscv/include/asm/syscall.h
4130 --- linux-4.6.2/arch/riscv/include/asm/syscall.h 1970-01-01 01:00:00.000000000 +0100
4131 +++ linux-4.6.2.riscv/arch/riscv/include/asm/syscall.h 2017-03-04 02:48:34.166888015 +0100
4134 + * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
4135 + * Copyright 2010 Tilera Corporation. All Rights Reserved.
4136 + * Copyright 2015 Regents of the University of California, Berkeley
4138 + * This program is free software; you can redistribute it and/or
4139 + * modify it under the terms of the GNU General Public License
4140 + * as published by the Free Software Foundation, version 2.
4142 + * This program is distributed in the hope that it will be useful, but
4143 + * WITHOUT ANY WARRANTY; without even the implied warranty of
4144 + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
4145 + * NON INFRINGEMENT. See the GNU General Public License for
4148 + * See asm-generic/syscall.h for descriptions of what we must do here.
4151 +#ifndef _ASM_RISCV_SYSCALL_H
4152 +#define _ASM_RISCV_SYSCALL_H
4154 +#include <linux/sched.h>
4155 +#include <linux/err.h>
4157 +/* The array of function pointers for syscalls. */
4158 +extern void *sys_call_table[];
4161 + * Only the low 32 bits of orig_r0 are meaningful, so we return int.
4162 + * This importantly ignores the high bits on 64-bit, so comparisons
4163 + * sign-extend the low 32 bits.
4165 +static inline int syscall_get_nr(struct task_struct *task,
4166 + struct pt_regs *regs)
4171 +static inline void syscall_set_nr(struct task_struct *task,
4172 + struct pt_regs *regs,
4178 +static inline void syscall_rollback(struct task_struct *task,
4179 + struct pt_regs *regs)
4181 + /* FIXME: We can't do this... */
4184 +static inline long syscall_get_error(struct task_struct *task,
4185 + struct pt_regs *regs)
4187 + unsigned long error = regs->a0;
4188 + return IS_ERR_VALUE(error) ? error : 0;
4191 +static inline long syscall_get_return_value(struct task_struct *task,
4192 + struct pt_regs *regs)
4197 +static inline void syscall_set_return_value(struct task_struct *task,
4198 + struct pt_regs *regs,
4199 + int error, long val)
4201 + regs->a0 = (long) error ?: val;
4204 +static inline void syscall_get_arguments(struct task_struct *task,
4205 + struct pt_regs *regs,
4206 + unsigned int i, unsigned int n,
4207 + unsigned long *args)
4209 + BUG_ON(i + n > 6);
4210 + memcpy(args, ®s->a0 + i * sizeof(regs->a0), n * sizeof(args[0]));
4213 +static inline void syscall_set_arguments(struct task_struct *task,
4214 + struct pt_regs *regs,
4215 + unsigned int i, unsigned int n,
4216 + const unsigned long *args)
4218 + BUG_ON(i + n > 6);
4219 + memcpy(®s->a0 + i * sizeof(regs->a0), args, n * sizeof(regs->a0));
4222 +#endif /* _ASM_TILE_SYSCALL_H */
4223 diff -Nur linux-4.6.2/arch/riscv/include/asm/syscalls.h linux-4.6.2.riscv/arch/riscv/include/asm/syscalls.h
4224 --- linux-4.6.2/arch/riscv/include/asm/syscalls.h 1970-01-01 01:00:00.000000000 +0100
4225 +++ linux-4.6.2.riscv/arch/riscv/include/asm/syscalls.h 2017-03-04 02:48:34.166888015 +0100
4227 +#ifndef _ASM_RISCV_SYSCALLS_H
4228 +#define _ASM_RISCV_SYSCALLS_H
4230 +#include <linux/linkage.h>
4232 +#include <asm-generic/syscalls.h>
4234 +/* kernel/sys_riscv.c */
4235 +asmlinkage long sys_sysriscv(unsigned long, unsigned long,
4236 + unsigned long, unsigned long);
4238 +#endif /* _ASM_RISCV_SYSCALLS_H */
4239 diff -Nur linux-4.6.2/arch/riscv/include/asm/thread_info.h linux-4.6.2.riscv/arch/riscv/include/asm/thread_info.h
4240 --- linux-4.6.2/arch/riscv/include/asm/thread_info.h 1970-01-01 01:00:00.000000000 +0100
4241 +++ linux-4.6.2.riscv/arch/riscv/include/asm/thread_info.h 2017-03-04 02:48:34.166888015 +0100
4243 +#ifndef _ASM_RISCV_THREAD_INFO_H
4244 +#define _ASM_RISCV_THREAD_INFO_H
4248 +#include <asm/page.h>
4249 +#include <linux/const.h>
4251 +/* thread information allocation */
4252 +#define THREAD_SIZE_ORDER (1)
4253 +#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
4255 +#ifndef __ASSEMBLY__
4257 +#include <asm/processor.h>
4258 +#include <asm/csr.h>
4260 +typedef unsigned long mm_segment_t;
4263 + * low level task data that entry.S needs immediate access to
4264 + * - this struct should fit entirely inside of one cache line
4265 + * - this struct resides at the bottom of the supervisor stack
4266 + * - if the members of this struct changes, the assembly constants
4267 + * in asm-offsets.c must be updated accordingly
4269 +struct thread_info {
4270 + struct task_struct *task; /* main task structure */
4271 + unsigned long flags; /* low level flags */
4272 + __u32 cpu; /* current CPU */
4273 + int preempt_count; /* 0 => preemptable, <0 => BUG */
4274 + mm_segment_t addr_limit;
4278 + * macros/functions for gaining access to the thread information structure
4280 + * preempt_count needs to be 1 initially, until the scheduler is functional.
4282 +#define INIT_THREAD_INFO(tsk) \
4287 + .preempt_count = INIT_PREEMPT_COUNT, \
4288 + .addr_limit = KERNEL_DS, \
4291 +#define init_thread_info (init_thread_union.thread_info)
4292 +#define init_stack (init_thread_union.stack)
4295 + * Pointer to the thread_info struct of the current process
4296 + * Assumes that the kernel mode stack (thread_union) is THREAD_SIZE-aligned
4298 +static inline struct thread_info *current_thread_info(void)
4300 + register unsigned long sp __asm__ ("sp");
4301 + return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
4304 +#endif /* !__ASSEMBLY__ */
4307 + * thread information flags
4308 + * - these are process state flags that various assembly files may need to
4310 + * - pending work-to-be-done flags are in lowest half-word
4311 + * - other flags in upper half-word(s)
4313 +#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
4314 +#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
4315 +#define TIF_SIGPENDING 2 /* signal pending */
4316 +#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
4317 +#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
4318 +#define TIF_MEMDIE 5 /* is terminating due to OOM killer */
4319 +#define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */
4321 +#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
4322 +#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
4323 +#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
4324 +#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
4326 +#define _TIF_WORK_MASK \
4327 + (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED)
4329 +#endif /* __KERNEL__ */
4331 +#endif /* _ASM_RISCV_THREAD_INFO_H */
4332 diff -Nur linux-4.6.2/arch/riscv/include/asm/timex.h linux-4.6.2.riscv/arch/riscv/include/asm/timex.h
4333 --- linux-4.6.2/arch/riscv/include/asm/timex.h 1970-01-01 01:00:00.000000000 +0100
4334 +++ linux-4.6.2.riscv/arch/riscv/include/asm/timex.h 2017-03-04 02:48:34.166888015 +0100
4336 +#ifndef _ASM_RISCV_TIMEX_H
4337 +#define _ASM_RISCV_TIMEX_H
4339 +#include <asm/param.h>
4341 +#define CLOCK_TICK_RATE (HZ * 100UL)
4343 +typedef unsigned long cycles_t;
4345 +static inline cycles_t get_cycles(void)
4347 +#if __riscv_xlen >= 64
4349 + __asm__ __volatile__ (
4355 + __asm__ __volatile__ (
4361 + : "=&r" (hi), "=&r" (lo), "=&r" (tmp));
4362 + return ((u64)hi << 32) | lo;
4366 +#define ARCH_HAS_READ_CURRENT_TIMER
4368 +static inline int read_current_timer(unsigned long *timer_val)
4370 + *timer_val = get_cycles();
4374 +#endif /* _ASM_RISCV_TIMEX_H */
4375 diff -Nur linux-4.6.2/arch/riscv/include/asm/tlbflush.h linux-4.6.2.riscv/arch/riscv/include/asm/tlbflush.h
4376 --- linux-4.6.2/arch/riscv/include/asm/tlbflush.h 1970-01-01 01:00:00.000000000 +0100
4377 +++ linux-4.6.2.riscv/arch/riscv/include/asm/tlbflush.h 2017-03-04 02:48:34.166888015 +0100
4379 +#ifndef _ASM_RISCV_TLBFLUSH_H
4380 +#define _ASM_RISCV_TLBFLUSH_H
4384 +#include <linux/mm.h>
4385 +#include <linux/bug.h>
4386 +#include <asm/csr.h>
4388 +/* Flush entire local TLB */
4389 +static inline void local_flush_tlb_all(void)
4391 + __asm__ __volatile__ ("sfence.vm");
4394 +/* Flush one page from local TLB */
4395 +static inline void local_flush_tlb_page(unsigned long addr)
4397 + __asm__ __volatile__ ("sfence.vm %0" : : "r" (addr));
4402 +#define flush_tlb_all() local_flush_tlb_all()
4403 +#define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
4404 +#define flush_tlb_range(vma, start, end) local_flush_tlb_all()
4406 +#else /* CONFIG_SMP */
4408 +#include <asm/sbi.h>
4410 +#define flush_tlb_all() sbi_remote_sfence_vm(0, 0)
4411 +#define flush_tlb_page(vma, addr) flush_tlb_range(vma, (addr), (addr) + 1)
4412 +#define flush_tlb_range(vma, start, end) \
4413 + sbi_remote_sfence_vm_range(0, 0, (start), (end) - (start))
4415 +#endif /* CONFIG_SMP */
4417 +/* Flush the TLB entries of the specified mm context */
4418 +static inline void flush_tlb_mm(struct mm_struct *mm)
4423 +/* Flush a range of kernel pages */
4424 +static inline void flush_tlb_kernel_range(unsigned long start,
4425 + unsigned long end)
4430 +#else /* !CONFIG_MMU */
4432 +static inline void flush_tlb_all(void)
4437 +static inline void flush_tlb_mm(struct mm_struct *mm)
4442 +static inline void flush_tlb_page(struct vm_area_struct *vma,
4443 + unsigned long addr)
4448 +static inline void flush_tlb_range(struct vm_area_struct *vma,
4449 + unsigned long start, unsigned long end)
4454 +static inline void flush_tlb_kernel_range(unsigned long start,
4455 + unsigned long end)
4460 +#endif /* CONFIG_MMU */
4462 +#endif /* _ASM_RISCV_TLBFLUSH_H */
4463 diff -Nur linux-4.6.2/arch/riscv/include/asm/tlb.h linux-4.6.2.riscv/arch/riscv/include/asm/tlb.h
4464 --- linux-4.6.2/arch/riscv/include/asm/tlb.h 1970-01-01 01:00:00.000000000 +0100
4465 +++ linux-4.6.2.riscv/arch/riscv/include/asm/tlb.h 2017-03-04 02:48:34.166888015 +0100
4467 +#ifndef _ASM_RISCV_TLB_H
4468 +#define _ASM_RISCV_TLB_H
4470 +#include <asm-generic/tlb.h>
4472 +static inline void tlb_flush(struct mmu_gather *tlb)
4474 + flush_tlb_mm(tlb->mm);
4477 +#endif /* _ASM_RISCV_TLB_H */
4478 diff -Nur linux-4.6.2/arch/riscv/include/asm/uaccess.h linux-4.6.2.riscv/arch/riscv/include/asm/uaccess.h
4479 --- linux-4.6.2/arch/riscv/include/asm/uaccess.h 1970-01-01 01:00:00.000000000 +0100
4480 +++ linux-4.6.2.riscv/arch/riscv/include/asm/uaccess.h 2017-03-04 02:48:34.166888015 +0100
4482 +#ifndef _ASM_RISCV_UACCESS_H
4483 +#define _ASM_RISCV_UACCESS_H
4486 + * User space memory access functions
4488 +#include <linux/errno.h>
4489 +#include <linux/compiler.h>
4490 +#include <linux/thread_info.h>
4491 +#include <asm/byteorder.h>
4492 +#include <asm/asm.h>
4494 +#ifdef CONFIG_RV_PUM
4495 +#define __enable_user_access() \
4496 + __asm__ __volatile__ ("csrc sstatus, %0" : : "r" (SR_PUM))
4497 +#define __disable_user_access() \
4498 + __asm__ __volatile__ ("csrs sstatus, %0" : : "r" (SR_PUM))
4500 +#define __enable_user_access()
4501 +#define __disable_user_access()
4505 + * The fs value determines whether argument validity checking should be
4506 + * performed or not. If get_fs() == USER_DS, checking is performed, with
4507 + * get_fs() == KERNEL_DS, checking is bypassed.
4509 + * For historical reasons, these macros are grossly misnamed.
4512 +#define KERNEL_DS (~0UL)
4513 +#define USER_DS (TASK_SIZE)
4515 +#define get_ds() (KERNEL_DS)
4516 +#define get_fs() (current_thread_info()->addr_limit)
4518 +static inline void set_fs(mm_segment_t fs)
4520 + current_thread_info()->addr_limit = fs;
4523 +#define segment_eq(a, b) ((a) == (b))
4525 +#define user_addr_max() (get_fs())
4528 +#define VERIFY_READ 0
4529 +#define VERIFY_WRITE 1
4532 + * access_ok: - Checks if a user space pointer is valid
4533 + * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that
4534 + * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
4535 + * to write to a block, it is always safe to read from it.
4536 + * @addr: User space pointer to start of block to check
4537 + * @size: Size of block to check
4539 + * Context: User context only. This function may sleep.
4541 + * Checks if a pointer to a block of memory in user space is valid.
4543 + * Returns true (nonzero) if the memory block may be valid, false (zero)
4544 + * if it is definitely invalid.
4546 + * Note that, depending on architecture, this function probably just
4547 + * checks that the pointer is in the user space range - after calling
4548 + * this function, memory access functions may still return -EFAULT.
4550 +#define access_ok(type, addr, size) ({ \
4551 + __chk_user_ptr(addr); \
4552 + likely(__access_ok((unsigned long __force)(addr), (size))); \
4555 +/* Ensure that the range [addr, addr+size) is within the process's
4558 +static inline int __access_ok(unsigned long addr, unsigned long size)
4560 + const mm_segment_t fs = get_fs();
4561 + return (size <= fs) && (addr <= (fs - size));
4565 + * The exception table consists of pairs of addresses: the first is the
4566 + * address of an instruction that is allowed to fault, and the second is
4567 + * the address at which the program should continue. No registers are
4568 + * modified, so it is entirely up to the continuation code to figure out
4571 + * All the routines below use bits of fixup code that are out of line
4572 + * with the main instruction path. This means when everything is well,
4573 + * we don't even have to jump over them. Further, they do not intrude
4574 + * on our cache or tlb entries.
4577 +struct exception_table_entry {
4578 + unsigned long insn, fixup;
4581 +extern int fixup_exception(struct pt_regs *);
4583 +#if defined(__LITTLE_ENDIAN)
4586 +#elif defined(__BIG_ENDIAN)
4590 +#error "Unknown endianness"
4594 + * The "__xxx" versions of the user access functions do not verify the address
4595 + * space - it must have been done previously with a separate "access_ok()"
4600 +#define __get_user_asm(insn, x, ptr, err) \
4602 + uintptr_t __tmp; \
4603 + __enable_user_access(); \
4604 + __asm__ __volatile__ ( \
4606 + " " insn " %1, %3\n" \
4608 + " .section .fixup,\"ax\"\n" \
4613 + " jump 2b, %2\n" \
4615 + " .section __ex_table,\"a\"\n" \
4616 + " .balign " SZPTR "\n" \
4617 + " " PTR " 1b, 3b\n" \
4619 + : "+r" (err), "=&r" (x), "=r" (__tmp) \
4620 + : "m" (*(ptr)), "i" (-EFAULT)); \
4621 + __disable_user_access(); \
4623 +#else /* !CONFIG_MMU */
4624 +#define __get_user_asm(insn, x, ptr, err) \
4625 + __asm__ __volatile__ ( \
4629 +#endif /* CONFIG_MMU */
4632 +#ifdef CONFIG_64BIT
4633 +#define __get_user_8(x, ptr, err) \
4634 + __get_user_asm("ld", x, ptr, err)
4635 +#else /* !CONFIG_64BIT */
4637 +#define __get_user_8(x, ptr, err) \
4639 + u32 __user *__ptr = (u32 __user *)(ptr); \
4641 + uintptr_t __tmp; \
4642 + __enable_user_access(); \
4643 + __asm__ __volatile__ ( \
4649 + " .section .fixup,\"ax\"\n" \
4655 + " jump 3b, %3\n" \
4657 + " .section __ex_table,\"a\"\n" \
4658 + " .balign " SZPTR "\n" \
4659 + " " PTR " 1b, 4b\n" \
4660 + " " PTR " 2b, 4b\n" \
4662 + : "+r" (err), "=&r" (__lo), "=r" (__hi), \
4664 + : "m" (__ptr[__LSW]), "m" (__ptr[__MSW]), \
4666 + __disable_user_access(); \
4667 + (x) = (__typeof__(x))((__typeof__((x)-(x)))( \
4668 + (((u64)__hi << 32) | __lo))); \
4670 +#else /* !CONFIG_MMU */
4671 +#define __get_user_8(x, ptr, err) \
4672 + (x) = (__typeof__(x))(*((u64 __user *)(ptr)))
4673 +#endif /* CONFIG_MMU */
4674 +#endif /* CONFIG_64BIT */
4678 + * __get_user: - Get a simple variable from user space, with less checking.
4679 + * @x: Variable to store result.
4680 + * @ptr: Source address, in user space.
4682 + * Context: User context only. This function may sleep.
4684 + * This macro copies a single simple variable from user space to kernel
4685 + * space. It supports simple types like char and int, but not larger
4686 + * data types like structures or arrays.
4688 + * @ptr must have pointer-to-simple-variable type, and the result of
4689 + * dereferencing @ptr must be assignable to @x without a cast.
4691 + * Caller must check the pointer with access_ok() before calling this
4694 + * Returns zero on success, or -EFAULT on error.
4695 + * On error, the variable @x is set to zero.
4697 +#define __get_user(x, ptr) \
4699 + register int __gu_err = 0; \
4700 + const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
4701 + __chk_user_ptr(__gu_ptr); \
4702 + switch (sizeof(*__gu_ptr)) { \
4704 + __get_user_asm("lb", (x), __gu_ptr, __gu_err); \
4707 + __get_user_asm("lh", (x), __gu_ptr, __gu_err); \
4710 + __get_user_asm("lw", (x), __gu_ptr, __gu_err); \
4713 + __get_user_8((x), __gu_ptr, __gu_err); \
4722 + * get_user: - Get a simple variable from user space.
4723 + * @x: Variable to store result.
4724 + * @ptr: Source address, in user space.
4726 + * Context: User context only. This function may sleep.
4728 + * This macro copies a single simple variable from user space to kernel
4729 + * space. It supports simple types like char and int, but not larger
4730 + * data types like structures or arrays.
4732 + * @ptr must have pointer-to-simple-variable type, and the result of
4733 + * dereferencing @ptr must be assignable to @x without a cast.
4735 + * Returns zero on success, or -EFAULT on error.
4736 + * On error, the variable @x is set to zero.
4738 +#define get_user(x, ptr) \
4740 + const __typeof__(*(ptr)) __user *__p = (ptr); \
4742 + access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \
4743 + __get_user((x), __p) : \
4744 + ((x) = 0, -EFAULT); \
4749 +#define __put_user_asm(insn, x, ptr, err) \
4751 + uintptr_t __tmp; \
4752 + __typeof__(*(ptr)) __x = x; \
4753 + __enable_user_access(); \
4754 + __asm__ __volatile__ ( \
4756 + " " insn " %z3, %2\n" \
4758 + " .section .fixup,\"ax\"\n" \
4762 + " jump 2b, %1\n" \
4764 + " .section __ex_table,\"a\"\n" \
4765 + " .balign " SZPTR "\n" \
4766 + " " PTR " 1b, 3b\n" \
4768 + : "+r" (err), "=r" (__tmp), "=m" (*(ptr)) \
4769 + : "rJ" (__x), "i" (-EFAULT)); \
4770 + __disable_user_access(); \
4772 +#else /* !CONFIG_MMU */
4773 +#define __put_user_asm(insn, x, ptr, err) \
4774 + __asm__ __volatile__ ( \
4777 + : "rJ" ((__typeof__(*(ptr))) x))
4778 +#endif /* CONFIG_MMU */
4781 +#ifdef CONFIG_64BIT
4782 +#define __put_user_8(x, ptr, err) \
4783 + __put_user_asm("sd", x, ptr, err)
4784 +#else /* !CONFIG_64BIT */
4786 +#define __put_user_8(x, ptr, err) \
4788 + u32 __user *__ptr = (u32 __user *)(ptr); \
4789 + u64 __x = (__typeof__((x)-(x)))(x); \
4790 + uintptr_t __tmp; \
4791 + __enable_user_access(); \
4792 + __asm__ __volatile__ ( \
4798 + " .section .fixup,\"ax\"\n" \
4802 + " jump 2b, %1\n" \
4804 + " .section __ex_table,\"a\"\n" \
4805 + " .balign " SZPTR "\n" \
4806 + " " PTR " 1b, 4b\n" \
4807 + " " PTR " 2b, 4b\n" \
4809 + : "+r" (err), "=r" (__tmp), \
4810 + "=m" (__ptr[__LSW]), \
4811 + "=m" (__ptr[__MSW]) \
4812 + : "rJ" (__x), "rJ" (__x >> 32), "i" (-EFAULT)); \
4813 + __disable_user_access(); \
4815 +#else /* !CONFIG_MMU */
4816 +#define __put_user_8(x, ptr, err) \
4817 + *((u64 __user *)(ptr)) = (u64)(x)
4818 +#endif /* CONFIG_MMU */
4819 +#endif /* CONFIG_64BIT */
4823 + * __put_user: - Write a simple value into user space, with less checking.
4824 + * @x: Value to copy to user space.
4825 + * @ptr: Destination address, in user space.
4827 + * Context: User context only. This function may sleep.
4829 + * This macro copies a single simple value from kernel space to user
4830 + * space. It supports simple types like char and int, but not larger
4831 + * data types like structures or arrays.
4833 + * @ptr must have pointer-to-simple-variable type, and @x must be assignable
4834 + * to the result of dereferencing @ptr.
4836 + * Caller must check the pointer with access_ok() before calling this
4839 + * Returns zero on success, or -EFAULT on error.
4841 +#define __put_user(x, ptr) \
4843 + register int __pu_err = 0; \
4844 + __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
4845 + __chk_user_ptr(__gu_ptr); \
4846 + switch (sizeof(*__gu_ptr)) { \
4848 + __put_user_asm("sb", (x), __gu_ptr, __pu_err); \
4851 + __put_user_asm("sh", (x), __gu_ptr, __pu_err); \
4854 + __put_user_asm("sw", (x), __gu_ptr, __pu_err); \
4857 + __put_user_8((x), __gu_ptr, __pu_err); \
4866 + * put_user: - Write a simple value into user space.
4867 + * @x: Value to copy to user space.
4868 + * @ptr: Destination address, in user space.
4870 + * Context: User context only. This function may sleep.
4872 + * This macro copies a single simple value from kernel space to user
4873 + * space. It supports simple types like char and int, but not larger
4874 + * data types like structures or arrays.
4876 + * @ptr must have pointer-to-simple-variable type, and @x must be assignable
4877 + * to the result of dereferencing @ptr.
4879 + * Returns zero on success, or -EFAULT on error.
4881 +#define put_user(x, ptr) \
4883 + __typeof__(*(ptr)) __user *__p = (ptr); \
4885 + access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \
4886 + __put_user((x), __p) : \
4891 +extern unsigned long __must_check __copy_user(void __user *to,
4892 + const void __user *from, unsigned long n);
4894 +static inline long __must_check __copy_from_user(void *to,
4895 + const void __user *from, unsigned long n)
4897 + return __copy_user(to, from, n);
4900 +static inline long __must_check __copy_to_user(void __user *to,
4901 + const void *from, unsigned long n)
4903 + return __copy_user(to, from, n);
4906 +#define __copy_from_user_inatomic(to, from, n) \
4907 + __copy_from_user((to), (from), (n))
4908 +#define __copy_to_user_inatomic(to, from, n) \
4909 + __copy_to_user((to), (from), (n))
4911 +static inline long copy_from_user(void *to,
4912 + const void __user * from, unsigned long n)
4915 + return access_ok(VERIFY_READ, from, n) ?
4916 + __copy_from_user(to, from, n) : n;
4919 +static inline long copy_to_user(void __user *to,
4920 + const void *from, unsigned long n)
4923 + return access_ok(VERIFY_WRITE, to, n) ?
4924 + __copy_to_user(to, from, n) : n;
4927 +extern long strncpy_from_user(char *dest, const char __user *src, long count);
4929 +extern long __must_check strlen_user(const char __user *str);
4930 +extern long __must_check strnlen_user(const char __user *str, long n);
4932 +extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
4934 +static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
4937 + return access_ok(VERIFY_WRITE, to, n) ?
4938 + __clear_user(to, n) : n;
4941 +#endif /* _ASM_RISCV_UACCESS_H */
4942 diff -Nur linux-4.6.2/arch/riscv/include/asm/unistd.h linux-4.6.2.riscv/arch/riscv/include/asm/unistd.h
4943 --- linux-4.6.2/arch/riscv/include/asm/unistd.h 1970-01-01 01:00:00.000000000 +0100
4944 +++ linux-4.6.2.riscv/arch/riscv/include/asm/unistd.h 2017-03-04 02:48:34.166888015 +0100
4946 +#define __ARCH_HAVE_MMU
4947 +#define __ARCH_WANT_SYS_CLONE
4948 +#include <uapi/asm/unistd.h>
4949 diff -Nur linux-4.6.2/arch/riscv/include/asm/vdso.h linux-4.6.2.riscv/arch/riscv/include/asm/vdso.h
4950 --- linux-4.6.2/arch/riscv/include/asm/vdso.h 1970-01-01 01:00:00.000000000 +0100
4951 +++ linux-4.6.2.riscv/arch/riscv/include/asm/vdso.h 2017-03-04 02:48:34.166888015 +0100
4953 +#ifndef _ASM_RISCV_VDSO_H
4954 +#define _ASM_RISCV_VDSO_H
4956 +#include <linux/types.h>
4961 +#define VDSO_SYMBOL(base, name) \
4963 + extern const char __vdso_##name[]; \
4964 + (void __user *)((unsigned long)(base) + __vdso_##name); \
4967 +#endif /* _ASM_RISCV_VDSO_H */
4968 diff -Nur linux-4.6.2/arch/riscv/include/asm/word-at-a-time.h linux-4.6.2.riscv/arch/riscv/include/asm/word-at-a-time.h
4969 --- linux-4.6.2/arch/riscv/include/asm/word-at-a-time.h 1970-01-01 01:00:00.000000000 +0100
4970 +++ linux-4.6.2.riscv/arch/riscv/include/asm/word-at-a-time.h 2017-03-04 02:48:34.166888015 +0100
4972 +#ifndef _ASM_RISCV_WORD_AT_A_TIME_H
4973 +#define _ASM_RISCV_WORD_AT_A_TIME_H
4975 +/* Derived from arch/x86/include/asm/word-at-a-time.h */
4977 +#include <linux/kernel.h>
4979 +struct word_at_a_time {
4980 + const unsigned long one_bits, high_bits;
4983 +#define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
4985 +static inline unsigned long has_zero(unsigned long val,
4986 + unsigned long *bits, const struct word_at_a_time *c)
4988 + unsigned long mask = ((val - c->one_bits) & ~val) & c->high_bits;
4993 +static inline unsigned long prep_zero_mask(unsigned long val,
4994 + unsigned long bits, const struct word_at_a_time *c)
4999 +static inline unsigned long create_zero_mask(unsigned long bits)
5001 + bits = (bits - 1) & ~bits;
5005 +static inline unsigned long find_zero(unsigned long mask)
5007 + return fls64(mask) >> 3;
5010 +/* The mask we created is directly usable as a bytemask */
5011 +#define zero_bytemask(mask) (mask)
5013 +#endif /* _ASM_RISCV_WORD_AT_A_TIME_H */
5014 diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/auxvec.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/auxvec.h
5015 --- linux-4.6.2/arch/riscv/include/uapi/asm/auxvec.h 1970-01-01 01:00:00.000000000 +0100
5016 +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/auxvec.h 2017-03-04 02:48:34.166888015 +0100
5018 +#ifndef _UAPI_ASM_RISCV_AUXVEC_H
5019 +#define _UAPI_ASM_RISCV_AUXVEC_H
5021 +/* vDSO location */
5022 +#define AT_SYSINFO_EHDR 33
5024 +#endif /* _UAPI_ASM_RISCV_AUXVEC_H */
5025 diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/bitsperlong.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/bitsperlong.h
5026 --- linux-4.6.2/arch/riscv/include/uapi/asm/bitsperlong.h 1970-01-01 01:00:00.000000000 +0100
5027 +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/bitsperlong.h 2017-03-04 02:48:34.166888015 +0100
5029 +#ifndef _UAPI_ASM_RISCV_BITSPERLONG_H
5030 +#define _UAPI_ASM_RISCV_BITSPERLONG_H
5032 +#define __BITS_PER_LONG (__SIZEOF_POINTER__ * 8)
5034 +#include <asm-generic/bitsperlong.h>
5036 +#endif /* _UAPI_ASM_RISCV_BITSPERLONG_H */
5037 diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/byteorder.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/byteorder.h
5038 --- linux-4.6.2/arch/riscv/include/uapi/asm/byteorder.h 1970-01-01 01:00:00.000000000 +0100
5039 +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/byteorder.h 2017-03-04 02:48:34.166888015 +0100
5041 +#ifndef _UAPI_ASM_RISCV_BYTEORDER_H
5042 +#define _UAPI_ASM_RISCV_BYTEORDER_H
5044 +#include <linux/byteorder/little_endian.h>
5046 +#endif /* _UAPI_ASM_RISCV_BYTEORDER_H */
5047 diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/elf.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/elf.h
5048 --- linux-4.6.2/arch/riscv/include/uapi/asm/elf.h 1970-01-01 01:00:00.000000000 +0100
5049 +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/elf.h 2017-03-04 02:48:34.166888015 +0100
5051 +#ifndef _UAPI_ASM_ELF_H
5052 +#define _UAPI_ASM_ELF_H
5054 +#include <asm/ptrace.h>
5056 +/* ELF register definitions */
5057 +typedef unsigned long elf_greg_t;
5058 +typedef struct user_regs_struct elf_gregset_t;
5059 +#define ELF_NGREG (sizeof(elf_gregset_t) / sizeof(elf_greg_t))
5061 +typedef struct user_fpregs_struct elf_fpregset_t;
5065 + * RISC-V relocation types
5068 +/* Relocation types used by the dynamic linker */
5069 +#define R_RISCV_NONE 0
5070 +#define R_RISCV_32 1
5071 +#define R_RISCV_64 2
5072 +#define R_RISCV_RELATIVE 3
5073 +#define R_RISCV_COPY 4
5074 +#define R_RISCV_JUMP_SLOT 5
5075 +#define R_RISCV_TLS_DTPMOD32 6
5076 +#define R_RISCV_TLS_DTPMOD64 7
5077 +#define R_RISCV_TLS_DTPREL32 8
5078 +#define R_RISCV_TLS_DTPREL64 9
5079 +#define R_RISCV_TLS_TPREL32 10
5080 +#define R_RISCV_TLS_TPREL64 11
5082 +/* Relocation types not used by the dynamic linker */
5083 +#define R_RISCV_BRANCH 16
5084 +#define R_RISCV_JAL 17
5085 +#define R_RISCV_CALL 18
5086 +#define R_RISCV_CALL_PLT 19
5087 +#define R_RISCV_GOT_HI20 20
5088 +#define R_RISCV_TLS_GOT_HI20 21
5089 +#define R_RISCV_TLS_GD_HI20 22
5090 +#define R_RISCV_PCREL_HI20 23
5091 +#define R_RISCV_PCREL_LO12_I 24
5092 +#define R_RISCV_PCREL_LO12_S 25
5093 +#define R_RISCV_HI20 26
5094 +#define R_RISCV_LO12_I 27
5095 +#define R_RISCV_LO12_S 28
5096 +#define R_RISCV_TPREL_HI20 29
5097 +#define R_RISCV_TPREL_LO12_I 30
5098 +#define R_RISCV_TPREL_LO12_S 31
5099 +#define R_RISCV_TPREL_ADD 32
5100 +#define R_RISCV_ADD8 33
5101 +#define R_RISCV_ADD16 34
5102 +#define R_RISCV_ADD32 35
5103 +#define R_RISCV_ADD64 36
5104 +#define R_RISCV_SUB8 37
5105 +#define R_RISCV_SUB16 38
5106 +#define R_RISCV_SUB32 39
5107 +#define R_RISCV_SUB64 40
5108 +#define R_RISCV_GNU_VTINHERIT 41
5109 +#define R_RISCV_GNU_VTENTRY 42
5110 +#define R_RISCV_ALIGN 43
5111 +#define R_RISCV_RVC_BRANCH 44
5112 +#define R_RISCV_RVC_JUMP 45
5114 +#endif /* _UAPI_ASM_ELF_H */
5115 diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/Kbuild linux-4.6.2.riscv/arch/riscv/include/uapi/asm/Kbuild
5116 --- linux-4.6.2/arch/riscv/include/uapi/asm/Kbuild 1970-01-01 01:00:00.000000000 +0100
5117 +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/Kbuild 2017-03-04 02:48:34.166888015 +0100
5119 +# UAPI Header export list
5120 +include include/uapi/asm-generic/Kbuild.asm
5122 +header-y += auxvec.h
5123 +header-y += bitsperlong.h
5124 +header-y += byteorder.h
5125 +header-y += ptrace.h
5126 +header-y += sigcontext.h
5127 +header-y += siginfo.h
5128 +header-y += unistd.h
5129 diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/ptrace.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/ptrace.h
5130 --- linux-4.6.2/arch/riscv/include/uapi/asm/ptrace.h 1970-01-01 01:00:00.000000000 +0100
5131 +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/ptrace.h 2017-03-04 02:48:34.166888015 +0100
5133 +#ifndef _UAPI_ASM_RISCV_PTRACE_H
5134 +#define _UAPI_ASM_RISCV_PTRACE_H
5136 +#ifndef __ASSEMBLY__
5138 +#include <linux/types.h>
5140 +/* User-mode register state for core dumps, ptrace, sigcontext
5142 + * This decouples struct pt_regs from the userspace ABI.
5143 + * struct user_regs_struct must form a prefix of struct pt_regs.
5145 +struct user_regs_struct {
5172 + unsigned long s10;
5173 + unsigned long s11;
5180 +struct user_fpregs_struct {
5185 +#endif /* __ASSEMBLY__ */
5187 +#endif /* _UAPI_ASM_RISCV_PTRACE_H */
5188 diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/sigcontext.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/sigcontext.h
5189 --- linux-4.6.2/arch/riscv/include/uapi/asm/sigcontext.h 1970-01-01 01:00:00.000000000 +0100
5190 +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/sigcontext.h 2017-03-04 02:48:34.166888015 +0100
5192 +#ifndef _UAPI_ASM_RISCV_SIGCONTEXT_H
5193 +#define _UAPI_ASM_RISCV_SIGCONTEXT_H
5195 +#include <asm/ptrace.h>
5197 +/* Signal context structure
5199 + * This contains the context saved before a signal handler is invoked;
5200 + * it is restored by sys_sigreturn / sys_rt_sigreturn.
5202 +struct sigcontext {
5203 + struct user_regs_struct sc_regs;
5204 + struct user_fpregs_struct sc_fpregs;
5207 +#endif /* _UAPI_ASM_RISCV_SIGCONTEXT_H */
5208 diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/siginfo.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/siginfo.h
5209 --- linux-4.6.2/arch/riscv/include/uapi/asm/siginfo.h 1970-01-01 01:00:00.000000000 +0100
5210 +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/siginfo.h 2017-03-04 02:48:34.166888015 +0100
5213 + * Copyright (C) 2012 ARM Ltd.
5214 + * Copyright (C) 2016 SiFive, Inc.
5216 + * This program is free software; you can redistribute it and/or modify
5217 + * it under the terms of the GNU General Public License version 2 as
5218 + * published by the Free Software Foundation.
5220 + * This program is distributed in the hope that it will be useful,
5221 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5222 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5223 + * GNU General Public License for more details.
5225 + * You should have received a copy of the GNU General Public License
5226 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5228 +#ifndef __ASM_SIGINFO_H
5229 +#define __ASM_SIGINFO_H
5231 +#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
5233 +#include <asm-generic/siginfo.h>
5236 diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/unistd.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/unistd.h
5237 --- linux-4.6.2/arch/riscv/include/uapi/asm/unistd.h 1970-01-01 01:00:00.000000000 +0100
5238 +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/unistd.h 2017-03-04 02:48:34.166888015 +0100
5240 +#include <asm-generic/unistd.h>
5242 +#define __NR_sysriscv __NR_arch_specific_syscall
5243 +#ifndef __riscv_atomic
5244 +__SYSCALL(__NR_sysriscv, sys_sysriscv)
5247 +#define RISCV_ATOMIC_CMPXCHG 1
5248 +#define RISCV_ATOMIC_CMPXCHG64 2
5249 diff -Nur linux-4.6.2/arch/riscv/initramfs.txt linux-4.6.2.riscv/arch/riscv/initramfs.txt
5250 --- linux-4.6.2/arch/riscv/initramfs.txt 1970-01-01 01:00:00.000000000 +0100
5251 +++ linux-4.6.2.riscv/arch/riscv/initramfs.txt 2017-03-04 02:48:34.166888015 +0100
5254 +file /bin/busybox tmp/bin/busybox 755 0 0
5256 +file /etc/inittab tmp/etc/inittab 755 0 0
5259 +nod /dev/console 644 0 0 c 5 1
5260 +nod /dev/null 644 0 0 c 1 3
5261 +slink /init /bin/busybox 755 0 0
5262 diff -Nur linux-4.6.2/arch/riscv/Kconfig linux-4.6.2.riscv/arch/riscv/Kconfig
5263 --- linux-4.6.2/arch/riscv/Kconfig 1970-01-01 01:00:00.000000000 +0100
5264 +++ linux-4.6.2.riscv/arch/riscv/Kconfig 2017-03-04 02:48:34.162887952 +0100
5267 +# For a description of the syntax of this configuration file,
5268 +# see Documentation/kbuild/kconfig-language.txt.
5273 + select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
5274 + select ARCH_WANT_FRAME_POINTERS
5275 + select CLONE_BACKWARDS
5277 + select GENERIC_CLOCKEVENTS
5278 + select GENERIC_CPU_DEVICES
5279 + select GENERIC_IRQ_SHOW
5280 + select GENERIC_PCI_IOMAP
5281 + select GENERIC_STRNCPY_FROM_USER
5282 + select GENERIC_STRNLEN_USER
5283 + select GENERIC_SMP_IDLE_THREAD
5284 + select GENERIC_ATOMIC64 if !64BIT || !RV_ATOMIC
5285 + select ARCH_WANT_OPTIONAL_GPIOLIB
5286 + select HAVE_MEMBLOCK
5287 + select HAVE_MEMBLOCK_NODE_MAP
5288 + select HAVE_DMA_API_DEBUG
5289 + select HAVE_DMA_CONTIGUOUS
5290 + select HAVE_GENERIC_DMA_COHERENT
5293 + select RV_ATOMIC if SMP
5294 + select RV_SYSRISCV_ATOMIC if !RV_ATOMIC
5296 + select SYSCTL_EXCEPTION_TRACE
5297 + select HAVE_ARCH_TRACEHOOK
5302 +# even on 32-bit, physical (and DMA) addresses are > 32-bits
5303 +config ARCH_PHYS_ADDR_T_64BIT
5306 +config ARCH_DMA_ADDR_T_64BIT
5309 +config STACKTRACE_SUPPORT
5312 +config RWSEM_GENERIC_SPINLOCK
5318 + select GENERIC_BUG_RELATIVE_POINTERS if 64BIT
5320 +config GENERIC_BUG_RELATIVE_POINTERS
5323 +config GENERIC_CALIBRATE_DELAY
5326 +config GENERIC_CSUM
5329 +config GENERIC_HWEIGHT
5332 +config PGTABLE_LEVELS
5334 + default 3 if 64BIT
5337 +menu "Platform type"
5340 + bool "Symmetric Multi-Processing"
5342 + This enables support for systems with more than one CPU. If
5343 + you say N here, the kernel will run on single and
5344 + multiprocessor machines, but will use only one CPU of a
5345 + multiprocessor machine. If you say Y here, the kernel will run
5346 + on many, but not all, single processor machines. On a single
5347 + processor machine, the kernel will run faster if you say N
5350 + If you don't know what to do here, say N.
5353 + int "Maximum number of CPUs (2-32)"
5359 + prompt "CPU selection"
5360 + default CPU_RV_ROCKET
5362 +config CPU_RV_ROCKET
5364 + select CPU_SUPPORTS_64BIT_KERNEL
5366 +config CPU_RV_GENERIC
5367 + bool "Generic RISC-V"
5368 + select CPU_SUPPORTS_32BIT_KERNEL
5369 + select CPU_SUPPORTS_64BIT_KERNEL
5373 +config CPU_SUPPORTS_32BIT_KERNEL
5375 +config CPU_SUPPORTS_64BIT_KERNEL
5379 + tristate "SBI console support"
5384 + bool "Use compressed instructions (RV32C or RV64C)"
5388 + bool "Use atomic memory instructions (RV32A or RV64A)"
5391 +config RV_SYSRISCV_ATOMIC
5392 + bool "Include support for atomic operation syscalls"
5395 + If atomic memory instructions are present, i.e.,
5396 + CONFIG_RV_ATOMIC, this includes support for the syscall that
5397 + provides atomic accesses. This is only useful to run
5398 + binaries that require atomic access but were compiled with
5401 + If CONFIG_RV_ATOMIC is unset, this option is mandatory.
5405 + prompt "Protect User Memory" if EXPERT
5407 + Protect User Memory (PUM) prevents the kernel from inadvertently
5408 + accessing user-space memory. There is a small performance cost
5409 + and kernel size increase if this is enabled.
5418 + prompt "Kernel code model"
5422 + bool "32-bit kernel"
5423 + depends on CPU_SUPPORTS_32BIT_KERNEL
5425 + Select this option to build a 32-bit kernel.
5428 + bool "64-bit kernel"
5429 + depends on CPU_SUPPORTS_64BIT_KERNEL
5431 + Select this option to build a 64-bit kernel.
5435 +source "mm/Kconfig"
5437 +source "kernel/Kconfig.preempt"
5439 +source "kernel/Kconfig.hz"
5446 + bool "PCI support"
5449 + This feature enables support for PCI bus system. If you say Y
5450 + here, the kernel will include drivers and infrastructure code
5451 + to support PCI bus devices.
5456 +config PCI_DOMAINS_GENERIC
5462 +source "drivers/pci/Kconfig"
5466 +source "init/Kconfig"
5468 +source "kernel/Kconfig.freezer"
5470 +menu "Executable file formats"
5472 +source "fs/Kconfig.binfmt"
5476 +menu "Power management options"
5478 +source kernel/power/Kconfig
5482 +source "net/Kconfig"
5484 +source "drivers/Kconfig"
5486 +source "fs/Kconfig"
5488 +menu "Kernel hacking"
5490 +config CMDLINE_BOOL
5491 + bool "Built-in kernel command line"
5494 + For most platforms, it is firmware or second stage bootloader
5495 + that by default specifies the kernel command line options.
5496 + However, it might be necessary or advantageous to either override
5497 + the default kernel command line or add a few extra options to it.
5498 + For such cases, this option allows hardcoding command line options
5499 + directly into the kernel.
5501 + For that, choose 'Y' here and fill in the extra boot parameters
5502 + in CONFIG_CMDLINE.
5504 + The built-in options will be concatenated to the default command
5505 + line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
5506 + command line will be ignored and replaced by the built-in string.
5509 + string "Built-in kernel command string"
5510 + depends on CMDLINE_BOOL
5513 + Supply command-line options at build time by entering them here.
5515 +config CMDLINE_OVERRIDE
5516 + bool "Built-in command line overrides bootloader arguments"
5518 + depends on CMDLINE_BOOL
5520 + Set this option to 'Y' to have the kernel ignore the bootloader
5521 + or firmware command line. Instead, the built-in command line
5522 + will be used exclusively.
5524 +config EARLY_PRINTK
5525 + bool "Early printk"
5528 + This option enables special console drivers which allow the kernel
5529 + to print messages very early in the bootup process.
5531 + This is useful for kernel debugging when your machine crashes very
5532 + early before the console code is initialized. For normal operation
5533 + it is not recommended because it looks ugly and doesn't cooperate
5534 + with klogd/syslogd or the X server. You should normally N here,
5535 + unless you want to debug such a crash.
5538 +source "lib/Kconfig.debug"
5540 +config CMDLINE_BOOL
5544 +source "security/Kconfig"
5546 +source "crypto/Kconfig"
5548 +source "lib/Kconfig"
5550 diff -Nur linux-4.6.2/arch/riscv/kernel/asm-offsets.c linux-4.6.2.riscv/arch/riscv/kernel/asm-offsets.c
5551 --- linux-4.6.2/arch/riscv/kernel/asm-offsets.c 1970-01-01 01:00:00.000000000 +0100
5552 +++ linux-4.6.2.riscv/arch/riscv/kernel/asm-offsets.c 2017-03-04 02:48:34.166888015 +0100
5554 +#include <linux/kbuild.h>
5555 +#include <linux/sched.h>
5556 +#include <asm/thread_info.h>
5557 +#include <asm/ptrace.h>
5559 +void asm_offsets(void)
5561 + OFFSET(TASK_THREAD_INFO, task_struct, stack);
5562 + OFFSET(THREAD_RA, task_struct, thread.ra);
5563 + OFFSET(THREAD_SP, task_struct, thread.sp);
5564 + OFFSET(THREAD_S0, task_struct, thread.s[0]);
5565 + OFFSET(THREAD_S1, task_struct, thread.s[1]);
5566 + OFFSET(THREAD_S2, task_struct, thread.s[2]);
5567 + OFFSET(THREAD_S3, task_struct, thread.s[3]);
5568 + OFFSET(THREAD_S4, task_struct, thread.s[4]);
5569 + OFFSET(THREAD_S5, task_struct, thread.s[5]);
5570 + OFFSET(THREAD_S6, task_struct, thread.s[6]);
5571 + OFFSET(THREAD_S7, task_struct, thread.s[7]);
5572 + OFFSET(THREAD_S8, task_struct, thread.s[8]);
5573 + OFFSET(THREAD_S9, task_struct, thread.s[9]);
5574 + OFFSET(THREAD_S10, task_struct, thread.s[10]);
5575 + OFFSET(THREAD_S11, task_struct, thread.s[11]);
5576 + OFFSET(THREAD_SP, task_struct, thread.sp);
5577 + OFFSET(TI_TASK, thread_info, task);
5578 + OFFSET(TI_FLAGS, thread_info, flags);
5579 + OFFSET(TI_CPU, thread_info, cpu);
5581 + OFFSET(THREAD_F0, task_struct, thread.fstate.f[0]);
5582 + OFFSET(THREAD_F1, task_struct, thread.fstate.f[1]);
5583 + OFFSET(THREAD_F2, task_struct, thread.fstate.f[2]);
5584 + OFFSET(THREAD_F3, task_struct, thread.fstate.f[3]);
5585 + OFFSET(THREAD_F4, task_struct, thread.fstate.f[4]);
5586 + OFFSET(THREAD_F5, task_struct, thread.fstate.f[5]);
5587 + OFFSET(THREAD_F6, task_struct, thread.fstate.f[6]);
5588 + OFFSET(THREAD_F7, task_struct, thread.fstate.f[7]);
5589 + OFFSET(THREAD_F8, task_struct, thread.fstate.f[8]);
5590 + OFFSET(THREAD_F9, task_struct, thread.fstate.f[9]);
5591 + OFFSET(THREAD_F10, task_struct, thread.fstate.f[10]);
5592 + OFFSET(THREAD_F11, task_struct, thread.fstate.f[11]);
5593 + OFFSET(THREAD_F12, task_struct, thread.fstate.f[12]);
5594 + OFFSET(THREAD_F13, task_struct, thread.fstate.f[13]);
5595 + OFFSET(THREAD_F14, task_struct, thread.fstate.f[14]);
5596 + OFFSET(THREAD_F15, task_struct, thread.fstate.f[15]);
5597 + OFFSET(THREAD_F16, task_struct, thread.fstate.f[16]);
5598 + OFFSET(THREAD_F17, task_struct, thread.fstate.f[17]);
5599 + OFFSET(THREAD_F18, task_struct, thread.fstate.f[18]);
5600 + OFFSET(THREAD_F19, task_struct, thread.fstate.f[19]);
5601 + OFFSET(THREAD_F20, task_struct, thread.fstate.f[20]);
5602 + OFFSET(THREAD_F21, task_struct, thread.fstate.f[21]);
5603 + OFFSET(THREAD_F22, task_struct, thread.fstate.f[22]);
5604 + OFFSET(THREAD_F23, task_struct, thread.fstate.f[23]);
5605 + OFFSET(THREAD_F24, task_struct, thread.fstate.f[24]);
5606 + OFFSET(THREAD_F25, task_struct, thread.fstate.f[25]);
5607 + OFFSET(THREAD_F26, task_struct, thread.fstate.f[26]);
5608 + OFFSET(THREAD_F27, task_struct, thread.fstate.f[27]);
5609 + OFFSET(THREAD_F28, task_struct, thread.fstate.f[28]);
5610 + OFFSET(THREAD_F29, task_struct, thread.fstate.f[29]);
5611 + OFFSET(THREAD_F30, task_struct, thread.fstate.f[30]);
5612 + OFFSET(THREAD_F31, task_struct, thread.fstate.f[31]);
5613 + OFFSET(THREAD_FCSR, task_struct, thread.fstate.fcsr);
5615 + DEFINE(PT_SIZE, sizeof(struct pt_regs));
5616 + OFFSET(PT_SEPC, pt_regs, sepc);
5617 + OFFSET(PT_RA, pt_regs, ra);
5618 + OFFSET(PT_FP, pt_regs, s0);
5619 + OFFSET(PT_S0, pt_regs, s0);
5620 + OFFSET(PT_S1, pt_regs, s1);
5621 + OFFSET(PT_S2, pt_regs, s2);
5622 + OFFSET(PT_S3, pt_regs, s3);
5623 + OFFSET(PT_S4, pt_regs, s4);
5624 + OFFSET(PT_S5, pt_regs, s5);
5625 + OFFSET(PT_S6, pt_regs, s6);
5626 + OFFSET(PT_S7, pt_regs, s7);
5627 + OFFSET(PT_S8, pt_regs, s8);
5628 + OFFSET(PT_S9, pt_regs, s9);
5629 + OFFSET(PT_S10, pt_regs, s10);
5630 + OFFSET(PT_S11, pt_regs, s11);
5631 + OFFSET(PT_SP, pt_regs, sp);
5632 + OFFSET(PT_TP, pt_regs, tp);
5633 + OFFSET(PT_A0, pt_regs, a0);
5634 + OFFSET(PT_A1, pt_regs, a1);
5635 + OFFSET(PT_A2, pt_regs, a2);
5636 + OFFSET(PT_A3, pt_regs, a3);
5637 + OFFSET(PT_A4, pt_regs, a4);
5638 + OFFSET(PT_A5, pt_regs, a5);
5639 + OFFSET(PT_A6, pt_regs, a6);
5640 + OFFSET(PT_A7, pt_regs, a7);
5641 + OFFSET(PT_T0, pt_regs, t0);
5642 + OFFSET(PT_T1, pt_regs, t1);
5643 + OFFSET(PT_T2, pt_regs, t2);
5644 + OFFSET(PT_T3, pt_regs, t3);
5645 + OFFSET(PT_T4, pt_regs, t4);
5646 + OFFSET(PT_T5, pt_regs, t5);
5647 + OFFSET(PT_T6, pt_regs, t6);
5648 + OFFSET(PT_GP, pt_regs, gp);
5649 + OFFSET(PT_SSTATUS, pt_regs, sstatus);
5650 + OFFSET(PT_SBADADDR, pt_regs, sbadaddr);
5651 + OFFSET(PT_SCAUSE, pt_regs, scause);
5653 diff -Nur linux-4.6.2/arch/riscv/kernel/cpu.c linux-4.6.2.riscv/arch/riscv/kernel/cpu.c
5654 --- linux-4.6.2/arch/riscv/kernel/cpu.c 1970-01-01 01:00:00.000000000 +0100
5655 +++ linux-4.6.2.riscv/arch/riscv/kernel/cpu.c 2017-03-04 02:48:34.166888015 +0100
5657 +#include <linux/init.h>
5658 +#include <linux/seq_file.h>
5660 +#ifdef CONFIG_PROC_FS
5662 +static void *c_start(struct seq_file *m, loff_t *pos)
5664 + *pos = cpumask_next(*pos - 1, cpu_online_mask);
5665 + if ((*pos) < nr_cpu_ids)
5666 + return (void *)(uintptr_t)(1 + *pos);
5670 +static void *c_next(struct seq_file *m, void *v, loff_t *pos)
5673 + return c_start(m, pos);
5676 +static void c_stop(struct seq_file *m, void *v)
5680 +static int c_show(struct seq_file *m, void *v)
5682 + unsigned long hart_id = (unsigned long)v - 1;
5684 + seq_printf(m, "hart\t: %lu\n", hart_id);
5685 + seq_printf(m, "isa\t: RV%zuG\n", sizeof(void *) * 8);
5686 + seq_printf(m, "\n");
5690 +const struct seq_operations cpuinfo_op = {
5697 +#endif /* CONFIG_PROC_FS */
5698 diff -Nur linux-4.6.2/arch/riscv/kernel/entry.S linux-4.6.2.riscv/arch/riscv/kernel/entry.S
5699 --- linux-4.6.2/arch/riscv/kernel/entry.S 1970-01-01 01:00:00.000000000 +0100
5700 +++ linux-4.6.2.riscv/arch/riscv/kernel/entry.S 2017-03-04 02:48:34.166888015 +0100
5702 +#include <linux/init.h>
5703 +#include <linux/linkage.h>
5705 +#include <asm/asm.h>
5706 +#include <asm/csr.h>
5707 +#include <asm/unistd.h>
5708 +#include <asm/thread_info.h>
5709 +#include <asm/asm-offsets.h>
5714 + LOCAL _restore_kernel_sp
5715 + LOCAL _save_context
5717 + /* If coming from userspace, preserve the user stack pointer and load
5718 + the kernel stack pointer. If we came from the kernel, sscratch
5719 + will contain 0, and we should continue on the current stack. */
5720 + csrrw sp, sscratch, sp
5721 + bnez sp, _save_context
5723 +_restore_kernel_sp:
5726 + addi sp, sp, -(PT_SIZE)
5727 + REG_S x1, PT_RA(sp)
5728 + REG_S x3, PT_GP(sp)
5729 + REG_S x4, PT_TP(sp)
5730 + REG_S x5, PT_T0(sp)
5731 + REG_S x6, PT_T1(sp)
5732 + REG_S x7, PT_T2(sp)
5733 + REG_S x8, PT_S0(sp)
5734 + REG_S x9, PT_S1(sp)
5735 + REG_S x10, PT_A0(sp)
5736 + REG_S x11, PT_A1(sp)
5737 + REG_S x12, PT_A2(sp)
5738 + REG_S x13, PT_A3(sp)
5739 + REG_S x14, PT_A4(sp)
5740 + REG_S x15, PT_A5(sp)
5741 + REG_S x16, PT_A6(sp)
5742 + REG_S x17, PT_A7(sp)
5743 + REG_S x18, PT_S2(sp)
5744 + REG_S x19, PT_S3(sp)
5745 + REG_S x20, PT_S4(sp)
5746 + REG_S x21, PT_S5(sp)
5747 + REG_S x22, PT_S6(sp)
5748 + REG_S x23, PT_S7(sp)
5749 + REG_S x24, PT_S8(sp)
5750 + REG_S x25, PT_S9(sp)
5751 + REG_S x26, PT_S10(sp)
5752 + REG_S x27, PT_S11(sp)
5753 + REG_S x28, PT_T3(sp)
5754 + REG_S x29, PT_T4(sp)
5755 + REG_S x30, PT_T5(sp)
5756 + REG_S x31, PT_T6(sp)
5758 + /* Disable FPU to detect illegal usage of
5759 + floating point in kernel space */
5763 + csrrc s1, sstatus, t0
5767 + REG_S s0, PT_SP(sp)
5768 + REG_S s1, PT_SSTATUS(sp)
5769 + REG_S s2, PT_SEPC(sp)
5770 + REG_S s3, PT_SBADADDR(sp)
5771 + REG_S s4, PT_SCAUSE(sp)
5774 + .macro RESTORE_ALL
5775 + REG_L a0, PT_SSTATUS(sp)
5776 + REG_L a2, PT_SEPC(sp)
5780 + REG_L x1, PT_RA(sp)
5781 + REG_L x3, PT_GP(sp)
5782 + REG_L x4, PT_TP(sp)
5783 + REG_L x5, PT_T0(sp)
5784 + REG_L x6, PT_T1(sp)
5785 + REG_L x7, PT_T2(sp)
5786 + REG_L x8, PT_S0(sp)
5787 + REG_L x9, PT_S1(sp)
5788 + REG_L x10, PT_A0(sp)
5789 + REG_L x11, PT_A1(sp)
5790 + REG_L x12, PT_A2(sp)
5791 + REG_L x13, PT_A3(sp)
5792 + REG_L x14, PT_A4(sp)
5793 + REG_L x15, PT_A5(sp)
5794 + REG_L x16, PT_A6(sp)
5795 + REG_L x17, PT_A7(sp)
5796 + REG_L x18, PT_S2(sp)
5797 + REG_L x19, PT_S3(sp)
5798 + REG_L x20, PT_S4(sp)
5799 + REG_L x21, PT_S5(sp)
5800 + REG_L x22, PT_S6(sp)
5801 + REG_L x23, PT_S7(sp)
5802 + REG_L x24, PT_S8(sp)
5803 + REG_L x25, PT_S9(sp)
5804 + REG_L x26, PT_S10(sp)
5805 + REG_L x27, PT_S11(sp)
5806 + REG_L x28, PT_T3(sp)
5807 + REG_L x29, PT_T4(sp)
5808 + REG_L x30, PT_T5(sp)
5809 + REG_L x31, PT_T6(sp)
5811 + REG_L x2, PT_SP(sp)
5814 +ENTRY(handle_exception)
5817 + /* Set sscratch register to 0, so that if a recursive exception
5818 + occurs, the exception vector knows it came from the kernel */
5821 + /* Compute address of current thread_info */
5822 + li tp, ~(THREAD_SIZE-1)
5824 + /* Set current pointer */
5825 + REG_L tp, TI_TASK(tp)
5827 +1: auipc gp, %pcrel_hi(_gp)
5828 + addi gp, gp, %pcrel_lo(1b)
5830 + la ra, ret_from_exception
5831 + /* MSB of cause differentiates between
5832 + interrupts and exceptions */
5835 + /* Handle interrupts */
5838 + move a1, sp /* pt_regs */
5841 + /* Handle syscalls */
5842 + li t0, EXC_SYSCALL
5843 + beq s4, t0, handle_syscall
5845 + /* Handle other exceptions */
5846 + slli t0, s4, LGPTR
5847 + la t1, excp_vect_table
5848 + la t2, excp_vect_table_end
5849 + move a0, sp /* pt_regs */
5851 + /* Check if exception code lies within bounds */
5856 + tail do_trap_unknown
5859 + /* Advance SEPC to avoid executing the original
5860 + scall instruction on sret */
5862 + REG_S s2, PT_SEPC(sp)
5863 + /* System calls run with interrupts enabled */
5864 + csrs sstatus, SR_IE
5865 + /* Trace syscalls, but only if requested by the user. */
5866 + REG_L t0, TASK_THREAD_INFO(tp)
5867 + REG_L t0, TI_FLAGS(t0)
5868 + andi t0, t0, _TIF_SYSCALL_TRACE
5869 + bnez t0, handle_syscall_trace_enter
5871 + /* Check to make sure we don't jump to a bogus syscall number. */
5872 + li t0, __NR_syscalls
5873 + la s0, sys_ni_syscall
5874 + /* Syscall number held in a7 */
5876 + la s0, sys_call_table
5877 + slli t0, a7, LGPTR
5884 + /* Set user a0 to kernel a0 */
5885 + REG_S a0, PT_A0(sp)
5886 + /* Trace syscalls, but only if requested by the user. */
5887 + REG_L t0, TASK_THREAD_INFO(tp)
5888 + REG_L t0, TI_FLAGS(t0)
5889 + andi t0, t0, _TIF_SYSCALL_TRACE
5890 + bnez t0, handle_syscall_trace_exit
5892 +ret_from_exception:
5893 + REG_L s0, PT_SSTATUS(sp)
5894 + csrc sstatus, SR_IE
5895 + andi s0, s0, SR_PS
5896 + bnez s0, restore_all
5899 + /* Interrupts must be disabled here so flags are checked atomically */
5900 + REG_L s0, TASK_THREAD_INFO(tp)
5901 + REG_L s0, TI_FLAGS(s0) /* current_thread_info->flags */
5902 + andi s1, s0, _TIF_WORK_MASK
5903 + bnez s1, work_pending
5905 + /* Save unwound kernel stack pointer in sscratch */
5906 + addi s0, sp, PT_SIZE
5913 + /* Enter slow path for supplementary processing */
5914 + la ra, ret_from_exception
5915 + andi s1, s0, _TIF_NEED_RESCHED
5916 + bnez s1, work_resched
5918 + /* Handle pending signals and notify-resume requests */
5919 + csrs sstatus, SR_IE /* Enable interrupts for do_notify_resume() */
5920 + move a0, sp /* pt_regs */
5921 + move a1, s0 /* current_thread_info->flags */
5922 + tail do_notify_resume
5926 +/* Slow paths for ptrace. */
5927 +handle_syscall_trace_enter:
5929 + call do_syscall_trace_enter
5930 + REG_L a0, PT_A0(sp)
5931 + REG_L a1, PT_A1(sp)
5932 + REG_L a2, PT_A2(sp)
5933 + REG_L a3, PT_A3(sp)
5934 + REG_L a4, PT_A4(sp)
5935 + REG_L a5, PT_A5(sp)
5936 + REG_L a6, PT_A6(sp)
5937 + REG_L a7, PT_A7(sp)
5938 + j check_syscall_nr
5939 +handle_syscall_trace_exit:
5941 + call do_syscall_trace_exit
5942 + j ret_from_exception
5944 +END(handle_exception)
5946 +ENTRY(ret_from_fork)
5947 + la ra, ret_from_exception
5948 + tail schedule_tail
5949 +ENDPROC(ret_from_fork)
5951 +ENTRY(ret_from_kernel_thread)
5952 + call schedule_tail
5953 + /* Call fn(arg) */
5954 + la ra, ret_from_exception
5957 +ENDPROC(ret_from_kernel_thread)
5961 + * Integer register context switch
5962 + * The callee-saved registers must be saved and restored.
5964 + * a0: previous task_struct (must be preserved across the switch)
5965 + * a1: next task_struct
5968 + /* Save context into prev->thread */
5969 + REG_S ra, THREAD_RA(a0)
5970 + REG_S sp, THREAD_SP(a0)
5971 + REG_S s0, THREAD_S0(a0)
5972 + REG_S s1, THREAD_S1(a0)
5973 + REG_S s2, THREAD_S2(a0)
5974 + REG_S s3, THREAD_S3(a0)
5975 + REG_S s4, THREAD_S4(a0)
5976 + REG_S s5, THREAD_S5(a0)
5977 + REG_S s6, THREAD_S6(a0)
5978 + REG_S s7, THREAD_S7(a0)
5979 + REG_S s8, THREAD_S8(a0)
5980 + REG_S s9, THREAD_S9(a0)
5981 + REG_S s10, THREAD_S10(a0)
5982 + REG_S s11, THREAD_S11(a0)
5983 + /* Restore context from next->thread */
5984 + REG_L ra, THREAD_RA(a1)
5985 + REG_L sp, THREAD_SP(a1)
5986 + REG_L s0, THREAD_S0(a1)
5987 + REG_L s1, THREAD_S1(a1)
5988 + REG_L s2, THREAD_S2(a1)
5989 + REG_L s3, THREAD_S3(a1)
5990 + REG_L s4, THREAD_S4(a1)
5991 + REG_L s5, THREAD_S5(a1)
5992 + REG_L s6, THREAD_S6(a1)
5993 + REG_L s7, THREAD_S7(a1)
5994 + REG_L s8, THREAD_S8(a1)
5995 + REG_L s9, THREAD_S9(a1)
5996 + REG_L s10, THREAD_S10(a1)
5997 + REG_L s11, THREAD_S11(a1)
5998 + mv tp, a1 /* Next current pointer */
6000 +ENDPROC(__switch_to)
6002 +ENTRY(__fstate_save)
6006 + fsd f0, THREAD_F0(a0)
6007 + fsd f1, THREAD_F1(a0)
6008 + fsd f2, THREAD_F2(a0)
6009 + fsd f3, THREAD_F3(a0)
6010 + fsd f4, THREAD_F4(a0)
6011 + fsd f5, THREAD_F5(a0)
6012 + fsd f6, THREAD_F6(a0)
6013 + fsd f7, THREAD_F7(a0)
6014 + fsd f8, THREAD_F8(a0)
6015 + fsd f9, THREAD_F9(a0)
6016 + fsd f10, THREAD_F10(a0)
6017 + fsd f11, THREAD_F11(a0)
6018 + fsd f12, THREAD_F12(a0)
6019 + fsd f13, THREAD_F13(a0)
6020 + fsd f14, THREAD_F14(a0)
6021 + fsd f15, THREAD_F15(a0)
6022 + fsd f16, THREAD_F16(a0)
6023 + fsd f17, THREAD_F17(a0)
6024 + fsd f18, THREAD_F18(a0)
6025 + fsd f19, THREAD_F19(a0)
6026 + fsd f20, THREAD_F20(a0)
6027 + fsd f21, THREAD_F21(a0)
6028 + fsd f22, THREAD_F22(a0)
6029 + fsd f23, THREAD_F23(a0)
6030 + fsd f24, THREAD_F24(a0)
6031 + fsd f25, THREAD_F25(a0)
6032 + fsd f26, THREAD_F26(a0)
6033 + fsd f27, THREAD_F27(a0)
6034 + fsd f28, THREAD_F28(a0)
6035 + fsd f29, THREAD_F29(a0)
6036 + fsd f30, THREAD_F30(a0)
6037 + fsd f31, THREAD_F31(a0)
6038 + sw t0, THREAD_FCSR(a0)
6041 +ENDPROC(__fstate_save)
6043 +ENTRY(__fstate_restore)
6045 + lw t0, THREAD_FCSR(a0)
6047 + fld f0, THREAD_F0(a0)
6048 + fld f1, THREAD_F1(a0)
6049 + fld f2, THREAD_F2(a0)
6050 + fld f3, THREAD_F3(a0)
6051 + fld f4, THREAD_F4(a0)
6052 + fld f5, THREAD_F5(a0)
6053 + fld f6, THREAD_F6(a0)
6054 + fld f7, THREAD_F7(a0)
6055 + fld f8, THREAD_F8(a0)
6056 + fld f9, THREAD_F9(a0)
6057 + fld f10, THREAD_F10(a0)
6058 + fld f11, THREAD_F11(a0)
6059 + fld f12, THREAD_F12(a0)
6060 + fld f13, THREAD_F13(a0)
6061 + fld f14, THREAD_F14(a0)
6062 + fld f15, THREAD_F15(a0)
6063 + fld f16, THREAD_F16(a0)
6064 + fld f17, THREAD_F17(a0)
6065 + fld f18, THREAD_F18(a0)
6066 + fld f19, THREAD_F19(a0)
6067 + fld f20, THREAD_F20(a0)
6068 + fld f21, THREAD_F21(a0)
6069 + fld f22, THREAD_F22(a0)
6070 + fld f23, THREAD_F23(a0)
6071 + fld f24, THREAD_F24(a0)
6072 + fld f25, THREAD_F25(a0)
6073 + fld f26, THREAD_F26(a0)
6074 + fld f27, THREAD_F27(a0)
6075 + fld f28, THREAD_F28(a0)
6076 + fld f29, THREAD_F29(a0)
6077 + fld f30, THREAD_F30(a0)
6078 + fld f31, THREAD_F31(a0)
6082 +ENDPROC(__fstate_restore)
6085 + .section ".rodata"
6086 + /* Exception vector table */
6087 +ENTRY(excp_vect_table)
6088 + PTR do_trap_insn_misaligned
6090 + PTR do_trap_insn_illegal
6091 + PTR do_trap_unknown
6092 + PTR do_trap_unknown
6094 + PTR do_trap_amo_misaligned
6096 + PTR 0 /* handle_syscall */
6098 +excp_vect_table_end:
6099 +END(excp_vect_table)
6101 diff -Nur linux-4.6.2/arch/riscv/kernel/head.S linux-4.6.2.riscv/arch/riscv/kernel/head.S
6102 --- linux-4.6.2/arch/riscv/kernel/head.S 1970-01-01 01:00:00.000000000 +0100
6103 +++ linux-4.6.2.riscv/arch/riscv/kernel/head.S 2017-03-04 02:48:34.166888015 +0100
6105 +#include <asm/thread_info.h>
6106 +#include <asm/asm-offsets.h>
6107 +#include <asm/asm.h>
6108 +#include <linux/init.h>
6109 +#include <linux/linkage.h>
6110 +#include <asm/thread_info.h>
6111 +#include <asm/page.h>
6112 +#include <asm/csr.h>
6116 + /* Load the global pointer (before any use of la) */
6117 +1: auipc gp, %pcrel_hi(_gp)
6118 + addi gp, gp, %pcrel_lo(1b)
6120 + /* Disable FPU to detect illegal usage of
6121 + floating point in kernel space */
6125 +#ifdef CONFIG_RV_PUM
6126 + /* Prevent inadvertent access to user memory */
6131 + /* See if we're the main hart */
6133 + bnez a0, .Lsecondary_start
6135 + /* Clear the .bss segment */
6136 + la a0, __bss_start
6142 + /* Initialize stack pointer */
6143 + la sp, init_thread_union + THREAD_SIZE
6144 + /* Initialize current task_struct pointer */
6151 + li a1, CONFIG_NR_CPUS
6152 + bgeu a0, a1, .Lsecondary_park
6154 + la a1, __cpu_up_stack_pointer
6155 + slli a0, a0, LGREG
6160 + beqz sp, .Lwait_for_cpu_up
6162 + /* Initialize task_struct pointer */
6163 + li tp, -THREAD_SIZE
6171 + /* We lack SMP support or have too many harts, so park this hart */
6173 + j .Lsecondary_park
6177 + /* Empty zero page */
6179 +ENTRY(empty_zero_page)
6180 + .fill (empty_zero_page + PAGE_SIZE) - ., 1, 0x00
6181 +END(empty_zero_page)
6182 diff -Nur linux-4.6.2/arch/riscv/kernel/irq.c linux-4.6.2.riscv/arch/riscv/kernel/irq.c
6183 --- linux-4.6.2/arch/riscv/kernel/irq.c 1970-01-01 01:00:00.000000000 +0100
6184 +++ linux-4.6.2.riscv/arch/riscv/kernel/irq.c 2017-03-04 02:48:34.166888015 +0100
6186 +#include <linux/interrupt.h>
6187 +#include <linux/ftrace.h>
6188 +#include <linux/seq_file.h>
6190 +#include <asm/ptrace.h>
6191 +#include <asm/sbi.h>
6192 +#include <asm/sbi-con.h>
6193 +#include <asm/smp.h>
6195 +struct plic_context {
6196 + volatile int priority_threshold;
6197 + volatile int claim;
6200 +static DEFINE_PER_CPU(struct plic_context *, plic_context);
6201 +static DEFINE_PER_CPU(unsigned int, irq_in_progress);
6203 +static void riscv_software_interrupt(void)
6208 + ret = handle_ipi();
6209 + if (ret != IRQ_NONE)
6213 + ret = sbi_console_isr();
6214 + if (ret != IRQ_NONE)
6220 +static void plic_interrupt(void)
6222 + unsigned int cpu = smp_processor_id();
6223 + unsigned int irq = per_cpu(plic_context, cpu)->claim;
6225 + BUG_ON(per_cpu(irq_in_progress, cpu) != 0);
6228 + per_cpu(irq_in_progress, cpu) = irq;
6229 + generic_handle_irq(irq);
6233 +asmlinkage void __irq_entry do_IRQ(unsigned int cause, struct pt_regs *regs)
6235 + struct pt_regs *old_regs = set_irq_regs(regs);
6238 + /* There are three classes of interrupt: timer, software, and
6239 + external devices. We dispatch between them here. External
6240 + device interrupts use the generic IRQ mechanisms. */
6242 + case INTERRUPT_CAUSE_TIMER:
6243 + riscv_timer_interrupt();
6245 + case INTERRUPT_CAUSE_SOFTWARE:
6246 + riscv_software_interrupt();
6248 + case INTERRUPT_CAUSE_EXTERNAL:
6256 + set_irq_regs(old_regs);
6259 +static void plic_irq_mask(struct irq_data *d)
6261 + unsigned int cpu = smp_processor_id();
6263 + BUG_ON(d->irq != per_cpu(irq_in_progress, cpu));
6266 +static void plic_irq_unmask(struct irq_data *d)
6268 + unsigned int cpu = smp_processor_id();
6270 + BUG_ON(d->irq != per_cpu(irq_in_progress, cpu));
6272 + per_cpu(plic_context, cpu)->claim = per_cpu(irq_in_progress, cpu);
6273 + per_cpu(irq_in_progress, cpu) = 0;
6276 +struct irq_chip plic_irq_chip = {
6278 + .irq_mask = plic_irq_mask,
6279 + .irq_mask_ack = plic_irq_mask,
6280 + .irq_unmask = plic_irq_unmask,
6283 +void __init init_IRQ(void)
6285 + /* Enable software interrupts (and disable the others) */
6286 + csr_write(sie, SIE_SSIE);
6288 diff -Nur linux-4.6.2/arch/riscv/kernel/Makefile linux-4.6.2.riscv/arch/riscv/kernel/Makefile
6289 --- linux-4.6.2/arch/riscv/kernel/Makefile 1970-01-01 01:00:00.000000000 +0100
6290 +++ linux-4.6.2.riscv/arch/riscv/kernel/Makefile 2017-03-04 02:48:34.166888015 +0100
6293 +# Makefile for the RISC-V Linux kernel
6296 +extra-y := head.o vmlinux.lds
6298 +obj-y := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \
6299 + sbi.o signal.o syscall_table.o sys_riscv.o time.o traps.o \
6300 + stacktrace.o vdso.o vdso/
6302 +obj-$(CONFIG_SMP) += smpboot.o smp.o
6303 +obj-$(CONFIG_SBI_CONSOLE) += sbi-con.o
6304 +obj-$(CONFIG_PCI) += pci.o
6307 diff -Nur linux-4.6.2/arch/riscv/kernel/pci.c linux-4.6.2.riscv/arch/riscv/kernel/pci.c
6308 --- linux-4.6.2/arch/riscv/kernel/pci.c 1970-01-01 01:00:00.000000000 +0100
6309 +++ linux-4.6.2.riscv/arch/riscv/kernel/pci.c 2017-03-04 02:48:34.166888015 +0100
6311 +#include <linux/init.h>
6312 +#include <linux/io.h>
6313 +#include <linux/kernel.h>
6314 +#include <linux/mm.h>
6315 +#include <linux/slab.h>
6316 +#include <linux/pci.h>
6319 + * Called after each bus is probed, but before its children are examined
6321 +void pcibios_fixup_bus(struct pci_bus *bus)
6323 + /* nothing to do, expected to be removed in the future */
6327 + * We don't have to worry about legacy ISA devices, so nothing to do here
6329 +resource_size_t pcibios_align_resource(void *data, const struct resource *res,
6330 + resource_size_t size, resource_size_t align)
6332 + return res->start;
6334 diff -Nur linux-4.6.2/arch/riscv/kernel/process.c linux-4.6.2.riscv/arch/riscv/kernel/process.c
6335 --- linux-4.6.2/arch/riscv/kernel/process.c 1970-01-01 01:00:00.000000000 +0100
6336 +++ linux-4.6.2.riscv/arch/riscv/kernel/process.c 2017-03-04 02:48:34.166888015 +0100
6338 +#include <linux/kernel.h>
6339 +#include <linux/sched.h>
6340 +#include <linux/tick.h>
6341 +#include <linux/ptrace.h>
6343 +#include <asm/unistd.h>
6344 +#include <asm/uaccess.h>
6345 +#include <asm/processor.h>
6346 +#include <asm/csr.h>
6347 +#include <asm/string.h>
6348 +#include <asm/switch_to.h>
6350 +extern asmlinkage void ret_from_fork(void);
6351 +extern asmlinkage void ret_from_kernel_thread(void);
6353 +void arch_cpu_idle(void)
6355 + wait_for_interrupt();
6356 + local_irq_enable();
6359 +void show_regs(struct pt_regs *regs)
6361 + show_regs_print_info(KERN_DEFAULT);
6363 + printk("sepc: " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n",
6364 + regs->sepc, regs->ra, regs->sp);
6365 + printk(" gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n",
6366 + regs->gp, regs->tp, regs->t0);
6367 + printk(" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
6368 + regs->t1, regs->t2, regs->s0);
6369 + printk(" s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
6370 + regs->s1, regs->a0, regs->a1);
6371 + printk(" a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
6372 + regs->a2, regs->a3, regs->a4);
6373 + printk(" a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
6374 + regs->a5, regs->a6, regs->a7);
6375 + printk(" s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
6376 + regs->s2, regs->s3, regs->s4);
6377 + printk(" s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
6378 + regs->s5, regs->s6, regs->s7);
6379 + printk(" s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
6380 + regs->s8, regs->s9, regs->s10);
6381 + printk(" s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
6382 + regs->s11, regs->t3, regs->t4);
6383 + printk(" t5 : " REG_FMT " t6 : " REG_FMT "\n",
6384 + regs->t5, regs->t6);
6386 + printk("sstatus: " REG_FMT " sbadaddr: " REG_FMT " scause: " REG_FMT "\n",
6387 + regs->sstatus, regs->sbadaddr, regs->scause);
6390 +void start_thread(struct pt_regs *regs, unsigned long pc,
6393 + regs->sstatus = SR_PIE /* User mode, irqs on */ | SR_FS_INITIAL;
6399 +void flush_thread(void)
6401 + /* Reset FPU context
6402 + * frm: round to nearest, ties to even (IEEE default)
6403 + * fflags: accrued exceptions cleared
6405 + memset(¤t->thread.fstate, 0,
6406 + sizeof(struct user_fpregs_struct));
6409 +int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
6411 + fstate_save(src, task_pt_regs(src));
6416 +int copy_thread(unsigned long clone_flags, unsigned long usp,
6417 + unsigned long arg, struct task_struct *p)
6419 + struct pt_regs *childregs = task_pt_regs(p);
6421 + /* p->thread holds context to be restored by __switch_to() */
6422 + if (unlikely(p->flags & PF_KTHREAD)) {
6423 + /* Kernel thread */
6424 + const register unsigned long gp __asm__ ("gp");
6425 + memset(childregs, 0, sizeof(struct pt_regs));
6426 + childregs->gp = gp;
6427 + childregs->sstatus = SR_PS | SR_PIE; /* Supervisor, irqs on */
6429 + p->thread.ra = (unsigned long)ret_from_kernel_thread;
6430 + p->thread.s[0] = usp; /* fn */
6431 + p->thread.s[1] = arg;
6433 + *childregs = *(current_pt_regs());
6434 + if (usp) /* User fork */
6435 + childregs->sp = usp;
6436 + if (clone_flags & CLONE_SETTLS)
6437 + childregs->tp = childregs->a5;
6438 + childregs->a0 = 0; /* Return value of fork() */
6439 + p->thread.ra = (unsigned long)ret_from_fork;
6441 + p->thread.sp = (unsigned long)childregs; /* kernel sp */
6444 diff -Nur linux-4.6.2/arch/riscv/kernel/ptrace.c linux-4.6.2.riscv/arch/riscv/kernel/ptrace.c
6445 --- linux-4.6.2/arch/riscv/kernel/ptrace.c 1970-01-01 01:00:00.000000000 +0100
6446 +++ linux-4.6.2.riscv/arch/riscv/kernel/ptrace.c 2017-03-04 02:48:34.166888015 +0100
6448 +#include <asm/ptrace.h>
6449 +#include <asm/syscall.h>
6450 +#include <asm/thread_info.h>
6451 +#include <linux/ptrace.h>
6452 +#include <linux/elf.h>
6453 +#include <linux/regset.h>
6454 +#include <linux/tracehook.h>
6455 +#include <trace/events/syscalls.h>
6457 +enum riscv_regset {
6462 + * Get registers from task and ready the result for userspace.
6464 +static char *getregs(struct task_struct *child, struct pt_regs *uregs)
6466 + *uregs = *task_pt_regs(child);
6467 + return (char *)uregs;
6470 +/* Put registers back to task. */
6471 +static void putregs(struct task_struct *child, struct pt_regs *uregs)
6473 + struct pt_regs *regs = task_pt_regs(child);
6477 +static int riscv_gpr_get(struct task_struct *target,
6478 + const struct user_regset *regset,
6479 + unsigned int pos, unsigned int count,
6480 + void *kbuf, void __user *ubuf)
6482 + struct pt_regs regs;
6484 + getregs(target, ®s);
6486 + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, ®s, 0,
6490 +static int riscv_gpr_set(struct task_struct *target,
6491 + const struct user_regset *regset,
6492 + unsigned int pos, unsigned int count,
6493 + const void *kbuf, const void __user *ubuf)
6496 + struct pt_regs regs;
6498 + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, ®s, 0,
6503 + putregs(target, ®s);
6509 +static const struct user_regset riscv_user_regset[] = {
6511 + .core_note_type = NT_PRSTATUS,
6513 + .size = sizeof(elf_greg_t),
6514 + .align = sizeof(elf_greg_t),
6515 + .get = &riscv_gpr_get,
6516 + .set = &riscv_gpr_set,
6520 +static const struct user_regset_view riscv_user_native_view = {
6522 + .e_machine = EM_RISCV,
6523 + .regsets = riscv_user_regset,
6524 + .n = ARRAY_SIZE(riscv_user_regset),
6527 +const struct user_regset_view *task_user_regset_view(struct task_struct *task)
6529 + return &riscv_user_native_view;
6532 +void ptrace_disable(struct task_struct *child)
6534 + clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
6537 +long arch_ptrace(struct task_struct *child, long request,
6538 + unsigned long addr, unsigned long data)
6542 + switch (request) {
6544 + ret = ptrace_request(child, request, addr, data);
6551 +/* Allows PTRACE_SYSCALL to work. These are called from entry.S in
6552 + * {handle,ret_from}_syscall. */
6553 +void do_syscall_trace_enter(struct pt_regs *regs)
6555 + if (test_thread_flag(TIF_SYSCALL_TRACE)) {
6556 + if (tracehook_report_syscall_entry(regs))
6557 + syscall_set_nr(current, regs, -1);
6560 +#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
6561 + if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
6562 + trace_sys_enter(regs, syscall_get_nr(current, regs));
6566 +void do_syscall_trace_exit(struct pt_regs *regs)
6568 + if (test_thread_flag(TIF_SYSCALL_TRACE))
6569 + tracehook_report_syscall_exit(regs, 0);
6571 +#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
6572 + if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
6573 + trace_sys_exit(regs, regs->regs[0]);
6576 diff -Nur linux-4.6.2/arch/riscv/kernel/reset.c linux-4.6.2.riscv/arch/riscv/kernel/reset.c
6577 --- linux-4.6.2/arch/riscv/kernel/reset.c 1970-01-01 01:00:00.000000000 +0100
6578 +++ linux-4.6.2.riscv/arch/riscv/kernel/reset.c 2017-03-04 02:48:34.166888015 +0100
6580 +#include <linux/reboot.h>
6581 +#include <linux/export.h>
6582 +#include <asm/sbi.h>
6584 +void (*pm_power_off)(void) = machine_power_off;
6585 +EXPORT_SYMBOL(pm_power_off);
6587 +void machine_restart(char *cmd)
6591 +void machine_halt(void)
6595 +void machine_power_off(void)
6599 diff -Nur linux-4.6.2/arch/riscv/kernel/sbi-con.c linux-4.6.2.riscv/arch/riscv/kernel/sbi-con.c
6600 --- linux-4.6.2/arch/riscv/kernel/sbi-con.c 1970-01-01 01:00:00.000000000 +0100
6601 +++ linux-4.6.2.riscv/arch/riscv/kernel/sbi-con.c 2017-03-04 02:48:34.166888015 +0100
6603 +#include <linux/init.h>
6604 +#include <linux/console.h>
6605 +#include <linux/tty.h>
6606 +#include <linux/tty_flip.h>
6607 +#include <linux/tty_driver.h>
6608 +#include <linux/module.h>
6609 +#include <linux/interrupt.h>
6611 +#include <asm/sbi.h>
6613 +static DEFINE_SPINLOCK(sbi_tty_port_lock);
6614 +static struct tty_port sbi_tty_port;
6615 +static struct tty_driver *sbi_tty_driver;
6617 +irqreturn_t sbi_console_isr(void)
6619 + int ch = sbi_console_getchar();
6623 + spin_lock(&sbi_tty_port_lock);
6624 + tty_insert_flip_char(&sbi_tty_port, ch, TTY_NORMAL);
6625 + tty_flip_buffer_push(&sbi_tty_port);
6626 + spin_unlock(&sbi_tty_port_lock);
6628 + return IRQ_HANDLED;
6631 +static int sbi_tty_open(struct tty_struct *tty, struct file *filp)
6636 +static int sbi_tty_write(struct tty_struct *tty,
6637 + const unsigned char *buf, int count)
6639 + const unsigned char *end;
6641 + for (end = buf + count; buf < end; buf++) {
6642 + sbi_console_putchar(*buf);
6647 +static int sbi_tty_write_room(struct tty_struct *tty)
6649 + return 1024; /* arbitrary */
6652 +static const struct tty_operations sbi_tty_ops = {
6653 + .open = sbi_tty_open,
6654 + .write = sbi_tty_write,
6655 + .write_room = sbi_tty_write_room,
6659 +static void sbi_console_write(struct console *co, const char *buf, unsigned n)
6661 + for ( ; n > 0; n--, buf++) {
6663 + sbi_console_putchar('\r');
6664 + sbi_console_putchar(*buf);
6668 +static struct tty_driver *sbi_console_device(struct console *co, int *index)
6670 + *index = co->index;
6671 + return sbi_tty_driver;
6674 +static int sbi_console_setup(struct console *co, char *options)
6676 + return co->index != 0 ? -ENODEV : 0;
6679 +static struct console sbi_console = {
6680 + .name = "sbi_console",
6681 + .write = sbi_console_write,
6682 + .device = sbi_console_device,
6683 + .setup = sbi_console_setup,
6684 + .flags = CON_PRINTBUFFER,
6688 +static int __init sbi_console_init(void)
6692 + register_console(&sbi_console);
6694 + sbi_tty_driver = tty_alloc_driver(1,
6695 + TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV);
6696 + if (unlikely(IS_ERR(sbi_tty_driver)))
6697 + return PTR_ERR(sbi_tty_driver);
6699 + sbi_tty_driver->driver_name = "sbi";
6700 + sbi_tty_driver->name = "ttySBI";
6701 + sbi_tty_driver->major = TTY_MAJOR;
6702 + sbi_tty_driver->minor_start = 0;
6703 + sbi_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
6704 + sbi_tty_driver->subtype = SERIAL_TYPE_NORMAL;
6705 + sbi_tty_driver->init_termios = tty_std_termios;
6706 + tty_set_operations(sbi_tty_driver, &sbi_tty_ops);
6708 + tty_port_init(&sbi_tty_port);
6709 + tty_port_link_device(&sbi_tty_port, sbi_tty_driver, 0);
6711 + ret = tty_register_driver(sbi_tty_driver);
6712 + if (unlikely(ret))
6715 + /* Poll the console once, which will trigger future interrupts */
6716 + sbi_console_isr();
6721 + put_tty_driver(sbi_tty_driver);
6725 +static void __exit sbi_console_exit(void)
6727 + tty_unregister_driver(sbi_tty_driver);
6728 + put_tty_driver(sbi_tty_driver);
6731 +module_init(sbi_console_init);
6732 +module_exit(sbi_console_exit);
6734 +MODULE_DESCRIPTION("RISC-V SBI console driver");
6735 +MODULE_LICENSE("GPL");
6737 +#ifdef CONFIG_EARLY_PRINTK
6739 +static struct console early_console_dev __initdata = {
6741 + .write = sbi_console_write,
6742 + .flags = CON_PRINTBUFFER | CON_BOOT,
6746 +static int __init setup_early_printk(char *str)
6748 + if (early_console == NULL) {
6749 + early_console = &early_console_dev;
6750 + register_console(early_console);
6755 +early_param("earlyprintk", setup_early_printk);
6758 diff -Nur linux-4.6.2/arch/riscv/kernel/sbi.S linux-4.6.2.riscv/arch/riscv/kernel/sbi.S
6759 --- linux-4.6.2/arch/riscv/kernel/sbi.S 1970-01-01 01:00:00.000000000 +0100
6760 +++ linux-4.6.2.riscv/arch/riscv/kernel/sbi.S 2017-03-04 02:48:34.166888015 +0100
6762 +.globl sbi_hart_id; sbi_hart_id = -2048
6763 +.globl sbi_num_harts; sbi_num_harts = -2032
6764 +.globl sbi_query_memory; sbi_query_memory = -2016
6765 +.globl sbi_console_putchar; sbi_console_putchar = -2000
6766 +.globl sbi_console_getchar; sbi_console_getchar = -1984
6767 +.globl sbi_send_ipi; sbi_send_ipi = -1952
6768 +.globl sbi_clear_ipi; sbi_clear_ipi = -1936
6769 +.globl sbi_timebase; sbi_timebase = -1920
6770 +.globl sbi_shutdown; sbi_shutdown = -1904
6771 +.globl sbi_set_timer; sbi_set_timer = -1888
6772 +.globl sbi_mask_interrupt; sbi_mask_interrupt = -1872
6773 +.globl sbi_unmask_interrupt; sbi_unmask_interrupt = -1856
6774 +.globl sbi_remote_sfence_vm; sbi_remote_sfence_vm = -1840
6775 +.globl sbi_remote_sfence_vm_range; sbi_remote_sfence_vm_range = -1824
6776 +.globl sbi_remote_fence_i; sbi_remote_fence_i = -1808
6777 diff -Nur linux-4.6.2/arch/riscv/kernel/setup.c linux-4.6.2.riscv/arch/riscv/kernel/setup.c
6778 --- linux-4.6.2/arch/riscv/kernel/setup.c 1970-01-01 01:00:00.000000000 +0100
6779 +++ linux-4.6.2.riscv/arch/riscv/kernel/setup.c 2017-03-04 02:48:34.166888015 +0100
6781 +#include <linux/init.h>
6782 +#include <linux/mm.h>
6783 +#include <linux/memblock.h>
6784 +#include <linux/sched.h>
6785 +#include <linux/initrd.h>
6786 +#include <linux/console.h>
6787 +#include <linux/screen_info.h>
6789 +#include <asm/setup.h>
6790 +#include <asm/sections.h>
6791 +#include <asm/pgtable.h>
6792 +#include <asm/smp.h>
6793 +#include <asm/sbi.h>
6795 +#ifdef CONFIG_DUMMY_CONSOLE
6796 +struct screen_info screen_info = {
6797 + .orig_video_lines = 30,
6798 + .orig_video_cols = 80,
6799 + .orig_video_mode = 0,
6800 + .orig_video_ega_bx = 0,
6801 + .orig_video_isVGA = 1,
6802 + .orig_video_points = 8
6806 +static char __initdata command_line[COMMAND_LINE_SIZE];
6807 +#ifdef CONFIG_CMDLINE_BOOL
6808 +static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
6809 +#endif /* CONFIG_CMDLINE_BOOL */
6811 +unsigned long va_pa_offset;
6812 +unsigned long pfn_base;
6814 +#ifdef CONFIG_BLK_DEV_INITRD
6815 +static void __init setup_initrd(void)
6817 + extern char __initramfs_start[];
6818 + extern unsigned long __initramfs_size;
6819 + unsigned long size;
6821 + if (__initramfs_size > 0) {
6822 + initrd_start = (unsigned long)(&__initramfs_start);
6823 + initrd_end = initrd_start + __initramfs_size;
6826 + if (initrd_start >= initrd_end) {
6827 + printk(KERN_INFO "initrd not found or empty");
6830 + if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
6831 + printk(KERN_ERR "initrd extends beyond end of memory");
6835 + size = initrd_end - initrd_start;
6836 + memblock_reserve(__pa(initrd_start), size);
6837 + initrd_below_start_ok = 1;
6839 + printk(KERN_INFO "Initial ramdisk at: 0x%p (%lu bytes)\n",
6840 + (void *)(initrd_start), size);
6843 + printk(KERN_CONT " - disabling initrd\n");
6847 +#endif /* CONFIG_BLK_DEV_INITRD */
6849 +static resource_size_t __initdata mem_size;
6851 +/* Parse "mem=nn[KkMmGg]" */
6852 +static int __init early_mem(char *p)
6856 + mem_size = memparse(p, &p) & PMD_MASK;
6857 + if (mem_size == 0)
6861 +early_param("mem", early_mem);
6863 +static void __init reserve_boot_page_table(pte_t *table)
6867 + memblock_reserve(__pa(table), PAGE_SIZE);
6869 + for (i = 0; i < PTRS_PER_PTE; i++) {
6870 + if (pte_present(table[i]) && !pte_huge(table[i]))
6871 + reserve_boot_page_table(pfn_to_virt(pte_pfn(table[i])));
6875 +static void __init setup_bootmem(void)
6877 + unsigned long ret;
6878 + memory_block_info info;
6880 + ret = sbi_query_memory(0, &info);
6882 + BUG_ON((info.base & ~PMD_MASK) != 0);
6883 + BUG_ON((info.size & ~PMD_MASK) != 0);
6884 + pr_info("Available physical memory: %ldMB\n", info.size >> 20);
6886 + /* The kernel image is mapped at VA=PAGE_OFFSET and PA=info.base */
6887 + va_pa_offset = PAGE_OFFSET - info.base;
6888 + pfn_base = PFN_DOWN(info.base);
6890 + if ((mem_size != 0) && (mem_size < info.size)) {
6891 + memblock_enforce_memory_limit(mem_size);
6892 + info.size = mem_size;
6893 + pr_notice("Physical memory usage limited to %lluMB\n",
6894 + (unsigned long long)(mem_size >> 20));
6896 + set_max_mapnr(PFN_DOWN(info.size));
6897 + max_low_pfn = PFN_DOWN(info.base + info.size);
6899 +#ifdef CONFIG_BLK_DEV_INITRD
6901 +#endif /* CONFIG_BLK_DEV_INITRD */
6903 + memblock_reserve(info.base, __pa(_end) - info.base);
6904 + reserve_boot_page_table(pfn_to_virt(csr_read(sptbr)));
6905 + memblock_allow_resize();
6908 +void __init setup_arch(char **cmdline_p)
6910 +#ifdef CONFIG_CMDLINE_BOOL
6911 +#ifdef CONFIG_CMDLINE_OVERRIDE
6912 + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
6914 + if (builtin_cmdline[0] != '\0') {
6915 + /* Append bootloader command line to built-in */
6916 + strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
6917 + strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
6918 + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
6920 +#endif /* CONFIG_CMDLINE_OVERRIDE */
6921 +#endif /* CONFIG_CMDLINE_BOOL */
6922 + strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
6923 + *cmdline_p = command_line;
6925 + parse_early_param();
6927 + init_mm.start_code = (unsigned long) _stext;
6928 + init_mm.end_code = (unsigned long) _etext;
6929 + init_mm.end_data = (unsigned long) _edata;
6930 + init_mm.brk = (unsigned long) _end;
6938 +#ifdef CONFIG_DUMMY_CONSOLE
6939 + conswitchp = &dummy_con;
6942 diff -Nur linux-4.6.2/arch/riscv/kernel/signal.c linux-4.6.2.riscv/arch/riscv/kernel/signal.c
6943 --- linux-4.6.2/arch/riscv/kernel/signal.c 1970-01-01 01:00:00.000000000 +0100
6944 +++ linux-4.6.2.riscv/arch/riscv/kernel/signal.c 2017-03-04 02:48:34.166888015 +0100
6946 +#include <linux/signal.h>
6947 +#include <linux/uaccess.h>
6948 +#include <linux/syscalls.h>
6949 +#include <linux/tracehook.h>
6950 +#include <linux/linkage.h>
6952 +#include <asm/ucontext.h>
6953 +#include <asm/vdso.h>
6954 +#include <asm/switch_to.h>
6955 +#include <asm/csr.h>
6957 +#define DEBUG_SIG 0
6959 +struct rt_sigframe {
6960 + struct siginfo info;
6961 + struct ucontext uc;
6964 +static long restore_sigcontext(struct pt_regs *regs,
6965 + struct sigcontext __user *sc)
6967 + struct task_struct *task = current;
6969 + /* sc_regs is structured the same as the start of pt_regs */
6970 + err = __copy_from_user(regs, &sc->sc_regs, sizeof(sc->sc_regs));
6971 + err |= __copy_from_user(&task->thread.fstate, &sc->sc_fpregs,
6972 + sizeof(sc->sc_fpregs));
6974 + fstate_restore(task, regs);
6978 +SYSCALL_DEFINE0(rt_sigreturn)
6980 + struct pt_regs *regs = current_pt_regs();
6981 + struct rt_sigframe __user *frame;
6982 + struct task_struct *task;
6985 + /* Always make any pending restarted system calls return -EINTR */
6986 + current->restart_block.fn = do_no_restart_syscall;
6988 + frame = (struct rt_sigframe __user *)regs->sp;
6990 + if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
6993 + if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
6996 + set_current_blocked(&set);
6998 + if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
7001 + if (restore_altstack(&frame->uc.uc_stack))
7008 + if (show_unhandled_signals) {
7009 + pr_info_ratelimited("%s[%d]: bad frame in %s: "
7010 + "frame=%p pc=%p sp=%p\n",
7011 + task->comm, task_pid_nr(task), __func__,
7012 + frame, (void *)regs->sepc, (void *)regs->sp);
7014 + force_sig(SIGSEGV, task);
7018 +static long setup_sigcontext(struct sigcontext __user *sc,
7019 + struct pt_regs *regs)
7021 + struct task_struct *task = current;
7023 + /* sc_regs is structured the same as the start of pt_regs */
7024 + err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
7025 + fstate_save(task, regs);
7026 + err |= __copy_to_user(&sc->sc_fpregs, &task->thread.fstate,
7027 + sizeof(sc->sc_fpregs));
7031 +static inline void __user *get_sigframe(struct ksignal *ksig,
7032 + struct pt_regs *regs, size_t framesize)
7035 + /* Default to using normal stack */
7039 + * If we are on the alternate signal stack and would overflow it, don't.
7040 + * Return an always-bogus address instead so we will die with SIGSEGV.
7042 + if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
7043 + return (void __user __force *)(-1UL);
7045 + /* This is the X/Open sanctioned signal stack switching. */
7046 + sp = sigsp(sp, ksig) - framesize;
7048 + /* Align the stack frame. */
7051 + return (void __user *)sp;
7055 +static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
7056 + struct pt_regs *regs)
7058 + struct rt_sigframe __user *frame;
7061 + frame = get_sigframe(ksig, regs, sizeof(*frame));
7062 + if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
7065 + err |= copy_siginfo_to_user(&frame->info, &ksig->info);
7067 + /* Create the ucontext. */
7068 + err |= __put_user(0, &frame->uc.uc_flags);
7069 + err |= __put_user(NULL, &frame->uc.uc_link);
7070 + err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
7071 + err |= setup_sigcontext(&frame->uc.uc_mcontext, regs);
7072 + err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
7076 + /* Set up to return from userspace. */
7077 + regs->ra = (unsigned long)VDSO_SYMBOL(
7078 + current->mm->context.vdso, rt_sigreturn);
7081 + * Set up registers for signal handler.
7082 + * Registers that we don't modify keep the value they had from
7083 + * user-space at the time we took the signal.
7084 + * We always pass siginfo and mcontext, regardless of SA_SIGINFO,
7085 + * since some things rely on this (e.g. glibc's debug/segfault.c).
7087 + regs->sepc = (unsigned long)ksig->ka.sa.sa_handler;
7088 + regs->sp = (unsigned long)frame;
7089 + regs->a0 = ksig->sig; /* a0: signal number */
7090 + regs->a1 = (unsigned long)(&frame->info); /* a1: siginfo pointer */
7091 + regs->a2 = (unsigned long)(&frame->uc); /* a2: ucontext pointer */
7094 + pr_info("SIG deliver (%s:%d): sig=%d pc=%p ra=%p sp=%p\n",
7095 + current->comm, task_pid_nr(current), ksig->sig,
7096 + (void *)regs->sepc, (void *)regs->ra, frame);
7102 +static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
7104 + sigset_t *oldset = sigmask_to_save();
7107 + /* Are we from a system call? */
7108 + if (regs->scause == EXC_SYSCALL) {
7109 + /* If so, check system call restarting.. */
7110 + switch (regs->a0) {
7111 + case -ERESTART_RESTARTBLOCK:
7112 + case -ERESTARTNOHAND:
7113 + regs->a0 = -EINTR;
7116 + case -ERESTARTSYS:
7117 + if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
7118 + regs->a0 = -EINTR;
7122 + case -ERESTARTNOINTR:
7123 + regs->sepc -= 0x4;
7128 + /* Set up the stack frame */
7129 + ret = setup_rt_frame(ksig, oldset, regs);
7131 + signal_setup_done(ret, ksig, 0);
7134 +static void do_signal(struct pt_regs *regs)
7136 + struct ksignal ksig;
7138 + if (get_signal(&ksig)) {
7139 + /* Actually deliver the signal */
7140 + handle_signal(&ksig, regs);
7144 + /* Did we come from a system call? */
7145 + if (regs->scause == EXC_SYSCALL) {
7146 + /* Restart the system call - no handlers present */
7147 + switch (regs->a0) {
7148 + case -ERESTARTNOHAND:
7149 + case -ERESTARTSYS:
7150 + case -ERESTARTNOINTR:
7151 + regs->sepc -= 0x4;
7153 + case -ERESTART_RESTARTBLOCK:
7154 + regs->a7 = __NR_restart_syscall;
7155 + regs->sepc -= 0x4;
7160 + /* If there is no signal to deliver, we just put the saved
7162 + restore_saved_sigmask();
7166 + * notification of userspace execution resumption
7167 + * - triggered by the _TIF_WORK_MASK flags
7169 +asmlinkage void do_notify_resume(struct pt_regs *regs,
7170 + unsigned long thread_info_flags)
7172 + /* Handle pending signal delivery */
7173 + if (thread_info_flags & _TIF_SIGPENDING) {
7177 + if (thread_info_flags & _TIF_NOTIFY_RESUME) {
7178 + clear_thread_flag(TIF_NOTIFY_RESUME);
7179 + tracehook_notify_resume(regs);
7182 diff -Nur linux-4.6.2/arch/riscv/kernel/smpboot.c linux-4.6.2.riscv/arch/riscv/kernel/smpboot.c
7183 --- linux-4.6.2/arch/riscv/kernel/smpboot.c 1970-01-01 01:00:00.000000000 +0100
7184 +++ linux-4.6.2.riscv/arch/riscv/kernel/smpboot.c 2017-03-04 02:48:34.166888015 +0100
7186 +#include <linux/module.h>
7187 +#include <linux/init.h>
7188 +#include <linux/kernel.h>
7189 +#include <linux/mm.h>
7190 +#include <linux/sched.h>
7191 +#include <linux/kernel_stat.h>
7192 +#include <linux/notifier.h>
7193 +#include <linux/cpu.h>
7194 +#include <linux/percpu.h>
7195 +#include <linux/delay.h>
7196 +#include <linux/err.h>
7197 +#include <linux/irq.h>
7198 +#include <asm/mmu_context.h>
7199 +#include <asm/tlbflush.h>
7200 +#include <asm/sections.h>
7201 +#include <asm/sbi.h>
7203 +void *__cpu_up_stack_pointer[NR_CPUS];
7205 +void __init smp_prepare_boot_cpu(void)
7209 +void __init smp_prepare_cpus(unsigned int max_cpus)
7213 +void __init setup_smp(void)
7215 + int i, num_cpus = sbi_num_harts();
7217 + for (i = 0; i < min(num_cpus, NR_CPUS); i++) {
7218 + set_cpu_possible(i, true);
7219 + set_cpu_present(i, true);
7223 +int __cpu_up(unsigned int cpu, struct task_struct *tidle)
7225 + /* Signal cpu to start */
7226 + __cpu_up_stack_pointer[cpu] = task_stack_page(tidle) + THREAD_SIZE;
7228 + while (!cpu_online(cpu))
7234 +void __init smp_cpus_done(unsigned int max_cpus)
7239 + * C entry point for a secondary processor.
7241 +asmlinkage void __init smp_callin(void)
7243 + struct mm_struct *mm = &init_mm;
7245 + /* All kernel threads share the same mm context. */
7246 + atomic_inc(&mm->mm_count);
7247 + current->active_mm = mm;
7250 + init_clockevent();
7251 + notify_cpu_starting(smp_processor_id());
7252 + set_cpu_online(smp_processor_id(), 1);
7253 + local_flush_tlb_all();
7254 + local_irq_enable();
7255 + preempt_disable();
7256 + cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
7258 diff -Nur linux-4.6.2/arch/riscv/kernel/smp.c linux-4.6.2.riscv/arch/riscv/kernel/smp.c
7259 --- linux-4.6.2/arch/riscv/kernel/smp.c 1970-01-01 01:00:00.000000000 +0100
7260 +++ linux-4.6.2.riscv/arch/riscv/kernel/smp.c 2017-03-04 02:48:34.166888015 +0100
7262 +#include <linux/interrupt.h>
7263 +#include <linux/smp.h>
7264 +#include <linux/sched.h>
7266 +#include <asm/sbi.h>
7267 +#include <asm/tlbflush.h>
7268 +#include <asm/cacheflush.h>
7270 +/* A collection of single bit ipi messages. */
7272 + unsigned long bits ____cacheline_aligned;
7273 +} ipi_data[NR_CPUS] __cacheline_aligned;
7275 +enum ipi_message_type {
7281 +irqreturn_t handle_ipi(void)
7283 + unsigned long *pending_ipis = &ipi_data[smp_processor_id()].bits;
7284 + unsigned long ops;
7286 + /* Clear pending IPI */
7287 + if (!sbi_clear_ipi())
7290 + mb(); /* Order interrupt and bit testing. */
7291 + while ((ops = xchg(pending_ipis, 0)) != 0) {
7292 + mb(); /* Order bit clearing and data access. */
7294 + if (ops & (1 << IPI_RESCHEDULE))
7297 + if (ops & (1 << IPI_CALL_FUNC))
7298 + generic_smp_call_function_interrupt();
7300 + BUG_ON((ops >> IPI_MAX) != 0);
7302 + mb(); /* Order data access and bit testing. */
7305 + return IRQ_HANDLED;
7309 +send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation)
7314 + for_each_cpu(i, to_whom)
7315 + set_bit(operation, &ipi_data[i].bits);
7318 + for_each_cpu(i, to_whom)
7322 +void arch_send_call_function_ipi_mask(struct cpumask *mask)
7324 + send_ipi_message(mask, IPI_CALL_FUNC);
7327 +void arch_send_call_function_single_ipi(int cpu)
7329 + send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC);
7332 +static void ipi_stop(void *unused)
7335 + wait_for_interrupt();
7338 +void smp_send_stop(void)
7340 + on_each_cpu(ipi_stop, NULL, 1);
7343 +void smp_send_reschedule(int cpu)
7345 + send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
7347 diff -Nur linux-4.6.2/arch/riscv/kernel/stacktrace.c linux-4.6.2.riscv/arch/riscv/kernel/stacktrace.c
7348 --- linux-4.6.2/arch/riscv/kernel/stacktrace.c 1970-01-01 01:00:00.000000000 +0100
7349 +++ linux-4.6.2.riscv/arch/riscv/kernel/stacktrace.c 2017-03-04 02:48:34.166888015 +0100
7351 +#include <linux/export.h>
7352 +#include <linux/kallsyms.h>
7353 +#include <linux/sched.h>
7354 +#include <linux/stacktrace.h>
7356 +#ifdef CONFIG_FRAME_POINTER
7358 +struct stackframe {
7363 +static void notrace walk_stackframe(struct task_struct *task,
7364 + struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg)
7366 + unsigned long fp, sp, pc;
7369 + fp = GET_FP(regs);
7370 + sp = GET_USP(regs);
7371 + pc = GET_IP(regs);
7372 + } else if (task == NULL || task == current) {
7373 + const register unsigned long current_sp __asm__ ("sp");
7374 + fp = (unsigned long)__builtin_frame_address(0);
7376 + pc = (unsigned long)walk_stackframe;
7378 + /* task blocked in __switch_to */
7379 + fp = task->thread.s[0];
7380 + sp = task->thread.sp;
7381 + pc = task->thread.ra;
7385 + unsigned long low, high;
7386 + struct stackframe *frame;
7388 + if (unlikely(!__kernel_text_address(pc) || fn(pc, arg)))
7391 + /* Validate frame pointer */
7392 + low = sp + sizeof(struct stackframe);
7393 + high = ALIGN(sp, THREAD_SIZE);
7394 + if (unlikely(fp < low || fp > high || fp & 0x7))
7396 + /* Unwind stack frame */
7397 + frame = (struct stackframe *)fp - 1;
7400 + pc = frame->ra - 0x4;
7404 +#else /* !CONFIG_FRAME_POINTER */
7406 +static void notrace walk_stackframe(struct task_struct *task,
7407 + struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg)
7409 + unsigned long sp, pc;
7410 + unsigned long *ksp;
7413 + sp = GET_USP(regs);
7414 + pc = GET_IP(regs);
7415 + } else if (task == NULL || task == current) {
7416 + const register unsigned long current_sp __asm__ ("sp");
7418 + pc = (unsigned long)walk_stackframe;
7420 + /* task blocked in __switch_to */
7421 + sp = task->thread.sp;
7422 + pc = task->thread.ra;
7425 + if (unlikely(sp & 0x7))
7428 + ksp = (unsigned long *)sp;
7429 + while (!kstack_end(ksp)) {
7430 + if (__kernel_text_address(pc) && unlikely(fn(pc, arg))) {
7433 + pc = (*ksp++) - 0x4;
7437 +#endif /* CONFIG_FRAME_POINTER */
7440 +static bool print_trace_address(unsigned long pc, void *arg)
7446 +void show_stack(struct task_struct *task, unsigned long *sp)
7448 + printk("Call Trace:\n");
7449 + walk_stackframe(task, NULL, print_trace_address, NULL);
7453 +static bool save_wchan(unsigned long pc, void *arg)
7455 + if (!in_sched_functions(pc)) {
7456 + unsigned long *p = arg;
7463 +unsigned long get_wchan(struct task_struct *task)
7467 + if (likely(task && task != current && task->state != TASK_RUNNING)) {
7468 + walk_stackframe(task, NULL, save_wchan, &pc);
7474 +#ifdef CONFIG_STACKTRACE
7476 +static bool __save_trace(unsigned long pc, void *arg, bool nosched)
7478 + struct stack_trace *trace = arg;
7480 + if (unlikely(nosched && in_sched_functions(pc)))
7482 + if (unlikely(trace->skip > 0)) {
7487 + trace->entries[trace->nr_entries++] = pc;
7488 + return (trace->nr_entries >= trace->max_entries);
7491 +static bool save_trace(unsigned long pc, void *arg)
7493 + return __save_trace(pc, arg, false);
7497 + * Save stack-backtrace addresses into a stack_trace buffer.
7499 +void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
7501 + walk_stackframe(tsk, NULL, save_trace, trace);
7502 + if (trace->nr_entries < trace->max_entries)
7503 + trace->entries[trace->nr_entries++] = ULONG_MAX;
7505 +EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
7507 +void save_stack_trace(struct stack_trace *trace)
7509 + save_stack_trace_tsk(NULL, trace);
7511 +EXPORT_SYMBOL_GPL(save_stack_trace);
7513 +#endif /* CONFIG_STACKTRACE */
7514 diff -Nur linux-4.6.2/arch/riscv/kernel/syscall_table.c linux-4.6.2.riscv/arch/riscv/kernel/syscall_table.c
7515 --- linux-4.6.2/arch/riscv/kernel/syscall_table.c 1970-01-01 01:00:00.000000000 +0100
7516 +++ linux-4.6.2.riscv/arch/riscv/kernel/syscall_table.c 2017-03-04 02:48:34.166888015 +0100
7518 +#include <linux/syscalls.h>
7520 +#include <asm/syscalls.h>
7523 +#define __SYSCALL(nr, call) [nr] = (call),
7525 +void *sys_call_table[__NR_syscalls] = {
7526 +#include <asm/unistd.h>
7528 diff -Nur linux-4.6.2/arch/riscv/kernel/sys_riscv.c linux-4.6.2.riscv/arch/riscv/kernel/sys_riscv.c
7529 --- linux-4.6.2/arch/riscv/kernel/sys_riscv.c 1970-01-01 01:00:00.000000000 +0100
7530 +++ linux-4.6.2.riscv/arch/riscv/kernel/sys_riscv.c 2017-03-04 02:48:34.166888015 +0100
7532 +#include <linux/syscalls.h>
7533 +#include <asm/unistd.h>
7535 +SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
7536 + unsigned long, prot, unsigned long, flags,
7537 + unsigned long, fd, off_t, offset)
7539 + if (unlikely(offset & (~PAGE_MASK)))
7541 + return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
7544 +#ifndef CONFIG_64BIT
7545 +SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
7546 + unsigned long, prot, unsigned long, flags,
7547 + unsigned long, fd, off_t, offset)
7549 + /* Note that the shift for mmap2 is constant (12),
7550 + regardless of PAGE_SIZE */
7551 + if (unlikely(offset & (~PAGE_MASK >> 12)))
7553 + return sys_mmap_pgoff(addr, len, prot, flags, fd,
7554 + offset >> (PAGE_SHIFT - 12));
7556 +#endif /* !CONFIG_64BIT */
7558 +#ifdef CONFIG_RV_SYSRISCV_ATOMIC
7559 +SYSCALL_DEFINE4(sysriscv, unsigned long, cmd, unsigned long, arg1,
7560 + unsigned long, arg2, unsigned long, arg3)
7562 + unsigned long flags;
7563 + unsigned long prev;
7564 + unsigned int *ptr;
7568 + case RISCV_ATOMIC_CMPXCHG:
7569 + ptr = (unsigned int *)arg1;
7570 + if (!access_ok(VERIFY_WRITE, ptr, sizeof(unsigned int)))
7573 + preempt_disable();
7574 + raw_local_irq_save(flags);
7575 + err = __get_user(prev, ptr);
7576 + if (likely(!err && prev == arg2))
7577 + err = __put_user(arg3, ptr);
7578 + raw_local_irq_restore(flags);
7581 + return unlikely(err) ? err : prev;
7583 + case RISCV_ATOMIC_CMPXCHG64:
7584 + ptr = (unsigned int *)arg1;
7585 + if (!access_ok(VERIFY_WRITE, ptr, sizeof(unsigned long)))
7588 + preempt_disable();
7589 + raw_local_irq_save(flags);
7590 + err = __get_user(prev, ptr);
7591 + if (likely(!err && prev == arg2))
7592 + err = __put_user(arg3, ptr);
7593 + raw_local_irq_restore(flags);
7596 + return unlikely(err) ? err : prev;
7601 +#endif /* CONFIG_RV_SYSRISCV_ATOMIC */
7602 diff -Nur linux-4.6.2/arch/riscv/kernel/time.c linux-4.6.2.riscv/arch/riscv/kernel/time.c
7603 --- linux-4.6.2/arch/riscv/kernel/time.c 1970-01-01 01:00:00.000000000 +0100
7604 +++ linux-4.6.2.riscv/arch/riscv/kernel/time.c 2017-03-04 02:48:34.166888015 +0100
7606 +#include <linux/clocksource.h>
7607 +#include <linux/clockchips.h>
7608 +#include <linux/interrupt.h>
7609 +#include <linux/irq.h>
7610 +#include <linux/delay.h>
7612 +#include <asm/irq.h>
7613 +#include <asm/csr.h>
7614 +#include <asm/sbi.h>
7615 +#include <asm/delay.h>
7617 +unsigned long timebase;
7619 +static DEFINE_PER_CPU(struct clock_event_device, clock_event);
7621 +static int riscv_timer_set_next_event(unsigned long delta,
7622 + struct clock_event_device *evdev)
7624 + sbi_set_timer(get_cycles() + delta);
7628 +static int riscv_timer_set_oneshot(struct clock_event_device *evt)
7630 + /* no-op; only one mode */
7634 +static int riscv_timer_set_shutdown(struct clock_event_device *evt)
7636 + /* can't stop the clock! */
7640 +static cycle_t riscv_rdtime(struct clocksource *cs)
7642 + return get_cycles();
7645 +static struct clocksource riscv_clocksource = {
7646 + .name = "riscv_clocksource",
7648 + .read = riscv_rdtime,
7649 +#ifdef CONFIG_64BITS
7650 + .mask = CLOCKSOURCE_MASK(64),
7652 + .mask = CLOCKSOURCE_MASK(32),
7653 +#endif /* CONFIG_64BITS */
7654 + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
7657 +void riscv_timer_interrupt(void)
7659 + int cpu = smp_processor_id();
7660 + struct clock_event_device *evdev = &per_cpu(clock_event, cpu);
7661 + evdev->event_handler(evdev);
7664 +void __init init_clockevent(void)
7666 + int cpu = smp_processor_id();
7667 + struct clock_event_device *ce = &per_cpu(clock_event, cpu);
7669 + *ce = (struct clock_event_device){
7670 + .name = "riscv_timer_clockevent",
7671 + .features = CLOCK_EVT_FEAT_ONESHOT,
7673 + .cpumask = cpumask_of(cpu),
7674 + .set_next_event = riscv_timer_set_next_event,
7675 + .set_state_oneshot = riscv_timer_set_oneshot,
7676 + .set_state_shutdown = riscv_timer_set_shutdown,
7679 + clockevents_config_and_register(ce, sbi_timebase(), 100, 0x7fffffff);
7682 +void __init time_init(void)
7684 + timebase = sbi_timebase();
7685 + lpj_fine = timebase;
7686 + do_div(lpj_fine, HZ);
7688 + clocksource_register_hz(&riscv_clocksource, timebase);
7689 + init_clockevent();
7691 + /* Enable timer interrupts. */
7692 + csr_set(sie, SIE_STIE);
7694 diff -Nur linux-4.6.2/arch/riscv/kernel/traps.c linux-4.6.2.riscv/arch/riscv/kernel/traps.c
7695 --- linux-4.6.2/arch/riscv/kernel/traps.c 1970-01-01 01:00:00.000000000 +0100
7696 +++ linux-4.6.2.riscv/arch/riscv/kernel/traps.c 2017-03-04 02:48:34.166888015 +0100
7698 +#include <linux/kernel.h>
7699 +#include <linux/init.h>
7700 +#include <linux/sched.h>
7701 +#include <linux/signal.h>
7702 +#include <linux/kdebug.h>
7703 +#include <linux/uaccess.h>
7704 +#include <linux/mm.h>
7705 +#include <linux/module.h>
7707 +#include <asm/processor.h>
7708 +#include <asm/ptrace.h>
7709 +#include <asm/csr.h>
7711 +int show_unhandled_signals = 1;
7713 +extern asmlinkage void handle_exception(void);
7715 +static DEFINE_SPINLOCK(die_lock);
7717 +void die(struct pt_regs *regs, const char *str)
7719 + static int die_counter;
7724 + spin_lock_irq(&die_lock);
7725 + console_verbose();
7726 + bust_spinlocks(1);
7728 + pr_emerg("%s [#%d]\n", str, ++die_counter);
7732 + ret = notify_die(DIE_OOPS, str, regs, 0, regs->scause, SIGSEGV);
7734 + bust_spinlocks(0);
7735 + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
7736 + spin_unlock_irq(&die_lock);
7739 + if (in_interrupt())
7740 + panic("Fatal exception in interrupt");
7741 + if (panic_on_oops)
7742 + panic("Fatal exception");
7743 + if (ret != NOTIFY_STOP)
7747 +static inline void do_trap_siginfo(int signo, int code,
7748 + unsigned long addr, struct task_struct *tsk)
7752 + info.si_signo = signo;
7753 + info.si_errno = 0;
7754 + info.si_code = code;
7755 + info.si_addr = (void __user *)addr;
7756 + force_sig_info(signo, &info, tsk);
7759 +void do_trap(struct pt_regs *regs, int signo, int code,
7760 + unsigned long addr, struct task_struct *tsk)
7762 + if (show_unhandled_signals && unhandled_signal(tsk, signo)
7763 + && printk_ratelimit()) {
7764 + pr_info("%s[%d]: unhandled signal %d code 0x%x at 0x" REG_FMT,
7765 + tsk->comm, task_pid_nr(tsk), signo, code, addr);
7766 + print_vma_addr(KERN_CONT " in ", GET_IP(regs));
7771 + do_trap_siginfo(signo, code, addr, tsk);
7774 +static void do_trap_error(struct pt_regs *regs, int signo, int code,
7775 + unsigned long addr, const char *str)
7777 + if (user_mode(regs)) {
7778 + do_trap(regs, signo, code, addr, current);
7780 + if (!fixup_exception(regs))
7785 +#define DO_ERROR_INFO(name, signo, code, str) \
7786 +asmlinkage void name(struct pt_regs *regs) \
7788 + do_trap_error(regs, signo, code, regs->sepc, "Oops - " str); \
7791 +DO_ERROR_INFO(do_trap_unknown,
7792 + SIGILL, ILL_ILLTRP, "unknown exception");
7793 +DO_ERROR_INFO(do_trap_amo_misaligned,
7794 + SIGBUS, BUS_ADRALN, "AMO address misaligned");
7795 +DO_ERROR_INFO(do_trap_insn_misaligned,
7796 + SIGBUS, BUS_ADRALN, "instruction address misaligned");
7797 +DO_ERROR_INFO(do_trap_insn_illegal,
7798 + SIGILL, ILL_ILLOPC, "illegal instruction");
7800 +asmlinkage void do_trap_break(struct pt_regs *regs)
7802 +#ifdef CONFIG_GENERIC_BUG
7803 + if (!user_mode(regs)) {
7804 + enum bug_trap_type type;
7806 + type = report_bug(regs->sepc, regs);
7808 + case BUG_TRAP_TYPE_NONE:
7810 + case BUG_TRAP_TYPE_WARN:
7811 + regs->sepc += sizeof(bug_insn_t);
7813 + case BUG_TRAP_TYPE_BUG:
7814 + die(regs, "Kernel BUG");
7817 +#endif /* CONFIG_GENERIC_BUG */
7819 + do_trap_siginfo(SIGTRAP, TRAP_BRKPT, regs->sepc, current);
7820 + regs->sepc += 0x4;
7823 +#ifdef CONFIG_GENERIC_BUG
7824 +int is_valid_bugaddr(unsigned long pc)
7828 + if (pc < PAGE_OFFSET)
7830 + if (probe_kernel_address((bug_insn_t __user *)pc, insn))
7832 + return (insn == __BUG_INSN);
7834 +#endif /* CONFIG_GENERIC_BUG */
7836 +void __init trap_init(void)
7838 + /* Set sup0 scratch register to 0, indicating to exception vector
7839 + that we are presently executing in the kernel */
7840 + csr_write(sscratch, 0);
7841 + /* Set the exception vector address */
7842 + csr_write(stvec, &handle_exception);
7844 diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/.gitignore linux-4.6.2.riscv/arch/riscv/kernel/vdso/.gitignore
7845 --- linux-4.6.2/arch/riscv/kernel/vdso/.gitignore 1970-01-01 01:00:00.000000000 +0100
7846 +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/.gitignore 2017-03-04 02:48:34.166888015 +0100
7849 diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/Makefile linux-4.6.2.riscv/arch/riscv/kernel/vdso/Makefile
7850 --- linux-4.6.2/arch/riscv/kernel/vdso/Makefile 1970-01-01 01:00:00.000000000 +0100
7851 +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/Makefile 2017-03-04 02:48:34.166888015 +0100
7853 +# Derived from arch/{arm64,tile}/kernel/vdso/Makefile
7855 +obj-vdso := sigreturn.o
7858 +targets := $(obj-vdso) vdso.so vdso.so.dbg
7859 +obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
7861 +#ccflags-y := -shared -fno-common -fno-builtin
7862 +#ccflags-y += -nostdlib -Wl,-soname=linux-vdso.so.1 \
7863 + $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
7865 +CFLAGS_vdso.so = $(c_flags)
7866 +CFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
7867 + $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
7868 +CFLAGS_vdso_syms.o = -r
7872 +# We also create a special relocatable object that should mirror the symbol
7873 +# table and layout of the linked DSO. With ld -R we can then refer to
7874 +# these symbols in the kernel code rather than hand-coded addresses.
7875 +extra-y += vdso.lds vdso-syms.o
7876 +$(obj)/built-in.o: $(obj)/vdso-syms.o
7877 +$(obj)/built-in.o: ld_flags += -R $(obj)/vdso-syms.o
7879 +CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
7882 +$(obj)/vdso.o : $(obj)/vdso.so
7884 +# Link rule for the *.so file; *.lds must be first
7885 +$(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso)
7886 + $(call if_changed,vdsold)
7887 +$(obj)/vdso-syms.o: $(src)/vdso.lds $(obj-vdso)
7888 + $(call if_changed,vdsold)
7890 +# Strip rule for the *.so file
7891 +$(obj)/%.so: OBJCOPYFLAGS := -S
7892 +$(obj)/%.so: $(obj)/%.so.dbg FORCE
7893 + $(call if_changed,objcopy)
7895 +# Assembly rules for the *.S files
7896 +$(obj-vdso): %.o: %.S
7897 + $(call if_changed_dep,vdsoas)
7899 +# Actual build commands
7900 +quiet_cmd_vdsold = VDSOLD $@
7901 + cmd_vdsold = $(CC) $(c_flags) -nostdlib $(CFLAGS_$(@F)) -Wl,-n -Wl,-T $^ -o $@
7902 +quiet_cmd_vdsoas = VDSOAS $@
7903 + cmd_vdsoas = $(CC) $(a_flags) -c -o $@ $<
7905 +# Install commands for the unstripped file
7906 +quiet_cmd_vdso_install = INSTALL $@
7907 + cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
7909 +vdso.so: $(obj)/vdso.so.dbg
7910 + @mkdir -p $(MODLIB)/vdso
7911 + $(call cmd,vdso_install)
7913 +vdso_install: vdso.so
7914 diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/sigreturn.S linux-4.6.2.riscv/arch/riscv/kernel/vdso/sigreturn.S
7915 --- linux-4.6.2/arch/riscv/kernel/vdso/sigreturn.S 1970-01-01 01:00:00.000000000 +0100
7916 +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/sigreturn.S 2017-03-04 02:48:34.166888015 +0100
7918 +#include <linux/linkage.h>
7919 +#include <asm/unistd.h>
7922 +ENTRY(__vdso_rt_sigreturn)
7925 + li a7, __NR_rt_sigreturn
7928 +ENDPROC(__vdso_rt_sigreturn)
7929 diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/vdso.lds.S linux-4.6.2.riscv/arch/riscv/kernel/vdso/vdso.lds.S
7930 --- linux-4.6.2/arch/riscv/kernel/vdso/vdso.lds.S 1970-01-01 01:00:00.000000000 +0100
7931 +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/vdso.lds.S 2017-03-04 02:48:34.166888015 +0100
7937 + . = SIZEOF_HEADERS;
7939 + .hash : { *(.hash) } :text
7940 + .gnu.hash : { *(.gnu.hash) }
7941 + .dynsym : { *(.dynsym) }
7942 + .dynstr : { *(.dynstr) }
7943 + .gnu.version : { *(.gnu.version) }
7944 + .gnu.version_d : { *(.gnu.version_d) }
7945 + .gnu.version_r : { *(.gnu.version_r) }
7947 + .note : { *(.note.*) } :text :note
7948 + .dynamic : { *(.dynamic) } :text :dynamic
7950 + .eh_frame_hdr : { *(.eh_frame_hdr) } :text :eh_frame_hdr
7951 + .eh_frame : { KEEP (*(.eh_frame)) } :text
7953 + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
7956 + * This linker script is used both with -r and with -shared.
7957 + * For the layouts to match, we need to skip more than enough
7958 + * space for the dynamic symbol table, etc. If this amount is
7959 + * insufficient, ld -shared will error; simply increase it here.
7962 + .text : { *(.text .text.*) } :text
7965 + *(.got.plt) *(.got)
7966 + *(.data .data.* .gnu.linkonce.d.*)
7968 + *(.bss .bss.* .gnu.linkonce.b.*)
7973 + * We must supply the ELF program headers explicitly to get just one
7974 + * PT_LOAD segment, and set the flags explicitly to make segments read-only.
7978 + text PT_LOAD FLAGS(5) FILEHDR PHDRS; /* PF_R|PF_X */
7979 + dynamic PT_DYNAMIC FLAGS(4); /* PF_R */
7980 + note PT_NOTE FLAGS(4); /* PF_R */
7981 + eh_frame_hdr PT_GNU_EH_FRAME;
7985 + * This controls what symbols we export from the DSO.
7991 + __vdso_rt_sigreturn;
7996 diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/vdso.S linux-4.6.2.riscv/arch/riscv/kernel/vdso/vdso.S
7997 --- linux-4.6.2/arch/riscv/kernel/vdso/vdso.S 1970-01-01 01:00:00.000000000 +0100
7998 +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/vdso.S 2017-03-04 02:48:34.166888015 +0100
8000 +#include <linux/init.h>
8001 +#include <linux/linkage.h>
8002 +#include <asm/page.h>
8004 + __PAGE_ALIGNED_DATA
8006 + .globl vdso_start, vdso_end
8009 + .incbin "arch/riscv/kernel/vdso/vdso.so"
8014 diff -Nur linux-4.6.2/arch/riscv/kernel/vdso.c linux-4.6.2.riscv/arch/riscv/kernel/vdso.c
8015 --- linux-4.6.2/arch/riscv/kernel/vdso.c 1970-01-01 01:00:00.000000000 +0100
8016 +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso.c 2017-03-04 02:48:34.166888015 +0100
8018 +#include <linux/mm.h>
8019 +#include <linux/slab.h>
8020 +#include <linux/binfmts.h>
8021 +#include <linux/err.h>
8023 +#include <asm/vdso.h>
8025 +extern char vdso_start[], vdso_end[];
8027 +static unsigned int vdso_pages;
8028 +static struct page **vdso_pagelist;
8031 + * The vDSO data page.
8034 + struct vdso_data data;
8035 + u8 page[PAGE_SIZE];
8036 +} vdso_data_store __page_aligned_data;
8037 +struct vdso_data *vdso_data = &vdso_data_store.data;
8039 +static int __init vdso_init(void)
8043 + vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
8044 + vdso_pagelist = kzalloc(sizeof(struct page *) * (vdso_pages + 1), GFP_KERNEL);
8045 + if (unlikely(vdso_pagelist == NULL)) {
8046 + pr_err("vdso: pagelist allocation failed\n");
8050 + for (i = 0; i < vdso_pages; i++) {
8052 + pg = virt_to_page(vdso_start + (i << PAGE_SHIFT));
8053 + ClearPageReserved(pg);
8054 + vdso_pagelist[i] = pg;
8056 + vdso_pagelist[i] = virt_to_page(vdso_data);
8060 +arch_initcall(vdso_init);
8062 +int arch_setup_additional_pages(struct linux_binprm *bprm,
8065 + struct mm_struct *mm = current->mm;
8066 + unsigned long vdso_base, vdso_len;
8069 + vdso_len = (vdso_pages + 1) << PAGE_SHIFT;
8071 + down_write(&mm->mmap_sem);
8072 + vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
8073 + if (unlikely(IS_ERR_VALUE(vdso_base))) {
8079 + * Put vDSO base into mm struct. We need to do this before calling
8080 + * install_special_mapping or the perf counter mmap tracking code
8081 + * will fail to recognise it as a vDSO (since arch_vma_name fails).
8083 + mm->context.vdso = (void *)vdso_base;
8085 + ret = install_special_mapping(mm, vdso_base, vdso_len,
8086 + (VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
8089 + if (unlikely(ret)) {
8090 + mm->context.vdso = NULL;
8094 + up_write(&mm->mmap_sem);
8098 +const char *arch_vma_name(struct vm_area_struct *vma)
8100 + if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso)) {
8107 + * Function stubs to prevent linker errors when AT_SYSINFO_EHDR is defined
8110 +int in_gate_area_no_mm(unsigned long addr)
8115 +int in_gate_area(struct mm_struct *mm, unsigned long addr)
8120 +struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
8124 diff -Nur linux-4.6.2/arch/riscv/kernel/vmlinux.lds.S linux-4.6.2.riscv/arch/riscv/kernel/vmlinux.lds.S
8125 --- linux-4.6.2/arch/riscv/kernel/vmlinux.lds.S 1970-01-01 01:00:00.000000000 +0100
8126 +++ linux-4.6.2.riscv/arch/riscv/kernel/vmlinux.lds.S 2017-03-04 02:48:34.166888015 +0100
8128 +#define LOAD_OFFSET PAGE_OFFSET
8129 +#include <asm/vmlinux.lds.h>
8130 +#include <asm/page.h>
8131 +#include <asm/cache.h>
8132 +#include <asm/thread_info.h>
8137 +jiffies = jiffies_64;
8141 + /* Beginning of code and text segment */
8146 + INIT_TEXT_SECTION(PAGE_SIZE)
8147 + INIT_DATA_SECTION(16)
8148 + /* we have to discard exit text and such at runtime, not link time */
8157 + PERCPU_SECTION(L1_CACHE_BYTES)
8173 + /* Start of data section */
8175 + RO_DATA_SECTION(PAGE_SIZE)
8176 + RW_DATA_SECTION(0x40, PAGE_SIZE, THREAD_SIZE)
8184 + /* End of data section */
8187 + BSS_SECTION(0x20, 0, 0x20)
8189 + EXCEPTION_TABLE(0x10)
8203 diff -Nur linux-4.6.2/arch/riscv/lib/ashldi3.c linux-4.6.2.riscv/arch/riscv/lib/ashldi3.c
8204 --- linux-4.6.2/arch/riscv/lib/ashldi3.c 1970-01-01 01:00:00.000000000 +0100
8205 +++ linux-4.6.2.riscv/arch/riscv/lib/ashldi3.c 2017-03-04 02:48:34.166888015 +0100
8207 +#include <linux/export.h>
8209 +#include "libgcc.h"
8211 +long long __ashldi3(long long u, word_type b)
8224 + w.s.high = (unsigned int) uu.s.low << -bm;
8226 + const unsigned int carries = (unsigned int) uu.s.low >> bm;
8228 + w.s.low = (unsigned int) uu.s.low << b;
8229 + w.s.high = ((unsigned int) uu.s.high << b) | carries;
8234 +EXPORT_SYMBOL(__ashldi3);
8235 diff -Nur linux-4.6.2/arch/riscv/lib/ashrdi3.c linux-4.6.2.riscv/arch/riscv/lib/ashrdi3.c
8236 --- linux-4.6.2/arch/riscv/lib/ashrdi3.c 1970-01-01 01:00:00.000000000 +0100
8237 +++ linux-4.6.2.riscv/arch/riscv/lib/ashrdi3.c 2017-03-04 02:48:34.166888015 +0100
8239 +#include <linux/export.h>
8241 +#include "libgcc.h"
8243 +long long __ashrdi3(long long u, word_type b)
8255 + /* w.s.high = 1..1 or 0..0 */
8258 + w.s.low = uu.s.high >> -bm;
8260 + const unsigned int carries = (unsigned int) uu.s.high << bm;
8262 + w.s.high = uu.s.high >> b;
8263 + w.s.low = ((unsigned int) uu.s.low >> b) | carries;
8268 +EXPORT_SYMBOL(__ashrdi3);
8269 diff -Nur linux-4.6.2/arch/riscv/lib/delay.c linux-4.6.2.riscv/arch/riscv/lib/delay.c
8270 --- linux-4.6.2/arch/riscv/lib/delay.c 1970-01-01 01:00:00.000000000 +0100
8271 +++ linux-4.6.2.riscv/arch/riscv/lib/delay.c 2017-03-04 02:48:34.166888015 +0100
8273 +#include <linux/delay.h>
8274 +#include <linux/param.h>
8275 +#include <linux/timex.h>
8276 +#include <linux/export.h>
8278 +void __delay(unsigned long cycles)
8280 + cycle_t t0 = get_cycles();
8281 + while ((unsigned long)(get_cycles() - t0) < cycles)
8285 +void udelay(unsigned long usecs)
8287 + __delay((unsigned long)(((u64)usecs * timebase) / 1000000UL));
8290 +EXPORT_SYMBOL(udelay);
8292 +void ndelay(unsigned long nsecs)
8294 + __delay((unsigned long)(((u64)nsecs * timebase) / 1000000000UL));
8296 +EXPORT_SYMBOL(ndelay);
8297 diff -Nur linux-4.6.2/arch/riscv/lib/libgcc.h linux-4.6.2.riscv/arch/riscv/lib/libgcc.h
8298 --- linux-4.6.2/arch/riscv/lib/libgcc.h 1970-01-01 01:00:00.000000000 +0100
8299 +++ linux-4.6.2.riscv/arch/riscv/lib/libgcc.h 2017-03-04 02:48:34.170888098 +0100
8301 +#ifndef __ASM_LIBGCC_H
8302 +#define __ASM_LIBGCC_H
8304 +#include <asm/byteorder.h>
8306 +typedef int word_type __attribute__ ((mode (__word__)));
8308 +#ifdef __BIG_ENDIAN
8312 +#elif defined(__LITTLE_ENDIAN)
8317 +#error I feel sick.
8321 + struct DWstruct s;
8325 +extern long long __ashldi3(long long u, word_type b);
8326 +extern long long __ashrdi3(long long u, word_type b);
8327 +extern word_type __cmpdi2(long long a, long long b);
8328 +extern long long __lshrdi3(long long u, word_type b);
8329 +extern long long __muldi3(long long u, long long v);
8330 +extern word_type __ucmpdi2(unsigned long long a, unsigned long long b);
8332 +#endif /* __ASM_LIBGCC_H */
8333 diff -Nur linux-4.6.2/arch/riscv/lib/lshrdi3.c linux-4.6.2.riscv/arch/riscv/lib/lshrdi3.c
8334 --- linux-4.6.2/arch/riscv/lib/lshrdi3.c 1970-01-01 01:00:00.000000000 +0100
8335 +++ linux-4.6.2.riscv/arch/riscv/lib/lshrdi3.c 2017-03-04 02:48:34.170888098 +0100
8337 +#include <linux/export.h>
8339 +#include "libgcc.h"
8341 +long long __lshrdi3(long long u, word_type b)
8354 + w.s.low = (unsigned int) uu.s.high >> -bm;
8356 + const unsigned int carries = (unsigned int) uu.s.high << bm;
8358 + w.s.high = (unsigned int) uu.s.high >> b;
8359 + w.s.low = ((unsigned int) uu.s.low >> b) | carries;
8364 +EXPORT_SYMBOL(__lshrdi3);
8365 diff -Nur linux-4.6.2/arch/riscv/lib/Makefile linux-4.6.2.riscv/arch/riscv/lib/Makefile
8366 --- linux-4.6.2/arch/riscv/lib/Makefile 1970-01-01 01:00:00.000000000 +0100
8367 +++ linux-4.6.2.riscv/arch/riscv/lib/Makefile 2017-03-04 02:48:34.166888015 +0100
8369 +lib-y := delay.o memcpy.o memset.o uaccess.o
8371 +ifeq ($(CONFIG_64BIT),)
8372 +lib-y += ashldi3.o ashrdi3.o lshrdi3.o
8374 diff -Nur linux-4.6.2/arch/riscv/lib/memcpy.S linux-4.6.2.riscv/arch/riscv/lib/memcpy.S
8375 --- linux-4.6.2/arch/riscv/lib/memcpy.S 1970-01-01 01:00:00.000000000 +0100
8376 +++ linux-4.6.2.riscv/arch/riscv/lib/memcpy.S 2017-03-04 02:48:34.170888098 +0100
8378 +#include <linux/linkage.h>
8379 +#include <asm/asm.h>
8381 +/* void *memcpy(void *, const void *, size_t) */
8383 + move t6, a0 /* Preserve return value */
8385 + /* Defer to byte-oriented copy for small sizes */
8388 + /* Use word-oriented copy only if low-order bits match */
8389 + andi a3, t6, SZREG-1
8390 + andi a4, a1, SZREG-1
8393 + beqz a3, 2f /* Skip if already aligned */
8394 + /* Round to nearest double word-aligned address
8395 + greater than or equal to start address */
8396 + andi a3, a1, ~(SZREG-1)
8397 + addi a3, a3, SZREG
8398 + /* Handle initial misalignment */
8406 + sub a2, a2, a4 /* Update count */
8409 + andi a4, a2, ~((16*SZREG)-1)
8414 + REG_L a5, SZREG(a1)
8415 + REG_L a6, 2*SZREG(a1)
8416 + REG_L a7, 3*SZREG(a1)
8417 + REG_L t0, 4*SZREG(a1)
8418 + REG_L t1, 5*SZREG(a1)
8419 + REG_L t2, 6*SZREG(a1)
8420 + REG_L t3, 7*SZREG(a1)
8421 + REG_L t4, 8*SZREG(a1)
8422 + REG_L t5, 9*SZREG(a1)
8424 + REG_S a5, SZREG(t6)
8425 + REG_S a6, 2*SZREG(t6)
8426 + REG_S a7, 3*SZREG(t6)
8427 + REG_S t0, 4*SZREG(t6)
8428 + REG_S t1, 5*SZREG(t6)
8429 + REG_S t2, 6*SZREG(t6)
8430 + REG_S t3, 7*SZREG(t6)
8431 + REG_S t4, 8*SZREG(t6)
8432 + REG_S t5, 9*SZREG(t6)
8433 + REG_L a4, 10*SZREG(a1)
8434 + REG_L a5, 11*SZREG(a1)
8435 + REG_L a6, 12*SZREG(a1)
8436 + REG_L a7, 13*SZREG(a1)
8437 + REG_L t0, 14*SZREG(a1)
8438 + REG_L t1, 15*SZREG(a1)
8439 + addi a1, a1, 16*SZREG
8440 + REG_S a4, 10*SZREG(t6)
8441 + REG_S a5, 11*SZREG(t6)
8442 + REG_S a6, 12*SZREG(t6)
8443 + REG_S a7, 13*SZREG(t6)
8444 + REG_S t0, 14*SZREG(t6)
8445 + REG_S t1, 15*SZREG(t6)
8446 + addi t6, t6, 16*SZREG
8448 + andi a2, a2, (16*SZREG)-1 /* Update count */
8451 + /* Handle trailing misalignment */
8463 diff -Nur linux-4.6.2/arch/riscv/lib/memset.S linux-4.6.2.riscv/arch/riscv/lib/memset.S
8464 --- linux-4.6.2/arch/riscv/lib/memset.S 1970-01-01 01:00:00.000000000 +0100
8465 +++ linux-4.6.2.riscv/arch/riscv/lib/memset.S 2017-03-04 02:48:34.170888098 +0100
8467 +#include <linux/linkage.h>
8468 +#include <asm/asm.h>
8470 +/* void *memset(void *, int, size_t) */
8472 + move t0, a0 /* Preserve return value */
8474 + /* Defer to byte-oriented fill for small sizes */
8478 + /* Round to nearest XLEN-aligned address
8479 + greater than or equal to start address */
8480 + addi a3, t0, SZREG-1
8481 + andi a3, a3, ~(SZREG-1)
8482 + beq a3, t0, 2f /* Skip if already aligned */
8483 + /* Handle initial misalignment */
8489 + sub a2, a2, a4 /* Update count */
8491 +2: /* Duff's device with 32 XLEN stores per iteration */
8492 + /* Broadcast value into all bytes */
8498 +#ifdef CONFIG_64BIT
8503 + /* Calculate end address */
8504 + andi a4, a2, ~(SZREG-1)
8507 + andi a4, a4, 31*SZREG /* Calculate remainder */
8508 + beqz a4, 3f /* Shortcut if no remainder */
8510 + addi a4, a4, 32*SZREG /* Calculate initial offset */
8512 + /* Adjust start address with offset */
8515 + /* Jump into loop body */
8516 + /* Assumes 32-bit instruction lengths */
8518 +#ifdef CONFIG_64BIT
8525 + REG_S a1, SZREG(t0)
8526 + REG_S a1, 2*SZREG(t0)
8527 + REG_S a1, 3*SZREG(t0)
8528 + REG_S a1, 4*SZREG(t0)
8529 + REG_S a1, 5*SZREG(t0)
8530 + REG_S a1, 6*SZREG(t0)
8531 + REG_S a1, 7*SZREG(t0)
8532 + REG_S a1, 8*SZREG(t0)
8533 + REG_S a1, 9*SZREG(t0)
8534 + REG_S a1, 10*SZREG(t0)
8535 + REG_S a1, 11*SZREG(t0)
8536 + REG_S a1, 12*SZREG(t0)
8537 + REG_S a1, 13*SZREG(t0)
8538 + REG_S a1, 14*SZREG(t0)
8539 + REG_S a1, 15*SZREG(t0)
8540 + REG_S a1, 16*SZREG(t0)
8541 + REG_S a1, 17*SZREG(t0)
8542 + REG_S a1, 18*SZREG(t0)
8543 + REG_S a1, 19*SZREG(t0)
8544 + REG_S a1, 20*SZREG(t0)
8545 + REG_S a1, 21*SZREG(t0)
8546 + REG_S a1, 22*SZREG(t0)
8547 + REG_S a1, 23*SZREG(t0)
8548 + REG_S a1, 24*SZREG(t0)
8549 + REG_S a1, 25*SZREG(t0)
8550 + REG_S a1, 26*SZREG(t0)
8551 + REG_S a1, 27*SZREG(t0)
8552 + REG_S a1, 28*SZREG(t0)
8553 + REG_S a1, 29*SZREG(t0)
8554 + REG_S a1, 30*SZREG(t0)
8555 + REG_S a1, 31*SZREG(t0)
8556 + addi t0, t0, 32*SZREG
8558 + andi a2, a2, SZREG-1 /* Update count */
8561 + /* Handle trailing misalignment */
8571 diff -Nur linux-4.6.2/arch/riscv/lib/uaccess.S linux-4.6.2.riscv/arch/riscv/lib/uaccess.S
8572 --- linux-4.6.2/arch/riscv/lib/uaccess.S 1970-01-01 01:00:00.000000000 +0100
8573 +++ linux-4.6.2.riscv/arch/riscv/lib/uaccess.S 2017-03-04 02:48:34.170888098 +0100
8575 +#include <linux/linkage.h>
8576 +#include <asm/asm.h>
8577 +#include <asm/csr.h>
8580 + .macro fixup op reg addr lbl
8584 + .section __ex_table,"a"
8592 +#ifdef CONFIG_RV_PUM
8593 + /* Enable access to user memory */
8599 + /* Use word-oriented copy only if low-order bits match */
8600 + andi t0, a0, SZREG-1
8601 + andi t1, a1, SZREG-1
8604 + addi t0, a1, SZREG-1
8605 + andi t1, a3, ~(SZREG-1)
8606 + andi t0, t0, ~(SZREG-1)
8607 + /* a3: terminal address of source region
8608 + * t0: lowest XLEN-aligned address in source
8609 + * t1: highest XLEN-aligned address in source
8614 + fixup REG_L, t2, (a1), 10f
8615 + fixup REG_S, t2, (a0), 10f
8616 + addi a1, a1, SZREG
8617 + addi a0, a0, SZREG
8623 +#ifdef CONFIG_RV_PUM
8624 + /* Disable access to user memory */
8629 +4: /* Edge case: unalignment */
8630 + fixup lbu, t2, (a1), 10f
8631 + fixup sb, t2, (a0), 10f
8636 +5: /* Edge case: remainder */
8637 + fixup lbu, t2, (a1), 10f
8638 + fixup sb, t2, (a0), 10f
8643 +ENDPROC(__copy_user)
8646 +ENTRY(__clear_user)
8648 +#ifdef CONFIG_RV_PUM
8649 + /* Enable access to user memory */
8655 + addi t0, a0, SZREG-1
8656 + andi t1, a3, ~(SZREG-1)
8657 + andi t0, t0, ~(SZREG-1)
8658 + /* a3: terminal address of target region
8659 + * t0: lowest doubleword-aligned address in target region
8660 + * t1: highest doubleword-aligned address in target region
8665 + fixup REG_S, zero, (a0), 10f
8666 + addi a0, a0, SZREG
8672 +#ifdef CONFIG_RV_PUM
8673 + /* Disable access to user memory */
8678 +4: /* Edge case: unalignment */
8679 + fixup sb, zero, (a0), 10f
8683 +5: /* Edge case: remainder */
8684 + fixup sb, zero, (a0), 10f
8688 +ENDPROC(__clear_user)
8690 + .section .fixup,"ax"
8693 +#ifdef CONFIG_RV_PUM
8694 + /* Disable access to user memory */
8700 diff -Nur linux-4.6.2/arch/riscv/Makefile linux-4.6.2.riscv/arch/riscv/Makefile
8701 --- linux-4.6.2/arch/riscv/Makefile 1970-01-01 01:00:00.000000000 +0100
8702 +++ linux-4.6.2.riscv/arch/riscv/Makefile 2017-03-04 02:48:34.162887952 +0100
8704 +# BK Id: %F% %I% %G% %U% %#%
8706 +# This file is included by the global makefile so that you can add your own
8707 +# architecture-specific flags and dependencies. Remember to do have actions
8708 +# for "archclean" and "archdep" for cleaning up and making dependencies for
8709 +# this architecture
8711 +# This file is subject to the terms and conditions of the GNU General Public
8712 +# License. See the file "COPYING" in the main directory of this archive
8713 +# for more details.
8715 +# Copyright (C) 1994 by Linus Torvalds
8716 +# Modifications for the RISC-V architecture:
8717 +# Quan Nguyen <quannguyen@eecs.berkeley.edu>
8718 +# Albert Ou <a_ou@eecs.berkeley.edu>
8721 +# arch/score/Makefile
8724 +OBJCOPYFLAGS := -O binary
8727 +ifeq ($(ARCH),riscv)
8728 + KBUILD_DEFCONFIG = riscv64_spike
8730 + KBUILD_DEFCONFIG = $(ARCH)_spike
8734 +ifeq ($(CONFIG_64BIT),y)
8736 + UTS_MACHINE := riscv64
8738 + KBUILD_CFLAGS += -mabi=lp64
8739 + KBUILD_AFLAGS += -mabi=lp64
8740 + KBUILD_MARCH = rv64im
8741 + LDFLAGS += -melf64lriscv
8744 + UTS_MACHINE := riscv32
8746 + KBUILD_CFLAGS += -mabi=ilp32
8747 + KBUILD_AFLAGS += -mabi=ilp32
8748 + KBUILD_MARCH = rv32im
8749 + LDFLAGS += -melf32lriscv
8752 +ifeq ($(CONFIG_RV_ATOMIC),y)
8753 + KBUILD_RV_ATOMIC = a
8756 +KBUILD_CFLAGS += -Wall
8758 +ifeq ($(CONFIG_RVC),y)
8762 +KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)fd$(KBUILD_RVC)
8764 +KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)$(KBUILD_RVC)
8765 +KBUILD_CFLAGS += -mno-save-restore
8767 +head-y := arch/riscv/kernel/head.o
8769 +core-y += arch/riscv/kernel/ arch/riscv/mm/
8771 +libs-y += arch/riscv/lib/
8774 diff -Nur linux-4.6.2/arch/riscv/mm/extable.c linux-4.6.2.riscv/arch/riscv/mm/extable.c
8775 --- linux-4.6.2/arch/riscv/mm/extable.c 1970-01-01 01:00:00.000000000 +0100
8776 +++ linux-4.6.2.riscv/arch/riscv/mm/extable.c 2017-03-04 02:48:34.170888098 +0100
8778 +#include <linux/module.h>
8779 +#include <linux/uaccess.h>
8781 +int fixup_exception(struct pt_regs *regs)
8783 + const struct exception_table_entry *fixup;
8785 + fixup = search_exception_tables(regs->sepc);
8787 + regs->sepc = fixup->fixup;
8792 diff -Nur linux-4.6.2/arch/riscv/mm/fault.c linux-4.6.2.riscv/arch/riscv/mm/fault.c
8793 --- linux-4.6.2/arch/riscv/mm/fault.c 1970-01-01 01:00:00.000000000 +0100
8794 +++ linux-4.6.2.riscv/arch/riscv/mm/fault.c 2017-03-04 02:48:34.170888098 +0100
8796 +#include <linux/mm.h>
8797 +#include <linux/kernel.h>
8798 +#include <linux/interrupt.h>
8799 +#include <linux/perf_event.h>
8800 +#include <linux/signal.h>
8801 +#include <linux/uaccess.h>
8803 +#include <asm/pgalloc.h>
8804 +#include <asm/ptrace.h>
8805 +#include <asm/uaccess.h>
8808 + * This routine handles page faults. It determines the address and the
8809 + * problem, and then passes it off to one of the appropriate routines.
8811 +asmlinkage void do_page_fault(struct pt_regs *regs)
8813 + struct task_struct *tsk;
8814 + struct vm_area_struct *vma;
8815 + struct mm_struct *mm;
8816 + unsigned long addr, cause;
8817 + unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
8818 + int fault, code = SEGV_MAPERR;
8820 + cause = regs->scause;
8821 + addr = regs->sbadaddr;
8827 + * Fault-in kernel-space virtual memory on-demand.
8828 + * The 'reference' page table is init_mm.pgd.
8830 + * NOTE! We MUST NOT take any locks for this case. We may
8831 + * be in an interrupt or a critical region, and should
8832 + * only copy the information from the master page table,
8835 + if (unlikely((addr >= VMALLOC_START) && (addr <= VMALLOC_END)))
8836 + goto vmalloc_fault;
8838 + /* Enable interrupts if they were enabled in the parent context. */
8839 + if (likely(regs->sstatus & SR_PIE))
8840 + local_irq_enable();
8843 + * If we're in an interrupt, have no user context, or are running
8844 + * in an atomic region, then we must not take the fault.
8846 + if (unlikely(faulthandler_disabled() || !mm))
8849 + if (user_mode(regs))
8850 + flags |= FAULT_FLAG_USER;
8852 + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
8855 + down_read(&mm->mmap_sem);
8856 + vma = find_vma(mm, addr);
8857 + if (unlikely(!vma))
8859 + if (likely(vma->vm_start <= addr))
8861 + if (unlikely(!(vma->vm_flags & VM_GROWSDOWN)))
8863 + if (unlikely(expand_stack(vma, addr)))
8867 + * Ok, we have a good vm_area for this memory access, so
8868 + * we can handle it.
8871 + code = SEGV_ACCERR;
8874 + case EXC_INST_ACCESS:
8875 + if (!(vma->vm_flags & VM_EXEC))
8878 + case EXC_LOAD_ACCESS:
8879 + if (!(vma->vm_flags & VM_READ))
8882 + case EXC_STORE_ACCESS:
8883 + if (!(vma->vm_flags & VM_WRITE))
8885 + flags |= FAULT_FLAG_WRITE;
8888 + panic("%s: unhandled cause %lu", __func__, cause);
8892 + * If for any reason at all we could not handle the fault,
8893 + * make sure we exit gracefully rather than endlessly redo
8896 + fault = handle_mm_fault(mm, vma, addr, flags);
8899 + * If we need to retry but a fatal signal is pending, handle the
8900 + * signal first. We do not need to release the mmap_sem because it
8901 + * would already be released in __lock_page_or_retry in mm/filemap.c.
8903 + if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(tsk))
8906 + if (unlikely(fault & VM_FAULT_ERROR)) {
8907 + if (fault & VM_FAULT_OOM)
8908 + goto out_of_memory;
8909 + else if (fault & VM_FAULT_SIGBUS)
8915 + * Major/minor page fault accounting is only done on the
8916 + * initial attempt. If we go through a retry, it is extremely
8917 + * likely that the page will be found in page cache at that point.
8919 + if (flags & FAULT_FLAG_ALLOW_RETRY) {
8920 + if (fault & VM_FAULT_MAJOR) {
8922 + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, addr);
8925 + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, addr);
8927 + if (fault & VM_FAULT_RETRY) {
8929 + * Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
8932 + flags &= ~(FAULT_FLAG_ALLOW_RETRY);
8933 + flags |= FAULT_FLAG_TRIED;
8936 + * No need to up_read(&mm->mmap_sem) as we would
8937 + * have already released it in __lock_page_or_retry
8938 + * in mm/filemap.c.
8944 + up_read(&mm->mmap_sem);
8948 + * Something tried to access memory that isn't in our memory map.
8949 + * Fix it, but check if it's kernel or user first.
8952 + up_read(&mm->mmap_sem);
8953 + /* User mode accesses just cause a SIGSEGV */
8954 + if (user_mode(regs)) {
8955 + do_trap(regs, SIGSEGV, code, addr, tsk);
8960 + /* Are we prepared to handle this kernel fault? */
8961 + if (fixup_exception(regs)) {
8966 + * Oops. The kernel tried to access some bad page. We'll have to
8967 + * terminate things with extreme prejudice.
8969 + bust_spinlocks(1);
8970 + pr_alert("Unable to handle kernel %s at virtual address " REG_FMT "\n",
8971 + (addr < PAGE_SIZE) ? "NULL pointer dereference" :
8972 + "paging request", addr);
8973 + die(regs, "Oops");
8977 + * We ran out of memory, call the OOM killer, and return the userspace
8978 + * (which will retry the fault, or kill us if we got oom-killed).
8981 + up_read(&mm->mmap_sem);
8982 + if (!user_mode(regs))
8984 + pagefault_out_of_memory();
8988 + up_read(&mm->mmap_sem);
8989 + /* Kernel mode? Handle exceptions or die */
8990 + if (!user_mode(regs))
8992 + do_trap(regs, SIGBUS, BUS_ADRERR, addr, tsk);
8997 + pgd_t *pgd, *pgd_k;
8998 + pud_t *pud, *pud_k;
8999 + pmd_t *pmd, *pmd_k;
9003 + if (user_mode(regs))
9007 + * Synchronize this task's top level page-table
9008 + * with the 'reference' page table.
9010 + * Do _not_ use "tsk->active_mm->pgd" here.
9011 + * We might be inside an interrupt in the middle
9012 + * of a task switch.
9014 + index = pgd_index(addr);
9015 + pgd = (pgd_t *)pfn_to_virt(csr_read(sptbr)) + index;
9016 + pgd_k = init_mm.pgd + index;
9018 + if (!pgd_present(*pgd_k))
9020 + set_pgd(pgd, *pgd_k);
9022 + pud = pud_offset(pgd, addr);
9023 + pud_k = pud_offset(pgd_k, addr);
9024 + if (!pud_present(*pud_k))
9027 + /* Since the vmalloc area is global, it is unnecessary
9028 + to copy individual PTEs */
9029 + pmd = pmd_offset(pud, addr);
9030 + pmd_k = pmd_offset(pud_k, addr);
9031 + if (!pmd_present(*pmd_k))
9033 + set_pmd(pmd, *pmd_k);
9035 + /* Make sure the actual PTE exists as well to
9036 + * catch kernel vmalloc-area accesses to non-mapped
9037 + * addresses. If we don't do this, this will just
9038 + * silently loop forever.
9040 + pte_k = pte_offset_kernel(pmd_k, addr);
9041 + if (!pte_present(*pte_k))
9046 diff -Nur linux-4.6.2/arch/riscv/mm/init.c linux-4.6.2.riscv/arch/riscv/mm/init.c
9047 --- linux-4.6.2/arch/riscv/mm/init.c 1970-01-01 01:00:00.000000000 +0100
9048 +++ linux-4.6.2.riscv/arch/riscv/mm/init.c 2017-03-04 02:48:34.170888098 +0100
9050 +#include <linux/init.h>
9051 +#include <linux/mm.h>
9052 +#include <linux/bootmem.h>
9053 +#include <linux/initrd.h>
9054 +#include <linux/memblock.h>
9055 +#include <linux/swap.h>
9057 +#include <asm/tlbflush.h>
9058 +#include <asm/sections.h>
9059 +#include <asm/pgtable.h>
9060 +#include <asm/io.h>
9063 +static void __init zone_sizes_init(void)
9065 + unsigned long zones_size[MAX_NR_ZONES];
9068 + memset(zones_size, 0, sizeof(zones_size));
9070 + for_each_online_node(nid) {
9072 + unsigned long start_pfn, end_pfn;
9074 + pgdat = NODE_DATA(nid);
9075 + start_pfn = pgdat->bdata->node_min_pfn;
9076 + end_pfn = pgdat->bdata->node_low_pfn;
9077 + memblock_add_node(start_pfn,
9078 + PFN_PHYS(end_pfn - start_pfn), nid);
9081 + zones_size[ZONE_NORMAL] = pfn_base + max_mapnr;
9082 + free_area_init_nodes(zones_size);
9085 +static void __init zone_sizes_init(void)
9087 + unsigned long zones_size[MAX_NR_ZONES];
9089 + memset(zones_size, 0, sizeof(zones_size));
9090 + memblock_add_node(PFN_PHYS(pfn_base), PFN_PHYS(max_mapnr), 0);
9091 + zones_size[ZONE_NORMAL] = pfn_base + max_mapnr;
9092 + free_area_init_nodes(zones_size);
9094 +#endif /* CONFIG_NUMA */
9096 +void setup_zero_page(void)
9098 + memset((void *)empty_zero_page, 0, PAGE_SIZE);
9101 +void __init paging_init(void)
9103 + init_mm.pgd = (pgd_t *)pfn_to_virt(csr_read(sptbr));
9105 + setup_zero_page();
9106 + local_flush_tlb_all();
9107 + zone_sizes_init();
9110 +void __init mem_init(void)
9112 +#ifdef CONFIG_FLATMEM
9114 +#endif /* CONFIG_FLATMEM */
9116 + high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
9117 + free_all_bootmem();
9119 + mem_init_print_info(NULL);
9122 +void free_initmem(void)
9124 + free_initmem_default(0);
9127 +#ifdef CONFIG_BLK_DEV_INITRD
9128 +void free_initrd_mem(unsigned long start, unsigned long end)
9130 +// free_reserved_area(start, end, 0, "initrd");
9132 +#endif /* CONFIG_BLK_DEV_INITRD */
9134 diff -Nur linux-4.6.2/arch/riscv/mm/ioremap.c linux-4.6.2.riscv/arch/riscv/mm/ioremap.c
9135 --- linux-4.6.2/arch/riscv/mm/ioremap.c 1970-01-01 01:00:00.000000000 +0100
9136 +++ linux-4.6.2.riscv/arch/riscv/mm/ioremap.c 2017-03-04 02:48:34.170888098 +0100
9138 +#include <linux/export.h>
9139 +#include <linux/mm.h>
9140 +#include <linux/vmalloc.h>
9141 +#include <linux/io.h>
9143 +#include <asm/pgtable.h>
9146 + * Remap an arbitrary physical address space into the kernel virtual
9147 + * address space. Needed when the kernel wants to access high addresses
9150 + * NOTE! We need to allow non-page-aligned mappings too: we will obviously
9151 + * have to convert them into an offset in a page-aligned mapping, but the
9152 + * caller shouldn't need to know that small detail.
9154 +static void __iomem *__ioremap_caller(phys_addr_t addr, size_t size,
9155 + pgprot_t prot, void *caller)
9157 + phys_addr_t last_addr;
9158 + unsigned long offset, vaddr;
9159 + struct vm_struct *area;
9161 + /* Disallow wrap-around or zero size */
9162 + last_addr = addr + size - 1;
9163 + if (!size || last_addr < addr) {
9167 + /* Page-align mappings */
9168 + offset = addr & (~PAGE_MASK);
9169 + addr &= PAGE_MASK;
9170 + size = PAGE_ALIGN(size + offset);
9172 + area = get_vm_area_caller(size, VM_IOREMAP, caller);
9176 + vaddr = (unsigned long)area->addr;
9178 + if (ioremap_page_range(vaddr, vaddr + size, addr, prot)) {
9179 + free_vm_area(area);
9183 + return (void __iomem *)(vaddr + offset);
9187 + * ioremap - map bus memory into CPU space
9188 + * @offset: bus address of the memory
9189 + * @size: size of the resource to map
9191 + * ioremap performs a platform specific sequence of operations to
9192 + * make bus memory CPU accessible via the readb/readw/readl/writeb/
9193 + * writew/writel functions and the other mmio helpers. The returned
9194 + * address is not guaranteed to be usable directly as a virtual
9197 + * Must be freed with iounmap.
9199 +void __iomem *ioremap(phys_addr_t offset, unsigned long size)
9201 + return __ioremap_caller(offset, size, PAGE_KERNEL,
9202 + __builtin_return_address(0));
9204 +EXPORT_SYMBOL(ioremap);
9208 + * iounmap - Free a IO remapping
9209 + * @addr: virtual address from ioremap_*
9211 + * Caller must ensure there is only one unmapping for the same pointer.
9213 +void iounmap(void __iomem *addr)
9215 + vunmap((void *)((unsigned long)addr & PAGE_MASK));
9217 +EXPORT_SYMBOL(iounmap);
9219 diff -Nur linux-4.6.2/arch/riscv/mm/Makefile linux-4.6.2.riscv/arch/riscv/mm/Makefile
9220 --- linux-4.6.2/arch/riscv/mm/Makefile 1970-01-01 01:00:00.000000000 +0100
9221 +++ linux-4.6.2.riscv/arch/riscv/mm/Makefile 2017-03-04 02:48:34.170888098 +0100
9223 +obj-y := init.o fault.o extable.o ioremap.o
9224 diff -Nur linux-4.6.2/.gitignore linux-4.6.2.riscv/.gitignore
9225 --- linux-4.6.2/.gitignore 2016-06-08 03:23:53.000000000 +0200
9226 +++ linux-4.6.2.riscv/.gitignore 2017-03-04 02:48:34.162887952 +0100
9229 -# NOTE! Don't add files that are generated in specific
9230 -# subdirectories here. Add them in the ".gitignore" file
9231 -# in that subdirectory instead.
9233 -# NOTE! Please use 'git ls-files -i --exclude-standard'
9234 -# command after changing this file, to see if there are
9235 -# any tracked files which get ignored after the change.
9267 +# Ignore everything...
9271 -# Top-level generic files
9284 -# Debian directory (make deb-pkg)
9289 -# tar directory (make tar*-pkg)
9294 -# git files that we don't want to ignore even it they are dot-files
9296 +# Then include just this.
9302 -# Generated include files
9306 -arch/*/include/generated
9308 -# stgit generated dirs
9333 -# Leavings from module signing
9344 +# The arch/.gitignore and arch/riscv/.gitignore have patterns to un-ignore the
9345 +# appropriate files.
9349 diff -Nur linux-4.6.2/README.md linux-4.6.2.riscv/README.md
9350 --- linux-4.6.2/README.md 1970-01-01 01:00:00.000000000 +0100
9351 +++ linux-4.6.2.riscv/README.md 2017-03-04 02:48:34.162887952 +0100
9355 +This is a port of Linux kernel for the [RISC-V](http://riscv.org/)
9356 +instruction set architecture.
9357 +Development is currently based on the
9358 +[4.6 longterm branch](https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/log/?h=linux-4.6.y).
9361 +## Obtaining kernel sources
9365 +Overlay the `riscv` architecture-specific subtree onto an upstream release:
9367 + $ curl -L https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.6.2.tar.xz | tar -xJ
9370 + $ git remote add -t master origin https://github.com/riscv/riscv-linux.git
9372 + $ git checkout -f -t origin/master
9374 +Note that the `-t <branch>` option minimizes the history fetched.
9375 +To add another branch:
9377 + $ git remote set-branches --add origin <branch>
9380 +### Full kernel source trees
9382 +For convenience, full kernel source trees are maintained on separate
9384 +[linux-stable](https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git):
9386 +* `linux-4.6.y-riscv`
9387 +* `linux-3.14.y-riscv` (historical)
9389 +## Building the kernel image
9391 +1. Create kernel configuration based on architecture defaults:
9393 + $ make ARCH=riscv defconfig
9395 +1. Optionally edit the configuration via an ncurses interface:
9397 + $ make ARCH=riscv menuconfig
9399 +1. Build the uncompressed kernel image:
9401 + $ make -j4 ARCH=riscv vmlinux
9403 +1. Boot the kernel in the functional simulator, optionally specifying a
9404 + raw disk image for the root filesystem:
9406 + $ spike +disk=path/to/root.img bbl vmlinux
9408 + `bbl` (the Berkeley Boot Loader) is available from the
9409 + [riscv-pk](https://github.com/riscv/riscv-pk) repository.
9411 +## Exporting kernel headers
9413 +The `riscv-gnu-toolchain` repository includes a copy of the kernel header files.
9414 +If the userspace API has changed, export the updated headers to the
9415 +`riscv-gnu-toolchain` source directory:
9417 + $ make ARCH=riscv headers_check
9418 + $ make ARCH=riscv INSTALL_HDR_PATH=path/to/riscv-gnu-toolchain/linux-headers headers_install
9420 +Rebuild `riscv64-unknown-linux-gnu-gcc` with the `linux` target:
9422 + $ cd path/to/riscv-gnu-toolchain