* tmp-917a9: ARM/vdso: Mark the vDSO code read-only after init x86/vdso: Mark the vDSO code read-only after init lkdtm: Verify that '__ro_after_init' works correctly arch: Introduce post-init read-only memory x86/mm: Always enable CONFIG_DEBUG_RODATA and remove the Kconfig option mm/init: Add 'rodata=off' boot cmdline parameter to disable read-only kernel mappings asm-generic: Consolidate mark_rodata_ro() Linux 4.4.6 ld-version: Fix awk regex compile failure target: Drop incorrect ABORT_TASK put for completed commands block: don't optimize for non-cloned bio in bio_get_last_bvec() MIPS: smp.c: Fix uninitialised temp_foreign_map MIPS: Fix build error when SMP is used without GIC ovl: fix getcwd() failure after unsuccessful rmdir ovl: copy new uid/gid into overlayfs runtime inode userfaultfd: don't block on the last VM updates at exit time powerpc/powernv: Fix OPAL_CONSOLE_FLUSH prototype and usages powerpc/powernv: Add a kmsg_dumper that flushes console output on panic powerpc: Fix dedotify for binutils >= 2.26 Revert "drm/radeon/pm: adjust display configuration after powerstate" drm/radeon: Fix error handling in radeon_flip_work_func. drm/amdgpu: Fix error handling in amdgpu_flip_work_func. Revert "drm/radeon: call hpd_irq_event on resume" x86/mm: Fix slow_virt_to_phys() for X86_PAE again gpu: ipu-v3: Do not bail out on missing optional port nodes mac80211: Fix Public Action frame RX in AP mode mac80211: check PN correctly for GCMP-encrypted fragmented MPDUs mac80211: minstrel_ht: fix a logic error in RTS/CTS handling mac80211: minstrel_ht: set default tx aggregation timeout to 0 mac80211: fix use of uninitialised values in RX aggregation mac80211: minstrel: Change expected throughput unit back to Kbps iwlwifi: mvm: inc pending frames counter also when txing non-sta can: gs_usb: fixed disconnect bug by removing erroneous use of kfree() cfg80211/wext: fix message ordering wext: fix message delay/ordering ovl: fix working on distributed fs as lower layer ovl: ignore lower entries when checking purity of non-directory entries ASoC: wm8958: Fix enum ctl accesses in a wrong type ASoC: wm8994: Fix enum ctl accesses in a wrong type ASoC: samsung: Use IRQ safe spin lock calls ASoC: dapm: Fix ctl value accesses in a wrong type ncpfs: fix a braino in OOM handling in ncp_fill_cache() jffs2: reduce the breakage on recovery from halfway failed rename() dmaengine: at_xdmac: fix residue computation tracing: Fix check for cpu online when event is disabled s390/dasd: fix diag 0x250 inline assembly s390/mm: four page table levels vs. fork KVM: MMU: fix reserved bit check for ept=0/CR0.WP=0/CR4.SMEP=1/EFER.NX=0 KVM: MMU: fix ept=0/pte.u=1/pte.w=0/CR0.WP=0/CR4.SMEP=1/EFER.NX=0 combo KVM: PPC: Book3S HV: Sanitize special-purpose register values on guest exit KVM: s390: correct fprs on SIGP (STOP AND) STORE STATUS KVM: VMX: disable PEBS before a guest entry kvm: cap halt polling at exactly halt_poll_ns PCI: Allow a NULL "parent" pointer in pci_bus_assign_domain_nr() ARM: OMAP2+: hwmod: Introduce ti,no-idle dt property ARM: dts: dra7: do not gate cpsw clock due to errata i877 ARM: mvebu: fix overlap of Crypto SRAM with PCIe memory window arm64: account for sparsemem section alignment when choosing vmemmap offset Linux 4.4.5 drm/amdgpu: fix topaz/tonga gmc assignment in 4.4 stable modules: fix longstanding /proc/kallsyms vs module insertion race. drm/i915: refine qemu south bridge detection drm/i915: more virtual south bridge detection block: get the 1st and last bvec via helpers block: check virt boundary in bio_will_gap() drm/amdgpu: Use drm_calloc_large for VM page_tables array thermal: cpu_cooling: fix out of bounds access in time_in_idle i2c: brcmstb: allocate correct amount of memory for regmap ubi: Fix out of bounds write in volume update code cxl: Fix PSL timebase synchronization detection MIPS: traps: Fix SIGFPE information leak from `do_ov' and `do_trap_or_bp' MIPS: scache: Fix scache init with invalid line size. USB: serial: option: add support for Quectel UC20 USB: serial: option: add support for Telit LE922 PID 0x1045 USB: qcserial: add Sierra Wireless EM74xx device ID USB: qcserial: add Dell Wireless 5809e Gobi 4G HSPA+ (rev3) USB: cp210x: Add ID for Parrot NMEA GPS Flight Recorder usb: chipidea: otg: change workqueue ci_otg as freezable ALSA: timer: Fix broken compat timer user status ioctl ALSA: hdspm: Fix zero-division ALSA: hdsp: Fix wrong boolean ctl value accesses ALSA: hdspm: Fix wrong boolean ctl value accesses ALSA: seq: oss: Don't drain at closing a client ALSA: pcm: Fix ioctls for X32 ABI ALSA: timer: Fix ioctls for X32 ABI ALSA: rawmidi: Fix ioctls X32 ABI ALSA: hda - Fix mic issues on Acer Aspire E1-472 ALSA: ctl: Fix ioctls for X32 ABI ALSA: usb-audio: Add a quirk for Plantronics DA45 adv7604: fix tx 5v detect regression dmaengine: pxa_dma: fix cyclic transfers Fix directory hardlinks from deleted directories jffs2: Fix page lock / f->sem deadlock Revert "jffs2: Fix lock acquisition order bug in jffs2_write_begin" Btrfs: fix loading of orphan roots leading to BUG_ON pata-rb532-cf: get rid of the irq_to_gpio() call tracing: Do not have 'comm' filter override event 'comm' field ata: ahci: don't mark HotPlugCapable Ports as external/removable PM / sleep / x86: Fix crash on graph trace through x86 suspend arm64: vmemmap: use virtual projection of linear region Adding Intel Lewisburg device IDs for SATA writeback: flush inode cgroup wb switches instead of pinning super_block block: bio: introduce helpers to get the 1st and last bvec libata: Align ata_device's id on a cacheline libata: fix HDIO_GET_32BIT ioctl drm/amdgpu: return from atombios_dp_get_dpcd only when error drm/amdgpu/gfx8: specify which engine to wait before vm flush drm/amdgpu: apply gfx_v8 fixes to gfx_v7 as well drm/amdgpu/pm: update current crtc info after setting the powerstate drm/radeon/pm: update current crtc info after setting the powerstate drm/ast: Fix incorrect register check for DRAM width target: Fix WRITE_SAME/DISCARD conversion to linux 512b sectors iommu/vt-d: Use BUS_NOTIFY_REMOVED_DEVICE in hotplug path iommu/amd: Fix boot warning when device 00:00.0 is not iommu covered iommu/amd: Apply workaround for ATS write permission check arm/arm64: KVM: Fix ioctl error handling KVM: x86: fix root cause for missed hardware breakpoints vfio: fix ioctl error handling Fix cifs_uniqueid_to_ino_t() function for s390x CIFS: Fix SMB2+ interim response processing for read requests cifs: fix out-of-bounds access in lease parsing fbcon: set a default value to blink interval kvm: x86: Update tsc multiplier on change. mips/kvm: fix ioctl error handling parisc: Fix ptrace syscall number and return value modification PCI: keystone: Fix MSI code that retrieves struct pcie_port pointer block: Initialize max_dev_sectors to 0 drm/amdgpu: mask out WC from BO on unsupported arches btrfs: async-thread: Fix a use-after-free error for trace btrfs: Fix no_space in write and rm loop Btrfs: fix deadlock running delayed iputs at transaction commit time drivers: sh: Restore legacy clock domain on SuperH platforms use ->d_seq to get coherency between ->d_inode and ->d_flags Linux 4.4.4 iwlwifi: mvm: don't allow sched scans without matches to be started iwlwifi: update and fix 7265 series PCI IDs iwlwifi: pcie: properly configure the debug buffer size for 8000 iwlwifi: dvm: fix WoWLAN security: let security modules use PTRACE_MODE_* with bitmasks IB/cma: Fix RDMA port validation for iWarp x86/irq: Plug vector cleanup race x86/irq: Call irq_force_move_complete with irq descriptor x86/irq: Remove outgoing CPU from vector cleanup mask x86/irq: Remove the cpumask allocation from send_cleanup_vector() x86/irq: Clear move_in_progress before sending cleanup IPI x86/irq: Remove offline cpus from vector cleanup x86/irq: Get rid of code duplication x86/irq: Copy vectormask instead of an AND operation x86/irq: Check vector allocation early x86/irq: Reorganize the search in assign_irq_vector x86/irq: Reorganize the return path in assign_irq_vector x86/irq: Do not use apic_chip_data.old_domain as temporary buffer x86/irq: Validate that irq descriptor is still active x86/irq: Fix a race in x86_vector_free_irqs() x86/irq: Call chip->irq_set_affinity in proper context x86/entry/compat: Add missing CLAC to entry_INT80_32 x86/mpx: Fix off-by-one comparison with nr_registers hpfs: don't truncate the file when delete fails do_last(): ELOOP failure exit should be done after leaving RCU mode should_follow_link(): validate ->d_seq after having decided to follow xen/pcifront: Fix mysterious crashes when NUMA locality information was extracted. xen/pciback: Save the number of MSI-X entries to be copied later. xen/pciback: Check PF instead of VF for PCI_COMMAND_MEMORY xen/scsiback: correct frontend counting xen/arm: correctly handle DMA mapping of compound pages ARM: at91/dt: fix typo in sama5d2 pinmux descriptions ARM: OMAP2+: Fix onenand initialization to avoid filesystem corruption do_last(): don't let a bogus return value from ->open() et.al. to confuse us kernel/resource.c: fix muxed resource handling in __request_region() sunrpc/cache: fix off-by-one in qword_get() tracing: Fix showing function event in available_events powerpc/eeh: Fix partial hotplug criterion KVM: x86: MMU: fix ubsan index-out-of-range warning KVM: x86: fix conversion of addresses to linear in 32-bit protected mode KVM: x86: fix missed hardware breakpoints KVM: arm/arm64: vgic: Ensure bitmaps are long enough KVM: async_pf: do not warn on page allocation failures of/irq: Fix msi-map calculation for nonzero rid-base NFSv4: Fix a dentry leak on alias use nfs: fix nfs_size_to_loff_t block: fix use-after-free in dio_bio_complete bio: return EINTR if copying to user space got interrupted i2c: i801: Adding Intel Lewisburg support for iTCO phy: core: fix wrong err handle for phy_power_on writeback: keep superblock pinned during cgroup writeback association switches cgroup: make sure a parent css isn't offlined before its children cpuset: make mm migration asynchronous PCI/AER: Flush workqueue on device remove to avoid use-after-free ARCv2: SMP: Emulate IPI to self using software triggered interrupt ARCv2: STAR 9000950267: Handle return from intr to Delay Slot #2 libata: fix sff host state machine locking while polling qla2xxx: Fix stale pointer access. spi: atmel: fix gpio chip-select in case of non-DT platform target: Fix race with SCF_SEND_DELAYED_TAS handling target: Fix remote-port TMR ABORT + se_cmd fabric stop target: Fix TAS handling for multi-session se_node_acls target: Fix LUN_RESET active TMR descriptor handling target: Fix LUN_RESET active I/O handling for ACK_KREF ALSA: hda - Fixing background noise on Dell Inspiron 3162 ALSA: hda - Apply clock gate workaround to Skylake, too Revert "workqueue: make sure delayed work run in local cpu" workqueue: handle NUMA_NO_NODE for unbound pool_workqueue lookup mac80211: Requeue work after scan complete for all VIF types. rfkill: fix rfkill_fop_read wait_event usage tick/nohz: Set the correct expiry when switching to nohz/lowres mode perf stat: Do not clean event's private stats cdc-acm:exclude Samsung phone 04e8:685d Revert "Staging: panel: usleep_range is preferred over udelay" Staging: speakup: Fix getting port information sd: Optimal I/O size is in bytes, not sectors libceph: don't spam dmesg with stray reply warnings libceph: use the right footer size when skipping a message libceph: don't bail early from try_read() when skipping a message libceph: fix ceph_msg_revoke() seccomp: always propagate NO_NEW_PRIVS on tsync cpufreq: Fix NULL reference crash while accessing policy->governor_data cpufreq: pxa2xx: fix pxa_cpufreq_change_voltage prototype hwmon: (ads1015) Handle negative conversion values correctly hwmon: (gpio-fan) Remove un-necessary speed_index lookup for thermal hook hwmon: (dell-smm) Blacklist Dell Studio XPS 8000 Thermal: do thermal zone update after a cooling device registered Thermal: handle thermal zone device properly during system sleep Thermal: initialize thermal zone device correctly IB/mlx5: Expose correct maximum number of CQE capacity IB/qib: Support creating qps with GFP_NOIO flag IB/qib: fix mcast detach when qp not attached IB/cm: Fix a recently introduced deadlock dmaengine: dw: disable BLOCK IRQs for non-cyclic xfer dmaengine: at_xdmac: fix resume for cyclic transfers dmaengine: dw: fix cyclic transfer callbacks dmaengine: dw: fix cyclic transfer setup nfit: fix multi-interface dimm handling, acpi6.1 compatibility ACPI / PCI / hotplug: unlock in error path in acpiphp_enable_slot() ACPI: Revert "ACPI / video: Add Dell Inspiron 5737 to the blacklist" ACPI / video: Add disable_backlight_sysfs_if quirk for the Toshiba Satellite R830 ACPI / video: Add disable_backlight_sysfs_if quirk for the Toshiba Portege R700 lib: sw842: select crc32 uapi: update install list after nvme.h rename ideapad-laptop: Add Lenovo Yoga 700 to no_hw_rfkill dmi list ideapad-laptop: Add Lenovo ideapad Y700-17ISK to no_hw_rfkill dmi list toshiba_acpi: Fix blank screen at boot if transflective backlight is supported make sure that freeing shmem fast symlinks is RCU-delayed drm/radeon/pm: adjust display configuration after powerstate drm/radeon: Don't hang in radeon_flip_work_func on disabled crtc. (v2) drm: Fix treatment of drm_vblank_offdelay in drm_vblank_on() (v2) drm: Fix drm_vblank_pre/post_modeset regression from Linux 4.4 drm: Prevent vblank counter bumps > 1 with active vblank clients. (v2) drm: No-Op redundant calls to drm_vblank_off() (v2) drm/radeon: use post-decrement in error handling drm/qxl: use kmalloc_array to alloc reloc_info in qxl_process_single_command drm/i915: fix error path in intel_setup_gmbus() drm/i915/dsi: don't pass arbitrary data to sideband drm/i915/dsi: defend gpio table against out of bounds access drm/i915/skl: Don't skip mst encoders in skl_ddi_pll_select() drm/i915: Don't reject primary plane windowing with color keying enabled on SKL+ drm/i915/dp: fall back to 18 bpp when sink capability is unknown drm/i915: Make sure DC writes are coherent on flush. drm/i915: Init power domains early in driver load drm/i915: intel_hpd_init(): Fix suspend/resume reprobing drm/i915: Restore inhibiting the load of the default context drm: fix missing reference counting decrease drm/radeon: hold reference to fences in radeon_sa_bo_new drm/radeon: mask out WC from BO on unsupported arches drm: add helper to check for wc memory support drm/radeon: fix DP audio support for APU with DCE4.1 display engine drm/radeon: Add a common function for DFS handling drm/radeon: cleaned up VCO output settings for DP audio drm/radeon: properly byte swap vce firmware setup drm/radeon: clean up fujitsu quirks drm/radeon: Fix "slow" audio over DP on DCE8+ drm/radeon: call hpd_irq_event on resume drm/radeon: Fix off-by-one errors in radeon_vm_bo_set_addr drm/dp/mst: deallocate payload on port destruction drm/dp/mst: Reverse order of MST enable and clearing VC payload table. drm/dp/mst: move GUID storage from mgr, port to only mst branch drm/dp/mst: Calculate MST PBN with 31.32 fixed point drm: Add drm_fixp_from_fraction and drm_fixp2int_ceil drm/dp/mst: fix in RAD element access drm/dp/mst: fix in MSTB RAD initialization drm/dp/mst: always send reply for UP request drm/dp/mst: process broadcast messages correctly drm/nouveau: platform: Fix deferred probe drm/nouveau/disp/dp: ensure sink is powered up before attempting link training drm/nouveau/display: Enable vblank irqs after display engine is on again. drm/nouveau/kms: take mode_config mutex in connector hotplug path drm/amdgpu/pm: adjust display configuration after powerstate drm/amdgpu: Don't hang in amdgpu_flip_work_func on disabled crtc. drm/amdgpu: use post-decrement in error handling drm/amdgpu: fix issue with overlapping userptrs drm/amdgpu: hold reference to fences in amdgpu_sa_bo_new (v2) drm/amdgpu: remove unnecessary forward declaration drm/amdgpu: fix s4 resume drm/amdgpu: remove exp hardware support from iceland drm/amdgpu: don't load MEC2 on topaz drm/amdgpu: drop topaz support from gmc8 module drm/amdgpu: pull topaz gmc bits into gmc_v7 drm/amdgpu: The VI specific EXE bit should only apply to GMC v8.0 above drm/amdgpu: iceland use CI based MC IP drm/amdgpu: move gmc7 support out of CIK dependency drm/amdgpu: no need to load MC firmware on fiji drm/amdgpu: fix amdgpu_bo_pin_restricted VRAM placing v2 drm/amdgpu: fix tonga smu resume drm/amdgpu: fix lost sync_to if scheduler is enabled. drm/amdgpu: call hpd_irq_event on resume drm/amdgpu: Fix off-by-one errors in amdgpu_vm_bo_map drm/vmwgfx: respect 'nomodeset' drm/vmwgfx: Fix a width / pitch mismatch on framebuffer updates drm/vmwgfx: Fix an incorrect lock check virtio_pci: fix use after free on release virtio_balloon: fix race between migration and ballooning virtio_balloon: fix race by fill and leak regulator: mt6311: MT6311_REGULATOR needs to select REGMAP_I2C regulator: axp20x: Fix GPIO LDO enable value for AXP22x clk: exynos: use irqsave version of spin_lock to avoid deadlock with irqs cxl: use correct operator when writing pcie config space values sparc64: fix incorrect sign extension in sys_sparc64_personality EDAC, mc_sysfs: Fix freeing bus' name EDAC: Robustify workqueues destruction MIPS: Fix buffer overflow in syscall_get_arguments() MIPS: Fix some missing CONFIG_CPU_MIPSR6 #ifdefs MIPS: hpet: Choose a safe value for the ETIME check MIPS: Loongson-3: Fix SMP_ASK_C0COUNT IPI handler Revert "MIPS: Fix PAGE_MASK definition" cputime: Prevent 32bit overflow in time[val|spec]_to_cputime() time: Avoid signed overflow in timekeeping_get_ns() Bluetooth: 6lowpan: Fix handling of uncompressed IPv6 packets Bluetooth: 6lowpan: Fix kernel NULL pointer dereferences Bluetooth: Fix incorrect removing of IRKs Bluetooth: Add support of Toshiba Broadcom based devices Bluetooth: Use continuous scanning when creating LE connections Drivers: hv: vmbus: Fix a Host signaling bug tools: hv: vss: fix the write()'s argument: error -> vss_msg mmc: sdhci: Allow override of get_cd() called from sdhci_request() mmc: sdhci: Allow override of mmc host operations mmc: sdhci-pci: Fix card detect race for Intel BXT/APL mmc: pxamci: fix again read-only gpio detection polarity mmc: sdhci-acpi: Fix card detect race for Intel BXT/APL mmc: mmci: fix an ages old detection error mmc: core: Enable tuning according to the actual timing mmc: sdhci: Fix sdhci_runtime_pm_bus_on/off() mmc: mmc: Fix incorrect use of driver strength switching HS200 and HS400 mmc: sdio: Fix invalid vdd in voltage switch power cycle mmc: sdhci: Fix DMA descriptor with zero data length mmc: sdhci-pci: Do not default to 33 Ohm driver strength for Intel SPT mmc: usdhi6rol0: handle NULL data in timeout clockevents/tcb_clksrc: Prevent disabling an already disabled clock posix-clock: Fix return code on the poll method's error path irqchip/gic-v3-its: Fix double ICC_EOIR write for LPI in EOImode==1 irqchip/atmel-aic: Fix wrong bit operation for IRQ priority irqchip/mxs: Add missing set_handle_irq() irqchip/omap-intc: Add support for spurious irq handling coresight: checking for NULL string in coresight_name_match() dm: fix dm_rq_target_io leak on faults with .request_fn DM w/ blk-mq paths dm snapshot: fix hung bios when copy error occurs dm space map metadata: remove unused variable in brb_pop() tda1004x: only update the frontend properties if locked vb2: fix a regression in poll() behavior for output,streams gspca: ov534/topro: prevent a division by 0 si2157: return -EINVAL if firmware blob is too big media: dvb-core: Don't force CAN_INVERSION_AUTO in oneshot mode rc: sunxi-cir: Initialize the spinlock properly namei: ->d_inode of a pinned dentry is stable only for positives mei: validate request value in client notify request ioctl mei: fix fasync return value on error rtlwifi: rtl8723be: Fix module parameter initialization rtlwifi: rtl8188ee: Fix module parameter initialization rtlwifi: rtl8192se: Fix module parameter initialization rtlwifi: rtl8723ae: Fix initialization of module parameters rtlwifi: rtl8192de: Fix incorrect module parameter descriptions rtlwifi: rtl8192ce: Fix handling of module parameters rtlwifi: rtl8192cu: Add missing parameter setup rtlwifi: rtl_pci: Fix kernel panic locks: fix unlock when fcntl_setlk races with a close um: link with -lpthread uml: fix hostfs mknod() uml: flush stdout before forking s390/fpu: signals vs. floating point control register s390/compat: correct restore of high gprs on signal return s390/dasd: fix performance drop s390/dasd: fix refcount for PAV reassignment s390/dasd: prevent incorrect length error under z/VM after PAV changes s390: fix normalization bug in exception table sorting btrfs: initialize the seq counter in struct btrfs_device Btrfs: Initialize btrfs_root->highest_objectid when loading tree root and subvolume roots Btrfs: fix transaction handle leak on failure to create hard link Btrfs: fix number of transaction units required to create symlink Btrfs: send, don't BUG_ON() when an empty symlink is found btrfs: statfs: report zero available if metadata are exhausted Btrfs: igrab inode in writepage Btrfs: add missing brelse when superblock checksum fails KVM: s390: fix memory overwrites when vx is disabled s390/kvm: remove dependency on struct save_area definition clocksource/drivers/vt8500: Increase the minimum delta genirq: Validate action before dereferencing it in handle_irq_event_percpu() mm: numa: quickly fail allocations for NUMA balancing on full nodes mm: thp: fix SMP race condition between THP page fault and MADV_DONTNEED ocfs2: unlock inode if deleting inode from orphan fails drm/i915: shut up gen8+ SDE irq dmesg noise iw_cxgb3: Fix incorrectly returning error on success spi: omap2-mcspi: Prevent duplicate gpio_request drivers: android: correct the size of struct binder_uintptr_t for BC_DEAD_BINDER_DONE USB: option: add "4G LTE usb-modem U901" USB: option: add support for SIM7100E USB: cp210x: add IDs for GE B650V3 and B850V3 boards usb: dwc3: Fix assignment of EP transfer resources can: ems_usb: Fix possible tx overflow dm thin: fix race condition when destroying thin pool workqueue bcache: Change refill_dirty() to always scan entire disk if necessary bcache: prevent crash on changing writeback_running bcache: allows use of register in udev to avoid "device_busy" error. bcache: unregister reboot notifier if bcache fails to unregister device bcache: fix a leak in bch_cached_dev_run() bcache: clear BCACHE_DEV_UNLINK_DONE flag when attaching a backing device bcache: Add a cond_resched() call to gc bcache: fix a livelock when we cause a huge number of cache misses lib/ucs2_string: Correct ucs2 -> utf8 conversion efi: Add pstore variables to the deletion whitelist efi: Make efivarfs entries immutable by default efi: Make our variable validation list include the guid efi: Do variable name validation tests in utf8 efi: Use ucs2_as_utf8 in efivarfs instead of open coding a bad version lib/ucs2_string: Add ucs2 -> utf8 helper functions ARM: 8457/1: psci-smp is built only for SMP drm/gma500: Use correct unref in the gem bo create function devm_memremap: Fix error value when memremap failed KVM: s390: fix guest fprs memory leak arm64: errata: Add -mpc-relative-literal-loads to build flags ARM: debug-ll: fix BCM63xx entry for multiplatform ext4: fix bh->b_state corruption sctp: Fix port hash table size computation unix_diag: fix incorrect sign extension in unix_lookup_by_ino tipc: unlock in error path rtnl: RTM_GETNETCONF: fix wrong return value IFF_NO_QUEUE: Fix for drivers not calling ether_setup() tcp/dccp: fix another race at listener dismantle route: check and remove route cache when we get route net_sched fix: reclassification needs to consider ether protocol changes pppoe: fix reference counting in PPPoE proxy l2tp: Fix error creating L2TP tunnels net/mlx4_en: Avoid changing dev->features directly in run-time net/mlx4_en: Choose time-stamping shift value according to HW frequency net/mlx4_en: Count HW buffer overrun only once qmi_wwan: add "4G LTE usb-modem U901" tcp: md5: release request socket instead of listener tipc: fix premature addition of node to lookup table af_unix: Guard against other == sk in unix_dgram_sendmsg af_unix: Don't set err in unix_stream_read_generic unless there was an error ipv4: fix memory leaks in ip_cmsg_send() callers bonding: Fix ARP monitor validation bpf: fix branch offset adjustment on backjumps after patching ctx expansion flow_dissector: Fix unaligned access in __skb_flow_dissector when used by eth_get_headlen net: Copy inner L3 and L4 headers as unaligned on GRE TEB sctp: translate network order to host order when users get a hmacid enic: increment devcmd2 result ring in case of timeout tg3: Fix for tg3 transmit queue 0 timed out when too many gso_segs net:Add sysctl_max_skb_frags tcp: do not drop syn_recv on all icmp reports unix: correctly track in-flight fds in sending process user_struct ipv6: fix a lockdep splat ipv6: addrconf: Fix recursive spin lock call ipv6/udp: use sticky pktinfo egress ifindex on connect() ipv6: enforce flowi6_oif usage in ip6_dst_lookup_tail() tcp: beware of alignments in tcp_get_info() switchdev: Require RTNL mutex to be held when sending FDB notifications inet: frag: Always orphan skbs inside ip_defrag() tipc: fix connection abort during subscription cancel net: dsa: fix mv88e6xxx switches sctp: allow setting SCTP_SACK_IMMEDIATELY by the application pptp: fix illegal memory access caused by multiple bind()s af_unix: fix struct pid memory leak tcp: fix NULL deref in tcp_v4_send_ack() lwt: fix rx checksum setting for lwt devices tunneling over ipv6 tunnels: Allow IPv6 UDP checksums to be correctly controlled. net: dp83640: Fix tx timestamp overflow handling. gro: Make GRO aware of lightweight tunnels. af_iucv: Validate socket address length in iucv_sock_bind() Conflicts: arch/arm64/Makefile arch/arm64/include/asm/cacheflush.h drivers/mmc/host/sdhci.c drivers/usb/dwc3/ep0.c drivers/usb/dwc3/gadget.c kernel/module.c sound/core/pcm_compat.c CRs-Fixed: 1010239 Signed-off-by: Runmin Wang <runminw@codeaurora.org> Change-Id: I41a28636fc9ad91f9d979b191784609476294cdf
1546 lines
37 KiB
C
1546 lines
37 KiB
C
/*
|
|
* linux/kernel/resource.c
|
|
*
|
|
* Copyright (C) 1999 Linus Torvalds
|
|
* Copyright (C) 1999 Martin Mares <mj@ucw.cz>
|
|
*
|
|
* Arbitrary resource management.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/export.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/ioport.h>
|
|
#include <linux/init.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/device.h>
|
|
#include <linux/pfn.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/resource_ext.h>
|
|
#include <asm/io.h>
|
|
|
|
|
|
struct resource ioport_resource = {
|
|
.name = "PCI IO",
|
|
.start = 0,
|
|
.end = IO_SPACE_LIMIT,
|
|
.flags = IORESOURCE_IO,
|
|
};
|
|
EXPORT_SYMBOL(ioport_resource);
|
|
|
|
struct resource iomem_resource = {
|
|
.name = "PCI mem",
|
|
.start = 0,
|
|
.end = -1,
|
|
.flags = IORESOURCE_MEM,
|
|
};
|
|
EXPORT_SYMBOL(iomem_resource);
|
|
|
|
/* constraints to be met while allocating resources */
|
|
struct resource_constraint {
|
|
resource_size_t min, max, align;
|
|
resource_size_t (*alignf)(void *, const struct resource *,
|
|
resource_size_t, resource_size_t);
|
|
void *alignf_data;
|
|
};
|
|
|
|
static DEFINE_RWLOCK(resource_lock);
|
|
|
|
/*
|
|
* For memory hotplug, there is no way to free resource entries allocated
|
|
* by boot mem after the system is up. So for reusing the resource entry
|
|
* we need to remember the resource.
|
|
*/
|
|
static struct resource *bootmem_resource_free;
|
|
static DEFINE_SPINLOCK(bootmem_resource_lock);
|
|
|
|
static struct resource *next_resource(struct resource *p, bool sibling_only)
|
|
{
|
|
/* Caller wants to traverse through siblings only */
|
|
if (sibling_only)
|
|
return p->sibling;
|
|
|
|
if (p->child)
|
|
return p->child;
|
|
while (!p->sibling && p->parent)
|
|
p = p->parent;
|
|
return p->sibling;
|
|
}
|
|
|
|
static void *r_next(struct seq_file *m, void *v, loff_t *pos)
|
|
{
|
|
struct resource *p = v;
|
|
(*pos)++;
|
|
return (void *)next_resource(p, false);
|
|
}
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
enum { MAX_IORES_LEVEL = 5 };
|
|
|
|
static void *r_start(struct seq_file *m, loff_t *pos)
|
|
__acquires(resource_lock)
|
|
{
|
|
struct resource *p = m->private;
|
|
loff_t l = 0;
|
|
read_lock(&resource_lock);
|
|
for (p = p->child; p && l < *pos; p = r_next(m, p, &l))
|
|
;
|
|
return p;
|
|
}
|
|
|
|
static void r_stop(struct seq_file *m, void *v)
|
|
__releases(resource_lock)
|
|
{
|
|
read_unlock(&resource_lock);
|
|
}
|
|
|
|
static int r_show(struct seq_file *m, void *v)
|
|
{
|
|
struct resource *root = m->private;
|
|
struct resource *r = v, *p;
|
|
int width = root->end < 0x10000 ? 4 : 8;
|
|
int depth;
|
|
|
|
for (depth = 0, p = r; depth < MAX_IORES_LEVEL; depth++, p = p->parent)
|
|
if (p->parent == root)
|
|
break;
|
|
seq_printf(m, "%*s%0*llx-%0*llx : %s\n",
|
|
depth * 2, "",
|
|
width, (unsigned long long) r->start,
|
|
width, (unsigned long long) r->end,
|
|
r->name ? r->name : "<BAD>");
|
|
return 0;
|
|
}
|
|
|
|
static const struct seq_operations resource_op = {
|
|
.start = r_start,
|
|
.next = r_next,
|
|
.stop = r_stop,
|
|
.show = r_show,
|
|
};
|
|
|
|
static int ioports_open(struct inode *inode, struct file *file)
|
|
{
|
|
int res = seq_open(file, &resource_op);
|
|
if (!res) {
|
|
struct seq_file *m = file->private_data;
|
|
m->private = &ioport_resource;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
static int iomem_open(struct inode *inode, struct file *file)
|
|
{
|
|
int res = seq_open(file, &resource_op);
|
|
if (!res) {
|
|
struct seq_file *m = file->private_data;
|
|
m->private = &iomem_resource;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
static const struct file_operations proc_ioports_operations = {
|
|
.open = ioports_open,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.release = seq_release,
|
|
};
|
|
|
|
static const struct file_operations proc_iomem_operations = {
|
|
.open = iomem_open,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.release = seq_release,
|
|
};
|
|
|
|
static int __init ioresources_init(void)
|
|
{
|
|
proc_create("ioports", 0, NULL, &proc_ioports_operations);
|
|
proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
|
|
return 0;
|
|
}
|
|
__initcall(ioresources_init);
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
static void free_resource(struct resource *res)
|
|
{
|
|
if (!res)
|
|
return;
|
|
|
|
if (!PageSlab(virt_to_head_page(res))) {
|
|
spin_lock(&bootmem_resource_lock);
|
|
res->sibling = bootmem_resource_free;
|
|
bootmem_resource_free = res;
|
|
spin_unlock(&bootmem_resource_lock);
|
|
} else {
|
|
kfree(res);
|
|
}
|
|
}
|
|
|
|
static struct resource *alloc_resource(gfp_t flags)
|
|
{
|
|
struct resource *res = NULL;
|
|
|
|
spin_lock(&bootmem_resource_lock);
|
|
if (bootmem_resource_free) {
|
|
res = bootmem_resource_free;
|
|
bootmem_resource_free = res->sibling;
|
|
}
|
|
spin_unlock(&bootmem_resource_lock);
|
|
|
|
if (res)
|
|
memset(res, 0, sizeof(struct resource));
|
|
else
|
|
res = kzalloc(sizeof(struct resource), flags);
|
|
|
|
return res;
|
|
}
|
|
|
|
/* Return the conflict entry if you can't request it */
|
|
static struct resource * __request_resource(struct resource *root, struct resource *new)
|
|
{
|
|
resource_size_t start = new->start;
|
|
resource_size_t end = new->end;
|
|
struct resource *tmp, **p;
|
|
|
|
if (end < start)
|
|
return root;
|
|
if (start < root->start)
|
|
return root;
|
|
if (end > root->end)
|
|
return root;
|
|
p = &root->child;
|
|
for (;;) {
|
|
tmp = *p;
|
|
if (!tmp || tmp->start > end) {
|
|
new->sibling = tmp;
|
|
*p = new;
|
|
new->parent = root;
|
|
return NULL;
|
|
}
|
|
p = &tmp->sibling;
|
|
if (tmp->end < start)
|
|
continue;
|
|
return tmp;
|
|
}
|
|
}
|
|
|
|
static int __release_resource(struct resource *old)
|
|
{
|
|
struct resource *tmp, **p;
|
|
|
|
p = &old->parent->child;
|
|
for (;;) {
|
|
tmp = *p;
|
|
if (!tmp)
|
|
break;
|
|
if (tmp == old) {
|
|
*p = tmp->sibling;
|
|
old->parent = NULL;
|
|
return 0;
|
|
}
|
|
p = &tmp->sibling;
|
|
}
|
|
return -EINVAL;
|
|
}
|
|
|
|
static void __release_child_resources(struct resource *r)
|
|
{
|
|
struct resource *tmp, *p;
|
|
resource_size_t size;
|
|
|
|
p = r->child;
|
|
r->child = NULL;
|
|
while (p) {
|
|
tmp = p;
|
|
p = p->sibling;
|
|
|
|
tmp->parent = NULL;
|
|
tmp->sibling = NULL;
|
|
__release_child_resources(tmp);
|
|
|
|
printk(KERN_DEBUG "release child resource %pR\n", tmp);
|
|
/* need to restore size, and keep flags */
|
|
size = resource_size(tmp);
|
|
tmp->start = 0;
|
|
tmp->end = size - 1;
|
|
}
|
|
}
|
|
|
|
void release_child_resources(struct resource *r)
|
|
{
|
|
write_lock(&resource_lock);
|
|
__release_child_resources(r);
|
|
write_unlock(&resource_lock);
|
|
}
|
|
|
|
/**
|
|
* request_resource_conflict - request and reserve an I/O or memory resource
|
|
* @root: root resource descriptor
|
|
* @new: resource descriptor desired by caller
|
|
*
|
|
* Returns 0 for success, conflict resource on error.
|
|
*/
|
|
struct resource *request_resource_conflict(struct resource *root, struct resource *new)
|
|
{
|
|
struct resource *conflict;
|
|
|
|
write_lock(&resource_lock);
|
|
conflict = __request_resource(root, new);
|
|
write_unlock(&resource_lock);
|
|
return conflict;
|
|
}
|
|
|
|
/**
|
|
* request_resource - request and reserve an I/O or memory resource
|
|
* @root: root resource descriptor
|
|
* @new: resource descriptor desired by caller
|
|
*
|
|
* Returns 0 for success, negative error code on error.
|
|
*/
|
|
int request_resource(struct resource *root, struct resource *new)
|
|
{
|
|
struct resource *conflict;
|
|
|
|
conflict = request_resource_conflict(root, new);
|
|
return conflict ? -EBUSY : 0;
|
|
}
|
|
|
|
EXPORT_SYMBOL(request_resource);
|
|
|
|
/**
|
|
* release_resource - release a previously reserved resource
|
|
* @old: resource pointer
|
|
*/
|
|
int release_resource(struct resource *old)
|
|
{
|
|
int retval;
|
|
|
|
write_lock(&resource_lock);
|
|
retval = __release_resource(old);
|
|
write_unlock(&resource_lock);
|
|
return retval;
|
|
}
|
|
|
|
EXPORT_SYMBOL(release_resource);
|
|
|
|
/*
|
|
* Finds the lowest iomem reosurce exists with-in [res->start.res->end)
|
|
* the caller must specify res->start, res->end, res->flags and "name".
|
|
* If found, returns 0, res is overwritten, if not found, returns -1.
|
|
* This walks through whole tree and not just first level children
|
|
* until and unless first_level_children_only is true.
|
|
*/
|
|
static int find_next_iomem_res(struct resource *res, char *name,
|
|
bool first_level_children_only)
|
|
{
|
|
resource_size_t start, end;
|
|
struct resource *p;
|
|
bool sibling_only = false;
|
|
|
|
BUG_ON(!res);
|
|
|
|
start = res->start;
|
|
end = res->end;
|
|
BUG_ON(start >= end);
|
|
|
|
if (first_level_children_only)
|
|
sibling_only = true;
|
|
|
|
read_lock(&resource_lock);
|
|
|
|
for (p = iomem_resource.child; p; p = next_resource(p, sibling_only)) {
|
|
if (p->flags != res->flags)
|
|
continue;
|
|
if (name && strcmp(p->name, name))
|
|
continue;
|
|
if (p->start > end) {
|
|
p = NULL;
|
|
break;
|
|
}
|
|
if ((p->end >= start) && (p->start < end))
|
|
break;
|
|
}
|
|
|
|
read_unlock(&resource_lock);
|
|
if (!p)
|
|
return -1;
|
|
/* copy data */
|
|
if (res->start < p->start)
|
|
res->start = p->start;
|
|
if (res->end > p->end)
|
|
res->end = p->end;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Walks through iomem resources and calls func() with matching resource
|
|
* ranges. This walks through whole tree and not just first level children.
|
|
* All the memory ranges which overlap start,end and also match flags and
|
|
* name are valid candidates.
|
|
*
|
|
* @name: name of resource
|
|
* @flags: resource flags
|
|
* @start: start addr
|
|
* @end: end addr
|
|
*/
|
|
int walk_iomem_res(char *name, unsigned long flags, u64 start, u64 end,
|
|
void *arg, int (*func)(u64, u64, void *))
|
|
{
|
|
struct resource res;
|
|
u64 orig_end;
|
|
int ret = -1;
|
|
|
|
res.start = start;
|
|
res.end = end;
|
|
res.flags = flags;
|
|
orig_end = res.end;
|
|
while ((res.start < res.end) &&
|
|
(!find_next_iomem_res(&res, name, false))) {
|
|
ret = (*func)(res.start, res.end, arg);
|
|
if (ret)
|
|
break;
|
|
res.start = res.end + 1;
|
|
res.end = orig_end;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* This function calls callback against all memory range of "System RAM"
|
|
* which are marked as IORESOURCE_MEM and IORESOUCE_BUSY.
|
|
* Now, this function is only for "System RAM". This function deals with
|
|
* full ranges and not pfn. If resources are not pfn aligned, dealing
|
|
* with pfn can truncate ranges.
|
|
*/
|
|
int walk_system_ram_res(u64 start, u64 end, void *arg,
|
|
int (*func)(u64, u64, void *))
|
|
{
|
|
struct resource res;
|
|
u64 orig_end;
|
|
int ret = -1;
|
|
|
|
res.start = start;
|
|
res.end = end;
|
|
res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
|
|
orig_end = res.end;
|
|
while ((res.start < res.end) &&
|
|
(!find_next_iomem_res(&res, "System RAM", true))) {
|
|
ret = (*func)(res.start, res.end, arg);
|
|
if (ret)
|
|
break;
|
|
res.start = res.end + 1;
|
|
res.end = orig_end;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
#if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
|
|
|
|
/*
|
|
* This function calls callback against all memory range of "System RAM"
|
|
* which are marked as IORESOURCE_MEM and IORESOUCE_BUSY.
|
|
* Now, this function is only for "System RAM".
|
|
*/
|
|
int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
|
|
void *arg, int (*func)(unsigned long, unsigned long, void *))
|
|
{
|
|
struct resource res;
|
|
unsigned long pfn, end_pfn;
|
|
u64 orig_end;
|
|
int ret = -1;
|
|
|
|
res.start = (u64) start_pfn << PAGE_SHIFT;
|
|
res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
|
|
res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
|
|
orig_end = res.end;
|
|
while ((res.start < res.end) &&
|
|
(find_next_iomem_res(&res, "System RAM", true) >= 0)) {
|
|
pfn = (res.start + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
end_pfn = (res.end + 1) >> PAGE_SHIFT;
|
|
if (end_pfn > pfn)
|
|
ret = (*func)(pfn, end_pfn - pfn, arg);
|
|
if (ret)
|
|
break;
|
|
res.start = res.end + 1;
|
|
res.end = orig_end;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
#endif
|
|
|
|
static int __is_ram(unsigned long pfn, unsigned long nr_pages, void *arg)
|
|
{
|
|
return 1;
|
|
}
|
|
/*
|
|
* This generic page_is_ram() returns true if specified address is
|
|
* registered as "System RAM" in iomem_resource list.
|
|
*/
|
|
int __weak page_is_ram(unsigned long pfn)
|
|
{
|
|
return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1;
|
|
}
|
|
EXPORT_SYMBOL_GPL(page_is_ram);
|
|
|
|
/**
|
|
* region_intersects() - determine intersection of region with known resources
|
|
* @start: region start address
|
|
* @size: size of region
|
|
* @name: name of resource (in iomem_resource)
|
|
*
|
|
* Check if the specified region partially overlaps or fully eclipses a
|
|
* resource identified by @name. Return REGION_DISJOINT if the region
|
|
* does not overlap @name, return REGION_MIXED if the region overlaps
|
|
* @type and another resource, and return REGION_INTERSECTS if the
|
|
* region overlaps @type and no other defined resource. Note, that
|
|
* REGION_INTERSECTS is also returned in the case when the specified
|
|
* region overlaps RAM and undefined memory holes.
|
|
*
|
|
* region_intersect() is used by memory remapping functions to ensure
|
|
* the user is not remapping RAM and is a vast speed up over walking
|
|
* through the resource table page by page.
|
|
*/
|
|
int region_intersects(resource_size_t start, size_t size, const char *name)
|
|
{
|
|
unsigned long flags = IORESOURCE_MEM | IORESOURCE_BUSY;
|
|
resource_size_t end = start + size - 1;
|
|
int type = 0; int other = 0;
|
|
struct resource *p;
|
|
|
|
read_lock(&resource_lock);
|
|
for (p = iomem_resource.child; p ; p = p->sibling) {
|
|
bool is_type = strcmp(p->name, name) == 0 && p->flags == flags;
|
|
|
|
if (start >= p->start && start <= p->end)
|
|
is_type ? type++ : other++;
|
|
if (end >= p->start && end <= p->end)
|
|
is_type ? type++ : other++;
|
|
if (p->start >= start && p->end <= end)
|
|
is_type ? type++ : other++;
|
|
}
|
|
read_unlock(&resource_lock);
|
|
|
|
if (other == 0)
|
|
return type ? REGION_INTERSECTS : REGION_DISJOINT;
|
|
|
|
if (type)
|
|
return REGION_MIXED;
|
|
|
|
return REGION_DISJOINT;
|
|
}
|
|
|
|
void __weak arch_remove_reservations(struct resource *avail)
|
|
{
|
|
}
|
|
|
|
static resource_size_t simple_align_resource(void *data,
|
|
const struct resource *avail,
|
|
resource_size_t size,
|
|
resource_size_t align)
|
|
{
|
|
return avail->start;
|
|
}
|
|
|
|
static void resource_clip(struct resource *res, resource_size_t min,
|
|
resource_size_t max)
|
|
{
|
|
if (res->start < min)
|
|
res->start = min;
|
|
if (res->end > max)
|
|
res->end = max;
|
|
}
|
|
|
|
/*
|
|
* Find empty slot in the resource tree with the given range and
|
|
* alignment constraints
|
|
*/
|
|
static int __find_resource(struct resource *root, struct resource *old,
|
|
struct resource *new,
|
|
resource_size_t size,
|
|
struct resource_constraint *constraint)
|
|
{
|
|
struct resource *this = root->child;
|
|
struct resource tmp = *new, avail, alloc;
|
|
|
|
tmp.start = root->start;
|
|
/*
|
|
* Skip past an allocated resource that starts at 0, since the assignment
|
|
* of this->start - 1 to tmp->end below would cause an underflow.
|
|
*/
|
|
if (this && this->start == root->start) {
|
|
tmp.start = (this == old) ? old->start : this->end + 1;
|
|
this = this->sibling;
|
|
}
|
|
for(;;) {
|
|
if (this)
|
|
tmp.end = (this == old) ? this->end : this->start - 1;
|
|
else
|
|
tmp.end = root->end;
|
|
|
|
if (tmp.end < tmp.start)
|
|
goto next;
|
|
|
|
resource_clip(&tmp, constraint->min, constraint->max);
|
|
arch_remove_reservations(&tmp);
|
|
|
|
/* Check for overflow after ALIGN() */
|
|
avail.start = ALIGN(tmp.start, constraint->align);
|
|
avail.end = tmp.end;
|
|
avail.flags = new->flags & ~IORESOURCE_UNSET;
|
|
if (avail.start >= tmp.start) {
|
|
alloc.flags = avail.flags;
|
|
alloc.start = constraint->alignf(constraint->alignf_data, &avail,
|
|
size, constraint->align);
|
|
alloc.end = alloc.start + size - 1;
|
|
if (resource_contains(&avail, &alloc)) {
|
|
new->start = alloc.start;
|
|
new->end = alloc.end;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
next: if (!this || this->end == root->end)
|
|
break;
|
|
|
|
if (this != old)
|
|
tmp.start = this->end + 1;
|
|
this = this->sibling;
|
|
}
|
|
return -EBUSY;
|
|
}
|
|
|
|
/*
|
|
* Find empty slot in the resource tree given range and alignment.
|
|
*/
|
|
static int find_resource(struct resource *root, struct resource *new,
|
|
resource_size_t size,
|
|
struct resource_constraint *constraint)
|
|
{
|
|
return __find_resource(root, NULL, new, size, constraint);
|
|
}
|
|
|
|
/**
|
|
* reallocate_resource - allocate a slot in the resource tree given range & alignment.
|
|
* The resource will be relocated if the new size cannot be reallocated in the
|
|
* current location.
|
|
*
|
|
* @root: root resource descriptor
|
|
* @old: resource descriptor desired by caller
|
|
* @newsize: new size of the resource descriptor
|
|
* @constraint: the size and alignment constraints to be met.
|
|
*/
|
|
static int reallocate_resource(struct resource *root, struct resource *old,
|
|
resource_size_t newsize,
|
|
struct resource_constraint *constraint)
|
|
{
|
|
int err=0;
|
|
struct resource new = *old;
|
|
struct resource *conflict;
|
|
|
|
write_lock(&resource_lock);
|
|
|
|
if ((err = __find_resource(root, old, &new, newsize, constraint)))
|
|
goto out;
|
|
|
|
if (resource_contains(&new, old)) {
|
|
old->start = new.start;
|
|
old->end = new.end;
|
|
goto out;
|
|
}
|
|
|
|
if (old->child) {
|
|
err = -EBUSY;
|
|
goto out;
|
|
}
|
|
|
|
if (resource_contains(old, &new)) {
|
|
old->start = new.start;
|
|
old->end = new.end;
|
|
} else {
|
|
__release_resource(old);
|
|
*old = new;
|
|
conflict = __request_resource(root, old);
|
|
BUG_ON(conflict);
|
|
}
|
|
out:
|
|
write_unlock(&resource_lock);
|
|
return err;
|
|
}
|
|
|
|
|
|
/**
|
|
* allocate_resource - allocate empty slot in the resource tree given range & alignment.
|
|
* The resource will be reallocated with a new size if it was already allocated
|
|
* @root: root resource descriptor
|
|
* @new: resource descriptor desired by caller
|
|
* @size: requested resource region size
|
|
* @min: minimum boundary to allocate
|
|
* @max: maximum boundary to allocate
|
|
* @align: alignment requested, in bytes
|
|
* @alignf: alignment function, optional, called if not NULL
|
|
* @alignf_data: arbitrary data to pass to the @alignf function
|
|
*/
|
|
int allocate_resource(struct resource *root, struct resource *new,
|
|
resource_size_t size, resource_size_t min,
|
|
resource_size_t max, resource_size_t align,
|
|
resource_size_t (*alignf)(void *,
|
|
const struct resource *,
|
|
resource_size_t,
|
|
resource_size_t),
|
|
void *alignf_data)
|
|
{
|
|
int err;
|
|
struct resource_constraint constraint;
|
|
|
|
if (!alignf)
|
|
alignf = simple_align_resource;
|
|
|
|
constraint.min = min;
|
|
constraint.max = max;
|
|
constraint.align = align;
|
|
constraint.alignf = alignf;
|
|
constraint.alignf_data = alignf_data;
|
|
|
|
if ( new->parent ) {
|
|
/* resource is already allocated, try reallocating with
|
|
the new constraints */
|
|
return reallocate_resource(root, new, size, &constraint);
|
|
}
|
|
|
|
write_lock(&resource_lock);
|
|
err = find_resource(root, new, size, &constraint);
|
|
if (err >= 0 && __request_resource(root, new))
|
|
err = -EBUSY;
|
|
write_unlock(&resource_lock);
|
|
return err;
|
|
}
|
|
|
|
EXPORT_SYMBOL(allocate_resource);
|
|
|
|
/**
|
|
* lookup_resource - find an existing resource by a resource start address
|
|
* @root: root resource descriptor
|
|
* @start: resource start address
|
|
*
|
|
* Returns a pointer to the resource if found, NULL otherwise
|
|
*/
|
|
struct resource *lookup_resource(struct resource *root, resource_size_t start)
|
|
{
|
|
struct resource *res;
|
|
|
|
read_lock(&resource_lock);
|
|
for (res = root->child; res; res = res->sibling) {
|
|
if (res->start == start)
|
|
break;
|
|
}
|
|
read_unlock(&resource_lock);
|
|
|
|
return res;
|
|
}
|
|
|
|
/*
|
|
* Insert a resource into the resource tree. If successful, return NULL,
|
|
* otherwise return the conflicting resource (compare to __request_resource())
|
|
*/
|
|
static struct resource * __insert_resource(struct resource *parent, struct resource *new)
|
|
{
|
|
struct resource *first, *next;
|
|
|
|
for (;; parent = first) {
|
|
first = __request_resource(parent, new);
|
|
if (!first)
|
|
return first;
|
|
|
|
if (first == parent)
|
|
return first;
|
|
if (WARN_ON(first == new)) /* duplicated insertion */
|
|
return first;
|
|
|
|
if ((first->start > new->start) || (first->end < new->end))
|
|
break;
|
|
if ((first->start == new->start) && (first->end == new->end))
|
|
break;
|
|
}
|
|
|
|
for (next = first; ; next = next->sibling) {
|
|
/* Partial overlap? Bad, and unfixable */
|
|
if (next->start < new->start || next->end > new->end)
|
|
return next;
|
|
if (!next->sibling)
|
|
break;
|
|
if (next->sibling->start > new->end)
|
|
break;
|
|
}
|
|
|
|
new->parent = parent;
|
|
new->sibling = next->sibling;
|
|
new->child = first;
|
|
|
|
next->sibling = NULL;
|
|
for (next = first; next; next = next->sibling)
|
|
next->parent = new;
|
|
|
|
if (parent->child == first) {
|
|
parent->child = new;
|
|
} else {
|
|
next = parent->child;
|
|
while (next->sibling != first)
|
|
next = next->sibling;
|
|
next->sibling = new;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
/**
|
|
* insert_resource_conflict - Inserts resource in the resource tree
|
|
* @parent: parent of the new resource
|
|
* @new: new resource to insert
|
|
*
|
|
* Returns 0 on success, conflict resource if the resource can't be inserted.
|
|
*
|
|
* This function is equivalent to request_resource_conflict when no conflict
|
|
* happens. If a conflict happens, and the conflicting resources
|
|
* entirely fit within the range of the new resource, then the new
|
|
* resource is inserted and the conflicting resources become children of
|
|
* the new resource.
|
|
*/
|
|
struct resource *insert_resource_conflict(struct resource *parent, struct resource *new)
|
|
{
|
|
struct resource *conflict;
|
|
|
|
write_lock(&resource_lock);
|
|
conflict = __insert_resource(parent, new);
|
|
write_unlock(&resource_lock);
|
|
return conflict;
|
|
}
|
|
|
|
/**
|
|
* insert_resource - Inserts a resource in the resource tree
|
|
* @parent: parent of the new resource
|
|
* @new: new resource to insert
|
|
*
|
|
* Returns 0 on success, -EBUSY if the resource can't be inserted.
|
|
*/
|
|
int insert_resource(struct resource *parent, struct resource *new)
|
|
{
|
|
struct resource *conflict;
|
|
|
|
conflict = insert_resource_conflict(parent, new);
|
|
return conflict ? -EBUSY : 0;
|
|
}
|
|
|
|
/**
|
|
* insert_resource_expand_to_fit - Insert a resource into the resource tree
|
|
* @root: root resource descriptor
|
|
* @new: new resource to insert
|
|
*
|
|
* Insert a resource into the resource tree, possibly expanding it in order
|
|
* to make it encompass any conflicting resources.
|
|
*/
|
|
void insert_resource_expand_to_fit(struct resource *root, struct resource *new)
|
|
{
|
|
if (new->parent)
|
|
return;
|
|
|
|
write_lock(&resource_lock);
|
|
for (;;) {
|
|
struct resource *conflict;
|
|
|
|
conflict = __insert_resource(root, new);
|
|
if (!conflict)
|
|
break;
|
|
if (conflict == root)
|
|
break;
|
|
|
|
/* Ok, expand resource to cover the conflict, then try again .. */
|
|
if (conflict->start < new->start)
|
|
new->start = conflict->start;
|
|
if (conflict->end > new->end)
|
|
new->end = conflict->end;
|
|
|
|
printk("Expanded resource %s due to conflict with %s\n", new->name, conflict->name);
|
|
}
|
|
write_unlock(&resource_lock);
|
|
}
|
|
|
|
static int __adjust_resource(struct resource *res, resource_size_t start,
|
|
resource_size_t size)
|
|
{
|
|
struct resource *tmp, *parent = res->parent;
|
|
resource_size_t end = start + size - 1;
|
|
int result = -EBUSY;
|
|
|
|
if (!parent)
|
|
goto skip;
|
|
|
|
if ((start < parent->start) || (end > parent->end))
|
|
goto out;
|
|
|
|
if (res->sibling && (res->sibling->start <= end))
|
|
goto out;
|
|
|
|
tmp = parent->child;
|
|
if (tmp != res) {
|
|
while (tmp->sibling != res)
|
|
tmp = tmp->sibling;
|
|
if (start <= tmp->end)
|
|
goto out;
|
|
}
|
|
|
|
skip:
|
|
for (tmp = res->child; tmp; tmp = tmp->sibling)
|
|
if ((tmp->start < start) || (tmp->end > end))
|
|
goto out;
|
|
|
|
res->start = start;
|
|
res->end = end;
|
|
result = 0;
|
|
|
|
out:
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* adjust_resource - modify a resource's start and size
|
|
* @res: resource to modify
|
|
* @start: new start value
|
|
* @size: new size
|
|
*
|
|
* Given an existing resource, change its start and size to match the
|
|
* arguments. Returns 0 on success, -EBUSY if it can't fit.
|
|
* Existing children of the resource are assumed to be immutable.
|
|
*/
|
|
int adjust_resource(struct resource *res, resource_size_t start,
|
|
resource_size_t size)
|
|
{
|
|
int result;
|
|
|
|
write_lock(&resource_lock);
|
|
result = __adjust_resource(res, start, size);
|
|
write_unlock(&resource_lock);
|
|
return result;
|
|
}
|
|
EXPORT_SYMBOL(adjust_resource);
|
|
|
|
static void __init __reserve_region_with_split(struct resource *root,
|
|
resource_size_t start, resource_size_t end,
|
|
const char *name)
|
|
{
|
|
struct resource *parent = root;
|
|
struct resource *conflict;
|
|
struct resource *res = alloc_resource(GFP_ATOMIC);
|
|
struct resource *next_res = NULL;
|
|
|
|
if (!res)
|
|
return;
|
|
|
|
res->name = name;
|
|
res->start = start;
|
|
res->end = end;
|
|
res->flags = IORESOURCE_BUSY;
|
|
|
|
while (1) {
|
|
|
|
conflict = __request_resource(parent, res);
|
|
if (!conflict) {
|
|
if (!next_res)
|
|
break;
|
|
res = next_res;
|
|
next_res = NULL;
|
|
continue;
|
|
}
|
|
|
|
/* conflict covered whole area */
|
|
if (conflict->start <= res->start &&
|
|
conflict->end >= res->end) {
|
|
free_resource(res);
|
|
WARN_ON(next_res);
|
|
break;
|
|
}
|
|
|
|
/* failed, split and try again */
|
|
if (conflict->start > res->start) {
|
|
end = res->end;
|
|
res->end = conflict->start - 1;
|
|
if (conflict->end < end) {
|
|
next_res = alloc_resource(GFP_ATOMIC);
|
|
if (!next_res) {
|
|
free_resource(res);
|
|
break;
|
|
}
|
|
next_res->name = name;
|
|
next_res->start = conflict->end + 1;
|
|
next_res->end = end;
|
|
next_res->flags = IORESOURCE_BUSY;
|
|
}
|
|
} else {
|
|
res->start = conflict->end + 1;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void __init reserve_region_with_split(struct resource *root,
|
|
resource_size_t start, resource_size_t end,
|
|
const char *name)
|
|
{
|
|
int abort = 0;
|
|
|
|
write_lock(&resource_lock);
|
|
if (root->start > start || root->end < end) {
|
|
pr_err("requested range [0x%llx-0x%llx] not in root %pr\n",
|
|
(unsigned long long)start, (unsigned long long)end,
|
|
root);
|
|
if (start > root->end || end < root->start)
|
|
abort = 1;
|
|
else {
|
|
if (end > root->end)
|
|
end = root->end;
|
|
if (start < root->start)
|
|
start = root->start;
|
|
pr_err("fixing request to [0x%llx-0x%llx]\n",
|
|
(unsigned long long)start,
|
|
(unsigned long long)end);
|
|
}
|
|
dump_stack();
|
|
}
|
|
if (!abort)
|
|
__reserve_region_with_split(root, start, end, name);
|
|
write_unlock(&resource_lock);
|
|
}
|
|
|
|
/**
|
|
* resource_alignment - calculate resource's alignment
|
|
* @res: resource pointer
|
|
*
|
|
* Returns alignment on success, 0 (invalid alignment) on failure.
|
|
*/
|
|
resource_size_t resource_alignment(struct resource *res)
|
|
{
|
|
switch (res->flags & (IORESOURCE_SIZEALIGN | IORESOURCE_STARTALIGN)) {
|
|
case IORESOURCE_SIZEALIGN:
|
|
return resource_size(res);
|
|
case IORESOURCE_STARTALIGN:
|
|
return res->start;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* This is compatibility stuff for IO resources.
|
|
*
|
|
* Note how this, unlike the above, knows about
|
|
* the IO flag meanings (busy etc).
|
|
*
|
|
* request_region creates a new busy region.
|
|
*
|
|
* release_region releases a matching busy region.
|
|
*/
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(muxed_resource_wait);
|
|
|
|
/**
|
|
* __request_region - create a new busy resource region
|
|
* @parent: parent resource descriptor
|
|
* @start: resource start address
|
|
* @n: resource region size
|
|
* @name: reserving caller's ID string
|
|
* @flags: IO resource flags
|
|
*/
|
|
struct resource * __request_region(struct resource *parent,
|
|
resource_size_t start, resource_size_t n,
|
|
const char *name, int flags)
|
|
{
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
struct resource *res = alloc_resource(GFP_KERNEL);
|
|
|
|
if (!res)
|
|
return NULL;
|
|
|
|
res->name = name;
|
|
res->start = start;
|
|
res->end = start + n - 1;
|
|
res->flags = resource_type(parent);
|
|
res->flags |= IORESOURCE_BUSY | flags;
|
|
|
|
write_lock(&resource_lock);
|
|
|
|
for (;;) {
|
|
struct resource *conflict;
|
|
|
|
conflict = __request_resource(parent, res);
|
|
if (!conflict)
|
|
break;
|
|
if (conflict != parent) {
|
|
if (!(conflict->flags & IORESOURCE_BUSY)) {
|
|
parent = conflict;
|
|
continue;
|
|
}
|
|
}
|
|
if (conflict->flags & flags & IORESOURCE_MUXED) {
|
|
add_wait_queue(&muxed_resource_wait, &wait);
|
|
write_unlock(&resource_lock);
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
schedule();
|
|
remove_wait_queue(&muxed_resource_wait, &wait);
|
|
write_lock(&resource_lock);
|
|
continue;
|
|
}
|
|
/* Uhhuh, that didn't work out.. */
|
|
free_resource(res);
|
|
res = NULL;
|
|
break;
|
|
}
|
|
write_unlock(&resource_lock);
|
|
return res;
|
|
}
|
|
EXPORT_SYMBOL(__request_region);
|
|
|
|
/**
|
|
* __release_region - release a previously reserved resource region
|
|
* @parent: parent resource descriptor
|
|
* @start: resource start address
|
|
* @n: resource region size
|
|
*
|
|
* The described resource region must match a currently busy region.
|
|
*/
|
|
void __release_region(struct resource *parent, resource_size_t start,
|
|
resource_size_t n)
|
|
{
|
|
struct resource **p;
|
|
resource_size_t end;
|
|
|
|
p = &parent->child;
|
|
end = start + n - 1;
|
|
|
|
write_lock(&resource_lock);
|
|
|
|
for (;;) {
|
|
struct resource *res = *p;
|
|
|
|
if (!res)
|
|
break;
|
|
if (res->start <= start && res->end >= end) {
|
|
if (!(res->flags & IORESOURCE_BUSY)) {
|
|
p = &res->child;
|
|
continue;
|
|
}
|
|
if (res->start != start || res->end != end)
|
|
break;
|
|
*p = res->sibling;
|
|
write_unlock(&resource_lock);
|
|
if (res->flags & IORESOURCE_MUXED)
|
|
wake_up(&muxed_resource_wait);
|
|
free_resource(res);
|
|
return;
|
|
}
|
|
p = &res->sibling;
|
|
}
|
|
|
|
write_unlock(&resource_lock);
|
|
|
|
printk(KERN_WARNING "Trying to free nonexistent resource "
|
|
"<%016llx-%016llx>\n", (unsigned long long)start,
|
|
(unsigned long long)end);
|
|
}
|
|
EXPORT_SYMBOL(__release_region);
|
|
|
|
#ifdef CONFIG_MEMORY_HOTREMOVE
|
|
/**
|
|
* release_mem_region_adjustable - release a previously reserved memory region
|
|
* @parent: parent resource descriptor
|
|
* @start: resource start address
|
|
* @size: resource region size
|
|
*
|
|
* This interface is intended for memory hot-delete. The requested region
|
|
* is released from a currently busy memory resource. The requested region
|
|
* must either match exactly or fit into a single busy resource entry. In
|
|
* the latter case, the remaining resource is adjusted accordingly.
|
|
* Existing children of the busy memory resource must be immutable in the
|
|
* request.
|
|
*
|
|
* Note:
|
|
* - Additional release conditions, such as overlapping region, can be
|
|
* supported after they are confirmed as valid cases.
|
|
* - When a busy memory resource gets split into two entries, the code
|
|
* assumes that all children remain in the lower address entry for
|
|
* simplicity. Enhance this logic when necessary.
|
|
*/
|
|
int release_mem_region_adjustable(struct resource *parent,
|
|
resource_size_t start, resource_size_t size)
|
|
{
|
|
struct resource **p;
|
|
struct resource *res;
|
|
struct resource *new_res;
|
|
resource_size_t end;
|
|
int ret = -EINVAL;
|
|
|
|
end = start + size - 1;
|
|
if ((start < parent->start) || (end > parent->end))
|
|
return ret;
|
|
|
|
/* The alloc_resource() result gets checked later */
|
|
new_res = alloc_resource(GFP_KERNEL);
|
|
|
|
p = &parent->child;
|
|
write_lock(&resource_lock);
|
|
|
|
while ((res = *p)) {
|
|
if (res->start >= end)
|
|
break;
|
|
|
|
/* look for the next resource if it does not fit into */
|
|
if (res->start > start || res->end < end) {
|
|
p = &res->sibling;
|
|
continue;
|
|
}
|
|
|
|
if (!(res->flags & IORESOURCE_MEM))
|
|
break;
|
|
|
|
if (!(res->flags & IORESOURCE_BUSY)) {
|
|
p = &res->child;
|
|
continue;
|
|
}
|
|
|
|
/* found the target resource; let's adjust accordingly */
|
|
if (res->start == start && res->end == end) {
|
|
/* free the whole entry */
|
|
*p = res->sibling;
|
|
free_resource(res);
|
|
ret = 0;
|
|
} else if (res->start == start && res->end != end) {
|
|
/* adjust the start */
|
|
ret = __adjust_resource(res, end + 1,
|
|
res->end - end);
|
|
} else if (res->start != start && res->end == end) {
|
|
/* adjust the end */
|
|
ret = __adjust_resource(res, res->start,
|
|
start - res->start);
|
|
} else {
|
|
/* split into two entries */
|
|
if (!new_res) {
|
|
ret = -ENOMEM;
|
|
break;
|
|
}
|
|
new_res->name = res->name;
|
|
new_res->start = end + 1;
|
|
new_res->end = res->end;
|
|
new_res->flags = res->flags;
|
|
new_res->parent = res->parent;
|
|
new_res->sibling = res->sibling;
|
|
new_res->child = NULL;
|
|
|
|
ret = __adjust_resource(res, res->start,
|
|
start - res->start);
|
|
if (ret)
|
|
break;
|
|
res->sibling = new_res;
|
|
new_res = NULL;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
write_unlock(&resource_lock);
|
|
free_resource(new_res);
|
|
return ret;
|
|
}
|
|
#endif /* CONFIG_MEMORY_HOTREMOVE */
|
|
|
|
/*
|
|
* Managed region resource
|
|
*/
|
|
static void devm_resource_release(struct device *dev, void *ptr)
|
|
{
|
|
struct resource **r = ptr;
|
|
|
|
release_resource(*r);
|
|
}
|
|
|
|
/**
|
|
* devm_request_resource() - request and reserve an I/O or memory resource
|
|
* @dev: device for which to request the resource
|
|
* @root: root of the resource tree from which to request the resource
|
|
* @new: descriptor of the resource to request
|
|
*
|
|
* This is a device-managed version of request_resource(). There is usually
|
|
* no need to release resources requested by this function explicitly since
|
|
* that will be taken care of when the device is unbound from its driver.
|
|
* If for some reason the resource needs to be released explicitly, because
|
|
* of ordering issues for example, drivers must call devm_release_resource()
|
|
* rather than the regular release_resource().
|
|
*
|
|
* When a conflict is detected between any existing resources and the newly
|
|
* requested resource, an error message will be printed.
|
|
*
|
|
* Returns 0 on success or a negative error code on failure.
|
|
*/
|
|
int devm_request_resource(struct device *dev, struct resource *root,
|
|
struct resource *new)
|
|
{
|
|
struct resource *conflict, **ptr;
|
|
|
|
ptr = devres_alloc(devm_resource_release, sizeof(*ptr), GFP_KERNEL);
|
|
if (!ptr)
|
|
return -ENOMEM;
|
|
|
|
*ptr = new;
|
|
|
|
conflict = request_resource_conflict(root, new);
|
|
if (conflict) {
|
|
dev_err(dev, "resource collision: %pR conflicts with %s %pR\n",
|
|
new, conflict->name, conflict);
|
|
devres_free(ptr);
|
|
return -EBUSY;
|
|
}
|
|
|
|
devres_add(dev, ptr);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(devm_request_resource);
|
|
|
|
static int devm_resource_match(struct device *dev, void *res, void *data)
|
|
{
|
|
struct resource **ptr = res;
|
|
|
|
return *ptr == data;
|
|
}
|
|
|
|
/**
|
|
* devm_release_resource() - release a previously requested resource
|
|
* @dev: device for which to release the resource
|
|
* @new: descriptor of the resource to release
|
|
*
|
|
* Releases a resource previously requested using devm_request_resource().
|
|
*/
|
|
void devm_release_resource(struct device *dev, struct resource *new)
|
|
{
|
|
WARN_ON(devres_release(dev, devm_resource_release, devm_resource_match,
|
|
new));
|
|
}
|
|
EXPORT_SYMBOL(devm_release_resource);
|
|
|
|
struct region_devres {
|
|
struct resource *parent;
|
|
resource_size_t start;
|
|
resource_size_t n;
|
|
};
|
|
|
|
static void devm_region_release(struct device *dev, void *res)
|
|
{
|
|
struct region_devres *this = res;
|
|
|
|
__release_region(this->parent, this->start, this->n);
|
|
}
|
|
|
|
static int devm_region_match(struct device *dev, void *res, void *match_data)
|
|
{
|
|
struct region_devres *this = res, *match = match_data;
|
|
|
|
return this->parent == match->parent &&
|
|
this->start == match->start && this->n == match->n;
|
|
}
|
|
|
|
struct resource * __devm_request_region(struct device *dev,
|
|
struct resource *parent, resource_size_t start,
|
|
resource_size_t n, const char *name)
|
|
{
|
|
struct region_devres *dr = NULL;
|
|
struct resource *res;
|
|
|
|
dr = devres_alloc(devm_region_release, sizeof(struct region_devres),
|
|
GFP_KERNEL);
|
|
if (!dr)
|
|
return NULL;
|
|
|
|
dr->parent = parent;
|
|
dr->start = start;
|
|
dr->n = n;
|
|
|
|
res = __request_region(parent, start, n, name, 0);
|
|
if (res)
|
|
devres_add(dev, dr);
|
|
else
|
|
devres_free(dr);
|
|
|
|
return res;
|
|
}
|
|
EXPORT_SYMBOL(__devm_request_region);
|
|
|
|
void __devm_release_region(struct device *dev, struct resource *parent,
|
|
resource_size_t start, resource_size_t n)
|
|
{
|
|
struct region_devres match_data = { parent, start, n };
|
|
|
|
__release_region(parent, start, n);
|
|
WARN_ON(devres_destroy(dev, devm_region_release, devm_region_match,
|
|
&match_data));
|
|
}
|
|
EXPORT_SYMBOL(__devm_release_region);
|
|
|
|
/*
|
|
* Called from init/main.c to reserve IO ports.
|
|
*/
|
|
#define MAXRESERVE 4
|
|
static int __init reserve_setup(char *str)
|
|
{
|
|
static int reserved;
|
|
static struct resource reserve[MAXRESERVE];
|
|
|
|
for (;;) {
|
|
unsigned int io_start, io_num;
|
|
int x = reserved;
|
|
|
|
if (get_option (&str, &io_start) != 2)
|
|
break;
|
|
if (get_option (&str, &io_num) == 0)
|
|
break;
|
|
if (x < MAXRESERVE) {
|
|
struct resource *res = reserve + x;
|
|
res->name = "reserved";
|
|
res->start = io_start;
|
|
res->end = io_start + io_num - 1;
|
|
res->flags = IORESOURCE_BUSY;
|
|
res->child = NULL;
|
|
if (request_resource(res->start >= 0x10000 ? &iomem_resource : &ioport_resource, res) == 0)
|
|
reserved = x+1;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
__setup("reserve=", reserve_setup);
|
|
|
|
/*
|
|
* Check if the requested addr and size spans more than any slot in the
|
|
* iomem resource tree.
|
|
*/
|
|
int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
|
|
{
|
|
struct resource *p = &iomem_resource;
|
|
int err = 0;
|
|
loff_t l;
|
|
|
|
read_lock(&resource_lock);
|
|
for (p = p->child; p ; p = r_next(NULL, p, &l)) {
|
|
/*
|
|
* We can probably skip the resources without
|
|
* IORESOURCE_IO attribute?
|
|
*/
|
|
if (p->start >= addr + size)
|
|
continue;
|
|
if (p->end < addr)
|
|
continue;
|
|
if (PFN_DOWN(p->start) <= PFN_DOWN(addr) &&
|
|
PFN_DOWN(p->end) >= PFN_DOWN(addr + size - 1))
|
|
continue;
|
|
/*
|
|
* if a resource is "BUSY", it's not a hardware resource
|
|
* but a driver mapping of such a resource; we don't want
|
|
* to warn for those; some drivers legitimately map only
|
|
* partial hardware resources. (example: vesafb)
|
|
*/
|
|
if (p->flags & IORESOURCE_BUSY)
|
|
continue;
|
|
|
|
printk(KERN_WARNING "resource sanity check: requesting [mem %#010llx-%#010llx], which spans more than %s %pR\n",
|
|
(unsigned long long)addr,
|
|
(unsigned long long)(addr + size - 1),
|
|
p->name, p);
|
|
err = -1;
|
|
break;
|
|
}
|
|
read_unlock(&resource_lock);
|
|
|
|
return err;
|
|
}
|
|
|
|
#ifdef CONFIG_STRICT_DEVMEM
|
|
static int strict_iomem_checks = 1;
|
|
#else
|
|
static int strict_iomem_checks;
|
|
#endif
|
|
|
|
/*
|
|
* check if an address is reserved in the iomem resource tree
|
|
* returns 1 if reserved, 0 if not reserved.
|
|
*/
|
|
int iomem_is_exclusive(u64 addr)
|
|
{
|
|
struct resource *p = &iomem_resource;
|
|
int err = 0;
|
|
loff_t l;
|
|
int size = PAGE_SIZE;
|
|
|
|
if (!strict_iomem_checks)
|
|
return 0;
|
|
|
|
addr = addr & PAGE_MASK;
|
|
|
|
read_lock(&resource_lock);
|
|
for (p = p->child; p ; p = r_next(NULL, p, &l)) {
|
|
/*
|
|
* We can probably skip the resources without
|
|
* IORESOURCE_IO attribute?
|
|
*/
|
|
if (p->start >= addr + size)
|
|
break;
|
|
if (p->end < addr)
|
|
continue;
|
|
if (p->flags & IORESOURCE_BUSY &&
|
|
p->flags & IORESOURCE_EXCLUSIVE) {
|
|
err = 1;
|
|
break;
|
|
}
|
|
}
|
|
read_unlock(&resource_lock);
|
|
|
|
return err;
|
|
}
|
|
|
|
struct resource_entry *resource_list_create_entry(struct resource *res,
|
|
size_t extra_size)
|
|
{
|
|
struct resource_entry *entry;
|
|
|
|
entry = kzalloc(sizeof(*entry) + extra_size, GFP_KERNEL);
|
|
if (entry) {
|
|
INIT_LIST_HEAD(&entry->node);
|
|
entry->res = res ? res : &entry->__res;
|
|
}
|
|
|
|
return entry;
|
|
}
|
|
EXPORT_SYMBOL(resource_list_create_entry);
|
|
|
|
void resource_list_free(struct list_head *head)
|
|
{
|
|
struct resource_entry *entry, *tmp;
|
|
|
|
list_for_each_entry_safe(entry, tmp, head, node)
|
|
resource_list_destroy_entry(entry);
|
|
}
|
|
EXPORT_SYMBOL(resource_list_free);
|
|
|
|
static int __init strict_iomem(char *str)
|
|
{
|
|
if (strstr(str, "relaxed"))
|
|
strict_iomem_checks = 0;
|
|
if (strstr(str, "strict"))
|
|
strict_iomem_checks = 1;
|
|
return 1;
|
|
}
|
|
|
|
__setup("iomem=", strict_iomem);
|