Changes in 4.9.276 ALSA: usb-audio: fix rate on Ozone Z90 USB headset media: dvb-usb: fix wrong definition Input: usbtouchscreen - fix control-request directions net: can: ems_usb: fix use-after-free in ems_usb_disconnect() usb: gadget: eem: fix echo command packet response issue USB: cdc-acm: blacklist Heimann USB Appset device ntfs: fix validity check for file name attribute iov_iter_fault_in_readable() should do nothing in xarray case Input: joydev - prevent use of not validated data in JSIOCSBTNMAP ioctl ARM: dts: at91: sama5d4: fix pinctrl muxing btrfs: clear defrag status of a root if starting transaction fails ext4: fix kernel infoleak via ext4_extent_header ext4: correct the cache_nr in tracepoint ext4_es_shrink_exit ext4: remove check for zero nr_to_scan in ext4_es_scan() ext4: fix avefreec in find_group_orlov SUNRPC: Fix the batch tasks count wraparound. SUNRPC: Should wake up the privileged task firstly. s390/cio: dont call css_wait_for_slow_path() inside a lock iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR iio: ltr501: ltr501_read_ps(): add missing endianness conversion serial: sh-sci: Stop dmaengine transfer in sci_stop_tx() serial_cs: Add Option International GSM-Ready 56K/ISDN modem serial_cs: remove wrong GLOBETROTTER.cis entry ath9k: Fix kernel NULL pointer dereference during ath_reset_internal() ssb: sdio: Don't overwrite const buffer if block_write fails seq_buf: Make trace_seq_putmem_hex() support data longer than 8 fuse: check connected before queueing on fpq->io spi: spi-loopback-test: Fix 'tx_buf' might be 'rx_buf' spi: spi-topcliff-pch: Fix potential double free in pch_spi_process_messages() spi: omap-100k: Fix the length judgment problem crypto: nx - add missing MODULE_DEVICE_TABLE media: cpia2: fix memory leak in cpia2_usb_probe media: cobalt: fix race condition in setting HPD media: pvrusb2: fix warning in pvr2_i2c_core_done crypto: qat - check return code of qat_hal_rd_rel_reg() crypto: qat - remove unused macro in FW loader media: v4l2-core: Avoid the dangling pointer in v4l2_fh_release media: bt8xx: Fix a missing check bug in bt878_probe media: st-hva: Fix potential NULL pointer dereferences mmc: via-sdmmc: add a check against NULL pointer dereference crypto: shash - avoid comparing pointers to exported functions under CFI media: dvb_net: avoid speculation from net slot media: siano: fix device register error path btrfs: abort transaction if we fail to update the delayed inode btrfs: disable build on platforms having page size 256K regulator: da9052: Ensure enough delay time for .set_voltage_time_sel ACPI: processor idle: Fix up C-state latency if not ordered block_dump: remove block_dump feature in mark_inode_dirty() fs: dlm: cancel work sync othercon random32: Fix implicit truncation warning in prandom_seed_state() fs: dlm: fix memory leak when fenced ACPI: bus: Call kobject_put() in acpi_init() error path platform/x86: toshiba_acpi: Fix missing error code in toshiba_acpi_setup_keyboard() ACPI: tables: Add custom DSDT file as makefile prerequisite ia64: mca_drv: fix incorrect array size calculation media: s5p_cec: decrement usage count if disabled crypto: ixp4xx - dma_unmap the correct address crypto: ux500 - Fix error return code in hash_hw_final() sata_highbank: fix deferred probing pata_rb532_cf: fix deferred probing media: I2C: change 'RST' to "RSET" to fix multiple build errors pata_octeon_cf: avoid WARN_ON() in ata_host_activate() pata_ep93xx: fix deferred probing media: tc358743: Fix error return code in tc358743_probe_of() media: siano: Fix out-of-bounds warnings in smscore_load_firmware_family2() mmc: usdhi6rol0: fix error return code in usdhi6_probe() media: s5p-g2d: Fix a memory leak on ctx->fh.m2m_ctx hwmon: (max31722) Remove non-standard ACPI device IDs hwmon: (max31790) Fix fan speed reporting for fan7..12 spi: spi-sun6i: Fix chipselect/clock bug crypto: nx - Fix RCU warning in nx842_OF_upd_status ACPI: sysfs: Fix a buffer overrun problem with description_show() ocfs2: fix snprintf() checking net: pch_gbe: Propagate error from devm_gpio_request_one() ehea: fix error return code in ehea_restart_qps() RDMA/rxe: Fix failure during driver load drm: qxl: ensure surf.data is ininitialized wireless: carl9170: fix LEDS build errors & warnings brcmsmac: mac80211_if: Fix a resource leak in an error handling path ath10k: Fix an error code in ath10k_add_interface() netlabel: Fix memory leak in netlbl_mgmt_add_common netfilter: nft_exthdr: check for IPv6 packet before further processing net: ethernet: aeroflex: fix UAF in greth_of_remove net: ethernet: ezchip: fix UAF in nps_enet_remove net: ethernet: ezchip: fix error handling vxlan: add missing rcu_read_lock() in neigh_reduce() i40e: Fix error handling in i40e_vsi_open Bluetooth: mgmt: Fix slab-out-of-bounds in tlv_data_is_valid writeback: fix obtain a reference to a freeing memcg css net: sched: fix warning in tcindex_alloc_perfect_hash tty: nozomi: Fix a resource leak in an error handling function iio: adis_buffer: do not return ints in irq handlers iio: accel: bma180: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: bma220: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: kxcjk-1013: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: stk8312: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: stk8ba50: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: ti-ads1015: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: vf610: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: gyro: bmg160: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: humidity: am2315: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: pulsed-light: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: isl29125: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: tcs3414: Fix buffer alignment in iio_push_to_buffers_with_timestamp() Input: hil_kbd - fix error return code in hil_dev_connect() char: pcmcia: error out if 'num_bytes_read' is greater than 4 in set_protocol() tty: nozomi: Fix the error handling path of 'nozomi_card_init()' scsi: FlashPoint: Rename si_flags field s390: appldata depends on PROC_SYSCTL staging: gdm724x: check for buffer overflow in gdm_lte_multi_sdu_pkt() staging: gdm724x: check for overflow in gdm_lte_netif_rx() of: Fix truncation of memory sizes on 32-bit platforms scsi: mpt3sas: Fix error return value in _scsih_expander_add() phy: ti: dm816x: Fix the error handling path in 'dm816x_usb_phy_probe() extcon: sm5502: Drop invalid register write in sm5502_reg_data extcon: max8997: Add missing modalias string configfs: fix memleak in configfs_release_bin_file leds: ktd2692: Fix an error handling path mm/huge_memory.c: don't discard hugepage if other processes are mapping it selftests/vm/pkeys: fix alloc_random_pkey() to make it really, really random mmc: vub3000: fix control-request direction scsi: core: Retry I/O for Notify (Enable Spinup) Required error net: pch_gbe: Use proper accessors to BE data in pch_ptp_match() hugetlb: clear huge pte during flush function on mips platform atm: iphase: fix possible use-after-free in ia_module_exit() mISDN: fix possible use-after-free in HFC_cleanup() atm: nicstar: Fix possible use-after-free in nicstar_cleanup() net: Treat __napi_schedule_irqoff() as __napi_schedule() on PREEMPT_RT reiserfs: add check for invalid 1st journal block drm/virtio: Fix double free on probe failure udf: Fix NULL pointer dereference in udf_symlink function e100: handle eeprom as little endian clk: tegra: Ensure that PLLU configuration is applied properly ipv6: use prandom_u32() for ID generation RDMA/cxgb4: Fix missing error code in create_qp() dm space maps: don't reset space map allocation cursor when committing net: micrel: check return value after calling platform_get_resource() fjes: check return value after calling platform_get_resource() selinux: use __GFP_NOWARN with GFP_NOWAIT in the AVC xfrm: Fix error reporting in xfrm_state_construct. wlcore/wl12xx: Fix wl12xx get_mac error if device is in ELP wl1251: Fix possible buffer overflow in wl1251_cmd_scan cw1200: add missing MODULE_DEVICE_TABLE MIPS: add PMD table accounting into MIPS'pmd_alloc_one atm: nicstar: use 'dma_free_coherent' instead of 'kfree' atm: nicstar: register the interrupt handler in the right place RDMA/rxe: Don't overwrite errno from ib_umem_get() sfc: avoid double pci_remove of VFs sfc: error code if SRIOV cannot be disabled wireless: wext-spy: Fix out-of-bounds warning RDMA/cma: Fix rdma_resolve_route() memory leak Bluetooth: Fix the HCI to MGMT status conversion table Bluetooth: Shutdown controller after workqueues are flushed or cancelled Bluetooth: btusb: fix bt fiwmare downloading failure issue for qca btsoc. sctp: add size validation when walking chunks fuse: reject internal errno can: gw: synchronize rcu operations before removing gw job entry can: bcm: delay release of struct bcm_op after synchronize_rcu() mac80211: fix memory corruption in EAPOL handling powerpc/barrier: Avoid collision with clang's __lwsync macro pinctrl/amd: Add device HID for new AMD GPIO controller mmc: sdhci: Fix warning message when accessing RPMB in HS400 mode mmc: core: clear flags before allowing to retune ata: ahci_sunxi: Disable DIPM ASoC: tegra: Set driver_name=tegra for all machine drivers qemu_fw_cfg: Make fw_cfg_rev_attr a proper kobj_attribute ipmi/watchdog: Stop watchdog timer when the current action is 'none' power: supply: ab8500: Fix an old bug seq_buf: Fix overflow in seq_buf_putmem_hex() ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe dm btree remove: assign new_root only when removal succeeds media: dtv5100: fix control-request directions media: zr364xx: fix memory leak in zr364xx_start_readpipe media: gspca/sq905: fix control-request direction media: gspca/sunplus: fix zero-length control requests media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K jfs: fix GPF in diFree smackfs: restrict bytes count in smk_set_cipso() KVM: x86: Use guest MAXPHYADDR from CPUID.0x8000_0008 iff TDP is enabled KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run() scsi: core: Fix bad pointer dereference when ehandler kthread is invalid tracing: Do not reference char * as a string in histograms fscrypt: don't ignore minor_hash when hash is 0 tty: serial: fsl_lpuart: fix the potential risk of division or modulo by zero misc/libmasm/module: Fix two use after free in ibmasm_init_one Revert "ALSA: bebob/oxfw: fix Kconfig entry for Mackie d.2 Pro" scsi: lpfc: Fix "Unexpected timeout" error in direct attach topology tty: serial: 8250: serial_cs: Fix a memory leak in error handling path fs/jfs: Fix missing error code in lmLogInit() scsi: iscsi: Add iscsi_cls_conn refcount helpers mfd: da9052/stmpe: Add and modify MODULE_DEVICE_TABLE s390/sclp_vt220: fix console name to match device ALSA: sb: Fix potential double-free of CSP mixer elements powerpc/ps3: Add dma_mask to ps3_dma_region gpio: zynq: Check return value of pm_runtime_get_sync ALSA: ppc: fix error return code in snd_pmac_probe() selftests/powerpc: Fix "no_handler" EBB selftest ASoC: soc-core: Fix the error return code in snd_soc_of_parse_audio_routing() ALSA: bebob: add support for ToneWeal FW66 usb: gadget: f_hid: fix endianness issue with descriptors usb: gadget: hid: fix error return code in hid_bind() powerpc/boot: Fixup device-tree on little endian backlight: lm3630a: Fix return code of .update_status() callback ALSA: hda: Add IRQ check for platform_get_irq() i2c: core: Disable client irq on reboot/shutdown lib/decompress_unlz4.c: correctly handle zero-padding around initrds. pwm: spear: Don't modify HW state in .remove callback power: supply: ab8500: Avoid NULL pointers power: reset: gpio-poweroff: add missing MODULE_DEVICE_TABLE ARM: 9087/1: kprobes: test-thumb: fix for LLVM_IAS=1 watchdog: Fix possible use-after-free in wdt_startup() watchdog: sc520_wdt: Fix possible use-after-free in wdt_turnoff() watchdog: Fix possible use-after-free by calling del_timer_sync() x86/fpu: Return proper error codes from user access functions orangefs: fix orangefs df output. ceph: remove bogus checks and WARN_ONs from ceph_set_page_dirty power: supply: charger-manager: add missing MODULE_DEVICE_TABLE power: supply: ab8500: add missing MODULE_DEVICE_TABLE pwm: tegra: Don't modify HW state in .remove callback ACPI: AMBA: Fix resource name in /proc/iomem virtio-blk: Fix memory leak among suspend/resume procedure virtio_console: Assure used length from device is limited PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun power: supply: rt5033_battery: Fix device tree enumeration um: fix error return code in slip_open() um: fix error return code in winch_tramp() watchdog: aspeed: fix hardware timeout calculation nfs: fix acl memory leak of posix_acl_create() ubifs: Set/Clear I_LINKABLE under i_lock for whiteout inode x86/fpu: Limit xstate copy size in xstateregs_set() ALSA: isa: Fix error return code in snd_cmi8330_probe() hexagon: use common DISCARDS macro ARM: dts: exynos: fix PWM LED max brightness on Odroid XU/XU3 ARM: dts: exynos: fix PWM LED max brightness on Odroid XU4 rtc: fix snprintf() checking in is_rtc_hctosys() ARM: dts: r8a7779, marzen: Fix DU clock names reset: bail if try_module_get() fails memory: fsl_ifc: fix leak of IO mapping on probe failure memory: fsl_ifc: fix leak of private memory on probe failure ARM: dts: am335x: align ti,pindir-d0-out-d1-in property with dt-shema scsi: be2iscsi: Fix an error handling path in beiscsi_dev_probe() mips: always link byteswap helpers into decompressor mips: disable branch profiling in boot/decompress.o MIPS: vdso: Invalid GIC access through VDSO seq_file: disallow extremely large seq buffer allocations Linux 4.9.276 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I595c090068eb1b1934b15a0d54394abc38b4b0cc
382 lines
8.7 KiB
C
382 lines
8.7 KiB
C
/*
|
|
* devtree.c - convenience functions for device tree manipulation
|
|
* Copyright 2007 David Gibson, IBM Corporation.
|
|
* Copyright (c) 2007 Freescale Semiconductor, Inc.
|
|
*
|
|
* Authors: David Gibson <david@gibson.dropbear.id.au>
|
|
* Scott Wood <scottwood@freescale.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*/
|
|
#include <stdarg.h>
|
|
#include <stddef.h>
|
|
#include "types.h"
|
|
#include "string.h"
|
|
#include "stdio.h"
|
|
#include "ops.h"
|
|
#include "of.h"
|
|
|
|
void dt_fixup_memory(u64 start, u64 size)
|
|
{
|
|
void *root, *memory;
|
|
int naddr, nsize, i;
|
|
u32 memreg[4];
|
|
|
|
root = finddevice("/");
|
|
if (getprop(root, "#address-cells", &naddr, sizeof(naddr)) < 0)
|
|
naddr = 2;
|
|
else
|
|
naddr = be32_to_cpu(naddr);
|
|
if (naddr < 1 || naddr > 2)
|
|
fatal("Can't cope with #address-cells == %d in /\n\r", naddr);
|
|
|
|
if (getprop(root, "#size-cells", &nsize, sizeof(nsize)) < 0)
|
|
nsize = 1;
|
|
else
|
|
nsize = be32_to_cpu(nsize);
|
|
if (nsize < 1 || nsize > 2)
|
|
fatal("Can't cope with #size-cells == %d in /\n\r", nsize);
|
|
|
|
i = 0;
|
|
if (naddr == 2)
|
|
memreg[i++] = cpu_to_be32(start >> 32);
|
|
memreg[i++] = cpu_to_be32(start & 0xffffffff);
|
|
if (nsize == 2)
|
|
memreg[i++] = cpu_to_be32(size >> 32);
|
|
memreg[i++] = cpu_to_be32(size & 0xffffffff);
|
|
|
|
memory = finddevice("/memory");
|
|
if (! memory) {
|
|
memory = create_node(NULL, "memory");
|
|
setprop_str(memory, "device_type", "memory");
|
|
}
|
|
|
|
printf("Memory <- <0x%x", be32_to_cpu(memreg[0]));
|
|
for (i = 1; i < (naddr + nsize); i++)
|
|
printf(" 0x%x", be32_to_cpu(memreg[i]));
|
|
printf("> (%ldMB)\n\r", (unsigned long)(size >> 20));
|
|
|
|
setprop(memory, "reg", memreg, (naddr + nsize)*sizeof(u32));
|
|
}
|
|
|
|
#define MHZ(x) ((x + 500000) / 1000000)
|
|
|
|
void dt_fixup_cpu_clocks(u32 cpu, u32 tb, u32 bus)
|
|
{
|
|
void *devp = NULL;
|
|
|
|
printf("CPU clock-frequency <- 0x%x (%dMHz)\n\r", cpu, MHZ(cpu));
|
|
printf("CPU timebase-frequency <- 0x%x (%dMHz)\n\r", tb, MHZ(tb));
|
|
if (bus > 0)
|
|
printf("CPU bus-frequency <- 0x%x (%dMHz)\n\r", bus, MHZ(bus));
|
|
|
|
while ((devp = find_node_by_devtype(devp, "cpu"))) {
|
|
setprop_val(devp, "clock-frequency", cpu_to_be32(cpu));
|
|
setprop_val(devp, "timebase-frequency", cpu_to_be32(tb));
|
|
if (bus > 0)
|
|
setprop_val(devp, "bus-frequency", cpu_to_be32(bus));
|
|
}
|
|
|
|
timebase_period_ns = 1000000000 / tb;
|
|
}
|
|
|
|
void dt_fixup_clock(const char *path, u32 freq)
|
|
{
|
|
void *devp = finddevice(path);
|
|
|
|
if (devp) {
|
|
printf("%s: clock-frequency <- %x (%dMHz)\n\r", path, freq, MHZ(freq));
|
|
setprop_val(devp, "clock-frequency", cpu_to_be32(freq));
|
|
}
|
|
}
|
|
|
|
void dt_fixup_mac_address_by_alias(const char *alias, const u8 *addr)
|
|
{
|
|
void *devp = find_node_by_alias(alias);
|
|
|
|
if (devp) {
|
|
printf("%s: local-mac-address <-"
|
|
" %02x:%02x:%02x:%02x:%02x:%02x\n\r", alias,
|
|
addr[0], addr[1], addr[2],
|
|
addr[3], addr[4], addr[5]);
|
|
|
|
setprop(devp, "local-mac-address", addr, 6);
|
|
}
|
|
}
|
|
|
|
void dt_fixup_mac_address(u32 index, const u8 *addr)
|
|
{
|
|
void *devp = find_node_by_prop_value(NULL, "linux,network-index",
|
|
(void*)&index, sizeof(index));
|
|
|
|
if (devp) {
|
|
printf("ENET%d: local-mac-address <-"
|
|
" %02x:%02x:%02x:%02x:%02x:%02x\n\r", index,
|
|
addr[0], addr[1], addr[2],
|
|
addr[3], addr[4], addr[5]);
|
|
|
|
setprop(devp, "local-mac-address", addr, 6);
|
|
}
|
|
}
|
|
|
|
void __dt_fixup_mac_addresses(u32 startindex, ...)
|
|
{
|
|
va_list ap;
|
|
u32 index = startindex;
|
|
const u8 *addr;
|
|
|
|
va_start(ap, startindex);
|
|
|
|
while ((addr = va_arg(ap, const u8 *)))
|
|
dt_fixup_mac_address(index++, addr);
|
|
|
|
va_end(ap);
|
|
}
|
|
|
|
#define MAX_ADDR_CELLS 4
|
|
|
|
void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize)
|
|
{
|
|
if (getprop(node, "#address-cells", naddr, 4) != 4)
|
|
*naddr = 2;
|
|
else
|
|
*naddr = be32_to_cpu(*naddr);
|
|
if (getprop(node, "#size-cells", nsize, 4) != 4)
|
|
*nsize = 1;
|
|
else
|
|
*nsize = be32_to_cpu(*nsize);
|
|
}
|
|
|
|
static void copy_val(u32 *dest, u32 *src, int naddr)
|
|
{
|
|
int pad = MAX_ADDR_CELLS - naddr;
|
|
|
|
memset(dest, 0, pad * 4);
|
|
memcpy(dest + pad, src, naddr * 4);
|
|
}
|
|
|
|
static int sub_reg(u32 *reg, u32 *sub)
|
|
{
|
|
int i, borrow = 0;
|
|
|
|
for (i = MAX_ADDR_CELLS - 1; i >= 0; i--) {
|
|
int prev_borrow = borrow;
|
|
borrow = reg[i] < sub[i] + prev_borrow;
|
|
reg[i] -= sub[i] + prev_borrow;
|
|
}
|
|
|
|
return !borrow;
|
|
}
|
|
|
|
static int add_reg(u32 *reg, u32 *add, int naddr)
|
|
{
|
|
int i, carry = 0;
|
|
|
|
for (i = MAX_ADDR_CELLS - 1; i >= MAX_ADDR_CELLS - naddr; i--) {
|
|
u64 tmp = (u64)be32_to_cpu(reg[i]) + be32_to_cpu(add[i]) + carry;
|
|
carry = tmp >> 32;
|
|
reg[i] = cpu_to_be32((u32)tmp);
|
|
}
|
|
|
|
return !carry;
|
|
}
|
|
|
|
/* It is assumed that if the first byte of reg fits in a
|
|
* range, then the whole reg block fits.
|
|
*/
|
|
static int compare_reg(u32 *reg, u32 *range, u32 *rangesize)
|
|
{
|
|
int i;
|
|
u32 end;
|
|
|
|
for (i = 0; i < MAX_ADDR_CELLS; i++) {
|
|
if (be32_to_cpu(reg[i]) < be32_to_cpu(range[i]))
|
|
return 0;
|
|
if (be32_to_cpu(reg[i]) > be32_to_cpu(range[i]))
|
|
break;
|
|
}
|
|
|
|
for (i = 0; i < MAX_ADDR_CELLS; i++) {
|
|
end = be32_to_cpu(range[i]) + be32_to_cpu(rangesize[i]);
|
|
|
|
if (be32_to_cpu(reg[i]) < end)
|
|
break;
|
|
if (be32_to_cpu(reg[i]) > end)
|
|
return 0;
|
|
}
|
|
|
|
return reg[i] != end;
|
|
}
|
|
|
|
/* reg must be MAX_ADDR_CELLS */
|
|
static int find_range(u32 *reg, u32 *ranges, int nregaddr,
|
|
int naddr, int nsize, int buflen)
|
|
{
|
|
int nrange = nregaddr + naddr + nsize;
|
|
int i;
|
|
|
|
for (i = 0; i + nrange <= buflen; i += nrange) {
|
|
u32 range_addr[MAX_ADDR_CELLS];
|
|
u32 range_size[MAX_ADDR_CELLS];
|
|
|
|
copy_val(range_addr, ranges + i, nregaddr);
|
|
copy_val(range_size, ranges + i + nregaddr + naddr, nsize);
|
|
|
|
if (compare_reg(reg, range_addr, range_size))
|
|
return i;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
/* Currently only generic buses without special encodings are supported.
|
|
* In particular, PCI is not supported. Also, only the beginning of the
|
|
* reg block is tracked; size is ignored except in ranges.
|
|
*/
|
|
static u32 prop_buf[MAX_PROP_LEN / 4];
|
|
|
|
static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,
|
|
unsigned long *size)
|
|
{
|
|
u32 last_addr[MAX_ADDR_CELLS];
|
|
u32 this_addr[MAX_ADDR_CELLS];
|
|
void *parent;
|
|
u64 ret_addr, ret_size;
|
|
u32 naddr, nsize, prev_naddr, prev_nsize;
|
|
int buflen, offset;
|
|
|
|
parent = get_parent(node);
|
|
if (!parent)
|
|
return 0;
|
|
|
|
dt_get_reg_format(parent, &naddr, &nsize);
|
|
if (nsize > 2)
|
|
return 0;
|
|
|
|
offset = (naddr + nsize) * res;
|
|
|
|
if (reglen < offset + naddr + nsize ||
|
|
MAX_PROP_LEN < (offset + naddr + nsize) * 4)
|
|
return 0;
|
|
|
|
copy_val(last_addr, prop_buf + offset, naddr);
|
|
|
|
ret_size = be32_to_cpu(prop_buf[offset + naddr]);
|
|
if (nsize == 2) {
|
|
ret_size <<= 32;
|
|
ret_size |= be32_to_cpu(prop_buf[offset + naddr + 1]);
|
|
}
|
|
|
|
for (;;) {
|
|
prev_naddr = naddr;
|
|
prev_nsize = nsize;
|
|
node = parent;
|
|
|
|
parent = get_parent(node);
|
|
if (!parent)
|
|
break;
|
|
|
|
dt_get_reg_format(parent, &naddr, &nsize);
|
|
|
|
buflen = getprop(node, "ranges", prop_buf,
|
|
sizeof(prop_buf));
|
|
if (buflen == 0)
|
|
continue;
|
|
if (buflen < 0 || buflen > sizeof(prop_buf))
|
|
return 0;
|
|
|
|
offset = find_range(last_addr, prop_buf, prev_naddr,
|
|
naddr, prev_nsize, buflen / 4);
|
|
if (offset < 0)
|
|
return 0;
|
|
|
|
copy_val(this_addr, prop_buf + offset, prev_naddr);
|
|
|
|
if (!sub_reg(last_addr, this_addr))
|
|
return 0;
|
|
|
|
copy_val(this_addr, prop_buf + offset + prev_naddr, naddr);
|
|
|
|
if (!add_reg(last_addr, this_addr, naddr))
|
|
return 0;
|
|
}
|
|
|
|
if (naddr > 2)
|
|
return 0;
|
|
|
|
ret_addr = ((u64)be32_to_cpu(last_addr[2]) << 32) | be32_to_cpu(last_addr[3]);
|
|
if (sizeof(void *) == 4 &&
|
|
(ret_addr >= 0x100000000ULL || ret_size > 0x100000000ULL ||
|
|
ret_addr + ret_size > 0x100000000ULL))
|
|
return 0;
|
|
|
|
*addr = ret_addr;
|
|
if (size)
|
|
*size = ret_size;
|
|
|
|
return 1;
|
|
}
|
|
|
|
int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size)
|
|
{
|
|
int reglen;
|
|
|
|
reglen = getprop(node, "reg", prop_buf, sizeof(prop_buf)) / 4;
|
|
return dt_xlate(node, res, reglen, addr, size);
|
|
}
|
|
|
|
int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr)
|
|
{
|
|
|
|
if (buflen > sizeof(prop_buf))
|
|
return 0;
|
|
|
|
memcpy(prop_buf, buf, buflen);
|
|
return dt_xlate(node, 0, buflen / 4, xlated_addr, NULL);
|
|
}
|
|
|
|
int dt_is_compatible(void *node, const char *compat)
|
|
{
|
|
char *buf = (char *)prop_buf;
|
|
int len, pos;
|
|
|
|
len = getprop(node, "compatible", buf, MAX_PROP_LEN);
|
|
if (len < 0)
|
|
return 0;
|
|
|
|
for (pos = 0; pos < len; pos++) {
|
|
if (!strcmp(buf + pos, compat))
|
|
return 1;
|
|
|
|
pos += strnlen(&buf[pos], len - pos);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int dt_get_virtual_reg(void *node, void **addr, int nres)
|
|
{
|
|
unsigned long xaddr;
|
|
int n, i;
|
|
|
|
n = getprop(node, "virtual-reg", addr, nres * 4);
|
|
if (n > 0) {
|
|
for (i = 0; i < n/4; i ++)
|
|
((u32 *)addr)[i] = be32_to_cpu(((u32 *)addr)[i]);
|
|
return n / 4;
|
|
}
|
|
|
|
for (n = 0; n < nres; n++) {
|
|
if (!dt_xlate_reg(node, n, &xaddr, NULL))
|
|
break;
|
|
|
|
addr[n] = (void *)xaddr;
|
|
}
|
|
|
|
return n;
|
|
}
|
|
|