version 4.19.325-cip127 * tag 'v4.19.325-cip127' of https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip: CIP: Bump version suffix to -cip127 after merge from cip/linux-4.19.y-st tree Update localversion-st, tree is up-to-date with 5.10.247. usb: uas: fix urb unmapping issue when the uas device is remove during ongoing data transfer scsi: pm80xx: Set phy->enable_completion only when we drm/amd/display: Check NULL before accessing wifi: ath10k: Fix connection after GTK rekeying pinctrl: single: fix bias pull up/down handling in pin_config_set ovl: fix UAF in ovl_dentry_update_reval by moving dput() in ovl_link_up fs: writeback: fix use-after-free in __mark_inode_dirty() libceph: fix potential use-after-free in have_mon_and_osd_map() drm: sti: fix device leaks at component probe USB: serial: option: add support for Rolling RW101R-GL USB: serial: ftdi_sio: add support for u-blox EVK-M101 usb: storage: sddr55: Reject out-of-bound new_pba USB: storage: Remove subclass and protocol overrides from Novatek quirk usb: storage: Fix memory leak in USB bulk transport usb: gadget: f_eem: Fix memory leak in eem_unwrap slimbus: ngd: Fix reference count leak in qcom_slim_ngd_notify_slaves dm-verity: fix unreliable memory allocation can: sun4i_can: sun4i_can_interrupt(): fix max irq loop handling can: sja1000: fix max irq loop handling atm/fore200e: Fix possible data race in fore200e_open() MIPS: mm: Prevent a TLB shutdown on initial uniquification iio:common:ssp_sensors: Fix an error handling path ssp_probe() spi: bcm63xx: fix premature CS deassertion on RX-only transactions net: sxgbe: fix potential NULL dereference in sxgbe_rx() can: kvaser_usb: leaf: Fix potential infinite loop in command parsers mtd: onenand: Pass correct pointer to IRQ handler fsdax: mark the iomap argument to dax_iomap_sector as const net: sctp: Fix some typos iommu/amd: Skip enabling command/event buffers for kdump nvme-fc: use lock accessing port_state and rport state net: netpoll: fix incorrect refcount handling causing incorrect cleanup net: ethernet: ti: netcp: Standardize knav_dma_open_channel to return NULL on error tipc: Fix use-after-free in tipc_mon_reinit_self(). sctp: prevent possible shift-out-of-bounds in sctp_transport_update_rto Bluetooth: btusb: reorder cleanup in btusb_disconnect to avoid UAF wifi: brcmfmac: fix crash while sending Action Frames in standalone AP Mode net/sched: sch_qfq: Fix null-deref in agg_dequeue Input: pegasus-notetaker - fix potential out-of-bounds access Input: remove third argument of usb_maxpacket() usb: deprecate the third argument of usb_maxpacket() ata: libata-scsi: Fix system suspend for a security locked drive fs/proc: fix uaf in proc_readdir_de() pmdomain: imx: Fix reference count leak in imx_gpc_remove pmdomain: arm: scmi: Fix genpd leak on provider registration failure net: qede: Initialize qede_ll_ops with designated initializer uio_hv_generic: Set event for all channels on the device ALSA: usb-audio: fix uac2 clock source at terminal parser kconfig/nconf: Initialize the default locale at startup kconfig/mconf: Initialize the default locale at startup vsock: Ignore signal/timeout on connect() if already established s390/ctcm: Fix double-kfree net: openvswitch: remove never-working support for setting nsh fields mlxsw: spectrum: Fix memory leak in mlxsw_sp_flower_stats() MIPS: Malta: Fix !EVA SOC-it PCI MMIO scsi: target: tcm_loop: Fix segfault in tcm_loop_tpg_address_show() scsi: sg: Do not sleep in atomic context Input: cros_ec_keyb - fix an invalid memory access be2net: pass wrb_params in case of OS2BMC HID: quirks: work around VID/PID conflict for 0x4c4a/0x4155 isdn: mISDN: hfcsusb: fix memory leak in hfcsusb_probe() spi: Try to get ACPI GPIO IRQ earlier ipv4: route: Prevent rt_bind_exception() from rebinding stale fnhe strparser: Fix signed/unsigned mismatch bug gcov: add support for GCC 15 mm/ksm: fix flag-dropping behavior in ksm_madvise ALSA: usb-audio: Fix NULL pointer dereference in snd_usb_mixer_controls_badd ASoC: cs4271: Fix regulator leak on probe failure regulator: fixed: use dev_err_probe for register Bluetooth: L2CAP: export l2cap_chan_hold for modules net_sched: remove need_resched() from qdisc_run() net/mlx5e: Fix maxrate wraparound in threshold between units net: sched: act_ife: initialize struct tc_ife to fix KMSAN kernel-infoleak Bluetooth: 6lowpan: Don't hold spin lock over sleeping functions Bluetooth: 6lowpan: fix BDADDR_LE vs ADDR_LE_DEV address type confusion Bluetooth: 6lowpan: reset link-local header on ipv6 recv path net: fec: correct rx_bytes statistic for the case SHIFT16 is set ASoC: max98090/91: fixed max98091 ALSA widget powering up/down HID: quirks: avoid Cooler Master MM712 dongle wakeup bug NFS4: Fix state renewals missing after boot extcon: adc-jack: Cleanup wakeup source only if it was enabled net: usb: qmi_wwan: initialize MAC header offset in qmimux_rx_fixup sctp: Prevent TOCTOU out-of-bounds write sctp: Hold RCU read lock while iterating over address list net: vlan: sync VLAN features with lower device ceph: add checking of wait_for_completion_killable() return value fbdev: Add bounds checking in bit_putcs to fix vmalloc-out-of-bounds ACPI: property: Return present device nodes only on fwnode interface 9p: sysfs_init: don't hardcode error to ENOMEM 9p: fix /sys/fs/9p/caches overwriting itself fs/hpfs: Fix error code for new_inode() failure in mkdir/create/mknod/symlink ACPICA: Update dsmethod.c to get rid of unused variable warning page_pool: Clamp pool size to max 16K pages Bluetooth: bcsp: receive data only if registered Bluetooth: SCO: Fix UAF on sco_conn_free net: macb: avoid dealing with endianness in macb_set_hwaddr() nfs4_setup_readdir(): insufficient locking for ->d_parent->d_inode dereferencing NFSv4.1: fix mount hang after CREATE_SESSION failure NFSv4: handle ERR_GRACE on delegation recalls remoteproc: qcom: q6v5: Avoid handling handover twice sparc/module: Add R_SPARC_UA64 relocation handling net: intel: fm10k: Fix parameter idx set but not used jfs: fix uninitialized waitqueue in transaction manager jfs: Verify inode mode when loading from disk ipv6: np->rxpmtu race annotation usb: xhci: plat: Facilitate using autosuspend for xhci plat devices usb: mon: Increase BUFF_MAX to 64 MiB to support multi-MB URBs allow finish_no_open(file, ERR_PTR(-E...)) scsi: lpfc: Define size of debugfs entry for xri rebalancing scsi: lpfc: Check return status of lpfc_reset_flush_io_context during TGT_RESET selftests/Makefile: include $(INSTALL_DEP_TARGETS) in clean target to clean net/lib dependency net/cls_cgroup: Fix task_get_classid() during qdisc run media: redrat3: use int type to store negative error codes net: sh_eth: Disable WoL if system can not suspend usb: gadget: f_hid: Fix zero length packet transfer net: call cond_resched() less often in __release_sock() ALSA: usb-audio: apply quirk for MOONDROP Quark2 net: nfc: nci: Increase NCI_DATA_TIMEOUT to 3000 ms dmaengine: mv_xor: match alloc_wc and free_wc scsi: pm8001: Use int instead of u32 to store error codes mips: lantiq: xway: sysctrl: rename stp clock mips: lantiq: danube: add missing properties to cpu node media: fix uninitialized symbol warnings extcon: adc-jack: Fix wakeup source leaks on device unbind rds: Fix endianness annotation for RDS_MPATH_HASH net: Call trace_sock_exceed_buf_limit() for memcg failure with SK_MEM_RECV. char: misc: Does not request module for miscdevice with dynamic minor usb: gadget: f_ncm: Fix MAC assignment NCM ethernet iio: adc: spear_adc: mask SPEAR_ADC_STATUS channel and avg sample before setting register media: imon: make send_packet() more robust net: ipv6: fix field-spanning memcpy warning in AH output bridge: Redirect to backup port when port is administratively down media: pci: ivtv: Don't create fake v4l2_fh drm/amdkfd: return -ENOTTY for unsupported IOCTLs selftests/net: Ensure assert() triggers in psock_tpacket.c selftests/net: Replace non-standard __WORDSIZE with sizeof(long) * 8 PCI: Disable MSI on RDC PCI to PCIe bridges drm/nouveau: replace snprintf() with scnprintf() in nvkm_snprintbf() mfd: madera: Work around false-positive -Wininitialized warning mfd: stmpe: Remove IRQ domain upon removal tools/power x86_energy_perf_policy: Prefer driver HWP limits tools/power x86_energy_perf_policy: Enhance HWP enable tools/cpupower: Fix incorrect size in cpuidle_state_disable() hwmon: (dell-smm) Add support for Dell OptiPlex 7040 uprobe: Do not emulate/sstep original instruction when ip is changed clocksource/drivers/vf-pit: Replace raw_readl/writel to readl/writel video: backlight: lp855x_bl: Set correct EPROM start for LP8556 tee: allow a driver to allocate a tee_device without a pool ACPICA: dispatcher: Use acpi_ds_clear_operands() in acpi_ds_call_control_method() irqchip/gic-v2m: Handle Multiple MSI base IRQ Alignment arc: Fix __fls() const-foldability via __builtin_clzl() cpufreq/longhaul: handle NULL policy in longhaul_exit selftests/bpf: Fix bpf_prog_detach2 usage in test_lirc_mode2 ACPI: video: force native for Lenovo 82K8 memstick: Add timeout to prevent indefinite waiting bpf: Don't use %pK through printk spi: loopback-test: Don't use %pK through printk soc: qcom: smem: Fix endian-unaware access of num_entries usb: gadget: f_fs: Fix epfile null pointer access after ep enable. serial: 8250_dw: Use devm_clk_get_optional() to get the input clock can: gs_usb: increase max interface to U8_MAX devcoredump: Fix circular locking dependency with devcd->mutex. x86/resctrl: Fix miscount of bandwidth event when reactivating previously unavailable RMID net: phy: dp83867: Disable EEE support as not implemented regmap: slimbus: fix bus_context pointer in regmap init calls usbnet: Prevents free active kevent wifi: ath10k: Fix memory leak on unsupported WMI command ASoC: qdsp6: q6asm: do not sleep while atomic fbdev: pvr2fb: Fix leftover reference to ONCHIP_NR_DMA_CHANNELS fbdev: bitblit: bound-check glyph index in bit_putcs* ACPI: video: Fix use-after-free in acpi_video_switch_brightness() fbdev: atyfb: Check if pll_ops->init_pll failed net: usb: asix_devices: Check return value of usbnet_get_endpoints btrfs: use smp_mb__after_atomic() when forcing COW in create_pending_snapshot() x86/bugs: Fix reporting of LFENCE retpoline Conflicts: drivers/slimbus/qcom-ngd-ctrl.c drivers/usb/gadget/function/f_fs.c drivers/usb/host/xhci-plat.c Change-Id: Id995e84f0ff2c819145f7ebd62bc8dcd47fbbb47
650 lines
15 KiB
C
650 lines
15 KiB
C
/*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
* for more details.
|
|
*
|
|
* Copyright (C) 1996 David S. Miller (davem@davemloft.net)
|
|
* Copyright (C) 1997, 1998, 1999, 2000 Ralf Baechle ralf@gnu.org
|
|
* Carsten Langgaard, carstenl@mips.com
|
|
* Copyright (C) 2002 MIPS Technologies, Inc. All rights reserved.
|
|
*/
|
|
#include <linux/cpu_pm.h>
|
|
#include <linux/init.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/smp.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/hugetlb.h>
|
|
#include <linux/export.h>
|
|
#include <linux/sort.h>
|
|
|
|
#include <asm/cpu.h>
|
|
#include <asm/cpu-type.h>
|
|
#include <asm/bootinfo.h>
|
|
#include <asm/hazards.h>
|
|
#include <asm/mmu_context.h>
|
|
#include <linux/pgtable.h>
|
|
#include <asm/tlb.h>
|
|
#include <asm/tlbmisc.h>
|
|
|
|
extern void build_tlb_refill_handler(void);
|
|
|
|
/*
|
|
* LOONGSON-2 has a 4 entry itlb which is a subset of jtlb, LOONGSON-3 has
|
|
* a 4 entry itlb and a 4 entry dtlb which are subsets of jtlb. Unfortunately,
|
|
* itlb/dtlb are not totally transparent to software.
|
|
*/
|
|
static inline void flush_micro_tlb(void)
|
|
{
|
|
switch (current_cpu_type()) {
|
|
case CPU_LOONGSON2:
|
|
write_c0_diag(LOONGSON_DIAG_ITLB);
|
|
break;
|
|
case CPU_LOONGSON3:
|
|
write_c0_diag(LOONGSON_DIAG_ITLB | LOONGSON_DIAG_DTLB);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static inline void flush_micro_tlb_vm(struct vm_area_struct *vma)
|
|
{
|
|
if (vma->vm_flags & VM_EXEC)
|
|
flush_micro_tlb();
|
|
}
|
|
|
|
void local_flush_tlb_all(void)
|
|
{
|
|
unsigned long flags;
|
|
unsigned long old_ctx;
|
|
int entry, ftlbhighset;
|
|
|
|
local_irq_save(flags);
|
|
/* Save old context and create impossible VPN2 value */
|
|
old_ctx = read_c0_entryhi();
|
|
htw_stop();
|
|
write_c0_entrylo0(0);
|
|
write_c0_entrylo1(0);
|
|
|
|
entry = num_wired_entries();
|
|
|
|
/*
|
|
* Blast 'em all away.
|
|
* If there are any wired entries, fall back to iterating
|
|
*/
|
|
if (cpu_has_tlbinv && !entry) {
|
|
if (current_cpu_data.tlbsizevtlb) {
|
|
write_c0_index(0);
|
|
mtc0_tlbw_hazard();
|
|
tlbinvf(); /* invalidate VTLB */
|
|
}
|
|
ftlbhighset = current_cpu_data.tlbsizevtlb +
|
|
current_cpu_data.tlbsizeftlbsets;
|
|
for (entry = current_cpu_data.tlbsizevtlb;
|
|
entry < ftlbhighset;
|
|
entry++) {
|
|
write_c0_index(entry);
|
|
mtc0_tlbw_hazard();
|
|
tlbinvf(); /* invalidate one FTLB set */
|
|
}
|
|
} else {
|
|
while (entry < current_cpu_data.tlbsize) {
|
|
/* Make sure all entries differ. */
|
|
write_c0_entryhi(UNIQUE_ENTRYHI(entry));
|
|
write_c0_index(entry);
|
|
mtc0_tlbw_hazard();
|
|
tlb_write_indexed();
|
|
entry++;
|
|
}
|
|
}
|
|
tlbw_use_hazard();
|
|
write_c0_entryhi(old_ctx);
|
|
htw_start();
|
|
flush_micro_tlb();
|
|
local_irq_restore(flags);
|
|
}
|
|
EXPORT_SYMBOL(local_flush_tlb_all);
|
|
|
|
/* All entries common to a mm share an asid. To effectively flush
|
|
these entries, we just bump the asid. */
|
|
void local_flush_tlb_mm(struct mm_struct *mm)
|
|
{
|
|
int cpu;
|
|
|
|
preempt_disable();
|
|
|
|
cpu = smp_processor_id();
|
|
|
|
if (cpu_context(cpu, mm) != 0) {
|
|
drop_mmu_context(mm, cpu);
|
|
}
|
|
|
|
preempt_enable();
|
|
}
|
|
|
|
void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
|
|
unsigned long end)
|
|
{
|
|
struct mm_struct *mm = vma->vm_mm;
|
|
int cpu = smp_processor_id();
|
|
|
|
if (cpu_context(cpu, mm) != 0) {
|
|
unsigned long size, flags;
|
|
|
|
local_irq_save(flags);
|
|
start = round_down(start, PAGE_SIZE << 1);
|
|
end = round_up(end, PAGE_SIZE << 1);
|
|
size = (end - start) >> (PAGE_SHIFT + 1);
|
|
if (size <= (current_cpu_data.tlbsizeftlbsets ?
|
|
current_cpu_data.tlbsize / 8 :
|
|
current_cpu_data.tlbsize / 2)) {
|
|
int oldpid = read_c0_entryhi();
|
|
int newpid = cpu_asid(cpu, mm);
|
|
|
|
htw_stop();
|
|
while (start < end) {
|
|
int idx;
|
|
|
|
write_c0_entryhi(start | newpid);
|
|
start += (PAGE_SIZE << 1);
|
|
mtc0_tlbw_hazard();
|
|
tlb_probe();
|
|
tlb_probe_hazard();
|
|
idx = read_c0_index();
|
|
write_c0_entrylo0(0);
|
|
write_c0_entrylo1(0);
|
|
if (idx < 0)
|
|
continue;
|
|
/* Make sure all entries differ. */
|
|
write_c0_entryhi(UNIQUE_ENTRYHI(idx));
|
|
mtc0_tlbw_hazard();
|
|
tlb_write_indexed();
|
|
}
|
|
tlbw_use_hazard();
|
|
write_c0_entryhi(oldpid);
|
|
htw_start();
|
|
} else {
|
|
drop_mmu_context(mm, cpu);
|
|
}
|
|
flush_micro_tlb();
|
|
local_irq_restore(flags);
|
|
}
|
|
}
|
|
|
|
void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
|
|
{
|
|
unsigned long size, flags;
|
|
|
|
local_irq_save(flags);
|
|
size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
|
|
size = (size + 1) >> 1;
|
|
if (size <= (current_cpu_data.tlbsizeftlbsets ?
|
|
current_cpu_data.tlbsize / 8 :
|
|
current_cpu_data.tlbsize / 2)) {
|
|
int pid = read_c0_entryhi();
|
|
|
|
start &= (PAGE_MASK << 1);
|
|
end += ((PAGE_SIZE << 1) - 1);
|
|
end &= (PAGE_MASK << 1);
|
|
htw_stop();
|
|
|
|
while (start < end) {
|
|
int idx;
|
|
|
|
write_c0_entryhi(start);
|
|
start += (PAGE_SIZE << 1);
|
|
mtc0_tlbw_hazard();
|
|
tlb_probe();
|
|
tlb_probe_hazard();
|
|
idx = read_c0_index();
|
|
write_c0_entrylo0(0);
|
|
write_c0_entrylo1(0);
|
|
if (idx < 0)
|
|
continue;
|
|
/* Make sure all entries differ. */
|
|
write_c0_entryhi(UNIQUE_ENTRYHI(idx));
|
|
mtc0_tlbw_hazard();
|
|
tlb_write_indexed();
|
|
}
|
|
tlbw_use_hazard();
|
|
write_c0_entryhi(pid);
|
|
htw_start();
|
|
} else {
|
|
local_flush_tlb_all();
|
|
}
|
|
flush_micro_tlb();
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
|
|
{
|
|
int cpu = smp_processor_id();
|
|
|
|
if (cpu_context(cpu, vma->vm_mm) != 0) {
|
|
unsigned long flags;
|
|
int oldpid, newpid, idx;
|
|
|
|
newpid = cpu_asid(cpu, vma->vm_mm);
|
|
page &= (PAGE_MASK << 1);
|
|
local_irq_save(flags);
|
|
oldpid = read_c0_entryhi();
|
|
htw_stop();
|
|
write_c0_entryhi(page | newpid);
|
|
mtc0_tlbw_hazard();
|
|
tlb_probe();
|
|
tlb_probe_hazard();
|
|
idx = read_c0_index();
|
|
write_c0_entrylo0(0);
|
|
write_c0_entrylo1(0);
|
|
if (idx < 0)
|
|
goto finish;
|
|
/* Make sure all entries differ. */
|
|
write_c0_entryhi(UNIQUE_ENTRYHI(idx));
|
|
mtc0_tlbw_hazard();
|
|
tlb_write_indexed();
|
|
tlbw_use_hazard();
|
|
|
|
finish:
|
|
write_c0_entryhi(oldpid);
|
|
htw_start();
|
|
flush_micro_tlb_vm(vma);
|
|
local_irq_restore(flags);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* This one is only used for pages with the global bit set so we don't care
|
|
* much about the ASID.
|
|
*/
|
|
void local_flush_tlb_one(unsigned long page)
|
|
{
|
|
unsigned long flags;
|
|
int oldpid, idx;
|
|
|
|
local_irq_save(flags);
|
|
oldpid = read_c0_entryhi();
|
|
htw_stop();
|
|
page &= (PAGE_MASK << 1);
|
|
write_c0_entryhi(page);
|
|
mtc0_tlbw_hazard();
|
|
tlb_probe();
|
|
tlb_probe_hazard();
|
|
idx = read_c0_index();
|
|
write_c0_entrylo0(0);
|
|
write_c0_entrylo1(0);
|
|
if (idx >= 0) {
|
|
/* Make sure all entries differ. */
|
|
write_c0_entryhi(UNIQUE_ENTRYHI(idx));
|
|
mtc0_tlbw_hazard();
|
|
tlb_write_indexed();
|
|
tlbw_use_hazard();
|
|
}
|
|
write_c0_entryhi(oldpid);
|
|
htw_start();
|
|
flush_micro_tlb();
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
/*
|
|
* We will need multiple versions of update_mmu_cache(), one that just
|
|
* updates the TLB with the new pte(s), and another which also checks
|
|
* for the R4k "end of page" hardware bug and does the needy.
|
|
*/
|
|
void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
|
|
{
|
|
unsigned long flags;
|
|
pgd_t *pgdp;
|
|
pud_t *pudp;
|
|
pmd_t *pmdp;
|
|
pte_t *ptep;
|
|
int idx, pid;
|
|
|
|
/*
|
|
* Handle debugger faulting in for debugee.
|
|
*/
|
|
if (current->active_mm != vma->vm_mm)
|
|
return;
|
|
|
|
local_irq_save(flags);
|
|
|
|
htw_stop();
|
|
pid = read_c0_entryhi() & cpu_asid_mask(¤t_cpu_data);
|
|
address &= (PAGE_MASK << 1);
|
|
write_c0_entryhi(address | pid);
|
|
pgdp = pgd_offset(vma->vm_mm, address);
|
|
mtc0_tlbw_hazard();
|
|
tlb_probe();
|
|
tlb_probe_hazard();
|
|
pudp = pud_offset(pgdp, address);
|
|
pmdp = pmd_offset(pudp, address);
|
|
idx = read_c0_index();
|
|
#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
|
|
/* this could be a huge page */
|
|
if (pmd_huge(*pmdp)) {
|
|
unsigned long lo;
|
|
write_c0_pagemask(PM_HUGE_MASK);
|
|
ptep = (pte_t *)pmdp;
|
|
lo = pte_to_entrylo(pte_val(*ptep));
|
|
write_c0_entrylo0(lo);
|
|
write_c0_entrylo1(lo + (HPAGE_SIZE >> 7));
|
|
|
|
mtc0_tlbw_hazard();
|
|
if (idx < 0)
|
|
tlb_write_random();
|
|
else
|
|
tlb_write_indexed();
|
|
tlbw_use_hazard();
|
|
write_c0_pagemask(PM_DEFAULT_MASK);
|
|
} else
|
|
#endif
|
|
{
|
|
ptep = pte_offset_map(pmdp, address);
|
|
|
|
#if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
|
|
#ifdef CONFIG_XPA
|
|
write_c0_entrylo0(pte_to_entrylo(ptep->pte_high));
|
|
if (cpu_has_xpa)
|
|
writex_c0_entrylo0(ptep->pte_low & _PFNX_MASK);
|
|
ptep++;
|
|
write_c0_entrylo1(pte_to_entrylo(ptep->pte_high));
|
|
if (cpu_has_xpa)
|
|
writex_c0_entrylo1(ptep->pte_low & _PFNX_MASK);
|
|
#else
|
|
write_c0_entrylo0(ptep->pte_high);
|
|
ptep++;
|
|
write_c0_entrylo1(ptep->pte_high);
|
|
#endif
|
|
#else
|
|
write_c0_entrylo0(pte_to_entrylo(pte_val(*ptep++)));
|
|
write_c0_entrylo1(pte_to_entrylo(pte_val(*ptep)));
|
|
#endif
|
|
mtc0_tlbw_hazard();
|
|
if (idx < 0)
|
|
tlb_write_random();
|
|
else
|
|
tlb_write_indexed();
|
|
}
|
|
tlbw_use_hazard();
|
|
htw_start();
|
|
flush_micro_tlb_vm(vma);
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
|
|
unsigned long entryhi, unsigned long pagemask)
|
|
{
|
|
#ifdef CONFIG_XPA
|
|
panic("Broken for XPA kernels");
|
|
#else
|
|
unsigned long flags;
|
|
unsigned long wired;
|
|
unsigned long old_pagemask;
|
|
unsigned long old_ctx;
|
|
|
|
local_irq_save(flags);
|
|
/* Save old context and create impossible VPN2 value */
|
|
old_ctx = read_c0_entryhi();
|
|
htw_stop();
|
|
old_pagemask = read_c0_pagemask();
|
|
wired = num_wired_entries();
|
|
write_c0_wired(wired + 1);
|
|
write_c0_index(wired);
|
|
tlbw_use_hazard(); /* What is the hazard here? */
|
|
write_c0_pagemask(pagemask);
|
|
write_c0_entryhi(entryhi);
|
|
write_c0_entrylo0(entrylo0);
|
|
write_c0_entrylo1(entrylo1);
|
|
mtc0_tlbw_hazard();
|
|
tlb_write_indexed();
|
|
tlbw_use_hazard();
|
|
|
|
write_c0_entryhi(old_ctx);
|
|
tlbw_use_hazard(); /* What is the hazard here? */
|
|
htw_start();
|
|
write_c0_pagemask(old_pagemask);
|
|
local_flush_tlb_all();
|
|
local_irq_restore(flags);
|
|
#endif
|
|
}
|
|
|
|
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
|
|
|
int has_transparent_hugepage(void)
|
|
{
|
|
static unsigned int mask = -1;
|
|
|
|
if (mask == -1) { /* first call comes during __init */
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
write_c0_pagemask(PM_HUGE_MASK);
|
|
back_to_back_c0_hazard();
|
|
mask = read_c0_pagemask();
|
|
write_c0_pagemask(PM_DEFAULT_MASK);
|
|
local_irq_restore(flags);
|
|
}
|
|
return mask == PM_HUGE_MASK;
|
|
}
|
|
EXPORT_SYMBOL(has_transparent_hugepage);
|
|
|
|
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
|
|
|
|
/*
|
|
* Used for loading TLB entries before trap_init() has started, when we
|
|
* don't actually want to add a wired entry which remains throughout the
|
|
* lifetime of the system
|
|
*/
|
|
|
|
int temp_tlb_entry;
|
|
|
|
__init int add_temporary_entry(unsigned long entrylo0, unsigned long entrylo1,
|
|
unsigned long entryhi, unsigned long pagemask)
|
|
{
|
|
int ret = 0;
|
|
unsigned long flags;
|
|
unsigned long wired;
|
|
unsigned long old_pagemask;
|
|
unsigned long old_ctx;
|
|
|
|
local_irq_save(flags);
|
|
/* Save old context and create impossible VPN2 value */
|
|
htw_stop();
|
|
old_ctx = read_c0_entryhi();
|
|
old_pagemask = read_c0_pagemask();
|
|
wired = num_wired_entries();
|
|
if (--temp_tlb_entry < wired) {
|
|
printk(KERN_WARNING
|
|
"No TLB space left for add_temporary_entry\n");
|
|
ret = -ENOSPC;
|
|
goto out;
|
|
}
|
|
|
|
write_c0_index(temp_tlb_entry);
|
|
write_c0_pagemask(pagemask);
|
|
write_c0_entryhi(entryhi);
|
|
write_c0_entrylo0(entrylo0);
|
|
write_c0_entrylo1(entrylo1);
|
|
mtc0_tlbw_hazard();
|
|
tlb_write_indexed();
|
|
tlbw_use_hazard();
|
|
|
|
write_c0_entryhi(old_ctx);
|
|
write_c0_pagemask(old_pagemask);
|
|
htw_start();
|
|
out:
|
|
local_irq_restore(flags);
|
|
return ret;
|
|
}
|
|
|
|
static int ntlb;
|
|
static int __init set_ntlb(char *str)
|
|
{
|
|
get_option(&str, &ntlb);
|
|
return 1;
|
|
}
|
|
|
|
__setup("ntlb=", set_ntlb);
|
|
|
|
|
|
/* Comparison function for EntryHi VPN fields. */
|
|
static int r4k_vpn_cmp(const void *a, const void *b)
|
|
{
|
|
long v = *(unsigned long *)a - *(unsigned long *)b;
|
|
int s = sizeof(long) > sizeof(int) ? sizeof(long) * 8 - 1: 0;
|
|
return s ? (v != 0) | v >> s : v;
|
|
}
|
|
|
|
/*
|
|
* Initialise all TLB entries with unique values that do not clash with
|
|
* what we have been handed over and what we'll be using ourselves.
|
|
*/
|
|
static void r4k_tlb_uniquify(void)
|
|
{
|
|
unsigned long tlb_vpns[1 << MIPS_CONF1_TLBS_SIZE];
|
|
int tlbsize = current_cpu_data.tlbsize;
|
|
int start = num_wired_entries();
|
|
unsigned long vpn_mask;
|
|
int cnt, ent, idx, i;
|
|
|
|
vpn_mask = GENMASK(cpu_vmbits - 1, 13);
|
|
vpn_mask |= IS_ENABLED(CONFIG_64BIT) ? 3ULL << 62 : 1 << 31;
|
|
|
|
htw_stop();
|
|
|
|
for (i = start, cnt = 0; i < tlbsize; i++, cnt++) {
|
|
unsigned long vpn;
|
|
|
|
write_c0_index(i);
|
|
mtc0_tlbr_hazard();
|
|
tlb_read();
|
|
tlb_read_hazard();
|
|
vpn = read_c0_entryhi();
|
|
vpn &= vpn_mask & PAGE_MASK;
|
|
tlb_vpns[cnt] = vpn;
|
|
|
|
/* Prevent any large pages from overlapping regular ones. */
|
|
write_c0_pagemask(read_c0_pagemask() & PM_DEFAULT_MASK);
|
|
mtc0_tlbw_hazard();
|
|
tlb_write_indexed();
|
|
tlbw_use_hazard();
|
|
}
|
|
|
|
sort(tlb_vpns, cnt, sizeof(tlb_vpns[0]), r4k_vpn_cmp, NULL);
|
|
|
|
write_c0_pagemask(PM_DEFAULT_MASK);
|
|
write_c0_entrylo0(0);
|
|
write_c0_entrylo1(0);
|
|
|
|
idx = 0;
|
|
ent = tlbsize;
|
|
for (i = start; i < tlbsize; i++)
|
|
while (1) {
|
|
unsigned long entryhi, vpn;
|
|
|
|
entryhi = UNIQUE_ENTRYHI(ent);
|
|
vpn = entryhi & vpn_mask & PAGE_MASK;
|
|
|
|
if (idx >= cnt || vpn < tlb_vpns[idx]) {
|
|
write_c0_entryhi(entryhi);
|
|
write_c0_index(i);
|
|
mtc0_tlbw_hazard();
|
|
tlb_write_indexed();
|
|
ent++;
|
|
break;
|
|
} else if (vpn == tlb_vpns[idx]) {
|
|
ent++;
|
|
} else {
|
|
idx++;
|
|
}
|
|
}
|
|
|
|
tlbw_use_hazard();
|
|
htw_start();
|
|
flush_micro_tlb();
|
|
}
|
|
|
|
/*
|
|
* Configure TLB (for init or after a CPU has been powered off).
|
|
*/
|
|
static void r4k_tlb_configure(void)
|
|
{
|
|
/*
|
|
* You should never change this register:
|
|
* - On R4600 1.7 the tlbp never hits for pages smaller than
|
|
* the value in the c0_pagemask register.
|
|
* - The entire mm handling assumes the c0_pagemask register to
|
|
* be set to fixed-size pages.
|
|
*/
|
|
write_c0_pagemask(PM_DEFAULT_MASK);
|
|
back_to_back_c0_hazard();
|
|
if (read_c0_pagemask() != PM_DEFAULT_MASK)
|
|
panic("MMU doesn't support PAGE_SIZE=0x%lx", PAGE_SIZE);
|
|
|
|
write_c0_wired(0);
|
|
if (current_cpu_type() == CPU_R10000 ||
|
|
current_cpu_type() == CPU_R12000 ||
|
|
current_cpu_type() == CPU_R14000 ||
|
|
current_cpu_type() == CPU_R16000)
|
|
write_c0_framemask(0);
|
|
|
|
if (cpu_has_rixi) {
|
|
/*
|
|
* Enable the no read, no exec bits, and enable large physical
|
|
* address.
|
|
*/
|
|
#ifdef CONFIG_64BIT
|
|
set_c0_pagegrain(PG_RIE | PG_XIE | PG_ELPA);
|
|
#else
|
|
set_c0_pagegrain(PG_RIE | PG_XIE);
|
|
#endif
|
|
}
|
|
|
|
temp_tlb_entry = current_cpu_data.tlbsize - 1;
|
|
|
|
/* From this point on the ARC firmware is dead. */
|
|
r4k_tlb_uniquify();
|
|
local_flush_tlb_all();
|
|
|
|
/* Did I tell you that ARC SUCKS? */
|
|
}
|
|
|
|
void tlb_init(void)
|
|
{
|
|
r4k_tlb_configure();
|
|
|
|
if (ntlb) {
|
|
if (ntlb > 1 && ntlb <= current_cpu_data.tlbsize) {
|
|
int wired = current_cpu_data.tlbsize - ntlb;
|
|
write_c0_wired(wired);
|
|
write_c0_index(wired-1);
|
|
printk("Restricting TLB to %d entries\n", ntlb);
|
|
} else
|
|
printk("Ignoring invalid argument ntlb=%d\n", ntlb);
|
|
}
|
|
|
|
build_tlb_refill_handler();
|
|
}
|
|
|
|
static int r4k_tlb_pm_notifier(struct notifier_block *self, unsigned long cmd,
|
|
void *v)
|
|
{
|
|
switch (cmd) {
|
|
case CPU_PM_ENTER_FAILED:
|
|
case CPU_PM_EXIT:
|
|
r4k_tlb_configure();
|
|
break;
|
|
}
|
|
|
|
return NOTIFY_OK;
|
|
}
|
|
|
|
static struct notifier_block r4k_tlb_pm_notifier_block = {
|
|
.notifier_call = r4k_tlb_pm_notifier,
|
|
};
|
|
|
|
static int __init r4k_tlb_init_pm(void)
|
|
{
|
|
return cpu_pm_register_notifier(&r4k_tlb_pm_notifier_block);
|
|
}
|
|
arch_initcall(r4k_tlb_init_pm);
|