repo_name string | path string | copies string | size string | content string | license string |
|---|---|---|---|---|---|
FXITech/kernel | arch/x86/kernel/acpi/boot.c | 2561 | 40848 | /*
* boot.c - Architecture-Specific Low-Level ACPI Boot Support
*
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
* Copyright (C) 2001 Jun Nakajima <jun.nakajima@intel.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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#include <linux/init.h>
#include <linux/acpi.h>
#include <linux/acpi_pmtmr.h>
#include <linux/efi.h>
#include <linux/cpumask.h>
#include <linux/module.h>
#include <linux/dmi.h>
#include <linux/irq.h>
#include <linux/slab.h>
#include <linux/bootmem.h>
#include <linux/ioport.h>
#include <linux/pci.h>
#include <asm/pci_x86.h>
#include <asm/pgtable.h>
#include <asm/io_apic.h>
#include <asm/apic.h>
#include <asm/io.h>
#include <asm/mpspec.h>
#include <asm/smp.h>
static int __initdata acpi_force = 0;
u32 acpi_rsdt_forced;
int acpi_disabled;
EXPORT_SYMBOL(acpi_disabled);
#ifdef CONFIG_X86_64
# include <asm/proto.h>
# include <asm/numa_64.h>
#endif /* X86 */
#define BAD_MADT_ENTRY(entry, end) ( \
(!entry) || (unsigned long)entry + sizeof(*entry) > end || \
((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
#define PREFIX "ACPI: "
int acpi_noirq; /* skip ACPI IRQ initialization */
int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
EXPORT_SYMBOL(acpi_pci_disabled);
int acpi_lapic;
int acpi_ioapic;
int acpi_strict;
u8 acpi_sci_flags __initdata;
int acpi_sci_override_gsi __initdata;
int acpi_skip_timer_override __initdata;
int acpi_use_timer_override __initdata;
int acpi_fix_pin2_polarity __initdata;
#ifdef CONFIG_X86_LOCAL_APIC
static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
#endif
#ifndef __HAVE_ARCH_CMPXCHG
#warning ACPI uses CMPXCHG, i486 and later hardware
#endif
/* --------------------------------------------------------------------------
Boot-time Configuration
-------------------------------------------------------------------------- */
/*
* The default interrupt routing model is PIC (8259). This gets
* overridden if IOAPICs are enumerated (below).
*/
enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
/*
* ISA irqs by default are the first 16 gsis but can be
* any gsi as specified by an interrupt source override.
*/
static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
};
static unsigned int gsi_to_irq(unsigned int gsi)
{
unsigned int irq = gsi + NR_IRQS_LEGACY;
unsigned int i;
for (i = 0; i < NR_IRQS_LEGACY; i++) {
if (isa_irq_to_gsi[i] == gsi) {
return i;
}
}
/* Provide an identity mapping of gsi == irq
* except on truly weird platforms that have
* non isa irqs in the first 16 gsis.
*/
if (gsi >= NR_IRQS_LEGACY)
irq = gsi;
else
irq = gsi_top + gsi;
return irq;
}
static u32 irq_to_gsi(int irq)
{
unsigned int gsi;
if (irq < NR_IRQS_LEGACY)
gsi = isa_irq_to_gsi[irq];
else if (irq < gsi_top)
gsi = irq;
else if (irq < (gsi_top + NR_IRQS_LEGACY))
gsi = irq - gsi_top;
else
gsi = 0xffffffff;
return gsi;
}
/*
* Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
* to map the target physical address. The problem is that set_fixmap()
* provides a single page, and it is possible that the page is not
* sufficient.
* By using this area, we can map up to MAX_IO_APICS pages temporarily,
* i.e. until the next __va_range() call.
*
* Important Safety Note: The fixed I/O APIC page numbers are *subtracted*
* from the fixed base. That's why we start at FIX_IO_APIC_BASE_END and
* count idx down while incrementing the phys address.
*/
char *__init __acpi_map_table(unsigned long phys, unsigned long size)
{
if (!phys || !size)
return NULL;
return early_ioremap(phys, size);
}
void __init __acpi_unmap_table(char *map, unsigned long size)
{
if (!map || !size)
return;
early_iounmap(map, size);
}
#ifdef CONFIG_X86_LOCAL_APIC
static int __init acpi_parse_madt(struct acpi_table_header *table)
{
struct acpi_table_madt *madt = NULL;
if (!cpu_has_apic)
return -EINVAL;
madt = (struct acpi_table_madt *)table;
if (!madt) {
printk(KERN_WARNING PREFIX "Unable to map MADT\n");
return -ENODEV;
}
if (madt->address) {
acpi_lapic_addr = (u64) madt->address;
printk(KERN_DEBUG PREFIX "Local APIC address 0x%08x\n",
madt->address);
}
default_acpi_madt_oem_check(madt->header.oem_id,
madt->header.oem_table_id);
return 0;
}
static void __cpuinit acpi_register_lapic(int id, u8 enabled)
{
unsigned int ver = 0;
if (id >= (MAX_LOCAL_APIC-1)) {
printk(KERN_INFO PREFIX "skipped apicid that is too big\n");
return;
}
if (!enabled) {
++disabled_cpus;
return;
}
if (boot_cpu_physical_apicid != -1U)
ver = apic_version[boot_cpu_physical_apicid];
generic_processor_info(id, ver);
}
static int __init
acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
{
struct acpi_madt_local_x2apic *processor = NULL;
int apic_id;
u8 enabled;
processor = (struct acpi_madt_local_x2apic *)header;
if (BAD_MADT_ENTRY(processor, end))
return -EINVAL;
acpi_table_print_madt_entry(header);
apic_id = processor->local_apic_id;
enabled = processor->lapic_flags & ACPI_MADT_ENABLED;
#ifdef CONFIG_X86_X2APIC
/*
* We need to register disabled CPU as well to permit
* counting disabled CPUs. This allows us to size
* cpus_possible_map more accurately, to permit
* to not preallocating memory for all NR_CPUS
* when we use CPU hotplug.
*/
if (!apic->apic_id_valid(apic_id) && enabled)
printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
else
acpi_register_lapic(apic_id, enabled);
#else
printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
#endif
return 0;
}
static int __init
acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
{
struct acpi_madt_local_apic *processor = NULL;
processor = (struct acpi_madt_local_apic *)header;
if (BAD_MADT_ENTRY(processor, end))
return -EINVAL;
acpi_table_print_madt_entry(header);
/*
* We need to register disabled CPU as well to permit
* counting disabled CPUs. This allows us to size
* cpus_possible_map more accurately, to permit
* to not preallocating memory for all NR_CPUS
* when we use CPU hotplug.
*/
acpi_register_lapic(processor->id, /* APIC ID */
processor->lapic_flags & ACPI_MADT_ENABLED);
return 0;
}
static int __init
acpi_parse_sapic(struct acpi_subtable_header *header, const unsigned long end)
{
struct acpi_madt_local_sapic *processor = NULL;
processor = (struct acpi_madt_local_sapic *)header;
if (BAD_MADT_ENTRY(processor, end))
return -EINVAL;
acpi_table_print_madt_entry(header);
acpi_register_lapic((processor->id << 8) | processor->eid,/* APIC ID */
processor->lapic_flags & ACPI_MADT_ENABLED);
return 0;
}
static int __init
acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
const unsigned long end)
{
struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
if (BAD_MADT_ENTRY(lapic_addr_ovr, end))
return -EINVAL;
acpi_lapic_addr = lapic_addr_ovr->address;
return 0;
}
static int __init
acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
const unsigned long end)
{
struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
if (BAD_MADT_ENTRY(x2apic_nmi, end))
return -EINVAL;
acpi_table_print_madt_entry(header);
if (x2apic_nmi->lint != 1)
printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
return 0;
}
static int __init
acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
{
struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
lapic_nmi = (struct acpi_madt_local_apic_nmi *)header;
if (BAD_MADT_ENTRY(lapic_nmi, end))
return -EINVAL;
acpi_table_print_madt_entry(header);
if (lapic_nmi->lint != 1)
printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
return 0;
}
#endif /*CONFIG_X86_LOCAL_APIC */
#ifdef CONFIG_X86_IO_APIC
static int __init
acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
{
struct acpi_madt_io_apic *ioapic = NULL;
ioapic = (struct acpi_madt_io_apic *)header;
if (BAD_MADT_ENTRY(ioapic, end))
return -EINVAL;
acpi_table_print_madt_entry(header);
mp_register_ioapic(ioapic->id,
ioapic->address, ioapic->global_irq_base);
return 0;
}
/*
* Parse Interrupt Source Override for the ACPI SCI
*/
static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
{
if (trigger == 0) /* compatible SCI trigger is level */
trigger = 3;
if (polarity == 0) /* compatible SCI polarity is low */
polarity = 3;
/* Command-line over-ride via acpi_sci= */
if (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)
trigger = (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
if (acpi_sci_flags & ACPI_MADT_POLARITY_MASK)
polarity = acpi_sci_flags & ACPI_MADT_POLARITY_MASK;
/*
* mp_config_acpi_legacy_irqs() already setup IRQs < 16
* If GSI is < 16, this will update its flags,
* else it will create a new mp_irqs[] entry.
*/
mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
/*
* stash over-ride to indicate we've been here
* and for later update of acpi_gbl_FADT
*/
acpi_sci_override_gsi = gsi;
return;
}
static int __init
acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
const unsigned long end)
{
struct acpi_madt_interrupt_override *intsrc = NULL;
intsrc = (struct acpi_madt_interrupt_override *)header;
if (BAD_MADT_ENTRY(intsrc, end))
return -EINVAL;
acpi_table_print_madt_entry(header);
if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
acpi_sci_ioapic_setup(intsrc->source_irq,
intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
(intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
intsrc->global_irq);
return 0;
}
if (intsrc->source_irq == 0 && intsrc->global_irq == 2) {
if (acpi_skip_timer_override) {
printk(PREFIX "BIOS IRQ0 pin2 override ignored.\n");
return 0;
}
if (acpi_fix_pin2_polarity && (intsrc->inti_flags & ACPI_MADT_POLARITY_MASK)) {
intsrc->inti_flags &= ~ACPI_MADT_POLARITY_MASK;
printk(PREFIX "BIOS IRQ0 pin2 override: forcing polarity to high active.\n");
}
}
mp_override_legacy_irq(intsrc->source_irq,
intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
(intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
intsrc->global_irq);
return 0;
}
static int __init
acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
{
struct acpi_madt_nmi_source *nmi_src = NULL;
nmi_src = (struct acpi_madt_nmi_source *)header;
if (BAD_MADT_ENTRY(nmi_src, end))
return -EINVAL;
acpi_table_print_madt_entry(header);
/* TBD: Support nimsrc entries? */
return 0;
}
#endif /* CONFIG_X86_IO_APIC */
/*
* acpi_pic_sci_set_trigger()
*
* use ELCR to set PIC-mode trigger type for SCI
*
* If a PIC-mode SCI is not recognized or gives spurious IRQ7's
* it may require Edge Trigger -- use "acpi_sci=edge"
*
* Port 0x4d0-4d1 are ECLR1 and ECLR2, the Edge/Level Control Registers
* for the 8259 PIC. bit[n] = 1 means irq[n] is Level, otherwise Edge.
* ECLR1 is IRQs 0-7 (IRQ 0, 1, 2 must be 0)
* ECLR2 is IRQs 8-15 (IRQ 8, 13 must be 0)
*/
void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
{
unsigned int mask = 1 << irq;
unsigned int old, new;
/* Real old ELCR mask */
old = inb(0x4d0) | (inb(0x4d1) << 8);
/*
* If we use ACPI to set PCI IRQs, then we should clear ELCR
* since we will set it correctly as we enable the PCI irq
* routing.
*/
new = acpi_noirq ? old : 0;
/*
* Update SCI information in the ELCR, it isn't in the PCI
* routing tables..
*/
switch (trigger) {
case 1: /* Edge - clear */
new &= ~mask;
break;
case 3: /* Level - set */
new |= mask;
break;
}
if (old == new)
return;
printk(PREFIX "setting ELCR to %04x (from %04x)\n", new, old);
outb(new, 0x4d0);
outb(new >> 8, 0x4d1);
}
int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
{
*irq = gsi_to_irq(gsi);
#ifdef CONFIG_X86_IO_APIC
if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
setup_IO_APIC_irq_extra(gsi);
#endif
return 0;
}
EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
{
if (isa_irq >= 16)
return -1;
*gsi = irq_to_gsi(isa_irq);
return 0;
}
static int acpi_register_gsi_pic(struct device *dev, u32 gsi,
int trigger, int polarity)
{
#ifdef CONFIG_PCI
/*
* Make sure all (legacy) PCI IRQs are set as level-triggered.
*/
if (trigger == ACPI_LEVEL_SENSITIVE)
eisa_set_level_irq(gsi);
#endif
return gsi;
}
static int acpi_register_gsi_ioapic(struct device *dev, u32 gsi,
int trigger, int polarity)
{
#ifdef CONFIG_X86_IO_APIC
gsi = mp_register_gsi(dev, gsi, trigger, polarity);
#endif
return gsi;
}
int (*__acpi_register_gsi)(struct device *dev, u32 gsi,
int trigger, int polarity) = acpi_register_gsi_pic;
/*
* success: return IRQ number (>=0)
* failure: return < 0
*/
int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
{
unsigned int irq;
unsigned int plat_gsi = gsi;
plat_gsi = (*__acpi_register_gsi)(dev, gsi, trigger, polarity);
irq = gsi_to_irq(plat_gsi);
return irq;
}
void __init acpi_set_irq_model_pic(void)
{
acpi_irq_model = ACPI_IRQ_MODEL_PIC;
__acpi_register_gsi = acpi_register_gsi_pic;
acpi_ioapic = 0;
}
void __init acpi_set_irq_model_ioapic(void)
{
acpi_irq_model = ACPI_IRQ_MODEL_IOAPIC;
__acpi_register_gsi = acpi_register_gsi_ioapic;
acpi_ioapic = 1;
}
/*
* ACPI based hotplug support for CPU
*/
#ifdef CONFIG_ACPI_HOTPLUG_CPU
#include <acpi/processor.h>
static void __cpuinit acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
{
#ifdef CONFIG_ACPI_NUMA
int nid;
nid = acpi_get_node(handle);
if (nid == -1 || !node_online(nid))
return;
set_apicid_to_node(physid, nid);
numa_set_node(cpu, nid);
#endif
}
static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu)
{
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
struct acpi_madt_local_apic *lapic;
cpumask_var_t tmp_map, new_map;
u8 physid;
int cpu;
int retval = -ENOMEM;
if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
return -EINVAL;
if (!buffer.length || !buffer.pointer)
return -EINVAL;
obj = buffer.pointer;
if (obj->type != ACPI_TYPE_BUFFER ||
obj->buffer.length < sizeof(*lapic)) {
kfree(buffer.pointer);
return -EINVAL;
}
lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
!(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
kfree(buffer.pointer);
return -EINVAL;
}
physid = lapic->id;
kfree(buffer.pointer);
buffer.length = ACPI_ALLOCATE_BUFFER;
buffer.pointer = NULL;
lapic = NULL;
if (!alloc_cpumask_var(&tmp_map, GFP_KERNEL))
goto out;
if (!alloc_cpumask_var(&new_map, GFP_KERNEL))
goto free_tmp_map;
cpumask_copy(tmp_map, cpu_present_mask);
acpi_register_lapic(physid, ACPI_MADT_ENABLED);
/*
* If mp_register_lapic successfully generates a new logical cpu
* number, then the following will get us exactly what was mapped
*/
cpumask_andnot(new_map, cpu_present_mask, tmp_map);
if (cpumask_empty(new_map)) {
printk ("Unable to map lapic to logical cpu number\n");
retval = -EINVAL;
goto free_new_map;
}
acpi_processor_set_pdc(handle);
cpu = cpumask_first(new_map);
acpi_map_cpu2node(handle, cpu, physid);
*pcpu = cpu;
retval = 0;
free_new_map:
free_cpumask_var(new_map);
free_tmp_map:
free_cpumask_var(tmp_map);
out:
return retval;
}
/* wrapper to silence section mismatch warning */
int __ref acpi_map_lsapic(acpi_handle handle, int *pcpu)
{
return _acpi_map_lsapic(handle, pcpu);
}
EXPORT_SYMBOL(acpi_map_lsapic);
int acpi_unmap_lsapic(int cpu)
{
per_cpu(x86_cpu_to_apicid, cpu) = -1;
set_cpu_present(cpu, false);
num_processors--;
return (0);
}
EXPORT_SYMBOL(acpi_unmap_lsapic);
#endif /* CONFIG_ACPI_HOTPLUG_CPU */
int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
{
/* TBD */
return -EINVAL;
}
EXPORT_SYMBOL(acpi_register_ioapic);
int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
{
/* TBD */
return -EINVAL;
}
EXPORT_SYMBOL(acpi_unregister_ioapic);
static int __init acpi_parse_sbf(struct acpi_table_header *table)
{
struct acpi_table_boot *sb;
sb = (struct acpi_table_boot *)table;
if (!sb) {
printk(KERN_WARNING PREFIX "Unable to map SBF\n");
return -ENODEV;
}
sbf_port = sb->cmos_index; /* Save CMOS port */
return 0;
}
#ifdef CONFIG_HPET_TIMER
#include <asm/hpet.h>
static struct __initdata resource *hpet_res;
static int __init acpi_parse_hpet(struct acpi_table_header *table)
{
struct acpi_table_hpet *hpet_tbl;
hpet_tbl = (struct acpi_table_hpet *)table;
if (!hpet_tbl) {
printk(KERN_WARNING PREFIX "Unable to map HPET\n");
return -ENODEV;
}
if (hpet_tbl->address.space_id != ACPI_SPACE_MEM) {
printk(KERN_WARNING PREFIX "HPET timers must be located in "
"memory.\n");
return -1;
}
hpet_address = hpet_tbl->address.address;
hpet_blockid = hpet_tbl->sequence;
/*
* Some broken BIOSes advertise HPET at 0x0. We really do not
* want to allocate a resource there.
*/
if (!hpet_address) {
printk(KERN_WARNING PREFIX
"HPET id: %#x base: %#lx is invalid\n",
hpet_tbl->id, hpet_address);
return 0;
}
#ifdef CONFIG_X86_64
/*
* Some even more broken BIOSes advertise HPET at
* 0xfed0000000000000 instead of 0xfed00000. Fix it up and add
* some noise:
*/
if (hpet_address == 0xfed0000000000000UL) {
if (!hpet_force_user) {
printk(KERN_WARNING PREFIX "HPET id: %#x "
"base: 0xfed0000000000000 is bogus\n "
"try hpet=force on the kernel command line to "
"fix it up to 0xfed00000.\n", hpet_tbl->id);
hpet_address = 0;
return 0;
}
printk(KERN_WARNING PREFIX
"HPET id: %#x base: 0xfed0000000000000 fixed up "
"to 0xfed00000.\n", hpet_tbl->id);
hpet_address >>= 32;
}
#endif
printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
hpet_tbl->id, hpet_address);
/*
* Allocate and initialize the HPET firmware resource for adding into
* the resource tree during the lateinit timeframe.
*/
#define HPET_RESOURCE_NAME_SIZE 9
hpet_res = alloc_bootmem(sizeof(*hpet_res) + HPET_RESOURCE_NAME_SIZE);
hpet_res->name = (void *)&hpet_res[1];
hpet_res->flags = IORESOURCE_MEM;
snprintf((char *)hpet_res->name, HPET_RESOURCE_NAME_SIZE, "HPET %u",
hpet_tbl->sequence);
hpet_res->start = hpet_address;
hpet_res->end = hpet_address + (1 * 1024) - 1;
return 0;
}
/*
* hpet_insert_resource inserts the HPET resources used into the resource
* tree.
*/
static __init int hpet_insert_resource(void)
{
if (!hpet_res)
return 1;
return insert_resource(&iomem_resource, hpet_res);
}
late_initcall(hpet_insert_resource);
#else
#define acpi_parse_hpet NULL
#endif
static int __init acpi_parse_fadt(struct acpi_table_header *table)
{
#ifdef CONFIG_X86_PM_TIMER
/* detect the location of the ACPI PM Timer */
if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
/* FADT rev. 2 */
if (acpi_gbl_FADT.xpm_timer_block.space_id !=
ACPI_ADR_SPACE_SYSTEM_IO)
return 0;
pmtmr_ioport = acpi_gbl_FADT.xpm_timer_block.address;
/*
* "X" fields are optional extensions to the original V1.0
* fields, so we must selectively expand V1.0 fields if the
* corresponding X field is zero.
*/
if (!pmtmr_ioport)
pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
} else {
/* FADT rev. 1 */
pmtmr_ioport = acpi_gbl_FADT.pm_timer_block;
}
if (pmtmr_ioport)
printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x\n",
pmtmr_ioport);
#endif
return 0;
}
#ifdef CONFIG_X86_LOCAL_APIC
/*
* Parse LAPIC entries in MADT
* returns 0 on success, < 0 on error
*/
static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
{
int count;
if (!cpu_has_apic)
return -ENODEV;
/*
* Note that the LAPIC address is obtained from the MADT (32-bit value)
* and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
*/
count =
acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
acpi_parse_lapic_addr_ovr, 0);
if (count < 0) {
printk(KERN_ERR PREFIX
"Error parsing LAPIC address override entry\n");
return count;
}
register_lapic_address(acpi_lapic_addr);
return count;
}
static int __init acpi_parse_madt_lapic_entries(void)
{
int count;
int x2count = 0;
if (!cpu_has_apic)
return -ENODEV;
/*
* Note that the LAPIC address is obtained from the MADT (32-bit value)
* and (optionally) overriden by a LAPIC_ADDR_OVR entry (64-bit value).
*/
count =
acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE,
acpi_parse_lapic_addr_ovr, 0);
if (count < 0) {
printk(KERN_ERR PREFIX
"Error parsing LAPIC address override entry\n");
return count;
}
register_lapic_address(acpi_lapic_addr);
count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
acpi_parse_sapic, MAX_LOCAL_APIC);
if (!count) {
x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
acpi_parse_x2apic, MAX_LOCAL_APIC);
count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
acpi_parse_lapic, MAX_LOCAL_APIC);
}
if (!count && !x2count) {
printk(KERN_ERR PREFIX "No LAPIC entries present\n");
/* TBD: Cleanup to allow fallback to MPS */
return -ENODEV;
} else if (count < 0 || x2count < 0) {
printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
/* TBD: Cleanup to allow fallback to MPS */
return count;
}
x2count =
acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
acpi_parse_x2apic_nmi, 0);
count =
acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
if (count < 0 || x2count < 0) {
printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
/* TBD: Cleanup to allow fallback to MPS */
return count;
}
return 0;
}
#endif /* CONFIG_X86_LOCAL_APIC */
#ifdef CONFIG_X86_IO_APIC
#define MP_ISA_BUS 0
#ifdef CONFIG_X86_ES7000
extern int es7000_plat;
#endif
void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
{
int ioapic;
int pin;
struct mpc_intsrc mp_irq;
/*
* Convert 'gsi' to 'ioapic.pin'.
*/
ioapic = mp_find_ioapic(gsi);
if (ioapic < 0)
return;
pin = mp_find_ioapic_pin(ioapic, gsi);
/*
* TBD: This check is for faulty timer entries, where the override
* erroneously sets the trigger to level, resulting in a HUGE
* increase of timer interrupts!
*/
if ((bus_irq == 0) && (trigger == 3))
trigger = 1;
mp_irq.type = MP_INTSRC;
mp_irq.irqtype = mp_INT;
mp_irq.irqflag = (trigger << 2) | polarity;
mp_irq.srcbus = MP_ISA_BUS;
mp_irq.srcbusirq = bus_irq; /* IRQ */
mp_irq.dstapic = mpc_ioapic_id(ioapic); /* APIC ID */
mp_irq.dstirq = pin; /* INTIN# */
mp_save_irq(&mp_irq);
isa_irq_to_gsi[bus_irq] = gsi;
}
void __init mp_config_acpi_legacy_irqs(void)
{
int i;
struct mpc_intsrc mp_irq;
#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
/*
* Fabricate the legacy ISA bus (bus #31).
*/
mp_bus_id_to_type[MP_ISA_BUS] = MP_BUS_ISA;
#endif
set_bit(MP_ISA_BUS, mp_bus_not_pci);
pr_debug("Bus #%d is ISA\n", MP_ISA_BUS);
#ifdef CONFIG_X86_ES7000
/*
* Older generations of ES7000 have no legacy identity mappings
*/
if (es7000_plat == 1)
return;
#endif
/*
* Use the default configuration for the IRQs 0-15. Unless
* overridden by (MADT) interrupt source override entries.
*/
for (i = 0; i < 16; i++) {
int ioapic, pin;
unsigned int dstapic;
int idx;
u32 gsi;
/* Locate the gsi that irq i maps to. */
if (acpi_isa_irq_to_gsi(i, &gsi))
continue;
/*
* Locate the IOAPIC that manages the ISA IRQ.
*/
ioapic = mp_find_ioapic(gsi);
if (ioapic < 0)
continue;
pin = mp_find_ioapic_pin(ioapic, gsi);
dstapic = mpc_ioapic_id(ioapic);
for (idx = 0; idx < mp_irq_entries; idx++) {
struct mpc_intsrc *irq = mp_irqs + idx;
/* Do we already have a mapping for this ISA IRQ? */
if (irq->srcbus == MP_ISA_BUS && irq->srcbusirq == i)
break;
/* Do we already have a mapping for this IOAPIC pin */
if (irq->dstapic == dstapic && irq->dstirq == pin)
break;
}
if (idx != mp_irq_entries) {
printk(KERN_DEBUG "ACPI: IRQ%d used by override.\n", i);
continue; /* IRQ already used */
}
mp_irq.type = MP_INTSRC;
mp_irq.irqflag = 0; /* Conforming */
mp_irq.srcbus = MP_ISA_BUS;
mp_irq.dstapic = dstapic;
mp_irq.irqtype = mp_INT;
mp_irq.srcbusirq = i; /* Identity mapped */
mp_irq.dstirq = pin;
mp_save_irq(&mp_irq);
}
}
static int mp_config_acpi_gsi(struct device *dev, u32 gsi, int trigger,
int polarity)
{
#ifdef CONFIG_X86_MPPARSE
struct mpc_intsrc mp_irq;
struct pci_dev *pdev;
unsigned char number;
unsigned int devfn;
int ioapic;
u8 pin;
if (!acpi_ioapic)
return 0;
if (!dev)
return 0;
if (dev->bus != &pci_bus_type)
return 0;
pdev = to_pci_dev(dev);
number = pdev->bus->number;
devfn = pdev->devfn;
pin = pdev->pin;
/* print the entry should happen on mptable identically */
mp_irq.type = MP_INTSRC;
mp_irq.irqtype = mp_INT;
mp_irq.irqflag = (trigger == ACPI_EDGE_SENSITIVE ? 4 : 0x0c) |
(polarity == ACPI_ACTIVE_HIGH ? 1 : 3);
mp_irq.srcbus = number;
mp_irq.srcbusirq = (((devfn >> 3) & 0x1f) << 2) | ((pin - 1) & 3);
ioapic = mp_find_ioapic(gsi);
mp_irq.dstapic = mpc_ioapic_id(ioapic);
mp_irq.dstirq = mp_find_ioapic_pin(ioapic, gsi);
mp_save_irq(&mp_irq);
#endif
return 0;
}
int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
{
int ioapic;
int ioapic_pin;
struct io_apic_irq_attr irq_attr;
if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
return gsi;
/* Don't set up the ACPI SCI because it's already set up */
if (acpi_gbl_FADT.sci_interrupt == gsi)
return gsi;
ioapic = mp_find_ioapic(gsi);
if (ioapic < 0) {
printk(KERN_WARNING "No IOAPIC for GSI %u\n", gsi);
return gsi;
}
ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
printk(KERN_ERR "Invalid reference to IOAPIC pin "
"%d-%d\n", mpc_ioapic_id(ioapic),
ioapic_pin);
return gsi;
}
if (enable_update_mptable)
mp_config_acpi_gsi(dev, gsi, trigger, polarity);
set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
return gsi;
}
/*
* Parse IOAPIC related entries in MADT
* returns 0 on success, < 0 on error
*/
static int __init acpi_parse_madt_ioapic_entries(void)
{
int count;
/*
* ACPI interpreter is required to complete interrupt setup,
* so if it is off, don't enumerate the io-apics with ACPI.
* If MPS is present, it will handle them,
* otherwise the system will stay in PIC mode
*/
if (acpi_disabled || acpi_noirq)
return -ENODEV;
if (!cpu_has_apic)
return -ENODEV;
/*
* if "noapic" boot option, don't look for IO-APICs
*/
if (skip_ioapic_setup) {
printk(KERN_INFO PREFIX "Skipping IOAPIC probe "
"due to 'noapic' option.\n");
return -ENODEV;
}
count =
acpi_table_parse_madt(ACPI_MADT_TYPE_IO_APIC, acpi_parse_ioapic,
MAX_IO_APICS);
if (!count) {
printk(KERN_ERR PREFIX "No IOAPIC entries present\n");
return -ENODEV;
} else if (count < 0) {
printk(KERN_ERR PREFIX "Error parsing IOAPIC entry\n");
return count;
}
count =
acpi_table_parse_madt(ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr,
nr_irqs);
if (count < 0) {
printk(KERN_ERR PREFIX
"Error parsing interrupt source overrides entry\n");
/* TBD: Cleanup to allow fallback to MPS */
return count;
}
/*
* If BIOS did not supply an INT_SRC_OVR for the SCI
* pretend we got one so we can set the SCI flags.
*/
if (!acpi_sci_override_gsi)
acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
acpi_gbl_FADT.sci_interrupt);
/* Fill in identity legacy mappings where no override */
mp_config_acpi_legacy_irqs();
count =
acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src,
nr_irqs);
if (count < 0) {
printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
/* TBD: Cleanup to allow fallback to MPS */
return count;
}
return 0;
}
#else
static inline int acpi_parse_madt_ioapic_entries(void)
{
return -1;
}
#endif /* !CONFIG_X86_IO_APIC */
static void __init early_acpi_process_madt(void)
{
#ifdef CONFIG_X86_LOCAL_APIC
int error;
if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
/*
* Parse MADT LAPIC entries
*/
error = early_acpi_parse_madt_lapic_addr_ovr();
if (!error) {
acpi_lapic = 1;
smp_found_config = 1;
}
if (error == -EINVAL) {
/*
* Dell Precision Workstation 410, 610 come here.
*/
printk(KERN_ERR PREFIX
"Invalid BIOS MADT, disabling ACPI\n");
disable_acpi();
}
}
#endif
}
static void __init acpi_process_madt(void)
{
#ifdef CONFIG_X86_LOCAL_APIC
int error;
if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
/*
* Parse MADT LAPIC entries
*/
error = acpi_parse_madt_lapic_entries();
if (!error) {
acpi_lapic = 1;
/*
* Parse MADT IO-APIC entries
*/
error = acpi_parse_madt_ioapic_entries();
if (!error) {
acpi_set_irq_model_ioapic();
smp_found_config = 1;
}
}
if (error == -EINVAL) {
/*
* Dell Precision Workstation 410, 610 come here.
*/
printk(KERN_ERR PREFIX
"Invalid BIOS MADT, disabling ACPI\n");
disable_acpi();
}
} else {
/*
* ACPI found no MADT, and so ACPI wants UP PIC mode.
* In the event an MPS table was found, forget it.
* Boot with "acpi=off" to use MPS on such a system.
*/
if (smp_found_config) {
printk(KERN_WARNING PREFIX
"No APIC-table, disabling MPS\n");
smp_found_config = 0;
}
}
/*
* ACPI supports both logical (e.g. Hyper-Threading) and physical
* processors, where MPS only supports physical.
*/
if (acpi_lapic && acpi_ioapic)
printk(KERN_INFO "Using ACPI (MADT) for SMP configuration "
"information\n");
else if (acpi_lapic)
printk(KERN_INFO "Using ACPI for processor (LAPIC) "
"configuration information\n");
#endif
return;
}
static int __init disable_acpi_irq(const struct dmi_system_id *d)
{
if (!acpi_force) {
printk(KERN_NOTICE "%s detected: force use of acpi=noirq\n",
d->ident);
acpi_noirq_set();
}
return 0;
}
static int __init disable_acpi_pci(const struct dmi_system_id *d)
{
if (!acpi_force) {
printk(KERN_NOTICE "%s detected: force use of pci=noacpi\n",
d->ident);
acpi_disable_pci();
}
return 0;
}
static int __init dmi_disable_acpi(const struct dmi_system_id *d)
{
if (!acpi_force) {
printk(KERN_NOTICE "%s detected: acpi off\n", d->ident);
disable_acpi();
} else {
printk(KERN_NOTICE
"Warning: DMI blacklist says broken, but acpi forced\n");
}
return 0;
}
/*
* Force ignoring BIOS IRQ0 pin2 override
*/
static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
{
/*
* The ati_ixp4x0_rev() early PCI quirk should have set
* the acpi_skip_timer_override flag already:
*/
if (!acpi_skip_timer_override) {
WARN(1, KERN_ERR "ati_ixp4x0 quirk not complete.\n");
pr_notice("%s detected: Ignoring BIOS IRQ0 pin2 override\n",
d->ident);
acpi_skip_timer_override = 1;
}
return 0;
}
/*
* If your system is blacklisted here, but you find that acpi=force
* works for you, please contact linux-acpi@vger.kernel.org
*/
static struct dmi_system_id __initdata acpi_dmi_table[] = {
/*
* Boxes that need ACPI disabled
*/
{
.callback = dmi_disable_acpi,
.ident = "IBM Thinkpad",
.matches = {
DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
DMI_MATCH(DMI_BOARD_NAME, "2629H1G"),
},
},
/*
* Boxes that need ACPI PCI IRQ routing disabled
*/
{
.callback = disable_acpi_irq,
.ident = "ASUS A7V",
.matches = {
DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC"),
DMI_MATCH(DMI_BOARD_NAME, "<A7V>"),
/* newer BIOS, Revision 1011, does work */
DMI_MATCH(DMI_BIOS_VERSION,
"ASUS A7V ACPI BIOS Revision 1007"),
},
},
{
/*
* Latest BIOS for IBM 600E (1.16) has bad pcinum
* for LPC bridge, which is needed for the PCI
* interrupt links to work. DSDT fix is in bug 5966.
* 2645, 2646 model numbers are shared with 600/600E/600X
*/
.callback = disable_acpi_irq,
.ident = "IBM Thinkpad 600 Series 2645",
.matches = {
DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
DMI_MATCH(DMI_BOARD_NAME, "2645"),
},
},
{
.callback = disable_acpi_irq,
.ident = "IBM Thinkpad 600 Series 2646",
.matches = {
DMI_MATCH(DMI_BOARD_VENDOR, "IBM"),
DMI_MATCH(DMI_BOARD_NAME, "2646"),
},
},
/*
* Boxes that need ACPI PCI IRQ routing and PCI scan disabled
*/
{ /* _BBN 0 bug */
.callback = disable_acpi_pci,
.ident = "ASUS PR-DLS",
.matches = {
DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
DMI_MATCH(DMI_BOARD_NAME, "PR-DLS"),
DMI_MATCH(DMI_BIOS_VERSION,
"ASUS PR-DLS ACPI BIOS Revision 1010"),
DMI_MATCH(DMI_BIOS_DATE, "03/21/2003")
},
},
{
.callback = disable_acpi_pci,
.ident = "Acer TravelMate 36x Laptop",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
},
},
{}
};
/* second table for DMI checks that should run after early-quirks */
static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
/*
* HP laptops which use a DSDT reporting as HP/SB400/10000,
* which includes some code which overrides all temperature
* trip points to 16C if the INTIN2 input of the I/O APIC
* is enabled. This input is incorrectly designated the
* ISA IRQ 0 via an interrupt source override even though
* it is wired to the output of the master 8259A and INTIN0
* is not connected at all. Force ignoring BIOS IRQ0 pin2
* override in that cases.
*/
{
.callback = dmi_ignore_irq0_timer_override,
.ident = "HP nx6115 laptop",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6115"),
},
},
{
.callback = dmi_ignore_irq0_timer_override,
.ident = "HP NX6125 laptop",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6125"),
},
},
{
.callback = dmi_ignore_irq0_timer_override,
.ident = "HP NX6325 laptop",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"),
},
},
{
.callback = dmi_ignore_irq0_timer_override,
.ident = "HP 6715b laptop",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
},
},
{}
};
/*
* acpi_boot_table_init() and acpi_boot_init()
* called from setup_arch(), always.
* 1. checksums all tables
* 2. enumerates lapics
* 3. enumerates io-apics
*
* acpi_table_init() is separate to allow reading SRAT without
* other side effects.
*
* side effects of acpi_boot_init:
* acpi_lapic = 1 if LAPIC found
* acpi_ioapic = 1 if IOAPIC found
* if (acpi_lapic && acpi_ioapic) smp_found_config = 1;
* if acpi_blacklisted() acpi_disabled = 1;
* acpi_irq_model=...
* ...
*/
void __init acpi_boot_table_init(void)
{
dmi_check_system(acpi_dmi_table);
/*
* If acpi_disabled, bail out
*/
if (acpi_disabled)
return;
/*
* Initialize the ACPI boot-time table parser.
*/
if (acpi_table_init()) {
disable_acpi();
return;
}
acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
/*
* blacklist may disable ACPI entirely
*/
if (acpi_blacklisted()) {
if (acpi_force) {
printk(KERN_WARNING PREFIX "acpi=force override\n");
} else {
printk(KERN_WARNING PREFIX "Disabling ACPI support\n");
disable_acpi();
return;
}
}
}
int __init early_acpi_boot_init(void)
{
/*
* If acpi_disabled, bail out
*/
if (acpi_disabled)
return 1;
/*
* Process the Multiple APIC Description Table (MADT), if present
*/
early_acpi_process_madt();
return 0;
}
int __init acpi_boot_init(void)
{
/* those are executed after early-quirks are executed */
dmi_check_system(acpi_dmi_table_late);
/*
* If acpi_disabled, bail out
*/
if (acpi_disabled)
return 1;
acpi_table_parse(ACPI_SIG_BOOT, acpi_parse_sbf);
/*
* set sci_int and PM timer address
*/
acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt);
/*
* Process the Multiple APIC Description Table (MADT), if present
*/
acpi_process_madt();
acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
if (!acpi_noirq)
x86_init.pci.init = pci_acpi_init;
return 0;
}
static int __init parse_acpi(char *arg)
{
if (!arg)
return -EINVAL;
/* "acpi=off" disables both ACPI table parsing and interpreter */
if (strcmp(arg, "off") == 0) {
disable_acpi();
}
/* acpi=force to over-ride black-list */
else if (strcmp(arg, "force") == 0) {
acpi_force = 1;
acpi_disabled = 0;
}
/* acpi=strict disables out-of-spec workarounds */
else if (strcmp(arg, "strict") == 0) {
acpi_strict = 1;
}
/* acpi=rsdt use RSDT instead of XSDT */
else if (strcmp(arg, "rsdt") == 0) {
acpi_rsdt_forced = 1;
}
/* "acpi=noirq" disables ACPI interrupt routing */
else if (strcmp(arg, "noirq") == 0) {
acpi_noirq_set();
}
/* "acpi=copy_dsdt" copys DSDT */
else if (strcmp(arg, "copy_dsdt") == 0) {
acpi_gbl_copy_dsdt_locally = 1;
} else {
/* Core will printk when we return error. */
return -EINVAL;
}
return 0;
}
early_param("acpi", parse_acpi);
/* FIXME: Using pci= for an ACPI parameter is a travesty. */
static int __init parse_pci(char *arg)
{
if (arg && strcmp(arg, "noacpi") == 0)
acpi_disable_pci();
return 0;
}
early_param("pci", parse_pci);
int __init acpi_mps_check(void)
{
#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_X86_MPPARSE)
/* mptable code is not built-in*/
if (acpi_disabled || acpi_noirq) {
printk(KERN_WARNING "MPS support code is not built-in.\n"
"Using acpi=off or acpi=noirq or pci=noacpi "
"may have problem\n");
return 1;
}
#endif
return 0;
}
#ifdef CONFIG_X86_IO_APIC
static int __init parse_acpi_skip_timer_override(char *arg)
{
acpi_skip_timer_override = 1;
return 0;
}
early_param("acpi_skip_timer_override", parse_acpi_skip_timer_override);
static int __init parse_acpi_use_timer_override(char *arg)
{
acpi_use_timer_override = 1;
return 0;
}
early_param("acpi_use_timer_override", parse_acpi_use_timer_override);
#endif /* CONFIG_X86_IO_APIC */
static int __init setup_acpi_sci(char *s)
{
if (!s)
return -EINVAL;
if (!strcmp(s, "edge"))
acpi_sci_flags = ACPI_MADT_TRIGGER_EDGE |
(acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
else if (!strcmp(s, "level"))
acpi_sci_flags = ACPI_MADT_TRIGGER_LEVEL |
(acpi_sci_flags & ~ACPI_MADT_TRIGGER_MASK);
else if (!strcmp(s, "high"))
acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_HIGH |
(acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
else if (!strcmp(s, "low"))
acpi_sci_flags = ACPI_MADT_POLARITY_ACTIVE_LOW |
(acpi_sci_flags & ~ACPI_MADT_POLARITY_MASK);
else
return -EINVAL;
return 0;
}
early_param("acpi_sci", setup_acpi_sci);
int __acpi_acquire_global_lock(unsigned int *lock)
{
unsigned int old, new, val;
do {
old = *lock;
new = (((old & ~0x3) + 2) + ((old >> 1) & 0x1));
val = cmpxchg(lock, old, new);
} while (unlikely (val != old));
return (new < 3) ? -1 : 0;
}
int __acpi_release_global_lock(unsigned int *lock)
{
unsigned int old, new, val;
do {
old = *lock;
new = old & ~0x3;
val = cmpxchg(lock, old, new);
} while (unlikely (val != old));
return old & 0x1;
}
| gpl-2.0 |
leolas/ANDROID-KERNEL-QX1 | arch/arm/mach-mv78xx0/buffalo-wxl-setup.c | 2817 | 3157 | /*
* arch/arm/mach-mv78xx0/buffalo-wxl-setup.c
*
* Buffalo WXL (Terastation Duo) Setup routines
*
* sebastien requiem <sebastien@requiem.fr>
*
* This file is licensed under the terms of the GNU General Public
* License version 2. This program is licensed "as is" without any
* warranty of any kind, whether express or implied.
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/ata_platform.h>
#include <linux/mv643xx_eth.h>
#include <linux/ethtool.h>
#include <linux/i2c.h>
#include <mach/mv78xx0.h>
#include <asm/mach-types.h>
#include <asm/mach/arch.h>
#include "common.h"
#include "mpp.h"
/* This arch has 2 Giga Ethernet */
static struct mv643xx_eth_platform_data db78x00_ge00_data = {
.phy_addr = MV643XX_ETH_PHY_ADDR(0),
};
static struct mv643xx_eth_platform_data db78x00_ge01_data = {
.phy_addr = MV643XX_ETH_PHY_ADDR(8),
};
/* 2 SATA controller supporting HotPlug */
static struct mv_sata_platform_data db78x00_sata_data = {
.n_ports = 2,
};
static struct i2c_board_info __initdata db78x00_i2c_rtc = {
I2C_BOARD_INFO("ds1338", 0x68),
};
static unsigned int wxl_mpp_config[] __initdata = {
MPP0_GE1_TXCLK,
MPP1_GE1_TXCTL,
MPP2_GE1_RXCTL,
MPP3_GE1_RXCLK,
MPP4_GE1_TXD0,
MPP5_GE1_TXD1,
MPP6_GE1_TXD2,
MPP7_GE1_TXD3,
MPP8_GE1_RXD0,
MPP9_GE1_RXD1,
MPP10_GE1_RXD2,
MPP11_GE1_RXD3,
MPP12_GPIO,
MPP13_SYSRST_OUTn,
MPP14_SATA1_ACTn,
MPP15_SATA0_ACTn,
MPP16_GPIO,
MPP17_GPIO,
MPP18_GPIO,
MPP19_GPIO,
MPP20_GPIO,
MPP21_GPIO,
MPP22_GPIO,
MPP23_GPIO,
MPP24_UA2_TXD,
MPP25_UA2_RXD,
MPP26_UA2_CTSn,
MPP27_UA2_RTSn,
MPP28_GPIO,
MPP29_SYSRST_OUTn,
MPP30_GPIO,
MPP31_GPIO,
MPP32_GPIO,
MPP33_GPIO,
MPP34_GPIO,
MPP35_GPIO,
MPP36_GPIO,
MPP37_GPIO,
MPP38_GPIO,
MPP39_GPIO,
MPP40_UNUSED,
MPP41_UNUSED,
MPP42_UNUSED,
MPP43_UNUSED,
MPP44_UNUSED,
MPP45_UNUSED,
MPP46_UNUSED,
MPP47_UNUSED,
MPP48_SATA1_ACTn,
MPP49_SATA0_ACTn,
0
};
static void __init wxl_init(void)
{
/*
* Basic MV78xx0 setup. Needs to be called early.
*/
mv78xx0_init();
mv78xx0_mpp_conf(wxl_mpp_config);
/*
* Partition on-chip peripherals between the two CPU cores.
*/
mv78xx0_ehci0_init();
mv78xx0_ehci1_init();
mv78xx0_ehci2_init();
mv78xx0_ge00_init(&db78x00_ge00_data);
mv78xx0_ge01_init(&db78x00_ge01_data);
mv78xx0_sata_init(&db78x00_sata_data);
mv78xx0_uart0_init();
mv78xx0_uart1_init();
mv78xx0_uart2_init();
mv78xx0_uart3_init();
mv78xx0_i2c_init();
i2c_register_board_info(0, &db78x00_i2c_rtc, 1);
}
static int __init wxl_pci_init(void)
{
if (machine_is_terastation_wxl()) {
/*
* Assign the x16 PCIe slot on the board to CPU core
* #0, and let CPU core #1 have the four x1 slots.
*/
if (mv78xx0_core_index() == 0)
mv78xx0_pcie_init(0, 1);
else
mv78xx0_pcie_init(1, 0);
}
return 0;
}
subsys_initcall(wxl_pci_init);
MACHINE_START(TERASTATION_WXL, "Buffalo Nas WXL")
/* Maintainer: Sebastien Requiem <sebastien@requiem.fr> */
.boot_params = 0x00000100,
.init_machine = wxl_init,
.map_io = mv78xx0_map_io,
.init_early = mv78xx0_init_early,
.init_irq = mv78xx0_init_irq,
.timer = &mv78xx0_timer,
MACHINE_END
| gpl-2.0 |
raden/melati-kernel | drivers/regulator/of_regulator.c | 3841 | 4983 | /*
* OF helpers for regulator framework
*
* Copyright (C) 2011 Texas Instruments, Inc.
* Rajendra Nayak <rnayak@ti.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 <linux/module.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/string.h>
#include <linux/regulator/machine.h>
static void of_get_regulation_constraints(struct device_node *np,
struct regulator_init_data **init_data)
{
const __be32 *min_uV, *max_uV, *uV_offset;
const __be32 *min_uA, *max_uA;
struct regulation_constraints *constraints = &(*init_data)->constraints;
constraints->name = of_get_property(np, "regulator-name", NULL);
min_uV = of_get_property(np, "regulator-min-microvolt", NULL);
if (min_uV)
constraints->min_uV = be32_to_cpu(*min_uV);
max_uV = of_get_property(np, "regulator-max-microvolt", NULL);
if (max_uV)
constraints->max_uV = be32_to_cpu(*max_uV);
/* Voltage change possible? */
if (constraints->min_uV != constraints->max_uV)
constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE;
/* Only one voltage? Then make sure it's set. */
if (min_uV && max_uV && constraints->min_uV == constraints->max_uV)
constraints->apply_uV = true;
uV_offset = of_get_property(np, "regulator-microvolt-offset", NULL);
if (uV_offset)
constraints->uV_offset = be32_to_cpu(*uV_offset);
min_uA = of_get_property(np, "regulator-min-microamp", NULL);
if (min_uA)
constraints->min_uA = be32_to_cpu(*min_uA);
max_uA = of_get_property(np, "regulator-max-microamp", NULL);
if (max_uA)
constraints->max_uA = be32_to_cpu(*max_uA);
/* Current change possible? */
if (constraints->min_uA != constraints->max_uA)
constraints->valid_ops_mask |= REGULATOR_CHANGE_CURRENT;
if (of_find_property(np, "regulator-boot-on", NULL))
constraints->boot_on = true;
if (of_find_property(np, "regulator-always-on", NULL))
constraints->always_on = true;
else /* status change should be possible if not always on. */
constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS;
}
static const char *consumer_supply_prop_name = "qcom,consumer-supplies";
#define MAX_DEV_NAME_LEN 256
/*
* Fill in regulator init_data based on qcom legacy requirements.
*/
static int of_get_qcom_regulator_init_data(struct device *dev,
struct regulator_init_data **init_data)
{
struct device_node *node = dev->of_node;
struct regulator_consumer_supply *consumer_supplies;
int i, rc, num_consumer_supplies, array_len;
array_len = of_property_count_strings(node, consumer_supply_prop_name);
if (array_len > 0) {
/* Array length must be divisible by 2. */
if (array_len & 1) {
dev_err(dev, "error: %s device node property value "
"contains an odd number of elements: %d\n",
consumer_supply_prop_name, array_len);
return -EINVAL;
}
num_consumer_supplies = array_len / 2;
consumer_supplies = devm_kzalloc(dev,
sizeof(struct regulator_consumer_supply)
* num_consumer_supplies, GFP_KERNEL);
if (consumer_supplies == NULL) {
dev_err(dev, "devm_kzalloc failed\n");
return -ENOMEM;
}
for (i = 0; i < num_consumer_supplies; i++) {
rc = of_property_read_string_index(node,
consumer_supply_prop_name, i * 2,
&consumer_supplies[i].supply);
if (rc) {
dev_err(dev, "of_property_read_string_index "
"failed, rc=%d\n", rc);
devm_kfree(dev, consumer_supplies);
return rc;
}
rc = of_property_read_string_index(node,
consumer_supply_prop_name, (i * 2) + 1,
&consumer_supplies[i].dev_name);
if (rc) {
dev_err(dev, "of_property_read_string_index "
"failed, rc=%d\n", rc);
devm_kfree(dev, consumer_supplies);
return rc;
}
/* Treat dev_name = "" as a wildcard. */
if (strnlen(consumer_supplies[i].dev_name,
MAX_DEV_NAME_LEN) == 0)
consumer_supplies[i].dev_name = NULL;
}
(*init_data)->consumer_supplies = consumer_supplies;
(*init_data)->num_consumer_supplies = num_consumer_supplies;
}
return 0;
}
/**
* of_get_regulator_init_data - extract regulator_init_data structure info
* @dev: device requesting for regulator_init_data
*
* Populates regulator_init_data structure by extracting data from device
* tree node, returns a pointer to the populated struture or NULL if memory
* alloc fails.
*/
struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
struct device_node *node)
{
struct regulator_init_data *init_data;
int rc;
if (!node)
return NULL;
init_data = devm_kzalloc(dev, sizeof(*init_data), GFP_KERNEL);
if (!init_data)
return NULL; /* Out of memory? */
of_get_regulation_constraints(node, &init_data);
rc = of_get_qcom_regulator_init_data(dev, &init_data);
if (rc) {
devm_kfree(dev, init_data);
return NULL;
}
return init_data;
}
EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
| gpl-2.0 |
tim-yang/linux-3.8 | arch/arm/mach-netx/fb.c | 4353 | 2120 | /*
* arch/arm/mach-netx/fb.c
*
* Copyright (c) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/device.h>
#include <linux/init.h>
#include <linux/dma-mapping.h>
#include <linux/amba/bus.h>
#include <linux/amba/clcd.h>
#include <linux/err.h>
#include <linux/gfp.h>
#include <asm/irq.h>
#include <mach/netx-regs.h>
#include <mach/hardware.h>
static struct clcd_panel *netx_panel;
void netx_clcd_enable(struct clcd_fb *fb)
{
}
int netx_clcd_setup(struct clcd_fb *fb)
{
dma_addr_t dma;
fb->panel = netx_panel;
fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, 1024*1024,
&dma, GFP_KERNEL);
if (!fb->fb.screen_base) {
printk(KERN_ERR "CLCD: unable to map framebuffer\n");
return -ENOMEM;
}
fb->fb.fix.smem_start = dma;
fb->fb.fix.smem_len = 1024*1024;
return 0;
}
int netx_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
{
return dma_mmap_writecombine(&fb->dev->dev, vma,
fb->fb.screen_base,
fb->fb.fix.smem_start,
fb->fb.fix.smem_len);
}
void netx_clcd_remove(struct clcd_fb *fb)
{
dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
fb->fb.screen_base, fb->fb.fix.smem_start);
}
static AMBA_AHB_DEVICE(fb, "fb", 0, 0x00104000, { NETX_IRQ_LCD }, NULL);
int netx_fb_init(struct clcd_board *board, struct clcd_panel *panel)
{
netx_panel = panel;
fb_device.dev.platform_data = board;
return amba_device_register(&fb_device, &iomem_resource);
}
| gpl-2.0 |
acklinr/omap-android-3.4 | drivers/net/wireless/ath/ath5k/pci.c | 4865 | 9766 | /*
* Copyright (c) 2008-2009 Atheros Communications Inc.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <linux/nl80211.h>
#include <linux/pci.h>
#include <linux/pci-aspm.h>
#include <linux/etherdevice.h>
#include <linux/module.h>
#include "../ath.h"
#include "ath5k.h"
#include "debug.h"
#include "base.h"
#include "reg.h"
/* Known PCI ids */
static DEFINE_PCI_DEVICE_TABLE(ath5k_pci_id_table) = {
{ PCI_VDEVICE(ATHEROS, 0x0207) }, /* 5210 early */
{ PCI_VDEVICE(ATHEROS, 0x0007) }, /* 5210 */
{ PCI_VDEVICE(ATHEROS, 0x0011) }, /* 5311 - this is on AHB bus !*/
{ PCI_VDEVICE(ATHEROS, 0x0012) }, /* 5211 */
{ PCI_VDEVICE(ATHEROS, 0x0013) }, /* 5212 */
{ PCI_VDEVICE(3COM_2, 0x0013) }, /* 3com 5212 */
{ PCI_VDEVICE(3COM, 0x0013) }, /* 3com 3CRDAG675 5212 */
{ PCI_VDEVICE(ATHEROS, 0x1014) }, /* IBM minipci 5212 */
{ PCI_VDEVICE(ATHEROS, 0x0014) }, /* 5212 compatible */
{ PCI_VDEVICE(ATHEROS, 0x0015) }, /* 5212 compatible */
{ PCI_VDEVICE(ATHEROS, 0x0016) }, /* 5212 compatible */
{ PCI_VDEVICE(ATHEROS, 0x0017) }, /* 5212 compatible */
{ PCI_VDEVICE(ATHEROS, 0x0018) }, /* 5212 compatible */
{ PCI_VDEVICE(ATHEROS, 0x0019) }, /* 5212 compatible */
{ PCI_VDEVICE(ATHEROS, 0x001a) }, /* 2413 Griffin-lite */
{ PCI_VDEVICE(ATHEROS, 0x001b) }, /* 5413 Eagle */
{ PCI_VDEVICE(ATHEROS, 0x001c) }, /* PCI-E cards */
{ PCI_VDEVICE(ATHEROS, 0x001d) }, /* 2417 Nala */
{ 0 }
};
MODULE_DEVICE_TABLE(pci, ath5k_pci_id_table);
/* return bus cachesize in 4B word units */
static void ath5k_pci_read_cachesize(struct ath_common *common, int *csz)
{
struct ath5k_hw *ah = (struct ath5k_hw *) common->priv;
u8 u8tmp;
pci_read_config_byte(ah->pdev, PCI_CACHE_LINE_SIZE, &u8tmp);
*csz = (int)u8tmp;
/*
* This check was put in to avoid "unpleasant" consequences if
* the bootrom has not fully initialized all PCI devices.
* Sometimes the cache line size register is not set
*/
if (*csz == 0)
*csz = L1_CACHE_BYTES >> 2; /* Use the default size */
}
/*
* Read from eeprom
*/
static bool
ath5k_pci_eeprom_read(struct ath_common *common, u32 offset, u16 *data)
{
struct ath5k_hw *ah = (struct ath5k_hw *) common->ah;
u32 status, timeout;
/*
* Initialize EEPROM access
*/
if (ah->ah_version == AR5K_AR5210) {
AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
(void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
} else {
ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
AR5K_EEPROM_CMD_READ);
}
for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
if (status & AR5K_EEPROM_STAT_RDDONE) {
if (status & AR5K_EEPROM_STAT_RDERR)
return false;
*data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
0xffff);
return true;
}
usleep_range(15, 20);
}
return false;
}
int ath5k_hw_read_srev(struct ath5k_hw *ah)
{
ah->ah_mac_srev = ath5k_hw_reg_read(ah, AR5K_SREV);
return 0;
}
/*
* Read the MAC address from eeprom or platform_data
*/
static int ath5k_pci_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
{
u8 mac_d[ETH_ALEN] = {};
u32 total, offset;
u16 data;
int octet;
AR5K_EEPROM_READ(0x20, data);
for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
AR5K_EEPROM_READ(offset, data);
total += data;
mac_d[octet + 1] = data & 0xff;
mac_d[octet] = data >> 8;
octet += 2;
}
if (!total || total == 3 * 0xffff)
return -EINVAL;
memcpy(mac, mac_d, ETH_ALEN);
return 0;
}
/* Common ath_bus_opts structure */
static const struct ath_bus_ops ath_pci_bus_ops = {
.ath_bus_type = ATH_PCI,
.read_cachesize = ath5k_pci_read_cachesize,
.eeprom_read = ath5k_pci_eeprom_read,
.eeprom_read_mac = ath5k_pci_eeprom_read_mac,
};
/********************\
* PCI Initialization *
\********************/
static int __devinit
ath5k_pci_probe(struct pci_dev *pdev,
const struct pci_device_id *id)
{
void __iomem *mem;
struct ath5k_hw *ah;
struct ieee80211_hw *hw;
int ret;
u8 csz;
/*
* L0s needs to be disabled on all ath5k cards.
*
* For distributions shipping with CONFIG_PCIEASPM (this will be enabled
* by default in the future in 2.6.36) this will also mean both L1 and
* L0s will be disabled when a pre 1.1 PCIe device is detected. We do
* know L1 works correctly even for all ath5k pre 1.1 PCIe devices
* though but cannot currently undue the effect of a blacklist, for
* details you can read pcie_aspm_sanity_check() and see how it adjusts
* the device link capability.
*
* It may be possible in the future to implement some PCI API to allow
* drivers to override blacklists for pre 1.1 PCIe but for now it is
* best to accept that both L0s and L1 will be disabled completely for
* distributions shipping with CONFIG_PCIEASPM rather than having this
* issue present. Motivation for adding this new API will be to help
* with power consumption for some of these devices.
*/
pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
ret = pci_enable_device(pdev);
if (ret) {
dev_err(&pdev->dev, "can't enable device\n");
goto err;
}
/* XXX 32-bit addressing only */
ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
if (ret) {
dev_err(&pdev->dev, "32-bit DMA not available\n");
goto err_dis;
}
/*
* Cache line size is used to size and align various
* structures used to communicate with the hardware.
*/
pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
if (csz == 0) {
/*
* Linux 2.4.18 (at least) writes the cache line size
* register as a 16-bit wide register which is wrong.
* We must have this setup properly for rx buffer
* DMA to work so force a reasonable value here if it
* comes up zero.
*/
csz = L1_CACHE_BYTES >> 2;
pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
}
/*
* The default setting of latency timer yields poor results,
* set it to the value used by other systems. It may be worth
* tweaking this setting more.
*/
pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
/* Enable bus mastering */
pci_set_master(pdev);
/*
* Disable the RETRY_TIMEOUT register (0x41) to keep
* PCI Tx retries from interfering with C3 CPU state.
*/
pci_write_config_byte(pdev, 0x41, 0);
ret = pci_request_region(pdev, 0, "ath5k");
if (ret) {
dev_err(&pdev->dev, "cannot reserve PCI memory region\n");
goto err_dis;
}
mem = pci_iomap(pdev, 0, 0);
if (!mem) {
dev_err(&pdev->dev, "cannot remap PCI memory region\n");
ret = -EIO;
goto err_reg;
}
/*
* Allocate hw (mac80211 main struct)
* and hw->priv (driver private data)
*/
hw = ieee80211_alloc_hw(sizeof(*ah), &ath5k_hw_ops);
if (hw == NULL) {
dev_err(&pdev->dev, "cannot allocate ieee80211_hw\n");
ret = -ENOMEM;
goto err_map;
}
dev_info(&pdev->dev, "registered as '%s'\n", wiphy_name(hw->wiphy));
ah = hw->priv;
ah->hw = hw;
ah->pdev = pdev;
ah->dev = &pdev->dev;
ah->irq = pdev->irq;
ah->devid = id->device;
ah->iobase = mem; /* So we can unmap it on detach */
/* Initialize */
ret = ath5k_init_ah(ah, &ath_pci_bus_ops);
if (ret)
goto err_free;
/* Set private data */
pci_set_drvdata(pdev, hw);
return 0;
err_free:
ieee80211_free_hw(hw);
err_map:
pci_iounmap(pdev, mem);
err_reg:
pci_release_region(pdev, 0);
err_dis:
pci_disable_device(pdev);
err:
return ret;
}
static void __devexit
ath5k_pci_remove(struct pci_dev *pdev)
{
struct ieee80211_hw *hw = pci_get_drvdata(pdev);
struct ath5k_hw *ah = hw->priv;
ath5k_deinit_ah(ah);
pci_iounmap(pdev, ah->iobase);
pci_release_region(pdev, 0);
pci_disable_device(pdev);
ieee80211_free_hw(hw);
}
#ifdef CONFIG_PM_SLEEP
static int ath5k_pci_suspend(struct device *dev)
{
struct pci_dev *pdev = to_pci_dev(dev);
struct ieee80211_hw *hw = pci_get_drvdata(pdev);
struct ath5k_hw *ah = hw->priv;
ath5k_led_off(ah);
return 0;
}
static int ath5k_pci_resume(struct device *dev)
{
struct pci_dev *pdev = to_pci_dev(dev);
struct ieee80211_hw *hw = pci_get_drvdata(pdev);
struct ath5k_hw *ah = hw->priv;
/*
* Suspend/Resume resets the PCI configuration space, so we have to
* re-disable the RETRY_TIMEOUT register (0x41) to keep
* PCI Tx retries from interfering with C3 CPU state
*/
pci_write_config_byte(pdev, 0x41, 0);
ath5k_led_enable(ah);
return 0;
}
static SIMPLE_DEV_PM_OPS(ath5k_pm_ops, ath5k_pci_suspend, ath5k_pci_resume);
#define ATH5K_PM_OPS (&ath5k_pm_ops)
#else
#define ATH5K_PM_OPS NULL
#endif /* CONFIG_PM_SLEEP */
static struct pci_driver ath5k_pci_driver = {
.name = KBUILD_MODNAME,
.id_table = ath5k_pci_id_table,
.probe = ath5k_pci_probe,
.remove = __devexit_p(ath5k_pci_remove),
.driver.pm = ATH5K_PM_OPS,
};
/*
* Module init/exit functions
*/
static int __init
init_ath5k_pci(void)
{
int ret;
ret = pci_register_driver(&ath5k_pci_driver);
if (ret) {
printk(KERN_ERR "ath5k_pci: can't register pci driver\n");
return ret;
}
return 0;
}
static void __exit
exit_ath5k_pci(void)
{
pci_unregister_driver(&ath5k_pci_driver);
}
module_init(init_ath5k_pci);
module_exit(exit_ath5k_pci);
| gpl-2.0 |
Megatron007/ghost | drivers/net/ethernet/sfc/mcdi_mon.c | 4865 | 11797 | /****************************************************************************
* Driver for Solarflare Solarstorm network controllers and boards
* Copyright 2011 Solarflare Communications Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, incorporated herein by reference.
*/
#include <linux/bitops.h>
#include <linux/slab.h>
#include <linux/hwmon.h>
#include <linux/stat.h>
#include "net_driver.h"
#include "mcdi.h"
#include "mcdi_pcol.h"
#include "nic.h"
enum efx_hwmon_type {
EFX_HWMON_UNKNOWN,
EFX_HWMON_TEMP, /* temperature */
EFX_HWMON_COOL, /* cooling device, probably a heatsink */
EFX_HWMON_IN /* input voltage */
};
static const struct {
const char *label;
enum efx_hwmon_type hwmon_type;
int port;
} efx_mcdi_sensor_type[MC_CMD_SENSOR_ENTRY_MAXNUM] = {
#define SENSOR(name, label, hwmon_type, port) \
[MC_CMD_SENSOR_##name] = { label, hwmon_type, port }
SENSOR(CONTROLLER_TEMP, "Controller temp.", EFX_HWMON_TEMP, -1),
SENSOR(PHY_COMMON_TEMP, "PHY temp.", EFX_HWMON_TEMP, -1),
SENSOR(CONTROLLER_COOLING, "Controller cooling", EFX_HWMON_COOL, -1),
SENSOR(PHY0_TEMP, "PHY temp.", EFX_HWMON_TEMP, 0),
SENSOR(PHY0_COOLING, "PHY cooling", EFX_HWMON_COOL, 0),
SENSOR(PHY1_TEMP, "PHY temp.", EFX_HWMON_TEMP, 1),
SENSOR(PHY1_COOLING, "PHY cooling", EFX_HWMON_COOL, 1),
SENSOR(IN_1V0, "1.0V supply", EFX_HWMON_IN, -1),
SENSOR(IN_1V2, "1.2V supply", EFX_HWMON_IN, -1),
SENSOR(IN_1V8, "1.8V supply", EFX_HWMON_IN, -1),
SENSOR(IN_2V5, "2.5V supply", EFX_HWMON_IN, -1),
SENSOR(IN_3V3, "3.3V supply", EFX_HWMON_IN, -1),
SENSOR(IN_12V0, "12.0V supply", EFX_HWMON_IN, -1),
SENSOR(IN_1V2A, "1.2V analogue supply", EFX_HWMON_IN, -1),
SENSOR(IN_VREF, "ref. voltage", EFX_HWMON_IN, -1),
#undef SENSOR
};
static const char *const sensor_status_names[] = {
[MC_CMD_SENSOR_STATE_OK] = "OK",
[MC_CMD_SENSOR_STATE_WARNING] = "Warning",
[MC_CMD_SENSOR_STATE_FATAL] = "Fatal",
[MC_CMD_SENSOR_STATE_BROKEN] = "Device failure",
};
void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev)
{
unsigned int type, state, value;
const char *name = NULL, *state_txt;
type = EFX_QWORD_FIELD(*ev, MCDI_EVENT_SENSOREVT_MONITOR);
state = EFX_QWORD_FIELD(*ev, MCDI_EVENT_SENSOREVT_STATE);
value = EFX_QWORD_FIELD(*ev, MCDI_EVENT_SENSOREVT_VALUE);
/* Deal gracefully with the board having more drivers than we
* know about, but do not expect new sensor states. */
if (type < ARRAY_SIZE(efx_mcdi_sensor_type))
name = efx_mcdi_sensor_type[type].label;
if (!name)
name = "No sensor name available";
EFX_BUG_ON_PARANOID(state >= ARRAY_SIZE(sensor_status_names));
state_txt = sensor_status_names[state];
netif_err(efx, hw, efx->net_dev,
"Sensor %d (%s) reports condition '%s' for raw value %d\n",
type, name, state_txt, value);
}
#ifdef CONFIG_SFC_MCDI_MON
struct efx_mcdi_mon_attribute {
struct device_attribute dev_attr;
unsigned int index;
unsigned int type;
unsigned int limit_value;
char name[12];
};
static int efx_mcdi_mon_update(struct efx_nic *efx)
{
struct efx_mcdi_mon *hwmon = efx_mcdi_mon(efx);
u8 inbuf[MC_CMD_READ_SENSORS_IN_LEN];
int rc;
MCDI_SET_DWORD(inbuf, READ_SENSORS_IN_DMA_ADDR_LO,
hwmon->dma_buf.dma_addr & 0xffffffff);
MCDI_SET_DWORD(inbuf, READ_SENSORS_IN_DMA_ADDR_HI,
(u64)hwmon->dma_buf.dma_addr >> 32);
rc = efx_mcdi_rpc(efx, MC_CMD_READ_SENSORS,
inbuf, sizeof(inbuf), NULL, 0, NULL);
if (rc == 0)
hwmon->last_update = jiffies;
return rc;
}
static ssize_t efx_mcdi_mon_show_name(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return sprintf(buf, "%s\n", KBUILD_MODNAME);
}
static int efx_mcdi_mon_get_entry(struct device *dev, unsigned int index,
efx_dword_t *entry)
{
struct efx_nic *efx = dev_get_drvdata(dev);
struct efx_mcdi_mon *hwmon = efx_mcdi_mon(efx);
int rc;
BUILD_BUG_ON(MC_CMD_READ_SENSORS_OUT_LEN != 0);
mutex_lock(&hwmon->update_lock);
/* Use cached value if last update was < 1 s ago */
if (time_before(jiffies, hwmon->last_update + HZ))
rc = 0;
else
rc = efx_mcdi_mon_update(efx);
/* Copy out the requested entry */
*entry = ((efx_dword_t *)hwmon->dma_buf.addr)[index];
mutex_unlock(&hwmon->update_lock);
return rc;
}
static ssize_t efx_mcdi_mon_show_value(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct efx_mcdi_mon_attribute *mon_attr =
container_of(attr, struct efx_mcdi_mon_attribute, dev_attr);
efx_dword_t entry;
unsigned int value;
int rc;
rc = efx_mcdi_mon_get_entry(dev, mon_attr->index, &entry);
if (rc)
return rc;
value = EFX_DWORD_FIELD(entry, MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_VALUE);
/* Convert temperature from degrees to milli-degrees Celsius */
if (efx_mcdi_sensor_type[mon_attr->type].hwmon_type == EFX_HWMON_TEMP)
value *= 1000;
return sprintf(buf, "%u\n", value);
}
static ssize_t efx_mcdi_mon_show_limit(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct efx_mcdi_mon_attribute *mon_attr =
container_of(attr, struct efx_mcdi_mon_attribute, dev_attr);
unsigned int value;
value = mon_attr->limit_value;
/* Convert temperature from degrees to milli-degrees Celsius */
if (efx_mcdi_sensor_type[mon_attr->type].hwmon_type == EFX_HWMON_TEMP)
value *= 1000;
return sprintf(buf, "%u\n", value);
}
static ssize_t efx_mcdi_mon_show_alarm(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct efx_mcdi_mon_attribute *mon_attr =
container_of(attr, struct efx_mcdi_mon_attribute, dev_attr);
efx_dword_t entry;
int state;
int rc;
rc = efx_mcdi_mon_get_entry(dev, mon_attr->index, &entry);
if (rc)
return rc;
state = EFX_DWORD_FIELD(entry, MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_STATE);
return sprintf(buf, "%d\n", state != MC_CMD_SENSOR_STATE_OK);
}
static ssize_t efx_mcdi_mon_show_label(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct efx_mcdi_mon_attribute *mon_attr =
container_of(attr, struct efx_mcdi_mon_attribute, dev_attr);
return sprintf(buf, "%s\n",
efx_mcdi_sensor_type[mon_attr->type].label);
}
static int
efx_mcdi_mon_add_attr(struct efx_nic *efx, const char *name,
ssize_t (*reader)(struct device *,
struct device_attribute *, char *),
unsigned int index, unsigned int type,
unsigned int limit_value)
{
struct efx_mcdi_mon *hwmon = efx_mcdi_mon(efx);
struct efx_mcdi_mon_attribute *attr = &hwmon->attrs[hwmon->n_attrs];
int rc;
strlcpy(attr->name, name, sizeof(attr->name));
attr->index = index;
attr->type = type;
attr->limit_value = limit_value;
attr->dev_attr.attr.name = attr->name;
attr->dev_attr.attr.mode = S_IRUGO;
attr->dev_attr.show = reader;
rc = device_create_file(&efx->pci_dev->dev, &attr->dev_attr);
if (rc == 0)
++hwmon->n_attrs;
return rc;
}
int efx_mcdi_mon_probe(struct efx_nic *efx)
{
struct efx_mcdi_mon *hwmon = efx_mcdi_mon(efx);
unsigned int n_attrs, n_temp = 0, n_cool = 0, n_in = 0;
u8 outbuf[MC_CMD_SENSOR_INFO_OUT_LENMAX];
size_t outlen;
char name[12];
u32 mask;
int rc, i, type;
BUILD_BUG_ON(MC_CMD_SENSOR_INFO_IN_LEN != 0);
rc = efx_mcdi_rpc(efx, MC_CMD_SENSOR_INFO, NULL, 0,
outbuf, sizeof(outbuf), &outlen);
if (rc)
return rc;
if (outlen < MC_CMD_SENSOR_INFO_OUT_LENMIN)
return -EIO;
/* Find out which sensors are present. Don't create a device
* if there are none.
*/
mask = MCDI_DWORD(outbuf, SENSOR_INFO_OUT_MASK);
if (mask == 0)
return 0;
/* Check again for short response */
if (outlen < MC_CMD_SENSOR_INFO_OUT_LEN(hweight32(mask)))
return -EIO;
rc = efx_nic_alloc_buffer(efx, &hwmon->dma_buf,
4 * MC_CMD_SENSOR_ENTRY_MAXNUM);
if (rc)
return rc;
mutex_init(&hwmon->update_lock);
efx_mcdi_mon_update(efx);
/* Allocate space for the maximum possible number of
* attributes for this set of sensors: name of the driver plus
* value, min, max, crit, alarm and label for each sensor.
*/
n_attrs = 1 + 6 * hweight32(mask);
hwmon->attrs = kcalloc(n_attrs, sizeof(*hwmon->attrs), GFP_KERNEL);
if (!hwmon->attrs) {
rc = -ENOMEM;
goto fail;
}
hwmon->device = hwmon_device_register(&efx->pci_dev->dev);
if (IS_ERR(hwmon->device)) {
rc = PTR_ERR(hwmon->device);
goto fail;
}
rc = efx_mcdi_mon_add_attr(efx, "name", efx_mcdi_mon_show_name, 0, 0, 0);
if (rc)
goto fail;
for (i = 0, type = -1; ; i++) {
const char *hwmon_prefix;
unsigned hwmon_index;
u16 min1, max1, min2, max2;
/* Find next sensor type or exit if there is none */
type++;
while (!(mask & (1 << type))) {
type++;
if (type == 32)
return 0;
}
/* Skip sensors specific to a different port */
if (efx_mcdi_sensor_type[type].hwmon_type != EFX_HWMON_UNKNOWN &&
efx_mcdi_sensor_type[type].port >= 0 &&
efx_mcdi_sensor_type[type].port != efx_port_num(efx))
continue;
switch (efx_mcdi_sensor_type[type].hwmon_type) {
case EFX_HWMON_TEMP:
hwmon_prefix = "temp";
hwmon_index = ++n_temp; /* 1-based */
break;
case EFX_HWMON_COOL:
/* This is likely to be a heatsink, but there
* is no convention for representing cooling
* devices other than fans.
*/
hwmon_prefix = "fan";
hwmon_index = ++n_cool; /* 1-based */
break;
default:
hwmon_prefix = "in";
hwmon_index = n_in++; /* 0-based */
break;
}
min1 = MCDI_ARRAY_FIELD(outbuf, SENSOR_ENTRY,
SENSOR_INFO_ENTRY, i, MIN1);
max1 = MCDI_ARRAY_FIELD(outbuf, SENSOR_ENTRY,
SENSOR_INFO_ENTRY, i, MAX1);
min2 = MCDI_ARRAY_FIELD(outbuf, SENSOR_ENTRY,
SENSOR_INFO_ENTRY, i, MIN2);
max2 = MCDI_ARRAY_FIELD(outbuf, SENSOR_ENTRY,
SENSOR_INFO_ENTRY, i, MAX2);
if (min1 != max1) {
snprintf(name, sizeof(name), "%s%u_input",
hwmon_prefix, hwmon_index);
rc = efx_mcdi_mon_add_attr(
efx, name, efx_mcdi_mon_show_value, i, type, 0);
if (rc)
goto fail;
snprintf(name, sizeof(name), "%s%u_min",
hwmon_prefix, hwmon_index);
rc = efx_mcdi_mon_add_attr(
efx, name, efx_mcdi_mon_show_limit,
i, type, min1);
if (rc)
goto fail;
snprintf(name, sizeof(name), "%s%u_max",
hwmon_prefix, hwmon_index);
rc = efx_mcdi_mon_add_attr(
efx, name, efx_mcdi_mon_show_limit,
i, type, max1);
if (rc)
goto fail;
if (min2 != max2) {
/* Assume max2 is critical value.
* But we have no good way to expose min2.
*/
snprintf(name, sizeof(name), "%s%u_crit",
hwmon_prefix, hwmon_index);
rc = efx_mcdi_mon_add_attr(
efx, name, efx_mcdi_mon_show_limit,
i, type, max2);
if (rc)
goto fail;
}
}
snprintf(name, sizeof(name), "%s%u_alarm",
hwmon_prefix, hwmon_index);
rc = efx_mcdi_mon_add_attr(
efx, name, efx_mcdi_mon_show_alarm, i, type, 0);
if (rc)
goto fail;
if (efx_mcdi_sensor_type[type].label) {
snprintf(name, sizeof(name), "%s%u_label",
hwmon_prefix, hwmon_index);
rc = efx_mcdi_mon_add_attr(
efx, name, efx_mcdi_mon_show_label, i, type, 0);
if (rc)
goto fail;
}
}
fail:
efx_mcdi_mon_remove(efx);
return rc;
}
void efx_mcdi_mon_remove(struct efx_nic *efx)
{
struct siena_nic_data *nic_data = efx->nic_data;
struct efx_mcdi_mon *hwmon = &nic_data->hwmon;
unsigned int i;
for (i = 0; i < hwmon->n_attrs; i++)
device_remove_file(&efx->pci_dev->dev,
&hwmon->attrs[i].dev_attr);
kfree(hwmon->attrs);
if (hwmon->device)
hwmon_device_unregister(hwmon->device);
efx_nic_free_buffer(efx, &hwmon->dma_buf);
}
#endif /* CONFIG_SFC_MCDI_MON */
| gpl-2.0 |
LeMaker/linux-sunxi | drivers/ata/pata_pdc2027x.c | 5121 | 21999 | /*
* Promise PATA TX2/TX4/TX2000/133 IDE driver for pdc20268 to pdc20277.
*
* 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.
*
* Ported to libata by:
* Albert Lee <albertcc@tw.ibm.com> IBM Corporation
*
* Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
* Portions Copyright (C) 1999 Promise Technology, Inc.
*
* Author: Frank Tiernan (frankt@promise.com)
* Released under terms of General Public License
*
*
* libata documentation is available via 'make {ps|pdf}docs',
* as Documentation/DocBook/libata.*
*
* Hardware information only available under NDA.
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <scsi/scsi.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_cmnd.h>
#include <linux/libata.h>
#define DRV_NAME "pata_pdc2027x"
#define DRV_VERSION "1.0"
#undef PDC_DEBUG
#ifdef PDC_DEBUG
#define PDPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
#else
#define PDPRINTK(fmt, args...)
#endif
enum {
PDC_MMIO_BAR = 5,
PDC_UDMA_100 = 0,
PDC_UDMA_133 = 1,
PDC_100_MHZ = 100000000,
PDC_133_MHZ = 133333333,
PDC_SYS_CTL = 0x1100,
PDC_ATA_CTL = 0x1104,
PDC_GLOBAL_CTL = 0x1108,
PDC_CTCR0 = 0x110C,
PDC_CTCR1 = 0x1110,
PDC_BYTE_COUNT = 0x1120,
PDC_PLL_CTL = 0x1202,
};
static int pdc2027x_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
static int pdc2027x_reinit_one(struct pci_dev *pdev);
static int pdc2027x_prereset(struct ata_link *link, unsigned long deadline);
static void pdc2027x_set_piomode(struct ata_port *ap, struct ata_device *adev);
static void pdc2027x_set_dmamode(struct ata_port *ap, struct ata_device *adev);
static int pdc2027x_check_atapi_dma(struct ata_queued_cmd *qc);
static unsigned long pdc2027x_mode_filter(struct ata_device *adev, unsigned long mask);
static int pdc2027x_cable_detect(struct ata_port *ap);
static int pdc2027x_set_mode(struct ata_link *link, struct ata_device **r_failed);
/*
* ATA Timing Tables based on 133MHz controller clock.
* These tables are only used when the controller is in 133MHz clock.
* If the controller is in 100MHz clock, the ASIC hardware will
* set the timing registers automatically when "set feature" command
* is issued to the device. However, if the controller clock is 133MHz,
* the following tables must be used.
*/
static struct pdc2027x_pio_timing {
u8 value0, value1, value2;
} pdc2027x_pio_timing_tbl [] = {
{ 0xfb, 0x2b, 0xac }, /* PIO mode 0 */
{ 0x46, 0x29, 0xa4 }, /* PIO mode 1 */
{ 0x23, 0x26, 0x64 }, /* PIO mode 2 */
{ 0x27, 0x0d, 0x35 }, /* PIO mode 3, IORDY on, Prefetch off */
{ 0x23, 0x09, 0x25 }, /* PIO mode 4, IORDY on, Prefetch off */
};
static struct pdc2027x_mdma_timing {
u8 value0, value1;
} pdc2027x_mdma_timing_tbl [] = {
{ 0xdf, 0x5f }, /* MDMA mode 0 */
{ 0x6b, 0x27 }, /* MDMA mode 1 */
{ 0x69, 0x25 }, /* MDMA mode 2 */
};
static struct pdc2027x_udma_timing {
u8 value0, value1, value2;
} pdc2027x_udma_timing_tbl [] = {
{ 0x4a, 0x0f, 0xd5 }, /* UDMA mode 0 */
{ 0x3a, 0x0a, 0xd0 }, /* UDMA mode 1 */
{ 0x2a, 0x07, 0xcd }, /* UDMA mode 2 */
{ 0x1a, 0x05, 0xcd }, /* UDMA mode 3 */
{ 0x1a, 0x03, 0xcd }, /* UDMA mode 4 */
{ 0x1a, 0x02, 0xcb }, /* UDMA mode 5 */
{ 0x1a, 0x01, 0xcb }, /* UDMA mode 6 */
};
static const struct pci_device_id pdc2027x_pci_tbl[] = {
{ PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20268), PDC_UDMA_100 },
{ PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20269), PDC_UDMA_133 },
{ PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20270), PDC_UDMA_100 },
{ PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20271), PDC_UDMA_133 },
{ PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20275), PDC_UDMA_133 },
{ PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20276), PDC_UDMA_133 },
{ PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20277), PDC_UDMA_133 },
{ } /* terminate list */
};
static struct pci_driver pdc2027x_pci_driver = {
.name = DRV_NAME,
.id_table = pdc2027x_pci_tbl,
.probe = pdc2027x_init_one,
.remove = ata_pci_remove_one,
#ifdef CONFIG_PM
.suspend = ata_pci_device_suspend,
.resume = pdc2027x_reinit_one,
#endif
};
static struct scsi_host_template pdc2027x_sht = {
ATA_BMDMA_SHT(DRV_NAME),
};
static struct ata_port_operations pdc2027x_pata100_ops = {
.inherits = &ata_bmdma_port_ops,
.check_atapi_dma = pdc2027x_check_atapi_dma,
.cable_detect = pdc2027x_cable_detect,
.prereset = pdc2027x_prereset,
};
static struct ata_port_operations pdc2027x_pata133_ops = {
.inherits = &pdc2027x_pata100_ops,
.mode_filter = pdc2027x_mode_filter,
.set_piomode = pdc2027x_set_piomode,
.set_dmamode = pdc2027x_set_dmamode,
.set_mode = pdc2027x_set_mode,
};
static struct ata_port_info pdc2027x_port_info[] = {
/* PDC_UDMA_100 */
{
.flags = ATA_FLAG_SLAVE_POSS,
.pio_mask = ATA_PIO4,
.mwdma_mask = ATA_MWDMA2,
.udma_mask = ATA_UDMA5,
.port_ops = &pdc2027x_pata100_ops,
},
/* PDC_UDMA_133 */
{
.flags = ATA_FLAG_SLAVE_POSS,
.pio_mask = ATA_PIO4,
.mwdma_mask = ATA_MWDMA2,
.udma_mask = ATA_UDMA6,
.port_ops = &pdc2027x_pata133_ops,
},
};
MODULE_AUTHOR("Andre Hedrick, Frank Tiernan, Albert Lee");
MODULE_DESCRIPTION("libata driver module for Promise PDC20268 to PDC20277");
MODULE_LICENSE("GPL");
MODULE_VERSION(DRV_VERSION);
MODULE_DEVICE_TABLE(pci, pdc2027x_pci_tbl);
/**
* port_mmio - Get the MMIO address of PDC2027x extended registers
* @ap: Port
* @offset: offset from mmio base
*/
static inline void __iomem *port_mmio(struct ata_port *ap, unsigned int offset)
{
return ap->host->iomap[PDC_MMIO_BAR] + ap->port_no * 0x100 + offset;
}
/**
* dev_mmio - Get the MMIO address of PDC2027x extended registers
* @ap: Port
* @adev: device
* @offset: offset from mmio base
*/
static inline void __iomem *dev_mmio(struct ata_port *ap, struct ata_device *adev, unsigned int offset)
{
u8 adj = (adev->devno) ? 0x08 : 0x00;
return port_mmio(ap, offset) + adj;
}
/**
* pdc2027x_pata_cable_detect - Probe host controller cable detect info
* @ap: Port for which cable detect info is desired
*
* Read 80c cable indicator from Promise extended register.
* This register is latched when the system is reset.
*
* LOCKING:
* None (inherited from caller).
*/
static int pdc2027x_cable_detect(struct ata_port *ap)
{
u32 cgcr;
/* check cable detect results */
cgcr = ioread32(port_mmio(ap, PDC_GLOBAL_CTL));
if (cgcr & (1 << 26))
goto cbl40;
PDPRINTK("No cable or 80-conductor cable on port %d\n", ap->port_no);
return ATA_CBL_PATA80;
cbl40:
printk(KERN_INFO DRV_NAME ": 40-conductor cable detected on port %d\n", ap->port_no);
return ATA_CBL_PATA40;
}
/**
* pdc2027x_port_enabled - Check PDC ATA control register to see whether the port is enabled.
* @ap: Port to check
*/
static inline int pdc2027x_port_enabled(struct ata_port *ap)
{
return ioread8(port_mmio(ap, PDC_ATA_CTL)) & 0x02;
}
/**
* pdc2027x_prereset - prereset for PATA host controller
* @link: Target link
* @deadline: deadline jiffies for the operation
*
* Probeinit including cable detection.
*
* LOCKING:
* None (inherited from caller).
*/
static int pdc2027x_prereset(struct ata_link *link, unsigned long deadline)
{
/* Check whether port enabled */
if (!pdc2027x_port_enabled(link->ap))
return -ENOENT;
return ata_sff_prereset(link, deadline);
}
/**
* pdc2720x_mode_filter - mode selection filter
* @adev: ATA device
* @mask: list of modes proposed
*
* Block UDMA on devices that cause trouble with this controller.
*/
static unsigned long pdc2027x_mode_filter(struct ata_device *adev, unsigned long mask)
{
unsigned char model_num[ATA_ID_PROD_LEN + 1];
struct ata_device *pair = ata_dev_pair(adev);
if (adev->class != ATA_DEV_ATA || adev->devno == 0 || pair == NULL)
return mask;
/* Check for slave of a Maxtor at UDMA6 */
ata_id_c_string(pair->id, model_num, ATA_ID_PROD,
ATA_ID_PROD_LEN + 1);
/* If the master is a maxtor in UDMA6 then the slave should not use UDMA 6 */
if (strstr(model_num, "Maxtor") == NULL && pair->dma_mode == XFER_UDMA_6)
mask &= ~ (1 << (6 + ATA_SHIFT_UDMA));
return mask;
}
/**
* pdc2027x_set_piomode - Initialize host controller PATA PIO timings
* @ap: Port to configure
* @adev: um
*
* Set PIO mode for device.
*
* LOCKING:
* None (inherited from caller).
*/
static void pdc2027x_set_piomode(struct ata_port *ap, struct ata_device *adev)
{
unsigned int pio = adev->pio_mode - XFER_PIO_0;
u32 ctcr0, ctcr1;
PDPRINTK("adev->pio_mode[%X]\n", adev->pio_mode);
/* Sanity check */
if (pio > 4) {
printk(KERN_ERR DRV_NAME ": Unknown pio mode [%d] ignored\n", pio);
return;
}
/* Set the PIO timing registers using value table for 133MHz */
PDPRINTK("Set pio regs... \n");
ctcr0 = ioread32(dev_mmio(ap, adev, PDC_CTCR0));
ctcr0 &= 0xffff0000;
ctcr0 |= pdc2027x_pio_timing_tbl[pio].value0 |
(pdc2027x_pio_timing_tbl[pio].value1 << 8);
iowrite32(ctcr0, dev_mmio(ap, adev, PDC_CTCR0));
ctcr1 = ioread32(dev_mmio(ap, adev, PDC_CTCR1));
ctcr1 &= 0x00ffffff;
ctcr1 |= (pdc2027x_pio_timing_tbl[pio].value2 << 24);
iowrite32(ctcr1, dev_mmio(ap, adev, PDC_CTCR1));
PDPRINTK("Set pio regs done\n");
PDPRINTK("Set to pio mode[%u] \n", pio);
}
/**
* pdc2027x_set_dmamode - Initialize host controller PATA UDMA timings
* @ap: Port to configure
* @adev: um
*
* Set UDMA mode for device.
*
* LOCKING:
* None (inherited from caller).
*/
static void pdc2027x_set_dmamode(struct ata_port *ap, struct ata_device *adev)
{
unsigned int dma_mode = adev->dma_mode;
u32 ctcr0, ctcr1;
if ((dma_mode >= XFER_UDMA_0) &&
(dma_mode <= XFER_UDMA_6)) {
/* Set the UDMA timing registers with value table for 133MHz */
unsigned int udma_mode = dma_mode & 0x07;
if (dma_mode == XFER_UDMA_2) {
/*
* Turn off tHOLD.
* If tHOLD is '1', the hardware will add half clock for data hold time.
* This code segment seems to be no effect. tHOLD will be overwritten below.
*/
ctcr1 = ioread32(dev_mmio(ap, adev, PDC_CTCR1));
iowrite32(ctcr1 & ~(1 << 7), dev_mmio(ap, adev, PDC_CTCR1));
}
PDPRINTK("Set udma regs... \n");
ctcr1 = ioread32(dev_mmio(ap, adev, PDC_CTCR1));
ctcr1 &= 0xff000000;
ctcr1 |= pdc2027x_udma_timing_tbl[udma_mode].value0 |
(pdc2027x_udma_timing_tbl[udma_mode].value1 << 8) |
(pdc2027x_udma_timing_tbl[udma_mode].value2 << 16);
iowrite32(ctcr1, dev_mmio(ap, adev, PDC_CTCR1));
PDPRINTK("Set udma regs done\n");
PDPRINTK("Set to udma mode[%u] \n", udma_mode);
} else if ((dma_mode >= XFER_MW_DMA_0) &&
(dma_mode <= XFER_MW_DMA_2)) {
/* Set the MDMA timing registers with value table for 133MHz */
unsigned int mdma_mode = dma_mode & 0x07;
PDPRINTK("Set mdma regs... \n");
ctcr0 = ioread32(dev_mmio(ap, adev, PDC_CTCR0));
ctcr0 &= 0x0000ffff;
ctcr0 |= (pdc2027x_mdma_timing_tbl[mdma_mode].value0 << 16) |
(pdc2027x_mdma_timing_tbl[mdma_mode].value1 << 24);
iowrite32(ctcr0, dev_mmio(ap, adev, PDC_CTCR0));
PDPRINTK("Set mdma regs done\n");
PDPRINTK("Set to mdma mode[%u] \n", mdma_mode);
} else {
printk(KERN_ERR DRV_NAME ": Unknown dma mode [%u] ignored\n", dma_mode);
}
}
/**
* pdc2027x_set_mode - Set the timing registers back to correct values.
* @link: link to configure
* @r_failed: Returned device for failure
*
* The pdc2027x hardware will look at "SET FEATURES" and change the timing registers
* automatically. The values set by the hardware might be incorrect, under 133Mhz PLL.
* This function overwrites the possibly incorrect values set by the hardware to be correct.
*/
static int pdc2027x_set_mode(struct ata_link *link, struct ata_device **r_failed)
{
struct ata_port *ap = link->ap;
struct ata_device *dev;
int rc;
rc = ata_do_set_mode(link, r_failed);
if (rc < 0)
return rc;
ata_for_each_dev(dev, link, ENABLED) {
pdc2027x_set_piomode(ap, dev);
/*
* Enable prefetch if the device support PIO only.
*/
if (dev->xfer_shift == ATA_SHIFT_PIO) {
u32 ctcr1 = ioread32(dev_mmio(ap, dev, PDC_CTCR1));
ctcr1 |= (1 << 25);
iowrite32(ctcr1, dev_mmio(ap, dev, PDC_CTCR1));
PDPRINTK("Turn on prefetch\n");
} else {
pdc2027x_set_dmamode(ap, dev);
}
}
return 0;
}
/**
* pdc2027x_check_atapi_dma - Check whether ATAPI DMA can be supported for this command
* @qc: Metadata associated with taskfile to check
*
* LOCKING:
* None (inherited from caller).
*
* RETURNS: 0 when ATAPI DMA can be used
* 1 otherwise
*/
static int pdc2027x_check_atapi_dma(struct ata_queued_cmd *qc)
{
struct scsi_cmnd *cmd = qc->scsicmd;
u8 *scsicmd = cmd->cmnd;
int rc = 1; /* atapi dma off by default */
/*
* This workaround is from Promise's GPL driver.
* If ATAPI DMA is used for commands not in the
* following white list, say MODE_SENSE and REQUEST_SENSE,
* pdc2027x might hit the irq lost problem.
*/
switch (scsicmd[0]) {
case READ_10:
case WRITE_10:
case READ_12:
case WRITE_12:
case READ_6:
case WRITE_6:
case 0xad: /* READ_DVD_STRUCTURE */
case 0xbe: /* READ_CD */
/* ATAPI DMA is ok */
rc = 0;
break;
default:
;
}
return rc;
}
/**
* pdc_read_counter - Read the ctr counter
* @host: target ATA host
*/
static long pdc_read_counter(struct ata_host *host)
{
void __iomem *mmio_base = host->iomap[PDC_MMIO_BAR];
long counter;
int retry = 1;
u32 bccrl, bccrh, bccrlv, bccrhv;
retry:
bccrl = ioread32(mmio_base + PDC_BYTE_COUNT) & 0x7fff;
bccrh = ioread32(mmio_base + PDC_BYTE_COUNT + 0x100) & 0x7fff;
/* Read the counter values again for verification */
bccrlv = ioread32(mmio_base + PDC_BYTE_COUNT) & 0x7fff;
bccrhv = ioread32(mmio_base + PDC_BYTE_COUNT + 0x100) & 0x7fff;
counter = (bccrh << 15) | bccrl;
PDPRINTK("bccrh [%X] bccrl [%X]\n", bccrh, bccrl);
PDPRINTK("bccrhv[%X] bccrlv[%X]\n", bccrhv, bccrlv);
/*
* The 30-bit decreasing counter are read by 2 pieces.
* Incorrect value may be read when both bccrh and bccrl are changing.
* Ex. When 7900 decrease to 78FF, wrong value 7800 might be read.
*/
if (retry && !(bccrh == bccrhv && bccrl >= bccrlv)) {
retry--;
PDPRINTK("rereading counter\n");
goto retry;
}
return counter;
}
/**
* adjust_pll - Adjust the PLL input clock in Hz.
*
* @pdc_controller: controller specific information
* @host: target ATA host
* @pll_clock: The input of PLL in HZ
*/
static void pdc_adjust_pll(struct ata_host *host, long pll_clock, unsigned int board_idx)
{
void __iomem *mmio_base = host->iomap[PDC_MMIO_BAR];
u16 pll_ctl;
long pll_clock_khz = pll_clock / 1000;
long pout_required = board_idx? PDC_133_MHZ:PDC_100_MHZ;
long ratio = pout_required / pll_clock_khz;
int F, R;
/* Sanity check */
if (unlikely(pll_clock_khz < 5000L || pll_clock_khz > 70000L)) {
printk(KERN_ERR DRV_NAME ": Invalid PLL input clock %ldkHz, give up!\n", pll_clock_khz);
return;
}
#ifdef PDC_DEBUG
PDPRINTK("pout_required is %ld\n", pout_required);
/* Show the current clock value of PLL control register
* (maybe already configured by the firmware)
*/
pll_ctl = ioread16(mmio_base + PDC_PLL_CTL);
PDPRINTK("pll_ctl[%X]\n", pll_ctl);
#endif
/*
* Calculate the ratio of F, R and OD
* POUT = (F + 2) / (( R + 2) * NO)
*/
if (ratio < 8600L) { /* 8.6x */
/* Using NO = 0x01, R = 0x0D */
R = 0x0d;
} else if (ratio < 12900L) { /* 12.9x */
/* Using NO = 0x01, R = 0x08 */
R = 0x08;
} else if (ratio < 16100L) { /* 16.1x */
/* Using NO = 0x01, R = 0x06 */
R = 0x06;
} else if (ratio < 64000L) { /* 64x */
R = 0x00;
} else {
/* Invalid ratio */
printk(KERN_ERR DRV_NAME ": Invalid ratio %ld, give up!\n", ratio);
return;
}
F = (ratio * (R+2)) / 1000 - 2;
if (unlikely(F < 0 || F > 127)) {
/* Invalid F */
printk(KERN_ERR DRV_NAME ": F[%d] invalid!\n", F);
return;
}
PDPRINTK("F[%d] R[%d] ratio*1000[%ld]\n", F, R, ratio);
pll_ctl = (R << 8) | F;
PDPRINTK("Writing pll_ctl[%X]\n", pll_ctl);
iowrite16(pll_ctl, mmio_base + PDC_PLL_CTL);
ioread16(mmio_base + PDC_PLL_CTL); /* flush */
/* Wait the PLL circuit to be stable */
mdelay(30);
#ifdef PDC_DEBUG
/*
* Show the current clock value of PLL control register
* (maybe configured by the firmware)
*/
pll_ctl = ioread16(mmio_base + PDC_PLL_CTL);
PDPRINTK("pll_ctl[%X]\n", pll_ctl);
#endif
return;
}
/**
* detect_pll_input_clock - Detect the PLL input clock in Hz.
* @host: target ATA host
* Ex. 16949000 on 33MHz PCI bus for pdc20275.
* Half of the PCI clock.
*/
static long pdc_detect_pll_input_clock(struct ata_host *host)
{
void __iomem *mmio_base = host->iomap[PDC_MMIO_BAR];
u32 scr;
long start_count, end_count;
struct timeval start_time, end_time;
long pll_clock, usec_elapsed;
/* Start the test mode */
scr = ioread32(mmio_base + PDC_SYS_CTL);
PDPRINTK("scr[%X]\n", scr);
iowrite32(scr | (0x01 << 14), mmio_base + PDC_SYS_CTL);
ioread32(mmio_base + PDC_SYS_CTL); /* flush */
/* Read current counter value */
start_count = pdc_read_counter(host);
do_gettimeofday(&start_time);
/* Let the counter run for 100 ms. */
mdelay(100);
/* Read the counter values again */
end_count = pdc_read_counter(host);
do_gettimeofday(&end_time);
/* Stop the test mode */
scr = ioread32(mmio_base + PDC_SYS_CTL);
PDPRINTK("scr[%X]\n", scr);
iowrite32(scr & ~(0x01 << 14), mmio_base + PDC_SYS_CTL);
ioread32(mmio_base + PDC_SYS_CTL); /* flush */
/* calculate the input clock in Hz */
usec_elapsed = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
(end_time.tv_usec - start_time.tv_usec);
pll_clock = ((start_count - end_count) & 0x3fffffff) / 100 *
(100000000 / usec_elapsed);
PDPRINTK("start[%ld] end[%ld] \n", start_count, end_count);
PDPRINTK("PLL input clock[%ld]Hz\n", pll_clock);
return pll_clock;
}
/**
* pdc_hardware_init - Initialize the hardware.
* @host: target ATA host
* @board_idx: board identifier
*/
static int pdc_hardware_init(struct ata_host *host, unsigned int board_idx)
{
long pll_clock;
/*
* Detect PLL input clock rate.
* On some system, where PCI bus is running at non-standard clock rate.
* Ex. 25MHz or 40MHz, we have to adjust the cycle_time.
* The pdc20275 controller employs PLL circuit to help correct timing registers setting.
*/
pll_clock = pdc_detect_pll_input_clock(host);
dev_info(host->dev, "PLL input clock %ld kHz\n", pll_clock/1000);
/* Adjust PLL control register */
pdc_adjust_pll(host, pll_clock, board_idx);
return 0;
}
/**
* pdc_ata_setup_port - setup the mmio address
* @port: ata ioports to setup
* @base: base address
*/
static void pdc_ata_setup_port(struct ata_ioports *port, void __iomem *base)
{
port->cmd_addr =
port->data_addr = base;
port->feature_addr =
port->error_addr = base + 0x05;
port->nsect_addr = base + 0x0a;
port->lbal_addr = base + 0x0f;
port->lbam_addr = base + 0x10;
port->lbah_addr = base + 0x15;
port->device_addr = base + 0x1a;
port->command_addr =
port->status_addr = base + 0x1f;
port->altstatus_addr =
port->ctl_addr = base + 0x81a;
}
/**
* pdc2027x_init_one - PCI probe function
* Called when an instance of PCI adapter is inserted.
* This function checks whether the hardware is supported,
* initialize hardware and register an instance of ata_host to
* libata. (implements struct pci_driver.probe() )
*
* @pdev: instance of pci_dev found
* @ent: matching entry in the id_tbl[]
*/
static int __devinit pdc2027x_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
{
static const unsigned long cmd_offset[] = { 0x17c0, 0x15c0 };
static const unsigned long bmdma_offset[] = { 0x1000, 0x1008 };
unsigned int board_idx = (unsigned int) ent->driver_data;
const struct ata_port_info *ppi[] =
{ &pdc2027x_port_info[board_idx], NULL };
struct ata_host *host;
void __iomem *mmio_base;
int i, rc;
ata_print_version_once(&pdev->dev, DRV_VERSION);
/* alloc host */
host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
if (!host)
return -ENOMEM;
/* acquire resources and fill host */
rc = pcim_enable_device(pdev);
if (rc)
return rc;
rc = pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME);
if (rc)
return rc;
host->iomap = pcim_iomap_table(pdev);
rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
if (rc)
return rc;
rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
if (rc)
return rc;
mmio_base = host->iomap[PDC_MMIO_BAR];
for (i = 0; i < 2; i++) {
struct ata_port *ap = host->ports[i];
pdc_ata_setup_port(&ap->ioaddr, mmio_base + cmd_offset[i]);
ap->ioaddr.bmdma_addr = mmio_base + bmdma_offset[i];
ata_port_pbar_desc(ap, PDC_MMIO_BAR, -1, "mmio");
ata_port_pbar_desc(ap, PDC_MMIO_BAR, cmd_offset[i], "cmd");
}
//pci_enable_intx(pdev);
/* initialize adapter */
if (pdc_hardware_init(host, board_idx) != 0)
return -EIO;
pci_set_master(pdev);
return ata_host_activate(host, pdev->irq, ata_bmdma_interrupt,
IRQF_SHARED, &pdc2027x_sht);
}
#ifdef CONFIG_PM
static int pdc2027x_reinit_one(struct pci_dev *pdev)
{
struct ata_host *host = dev_get_drvdata(&pdev->dev);
unsigned int board_idx;
int rc;
rc = ata_pci_device_do_resume(pdev);
if (rc)
return rc;
if (pdev->device == PCI_DEVICE_ID_PROMISE_20268 ||
pdev->device == PCI_DEVICE_ID_PROMISE_20270)
board_idx = PDC_UDMA_100;
else
board_idx = PDC_UDMA_133;
if (pdc_hardware_init(host, board_idx))
return -EIO;
ata_host_resume(host);
return 0;
}
#endif
/**
* pdc2027x_init - Called after this module is loaded into the kernel.
*/
static int __init pdc2027x_init(void)
{
return pci_register_driver(&pdc2027x_pci_driver);
}
/**
* pdc2027x_exit - Called before this module unloaded from the kernel
*/
static void __exit pdc2027x_exit(void)
{
pci_unregister_driver(&pdc2027x_pci_driver);
}
module_init(pdc2027x_init);
module_exit(pdc2027x_exit);
| gpl-2.0 |
showp1984/bricked-ville-3.4 | drivers/md/persistent-data/dm-block-manager.c | 5121 | 13481 | /*
* Copyright (C) 2011 Red Hat, Inc.
*
* This file is released under the GPL.
*/
#include "dm-block-manager.h"
#include "dm-persistent-data-internal.h"
#include "../dm-bufio.h"
#include <linux/crc32c.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/rwsem.h>
#include <linux/device-mapper.h>
#include <linux/stacktrace.h>
#define DM_MSG_PREFIX "block manager"
/*----------------------------------------------------------------*/
/*
* This is a read/write semaphore with a couple of differences.
*
* i) There is a restriction on the number of concurrent read locks that
* may be held at once. This is just an implementation detail.
*
* ii) Recursive locking attempts are detected and return EINVAL. A stack
* trace is also emitted for the previous lock aquisition.
*
* iii) Priority is given to write locks.
*/
#define MAX_HOLDERS 4
#define MAX_STACK 10
typedef unsigned long stack_entries[MAX_STACK];
struct block_lock {
spinlock_t lock;
__s32 count;
struct list_head waiters;
struct task_struct *holders[MAX_HOLDERS];
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
struct stack_trace traces[MAX_HOLDERS];
stack_entries entries[MAX_HOLDERS];
#endif
};
struct waiter {
struct list_head list;
struct task_struct *task;
int wants_write;
};
static unsigned __find_holder(struct block_lock *lock,
struct task_struct *task)
{
unsigned i;
for (i = 0; i < MAX_HOLDERS; i++)
if (lock->holders[i] == task)
break;
BUG_ON(i == MAX_HOLDERS);
return i;
}
/* call this *after* you increment lock->count */
static void __add_holder(struct block_lock *lock, struct task_struct *task)
{
unsigned h = __find_holder(lock, NULL);
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
struct stack_trace *t;
#endif
get_task_struct(task);
lock->holders[h] = task;
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
t = lock->traces + h;
t->nr_entries = 0;
t->max_entries = MAX_STACK;
t->entries = lock->entries[h];
t->skip = 2;
save_stack_trace(t);
#endif
}
/* call this *before* you decrement lock->count */
static void __del_holder(struct block_lock *lock, struct task_struct *task)
{
unsigned h = __find_holder(lock, task);
lock->holders[h] = NULL;
put_task_struct(task);
}
static int __check_holder(struct block_lock *lock)
{
unsigned i;
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
static struct stack_trace t;
static stack_entries entries;
#endif
for (i = 0; i < MAX_HOLDERS; i++) {
if (lock->holders[i] == current) {
DMERR("recursive lock detected in pool metadata");
#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
DMERR("previously held here:");
print_stack_trace(lock->traces + i, 4);
DMERR("subsequent aquisition attempted here:");
t.nr_entries = 0;
t.max_entries = MAX_STACK;
t.entries = entries;
t.skip = 3;
save_stack_trace(&t);
print_stack_trace(&t, 4);
#endif
return -EINVAL;
}
}
return 0;
}
static void __wait(struct waiter *w)
{
for (;;) {
set_task_state(current, TASK_UNINTERRUPTIBLE);
if (!w->task)
break;
schedule();
}
set_task_state(current, TASK_RUNNING);
}
static void __wake_waiter(struct waiter *w)
{
struct task_struct *task;
list_del(&w->list);
task = w->task;
smp_mb();
w->task = NULL;
wake_up_process(task);
}
/*
* We either wake a few readers or a single writer.
*/
static void __wake_many(struct block_lock *lock)
{
struct waiter *w, *tmp;
BUG_ON(lock->count < 0);
list_for_each_entry_safe(w, tmp, &lock->waiters, list) {
if (lock->count >= MAX_HOLDERS)
return;
if (w->wants_write) {
if (lock->count > 0)
return; /* still read locked */
lock->count = -1;
__add_holder(lock, w->task);
__wake_waiter(w);
return;
}
lock->count++;
__add_holder(lock, w->task);
__wake_waiter(w);
}
}
static void bl_init(struct block_lock *lock)
{
int i;
spin_lock_init(&lock->lock);
lock->count = 0;
INIT_LIST_HEAD(&lock->waiters);
for (i = 0; i < MAX_HOLDERS; i++)
lock->holders[i] = NULL;
}
static int __available_for_read(struct block_lock *lock)
{
return lock->count >= 0 &&
lock->count < MAX_HOLDERS &&
list_empty(&lock->waiters);
}
static int bl_down_read(struct block_lock *lock)
{
int r;
struct waiter w;
spin_lock(&lock->lock);
r = __check_holder(lock);
if (r) {
spin_unlock(&lock->lock);
return r;
}
if (__available_for_read(lock)) {
lock->count++;
__add_holder(lock, current);
spin_unlock(&lock->lock);
return 0;
}
get_task_struct(current);
w.task = current;
w.wants_write = 0;
list_add_tail(&w.list, &lock->waiters);
spin_unlock(&lock->lock);
__wait(&w);
put_task_struct(current);
return 0;
}
static int bl_down_read_nonblock(struct block_lock *lock)
{
int r;
spin_lock(&lock->lock);
r = __check_holder(lock);
if (r)
goto out;
if (__available_for_read(lock)) {
lock->count++;
__add_holder(lock, current);
r = 0;
} else
r = -EWOULDBLOCK;
out:
spin_unlock(&lock->lock);
return r;
}
static void bl_up_read(struct block_lock *lock)
{
spin_lock(&lock->lock);
BUG_ON(lock->count <= 0);
__del_holder(lock, current);
--lock->count;
if (!list_empty(&lock->waiters))
__wake_many(lock);
spin_unlock(&lock->lock);
}
static int bl_down_write(struct block_lock *lock)
{
int r;
struct waiter w;
spin_lock(&lock->lock);
r = __check_holder(lock);
if (r) {
spin_unlock(&lock->lock);
return r;
}
if (lock->count == 0 && list_empty(&lock->waiters)) {
lock->count = -1;
__add_holder(lock, current);
spin_unlock(&lock->lock);
return 0;
}
get_task_struct(current);
w.task = current;
w.wants_write = 1;
/*
* Writers given priority. We know there's only one mutator in the
* system, so ignoring the ordering reversal.
*/
list_add(&w.list, &lock->waiters);
spin_unlock(&lock->lock);
__wait(&w);
put_task_struct(current);
return 0;
}
static void bl_up_write(struct block_lock *lock)
{
spin_lock(&lock->lock);
__del_holder(lock, current);
lock->count = 0;
if (!list_empty(&lock->waiters))
__wake_many(lock);
spin_unlock(&lock->lock);
}
static void report_recursive_bug(dm_block_t b, int r)
{
if (r == -EINVAL)
DMERR("recursive acquisition of block %llu requested.",
(unsigned long long) b);
}
/*----------------------------------------------------------------*/
/*
* Block manager is currently implemented using dm-bufio. struct
* dm_block_manager and struct dm_block map directly onto a couple of
* structs in the bufio interface. I want to retain the freedom to move
* away from bufio in the future. So these structs are just cast within
* this .c file, rather than making it through to the public interface.
*/
static struct dm_buffer *to_buffer(struct dm_block *b)
{
return (struct dm_buffer *) b;
}
static struct dm_bufio_client *to_bufio(struct dm_block_manager *bm)
{
return (struct dm_bufio_client *) bm;
}
dm_block_t dm_block_location(struct dm_block *b)
{
return dm_bufio_get_block_number(to_buffer(b));
}
EXPORT_SYMBOL_GPL(dm_block_location);
void *dm_block_data(struct dm_block *b)
{
return dm_bufio_get_block_data(to_buffer(b));
}
EXPORT_SYMBOL_GPL(dm_block_data);
struct buffer_aux {
struct dm_block_validator *validator;
struct block_lock lock;
int write_locked;
};
static void dm_block_manager_alloc_callback(struct dm_buffer *buf)
{
struct buffer_aux *aux = dm_bufio_get_aux_data(buf);
aux->validator = NULL;
bl_init(&aux->lock);
}
static void dm_block_manager_write_callback(struct dm_buffer *buf)
{
struct buffer_aux *aux = dm_bufio_get_aux_data(buf);
if (aux->validator) {
aux->validator->prepare_for_write(aux->validator, (struct dm_block *) buf,
dm_bufio_get_block_size(dm_bufio_get_client(buf)));
}
}
/*----------------------------------------------------------------
* Public interface
*--------------------------------------------------------------*/
struct dm_block_manager *dm_block_manager_create(struct block_device *bdev,
unsigned block_size,
unsigned cache_size,
unsigned max_held_per_thread)
{
return (struct dm_block_manager *)
dm_bufio_client_create(bdev, block_size, max_held_per_thread,
sizeof(struct buffer_aux),
dm_block_manager_alloc_callback,
dm_block_manager_write_callback);
}
EXPORT_SYMBOL_GPL(dm_block_manager_create);
void dm_block_manager_destroy(struct dm_block_manager *bm)
{
return dm_bufio_client_destroy(to_bufio(bm));
}
EXPORT_SYMBOL_GPL(dm_block_manager_destroy);
unsigned dm_bm_block_size(struct dm_block_manager *bm)
{
return dm_bufio_get_block_size(to_bufio(bm));
}
EXPORT_SYMBOL_GPL(dm_bm_block_size);
dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm)
{
return dm_bufio_get_device_size(to_bufio(bm));
}
static int dm_bm_validate_buffer(struct dm_block_manager *bm,
struct dm_buffer *buf,
struct buffer_aux *aux,
struct dm_block_validator *v)
{
if (unlikely(!aux->validator)) {
int r;
if (!v)
return 0;
r = v->check(v, (struct dm_block *) buf, dm_bufio_get_block_size(to_bufio(bm)));
if (unlikely(r))
return r;
aux->validator = v;
} else {
if (unlikely(aux->validator != v)) {
DMERR("validator mismatch (old=%s vs new=%s) for block %llu",
aux->validator->name, v ? v->name : "NULL",
(unsigned long long)
dm_bufio_get_block_number(buf));
return -EINVAL;
}
}
return 0;
}
int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
struct dm_block_validator *v,
struct dm_block **result)
{
struct buffer_aux *aux;
void *p;
int r;
p = dm_bufio_read(to_bufio(bm), b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p)))
return PTR_ERR(p);
aux = dm_bufio_get_aux_data(to_buffer(*result));
r = bl_down_read(&aux->lock);
if (unlikely(r)) {
dm_bufio_release(to_buffer(*result));
report_recursive_bug(b, r);
return r;
}
aux->write_locked = 0;
r = dm_bm_validate_buffer(bm, to_buffer(*result), aux, v);
if (unlikely(r)) {
bl_up_read(&aux->lock);
dm_bufio_release(to_buffer(*result));
return r;
}
return 0;
}
EXPORT_SYMBOL_GPL(dm_bm_read_lock);
int dm_bm_write_lock(struct dm_block_manager *bm,
dm_block_t b, struct dm_block_validator *v,
struct dm_block **result)
{
struct buffer_aux *aux;
void *p;
int r;
p = dm_bufio_read(to_bufio(bm), b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p)))
return PTR_ERR(p);
aux = dm_bufio_get_aux_data(to_buffer(*result));
r = bl_down_write(&aux->lock);
if (r) {
dm_bufio_release(to_buffer(*result));
report_recursive_bug(b, r);
return r;
}
aux->write_locked = 1;
r = dm_bm_validate_buffer(bm, to_buffer(*result), aux, v);
if (unlikely(r)) {
bl_up_write(&aux->lock);
dm_bufio_release(to_buffer(*result));
return r;
}
return 0;
}
EXPORT_SYMBOL_GPL(dm_bm_write_lock);
int dm_bm_read_try_lock(struct dm_block_manager *bm,
dm_block_t b, struct dm_block_validator *v,
struct dm_block **result)
{
struct buffer_aux *aux;
void *p;
int r;
p = dm_bufio_get(to_bufio(bm), b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p)))
return PTR_ERR(p);
if (unlikely(!p))
return -EWOULDBLOCK;
aux = dm_bufio_get_aux_data(to_buffer(*result));
r = bl_down_read_nonblock(&aux->lock);
if (r < 0) {
dm_bufio_release(to_buffer(*result));
report_recursive_bug(b, r);
return r;
}
aux->write_locked = 0;
r = dm_bm_validate_buffer(bm, to_buffer(*result), aux, v);
if (unlikely(r)) {
bl_up_read(&aux->lock);
dm_bufio_release(to_buffer(*result));
return r;
}
return 0;
}
int dm_bm_write_lock_zero(struct dm_block_manager *bm,
dm_block_t b, struct dm_block_validator *v,
struct dm_block **result)
{
int r;
struct buffer_aux *aux;
void *p;
p = dm_bufio_new(to_bufio(bm), b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p)))
return PTR_ERR(p);
memset(p, 0, dm_bm_block_size(bm));
aux = dm_bufio_get_aux_data(to_buffer(*result));
r = bl_down_write(&aux->lock);
if (r) {
dm_bufio_release(to_buffer(*result));
return r;
}
aux->write_locked = 1;
aux->validator = v;
return 0;
}
int dm_bm_unlock(struct dm_block *b)
{
struct buffer_aux *aux;
aux = dm_bufio_get_aux_data(to_buffer(b));
if (aux->write_locked) {
dm_bufio_mark_buffer_dirty(to_buffer(b));
bl_up_write(&aux->lock);
} else
bl_up_read(&aux->lock);
dm_bufio_release(to_buffer(b));
return 0;
}
EXPORT_SYMBOL_GPL(dm_bm_unlock);
int dm_bm_unlock_move(struct dm_block *b, dm_block_t n)
{
struct buffer_aux *aux;
aux = dm_bufio_get_aux_data(to_buffer(b));
if (aux->write_locked) {
dm_bufio_mark_buffer_dirty(to_buffer(b));
bl_up_write(&aux->lock);
} else
bl_up_read(&aux->lock);
dm_bufio_release_move(to_buffer(b), n);
return 0;
}
int dm_bm_flush_and_unlock(struct dm_block_manager *bm,
struct dm_block *superblock)
{
int r;
r = dm_bufio_write_dirty_buffers(to_bufio(bm));
if (unlikely(r))
return r;
r = dm_bufio_issue_flush(to_bufio(bm));
if (unlikely(r))
return r;
dm_bm_unlock(superblock);
r = dm_bufio_write_dirty_buffers(to_bufio(bm));
if (unlikely(r))
return r;
r = dm_bufio_issue_flush(to_bufio(bm));
if (unlikely(r))
return r;
return 0;
}
u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor)
{
return crc32c(~(u32) 0, data, len) ^ init_xor;
}
EXPORT_SYMBOL_GPL(dm_bm_checksum);
/*----------------------------------------------------------------*/
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
MODULE_DESCRIPTION("Immutable metadata library for dm");
/*----------------------------------------------------------------*/
| gpl-2.0 |
cmartinbaughman/android_kernel_htc_msm8660-bt | drivers/ide/it8213.c | 9217 | 5669 | /*
* ITE 8213 IDE driver
*
* Copyright (C) 2006 Jack Lee
* Copyright (C) 2006 Alan Cox
* Copyright (C) 2007 Bartlomiej Zolnierkiewicz
*/
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/ide.h>
#include <linux/init.h>
#define DRV_NAME "it8213"
/**
* it8213_set_pio_mode - set host controller for PIO mode
* @hwif: port
* @drive: drive
*
* Set the interface PIO mode.
*/
static void it8213_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
{
struct pci_dev *dev = to_pci_dev(hwif->dev);
int is_slave = drive->dn & 1;
int master_port = 0x40;
int slave_port = 0x44;
unsigned long flags;
u16 master_data;
u8 slave_data;
static DEFINE_SPINLOCK(tune_lock);
int control = 0;
const u8 pio = drive->pio_mode - XFER_PIO_0;
static const u8 timings[][2] = {
{ 0, 0 },
{ 0, 0 },
{ 1, 0 },
{ 2, 1 },
{ 2, 3 }, };
spin_lock_irqsave(&tune_lock, flags);
pci_read_config_word(dev, master_port, &master_data);
if (pio > 1)
control |= 1; /* Programmable timing on */
if (drive->media != ide_disk)
control |= 4; /* ATAPI */
if (ide_pio_need_iordy(drive, pio))
control |= 2; /* IORDY */
if (is_slave) {
master_data |= 0x4000;
master_data &= ~0x0070;
if (pio > 1)
master_data = master_data | (control << 4);
pci_read_config_byte(dev, slave_port, &slave_data);
slave_data = slave_data & 0xf0;
slave_data = slave_data | (timings[pio][0] << 2) | timings[pio][1];
} else {
master_data &= ~0x3307;
if (pio > 1)
master_data = master_data | control;
master_data = master_data | (timings[pio][0] << 12) | (timings[pio][1] << 8);
}
pci_write_config_word(dev, master_port, master_data);
if (is_slave)
pci_write_config_byte(dev, slave_port, slave_data);
spin_unlock_irqrestore(&tune_lock, flags);
}
/**
* it8213_set_dma_mode - set host controller for DMA mode
* @hwif: port
* @drive: drive
*
* Tune the ITE chipset for the DMA mode.
*/
static void it8213_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
{
struct pci_dev *dev = to_pci_dev(hwif->dev);
u8 maslave = 0x40;
int a_speed = 3 << (drive->dn * 4);
int u_flag = 1 << drive->dn;
int v_flag = 0x01 << drive->dn;
int w_flag = 0x10 << drive->dn;
int u_speed = 0;
u16 reg4042, reg4a;
u8 reg48, reg54, reg55;
const u8 speed = drive->dma_mode;
pci_read_config_word(dev, maslave, ®4042);
pci_read_config_byte(dev, 0x48, ®48);
pci_read_config_word(dev, 0x4a, ®4a);
pci_read_config_byte(dev, 0x54, ®54);
pci_read_config_byte(dev, 0x55, ®55);
if (speed >= XFER_UDMA_0) {
u8 udma = speed - XFER_UDMA_0;
u_speed = min_t(u8, 2 - (udma & 1), udma) << (drive->dn * 4);
if (!(reg48 & u_flag))
pci_write_config_byte(dev, 0x48, reg48 | u_flag);
if (speed >= XFER_UDMA_5)
pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag);
else
pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
if ((reg4a & a_speed) != u_speed)
pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed);
if (speed > XFER_UDMA_2) {
if (!(reg54 & v_flag))
pci_write_config_byte(dev, 0x54, reg54 | v_flag);
} else
pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
} else {
const u8 mwdma_to_pio[] = { 0, 3, 4 };
if (reg48 & u_flag)
pci_write_config_byte(dev, 0x48, reg48 & ~u_flag);
if (reg4a & a_speed)
pci_write_config_word(dev, 0x4a, reg4a & ~a_speed);
if (reg54 & v_flag)
pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
if (reg55 & w_flag)
pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag);
if (speed >= XFER_MW_DMA_0)
drive->pio_mode =
mwdma_to_pio[speed - XFER_MW_DMA_0] + XFER_PIO_0;
else
drive->pio_mode = XFER_PIO_2; /* for SWDMA2 */
it8213_set_pio_mode(hwif, drive);
}
}
static u8 it8213_cable_detect(ide_hwif_t *hwif)
{
struct pci_dev *dev = to_pci_dev(hwif->dev);
u8 reg42h = 0;
pci_read_config_byte(dev, 0x42, ®42h);
return (reg42h & 0x02) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
}
static const struct ide_port_ops it8213_port_ops = {
.set_pio_mode = it8213_set_pio_mode,
.set_dma_mode = it8213_set_dma_mode,
.cable_detect = it8213_cable_detect,
};
static const struct ide_port_info it8213_chipset __devinitdata = {
.name = DRV_NAME,
.enablebits = { {0x41, 0x80, 0x80} },
.port_ops = &it8213_port_ops,
.host_flags = IDE_HFLAG_SINGLE,
.pio_mask = ATA_PIO4,
.swdma_mask = ATA_SWDMA2_ONLY,
.mwdma_mask = ATA_MWDMA12_ONLY,
.udma_mask = ATA_UDMA6,
};
/**
* it8213_init_one - pci layer discovery entry
* @dev: PCI device
* @id: ident table entry
*
* Called by the PCI code when it finds an ITE8213 controller. As
* this device follows the standard interfaces we can use the
* standard helper functions to do almost all the work for us.
*/
static int __devinit it8213_init_one(struct pci_dev *dev, const struct pci_device_id *id)
{
return ide_pci_init_one(dev, &it8213_chipset, NULL);
}
static const struct pci_device_id it8213_pci_tbl[] = {
{ PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8213), 0 },
{ 0, },
};
MODULE_DEVICE_TABLE(pci, it8213_pci_tbl);
static struct pci_driver it8213_pci_driver = {
.name = "ITE8213_IDE",
.id_table = it8213_pci_tbl,
.probe = it8213_init_one,
.remove = ide_pci_remove,
.suspend = ide_pci_suspend,
.resume = ide_pci_resume,
};
static int __init it8213_ide_init(void)
{
return ide_pci_register_driver(&it8213_pci_driver);
}
static void __exit it8213_ide_exit(void)
{
pci_unregister_driver(&it8213_pci_driver);
}
module_init(it8213_ide_init);
module_exit(it8213_ide_exit);
MODULE_AUTHOR("Jack Lee, Alan Cox");
MODULE_DESCRIPTION("PCI driver module for the ITE 8213");
MODULE_LICENSE("GPL");
| gpl-2.0 |
Fusion-Devices/android_kernel_samsung_manta | drivers/s390/char/sclp_cpi.c | 9985 | 1088 | /*
* drivers/s390/char/sclp_cpi.c
* SCLP control programm identification
*
* Copyright IBM Corp. 2001, 2007
* Author(s): Martin Peschke <mpeschke@de.ibm.com>
* Michael Ernst <mernst@de.ibm.com>
*/
#include <linux/kmod.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/version.h>
#include "sclp_cpi_sys.h"
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Identify this operating system instance "
"to the System z hardware");
MODULE_AUTHOR("Martin Peschke <mpeschke@de.ibm.com>, "
"Michael Ernst <mernst@de.ibm.com>");
static char *system_name = "";
static char *sysplex_name = "";
module_param(system_name, charp, 0);
MODULE_PARM_DESC(system_name, "e.g. hostname - max. 8 characters");
module_param(sysplex_name, charp, 0);
MODULE_PARM_DESC(sysplex_name, "if applicable - max. 8 characters");
static int __init cpi_module_init(void)
{
return sclp_cpi_set_data(system_name, sysplex_name, "LINUX",
LINUX_VERSION_CODE);
}
static void __exit cpi_module_exit(void)
{
}
module_init(cpi_module_init);
module_exit(cpi_module_exit);
| gpl-2.0 |
lbxl2345/glibc | sysdeps/mach/hurd/poll.c | 2 | 1586 | /* poll file descriptors. Hurd version.
Copyright (C) 1998-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sys/poll.h>
#include <sys/time.h>
#include <hurd.h>
#include <hurd/fd.h>
/* Poll the file descriptors described by the NFDS structures starting at
FDS. If TIMEOUT is nonzero and not -1, allow TIMEOUT milliseconds for
an event to occur; if TIMEOUT is -1, block until an event occurs.
Returns the number of file descriptors with events, zero if timed out,
or -1 for errors. */
int
__poll (struct pollfd *fds, nfds_t nfds, int timeout)
{
struct timespec ts, *to;
if (timeout < 0)
to = NULL;
else
{
ts.tv_sec = timeout / 1000;
ts.tv_nsec = (timeout % 1000) * 1000000;
to = &ts;
}
return _hurd_select (nfds, fds, NULL, NULL, NULL, to, NULL);
}
libc_hidden_def (__poll)
weak_alias (__poll, poll)
| gpl-2.0 |
mssurajkaiga/empathy | libempathy-gtk/empathy-dialpad-widget.c | 2 | 6240 | /*
* Copyright (C) 2011 Collabora Ltd.
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authors: Danielle Madeley <danielle.madeley@collabora.co.uk>
*/
#include <config.h>
#include "empathy-dialpad-widget.h"
#include <libempathy-gtk/empathy-dialpad-button.h>
G_DEFINE_TYPE (EmpathyDialpadWidget, empathy_dialpad_widget, GTK_TYPE_BOX);
enum /* signals */
{
START_TONE,
STOP_TONE,
NUM_SIGNALS
};
static guint signals[NUM_SIGNALS] = { 0, };
struct _EmpathyDialpadWidgetPrivate
{
GtkWidget *entry;
/* gchar representing the button (like '7') -> GtkButton */
GHashTable *buttons;
};
static void
empathy_dialpad_widget_dispose (GObject *object)
{
EmpathyDialpadWidget *self = EMPATHY_DIALPAD_WIDGET (object);
void (*chain_up) (GObject *) =
((GObjectClass *) empathy_dialpad_widget_parent_class)->dispose;
g_hash_table_unref (self->priv->buttons);
if (chain_up != NULL)
chain_up (object);
}
static void
empathy_dialpad_widget_class_init (EmpathyDialpadWidgetClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->dispose = empathy_dialpad_widget_dispose;
signals[START_TONE] = g_signal_new ("start-tone",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE,
1, G_TYPE_UINT);
signals[STOP_TONE] = g_signal_new ("stop-tone",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE,
1, G_TYPE_UINT);
g_type_class_add_private (gobject_class,
sizeof (EmpathyDialpadWidgetPrivate));
}
static gboolean
dtmf_dialpad_button_pressed_cb (EmpathyDialpadButton *button,
GdkEventButton *event,
EmpathyDialpadWidget *self)
{
GtkEntryBuffer *buffer = gtk_entry_get_buffer (GTK_ENTRY (self->priv->entry));
TpDTMFEvent tone;
const gchar *label;
tone = empathy_dialpad_button_get_event (button);
label = empathy_dialpad_button_get_label (button);
g_signal_emit (self, signals[START_TONE], 0, tone);
gtk_entry_buffer_insert_text (buffer, -1, label, -1);
gtk_editable_set_position (GTK_EDITABLE (self->priv->entry), -1);
return FALSE;
}
static gboolean
dtmf_dialpad_button_released_cb (EmpathyDialpadButton *button,
GdkEventButton *event,
EmpathyDialpadWidget *self)
{
TpDTMFEvent tone;
tone = empathy_dialpad_button_get_event (button);
g_signal_emit (self, signals[STOP_TONE], 0, tone);
return FALSE;
}
static void
empathy_dialpad_widget_init (EmpathyDialpadWidget *self)
{
GtkWidget *grid;
int i;
struct {
const gchar *label;
const gchar *sublabel;
TpDTMFEvent event;
} dtmfbuttons[] = { { "1", "", TP_DTMF_EVENT_DIGIT_1 },
{ "2", "abc", TP_DTMF_EVENT_DIGIT_2 },
{ "3", "def", TP_DTMF_EVENT_DIGIT_3 },
{ "4", "ghi", TP_DTMF_EVENT_DIGIT_4 },
{ "5", "jkl", TP_DTMF_EVENT_DIGIT_5 },
{ "6", "mno", TP_DTMF_EVENT_DIGIT_6 },
{ "7", "pqrs", TP_DTMF_EVENT_DIGIT_7 },
{ "8", "tuv", TP_DTMF_EVENT_DIGIT_8 },
{ "9", "wxyz", TP_DTMF_EVENT_DIGIT_9 },
{ "#", "", TP_DTMF_EVENT_HASH },
{ "0", "", TP_DTMF_EVENT_DIGIT_0 },
{ "*", "", TP_DTMF_EVENT_ASTERISK },
{ NULL, } };
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_DIALPAD_WIDGET,
EmpathyDialpadWidgetPrivate);
gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
GTK_ORIENTATION_VERTICAL);
gtk_box_set_spacing (GTK_BOX (self), 3);
self->priv->entry = gtk_entry_new ();
gtk_editable_set_editable (GTK_EDITABLE (self->priv->entry), FALSE);
gtk_box_pack_start (GTK_BOX (self), self->priv->entry, FALSE, FALSE, 3);
grid = gtk_grid_new ();
gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
gtk_grid_set_row_homogeneous (GTK_GRID (grid), TRUE);
self->priv->buttons = g_hash_table_new (NULL, NULL);
for (i = 0; dtmfbuttons[i].label != NULL; i++)
{
GtkWidget *button;
button = empathy_dialpad_button_new (dtmfbuttons[i].label,
dtmfbuttons[i].sublabel, dtmfbuttons[i].event);
gtk_grid_attach (GTK_GRID (grid), button, i % 3, i / 3,
1, 1);
g_signal_connect (G_OBJECT (button), "button-press-event",
G_CALLBACK (dtmf_dialpad_button_pressed_cb), self);
g_signal_connect (G_OBJECT (button), "button-release-event",
G_CALLBACK (dtmf_dialpad_button_released_cb), self);
g_hash_table_insert (self->priv->buttons,
GUINT_TO_POINTER (dtmfbuttons[i].label[0]), button);
}
gtk_box_pack_start (GTK_BOX (self), grid, FALSE, FALSE, 3);
/* show everything but the packing box */
gtk_widget_show_all (GTK_WIDGET (self));
gtk_widget_hide (GTK_WIDGET (self));
}
GtkWidget *
empathy_dialpad_widget_new (void)
{
return g_object_new (EMPATHY_TYPE_DIALPAD_WIDGET, NULL);
}
void
empathy_dialpad_widget_press_key (EmpathyDialpadWidget *self,
gchar key)
{
EmpathyDialpadButton *button;
button = g_hash_table_lookup (self->priv->buttons, GUINT_TO_POINTER (key));
if (button == NULL)
return;
/* gtk_widget_activate() just does the button-pressed animation, it doesn't
* fire the callbacks so we do it manually. */
dtmf_dialpad_button_pressed_cb (button, NULL, self);
gtk_widget_activate (GTK_WIDGET (button));
dtmf_dialpad_button_released_cb (button, NULL, self);
}
| gpl-2.0 |
iegor/kdevelop | lib/antlr/src/CommonHiddenStreamToken.cpp | 2 | 1098 | /* ANTLR Translator Generator
* Project led by Terence Parr at http://www.jGuru.com
* Software rights: http://www.antlr.org/license.html
*
* $Id: CommonHiddenStreamToken.cpp 626096 2007-01-22 06:35:06Z okellogg $
*/
#include "antlr/CommonHiddenStreamToken.hpp"
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
namespace antlr {
#endif
CommonHiddenStreamToken::CommonHiddenStreamToken()
: CommonToken()
{
}
CommonHiddenStreamToken::CommonHiddenStreamToken(int t, const ANTLR_USE_NAMESPACE(std)string& txt)
: CommonToken(t,txt)
{
}
CommonHiddenStreamToken::CommonHiddenStreamToken(const ANTLR_USE_NAMESPACE(std)string& s)
: CommonToken(s)
{
}
RefToken CommonHiddenStreamToken::getHiddenAfter()
{
return hiddenAfter;
}
RefToken CommonHiddenStreamToken::getHiddenBefore()
{
return hiddenBefore;
}
RefToken CommonHiddenStreamToken::factory()
{
return RefToken(new CommonHiddenStreamToken);
}
void CommonHiddenStreamToken::setHiddenAfter(RefToken t)
{
hiddenAfter = t;
}
void CommonHiddenStreamToken::setHiddenBefore(RefToken t)
{
hiddenBefore = t;
}
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
}
#endif
| gpl-2.0 |
linux-audit/audit-userspace | tools/aulastlog/aulastlog-llist.c | 2 | 2989 | /*
* aulastlog-llist.c - Minimal linked list library
* Copyright (c) 2008 Red Hat Inc., Durham, North Carolina.
* All Rights Reserved.
*
* This software may be freely redistributed and/or modified under the
* terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1335, USA.
*
* Authors:
* Steve Grubb <sgrubb@redhat.com>
*/
#include <stdlib.h>
#include <string.h>
#include "aulastlog-llist.h"
void list_create(llist *l)
{
l->head = NULL;
l->cur = NULL;
l->cnt = 0;
}
lnode *list_next(llist *l)
{
if (l->cur == NULL)
return NULL;
l->cur = l->cur->next;
return l->cur;
}
void list_append(llist *l, lnode *node)
{
lnode* newnode;
newnode = malloc(sizeof(lnode));
newnode->sec = node->sec;
newnode->uid = node->uid;
newnode->name = strdup(node->name);
if (node->host)
newnode->host = strdup(node->host);
else
newnode->host = NULL;
if (node->term)
newnode->term = strdup(node->term);
else
newnode->term = NULL;
newnode->item = l->cnt;
newnode->next = NULL;
// if we are at top, fix this up
if (l->head == NULL)
l->head = newnode;
else // Otherwise add pointer to newnode
l->cur->next = newnode;
// make newnode current
l->cur = newnode;
l->cnt++;
}
void list_clear(llist* l)
{
lnode* nextnode;
register lnode* current;
current = l->head;
while (current) {
nextnode=current->next;
free(current->name);
free(current->host);
free(current->term);
free(current);
current=nextnode;
}
l->head = NULL;
l->cur = NULL;
l->cnt = 0;
}
int list_update_login(llist* l, time_t t)
{
register lnode* cur;
if (l == NULL)
return 0;
cur=list_get_cur(l);
cur->sec = t;
return 1;
}
int list_update_host(llist* l, const char *h)
{
register lnode* cur;
if (l == NULL)
return 0;
cur=list_get_cur(l);
if (h) {
free(cur->host);
cur->host = strdup(h);
} else
cur->host = NULL;
return 1;
}
int list_update_term(llist* l, const char *t)
{
register lnode* cur;
if (l == NULL)
return 0;
cur=list_get_cur(l);
if (t) {
free(cur->term);
cur->term = strdup(t);
} else
cur->term = NULL;
return 1;
}
lnode *list_find_uid(llist *l, uid_t uid)
{
register lnode* node;
node = l->head; /* start at the beginning */
while (node) {
if (node->uid == uid) {
l->cur = node;
return node;
} else
node = node->next;
}
return NULL;
}
| gpl-2.0 |
totalspectrum/binutils-propeller | gdb/avr-tdep.c | 2 | 51442 | /* Target-dependent code for Atmel AVR, for GDB.
Copyright (C) 1996-2017 Free Software Foundation, Inc.
This file is part of GDB.
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Contributed by Theodore A. Roth, troth@openavr.org */
/* Portions of this file were taken from the original gdb-4.18 patch developed
by Denis Chertykov, denisc@overta.ru */
#include "defs.h"
#include "frame.h"
#include "frame-unwind.h"
#include "frame-base.h"
#include "trad-frame.h"
#include "gdbcmd.h"
#include "gdbcore.h"
#include "gdbtypes.h"
#include "inferior.h"
#include "symfile.h"
#include "arch-utils.h"
#include "regcache.h"
#include "dis-asm.h"
#include "objfiles.h"
#include <algorithm>
/* AVR Background:
(AVR micros are pure Harvard Architecture processors.)
The AVR family of microcontrollers have three distinctly different memory
spaces: flash, sram and eeprom. The flash is 16 bits wide and is used for
the most part to store program instructions. The sram is 8 bits wide and is
used for the stack and the heap. Some devices lack sram and some can have
an additional external sram added on as a peripheral.
The eeprom is 8 bits wide and is used to store data when the device is
powered down. Eeprom is not directly accessible, it can only be accessed
via io-registers using a special algorithm. Accessing eeprom via gdb's
remote serial protocol ('m' or 'M' packets) looks difficult to do and is
not included at this time.
[The eeprom could be read manually via ``x/b <eaddr + AVR_EMEM_START>'' or
written using ``set {unsigned char}<eaddr + AVR_EMEM_START>''. For this to
work, the remote target must be able to handle eeprom accesses and perform
the address translation.]
All three memory spaces have physical addresses beginning at 0x0. In
addition, the flash is addressed by gcc/binutils/gdb with respect to 8 bit
bytes instead of the 16 bit wide words used by the real device for the
Program Counter.
In order for remote targets to work correctly, extra bits must be added to
addresses before they are send to the target or received from the target
via the remote serial protocol. The extra bits are the MSBs and are used to
decode which memory space the address is referring to. */
/* Constants: prefixed with AVR_ to avoid name space clashes */
/* Address space flags */
/* We are assigning the TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 to the flash address
space. */
#define AVR_TYPE_ADDRESS_CLASS_FLASH TYPE_ADDRESS_CLASS_1
#define AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH \
TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
enum
{
AVR_REG_W = 24,
AVR_REG_X = 26,
AVR_REG_Y = 28,
AVR_FP_REGNUM = 28,
AVR_REG_Z = 30,
AVR_SREG_REGNUM = 32,
AVR_SP_REGNUM = 33,
AVR_PC_REGNUM = 34,
AVR_NUM_REGS = 32 + 1 /*SREG*/ + 1 /*SP*/ + 1 /*PC*/,
AVR_NUM_REG_BYTES = 32 + 1 /*SREG*/ + 2 /*SP*/ + 4 /*PC*/,
/* Pseudo registers. */
AVR_PSEUDO_PC_REGNUM = 35,
AVR_NUM_PSEUDO_REGS = 1,
AVR_PC_REG_INDEX = 35, /* index into array of registers */
AVR_MAX_PROLOGUE_SIZE = 64, /* bytes */
/* Count of pushed registers. From r2 to r17 (inclusively), r28, r29 */
AVR_MAX_PUSHES = 18,
/* Number of the last pushed register. r17 for current avr-gcc */
AVR_LAST_PUSHED_REGNUM = 17,
AVR_ARG1_REGNUM = 24, /* Single byte argument */
AVR_ARGN_REGNUM = 25, /* Multi byte argments */
AVR_LAST_ARG_REGNUM = 8, /* Last argument register */
AVR_RET1_REGNUM = 24, /* Single byte return value */
AVR_RETN_REGNUM = 25, /* Multi byte return value */
/* FIXME: TRoth/2002-01-??: Can we shift all these memory masks left 8
bits? Do these have to match the bfd vma values? It sure would make
things easier in the future if they didn't need to match.
Note: I chose these values so as to be consistent with bfd vma
addresses.
TRoth/2002-04-08: There is already a conflict with very large programs
in the mega128. The mega128 has 128K instruction bytes (64K words),
thus the Most Significant Bit is 0x10000 which gets masked off my
AVR_MEM_MASK.
The problem manifests itself when trying to set a breakpoint in a
function which resides in the upper half of the instruction space and
thus requires a 17-bit address.
For now, I've just removed the EEPROM mask and changed AVR_MEM_MASK
from 0x00ff0000 to 0x00f00000. Eeprom is not accessible from gdb yet,
but could be for some remote targets by just adding the correct offset
to the address and letting the remote target handle the low-level
details of actually accessing the eeprom. */
AVR_IMEM_START = 0x00000000, /* INSN memory */
AVR_SMEM_START = 0x00800000, /* SRAM memory */
#if 1
/* No eeprom mask defined */
AVR_MEM_MASK = 0x00f00000, /* mask to determine memory space */
#else
AVR_EMEM_START = 0x00810000, /* EEPROM memory */
AVR_MEM_MASK = 0x00ff0000, /* mask to determine memory space */
#endif
};
/* Prologue types:
NORMAL and CALL are the typical types (the -mcall-prologues gcc option
causes the generation of the CALL type prologues). */
enum {
AVR_PROLOGUE_NONE, /* No prologue */
AVR_PROLOGUE_NORMAL,
AVR_PROLOGUE_CALL, /* -mcall-prologues */
AVR_PROLOGUE_MAIN,
AVR_PROLOGUE_INTR, /* interrupt handler */
AVR_PROLOGUE_SIG, /* signal handler */
};
/* Any function with a frame looks like this
....... <-SP POINTS HERE
LOCALS1 <-FP POINTS HERE
LOCALS0
SAVED FP
SAVED R3
SAVED R2
RET PC
FIRST ARG
SECOND ARG */
struct avr_unwind_cache
{
/* The previous frame's inner most stack address. Used as this
frame ID's stack_addr. */
CORE_ADDR prev_sp;
/* The frame's base, optionally used by the high-level debug info. */
CORE_ADDR base;
int size;
int prologue_type;
/* Table indicating the location of each and every register. */
struct trad_frame_saved_reg *saved_regs;
};
struct gdbarch_tdep
{
/* Number of bytes stored to the stack by call instructions.
2 bytes for avr1-5 and avrxmega1-5, 3 bytes for avr6 and avrxmega6-7. */
int call_length;
/* Type for void. */
struct type *void_type;
/* Type for a function returning void. */
struct type *func_void_type;
/* Type for a pointer to a function. Used for the type of PC. */
struct type *pc_type;
};
/* Lookup the name of a register given it's number. */
static const char *
avr_register_name (struct gdbarch *gdbarch, int regnum)
{
static const char * const register_names[] = {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
"r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
"SREG", "SP", "PC2",
"pc"
};
if (regnum < 0)
return NULL;
if (regnum >= (sizeof (register_names) / sizeof (*register_names)))
return NULL;
return register_names[regnum];
}
/* Return the GDB type object for the "standard" data type
of data in register N. */
static struct type *
avr_register_type (struct gdbarch *gdbarch, int reg_nr)
{
if (reg_nr == AVR_PC_REGNUM)
return builtin_type (gdbarch)->builtin_uint32;
if (reg_nr == AVR_PSEUDO_PC_REGNUM)
return gdbarch_tdep (gdbarch)->pc_type;
if (reg_nr == AVR_SP_REGNUM)
return builtin_type (gdbarch)->builtin_data_ptr;
return builtin_type (gdbarch)->builtin_uint8;
}
/* Instruction address checks and convertions. */
static CORE_ADDR
avr_make_iaddr (CORE_ADDR x)
{
return ((x) | AVR_IMEM_START);
}
/* FIXME: TRoth: Really need to use a larger mask for instructions. Some
devices are already up to 128KBytes of flash space.
TRoth/2002-04-8: See comment above where AVR_IMEM_START is defined. */
static CORE_ADDR
avr_convert_iaddr_to_raw (CORE_ADDR x)
{
return ((x) & 0xffffffff);
}
/* SRAM address checks and convertions. */
static CORE_ADDR
avr_make_saddr (CORE_ADDR x)
{
/* Return 0 for NULL. */
if (x == 0)
return 0;
return ((x) | AVR_SMEM_START);
}
static CORE_ADDR
avr_convert_saddr_to_raw (CORE_ADDR x)
{
return ((x) & 0xffffffff);
}
/* EEPROM address checks and convertions. I don't know if these will ever
actually be used, but I've added them just the same. TRoth */
/* TRoth/2002-04-08: Commented out for now to allow fix for problem with large
programs in the mega128. */
/* static CORE_ADDR */
/* avr_make_eaddr (CORE_ADDR x) */
/* { */
/* return ((x) | AVR_EMEM_START); */
/* } */
/* static int */
/* avr_eaddr_p (CORE_ADDR x) */
/* { */
/* return (((x) & AVR_MEM_MASK) == AVR_EMEM_START); */
/* } */
/* static CORE_ADDR */
/* avr_convert_eaddr_to_raw (CORE_ADDR x) */
/* { */
/* return ((x) & 0xffffffff); */
/* } */
/* Convert from address to pointer and vice-versa. */
static void
avr_address_to_pointer (struct gdbarch *gdbarch,
struct type *type, gdb_byte *buf, CORE_ADDR addr)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* Is it a data address in flash? */
if (AVR_TYPE_ADDRESS_CLASS_FLASH (type))
{
/* A data pointer in flash is byte addressed. */
store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order,
avr_convert_iaddr_to_raw (addr));
}
/* Is it a code address? */
else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
|| TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
{
/* A code pointer is word (16 bits) addressed. We shift the address down
by 1 bit to convert it to a pointer. */
store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order,
avr_convert_iaddr_to_raw (addr >> 1));
}
else
{
/* Strip off any upper segment bits. */
store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order,
avr_convert_saddr_to_raw (addr));
}
}
static CORE_ADDR
avr_pointer_to_address (struct gdbarch *gdbarch,
struct type *type, const gdb_byte *buf)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
CORE_ADDR addr
= extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order);
/* Is it a data address in flash? */
if (AVR_TYPE_ADDRESS_CLASS_FLASH (type))
{
/* A data pointer in flash is already byte addressed. */
return avr_make_iaddr (addr);
}
/* Is it a code address? */
else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC
|| TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD
|| TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type)))
{
/* A code pointer is word (16 bits) addressed so we shift it up
by 1 bit to convert it to an address. */
return avr_make_iaddr (addr << 1);
}
else
return avr_make_saddr (addr);
}
static CORE_ADDR
avr_integer_to_address (struct gdbarch *gdbarch,
struct type *type, const gdb_byte *buf)
{
ULONGEST addr = unpack_long (type, buf);
return avr_make_saddr (addr);
}
static CORE_ADDR
avr_read_pc (struct regcache *regcache)
{
ULONGEST pc;
regcache_cooked_read_unsigned (regcache, AVR_PC_REGNUM, &pc);
return avr_make_iaddr (pc);
}
static void
avr_write_pc (struct regcache *regcache, CORE_ADDR val)
{
regcache_cooked_write_unsigned (regcache, AVR_PC_REGNUM,
avr_convert_iaddr_to_raw (val));
}
static enum register_status
avr_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
int regnum, gdb_byte *buf)
{
ULONGEST val;
enum register_status status;
switch (regnum)
{
case AVR_PSEUDO_PC_REGNUM:
status = regcache_raw_read_unsigned (regcache, AVR_PC_REGNUM, &val);
if (status != REG_VALID)
return status;
val >>= 1;
store_unsigned_integer (buf, 4, gdbarch_byte_order (gdbarch), val);
return status;
default:
internal_error (__FILE__, __LINE__, _("invalid regnum"));
}
}
static void
avr_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
int regnum, const gdb_byte *buf)
{
ULONGEST val;
switch (regnum)
{
case AVR_PSEUDO_PC_REGNUM:
val = extract_unsigned_integer (buf, 4, gdbarch_byte_order (gdbarch));
val <<= 1;
regcache_raw_write_unsigned (regcache, AVR_PC_REGNUM, val);
break;
default:
internal_error (__FILE__, __LINE__, _("invalid regnum"));
}
}
/* Function: avr_scan_prologue
This function decodes an AVR function prologue to determine:
1) the size of the stack frame
2) which registers are saved on it
3) the offsets of saved regs
This information is stored in the avr_unwind_cache structure.
Some devices lack the sbiw instruction, so on those replace this:
sbiw r28, XX
with this:
subi r28,lo8(XX)
sbci r29,hi8(XX)
A typical AVR function prologue with a frame pointer might look like this:
push rXX ; saved regs
...
push r28
push r29
in r28,__SP_L__
in r29,__SP_H__
sbiw r28,<LOCALS_SIZE>
in __tmp_reg__,__SREG__
cli
out __SP_H__,r29
out __SREG__,__tmp_reg__
out __SP_L__,r28
A typical AVR function prologue without a frame pointer might look like
this:
push rXX ; saved regs
...
A main function prologue looks like this:
ldi r28,lo8(<RAM_ADDR> - <LOCALS_SIZE>)
ldi r29,hi8(<RAM_ADDR> - <LOCALS_SIZE>)
out __SP_H__,r29
out __SP_L__,r28
A signal handler prologue looks like this:
push __zero_reg__
push __tmp_reg__
in __tmp_reg__, __SREG__
push __tmp_reg__
clr __zero_reg__
push rXX ; save registers r18:r27, r30:r31
...
push r28 ; save frame pointer
push r29
in r28, __SP_L__
in r29, __SP_H__
sbiw r28, <LOCALS_SIZE>
out __SP_H__, r29
out __SP_L__, r28
A interrupt handler prologue looks like this:
sei
push __zero_reg__
push __tmp_reg__
in __tmp_reg__, __SREG__
push __tmp_reg__
clr __zero_reg__
push rXX ; save registers r18:r27, r30:r31
...
push r28 ; save frame pointer
push r29
in r28, __SP_L__
in r29, __SP_H__
sbiw r28, <LOCALS_SIZE>
cli
out __SP_H__, r29
sei
out __SP_L__, r28
A `-mcall-prologues' prologue looks like this (Note that the megas use a
jmp instead of a rjmp, thus the prologue is one word larger since jmp is a
32 bit insn and rjmp is a 16 bit insn):
ldi r26,lo8(<LOCALS_SIZE>)
ldi r27,hi8(<LOCALS_SIZE>)
ldi r30,pm_lo8(.L_foo_body)
ldi r31,pm_hi8(.L_foo_body)
rjmp __prologue_saves__+RRR
.L_foo_body: */
/* Not really part of a prologue, but still need to scan for it, is when a
function prologue moves values passed via registers as arguments to new
registers. In this case, all local variables live in registers, so there
may be some register saves. This is what it looks like:
movw rMM, rNN
...
There could be multiple movw's. If the target doesn't have a movw insn, it
will use two mov insns. This could be done after any of the above prologue
types. */
static CORE_ADDR
avr_scan_prologue (struct gdbarch *gdbarch, CORE_ADDR pc_beg, CORE_ADDR pc_end,
struct avr_unwind_cache *info)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
int i;
unsigned short insn;
int scan_stage = 0;
struct bound_minimal_symbol msymbol;
unsigned char prologue[AVR_MAX_PROLOGUE_SIZE];
int vpc = 0;
int len;
len = pc_end - pc_beg;
if (len > AVR_MAX_PROLOGUE_SIZE)
len = AVR_MAX_PROLOGUE_SIZE;
/* FIXME: TRoth/2003-06-11: This could be made more efficient by only
reading in the bytes of the prologue. The problem is that the figuring
out where the end of the prologue is is a bit difficult. The old code
tried to do that, but failed quite often. */
read_memory (pc_beg, prologue, len);
/* Scanning main()'s prologue
ldi r28,lo8(<RAM_ADDR> - <LOCALS_SIZE>)
ldi r29,hi8(<RAM_ADDR> - <LOCALS_SIZE>)
out __SP_H__,r29
out __SP_L__,r28 */
if (len >= 4)
{
CORE_ADDR locals;
static const unsigned char img[] = {
0xde, 0xbf, /* out __SP_H__,r29 */
0xcd, 0xbf /* out __SP_L__,r28 */
};
insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
/* ldi r28,lo8(<RAM_ADDR> - <LOCALS_SIZE>) */
if ((insn & 0xf0f0) == 0xe0c0)
{
locals = (insn & 0xf) | ((insn & 0x0f00) >> 4);
insn = extract_unsigned_integer (&prologue[vpc + 2], 2, byte_order);
/* ldi r29,hi8(<RAM_ADDR> - <LOCALS_SIZE>) */
if ((insn & 0xf0f0) == 0xe0d0)
{
locals |= ((insn & 0xf) | ((insn & 0x0f00) >> 4)) << 8;
if (vpc + 4 + sizeof (img) < len
&& memcmp (prologue + vpc + 4, img, sizeof (img)) == 0)
{
info->prologue_type = AVR_PROLOGUE_MAIN;
info->base = locals;
return pc_beg + 4;
}
}
}
}
/* Scanning `-mcall-prologues' prologue
Classic prologue is 10 bytes, mega prologue is a 12 bytes long */
while (1) /* Using a while to avoid many goto's */
{
int loc_size;
int body_addr;
unsigned num_pushes;
int pc_offset = 0;
/* At least the fifth instruction must have been executed to
modify frame shape. */
if (len < 10)
break;
insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
/* ldi r26,<LOCALS_SIZE> */
if ((insn & 0xf0f0) != 0xe0a0)
break;
loc_size = (insn & 0xf) | ((insn & 0x0f00) >> 4);
pc_offset += 2;
insn = extract_unsigned_integer (&prologue[vpc + 2], 2, byte_order);
/* ldi r27,<LOCALS_SIZE> / 256 */
if ((insn & 0xf0f0) != 0xe0b0)
break;
loc_size |= ((insn & 0xf) | ((insn & 0x0f00) >> 4)) << 8;
pc_offset += 2;
insn = extract_unsigned_integer (&prologue[vpc + 4], 2, byte_order);
/* ldi r30,pm_lo8(.L_foo_body) */
if ((insn & 0xf0f0) != 0xe0e0)
break;
body_addr = (insn & 0xf) | ((insn & 0x0f00) >> 4);
pc_offset += 2;
insn = extract_unsigned_integer (&prologue[vpc + 6], 2, byte_order);
/* ldi r31,pm_hi8(.L_foo_body) */
if ((insn & 0xf0f0) != 0xe0f0)
break;
body_addr |= ((insn & 0xf) | ((insn & 0x0f00) >> 4)) << 8;
pc_offset += 2;
msymbol = lookup_minimal_symbol ("__prologue_saves__", NULL, NULL);
if (!msymbol.minsym)
break;
insn = extract_unsigned_integer (&prologue[vpc + 8], 2, byte_order);
/* rjmp __prologue_saves__+RRR */
if ((insn & 0xf000) == 0xc000)
{
/* Extract PC relative offset from RJMP */
i = (insn & 0xfff) | (insn & 0x800 ? (-1 ^ 0xfff) : 0);
/* Convert offset to byte addressable mode */
i *= 2;
/* Destination address */
i += pc_beg + 10;
if (body_addr != (pc_beg + 10)/2)
break;
pc_offset += 2;
}
else if ((insn & 0xfe0e) == 0x940c)
{
/* Extract absolute PC address from JMP */
i = (((insn & 0x1) | ((insn & 0x1f0) >> 3) << 16)
| (extract_unsigned_integer (&prologue[vpc + 10], 2, byte_order)
& 0xffff));
/* Convert address to byte addressable mode */
i *= 2;
if (body_addr != (pc_beg + 12)/2)
break;
pc_offset += 4;
}
else
break;
/* Resolve offset (in words) from __prologue_saves__ symbol.
Which is a pushes count in `-mcall-prologues' mode */
num_pushes = AVR_MAX_PUSHES - (i - BMSYMBOL_VALUE_ADDRESS (msymbol)) / 2;
if (num_pushes > AVR_MAX_PUSHES)
{
fprintf_unfiltered (gdb_stderr, _("Num pushes too large: %d\n"),
num_pushes);
num_pushes = 0;
}
if (num_pushes)
{
int from;
info->saved_regs[AVR_FP_REGNUM + 1].addr = num_pushes;
if (num_pushes >= 2)
info->saved_regs[AVR_FP_REGNUM].addr = num_pushes - 1;
i = 0;
for (from = AVR_LAST_PUSHED_REGNUM + 1 - (num_pushes - 2);
from <= AVR_LAST_PUSHED_REGNUM; ++from)
info->saved_regs [from].addr = ++i;
}
info->size = loc_size + num_pushes;
info->prologue_type = AVR_PROLOGUE_CALL;
return pc_beg + pc_offset;
}
/* Scan for the beginning of the prologue for an interrupt or signal
function. Note that we have to set the prologue type here since the
third stage of the prologue may not be present (e.g. no saved registered
or changing of the SP register). */
if (1)
{
static const unsigned char img[] = {
0x78, 0x94, /* sei */
0x1f, 0x92, /* push r1 */
0x0f, 0x92, /* push r0 */
0x0f, 0xb6, /* in r0,0x3f SREG */
0x0f, 0x92, /* push r0 */
0x11, 0x24 /* clr r1 */
};
if (len >= sizeof (img)
&& memcmp (prologue, img, sizeof (img)) == 0)
{
info->prologue_type = AVR_PROLOGUE_INTR;
vpc += sizeof (img);
info->saved_regs[AVR_SREG_REGNUM].addr = 3;
info->saved_regs[0].addr = 2;
info->saved_regs[1].addr = 1;
info->size += 3;
}
else if (len >= sizeof (img) - 2
&& memcmp (img + 2, prologue, sizeof (img) - 2) == 0)
{
info->prologue_type = AVR_PROLOGUE_SIG;
vpc += sizeof (img) - 2;
info->saved_regs[AVR_SREG_REGNUM].addr = 3;
info->saved_regs[0].addr = 2;
info->saved_regs[1].addr = 1;
info->size += 2;
}
}
/* First stage of the prologue scanning.
Scan pushes (saved registers) */
for (; vpc < len; vpc += 2)
{
insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
if ((insn & 0xfe0f) == 0x920f) /* push rXX */
{
/* Bits 4-9 contain a mask for registers R0-R32. */
int regno = (insn & 0x1f0) >> 4;
info->size++;
info->saved_regs[regno].addr = info->size;
scan_stage = 1;
}
else
break;
}
gdb_assert (vpc < AVR_MAX_PROLOGUE_SIZE);
/* Handle static small stack allocation using rcall or push. */
while (scan_stage == 1 && vpc < len)
{
insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
if (insn == 0xd000) /* rcall .+0 */
{
info->size += gdbarch_tdep (gdbarch)->call_length;
vpc += 2;
}
else if (insn == 0x920f || insn == 0x921f) /* push r0 or push r1 */
{
info->size += 1;
vpc += 2;
}
else
break;
}
/* Second stage of the prologue scanning.
Scan:
in r28,__SP_L__
in r29,__SP_H__ */
if (scan_stage == 1 && vpc < len)
{
static const unsigned char img[] = {
0xcd, 0xb7, /* in r28,__SP_L__ */
0xde, 0xb7 /* in r29,__SP_H__ */
};
if (vpc + sizeof (img) < len
&& memcmp (prologue + vpc, img, sizeof (img)) == 0)
{
vpc += 4;
scan_stage = 2;
}
}
/* Third stage of the prologue scanning. (Really two stages).
Scan for:
sbiw r28,XX or subi r28,lo8(XX)
sbci r29,hi8(XX)
in __tmp_reg__,__SREG__
cli
out __SP_H__,r29
out __SREG__,__tmp_reg__
out __SP_L__,r28 */
if (scan_stage == 2 && vpc < len)
{
int locals_size = 0;
static const unsigned char img[] = {
0x0f, 0xb6, /* in r0,0x3f */
0xf8, 0x94, /* cli */
0xde, 0xbf, /* out 0x3e,r29 ; SPH */
0x0f, 0xbe, /* out 0x3f,r0 ; SREG */
0xcd, 0xbf /* out 0x3d,r28 ; SPL */
};
static const unsigned char img_sig[] = {
0xde, 0xbf, /* out 0x3e,r29 ; SPH */
0xcd, 0xbf /* out 0x3d,r28 ; SPL */
};
static const unsigned char img_int[] = {
0xf8, 0x94, /* cli */
0xde, 0xbf, /* out 0x3e,r29 ; SPH */
0x78, 0x94, /* sei */
0xcd, 0xbf /* out 0x3d,r28 ; SPL */
};
insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
if ((insn & 0xff30) == 0x9720) /* sbiw r28,XXX */
{
locals_size = (insn & 0xf) | ((insn & 0xc0) >> 2);
vpc += 2;
}
else if ((insn & 0xf0f0) == 0x50c0) /* subi r28,lo8(XX) */
{
locals_size = (insn & 0xf) | ((insn & 0xf00) >> 4);
vpc += 2;
insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
vpc += 2;
locals_size += ((insn & 0xf) | ((insn & 0xf00) >> 4)) << 8;
}
else
return pc_beg + vpc;
/* Scan the last part of the prologue. May not be present for interrupt
or signal handler functions, which is why we set the prologue type
when we saw the beginning of the prologue previously. */
if (vpc + sizeof (img_sig) < len
&& memcmp (prologue + vpc, img_sig, sizeof (img_sig)) == 0)
{
vpc += sizeof (img_sig);
}
else if (vpc + sizeof (img_int) < len
&& memcmp (prologue + vpc, img_int, sizeof (img_int)) == 0)
{
vpc += sizeof (img_int);
}
if (vpc + sizeof (img) < len
&& memcmp (prologue + vpc, img, sizeof (img)) == 0)
{
info->prologue_type = AVR_PROLOGUE_NORMAL;
vpc += sizeof (img);
}
info->size += locals_size;
/* Fall through. */
}
/* If we got this far, we could not scan the prologue, so just return the pc
of the frame plus an adjustment for argument move insns. */
for (; vpc < len; vpc += 2)
{
insn = extract_unsigned_integer (&prologue[vpc], 2, byte_order);
if ((insn & 0xff00) == 0x0100) /* movw rXX, rYY */
continue;
else if ((insn & 0xfc00) == 0x2c00) /* mov rXX, rYY */
continue;
else
break;
}
return pc_beg + vpc;
}
static CORE_ADDR
avr_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
{
CORE_ADDR func_addr, func_end;
CORE_ADDR post_prologue_pc;
/* See what the symbol table says */
if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
return pc;
post_prologue_pc = skip_prologue_using_sal (gdbarch, func_addr);
if (post_prologue_pc != 0)
return std::max (pc, post_prologue_pc);
{
CORE_ADDR prologue_end = pc;
struct avr_unwind_cache info = {0};
struct trad_frame_saved_reg saved_regs[AVR_NUM_REGS];
info.saved_regs = saved_regs;
/* Need to run the prologue scanner to figure out if the function has a
prologue and possibly skip over moving arguments passed via registers
to other registers. */
prologue_end = avr_scan_prologue (gdbarch, func_addr, func_end, &info);
if (info.prologue_type != AVR_PROLOGUE_NONE)
return prologue_end;
}
/* Either we didn't find the start of this function (nothing we can do),
or there's no line info, or the line after the prologue is after
the end of the function (there probably isn't a prologue). */
return pc;
}
/* Not all avr devices support the BREAK insn. Those that don't should treat
it as a NOP. Thus, it should be ok. Since the avr is currently a remote
only target, this shouldn't be a problem (I hope). TRoth/2003-05-14 */
constexpr gdb_byte avr_break_insn [] = { 0x98, 0x95 };
typedef BP_MANIPULATION (avr_break_insn) avr_breakpoint;
/* Determine, for architecture GDBARCH, how a return value of TYPE
should be returned. If it is supposed to be returned in registers,
and READBUF is non-zero, read the appropriate value from REGCACHE,
and copy it into READBUF. If WRITEBUF is non-zero, write the value
from WRITEBUF into REGCACHE. */
static enum return_value_convention
avr_return_value (struct gdbarch *gdbarch, struct value *function,
struct type *valtype, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
int i;
/* Single byte are returned in r24.
Otherwise, the MSB of the return value is always in r25, calculate which
register holds the LSB. */
int lsb_reg;
if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
|| TYPE_CODE (valtype) == TYPE_CODE_UNION
|| TYPE_CODE (valtype) == TYPE_CODE_ARRAY)
&& TYPE_LENGTH (valtype) > 8)
return RETURN_VALUE_STRUCT_CONVENTION;
if (TYPE_LENGTH (valtype) <= 2)
lsb_reg = 24;
else if (TYPE_LENGTH (valtype) <= 4)
lsb_reg = 22;
else if (TYPE_LENGTH (valtype) <= 8)
lsb_reg = 18;
else
gdb_assert_not_reached ("unexpected type length");
if (writebuf != NULL)
{
for (i = 0; i < TYPE_LENGTH (valtype); i++)
regcache_cooked_write (regcache, lsb_reg + i, writebuf + i);
}
if (readbuf != NULL)
{
for (i = 0; i < TYPE_LENGTH (valtype); i++)
regcache_cooked_read (regcache, lsb_reg + i, readbuf + i);
}
return RETURN_VALUE_REGISTER_CONVENTION;
}
/* Put here the code to store, into fi->saved_regs, the addresses of
the saved registers of frame described by FRAME_INFO. This
includes special registers such as pc and fp saved in special ways
in the stack frame. sp is even more special: the address we return
for it IS the sp for the next frame. */
static struct avr_unwind_cache *
avr_frame_unwind_cache (struct frame_info *this_frame,
void **this_prologue_cache)
{
CORE_ADDR start_pc, current_pc;
ULONGEST prev_sp;
ULONGEST this_base;
struct avr_unwind_cache *info;
struct gdbarch *gdbarch;
struct gdbarch_tdep *tdep;
int i;
if (*this_prologue_cache)
return (struct avr_unwind_cache *) *this_prologue_cache;
info = FRAME_OBSTACK_ZALLOC (struct avr_unwind_cache);
*this_prologue_cache = info;
info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
info->size = 0;
info->prologue_type = AVR_PROLOGUE_NONE;
start_pc = get_frame_func (this_frame);
current_pc = get_frame_pc (this_frame);
if ((start_pc > 0) && (start_pc <= current_pc))
avr_scan_prologue (get_frame_arch (this_frame),
start_pc, current_pc, info);
if ((info->prologue_type != AVR_PROLOGUE_NONE)
&& (info->prologue_type != AVR_PROLOGUE_MAIN))
{
ULONGEST high_base; /* High byte of FP */
/* The SP was moved to the FP. This indicates that a new frame
was created. Get THIS frame's FP value by unwinding it from
the next frame. */
this_base = get_frame_register_unsigned (this_frame, AVR_FP_REGNUM);
high_base = get_frame_register_unsigned (this_frame, AVR_FP_REGNUM + 1);
this_base += (high_base << 8);
/* The FP points at the last saved register. Adjust the FP back
to before the first saved register giving the SP. */
prev_sp = this_base + info->size;
}
else
{
/* Assume that the FP is this frame's SP but with that pushed
stack space added back. */
this_base = get_frame_register_unsigned (this_frame, AVR_SP_REGNUM);
prev_sp = this_base + info->size;
}
/* Add 1 here to adjust for the post-decrement nature of the push
instruction.*/
info->prev_sp = avr_make_saddr (prev_sp + 1);
info->base = avr_make_saddr (this_base);
gdbarch = get_frame_arch (this_frame);
/* Adjust all the saved registers so that they contain addresses and not
offsets. */
for (i = 0; i < gdbarch_num_regs (gdbarch) - 1; i++)
if (info->saved_regs[i].addr > 0)
info->saved_regs[i].addr = info->prev_sp - info->saved_regs[i].addr;
/* Except for the main and startup code, the return PC is always saved on
the stack and is at the base of the frame. */
if (info->prologue_type != AVR_PROLOGUE_MAIN)
info->saved_regs[AVR_PC_REGNUM].addr = info->prev_sp;
/* The previous frame's SP needed to be computed. Save the computed
value. */
tdep = gdbarch_tdep (gdbarch);
trad_frame_set_value (info->saved_regs, AVR_SP_REGNUM,
info->prev_sp - 1 + tdep->call_length);
return info;
}
static CORE_ADDR
avr_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
{
ULONGEST pc;
pc = frame_unwind_register_unsigned (next_frame, AVR_PC_REGNUM);
return avr_make_iaddr (pc);
}
static CORE_ADDR
avr_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
{
ULONGEST sp;
sp = frame_unwind_register_unsigned (next_frame, AVR_SP_REGNUM);
return avr_make_saddr (sp);
}
/* Given a GDB frame, determine the address of the calling function's
frame. This will be used to create a new GDB frame struct. */
static void
avr_frame_this_id (struct frame_info *this_frame,
void **this_prologue_cache,
struct frame_id *this_id)
{
struct avr_unwind_cache *info
= avr_frame_unwind_cache (this_frame, this_prologue_cache);
CORE_ADDR base;
CORE_ADDR func;
struct frame_id id;
/* The FUNC is easy. */
func = get_frame_func (this_frame);
/* Hopefully the prologue analysis either correctly determined the
frame's base (which is the SP from the previous frame), or set
that base to "NULL". */
base = info->prev_sp;
if (base == 0)
return;
id = frame_id_build (base, func);
(*this_id) = id;
}
static struct value *
avr_frame_prev_register (struct frame_info *this_frame,
void **this_prologue_cache, int regnum)
{
struct avr_unwind_cache *info
= avr_frame_unwind_cache (this_frame, this_prologue_cache);
if (regnum == AVR_PC_REGNUM || regnum == AVR_PSEUDO_PC_REGNUM)
{
if (trad_frame_addr_p (info->saved_regs, AVR_PC_REGNUM))
{
/* Reading the return PC from the PC register is slightly
abnormal. register_size(AVR_PC_REGNUM) says it is 4 bytes,
but in reality, only two bytes (3 in upcoming mega256) are
stored on the stack.
Also, note that the value on the stack is an addr to a word
not a byte, so we will need to multiply it by two at some
point.
And to confuse matters even more, the return address stored
on the stack is in big endian byte order, even though most
everything else about the avr is little endian. Ick! */
ULONGEST pc;
int i;
gdb_byte buf[3];
struct gdbarch *gdbarch = get_frame_arch (this_frame);
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
read_memory (info->saved_regs[AVR_PC_REGNUM].addr,
buf, tdep->call_length);
/* Extract the PC read from memory as a big-endian. */
pc = 0;
for (i = 0; i < tdep->call_length; i++)
pc = (pc << 8) | buf[i];
if (regnum == AVR_PC_REGNUM)
pc <<= 1;
return frame_unwind_got_constant (this_frame, regnum, pc);
}
return frame_unwind_got_optimized (this_frame, regnum);
}
return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
}
static const struct frame_unwind avr_frame_unwind = {
NORMAL_FRAME,
default_frame_unwind_stop_reason,
avr_frame_this_id,
avr_frame_prev_register,
NULL,
default_frame_sniffer
};
static CORE_ADDR
avr_frame_base_address (struct frame_info *this_frame, void **this_cache)
{
struct avr_unwind_cache *info
= avr_frame_unwind_cache (this_frame, this_cache);
return info->base;
}
static const struct frame_base avr_frame_base = {
&avr_frame_unwind,
avr_frame_base_address,
avr_frame_base_address,
avr_frame_base_address
};
/* Assuming THIS_FRAME is a dummy, return the frame ID of that dummy
frame. The frame ID's base needs to match the TOS value saved by
save_dummy_frame_tos(), and the PC match the dummy frame's breakpoint. */
static struct frame_id
avr_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
{
ULONGEST base;
base = get_frame_register_unsigned (this_frame, AVR_SP_REGNUM);
return frame_id_build (avr_make_saddr (base), get_frame_pc (this_frame));
}
/* When arguments must be pushed onto the stack, they go on in reverse
order. The below implements a FILO (stack) to do this. */
struct stack_item
{
int len;
struct stack_item *prev;
gdb_byte *data;
};
static struct stack_item *
push_stack_item (struct stack_item *prev, const bfd_byte *contents, int len)
{
struct stack_item *si;
si = XNEW (struct stack_item);
si->data = (gdb_byte *) xmalloc (len);
si->len = len;
si->prev = prev;
memcpy (si->data, contents, len);
return si;
}
static struct stack_item *pop_stack_item (struct stack_item *si);
static struct stack_item *
pop_stack_item (struct stack_item *si)
{
struct stack_item *dead = si;
si = si->prev;
xfree (dead->data);
xfree (dead);
return si;
}
/* Setup the function arguments for calling a function in the inferior.
On the AVR architecture, there are 18 registers (R25 to R8) which are
dedicated for passing function arguments. Up to the first 18 arguments
(depending on size) may go into these registers. The rest go on the stack.
All arguments are aligned to start in even-numbered registers (odd-sized
arguments, including char, have one free register above them). For example,
an int in arg1 and a char in arg2 would be passed as such:
arg1 -> r25:r24
arg2 -> r22
Arguments that are larger than 2 bytes will be split between two or more
registers as available, but will NOT be split between a register and the
stack. Arguments that go onto the stack are pushed last arg first (this is
similar to the d10v). */
/* NOTE: TRoth/2003-06-17: The rest of this comment is old looks to be
inaccurate.
An exceptional case exists for struct arguments (and possibly other
aggregates such as arrays) -- if the size is larger than WORDSIZE bytes but
not a multiple of WORDSIZE bytes. In this case the argument is never split
between the registers and the stack, but instead is copied in its entirety
onto the stack, AND also copied into as many registers as there is room
for. In other words, space in registers permitting, two copies of the same
argument are passed in. As far as I can tell, only the one on the stack is
used, although that may be a function of the level of compiler
optimization. I suspect this is a compiler bug. Arguments of these odd
sizes are left-justified within the word (as opposed to arguments smaller
than WORDSIZE bytes, which are right-justified).
If the function is to return an aggregate type such as a struct, the caller
must allocate space into which the callee will copy the return value. In
this case, a pointer to the return value location is passed into the callee
in register R0, which displaces one of the other arguments passed in via
registers R0 to R2. */
static CORE_ADDR
avr_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
struct regcache *regcache, CORE_ADDR bp_addr,
int nargs, struct value **args, CORE_ADDR sp,
int struct_return, CORE_ADDR struct_addr)
{
int i;
gdb_byte buf[3];
int call_length = gdbarch_tdep (gdbarch)->call_length;
CORE_ADDR return_pc = avr_convert_iaddr_to_raw (bp_addr);
int regnum = AVR_ARGN_REGNUM;
struct stack_item *si = NULL;
if (struct_return)
{
regcache_cooked_write_unsigned
(regcache, regnum--, (struct_addr >> 8) & 0xff);
regcache_cooked_write_unsigned
(regcache, regnum--, struct_addr & 0xff);
/* SP being post decremented, we need to reserve one byte so that the
return address won't overwrite the result (or vice-versa). */
if (sp == struct_addr)
sp--;
}
for (i = 0; i < nargs; i++)
{
int last_regnum;
int j;
struct value *arg = args[i];
struct type *type = check_typedef (value_type (arg));
const bfd_byte *contents = value_contents (arg);
int len = TYPE_LENGTH (type);
/* Calculate the potential last register needed.
E.g. For length 2, registers regnum and regnum-1 (say 25 and 24)
shall be used. So, last needed register will be regnum-1(24). */
last_regnum = regnum - (len + (len & 1)) + 1;
/* If there are registers available, use them. Once we start putting
stuff on the stack, all subsequent args go on stack. */
if ((si == NULL) && (last_regnum >= AVR_LAST_ARG_REGNUM))
{
/* Skip a register for odd length args. */
if (len & 1)
regnum--;
/* Write MSB of argument into register and subsequent bytes in
decreasing register numbers. */
for (j = 0; j < len; j++)
regcache_cooked_write_unsigned
(regcache, regnum--, contents[len - j - 1]);
}
/* No registers available, push the args onto the stack. */
else
{
/* From here on, we don't care about regnum. */
si = push_stack_item (si, contents, len);
}
}
/* Push args onto the stack. */
while (si)
{
sp -= si->len;
/* Add 1 to sp here to account for post decr nature of pushes. */
write_memory (sp + 1, si->data, si->len);
si = pop_stack_item (si);
}
/* Set the return address. For the avr, the return address is the BP_ADDR.
Need to push the return address onto the stack noting that it needs to be
in big-endian order on the stack. */
for (i = 1; i <= call_length; i++)
{
buf[call_length - i] = return_pc & 0xff;
return_pc >>= 8;
}
sp -= call_length;
/* Use 'sp + 1' since pushes are post decr ops. */
write_memory (sp + 1, buf, call_length);
/* Finally, update the SP register. */
regcache_cooked_write_unsigned (regcache, AVR_SP_REGNUM,
avr_convert_saddr_to_raw (sp));
/* Return SP value for the dummy frame, where the return address hasn't been
pushed. */
return sp + call_length;
}
/* Unfortunately dwarf2 register for SP is 32. */
static int
avr_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
{
if (reg >= 0 && reg < 32)
return reg;
if (reg == 32)
return AVR_SP_REGNUM;
return -1;
}
/* Implementation of `address_class_type_flags' gdbarch method.
This method maps DW_AT_address_class attributes to a
type_instance_flag_value. */
static int
avr_address_class_type_flags (int byte_size, int dwarf2_addr_class)
{
/* The value 1 of the DW_AT_address_class attribute corresponds to the
__flash qualifier. Note that this attribute is only valid with
pointer types and therefore the flag is set to the pointer type and
not its target type. */
if (dwarf2_addr_class == 1 && byte_size == 2)
return AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH;
return 0;
}
/* Implementation of `address_class_type_flags_to_name' gdbarch method.
Convert a type_instance_flag_value to an address space qualifier. */
static const char*
avr_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
{
if (type_flags & AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH)
return "flash";
else
return NULL;
}
/* Implementation of `address_class_name_to_type_flags' gdbarch method.
Convert an address space qualifier to a type_instance_flag_value. */
static int
avr_address_class_name_to_type_flags (struct gdbarch *gdbarch,
const char* name,
int *type_flags_ptr)
{
if (strcmp (name, "flash") == 0)
{
*type_flags_ptr = AVR_TYPE_INSTANCE_FLAG_ADDRESS_CLASS_FLASH;
return 1;
}
else
return 0;
}
/* Initialize the gdbarch structure for the AVR's. */
static struct gdbarch *
avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
{
struct gdbarch *gdbarch;
struct gdbarch_tdep *tdep;
struct gdbarch_list *best_arch;
int call_length;
/* Avr-6 call instructions save 3 bytes. */
switch (info.bfd_arch_info->mach)
{
case bfd_mach_avr1:
case bfd_mach_avrxmega1:
case bfd_mach_avr2:
case bfd_mach_avrxmega2:
case bfd_mach_avr3:
case bfd_mach_avrxmega3:
case bfd_mach_avr4:
case bfd_mach_avrxmega4:
case bfd_mach_avr5:
case bfd_mach_avrxmega5:
default:
call_length = 2;
break;
case bfd_mach_avr6:
case bfd_mach_avrxmega6:
case bfd_mach_avrxmega7:
call_length = 3;
break;
}
/* If there is already a candidate, use it. */
for (best_arch = gdbarch_list_lookup_by_info (arches, &info);
best_arch != NULL;
best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
{
if (gdbarch_tdep (best_arch->gdbarch)->call_length == call_length)
return best_arch->gdbarch;
}
/* None found, create a new architecture from the information provided. */
tdep = XNEW (struct gdbarch_tdep);
gdbarch = gdbarch_alloc (&info, tdep);
tdep->call_length = call_length;
/* Create a type for PC. We can't use builtin types here, as they may not
be defined. */
tdep->void_type = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
tdep->func_void_type = make_function_type (tdep->void_type, NULL);
tdep->pc_type = arch_pointer_type (gdbarch, 4 * TARGET_CHAR_BIT, NULL,
tdep->func_void_type);
set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
set_gdbarch_int_bit (gdbarch, 2 * TARGET_CHAR_BIT);
set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT);
set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
set_gdbarch_addr_bit (gdbarch, 32);
set_gdbarch_wchar_bit (gdbarch, 2 * TARGET_CHAR_BIT);
set_gdbarch_wchar_signed (gdbarch, 1);
set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
set_gdbarch_long_double_bit (gdbarch, 4 * TARGET_CHAR_BIT);
set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
set_gdbarch_double_format (gdbarch, floatformats_ieee_single);
set_gdbarch_long_double_format (gdbarch, floatformats_ieee_single);
set_gdbarch_read_pc (gdbarch, avr_read_pc);
set_gdbarch_write_pc (gdbarch, avr_write_pc);
set_gdbarch_num_regs (gdbarch, AVR_NUM_REGS);
set_gdbarch_sp_regnum (gdbarch, AVR_SP_REGNUM);
set_gdbarch_pc_regnum (gdbarch, AVR_PC_REGNUM);
set_gdbarch_register_name (gdbarch, avr_register_name);
set_gdbarch_register_type (gdbarch, avr_register_type);
set_gdbarch_num_pseudo_regs (gdbarch, AVR_NUM_PSEUDO_REGS);
set_gdbarch_pseudo_register_read (gdbarch, avr_pseudo_register_read);
set_gdbarch_pseudo_register_write (gdbarch, avr_pseudo_register_write);
set_gdbarch_return_value (gdbarch, avr_return_value);
set_gdbarch_print_insn (gdbarch, print_insn_avr);
set_gdbarch_push_dummy_call (gdbarch, avr_push_dummy_call);
set_gdbarch_dwarf2_reg_to_regnum (gdbarch, avr_dwarf_reg_to_regnum);
set_gdbarch_address_to_pointer (gdbarch, avr_address_to_pointer);
set_gdbarch_pointer_to_address (gdbarch, avr_pointer_to_address);
set_gdbarch_integer_to_address (gdbarch, avr_integer_to_address);
set_gdbarch_skip_prologue (gdbarch, avr_skip_prologue);
set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
set_gdbarch_breakpoint_kind_from_pc (gdbarch, avr_breakpoint::kind_from_pc);
set_gdbarch_sw_breakpoint_from_kind (gdbarch, avr_breakpoint::bp_from_kind);
frame_unwind_append_unwinder (gdbarch, &avr_frame_unwind);
frame_base_set_default (gdbarch, &avr_frame_base);
set_gdbarch_dummy_id (gdbarch, avr_dummy_id);
set_gdbarch_unwind_pc (gdbarch, avr_unwind_pc);
set_gdbarch_unwind_sp (gdbarch, avr_unwind_sp);
set_gdbarch_address_class_type_flags (gdbarch, avr_address_class_type_flags);
set_gdbarch_address_class_name_to_type_flags
(gdbarch, avr_address_class_name_to_type_flags);
set_gdbarch_address_class_type_flags_to_name
(gdbarch, avr_address_class_type_flags_to_name);
return gdbarch;
}
/* Send a query request to the avr remote target asking for values of the io
registers. If args parameter is not NULL, then the user has requested info
on a specific io register [This still needs implemented and is ignored for
now]. The query string should be one of these forms:
"Ravr.io_reg" -> reply is "NN" number of io registers
"Ravr.io_reg:addr,len" where addr is first register and len is number of
registers to be read. The reply should be "<NAME>,VV;" for each io register
where, <NAME> is a string, and VV is the hex value of the register.
All io registers are 8-bit. */
static void
avr_io_reg_read_command (char *args, int from_tty)
{
LONGEST bufsiz = 0;
gdb_byte *buf;
const char *bufstr;
char query[400];
const char *p;
unsigned int nreg = 0;
unsigned int val;
int i, j, k, step;
/* Find out how many io registers the target has. */
bufsiz = target_read_alloc (¤t_target, TARGET_OBJECT_AVR,
"avr.io_reg", &buf);
bufstr = (const char *) buf;
if (bufsiz <= 0)
{
fprintf_unfiltered (gdb_stderr,
_("ERR: info io_registers NOT supported "
"by current target\n"));
return;
}
if (sscanf (bufstr, "%x", &nreg) != 1)
{
fprintf_unfiltered (gdb_stderr,
_("Error fetching number of io registers\n"));
xfree (buf);
return;
}
xfree (buf);
reinitialize_more_filter ();
printf_unfiltered (_("Target has %u io registers:\n\n"), nreg);
/* only fetch up to 8 registers at a time to keep the buffer small */
step = 8;
for (i = 0; i < nreg; i += step)
{
/* how many registers this round? */
j = step;
if ((i+j) >= nreg)
j = nreg - i; /* last block is less than 8 registers */
snprintf (query, sizeof (query) - 1, "avr.io_reg:%x,%x", i, j);
bufsiz = target_read_alloc (¤t_target, TARGET_OBJECT_AVR,
query, &buf);
p = (const char *) buf;
for (k = i; k < (i + j); k++)
{
if (sscanf (p, "%[^,],%x;", query, &val) == 2)
{
printf_filtered ("[%02x] %-15s : %02x\n", k, query, val);
while ((*p != ';') && (*p != '\0'))
p++;
p++; /* skip over ';' */
if (*p == '\0')
break;
}
}
xfree (buf);
}
}
extern initialize_file_ftype _initialize_avr_tdep; /* -Wmissing-prototypes */
void
_initialize_avr_tdep (void)
{
register_gdbarch_init (bfd_arch_avr, avr_gdbarch_init);
/* Add a new command to allow the user to query the avr remote target for
the values of the io space registers in a saner way than just using
`x/NNNb ADDR`. */
/* FIXME: TRoth/2002-02-18: This should probably be changed to 'info avr
io_registers' to signify it is not available on other platforms. */
add_info ("io_registers", avr_io_reg_read_command,
_("query remote avr target for io space register values"));
}
| gpl-2.0 |
unusual-thoughts/linux-xps13 | drivers/pinctrl/bcm/pinctrl-bcm281xx.c | 2 | 48429 | /*
* Copyright (C) 2013 Broadcom Corporation
*
* 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 version 2.
*
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
* kind, whether express or implied; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/err.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pinctrl/pinctrl.h>
#include <linux/pinctrl/pinmux.h>
#include <linux/pinctrl/pinconf.h>
#include <linux/pinctrl/pinconf-generic.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include "../core.h"
#include "../pinctrl-utils.h"
/* BCM281XX Pin Control Registers Definitions */
/* Function Select bits are the same for all pin control registers */
#define BCM281XX_PIN_REG_F_SEL_MASK 0x0700
#define BCM281XX_PIN_REG_F_SEL_SHIFT 8
/* Standard pin register */
#define BCM281XX_STD_PIN_REG_DRV_STR_MASK 0x0007
#define BCM281XX_STD_PIN_REG_DRV_STR_SHIFT 0
#define BCM281XX_STD_PIN_REG_INPUT_DIS_MASK 0x0008
#define BCM281XX_STD_PIN_REG_INPUT_DIS_SHIFT 3
#define BCM281XX_STD_PIN_REG_SLEW_MASK 0x0010
#define BCM281XX_STD_PIN_REG_SLEW_SHIFT 4
#define BCM281XX_STD_PIN_REG_PULL_UP_MASK 0x0020
#define BCM281XX_STD_PIN_REG_PULL_UP_SHIFT 5
#define BCM281XX_STD_PIN_REG_PULL_DN_MASK 0x0040
#define BCM281XX_STD_PIN_REG_PULL_DN_SHIFT 6
#define BCM281XX_STD_PIN_REG_HYST_MASK 0x0080
#define BCM281XX_STD_PIN_REG_HYST_SHIFT 7
/* I2C pin register */
#define BCM281XX_I2C_PIN_REG_INPUT_DIS_MASK 0x0004
#define BCM281XX_I2C_PIN_REG_INPUT_DIS_SHIFT 2
#define BCM281XX_I2C_PIN_REG_SLEW_MASK 0x0008
#define BCM281XX_I2C_PIN_REG_SLEW_SHIFT 3
#define BCM281XX_I2C_PIN_REG_PULL_UP_STR_MASK 0x0070
#define BCM281XX_I2C_PIN_REG_PULL_UP_STR_SHIFT 4
/* HDMI pin register */
#define BCM281XX_HDMI_PIN_REG_INPUT_DIS_MASK 0x0008
#define BCM281XX_HDMI_PIN_REG_INPUT_DIS_SHIFT 3
#define BCM281XX_HDMI_PIN_REG_MODE_MASK 0x0010
#define BCM281XX_HDMI_PIN_REG_MODE_SHIFT 4
/**
* bcm281xx_pin_type - types of pin register
*/
enum bcm281xx_pin_type {
BCM281XX_PIN_TYPE_UNKNOWN = 0,
BCM281XX_PIN_TYPE_STD,
BCM281XX_PIN_TYPE_I2C,
BCM281XX_PIN_TYPE_HDMI,
};
static enum bcm281xx_pin_type std_pin = BCM281XX_PIN_TYPE_STD;
static enum bcm281xx_pin_type i2c_pin = BCM281XX_PIN_TYPE_I2C;
static enum bcm281xx_pin_type hdmi_pin = BCM281XX_PIN_TYPE_HDMI;
/**
* bcm281xx_pin_function- define pin function
*/
struct bcm281xx_pin_function {
const char *name;
const char * const *groups;
const unsigned ngroups;
};
/**
* bcm281xx_pinctrl_data - Broadcom-specific pinctrl data
* @reg_base - base of pinctrl registers
*/
struct bcm281xx_pinctrl_data {
void __iomem *reg_base;
/* List of all pins */
const struct pinctrl_pin_desc *pins;
const unsigned npins;
const struct bcm281xx_pin_function *functions;
const unsigned nfunctions;
struct regmap *regmap;
};
/*
* Pin number definition. The order here must be the same as defined in the
* PADCTRLREG block in the RDB.
*/
#define BCM281XX_PIN_ADCSYNC 0
#define BCM281XX_PIN_BAT_RM 1
#define BCM281XX_PIN_BSC1_SCL 2
#define BCM281XX_PIN_BSC1_SDA 3
#define BCM281XX_PIN_BSC2_SCL 4
#define BCM281XX_PIN_BSC2_SDA 5
#define BCM281XX_PIN_CLASSGPWR 6
#define BCM281XX_PIN_CLK_CX8 7
#define BCM281XX_PIN_CLKOUT_0 8
#define BCM281XX_PIN_CLKOUT_1 9
#define BCM281XX_PIN_CLKOUT_2 10
#define BCM281XX_PIN_CLKOUT_3 11
#define BCM281XX_PIN_CLKREQ_IN_0 12
#define BCM281XX_PIN_CLKREQ_IN_1 13
#define BCM281XX_PIN_CWS_SYS_REQ1 14
#define BCM281XX_PIN_CWS_SYS_REQ2 15
#define BCM281XX_PIN_CWS_SYS_REQ3 16
#define BCM281XX_PIN_DIGMIC1_CLK 17
#define BCM281XX_PIN_DIGMIC1_DQ 18
#define BCM281XX_PIN_DIGMIC2_CLK 19
#define BCM281XX_PIN_DIGMIC2_DQ 20
#define BCM281XX_PIN_GPEN13 21
#define BCM281XX_PIN_GPEN14 22
#define BCM281XX_PIN_GPEN15 23
#define BCM281XX_PIN_GPIO00 24
#define BCM281XX_PIN_GPIO01 25
#define BCM281XX_PIN_GPIO02 26
#define BCM281XX_PIN_GPIO03 27
#define BCM281XX_PIN_GPIO04 28
#define BCM281XX_PIN_GPIO05 29
#define BCM281XX_PIN_GPIO06 30
#define BCM281XX_PIN_GPIO07 31
#define BCM281XX_PIN_GPIO08 32
#define BCM281XX_PIN_GPIO09 33
#define BCM281XX_PIN_GPIO10 34
#define BCM281XX_PIN_GPIO11 35
#define BCM281XX_PIN_GPIO12 36
#define BCM281XX_PIN_GPIO13 37
#define BCM281XX_PIN_GPIO14 38
#define BCM281XX_PIN_GPS_PABLANK 39
#define BCM281XX_PIN_GPS_TMARK 40
#define BCM281XX_PIN_HDMI_SCL 41
#define BCM281XX_PIN_HDMI_SDA 42
#define BCM281XX_PIN_IC_DM 43
#define BCM281XX_PIN_IC_DP 44
#define BCM281XX_PIN_KP_COL_IP_0 45
#define BCM281XX_PIN_KP_COL_IP_1 46
#define BCM281XX_PIN_KP_COL_IP_2 47
#define BCM281XX_PIN_KP_COL_IP_3 48
#define BCM281XX_PIN_KP_ROW_OP_0 49
#define BCM281XX_PIN_KP_ROW_OP_1 50
#define BCM281XX_PIN_KP_ROW_OP_2 51
#define BCM281XX_PIN_KP_ROW_OP_3 52
#define BCM281XX_PIN_LCD_B_0 53
#define BCM281XX_PIN_LCD_B_1 54
#define BCM281XX_PIN_LCD_B_2 55
#define BCM281XX_PIN_LCD_B_3 56
#define BCM281XX_PIN_LCD_B_4 57
#define BCM281XX_PIN_LCD_B_5 58
#define BCM281XX_PIN_LCD_B_6 59
#define BCM281XX_PIN_LCD_B_7 60
#define BCM281XX_PIN_LCD_G_0 61
#define BCM281XX_PIN_LCD_G_1 62
#define BCM281XX_PIN_LCD_G_2 63
#define BCM281XX_PIN_LCD_G_3 64
#define BCM281XX_PIN_LCD_G_4 65
#define BCM281XX_PIN_LCD_G_5 66
#define BCM281XX_PIN_LCD_G_6 67
#define BCM281XX_PIN_LCD_G_7 68
#define BCM281XX_PIN_LCD_HSYNC 69
#define BCM281XX_PIN_LCD_OE 70
#define BCM281XX_PIN_LCD_PCLK 71
#define BCM281XX_PIN_LCD_R_0 72
#define BCM281XX_PIN_LCD_R_1 73
#define BCM281XX_PIN_LCD_R_2 74
#define BCM281XX_PIN_LCD_R_3 75
#define BCM281XX_PIN_LCD_R_4 76
#define BCM281XX_PIN_LCD_R_5 77
#define BCM281XX_PIN_LCD_R_6 78
#define BCM281XX_PIN_LCD_R_7 79
#define BCM281XX_PIN_LCD_VSYNC 80
#define BCM281XX_PIN_MDMGPIO0 81
#define BCM281XX_PIN_MDMGPIO1 82
#define BCM281XX_PIN_MDMGPIO2 83
#define BCM281XX_PIN_MDMGPIO3 84
#define BCM281XX_PIN_MDMGPIO4 85
#define BCM281XX_PIN_MDMGPIO5 86
#define BCM281XX_PIN_MDMGPIO6 87
#define BCM281XX_PIN_MDMGPIO7 88
#define BCM281XX_PIN_MDMGPIO8 89
#define BCM281XX_PIN_MPHI_DATA_0 90
#define BCM281XX_PIN_MPHI_DATA_1 91
#define BCM281XX_PIN_MPHI_DATA_2 92
#define BCM281XX_PIN_MPHI_DATA_3 93
#define BCM281XX_PIN_MPHI_DATA_4 94
#define BCM281XX_PIN_MPHI_DATA_5 95
#define BCM281XX_PIN_MPHI_DATA_6 96
#define BCM281XX_PIN_MPHI_DATA_7 97
#define BCM281XX_PIN_MPHI_DATA_8 98
#define BCM281XX_PIN_MPHI_DATA_9 99
#define BCM281XX_PIN_MPHI_DATA_10 100
#define BCM281XX_PIN_MPHI_DATA_11 101
#define BCM281XX_PIN_MPHI_DATA_12 102
#define BCM281XX_PIN_MPHI_DATA_13 103
#define BCM281XX_PIN_MPHI_DATA_14 104
#define BCM281XX_PIN_MPHI_DATA_15 105
#define BCM281XX_PIN_MPHI_HA0 106
#define BCM281XX_PIN_MPHI_HAT0 107
#define BCM281XX_PIN_MPHI_HAT1 108
#define BCM281XX_PIN_MPHI_HCE0_N 109
#define BCM281XX_PIN_MPHI_HCE1_N 110
#define BCM281XX_PIN_MPHI_HRD_N 111
#define BCM281XX_PIN_MPHI_HWR_N 112
#define BCM281XX_PIN_MPHI_RUN0 113
#define BCM281XX_PIN_MPHI_RUN1 114
#define BCM281XX_PIN_MTX_SCAN_CLK 115
#define BCM281XX_PIN_MTX_SCAN_DATA 116
#define BCM281XX_PIN_NAND_AD_0 117
#define BCM281XX_PIN_NAND_AD_1 118
#define BCM281XX_PIN_NAND_AD_2 119
#define BCM281XX_PIN_NAND_AD_3 120
#define BCM281XX_PIN_NAND_AD_4 121
#define BCM281XX_PIN_NAND_AD_5 122
#define BCM281XX_PIN_NAND_AD_6 123
#define BCM281XX_PIN_NAND_AD_7 124
#define BCM281XX_PIN_NAND_ALE 125
#define BCM281XX_PIN_NAND_CEN_0 126
#define BCM281XX_PIN_NAND_CEN_1 127
#define BCM281XX_PIN_NAND_CLE 128
#define BCM281XX_PIN_NAND_OEN 129
#define BCM281XX_PIN_NAND_RDY_0 130
#define BCM281XX_PIN_NAND_RDY_1 131
#define BCM281XX_PIN_NAND_WEN 132
#define BCM281XX_PIN_NAND_WP 133
#define BCM281XX_PIN_PC1 134
#define BCM281XX_PIN_PC2 135
#define BCM281XX_PIN_PMU_INT 136
#define BCM281XX_PIN_PMU_SCL 137
#define BCM281XX_PIN_PMU_SDA 138
#define BCM281XX_PIN_RFST2G_MTSLOTEN3G 139
#define BCM281XX_PIN_RGMII_0_RX_CTL 140
#define BCM281XX_PIN_RGMII_0_RXC 141
#define BCM281XX_PIN_RGMII_0_RXD_0 142
#define BCM281XX_PIN_RGMII_0_RXD_1 143
#define BCM281XX_PIN_RGMII_0_RXD_2 144
#define BCM281XX_PIN_RGMII_0_RXD_3 145
#define BCM281XX_PIN_RGMII_0_TX_CTL 146
#define BCM281XX_PIN_RGMII_0_TXC 147
#define BCM281XX_PIN_RGMII_0_TXD_0 148
#define BCM281XX_PIN_RGMII_0_TXD_1 149
#define BCM281XX_PIN_RGMII_0_TXD_2 150
#define BCM281XX_PIN_RGMII_0_TXD_3 151
#define BCM281XX_PIN_RGMII_1_RX_CTL 152
#define BCM281XX_PIN_RGMII_1_RXC 153
#define BCM281XX_PIN_RGMII_1_RXD_0 154
#define BCM281XX_PIN_RGMII_1_RXD_1 155
#define BCM281XX_PIN_RGMII_1_RXD_2 156
#define BCM281XX_PIN_RGMII_1_RXD_3 157
#define BCM281XX_PIN_RGMII_1_TX_CTL 158
#define BCM281XX_PIN_RGMII_1_TXC 159
#define BCM281XX_PIN_RGMII_1_TXD_0 160
#define BCM281XX_PIN_RGMII_1_TXD_1 161
#define BCM281XX_PIN_RGMII_1_TXD_2 162
#define BCM281XX_PIN_RGMII_1_TXD_3 163
#define BCM281XX_PIN_RGMII_GPIO_0 164
#define BCM281XX_PIN_RGMII_GPIO_1 165
#define BCM281XX_PIN_RGMII_GPIO_2 166
#define BCM281XX_PIN_RGMII_GPIO_3 167
#define BCM281XX_PIN_RTXDATA2G_TXDATA3G1 168
#define BCM281XX_PIN_RTXEN2G_TXDATA3G2 169
#define BCM281XX_PIN_RXDATA3G0 170
#define BCM281XX_PIN_RXDATA3G1 171
#define BCM281XX_PIN_RXDATA3G2 172
#define BCM281XX_PIN_SDIO1_CLK 173
#define BCM281XX_PIN_SDIO1_CMD 174
#define BCM281XX_PIN_SDIO1_DATA_0 175
#define BCM281XX_PIN_SDIO1_DATA_1 176
#define BCM281XX_PIN_SDIO1_DATA_2 177
#define BCM281XX_PIN_SDIO1_DATA_3 178
#define BCM281XX_PIN_SDIO4_CLK 179
#define BCM281XX_PIN_SDIO4_CMD 180
#define BCM281XX_PIN_SDIO4_DATA_0 181
#define BCM281XX_PIN_SDIO4_DATA_1 182
#define BCM281XX_PIN_SDIO4_DATA_2 183
#define BCM281XX_PIN_SDIO4_DATA_3 184
#define BCM281XX_PIN_SIM_CLK 185
#define BCM281XX_PIN_SIM_DATA 186
#define BCM281XX_PIN_SIM_DET 187
#define BCM281XX_PIN_SIM_RESETN 188
#define BCM281XX_PIN_SIM2_CLK 189
#define BCM281XX_PIN_SIM2_DATA 190
#define BCM281XX_PIN_SIM2_DET 191
#define BCM281XX_PIN_SIM2_RESETN 192
#define BCM281XX_PIN_SRI_C 193
#define BCM281XX_PIN_SRI_D 194
#define BCM281XX_PIN_SRI_E 195
#define BCM281XX_PIN_SSP_EXTCLK 196
#define BCM281XX_PIN_SSP0_CLK 197
#define BCM281XX_PIN_SSP0_FS 198
#define BCM281XX_PIN_SSP0_RXD 199
#define BCM281XX_PIN_SSP0_TXD 200
#define BCM281XX_PIN_SSP2_CLK 201
#define BCM281XX_PIN_SSP2_FS_0 202
#define BCM281XX_PIN_SSP2_FS_1 203
#define BCM281XX_PIN_SSP2_FS_2 204
#define BCM281XX_PIN_SSP2_FS_3 205
#define BCM281XX_PIN_SSP2_RXD_0 206
#define BCM281XX_PIN_SSP2_RXD_1 207
#define BCM281XX_PIN_SSP2_TXD_0 208
#define BCM281XX_PIN_SSP2_TXD_1 209
#define BCM281XX_PIN_SSP3_CLK 210
#define BCM281XX_PIN_SSP3_FS 211
#define BCM281XX_PIN_SSP3_RXD 212
#define BCM281XX_PIN_SSP3_TXD 213
#define BCM281XX_PIN_SSP4_CLK 214
#define BCM281XX_PIN_SSP4_FS 215
#define BCM281XX_PIN_SSP4_RXD 216
#define BCM281XX_PIN_SSP4_TXD 217
#define BCM281XX_PIN_SSP5_CLK 218
#define BCM281XX_PIN_SSP5_FS 219
#define BCM281XX_PIN_SSP5_RXD 220
#define BCM281XX_PIN_SSP5_TXD 221
#define BCM281XX_PIN_SSP6_CLK 222
#define BCM281XX_PIN_SSP6_FS 223
#define BCM281XX_PIN_SSP6_RXD 224
#define BCM281XX_PIN_SSP6_TXD 225
#define BCM281XX_PIN_STAT_1 226
#define BCM281XX_PIN_STAT_2 227
#define BCM281XX_PIN_SYSCLKEN 228
#define BCM281XX_PIN_TRACECLK 229
#define BCM281XX_PIN_TRACEDT00 230
#define BCM281XX_PIN_TRACEDT01 231
#define BCM281XX_PIN_TRACEDT02 232
#define BCM281XX_PIN_TRACEDT03 233
#define BCM281XX_PIN_TRACEDT04 234
#define BCM281XX_PIN_TRACEDT05 235
#define BCM281XX_PIN_TRACEDT06 236
#define BCM281XX_PIN_TRACEDT07 237
#define BCM281XX_PIN_TRACEDT08 238
#define BCM281XX_PIN_TRACEDT09 239
#define BCM281XX_PIN_TRACEDT10 240
#define BCM281XX_PIN_TRACEDT11 241
#define BCM281XX_PIN_TRACEDT12 242
#define BCM281XX_PIN_TRACEDT13 243
#define BCM281XX_PIN_TRACEDT14 244
#define BCM281XX_PIN_TRACEDT15 245
#define BCM281XX_PIN_TXDATA3G0 246
#define BCM281XX_PIN_TXPWRIND 247
#define BCM281XX_PIN_UARTB1_UCTS 248
#define BCM281XX_PIN_UARTB1_URTS 249
#define BCM281XX_PIN_UARTB1_URXD 250
#define BCM281XX_PIN_UARTB1_UTXD 251
#define BCM281XX_PIN_UARTB2_URXD 252
#define BCM281XX_PIN_UARTB2_UTXD 253
#define BCM281XX_PIN_UARTB3_UCTS 254
#define BCM281XX_PIN_UARTB3_URTS 255
#define BCM281XX_PIN_UARTB3_URXD 256
#define BCM281XX_PIN_UARTB3_UTXD 257
#define BCM281XX_PIN_UARTB4_UCTS 258
#define BCM281XX_PIN_UARTB4_URTS 259
#define BCM281XX_PIN_UARTB4_URXD 260
#define BCM281XX_PIN_UARTB4_UTXD 261
#define BCM281XX_PIN_VC_CAM1_SCL 262
#define BCM281XX_PIN_VC_CAM1_SDA 263
#define BCM281XX_PIN_VC_CAM2_SCL 264
#define BCM281XX_PIN_VC_CAM2_SDA 265
#define BCM281XX_PIN_VC_CAM3_SCL 266
#define BCM281XX_PIN_VC_CAM3_SDA 267
#define BCM281XX_PIN_DESC(a, b, c) \
{ .number = a, .name = b, .drv_data = &c##_pin }
/*
* Pin description definition. The order here must be the same as defined in
* the PADCTRLREG block in the RDB, since the pin number is used as an index
* into this array.
*/
static const struct pinctrl_pin_desc bcm281xx_pinctrl_pins[] = {
BCM281XX_PIN_DESC(BCM281XX_PIN_ADCSYNC, "adcsync", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_BAT_RM, "bat_rm", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_BSC1_SCL, "bsc1_scl", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_BSC1_SDA, "bsc1_sda", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_BSC2_SCL, "bsc2_scl", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_BSC2_SDA, "bsc2_sda", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_CLASSGPWR, "classgpwr", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CLK_CX8, "clk_cx8", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CLKOUT_0, "clkout_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CLKOUT_1, "clkout_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CLKOUT_2, "clkout_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CLKOUT_3, "clkout_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CLKREQ_IN_0, "clkreq_in_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CLKREQ_IN_1, "clkreq_in_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CWS_SYS_REQ1, "cws_sys_req1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CWS_SYS_REQ2, "cws_sys_req2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_CWS_SYS_REQ3, "cws_sys_req3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_DIGMIC1_CLK, "digmic1_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_DIGMIC1_DQ, "digmic1_dq", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_DIGMIC2_CLK, "digmic2_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_DIGMIC2_DQ, "digmic2_dq", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPEN13, "gpen13", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPEN14, "gpen14", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPEN15, "gpen15", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO00, "gpio00", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO01, "gpio01", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO02, "gpio02", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO03, "gpio03", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO04, "gpio04", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO05, "gpio05", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO06, "gpio06", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO07, "gpio07", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO08, "gpio08", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO09, "gpio09", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO10, "gpio10", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO11, "gpio11", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO12, "gpio12", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO13, "gpio13", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPIO14, "gpio14", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPS_PABLANK, "gps_pablank", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_GPS_TMARK, "gps_tmark", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_HDMI_SCL, "hdmi_scl", hdmi),
BCM281XX_PIN_DESC(BCM281XX_PIN_HDMI_SDA, "hdmi_sda", hdmi),
BCM281XX_PIN_DESC(BCM281XX_PIN_IC_DM, "ic_dm", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_IC_DP, "ic_dp", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_KP_COL_IP_0, "kp_col_ip_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_KP_COL_IP_1, "kp_col_ip_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_KP_COL_IP_2, "kp_col_ip_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_KP_COL_IP_3, "kp_col_ip_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_KP_ROW_OP_0, "kp_row_op_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_KP_ROW_OP_1, "kp_row_op_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_KP_ROW_OP_2, "kp_row_op_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_KP_ROW_OP_3, "kp_row_op_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_B_0, "lcd_b_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_B_1, "lcd_b_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_B_2, "lcd_b_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_B_3, "lcd_b_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_B_4, "lcd_b_4", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_B_5, "lcd_b_5", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_B_6, "lcd_b_6", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_B_7, "lcd_b_7", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_G_0, "lcd_g_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_G_1, "lcd_g_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_G_2, "lcd_g_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_G_3, "lcd_g_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_G_4, "lcd_g_4", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_G_5, "lcd_g_5", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_G_6, "lcd_g_6", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_G_7, "lcd_g_7", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_HSYNC, "lcd_hsync", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_OE, "lcd_oe", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_PCLK, "lcd_pclk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_R_0, "lcd_r_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_R_1, "lcd_r_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_R_2, "lcd_r_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_R_3, "lcd_r_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_R_4, "lcd_r_4", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_R_5, "lcd_r_5", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_R_6, "lcd_r_6", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_R_7, "lcd_r_7", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_LCD_VSYNC, "lcd_vsync", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MDMGPIO0, "mdmgpio0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MDMGPIO1, "mdmgpio1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MDMGPIO2, "mdmgpio2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MDMGPIO3, "mdmgpio3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MDMGPIO4, "mdmgpio4", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MDMGPIO5, "mdmgpio5", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MDMGPIO6, "mdmgpio6", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MDMGPIO7, "mdmgpio7", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MDMGPIO8, "mdmgpio8", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_0, "mphi_data_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_1, "mphi_data_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_2, "mphi_data_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_3, "mphi_data_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_4, "mphi_data_4", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_5, "mphi_data_5", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_6, "mphi_data_6", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_7, "mphi_data_7", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_8, "mphi_data_8", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_9, "mphi_data_9", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_10, "mphi_data_10", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_11, "mphi_data_11", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_12, "mphi_data_12", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_13, "mphi_data_13", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_14, "mphi_data_14", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_DATA_15, "mphi_data_15", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_HA0, "mphi_ha0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_HAT0, "mphi_hat0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_HAT1, "mphi_hat1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_HCE0_N, "mphi_hce0_n", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_HCE1_N, "mphi_hce1_n", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_HRD_N, "mphi_hrd_n", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_HWR_N, "mphi_hwr_n", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_RUN0, "mphi_run0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MPHI_RUN1, "mphi_run1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MTX_SCAN_CLK, "mtx_scan_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_MTX_SCAN_DATA, "mtx_scan_data", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_AD_0, "nand_ad_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_AD_1, "nand_ad_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_AD_2, "nand_ad_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_AD_3, "nand_ad_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_AD_4, "nand_ad_4", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_AD_5, "nand_ad_5", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_AD_6, "nand_ad_6", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_AD_7, "nand_ad_7", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_ALE, "nand_ale", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_CEN_0, "nand_cen_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_CEN_1, "nand_cen_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_CLE, "nand_cle", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_OEN, "nand_oen", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_RDY_0, "nand_rdy_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_RDY_1, "nand_rdy_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_WEN, "nand_wen", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_NAND_WP, "nand_wp", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_PC1, "pc1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_PC2, "pc2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_PMU_INT, "pmu_int", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_PMU_SCL, "pmu_scl", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_PMU_SDA, "pmu_sda", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_RFST2G_MTSLOTEN3G, "rfst2g_mtsloten3g",
std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_RX_CTL, "rgmii_0_rx_ctl", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_RXC, "rgmii_0_rxc", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_RXD_0, "rgmii_0_rxd_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_RXD_1, "rgmii_0_rxd_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_RXD_2, "rgmii_0_rxd_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_RXD_3, "rgmii_0_rxd_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_TX_CTL, "rgmii_0_tx_ctl", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_TXC, "rgmii_0_txc", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_TXD_0, "rgmii_0_txd_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_TXD_1, "rgmii_0_txd_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_TXD_2, "rgmii_0_txd_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_0_TXD_3, "rgmii_0_txd_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_RX_CTL, "rgmii_1_rx_ctl", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_RXC, "rgmii_1_rxc", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_RXD_0, "rgmii_1_rxd_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_RXD_1, "rgmii_1_rxd_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_RXD_2, "rgmii_1_rxd_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_RXD_3, "rgmii_1_rxd_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_TX_CTL, "rgmii_1_tx_ctl", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_TXC, "rgmii_1_txc", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_TXD_0, "rgmii_1_txd_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_TXD_1, "rgmii_1_txd_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_TXD_2, "rgmii_1_txd_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_1_TXD_3, "rgmii_1_txd_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_GPIO_0, "rgmii_gpio_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_GPIO_1, "rgmii_gpio_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_GPIO_2, "rgmii_gpio_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RGMII_GPIO_3, "rgmii_gpio_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RTXDATA2G_TXDATA3G1,
"rtxdata2g_txdata3g1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RTXEN2G_TXDATA3G2, "rtxen2g_txdata3g2",
std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RXDATA3G0, "rxdata3g0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RXDATA3G1, "rxdata3g1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_RXDATA3G2, "rxdata3g2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO1_CLK, "sdio1_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO1_CMD, "sdio1_cmd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO1_DATA_0, "sdio1_data_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO1_DATA_1, "sdio1_data_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO1_DATA_2, "sdio1_data_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO1_DATA_3, "sdio1_data_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO4_CLK, "sdio4_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO4_CMD, "sdio4_cmd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO4_DATA_0, "sdio4_data_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO4_DATA_1, "sdio4_data_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO4_DATA_2, "sdio4_data_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SDIO4_DATA_3, "sdio4_data_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SIM_CLK, "sim_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SIM_DATA, "sim_data", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SIM_DET, "sim_det", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SIM_RESETN, "sim_resetn", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SIM2_CLK, "sim2_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SIM2_DATA, "sim2_data", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SIM2_DET, "sim2_det", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SIM2_RESETN, "sim2_resetn", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SRI_C, "sri_c", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SRI_D, "sri_d", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SRI_E, "sri_e", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP_EXTCLK, "ssp_extclk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP0_CLK, "ssp0_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP0_FS, "ssp0_fs", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP0_RXD, "ssp0_rxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP0_TXD, "ssp0_txd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP2_CLK, "ssp2_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP2_FS_0, "ssp2_fs_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP2_FS_1, "ssp2_fs_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP2_FS_2, "ssp2_fs_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP2_FS_3, "ssp2_fs_3", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP2_RXD_0, "ssp2_rxd_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP2_RXD_1, "ssp2_rxd_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP2_TXD_0, "ssp2_txd_0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP2_TXD_1, "ssp2_txd_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP3_CLK, "ssp3_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP3_FS, "ssp3_fs", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP3_RXD, "ssp3_rxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP3_TXD, "ssp3_txd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP4_CLK, "ssp4_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP4_FS, "ssp4_fs", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP4_RXD, "ssp4_rxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP4_TXD, "ssp4_txd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP5_CLK, "ssp5_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP5_FS, "ssp5_fs", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP5_RXD, "ssp5_rxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP5_TXD, "ssp5_txd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP6_CLK, "ssp6_clk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP6_FS, "ssp6_fs", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP6_RXD, "ssp6_rxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SSP6_TXD, "ssp6_txd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_STAT_1, "stat_1", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_STAT_2, "stat_2", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_SYSCLKEN, "sysclken", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACECLK, "traceclk", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT00, "tracedt00", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT01, "tracedt01", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT02, "tracedt02", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT03, "tracedt03", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT04, "tracedt04", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT05, "tracedt05", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT06, "tracedt06", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT07, "tracedt07", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT08, "tracedt08", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT09, "tracedt09", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT10, "tracedt10", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT11, "tracedt11", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT12, "tracedt12", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT13, "tracedt13", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT14, "tracedt14", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TRACEDT15, "tracedt15", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TXDATA3G0, "txdata3g0", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_TXPWRIND, "txpwrind", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB1_UCTS, "uartb1_ucts", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB1_URTS, "uartb1_urts", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB1_URXD, "uartb1_urxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB1_UTXD, "uartb1_utxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB2_URXD, "uartb2_urxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB2_UTXD, "uartb2_utxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB3_UCTS, "uartb3_ucts", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB3_URTS, "uartb3_urts", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB3_URXD, "uartb3_urxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB3_UTXD, "uartb3_utxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB4_UCTS, "uartb4_ucts", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB4_URTS, "uartb4_urts", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB4_URXD, "uartb4_urxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_UARTB4_UTXD, "uartb4_utxd", std),
BCM281XX_PIN_DESC(BCM281XX_PIN_VC_CAM1_SCL, "vc_cam1_scl", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_VC_CAM1_SDA, "vc_cam1_sda", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_VC_CAM2_SCL, "vc_cam2_scl", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_VC_CAM2_SDA, "vc_cam2_sda", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_VC_CAM3_SCL, "vc_cam3_scl", i2c),
BCM281XX_PIN_DESC(BCM281XX_PIN_VC_CAM3_SDA, "vc_cam3_sda", i2c),
};
static const char * const bcm281xx_alt_groups[] = {
"adcsync",
"bat_rm",
"bsc1_scl",
"bsc1_sda",
"bsc2_scl",
"bsc2_sda",
"classgpwr",
"clk_cx8",
"clkout_0",
"clkout_1",
"clkout_2",
"clkout_3",
"clkreq_in_0",
"clkreq_in_1",
"cws_sys_req1",
"cws_sys_req2",
"cws_sys_req3",
"digmic1_clk",
"digmic1_dq",
"digmic2_clk",
"digmic2_dq",
"gpen13",
"gpen14",
"gpen15",
"gpio00",
"gpio01",
"gpio02",
"gpio03",
"gpio04",
"gpio05",
"gpio06",
"gpio07",
"gpio08",
"gpio09",
"gpio10",
"gpio11",
"gpio12",
"gpio13",
"gpio14",
"gps_pablank",
"gps_tmark",
"hdmi_scl",
"hdmi_sda",
"ic_dm",
"ic_dp",
"kp_col_ip_0",
"kp_col_ip_1",
"kp_col_ip_2",
"kp_col_ip_3",
"kp_row_op_0",
"kp_row_op_1",
"kp_row_op_2",
"kp_row_op_3",
"lcd_b_0",
"lcd_b_1",
"lcd_b_2",
"lcd_b_3",
"lcd_b_4",
"lcd_b_5",
"lcd_b_6",
"lcd_b_7",
"lcd_g_0",
"lcd_g_1",
"lcd_g_2",
"lcd_g_3",
"lcd_g_4",
"lcd_g_5",
"lcd_g_6",
"lcd_g_7",
"lcd_hsync",
"lcd_oe",
"lcd_pclk",
"lcd_r_0",
"lcd_r_1",
"lcd_r_2",
"lcd_r_3",
"lcd_r_4",
"lcd_r_5",
"lcd_r_6",
"lcd_r_7",
"lcd_vsync",
"mdmgpio0",
"mdmgpio1",
"mdmgpio2",
"mdmgpio3",
"mdmgpio4",
"mdmgpio5",
"mdmgpio6",
"mdmgpio7",
"mdmgpio8",
"mphi_data_0",
"mphi_data_1",
"mphi_data_2",
"mphi_data_3",
"mphi_data_4",
"mphi_data_5",
"mphi_data_6",
"mphi_data_7",
"mphi_data_8",
"mphi_data_9",
"mphi_data_10",
"mphi_data_11",
"mphi_data_12",
"mphi_data_13",
"mphi_data_14",
"mphi_data_15",
"mphi_ha0",
"mphi_hat0",
"mphi_hat1",
"mphi_hce0_n",
"mphi_hce1_n",
"mphi_hrd_n",
"mphi_hwr_n",
"mphi_run0",
"mphi_run1",
"mtx_scan_clk",
"mtx_scan_data",
"nand_ad_0",
"nand_ad_1",
"nand_ad_2",
"nand_ad_3",
"nand_ad_4",
"nand_ad_5",
"nand_ad_6",
"nand_ad_7",
"nand_ale",
"nand_cen_0",
"nand_cen_1",
"nand_cle",
"nand_oen",
"nand_rdy_0",
"nand_rdy_1",
"nand_wen",
"nand_wp",
"pc1",
"pc2",
"pmu_int",
"pmu_scl",
"pmu_sda",
"rfst2g_mtsloten3g",
"rgmii_0_rx_ctl",
"rgmii_0_rxc",
"rgmii_0_rxd_0",
"rgmii_0_rxd_1",
"rgmii_0_rxd_2",
"rgmii_0_rxd_3",
"rgmii_0_tx_ctl",
"rgmii_0_txc",
"rgmii_0_txd_0",
"rgmii_0_txd_1",
"rgmii_0_txd_2",
"rgmii_0_txd_3",
"rgmii_1_rx_ctl",
"rgmii_1_rxc",
"rgmii_1_rxd_0",
"rgmii_1_rxd_1",
"rgmii_1_rxd_2",
"rgmii_1_rxd_3",
"rgmii_1_tx_ctl",
"rgmii_1_txc",
"rgmii_1_txd_0",
"rgmii_1_txd_1",
"rgmii_1_txd_2",
"rgmii_1_txd_3",
"rgmii_gpio_0",
"rgmii_gpio_1",
"rgmii_gpio_2",
"rgmii_gpio_3",
"rtxdata2g_txdata3g1",
"rtxen2g_txdata3g2",
"rxdata3g0",
"rxdata3g1",
"rxdata3g2",
"sdio1_clk",
"sdio1_cmd",
"sdio1_data_0",
"sdio1_data_1",
"sdio1_data_2",
"sdio1_data_3",
"sdio4_clk",
"sdio4_cmd",
"sdio4_data_0",
"sdio4_data_1",
"sdio4_data_2",
"sdio4_data_3",
"sim_clk",
"sim_data",
"sim_det",
"sim_resetn",
"sim2_clk",
"sim2_data",
"sim2_det",
"sim2_resetn",
"sri_c",
"sri_d",
"sri_e",
"ssp_extclk",
"ssp0_clk",
"ssp0_fs",
"ssp0_rxd",
"ssp0_txd",
"ssp2_clk",
"ssp2_fs_0",
"ssp2_fs_1",
"ssp2_fs_2",
"ssp2_fs_3",
"ssp2_rxd_0",
"ssp2_rxd_1",
"ssp2_txd_0",
"ssp2_txd_1",
"ssp3_clk",
"ssp3_fs",
"ssp3_rxd",
"ssp3_txd",
"ssp4_clk",
"ssp4_fs",
"ssp4_rxd",
"ssp4_txd",
"ssp5_clk",
"ssp5_fs",
"ssp5_rxd",
"ssp5_txd",
"ssp6_clk",
"ssp6_fs",
"ssp6_rxd",
"ssp6_txd",
"stat_1",
"stat_2",
"sysclken",
"traceclk",
"tracedt00",
"tracedt01",
"tracedt02",
"tracedt03",
"tracedt04",
"tracedt05",
"tracedt06",
"tracedt07",
"tracedt08",
"tracedt09",
"tracedt10",
"tracedt11",
"tracedt12",
"tracedt13",
"tracedt14",
"tracedt15",
"txdata3g0",
"txpwrind",
"uartb1_ucts",
"uartb1_urts",
"uartb1_urxd",
"uartb1_utxd",
"uartb2_urxd",
"uartb2_utxd",
"uartb3_ucts",
"uartb3_urts",
"uartb3_urxd",
"uartb3_utxd",
"uartb4_ucts",
"uartb4_urts",
"uartb4_urxd",
"uartb4_utxd",
"vc_cam1_scl",
"vc_cam1_sda",
"vc_cam2_scl",
"vc_cam2_sda",
"vc_cam3_scl",
"vc_cam3_sda",
};
/* Every pin can implement all ALT1-ALT4 functions */
#define BCM281XX_PIN_FUNCTION(fcn_name) \
{ \
.name = #fcn_name, \
.groups = bcm281xx_alt_groups, \
.ngroups = ARRAY_SIZE(bcm281xx_alt_groups), \
}
static const struct bcm281xx_pin_function bcm281xx_functions[] = {
BCM281XX_PIN_FUNCTION(alt1),
BCM281XX_PIN_FUNCTION(alt2),
BCM281XX_PIN_FUNCTION(alt3),
BCM281XX_PIN_FUNCTION(alt4),
};
static struct bcm281xx_pinctrl_data bcm281xx_pinctrl = {
.pins = bcm281xx_pinctrl_pins,
.npins = ARRAY_SIZE(bcm281xx_pinctrl_pins),
.functions = bcm281xx_functions,
.nfunctions = ARRAY_SIZE(bcm281xx_functions),
};
static inline enum bcm281xx_pin_type pin_type_get(struct pinctrl_dev *pctldev,
unsigned pin)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
if (pin >= pdata->npins)
return BCM281XX_PIN_TYPE_UNKNOWN;
return *(enum bcm281xx_pin_type *)(pdata->pins[pin].drv_data);
}
#define BCM281XX_PIN_SHIFT(type, param) \
(BCM281XX_ ## type ## _PIN_REG_ ## param ## _SHIFT)
#define BCM281XX_PIN_MASK(type, param) \
(BCM281XX_ ## type ## _PIN_REG_ ## param ## _MASK)
/*
* This helper function is used to build up the value and mask used to write to
* a pin register, but does not actually write to the register.
*/
static inline void bcm281xx_pin_update(u32 *reg_val, u32 *reg_mask,
u32 param_val, u32 param_shift,
u32 param_mask)
{
*reg_val &= ~param_mask;
*reg_val |= (param_val << param_shift) & param_mask;
*reg_mask |= param_mask;
}
static const struct regmap_config bcm281xx_pinctrl_regmap_config = {
.reg_bits = 32,
.reg_stride = 4,
.val_bits = 32,
.max_register = BCM281XX_PIN_VC_CAM3_SDA,
};
static int bcm281xx_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
return pdata->npins;
}
static const char *bcm281xx_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
unsigned group)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
return pdata->pins[group].name;
}
static int bcm281xx_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
unsigned group,
const unsigned **pins,
unsigned *num_pins)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
*pins = &pdata->pins[group].number;
*num_pins = 1;
return 0;
}
static void bcm281xx_pinctrl_pin_dbg_show(struct pinctrl_dev *pctldev,
struct seq_file *s,
unsigned offset)
{
seq_printf(s, " %s", dev_name(pctldev->dev));
}
static struct pinctrl_ops bcm281xx_pinctrl_ops = {
.get_groups_count = bcm281xx_pinctrl_get_groups_count,
.get_group_name = bcm281xx_pinctrl_get_group_name,
.get_group_pins = bcm281xx_pinctrl_get_group_pins,
.pin_dbg_show = bcm281xx_pinctrl_pin_dbg_show,
.dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
.dt_free_map = pinctrl_utils_free_map,
};
static int bcm281xx_pinctrl_get_fcns_count(struct pinctrl_dev *pctldev)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
return pdata->nfunctions;
}
static const char *bcm281xx_pinctrl_get_fcn_name(struct pinctrl_dev *pctldev,
unsigned function)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
return pdata->functions[function].name;
}
static int bcm281xx_pinctrl_get_fcn_groups(struct pinctrl_dev *pctldev,
unsigned function,
const char * const **groups,
unsigned * const num_groups)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
*groups = pdata->functions[function].groups;
*num_groups = pdata->functions[function].ngroups;
return 0;
}
static int bcm281xx_pinmux_set(struct pinctrl_dev *pctldev,
unsigned function,
unsigned group)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
const struct bcm281xx_pin_function *f = &pdata->functions[function];
u32 offset = 4 * pdata->pins[group].number;
int rc = 0;
dev_dbg(pctldev->dev,
"%s(): Enable function %s (%d) of pin %s (%d) @offset 0x%x.\n",
__func__, f->name, function, pdata->pins[group].name,
pdata->pins[group].number, offset);
rc = regmap_update_bits(pdata->regmap, offset,
BCM281XX_PIN_REG_F_SEL_MASK,
function << BCM281XX_PIN_REG_F_SEL_SHIFT);
if (rc)
dev_err(pctldev->dev,
"Error updating register for pin %s (%d).\n",
pdata->pins[group].name, pdata->pins[group].number);
return rc;
}
static struct pinmux_ops bcm281xx_pinctrl_pinmux_ops = {
.get_functions_count = bcm281xx_pinctrl_get_fcns_count,
.get_function_name = bcm281xx_pinctrl_get_fcn_name,
.get_function_groups = bcm281xx_pinctrl_get_fcn_groups,
.set_mux = bcm281xx_pinmux_set,
};
static int bcm281xx_pinctrl_pin_config_get(struct pinctrl_dev *pctldev,
unsigned pin,
unsigned long *config)
{
return -ENOTSUPP;
}
/* Goes through the configs and update register val/mask */
static int bcm281xx_std_pin_update(struct pinctrl_dev *pctldev,
unsigned pin,
unsigned long *configs,
unsigned num_configs,
u32 *val,
u32 *mask)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
int i;
enum pin_config_param param;
u16 arg;
for (i = 0; i < num_configs; i++) {
param = pinconf_to_config_param(configs[i]);
arg = pinconf_to_config_argument(configs[i]);
switch (param) {
case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
arg = (arg >= 1 ? 1 : 0);
bcm281xx_pin_update(val, mask, arg,
BCM281XX_PIN_SHIFT(STD, HYST),
BCM281XX_PIN_MASK(STD, HYST));
break;
/*
* The pin bias can only be one of pull-up, pull-down, or
* disable. The user does not need to specify a value for the
* property, and the default value from pinconf-generic is
* ignored.
*/
case PIN_CONFIG_BIAS_DISABLE:
bcm281xx_pin_update(val, mask, 0,
BCM281XX_PIN_SHIFT(STD, PULL_UP),
BCM281XX_PIN_MASK(STD, PULL_UP));
bcm281xx_pin_update(val, mask, 0,
BCM281XX_PIN_SHIFT(STD, PULL_DN),
BCM281XX_PIN_MASK(STD, PULL_DN));
break;
case PIN_CONFIG_BIAS_PULL_UP:
bcm281xx_pin_update(val, mask, 1,
BCM281XX_PIN_SHIFT(STD, PULL_UP),
BCM281XX_PIN_MASK(STD, PULL_UP));
bcm281xx_pin_update(val, mask, 0,
BCM281XX_PIN_SHIFT(STD, PULL_DN),
BCM281XX_PIN_MASK(STD, PULL_DN));
break;
case PIN_CONFIG_BIAS_PULL_DOWN:
bcm281xx_pin_update(val, mask, 0,
BCM281XX_PIN_SHIFT(STD, PULL_UP),
BCM281XX_PIN_MASK(STD, PULL_UP));
bcm281xx_pin_update(val, mask, 1,
BCM281XX_PIN_SHIFT(STD, PULL_DN),
BCM281XX_PIN_MASK(STD, PULL_DN));
break;
case PIN_CONFIG_SLEW_RATE:
arg = (arg >= 1 ? 1 : 0);
bcm281xx_pin_update(val, mask, arg,
BCM281XX_PIN_SHIFT(STD, SLEW),
BCM281XX_PIN_MASK(STD, SLEW));
break;
case PIN_CONFIG_INPUT_ENABLE:
/* inversed since register is for input _disable_ */
arg = (arg >= 1 ? 0 : 1);
bcm281xx_pin_update(val, mask, arg,
BCM281XX_PIN_SHIFT(STD, INPUT_DIS),
BCM281XX_PIN_MASK(STD, INPUT_DIS));
break;
case PIN_CONFIG_DRIVE_STRENGTH:
/* Valid range is 2-16 mA, even numbers only */
if ((arg < 2) || (arg > 16) || (arg % 2)) {
dev_err(pctldev->dev,
"Invalid Drive Strength value (%d) for "
"pin %s (%d). Valid values are "
"(2..16) mA, even numbers only.\n",
arg, pdata->pins[pin].name, pin);
return -EINVAL;
}
bcm281xx_pin_update(val, mask, (arg/2)-1,
BCM281XX_PIN_SHIFT(STD, DRV_STR),
BCM281XX_PIN_MASK(STD, DRV_STR));
break;
default:
dev_err(pctldev->dev,
"Unrecognized pin config %d for pin %s (%d).\n",
param, pdata->pins[pin].name, pin);
return -EINVAL;
} /* switch config */
} /* for each config */
return 0;
}
/*
* The pull-up strength for an I2C pin is represented by bits 4-6 in the
* register with the following mapping:
* 0b000: No pull-up
* 0b001: 1200 Ohm
* 0b010: 1800 Ohm
* 0b011: 720 Ohm
* 0b100: 2700 Ohm
* 0b101: 831 Ohm
* 0b110: 1080 Ohm
* 0b111: 568 Ohm
* This array maps pull-up strength in Ohms to register values (1+index).
*/
static const u16 bcm281xx_pullup_map[] = {
1200, 1800, 720, 2700, 831, 1080, 568
};
/* Goes through the configs and update register val/mask */
static int bcm281xx_i2c_pin_update(struct pinctrl_dev *pctldev,
unsigned pin,
unsigned long *configs,
unsigned num_configs,
u32 *val,
u32 *mask)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
int i, j;
enum pin_config_param param;
u16 arg;
for (i = 0; i < num_configs; i++) {
param = pinconf_to_config_param(configs[i]);
arg = pinconf_to_config_argument(configs[i]);
switch (param) {
case PIN_CONFIG_BIAS_PULL_UP:
for (j = 0; j < ARRAY_SIZE(bcm281xx_pullup_map); j++)
if (bcm281xx_pullup_map[j] == arg)
break;
if (j == ARRAY_SIZE(bcm281xx_pullup_map)) {
dev_err(pctldev->dev,
"Invalid pull-up value (%d) for pin %s "
"(%d). Valid values are 568, 720, 831, "
"1080, 1200, 1800, 2700 Ohms.\n",
arg, pdata->pins[pin].name, pin);
return -EINVAL;
}
bcm281xx_pin_update(val, mask, j+1,
BCM281XX_PIN_SHIFT(I2C, PULL_UP_STR),
BCM281XX_PIN_MASK(I2C, PULL_UP_STR));
break;
case PIN_CONFIG_BIAS_DISABLE:
bcm281xx_pin_update(val, mask, 0,
BCM281XX_PIN_SHIFT(I2C, PULL_UP_STR),
BCM281XX_PIN_MASK(I2C, PULL_UP_STR));
break;
case PIN_CONFIG_SLEW_RATE:
arg = (arg >= 1 ? 1 : 0);
bcm281xx_pin_update(val, mask, arg,
BCM281XX_PIN_SHIFT(I2C, SLEW),
BCM281XX_PIN_MASK(I2C, SLEW));
break;
case PIN_CONFIG_INPUT_ENABLE:
/* inversed since register is for input _disable_ */
arg = (arg >= 1 ? 0 : 1);
bcm281xx_pin_update(val, mask, arg,
BCM281XX_PIN_SHIFT(I2C, INPUT_DIS),
BCM281XX_PIN_MASK(I2C, INPUT_DIS));
break;
default:
dev_err(pctldev->dev,
"Unrecognized pin config %d for pin %s (%d).\n",
param, pdata->pins[pin].name, pin);
return -EINVAL;
} /* switch config */
} /* for each config */
return 0;
}
/* Goes through the configs and update register val/mask */
static int bcm281xx_hdmi_pin_update(struct pinctrl_dev *pctldev,
unsigned pin,
unsigned long *configs,
unsigned num_configs,
u32 *val,
u32 *mask)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
int i;
enum pin_config_param param;
u16 arg;
for (i = 0; i < num_configs; i++) {
param = pinconf_to_config_param(configs[i]);
arg = pinconf_to_config_argument(configs[i]);
switch (param) {
case PIN_CONFIG_SLEW_RATE:
arg = (arg >= 1 ? 1 : 0);
bcm281xx_pin_update(val, mask, arg,
BCM281XX_PIN_SHIFT(HDMI, MODE),
BCM281XX_PIN_MASK(HDMI, MODE));
break;
case PIN_CONFIG_INPUT_ENABLE:
/* inversed since register is for input _disable_ */
arg = (arg >= 1 ? 0 : 1);
bcm281xx_pin_update(val, mask, arg,
BCM281XX_PIN_SHIFT(HDMI, INPUT_DIS),
BCM281XX_PIN_MASK(HDMI, INPUT_DIS));
break;
default:
dev_err(pctldev->dev,
"Unrecognized pin config %d for pin %s (%d).\n",
param, pdata->pins[pin].name, pin);
return -EINVAL;
} /* switch config */
} /* for each config */
return 0;
}
static int bcm281xx_pinctrl_pin_config_set(struct pinctrl_dev *pctldev,
unsigned pin,
unsigned long *configs,
unsigned num_configs)
{
struct bcm281xx_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev);
enum bcm281xx_pin_type pin_type;
u32 offset = 4 * pin;
u32 cfg_val, cfg_mask;
int rc;
cfg_val = 0;
cfg_mask = 0;
pin_type = pin_type_get(pctldev, pin);
/* Different pins have different configuration options */
switch (pin_type) {
case BCM281XX_PIN_TYPE_STD:
rc = bcm281xx_std_pin_update(pctldev, pin, configs,
num_configs, &cfg_val, &cfg_mask);
break;
case BCM281XX_PIN_TYPE_I2C:
rc = bcm281xx_i2c_pin_update(pctldev, pin, configs,
num_configs, &cfg_val, &cfg_mask);
break;
case BCM281XX_PIN_TYPE_HDMI:
rc = bcm281xx_hdmi_pin_update(pctldev, pin, configs,
num_configs, &cfg_val, &cfg_mask);
break;
default:
dev_err(pctldev->dev, "Unknown pin type for pin %s (%d).\n",
pdata->pins[pin].name, pin);
return -EINVAL;
} /* switch pin type */
if (rc)
return rc;
dev_dbg(pctldev->dev,
"%s(): Set pin %s (%d) with config 0x%x, mask 0x%x\n",
__func__, pdata->pins[pin].name, pin, cfg_val, cfg_mask);
rc = regmap_update_bits(pdata->regmap, offset, cfg_mask, cfg_val);
if (rc) {
dev_err(pctldev->dev,
"Error updating register for pin %s (%d).\n",
pdata->pins[pin].name, pin);
return rc;
}
return 0;
}
static struct pinconf_ops bcm281xx_pinctrl_pinconf_ops = {
.pin_config_get = bcm281xx_pinctrl_pin_config_get,
.pin_config_set = bcm281xx_pinctrl_pin_config_set,
};
static struct pinctrl_desc bcm281xx_pinctrl_desc = {
/* name, pins, npins members initialized in probe function */
.pctlops = &bcm281xx_pinctrl_ops,
.pmxops = &bcm281xx_pinctrl_pinmux_ops,
.confops = &bcm281xx_pinctrl_pinconf_ops,
.owner = THIS_MODULE,
};
static int __init bcm281xx_pinctrl_probe(struct platform_device *pdev)
{
struct bcm281xx_pinctrl_data *pdata = &bcm281xx_pinctrl;
struct resource *res;
struct pinctrl_dev *pctl;
/* So far We can assume there is only 1 bank of registers */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
pdata->reg_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(pdata->reg_base)) {
dev_err(&pdev->dev, "Failed to ioremap MEM resource\n");
return -ENODEV;
}
/* Initialize the dynamic part of pinctrl_desc */
pdata->regmap = devm_regmap_init_mmio(&pdev->dev, pdata->reg_base,
&bcm281xx_pinctrl_regmap_config);
if (IS_ERR(pdata->regmap)) {
dev_err(&pdev->dev, "Regmap MMIO init failed.\n");
return -ENODEV;
}
bcm281xx_pinctrl_desc.name = dev_name(&pdev->dev);
bcm281xx_pinctrl_desc.pins = bcm281xx_pinctrl.pins;
bcm281xx_pinctrl_desc.npins = bcm281xx_pinctrl.npins;
pctl = pinctrl_register(&bcm281xx_pinctrl_desc,
&pdev->dev,
pdata);
if (IS_ERR(pctl)) {
dev_err(&pdev->dev, "Failed to register pinctrl\n");
return PTR_ERR(pctl);
}
platform_set_drvdata(pdev, pdata);
return 0;
}
static const struct of_device_id bcm281xx_pinctrl_of_match[] = {
{ .compatible = "brcm,bcm11351-pinctrl", },
{ },
};
static struct platform_driver bcm281xx_pinctrl_driver = {
.driver = {
.name = "bcm281xx-pinctrl",
.of_match_table = bcm281xx_pinctrl_of_match,
},
};
module_platform_driver_probe(bcm281xx_pinctrl_driver, bcm281xx_pinctrl_probe);
MODULE_AUTHOR("Broadcom Corporation <bcm-kernel-feedback-list@broadcom.com>");
MODULE_AUTHOR("Sherman Yin <syin@broadcom.com>");
MODULE_DESCRIPTION("Broadcom BCM281xx pinctrl driver");
MODULE_LICENSE("GPL v2");
| gpl-2.0 |
EZchip/gcc | gcc/fold-const.c | 2 | 543282 | /* Fold a constant sub-tree into a single node for C-compiler
Copyright (C) 1987-2013 Free Software Foundation, Inc.
This file is part of GCC.
GCC 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 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/*@@ This file should be rewritten to use an arbitrary precision
@@ representation for "struct tree_int_cst" and "struct tree_real_cst".
@@ Perhaps the routines could also be used for bc/dc, and made a lib.
@@ The routines that translate from the ap rep should
@@ warn if precision et. al. is lost.
@@ This would also make life easier when this technology is used
@@ for cross-compilers. */
/* The entry points in this file are fold, size_int_wide and size_binop.
fold takes a tree as argument and returns a simplified tree.
size_binop takes a tree code for an arithmetic operation
and two operands that are trees, and produces a tree for the
result, assuming the type comes from `sizetype'.
size_int takes an integer value, and creates a tree constant
with type from `sizetype'.
Note: Since the folders get called on non-gimple code as well as
gimple code, we need to handle GIMPLE tuples as well as their
corresponding tree equivalents. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "flags.h"
#include "tree.h"
#include "realmpfr.h"
#include "rtl.h"
#include "expr.h"
#include "tm_p.h"
#include "target.h"
#include "diagnostic-core.h"
#include "intl.h"
#include "ggc.h"
#include "hash-table.h"
#include "langhooks.h"
#include "md5.h"
#include "gimple.h"
#include "tree-flow.h"
/* Nonzero if we are folding constants inside an initializer; zero
otherwise. */
int folding_initializer = 0;
/* The following constants represent a bit based encoding of GCC's
comparison operators. This encoding simplifies transformations
on relational comparison operators, such as AND and OR. */
enum comparison_code {
COMPCODE_FALSE = 0,
COMPCODE_LT = 1,
COMPCODE_EQ = 2,
COMPCODE_LE = 3,
COMPCODE_GT = 4,
COMPCODE_LTGT = 5,
COMPCODE_GE = 6,
COMPCODE_ORD = 7,
COMPCODE_UNORD = 8,
COMPCODE_UNLT = 9,
COMPCODE_UNEQ = 10,
COMPCODE_UNLE = 11,
COMPCODE_UNGT = 12,
COMPCODE_NE = 13,
COMPCODE_UNGE = 14,
COMPCODE_TRUE = 15
};
static bool negate_mathfn_p (enum built_in_function);
static bool negate_expr_p (tree);
static tree negate_expr (tree);
static tree split_tree (tree, enum tree_code, tree *, tree *, tree *, int);
static tree associate_trees (location_t, tree, tree, enum tree_code, tree);
static tree const_binop (enum tree_code, tree, tree);
static enum comparison_code comparison_to_compcode (enum tree_code);
static enum tree_code compcode_to_comparison (enum comparison_code);
static int operand_equal_for_comparison_p (tree, tree, tree);
static int twoval_comparison_p (tree, tree *, tree *, int *);
static tree eval_subst (location_t, tree, tree, tree, tree, tree);
static tree pedantic_omit_one_operand_loc (location_t, tree, tree, tree);
static tree distribute_bit_expr (location_t, enum tree_code, tree, tree, tree);
static tree make_bit_field_ref (location_t, tree, tree,
HOST_WIDE_INT, HOST_WIDE_INT, int);
static tree optimize_bit_field_compare (location_t, enum tree_code,
tree, tree, tree);
static tree decode_field_reference (location_t, tree, HOST_WIDE_INT *,
HOST_WIDE_INT *,
enum machine_mode *, int *, int *,
tree *, tree *);
static int all_ones_mask_p (const_tree, int);
static tree sign_bit_p (tree, const_tree);
static int simple_operand_p (const_tree);
static bool simple_operand_p_2 (tree);
static tree range_binop (enum tree_code, tree, tree, int, tree, int);
static tree range_predecessor (tree);
static tree range_successor (tree);
static tree fold_range_test (location_t, enum tree_code, tree, tree, tree);
static tree fold_cond_expr_with_comparison (location_t, tree, tree, tree, tree);
static tree unextend (tree, int, int, tree);
static tree optimize_minmax_comparison (location_t, enum tree_code,
tree, tree, tree);
static tree extract_muldiv (tree, tree, enum tree_code, tree, bool *);
static tree extract_muldiv_1 (tree, tree, enum tree_code, tree, bool *);
static tree fold_binary_op_with_conditional_arg (location_t,
enum tree_code, tree,
tree, tree,
tree, tree, int);
static tree fold_mathfn_compare (location_t,
enum built_in_function, enum tree_code,
tree, tree, tree);
static tree fold_inf_compare (location_t, enum tree_code, tree, tree, tree);
static tree fold_div_compare (location_t, enum tree_code, tree, tree, tree);
static bool reorder_operands_p (const_tree, const_tree);
static tree fold_negate_const (tree, tree);
static tree fold_not_const (const_tree, tree);
static tree fold_relational_const (enum tree_code, tree, tree, tree);
static tree fold_convert_const (enum tree_code, tree, tree);
/* Return EXPR_LOCATION of T if it is not UNKNOWN_LOCATION.
Otherwise, return LOC. */
static location_t
expr_location_or (tree t, location_t loc)
{
location_t tloc = EXPR_LOCATION (t);
return tloc == UNKNOWN_LOCATION ? loc : tloc;
}
/* Similar to protected_set_expr_location, but never modify x in place,
if location can and needs to be set, unshare it. */
static inline tree
protected_set_expr_location_unshare (tree x, location_t loc)
{
if (CAN_HAVE_LOCATION_P (x)
&& EXPR_LOCATION (x) != loc
&& !(TREE_CODE (x) == SAVE_EXPR
|| TREE_CODE (x) == TARGET_EXPR
|| TREE_CODE (x) == BIND_EXPR))
{
x = copy_node (x);
SET_EXPR_LOCATION (x, loc);
}
return x;
}
/* If ARG2 divides ARG1 with zero remainder, carries out the division
of type CODE and returns the quotient.
Otherwise returns NULL_TREE. */
tree
div_if_zero_remainder (enum tree_code code, const_tree arg1, const_tree arg2)
{
double_int quo, rem;
int uns;
/* The sign of the division is according to operand two, that
does the correct thing for POINTER_PLUS_EXPR where we want
a signed division. */
uns = TYPE_UNSIGNED (TREE_TYPE (arg2));
quo = tree_to_double_int (arg1).divmod (tree_to_double_int (arg2),
uns, code, &rem);
if (rem.is_zero ())
return build_int_cst_wide (TREE_TYPE (arg1), quo.low, quo.high);
return NULL_TREE;
}
/* This is nonzero if we should defer warnings about undefined
overflow. This facility exists because these warnings are a
special case. The code to estimate loop iterations does not want
to issue any warnings, since it works with expressions which do not
occur in user code. Various bits of cleanup code call fold(), but
only use the result if it has certain characteristics (e.g., is a
constant); that code only wants to issue a warning if the result is
used. */
static int fold_deferring_overflow_warnings;
/* If a warning about undefined overflow is deferred, this is the
warning. Note that this may cause us to turn two warnings into
one, but that is fine since it is sufficient to only give one
warning per expression. */
static const char* fold_deferred_overflow_warning;
/* If a warning about undefined overflow is deferred, this is the
level at which the warning should be emitted. */
static enum warn_strict_overflow_code fold_deferred_overflow_code;
/* Start deferring overflow warnings. We could use a stack here to
permit nested calls, but at present it is not necessary. */
void
fold_defer_overflow_warnings (void)
{
++fold_deferring_overflow_warnings;
}
/* Stop deferring overflow warnings. If there is a pending warning,
and ISSUE is true, then issue the warning if appropriate. STMT is
the statement with which the warning should be associated (used for
location information); STMT may be NULL. CODE is the level of the
warning--a warn_strict_overflow_code value. This function will use
the smaller of CODE and the deferred code when deciding whether to
issue the warning. CODE may be zero to mean to always use the
deferred code. */
void
fold_undefer_overflow_warnings (bool issue, const_gimple stmt, int code)
{
const char *warnmsg;
location_t locus;
gcc_assert (fold_deferring_overflow_warnings > 0);
--fold_deferring_overflow_warnings;
if (fold_deferring_overflow_warnings > 0)
{
if (fold_deferred_overflow_warning != NULL
&& code != 0
&& code < (int) fold_deferred_overflow_code)
fold_deferred_overflow_code = (enum warn_strict_overflow_code) code;
return;
}
warnmsg = fold_deferred_overflow_warning;
fold_deferred_overflow_warning = NULL;
if (!issue || warnmsg == NULL)
return;
if (gimple_no_warning_p (stmt))
return;
/* Use the smallest code level when deciding to issue the
warning. */
if (code == 0 || code > (int) fold_deferred_overflow_code)
code = fold_deferred_overflow_code;
if (!issue_strict_overflow_warning (code))
return;
if (stmt == NULL)
locus = input_location;
else
locus = gimple_location (stmt);
warning_at (locus, OPT_Wstrict_overflow, "%s", warnmsg);
}
/* Stop deferring overflow warnings, ignoring any deferred
warnings. */
void
fold_undefer_and_ignore_overflow_warnings (void)
{
fold_undefer_overflow_warnings (false, NULL, 0);
}
/* Whether we are deferring overflow warnings. */
bool
fold_deferring_overflow_warnings_p (void)
{
return fold_deferring_overflow_warnings > 0;
}
/* This is called when we fold something based on the fact that signed
overflow is undefined. */
static void
fold_overflow_warning (const char* gmsgid, enum warn_strict_overflow_code wc)
{
if (fold_deferring_overflow_warnings > 0)
{
if (fold_deferred_overflow_warning == NULL
|| wc < fold_deferred_overflow_code)
{
fold_deferred_overflow_warning = gmsgid;
fold_deferred_overflow_code = wc;
}
}
else if (issue_strict_overflow_warning (wc))
warning (OPT_Wstrict_overflow, gmsgid);
}
/* Return true if the built-in mathematical function specified by CODE
is odd, i.e. -f(x) == f(-x). */
static bool
negate_mathfn_p (enum built_in_function code)
{
switch (code)
{
CASE_FLT_FN (BUILT_IN_ASIN):
CASE_FLT_FN (BUILT_IN_ASINH):
CASE_FLT_FN (BUILT_IN_ATAN):
CASE_FLT_FN (BUILT_IN_ATANH):
CASE_FLT_FN (BUILT_IN_CASIN):
CASE_FLT_FN (BUILT_IN_CASINH):
CASE_FLT_FN (BUILT_IN_CATAN):
CASE_FLT_FN (BUILT_IN_CATANH):
CASE_FLT_FN (BUILT_IN_CBRT):
CASE_FLT_FN (BUILT_IN_CPROJ):
CASE_FLT_FN (BUILT_IN_CSIN):
CASE_FLT_FN (BUILT_IN_CSINH):
CASE_FLT_FN (BUILT_IN_CTAN):
CASE_FLT_FN (BUILT_IN_CTANH):
CASE_FLT_FN (BUILT_IN_ERF):
CASE_FLT_FN (BUILT_IN_LLROUND):
CASE_FLT_FN (BUILT_IN_LROUND):
CASE_FLT_FN (BUILT_IN_ROUND):
CASE_FLT_FN (BUILT_IN_SIN):
CASE_FLT_FN (BUILT_IN_SINH):
CASE_FLT_FN (BUILT_IN_TAN):
CASE_FLT_FN (BUILT_IN_TANH):
CASE_FLT_FN (BUILT_IN_TRUNC):
return true;
CASE_FLT_FN (BUILT_IN_LLRINT):
CASE_FLT_FN (BUILT_IN_LRINT):
CASE_FLT_FN (BUILT_IN_NEARBYINT):
CASE_FLT_FN (BUILT_IN_RINT):
return !flag_rounding_math;
default:
break;
}
return false;
}
/* Check whether we may negate an integer constant T without causing
overflow. */
bool
may_negate_without_overflow_p (const_tree t)
{
unsigned HOST_WIDE_INT val;
unsigned int prec;
tree type;
gcc_assert (TREE_CODE (t) == INTEGER_CST);
type = TREE_TYPE (t);
if (TYPE_UNSIGNED (type))
return false;
prec = TYPE_PRECISION (type);
if (prec > HOST_BITS_PER_WIDE_INT)
{
if (TREE_INT_CST_LOW (t) != 0)
return true;
prec -= HOST_BITS_PER_WIDE_INT;
val = TREE_INT_CST_HIGH (t);
}
else
val = TREE_INT_CST_LOW (t);
if (prec < HOST_BITS_PER_WIDE_INT)
val &= ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
return val != ((unsigned HOST_WIDE_INT) 1 << (prec - 1));
}
/* Determine whether an expression T can be cheaply negated using
the function negate_expr without introducing undefined overflow. */
static bool
negate_expr_p (tree t)
{
tree type;
if (t == 0)
return false;
type = TREE_TYPE (t);
STRIP_SIGN_NOPS (t);
switch (TREE_CODE (t))
{
case INTEGER_CST:
if (TYPE_OVERFLOW_WRAPS (type))
return true;
/* Check that -CST will not overflow type. */
return may_negate_without_overflow_p (t);
case BIT_NOT_EXPR:
return (INTEGRAL_TYPE_P (type)
&& TYPE_OVERFLOW_WRAPS (type));
case FIXED_CST:
case NEGATE_EXPR:
return true;
case REAL_CST:
/* We want to canonicalize to positive real constants. Pretend
that only negative ones can be easily negated. */
return REAL_VALUE_NEGATIVE (TREE_REAL_CST (t));
case COMPLEX_CST:
return negate_expr_p (TREE_REALPART (t))
&& negate_expr_p (TREE_IMAGPART (t));
case COMPLEX_EXPR:
return negate_expr_p (TREE_OPERAND (t, 0))
&& negate_expr_p (TREE_OPERAND (t, 1));
case CONJ_EXPR:
return negate_expr_p (TREE_OPERAND (t, 0));
case PLUS_EXPR:
if (HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type))
|| HONOR_SIGNED_ZEROS (TYPE_MODE (type)))
return false;
/* -(A + B) -> (-B) - A. */
if (negate_expr_p (TREE_OPERAND (t, 1))
&& reorder_operands_p (TREE_OPERAND (t, 0),
TREE_OPERAND (t, 1)))
return true;
/* -(A + B) -> (-A) - B. */
return negate_expr_p (TREE_OPERAND (t, 0));
case MINUS_EXPR:
/* We can't turn -(A-B) into B-A when we honor signed zeros. */
return !HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (type))
&& reorder_operands_p (TREE_OPERAND (t, 0),
TREE_OPERAND (t, 1));
case MULT_EXPR:
if (TYPE_UNSIGNED (TREE_TYPE (t)))
break;
/* Fall through. */
case RDIV_EXPR:
if (! HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (TREE_TYPE (t))))
return negate_expr_p (TREE_OPERAND (t, 1))
|| negate_expr_p (TREE_OPERAND (t, 0));
break;
case TRUNC_DIV_EXPR:
case ROUND_DIV_EXPR:
case FLOOR_DIV_EXPR:
case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
/* In general we can't negate A / B, because if A is INT_MIN and
B is 1, we may turn this into INT_MIN / -1 which is undefined
and actually traps on some architectures. But if overflow is
undefined, we can negate, because - (INT_MIN / 1) is an
overflow. */
if (INTEGRAL_TYPE_P (TREE_TYPE (t))
&& !TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (t)))
break;
return negate_expr_p (TREE_OPERAND (t, 1))
|| negate_expr_p (TREE_OPERAND (t, 0));
case NOP_EXPR:
/* Negate -((double)float) as (double)(-float). */
if (TREE_CODE (type) == REAL_TYPE)
{
tree tem = strip_float_extensions (t);
if (tem != t)
return negate_expr_p (tem);
}
break;
case CALL_EXPR:
/* Negate -f(x) as f(-x). */
if (negate_mathfn_p (builtin_mathfn_code (t)))
return negate_expr_p (CALL_EXPR_ARG (t, 0));
break;
case RSHIFT_EXPR:
/* Optimize -((int)x >> 31) into (unsigned)x >> 31. */
if (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST)
{
tree op1 = TREE_OPERAND (t, 1);
if (TREE_INT_CST_HIGH (op1) == 0
&& (unsigned HOST_WIDE_INT) (TYPE_PRECISION (type) - 1)
== TREE_INT_CST_LOW (op1))
return true;
}
break;
default:
break;
}
return false;
}
/* Given T, an expression, return a folded tree for -T or NULL_TREE, if no
simplification is possible.
If negate_expr_p would return true for T, NULL_TREE will never be
returned. */
static tree
fold_negate_expr (location_t loc, tree t)
{
tree type = TREE_TYPE (t);
tree tem;
switch (TREE_CODE (t))
{
/* Convert - (~A) to A + 1. */
case BIT_NOT_EXPR:
if (INTEGRAL_TYPE_P (type))
return fold_build2_loc (loc, PLUS_EXPR, type, TREE_OPERAND (t, 0),
build_int_cst (type, 1));
break;
case INTEGER_CST:
tem = fold_negate_const (t, type);
if (TREE_OVERFLOW (tem) == TREE_OVERFLOW (t)
|| !TYPE_OVERFLOW_TRAPS (type))
return tem;
break;
case REAL_CST:
tem = fold_negate_const (t, type);
/* Two's complement FP formats, such as c4x, may overflow. */
if (!TREE_OVERFLOW (tem) || !flag_trapping_math)
return tem;
break;
case FIXED_CST:
tem = fold_negate_const (t, type);
return tem;
case COMPLEX_CST:
{
tree rpart = negate_expr (TREE_REALPART (t));
tree ipart = negate_expr (TREE_IMAGPART (t));
if ((TREE_CODE (rpart) == REAL_CST
&& TREE_CODE (ipart) == REAL_CST)
|| (TREE_CODE (rpart) == INTEGER_CST
&& TREE_CODE (ipart) == INTEGER_CST))
return build_complex (type, rpart, ipart);
}
break;
case COMPLEX_EXPR:
if (negate_expr_p (t))
return fold_build2_loc (loc, COMPLEX_EXPR, type,
fold_negate_expr (loc, TREE_OPERAND (t, 0)),
fold_negate_expr (loc, TREE_OPERAND (t, 1)));
break;
case CONJ_EXPR:
if (negate_expr_p (t))
return fold_build1_loc (loc, CONJ_EXPR, type,
fold_negate_expr (loc, TREE_OPERAND (t, 0)));
break;
case NEGATE_EXPR:
return TREE_OPERAND (t, 0);
case PLUS_EXPR:
if (!HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (type)))
{
/* -(A + B) -> (-B) - A. */
if (negate_expr_p (TREE_OPERAND (t, 1))
&& reorder_operands_p (TREE_OPERAND (t, 0),
TREE_OPERAND (t, 1)))
{
tem = negate_expr (TREE_OPERAND (t, 1));
return fold_build2_loc (loc, MINUS_EXPR, type,
tem, TREE_OPERAND (t, 0));
}
/* -(A + B) -> (-A) - B. */
if (negate_expr_p (TREE_OPERAND (t, 0)))
{
tem = negate_expr (TREE_OPERAND (t, 0));
return fold_build2_loc (loc, MINUS_EXPR, type,
tem, TREE_OPERAND (t, 1));
}
}
break;
case MINUS_EXPR:
/* - (A - B) -> B - A */
if (!HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (type))
&& reorder_operands_p (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1)))
return fold_build2_loc (loc, MINUS_EXPR, type,
TREE_OPERAND (t, 1), TREE_OPERAND (t, 0));
break;
case MULT_EXPR:
if (TYPE_UNSIGNED (type))
break;
/* Fall through. */
case RDIV_EXPR:
if (! HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type)))
{
tem = TREE_OPERAND (t, 1);
if (negate_expr_p (tem))
return fold_build2_loc (loc, TREE_CODE (t), type,
TREE_OPERAND (t, 0), negate_expr (tem));
tem = TREE_OPERAND (t, 0);
if (negate_expr_p (tem))
return fold_build2_loc (loc, TREE_CODE (t), type,
negate_expr (tem), TREE_OPERAND (t, 1));
}
break;
case TRUNC_DIV_EXPR:
case ROUND_DIV_EXPR:
case FLOOR_DIV_EXPR:
case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
/* In general we can't negate A / B, because if A is INT_MIN and
B is 1, we may turn this into INT_MIN / -1 which is undefined
and actually traps on some architectures. But if overflow is
undefined, we can negate, because - (INT_MIN / 1) is an
overflow. */
if (!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
{
const char * const warnmsg = G_("assuming signed overflow does not "
"occur when negating a division");
tem = TREE_OPERAND (t, 1);
if (negate_expr_p (tem))
{
if (INTEGRAL_TYPE_P (type)
&& (TREE_CODE (tem) != INTEGER_CST
|| integer_onep (tem)))
fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MISC);
return fold_build2_loc (loc, TREE_CODE (t), type,
TREE_OPERAND (t, 0), negate_expr (tem));
}
tem = TREE_OPERAND (t, 0);
if (negate_expr_p (tem))
{
if (INTEGRAL_TYPE_P (type)
&& (TREE_CODE (tem) != INTEGER_CST
|| tree_int_cst_equal (tem, TYPE_MIN_VALUE (type))))
fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MISC);
return fold_build2_loc (loc, TREE_CODE (t), type,
negate_expr (tem), TREE_OPERAND (t, 1));
}
}
break;
case NOP_EXPR:
/* Convert -((double)float) into (double)(-float). */
if (TREE_CODE (type) == REAL_TYPE)
{
tem = strip_float_extensions (t);
if (tem != t && negate_expr_p (tem))
return fold_convert_loc (loc, type, negate_expr (tem));
}
break;
case CALL_EXPR:
/* Negate -f(x) as f(-x). */
if (negate_mathfn_p (builtin_mathfn_code (t))
&& negate_expr_p (CALL_EXPR_ARG (t, 0)))
{
tree fndecl, arg;
fndecl = get_callee_fndecl (t);
arg = negate_expr (CALL_EXPR_ARG (t, 0));
return build_call_expr_loc (loc, fndecl, 1, arg);
}
break;
case RSHIFT_EXPR:
/* Optimize -((int)x >> 31) into (unsigned)x >> 31. */
if (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST)
{
tree op1 = TREE_OPERAND (t, 1);
if (TREE_INT_CST_HIGH (op1) == 0
&& (unsigned HOST_WIDE_INT) (TYPE_PRECISION (type) - 1)
== TREE_INT_CST_LOW (op1))
{
tree ntype = TYPE_UNSIGNED (type)
? signed_type_for (type)
: unsigned_type_for (type);
tree temp = fold_convert_loc (loc, ntype, TREE_OPERAND (t, 0));
temp = fold_build2_loc (loc, RSHIFT_EXPR, ntype, temp, op1);
return fold_convert_loc (loc, type, temp);
}
}
break;
default:
break;
}
return NULL_TREE;
}
/* Like fold_negate_expr, but return a NEGATE_EXPR tree, if T can not be
negated in a simpler way. Also allow for T to be NULL_TREE, in which case
return NULL_TREE. */
static tree
negate_expr (tree t)
{
tree type, tem;
location_t loc;
if (t == NULL_TREE)
return NULL_TREE;
loc = EXPR_LOCATION (t);
type = TREE_TYPE (t);
STRIP_SIGN_NOPS (t);
tem = fold_negate_expr (loc, t);
if (!tem)
tem = build1_loc (loc, NEGATE_EXPR, TREE_TYPE (t), t);
return fold_convert_loc (loc, type, tem);
}
/* Split a tree IN into a constant, literal and variable parts that could be
combined with CODE to make IN. "constant" means an expression with
TREE_CONSTANT but that isn't an actual constant. CODE must be a
commutative arithmetic operation. Store the constant part into *CONP,
the literal in *LITP and return the variable part. If a part isn't
present, set it to null. If the tree does not decompose in this way,
return the entire tree as the variable part and the other parts as null.
If CODE is PLUS_EXPR we also split trees that use MINUS_EXPR. In that
case, we negate an operand that was subtracted. Except if it is a
literal for which we use *MINUS_LITP instead.
If NEGATE_P is true, we are negating all of IN, again except a literal
for which we use *MINUS_LITP instead.
If IN is itself a literal or constant, return it as appropriate.
Note that we do not guarantee that any of the three values will be the
same type as IN, but they will have the same signedness and mode. */
static tree
split_tree (tree in, enum tree_code code, tree *conp, tree *litp,
tree *minus_litp, int negate_p)
{
tree var = 0;
*conp = 0;
*litp = 0;
*minus_litp = 0;
/* Strip any conversions that don't change the machine mode or signedness. */
STRIP_SIGN_NOPS (in);
if (TREE_CODE (in) == INTEGER_CST || TREE_CODE (in) == REAL_CST
|| TREE_CODE (in) == FIXED_CST)
*litp = in;
else if (TREE_CODE (in) == code
|| ((! FLOAT_TYPE_P (TREE_TYPE (in)) || flag_associative_math)
&& ! SAT_FIXED_POINT_TYPE_P (TREE_TYPE (in))
/* We can associate addition and subtraction together (even
though the C standard doesn't say so) for integers because
the value is not affected. For reals, the value might be
affected, so we can't. */
&& ((code == PLUS_EXPR && TREE_CODE (in) == MINUS_EXPR)
|| (code == MINUS_EXPR && TREE_CODE (in) == PLUS_EXPR))))
{
tree op0 = TREE_OPERAND (in, 0);
tree op1 = TREE_OPERAND (in, 1);
int neg1_p = TREE_CODE (in) == MINUS_EXPR;
int neg_litp_p = 0, neg_conp_p = 0, neg_var_p = 0;
/* First see if either of the operands is a literal, then a constant. */
if (TREE_CODE (op0) == INTEGER_CST || TREE_CODE (op0) == REAL_CST
|| TREE_CODE (op0) == FIXED_CST)
*litp = op0, op0 = 0;
else if (TREE_CODE (op1) == INTEGER_CST || TREE_CODE (op1) == REAL_CST
|| TREE_CODE (op1) == FIXED_CST)
*litp = op1, neg_litp_p = neg1_p, op1 = 0;
if (op0 != 0 && TREE_CONSTANT (op0))
*conp = op0, op0 = 0;
else if (op1 != 0 && TREE_CONSTANT (op1))
*conp = op1, neg_conp_p = neg1_p, op1 = 0;
/* If we haven't dealt with either operand, this is not a case we can
decompose. Otherwise, VAR is either of the ones remaining, if any. */
if (op0 != 0 && op1 != 0)
var = in;
else if (op0 != 0)
var = op0;
else
var = op1, neg_var_p = neg1_p;
/* Now do any needed negations. */
if (neg_litp_p)
*minus_litp = *litp, *litp = 0;
if (neg_conp_p)
*conp = negate_expr (*conp);
if (neg_var_p)
var = negate_expr (var);
}
else if (TREE_CODE (in) == BIT_NOT_EXPR
&& code == PLUS_EXPR)
{
/* -X - 1 is folded to ~X, undo that here. */
*minus_litp = build_one_cst (TREE_TYPE (in));
var = negate_expr (TREE_OPERAND (in, 0));
}
else if (TREE_CONSTANT (in))
*conp = in;
else
var = in;
if (negate_p)
{
if (*litp)
*minus_litp = *litp, *litp = 0;
else if (*minus_litp)
*litp = *minus_litp, *minus_litp = 0;
*conp = negate_expr (*conp);
var = negate_expr (var);
}
return var;
}
/* Re-associate trees split by the above function. T1 and T2 are
either expressions to associate or null. Return the new
expression, if any. LOC is the location of the new expression. If
we build an operation, do it in TYPE and with CODE. */
static tree
associate_trees (location_t loc, tree t1, tree t2, enum tree_code code, tree type)
{
if (t1 == 0)
return t2;
else if (t2 == 0)
return t1;
/* If either input is CODE, a PLUS_EXPR, or a MINUS_EXPR, don't
try to fold this since we will have infinite recursion. But do
deal with any NEGATE_EXPRs. */
if (TREE_CODE (t1) == code || TREE_CODE (t2) == code
|| TREE_CODE (t1) == MINUS_EXPR || TREE_CODE (t2) == MINUS_EXPR)
{
if (code == PLUS_EXPR)
{
if (TREE_CODE (t1) == NEGATE_EXPR)
return build2_loc (loc, MINUS_EXPR, type,
fold_convert_loc (loc, type, t2),
fold_convert_loc (loc, type,
TREE_OPERAND (t1, 0)));
else if (TREE_CODE (t2) == NEGATE_EXPR)
return build2_loc (loc, MINUS_EXPR, type,
fold_convert_loc (loc, type, t1),
fold_convert_loc (loc, type,
TREE_OPERAND (t2, 0)));
else if (integer_zerop (t2))
return fold_convert_loc (loc, type, t1);
}
else if (code == MINUS_EXPR)
{
if (integer_zerop (t2))
return fold_convert_loc (loc, type, t1);
}
return build2_loc (loc, code, type, fold_convert_loc (loc, type, t1),
fold_convert_loc (loc, type, t2));
}
return fold_build2_loc (loc, code, type, fold_convert_loc (loc, type, t1),
fold_convert_loc (loc, type, t2));
}
/* Check whether TYPE1 and TYPE2 are equivalent integer types, suitable
for use in int_const_binop, size_binop and size_diffop. */
static bool
int_binop_types_match_p (enum tree_code code, const_tree type1, const_tree type2)
{
if (!INTEGRAL_TYPE_P (type1) && !POINTER_TYPE_P (type1))
return false;
if (!INTEGRAL_TYPE_P (type2) && !POINTER_TYPE_P (type2))
return false;
switch (code)
{
case LSHIFT_EXPR:
case RSHIFT_EXPR:
case LROTATE_EXPR:
case RROTATE_EXPR:
return true;
default:
break;
}
return TYPE_UNSIGNED (type1) == TYPE_UNSIGNED (type2)
&& TYPE_PRECISION (type1) == TYPE_PRECISION (type2)
&& TYPE_MODE (type1) == TYPE_MODE (type2);
}
/* Combine two integer constants ARG1 and ARG2 under operation CODE
to produce a new constant. Return NULL_TREE if we don't know how
to evaluate CODE at compile-time. */
static tree
int_const_binop_1 (enum tree_code code, const_tree arg1, const_tree arg2,
int overflowable)
{
double_int op1, op2, res, tmp;
tree t;
tree type = TREE_TYPE (arg1);
bool uns = TYPE_UNSIGNED (type);
bool overflow = false;
op1 = tree_to_double_int (arg1);
op2 = tree_to_double_int (arg2);
switch (code)
{
case BIT_IOR_EXPR:
res = op1 | op2;
break;
case BIT_XOR_EXPR:
res = op1 ^ op2;
break;
case BIT_AND_EXPR:
res = op1 & op2;
break;
case RSHIFT_EXPR:
res = op1.rshift (op2.to_shwi (), TYPE_PRECISION (type), !uns);
break;
case LSHIFT_EXPR:
/* It's unclear from the C standard whether shifts can overflow.
The following code ignores overflow; perhaps a C standard
interpretation ruling is needed. */
res = op1.lshift (op2.to_shwi (), TYPE_PRECISION (type), !uns);
break;
case RROTATE_EXPR:
res = op1.rrotate (op2.to_shwi (), TYPE_PRECISION (type));
break;
case LROTATE_EXPR:
res = op1.lrotate (op2.to_shwi (), TYPE_PRECISION (type));
break;
case PLUS_EXPR:
res = op1.add_with_sign (op2, false, &overflow);
break;
case MINUS_EXPR:
res = op1.sub_with_overflow (op2, &overflow);
break;
case MULT_EXPR:
res = op1.mul_with_sign (op2, false, &overflow);
break;
case MULT_HIGHPART_EXPR:
/* ??? Need quad precision, or an additional shift operand
to the multiply primitive, to handle very large highparts. */
if (TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT)
return NULL_TREE;
tmp = op1 - op2;
res = tmp.rshift (TYPE_PRECISION (type), TYPE_PRECISION (type), !uns);
break;
case TRUNC_DIV_EXPR:
case FLOOR_DIV_EXPR: case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
/* This is a shortcut for a common special case. */
if (op2.high == 0 && (HOST_WIDE_INT) op2.low > 0
&& !TREE_OVERFLOW (arg1)
&& !TREE_OVERFLOW (arg2)
&& op1.high == 0 && (HOST_WIDE_INT) op1.low >= 0)
{
if (code == CEIL_DIV_EXPR)
op1.low += op2.low - 1;
res.low = op1.low / op2.low, res.high = 0;
break;
}
/* ... fall through ... */
case ROUND_DIV_EXPR:
if (op2.is_zero ())
return NULL_TREE;
if (op2.is_one ())
{
res = op1;
break;
}
if (op1 == op2 && !op1.is_zero ())
{
res = double_int_one;
break;
}
res = op1.divmod_with_overflow (op2, uns, code, &tmp, &overflow);
break;
case TRUNC_MOD_EXPR:
case FLOOR_MOD_EXPR: case CEIL_MOD_EXPR:
/* This is a shortcut for a common special case. */
if (op2.high == 0 && (HOST_WIDE_INT) op2.low > 0
&& !TREE_OVERFLOW (arg1)
&& !TREE_OVERFLOW (arg2)
&& op1.high == 0 && (HOST_WIDE_INT) op1.low >= 0)
{
if (code == CEIL_MOD_EXPR)
op1.low += op2.low - 1;
res.low = op1.low % op2.low, res.high = 0;
break;
}
/* ... fall through ... */
case ROUND_MOD_EXPR:
if (op2.is_zero ())
return NULL_TREE;
tmp = op1.divmod_with_overflow (op2, uns, code, &res, &overflow);
break;
case MIN_EXPR:
res = op1.min (op2, uns);
break;
case MAX_EXPR:
res = op1.max (op2, uns);
break;
default:
return NULL_TREE;
}
t = force_fit_type_double (TREE_TYPE (arg1), res, overflowable,
(!uns && overflow)
| TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2));
return t;
}
tree
int_const_binop (enum tree_code code, const_tree arg1, const_tree arg2)
{
return int_const_binop_1 (code, arg1, arg2, 1);
}
/* Combine two constants ARG1 and ARG2 under operation CODE to produce a new
constant. We assume ARG1 and ARG2 have the same data type, or at least
are the same kind of constant and the same machine mode. Return zero if
combining the constants is not allowed in the current operating mode. */
static tree
const_binop (enum tree_code code, tree arg1, tree arg2)
{
/* Sanity check for the recursive cases. */
if (!arg1 || !arg2)
return NULL_TREE;
STRIP_NOPS (arg1);
STRIP_NOPS (arg2);
if (TREE_CODE (arg1) == INTEGER_CST)
return int_const_binop (code, arg1, arg2);
if (TREE_CODE (arg1) == REAL_CST)
{
enum machine_mode mode;
REAL_VALUE_TYPE d1;
REAL_VALUE_TYPE d2;
REAL_VALUE_TYPE value;
REAL_VALUE_TYPE result;
bool inexact;
tree t, type;
/* The following codes are handled by real_arithmetic. */
switch (code)
{
case PLUS_EXPR:
case MINUS_EXPR:
case MULT_EXPR:
case RDIV_EXPR:
case MIN_EXPR:
case MAX_EXPR:
break;
default:
return NULL_TREE;
}
d1 = TREE_REAL_CST (arg1);
d2 = TREE_REAL_CST (arg2);
type = TREE_TYPE (arg1);
mode = TYPE_MODE (type);
/* Don't perform operation if we honor signaling NaNs and
either operand is a NaN. */
if (HONOR_SNANS (mode)
&& (REAL_VALUE_ISNAN (d1) || REAL_VALUE_ISNAN (d2)))
return NULL_TREE;
/* Don't perform operation if it would raise a division
by zero exception. */
if (code == RDIV_EXPR
&& REAL_VALUES_EQUAL (d2, dconst0)
&& (flag_trapping_math || ! MODE_HAS_INFINITIES (mode)))
return NULL_TREE;
/* If either operand is a NaN, just return it. Otherwise, set up
for floating-point trap; we return an overflow. */
if (REAL_VALUE_ISNAN (d1))
return arg1;
else if (REAL_VALUE_ISNAN (d2))
return arg2;
inexact = real_arithmetic (&value, code, &d1, &d2);
real_convert (&result, mode, &value);
/* Don't constant fold this floating point operation if
the result has overflowed and flag_trapping_math. */
if (flag_trapping_math
&& MODE_HAS_INFINITIES (mode)
&& REAL_VALUE_ISINF (result)
&& !REAL_VALUE_ISINF (d1)
&& !REAL_VALUE_ISINF (d2))
return NULL_TREE;
/* Don't constant fold this floating point operation if the
result may dependent upon the run-time rounding mode and
flag_rounding_math is set, or if GCC's software emulation
is unable to accurately represent the result. */
if ((flag_rounding_math
|| (MODE_COMPOSITE_P (mode) && !flag_unsafe_math_optimizations))
&& (inexact || !real_identical (&result, &value)))
return NULL_TREE;
t = build_real (type, result);
TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2);
return t;
}
if (TREE_CODE (arg1) == FIXED_CST)
{
FIXED_VALUE_TYPE f1;
FIXED_VALUE_TYPE f2;
FIXED_VALUE_TYPE result;
tree t, type;
int sat_p;
bool overflow_p;
/* The following codes are handled by fixed_arithmetic. */
switch (code)
{
case PLUS_EXPR:
case MINUS_EXPR:
case MULT_EXPR:
case TRUNC_DIV_EXPR:
f2 = TREE_FIXED_CST (arg2);
break;
case LSHIFT_EXPR:
case RSHIFT_EXPR:
f2.data.high = TREE_INT_CST_HIGH (arg2);
f2.data.low = TREE_INT_CST_LOW (arg2);
f2.mode = SImode;
break;
default:
return NULL_TREE;
}
f1 = TREE_FIXED_CST (arg1);
type = TREE_TYPE (arg1);
sat_p = TYPE_SATURATING (type);
overflow_p = fixed_arithmetic (&result, code, &f1, &f2, sat_p);
t = build_fixed (type, result);
/* Propagate overflow flags. */
if (overflow_p | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2))
TREE_OVERFLOW (t) = 1;
return t;
}
if (TREE_CODE (arg1) == COMPLEX_CST)
{
tree type = TREE_TYPE (arg1);
tree r1 = TREE_REALPART (arg1);
tree i1 = TREE_IMAGPART (arg1);
tree r2 = TREE_REALPART (arg2);
tree i2 = TREE_IMAGPART (arg2);
tree real, imag;
switch (code)
{
case PLUS_EXPR:
case MINUS_EXPR:
real = const_binop (code, r1, r2);
imag = const_binop (code, i1, i2);
break;
case MULT_EXPR:
if (COMPLEX_FLOAT_TYPE_P (type))
return do_mpc_arg2 (arg1, arg2, type,
/* do_nonfinite= */ folding_initializer,
mpc_mul);
real = const_binop (MINUS_EXPR,
const_binop (MULT_EXPR, r1, r2),
const_binop (MULT_EXPR, i1, i2));
imag = const_binop (PLUS_EXPR,
const_binop (MULT_EXPR, r1, i2),
const_binop (MULT_EXPR, i1, r2));
break;
case RDIV_EXPR:
if (COMPLEX_FLOAT_TYPE_P (type))
return do_mpc_arg2 (arg1, arg2, type,
/* do_nonfinite= */ folding_initializer,
mpc_div);
/* Fallthru ... */
case TRUNC_DIV_EXPR:
case CEIL_DIV_EXPR:
case FLOOR_DIV_EXPR:
case ROUND_DIV_EXPR:
if (flag_complex_method == 0)
{
/* Keep this algorithm in sync with
tree-complex.c:expand_complex_div_straight().
Expand complex division to scalars, straightforward algorithm.
a / b = ((ar*br + ai*bi)/t) + i((ai*br - ar*bi)/t)
t = br*br + bi*bi
*/
tree magsquared
= const_binop (PLUS_EXPR,
const_binop (MULT_EXPR, r2, r2),
const_binop (MULT_EXPR, i2, i2));
tree t1
= const_binop (PLUS_EXPR,
const_binop (MULT_EXPR, r1, r2),
const_binop (MULT_EXPR, i1, i2));
tree t2
= const_binop (MINUS_EXPR,
const_binop (MULT_EXPR, i1, r2),
const_binop (MULT_EXPR, r1, i2));
real = const_binop (code, t1, magsquared);
imag = const_binop (code, t2, magsquared);
}
else
{
/* Keep this algorithm in sync with
tree-complex.c:expand_complex_div_wide().
Expand complex division to scalars, modified algorithm to minimize
overflow with wide input ranges. */
tree compare = fold_build2 (LT_EXPR, boolean_type_node,
fold_abs_const (r2, TREE_TYPE (type)),
fold_abs_const (i2, TREE_TYPE (type)));
if (integer_nonzerop (compare))
{
/* In the TRUE branch, we compute
ratio = br/bi;
div = (br * ratio) + bi;
tr = (ar * ratio) + ai;
ti = (ai * ratio) - ar;
tr = tr / div;
ti = ti / div; */
tree ratio = const_binop (code, r2, i2);
tree div = const_binop (PLUS_EXPR, i2,
const_binop (MULT_EXPR, r2, ratio));
real = const_binop (MULT_EXPR, r1, ratio);
real = const_binop (PLUS_EXPR, real, i1);
real = const_binop (code, real, div);
imag = const_binop (MULT_EXPR, i1, ratio);
imag = const_binop (MINUS_EXPR, imag, r1);
imag = const_binop (code, imag, div);
}
else
{
/* In the FALSE branch, we compute
ratio = d/c;
divisor = (d * ratio) + c;
tr = (b * ratio) + a;
ti = b - (a * ratio);
tr = tr / div;
ti = ti / div; */
tree ratio = const_binop (code, i2, r2);
tree div = const_binop (PLUS_EXPR, r2,
const_binop (MULT_EXPR, i2, ratio));
real = const_binop (MULT_EXPR, i1, ratio);
real = const_binop (PLUS_EXPR, real, r1);
real = const_binop (code, real, div);
imag = const_binop (MULT_EXPR, r1, ratio);
imag = const_binop (MINUS_EXPR, i1, imag);
imag = const_binop (code, imag, div);
}
}
break;
default:
return NULL_TREE;
}
if (real && imag)
return build_complex (type, real, imag);
}
if (TREE_CODE (arg1) == VECTOR_CST
&& TREE_CODE (arg2) == VECTOR_CST)
{
tree type = TREE_TYPE(arg1);
int count = TYPE_VECTOR_SUBPARTS (type), i;
tree *elts = XALLOCAVEC (tree, count);
for (i = 0; i < count; i++)
{
tree elem1 = VECTOR_CST_ELT (arg1, i);
tree elem2 = VECTOR_CST_ELT (arg2, i);
elts[i] = const_binop (code, elem1, elem2);
/* It is possible that const_binop cannot handle the given
code and return NULL_TREE */
if(elts[i] == NULL_TREE)
return NULL_TREE;
}
return build_vector (type, elts);
}
return NULL_TREE;
}
/* Create a sizetype INT_CST node with NUMBER sign extended. KIND
indicates which particular sizetype to create. */
tree
size_int_kind (HOST_WIDE_INT number, enum size_type_kind kind)
{
return build_int_cst (sizetype_tab[(int) kind], number);
}
/* Combine operands OP1 and OP2 with arithmetic operation CODE. CODE
is a tree code. The type of the result is taken from the operands.
Both must be equivalent integer types, ala int_binop_types_match_p.
If the operands are constant, so is the result. */
tree
size_binop_loc (location_t loc, enum tree_code code, tree arg0, tree arg1)
{
tree type = TREE_TYPE (arg0);
if (arg0 == error_mark_node || arg1 == error_mark_node)
return error_mark_node;
gcc_assert (int_binop_types_match_p (code, TREE_TYPE (arg0),
TREE_TYPE (arg1)));
/* Handle the special case of two integer constants faster. */
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
{
/* And some specific cases even faster than that. */
if (code == PLUS_EXPR)
{
if (integer_zerop (arg0) && !TREE_OVERFLOW (arg0))
return arg1;
if (integer_zerop (arg1) && !TREE_OVERFLOW (arg1))
return arg0;
}
else if (code == MINUS_EXPR)
{
if (integer_zerop (arg1) && !TREE_OVERFLOW (arg1))
return arg0;
}
else if (code == MULT_EXPR)
{
if (integer_onep (arg0) && !TREE_OVERFLOW (arg0))
return arg1;
}
/* Handle general case of two integer constants. For sizetype
constant calculations we always want to know about overflow,
even in the unsigned case. */
return int_const_binop_1 (code, arg0, arg1, -1);
}
return fold_build2_loc (loc, code, type, arg0, arg1);
}
/* Given two values, either both of sizetype or both of bitsizetype,
compute the difference between the two values. Return the value
in signed type corresponding to the type of the operands. */
tree
size_diffop_loc (location_t loc, tree arg0, tree arg1)
{
tree type = TREE_TYPE (arg0);
tree ctype;
gcc_assert (int_binop_types_match_p (MINUS_EXPR, TREE_TYPE (arg0),
TREE_TYPE (arg1)));
/* If the type is already signed, just do the simple thing. */
if (!TYPE_UNSIGNED (type))
return size_binop_loc (loc, MINUS_EXPR, arg0, arg1);
if (type == sizetype)
ctype = ssizetype;
else if (type == bitsizetype)
ctype = sbitsizetype;
else
ctype = signed_type_for (type);
/* If either operand is not a constant, do the conversions to the signed
type and subtract. The hardware will do the right thing with any
overflow in the subtraction. */
if (TREE_CODE (arg0) != INTEGER_CST || TREE_CODE (arg1) != INTEGER_CST)
return size_binop_loc (loc, MINUS_EXPR,
fold_convert_loc (loc, ctype, arg0),
fold_convert_loc (loc, ctype, arg1));
/* If ARG0 is larger than ARG1, subtract and return the result in CTYPE.
Otherwise, subtract the other way, convert to CTYPE (we know that can't
overflow) and negate (which can't either). Special-case a result
of zero while we're here. */
if (tree_int_cst_equal (arg0, arg1))
return build_int_cst (ctype, 0);
else if (tree_int_cst_lt (arg1, arg0))
return fold_convert_loc (loc, ctype,
size_binop_loc (loc, MINUS_EXPR, arg0, arg1));
else
return size_binop_loc (loc, MINUS_EXPR, build_int_cst (ctype, 0),
fold_convert_loc (loc, ctype,
size_binop_loc (loc,
MINUS_EXPR,
arg1, arg0)));
}
/* A subroutine of fold_convert_const handling conversions of an
INTEGER_CST to another integer type. */
static tree
fold_convert_const_int_from_int (tree type, const_tree arg1)
{
tree t;
/* Given an integer constant, make new constant with new type,
appropriately sign-extended or truncated. */
t = force_fit_type_double (type, tree_to_double_int (arg1),
!POINTER_TYPE_P (TREE_TYPE (arg1)),
(TREE_INT_CST_HIGH (arg1) < 0
&& (TYPE_UNSIGNED (type)
< TYPE_UNSIGNED (TREE_TYPE (arg1))))
| TREE_OVERFLOW (arg1));
return t;
}
/* A subroutine of fold_convert_const handling conversions a REAL_CST
to an integer type. */
static tree
fold_convert_const_int_from_real (enum tree_code code, tree type, const_tree arg1)
{
int overflow = 0;
tree t;
/* The following code implements the floating point to integer
conversion rules required by the Java Language Specification,
that IEEE NaNs are mapped to zero and values that overflow
the target precision saturate, i.e. values greater than
INT_MAX are mapped to INT_MAX, and values less than INT_MIN
are mapped to INT_MIN. These semantics are allowed by the
C and C++ standards that simply state that the behavior of
FP-to-integer conversion is unspecified upon overflow. */
double_int val;
REAL_VALUE_TYPE r;
REAL_VALUE_TYPE x = TREE_REAL_CST (arg1);
switch (code)
{
case FIX_TRUNC_EXPR:
real_trunc (&r, VOIDmode, &x);
break;
default:
gcc_unreachable ();
}
/* If R is NaN, return zero and show we have an overflow. */
if (REAL_VALUE_ISNAN (r))
{
overflow = 1;
val = double_int_zero;
}
/* See if R is less than the lower bound or greater than the
upper bound. */
if (! overflow)
{
tree lt = TYPE_MIN_VALUE (type);
REAL_VALUE_TYPE l = real_value_from_int_cst (NULL_TREE, lt);
if (REAL_VALUES_LESS (r, l))
{
overflow = 1;
val = tree_to_double_int (lt);
}
}
if (! overflow)
{
tree ut = TYPE_MAX_VALUE (type);
if (ut)
{
REAL_VALUE_TYPE u = real_value_from_int_cst (NULL_TREE, ut);
if (REAL_VALUES_LESS (u, r))
{
overflow = 1;
val = tree_to_double_int (ut);
}
}
}
if (! overflow)
real_to_integer2 ((HOST_WIDE_INT *) &val.low, &val.high, &r);
t = force_fit_type_double (type, val, -1, overflow | TREE_OVERFLOW (arg1));
return t;
}
/* A subroutine of fold_convert_const handling conversions of a
FIXED_CST to an integer type. */
static tree
fold_convert_const_int_from_fixed (tree type, const_tree arg1)
{
tree t;
double_int temp, temp_trunc;
unsigned int mode;
/* Right shift FIXED_CST to temp by fbit. */
temp = TREE_FIXED_CST (arg1).data;
mode = TREE_FIXED_CST (arg1).mode;
if (GET_MODE_FBIT (mode) < HOST_BITS_PER_DOUBLE_INT)
{
temp = temp.rshift (GET_MODE_FBIT (mode),
HOST_BITS_PER_DOUBLE_INT,
SIGNED_FIXED_POINT_MODE_P (mode));
/* Left shift temp to temp_trunc by fbit. */
temp_trunc = temp.lshift (GET_MODE_FBIT (mode),
HOST_BITS_PER_DOUBLE_INT,
SIGNED_FIXED_POINT_MODE_P (mode));
}
else
{
temp = double_int_zero;
temp_trunc = double_int_zero;
}
/* If FIXED_CST is negative, we need to round the value toward 0.
By checking if the fractional bits are not zero to add 1 to temp. */
if (SIGNED_FIXED_POINT_MODE_P (mode)
&& temp_trunc.is_negative ()
&& TREE_FIXED_CST (arg1).data != temp_trunc)
temp += double_int_one;
/* Given a fixed-point constant, make new constant with new type,
appropriately sign-extended or truncated. */
t = force_fit_type_double (type, temp, -1,
(temp.is_negative ()
&& (TYPE_UNSIGNED (type)
< TYPE_UNSIGNED (TREE_TYPE (arg1))))
| TREE_OVERFLOW (arg1));
return t;
}
/* A subroutine of fold_convert_const handling conversions a REAL_CST
to another floating point type. */
static tree
fold_convert_const_real_from_real (tree type, const_tree arg1)
{
REAL_VALUE_TYPE value;
tree t;
real_convert (&value, TYPE_MODE (type), &TREE_REAL_CST (arg1));
t = build_real (type, value);
/* If converting an infinity or NAN to a representation that doesn't
have one, set the overflow bit so that we can produce some kind of
error message at the appropriate point if necessary. It's not the
most user-friendly message, but it's better than nothing. */
if (REAL_VALUE_ISINF (TREE_REAL_CST (arg1))
&& !MODE_HAS_INFINITIES (TYPE_MODE (type)))
TREE_OVERFLOW (t) = 1;
else if (REAL_VALUE_ISNAN (TREE_REAL_CST (arg1))
&& !MODE_HAS_NANS (TYPE_MODE (type)))
TREE_OVERFLOW (t) = 1;
/* Regular overflow, conversion produced an infinity in a mode that
can't represent them. */
else if (!MODE_HAS_INFINITIES (TYPE_MODE (type))
&& REAL_VALUE_ISINF (value)
&& !REAL_VALUE_ISINF (TREE_REAL_CST (arg1)))
TREE_OVERFLOW (t) = 1;
else
TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1);
return t;
}
/* A subroutine of fold_convert_const handling conversions a FIXED_CST
to a floating point type. */
static tree
fold_convert_const_real_from_fixed (tree type, const_tree arg1)
{
REAL_VALUE_TYPE value;
tree t;
real_convert_from_fixed (&value, TYPE_MODE (type), &TREE_FIXED_CST (arg1));
t = build_real (type, value);
TREE_OVERFLOW (t) = TREE_OVERFLOW (arg1);
return t;
}
/* A subroutine of fold_convert_const handling conversions a FIXED_CST
to another fixed-point type. */
static tree
fold_convert_const_fixed_from_fixed (tree type, const_tree arg1)
{
FIXED_VALUE_TYPE value;
tree t;
bool overflow_p;
overflow_p = fixed_convert (&value, TYPE_MODE (type), &TREE_FIXED_CST (arg1),
TYPE_SATURATING (type));
t = build_fixed (type, value);
/* Propagate overflow flags. */
if (overflow_p | TREE_OVERFLOW (arg1))
TREE_OVERFLOW (t) = 1;
return t;
}
/* A subroutine of fold_convert_const handling conversions an INTEGER_CST
to a fixed-point type. */
static tree
fold_convert_const_fixed_from_int (tree type, const_tree arg1)
{
FIXED_VALUE_TYPE value;
tree t;
bool overflow_p;
overflow_p = fixed_convert_from_int (&value, TYPE_MODE (type),
TREE_INT_CST (arg1),
TYPE_UNSIGNED (TREE_TYPE (arg1)),
TYPE_SATURATING (type));
t = build_fixed (type, value);
/* Propagate overflow flags. */
if (overflow_p | TREE_OVERFLOW (arg1))
TREE_OVERFLOW (t) = 1;
return t;
}
/* A subroutine of fold_convert_const handling conversions a REAL_CST
to a fixed-point type. */
static tree
fold_convert_const_fixed_from_real (tree type, const_tree arg1)
{
FIXED_VALUE_TYPE value;
tree t;
bool overflow_p;
overflow_p = fixed_convert_from_real (&value, TYPE_MODE (type),
&TREE_REAL_CST (arg1),
TYPE_SATURATING (type));
t = build_fixed (type, value);
/* Propagate overflow flags. */
if (overflow_p | TREE_OVERFLOW (arg1))
TREE_OVERFLOW (t) = 1;
return t;
}
/* Attempt to fold type conversion operation CODE of expression ARG1 to
type TYPE. If no simplification can be done return NULL_TREE. */
static tree
fold_convert_const (enum tree_code code, tree type, tree arg1)
{
if (TREE_TYPE (arg1) == type)
return arg1;
if (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type)
|| TREE_CODE (type) == OFFSET_TYPE)
{
if (TREE_CODE (arg1) == INTEGER_CST)
return fold_convert_const_int_from_int (type, arg1);
else if (TREE_CODE (arg1) == REAL_CST)
return fold_convert_const_int_from_real (code, type, arg1);
else if (TREE_CODE (arg1) == FIXED_CST)
return fold_convert_const_int_from_fixed (type, arg1);
}
else if (TREE_CODE (type) == REAL_TYPE)
{
if (TREE_CODE (arg1) == INTEGER_CST)
return build_real_from_int_cst (type, arg1);
else if (TREE_CODE (arg1) == REAL_CST)
return fold_convert_const_real_from_real (type, arg1);
else if (TREE_CODE (arg1) == FIXED_CST)
return fold_convert_const_real_from_fixed (type, arg1);
}
else if (TREE_CODE (type) == FIXED_POINT_TYPE)
{
if (TREE_CODE (arg1) == FIXED_CST)
return fold_convert_const_fixed_from_fixed (type, arg1);
else if (TREE_CODE (arg1) == INTEGER_CST)
return fold_convert_const_fixed_from_int (type, arg1);
else if (TREE_CODE (arg1) == REAL_CST)
return fold_convert_const_fixed_from_real (type, arg1);
}
return NULL_TREE;
}
/* Construct a vector of zero elements of vector type TYPE. */
static tree
build_zero_vector (tree type)
{
tree t;
t = fold_convert_const (NOP_EXPR, TREE_TYPE (type), integer_zero_node);
return build_vector_from_val (type, t);
}
/* Returns true, if ARG is convertible to TYPE using a NOP_EXPR. */
bool
fold_convertible_p (const_tree type, const_tree arg)
{
tree orig = TREE_TYPE (arg);
if (type == orig)
return true;
if (TREE_CODE (arg) == ERROR_MARK
|| TREE_CODE (type) == ERROR_MARK
|| TREE_CODE (orig) == ERROR_MARK)
return false;
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig))
return true;
switch (TREE_CODE (type))
{
case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
case POINTER_TYPE: case REFERENCE_TYPE:
case OFFSET_TYPE:
if (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
|| TREE_CODE (orig) == OFFSET_TYPE)
return true;
return (TREE_CODE (orig) == VECTOR_TYPE
&& tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
case REAL_TYPE:
case FIXED_POINT_TYPE:
case COMPLEX_TYPE:
case VECTOR_TYPE:
case VOID_TYPE:
return TREE_CODE (type) == TREE_CODE (orig);
default:
return false;
}
}
/* Convert expression ARG to type TYPE. Used by the middle-end for
simple conversions in preference to calling the front-end's convert. */
tree
fold_convert_loc (location_t loc, tree type, tree arg)
{
tree orig = TREE_TYPE (arg);
tree tem;
if (type == orig)
return arg;
if (TREE_CODE (arg) == ERROR_MARK
|| TREE_CODE (type) == ERROR_MARK
|| TREE_CODE (orig) == ERROR_MARK)
return error_mark_node;
switch (TREE_CODE (type))
{
case POINTER_TYPE:
case REFERENCE_TYPE:
/* Handle conversions between pointers to different address spaces. */
if (POINTER_TYPE_P (orig)
&& (TYPE_ADDR_SPACE (TREE_TYPE (type))
!= TYPE_ADDR_SPACE (TREE_TYPE (orig))))
return fold_build1_loc (loc, ADDR_SPACE_CONVERT_EXPR, type, arg);
/* fall through */
case INTEGER_TYPE: case ENUMERAL_TYPE: case BOOLEAN_TYPE:
case OFFSET_TYPE:
if (TREE_CODE (arg) == INTEGER_CST)
{
tem = fold_convert_const (NOP_EXPR, type, arg);
if (tem != NULL_TREE)
return tem;
}
if (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
|| TREE_CODE (orig) == OFFSET_TYPE)
return fold_build1_loc (loc, NOP_EXPR, type, arg);
if (TREE_CODE (orig) == COMPLEX_TYPE)
return fold_convert_loc (loc, type,
fold_build1_loc (loc, REALPART_EXPR,
TREE_TYPE (orig), arg));
gcc_assert (TREE_CODE (orig) == VECTOR_TYPE
&& tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
return fold_build1_loc (loc, NOP_EXPR, type, arg);
case REAL_TYPE:
if (TREE_CODE (arg) == INTEGER_CST)
{
tem = fold_convert_const (FLOAT_EXPR, type, arg);
if (tem != NULL_TREE)
return tem;
}
else if (TREE_CODE (arg) == REAL_CST)
{
tem = fold_convert_const (NOP_EXPR, type, arg);
if (tem != NULL_TREE)
return tem;
}
else if (TREE_CODE (arg) == FIXED_CST)
{
tem = fold_convert_const (FIXED_CONVERT_EXPR, type, arg);
if (tem != NULL_TREE)
return tem;
}
switch (TREE_CODE (orig))
{
case INTEGER_TYPE:
case BOOLEAN_TYPE: case ENUMERAL_TYPE:
case POINTER_TYPE: case REFERENCE_TYPE:
return fold_build1_loc (loc, FLOAT_EXPR, type, arg);
case REAL_TYPE:
return fold_build1_loc (loc, NOP_EXPR, type, arg);
case FIXED_POINT_TYPE:
return fold_build1_loc (loc, FIXED_CONVERT_EXPR, type, arg);
case COMPLEX_TYPE:
tem = fold_build1_loc (loc, REALPART_EXPR, TREE_TYPE (orig), arg);
return fold_convert_loc (loc, type, tem);
default:
gcc_unreachable ();
}
case FIXED_POINT_TYPE:
if (TREE_CODE (arg) == FIXED_CST || TREE_CODE (arg) == INTEGER_CST
|| TREE_CODE (arg) == REAL_CST)
{
tem = fold_convert_const (FIXED_CONVERT_EXPR, type, arg);
if (tem != NULL_TREE)
goto fold_convert_exit;
}
switch (TREE_CODE (orig))
{
case FIXED_POINT_TYPE:
case INTEGER_TYPE:
case ENUMERAL_TYPE:
case BOOLEAN_TYPE:
case REAL_TYPE:
return fold_build1_loc (loc, FIXED_CONVERT_EXPR, type, arg);
case COMPLEX_TYPE:
tem = fold_build1_loc (loc, REALPART_EXPR, TREE_TYPE (orig), arg);
return fold_convert_loc (loc, type, tem);
default:
gcc_unreachable ();
}
case COMPLEX_TYPE:
switch (TREE_CODE (orig))
{
case INTEGER_TYPE:
case BOOLEAN_TYPE: case ENUMERAL_TYPE:
case POINTER_TYPE: case REFERENCE_TYPE:
case REAL_TYPE:
case FIXED_POINT_TYPE:
return fold_build2_loc (loc, COMPLEX_EXPR, type,
fold_convert_loc (loc, TREE_TYPE (type), arg),
fold_convert_loc (loc, TREE_TYPE (type),
integer_zero_node));
case COMPLEX_TYPE:
{
tree rpart, ipart;
if (TREE_CODE (arg) == COMPLEX_EXPR)
{
rpart = fold_convert_loc (loc, TREE_TYPE (type),
TREE_OPERAND (arg, 0));
ipart = fold_convert_loc (loc, TREE_TYPE (type),
TREE_OPERAND (arg, 1));
return fold_build2_loc (loc, COMPLEX_EXPR, type, rpart, ipart);
}
arg = save_expr (arg);
rpart = fold_build1_loc (loc, REALPART_EXPR, TREE_TYPE (orig), arg);
ipart = fold_build1_loc (loc, IMAGPART_EXPR, TREE_TYPE (orig), arg);
rpart = fold_convert_loc (loc, TREE_TYPE (type), rpart);
ipart = fold_convert_loc (loc, TREE_TYPE (type), ipart);
return fold_build2_loc (loc, COMPLEX_EXPR, type, rpart, ipart);
}
default:
gcc_unreachable ();
}
case VECTOR_TYPE:
if (integer_zerop (arg))
return build_zero_vector (type);
gcc_assert (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
gcc_assert (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
|| TREE_CODE (orig) == VECTOR_TYPE);
return fold_build1_loc (loc, VIEW_CONVERT_EXPR, type, arg);
case VOID_TYPE:
tem = fold_ignored_result (arg);
return fold_build1_loc (loc, NOP_EXPR, type, tem);
default:
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig))
return fold_build1_loc (loc, NOP_EXPR, type, arg);
gcc_unreachable ();
}
fold_convert_exit:
protected_set_expr_location_unshare (tem, loc);
return tem;
}
/* Return false if expr can be assumed not to be an lvalue, true
otherwise. */
static bool
maybe_lvalue_p (const_tree x)
{
/* We only need to wrap lvalue tree codes. */
switch (TREE_CODE (x))
{
case VAR_DECL:
case PARM_DECL:
case RESULT_DECL:
case LABEL_DECL:
case FUNCTION_DECL:
case SSA_NAME:
case COMPONENT_REF:
case MEM_REF:
case INDIRECT_REF:
case ARRAY_REF:
case ARRAY_RANGE_REF:
case BIT_FIELD_REF:
case OBJ_TYPE_REF:
case REALPART_EXPR:
case IMAGPART_EXPR:
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case SAVE_EXPR:
case TRY_CATCH_EXPR:
case WITH_CLEANUP_EXPR:
case COMPOUND_EXPR:
case MODIFY_EXPR:
case TARGET_EXPR:
case COND_EXPR:
case BIND_EXPR:
break;
default:
/* Assume the worst for front-end tree codes. */
if ((int)TREE_CODE (x) >= NUM_TREE_CODES)
break;
return false;
}
return true;
}
/* Return an expr equal to X but certainly not valid as an lvalue. */
tree
non_lvalue_loc (location_t loc, tree x)
{
/* While we are in GIMPLE, NON_LVALUE_EXPR doesn't mean anything to
us. */
if (in_gimple_form)
return x;
if (! maybe_lvalue_p (x))
return x;
return build1_loc (loc, NON_LVALUE_EXPR, TREE_TYPE (x), x);
}
/* Nonzero means lvalues are limited to those valid in pedantic ANSI C.
Zero means allow extended lvalues. */
int pedantic_lvalues;
/* When pedantic, return an expr equal to X but certainly not valid as a
pedantic lvalue. Otherwise, return X. */
static tree
pedantic_non_lvalue_loc (location_t loc, tree x)
{
if (pedantic_lvalues)
return non_lvalue_loc (loc, x);
return protected_set_expr_location_unshare (x, loc);
}
/* Given a tree comparison code, return the code that is the logical inverse.
It is generally not safe to do this for floating-point comparisons, except
for EQ_EXPR, NE_EXPR, ORDERED_EXPR and UNORDERED_EXPR, so we return
ERROR_MARK in this case. */
enum tree_code
invert_tree_comparison (enum tree_code code, bool honor_nans)
{
if (honor_nans && flag_trapping_math && code != EQ_EXPR && code != NE_EXPR
&& code != ORDERED_EXPR && code != UNORDERED_EXPR)
return ERROR_MARK;
switch (code)
{
case EQ_EXPR:
return NE_EXPR;
case NE_EXPR:
return EQ_EXPR;
case GT_EXPR:
return honor_nans ? UNLE_EXPR : LE_EXPR;
case GE_EXPR:
return honor_nans ? UNLT_EXPR : LT_EXPR;
case LT_EXPR:
return honor_nans ? UNGE_EXPR : GE_EXPR;
case LE_EXPR:
return honor_nans ? UNGT_EXPR : GT_EXPR;
case LTGT_EXPR:
return UNEQ_EXPR;
case UNEQ_EXPR:
return LTGT_EXPR;
case UNGT_EXPR:
return LE_EXPR;
case UNGE_EXPR:
return LT_EXPR;
case UNLT_EXPR:
return GE_EXPR;
case UNLE_EXPR:
return GT_EXPR;
case ORDERED_EXPR:
return UNORDERED_EXPR;
case UNORDERED_EXPR:
return ORDERED_EXPR;
default:
gcc_unreachable ();
}
}
/* Similar, but return the comparison that results if the operands are
swapped. This is safe for floating-point. */
enum tree_code
swap_tree_comparison (enum tree_code code)
{
switch (code)
{
case EQ_EXPR:
case NE_EXPR:
case ORDERED_EXPR:
case UNORDERED_EXPR:
case LTGT_EXPR:
case UNEQ_EXPR:
return code;
case GT_EXPR:
return LT_EXPR;
case GE_EXPR:
return LE_EXPR;
case LT_EXPR:
return GT_EXPR;
case LE_EXPR:
return GE_EXPR;
case UNGT_EXPR:
return UNLT_EXPR;
case UNGE_EXPR:
return UNLE_EXPR;
case UNLT_EXPR:
return UNGT_EXPR;
case UNLE_EXPR:
return UNGE_EXPR;
default:
gcc_unreachable ();
}
}
/* Convert a comparison tree code from an enum tree_code representation
into a compcode bit-based encoding. This function is the inverse of
compcode_to_comparison. */
static enum comparison_code
comparison_to_compcode (enum tree_code code)
{
switch (code)
{
case LT_EXPR:
return COMPCODE_LT;
case EQ_EXPR:
return COMPCODE_EQ;
case LE_EXPR:
return COMPCODE_LE;
case GT_EXPR:
return COMPCODE_GT;
case NE_EXPR:
return COMPCODE_NE;
case GE_EXPR:
return COMPCODE_GE;
case ORDERED_EXPR:
return COMPCODE_ORD;
case UNORDERED_EXPR:
return COMPCODE_UNORD;
case UNLT_EXPR:
return COMPCODE_UNLT;
case UNEQ_EXPR:
return COMPCODE_UNEQ;
case UNLE_EXPR:
return COMPCODE_UNLE;
case UNGT_EXPR:
return COMPCODE_UNGT;
case LTGT_EXPR:
return COMPCODE_LTGT;
case UNGE_EXPR:
return COMPCODE_UNGE;
default:
gcc_unreachable ();
}
}
/* Convert a compcode bit-based encoding of a comparison operator back
to GCC's enum tree_code representation. This function is the
inverse of comparison_to_compcode. */
static enum tree_code
compcode_to_comparison (enum comparison_code code)
{
switch (code)
{
case COMPCODE_LT:
return LT_EXPR;
case COMPCODE_EQ:
return EQ_EXPR;
case COMPCODE_LE:
return LE_EXPR;
case COMPCODE_GT:
return GT_EXPR;
case COMPCODE_NE:
return NE_EXPR;
case COMPCODE_GE:
return GE_EXPR;
case COMPCODE_ORD:
return ORDERED_EXPR;
case COMPCODE_UNORD:
return UNORDERED_EXPR;
case COMPCODE_UNLT:
return UNLT_EXPR;
case COMPCODE_UNEQ:
return UNEQ_EXPR;
case COMPCODE_UNLE:
return UNLE_EXPR;
case COMPCODE_UNGT:
return UNGT_EXPR;
case COMPCODE_LTGT:
return LTGT_EXPR;
case COMPCODE_UNGE:
return UNGE_EXPR;
default:
gcc_unreachable ();
}
}
/* Return a tree for the comparison which is the combination of
doing the AND or OR (depending on CODE) of the two operations LCODE
and RCODE on the identical operands LL_ARG and LR_ARG. Take into account
the possibility of trapping if the mode has NaNs, and return NULL_TREE
if this makes the transformation invalid. */
tree
combine_comparisons (location_t loc,
enum tree_code code, enum tree_code lcode,
enum tree_code rcode, tree truth_type,
tree ll_arg, tree lr_arg)
{
bool honor_nans = HONOR_NANS (TYPE_MODE (TREE_TYPE (ll_arg)));
enum comparison_code lcompcode = comparison_to_compcode (lcode);
enum comparison_code rcompcode = comparison_to_compcode (rcode);
int compcode;
switch (code)
{
case TRUTH_AND_EXPR: case TRUTH_ANDIF_EXPR:
compcode = lcompcode & rcompcode;
break;
case TRUTH_OR_EXPR: case TRUTH_ORIF_EXPR:
compcode = lcompcode | rcompcode;
break;
default:
return NULL_TREE;
}
if (!honor_nans)
{
/* Eliminate unordered comparisons, as well as LTGT and ORD
which are not used unless the mode has NaNs. */
compcode &= ~COMPCODE_UNORD;
if (compcode == COMPCODE_LTGT)
compcode = COMPCODE_NE;
else if (compcode == COMPCODE_ORD)
compcode = COMPCODE_TRUE;
}
else if (flag_trapping_math)
{
/* Check that the original operation and the optimized ones will trap
under the same condition. */
bool ltrap = (lcompcode & COMPCODE_UNORD) == 0
&& (lcompcode != COMPCODE_EQ)
&& (lcompcode != COMPCODE_ORD);
bool rtrap = (rcompcode & COMPCODE_UNORD) == 0
&& (rcompcode != COMPCODE_EQ)
&& (rcompcode != COMPCODE_ORD);
bool trap = (compcode & COMPCODE_UNORD) == 0
&& (compcode != COMPCODE_EQ)
&& (compcode != COMPCODE_ORD);
/* In a short-circuited boolean expression the LHS might be
such that the RHS, if evaluated, will never trap. For
example, in ORD (x, y) && (x < y), we evaluate the RHS only
if neither x nor y is NaN. (This is a mixed blessing: for
example, the expression above will never trap, hence
optimizing it to x < y would be invalid). */
if ((code == TRUTH_ORIF_EXPR && (lcompcode & COMPCODE_UNORD))
|| (code == TRUTH_ANDIF_EXPR && !(lcompcode & COMPCODE_UNORD)))
rtrap = false;
/* If the comparison was short-circuited, and only the RHS
trapped, we may now generate a spurious trap. */
if (rtrap && !ltrap
&& (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR))
return NULL_TREE;
/* If we changed the conditions that cause a trap, we lose. */
if ((ltrap || rtrap) != trap)
return NULL_TREE;
}
if (compcode == COMPCODE_TRUE)
return constant_boolean_node (true, truth_type);
else if (compcode == COMPCODE_FALSE)
return constant_boolean_node (false, truth_type);
else
{
enum tree_code tcode;
tcode = compcode_to_comparison ((enum comparison_code) compcode);
return fold_build2_loc (loc, tcode, truth_type, ll_arg, lr_arg);
}
}
/* Return nonzero if two operands (typically of the same tree node)
are necessarily equal. If either argument has side-effects this
function returns zero. FLAGS modifies behavior as follows:
If OEP_ONLY_CONST is set, only return nonzero for constants.
This function tests whether the operands are indistinguishable;
it does not test whether they are equal using C's == operation.
The distinction is important for IEEE floating point, because
(1) -0.0 and 0.0 are distinguishable, but -0.0==0.0, and
(2) two NaNs may be indistinguishable, but NaN!=NaN.
If OEP_ONLY_CONST is unset, a VAR_DECL is considered equal to itself
even though it may hold multiple values during a function.
This is because a GCC tree node guarantees that nothing else is
executed between the evaluation of its "operands" (which may often
be evaluated in arbitrary order). Hence if the operands themselves
don't side-effect, the VAR_DECLs, PARM_DECLs etc... must hold the
same value in each operand/subexpression. Hence leaving OEP_ONLY_CONST
unset means assuming isochronic (or instantaneous) tree equivalence.
Unless comparing arbitrary expression trees, such as from different
statements, this flag can usually be left unset.
If OEP_PURE_SAME is set, then pure functions with identical arguments
are considered the same. It is used when the caller has other ways
to ensure that global memory is unchanged in between. */
int
operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
{
/* If either is ERROR_MARK, they aren't equal. */
if (TREE_CODE (arg0) == ERROR_MARK || TREE_CODE (arg1) == ERROR_MARK
|| TREE_TYPE (arg0) == error_mark_node
|| TREE_TYPE (arg1) == error_mark_node)
return 0;
/* Similar, if either does not have a type (like a released SSA name),
they aren't equal. */
if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
return 0;
/* Check equality of integer constants before bailing out due to
precision differences. */
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
return tree_int_cst_equal (arg0, arg1);
/* If both types don't have the same signedness, then we can't consider
them equal. We must check this before the STRIP_NOPS calls
because they may change the signedness of the arguments. As pointers
strictly don't have a signedness, require either two pointers or
two non-pointers as well. */
if (TYPE_UNSIGNED (TREE_TYPE (arg0)) != TYPE_UNSIGNED (TREE_TYPE (arg1))
|| POINTER_TYPE_P (TREE_TYPE (arg0)) != POINTER_TYPE_P (TREE_TYPE (arg1)))
return 0;
/* We cannot consider pointers to different address space equal. */
if (POINTER_TYPE_P (TREE_TYPE (arg0)) && POINTER_TYPE_P (TREE_TYPE (arg1))
&& (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg0)))
!= TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg1)))))
return 0;
/* If both types don't have the same precision, then it is not safe
to strip NOPs. */
if (TYPE_PRECISION (TREE_TYPE (arg0)) != TYPE_PRECISION (TREE_TYPE (arg1)))
return 0;
STRIP_NOPS (arg0);
STRIP_NOPS (arg1);
/* In case both args are comparisons but with different comparison
code, try to swap the comparison operands of one arg to produce
a match and compare that variant. */
if (TREE_CODE (arg0) != TREE_CODE (arg1)
&& COMPARISON_CLASS_P (arg0)
&& COMPARISON_CLASS_P (arg1))
{
enum tree_code swap_code = swap_tree_comparison (TREE_CODE (arg1));
if (TREE_CODE (arg0) == swap_code)
return operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 1), flags)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 0), flags);
}
if (TREE_CODE (arg0) != TREE_CODE (arg1)
/* This is needed for conversions and for COMPONENT_REF.
Might as well play it safe and always test this. */
|| TREE_CODE (TREE_TYPE (arg0)) == ERROR_MARK
|| TREE_CODE (TREE_TYPE (arg1)) == ERROR_MARK
|| TYPE_MODE (TREE_TYPE (arg0)) != TYPE_MODE (TREE_TYPE (arg1)))
return 0;
/* If ARG0 and ARG1 are the same SAVE_EXPR, they are necessarily equal.
We don't care about side effects in that case because the SAVE_EXPR
takes care of that for us. In all other cases, two expressions are
equal if they have no side effects. If we have two identical
expressions with side effects that should be treated the same due
to the only side effects being identical SAVE_EXPR's, that will
be detected in the recursive calls below.
If we are taking an invariant address of two identical objects
they are necessarily equal as well. */
if (arg0 == arg1 && ! (flags & OEP_ONLY_CONST)
&& (TREE_CODE (arg0) == SAVE_EXPR
|| (flags & OEP_CONSTANT_ADDRESS_OF)
|| (! TREE_SIDE_EFFECTS (arg0) && ! TREE_SIDE_EFFECTS (arg1))))
return 1;
/* Next handle constant cases, those for which we can return 1 even
if ONLY_CONST is set. */
if (TREE_CONSTANT (arg0) && TREE_CONSTANT (arg1))
switch (TREE_CODE (arg0))
{
case INTEGER_CST:
return tree_int_cst_equal (arg0, arg1);
case FIXED_CST:
return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (arg0),
TREE_FIXED_CST (arg1));
case REAL_CST:
if (REAL_VALUES_IDENTICAL (TREE_REAL_CST (arg0),
TREE_REAL_CST (arg1)))
return 1;
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0))))
{
/* If we do not distinguish between signed and unsigned zero,
consider them equal. */
if (real_zerop (arg0) && real_zerop (arg1))
return 1;
}
return 0;
case VECTOR_CST:
{
unsigned i;
if (VECTOR_CST_NELTS (arg0) != VECTOR_CST_NELTS (arg1))
return 0;
for (i = 0; i < VECTOR_CST_NELTS (arg0); ++i)
{
if (!operand_equal_p (VECTOR_CST_ELT (arg0, i),
VECTOR_CST_ELT (arg1, i), flags))
return 0;
}
return 1;
}
case COMPLEX_CST:
return (operand_equal_p (TREE_REALPART (arg0), TREE_REALPART (arg1),
flags)
&& operand_equal_p (TREE_IMAGPART (arg0), TREE_IMAGPART (arg1),
flags));
case STRING_CST:
return (TREE_STRING_LENGTH (arg0) == TREE_STRING_LENGTH (arg1)
&& ! memcmp (TREE_STRING_POINTER (arg0),
TREE_STRING_POINTER (arg1),
TREE_STRING_LENGTH (arg0)));
case ADDR_EXPR:
return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0),
TREE_CONSTANT (arg0) && TREE_CONSTANT (arg1)
? OEP_CONSTANT_ADDRESS_OF : 0);
default:
break;
}
if (flags & OEP_ONLY_CONST)
return 0;
/* Define macros to test an operand from arg0 and arg1 for equality and a
variant that allows null and views null as being different from any
non-null value. In the latter case, if either is null, the both
must be; otherwise, do the normal comparison. */
#define OP_SAME(N) operand_equal_p (TREE_OPERAND (arg0, N), \
TREE_OPERAND (arg1, N), flags)
#define OP_SAME_WITH_NULL(N) \
((!TREE_OPERAND (arg0, N) || !TREE_OPERAND (arg1, N)) \
? TREE_OPERAND (arg0, N) == TREE_OPERAND (arg1, N) : OP_SAME (N))
switch (TREE_CODE_CLASS (TREE_CODE (arg0)))
{
case tcc_unary:
/* Two conversions are equal only if signedness and modes match. */
switch (TREE_CODE (arg0))
{
CASE_CONVERT:
case FIX_TRUNC_EXPR:
if (TYPE_UNSIGNED (TREE_TYPE (arg0))
!= TYPE_UNSIGNED (TREE_TYPE (arg1)))
return 0;
break;
default:
break;
}
return OP_SAME (0);
case tcc_comparison:
case tcc_binary:
if (OP_SAME (0) && OP_SAME (1))
return 1;
/* For commutative ops, allow the other order. */
return (commutative_tree_code (TREE_CODE (arg0))
&& operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 1), flags)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 0), flags));
case tcc_reference:
/* If either of the pointer (or reference) expressions we are
dereferencing contain a side effect, these cannot be equal,
but their addresses can be. */
if ((flags & OEP_CONSTANT_ADDRESS_OF) == 0
&& (TREE_SIDE_EFFECTS (arg0)
|| TREE_SIDE_EFFECTS (arg1)))
return 0;
switch (TREE_CODE (arg0))
{
case INDIRECT_REF:
flags &= ~OEP_CONSTANT_ADDRESS_OF;
return OP_SAME (0);
case REALPART_EXPR:
case IMAGPART_EXPR:
return OP_SAME (0);
case TARGET_MEM_REF:
flags &= ~OEP_CONSTANT_ADDRESS_OF;
/* Require equal extra operands and then fall through to MEM_REF
handling of the two common operands. */
if (!OP_SAME_WITH_NULL (2)
|| !OP_SAME_WITH_NULL (3)
|| !OP_SAME_WITH_NULL (4))
return 0;
/* Fallthru. */
case MEM_REF:
flags &= ~OEP_CONSTANT_ADDRESS_OF;
/* Require equal access sizes, and similar pointer types.
We can have incomplete types for array references of
variable-sized arrays from the Fortran frontent
though. */
return ((TYPE_SIZE (TREE_TYPE (arg0)) == TYPE_SIZE (TREE_TYPE (arg1))
|| (TYPE_SIZE (TREE_TYPE (arg0))
&& TYPE_SIZE (TREE_TYPE (arg1))
&& operand_equal_p (TYPE_SIZE (TREE_TYPE (arg0)),
TYPE_SIZE (TREE_TYPE (arg1)), flags)))
&& (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg0, 1)))
== TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg1, 1))))
&& OP_SAME (0) && OP_SAME (1));
case ARRAY_REF:
case ARRAY_RANGE_REF:
/* Operands 2 and 3 may be null.
Compare the array index by value if it is constant first as we
may have different types but same value here. */
if (!OP_SAME (0))
return 0;
flags &= ~OEP_CONSTANT_ADDRESS_OF;
return ((tree_int_cst_equal (TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 1))
|| OP_SAME (1))
&& OP_SAME_WITH_NULL (2)
&& OP_SAME_WITH_NULL (3));
case COMPONENT_REF:
/* Handle operand 2 the same as for ARRAY_REF. Operand 0
may be NULL when we're called to compare MEM_EXPRs. */
if (!OP_SAME_WITH_NULL (0))
return 0;
flags &= ~OEP_CONSTANT_ADDRESS_OF;
return OP_SAME (1) && OP_SAME_WITH_NULL (2);
case BIT_FIELD_REF:
if (!OP_SAME (0))
return 0;
flags &= ~OEP_CONSTANT_ADDRESS_OF;
return OP_SAME (1) && OP_SAME (2);
default:
return 0;
}
case tcc_expression:
switch (TREE_CODE (arg0))
{
case ADDR_EXPR:
case TRUTH_NOT_EXPR:
return OP_SAME (0);
case TRUTH_ANDIF_EXPR:
case TRUTH_ORIF_EXPR:
return OP_SAME (0) && OP_SAME (1);
case FMA_EXPR:
case WIDEN_MULT_PLUS_EXPR:
case WIDEN_MULT_MINUS_EXPR:
if (!OP_SAME (2))
return 0;
/* The multiplcation operands are commutative. */
/* FALLTHRU */
case TRUTH_AND_EXPR:
case TRUTH_OR_EXPR:
case TRUTH_XOR_EXPR:
if (OP_SAME (0) && OP_SAME (1))
return 1;
/* Otherwise take into account this is a commutative operation. */
return (operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 1), flags)
&& operand_equal_p (TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 0), flags));
case COND_EXPR:
case VEC_COND_EXPR:
case DOT_PROD_EXPR:
return OP_SAME (0) && OP_SAME (1) && OP_SAME (2);
default:
return 0;
}
case tcc_vl_exp:
switch (TREE_CODE (arg0))
{
case CALL_EXPR:
/* If the CALL_EXPRs call different functions, then they
clearly can not be equal. */
if (! operand_equal_p (CALL_EXPR_FN (arg0), CALL_EXPR_FN (arg1),
flags))
return 0;
{
unsigned int cef = call_expr_flags (arg0);
if (flags & OEP_PURE_SAME)
cef &= ECF_CONST | ECF_PURE;
else
cef &= ECF_CONST;
if (!cef)
return 0;
}
/* Now see if all the arguments are the same. */
{
const_call_expr_arg_iterator iter0, iter1;
const_tree a0, a1;
for (a0 = first_const_call_expr_arg (arg0, &iter0),
a1 = first_const_call_expr_arg (arg1, &iter1);
a0 && a1;
a0 = next_const_call_expr_arg (&iter0),
a1 = next_const_call_expr_arg (&iter1))
if (! operand_equal_p (a0, a1, flags))
return 0;
/* If we get here and both argument lists are exhausted
then the CALL_EXPRs are equal. */
return ! (a0 || a1);
}
default:
return 0;
}
case tcc_declaration:
/* Consider __builtin_sqrt equal to sqrt. */
return (TREE_CODE (arg0) == FUNCTION_DECL
&& DECL_BUILT_IN (arg0) && DECL_BUILT_IN (arg1)
&& DECL_BUILT_IN_CLASS (arg0) == DECL_BUILT_IN_CLASS (arg1)
&& DECL_FUNCTION_CODE (arg0) == DECL_FUNCTION_CODE (arg1));
default:
return 0;
}
#undef OP_SAME
#undef OP_SAME_WITH_NULL
}
/* Similar to operand_equal_p, but see if ARG0 might have been made by
shorten_compare from ARG1 when ARG1 was being compared with OTHER.
When in doubt, return 0. */
static int
operand_equal_for_comparison_p (tree arg0, tree arg1, tree other)
{
int unsignedp1, unsignedpo;
tree primarg0, primarg1, primother;
unsigned int correct_width;
if (operand_equal_p (arg0, arg1, 0))
return 1;
if (! INTEGRAL_TYPE_P (TREE_TYPE (arg0))
|| ! INTEGRAL_TYPE_P (TREE_TYPE (arg1)))
return 0;
/* Discard any conversions that don't change the modes of ARG0 and ARG1
and see if the inner values are the same. This removes any
signedness comparison, which doesn't matter here. */
primarg0 = arg0, primarg1 = arg1;
STRIP_NOPS (primarg0);
STRIP_NOPS (primarg1);
if (operand_equal_p (primarg0, primarg1, 0))
return 1;
/* Duplicate what shorten_compare does to ARG1 and see if that gives the
actual comparison operand, ARG0.
First throw away any conversions to wider types
already present in the operands. */
primarg1 = get_narrower (arg1, &unsignedp1);
primother = get_narrower (other, &unsignedpo);
correct_width = TYPE_PRECISION (TREE_TYPE (arg1));
if (unsignedp1 == unsignedpo
&& TYPE_PRECISION (TREE_TYPE (primarg1)) < correct_width
&& TYPE_PRECISION (TREE_TYPE (primother)) < correct_width)
{
tree type = TREE_TYPE (arg0);
/* Make sure shorter operand is extended the right way
to match the longer operand. */
primarg1 = fold_convert (signed_or_unsigned_type_for
(unsignedp1, TREE_TYPE (primarg1)), primarg1);
if (operand_equal_p (arg0, fold_convert (type, primarg1), 0))
return 1;
}
return 0;
}
/* See if ARG is an expression that is either a comparison or is performing
arithmetic on comparisons. The comparisons must only be comparing
two different values, which will be stored in *CVAL1 and *CVAL2; if
they are nonzero it means that some operands have already been found.
No variables may be used anywhere else in the expression except in the
comparisons. If SAVE_P is true it means we removed a SAVE_EXPR around
the expression and save_expr needs to be called with CVAL1 and CVAL2.
If this is true, return 1. Otherwise, return zero. */
static int
twoval_comparison_p (tree arg, tree *cval1, tree *cval2, int *save_p)
{
enum tree_code code = TREE_CODE (arg);
enum tree_code_class tclass = TREE_CODE_CLASS (code);
/* We can handle some of the tcc_expression cases here. */
if (tclass == tcc_expression && code == TRUTH_NOT_EXPR)
tclass = tcc_unary;
else if (tclass == tcc_expression
&& (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR
|| code == COMPOUND_EXPR))
tclass = tcc_binary;
else if (tclass == tcc_expression && code == SAVE_EXPR
&& ! TREE_SIDE_EFFECTS (TREE_OPERAND (arg, 0)))
{
/* If we've already found a CVAL1 or CVAL2, this expression is
two complex to handle. */
if (*cval1 || *cval2)
return 0;
tclass = tcc_unary;
*save_p = 1;
}
switch (tclass)
{
case tcc_unary:
return twoval_comparison_p (TREE_OPERAND (arg, 0), cval1, cval2, save_p);
case tcc_binary:
return (twoval_comparison_p (TREE_OPERAND (arg, 0), cval1, cval2, save_p)
&& twoval_comparison_p (TREE_OPERAND (arg, 1),
cval1, cval2, save_p));
case tcc_constant:
return 1;
case tcc_expression:
if (code == COND_EXPR)
return (twoval_comparison_p (TREE_OPERAND (arg, 0),
cval1, cval2, save_p)
&& twoval_comparison_p (TREE_OPERAND (arg, 1),
cval1, cval2, save_p)
&& twoval_comparison_p (TREE_OPERAND (arg, 2),
cval1, cval2, save_p));
return 0;
case tcc_comparison:
/* First see if we can handle the first operand, then the second. For
the second operand, we know *CVAL1 can't be zero. It must be that
one side of the comparison is each of the values; test for the
case where this isn't true by failing if the two operands
are the same. */
if (operand_equal_p (TREE_OPERAND (arg, 0),
TREE_OPERAND (arg, 1), 0))
return 0;
if (*cval1 == 0)
*cval1 = TREE_OPERAND (arg, 0);
else if (operand_equal_p (*cval1, TREE_OPERAND (arg, 0), 0))
;
else if (*cval2 == 0)
*cval2 = TREE_OPERAND (arg, 0);
else if (operand_equal_p (*cval2, TREE_OPERAND (arg, 0), 0))
;
else
return 0;
if (operand_equal_p (*cval1, TREE_OPERAND (arg, 1), 0))
;
else if (*cval2 == 0)
*cval2 = TREE_OPERAND (arg, 1);
else if (operand_equal_p (*cval2, TREE_OPERAND (arg, 1), 0))
;
else
return 0;
return 1;
default:
return 0;
}
}
/* ARG is a tree that is known to contain just arithmetic operations and
comparisons. Evaluate the operations in the tree substituting NEW0 for
any occurrence of OLD0 as an operand of a comparison and likewise for
NEW1 and OLD1. */
static tree
eval_subst (location_t loc, tree arg, tree old0, tree new0,
tree old1, tree new1)
{
tree type = TREE_TYPE (arg);
enum tree_code code = TREE_CODE (arg);
enum tree_code_class tclass = TREE_CODE_CLASS (code);
/* We can handle some of the tcc_expression cases here. */
if (tclass == tcc_expression && code == TRUTH_NOT_EXPR)
tclass = tcc_unary;
else if (tclass == tcc_expression
&& (code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR))
tclass = tcc_binary;
switch (tclass)
{
case tcc_unary:
return fold_build1_loc (loc, code, type,
eval_subst (loc, TREE_OPERAND (arg, 0),
old0, new0, old1, new1));
case tcc_binary:
return fold_build2_loc (loc, code, type,
eval_subst (loc, TREE_OPERAND (arg, 0),
old0, new0, old1, new1),
eval_subst (loc, TREE_OPERAND (arg, 1),
old0, new0, old1, new1));
case tcc_expression:
switch (code)
{
case SAVE_EXPR:
return eval_subst (loc, TREE_OPERAND (arg, 0), old0, new0,
old1, new1);
case COMPOUND_EXPR:
return eval_subst (loc, TREE_OPERAND (arg, 1), old0, new0,
old1, new1);
case COND_EXPR:
return fold_build3_loc (loc, code, type,
eval_subst (loc, TREE_OPERAND (arg, 0),
old0, new0, old1, new1),
eval_subst (loc, TREE_OPERAND (arg, 1),
old0, new0, old1, new1),
eval_subst (loc, TREE_OPERAND (arg, 2),
old0, new0, old1, new1));
default:
break;
}
/* Fall through - ??? */
case tcc_comparison:
{
tree arg0 = TREE_OPERAND (arg, 0);
tree arg1 = TREE_OPERAND (arg, 1);
/* We need to check both for exact equality and tree equality. The
former will be true if the operand has a side-effect. In that
case, we know the operand occurred exactly once. */
if (arg0 == old0 || operand_equal_p (arg0, old0, 0))
arg0 = new0;
else if (arg0 == old1 || operand_equal_p (arg0, old1, 0))
arg0 = new1;
if (arg1 == old0 || operand_equal_p (arg1, old0, 0))
arg1 = new0;
else if (arg1 == old1 || operand_equal_p (arg1, old1, 0))
arg1 = new1;
return fold_build2_loc (loc, code, type, arg0, arg1);
}
default:
return arg;
}
}
/* Return a tree for the case when the result of an expression is RESULT
converted to TYPE and OMITTED was previously an operand of the expression
but is now not needed (e.g., we folded OMITTED * 0).
If OMITTED has side effects, we must evaluate it. Otherwise, just do
the conversion of RESULT to TYPE. */
tree
omit_one_operand_loc (location_t loc, tree type, tree result, tree omitted)
{
tree t = fold_convert_loc (loc, type, result);
/* If the resulting operand is an empty statement, just return the omitted
statement casted to void. */
if (IS_EMPTY_STMT (t) && TREE_SIDE_EFFECTS (omitted))
return build1_loc (loc, NOP_EXPR, void_type_node,
fold_ignored_result (omitted));
if (TREE_SIDE_EFFECTS (omitted))
return build2_loc (loc, COMPOUND_EXPR, type,
fold_ignored_result (omitted), t);
return non_lvalue_loc (loc, t);
}
/* Similar, but call pedantic_non_lvalue instead of non_lvalue. */
static tree
pedantic_omit_one_operand_loc (location_t loc, tree type, tree result,
tree omitted)
{
tree t = fold_convert_loc (loc, type, result);
/* If the resulting operand is an empty statement, just return the omitted
statement casted to void. */
if (IS_EMPTY_STMT (t) && TREE_SIDE_EFFECTS (omitted))
return build1_loc (loc, NOP_EXPR, void_type_node,
fold_ignored_result (omitted));
if (TREE_SIDE_EFFECTS (omitted))
return build2_loc (loc, COMPOUND_EXPR, type,
fold_ignored_result (omitted), t);
return pedantic_non_lvalue_loc (loc, t);
}
/* Return a tree for the case when the result of an expression is RESULT
converted to TYPE and OMITTED1 and OMITTED2 were previously operands
of the expression but are now not needed.
If OMITTED1 or OMITTED2 has side effects, they must be evaluated.
If both OMITTED1 and OMITTED2 have side effects, OMITTED1 is
evaluated before OMITTED2. Otherwise, if neither has side effects,
just do the conversion of RESULT to TYPE. */
tree
omit_two_operands_loc (location_t loc, tree type, tree result,
tree omitted1, tree omitted2)
{
tree t = fold_convert_loc (loc, type, result);
if (TREE_SIDE_EFFECTS (omitted2))
t = build2_loc (loc, COMPOUND_EXPR, type, omitted2, t);
if (TREE_SIDE_EFFECTS (omitted1))
t = build2_loc (loc, COMPOUND_EXPR, type, omitted1, t);
return TREE_CODE (t) != COMPOUND_EXPR ? non_lvalue_loc (loc, t) : t;
}
/* Return a simplified tree node for the truth-negation of ARG. This
never alters ARG itself. We assume that ARG is an operation that
returns a truth value (0 or 1).
FIXME: one would think we would fold the result, but it causes
problems with the dominator optimizer. */
tree
fold_truth_not_expr (location_t loc, tree arg)
{
tree type = TREE_TYPE (arg);
enum tree_code code = TREE_CODE (arg);
location_t loc1, loc2;
/* If this is a comparison, we can simply invert it, except for
floating-point non-equality comparisons, in which case we just
enclose a TRUTH_NOT_EXPR around what we have. */
if (TREE_CODE_CLASS (code) == tcc_comparison)
{
tree op_type = TREE_TYPE (TREE_OPERAND (arg, 0));
if (FLOAT_TYPE_P (op_type)
&& flag_trapping_math
&& code != ORDERED_EXPR && code != UNORDERED_EXPR
&& code != NE_EXPR && code != EQ_EXPR)
return NULL_TREE;
code = invert_tree_comparison (code, HONOR_NANS (TYPE_MODE (op_type)));
if (code == ERROR_MARK)
return NULL_TREE;
return build2_loc (loc, code, type, TREE_OPERAND (arg, 0),
TREE_OPERAND (arg, 1));
}
switch (code)
{
case INTEGER_CST:
return constant_boolean_node (integer_zerop (arg), type);
case TRUTH_AND_EXPR:
loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc);
return build2_loc (loc, TRUTH_OR_EXPR, type,
invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)),
invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1)));
case TRUTH_OR_EXPR:
loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc);
return build2_loc (loc, TRUTH_AND_EXPR, type,
invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)),
invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1)));
case TRUTH_XOR_EXPR:
/* Here we can invert either operand. We invert the first operand
unless the second operand is a TRUTH_NOT_EXPR in which case our
result is the XOR of the first operand with the inside of the
negation of the second operand. */
if (TREE_CODE (TREE_OPERAND (arg, 1)) == TRUTH_NOT_EXPR)
return build2_loc (loc, TRUTH_XOR_EXPR, type, TREE_OPERAND (arg, 0),
TREE_OPERAND (TREE_OPERAND (arg, 1), 0));
else
return build2_loc (loc, TRUTH_XOR_EXPR, type,
invert_truthvalue_loc (loc, TREE_OPERAND (arg, 0)),
TREE_OPERAND (arg, 1));
case TRUTH_ANDIF_EXPR:
loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc);
return build2_loc (loc, TRUTH_ORIF_EXPR, type,
invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)),
invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1)));
case TRUTH_ORIF_EXPR:
loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
loc2 = expr_location_or (TREE_OPERAND (arg, 1), loc);
return build2_loc (loc, TRUTH_ANDIF_EXPR, type,
invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)),
invert_truthvalue_loc (loc2, TREE_OPERAND (arg, 1)));
case TRUTH_NOT_EXPR:
return TREE_OPERAND (arg, 0);
case COND_EXPR:
{
tree arg1 = TREE_OPERAND (arg, 1);
tree arg2 = TREE_OPERAND (arg, 2);
loc1 = expr_location_or (TREE_OPERAND (arg, 1), loc);
loc2 = expr_location_or (TREE_OPERAND (arg, 2), loc);
/* A COND_EXPR may have a throw as one operand, which
then has void type. Just leave void operands
as they are. */
return build3_loc (loc, COND_EXPR, type, TREE_OPERAND (arg, 0),
VOID_TYPE_P (TREE_TYPE (arg1))
? arg1 : invert_truthvalue_loc (loc1, arg1),
VOID_TYPE_P (TREE_TYPE (arg2))
? arg2 : invert_truthvalue_loc (loc2, arg2));
}
case COMPOUND_EXPR:
loc1 = expr_location_or (TREE_OPERAND (arg, 1), loc);
return build2_loc (loc, COMPOUND_EXPR, type,
TREE_OPERAND (arg, 0),
invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 1)));
case NON_LVALUE_EXPR:
loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
return invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0));
CASE_CONVERT:
if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
return build1_loc (loc, TRUTH_NOT_EXPR, type, arg);
/* ... fall through ... */
case FLOAT_EXPR:
loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
return build1_loc (loc, TREE_CODE (arg), type,
invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)));
case BIT_AND_EXPR:
if (!integer_onep (TREE_OPERAND (arg, 1)))
return NULL_TREE;
return build2_loc (loc, EQ_EXPR, type, arg, build_int_cst (type, 0));
case SAVE_EXPR:
return build1_loc (loc, TRUTH_NOT_EXPR, type, arg);
case CLEANUP_POINT_EXPR:
loc1 = expr_location_or (TREE_OPERAND (arg, 0), loc);
return build1_loc (loc, CLEANUP_POINT_EXPR, type,
invert_truthvalue_loc (loc1, TREE_OPERAND (arg, 0)));
default:
return NULL_TREE;
}
}
/* Return a simplified tree node for the truth-negation of ARG. This
never alters ARG itself. We assume that ARG is an operation that
returns a truth value (0 or 1).
FIXME: one would think we would fold the result, but it causes
problems with the dominator optimizer. */
tree
invert_truthvalue_loc (location_t loc, tree arg)
{
tree tem;
if (TREE_CODE (arg) == ERROR_MARK)
return arg;
tem = fold_truth_not_expr (loc, arg);
if (!tem)
tem = build1_loc (loc, TRUTH_NOT_EXPR, TREE_TYPE (arg), arg);
return tem;
}
/* Given a bit-wise operation CODE applied to ARG0 and ARG1, see if both
operands are another bit-wise operation with a common input. If so,
distribute the bit operations to save an operation and possibly two if
constants are involved. For example, convert
(A | B) & (A | C) into A | (B & C)
Further simplification will occur if B and C are constants.
If this optimization cannot be done, 0 will be returned. */
static tree
distribute_bit_expr (location_t loc, enum tree_code code, tree type,
tree arg0, tree arg1)
{
tree common;
tree left, right;
if (TREE_CODE (arg0) != TREE_CODE (arg1)
|| TREE_CODE (arg0) == code
|| (TREE_CODE (arg0) != BIT_AND_EXPR
&& TREE_CODE (arg0) != BIT_IOR_EXPR))
return 0;
if (operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0), 0))
{
common = TREE_OPERAND (arg0, 0);
left = TREE_OPERAND (arg0, 1);
right = TREE_OPERAND (arg1, 1);
}
else if (operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 1), 0))
{
common = TREE_OPERAND (arg0, 0);
left = TREE_OPERAND (arg0, 1);
right = TREE_OPERAND (arg1, 0);
}
else if (operand_equal_p (TREE_OPERAND (arg0, 1), TREE_OPERAND (arg1, 0), 0))
{
common = TREE_OPERAND (arg0, 1);
left = TREE_OPERAND (arg0, 0);
right = TREE_OPERAND (arg1, 1);
}
else if (operand_equal_p (TREE_OPERAND (arg0, 1), TREE_OPERAND (arg1, 1), 0))
{
common = TREE_OPERAND (arg0, 1);
left = TREE_OPERAND (arg0, 0);
right = TREE_OPERAND (arg1, 0);
}
else
return 0;
common = fold_convert_loc (loc, type, common);
left = fold_convert_loc (loc, type, left);
right = fold_convert_loc (loc, type, right);
return fold_build2_loc (loc, TREE_CODE (arg0), type, common,
fold_build2_loc (loc, code, type, left, right));
}
/* Knowing that ARG0 and ARG1 are both RDIV_EXPRs, simplify a binary operation
with code CODE. This optimization is unsafe. */
static tree
distribute_real_division (location_t loc, enum tree_code code, tree type,
tree arg0, tree arg1)
{
bool mul0 = TREE_CODE (arg0) == MULT_EXPR;
bool mul1 = TREE_CODE (arg1) == MULT_EXPR;
/* (A / C) +- (B / C) -> (A +- B) / C. */
if (mul0 == mul1
&& operand_equal_p (TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 1), 0))
return fold_build2_loc (loc, mul0 ? MULT_EXPR : RDIV_EXPR, type,
fold_build2_loc (loc, code, type,
TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0)),
TREE_OPERAND (arg0, 1));
/* (A / C1) +- (A / C2) -> A * (1 / C1 +- 1 / C2). */
if (operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0), 0)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == REAL_CST
&& TREE_CODE (TREE_OPERAND (arg1, 1)) == REAL_CST)
{
REAL_VALUE_TYPE r0, r1;
r0 = TREE_REAL_CST (TREE_OPERAND (arg0, 1));
r1 = TREE_REAL_CST (TREE_OPERAND (arg1, 1));
if (!mul0)
real_arithmetic (&r0, RDIV_EXPR, &dconst1, &r0);
if (!mul1)
real_arithmetic (&r1, RDIV_EXPR, &dconst1, &r1);
real_arithmetic (&r0, code, &r0, &r1);
return fold_build2_loc (loc, MULT_EXPR, type,
TREE_OPERAND (arg0, 0),
build_real (type, r0));
}
return NULL_TREE;
}
/* Return a BIT_FIELD_REF of type TYPE to refer to BITSIZE bits of INNER
starting at BITPOS. The field is unsigned if UNSIGNEDP is nonzero. */
static tree
make_bit_field_ref (location_t loc, tree inner, tree type,
HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos, int unsignedp)
{
tree result, bftype;
if (bitpos == 0)
{
tree size = TYPE_SIZE (TREE_TYPE (inner));
if ((INTEGRAL_TYPE_P (TREE_TYPE (inner))
|| POINTER_TYPE_P (TREE_TYPE (inner)))
&& host_integerp (size, 0)
&& tree_low_cst (size, 0) == bitsize)
return fold_convert_loc (loc, type, inner);
}
bftype = type;
if (TYPE_PRECISION (bftype) != bitsize
|| TYPE_UNSIGNED (bftype) == !unsignedp)
bftype = build_nonstandard_integer_type (bitsize, 0);
result = build3_loc (loc, BIT_FIELD_REF, bftype, inner,
size_int (bitsize), bitsize_int (bitpos));
if (bftype != type)
result = fold_convert_loc (loc, type, result);
return result;
}
/* Optimize a bit-field compare.
There are two cases: First is a compare against a constant and the
second is a comparison of two items where the fields are at the same
bit position relative to the start of a chunk (byte, halfword, word)
large enough to contain it. In these cases we can avoid the shift
implicit in bitfield extractions.
For constants, we emit a compare of the shifted constant with the
BIT_AND_EXPR of a mask and a byte, halfword, or word of the operand being
compared. For two fields at the same position, we do the ANDs with the
similar mask and compare the result of the ANDs.
CODE is the comparison code, known to be either NE_EXPR or EQ_EXPR.
COMPARE_TYPE is the type of the comparison, and LHS and RHS
are the left and right operands of the comparison, respectively.
If the optimization described above can be done, we return the resulting
tree. Otherwise we return zero. */
static tree
optimize_bit_field_compare (location_t loc, enum tree_code code,
tree compare_type, tree lhs, tree rhs)
{
HOST_WIDE_INT lbitpos, lbitsize, rbitpos, rbitsize, nbitpos, nbitsize;
tree type = TREE_TYPE (lhs);
tree signed_type, unsigned_type;
int const_p = TREE_CODE (rhs) == INTEGER_CST;
enum machine_mode lmode, rmode, nmode;
int lunsignedp, runsignedp;
int lvolatilep = 0, rvolatilep = 0;
tree linner, rinner = NULL_TREE;
tree mask;
tree offset;
/* In the strict volatile bitfields case, doing code changes here may prevent
other optimizations, in particular in a SLOW_BYTE_ACCESS setting. */
if (flag_strict_volatile_bitfields > 0)
return 0;
/* Get all the information about the extractions being done. If the bit size
if the same as the size of the underlying object, we aren't doing an
extraction at all and so can do nothing. We also don't want to
do anything if the inner expression is a PLACEHOLDER_EXPR since we
then will no longer be able to replace it. */
linner = get_inner_reference (lhs, &lbitsize, &lbitpos, &offset, &lmode,
&lunsignedp, &lvolatilep, false);
if (linner == lhs || lbitsize == GET_MODE_BITSIZE (lmode) || lbitsize < 0
|| offset != 0 || TREE_CODE (linner) == PLACEHOLDER_EXPR)
return 0;
if (!const_p)
{
/* If this is not a constant, we can only do something if bit positions,
sizes, and signedness are the same. */
rinner = get_inner_reference (rhs, &rbitsize, &rbitpos, &offset, &rmode,
&runsignedp, &rvolatilep, false);
if (rinner == rhs || lbitpos != rbitpos || lbitsize != rbitsize
|| lunsignedp != runsignedp || offset != 0
|| TREE_CODE (rinner) == PLACEHOLDER_EXPR)
return 0;
}
/* See if we can find a mode to refer to this field. We should be able to,
but fail if we can't. */
if (lvolatilep
&& GET_MODE_BITSIZE (lmode) > 0
&& flag_strict_volatile_bitfields > 0)
nmode = lmode;
else
nmode = get_best_mode (lbitsize, lbitpos, 0, 0,
const_p ? TYPE_ALIGN (TREE_TYPE (linner))
: MIN (TYPE_ALIGN (TREE_TYPE (linner)),
TYPE_ALIGN (TREE_TYPE (rinner))),
word_mode, lvolatilep || rvolatilep);
if (nmode == VOIDmode)
return 0;
/* Set signed and unsigned types of the precision of this mode for the
shifts below. */
signed_type = lang_hooks.types.type_for_mode (nmode, 0);
unsigned_type = lang_hooks.types.type_for_mode (nmode, 1);
/* Compute the bit position and size for the new reference and our offset
within it. If the new reference is the same size as the original, we
won't optimize anything, so return zero. */
nbitsize = GET_MODE_BITSIZE (nmode);
nbitpos = lbitpos & ~ (nbitsize - 1);
lbitpos -= nbitpos;
if (nbitsize == lbitsize)
return 0;
if (BYTES_BIG_ENDIAN)
lbitpos = nbitsize - lbitsize - lbitpos;
/* Make the mask to be used against the extracted field. */
mask = build_int_cst_type (unsigned_type, -1);
mask = const_binop (LSHIFT_EXPR, mask, size_int (nbitsize - lbitsize));
mask = const_binop (RSHIFT_EXPR, mask,
size_int (nbitsize - lbitsize - lbitpos));
if (! const_p)
/* If not comparing with constant, just rework the comparison
and return. */
return fold_build2_loc (loc, code, compare_type,
fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type,
make_bit_field_ref (loc, linner,
unsigned_type,
nbitsize, nbitpos,
1),
mask),
fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type,
make_bit_field_ref (loc, rinner,
unsigned_type,
nbitsize, nbitpos,
1),
mask));
/* Otherwise, we are handling the constant case. See if the constant is too
big for the field. Warn and return a tree of for 0 (false) if so. We do
this not only for its own sake, but to avoid having to test for this
error case below. If we didn't, we might generate wrong code.
For unsigned fields, the constant shifted right by the field length should
be all zero. For signed fields, the high-order bits should agree with
the sign bit. */
if (lunsignedp)
{
if (! integer_zerop (const_binop (RSHIFT_EXPR,
fold_convert_loc (loc,
unsigned_type, rhs),
size_int (lbitsize))))
{
warning (0, "comparison is always %d due to width of bit-field",
code == NE_EXPR);
return constant_boolean_node (code == NE_EXPR, compare_type);
}
}
else
{
tree tem = const_binop (RSHIFT_EXPR,
fold_convert_loc (loc, signed_type, rhs),
size_int (lbitsize - 1));
if (! integer_zerop (tem) && ! integer_all_onesp (tem))
{
warning (0, "comparison is always %d due to width of bit-field",
code == NE_EXPR);
return constant_boolean_node (code == NE_EXPR, compare_type);
}
}
/* Single-bit compares should always be against zero. */
if (lbitsize == 1 && ! integer_zerop (rhs))
{
code = code == EQ_EXPR ? NE_EXPR : EQ_EXPR;
rhs = build_int_cst (type, 0);
}
/* Make a new bitfield reference, shift the constant over the
appropriate number of bits and mask it with the computed mask
(in case this was a signed field). If we changed it, make a new one. */
lhs = make_bit_field_ref (loc, linner, unsigned_type, nbitsize, nbitpos, 1);
if (lvolatilep)
{
TREE_SIDE_EFFECTS (lhs) = 1;
TREE_THIS_VOLATILE (lhs) = 1;
}
rhs = const_binop (BIT_AND_EXPR,
const_binop (LSHIFT_EXPR,
fold_convert_loc (loc, unsigned_type, rhs),
size_int (lbitpos)),
mask);
lhs = build2_loc (loc, code, compare_type,
build2 (BIT_AND_EXPR, unsigned_type, lhs, mask), rhs);
return lhs;
}
/* Subroutine for fold_truth_andor_1: decode a field reference.
If EXP is a comparison reference, we return the innermost reference.
*PBITSIZE is set to the number of bits in the reference, *PBITPOS is
set to the starting bit number.
If the innermost field can be completely contained in a mode-sized
unit, *PMODE is set to that mode. Otherwise, it is set to VOIDmode.
*PVOLATILEP is set to 1 if the any expression encountered is volatile;
otherwise it is not changed.
*PUNSIGNEDP is set to the signedness of the field.
*PMASK is set to the mask used. This is either contained in a
BIT_AND_EXPR or derived from the width of the field.
*PAND_MASK is set to the mask found in a BIT_AND_EXPR, if any.
Return 0 if this is not a component reference or is one that we can't
do anything with. */
static tree
decode_field_reference (location_t loc, tree exp, HOST_WIDE_INT *pbitsize,
HOST_WIDE_INT *pbitpos, enum machine_mode *pmode,
int *punsignedp, int *pvolatilep,
tree *pmask, tree *pand_mask)
{
tree outer_type = 0;
tree and_mask = 0;
tree mask, inner, offset;
tree unsigned_type;
unsigned int precision;
/* All the optimizations using this function assume integer fields.
There are problems with FP fields since the type_for_size call
below can fail for, e.g., XFmode. */
if (! INTEGRAL_TYPE_P (TREE_TYPE (exp)))
return 0;
/* We are interested in the bare arrangement of bits, so strip everything
that doesn't affect the machine mode. However, record the type of the
outermost expression if it may matter below. */
if (CONVERT_EXPR_P (exp)
|| TREE_CODE (exp) == NON_LVALUE_EXPR)
outer_type = TREE_TYPE (exp);
STRIP_NOPS (exp);
if (TREE_CODE (exp) == BIT_AND_EXPR)
{
and_mask = TREE_OPERAND (exp, 1);
exp = TREE_OPERAND (exp, 0);
STRIP_NOPS (exp); STRIP_NOPS (and_mask);
if (TREE_CODE (and_mask) != INTEGER_CST)
return 0;
}
inner = get_inner_reference (exp, pbitsize, pbitpos, &offset, pmode,
punsignedp, pvolatilep, false);
if ((inner == exp && and_mask == 0)
|| *pbitsize < 0 || offset != 0
|| TREE_CODE (inner) == PLACEHOLDER_EXPR)
return 0;
/* If the number of bits in the reference is the same as the bitsize of
the outer type, then the outer type gives the signedness. Otherwise
(in case of a small bitfield) the signedness is unchanged. */
if (outer_type && *pbitsize == TYPE_PRECISION (outer_type))
*punsignedp = TYPE_UNSIGNED (outer_type);
/* Compute the mask to access the bitfield. */
unsigned_type = lang_hooks.types.type_for_size (*pbitsize, 1);
precision = TYPE_PRECISION (unsigned_type);
mask = build_int_cst_type (unsigned_type, -1);
mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize));
mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize));
/* Merge it with the mask we found in the BIT_AND_EXPR, if any. */
if (and_mask != 0)
mask = fold_build2_loc (loc, BIT_AND_EXPR, unsigned_type,
fold_convert_loc (loc, unsigned_type, and_mask), mask);
*pmask = mask;
*pand_mask = and_mask;
return inner;
}
/* Return nonzero if MASK represents a mask of SIZE ones in the low-order
bit positions. */
static int
all_ones_mask_p (const_tree mask, int size)
{
tree type = TREE_TYPE (mask);
unsigned int precision = TYPE_PRECISION (type);
tree tmask;
tmask = build_int_cst_type (signed_type_for (type), -1);
return
tree_int_cst_equal (mask,
const_binop (RSHIFT_EXPR,
const_binop (LSHIFT_EXPR, tmask,
size_int (precision - size)),
size_int (precision - size)));
}
/* Subroutine for fold: determine if VAL is the INTEGER_CONST that
represents the sign bit of EXP's type. If EXP represents a sign
or zero extension, also test VAL against the unextended type.
The return value is the (sub)expression whose sign bit is VAL,
or NULL_TREE otherwise. */
static tree
sign_bit_p (tree exp, const_tree val)
{
unsigned HOST_WIDE_INT mask_lo, lo;
HOST_WIDE_INT mask_hi, hi;
int width;
tree t;
/* Tree EXP must have an integral type. */
t = TREE_TYPE (exp);
if (! INTEGRAL_TYPE_P (t))
return NULL_TREE;
/* Tree VAL must be an integer constant. */
if (TREE_CODE (val) != INTEGER_CST
|| TREE_OVERFLOW (val))
return NULL_TREE;
width = TYPE_PRECISION (t);
if (width > HOST_BITS_PER_WIDE_INT)
{
hi = (unsigned HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT - 1);
lo = 0;
mask_hi = ((unsigned HOST_WIDE_INT) -1
>> (HOST_BITS_PER_DOUBLE_INT - width));
mask_lo = -1;
}
else
{
hi = 0;
lo = (unsigned HOST_WIDE_INT) 1 << (width - 1);
mask_hi = 0;
mask_lo = ((unsigned HOST_WIDE_INT) -1
>> (HOST_BITS_PER_WIDE_INT - width));
}
/* We mask off those bits beyond TREE_TYPE (exp) so that we can
treat VAL as if it were unsigned. */
if ((TREE_INT_CST_HIGH (val) & mask_hi) == hi
&& (TREE_INT_CST_LOW (val) & mask_lo) == lo)
return exp;
/* Handle extension from a narrower type. */
if (TREE_CODE (exp) == NOP_EXPR
&& TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0))) < width)
return sign_bit_p (TREE_OPERAND (exp, 0), val);
return NULL_TREE;
}
/* Subroutine for fold_truth_andor_1: determine if an operand is simple enough
to be evaluated unconditionally. */
static int
simple_operand_p (const_tree exp)
{
/* Strip any conversions that don't change the machine mode. */
STRIP_NOPS (exp);
return (CONSTANT_CLASS_P (exp)
|| TREE_CODE (exp) == SSA_NAME
|| (DECL_P (exp)
&& ! TREE_ADDRESSABLE (exp)
&& ! TREE_THIS_VOLATILE (exp)
&& ! DECL_NONLOCAL (exp)
/* Don't regard global variables as simple. They may be
allocated in ways unknown to the compiler (shared memory,
#pragma weak, etc). */
&& ! TREE_PUBLIC (exp)
&& ! DECL_EXTERNAL (exp)
/* Loading a static variable is unduly expensive, but global
registers aren't expensive. */
&& (! TREE_STATIC (exp) || DECL_REGISTER (exp))));
}
/* Subroutine for fold_truth_andor: determine if an operand is simple enough
to be evaluated unconditionally.
I addition to simple_operand_p, we assume that comparisons, conversions,
and logic-not operations are simple, if their operands are simple, too. */
static bool
simple_operand_p_2 (tree exp)
{
enum tree_code code;
if (TREE_SIDE_EFFECTS (exp)
|| tree_could_trap_p (exp))
return false;
while (CONVERT_EXPR_P (exp))
exp = TREE_OPERAND (exp, 0);
code = TREE_CODE (exp);
if (TREE_CODE_CLASS (code) == tcc_comparison)
return (simple_operand_p (TREE_OPERAND (exp, 0))
&& simple_operand_p (TREE_OPERAND (exp, 1)));
if (code == TRUTH_NOT_EXPR)
return simple_operand_p_2 (TREE_OPERAND (exp, 0));
return simple_operand_p (exp);
}
/* The following functions are subroutines to fold_range_test and allow it to
try to change a logical combination of comparisons into a range test.
For example, both
X == 2 || X == 3 || X == 4 || X == 5
and
X >= 2 && X <= 5
are converted to
(unsigned) (X - 2) <= 3
We describe each set of comparisons as being either inside or outside
a range, using a variable named like IN_P, and then describe the
range with a lower and upper bound. If one of the bounds is omitted,
it represents either the highest or lowest value of the type.
In the comments below, we represent a range by two numbers in brackets
preceded by a "+" to designate being inside that range, or a "-" to
designate being outside that range, so the condition can be inverted by
flipping the prefix. An omitted bound is represented by a "-". For
example, "- [-, 10]" means being outside the range starting at the lowest
possible value and ending at 10, in other words, being greater than 10.
The range "+ [-, -]" is always true and hence the range "- [-, -]" is
always false.
We set up things so that the missing bounds are handled in a consistent
manner so neither a missing bound nor "true" and "false" need to be
handled using a special case. */
/* Return the result of applying CODE to ARG0 and ARG1, but handle the case
of ARG0 and/or ARG1 being omitted, meaning an unlimited range. UPPER0_P
and UPPER1_P are nonzero if the respective argument is an upper bound
and zero for a lower. TYPE, if nonzero, is the type of the result; it
must be specified for a comparison. ARG1 will be converted to ARG0's
type if both are specified. */
static tree
range_binop (enum tree_code code, tree type, tree arg0, int upper0_p,
tree arg1, int upper1_p)
{
tree tem;
int result;
int sgn0, sgn1;
/* If neither arg represents infinity, do the normal operation.
Else, if not a comparison, return infinity. Else handle the special
comparison rules. Note that most of the cases below won't occur, but
are handled for consistency. */
if (arg0 != 0 && arg1 != 0)
{
tem = fold_build2 (code, type != 0 ? type : TREE_TYPE (arg0),
arg0, fold_convert (TREE_TYPE (arg0), arg1));
STRIP_NOPS (tem);
return TREE_CODE (tem) == INTEGER_CST ? tem : 0;
}
if (TREE_CODE_CLASS (code) != tcc_comparison)
return 0;
/* Set SGN[01] to -1 if ARG[01] is a lower bound, 1 for upper, and 0
for neither. In real maths, we cannot assume open ended ranges are
the same. But, this is computer arithmetic, where numbers are finite.
We can therefore make the transformation of any unbounded range with
the value Z, Z being greater than any representable number. This permits
us to treat unbounded ranges as equal. */
sgn0 = arg0 != 0 ? 0 : (upper0_p ? 1 : -1);
sgn1 = arg1 != 0 ? 0 : (upper1_p ? 1 : -1);
switch (code)
{
case EQ_EXPR:
result = sgn0 == sgn1;
break;
case NE_EXPR:
result = sgn0 != sgn1;
break;
case LT_EXPR:
result = sgn0 < sgn1;
break;
case LE_EXPR:
result = sgn0 <= sgn1;
break;
case GT_EXPR:
result = sgn0 > sgn1;
break;
case GE_EXPR:
result = sgn0 >= sgn1;
break;
default:
gcc_unreachable ();
}
return constant_boolean_node (result, type);
}
/* Helper routine for make_range. Perform one step for it, return
new expression if the loop should continue or NULL_TREE if it should
stop. */
tree
make_range_step (location_t loc, enum tree_code code, tree arg0, tree arg1,
tree exp_type, tree *p_low, tree *p_high, int *p_in_p,
bool *strict_overflow_p)
{
tree arg0_type = TREE_TYPE (arg0);
tree n_low, n_high, low = *p_low, high = *p_high;
int in_p = *p_in_p, n_in_p;
switch (code)
{
case TRUTH_NOT_EXPR:
/* We can only do something if the range is testing for zero. */
if (low == NULL_TREE || high == NULL_TREE
|| ! integer_zerop (low) || ! integer_zerop (high))
return NULL_TREE;
*p_in_p = ! in_p;
return arg0;
case EQ_EXPR: case NE_EXPR:
case LT_EXPR: case LE_EXPR: case GE_EXPR: case GT_EXPR:
/* We can only do something if the range is testing for zero
and if the second operand is an integer constant. Note that
saying something is "in" the range we make is done by
complementing IN_P since it will set in the initial case of
being not equal to zero; "out" is leaving it alone. */
if (low == NULL_TREE || high == NULL_TREE
|| ! integer_zerop (low) || ! integer_zerop (high)
|| TREE_CODE (arg1) != INTEGER_CST)
return NULL_TREE;
switch (code)
{
case NE_EXPR: /* - [c, c] */
low = high = arg1;
break;
case EQ_EXPR: /* + [c, c] */
in_p = ! in_p, low = high = arg1;
break;
case GT_EXPR: /* - [-, c] */
low = 0, high = arg1;
break;
case GE_EXPR: /* + [c, -] */
in_p = ! in_p, low = arg1, high = 0;
break;
case LT_EXPR: /* - [c, -] */
low = arg1, high = 0;
break;
case LE_EXPR: /* + [-, c] */
in_p = ! in_p, low = 0, high = arg1;
break;
default:
gcc_unreachable ();
}
/* If this is an unsigned comparison, we also know that EXP is
greater than or equal to zero. We base the range tests we make
on that fact, so we record it here so we can parse existing
range tests. We test arg0_type since often the return type
of, e.g. EQ_EXPR, is boolean. */
if (TYPE_UNSIGNED (arg0_type) && (low == 0 || high == 0))
{
if (! merge_ranges (&n_in_p, &n_low, &n_high,
in_p, low, high, 1,
build_int_cst (arg0_type, 0),
NULL_TREE))
return NULL_TREE;
in_p = n_in_p, low = n_low, high = n_high;
/* If the high bound is missing, but we have a nonzero low
bound, reverse the range so it goes from zero to the low bound
minus 1. */
if (high == 0 && low && ! integer_zerop (low))
{
in_p = ! in_p;
high = range_binop (MINUS_EXPR, NULL_TREE, low, 0,
integer_one_node, 0);
low = build_int_cst (arg0_type, 0);
}
}
*p_low = low;
*p_high = high;
*p_in_p = in_p;
return arg0;
case NEGATE_EXPR:
/* If flag_wrapv and ARG0_TYPE is signed, make sure
low and high are non-NULL, then normalize will DTRT. */
if (!TYPE_UNSIGNED (arg0_type)
&& !TYPE_OVERFLOW_UNDEFINED (arg0_type))
{
if (low == NULL_TREE)
low = TYPE_MIN_VALUE (arg0_type);
if (high == NULL_TREE)
high = TYPE_MAX_VALUE (arg0_type);
}
/* (-x) IN [a,b] -> x in [-b, -a] */
n_low = range_binop (MINUS_EXPR, exp_type,
build_int_cst (exp_type, 0),
0, high, 1);
n_high = range_binop (MINUS_EXPR, exp_type,
build_int_cst (exp_type, 0),
0, low, 0);
if (n_high != 0 && TREE_OVERFLOW (n_high))
return NULL_TREE;
goto normalize;
case BIT_NOT_EXPR:
/* ~ X -> -X - 1 */
return build2_loc (loc, MINUS_EXPR, exp_type, negate_expr (arg0),
build_int_cst (exp_type, 1));
case PLUS_EXPR:
case MINUS_EXPR:
if (TREE_CODE (arg1) != INTEGER_CST)
return NULL_TREE;
/* If flag_wrapv and ARG0_TYPE is signed, then we cannot
move a constant to the other side. */
if (!TYPE_UNSIGNED (arg0_type)
&& !TYPE_OVERFLOW_UNDEFINED (arg0_type))
return NULL_TREE;
/* If EXP is signed, any overflow in the computation is undefined,
so we don't worry about it so long as our computations on
the bounds don't overflow. For unsigned, overflow is defined
and this is exactly the right thing. */
n_low = range_binop (code == MINUS_EXPR ? PLUS_EXPR : MINUS_EXPR,
arg0_type, low, 0, arg1, 0);
n_high = range_binop (code == MINUS_EXPR ? PLUS_EXPR : MINUS_EXPR,
arg0_type, high, 1, arg1, 0);
if ((n_low != 0 && TREE_OVERFLOW (n_low))
|| (n_high != 0 && TREE_OVERFLOW (n_high)))
return NULL_TREE;
if (TYPE_OVERFLOW_UNDEFINED (arg0_type))
*strict_overflow_p = true;
normalize:
/* Check for an unsigned range which has wrapped around the maximum
value thus making n_high < n_low, and normalize it. */
if (n_low && n_high && tree_int_cst_lt (n_high, n_low))
{
low = range_binop (PLUS_EXPR, arg0_type, n_high, 0,
integer_one_node, 0);
high = range_binop (MINUS_EXPR, arg0_type, n_low, 0,
integer_one_node, 0);
/* If the range is of the form +/- [ x+1, x ], we won't
be able to normalize it. But then, it represents the
whole range or the empty set, so make it
+/- [ -, - ]. */
if (tree_int_cst_equal (n_low, low)
&& tree_int_cst_equal (n_high, high))
low = high = 0;
else
in_p = ! in_p;
}
else
low = n_low, high = n_high;
*p_low = low;
*p_high = high;
*p_in_p = in_p;
return arg0;
CASE_CONVERT:
case NON_LVALUE_EXPR:
if (TYPE_PRECISION (arg0_type) > TYPE_PRECISION (exp_type))
return NULL_TREE;
if (! INTEGRAL_TYPE_P (arg0_type)
|| (low != 0 && ! int_fits_type_p (low, arg0_type))
|| (high != 0 && ! int_fits_type_p (high, arg0_type)))
return NULL_TREE;
n_low = low, n_high = high;
if (n_low != 0)
n_low = fold_convert_loc (loc, arg0_type, n_low);
if (n_high != 0)
n_high = fold_convert_loc (loc, arg0_type, n_high);
/* If we're converting arg0 from an unsigned type, to exp,
a signed type, we will be doing the comparison as unsigned.
The tests above have already verified that LOW and HIGH
are both positive.
So we have to ensure that we will handle large unsigned
values the same way that the current signed bounds treat
negative values. */
if (!TYPE_UNSIGNED (exp_type) && TYPE_UNSIGNED (arg0_type))
{
tree high_positive;
tree equiv_type;
/* For fixed-point modes, we need to pass the saturating flag
as the 2nd parameter. */
if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (arg0_type)))
equiv_type
= lang_hooks.types.type_for_mode (TYPE_MODE (arg0_type),
TYPE_SATURATING (arg0_type));
else
equiv_type
= lang_hooks.types.type_for_mode (TYPE_MODE (arg0_type), 1);
/* A range without an upper bound is, naturally, unbounded.
Since convert would have cropped a very large value, use
the max value for the destination type. */
high_positive
= TYPE_MAX_VALUE (equiv_type) ? TYPE_MAX_VALUE (equiv_type)
: TYPE_MAX_VALUE (arg0_type);
if (TYPE_PRECISION (exp_type) == TYPE_PRECISION (arg0_type))
high_positive = fold_build2_loc (loc, RSHIFT_EXPR, arg0_type,
fold_convert_loc (loc, arg0_type,
high_positive),
build_int_cst (arg0_type, 1));
/* If the low bound is specified, "and" the range with the
range for which the original unsigned value will be
positive. */
if (low != 0)
{
if (! merge_ranges (&n_in_p, &n_low, &n_high, 1, n_low, n_high,
1, fold_convert_loc (loc, arg0_type,
integer_zero_node),
high_positive))
return NULL_TREE;
in_p = (n_in_p == in_p);
}
else
{
/* Otherwise, "or" the range with the range of the input
that will be interpreted as negative. */
if (! merge_ranges (&n_in_p, &n_low, &n_high, 0, n_low, n_high,
1, fold_convert_loc (loc, arg0_type,
integer_zero_node),
high_positive))
return NULL_TREE;
in_p = (in_p != n_in_p);
}
}
*p_low = n_low;
*p_high = n_high;
*p_in_p = in_p;
return arg0;
default:
return NULL_TREE;
}
}
/* Given EXP, a logical expression, set the range it is testing into
variables denoted by PIN_P, PLOW, and PHIGH. Return the expression
actually being tested. *PLOW and *PHIGH will be made of the same
type as the returned expression. If EXP is not a comparison, we
will most likely not be returning a useful value and range. Set
*STRICT_OVERFLOW_P to true if the return value is only valid
because signed overflow is undefined; otherwise, do not change
*STRICT_OVERFLOW_P. */
tree
make_range (tree exp, int *pin_p, tree *plow, tree *phigh,
bool *strict_overflow_p)
{
enum tree_code code;
tree arg0, arg1 = NULL_TREE;
tree exp_type, nexp;
int in_p;
tree low, high;
location_t loc = EXPR_LOCATION (exp);
/* Start with simply saying "EXP != 0" and then look at the code of EXP
and see if we can refine the range. Some of the cases below may not
happen, but it doesn't seem worth worrying about this. We "continue"
the outer loop when we've changed something; otherwise we "break"
the switch, which will "break" the while. */
in_p = 0;
low = high = build_int_cst (TREE_TYPE (exp), 0);
while (1)
{
code = TREE_CODE (exp);
exp_type = TREE_TYPE (exp);
arg0 = NULL_TREE;
if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
{
if (TREE_OPERAND_LENGTH (exp) > 0)
arg0 = TREE_OPERAND (exp, 0);
if (TREE_CODE_CLASS (code) == tcc_binary
|| TREE_CODE_CLASS (code) == tcc_comparison
|| (TREE_CODE_CLASS (code) == tcc_expression
&& TREE_OPERAND_LENGTH (exp) > 1))
arg1 = TREE_OPERAND (exp, 1);
}
if (arg0 == NULL_TREE)
break;
nexp = make_range_step (loc, code, arg0, arg1, exp_type, &low,
&high, &in_p, strict_overflow_p);
if (nexp == NULL_TREE)
break;
exp = nexp;
}
/* If EXP is a constant, we can evaluate whether this is true or false. */
if (TREE_CODE (exp) == INTEGER_CST)
{
in_p = in_p == (integer_onep (range_binop (GE_EXPR, integer_type_node,
exp, 0, low, 0))
&& integer_onep (range_binop (LE_EXPR, integer_type_node,
exp, 1, high, 1)));
low = high = 0;
exp = 0;
}
*pin_p = in_p, *plow = low, *phigh = high;
return exp;
}
/* Given a range, LOW, HIGH, and IN_P, an expression, EXP, and a result
type, TYPE, return an expression to test if EXP is in (or out of, depending
on IN_P) the range. Return 0 if the test couldn't be created. */
tree
build_range_check (location_t loc, tree type, tree exp, int in_p,
tree low, tree high)
{
tree etype = TREE_TYPE (exp), value;
#ifdef HAVE_canonicalize_funcptr_for_compare
/* Disable this optimization for function pointer expressions
on targets that require function pointer canonicalization. */
if (HAVE_canonicalize_funcptr_for_compare
&& TREE_CODE (etype) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (etype)) == FUNCTION_TYPE)
return NULL_TREE;
#endif
if (! in_p)
{
value = build_range_check (loc, type, exp, 1, low, high);
if (value != 0)
return invert_truthvalue_loc (loc, value);
return 0;
}
if (low == 0 && high == 0)
return build_int_cst (type, 1);
if (low == 0)
return fold_build2_loc (loc, LE_EXPR, type, exp,
fold_convert_loc (loc, etype, high));
if (high == 0)
return fold_build2_loc (loc, GE_EXPR, type, exp,
fold_convert_loc (loc, etype, low));
if (operand_equal_p (low, high, 0))
return fold_build2_loc (loc, EQ_EXPR, type, exp,
fold_convert_loc (loc, etype, low));
if (integer_zerop (low))
{
if (! TYPE_UNSIGNED (etype))
{
etype = unsigned_type_for (etype);
high = fold_convert_loc (loc, etype, high);
exp = fold_convert_loc (loc, etype, exp);
}
return build_range_check (loc, type, exp, 1, 0, high);
}
/* Optimize (c>=1) && (c<=127) into (signed char)c > 0. */
if (integer_onep (low) && TREE_CODE (high) == INTEGER_CST)
{
unsigned HOST_WIDE_INT lo;
HOST_WIDE_INT hi;
int prec;
prec = TYPE_PRECISION (etype);
if (prec <= HOST_BITS_PER_WIDE_INT)
{
hi = 0;
lo = ((unsigned HOST_WIDE_INT) 1 << (prec - 1)) - 1;
}
else
{
hi = ((HOST_WIDE_INT) 1 << (prec - HOST_BITS_PER_WIDE_INT - 1)) - 1;
lo = (unsigned HOST_WIDE_INT) -1;
}
if (TREE_INT_CST_HIGH (high) == hi && TREE_INT_CST_LOW (high) == lo)
{
if (TYPE_UNSIGNED (etype))
{
tree signed_etype = signed_type_for (etype);
if (TYPE_PRECISION (signed_etype) != TYPE_PRECISION (etype))
etype
= build_nonstandard_integer_type (TYPE_PRECISION (etype), 0);
else
etype = signed_etype;
exp = fold_convert_loc (loc, etype, exp);
}
return fold_build2_loc (loc, GT_EXPR, type, exp,
build_int_cst (etype, 0));
}
}
/* Optimize (c>=low) && (c<=high) into (c-low>=0) && (c-low<=high-low).
This requires wrap-around arithmetics for the type of the expression.
First make sure that arithmetics in this type is valid, then make sure
that it wraps around. */
if (TREE_CODE (etype) == ENUMERAL_TYPE || TREE_CODE (etype) == BOOLEAN_TYPE)
etype = lang_hooks.types.type_for_size (TYPE_PRECISION (etype),
TYPE_UNSIGNED (etype));
if (TREE_CODE (etype) == INTEGER_TYPE && !TYPE_OVERFLOW_WRAPS (etype))
{
tree utype, minv, maxv;
/* Check if (unsigned) INT_MAX + 1 == (unsigned) INT_MIN
for the type in question, as we rely on this here. */
utype = unsigned_type_for (etype);
maxv = fold_convert_loc (loc, utype, TYPE_MAX_VALUE (etype));
maxv = range_binop (PLUS_EXPR, NULL_TREE, maxv, 1,
integer_one_node, 1);
minv = fold_convert_loc (loc, utype, TYPE_MIN_VALUE (etype));
if (integer_zerop (range_binop (NE_EXPR, integer_type_node,
minv, 1, maxv, 1)))
etype = utype;
else
return 0;
}
high = fold_convert_loc (loc, etype, high);
low = fold_convert_loc (loc, etype, low);
exp = fold_convert_loc (loc, etype, exp);
value = const_binop (MINUS_EXPR, high, low);
if (POINTER_TYPE_P (etype))
{
if (value != 0 && !TREE_OVERFLOW (value))
{
low = fold_build1_loc (loc, NEGATE_EXPR, TREE_TYPE (low), low);
return build_range_check (loc, type,
fold_build_pointer_plus_loc (loc, exp, low),
1, build_int_cst (etype, 0), value);
}
return 0;
}
if (value != 0 && !TREE_OVERFLOW (value))
return build_range_check (loc, type,
fold_build2_loc (loc, MINUS_EXPR, etype, exp, low),
1, build_int_cst (etype, 0), value);
return 0;
}
/* Return the predecessor of VAL in its type, handling the infinite case. */
static tree
range_predecessor (tree val)
{
tree type = TREE_TYPE (val);
if (INTEGRAL_TYPE_P (type)
&& operand_equal_p (val, TYPE_MIN_VALUE (type), 0))
return 0;
else
return range_binop (MINUS_EXPR, NULL_TREE, val, 0, integer_one_node, 0);
}
/* Return the successor of VAL in its type, handling the infinite case. */
static tree
range_successor (tree val)
{
tree type = TREE_TYPE (val);
if (INTEGRAL_TYPE_P (type)
&& operand_equal_p (val, TYPE_MAX_VALUE (type), 0))
return 0;
else
return range_binop (PLUS_EXPR, NULL_TREE, val, 0, integer_one_node, 0);
}
/* Given two ranges, see if we can merge them into one. Return 1 if we
can, 0 if we can't. Set the output range into the specified parameters. */
bool
merge_ranges (int *pin_p, tree *plow, tree *phigh, int in0_p, tree low0,
tree high0, int in1_p, tree low1, tree high1)
{
int no_overlap;
int subset;
int temp;
tree tem;
int in_p;
tree low, high;
int lowequal = ((low0 == 0 && low1 == 0)
|| integer_onep (range_binop (EQ_EXPR, integer_type_node,
low0, 0, low1, 0)));
int highequal = ((high0 == 0 && high1 == 0)
|| integer_onep (range_binop (EQ_EXPR, integer_type_node,
high0, 1, high1, 1)));
/* Make range 0 be the range that starts first, or ends last if they
start at the same value. Swap them if it isn't. */
if (integer_onep (range_binop (GT_EXPR, integer_type_node,
low0, 0, low1, 0))
|| (lowequal
&& integer_onep (range_binop (GT_EXPR, integer_type_node,
high1, 1, high0, 1))))
{
temp = in0_p, in0_p = in1_p, in1_p = temp;
tem = low0, low0 = low1, low1 = tem;
tem = high0, high0 = high1, high1 = tem;
}
/* Now flag two cases, whether the ranges are disjoint or whether the
second range is totally subsumed in the first. Note that the tests
below are simplified by the ones above. */
no_overlap = integer_onep (range_binop (LT_EXPR, integer_type_node,
high0, 1, low1, 0));
subset = integer_onep (range_binop (LE_EXPR, integer_type_node,
high1, 1, high0, 1));
/* We now have four cases, depending on whether we are including or
excluding the two ranges. */
if (in0_p && in1_p)
{
/* If they don't overlap, the result is false. If the second range
is a subset it is the result. Otherwise, the range is from the start
of the second to the end of the first. */
if (no_overlap)
in_p = 0, low = high = 0;
else if (subset)
in_p = 1, low = low1, high = high1;
else
in_p = 1, low = low1, high = high0;
}
else if (in0_p && ! in1_p)
{
/* If they don't overlap, the result is the first range. If they are
equal, the result is false. If the second range is a subset of the
first, and the ranges begin at the same place, we go from just after
the end of the second range to the end of the first. If the second
range is not a subset of the first, or if it is a subset and both
ranges end at the same place, the range starts at the start of the
first range and ends just before the second range.
Otherwise, we can't describe this as a single range. */
if (no_overlap)
in_p = 1, low = low0, high = high0;
else if (lowequal && highequal)
in_p = 0, low = high = 0;
else if (subset && lowequal)
{
low = range_successor (high1);
high = high0;
in_p = 1;
if (low == 0)
{
/* We are in the weird situation where high0 > high1 but
high1 has no successor. Punt. */
return 0;
}
}
else if (! subset || highequal)
{
low = low0;
high = range_predecessor (low1);
in_p = 1;
if (high == 0)
{
/* low0 < low1 but low1 has no predecessor. Punt. */
return 0;
}
}
else
return 0;
}
else if (! in0_p && in1_p)
{
/* If they don't overlap, the result is the second range. If the second
is a subset of the first, the result is false. Otherwise,
the range starts just after the first range and ends at the
end of the second. */
if (no_overlap)
in_p = 1, low = low1, high = high1;
else if (subset || highequal)
in_p = 0, low = high = 0;
else
{
low = range_successor (high0);
high = high1;
in_p = 1;
if (low == 0)
{
/* high1 > high0 but high0 has no successor. Punt. */
return 0;
}
}
}
else
{
/* The case where we are excluding both ranges. Here the complex case
is if they don't overlap. In that case, the only time we have a
range is if they are adjacent. If the second is a subset of the
first, the result is the first. Otherwise, the range to exclude
starts at the beginning of the first range and ends at the end of the
second. */
if (no_overlap)
{
if (integer_onep (range_binop (EQ_EXPR, integer_type_node,
range_successor (high0),
1, low1, 0)))
in_p = 0, low = low0, high = high1;
else
{
/* Canonicalize - [min, x] into - [-, x]. */
if (low0 && TREE_CODE (low0) == INTEGER_CST)
switch (TREE_CODE (TREE_TYPE (low0)))
{
case ENUMERAL_TYPE:
if (TYPE_PRECISION (TREE_TYPE (low0))
!= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (low0))))
break;
/* FALLTHROUGH */
case INTEGER_TYPE:
if (tree_int_cst_equal (low0,
TYPE_MIN_VALUE (TREE_TYPE (low0))))
low0 = 0;
break;
case POINTER_TYPE:
if (TYPE_UNSIGNED (TREE_TYPE (low0))
&& integer_zerop (low0))
low0 = 0;
break;
default:
break;
}
/* Canonicalize - [x, max] into - [x, -]. */
if (high1 && TREE_CODE (high1) == INTEGER_CST)
switch (TREE_CODE (TREE_TYPE (high1)))
{
case ENUMERAL_TYPE:
if (TYPE_PRECISION (TREE_TYPE (high1))
!= GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (high1))))
break;
/* FALLTHROUGH */
case INTEGER_TYPE:
if (tree_int_cst_equal (high1,
TYPE_MAX_VALUE (TREE_TYPE (high1))))
high1 = 0;
break;
case POINTER_TYPE:
if (TYPE_UNSIGNED (TREE_TYPE (high1))
&& integer_zerop (range_binop (PLUS_EXPR, NULL_TREE,
high1, 1,
integer_one_node, 1)))
high1 = 0;
break;
default:
break;
}
/* The ranges might be also adjacent between the maximum and
minimum values of the given type. For
- [{min,-}, x] and - [y, {max,-}] ranges where x + 1 < y
return + [x + 1, y - 1]. */
if (low0 == 0 && high1 == 0)
{
low = range_successor (high0);
high = range_predecessor (low1);
if (low == 0 || high == 0)
return 0;
in_p = 1;
}
else
return 0;
}
}
else if (subset)
in_p = 0, low = low0, high = high0;
else
in_p = 0, low = low0, high = high1;
}
*pin_p = in_p, *plow = low, *phigh = high;
return 1;
}
/* Subroutine of fold, looking inside expressions of the form
A op B ? A : C, where ARG0, ARG1 and ARG2 are the three operands
of the COND_EXPR. This function is being used also to optimize
A op B ? C : A, by reversing the comparison first.
Return a folded expression whose code is not a COND_EXPR
anymore, or NULL_TREE if no folding opportunity is found. */
static tree
fold_cond_expr_with_comparison (location_t loc, tree type,
tree arg0, tree arg1, tree arg2)
{
enum tree_code comp_code = TREE_CODE (arg0);
tree arg00 = TREE_OPERAND (arg0, 0);
tree arg01 = TREE_OPERAND (arg0, 1);
tree arg1_type = TREE_TYPE (arg1);
tree tem;
STRIP_NOPS (arg1);
STRIP_NOPS (arg2);
/* If we have A op 0 ? A : -A, consider applying the following
transformations:
A == 0? A : -A same as -A
A != 0? A : -A same as A
A >= 0? A : -A same as abs (A)
A > 0? A : -A same as abs (A)
A <= 0? A : -A same as -abs (A)
A < 0? A : -A same as -abs (A)
None of these transformations work for modes with signed
zeros. If A is +/-0, the first two transformations will
change the sign of the result (from +0 to -0, or vice
versa). The last four will fix the sign of the result,
even though the original expressions could be positive or
negative, depending on the sign of A.
Note that all these transformations are correct if A is
NaN, since the two alternatives (A and -A) are also NaNs. */
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (type))
&& (FLOAT_TYPE_P (TREE_TYPE (arg01))
? real_zerop (arg01)
: integer_zerop (arg01))
&& ((TREE_CODE (arg2) == NEGATE_EXPR
&& operand_equal_p (TREE_OPERAND (arg2, 0), arg1, 0))
/* In the case that A is of the form X-Y, '-A' (arg2) may
have already been folded to Y-X, check for that. */
|| (TREE_CODE (arg1) == MINUS_EXPR
&& TREE_CODE (arg2) == MINUS_EXPR
&& operand_equal_p (TREE_OPERAND (arg1, 0),
TREE_OPERAND (arg2, 1), 0)
&& operand_equal_p (TREE_OPERAND (arg1, 1),
TREE_OPERAND (arg2, 0), 0))))
switch (comp_code)
{
case EQ_EXPR:
case UNEQ_EXPR:
tem = fold_convert_loc (loc, arg1_type, arg1);
return pedantic_non_lvalue_loc (loc,
fold_convert_loc (loc, type,
negate_expr (tem)));
case NE_EXPR:
case LTGT_EXPR:
return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1));
case UNGE_EXPR:
case UNGT_EXPR:
if (flag_trapping_math)
break;
/* Fall through. */
case GE_EXPR:
case GT_EXPR:
if (TYPE_UNSIGNED (TREE_TYPE (arg1)))
arg1 = fold_convert_loc (loc, signed_type_for
(TREE_TYPE (arg1)), arg1);
tem = fold_build1_loc (loc, ABS_EXPR, TREE_TYPE (arg1), arg1);
return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, tem));
case UNLE_EXPR:
case UNLT_EXPR:
if (flag_trapping_math)
break;
case LE_EXPR:
case LT_EXPR:
if (TYPE_UNSIGNED (TREE_TYPE (arg1)))
arg1 = fold_convert_loc (loc, signed_type_for
(TREE_TYPE (arg1)), arg1);
tem = fold_build1_loc (loc, ABS_EXPR, TREE_TYPE (arg1), arg1);
return negate_expr (fold_convert_loc (loc, type, tem));
default:
gcc_assert (TREE_CODE_CLASS (comp_code) == tcc_comparison);
break;
}
/* A != 0 ? A : 0 is simply A, unless A is -0. Likewise
A == 0 ? A : 0 is always 0 unless A is -0. Note that
both transformations are correct when A is NaN: A != 0
is then true, and A == 0 is false. */
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (type))
&& integer_zerop (arg01) && integer_zerop (arg2))
{
if (comp_code == NE_EXPR)
return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1));
else if (comp_code == EQ_EXPR)
return build_int_cst (type, 0);
}
/* Try some transformations of A op B ? A : B.
A == B? A : B same as B
A != B? A : B same as A
A >= B? A : B same as max (A, B)
A > B? A : B same as max (B, A)
A <= B? A : B same as min (A, B)
A < B? A : B same as min (B, A)
As above, these transformations don't work in the presence
of signed zeros. For example, if A and B are zeros of
opposite sign, the first two transformations will change
the sign of the result. In the last four, the original
expressions give different results for (A=+0, B=-0) and
(A=-0, B=+0), but the transformed expressions do not.
The first two transformations are correct if either A or B
is a NaN. In the first transformation, the condition will
be false, and B will indeed be chosen. In the case of the
second transformation, the condition A != B will be true,
and A will be chosen.
The conversions to max() and min() are not correct if B is
a number and A is not. The conditions in the original
expressions will be false, so all four give B. The min()
and max() versions would give a NaN instead. */
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (type))
&& operand_equal_for_comparison_p (arg01, arg2, arg00)
/* Avoid these transformations if the COND_EXPR may be used
as an lvalue in the C++ front-end. PR c++/19199. */
&& (in_gimple_form
|| (strcmp (lang_hooks.name, "GNU C++") != 0
&& strcmp (lang_hooks.name, "GNU Objective-C++") != 0)
|| ! maybe_lvalue_p (arg1)
|| ! maybe_lvalue_p (arg2)))
{
tree comp_op0 = arg00;
tree comp_op1 = arg01;
tree comp_type = TREE_TYPE (comp_op0);
/* Avoid adding NOP_EXPRs in case this is an lvalue. */
if (TYPE_MAIN_VARIANT (comp_type) == TYPE_MAIN_VARIANT (type))
{
comp_type = type;
comp_op0 = arg1;
comp_op1 = arg2;
}
switch (comp_code)
{
case EQ_EXPR:
return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, arg2));
case NE_EXPR:
return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1));
case LE_EXPR:
case LT_EXPR:
case UNLE_EXPR:
case UNLT_EXPR:
/* In C++ a ?: expression can be an lvalue, so put the
operand which will be used if they are equal first
so that we can convert this back to the
corresponding COND_EXPR. */
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1))))
{
comp_op0 = fold_convert_loc (loc, comp_type, comp_op0);
comp_op1 = fold_convert_loc (loc, comp_type, comp_op1);
tem = (comp_code == LE_EXPR || comp_code == UNLE_EXPR)
? fold_build2_loc (loc, MIN_EXPR, comp_type, comp_op0, comp_op1)
: fold_build2_loc (loc, MIN_EXPR, comp_type,
comp_op1, comp_op0);
return pedantic_non_lvalue_loc (loc,
fold_convert_loc (loc, type, tem));
}
break;
case GE_EXPR:
case GT_EXPR:
case UNGE_EXPR:
case UNGT_EXPR:
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1))))
{
comp_op0 = fold_convert_loc (loc, comp_type, comp_op0);
comp_op1 = fold_convert_loc (loc, comp_type, comp_op1);
tem = (comp_code == GE_EXPR || comp_code == UNGE_EXPR)
? fold_build2_loc (loc, MAX_EXPR, comp_type, comp_op0, comp_op1)
: fold_build2_loc (loc, MAX_EXPR, comp_type,
comp_op1, comp_op0);
return pedantic_non_lvalue_loc (loc,
fold_convert_loc (loc, type, tem));
}
break;
case UNEQ_EXPR:
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1))))
return pedantic_non_lvalue_loc (loc,
fold_convert_loc (loc, type, arg2));
break;
case LTGT_EXPR:
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1))))
return pedantic_non_lvalue_loc (loc,
fold_convert_loc (loc, type, arg1));
break;
default:
gcc_assert (TREE_CODE_CLASS (comp_code) == tcc_comparison);
break;
}
}
/* If this is A op C1 ? A : C2 with C1 and C2 constant integers,
we might still be able to simplify this. For example,
if C1 is one less or one more than C2, this might have started
out as a MIN or MAX and been transformed by this function.
Only good for INTEGER_TYPEs, because we need TYPE_MAX_VALUE. */
if (INTEGRAL_TYPE_P (type)
&& TREE_CODE (arg01) == INTEGER_CST
&& TREE_CODE (arg2) == INTEGER_CST)
switch (comp_code)
{
case EQ_EXPR:
if (TREE_CODE (arg1) == INTEGER_CST)
break;
/* We can replace A with C1 in this case. */
arg1 = fold_convert_loc (loc, type, arg01);
return fold_build3_loc (loc, COND_EXPR, type, arg0, arg1, arg2);
case LT_EXPR:
/* If C1 is C2 + 1, this is min(A, C2), but use ARG00's type for
MIN_EXPR, to preserve the signedness of the comparison. */
if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type),
OEP_ONLY_CONST)
&& operand_equal_p (arg01,
const_binop (PLUS_EXPR, arg2,
build_int_cst (type, 1)),
OEP_ONLY_CONST))
{
tem = fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (arg00), arg00,
fold_convert_loc (loc, TREE_TYPE (arg00),
arg2));
return pedantic_non_lvalue_loc (loc,
fold_convert_loc (loc, type, tem));
}
break;
case LE_EXPR:
/* If C1 is C2 - 1, this is min(A, C2), with the same care
as above. */
if (! operand_equal_p (arg2, TYPE_MIN_VALUE (type),
OEP_ONLY_CONST)
&& operand_equal_p (arg01,
const_binop (MINUS_EXPR, arg2,
build_int_cst (type, 1)),
OEP_ONLY_CONST))
{
tem = fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (arg00), arg00,
fold_convert_loc (loc, TREE_TYPE (arg00),
arg2));
return pedantic_non_lvalue_loc (loc,
fold_convert_loc (loc, type, tem));
}
break;
case GT_EXPR:
/* If C1 is C2 - 1, this is max(A, C2), but use ARG00's type for
MAX_EXPR, to preserve the signedness of the comparison. */
if (! operand_equal_p (arg2, TYPE_MIN_VALUE (type),
OEP_ONLY_CONST)
&& operand_equal_p (arg01,
const_binop (MINUS_EXPR, arg2,
build_int_cst (type, 1)),
OEP_ONLY_CONST))
{
tem = fold_build2_loc (loc, MAX_EXPR, TREE_TYPE (arg00), arg00,
fold_convert_loc (loc, TREE_TYPE (arg00),
arg2));
return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, tem));
}
break;
case GE_EXPR:
/* If C1 is C2 + 1, this is max(A, C2), with the same care as above. */
if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type),
OEP_ONLY_CONST)
&& operand_equal_p (arg01,
const_binop (PLUS_EXPR, arg2,
build_int_cst (type, 1)),
OEP_ONLY_CONST))
{
tem = fold_build2_loc (loc, MAX_EXPR, TREE_TYPE (arg00), arg00,
fold_convert_loc (loc, TREE_TYPE (arg00),
arg2));
return pedantic_non_lvalue_loc (loc, fold_convert_loc (loc, type, tem));
}
break;
case NE_EXPR:
break;
default:
gcc_unreachable ();
}
return NULL_TREE;
}
#ifndef LOGICAL_OP_NON_SHORT_CIRCUIT
#define LOGICAL_OP_NON_SHORT_CIRCUIT \
(BRANCH_COST (optimize_function_for_speed_p (cfun), \
false) >= 2)
#endif
/* EXP is some logical combination of boolean tests. See if we can
merge it into some range test. Return the new tree if so. */
static tree
fold_range_test (location_t loc, enum tree_code code, tree type,
tree op0, tree op1)
{
int or_op = (code == TRUTH_ORIF_EXPR
|| code == TRUTH_OR_EXPR);
int in0_p, in1_p, in_p;
tree low0, low1, low, high0, high1, high;
bool strict_overflow_p = false;
tree lhs = make_range (op0, &in0_p, &low0, &high0, &strict_overflow_p);
tree rhs = make_range (op1, &in1_p, &low1, &high1, &strict_overflow_p);
tree tem;
const char * const warnmsg = G_("assuming signed overflow does not occur "
"when simplifying range test");
/* If this is an OR operation, invert both sides; we will invert
again at the end. */
if (or_op)
in0_p = ! in0_p, in1_p = ! in1_p;
/* If both expressions are the same, if we can merge the ranges, and we
can build the range test, return it or it inverted. If one of the
ranges is always true or always false, consider it to be the same
expression as the other. */
if ((lhs == 0 || rhs == 0 || operand_equal_p (lhs, rhs, 0))
&& merge_ranges (&in_p, &low, &high, in0_p, low0, high0,
in1_p, low1, high1)
&& 0 != (tem = (build_range_check (loc, type,
lhs != 0 ? lhs
: rhs != 0 ? rhs : integer_zero_node,
in_p, low, high))))
{
if (strict_overflow_p)
fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON);
return or_op ? invert_truthvalue_loc (loc, tem) : tem;
}
/* On machines where the branch cost is expensive, if this is a
short-circuited branch and the underlying object on both sides
is the same, make a non-short-circuit operation. */
else if (LOGICAL_OP_NON_SHORT_CIRCUIT
&& lhs != 0 && rhs != 0
&& (code == TRUTH_ANDIF_EXPR
|| code == TRUTH_ORIF_EXPR)
&& operand_equal_p (lhs, rhs, 0))
{
/* If simple enough, just rewrite. Otherwise, make a SAVE_EXPR
unless we are at top level or LHS contains a PLACEHOLDER_EXPR, in
which cases we can't do this. */
if (simple_operand_p (lhs))
return build2_loc (loc, code == TRUTH_ANDIF_EXPR
? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
type, op0, op1);
else if (!lang_hooks.decls.global_bindings_p ()
&& !CONTAINS_PLACEHOLDER_P (lhs))
{
tree common = save_expr (lhs);
if (0 != (lhs = build_range_check (loc, type, common,
or_op ? ! in0_p : in0_p,
low0, high0))
&& (0 != (rhs = build_range_check (loc, type, common,
or_op ? ! in1_p : in1_p,
low1, high1))))
{
if (strict_overflow_p)
fold_overflow_warning (warnmsg,
WARN_STRICT_OVERFLOW_COMPARISON);
return build2_loc (loc, code == TRUTH_ANDIF_EXPR
? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
type, lhs, rhs);
}
}
}
return 0;
}
/* Subroutine for fold_truth_andor_1: C is an INTEGER_CST interpreted as a P
bit value. Arrange things so the extra bits will be set to zero if and
only if C is signed-extended to its full width. If MASK is nonzero,
it is an INTEGER_CST that should be AND'ed with the extra bits. */
static tree
unextend (tree c, int p, int unsignedp, tree mask)
{
tree type = TREE_TYPE (c);
int modesize = GET_MODE_BITSIZE (TYPE_MODE (type));
tree temp;
if (p == modesize || unsignedp)
return c;
/* We work by getting just the sign bit into the low-order bit, then
into the high-order bit, then sign-extend. We then XOR that value
with C. */
temp = const_binop (RSHIFT_EXPR, c, size_int (p - 1));
temp = const_binop (BIT_AND_EXPR, temp, size_int (1));
/* We must use a signed type in order to get an arithmetic right shift.
However, we must also avoid introducing accidental overflows, so that
a subsequent call to integer_zerop will work. Hence we must
do the type conversion here. At this point, the constant is either
zero or one, and the conversion to a signed type can never overflow.
We could get an overflow if this conversion is done anywhere else. */
if (TYPE_UNSIGNED (type))
temp = fold_convert (signed_type_for (type), temp);
temp = const_binop (LSHIFT_EXPR, temp, size_int (modesize - 1));
temp = const_binop (RSHIFT_EXPR, temp, size_int (modesize - p - 1));
if (mask != 0)
temp = const_binop (BIT_AND_EXPR, temp,
fold_convert (TREE_TYPE (c), mask));
/* If necessary, convert the type back to match the type of C. */
if (TYPE_UNSIGNED (type))
temp = fold_convert (type, temp);
return fold_convert (type, const_binop (BIT_XOR_EXPR, c, temp));
}
/* For an expression that has the form
(A && B) || ~B
or
(A || B) && ~B,
we can drop one of the inner expressions and simplify to
A || ~B
or
A && ~B
LOC is the location of the resulting expression. OP is the inner
logical operation; the left-hand side in the examples above, while CMPOP
is the right-hand side. RHS_ONLY is used to prevent us from accidentally
removing a condition that guards another, as in
(A != NULL && A->...) || A == NULL
which we must not transform. If RHS_ONLY is true, only eliminate the
right-most operand of the inner logical operation. */
static tree
merge_truthop_with_opposite_arm (location_t loc, tree op, tree cmpop,
bool rhs_only)
{
tree type = TREE_TYPE (cmpop);
enum tree_code code = TREE_CODE (cmpop);
enum tree_code truthop_code = TREE_CODE (op);
tree lhs = TREE_OPERAND (op, 0);
tree rhs = TREE_OPERAND (op, 1);
tree orig_lhs = lhs, orig_rhs = rhs;
enum tree_code rhs_code = TREE_CODE (rhs);
enum tree_code lhs_code = TREE_CODE (lhs);
enum tree_code inv_code;
if (TREE_SIDE_EFFECTS (op) || TREE_SIDE_EFFECTS (cmpop))
return NULL_TREE;
if (TREE_CODE_CLASS (code) != tcc_comparison)
return NULL_TREE;
if (rhs_code == truthop_code)
{
tree newrhs = merge_truthop_with_opposite_arm (loc, rhs, cmpop, rhs_only);
if (newrhs != NULL_TREE)
{
rhs = newrhs;
rhs_code = TREE_CODE (rhs);
}
}
if (lhs_code == truthop_code && !rhs_only)
{
tree newlhs = merge_truthop_with_opposite_arm (loc, lhs, cmpop, false);
if (newlhs != NULL_TREE)
{
lhs = newlhs;
lhs_code = TREE_CODE (lhs);
}
}
inv_code = invert_tree_comparison (code, HONOR_NANS (TYPE_MODE (type)));
if (inv_code == rhs_code
&& operand_equal_p (TREE_OPERAND (rhs, 0), TREE_OPERAND (cmpop, 0), 0)
&& operand_equal_p (TREE_OPERAND (rhs, 1), TREE_OPERAND (cmpop, 1), 0))
return lhs;
if (!rhs_only && inv_code == lhs_code
&& operand_equal_p (TREE_OPERAND (lhs, 0), TREE_OPERAND (cmpop, 0), 0)
&& operand_equal_p (TREE_OPERAND (lhs, 1), TREE_OPERAND (cmpop, 1), 0))
return rhs;
if (rhs != orig_rhs || lhs != orig_lhs)
return fold_build2_loc (loc, truthop_code, TREE_TYPE (cmpop),
lhs, rhs);
return NULL_TREE;
}
/* Find ways of folding logical expressions of LHS and RHS:
Try to merge two comparisons to the same innermost item.
Look for range tests like "ch >= '0' && ch <= '9'".
Look for combinations of simple terms on machines with expensive branches
and evaluate the RHS unconditionally.
For example, if we have p->a == 2 && p->b == 4 and we can make an
object large enough to span both A and B, we can do this with a comparison
against the object ANDed with the a mask.
If we have p->a == q->a && p->b == q->b, we may be able to use bit masking
operations to do this with one comparison.
We check for both normal comparisons and the BIT_AND_EXPRs made this by
function and the one above.
CODE is the logical operation being done. It can be TRUTH_ANDIF_EXPR,
TRUTH_AND_EXPR, TRUTH_ORIF_EXPR, or TRUTH_OR_EXPR.
TRUTH_TYPE is the type of the logical operand and LHS and RHS are its
two operands.
We return the simplified tree or 0 if no optimization is possible. */
static tree
fold_truth_andor_1 (location_t loc, enum tree_code code, tree truth_type,
tree lhs, tree rhs)
{
/* If this is the "or" of two comparisons, we can do something if
the comparisons are NE_EXPR. If this is the "and", we can do something
if the comparisons are EQ_EXPR. I.e.,
(a->b == 2 && a->c == 4) can become (a->new == NEW).
WANTED_CODE is this operation code. For single bit fields, we can
convert EQ_EXPR to NE_EXPR so we need not reject the "wrong"
comparison for one-bit fields. */
enum tree_code wanted_code;
enum tree_code lcode, rcode;
tree ll_arg, lr_arg, rl_arg, rr_arg;
tree ll_inner, lr_inner, rl_inner, rr_inner;
HOST_WIDE_INT ll_bitsize, ll_bitpos, lr_bitsize, lr_bitpos;
HOST_WIDE_INT rl_bitsize, rl_bitpos, rr_bitsize, rr_bitpos;
HOST_WIDE_INT xll_bitpos, xlr_bitpos, xrl_bitpos, xrr_bitpos;
HOST_WIDE_INT lnbitsize, lnbitpos, rnbitsize, rnbitpos;
int ll_unsignedp, lr_unsignedp, rl_unsignedp, rr_unsignedp;
enum machine_mode ll_mode, lr_mode, rl_mode, rr_mode;
enum machine_mode lnmode, rnmode;
tree ll_mask, lr_mask, rl_mask, rr_mask;
tree ll_and_mask, lr_and_mask, rl_and_mask, rr_and_mask;
tree l_const, r_const;
tree lntype, rntype, result;
HOST_WIDE_INT first_bit, end_bit;
int volatilep;
/* Start by getting the comparison codes. Fail if anything is volatile.
If one operand is a BIT_AND_EXPR with the constant one, treat it as if
it were surrounded with a NE_EXPR. */
if (TREE_SIDE_EFFECTS (lhs) || TREE_SIDE_EFFECTS (rhs))
return 0;
lcode = TREE_CODE (lhs);
rcode = TREE_CODE (rhs);
if (lcode == BIT_AND_EXPR && integer_onep (TREE_OPERAND (lhs, 1)))
{
lhs = build2 (NE_EXPR, truth_type, lhs,
build_int_cst (TREE_TYPE (lhs), 0));
lcode = NE_EXPR;
}
if (rcode == BIT_AND_EXPR && integer_onep (TREE_OPERAND (rhs, 1)))
{
rhs = build2 (NE_EXPR, truth_type, rhs,
build_int_cst (TREE_TYPE (rhs), 0));
rcode = NE_EXPR;
}
if (TREE_CODE_CLASS (lcode) != tcc_comparison
|| TREE_CODE_CLASS (rcode) != tcc_comparison)
return 0;
ll_arg = TREE_OPERAND (lhs, 0);
lr_arg = TREE_OPERAND (lhs, 1);
rl_arg = TREE_OPERAND (rhs, 0);
rr_arg = TREE_OPERAND (rhs, 1);
/* Simplify (x<y) && (x==y) into (x<=y) and related optimizations. */
if (simple_operand_p (ll_arg)
&& simple_operand_p (lr_arg))
{
if (operand_equal_p (ll_arg, rl_arg, 0)
&& operand_equal_p (lr_arg, rr_arg, 0))
{
result = combine_comparisons (loc, code, lcode, rcode,
truth_type, ll_arg, lr_arg);
if (result)
return result;
}
else if (operand_equal_p (ll_arg, rr_arg, 0)
&& operand_equal_p (lr_arg, rl_arg, 0))
{
result = combine_comparisons (loc, code, lcode,
swap_tree_comparison (rcode),
truth_type, ll_arg, lr_arg);
if (result)
return result;
}
}
code = ((code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR)
? TRUTH_AND_EXPR : TRUTH_OR_EXPR);
/* If the RHS can be evaluated unconditionally and its operands are
simple, it wins to evaluate the RHS unconditionally on machines
with expensive branches. In this case, this isn't a comparison
that can be merged. */
if (BRANCH_COST (optimize_function_for_speed_p (cfun),
false) >= 2
&& ! FLOAT_TYPE_P (TREE_TYPE (rl_arg))
&& simple_operand_p (rl_arg)
&& simple_operand_p (rr_arg))
{
/* Convert (a != 0) || (b != 0) into (a | b) != 0. */
if (code == TRUTH_OR_EXPR
&& lcode == NE_EXPR && integer_zerop (lr_arg)
&& rcode == NE_EXPR && integer_zerop (rr_arg)
&& TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg)
&& INTEGRAL_TYPE_P (TREE_TYPE (ll_arg)))
return build2_loc (loc, NE_EXPR, truth_type,
build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
ll_arg, rl_arg),
build_int_cst (TREE_TYPE (ll_arg), 0));
/* Convert (a == 0) && (b == 0) into (a | b) == 0. */
if (code == TRUTH_AND_EXPR
&& lcode == EQ_EXPR && integer_zerop (lr_arg)
&& rcode == EQ_EXPR && integer_zerop (rr_arg)
&& TREE_TYPE (ll_arg) == TREE_TYPE (rl_arg)
&& INTEGRAL_TYPE_P (TREE_TYPE (ll_arg)))
return build2_loc (loc, EQ_EXPR, truth_type,
build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
ll_arg, rl_arg),
build_int_cst (TREE_TYPE (ll_arg), 0));
}
/* See if the comparisons can be merged. Then get all the parameters for
each side. */
if ((lcode != EQ_EXPR && lcode != NE_EXPR)
|| (rcode != EQ_EXPR && rcode != NE_EXPR))
return 0;
volatilep = 0;
ll_inner = decode_field_reference (loc, ll_arg,
&ll_bitsize, &ll_bitpos, &ll_mode,
&ll_unsignedp, &volatilep, &ll_mask,
&ll_and_mask);
lr_inner = decode_field_reference (loc, lr_arg,
&lr_bitsize, &lr_bitpos, &lr_mode,
&lr_unsignedp, &volatilep, &lr_mask,
&lr_and_mask);
rl_inner = decode_field_reference (loc, rl_arg,
&rl_bitsize, &rl_bitpos, &rl_mode,
&rl_unsignedp, &volatilep, &rl_mask,
&rl_and_mask);
rr_inner = decode_field_reference (loc, rr_arg,
&rr_bitsize, &rr_bitpos, &rr_mode,
&rr_unsignedp, &volatilep, &rr_mask,
&rr_and_mask);
/* It must be true that the inner operation on the lhs of each
comparison must be the same if we are to be able to do anything.
Then see if we have constants. If not, the same must be true for
the rhs's. */
if (volatilep || ll_inner == 0 || rl_inner == 0
|| ! operand_equal_p (ll_inner, rl_inner, 0))
return 0;
if (TREE_CODE (lr_arg) == INTEGER_CST
&& TREE_CODE (rr_arg) == INTEGER_CST)
l_const = lr_arg, r_const = rr_arg;
else if (lr_inner == 0 || rr_inner == 0
|| ! operand_equal_p (lr_inner, rr_inner, 0))
return 0;
else
l_const = r_const = 0;
/* If either comparison code is not correct for our logical operation,
fail. However, we can convert a one-bit comparison against zero into
the opposite comparison against that bit being set in the field. */
wanted_code = (code == TRUTH_AND_EXPR ? EQ_EXPR : NE_EXPR);
if (lcode != wanted_code)
{
if (l_const && integer_zerop (l_const) && integer_pow2p (ll_mask))
{
/* Make the left operand unsigned, since we are only interested
in the value of one bit. Otherwise we are doing the wrong
thing below. */
ll_unsignedp = 1;
l_const = ll_mask;
}
else
return 0;
}
/* This is analogous to the code for l_const above. */
if (rcode != wanted_code)
{
if (r_const && integer_zerop (r_const) && integer_pow2p (rl_mask))
{
rl_unsignedp = 1;
r_const = rl_mask;
}
else
return 0;
}
/* See if we can find a mode that contains both fields being compared on
the left. If we can't, fail. Otherwise, update all constants and masks
to be relative to a field of that size. */
first_bit = MIN (ll_bitpos, rl_bitpos);
end_bit = MAX (ll_bitpos + ll_bitsize, rl_bitpos + rl_bitsize);
lnmode = get_best_mode (end_bit - first_bit, first_bit, 0, 0,
TYPE_ALIGN (TREE_TYPE (ll_inner)), word_mode,
volatilep);
if (lnmode == VOIDmode)
return 0;
lnbitsize = GET_MODE_BITSIZE (lnmode);
lnbitpos = first_bit & ~ (lnbitsize - 1);
lntype = lang_hooks.types.type_for_size (lnbitsize, 1);
xll_bitpos = ll_bitpos - lnbitpos, xrl_bitpos = rl_bitpos - lnbitpos;
if (BYTES_BIG_ENDIAN)
{
xll_bitpos = lnbitsize - xll_bitpos - ll_bitsize;
xrl_bitpos = lnbitsize - xrl_bitpos - rl_bitsize;
}
ll_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc, lntype, ll_mask),
size_int (xll_bitpos));
rl_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc, lntype, rl_mask),
size_int (xrl_bitpos));
if (l_const)
{
l_const = fold_convert_loc (loc, lntype, l_const);
l_const = unextend (l_const, ll_bitsize, ll_unsignedp, ll_and_mask);
l_const = const_binop (LSHIFT_EXPR, l_const, size_int (xll_bitpos));
if (! integer_zerop (const_binop (BIT_AND_EXPR, l_const,
fold_build1_loc (loc, BIT_NOT_EXPR,
lntype, ll_mask))))
{
warning (0, "comparison is always %d", wanted_code == NE_EXPR);
return constant_boolean_node (wanted_code == NE_EXPR, truth_type);
}
}
if (r_const)
{
r_const = fold_convert_loc (loc, lntype, r_const);
r_const = unextend (r_const, rl_bitsize, rl_unsignedp, rl_and_mask);
r_const = const_binop (LSHIFT_EXPR, r_const, size_int (xrl_bitpos));
if (! integer_zerop (const_binop (BIT_AND_EXPR, r_const,
fold_build1_loc (loc, BIT_NOT_EXPR,
lntype, rl_mask))))
{
warning (0, "comparison is always %d", wanted_code == NE_EXPR);
return constant_boolean_node (wanted_code == NE_EXPR, truth_type);
}
}
/* If the right sides are not constant, do the same for it. Also,
disallow this optimization if a size or signedness mismatch occurs
between the left and right sides. */
if (l_const == 0)
{
if (ll_bitsize != lr_bitsize || rl_bitsize != rr_bitsize
|| ll_unsignedp != lr_unsignedp || rl_unsignedp != rr_unsignedp
/* Make sure the two fields on the right
correspond to the left without being swapped. */
|| ll_bitpos - rl_bitpos != lr_bitpos - rr_bitpos)
return 0;
first_bit = MIN (lr_bitpos, rr_bitpos);
end_bit = MAX (lr_bitpos + lr_bitsize, rr_bitpos + rr_bitsize);
rnmode = get_best_mode (end_bit - first_bit, first_bit, 0, 0,
TYPE_ALIGN (TREE_TYPE (lr_inner)), word_mode,
volatilep);
if (rnmode == VOIDmode)
return 0;
rnbitsize = GET_MODE_BITSIZE (rnmode);
rnbitpos = first_bit & ~ (rnbitsize - 1);
rntype = lang_hooks.types.type_for_size (rnbitsize, 1);
xlr_bitpos = lr_bitpos - rnbitpos, xrr_bitpos = rr_bitpos - rnbitpos;
if (BYTES_BIG_ENDIAN)
{
xlr_bitpos = rnbitsize - xlr_bitpos - lr_bitsize;
xrr_bitpos = rnbitsize - xrr_bitpos - rr_bitsize;
}
lr_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc,
rntype, lr_mask),
size_int (xlr_bitpos));
rr_mask = const_binop (LSHIFT_EXPR, fold_convert_loc (loc,
rntype, rr_mask),
size_int (xrr_bitpos));
/* Make a mask that corresponds to both fields being compared.
Do this for both items being compared. If the operands are the
same size and the bits being compared are in the same position
then we can do this by masking both and comparing the masked
results. */
ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask);
lr_mask = const_binop (BIT_IOR_EXPR, lr_mask, rr_mask);
if (lnbitsize == rnbitsize && xll_bitpos == xlr_bitpos)
{
lhs = make_bit_field_ref (loc, ll_inner, lntype, lnbitsize, lnbitpos,
ll_unsignedp || rl_unsignedp);
if (! all_ones_mask_p (ll_mask, lnbitsize))
lhs = build2 (BIT_AND_EXPR, lntype, lhs, ll_mask);
rhs = make_bit_field_ref (loc, lr_inner, rntype, rnbitsize, rnbitpos,
lr_unsignedp || rr_unsignedp);
if (! all_ones_mask_p (lr_mask, rnbitsize))
rhs = build2 (BIT_AND_EXPR, rntype, rhs, lr_mask);
return build2_loc (loc, wanted_code, truth_type, lhs, rhs);
}
/* There is still another way we can do something: If both pairs of
fields being compared are adjacent, we may be able to make a wider
field containing them both.
Note that we still must mask the lhs/rhs expressions. Furthermore,
the mask must be shifted to account for the shift done by
make_bit_field_ref. */
if ((ll_bitsize + ll_bitpos == rl_bitpos
&& lr_bitsize + lr_bitpos == rr_bitpos)
|| (ll_bitpos == rl_bitpos + rl_bitsize
&& lr_bitpos == rr_bitpos + rr_bitsize))
{
tree type;
lhs = make_bit_field_ref (loc, ll_inner, lntype,
ll_bitsize + rl_bitsize,
MIN (ll_bitpos, rl_bitpos), ll_unsignedp);
rhs = make_bit_field_ref (loc, lr_inner, rntype,
lr_bitsize + rr_bitsize,
MIN (lr_bitpos, rr_bitpos), lr_unsignedp);
ll_mask = const_binop (RSHIFT_EXPR, ll_mask,
size_int (MIN (xll_bitpos, xrl_bitpos)));
lr_mask = const_binop (RSHIFT_EXPR, lr_mask,
size_int (MIN (xlr_bitpos, xrr_bitpos)));
/* Convert to the smaller type before masking out unwanted bits. */
type = lntype;
if (lntype != rntype)
{
if (lnbitsize > rnbitsize)
{
lhs = fold_convert_loc (loc, rntype, lhs);
ll_mask = fold_convert_loc (loc, rntype, ll_mask);
type = rntype;
}
else if (lnbitsize < rnbitsize)
{
rhs = fold_convert_loc (loc, lntype, rhs);
lr_mask = fold_convert_loc (loc, lntype, lr_mask);
type = lntype;
}
}
if (! all_ones_mask_p (ll_mask, ll_bitsize + rl_bitsize))
lhs = build2 (BIT_AND_EXPR, type, lhs, ll_mask);
if (! all_ones_mask_p (lr_mask, lr_bitsize + rr_bitsize))
rhs = build2 (BIT_AND_EXPR, type, rhs, lr_mask);
return build2_loc (loc, wanted_code, truth_type, lhs, rhs);
}
return 0;
}
/* Handle the case of comparisons with constants. If there is something in
common between the masks, those bits of the constants must be the same.
If not, the condition is always false. Test for this to avoid generating
incorrect code below. */
result = const_binop (BIT_AND_EXPR, ll_mask, rl_mask);
if (! integer_zerop (result)
&& simple_cst_equal (const_binop (BIT_AND_EXPR, result, l_const),
const_binop (BIT_AND_EXPR, result, r_const)) != 1)
{
if (wanted_code == NE_EXPR)
{
warning (0, "%<or%> of unmatched not-equal tests is always 1");
return constant_boolean_node (true, truth_type);
}
else
{
warning (0, "%<and%> of mutually exclusive equal-tests is always 0");
return constant_boolean_node (false, truth_type);
}
}
/* Construct the expression we will return. First get the component
reference we will make. Unless the mask is all ones the width of
that field, perform the mask operation. Then compare with the
merged constant. */
result = make_bit_field_ref (loc, ll_inner, lntype, lnbitsize, lnbitpos,
ll_unsignedp || rl_unsignedp);
ll_mask = const_binop (BIT_IOR_EXPR, ll_mask, rl_mask);
if (! all_ones_mask_p (ll_mask, lnbitsize))
result = build2_loc (loc, BIT_AND_EXPR, lntype, result, ll_mask);
return build2_loc (loc, wanted_code, truth_type, result,
const_binop (BIT_IOR_EXPR, l_const, r_const));
}
/* Optimize T, which is a comparison of a MIN_EXPR or MAX_EXPR with a
constant. */
static tree
optimize_minmax_comparison (location_t loc, enum tree_code code, tree type,
tree op0, tree op1)
{
tree arg0 = op0;
enum tree_code op_code;
tree comp_const;
tree minmax_const;
int consts_equal, consts_lt;
tree inner;
STRIP_SIGN_NOPS (arg0);
op_code = TREE_CODE (arg0);
minmax_const = TREE_OPERAND (arg0, 1);
comp_const = fold_convert_loc (loc, TREE_TYPE (arg0), op1);
consts_equal = tree_int_cst_equal (minmax_const, comp_const);
consts_lt = tree_int_cst_lt (minmax_const, comp_const);
inner = TREE_OPERAND (arg0, 0);
/* If something does not permit us to optimize, return the original tree. */
if ((op_code != MIN_EXPR && op_code != MAX_EXPR)
|| TREE_CODE (comp_const) != INTEGER_CST
|| TREE_OVERFLOW (comp_const)
|| TREE_CODE (minmax_const) != INTEGER_CST
|| TREE_OVERFLOW (minmax_const))
return NULL_TREE;
/* Now handle all the various comparison codes. We only handle EQ_EXPR
and GT_EXPR, doing the rest with recursive calls using logical
simplifications. */
switch (code)
{
case NE_EXPR: case LT_EXPR: case LE_EXPR:
{
tree tem
= optimize_minmax_comparison (loc,
invert_tree_comparison (code, false),
type, op0, op1);
if (tem)
return invert_truthvalue_loc (loc, tem);
return NULL_TREE;
}
case GE_EXPR:
return
fold_build2_loc (loc, TRUTH_ORIF_EXPR, type,
optimize_minmax_comparison
(loc, EQ_EXPR, type, arg0, comp_const),
optimize_minmax_comparison
(loc, GT_EXPR, type, arg0, comp_const));
case EQ_EXPR:
if (op_code == MAX_EXPR && consts_equal)
/* MAX (X, 0) == 0 -> X <= 0 */
return fold_build2_loc (loc, LE_EXPR, type, inner, comp_const);
else if (op_code == MAX_EXPR && consts_lt)
/* MAX (X, 0) == 5 -> X == 5 */
return fold_build2_loc (loc, EQ_EXPR, type, inner, comp_const);
else if (op_code == MAX_EXPR)
/* MAX (X, 0) == -1 -> false */
return omit_one_operand_loc (loc, type, integer_zero_node, inner);
else if (consts_equal)
/* MIN (X, 0) == 0 -> X >= 0 */
return fold_build2_loc (loc, GE_EXPR, type, inner, comp_const);
else if (consts_lt)
/* MIN (X, 0) == 5 -> false */
return omit_one_operand_loc (loc, type, integer_zero_node, inner);
else
/* MIN (X, 0) == -1 -> X == -1 */
return fold_build2_loc (loc, EQ_EXPR, type, inner, comp_const);
case GT_EXPR:
if (op_code == MAX_EXPR && (consts_equal || consts_lt))
/* MAX (X, 0) > 0 -> X > 0
MAX (X, 0) > 5 -> X > 5 */
return fold_build2_loc (loc, GT_EXPR, type, inner, comp_const);
else if (op_code == MAX_EXPR)
/* MAX (X, 0) > -1 -> true */
return omit_one_operand_loc (loc, type, integer_one_node, inner);
else if (op_code == MIN_EXPR && (consts_equal || consts_lt))
/* MIN (X, 0) > 0 -> false
MIN (X, 0) > 5 -> false */
return omit_one_operand_loc (loc, type, integer_zero_node, inner);
else
/* MIN (X, 0) > -1 -> X > -1 */
return fold_build2_loc (loc, GT_EXPR, type, inner, comp_const);
default:
return NULL_TREE;
}
}
/* T is an integer expression that is being multiplied, divided, or taken a
modulus (CODE says which and what kind of divide or modulus) by a
constant C. See if we can eliminate that operation by folding it with
other operations already in T. WIDE_TYPE, if non-null, is a type that
should be used for the computation if wider than our type.
For example, if we are dividing (X * 8) + (Y * 16) by 4, we can return
(X * 2) + (Y * 4). We must, however, be assured that either the original
expression would not overflow or that overflow is undefined for the type
in the language in question.
If we return a non-null expression, it is an equivalent form of the
original computation, but need not be in the original type.
We set *STRICT_OVERFLOW_P to true if the return values depends on
signed overflow being undefined. Otherwise we do not change
*STRICT_OVERFLOW_P. */
static tree
extract_muldiv (tree t, tree c, enum tree_code code, tree wide_type,
bool *strict_overflow_p)
{
/* To avoid exponential search depth, refuse to allow recursion past
three levels. Beyond that (1) it's highly unlikely that we'll find
something interesting and (2) we've probably processed it before
when we built the inner expression. */
static int depth;
tree ret;
if (depth > 3)
return NULL;
depth++;
ret = extract_muldiv_1 (t, c, code, wide_type, strict_overflow_p);
depth--;
return ret;
}
static tree
extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type,
bool *strict_overflow_p)
{
tree type = TREE_TYPE (t);
enum tree_code tcode = TREE_CODE (t);
tree ctype = (wide_type != 0 && (GET_MODE_SIZE (TYPE_MODE (wide_type))
> GET_MODE_SIZE (TYPE_MODE (type)))
? wide_type : type);
tree t1, t2;
int same_p = tcode == code;
tree op0 = NULL_TREE, op1 = NULL_TREE;
bool sub_strict_overflow_p;
/* Don't deal with constants of zero here; they confuse the code below. */
if (integer_zerop (c))
return NULL_TREE;
if (TREE_CODE_CLASS (tcode) == tcc_unary)
op0 = TREE_OPERAND (t, 0);
if (TREE_CODE_CLASS (tcode) == tcc_binary)
op0 = TREE_OPERAND (t, 0), op1 = TREE_OPERAND (t, 1);
/* Note that we need not handle conditional operations here since fold
already handles those cases. So just do arithmetic here. */
switch (tcode)
{
case INTEGER_CST:
/* For a constant, we can always simplify if we are a multiply
or (for divide and modulus) if it is a multiple of our constant. */
if (code == MULT_EXPR
|| integer_zerop (const_binop (TRUNC_MOD_EXPR, t, c)))
return const_binop (code, fold_convert (ctype, t),
fold_convert (ctype, c));
break;
CASE_CONVERT: case NON_LVALUE_EXPR:
/* If op0 is an expression ... */
if ((COMPARISON_CLASS_P (op0)
|| UNARY_CLASS_P (op0)
|| BINARY_CLASS_P (op0)
|| VL_EXP_CLASS_P (op0)
|| EXPRESSION_CLASS_P (op0))
/* ... and has wrapping overflow, and its type is smaller
than ctype, then we cannot pass through as widening. */
&& ((TYPE_OVERFLOW_WRAPS (TREE_TYPE (op0))
&& (TYPE_PRECISION (ctype)
> TYPE_PRECISION (TREE_TYPE (op0))))
/* ... or this is a truncation (t is narrower than op0),
then we cannot pass through this narrowing. */
|| (TYPE_PRECISION (type)
< TYPE_PRECISION (TREE_TYPE (op0)))
/* ... or signedness changes for division or modulus,
then we cannot pass through this conversion. */
|| (code != MULT_EXPR
&& (TYPE_UNSIGNED (ctype)
!= TYPE_UNSIGNED (TREE_TYPE (op0))))
/* ... or has undefined overflow while the converted to
type has not, we cannot do the operation in the inner type
as that would introduce undefined overflow. */
|| (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (op0))
&& !TYPE_OVERFLOW_UNDEFINED (type))))
break;
/* Pass the constant down and see if we can make a simplification. If
we can, replace this expression with the inner simplification for
possible later conversion to our or some other type. */
if ((t2 = fold_convert (TREE_TYPE (op0), c)) != 0
&& TREE_CODE (t2) == INTEGER_CST
&& !TREE_OVERFLOW (t2)
&& (0 != (t1 = extract_muldiv (op0, t2, code,
code == MULT_EXPR
? ctype : NULL_TREE,
strict_overflow_p))))
return t1;
break;
case ABS_EXPR:
/* If widening the type changes it from signed to unsigned, then we
must avoid building ABS_EXPR itself as unsigned. */
if (TYPE_UNSIGNED (ctype) && !TYPE_UNSIGNED (type))
{
tree cstype = (*signed_type_for) (ctype);
if ((t1 = extract_muldiv (op0, c, code, cstype, strict_overflow_p))
!= 0)
{
t1 = fold_build1 (tcode, cstype, fold_convert (cstype, t1));
return fold_convert (ctype, t1);
}
break;
}
/* If the constant is negative, we cannot simplify this. */
if (tree_int_cst_sgn (c) == -1)
break;
/* FALLTHROUGH */
case NEGATE_EXPR:
/* For division and modulus, type can't be unsigned, as e.g.
(-(x / 2U)) / 2U isn't equal to -((x / 2U) / 2U) for x >= 2.
For signed types, even with wrapping overflow, this is fine. */
if (code != MULT_EXPR && TYPE_UNSIGNED (type))
break;
if ((t1 = extract_muldiv (op0, c, code, wide_type, strict_overflow_p))
!= 0)
return fold_build1 (tcode, ctype, fold_convert (ctype, t1));
break;
case MIN_EXPR: case MAX_EXPR:
/* If widening the type changes the signedness, then we can't perform
this optimization as that changes the result. */
if (TYPE_UNSIGNED (ctype) != TYPE_UNSIGNED (type))
break;
/* MIN (a, b) / 5 -> MIN (a / 5, b / 5) */
sub_strict_overflow_p = false;
if ((t1 = extract_muldiv (op0, c, code, wide_type,
&sub_strict_overflow_p)) != 0
&& (t2 = extract_muldiv (op1, c, code, wide_type,
&sub_strict_overflow_p)) != 0)
{
if (tree_int_cst_sgn (c) < 0)
tcode = (tcode == MIN_EXPR ? MAX_EXPR : MIN_EXPR);
if (sub_strict_overflow_p)
*strict_overflow_p = true;
return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
fold_convert (ctype, t2));
}
break;
case LSHIFT_EXPR: case RSHIFT_EXPR:
/* If the second operand is constant, this is a multiplication
or floor division, by a power of two, so we can treat it that
way unless the multiplier or divisor overflows. Signed
left-shift overflow is implementation-defined rather than
undefined in C90, so do not convert signed left shift into
multiplication. */
if (TREE_CODE (op1) == INTEGER_CST
&& (tcode == RSHIFT_EXPR || TYPE_UNSIGNED (TREE_TYPE (op0)))
/* const_binop may not detect overflow correctly,
so check for it explicitly here. */
&& TYPE_PRECISION (TREE_TYPE (size_one_node)) > TREE_INT_CST_LOW (op1)
&& TREE_INT_CST_HIGH (op1) == 0
&& 0 != (t1 = fold_convert (ctype,
const_binop (LSHIFT_EXPR,
size_one_node,
op1)))
&& !TREE_OVERFLOW (t1))
return extract_muldiv (build2 (tcode == LSHIFT_EXPR
? MULT_EXPR : FLOOR_DIV_EXPR,
ctype,
fold_convert (ctype, op0),
t1),
c, code, wide_type, strict_overflow_p);
break;
case PLUS_EXPR: case MINUS_EXPR:
/* See if we can eliminate the operation on both sides. If we can, we
can return a new PLUS or MINUS. If we can't, the only remaining
cases where we can do anything are if the second operand is a
constant. */
sub_strict_overflow_p = false;
t1 = extract_muldiv (op0, c, code, wide_type, &sub_strict_overflow_p);
t2 = extract_muldiv (op1, c, code, wide_type, &sub_strict_overflow_p);
if (t1 != 0 && t2 != 0
&& (code == MULT_EXPR
/* If not multiplication, we can only do this if both operands
are divisible by c. */
|| (multiple_of_p (ctype, op0, c)
&& multiple_of_p (ctype, op1, c))))
{
if (sub_strict_overflow_p)
*strict_overflow_p = true;
return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
fold_convert (ctype, t2));
}
/* If this was a subtraction, negate OP1 and set it to be an addition.
This simplifies the logic below. */
if (tcode == MINUS_EXPR)
{
tcode = PLUS_EXPR, op1 = negate_expr (op1);
/* If OP1 was not easily negatable, the constant may be OP0. */
if (TREE_CODE (op0) == INTEGER_CST)
{
tree tem = op0;
op0 = op1;
op1 = tem;
tem = t1;
t1 = t2;
t2 = tem;
}
}
if (TREE_CODE (op1) != INTEGER_CST)
break;
/* If either OP1 or C are negative, this optimization is not safe for
some of the division and remainder types while for others we need
to change the code. */
if (tree_int_cst_sgn (op1) < 0 || tree_int_cst_sgn (c) < 0)
{
if (code == CEIL_DIV_EXPR)
code = FLOOR_DIV_EXPR;
else if (code == FLOOR_DIV_EXPR)
code = CEIL_DIV_EXPR;
else if (code != MULT_EXPR
&& code != CEIL_MOD_EXPR && code != FLOOR_MOD_EXPR)
break;
}
/* If it's a multiply or a division/modulus operation of a multiple
of our constant, do the operation and verify it doesn't overflow. */
if (code == MULT_EXPR
|| integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c)))
{
op1 = const_binop (code, fold_convert (ctype, op1),
fold_convert (ctype, c));
/* We allow the constant to overflow with wrapping semantics. */
if (op1 == 0
|| (TREE_OVERFLOW (op1) && !TYPE_OVERFLOW_WRAPS (ctype)))
break;
}
else
break;
/* If we have an unsigned type, we cannot widen the operation since it
will change the result if the original computation overflowed. */
if (TYPE_UNSIGNED (ctype) && ctype != type)
break;
/* If we were able to eliminate our operation from the first side,
apply our operation to the second side and reform the PLUS. */
if (t1 != 0 && (TREE_CODE (t1) != code || code == MULT_EXPR))
return fold_build2 (tcode, ctype, fold_convert (ctype, t1), op1);
/* The last case is if we are a multiply. In that case, we can
apply the distributive law to commute the multiply and addition
if the multiplication of the constants doesn't overflow. */
if (code == MULT_EXPR)
return fold_build2 (tcode, ctype,
fold_build2 (code, ctype,
fold_convert (ctype, op0),
fold_convert (ctype, c)),
op1);
break;
case MULT_EXPR:
/* We have a special case here if we are doing something like
(C * 8) % 4 since we know that's zero. */
if ((code == TRUNC_MOD_EXPR || code == CEIL_MOD_EXPR
|| code == FLOOR_MOD_EXPR || code == ROUND_MOD_EXPR)
/* If the multiplication can overflow we cannot optimize this. */
&& TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (t))
&& TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
&& integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c)))
{
*strict_overflow_p = true;
return omit_one_operand (type, integer_zero_node, op0);
}
/* ... fall through ... */
case TRUNC_DIV_EXPR: case CEIL_DIV_EXPR: case FLOOR_DIV_EXPR:
case ROUND_DIV_EXPR: case EXACT_DIV_EXPR:
/* If we can extract our operation from the LHS, do so and return a
new operation. Likewise for the RHS from a MULT_EXPR. Otherwise,
do something only if the second operand is a constant. */
if (same_p
&& (t1 = extract_muldiv (op0, c, code, wide_type,
strict_overflow_p)) != 0)
return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
fold_convert (ctype, op1));
else if (tcode == MULT_EXPR && code == MULT_EXPR
&& (t1 = extract_muldiv (op1, c, code, wide_type,
strict_overflow_p)) != 0)
return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
fold_convert (ctype, t1));
else if (TREE_CODE (op1) != INTEGER_CST)
return 0;
/* If these are the same operation types, we can associate them
assuming no overflow. */
if (tcode == code)
{
double_int mul;
bool overflow_p;
unsigned prec = TYPE_PRECISION (ctype);
bool uns = TYPE_UNSIGNED (ctype);
double_int diop1 = tree_to_double_int (op1).ext (prec, uns);
double_int dic = tree_to_double_int (c).ext (prec, uns);
mul = diop1.mul_with_sign (dic, false, &overflow_p);
overflow_p = ((!uns && overflow_p)
| TREE_OVERFLOW (c) | TREE_OVERFLOW (op1));
if (!double_int_fits_to_tree_p (ctype, mul)
&& ((uns && tcode != MULT_EXPR) || !uns))
overflow_p = 1;
if (!overflow_p)
return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
double_int_to_tree (ctype, mul));
}
/* If these operations "cancel" each other, we have the main
optimizations of this pass, which occur when either constant is a
multiple of the other, in which case we replace this with either an
operation or CODE or TCODE.
If we have an unsigned type, we cannot do this since it will change
the result if the original computation overflowed. */
if (TYPE_OVERFLOW_UNDEFINED (ctype)
&& ((code == MULT_EXPR && tcode == EXACT_DIV_EXPR)
|| (tcode == MULT_EXPR
&& code != TRUNC_MOD_EXPR && code != CEIL_MOD_EXPR
&& code != FLOOR_MOD_EXPR && code != ROUND_MOD_EXPR
&& code != MULT_EXPR)))
{
if (integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c)))
{
if (TYPE_OVERFLOW_UNDEFINED (ctype))
*strict_overflow_p = true;
return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
fold_convert (ctype,
const_binop (TRUNC_DIV_EXPR,
op1, c)));
}
else if (integer_zerop (const_binop (TRUNC_MOD_EXPR, c, op1)))
{
if (TYPE_OVERFLOW_UNDEFINED (ctype))
*strict_overflow_p = true;
return fold_build2 (code, ctype, fold_convert (ctype, op0),
fold_convert (ctype,
const_binop (TRUNC_DIV_EXPR,
c, op1)));
}
}
break;
default:
break;
}
return 0;
}
/* Return a node which has the indicated constant VALUE (either 0 or
1 for scalars or {-1,-1,..} or {0,0,...} for vectors),
and is of the indicated TYPE. */
tree
constant_boolean_node (bool value, tree type)
{
if (type == integer_type_node)
return value ? integer_one_node : integer_zero_node;
else if (type == boolean_type_node)
return value ? boolean_true_node : boolean_false_node;
else if (TREE_CODE (type) == VECTOR_TYPE)
return build_vector_from_val (type,
build_int_cst (TREE_TYPE (type),
value ? -1 : 0));
else
return fold_convert (type, value ? integer_one_node : integer_zero_node);
}
/* Transform `a + (b ? x : y)' into `b ? (a + x) : (a + y)'.
Transform, `a + (x < y)' into `(x < y) ? (a + 1) : (a + 0)'. Here
CODE corresponds to the `+', COND to the `(b ? x : y)' or `(x < y)'
expression, and ARG to `a'. If COND_FIRST_P is nonzero, then the
COND is the first argument to CODE; otherwise (as in the example
given here), it is the second argument. TYPE is the type of the
original expression. Return NULL_TREE if no simplification is
possible. */
static tree
fold_binary_op_with_conditional_arg (location_t loc,
enum tree_code code,
tree type, tree op0, tree op1,
tree cond, tree arg, int cond_first_p)
{
tree cond_type = cond_first_p ? TREE_TYPE (op0) : TREE_TYPE (op1);
tree arg_type = cond_first_p ? TREE_TYPE (op1) : TREE_TYPE (op0);
tree test, true_value, false_value;
tree lhs = NULL_TREE;
tree rhs = NULL_TREE;
enum tree_code cond_code = COND_EXPR;
if (TREE_CODE (cond) == COND_EXPR
|| TREE_CODE (cond) == VEC_COND_EXPR)
{
test = TREE_OPERAND (cond, 0);
true_value = TREE_OPERAND (cond, 1);
false_value = TREE_OPERAND (cond, 2);
/* If this operand throws an expression, then it does not make
sense to try to perform a logical or arithmetic operation
involving it. */
if (VOID_TYPE_P (TREE_TYPE (true_value)))
lhs = true_value;
if (VOID_TYPE_P (TREE_TYPE (false_value)))
rhs = false_value;
}
else
{
tree testtype = TREE_TYPE (cond);
test = cond;
true_value = constant_boolean_node (true, testtype);
false_value = constant_boolean_node (false, testtype);
}
if (TREE_CODE (TREE_TYPE (test)) == VECTOR_TYPE)
cond_code = VEC_COND_EXPR;
/* This transformation is only worthwhile if we don't have to wrap ARG
in a SAVE_EXPR and the operation can be simplified without recursing
on at least one of the branches once its pushed inside the COND_EXPR. */
if (!TREE_CONSTANT (arg)
&& (TREE_SIDE_EFFECTS (arg)
|| TREE_CODE (arg) == COND_EXPR || TREE_CODE (arg) == VEC_COND_EXPR
|| TREE_CONSTANT (true_value) || TREE_CONSTANT (false_value)))
return NULL_TREE;
arg = fold_convert_loc (loc, arg_type, arg);
if (lhs == 0)
{
true_value = fold_convert_loc (loc, cond_type, true_value);
if (cond_first_p)
lhs = fold_build2_loc (loc, code, type, true_value, arg);
else
lhs = fold_build2_loc (loc, code, type, arg, true_value);
}
if (rhs == 0)
{
false_value = fold_convert_loc (loc, cond_type, false_value);
if (cond_first_p)
rhs = fold_build2_loc (loc, code, type, false_value, arg);
else
rhs = fold_build2_loc (loc, code, type, arg, false_value);
}
/* Check that we have simplified at least one of the branches. */
if (!TREE_CONSTANT (arg) && !TREE_CONSTANT (lhs) && !TREE_CONSTANT (rhs))
return NULL_TREE;
return fold_build3_loc (loc, cond_code, type, test, lhs, rhs);
}
/* Subroutine of fold() that checks for the addition of +/- 0.0.
If !NEGATE, return true if ADDEND is +/-0.0 and, for all X of type
TYPE, X + ADDEND is the same as X. If NEGATE, return true if X -
ADDEND is the same as X.
X + 0 and X - 0 both give X when X is NaN, infinite, or nonzero
and finite. The problematic cases are when X is zero, and its mode
has signed zeros. In the case of rounding towards -infinity,
X - 0 is not the same as X because 0 - 0 is -0. In other rounding
modes, X + 0 is not the same as X because -0 + 0 is 0. */
bool
fold_real_zero_addition_p (const_tree type, const_tree addend, int negate)
{
if (!real_zerop (addend))
return false;
/* Don't allow the fold with -fsignaling-nans. */
if (HONOR_SNANS (TYPE_MODE (type)))
return false;
/* Allow the fold if zeros aren't signed, or their sign isn't important. */
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (type)))
return true;
/* Treat x + -0 as x - 0 and x - -0 as x + 0. */
if (TREE_CODE (addend) == REAL_CST
&& REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (addend)))
negate = !negate;
/* The mode has signed zeros, and we have to honor their sign.
In this situation, there is only one case we can return true for.
X - 0 is the same as X unless rounding towards -infinity is
supported. */
return negate && !HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type));
}
/* Subroutine of fold() that checks comparisons of built-in math
functions against real constants.
FCODE is the DECL_FUNCTION_CODE of the built-in, CODE is the comparison
operator: EQ_EXPR, NE_EXPR, GT_EXPR, LT_EXPR, GE_EXPR or LE_EXPR. TYPE
is the type of the result and ARG0 and ARG1 are the operands of the
comparison. ARG1 must be a TREE_REAL_CST.
The function returns the constant folded tree if a simplification
can be made, and NULL_TREE otherwise. */
static tree
fold_mathfn_compare (location_t loc,
enum built_in_function fcode, enum tree_code code,
tree type, tree arg0, tree arg1)
{
REAL_VALUE_TYPE c;
if (BUILTIN_SQRT_P (fcode))
{
tree arg = CALL_EXPR_ARG (arg0, 0);
enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg0));
c = TREE_REAL_CST (arg1);
if (REAL_VALUE_NEGATIVE (c))
{
/* sqrt(x) < y is always false, if y is negative. */
if (code == EQ_EXPR || code == LT_EXPR || code == LE_EXPR)
return omit_one_operand_loc (loc, type, integer_zero_node, arg);
/* sqrt(x) > y is always true, if y is negative and we
don't care about NaNs, i.e. negative values of x. */
if (code == NE_EXPR || !HONOR_NANS (mode))
return omit_one_operand_loc (loc, type, integer_one_node, arg);
/* sqrt(x) > y is the same as x >= 0, if y is negative. */
return fold_build2_loc (loc, GE_EXPR, type, arg,
build_real (TREE_TYPE (arg), dconst0));
}
else if (code == GT_EXPR || code == GE_EXPR)
{
REAL_VALUE_TYPE c2;
REAL_ARITHMETIC (c2, MULT_EXPR, c, c);
real_convert (&c2, mode, &c2);
if (REAL_VALUE_ISINF (c2))
{
/* sqrt(x) > y is x == +Inf, when y is very large. */
if (HONOR_INFINITIES (mode))
return fold_build2_loc (loc, EQ_EXPR, type, arg,
build_real (TREE_TYPE (arg), c2));
/* sqrt(x) > y is always false, when y is very large
and we don't care about infinities. */
return omit_one_operand_loc (loc, type, integer_zero_node, arg);
}
/* sqrt(x) > c is the same as x > c*c. */
return fold_build2_loc (loc, code, type, arg,
build_real (TREE_TYPE (arg), c2));
}
else if (code == LT_EXPR || code == LE_EXPR)
{
REAL_VALUE_TYPE c2;
REAL_ARITHMETIC (c2, MULT_EXPR, c, c);
real_convert (&c2, mode, &c2);
if (REAL_VALUE_ISINF (c2))
{
/* sqrt(x) < y is always true, when y is a very large
value and we don't care about NaNs or Infinities. */
if (! HONOR_NANS (mode) && ! HONOR_INFINITIES (mode))
return omit_one_operand_loc (loc, type, integer_one_node, arg);
/* sqrt(x) < y is x != +Inf when y is very large and we
don't care about NaNs. */
if (! HONOR_NANS (mode))
return fold_build2_loc (loc, NE_EXPR, type, arg,
build_real (TREE_TYPE (arg), c2));
/* sqrt(x) < y is x >= 0 when y is very large and we
don't care about Infinities. */
if (! HONOR_INFINITIES (mode))
return fold_build2_loc (loc, GE_EXPR, type, arg,
build_real (TREE_TYPE (arg), dconst0));
/* sqrt(x) < y is x >= 0 && x != +Inf, when y is large. */
arg = save_expr (arg);
return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type,
fold_build2_loc (loc, GE_EXPR, type, arg,
build_real (TREE_TYPE (arg),
dconst0)),
fold_build2_loc (loc, NE_EXPR, type, arg,
build_real (TREE_TYPE (arg),
c2)));
}
/* sqrt(x) < c is the same as x < c*c, if we ignore NaNs. */
if (! HONOR_NANS (mode))
return fold_build2_loc (loc, code, type, arg,
build_real (TREE_TYPE (arg), c2));
/* sqrt(x) < c is the same as x >= 0 && x < c*c. */
arg = save_expr (arg);
return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type,
fold_build2_loc (loc, GE_EXPR, type, arg,
build_real (TREE_TYPE (arg),
dconst0)),
fold_build2_loc (loc, code, type, arg,
build_real (TREE_TYPE (arg),
c2)));
}
}
return NULL_TREE;
}
/* Subroutine of fold() that optimizes comparisons against Infinities,
either +Inf or -Inf.
CODE is the comparison operator: EQ_EXPR, NE_EXPR, GT_EXPR, LT_EXPR,
GE_EXPR or LE_EXPR. TYPE is the type of the result and ARG0 and ARG1
are the operands of the comparison. ARG1 must be a TREE_REAL_CST.
The function returns the constant folded tree if a simplification
can be made, and NULL_TREE otherwise. */
static tree
fold_inf_compare (location_t loc, enum tree_code code, tree type,
tree arg0, tree arg1)
{
enum machine_mode mode;
REAL_VALUE_TYPE max;
tree temp;
bool neg;
mode = TYPE_MODE (TREE_TYPE (arg0));
/* For negative infinity swap the sense of the comparison. */
neg = REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1));
if (neg)
code = swap_tree_comparison (code);
switch (code)
{
case GT_EXPR:
/* x > +Inf is always false, if with ignore sNANs. */
if (HONOR_SNANS (mode))
return NULL_TREE;
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
case LE_EXPR:
/* x <= +Inf is always true, if we don't case about NaNs. */
if (! HONOR_NANS (mode))
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
/* x <= +Inf is the same as x == x, i.e. isfinite(x). */
arg0 = save_expr (arg0);
return fold_build2_loc (loc, EQ_EXPR, type, arg0, arg0);
case EQ_EXPR:
case GE_EXPR:
/* x == +Inf and x >= +Inf are always equal to x > DBL_MAX. */
real_maxval (&max, neg, mode);
return fold_build2_loc (loc, neg ? LT_EXPR : GT_EXPR, type,
arg0, build_real (TREE_TYPE (arg0), max));
case LT_EXPR:
/* x < +Inf is always equal to x <= DBL_MAX. */
real_maxval (&max, neg, mode);
return fold_build2_loc (loc, neg ? GE_EXPR : LE_EXPR, type,
arg0, build_real (TREE_TYPE (arg0), max));
case NE_EXPR:
/* x != +Inf is always equal to !(x > DBL_MAX). */
real_maxval (&max, neg, mode);
if (! HONOR_NANS (mode))
return fold_build2_loc (loc, neg ? GE_EXPR : LE_EXPR, type,
arg0, build_real (TREE_TYPE (arg0), max));
temp = fold_build2_loc (loc, neg ? LT_EXPR : GT_EXPR, type,
arg0, build_real (TREE_TYPE (arg0), max));
return fold_build1_loc (loc, TRUTH_NOT_EXPR, type, temp);
default:
break;
}
return NULL_TREE;
}
/* Subroutine of fold() that optimizes comparisons of a division by
a nonzero integer constant against an integer constant, i.e.
X/C1 op C2.
CODE is the comparison operator: EQ_EXPR, NE_EXPR, GT_EXPR, LT_EXPR,
GE_EXPR or LE_EXPR. TYPE is the type of the result and ARG0 and ARG1
are the operands of the comparison. ARG1 must be a TREE_REAL_CST.
The function returns the constant folded tree if a simplification
can be made, and NULL_TREE otherwise. */
static tree
fold_div_compare (location_t loc,
enum tree_code code, tree type, tree arg0, tree arg1)
{
tree prod, tmp, hi, lo;
tree arg00 = TREE_OPERAND (arg0, 0);
tree arg01 = TREE_OPERAND (arg0, 1);
double_int val;
bool unsigned_p = TYPE_UNSIGNED (TREE_TYPE (arg0));
bool neg_overflow;
bool overflow;
/* We have to do this the hard way to detect unsigned overflow.
prod = int_const_binop (MULT_EXPR, arg01, arg1); */
val = TREE_INT_CST (arg01)
.mul_with_sign (TREE_INT_CST (arg1), unsigned_p, &overflow);
prod = force_fit_type_double (TREE_TYPE (arg00), val, -1, overflow);
neg_overflow = false;
if (unsigned_p)
{
tmp = int_const_binop (MINUS_EXPR, arg01,
build_int_cst (TREE_TYPE (arg01), 1));
lo = prod;
/* Likewise hi = int_const_binop (PLUS_EXPR, prod, tmp). */
val = TREE_INT_CST (prod)
.add_with_sign (TREE_INT_CST (tmp), unsigned_p, &overflow);
hi = force_fit_type_double (TREE_TYPE (arg00), val,
-1, overflow | TREE_OVERFLOW (prod));
}
else if (tree_int_cst_sgn (arg01) >= 0)
{
tmp = int_const_binop (MINUS_EXPR, arg01,
build_int_cst (TREE_TYPE (arg01), 1));
switch (tree_int_cst_sgn (arg1))
{
case -1:
neg_overflow = true;
lo = int_const_binop (MINUS_EXPR, prod, tmp);
hi = prod;
break;
case 0:
lo = fold_negate_const (tmp, TREE_TYPE (arg0));
hi = tmp;
break;
case 1:
hi = int_const_binop (PLUS_EXPR, prod, tmp);
lo = prod;
break;
default:
gcc_unreachable ();
}
}
else
{
/* A negative divisor reverses the relational operators. */
code = swap_tree_comparison (code);
tmp = int_const_binop (PLUS_EXPR, arg01,
build_int_cst (TREE_TYPE (arg01), 1));
switch (tree_int_cst_sgn (arg1))
{
case -1:
hi = int_const_binop (MINUS_EXPR, prod, tmp);
lo = prod;
break;
case 0:
hi = fold_negate_const (tmp, TREE_TYPE (arg0));
lo = tmp;
break;
case 1:
neg_overflow = true;
lo = int_const_binop (PLUS_EXPR, prod, tmp);
hi = prod;
break;
default:
gcc_unreachable ();
}
}
switch (code)
{
case EQ_EXPR:
if (TREE_OVERFLOW (lo) && TREE_OVERFLOW (hi))
return omit_one_operand_loc (loc, type, integer_zero_node, arg00);
if (TREE_OVERFLOW (hi))
return fold_build2_loc (loc, GE_EXPR, type, arg00, lo);
if (TREE_OVERFLOW (lo))
return fold_build2_loc (loc, LE_EXPR, type, arg00, hi);
return build_range_check (loc, type, arg00, 1, lo, hi);
case NE_EXPR:
if (TREE_OVERFLOW (lo) && TREE_OVERFLOW (hi))
return omit_one_operand_loc (loc, type, integer_one_node, arg00);
if (TREE_OVERFLOW (hi))
return fold_build2_loc (loc, LT_EXPR, type, arg00, lo);
if (TREE_OVERFLOW (lo))
return fold_build2_loc (loc, GT_EXPR, type, arg00, hi);
return build_range_check (loc, type, arg00, 0, lo, hi);
case LT_EXPR:
if (TREE_OVERFLOW (lo))
{
tmp = neg_overflow ? integer_zero_node : integer_one_node;
return omit_one_operand_loc (loc, type, tmp, arg00);
}
return fold_build2_loc (loc, LT_EXPR, type, arg00, lo);
case LE_EXPR:
if (TREE_OVERFLOW (hi))
{
tmp = neg_overflow ? integer_zero_node : integer_one_node;
return omit_one_operand_loc (loc, type, tmp, arg00);
}
return fold_build2_loc (loc, LE_EXPR, type, arg00, hi);
case GT_EXPR:
if (TREE_OVERFLOW (hi))
{
tmp = neg_overflow ? integer_one_node : integer_zero_node;
return omit_one_operand_loc (loc, type, tmp, arg00);
}
return fold_build2_loc (loc, GT_EXPR, type, arg00, hi);
case GE_EXPR:
if (TREE_OVERFLOW (lo))
{
tmp = neg_overflow ? integer_one_node : integer_zero_node;
return omit_one_operand_loc (loc, type, tmp, arg00);
}
return fold_build2_loc (loc, GE_EXPR, type, arg00, lo);
default:
break;
}
return NULL_TREE;
}
/* If CODE with arguments ARG0 and ARG1 represents a single bit
equality/inequality test, then return a simplified form of the test
using a sign testing. Otherwise return NULL. TYPE is the desired
result type. */
static tree
fold_single_bit_test_into_sign_test (location_t loc,
enum tree_code code, tree arg0, tree arg1,
tree result_type)
{
/* If this is testing a single bit, we can optimize the test. */
if ((code == NE_EXPR || code == EQ_EXPR)
&& TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
&& integer_pow2p (TREE_OPERAND (arg0, 1)))
{
/* If we have (A & C) != 0 where C is the sign bit of A, convert
this into A < 0. Similarly for (A & C) == 0 into A >= 0. */
tree arg00 = sign_bit_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1));
if (arg00 != NULL_TREE
/* This is only a win if casting to a signed type is cheap,
i.e. when arg00's type is not a partial mode. */
&& TYPE_PRECISION (TREE_TYPE (arg00))
== GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (arg00))))
{
tree stype = signed_type_for (TREE_TYPE (arg00));
return fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR,
result_type,
fold_convert_loc (loc, stype, arg00),
build_int_cst (stype, 0));
}
}
return NULL_TREE;
}
/* If CODE with arguments ARG0 and ARG1 represents a single bit
equality/inequality test, then return a simplified form of
the test using shifts and logical operations. Otherwise return
NULL. TYPE is the desired result type. */
tree
fold_single_bit_test (location_t loc, enum tree_code code,
tree arg0, tree arg1, tree result_type)
{
/* If this is testing a single bit, we can optimize the test. */
if ((code == NE_EXPR || code == EQ_EXPR)
&& TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
&& integer_pow2p (TREE_OPERAND (arg0, 1)))
{
tree inner = TREE_OPERAND (arg0, 0);
tree type = TREE_TYPE (arg0);
int bitnum = tree_log2 (TREE_OPERAND (arg0, 1));
enum machine_mode operand_mode = TYPE_MODE (type);
int ops_unsigned;
tree signed_type, unsigned_type, intermediate_type;
tree tem, one;
/* First, see if we can fold the single bit test into a sign-bit
test. */
tem = fold_single_bit_test_into_sign_test (loc, code, arg0, arg1,
result_type);
if (tem)
return tem;
/* Otherwise we have (A & C) != 0 where C is a single bit,
convert that into ((A >> C2) & 1). Where C2 = log2(C).
Similarly for (A & C) == 0. */
/* If INNER is a right shift of a constant and it plus BITNUM does
not overflow, adjust BITNUM and INNER. */
if (TREE_CODE (inner) == RSHIFT_EXPR
&& TREE_CODE (TREE_OPERAND (inner, 1)) == INTEGER_CST
&& TREE_INT_CST_HIGH (TREE_OPERAND (inner, 1)) == 0
&& bitnum < TYPE_PRECISION (type)
&& 0 > compare_tree_int (TREE_OPERAND (inner, 1),
bitnum - TYPE_PRECISION (type)))
{
bitnum += TREE_INT_CST_LOW (TREE_OPERAND (inner, 1));
inner = TREE_OPERAND (inner, 0);
}
/* If we are going to be able to omit the AND below, we must do our
operations as unsigned. If we must use the AND, we have a choice.
Normally unsigned is faster, but for some machines signed is. */
#ifdef LOAD_EXTEND_OP
ops_unsigned = (LOAD_EXTEND_OP (operand_mode) == SIGN_EXTEND
&& !flag_syntax_only) ? 0 : 1;
#else
ops_unsigned = 1;
#endif
signed_type = lang_hooks.types.type_for_mode (operand_mode, 0);
unsigned_type = lang_hooks.types.type_for_mode (operand_mode, 1);
intermediate_type = ops_unsigned ? unsigned_type : signed_type;
inner = fold_convert_loc (loc, intermediate_type, inner);
if (bitnum != 0)
inner = build2 (RSHIFT_EXPR, intermediate_type,
inner, size_int (bitnum));
one = build_int_cst (intermediate_type, 1);
if (code == EQ_EXPR)
inner = fold_build2_loc (loc, BIT_XOR_EXPR, intermediate_type, inner, one);
/* Put the AND last so it can combine with more things. */
inner = build2 (BIT_AND_EXPR, intermediate_type, inner, one);
/* Make sure to return the proper type. */
inner = fold_convert_loc (loc, result_type, inner);
return inner;
}
return NULL_TREE;
}
/* Check whether we are allowed to reorder operands arg0 and arg1,
such that the evaluation of arg1 occurs before arg0. */
static bool
reorder_operands_p (const_tree arg0, const_tree arg1)
{
if (! flag_evaluation_order)
return true;
if (TREE_CONSTANT (arg0) || TREE_CONSTANT (arg1))
return true;
return ! TREE_SIDE_EFFECTS (arg0)
&& ! TREE_SIDE_EFFECTS (arg1);
}
/* Test whether it is preferable two swap two operands, ARG0 and
ARG1, for example because ARG0 is an integer constant and ARG1
isn't. If REORDER is true, only recommend swapping if we can
evaluate the operands in reverse order. */
bool
tree_swap_operands_p (const_tree arg0, const_tree arg1, bool reorder)
{
STRIP_SIGN_NOPS (arg0);
STRIP_SIGN_NOPS (arg1);
if (TREE_CODE (arg1) == INTEGER_CST)
return 0;
if (TREE_CODE (arg0) == INTEGER_CST)
return 1;
if (TREE_CODE (arg1) == REAL_CST)
return 0;
if (TREE_CODE (arg0) == REAL_CST)
return 1;
if (TREE_CODE (arg1) == FIXED_CST)
return 0;
if (TREE_CODE (arg0) == FIXED_CST)
return 1;
if (TREE_CODE (arg1) == COMPLEX_CST)
return 0;
if (TREE_CODE (arg0) == COMPLEX_CST)
return 1;
if (TREE_CONSTANT (arg1))
return 0;
if (TREE_CONSTANT (arg0))
return 1;
if (optimize_function_for_size_p (cfun))
return 0;
if (reorder && flag_evaluation_order
&& (TREE_SIDE_EFFECTS (arg0) || TREE_SIDE_EFFECTS (arg1)))
return 0;
/* It is preferable to swap two SSA_NAME to ensure a canonical form
for commutative and comparison operators. Ensuring a canonical
form allows the optimizers to find additional redundancies without
having to explicitly check for both orderings. */
if (TREE_CODE (arg0) == SSA_NAME
&& TREE_CODE (arg1) == SSA_NAME
&& SSA_NAME_VERSION (arg0) > SSA_NAME_VERSION (arg1))
return 1;
/* Put SSA_NAMEs last. */
if (TREE_CODE (arg1) == SSA_NAME)
return 0;
if (TREE_CODE (arg0) == SSA_NAME)
return 1;
/* Put variables last. */
if (DECL_P (arg1))
return 0;
if (DECL_P (arg0))
return 1;
return 0;
}
/* Fold comparison ARG0 CODE ARG1 (with result in TYPE), where
ARG0 is extended to a wider type. */
static tree
fold_widened_comparison (location_t loc, enum tree_code code,
tree type, tree arg0, tree arg1)
{
tree arg0_unw = get_unwidened (arg0, NULL_TREE);
tree arg1_unw;
tree shorter_type, outer_type;
tree min, max;
bool above, below;
if (arg0_unw == arg0)
return NULL_TREE;
shorter_type = TREE_TYPE (arg0_unw);
#ifdef HAVE_canonicalize_funcptr_for_compare
/* Disable this optimization if we're casting a function pointer
type on targets that require function pointer canonicalization. */
if (HAVE_canonicalize_funcptr_for_compare
&& TREE_CODE (shorter_type) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (shorter_type)) == FUNCTION_TYPE)
return NULL_TREE;
#endif
if (TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (shorter_type))
return NULL_TREE;
arg1_unw = get_unwidened (arg1, NULL_TREE);
/* If possible, express the comparison in the shorter mode. */
if ((code == EQ_EXPR || code == NE_EXPR
|| TYPE_UNSIGNED (TREE_TYPE (arg0)) == TYPE_UNSIGNED (shorter_type))
&& (TREE_TYPE (arg1_unw) == shorter_type
|| ((TYPE_PRECISION (shorter_type)
>= TYPE_PRECISION (TREE_TYPE (arg1_unw)))
&& (TYPE_UNSIGNED (shorter_type)
== TYPE_UNSIGNED (TREE_TYPE (arg1_unw))))
|| (TREE_CODE (arg1_unw) == INTEGER_CST
&& (TREE_CODE (shorter_type) == INTEGER_TYPE
|| TREE_CODE (shorter_type) == BOOLEAN_TYPE)
&& int_fits_type_p (arg1_unw, shorter_type))))
return fold_build2_loc (loc, code, type, arg0_unw,
fold_convert_loc (loc, shorter_type, arg1_unw));
if (TREE_CODE (arg1_unw) != INTEGER_CST
|| TREE_CODE (shorter_type) != INTEGER_TYPE
|| !int_fits_type_p (arg1_unw, shorter_type))
return NULL_TREE;
/* If we are comparing with the integer that does not fit into the range
of the shorter type, the result is known. */
outer_type = TREE_TYPE (arg1_unw);
min = lower_bound_in_type (outer_type, shorter_type);
max = upper_bound_in_type (outer_type, shorter_type);
above = integer_nonzerop (fold_relational_const (LT_EXPR, type,
max, arg1_unw));
below = integer_nonzerop (fold_relational_const (LT_EXPR, type,
arg1_unw, min));
switch (code)
{
case EQ_EXPR:
if (above || below)
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
break;
case NE_EXPR:
if (above || below)
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
break;
case LT_EXPR:
case LE_EXPR:
if (above)
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
else if (below)
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
case GT_EXPR:
case GE_EXPR:
if (above)
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
else if (below)
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
default:
break;
}
return NULL_TREE;
}
/* Fold comparison ARG0 CODE ARG1 (with result in TYPE), where for
ARG0 just the signedness is changed. */
static tree
fold_sign_changed_comparison (location_t loc, enum tree_code code, tree type,
tree arg0, tree arg1)
{
tree arg0_inner;
tree inner_type, outer_type;
if (!CONVERT_EXPR_P (arg0))
return NULL_TREE;
outer_type = TREE_TYPE (arg0);
arg0_inner = TREE_OPERAND (arg0, 0);
inner_type = TREE_TYPE (arg0_inner);
#ifdef HAVE_canonicalize_funcptr_for_compare
/* Disable this optimization if we're casting a function pointer
type on targets that require function pointer canonicalization. */
if (HAVE_canonicalize_funcptr_for_compare
&& TREE_CODE (inner_type) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (inner_type)) == FUNCTION_TYPE)
return NULL_TREE;
#endif
if (TYPE_PRECISION (inner_type) != TYPE_PRECISION (outer_type))
return NULL_TREE;
if (TREE_CODE (arg1) != INTEGER_CST
&& !(CONVERT_EXPR_P (arg1)
&& TREE_TYPE (TREE_OPERAND (arg1, 0)) == inner_type))
return NULL_TREE;
if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
&& code != NE_EXPR
&& code != EQ_EXPR)
return NULL_TREE;
if (POINTER_TYPE_P (inner_type) != POINTER_TYPE_P (outer_type))
return NULL_TREE;
if (TREE_CODE (arg1) == INTEGER_CST)
arg1 = force_fit_type_double (inner_type, tree_to_double_int (arg1),
0, TREE_OVERFLOW (arg1));
else
arg1 = fold_convert_loc (loc, inner_type, arg1);
return fold_build2_loc (loc, code, type, arg0_inner, arg1);
}
/* Tries to replace &a[idx] p+ s * delta with &a[idx + delta], if s is
step of the array. Reconstructs s and delta in the case of s *
delta being an integer constant (and thus already folded). ADDR is
the address. MULT is the multiplicative expression. If the
function succeeds, the new address expression is returned.
Otherwise NULL_TREE is returned. LOC is the location of the
resulting expression. */
static tree
try_move_mult_to_index (location_t loc, tree addr, tree op1)
{
tree s, delta, step;
tree ref = TREE_OPERAND (addr, 0), pref;
tree ret, pos;
tree itype;
bool mdim = false;
/* Strip the nops that might be added when converting op1 to sizetype. */
STRIP_NOPS (op1);
/* Canonicalize op1 into a possibly non-constant delta
and an INTEGER_CST s. */
if (TREE_CODE (op1) == MULT_EXPR)
{
tree arg0 = TREE_OPERAND (op1, 0), arg1 = TREE_OPERAND (op1, 1);
STRIP_NOPS (arg0);
STRIP_NOPS (arg1);
if (TREE_CODE (arg0) == INTEGER_CST)
{
s = arg0;
delta = arg1;
}
else if (TREE_CODE (arg1) == INTEGER_CST)
{
s = arg1;
delta = arg0;
}
else
return NULL_TREE;
}
else if (TREE_CODE (op1) == INTEGER_CST)
{
delta = op1;
s = NULL_TREE;
}
else
{
/* Simulate we are delta * 1. */
delta = op1;
s = integer_one_node;
}
/* Handle &x.array the same as we would handle &x.array[0]. */
if (TREE_CODE (ref) == COMPONENT_REF
&& TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
{
tree domain;
/* Remember if this was a multi-dimensional array. */
if (TREE_CODE (TREE_OPERAND (ref, 0)) == ARRAY_REF)
mdim = true;
domain = TYPE_DOMAIN (TREE_TYPE (ref));
if (! domain)
goto cont;
itype = TREE_TYPE (domain);
step = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ref)));
if (TREE_CODE (step) != INTEGER_CST)
goto cont;
if (s)
{
if (! tree_int_cst_equal (step, s))
goto cont;
}
else
{
/* Try if delta is a multiple of step. */
tree tmp = div_if_zero_remainder (EXACT_DIV_EXPR, op1, step);
if (! tmp)
goto cont;
delta = tmp;
}
/* Only fold here if we can verify we do not overflow one
dimension of a multi-dimensional array. */
if (mdim)
{
tree tmp;
if (!TYPE_MIN_VALUE (domain)
|| !TYPE_MAX_VALUE (domain)
|| TREE_CODE (TYPE_MAX_VALUE (domain)) != INTEGER_CST)
goto cont;
tmp = fold_binary_loc (loc, PLUS_EXPR, itype,
fold_convert_loc (loc, itype,
TYPE_MIN_VALUE (domain)),
fold_convert_loc (loc, itype, delta));
if (TREE_CODE (tmp) != INTEGER_CST
|| tree_int_cst_lt (TYPE_MAX_VALUE (domain), tmp))
goto cont;
}
/* We found a suitable component reference. */
pref = TREE_OPERAND (addr, 0);
ret = copy_node (pref);
SET_EXPR_LOCATION (ret, loc);
ret = build4_loc (loc, ARRAY_REF, TREE_TYPE (TREE_TYPE (ref)), ret,
fold_build2_loc
(loc, PLUS_EXPR, itype,
fold_convert_loc (loc, itype,
TYPE_MIN_VALUE
(TYPE_DOMAIN (TREE_TYPE (ref)))),
fold_convert_loc (loc, itype, delta)),
NULL_TREE, NULL_TREE);
return build_fold_addr_expr_loc (loc, ret);
}
cont:
for (;; ref = TREE_OPERAND (ref, 0))
{
if (TREE_CODE (ref) == ARRAY_REF)
{
tree domain;
/* Remember if this was a multi-dimensional array. */
if (TREE_CODE (TREE_OPERAND (ref, 0)) == ARRAY_REF)
mdim = true;
domain = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (ref, 0)));
if (! domain)
continue;
itype = TREE_TYPE (domain);
step = array_ref_element_size (ref);
if (TREE_CODE (step) != INTEGER_CST)
continue;
if (s)
{
if (! tree_int_cst_equal (step, s))
continue;
}
else
{
/* Try if delta is a multiple of step. */
tree tmp = div_if_zero_remainder (EXACT_DIV_EXPR, op1, step);
if (! tmp)
continue;
delta = tmp;
}
/* Only fold here if we can verify we do not overflow one
dimension of a multi-dimensional array. */
if (mdim)
{
tree tmp;
if (TREE_CODE (TREE_OPERAND (ref, 1)) != INTEGER_CST
|| !TYPE_MAX_VALUE (domain)
|| TREE_CODE (TYPE_MAX_VALUE (domain)) != INTEGER_CST)
continue;
tmp = fold_binary_loc (loc, PLUS_EXPR, itype,
fold_convert_loc (loc, itype,
TREE_OPERAND (ref, 1)),
fold_convert_loc (loc, itype, delta));
if (!tmp
|| TREE_CODE (tmp) != INTEGER_CST
|| tree_int_cst_lt (TYPE_MAX_VALUE (domain), tmp))
continue;
}
break;
}
else
mdim = false;
if (!handled_component_p (ref))
return NULL_TREE;
}
/* We found the suitable array reference. So copy everything up to it,
and replace the index. */
pref = TREE_OPERAND (addr, 0);
ret = copy_node (pref);
SET_EXPR_LOCATION (ret, loc);
pos = ret;
while (pref != ref)
{
pref = TREE_OPERAND (pref, 0);
TREE_OPERAND (pos, 0) = copy_node (pref);
pos = TREE_OPERAND (pos, 0);
}
TREE_OPERAND (pos, 1)
= fold_build2_loc (loc, PLUS_EXPR, itype,
fold_convert_loc (loc, itype, TREE_OPERAND (pos, 1)),
fold_convert_loc (loc, itype, delta));
return fold_build1_loc (loc, ADDR_EXPR, TREE_TYPE (addr), ret);
}
/* Fold A < X && A + 1 > Y to A < X && A >= Y. Normally A + 1 > Y
means A >= Y && A != MAX, but in this case we know that
A < X <= MAX. INEQ is A + 1 > Y, BOUND is A < X. */
static tree
fold_to_nonsharp_ineq_using_bound (location_t loc, tree ineq, tree bound)
{
tree a, typea, type = TREE_TYPE (ineq), a1, diff, y;
if (TREE_CODE (bound) == LT_EXPR)
a = TREE_OPERAND (bound, 0);
else if (TREE_CODE (bound) == GT_EXPR)
a = TREE_OPERAND (bound, 1);
else
return NULL_TREE;
typea = TREE_TYPE (a);
if (!INTEGRAL_TYPE_P (typea)
&& !POINTER_TYPE_P (typea))
return NULL_TREE;
if (TREE_CODE (ineq) == LT_EXPR)
{
a1 = TREE_OPERAND (ineq, 1);
y = TREE_OPERAND (ineq, 0);
}
else if (TREE_CODE (ineq) == GT_EXPR)
{
a1 = TREE_OPERAND (ineq, 0);
y = TREE_OPERAND (ineq, 1);
}
else
return NULL_TREE;
if (TREE_TYPE (a1) != typea)
return NULL_TREE;
if (POINTER_TYPE_P (typea))
{
/* Convert the pointer types into integer before taking the difference. */
tree ta = fold_convert_loc (loc, ssizetype, a);
tree ta1 = fold_convert_loc (loc, ssizetype, a1);
diff = fold_binary_loc (loc, MINUS_EXPR, ssizetype, ta1, ta);
}
else
diff = fold_binary_loc (loc, MINUS_EXPR, typea, a1, a);
if (!diff || !integer_onep (diff))
return NULL_TREE;
return fold_build2_loc (loc, GE_EXPR, type, a, y);
}
/* Fold a sum or difference of at least one multiplication.
Returns the folded tree or NULL if no simplification could be made. */
static tree
fold_plusminus_mult_expr (location_t loc, enum tree_code code, tree type,
tree arg0, tree arg1)
{
tree arg00, arg01, arg10, arg11;
tree alt0 = NULL_TREE, alt1 = NULL_TREE, same;
/* (A * C) +- (B * C) -> (A+-B) * C.
(A * C) +- A -> A * (C+-1).
We are most concerned about the case where C is a constant,
but other combinations show up during loop reduction. Since
it is not difficult, try all four possibilities. */
if (TREE_CODE (arg0) == MULT_EXPR)
{
arg00 = TREE_OPERAND (arg0, 0);
arg01 = TREE_OPERAND (arg0, 1);
}
else if (TREE_CODE (arg0) == INTEGER_CST)
{
arg00 = build_one_cst (type);
arg01 = arg0;
}
else
{
/* We cannot generate constant 1 for fract. */
if (ALL_FRACT_MODE_P (TYPE_MODE (type)))
return NULL_TREE;
arg00 = arg0;
arg01 = build_one_cst (type);
}
if (TREE_CODE (arg1) == MULT_EXPR)
{
arg10 = TREE_OPERAND (arg1, 0);
arg11 = TREE_OPERAND (arg1, 1);
}
else if (TREE_CODE (arg1) == INTEGER_CST)
{
arg10 = build_one_cst (type);
/* As we canonicalize A - 2 to A + -2 get rid of that sign for
the purpose of this canonicalization. */
if (TREE_INT_CST_HIGH (arg1) == -1
&& negate_expr_p (arg1)
&& code == PLUS_EXPR)
{
arg11 = negate_expr (arg1);
code = MINUS_EXPR;
}
else
arg11 = arg1;
}
else
{
/* We cannot generate constant 1 for fract. */
if (ALL_FRACT_MODE_P (TYPE_MODE (type)))
return NULL_TREE;
arg10 = arg1;
arg11 = build_one_cst (type);
}
same = NULL_TREE;
if (operand_equal_p (arg01, arg11, 0))
same = arg01, alt0 = arg00, alt1 = arg10;
else if (operand_equal_p (arg00, arg10, 0))
same = arg00, alt0 = arg01, alt1 = arg11;
else if (operand_equal_p (arg00, arg11, 0))
same = arg00, alt0 = arg01, alt1 = arg10;
else if (operand_equal_p (arg01, arg10, 0))
same = arg01, alt0 = arg00, alt1 = arg11;
/* No identical multiplicands; see if we can find a common
power-of-two factor in non-power-of-two multiplies. This
can help in multi-dimensional array access. */
else if (host_integerp (arg01, 0)
&& host_integerp (arg11, 0))
{
HOST_WIDE_INT int01, int11, tmp;
bool swap = false;
tree maybe_same;
int01 = TREE_INT_CST_LOW (arg01);
int11 = TREE_INT_CST_LOW (arg11);
/* Move min of absolute values to int11. */
if (absu_hwi (int01) < absu_hwi (int11))
{
tmp = int01, int01 = int11, int11 = tmp;
alt0 = arg00, arg00 = arg10, arg10 = alt0;
maybe_same = arg01;
swap = true;
}
else
maybe_same = arg11;
if (exact_log2 (absu_hwi (int11)) > 0 && int01 % int11 == 0
/* The remainder should not be a constant, otherwise we
end up folding i * 4 + 2 to (i * 2 + 1) * 2 which has
increased the number of multiplications necessary. */
&& TREE_CODE (arg10) != INTEGER_CST)
{
alt0 = fold_build2_loc (loc, MULT_EXPR, TREE_TYPE (arg00), arg00,
build_int_cst (TREE_TYPE (arg00),
int01 / int11));
alt1 = arg10;
same = maybe_same;
if (swap)
maybe_same = alt0, alt0 = alt1, alt1 = maybe_same;
}
}
if (same)
return fold_build2_loc (loc, MULT_EXPR, type,
fold_build2_loc (loc, code, type,
fold_convert_loc (loc, type, alt0),
fold_convert_loc (loc, type, alt1)),
fold_convert_loc (loc, type, same));
return NULL_TREE;
}
/* Subroutine of native_encode_expr. Encode the INTEGER_CST
specified by EXPR into the buffer PTR of length LEN bytes.
Return the number of bytes placed in the buffer, or zero
upon failure. */
static int
native_encode_int (const_tree expr, unsigned char *ptr, int len)
{
tree type = TREE_TYPE (expr);
int total_bytes = GET_MODE_SIZE (TYPE_MODE (type));
int byte, offset, word, words;
unsigned char value;
if (total_bytes > len)
return 0;
words = total_bytes / UNITS_PER_WORD;
for (byte = 0; byte < total_bytes; byte++)
{
int bitpos = byte * BITS_PER_UNIT;
if (bitpos < HOST_BITS_PER_WIDE_INT)
value = (unsigned char) (TREE_INT_CST_LOW (expr) >> bitpos);
else
value = (unsigned char) (TREE_INT_CST_HIGH (expr)
>> (bitpos - HOST_BITS_PER_WIDE_INT));
if (total_bytes > UNITS_PER_WORD)
{
word = byte / UNITS_PER_WORD;
if (WORDS_BIG_ENDIAN)
word = (words - 1) - word;
offset = word * UNITS_PER_WORD;
if (BYTES_BIG_ENDIAN)
offset += (UNITS_PER_WORD - 1) - (byte % UNITS_PER_WORD);
else
offset += byte % UNITS_PER_WORD;
}
else
offset = BYTES_BIG_ENDIAN ? (total_bytes - 1) - byte : byte;
ptr[offset] = value;
}
return total_bytes;
}
/* Subroutine of native_encode_expr. Encode the FIXED_CST
specified by EXPR into the buffer PTR of length LEN bytes.
Return the number of bytes placed in the buffer, or zero
upon failure. */
static int
native_encode_fixed (const_tree expr, unsigned char *ptr, int len)
{
tree type = TREE_TYPE (expr);
enum machine_mode mode = TYPE_MODE (type);
int total_bytes = GET_MODE_SIZE (mode);
FIXED_VALUE_TYPE value;
tree i_value, i_type;
if (total_bytes * BITS_PER_UNIT > HOST_BITS_PER_DOUBLE_INT)
return 0;
i_type = lang_hooks.types.type_for_size (GET_MODE_BITSIZE (mode), 1);
if (NULL_TREE == i_type
|| TYPE_PRECISION (i_type) != total_bytes)
return 0;
value = TREE_FIXED_CST (expr);
i_value = double_int_to_tree (i_type, value.data);
return native_encode_int (i_value, ptr, len);
}
/* Subroutine of native_encode_expr. Encode the REAL_CST
specified by EXPR into the buffer PTR of length LEN bytes.
Return the number of bytes placed in the buffer, or zero
upon failure. */
static int
native_encode_real (const_tree expr, unsigned char *ptr, int len)
{
tree type = TREE_TYPE (expr);
int total_bytes = GET_MODE_SIZE (TYPE_MODE (type));
int byte, offset, word, words, bitpos;
unsigned char value;
/* There are always 32 bits in each long, no matter the size of
the hosts long. We handle floating point representations with
up to 192 bits. */
long tmp[6];
if (total_bytes > len)
return 0;
words = (32 / BITS_PER_UNIT) / UNITS_PER_WORD;
real_to_target (tmp, TREE_REAL_CST_PTR (expr), TYPE_MODE (type));
for (bitpos = 0; bitpos < total_bytes * BITS_PER_UNIT;
bitpos += BITS_PER_UNIT)
{
byte = (bitpos / BITS_PER_UNIT) & 3;
value = (unsigned char) (tmp[bitpos / 32] >> (bitpos & 31));
if (UNITS_PER_WORD < 4)
{
word = byte / UNITS_PER_WORD;
if (WORDS_BIG_ENDIAN)
word = (words - 1) - word;
offset = word * UNITS_PER_WORD;
if (BYTES_BIG_ENDIAN)
offset += (UNITS_PER_WORD - 1) - (byte % UNITS_PER_WORD);
else
offset += byte % UNITS_PER_WORD;
}
else
offset = BYTES_BIG_ENDIAN ? 3 - byte : byte;
ptr[offset + ((bitpos / BITS_PER_UNIT) & ~3)] = value;
}
return total_bytes;
}
/* Subroutine of native_encode_expr. Encode the COMPLEX_CST
specified by EXPR into the buffer PTR of length LEN bytes.
Return the number of bytes placed in the buffer, or zero
upon failure. */
static int
native_encode_complex (const_tree expr, unsigned char *ptr, int len)
{
int rsize, isize;
tree part;
part = TREE_REALPART (expr);
rsize = native_encode_expr (part, ptr, len);
if (rsize == 0)
return 0;
part = TREE_IMAGPART (expr);
isize = native_encode_expr (part, ptr+rsize, len-rsize);
if (isize != rsize)
return 0;
return rsize + isize;
}
/* Subroutine of native_encode_expr. Encode the VECTOR_CST
specified by EXPR into the buffer PTR of length LEN bytes.
Return the number of bytes placed in the buffer, or zero
upon failure. */
static int
native_encode_vector (const_tree expr, unsigned char *ptr, int len)
{
unsigned i, count;
int size, offset;
tree itype, elem;
offset = 0;
count = VECTOR_CST_NELTS (expr);
itype = TREE_TYPE (TREE_TYPE (expr));
size = GET_MODE_SIZE (TYPE_MODE (itype));
for (i = 0; i < count; i++)
{
elem = VECTOR_CST_ELT (expr, i);
if (native_encode_expr (elem, ptr+offset, len-offset) != size)
return 0;
offset += size;
}
return offset;
}
/* Subroutine of native_encode_expr. Encode the STRING_CST
specified by EXPR into the buffer PTR of length LEN bytes.
Return the number of bytes placed in the buffer, or zero
upon failure. */
static int
native_encode_string (const_tree expr, unsigned char *ptr, int len)
{
tree type = TREE_TYPE (expr);
HOST_WIDE_INT total_bytes;
if (TREE_CODE (type) != ARRAY_TYPE
|| TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE
|| GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))) != BITS_PER_UNIT
|| !host_integerp (TYPE_SIZE_UNIT (type), 0))
return 0;
total_bytes = tree_low_cst (TYPE_SIZE_UNIT (type), 0);
if (total_bytes > len)
return 0;
if (TREE_STRING_LENGTH (expr) < total_bytes)
{
memcpy (ptr, TREE_STRING_POINTER (expr), TREE_STRING_LENGTH (expr));
memset (ptr + TREE_STRING_LENGTH (expr), 0,
total_bytes - TREE_STRING_LENGTH (expr));
}
else
memcpy (ptr, TREE_STRING_POINTER (expr), total_bytes);
return total_bytes;
}
/* Subroutine of fold_view_convert_expr. Encode the INTEGER_CST,
REAL_CST, COMPLEX_CST or VECTOR_CST specified by EXPR into the
buffer PTR of length LEN bytes. Return the number of bytes
placed in the buffer, or zero upon failure. */
int
native_encode_expr (const_tree expr, unsigned char *ptr, int len)
{
switch (TREE_CODE (expr))
{
case INTEGER_CST:
return native_encode_int (expr, ptr, len);
case REAL_CST:
return native_encode_real (expr, ptr, len);
case FIXED_CST:
return native_encode_fixed (expr, ptr, len);
case COMPLEX_CST:
return native_encode_complex (expr, ptr, len);
case VECTOR_CST:
return native_encode_vector (expr, ptr, len);
case STRING_CST:
return native_encode_string (expr, ptr, len);
default:
return 0;
}
}
/* Subroutine of native_interpret_expr. Interpret the contents of
the buffer PTR of length LEN as an INTEGER_CST of type TYPE.
If the buffer cannot be interpreted, return NULL_TREE. */
static tree
native_interpret_int (tree type, const unsigned char *ptr, int len)
{
int total_bytes = GET_MODE_SIZE (TYPE_MODE (type));
double_int result;
if (total_bytes > len
|| total_bytes * BITS_PER_UNIT > HOST_BITS_PER_DOUBLE_INT)
return NULL_TREE;
result = double_int::from_buffer (ptr, total_bytes);
return double_int_to_tree (type, result);
}
/* Subroutine of native_interpret_expr. Interpret the contents of
the buffer PTR of length LEN as a FIXED_CST of type TYPE.
If the buffer cannot be interpreted, return NULL_TREE. */
static tree
native_interpret_fixed (tree type, const unsigned char *ptr, int len)
{
int total_bytes = GET_MODE_SIZE (TYPE_MODE (type));
double_int result;
FIXED_VALUE_TYPE fixed_value;
if (total_bytes > len
|| total_bytes * BITS_PER_UNIT > HOST_BITS_PER_DOUBLE_INT)
return NULL_TREE;
result = double_int::from_buffer (ptr, total_bytes);
fixed_value = fixed_from_double_int (result, TYPE_MODE (type));
return build_fixed (type, fixed_value);
}
/* Subroutine of native_interpret_expr. Interpret the contents of
the buffer PTR of length LEN as a REAL_CST of type TYPE.
If the buffer cannot be interpreted, return NULL_TREE. */
static tree
native_interpret_real (tree type, const unsigned char *ptr, int len)
{
enum machine_mode mode = TYPE_MODE (type);
int total_bytes = GET_MODE_SIZE (mode);
int byte, offset, word, words, bitpos;
unsigned char value;
/* There are always 32 bits in each long, no matter the size of
the hosts long. We handle floating point representations with
up to 192 bits. */
REAL_VALUE_TYPE r;
long tmp[6];
total_bytes = GET_MODE_SIZE (TYPE_MODE (type));
if (total_bytes > len || total_bytes > 24)
return NULL_TREE;
words = (32 / BITS_PER_UNIT) / UNITS_PER_WORD;
memset (tmp, 0, sizeof (tmp));
for (bitpos = 0; bitpos < total_bytes * BITS_PER_UNIT;
bitpos += BITS_PER_UNIT)
{
byte = (bitpos / BITS_PER_UNIT) & 3;
if (UNITS_PER_WORD < 4)
{
word = byte / UNITS_PER_WORD;
if (WORDS_BIG_ENDIAN)
word = (words - 1) - word;
offset = word * UNITS_PER_WORD;
if (BYTES_BIG_ENDIAN)
offset += (UNITS_PER_WORD - 1) - (byte % UNITS_PER_WORD);
else
offset += byte % UNITS_PER_WORD;
}
else
offset = BYTES_BIG_ENDIAN ? 3 - byte : byte;
value = ptr[offset + ((bitpos / BITS_PER_UNIT) & ~3)];
tmp[bitpos / 32] |= (unsigned long)value << (bitpos & 31);
}
real_from_target (&r, tmp, mode);
return build_real (type, r);
}
/* Subroutine of native_interpret_expr. Interpret the contents of
the buffer PTR of length LEN as a COMPLEX_CST of type TYPE.
If the buffer cannot be interpreted, return NULL_TREE. */
static tree
native_interpret_complex (tree type, const unsigned char *ptr, int len)
{
tree etype, rpart, ipart;
int size;
etype = TREE_TYPE (type);
size = GET_MODE_SIZE (TYPE_MODE (etype));
if (size * 2 > len)
return NULL_TREE;
rpart = native_interpret_expr (etype, ptr, size);
if (!rpart)
return NULL_TREE;
ipart = native_interpret_expr (etype, ptr+size, size);
if (!ipart)
return NULL_TREE;
return build_complex (type, rpart, ipart);
}
/* Subroutine of native_interpret_expr. Interpret the contents of
the buffer PTR of length LEN as a VECTOR_CST of type TYPE.
If the buffer cannot be interpreted, return NULL_TREE. */
static tree
native_interpret_vector (tree type, const unsigned char *ptr, int len)
{
tree etype, elem;
int i, size, count;
tree *elements;
etype = TREE_TYPE (type);
size = GET_MODE_SIZE (TYPE_MODE (etype));
count = TYPE_VECTOR_SUBPARTS (type);
if (size * count > len)
return NULL_TREE;
elements = XALLOCAVEC (tree, count);
for (i = count - 1; i >= 0; i--)
{
elem = native_interpret_expr (etype, ptr+(i*size), size);
if (!elem)
return NULL_TREE;
elements[i] = elem;
}
return build_vector (type, elements);
}
/* Subroutine of fold_view_convert_expr. Interpret the contents of
the buffer PTR of length LEN as a constant of type TYPE. For
INTEGRAL_TYPE_P we return an INTEGER_CST, for SCALAR_FLOAT_TYPE_P
we return a REAL_CST, etc... If the buffer cannot be interpreted,
return NULL_TREE. */
tree
native_interpret_expr (tree type, const unsigned char *ptr, int len)
{
switch (TREE_CODE (type))
{
case INTEGER_TYPE:
case ENUMERAL_TYPE:
case BOOLEAN_TYPE:
case POINTER_TYPE:
case REFERENCE_TYPE:
return native_interpret_int (type, ptr, len);
case REAL_TYPE:
return native_interpret_real (type, ptr, len);
case FIXED_POINT_TYPE:
return native_interpret_fixed (type, ptr, len);
case COMPLEX_TYPE:
return native_interpret_complex (type, ptr, len);
case VECTOR_TYPE:
return native_interpret_vector (type, ptr, len);
default:
return NULL_TREE;
}
}
/* Returns true if we can interpret the contents of a native encoding
as TYPE. */
static bool
can_native_interpret_type_p (tree type)
{
switch (TREE_CODE (type))
{
case INTEGER_TYPE:
case ENUMERAL_TYPE:
case BOOLEAN_TYPE:
case POINTER_TYPE:
case REFERENCE_TYPE:
case FIXED_POINT_TYPE:
case REAL_TYPE:
case COMPLEX_TYPE:
case VECTOR_TYPE:
return true;
default:
return false;
}
}
/* Fold a VIEW_CONVERT_EXPR of a constant expression EXPR to type
TYPE at compile-time. If we're unable to perform the conversion
return NULL_TREE. */
static tree
fold_view_convert_expr (tree type, tree expr)
{
/* We support up to 512-bit values (for V8DFmode). */
unsigned char buffer[64];
int len;
/* Check that the host and target are sane. */
if (CHAR_BIT != 8 || BITS_PER_UNIT != 8)
return NULL_TREE;
len = native_encode_expr (expr, buffer, sizeof (buffer));
if (len == 0)
return NULL_TREE;
return native_interpret_expr (type, buffer, len);
}
/* Build an expression for the address of T. Folds away INDIRECT_REF
to avoid confusing the gimplify process. */
tree
build_fold_addr_expr_with_type_loc (location_t loc, tree t, tree ptrtype)
{
/* The size of the object is not relevant when talking about its address. */
if (TREE_CODE (t) == WITH_SIZE_EXPR)
t = TREE_OPERAND (t, 0);
if (TREE_CODE (t) == INDIRECT_REF)
{
t = TREE_OPERAND (t, 0);
if (TREE_TYPE (t) != ptrtype)
t = build1_loc (loc, NOP_EXPR, ptrtype, t);
}
else if (TREE_CODE (t) == MEM_REF
&& integer_zerop (TREE_OPERAND (t, 1)))
return TREE_OPERAND (t, 0);
else if (TREE_CODE (t) == MEM_REF
&& TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST)
return fold_binary (POINTER_PLUS_EXPR, ptrtype,
TREE_OPERAND (t, 0),
convert_to_ptrofftype (TREE_OPERAND (t, 1)));
else if (TREE_CODE (t) == VIEW_CONVERT_EXPR)
{
t = build_fold_addr_expr_loc (loc, TREE_OPERAND (t, 0));
if (TREE_TYPE (t) != ptrtype)
t = fold_convert_loc (loc, ptrtype, t);
}
else
t = build1_loc (loc, ADDR_EXPR, ptrtype, t);
return t;
}
/* Build an expression for the address of T. */
tree
build_fold_addr_expr_loc (location_t loc, tree t)
{
tree ptrtype = build_pointer_type (TREE_TYPE (t));
return build_fold_addr_expr_with_type_loc (loc, t, ptrtype);
}
static bool vec_cst_ctor_to_array (tree, tree *);
/* Fold a unary expression of code CODE and type TYPE with operand
OP0. Return the folded expression if folding is successful.
Otherwise, return NULL_TREE. */
tree
fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
{
tree tem;
tree arg0;
enum tree_code_class kind = TREE_CODE_CLASS (code);
gcc_assert (IS_EXPR_CODE_CLASS (kind)
&& TREE_CODE_LENGTH (code) == 1);
arg0 = op0;
if (arg0)
{
if (CONVERT_EXPR_CODE_P (code)
|| code == FLOAT_EXPR || code == ABS_EXPR || code == NEGATE_EXPR)
{
/* Don't use STRIP_NOPS, because signedness of argument type
matters. */
STRIP_SIGN_NOPS (arg0);
}
else
{
/* Strip any conversions that don't change the mode. This
is safe for every expression, except for a comparison
expression because its signedness is derived from its
operands.
Note that this is done as an internal manipulation within
the constant folder, in order to find the simplest
representation of the arguments so that their form can be
studied. In any cases, the appropriate type conversions
should be put back in the tree that will get out of the
constant folder. */
STRIP_NOPS (arg0);
}
}
if (TREE_CODE_CLASS (code) == tcc_unary)
{
if (TREE_CODE (arg0) == COMPOUND_EXPR)
return build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
fold_build1_loc (loc, code, type,
fold_convert_loc (loc, TREE_TYPE (op0),
TREE_OPERAND (arg0, 1))));
else if (TREE_CODE (arg0) == COND_EXPR)
{
tree arg01 = TREE_OPERAND (arg0, 1);
tree arg02 = TREE_OPERAND (arg0, 2);
if (! VOID_TYPE_P (TREE_TYPE (arg01)))
arg01 = fold_build1_loc (loc, code, type,
fold_convert_loc (loc,
TREE_TYPE (op0), arg01));
if (! VOID_TYPE_P (TREE_TYPE (arg02)))
arg02 = fold_build1_loc (loc, code, type,
fold_convert_loc (loc,
TREE_TYPE (op0), arg02));
tem = fold_build3_loc (loc, COND_EXPR, type, TREE_OPERAND (arg0, 0),
arg01, arg02);
/* If this was a conversion, and all we did was to move into
inside the COND_EXPR, bring it back out. But leave it if
it is a conversion from integer to integer and the
result precision is no wider than a word since such a
conversion is cheap and may be optimized away by combine,
while it couldn't if it were outside the COND_EXPR. Then return
so we don't get into an infinite recursion loop taking the
conversion out and then back in. */
if ((CONVERT_EXPR_CODE_P (code)
|| code == NON_LVALUE_EXPR)
&& TREE_CODE (tem) == COND_EXPR
&& TREE_CODE (TREE_OPERAND (tem, 1)) == code
&& TREE_CODE (TREE_OPERAND (tem, 2)) == code
&& ! VOID_TYPE_P (TREE_OPERAND (tem, 1))
&& ! VOID_TYPE_P (TREE_OPERAND (tem, 2))
&& (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (tem, 1), 0))
== TREE_TYPE (TREE_OPERAND (TREE_OPERAND (tem, 2), 0)))
&& (! (INTEGRAL_TYPE_P (TREE_TYPE (tem))
&& (INTEGRAL_TYPE_P
(TREE_TYPE (TREE_OPERAND (TREE_OPERAND (tem, 1), 0))))
&& TYPE_PRECISION (TREE_TYPE (tem)) <= BITS_PER_WORD)
|| flag_syntax_only))
tem = build1_loc (loc, code, type,
build3 (COND_EXPR,
TREE_TYPE (TREE_OPERAND
(TREE_OPERAND (tem, 1), 0)),
TREE_OPERAND (tem, 0),
TREE_OPERAND (TREE_OPERAND (tem, 1), 0),
TREE_OPERAND (TREE_OPERAND (tem, 2),
0)));
return tem;
}
}
switch (code)
{
case PAREN_EXPR:
/* Re-association barriers around constants and other re-association
barriers can be removed. */
if (CONSTANT_CLASS_P (op0)
|| TREE_CODE (op0) == PAREN_EXPR)
return fold_convert_loc (loc, type, op0);
return NULL_TREE;
CASE_CONVERT:
case FLOAT_EXPR:
case FIX_TRUNC_EXPR:
if (TREE_TYPE (op0) == type)
return op0;
if (COMPARISON_CLASS_P (op0))
{
/* If we have (type) (a CMP b) and type is an integral type, return
new expression involving the new type. Canonicalize
(type) (a CMP b) to (a CMP b) ? (type) true : (type) false for
non-integral type.
Do not fold the result as that would not simplify further, also
folding again results in recursions. */
if (TREE_CODE (type) == BOOLEAN_TYPE)
return build2_loc (loc, TREE_CODE (op0), type,
TREE_OPERAND (op0, 0),
TREE_OPERAND (op0, 1));
else if (!INTEGRAL_TYPE_P (type) && !VOID_TYPE_P (type)
&& TREE_CODE (type) != VECTOR_TYPE)
return build3_loc (loc, COND_EXPR, type, op0,
constant_boolean_node (true, type),
constant_boolean_node (false, type));
}
/* Handle cases of two conversions in a row. */
if (CONVERT_EXPR_P (op0))
{
tree inside_type = TREE_TYPE (TREE_OPERAND (op0, 0));
tree inter_type = TREE_TYPE (op0);
int inside_int = INTEGRAL_TYPE_P (inside_type);
int inside_ptr = POINTER_TYPE_P (inside_type);
int inside_float = FLOAT_TYPE_P (inside_type);
int inside_vec = TREE_CODE (inside_type) == VECTOR_TYPE;
unsigned int inside_prec = TYPE_PRECISION (inside_type);
int inside_unsignedp = TYPE_UNSIGNED (inside_type);
int inter_int = INTEGRAL_TYPE_P (inter_type);
int inter_ptr = POINTER_TYPE_P (inter_type);
int inter_float = FLOAT_TYPE_P (inter_type);
int inter_vec = TREE_CODE (inter_type) == VECTOR_TYPE;
unsigned int inter_prec = TYPE_PRECISION (inter_type);
int inter_unsignedp = TYPE_UNSIGNED (inter_type);
int final_int = INTEGRAL_TYPE_P (type);
int final_ptr = POINTER_TYPE_P (type);
int final_float = FLOAT_TYPE_P (type);
int final_vec = TREE_CODE (type) == VECTOR_TYPE;
unsigned int final_prec = TYPE_PRECISION (type);
int final_unsignedp = TYPE_UNSIGNED (type);
/* In addition to the cases of two conversions in a row
handled below, if we are converting something to its own
type via an object of identical or wider precision, neither
conversion is needed. */
if (TYPE_MAIN_VARIANT (inside_type) == TYPE_MAIN_VARIANT (type)
&& (((inter_int || inter_ptr) && final_int)
|| (inter_float && final_float))
&& inter_prec >= final_prec)
return fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 0));
/* Likewise, if the intermediate and initial types are either both
float or both integer, we don't need the middle conversion if the
former is wider than the latter and doesn't change the signedness
(for integers). Avoid this if the final type is a pointer since
then we sometimes need the middle conversion. Likewise if the
final type has a precision not equal to the size of its mode. */
if (((inter_int && inside_int)
|| (inter_float && inside_float)
|| (inter_vec && inside_vec))
&& inter_prec >= inside_prec
&& (inter_float || inter_vec
|| inter_unsignedp == inside_unsignedp)
&& ! (final_prec != GET_MODE_PRECISION (TYPE_MODE (type))
&& TYPE_MODE (type) == TYPE_MODE (inter_type))
&& ! final_ptr
&& (! final_vec || inter_prec == inside_prec))
return fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 0));
/* If we have a sign-extension of a zero-extended value, we can
replace that by a single zero-extension. Likewise if the
final conversion does not change precision we can drop the
intermediate conversion. */
if (inside_int && inter_int && final_int
&& ((inside_prec < inter_prec && inter_prec < final_prec
&& inside_unsignedp && !inter_unsignedp)
|| final_prec == inter_prec))
return fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 0));
/* Two conversions in a row are not needed unless:
- some conversion is floating-point (overstrict for now), or
- some conversion is a vector (overstrict for now), or
- the intermediate type is narrower than both initial and
final, or
- the intermediate type and innermost type differ in signedness,
and the outermost type is wider than the intermediate, or
- the initial type is a pointer type and the precisions of the
intermediate and final types differ, or
- the final type is a pointer type and the precisions of the
initial and intermediate types differ. */
if (! inside_float && ! inter_float && ! final_float
&& ! inside_vec && ! inter_vec && ! final_vec
&& (inter_prec >= inside_prec || inter_prec >= final_prec)
&& ! (inside_int && inter_int
&& inter_unsignedp != inside_unsignedp
&& inter_prec < final_prec)
&& ((inter_unsignedp && inter_prec > inside_prec)
== (final_unsignedp && final_prec > inter_prec))
&& ! (inside_ptr && inter_prec != final_prec)
&& ! (final_ptr && inside_prec != inter_prec)
&& ! (final_prec != GET_MODE_PRECISION (TYPE_MODE (type))
&& TYPE_MODE (type) == TYPE_MODE (inter_type)))
return fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 0));
}
/* Handle (T *)&A.B.C for A being of type T and B and C
living at offset zero. This occurs frequently in
C++ upcasting and then accessing the base. */
if (TREE_CODE (op0) == ADDR_EXPR
&& POINTER_TYPE_P (type)
&& handled_component_p (TREE_OPERAND (op0, 0)))
{
HOST_WIDE_INT bitsize, bitpos;
tree offset;
enum machine_mode mode;
int unsignedp, volatilep;
tree base = TREE_OPERAND (op0, 0);
base = get_inner_reference (base, &bitsize, &bitpos, &offset,
&mode, &unsignedp, &volatilep, false);
/* If the reference was to a (constant) zero offset, we can use
the address of the base if it has the same base type
as the result type and the pointer type is unqualified. */
if (! offset && bitpos == 0
&& (TYPE_MAIN_VARIANT (TREE_TYPE (type))
== TYPE_MAIN_VARIANT (TREE_TYPE (base)))
&& TYPE_QUALS (type) == TYPE_UNQUALIFIED)
return fold_convert_loc (loc, type,
build_fold_addr_expr_loc (loc, base));
}
if (TREE_CODE (op0) == MODIFY_EXPR
&& TREE_CONSTANT (TREE_OPERAND (op0, 1))
/* Detect assigning a bitfield. */
&& !(TREE_CODE (TREE_OPERAND (op0, 0)) == COMPONENT_REF
&& DECL_BIT_FIELD
(TREE_OPERAND (TREE_OPERAND (op0, 0), 1))))
{
/* Don't leave an assignment inside a conversion
unless assigning a bitfield. */
tem = fold_build1_loc (loc, code, type, TREE_OPERAND (op0, 1));
/* First do the assignment, then return converted constant. */
tem = build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (tem), op0, tem);
TREE_NO_WARNING (tem) = 1;
TREE_USED (tem) = 1;
return tem;
}
/* Convert (T)(x & c) into (T)x & (T)c, if c is an integer
constants (if x has signed type, the sign bit cannot be set
in c). This folds extension into the BIT_AND_EXPR.
??? We don't do it for BOOLEAN_TYPE or ENUMERAL_TYPE because they
very likely don't have maximal range for their precision and this
transformation effectively doesn't preserve non-maximal ranges. */
if (TREE_CODE (type) == INTEGER_TYPE
&& TREE_CODE (op0) == BIT_AND_EXPR
&& TREE_CODE (TREE_OPERAND (op0, 1)) == INTEGER_CST)
{
tree and_expr = op0;
tree and0 = TREE_OPERAND (and_expr, 0);
tree and1 = TREE_OPERAND (and_expr, 1);
int change = 0;
if (TYPE_UNSIGNED (TREE_TYPE (and_expr))
|| (TYPE_PRECISION (type)
<= TYPE_PRECISION (TREE_TYPE (and_expr))))
change = 1;
else if (TYPE_PRECISION (TREE_TYPE (and1))
<= HOST_BITS_PER_WIDE_INT
&& host_integerp (and1, 1))
{
unsigned HOST_WIDE_INT cst;
cst = tree_low_cst (and1, 1);
cst &= (HOST_WIDE_INT) -1
<< (TYPE_PRECISION (TREE_TYPE (and1)) - 1);
change = (cst == 0);
#ifdef LOAD_EXTEND_OP
if (change
&& !flag_syntax_only
&& (LOAD_EXTEND_OP (TYPE_MODE (TREE_TYPE (and0)))
== ZERO_EXTEND))
{
tree uns = unsigned_type_for (TREE_TYPE (and0));
and0 = fold_convert_loc (loc, uns, and0);
and1 = fold_convert_loc (loc, uns, and1);
}
#endif
}
if (change)
{
tem = force_fit_type_double (type, tree_to_double_int (and1),
0, TREE_OVERFLOW (and1));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_convert_loc (loc, type, and0), tem);
}
}
/* Convert (T1)(X p+ Y) into ((T1)X p+ Y), for pointer type,
when one of the new casts will fold away. Conservatively we assume
that this happens when X or Y is NOP_EXPR or Y is INTEGER_CST. */
if (POINTER_TYPE_P (type)
&& TREE_CODE (arg0) == POINTER_PLUS_EXPR
&& (!TYPE_RESTRICT (type) || TYPE_RESTRICT (TREE_TYPE (arg0)))
&& (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
|| TREE_CODE (TREE_OPERAND (arg0, 0)) == NOP_EXPR
|| TREE_CODE (TREE_OPERAND (arg0, 1)) == NOP_EXPR))
{
tree arg00 = TREE_OPERAND (arg0, 0);
tree arg01 = TREE_OPERAND (arg0, 1);
return fold_build_pointer_plus_loc
(loc, fold_convert_loc (loc, type, arg00), arg01);
}
/* Convert (T1)(~(T2)X) into ~(T1)X if T1 and T2 are integral types
of the same precision, and X is an integer type not narrower than
types T1 or T2, i.e. the cast (T2)X isn't an extension. */
if (INTEGRAL_TYPE_P (type)
&& TREE_CODE (op0) == BIT_NOT_EXPR
&& INTEGRAL_TYPE_P (TREE_TYPE (op0))
&& CONVERT_EXPR_P (TREE_OPERAND (op0, 0))
&& TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0)))
{
tem = TREE_OPERAND (TREE_OPERAND (op0, 0), 0);
if (INTEGRAL_TYPE_P (TREE_TYPE (tem))
&& TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (tem)))
return fold_build1_loc (loc, BIT_NOT_EXPR, type,
fold_convert_loc (loc, type, tem));
}
/* Convert (T1)(X * Y) into (T1)X * (T1)Y if T1 is narrower than the
type of X and Y (integer types only). */
if (INTEGRAL_TYPE_P (type)
&& TREE_CODE (op0) == MULT_EXPR
&& INTEGRAL_TYPE_P (TREE_TYPE (op0))
&& TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (op0)))
{
/* Be careful not to introduce new overflows. */
tree mult_type;
if (TYPE_OVERFLOW_WRAPS (type))
mult_type = type;
else
mult_type = unsigned_type_for (type);
if (TYPE_PRECISION (mult_type) < TYPE_PRECISION (TREE_TYPE (op0)))
{
tem = fold_build2_loc (loc, MULT_EXPR, mult_type,
fold_convert_loc (loc, mult_type,
TREE_OPERAND (op0, 0)),
fold_convert_loc (loc, mult_type,
TREE_OPERAND (op0, 1)));
return fold_convert_loc (loc, type, tem);
}
}
tem = fold_convert_const (code, type, op0);
return tem ? tem : NULL_TREE;
case ADDR_SPACE_CONVERT_EXPR:
if (integer_zerop (arg0))
return fold_convert_const (code, type, arg0);
return NULL_TREE;
case FIXED_CONVERT_EXPR:
tem = fold_convert_const (code, type, arg0);
return tem ? tem : NULL_TREE;
case VIEW_CONVERT_EXPR:
if (TREE_TYPE (op0) == type)
return op0;
if (TREE_CODE (op0) == VIEW_CONVERT_EXPR)
return fold_build1_loc (loc, VIEW_CONVERT_EXPR,
type, TREE_OPERAND (op0, 0));
if (TREE_CODE (op0) == MEM_REF)
return fold_build2_loc (loc, MEM_REF, type,
TREE_OPERAND (op0, 0), TREE_OPERAND (op0, 1));
/* For integral conversions with the same precision or pointer
conversions use a NOP_EXPR instead. */
if ((INTEGRAL_TYPE_P (type)
|| POINTER_TYPE_P (type))
&& (INTEGRAL_TYPE_P (TREE_TYPE (op0))
|| POINTER_TYPE_P (TREE_TYPE (op0)))
&& TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (op0)))
return fold_convert_loc (loc, type, op0);
/* Strip inner integral conversions that do not change the precision. */
if (CONVERT_EXPR_P (op0)
&& (INTEGRAL_TYPE_P (TREE_TYPE (op0))
|| POINTER_TYPE_P (TREE_TYPE (op0)))
&& (INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0)))
|| POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (op0, 0))))
&& (TYPE_PRECISION (TREE_TYPE (op0))
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))))
return fold_build1_loc (loc, VIEW_CONVERT_EXPR,
type, TREE_OPERAND (op0, 0));
return fold_view_convert_expr (type, op0);
case NEGATE_EXPR:
tem = fold_negate_expr (loc, arg0);
if (tem)
return fold_convert_loc (loc, type, tem);
return NULL_TREE;
case ABS_EXPR:
if (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST)
return fold_abs_const (arg0, type);
else if (TREE_CODE (arg0) == NEGATE_EXPR)
return fold_build1_loc (loc, ABS_EXPR, type, TREE_OPERAND (arg0, 0));
/* Convert fabs((double)float) into (double)fabsf(float). */
else if (TREE_CODE (arg0) == NOP_EXPR
&& TREE_CODE (type) == REAL_TYPE)
{
tree targ0 = strip_float_extensions (arg0);
if (targ0 != arg0)
return fold_convert_loc (loc, type,
fold_build1_loc (loc, ABS_EXPR,
TREE_TYPE (targ0),
targ0));
}
/* ABS_EXPR<ABS_EXPR<x>> = ABS_EXPR<x> even if flag_wrapv is on. */
else if (TREE_CODE (arg0) == ABS_EXPR)
return arg0;
else if (tree_expr_nonnegative_p (arg0))
return arg0;
/* Strip sign ops from argument. */
if (TREE_CODE (type) == REAL_TYPE)
{
tem = fold_strip_sign_ops (arg0);
if (tem)
return fold_build1_loc (loc, ABS_EXPR, type,
fold_convert_loc (loc, type, tem));
}
return NULL_TREE;
case CONJ_EXPR:
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
return fold_convert_loc (loc, type, arg0);
if (TREE_CODE (arg0) == COMPLEX_EXPR)
{
tree itype = TREE_TYPE (type);
tree rpart = fold_convert_loc (loc, itype, TREE_OPERAND (arg0, 0));
tree ipart = fold_convert_loc (loc, itype, TREE_OPERAND (arg0, 1));
return fold_build2_loc (loc, COMPLEX_EXPR, type, rpart,
negate_expr (ipart));
}
if (TREE_CODE (arg0) == COMPLEX_CST)
{
tree itype = TREE_TYPE (type);
tree rpart = fold_convert_loc (loc, itype, TREE_REALPART (arg0));
tree ipart = fold_convert_loc (loc, itype, TREE_IMAGPART (arg0));
return build_complex (type, rpart, negate_expr (ipart));
}
if (TREE_CODE (arg0) == CONJ_EXPR)
return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
return NULL_TREE;
case BIT_NOT_EXPR:
if (TREE_CODE (arg0) == INTEGER_CST)
return fold_not_const (arg0, type);
else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
/* Convert ~ (-A) to A - 1. */
else if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == NEGATE_EXPR)
return fold_build2_loc (loc, MINUS_EXPR, type,
fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0)),
build_int_cst (type, 1));
/* Convert ~ (A - 1) or ~ (A + -1) to -A. */
else if (INTEGRAL_TYPE_P (type)
&& ((TREE_CODE (arg0) == MINUS_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1)))
|| (TREE_CODE (arg0) == PLUS_EXPR
&& integer_all_onesp (TREE_OPERAND (arg0, 1)))))
return fold_build1_loc (loc, NEGATE_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)));
/* Convert ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify. */
else if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& (tem = fold_unary_loc (loc, BIT_NOT_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)))))
return fold_build2_loc (loc, BIT_XOR_EXPR, type, tem,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 1)));
else if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& (tem = fold_unary_loc (loc, BIT_NOT_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 1)))))
return fold_build2_loc (loc, BIT_XOR_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)), tem);
/* Perform BIT_NOT_EXPR on each element individually. */
else if (TREE_CODE (arg0) == VECTOR_CST)
{
tree *elements;
tree elem;
unsigned count = VECTOR_CST_NELTS (arg0), i;
elements = XALLOCAVEC (tree, count);
for (i = 0; i < count; i++)
{
elem = VECTOR_CST_ELT (arg0, i);
elem = fold_unary_loc (loc, BIT_NOT_EXPR, TREE_TYPE (type), elem);
if (elem == NULL_TREE)
break;
elements[i] = elem;
}
if (i == count)
return build_vector (type, elements);
}
return NULL_TREE;
case TRUTH_NOT_EXPR:
/* The argument to invert_truthvalue must have Boolean type. */
if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE)
arg0 = fold_convert_loc (loc, boolean_type_node, arg0);
/* Note that the operand of this must be an int
and its values must be 0 or 1.
("true" is a fixed value perhaps depending on the language,
but we don't handle values other than 1 correctly yet.) */
tem = fold_truth_not_expr (loc, arg0);
if (!tem)
return NULL_TREE;
return fold_convert_loc (loc, type, tem);
case REALPART_EXPR:
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
return fold_convert_loc (loc, type, arg0);
if (TREE_CODE (arg0) == COMPLEX_EXPR)
return omit_one_operand_loc (loc, type, TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg0, 1));
if (TREE_CODE (arg0) == COMPLEX_CST)
return fold_convert_loc (loc, type, TREE_REALPART (arg0));
if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
{
tree itype = TREE_TYPE (TREE_TYPE (arg0));
tem = fold_build2_loc (loc, TREE_CODE (arg0), itype,
fold_build1_loc (loc, REALPART_EXPR, itype,
TREE_OPERAND (arg0, 0)),
fold_build1_loc (loc, REALPART_EXPR, itype,
TREE_OPERAND (arg0, 1)));
return fold_convert_loc (loc, type, tem);
}
if (TREE_CODE (arg0) == CONJ_EXPR)
{
tree itype = TREE_TYPE (TREE_TYPE (arg0));
tem = fold_build1_loc (loc, REALPART_EXPR, itype,
TREE_OPERAND (arg0, 0));
return fold_convert_loc (loc, type, tem);
}
if (TREE_CODE (arg0) == CALL_EXPR)
{
tree fn = get_callee_fndecl (arg0);
if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
switch (DECL_FUNCTION_CODE (fn))
{
CASE_FLT_FN (BUILT_IN_CEXPI):
fn = mathfn_built_in (type, BUILT_IN_COS);
if (fn)
return build_call_expr_loc (loc, fn, 1, CALL_EXPR_ARG (arg0, 0));
break;
default:
break;
}
}
return NULL_TREE;
case IMAGPART_EXPR:
if (TREE_CODE (TREE_TYPE (arg0)) != COMPLEX_TYPE)
return build_zero_cst (type);
if (TREE_CODE (arg0) == COMPLEX_EXPR)
return omit_one_operand_loc (loc, type, TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg0, 0));
if (TREE_CODE (arg0) == COMPLEX_CST)
return fold_convert_loc (loc, type, TREE_IMAGPART (arg0));
if (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
{
tree itype = TREE_TYPE (TREE_TYPE (arg0));
tem = fold_build2_loc (loc, TREE_CODE (arg0), itype,
fold_build1_loc (loc, IMAGPART_EXPR, itype,
TREE_OPERAND (arg0, 0)),
fold_build1_loc (loc, IMAGPART_EXPR, itype,
TREE_OPERAND (arg0, 1)));
return fold_convert_loc (loc, type, tem);
}
if (TREE_CODE (arg0) == CONJ_EXPR)
{
tree itype = TREE_TYPE (TREE_TYPE (arg0));
tem = fold_build1_loc (loc, IMAGPART_EXPR, itype, TREE_OPERAND (arg0, 0));
return fold_convert_loc (loc, type, negate_expr (tem));
}
if (TREE_CODE (arg0) == CALL_EXPR)
{
tree fn = get_callee_fndecl (arg0);
if (fn && DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL)
switch (DECL_FUNCTION_CODE (fn))
{
CASE_FLT_FN (BUILT_IN_CEXPI):
fn = mathfn_built_in (type, BUILT_IN_SIN);
if (fn)
return build_call_expr_loc (loc, fn, 1, CALL_EXPR_ARG (arg0, 0));
break;
default:
break;
}
}
return NULL_TREE;
case INDIRECT_REF:
/* Fold *&X to X if X is an lvalue. */
if (TREE_CODE (op0) == ADDR_EXPR)
{
tree op00 = TREE_OPERAND (op0, 0);
if ((TREE_CODE (op00) == VAR_DECL
|| TREE_CODE (op00) == PARM_DECL
|| TREE_CODE (op00) == RESULT_DECL)
&& !TREE_READONLY (op00))
return op00;
}
return NULL_TREE;
case VEC_UNPACK_LO_EXPR:
case VEC_UNPACK_HI_EXPR:
case VEC_UNPACK_FLOAT_LO_EXPR:
case VEC_UNPACK_FLOAT_HI_EXPR:
{
unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i;
tree *elts;
enum tree_code subcode;
gcc_assert (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)) == nelts * 2);
if (TREE_CODE (arg0) != VECTOR_CST)
return NULL_TREE;
elts = XALLOCAVEC (tree, nelts * 2);
if (!vec_cst_ctor_to_array (arg0, elts))
return NULL_TREE;
if ((!BYTES_BIG_ENDIAN) ^ (code == VEC_UNPACK_LO_EXPR
|| code == VEC_UNPACK_FLOAT_LO_EXPR))
elts += nelts;
if (code == VEC_UNPACK_LO_EXPR || code == VEC_UNPACK_HI_EXPR)
subcode = NOP_EXPR;
else
subcode = FLOAT_EXPR;
for (i = 0; i < nelts; i++)
{
elts[i] = fold_convert_const (subcode, TREE_TYPE (type), elts[i]);
if (elts[i] == NULL_TREE || !CONSTANT_CLASS_P (elts[i]))
return NULL_TREE;
}
return build_vector (type, elts);
}
case REDUC_MIN_EXPR:
case REDUC_MAX_EXPR:
case REDUC_PLUS_EXPR:
{
unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i;
tree *elts;
enum tree_code subcode;
if (TREE_CODE (op0) != VECTOR_CST)
return NULL_TREE;
elts = XALLOCAVEC (tree, nelts);
if (!vec_cst_ctor_to_array (op0, elts))
return NULL_TREE;
switch (code)
{
case REDUC_MIN_EXPR: subcode = MIN_EXPR; break;
case REDUC_MAX_EXPR: subcode = MAX_EXPR; break;
case REDUC_PLUS_EXPR: subcode = PLUS_EXPR; break;
default: gcc_unreachable ();
}
for (i = 1; i < nelts; i++)
{
elts[0] = const_binop (subcode, elts[0], elts[i]);
if (elts[0] == NULL_TREE || !CONSTANT_CLASS_P (elts[0]))
return NULL_TREE;
elts[i] = build_zero_cst (TREE_TYPE (type));
}
return build_vector (type, elts);
}
default:
return NULL_TREE;
} /* switch (code) */
}
/* If the operation was a conversion do _not_ mark a resulting constant
with TREE_OVERFLOW if the original constant was not. These conversions
have implementation defined behavior and retaining the TREE_OVERFLOW
flag here would confuse later passes such as VRP. */
tree
fold_unary_ignore_overflow_loc (location_t loc, enum tree_code code,
tree type, tree op0)
{
tree res = fold_unary_loc (loc, code, type, op0);
if (res
&& TREE_CODE (res) == INTEGER_CST
&& TREE_CODE (op0) == INTEGER_CST
&& CONVERT_EXPR_CODE_P (code))
TREE_OVERFLOW (res) = TREE_OVERFLOW (op0);
return res;
}
/* Fold a binary bitwise/truth expression of code CODE and type TYPE with
operands OP0 and OP1. LOC is the location of the resulting expression.
ARG0 and ARG1 are the NOP_STRIPed results of OP0 and OP1.
Return the folded expression if folding is successful. Otherwise,
return NULL_TREE. */
static tree
fold_truth_andor (location_t loc, enum tree_code code, tree type,
tree arg0, tree arg1, tree op0, tree op1)
{
tree tem;
/* We only do these simplifications if we are optimizing. */
if (!optimize)
return NULL_TREE;
/* Check for things like (A || B) && (A || C). We can convert this
to A || (B && C). Note that either operator can be any of the four
truth and/or operations and the transformation will still be
valid. Also note that we only care about order for the
ANDIF and ORIF operators. If B contains side effects, this
might change the truth-value of A. */
if (TREE_CODE (arg0) == TREE_CODE (arg1)
&& (TREE_CODE (arg0) == TRUTH_ANDIF_EXPR
|| TREE_CODE (arg0) == TRUTH_ORIF_EXPR
|| TREE_CODE (arg0) == TRUTH_AND_EXPR
|| TREE_CODE (arg0) == TRUTH_OR_EXPR)
&& ! TREE_SIDE_EFFECTS (TREE_OPERAND (arg0, 1)))
{
tree a00 = TREE_OPERAND (arg0, 0);
tree a01 = TREE_OPERAND (arg0, 1);
tree a10 = TREE_OPERAND (arg1, 0);
tree a11 = TREE_OPERAND (arg1, 1);
int commutative = ((TREE_CODE (arg0) == TRUTH_OR_EXPR
|| TREE_CODE (arg0) == TRUTH_AND_EXPR)
&& (code == TRUTH_AND_EXPR
|| code == TRUTH_OR_EXPR));
if (operand_equal_p (a00, a10, 0))
return fold_build2_loc (loc, TREE_CODE (arg0), type, a00,
fold_build2_loc (loc, code, type, a01, a11));
else if (commutative && operand_equal_p (a00, a11, 0))
return fold_build2_loc (loc, TREE_CODE (arg0), type, a00,
fold_build2_loc (loc, code, type, a01, a10));
else if (commutative && operand_equal_p (a01, a10, 0))
return fold_build2_loc (loc, TREE_CODE (arg0), type, a01,
fold_build2_loc (loc, code, type, a00, a11));
/* This case if tricky because we must either have commutative
operators or else A10 must not have side-effects. */
else if ((commutative || ! TREE_SIDE_EFFECTS (a10))
&& operand_equal_p (a01, a11, 0))
return fold_build2_loc (loc, TREE_CODE (arg0), type,
fold_build2_loc (loc, code, type, a00, a10),
a01);
}
/* See if we can build a range comparison. */
if (0 != (tem = fold_range_test (loc, code, type, op0, op1)))
return tem;
if ((code == TRUTH_ANDIF_EXPR && TREE_CODE (arg0) == TRUTH_ORIF_EXPR)
|| (code == TRUTH_ORIF_EXPR && TREE_CODE (arg0) == TRUTH_ANDIF_EXPR))
{
tem = merge_truthop_with_opposite_arm (loc, arg0, arg1, true);
if (tem)
return fold_build2_loc (loc, code, type, tem, arg1);
}
if ((code == TRUTH_ANDIF_EXPR && TREE_CODE (arg1) == TRUTH_ORIF_EXPR)
|| (code == TRUTH_ORIF_EXPR && TREE_CODE (arg1) == TRUTH_ANDIF_EXPR))
{
tem = merge_truthop_with_opposite_arm (loc, arg1, arg0, false);
if (tem)
return fold_build2_loc (loc, code, type, arg0, tem);
}
/* Check for the possibility of merging component references. If our
lhs is another similar operation, try to merge its rhs with our
rhs. Then try to merge our lhs and rhs. */
if (TREE_CODE (arg0) == code
&& 0 != (tem = fold_truth_andor_1 (loc, code, type,
TREE_OPERAND (arg0, 1), arg1)))
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem);
if ((tem = fold_truth_andor_1 (loc, code, type, arg0, arg1)) != 0)
return tem;
if (LOGICAL_OP_NON_SHORT_CIRCUIT
&& (code == TRUTH_AND_EXPR
|| code == TRUTH_ANDIF_EXPR
|| code == TRUTH_OR_EXPR
|| code == TRUTH_ORIF_EXPR))
{
enum tree_code ncode, icode;
ncode = (code == TRUTH_ANDIF_EXPR || code == TRUTH_AND_EXPR)
? TRUTH_AND_EXPR : TRUTH_OR_EXPR;
icode = ncode == TRUTH_AND_EXPR ? TRUTH_ANDIF_EXPR : TRUTH_ORIF_EXPR;
/* Transform ((A AND-IF B) AND[-IF] C) into (A AND-IF (B AND C)),
or ((A OR-IF B) OR[-IF] C) into (A OR-IF (B OR C))
We don't want to pack more than two leafs to a non-IF AND/OR
expression.
If tree-code of left-hand operand isn't an AND/OR-IF code and not
equal to IF-CODE, then we don't want to add right-hand operand.
If the inner right-hand side of left-hand operand has
side-effects, or isn't simple, then we can't add to it,
as otherwise we might destroy if-sequence. */
if (TREE_CODE (arg0) == icode
&& simple_operand_p_2 (arg1)
/* Needed for sequence points to handle trappings, and
side-effects. */
&& simple_operand_p_2 (TREE_OPERAND (arg0, 1)))
{
tem = fold_build2_loc (loc, ncode, type, TREE_OPERAND (arg0, 1),
arg1);
return fold_build2_loc (loc, icode, type, TREE_OPERAND (arg0, 0),
tem);
}
/* Same as abouve but for (A AND[-IF] (B AND-IF C)) -> ((A AND B) AND-IF C),
or (A OR[-IF] (B OR-IF C) -> ((A OR B) OR-IF C). */
else if (TREE_CODE (arg1) == icode
&& simple_operand_p_2 (arg0)
/* Needed for sequence points to handle trappings, and
side-effects. */
&& simple_operand_p_2 (TREE_OPERAND (arg1, 0)))
{
tem = fold_build2_loc (loc, ncode, type,
arg0, TREE_OPERAND (arg1, 0));
return fold_build2_loc (loc, icode, type, tem,
TREE_OPERAND (arg1, 1));
}
/* Transform (A AND-IF B) into (A AND B), or (A OR-IF B)
into (A OR B).
For sequence point consistancy, we need to check for trapping,
and side-effects. */
else if (code == icode && simple_operand_p_2 (arg0)
&& simple_operand_p_2 (arg1))
return fold_build2_loc (loc, ncode, type, arg0, arg1);
}
return NULL_TREE;
}
/* Fold a binary expression of code CODE and type TYPE with operands
OP0 and OP1, containing either a MIN-MAX or a MAX-MIN combination.
Return the folded expression if folding is successful. Otherwise,
return NULL_TREE. */
static tree
fold_minmax (location_t loc, enum tree_code code, tree type, tree op0, tree op1)
{
enum tree_code compl_code;
if (code == MIN_EXPR)
compl_code = MAX_EXPR;
else if (code == MAX_EXPR)
compl_code = MIN_EXPR;
else
gcc_unreachable ();
/* MIN (MAX (a, b), b) == b. */
if (TREE_CODE (op0) == compl_code
&& operand_equal_p (TREE_OPERAND (op0, 1), op1, 0))
return omit_one_operand_loc (loc, type, op1, TREE_OPERAND (op0, 0));
/* MIN (MAX (b, a), b) == b. */
if (TREE_CODE (op0) == compl_code
&& operand_equal_p (TREE_OPERAND (op0, 0), op1, 0)
&& reorder_operands_p (TREE_OPERAND (op0, 1), op1))
return omit_one_operand_loc (loc, type, op1, TREE_OPERAND (op0, 1));
/* MIN (a, MAX (a, b)) == a. */
if (TREE_CODE (op1) == compl_code
&& operand_equal_p (op0, TREE_OPERAND (op1, 0), 0)
&& reorder_operands_p (op0, TREE_OPERAND (op1, 1)))
return omit_one_operand_loc (loc, type, op0, TREE_OPERAND (op1, 1));
/* MIN (a, MAX (b, a)) == a. */
if (TREE_CODE (op1) == compl_code
&& operand_equal_p (op0, TREE_OPERAND (op1, 1), 0)
&& reorder_operands_p (op0, TREE_OPERAND (op1, 0)))
return omit_one_operand_loc (loc, type, op0, TREE_OPERAND (op1, 0));
return NULL_TREE;
}
/* Helper that tries to canonicalize the comparison ARG0 CODE ARG1
by changing CODE to reduce the magnitude of constants involved in
ARG0 of the comparison.
Returns a canonicalized comparison tree if a simplification was
possible, otherwise returns NULL_TREE.
Set *STRICT_OVERFLOW_P to true if the canonicalization is only
valid if signed overflow is undefined. */
static tree
maybe_canonicalize_comparison_1 (location_t loc, enum tree_code code, tree type,
tree arg0, tree arg1,
bool *strict_overflow_p)
{
enum tree_code code0 = TREE_CODE (arg0);
tree t, cst0 = NULL_TREE;
int sgn0;
bool swap = false;
/* Match A +- CST code arg1 and CST code arg1. We can change the
first form only if overflow is undefined. */
if (!((TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0))
/* In principle pointers also have undefined overflow behavior,
but that causes problems elsewhere. */
&& !POINTER_TYPE_P (TREE_TYPE (arg0))
&& (code0 == MINUS_EXPR
|| code0 == PLUS_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
|| code0 == INTEGER_CST))
return NULL_TREE;
/* Identify the constant in arg0 and its sign. */
if (code0 == INTEGER_CST)
cst0 = arg0;
else
cst0 = TREE_OPERAND (arg0, 1);
sgn0 = tree_int_cst_sgn (cst0);
/* Overflowed constants and zero will cause problems. */
if (integer_zerop (cst0)
|| TREE_OVERFLOW (cst0))
return NULL_TREE;
/* See if we can reduce the magnitude of the constant in
arg0 by changing the comparison code. */
if (code0 == INTEGER_CST)
{
/* CST <= arg1 -> CST-1 < arg1. */
if (code == LE_EXPR && sgn0 == 1)
code = LT_EXPR;
/* -CST < arg1 -> -CST-1 <= arg1. */
else if (code == LT_EXPR && sgn0 == -1)
code = LE_EXPR;
/* CST > arg1 -> CST-1 >= arg1. */
else if (code == GT_EXPR && sgn0 == 1)
code = GE_EXPR;
/* -CST >= arg1 -> -CST-1 > arg1. */
else if (code == GE_EXPR && sgn0 == -1)
code = GT_EXPR;
else
return NULL_TREE;
/* arg1 code' CST' might be more canonical. */
swap = true;
}
else
{
/* A - CST < arg1 -> A - CST-1 <= arg1. */
if (code == LT_EXPR
&& code0 == ((sgn0 == -1) ? PLUS_EXPR : MINUS_EXPR))
code = LE_EXPR;
/* A + CST > arg1 -> A + CST-1 >= arg1. */
else if (code == GT_EXPR
&& code0 == ((sgn0 == -1) ? MINUS_EXPR : PLUS_EXPR))
code = GE_EXPR;
/* A + CST <= arg1 -> A + CST-1 < arg1. */
else if (code == LE_EXPR
&& code0 == ((sgn0 == -1) ? MINUS_EXPR : PLUS_EXPR))
code = LT_EXPR;
/* A - CST >= arg1 -> A - CST-1 > arg1. */
else if (code == GE_EXPR
&& code0 == ((sgn0 == -1) ? PLUS_EXPR : MINUS_EXPR))
code = GT_EXPR;
else
return NULL_TREE;
*strict_overflow_p = true;
}
/* Now build the constant reduced in magnitude. But not if that
would produce one outside of its types range. */
if (INTEGRAL_TYPE_P (TREE_TYPE (cst0))
&& ((sgn0 == 1
&& TYPE_MIN_VALUE (TREE_TYPE (cst0))
&& tree_int_cst_equal (cst0, TYPE_MIN_VALUE (TREE_TYPE (cst0))))
|| (sgn0 == -1
&& TYPE_MAX_VALUE (TREE_TYPE (cst0))
&& tree_int_cst_equal (cst0, TYPE_MAX_VALUE (TREE_TYPE (cst0))))))
/* We cannot swap the comparison here as that would cause us to
endlessly recurse. */
return NULL_TREE;
t = int_const_binop (sgn0 == -1 ? PLUS_EXPR : MINUS_EXPR,
cst0, build_int_cst (TREE_TYPE (cst0), 1));
if (code0 != INTEGER_CST)
t = fold_build2_loc (loc, code0, TREE_TYPE (arg0), TREE_OPERAND (arg0, 0), t);
t = fold_convert (TREE_TYPE (arg1), t);
/* If swapping might yield to a more canonical form, do so. */
if (swap)
return fold_build2_loc (loc, swap_tree_comparison (code), type, arg1, t);
else
return fold_build2_loc (loc, code, type, t, arg1);
}
/* Canonicalize the comparison ARG0 CODE ARG1 with type TYPE with undefined
overflow further. Try to decrease the magnitude of constants involved
by changing LE_EXPR and GE_EXPR to LT_EXPR and GT_EXPR or vice versa
and put sole constants at the second argument position.
Returns the canonicalized tree if changed, otherwise NULL_TREE. */
static tree
maybe_canonicalize_comparison (location_t loc, enum tree_code code, tree type,
tree arg0, tree arg1)
{
tree t;
bool strict_overflow_p;
const char * const warnmsg = G_("assuming signed overflow does not occur "
"when reducing constant in comparison");
/* Try canonicalization by simplifying arg0. */
strict_overflow_p = false;
t = maybe_canonicalize_comparison_1 (loc, code, type, arg0, arg1,
&strict_overflow_p);
if (t)
{
if (strict_overflow_p)
fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE);
return t;
}
/* Try canonicalization by simplifying arg1 using the swapped
comparison. */
code = swap_tree_comparison (code);
strict_overflow_p = false;
t = maybe_canonicalize_comparison_1 (loc, code, type, arg1, arg0,
&strict_overflow_p);
if (t && strict_overflow_p)
fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE);
return t;
}
/* Return whether BASE + OFFSET + BITPOS may wrap around the address
space. This is used to avoid issuing overflow warnings for
expressions like &p->x which can not wrap. */
static bool
pointer_may_wrap_p (tree base, tree offset, HOST_WIDE_INT bitpos)
{
double_int di_offset, total;
if (!POINTER_TYPE_P (TREE_TYPE (base)))
return true;
if (bitpos < 0)
return true;
if (offset == NULL_TREE)
di_offset = double_int_zero;
else if (TREE_CODE (offset) != INTEGER_CST || TREE_OVERFLOW (offset))
return true;
else
di_offset = TREE_INT_CST (offset);
bool overflow;
double_int units = double_int::from_uhwi (bitpos / BITS_PER_UNIT);
total = di_offset.add_with_sign (units, true, &overflow);
if (overflow)
return true;
if (total.high != 0)
return true;
HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (TREE_TYPE (base)));
if (size <= 0)
return true;
/* We can do slightly better for SIZE if we have an ADDR_EXPR of an
array. */
if (TREE_CODE (base) == ADDR_EXPR)
{
HOST_WIDE_INT base_size;
base_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (base, 0)));
if (base_size > 0 && size < base_size)
size = base_size;
}
return total.low > (unsigned HOST_WIDE_INT) size;
}
/* Subroutine of fold_binary. This routine performs all of the
transformations that are common to the equality/inequality
operators (EQ_EXPR and NE_EXPR) and the ordering operators
(LT_EXPR, LE_EXPR, GE_EXPR and GT_EXPR). Callers other than
fold_binary should call fold_binary. Fold a comparison with
tree code CODE and type TYPE with operands OP0 and OP1. Return
the folded comparison or NULL_TREE. */
static tree
fold_comparison (location_t loc, enum tree_code code, tree type,
tree op0, tree op1)
{
tree arg0, arg1, tem;
arg0 = op0;
arg1 = op1;
STRIP_SIGN_NOPS (arg0);
STRIP_SIGN_NOPS (arg1);
tem = fold_relational_const (code, type, arg0, arg1);
if (tem != NULL_TREE)
return tem;
/* If one arg is a real or integer constant, put it last. */
if (tree_swap_operands_p (arg0, arg1, true))
return fold_build2_loc (loc, swap_tree_comparison (code), type, op1, op0);
/* Transform comparisons of the form X +- C1 CMP C2 to X CMP C2 +- C1. */
if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
&& (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& !TREE_OVERFLOW (TREE_OPERAND (arg0, 1))
&& TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))
&& (TREE_CODE (arg1) == INTEGER_CST
&& !TREE_OVERFLOW (arg1)))
{
tree const1 = TREE_OPERAND (arg0, 1);
tree const2 = arg1;
tree variable = TREE_OPERAND (arg0, 0);
tree lhs;
int lhs_add;
lhs_add = TREE_CODE (arg0) != PLUS_EXPR;
lhs = fold_build2_loc (loc, lhs_add ? PLUS_EXPR : MINUS_EXPR,
TREE_TYPE (arg1), const2, const1);
/* If the constant operation overflowed this can be
simplified as a comparison against INT_MAX/INT_MIN. */
if (TREE_CODE (lhs) == INTEGER_CST
&& TREE_OVERFLOW (lhs))
{
int const1_sgn = tree_int_cst_sgn (const1);
enum tree_code code2 = code;
/* Get the sign of the constant on the lhs if the
operation were VARIABLE + CONST1. */
if (TREE_CODE (arg0) == MINUS_EXPR)
const1_sgn = -const1_sgn;
/* The sign of the constant determines if we overflowed
INT_MAX (const1_sgn == -1) or INT_MIN (const1_sgn == 1).
Canonicalize to the INT_MIN overflow by swapping the comparison
if necessary. */
if (const1_sgn == -1)
code2 = swap_tree_comparison (code);
/* We now can look at the canonicalized case
VARIABLE + 1 CODE2 INT_MIN
and decide on the result. */
if (code2 == LT_EXPR
|| code2 == LE_EXPR
|| code2 == EQ_EXPR)
return omit_one_operand_loc (loc, type, boolean_false_node, variable);
else if (code2 == NE_EXPR
|| code2 == GE_EXPR
|| code2 == GT_EXPR)
return omit_one_operand_loc (loc, type, boolean_true_node, variable);
}
if (TREE_CODE (lhs) == TREE_CODE (arg1)
&& (TREE_CODE (lhs) != INTEGER_CST
|| !TREE_OVERFLOW (lhs)))
{
if (code != EQ_EXPR && code != NE_EXPR)
fold_overflow_warning ("assuming signed overflow does not occur "
"when changing X +- C1 cmp C2 to "
"X cmp C1 +- C2",
WARN_STRICT_OVERFLOW_COMPARISON);
return fold_build2_loc (loc, code, type, variable, lhs);
}
}
/* For comparisons of pointers we can decompose it to a compile time
comparison of the base objects and the offsets into the object.
This requires at least one operand being an ADDR_EXPR or a
POINTER_PLUS_EXPR to do more than the operand_equal_p test below. */
if (POINTER_TYPE_P (TREE_TYPE (arg0))
&& (TREE_CODE (arg0) == ADDR_EXPR
|| TREE_CODE (arg1) == ADDR_EXPR
|| TREE_CODE (arg0) == POINTER_PLUS_EXPR
|| TREE_CODE (arg1) == POINTER_PLUS_EXPR))
{
tree base0, base1, offset0 = NULL_TREE, offset1 = NULL_TREE;
HOST_WIDE_INT bitsize, bitpos0 = 0, bitpos1 = 0;
enum machine_mode mode;
int volatilep, unsignedp;
bool indirect_base0 = false, indirect_base1 = false;
/* Get base and offset for the access. Strip ADDR_EXPR for
get_inner_reference, but put it back by stripping INDIRECT_REF
off the base object if possible. indirect_baseN will be true
if baseN is not an address but refers to the object itself. */
base0 = arg0;
if (TREE_CODE (arg0) == ADDR_EXPR)
{
base0 = get_inner_reference (TREE_OPERAND (arg0, 0),
&bitsize, &bitpos0, &offset0, &mode,
&unsignedp, &volatilep, false);
if (TREE_CODE (base0) == INDIRECT_REF)
base0 = TREE_OPERAND (base0, 0);
else
indirect_base0 = true;
}
else if (TREE_CODE (arg0) == POINTER_PLUS_EXPR)
{
base0 = TREE_OPERAND (arg0, 0);
STRIP_SIGN_NOPS (base0);
if (TREE_CODE (base0) == ADDR_EXPR)
{
base0 = TREE_OPERAND (base0, 0);
indirect_base0 = true;
}
offset0 = TREE_OPERAND (arg0, 1);
if (host_integerp (offset0, 0))
{
HOST_WIDE_INT off = size_low_cst (offset0);
if ((HOST_WIDE_INT) (((unsigned HOST_WIDE_INT) off)
* BITS_PER_UNIT)
/ BITS_PER_UNIT == (HOST_WIDE_INT) off)
{
bitpos0 = off * BITS_PER_UNIT;
offset0 = NULL_TREE;
}
}
}
base1 = arg1;
if (TREE_CODE (arg1) == ADDR_EXPR)
{
base1 = get_inner_reference (TREE_OPERAND (arg1, 0),
&bitsize, &bitpos1, &offset1, &mode,
&unsignedp, &volatilep, false);
if (TREE_CODE (base1) == INDIRECT_REF)
base1 = TREE_OPERAND (base1, 0);
else
indirect_base1 = true;
}
else if (TREE_CODE (arg1) == POINTER_PLUS_EXPR)
{
base1 = TREE_OPERAND (arg1, 0);
STRIP_SIGN_NOPS (base1);
if (TREE_CODE (base1) == ADDR_EXPR)
{
base1 = TREE_OPERAND (base1, 0);
indirect_base1 = true;
}
offset1 = TREE_OPERAND (arg1, 1);
if (host_integerp (offset1, 0))
{
HOST_WIDE_INT off = size_low_cst (offset1);
if ((HOST_WIDE_INT) (((unsigned HOST_WIDE_INT) off)
* BITS_PER_UNIT)
/ BITS_PER_UNIT == (HOST_WIDE_INT) off)
{
bitpos1 = off * BITS_PER_UNIT;
offset1 = NULL_TREE;
}
}
}
/* A local variable can never be pointed to by
the default SSA name of an incoming parameter. */
if ((TREE_CODE (arg0) == ADDR_EXPR
&& indirect_base0
&& TREE_CODE (base0) == VAR_DECL
&& auto_var_in_fn_p (base0, current_function_decl)
&& !indirect_base1
&& TREE_CODE (base1) == SSA_NAME
&& SSA_NAME_IS_DEFAULT_DEF (base1)
&& TREE_CODE (SSA_NAME_VAR (base1)) == PARM_DECL)
|| (TREE_CODE (arg1) == ADDR_EXPR
&& indirect_base1
&& TREE_CODE (base1) == VAR_DECL
&& auto_var_in_fn_p (base1, current_function_decl)
&& !indirect_base0
&& TREE_CODE (base0) == SSA_NAME
&& SSA_NAME_IS_DEFAULT_DEF (base0)
&& TREE_CODE (SSA_NAME_VAR (base0)) == PARM_DECL))
{
if (code == NE_EXPR)
return constant_boolean_node (1, type);
else if (code == EQ_EXPR)
return constant_boolean_node (0, type);
}
/* If we have equivalent bases we might be able to simplify. */
else if (indirect_base0 == indirect_base1
&& operand_equal_p (base0, base1, 0))
{
/* We can fold this expression to a constant if the non-constant
offset parts are equal. */
if ((offset0 == offset1
|| (offset0 && offset1
&& operand_equal_p (offset0, offset1, 0)))
&& (code == EQ_EXPR
|| code == NE_EXPR
|| (indirect_base0 && DECL_P (base0))
|| POINTER_TYPE_OVERFLOW_UNDEFINED))
{
if (code != EQ_EXPR
&& code != NE_EXPR
&& bitpos0 != bitpos1
&& (pointer_may_wrap_p (base0, offset0, bitpos0)
|| pointer_may_wrap_p (base1, offset1, bitpos1)))
fold_overflow_warning (("assuming pointer wraparound does not "
"occur when comparing P +- C1 with "
"P +- C2"),
WARN_STRICT_OVERFLOW_CONDITIONAL);
switch (code)
{
case EQ_EXPR:
return constant_boolean_node (bitpos0 == bitpos1, type);
case NE_EXPR:
return constant_boolean_node (bitpos0 != bitpos1, type);
case LT_EXPR:
return constant_boolean_node (bitpos0 < bitpos1, type);
case LE_EXPR:
return constant_boolean_node (bitpos0 <= bitpos1, type);
case GE_EXPR:
return constant_boolean_node (bitpos0 >= bitpos1, type);
case GT_EXPR:
return constant_boolean_node (bitpos0 > bitpos1, type);
default:;
}
}
/* We can simplify the comparison to a comparison of the variable
offset parts if the constant offset parts are equal.
Be careful to use signed sizetype here because otherwise we
mess with array offsets in the wrong way. This is possible
because pointer arithmetic is restricted to retain within an
object and overflow on pointer differences is undefined as of
6.5.6/8 and /9 with respect to the signed ptrdiff_t. */
else if (bitpos0 == bitpos1
&& ((code == EQ_EXPR || code == NE_EXPR)
|| (indirect_base0 && DECL_P (base0))
|| POINTER_TYPE_OVERFLOW_UNDEFINED))
{
/* By converting to signed sizetype we cover middle-end pointer
arithmetic which operates on unsigned pointer types of size
type size and ARRAY_REF offsets which are properly sign or
zero extended from their type in case it is narrower than
sizetype. */
if (offset0 == NULL_TREE)
offset0 = build_int_cst (ssizetype, 0);
else
offset0 = fold_convert_loc (loc, ssizetype, offset0);
if (offset1 == NULL_TREE)
offset1 = build_int_cst (ssizetype, 0);
else
offset1 = fold_convert_loc (loc, ssizetype, offset1);
if (code != EQ_EXPR
&& code != NE_EXPR
&& (pointer_may_wrap_p (base0, offset0, bitpos0)
|| pointer_may_wrap_p (base1, offset1, bitpos1)))
fold_overflow_warning (("assuming pointer wraparound does not "
"occur when comparing P +- C1 with "
"P +- C2"),
WARN_STRICT_OVERFLOW_COMPARISON);
return fold_build2_loc (loc, code, type, offset0, offset1);
}
}
/* For non-equal bases we can simplify if they are addresses
of local binding decls or constants. */
else if (indirect_base0 && indirect_base1
/* We know that !operand_equal_p (base0, base1, 0)
because the if condition was false. But make
sure two decls are not the same. */
&& base0 != base1
&& TREE_CODE (arg0) == ADDR_EXPR
&& TREE_CODE (arg1) == ADDR_EXPR
&& (((TREE_CODE (base0) == VAR_DECL
|| TREE_CODE (base0) == PARM_DECL)
&& (targetm.binds_local_p (base0)
|| CONSTANT_CLASS_P (base1)))
|| CONSTANT_CLASS_P (base0))
&& (((TREE_CODE (base1) == VAR_DECL
|| TREE_CODE (base1) == PARM_DECL)
&& (targetm.binds_local_p (base1)
|| CONSTANT_CLASS_P (base0)))
|| CONSTANT_CLASS_P (base1)))
{
if (code == EQ_EXPR)
return omit_two_operands_loc (loc, type, boolean_false_node,
arg0, arg1);
else if (code == NE_EXPR)
return omit_two_operands_loc (loc, type, boolean_true_node,
arg0, arg1);
}
/* For equal offsets we can simplify to a comparison of the
base addresses. */
else if (bitpos0 == bitpos1
&& (indirect_base0
? base0 != TREE_OPERAND (arg0, 0) : base0 != arg0)
&& (indirect_base1
? base1 != TREE_OPERAND (arg1, 0) : base1 != arg1)
&& ((offset0 == offset1)
|| (offset0 && offset1
&& operand_equal_p (offset0, offset1, 0))))
{
if (indirect_base0)
base0 = build_fold_addr_expr_loc (loc, base0);
if (indirect_base1)
base1 = build_fold_addr_expr_loc (loc, base1);
return fold_build2_loc (loc, code, type, base0, base1);
}
}
/* Transform comparisons of the form X +- C1 CMP Y +- C2 to
X CMP Y +- C2 +- C1 for signed X, Y. This is valid if
the resulting offset is smaller in absolute value than the
original one. */
if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0))
&& (TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
&& (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& !TREE_OVERFLOW (TREE_OPERAND (arg0, 1)))
&& (TREE_CODE (arg1) == PLUS_EXPR || TREE_CODE (arg1) == MINUS_EXPR)
&& (TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
&& !TREE_OVERFLOW (TREE_OPERAND (arg1, 1))))
{
tree const1 = TREE_OPERAND (arg0, 1);
tree const2 = TREE_OPERAND (arg1, 1);
tree variable1 = TREE_OPERAND (arg0, 0);
tree variable2 = TREE_OPERAND (arg1, 0);
tree cst;
const char * const warnmsg = G_("assuming signed overflow does not "
"occur when combining constants around "
"a comparison");
/* Put the constant on the side where it doesn't overflow and is
of lower absolute value than before. */
cst = int_const_binop (TREE_CODE (arg0) == TREE_CODE (arg1)
? MINUS_EXPR : PLUS_EXPR,
const2, const1);
if (!TREE_OVERFLOW (cst)
&& tree_int_cst_compare (const2, cst) == tree_int_cst_sgn (const2))
{
fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON);
return fold_build2_loc (loc, code, type,
variable1,
fold_build2_loc (loc,
TREE_CODE (arg1), TREE_TYPE (arg1),
variable2, cst));
}
cst = int_const_binop (TREE_CODE (arg0) == TREE_CODE (arg1)
? MINUS_EXPR : PLUS_EXPR,
const1, const2);
if (!TREE_OVERFLOW (cst)
&& tree_int_cst_compare (const1, cst) == tree_int_cst_sgn (const1))
{
fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON);
return fold_build2_loc (loc, code, type,
fold_build2_loc (loc, TREE_CODE (arg0), TREE_TYPE (arg0),
variable1, cst),
variable2);
}
}
/* Transform comparisons of the form X * C1 CMP 0 to X CMP 0 in the
signed arithmetic case. That form is created by the compiler
often enough for folding it to be of value. One example is in
computing loop trip counts after Operator Strength Reduction. */
if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0))
&& TREE_CODE (arg0) == MULT_EXPR
&& (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& !TREE_OVERFLOW (TREE_OPERAND (arg0, 1)))
&& integer_zerop (arg1))
{
tree const1 = TREE_OPERAND (arg0, 1);
tree const2 = arg1; /* zero */
tree variable1 = TREE_OPERAND (arg0, 0);
enum tree_code cmp_code = code;
/* Handle unfolded multiplication by zero. */
if (integer_zerop (const1))
return fold_build2_loc (loc, cmp_code, type, const1, const2);
fold_overflow_warning (("assuming signed overflow does not occur when "
"eliminating multiplication in comparison "
"with zero"),
WARN_STRICT_OVERFLOW_COMPARISON);
/* If const1 is negative we swap the sense of the comparison. */
if (tree_int_cst_sgn (const1) < 0)
cmp_code = swap_tree_comparison (cmp_code);
return fold_build2_loc (loc, cmp_code, type, variable1, const2);
}
tem = maybe_canonicalize_comparison (loc, code, type, arg0, arg1);
if (tem)
return tem;
if (FLOAT_TYPE_P (TREE_TYPE (arg0)))
{
tree targ0 = strip_float_extensions (arg0);
tree targ1 = strip_float_extensions (arg1);
tree newtype = TREE_TYPE (targ0);
if (TYPE_PRECISION (TREE_TYPE (targ1)) > TYPE_PRECISION (newtype))
newtype = TREE_TYPE (targ1);
/* Fold (double)float1 CMP (double)float2 into float1 CMP float2. */
if (TYPE_PRECISION (newtype) < TYPE_PRECISION (TREE_TYPE (arg0)))
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, newtype, targ0),
fold_convert_loc (loc, newtype, targ1));
/* (-a) CMP (-b) -> b CMP a */
if (TREE_CODE (arg0) == NEGATE_EXPR
&& TREE_CODE (arg1) == NEGATE_EXPR)
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg1, 0),
TREE_OPERAND (arg0, 0));
if (TREE_CODE (arg1) == REAL_CST)
{
REAL_VALUE_TYPE cst;
cst = TREE_REAL_CST (arg1);
/* (-a) CMP CST -> a swap(CMP) (-CST) */
if (TREE_CODE (arg0) == NEGATE_EXPR)
return fold_build2_loc (loc, swap_tree_comparison (code), type,
TREE_OPERAND (arg0, 0),
build_real (TREE_TYPE (arg1),
real_value_negate (&cst)));
/* IEEE doesn't distinguish +0 and -0 in comparisons. */
/* a CMP (-0) -> a CMP 0 */
if (REAL_VALUE_MINUS_ZERO (cst))
return fold_build2_loc (loc, code, type, arg0,
build_real (TREE_TYPE (arg1), dconst0));
/* x != NaN is always true, other ops are always false. */
if (REAL_VALUE_ISNAN (cst)
&& ! HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1))))
{
tem = (code == NE_EXPR) ? integer_one_node : integer_zero_node;
return omit_one_operand_loc (loc, type, tem, arg0);
}
/* Fold comparisons against infinity. */
if (REAL_VALUE_ISINF (cst)
&& MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg1))))
{
tem = fold_inf_compare (loc, code, type, arg0, arg1);
if (tem != NULL_TREE)
return tem;
}
}
/* If this is a comparison of a real constant with a PLUS_EXPR
or a MINUS_EXPR of a real constant, we can convert it into a
comparison with a revised real constant as long as no overflow
occurs when unsafe_math_optimizations are enabled. */
if (flag_unsafe_math_optimizations
&& TREE_CODE (arg1) == REAL_CST
&& (TREE_CODE (arg0) == PLUS_EXPR
|| TREE_CODE (arg0) == MINUS_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == REAL_CST
&& 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR
? MINUS_EXPR : PLUS_EXPR,
arg1, TREE_OPERAND (arg0, 1)))
&& !TREE_OVERFLOW (tem))
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem);
/* Likewise, we can simplify a comparison of a real constant with
a MINUS_EXPR whose first operand is also a real constant, i.e.
(c1 - x) < c2 becomes x > c1-c2. Reordering is allowed on
floating-point types only if -fassociative-math is set. */
if (flag_associative_math
&& TREE_CODE (arg1) == REAL_CST
&& TREE_CODE (arg0) == MINUS_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == REAL_CST
&& 0 != (tem = const_binop (MINUS_EXPR, TREE_OPERAND (arg0, 0),
arg1))
&& !TREE_OVERFLOW (tem))
return fold_build2_loc (loc, swap_tree_comparison (code), type,
TREE_OPERAND (arg0, 1), tem);
/* Fold comparisons against built-in math functions. */
if (TREE_CODE (arg1) == REAL_CST
&& flag_unsafe_math_optimizations
&& ! flag_errno_math)
{
enum built_in_function fcode = builtin_mathfn_code (arg0);
if (fcode != END_BUILTINS)
{
tem = fold_mathfn_compare (loc, fcode, code, type, arg0, arg1);
if (tem != NULL_TREE)
return tem;
}
}
}
if (TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE
&& CONVERT_EXPR_P (arg0))
{
/* If we are widening one operand of an integer comparison,
see if the other operand is similarly being widened. Perhaps we
can do the comparison in the narrower type. */
tem = fold_widened_comparison (loc, code, type, arg0, arg1);
if (tem)
return tem;
/* Or if we are changing signedness. */
tem = fold_sign_changed_comparison (loc, code, type, arg0, arg1);
if (tem)
return tem;
}
/* If this is comparing a constant with a MIN_EXPR or a MAX_EXPR of a
constant, we can simplify it. */
if (TREE_CODE (arg1) == INTEGER_CST
&& (TREE_CODE (arg0) == MIN_EXPR
|| TREE_CODE (arg0) == MAX_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
{
tem = optimize_minmax_comparison (loc, code, type, op0, op1);
if (tem)
return tem;
}
/* Simplify comparison of something with itself. (For IEEE
floating-point, we can only do some of these simplifications.) */
if (operand_equal_p (arg0, arg1, 0))
{
switch (code)
{
case EQ_EXPR:
if (! FLOAT_TYPE_P (TREE_TYPE (arg0))
|| ! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))))
return constant_boolean_node (1, type);
break;
case GE_EXPR:
case LE_EXPR:
if (! FLOAT_TYPE_P (TREE_TYPE (arg0))
|| ! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))))
return constant_boolean_node (1, type);
return fold_build2_loc (loc, EQ_EXPR, type, arg0, arg1);
case NE_EXPR:
/* For NE, we can only do this simplification if integer
or we don't honor IEEE floating point NaNs. */
if (FLOAT_TYPE_P (TREE_TYPE (arg0))
&& HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))))
break;
/* ... fall through ... */
case GT_EXPR:
case LT_EXPR:
return constant_boolean_node (0, type);
default:
gcc_unreachable ();
}
}
/* If we are comparing an expression that just has comparisons
of two integer values, arithmetic expressions of those comparisons,
and constants, we can simplify it. There are only three cases
to check: the two values can either be equal, the first can be
greater, or the second can be greater. Fold the expression for
those three values. Since each value must be 0 or 1, we have
eight possibilities, each of which corresponds to the constant 0
or 1 or one of the six possible comparisons.
This handles common cases like (a > b) == 0 but also handles
expressions like ((x > y) - (y > x)) > 0, which supposedly
occur in macroized code. */
if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) != INTEGER_CST)
{
tree cval1 = 0, cval2 = 0;
int save_p = 0;
if (twoval_comparison_p (arg0, &cval1, &cval2, &save_p)
/* Don't handle degenerate cases here; they should already
have been handled anyway. */
&& cval1 != 0 && cval2 != 0
&& ! (TREE_CONSTANT (cval1) && TREE_CONSTANT (cval2))
&& TREE_TYPE (cval1) == TREE_TYPE (cval2)
&& INTEGRAL_TYPE_P (TREE_TYPE (cval1))
&& TYPE_MAX_VALUE (TREE_TYPE (cval1))
&& TYPE_MAX_VALUE (TREE_TYPE (cval2))
&& ! operand_equal_p (TYPE_MIN_VALUE (TREE_TYPE (cval1)),
TYPE_MAX_VALUE (TREE_TYPE (cval2)), 0))
{
tree maxval = TYPE_MAX_VALUE (TREE_TYPE (cval1));
tree minval = TYPE_MIN_VALUE (TREE_TYPE (cval1));
/* We can't just pass T to eval_subst in case cval1 or cval2
was the same as ARG1. */
tree high_result
= fold_build2_loc (loc, code, type,
eval_subst (loc, arg0, cval1, maxval,
cval2, minval),
arg1);
tree equal_result
= fold_build2_loc (loc, code, type,
eval_subst (loc, arg0, cval1, maxval,
cval2, maxval),
arg1);
tree low_result
= fold_build2_loc (loc, code, type,
eval_subst (loc, arg0, cval1, minval,
cval2, maxval),
arg1);
/* All three of these results should be 0 or 1. Confirm they are.
Then use those values to select the proper code to use. */
if (TREE_CODE (high_result) == INTEGER_CST
&& TREE_CODE (equal_result) == INTEGER_CST
&& TREE_CODE (low_result) == INTEGER_CST)
{
/* Make a 3-bit mask with the high-order bit being the
value for `>', the next for '=', and the low for '<'. */
switch ((integer_onep (high_result) * 4)
+ (integer_onep (equal_result) * 2)
+ integer_onep (low_result))
{
case 0:
/* Always false. */
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
case 1:
code = LT_EXPR;
break;
case 2:
code = EQ_EXPR;
break;
case 3:
code = LE_EXPR;
break;
case 4:
code = GT_EXPR;
break;
case 5:
code = NE_EXPR;
break;
case 6:
code = GE_EXPR;
break;
case 7:
/* Always true. */
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
}
if (save_p)
{
tem = save_expr (build2 (code, type, cval1, cval2));
SET_EXPR_LOCATION (tem, loc);
return tem;
}
return fold_build2_loc (loc, code, type, cval1, cval2);
}
}
}
/* We can fold X/C1 op C2 where C1 and C2 are integer constants
into a single range test. */
if ((TREE_CODE (arg0) == TRUNC_DIV_EXPR
|| TREE_CODE (arg0) == EXACT_DIV_EXPR)
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& !integer_zerop (TREE_OPERAND (arg0, 1))
&& !TREE_OVERFLOW (TREE_OPERAND (arg0, 1))
&& !TREE_OVERFLOW (arg1))
{
tem = fold_div_compare (loc, code, type, arg0, arg1);
if (tem != NULL_TREE)
return tem;
}
/* Fold ~X op ~Y as Y op X. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == BIT_NOT_EXPR)
{
tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0));
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, cmp_type,
TREE_OPERAND (arg1, 0)),
TREE_OPERAND (arg0, 0));
}
/* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == INTEGER_CST)
{
tree cmp_type = TREE_TYPE (TREE_OPERAND (arg0, 0));
return fold_build2_loc (loc, swap_tree_comparison (code), type,
TREE_OPERAND (arg0, 0),
fold_build1_loc (loc, BIT_NOT_EXPR, cmp_type,
fold_convert_loc (loc, cmp_type, arg1)));
}
return NULL_TREE;
}
/* Subroutine of fold_binary. Optimize complex multiplications of the
form z * conj(z), as pow(realpart(z),2) + pow(imagpart(z),2). The
argument EXPR represents the expression "z" of type TYPE. */
static tree
fold_mult_zconjz (location_t loc, tree type, tree expr)
{
tree itype = TREE_TYPE (type);
tree rpart, ipart, tem;
if (TREE_CODE (expr) == COMPLEX_EXPR)
{
rpart = TREE_OPERAND (expr, 0);
ipart = TREE_OPERAND (expr, 1);
}
else if (TREE_CODE (expr) == COMPLEX_CST)
{
rpart = TREE_REALPART (expr);
ipart = TREE_IMAGPART (expr);
}
else
{
expr = save_expr (expr);
rpart = fold_build1_loc (loc, REALPART_EXPR, itype, expr);
ipart = fold_build1_loc (loc, IMAGPART_EXPR, itype, expr);
}
rpart = save_expr (rpart);
ipart = save_expr (ipart);
tem = fold_build2_loc (loc, PLUS_EXPR, itype,
fold_build2_loc (loc, MULT_EXPR, itype, rpart, rpart),
fold_build2_loc (loc, MULT_EXPR, itype, ipart, ipart));
return fold_build2_loc (loc, COMPLEX_EXPR, type, tem,
build_zero_cst (itype));
}
/* Subroutine of fold_binary. If P is the value of EXPR, computes
power-of-two M and (arbitrary) N such that M divides (P-N). This condition
guarantees that P and N have the same least significant log2(M) bits.
N is not otherwise constrained. In particular, N is not normalized to
0 <= N < M as is common. In general, the precise value of P is unknown.
M is chosen as large as possible such that constant N can be determined.
Returns M and sets *RESIDUE to N.
If ALLOW_FUNC_ALIGN is true, do take functions' DECL_ALIGN_UNIT into
account. This is not always possible due to PR 35705.
*/
static unsigned HOST_WIDE_INT
get_pointer_modulus_and_residue (tree expr, unsigned HOST_WIDE_INT *residue,
bool allow_func_align)
{
enum tree_code code;
*residue = 0;
code = TREE_CODE (expr);
if (code == ADDR_EXPR)
{
unsigned int bitalign;
get_object_alignment_1 (TREE_OPERAND (expr, 0), &bitalign, residue);
*residue /= BITS_PER_UNIT;
return bitalign / BITS_PER_UNIT;
}
else if (code == POINTER_PLUS_EXPR)
{
tree op0, op1;
unsigned HOST_WIDE_INT modulus;
enum tree_code inner_code;
op0 = TREE_OPERAND (expr, 0);
STRIP_NOPS (op0);
modulus = get_pointer_modulus_and_residue (op0, residue,
allow_func_align);
op1 = TREE_OPERAND (expr, 1);
STRIP_NOPS (op1);
inner_code = TREE_CODE (op1);
if (inner_code == INTEGER_CST)
{
*residue += TREE_INT_CST_LOW (op1);
return modulus;
}
else if (inner_code == MULT_EXPR)
{
op1 = TREE_OPERAND (op1, 1);
if (TREE_CODE (op1) == INTEGER_CST)
{
unsigned HOST_WIDE_INT align;
/* Compute the greatest power-of-2 divisor of op1. */
align = TREE_INT_CST_LOW (op1);
align &= -align;
/* If align is non-zero and less than *modulus, replace
*modulus with align., If align is 0, then either op1 is 0
or the greatest power-of-2 divisor of op1 doesn't fit in an
unsigned HOST_WIDE_INT. In either case, no additional
constraint is imposed. */
if (align)
modulus = MIN (modulus, align);
return modulus;
}
}
}
/* If we get here, we were unable to determine anything useful about the
expression. */
return 1;
}
/* Helper function for fold_vec_perm. Store elements of VECTOR_CST or
CONSTRUCTOR ARG into array ELTS and return true if successful. */
static bool
vec_cst_ctor_to_array (tree arg, tree *elts)
{
unsigned int nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg)), i;
if (TREE_CODE (arg) == VECTOR_CST)
{
for (i = 0; i < VECTOR_CST_NELTS (arg); ++i)
elts[i] = VECTOR_CST_ELT (arg, i);
}
else if (TREE_CODE (arg) == CONSTRUCTOR)
{
constructor_elt *elt;
FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (arg), i, elt)
if (i >= nelts || TREE_CODE (TREE_TYPE (elt->value)) == VECTOR_TYPE)
return false;
else
elts[i] = elt->value;
}
else
return false;
for (; i < nelts; i++)
elts[i]
= fold_convert (TREE_TYPE (TREE_TYPE (arg)), integer_zero_node);
return true;
}
/* Attempt to fold vector permutation of ARG0 and ARG1 vectors using SEL
selector. Return the folded VECTOR_CST or CONSTRUCTOR if successful,
NULL_TREE otherwise. */
static tree
fold_vec_perm (tree type, tree arg0, tree arg1, const unsigned char *sel)
{
unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i;
tree *elts;
bool need_ctor = false;
gcc_assert (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)) == nelts
&& TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg1)) == nelts);
if (TREE_TYPE (TREE_TYPE (arg0)) != TREE_TYPE (type)
|| TREE_TYPE (TREE_TYPE (arg1)) != TREE_TYPE (type))
return NULL_TREE;
elts = XALLOCAVEC (tree, nelts * 3);
if (!vec_cst_ctor_to_array (arg0, elts)
|| !vec_cst_ctor_to_array (arg1, elts + nelts))
return NULL_TREE;
for (i = 0; i < nelts; i++)
{
if (!CONSTANT_CLASS_P (elts[sel[i]]))
need_ctor = true;
elts[i + 2 * nelts] = unshare_expr (elts[sel[i]]);
}
if (need_ctor)
{
vec<constructor_elt, va_gc> *v;
vec_alloc (v, nelts);
for (i = 0; i < nelts; i++)
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, elts[2 * nelts + i]);
return build_constructor (type, v);
}
else
return build_vector (type, &elts[2 * nelts]);
}
/* Try to fold a pointer difference of type TYPE two address expressions of
array references AREF0 and AREF1 using location LOC. Return a
simplified expression for the difference or NULL_TREE. */
static tree
fold_addr_of_array_ref_difference (location_t loc, tree type,
tree aref0, tree aref1)
{
tree base0 = TREE_OPERAND (aref0, 0);
tree base1 = TREE_OPERAND (aref1, 0);
tree base_offset = build_int_cst (type, 0);
/* If the bases are array references as well, recurse. If the bases
are pointer indirections compute the difference of the pointers.
If the bases are equal, we are set. */
if ((TREE_CODE (base0) == ARRAY_REF
&& TREE_CODE (base1) == ARRAY_REF
&& (base_offset
= fold_addr_of_array_ref_difference (loc, type, base0, base1)))
|| (INDIRECT_REF_P (base0)
&& INDIRECT_REF_P (base1)
&& (base_offset = fold_binary_loc (loc, MINUS_EXPR, type,
TREE_OPERAND (base0, 0),
TREE_OPERAND (base1, 0))))
|| operand_equal_p (base0, base1, 0))
{
tree op0 = fold_convert_loc (loc, type, TREE_OPERAND (aref0, 1));
tree op1 = fold_convert_loc (loc, type, TREE_OPERAND (aref1, 1));
tree esz = fold_convert_loc (loc, type, array_ref_element_size (aref0));
tree diff = build2 (MINUS_EXPR, type, op0, op1);
return fold_build2_loc (loc, PLUS_EXPR, type,
base_offset,
fold_build2_loc (loc, MULT_EXPR, type,
diff, esz));
}
return NULL_TREE;
}
/* If the real or vector real constant CST of type TYPE has an exact
inverse, return it, else return NULL. */
static tree
exact_inverse (tree type, tree cst)
{
REAL_VALUE_TYPE r;
tree unit_type, *elts;
enum machine_mode mode;
unsigned vec_nelts, i;
switch (TREE_CODE (cst))
{
case REAL_CST:
r = TREE_REAL_CST (cst);
if (exact_real_inverse (TYPE_MODE (type), &r))
return build_real (type, r);
return NULL_TREE;
case VECTOR_CST:
vec_nelts = VECTOR_CST_NELTS (cst);
elts = XALLOCAVEC (tree, vec_nelts);
unit_type = TREE_TYPE (type);
mode = TYPE_MODE (unit_type);
for (i = 0; i < vec_nelts; i++)
{
r = TREE_REAL_CST (VECTOR_CST_ELT (cst, i));
if (!exact_real_inverse (mode, &r))
return NULL_TREE;
elts[i] = build_real (unit_type, r);
}
return build_vector (type, elts);
default:
return NULL_TREE;
}
}
/* Fold a binary expression of code CODE and type TYPE with operands
OP0 and OP1. LOC is the location of the resulting expression.
Return the folded expression if folding is successful. Otherwise,
return NULL_TREE. */
tree
fold_binary_loc (location_t loc,
enum tree_code code, tree type, tree op0, tree op1)
{
enum tree_code_class kind = TREE_CODE_CLASS (code);
tree arg0, arg1, tem;
tree t1 = NULL_TREE;
bool strict_overflow_p;
gcc_assert (IS_EXPR_CODE_CLASS (kind)
&& TREE_CODE_LENGTH (code) == 2
&& op0 != NULL_TREE
&& op1 != NULL_TREE);
arg0 = op0;
arg1 = op1;
/* Strip any conversions that don't change the mode. This is
safe for every expression, except for a comparison expression
because its signedness is derived from its operands. So, in
the latter case, only strip conversions that don't change the
signedness. MIN_EXPR/MAX_EXPR also need signedness of arguments
preserved.
Note that this is done as an internal manipulation within the
constant folder, in order to find the simplest representation
of the arguments so that their form can be studied. In any
cases, the appropriate type conversions should be put back in
the tree that will get out of the constant folder. */
if (kind == tcc_comparison || code == MIN_EXPR || code == MAX_EXPR)
{
STRIP_SIGN_NOPS (arg0);
STRIP_SIGN_NOPS (arg1);
}
else
{
STRIP_NOPS (arg0);
STRIP_NOPS (arg1);
}
/* Note that TREE_CONSTANT isn't enough: static var addresses are
constant but we can't do arithmetic on them. */
if ((TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
|| (TREE_CODE (arg0) == REAL_CST && TREE_CODE (arg1) == REAL_CST)
|| (TREE_CODE (arg0) == FIXED_CST && TREE_CODE (arg1) == FIXED_CST)
|| (TREE_CODE (arg0) == FIXED_CST && TREE_CODE (arg1) == INTEGER_CST)
|| (TREE_CODE (arg0) == COMPLEX_CST && TREE_CODE (arg1) == COMPLEX_CST)
|| (TREE_CODE (arg0) == VECTOR_CST && TREE_CODE (arg1) == VECTOR_CST))
{
if (kind == tcc_binary)
{
/* Make sure type and arg0 have the same saturating flag. */
gcc_assert (TYPE_SATURATING (type)
== TYPE_SATURATING (TREE_TYPE (arg0)));
tem = const_binop (code, arg0, arg1);
}
else if (kind == tcc_comparison)
tem = fold_relational_const (code, type, arg0, arg1);
else
tem = NULL_TREE;
if (tem != NULL_TREE)
{
if (TREE_TYPE (tem) != type)
tem = fold_convert_loc (loc, type, tem);
return tem;
}
}
/* If this is a commutative operation, and ARG0 is a constant, move it
to ARG1 to reduce the number of tests below. */
if (commutative_tree_code (code)
&& tree_swap_operands_p (arg0, arg1, true))
return fold_build2_loc (loc, code, type, op1, op0);
/* ARG0 is the first operand of EXPR, and ARG1 is the second operand.
First check for cases where an arithmetic operation is applied to a
compound, conditional, or comparison operation. Push the arithmetic
operation inside the compound or conditional to see if any folding
can then be done. Convert comparison to conditional for this purpose.
The also optimizes non-constant cases that used to be done in
expand_expr.
Before we do that, see if this is a BIT_AND_EXPR or a BIT_IOR_EXPR,
one of the operands is a comparison and the other is a comparison, a
BIT_AND_EXPR with the constant 1, or a truth value. In that case, the
code below would make the expression more complex. Change it to a
TRUTH_{AND,OR}_EXPR. Likewise, convert a similar NE_EXPR to
TRUTH_XOR_EXPR and an EQ_EXPR to the inversion of a TRUTH_XOR_EXPR. */
if ((code == BIT_AND_EXPR || code == BIT_IOR_EXPR
|| code == EQ_EXPR || code == NE_EXPR)
&& TREE_CODE (type) != VECTOR_TYPE
&& ((truth_value_p (TREE_CODE (arg0))
&& (truth_value_p (TREE_CODE (arg1))
|| (TREE_CODE (arg1) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg1, 1)))))
|| (truth_value_p (TREE_CODE (arg1))
&& (truth_value_p (TREE_CODE (arg0))
|| (TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1)))))))
{
tem = fold_build2_loc (loc, code == BIT_AND_EXPR ? TRUTH_AND_EXPR
: code == BIT_IOR_EXPR ? TRUTH_OR_EXPR
: TRUTH_XOR_EXPR,
boolean_type_node,
fold_convert_loc (loc, boolean_type_node, arg0),
fold_convert_loc (loc, boolean_type_node, arg1));
if (code == EQ_EXPR)
tem = invert_truthvalue_loc (loc, tem);
return fold_convert_loc (loc, type, tem);
}
if (TREE_CODE_CLASS (code) == tcc_binary
|| TREE_CODE_CLASS (code) == tcc_comparison)
{
if (TREE_CODE (arg0) == COMPOUND_EXPR)
{
tem = fold_build2_loc (loc, code, type,
fold_convert_loc (loc, TREE_TYPE (op0),
TREE_OPERAND (arg0, 1)), op1);
return build2_loc (loc, COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
tem);
}
if (TREE_CODE (arg1) == COMPOUND_EXPR
&& reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
{
tem = fold_build2_loc (loc, code, type, op0,
fold_convert_loc (loc, TREE_TYPE (op1),
TREE_OPERAND (arg1, 1)));
return build2_loc (loc, COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
tem);
}
if (TREE_CODE (arg0) == COND_EXPR
|| TREE_CODE (arg0) == VEC_COND_EXPR
|| COMPARISON_CLASS_P (arg0))
{
tem = fold_binary_op_with_conditional_arg (loc, code, type, op0, op1,
arg0, arg1,
/*cond_first_p=*/1);
if (tem != NULL_TREE)
return tem;
}
if (TREE_CODE (arg1) == COND_EXPR
|| TREE_CODE (arg1) == VEC_COND_EXPR
|| COMPARISON_CLASS_P (arg1))
{
tem = fold_binary_op_with_conditional_arg (loc, code, type, op0, op1,
arg1, arg0,
/*cond_first_p=*/0);
if (tem != NULL_TREE)
return tem;
}
}
switch (code)
{
case MEM_REF:
/* MEM[&MEM[p, CST1], CST2] -> MEM[p, CST1 + CST2]. */
if (TREE_CODE (arg0) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == MEM_REF)
{
tree iref = TREE_OPERAND (arg0, 0);
return fold_build2 (MEM_REF, type,
TREE_OPERAND (iref, 0),
int_const_binop (PLUS_EXPR, arg1,
TREE_OPERAND (iref, 1)));
}
/* MEM[&a.b, CST2] -> MEM[&a, offsetof (a, b) + CST2]. */
if (TREE_CODE (arg0) == ADDR_EXPR
&& handled_component_p (TREE_OPERAND (arg0, 0)))
{
tree base;
HOST_WIDE_INT coffset;
base = get_addr_base_and_unit_offset (TREE_OPERAND (arg0, 0),
&coffset);
if (!base)
return NULL_TREE;
return fold_build2 (MEM_REF, type,
build_fold_addr_expr (base),
int_const_binop (PLUS_EXPR, arg1,
size_int (coffset)));
}
return NULL_TREE;
case POINTER_PLUS_EXPR:
/* 0 +p index -> (type)index */
if (integer_zerop (arg0))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1));
/* PTR +p 0 -> PTR */
if (integer_zerop (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* INT +p INT -> (PTR)(INT + INT). Stripping types allows for this. */
if (INTEGRAL_TYPE_P (TREE_TYPE (arg1))
&& INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
return fold_convert_loc (loc, type,
fold_build2_loc (loc, PLUS_EXPR, sizetype,
fold_convert_loc (loc, sizetype,
arg1),
fold_convert_loc (loc, sizetype,
arg0)));
/* (PTR +p B) +p A -> PTR +p (B + A) */
if (TREE_CODE (arg0) == POINTER_PLUS_EXPR)
{
tree inner;
tree arg01 = fold_convert_loc (loc, sizetype, TREE_OPERAND (arg0, 1));
tree arg00 = TREE_OPERAND (arg0, 0);
inner = fold_build2_loc (loc, PLUS_EXPR, sizetype,
arg01, fold_convert_loc (loc, sizetype, arg1));
return fold_convert_loc (loc, type,
fold_build_pointer_plus_loc (loc,
arg00, inner));
}
/* PTR_CST +p CST -> CST1 */
if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST)
return fold_build2_loc (loc, PLUS_EXPR, type, arg0,
fold_convert_loc (loc, type, arg1));
/* Try replacing &a[i1] +p c * i2 with &a[i1 + i2], if c is step
of the array. Loop optimizer sometimes produce this type of
expressions. */
if (TREE_CODE (arg0) == ADDR_EXPR)
{
tem = try_move_mult_to_index (loc, arg0,
fold_convert_loc (loc,
ssizetype, arg1));
if (tem)
return fold_convert_loc (loc, type, tem);
}
return NULL_TREE;
case PLUS_EXPR:
/* A + (-B) -> A - B */
if (TREE_CODE (arg1) == NEGATE_EXPR)
return fold_build2_loc (loc, MINUS_EXPR, type,
fold_convert_loc (loc, type, arg0),
fold_convert_loc (loc, type,
TREE_OPERAND (arg1, 0)));
/* (-A) + B -> B - A */
if (TREE_CODE (arg0) == NEGATE_EXPR
&& reorder_operands_p (TREE_OPERAND (arg0, 0), arg1))
return fold_build2_loc (loc, MINUS_EXPR, type,
fold_convert_loc (loc, type, arg1),
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)));
if (INTEGRAL_TYPE_P (type))
{
/* Convert ~A + 1 to -A. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& integer_onep (arg1))
return fold_build1_loc (loc, NEGATE_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)));
/* ~X + X is -1. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& !TYPE_OVERFLOW_TRAPS (type))
{
tree tem = TREE_OPERAND (arg0, 0);
STRIP_NOPS (tem);
if (operand_equal_p (tem, arg1, 0))
{
t1 = build_int_cst_type (type, -1);
return omit_one_operand_loc (loc, type, t1, arg1);
}
}
/* X + ~X is -1. */
if (TREE_CODE (arg1) == BIT_NOT_EXPR
&& !TYPE_OVERFLOW_TRAPS (type))
{
tree tem = TREE_OPERAND (arg1, 0);
STRIP_NOPS (tem);
if (operand_equal_p (arg0, tem, 0))
{
t1 = build_int_cst_type (type, -1);
return omit_one_operand_loc (loc, type, t1, arg0);
}
}
/* X + (X / CST) * -CST is X % CST. */
if (TREE_CODE (arg1) == MULT_EXPR
&& TREE_CODE (TREE_OPERAND (arg1, 0)) == TRUNC_DIV_EXPR
&& operand_equal_p (arg0,
TREE_OPERAND (TREE_OPERAND (arg1, 0), 0), 0))
{
tree cst0 = TREE_OPERAND (TREE_OPERAND (arg1, 0), 1);
tree cst1 = TREE_OPERAND (arg1, 1);
tree sum = fold_binary_loc (loc, PLUS_EXPR, TREE_TYPE (cst1),
cst1, cst0);
if (sum && integer_zerop (sum))
return fold_convert_loc (loc, type,
fold_build2_loc (loc, TRUNC_MOD_EXPR,
TREE_TYPE (arg0), arg0,
cst0));
}
}
/* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the same or
one. Make sure the type is not saturating and has the signedness of
the stripped operands, as fold_plusminus_mult_expr will re-associate.
??? The latter condition should use TYPE_OVERFLOW_* flags instead. */
if ((TREE_CODE (arg0) == MULT_EXPR
|| TREE_CODE (arg1) == MULT_EXPR)
&& !TYPE_SATURATING (type)
&& TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg0))
&& TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg1))
&& (!FLOAT_TYPE_P (type) || flag_associative_math))
{
tree tem = fold_plusminus_mult_expr (loc, code, type, arg0, arg1);
if (tem)
return tem;
}
if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* If we are adding two BIT_AND_EXPR's, both of which are and'ing
with a constant, and the two constants have no bits in common,
we should treat this as a BIT_IOR_EXPR since this may produce more
simplifications. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == BIT_AND_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
&& integer_zerop (const_binop (BIT_AND_EXPR,
TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 1))))
{
code = BIT_IOR_EXPR;
goto bit_ior;
}
/* Reassociate (plus (plus (mult) (foo)) (mult)) as
(plus (plus (mult) (mult)) (foo)) so that we can
take advantage of the factoring cases below. */
if (TYPE_OVERFLOW_WRAPS (type)
&& (((TREE_CODE (arg0) == PLUS_EXPR
|| TREE_CODE (arg0) == MINUS_EXPR)
&& TREE_CODE (arg1) == MULT_EXPR)
|| ((TREE_CODE (arg1) == PLUS_EXPR
|| TREE_CODE (arg1) == MINUS_EXPR)
&& TREE_CODE (arg0) == MULT_EXPR)))
{
tree parg0, parg1, parg, marg;
enum tree_code pcode;
if (TREE_CODE (arg1) == MULT_EXPR)
parg = arg0, marg = arg1;
else
parg = arg1, marg = arg0;
pcode = TREE_CODE (parg);
parg0 = TREE_OPERAND (parg, 0);
parg1 = TREE_OPERAND (parg, 1);
STRIP_NOPS (parg0);
STRIP_NOPS (parg1);
if (TREE_CODE (parg0) == MULT_EXPR
&& TREE_CODE (parg1) != MULT_EXPR)
return fold_build2_loc (loc, pcode, type,
fold_build2_loc (loc, PLUS_EXPR, type,
fold_convert_loc (loc, type,
parg0),
fold_convert_loc (loc, type,
marg)),
fold_convert_loc (loc, type, parg1));
if (TREE_CODE (parg0) != MULT_EXPR
&& TREE_CODE (parg1) == MULT_EXPR)
return
fold_build2_loc (loc, PLUS_EXPR, type,
fold_convert_loc (loc, type, parg0),
fold_build2_loc (loc, pcode, type,
fold_convert_loc (loc, type, marg),
fold_convert_loc (loc, type,
parg1)));
}
}
else
{
/* See if ARG1 is zero and X + ARG1 reduces to X. */
if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 0))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* Likewise if the operands are reversed. */
if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1));
/* Convert X + -C into X - C. */
if (TREE_CODE (arg1) == REAL_CST
&& REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1)))
{
tem = fold_negate_const (arg1, type);
if (!TREE_OVERFLOW (arg1) || !flag_trapping_math)
return fold_build2_loc (loc, MINUS_EXPR, type,
fold_convert_loc (loc, type, arg0),
fold_convert_loc (loc, type, tem));
}
/* Fold __complex__ ( x, 0 ) + __complex__ ( 0, y )
to __complex__ ( x, y ). This is not the same for SNaNs or
if signed zeros are involved. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))
&& COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0)))
{
tree rtype = TREE_TYPE (TREE_TYPE (arg0));
tree arg0r = fold_unary_loc (loc, REALPART_EXPR, rtype, arg0);
tree arg0i = fold_unary_loc (loc, IMAGPART_EXPR, rtype, arg0);
bool arg0rz = false, arg0iz = false;
if ((arg0r && (arg0rz = real_zerop (arg0r)))
|| (arg0i && (arg0iz = real_zerop (arg0i))))
{
tree arg1r = fold_unary_loc (loc, REALPART_EXPR, rtype, arg1);
tree arg1i = fold_unary_loc (loc, IMAGPART_EXPR, rtype, arg1);
if (arg0rz && arg1i && real_zerop (arg1i))
{
tree rp = arg1r ? arg1r
: build1 (REALPART_EXPR, rtype, arg1);
tree ip = arg0i ? arg0i
: build1 (IMAGPART_EXPR, rtype, arg0);
return fold_build2_loc (loc, COMPLEX_EXPR, type, rp, ip);
}
else if (arg0iz && arg1r && real_zerop (arg1r))
{
tree rp = arg0r ? arg0r
: build1 (REALPART_EXPR, rtype, arg0);
tree ip = arg1i ? arg1i
: build1 (IMAGPART_EXPR, rtype, arg1);
return fold_build2_loc (loc, COMPLEX_EXPR, type, rp, ip);
}
}
}
if (flag_unsafe_math_optimizations
&& (TREE_CODE (arg0) == RDIV_EXPR || TREE_CODE (arg0) == MULT_EXPR)
&& (TREE_CODE (arg1) == RDIV_EXPR || TREE_CODE (arg1) == MULT_EXPR)
&& (tem = distribute_real_division (loc, code, type, arg0, arg1)))
return tem;
/* Convert x+x into x*2.0. */
if (operand_equal_p (arg0, arg1, 0)
&& SCALAR_FLOAT_TYPE_P (type))
return fold_build2_loc (loc, MULT_EXPR, type, arg0,
build_real (type, dconst2));
/* Convert a + (b*c + d*e) into (a + b*c) + d*e.
We associate floats only if the user has specified
-fassociative-math. */
if (flag_associative_math
&& TREE_CODE (arg1) == PLUS_EXPR
&& TREE_CODE (arg0) != MULT_EXPR)
{
tree tree10 = TREE_OPERAND (arg1, 0);
tree tree11 = TREE_OPERAND (arg1, 1);
if (TREE_CODE (tree11) == MULT_EXPR
&& TREE_CODE (tree10) == MULT_EXPR)
{
tree tree0;
tree0 = fold_build2_loc (loc, PLUS_EXPR, type, arg0, tree10);
return fold_build2_loc (loc, PLUS_EXPR, type, tree0, tree11);
}
}
/* Convert (b*c + d*e) + a into b*c + (d*e +a).
We associate floats only if the user has specified
-fassociative-math. */
if (flag_associative_math
&& TREE_CODE (arg0) == PLUS_EXPR
&& TREE_CODE (arg1) != MULT_EXPR)
{
tree tree00 = TREE_OPERAND (arg0, 0);
tree tree01 = TREE_OPERAND (arg0, 1);
if (TREE_CODE (tree01) == MULT_EXPR
&& TREE_CODE (tree00) == MULT_EXPR)
{
tree tree0;
tree0 = fold_build2_loc (loc, PLUS_EXPR, type, tree01, arg1);
return fold_build2_loc (loc, PLUS_EXPR, type, tree00, tree0);
}
}
}
bit_rotate:
/* (A << C1) + (A >> C2) if A is unsigned and C1+C2 is the size of A
is a rotate of A by C1 bits. */
/* (A << B) + (A >> (Z - B)) if A is unsigned and Z is the size of A
is a rotate of A by B bits. */
{
enum tree_code code0, code1;
tree rtype;
code0 = TREE_CODE (arg0);
code1 = TREE_CODE (arg1);
if (((code0 == RSHIFT_EXPR && code1 == LSHIFT_EXPR)
|| (code1 == RSHIFT_EXPR && code0 == LSHIFT_EXPR))
&& operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0), 0)
&& (rtype = TREE_TYPE (TREE_OPERAND (arg0, 0)),
TYPE_UNSIGNED (rtype))
/* Only create rotates in complete modes. Other cases are not
expanded properly. */
&& TYPE_PRECISION (rtype) == GET_MODE_PRECISION (TYPE_MODE (rtype)))
{
tree tree01, tree11;
enum tree_code code01, code11;
tree01 = TREE_OPERAND (arg0, 1);
tree11 = TREE_OPERAND (arg1, 1);
STRIP_NOPS (tree01);
STRIP_NOPS (tree11);
code01 = TREE_CODE (tree01);
code11 = TREE_CODE (tree11);
if (code01 == INTEGER_CST
&& code11 == INTEGER_CST
&& TREE_INT_CST_HIGH (tree01) == 0
&& TREE_INT_CST_HIGH (tree11) == 0
&& ((TREE_INT_CST_LOW (tree01) + TREE_INT_CST_LOW (tree11))
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))))
{
tem = build2_loc (loc, LROTATE_EXPR,
TREE_TYPE (TREE_OPERAND (arg0, 0)),
TREE_OPERAND (arg0, 0),
code0 == LSHIFT_EXPR ? tree01 : tree11);
return fold_convert_loc (loc, type, tem);
}
else if (code11 == MINUS_EXPR)
{
tree tree110, tree111;
tree110 = TREE_OPERAND (tree11, 0);
tree111 = TREE_OPERAND (tree11, 1);
STRIP_NOPS (tree110);
STRIP_NOPS (tree111);
if (TREE_CODE (tree110) == INTEGER_CST
&& 0 == compare_tree_int (tree110,
TYPE_PRECISION
(TREE_TYPE (TREE_OPERAND
(arg0, 0))))
&& operand_equal_p (tree01, tree111, 0))
return
fold_convert_loc (loc, type,
build2 ((code0 == LSHIFT_EXPR
? LROTATE_EXPR
: RROTATE_EXPR),
TREE_TYPE (TREE_OPERAND (arg0, 0)),
TREE_OPERAND (arg0, 0), tree01));
}
else if (code01 == MINUS_EXPR)
{
tree tree010, tree011;
tree010 = TREE_OPERAND (tree01, 0);
tree011 = TREE_OPERAND (tree01, 1);
STRIP_NOPS (tree010);
STRIP_NOPS (tree011);
if (TREE_CODE (tree010) == INTEGER_CST
&& 0 == compare_tree_int (tree010,
TYPE_PRECISION
(TREE_TYPE (TREE_OPERAND
(arg0, 0))))
&& operand_equal_p (tree11, tree011, 0))
return fold_convert_loc
(loc, type,
build2 ((code0 != LSHIFT_EXPR
? LROTATE_EXPR
: RROTATE_EXPR),
TREE_TYPE (TREE_OPERAND (arg0, 0)),
TREE_OPERAND (arg0, 0), tree11));
}
}
}
associate:
/* In most languages, can't associate operations on floats through
parentheses. Rather than remember where the parentheses were, we
don't associate floats at all, unless the user has specified
-fassociative-math.
And, we need to make sure type is not saturating. */
if ((! FLOAT_TYPE_P (type) || flag_associative_math)
&& !TYPE_SATURATING (type))
{
tree var0, con0, lit0, minus_lit0;
tree var1, con1, lit1, minus_lit1;
tree atype = type;
bool ok = true;
/* Split both trees into variables, constants, and literals. Then
associate each group together, the constants with literals,
then the result with variables. This increases the chances of
literals being recombined later and of generating relocatable
expressions for the sum of a constant and literal. */
var0 = split_tree (arg0, code, &con0, &lit0, &minus_lit0, 0);
var1 = split_tree (arg1, code, &con1, &lit1, &minus_lit1,
code == MINUS_EXPR);
/* Recombine MINUS_EXPR operands by using PLUS_EXPR. */
if (code == MINUS_EXPR)
code = PLUS_EXPR;
/* With undefined overflow prefer doing association in a type
which wraps on overflow, if that is one of the operand types. */
if ((POINTER_TYPE_P (type) && POINTER_TYPE_OVERFLOW_UNDEFINED)
|| (INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_WRAPS (type)))
{
if (INTEGRAL_TYPE_P (TREE_TYPE (arg0))
&& TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0)))
atype = TREE_TYPE (arg0);
else if (INTEGRAL_TYPE_P (TREE_TYPE (arg1))
&& TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1)))
atype = TREE_TYPE (arg1);
gcc_assert (TYPE_PRECISION (atype) == TYPE_PRECISION (type));
}
/* With undefined overflow we can only associate constants with one
variable, and constants whose association doesn't overflow. */
if ((POINTER_TYPE_P (atype) && POINTER_TYPE_OVERFLOW_UNDEFINED)
|| (INTEGRAL_TYPE_P (atype) && !TYPE_OVERFLOW_WRAPS (atype)))
{
if (var0 && var1)
{
tree tmp0 = var0;
tree tmp1 = var1;
if (TREE_CODE (tmp0) == NEGATE_EXPR)
tmp0 = TREE_OPERAND (tmp0, 0);
if (CONVERT_EXPR_P (tmp0)
&& INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (tmp0, 0)))
&& (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (tmp0, 0)))
<= TYPE_PRECISION (atype)))
tmp0 = TREE_OPERAND (tmp0, 0);
if (TREE_CODE (tmp1) == NEGATE_EXPR)
tmp1 = TREE_OPERAND (tmp1, 0);
if (CONVERT_EXPR_P (tmp1)
&& INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (tmp1, 0)))
&& (TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (tmp1, 0)))
<= TYPE_PRECISION (atype)))
tmp1 = TREE_OPERAND (tmp1, 0);
/* The only case we can still associate with two variables
is if they are the same, modulo negation and bit-pattern
preserving conversions. */
if (!operand_equal_p (tmp0, tmp1, 0))
ok = false;
}
}
/* Only do something if we found more than two objects. Otherwise,
nothing has changed and we risk infinite recursion. */
if (ok
&& (2 < ((var0 != 0) + (var1 != 0)
+ (con0 != 0) + (con1 != 0)
+ (lit0 != 0) + (lit1 != 0)
+ (minus_lit0 != 0) + (minus_lit1 != 0))))
{
bool any_overflows = false;
if (lit0) any_overflows |= TREE_OVERFLOW (lit0);
if (lit1) any_overflows |= TREE_OVERFLOW (lit1);
if (minus_lit0) any_overflows |= TREE_OVERFLOW (minus_lit0);
if (minus_lit1) any_overflows |= TREE_OVERFLOW (minus_lit1);
var0 = associate_trees (loc, var0, var1, code, atype);
con0 = associate_trees (loc, con0, con1, code, atype);
lit0 = associate_trees (loc, lit0, lit1, code, atype);
minus_lit0 = associate_trees (loc, minus_lit0, minus_lit1,
code, atype);
/* Preserve the MINUS_EXPR if the negative part of the literal is
greater than the positive part. Otherwise, the multiplicative
folding code (i.e extract_muldiv) may be fooled in case
unsigned constants are subtracted, like in the following
example: ((X*2 + 4) - 8U)/2. */
if (minus_lit0 && lit0)
{
if (TREE_CODE (lit0) == INTEGER_CST
&& TREE_CODE (minus_lit0) == INTEGER_CST
&& tree_int_cst_lt (lit0, minus_lit0))
{
minus_lit0 = associate_trees (loc, minus_lit0, lit0,
MINUS_EXPR, atype);
lit0 = 0;
}
else
{
lit0 = associate_trees (loc, lit0, minus_lit0,
MINUS_EXPR, atype);
minus_lit0 = 0;
}
}
/* Don't introduce overflows through reassociation. */
if (!any_overflows
&& ((lit0 && TREE_OVERFLOW (lit0))
|| (minus_lit0 && TREE_OVERFLOW (minus_lit0))))
return NULL_TREE;
if (minus_lit0)
{
if (con0 == 0)
return
fold_convert_loc (loc, type,
associate_trees (loc, var0, minus_lit0,
MINUS_EXPR, atype));
else
{
con0 = associate_trees (loc, con0, minus_lit0,
MINUS_EXPR, atype);
return
fold_convert_loc (loc, type,
associate_trees (loc, var0, con0,
PLUS_EXPR, atype));
}
}
con0 = associate_trees (loc, con0, lit0, code, atype);
return
fold_convert_loc (loc, type, associate_trees (loc, var0, con0,
code, atype));
}
}
return NULL_TREE;
case MINUS_EXPR:
/* Pointer simplifications for subtraction, simple reassociations. */
if (POINTER_TYPE_P (TREE_TYPE (arg1)) && POINTER_TYPE_P (TREE_TYPE (arg0)))
{
/* (PTR0 p+ A) - (PTR1 p+ B) -> (PTR0 - PTR1) + (A - B) */
if (TREE_CODE (arg0) == POINTER_PLUS_EXPR
&& TREE_CODE (arg1) == POINTER_PLUS_EXPR)
{
tree arg00 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
tree arg01 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
tree arg10 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
tree arg11 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
return fold_build2_loc (loc, PLUS_EXPR, type,
fold_build2_loc (loc, MINUS_EXPR, type,
arg00, arg10),
fold_build2_loc (loc, MINUS_EXPR, type,
arg01, arg11));
}
/* (PTR0 p+ A) - PTR1 -> (PTR0 - PTR1) + A, assuming PTR0 - PTR1 simplifies. */
else if (TREE_CODE (arg0) == POINTER_PLUS_EXPR)
{
tree arg00 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
tree arg01 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
tree tmp = fold_binary_loc (loc, MINUS_EXPR, type, arg00,
fold_convert_loc (loc, type, arg1));
if (tmp)
return fold_build2_loc (loc, PLUS_EXPR, type, tmp, arg01);
}
}
/* A - (-B) -> A + B */
if (TREE_CODE (arg1) == NEGATE_EXPR)
return fold_build2_loc (loc, PLUS_EXPR, type, op0,
fold_convert_loc (loc, type,
TREE_OPERAND (arg1, 0)));
/* (-A) - B -> (-B) - A where B is easily negated and we can swap. */
if (TREE_CODE (arg0) == NEGATE_EXPR
&& (FLOAT_TYPE_P (type)
|| INTEGRAL_TYPE_P (type))
&& negate_expr_p (arg1)
&& reorder_operands_p (arg0, arg1))
return fold_build2_loc (loc, MINUS_EXPR, type,
fold_convert_loc (loc, type,
negate_expr (arg1)),
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)));
/* Convert -A - 1 to ~A. */
if (INTEGRAL_TYPE_P (type)
&& TREE_CODE (arg0) == NEGATE_EXPR
&& integer_onep (arg1)
&& !TYPE_OVERFLOW_TRAPS (type))
return fold_build1_loc (loc, BIT_NOT_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)));
/* Convert -1 - A to ~A. */
if (INTEGRAL_TYPE_P (type)
&& integer_all_onesp (arg0))
return fold_build1_loc (loc, BIT_NOT_EXPR, type, op1);
/* X - (X / CST) * CST is X % CST. */
if (INTEGRAL_TYPE_P (type)
&& TREE_CODE (arg1) == MULT_EXPR
&& TREE_CODE (TREE_OPERAND (arg1, 0)) == TRUNC_DIV_EXPR
&& operand_equal_p (arg0,
TREE_OPERAND (TREE_OPERAND (arg1, 0), 0), 0)
&& operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg1, 0), 1),
TREE_OPERAND (arg1, 1), 0))
return
fold_convert_loc (loc, type,
fold_build2_loc (loc, TRUNC_MOD_EXPR, TREE_TYPE (arg0),
arg0, TREE_OPERAND (arg1, 1)));
if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg0))
return negate_expr (fold_convert_loc (loc, type, arg1));
if (integer_zerop (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* Fold A - (A & B) into ~B & A. */
if (!TREE_SIDE_EFFECTS (arg0)
&& TREE_CODE (arg1) == BIT_AND_EXPR)
{
if (operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0))
{
tree arg10 = fold_convert_loc (loc, type,
TREE_OPERAND (arg1, 0));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_build1_loc (loc, BIT_NOT_EXPR,
type, arg10),
fold_convert_loc (loc, type, arg0));
}
if (operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
tree arg11 = fold_convert_loc (loc,
type, TREE_OPERAND (arg1, 1));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_build1_loc (loc, BIT_NOT_EXPR,
type, arg11),
fold_convert_loc (loc, type, arg0));
}
}
/* Fold (A & ~B) - (A & B) into (A ^ B) - B, where B is
any power of 2 minus 1. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == BIT_AND_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0), 0))
{
tree mask0 = TREE_OPERAND (arg0, 1);
tree mask1 = TREE_OPERAND (arg1, 1);
tree tem = fold_build1_loc (loc, BIT_NOT_EXPR, type, mask0);
if (operand_equal_p (tem, mask1, 0))
{
tem = fold_build2_loc (loc, BIT_XOR_EXPR, type,
TREE_OPERAND (arg0, 0), mask1);
return fold_build2_loc (loc, MINUS_EXPR, type, tem, mask1);
}
}
}
/* See if ARG1 is zero and X - ARG1 reduces to X. */
else if (fold_real_zero_addition_p (TREE_TYPE (arg0), arg1, 1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* (ARG0 - ARG1) is the same as (-ARG1 + ARG0). So check whether
ARG0 is zero and X + ARG0 reduces to X, since that would mean
(-ARG1 + ARG0) reduces to -ARG1. */
else if (fold_real_zero_addition_p (TREE_TYPE (arg1), arg0, 0))
return negate_expr (fold_convert_loc (loc, type, arg1));
/* Fold __complex__ ( x, 0 ) - __complex__ ( 0, y ) to
__complex__ ( x, -y ). This is not the same for SNaNs or if
signed zeros are involved. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))
&& COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0)))
{
tree rtype = TREE_TYPE (TREE_TYPE (arg0));
tree arg0r = fold_unary_loc (loc, REALPART_EXPR, rtype, arg0);
tree arg0i = fold_unary_loc (loc, IMAGPART_EXPR, rtype, arg0);
bool arg0rz = false, arg0iz = false;
if ((arg0r && (arg0rz = real_zerop (arg0r)))
|| (arg0i && (arg0iz = real_zerop (arg0i))))
{
tree arg1r = fold_unary_loc (loc, REALPART_EXPR, rtype, arg1);
tree arg1i = fold_unary_loc (loc, IMAGPART_EXPR, rtype, arg1);
if (arg0rz && arg1i && real_zerop (arg1i))
{
tree rp = fold_build1_loc (loc, NEGATE_EXPR, rtype,
arg1r ? arg1r
: build1 (REALPART_EXPR, rtype, arg1));
tree ip = arg0i ? arg0i
: build1 (IMAGPART_EXPR, rtype, arg0);
return fold_build2_loc (loc, COMPLEX_EXPR, type, rp, ip);
}
else if (arg0iz && arg1r && real_zerop (arg1r))
{
tree rp = arg0r ? arg0r
: build1 (REALPART_EXPR, rtype, arg0);
tree ip = fold_build1_loc (loc, NEGATE_EXPR, rtype,
arg1i ? arg1i
: build1 (IMAGPART_EXPR, rtype, arg1));
return fold_build2_loc (loc, COMPLEX_EXPR, type, rp, ip);
}
}
}
/* Fold &x - &x. This can happen from &x.foo - &x.
This is unsafe for certain floats even in non-IEEE formats.
In IEEE, it is unsafe because it does wrong for NaNs.
Also note that operand_equal_p is always false if an operand
is volatile. */
if ((!FLOAT_TYPE_P (type) || !HONOR_NANS (TYPE_MODE (type)))
&& operand_equal_p (arg0, arg1, 0))
return build_zero_cst (type);
/* A - B -> A + (-B) if B is easily negatable. */
if (negate_expr_p (arg1)
&& ((FLOAT_TYPE_P (type)
/* Avoid this transformation if B is a positive REAL_CST. */
&& (TREE_CODE (arg1) != REAL_CST
|| REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg1))))
|| INTEGRAL_TYPE_P (type)))
return fold_build2_loc (loc, PLUS_EXPR, type,
fold_convert_loc (loc, type, arg0),
fold_convert_loc (loc, type,
negate_expr (arg1)));
/* Try folding difference of addresses. */
{
HOST_WIDE_INT diff;
if ((TREE_CODE (arg0) == ADDR_EXPR
|| TREE_CODE (arg1) == ADDR_EXPR)
&& ptr_difference_const (arg0, arg1, &diff))
return build_int_cst_type (type, diff);
}
/* Fold &a[i] - &a[j] to i-j. */
if (TREE_CODE (arg0) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == ARRAY_REF
&& TREE_CODE (arg1) == ADDR_EXPR
&& TREE_CODE (TREE_OPERAND (arg1, 0)) == ARRAY_REF)
{
tree tem = fold_addr_of_array_ref_difference (loc, type,
TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0));
if (tem)
return tem;
}
if (FLOAT_TYPE_P (type)
&& flag_unsafe_math_optimizations
&& (TREE_CODE (arg0) == RDIV_EXPR || TREE_CODE (arg0) == MULT_EXPR)
&& (TREE_CODE (arg1) == RDIV_EXPR || TREE_CODE (arg1) == MULT_EXPR)
&& (tem = distribute_real_division (loc, code, type, arg0, arg1)))
return tem;
/* Handle (A1 * C1) - (A2 * C2) with A1, A2 or C1, C2 being the same or
one. Make sure the type is not saturating and has the signedness of
the stripped operands, as fold_plusminus_mult_expr will re-associate.
??? The latter condition should use TYPE_OVERFLOW_* flags instead. */
if ((TREE_CODE (arg0) == MULT_EXPR
|| TREE_CODE (arg1) == MULT_EXPR)
&& !TYPE_SATURATING (type)
&& TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg0))
&& TYPE_UNSIGNED (type) == TYPE_UNSIGNED (TREE_TYPE (arg1))
&& (!FLOAT_TYPE_P (type) || flag_associative_math))
{
tree tem = fold_plusminus_mult_expr (loc, code, type, arg0, arg1);
if (tem)
return tem;
}
goto associate;
case MULT_EXPR:
/* (-A) * (-B) -> A * B */
if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
return fold_build2_loc (loc, MULT_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)),
fold_convert_loc (loc, type,
negate_expr (arg1)));
if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0))
return fold_build2_loc (loc, MULT_EXPR, type,
fold_convert_loc (loc, type,
negate_expr (arg0)),
fold_convert_loc (loc, type,
TREE_OPERAND (arg1, 0)));
if (! FLOAT_TYPE_P (type))
{
if (integer_zerop (arg1))
return omit_one_operand_loc (loc, type, arg1, arg0);
if (integer_onep (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* Transform x * -1 into -x. Make sure to do the negation
on the original operand with conversions not stripped
because we can only strip non-sign-changing conversions. */
if (integer_all_onesp (arg1))
return fold_convert_loc (loc, type, negate_expr (op0));
/* Transform x * -C into -x * C if x is easily negatable. */
if (TREE_CODE (arg1) == INTEGER_CST
&& tree_int_cst_sgn (arg1) == -1
&& negate_expr_p (arg0)
&& (tem = negate_expr (arg1)) != arg1
&& !TREE_OVERFLOW (tem))
return fold_build2_loc (loc, MULT_EXPR, type,
fold_convert_loc (loc, type,
negate_expr (arg0)),
tem);
/* (a * (1 << b)) is (a << b) */
if (TREE_CODE (arg1) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg1, 0)))
return fold_build2_loc (loc, LSHIFT_EXPR, type, op0,
TREE_OPERAND (arg1, 1));
if (TREE_CODE (arg0) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg0, 0)))
return fold_build2_loc (loc, LSHIFT_EXPR, type, op1,
TREE_OPERAND (arg0, 1));
/* (A + A) * C -> A * 2 * C */
if (TREE_CODE (arg0) == PLUS_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg0, 1), 0))
return fold_build2_loc (loc, MULT_EXPR, type,
omit_one_operand_loc (loc, type,
TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg0, 1)),
fold_build2_loc (loc, MULT_EXPR, type,
build_int_cst (type, 2) , arg1));
strict_overflow_p = false;
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE,
&strict_overflow_p)))
{
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not "
"occur when simplifying "
"multiplication"),
WARN_STRICT_OVERFLOW_MISC);
return fold_convert_loc (loc, type, tem);
}
/* Optimize z * conj(z) for integer complex numbers. */
if (TREE_CODE (arg0) == CONJ_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
return fold_mult_zconjz (loc, type, arg1);
if (TREE_CODE (arg1) == CONJ_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
return fold_mult_zconjz (loc, type, arg0);
}
else
{
/* Maybe fold x * 0 to 0. The expressions aren't the same
when x is NaN, since x * 0 is also NaN. Nor are they the
same in modes with signed zeros, since multiplying a
negative value by 0 gives -0, not +0. */
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_zerop (arg1))
return omit_one_operand_loc (loc, type, arg1, arg0);
/* In IEEE floating point, x*1 is not equivalent to x for snans.
Likewise for complex arithmetic with signed zeros. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))
|| !COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0)))
&& real_onep (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* Transform x * -1.0 into -x. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))
|| !COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0)))
&& real_minus_onep (arg1))
return fold_convert_loc (loc, type, negate_expr (arg0));
/* Convert (C1/X)*C2 into (C1*C2)/X. This transformation may change
the result for floating point types due to rounding so it is applied
only if -fassociative-math was specify. */
if (flag_associative_math
&& TREE_CODE (arg0) == RDIV_EXPR
&& TREE_CODE (arg1) == REAL_CST
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == REAL_CST)
{
tree tem = const_binop (MULT_EXPR, TREE_OPERAND (arg0, 0),
arg1);
if (tem)
return fold_build2_loc (loc, RDIV_EXPR, type, tem,
TREE_OPERAND (arg0, 1));
}
/* Strip sign operations from X in X*X, i.e. -Y*-Y -> Y*Y. */
if (operand_equal_p (arg0, arg1, 0))
{
tree tem = fold_strip_sign_ops (arg0);
if (tem != NULL_TREE)
{
tem = fold_convert_loc (loc, type, tem);
return fold_build2_loc (loc, MULT_EXPR, type, tem, tem);
}
}
/* Fold z * +-I to __complex__ (-+__imag z, +-__real z).
This is not the same for NaNs or if signed zeros are
involved. */
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))
&& COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))
&& TREE_CODE (arg1) == COMPLEX_CST
&& real_zerop (TREE_REALPART (arg1)))
{
tree rtype = TREE_TYPE (TREE_TYPE (arg0));
if (real_onep (TREE_IMAGPART (arg1)))
return
fold_build2_loc (loc, COMPLEX_EXPR, type,
negate_expr (fold_build1_loc (loc, IMAGPART_EXPR,
rtype, arg0)),
fold_build1_loc (loc, REALPART_EXPR, rtype, arg0));
else if (real_minus_onep (TREE_IMAGPART (arg1)))
return
fold_build2_loc (loc, COMPLEX_EXPR, type,
fold_build1_loc (loc, IMAGPART_EXPR, rtype, arg0),
negate_expr (fold_build1_loc (loc, REALPART_EXPR,
rtype, arg0)));
}
/* Optimize z * conj(z) for floating point complex numbers.
Guarded by flag_unsafe_math_optimizations as non-finite
imaginary components don't produce scalar results. */
if (flag_unsafe_math_optimizations
&& TREE_CODE (arg0) == CONJ_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
return fold_mult_zconjz (loc, type, arg1);
if (flag_unsafe_math_optimizations
&& TREE_CODE (arg1) == CONJ_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
return fold_mult_zconjz (loc, type, arg0);
if (flag_unsafe_math_optimizations)
{
enum built_in_function fcode0 = builtin_mathfn_code (arg0);
enum built_in_function fcode1 = builtin_mathfn_code (arg1);
/* Optimizations of root(...)*root(...). */
if (fcode0 == fcode1 && BUILTIN_ROOT_P (fcode0))
{
tree rootfn, arg;
tree arg00 = CALL_EXPR_ARG (arg0, 0);
tree arg10 = CALL_EXPR_ARG (arg1, 0);
/* Optimize sqrt(x)*sqrt(x) as x. */
if (BUILTIN_SQRT_P (fcode0)
&& operand_equal_p (arg00, arg10, 0)
&& ! HONOR_SNANS (TYPE_MODE (type)))
return arg00;
/* Optimize root(x)*root(y) as root(x*y). */
rootfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0);
arg = fold_build2_loc (loc, MULT_EXPR, type, arg00, arg10);
return build_call_expr_loc (loc, rootfn, 1, arg);
}
/* Optimize expN(x)*expN(y) as expN(x+y). */
if (fcode0 == fcode1 && BUILTIN_EXPONENT_P (fcode0))
{
tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0);
tree arg = fold_build2_loc (loc, PLUS_EXPR, type,
CALL_EXPR_ARG (arg0, 0),
CALL_EXPR_ARG (arg1, 0));
return build_call_expr_loc (loc, expfn, 1, arg);
}
/* Optimizations of pow(...)*pow(...). */
if ((fcode0 == BUILT_IN_POW && fcode1 == BUILT_IN_POW)
|| (fcode0 == BUILT_IN_POWF && fcode1 == BUILT_IN_POWF)
|| (fcode0 == BUILT_IN_POWL && fcode1 == BUILT_IN_POWL))
{
tree arg00 = CALL_EXPR_ARG (arg0, 0);
tree arg01 = CALL_EXPR_ARG (arg0, 1);
tree arg10 = CALL_EXPR_ARG (arg1, 0);
tree arg11 = CALL_EXPR_ARG (arg1, 1);
/* Optimize pow(x,y)*pow(z,y) as pow(x*z,y). */
if (operand_equal_p (arg01, arg11, 0))
{
tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0);
tree arg = fold_build2_loc (loc, MULT_EXPR, type,
arg00, arg10);
return build_call_expr_loc (loc, powfn, 2, arg, arg01);
}
/* Optimize pow(x,y)*pow(x,z) as pow(x,y+z). */
if (operand_equal_p (arg00, arg10, 0))
{
tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0);
tree arg = fold_build2_loc (loc, PLUS_EXPR, type,
arg01, arg11);
return build_call_expr_loc (loc, powfn, 2, arg00, arg);
}
}
/* Optimize tan(x)*cos(x) as sin(x). */
if (((fcode0 == BUILT_IN_TAN && fcode1 == BUILT_IN_COS)
|| (fcode0 == BUILT_IN_TANF && fcode1 == BUILT_IN_COSF)
|| (fcode0 == BUILT_IN_TANL && fcode1 == BUILT_IN_COSL)
|| (fcode0 == BUILT_IN_COS && fcode1 == BUILT_IN_TAN)
|| (fcode0 == BUILT_IN_COSF && fcode1 == BUILT_IN_TANF)
|| (fcode0 == BUILT_IN_COSL && fcode1 == BUILT_IN_TANL))
&& operand_equal_p (CALL_EXPR_ARG (arg0, 0),
CALL_EXPR_ARG (arg1, 0), 0))
{
tree sinfn = mathfn_built_in (type, BUILT_IN_SIN);
if (sinfn != NULL_TREE)
return build_call_expr_loc (loc, sinfn, 1,
CALL_EXPR_ARG (arg0, 0));
}
/* Optimize x*pow(x,c) as pow(x,c+1). */
if (fcode1 == BUILT_IN_POW
|| fcode1 == BUILT_IN_POWF
|| fcode1 == BUILT_IN_POWL)
{
tree arg10 = CALL_EXPR_ARG (arg1, 0);
tree arg11 = CALL_EXPR_ARG (arg1, 1);
if (TREE_CODE (arg11) == REAL_CST
&& !TREE_OVERFLOW (arg11)
&& operand_equal_p (arg0, arg10, 0))
{
tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0);
REAL_VALUE_TYPE c;
tree arg;
c = TREE_REAL_CST (arg11);
real_arithmetic (&c, PLUS_EXPR, &c, &dconst1);
arg = build_real (type, c);
return build_call_expr_loc (loc, powfn, 2, arg0, arg);
}
}
/* Optimize pow(x,c)*x as pow(x,c+1). */
if (fcode0 == BUILT_IN_POW
|| fcode0 == BUILT_IN_POWF
|| fcode0 == BUILT_IN_POWL)
{
tree arg00 = CALL_EXPR_ARG (arg0, 0);
tree arg01 = CALL_EXPR_ARG (arg0, 1);
if (TREE_CODE (arg01) == REAL_CST
&& !TREE_OVERFLOW (arg01)
&& operand_equal_p (arg1, arg00, 0))
{
tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0);
REAL_VALUE_TYPE c;
tree arg;
c = TREE_REAL_CST (arg01);
real_arithmetic (&c, PLUS_EXPR, &c, &dconst1);
arg = build_real (type, c);
return build_call_expr_loc (loc, powfn, 2, arg1, arg);
}
}
/* Canonicalize x*x as pow(x,2.0), which is expanded as x*x. */
if (!in_gimple_form
&& optimize
&& operand_equal_p (arg0, arg1, 0))
{
tree powfn = mathfn_built_in (type, BUILT_IN_POW);
if (powfn)
{
tree arg = build_real (type, dconst2);
return build_call_expr_loc (loc, powfn, 2, arg0, arg);
}
}
}
}
goto associate;
case BIT_IOR_EXPR:
bit_ior:
if (integer_all_onesp (arg1))
return omit_one_operand_loc (loc, type, arg1, arg0);
if (integer_zerop (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
if (operand_equal_p (arg0, arg1, 0))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* ~X | X is -1. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
{
t1 = build_zero_cst (type);
t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1);
return omit_one_operand_loc (loc, type, t1, arg1);
}
/* X | ~X is -1. */
if (TREE_CODE (arg1) == BIT_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
t1 = build_zero_cst (type);
t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1);
return omit_one_operand_loc (loc, type, t1, arg0);
}
/* Canonicalize (X & C1) | C2. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
{
double_int c1, c2, c3, msk;
int width = TYPE_PRECISION (type), w;
c1 = tree_to_double_int (TREE_OPERAND (arg0, 1));
c2 = tree_to_double_int (arg1);
/* If (C1&C2) == C1, then (X&C1)|C2 becomes (X,C2). */
if ((c1 & c2) == c1)
return omit_one_operand_loc (loc, type, arg1,
TREE_OPERAND (arg0, 0));
msk = double_int::mask (width);
/* If (C1|C2) == ~0 then (X&C1)|C2 becomes X|C2. */
if (msk.and_not (c1 | c2).is_zero ())
return fold_build2_loc (loc, BIT_IOR_EXPR, type,
TREE_OPERAND (arg0, 0), arg1);
/* Minimize the number of bits set in C1, i.e. C1 := C1 & ~C2,
unless (C1 & ~C2) | (C2 & C3) for some C3 is a mask of some
mode which allows further optimizations. */
c1 &= msk;
c2 &= msk;
c3 = c1.and_not (c2);
for (w = BITS_PER_UNIT;
w <= width && w <= HOST_BITS_PER_WIDE_INT;
w <<= 1)
{
unsigned HOST_WIDE_INT mask
= (unsigned HOST_WIDE_INT) -1 >> (HOST_BITS_PER_WIDE_INT - w);
if (((c1.low | c2.low) & mask) == mask
&& (c1.low & ~mask) == 0 && c1.high == 0)
{
c3 = double_int::from_uhwi (mask);
break;
}
}
if (c3 != c1)
return fold_build2_loc (loc, BIT_IOR_EXPR, type,
fold_build2_loc (loc, BIT_AND_EXPR, type,
TREE_OPERAND (arg0, 0),
double_int_to_tree (type,
c3)),
arg1);
}
/* (X & Y) | Y is (X, Y). */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 0));
/* (X & Y) | X is (Y, X). */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
&& reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 1));
/* X | (X & Y) is (Y, X). */
if (TREE_CODE (arg1) == BIT_AND_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)
&& reorder_operands_p (arg0, TREE_OPERAND (arg1, 1)))
return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 1));
/* X | (Y & X) is (Y, X). */
if (TREE_CODE (arg1) == BIT_AND_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0)
&& reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 0));
/* (X & ~Y) | (~X & Y) is X ^ Y */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == BIT_AND_EXPR)
{
tree a0, a1, l0, l1, n0, n1;
a0 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
a1 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
l0 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
l1 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
n0 = fold_build1_loc (loc, BIT_NOT_EXPR, type, l0);
n1 = fold_build1_loc (loc, BIT_NOT_EXPR, type, l1);
if ((operand_equal_p (n0, a0, 0)
&& operand_equal_p (n1, a1, 0))
|| (operand_equal_p (n0, a1, 0)
&& operand_equal_p (n1, a0, 0)))
return fold_build2_loc (loc, BIT_XOR_EXPR, type, l0, n1);
}
t1 = distribute_bit_expr (loc, code, type, arg0, arg1);
if (t1 != NULL_TREE)
return t1;
/* Convert (or (not arg0) (not arg1)) to (not (and (arg0) (arg1))).
This results in more efficient code for machines without a NAND
instruction. Combine will canonicalize to the first form
which will allow use of NAND instructions provided by the
backend if they exist. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == BIT_NOT_EXPR)
{
return
fold_build1_loc (loc, BIT_NOT_EXPR, type,
build2 (BIT_AND_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)),
fold_convert_loc (loc, type,
TREE_OPERAND (arg1, 0))));
}
/* See if this can be simplified into a rotate first. If that
is unsuccessful continue in the association code. */
goto bit_rotate;
case BIT_XOR_EXPR:
if (integer_zerop (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
if (integer_all_onesp (arg1))
return fold_build1_loc (loc, BIT_NOT_EXPR, type, op0);
if (operand_equal_p (arg0, arg1, 0))
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
/* ~X ^ X is -1. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
{
t1 = build_zero_cst (type);
t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1);
return omit_one_operand_loc (loc, type, t1, arg1);
}
/* X ^ ~X is -1. */
if (TREE_CODE (arg1) == BIT_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
t1 = build_zero_cst (type);
t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1);
return omit_one_operand_loc (loc, type, t1, arg0);
}
/* If we are XORing two BIT_AND_EXPR's, both of which are and'ing
with a constant, and the two constants have no bits in common,
we should treat this as a BIT_IOR_EXPR since this may produce more
simplifications. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == BIT_AND_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg1, 1)) == INTEGER_CST
&& integer_zerop (const_binop (BIT_AND_EXPR,
TREE_OPERAND (arg0, 1),
TREE_OPERAND (arg1, 1))))
{
code = BIT_IOR_EXPR;
goto bit_ior;
}
/* (X | Y) ^ X -> Y & ~ X*/
if (TREE_CODE (arg0) == BIT_IOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
{
tree t2 = TREE_OPERAND (arg0, 1);
t1 = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg1),
arg1);
t1 = fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_convert_loc (loc, type, t2),
fold_convert_loc (loc, type, t1));
return t1;
}
/* (Y | X) ^ X -> Y & ~ X*/
if (TREE_CODE (arg0) == BIT_IOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
{
tree t2 = TREE_OPERAND (arg0, 0);
t1 = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg1),
arg1);
t1 = fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_convert_loc (loc, type, t2),
fold_convert_loc (loc, type, t1));
return t1;
}
/* X ^ (X | Y) -> Y & ~ X*/
if (TREE_CODE (arg1) == BIT_IOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg1, 0), arg0, 0))
{
tree t2 = TREE_OPERAND (arg1, 1);
t1 = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg0),
arg0);
t1 = fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_convert_loc (loc, type, t2),
fold_convert_loc (loc, type, t1));
return t1;
}
/* X ^ (Y | X) -> Y & ~ X*/
if (TREE_CODE (arg1) == BIT_IOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg1, 1), arg0, 0))
{
tree t2 = TREE_OPERAND (arg1, 0);
t1 = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg0),
arg0);
t1 = fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_convert_loc (loc, type, t2),
fold_convert_loc (loc, type, t1));
return t1;
}
/* Convert ~X ^ ~Y to X ^ Y. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == BIT_NOT_EXPR)
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)),
fold_convert_loc (loc, type,
TREE_OPERAND (arg1, 0)));
/* Convert ~X ^ C to X ^ ~C. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == INTEGER_CST)
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)),
fold_build1_loc (loc, BIT_NOT_EXPR, type, arg1));
/* Fold (X & 1) ^ 1 as (X & 1) == 0. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1))
&& integer_onep (arg1))
return fold_build2_loc (loc, EQ_EXPR, type, arg0,
build_zero_cst (TREE_TYPE (arg0)));
/* Fold (X & Y) ^ Y as ~X & Y. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
{
tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_build1_loc (loc, BIT_NOT_EXPR, type, tem),
fold_convert_loc (loc, type, arg1));
}
/* Fold (X & Y) ^ X as ~Y & X. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
&& reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
{
tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_build1_loc (loc, BIT_NOT_EXPR, type, tem),
fold_convert_loc (loc, type, arg1));
}
/* Fold X ^ (X & Y) as X & ~Y. */
if (TREE_CODE (arg1) == BIT_AND_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_convert_loc (loc, type, arg0),
fold_build1_loc (loc, BIT_NOT_EXPR, type, tem));
}
/* Fold X ^ (Y & X) as ~Y & X. */
if (TREE_CODE (arg1) == BIT_AND_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0)
&& reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
{
tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_build1_loc (loc, BIT_NOT_EXPR, type, tem),
fold_convert_loc (loc, type, arg0));
}
/* See if this can be simplified into a rotate first. If that
is unsuccessful continue in the association code. */
goto bit_rotate;
case BIT_AND_EXPR:
if (integer_all_onesp (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
if (integer_zerop (arg1))
return omit_one_operand_loc (loc, type, arg1, arg0);
if (operand_equal_p (arg0, arg1, 0))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* ~X & X, (X == 0) & X, and !X & X are always zero. */
if ((TREE_CODE (arg0) == BIT_NOT_EXPR
|| TREE_CODE (arg0) == TRUTH_NOT_EXPR
|| (TREE_CODE (arg0) == EQ_EXPR
&& integer_zerop (TREE_OPERAND (arg0, 1))))
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
return omit_one_operand_loc (loc, type, integer_zero_node, arg1);
/* X & ~X , X & (X == 0), and X & !X are always zero. */
if ((TREE_CODE (arg1) == BIT_NOT_EXPR
|| TREE_CODE (arg1) == TRUTH_NOT_EXPR
|| (TREE_CODE (arg1) == EQ_EXPR
&& integer_zerop (TREE_OPERAND (arg1, 1))))
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
/* Canonicalize (X | C1) & C2 as (X & C2) | (C1 & C2). */
if (TREE_CODE (arg0) == BIT_IOR_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
{
tree tmp1 = fold_convert_loc (loc, type, arg1);
tree tmp2 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
tree tmp3 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
tmp2 = fold_build2_loc (loc, BIT_AND_EXPR, type, tmp2, tmp1);
tmp3 = fold_build2_loc (loc, BIT_AND_EXPR, type, tmp3, tmp1);
return
fold_convert_loc (loc, type,
fold_build2_loc (loc, BIT_IOR_EXPR,
type, tmp2, tmp3));
}
/* (X | Y) & Y is (X, Y). */
if (TREE_CODE (arg0) == BIT_IOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 0));
/* (X | Y) & X is (Y, X). */
if (TREE_CODE (arg0) == BIT_IOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
&& reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 1));
/* X & (X | Y) is (Y, X). */
if (TREE_CODE (arg1) == BIT_IOR_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)
&& reorder_operands_p (arg0, TREE_OPERAND (arg1, 1)))
return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 1));
/* X & (Y | X) is (Y, X). */
if (TREE_CODE (arg1) == BIT_IOR_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0)
&& reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 0));
/* Fold (X ^ 1) & 1 as (X & 1) == 0. */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1))
&& integer_onep (arg1))
{
tree tem2;
tem = TREE_OPERAND (arg0, 0);
tem2 = fold_convert_loc (loc, TREE_TYPE (tem), arg1);
tem2 = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (tem),
tem, tem2);
return fold_build2_loc (loc, EQ_EXPR, type, tem2,
build_zero_cst (TREE_TYPE (tem)));
}
/* Fold ~X & 1 as (X & 1) == 0. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& integer_onep (arg1))
{
tree tem2;
tem = TREE_OPERAND (arg0, 0);
tem2 = fold_convert_loc (loc, TREE_TYPE (tem), arg1);
tem2 = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (tem),
tem, tem2);
return fold_build2_loc (loc, EQ_EXPR, type, tem2,
build_zero_cst (TREE_TYPE (tem)));
}
/* Fold !X & 1 as X == 0. */
if (TREE_CODE (arg0) == TRUTH_NOT_EXPR
&& integer_onep (arg1))
{
tem = TREE_OPERAND (arg0, 0);
return fold_build2_loc (loc, EQ_EXPR, type, tem,
build_zero_cst (TREE_TYPE (tem)));
}
/* Fold (X ^ Y) & Y as ~X & Y. */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
{
tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_build1_loc (loc, BIT_NOT_EXPR, type, tem),
fold_convert_loc (loc, type, arg1));
}
/* Fold (X ^ Y) & X as ~Y & X. */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
&& reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
{
tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_build1_loc (loc, BIT_NOT_EXPR, type, tem),
fold_convert_loc (loc, type, arg1));
}
/* Fold X & (X ^ Y) as X & ~Y. */
if (TREE_CODE (arg1) == BIT_XOR_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_convert_loc (loc, type, arg0),
fold_build1_loc (loc, BIT_NOT_EXPR, type, tem));
}
/* Fold X & (Y ^ X) as ~Y & X. */
if (TREE_CODE (arg1) == BIT_XOR_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0)
&& reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
{
tem = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_build1_loc (loc, BIT_NOT_EXPR, type, tem),
fold_convert_loc (loc, type, arg0));
}
/* Fold (X * Y) & -(1 << CST) to X * Y if Y is a constant
multiple of 1 << CST. */
if (TREE_CODE (arg1) == INTEGER_CST)
{
double_int cst1 = tree_to_double_int (arg1);
double_int ncst1 = (-cst1).ext(TYPE_PRECISION (TREE_TYPE (arg1)),
TYPE_UNSIGNED (TREE_TYPE (arg1)));
if ((cst1 & ncst1) == ncst1
&& multiple_of_p (type, arg0,
double_int_to_tree (TREE_TYPE (arg1), ncst1)))
return fold_convert_loc (loc, type, arg0);
}
/* Fold (X * CST1) & CST2 to zero if we can, or drop known zero
bits from CST2. */
if (TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (arg0) == MULT_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
{
int arg1tz
= tree_to_double_int (TREE_OPERAND (arg0, 1)).trailing_zeros ();
if (arg1tz > 0)
{
double_int arg1mask, masked;
arg1mask = ~double_int::mask (arg1tz);
arg1mask = arg1mask.ext (TYPE_PRECISION (type),
TYPE_UNSIGNED (type));
masked = arg1mask & tree_to_double_int (arg1);
if (masked.is_zero ())
return omit_two_operands_loc (loc, type, build_zero_cst (type),
arg0, arg1);
else if (masked != tree_to_double_int (arg1))
return fold_build2_loc (loc, code, type, op0,
double_int_to_tree (type, masked));
}
}
/* For constants M and N, if M == (1LL << cst) - 1 && (N & M) == M,
((A & N) + B) & M -> (A + B) & M
Similarly if (N & M) == 0,
((A | N) + B) & M -> (A + B) & M
and for - instead of + (or unary - instead of +)
and/or ^ instead of |.
If B is constant and (B & M) == 0, fold into A & M. */
if (host_integerp (arg1, 1))
{
unsigned HOST_WIDE_INT cst1 = tree_low_cst (arg1, 1);
if (~cst1 && (cst1 & (cst1 + 1)) == 0
&& INTEGRAL_TYPE_P (TREE_TYPE (arg0))
&& (TREE_CODE (arg0) == PLUS_EXPR
|| TREE_CODE (arg0) == MINUS_EXPR
|| TREE_CODE (arg0) == NEGATE_EXPR)
&& (TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0))
|| TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE))
{
tree pmop[2];
int which = 0;
unsigned HOST_WIDE_INT cst0;
/* Now we know that arg0 is (C + D) or (C - D) or
-C and arg1 (M) is == (1LL << cst) - 1.
Store C into PMOP[0] and D into PMOP[1]. */
pmop[0] = TREE_OPERAND (arg0, 0);
pmop[1] = NULL;
if (TREE_CODE (arg0) != NEGATE_EXPR)
{
pmop[1] = TREE_OPERAND (arg0, 1);
which = 1;
}
if (!host_integerp (TYPE_MAX_VALUE (TREE_TYPE (arg0)), 1)
|| (tree_low_cst (TYPE_MAX_VALUE (TREE_TYPE (arg0)), 1)
& cst1) != cst1)
which = -1;
for (; which >= 0; which--)
switch (TREE_CODE (pmop[which]))
{
case BIT_AND_EXPR:
case BIT_IOR_EXPR:
case BIT_XOR_EXPR:
if (TREE_CODE (TREE_OPERAND (pmop[which], 1))
!= INTEGER_CST)
break;
/* tree_low_cst not used, because we don't care about
the upper bits. */
cst0 = TREE_INT_CST_LOW (TREE_OPERAND (pmop[which], 1));
cst0 &= cst1;
if (TREE_CODE (pmop[which]) == BIT_AND_EXPR)
{
if (cst0 != cst1)
break;
}
else if (cst0 != 0)
break;
/* If C or D is of the form (A & N) where
(N & M) == M, or of the form (A | N) or
(A ^ N) where (N & M) == 0, replace it with A. */
pmop[which] = TREE_OPERAND (pmop[which], 0);
break;
case INTEGER_CST:
/* If C or D is a N where (N & M) == 0, it can be
omitted (assumed 0). */
if ((TREE_CODE (arg0) == PLUS_EXPR
|| (TREE_CODE (arg0) == MINUS_EXPR && which == 0))
&& (TREE_INT_CST_LOW (pmop[which]) & cst1) == 0)
pmop[which] = NULL;
break;
default:
break;
}
/* Only build anything new if we optimized one or both arguments
above. */
if (pmop[0] != TREE_OPERAND (arg0, 0)
|| (TREE_CODE (arg0) != NEGATE_EXPR
&& pmop[1] != TREE_OPERAND (arg0, 1)))
{
tree utype = TREE_TYPE (arg0);
if (! TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0)))
{
/* Perform the operations in a type that has defined
overflow behavior. */
utype = unsigned_type_for (TREE_TYPE (arg0));
if (pmop[0] != NULL)
pmop[0] = fold_convert_loc (loc, utype, pmop[0]);
if (pmop[1] != NULL)
pmop[1] = fold_convert_loc (loc, utype, pmop[1]);
}
if (TREE_CODE (arg0) == NEGATE_EXPR)
tem = fold_build1_loc (loc, NEGATE_EXPR, utype, pmop[0]);
else if (TREE_CODE (arg0) == PLUS_EXPR)
{
if (pmop[0] != NULL && pmop[1] != NULL)
tem = fold_build2_loc (loc, PLUS_EXPR, utype,
pmop[0], pmop[1]);
else if (pmop[0] != NULL)
tem = pmop[0];
else if (pmop[1] != NULL)
tem = pmop[1];
else
return build_int_cst (type, 0);
}
else if (pmop[0] == NULL)
tem = fold_build1_loc (loc, NEGATE_EXPR, utype, pmop[1]);
else
tem = fold_build2_loc (loc, MINUS_EXPR, utype,
pmop[0], pmop[1]);
/* TEM is now the new binary +, - or unary - replacement. */
tem = fold_build2_loc (loc, BIT_AND_EXPR, utype, tem,
fold_convert_loc (loc, utype, arg1));
return fold_convert_loc (loc, type, tem);
}
}
}
t1 = distribute_bit_expr (loc, code, type, arg0, arg1);
if (t1 != NULL_TREE)
return t1;
/* Simplify ((int)c & 0377) into (int)c, if c is unsigned char. */
if (TREE_CODE (arg1) == INTEGER_CST && TREE_CODE (arg0) == NOP_EXPR
&& TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg0, 0))))
{
unsigned int prec
= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)));
if (prec < BITS_PER_WORD && prec < HOST_BITS_PER_WIDE_INT
&& (~TREE_INT_CST_LOW (arg1)
& (((HOST_WIDE_INT) 1 << prec) - 1)) == 0)
return
fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
}
/* Convert (and (not arg0) (not arg1)) to (not (or (arg0) (arg1))).
This results in more efficient code for machines without a NOR
instruction. Combine will canonicalize to the first form
which will allow use of NOR instructions provided by the
backend if they exist. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& TREE_CODE (arg1) == BIT_NOT_EXPR)
{
return fold_build1_loc (loc, BIT_NOT_EXPR, type,
build2 (BIT_IOR_EXPR, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)),
fold_convert_loc (loc, type,
TREE_OPERAND (arg1, 0))));
}
/* If arg0 is derived from the address of an object or function, we may
be able to fold this expression using the object or function's
alignment. */
if (POINTER_TYPE_P (TREE_TYPE (arg0)) && host_integerp (arg1, 1))
{
unsigned HOST_WIDE_INT modulus, residue;
unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (arg1);
modulus = get_pointer_modulus_and_residue (arg0, &residue,
integer_onep (arg1));
/* This works because modulus is a power of 2. If this weren't the
case, we'd have to replace it by its greatest power-of-2
divisor: modulus & -modulus. */
if (low < modulus)
return build_int_cst (type, residue & low);
}
/* Fold (X << C1) & C2 into (X << C1) & (C2 | ((1 << C1) - 1))
(X >> C1) & C2 into (X >> C1) & (C2 | ~((type) -1 >> C1))
if the new mask might be further optimized. */
if ((TREE_CODE (arg0) == LSHIFT_EXPR
|| TREE_CODE (arg0) == RSHIFT_EXPR)
&& host_integerp (TREE_OPERAND (arg0, 1), 1)
&& host_integerp (arg1, TYPE_UNSIGNED (TREE_TYPE (arg1)))
&& tree_low_cst (TREE_OPERAND (arg0, 1), 1)
< TYPE_PRECISION (TREE_TYPE (arg0))
&& TYPE_PRECISION (TREE_TYPE (arg0)) <= HOST_BITS_PER_WIDE_INT
&& tree_low_cst (TREE_OPERAND (arg0, 1), 1) > 0)
{
unsigned int shiftc = tree_low_cst (TREE_OPERAND (arg0, 1), 1);
unsigned HOST_WIDE_INT mask
= tree_low_cst (arg1, TYPE_UNSIGNED (TREE_TYPE (arg1)));
unsigned HOST_WIDE_INT newmask, zerobits = 0;
tree shift_type = TREE_TYPE (arg0);
if (TREE_CODE (arg0) == LSHIFT_EXPR)
zerobits = ((((unsigned HOST_WIDE_INT) 1) << shiftc) - 1);
else if (TREE_CODE (arg0) == RSHIFT_EXPR
&& TYPE_PRECISION (TREE_TYPE (arg0))
== GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (arg0))))
{
unsigned int prec = TYPE_PRECISION (TREE_TYPE (arg0));
tree arg00 = TREE_OPERAND (arg0, 0);
/* See if more bits can be proven as zero because of
zero extension. */
if (TREE_CODE (arg00) == NOP_EXPR
&& TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg00, 0))))
{
tree inner_type = TREE_TYPE (TREE_OPERAND (arg00, 0));
if (TYPE_PRECISION (inner_type)
== GET_MODE_BITSIZE (TYPE_MODE (inner_type))
&& TYPE_PRECISION (inner_type) < prec)
{
prec = TYPE_PRECISION (inner_type);
/* See if we can shorten the right shift. */
if (shiftc < prec)
shift_type = inner_type;
}
}
zerobits = ~(unsigned HOST_WIDE_INT) 0;
zerobits >>= HOST_BITS_PER_WIDE_INT - shiftc;
zerobits <<= prec - shiftc;
/* For arithmetic shift if sign bit could be set, zerobits
can contain actually sign bits, so no transformation is
possible, unless MASK masks them all away. In that
case the shift needs to be converted into logical shift. */
if (!TYPE_UNSIGNED (TREE_TYPE (arg0))
&& prec == TYPE_PRECISION (TREE_TYPE (arg0)))
{
if ((mask & zerobits) == 0)
shift_type = unsigned_type_for (TREE_TYPE (arg0));
else
zerobits = 0;
}
}
/* ((X << 16) & 0xff00) is (X, 0). */
if ((mask & zerobits) == mask)
return omit_one_operand_loc (loc, type,
build_int_cst (type, 0), arg0);
newmask = mask | zerobits;
if (newmask != mask && (newmask & (newmask + 1)) == 0)
{
unsigned int prec;
/* Only do the transformation if NEWMASK is some integer
mode's mask. */
for (prec = BITS_PER_UNIT;
prec < HOST_BITS_PER_WIDE_INT; prec <<= 1)
if (newmask == (((unsigned HOST_WIDE_INT) 1) << prec) - 1)
break;
if (prec < HOST_BITS_PER_WIDE_INT
|| newmask == ~(unsigned HOST_WIDE_INT) 0)
{
tree newmaskt;
if (shift_type != TREE_TYPE (arg0))
{
tem = fold_build2_loc (loc, TREE_CODE (arg0), shift_type,
fold_convert_loc (loc, shift_type,
TREE_OPERAND (arg0, 0)),
TREE_OPERAND (arg0, 1));
tem = fold_convert_loc (loc, type, tem);
}
else
tem = op0;
newmaskt = build_int_cst_type (TREE_TYPE (op1), newmask);
if (!tree_int_cst_equal (newmaskt, arg1))
return fold_build2_loc (loc, BIT_AND_EXPR, type, tem, newmaskt);
}
}
}
goto associate;
case RDIV_EXPR:
/* Don't touch a floating-point divide by zero unless the mode
of the constant can represent infinity. */
if (TREE_CODE (arg1) == REAL_CST
&& !MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg1)))
&& real_zerop (arg1))
return NULL_TREE;
/* Optimize A / A to 1.0 if we don't care about
NaNs or Infinities. Skip the transformation
for non-real operands. */
if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (arg0))
&& ! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
&& ! HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg0)))
&& operand_equal_p (arg0, arg1, 0))
{
tree r = build_real (TREE_TYPE (arg0), dconst1);
return omit_two_operands_loc (loc, type, r, arg0, arg1);
}
/* The complex version of the above A / A optimization. */
if (COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))
&& operand_equal_p (arg0, arg1, 0))
{
tree elem_type = TREE_TYPE (TREE_TYPE (arg0));
if (! HONOR_NANS (TYPE_MODE (elem_type))
&& ! HONOR_INFINITIES (TYPE_MODE (elem_type)))
{
tree r = build_real (elem_type, dconst1);
/* omit_two_operands will call fold_convert for us. */
return omit_two_operands_loc (loc, type, r, arg0, arg1);
}
}
/* (-A) / (-B) -> A / B */
if (TREE_CODE (arg0) == NEGATE_EXPR && negate_expr_p (arg1))
return fold_build2_loc (loc, RDIV_EXPR, type,
TREE_OPERAND (arg0, 0),
negate_expr (arg1));
if (TREE_CODE (arg1) == NEGATE_EXPR && negate_expr_p (arg0))
return fold_build2_loc (loc, RDIV_EXPR, type,
negate_expr (arg0),
TREE_OPERAND (arg1, 0));
/* In IEEE floating point, x/1 is not equivalent to x for snans. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_onep (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* In IEEE floating point, x/-1 is not equivalent to -x for snans. */
if (!HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_minus_onep (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type,
negate_expr (arg0)));
/* If ARG1 is a constant, we can convert this to a multiply by the
reciprocal. This does not have the same rounding properties,
so only do this if -freciprocal-math. We can actually
always safely do it if ARG1 is a power of two, but it's hard to
tell if it is or not in a portable manner. */
if (optimize
&& (TREE_CODE (arg1) == REAL_CST
|| (TREE_CODE (arg1) == COMPLEX_CST
&& COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg1)))
|| (TREE_CODE (arg1) == VECTOR_CST
&& VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg1)))))
{
if (flag_reciprocal_math
&& 0 != (tem = const_binop (code, build_one_cst (type), arg1)))
return fold_build2_loc (loc, MULT_EXPR, type, arg0, tem);
/* Find the reciprocal if optimizing and the result is exact.
TODO: Complex reciprocal not implemented. */
if (TREE_CODE (arg1) != COMPLEX_CST)
{
tree inverse = exact_inverse (TREE_TYPE (arg0), arg1);
if (inverse)
return fold_build2_loc (loc, MULT_EXPR, type, arg0, inverse);
}
}
/* Convert A/B/C to A/(B*C). */
if (flag_reciprocal_math
&& TREE_CODE (arg0) == RDIV_EXPR)
return fold_build2_loc (loc, RDIV_EXPR, type, TREE_OPERAND (arg0, 0),
fold_build2_loc (loc, MULT_EXPR, type,
TREE_OPERAND (arg0, 1), arg1));
/* Convert A/(B/C) to (A/B)*C. */
if (flag_reciprocal_math
&& TREE_CODE (arg1) == RDIV_EXPR)
return fold_build2_loc (loc, MULT_EXPR, type,
fold_build2_loc (loc, RDIV_EXPR, type, arg0,
TREE_OPERAND (arg1, 0)),
TREE_OPERAND (arg1, 1));
/* Convert C1/(X*C2) into (C1/C2)/X. */
if (flag_reciprocal_math
&& TREE_CODE (arg1) == MULT_EXPR
&& TREE_CODE (arg0) == REAL_CST
&& TREE_CODE (TREE_OPERAND (arg1, 1)) == REAL_CST)
{
tree tem = const_binop (RDIV_EXPR, arg0,
TREE_OPERAND (arg1, 1));
if (tem)
return fold_build2_loc (loc, RDIV_EXPR, type, tem,
TREE_OPERAND (arg1, 0));
}
if (flag_unsafe_math_optimizations)
{
enum built_in_function fcode0 = builtin_mathfn_code (arg0);
enum built_in_function fcode1 = builtin_mathfn_code (arg1);
/* Optimize sin(x)/cos(x) as tan(x). */
if (((fcode0 == BUILT_IN_SIN && fcode1 == BUILT_IN_COS)
|| (fcode0 == BUILT_IN_SINF && fcode1 == BUILT_IN_COSF)
|| (fcode0 == BUILT_IN_SINL && fcode1 == BUILT_IN_COSL))
&& operand_equal_p (CALL_EXPR_ARG (arg0, 0),
CALL_EXPR_ARG (arg1, 0), 0))
{
tree tanfn = mathfn_built_in (type, BUILT_IN_TAN);
if (tanfn != NULL_TREE)
return build_call_expr_loc (loc, tanfn, 1, CALL_EXPR_ARG (arg0, 0));
}
/* Optimize cos(x)/sin(x) as 1.0/tan(x). */
if (((fcode0 == BUILT_IN_COS && fcode1 == BUILT_IN_SIN)
|| (fcode0 == BUILT_IN_COSF && fcode1 == BUILT_IN_SINF)
|| (fcode0 == BUILT_IN_COSL && fcode1 == BUILT_IN_SINL))
&& operand_equal_p (CALL_EXPR_ARG (arg0, 0),
CALL_EXPR_ARG (arg1, 0), 0))
{
tree tanfn = mathfn_built_in (type, BUILT_IN_TAN);
if (tanfn != NULL_TREE)
{
tree tmp = build_call_expr_loc (loc, tanfn, 1,
CALL_EXPR_ARG (arg0, 0));
return fold_build2_loc (loc, RDIV_EXPR, type,
build_real (type, dconst1), tmp);
}
}
/* Optimize sin(x)/tan(x) as cos(x) if we don't care about
NaNs or Infinities. */
if (((fcode0 == BUILT_IN_SIN && fcode1 == BUILT_IN_TAN)
|| (fcode0 == BUILT_IN_SINF && fcode1 == BUILT_IN_TANF)
|| (fcode0 == BUILT_IN_SINL && fcode1 == BUILT_IN_TANL)))
{
tree arg00 = CALL_EXPR_ARG (arg0, 0);
tree arg01 = CALL_EXPR_ARG (arg1, 0);
if (! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg00)))
&& ! HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg00)))
&& operand_equal_p (arg00, arg01, 0))
{
tree cosfn = mathfn_built_in (type, BUILT_IN_COS);
if (cosfn != NULL_TREE)
return build_call_expr_loc (loc, cosfn, 1, arg00);
}
}
/* Optimize tan(x)/sin(x) as 1.0/cos(x) if we don't care about
NaNs or Infinities. */
if (((fcode0 == BUILT_IN_TAN && fcode1 == BUILT_IN_SIN)
|| (fcode0 == BUILT_IN_TANF && fcode1 == BUILT_IN_SINF)
|| (fcode0 == BUILT_IN_TANL && fcode1 == BUILT_IN_SINL)))
{
tree arg00 = CALL_EXPR_ARG (arg0, 0);
tree arg01 = CALL_EXPR_ARG (arg1, 0);
if (! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg00)))
&& ! HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg00)))
&& operand_equal_p (arg00, arg01, 0))
{
tree cosfn = mathfn_built_in (type, BUILT_IN_COS);
if (cosfn != NULL_TREE)
{
tree tmp = build_call_expr_loc (loc, cosfn, 1, arg00);
return fold_build2_loc (loc, RDIV_EXPR, type,
build_real (type, dconst1),
tmp);
}
}
}
/* Optimize pow(x,c)/x as pow(x,c-1). */
if (fcode0 == BUILT_IN_POW
|| fcode0 == BUILT_IN_POWF
|| fcode0 == BUILT_IN_POWL)
{
tree arg00 = CALL_EXPR_ARG (arg0, 0);
tree arg01 = CALL_EXPR_ARG (arg0, 1);
if (TREE_CODE (arg01) == REAL_CST
&& !TREE_OVERFLOW (arg01)
&& operand_equal_p (arg1, arg00, 0))
{
tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg0), 0);
REAL_VALUE_TYPE c;
tree arg;
c = TREE_REAL_CST (arg01);
real_arithmetic (&c, MINUS_EXPR, &c, &dconst1);
arg = build_real (type, c);
return build_call_expr_loc (loc, powfn, 2, arg1, arg);
}
}
/* Optimize a/root(b/c) into a*root(c/b). */
if (BUILTIN_ROOT_P (fcode1))
{
tree rootarg = CALL_EXPR_ARG (arg1, 0);
if (TREE_CODE (rootarg) == RDIV_EXPR)
{
tree rootfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0);
tree b = TREE_OPERAND (rootarg, 0);
tree c = TREE_OPERAND (rootarg, 1);
tree tmp = fold_build2_loc (loc, RDIV_EXPR, type, c, b);
tmp = build_call_expr_loc (loc, rootfn, 1, tmp);
return fold_build2_loc (loc, MULT_EXPR, type, arg0, tmp);
}
}
/* Optimize x/expN(y) into x*expN(-y). */
if (BUILTIN_EXPONENT_P (fcode1))
{
tree expfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0);
tree arg = negate_expr (CALL_EXPR_ARG (arg1, 0));
arg1 = build_call_expr_loc (loc,
expfn, 1,
fold_convert_loc (loc, type, arg));
return fold_build2_loc (loc, MULT_EXPR, type, arg0, arg1);
}
/* Optimize x/pow(y,z) into x*pow(y,-z). */
if (fcode1 == BUILT_IN_POW
|| fcode1 == BUILT_IN_POWF
|| fcode1 == BUILT_IN_POWL)
{
tree powfn = TREE_OPERAND (CALL_EXPR_FN (arg1), 0);
tree arg10 = CALL_EXPR_ARG (arg1, 0);
tree arg11 = CALL_EXPR_ARG (arg1, 1);
tree neg11 = fold_convert_loc (loc, type,
negate_expr (arg11));
arg1 = build_call_expr_loc (loc, powfn, 2, arg10, neg11);
return fold_build2_loc (loc, MULT_EXPR, type, arg0, arg1);
}
}
return NULL_TREE;
case TRUNC_DIV_EXPR:
/* Optimize (X & (-A)) / A where A is a power of 2,
to X >> log2(A) */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& !TYPE_UNSIGNED (type) && TREE_CODE (arg1) == INTEGER_CST
&& integer_pow2p (arg1) && tree_int_cst_sgn (arg1) > 0)
{
tree sum = fold_binary_loc (loc, PLUS_EXPR, TREE_TYPE (arg1),
arg1, TREE_OPERAND (arg0, 1));
if (sum && integer_zerop (sum)) {
unsigned long pow2;
if (TREE_INT_CST_LOW (arg1))
pow2 = exact_log2 (TREE_INT_CST_LOW (arg1));
else
pow2 = exact_log2 (TREE_INT_CST_HIGH (arg1))
+ HOST_BITS_PER_WIDE_INT;
return fold_build2_loc (loc, RSHIFT_EXPR, type,
TREE_OPERAND (arg0, 0),
build_int_cst (integer_type_node, pow2));
}
}
/* Fall through */
case FLOOR_DIV_EXPR:
/* Simplify A / (B << N) where A and B are positive and B is
a power of 2, to A >> (N + log2(B)). */
strict_overflow_p = false;
if (TREE_CODE (arg1) == LSHIFT_EXPR
&& (TYPE_UNSIGNED (type)
|| tree_expr_nonnegative_warnv_p (op0, &strict_overflow_p)))
{
tree sval = TREE_OPERAND (arg1, 0);
if (integer_pow2p (sval) && tree_int_cst_sgn (sval) > 0)
{
tree sh_cnt = TREE_OPERAND (arg1, 1);
unsigned long pow2;
if (TREE_INT_CST_LOW (sval))
pow2 = exact_log2 (TREE_INT_CST_LOW (sval));
else
pow2 = exact_log2 (TREE_INT_CST_HIGH (sval))
+ HOST_BITS_PER_WIDE_INT;
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not "
"occur when simplifying A / (B << N)"),
WARN_STRICT_OVERFLOW_MISC);
sh_cnt = fold_build2_loc (loc, PLUS_EXPR, TREE_TYPE (sh_cnt),
sh_cnt,
build_int_cst (TREE_TYPE (sh_cnt),
pow2));
return fold_build2_loc (loc, RSHIFT_EXPR, type,
fold_convert_loc (loc, type, arg0), sh_cnt);
}
}
/* For unsigned integral types, FLOOR_DIV_EXPR is the same as
TRUNC_DIV_EXPR. Rewrite into the latter in this case. */
if (INTEGRAL_TYPE_P (type)
&& TYPE_UNSIGNED (type)
&& code == FLOOR_DIV_EXPR)
return fold_build2_loc (loc, TRUNC_DIV_EXPR, type, op0, op1);
/* Fall through */
case ROUND_DIV_EXPR:
case CEIL_DIV_EXPR:
case EXACT_DIV_EXPR:
if (integer_onep (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
if (integer_zerop (arg1))
return NULL_TREE;
/* X / -1 is -X. */
if (!TYPE_UNSIGNED (type)
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_INT_CST_LOW (arg1) == (unsigned HOST_WIDE_INT) -1
&& TREE_INT_CST_HIGH (arg1) == -1)
return fold_convert_loc (loc, type, negate_expr (arg0));
/* Convert -A / -B to A / B when the type is signed and overflow is
undefined. */
if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
&& TREE_CODE (arg0) == NEGATE_EXPR
&& negate_expr_p (arg1))
{
if (INTEGRAL_TYPE_P (type))
fold_overflow_warning (("assuming signed overflow does not occur "
"when distributing negation across "
"division"),
WARN_STRICT_OVERFLOW_MISC);
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)),
fold_convert_loc (loc, type,
negate_expr (arg1)));
}
if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
&& TREE_CODE (arg1) == NEGATE_EXPR
&& negate_expr_p (arg0))
{
if (INTEGRAL_TYPE_P (type))
fold_overflow_warning (("assuming signed overflow does not occur "
"when distributing negation across "
"division"),
WARN_STRICT_OVERFLOW_MISC);
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, type,
negate_expr (arg0)),
fold_convert_loc (loc, type,
TREE_OPERAND (arg1, 0)));
}
/* If arg0 is a multiple of arg1, then rewrite to the fastest div
operation, EXACT_DIV_EXPR.
Note that only CEIL_DIV_EXPR and FLOOR_DIV_EXPR are rewritten now.
At one time others generated faster code, it's not clear if they do
after the last round to changes to the DIV code in expmed.c. */
if ((code == CEIL_DIV_EXPR || code == FLOOR_DIV_EXPR)
&& multiple_of_p (type, arg0, arg1))
return fold_build2_loc (loc, EXACT_DIV_EXPR, type, arg0, arg1);
strict_overflow_p = false;
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE,
&strict_overflow_p)))
{
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not occur "
"when simplifying division"),
WARN_STRICT_OVERFLOW_MISC);
return fold_convert_loc (loc, type, tem);
}
return NULL_TREE;
case CEIL_MOD_EXPR:
case FLOOR_MOD_EXPR:
case ROUND_MOD_EXPR:
case TRUNC_MOD_EXPR:
/* X % 1 is always zero, but be sure to preserve any side
effects in X. */
if (integer_onep (arg1))
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
/* X % 0, return X % 0 unchanged so that we can get the
proper warnings and errors. */
if (integer_zerop (arg1))
return NULL_TREE;
/* 0 % X is always zero, but be sure to preserve any side
effects in X. Place this after checking for X == 0. */
if (integer_zerop (arg0))
return omit_one_operand_loc (loc, type, integer_zero_node, arg1);
/* X % -1 is zero. */
if (!TYPE_UNSIGNED (type)
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_INT_CST_LOW (arg1) == (unsigned HOST_WIDE_INT) -1
&& TREE_INT_CST_HIGH (arg1) == -1)
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
/* X % -C is the same as X % C. */
if (code == TRUNC_MOD_EXPR
&& !TYPE_UNSIGNED (type)
&& TREE_CODE (arg1) == INTEGER_CST
&& !TREE_OVERFLOW (arg1)
&& TREE_INT_CST_HIGH (arg1) < 0
&& !TYPE_OVERFLOW_TRAPS (type)
/* Avoid this transformation if C is INT_MIN, i.e. C == -C. */
&& !sign_bit_p (arg1, arg1))
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, type, arg0),
fold_convert_loc (loc, type,
negate_expr (arg1)));
/* X % -Y is the same as X % Y. */
if (code == TRUNC_MOD_EXPR
&& !TYPE_UNSIGNED (type)
&& TREE_CODE (arg1) == NEGATE_EXPR
&& !TYPE_OVERFLOW_TRAPS (type))
return fold_build2_loc (loc, code, type, fold_convert_loc (loc, type, arg0),
fold_convert_loc (loc, type,
TREE_OPERAND (arg1, 0)));
strict_overflow_p = false;
if (TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = extract_muldiv (op0, arg1, code, NULL_TREE,
&strict_overflow_p)))
{
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not occur "
"when simplifying modulus"),
WARN_STRICT_OVERFLOW_MISC);
return fold_convert_loc (loc, type, tem);
}
/* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR,
i.e. "X % C" into "X & (C - 1)", if X and C are positive. */
if ((code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR)
&& (TYPE_UNSIGNED (type)
|| tree_expr_nonnegative_warnv_p (op0, &strict_overflow_p)))
{
tree c = arg1;
/* Also optimize A % (C << N) where C is a power of 2,
to A & ((C << N) - 1). */
if (TREE_CODE (arg1) == LSHIFT_EXPR)
c = TREE_OPERAND (arg1, 0);
if (integer_pow2p (c) && tree_int_cst_sgn (c) > 0)
{
tree mask
= fold_build2_loc (loc, MINUS_EXPR, TREE_TYPE (arg1), arg1,
build_int_cst (TREE_TYPE (arg1), 1));
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not "
"occur when simplifying "
"X % (power of two)"),
WARN_STRICT_OVERFLOW_MISC);
return fold_build2_loc (loc, BIT_AND_EXPR, type,
fold_convert_loc (loc, type, arg0),
fold_convert_loc (loc, type, mask));
}
}
return NULL_TREE;
case LROTATE_EXPR:
case RROTATE_EXPR:
if (integer_all_onesp (arg0))
return omit_one_operand_loc (loc, type, arg0, arg1);
goto shift;
case RSHIFT_EXPR:
/* Optimize -1 >> x for arithmetic right shifts. */
if (integer_all_onesp (arg0) && !TYPE_UNSIGNED (type)
&& tree_expr_nonnegative_p (arg1))
return omit_one_operand_loc (loc, type, arg0, arg1);
/* ... fall through ... */
case LSHIFT_EXPR:
shift:
if (integer_zerop (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
if (integer_zerop (arg0))
return omit_one_operand_loc (loc, type, arg0, arg1);
/* Since negative shift count is not well-defined,
don't try to compute it in the compiler. */
if (TREE_CODE (arg1) == INTEGER_CST && tree_int_cst_sgn (arg1) < 0)
return NULL_TREE;
/* Turn (a OP c1) OP c2 into a OP (c1+c2). */
if (TREE_CODE (op0) == code && host_integerp (arg1, false)
&& TREE_INT_CST_LOW (arg1) < TYPE_PRECISION (type)
&& host_integerp (TREE_OPERAND (arg0, 1), false)
&& TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)) < TYPE_PRECISION (type))
{
HOST_WIDE_INT low = (TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1))
+ TREE_INT_CST_LOW (arg1));
/* Deal with a OP (c1 + c2) being undefined but (a OP c1) OP c2
being well defined. */
if (low >= TYPE_PRECISION (type))
{
if (code == LROTATE_EXPR || code == RROTATE_EXPR)
low = low % TYPE_PRECISION (type);
else if (TYPE_UNSIGNED (type) || code == LSHIFT_EXPR)
return omit_one_operand_loc (loc, type, build_int_cst (type, 0),
TREE_OPERAND (arg0, 0));
else
low = TYPE_PRECISION (type) - 1;
}
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0),
build_int_cst (type, low));
}
/* Transform (x >> c) << c into x & (-1<<c), or transform (x << c) >> c
into x & ((unsigned)-1 >> c) for unsigned types. */
if (((code == LSHIFT_EXPR && TREE_CODE (arg0) == RSHIFT_EXPR)
|| (TYPE_UNSIGNED (type)
&& code == RSHIFT_EXPR && TREE_CODE (arg0) == LSHIFT_EXPR))
&& host_integerp (arg1, false)
&& TREE_INT_CST_LOW (arg1) < TYPE_PRECISION (type)
&& host_integerp (TREE_OPERAND (arg0, 1), false)
&& TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)) < TYPE_PRECISION (type))
{
HOST_WIDE_INT low0 = TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1));
HOST_WIDE_INT low1 = TREE_INT_CST_LOW (arg1);
tree lshift;
tree arg00;
if (low0 == low1)
{
arg00 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
lshift = build_int_cst (type, -1);
lshift = int_const_binop (code, lshift, arg1);
return fold_build2_loc (loc, BIT_AND_EXPR, type, arg00, lshift);
}
}
/* Rewrite an LROTATE_EXPR by a constant into an
RROTATE_EXPR by a new constant. */
if (code == LROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST)
{
tree tem = build_int_cst (TREE_TYPE (arg1),
TYPE_PRECISION (type));
tem = const_binop (MINUS_EXPR, tem, arg1);
return fold_build2_loc (loc, RROTATE_EXPR, type, op0, tem);
}
/* If we have a rotate of a bit operation with the rotate count and
the second operand of the bit operation both constant,
permute the two operations. */
if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST
&& (TREE_CODE (arg0) == BIT_AND_EXPR
|| TREE_CODE (arg0) == BIT_IOR_EXPR
|| TREE_CODE (arg0) == BIT_XOR_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
return fold_build2_loc (loc, TREE_CODE (arg0), type,
fold_build2_loc (loc, code, type,
TREE_OPERAND (arg0, 0), arg1),
fold_build2_loc (loc, code, type,
TREE_OPERAND (arg0, 1), arg1));
/* Two consecutive rotates adding up to the precision of the
type can be ignored. */
if (code == RROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (arg0) == RROTATE_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& TREE_INT_CST_HIGH (arg1) == 0
&& TREE_INT_CST_HIGH (TREE_OPERAND (arg0, 1)) == 0
&& ((TREE_INT_CST_LOW (arg1)
+ TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)))
== (unsigned int) TYPE_PRECISION (type)))
return TREE_OPERAND (arg0, 0);
/* Fold (X & C2) << C1 into (X << C1) & (C2 << C1)
(X & C2) >> C1 into (X >> C1) & (C2 >> C1)
if the latter can be further optimized. */
if ((code == LSHIFT_EXPR || code == RSHIFT_EXPR)
&& TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
{
tree mask = fold_build2_loc (loc, code, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 1)),
arg1);
tree shift = fold_build2_loc (loc, code, type,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)),
arg1);
tem = fold_binary_loc (loc, BIT_AND_EXPR, type, shift, mask);
if (tem)
return tem;
}
return NULL_TREE;
case MIN_EXPR:
if (operand_equal_p (arg0, arg1, 0))
return omit_one_operand_loc (loc, type, arg0, arg1);
if (INTEGRAL_TYPE_P (type)
&& operand_equal_p (arg1, TYPE_MIN_VALUE (type), OEP_ONLY_CONST))
return omit_one_operand_loc (loc, type, arg1, arg0);
tem = fold_minmax (loc, MIN_EXPR, type, arg0, arg1);
if (tem)
return tem;
goto associate;
case MAX_EXPR:
if (operand_equal_p (arg0, arg1, 0))
return omit_one_operand_loc (loc, type, arg0, arg1);
if (INTEGRAL_TYPE_P (type)
&& TYPE_MAX_VALUE (type)
&& operand_equal_p (arg1, TYPE_MAX_VALUE (type), OEP_ONLY_CONST))
return omit_one_operand_loc (loc, type, arg1, arg0);
tem = fold_minmax (loc, MAX_EXPR, type, arg0, arg1);
if (tem)
return tem;
goto associate;
case TRUTH_ANDIF_EXPR:
/* Note that the operands of this must be ints
and their values must be 0 or 1.
("true" is a fixed value perhaps depending on the language.) */
/* If first arg is constant zero, return it. */
if (integer_zerop (arg0))
return fold_convert_loc (loc, type, arg0);
case TRUTH_AND_EXPR:
/* If either arg is constant true, drop it. */
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1));
if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1)
/* Preserve sequence points. */
&& (code != TRUTH_ANDIF_EXPR || ! TREE_SIDE_EFFECTS (arg0)))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* If second arg is constant zero, result is zero, but first arg
must be evaluated. */
if (integer_zerop (arg1))
return omit_one_operand_loc (loc, type, arg1, arg0);
/* Likewise for first arg, but note that only the TRUTH_AND_EXPR
case will be handled here. */
if (integer_zerop (arg0))
return omit_one_operand_loc (loc, type, arg0, arg1);
/* !X && X is always false. */
if (TREE_CODE (arg0) == TRUTH_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
return omit_one_operand_loc (loc, type, integer_zero_node, arg1);
/* X && !X is always false. */
if (TREE_CODE (arg1) == TRUTH_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
/* A < X && A + 1 > Y ==> A < X && A >= Y. Normally A + 1 > Y
means A >= Y && A != MAX, but in this case we know that
A < X <= MAX. */
if (!TREE_SIDE_EFFECTS (arg0)
&& !TREE_SIDE_EFFECTS (arg1))
{
tem = fold_to_nonsharp_ineq_using_bound (loc, arg0, arg1);
if (tem && !operand_equal_p (tem, arg0, 0))
return fold_build2_loc (loc, code, type, tem, arg1);
tem = fold_to_nonsharp_ineq_using_bound (loc, arg1, arg0);
if (tem && !operand_equal_p (tem, arg1, 0))
return fold_build2_loc (loc, code, type, arg0, tem);
}
if ((tem = fold_truth_andor (loc, code, type, arg0, arg1, op0, op1))
!= NULL_TREE)
return tem;
return NULL_TREE;
case TRUTH_ORIF_EXPR:
/* Note that the operands of this must be ints
and their values must be 0 or true.
("true" is a fixed value perhaps depending on the language.) */
/* If first arg is constant true, return it. */
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
return fold_convert_loc (loc, type, arg0);
case TRUTH_OR_EXPR:
/* If either arg is constant zero, drop it. */
if (TREE_CODE (arg0) == INTEGER_CST && integer_zerop (arg0))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg1));
if (TREE_CODE (arg1) == INTEGER_CST && integer_zerop (arg1)
/* Preserve sequence points. */
&& (code != TRUTH_ORIF_EXPR || ! TREE_SIDE_EFFECTS (arg0)))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* If second arg is constant true, result is true, but we must
evaluate first arg. */
if (TREE_CODE (arg1) == INTEGER_CST && ! integer_zerop (arg1))
return omit_one_operand_loc (loc, type, arg1, arg0);
/* Likewise for first arg, but note this only occurs here for
TRUTH_OR_EXPR. */
if (TREE_CODE (arg0) == INTEGER_CST && ! integer_zerop (arg0))
return omit_one_operand_loc (loc, type, arg0, arg1);
/* !X || X is always true. */
if (TREE_CODE (arg0) == TRUTH_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
return omit_one_operand_loc (loc, type, integer_one_node, arg1);
/* X || !X is always true. */
if (TREE_CODE (arg1) == TRUTH_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
/* (X && !Y) || (!X && Y) is X ^ Y */
if (TREE_CODE (arg0) == TRUTH_AND_EXPR
&& TREE_CODE (arg1) == TRUTH_AND_EXPR)
{
tree a0, a1, l0, l1, n0, n1;
a0 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
a1 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
l0 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
l1 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
n0 = fold_build1_loc (loc, TRUTH_NOT_EXPR, type, l0);
n1 = fold_build1_loc (loc, TRUTH_NOT_EXPR, type, l1);
if ((operand_equal_p (n0, a0, 0)
&& operand_equal_p (n1, a1, 0))
|| (operand_equal_p (n0, a1, 0)
&& operand_equal_p (n1, a0, 0)))
return fold_build2_loc (loc, TRUTH_XOR_EXPR, type, l0, n1);
}
if ((tem = fold_truth_andor (loc, code, type, arg0, arg1, op0, op1))
!= NULL_TREE)
return tem;
return NULL_TREE;
case TRUTH_XOR_EXPR:
/* If the second arg is constant zero, drop it. */
if (integer_zerop (arg1))
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* If the second arg is constant true, this is a logical inversion. */
if (integer_onep (arg1))
{
/* Only call invert_truthvalue if operand is a truth value. */
if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE)
tem = fold_build1_loc (loc, TRUTH_NOT_EXPR, TREE_TYPE (arg0), arg0);
else
tem = invert_truthvalue_loc (loc, arg0);
return non_lvalue_loc (loc, fold_convert_loc (loc, type, tem));
}
/* Identical arguments cancel to zero. */
if (operand_equal_p (arg0, arg1, 0))
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
/* !X ^ X is always true. */
if (TREE_CODE (arg0) == TRUTH_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
return omit_one_operand_loc (loc, type, integer_one_node, arg1);
/* X ^ !X is always true. */
if (TREE_CODE (arg1) == TRUTH_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
return NULL_TREE;
case EQ_EXPR:
case NE_EXPR:
STRIP_NOPS (arg0);
STRIP_NOPS (arg1);
tem = fold_comparison (loc, code, type, op0, op1);
if (tem != NULL_TREE)
return tem;
/* bool_var != 0 becomes bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1)
&& code == NE_EXPR)
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* bool_var == 1 becomes bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1)
&& code == EQ_EXPR)
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* bool_var != 1 becomes !bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1)
&& code == NE_EXPR)
return fold_convert_loc (loc, type,
fold_build1_loc (loc, TRUTH_NOT_EXPR,
TREE_TYPE (arg0), arg0));
/* bool_var == 0 becomes !bool_var. */
if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1)
&& code == EQ_EXPR)
return fold_convert_loc (loc, type,
fold_build1_loc (loc, TRUTH_NOT_EXPR,
TREE_TYPE (arg0), arg0));
/* !exp != 0 becomes !exp */
if (TREE_CODE (arg0) == TRUTH_NOT_EXPR && integer_zerop (arg1)
&& code == NE_EXPR)
return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
/* If this is an equality comparison of the address of two non-weak,
unaliased symbols neither of which are extern (since we do not
have access to attributes for externs), then we know the result. */
if (TREE_CODE (arg0) == ADDR_EXPR
&& VAR_OR_FUNCTION_DECL_P (TREE_OPERAND (arg0, 0))
&& ! DECL_WEAK (TREE_OPERAND (arg0, 0))
&& ! lookup_attribute ("alias",
DECL_ATTRIBUTES (TREE_OPERAND (arg0, 0)))
&& ! DECL_EXTERNAL (TREE_OPERAND (arg0, 0))
&& TREE_CODE (arg1) == ADDR_EXPR
&& VAR_OR_FUNCTION_DECL_P (TREE_OPERAND (arg1, 0))
&& ! DECL_WEAK (TREE_OPERAND (arg1, 0))
&& ! lookup_attribute ("alias",
DECL_ATTRIBUTES (TREE_OPERAND (arg1, 0)))
&& ! DECL_EXTERNAL (TREE_OPERAND (arg1, 0)))
{
/* We know that we're looking at the address of two
non-weak, unaliased, static _DECL nodes.
It is both wasteful and incorrect to call operand_equal_p
to compare the two ADDR_EXPR nodes. It is wasteful in that
all we need to do is test pointer equality for the arguments
to the two ADDR_EXPR nodes. It is incorrect to use
operand_equal_p as that function is NOT equivalent to a
C equality test. It can in fact return false for two
objects which would test as equal using the C equality
operator. */
bool equal = TREE_OPERAND (arg0, 0) == TREE_OPERAND (arg1, 0);
return constant_boolean_node (equal
? code == EQ_EXPR : code != EQ_EXPR,
type);
}
/* If this is an EQ or NE comparison of a constant with a PLUS_EXPR or
a MINUS_EXPR of a constant, we can convert it into a comparison with
a revised constant as long as no overflow occurs. */
if (TREE_CODE (arg1) == INTEGER_CST
&& (TREE_CODE (arg0) == PLUS_EXPR
|| TREE_CODE (arg0) == MINUS_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR
? MINUS_EXPR : PLUS_EXPR,
fold_convert_loc (loc, TREE_TYPE (arg0),
arg1),
TREE_OPERAND (arg0, 1)))
&& !TREE_OVERFLOW (tem))
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem);
/* Similarly for a NEGATE_EXPR. */
if (TREE_CODE (arg0) == NEGATE_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& 0 != (tem = negate_expr (fold_convert_loc (loc, TREE_TYPE (arg0),
arg1)))
&& TREE_CODE (tem) == INTEGER_CST
&& !TREE_OVERFLOW (tem))
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), tem);
/* Similarly for a BIT_XOR_EXPR; X ^ C1 == C2 is X == (C1 ^ C2). */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0),
fold_build2_loc (loc, BIT_XOR_EXPR, TREE_TYPE (arg0),
fold_convert_loc (loc,
TREE_TYPE (arg0),
arg1),
TREE_OPERAND (arg0, 1)));
/* Transform comparisons of the form X +- Y CMP X to Y CMP 0. */
if ((TREE_CODE (arg0) == PLUS_EXPR
|| TREE_CODE (arg0) == POINTER_PLUS_EXPR
|| TREE_CODE (arg0) == MINUS_EXPR)
&& operand_equal_p (tree_strip_nop_conversions (TREE_OPERAND (arg0,
0)),
arg1, 0)
&& (INTEGRAL_TYPE_P (TREE_TYPE (arg0))
|| POINTER_TYPE_P (TREE_TYPE (arg0))))
{
tree val = TREE_OPERAND (arg0, 1);
return omit_two_operands_loc (loc, type,
fold_build2_loc (loc, code, type,
val,
build_int_cst (TREE_TYPE (val),
0)),
TREE_OPERAND (arg0, 0), arg1);
}
/* Transform comparisons of the form C - X CMP X if C % 2 == 1. */
if (TREE_CODE (arg0) == MINUS_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == INTEGER_CST
&& operand_equal_p (tree_strip_nop_conversions (TREE_OPERAND (arg0,
1)),
arg1, 0)
&& (TREE_INT_CST_LOW (TREE_OPERAND (arg0, 0)) & 1) == 1)
{
return omit_two_operands_loc (loc, type,
code == NE_EXPR
? boolean_true_node : boolean_false_node,
TREE_OPERAND (arg0, 1), arg1);
}
/* If we have X - Y == 0, we can convert that to X == Y and similarly
for !=. Don't do this for ordered comparisons due to overflow. */
if (TREE_CODE (arg0) == MINUS_EXPR
&& integer_zerop (arg1))
return fold_build2_loc (loc, code, type,
TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 1));
/* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0. */
if (TREE_CODE (arg0) == ABS_EXPR
&& (integer_zerop (arg1) || real_zerop (arg1)))
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0), arg1);
/* If this is an EQ or NE comparison with zero and ARG0 is
(1 << foo) & bar, convert it to (bar >> foo) & 1. Both require
two operations, but the latter can be done in one less insn
on machines that have only two-operand insns or on which a
constant cannot be the first operand. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_zerop (arg1))
{
tree arg00 = TREE_OPERAND (arg0, 0);
tree arg01 = TREE_OPERAND (arg0, 1);
if (TREE_CODE (arg00) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg00, 0)))
{
tree tem = fold_build2_loc (loc, RSHIFT_EXPR, TREE_TYPE (arg00),
arg01, TREE_OPERAND (arg00, 1));
tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0), tem,
build_int_cst (TREE_TYPE (arg0), 1));
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, TREE_TYPE (arg1), tem),
arg1);
}
else if (TREE_CODE (arg01) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg01, 0)))
{
tree tem = fold_build2_loc (loc, RSHIFT_EXPR, TREE_TYPE (arg01),
arg00, TREE_OPERAND (arg01, 1));
tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0), tem,
build_int_cst (TREE_TYPE (arg0), 1));
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, TREE_TYPE (arg1), tem),
arg1);
}
}
/* If this is an NE or EQ comparison of zero against the result of a
signed MOD operation whose second operand is a power of 2, make
the MOD operation unsigned since it is simpler and equivalent. */
if (integer_zerop (arg1)
&& !TYPE_UNSIGNED (TREE_TYPE (arg0))
&& (TREE_CODE (arg0) == TRUNC_MOD_EXPR
|| TREE_CODE (arg0) == CEIL_MOD_EXPR
|| TREE_CODE (arg0) == FLOOR_MOD_EXPR
|| TREE_CODE (arg0) == ROUND_MOD_EXPR)
&& integer_pow2p (TREE_OPERAND (arg0, 1)))
{
tree newtype = unsigned_type_for (TREE_TYPE (arg0));
tree newmod = fold_build2_loc (loc, TREE_CODE (arg0), newtype,
fold_convert_loc (loc, newtype,
TREE_OPERAND (arg0, 0)),
fold_convert_loc (loc, newtype,
TREE_OPERAND (arg0, 1)));
return fold_build2_loc (loc, code, type, newmod,
fold_convert_loc (loc, newtype, arg1));
}
/* Fold ((X >> C1) & C2) == 0 and ((X >> C1) & C2) != 0 where
C1 is a valid shift constant, and C2 is a power of two, i.e.
a single bit. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == RSHIFT_EXPR
&& TREE_CODE (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1))
== INTEGER_CST
&& integer_pow2p (TREE_OPERAND (arg0, 1))
&& integer_zerop (arg1))
{
tree itype = TREE_TYPE (arg0);
unsigned HOST_WIDE_INT prec = TYPE_PRECISION (itype);
tree arg001 = TREE_OPERAND (TREE_OPERAND (arg0, 0), 1);
/* Check for a valid shift count. */
if (TREE_INT_CST_HIGH (arg001) == 0
&& TREE_INT_CST_LOW (arg001) < prec)
{
tree arg01 = TREE_OPERAND (arg0, 1);
tree arg000 = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0);
unsigned HOST_WIDE_INT log2 = tree_log2 (arg01);
/* If (C2 << C1) doesn't overflow, then ((X >> C1) & C2) != 0
can be rewritten as (X & (C2 << C1)) != 0. */
if ((log2 + TREE_INT_CST_LOW (arg001)) < prec)
{
tem = fold_build2_loc (loc, LSHIFT_EXPR, itype, arg01, arg001);
tem = fold_build2_loc (loc, BIT_AND_EXPR, itype, arg000, tem);
return fold_build2_loc (loc, code, type, tem,
fold_convert_loc (loc, itype, arg1));
}
/* Otherwise, for signed (arithmetic) shifts,
((X >> C1) & C2) != 0 is rewritten as X < 0, and
((X >> C1) & C2) == 0 is rewritten as X >= 0. */
else if (!TYPE_UNSIGNED (itype))
return fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR, type,
arg000, build_int_cst (itype, 0));
/* Otherwise, of unsigned (logical) shifts,
((X >> C1) & C2) != 0 is rewritten as (X,false), and
((X >> C1) & C2) == 0 is rewritten as (X,true). */
else
return omit_one_operand_loc (loc, type,
code == EQ_EXPR ? integer_one_node
: integer_zero_node,
arg000);
}
}
/* If we have (A & C) == C where C is a power of 2, convert this into
(A & C) != 0. Similarly for NE_EXPR. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_pow2p (TREE_OPERAND (arg0, 1))
&& operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
return fold_build2_loc (loc, code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type,
arg0, fold_convert_loc (loc, TREE_TYPE (arg0),
integer_zero_node));
/* If we have (A & C) != 0 or (A & C) == 0 and C is the sign
bit, then fold the expression into A < 0 or A >= 0. */
tem = fold_single_bit_test_into_sign_test (loc, code, arg0, arg1, type);
if (tem)
return tem;
/* If we have (A & C) == D where D & ~C != 0, convert this into 0.
Similarly for NE_EXPR. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
{
tree notc = fold_build1_loc (loc, BIT_NOT_EXPR,
TREE_TYPE (TREE_OPERAND (arg0, 1)),
TREE_OPERAND (arg0, 1));
tree dandnotc
= fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0),
fold_convert_loc (loc, TREE_TYPE (arg0), arg1),
notc);
tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node;
if (integer_nonzerop (dandnotc))
return omit_one_operand_loc (loc, type, rslt, arg0);
}
/* If we have (A | C) == D where C & ~D != 0, convert this into 0.
Similarly for NE_EXPR. */
if (TREE_CODE (arg0) == BIT_IOR_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
{
tree notd = fold_build1_loc (loc, BIT_NOT_EXPR, TREE_TYPE (arg1), arg1);
tree candnotd
= fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0),
TREE_OPERAND (arg0, 1),
fold_convert_loc (loc, TREE_TYPE (arg0), notd));
tree rslt = code == EQ_EXPR ? integer_zero_node : integer_one_node;
if (integer_nonzerop (candnotd))
return omit_one_operand_loc (loc, type, rslt, arg0);
}
/* If this is a comparison of a field, we may be able to simplify it. */
if ((TREE_CODE (arg0) == COMPONENT_REF
|| TREE_CODE (arg0) == BIT_FIELD_REF)
/* Handle the constant case even without -O
to make sure the warnings are given. */
&& (optimize || TREE_CODE (arg1) == INTEGER_CST))
{
t1 = optimize_bit_field_compare (loc, code, type, arg0, arg1);
if (t1)
return t1;
}
/* Optimize comparisons of strlen vs zero to a compare of the
first character of the string vs zero. To wit,
strlen(ptr) == 0 => *ptr == 0
strlen(ptr) != 0 => *ptr != 0
Other cases should reduce to one of these two (or a constant)
due to the return value of strlen being unsigned. */
if (TREE_CODE (arg0) == CALL_EXPR
&& integer_zerop (arg1))
{
tree fndecl = get_callee_fndecl (arg0);
if (fndecl
&& DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
&& DECL_FUNCTION_CODE (fndecl) == BUILT_IN_STRLEN
&& call_expr_nargs (arg0) == 1
&& TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (arg0, 0))) == POINTER_TYPE)
{
tree iref = build_fold_indirect_ref_loc (loc,
CALL_EXPR_ARG (arg0, 0));
return fold_build2_loc (loc, code, type, iref,
build_int_cst (TREE_TYPE (iref), 0));
}
}
/* Fold (X >> C) != 0 into X < 0 if C is one less than the width
of X. Similarly fold (X >> C) == 0 into X >= 0. */
if (TREE_CODE (arg0) == RSHIFT_EXPR
&& integer_zerop (arg1)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
{
tree arg00 = TREE_OPERAND (arg0, 0);
tree arg01 = TREE_OPERAND (arg0, 1);
tree itype = TREE_TYPE (arg00);
if (TREE_INT_CST_HIGH (arg01) == 0
&& TREE_INT_CST_LOW (arg01)
== (unsigned HOST_WIDE_INT) (TYPE_PRECISION (itype) - 1))
{
if (TYPE_UNSIGNED (itype))
{
itype = signed_type_for (itype);
arg00 = fold_convert_loc (loc, itype, arg00);
}
return fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR,
type, arg00, build_zero_cst (itype));
}
}
/* (X ^ Y) == 0 becomes X == Y, and (X ^ Y) != 0 becomes X != Y. */
if (integer_zerop (arg1)
&& TREE_CODE (arg0) == BIT_XOR_EXPR)
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg0, 1));
/* (X ^ Y) == Y becomes X == 0. We know that Y has no side-effects. */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0),
build_zero_cst (TREE_TYPE (arg0)));
/* Likewise (X ^ Y) == X becomes Y == 0. X has no side-effects. */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
&& reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 1),
build_zero_cst (TREE_TYPE (arg0)));
/* (X ^ C1) op C2 can be rewritten as X op (C1 ^ C2). */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
return fold_build2_loc (loc, code, type, TREE_OPERAND (arg0, 0),
fold_build2_loc (loc, BIT_XOR_EXPR, TREE_TYPE (arg1),
TREE_OPERAND (arg0, 1), arg1));
/* Fold (~X & C) == 0 into (X & C) != 0 and (~X & C) != 0 into
(X & C) == 0 when C is a single bit. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_NOT_EXPR
&& integer_zerop (arg1)
&& integer_pow2p (TREE_OPERAND (arg0, 1)))
{
tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0),
TREE_OPERAND (TREE_OPERAND (arg0, 0), 0),
TREE_OPERAND (arg0, 1));
return fold_build2_loc (loc, code == EQ_EXPR ? NE_EXPR : EQ_EXPR,
type, tem,
fold_convert_loc (loc, TREE_TYPE (arg0),
arg1));
}
/* Fold ((X & C) ^ C) eq/ne 0 into (X & C) ne/eq 0, when the
constant C is a power of two, i.e. a single bit. */
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_AND_EXPR
&& integer_zerop (arg1)
&& integer_pow2p (TREE_OPERAND (arg0, 1))
&& operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1),
TREE_OPERAND (arg0, 1), OEP_ONLY_CONST))
{
tree arg00 = TREE_OPERAND (arg0, 0);
return fold_build2_loc (loc, code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type,
arg00, build_int_cst (TREE_TYPE (arg00), 0));
}
/* Likewise, fold ((X ^ C) & C) eq/ne 0 into (X & C) ne/eq 0,
when is C is a power of two, i.e. a single bit. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_XOR_EXPR
&& integer_zerop (arg1)
&& integer_pow2p (TREE_OPERAND (arg0, 1))
&& operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1),
TREE_OPERAND (arg0, 1), OEP_ONLY_CONST))
{
tree arg000 = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0);
tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg000),
arg000, TREE_OPERAND (arg0, 1));
return fold_build2_loc (loc, code == EQ_EXPR ? NE_EXPR : EQ_EXPR, type,
tem, build_int_cst (TREE_TYPE (tem), 0));
}
if (integer_zerop (arg1)
&& tree_expr_nonzero_p (arg0))
{
tree res = constant_boolean_node (code==NE_EXPR, type);
return omit_one_operand_loc (loc, type, res, arg0);
}
/* Fold -X op -Y as X op Y, where op is eq/ne. */
if (TREE_CODE (arg0) == NEGATE_EXPR
&& TREE_CODE (arg1) == NEGATE_EXPR)
return fold_build2_loc (loc, code, type,
TREE_OPERAND (arg0, 0),
fold_convert_loc (loc, TREE_TYPE (arg0),
TREE_OPERAND (arg1, 0)));
/* Fold (X & C) op (Y & C) as (X ^ Y) & C op 0", and symmetries. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == BIT_AND_EXPR)
{
tree arg00 = TREE_OPERAND (arg0, 0);
tree arg01 = TREE_OPERAND (arg0, 1);
tree arg10 = TREE_OPERAND (arg1, 0);
tree arg11 = TREE_OPERAND (arg1, 1);
tree itype = TREE_TYPE (arg0);
if (operand_equal_p (arg01, arg11, 0))
return fold_build2_loc (loc, code, type,
fold_build2_loc (loc, BIT_AND_EXPR, itype,
fold_build2_loc (loc,
BIT_XOR_EXPR, itype,
arg00, arg10),
arg01),
build_zero_cst (itype));
if (operand_equal_p (arg01, arg10, 0))
return fold_build2_loc (loc, code, type,
fold_build2_loc (loc, BIT_AND_EXPR, itype,
fold_build2_loc (loc,
BIT_XOR_EXPR, itype,
arg00, arg11),
arg01),
build_zero_cst (itype));
if (operand_equal_p (arg00, arg11, 0))
return fold_build2_loc (loc, code, type,
fold_build2_loc (loc, BIT_AND_EXPR, itype,
fold_build2_loc (loc,
BIT_XOR_EXPR, itype,
arg01, arg10),
arg00),
build_zero_cst (itype));
if (operand_equal_p (arg00, arg10, 0))
return fold_build2_loc (loc, code, type,
fold_build2_loc (loc, BIT_AND_EXPR, itype,
fold_build2_loc (loc,
BIT_XOR_EXPR, itype,
arg01, arg11),
arg00),
build_zero_cst (itype));
}
if (TREE_CODE (arg0) == BIT_XOR_EXPR
&& TREE_CODE (arg1) == BIT_XOR_EXPR)
{
tree arg00 = TREE_OPERAND (arg0, 0);
tree arg01 = TREE_OPERAND (arg0, 1);
tree arg10 = TREE_OPERAND (arg1, 0);
tree arg11 = TREE_OPERAND (arg1, 1);
tree itype = TREE_TYPE (arg0);
/* Optimize (X ^ Z) op (Y ^ Z) as X op Y, and symmetries.
operand_equal_p guarantees no side-effects so we don't need
to use omit_one_operand on Z. */
if (operand_equal_p (arg01, arg11, 0))
return fold_build2_loc (loc, code, type, arg00,
fold_convert_loc (loc, TREE_TYPE (arg00),
arg10));
if (operand_equal_p (arg01, arg10, 0))
return fold_build2_loc (loc, code, type, arg00,
fold_convert_loc (loc, TREE_TYPE (arg00),
arg11));
if (operand_equal_p (arg00, arg11, 0))
return fold_build2_loc (loc, code, type, arg01,
fold_convert_loc (loc, TREE_TYPE (arg01),
arg10));
if (operand_equal_p (arg00, arg10, 0))
return fold_build2_loc (loc, code, type, arg01,
fold_convert_loc (loc, TREE_TYPE (arg01),
arg11));
/* Optimize (X ^ C1) op (Y ^ C2) as (X ^ (C1 ^ C2)) op Y. */
if (TREE_CODE (arg01) == INTEGER_CST
&& TREE_CODE (arg11) == INTEGER_CST)
{
tem = fold_build2_loc (loc, BIT_XOR_EXPR, itype, arg01,
fold_convert_loc (loc, itype, arg11));
tem = fold_build2_loc (loc, BIT_XOR_EXPR, itype, arg00, tem);
return fold_build2_loc (loc, code, type, tem,
fold_convert_loc (loc, itype, arg10));
}
}
/* Attempt to simplify equality/inequality comparisons of complex
values. Only lower the comparison if the result is known or
can be simplified to a single scalar comparison. */
if ((TREE_CODE (arg0) == COMPLEX_EXPR
|| TREE_CODE (arg0) == COMPLEX_CST)
&& (TREE_CODE (arg1) == COMPLEX_EXPR
|| TREE_CODE (arg1) == COMPLEX_CST))
{
tree real0, imag0, real1, imag1;
tree rcond, icond;
if (TREE_CODE (arg0) == COMPLEX_EXPR)
{
real0 = TREE_OPERAND (arg0, 0);
imag0 = TREE_OPERAND (arg0, 1);
}
else
{
real0 = TREE_REALPART (arg0);
imag0 = TREE_IMAGPART (arg0);
}
if (TREE_CODE (arg1) == COMPLEX_EXPR)
{
real1 = TREE_OPERAND (arg1, 0);
imag1 = TREE_OPERAND (arg1, 1);
}
else
{
real1 = TREE_REALPART (arg1);
imag1 = TREE_IMAGPART (arg1);
}
rcond = fold_binary_loc (loc, code, type, real0, real1);
if (rcond && TREE_CODE (rcond) == INTEGER_CST)
{
if (integer_zerop (rcond))
{
if (code == EQ_EXPR)
return omit_two_operands_loc (loc, type, boolean_false_node,
imag0, imag1);
return fold_build2_loc (loc, NE_EXPR, type, imag0, imag1);
}
else
{
if (code == NE_EXPR)
return omit_two_operands_loc (loc, type, boolean_true_node,
imag0, imag1);
return fold_build2_loc (loc, EQ_EXPR, type, imag0, imag1);
}
}
icond = fold_binary_loc (loc, code, type, imag0, imag1);
if (icond && TREE_CODE (icond) == INTEGER_CST)
{
if (integer_zerop (icond))
{
if (code == EQ_EXPR)
return omit_two_operands_loc (loc, type, boolean_false_node,
real0, real1);
return fold_build2_loc (loc, NE_EXPR, type, real0, real1);
}
else
{
if (code == NE_EXPR)
return omit_two_operands_loc (loc, type, boolean_true_node,
real0, real1);
return fold_build2_loc (loc, EQ_EXPR, type, real0, real1);
}
}
}
return NULL_TREE;
case LT_EXPR:
case GT_EXPR:
case LE_EXPR:
case GE_EXPR:
tem = fold_comparison (loc, code, type, op0, op1);
if (tem != NULL_TREE)
return tem;
/* Transform comparisons of the form X +- C CMP X. */
if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
&& ((TREE_CODE (TREE_OPERAND (arg0, 1)) == REAL_CST
&& !HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))))
|| (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
&& TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))))
{
tree arg01 = TREE_OPERAND (arg0, 1);
enum tree_code code0 = TREE_CODE (arg0);
int is_positive;
if (TREE_CODE (arg01) == REAL_CST)
is_positive = REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg01)) ? -1 : 1;
else
is_positive = tree_int_cst_sgn (arg01);
/* (X - c) > X becomes false. */
if (code == GT_EXPR
&& ((code0 == MINUS_EXPR && is_positive >= 0)
|| (code0 == PLUS_EXPR && is_positive <= 0)))
{
if (TREE_CODE (arg01) == INTEGER_CST
&& TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))
fold_overflow_warning (("assuming signed overflow does not "
"occur when assuming that (X - c) > X "
"is always false"),
WARN_STRICT_OVERFLOW_ALL);
return constant_boolean_node (0, type);
}
/* Likewise (X + c) < X becomes false. */
if (code == LT_EXPR
&& ((code0 == PLUS_EXPR && is_positive >= 0)
|| (code0 == MINUS_EXPR && is_positive <= 0)))
{
if (TREE_CODE (arg01) == INTEGER_CST
&& TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))
fold_overflow_warning (("assuming signed overflow does not "
"occur when assuming that "
"(X + c) < X is always false"),
WARN_STRICT_OVERFLOW_ALL);
return constant_boolean_node (0, type);
}
/* Convert (X - c) <= X to true. */
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))
&& code == LE_EXPR
&& ((code0 == MINUS_EXPR && is_positive >= 0)
|| (code0 == PLUS_EXPR && is_positive <= 0)))
{
if (TREE_CODE (arg01) == INTEGER_CST
&& TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))
fold_overflow_warning (("assuming signed overflow does not "
"occur when assuming that "
"(X - c) <= X is always true"),
WARN_STRICT_OVERFLOW_ALL);
return constant_boolean_node (1, type);
}
/* Convert (X + c) >= X to true. */
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg1)))
&& code == GE_EXPR
&& ((code0 == PLUS_EXPR && is_positive >= 0)
|| (code0 == MINUS_EXPR && is_positive <= 0)))
{
if (TREE_CODE (arg01) == INTEGER_CST
&& TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))
fold_overflow_warning (("assuming signed overflow does not "
"occur when assuming that "
"(X + c) >= X is always true"),
WARN_STRICT_OVERFLOW_ALL);
return constant_boolean_node (1, type);
}
if (TREE_CODE (arg01) == INTEGER_CST)
{
/* Convert X + c > X and X - c < X to true for integers. */
if (code == GT_EXPR
&& ((code0 == PLUS_EXPR && is_positive > 0)
|| (code0 == MINUS_EXPR && is_positive < 0)))
{
if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))
fold_overflow_warning (("assuming signed overflow does "
"not occur when assuming that "
"(X + c) > X is always true"),
WARN_STRICT_OVERFLOW_ALL);
return constant_boolean_node (1, type);
}
if (code == LT_EXPR
&& ((code0 == MINUS_EXPR && is_positive > 0)
|| (code0 == PLUS_EXPR && is_positive < 0)))
{
if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))
fold_overflow_warning (("assuming signed overflow does "
"not occur when assuming that "
"(X - c) < X is always true"),
WARN_STRICT_OVERFLOW_ALL);
return constant_boolean_node (1, type);
}
/* Convert X + c <= X and X - c >= X to false for integers. */
if (code == LE_EXPR
&& ((code0 == PLUS_EXPR && is_positive > 0)
|| (code0 == MINUS_EXPR && is_positive < 0)))
{
if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))
fold_overflow_warning (("assuming signed overflow does "
"not occur when assuming that "
"(X + c) <= X is always false"),
WARN_STRICT_OVERFLOW_ALL);
return constant_boolean_node (0, type);
}
if (code == GE_EXPR
&& ((code0 == MINUS_EXPR && is_positive > 0)
|| (code0 == PLUS_EXPR && is_positive < 0)))
{
if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))
fold_overflow_warning (("assuming signed overflow does "
"not occur when assuming that "
"(X - c) >= X is always false"),
WARN_STRICT_OVERFLOW_ALL);
return constant_boolean_node (0, type);
}
}
}
/* Comparisons with the highest or lowest possible integer of
the specified precision will have known values. */
{
tree arg1_type = TREE_TYPE (arg1);
unsigned int width = TYPE_PRECISION (arg1_type);
if (TREE_CODE (arg1) == INTEGER_CST
&& width <= HOST_BITS_PER_DOUBLE_INT
&& (INTEGRAL_TYPE_P (arg1_type) || POINTER_TYPE_P (arg1_type)))
{
HOST_WIDE_INT signed_max_hi;
unsigned HOST_WIDE_INT signed_max_lo;
unsigned HOST_WIDE_INT max_hi, max_lo, min_hi, min_lo;
if (width <= HOST_BITS_PER_WIDE_INT)
{
signed_max_lo = ((unsigned HOST_WIDE_INT) 1 << (width - 1))
- 1;
signed_max_hi = 0;
max_hi = 0;
if (TYPE_UNSIGNED (arg1_type))
{
max_lo = ((unsigned HOST_WIDE_INT) 2 << (width - 1)) - 1;
min_lo = 0;
min_hi = 0;
}
else
{
max_lo = signed_max_lo;
min_lo = ((unsigned HOST_WIDE_INT) -1 << (width - 1));
min_hi = -1;
}
}
else
{
width -= HOST_BITS_PER_WIDE_INT;
signed_max_lo = -1;
signed_max_hi = ((unsigned HOST_WIDE_INT) 1 << (width - 1))
- 1;
max_lo = -1;
min_lo = 0;
if (TYPE_UNSIGNED (arg1_type))
{
max_hi = ((unsigned HOST_WIDE_INT) 2 << (width - 1)) - 1;
min_hi = 0;
}
else
{
max_hi = signed_max_hi;
min_hi = ((unsigned HOST_WIDE_INT) -1 << (width - 1));
}
}
if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1) == max_hi
&& TREE_INT_CST_LOW (arg1) == max_lo)
switch (code)
{
case GT_EXPR:
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
case GE_EXPR:
return fold_build2_loc (loc, EQ_EXPR, type, op0, op1);
case LE_EXPR:
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
case LT_EXPR:
return fold_build2_loc (loc, NE_EXPR, type, op0, op1);
/* The GE_EXPR and LT_EXPR cases above are not normally
reached because of previous transformations. */
default:
break;
}
else if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1)
== max_hi
&& TREE_INT_CST_LOW (arg1) == max_lo - 1)
switch (code)
{
case GT_EXPR:
arg1 = const_binop (PLUS_EXPR, arg1,
build_int_cst (TREE_TYPE (arg1), 1));
return fold_build2_loc (loc, EQ_EXPR, type,
fold_convert_loc (loc,
TREE_TYPE (arg1), arg0),
arg1);
case LE_EXPR:
arg1 = const_binop (PLUS_EXPR, arg1,
build_int_cst (TREE_TYPE (arg1), 1));
return fold_build2_loc (loc, NE_EXPR, type,
fold_convert_loc (loc, TREE_TYPE (arg1),
arg0),
arg1);
default:
break;
}
else if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1)
== min_hi
&& TREE_INT_CST_LOW (arg1) == min_lo)
switch (code)
{
case LT_EXPR:
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
case LE_EXPR:
return fold_build2_loc (loc, EQ_EXPR, type, op0, op1);
case GE_EXPR:
return omit_one_operand_loc (loc, type, integer_one_node, arg0);
case GT_EXPR:
return fold_build2_loc (loc, NE_EXPR, type, op0, op1);
default:
break;
}
else if ((unsigned HOST_WIDE_INT) TREE_INT_CST_HIGH (arg1)
== min_hi
&& TREE_INT_CST_LOW (arg1) == min_lo + 1)
switch (code)
{
case GE_EXPR:
arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node);
return fold_build2_loc (loc, NE_EXPR, type,
fold_convert_loc (loc,
TREE_TYPE (arg1), arg0),
arg1);
case LT_EXPR:
arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node);
return fold_build2_loc (loc, EQ_EXPR, type,
fold_convert_loc (loc, TREE_TYPE (arg1),
arg0),
arg1);
default:
break;
}
else if (TREE_INT_CST_HIGH (arg1) == signed_max_hi
&& TREE_INT_CST_LOW (arg1) == signed_max_lo
&& TYPE_UNSIGNED (arg1_type)
/* We will flip the signedness of the comparison operator
associated with the mode of arg1, so the sign bit is
specified by this mode. Check that arg1 is the signed
max associated with this sign bit. */
&& width == GET_MODE_BITSIZE (TYPE_MODE (arg1_type))
/* signed_type does not work on pointer types. */
&& INTEGRAL_TYPE_P (arg1_type))
{
/* The following case also applies to X < signed_max+1
and X >= signed_max+1 because previous transformations. */
if (code == LE_EXPR || code == GT_EXPR)
{
tree st;
st = signed_type_for (TREE_TYPE (arg1));
return fold_build2_loc (loc,
code == LE_EXPR ? GE_EXPR : LT_EXPR,
type, fold_convert_loc (loc, st, arg0),
build_int_cst (st, 0));
}
}
}
}
/* If we are comparing an ABS_EXPR with a constant, we can
convert all the cases into explicit comparisons, but they may
well not be faster than doing the ABS and one comparison.
But ABS (X) <= C is a range comparison, which becomes a subtraction
and a comparison, and is probably faster. */
if (code == LE_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
&& TREE_CODE (arg0) == ABS_EXPR
&& ! TREE_SIDE_EFFECTS (arg0)
&& (0 != (tem = negate_expr (arg1)))
&& TREE_CODE (tem) == INTEGER_CST
&& !TREE_OVERFLOW (tem))
return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type,
build2 (GE_EXPR, type,
TREE_OPERAND (arg0, 0), tem),
build2 (LE_EXPR, type,
TREE_OPERAND (arg0, 0), arg1));
/* Convert ABS_EXPR<x> >= 0 to true. */
strict_overflow_p = false;
if (code == GE_EXPR
&& (integer_zerop (arg1)
|| (! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
&& real_zerop (arg1)))
&& tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))
{
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not occur "
"when simplifying comparison of "
"absolute value and zero"),
WARN_STRICT_OVERFLOW_CONDITIONAL);
return omit_one_operand_loc (loc, type,
constant_boolean_node (true, type),
arg0);
}
/* Convert ABS_EXPR<x> < 0 to false. */
strict_overflow_p = false;
if (code == LT_EXPR
&& (integer_zerop (arg1) || real_zerop (arg1))
&& tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))
{
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not occur "
"when simplifying comparison of "
"absolute value and zero"),
WARN_STRICT_OVERFLOW_CONDITIONAL);
return omit_one_operand_loc (loc, type,
constant_boolean_node (false, type),
arg0);
}
/* If X is unsigned, convert X < (1 << Y) into X >> Y == 0
and similarly for >= into !=. */
if ((code == LT_EXPR || code == GE_EXPR)
&& TYPE_UNSIGNED (TREE_TYPE (arg0))
&& TREE_CODE (arg1) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg1, 0)))
return build2_loc (loc, code == LT_EXPR ? EQ_EXPR : NE_EXPR, type,
build2 (RSHIFT_EXPR, TREE_TYPE (arg0), arg0,
TREE_OPERAND (arg1, 1)),
build_zero_cst (TREE_TYPE (arg0)));
/* Similarly for X < (cast) (1 << Y). But cast can't be narrowing,
otherwise Y might be >= # of bits in X's type and thus e.g.
(unsigned char) (1 << Y) for Y 15 might be 0.
If the cast is widening, then 1 << Y should have unsigned type,
otherwise if Y is number of bits in the signed shift type minus 1,
we can't optimize this. E.g. (unsigned long long) (1 << Y) for Y
31 might be 0xffffffff80000000. */
if ((code == LT_EXPR || code == GE_EXPR)
&& TYPE_UNSIGNED (TREE_TYPE (arg0))
&& CONVERT_EXPR_P (arg1)
&& TREE_CODE (TREE_OPERAND (arg1, 0)) == LSHIFT_EXPR
&& (TYPE_PRECISION (TREE_TYPE (arg1))
>= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg1, 0))))
&& (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg1, 0)))
|| (TYPE_PRECISION (TREE_TYPE (arg1))
== TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg1, 0)))))
&& integer_onep (TREE_OPERAND (TREE_OPERAND (arg1, 0), 0)))
{
tem = build2 (RSHIFT_EXPR, TREE_TYPE (arg0), arg0,
TREE_OPERAND (TREE_OPERAND (arg1, 0), 1));
return build2_loc (loc, code == LT_EXPR ? EQ_EXPR : NE_EXPR, type,
fold_convert_loc (loc, TREE_TYPE (arg0), tem),
build_zero_cst (TREE_TYPE (arg0)));
}
return NULL_TREE;
case UNORDERED_EXPR:
case ORDERED_EXPR:
case UNLT_EXPR:
case UNLE_EXPR:
case UNGT_EXPR:
case UNGE_EXPR:
case UNEQ_EXPR:
case LTGT_EXPR:
if (TREE_CODE (arg0) == REAL_CST && TREE_CODE (arg1) == REAL_CST)
{
t1 = fold_relational_const (code, type, arg0, arg1);
if (t1 != NULL_TREE)
return t1;
}
/* If the first operand is NaN, the result is constant. */
if (TREE_CODE (arg0) == REAL_CST
&& REAL_VALUE_ISNAN (TREE_REAL_CST (arg0))
&& (code != LTGT_EXPR || ! flag_trapping_math))
{
t1 = (code == ORDERED_EXPR || code == LTGT_EXPR)
? integer_zero_node
: integer_one_node;
return omit_one_operand_loc (loc, type, t1, arg1);
}
/* If the second operand is NaN, the result is constant. */
if (TREE_CODE (arg1) == REAL_CST
&& REAL_VALUE_ISNAN (TREE_REAL_CST (arg1))
&& (code != LTGT_EXPR || ! flag_trapping_math))
{
t1 = (code == ORDERED_EXPR || code == LTGT_EXPR)
? integer_zero_node
: integer_one_node;
return omit_one_operand_loc (loc, type, t1, arg0);
}
/* Simplify unordered comparison of something with itself. */
if ((code == UNLE_EXPR || code == UNGE_EXPR || code == UNEQ_EXPR)
&& operand_equal_p (arg0, arg1, 0))
return constant_boolean_node (1, type);
if (code == LTGT_EXPR
&& !flag_trapping_math
&& operand_equal_p (arg0, arg1, 0))
return constant_boolean_node (0, type);
/* Fold (double)float1 CMP (double)float2 into float1 CMP float2. */
{
tree targ0 = strip_float_extensions (arg0);
tree targ1 = strip_float_extensions (arg1);
tree newtype = TREE_TYPE (targ0);
if (TYPE_PRECISION (TREE_TYPE (targ1)) > TYPE_PRECISION (newtype))
newtype = TREE_TYPE (targ1);
if (TYPE_PRECISION (newtype) < TYPE_PRECISION (TREE_TYPE (arg0)))
return fold_build2_loc (loc, code, type,
fold_convert_loc (loc, newtype, targ0),
fold_convert_loc (loc, newtype, targ1));
}
return NULL_TREE;
case COMPOUND_EXPR:
/* When pedantic, a compound expression can be neither an lvalue
nor an integer constant expression. */
if (TREE_SIDE_EFFECTS (arg0) || TREE_CONSTANT (arg1))
return NULL_TREE;
/* Don't let (0, 0) be null pointer constant. */
tem = integer_zerop (arg1) ? build1 (NOP_EXPR, type, arg1)
: fold_convert_loc (loc, type, arg1);
return pedantic_non_lvalue_loc (loc, tem);
case COMPLEX_EXPR:
if ((TREE_CODE (arg0) == REAL_CST
&& TREE_CODE (arg1) == REAL_CST)
|| (TREE_CODE (arg0) == INTEGER_CST
&& TREE_CODE (arg1) == INTEGER_CST))
return build_complex (type, arg0, arg1);
if (TREE_CODE (arg0) == REALPART_EXPR
&& TREE_CODE (arg1) == IMAGPART_EXPR
&& TREE_TYPE (TREE_OPERAND (arg0, 0)) == type
&& operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0), 0))
return omit_one_operand_loc (loc, type, TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 0));
return NULL_TREE;
case ASSERT_EXPR:
/* An ASSERT_EXPR should never be passed to fold_binary. */
gcc_unreachable ();
case VEC_PACK_TRUNC_EXPR:
case VEC_PACK_FIX_TRUNC_EXPR:
{
unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i;
tree *elts;
gcc_assert (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)) == nelts / 2
&& TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg1)) == nelts / 2);
if (TREE_CODE (arg0) != VECTOR_CST || TREE_CODE (arg1) != VECTOR_CST)
return NULL_TREE;
elts = XALLOCAVEC (tree, nelts);
if (!vec_cst_ctor_to_array (arg0, elts)
|| !vec_cst_ctor_to_array (arg1, elts + nelts / 2))
return NULL_TREE;
for (i = 0; i < nelts; i++)
{
elts[i] = fold_convert_const (code == VEC_PACK_TRUNC_EXPR
? NOP_EXPR : FIX_TRUNC_EXPR,
TREE_TYPE (type), elts[i]);
if (elts[i] == NULL_TREE || !CONSTANT_CLASS_P (elts[i]))
return NULL_TREE;
}
return build_vector (type, elts);
}
case VEC_WIDEN_MULT_LO_EXPR:
case VEC_WIDEN_MULT_HI_EXPR:
case VEC_WIDEN_MULT_EVEN_EXPR:
case VEC_WIDEN_MULT_ODD_EXPR:
{
unsigned int nelts = TYPE_VECTOR_SUBPARTS (type);
unsigned int out, ofs, scale;
tree *elts;
gcc_assert (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)) == nelts * 2
&& TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg1)) == nelts * 2);
if (TREE_CODE (arg0) != VECTOR_CST || TREE_CODE (arg1) != VECTOR_CST)
return NULL_TREE;
elts = XALLOCAVEC (tree, nelts * 4);
if (!vec_cst_ctor_to_array (arg0, elts)
|| !vec_cst_ctor_to_array (arg1, elts + nelts * 2))
return NULL_TREE;
if (code == VEC_WIDEN_MULT_LO_EXPR)
scale = 0, ofs = BYTES_BIG_ENDIAN ? nelts : 0;
else if (code == VEC_WIDEN_MULT_HI_EXPR)
scale = 0, ofs = BYTES_BIG_ENDIAN ? 0 : nelts;
else if (code == VEC_WIDEN_MULT_EVEN_EXPR)
scale = 1, ofs = 0;
else /* if (code == VEC_WIDEN_MULT_ODD_EXPR) */
scale = 1, ofs = 1;
for (out = 0; out < nelts; out++)
{
unsigned int in1 = (out << scale) + ofs;
unsigned int in2 = in1 + nelts * 2;
tree t1, t2;
t1 = fold_convert_const (NOP_EXPR, TREE_TYPE (type), elts[in1]);
t2 = fold_convert_const (NOP_EXPR, TREE_TYPE (type), elts[in2]);
if (t1 == NULL_TREE || t2 == NULL_TREE)
return NULL_TREE;
elts[out] = const_binop (MULT_EXPR, t1, t2);
if (elts[out] == NULL_TREE || !CONSTANT_CLASS_P (elts[out]))
return NULL_TREE;
}
return build_vector (type, elts);
}
default:
return NULL_TREE;
} /* switch (code) */
}
/* Callback for walk_tree, looking for LABEL_EXPR. Return *TP if it is
a LABEL_EXPR; otherwise return NULL_TREE. Do not check the subtrees
of GOTO_EXPR. */
static tree
contains_label_1 (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
{
switch (TREE_CODE (*tp))
{
case LABEL_EXPR:
return *tp;
case GOTO_EXPR:
*walk_subtrees = 0;
/* ... fall through ... */
default:
return NULL_TREE;
}
}
/* Return whether the sub-tree ST contains a label which is accessible from
outside the sub-tree. */
static bool
contains_label_p (tree st)
{
return
(walk_tree_without_duplicates (&st, contains_label_1 , NULL) != NULL_TREE);
}
/* Fold a ternary expression of code CODE and type TYPE with operands
OP0, OP1, and OP2. Return the folded expression if folding is
successful. Otherwise, return NULL_TREE. */
tree
fold_ternary_loc (location_t loc, enum tree_code code, tree type,
tree op0, tree op1, tree op2)
{
tree tem;
tree arg0 = NULL_TREE, arg1 = NULL_TREE, arg2 = NULL_TREE;
enum tree_code_class kind = TREE_CODE_CLASS (code);
gcc_assert (IS_EXPR_CODE_CLASS (kind)
&& TREE_CODE_LENGTH (code) == 3);
/* Strip any conversions that don't change the mode. This is safe
for every expression, except for a comparison expression because
its signedness is derived from its operands. So, in the latter
case, only strip conversions that don't change the signedness.
Note that this is done as an internal manipulation within the
constant folder, in order to find the simplest representation of
the arguments so that their form can be studied. In any cases,
the appropriate type conversions should be put back in the tree
that will get out of the constant folder. */
if (op0)
{
arg0 = op0;
STRIP_NOPS (arg0);
}
if (op1)
{
arg1 = op1;
STRIP_NOPS (arg1);
}
if (op2)
{
arg2 = op2;
STRIP_NOPS (arg2);
}
switch (code)
{
case COMPONENT_REF:
if (TREE_CODE (arg0) == CONSTRUCTOR
&& ! type_contains_placeholder_p (TREE_TYPE (arg0)))
{
unsigned HOST_WIDE_INT idx;
tree field, value;
FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (arg0), idx, field, value)
if (field == arg1)
return value;
}
return NULL_TREE;
case COND_EXPR:
/* Pedantic ANSI C says that a conditional expression is never an lvalue,
so all simple results must be passed through pedantic_non_lvalue. */
if (TREE_CODE (arg0) == INTEGER_CST)
{
tree unused_op = integer_zerop (arg0) ? op1 : op2;
tem = integer_zerop (arg0) ? op2 : op1;
/* Only optimize constant conditions when the selected branch
has the same type as the COND_EXPR. This avoids optimizing
away "c ? x : throw", where the throw has a void type.
Avoid throwing away that operand which contains label. */
if ((!TREE_SIDE_EFFECTS (unused_op)
|| !contains_label_p (unused_op))
&& (! VOID_TYPE_P (TREE_TYPE (tem))
|| VOID_TYPE_P (type)))
return pedantic_non_lvalue_loc (loc, tem);
return NULL_TREE;
}
if (operand_equal_p (arg1, op2, 0))
return pedantic_omit_one_operand_loc (loc, type, arg1, arg0);
/* If we have A op B ? A : C, we may be able to convert this to a
simpler expression, depending on the operation and the values
of B and C. Signed zeros prevent all of these transformations,
for reasons given above each one.
Also try swapping the arguments and inverting the conditional. */
if (COMPARISON_CLASS_P (arg0)
&& operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0),
arg1, TREE_OPERAND (arg0, 1))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg1))))
{
tem = fold_cond_expr_with_comparison (loc, type, arg0, op1, op2);
if (tem)
return tem;
}
if (COMPARISON_CLASS_P (arg0)
&& operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0),
op2,
TREE_OPERAND (arg0, 1))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (op2))))
{
location_t loc0 = expr_location_or (arg0, loc);
tem = fold_truth_not_expr (loc0, arg0);
if (tem && COMPARISON_CLASS_P (tem))
{
tem = fold_cond_expr_with_comparison (loc, type, tem, op2, op1);
if (tem)
return tem;
}
}
/* If the second operand is simpler than the third, swap them
since that produces better jump optimization results. */
if (truth_value_p (TREE_CODE (arg0))
&& tree_swap_operands_p (op1, op2, false))
{
location_t loc0 = expr_location_or (arg0, loc);
/* See if this can be inverted. If it can't, possibly because
it was a floating-point inequality comparison, don't do
anything. */
tem = fold_truth_not_expr (loc0, arg0);
if (tem)
return fold_build3_loc (loc, code, type, tem, op2, op1);
}
/* Convert A ? 1 : 0 to simply A. */
if (integer_onep (op1)
&& integer_zerop (op2)
/* If we try to convert OP0 to our type, the
call to fold will try to move the conversion inside
a COND, which will recurse. In that case, the COND_EXPR
is probably the best choice, so leave it alone. */
&& type == TREE_TYPE (arg0))
return pedantic_non_lvalue_loc (loc, arg0);
/* Convert A ? 0 : 1 to !A. This prefers the use of NOT_EXPR
over COND_EXPR in cases such as floating point comparisons. */
if (integer_zerop (op1)
&& integer_onep (op2)
&& truth_value_p (TREE_CODE (arg0)))
return pedantic_non_lvalue_loc (loc,
fold_convert_loc (loc, type,
invert_truthvalue_loc (loc,
arg0)));
/* A < 0 ? <sign bit of A> : 0 is simply (A & <sign bit of A>). */
if (TREE_CODE (arg0) == LT_EXPR
&& integer_zerop (TREE_OPERAND (arg0, 1))
&& integer_zerop (op2)
&& (tem = sign_bit_p (TREE_OPERAND (arg0, 0), arg1)))
{
/* sign_bit_p only checks ARG1 bits within A's precision.
If <sign bit of A> has wider type than A, bits outside
of A's precision in <sign bit of A> need to be checked.
If they are all 0, this optimization needs to be done
in unsigned A's type, if they are all 1 in signed A's type,
otherwise this can't be done. */
if (TYPE_PRECISION (TREE_TYPE (tem))
< TYPE_PRECISION (TREE_TYPE (arg1))
&& TYPE_PRECISION (TREE_TYPE (tem))
< TYPE_PRECISION (type))
{
unsigned HOST_WIDE_INT mask_lo;
HOST_WIDE_INT mask_hi;
int inner_width, outer_width;
tree tem_type;
inner_width = TYPE_PRECISION (TREE_TYPE (tem));
outer_width = TYPE_PRECISION (TREE_TYPE (arg1));
if (outer_width > TYPE_PRECISION (type))
outer_width = TYPE_PRECISION (type);
if (outer_width > HOST_BITS_PER_WIDE_INT)
{
mask_hi = ((unsigned HOST_WIDE_INT) -1
>> (HOST_BITS_PER_DOUBLE_INT - outer_width));
mask_lo = -1;
}
else
{
mask_hi = 0;
mask_lo = ((unsigned HOST_WIDE_INT) -1
>> (HOST_BITS_PER_WIDE_INT - outer_width));
}
if (inner_width > HOST_BITS_PER_WIDE_INT)
{
mask_hi &= ~((unsigned HOST_WIDE_INT) -1
>> (HOST_BITS_PER_WIDE_INT - inner_width));
mask_lo = 0;
}
else
mask_lo &= ~((unsigned HOST_WIDE_INT) -1
>> (HOST_BITS_PER_WIDE_INT - inner_width));
if ((TREE_INT_CST_HIGH (arg1) & mask_hi) == mask_hi
&& (TREE_INT_CST_LOW (arg1) & mask_lo) == mask_lo)
{
tem_type = signed_type_for (TREE_TYPE (tem));
tem = fold_convert_loc (loc, tem_type, tem);
}
else if ((TREE_INT_CST_HIGH (arg1) & mask_hi) == 0
&& (TREE_INT_CST_LOW (arg1) & mask_lo) == 0)
{
tem_type = unsigned_type_for (TREE_TYPE (tem));
tem = fold_convert_loc (loc, tem_type, tem);
}
else
tem = NULL;
}
if (tem)
return
fold_convert_loc (loc, type,
fold_build2_loc (loc, BIT_AND_EXPR,
TREE_TYPE (tem), tem,
fold_convert_loc (loc,
TREE_TYPE (tem),
arg1)));
}
/* (A >> N) & 1 ? (1 << N) : 0 is simply A & (1 << N). A & 1 was
already handled above. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& integer_onep (TREE_OPERAND (arg0, 1))
&& integer_zerop (op2)
&& integer_pow2p (arg1))
{
tree tem = TREE_OPERAND (arg0, 0);
STRIP_NOPS (tem);
if (TREE_CODE (tem) == RSHIFT_EXPR
&& TREE_CODE (TREE_OPERAND (tem, 1)) == INTEGER_CST
&& (unsigned HOST_WIDE_INT) tree_log2 (arg1) ==
TREE_INT_CST_LOW (TREE_OPERAND (tem, 1)))
return fold_build2_loc (loc, BIT_AND_EXPR, type,
TREE_OPERAND (tem, 0), arg1);
}
/* A & N ? N : 0 is simply A & N if N is a power of two. This
is probably obsolete because the first operand should be a
truth value (that's why we have the two cases above), but let's
leave it in until we can confirm this for all front-ends. */
if (integer_zerop (op2)
&& TREE_CODE (arg0) == NE_EXPR
&& integer_zerop (TREE_OPERAND (arg0, 1))
&& integer_pow2p (arg1)
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == BIT_AND_EXPR
&& operand_equal_p (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1),
arg1, OEP_ONLY_CONST))
return pedantic_non_lvalue_loc (loc,
fold_convert_loc (loc, type,
TREE_OPERAND (arg0, 0)));
/* Convert A ? B : 0 into A && B if A and B are truth values. */
if (integer_zerop (op2)
&& truth_value_p (TREE_CODE (arg0))
&& truth_value_p (TREE_CODE (arg1)))
return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type,
fold_convert_loc (loc, type, arg0),
arg1);
/* Convert A ? B : 1 into !A || B if A and B are truth values. */
if (integer_onep (op2)
&& truth_value_p (TREE_CODE (arg0))
&& truth_value_p (TREE_CODE (arg1)))
{
location_t loc0 = expr_location_or (arg0, loc);
/* Only perform transformation if ARG0 is easily inverted. */
tem = fold_truth_not_expr (loc0, arg0);
if (tem)
return fold_build2_loc (loc, TRUTH_ORIF_EXPR, type,
fold_convert_loc (loc, type, tem),
arg1);
}
/* Convert A ? 0 : B into !A && B if A and B are truth values. */
if (integer_zerop (arg1)
&& truth_value_p (TREE_CODE (arg0))
&& truth_value_p (TREE_CODE (op2)))
{
location_t loc0 = expr_location_or (arg0, loc);
/* Only perform transformation if ARG0 is easily inverted. */
tem = fold_truth_not_expr (loc0, arg0);
if (tem)
return fold_build2_loc (loc, TRUTH_ANDIF_EXPR, type,
fold_convert_loc (loc, type, tem),
op2);
}
/* Convert A ? 1 : B into A || B if A and B are truth values. */
if (integer_onep (arg1)
&& truth_value_p (TREE_CODE (arg0))
&& truth_value_p (TREE_CODE (op2)))
return fold_build2_loc (loc, TRUTH_ORIF_EXPR, type,
fold_convert_loc (loc, type, arg0),
op2);
return NULL_TREE;
case VEC_COND_EXPR:
if (TREE_CODE (arg0) == VECTOR_CST)
{
if (integer_all_onesp (arg0) && !TREE_SIDE_EFFECTS (op2))
return pedantic_non_lvalue_loc (loc, op1);
if (integer_zerop (arg0) && !TREE_SIDE_EFFECTS (op1))
return pedantic_non_lvalue_loc (loc, op2);
}
return NULL_TREE;
case CALL_EXPR:
/* CALL_EXPRs used to be ternary exprs. Catch any mistaken uses
of fold_ternary on them. */
gcc_unreachable ();
case BIT_FIELD_REF:
if ((TREE_CODE (arg0) == VECTOR_CST
|| (TREE_CODE (arg0) == CONSTRUCTOR
&& TREE_CODE (TREE_TYPE (arg0)) == VECTOR_TYPE))
&& (type == TREE_TYPE (TREE_TYPE (arg0))
|| (TREE_CODE (type) == VECTOR_TYPE
&& TREE_TYPE (type) == TREE_TYPE (TREE_TYPE (arg0)))))
{
tree eltype = TREE_TYPE (TREE_TYPE (arg0));
unsigned HOST_WIDE_INT width = tree_low_cst (TYPE_SIZE (eltype), 1);
unsigned HOST_WIDE_INT n = tree_low_cst (arg1, 1);
unsigned HOST_WIDE_INT idx = tree_low_cst (op2, 1);
if (n != 0
&& (idx % width) == 0
&& (n % width) == 0
&& ((idx + n) / width) <= TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg0)))
{
idx = idx / width;
n = n / width;
if (TREE_CODE (arg0) == VECTOR_CST)
{
if (n == 1)
return VECTOR_CST_ELT (arg0, idx);
tree *vals = XALLOCAVEC (tree, n);
for (unsigned i = 0; i < n; ++i)
vals[i] = VECTOR_CST_ELT (arg0, idx + i);
return build_vector (type, vals);
}
/* Constructor elements can be subvectors. */
unsigned HOST_WIDE_INT k = 1;
if (CONSTRUCTOR_NELTS (arg0) != 0)
{
tree cons_elem = TREE_TYPE (CONSTRUCTOR_ELT (arg0, 0)->value);
if (TREE_CODE (cons_elem) == VECTOR_TYPE)
k = TYPE_VECTOR_SUBPARTS (cons_elem);
}
/* We keep an exact subset of the constructor elements. */
if ((idx % k) == 0 && (n % k) == 0)
{
if (CONSTRUCTOR_NELTS (arg0) == 0)
return build_constructor (type, NULL);
idx /= k;
n /= k;
if (n == 1)
{
if (idx < CONSTRUCTOR_NELTS (arg0))
return CONSTRUCTOR_ELT (arg0, idx)->value;
return build_zero_cst (type);
}
vec<constructor_elt, va_gc> *vals;
vec_alloc (vals, n);
for (unsigned i = 0;
i < n && idx + i < CONSTRUCTOR_NELTS (arg0);
++i)
CONSTRUCTOR_APPEND_ELT (vals, NULL_TREE,
CONSTRUCTOR_ELT
(arg0, idx + i)->value);
return build_constructor (type, vals);
}
/* The bitfield references a single constructor element. */
else if (idx + n <= (idx / k + 1) * k)
{
if (CONSTRUCTOR_NELTS (arg0) <= idx / k)
return build_zero_cst (type);
else if (n == k)
return CONSTRUCTOR_ELT (arg0, idx / k)->value;
else
return fold_build3_loc (loc, code, type,
CONSTRUCTOR_ELT (arg0, idx / k)->value, op1,
build_int_cst (TREE_TYPE (op2), (idx % k) * width));
}
}
}
/* A bit-field-ref that referenced the full argument can be stripped. */
if (INTEGRAL_TYPE_P (TREE_TYPE (arg0))
&& TYPE_PRECISION (TREE_TYPE (arg0)) == tree_low_cst (arg1, 1)
&& integer_zerop (op2))
return fold_convert_loc (loc, type, arg0);
/* On constants we can use native encode/interpret to constant
fold (nearly) all BIT_FIELD_REFs. */
if (CONSTANT_CLASS_P (arg0)
&& can_native_interpret_type_p (type)
&& host_integerp (TYPE_SIZE_UNIT (TREE_TYPE (arg0)), 1)
/* This limitation should not be necessary, we just need to
round this up to mode size. */
&& tree_low_cst (op1, 1) % BITS_PER_UNIT == 0
/* Need bit-shifting of the buffer to relax the following. */
&& tree_low_cst (op2, 1) % BITS_PER_UNIT == 0)
{
unsigned HOST_WIDE_INT bitpos = tree_low_cst (op2, 1);
unsigned HOST_WIDE_INT bitsize = tree_low_cst (op1, 1);
unsigned HOST_WIDE_INT clen;
clen = tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (arg0)), 1);
/* ??? We cannot tell native_encode_expr to start at
some random byte only. So limit us to a reasonable amount
of work. */
if (clen <= 4096)
{
unsigned char *b = XALLOCAVEC (unsigned char, clen);
unsigned HOST_WIDE_INT len = native_encode_expr (arg0, b, clen);
if (len > 0
&& len * BITS_PER_UNIT >= bitpos + bitsize)
{
tree v = native_interpret_expr (type,
b + bitpos / BITS_PER_UNIT,
bitsize / BITS_PER_UNIT);
if (v)
return v;
}
}
}
return NULL_TREE;
case FMA_EXPR:
/* For integers we can decompose the FMA if possible. */
if (TREE_CODE (arg0) == INTEGER_CST
&& TREE_CODE (arg1) == INTEGER_CST)
return fold_build2_loc (loc, PLUS_EXPR, type,
const_binop (MULT_EXPR, arg0, arg1), arg2);
if (integer_zerop (arg2))
return fold_build2_loc (loc, MULT_EXPR, type, arg0, arg1);
return fold_fma (loc, type, arg0, arg1, arg2);
case VEC_PERM_EXPR:
if (TREE_CODE (arg2) == VECTOR_CST)
{
unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i, mask;
unsigned char *sel = XALLOCAVEC (unsigned char, nelts);
tree t;
bool need_mask_canon = false;
bool all_in_vec0 = true;
bool all_in_vec1 = true;
bool maybe_identity = true;
bool single_arg = (op0 == op1);
bool changed = false;
mask = single_arg ? (nelts - 1) : (2 * nelts - 1);
gcc_assert (nelts == VECTOR_CST_NELTS (arg2));
for (i = 0; i < nelts; i++)
{
tree val = VECTOR_CST_ELT (arg2, i);
if (TREE_CODE (val) != INTEGER_CST)
return NULL_TREE;
sel[i] = TREE_INT_CST_LOW (val) & mask;
if (TREE_INT_CST_HIGH (val)
|| ((unsigned HOST_WIDE_INT)
TREE_INT_CST_LOW (val) != sel[i]))
need_mask_canon = true;
if (sel[i] < nelts)
all_in_vec1 = false;
else
all_in_vec0 = false;
if ((sel[i] & (nelts-1)) != i)
maybe_identity = false;
}
if (maybe_identity)
{
if (all_in_vec0)
return op0;
if (all_in_vec1)
return op1;
}
if (all_in_vec0)
op1 = op0;
else if (all_in_vec1)
{
op0 = op1;
for (i = 0; i < nelts; i++)
sel[i] -= nelts;
need_mask_canon = true;
}
if ((TREE_CODE (op0) == VECTOR_CST
|| TREE_CODE (op0) == CONSTRUCTOR)
&& (TREE_CODE (op1) == VECTOR_CST
|| TREE_CODE (op1) == CONSTRUCTOR))
{
t = fold_vec_perm (type, op0, op1, sel);
if (t != NULL_TREE)
return t;
}
if (op0 == op1 && !single_arg)
changed = true;
if (need_mask_canon && arg2 == op2)
{
tree *tsel = XALLOCAVEC (tree, nelts);
tree eltype = TREE_TYPE (TREE_TYPE (arg2));
for (i = 0; i < nelts; i++)
tsel[i] = build_int_cst (eltype, sel[i]);
op2 = build_vector (TREE_TYPE (arg2), tsel);
changed = true;
}
if (changed)
return build3_loc (loc, VEC_PERM_EXPR, type, op0, op1, op2);
}
return NULL_TREE;
default:
return NULL_TREE;
} /* switch (code) */
}
/* Perform constant folding and related simplification of EXPR.
The related simplifications include x*1 => x, x*0 => 0, etc.,
and application of the associative law.
NOP_EXPR conversions may be removed freely (as long as we
are careful not to change the type of the overall expression).
We cannot simplify through a CONVERT_EXPR, FIX_EXPR or FLOAT_EXPR,
but we can constant-fold them if they have constant operands. */
#ifdef ENABLE_FOLD_CHECKING
# define fold(x) fold_1 (x)
static tree fold_1 (tree);
static
#endif
tree
fold (tree expr)
{
const tree t = expr;
enum tree_code code = TREE_CODE (t);
enum tree_code_class kind = TREE_CODE_CLASS (code);
tree tem;
location_t loc = EXPR_LOCATION (expr);
/* Return right away if a constant. */
if (kind == tcc_constant)
return t;
/* CALL_EXPR-like objects with variable numbers of operands are
treated specially. */
if (kind == tcc_vl_exp)
{
if (code == CALL_EXPR)
{
tem = fold_call_expr (loc, expr, false);
return tem ? tem : expr;
}
return expr;
}
if (IS_EXPR_CODE_CLASS (kind))
{
tree type = TREE_TYPE (t);
tree op0, op1, op2;
switch (TREE_CODE_LENGTH (code))
{
case 1:
op0 = TREE_OPERAND (t, 0);
tem = fold_unary_loc (loc, code, type, op0);
return tem ? tem : expr;
case 2:
op0 = TREE_OPERAND (t, 0);
op1 = TREE_OPERAND (t, 1);
tem = fold_binary_loc (loc, code, type, op0, op1);
return tem ? tem : expr;
case 3:
op0 = TREE_OPERAND (t, 0);
op1 = TREE_OPERAND (t, 1);
op2 = TREE_OPERAND (t, 2);
tem = fold_ternary_loc (loc, code, type, op0, op1, op2);
return tem ? tem : expr;
default:
break;
}
}
switch (code)
{
case ARRAY_REF:
{
tree op0 = TREE_OPERAND (t, 0);
tree op1 = TREE_OPERAND (t, 1);
if (TREE_CODE (op1) == INTEGER_CST
&& TREE_CODE (op0) == CONSTRUCTOR
&& ! type_contains_placeholder_p (TREE_TYPE (op0)))
{
vec<constructor_elt, va_gc> *elts = CONSTRUCTOR_ELTS (op0);
unsigned HOST_WIDE_INT end = vec_safe_length (elts);
unsigned HOST_WIDE_INT begin = 0;
/* Find a matching index by means of a binary search. */
while (begin != end)
{
unsigned HOST_WIDE_INT middle = (begin + end) / 2;
tree index = (*elts)[middle].index;
if (TREE_CODE (index) == INTEGER_CST
&& tree_int_cst_lt (index, op1))
begin = middle + 1;
else if (TREE_CODE (index) == INTEGER_CST
&& tree_int_cst_lt (op1, index))
end = middle;
else if (TREE_CODE (index) == RANGE_EXPR
&& tree_int_cst_lt (TREE_OPERAND (index, 1), op1))
begin = middle + 1;
else if (TREE_CODE (index) == RANGE_EXPR
&& tree_int_cst_lt (op1, TREE_OPERAND (index, 0)))
end = middle;
else
return (*elts)[middle].value;
}
}
return t;
}
/* Return a VECTOR_CST if possible. */
case CONSTRUCTOR:
{
tree type = TREE_TYPE (t);
if (TREE_CODE (type) != VECTOR_TYPE)
return t;
tree *vec = XALLOCAVEC (tree, TYPE_VECTOR_SUBPARTS (type));
unsigned HOST_WIDE_INT idx, pos = 0;
tree value;
FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), idx, value)
{
if (!CONSTANT_CLASS_P (value))
return t;
if (TREE_CODE (value) == VECTOR_CST)
{
for (unsigned i = 0; i < VECTOR_CST_NELTS (value); ++i)
vec[pos++] = VECTOR_CST_ELT (value, i);
}
else
vec[pos++] = value;
}
for (; pos < TYPE_VECTOR_SUBPARTS (type); ++pos)
vec[pos] = build_zero_cst (TREE_TYPE (type));
return build_vector (type, vec);
}
case CONST_DECL:
return fold (DECL_INITIAL (t));
default:
return t;
} /* switch (code) */
}
#ifdef ENABLE_FOLD_CHECKING
#undef fold
static void fold_checksum_tree (const_tree, struct md5_ctx *,
hash_table <pointer_hash <tree_node> >);
static void fold_check_failed (const_tree, const_tree);
void print_fold_checksum (const_tree);
/* When --enable-checking=fold, compute a digest of expr before
and after actual fold call to see if fold did not accidentally
change original expr. */
tree
fold (tree expr)
{
tree ret;
struct md5_ctx ctx;
unsigned char checksum_before[16], checksum_after[16];
hash_table <pointer_hash <tree_node> > ht;
ht.create (32);
md5_init_ctx (&ctx);
fold_checksum_tree (expr, &ctx, ht);
md5_finish_ctx (&ctx, checksum_before);
ht.empty ();
ret = fold_1 (expr);
md5_init_ctx (&ctx);
fold_checksum_tree (expr, &ctx, ht);
md5_finish_ctx (&ctx, checksum_after);
ht.dispose ();
if (memcmp (checksum_before, checksum_after, 16))
fold_check_failed (expr, ret);
return ret;
}
void
print_fold_checksum (const_tree expr)
{
struct md5_ctx ctx;
unsigned char checksum[16], cnt;
hash_table <pointer_hash <tree_node> > ht;
ht.create (32);
md5_init_ctx (&ctx);
fold_checksum_tree (expr, &ctx, ht);
md5_finish_ctx (&ctx, checksum);
ht.dispose ();
for (cnt = 0; cnt < 16; ++cnt)
fprintf (stderr, "%02x", checksum[cnt]);
putc ('\n', stderr);
}
static void
fold_check_failed (const_tree expr ATTRIBUTE_UNUSED, const_tree ret ATTRIBUTE_UNUSED)
{
internal_error ("fold check: original tree changed by fold");
}
static void
fold_checksum_tree (const_tree expr, struct md5_ctx *ctx,
hash_table <pointer_hash <tree_node> > ht)
{
tree_node **slot;
enum tree_code code;
union tree_node buf;
int i, len;
recursive_label:
if (expr == NULL)
return;
slot = ht.find_slot (expr, INSERT);
if (*slot != NULL)
return;
*slot = CONST_CAST_TREE (expr);
code = TREE_CODE (expr);
if (TREE_CODE_CLASS (code) == tcc_declaration
&& DECL_ASSEMBLER_NAME_SET_P (expr))
{
/* Allow DECL_ASSEMBLER_NAME to be modified. */
memcpy ((char *) &buf, expr, tree_size (expr));
SET_DECL_ASSEMBLER_NAME ((tree)&buf, NULL);
expr = (tree) &buf;
}
else if (TREE_CODE_CLASS (code) == tcc_type
&& (TYPE_POINTER_TO (expr)
|| TYPE_REFERENCE_TO (expr)
|| TYPE_CACHED_VALUES_P (expr)
|| TYPE_CONTAINS_PLACEHOLDER_INTERNAL (expr)
|| TYPE_NEXT_VARIANT (expr)))
{
/* Allow these fields to be modified. */
tree tmp;
memcpy ((char *) &buf, expr, tree_size (expr));
expr = tmp = (tree) &buf;
TYPE_CONTAINS_PLACEHOLDER_INTERNAL (tmp) = 0;
TYPE_POINTER_TO (tmp) = NULL;
TYPE_REFERENCE_TO (tmp) = NULL;
TYPE_NEXT_VARIANT (tmp) = NULL;
if (TYPE_CACHED_VALUES_P (tmp))
{
TYPE_CACHED_VALUES_P (tmp) = 0;
TYPE_CACHED_VALUES (tmp) = NULL;
}
}
md5_process_bytes (expr, tree_size (expr), ctx);
if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
fold_checksum_tree (TREE_TYPE (expr), ctx, ht);
if (TREE_CODE_CLASS (code) != tcc_type
&& TREE_CODE_CLASS (code) != tcc_declaration
&& code != TREE_LIST
&& code != SSA_NAME
&& CODE_CONTAINS_STRUCT (code, TS_COMMON))
fold_checksum_tree (TREE_CHAIN (expr), ctx, ht);
switch (TREE_CODE_CLASS (code))
{
case tcc_constant:
switch (code)
{
case STRING_CST:
md5_process_bytes (TREE_STRING_POINTER (expr),
TREE_STRING_LENGTH (expr), ctx);
break;
case COMPLEX_CST:
fold_checksum_tree (TREE_REALPART (expr), ctx, ht);
fold_checksum_tree (TREE_IMAGPART (expr), ctx, ht);
break;
case VECTOR_CST:
for (i = 0; i < (int) VECTOR_CST_NELTS (expr); ++i)
fold_checksum_tree (VECTOR_CST_ELT (expr, i), ctx, ht);
break;
default:
break;
}
break;
case tcc_exceptional:
switch (code)
{
case TREE_LIST:
fold_checksum_tree (TREE_PURPOSE (expr), ctx, ht);
fold_checksum_tree (TREE_VALUE (expr), ctx, ht);
expr = TREE_CHAIN (expr);
goto recursive_label;
break;
case TREE_VEC:
for (i = 0; i < TREE_VEC_LENGTH (expr); ++i)
fold_checksum_tree (TREE_VEC_ELT (expr, i), ctx, ht);
break;
default:
break;
}
break;
case tcc_expression:
case tcc_reference:
case tcc_comparison:
case tcc_unary:
case tcc_binary:
case tcc_statement:
case tcc_vl_exp:
len = TREE_OPERAND_LENGTH (expr);
for (i = 0; i < len; ++i)
fold_checksum_tree (TREE_OPERAND (expr, i), ctx, ht);
break;
case tcc_declaration:
fold_checksum_tree (DECL_NAME (expr), ctx, ht);
fold_checksum_tree (DECL_CONTEXT (expr), ctx, ht);
if (CODE_CONTAINS_STRUCT (TREE_CODE (expr), TS_DECL_COMMON))
{
fold_checksum_tree (DECL_SIZE (expr), ctx, ht);
fold_checksum_tree (DECL_SIZE_UNIT (expr), ctx, ht);
fold_checksum_tree (DECL_INITIAL (expr), ctx, ht);
fold_checksum_tree (DECL_ABSTRACT_ORIGIN (expr), ctx, ht);
fold_checksum_tree (DECL_ATTRIBUTES (expr), ctx, ht);
}
if (CODE_CONTAINS_STRUCT (TREE_CODE (expr), TS_DECL_WITH_VIS))
fold_checksum_tree (DECL_SECTION_NAME (expr), ctx, ht);
if (CODE_CONTAINS_STRUCT (TREE_CODE (expr), TS_DECL_NON_COMMON))
{
fold_checksum_tree (DECL_VINDEX (expr), ctx, ht);
fold_checksum_tree (DECL_RESULT_FLD (expr), ctx, ht);
fold_checksum_tree (DECL_ARGUMENT_FLD (expr), ctx, ht);
}
break;
case tcc_type:
if (TREE_CODE (expr) == ENUMERAL_TYPE)
fold_checksum_tree (TYPE_VALUES (expr), ctx, ht);
fold_checksum_tree (TYPE_SIZE (expr), ctx, ht);
fold_checksum_tree (TYPE_SIZE_UNIT (expr), ctx, ht);
fold_checksum_tree (TYPE_ATTRIBUTES (expr), ctx, ht);
fold_checksum_tree (TYPE_NAME (expr), ctx, ht);
if (INTEGRAL_TYPE_P (expr)
|| SCALAR_FLOAT_TYPE_P (expr))
{
fold_checksum_tree (TYPE_MIN_VALUE (expr), ctx, ht);
fold_checksum_tree (TYPE_MAX_VALUE (expr), ctx, ht);
}
fold_checksum_tree (TYPE_MAIN_VARIANT (expr), ctx, ht);
if (TREE_CODE (expr) == RECORD_TYPE
|| TREE_CODE (expr) == UNION_TYPE
|| TREE_CODE (expr) == QUAL_UNION_TYPE)
fold_checksum_tree (TYPE_BINFO (expr), ctx, ht);
fold_checksum_tree (TYPE_CONTEXT (expr), ctx, ht);
break;
default:
break;
}
}
/* Helper function for outputting the checksum of a tree T. When
debugging with gdb, you can "define mynext" to be "next" followed
by "call debug_fold_checksum (op0)", then just trace down till the
outputs differ. */
DEBUG_FUNCTION void
debug_fold_checksum (const_tree t)
{
int i;
unsigned char checksum[16];
struct md5_ctx ctx;
hash_table <pointer_hash <tree_node> > ht;
ht.create (32);
md5_init_ctx (&ctx);
fold_checksum_tree (t, &ctx, ht);
md5_finish_ctx (&ctx, checksum);
ht.empty ();
for (i = 0; i < 16; i++)
fprintf (stderr, "%d ", checksum[i]);
fprintf (stderr, "\n");
}
#endif
/* Fold a unary tree expression with code CODE of type TYPE with an
operand OP0. LOC is the location of the resulting expression.
Return a folded expression if successful. Otherwise, return a tree
expression with code CODE of type TYPE with an operand OP0. */
tree
fold_build1_stat_loc (location_t loc,
enum tree_code code, tree type, tree op0 MEM_STAT_DECL)
{
tree tem;
#ifdef ENABLE_FOLD_CHECKING
unsigned char checksum_before[16], checksum_after[16];
struct md5_ctx ctx;
hash_table <pointer_hash <tree_node> > ht;
ht.create (32);
md5_init_ctx (&ctx);
fold_checksum_tree (op0, &ctx, ht);
md5_finish_ctx (&ctx, checksum_before);
ht.empty ();
#endif
tem = fold_unary_loc (loc, code, type, op0);
if (!tem)
tem = build1_stat_loc (loc, code, type, op0 PASS_MEM_STAT);
#ifdef ENABLE_FOLD_CHECKING
md5_init_ctx (&ctx);
fold_checksum_tree (op0, &ctx, ht);
md5_finish_ctx (&ctx, checksum_after);
ht.dispose ();
if (memcmp (checksum_before, checksum_after, 16))
fold_check_failed (op0, tem);
#endif
return tem;
}
/* Fold a binary tree expression with code CODE of type TYPE with
operands OP0 and OP1. LOC is the location of the resulting
expression. Return a folded expression if successful. Otherwise,
return a tree expression with code CODE of type TYPE with operands
OP0 and OP1. */
tree
fold_build2_stat_loc (location_t loc,
enum tree_code code, tree type, tree op0, tree op1
MEM_STAT_DECL)
{
tree tem;
#ifdef ENABLE_FOLD_CHECKING
unsigned char checksum_before_op0[16],
checksum_before_op1[16],
checksum_after_op0[16],
checksum_after_op1[16];
struct md5_ctx ctx;
hash_table <pointer_hash <tree_node> > ht;
ht.create (32);
md5_init_ctx (&ctx);
fold_checksum_tree (op0, &ctx, ht);
md5_finish_ctx (&ctx, checksum_before_op0);
ht.empty ();
md5_init_ctx (&ctx);
fold_checksum_tree (op1, &ctx, ht);
md5_finish_ctx (&ctx, checksum_before_op1);
ht.empty ();
#endif
tem = fold_binary_loc (loc, code, type, op0, op1);
if (!tem)
tem = build2_stat_loc (loc, code, type, op0, op1 PASS_MEM_STAT);
#ifdef ENABLE_FOLD_CHECKING
md5_init_ctx (&ctx);
fold_checksum_tree (op0, &ctx, ht);
md5_finish_ctx (&ctx, checksum_after_op0);
ht.empty ();
if (memcmp (checksum_before_op0, checksum_after_op0, 16))
fold_check_failed (op0, tem);
md5_init_ctx (&ctx);
fold_checksum_tree (op1, &ctx, ht);
md5_finish_ctx (&ctx, checksum_after_op1);
ht.dispose ();
if (memcmp (checksum_before_op1, checksum_after_op1, 16))
fold_check_failed (op1, tem);
#endif
return tem;
}
/* Fold a ternary tree expression with code CODE of type TYPE with
operands OP0, OP1, and OP2. Return a folded expression if
successful. Otherwise, return a tree expression with code CODE of
type TYPE with operands OP0, OP1, and OP2. */
tree
fold_build3_stat_loc (location_t loc, enum tree_code code, tree type,
tree op0, tree op1, tree op2 MEM_STAT_DECL)
{
tree tem;
#ifdef ENABLE_FOLD_CHECKING
unsigned char checksum_before_op0[16],
checksum_before_op1[16],
checksum_before_op2[16],
checksum_after_op0[16],
checksum_after_op1[16],
checksum_after_op2[16];
struct md5_ctx ctx;
hash_table <pointer_hash <tree_node> > ht;
ht.create (32);
md5_init_ctx (&ctx);
fold_checksum_tree (op0, &ctx, ht);
md5_finish_ctx (&ctx, checksum_before_op0);
ht.empty ();
md5_init_ctx (&ctx);
fold_checksum_tree (op1, &ctx, ht);
md5_finish_ctx (&ctx, checksum_before_op1);
ht.empty ();
md5_init_ctx (&ctx);
fold_checksum_tree (op2, &ctx, ht);
md5_finish_ctx (&ctx, checksum_before_op2);
ht.empty ();
#endif
gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp);
tem = fold_ternary_loc (loc, code, type, op0, op1, op2);
if (!tem)
tem = build3_stat_loc (loc, code, type, op0, op1, op2 PASS_MEM_STAT);
#ifdef ENABLE_FOLD_CHECKING
md5_init_ctx (&ctx);
fold_checksum_tree (op0, &ctx, ht);
md5_finish_ctx (&ctx, checksum_after_op0);
ht.empty ();
if (memcmp (checksum_before_op0, checksum_after_op0, 16))
fold_check_failed (op0, tem);
md5_init_ctx (&ctx);
fold_checksum_tree (op1, &ctx, ht);
md5_finish_ctx (&ctx, checksum_after_op1);
ht.empty ();
if (memcmp (checksum_before_op1, checksum_after_op1, 16))
fold_check_failed (op1, tem);
md5_init_ctx (&ctx);
fold_checksum_tree (op2, &ctx, ht);
md5_finish_ctx (&ctx, checksum_after_op2);
ht.dispose ();
if (memcmp (checksum_before_op2, checksum_after_op2, 16))
fold_check_failed (op2, tem);
#endif
return tem;
}
/* Fold a CALL_EXPR expression of type TYPE with operands FN and NARGS
arguments in ARGARRAY, and a null static chain.
Return a folded expression if successful. Otherwise, return a CALL_EXPR
of type TYPE from the given operands as constructed by build_call_array. */
tree
fold_build_call_array_loc (location_t loc, tree type, tree fn,
int nargs, tree *argarray)
{
tree tem;
#ifdef ENABLE_FOLD_CHECKING
unsigned char checksum_before_fn[16],
checksum_before_arglist[16],
checksum_after_fn[16],
checksum_after_arglist[16];
struct md5_ctx ctx;
hash_table <pointer_hash <tree_node> > ht;
int i;
ht.create (32);
md5_init_ctx (&ctx);
fold_checksum_tree (fn, &ctx, ht);
md5_finish_ctx (&ctx, checksum_before_fn);
ht.empty ();
md5_init_ctx (&ctx);
for (i = 0; i < nargs; i++)
fold_checksum_tree (argarray[i], &ctx, ht);
md5_finish_ctx (&ctx, checksum_before_arglist);
ht.empty ();
#endif
tem = fold_builtin_call_array (loc, type, fn, nargs, argarray);
#ifdef ENABLE_FOLD_CHECKING
md5_init_ctx (&ctx);
fold_checksum_tree (fn, &ctx, ht);
md5_finish_ctx (&ctx, checksum_after_fn);
ht.empty ();
if (memcmp (checksum_before_fn, checksum_after_fn, 16))
fold_check_failed (fn, tem);
md5_init_ctx (&ctx);
for (i = 0; i < nargs; i++)
fold_checksum_tree (argarray[i], &ctx, ht);
md5_finish_ctx (&ctx, checksum_after_arglist);
ht.dispose ();
if (memcmp (checksum_before_arglist, checksum_after_arglist, 16))
fold_check_failed (NULL_TREE, tem);
#endif
return tem;
}
/* Perform constant folding and related simplification of initializer
expression EXPR. These behave identically to "fold_buildN" but ignore
potential run-time traps and exceptions that fold must preserve. */
#define START_FOLD_INIT \
int saved_signaling_nans = flag_signaling_nans;\
int saved_trapping_math = flag_trapping_math;\
int saved_rounding_math = flag_rounding_math;\
int saved_trapv = flag_trapv;\
int saved_folding_initializer = folding_initializer;\
flag_signaling_nans = 0;\
flag_trapping_math = 0;\
flag_rounding_math = 0;\
flag_trapv = 0;\
folding_initializer = 1;
#define END_FOLD_INIT \
flag_signaling_nans = saved_signaling_nans;\
flag_trapping_math = saved_trapping_math;\
flag_rounding_math = saved_rounding_math;\
flag_trapv = saved_trapv;\
folding_initializer = saved_folding_initializer;
tree
fold_build1_initializer_loc (location_t loc, enum tree_code code,
tree type, tree op)
{
tree result;
START_FOLD_INIT;
result = fold_build1_loc (loc, code, type, op);
END_FOLD_INIT;
return result;
}
tree
fold_build2_initializer_loc (location_t loc, enum tree_code code,
tree type, tree op0, tree op1)
{
tree result;
START_FOLD_INIT;
result = fold_build2_loc (loc, code, type, op0, op1);
END_FOLD_INIT;
return result;
}
tree
fold_build3_initializer_loc (location_t loc, enum tree_code code,
tree type, tree op0, tree op1, tree op2)
{
tree result;
START_FOLD_INIT;
result = fold_build3_loc (loc, code, type, op0, op1, op2);
END_FOLD_INIT;
return result;
}
tree
fold_build_call_array_initializer_loc (location_t loc, tree type, tree fn,
int nargs, tree *argarray)
{
tree result;
START_FOLD_INIT;
result = fold_build_call_array_loc (loc, type, fn, nargs, argarray);
END_FOLD_INIT;
return result;
}
#undef START_FOLD_INIT
#undef END_FOLD_INIT
/* Determine if first argument is a multiple of second argument. Return 0 if
it is not, or we cannot easily determined it to be.
An example of the sort of thing we care about (at this point; this routine
could surely be made more general, and expanded to do what the *_DIV_EXPR's
fold cases do now) is discovering that
SAVE_EXPR (I) * SAVE_EXPR (J * 8)
is a multiple of
SAVE_EXPR (J * 8)
when we know that the two SAVE_EXPR (J * 8) nodes are the same node.
This code also handles discovering that
SAVE_EXPR (I) * SAVE_EXPR (J * 8)
is a multiple of 8 so we don't have to worry about dealing with a
possible remainder.
Note that we *look* inside a SAVE_EXPR only to determine how it was
calculated; it is not safe for fold to do much of anything else with the
internals of a SAVE_EXPR, since it cannot know when it will be evaluated
at run time. For example, the latter example above *cannot* be implemented
as SAVE_EXPR (I) * J or any variant thereof, since the value of J at
evaluation time of the original SAVE_EXPR is not necessarily the same at
the time the new expression is evaluated. The only optimization of this
sort that would be valid is changing
SAVE_EXPR (I) * SAVE_EXPR (SAVE_EXPR (J) * 8)
divided by 8 to
SAVE_EXPR (I) * SAVE_EXPR (J)
(where the same SAVE_EXPR (J) is used in the original and the
transformed version). */
int
multiple_of_p (tree type, const_tree top, const_tree bottom)
{
if (operand_equal_p (top, bottom, 0))
return 1;
if (TREE_CODE (type) != INTEGER_TYPE)
return 0;
switch (TREE_CODE (top))
{
case BIT_AND_EXPR:
/* Bitwise and provides a power of two multiple. If the mask is
a multiple of BOTTOM then TOP is a multiple of BOTTOM. */
if (!integer_pow2p (bottom))
return 0;
/* FALLTHRU */
case MULT_EXPR:
return (multiple_of_p (type, TREE_OPERAND (top, 0), bottom)
|| multiple_of_p (type, TREE_OPERAND (top, 1), bottom));
case PLUS_EXPR:
case MINUS_EXPR:
return (multiple_of_p (type, TREE_OPERAND (top, 0), bottom)
&& multiple_of_p (type, TREE_OPERAND (top, 1), bottom));
case LSHIFT_EXPR:
if (TREE_CODE (TREE_OPERAND (top, 1)) == INTEGER_CST)
{
tree op1, t1;
op1 = TREE_OPERAND (top, 1);
/* const_binop may not detect overflow correctly,
so check for it explicitly here. */
if (TYPE_PRECISION (TREE_TYPE (size_one_node))
> TREE_INT_CST_LOW (op1)
&& TREE_INT_CST_HIGH (op1) == 0
&& 0 != (t1 = fold_convert (type,
const_binop (LSHIFT_EXPR,
size_one_node,
op1)))
&& !TREE_OVERFLOW (t1))
return multiple_of_p (type, t1, bottom);
}
return 0;
case NOP_EXPR:
/* Can't handle conversions from non-integral or wider integral type. */
if ((TREE_CODE (TREE_TYPE (TREE_OPERAND (top, 0))) != INTEGER_TYPE)
|| (TYPE_PRECISION (type)
< TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (top, 0)))))
return 0;
/* .. fall through ... */
case SAVE_EXPR:
return multiple_of_p (type, TREE_OPERAND (top, 0), bottom);
case COND_EXPR:
return (multiple_of_p (type, TREE_OPERAND (top, 1), bottom)
&& multiple_of_p (type, TREE_OPERAND (top, 2), bottom));
case INTEGER_CST:
if (TREE_CODE (bottom) != INTEGER_CST
|| integer_zerop (bottom)
|| (TYPE_UNSIGNED (type)
&& (tree_int_cst_sgn (top) < 0
|| tree_int_cst_sgn (bottom) < 0)))
return 0;
return integer_zerop (int_const_binop (TRUNC_MOD_EXPR,
top, bottom));
default:
return 0;
}
}
/* Return true if CODE or TYPE is known to be non-negative. */
static bool
tree_simple_nonnegative_warnv_p (enum tree_code code, tree type)
{
if ((TYPE_PRECISION (type) != 1 || TYPE_UNSIGNED (type))
&& truth_value_p (code))
/* Truth values evaluate to 0 or 1, which is nonnegative unless we
have a signed:1 type (where the value is -1 and 0). */
return true;
return false;
}
/* Return true if (CODE OP0) is known to be non-negative. If the return
value is based on the assumption that signed overflow is undefined,
set *STRICT_OVERFLOW_P to true; otherwise, don't change
*STRICT_OVERFLOW_P. */
bool
tree_unary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0,
bool *strict_overflow_p)
{
if (TYPE_UNSIGNED (type))
return true;
switch (code)
{
case ABS_EXPR:
/* We can't return 1 if flag_wrapv is set because
ABS_EXPR<INT_MIN> = INT_MIN. */
if (!INTEGRAL_TYPE_P (type))
return true;
if (TYPE_OVERFLOW_UNDEFINED (type))
{
*strict_overflow_p = true;
return true;
}
break;
case NON_LVALUE_EXPR:
case FLOAT_EXPR:
case FIX_TRUNC_EXPR:
return tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p);
case NOP_EXPR:
{
tree inner_type = TREE_TYPE (op0);
tree outer_type = type;
if (TREE_CODE (outer_type) == REAL_TYPE)
{
if (TREE_CODE (inner_type) == REAL_TYPE)
return tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p);
if (TREE_CODE (inner_type) == INTEGER_TYPE)
{
if (TYPE_UNSIGNED (inner_type))
return true;
return tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p);
}
}
else if (TREE_CODE (outer_type) == INTEGER_TYPE)
{
if (TREE_CODE (inner_type) == REAL_TYPE)
return tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p);
if (TREE_CODE (inner_type) == INTEGER_TYPE)
return TYPE_PRECISION (inner_type) < TYPE_PRECISION (outer_type)
&& TYPE_UNSIGNED (inner_type);
}
}
break;
default:
return tree_simple_nonnegative_warnv_p (code, type);
}
/* We don't know sign of `t', so be conservative and return false. */
return false;
}
/* Return true if (CODE OP0 OP1) is known to be non-negative. If the return
value is based on the assumption that signed overflow is undefined,
set *STRICT_OVERFLOW_P to true; otherwise, don't change
*STRICT_OVERFLOW_P. */
bool
tree_binary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0,
tree op1, bool *strict_overflow_p)
{
if (TYPE_UNSIGNED (type))
return true;
switch (code)
{
case POINTER_PLUS_EXPR:
case PLUS_EXPR:
if (FLOAT_TYPE_P (type))
return (tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p)
&& tree_expr_nonnegative_warnv_p (op1,
strict_overflow_p));
/* zero_extend(x) + zero_extend(y) is non-negative if x and y are
both unsigned and at least 2 bits shorter than the result. */
if (TREE_CODE (type) == INTEGER_TYPE
&& TREE_CODE (op0) == NOP_EXPR
&& TREE_CODE (op1) == NOP_EXPR)
{
tree inner1 = TREE_TYPE (TREE_OPERAND (op0, 0));
tree inner2 = TREE_TYPE (TREE_OPERAND (op1, 0));
if (TREE_CODE (inner1) == INTEGER_TYPE && TYPE_UNSIGNED (inner1)
&& TREE_CODE (inner2) == INTEGER_TYPE && TYPE_UNSIGNED (inner2))
{
unsigned int prec = MAX (TYPE_PRECISION (inner1),
TYPE_PRECISION (inner2)) + 1;
return prec < TYPE_PRECISION (type);
}
}
break;
case MULT_EXPR:
if (FLOAT_TYPE_P (type))
{
/* x * x for floating point x is always non-negative. */
if (operand_equal_p (op0, op1, 0))
return true;
return (tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p)
&& tree_expr_nonnegative_warnv_p (op1,
strict_overflow_p));
}
/* zero_extend(x) * zero_extend(y) is non-negative if x and y are
both unsigned and their total bits is shorter than the result. */
if (TREE_CODE (type) == INTEGER_TYPE
&& (TREE_CODE (op0) == NOP_EXPR || TREE_CODE (op0) == INTEGER_CST)
&& (TREE_CODE (op1) == NOP_EXPR || TREE_CODE (op1) == INTEGER_CST))
{
tree inner0 = (TREE_CODE (op0) == NOP_EXPR)
? TREE_TYPE (TREE_OPERAND (op0, 0))
: TREE_TYPE (op0);
tree inner1 = (TREE_CODE (op1) == NOP_EXPR)
? TREE_TYPE (TREE_OPERAND (op1, 0))
: TREE_TYPE (op1);
bool unsigned0 = TYPE_UNSIGNED (inner0);
bool unsigned1 = TYPE_UNSIGNED (inner1);
if (TREE_CODE (op0) == INTEGER_CST)
unsigned0 = unsigned0 || tree_int_cst_sgn (op0) >= 0;
if (TREE_CODE (op1) == INTEGER_CST)
unsigned1 = unsigned1 || tree_int_cst_sgn (op1) >= 0;
if (TREE_CODE (inner0) == INTEGER_TYPE && unsigned0
&& TREE_CODE (inner1) == INTEGER_TYPE && unsigned1)
{
unsigned int precision0 = (TREE_CODE (op0) == INTEGER_CST)
? tree_int_cst_min_precision (op0, /*unsignedp=*/true)
: TYPE_PRECISION (inner0);
unsigned int precision1 = (TREE_CODE (op1) == INTEGER_CST)
? tree_int_cst_min_precision (op1, /*unsignedp=*/true)
: TYPE_PRECISION (inner1);
return precision0 + precision1 < TYPE_PRECISION (type);
}
}
return false;
case BIT_AND_EXPR:
case MAX_EXPR:
return (tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p)
|| tree_expr_nonnegative_warnv_p (op1,
strict_overflow_p));
case BIT_IOR_EXPR:
case BIT_XOR_EXPR:
case MIN_EXPR:
case RDIV_EXPR:
case TRUNC_DIV_EXPR:
case CEIL_DIV_EXPR:
case FLOOR_DIV_EXPR:
case ROUND_DIV_EXPR:
return (tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p)
&& tree_expr_nonnegative_warnv_p (op1,
strict_overflow_p));
case TRUNC_MOD_EXPR:
case CEIL_MOD_EXPR:
case FLOOR_MOD_EXPR:
case ROUND_MOD_EXPR:
return tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p);
default:
return tree_simple_nonnegative_warnv_p (code, type);
}
/* We don't know sign of `t', so be conservative and return false. */
return false;
}
/* Return true if T is known to be non-negative. If the return
value is based on the assumption that signed overflow is undefined,
set *STRICT_OVERFLOW_P to true; otherwise, don't change
*STRICT_OVERFLOW_P. */
bool
tree_single_nonnegative_warnv_p (tree t, bool *strict_overflow_p)
{
if (TYPE_UNSIGNED (TREE_TYPE (t)))
return true;
switch (TREE_CODE (t))
{
case INTEGER_CST:
return tree_int_cst_sgn (t) >= 0;
case REAL_CST:
return ! REAL_VALUE_NEGATIVE (TREE_REAL_CST (t));
case FIXED_CST:
return ! FIXED_VALUE_NEGATIVE (TREE_FIXED_CST (t));
case COND_EXPR:
return (tree_expr_nonnegative_warnv_p (TREE_OPERAND (t, 1),
strict_overflow_p)
&& tree_expr_nonnegative_warnv_p (TREE_OPERAND (t, 2),
strict_overflow_p));
default:
return tree_simple_nonnegative_warnv_p (TREE_CODE (t),
TREE_TYPE (t));
}
/* We don't know sign of `t', so be conservative and return false. */
return false;
}
/* Return true if T is known to be non-negative. If the return
value is based on the assumption that signed overflow is undefined,
set *STRICT_OVERFLOW_P to true; otherwise, don't change
*STRICT_OVERFLOW_P. */
bool
tree_call_nonnegative_warnv_p (tree type, tree fndecl,
tree arg0, tree arg1, bool *strict_overflow_p)
{
if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
switch (DECL_FUNCTION_CODE (fndecl))
{
CASE_FLT_FN (BUILT_IN_ACOS):
CASE_FLT_FN (BUILT_IN_ACOSH):
CASE_FLT_FN (BUILT_IN_CABS):
CASE_FLT_FN (BUILT_IN_COSH):
CASE_FLT_FN (BUILT_IN_ERFC):
CASE_FLT_FN (BUILT_IN_EXP):
CASE_FLT_FN (BUILT_IN_EXP10):
CASE_FLT_FN (BUILT_IN_EXP2):
CASE_FLT_FN (BUILT_IN_FABS):
CASE_FLT_FN (BUILT_IN_FDIM):
CASE_FLT_FN (BUILT_IN_HYPOT):
CASE_FLT_FN (BUILT_IN_POW10):
CASE_INT_FN (BUILT_IN_FFS):
CASE_INT_FN (BUILT_IN_PARITY):
CASE_INT_FN (BUILT_IN_POPCOUNT):
case BUILT_IN_BSWAP32:
case BUILT_IN_BSWAP64:
/* Always true. */
return true;
CASE_FLT_FN (BUILT_IN_SQRT):
/* sqrt(-0.0) is -0.0. */
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (type)))
return true;
return tree_expr_nonnegative_warnv_p (arg0,
strict_overflow_p);
CASE_FLT_FN (BUILT_IN_ASINH):
CASE_FLT_FN (BUILT_IN_ATAN):
CASE_FLT_FN (BUILT_IN_ATANH):
CASE_FLT_FN (BUILT_IN_CBRT):
CASE_FLT_FN (BUILT_IN_CEIL):
CASE_FLT_FN (BUILT_IN_ERF):
CASE_FLT_FN (BUILT_IN_EXPM1):
CASE_FLT_FN (BUILT_IN_FLOOR):
CASE_FLT_FN (BUILT_IN_FMOD):
CASE_FLT_FN (BUILT_IN_FREXP):
CASE_FLT_FN (BUILT_IN_ICEIL):
CASE_FLT_FN (BUILT_IN_IFLOOR):
CASE_FLT_FN (BUILT_IN_IRINT):
CASE_FLT_FN (BUILT_IN_IROUND):
CASE_FLT_FN (BUILT_IN_LCEIL):
CASE_FLT_FN (BUILT_IN_LDEXP):
CASE_FLT_FN (BUILT_IN_LFLOOR):
CASE_FLT_FN (BUILT_IN_LLCEIL):
CASE_FLT_FN (BUILT_IN_LLFLOOR):
CASE_FLT_FN (BUILT_IN_LLRINT):
CASE_FLT_FN (BUILT_IN_LLROUND):
CASE_FLT_FN (BUILT_IN_LRINT):
CASE_FLT_FN (BUILT_IN_LROUND):
CASE_FLT_FN (BUILT_IN_MODF):
CASE_FLT_FN (BUILT_IN_NEARBYINT):
CASE_FLT_FN (BUILT_IN_RINT):
CASE_FLT_FN (BUILT_IN_ROUND):
CASE_FLT_FN (BUILT_IN_SCALB):
CASE_FLT_FN (BUILT_IN_SCALBLN):
CASE_FLT_FN (BUILT_IN_SCALBN):
CASE_FLT_FN (BUILT_IN_SIGNBIT):
CASE_FLT_FN (BUILT_IN_SIGNIFICAND):
CASE_FLT_FN (BUILT_IN_SINH):
CASE_FLT_FN (BUILT_IN_TANH):
CASE_FLT_FN (BUILT_IN_TRUNC):
/* True if the 1st argument is nonnegative. */
return tree_expr_nonnegative_warnv_p (arg0,
strict_overflow_p);
CASE_FLT_FN (BUILT_IN_FMAX):
/* True if the 1st OR 2nd arguments are nonnegative. */
return (tree_expr_nonnegative_warnv_p (arg0,
strict_overflow_p)
|| (tree_expr_nonnegative_warnv_p (arg1,
strict_overflow_p)));
CASE_FLT_FN (BUILT_IN_FMIN):
/* True if the 1st AND 2nd arguments are nonnegative. */
return (tree_expr_nonnegative_warnv_p (arg0,
strict_overflow_p)
&& (tree_expr_nonnegative_warnv_p (arg1,
strict_overflow_p)));
CASE_FLT_FN (BUILT_IN_COPYSIGN):
/* True if the 2nd argument is nonnegative. */
return tree_expr_nonnegative_warnv_p (arg1,
strict_overflow_p);
CASE_FLT_FN (BUILT_IN_POWI):
/* True if the 1st argument is nonnegative or the second
argument is an even integer. */
if (TREE_CODE (arg1) == INTEGER_CST
&& (TREE_INT_CST_LOW (arg1) & 1) == 0)
return true;
return tree_expr_nonnegative_warnv_p (arg0,
strict_overflow_p);
CASE_FLT_FN (BUILT_IN_POW):
/* True if the 1st argument is nonnegative or the second
argument is an even integer valued real. */
if (TREE_CODE (arg1) == REAL_CST)
{
REAL_VALUE_TYPE c;
HOST_WIDE_INT n;
c = TREE_REAL_CST (arg1);
n = real_to_integer (&c);
if ((n & 1) == 0)
{
REAL_VALUE_TYPE cint;
real_from_integer (&cint, VOIDmode, n,
n < 0 ? -1 : 0, 0);
if (real_identical (&c, &cint))
return true;
}
}
return tree_expr_nonnegative_warnv_p (arg0,
strict_overflow_p);
default:
break;
}
return tree_simple_nonnegative_warnv_p (CALL_EXPR,
type);
}
/* Return true if T is known to be non-negative. If the return
value is based on the assumption that signed overflow is undefined,
set *STRICT_OVERFLOW_P to true; otherwise, don't change
*STRICT_OVERFLOW_P. */
bool
tree_invalid_nonnegative_warnv_p (tree t, bool *strict_overflow_p)
{
enum tree_code code = TREE_CODE (t);
if (TYPE_UNSIGNED (TREE_TYPE (t)))
return true;
switch (code)
{
case TARGET_EXPR:
{
tree temp = TARGET_EXPR_SLOT (t);
t = TARGET_EXPR_INITIAL (t);
/* If the initializer is non-void, then it's a normal expression
that will be assigned to the slot. */
if (!VOID_TYPE_P (t))
return tree_expr_nonnegative_warnv_p (t, strict_overflow_p);
/* Otherwise, the initializer sets the slot in some way. One common
way is an assignment statement at the end of the initializer. */
while (1)
{
if (TREE_CODE (t) == BIND_EXPR)
t = expr_last (BIND_EXPR_BODY (t));
else if (TREE_CODE (t) == TRY_FINALLY_EXPR
|| TREE_CODE (t) == TRY_CATCH_EXPR)
t = expr_last (TREE_OPERAND (t, 0));
else if (TREE_CODE (t) == STATEMENT_LIST)
t = expr_last (t);
else
break;
}
if (TREE_CODE (t) == MODIFY_EXPR
&& TREE_OPERAND (t, 0) == temp)
return tree_expr_nonnegative_warnv_p (TREE_OPERAND (t, 1),
strict_overflow_p);
return false;
}
case CALL_EXPR:
{
tree arg0 = call_expr_nargs (t) > 0 ? CALL_EXPR_ARG (t, 0) : NULL_TREE;
tree arg1 = call_expr_nargs (t) > 1 ? CALL_EXPR_ARG (t, 1) : NULL_TREE;
return tree_call_nonnegative_warnv_p (TREE_TYPE (t),
get_callee_fndecl (t),
arg0,
arg1,
strict_overflow_p);
}
case COMPOUND_EXPR:
case MODIFY_EXPR:
return tree_expr_nonnegative_warnv_p (TREE_OPERAND (t, 1),
strict_overflow_p);
case BIND_EXPR:
return tree_expr_nonnegative_warnv_p (expr_last (TREE_OPERAND (t, 1)),
strict_overflow_p);
case SAVE_EXPR:
return tree_expr_nonnegative_warnv_p (TREE_OPERAND (t, 0),
strict_overflow_p);
default:
return tree_simple_nonnegative_warnv_p (TREE_CODE (t),
TREE_TYPE (t));
}
/* We don't know sign of `t', so be conservative and return false. */
return false;
}
/* Return true if T is known to be non-negative. If the return
value is based on the assumption that signed overflow is undefined,
set *STRICT_OVERFLOW_P to true; otherwise, don't change
*STRICT_OVERFLOW_P. */
bool
tree_expr_nonnegative_warnv_p (tree t, bool *strict_overflow_p)
{
enum tree_code code;
if (t == error_mark_node)
return false;
code = TREE_CODE (t);
switch (TREE_CODE_CLASS (code))
{
case tcc_binary:
case tcc_comparison:
return tree_binary_nonnegative_warnv_p (TREE_CODE (t),
TREE_TYPE (t),
TREE_OPERAND (t, 0),
TREE_OPERAND (t, 1),
strict_overflow_p);
case tcc_unary:
return tree_unary_nonnegative_warnv_p (TREE_CODE (t),
TREE_TYPE (t),
TREE_OPERAND (t, 0),
strict_overflow_p);
case tcc_constant:
case tcc_declaration:
case tcc_reference:
return tree_single_nonnegative_warnv_p (t, strict_overflow_p);
default:
break;
}
switch (code)
{
case TRUTH_AND_EXPR:
case TRUTH_OR_EXPR:
case TRUTH_XOR_EXPR:
return tree_binary_nonnegative_warnv_p (TREE_CODE (t),
TREE_TYPE (t),
TREE_OPERAND (t, 0),
TREE_OPERAND (t, 1),
strict_overflow_p);
case TRUTH_NOT_EXPR:
return tree_unary_nonnegative_warnv_p (TREE_CODE (t),
TREE_TYPE (t),
TREE_OPERAND (t, 0),
strict_overflow_p);
case COND_EXPR:
case CONSTRUCTOR:
case OBJ_TYPE_REF:
case ASSERT_EXPR:
case ADDR_EXPR:
case WITH_SIZE_EXPR:
case SSA_NAME:
return tree_single_nonnegative_warnv_p (t, strict_overflow_p);
default:
return tree_invalid_nonnegative_warnv_p (t, strict_overflow_p);
}
}
/* Return true if `t' is known to be non-negative. Handle warnings
about undefined signed overflow. */
bool
tree_expr_nonnegative_p (tree t)
{
bool ret, strict_overflow_p;
strict_overflow_p = false;
ret = tree_expr_nonnegative_warnv_p (t, &strict_overflow_p);
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not occur when "
"determining that expression is always "
"non-negative"),
WARN_STRICT_OVERFLOW_MISC);
return ret;
}
/* Return true when (CODE OP0) is an address and is known to be nonzero.
For floating point we further ensure that T is not denormal.
Similar logic is present in nonzero_address in rtlanal.h.
If the return value is based on the assumption that signed overflow
is undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't
change *STRICT_OVERFLOW_P. */
bool
tree_unary_nonzero_warnv_p (enum tree_code code, tree type, tree op0,
bool *strict_overflow_p)
{
switch (code)
{
case ABS_EXPR:
return tree_expr_nonzero_warnv_p (op0,
strict_overflow_p);
case NOP_EXPR:
{
tree inner_type = TREE_TYPE (op0);
tree outer_type = type;
return (TYPE_PRECISION (outer_type) >= TYPE_PRECISION (inner_type)
&& tree_expr_nonzero_warnv_p (op0,
strict_overflow_p));
}
break;
case NON_LVALUE_EXPR:
return tree_expr_nonzero_warnv_p (op0,
strict_overflow_p);
default:
break;
}
return false;
}
/* Return true when (CODE OP0 OP1) is an address and is known to be nonzero.
For floating point we further ensure that T is not denormal.
Similar logic is present in nonzero_address in rtlanal.h.
If the return value is based on the assumption that signed overflow
is undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't
change *STRICT_OVERFLOW_P. */
bool
tree_binary_nonzero_warnv_p (enum tree_code code,
tree type,
tree op0,
tree op1, bool *strict_overflow_p)
{
bool sub_strict_overflow_p;
switch (code)
{
case POINTER_PLUS_EXPR:
case PLUS_EXPR:
if (TYPE_OVERFLOW_UNDEFINED (type))
{
/* With the presence of negative values it is hard
to say something. */
sub_strict_overflow_p = false;
if (!tree_expr_nonnegative_warnv_p (op0,
&sub_strict_overflow_p)
|| !tree_expr_nonnegative_warnv_p (op1,
&sub_strict_overflow_p))
return false;
/* One of operands must be positive and the other non-negative. */
/* We don't set *STRICT_OVERFLOW_P here: even if this value
overflows, on a twos-complement machine the sum of two
nonnegative numbers can never be zero. */
return (tree_expr_nonzero_warnv_p (op0,
strict_overflow_p)
|| tree_expr_nonzero_warnv_p (op1,
strict_overflow_p));
}
break;
case MULT_EXPR:
if (TYPE_OVERFLOW_UNDEFINED (type))
{
if (tree_expr_nonzero_warnv_p (op0,
strict_overflow_p)
&& tree_expr_nonzero_warnv_p (op1,
strict_overflow_p))
{
*strict_overflow_p = true;
return true;
}
}
break;
case MIN_EXPR:
sub_strict_overflow_p = false;
if (tree_expr_nonzero_warnv_p (op0,
&sub_strict_overflow_p)
&& tree_expr_nonzero_warnv_p (op1,
&sub_strict_overflow_p))
{
if (sub_strict_overflow_p)
*strict_overflow_p = true;
}
break;
case MAX_EXPR:
sub_strict_overflow_p = false;
if (tree_expr_nonzero_warnv_p (op0,
&sub_strict_overflow_p))
{
if (sub_strict_overflow_p)
*strict_overflow_p = true;
/* When both operands are nonzero, then MAX must be too. */
if (tree_expr_nonzero_warnv_p (op1,
strict_overflow_p))
return true;
/* MAX where operand 0 is positive is positive. */
return tree_expr_nonnegative_warnv_p (op0,
strict_overflow_p);
}
/* MAX where operand 1 is positive is positive. */
else if (tree_expr_nonzero_warnv_p (op1,
&sub_strict_overflow_p)
&& tree_expr_nonnegative_warnv_p (op1,
&sub_strict_overflow_p))
{
if (sub_strict_overflow_p)
*strict_overflow_p = true;
return true;
}
break;
case BIT_IOR_EXPR:
return (tree_expr_nonzero_warnv_p (op1,
strict_overflow_p)
|| tree_expr_nonzero_warnv_p (op0,
strict_overflow_p));
default:
break;
}
return false;
}
/* Return true when T is an address and is known to be nonzero.
For floating point we further ensure that T is not denormal.
Similar logic is present in nonzero_address in rtlanal.h.
If the return value is based on the assumption that signed overflow
is undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't
change *STRICT_OVERFLOW_P. */
bool
tree_single_nonzero_warnv_p (tree t, bool *strict_overflow_p)
{
bool sub_strict_overflow_p;
switch (TREE_CODE (t))
{
case INTEGER_CST:
return !integer_zerop (t);
case ADDR_EXPR:
{
tree base = TREE_OPERAND (t, 0);
if (!DECL_P (base))
base = get_base_address (base);
if (!base)
return false;
/* Weak declarations may link to NULL. Other things may also be NULL
so protect with -fdelete-null-pointer-checks; but not variables
allocated on the stack. */
if (DECL_P (base)
&& (flag_delete_null_pointer_checks
|| (DECL_CONTEXT (base)
&& TREE_CODE (DECL_CONTEXT (base)) == FUNCTION_DECL
&& auto_var_in_fn_p (base, DECL_CONTEXT (base)))))
return !VAR_OR_FUNCTION_DECL_P (base) || !DECL_WEAK (base);
/* Constants are never weak. */
if (CONSTANT_CLASS_P (base))
return true;
return false;
}
case COND_EXPR:
sub_strict_overflow_p = false;
if (tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 1),
&sub_strict_overflow_p)
&& tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 2),
&sub_strict_overflow_p))
{
if (sub_strict_overflow_p)
*strict_overflow_p = true;
return true;
}
break;
default:
break;
}
return false;
}
/* Return true when T is an address and is known to be nonzero.
For floating point we further ensure that T is not denormal.
Similar logic is present in nonzero_address in rtlanal.h.
If the return value is based on the assumption that signed overflow
is undefined, set *STRICT_OVERFLOW_P to true; otherwise, don't
change *STRICT_OVERFLOW_P. */
bool
tree_expr_nonzero_warnv_p (tree t, bool *strict_overflow_p)
{
tree type = TREE_TYPE (t);
enum tree_code code;
/* Doing something useful for floating point would need more work. */
if (!INTEGRAL_TYPE_P (type) && !POINTER_TYPE_P (type))
return false;
code = TREE_CODE (t);
switch (TREE_CODE_CLASS (code))
{
case tcc_unary:
return tree_unary_nonzero_warnv_p (code, type, TREE_OPERAND (t, 0),
strict_overflow_p);
case tcc_binary:
case tcc_comparison:
return tree_binary_nonzero_warnv_p (code, type,
TREE_OPERAND (t, 0),
TREE_OPERAND (t, 1),
strict_overflow_p);
case tcc_constant:
case tcc_declaration:
case tcc_reference:
return tree_single_nonzero_warnv_p (t, strict_overflow_p);
default:
break;
}
switch (code)
{
case TRUTH_NOT_EXPR:
return tree_unary_nonzero_warnv_p (code, type, TREE_OPERAND (t, 0),
strict_overflow_p);
case TRUTH_AND_EXPR:
case TRUTH_OR_EXPR:
case TRUTH_XOR_EXPR:
return tree_binary_nonzero_warnv_p (code, type,
TREE_OPERAND (t, 0),
TREE_OPERAND (t, 1),
strict_overflow_p);
case COND_EXPR:
case CONSTRUCTOR:
case OBJ_TYPE_REF:
case ASSERT_EXPR:
case ADDR_EXPR:
case WITH_SIZE_EXPR:
case SSA_NAME:
return tree_single_nonzero_warnv_p (t, strict_overflow_p);
case COMPOUND_EXPR:
case MODIFY_EXPR:
case BIND_EXPR:
return tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 1),
strict_overflow_p);
case SAVE_EXPR:
return tree_expr_nonzero_warnv_p (TREE_OPERAND (t, 0),
strict_overflow_p);
case CALL_EXPR:
return alloca_call_p (t);
default:
break;
}
return false;
}
/* Return true when T is an address and is known to be nonzero.
Handle warnings about undefined signed overflow. */
bool
tree_expr_nonzero_p (tree t)
{
bool ret, strict_overflow_p;
strict_overflow_p = false;
ret = tree_expr_nonzero_warnv_p (t, &strict_overflow_p);
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not occur when "
"determining that expression is always "
"non-zero"),
WARN_STRICT_OVERFLOW_MISC);
return ret;
}
/* Given the components of a binary expression CODE, TYPE, OP0 and OP1,
attempt to fold the expression to a constant without modifying TYPE,
OP0 or OP1.
If the expression could be simplified to a constant, then return
the constant. If the expression would not be simplified to a
constant, then return NULL_TREE. */
tree
fold_binary_to_constant (enum tree_code code, tree type, tree op0, tree op1)
{
tree tem = fold_binary (code, type, op0, op1);
return (tem && TREE_CONSTANT (tem)) ? tem : NULL_TREE;
}
/* Given the components of a unary expression CODE, TYPE and OP0,
attempt to fold the expression to a constant without modifying
TYPE or OP0.
If the expression could be simplified to a constant, then return
the constant. If the expression would not be simplified to a
constant, then return NULL_TREE. */
tree
fold_unary_to_constant (enum tree_code code, tree type, tree op0)
{
tree tem = fold_unary (code, type, op0);
return (tem && TREE_CONSTANT (tem)) ? tem : NULL_TREE;
}
/* If EXP represents referencing an element in a constant string
(either via pointer arithmetic or array indexing), return the
tree representing the value accessed, otherwise return NULL. */
tree
fold_read_from_constant_string (tree exp)
{
if ((TREE_CODE (exp) == INDIRECT_REF
|| TREE_CODE (exp) == ARRAY_REF)
&& TREE_CODE (TREE_TYPE (exp)) == INTEGER_TYPE)
{
tree exp1 = TREE_OPERAND (exp, 0);
tree index;
tree string;
location_t loc = EXPR_LOCATION (exp);
if (TREE_CODE (exp) == INDIRECT_REF)
string = string_constant (exp1, &index);
else
{
tree low_bound = array_ref_low_bound (exp);
index = fold_convert_loc (loc, sizetype, TREE_OPERAND (exp, 1));
/* Optimize the special-case of a zero lower bound.
We convert the low_bound to sizetype to avoid some problems
with constant folding. (E.g. suppose the lower bound is 1,
and its mode is QI. Without the conversion,l (ARRAY
+(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
+INDEX), which becomes (ARRAY+255+INDEX). Oops!) */
if (! integer_zerop (low_bound))
index = size_diffop_loc (loc, index,
fold_convert_loc (loc, sizetype, low_bound));
string = exp1;
}
if (string
&& TYPE_MODE (TREE_TYPE (exp)) == TYPE_MODE (TREE_TYPE (TREE_TYPE (string)))
&& TREE_CODE (string) == STRING_CST
&& TREE_CODE (index) == INTEGER_CST
&& compare_tree_int (index, TREE_STRING_LENGTH (string)) < 0
&& (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_TYPE (string))))
== MODE_INT)
&& (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (string)))) == 1))
return build_int_cst_type (TREE_TYPE (exp),
(TREE_STRING_POINTER (string)
[TREE_INT_CST_LOW (index)]));
}
return NULL;
}
/* Return the tree for neg (ARG0) when ARG0 is known to be either
an integer constant, real, or fixed-point constant.
TYPE is the type of the result. */
static tree
fold_negate_const (tree arg0, tree type)
{
tree t = NULL_TREE;
switch (TREE_CODE (arg0))
{
case INTEGER_CST:
{
double_int val = tree_to_double_int (arg0);
bool overflow;
val = val.neg_with_overflow (&overflow);
t = force_fit_type_double (type, val, 1,
(overflow | TREE_OVERFLOW (arg0))
&& !TYPE_UNSIGNED (type));
break;
}
case REAL_CST:
t = build_real (type, real_value_negate (&TREE_REAL_CST (arg0)));
break;
case FIXED_CST:
{
FIXED_VALUE_TYPE f;
bool overflow_p = fixed_arithmetic (&f, NEGATE_EXPR,
&(TREE_FIXED_CST (arg0)), NULL,
TYPE_SATURATING (type));
t = build_fixed (type, f);
/* Propagate overflow flags. */
if (overflow_p | TREE_OVERFLOW (arg0))
TREE_OVERFLOW (t) = 1;
break;
}
default:
gcc_unreachable ();
}
return t;
}
/* Return the tree for abs (ARG0) when ARG0 is known to be either
an integer constant or real constant.
TYPE is the type of the result. */
tree
fold_abs_const (tree arg0, tree type)
{
tree t = NULL_TREE;
switch (TREE_CODE (arg0))
{
case INTEGER_CST:
{
double_int val = tree_to_double_int (arg0);
/* If the value is unsigned or non-negative, then the absolute value
is the same as the ordinary value. */
if (TYPE_UNSIGNED (type)
|| !val.is_negative ())
t = arg0;
/* If the value is negative, then the absolute value is
its negation. */
else
{
bool overflow;
val = val.neg_with_overflow (&overflow);
t = force_fit_type_double (type, val, -1,
overflow | TREE_OVERFLOW (arg0));
}
}
break;
case REAL_CST:
if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg0)))
t = build_real (type, real_value_negate (&TREE_REAL_CST (arg0)));
else
t = arg0;
break;
default:
gcc_unreachable ();
}
return t;
}
/* Return the tree for not (ARG0) when ARG0 is known to be an integer
constant. TYPE is the type of the result. */
static tree
fold_not_const (const_tree arg0, tree type)
{
double_int val;
gcc_assert (TREE_CODE (arg0) == INTEGER_CST);
val = ~tree_to_double_int (arg0);
return force_fit_type_double (type, val, 0, TREE_OVERFLOW (arg0));
}
/* Given CODE, a relational operator, the target type, TYPE and two
constant operands OP0 and OP1, return the result of the
relational operation. If the result is not a compile time
constant, then return NULL_TREE. */
static tree
fold_relational_const (enum tree_code code, tree type, tree op0, tree op1)
{
int result, invert;
/* From here on, the only cases we handle are when the result is
known to be a constant. */
if (TREE_CODE (op0) == REAL_CST && TREE_CODE (op1) == REAL_CST)
{
const REAL_VALUE_TYPE *c0 = TREE_REAL_CST_PTR (op0);
const REAL_VALUE_TYPE *c1 = TREE_REAL_CST_PTR (op1);
/* Handle the cases where either operand is a NaN. */
if (real_isnan (c0) || real_isnan (c1))
{
switch (code)
{
case EQ_EXPR:
case ORDERED_EXPR:
result = 0;
break;
case NE_EXPR:
case UNORDERED_EXPR:
case UNLT_EXPR:
case UNLE_EXPR:
case UNGT_EXPR:
case UNGE_EXPR:
case UNEQ_EXPR:
result = 1;
break;
case LT_EXPR:
case LE_EXPR:
case GT_EXPR:
case GE_EXPR:
case LTGT_EXPR:
if (flag_trapping_math)
return NULL_TREE;
result = 0;
break;
default:
gcc_unreachable ();
}
return constant_boolean_node (result, type);
}
return constant_boolean_node (real_compare (code, c0, c1), type);
}
if (TREE_CODE (op0) == FIXED_CST && TREE_CODE (op1) == FIXED_CST)
{
const FIXED_VALUE_TYPE *c0 = TREE_FIXED_CST_PTR (op0);
const FIXED_VALUE_TYPE *c1 = TREE_FIXED_CST_PTR (op1);
return constant_boolean_node (fixed_compare (code, c0, c1), type);
}
/* Handle equality/inequality of complex constants. */
if (TREE_CODE (op0) == COMPLEX_CST && TREE_CODE (op1) == COMPLEX_CST)
{
tree rcond = fold_relational_const (code, type,
TREE_REALPART (op0),
TREE_REALPART (op1));
tree icond = fold_relational_const (code, type,
TREE_IMAGPART (op0),
TREE_IMAGPART (op1));
if (code == EQ_EXPR)
return fold_build2 (TRUTH_ANDIF_EXPR, type, rcond, icond);
else if (code == NE_EXPR)
return fold_build2 (TRUTH_ORIF_EXPR, type, rcond, icond);
else
return NULL_TREE;
}
if (TREE_CODE (op0) == VECTOR_CST && TREE_CODE (op1) == VECTOR_CST)
{
unsigned count = VECTOR_CST_NELTS (op0);
tree *elts = XALLOCAVEC (tree, count);
gcc_assert (VECTOR_CST_NELTS (op1) == count
&& TYPE_VECTOR_SUBPARTS (type) == count);
for (unsigned i = 0; i < count; i++)
{
tree elem_type = TREE_TYPE (type);
tree elem0 = VECTOR_CST_ELT (op0, i);
tree elem1 = VECTOR_CST_ELT (op1, i);
tree tem = fold_relational_const (code, elem_type,
elem0, elem1);
if (tem == NULL_TREE)
return NULL_TREE;
elts[i] = build_int_cst (elem_type, integer_zerop (tem) ? 0 : -1);
}
return build_vector (type, elts);
}
/* From here on we only handle LT, LE, GT, GE, EQ and NE.
To compute GT, swap the arguments and do LT.
To compute GE, do LT and invert the result.
To compute LE, swap the arguments, do LT and invert the result.
To compute NE, do EQ and invert the result.
Therefore, the code below must handle only EQ and LT. */
if (code == LE_EXPR || code == GT_EXPR)
{
tree tem = op0;
op0 = op1;
op1 = tem;
code = swap_tree_comparison (code);
}
/* Note that it is safe to invert for real values here because we
have already handled the one case that it matters. */
invert = 0;
if (code == NE_EXPR || code == GE_EXPR)
{
invert = 1;
code = invert_tree_comparison (code, false);
}
/* Compute a result for LT or EQ if args permit;
Otherwise return T. */
if (TREE_CODE (op0) == INTEGER_CST && TREE_CODE (op1) == INTEGER_CST)
{
if (code == EQ_EXPR)
result = tree_int_cst_equal (op0, op1);
else if (TYPE_UNSIGNED (TREE_TYPE (op0)))
result = INT_CST_LT_UNSIGNED (op0, op1);
else
result = INT_CST_LT (op0, op1);
}
else
return NULL_TREE;
if (invert)
result ^= 1;
return constant_boolean_node (result, type);
}
/* If necessary, return a CLEANUP_POINT_EXPR for EXPR with the
indicated TYPE. If no CLEANUP_POINT_EXPR is necessary, return EXPR
itself. */
tree
fold_build_cleanup_point_expr (tree type, tree expr)
{
/* If the expression does not have side effects then we don't have to wrap
it with a cleanup point expression. */
if (!TREE_SIDE_EFFECTS (expr))
return expr;
/* If the expression is a return, check to see if the expression inside the
return has no side effects or the right hand side of the modify expression
inside the return. If either don't have side effects set we don't need to
wrap the expression in a cleanup point expression. Note we don't check the
left hand side of the modify because it should always be a return decl. */
if (TREE_CODE (expr) == RETURN_EXPR)
{
tree op = TREE_OPERAND (expr, 0);
if (!op || !TREE_SIDE_EFFECTS (op))
return expr;
op = TREE_OPERAND (op, 1);
if (!TREE_SIDE_EFFECTS (op))
return expr;
}
return build1 (CLEANUP_POINT_EXPR, type, expr);
}
/* Given a pointer value OP0 and a type TYPE, return a simplified version
of an indirection through OP0, or NULL_TREE if no simplification is
possible. */
tree
fold_indirect_ref_1 (location_t loc, tree type, tree op0)
{
tree sub = op0;
tree subtype;
STRIP_NOPS (sub);
subtype = TREE_TYPE (sub);
if (!POINTER_TYPE_P (subtype))
return NULL_TREE;
if (TREE_CODE (sub) == ADDR_EXPR)
{
tree op = TREE_OPERAND (sub, 0);
tree optype = TREE_TYPE (op);
/* *&CONST_DECL -> to the value of the const decl. */
if (TREE_CODE (op) == CONST_DECL)
return DECL_INITIAL (op);
/* *&p => p; make sure to handle *&"str"[cst] here. */
if (type == optype)
{
tree fop = fold_read_from_constant_string (op);
if (fop)
return fop;
else
return op;
}
/* *(foo *)&fooarray => fooarray[0] */
else if (TREE_CODE (optype) == ARRAY_TYPE
&& type == TREE_TYPE (optype)
&& (!in_gimple_form
|| TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST))
{
tree type_domain = TYPE_DOMAIN (optype);
tree min_val = size_zero_node;
if (type_domain && TYPE_MIN_VALUE (type_domain))
min_val = TYPE_MIN_VALUE (type_domain);
if (in_gimple_form
&& TREE_CODE (min_val) != INTEGER_CST)
return NULL_TREE;
return build4_loc (loc, ARRAY_REF, type, op, min_val,
NULL_TREE, NULL_TREE);
}
/* *(foo *)&complexfoo => __real__ complexfoo */
else if (TREE_CODE (optype) == COMPLEX_TYPE
&& type == TREE_TYPE (optype))
return fold_build1_loc (loc, REALPART_EXPR, type, op);
/* *(foo *)&vectorfoo => BIT_FIELD_REF<vectorfoo,...> */
else if (TREE_CODE (optype) == VECTOR_TYPE
&& type == TREE_TYPE (optype))
{
tree part_width = TYPE_SIZE (type);
tree index = bitsize_int (0);
return fold_build3_loc (loc, BIT_FIELD_REF, type, op, part_width, index);
}
}
if (TREE_CODE (sub) == POINTER_PLUS_EXPR
&& TREE_CODE (TREE_OPERAND (sub, 1)) == INTEGER_CST)
{
tree op00 = TREE_OPERAND (sub, 0);
tree op01 = TREE_OPERAND (sub, 1);
STRIP_NOPS (op00);
if (TREE_CODE (op00) == ADDR_EXPR)
{
tree op00type;
op00 = TREE_OPERAND (op00, 0);
op00type = TREE_TYPE (op00);
/* ((foo*)&vectorfoo)[1] => BIT_FIELD_REF<vectorfoo,...> */
if (TREE_CODE (op00type) == VECTOR_TYPE
&& type == TREE_TYPE (op00type))
{
HOST_WIDE_INT offset = tree_low_cst (op01, 0);
tree part_width = TYPE_SIZE (type);
unsigned HOST_WIDE_INT part_widthi = tree_low_cst (part_width, 0)/BITS_PER_UNIT;
unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT;
tree index = bitsize_int (indexi);
if (offset/part_widthi <= TYPE_VECTOR_SUBPARTS (op00type))
return fold_build3_loc (loc,
BIT_FIELD_REF, type, op00,
part_width, index);
}
/* ((foo*)&complexfoo)[1] => __imag__ complexfoo */
else if (TREE_CODE (op00type) == COMPLEX_TYPE
&& type == TREE_TYPE (op00type))
{
tree size = TYPE_SIZE_UNIT (type);
if (tree_int_cst_equal (size, op01))
return fold_build1_loc (loc, IMAGPART_EXPR, type, op00);
}
/* ((foo *)&fooarray)[1] => fooarray[1] */
else if (TREE_CODE (op00type) == ARRAY_TYPE
&& type == TREE_TYPE (op00type))
{
tree type_domain = TYPE_DOMAIN (op00type);
tree min_val = size_zero_node;
if (type_domain && TYPE_MIN_VALUE (type_domain))
min_val = TYPE_MIN_VALUE (type_domain);
op01 = size_binop_loc (loc, EXACT_DIV_EXPR, op01,
TYPE_SIZE_UNIT (type));
op01 = size_binop_loc (loc, PLUS_EXPR, op01, min_val);
return build4_loc (loc, ARRAY_REF, type, op00, op01,
NULL_TREE, NULL_TREE);
}
}
}
/* *(foo *)fooarrptr => (*fooarrptr)[0] */
if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE
&& type == TREE_TYPE (TREE_TYPE (subtype))
&& (!in_gimple_form
|| TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST))
{
tree type_domain;
tree min_val = size_zero_node;
sub = build_fold_indirect_ref_loc (loc, sub);
type_domain = TYPE_DOMAIN (TREE_TYPE (sub));
if (type_domain && TYPE_MIN_VALUE (type_domain))
min_val = TYPE_MIN_VALUE (type_domain);
if (in_gimple_form
&& TREE_CODE (min_val) != INTEGER_CST)
return NULL_TREE;
return build4_loc (loc, ARRAY_REF, type, sub, min_val, NULL_TREE,
NULL_TREE);
}
return NULL_TREE;
}
/* Builds an expression for an indirection through T, simplifying some
cases. */
tree
build_fold_indirect_ref_loc (location_t loc, tree t)
{
tree type = TREE_TYPE (TREE_TYPE (t));
tree sub = fold_indirect_ref_1 (loc, type, t);
if (sub)
return sub;
return build1_loc (loc, INDIRECT_REF, type, t);
}
/* Given an INDIRECT_REF T, return either T or a simplified version. */
tree
fold_indirect_ref_loc (location_t loc, tree t)
{
tree sub = fold_indirect_ref_1 (loc, TREE_TYPE (t), TREE_OPERAND (t, 0));
if (sub)
return sub;
else
return t;
}
/* Strip non-trapping, non-side-effecting tree nodes from an expression
whose result is ignored. The type of the returned tree need not be
the same as the original expression. */
tree
fold_ignored_result (tree t)
{
if (!TREE_SIDE_EFFECTS (t))
return integer_zero_node;
for (;;)
switch (TREE_CODE_CLASS (TREE_CODE (t)))
{
case tcc_unary:
t = TREE_OPERAND (t, 0);
break;
case tcc_binary:
case tcc_comparison:
if (!TREE_SIDE_EFFECTS (TREE_OPERAND (t, 1)))
t = TREE_OPERAND (t, 0);
else if (!TREE_SIDE_EFFECTS (TREE_OPERAND (t, 0)))
t = TREE_OPERAND (t, 1);
else
return t;
break;
case tcc_expression:
switch (TREE_CODE (t))
{
case COMPOUND_EXPR:
if (TREE_SIDE_EFFECTS (TREE_OPERAND (t, 1)))
return t;
t = TREE_OPERAND (t, 0);
break;
case COND_EXPR:
if (TREE_SIDE_EFFECTS (TREE_OPERAND (t, 1))
|| TREE_SIDE_EFFECTS (TREE_OPERAND (t, 2)))
return t;
t = TREE_OPERAND (t, 0);
break;
default:
return t;
}
break;
default:
return t;
}
}
/* Return the value of VALUE, rounded up to a multiple of DIVISOR.
This can only be applied to objects of a sizetype. */
tree
round_up_loc (location_t loc, tree value, int divisor)
{
tree div = NULL_TREE;
gcc_assert (divisor > 0);
if (divisor == 1)
return value;
/* See if VALUE is already a multiple of DIVISOR. If so, we don't
have to do anything. Only do this when we are not given a const,
because in that case, this check is more expensive than just
doing it. */
if (TREE_CODE (value) != INTEGER_CST)
{
div = build_int_cst (TREE_TYPE (value), divisor);
if (multiple_of_p (TREE_TYPE (value), value, div))
return value;
}
/* If divisor is a power of two, simplify this to bit manipulation. */
if (divisor == (divisor & -divisor))
{
if (TREE_CODE (value) == INTEGER_CST)
{
double_int val = tree_to_double_int (value);
bool overflow_p;
if ((val.low & (divisor - 1)) == 0)
return value;
overflow_p = TREE_OVERFLOW (value);
val.low &= ~(divisor - 1);
val.low += divisor;
if (val.low == 0)
{
val.high++;
if (val.high == 0)
overflow_p = true;
}
return force_fit_type_double (TREE_TYPE (value), val,
-1, overflow_p);
}
else
{
tree t;
t = build_int_cst (TREE_TYPE (value), divisor - 1);
value = size_binop_loc (loc, PLUS_EXPR, value, t);
t = build_int_cst (TREE_TYPE (value), -divisor);
value = size_binop_loc (loc, BIT_AND_EXPR, value, t);
}
}
else
{
if (!div)
div = build_int_cst (TREE_TYPE (value), divisor);
value = size_binop_loc (loc, CEIL_DIV_EXPR, value, div);
value = size_binop_loc (loc, MULT_EXPR, value, div);
}
return value;
}
/* Likewise, but round down. */
tree
round_down_loc (location_t loc, tree value, int divisor)
{
tree div = NULL_TREE;
gcc_assert (divisor > 0);
if (divisor == 1)
return value;
/* See if VALUE is already a multiple of DIVISOR. If so, we don't
have to do anything. Only do this when we are not given a const,
because in that case, this check is more expensive than just
doing it. */
if (TREE_CODE (value) != INTEGER_CST)
{
div = build_int_cst (TREE_TYPE (value), divisor);
if (multiple_of_p (TREE_TYPE (value), value, div))
return value;
}
/* If divisor is a power of two, simplify this to bit manipulation. */
if (divisor == (divisor & -divisor))
{
tree t;
t = build_int_cst (TREE_TYPE (value), -divisor);
value = size_binop_loc (loc, BIT_AND_EXPR, value, t);
}
else
{
if (!div)
div = build_int_cst (TREE_TYPE (value), divisor);
value = size_binop_loc (loc, FLOOR_DIV_EXPR, value, div);
value = size_binop_loc (loc, MULT_EXPR, value, div);
}
return value;
}
/* Returns the pointer to the base of the object addressed by EXP and
extracts the information about the offset of the access, storing it
to PBITPOS and POFFSET. */
static tree
split_address_to_core_and_offset (tree exp,
HOST_WIDE_INT *pbitpos, tree *poffset)
{
tree core;
enum machine_mode mode;
int unsignedp, volatilep;
HOST_WIDE_INT bitsize;
location_t loc = EXPR_LOCATION (exp);
if (TREE_CODE (exp) == ADDR_EXPR)
{
core = get_inner_reference (TREE_OPERAND (exp, 0), &bitsize, pbitpos,
poffset, &mode, &unsignedp, &volatilep,
false);
core = build_fold_addr_expr_loc (loc, core);
}
else
{
core = exp;
*pbitpos = 0;
*poffset = NULL_TREE;
}
return core;
}
/* Returns true if addresses of E1 and E2 differ by a constant, false
otherwise. If they do, E1 - E2 is stored in *DIFF. */
bool
ptr_difference_const (tree e1, tree e2, HOST_WIDE_INT *diff)
{
tree core1, core2;
HOST_WIDE_INT bitpos1, bitpos2;
tree toffset1, toffset2, tdiff, type;
core1 = split_address_to_core_and_offset (e1, &bitpos1, &toffset1);
core2 = split_address_to_core_and_offset (e2, &bitpos2, &toffset2);
if (bitpos1 % BITS_PER_UNIT != 0
|| bitpos2 % BITS_PER_UNIT != 0
|| !operand_equal_p (core1, core2, 0))
return false;
if (toffset1 && toffset2)
{
type = TREE_TYPE (toffset1);
if (type != TREE_TYPE (toffset2))
toffset2 = fold_convert (type, toffset2);
tdiff = fold_build2 (MINUS_EXPR, type, toffset1, toffset2);
if (!cst_and_fits_in_hwi (tdiff))
return false;
*diff = int_cst_value (tdiff);
}
else if (toffset1 || toffset2)
{
/* If only one of the offsets is non-constant, the difference cannot
be a constant. */
return false;
}
else
*diff = 0;
*diff += (bitpos1 - bitpos2) / BITS_PER_UNIT;
return true;
}
/* Simplify the floating point expression EXP when the sign of the
result is not significant. Return NULL_TREE if no simplification
is possible. */
tree
fold_strip_sign_ops (tree exp)
{
tree arg0, arg1;
location_t loc = EXPR_LOCATION (exp);
switch (TREE_CODE (exp))
{
case ABS_EXPR:
case NEGATE_EXPR:
arg0 = fold_strip_sign_ops (TREE_OPERAND (exp, 0));
return arg0 ? arg0 : TREE_OPERAND (exp, 0);
case MULT_EXPR:
case RDIV_EXPR:
if (HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (TREE_TYPE (exp))))
return NULL_TREE;
arg0 = fold_strip_sign_ops (TREE_OPERAND (exp, 0));
arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 1));
if (arg0 != NULL_TREE || arg1 != NULL_TREE)
return fold_build2_loc (loc, TREE_CODE (exp), TREE_TYPE (exp),
arg0 ? arg0 : TREE_OPERAND (exp, 0),
arg1 ? arg1 : TREE_OPERAND (exp, 1));
break;
case COMPOUND_EXPR:
arg0 = TREE_OPERAND (exp, 0);
arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 1));
if (arg1)
return fold_build2_loc (loc, COMPOUND_EXPR, TREE_TYPE (exp), arg0, arg1);
break;
case COND_EXPR:
arg0 = fold_strip_sign_ops (TREE_OPERAND (exp, 1));
arg1 = fold_strip_sign_ops (TREE_OPERAND (exp, 2));
if (arg0 || arg1)
return fold_build3_loc (loc,
COND_EXPR, TREE_TYPE (exp), TREE_OPERAND (exp, 0),
arg0 ? arg0 : TREE_OPERAND (exp, 1),
arg1 ? arg1 : TREE_OPERAND (exp, 2));
break;
case CALL_EXPR:
{
const enum built_in_function fcode = builtin_mathfn_code (exp);
switch (fcode)
{
CASE_FLT_FN (BUILT_IN_COPYSIGN):
/* Strip copysign function call, return the 1st argument. */
arg0 = CALL_EXPR_ARG (exp, 0);
arg1 = CALL_EXPR_ARG (exp, 1);
return omit_one_operand_loc (loc, TREE_TYPE (exp), arg0, arg1);
default:
/* Strip sign ops from the argument of "odd" math functions. */
if (negate_mathfn_p (fcode))
{
arg0 = fold_strip_sign_ops (CALL_EXPR_ARG (exp, 0));
if (arg0)
return build_call_expr_loc (loc, get_callee_fndecl (exp), 1, arg0);
}
break;
}
}
break;
default:
break;
}
return NULL_TREE;
}
| gpl-2.0 |
haiphamspkt/haiphamkernel | arch/arm/mach-pxa/zeus.c | 2 | 20578 | /*
* Support for the Arcom ZEUS.
*
* Copyright (C) 2006 Arcom Control Systems Ltd.
*
* Loosely based on Arcom's 2.6.16.28.
* Maintained by Marc Zyngier <maz@misterjones.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/cpufreq.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/pm.h>
#include <linux/gpio.h>
#include <linux/serial_8250.h>
#include <linux/dm9000.h>
#include <linux/mmc/host.h>
#include <linux/spi/spi.h>
#include <linux/spi/pxa2xx_spi.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/physmap.h>
#include <linux/i2c.h>
#include <linux/i2c/pxa-i2c.h>
#include <linux/i2c/pca953x.h>
#include <linux/apm-emulation.h>
#include <linux/can/platform/mcp251x.h>
#include <asm/mach-types.h>
#include <asm/suspend.h>
#include <asm/mach/arch.h>
#include <asm/mach/map.h>
#include <mach/pxa27x.h>
#include <mach/regs-uart.h>
#include <mach/ohci.h>
#include <mach/mmc.h>
#include <mach/pxa27x-udc.h>
#include <mach/udc.h>
#include <mach/pxafb.h>
#include <mach/pm.h>
#include <mach/audio.h>
#include <mach/arcom-pcmcia.h>
#include <mach/zeus.h>
#include <mach/smemc.h>
#include "generic.h"
/*
* Interrupt handling
*/
static unsigned long zeus_irq_enabled_mask;
static const int zeus_isa_irqs[] = { 3, 4, 5, 6, 7, 10, 11, 12, };
static const int zeus_isa_irq_map[] = {
0, /* ISA irq #0, invalid */
0, /* ISA irq #1, invalid */
0, /* ISA irq #2, invalid */
1 << 0, /* ISA irq #3 */
1 << 1, /* ISA irq #4 */
1 << 2, /* ISA irq #5 */
1 << 3, /* ISA irq #6 */
1 << 4, /* ISA irq #7 */
0, /* ISA irq #8, invalid */
0, /* ISA irq #9, invalid */
1 << 5, /* ISA irq #10 */
1 << 6, /* ISA irq #11 */
1 << 7, /* ISA irq #12 */
};
static inline int zeus_irq_to_bitmask(unsigned int irq)
{
return zeus_isa_irq_map[irq - PXA_ISA_IRQ(0)];
}
static inline int zeus_bit_to_irq(int bit)
{
return zeus_isa_irqs[bit] + PXA_ISA_IRQ(0);
}
static void zeus_ack_irq(struct irq_data *d)
{
__raw_writew(zeus_irq_to_bitmask(d->irq), ZEUS_CPLD_ISA_IRQ);
}
static void zeus_mask_irq(struct irq_data *d)
{
zeus_irq_enabled_mask &= ~(zeus_irq_to_bitmask(d->irq));
}
static void zeus_unmask_irq(struct irq_data *d)
{
zeus_irq_enabled_mask |= zeus_irq_to_bitmask(d->irq);
}
static inline unsigned long zeus_irq_pending(void)
{
return __raw_readw(ZEUS_CPLD_ISA_IRQ) & zeus_irq_enabled_mask;
}
static void zeus_irq_handler(unsigned int irq, struct irq_desc *desc)
{
unsigned long pending;
pending = zeus_irq_pending();
do {
/* we're in a chained irq handler,
* so ack the interrupt by hand */
desc->irq_data.chip->irq_ack(&desc->irq_data);
if (likely(pending)) {
irq = zeus_bit_to_irq(__ffs(pending));
generic_handle_irq(irq);
}
pending = zeus_irq_pending();
} while (pending);
}
static struct irq_chip zeus_irq_chip = {
.name = "ISA",
.irq_ack = zeus_ack_irq,
.irq_mask = zeus_mask_irq,
.irq_unmask = zeus_unmask_irq,
};
static void __init zeus_init_irq(void)
{
int level;
int isa_irq;
pxa27x_init_irq();
/* Peripheral IRQs. It would be nice to move those inside driver
configuration, but it is not supported at the moment. */
irq_set_irq_type(gpio_to_irq(ZEUS_AC97_GPIO), IRQ_TYPE_EDGE_RISING);
irq_set_irq_type(gpio_to_irq(ZEUS_WAKEUP_GPIO), IRQ_TYPE_EDGE_RISING);
irq_set_irq_type(gpio_to_irq(ZEUS_PTT_GPIO), IRQ_TYPE_EDGE_RISING);
irq_set_irq_type(gpio_to_irq(ZEUS_EXTGPIO_GPIO),
IRQ_TYPE_EDGE_FALLING);
irq_set_irq_type(gpio_to_irq(ZEUS_CAN_GPIO), IRQ_TYPE_EDGE_FALLING);
/* Setup ISA IRQs */
for (level = 0; level < ARRAY_SIZE(zeus_isa_irqs); level++) {
isa_irq = zeus_bit_to_irq(level);
irq_set_chip_and_handler(isa_irq, &zeus_irq_chip,
handle_edge_irq);
set_irq_flags(isa_irq, IRQF_VALID | IRQF_PROBE);
}
irq_set_irq_type(gpio_to_irq(ZEUS_ISA_GPIO), IRQ_TYPE_EDGE_RISING);
irq_set_chained_handler(gpio_to_irq(ZEUS_ISA_GPIO), zeus_irq_handler);
}
/*
* Platform devices
*/
/* Flash */
static struct resource zeus_mtd_resources[] = {
[0] = { /* NOR Flash (up to 64MB) */
.start = ZEUS_FLASH_PHYS,
.end = ZEUS_FLASH_PHYS + SZ_64M - 1,
.flags = IORESOURCE_MEM,
},
[1] = { /* SRAM */
.start = ZEUS_SRAM_PHYS,
.end = ZEUS_SRAM_PHYS + SZ_512K - 1,
.flags = IORESOURCE_MEM,
},
};
static struct physmap_flash_data zeus_flash_data[] = {
[0] = {
.width = 2,
.parts = NULL,
.nr_parts = 0,
},
};
static struct platform_device zeus_mtd_devices[] = {
[0] = {
.name = "physmap-flash",
.id = 0,
.dev = {
.platform_data = &zeus_flash_data[0],
},
.resource = &zeus_mtd_resources[0],
.num_resources = 1,
},
};
/* Serial */
static struct resource zeus_serial_resources[] = {
{
.start = 0x10000000,
.end = 0x1000000f,
.flags = IORESOURCE_MEM,
},
{
.start = 0x10800000,
.end = 0x1080000f,
.flags = IORESOURCE_MEM,
},
{
.start = 0x11000000,
.end = 0x1100000f,
.flags = IORESOURCE_MEM,
},
{
.start = 0x40100000,
.end = 0x4010001f,
.flags = IORESOURCE_MEM,
},
{
.start = 0x40200000,
.end = 0x4020001f,
.flags = IORESOURCE_MEM,
},
{
.start = 0x40700000,
.end = 0x4070001f,
.flags = IORESOURCE_MEM,
},
};
static struct plat_serial8250_port serial_platform_data[] = {
/* External UARTs */
/* FIXME: Shared IRQs on COM1-COM4 will not work properly on v1i1 hardware. */
{ /* COM1 */
.mapbase = 0x10000000,
.irq = gpio_to_irq(ZEUS_UARTA_GPIO),
.irqflags = IRQF_TRIGGER_RISING,
.uartclk = 14745600,
.regshift = 1,
.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
.iotype = UPIO_MEM,
},
{ /* COM2 */
.mapbase = 0x10800000,
.irq = gpio_to_irq(ZEUS_UARTB_GPIO),
.irqflags = IRQF_TRIGGER_RISING,
.uartclk = 14745600,
.regshift = 1,
.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
.iotype = UPIO_MEM,
},
{ /* COM3 */
.mapbase = 0x11000000,
.irq = gpio_to_irq(ZEUS_UARTC_GPIO),
.irqflags = IRQF_TRIGGER_RISING,
.uartclk = 14745600,
.regshift = 1,
.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
.iotype = UPIO_MEM,
},
{ /* COM4 */
.mapbase = 0x11800000,
.irq = gpio_to_irq(ZEUS_UARTD_GPIO),
.irqflags = IRQF_TRIGGER_RISING,
.uartclk = 14745600,
.regshift = 1,
.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
.iotype = UPIO_MEM,
},
/* Internal UARTs */
{ /* FFUART */
.membase = (void *)&FFUART,
.mapbase = __PREG(FFUART),
.irq = IRQ_FFUART,
.uartclk = 921600 * 16,
.regshift = 2,
.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
.iotype = UPIO_MEM,
},
{ /* BTUART */
.membase = (void *)&BTUART,
.mapbase = __PREG(BTUART),
.irq = IRQ_BTUART,
.uartclk = 921600 * 16,
.regshift = 2,
.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
.iotype = UPIO_MEM,
},
{ /* STUART */
.membase = (void *)&STUART,
.mapbase = __PREG(STUART),
.irq = IRQ_STUART,
.uartclk = 921600 * 16,
.regshift = 2,
.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
.iotype = UPIO_MEM,
},
{ },
};
static struct platform_device zeus_serial_device = {
.name = "serial8250",
.id = PLAT8250_DEV_PLATFORM,
.dev = {
.platform_data = serial_platform_data,
},
.num_resources = ARRAY_SIZE(zeus_serial_resources),
.resource = zeus_serial_resources,
};
/* Ethernet */
static struct resource zeus_dm9k0_resource[] = {
[0] = {
.start = ZEUS_ETH0_PHYS,
.end = ZEUS_ETH0_PHYS + 1,
.flags = IORESOURCE_MEM
},
[1] = {
.start = ZEUS_ETH0_PHYS + 2,
.end = ZEUS_ETH0_PHYS + 3,
.flags = IORESOURCE_MEM
},
[2] = {
.start = gpio_to_irq(ZEUS_ETH0_GPIO),
.end = gpio_to_irq(ZEUS_ETH0_GPIO),
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
},
};
static struct resource zeus_dm9k1_resource[] = {
[0] = {
.start = ZEUS_ETH1_PHYS,
.end = ZEUS_ETH1_PHYS + 1,
.flags = IORESOURCE_MEM
},
[1] = {
.start = ZEUS_ETH1_PHYS + 2,
.end = ZEUS_ETH1_PHYS + 3,
.flags = IORESOURCE_MEM,
},
[2] = {
.start = gpio_to_irq(ZEUS_ETH1_GPIO),
.end = gpio_to_irq(ZEUS_ETH1_GPIO),
.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE,
},
};
static struct dm9000_plat_data zeus_dm9k_platdata = {
.flags = DM9000_PLATF_16BITONLY,
};
static struct platform_device zeus_dm9k0_device = {
.name = "dm9000",
.id = 0,
.num_resources = ARRAY_SIZE(zeus_dm9k0_resource),
.resource = zeus_dm9k0_resource,
.dev = {
.platform_data = &zeus_dm9k_platdata,
}
};
static struct platform_device zeus_dm9k1_device = {
.name = "dm9000",
.id = 1,
.num_resources = ARRAY_SIZE(zeus_dm9k1_resource),
.resource = zeus_dm9k1_resource,
.dev = {
.platform_data = &zeus_dm9k_platdata,
}
};
/* External SRAM */
static struct resource zeus_sram_resource = {
.start = ZEUS_SRAM_PHYS,
.end = ZEUS_SRAM_PHYS + ZEUS_SRAM_SIZE * 2 - 1,
.flags = IORESOURCE_MEM,
};
static struct platform_device zeus_sram_device = {
.name = "pxa2xx-8bit-sram",
.id = 0,
.num_resources = 1,
.resource = &zeus_sram_resource,
};
/* SPI interface on SSP3 */
static struct pxa2xx_spi_master pxa2xx_spi_ssp3_master_info = {
.num_chipselect = 1,
.enable_dma = 1,
};
/* CAN bus on SPI */
static int zeus_mcp2515_setup(struct spi_device *sdev)
{
int err;
err = gpio_request(ZEUS_CAN_SHDN_GPIO, "CAN shutdown");
if (err)
return err;
err = gpio_direction_output(ZEUS_CAN_SHDN_GPIO, 1);
if (err) {
gpio_free(ZEUS_CAN_SHDN_GPIO);
return err;
}
return 0;
}
static int zeus_mcp2515_transceiver_enable(int enable)
{
gpio_set_value(ZEUS_CAN_SHDN_GPIO, !enable);
return 0;
}
static struct mcp251x_platform_data zeus_mcp2515_pdata = {
.oscillator_frequency = 16*1000*1000,
.board_specific_setup = zeus_mcp2515_setup,
.power_enable = zeus_mcp2515_transceiver_enable,
};
static struct spi_board_info zeus_spi_board_info[] = {
[0] = {
.modalias = "mcp2515",
.platform_data = &zeus_mcp2515_pdata,
.irq = gpio_to_irq(ZEUS_CAN_GPIO),
.max_speed_hz = 1*1000*1000,
.bus_num = 3,
.mode = SPI_MODE_0,
.chip_select = 0,
},
};
/* Leds */
static struct gpio_led zeus_leds[] = {
[0] = {
.name = "zeus:yellow:1",
.default_trigger = "heartbeat",
.gpio = ZEUS_EXT0_GPIO(3),
.active_low = 1,
},
[1] = {
.name = "zeus:yellow:2",
.default_trigger = "default-on",
.gpio = ZEUS_EXT0_GPIO(4),
.active_low = 1,
},
[2] = {
.name = "zeus:yellow:3",
.default_trigger = "default-on",
.gpio = ZEUS_EXT0_GPIO(5),
.active_low = 1,
},
};
static struct gpio_led_platform_data zeus_leds_info = {
.leds = zeus_leds,
.num_leds = ARRAY_SIZE(zeus_leds),
};
static struct platform_device zeus_leds_device = {
.name = "leds-gpio",
.id = -1,
.dev = {
.platform_data = &zeus_leds_info,
},
};
static void zeus_cf_reset(int state)
{
u16 cpld_state = __raw_readw(ZEUS_CPLD_CONTROL);
if (state)
cpld_state |= ZEUS_CPLD_CONTROL_CF_RST;
else
cpld_state &= ~ZEUS_CPLD_CONTROL_CF_RST;
__raw_writew(cpld_state, ZEUS_CPLD_CONTROL);
}
static struct arcom_pcmcia_pdata zeus_pcmcia_info = {
.cd_gpio = ZEUS_CF_CD_GPIO,
.rdy_gpio = ZEUS_CF_RDY_GPIO,
.pwr_gpio = ZEUS_CF_PWEN_GPIO,
.reset = zeus_cf_reset,
};
static struct platform_device zeus_pcmcia_device = {
.name = "zeus-pcmcia",
.id = -1,
.dev = {
.platform_data = &zeus_pcmcia_info,
},
};
static struct resource zeus_max6369_resource = {
.start = ZEUS_CPLD_EXTWDOG_PHYS,
.end = ZEUS_CPLD_EXTWDOG_PHYS,
.flags = IORESOURCE_MEM,
};
struct platform_device zeus_max6369_device = {
.name = "max6369_wdt",
.id = -1,
.resource = &zeus_max6369_resource,
.num_resources = 1,
};
static struct platform_device *zeus_devices[] __initdata = {
&zeus_serial_device,
&zeus_mtd_devices[0],
&zeus_dm9k0_device,
&zeus_dm9k1_device,
&zeus_sram_device,
&zeus_leds_device,
&zeus_pcmcia_device,
&zeus_max6369_device,
};
/* AC'97 */
static pxa2xx_audio_ops_t zeus_ac97_info = {
.reset_gpio = 95,
};
/*
* USB host
*/
static int zeus_ohci_init(struct device *dev)
{
int err;
/* Switch on port 2. */
if ((err = gpio_request(ZEUS_USB2_PWREN_GPIO, "USB2_PWREN"))) {
dev_err(dev, "Can't request USB2_PWREN\n");
return err;
}
if ((err = gpio_direction_output(ZEUS_USB2_PWREN_GPIO, 1))) {
gpio_free(ZEUS_USB2_PWREN_GPIO);
dev_err(dev, "Can't enable USB2_PWREN\n");
return err;
}
/* Port 2 is shared between host and client interface. */
UP2OCR = UP2OCR_HXOE | UP2OCR_HXS | UP2OCR_DMPDE | UP2OCR_DPPDE;
return 0;
}
static void zeus_ohci_exit(struct device *dev)
{
/* Power-off port 2 */
gpio_direction_output(ZEUS_USB2_PWREN_GPIO, 0);
gpio_free(ZEUS_USB2_PWREN_GPIO);
}
static struct pxaohci_platform_data zeus_ohci_platform_data = {
.port_mode = PMM_NPS_MODE,
/* Clear Power Control Polarity Low and set Power Sense
* Polarity Low. Supply power to USB ports. */
.flags = ENABLE_PORT_ALL | POWER_SENSE_LOW,
.init = zeus_ohci_init,
.exit = zeus_ohci_exit,
};
/*
* Flat Panel
*/
static void zeus_lcd_power(int on, struct fb_var_screeninfo *si)
{
gpio_set_value(ZEUS_LCD_EN_GPIO, on);
}
static void zeus_backlight_power(int on)
{
gpio_set_value(ZEUS_BKLEN_GPIO, on);
}
static int zeus_setup_fb_gpios(void)
{
int err;
if ((err = gpio_request(ZEUS_LCD_EN_GPIO, "LCD_EN")))
goto out_err;
if ((err = gpio_direction_output(ZEUS_LCD_EN_GPIO, 0)))
goto out_err_lcd;
if ((err = gpio_request(ZEUS_BKLEN_GPIO, "BKLEN")))
goto out_err_lcd;
if ((err = gpio_direction_output(ZEUS_BKLEN_GPIO, 0)))
goto out_err_bkl;
return 0;
out_err_bkl:
gpio_free(ZEUS_BKLEN_GPIO);
out_err_lcd:
gpio_free(ZEUS_LCD_EN_GPIO);
out_err:
return err;
}
static struct pxafb_mode_info zeus_fb_mode_info[] = {
{
.pixclock = 39722,
.xres = 640,
.yres = 480,
.bpp = 16,
.hsync_len = 63,
.left_margin = 16,
.right_margin = 81,
.vsync_len = 2,
.upper_margin = 12,
.lower_margin = 31,
.sync = 0,
},
};
static struct pxafb_mach_info zeus_fb_info = {
.modes = zeus_fb_mode_info,
.num_modes = 1,
.lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
.pxafb_lcd_power = zeus_lcd_power,
.pxafb_backlight_power = zeus_backlight_power,
};
/*
* MMC/SD Device
*
* The card detect interrupt isn't debounced so we delay it by 250ms
* to give the card a chance to fully insert/eject.
*/
static struct pxamci_platform_data zeus_mci_platform_data = {
.ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
.detect_delay_ms = 250,
.gpio_card_detect = ZEUS_MMC_CD_GPIO,
.gpio_card_ro = ZEUS_MMC_WP_GPIO,
.gpio_card_ro_invert = 1,
.gpio_power = -1
};
/*
* USB Device Controller
*/
static void zeus_udc_command(int cmd)
{
switch (cmd) {
case PXA2XX_UDC_CMD_DISCONNECT:
pr_info("zeus: disconnecting USB client\n");
UP2OCR = UP2OCR_HXOE | UP2OCR_HXS | UP2OCR_DMPDE | UP2OCR_DPPDE;
break;
case PXA2XX_UDC_CMD_CONNECT:
pr_info("zeus: connecting USB client\n");
UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE;
break;
}
}
static struct pxa2xx_udc_mach_info zeus_udc_info = {
.udc_command = zeus_udc_command,
};
#ifdef CONFIG_PM
static void zeus_power_off(void)
{
local_irq_disable();
cpu_suspend(PWRMODE_DEEPSLEEP, pxa27x_finish_suspend);
}
#else
#define zeus_power_off NULL
#endif
#ifdef CONFIG_APM_EMULATION
static void zeus_get_power_status(struct apm_power_info *info)
{
/* Power supply is always present */
info->ac_line_status = APM_AC_ONLINE;
info->battery_status = APM_BATTERY_STATUS_NOT_PRESENT;
info->battery_flag = APM_BATTERY_FLAG_NOT_PRESENT;
}
static inline void zeus_setup_apm(void)
{
apm_get_power_status = zeus_get_power_status;
}
#else
static inline void zeus_setup_apm(void)
{
}
#endif
static int zeus_get_pcb_info(struct i2c_client *client, unsigned gpio,
unsigned ngpio, void *context)
{
int i;
u8 pcb_info = 0;
for (i = 0; i < 8; i++) {
int pcb_bit = gpio + i + 8;
if (gpio_request(pcb_bit, "pcb info")) {
dev_err(&client->dev, "Can't request pcb info %d\n", i);
continue;
}
if (gpio_direction_input(pcb_bit)) {
dev_err(&client->dev, "Can't read pcb info %d\n", i);
gpio_free(pcb_bit);
continue;
}
pcb_info |= !!gpio_get_value(pcb_bit) << i;
gpio_free(pcb_bit);
}
dev_info(&client->dev, "Zeus PCB version %d issue %d\n",
pcb_info >> 4, pcb_info & 0xf);
return 0;
}
static struct pca953x_platform_data zeus_pca953x_pdata[] = {
[0] = { .gpio_base = ZEUS_EXT0_GPIO_BASE, },
[1] = {
.gpio_base = ZEUS_EXT1_GPIO_BASE,
.setup = zeus_get_pcb_info,
},
[2] = { .gpio_base = ZEUS_USER_GPIO_BASE, },
};
static struct i2c_board_info __initdata zeus_i2c_devices[] = {
{
I2C_BOARD_INFO("pca9535", 0x21),
.platform_data = &zeus_pca953x_pdata[0],
},
{
I2C_BOARD_INFO("pca9535", 0x22),
.platform_data = &zeus_pca953x_pdata[1],
},
{
I2C_BOARD_INFO("pca9535", 0x20),
.platform_data = &zeus_pca953x_pdata[2],
.irq = gpio_to_irq(ZEUS_EXTGPIO_GPIO),
},
{ I2C_BOARD_INFO("lm75a", 0x48) },
{ I2C_BOARD_INFO("24c01", 0x50) },
{ I2C_BOARD_INFO("isl1208", 0x6f) },
};
static mfp_cfg_t zeus_pin_config[] __initdata = {
/* AC97 */
GPIO28_AC97_BITCLK,
GPIO29_AC97_SDATA_IN_0,
GPIO30_AC97_SDATA_OUT,
GPIO31_AC97_SYNC,
GPIO15_nCS_1,
GPIO78_nCS_2,
GPIO80_nCS_4,
GPIO33_nCS_5,
GPIO22_GPIO,
GPIO32_MMC_CLK,
GPIO92_MMC_DAT_0,
GPIO109_MMC_DAT_1,
GPIO110_MMC_DAT_2,
GPIO111_MMC_DAT_3,
GPIO112_MMC_CMD,
GPIO88_USBH1_PWR,
GPIO89_USBH1_PEN,
GPIO119_USBH2_PWR,
GPIO120_USBH2_PEN,
GPIO86_LCD_LDD_16,
GPIO87_LCD_LDD_17,
GPIO102_GPIO,
GPIO104_CIF_DD_2,
GPIO105_CIF_DD_1,
GPIO81_SSP3_TXD,
GPIO82_SSP3_RXD,
GPIO83_SSP3_SFRM,
GPIO84_SSP3_SCLK,
GPIO48_nPOE,
GPIO49_nPWE,
GPIO50_nPIOR,
GPIO51_nPIOW,
GPIO85_nPCE_1,
GPIO54_nPCE_2,
GPIO79_PSKTSEL,
GPIO55_nPREG,
GPIO56_nPWAIT,
GPIO57_nIOIS16,
GPIO36_GPIO, /* CF CD */
GPIO97_GPIO, /* CF PWREN */
GPIO99_GPIO, /* CF RDY */
};
/*
* DM9k MSCx settings: SRAM, 16 bits
* 17 cycles delay first access
* 5 cycles delay next access
* 13 cycles recovery time
* faster device
*/
#define DM9K_MSC_VALUE 0xe4c9
static void __init zeus_init(void)
{
u16 dm9000_msc = DM9K_MSC_VALUE;
u32 msc0, msc1;
system_rev = __raw_readw(ZEUS_CPLD_VERSION);
pr_info("Zeus CPLD V%dI%d\n", (system_rev & 0xf0) >> 4, (system_rev & 0x0f));
/* Fix timings for dm9000s (CS1/CS2)*/
msc0 = (__raw_readl(MSC0) & 0x0000ffff) | (dm9000_msc << 16);
msc1 = (__raw_readl(MSC1) & 0xffff0000) | dm9000_msc;
__raw_writel(msc0, MSC0);
__raw_writel(msc1, MSC1);
pm_power_off = zeus_power_off;
zeus_setup_apm();
pxa2xx_mfp_config(ARRAY_AND_SIZE(zeus_pin_config));
platform_add_devices(zeus_devices, ARRAY_SIZE(zeus_devices));
pxa_set_ohci_info(&zeus_ohci_platform_data);
if (zeus_setup_fb_gpios())
pr_err("Failed to setup fb gpios\n");
else
pxa_set_fb_info(NULL, &zeus_fb_info);
pxa_set_mci_info(&zeus_mci_platform_data);
pxa_set_udc_info(&zeus_udc_info);
pxa_set_ac97_info(&zeus_ac97_info);
pxa_set_i2c_info(NULL);
i2c_register_board_info(0, ARRAY_AND_SIZE(zeus_i2c_devices));
pxa2xx_set_spi_info(3, &pxa2xx_spi_ssp3_master_info);
spi_register_board_info(zeus_spi_board_info, ARRAY_SIZE(zeus_spi_board_info));
}
static struct map_desc zeus_io_desc[] __initdata = {
{
.virtual = (unsigned long)ZEUS_CPLD_VERSION,
.pfn = __phys_to_pfn(ZEUS_CPLD_VERSION_PHYS),
.length = 0x1000,
.type = MT_DEVICE,
},
{
.virtual = (unsigned long)ZEUS_CPLD_ISA_IRQ,
.pfn = __phys_to_pfn(ZEUS_CPLD_ISA_IRQ_PHYS),
.length = 0x1000,
.type = MT_DEVICE,
},
{
.virtual = (unsigned long)ZEUS_CPLD_CONTROL,
.pfn = __phys_to_pfn(ZEUS_CPLD_CONTROL_PHYS),
.length = 0x1000,
.type = MT_DEVICE,
},
{
.virtual = (unsigned long)ZEUS_PC104IO,
.pfn = __phys_to_pfn(ZEUS_PC104IO_PHYS),
.length = 0x00800000,
.type = MT_DEVICE,
},
};
static void __init zeus_map_io(void)
{
pxa27x_map_io();
iotable_init(zeus_io_desc, ARRAY_SIZE(zeus_io_desc));
/* Clear PSPR to ensure a full restart on wake-up. */
PMCR = PSPR = 0;
/* enable internal 32.768Khz oscillator (ignore OSCC_OOK) */
OSCC |= OSCC_OON;
/* Some clock cycles later (from OSCC_ON), programme PCFR (OPDE...).
* float chip selects and PCMCIA */
PCFR = PCFR_OPDE | PCFR_DC_EN | PCFR_FS | PCFR_FP;
}
MACHINE_START(ARCOM_ZEUS, "Arcom/Eurotech ZEUS")
/* Maintainer: Marc Zyngier <maz@misterjones.org> */
.atag_offset = 0x100,
.map_io = zeus_map_io,
.nr_irqs = ZEUS_NR_IRQS,
.init_irq = zeus_init_irq,
.handle_irq = pxa27x_handle_irq,
.timer = &pxa_timer,
.init_machine = zeus_init,
.restart = pxa_restart,
MACHINE_END
| gpl-2.0 |
Jopie64/pjsip | pjmedia/src/pjmedia/sound_legacy.c | 2 | 8176 | /* $Id$ */
/*
* Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* This is implementation of legacy sound device API, for applications
* that still use the old/deprecated sound device API. This implementation
* uses the new Audio Device API.
*
* Please see http://trac.pjsip.org/repos/wiki/Audio_Dev_API for more
* information.
*/
#include <pjmedia/sound.h>
#include <pjmedia-audiodev/errno.h>
#include <pj/assert.h>
#if PJMEDIA_HAS_LEGACY_SOUND_API
static struct legacy_subsys
{
pjmedia_snd_dev_info info[4];
unsigned info_counter;
unsigned user_rec_latency;
unsigned user_play_latency;
} g_sys;
struct pjmedia_snd_stream
{
pj_pool_t *pool;
pjmedia_aud_stream *aud_strm;
pjmedia_snd_rec_cb user_rec_cb;
pjmedia_snd_play_cb user_play_cb;
void *user_user_data;
};
PJ_DEF(pj_status_t) pjmedia_snd_init(pj_pool_factory *factory)
{
return pjmedia_aud_subsys_init(factory);
}
PJ_DEF(pj_status_t) pjmedia_snd_deinit(void)
{
return pjmedia_aud_subsys_shutdown();
}
PJ_DEF(int) pjmedia_snd_get_dev_count(void)
{
return pjmedia_aud_dev_count();
}
PJ_DEF(const pjmedia_snd_dev_info*) pjmedia_snd_get_dev_info(unsigned index)
{
pjmedia_snd_dev_info *oi = &g_sys.info[g_sys.info_counter];
pjmedia_aud_dev_info di;
g_sys.info_counter = (g_sys.info_counter+1) % PJ_ARRAY_SIZE(g_sys.info);
if (pjmedia_aud_dev_get_info(index, &di) != PJ_SUCCESS)
return NULL;
pj_bzero(oi, sizeof(*oi));
pj_ansi_strncpy(oi->name, di.name, sizeof(oi->name));
oi->name[sizeof(oi->name)-1] = '\0';
oi->input_count = di.input_count;
oi->output_count = di.output_count;
oi->default_samples_per_sec = di.default_samples_per_sec;
return oi;
}
static pj_status_t snd_play_cb(void *user_data,
pjmedia_frame *frame)
{
pjmedia_snd_stream *strm = (pjmedia_snd_stream*)user_data;
frame->type = PJMEDIA_FRAME_TYPE_AUDIO;
return strm->user_play_cb(strm->user_user_data,
frame->timestamp.u32.lo,
frame->buf,
frame->size);
}
static pj_status_t snd_rec_cb(void *user_data,
pjmedia_frame *frame)
{
pjmedia_snd_stream *strm = (pjmedia_snd_stream*)user_data;
return strm->user_rec_cb(strm->user_user_data,
frame->timestamp.u32.lo,
frame->buf,
frame->size);
}
static pj_status_t open_stream( pjmedia_dir dir,
int rec_id,
int play_id,
unsigned clock_rate,
unsigned channel_count,
unsigned samples_per_frame,
unsigned bits_per_sample,
pjmedia_snd_rec_cb rec_cb,
pjmedia_snd_play_cb play_cb,
void *user_data,
pjmedia_snd_stream **p_snd_strm)
{
pj_pool_t *pool;
pjmedia_snd_stream *snd_strm;
pjmedia_aud_param param;
pj_status_t status;
/* Initialize parameters */
if (dir & PJMEDIA_DIR_CAPTURE) {
status = pjmedia_aud_dev_default_param(rec_id, ¶m);
} else {
status = pjmedia_aud_dev_default_param(play_id, ¶m);
}
if (status != PJ_SUCCESS)
return status;
param.dir = dir;
param.rec_id = rec_id;
param.play_id = play_id;
param.clock_rate = clock_rate;
param.channel_count = channel_count;
param.samples_per_frame = samples_per_frame;
param.bits_per_sample = bits_per_sample;
/* Latencies setting */
if ((dir & PJMEDIA_DIR_CAPTURE) && g_sys.user_rec_latency) {
param.flags |= PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY;
param.input_latency_ms = g_sys.user_rec_latency;
}
if ((dir & PJMEDIA_DIR_PLAYBACK) && g_sys.user_play_latency) {
param.flags |= PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY;
param.output_latency_ms = g_sys.user_play_latency;
}
/* Create sound wrapper */
pool = pj_pool_create(pjmedia_aud_subsys_get_pool_factory(),
"legacy-snd", 512, 512, NULL);
snd_strm = PJ_POOL_ZALLOC_T(pool, pjmedia_snd_stream);
snd_strm->pool = pool;
snd_strm->user_rec_cb = rec_cb;
snd_strm->user_play_cb = play_cb;
snd_strm->user_user_data = user_data;
/* Create the stream */
status = pjmedia_aud_stream_create(¶m, &snd_rec_cb,
&snd_play_cb, snd_strm,
&snd_strm->aud_strm);
if (status != PJ_SUCCESS) {
pj_pool_release(pool);
return status;
}
*p_snd_strm = snd_strm;
return PJ_SUCCESS;
}
PJ_DEF(pj_status_t) pjmedia_snd_open_rec( int index,
unsigned clock_rate,
unsigned channel_count,
unsigned samples_per_frame,
unsigned bits_per_sample,
pjmedia_snd_rec_cb rec_cb,
void *user_data,
pjmedia_snd_stream **p_snd_strm)
{
return open_stream(PJMEDIA_DIR_CAPTURE, index, PJMEDIA_AUD_INVALID_DEV,
clock_rate, channel_count, samples_per_frame,
bits_per_sample, rec_cb, NULL,
user_data, p_snd_strm);
}
PJ_DEF(pj_status_t) pjmedia_snd_open_player( int index,
unsigned clock_rate,
unsigned channel_count,
unsigned samples_per_frame,
unsigned bits_per_sample,
pjmedia_snd_play_cb play_cb,
void *user_data,
pjmedia_snd_stream **p_snd_strm )
{
return open_stream(PJMEDIA_DIR_PLAYBACK, PJMEDIA_AUD_INVALID_DEV, index,
clock_rate, channel_count, samples_per_frame,
bits_per_sample, NULL, play_cb,
user_data, p_snd_strm);
}
PJ_DEF(pj_status_t) pjmedia_snd_open( int rec_id,
int play_id,
unsigned clock_rate,
unsigned channel_count,
unsigned samples_per_frame,
unsigned bits_per_sample,
pjmedia_snd_rec_cb rec_cb,
pjmedia_snd_play_cb play_cb,
void *user_data,
pjmedia_snd_stream **p_snd_strm)
{
return open_stream(PJMEDIA_DIR_CAPTURE_PLAYBACK, rec_id, play_id,
clock_rate, channel_count, samples_per_frame,
bits_per_sample, rec_cb, play_cb,
user_data, p_snd_strm);
}
PJ_DEF(pj_status_t) pjmedia_snd_stream_start(pjmedia_snd_stream *stream)
{
return pjmedia_aud_stream_start(stream->aud_strm);
}
PJ_DEF(pj_status_t) pjmedia_snd_stream_stop(pjmedia_snd_stream *stream)
{
return pjmedia_aud_stream_stop(stream->aud_strm);
}
PJ_DEF(pj_status_t) pjmedia_snd_stream_get_info(pjmedia_snd_stream *strm,
pjmedia_snd_stream_info *pi)
{
pjmedia_aud_param param;
pj_status_t status;
status = pjmedia_aud_stream_get_param(strm->aud_strm, ¶m);
if (status != PJ_SUCCESS)
return status;
pj_bzero(pi, sizeof(*pi));
pi->dir = param.dir;
pi->play_id = param.play_id;
pi->rec_id = param.rec_id;
pi->clock_rate = param.clock_rate;
pi->channel_count = param.channel_count;
pi->samples_per_frame = param.samples_per_frame;
pi->bits_per_sample = param.bits_per_sample;
if (param.flags & PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY) {
pi->rec_latency = param.input_latency_ms;
}
if (param.flags & PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY) {
pi->play_latency = param.output_latency_ms;
}
return PJ_SUCCESS;
}
PJ_DEF(pj_status_t) pjmedia_snd_stream_close(pjmedia_snd_stream *stream)
{
pj_status_t status;
status = pjmedia_aud_stream_destroy(stream->aud_strm);
if (status != PJ_SUCCESS)
return status;
pj_pool_release(stream->pool);
return PJ_SUCCESS;
}
PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency,
unsigned output_latency)
{
g_sys.user_rec_latency = input_latency;
g_sys.user_play_latency = output_latency;
return PJ_SUCCESS;
}
#endif /* PJMEDIA_HAS_LEGACY_SOUND_API */
| gpl-2.0 |
Illedran/pgrouting | src/vrp_basic/src/VRP_core.cpp | 2 | 6055 | /*PGR-GNU*****************************************************************
Copyright (c) 2013 Khondoker Md. Razequl Islam
ziboncsedu@gmail.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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/
#ifdef __MINGW32__
#include <winsock2.h>
#include <windows.h>
#endif
#include "VRP.h"
#include "VRP_Solver.h"
#include <exception>
#undef PGR_LOGGER_ON
#define PGR_LOGGER_LOC
#define PGR_LOGGER_FILE "/tmp/vrp-debug.log"
#include "../../common/src/pgr_logger.h"
CVRPSolver solver;
void loadOrders(vrp_orders_t *orders, int order_count, int depotId)
{
int i;
PGR_LOGF("%s: %d\n", "Depot ID", id)
for(i = 0; i < order_count; i++)
{
int id = orders[i].id;
PGR_LOGF("%s: %d\n", "Order ID", id)
if (id == depotId)
{
PGR_LOG("Got depot");
// This order represents Deopot
CDepotInfo depot;
depot.setDepotId(id);
Point pt;
pt.X = orders[i].x;
pt.Y = orders[i].y;
depot.setDepotLocation(pt);
int openTime = orders[i].open_time;
depot.setOpenTime(openTime);
int closeTime = orders[i].close_time;
depot.setCloseTime(closeTime);
solver.addDepot(depot);
}
else
{
// This is an order
COrderInfo order;
order.setOrderId(id);
Point pt;
pt.X = orders[i].x;
pt.Y = orders[i].y;
order.setOrderLocation(pt);
int demand = orders[i].order_unit;
order.setOrderUnit(demand);
int openTime = orders[i].open_time;
order.setOpenTime(openTime);
int closeTime = orders[i].close_time;
order.setCloseTime(closeTime);
int serviceTime = orders[i].service_time;
order.setServiceTime(serviceTime);
solver.addOrder(order);
}
}
}
void loadVehicles(vrp_vehicles_t *vehicles, int vehicle_count)
{
int i;
for(i = 0; i < vehicle_count; i++)
{
CVehicleInfo vehicle;
int id = vehicles[i].id;
vehicle.setId(id);
int capcity = vehicles[i].capacity;
vehicle.setCapacity(capcity);
vehicle.setCostPerKM(1);
solver.addVehicle(vehicle);
}
}
void loadDistanceMatrix(vrp_cost_element_t *costmatrix, int cost_count, int depotId)
{
int i;
for(i = 0; i < cost_count; i++)
{
int fromId = costmatrix[i].src_id;
int toId = costmatrix[i].dest_id;
CostPack cpack;
cpack.cost = costmatrix[i].cost;
cpack.distance = costmatrix[i].distance;
cpack.traveltime = costmatrix[i].traveltime;
if(fromId == depotId)
solver.addDepotToOrderCost(fromId, toId, cpack);
else if(toId == depotId)
solver.addOrderToDepotCost(fromId, toId, cpack);
else
solver.addOrderToOrderCost(fromId, toId, cpack);
}
}
int find_vrp_solution(vrp_vehicles_t *vehicles, size_t vehicle_count,
vrp_orders_t *orders, size_t order_count,
vrp_cost_element_t *costmatrix, size_t cost_count,
int depot_id,
vrp_result_element_t **results, size_t *result_count, char **err_msg)
{
int res;
std::string strError;
try {
PGR_LOG("Before load order");
loadOrders(orders, static_cast<int>(order_count), depot_id);
PGR_LOG("After load order");
loadVehicles(vehicles, static_cast<int>(vehicle_count));
PGR_LOG("After load vehicles");
loadDistanceMatrix(costmatrix, static_cast<int>(cost_count), depot_id);
PGR_LOG("After load distance matrix");
res = solver.solveVRP(strError);
PGR_LOG("After VRP Solve");
}
catch(std::exception& e) {
*err_msg = (char *) e.what();
return -1;
}
catch(...) {
*err_msg = (char *) "Caught unknown exception!";
return -1;
}
if (res < 0)
return res;
else
{
try {
CSolutionInfo solution;
CTourInfo ctour;
// bool bOK =
solver.getSolution(solution, strError);
auto totalRoute = solution.getTourInfoVector().size();
size_t totRows = 0;
for(size_t i = 0; i < totalRoute; i++)
{
totRows += (solution.getTour(static_cast<int>(i)).getServedOrderCount() + 2);
}
*results = (vrp_result_element_t *) malloc(totRows * sizeof(vrp_result_element_t));
*result_count = totRows;
int cnt = 0;
for(size_t i = 0; i < totalRoute; i++)
{
ctour = solution.getTour(static_cast<int>(i));
std::vector<int> vecOrder = ctour.getOrderVector();
auto totalOrder = vecOrder.size();
// For start depot
(*results)[cnt].order_id = ctour.getStartDepot();
(*results)[cnt].order_pos = 0;
(*results)[cnt].vehicle_id = ctour.getVehicleId();
(*results)[cnt].arrival_time = -1;
(*results)[cnt].depart_time = ctour.getStartTime(0);
cnt++;
// For each order
for(size_t j = 0; j < totalOrder; j++)
{
(*results)[cnt].order_id = vecOrder[j];
(*results)[cnt].order_pos = static_cast<int>(j) + 1;
(*results)[cnt].vehicle_id = ctour.getVehicleId();
(*results)[cnt].depart_time = ctour.getStartTime(static_cast<int>(j) + 1);
(*results)[cnt].arrival_time = ctour.getStartTime(static_cast<int>(j) + 1) - solver.getServiceTime(vecOrder[j]);
cnt++;
}
// For return depot
(*results)[cnt].order_id = ctour.getEndDepot();
(*results)[cnt].order_pos = static_cast<int>(totalOrder) + 1;
(*results)[cnt].vehicle_id = ctour.getVehicleId();
(*results)[cnt].arrival_time = ctour.getStartTime(static_cast<int>(totalOrder) + 1);
(*results)[cnt].depart_time = -1;
cnt++;
}
}
catch(std::exception& e) {
*err_msg = (char *) e.what();
return -1;
}
catch(...) {
*err_msg = (char *) "Caught unknown exception!";
return -1;
}
}
return EXIT_SUCCESS;
}
| gpl-2.0 |
Libvisual/libvisual-avs | plugins/transform/rotblit/r_rotblit.cpp | 2 | 9395 | /*
LICENSE
-------
Copyright 2005 Nullsoft, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Nullsoft nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// alphachannel safe 11/21/99
#include <windows.h>
#include <commctrl.h>
#include "r_defs.h"
#include "resource.h"
#include "timing.h"
#ifndef LASER
#include <math.h>
#define M_PI 3.1415926536
#define C_THISCLASS C_RotBlitClass
#define MOD_NAME "Trans / Roto Blitter"
class C_THISCLASS : public C_RBASE {
protected:
public:
C_THISCLASS();
virtual ~C_THISCLASS();
virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
virtual char *get_desc() { return MOD_NAME; }
virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
virtual void load_config(unsigned char *data, int len);
virtual int save_config(unsigned char *data);
int zoom_scale, rot_dir, blend, beatch, beatch_speed, zoom_scale2, beatch_scale,scale_fpos;
int rot_rev;
int subpixel;
double rot_rev_pos;
int l_w, l_h;
int *w_mul;
};
#define PUT_INT(y) data[pos]=(y)&255; data[pos+1]=(y>>8)&255; data[pos+2]=(y>>16)&255; data[pos+3]=(y>>24)&255
#define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
void C_THISCLASS::load_config(unsigned char *data, int len)
{
int pos=0;
if (len-pos >= 4) { zoom_scale=GET_INT(); pos+=4; }
if (len-pos >= 4) { rot_dir=GET_INT(); pos+=4; }
if (len-pos >= 4) { blend=GET_INT(); pos+=4; }
if (len-pos >= 4) { beatch=GET_INT(); pos+=4; }
if (len-pos >= 4) { beatch_speed=GET_INT(); pos+=4; }
if (len-pos >= 4) { zoom_scale2=GET_INT(); pos+=4; }
if (len-pos >= 4) { beatch_scale=GET_INT(); pos+=4; }
if (len-pos >= 4) { subpixel=GET_INT(); pos+=4; }
else subpixel=0;
scale_fpos=zoom_scale;
}
int C_THISCLASS::save_config(unsigned char *data)
{
int pos=0;
PUT_INT(zoom_scale); pos+=4;
PUT_INT(rot_dir); pos+=4;
PUT_INT(blend); pos+=4;
PUT_INT(beatch); pos+=4;
PUT_INT(beatch_speed); pos+=4;
PUT_INT(zoom_scale2); pos+=4;
PUT_INT(beatch_scale); pos+=4;
PUT_INT(subpixel); pos+=4;
return pos;
}
C_THISCLASS::C_THISCLASS()
{
zoom_scale=31;
rot_dir=31;
blend=0;
rot_rev=1;
rot_rev_pos=1.0;
beatch=0;
l_w=l_h=0;
w_mul=NULL;
beatch_speed=0;
beatch_scale=0;
zoom_scale2=31;
scale_fpos=zoom_scale;
subpixel=1;
}
C_THISCLASS::~C_THISCLASS()
{
if (w_mul) GlobalFree(w_mul);
w_mul=NULL;
l_w=l_h=0;
}
int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
{
int y;
if (l_w != w || l_h != h || !w_mul) // generate width table
{
int x;
if (w_mul) GlobalFree(w_mul);
l_w=w;
l_h=h;
w_mul=(int *)GlobalAlloc(GMEM_FIXED,sizeof(int)*h);
for (x = 0; x < h; x ++)
w_mul[x]=x*w;
}
if (isBeat&0x80000000) return 0;
unsigned int *dest=(unsigned int *) fbout;
unsigned int *src=(unsigned int *) framebuffer;
unsigned int *bdest=(unsigned int *) framebuffer;
if (isBeat && beatch)
{
rot_rev=-rot_rev;
}
if (!beatch) rot_rev=1;
rot_rev_pos+=(1.0/(1+beatch_speed*4))*(rot_rev-rot_rev_pos);
if (rot_rev_pos > rot_rev && rot_rev>0) rot_rev_pos=rot_rev;
if (rot_rev_pos < rot_rev && rot_rev<0) rot_rev_pos=rot_rev;
if (isBeat && beatch_scale)
{
scale_fpos=zoom_scale2;
}
int f_val;
if (zoom_scale < zoom_scale2)
{
f_val=max(scale_fpos,zoom_scale);
if (scale_fpos > zoom_scale) scale_fpos -= 3;
}
else
{
f_val=min(scale_fpos,zoom_scale);
if (scale_fpos < zoom_scale) scale_fpos+=3;
}
double zoom = 1.0 + (f_val-31)/31.0;
double theta=((rot_dir-32))*rot_rev_pos;
double temp;
int ds_dx, dt_dx, ds_dy, dt_dy, s, t, sstart, tstart;
int x, offset=0;
temp = cos((theta)*M_PI/180.0)*zoom;
ds_dx = (int) (temp*65536.0);
dt_dy = (int) (temp*65536.0);
temp = sin((theta)*M_PI/180.0)*zoom;
ds_dy = - (int) (temp*65536.0);
dt_dx = (int) (temp*65536.0);
s = sstart = -(((w-1)/2)*ds_dx + ((h-1)/2)*ds_dy) + (w-1)*(32768 + (1<<20));
t = tstart = -(((w-1)/2)*dt_dx + ((h-1)/2)*dt_dy) + (h-1)*(32768 + (1<<20));
int ds, dt;
ds = (w-1)<<16;
dt = (h-1)<<16;
y = h;
if (ds_dx <= -ds || ds_dx >= ds || dt_dx <= -dt || dt_dx >= dt);
else while (y--)
{
if (ds) s %= ds;
if (dt) t %= dt;
if (s < 0) s+=ds; if (t < 0) t+=dt;
x = w;
offset = y*w;
#define DO_LOOP(Z) while (x--) { Z; s += ds_dx; t += dt_dx; }
#define DO_LOOPS(Z) \
if (ds_dx <= 0 && dt_dx <= 0) DO_LOOP(if (t < 0) t += dt; if (s < 0) s += ds; Z) \
else if (ds_dx <= 0) DO_LOOP(if (t >= dt) t -= dt; if (s < 0) s += ds; Z) \
else if (dt_dx <= 0) DO_LOOP(if (t < 0) t += dt; if (s >= ds) s -= ds; Z) \
else DO_LOOP(if (t >= dt) t -= dt; if (s >= ds) s -= ds; Z)
if (subpixel && blend) DO_LOOPS(*dest++ = BLEND_AVG(*bdest++,BLEND4_16(src+(s>>16)+w_mul[t>>16],w,s,t)))
else if (subpixel) DO_LOOPS(*dest++ = BLEND4_16(src+(s>>16)+w_mul[t>>16],w,s,t))
else if (!blend) DO_LOOPS(*dest++ = src[(s>>16)+w_mul[t>>16]])
else DO_LOOPS(*dest++ = BLEND_AVG(*bdest++,src[(s>>16)+w_mul[t>>16]]))
s = (sstart += ds_dy);
t = (tstart += dt_dy);
}
#ifndef NO_MMX
__asm emms;
#endif
return 1;
}
C_RBASE *R_RotBlit(char *desc)
{
if (desc) { strcpy(desc,MOD_NAME); return NULL; }
return (C_RBASE *) new C_THISCLASS();
}
static C_THISCLASS *g_this;
static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
{
int *a=NULL;
switch (uMsg)
{
case WM_INITDIALOG:
SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,0);
SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,256);
SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->zoom_scale);
SendDlgItemMessage(hwndDlg,IDC_SLIDER6,TBM_SETRANGEMIN,0,0);
SendDlgItemMessage(hwndDlg,IDC_SLIDER6,TBM_SETRANGEMAX,0,256);
SendDlgItemMessage(hwndDlg,IDC_SLIDER6,TBM_SETPOS,1,g_this->zoom_scale2);
SendDlgItemMessage(hwndDlg,IDC_SLIDER5,TBM_SETRANGEMIN,0,0);
SendDlgItemMessage(hwndDlg,IDC_SLIDER5,TBM_SETRANGEMAX,0,8);
SendDlgItemMessage(hwndDlg,IDC_SLIDER5,TBM_SETPOS,1,g_this->beatch_speed);
SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMIN,0,0);
SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMAX,0,64);
SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETPOS,1,g_this->rot_dir);
if (g_this->subpixel) CheckDlgButton(hwndDlg,IDC_CHECK2,BST_CHECKED);
else if (g_this->blend==1) CheckDlgButton(hwndDlg,IDC_BLEND,BST_CHECKED);
if (g_this->beatch==1) CheckDlgButton(hwndDlg,IDC_CHECK1,BST_CHECKED);
if (g_this->beatch_scale==1) CheckDlgButton(hwndDlg,IDC_CHECK6,BST_CHECKED);
return 1;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_BLEND:
if (IsDlgButtonChecked(hwndDlg,IDC_BLEND))
{
g_this->blend=1;
}
else g_this->blend=0;
break;
case IDC_CHECK1:
if (IsDlgButtonChecked(hwndDlg,IDC_CHECK1))
g_this->beatch=1;
else g_this->beatch=0;
break;
case IDC_CHECK2:
if (IsDlgButtonChecked(hwndDlg,IDC_CHECK2))
{
g_this->subpixel=1;
}
else g_this->subpixel=0;
break;
case IDC_CHECK6:
if (IsDlgButtonChecked(hwndDlg,IDC_CHECK6))
g_this->beatch_scale=1;
else g_this->beatch_scale=0;
break;
}
return 0;
case WM_HSCROLL:
{
HWND swnd = (HWND) lParam;
int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
{
g_this->zoom_scale=t;
}
if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER6))
{
g_this->zoom_scale2=t;
g_this->scale_fpos=t;
}
if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER2))
{
g_this->rot_dir=t;
}
if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER5))
{
g_this->beatch_speed=t;
}
}
}
return 0;
}
HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
{
g_this = this;
return CreateDialog(hInstance,MAKEINTRESOURCE(IDD_CFG_ROTBLT),hwndParent,g_DlgProc);
}
#else
C_RBASE *R_RotBlit(char *desc)
{ return NULL; }
#endif | gpl-2.0 |
geopython/QGIS | external/mdal/frmts/mdal_hec2d.cpp | 2 | 19913 | /*
MDAL - mMesh Data Abstraction Library (MIT License)
Copyright (C) 2016 Lutra Consulting
Copyright (C) 2018 Peter Petrik (zilolv at gmail dot com)
*/
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <iterator>
#include "assert.h"
#include "mdal_hec2d.hpp"
#include "mdal_hdf5.hpp"
#include "mdal_utils.hpp"
static HdfFile openHdfFile( const std::string &fileName )
{
HdfFile file( fileName );
if ( !file.isValid() )
{
throw MDAL_Status::Err_UnknownFormat;
}
return file;
}
static HdfGroup openHdfGroup( const HdfFile &hdfFile, const std::string &name )
{
HdfGroup grp = hdfFile.group( name );
if ( !grp.isValid() )
{
throw MDAL_Status::Err_UnknownFormat;
}
return grp;
}
static HdfGroup openHdfGroup( const HdfGroup &hdfGroup, const std::string &name )
{
HdfGroup grp = hdfGroup.group( name );
if ( !grp.isValid() )
{
throw MDAL_Status::Err_UnknownFormat;
}
return grp;
}
static HdfDataset openHdfDataset( const HdfGroup &hdfGroup, const std::string &name )
{
HdfDataset dsFileType = hdfGroup.dataset( name );
if ( !dsFileType.isValid() )
{
throw MDAL_Status::Err_UnknownFormat;
}
return dsFileType;
}
static std::string openHdfAttribute( const HdfFile &hdfFile, const std::string &name )
{
HdfAttribute attr = hdfFile.attribute( name );
if ( !attr.isValid() )
{
throw MDAL_Status::Err_UnknownFormat;
}
return attr.readString();
}
static HdfGroup getBaseOutputGroup( const HdfFile &hdfFile )
{
HdfGroup gResults = openHdfGroup( hdfFile, "Results" );
HdfGroup gUnsteady = openHdfGroup( gResults, "Unsteady" );
HdfGroup gOutput = openHdfGroup( gUnsteady, "Output" );
HdfGroup gOBlocks = openHdfGroup( gOutput, "Output Blocks" );
HdfGroup gBaseO = openHdfGroup( gOBlocks, "Base Output" );
return gBaseO;
}
static HdfGroup get2DFlowAreasGroup( const HdfFile &hdfFile, const std::string loc )
{
HdfGroup gBaseO = getBaseOutputGroup( hdfFile );
HdfGroup gLoc = openHdfGroup( gBaseO, loc );
HdfGroup g2DFlowRes = openHdfGroup( gLoc, "2D Flow Areas" );
return g2DFlowRes;
}
static std::vector<float> readTimes( const HdfFile &hdfFile )
{
HdfGroup gBaseO = getBaseOutputGroup( hdfFile );
HdfGroup gUnsteadTS = openHdfGroup( gBaseO, "Unsteady Time Series" );
HdfDataset dsTimes = openHdfDataset( gUnsteadTS, "Time" );
std::vector<float> times = dsTimes.readArray();
return times;
}
static std::vector<int> readFace2Cells( const HdfFile &hdfFile, const std::string &flowAreaName, size_t *nFaces )
{
// First read face to node mapping
HdfGroup gGeom = openHdfGroup( hdfFile, "Geometry" );
HdfGroup gGeom2DFlowAreas = openHdfGroup( gGeom, "2D Flow Areas" );
HdfGroup gArea = openHdfGroup( gGeom2DFlowAreas, flowAreaName );
HdfDataset dsFace2Cells = openHdfDataset( gArea, "Faces Cell Indexes" );
std::vector<hsize_t> fdims = dsFace2Cells.dims();
std::vector<int> face2Cells = dsFace2Cells.readArrayInt(); //2x nFaces
*nFaces = fdims[0];
return face2Cells;
}
void MDAL::DriverHec2D::readFaceOutput( const HdfFile &hdfFile,
const HdfGroup &rootGroup,
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames,
const std::string rawDatasetName,
const std::string datasetName,
const std::vector<float> × )
{
double eps = std::numeric_limits<double>::min();
std::shared_ptr<DatasetGroup> group = std::make_shared< DatasetGroup >(
name(),
mMesh.get(),
mFileName,
datasetName
);
group->setIsOnVertices( false );
group->setIsScalar( true );
std::vector<std::shared_ptr<MDAL::MemoryDataset>> datasets;
for ( size_t tidx = 0; tidx < times.size(); ++tidx )
{
std::shared_ptr<MDAL::MemoryDataset> dataset = std::make_shared< MemoryDataset >( group.get() );
double time = static_cast<double>( times[tidx] );
dataset->setTime( time );
datasets.push_back( dataset );
}
std::shared_ptr<MDAL::MemoryDataset> firstDataset;
for ( size_t nArea = 0; nArea < flowAreaNames.size(); ++nArea )
{
std::string flowAreaName = flowAreaNames[nArea];
size_t nFaces;
std::vector<int> face2Cells = readFace2Cells( hdfFile, flowAreaName, &nFaces );
HdfGroup gFlowAreaRes = openHdfGroup( rootGroup, flowAreaName );
HdfDataset dsVals = openHdfDataset( gFlowAreaRes, rawDatasetName );
std::vector<float> vals = dsVals.readArray();
for ( size_t tidx = 0; tidx < times.size(); ++tidx )
{
std::shared_ptr<MDAL::MemoryDataset> dataset = datasets[tidx];
double *values = dataset->values();
for ( size_t i = 0; i < nFaces; ++i )
{
size_t idx = tidx * nFaces + i;
double val = static_cast<double>( vals[idx] ); // This is value on face!
if ( !std::isnan( val ) && fabs( val ) > eps ) //not nan and not 0
{
for ( size_t c = 0; c < 2; ++c )
{
size_t cell_idx = static_cast<size_t>( face2Cells[2 * i + c] ) + areaElemStartIndex[nArea];
// Take just maximum
if ( std::isnan( values[cell_idx] ) || values[cell_idx] < val )
{
values[cell_idx] = val;
}
}
}
}
}
}
for ( auto dataset : datasets )
{
dataset->setStatistics( MDAL::calculateStatistics( dataset ) );
group->datasets.push_back( dataset );
}
group->setStatistics( MDAL::calculateStatistics( group ) );
mMesh->datasetGroups.push_back( group );
}
void MDAL::DriverHec2D::readFaceResults( const HdfFile &hdfFile,
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames )
{
// UNSTEADY
HdfGroup flowGroup = get2DFlowAreasGroup( hdfFile, "Unsteady Time Series" );
std::vector<float> times = readTimes( hdfFile );
readFaceOutput( hdfFile, flowGroup, areaElemStartIndex, flowAreaNames, "Face Shear Stress", "Face Shear Stress", times );
readFaceOutput( hdfFile, flowGroup, areaElemStartIndex, flowAreaNames, "Face Velocity", "Face Velocity", times );
// SUMMARY
flowGroup = get2DFlowAreasGroup( hdfFile, "Summary Output" );
times.clear();
times.push_back( 0.0f );
readFaceOutput( hdfFile, flowGroup, areaElemStartIndex, flowAreaNames, "Maximum Face Shear Stress", "Face Shear Stress/Maximums", times );
readFaceOutput( hdfFile, flowGroup, areaElemStartIndex, flowAreaNames, "Maximum Face Velocity", "Face Velocity/Maximums", times );
}
std::shared_ptr<MDAL::MemoryDataset> MDAL::DriverHec2D::readElemOutput( const HdfGroup &rootGroup,
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames,
const std::string rawDatasetName,
const std::string datasetName,
const std::vector<float> ×,
std::shared_ptr<MDAL::MemoryDataset> bed_elevation )
{
double eps = std::numeric_limits<double>::min();
std::shared_ptr<DatasetGroup> group = std::make_shared< DatasetGroup >(
name(),
mMesh.get(),
mFileName,
datasetName
);
group->setIsOnVertices( false );
group->setIsScalar( true );
std::vector<std::shared_ptr<MDAL::MemoryDataset>> datasets;
for ( size_t tidx = 0; tidx < times.size(); ++tidx )
{
std::shared_ptr<MDAL::MemoryDataset> dataset = std::make_shared< MemoryDataset >( group.get() );
double time = static_cast<double>( times[tidx] );
dataset->setTime( time );
datasets.push_back( dataset );
}
for ( size_t nArea = 0; nArea < flowAreaNames.size(); ++nArea )
{
size_t nAreaElements = areaElemStartIndex[nArea + 1] - areaElemStartIndex[nArea];
std::string flowAreaName = flowAreaNames[nArea];
HdfGroup gFlowAreaRes = openHdfGroup( rootGroup, flowAreaName );
HdfDataset dsVals = openHdfDataset( gFlowAreaRes, rawDatasetName );
std::vector<float> vals = dsVals.readArray();
for ( size_t tidx = 0; tidx < times.size(); ++tidx )
{
std::shared_ptr<MDAL::MemoryDataset> dataset = datasets[tidx];
double *values = dataset->values();
for ( size_t i = 0; i < nAreaElements; ++i )
{
size_t idx = tidx * nAreaElements + i;
size_t eInx = areaElemStartIndex[nArea] + i;
double val = static_cast<double>( vals[idx] );
if ( !std::isnan( val ) )
{
if ( !bed_elevation )
{
// we are populating bed elevation dataset
values[eInx] = val;
}
else
{
if ( datasetName == "Depth" )
{
if ( fabs( val ) > eps ) // 0 Depth is no-data
{
values[eInx] = val;
}
}
else //Water surface
{
assert( bed_elevation );
double bed_elev = bed_elevation->values()[eInx];
if ( std::isnan( bed_elev ) || fabs( bed_elev - val ) > eps ) // change from bed elevation
{
values[eInx] = val;
}
}
}
}
}
}
}
for ( auto dataset : datasets )
{
dataset->setStatistics( MDAL::calculateStatistics( dataset ) );
group->datasets.push_back( dataset );
}
group->setStatistics( MDAL::calculateStatistics( group ) );
mMesh->datasetGroups.push_back( group );
return datasets[0];
}
std::shared_ptr<MDAL::MemoryDataset> MDAL::DriverHec2D::readBedElevation(
const HdfGroup &gGeom2DFlowAreas,
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames )
{
std::vector<float> times( 1, 0.0f );
return readElemOutput(
gGeom2DFlowAreas,
areaElemStartIndex,
flowAreaNames,
"Cells Minimum Elevation",
"Bed Elevation",
times,
std::shared_ptr<MDAL::MemoryDataset>()
);
}
void MDAL::DriverHec2D::readElemResults(
const HdfFile &hdfFile,
std::shared_ptr<MDAL::MemoryDataset> bed_elevation,
const std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames )
{
// UNSTEADY
HdfGroup flowGroup = get2DFlowAreasGroup( hdfFile, "Unsteady Time Series" );
std::vector<float> times = readTimes( hdfFile );
readElemOutput(
flowGroup,
areaElemStartIndex,
flowAreaNames,
"Water Surface",
"Water Surface",
times,
bed_elevation );
readElemOutput(
flowGroup,
areaElemStartIndex,
flowAreaNames,
"Depth",
"Depth",
times,
bed_elevation );
// SUMMARY
flowGroup = get2DFlowAreasGroup( hdfFile, "Summary Output" );
times.clear();
times.push_back( 0.0f );
readElemOutput(
flowGroup,
areaElemStartIndex,
flowAreaNames,
"Maximum Water Surface",
"Water Surface/Maximums",
times,
bed_elevation
);
}
std::vector<std::string> MDAL::DriverHec2D::read2DFlowAreasNamesOld( HdfGroup gGeom2DFlowAreas ) const
{
HdfDataset dsNames = openHdfDataset( gGeom2DFlowAreas, "Names" );
std::vector<std::string> names = dsNames.readArrayString();
if ( names.empty() )
{
throw MDAL_Status::Err_InvalidData;
}
return names;
}
/**
For 5.0.5+ format
DATATYPE H5T_COMPOUND {
H5T_STRING {
STRSIZE 16;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
} "Name";
H5T_IEEE_F32LE "Mann";
H5T_IEEE_F32LE "Cell Vol Tol";
H5T_IEEE_F32LE "Cell Min Area Fraction";
H5T_IEEE_F32LE "Face Profile Tol";
H5T_IEEE_F32LE "Face Area Tol";
H5T_IEEE_F32LE "Face Conv Ratio";
H5T_IEEE_F32LE "Laminar Depth";
H5T_IEEE_F32LE "Spacing dx";
H5T_IEEE_F32LE "Spacing dy";
H5T_IEEE_F32LE "Shift dx";
H5T_IEEE_F32LE "Shift dy";
H5T_STD_I32LE "Cell Count";
}
*/
typedef struct FlowAreasAttribute505
{
char name[HDF_MAX_NAME];
float mann;
float cellVolTol;
float cellMinAreaFraction;
float faceProfileTol;
float faceAreaTol;
float faceConvRatio;
float laminarDepth;
float spacingDx;
float spacingDy;
float shifyDx;
float shifyDy;
int cellCount;
} FlowAreasAttribute505;
std::vector<std::string> MDAL::DriverHec2D::read2DFlowAreasNames505( HdfGroup gGeom2DFlowAreas ) const
{
HdfDataset dsAttributes = openHdfDataset( gGeom2DFlowAreas, "Attributes" );
hid_t attributeHID = H5Tcreate( H5T_COMPOUND, sizeof( FlowAreasAttribute505 ) );
hid_t stringHID = H5Tcopy( H5T_C_S1 );
H5Tset_size( stringHID, HDF_MAX_NAME );
H5Tinsert( attributeHID, "Name", HOFFSET( FlowAreasAttribute505, name ), stringHID );
H5Tinsert( attributeHID, "Mann", HOFFSET( FlowAreasAttribute505, mann ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Cell Vol Tol", HOFFSET( FlowAreasAttribute505, cellVolTol ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Cell Min Area Fraction", HOFFSET( FlowAreasAttribute505, cellMinAreaFraction ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Face Profile Tol", HOFFSET( FlowAreasAttribute505, faceProfileTol ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Face Area Tol", HOFFSET( FlowAreasAttribute505, faceAreaTol ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Face Conv Ratio", HOFFSET( FlowAreasAttribute505, faceConvRatio ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Laminar Depth", HOFFSET( FlowAreasAttribute505, laminarDepth ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Spacing dx", HOFFSET( FlowAreasAttribute505, spacingDx ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Spacing dy", HOFFSET( FlowAreasAttribute505, spacingDy ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Shift dx", HOFFSET( FlowAreasAttribute505, shifyDx ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Shift dy", HOFFSET( FlowAreasAttribute505, shifyDy ), H5T_NATIVE_FLOAT );
H5Tinsert( attributeHID, "Cell Count", HOFFSET( FlowAreasAttribute505, cellCount ), H5T_NATIVE_INT );
std::vector<FlowAreasAttribute505> attributes = dsAttributes.readArray<FlowAreasAttribute505>( attributeHID );
H5Tclose( attributeHID );
H5Tclose( stringHID );
std::vector<std::string> names;
if ( attributes.empty() )
{
throw MDAL_Status::Err_InvalidData;
}
for ( const auto &attr : attributes )
{
std::string dat = std::string( attr.name );
names.push_back( MDAL::trim( dat ) );
}
return names;
}
void MDAL::DriverHec2D::setProjection( HdfFile hdfFile )
{
try
{
std::string proj_wkt = openHdfAttribute( hdfFile, "Projection" );
mMesh->setSourceCrsFromWKT( proj_wkt );
}
catch ( MDAL_Status ) { /* projection not set */}
}
void MDAL::DriverHec2D::parseMesh(
HdfGroup gGeom2DFlowAreas,
std::vector<size_t> &areaElemStartIndex,
const std::vector<std::string> &flowAreaNames )
{
Faces faces;
Vertices vertices;
size_t maxVerticesInFace = 0;
for ( size_t nArea = 0; nArea < flowAreaNames.size(); ++nArea )
{
std::string flowAreaName = flowAreaNames[nArea];
HdfGroup gArea = openHdfGroup( gGeom2DFlowAreas, flowAreaName );
HdfDataset dsCoords = openHdfDataset( gArea, "FacePoints Coordinate" );
std::vector<hsize_t> cdims = dsCoords.dims();
std::vector<double> coords = dsCoords.readArrayDouble(); //2xnNodes matrix in array
size_t nNodes = cdims[0];
size_t areaNodeStartIndex = vertices.size();
vertices.resize( areaNodeStartIndex + nNodes );
for ( size_t n = 0; n < nNodes; ++n )
{
size_t nIdx = areaNodeStartIndex + n;
vertices[nIdx].x = coords[cdims[1] * n];
vertices[nIdx].y = coords[cdims[1] * n + 1];
}
HdfDataset dsElems = openHdfDataset( gArea, "Cells FacePoint Indexes" );
std::vector<hsize_t> edims = dsElems.dims();
size_t nElems = edims[0];
size_t maxFaces = edims[1]; // elems have up to 8 faces, but sometimes the table has less than 8 columns
std::vector<int> elem_nodes = dsElems.readArrayInt(); //maxFacesxnElements matrix in array
areaElemStartIndex[nArea] = faces.size();
faces.resize( faces.size() + nElems );
for ( size_t e = 0; e < nElems; ++e )
{
size_t eIdx = areaElemStartIndex[nArea] + e;
std::vector<size_t> idx( maxFaces );
size_t nValidVertexes = maxFaces;
for ( size_t fi = 0; fi < maxFaces; ++fi )
{
int elem_node_idx = elem_nodes[edims[1] * e + fi];
if ( elem_node_idx == -1 )
{
nValidVertexes = fi;
break;
}
else
{
idx[fi] = areaNodeStartIndex + static_cast<size_t>( elem_node_idx ); // shift by this area start node index
}
}
if ( nValidVertexes > 0 )
faces[eIdx].assign( idx.begin(), std::next( idx.begin(), nValidVertexes ) );
if ( nValidVertexes > maxVerticesInFace )
maxVerticesInFace = nValidVertexes;
}
}
areaElemStartIndex[flowAreaNames.size()] = faces.size();
mMesh.reset(
new MemoryMesh(
name(),
vertices.size(),
faces.size(),
maxVerticesInFace,
computeExtent( vertices ),
mFileName
)
);
mMesh->faces = faces;
mMesh->vertices = vertices;
}
MDAL::DriverHec2D::DriverHec2D()
: Driver( "HEC2D",
"HEC-RAS 2D",
"*.hdf",
Capability::ReadMesh )
{
}
MDAL::DriverHec2D *MDAL::DriverHec2D::create()
{
return new DriverHec2D();
}
bool MDAL::DriverHec2D::canRead( const std::string &uri )
{
try
{
HdfFile hdfFile = openHdfFile( uri );
std::string fileType = openHdfAttribute( hdfFile, "File Type" );
return canReadOldFormat( fileType ) || canReadFormat505( fileType );
}
catch ( MDAL_Status )
{
return false;
}
}
bool MDAL::DriverHec2D::canReadOldFormat( const std::string &fileType ) const
{
return fileType == "HEC-RAS Results";
}
bool MDAL::DriverHec2D::canReadFormat505( const std::string &fileType ) const
{
return fileType == "HEC-RAS Geometry";
}
std::unique_ptr<MDAL::Mesh> MDAL::DriverHec2D::load( const std::string &resultsFile, MDAL_Status *status )
{
mFileName = resultsFile;
if ( status ) *status = MDAL_Status::None;
mMesh.reset();
try
{
HdfFile hdfFile = openHdfFile( mFileName );
// Verify it is correct file
std::string fileType = openHdfAttribute( hdfFile, "File Type" );
bool oldFormat = canReadOldFormat( fileType );
HdfGroup gGeom = openHdfGroup( hdfFile, "Geometry" );
HdfGroup gGeom2DFlowAreas = openHdfGroup( gGeom, "2D Flow Areas" );
std::vector<std::string> flowAreaNames;
if ( oldFormat )
flowAreaNames = read2DFlowAreasNamesOld( gGeom2DFlowAreas );
else
flowAreaNames = read2DFlowAreasNames505( gGeom2DFlowAreas );
std::vector<size_t> areaElemStartIndex( flowAreaNames.size() + 1 );
parseMesh( gGeom2DFlowAreas, areaElemStartIndex, flowAreaNames );
setProjection( hdfFile );
//Elevation
std::shared_ptr<MDAL::MemoryDataset> bed_elevation = readBedElevation( gGeom2DFlowAreas, areaElemStartIndex, flowAreaNames );
// Element centered Values
readElemResults( hdfFile, bed_elevation, areaElemStartIndex, flowAreaNames );
// Face centered Values
readFaceResults( hdfFile, areaElemStartIndex, flowAreaNames );
}
catch ( MDAL_Status error )
{
if ( status ) *status = ( error );
mMesh.reset();
}
return std::unique_ptr<Mesh>( mMesh.release() );
}
| gpl-2.0 |
cedric-vincent/PRoot | src/path/path.c | 2 | 19659 | /* -*- c-set-style: "K&R"; c-basic-offset: 8 -*-
*
* This file is part of PRoot.
*
* Copyright (C) 2015 STMicroelectronics
*
* 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.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*/
#include <string.h> /* string(3), */
#include <stdarg.h> /* va_*(3), */
#include <assert.h> /* assert(3), */
#include <fcntl.h> /* AT_*, */
#include <unistd.h> /* readlink*(2), *stat(2), getpid(2), */
#include <sys/types.h> /* pid_t, */
#include <sys/stat.h> /* S_ISDIR, */
#include <dirent.h> /* opendir(3), readdir(3), */
#include <stdio.h> /* snprintf(3), */
#include <errno.h> /* E*, */
#include <stddef.h> /* ptrdiff_t, */
#include <inttypes.h> /* PRI*, */
#include "path/path.h"
#include "path/binding.h"
#include "path/canon.h"
#include "path/proc.h"
#include "extension/extension.h"
#include "cli/note.h"
#include "build.h"
#include "compat.h"
/**
* Copy in @result the concatenation of several paths (@number_paths)
* and adds a path separator ('/') in between when needed. This
* function returns -errno if an error occured, otherwise it returns 0.
*/
int join_paths(int number_paths, char result[PATH_MAX], ...)
{
va_list paths;
size_t length;
int status;
int i;
result[0] = '\0';
length = 0;
status = 0;
/* Parse the list of variadic arguments. */
va_start(paths, result);
for (i = 0; i < number_paths; i++) {
const char *path;
size_t path_length;
size_t new_length;
path = va_arg(paths, const char *);
if (path == NULL)
continue;
path_length = strlen(path);
/* A new path separator is needed. */
if (length > 0 && result[length - 1] != '/' && path[0] != '/') {
new_length = length + path_length + 1;
if (new_length + 1 >= PATH_MAX) {
status = -ENAMETOOLONG;
break;
}
strcat(result + length, "/");
strcat(result + length, path);
length = new_length;
}
/* There are already two path separators. */
else if (length > 0 && result[length - 1] == '/' && path[0] == '/') {
new_length = length + path_length - 1;
if (new_length + 1 >= PATH_MAX) {
status = -ENAMETOOLONG;
break;
}
strcat(result + length, path + 1);
length += path_length - 1;
}
/* There's already one path separator or result[] is empty. */
else {
new_length = length + path_length;
if (new_length + 1 >= PATH_MAX) {
status = -ENAMETOOLONG;
break;
}
strcat(result + length, path);
length += path_length;
}
status = 0;
}
va_end(paths);
return status;
}
/**
* Put in @host_path the full path to the given shell @command. The
* @command is searched in @paths if not null, otherwise in $PATH
* (relatively to the @tracee's file-system name-space). This
* function always returns -1 on error, otherwise 0.
*/
int which(Tracee *tracee, const char *paths, char host_path[PATH_MAX], const char *command)
{
char path[PATH_MAX];
const char *cursor;
struct stat statr;
int status;
bool is_explicit;
bool found;
assert(command != NULL);
is_explicit = (strchr(command, '/') != NULL);
/* Is the command available without any $PATH look-up? */
status = realpath2(tracee, host_path, command, true);
if (status == 0 && stat(host_path, &statr) == 0) {
if (is_explicit && !S_ISREG(statr.st_mode)) {
note(tracee, ERROR, USER, "'%s' is not a regular file", command);
return -EACCES;
}
if (is_explicit && (statr.st_mode & S_IXUSR) == 0) {
note(tracee, ERROR, USER, "'%s' is not executable", command);
return -EACCES;
}
found = true;
/* Don't dereference the final component to preserve
* argv0 in case it is a symlink to script. */
(void) realpath2(tracee, host_path, command, false);
}
else
found = false;
/* Is the the explicit command was found? */
if (is_explicit) {
if (found)
return 0;
else
goto not_found;
}
/* Otherwise search the command in $PATH. */
paths = paths ?: getenv("PATH");
if (paths == NULL || strcmp(paths, "") == 0)
goto not_found;
cursor = paths;
do {
size_t length;
length = strcspn(cursor, ":");
cursor += length + 1;
if (length >= PATH_MAX)
continue;
else if (length == 0)
strcpy(path, ".");
else {
strncpy(path, cursor - length - 1, length);
path[length] = '\0';
}
/* Avoid buffer-overflow. */
if (length + strlen(command) + 2 >= PATH_MAX)
continue;
strcat(path, "/");
strcat(path, command);
status = realpath2(tracee, host_path, path, true);
if (status == 0
&& stat(host_path, &statr) == 0
&& S_ISREG(statr.st_mode)
&& (statr.st_mode & S_IXUSR) != 0) {
/* Don't dereference the final component to preserve
* argv0 in case it is a symlink to script. */
(void) realpath2(tracee, host_path, path, false);
return 0;
}
} while (*(cursor - 1) != '\0');
not_found:
status = getcwd2(tracee, path);
if (status < 0)
strcpy(path, "<unknown>");
note(tracee, ERROR, USER, "'%s' not found (root = %s, cwd = %s, $PATH=%s)",
command, get_root(tracee), path, paths);
/* Check if the command was found without any $PATH look-up
* but it didn't contain "/". */
if (found && !is_explicit)
note(tracee, ERROR, USER,
"to execute a local program, use the './' prefix, for example: ./%s", command);
return -1;
}
/**
* Put in @host_path the canonicalized form of @path. In the nominal
* case (@tracee == NULL), this function is barely equivalent to
* realpath(), but when doing sub-reconfiguration, the path is
* canonicalized relatively to the current @tracee's file-system
* name-space. This function returns -errno on error, otherwise 0.
*/
int realpath2(Tracee *tracee, char host_path[PATH_MAX], const char *path, bool deref_final)
{
int status;
if (tracee == NULL)
status = (realpath(path, host_path) == NULL ? -errno : 0);
else
status = translate_path(tracee, host_path, AT_FDCWD, path, deref_final);
return status;
}
/**
* Put in @guest_path the canonicalized current working directory. In
* the nominal case (@tracee == NULL), this function is barely
* equivalent to realpath(), but when doing sub-reconfiguration, the
* path is canonicalized relatively to the current @tracee's
* file-system name-space. This function returns -errno on error,
* otherwise 0.
*/
int getcwd2(Tracee *tracee, char guest_path[PATH_MAX])
{
if (tracee == NULL) {
if (getcwd(guest_path, PATH_MAX) == NULL)
return -errno;
}
else {
if (strlen(tracee->fs->cwd) >= PATH_MAX)
return -ENAMETOOLONG;
strcpy(guest_path, tracee->fs->cwd);
}
return 0;
}
/**
* Remove the trailing "/" or "/.".
*/
void chop_finality(char *path)
{
size_t length = strlen(path);
if (path[length - 1] == '.') {
assert(length >= 2);
/* Special case for "/." */
if (length == 2)
path[length - 1] = '\0';
else
path[length - 2] = '\0';
}
else if (path[length - 1] == '/') {
/* Special case for "/" */
if (length > 1)
path[length - 1] = '\0';
}
}
/**
* Put in @path the result of readlink(/proc/@pid/fd/@fd). This
* function returns -errno if an error occured, otherwise 0.
*/
int readlink_proc_pid_fd(pid_t pid, int fd, char path[PATH_MAX])
{
char link[32]; /* 32 > sizeof("/proc//cwd") + sizeof(#ULONG_MAX) */
int status;
/* Format the path to the "virtual" link. */
status = snprintf(link, sizeof(link), "/proc/%d/fd/%d", pid, fd);
if (status < 0)
return -EBADF;
if ((size_t) status >= sizeof(link))
return -EBADF;
/* Read the value of this "virtual" link. */
status = readlink(link, path, PATH_MAX);
if (status < 0)
return -EBADF;
if (status >= PATH_MAX)
return -ENAMETOOLONG;
path[status] = '\0';
return 0;
}
/**
* Copy in @result the equivalent of "@tracee->root + canon(@dir_fd +
* @user_path)". If @user_path is not absolute then it is relative to
* the directory referred by the descriptor @dir_fd (AT_FDCWD is for
* the current working directory). See the documentation of
* canonicalize() for the meaning of @deref_final. This function
* returns -errno if an error occured, otherwise 0.
*/
int translate_path(Tracee *tracee, char result[PATH_MAX], int dir_fd,
const char *user_path, bool deref_final)
{
char guest_path[PATH_MAX];
int status;
/* Use "/" as the base if it is an absolute guest path. */
if (user_path[0] == '/') {
strcpy(result, "/");
}
/* It is relative to a directory referred by a descriptor, see
* openat(2) for details. */
else if (dir_fd != AT_FDCWD) {
/* /proc/@tracee->pid/fd/@dir_fd -> result. */
status = readlink_proc_pid_fd(tracee->pid, dir_fd, result);
if (status < 0)
return status;
/* Named file descriptors may reference special
* objects like pipes, sockets, inodes, ... Such
* objects do not belong to the file-system. */
if (result[0] != '/')
return -ENOTDIR;
/* Remove the leading "root" part of the base
* (required!). */
status = detranslate_path(tracee, result, NULL);
if (status < 0)
return status;
}
/* It is relative to the current working directory. */
else {
status = getcwd2(tracee, result);
if (status < 0)
return status;
}
VERBOSE(tracee, 2, "vpid %" PRIu64 ": translate(\"%s\" + \"%s\")",
tracee != NULL ? tracee->vpid : 0, result, user_path);
status = notify_extensions(tracee, GUEST_PATH, (intptr_t) result, (intptr_t) user_path);
if (status < 0)
return status;
if (status > 0)
goto skip;
/* So far "result" was used as a base path, it's time to join
* it to the user path. */
assert(result[0] == '/');
status = join_paths(2, guest_path, result, user_path);
if (status < 0)
return status;
strcpy(result, "/");
/* Canonicalize regarding the new root. */
status = canonicalize(tracee, guest_path, deref_final, result, 0);
if (status < 0)
return status;
/* Final binding substitution to convert "result" into a host
* path, since canonicalize() works from the guest
* point-of-view. */
status = substitute_binding(tracee, GUEST, result);
if (status < 0)
return status;
skip:
VERBOSE(tracee, 2, "vpid %" PRIu64 ": -> \"%s\"",
tracee != NULL ? tracee->vpid : 0, result);
status = notify_extensions(tracee, TRANSLATED_PATH, (intptr_t) result, 0);
if (status < 0)
return status;
return 0;
}
/**
* Remove/substitute the leading part of a "translated" @path. It
* returns 0 if no transformation is required (ie. symmetric binding),
* otherwise it returns the size in bytes of the updated @path,
* including the end-of-string terminator. On error it returns
* -errno.
*/
int detranslate_path(Tracee *tracee, char path[PATH_MAX], const char t_referrer[PATH_MAX])
{
size_t prefix_length;
ssize_t new_length;
bool sanity_check;
bool follow_binding;
/* Sanity check. */
if (strnlen(path, PATH_MAX) >= PATH_MAX)
return -ENAMETOOLONG;
/* Don't try to detranslate relative paths (typically the
* target of a relative symbolic link). */
if (path[0] != '/')
return 0;
/* Is it a symlink? */
if (t_referrer != NULL) {
Comparison comparison;
sanity_check = false;
follow_binding = false;
/* In some cases bindings have to be resolved. */
comparison = compare_paths("/proc", t_referrer);
if (comparison == PATH1_IS_PREFIX) {
/* Some links in "/proc" are generated
* dynamically by the kernel. PRoot has to
* emulate some of them. */
char proc_path[PATH_MAX];
strcpy(proc_path, path);
new_length = readlink_proc2(tracee, proc_path, t_referrer);
if (new_length < 0)
return new_length;
if (new_length != 0) {
strcpy(path, proc_path);
return new_length + 1;
}
/* Always resolve bindings for symlinks in
* "/proc", they always point to the emulated
* file-system namespace by design. */
follow_binding = true;
}
else if (!belongs_to_guestfs(tracee, t_referrer)) {
const char *binding_referree;
const char *binding_referrer;
binding_referree = get_path_binding(tracee, HOST, path);
binding_referrer = get_path_binding(tracee, HOST, t_referrer);
assert(binding_referrer != NULL);
/* Resolve bindings for symlinks that belong
* to a binding and point to the same binding.
* For example, if "-b /lib:/foo" is specified
* and the symlink "/lib/a -> /lib/b" exists
* in the host rootfs namespace, then it
* should appear as "/foo/a -> /foo/b" in the
* guest rootfs namespace for consistency
* reasons. */
if (binding_referree != NULL) {
comparison = compare_paths(binding_referree, binding_referrer);
follow_binding = (comparison == PATHS_ARE_EQUAL);
}
}
}
else {
sanity_check = true;
follow_binding = true;
}
if (follow_binding) {
switch (substitute_binding(tracee, HOST, path)) {
case 0:
return 0;
case 1:
return strlen(path) + 1;
default:
break;
}
}
switch (compare_paths(get_root(tracee), path)) {
case PATH1_IS_PREFIX:
/* Remove the leading part, that is, the "root". */
prefix_length = strlen(get_root(tracee));
/* Special case when path to the guest rootfs == "/". */
if (prefix_length == 1)
prefix_length = 0;
new_length = strlen(path) - prefix_length;
memmove(path, path + prefix_length, new_length);
path[new_length] = '\0';
break;
case PATHS_ARE_EQUAL:
/* Special case when path == root. */
new_length = 1;
strcpy(path, "/");
break;
default:
/* Ensure the path is within the new root. */
if (sanity_check)
return -EPERM;
else
return 0;
}
return new_length + 1;
}
/**
* Check if the translated @host_path belongs to the guest rootfs,
* that is, isn't from a binding.
*/
bool belongs_to_guestfs(const Tracee *tracee, const char *host_path)
{
Comparison comparison;
comparison = compare_paths(get_root(tracee), host_path);
return (comparison == PATHS_ARE_EQUAL || comparison == PATH1_IS_PREFIX);
}
/**
* Compare @path1 with @path2, which are respectively @length1 and
* @length2 long.
*
* This function works only with paths canonicalized in the same
* namespace (host/guest)!
*/
Comparison compare_paths2(const char *path1, size_t length1, const char *path2, size_t length2)
{
size_t length_min;
bool is_prefix;
char sentinel;
#if defined DEBUG_OPATH
assert(length(path1) == length1);
assert(length(path2) == length2);
#endif
assert(length1 > 0);
assert(length2 > 0);
if (!length1 || !length2) {
return PATHS_ARE_NOT_COMPARABLE;
}
/* Remove potential trailing '/' for the comparison. */
if (path1[length1 - 1] == '/')
length1--;
if (path2[length2 - 1] == '/')
length2--;
if (length1 < length2) {
length_min = length1;
sentinel = path2[length_min];
}
else {
length_min = length2;
sentinel = path1[length_min];
}
/* Optimize obvious cases. */
if (sentinel != '/' && sentinel != '\0')
return PATHS_ARE_NOT_COMPARABLE;
is_prefix = (strncmp(path1, path2, length_min) == 0);
if (!is_prefix)
return PATHS_ARE_NOT_COMPARABLE;
if (length1 == length2)
return PATHS_ARE_EQUAL;
else if (length1 < length2)
return PATH1_IS_PREFIX;
else if (length1 > length2)
return PATH2_IS_PREFIX;
assert(0);
return PATHS_ARE_NOT_COMPARABLE;
}
Comparison compare_paths(const char *path1, const char *path2)
{
return compare_paths2(path1, strlen(path1), path2, strlen(path2));
}
typedef int (*foreach_fd_t)(const Tracee *tracee, int fd, char path[PATH_MAX]);
/**
* Call @callback on each open file descriptors of @pid. It returns
* the status of the first failure, that is, if @callback returned
* seomthing lesser than 0, otherwise 0.
*/
static int foreach_fd(const Tracee *tracee, foreach_fd_t callback)
{
struct dirent *dirent;
char path[PATH_MAX];
char proc_fd[32]; /* 32 > sizeof("/proc//fd") + sizeof(#ULONG_MAX) */
int status;
DIR *dirp;
/* Format the path to the "virtual" directory. */
status = snprintf(proc_fd, sizeof(proc_fd), "/proc/%d/fd", tracee->pid);
if (status < 0 || (size_t) status >= sizeof(proc_fd))
return 0;
/* Open the virtual directory "/proc/$pid/fd". */
dirp = opendir(proc_fd);
if (dirp == NULL)
return 0;
while ((dirent = readdir(dirp)) != NULL) {
/* Read the value of this "virtual" link. Don't use
* readlinkat(2) here since it would require Linux >=
* 2.6.16 and Glibc >= 2.4, whereas PRoot is supposed
* to work on any Linux 2.6 systems. */
char tmp[PATH_MAX];
if (strlen(proc_fd) + strlen(dirent->d_name) + 1 >= PATH_MAX)
continue;
strcpy(tmp, proc_fd);
strcat(tmp, "/");
strcat(tmp, dirent->d_name);
status = readlink(tmp, path, PATH_MAX);
if (status < 0 || status >= PATH_MAX)
continue;
path[status] = '\0';
/* Ensure it points to a path (not a socket or somethink like that). */
if (path[0] != '/')
continue;
status = callback(tracee, atoi(dirent->d_name), path);
if (status < 0)
goto end;
}
status = 0;
end:
closedir(dirp);
return status;
}
/**
* Helper for list_open_fd().
*/
static int list_open_fd_callback(const Tracee *tracee, int fd, char path[PATH_MAX])
{
VERBOSE(tracee, 1, "pid %d: access to \"%s\" (fd %d) won't be translated until closed",
tracee->pid, path, fd);
notify_extensions((Tracee*)tracee, ALREADY_OPENED_FD, (intptr_t)path, (intptr_t)fd);
return 0;
}
/**
* Warn for files that are open. It is useful right after PRoot has
* attached a process.
*/
int list_open_fd(const Tracee *tracee)
{
return foreach_fd(tracee, list_open_fd_callback);
}
/**
* Substitute the first @old_prefix_length bytes of @path with
* @new_prefix (the caller has to provides a correct
* @new_prefix_length). This function returns the new length of
* @path. Note: this function takes care about special cases (like
* "/").
*/
size_t substitute_path_prefix(char path[PATH_MAX], size_t old_prefix_length,
const char *new_prefix, size_t new_prefix_length)
{
size_t path_length;
size_t new_length;
path_length = strlen(path);
assert(old_prefix_length < PATH_MAX);
assert(new_prefix_length < PATH_MAX);
if (new_prefix_length == 1) {
/* Special case: "/foo" -> "/". Substitute "/foo/bin"
* with "/bin" not "//bin". */
new_length = path_length - old_prefix_length;
if (new_length != 0)
memmove(path, path + old_prefix_length, new_length);
else {
/* Special case: "/". */
path[0] = '/';
new_length = 1;
}
}
else if (old_prefix_length == 1) {
/* Special case: "/" -> "/foo". Substitute "/bin" with
* "/foo/bin" not "/foobin". */
new_length = new_prefix_length + path_length;
if (new_length >= PATH_MAX)
return -ENAMETOOLONG;
if (path_length > 1) {
memmove(path + new_prefix_length, path, path_length);
memcpy(path, new_prefix, new_prefix_length);
}
else {
/* Special case: "/". */
memcpy(path, new_prefix, new_prefix_length);
new_length = new_prefix_length;
}
}
else {
/* Generic case. */
new_length = path_length - old_prefix_length + new_prefix_length;
if (new_length >= PATH_MAX)
return -ENAMETOOLONG;
memmove(path + new_prefix_length,
path + old_prefix_length,
path_length - old_prefix_length);
memcpy(path, new_prefix, new_prefix_length);
}
assert(new_length < PATH_MAX);
path[new_length] = '\0';
return new_length;
}
| gpl-2.0 |
thanhphat11/Googy-Max-N4-TW511-Kernel | mm/slub.c | 2 | 134336 | /*
* SLUB: A slab allocator that limits cache line use instead of queuing
* objects in per cpu and per node lists.
*
* The allocator synchronizes using per slab locks or atomic operatios
* and only uses a centralized lock to manage a pool of partial slabs.
*
* (C) 2007 SGI, Christoph Lameter
* (C) 2011 Linux Foundation, Christoph Lameter
*/
#include <linux/mm.h>
#include <linux/swap.h> /* struct reclaim_state */
#include <linux/module.h>
#include <linux/bit_spinlock.h>
#include <linux/interrupt.h>
#include <linux/bitops.h>
#include <linux/slab.h>
#include "slab.h"
#include <linux/proc_fs.h>
#include <linux/notifier.h>
#include <linux/seq_file.h>
#include <linux/kmemcheck.h>
#include <linux/cpu.h>
#include <linux/cpuset.h>
#include <linux/mempolicy.h>
#include <linux/ctype.h>
#include <linux/debugobjects.h>
#include <linux/kallsyms.h>
#include <linux/memory.h>
#include <linux/math64.h>
#include <linux/fault-inject.h>
#include <linux/stacktrace.h>
#include <linux/prefetch.h>
#include <linux/memcontrol.h>
#ifdef CONFIG_TIMA_RKP_RO_CRED
#include <linux/security.h>
#endif /*CONFIG_TIMA_RKP_RO_CRED*/
#ifdef CONFIG_TIMA_RKP_RO_CRED
#define check_cred_cache(s,r) \
do { \
if ((s->name) && !strcmp(s->name,"cred_jar_ro")) \
return r; \
} while (0)
#else
#define check_cred_cache(s,r)
#endif /* CONFIG_TIMA_RKP_RO_CRED */
#include <trace/events/kmem.h>
#include "internal.h"
/*
* Lock order:
* 1. slab_mutex (Global Mutex)
* 2. node->list_lock
* 3. slab_lock(page) (Only on some arches and for debugging)
*
* slab_mutex
*
* The role of the slab_mutex is to protect the list of all the slabs
* and to synchronize major metadata changes to slab cache structures.
*
* The slab_lock is only used for debugging and on arches that do not
* have the ability to do a cmpxchg_double. It only protects the second
* double word in the page struct. Meaning
* A. page->freelist -> List of object free in a page
* B. page->counters -> Counters of objects
* C. page->frozen -> frozen state
*
* If a slab is frozen then it is exempt from list management. It is not
* on any list. The processor that froze the slab is the one who can
* perform list operations on the page. Other processors may put objects
* onto the freelist but the processor that froze the slab is the only
* one that can retrieve the objects from the page's freelist.
*
* The list_lock protects the partial and full list on each node and
* the partial slab counter. If taken then no new slabs may be added or
* removed from the lists nor make the number of partial slabs be modified.
* (Note that the total number of slabs is an atomic value that may be
* modified without taking the list lock).
*
* The list_lock is a centralized lock and thus we avoid taking it as
* much as possible. As long as SLUB does not have to handle partial
* slabs, operations can continue without any centralized lock. F.e.
* allocating a long series of objects that fill up slabs does not require
* the list lock.
* Interrupts are disabled during allocation and deallocation in order to
* make the slab allocator safe to use in the context of an irq. In addition
* interrupts are disabled to ensure that the processor does not change
* while handling per_cpu slabs, due to kernel preemption.
*
* SLUB assigns one slab for allocation to each processor.
* Allocations only occur from these slabs called cpu slabs.
*
* Slabs with free elements are kept on a partial list and during regular
* operations no list for full slabs is used. If an object in a full slab is
* freed then the slab will show up again on the partial lists.
* We track full slabs for debugging purposes though because otherwise we
* cannot scan all objects.
*
* Slabs are freed when they become empty. Teardown and setup is
* minimal so we rely on the page allocators per cpu caches for
* fast frees and allocs.
*
* Overloading of page flags that are otherwise used for LRU management.
*
* PageActive The slab is frozen and exempt from list processing.
* This means that the slab is dedicated to a purpose
* such as satisfying allocations for a specific
* processor. Objects may be freed in the slab while
* it is frozen but slab_free will then skip the usual
* list operations. It is up to the processor holding
* the slab to integrate the slab into the slab lists
* when the slab is no longer needed.
*
* One use of this flag is to mark slabs that are
* used for allocations. Then such a slab becomes a cpu
* slab. The cpu slab may be equipped with an additional
* freelist that allows lockless access to
* free objects in addition to the regular freelist
* that requires the slab lock.
*
* PageError Slab requires special handling due to debug
* options set. This moves slab handling out of
* the fast path and disables lockless freelists.
*/
extern int boot_mode_security;
static inline int kmem_cache_debug(struct kmem_cache *s)
{
#ifdef CONFIG_SLUB_DEBUG
return unlikely(s->flags & SLAB_DEBUG_FLAGS);
#else
return 0;
#endif
}
#ifdef CONFIG_TIMA_RKP_RO_CRED
void v7_flush_kern_dcache_area(void *addr, size_t size);
spinlock_t ro_pages_lock = __SPIN_LOCK_UNLOCKED();
/* Array for tracking whether a given page is allocatedk*/
/* First Page is allocated for init_credential */
char ro_pages_stat[1 << RO_PAGES_ORDER] = { 1 };
/* Test Code: To be removed*/
/* Lets calculate whether we consume more than 1MB */
void rkp_calc_max_threshold(void)
{
unsigned int i,sum = 0;
for(i = 0;i < (1 << RO_PAGES_ORDER);i++) {
sum = sum + ro_pages_stat[i];
}
if(sum > 256 )
panic(" Consuming more than 1M ");
}
/* Main Routine for allocating Read-Only Cred Pages*/
struct page *alloc_ro_pages(int order)
{
struct page *page = NULL;
unsigned long flags;
int i = 0, j = 0;
spin_lock_irqsave(&ro_pages_lock,flags);
for (i = 0; i <= (1 << RO_PAGES_ORDER) - (1 << order); i++) {
for (j = 0; j < (1 << order); j++)
if (ro_pages_stat[i + j])
break;
if (j == (1 << order))
break; /* Allocation successful. */
}
if (i != (1 << RO_PAGES_ORDER) - (1 << order) + 1) {
/* Allocation successful. */
for (j = 0; j < (1 << order); j++)
ro_pages_stat[i + j] = 1;
printk(KERN_ERR"RKP RO CRED ALLOC -> order %x, %lx\n", order, ((unsigned long) __rkp_ro_start) + (i << 12));
page = virt_to_page(((unsigned long) __rkp_ro_start) + (i << 12));
// Test Code to be removed
rkp_calc_max_threshold();
}
else {
panic(KERN_ERR"TIMA-RKP: RO cred alloc failed order %x - i %x - j %x\n", order, i, j);
}
spin_unlock_irqrestore(&ro_pages_lock,flags);
return page;
}
/* Main Routine for freeing Read-Only Cred Pages*/
void free_ro_pages(struct page *page, int order)
{
int i, j;
unsigned long flags;
spin_lock_irqsave(&ro_pages_lock,flags);
i = (page_to_phys(page) - __pa((unsigned long) __rkp_ro_start)) >> 12;
printk(KERN_ERR"RKP RO CRED FREE-> order %x address %p\n", order, __va(page_to_phys(page)));
for (j = 0; j < (1 << order); j++)
ro_pages_stat[i + j] = 0;
spin_unlock_irqrestore(&ro_pages_lock,flags);
}
#endif /* CONFIG_TIMA_RKP_RO_CRED */
/*
* Issues still to be resolved:
*
* - Support PAGE_ALLOC_DEBUG. Should be easy to do.
*
* - Variable sizing of the per node arrays
*/
/* Enable to test recovery from slab corruption on boot */
#undef SLUB_RESILIENCY_TEST
/* Enable to log cmpxchg failures */
#undef SLUB_DEBUG_CMPXCHG
/*
* Mininum number of partial slabs. These will be left on the partial
* lists even if they are empty. kmem_cache_shrink may reclaim them.
*/
#define MIN_PARTIAL 5
/*
* Maximum number of desirable partial slabs.
* The existence of more partial slabs makes kmem_cache_shrink
* sort the partial list by the number of objects in the.
*/
#define MAX_PARTIAL 10
#define DEBUG_DEFAULT_FLAGS (SLAB_DEBUG_FREE | SLAB_RED_ZONE | \
SLAB_POISON | SLAB_STORE_USER)
/*
* Debugging flags that require metadata to be stored in the slab. These get
* disabled when slub_debug=O is used and a cache's min order increases with
* metadata.
*/
#define DEBUG_METADATA_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
/*
* Set of flags that will prevent slab merging
*/
#define SLUB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \
SLAB_TRACE | SLAB_DESTROY_BY_RCU | SLAB_NOLEAKTRACE | \
SLAB_FAILSLAB)
#define SLUB_MERGE_SAME (SLAB_DEBUG_FREE | SLAB_RECLAIM_ACCOUNT | \
SLAB_CACHE_DMA | SLAB_NOTRACK)
#define OO_SHIFT 16
#define OO_MASK ((1 << OO_SHIFT) - 1)
#define MAX_OBJS_PER_PAGE 32767 /* since page.objects is u15 */
/* Internal SLUB flags */
#define __OBJECT_POISON 0x80000000UL /* Poison object */
#define __CMPXCHG_DOUBLE 0x40000000UL /* Use cmpxchg_double */
#ifdef CONFIG_SMP
static struct notifier_block slab_notifier;
#endif
/*
* Tracking user of a slab.
*/
#define TRACK_ADDRS_COUNT 16
struct track {
unsigned long addr; /* Called from address */
#ifdef CONFIG_STACKTRACE
unsigned long addrs[TRACK_ADDRS_COUNT]; /* Called from address */
#endif
int cpu; /* Was running on cpu */
int pid; /* Pid context */
unsigned long when; /* When did the operation occur */
};
enum track_item { TRACK_ALLOC, TRACK_FREE };
#ifdef CONFIG_SYSFS
static int sysfs_slab_add(struct kmem_cache *);
static int sysfs_slab_alias(struct kmem_cache *, const char *);
static void sysfs_slab_remove(struct kmem_cache *);
static void memcg_propagate_slab_attrs(struct kmem_cache *s);
#else
static inline int sysfs_slab_add(struct kmem_cache *s) { return 0; }
static inline int sysfs_slab_alias(struct kmem_cache *s, const char *p)
{ return 0; }
static inline void sysfs_slab_remove(struct kmem_cache *s) { }
static inline void memcg_propagate_slab_attrs(struct kmem_cache *s) { }
#endif
static inline void stat(const struct kmem_cache *s, enum stat_item si)
{
#ifdef CONFIG_SLUB_STATS
__this_cpu_inc(s->cpu_slab->stat[si]);
#endif
}
/********************************************************************
* Core slab cache functions
*******************************************************************/
static inline struct kmem_cache_node *get_node(struct kmem_cache *s, int node)
{
return s->node[node];
}
/* Verify that a pointer has an address that is valid within a slab page */
static inline int check_valid_pointer(struct kmem_cache *s,
struct page *page, const void *object)
{
void *base;
if (!object)
return 1;
base = page_address(page);
if (object < base || object >= base + page->objects * s->size ||
(object - base) % s->size) {
return 0;
}
return 1;
}
static inline void *get_freepointer(struct kmem_cache *s, void *object)
{
return *(void **)(object + s->offset);
}
static void prefetch_freepointer(const struct kmem_cache *s, void *object)
{
prefetch(object + s->offset);
}
static inline void *get_freepointer_safe(struct kmem_cache *s, void *object)
{
void *p;
#ifdef CONFIG_DEBUG_PAGEALLOC
probe_kernel_read(&p, (void **)(object + s->offset), sizeof(p));
#else
p = get_freepointer(s, object);
#endif
return p;
}
static void set_freepointer(struct kmem_cache *s, void *object, void *fp)
{
#ifdef CONFIG_TIMA_RKP_RO_CRED
if (rkp_cred_enable && s->name && !strcmp(s->name, "cred_jar_ro")) {
//#ifndef CONFIG_TIMA_RKP_COHERENT_TT
tima_cache_flush(((unsigned long) object) + ((unsigned long) s->offset));
//#endif
tima_send_cmd3((unsigned long) object, (unsigned long) s->offset,
(unsigned long) fp, 0x44);
}
else
#endif /*CONFIG_TIMA_RKP_RO_CRED*/
*(void **)(object + s->offset) = fp;
}
/* Loop over all objects in a slab */
#define for_each_object(__p, __s, __addr, __objects) \
for (__p = (__addr); __p < (__addr) + (__objects) * (__s)->size;\
__p += (__s)->size)
/* Determine object index from a given position */
static inline int slab_index(void *p, struct kmem_cache *s, void *addr)
{
return (p - addr) / s->size;
}
static inline size_t slab_ksize(const struct kmem_cache *s)
{
#ifdef CONFIG_SLUB_DEBUG
/*
* Debugging requires use of the padding between object
* and whatever may come after it.
*/
if (s->flags & (SLAB_RED_ZONE | SLAB_POISON))
return s->object_size;
#endif
/*
* If we have the need to store the freelist pointer
* back there or track user information then we can
* only use the space before that information.
*/
if (s->flags & (SLAB_DESTROY_BY_RCU | SLAB_STORE_USER))
return s->inuse;
/*
* Else we can use all the padding etc for the allocation
*/
return s->size;
}
static inline int order_objects(int order, unsigned long size, int reserved)
{
return ((PAGE_SIZE << order) - reserved) / size;
}
static inline struct kmem_cache_order_objects oo_make(int order,
unsigned long size, int reserved)
{
struct kmem_cache_order_objects x = {
(order << OO_SHIFT) + order_objects(order, size, reserved)
};
return x;
}
static inline int oo_order(struct kmem_cache_order_objects x)
{
return x.x >> OO_SHIFT;
}
static inline int oo_objects(struct kmem_cache_order_objects x)
{
return x.x & OO_MASK;
}
/*
* Per slab locking using the pagelock
*/
static __always_inline void slab_lock(struct page *page)
{
bit_spin_lock(PG_locked, &page->flags);
}
static __always_inline void slab_unlock(struct page *page)
{
__bit_spin_unlock(PG_locked, &page->flags);
}
/* Interrupts must be disabled (for the fallback code to work right) */
static inline bool __cmpxchg_double_slab(struct kmem_cache *s, struct page *page,
void *freelist_old, unsigned long counters_old,
void *freelist_new, unsigned long counters_new,
const char *n)
{
VM_BUG_ON(!irqs_disabled());
#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
if (s->flags & __CMPXCHG_DOUBLE) {
if (cmpxchg_double(&page->freelist, &page->counters,
freelist_old, counters_old,
freelist_new, counters_new))
return 1;
} else
#endif
{
slab_lock(page);
if (page->freelist == freelist_old && page->counters == counters_old) {
page->freelist = freelist_new;
page->counters = counters_new;
slab_unlock(page);
return 1;
}
slab_unlock(page);
}
cpu_relax();
stat(s, CMPXCHG_DOUBLE_FAIL);
#ifdef SLUB_DEBUG_CMPXCHG
printk(KERN_INFO "%s %s: cmpxchg double redo ", n, s->name);
#endif
return 0;
}
static inline bool cmpxchg_double_slab(struct kmem_cache *s, struct page *page,
void *freelist_old, unsigned long counters_old,
void *freelist_new, unsigned long counters_new,
const char *n)
{
#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
if (s->flags & __CMPXCHG_DOUBLE) {
if (cmpxchg_double(&page->freelist, &page->counters,
freelist_old, counters_old,
freelist_new, counters_new))
return 1;
} else
#endif
{
unsigned long flags;
local_irq_save(flags);
slab_lock(page);
if (page->freelist == freelist_old && page->counters == counters_old) {
page->freelist = freelist_new;
page->counters = counters_new;
slab_unlock(page);
local_irq_restore(flags);
return 1;
}
slab_unlock(page);
local_irq_restore(flags);
}
cpu_relax();
stat(s, CMPXCHG_DOUBLE_FAIL);
#ifdef SLUB_DEBUG_CMPXCHG
printk(KERN_INFO "%s %s: cmpxchg double redo ", n, s->name);
#endif
return 0;
}
#ifdef CONFIG_SLUB_DEBUG
/*
* Determine a map of object in use on a page.
*
* Node listlock must be held to guarantee that the page does
* not vanish from under us.
*/
static void get_map(struct kmem_cache *s, struct page *page, unsigned long *map)
{
void *p;
void *addr = page_address(page);
check_cred_cache(s, );
for (p = page->freelist; p; p = get_freepointer(s, p))
set_bit(slab_index(p, s, addr), map);
}
/*
* Debug settings:
*/
#ifdef CONFIG_SLUB_DEBUG_ON
static int slub_debug = DEBUG_DEFAULT_FLAGS;
#else
static int slub_debug;
#endif
static char *slub_debug_slabs;
static int disable_higher_order_debug;
/*
* Object debugging
*/
static void print_section(char *text, u8 *addr, unsigned int length)
{
print_hex_dump(KERN_ERR, text, DUMP_PREFIX_ADDRESS, 16, 1, addr,
length, 1);
}
static struct track *get_track(struct kmem_cache *s, void *object,
enum track_item alloc)
{
struct track *p;
if (s->offset)
p = object + s->offset + sizeof(void *);
else
p = object + s->inuse;
return p + alloc;
}
static void set_track(struct kmem_cache *s, void *object,
enum track_item alloc, unsigned long addr)
{
struct track *p = get_track(s, object, alloc);
check_cred_cache(s, );
if (addr) {
#ifdef CONFIG_STACKTRACE
struct stack_trace trace;
int i;
trace.nr_entries = 0;
trace.max_entries = TRACK_ADDRS_COUNT;
trace.entries = p->addrs;
trace.skip = 3;
save_stack_trace(&trace);
/* See rant in lockdep.c */
if (trace.nr_entries != 0 &&
trace.entries[trace.nr_entries - 1] == ULONG_MAX)
trace.nr_entries--;
for (i = trace.nr_entries; i < TRACK_ADDRS_COUNT; i++)
p->addrs[i] = 0;
#endif
p->addr = addr;
p->cpu = smp_processor_id();
p->pid = current->pid;
p->when = jiffies;
} else
memset(p, 0, sizeof(struct track));
}
static void init_tracking(struct kmem_cache *s, void *object)
{
if (!(s->flags & SLAB_STORE_USER))
return;
set_track(s, object, TRACK_FREE, 0UL);
set_track(s, object, TRACK_ALLOC, 0UL);
}
static void print_track(const char *s, struct track *t)
{
if (!t->addr)
return;
printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
#ifdef CONFIG_STACKTRACE
{
int i;
for (i = 0; i < TRACK_ADDRS_COUNT; i++)
if (t->addrs[i])
printk(KERN_ERR "\t%pS\n", (void *)t->addrs[i]);
else
break;
}
#endif
}
static void print_tracking(struct kmem_cache *s, void *object)
{
if (!(s->flags & SLAB_STORE_USER))
return;
print_track("Allocated", get_track(s, object, TRACK_ALLOC));
print_track("Freed", get_track(s, object, TRACK_FREE));
}
static void print_page_info(struct page *page)
{
printk(KERN_ERR "INFO: Slab 0x%p objects=%u used=%u fp=0x%p flags=0x%04lx\n",
page, page->objects, page->inuse, page->freelist, page->flags);
}
static void slab_bug(struct kmem_cache *s, char *fmt, ...)
{
va_list args;
char buf[100];
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
printk(KERN_ERR "========================================"
"=====================================\n");
printk(KERN_ERR "BUG %s (%s): %s\n", s->name, print_tainted(), buf);
printk(KERN_ERR "----------------------------------------"
"-------------------------------------\n\n");
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
}
static void slab_fix(struct kmem_cache *s, char *fmt, ...)
{
va_list args;
char buf[100];
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
printk(KERN_ERR "FIX %s: %s\n", s->name, buf);
}
static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)
{
unsigned int off; /* Offset of last byte */
u8 *addr = page_address(page);
print_tracking(s, p);
print_page_info(page);
printk(KERN_ERR "INFO: Object 0x%p @offset=%tu fp=0x%p\n\n",
p, p - addr, get_freepointer(s, p));
if (p > addr + 16)
print_section("Bytes b4 ", p - 16, 16);
print_section("Object ", p, min_t(unsigned long, s->object_size,
PAGE_SIZE));
if (s->flags & SLAB_RED_ZONE)
print_section("Redzone ", p + s->object_size,
s->inuse - s->object_size);
if (s->offset)
off = s->offset + sizeof(void *);
else
off = s->inuse;
if (s->flags & SLAB_STORE_USER)
off += 2 * sizeof(struct track);
if (off != s->size)
/* Beginning of the filler is the free pointer */
print_section("Padding ", p + off, s->size - off);
dump_stack();
}
static void object_err(struct kmem_cache *s, struct page *page,
u8 *object, char *reason)
{
slab_bug(s, "%s", reason);
print_trailer(s, page, object);
if (slub_debug)
panic("SLUB ERROR: object_err");
}
static void slab_err(struct kmem_cache *s, struct page *page, const char *fmt, ...)
{
va_list args;
char buf[100];
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
slab_bug(s, "%s", buf);
print_page_info(page);
dump_stack();
if (slub_debug)
panic("SLUB ERROR: slab_err");
}
static void slab_err_nopanic(struct kmem_cache *s, struct page *page, const char *fmt, ...)
{
va_list args;
char buf[100];
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
slab_bug(s, "%s", buf);
print_page_info(page);
dump_stack();
}
static void init_object(struct kmem_cache *s, void *object, u8 val)
{
u8 *p = object;
check_cred_cache(s, );
if (s->flags & __OBJECT_POISON) {
memset(p, POISON_FREE, s->object_size - 1);
p[s->object_size - 1] = POISON_END;
}
if (s->flags & SLAB_RED_ZONE)
memset(p + s->object_size, val, s->inuse - s->object_size);
}
static void restore_bytes(struct kmem_cache *s, char *message, u8 data,
void *from, void *to)
{
slab_fix(s, "Restoring 0x%p-0x%p=0x%x\n", from, to - 1, data);
memset(from, data, to - from);
}
static int check_bytes_and_report(struct kmem_cache *s, struct page *page,
u8 *object, char *what,
u8 *start, unsigned int value, unsigned int bytes)
{
u8 *fault;
u8 *end;
check_cred_cache(s,1);
fault = memchr_inv(start, value, bytes);
if (!fault)
return 1;
end = start + bytes;
while (end > fault && end[-1] == value)
end--;
slab_bug(s, "%s overwritten", what);
printk(KERN_ERR "INFO: 0x%p-0x%p. First byte 0x%x instead of 0x%x\n",
fault, end - 1, fault[0], value);
print_trailer(s, page, object);
if (slub_debug)
panic("SLUB ERROR: check_bytes_and_report. Can it be restored?");
restore_bytes(s, what, value, fault, end);
return 0;
}
/*
* Object layout:
*
* object address
* Bytes of the object to be managed.
* If the freepointer may overlay the object then the free
* pointer is the first word of the object.
*
* Poisoning uses 0x6b (POISON_FREE) and the last byte is
* 0xa5 (POISON_END)
*
* object + s->object_size
* Padding to reach word boundary. This is also used for Redzoning.
* Padding is extended by another word if Redzoning is enabled and
* object_size == inuse.
*
* We fill with 0xbb (RED_INACTIVE) for inactive objects and with
* 0xcc (RED_ACTIVE) for objects in use.
*
* object + s->inuse
* Meta data starts here.
*
* A. Free pointer (if we cannot overwrite object on free)
* B. Tracking data for SLAB_STORE_USER
* C. Padding to reach required alignment boundary or at mininum
* one word if debugging is on to be able to detect writes
* before the word boundary.
*
* Padding is done using 0x5a (POISON_INUSE)
*
* object + s->size
* Nothing is used beyond s->size.
*
* If slabcaches are merged then the object_size and inuse boundaries are mostly
* ignored. And therefore no slab options that rely on these boundaries
* may be used with merged slabcaches.
*/
static int check_pad_bytes(struct kmem_cache *s, struct page *page, u8 *p)
{
unsigned long off = s->inuse; /* The end of info */
if (s->offset)
/* Freepointer is placed after the object. */
off += sizeof(void *);
if (s->flags & SLAB_STORE_USER)
/* We also have user information there */
off += 2 * sizeof(struct track);
if (s->size == off)
return 1;
return check_bytes_and_report(s, page, p, "Object padding",
p + off, POISON_INUSE, s->size - off);
}
/* Check the pad bytes at the end of a slab page */
static int slab_pad_check(struct kmem_cache *s, struct page *page)
{
u8 *start;
u8 *fault;
u8 *end;
int length;
int remainder;
if (!(s->flags & SLAB_POISON))
return 1;
check_cred_cache(s,1);
start = page_address(page);
length = (PAGE_SIZE << compound_order(page)) - s->reserved;
end = start + length;
remainder = length % s->size;
if (!remainder)
return 1;
fault = memchr_inv(end - remainder, POISON_INUSE, remainder);
if (!fault)
return 1;
while (end > fault && end[-1] == POISON_INUSE)
end--;
slab_err_nopanic(s, page, "Padding overwritten. 0x%p-0x%p", fault, end - 1);
print_section("Padding ", end - remainder, remainder);
if (slub_debug)
panic("SLUB ERROR: slab_pad_check. Can it be restored?");
restore_bytes(s, "slab padding", POISON_INUSE, end - remainder, end);
return 0;
}
static int check_object(struct kmem_cache *s, struct page *page,
void *object, u8 val)
{
u8 *p = object;
u8 *endobject = object + s->object_size;
if (s->flags & SLAB_RED_ZONE) {
if (!check_bytes_and_report(s, page, object, "Redzone",
endobject, val, s->inuse - s->object_size))
return 0;
} else {
if ((s->flags & SLAB_POISON) && s->object_size < s->inuse) {
check_bytes_and_report(s, page, p, "Alignment padding",
endobject, POISON_INUSE, s->inuse - s->object_size);
}
}
if (s->flags & SLAB_POISON) {
if (val != SLUB_RED_ACTIVE && (s->flags & __OBJECT_POISON) &&
(!check_bytes_and_report(s, page, p, "Poison", p,
POISON_FREE, s->object_size - 1) ||
!check_bytes_and_report(s, page, p, "Poison",
p + s->object_size - 1, POISON_END, 1)))
return 0;
/*
* check_pad_bytes cleans up on its own.
*/
check_pad_bytes(s, page, p);
}
if (!s->offset && val == SLUB_RED_ACTIVE)
/*
* Object and freepointer overlap. Cannot check
* freepointer while object is allocated.
*/
return 1;
/* Check free pointer validity */
if (!check_valid_pointer(s, page, get_freepointer(s, p))) {
object_err(s, page, p, "Freepointer corrupt");
/*
* No choice but to zap it and thus lose the remainder
* of the free objects in this slab. May cause
* another error because the object count is now wrong.
*/
set_freepointer(s, p, NULL);
return 0;
}
return 1;
}
static int check_slab(struct kmem_cache *s, struct page *page)
{
int maxobj;
VM_BUG_ON(!irqs_disabled());
if (!PageSlab(page)) {
slab_err(s, page, "Not a valid slab page");
return 0;
}
#ifdef CONFIG_TIMA_RKP_RO_CRED
/*
* Skip this function for now
*/
if (s->name && !strcmp(s->name, "cred_jar_ro"))
return 1;
#endif /*CONFIG_TIMA_RKP_RO_CRED*/
maxobj = order_objects(compound_order(page), s->size, s->reserved);
if (page->objects > maxobj) {
slab_err(s, page, "objects %u > max %u",
s->name, page->objects, maxobj);
return 0;
}
if (page->inuse > page->objects) {
slab_err(s, page, "inuse %u > max %u",
s->name, page->inuse, page->objects);
return 0;
}
/* Slab_pad_check fixes things up after itself */
slab_pad_check(s, page);
return 1;
}
/*
* Determine if a certain object on a page is on the freelist. Must hold the
* slab lock to guarantee that the chains are in a consistent state.
*/
static int on_freelist(struct kmem_cache *s, struct page *page, void *search)
{
int nr = 0;
void *fp;
void *object = NULL;
unsigned long max_objects;
fp = page->freelist;
check_cred_cache(s,0);
while (fp && nr <= page->objects) {
if (fp == search)
return 1;
if (!check_valid_pointer(s, page, fp)) {
if (object) {
object_err(s, page, object,
"Freechain corrupt");
set_freepointer(s, object, NULL);
break;
} else {
slab_err(s, page, "Freepointer corrupt");
page->freelist = NULL;
page->inuse = page->objects;
slab_fix(s, "Freelist cleared");
return 0;
}
break;
}
object = fp;
fp = get_freepointer(s, object);
nr++;
}
max_objects = order_objects(compound_order(page), s->size, s->reserved);
if (max_objects > MAX_OBJS_PER_PAGE)
max_objects = MAX_OBJS_PER_PAGE;
if (page->objects != max_objects) {
slab_err(s, page, "Wrong number of objects. Found %d but "
"should be %d", page->objects, max_objects);
page->objects = max_objects;
slab_fix(s, "Number of objects adjusted.");
}
if (page->inuse != page->objects - nr) {
slab_err(s, page, "Wrong object count. Counter is %d but "
"counted were %d", page->inuse, page->objects - nr);
page->inuse = page->objects - nr;
slab_fix(s, "Object count adjusted.");
}
return search == NULL;
}
static void trace(struct kmem_cache *s, struct page *page, void *object,
int alloc)
{
if (s->flags & SLAB_TRACE) {
printk(KERN_INFO "TRACE %s %s 0x%p inuse=%d fp=0x%p\n",
s->name,
alloc ? "alloc" : "free",
object, page->inuse,
page->freelist);
if (!alloc)
print_section("Object ", (void *)object, s->object_size);
dump_stack();
}
}
/*
* Hooks for other subsystems that check memory allocations. In a typical
* production configuration these hooks all should produce no code at all.
*/
static inline int slab_pre_alloc_hook(struct kmem_cache *s, gfp_t flags)
{
flags &= gfp_allowed_mask;
lockdep_trace_alloc(flags);
might_sleep_if(flags & __GFP_WAIT);
return should_failslab(s->object_size, flags, s->flags);
}
static inline void slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags, void *object)
{
flags &= gfp_allowed_mask;
kmemcheck_slab_alloc(s, flags, object, slab_ksize(s));
kmemleak_alloc_recursive(object, s->object_size, 1, s->flags, flags);
}
static inline void slab_free_hook(struct kmem_cache *s, void *x)
{
kmemleak_free_recursive(x, s->flags);
/*
* Trouble is that we may no longer disable interupts in the fast path
* So in order to make the debug calls that expect irqs to be
* disabled we need to disable interrupts temporarily.
*/
#if defined(CONFIG_KMEMCHECK) || defined(CONFIG_LOCKDEP)
{
unsigned long flags;
local_irq_save(flags);
kmemcheck_slab_free(s, x, s->object_size);
debug_check_no_locks_freed(x, s->object_size);
local_irq_restore(flags);
}
#endif
if (!(s->flags & SLAB_DEBUG_OBJECTS))
debug_check_no_obj_freed(x, s->object_size);
}
/*
* Tracking of fully allocated slabs for debugging purposes.
*
* list_lock must be held.
*/
static void add_full(struct kmem_cache *s,
struct kmem_cache_node *n, struct page *page)
{
check_cred_cache(s, );
if (!(s->flags & SLAB_STORE_USER))
return;
list_add(&page->lru, &n->full);
}
/*
* list_lock must be held.
*/
static void remove_full(struct kmem_cache *s, struct page *page)
{
check_cred_cache(s, );
if (!(s->flags & SLAB_STORE_USER))
return;
list_del(&page->lru);
}
/* Tracking of the number of slabs for debugging purposes */
static inline unsigned long slabs_node(struct kmem_cache *s, int node)
{
struct kmem_cache_node *n = get_node(s, node);
return atomic_long_read(&n->nr_slabs);
}
static inline unsigned long node_nr_slabs(struct kmem_cache_node *n)
{
return atomic_long_read(&n->nr_slabs);
}
static inline void inc_slabs_node(struct kmem_cache *s, int node, int objects)
{
struct kmem_cache_node *n = get_node(s, node);
/*
* May be called early in order to allocate a slab for the
* kmem_cache_node structure. Solve the chicken-egg
* dilemma by deferring the increment of the count during
* bootstrap (see early_kmem_cache_node_alloc).
*/
if (likely(n)) {
atomic_long_inc(&n->nr_slabs);
atomic_long_add(objects, &n->total_objects);
}
}
static inline void dec_slabs_node(struct kmem_cache *s, int node, int objects)
{
struct kmem_cache_node *n = get_node(s, node);
atomic_long_dec(&n->nr_slabs);
atomic_long_sub(objects, &n->total_objects);
}
/* Object debug checks for alloc/free paths */
static void setup_object_debug(struct kmem_cache *s, struct page *page,
void *object)
{
if (!(s->flags & (SLAB_STORE_USER|SLAB_RED_ZONE|__OBJECT_POISON)))
return;
init_object(s, object, SLUB_RED_INACTIVE);
init_tracking(s, object);
}
static noinline int alloc_debug_processing(struct kmem_cache *s, struct page *page,
void *object, unsigned long addr)
{
check_cred_cache(s,0);
if (!check_slab(s, page))
goto bad;
if (!check_valid_pointer(s, page, object)) {
object_err(s, page, object, "Freelist Pointer check fails");
goto bad;
}
if (!check_object(s, page, object, SLUB_RED_INACTIVE))
goto bad;
/* Success perform special debug activities for allocs */
if (s->flags & SLAB_STORE_USER)
set_track(s, object, TRACK_ALLOC, addr);
trace(s, page, object, 1);
init_object(s, object, SLUB_RED_ACTIVE);
return 1;
bad:
if (PageSlab(page)) {
/*
* If this is a slab page then lets do the best we can
* to avoid issues in the future. Marking all objects
* as used avoids touching the remaining objects.
*/
slab_fix(s, "Marking all objects used");
page->inuse = page->objects;
page->freelist = NULL;
}
return 0;
}
static noinline struct kmem_cache_node *free_debug_processing(
struct kmem_cache *s, struct page *page, void *object,
unsigned long addr, unsigned long *flags)
{
struct kmem_cache_node *n = get_node(s, page_to_nid(page));
check_cred_cache(s,NULL);
spin_lock_irqsave(&n->list_lock, *flags);
slab_lock(page);
if (!check_slab(s, page))
goto fail;
if (!check_valid_pointer(s, page, object)) {
slab_err(s, page, "Invalid object pointer 0x%p", object);
goto fail;
}
if (on_freelist(s, page, object)) {
object_err(s, page, object, "Object already free");
goto fail;
}
if (!check_object(s, page, object, SLUB_RED_ACTIVE))
goto out;
if (unlikely(s != page->slab_cache)) {
if (!PageSlab(page)) {
slab_err(s, page, "Attempt to free object(0x%p) "
"outside of slab", object);
} else if (!page->slab_cache) {
printk(KERN_ERR
"SLUB <none>: no slab for object 0x%p.\n",
object);
dump_stack();
} else
object_err(s, page, object,
"page slab pointer corrupt.");
goto fail;
}
if (s->flags & SLAB_STORE_USER)
set_track(s, object, TRACK_FREE, addr);
trace(s, page, object, 0);
init_object(s, object, SLUB_RED_INACTIVE);
out:
slab_unlock(page);
/*
* Keep node_lock to preserve integrity
* until the object is actually freed
*/
return n;
fail:
slab_unlock(page);
spin_unlock_irqrestore(&n->list_lock, *flags);
slab_fix(s, "Object at 0x%p not freed", object);
return NULL;
}
static int __init setup_slub_debug(char *str)
{
slub_debug = DEBUG_DEFAULT_FLAGS;
if (*str++ != '=' || !*str)
/*
* No options specified. Switch on full debugging.
*/
goto out;
if (*str == ',')
/*
* No options but restriction on slabs. This means full
* debugging for slabs matching a pattern.
*/
goto check_slabs;
if (tolower(*str) == 'o') {
/*
* Avoid enabling debugging on caches if its minimum order
* would increase as a result.
*/
disable_higher_order_debug = 1;
goto out;
}
slub_debug = 0;
if (*str == '-')
/*
* Switch off all debugging measures.
*/
goto out;
/*
* Determine which debug features should be switched on
*/
for (; *str && *str != ','; str++) {
switch (tolower(*str)) {
case 'f':
slub_debug |= SLAB_DEBUG_FREE;
break;
case 'z':
slub_debug |= SLAB_RED_ZONE;
break;
case 'p':
slub_debug |= SLAB_POISON;
break;
case 'u':
slub_debug |= SLAB_STORE_USER;
break;
case 't':
slub_debug |= SLAB_TRACE;
break;
case 'a':
slub_debug |= SLAB_FAILSLAB;
break;
default:
printk(KERN_ERR "slub_debug option '%c' "
"unknown. skipped\n", *str);
}
}
check_slabs:
if (*str == ',')
slub_debug_slabs = str + 1;
out:
return 1;
}
__setup("slub_debug", setup_slub_debug);
static unsigned long kmem_cache_flags(unsigned long object_size,
unsigned long flags, const char *name,
void (*ctor)(void *))
{
/*
* Enable debugging if selected on the kernel commandline.
*/
#ifdef CONFIG_TIMA_RKP_RO_CRED
return flags;
#else
if (slub_debug && (!slub_debug_slabs || (name &&
!strncmp(slub_debug_slabs, name, strlen(slub_debug_slabs)))))
flags |= slub_debug;
return flags;
#endif
}
#else
static inline void setup_object_debug(struct kmem_cache *s,
struct page *page, void *object) {}
static inline int alloc_debug_processing(struct kmem_cache *s,
struct page *page, void *object, unsigned long addr) { return 0; }
static inline struct kmem_cache_node *free_debug_processing(
struct kmem_cache *s, struct page *page, void *object,
unsigned long addr, unsigned long *flags) { return NULL; }
static inline int slab_pad_check(struct kmem_cache *s, struct page *page)
{ return 1; }
static inline int check_object(struct kmem_cache *s, struct page *page,
void *object, u8 val) { return 1; }
static inline void add_full(struct kmem_cache *s, struct kmem_cache_node *n,
struct page *page) {}
static inline void remove_full(struct kmem_cache *s, struct page *page) {}
static inline unsigned long kmem_cache_flags(unsigned long object_size,
unsigned long flags, const char *name,
void (*ctor)(void *))
{
return flags;
}
#define slub_debug 0
#define disable_higher_order_debug 0
static inline unsigned long slabs_node(struct kmem_cache *s, int node)
{ return 0; }
static inline unsigned long node_nr_slabs(struct kmem_cache_node *n)
{ return 0; }
static inline void inc_slabs_node(struct kmem_cache *s, int node,
int objects) {}
static inline void dec_slabs_node(struct kmem_cache *s, int node,
int objects) {}
static inline int slab_pre_alloc_hook(struct kmem_cache *s, gfp_t flags)
{ return 0; }
static inline void slab_post_alloc_hook(struct kmem_cache *s, gfp_t flags,
void *object) {}
static inline void slab_free_hook(struct kmem_cache *s, void *x) {}
#endif /* CONFIG_SLUB_DEBUG */
/*
* Slab allocation and freeing
*/
static inline struct page *alloc_slab_page(gfp_t flags, int node,
struct kmem_cache_order_objects oo)
{
int order = oo_order(oo);
flags |= __GFP_NOTRACK;
if (node == NUMA_NO_NODE)
return alloc_pages(flags, order);
else
return alloc_pages_exact_node(node, flags, order);
}
static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
{
struct page *page;
struct kmem_cache_order_objects oo = s->oo;
gfp_t alloc_gfp;
flags &= gfp_allowed_mask;
if (flags & __GFP_WAIT)
local_irq_enable();
flags |= s->allocflags;
/*
* Let the initial higher-order allocation fail under memory pressure
* so we fall-back to the minimum order allocation.
*/
alloc_gfp = (flags | __GFP_NOWARN | __GFP_NORETRY) & ~__GFP_NOFAIL;
#ifdef CONFIG_TIMA_RKP_RO_CRED
/*
* We modify the following so that slab alloc for protected data
* types are allocated from our own pool.
*/
if (s->name && !strcmp(s->name, "cred_jar_ro")) {
page = alloc_ro_pages(oo_order(oo));
} else {
#endif
page = alloc_slab_page(alloc_gfp, node, oo);
if (unlikely(!page)) {
oo = s->min;
/*
* Allocation may have failed due to fragmentation.
* Try a lower order alloc if possible
*/
page = alloc_slab_page(flags, node, oo);
if (page)
stat(s, ORDER_FALLBACK);
}
#ifdef CONFIG_TIMA_RKP_RO_CRED
}
#endif
if (kmemcheck_enabled && page
&& !(s->flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS))) {
int pages = 1 << oo_order(oo);
kmemcheck_alloc_shadow(page, oo_order(oo), flags, node);
/*
* Objects from caches that have a constructor don't get
* cleared when they're allocated, so we need to do it here.
*/
if (s->ctor)
kmemcheck_mark_uninitialized_pages(page, pages);
else
kmemcheck_mark_unallocated_pages(page, pages);
}
if (flags & __GFP_WAIT)
local_irq_disable();
if (!page)
return NULL;
page->objects = oo_objects(oo);
mod_zone_page_state(page_zone(page),
(s->flags & SLAB_RECLAIM_ACCOUNT) ?
NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
1 << oo_order(oo));
return page;
}
static void setup_object(struct kmem_cache *s, struct page *page,
void *object)
{
setup_object_debug(s, page, object);
if (unlikely(s->ctor))
s->ctor(object);
}
extern int boot_mode_security;
static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
{
struct page *page;
void *start;
void *last;
void *p;
int order;
BUG_ON(flags & GFP_SLAB_BUG_MASK);
page = allocate_slab(s,
flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node);
if (!page)
goto out;
order = compound_order(page);
inc_slabs_node(s, page_to_nid(page), page->objects);
memcg_bind_pages(s, order);
page->slab_cache = s;
__SetPageSlab(page);
if (page->pfmemalloc)
SetPageSlabPfmemalloc(page);
start = page_address(page);
if (unlikely(s->flags & SLAB_POISON))
memset(start, POISON_INUSE, PAGE_SIZE << order);
last = start;
for_each_object(p, s, start, page->objects) {
setup_object(s, page, last);
set_freepointer(s, last, p);
last = p;
}
setup_object(s, page, last);
set_freepointer(s, last, NULL);
#ifdef CONFIG_RKP_DBLMAP_PROT
if (boot_mode_security){
tima_send_cmd5(page_to_phys(page), compound_order(page), 1, (unsigned long) __pa(rkp_double_bitmap), 0, 0x4a);
}
#endif
#ifdef TIMA_RKP_KDATA_PROT
if(rkp_cred_enable)
tima_send_cmd3(page_to_phys(page), compound_order(page), 1, 0x26);
#endif
page->freelist = start;
page->inuse = page->objects;
page->frozen = 1;
out:
return page;
}
static void __free_slab(struct kmem_cache *s, struct page *page)
{
int order = compound_order(page);
int pages = 1 << order;
#ifdef CONFIG_RKP_DBLMAP_PROT
if (boot_mode_security){
tima_send_cmd5(page_to_phys(page), compound_order(page), 0, (unsigned long) __pa(rkp_double_bitmap), 0, 0x4a);
}
#endif
if (kmem_cache_debug(s)) {
void *p;
slab_pad_check(s, page);
for_each_object(p, s, page_address(page),
page->objects)
check_object(s, page, p, SLUB_RED_INACTIVE);
}
kmemcheck_free_shadow(page, compound_order(page));
mod_zone_page_state(page_zone(page),
(s->flags & SLAB_RECLAIM_ACCOUNT) ?
NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
-pages);
__ClearPageSlabPfmemalloc(page);
__ClearPageSlab(page);
memcg_release_pages(s, order);
page_mapcount_reset(page);
if (current->reclaim_state)
current->reclaim_state->reclaimed_slab += pages;
#ifdef CONFIG_TIMA_RKP_RO_CRED
/* We free the protected pages here. */
if (s->name && !strcmp(s->name, "cred_jar_ro"))
free_ro_pages(page, order);
else
#endif
__free_memcg_kmem_pages(page, order);
}
#define need_reserve_slab_rcu \
(sizeof(((struct page *)NULL)->lru) < sizeof(struct rcu_head))
static void rcu_free_slab(struct rcu_head *h)
{
struct page *page;
if (need_reserve_slab_rcu)
page = virt_to_head_page(h);
else
page = container_of((struct list_head *)h, struct page, lru);
__free_slab(page->slab_cache, page);
}
static void free_slab(struct kmem_cache *s, struct page *page)
{
#ifdef TIMA_RKP_KDATA_PROT
if(rkp_cred_enable)
tima_send_cmd3(page_to_phys(page), compound_order(page), 0, 0x26);
#endif
if (unlikely(s->flags & SLAB_DESTROY_BY_RCU)) {
struct rcu_head *head;
if (need_reserve_slab_rcu) {
int order = compound_order(page);
int offset = (PAGE_SIZE << order) - s->reserved;
VM_BUG_ON(s->reserved != sizeof(*head));
head = page_address(page) + offset;
} else {
/*
* RCU free overloads the RCU head over the LRU
*/
head = (void *)&page->lru;
}
call_rcu(head, rcu_free_slab);
} else
__free_slab(s, page);
}
static void discard_slab(struct kmem_cache *s, struct page *page)
{
dec_slabs_node(s, page_to_nid(page), page->objects);
free_slab(s, page);
}
/*
* Management of partially allocated slabs.
*
* list_lock must be held.
*/
static inline void add_partial(struct kmem_cache_node *n,
struct page *page, int tail)
{
n->nr_partial++;
if (tail == DEACTIVATE_TO_TAIL)
list_add_tail(&page->lru, &n->partial);
else
list_add(&page->lru, &n->partial);
}
/*
* list_lock must be held.
*/
static inline void remove_partial(struct kmem_cache_node *n,
struct page *page)
{
list_del(&page->lru);
n->nr_partial--;
}
/*
* Remove slab from the partial list, freeze it and
* return the pointer to the freelist.
*
* Returns a list of objects or NULL if it fails.
*
* Must hold list_lock since we modify the partial list.
*/
static inline void *acquire_slab(struct kmem_cache *s,
struct kmem_cache_node *n, struct page *page,
int mode, int *objects)
{
void *freelist;
unsigned long counters;
struct page new;
/*
* Zap the freelist and set the frozen bit.
* The old freelist is the list of objects for the
* per cpu allocation list.
*/
freelist = page->freelist;
counters = page->counters;
new.counters = counters;
*objects = new.objects - new.inuse;
if (mode) {
new.inuse = page->objects;
new.freelist = NULL;
} else {
new.freelist = freelist;
}
VM_BUG_ON(new.frozen);
new.frozen = 1;
if (!__cmpxchg_double_slab(s, page,
freelist, counters,
new.freelist, new.counters,
"acquire_slab"))
return NULL;
remove_partial(n, page);
WARN_ON(!freelist);
return freelist;
}
static void put_cpu_partial(struct kmem_cache *s, struct page *page, int drain);
static inline bool pfmemalloc_match(struct page *page, gfp_t gfpflags);
/*
* Try to allocate a partial slab from a specific node.
*/
static void *get_partial_node(struct kmem_cache *s, struct kmem_cache_node *n,
struct kmem_cache_cpu *c, gfp_t flags)
{
struct page *page, *page2;
void *object = NULL;
int available = 0;
int objects;
/*
* Racy check. If we mistakenly see no partial slabs then we
* just allocate an empty slab. If we mistakenly try to get a
* partial slab and there is none available then get_partials()
* will return NULL.
*/
if (!n || !n->nr_partial)
return NULL;
spin_lock(&n->list_lock);
list_for_each_entry_safe(page, page2, &n->partial, lru) {
void *t;
if (!pfmemalloc_match(page, flags))
continue;
t = acquire_slab(s, n, page, object == NULL, &objects);
if (!t)
break;
available += objects;
if (!object) {
c->page = page;
stat(s, ALLOC_FROM_PARTIAL);
object = t;
} else {
put_cpu_partial(s, page, 0);
stat(s, CPU_PARTIAL_NODE);
}
if (kmem_cache_debug(s) || available > s->cpu_partial / 2)
break;
}
spin_unlock(&n->list_lock);
return object;
}
/*
* Get a page from somewhere. Search in increasing NUMA distances.
*/
static void *get_any_partial(struct kmem_cache *s, gfp_t flags,
struct kmem_cache_cpu *c)
{
#ifdef CONFIG_NUMA
struct zonelist *zonelist;
struct zoneref *z;
struct zone *zone;
enum zone_type high_zoneidx = gfp_zone(flags);
void *object;
unsigned int cpuset_mems_cookie;
/*
* The defrag ratio allows a configuration of the tradeoffs between
* inter node defragmentation and node local allocations. A lower
* defrag_ratio increases the tendency to do local allocations
* instead of attempting to obtain partial slabs from other nodes.
*
* If the defrag_ratio is set to 0 then kmalloc() always
* returns node local objects. If the ratio is higher then kmalloc()
* may return off node objects because partial slabs are obtained
* from other nodes and filled up.
*
* If /sys/kernel/slab/xx/defrag_ratio is set to 100 (which makes
* defrag_ratio = 1000) then every (well almost) allocation will
* first attempt to defrag slab caches on other nodes. This means
* scanning over all nodes to look for partial slabs which may be
* expensive if we do it every time we are trying to find a slab
* with available objects.
*/
if (!s->remote_node_defrag_ratio ||
get_cycles() % 1024 > s->remote_node_defrag_ratio)
return NULL;
do {
cpuset_mems_cookie = get_mems_allowed();
zonelist = node_zonelist(slab_node(), flags);
for_each_zone_zonelist(zone, z, zonelist, high_zoneidx) {
struct kmem_cache_node *n;
n = get_node(s, zone_to_nid(zone));
if (n && cpuset_zone_allowed_hardwall(zone, flags) &&
n->nr_partial > s->min_partial) {
object = get_partial_node(s, n, c, flags);
if (object) {
/*
* Return the object even if
* put_mems_allowed indicated that
* the cpuset mems_allowed was
* updated in parallel. It's a
* harmless race between the alloc
* and the cpuset update.
*/
put_mems_allowed(cpuset_mems_cookie);
return object;
}
}
}
} while (!put_mems_allowed(cpuset_mems_cookie));
#endif
return NULL;
}
/*
* Get a partial page, lock it and return it.
*/
static void *get_partial(struct kmem_cache *s, gfp_t flags, int node,
struct kmem_cache_cpu *c)
{
void *object;
int searchnode = (node == NUMA_NO_NODE) ? numa_node_id() : node;
object = get_partial_node(s, get_node(s, searchnode), c, flags);
if (object || node != NUMA_NO_NODE)
return object;
return get_any_partial(s, flags, c);
}
#ifdef CONFIG_PREEMPT
/*
* Calculate the next globally unique transaction for disambiguiation
* during cmpxchg. The transactions start with the cpu number and are then
* incremented by CONFIG_NR_CPUS.
*/
#define TID_STEP roundup_pow_of_two(CONFIG_NR_CPUS)
#else
/*
* No preemption supported therefore also no need to check for
* different cpus.
*/
#define TID_STEP 1
#endif
static inline unsigned long next_tid(unsigned long tid)
{
return tid + TID_STEP;
}
static inline unsigned int tid_to_cpu(unsigned long tid)
{
return tid % TID_STEP;
}
static inline unsigned long tid_to_event(unsigned long tid)
{
return tid / TID_STEP;
}
static inline unsigned int init_tid(int cpu)
{
return cpu;
}
static inline void note_cmpxchg_failure(const char *n,
const struct kmem_cache *s, unsigned long tid)
{
#ifdef SLUB_DEBUG_CMPXCHG
unsigned long actual_tid = __this_cpu_read(s->cpu_slab->tid);
printk(KERN_INFO "%s %s: cmpxchg redo ", n, s->name);
#ifdef CONFIG_PREEMPT
if (tid_to_cpu(tid) != tid_to_cpu(actual_tid))
printk("due to cpu change %d -> %d\n",
tid_to_cpu(tid), tid_to_cpu(actual_tid));
else
#endif
if (tid_to_event(tid) != tid_to_event(actual_tid))
printk("due to cpu running other code. Event %ld->%ld\n",
tid_to_event(tid), tid_to_event(actual_tid));
else
printk("for unknown reason: actual=%lx was=%lx target=%lx\n",
actual_tid, tid, next_tid(tid));
#endif
stat(s, CMPXCHG_DOUBLE_CPU_FAIL);
}
static void init_kmem_cache_cpus(struct kmem_cache *s)
{
int cpu;
for_each_possible_cpu(cpu)
per_cpu_ptr(s->cpu_slab, cpu)->tid = init_tid(cpu);
}
/*
* Remove the cpu slab
*/
static void deactivate_slab(struct kmem_cache *s, struct page *page, void *freelist)
{
enum slab_modes { M_NONE, M_PARTIAL, M_FULL, M_FREE };
struct kmem_cache_node *n = get_node(s, page_to_nid(page));
int lock = 0;
enum slab_modes l = M_NONE, m = M_NONE;
void *nextfree;
int tail = DEACTIVATE_TO_HEAD;
struct page new;
struct page old;
if (page->freelist) {
stat(s, DEACTIVATE_REMOTE_FREES);
tail = DEACTIVATE_TO_TAIL;
}
/*
* Stage one: Free all available per cpu objects back
* to the page freelist while it is still frozen. Leave the
* last one.
*
* There is no need to take the list->lock because the page
* is still frozen.
*/
while (freelist && (nextfree = get_freepointer(s, freelist))) {
void *prior;
unsigned long counters;
do {
prior = page->freelist;
counters = page->counters;
set_freepointer(s, freelist, prior);
new.counters = counters;
new.inuse--;
VM_BUG_ON(!new.frozen);
} while (!__cmpxchg_double_slab(s, page,
prior, counters,
freelist, new.counters,
"drain percpu freelist"));
freelist = nextfree;
}
/*
* Stage two: Ensure that the page is unfrozen while the
* list presence reflects the actual number of objects
* during unfreeze.
*
* We setup the list membership and then perform a cmpxchg
* with the count. If there is a mismatch then the page
* is not unfrozen but the page is on the wrong list.
*
* Then we restart the process which may have to remove
* the page from the list that we just put it on again
* because the number of objects in the slab may have
* changed.
*/
redo:
old.freelist = page->freelist;
old.counters = page->counters;
VM_BUG_ON(!old.frozen);
/* Determine target state of the slab */
new.counters = old.counters;
if (freelist) {
new.inuse--;
set_freepointer(s, freelist, old.freelist);
new.freelist = freelist;
} else
new.freelist = old.freelist;
new.frozen = 0;
if (!new.inuse && n->nr_partial > s->min_partial)
m = M_FREE;
else if (new.freelist) {
m = M_PARTIAL;
if (!lock) {
lock = 1;
/*
* Taking the spinlock removes the possiblity
* that acquire_slab() will see a slab page that
* is frozen
*/
spin_lock(&n->list_lock);
}
} else {
m = M_FULL;
if (kmem_cache_debug(s) && !lock) {
lock = 1;
/*
* This also ensures that the scanning of full
* slabs from diagnostic functions will not see
* any frozen slabs.
*/
spin_lock(&n->list_lock);
}
}
if (l != m) {
if (l == M_PARTIAL)
remove_partial(n, page);
else if (l == M_FULL)
remove_full(s, page);
if (m == M_PARTIAL) {
add_partial(n, page, tail);
stat(s, tail);
} else if (m == M_FULL) {
stat(s, DEACTIVATE_FULL);
add_full(s, n, page);
}
}
l = m;
if (!__cmpxchg_double_slab(s, page,
old.freelist, old.counters,
new.freelist, new.counters,
"unfreezing slab"))
goto redo;
if (lock)
spin_unlock(&n->list_lock);
if (m == M_FREE) {
stat(s, DEACTIVATE_EMPTY);
discard_slab(s, page);
stat(s, FREE_SLAB);
}
}
/*
* Unfreeze all the cpu partial slabs.
*
* This function must be called with interrupts disabled
* for the cpu using c (or some other guarantee must be there
* to guarantee no concurrent accesses).
*/
static void unfreeze_partials(struct kmem_cache *s,
struct kmem_cache_cpu *c)
{
struct kmem_cache_node *n = NULL, *n2 = NULL;
struct page *page, *discard_page = NULL;
while ((page = c->partial)) {
struct page new;
struct page old;
c->partial = page->next;
n2 = get_node(s, page_to_nid(page));
if (n != n2) {
if (n)
spin_unlock(&n->list_lock);
n = n2;
spin_lock(&n->list_lock);
}
do {
old.freelist = page->freelist;
old.counters = page->counters;
VM_BUG_ON(!old.frozen);
new.counters = old.counters;
new.freelist = old.freelist;
new.frozen = 0;
} while (!__cmpxchg_double_slab(s, page,
old.freelist, old.counters,
new.freelist, new.counters,
"unfreezing slab"));
if (unlikely(!new.inuse && n->nr_partial > s->min_partial)) {
page->next = discard_page;
discard_page = page;
} else {
add_partial(n, page, DEACTIVATE_TO_TAIL);
stat(s, FREE_ADD_PARTIAL);
}
}
if (n)
spin_unlock(&n->list_lock);
while (discard_page) {
page = discard_page;
discard_page = discard_page->next;
stat(s, DEACTIVATE_EMPTY);
discard_slab(s, page);
stat(s, FREE_SLAB);
}
}
/*
* Put a page that was just frozen (in __slab_free) into a partial page
* slot if available. This is done without interrupts disabled and without
* preemption disabled. The cmpxchg is racy and may put the partial page
* onto a random cpus partial slot.
*
* If we did not find a slot then simply move all the partials to the
* per node partial list.
*/
static void put_cpu_partial(struct kmem_cache *s, struct page *page, int drain)
{
struct page *oldpage;
int pages;
int pobjects;
do {
pages = 0;
pobjects = 0;
oldpage = this_cpu_read(s->cpu_slab->partial);
if (oldpage) {
pobjects = oldpage->pobjects;
pages = oldpage->pages;
if (drain && pobjects > s->cpu_partial) {
unsigned long flags;
/*
* partial array is full. Move the existing
* set to the per node partial list.
*/
local_irq_save(flags);
unfreeze_partials(s, this_cpu_ptr(s->cpu_slab));
local_irq_restore(flags);
oldpage = NULL;
pobjects = 0;
pages = 0;
stat(s, CPU_PARTIAL_DRAIN);
}
}
pages++;
pobjects += page->objects - page->inuse;
page->pages = pages;
page->pobjects = pobjects;
page->next = oldpage;
} while (this_cpu_cmpxchg(s->cpu_slab->partial, oldpage, page) != oldpage);
}
static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
{
stat(s, CPUSLAB_FLUSH);
deactivate_slab(s, c->page, c->freelist);
c->tid = next_tid(c->tid);
c->page = NULL;
c->freelist = NULL;
}
/*
* Flush cpu slab.
*
* Called from IPI handler with interrupts disabled.
*/
static inline void __flush_cpu_slab(struct kmem_cache *s, int cpu)
{
struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu);
if (likely(c)) {
if (c->page)
flush_slab(s, c);
unfreeze_partials(s, c);
}
}
static void flush_cpu_slab(void *d)
{
struct kmem_cache *s = d;
__flush_cpu_slab(s, smp_processor_id());
}
static bool has_cpu_slab(int cpu, void *info)
{
struct kmem_cache *s = info;
struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu);
return c->page || c->partial;
}
static void flush_all(struct kmem_cache *s)
{
on_each_cpu_cond(has_cpu_slab, flush_cpu_slab, s, 1, GFP_ATOMIC);
}
/*
* Check if the objects in a per cpu structure fit numa
* locality expectations.
*/
static inline int node_match(struct page *page, int node)
{
#ifdef CONFIG_NUMA
if (!page || (node != NUMA_NO_NODE && page_to_nid(page) != node))
return 0;
#endif
return 1;
}
static int count_free(struct page *page)
{
return page->objects - page->inuse;
}
static unsigned long count_partial(struct kmem_cache_node *n,
int (*get_count)(struct page *))
{
unsigned long flags;
unsigned long x = 0;
struct page *page;
spin_lock_irqsave(&n->list_lock, flags);
list_for_each_entry(page, &n->partial, lru)
x += get_count(page);
spin_unlock_irqrestore(&n->list_lock, flags);
return x;
}
static inline unsigned long node_nr_objs(struct kmem_cache_node *n)
{
#ifdef CONFIG_SLUB_DEBUG
return atomic_long_read(&n->total_objects);
#else
return 0;
#endif
}
static noinline void
slab_out_of_memory(struct kmem_cache *s, gfp_t gfpflags, int nid)
{
int node;
printk(KERN_WARNING
"SLUB: Unable to allocate memory on node %d (gfp=0x%x)\n",
nid, gfpflags);
printk(KERN_WARNING " cache: %s, object size: %d, buffer size: %d, "
"default order: %d, min order: %d\n", s->name, s->object_size,
s->size, oo_order(s->oo), oo_order(s->min));
if (oo_order(s->min) > get_order(s->object_size))
printk(KERN_WARNING " %s debugging increased min order, use "
"slub_debug=O to disable.\n", s->name);
for_each_online_node(node) {
struct kmem_cache_node *n = get_node(s, node);
unsigned long nr_slabs;
unsigned long nr_objs;
unsigned long nr_free;
if (!n)
continue;
nr_free = count_partial(n, count_free);
nr_slabs = node_nr_slabs(n);
nr_objs = node_nr_objs(n);
printk(KERN_WARNING
" node %d: slabs: %ld, objs: %ld, free: %ld\n",
node, nr_slabs, nr_objs, nr_free);
}
}
static inline void *new_slab_objects(struct kmem_cache *s, gfp_t flags,
int node, struct kmem_cache_cpu **pc)
{
void *freelist;
struct kmem_cache_cpu *c = *pc;
struct page *page;
freelist = get_partial(s, flags, node, c);
if (freelist)
return freelist;
page = new_slab(s, flags, node);
if (page) {
c = __this_cpu_ptr(s->cpu_slab);
if (c->page)
flush_slab(s, c);
/*
* No other reference to the page yet so we can
* muck around with it freely without cmpxchg
*/
freelist = page->freelist;
page->freelist = NULL;
stat(s, ALLOC_SLAB);
c->page = page;
*pc = c;
} else
freelist = NULL;
return freelist;
}
static inline bool pfmemalloc_match(struct page *page, gfp_t gfpflags)
{
if (unlikely(PageSlabPfmemalloc(page)))
return gfp_pfmemalloc_allowed(gfpflags);
return true;
}
/*
* Check the page->freelist of a page and either transfer the freelist to the per cpu freelist
* or deactivate the page.
*
* The page is still frozen if the return value is not NULL.
*
* If this function returns NULL then the page has been unfrozen.
*
* This function must be called with interrupt disabled.
*/
static inline void *get_freelist(struct kmem_cache *s, struct page *page)
{
struct page new;
unsigned long counters;
void *freelist;
do {
freelist = page->freelist;
counters = page->counters;
new.counters = counters;
VM_BUG_ON(!new.frozen);
new.inuse = page->objects;
new.frozen = freelist != NULL;
} while (!__cmpxchg_double_slab(s, page,
freelist, counters,
NULL, new.counters,
"get_freelist"));
return freelist;
}
/*
* Slow path. The lockless freelist is empty or we need to perform
* debugging duties.
*
* Processing is still very fast if new objects have been freed to the
* regular freelist. In that case we simply take over the regular freelist
* as the lockless freelist and zap the regular freelist.
*
* If that is not working then we fall back to the partial lists. We take the
* first element of the freelist as the object to allocate now and move the
* rest of the freelist to the lockless freelist.
*
* And if we were unable to get a new slab from the partial slab lists then
* we need to allocate a new slab. This is the slowest path since it involves
* a call to the page allocator and the setup of a new slab.
*/
static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
unsigned long addr, struct kmem_cache_cpu *c)
{
void *freelist;
struct page *page;
unsigned long flags;
local_irq_save(flags);
#ifdef CONFIG_PREEMPT
/*
* We may have been preempted and rescheduled on a different
* cpu before disabling interrupts. Need to reload cpu area
* pointer.
*/
c = this_cpu_ptr(s->cpu_slab);
#endif
page = c->page;
if (!page)
goto new_slab;
redo:
if (unlikely(!node_match(page, node))) {
stat(s, ALLOC_NODE_MISMATCH);
deactivate_slab(s, page, c->freelist);
c->page = NULL;
c->freelist = NULL;
goto new_slab;
}
/*
* By rights, we should be searching for a slab page that was
* PFMEMALLOC but right now, we are losing the pfmemalloc
* information when the page leaves the per-cpu allocator
*/
if (unlikely(!pfmemalloc_match(page, gfpflags))) {
deactivate_slab(s, page, c->freelist);
c->page = NULL;
c->freelist = NULL;
goto new_slab;
}
/* must check again c->freelist in case of cpu migration or IRQ */
freelist = c->freelist;
if (freelist)
goto load_freelist;
stat(s, ALLOC_SLOWPATH);
freelist = get_freelist(s, page);
if (!freelist) {
c->page = NULL;
stat(s, DEACTIVATE_BYPASS);
goto new_slab;
}
stat(s, ALLOC_REFILL);
load_freelist:
/*
* freelist is pointing to the list of objects to be used.
* page is pointing to the page from which the objects are obtained.
* That page must be frozen for per cpu allocations to work.
*/
VM_BUG_ON(!c->page->frozen);
c->freelist = get_freepointer(s, freelist);
c->tid = next_tid(c->tid);
local_irq_restore(flags);
return freelist;
new_slab:
if (c->partial) {
page = c->page = c->partial;
c->partial = page->next;
stat(s, CPU_PARTIAL_ALLOC);
c->freelist = NULL;
goto redo;
}
freelist = new_slab_objects(s, gfpflags, node, &c);
if (unlikely(!freelist)) {
if (!(gfpflags & __GFP_NOWARN) && printk_ratelimit())
slab_out_of_memory(s, gfpflags, node);
local_irq_restore(flags);
return NULL;
}
page = c->page;
if (likely(!kmem_cache_debug(s) && pfmemalloc_match(page, gfpflags)))
goto load_freelist;
/* Only entered in the debug case */
if (kmem_cache_debug(s) && !alloc_debug_processing(s, page, freelist, addr))
goto new_slab; /* Slab failed checks. Next slab needed */
deactivate_slab(s, page, get_freepointer(s, freelist));
c->page = NULL;
c->freelist = NULL;
local_irq_restore(flags);
return freelist;
}
/*
* Inlined fastpath so that allocation functions (kmalloc, kmem_cache_alloc)
* have the fastpath folded into their functions. So no function call
* overhead for requests that can be satisfied on the fastpath.
*
* The fastpath works by first checking if the lockless freelist can be used.
* If not then __slab_alloc is called for slow processing.
*
* Otherwise we can simply pick the next object from the lockless free list.
*/
static __always_inline void *slab_alloc_node(struct kmem_cache *s,
gfp_t gfpflags, int node, unsigned long addr)
{
void **object;
struct kmem_cache_cpu *c;
struct page *page;
unsigned long tid;
if (slab_pre_alloc_hook(s, gfpflags))
return NULL;
s = memcg_kmem_get_cache(s, gfpflags);
redo:
/*
* Must read kmem_cache cpu data via this cpu ptr. Preemption is
* enabled. We may switch back and forth between cpus while
* reading from one cpu area. That does not matter as long
* as we end up on the original cpu again when doing the cmpxchg.
*
* Preemption is disabled for the retrieval of the tid because that
* must occur from the current processor. We cannot allow rescheduling
* on a different processor between the determination of the pointer
* and the retrieval of the tid.
*/
preempt_disable();
c = __this_cpu_ptr(s->cpu_slab);
/*
* The transaction ids are globally unique per cpu and per operation on
* a per cpu queue. Thus they can be guarantee that the cmpxchg_double
* occurs on the right processor and that there was no operation on the
* linked list in between.
*/
tid = c->tid;
preempt_enable();
object = c->freelist;
page = c->page;
if (unlikely(!object || !node_match(page, node)))
object = __slab_alloc(s, gfpflags, node, addr, c);
else {
void *next_object = get_freepointer_safe(s, object);
/*
* The cmpxchg will only match if there was no additional
* operation and if we are on the right processor.
*
* The cmpxchg does the following atomically (without lock semantics!)
* 1. Relocate first pointer to the current per cpu area.
* 2. Verify that tid and freelist have not been changed
* 3. If they were not changed replace tid and freelist
*
* Since this is without lock semantics the protection is only against
* code executing on this cpu *not* from access by other cpus.
*/
if (unlikely(!this_cpu_cmpxchg_double(
s->cpu_slab->freelist, s->cpu_slab->tid,
object, tid,
next_object, next_tid(tid)))) {
note_cmpxchg_failure("slab_alloc", s, tid);
goto redo;
}
prefetch_freepointer(s, next_object);
stat(s, ALLOC_FASTPATH);
}
if (unlikely(gfpflags & __GFP_ZERO) && object)
memset(object, 0, s->object_size);
slab_post_alloc_hook(s, gfpflags, object);
return object;
}
static __always_inline void *slab_alloc(struct kmem_cache *s,
gfp_t gfpflags, unsigned long addr)
{
return slab_alloc_node(s, gfpflags, NUMA_NO_NODE, addr);
}
void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags)
{
void *ret = slab_alloc(s, gfpflags, _RET_IP_);
trace_kmem_cache_alloc(_RET_IP_, ret, s->object_size, s->size, gfpflags);
return ret;
}
EXPORT_SYMBOL(kmem_cache_alloc);
#ifdef CONFIG_TRACING
void *kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t gfpflags, size_t size)
{
void *ret = slab_alloc(s, gfpflags, _RET_IP_);
trace_kmalloc(_RET_IP_, ret, size, s->size, gfpflags);
return ret;
}
EXPORT_SYMBOL(kmem_cache_alloc_trace);
void *kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
{
void *ret = kmalloc_order(size, flags, order);
trace_kmalloc(_RET_IP_, ret, size, PAGE_SIZE << order, flags);
return ret;
}
EXPORT_SYMBOL(kmalloc_order_trace);
#endif
#ifdef CONFIG_NUMA
void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, int node)
{
void *ret = slab_alloc_node(s, gfpflags, node, _RET_IP_);
trace_kmem_cache_alloc_node(_RET_IP_, ret,
s->object_size, s->size, gfpflags, node);
return ret;
}
EXPORT_SYMBOL(kmem_cache_alloc_node);
#ifdef CONFIG_TRACING
void *kmem_cache_alloc_node_trace(struct kmem_cache *s,
gfp_t gfpflags,
int node, size_t size)
{
void *ret = slab_alloc_node(s, gfpflags, node, _RET_IP_);
trace_kmalloc_node(_RET_IP_, ret,
size, s->size, gfpflags, node);
return ret;
}
EXPORT_SYMBOL(kmem_cache_alloc_node_trace);
#endif
#endif
/*
* Slow patch handling. This may still be called frequently since objects
* have a longer lifetime than the cpu slabs in most processing loads.
*
* So we still attempt to reduce cache line usage. Just take the slab
* lock and free the item. If there is no additional partial page
* handling required then we can return immediately.
*/
static void __slab_free(struct kmem_cache *s, struct page *page,
void *x, unsigned long addr)
{
void *prior;
void **object = (void *)x;
int was_frozen;
struct page new;
unsigned long counters;
struct kmem_cache_node *n = NULL;
unsigned long uninitialized_var(flags);
stat(s, FREE_SLOWPATH);
if (kmem_cache_debug(s) &&
!(n = free_debug_processing(s, page, x, addr, &flags)))
return;
do {
if (unlikely(n)) {
spin_unlock_irqrestore(&n->list_lock, flags);
n = NULL;
}
prior = page->freelist;
counters = page->counters;
set_freepointer(s, object, prior);
new.counters = counters;
was_frozen = new.frozen;
new.inuse--;
if ((!new.inuse || !prior) && !was_frozen) {
if (!kmem_cache_debug(s) && !prior)
/*
* Slab was on no list before and will be partially empty
* We can defer the list move and instead freeze it.
*/
new.frozen = 1;
else { /* Needs to be taken off a list */
n = get_node(s, page_to_nid(page));
/*
* Speculatively acquire the list_lock.
* If the cmpxchg does not succeed then we may
* drop the list_lock without any processing.
*
* Otherwise the list_lock will synchronize with
* other processors updating the list of slabs.
*/
spin_lock_irqsave(&n->list_lock, flags);
}
}
} while (!cmpxchg_double_slab(s, page,
prior, counters,
object, new.counters,
"__slab_free"));
if (likely(!n)) {
/*
* If we just froze the page then put it onto the
* per cpu partial list.
*/
if (new.frozen && !was_frozen) {
put_cpu_partial(s, page, 1);
stat(s, CPU_PARTIAL_FREE);
}
/*
* The list lock was not taken therefore no list
* activity can be necessary.
*/
if (was_frozen)
stat(s, FREE_FROZEN);
return;
}
if (unlikely(!new.inuse && n->nr_partial > s->min_partial))
goto slab_empty;
/*
* Objects left in the slab. If it was not on the partial list before
* then add it.
*/
if (kmem_cache_debug(s) && unlikely(!prior)) {
remove_full(s, page);
add_partial(n, page, DEACTIVATE_TO_TAIL);
stat(s, FREE_ADD_PARTIAL);
}
spin_unlock_irqrestore(&n->list_lock, flags);
return;
slab_empty:
if (prior) {
/*
* Slab on the partial list.
*/
remove_partial(n, page);
stat(s, FREE_REMOVE_PARTIAL);
} else
/* Slab must be on the full list */
remove_full(s, page);
spin_unlock_irqrestore(&n->list_lock, flags);
stat(s, FREE_SLAB);
discard_slab(s, page);
}
/*
* Fastpath with forced inlining to produce a kfree and kmem_cache_free that
* can perform fastpath freeing without additional function calls.
*
* The fastpath is only possible if we are freeing to the current cpu slab
* of this processor. This typically the case if we have just allocated
* the item before.
*
* If fastpath is not possible then fall back to __slab_free where we deal
* with all sorts of special processing.
*/
static __always_inline void slab_free(struct kmem_cache *s,
struct page *page, void *x, unsigned long addr)
{
void **object = (void *)x;
struct kmem_cache_cpu *c;
unsigned long tid;
slab_free_hook(s, x);
redo:
/*
* Determine the currently cpus per cpu slab.
* The cpu may change afterward. However that does not matter since
* data is retrieved via this pointer. If we are on the same cpu
* during the cmpxchg then the free will succedd.
*/
preempt_disable();
c = __this_cpu_ptr(s->cpu_slab);
tid = c->tid;
preempt_enable();
if (likely(page == c->page)) {
set_freepointer(s, object, c->freelist);
if (unlikely(!this_cpu_cmpxchg_double(
s->cpu_slab->freelist, s->cpu_slab->tid,
c->freelist, tid,
object, next_tid(tid)))) {
note_cmpxchg_failure("slab_free", s, tid);
goto redo;
}
stat(s, FREE_FASTPATH);
} else
__slab_free(s, page, x, addr);
}
void kmem_cache_free(struct kmem_cache *s, void *x)
{
s = cache_from_obj(s, x);
if (!s)
return;
slab_free(s, virt_to_head_page(x), x, _RET_IP_);
trace_kmem_cache_free(_RET_IP_, x);
}
EXPORT_SYMBOL(kmem_cache_free);
/*
* Object placement in a slab is made very easy because we always start at
* offset 0. If we tune the size of the object to the alignment then we can
* get the required alignment by putting one properly sized object after
* another.
*
* Notice that the allocation order determines the sizes of the per cpu
* caches. Each processor has always one slab available for allocations.
* Increasing the allocation order reduces the number of times that slabs
* must be moved on and off the partial lists and is therefore a factor in
* locking overhead.
*/
/*
* Mininum / Maximum order of slab pages. This influences locking overhead
* and slab fragmentation. A higher order reduces the number of partial slabs
* and increases the number of allocations possible without having to
* take the list_lock.
*/
static int slub_min_order;
static int slub_max_order = PAGE_ALLOC_COSTLY_ORDER;
static int slub_min_objects;
/*
* Merge control. If this is set then no merging of slab caches will occur.
* (Could be removed. This was introduced to pacify the merge skeptics.)
*/
static int slub_nomerge;
/*
* Calculate the order of allocation given an slab object size.
*
* The order of allocation has significant impact on performance and other
* system components. Generally order 0 allocations should be preferred since
* order 0 does not cause fragmentation in the page allocator. Larger objects
* be problematic to put into order 0 slabs because there may be too much
* unused space left. We go to a higher order if more than 1/16th of the slab
* would be wasted.
*
* In order to reach satisfactory performance we must ensure that a minimum
* number of objects is in one slab. Otherwise we may generate too much
* activity on the partial lists which requires taking the list_lock. This is
* less a concern for large slabs though which are rarely used.
*
* slub_max_order specifies the order where we begin to stop considering the
* number of objects in a slab as critical. If we reach slub_max_order then
* we try to keep the page order as low as possible. So we accept more waste
* of space in favor of a small page order.
*
* Higher order allocations also allow the placement of more objects in a
* slab and thereby reduce object handling overhead. If the user has
* requested a higher mininum order then we start with that one instead of
* the smallest order which will fit the object.
*/
static inline int slab_order(int size, int min_objects,
int max_order, int fract_leftover, int reserved)
{
int order;
int rem;
int min_order = slub_min_order;
if (order_objects(min_order, size, reserved) > MAX_OBJS_PER_PAGE)
return get_order(size * MAX_OBJS_PER_PAGE) - 1;
for (order = max(min_order,
fls(min_objects * size - 1) - PAGE_SHIFT);
order <= max_order; order++) {
unsigned long slab_size = PAGE_SIZE << order;
if (slab_size < min_objects * size + reserved)
continue;
rem = (slab_size - reserved) % size;
if (rem <= slab_size / fract_leftover)
break;
}
return order;
}
static inline int calculate_order(int size, int reserved)
{
int order;
int min_objects;
int fraction;
int max_objects;
/*
* Attempt to find best configuration for a slab. This
* works by first attempting to generate a layout with
* the best configuration and backing off gradually.
*
* First we reduce the acceptable waste in a slab. Then
* we reduce the minimum objects required in a slab.
*/
min_objects = slub_min_objects;
if (!min_objects)
min_objects = 4 * (fls(nr_cpu_ids) + 1);
max_objects = order_objects(slub_max_order, size, reserved);
min_objects = min(min_objects, max_objects);
while (min_objects > 1) {
fraction = 16;
while (fraction >= 4) {
order = slab_order(size, min_objects,
slub_max_order, fraction, reserved);
if (order <= slub_max_order)
return order;
fraction /= 2;
}
min_objects--;
}
/*
* We were unable to place multiple objects in a slab. Now
* lets see if we can place a single object there.
*/
order = slab_order(size, 1, slub_max_order, 1, reserved);
if (order <= slub_max_order)
return order;
/*
* Doh this slab cannot be placed using slub_max_order.
*/
order = slab_order(size, 1, MAX_ORDER, 1, reserved);
if (order < MAX_ORDER)
return order;
return -ENOSYS;
}
static void
init_kmem_cache_node(struct kmem_cache_node *n)
{
n->nr_partial = 0;
spin_lock_init(&n->list_lock);
INIT_LIST_HEAD(&n->partial);
#ifdef CONFIG_SLUB_DEBUG
atomic_long_set(&n->nr_slabs, 0);
atomic_long_set(&n->total_objects, 0);
INIT_LIST_HEAD(&n->full);
#endif
}
static inline int alloc_kmem_cache_cpus(struct kmem_cache *s)
{
BUILD_BUG_ON(PERCPU_DYNAMIC_EARLY_SIZE <
KMALLOC_SHIFT_HIGH * sizeof(struct kmem_cache_cpu));
/*
* Must align to double word boundary for the double cmpxchg
* instructions to work; see __pcpu_double_call_return_bool().
*/
s->cpu_slab = __alloc_percpu(sizeof(struct kmem_cache_cpu),
2 * sizeof(void *));
if (!s->cpu_slab)
return 0;
init_kmem_cache_cpus(s);
return 1;
}
static struct kmem_cache *kmem_cache_node;
/*
* No kmalloc_node yet so do it by hand. We know that this is the first
* slab on the node for this slabcache. There are no concurrent accesses
* possible.
*
* Note that this function only works on the kmalloc_node_cache
* when allocating for the kmalloc_node_cache. This is used for bootstrapping
* memory on a fresh node that has no slab structures yet.
*/
static void early_kmem_cache_node_alloc(int node)
{
struct page *page;
struct kmem_cache_node *n;
BUG_ON(kmem_cache_node->size < sizeof(struct kmem_cache_node));
page = new_slab(kmem_cache_node, GFP_NOWAIT, node);
BUG_ON(!page);
if (page_to_nid(page) != node) {
printk(KERN_ERR "SLUB: Unable to allocate memory from "
"node %d\n", node);
printk(KERN_ERR "SLUB: Allocating a useless per node structure "
"in order to be able to continue\n");
}
n = page->freelist;
BUG_ON(!n);
page->freelist = get_freepointer(kmem_cache_node, n);
page->inuse = 1;
page->frozen = 0;
kmem_cache_node->node[node] = n;
#ifdef CONFIG_SLUB_DEBUG
init_object(kmem_cache_node, n, SLUB_RED_ACTIVE);
init_tracking(kmem_cache_node, n);
#endif
init_kmem_cache_node(n);
inc_slabs_node(kmem_cache_node, node, page->objects);
add_partial(n, page, DEACTIVATE_TO_HEAD);
}
static void free_kmem_cache_nodes(struct kmem_cache *s)
{
int node;
for_each_node_state(node, N_NORMAL_MEMORY) {
struct kmem_cache_node *n = s->node[node];
if (n)
kmem_cache_free(kmem_cache_node, n);
s->node[node] = NULL;
}
}
static int init_kmem_cache_nodes(struct kmem_cache *s)
{
int node;
for_each_node_state(node, N_NORMAL_MEMORY) {
struct kmem_cache_node *n;
if (slab_state == DOWN) {
early_kmem_cache_node_alloc(node);
continue;
}
n = kmem_cache_alloc_node(kmem_cache_node,
GFP_KERNEL, node);
if (!n) {
free_kmem_cache_nodes(s);
return 0;
}
s->node[node] = n;
init_kmem_cache_node(n);
}
return 1;
}
static void set_min_partial(struct kmem_cache *s, unsigned long min)
{
if (min < MIN_PARTIAL)
min = MIN_PARTIAL;
else if (min > MAX_PARTIAL)
min = MAX_PARTIAL;
s->min_partial = min;
}
/*
* calculate_sizes() determines the order and the distribution of data within
* a slab object.
*/
static int calculate_sizes(struct kmem_cache *s, int forced_order)
{
unsigned long flags = s->flags;
unsigned long size = s->object_size;
int order;
/*
* Round up object size to the next word boundary. We can only
* place the free pointer at word boundaries and this determines
* the possible location of the free pointer.
*/
size = ALIGN(size, sizeof(void *));
#ifdef CONFIG_SLUB_DEBUG
/*
* Determine if we can poison the object itself. If the user of
* the slab may touch the object after free or before allocation
* then we should never poison the object itself.
*/
if ((flags & SLAB_POISON) && !(flags & SLAB_DESTROY_BY_RCU) &&
!s->ctor)
s->flags |= __OBJECT_POISON;
else
s->flags &= ~__OBJECT_POISON;
/*
* If we are Redzoning then check if there is some space between the
* end of the object and the free pointer. If not then add an
* additional word to have some bytes to store Redzone information.
*/
if ((flags & SLAB_RED_ZONE) && size == s->object_size)
size += sizeof(void *);
#endif
/*
* With that we have determined the number of bytes in actual use
* by the object. This is the potential offset to the free pointer.
*/
s->inuse = size;
if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
s->ctor)) {
/*
* Relocate free pointer after the object if it is not
* permitted to overwrite the first word of the object on
* kmem_cache_free.
*
* This is the case if we do RCU, have a constructor or
* destructor or are poisoning the objects.
*/
s->offset = size;
size += sizeof(void *);
}
#ifdef CONFIG_SLUB_DEBUG
if (flags & SLAB_STORE_USER)
/*
* Need to store information about allocs and frees after
* the object.
*/
size += 2 * sizeof(struct track);
if (flags & SLAB_RED_ZONE)
/*
* Add some empty padding so that we can catch
* overwrites from earlier objects rather than let
* tracking information or the free pointer be
* corrupted if a user writes before the start
* of the object.
*/
size += sizeof(void *);
#endif
/*
* SLUB stores one object immediately after another beginning from
* offset 0. In order to align the objects we have to simply size
* each object to conform to the alignment.
*/
size = ALIGN(size, s->align);
s->size = size;
if (forced_order >= 0)
order = forced_order;
else
order = calculate_order(size, s->reserved);
if (order < 0)
return 0;
s->allocflags = 0;
if (order)
s->allocflags |= __GFP_COMP;
if (s->flags & SLAB_CACHE_DMA)
s->allocflags |= GFP_DMA;
if (s->flags & SLAB_RECLAIM_ACCOUNT)
s->allocflags |= __GFP_RECLAIMABLE;
/*
* Determine the number of objects per slab
*/
s->oo = oo_make(order, size, s->reserved);
s->min = oo_make(get_order(size), size, s->reserved);
if (oo_objects(s->oo) > oo_objects(s->max))
s->max = s->oo;
return !!oo_objects(s->oo);
}
static int kmem_cache_open(struct kmem_cache *s, unsigned long flags)
{
s->flags = kmem_cache_flags(s->size, flags, s->name, s->ctor);
s->reserved = 0;
if (need_reserve_slab_rcu && (s->flags & SLAB_DESTROY_BY_RCU))
s->reserved = sizeof(struct rcu_head);
if (!calculate_sizes(s, -1))
goto error;
if (disable_higher_order_debug) {
/*
* Disable debugging flags that store metadata if the min slab
* order increased.
*/
if (get_order(s->size) > get_order(s->object_size)) {
s->flags &= ~DEBUG_METADATA_FLAGS;
s->offset = 0;
if (!calculate_sizes(s, -1))
goto error;
}
}
#if defined(CONFIG_HAVE_CMPXCHG_DOUBLE) && \
defined(CONFIG_HAVE_ALIGNED_STRUCT_PAGE)
if (system_has_cmpxchg_double() && (s->flags & SLAB_DEBUG_FLAGS) == 0)
/* Enable fast mode */
s->flags |= __CMPXCHG_DOUBLE;
#endif
/*
* The larger the object size is, the more pages we want on the partial
* list to avoid pounding the page allocator excessively.
*/
set_min_partial(s, ilog2(s->size) / 2);
/*
* cpu_partial determined the maximum number of objects kept in the
* per cpu partial lists of a processor.
*
* Per cpu partial lists mainly contain slabs that just have one
* object freed. If they are used for allocation then they can be
* filled up again with minimal effort. The slab will never hit the
* per node partial lists and therefore no locking will be required.
*
* This setting also determines
*
* A) The number of objects from per cpu partial slabs dumped to the
* per node list when we reach the limit.
* B) The number of objects in cpu partial slabs to extract from the
* per node list when we run out of per cpu objects. We only fetch 50%
* to keep some capacity around for frees.
*/
if (kmem_cache_debug(s))
s->cpu_partial = 0;
else if (s->size >= PAGE_SIZE)
s->cpu_partial = 2;
else if (s->size >= 1024)
s->cpu_partial = 6;
else if (s->size >= 256)
s->cpu_partial = 13;
else
s->cpu_partial = 30;
#ifdef CONFIG_NUMA
s->remote_node_defrag_ratio = 1000;
#endif
if (!init_kmem_cache_nodes(s))
goto error;
if (alloc_kmem_cache_cpus(s))
return 0;
free_kmem_cache_nodes(s);
error:
if (flags & SLAB_PANIC)
panic("Cannot create slab %s size=%lu realsize=%u "
"order=%u offset=%u flags=%lx\n",
s->name, (unsigned long)s->size, s->size, oo_order(s->oo),
s->offset, flags);
return -EINVAL;
}
static void list_slab_objects(struct kmem_cache *s, struct page *page,
const char *text)
{
#ifdef CONFIG_SLUB_DEBUG
void *addr = page_address(page);
void *p;
unsigned long *map = kzalloc(BITS_TO_LONGS(page->objects) *
sizeof(long), GFP_ATOMIC);
if (!map)
return;
slab_err_nopanic(s, page, text, s->name);
slab_lock(page);
get_map(s, page, map);
for_each_object(p, s, addr, page->objects) {
if (!test_bit(slab_index(p, s, addr), map)) {
printk(KERN_ERR "INFO: Object 0x%p @offset=%tu\n",
p, p - addr);
print_tracking(s, p);
}
}
if (slub_debug)
panic("SLUB ERROR: list_slab_objects.");
slab_unlock(page);
kfree(map);
#endif
}
/*
* Attempt to free all partial slabs on a node.
* This is called from kmem_cache_close(). We must be the last thread
* using the cache and therefore we do not need to lock anymore.
*/
static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n)
{
struct page *page, *h;
list_for_each_entry_safe(page, h, &n->partial, lru) {
if (!page->inuse) {
remove_partial(n, page);
discard_slab(s, page);
} else {
list_slab_objects(s, page,
"Objects remaining in %s on kmem_cache_close()");
}
}
}
/*
* Release all resources used by a slab cache.
*/
static inline int kmem_cache_close(struct kmem_cache *s)
{
int node;
flush_all(s);
/* Attempt to free all objects */
for_each_node_state(node, N_NORMAL_MEMORY) {
struct kmem_cache_node *n = get_node(s, node);
free_partial(s, n);
if (n->nr_partial || slabs_node(s, node))
return 1;
}
free_percpu(s->cpu_slab);
free_kmem_cache_nodes(s);
return 0;
}
int __kmem_cache_shutdown(struct kmem_cache *s)
{
int rc = kmem_cache_close(s);
if (!rc) {
/*
* We do the same lock strategy around sysfs_slab_add, see
* __kmem_cache_create. Because this is pretty much the last
* operation we do and the lock will be released shortly after
* that in slab_common.c, we could just move sysfs_slab_remove
* to a later point in common code. We should do that when we
* have a common sysfs framework for all allocators.
*/
mutex_unlock(&slab_mutex);
sysfs_slab_remove(s);
mutex_lock(&slab_mutex);
}
return rc;
}
/********************************************************************
* Kmalloc subsystem
*******************************************************************/
static int __init setup_slub_min_order(char *str)
{
get_option(&str, &slub_min_order);
return 1;
}
__setup("slub_min_order=", setup_slub_min_order);
static int __init setup_slub_max_order(char *str)
{
get_option(&str, &slub_max_order);
slub_max_order = min(slub_max_order, MAX_ORDER - 1);
return 1;
}
__setup("slub_max_order=", setup_slub_max_order);
static int __init setup_slub_min_objects(char *str)
{
get_option(&str, &slub_min_objects);
return 1;
}
__setup("slub_min_objects=", setup_slub_min_objects);
static int __init setup_slub_nomerge(char *str)
{
slub_nomerge = 1;
return 1;
}
__setup("slub_nomerge", setup_slub_nomerge);
void *__kmalloc(size_t size, gfp_t flags)
{
struct kmem_cache *s;
void *ret;
if (unlikely(size > KMALLOC_MAX_CACHE_SIZE))
return kmalloc_large(size, flags);
s = kmalloc_slab(size, flags);
if (unlikely(ZERO_OR_NULL_PTR(s)))
return s;
ret = slab_alloc(s, flags, _RET_IP_);
trace_kmalloc(_RET_IP_, ret, size, s->size, flags);
return ret;
}
EXPORT_SYMBOL(__kmalloc);
#ifdef CONFIG_NUMA
static void *kmalloc_large_node(size_t size, gfp_t flags, int node)
{
struct page *page;
void *ptr = NULL;
flags |= __GFP_COMP | __GFP_NOTRACK | __GFP_KMEMCG;
page = alloc_pages_node(node, flags, get_order(size));
if (page)
ptr = page_address(page);
kmemleak_alloc(ptr, size, 1, flags);
return ptr;
}
void *__kmalloc_node(size_t size, gfp_t flags, int node)
{
struct kmem_cache *s;
void *ret;
if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) {
ret = kmalloc_large_node(size, flags, node);
trace_kmalloc_node(_RET_IP_, ret,
size, PAGE_SIZE << get_order(size),
flags, node);
return ret;
}
s = kmalloc_slab(size, flags);
if (unlikely(ZERO_OR_NULL_PTR(s)))
return s;
ret = slab_alloc_node(s, flags, node, _RET_IP_);
trace_kmalloc_node(_RET_IP_, ret, size, s->size, flags, node);
return ret;
}
EXPORT_SYMBOL(__kmalloc_node);
#endif
size_t ksize(const void *object)
{
struct page *page;
if (unlikely(object == ZERO_SIZE_PTR))
return 0;
page = virt_to_head_page(object);
if (unlikely(!PageSlab(page))) {
WARN_ON(!PageCompound(page));
return PAGE_SIZE << compound_order(page);
}
return slab_ksize(page->slab_cache);
}
EXPORT_SYMBOL(ksize);
#ifdef CONFIG_SLUB_DEBUG
bool verify_mem_not_deleted(const void *x)
{
struct page *page;
void *object = (void *)x;
unsigned long flags;
bool rv;
if (unlikely(ZERO_OR_NULL_PTR(x)))
return false;
local_irq_save(flags);
page = virt_to_head_page(x);
if (unlikely(!PageSlab(page))) {
/* maybe it was from stack? */
rv = true;
goto out_unlock;
}
slab_lock(page);
if (on_freelist(page->slab_cache, page, object)) {
object_err(page->slab_cache, page, object, "Object is on free-list");
rv = false;
} else {
rv = true;
}
slab_unlock(page);
out_unlock:
local_irq_restore(flags);
return rv;
}
EXPORT_SYMBOL(verify_mem_not_deleted);
#endif
void kfree(const void *x)
{
struct page *page;
void *object = (void *)x;
trace_kfree(_RET_IP_, x);
if (unlikely(ZERO_OR_NULL_PTR(x)))
return;
page = virt_to_head_page(x);
if (unlikely(!PageSlab(page))) {
BUG_ON(!PageCompound(page));
kmemleak_free(x);
__free_memcg_kmem_pages(page, compound_order(page));
return;
}
slab_free(page->slab_cache, page, object, _RET_IP_);
}
EXPORT_SYMBOL(kfree);
/*
* kmem_cache_shrink removes empty slabs from the partial lists and sorts
* the remaining slabs by the number of items in use. The slabs with the
* most items in use come first. New allocations will then fill those up
* and thus they can be removed from the partial lists.
*
* The slabs with the least items are placed last. This results in them
* being allocated from last increasing the chance that the last objects
* are freed in them.
*/
int kmem_cache_shrink(struct kmem_cache *s)
{
int node;
int i;
struct kmem_cache_node *n;
struct page *page;
struct page *t;
int objects = oo_objects(s->max);
struct list_head *slabs_by_inuse =
kmalloc(sizeof(struct list_head) * objects, GFP_KERNEL);
unsigned long flags;
if (!slabs_by_inuse)
return -ENOMEM;
flush_all(s);
for_each_node_state(node, N_NORMAL_MEMORY) {
n = get_node(s, node);
if (!n->nr_partial)
continue;
for (i = 0; i < objects; i++)
INIT_LIST_HEAD(slabs_by_inuse + i);
spin_lock_irqsave(&n->list_lock, flags);
/*
* Build lists indexed by the items in use in each slab.
*
* Note that concurrent frees may occur while we hold the
* list_lock. page->inuse here is the upper limit.
*/
list_for_each_entry_safe(page, t, &n->partial, lru) {
list_move(&page->lru, slabs_by_inuse + page->inuse);
if (!page->inuse)
n->nr_partial--;
}
/*
* Rebuild the partial list with the slabs filled up most
* first and the least used slabs at the end.
*/
for (i = objects - 1; i > 0; i--)
list_splice(slabs_by_inuse + i, n->partial.prev);
spin_unlock_irqrestore(&n->list_lock, flags);
/* Release empty slabs */
list_for_each_entry_safe(page, t, slabs_by_inuse, lru)
discard_slab(s, page);
}
kfree(slabs_by_inuse);
return 0;
}
EXPORT_SYMBOL(kmem_cache_shrink);
static int slab_mem_going_offline_callback(void *arg)
{
struct kmem_cache *s;
mutex_lock(&slab_mutex);
list_for_each_entry(s, &slab_caches, list)
kmem_cache_shrink(s);
mutex_unlock(&slab_mutex);
return 0;
}
static void slab_mem_offline_callback(void *arg)
{
struct kmem_cache_node *n;
struct kmem_cache *s;
struct memory_notify *marg = arg;
int offline_node;
offline_node = marg->status_change_nid_normal;
/*
* If the node still has available memory. we need kmem_cache_node
* for it yet.
*/
if (offline_node < 0)
return;
mutex_lock(&slab_mutex);
list_for_each_entry(s, &slab_caches, list) {
n = get_node(s, offline_node);
if (n) {
/*
* if n->nr_slabs > 0, slabs still exist on the node
* that is going down. We were unable to free them,
* and offline_pages() function shouldn't call this
* callback. So, we must fail.
*/
BUG_ON(slabs_node(s, offline_node));
s->node[offline_node] = NULL;
kmem_cache_free(kmem_cache_node, n);
}
}
mutex_unlock(&slab_mutex);
}
static int slab_mem_going_online_callback(void *arg)
{
struct kmem_cache_node *n;
struct kmem_cache *s;
struct memory_notify *marg = arg;
int nid = marg->status_change_nid_normal;
int ret = 0;
/*
* If the node's memory is already available, then kmem_cache_node is
* already created. Nothing to do.
*/
if (nid < 0)
return 0;
/*
* We are bringing a node online. No memory is available yet. We must
* allocate a kmem_cache_node structure in order to bring the node
* online.
*/
mutex_lock(&slab_mutex);
list_for_each_entry(s, &slab_caches, list) {
/*
* XXX: kmem_cache_alloc_node will fallback to other nodes
* since memory is not yet available from the node that
* is brought up.
*/
n = kmem_cache_alloc(kmem_cache_node, GFP_KERNEL);
if (!n) {
ret = -ENOMEM;
goto out;
}
init_kmem_cache_node(n);
s->node[nid] = n;
}
out:
mutex_unlock(&slab_mutex);
return ret;
}
static int slab_memory_callback(struct notifier_block *self,
unsigned long action, void *arg)
{
int ret = 0;
switch (action) {
case MEM_GOING_ONLINE:
ret = slab_mem_going_online_callback(arg);
break;
case MEM_GOING_OFFLINE:
ret = slab_mem_going_offline_callback(arg);
break;
case MEM_OFFLINE:
case MEM_CANCEL_ONLINE:
slab_mem_offline_callback(arg);
break;
case MEM_ONLINE:
case MEM_CANCEL_OFFLINE:
break;
}
if (ret)
ret = notifier_from_errno(ret);
else
ret = NOTIFY_OK;
return ret;
}
static struct notifier_block slab_memory_callback_nb = {
.notifier_call = slab_memory_callback,
.priority = SLAB_CALLBACK_PRI,
};
/********************************************************************
* Basic setup of slabs
*******************************************************************/
/*
* Used for early kmem_cache structures that were allocated using
* the page allocator. Allocate them properly then fix up the pointers
* that may be pointing to the wrong kmem_cache structure.
*/
static struct kmem_cache * __init bootstrap(struct kmem_cache *static_cache)
{
int node;
struct kmem_cache *s = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
memcpy(s, static_cache, kmem_cache->object_size);
/*
* This runs very early, and only the boot processor is supposed to be
* up. Even if it weren't true, IRQs are not up so we couldn't fire
* IPIs around.
*/
__flush_cpu_slab(s, smp_processor_id());
for_each_node_state(node, N_NORMAL_MEMORY) {
struct kmem_cache_node *n = get_node(s, node);
struct page *p;
if (n) {
list_for_each_entry(p, &n->partial, lru)
p->slab_cache = s;
#ifdef CONFIG_SLUB_DEBUG
#ifndef CONFIG_TIMA_RKP_RO_CRED
list_for_each_entry(p, &n->full, lru)
p->slab_cache = s;
#endif /*CONFIG_TIMA_RKP_RO_CRED*/
#endif
}
}
list_add(&s->list, &slab_caches);
return s;
}
void __init kmem_cache_init(void)
{
static __initdata struct kmem_cache boot_kmem_cache,
boot_kmem_cache_node;
if (debug_guardpage_minorder())
slub_max_order = 0;
kmem_cache_node = &boot_kmem_cache_node;
kmem_cache = &boot_kmem_cache;
create_boot_cache(kmem_cache_node, "kmem_cache_node",
sizeof(struct kmem_cache_node), SLAB_HWCACHE_ALIGN);
register_hotmemory_notifier(&slab_memory_callback_nb);
/* Able to allocate the per node structures */
slab_state = PARTIAL;
create_boot_cache(kmem_cache, "kmem_cache",
offsetof(struct kmem_cache, node) +
nr_node_ids * sizeof(struct kmem_cache_node *),
SLAB_HWCACHE_ALIGN);
kmem_cache = bootstrap(&boot_kmem_cache);
/*
* Allocate kmem_cache_node properly from the kmem_cache slab.
* kmem_cache_node is separately allocated so no need to
* update any list pointers.
*/
kmem_cache_node = bootstrap(&boot_kmem_cache_node);
/* Now we can use the kmem_cache to allocate kmalloc slabs */
create_kmalloc_caches(0);
#ifdef CONFIG_SMP
register_cpu_notifier(&slab_notifier);
#endif
printk(KERN_INFO
"SLUB: HWalign=%d, Order=%d-%d, MinObjects=%d,"
" CPUs=%d, Nodes=%d\n",
cache_line_size(),
slub_min_order, slub_max_order, slub_min_objects,
nr_cpu_ids, nr_node_ids);
}
void __init kmem_cache_init_late(void)
{
}
/*
* Find a mergeable slab cache
*/
static int slab_unmergeable(struct kmem_cache *s)
{
if (slub_nomerge || (s->flags & SLUB_NEVER_MERGE))
return 1;
if (s->ctor)
return 1;
/*
* We may have set a slab to be unmergeable during bootstrap.
*/
if (s->refcount < 0)
return 1;
return 0;
}
static struct kmem_cache *find_mergeable(struct mem_cgroup *memcg, size_t size,
size_t align, unsigned long flags, const char *name,
void (*ctor)(void *))
{
struct kmem_cache *s;
if (slub_nomerge || (flags & SLUB_NEVER_MERGE))
return NULL;
if (ctor)
return NULL;
size = ALIGN(size, sizeof(void *));
align = calculate_alignment(flags, align, size);
size = ALIGN(size, align);
flags = kmem_cache_flags(size, flags, name, NULL);
list_for_each_entry(s, &slab_caches, list) {
if (slab_unmergeable(s))
continue;
if (size > s->size)
continue;
if ((flags & SLUB_MERGE_SAME) != (s->flags & SLUB_MERGE_SAME))
continue;
/*
* Check if alignment is compatible.
* Courtesy of Adrian Drzewiecki
*/
if ((s->size & ~(align - 1)) != s->size)
continue;
if (s->size - size >= sizeof(void *))
continue;
if (!cache_match_memcg(s, memcg))
continue;
return s;
}
return NULL;
}
struct kmem_cache *
__kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
size_t align, unsigned long flags, void (*ctor)(void *))
{
struct kmem_cache *s;
s = find_mergeable(memcg, size, align, flags, name, ctor);
if (s) {
s->refcount++;
/*
* Adjust the object sizes so that we clear
* the complete object on kzalloc.
*/
s->object_size = max(s->object_size, (int)size);
s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
if (sysfs_slab_alias(s, name)) {
s->refcount--;
s = NULL;
}
}
return s;
}
int __kmem_cache_create(struct kmem_cache *s, unsigned long flags)
{
int err;
err = kmem_cache_open(s, flags);
if (err)
return err;
/* Mutex is not taken during early boot */
if (slab_state <= UP)
return 0;
memcg_propagate_slab_attrs(s);
mutex_unlock(&slab_mutex);
err = sysfs_slab_add(s);
mutex_lock(&slab_mutex);
if (err)
kmem_cache_close(s);
return err;
}
#ifdef CONFIG_SMP
/*
* Use the cpu notifier to insure that the cpu slabs are flushed when
* necessary.
*/
static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
unsigned long action, void *hcpu)
{
long cpu = (long)hcpu;
struct kmem_cache *s;
unsigned long flags;
switch (action) {
case CPU_UP_CANCELED:
case CPU_UP_CANCELED_FROZEN:
case CPU_DEAD:
case CPU_DEAD_FROZEN:
mutex_lock(&slab_mutex);
list_for_each_entry(s, &slab_caches, list) {
local_irq_save(flags);
__flush_cpu_slab(s, cpu);
local_irq_restore(flags);
}
mutex_unlock(&slab_mutex);
break;
default:
break;
}
return NOTIFY_OK;
}
static struct notifier_block __cpuinitdata slab_notifier = {
.notifier_call = slab_cpuup_callback
};
#endif
void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller)
{
struct kmem_cache *s;
void *ret;
if (unlikely(size > KMALLOC_MAX_CACHE_SIZE))
return kmalloc_large(size, gfpflags);
s = kmalloc_slab(size, gfpflags);
if (unlikely(ZERO_OR_NULL_PTR(s)))
return s;
ret = slab_alloc(s, gfpflags, caller);
/* Honor the call site pointer we received. */
trace_kmalloc(caller, ret, size, s->size, gfpflags);
return ret;
}
#ifdef CONFIG_NUMA
void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
int node, unsigned long caller)
{
struct kmem_cache *s;
void *ret;
if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) {
ret = kmalloc_large_node(size, gfpflags, node);
trace_kmalloc_node(caller, ret,
size, PAGE_SIZE << get_order(size),
gfpflags, node);
return ret;
}
s = kmalloc_slab(size, gfpflags);
if (unlikely(ZERO_OR_NULL_PTR(s)))
return s;
ret = slab_alloc_node(s, gfpflags, node, caller);
/* Honor the call site pointer we received. */
trace_kmalloc_node(caller, ret, size, s->size, gfpflags, node);
return ret;
}
#endif
#ifdef CONFIG_SYSFS
static int count_inuse(struct page *page)
{
return page->inuse;
}
static int count_total(struct page *page)
{
return page->objects;
}
#endif
#ifdef CONFIG_SLUB_DEBUG
static int validate_slab(struct kmem_cache *s, struct page *page,
unsigned long *map)
{
void *p;
void *addr = page_address(page);
if (!check_slab(s, page) ||
!on_freelist(s, page, NULL))
return 0;
/* Now we know that a valid freelist exists */
bitmap_zero(map, page->objects);
get_map(s, page, map);
for_each_object(p, s, addr, page->objects) {
if (test_bit(slab_index(p, s, addr), map))
if (!check_object(s, page, p, SLUB_RED_INACTIVE))
return 0;
}
for_each_object(p, s, addr, page->objects)
if (!test_bit(slab_index(p, s, addr), map))
if (!check_object(s, page, p, SLUB_RED_ACTIVE))
return 0;
return 1;
}
static void validate_slab_slab(struct kmem_cache *s, struct page *page,
unsigned long *map)
{
slab_lock(page);
validate_slab(s, page, map);
slab_unlock(page);
}
static int validate_slab_node(struct kmem_cache *s,
struct kmem_cache_node *n, unsigned long *map)
{
unsigned long count = 0;
struct page *page;
unsigned long flags;
spin_lock_irqsave(&n->list_lock, flags);
list_for_each_entry(page, &n->partial, lru) {
validate_slab_slab(s, page, map);
count++;
}
if (count != n->nr_partial)
printk(KERN_ERR "SLUB %s: %ld partial slabs counted but "
"counter=%ld\n", s->name, count, n->nr_partial);
if (!(s->flags & SLAB_STORE_USER))
goto out;
list_for_each_entry(page, &n->full, lru) {
validate_slab_slab(s, page, map);
count++;
}
if (count != atomic_long_read(&n->nr_slabs))
printk(KERN_ERR "SLUB: %s %ld slabs counted but "
"counter=%ld\n", s->name, count,
atomic_long_read(&n->nr_slabs));
out:
spin_unlock_irqrestore(&n->list_lock, flags);
return count;
}
static long validate_slab_cache(struct kmem_cache *s)
{
int node;
unsigned long count = 0;
unsigned long *map = kmalloc(BITS_TO_LONGS(oo_objects(s->max)) *
sizeof(unsigned long), GFP_KERNEL);
if (!map)
return -ENOMEM;
flush_all(s);
for_each_node_state(node, N_NORMAL_MEMORY) {
struct kmem_cache_node *n = get_node(s, node);
count += validate_slab_node(s, n, map);
}
kfree(map);
return count;
}
/*
* Generate lists of code addresses where slabcache objects are allocated
* and freed.
*/
struct location {
unsigned long count;
unsigned long addr;
long long sum_time;
long min_time;
long max_time;
long min_pid;
long max_pid;
DECLARE_BITMAP(cpus, NR_CPUS);
nodemask_t nodes;
};
struct loc_track {
unsigned long max;
unsigned long count;
struct location *loc;
};
static void free_loc_track(struct loc_track *t)
{
if (t->max)
free_pages((unsigned long)t->loc,
get_order(sizeof(struct location) * t->max));
}
static int alloc_loc_track(struct loc_track *t, unsigned long max, gfp_t flags)
{
struct location *l;
int order;
order = get_order(sizeof(struct location) * max);
l = (void *)__get_free_pages(flags, order);
if (!l)
return 0;
if (t->count) {
memcpy(l, t->loc, sizeof(struct location) * t->count);
free_loc_track(t);
}
t->max = max;
t->loc = l;
return 1;
}
static int add_location(struct loc_track *t, struct kmem_cache *s,
const struct track *track)
{
long start, end, pos;
struct location *l;
unsigned long caddr;
unsigned long age = jiffies - track->when;
start = -1;
end = t->count;
for ( ; ; ) {
pos = start + (end - start + 1) / 2;
/*
* There is nothing at "end". If we end up there
* we need to add something to before end.
*/
if (pos == end)
break;
caddr = t->loc[pos].addr;
if (track->addr == caddr) {
l = &t->loc[pos];
l->count++;
if (track->when) {
l->sum_time += age;
if (age < l->min_time)
l->min_time = age;
if (age > l->max_time)
l->max_time = age;
if (track->pid < l->min_pid)
l->min_pid = track->pid;
if (track->pid > l->max_pid)
l->max_pid = track->pid;
cpumask_set_cpu(track->cpu,
to_cpumask(l->cpus));
}
node_set(page_to_nid(virt_to_page(track)), l->nodes);
return 1;
}
if (track->addr < caddr)
end = pos;
else
start = pos;
}
/*
* Not found. Insert new tracking element.
*/
if (t->count >= t->max && !alloc_loc_track(t, 2 * t->max, GFP_ATOMIC))
return 0;
l = t->loc + pos;
if (pos < t->count)
memmove(l + 1, l,
(t->count - pos) * sizeof(struct location));
t->count++;
l->count = 1;
l->addr = track->addr;
l->sum_time = age;
l->min_time = age;
l->max_time = age;
l->min_pid = track->pid;
l->max_pid = track->pid;
cpumask_clear(to_cpumask(l->cpus));
cpumask_set_cpu(track->cpu, to_cpumask(l->cpus));
nodes_clear(l->nodes);
node_set(page_to_nid(virt_to_page(track)), l->nodes);
return 1;
}
static void process_slab(struct loc_track *t, struct kmem_cache *s,
struct page *page, enum track_item alloc,
unsigned long *map)
{
void *addr = page_address(page);
void *p;
bitmap_zero(map, page->objects);
get_map(s, page, map);
for_each_object(p, s, addr, page->objects)
if (!test_bit(slab_index(p, s, addr), map))
add_location(t, s, get_track(s, p, alloc));
}
static int list_locations(struct kmem_cache *s, char *buf,
enum track_item alloc)
{
int len = 0;
unsigned long i;
struct loc_track t = { 0, 0, NULL };
int node;
unsigned long *map = kmalloc(BITS_TO_LONGS(oo_objects(s->max)) *
sizeof(unsigned long), GFP_KERNEL);
if (!map || !alloc_loc_track(&t, PAGE_SIZE / sizeof(struct location),
GFP_TEMPORARY)) {
kfree(map);
return sprintf(buf, "Out of memory\n");
}
/* Push back cpu slabs */
flush_all(s);
for_each_node_state(node, N_NORMAL_MEMORY) {
struct kmem_cache_node *n = get_node(s, node);
unsigned long flags;
struct page *page;
if (!atomic_long_read(&n->nr_slabs))
continue;
spin_lock_irqsave(&n->list_lock, flags);
list_for_each_entry(page, &n->partial, lru)
process_slab(&t, s, page, alloc, map);
list_for_each_entry(page, &n->full, lru)
process_slab(&t, s, page, alloc, map);
spin_unlock_irqrestore(&n->list_lock, flags);
}
for (i = 0; i < t.count; i++) {
struct location *l = &t.loc[i];
if (len > PAGE_SIZE - KSYM_SYMBOL_LEN - 100)
break;
len += sprintf(buf + len, "%7ld ", l->count);
if (l->addr)
len += sprintf(buf + len, "%pS", (void *)l->addr);
else
len += sprintf(buf + len, "<not-available>");
if (l->sum_time != l->min_time) {
len += sprintf(buf + len, " age=%ld/%ld/%ld",
l->min_time,
(long)div_u64(l->sum_time, l->count),
l->max_time);
} else
len += sprintf(buf + len, " age=%ld",
l->min_time);
if (l->min_pid != l->max_pid)
len += sprintf(buf + len, " pid=%ld-%ld",
l->min_pid, l->max_pid);
else
len += sprintf(buf + len, " pid=%ld",
l->min_pid);
if (num_online_cpus() > 1 &&
!cpumask_empty(to_cpumask(l->cpus)) &&
len < PAGE_SIZE - 60) {
len += sprintf(buf + len, " cpus=");
len += cpulist_scnprintf(buf + len, PAGE_SIZE - len - 50,
to_cpumask(l->cpus));
}
if (nr_online_nodes > 1 && !nodes_empty(l->nodes) &&
len < PAGE_SIZE - 60) {
len += sprintf(buf + len, " nodes=");
len += nodelist_scnprintf(buf + len, PAGE_SIZE - len - 50,
l->nodes);
}
len += sprintf(buf + len, "\n");
}
free_loc_track(&t);
kfree(map);
if (!t.count)
len += sprintf(buf, "No data\n");
return len;
}
#endif
#ifdef SLUB_RESILIENCY_TEST
static void resiliency_test(void)
{
u8 *p;
BUILD_BUG_ON(KMALLOC_MIN_SIZE > 16 || KMALLOC_SHIFT_HIGH < 10);
printk(KERN_ERR "SLUB resiliency testing\n");
printk(KERN_ERR "-----------------------\n");
printk(KERN_ERR "A. Corruption after allocation\n");
p = kzalloc(16, GFP_KERNEL);
p[16] = 0x12;
printk(KERN_ERR "\n1. kmalloc-16: Clobber Redzone/next pointer"
" 0x12->0x%p\n\n", p + 16);
validate_slab_cache(kmalloc_caches[4]);
/* Hmmm... The next two are dangerous */
p = kzalloc(32, GFP_KERNEL);
p[32 + sizeof(void *)] = 0x34;
printk(KERN_ERR "\n2. kmalloc-32: Clobber next pointer/next slab"
" 0x34 -> -0x%p\n", p);
printk(KERN_ERR
"If allocated object is overwritten then not detectable\n\n");
validate_slab_cache(kmalloc_caches[5]);
p = kzalloc(64, GFP_KERNEL);
p += 64 + (get_cycles() & 0xff) * sizeof(void *);
*p = 0x56;
printk(KERN_ERR "\n3. kmalloc-64: corrupting random byte 0x56->0x%p\n",
p);
printk(KERN_ERR
"If allocated object is overwritten then not detectable\n\n");
validate_slab_cache(kmalloc_caches[6]);
printk(KERN_ERR "\nB. Corruption after free\n");
p = kzalloc(128, GFP_KERNEL);
kfree(p);
*p = 0x78;
printk(KERN_ERR "1. kmalloc-128: Clobber first word 0x78->0x%p\n\n", p);
validate_slab_cache(kmalloc_caches[7]);
p = kzalloc(256, GFP_KERNEL);
kfree(p);
p[50] = 0x9a;
printk(KERN_ERR "\n2. kmalloc-256: Clobber 50th byte 0x9a->0x%p\n\n",
p);
validate_slab_cache(kmalloc_caches[8]);
p = kzalloc(512, GFP_KERNEL);
kfree(p);
p[512] = 0xab;
printk(KERN_ERR "\n3. kmalloc-512: Clobber redzone 0xab->0x%p\n\n", p);
validate_slab_cache(kmalloc_caches[9]);
}
#else
#ifdef CONFIG_SYSFS
static void resiliency_test(void) {};
#endif
#endif
#ifdef CONFIG_SYSFS
enum slab_stat_type {
SL_ALL, /* All slabs */
SL_PARTIAL, /* Only partially allocated slabs */
SL_CPU, /* Only slabs used for cpu caches */
SL_OBJECTS, /* Determine allocated objects not slabs */
SL_TOTAL /* Determine object capacity not slabs */
};
#define SO_ALL (1 << SL_ALL)
#define SO_PARTIAL (1 << SL_PARTIAL)
#define SO_CPU (1 << SL_CPU)
#define SO_OBJECTS (1 << SL_OBJECTS)
#define SO_TOTAL (1 << SL_TOTAL)
static ssize_t show_slab_objects(struct kmem_cache *s,
char *buf, unsigned long flags)
{
unsigned long total = 0;
int node;
int x;
unsigned long *nodes;
unsigned long *per_cpu;
nodes = kzalloc(2 * sizeof(unsigned long) * nr_node_ids, GFP_KERNEL);
if (!nodes)
return -ENOMEM;
per_cpu = nodes + nr_node_ids;
if (flags & SO_CPU) {
int cpu;
for_each_possible_cpu(cpu) {
struct kmem_cache_cpu *c = per_cpu_ptr(s->cpu_slab, cpu);
int node;
struct page *page;
page = ACCESS_ONCE(c->page);
if (!page)
continue;
node = page_to_nid(page);
if (flags & SO_TOTAL)
x = page->objects;
else if (flags & SO_OBJECTS)
x = page->inuse;
else
x = 1;
total += x;
nodes[node] += x;
page = ACCESS_ONCE(c->partial);
if (page) {
node = page_to_nid(page);
if (flags & SO_TOTAL)
WARN_ON_ONCE(1);
else if (flags & SO_OBJECTS)
WARN_ON_ONCE(1);
else
x = page->pages;
total += x;
nodes[node] += x;
}
per_cpu[node]++;
}
}
lock_memory_hotplug();
#ifdef CONFIG_SLUB_DEBUG
if (flags & SO_ALL) {
for_each_node_state(node, N_NORMAL_MEMORY) {
struct kmem_cache_node *n = get_node(s, node);
if (flags & SO_TOTAL)
x = atomic_long_read(&n->total_objects);
else if (flags & SO_OBJECTS)
x = atomic_long_read(&n->total_objects) -
count_partial(n, count_free);
else
x = atomic_long_read(&n->nr_slabs);
total += x;
nodes[node] += x;
}
} else
#endif
if (flags & SO_PARTIAL) {
for_each_node_state(node, N_NORMAL_MEMORY) {
struct kmem_cache_node *n = get_node(s, node);
if (flags & SO_TOTAL)
x = count_partial(n, count_total);
else if (flags & SO_OBJECTS)
x = count_partial(n, count_inuse);
else
x = n->nr_partial;
total += x;
nodes[node] += x;
}
}
x = sprintf(buf, "%lu", total);
#ifdef CONFIG_NUMA
for_each_node_state(node, N_NORMAL_MEMORY)
if (nodes[node])
x += sprintf(buf + x, " N%d=%lu",
node, nodes[node]);
#endif
unlock_memory_hotplug();
kfree(nodes);
return x + sprintf(buf + x, "\n");
}
#ifdef CONFIG_SLUB_DEBUG
static int any_slab_objects(struct kmem_cache *s)
{
int node;
for_each_online_node(node) {
struct kmem_cache_node *n = get_node(s, node);
if (!n)
continue;
if (atomic_long_read(&n->total_objects))
return 1;
}
return 0;
}
#endif
#define to_slab_attr(n) container_of(n, struct slab_attribute, attr)
#define to_slab(n) container_of(n, struct kmem_cache, kobj)
struct slab_attribute {
struct attribute attr;
ssize_t (*show)(struct kmem_cache *s, char *buf);
ssize_t (*store)(struct kmem_cache *s, const char *x, size_t count);
};
#define SLAB_ATTR_RO(_name) \
static struct slab_attribute _name##_attr = \
__ATTR(_name, 0400, _name##_show, NULL)
#define SLAB_ATTR(_name) \
static struct slab_attribute _name##_attr = \
__ATTR(_name, 0600, _name##_show, _name##_store)
static ssize_t slab_size_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", s->size);
}
SLAB_ATTR_RO(slab_size);
static ssize_t align_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", s->align);
}
SLAB_ATTR_RO(align);
static ssize_t object_size_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", s->object_size);
}
SLAB_ATTR_RO(object_size);
static ssize_t objs_per_slab_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", oo_objects(s->oo));
}
SLAB_ATTR_RO(objs_per_slab);
static ssize_t order_store(struct kmem_cache *s,
const char *buf, size_t length)
{
unsigned long order;
int err;
err = strict_strtoul(buf, 10, &order);
if (err)
return err;
if (order > slub_max_order || order < slub_min_order)
return -EINVAL;
calculate_sizes(s, order);
return length;
}
static ssize_t order_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", oo_order(s->oo));
}
SLAB_ATTR(order);
static ssize_t min_partial_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%lu\n", s->min_partial);
}
static ssize_t min_partial_store(struct kmem_cache *s, const char *buf,
size_t length)
{
unsigned long min;
int err;
err = strict_strtoul(buf, 10, &min);
if (err)
return err;
set_min_partial(s, min);
return length;
}
SLAB_ATTR(min_partial);
static ssize_t cpu_partial_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%u\n", s->cpu_partial);
}
static ssize_t cpu_partial_store(struct kmem_cache *s, const char *buf,
size_t length)
{
unsigned long objects;
int err;
err = strict_strtoul(buf, 10, &objects);
if (err)
return err;
if (objects && kmem_cache_debug(s))
return -EINVAL;
s->cpu_partial = objects;
flush_all(s);
return length;
}
SLAB_ATTR(cpu_partial);
static ssize_t ctor_show(struct kmem_cache *s, char *buf)
{
if (!s->ctor)
return 0;
return sprintf(buf, "%pS\n", s->ctor);
}
SLAB_ATTR_RO(ctor);
static ssize_t aliases_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", s->refcount - 1);
}
SLAB_ATTR_RO(aliases);
static ssize_t partial_show(struct kmem_cache *s, char *buf)
{
return show_slab_objects(s, buf, SO_PARTIAL);
}
SLAB_ATTR_RO(partial);
static ssize_t cpu_slabs_show(struct kmem_cache *s, char *buf)
{
return show_slab_objects(s, buf, SO_CPU);
}
SLAB_ATTR_RO(cpu_slabs);
static ssize_t objects_show(struct kmem_cache *s, char *buf)
{
return show_slab_objects(s, buf, SO_ALL|SO_OBJECTS);
}
SLAB_ATTR_RO(objects);
static ssize_t objects_partial_show(struct kmem_cache *s, char *buf)
{
return show_slab_objects(s, buf, SO_PARTIAL|SO_OBJECTS);
}
SLAB_ATTR_RO(objects_partial);
static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)
{
int objects = 0;
int pages = 0;
int cpu;
int len;
for_each_online_cpu(cpu) {
struct page *page = per_cpu_ptr(s->cpu_slab, cpu)->partial;
if (page) {
pages += page->pages;
objects += page->pobjects;
}
}
len = sprintf(buf, "%d(%d)", objects, pages);
#ifdef CONFIG_SMP
for_each_online_cpu(cpu) {
struct page *page = per_cpu_ptr(s->cpu_slab, cpu) ->partial;
if (page && len < PAGE_SIZE - 20)
len += sprintf(buf + len, " C%d=%d(%d)", cpu,
page->pobjects, page->pages);
}
#endif
return len + sprintf(buf + len, "\n");
}
SLAB_ATTR_RO(slabs_cpu_partial);
static ssize_t reclaim_account_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_RECLAIM_ACCOUNT));
}
static ssize_t reclaim_account_store(struct kmem_cache *s,
const char *buf, size_t length)
{
s->flags &= ~SLAB_RECLAIM_ACCOUNT;
if (buf[0] == '1')
s->flags |= SLAB_RECLAIM_ACCOUNT;
return length;
}
SLAB_ATTR(reclaim_account);
static ssize_t hwcache_align_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_HWCACHE_ALIGN));
}
SLAB_ATTR_RO(hwcache_align);
#ifdef CONFIG_ZONE_DMA
static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_CACHE_DMA));
}
SLAB_ATTR_RO(cache_dma);
#endif
static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
}
SLAB_ATTR_RO(destroy_by_rcu);
static ssize_t reserved_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", s->reserved);
}
SLAB_ATTR_RO(reserved);
#ifdef CONFIG_SLUB_DEBUG
static ssize_t slabs_show(struct kmem_cache *s, char *buf)
{
return show_slab_objects(s, buf, SO_ALL);
}
SLAB_ATTR_RO(slabs);
static ssize_t total_objects_show(struct kmem_cache *s, char *buf)
{
return show_slab_objects(s, buf, SO_ALL|SO_TOTAL);
}
SLAB_ATTR_RO(total_objects);
static ssize_t sanity_checks_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_DEBUG_FREE));
}
static ssize_t sanity_checks_store(struct kmem_cache *s,
const char *buf, size_t length)
{
s->flags &= ~SLAB_DEBUG_FREE;
if (buf[0] == '1') {
s->flags &= ~__CMPXCHG_DOUBLE;
s->flags |= SLAB_DEBUG_FREE;
}
return length;
}
SLAB_ATTR(sanity_checks);
static ssize_t trace_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_TRACE));
}
static ssize_t trace_store(struct kmem_cache *s, const char *buf,
size_t length)
{
s->flags &= ~SLAB_TRACE;
if (buf[0] == '1') {
s->flags &= ~__CMPXCHG_DOUBLE;
s->flags |= SLAB_TRACE;
}
return length;
}
SLAB_ATTR(trace);
static ssize_t red_zone_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_RED_ZONE));
}
static ssize_t red_zone_store(struct kmem_cache *s,
const char *buf, size_t length)
{
if (any_slab_objects(s))
return -EBUSY;
s->flags &= ~SLAB_RED_ZONE;
if (buf[0] == '1') {
s->flags &= ~__CMPXCHG_DOUBLE;
s->flags |= SLAB_RED_ZONE;
}
calculate_sizes(s, -1);
return length;
}
SLAB_ATTR(red_zone);
static ssize_t poison_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_POISON));
}
static ssize_t poison_store(struct kmem_cache *s,
const char *buf, size_t length)
{
if (any_slab_objects(s))
return -EBUSY;
s->flags &= ~SLAB_POISON;
if (buf[0] == '1') {
s->flags &= ~__CMPXCHG_DOUBLE;
s->flags |= SLAB_POISON;
}
calculate_sizes(s, -1);
return length;
}
SLAB_ATTR(poison);
static ssize_t store_user_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_STORE_USER));
}
static ssize_t store_user_store(struct kmem_cache *s,
const char *buf, size_t length)
{
if (any_slab_objects(s))
return -EBUSY;
s->flags &= ~SLAB_STORE_USER;
if (buf[0] == '1') {
s->flags &= ~__CMPXCHG_DOUBLE;
s->flags |= SLAB_STORE_USER;
}
calculate_sizes(s, -1);
return length;
}
SLAB_ATTR(store_user);
static ssize_t validate_show(struct kmem_cache *s, char *buf)
{
return 0;
}
static ssize_t validate_store(struct kmem_cache *s,
const char *buf, size_t length)
{
int ret = -EINVAL;
if (buf[0] == '1') {
ret = validate_slab_cache(s);
if (ret >= 0)
ret = length;
}
return ret;
}
SLAB_ATTR(validate);
static ssize_t alloc_calls_show(struct kmem_cache *s, char *buf)
{
if (!(s->flags & SLAB_STORE_USER))
return -ENOSYS;
return list_locations(s, buf, TRACK_ALLOC);
}
SLAB_ATTR_RO(alloc_calls);
static ssize_t free_calls_show(struct kmem_cache *s, char *buf)
{
if (!(s->flags & SLAB_STORE_USER))
return -ENOSYS;
return list_locations(s, buf, TRACK_FREE);
}
SLAB_ATTR_RO(free_calls);
#endif /* CONFIG_SLUB_DEBUG */
#ifdef CONFIG_FAILSLAB
static ssize_t failslab_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", !!(s->flags & SLAB_FAILSLAB));
}
static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
size_t length)
{
s->flags &= ~SLAB_FAILSLAB;
if (buf[0] == '1')
s->flags |= SLAB_FAILSLAB;
return length;
}
SLAB_ATTR(failslab);
#endif
static ssize_t shrink_show(struct kmem_cache *s, char *buf)
{
return 0;
}
static ssize_t shrink_store(struct kmem_cache *s,
const char *buf, size_t length)
{
if (buf[0] == '1') {
int rc = kmem_cache_shrink(s);
if (rc)
return rc;
} else
return -EINVAL;
return length;
}
SLAB_ATTR(shrink);
#ifdef CONFIG_NUMA
static ssize_t remote_node_defrag_ratio_show(struct kmem_cache *s, char *buf)
{
return sprintf(buf, "%d\n", s->remote_node_defrag_ratio / 10);
}
static ssize_t remote_node_defrag_ratio_store(struct kmem_cache *s,
const char *buf, size_t length)
{
unsigned long ratio;
int err;
err = strict_strtoul(buf, 10, &ratio);
if (err)
return err;
if (ratio <= 100)
s->remote_node_defrag_ratio = ratio * 10;
return length;
}
SLAB_ATTR(remote_node_defrag_ratio);
#endif
#ifdef CONFIG_SLUB_STATS
static int show_stat(struct kmem_cache *s, char *buf, enum stat_item si)
{
unsigned long sum = 0;
int cpu;
int len;
int *data = kmalloc(nr_cpu_ids * sizeof(int), GFP_KERNEL);
if (!data)
return -ENOMEM;
for_each_online_cpu(cpu) {
unsigned x = per_cpu_ptr(s->cpu_slab, cpu)->stat[si];
data[cpu] = x;
sum += x;
}
len = sprintf(buf, "%lu", sum);
#ifdef CONFIG_SMP
for_each_online_cpu(cpu) {
if (data[cpu] && len < PAGE_SIZE - 20)
len += sprintf(buf + len, " C%d=%u", cpu, data[cpu]);
}
#endif
kfree(data);
return len + sprintf(buf + len, "\n");
}
static void clear_stat(struct kmem_cache *s, enum stat_item si)
{
int cpu;
for_each_online_cpu(cpu)
per_cpu_ptr(s->cpu_slab, cpu)->stat[si] = 0;
}
#define STAT_ATTR(si, text) \
static ssize_t text##_show(struct kmem_cache *s, char *buf) \
{ \
return show_stat(s, buf, si); \
} \
static ssize_t text##_store(struct kmem_cache *s, \
const char *buf, size_t length) \
{ \
if (buf[0] != '0') \
return -EINVAL; \
clear_stat(s, si); \
return length; \
} \
SLAB_ATTR(text); \
STAT_ATTR(ALLOC_FASTPATH, alloc_fastpath);
STAT_ATTR(ALLOC_SLOWPATH, alloc_slowpath);
STAT_ATTR(FREE_FASTPATH, free_fastpath);
STAT_ATTR(FREE_SLOWPATH, free_slowpath);
STAT_ATTR(FREE_FROZEN, free_frozen);
STAT_ATTR(FREE_ADD_PARTIAL, free_add_partial);
STAT_ATTR(FREE_REMOVE_PARTIAL, free_remove_partial);
STAT_ATTR(ALLOC_FROM_PARTIAL, alloc_from_partial);
STAT_ATTR(ALLOC_SLAB, alloc_slab);
STAT_ATTR(ALLOC_REFILL, alloc_refill);
STAT_ATTR(ALLOC_NODE_MISMATCH, alloc_node_mismatch);
STAT_ATTR(FREE_SLAB, free_slab);
STAT_ATTR(CPUSLAB_FLUSH, cpuslab_flush);
STAT_ATTR(DEACTIVATE_FULL, deactivate_full);
STAT_ATTR(DEACTIVATE_EMPTY, deactivate_empty);
STAT_ATTR(DEACTIVATE_TO_HEAD, deactivate_to_head);
STAT_ATTR(DEACTIVATE_TO_TAIL, deactivate_to_tail);
STAT_ATTR(DEACTIVATE_REMOTE_FREES, deactivate_remote_frees);
STAT_ATTR(DEACTIVATE_BYPASS, deactivate_bypass);
STAT_ATTR(ORDER_FALLBACK, order_fallback);
STAT_ATTR(CMPXCHG_DOUBLE_CPU_FAIL, cmpxchg_double_cpu_fail);
STAT_ATTR(CMPXCHG_DOUBLE_FAIL, cmpxchg_double_fail);
STAT_ATTR(CPU_PARTIAL_ALLOC, cpu_partial_alloc);
STAT_ATTR(CPU_PARTIAL_FREE, cpu_partial_free);
STAT_ATTR(CPU_PARTIAL_NODE, cpu_partial_node);
STAT_ATTR(CPU_PARTIAL_DRAIN, cpu_partial_drain);
#endif
static struct attribute *slab_attrs[] = {
&slab_size_attr.attr,
&object_size_attr.attr,
&objs_per_slab_attr.attr,
&order_attr.attr,
&min_partial_attr.attr,
&cpu_partial_attr.attr,
&objects_attr.attr,
&objects_partial_attr.attr,
&partial_attr.attr,
&cpu_slabs_attr.attr,
&ctor_attr.attr,
&aliases_attr.attr,
&align_attr.attr,
&hwcache_align_attr.attr,
&reclaim_account_attr.attr,
&destroy_by_rcu_attr.attr,
&shrink_attr.attr,
&reserved_attr.attr,
&slabs_cpu_partial_attr.attr,
#ifdef CONFIG_SLUB_DEBUG
&total_objects_attr.attr,
&slabs_attr.attr,
&sanity_checks_attr.attr,
&trace_attr.attr,
&red_zone_attr.attr,
&poison_attr.attr,
&store_user_attr.attr,
&validate_attr.attr,
&alloc_calls_attr.attr,
&free_calls_attr.attr,
#endif
#ifdef CONFIG_ZONE_DMA
&cache_dma_attr.attr,
#endif
#ifdef CONFIG_NUMA
&remote_node_defrag_ratio_attr.attr,
#endif
#ifdef CONFIG_SLUB_STATS
&alloc_fastpath_attr.attr,
&alloc_slowpath_attr.attr,
&free_fastpath_attr.attr,
&free_slowpath_attr.attr,
&free_frozen_attr.attr,
&free_add_partial_attr.attr,
&free_remove_partial_attr.attr,
&alloc_from_partial_attr.attr,
&alloc_slab_attr.attr,
&alloc_refill_attr.attr,
&alloc_node_mismatch_attr.attr,
&free_slab_attr.attr,
&cpuslab_flush_attr.attr,
&deactivate_full_attr.attr,
&deactivate_empty_attr.attr,
&deactivate_to_head_attr.attr,
&deactivate_to_tail_attr.attr,
&deactivate_remote_frees_attr.attr,
&deactivate_bypass_attr.attr,
&order_fallback_attr.attr,
&cmpxchg_double_fail_attr.attr,
&cmpxchg_double_cpu_fail_attr.attr,
&cpu_partial_alloc_attr.attr,
&cpu_partial_free_attr.attr,
&cpu_partial_node_attr.attr,
&cpu_partial_drain_attr.attr,
#endif
#ifdef CONFIG_FAILSLAB
&failslab_attr.attr,
#endif
NULL
};
static struct attribute_group slab_attr_group = {
.attrs = slab_attrs,
};
static ssize_t slab_attr_show(struct kobject *kobj,
struct attribute *attr,
char *buf)
{
struct slab_attribute *attribute;
struct kmem_cache *s;
int err;
attribute = to_slab_attr(attr);
s = to_slab(kobj);
if (!attribute->show)
return -EIO;
err = attribute->show(s, buf);
return err;
}
static ssize_t slab_attr_store(struct kobject *kobj,
struct attribute *attr,
const char *buf, size_t len)
{
struct slab_attribute *attribute;
struct kmem_cache *s;
int err;
attribute = to_slab_attr(attr);
s = to_slab(kobj);
if (!attribute->store)
return -EIO;
err = attribute->store(s, buf, len);
#ifdef CONFIG_MEMCG_KMEM
if (slab_state >= FULL && err >= 0 && is_root_cache(s)) {
int i;
mutex_lock(&slab_mutex);
if (s->max_attr_size < len)
s->max_attr_size = len;
/*
* This is a best effort propagation, so this function's return
* value will be determined by the parent cache only. This is
* basically because not all attributes will have a well
* defined semantics for rollbacks - most of the actions will
* have permanent effects.
*
* Returning the error value of any of the children that fail
* is not 100 % defined, in the sense that users seeing the
* error code won't be able to know anything about the state of
* the cache.
*
* Only returning the error code for the parent cache at least
* has well defined semantics. The cache being written to
* directly either failed or succeeded, in which case we loop
* through the descendants with best-effort propagation.
*/
for_each_memcg_cache_index(i) {
struct kmem_cache *c = cache_from_memcg(s, i);
if (c)
attribute->store(c, buf, len);
}
mutex_unlock(&slab_mutex);
}
#endif
return err;
}
static void memcg_propagate_slab_attrs(struct kmem_cache *s)
{
#ifdef CONFIG_MEMCG_KMEM
int i;
char *buffer = NULL;
if (!is_root_cache(s))
return;
/*
* This mean this cache had no attribute written. Therefore, no point
* in copying default values around
*/
if (!s->max_attr_size)
return;
for (i = 0; i < ARRAY_SIZE(slab_attrs); i++) {
char mbuf[64];
char *buf;
struct slab_attribute *attr = to_slab_attr(slab_attrs[i]);
if (!attr || !attr->store || !attr->show)
continue;
/*
* It is really bad that we have to allocate here, so we will
* do it only as a fallback. If we actually allocate, though,
* we can just use the allocated buffer until the end.
*
* Most of the slub attributes will tend to be very small in
* size, but sysfs allows buffers up to a page, so they can
* theoretically happen.
*/
if (buffer)
buf = buffer;
else if (s->max_attr_size < ARRAY_SIZE(mbuf))
buf = mbuf;
else {
buffer = (char *) get_zeroed_page(GFP_KERNEL);
if (WARN_ON(!buffer))
continue;
buf = buffer;
}
attr->show(s->memcg_params->root_cache, buf);
attr->store(s, buf, strlen(buf));
}
if (buffer)
free_page((unsigned long)buffer);
#endif
}
static const struct sysfs_ops slab_sysfs_ops = {
.show = slab_attr_show,
.store = slab_attr_store,
};
static struct kobj_type slab_ktype = {
.sysfs_ops = &slab_sysfs_ops,
};
static int uevent_filter(struct kset *kset, struct kobject *kobj)
{
struct kobj_type *ktype = get_ktype(kobj);
if (ktype == &slab_ktype)
return 1;
return 0;
}
static const struct kset_uevent_ops slab_uevent_ops = {
.filter = uevent_filter,
};
static struct kset *slab_kset;
#define ID_STR_LENGTH 64
/* Create a unique string id for a slab cache:
*
* Format :[flags-]size
*/
static char *create_unique_id(struct kmem_cache *s)
{
char *name = kmalloc(ID_STR_LENGTH, GFP_KERNEL);
char *p = name;
BUG_ON(!name);
*p++ = ':';
/*
* First flags affecting slabcache operations. We will only
* get here for aliasable slabs so we do not need to support
* too many flags. The flags here must cover all flags that
* are matched during merging to guarantee that the id is
* unique.
*/
if (s->flags & SLAB_CACHE_DMA)
*p++ = 'd';
if (s->flags & SLAB_RECLAIM_ACCOUNT)
*p++ = 'a';
if (s->flags & SLAB_DEBUG_FREE)
*p++ = 'F';
if (!(s->flags & SLAB_NOTRACK))
*p++ = 't';
if (p != name + 1)
*p++ = '-';
p += sprintf(p, "%07d", s->size);
#ifdef CONFIG_MEMCG_KMEM
if (!is_root_cache(s))
p += sprintf(p, "-%08d", memcg_cache_id(s->memcg_params->memcg));
#endif
BUG_ON(p > name + ID_STR_LENGTH - 1);
return name;
}
static int sysfs_slab_add(struct kmem_cache *s)
{
int err;
const char *name;
int unmergeable = slab_unmergeable(s);
if (unmergeable) {
/*
* Slabcache can never be merged so we can use the name proper.
* This is typically the case for debug situations. In that
* case we can catch duplicate names easily.
*/
sysfs_remove_link(&slab_kset->kobj, s->name);
name = s->name;
} else {
/*
* Create a unique name for the slab as a target
* for the symlinks.
*/
name = create_unique_id(s);
}
s->kobj.kset = slab_kset;
err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
if (err) {
kobject_put(&s->kobj);
return err;
}
err = sysfs_create_group(&s->kobj, &slab_attr_group);
if (err) {
kobject_del(&s->kobj);
kobject_put(&s->kobj);
return err;
}
kobject_uevent(&s->kobj, KOBJ_ADD);
if (!unmergeable) {
/* Setup first alias */
sysfs_slab_alias(s, s->name);
kfree(name);
}
return 0;
}
static void sysfs_slab_remove(struct kmem_cache *s)
{
if (slab_state < FULL)
/*
* Sysfs has not been setup yet so no need to remove the
* cache from sysfs.
*/
return;
kobject_uevent(&s->kobj, KOBJ_REMOVE);
kobject_del(&s->kobj);
kobject_put(&s->kobj);
}
/*
* Need to buffer aliases during bootup until sysfs becomes
* available lest we lose that information.
*/
struct saved_alias {
struct kmem_cache *s;
const char *name;
struct saved_alias *next;
};
static struct saved_alias *alias_list;
static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
{
struct saved_alias *al;
if (slab_state == FULL) {
/*
* If we have a leftover link then remove it.
*/
sysfs_remove_link(&slab_kset->kobj, name);
return sysfs_create_link(&slab_kset->kobj, &s->kobj, name);
}
al = kmalloc(sizeof(struct saved_alias), GFP_KERNEL);
if (!al)
return -ENOMEM;
al->s = s;
al->name = name;
al->next = alias_list;
alias_list = al;
return 0;
}
static int __init slab_sysfs_init(void)
{
struct kmem_cache *s;
int err;
mutex_lock(&slab_mutex);
slab_kset = kset_create_and_add("slab", &slab_uevent_ops, kernel_kobj);
if (!slab_kset) {
mutex_unlock(&slab_mutex);
printk(KERN_ERR "Cannot register slab subsystem.\n");
return -ENOSYS;
}
slab_state = FULL;
list_for_each_entry(s, &slab_caches, list) {
err = sysfs_slab_add(s);
if (err)
printk(KERN_ERR "SLUB: Unable to add boot slab %s"
" to sysfs\n", s->name);
}
while (alias_list) {
struct saved_alias *al = alias_list;
alias_list = alias_list->next;
err = sysfs_slab_alias(al->s, al->name);
if (err)
printk(KERN_ERR "SLUB: Unable to add boot slab alias"
" %s to sysfs\n", al->name);
kfree(al);
}
mutex_unlock(&slab_mutex);
resiliency_test();
return 0;
}
__initcall(slab_sysfs_init);
#endif /* CONFIG_SYSFS */
/*
* The /proc/slabinfo ABI
*/
#ifdef CONFIG_SLABINFO
void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo)
{
unsigned long nr_partials = 0;
unsigned long nr_slabs = 0;
unsigned long nr_objs = 0;
unsigned long nr_free = 0;
int node;
for_each_online_node(node) {
struct kmem_cache_node *n = get_node(s, node);
if (!n)
continue;
nr_partials += n->nr_partial;
nr_slabs += atomic_long_read(&n->nr_slabs);
nr_objs += atomic_long_read(&n->total_objects);
nr_free += count_partial(n, count_free);
}
sinfo->active_objs = nr_objs - nr_free;
sinfo->num_objs = nr_objs;
sinfo->active_slabs = nr_slabs;
sinfo->num_slabs = nr_slabs;
sinfo->objects_per_slab = oo_objects(s->oo);
sinfo->cache_order = oo_order(s->oo);
}
void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *s)
{
}
ssize_t slabinfo_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos)
{
return -EIO;
}
#endif /* CONFIG_SLABINFO */
| gpl-2.0 |
hlarsen/TBCPvP | dep/acelite/ace/Sbrk_Memory_Pool.cpp | 2 | 2986 | // $Id: Sbrk_Memory_Pool.cpp 91286 2010-08-05 09:04:31Z johnnyw $
#include "ace/OS_NS_unistd.h"
#include "ace/Sbrk_Memory_Pool.h"
#include "ace/Log_Msg.h"
#if !defined (ACE_LACKS_SBRK)
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
ACE_ALLOC_HOOK_DEFINE(ACE_Sbrk_Memory_Pool)
// Ask system for more local memory via sbrk(2).
void *
ACE_Sbrk_Memory_Pool::acquire (size_t nbytes,
size_t &rounded_bytes)
{
ACE_TRACE ("ACE_Sbrk_Memory_Pool::acquire");
rounded_bytes = this->round_up (nbytes);
// ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) acquiring more chunks, nbytes = %d, rounded_bytes = %d\n"), nbytes, rounded_bytes));
void *cp = ACE_OS::sbrk (rounded_bytes);
if (cp == MAP_FAILED)
ACE_ERROR_RETURN ((LM_ERROR,
"(%P|%t) cp = %u\n",
cp),
0);
else
// ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) acquired more chunks, nbytes = %d, rounded_bytes = %d, new break = %u\n"), nbytes, rounded_bytes, cp));
return cp;
}
/* No-op for now... */
int
ACE_Sbrk_Memory_Pool::release (int)
{
ACE_TRACE ("ACE_Sbrk_Memory_Pool::release");
return 0;
}
int
ACE_Sbrk_Memory_Pool::sync (ssize_t, int)
{
ACE_TRACE ("ACE_Sbrk_Memory_Pool::sync");
return 0;
}
int
ACE_Sbrk_Memory_Pool::sync (void *, size_t, int)
{
ACE_TRACE ("ACE_Sbrk_Memory_Pool::sync");
return 0;
}
int
ACE_Sbrk_Memory_Pool::protect (ssize_t, int)
{
ACE_TRACE ("ACE_Sbrk_Memory_Pool::protect");
return 0;
}
int
ACE_Sbrk_Memory_Pool::protect (void *, size_t, int)
{
ACE_TRACE ("ACE_Sbrk_Memory_Pool::protect");
return 0;
}
// Ask system for initial chunk of local memory.
void *
ACE_Sbrk_Memory_Pool::init_acquire (size_t nbytes,
size_t &rounded_bytes,
int &first_time)
{
ACE_TRACE ("ACE_Sbrk_Memory_Pool::init_acquire");
// Note that we assume that when ACE_Sbrk_Memory_Pool is used,
// ACE_Malloc's constructor will only get called once. If this
// assumption doesn't hold, we are in deep trouble!
first_time = 1;
return this->acquire (nbytes, rounded_bytes);
}
void
ACE_Sbrk_Memory_Pool::dump (void) const
{
#if defined (ACE_HAS_DUMP)
ACE_TRACE ("ACE_Sbrk_Memory_Pool::dump");
#endif /* ACE_HAS_DUMP */
}
ACE_Sbrk_Memory_Pool::ACE_Sbrk_Memory_Pool (const ACE_TCHAR *,
const OPTIONS *)
{
ACE_TRACE ("ACE_Sbrk_Memory_Pool::ACE_Sbrk_Memory_Pool");
}
ACE_Sbrk_Memory_Pool::~ACE_Sbrk_Memory_Pool (void)
{
}
void *
ACE_Sbrk_Memory_Pool::base_addr (void) const
{
return 0;
}
// Round up the request to a multiple of the page size.
size_t
ACE_Sbrk_Memory_Pool::round_up (size_t nbytes)
{
ACE_TRACE ("ACE_Sbrk_Memory_Pool::round_up");
return ACE::round_to_pagesize (nbytes);
}
ACE_END_VERSIONED_NAMESPACE_DECL
#endif /* !ACE_LACKS_SBRK */ | gpl-2.0 |
yanniks/android_kernel_huawei_g615 | drivers/input/keyboard/k3v2_power_key.c | 2 | 6450 | /*
* Filename:kernel/drivers/input/keyboard/k3v2_power_key.c
* Discription:realize power key in kernel.
* Copyright (C) 2011 Hisilicon
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Revision history:
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/earlysuspend.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/clk.h>
#include <linux/mux.h>
#include <asm/irq.h>
#include <mach/k3_keypad.h>
#define TRUE (1)
#define FALSE (0)
#define POWER_KEY_RELEASE (0)
#define POWER_KEY_PRESS (1)
struct k3v2_power_key {
struct input_dev *input_dev;
void __iomem *base;
int power_key_press_irq;
int power_key_release_irq;
int power_key_long_press_1s_irq;
};
static int k3v2_power_key_open(struct input_dev *dev)
{
return 0;
}
static void k3v2_power_key_close(struct input_dev *dev)
{
}
static irqreturn_t k3v2_power_key_irq_handler(int irq, void *dev_id)
{
struct k3v2_power_key *power_key = (struct k3v2_power_key *)dev_id;
switch(irq) {
case IRQ_POWER_KEY_PRESS:
printk(KERN_DEBUG "[%s]response press interrupt!\n", __FUNCTION__);
input_report_key(power_key->input_dev, KEY_POWER, POWER_KEY_PRESS);
input_sync(power_key->input_dev);
break;
case IRQ_POWER_KEY_RELEASE:
printk(KERN_DEBUG "[%s]response release interrupt!\n", __FUNCTION__);
input_report_key(power_key->input_dev, KEY_POWER, POWER_KEY_RELEASE);
input_sync(power_key->input_dev);
break;
default:
printk(KERN_ERR "[%s]invalid irq %d!\n", __FUNCTION__, irq);
break;
}
return IRQ_HANDLED;
}
static int __devinit k3v2_power_key_probe(struct platform_device* pdev)
{
struct k3v2_power_key *power_key = NULL;
struct input_dev *input_dev = NULL;
int err;
if(NULL == pdev) {
printk(KERN_ERR "[Pwrkey]parameter error!\n");
err = -EINVAL;
return err;
}
power_key = kzalloc(sizeof(struct k3v2_power_key), GFP_KERNEL);
if(!power_key) {
dev_err(&pdev->dev, "Failed to allocate struct k3v2_power_key!\n");
err = -ENOMEM;
return err;
}
input_dev = input_allocate_device();
if (!input_dev) {
dev_err(&pdev->dev, "Failed to allocate struct input_dev!\n");
err = -ENOMEM;
goto err_alloc_input_device;
}
input_dev->name = pdev->name;
input_dev->id.bustype = BUS_HOST;
input_dev->dev.parent = &pdev->dev;
input_set_drvdata(input_dev, power_key);
set_bit(EV_KEY, input_dev->evbit);
set_bit(EV_SYN, input_dev->evbit);
set_bit(KEY_POWER, input_dev->keybit);
input_dev->open = k3v2_power_key_open;
input_dev->close = k3v2_power_key_close;
power_key->input_dev = input_dev;
power_key->power_key_press_irq = platform_get_irq(pdev, 0);
if (power_key->power_key_press_irq < 0) {
dev_err(&pdev->dev, "Failed to get power key press irq!\n");
err = power_key->power_key_press_irq;
goto err_get_irq;
}
err = request_irq(power_key->power_key_press_irq, k3v2_power_key_irq_handler, IRQF_NO_SUSPEND, pdev->name, power_key);
if (err) {
dev_err(&pdev->dev, "Failed to request press interupt handler!\n");
goto err_request_irq;
}
power_key->power_key_release_irq = platform_get_irq(pdev, 1);
if (power_key->power_key_release_irq < 0) {
dev_err(&pdev->dev, "Failed to get power key release irq!\n");
err = power_key->power_key_release_irq;
goto err_get_irq;
}
err = request_irq(power_key->power_key_release_irq, k3v2_power_key_irq_handler, IRQF_NO_SUSPEND, pdev->name, power_key);
if (err) {
dev_err(&pdev->dev, "Failed to request release interupt handler!\n");
goto err_request_irq;
}
err = input_register_device(power_key->input_dev);
if (err) {
dev_err(&pdev->dev, "Failed to register input device!\n");
goto err_register_device;
}
device_init_wakeup(&pdev->dev, true);
platform_set_drvdata(pdev, power_key);
dev_info(&pdev->dev, "k3v2 power key driver probes successfully!\n");
return 0;
err_register_device:
free_irq(power_key->power_key_press_irq, power_key);
free_irq(power_key->power_key_release_irq, power_key);
err_request_irq:
err_get_irq:
input_free_device(input_dev);
err_alloc_input_device:
kfree(power_key);
power_key = NULL;
pr_info(KERN_ERR "K3v2 power_key probe failed! ret = %d.\n", err);
return err;
}
static int __devexit k3v2_power_key_remove(struct platform_device *pdev)
{
struct k3v2_power_key *power_key = platform_get_drvdata(pdev);
if(power_key == NULL){
dev_info(&pdev->dev, "get invalid power_key pointer\n");
return -EINVAL;
}
free_irq(power_key->power_key_press_irq, power_key);
free_irq(power_key->power_key_release_irq, power_key);
input_unregister_device(power_key->input_dev);
platform_set_drvdata(pdev, NULL);
kfree(power_key);
return 0;
}
#ifdef CONFIG_PM
static int k3v2_power_key_suspend(struct platform_device *pdev)
{
pr_info("[%s]suspend successfully\n", __FUNCTION__);
return 0;
}
static int k3v2_power_key_resume(struct platform_device *pdev)
{
pr_info("[%s]resume successfully\n", __FUNCTION__);
return 0;
}
#endif
struct platform_driver k3v2_power_key_driver = {
.probe = k3v2_power_key_probe,
.remove = __devexit_p(k3v2_power_key_remove),
.driver = {
.name = "k3v2_power_key",
.owner = THIS_MODULE,
},
#ifdef CONFIG_PM
.suspend = k3v2_power_key_suspend,
.resume = k3v2_power_key_resume,
#endif
};
static int __init k3v2_power_key_init(void)
{
pr_info(KERN_INFO "k3v2 power key init!\n");
return platform_driver_register(&k3v2_power_key_driver);
}
static void __exit k3v2_power_key_exit(void)
{
pr_info(KERN_INFO "k3v2 power key exit!\n");
platform_driver_unregister(&k3v2_power_key_driver);
}
module_init(k3v2_power_key_init);
module_exit(k3v2_power_key_exit);
MODULE_AUTHOR("Hisilicon K3 Driver Group");
MODULE_DESCRIPTION("K3v2 keypad platform driver");
MODULE_LICENSE("GPL");
| gpl-2.0 |
hajuuk/R7000 | ap/gpl/transmission/openssl/crypto/engine/hw_4758_cca.c | 2 | 25239 | /* Author: Maurice Gittens <maurice@gittens.nl> */
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#include <stdio.h>
#include <openssl/crypto.h>
/* #include <openssl/pem.h> */
#include "cryptlib.h"
#include <openssl/dso.h>
#include <openssl/x509.h>
#include <openssl/objects.h>
#include <openssl/engine.h>
#ifndef OPENSSL_NO_HW
#ifndef OPENSSL_NO_HW_4758_CCA
#ifdef FLAT_INC
#include "hw_4758_cca.h"
#else
#include "vendor_defns/hw_4758_cca.h"
#endif
#include "hw_4758_cca_err.c"
static int ibm_4758_cca_destroy(ENGINE *e);
static int ibm_4758_cca_init(ENGINE *e);
static int ibm_4758_cca_finish(ENGINE *e);
static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
/* rsa functions */
/*---------------*/
#ifndef OPENSSL_NO_RSA
static int cca_rsa_pub_enc(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa,int padding);
static int cca_rsa_priv_dec(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa,int padding);
static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
static int cca_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
/* utility functions */
/*-----------------------*/
static EVP_PKEY *ibm_4758_load_privkey(ENGINE*, const char*,
UI_METHOD *ui_method, void *callback_data);
static EVP_PKEY *ibm_4758_load_pubkey(ENGINE*, const char*,
UI_METHOD *ui_method, void *callback_data);
static int getModulusAndExponent(const unsigned char *token, long *exponentLength,
unsigned char *exponent, long *modulusLength,
long *modulusFieldLength, unsigned char *modulus);
#endif
/* RAND number functions */
/*-----------------------*/
static int cca_get_random_bytes(unsigned char*, int );
static int cca_random_status(void);
static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
int idx,long argl, void *argp);
/* Function pointers for CCA verbs */
/*---------------------------------*/
#ifndef OPENSSL_NO_RSA
static F_KEYRECORDREAD keyRecordRead;
static F_DIGITALSIGNATUREGENERATE digitalSignatureGenerate;
static F_DIGITALSIGNATUREVERIFY digitalSignatureVerify;
static F_PUBLICKEYEXTRACT publicKeyExtract;
static F_PKAENCRYPT pkaEncrypt;
static F_PKADECRYPT pkaDecrypt;
#endif
static F_RANDOMNUMBERGENERATE randomNumberGenerate;
/* static variables */
/*------------------*/
static const char *CCA4758_LIB_NAME = NULL;
static const char *get_CCA4758_LIB_NAME(void)
{
if(CCA4758_LIB_NAME)
return CCA4758_LIB_NAME;
return CCA_LIB_NAME;
}
static void free_CCA4758_LIB_NAME(void)
{
if(CCA4758_LIB_NAME)
OPENSSL_free((void*)CCA4758_LIB_NAME);
CCA4758_LIB_NAME = NULL;
}
static long set_CCA4758_LIB_NAME(const char *name)
{
free_CCA4758_LIB_NAME();
return (((CCA4758_LIB_NAME = BUF_strdup(name)) != NULL) ? 1 : 0);
}
#ifndef OPENSSL_NO_RSA
static const char* n_keyRecordRead = CSNDKRR;
static const char* n_digitalSignatureGenerate = CSNDDSG;
static const char* n_digitalSignatureVerify = CSNDDSV;
static const char* n_publicKeyExtract = CSNDPKX;
static const char* n_pkaEncrypt = CSNDPKE;
static const char* n_pkaDecrypt = CSNDPKD;
#endif
static const char* n_randomNumberGenerate = CSNBRNG;
static int hndidx = -1;
static DSO *dso = NULL;
/* openssl engine initialization structures */
/*------------------------------------------*/
#define CCA4758_CMD_SO_PATH ENGINE_CMD_BASE
static const ENGINE_CMD_DEFN cca4758_cmd_defns[] = {
{CCA4758_CMD_SO_PATH,
"SO_PATH",
"Specifies the path to the '4758cca' shared library",
ENGINE_CMD_FLAG_STRING},
{0, NULL, NULL, 0}
};
#ifndef OPENSSL_NO_RSA
static RSA_METHOD ibm_4758_cca_rsa =
{
"IBM 4758 CCA RSA method",
cca_rsa_pub_enc,
NULL,
NULL,
cca_rsa_priv_dec,
NULL, /*rsa_mod_exp,*/
NULL, /*mod_exp_mont,*/
NULL, /* init */
NULL, /* finish */
RSA_FLAG_SIGN_VER, /* flags */
NULL, /* app_data */
cca_rsa_sign, /* rsa_sign */
cca_rsa_verify /* rsa_verify */
};
#endif
static RAND_METHOD ibm_4758_cca_rand =
{
/* "IBM 4758 RAND method", */
NULL, /* seed */
cca_get_random_bytes, /* get random bytes from the card */
NULL, /* cleanup */
NULL, /* add */
cca_get_random_bytes, /* pseudo rand */
cca_random_status, /* status */
};
static const char *engine_4758_cca_id = "4758cca";
static const char *engine_4758_cca_name = "IBM 4758 CCA hardware engine support";
/* engine implementation */
/*-----------------------*/
static int bind_helper(ENGINE *e)
{
if(!ENGINE_set_id(e, engine_4758_cca_id) ||
!ENGINE_set_name(e, engine_4758_cca_name) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_RSA(e, &ibm_4758_cca_rsa) ||
#endif
!ENGINE_set_RAND(e, &ibm_4758_cca_rand) ||
!ENGINE_set_destroy_function(e, ibm_4758_cca_destroy) ||
!ENGINE_set_init_function(e, ibm_4758_cca_init) ||
!ENGINE_set_finish_function(e, ibm_4758_cca_finish) ||
!ENGINE_set_ctrl_function(e, ibm_4758_cca_ctrl) ||
!ENGINE_set_load_privkey_function(e, ibm_4758_load_privkey) ||
!ENGINE_set_load_pubkey_function(e, ibm_4758_load_pubkey) ||
!ENGINE_set_cmd_defns(e, cca4758_cmd_defns))
return 0;
/* Ensure the error handling is set up */
ERR_load_CCA4758_strings();
return 1;
}
#ifndef ENGINE_DYNAMIC_SUPPORT
static ENGINE *engine_4758_cca(void)
{
ENGINE *ret = ENGINE_new();
if(!ret)
return NULL;
if(!bind_helper(ret))
{
ENGINE_free(ret);
return NULL;
}
return ret;
}
void ENGINE_load_4758cca(void)
{
ENGINE *e_4758 = engine_4758_cca();
if (!e_4758) return;
ENGINE_add(e_4758);
ENGINE_free(e_4758);
ERR_clear_error();
}
#endif
static int ibm_4758_cca_destroy(ENGINE *e)
{
ERR_unload_CCA4758_strings();
free_CCA4758_LIB_NAME();
return 1;
}
static int ibm_4758_cca_init(ENGINE *e)
{
if(dso)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_ALREADY_LOADED);
goto err;
}
dso = DSO_load(NULL, get_CCA4758_LIB_NAME(), NULL, 0);
if(!dso)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
goto err;
}
#ifndef OPENSSL_NO_RSA
if(!(keyRecordRead = (F_KEYRECORDREAD)
DSO_bind_func(dso, n_keyRecordRead)) ||
!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
DSO_bind_func(dso, n_randomNumberGenerate)) ||
!(digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)
DSO_bind_func(dso, n_digitalSignatureGenerate)) ||
!(digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)
DSO_bind_func(dso, n_digitalSignatureVerify)) ||
!(publicKeyExtract = (F_PUBLICKEYEXTRACT)
DSO_bind_func(dso, n_publicKeyExtract)) ||
!(pkaEncrypt = (F_PKAENCRYPT)
DSO_bind_func(dso, n_pkaEncrypt)) ||
!(pkaDecrypt = (F_PKADECRYPT)
DSO_bind_func(dso, n_pkaDecrypt)))
{
CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
goto err;
}
#else
if(!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
DSO_bind_func(dso, n_randomNumberGenerate)))
{
CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
goto err;
}
#endif
hndidx = RSA_get_ex_new_index(0, "IBM 4758 CCA RSA key handle",
NULL, NULL, cca_ex_free);
return 1;
err:
if(dso)
DSO_free(dso);
dso = NULL;
keyRecordRead = (F_KEYRECORDREAD)0;
randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0;
digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0;
publicKeyExtract = (F_PUBLICKEYEXTRACT)0;
pkaEncrypt = (F_PKAENCRYPT)0;
pkaDecrypt = (F_PKADECRYPT)0;
return 0;
}
static int ibm_4758_cca_finish(ENGINE *e)
{
free_CCA4758_LIB_NAME();
if(!dso)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
CCA4758_R_NOT_LOADED);
return 0;
}
if(!DSO_free(dso))
{
CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
CCA4758_R_UNIT_FAILURE);
return 0;
}
dso = NULL;
keyRecordRead = (F_KEYRECORDREAD)0;
randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0;
digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0;
publicKeyExtract = (F_PUBLICKEYEXTRACT)0;
pkaEncrypt = (F_PKAENCRYPT)0;
pkaDecrypt = (F_PKADECRYPT)0;
return 1;
}
static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
{
int initialised = ((dso == NULL) ? 0 : 1);
switch(cmd)
{
case CCA4758_CMD_SO_PATH:
if(p == NULL)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
if(initialised)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
CCA4758_R_ALREADY_LOADED);
return 0;
}
return set_CCA4758_LIB_NAME((const char *)p);
default:
break;
}
CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
CCA4758_R_COMMAND_NOT_IMPLEMENTED);
return 0;
}
#ifndef OPENSSL_NO_RSA
#define MAX_CCA_PKA_TOKEN_SIZE 2500
static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id,
UI_METHOD *ui_method, void *callback_data)
{
RSA *rtmp = NULL;
EVP_PKEY *res = NULL;
unsigned char* keyToken = NULL;
unsigned char pubKeyToken[MAX_CCA_PKA_TOKEN_SIZE];
long pubKeyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
long returnCode;
long reasonCode;
long exitDataLength = 0;
long ruleArrayLength = 0;
unsigned char exitData[8];
unsigned char ruleArray[8];
unsigned char keyLabel[64];
long keyLabelLength = strlen(key_id);
unsigned char modulus[256];
long modulusFieldLength = sizeof(modulus);
long modulusLength = 0;
unsigned char exponent[256];
long exponentLength = sizeof(exponent);
if (keyLabelLength > sizeof(keyLabel))
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
return NULL;
}
memset(keyLabel,' ', sizeof(keyLabel));
memcpy(keyLabel, key_id, keyLabelLength);
keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
if (!keyToken)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
ERR_R_MALLOC_FAILURE);
goto err;
}
keyRecordRead(&returnCode, &reasonCode, &exitDataLength,
exitData, &ruleArrayLength, ruleArray, keyLabel,
&keyTokenLength, keyToken+sizeof(long));
if (returnCode)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
goto err;
}
publicKeyExtract(&returnCode, &reasonCode, &exitDataLength,
exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
keyToken+sizeof(long), &pubKeyTokenLength, pubKeyToken);
if (returnCode)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
goto err;
}
if (!getModulusAndExponent(pubKeyToken, &exponentLength,
exponent, &modulusLength, &modulusFieldLength,
modulus))
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
goto err;
}
(*(long*)keyToken) = keyTokenLength;
rtmp = RSA_new_method(e);
RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
rtmp->flags |= RSA_FLAG_EXT_PKEY;
res = EVP_PKEY_new();
EVP_PKEY_assign_RSA(res, rtmp);
return res;
err:
if (keyToken)
OPENSSL_free(keyToken);
if (res)
EVP_PKEY_free(res);
if (rtmp)
RSA_free(rtmp);
return NULL;
}
static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,
UI_METHOD *ui_method, void *callback_data)
{
RSA *rtmp = NULL;
EVP_PKEY *res = NULL;
unsigned char* keyToken = NULL;
long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
long returnCode;
long reasonCode;
long exitDataLength = 0;
long ruleArrayLength = 0;
unsigned char exitData[8];
unsigned char ruleArray[8];
unsigned char keyLabel[64];
long keyLabelLength = strlen(key_id);
unsigned char modulus[512];
long modulusFieldLength = sizeof(modulus);
long modulusLength = 0;
unsigned char exponent[512];
long exponentLength = sizeof(exponent);
if (keyLabelLength > sizeof(keyLabel))
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
return NULL;
}
memset(keyLabel,' ', sizeof(keyLabel));
memcpy(keyLabel, key_id, keyLabelLength);
keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
if (!keyToken)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,
ERR_R_MALLOC_FAILURE);
goto err;
}
keyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData,
&ruleArrayLength, ruleArray, keyLabel, &keyTokenLength,
keyToken+sizeof(long));
if (returnCode)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
ERR_R_MALLOC_FAILURE);
goto err;
}
if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength,
exponent, &modulusLength, &modulusFieldLength, modulus))
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_FAILED_LOADING_PUBLIC_KEY);
goto err;
}
(*(long*)keyToken) = keyTokenLength;
rtmp = RSA_new_method(e);
RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
rtmp->flags |= RSA_FLAG_EXT_PKEY;
res = EVP_PKEY_new();
EVP_PKEY_assign_RSA(res, rtmp);
return res;
err:
if (keyToken)
OPENSSL_free(keyToken);
if (res)
EVP_PKEY_free(res);
if (rtmp)
RSA_free(rtmp);
return NULL;
}
static int cca_rsa_pub_enc(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa,int padding)
{
long returnCode;
long reasonCode;
long lflen = flen;
long exitDataLength = 0;
unsigned char exitData[8];
long ruleArrayLength = 1;
unsigned char ruleArray[8] = "PKCS-1.2";
long dataStructureLength = 0;
unsigned char dataStructure[8];
long outputLength = RSA_size(rsa);
long keyTokenLength;
unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
keyTokenLength = *(long*)keyToken;
keyToken+=sizeof(long);
pkaEncrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
&ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
&dataStructureLength, dataStructure, &keyTokenLength,
keyToken, &outputLength, to);
if (returnCode || reasonCode)
return -(returnCode << 16 | reasonCode);
return outputLength;
}
static int cca_rsa_priv_dec(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa,int padding)
{
long returnCode;
long reasonCode;
long lflen = flen;
long exitDataLength = 0;
unsigned char exitData[8];
long ruleArrayLength = 1;
unsigned char ruleArray[8] = "PKCS-1.2";
long dataStructureLength = 0;
unsigned char dataStructure[8];
long outputLength = RSA_size(rsa);
long keyTokenLength;
unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
keyTokenLength = *(long*)keyToken;
keyToken+=sizeof(long);
pkaDecrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
&ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
&dataStructureLength, dataStructure, &keyTokenLength,
keyToken, &outputLength, to);
return (returnCode | reasonCode) ? 0 : 1;
}
#define SSL_SIG_LEN 36
static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)
{
long returnCode;
long reasonCode;
long lsiglen = siglen;
long exitDataLength = 0;
unsigned char exitData[8];
long ruleArrayLength = 1;
unsigned char ruleArray[8] = "PKCS-1.1";
long keyTokenLength;
unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
long length = SSL_SIG_LEN;
long keyLength ;
unsigned char *hashBuffer = NULL;
X509_SIG sig;
ASN1_TYPE parameter;
X509_ALGOR algorithm;
ASN1_OCTET_STRING digest;
keyTokenLength = *(long*)keyToken;
keyToken+=sizeof(long);
if (type == NID_md5 || type == NID_sha1)
{
sig.algor = &algorithm;
algorithm.algorithm = OBJ_nid2obj(type);
if (!algorithm.algorithm)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
return 0;
}
if (!algorithm.algorithm->length)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
return 0;
}
parameter.type = V_ASN1_NULL;
parameter.value.ptr = NULL;
algorithm.parameter = ¶meter;
sig.digest = &digest;
sig.digest->data = (unsigned char*)m;
sig.digest->length = m_len;
length = i2d_X509_SIG(&sig, NULL);
}
keyLength = RSA_size(rsa);
if (length - RSA_PKCS1_PADDING > keyLength)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
return 0;
}
switch (type)
{
case NID_md5_sha1 :
if (m_len != SSL_SIG_LEN)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
return 0;
}
hashBuffer = (unsigned char *)m;
length = m_len;
break;
case NID_md5 :
{
unsigned char *ptr;
ptr = hashBuffer = OPENSSL_malloc(
(unsigned int)keyLength+1);
if (!hashBuffer)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
ERR_R_MALLOC_FAILURE);
return 0;
}
i2d_X509_SIG(&sig, &ptr);
}
break;
case NID_sha1 :
{
unsigned char *ptr;
ptr = hashBuffer = OPENSSL_malloc(
(unsigned int)keyLength+1);
if (!hashBuffer)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
ERR_R_MALLOC_FAILURE);
return 0;
}
i2d_X509_SIG(&sig, &ptr);
}
break;
default:
return 0;
}
digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength,
exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
keyToken, &length, hashBuffer, &lsiglen, sigbuf);
if (type == NID_sha1 || type == NID_md5)
{
OPENSSL_cleanse(hashBuffer, keyLength+1);
OPENSSL_free(hashBuffer);
}
return ((returnCode || reasonCode) ? 0 : 1);
}
#define SSL_SIG_LEN 36
static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
unsigned char *sigret, unsigned int *siglen, const RSA *rsa)
{
long returnCode;
long reasonCode;
long exitDataLength = 0;
unsigned char exitData[8];
long ruleArrayLength = 1;
unsigned char ruleArray[8] = "PKCS-1.1";
long outputLength=256;
long outputBitLength;
long keyTokenLength;
unsigned char *hashBuffer = NULL;
unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
long length = SSL_SIG_LEN;
long keyLength ;
X509_SIG sig;
ASN1_TYPE parameter;
X509_ALGOR algorithm;
ASN1_OCTET_STRING digest;
keyTokenLength = *(long*)keyToken;
keyToken+=sizeof(long);
if (type == NID_md5 || type == NID_sha1)
{
sig.algor = &algorithm;
algorithm.algorithm = OBJ_nid2obj(type);
if (!algorithm.algorithm)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
return 0;
}
if (!algorithm.algorithm->length)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
return 0;
}
parameter.type = V_ASN1_NULL;
parameter.value.ptr = NULL;
algorithm.parameter = ¶meter;
sig.digest = &digest;
sig.digest->data = (unsigned char*)m;
sig.digest->length = m_len;
length = i2d_X509_SIG(&sig, NULL);
}
keyLength = RSA_size(rsa);
if (length - RSA_PKCS1_PADDING > keyLength)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
return 0;
}
switch (type)
{
case NID_md5_sha1 :
if (m_len != SSL_SIG_LEN)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
return 0;
}
hashBuffer = (unsigned char*)m;
length = m_len;
break;
case NID_md5 :
{
unsigned char *ptr;
ptr = hashBuffer = OPENSSL_malloc(
(unsigned int)keyLength+1);
if (!hashBuffer)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
ERR_R_MALLOC_FAILURE);
return 0;
}
i2d_X509_SIG(&sig, &ptr);
}
break;
case NID_sha1 :
{
unsigned char *ptr;
ptr = hashBuffer = OPENSSL_malloc(
(unsigned int)keyLength+1);
if (!hashBuffer)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
ERR_R_MALLOC_FAILURE);
return 0;
}
i2d_X509_SIG(&sig, &ptr);
}
break;
default:
return 0;
}
digitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength,
exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
keyToken, &length, hashBuffer, &outputLength, &outputBitLength,
sigret);
if (type == NID_sha1 || type == NID_md5)
{
OPENSSL_cleanse(hashBuffer, keyLength+1);
OPENSSL_free(hashBuffer);
}
*siglen = outputLength;
return ((returnCode || reasonCode) ? 0 : 1);
}
static int getModulusAndExponent(const unsigned char*token, long *exponentLength,
unsigned char *exponent, long *modulusLength, long *modulusFieldLength,
unsigned char *modulus)
{
unsigned long len;
if (*token++ != (char)0x1E) /* internal PKA token? */
return 0;
if (*token++) /* token version must be zero */
return 0;
len = *token++;
len = len << 8;
len |= (unsigned char)*token++;
token += 4; /* skip reserved bytes */
if (*token++ == (char)0x04)
{
if (*token++) /* token version must be zero */
return 0;
len = *token++;
len = len << 8;
len |= (unsigned char)*token++;
token+=2; /* skip reserved section */
len = *token++;
len = len << 8;
len |= (unsigned char)*token++;
*exponentLength = len;
len = *token++;
len = len << 8;
len |= (unsigned char)*token++;
*modulusLength = len;
len = *token++;
len = len << 8;
len |= (unsigned char)*token++;
*modulusFieldLength = len;
memcpy(exponent, token, *exponentLength);
token+= *exponentLength;
memcpy(modulus, token, *modulusFieldLength);
return 1;
}
return 0;
}
#endif /* OPENSSL_NO_RSA */
static int cca_random_status(void)
{
return 1;
}
static int cca_get_random_bytes(unsigned char* buf, int num)
{
long ret_code;
long reason_code;
long exit_data_length;
unsigned char exit_data[4];
unsigned char form[] = "RANDOM ";
unsigned char rand_buf[8];
while(num >= sizeof(rand_buf))
{
randomNumberGenerate(&ret_code, &reason_code, &exit_data_length,
exit_data, form, rand_buf);
if (ret_code)
return 0;
num -= sizeof(rand_buf);
memcpy(buf, rand_buf, sizeof(rand_buf));
buf += sizeof(rand_buf);
}
if (num)
{
randomNumberGenerate(&ret_code, &reason_code, NULL, NULL,
form, rand_buf);
if (ret_code)
return 0;
memcpy(buf, rand_buf, num);
}
return 1;
}
static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, int idx,
long argl, void *argp)
{
if (item)
OPENSSL_free(item);
}
/* Goo to handle building as a dynamic engine */
#ifdef ENGINE_DYNAMIC_SUPPORT
static int bind_fn(ENGINE *e, const char *id)
{
if(id && (strcmp(id, engine_4758_cca_id) != 0))
return 0;
if(!bind_helper(e))
return 0;
return 1;
}
IMPLEMENT_DYNAMIC_CHECK_FN()
IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
#endif /* ENGINE_DYNAMIC_SUPPORT */
#endif /* !OPENSSL_NO_HW_4758_CCA */
#endif /* !OPENSSL_NO_HW */
| gpl-2.0 |
samtygier/mate-display-manager | daemon/mdm-local-display-factory.c | 2 | 16947 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib-object.h>
#include "mdm-display-factory.h"
#include "mdm-local-display-factory.h"
#include "mdm-local-display-factory-glue.h"
#include "mdm-display-store.h"
#include "mdm-static-display.h"
#include "mdm-transient-display.h"
#include "mdm-static-factory-display.h"
#include "mdm-product-display.h"
#define MDM_LOCAL_DISPLAY_FACTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MDM_TYPE_LOCAL_DISPLAY_FACTORY, MdmLocalDisplayFactoryPrivate))
#define CK_SEAT1_PATH "/org/freedesktop/ConsoleKit/Seat1"
#define MDM_DBUS_PATH "/org/mate/DisplayManager"
#define MDM_LOCAL_DISPLAY_FACTORY_DBUS_PATH MDM_DBUS_PATH "/LocalDisplayFactory"
#define MDM_MANAGER_DBUS_NAME "org.mate.DisplayManager.LocalDisplayFactory"
#define MAX_DISPLAY_FAILURES 5
struct MdmLocalDisplayFactoryPrivate
{
DBusGConnection *connection;
DBusGProxy *proxy;
GHashTable *displays;
/* FIXME: this needs to be per seat? */
guint num_failures;
};
enum {
PROP_0,
};
static void mdm_local_display_factory_class_init (MdmLocalDisplayFactoryClass *klass);
static void mdm_local_display_factory_init (MdmLocalDisplayFactory *factory);
static void mdm_local_display_factory_finalize (GObject *object);
static MdmDisplay *create_display (MdmLocalDisplayFactory *factory);
static gpointer local_display_factory_object = NULL;
G_DEFINE_TYPE (MdmLocalDisplayFactory, mdm_local_display_factory, MDM_TYPE_DISPLAY_FACTORY)
GQuark
mdm_local_display_factory_error_quark (void)
{
static GQuark ret = 0;
if (ret == 0) {
ret = g_quark_from_static_string ("mdm_local_display_factory_error");
}
return ret;
}
static void
listify_hash (gpointer key,
MdmDisplay *display,
GList **list)
{
*list = g_list_prepend (*list, key);
}
static int
sort_nums (gpointer a,
gpointer b)
{
guint32 num_a;
guint32 num_b;
num_a = GPOINTER_TO_UINT (a);
num_b = GPOINTER_TO_UINT (b);
if (num_a > num_b) {
return 1;
} else if (num_a < num_b) {
return -1;
} else {
return 0;
}
}
static guint32
take_next_display_number (MdmLocalDisplayFactory *factory)
{
GList *list;
GList *l;
guint32 ret;
ret = 0;
list = NULL;
g_hash_table_foreach (factory->priv->displays, (GHFunc)listify_hash, &list);
if (list == NULL) {
goto out;
}
/* sort low to high */
list = g_list_sort (list, (GCompareFunc)sort_nums);
g_debug ("MdmLocalDisplayFactory: Found the following X displays:");
for (l = list; l != NULL; l = l->next) {
g_debug ("MdmLocalDisplayFactory: %u", GPOINTER_TO_UINT (l->data));
}
for (l = list; l != NULL; l = l->next) {
guint32 num;
num = GPOINTER_TO_UINT (l->data);
/* always fill zero */
if (l->prev == NULL && num != 0) {
ret = 0;
break;
}
/* now find the first hole */
if (l->next == NULL || GPOINTER_TO_UINT (l->next->data) != (num + 1)) {
ret = num + 1;
break;
}
}
out:
/* now reserve this number */
g_debug ("MdmLocalDisplayFactory: Reserving X display: %u", ret);
g_hash_table_insert (factory->priv->displays, GUINT_TO_POINTER (ret), NULL);
return ret;
}
static void
on_display_disposed (MdmLocalDisplayFactory *factory,
MdmDisplay *display)
{
g_debug ("MdmLocalDisplayFactory: Display %p disposed", display);
}
static void
store_display (MdmLocalDisplayFactory *factory,
guint32 num,
MdmDisplay *display)
{
MdmDisplayStore *store;
g_object_weak_ref (G_OBJECT (display), (GWeakNotify)on_display_disposed, factory);
store = mdm_display_factory_get_display_store (MDM_DISPLAY_FACTORY (factory));
mdm_display_store_add (store, display);
/* now fill our reserved spot */
g_hash_table_insert (factory->priv->displays, GUINT_TO_POINTER (num), NULL);
}
/*
Example:
dbus-send --system --dest=org.mate.DisplayManager \
--type=method_call --print-reply --reply-timeout=2000 \
/org/mate/DisplayManager/Manager \
org.mate.DisplayManager.Manager.GetDisplays
*/
gboolean
mdm_local_display_factory_create_transient_display (MdmLocalDisplayFactory *factory,
char **id,
GError **error)
{
gboolean ret;
MdmDisplay *display;
guint32 num;
g_return_val_if_fail (MDM_IS_LOCAL_DISPLAY_FACTORY (factory), FALSE);
ret = FALSE;
num = take_next_display_number (factory);
g_debug ("MdmLocalDisplayFactory: Creating transient display %d", num);
display = mdm_transient_display_new (num);
/* FIXME: don't hardcode seat1? */
g_object_set (display, "seat-id", CK_SEAT1_PATH, NULL);
store_display (factory, num, display);
if (! mdm_display_manage (display)) {
display = NULL;
goto out;
}
if (! mdm_display_get_id (display, id, NULL)) {
display = NULL;
goto out;
}
ret = TRUE;
out:
/* ref either held by store or not at all */
g_object_unref (display);
return ret;
}
gboolean
mdm_local_display_factory_create_product_display (MdmLocalDisplayFactory *factory,
const char *parent_display_id,
const char *relay_address,
char **id,
GError **error)
{
gboolean ret;
MdmDisplay *display;
guint32 num;
g_return_val_if_fail (MDM_IS_LOCAL_DISPLAY_FACTORY (factory), FALSE);
ret = FALSE;
g_debug ("MdmLocalDisplayFactory: Creating product display parent %s address:%s",
parent_display_id, relay_address);
num = take_next_display_number (factory);
g_debug ("MdmLocalDisplayFactory: got display num %u", num);
display = mdm_product_display_new (num, relay_address);
/* FIXME: don't hardcode seat1? */
g_object_set (display, "seat-id", CK_SEAT1_PATH, NULL);
store_display (factory, num, display);
if (! mdm_display_manage (display)) {
display = NULL;
goto out;
}
if (! mdm_display_get_id (display, id, NULL)) {
display = NULL;
goto out;
}
ret = TRUE;
out:
/* ref either held by store or not at all */
g_object_unref (display);
return ret;
}
static void
on_static_display_status_changed (MdmDisplay *display,
GParamSpec *arg1,
MdmLocalDisplayFactory *factory)
{
int status;
MdmDisplayStore *store;
int num;
num = -1;
mdm_display_get_x11_display_number (display, &num, NULL);
g_assert (num != -1);
store = mdm_display_factory_get_display_store (MDM_DISPLAY_FACTORY (factory));
status = mdm_display_get_status (display);
g_debug ("MdmLocalDisplayFactory: static display status changed: %d", status);
switch (status) {
case MDM_DISPLAY_FINISHED:
/* remove the display number from factory->priv->displays
so that it may be reused */
g_hash_table_remove (factory->priv->displays, GUINT_TO_POINTER (num));
mdm_display_store_remove (store, display);
/* reset num failures */
factory->priv->num_failures = 0;
create_display (factory);
break;
case MDM_DISPLAY_FAILED:
/* leave the display number in factory->priv->displays
so that it doesn't get reused */
mdm_display_store_remove (store, display);
factory->priv->num_failures++;
if (factory->priv->num_failures > MAX_DISPLAY_FAILURES) {
/* oh shit */
g_warning ("MdmLocalDisplayFactory: maximum number of X display failures reached: check X server log for errors");
/* FIXME: should monitor hardware changes to
try again when seats change */
} else {
create_display (factory);
}
break;
case MDM_DISPLAY_UNMANAGED:
break;
case MDM_DISPLAY_PREPARED:
break;
case MDM_DISPLAY_MANAGED:
break;
default:
g_assert_not_reached ();
break;
}
}
static MdmDisplay *
create_display (MdmLocalDisplayFactory *factory)
{
MdmDisplay *display;
guint32 num;
num = take_next_display_number (factory);
#if 0
display = mdm_static_factory_display_new (num);
#else
display = mdm_static_display_new (num);
#endif
if (display == NULL) {
g_warning ("Unable to create display: %d", num);
return NULL;
}
/* FIXME: don't hardcode seat1? */
g_object_set (display, "seat-id", CK_SEAT1_PATH, NULL);
g_signal_connect (display,
"notify::status",
G_CALLBACK (on_static_display_status_changed),
factory);
store_display (factory, num, display);
/* let store own the ref */
g_object_unref (display);
if (! mdm_display_manage (display)) {
mdm_display_unmanage (display);
}
return display;
}
static gboolean
mdm_local_display_factory_start (MdmDisplayFactory *base_factory)
{
gboolean ret;
MdmLocalDisplayFactory *factory = MDM_LOCAL_DISPLAY_FACTORY (base_factory);
MdmDisplay *display;
g_return_val_if_fail (MDM_IS_LOCAL_DISPLAY_FACTORY (factory), FALSE);
ret = TRUE;
/* FIXME: use seat configuration */
display = create_display (factory);
if (display == NULL) {
ret = FALSE;
}
return ret;
}
static gboolean
mdm_local_display_factory_stop (MdmDisplayFactory *base_factory)
{
MdmLocalDisplayFactory *factory = MDM_LOCAL_DISPLAY_FACTORY (base_factory);
g_return_val_if_fail (MDM_IS_LOCAL_DISPLAY_FACTORY (factory), FALSE);
return TRUE;
}
static void
mdm_local_display_factory_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
mdm_local_display_factory_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
register_factory (MdmLocalDisplayFactory *factory)
{
GError *error = NULL;
error = NULL;
factory->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (factory->priv->connection == NULL) {
if (error != NULL) {
g_critical ("error getting system bus: %s", error->message);
g_error_free (error);
}
exit (1);
}
dbus_g_connection_register_g_object (factory->priv->connection, MDM_LOCAL_DISPLAY_FACTORY_DBUS_PATH, G_OBJECT (factory));
return TRUE;
}
static GObject *
mdm_local_display_factory_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
MdmLocalDisplayFactory *factory;
gboolean res;
factory = MDM_LOCAL_DISPLAY_FACTORY (G_OBJECT_CLASS (mdm_local_display_factory_parent_class)->constructor (type,
n_construct_properties,
construct_properties));
res = register_factory (factory);
if (! res) {
g_warning ("Unable to register local display factory with system bus");
}
return G_OBJECT (factory);
}
static void
mdm_local_display_factory_class_init (MdmLocalDisplayFactoryClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
MdmDisplayFactoryClass *factory_class = MDM_DISPLAY_FACTORY_CLASS (klass);
object_class->get_property = mdm_local_display_factory_get_property;
object_class->set_property = mdm_local_display_factory_set_property;
object_class->finalize = mdm_local_display_factory_finalize;
object_class->constructor = mdm_local_display_factory_constructor;
factory_class->start = mdm_local_display_factory_start;
factory_class->stop = mdm_local_display_factory_stop;
g_type_class_add_private (klass, sizeof (MdmLocalDisplayFactoryPrivate));
dbus_g_object_type_install_info (MDM_TYPE_LOCAL_DISPLAY_FACTORY, &dbus_glib_mdm_local_display_factory_object_info);
}
static void
mdm_local_display_factory_init (MdmLocalDisplayFactory *factory)
{
factory->priv = MDM_LOCAL_DISPLAY_FACTORY_GET_PRIVATE (factory);
factory->priv->displays = g_hash_table_new (NULL, NULL);
}
static void
mdm_local_display_factory_finalize (GObject *object)
{
MdmLocalDisplayFactory *factory;
g_return_if_fail (object != NULL);
g_return_if_fail (MDM_IS_LOCAL_DISPLAY_FACTORY (object));
factory = MDM_LOCAL_DISPLAY_FACTORY (object);
g_return_if_fail (factory->priv != NULL);
g_hash_table_destroy (factory->priv->displays);
G_OBJECT_CLASS (mdm_local_display_factory_parent_class)->finalize (object);
}
MdmLocalDisplayFactory *
mdm_local_display_factory_new (MdmDisplayStore *store)
{
if (local_display_factory_object != NULL) {
g_object_ref (local_display_factory_object);
} else {
local_display_factory_object = g_object_new (MDM_TYPE_LOCAL_DISPLAY_FACTORY,
"display-store", store,
NULL);
g_object_add_weak_pointer (local_display_factory_object,
(gpointer *) &local_display_factory_object);
}
return MDM_LOCAL_DISPLAY_FACTORY (local_display_factory_object);
}
| gpl-2.0 |
wangtzh/foedus_code | tests-core/src/foedus/snapshot/test_snapshot_sequential.cpp | 2 | 5842 | /*
* Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
* 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* HP designates this particular file as subject to the "Classpath" exception
* as provided by HP in the LICENSE.txt file that accompanied this code.
*/
#include <gtest/gtest.h>
#include <string>
#include "foedus/engine.hpp"
#include "foedus/engine_options.hpp"
#include "foedus/test_common.hpp"
#include "foedus/log/log_manager.hpp"
#include "foedus/proc/proc_manager.hpp"
#include "foedus/snapshot/snapshot_id.hpp"
#include "foedus/snapshot/snapshot_manager.hpp"
#include "foedus/snapshot/snapshot_manager_pimpl.hpp"
#include "foedus/storage/storage_manager.hpp"
#include "foedus/storage/sequential/sequential_metadata.hpp"
#include "foedus/storage/sequential/sequential_storage.hpp"
#include "foedus/thread/thread_pool.hpp"
#include "foedus/xct/xct_manager.hpp"
/**
* @file test_snapshot_sequential.cpp
* Snapshot for sequential storage.
*/
namespace foedus {
namespace snapshot {
DEFINE_TEST_CASE_PACKAGE(SnapshotSequentialTest, foedus.snapshot);
const uint32_t kRecords = 1024;
const uint32_t kThreads = 2;
const storage::StorageName kName("test");
ErrorStack appends_task(const proc::ProcArguments& args) {
EXPECT_EQ(sizeof(uint32_t), args.input_len_);
uint32_t id = *reinterpret_cast<const uint32_t*>(args.input_buffer_);
EXPECT_NE(id, 2U);
thread::Thread* context = args.context_;
storage::sequential::SequentialStorage sequential(args.engine_, kName);
ASSERT_ND(sequential.exists());
xct::XctManager* xct_manager = args.engine_->get_xct_manager();
WRAP_ERROR_CODE(xct_manager->begin_xct(context, xct::kSerializable));
for (uint32_t i = 0; i < kRecords / 2U; ++i) {
uint64_t rec = id * kRecords / 2U + i;
WRAP_ERROR_CODE(sequential.append_record(context, &rec, sizeof(rec)));
}
Epoch commit_epoch;
WRAP_ERROR_CODE(xct_manager->precommit_xct(context, &commit_epoch));
WRAP_ERROR_CODE(xct_manager->wait_for_commit(commit_epoch));
return kRetOk;
}
/* TODO(Hideaki) We should have a verify. as soon as we add scan API.
ErrorStack verify_task(const proc::ProcArguments& args) {
thread::Thread* context = args.context_;
storage::sequential::SequentialStorage sequential(args.engine_, kName);
ASSERT_ND(sequential.exists());
xct::XctManager* xct_manager = args.engine_->get_xct_manager();
WRAP_ERROR_CODE(xct_manager->begin_xct(context, xct::kSerializable));
for (uint32_t i = 0; i < kRecords; ++i) {
storage::sequential::SequentialOffset rec = i;
storage::sequential::SequentialOffset data = 0;
WRAP_ERROR_CODE(sequential.get_record(context, rec, &data));
EXPECT_EQ(rec, data) << i;
}
Epoch commit_epoch;
WRAP_ERROR_CODE(xct_manager->precommit_xct(context, &commit_epoch));
return kRetOk;
}
*/
void test_appends(bool multiple_loggers, bool multiple_partitions) {
EngineOptions options = get_tiny_options();
if (multiple_partitions) {
options.thread_.thread_count_per_group_ = 1;
options.thread_.group_count_ = 2;
options.log_.loggers_per_node_ = 1;
} else {
options.thread_.thread_count_per_group_ = kThreads;
options.thread_.group_count_ = 1;
options.log_.loggers_per_node_ = multiple_loggers ? kThreads : 1;
}
{
Engine engine(options);
const proc::ProcName kAppends("appends_task");
engine.get_proc_manager()->pre_register(kAppends, appends_task);
// engine.get_proc_manager()->pre_register("verify_task", verify_task);
COERCE_ERROR(engine.initialize());
{
UninitializeGuard guard(&engine);
storage::sequential::SequentialStorage out;
Epoch commit_epoch;
storage::sequential::SequentialMetadata meta(kName);
COERCE_ERROR(engine.get_storage_manager()->create_sequential(&meta, &out, &commit_epoch));
EXPECT_TRUE(out.exists());
EXPECT_TRUE(commit_epoch.is_valid());
thread::ThreadPool* pool = engine.get_thread_pool();
for (uint32_t i = 0; i < kThreads; ++i) {
if (multiple_partitions) {
COERCE_ERROR(pool->impersonate_on_numa_node_synchronous(i, kAppends, &i, sizeof(i)));
} else {
COERCE_ERROR(pool->impersonate_on_numa_core_synchronous(i, kAppends, &i, sizeof(i)));
}
}
// COERCE_ERROR(engine.get_thread_pool()->impersonate_synchronous("verify_task"));
engine.get_snapshot_manager()->trigger_snapshot_immediate(true);
COERCE_ERROR(engine.uninitialize());
}
}
{
Engine engine(options);
// engine.get_proc_manager()->pre_register("verify_task", verify_task);
COERCE_ERROR(engine.initialize());
{
UninitializeGuard guard(&engine);
// COERCE_ERROR(engine.get_thread_pool()->impersonate_synchronous("verify_task"));
COERCE_ERROR(engine.uninitialize());
}
}
cleanup_test(options);
}
TEST(SnapshotSequentialTest, AppendsOneLogger) { test_appends(false, false); }
TEST(SnapshotSequentialTest, AppendsTwoLoggers) { test_appends(true, false); }
TEST(SnapshotSequentialTest, AppendsTwoPartitions) { test_appends(true, true); }
} // namespace snapshot
} // namespace foedus
TEST_MAIN_CAPTURE_SIGNALS(SnapshotSequentialTest, foedus.snapshot);
| gpl-2.0 |
husk00/sonandoSatelites-fictional-serie | GPredict-osc/src/gtk-sat-data.c | 2 | 10051 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Gpredict: Real-time satellite tracking and orbit prediction program
Copyright (C) 2001-2009 Alexandru Csete, OZ9AEC.
Authors: Alexandru Csete <oz9aec@gmail.com>
Comments, questions and bugreports should be submitted via
http://sourceforge.net/projects/gpredict/
More details can be found at the project home page:
http://gpredict.oz9aec.net/
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, visit http://www.fsf.org/
*/
#include <glib.h>
#include <glib/gi18n.h>
#include "sgpsdp/sgp4sdp4.h"
#include "gtk-sat-data.h"
#include "sat-log.h"
#ifdef HAVE_CONFIG_H
# include <build-config.h>
#endif
#include "orbit-tools.h"
#include "time-tools.h"
#include "compat.h"
/** \brief Read TLE data for a given satellite into memory.
* \param catnum The catalog number of the satellite.
* \param sat Pointer to a valid sat_t structure.
* \return 0 if successfull, 1 if an I/O error occurred,
* 2 if the TLE data appears to be bad.
*
*/
gint
gtk_sat_data_read_sat (gint catnum, sat_t *sat)
{
guint errorcode = 0;
GError *error = NULL;
GKeyFile *data;
gchar *filename = NULL, *path = NULL;
gchar *tlestr1,*tlestr2,*rawtle;
/* ensure that sat != NULL */
g_return_val_if_fail (sat != NULL, 1);
/* .sat file names */
filename = g_strdup_printf ("%d.sat", catnum);
path = sat_file_name_from_catnum (catnum);
/* open .sat file */
data = g_key_file_new ();
if (!g_key_file_load_from_file (data, path, G_KEY_FILE_KEEP_COMMENTS, &error)) {
/* an error occurred */
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s: Failed to load data from %s (%s)"),
__FUNCTION__, path, error->message);
g_clear_error (&error);
errorcode = 1;
}
else {
/* read name, nickname, and website */
sat->name = g_key_file_get_string (data, "Satellite", "NAME", &error);
if (error != NULL) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s: Error reading NAME from %s (%s)"),
__FUNCTION__, path, error->message);
g_clear_error (&error);
sat->name = g_strdup ("Error");
}
sat->nickname = g_key_file_get_string (data, "Satellite", "NICKNAME", &error);
if (error != NULL) {
sat_log_log (SAT_LOG_LEVEL_MSG,
_("%s: Satellite %d has no NICKNAME"),
__FUNCTION__, catnum);
g_clear_error (&error);
sat->nickname = g_strdup (sat->name);
}
sat->website = g_key_file_get_string (data, "Satellite", "WEBSITE", NULL); /* website may be NULL */
/* get TLE data */
tlestr1 = g_key_file_get_string (data, "Satellite", "TLE1", NULL);
tlestr2 = g_key_file_get_string (data, "Satellite", "TLE2", NULL);
rawtle = g_strconcat (tlestr1, tlestr2, NULL);
if (!Good_Elements (rawtle)) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
_("%s: TLE data for %d appears to be bad"),
__FUNCTION__, catnum);
errorcode = 2;
}
Convert_Satellite_Data (rawtle, &sat->tle);
g_free (tlestr1);
g_free (tlestr2);
g_free (rawtle);
/* VERY, VERY important! If not done, some sats
will not get initialised, the first time SGP4/SDP4
is called. Consequently, the resulting data will
be NAN, INF or similar nonsense.
For some reason, not even using g_new0 seems to
be enough.
*/
sat->flags = 0;
select_ephemeris (sat);
/* initialise variable fields */
sat->jul_utc = 0.0;
sat->tsince = 0.0;
sat->az = 0.0;
sat->el = 0.0;
sat->range = 0.0;
sat->range_rate = 0.0;
sat->ra = 0.0;
sat->dec = 0.0;
sat->ssplat = 0.0;
sat->ssplon = 0.0;
sat->alt = 0.0;
sat->velo = 0.0;
sat->ma = 0.0;
sat->footprint = 0.0;
sat->phase = 0.0;
sat->aos = 0.0;
sat->los = 0.0;
/* calculate satellite data at epoch */
gtk_sat_data_init_sat (sat, NULL);
}
g_free (filename);
g_free (path);
g_key_file_free (data);
return errorcode;
}
/** \brief Initialise satellite data.
* \param sat The satellite to initialise.
* \param qth Optional QTH info, use (0,0) if NULL.
*
* This function calculates the satellite data at t = 0, ie. epoch time
* The function is called automatically by gtk_sat_data_read_sat.
*/
void
gtk_sat_data_init_sat (sat_t *sat, qth_t *qth)
{
geodetic_t obs_geodetic;
obs_set_t obs_set;
geodetic_t sat_geodetic;
double jul_utc, age;
g_return_if_fail (sat != NULL);
jul_utc = Julian_Date_of_Epoch (sat->tle.epoch); // => tsince = 0.0
sat->jul_epoch = jul_utc;
/* initialise observer location */
if (qth != NULL) {
obs_geodetic.lon = qth->lon * de2ra;
obs_geodetic.lat = qth->lat * de2ra;
obs_geodetic.alt = qth->alt / 1000.0;
obs_geodetic.theta = 0;
}
else {
obs_geodetic.lon = 0.0;
obs_geodetic.lat = 0.0;
obs_geodetic.alt = 0.0;
obs_geodetic.theta = 0;
}
/* execute computations */
if (sat->flags & DEEP_SPACE_EPHEM_FLAG)
SDP4 (sat, 0.0);
else
SGP4 (sat, 0.0);
/* scale position and velocity to km and km/sec */
Convert_Sat_State (&sat->pos, &sat->vel);
/* get the velocity of the satellite */
Magnitude (&sat->vel);
sat->velo = sat->vel.w;
Calculate_Obs (jul_utc, &sat->pos, &sat->vel, &obs_geodetic, &obs_set);
Calculate_LatLonAlt (jul_utc, &sat->pos, &sat_geodetic);
while (sat_geodetic.lon < -pi)
sat_geodetic.lon += twopi;
while (sat_geodetic.lon > (pi))
sat_geodetic.lon -= twopi;
sat->az = Degrees (obs_set.az);
sat->el = Degrees (obs_set.el);
sat->range = obs_set.range;
sat->range_rate = obs_set.range_rate;
sat->ssplat = Degrees (sat_geodetic.lat);
sat->ssplon = Degrees (sat_geodetic.lon);
sat->alt = sat_geodetic.alt;
sat->ma = Degrees (sat->phase);
sat->ma *= 256.0/360.0;
sat->footprint = 2.0 * xkmper * acos (xkmper/sat->pos.w);
age = 0.0;
sat->orbit = (long) floor((sat->tle.xno * xmnpda/twopi +
age * sat->tle.bstar * ae) * age +
sat->tle.xmo/twopi) + sat->tle.revnum - 1;
/* orbit type */
sat->otype = get_orbit_type (sat);
}
/** \brief Copy satellite data.
* \param source Pointer to the source satellite to copy data from.
* \param dest Pointer to the destination satellite to copy data into.
* \param qth Pointer to the observer data (needed to initialize sat)
*
* This function copies the satellite data from a source sat_t structure into
* the destination. The function copies the tle_t data and calls gtk_sat_data_inti_sat()
* function for initializing the other fields.
*
*/
void gtk_sat_data_copy_sat (const sat_t *source, sat_t *dest, qth_t *qth)
{
guint i;
g_return_if_fail ((source != NULL) && (dest != NULL));
dest->tle.epoch = source->tle.epoch;
dest->tle.epoch_year = source->tle.epoch_year;
dest->tle.epoch_day = source->tle.epoch_day;
dest->tle.epoch_fod = source->tle.epoch_fod;
dest->tle.xndt2o = source->tle.xndt2o;
dest->tle.xndd6o = source->tle.xndd6o;
dest->tle.bstar = source->tle.bstar;
dest->tle.xincl = source->tle.xincl;
dest->tle.xnodeo = source->tle.xnodeo;
dest->tle.eo = source->tle.eo;
dest->tle.omegao = source->tle.omegao;
dest->tle.xmo = source->tle.xmo;
dest->tle.xno = source->tle.xno;
dest->tle.catnr = source->tle.catnr;
dest->tle.elset = source->tle.elset;
dest->tle.revnum = source->tle.revnum;
dest->name = g_strdup (source->name);
dest->nickname = g_strdup (source->nickname);
for (i = 0; i < 9; i++)
dest->tle.idesg[i] = source->tle.idesg[i];
dest->tle.status = source->tle.status;
dest->tle.xincl1 = source->tle.xincl1;
dest->tle.omegao1 = source->tle.omegao1;
dest->otype = source->otype;
/* very important */
dest->flags = 0;
select_ephemeris (dest);
/* initialise variable fields */
dest->jul_utc = 0.0;
dest->tsince = 0.0;
dest->az = 0.0;
dest->el = 0.0;
dest->range = 0.0;
dest->range_rate = 0.0;
dest->ra = 0.0;
dest->dec = 0.0;
dest->ssplat = 0.0;
dest->ssplon = 0.0;
dest->alt = 0.0;
dest->velo = 0.0;
dest->ma = 0.0;
dest->footprint = 0.0;
dest->phase = 0.0;
dest->aos = 0.0;
dest->los = 0.0;
gtk_sat_data_init_sat (dest, qth);
}
/** \brief Free satellite data
* \param sat Pointer to the satellite data to free
*
* This function frees the memory that has been dyunamically allocated
* when creating a new satellite object.
*/
void gtk_sat_data_free_sat(sat_t *sat)
{
if (sat){
if (sat->name){
g_free(sat->name);
sat->name=NULL;
}
if (sat->nickname){
g_free(sat->nickname);
sat->nickname=NULL;
}
if (sat->website){
g_free(sat->website);
sat->website=NULL;
}
g_free(sat);
}
}
| gpl-2.0 |
jmtd/doom64 | src/kex/m_password.c | 2 | 9558 | // Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// Copyright(C) 1997 Midway Home Entertainment, Inc
// Copyright(C) 2007-2012 Samuel Villarreal
//
// 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.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//-----------------------------------------------------------------------------
//
// DESCRIPTION:
// Password system
//
//-----------------------------------------------------------------------------
#include "doomdef.h"
#include "doomstat.h"
#include "d_englsh.h"
#include "i_swap.h"
#include "con_console.h"
#include "m_password.h"
//
// PASSWORD STUFF
//
byte passwordData[16];
dboolean doPassword = false;
const char *passwordChar = "bcdfghjklmnpqrstvwxyz0123456789?";
static const int passwordTable[10] = { 1, 8, 9, 5, 6, 2, 7, 0, 4, 3 };
CVAR_EXTERNAL(p_features);
//
// M_EncodePassItem
//
static void M_EncodePassItem(int *bit, int value, int maxvalue) {
value = (value << 3);
*bit = value / maxvalue;
if((value % maxvalue) != 0) {
*bit = *bit + 1;
}
}
//
// M_CheckPassCode
//
static dboolean M_CheckPassCode(int *bit1, int *bit2, int *bit3, byte *encode) {
byte checkByte = 0;
if(*bit1 < 0) {
*bit2 = (*bit1 + 7) >> 3;
}
else {
*bit2 = (*bit1 >> 3);
}
*bit3 = (*bit1 & 7);
if(*bit1 < 0) {
if(*bit3 != 0) {
*bit3 -= 7;
}
}
checkByte = *(byte*)(encode + *bit2);
if((checkByte & (0x80 >> *bit3)) != 0) {
return true;
}
return false;
}
//
// M_EncodePassword
//
void M_EncodePassword(void) {
byte encode[10];
int i;
int bit = 0;
short decodebit[3];
int passBit = 0;
int xbit1 = 8;
int xbit2 = 0;
int xbit3 = 0;
player_t *player;
dmemset(encode, 0, 10);
dmemset(passwordData, 0, 16);
player = &players[consoleplayer];
// map and skill
encode[0] = ((((nextmap & 0x3f) << 2) & 0xff) | (gameskill & 3));
// weapons
for(i = 0; i < NUMWEAPONS; i++) {
if(i != wp_fist && i != wp_pistol) {
if(player->weaponowned[i]) {
encode[1] |= (1 << bit);
encode[1] = encode[1] & 0xff;
}
bit++;
}
}
// backpack
if(player->backpack) {
encode[5] |= 0x80;
}
bit = 0;
// clip
M_EncodePassItem(&bit, player->ammo[am_clip], player->maxammo[am_clip]);
encode[2] = (bit << 4) & 0xff;
// shell
M_EncodePassItem(&bit, player->ammo[am_shell], player->maxammo[am_shell]);
encode[2] |= bit & 0xff;
// cell
M_EncodePassItem(&bit, player->ammo[am_cell], player->maxammo[am_cell]);
encode[3] = (bit << 4) & 0xff;
// rocket
M_EncodePassItem(&bit, player->ammo[am_misl], player->maxammo[am_misl]);
encode[3] |= bit & 0xff;
// health
M_EncodePassItem(&bit, player->health, 200);
encode[4] = (bit << 4);
// armor
M_EncodePassItem(&bit, player->armorpoints, 200);
encode[4] |= bit;
// armortype
encode[5] |= player->armortype;
// artifacts
encode[5] |= (player->artifacts << 2);
decodebit[0] = I_SwapBE16(*(short*)&encode[0]);
decodebit[1] = I_SwapBE16(*(short*)&encode[2]);
decodebit[2] = I_SwapBE16(*(short*)&encode[4]);
*(short*)&encode[6] = I_SwapBE16(~(decodebit[0] + decodebit[1] + decodebit[2]));
*(short*)&encode[8] = I_SwapBE16(~(decodebit[0] ^ decodebit[1] ^ decodebit[2]));
for(i = 0; i < 10; i++) {
bit = *(byte*)(encode + passwordTable[i]);
encode[i] = (encode[i] ^ bit);
}
bit = 0;
while(bit < 0x50) {
passBit = 0;
if(M_CheckPassCode(&bit, &xbit2, &xbit3, encode)) {
passBit = 16;
}
xbit1 = 8;
bit++;
for(i = 0; i < 4; i++) {
if(M_CheckPassCode(&bit, &xbit2, &xbit3, encode)) {
passBit |= xbit1;
}
xbit1 >>= 1;
bit++;
}
*(byte*)(passwordData + ((bit - 1) / 5)) = passBit;
}
}
//
// M_DecodePassItem
//
static int M_DecodePassItem(int bytecode, int maxvalue) {
int value;
int bitsum = (bytecode * maxvalue);
if(bitsum >= 0) {
value = (bitsum >> 3);
}
else {
value = ((bitsum + 7) >> 3);
}
return value;
}
//
// M_DecodePassword
//
dboolean M_DecodePassword(dboolean checkOnly) {
byte data[16];
byte decode[10];
int bit = 0;
int i = 0;
short xbit1 = 0;
short xbit2 = 0;
short xbit3 = 0;
short x, y;
player_t *player;
dmemcpy(data, passwordData, 16);
dmemset(decode, 0, 10);
player = &players[consoleplayer];
//
// decode password
//
while(bit < 0x50) {
int passBit = 0;
int decodeBit = 0x80;
byte checkByte = 0;
i = 0;
while(i != 8) {
int j = 0;
i += 4;
for(j = 0; j < 4; j++) {
checkByte = *(byte*)(data + (bit / 5));
if((checkByte & (16 >> (bit % 5)))) {
passBit |= decodeBit;
}
bit++;
decodeBit >>= 1;
}
}
if((bit - 1) >= 0) {
checkByte = ((bit - 1) >> 3);
}
else {
checkByte = (((bit - 1) + 7) >> 3);
}
*(byte*)(decode + checkByte) = passBit;
}
for(i = 9; i >= 0; i--) {
bit = *(byte*)(decode + passwordTable[i]);
decode[i] = (decode[i] ^ bit);
}
//
// verify decoded password
//
xbit1 = I_SwapBE16(*(short*)&decode[0]);
xbit2 = I_SwapBE16(*(short*)&decode[2]);
xbit3 = I_SwapBE16(*(short*)&decode[4]);
x = ((~((xbit1 + xbit2) + xbit3) << 16) >> 16);
y = I_SwapBE16(*(short*)&decode[6]);
if(x != y) {
return false;
}
x = ((~(xbit1 ^ (xbit2 ^ xbit3)) << 16) >> 16);
y = I_SwapBE16(*(short*)&decode[8]);
if(x != y) {
return false;
}
//
// verify map
//
if((decode[0] >> 2) >= 33) {
return false;
}
//
// verify skill
//
if((decode[0] & 3) > sk_nightmare) {
return false;
}
//
// verify ammo?
//
if((decode[2] & 0xf) >= 9 || (decode[2] >> 4) >= 9) {
return false;
}
//
// verify ammo?
//
if((decode[3] & 0xf) >= 9 || (decode[3] >> 4) >= 9) {
return false;
}
//
// verify health/armor?
//
if((decode[4] & 0xf) >= 9 || (decode[4] >> 4) >= 9) {
return false;
}
//
// verify armortype
//
if((decode[5] & 3) >= 3) {
return false;
}
if(checkOnly) {
return true;
}
bit = 0;
//
// get map
//
gamemap = decode[0] >> 2;
//
// get skill
//
gameskill = decode[0] & 3;
//
// get weapons
//
for(i = 0; i < NUMWEAPONS; i++) {
if(i != wp_fist && i != wp_pistol) {
if(decode[1] & (1 << bit)) {
player->weaponowned[i] = true;
}
bit++;
}
}
//
// get backpack
//
if(decode[5] & 0x80) {
player->backpack = true;
player->maxammo[am_clip] = (maxammo[am_clip] << 1);
player->maxammo[am_shell] = (maxammo[am_shell] << 1);
player->maxammo[am_cell] = (maxammo[am_cell] << 1);
player->maxammo[am_misl] = (maxammo[am_misl] << 1);
}
//
// get ammo
//
player->ammo[am_clip] = M_DecodePassItem(decode[2] >> 4, player->maxammo[am_clip]);
player->ammo[am_shell] = M_DecodePassItem(decode[2] & 0xf, player->maxammo[am_shell]);
player->ammo[am_cell] = M_DecodePassItem(decode[3] >> 4, player->maxammo[am_cell]);
player->ammo[am_misl] = M_DecodePassItem(decode[3] & 0xf, player->maxammo[am_misl]);
//
// get health
//
player->health = M_DecodePassItem(decode[4] >> 4, 200);
if(player->mo) {
player->mo->health = player->health;
}
//
// getarmor
//
player->armorpoints = M_DecodePassItem(decode[4] & 0xf, 200);
//
// get armor type
//
player->armortype = (decode[5] & 3);
//
// get artifacts
//
player->artifacts = ((decode[5] >> 2) & 7);
//
// set cheat menu if password leads to map 01
//
CON_CvarSetValue(p_features.name, ((decode[0] >> 2) == 1) ? 1.0f : 0.0f);
return true;
}
| gpl-2.0 |
JonnyH/dolphin | Source/Core/DolphinQt/MainWindow.cpp | 2 | 56052 | // Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <QApplication>
#include <QCloseEvent>
#include <QDateTime>
#include <QDir>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QFileDialog>
#include <QFileInfo>
#include <QIcon>
#include <QMimeData>
#include <QProgressDialog>
#include <QStackedWidget>
#include <QVBoxLayout>
#include <QWindow>
#include <future>
#include <optional>
#if defined(__unix__) || defined(__unix) || defined(__APPLE__)
#include <signal.h>
#include "QtUtils/SignalDaemon.h"
#endif
#ifndef WIN32
#include <qpa/qplatformnativeinterface.h>
#endif
#include "Common/ScopeGuard.h"
#include "Common/Version.h"
#include "Common/WindowSystemInfo.h"
#include "Core/Boot/Boot.h"
#include "Core/BootManager.h"
#include "Core/CommonTitles.h"
#include "Core/Config/MainSettings.h"
#include "Core/Config/NetplaySettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/DVD/DVDInterface.h"
#include "Core/HW/GCKeyboard.h"
#include "Core/HW/GCPad.h"
#include "Core/HW/ProcessorInterface.h"
#include "Core/HW/SI/SI_Device.h"
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HotkeyManager.h"
#include "Core/IOS/USB/Bluetooth/BTEmu.h"
#include "Core/IOS/USB/Bluetooth/WiimoteDevice.h"
#include "Core/Movie.h"
#include "Core/NetPlayClient.h"
#include "Core/NetPlayProto.h"
#include "Core/NetPlayServer.h"
#include "Core/State.h"
#include "DiscIO/NANDImporter.h"
#include "DolphinQt/AboutDialog.h"
#include "DolphinQt/CheatsManager.h"
#include "DolphinQt/Config/ControllersWindow.h"
#include "DolphinQt/Config/Graphics/GraphicsWindow.h"
#include "DolphinQt/Config/LogConfigWidget.h"
#include "DolphinQt/Config/LogWidget.h"
#include "DolphinQt/Config/Mapping/MappingWindow.h"
#include "DolphinQt/Config/SettingsWindow.h"
#include "DolphinQt/Debugger/BreakpointWidget.h"
#include "DolphinQt/Debugger/CodeViewWidget.h"
#include "DolphinQt/Debugger/CodeWidget.h"
#include "DolphinQt/Debugger/JITWidget.h"
#include "DolphinQt/Debugger/MemoryWidget.h"
#include "DolphinQt/Debugger/RegisterWidget.h"
#include "DolphinQt/Debugger/WatchWidget.h"
#include "DolphinQt/DiscordHandler.h"
#include "DolphinQt/FIFO/FIFOPlayerWindow.h"
#include "DolphinQt/GCMemcardManager.h"
#include "DolphinQt/GameList/GameList.h"
#include "DolphinQt/Host.h"
#include "DolphinQt/HotkeyScheduler.h"
#include "DolphinQt/MainWindow.h"
#include "DolphinQt/MenuBar.h"
#include "DolphinQt/NetPlay/NetPlayBrowser.h"
#include "DolphinQt/NetPlay/NetPlayDialog.h"
#include "DolphinQt/NetPlay/NetPlaySetupDialog.h"
#include "DolphinQt/QtUtils/FileOpenEventFilter.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/QtUtils/QueueOnObject.h"
#include "DolphinQt/QtUtils/RunOnObject.h"
#include "DolphinQt/QtUtils/WindowActivationEventFilter.h"
#include "DolphinQt/RenderWidget.h"
#include "DolphinQt/ResourcePackManager.h"
#include "DolphinQt/Resources.h"
#include "DolphinQt/SearchBar.h"
#include "DolphinQt/Settings.h"
#include "DolphinQt/TAS/GCTASInputWindow.h"
#include "DolphinQt/TAS/WiiTASInputWindow.h"
#include "DolphinQt/ToolBar.h"
#include "DolphinQt/WiiUpdate.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "UICommon/DiscordPresence.h"
#include "UICommon/GameFile.h"
#include "UICommon/ResourcePack/Manager.h"
#include "UICommon/ResourcePack/Manifest.h"
#include "UICommon/ResourcePack/ResourcePack.h"
#include "UICommon/UICommon.h"
#include "VideoCommon/NetPlayChatUI.h"
#include "VideoCommon/VideoConfig.h"
#if defined(HAVE_XRANDR) && HAVE_XRANDR
#include "UICommon/X11Utils.h"
// This #define within X11/X.h conflicts with our WiimoteSource enum.
#undef None
#endif
#if defined(__unix__) || defined(__unix) || defined(__APPLE__)
void MainWindow::OnSignal()
{
close();
}
static void InstallSignalHandler()
{
struct sigaction sa;
sa.sa_handler = &SignalDaemon::HandleInterrupt;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESETHAND;
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
}
#endif
static WindowSystemType GetWindowSystemType()
{
// Determine WSI type based on Qt platform.
QString platform_name = QGuiApplication::platformName();
if (platform_name == QStringLiteral("windows"))
return WindowSystemType::Windows;
else if (platform_name == QStringLiteral("cocoa"))
return WindowSystemType::MacOS;
else if (platform_name == QStringLiteral("xcb"))
return WindowSystemType::X11;
else if (platform_name == QStringLiteral("wayland"))
return WindowSystemType::Wayland;
ModalMessageBox::critical(
nullptr, QStringLiteral("Error"),
QString::asprintf("Unknown Qt platform: %s", platform_name.toStdString().c_str()));
return WindowSystemType::Headless;
}
static WindowSystemInfo GetWindowSystemInfo(QWindow* window)
{
WindowSystemInfo wsi;
wsi.type = GetWindowSystemType();
// Our Win32 Qt external doesn't have the private API.
#if defined(WIN32) || defined(__APPLE__)
wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
#else
QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface();
wsi.display_connection = pni->nativeResourceForWindow("display", window);
if (wsi.type == WindowSystemType::Wayland)
wsi.render_surface = window ? pni->nativeResourceForWindow("surface", window) : nullptr;
else
wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
#endif
wsi.render_surface_scale = window ? static_cast<float>(window->devicePixelRatio()) : 1.0f;
return wsi;
}
static std::vector<std::string> StringListToStdVector(QStringList list)
{
std::vector<std::string> result;
result.reserve(list.size());
for (const QString& s : list)
result.push_back(s.toStdString());
return result;
}
MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters,
const std::string& movie_path)
: QMainWindow(nullptr)
{
setWindowTitle(QString::fromStdString(Common::scm_rev_str));
setWindowIcon(Resources::GetAppIcon());
setUnifiedTitleAndToolBarOnMac(true);
setAcceptDrops(true);
setAttribute(Qt::WA_NativeWindow);
InitControllers();
CreateComponents();
ConnectGameList();
ConnectHost();
ConnectToolBar();
ConnectRenderWidget();
ConnectStack();
ConnectMenuBar();
ConnectHotkeys();
InitCoreCallbacks();
NetPlayInit();
#if defined(__unix__) || defined(__unix) || defined(__APPLE__)
auto* daemon = new SignalDaemon(this);
connect(daemon, &SignalDaemon::InterruptReceived, this, &MainWindow::OnSignal);
InstallSignalHandler();
#endif
if (boot_parameters)
{
m_pending_boot = std::move(boot_parameters);
if (!movie_path.empty())
{
if (Movie::PlayInput(movie_path, &m_pending_boot->savestate_path))
emit RecordingStatusChanged(true);
}
}
QSettings& settings = Settings::GetQSettings();
restoreState(settings.value(QStringLiteral("mainwindow/state")).toByteArray());
restoreGeometry(settings.value(QStringLiteral("mainwindow/geometry")).toByteArray());
m_render_widget_geometry = settings.value(QStringLiteral("renderwidget/geometry")).toByteArray();
// Restoring of window states can sometimes go wrong, resulting in widgets being visible when they
// shouldn't be so we have to reapply all our rules afterwards.
Settings::Instance().RefreshWidgetVisibility();
if (!ResourcePack::Init())
ModalMessageBox::critical(this, tr("Error"),
tr("Error occured while loading some texture packs"));
for (auto& pack : ResourcePack::GetPacks())
{
if (!pack.IsValid())
{
ModalMessageBox::critical(this, tr("Error"),
tr("Invalid Pack %1 provided: %2")
.arg(QString::fromStdString(pack.GetPath()))
.arg(QString::fromStdString(pack.GetError())));
return;
}
}
}
MainWindow::~MainWindow()
{
// Shut down NetPlay first to avoid race condition segfault
Settings::Instance().ResetNetPlayClient();
Settings::Instance().ResetNetPlayServer();
delete m_render_widget;
delete m_netplay_dialog;
for (int i = 0; i < 4; i++)
{
delete m_gc_tas_input_windows[i];
delete m_wii_tas_input_windows[i];
}
ShutdownControllers();
QSettings& settings = Settings::GetQSettings();
settings.setValue(QStringLiteral("mainwindow/state"), saveState());
settings.setValue(QStringLiteral("mainwindow/geometry"), saveGeometry());
settings.setValue(QStringLiteral("renderwidget/geometry"), m_render_widget_geometry);
Config::Save();
}
void MainWindow::InitControllers()
{
if (g_controller_interface.IsInit())
return;
g_controller_interface.Initialize(GetWindowSystemInfo(windowHandle()));
Pad::Initialize();
Keyboard::Initialize();
Wiimote::Initialize(Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES);
m_hotkey_scheduler = new HotkeyScheduler();
m_hotkey_scheduler->Start();
// Defaults won't work reliabily without loading and saving the config first
Wiimote::LoadConfig();
Wiimote::GetConfig()->SaveConfig();
Pad::LoadConfig();
Pad::GetConfig()->SaveConfig();
Keyboard::LoadConfig();
Keyboard::GetConfig()->SaveConfig();
}
void MainWindow::ShutdownControllers()
{
m_hotkey_scheduler->Stop();
Pad::Shutdown();
Keyboard::Shutdown();
Wiimote::Shutdown();
HotkeyManagerEmu::Shutdown();
g_controller_interface.Shutdown();
m_hotkey_scheduler->deleteLater();
}
void MainWindow::InitCoreCallbacks()
{
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, [=](Core::State state) {
if (state == Core::State::Uninitialized)
OnStopComplete();
if (state != Core::State::Uninitialized && NetPlay::IsNetPlayRunning() && m_controllers_window)
m_controllers_window->reject();
if (state == Core::State::Running && m_fullscreen_requested)
{
FullScreen();
m_fullscreen_requested = false;
}
});
installEventFilter(this);
m_render_widget->installEventFilter(this);
// Handle file open events
auto* filter = new FileOpenEventFilter(QGuiApplication::instance());
connect(filter, &FileOpenEventFilter::fileOpened, this, [=](const QString& file_name) {
StartGame(BootParameters::GenerateFromFile(file_name.toStdString()));
});
}
static void InstallHotkeyFilter(QWidget* dialog)
{
auto* filter = new WindowActivationEventFilter(dialog);
dialog->installEventFilter(filter);
filter->connect(filter, &WindowActivationEventFilter::windowDeactivated,
[] { HotkeyManagerEmu::Enable(true); });
filter->connect(filter, &WindowActivationEventFilter::windowActivated,
[] { HotkeyManagerEmu::Enable(false); });
}
void MainWindow::CreateComponents()
{
m_menu_bar = new MenuBar(this);
m_tool_bar = new ToolBar(this);
m_search_bar = new SearchBar(this);
m_game_list = new GameList(this);
m_render_widget = new RenderWidget;
m_stack = new QStackedWidget(this);
for (int i = 0; i < 4; i++)
{
m_gc_tas_input_windows[i] = new GCTASInputWindow(nullptr, i);
m_wii_tas_input_windows[i] = new WiiTASInputWindow(nullptr, i);
}
Movie::SetGCInputManip([this](GCPadStatus* pad_status, int controller_id) {
m_gc_tas_input_windows[controller_id]->GetValues(pad_status);
});
Movie::SetWiiInputManip([this](WiimoteCommon::DataReportBuilder& rpt, int controller_id, int ext,
const WiimoteEmu::EncryptionKey& key) {
m_wii_tas_input_windows[controller_id]->GetValues(rpt, ext, key);
});
m_jit_widget = new JITWidget(this);
m_log_widget = new LogWidget(this);
m_log_config_widget = new LogConfigWidget(this);
m_memory_widget = new MemoryWidget(this);
m_register_widget = new RegisterWidget(this);
m_watch_widget = new WatchWidget(this);
m_breakpoint_widget = new BreakpointWidget(this);
m_code_widget = new CodeWidget(this);
m_cheats_manager = new CheatsManager(this);
connect(m_watch_widget, &WatchWidget::RequestMemoryBreakpoint,
[this](u32 addr) { m_breakpoint_widget->AddAddressMBP(addr); });
connect(m_register_widget, &RegisterWidget::RequestMemoryBreakpoint,
[this](u32 addr) { m_breakpoint_widget->AddAddressMBP(addr); });
connect(m_register_widget, &RegisterWidget::RequestViewInMemory, m_memory_widget,
[this](u32 addr) { m_memory_widget->SetAddress(addr); });
connect(m_register_widget, &RegisterWidget::RequestViewInCode, m_code_widget, [this](u32 addr) {
m_code_widget->SetAddress(addr, CodeViewWidget::SetAddressUpdate::WithUpdate);
});
connect(m_code_widget, &CodeWidget::BreakpointsChanged, m_breakpoint_widget,
&BreakpointWidget::Update);
connect(m_code_widget, &CodeWidget::RequestPPCComparison, m_jit_widget, &JITWidget::Compare);
connect(m_code_widget, &CodeWidget::ShowMemory, m_memory_widget, &MemoryWidget::SetAddress);
connect(m_memory_widget, &MemoryWidget::BreakpointsChanged, m_breakpoint_widget,
&BreakpointWidget::Update);
connect(m_memory_widget, &MemoryWidget::ShowCode, m_code_widget, [this](u32 address) {
m_code_widget->SetAddress(address, CodeViewWidget::SetAddressUpdate::WithUpdate);
});
connect(m_breakpoint_widget, &BreakpointWidget::BreakpointsChanged, m_code_widget,
&CodeWidget::Update);
connect(m_breakpoint_widget, &BreakpointWidget::BreakpointsChanged, m_memory_widget,
&MemoryWidget::Update);
connect(m_breakpoint_widget, &BreakpointWidget::SelectedBreakpoint, [this](u32 address) {
if (Core::GetState() == Core::State::Paused)
m_code_widget->SetAddress(address, CodeViewWidget::SetAddressUpdate::WithUpdate);
});
}
void MainWindow::ConnectMenuBar()
{
setMenuBar(m_menu_bar);
// File
connect(m_menu_bar, &MenuBar::Open, this, &MainWindow::Open);
connect(m_menu_bar, &MenuBar::Exit, this, &MainWindow::close);
connect(m_menu_bar, &MenuBar::EjectDisc, this, &MainWindow::EjectDisc);
connect(m_menu_bar, &MenuBar::ChangeDisc, this, &MainWindow::ChangeDisc);
connect(m_menu_bar, &MenuBar::BootDVDBackup, this,
[this](const QString& drive) { StartGame(drive, ScanForSecondDisc::No); });
// Emulation
connect(m_menu_bar, &MenuBar::Pause, this, &MainWindow::Pause);
connect(m_menu_bar, &MenuBar::Play, this, [this]() { Play(); });
connect(m_menu_bar, &MenuBar::Stop, this, &MainWindow::RequestStop);
connect(m_menu_bar, &MenuBar::Reset, this, &MainWindow::Reset);
connect(m_menu_bar, &MenuBar::Fullscreen, this, &MainWindow::FullScreen);
connect(m_menu_bar, &MenuBar::FrameAdvance, this, &MainWindow::FrameAdvance);
connect(m_menu_bar, &MenuBar::Screenshot, this, &MainWindow::ScreenShot);
connect(m_menu_bar, &MenuBar::StateLoad, this, &MainWindow::StateLoad);
connect(m_menu_bar, &MenuBar::StateSave, this, &MainWindow::StateSave);
connect(m_menu_bar, &MenuBar::StateLoadSlot, this, &MainWindow::StateLoadSlot);
connect(m_menu_bar, &MenuBar::StateSaveSlot, this, &MainWindow::StateSaveSlot);
connect(m_menu_bar, &MenuBar::StateLoadSlotAt, this, &MainWindow::StateLoadSlotAt);
connect(m_menu_bar, &MenuBar::StateSaveSlotAt, this, &MainWindow::StateSaveSlotAt);
connect(m_menu_bar, &MenuBar::StateLoadUndo, this, &MainWindow::StateLoadUndo);
connect(m_menu_bar, &MenuBar::StateSaveUndo, this, &MainWindow::StateSaveUndo);
connect(m_menu_bar, &MenuBar::StateSaveOldest, this, &MainWindow::StateSaveOldest);
connect(m_menu_bar, &MenuBar::SetStateSlot, this, &MainWindow::SetStateSlot);
// Options
connect(m_menu_bar, &MenuBar::Configure, this, &MainWindow::ShowSettingsWindow);
connect(m_menu_bar, &MenuBar::ConfigureGraphics, this, &MainWindow::ShowGraphicsWindow);
connect(m_menu_bar, &MenuBar::ConfigureAudio, this, &MainWindow::ShowAudioWindow);
connect(m_menu_bar, &MenuBar::ConfigureControllers, this, &MainWindow::ShowControllersWindow);
connect(m_menu_bar, &MenuBar::ConfigureHotkeys, this, &MainWindow::ShowHotkeyDialog);
// Tools
connect(m_menu_bar, &MenuBar::ShowMemcardManager, this, &MainWindow::ShowMemcardManager);
connect(m_menu_bar, &MenuBar::ShowResourcePackManager, this,
&MainWindow::ShowResourcePackManager);
connect(m_menu_bar, &MenuBar::ShowCheatsManager, this, &MainWindow::ShowCheatsManager);
connect(m_menu_bar, &MenuBar::BootGameCubeIPL, this, &MainWindow::OnBootGameCubeIPL);
connect(m_menu_bar, &MenuBar::ImportNANDBackup, this, &MainWindow::OnImportNANDBackup);
connect(m_menu_bar, &MenuBar::PerformOnlineUpdate, this, &MainWindow::PerformOnlineUpdate);
connect(m_menu_bar, &MenuBar::BootWiiSystemMenu, this, &MainWindow::BootWiiSystemMenu);
connect(m_menu_bar, &MenuBar::StartNetPlay, this, &MainWindow::ShowNetPlaySetupDialog);
connect(m_menu_bar, &MenuBar::BrowseNetPlay, this, &MainWindow::ShowNetPlayBrowser);
connect(m_menu_bar, &MenuBar::ShowFIFOPlayer, this, &MainWindow::ShowFIFOPlayer);
connect(m_menu_bar, &MenuBar::ConnectWiiRemote, this, &MainWindow::OnConnectWiiRemote);
// Movie
connect(m_menu_bar, &MenuBar::PlayRecording, this, &MainWindow::OnPlayRecording);
connect(m_menu_bar, &MenuBar::StartRecording, this, &MainWindow::OnStartRecording);
connect(m_menu_bar, &MenuBar::StopRecording, this, &MainWindow::OnStopRecording);
connect(m_menu_bar, &MenuBar::ExportRecording, this, &MainWindow::OnExportRecording);
connect(m_menu_bar, &MenuBar::ShowTASInput, this, &MainWindow::ShowTASInput);
// View
connect(m_menu_bar, &MenuBar::ShowList, m_game_list, &GameList::SetListView);
connect(m_menu_bar, &MenuBar::ShowGrid, m_game_list, &GameList::SetGridView);
connect(m_menu_bar, &MenuBar::PurgeGameListCache, m_game_list, &GameList::PurgeCache);
connect(m_menu_bar, &MenuBar::ShowSearch, m_search_bar, &SearchBar::Show);
connect(m_menu_bar, &MenuBar::ColumnVisibilityToggled, m_game_list,
&GameList::OnColumnVisibilityToggled);
connect(m_menu_bar, &MenuBar::GameListPlatformVisibilityToggled, m_game_list,
&GameList::OnGameListVisibilityChanged);
connect(m_menu_bar, &MenuBar::GameListRegionVisibilityToggled, m_game_list,
&GameList::OnGameListVisibilityChanged);
connect(m_menu_bar, &MenuBar::ShowAboutDialog, this, &MainWindow::ShowAboutDialog);
connect(m_game_list, &GameList::SelectionChanged, m_menu_bar, &MenuBar::SelectionChanged);
connect(this, &MainWindow::ReadOnlyModeChanged, m_menu_bar, &MenuBar::ReadOnlyModeChanged);
connect(this, &MainWindow::RecordingStatusChanged, m_menu_bar, &MenuBar::RecordingStatusChanged);
// Symbols
connect(m_menu_bar, &MenuBar::NotifySymbolsUpdated, [this] {
m_code_widget->UpdateSymbols();
m_code_widget->Update();
});
}
void MainWindow::ConnectHotkeys()
{
connect(m_hotkey_scheduler, &HotkeyScheduler::Open, this, &MainWindow::Open);
connect(m_hotkey_scheduler, &HotkeyScheduler::ChangeDisc, this, &MainWindow::ChangeDisc);
connect(m_hotkey_scheduler, &HotkeyScheduler::EjectDisc, this, &MainWindow::EjectDisc);
connect(m_hotkey_scheduler, &HotkeyScheduler::ExitHotkey, this, &MainWindow::close);
connect(m_hotkey_scheduler, &HotkeyScheduler::TogglePauseHotkey, this, &MainWindow::TogglePause);
connect(m_hotkey_scheduler, &HotkeyScheduler::ActivateChat, this, &MainWindow::OnActivateChat);
connect(m_hotkey_scheduler, &HotkeyScheduler::RequestGolfControl, this,
&MainWindow::OnRequestGolfControl);
connect(m_hotkey_scheduler, &HotkeyScheduler::RefreshGameListHotkey, this,
&MainWindow::RefreshGameList);
connect(m_hotkey_scheduler, &HotkeyScheduler::StopHotkey, this, &MainWindow::RequestStop);
connect(m_hotkey_scheduler, &HotkeyScheduler::ResetHotkey, this, &MainWindow::Reset);
connect(m_hotkey_scheduler, &HotkeyScheduler::ScreenShotHotkey, this, &MainWindow::ScreenShot);
connect(m_hotkey_scheduler, &HotkeyScheduler::FullScreenHotkey, this, &MainWindow::FullScreen);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateLoadSlot, this, &MainWindow::StateLoadSlotAt);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateSaveSlot, this, &MainWindow::StateSaveSlotAt);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateLoadLastSaved, this,
&MainWindow::StateLoadLastSavedAt);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateLoadUndo, this, &MainWindow::StateLoadUndo);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateSaveUndo, this, &MainWindow::StateSaveUndo);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateSaveOldest, this,
&MainWindow::StateSaveOldest);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateSaveFile, this, &MainWindow::StateSave);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateLoadFile, this, &MainWindow::StateLoad);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateLoadSlotHotkey, this,
&MainWindow::StateLoadSlot);
connect(m_hotkey_scheduler, &HotkeyScheduler::StateSaveSlotHotkey, this,
&MainWindow::StateSaveSlot);
connect(m_hotkey_scheduler, &HotkeyScheduler::SetStateSlotHotkey, this,
&MainWindow::SetStateSlot);
connect(m_hotkey_scheduler, &HotkeyScheduler::StartRecording, this,
&MainWindow::OnStartRecording);
connect(m_hotkey_scheduler, &HotkeyScheduler::ExportRecording, this,
&MainWindow::OnExportRecording);
connect(m_hotkey_scheduler, &HotkeyScheduler::ConnectWiiRemote, this,
&MainWindow::OnConnectWiiRemote);
connect(m_hotkey_scheduler, &HotkeyScheduler::ToggleReadOnlyMode, [this] {
bool read_only = !Movie::IsReadOnly();
Movie::SetReadOnly(read_only);
emit ReadOnlyModeChanged(read_only);
});
connect(m_hotkey_scheduler, &HotkeyScheduler::Step, m_code_widget, &CodeWidget::Step);
connect(m_hotkey_scheduler, &HotkeyScheduler::StepOver, m_code_widget, &CodeWidget::StepOver);
connect(m_hotkey_scheduler, &HotkeyScheduler::StepOut, m_code_widget, &CodeWidget::StepOut);
connect(m_hotkey_scheduler, &HotkeyScheduler::Skip, m_code_widget, &CodeWidget::Skip);
connect(m_hotkey_scheduler, &HotkeyScheduler::ShowPC, m_code_widget, &CodeWidget::ShowPC);
connect(m_hotkey_scheduler, &HotkeyScheduler::SetPC, m_code_widget, &CodeWidget::SetPC);
connect(m_hotkey_scheduler, &HotkeyScheduler::ToggleBreakpoint, m_code_widget,
&CodeWidget::ToggleBreakpoint);
connect(m_hotkey_scheduler, &HotkeyScheduler::AddBreakpoint, m_code_widget,
&CodeWidget::AddBreakpoint);
}
void MainWindow::ConnectToolBar()
{
addToolBar(m_tool_bar);
connect(m_tool_bar, &ToolBar::OpenPressed, this, &MainWindow::Open);
connect(m_tool_bar, &ToolBar::RefreshPressed, this, &MainWindow::RefreshGameList);
connect(m_tool_bar, &ToolBar::PlayPressed, this, [this]() { Play(); });
connect(m_tool_bar, &ToolBar::PausePressed, this, &MainWindow::Pause);
connect(m_tool_bar, &ToolBar::StopPressed, this, &MainWindow::RequestStop);
connect(m_tool_bar, &ToolBar::FullScreenPressed, this, &MainWindow::FullScreen);
connect(m_tool_bar, &ToolBar::ScreenShotPressed, this, &MainWindow::ScreenShot);
connect(m_tool_bar, &ToolBar::SettingsPressed, this, &MainWindow::ShowSettingsWindow);
connect(m_tool_bar, &ToolBar::ControllersPressed, this, &MainWindow::ShowControllersWindow);
connect(m_tool_bar, &ToolBar::GraphicsPressed, this, &MainWindow::ShowGraphicsWindow);
connect(m_tool_bar, &ToolBar::StepPressed, m_code_widget, &CodeWidget::Step);
connect(m_tool_bar, &ToolBar::StepOverPressed, m_code_widget, &CodeWidget::StepOver);
connect(m_tool_bar, &ToolBar::StepOutPressed, m_code_widget, &CodeWidget::StepOut);
connect(m_tool_bar, &ToolBar::SkipPressed, m_code_widget, &CodeWidget::Skip);
connect(m_tool_bar, &ToolBar::ShowPCPressed, m_code_widget, &CodeWidget::ShowPC);
connect(m_tool_bar, &ToolBar::SetPCPressed, m_code_widget, &CodeWidget::SetPC);
}
void MainWindow::ConnectGameList()
{
connect(m_game_list, &GameList::GameSelected, this, [this]() { Play(); });
connect(m_game_list, &GameList::NetPlayHost, this, &MainWindow::NetPlayHost);
connect(m_game_list, &GameList::OpenGeneralSettings, this, &MainWindow::ShowGeneralWindow);
}
void MainWindow::ConnectRenderWidget()
{
m_rendering_to_main = false;
m_render_widget->hide();
connect(m_render_widget, &RenderWidget::Closed, this, &MainWindow::ForceStop);
connect(m_render_widget, &RenderWidget::FocusChanged, this, [this](bool focus) {
if (m_render_widget->isFullScreen())
SetFullScreenResolution(focus);
});
}
void MainWindow::ConnectHost()
{
connect(Host::GetInstance(), &Host::UpdateProgressDialog, this,
&MainWindow::OnUpdateProgressDialog);
connect(Host::GetInstance(), &Host::RequestStop, this, &MainWindow::RequestStop);
}
void MainWindow::ConnectStack()
{
auto* widget = new QWidget;
auto* layout = new QVBoxLayout;
widget->setLayout(layout);
layout->addWidget(m_game_list);
layout->addWidget(m_search_bar);
layout->setMargin(0);
connect(m_search_bar, &SearchBar::Search, m_game_list, &GameList::SetSearchTerm);
m_stack->addWidget(widget);
setCentralWidget(m_stack);
setDockOptions(DockOption::AllowNestedDocks | DockOption::AllowTabbedDocks);
setTabPosition(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea, QTabWidget::North);
addDockWidget(Qt::LeftDockWidgetArea, m_log_widget);
addDockWidget(Qt::LeftDockWidgetArea, m_log_config_widget);
addDockWidget(Qt::LeftDockWidgetArea, m_code_widget);
addDockWidget(Qt::LeftDockWidgetArea, m_register_widget);
addDockWidget(Qt::LeftDockWidgetArea, m_watch_widget);
addDockWidget(Qt::LeftDockWidgetArea, m_breakpoint_widget);
addDockWidget(Qt::LeftDockWidgetArea, m_memory_widget);
addDockWidget(Qt::LeftDockWidgetArea, m_jit_widget);
tabifyDockWidget(m_log_widget, m_log_config_widget);
tabifyDockWidget(m_log_widget, m_code_widget);
tabifyDockWidget(m_log_widget, m_register_widget);
tabifyDockWidget(m_log_widget, m_watch_widget);
tabifyDockWidget(m_log_widget, m_breakpoint_widget);
tabifyDockWidget(m_log_widget, m_memory_widget);
tabifyDockWidget(m_log_widget, m_jit_widget);
}
void MainWindow::RefreshGameList()
{
Settings::Instance().ReloadTitleDB();
Settings::Instance().RefreshGameList();
}
QStringList MainWindow::PromptFileNames()
{
auto& settings = Settings::Instance().GetQSettings();
QStringList paths = QFileDialog::getOpenFileNames(
this, tr("Select a File"),
settings.value(QStringLiteral("mainwindow/lastdir"), QString{}).toString(),
tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wad *.dff *.m3u);;"
"All Files (*)"));
if (!paths.isEmpty())
{
settings.setValue(QStringLiteral("mainwindow/lastdir"),
QFileInfo(paths.front()).absoluteDir().absolutePath());
}
return paths;
}
void MainWindow::ChangeDisc()
{
std::vector<std::string> paths = StringListToStdVector(PromptFileNames());
if (!paths.empty())
Core::RunAsCPUThread([&paths] { DVDInterface::ChangeDisc(paths); });
}
void MainWindow::EjectDisc()
{
Core::RunAsCPUThread([] { DVDInterface::EjectDisc(DVDInterface::EjectCause::User); });
}
void MainWindow::Open()
{
QStringList files = PromptFileNames();
if (!files.isEmpty())
StartGame(StringListToStdVector(files));
}
void MainWindow::Play(const std::optional<std::string>& savestate_path)
{
// If we're in a paused game, start it up again.
// Otherwise, play the selected game, if there is one.
// Otherwise, play the default game.
// Otherwise, play the last played game, if there is one.
// Otherwise, prompt for a new game.
if (Core::GetState() == Core::State::Paused)
{
Core::SetState(Core::State::Running);
}
else
{
std::shared_ptr<const UICommon::GameFile> selection = m_game_list->GetSelectedGame();
if (selection)
{
StartGame(selection->GetFilePath(), ScanForSecondDisc::Yes, savestate_path);
EnableScreenSaver(false);
}
else
{
const QString default_path = QString::fromStdString(Config::Get(Config::MAIN_DEFAULT_ISO));
if (!default_path.isEmpty() && QFile::exists(default_path))
{
StartGame(default_path, ScanForSecondDisc::Yes, savestate_path);
EnableScreenSaver(false);
}
else
{
Open();
}
}
}
}
void MainWindow::Pause()
{
Core::SetState(Core::State::Paused);
}
void MainWindow::TogglePause()
{
if (Core::GetState() == Core::State::Paused)
{
Play();
}
else
{
Pause();
}
}
void MainWindow::OnStopComplete()
{
m_stop_requested = false;
HideRenderWidget();
EnableScreenSaver(true);
#ifdef USE_DISCORD_PRESENCE
if (!m_netplay_dialog->isVisible())
Discord::UpdateDiscordPresence();
#endif
SetFullScreenResolution(false);
if (m_exit_requested || Settings::Instance().IsBatchModeEnabled())
QGuiApplication::instance()->quit();
// If the current emulation prevented the booting of another, do that now
if (m_pending_boot != nullptr)
{
StartGame(std::move(m_pending_boot));
m_pending_boot.reset();
}
}
bool MainWindow::RequestStop()
{
if (!Core::IsRunning())
{
Core::QueueHostJob([this] { OnStopComplete(); }, true);
return true;
}
if (!m_render_widget->isFullScreen())
m_render_widget_geometry = m_render_widget->saveGeometry();
else
FullScreen();
if (SConfig::GetInstance().bConfirmStop)
{
if (std::exchange(m_stop_confirm_showing, true))
return true;
Common::ScopeGuard confirm_lock([this] { m_stop_confirm_showing = false; });
const Core::State state = Core::GetState();
// Only pause the game, if NetPlay is not running
bool pause = !Settings::Instance().GetNetPlayClient();
if (pause)
Core::SetState(Core::State::Paused);
auto confirm = ModalMessageBox::question(
this, tr("Confirm"),
m_stop_requested ? tr("A shutdown is already in progress. Unsaved data "
"may be lost if you stop the current emulation "
"before it completes. Force stop?") :
tr("Do you want to stop the current emulation?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton, Qt::ApplicationModal);
if (confirm != QMessageBox::Yes)
{
if (pause)
Core::SetState(state);
return false;
}
}
OnStopRecording();
// TODO: Add Debugger shutdown
if (!m_stop_requested && UICommon::TriggerSTMPowerEvent())
{
m_stop_requested = true;
// Unpause because gracefully shutting down needs the game to actually request a shutdown.
// TODO: Do not unpause in debug mode to allow debugging until the complete shutdown.
if (Core::GetState() == Core::State::Paused)
Core::SetState(Core::State::Running);
// Tell NetPlay about the power event
if (NetPlay::IsNetPlayRunning())
NetPlay::SendPowerButtonEvent();
return true;
}
ForceStop();
#ifdef Q_OS_WIN
// Allow windows to idle or turn off display again
SetThreadExecutionState(ES_CONTINUOUS);
#endif
return true;
}
void MainWindow::ForceStop()
{
Core::Stop();
}
void MainWindow::Reset()
{
if (Movie::IsRecordingInput())
Movie::SetReset(true);
ProcessorInterface::ResetButton_Tap();
}
void MainWindow::FrameAdvance()
{
Core::DoFrameStep();
}
void MainWindow::FullScreen()
{
// If the render widget is fullscreen we want to reset it to whatever is in
// settings. If it's set to be fullscreen then it just remakes the window,
// which probably isn't ideal.
bool was_fullscreen = m_render_widget->isFullScreen();
if (!was_fullscreen)
m_render_widget_geometry = m_render_widget->saveGeometry();
HideRenderWidget(false);
SetFullScreenResolution(!was_fullscreen);
if (was_fullscreen)
{
ShowRenderWidget();
}
else
{
m_render_widget->showFullScreen();
}
}
void MainWindow::ScreenShot()
{
Core::SaveScreenShot();
}
void MainWindow::ScanForSecondDiscAndStartGame(const UICommon::GameFile& game,
const std::optional<std::string>& savestate_path)
{
auto second_game = m_game_list->FindSecondDisc(game);
std::vector<std::string> paths = {game.GetFilePath()};
if (second_game != nullptr)
paths.push_back(second_game->GetFilePath());
StartGame(paths, savestate_path);
}
void MainWindow::StartGame(const QString& path, ScanForSecondDisc scan,
const std::optional<std::string>& savestate_path)
{
StartGame(path.toStdString(), scan, savestate_path);
}
void MainWindow::StartGame(const std::string& path, ScanForSecondDisc scan,
const std::optional<std::string>& savestate_path)
{
if (scan == ScanForSecondDisc::Yes)
{
std::shared_ptr<const UICommon::GameFile> game = m_game_list->FindGame(path);
if (game != nullptr)
{
ScanForSecondDiscAndStartGame(*game, savestate_path);
return;
}
}
StartGame(BootParameters::GenerateFromFile(path, savestate_path));
}
void MainWindow::StartGame(const std::vector<std::string>& paths,
const std::optional<std::string>& savestate_path)
{
StartGame(BootParameters::GenerateFromFile(paths, savestate_path));
}
void MainWindow::StartGame(std::unique_ptr<BootParameters>&& parameters)
{
// If we're running, only start a new game once we've stopped the last.
if (Core::GetState() != Core::State::Uninitialized)
{
if (!RequestStop())
return;
// As long as the shutdown isn't complete, we can't boot, so let's boot later
m_pending_boot = std::move(parameters);
return;
}
// We need the render widget before booting.
ShowRenderWidget();
// Boot up, show an error if it fails to load the game.
if (!BootManager::BootCore(std::move(parameters),
GetWindowSystemInfo(m_render_widget->windowHandle())))
{
ModalMessageBox::critical(this, tr("Error"), tr("Failed to init core"), QMessageBox::Ok);
HideRenderWidget();
return;
}
#ifdef USE_DISCORD_PRESENCE
if (!NetPlay::IsNetPlayRunning())
Discord::UpdateDiscordPresence();
#endif
if (Config::Get(Config::MAIN_FULLSCREEN))
m_fullscreen_requested = true;
#ifdef Q_OS_WIN
// Prevents Windows from sleeping, turning off the display, or idling
EXECUTION_STATE shouldScreenSave =
Config::Get(Config::MAIN_DISABLE_SCREENSAVER) ? ES_DISPLAY_REQUIRED : 0;
SetThreadExecutionState(ES_CONTINUOUS | shouldScreenSave | ES_SYSTEM_REQUIRED);
#endif
}
void MainWindow::SetFullScreenResolution(bool fullscreen)
{
if (Config::Get(Config::MAIN_FULLSCREEN_DISPLAY_RES) == "Auto")
return;
#ifdef _WIN32
if (!fullscreen)
{
ChangeDisplaySettings(nullptr, CDS_FULLSCREEN);
return;
}
DEVMODE screen_settings;
memset(&screen_settings, 0, sizeof(screen_settings));
screen_settings.dmSize = sizeof(screen_settings);
sscanf(Config::Get(Config::MAIN_FULLSCREEN_DISPLAY_RES).c_str(), "%dx%d",
&screen_settings.dmPelsWidth, &screen_settings.dmPelsHeight);
screen_settings.dmBitsPerPel = 32;
screen_settings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
ChangeDisplaySettings(&screen_settings, CDS_FULLSCREEN);
#elif defined(HAVE_XRANDR) && HAVE_XRANDR
if (m_xrr_config)
m_xrr_config->ToggleDisplayMode(fullscreen);
#endif
}
void MainWindow::ShowRenderWidget()
{
SetFullScreenResolution(false);
Host::GetInstance()->SetRenderFullscreen(false);
if (Config::Get(Config::MAIN_RENDER_TO_MAIN))
{
// If we're rendering to main, add it to the stack and update our title when necessary.
m_rendering_to_main = true;
m_stack->setCurrentIndex(m_stack->addWidget(m_render_widget));
connect(Host::GetInstance(), &Host::RequestTitle, this, &MainWindow::setWindowTitle);
m_stack->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
m_stack->repaint();
Host::GetInstance()->SetRenderFocus(isActiveWindow());
}
else
{
// Otherwise, just show it.
m_rendering_to_main = false;
m_render_widget->showNormal();
m_render_widget->restoreGeometry(m_render_widget_geometry);
}
}
void MainWindow::HideRenderWidget(bool reinit)
{
if (m_rendering_to_main)
{
// Remove the widget from the stack and reparent it to nullptr, so that it can draw
// itself in a new window if it wants. Disconnect the title updates.
m_stack->removeWidget(m_render_widget);
m_render_widget->setParent(nullptr);
m_rendering_to_main = false;
m_stack->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
disconnect(Host::GetInstance(), &Host::RequestTitle, this, &MainWindow::setWindowTitle);
setWindowTitle(QString::fromStdString(Common::scm_rev_str));
}
// The following code works around a driver bug that would lead to Dolphin crashing when changing
// graphics backends (e.g. OpenGL to Vulkan). To avoid this the render widget is (safely)
// recreated
if (reinit)
{
m_render_widget->hide();
disconnect(m_render_widget, &RenderWidget::Closed, this, &MainWindow::ForceStop);
m_render_widget->removeEventFilter(this);
m_render_widget->deleteLater();
m_render_widget = new RenderWidget;
m_render_widget->installEventFilter(this);
connect(m_render_widget, &RenderWidget::Closed, this, &MainWindow::ForceStop);
connect(m_render_widget, &RenderWidget::FocusChanged, this, [this](bool focus) {
if (m_render_widget->isFullScreen())
SetFullScreenResolution(focus);
});
// The controller interface will still be registered to the old render widget, if the core
// has booted. Therefore, we should re-bind it to the main window for now. When the core
// is next started, it will be swapped back to the new render widget.
g_controller_interface.ChangeWindow(GetWindowSystemInfo(windowHandle()).render_surface);
}
}
void MainWindow::ShowControllersWindow()
{
if (!m_controllers_window)
{
m_controllers_window = new ControllersWindow(this);
InstallHotkeyFilter(m_controllers_window);
}
m_controllers_window->show();
m_controllers_window->raise();
m_controllers_window->activateWindow();
}
void MainWindow::ShowSettingsWindow()
{
if (!m_settings_window)
{
m_settings_window = new SettingsWindow(this);
InstallHotkeyFilter(m_settings_window);
}
m_settings_window->show();
m_settings_window->raise();
m_settings_window->activateWindow();
}
void MainWindow::ShowAudioWindow()
{
ShowSettingsWindow();
m_settings_window->SelectAudioPane();
}
void MainWindow::ShowGeneralWindow()
{
ShowSettingsWindow();
m_settings_window->SelectGeneralPane();
}
void MainWindow::ShowAboutDialog()
{
AboutDialog about{this};
about.exec();
}
void MainWindow::ShowHotkeyDialog()
{
if (!m_hotkey_window)
{
m_hotkey_window = new MappingWindow(this, MappingWindow::Type::MAPPING_HOTKEYS, 0);
InstallHotkeyFilter(m_hotkey_window);
}
m_hotkey_window->show();
m_hotkey_window->raise();
m_hotkey_window->activateWindow();
}
void MainWindow::ShowGraphicsWindow()
{
if (!m_graphics_window)
{
#if defined(HAVE_XRANDR) && HAVE_XRANDR
if (GetWindowSystemType() == WindowSystemType::X11)
{
m_xrr_config = std::make_unique<X11Utils::XRRConfiguration>(
static_cast<Display*>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow(
"display", windowHandle())),
winId());
}
m_graphics_window = new GraphicsWindow(m_xrr_config.get(), this);
#else
m_graphics_window = new GraphicsWindow(nullptr, this);
#endif
InstallHotkeyFilter(m_graphics_window);
}
m_graphics_window->show();
m_graphics_window->raise();
m_graphics_window->activateWindow();
}
void MainWindow::ShowNetPlaySetupDialog()
{
m_netplay_setup_dialog->show();
m_netplay_setup_dialog->raise();
m_netplay_setup_dialog->activateWindow();
}
void MainWindow::ShowNetPlayBrowser()
{
auto* browser = new NetPlayBrowser(this);
connect(browser, &NetPlayBrowser::Join, this, &MainWindow::NetPlayJoin);
browser->exec();
}
void MainWindow::ShowFIFOPlayer()
{
if (!m_fifo_window)
{
m_fifo_window = new FIFOPlayerWindow(this);
connect(m_fifo_window, &FIFOPlayerWindow::LoadFIFORequested, this,
[this](const QString& path) { StartGame(path, ScanForSecondDisc::No); });
}
m_fifo_window->show();
m_fifo_window->raise();
m_fifo_window->activateWindow();
}
void MainWindow::StateLoad()
{
QString path = QFileDialog::getOpenFileName(this, tr("Select a File"), QDir::currentPath(),
tr("All Save States (*.sav *.s##);; All Files (*)"));
State::LoadAs(path.toStdString());
}
void MainWindow::StateSave()
{
QString path = QFileDialog::getSaveFileName(this, tr("Select a File"), QDir::currentPath(),
tr("All Save States (*.sav *.s##);; All Files (*)"));
State::SaveAs(path.toStdString());
}
void MainWindow::StateLoadSlot()
{
State::Load(m_state_slot);
}
void MainWindow::StateSaveSlot()
{
State::Save(m_state_slot);
}
void MainWindow::StateLoadSlotAt(int slot)
{
State::Load(slot);
}
void MainWindow::StateLoadLastSavedAt(int slot)
{
State::LoadLastSaved(slot);
}
void MainWindow::StateSaveSlotAt(int slot)
{
State::Save(slot);
}
void MainWindow::StateLoadUndo()
{
State::UndoLoadState();
}
void MainWindow::StateSaveUndo()
{
State::UndoSaveState();
}
void MainWindow::StateSaveOldest()
{
State::SaveFirstSaved();
}
void MainWindow::SetStateSlot(int slot)
{
Settings::Instance().SetStateSlot(slot);
m_state_slot = slot;
Core::DisplayMessage(StringFromFormat("Selected slot %d - %s", m_state_slot,
State::GetInfoStringOfSlot(m_state_slot, false).c_str()),
2500);
}
void MainWindow::PerformOnlineUpdate(const std::string& region)
{
WiiUpdate::PerformOnlineUpdate(region, this);
// Since the update may have installed a newer system menu, refresh the tools menu.
m_menu_bar->UpdateToolsMenu(false);
}
void MainWindow::BootWiiSystemMenu()
{
StartGame(std::make_unique<BootParameters>(BootParameters::NANDTitle{Titles::SYSTEM_MENU}));
}
void MainWindow::NetPlayInit()
{
m_netplay_setup_dialog = new NetPlaySetupDialog(this);
m_netplay_dialog = new NetPlayDialog;
#ifdef USE_DISCORD_PRESENCE
m_netplay_discord = new DiscordHandler(this);
#endif
connect(m_netplay_dialog, &NetPlayDialog::Boot, this,
[this](const QString& path) { StartGame(path, ScanForSecondDisc::Yes); });
connect(m_netplay_dialog, &NetPlayDialog::Stop, this, &MainWindow::ForceStop);
connect(m_netplay_dialog, &NetPlayDialog::rejected, this, &MainWindow::NetPlayQuit);
connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Join, this, &MainWindow::NetPlayJoin);
connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Host, this, &MainWindow::NetPlayHost);
#ifdef USE_DISCORD_PRESENCE
connect(m_netplay_discord, &DiscordHandler::Join, this, &MainWindow::NetPlayJoin);
Discord::InitNetPlayFunctionality(*m_netplay_discord);
m_netplay_discord->Start();
#endif
}
bool MainWindow::NetPlayJoin()
{
if (Core::IsRunning())
{
ModalMessageBox::critical(
nullptr, QObject::tr("Error"),
QObject::tr("Can't start a NetPlay Session while a game is still running!"));
return false;
}
if (m_netplay_dialog->isVisible())
{
ModalMessageBox::critical(nullptr, QObject::tr("Error"),
QObject::tr("A NetPlay Session is already in progress!"));
return false;
}
auto server = Settings::Instance().GetNetPlayServer();
// Settings
const std::string traversal_choice = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE);
const bool is_traversal = traversal_choice == "traversal";
std::string host_ip;
u16 host_port;
if (server)
{
host_ip = "127.0.0.1";
host_port = server->GetPort();
}
else
{
host_ip = is_traversal ? Config::Get(Config::NETPLAY_HOST_CODE) :
Config::Get(Config::NETPLAY_ADDRESS);
host_port = Config::Get(Config::NETPLAY_CONNECT_PORT);
}
const std::string traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER);
const u16 traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT);
const std::string nickname = Config::Get(Config::NETPLAY_NICKNAME);
const std::string network_mode = Config::Get(Config::NETPLAY_NETWORK_MODE);
const bool host_input_authority = network_mode == "hostinputauthority" || network_mode == "golf";
if (server)
{
server->SetHostInputAuthority(host_input_authority);
server->AdjustPadBufferSize(Config::Get(Config::NETPLAY_BUFFER_SIZE));
}
// Create Client
const bool is_hosting_netplay = server != nullptr;
Settings::Instance().ResetNetPlayClient(new NetPlay::NetPlayClient(
host_ip, host_port, m_netplay_dialog, nickname,
NetPlay::NetTraversalConfig{is_hosting_netplay ? false : is_traversal, traversal_host,
traversal_port}));
if (!Settings::Instance().GetNetPlayClient()->IsConnected())
{
NetPlayQuit();
return false;
}
if (server != nullptr)
server->SetNetPlayUI(m_netplay_dialog);
m_netplay_setup_dialog->close();
m_netplay_dialog->show(nickname, is_traversal);
return true;
}
bool MainWindow::NetPlayHost(const QString& game_id)
{
if (Core::IsRunning())
{
ModalMessageBox::critical(
nullptr, QObject::tr("Error"),
QObject::tr("Can't start a NetPlay Session while a game is still running!"));
return false;
}
if (m_netplay_dialog->isVisible())
{
ModalMessageBox::critical(nullptr, QObject::tr("Error"),
QObject::tr("A NetPlay Session is already in progress!"));
return false;
}
// Settings
u16 host_port = Config::Get(Config::NETPLAY_HOST_PORT);
const std::string traversal_choice = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE);
const bool is_traversal = traversal_choice == "traversal";
const bool use_upnp = Config::Get(Config::NETPLAY_USE_UPNP);
const std::string traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER);
const u16 traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT);
if (is_traversal)
host_port = Config::Get(Config::NETPLAY_LISTEN_PORT);
// Create Server
Settings::Instance().ResetNetPlayServer(new NetPlay::NetPlayServer(
host_port, use_upnp,
NetPlay::NetTraversalConfig{is_traversal, traversal_host, traversal_port}));
if (!Settings::Instance().GetNetPlayServer()->is_connected)
{
ModalMessageBox::critical(
nullptr, QObject::tr("Failed to open server"),
QObject::tr(
"Failed to listen on port %1. Is another instance of the NetPlay server running?")
.arg(host_port));
NetPlayQuit();
return false;
}
Settings::Instance().GetNetPlayServer()->ChangeGame(game_id.toStdString());
// Join our local server
return NetPlayJoin();
}
void MainWindow::NetPlayQuit()
{
Settings::Instance().ResetNetPlayClient();
Settings::Instance().ResetNetPlayServer();
#ifdef USE_DISCORD_PRESENCE
Discord::UpdateDiscordPresence();
#endif
}
void MainWindow::EnableScreenSaver(bool enable)
{
#if defined(HAVE_XRANDR) && HAVE_XRANDR
if (GetWindowSystemType() == WindowSystemType::X11)
UICommon::EnableScreenSaver(winId(), enable);
#else
UICommon::EnableScreenSaver(enable);
#endif
}
bool MainWindow::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::Close)
{
if (RequestStop() && object == this)
m_exit_requested = true;
static_cast<QCloseEvent*>(event)->ignore();
return true;
}
return false;
}
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1)
event->acceptProposedAction();
}
void MainWindow::dropEvent(QDropEvent* event)
{
const QList<QUrl>& urls = event->mimeData()->urls();
if (urls.empty())
return;
QStringList files;
QStringList folders;
for (const QUrl& url : urls)
{
QFileInfo file_info(url.toLocalFile());
QString path = file_info.filePath();
if (!file_info.exists() || !file_info.isReadable())
{
ModalMessageBox::critical(this, tr("Error"), tr("Failed to open '%1'").arg(path));
return;
}
(file_info.isFile() ? files : folders).append(path);
}
if (!files.isEmpty())
{
StartGame(StringListToStdVector(files));
}
else
{
Settings& settings = Settings::Instance();
const bool show_confirm = !settings.GetPaths().empty();
for (const QString& folder : folders)
{
if (show_confirm)
{
if (ModalMessageBox::question(
this, tr("Confirm"),
tr("Do you want to add \"%1\" to the list of Game Paths?").arg(folder)) !=
QMessageBox::Yes)
return;
}
settings.AddPath(folder);
}
}
}
QSize MainWindow::sizeHint() const
{
return QSize(800, 600);
}
void MainWindow::OnBootGameCubeIPL(DiscIO::Region region)
{
StartGame(std::make_unique<BootParameters>(BootParameters::IPL{region}));
}
void MainWindow::OnImportNANDBackup()
{
auto response = ModalMessageBox::question(
this, tr("Question"),
tr("Merging a new NAND over your currently selected NAND will overwrite any channels "
"and savegames that already exist. This process is not reversible, so it is "
"recommended that you keep backups of both NANDs. Are you sure you want to "
"continue?"));
if (response == QMessageBox::No)
return;
QString file = QFileDialog::getOpenFileName(this, tr("Select the save file"), QDir::currentPath(),
tr("BootMii NAND backup file (*.bin);;"
"All Files (*)"));
if (file.isEmpty())
return;
QProgressDialog* dialog = new QProgressDialog(this);
dialog->setMinimum(0);
dialog->setMaximum(0);
dialog->setLabelText(tr("Importing NAND backup"));
dialog->setCancelButton(nullptr);
auto beginning = QDateTime::currentDateTime().toMSecsSinceEpoch();
auto result = std::async(std::launch::async, [&] {
DiscIO::NANDImporter().ImportNANDBin(
file.toStdString(),
[&dialog, beginning] {
QueueOnObject(dialog, [&dialog, beginning] {
dialog->setLabelText(
tr("Importing NAND backup\n Time elapsed: %1s")
.arg((QDateTime::currentDateTime().toMSecsSinceEpoch() - beginning) / 1000));
});
},
[this] {
std::optional<std::string> keys_file = RunOnObject(this, [this] {
return QFileDialog::getOpenFileName(this, tr("Select the keys file (OTP/SEEPROM dump)"),
QDir::currentPath(),
tr("BootMii keys file (*.bin);;"
"All Files (*)"))
.toStdString();
});
if (keys_file)
return *keys_file;
return std::string("");
});
QueueOnObject(dialog, &QProgressDialog::close);
});
dialog->exec();
result.wait();
m_menu_bar->UpdateToolsMenu(Core::IsRunning());
}
void MainWindow::OnPlayRecording()
{
QString dtm_file = QFileDialog::getOpenFileName(this, tr("Select the Recording File"), QString(),
tr("Dolphin TAS Movies (*.dtm)"));
if (dtm_file.isEmpty())
return;
if (!Movie::IsReadOnly())
{
// let's make the read-only flag consistent at the start of a movie.
Movie::SetReadOnly(true);
emit ReadOnlyModeChanged(true);
}
std::optional<std::string> savestate_path;
if (Movie::PlayInput(dtm_file.toStdString(), &savestate_path))
{
emit RecordingStatusChanged(true);
Play(savestate_path);
}
}
void MainWindow::OnStartRecording()
{
if ((!Core::IsRunningAndStarted() && Core::IsRunning()) || Movie::IsRecordingInput() ||
Movie::IsPlayingInput())
return;
if (Movie::IsReadOnly())
{
// The user just chose to record a movie, so that should take precedence
Movie::SetReadOnly(false);
emit ReadOnlyModeChanged(true);
}
int controllers = 0;
for (int i = 0; i < 4; i++)
{
if (SerialInterface::SIDevice_IsGCController(SConfig::GetInstance().m_SIDevice[i]))
controllers |= (1 << i);
if (WiimoteCommon::GetSource(i) != WiimoteSource::None)
controllers |= (1 << (i + 4));
}
if (Movie::BeginRecordingInput(controllers))
{
emit RecordingStatusChanged(true);
if (!Core::IsRunning())
Play();
}
}
void MainWindow::OnStopRecording()
{
if (Movie::IsRecordingInput())
OnExportRecording();
if (Movie::IsMovieActive())
Movie::EndPlayInput(false);
emit RecordingStatusChanged(false);
}
void MainWindow::OnExportRecording()
{
bool was_paused = Core::GetState() == Core::State::Paused;
if (!was_paused)
Core::SetState(Core::State::Paused);
QString dtm_file = QFileDialog::getSaveFileName(this, tr("Select the Recording File"), QString(),
tr("Dolphin TAS Movies (*.dtm)"));
if (!dtm_file.isEmpty())
Movie::SaveRecording(dtm_file.toStdString());
if (!was_paused)
Core::SetState(Core::State::Running);
}
void MainWindow::OnActivateChat()
{
if (g_netplay_chat_ui)
g_netplay_chat_ui->Activate();
}
void MainWindow::OnRequestGolfControl()
{
auto client = Settings::Instance().GetNetPlayClient();
if (client)
client->RequestGolfControl();
}
void MainWindow::ShowTASInput()
{
for (int i = 0; i < num_gc_controllers; i++)
{
if (SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_NONE &&
SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_GC_GBA)
{
m_gc_tas_input_windows[i]->show();
m_gc_tas_input_windows[i]->raise();
m_gc_tas_input_windows[i]->activateWindow();
}
}
for (int i = 0; i < num_wii_controllers; i++)
{
if (WiimoteCommon::GetSource(i) == WiimoteSource::Emulated &&
(!Core::IsRunning() || SConfig::GetInstance().bWii))
{
m_wii_tas_input_windows[i]->show();
m_wii_tas_input_windows[i]->raise();
m_wii_tas_input_windows[i]->activateWindow();
}
}
}
void MainWindow::OnConnectWiiRemote(int id)
{
const auto ios = IOS::HLE::GetIOS();
if (!ios || SConfig::GetInstance().m_bt_passthrough_enabled)
return;
Core::RunAsCPUThread([&] {
const auto bt = std::static_pointer_cast<IOS::HLE::Device::BluetoothEmu>(
ios->GetDeviceByName("/dev/usb/oh1/57e/305"));
const bool is_connected = bt && bt->AccessWiimoteByIndex(id)->IsConnected();
Wiimote::Connect(id, !is_connected);
});
}
void MainWindow::ShowMemcardManager()
{
GCMemcardManager manager(this);
manager.exec();
}
void MainWindow::ShowResourcePackManager()
{
ResourcePackManager manager(this);
manager.exec();
}
void MainWindow::ShowCheatsManager()
{
m_cheats_manager->show();
}
void MainWindow::OnUpdateProgressDialog(QString title, int progress, int total)
{
if (!m_progress_dialog)
{
m_progress_dialog = new QProgressDialog(m_render_widget, Qt::WindowTitleHint);
m_progress_dialog->show();
m_progress_dialog->setCancelButton(nullptr);
m_progress_dialog->setWindowTitle(tr("Dolphin"));
}
m_progress_dialog->setValue(progress);
m_progress_dialog->setLabelText(title);
m_progress_dialog->setMaximum(total);
if (total < 0 || progress >= total)
{
m_progress_dialog->hide();
m_progress_dialog->deleteLater();
m_progress_dialog = nullptr;
}
}
void MainWindow::Show()
{
if (!Settings::Instance().IsBatchModeEnabled())
QWidget::show();
// If the booting of a game was requested on start up, do that now
if (m_pending_boot != nullptr)
{
StartGame(std::move(m_pending_boot));
m_pending_boot.reset();
}
}
| gpl-2.0 |
mozilla-b2g/kernel_flatfish | drivers/usb/sun7i_usb/manager/usb_msg_center.c | 2 | 9259 | /*
*************************************************************************************
* Linux
* USB Host Controller Driver
*
* (c) Copyright 2006-2012, SoftWinners Co,Ld.
* All Rights Reserved
*
* File Name : usb_msg_center.c
*
* Author : javen
*
* Description : USB 消息分发
*
* History :
* <author> <time> <version > <desc>
* javen 2011-4-14 1.0 create this file
*
*************************************************************************************
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/ioport.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/timer.h>
#include <linux/list.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <asm/byteorder.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>
#include <asm/unaligned.h>
#include <mach/irqs.h>
#include "../include/sw_usb_config.h"
#include "usb_manager.h"
#include "usbc_platform.h"
#include "usb_hw_scan.h"
#include "usb_msg_center.h"
/*
extern int axp_usbvol(void );
extern int axp_usbcur(void);
extern int axp_usbvol_restore(void);
extern int axp_usbcur_restore(void);
*/
static struct usb_msg_center_info g_center_info;
void print_usb_msg(struct usb_msg_center_info * center_info)
{
DMSG_DBG_MANAGER("hw_insmod_host = %d\n", center_info->msg.hw_insmod_host);
DMSG_DBG_MANAGER("hw_rmmod_host = %d\n", center_info->msg.hw_rmmod_host);
DMSG_DBG_MANAGER("hw_insmod_device = %d\n", center_info->msg.hw_insmod_device);
DMSG_DBG_MANAGER("hw_rmmod_device = %d\n", center_info->msg.hw_rmmod_device);
}
enum usb_role get_usb_role(void)
{
return g_center_info.role;
}
static void set_usb_role(struct usb_msg_center_info *center_info, enum usb_role role)
{
center_info->role = role;
return;
}
/*
void app_insmod_usb_host(void)
{
g_center_info.msg.app_insmod_host = 1;
}
void app_rmmod_usb_host(void)
{
g_center_info.msg.app_rmmod_host = 1;
}
void app_insmod_usb_device(void)
{
g_center_info.msg.app_insmod_device = 1;
}
void app_rmmod_usb_device(void)
{
g_center_info.msg.app_rmmod_device = 1;
}
*/
void hw_insmod_usb_host(void)
{
g_center_info.msg.hw_insmod_host = 1;
}
void hw_rmmod_usb_host(void)
{
g_center_info.msg.hw_rmmod_host = 1;
}
void hw_insmod_usb_device(void)
{
g_center_info.msg.hw_insmod_device = 1;
}
void hw_rmmod_usb_device(void)
{
g_center_info.msg.hw_rmmod_device = 1;
}
/*
*******************************************************************************
* modify_msg
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
static void modify_msg(struct usb_msg *msg)
{
if(msg->hw_insmod_host && msg->hw_rmmod_host){
msg->hw_insmod_host = 0;
msg->hw_rmmod_host = 0;
}
if(msg->hw_insmod_device && msg->hw_rmmod_device){
msg->hw_insmod_device = 0;
msg->hw_rmmod_device = 0;
}
return;
}
/*
*******************************************************************************
* insmod_host_driver
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
static void insmod_host_driver(struct usb_msg_center_info *center_info)
{
DMSG_INFO("\n\ninsmod_host_driver\n\n");
set_usb_role(center_info, USB_ROLE_HOST);
sw_usb_host0_enable();
return;
}
/*
*******************************************************************************
* rmmod_host_driver
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
static void rmmod_host_driver(struct usb_msg_center_info *center_info)
{
int ret = 0;
DMSG_INFO("\n\nrmmod_host_driver\n\n");
ret = sw_usb_host0_disable();
if(ret != 0){
DMSG_PANIC("err: disable hcd0 failed\n");
return;
}
set_usb_role(center_info, USB_ROLE_NULL);
return;
}
/*
*******************************************************************************
* insmod_device_driver
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
static void insmod_device_driver(struct usb_msg_center_info *center_info)
{
DMSG_INFO("\n\ninsmod_device_driver\n\n");
//axp_usbvol();
//axp_usbcur();
set_usb_role(center_info, USB_ROLE_DEVICE);
sw_usb_device_enable();
return;
}
/*
*******************************************************************************
* rmmod_device_driver
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
static void rmmod_device_driver(struct usb_msg_center_info *center_info)
{
DMSG_INFO("\n\nrmmod_device_driver\n\n");
set_usb_role(center_info, USB_ROLE_NULL);
sw_usb_device_disable();
//axp_usbcur_restore();
//axp_usbvol_restore();
return;
}
/*
*******************************************************************************
* do_usb_role_null
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
static void do_usb_role_null(struct usb_msg_center_info *center_info)
{
if(center_info->msg.hw_insmod_host){
insmod_host_driver(center_info);
center_info->msg.hw_insmod_host = 0;
goto end;
}
if(center_info->msg.hw_insmod_device){
insmod_device_driver(center_info);
center_info->msg.hw_insmod_device = 0;
goto end;
}
end:
memset(¢er_info->msg, 0, sizeof(struct usb_msg));
return;
}
/*
*******************************************************************************
* do_usb_role_host
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
static void do_usb_role_host(struct usb_msg_center_info *center_info)
{
if(center_info->msg.hw_rmmod_host){
rmmod_host_driver(center_info);
center_info->msg.hw_rmmod_host = 0;
goto end;
}
end:
memset(¢er_info->msg, 0, sizeof(struct usb_msg));
return;
}
/*
*******************************************************************************
* do_usb_role_device
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
static void do_usb_role_device(struct usb_msg_center_info *center_info)
{
if(center_info->msg.hw_rmmod_device){
rmmod_device_driver(center_info);
center_info->msg.hw_rmmod_device = 0;
goto end;
}
end:
memset(¢er_info->msg, 0, sizeof(struct usb_msg));
return;
}
/*
*******************************************************************************
* usb_msg_center
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
void usb_msg_center(struct usb_cfg *cfg)
{
enum usb_role role = USB_ROLE_NULL;
struct usb_msg_center_info * center_info = &g_center_info;
/* receive massage */
print_usb_msg(center_info);
modify_msg(¢er_info->msg);
/* execute cmd */
role = get_usb_role();
DMSG_DBG_MANAGER("role=%d\n", get_usb_role());
switch(role){
case USB_ROLE_NULL:
do_usb_role_null(center_info);
break;
case USB_ROLE_HOST:
do_usb_role_host(center_info);
break;
case USB_ROLE_DEVICE:
do_usb_role_device(center_info);
break;
default:
DMSG_PANIC("ERR: unkown role(%x)\n", role);
}
return;
}
/*
*******************************************************************************
* usb_msg_center_init
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
s32 usb_msg_center_init(struct usb_cfg *cfg)
{
struct usb_msg_center_info *center_info = &g_center_info;
memset(center_info, 0, sizeof(struct usb_msg_center_info));
return 0;
}
/*
*******************************************************************************
* usb_msg_center_exit
*
* Description:
* void
*
* Parameters:
* void
*
* Return value:
* void
*
* note:
* void
*
*******************************************************************************
*/
s32 usb_msg_center_exit(struct usb_cfg *cfg)
{
struct usb_msg_center_info *center_info = &g_center_info;
memset(center_info, 0, sizeof(struct usb_msg_center_info));
return 0;
}
| gpl-2.0 |
sangwook236/general-development-and-testing | sw_dev/cpp/rnd/test/machine_vision/opencv/opencv_hand_pose_estimation.cpp | 2 | 45784 | //#include "stdafx.h"
//#define CV_NO_BACKWARD_COMPATIBILITY
#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <ctime>
namespace my_opencv {
void contour(IplImage *srcImg, IplImage *grayImg);
void make_contour(const cv::Mat &img, const cv::Rect &roi, const int segmentId, std::vector<std::vector<cv::Point> > &contours, std::vector<cv::Vec4i> &hierarchy);
void make_convex_hull(const cv::Mat &img, const cv::Rect &roi, const int segmentId, std::vector<cv::Point> &convexHull);
void find_convexity_defect(CvMemStorage *storage, const std::vector<cv::Point> &contour, const std::vector<cv::Point> &convexHull, const double distanceThreshold, const double depthThreshold, std::vector<std::vector<CvConvexityDefect> > &convexityDefects, std::vector<cv::Point> &convexityDefectPoints);
bool calculate_curvature(const cv::Point2d &v1, const cv::Point2d &v2, double &curvature);
bool find_curvature_points(const std::vector<cv::Point> &fingerContour, const size_t displaceIndex, size_t &minIdx, size_t &maxIdx);
void compute_distance_transform(const cv::Mat &gray, cv::Mat &distanceTransform);
void snake(IplImage *srcImage, IplImage *grayImage);
void segment_motion_using_mhi(const bool useConvexHull, const cv::Mat &prev_gray_img, const cv::Mat &curr_gray_img, cv::Mat &mhi, cv::Mat &segmentMask, std::vector<std::vector<cv::Point> > &pointSets, std::vector<cv::Vec4i> &hierarchy);
} // namespace my_opencv
namespace {
namespace local {
void segment_motion_using_Farneback_motion_estimation(const bool useConvexHull, const cv::Mat &prev_gray_img, const cv::Mat &curr_gray_img, cv::Mat &segmentMask, std::vector<std::vector<cv::Point> > &pointSets, std::vector<cv::Vec4i> &hierarchy)
{
pointSets.clear();
hierarchy.clear();
cv::Mat flow;
cv::calcOpticalFlowFarneback(prev_gray_img, curr_gray_img, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
segmentMask = cv::Mat::zeros(flow.rows, flow.cols, CV_8UC1);
#if 0
const double mag_threshold = 1.0;
for (int r = 0; r < flow.rows; ++r)
for (int c = 0; c < flow.cols; ++c)
{
const cv::Point2f &fxy = flow.at<cv::Point2f>(r, c);
segmentMask.at<unsigned char>(r, c) = (fxy.x*fxy.x + fxy.y*fxy.y > mag_threshold ? 1 : 0);
}
#else
std::multimap<double, cv::Point2i> mag_pos_pairs;
for (int r = 0; r < flow.rows; ++r)
for (int c = 0; c < flow.cols; ++c)
{
const cv::Point2f &fxy = flow.at<cv::Point2f>(r, c);
mag_pos_pairs.insert(std::make_pair(fxy.x*fxy.x + fxy.y*fxy.y, cv::Point2i(c, r)));
}
const double threshold_ratio = 0.2;
const size_t numPairs = mag_pos_pairs.size();
const size_t lower_bound_num = (size_t)std::floor(numPairs * threshold_ratio);
std::multimap<double, cv::Point2i>::iterator itBegin = mag_pos_pairs.begin();
std::advance(itBegin, lower_bound_num);
for (std::multimap<double, cv::Point2i>::iterator it = itBegin; it != mag_pos_pairs.end(); ++it)
segmentMask.at<unsigned char>(it->second.y, it->second.x) = 1;
#endif
if (useConvexHull)
{
std::vector<cv::Point> convexHull;
my_opencv::make_convex_hull(segmentMask, cv::Rect(), 1, convexHull);
if (!convexHull.empty()) pointSets.push_back(convexHull);
}
else
{
my_opencv::make_contour(segmentMask, cv::Rect(), 1, pointSets, hierarchy);
}
}
void findHandContour(const cv::Mat &edgeImg, std::vector<std::vector<cv::Point> > &contours)
{
std::vector<cv::Vec4i> hierarchy;
cv::findContours((cv::Mat &)edgeImg, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
//cv::findContours((cv::Mat &)edgeImg, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
}
void findBetterHandContour(const cv::Size &imgSize, const std::vector<std::vector<cv::Point> > &contours, const std::vector<cv::Point> &convexHull, const size_t contourId, const cv::Point &seed, std::vector<std::vector<cv::Point> > &silhouetteContours)
{
cv::Mat gray(imgSize, CV_8UC1, cv::Scalar::all(0));
{
const cv::Point *h = (const cv::Point *)&convexHull[0];
const size_t num = convexHull.size();
cv::polylines(gray, (const cv::Point **)&h, (int *)&num, 1, true, CV_RGB(128, 128, 128), 1, 8, 0);
cv::drawContours(gray, contours, contourId, CV_RGB(255, 255, 255), 1, 8);
cv::floodFill(gray, seed, CV_RGB(255, 255, 255));
}
gray = gray > 192;
//const cv::Mat &selement = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(3, 3), cv::Point(-1, -1));
const cv::Mat &selement = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5), cv::Point(-1, -1));
//const cv::Mat &selement = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(7, 7), cv::Point(-1, -1));
const int iterations = 1;
cv::morphologyEx(gray, gray, cv::MORPH_OPEN, selement, cv::Point(-1, -1), iterations);
std::vector<cv::Vec4i> hierarchy;
cv::findContours(gray, silhouetteContours, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
}
void findBetterHandContour(const cv::Size &imgSize, const std::vector<cv::Point> &contour, const std::vector<cv::Point> &convexHull, const cv::Point &seed, std::vector<std::vector<cv::Point> > &silhouetteContours)
{
cv::Mat gray(imgSize, CV_8UC1, cv::Scalar::all(0));
{
const cv::Point *h1 = (const cv::Point *)&convexHull[0];
const size_t num1 = convexHull.size();
cv::polylines(gray, (const cv::Point **)&h1, (int *)&num1, 1, true, CV_RGB(128, 128, 128), 1, 8, 0);
const cv::Point *h2 = (const cv::Point *)&contour[0];
const size_t num2 = contour.size();
cv::polylines(gray, (const cv::Point **)&h2, (int *)&num2, 1, true, CV_RGB(255, 255, 255), 1, 8, 0);
cv::floodFill(gray, seed, CV_RGB(255, 255, 255));
}
gray = gray > 192;
//const cv::Mat &selement = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(3, 3), cv::Point(-1, -1));
const cv::Mat &selement = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5), cv::Point(-1, -1));
//const cv::Mat &selement = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(7, 7), cv::Point(-1, -1));
const int iterations = 1;
cv::morphologyEx(gray, gray, cv::MORPH_OPEN, selement, cv::Point(-1, -1), iterations);
std::vector<cv::Vec4i> hierarchy;
cv::findContours(gray, silhouetteContours, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
}
void findHandSilhouette(const cv::Size &imgSize, const std::vector<std::vector<cv::Point> > &contours, const std::vector<cv::Point> &convexHull, const size_t contourId, const cv::Scalar &hullMeanPt, std::vector<std::vector<cv::Point> > &silhouetteContours, cv::Point &palmCenterPoint)
{
if (contours.empty() || contours[contourId].empty() || convexHull.empty()) return;
cv::Mat gray(imgSize, CV_8UC1, cv::Scalar::all(255));
cv::drawContours(gray, contours, contourId, CV_RGB(0, 0, 0), 1, 8);
cv::Mat distanceTransform; // CV_32FC1
my_opencv::compute_distance_transform(gray, distanceTransform);
cv::Mat mask(imgSize, CV_8UC1, cv::Scalar::all(0));
{
const cv::Point *h = (const cv::Point *)&convexHull[0];
const size_t num = convexHull.size();
cv::polylines(mask, (const cv::Point **)&h, (int *)&num, 1, true, CV_RGB(255, 255, 255), 1, 8, 0);
cv::floodFill(mask, cv::Point(cvRound(hullMeanPt[0]), cvRound(hullMeanPt[1])), CV_RGB(255, 255, 255));
}
// FIXME [check] >>
// palmCenterPoint has a strange value, but the result is correct ???
cv::minMaxLoc(distanceTransform, NULL, NULL, NULL, &palmCenterPoint, mask);
//
findBetterHandContour(imgSize, contours, convexHull, contourId, palmCenterPoint, silhouetteContours);
}
bool segmentFinger(cv::Mat &img, const cv::Point &startPt, const cv::Point &endPt, const std::vector<cv::Point> &handContour, const double distanceThreshold, std::vector<std::vector<cv::Point> > &fingerContours)
{
// FIXME [enhance] >> searching speed
int flag = 0;
bool is_final = false;
std::vector<cv::Point> fingerContour;
for (std::vector<cv::Point>::const_iterator itPt = handContour.begin(); itPt != handContour.end(); ++itPt)
{
if (cv::norm(*itPt - startPt) <= distanceThreshold)
{
if (flag)
{
std::cout << "start point error !!!" << std::endl;
return false;
}
else flag = -1;
}
else if (cv::norm(*itPt - endPt) <= distanceThreshold)
{
if (flag)
{
if (1 == flag)
{
std::cout << "end point error !!!" << std::endl;
return false;
}
else
{
fingerContour.push_back(*itPt);
break;
}
}
else
{
is_final = true;
}
}
if (!flag) continue;
fingerContour.push_back(*itPt);
}
if (is_final)
{
for (std::vector<cv::Point>::const_iterator itPt = handContour.begin(); itPt != handContour.end(); ++itPt)
{
if (cv::norm(*itPt - endPt) <= distanceThreshold)
{
if (flag)
{
if (1 == flag)
{
std::cout << "end point error !!!" << std::endl;
return false;
}
else
{
fingerContour.push_back(*itPt);
break;
}
}
else break;
}
if (!flag) continue;
fingerContour.push_back(*itPt);
}
}
fingerContours.push_back(fingerContour);
return true;
}
void findFingertips(const std::vector<std::vector<cv::Point> > &fingerContours, const size_t displaceIndex, const cv::Point &palmCenterPoint, const cv::Point &hullCenterPoint, std::vector<cv::Point> &fingertips)
{
#if 1
const size_t &count = fingerContours.size();
std::vector<cv::Point> minFingerTipPoints, maxFingerTipPoints;
minFingerTipPoints.reserve(count);
maxFingerTipPoints.reserve(count);
for (std::vector<std::vector<cv::Point> >::const_iterator it = fingerContours.begin(); it != fingerContours.end(); ++it)
{
size_t minIdx = -1, maxIdx = -1;
if (my_opencv::find_curvature_points(*it, displaceIndex, minIdx, maxIdx))
{
if ((size_t)-1 != minIdx) minFingerTipPoints.push_back((*it)[minIdx]);
if ((size_t)-1 != maxIdx) maxFingerTipPoints.push_back((*it)[maxIdx]);
}
}
fingertips.swap(minFingerTipPoints);
#elif 0
const size_t &count = fingerContours.size();
fingertips.reserve(count);
for (std::vector<std::vector<cv::Point> >::const_iterator it = fingerContours.begin(); it != fingerContours.end(); ++it)
{
size_t minIdx = -1, maxIdx = -1;
if (find_curvature_points(*it, displaceIndex, minIdx, maxIdx))
{
if (-1 != minIdx && -1 != maxIdx)
{
const cv::Point &pt1 = (*it)[minIdx], &pt2 = (*it)[maxIdx];
const double len1 = (pt1.x - palmCenterPoint.x) * (pt1.x - palmCenterPoint.x) + (pt1.y - palmCenterPoint.y) * (pt1.y - palmCenterPoint.y);
const double len2 = (pt2.x - palmCenterPoint.x) * (pt2.x - palmCenterPoint.x) + (pt2.y - palmCenterPoint.y) * (pt2.y - palmCenterPoint.y);
fingertips.push_back((*it)[len1 >= len2 ? minIdx : maxIdx]);
}
else if (-1 != minIdx) fingertips.push_back((*it)[minIdx]);
else if (-1 != maxIdx) fingertips.push_back((*it)[maxIdx]);
}
}
#else
cv::Point maxPt;
for (std::vector<std::vector<cv::Point> >::const_iterator it = fingerContours.begin(); it != fingerContours.end(); ++it)
{
double maxDist = 0.0;
bool flag = false;
for (std::vector<cv::Point>::const_iterator itPoint = it->begin(); itPoint != it->end(); ++itPoint)
{
const double dist = (itPoint->x - palmCenterPoint.x) * (itPoint->x - palmCenterPoint.x) + (itPoint->y - palmCenterPoint.y) * (itPoint->y - palmCenterPoint.y);
if (dist > maxDist)
{
maxDist = dist;
maxPt = *itPoint;
flag = true;
}
}
if (flag) fingertips.push_back(maxPt);
}
#endif
// FIXME [check] >> is it correct?
const cv::Point v1(hullCenterPoint - palmCenterPoint);
#if defined(__GNUC__)
std::vector<cv::Point>::iterator it = fingertips.begin();
#else
std::vector<cv::Point>::const_iterator it = fingertips.begin();
#endif
while (it != fingertips.end())
{
const cv::Point v2(*it - palmCenterPoint);
if (v1.x * v2.x + v1.y * v2.y < 0.0)
it = fingertips.erase(it);
if (it == fingertips.end())
break;
++it;
}
}
struct FingerDistanceComparator
{
FingerDistanceComparator(const cv::Point &thumb)
: thumb_(thumb)
{}
bool operator()(const cv::Point &lhs, const cv::Point &rhs) const
{
const double dist1((lhs.x - thumb_.x) * (lhs.x - thumb_.x) + (lhs.y - thumb_.y) * (lhs.y - thumb_.y));
const double dist2((rhs.x - thumb_.x) * (rhs.x - thumb_.x) + (rhs.y - thumb_.y) * (rhs.y - thumb_.y));
return dist1 < dist2;
}
private:
const cv::Point &thumb_;
};
size_t findThumb(const std::vector<cv::Point> &fingertips)
{
size_t thumbIdx = -1;
if (!fingertips.empty())
{
cv::Point center(0, 0);
for (std::vector<cv::Point>::const_iterator it = fingertips.begin(); it != fingertips.end(); ++it)
center += *it;
const size_t &count = fingertips.size();
center.x /= count;
center.y /= count;
thumbIdx = std::distance(fingertips.begin(), std::max_element(fingertips.begin(), fingertips.end(), FingerDistanceComparator(center)));
}
return thumbIdx;
}
bool findFingerOrder(std::vector<cv::Point> &fingertips)
{
const size_t &thumbIdx = findThumb(fingertips);
if (size_t(-1) != thumbIdx)
{
std::sort(fingertips.begin(), fingertips.end(), FingerDistanceComparator(fingertips[thumbIdx]));
return true;
}
else return false;
}
void extractMserOnHand(const cv::Mat &img, const cv::Mat &mask, std::vector<cv::KeyPoint> &keypoints)
{
cv::Mat masked_img;
img.copyTo(masked_img, mask);
// "FAST", "STAR", "SIFT", "SURF", "MSER", "GFTT", "HARRIS"
// also combined format is supported: feature detector adapter name ("Grid", "Pyramid") + feature detector name (see above), e.g. "GridFAST", "PyramidSTAR", etc.
cv::Ptr<cv::FeatureDetector> detector = cv::MSER::create();
if (detector.empty())
{
std::cout << "can not create detector of given types" << std::endl;
return;
}
detector->detect(masked_img, keypoints);
}
void drawCoutourSequentially(const std::vector<cv::Point> &contour, const std::string &windowName, cv::Mat &cimg)
{
size_t k = 0;
for (std::vector<cv::Point>::const_iterator itPt = contour.begin(); itPt != contour.end(); ++itPt, ++k)
{
bool is_drawn = false;
if (0 == k % 30)
{
cv::circle(cimg, *itPt, 5, CV_RGB(255, 0, 0), cv::FILLED);
is_drawn = true;
}
if (10 == k % 30)
{
cv::circle(cimg, *itPt, 5, CV_RGB(0, 255, 0), cv::FILLED);
is_drawn = true;
}
if (20 == k % 30)
{
cv::circle(cimg, *itPt, 5, CV_RGB(0, 0, 255), cv::FILLED);
is_drawn = true;
}
if (is_drawn)
{
cv::imshow(windowName, cimg);
cv::waitKey(50);
}
}
}
struct MaxAreaCompare
{
bool operator()(const std::vector<cv::Point> &lhs, const std::vector<cv::Point> &rhs) const
{
const double area1 = cv::contourArea(cv::Mat(lhs));
const double area2 = cv::contourArea(cv::Mat(rhs));
return area1 < area2;
}
};
bool estimateHandPose(const cv::Mat &img, const cv::Mat &gray, cv::Point &palmCenterPoint, std::vector<cv::Point> &fingertips, const bool is_drawn = false, const std::string &windowName = std::string())
{
CvMemStorage *storage = cvCreateMemStorage();
const double &startTime = (double)cv::getTickCount();
//------------------------------------------------------------------
// extract edge
cv::Mat edge;
{
const int lowerEdgeThreshold = 20, upperEdgeThreshold = 50;
cv::blur(gray, edge, cv::Size(3, 3));
cv::Canny(edge, edge, lowerEdgeThreshold, upperEdgeThreshold, 3, true);
}
cv::Mat cedge_img;
if (is_drawn)
{
img.copyTo(cedge_img, edge);
//cedge_img = cedge_img > 0;
if (!windowName.empty())
{
cv::imshow(windowName, cedge_img);
cv::waitKey(0);
}
}
//------------------------------------------------------------------
// find hand contour
std::vector<std::vector<cv::Point> > contours;
findHandContour(edge, contours);
if (contours.empty())
{
std::cout << "can't find hand contour" << std::endl;
return false;
}
const size_t maxAreaIdx = std::distance(contours.begin(), std::max_element(contours.begin(), contours.end(), MaxAreaCompare()));
const std::vector<cv::Point> &maxAreaContour = contours[maxAreaIdx];
// FIXME [delete] >>
//{
// if (is_drawn && !windowName.empty())
// {
// cv::Mat tmp_img(cedge_img.clone());
// for (size_t i = 0; i < contours.size(); ++i)
// {
// //drawCoutourSequentially(contours[i], windowName, tmp_img);
// cv::drawContours(tmp_img, contours, i, CV_RGB(255, 0, 0));
// cv::imshow(windowName, tmp_img);
// cv::waitKey(0);
// }
// }
//}
//------------------------------------------------------------------
// calculate convex hull
std::vector<cv::Point> convexHull;
cv::convexHull(cv::Mat(maxAreaContour), convexHull, false);
if (convexHull.empty())
{
std::cout << "can't find any convex hull" << std::endl;
return false;
}
const cv::Scalar &handMeanPt = cv::mean(cv::Mat(maxAreaContour));
const cv::Scalar &hullMeanPt = cv::mean(cv::Mat(convexHull));
//------------------------------------------------------------------
// find hand contour & silhouette using hand contour
std::vector<std::vector<cv::Point> > silhouetteContours;
//cv::Point palmCenterPoint;
if (!contours[maxAreaIdx].empty())
findHandSilhouette(gray.size(), contours, convexHull, maxAreaIdx, hullMeanPt, silhouetteContours, palmCenterPoint);
if (silhouetteContours.empty())
{
std::cout << "can't find hand silhouette" << std::endl;
if (is_drawn && !windowName.empty())
{
cv::circle(cedge_img, palmCenterPoint, 7, CV_RGB(255, 0, 255), 2, 8, 0);
cv::imshow(windowName, cedge_img);
cv::waitKey(0);
}
return false;
}
const size_t maxAreaSilhouetteIdx = std::distance(silhouetteContours.begin(), std::max_element(silhouetteContours.begin(), silhouetteContours.end(), MaxAreaCompare()));
const std::vector<cv::Point> &maxAreaSilhouetteContour = silhouetteContours[maxAreaSilhouetteIdx];
// generate hand silhouette
cv::Mat silhouette_img(gray.size(), gray.depth(), cv::Scalar::all(0));
if (!silhouetteContours[maxAreaSilhouetteIdx].empty())
{
cv::drawContours(silhouette_img, silhouetteContours, maxAreaSilhouetteIdx, CV_RGB(255, 255, 255), 1, 8);
cv::floodFill(silhouette_img, palmCenterPoint, CV_RGB(255, 255, 255));
}
// display hand silhouette
if (is_drawn && !windowName.empty())
{
cv::imshow(windowName, silhouette_img);
cv::waitKey(0);
}
// draw hand contour & convex hull
if (is_drawn)
{
if (!contours[maxAreaIdx].empty())
{
const int maxLevel = 0;
cv::drawContours(cedge_img, contours, maxAreaIdx, CV_RGB(0, 0, 255), 1, 8, std::vector<cv::Vec4i>(), maxLevel, cv::Point());
const cv::Point *h = (const cv::Point *)&convexHull[0];
const size_t num = convexHull.size();
cv::polylines(cedge_img, (const cv::Point **)&h, (int *)&num, 1, true, CV_RGB(0, 255, 0), 1, 8, 0);
}
if (!windowName.empty())
{
cv::imshow(windowName, cedge_img);
cv::waitKey(0);
}
}
//------------------------------------------------------------------
// find convexity defect
std::vector<std::vector<CvConvexityDefect> > convexityDefects;
std::vector<cv::Point> convexityDefectPoints;
const double distanceThreshold = 2.0;
const double depthThreshold = 5.0;
my_opencv::find_convexity_defect(storage, maxAreaSilhouetteContour, convexHull, distanceThreshold, depthThreshold, convexityDefects, convexityDefectPoints);
const cv::Scalar &defectMeanPt = cv::mean(cv::Mat(convexityDefectPoints));
// draw convexity defect
if (is_drawn)
{
for (std::vector<std::vector<CvConvexityDefect> >::const_iterator it = convexityDefects.begin(); it != convexityDefects.end(); ++it)
{
for (std::vector<CvConvexityDefect>::const_iterator itDefect = it->begin(); itDefect != it->end(); ++itDefect)
{
cv::line(cedge_img, cv::Point(itDefect->start->x, itDefect->start->y), cv::Point(itDefect->depth_point->x, itDefect->depth_point->y), CV_RGB(255, 255, 0), 1, 8, 0);
cv::line(cedge_img, cv::Point(itDefect->end->x, itDefect->end->y), cv::Point(itDefect->depth_point->x, itDefect->depth_point->y), CV_RGB(255, 255, 0), 1, 8, 0);
cv::circle(cedge_img, cv::Point(itDefect->depth_point->x, itDefect->depth_point->y), 2, CV_RGB(255, 255, 0), cv::FILLED, 8, 0);
}
}
if (!windowName.empty())
{
cv::imshow(windowName, cedge_img);
cv::waitKey(0);
}
}
//------------------------------------------------------------------
// segment fingers
std::vector<std::vector<cv::Point> > fingerContours;
{
const double distanceThreshold = 0.5;
if (convexityDefectPoints.size() >= 2)
{
std::vector<cv::Point>::const_iterator it = convexityDefectPoints.begin(), itPrev = it;
++it;
for (; it != convexityDefectPoints.end(); ++it)
{
// FIXME [modify] >> Oops !!! stupid implementation
// it is better to use index of points in the convexity defects
// I assume that convexity defect points have been already sorted
const bool retval = segmentFinger(cedge_img, *itPrev, *it, maxAreaSilhouetteContour, distanceThreshold, fingerContours);
itPrev = it;
}
const bool retval = segmentFinger(cedge_img, *itPrev, convexityDefectPoints.front(), maxAreaSilhouetteContour, distanceThreshold, fingerContours);
}
}
//------------------------------------------------------------------
// find fingertips
//std::vector<cv::Point> fingertips;
{
const size_t displaceIndex = 15;
findFingertips(fingerContours, displaceIndex, palmCenterPoint, cv::Point(cvRound(hullMeanPt[0]), cvRound(hullMeanPt[1])), fingertips);
}
// draw segmented fingers
if (is_drawn)
{
const size_t &numContour = fingerContours.size();
for (size_t i = 0; i < numContour; ++i)
{
if (!fingerContours[i].empty())
{
const int r = std::rand() % 256, g = std::rand() % 256, b = std::rand() % 256;
cv::drawContours(cedge_img, fingerContours, i, CV_RGB(r, g, b), 2, 8);
}
}
if (!windowName.empty())
{
cv::imshow(windowName, cedge_img);
cv::waitKey(0);
}
}
//------------------------------------------------------------------
// find finger order
if (!findFingerOrder(fingertips))
{
std::cout << "can't order fingers" << std::endl;
return false;
}
// draw fingertips
if (is_drawn)
{
size_t k = 0;
for (std::vector<cv::Point>::iterator it = fingertips.begin(); it != fingertips.end(); ++it, ++k)
{
if (0 == k) cv::circle(cedge_img, *it, 3, CV_RGB(255, 0, 0), 2, 8, 0);
if (1 == k) cv::circle(cedge_img, *it, 3, CV_RGB(255, 165, 0), 2, 8, 0);
if (2 == k) cv::circle(cedge_img, *it, 3, CV_RGB(255, 255, 0), 2, 8, 0);
if (3 == k) cv::circle(cedge_img, *it, 3, CV_RGB(0, 128, 0), 2, 8, 0);
if (4 == k) cv::circle(cedge_img, *it, 3, CV_RGB(0, 0, 255), 2, 8, 0);
if (5 == k) cv::circle(cedge_img, *it, 3, CV_RGB(75, 0, 130), 2, 8, 0);
if (6 == k) cv::circle(cedge_img, *it, 3, CV_RGB(238, 130, 238), 2, 8, 0);
}
}
//------------------------------------------------------------------
// draw center points
if (is_drawn)
{
cv::circle(cedge_img, cv::Point(cvRound(handMeanPt[0]), cvRound(handMeanPt[1])), 5, CV_RGB(0, 0, 255), 2, 8, 0);
cv::circle(cedge_img, cv::Point(cvRound(hullMeanPt[0]), cvRound(hullMeanPt[1])), 5, CV_RGB(0, 255, 0), 2, 8, 0);
cv::circle(cedge_img, cv::Point(cvRound(defectMeanPt[0]), cvRound(defectMeanPt[1])), 5, CV_RGB(255, 0, 0), 2, 8, 0);
cv::circle(cedge_img, palmCenterPoint, 7, CV_RGB(255, 0, 255), 2, 8, 0);
if (!windowName.empty())
{
cv::imshow(windowName, cedge_img);
cv::waitKey(0);
}
}
//
const double &endTime = (double)cv::getTickCount();
std::cout << "processing time " << ((endTime - startTime) / ((double)cv::getTickFrequency() * 1000.0)) << " ms" << std::endl;
/*
//------------------------------------------------------------------
// extract MSER on the hand only
std::vector<cv::KeyPoint> keypoints;
extractMserOnHand(img, silhouette_img, keypoints);
// draw keypoints
if (is_drawn)
{
for (std::vector<cv::KeyPoint>::iterator it = keypoints.begin(); it != keypoints.end(); ++it)
{
const double radius = it->size * 0.1;
const double angle = it->angle * CV_PI / 180.0;
cv::circle(cedge_img, cv::Point(cvRound(it->pt.x), cvRound(it->pt.y)), cvRound(radius), CV_RGB(0, 255, 255), 2, 8, 0);
if (-1 != it->angle)
cv::line(cedge_img, cv::Point(cvRound(it->pt.x), cvRound(it->pt.y)), cv::Point(cvRound(it->pt.x + radius * std::cos(angle)), cvRound(it->pt.y + radius * std::sin(angle))), CV_RGB(0, 255, 255), 2, 8, 0);
}
if (!windowName.empty())
{
cv::imshow(windowName, cedge_img);
cv::waitKey(0);
}
}
*/
//------------------------------------------------------------------
if (is_drawn && !windowName.empty())
{
//
cv::Mat resultant_img;
resultant_img = cedge_img;
//resultant_img = distance_img;
//resultant_img = silhouette_img;
cv::imshow(windowName, resultant_img);
}
cvClearMemStorage(storage);
cvReleaseMemStorage(&storage);
return true;
}
} // namespace local
} // unnamed namespace
namespace my_opencv {
void hand_pose_estimation()
{
#if 0
std::list<std::string> filenames;
#if 0
filenames.push_back("../data/machine_vision/opencv/hand_01.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_02.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_03.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_04.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_05.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_06.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_07.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_08.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_09.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_10.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_11.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_12.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_13.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_14.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_15.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_16.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_17.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_18.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_19.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_20.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_21.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_22.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_23.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_24.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_25.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_26.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_27.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_28.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_29.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_30.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_31.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_32.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_33.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_34.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_35.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_36.jpg");
#elif 1
filenames.push_back("../data/machine_vision/opencv/simple_hand_01.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_02.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_03.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_04.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_05.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_06.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_07.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_08.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_09.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_10.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_11.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_12.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_13.jpg");
#endif
const char *windowName = "hand pose estimation";
cvNamedWindow(windowName, CV_WINDOW_AUTOSIZE);
//
for (std::list<std::string>::iterator it = filenames.begin(); it != filenames.end(); ++it)
{
IplImage *srcImage = cvLoadImage(it->c_str());
if (NULL == srcImage)
{
std::cout << "image file not found: " << *it << std::endl;
continue;
}
IplImage *grayImage = NULL;
if (1 == srcImage->nChannels)
cvCopy(srcImage, grayImage, NULL);
else
{
grayImage = cvCreateImage(cvGetSize(srcImage), srcImage->depth, 1);
#if defined(__GNUC__)
if (strcasecmp(image->channelSeq, "RGB") == 0)
#elif defined(_MSC_VER)
if (_stricmp(srcImage->channelSeq, "RGB") == 0)
#endif
cvCvtColor(srcImage, grayImage, CV_RGB2GRAY);
#if defined(__GNUC__)
if (strcasecmp(image->channelSeq, "BGR") == 0)
#elif defined(_MSC_VER)
else if (_stricmp(srcImage->channelSeq, "BGR") == 0)
#endif
cvCvtColor(srcImage, grayImage, CV_BGR2GRAY);
else
assert(false);
grayImage->origin = srcImage->origin;
}
// smoothing.
// TODO [check] >> smoothing is needed?
//
//contour(srcImage, grayImage);
//snake(srcImage, grayImage);
#if 0
local::mser(srcImage, grayImage);
#else
local::mser(cv::Mat(srcImage), cv::Mat(grayImage));
#endif
//
cvShowImage(windowName, srcImage);
const unsigned char key = cvWaitKey(0);
if (27 == key)
break;
//
cvReleaseImage(&grayImage);
cvReleaseImage(&srcImage);
}
cvDestroyWindow(windowName);
#elif 1
std::list<std::string> filenames;
#if 0
filenames.push_back("../data/machine_vision/opencv/pic1.png");
filenames.push_back("../data/machine_vision/opencv/pic2.png");
filenames.push_back("../data/machine_vision/opencv/pic3.png");
filenames.push_back("../data/machine_vision/opencv/pic4.png");
filenames.push_back("../data/machine_vision/opencv/pic5.png");
filenames.push_back("../data/machine_vision/opencv/pic6.png");
filenames.push_back("../data/machine_vision/opencv/stuff.jpg");
filenames.push_back("../data/machine_vision/opencv/synthetic_face.png");
filenames.push_back("../data/machine_vision/opencv/puzzle.png");
filenames.push_back("../data/machine_vision/opencv/fruits.jpg");
filenames.push_back("../data/machine_vision/opencv/lena_rgb.bmp");
filenames.push_back("../data/machine_vision/opencv/hand_01.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_05.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_24.jpg");
#elif 1
//filenames.push_back("../data/machine_vision/opencv/hand_left_1.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_right_1.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_01.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_02.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_03.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_04.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_05.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_06.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_07.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_08.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_09.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_10.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_11.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_12.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_13.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_14.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_15.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_16.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_17.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_18.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_19.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_20.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_21.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_22.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_23.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_24.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_25.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_26.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_27.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_28.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_29.jpg");
//filenames.push_back("../data/machine_vision/opencv/hand_30.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_31.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_32.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_33.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_34.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_35.jpg");
filenames.push_back("../data/machine_vision/opencv/hand_36.jpg");
#elif 0
filenames.push_back("../data/machine_vision/opencv/simple_hand_01.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_02.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_03.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_04.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_05.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_06.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_07.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_08.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_09.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_10.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_11.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_12.jpg");
filenames.push_back("../data/machine_vision/opencv/simple_hand_13.jpg");
#endif
const std::string windowName1("hand pose estimation - original");
const std::string windowName2("hand pose estimation - processed");
cv::namedWindow(windowName1, cv::WINDOW_AUTOSIZE);
cv::namedWindow(windowName2, cv::WINDOW_AUTOSIZE);
for (std::list<std::string>::iterator it = filenames.begin(); it != filenames.end(); ++it)
{
const cv::Mat &img = cv::imread(*it, cv::IMREAD_COLOR);
if (img.empty())
{
std::cout << "fail to load image file: " << *it << std::endl;
continue;
}
cv::imshow(windowName1, img);
cv::Mat gray;
if (1 == img.channels())
img.copyTo(gray);
else
cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY);
//cv::cvtColor(img, gray, cv::COLOR_RGB2GRAY);
cv::Point palmCenterPoint;
std::vector<cv::Point> fingertips;
if (local::estimateHandPose(img, gray, palmCenterPoint, fingertips, true, windowName2))
{
std::cout << "\tthe center of palm: (" << palmCenterPoint.x << ", " << palmCenterPoint.y << ")" << std::endl;
std::cout << '\t' << fingertips.size() << " fingertips found !!!" << std::endl;
}
const unsigned char key = cv::waitKey(0);
if (27 == key)
break;
}
cv::destroyWindow(windowName1);
cv::destroyWindow(windowName2);
#else
const int imageWidth = 640, imageHeight = 480;
const int camId = -1;
cv::VideoCapture capture(camId);
if (!capture.isOpened())
{
std::cout << "a vision sensor not found" << std::endl;
return;
}
const bool b1 = capture.set(CV_CAP_PROP_FRAME_WIDTH, imageWidth);
const bool b2 = capture.set(CV_CAP_PROP_FRAME_HEIGHT, imageHeight);
const std::string windowName("hand pose estimation");
cv::namedWindow(windowName, cv::WINDOW_AUTOSIZE);
cv::Mat prevgray, gray, frame, frame2;
cv::Mat mhi, segmentMask;
cv::Mat img;
std::vector<std::vector<cv::Point> > pointSets;
std::vector<cv::Vec4i> hierarchy;
const int maxLevel = 5;
size_t maxAreaIdx = -1;
for (;;)
{
#if defined(_DEBUG) || defined(DEBUG)
const size_t MAX_SEGMENTATION_FRAMES = 20;
#else
const size_t MAX_SEGMENTATION_FRAMES = 50;
#endif
size_t numSegmentationFrames = 0;
do
{
maxAreaIdx = -1;
#if 1
capture >> frame;
if (frame.empty())
{
std::cout << "a frame not found ..." << std::endl;
break;
//continue;
}
#else
capture >> frame2;
if (frame2.empty())
{
std::cout << "a frame not found ..." << std::endl;
break;
//continue;
}
if (frame2.cols != imageWidth || frame2.rows != imageHeight)
{
//cv::resize(frame2, frame, cv::Size(imageWidth, imageHeight), 0.0, 0.0, cv::INTER_LINEAR);
cv::pyrDown(frame2, frame);
}
else frame = frame2;
#endif
cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
cv::cvtColor(gray, img, cv::COLOR_GRAY2BGR);
// smoothing
#if 0
// METHOD #1: down-scale and up-scale the image to filter out the noise.
{
cv::Mat tmp;
cv::pyrDown(gray, tmp);
cv::pyrUp(tmp, gray);
}
#elif 0
// METHOD #2: Gaussian filtering.
{
// FIXME [adjust] >> adjust parameters.
const int kernelSize = 3;
const double sigma = 2.0;
cv::GaussianBlur(gray, gray, cv::Size(kernelSize, kernelSize), sigma, sigma, cv::BORDER_DEFAULT);
}
#elif 0
// METHOD #3: box filtering.
{
// FIXME [adjust] >> adjust parameters.
const int ddepth = -1; // the output image depth. -1 to use src.depth().
const int kernelSize = 5;
const bool normalize = true;
cv::boxFilter(gray.clone(), gray, ddepth, cv::Size(kernelSize, kernelSize), cv::Point(-1, -1), normalize, cv::BORDER_DEFAULT);
//cv::blur(gray.clone(), gray, cv::Size(kernelSize, kernelSize), cv::Point(-1, -1), cv::BORDER_DEFAULT); // use the normalized box filter.
}
#elif 0
// METHOD #4: bilateral filtering.
{
// FIXME [adjust] >> adjust parameters.
const int diameter = -1; // diameter of each pixel neighborhood that is used during filtering. if it is non-positive, it is computed from sigmaSpace.
const double sigmaColor = 3.0; // for range filter.
const double sigmaSpace = 50.0; // for space filter.
cv::bilateralFilter(gray.clone(), gray, diameter, sigmaColor, sigmaSpace, cv::BORDER_DEFAULT);
}
#else
// METHOD #5: no filtering.
//gray = gray;
#endif
if (!prevgray.empty())
{
if (mhi.empty())
mhi.create(gray.rows, gray.cols, CV_32F);
const bool useConvexHull = false;
segment_motion_using_mhi(useConvexHull, prevgray, gray, mhi, segmentMask, pointSets, hierarchy);
//local::segment_motion_using_Farneback_motion_estimation(useConvexHull, prevgray, gray, segmentMask, pointSets, hierarchy);
double maxArea = 0.0;
size_t idx = 0;
for (std::vector<std::vector<cv::Point> >::iterator it = pointSets.begin(); it != pointSets.end(); ++it, ++idx)
{
if (it->empty()) continue;
const double area = cv::contourArea(cv::Mat(*it));
if (area > maxArea)
{
maxArea = area;
maxAreaIdx = idx;
}
}
#if 0
cv::drawContours(img, pointSets, -1, CV_RGB(255, 0, 0), 1, 8, hierarchy, maxLevel, cv::Point());
#elif 0
const size_t num = pointSets.size();
for (size_t k = 0; k < num; ++k)
{
if (cv::contourArea(cv::Mat(pointSets[k])) < 100.0) continue;
const int r = rand() % 256, g = rand() % 256, b = rand() % 256;
if (!pointSets[k].empty())
cv::drawContours(img, pointSets, k, CV_RGB(r, g, b), 1, 8, hierarchy, maxLevel, cv::Point());
}
#else
if (-1 != maxAreaIdx)
if (!pointSets[maxAreaIdx].empty())
{
cv::drawContours(img, pointSets, maxAreaIdx, CV_RGB(0, 0, 255), 1, 8, hierarchy, 0, cv::Point());
//cv::drawContours(img, pointSets, maxAreaIdx, CV_RGB(0, 0, 255), 1, 8, hierarchy, maxLevel, cv::Point());
}
#endif
std::ostringstream sstream;
sstream << "segmentation step: " << (numSegmentationFrames + 1) << " / " << MAX_SEGMENTATION_FRAMES;
cv::putText(img, sstream.str(), cv::Point(5, 10), cv::FONT_HERSHEY_COMPLEX, 0.3, CV_RGB(255, 0, 255), 1, 8, false);
cv::imshow(windowName, img);
}
if (cv::waitKey(1) >= 0)
break;
std::swap(prevgray, gray);
} while (++numSegmentationFrames < MAX_SEGMENTATION_FRAMES);
//
#if defined(_DEBUG) || defined(DEBUG)
const size_t MAX_ACQUISITION_FRAMES = 5;
#else
const size_t MAX_ACQUISITION_FRAMES = 20;
#endif
size_t numAcquisitionFrames = 0;
do
{
#if 1
capture >> frame;
if (frame.empty())
{
std::cout << "a frame not found ..." << std::endl;
break;
//continue;
}
#else
capture >> frame2;
if (frame2.empty())
{
std::cout << "a frame not found ..." << std::endl;
break;
//continue;
}
if (frame2.cols != imageWidth || frame2.rows != imageHeight)
{
//cv::resize(frame2, frame, cv::Size(imageWidth, imageHeight), 0.0, 0.0, cv::INTER_LINEAR);
cv::pyrDown(frame2, frame);
}
else frame = frame2;
#endif
cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
cv::cvtColor(gray, img, cv::COLOR_GRAY2BGR);
if (-1 != maxAreaIdx)
if (!pointSets[maxAreaIdx].empty()) cv::drawContours(img, pointSets, maxAreaIdx, CV_RGB(0, 0, 255), 1, 8, hierarchy, 0, cv::Point());
//if (!pointSets[maxAreaIdx].empty()) cv::drawContours(img, pointSets, maxAreaIdx, CV_RGB(0, 0, 255), 1, 8, hierarchy, maxLevel, cv::Point());
std::ostringstream sstream;
sstream << "acquisition step: " << (numAcquisitionFrames + 1) << " / " << MAX_ACQUISITION_FRAMES;
cv::putText(img, sstream.str(), cv::Point(5, 10), cv::FONT_HERSHEY_COMPLEX, 0.3, CV_RGB(255, 0, 255), 1, 8, false);
cv::imshow(windowName, img);
if (cv::waitKey(30) >= 0)
break;
} while (++numAcquisitionFrames < MAX_ACQUISITION_FRAMES);
if (!pointSets.empty() && -1 != maxAreaIdx)
{
{
const cv::Mat &selement7 = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(7, 7), cv::Point(-1, -1));
const cv::Mat &selement5 = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5), cv::Point(-1, -1));
const cv::Mat &selement3 = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(3, 3), cv::Point(-1, -1));
#if 0
cv::dilate(segmentMask, segmentMask, selement3, cv::Point(-1, -1), 3);
cv::erode(segmentMask, segmentMask, selement3, cv::Point(-1, -1), 5);
#else
cv::morphologyEx(segmentMask, segmentMask, cv::MORPH_CLOSE, selement3, cv::Point(-1, -1), 3);
cv::morphologyEx(segmentMask, segmentMask, cv::MORPH_OPEN, selement3, cv::Point(-1, -1), 5);
#endif
}
cv::Mat semgented_gray;
gray.copyTo(semgented_gray, segmentMask);
//cv::equalizeHist(semgented_gray, semgented_gray);
// FIXME [delete] >>
cv::Mat semgented_img;
img.copyTo(semgented_img, segmentMask);
//const size_t NUMBER_OF_SNAKE_POINTS = 50;
const size_t NUMBER_OF_SNAKE_POINTS = 0;
const float alpha = 3.0f; // weight(s) of continuity energy, single float or array of length floats, one for each contour point.
const float beta = 5.0f; // weight(s) of curvature energy, single float or array of length floats, one for each contour point.
const float gamma = 2.0f; // weight(s) of image energy, single float or array of length floats, one for each contour point.
const bool use_gradient = true; // gradient flag; if true, the function calculates the gradient magnitude for every image pixel and consideres it as the energy field, otherwise the input image itself is considered.
const CvSize win = cvSize(21, 21); // size of neighborhood of every point used to search the minimum, both win.width and win.height must be odd.
std::vector<cv::Point> snake_contour;
local::fit_contour_by_snake(semgented_gray, pointSets[maxAreaIdx], NUMBER_OF_SNAKE_POINTS, alpha, beta, gamma, use_gradient, win, snake_contour);
if (!snake_contour.empty())
{
// draw snake on image
const cv::Point *snake_pts = &snake_contour[0];
const size_t numSnakePts = 0 == NUMBER_OF_SNAKE_POINTS ? snake_contour.size() : NUMBER_OF_SNAKE_POINTS;
cv::polylines(semgented_img, (const cv::Point **)&snake_pts, (int *)&numSnakePts, 1, true, CV_RGB(255, 0, 0), 2, 8, 0);
cv::putText(semgented_img, "pose estimation step", cv::Point(5, 10), cv::FONT_HERSHEY_COMPLEX, 0.3, CV_RGB(255, 0, 255), 1, 8, false);
cv::imshow(windowName, semgented_img);
}
}
if (cv::waitKey(0) >= 0)
break;
}
cv::destroyWindow(windowName);
#endif
}
} // namespace my_opencv
| gpl-2.0 |
RolanDroid/lge_MonsterKernel-JB-Stock | drivers/media/video/msm/vx6953_reg_v4l2.c | 1026 | 3644 | /* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "vx6953_v4l2.h"
const struct reg_struct_init vx6953_reg_init[1] = {
{
10, /*REG = 0x0112 , 10 bit */
10, /*REG = 0x0113*/
9, /*REG = 0x0301 vt_pix_clk_div*/
4, /*REG = 0x0305 pre_pll_clk_div*/
133, /*REG = 0x0307 pll_multiplier*/
10, /*REG = 0x0309 op_pix_clk_div*/
0x08, /*REG = 0x3030*/
0x02, /*REG = 0x0111*/
0x01, /*REG = 0x0b00 ,lens shading off */
0x30, /*REG = 0x3001*/
0x33, /*REG = 0x3004*/
0x09, /*REG = 0x3007*/
0x1F, /*REG = 0x3016*/
0x03, /*REG = 0x301d*/
0x11, /*REG = 0x317E*/
0x09, /*REG = 0x317F*/
0x38, /*REG = 0x3400*/
0x00, /*REG_0x0b06*/
0x80, /*REG_0x0b07*/
0x01, /*REG_0x0b08*/
0x4F, /*REG_0x0b09*/
0x18, /*REG_0x0136*/
0x00, /*/REG_0x0137*/
0x20, /*REG = 0x0b83*/
0x90, /*REG = 0x0b84*/
0x20, /*REG = 0x0b85*/
0x80, /*REG = 0x0b88*/
0x00, /*REG = 0x0b89*/
0x00, /*REG = 0x0b8a*/
}
};
const struct reg_struct vx6953_reg_pat[2] = {
{/* Preview */
0x03, /*REG = 0x0202 coarse integration_time_hi*/
0xd0, /*REG = 0x0203 coarse_integration_time_lo*/
0xc0, /*REG = 0x0205 analogue_gain_code_global*/
0x03, /*REG = 0x0340 frame_length_lines_hi*/
0xf0, /*REG = 0x0341 frame_length_lines_lo*/
0x0b, /*REG = 0x0342 line_length_pck_hi*/
0xa5, /*REG = 0x0343 line_length_pck_lo*/
0x03, /*REG = 0x3005*/
0x00, /*REG = 0x3010*/
0x01, /*REG = 0x3011*/
0x6a, /*REG = 0x301a*/
0x03, /*REG = 0x3035*/
0x2c, /*REG = 0x3036*/
0x00, /*REG = 0x3041*/
0x24, /*REG = 0x3042*/
0x81, /*REG = 0x3045*/
0x02, /*REG = 0x0b80 edof estimate*/
0x01, /*REG = 0x0900*/
0x22, /*REG = 0x0901*/
0x04, /*REG = 0x0902*/
0x03, /*REG = 0x0383*/
0x03, /*REG = 0x0387*/
0x05, /*REG = 0x034c*/
0x18, /*REG = 0x034d*/
0x03, /*REG = 0x034e*/
0xd4, /*REG = 0x034f*/
0x02, /*0x1716*/
0x04, /*0x1717*/
0x08, /*0x1718*/
0x80, /*0x1719*/
0x01, /*0x3210*/
0x02, /*0x111*/
0x01, /*0x3410*/
0x01, /*0x3098*/
0x05, /*0x309D*/
0x02,
0x04,
},
{ /* Snapshot */
0x07,/*REG = 0x0202 coarse_integration_time_hi*/
0x00,/*REG = 0x0203 coarse_integration_time_lo*/
0xc0,/*REG = 0x0205 analogue_gain_code_global*/
0x07,/*REG = 0x0340 frame_length_lines_hi*/
0xd0,/*REG = 0x0341 frame_length_lines_lo*/
0x0b,/*REG = 0x0342 line_length_pck_hi*/
0x8c,/*REG = 0x0343 line_length_pck_lo*/
0x01,/*REG = 0x3005*/
0x00,/*REG = 0x3010*/
0x00,/*REG = 0x3011*/
0x55,/*REG = 0x301a*/
0x01,/*REG = 0x3035*/
0x23,/*REG = 0x3036*/
0x00,/*REG = 0x3041*/
0x24,/*REG = 0x3042*/
0xb7,/*REG = 0x3045*/
0x01,/*REG = 0x0b80 edof application*/
0x00,/*REG = 0x0900*/
0x00,/*REG = 0x0901*/
0x00,/*REG = 0x0902*/
0x01,/*REG = 0x0383*/
0x01,/*REG = 0x0387*/
0x0A,/*REG = 0x034c*/
0x30,/*REG = 0x034d*/
0x07,/*REG = 0x034e*/
0xA8,/*REG = 0x034f*/
0x02,/*0x1716*/
0x0d,/*0x1717*/
0x07,/*0x1718*/
0x7d,/*0x1719*/
0x01,/*0x3210*/
0x02,/*0x111*/
0x01,/*0x3410*/
0x01,/*0x3098*/
0x05, /*0x309D*/
0x02,
0x00,
}
};
struct vx6953_reg vx6953_regs = {
.reg_pat_init = &vx6953_reg_init[0],
.reg_pat = &vx6953_reg_pat[0],
};
| gpl-2.0 |
clemsyn/TF101-kernelOC | arch/arm/mach-omap2/clkt34xx_dpll3m2.c | 1026 | 3190 | /*
* OMAP34xx M2 divider clock code
*
* Copyright (C) 2007-2008 Texas Instruments, Inc.
* Copyright (C) 2007-2010 Nokia Corporation
*
* Paul Walmsley
* Jouni Högander
*
* Parts of this code are based on code written by
* Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#undef DEBUG
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <plat/clock.h>
#include <plat/sram.h>
#include <plat/sdrc.h>
#include "clock.h"
#include "clock3xxx.h"
#include "clock34xx.h"
#include "sdrc.h"
#define CYCLES_PER_MHZ 1000000
/*
* CORE DPLL (DPLL3) M2 divider rate programming functions
*
* These call into SRAM code to do the actual CM writes, since the SDRAM
* is clocked from DPLL3.
*/
/**
* omap3_core_dpll_m2_set_rate - set CORE DPLL M2 divider
* @clk: struct clk * of DPLL to set
* @rate: rounded target rate
*
* Program the DPLL M2 divider with the rounded target rate. Returns
* -EINVAL upon error, or 0 upon success.
*/
int omap3_core_dpll_m2_set_rate(struct clk *clk, unsigned long rate)
{
u32 new_div = 0;
u32 unlock_dll = 0;
u32 c;
unsigned long validrate, sdrcrate, _mpurate;
struct omap_sdrc_params *sdrc_cs0;
struct omap_sdrc_params *sdrc_cs1;
int ret;
if (!clk || !rate)
return -EINVAL;
validrate = omap2_clksel_round_rate_div(clk, rate, &new_div);
if (validrate != rate)
return -EINVAL;
sdrcrate = sdrc_ick_p->rate;
if (rate > clk->rate)
sdrcrate <<= ((rate / clk->rate) >> 1);
else
sdrcrate >>= ((clk->rate / rate) >> 1);
ret = omap2_sdrc_get_params(sdrcrate, &sdrc_cs0, &sdrc_cs1);
if (ret)
return -EINVAL;
if (sdrcrate < MIN_SDRC_DLL_LOCK_FREQ) {
pr_debug("clock: will unlock SDRC DLL\n");
unlock_dll = 1;
}
/*
* XXX This only needs to be done when the CPU frequency changes
*/
_mpurate = arm_fck_p->rate / CYCLES_PER_MHZ;
c = (_mpurate << SDRC_MPURATE_SCALE) >> SDRC_MPURATE_BASE_SHIFT;
c += 1; /* for safety */
c *= SDRC_MPURATE_LOOPS;
c >>= SDRC_MPURATE_SCALE;
if (c == 0)
c = 1;
pr_debug("clock: changing CORE DPLL rate from %lu to %lu\n", clk->rate,
validrate);
pr_debug("clock: SDRC CS0 timing params used:"
" RFR %08x CTRLA %08x CTRLB %08x MR %08x\n",
sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,
sdrc_cs0->actim_ctrlb, sdrc_cs0->mr);
if (sdrc_cs1)
pr_debug("clock: SDRC CS1 timing params used: "
" RFR %08x CTRLA %08x CTRLB %08x MR %08x\n",
sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla,
sdrc_cs1->actim_ctrlb, sdrc_cs1->mr);
if (sdrc_cs1)
omap3_configure_core_dpll(
new_div, unlock_dll, c, rate > clk->rate,
sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,
sdrc_cs0->actim_ctrlb, sdrc_cs0->mr,
sdrc_cs1->rfr_ctrl, sdrc_cs1->actim_ctrla,
sdrc_cs1->actim_ctrlb, sdrc_cs1->mr);
else
omap3_configure_core_dpll(
new_div, unlock_dll, c, rate > clk->rate,
sdrc_cs0->rfr_ctrl, sdrc_cs0->actim_ctrla,
sdrc_cs0->actim_ctrlb, sdrc_cs0->mr,
0, 0, 0, 0);
return 0;
}
| gpl-2.0 |
DESHONOR/android_kernel_huawei_msm8916_Blefish | drivers/staging/bcm/Bcmchar.c | 1794 | 64058 | #include <linux/fs.h>
#include "headers.h"
/***************************************************************
* Function - bcm_char_open()
*
* Description - This is the "open" entry point for the character
* driver.
*
* Parameters - inode: Pointer to the Inode structure of char device
* filp : File pointer of the char device
*
* Returns - Zero(Success)
****************************************************************/
static int bcm_char_open(struct inode *inode, struct file * filp)
{
struct bcm_mini_adapter *Adapter = NULL;
struct bcm_tarang_data *pTarang = NULL;
Adapter = GET_BCM_ADAPTER(gblpnetdev);
pTarang = kzalloc(sizeof(struct bcm_tarang_data), GFP_KERNEL);
if (!pTarang)
return -ENOMEM;
pTarang->Adapter = Adapter;
pTarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB);
down(&Adapter->RxAppControlQueuelock);
pTarang->next = Adapter->pTarangs;
Adapter->pTarangs = pTarang;
up(&Adapter->RxAppControlQueuelock);
/* Store the Adapter structure */
filp->private_data = pTarang;
/* Start Queuing the control response Packets */
atomic_inc(&Adapter->ApplicationRunning);
nonseekable_open(inode, filp);
return 0;
}
static int bcm_char_release(struct inode *inode, struct file *filp)
{
struct bcm_tarang_data *pTarang, *tmp, *ptmp;
struct bcm_mini_adapter *Adapter = NULL;
struct sk_buff *pkt, *npkt;
pTarang = (struct bcm_tarang_data *)filp->private_data;
if (pTarang == NULL) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"ptarang is null\n");
return 0;
}
Adapter = pTarang->Adapter;
down(&Adapter->RxAppControlQueuelock);
tmp = Adapter->pTarangs;
for (ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next) {
if (tmp == pTarang)
break;
}
if (tmp) {
if (!ptmp)
Adapter->pTarangs = tmp->next;
else
ptmp->next = tmp->next;
} else {
up(&Adapter->RxAppControlQueuelock);
return 0;
}
pkt = pTarang->RxAppControlHead;
while (pkt) {
npkt = pkt->next;
kfree_skb(pkt);
pkt = npkt;
}
up(&Adapter->RxAppControlQueuelock);
/* Stop Queuing the control response Packets */
atomic_dec(&Adapter->ApplicationRunning);
kfree(pTarang);
/* remove this filp from the asynchronously notified filp's */
filp->private_data = NULL;
return 0;
}
static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size,
loff_t *f_pos)
{
struct bcm_tarang_data *pTarang = filp->private_data;
struct bcm_mini_adapter *Adapter = pTarang->Adapter;
struct sk_buff *Packet = NULL;
ssize_t PktLen = 0;
int wait_ret_val = 0;
unsigned long ret = 0;
wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
(pTarang->RxAppControlHead ||
Adapter->device_removed));
if ((wait_ret_val == -ERESTARTSYS)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
"Exiting as i've been asked to exit!!!\n");
return wait_ret_val;
}
if (Adapter->device_removed) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
"Device Removed... Killing the Apps...\n");
return -ENODEV;
}
if (FALSE == Adapter->fw_download_done)
return -EACCES;
down(&Adapter->RxAppControlQueuelock);
if (pTarang->RxAppControlHead) {
Packet = pTarang->RxAppControlHead;
DEQUEUEPACKET(pTarang->RxAppControlHead,
pTarang->RxAppControlTail);
pTarang->AppCtrlQueueLen--;
}
up(&Adapter->RxAppControlQueuelock);
if (Packet) {
PktLen = Packet->len;
ret = copy_to_user(buf, Packet->data,
min_t(size_t, PktLen, size));
if (ret) {
dev_kfree_skb(Packet);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Returning from copy to user failure\n");
return -EFAULT;
}
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
"Read %zd Bytes From Adapter packet = %p by process %d!\n",
PktLen, Packet, current->pid);
dev_kfree_skb(Packet);
}
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<\n");
return PktLen;
}
static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
{
struct bcm_tarang_data *pTarang = filp->private_data;
void __user *argp = (void __user *)arg;
struct bcm_mini_adapter *Adapter = pTarang->Adapter;
INT Status = STATUS_FAILURE;
int timeout = 0;
struct bcm_ioctl_buffer IoBuffer;
int bytes;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX", cmd, arg);
if (_IOC_TYPE(cmd) != BCM_IOCTL)
return -EFAULT;
if (_IOC_DIR(cmd) & _IOC_READ)
Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
Status = STATUS_SUCCESS;
if (Status)
return -EFAULT;
if (Adapter->device_removed)
return -EFAULT;
if (FALSE == Adapter->fw_download_done) {
switch (cmd) {
case IOCTL_MAC_ADDR_REQ:
case IOCTL_LINK_REQ:
case IOCTL_CM_REQUEST:
case IOCTL_SS_INFO_REQ:
case IOCTL_SEND_CONTROL_MESSAGE:
case IOCTL_IDLE_REQ:
case IOCTL_BCM_GPIO_SET_REQUEST:
case IOCTL_BCM_GPIO_STATUS_REQUEST:
return -EACCES;
default:
break;
}
}
Status = vendorextnIoctl(Adapter, cmd, arg);
if (Status != CONTINUE_COMMON_PATH)
return Status;
switch (cmd) {
/* Rdms for Swin Idle... */
case IOCTL_BCM_REGISTER_READ_PRIVATE: {
struct bcm_rdm_buffer sRdmBuffer = {0};
PCHAR temp_buff;
UINT Bufflen;
u16 temp_value;
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength > sizeof(sRdmBuffer))
return -EINVAL;
if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
return -EFAULT;
if (IoBuffer.OutputLength > USHRT_MAX ||
IoBuffer.OutputLength == 0) {
return -EINVAL;
}
Bufflen = IoBuffer.OutputLength;
temp_value = 4 - (Bufflen % 4);
Bufflen += temp_value % 4;
temp_buff = kmalloc(Bufflen, GFP_KERNEL);
if (!temp_buff)
return -ENOMEM;
bytes = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
(PUINT)temp_buff, Bufflen);
if (bytes > 0) {
Status = STATUS_SUCCESS;
if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
kfree(temp_buff);
return -EFAULT;
}
} else {
Status = bytes;
}
kfree(temp_buff);
break;
}
case IOCTL_BCM_REGISTER_WRITE_PRIVATE: {
struct bcm_wrm_buffer sWrmBuffer = {0};
UINT uiTempVar = 0;
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength > sizeof(sWrmBuffer))
return -EINVAL;
/* Get WrmBuffer structure */
if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
return -EFAULT;
uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
((uiTempVar == EEPROM_REJECT_REG_1) ||
(uiTempVar == EEPROM_REJECT_REG_2) ||
(uiTempVar == EEPROM_REJECT_REG_3) ||
(uiTempVar == EEPROM_REJECT_REG_4))) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
return -EFAULT;
}
Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
(PUINT)sWrmBuffer.Data, sizeof(ULONG));
if (Status == STATUS_SUCCESS) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
} else {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
Status = -EFAULT;
}
break;
}
case IOCTL_BCM_REGISTER_READ:
case IOCTL_BCM_EEPROM_REGISTER_READ: {
struct bcm_rdm_buffer sRdmBuffer = {0};
PCHAR temp_buff = NULL;
UINT uiTempVar = 0;
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
return -EACCES;
}
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength > sizeof(sRdmBuffer))
return -EINVAL;
if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
return -EFAULT;
if (IoBuffer.OutputLength > USHRT_MAX ||
IoBuffer.OutputLength == 0) {
return -EINVAL;
}
temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
if (!temp_buff)
return STATUS_FAILURE;
if ((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
((ULONG)sRdmBuffer.Register & 0x3)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
(int)sRdmBuffer.Register);
kfree(temp_buff);
return -EINVAL;
}
uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
bytes = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register, (PUINT)temp_buff, IoBuffer.OutputLength);
if (bytes > 0) {
Status = STATUS_SUCCESS;
if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
kfree(temp_buff);
return -EFAULT;
}
} else {
Status = bytes;
}
kfree(temp_buff);
break;
}
case IOCTL_BCM_REGISTER_WRITE:
case IOCTL_BCM_EEPROM_REGISTER_WRITE: {
struct bcm_wrm_buffer sWrmBuffer = {0};
UINT uiTempVar = 0;
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
return -EACCES;
}
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength > sizeof(sWrmBuffer))
return -EINVAL;
/* Get WrmBuffer structure */
if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
return -EFAULT;
if ((((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
((ULONG)sWrmBuffer.Register & 0x3)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)sWrmBuffer.Register);
return -EINVAL;
}
uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
((uiTempVar == EEPROM_REJECT_REG_1) ||
(uiTempVar == EEPROM_REJECT_REG_2) ||
(uiTempVar == EEPROM_REJECT_REG_3) ||
(uiTempVar == EEPROM_REJECT_REG_4)) &&
(cmd == IOCTL_BCM_REGISTER_WRITE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
return -EFAULT;
}
Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
(PUINT)sWrmBuffer.Data, sWrmBuffer.Length);
if (Status == STATUS_SUCCESS) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
} else {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
Status = -EFAULT;
}
break;
}
case IOCTL_BCM_GPIO_SET_REQUEST: {
UCHAR ucResetValue[4];
UINT value = 0;
UINT uiBit = 0;
UINT uiOperation = 0;
struct bcm_gpio_info gpio_info = {0};
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "GPIO Can't be set/clear in Low power Mode");
return -EACCES;
}
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength > sizeof(gpio_info))
return -EINVAL;
if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
return -EFAULT;
uiBit = gpio_info.uiGpioNumber;
uiOperation = gpio_info.uiGpioValue;
value = (1<<uiBit);
if (IsReqGpioIsLedInNVM(Adapter, value) == FALSE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!", value);
Status = -EINVAL;
break;
}
/* Set - setting 1 */
if (uiOperation) {
/* Set the gpio output register */
Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, (PUINT)(&value), sizeof(UINT));
if (Status == STATUS_SUCCESS) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
} else {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to set the %dth GPIO\n", uiBit);
break;
}
} else {
/* Set the gpio output register */
Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, (PUINT)(&value), sizeof(UINT));
if (Status == STATUS_SUCCESS) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
} else {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to clear the %dth GPIO\n", uiBit);
break;
}
}
bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
if (bytes < 0) {
Status = bytes;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
"GPIO_MODE_REGISTER read failed");
break;
} else {
Status = STATUS_SUCCESS;
}
/* Set the gpio mode register to output */
*(UINT *)ucResetValue |= (1<<uiBit);
Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
(PUINT)ucResetValue, sizeof(UINT));
if (Status == STATUS_SUCCESS) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO to output Mode\n");
} else {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to put GPIO in Output Mode\n");
break;
}
}
break;
case BCM_LED_THREAD_STATE_CHANGE_REQ: {
struct bcm_user_thread_req threadReq = {0};
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "User made LED thread InActive");
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "GPIO Can't be set/clear in Low power Mode");
Status = -EACCES;
break;
}
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength > sizeof(threadReq))
return -EINVAL;
if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
return -EFAULT;
/* if LED thread is running(Actively or Inactively) set it state to make inactive */
if (Adapter->LEDInfo.led_thread_running) {
if (threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Activating thread req");
Adapter->DriverState = LED_THREAD_ACTIVE;
} else {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DeActivating Thread req.....");
Adapter->DriverState = LED_THREAD_INACTIVE;
}
/* signal thread. */
wake_up(&Adapter->LEDInfo.notify_led_event);
}
}
break;
case IOCTL_BCM_GPIO_STATUS_REQUEST: {
ULONG uiBit = 0;
UCHAR ucRead[4];
struct bcm_gpio_info gpio_info = {0};
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE))
return -EACCES;
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength > sizeof(gpio_info))
return -EINVAL;
if (copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
return -EFAULT;
uiBit = gpio_info.uiGpioNumber;
/* Set the gpio output register */
bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
(PUINT)ucRead, sizeof(UINT));
if (bytes < 0) {
Status = bytes;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM Failed\n");
return Status;
} else {
Status = STATUS_SUCCESS;
}
}
break;
case IOCTL_BCM_GPIO_MULTI_REQUEST: {
UCHAR ucResetValue[4];
struct bcm_gpio_multi_info gpio_multi_info[MAX_IDX];
struct bcm_gpio_multi_info *pgpio_multi_info = (struct bcm_gpio_multi_info *)gpio_multi_info;
memset(pgpio_multi_info, 0, MAX_IDX * sizeof(struct bcm_gpio_multi_info));
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE))
return -EINVAL;
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength > sizeof(gpio_multi_info))
return -EINVAL;
if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
return -EFAULT;
if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_info[WIMAX_IDX].uiGPIOMask) == FALSE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
"Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
pgpio_multi_info[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
Status = -EINVAL;
break;
}
/* Set the gpio output register */
if ((pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
(pgpio_multi_info[WIMAX_IDX].uiGPIOCommand)) {
/* Set 1's in GPIO OUTPUT REGISTER */
*(UINT *)ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
if (*(UINT *) ucResetValue)
Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG,
(PUINT)ucResetValue, sizeof(ULONG));
if (Status != STATUS_SUCCESS) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
return Status;
}
/* Clear to 0's in GPIO OUTPUT REGISTER */
*(UINT *)ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
(~(pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
if (*(UINT *) ucResetValue)
Status = wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, (PUINT)ucResetValue, sizeof(ULONG));
if (Status != STATUS_SUCCESS) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM to BCM_GPIO_OUTPUT_CLR_REG Failed.");
return Status;
}
}
if (pgpio_multi_info[WIMAX_IDX].uiGPIOMask) {
bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
if (bytes < 0) {
Status = bytes;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "RDM to GPIO_PIN_STATE_REGISTER Failed.");
return Status;
} else {
Status = STATUS_SUCCESS;
}
pgpio_multi_info[WIMAX_IDX].uiGPIOValue = (*(UINT *)ucResetValue &
pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
}
Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Failed while copying Content to IOBufer for user space err:%d", Status);
return -EFAULT;
}
}
break;
case IOCTL_BCM_GPIO_MODE_REQUEST: {
UCHAR ucResetValue[4];
struct bcm_gpio_multi_mode gpio_multi_mode[MAX_IDX];
struct bcm_gpio_multi_mode *pgpio_multi_mode = (struct bcm_gpio_multi_mode *)gpio_multi_mode;
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE))
return -EINVAL;
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
return -EINVAL;
if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
return -EFAULT;
bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
if (bytes < 0) {
Status = bytes;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read of GPIO_MODE_REGISTER failed");
return Status;
} else {
Status = STATUS_SUCCESS;
}
/* Validating the request */
if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) == FALSE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
"Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
pgpio_multi_mode[WIMAX_IDX].uiGPIOMask, Adapter->gpioBitMap);
Status = -EINVAL;
break;
}
if (pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) {
/* write all OUT's (1's) */
*(UINT *) ucResetValue |= (pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
/* write all IN's (0's) */
*(UINT *) ucResetValue &= ~((~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
/* Currently implemented return the modes of all GPIO's
* else needs to bit AND with mask
*/
pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER, (PUINT)ucResetValue, sizeof(ULONG));
if (Status == STATUS_SUCCESS) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
"WRM to GPIO_MODE_REGISTER Done");
} else {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"WRM to GPIO_MODE_REGISTER Failed");
Status = -EFAULT;
break;
}
} else {
/* if uiGPIOMask is 0 then return mode register configuration */
pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
}
Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Failed while copying Content to IOBufer for user space err:%d", Status);
return -EFAULT;
}
}
break;
case IOCTL_MAC_ADDR_REQ:
case IOCTL_LINK_REQ:
case IOCTL_CM_REQUEST:
case IOCTL_SS_INFO_REQ:
case IOCTL_SEND_CONTROL_MESSAGE:
case IOCTL_IDLE_REQ: {
PVOID pvBuffer = NULL;
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength < sizeof(struct bcm_link_request))
return -EINVAL;
if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE)
return -EINVAL;
pvBuffer = memdup_user(IoBuffer.InputBuffer,
IoBuffer.InputLength);
if (IS_ERR(pvBuffer))
return PTR_ERR(pvBuffer);
down(&Adapter->LowPowerModeSync);
Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
!Adapter->bPreparingForLowPowerMode,
(1 * HZ));
if (Status == -ERESTARTSYS)
goto cntrlEnd;
if (Adapter->bPreparingForLowPowerMode) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
"Preparing Idle Mode is still True - Hence Rejecting control message\n");
Status = STATUS_FAILURE;
goto cntrlEnd;
}
Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
cntrlEnd:
up(&Adapter->LowPowerModeSync);
kfree(pvBuffer);
break;
}
case IOCTL_BCM_BUFFER_DOWNLOAD_START: {
if (down_trylock(&Adapter->NVMRdmWrmLock)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
"IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
return -EACCES;
}
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Starting the firmware download PID =0x%x!!!!\n", current->pid);
if (down_trylock(&Adapter->fw_download_sema))
return -EBUSY;
Adapter->bBinDownloaded = FALSE;
Adapter->fw_download_process_pid = current->pid;
Adapter->bCfgDownloaded = FALSE;
Adapter->fw_download_done = FALSE;
netif_carrier_off(Adapter->dev);
netif_stop_queue(Adapter->dev);
Status = reset_card_proc(Adapter);
if (Status) {
pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
up(&Adapter->fw_download_sema);
up(&Adapter->NVMRdmWrmLock);
return Status;
}
mdelay(10);
up(&Adapter->NVMRdmWrmLock);
return Status;
}
case IOCTL_BCM_BUFFER_DOWNLOAD: {
struct bcm_firmware_info *psFwInfo = NULL;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
if (!down_trylock(&Adapter->fw_download_sema)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Invalid way to download buffer. Use Start and then call this!!!\n");
up(&Adapter->fw_download_sema);
Status = -EINVAL;
return Status;
}
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
up(&Adapter->fw_download_sema);
return -EFAULT;
}
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Length for FW DLD is : %lx\n", IoBuffer.InputLength);
if (IoBuffer.InputLength > sizeof(struct bcm_firmware_info)) {
up(&Adapter->fw_download_sema);
return -EINVAL;
}
psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
if (!psFwInfo) {
up(&Adapter->fw_download_sema);
return -ENOMEM;
}
if (copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength)) {
up(&Adapter->fw_download_sema);
kfree(psFwInfo);
return -EFAULT;
}
if (!psFwInfo->pvMappedFirmwareAddress ||
(psFwInfo->u32FirmwareLength == 0)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
psFwInfo->u32FirmwareLength);
up(&Adapter->fw_download_sema);
kfree(psFwInfo);
Status = -EINVAL;
return Status;
}
Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
if (Status != STATUS_SUCCESS) {
if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR)
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
else
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
/* up(&Adapter->fw_download_sema); */
if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Adapter->DriverState = DRIVER_INIT;
Adapter->LEDInfo.bLedInitDone = FALSE;
wake_up(&Adapter->LEDInfo.notify_led_event);
}
}
if (Status != STATUS_SUCCESS)
up(&Adapter->fw_download_sema);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
kfree(psFwInfo);
return Status;
}
case IOCTL_BCM_BUFFER_DOWNLOAD_STOP: {
if (!down_trylock(&Adapter->fw_download_sema)) {
up(&Adapter->fw_download_sema);
return -EINVAL;
}
if (down_trylock(&Adapter->NVMRdmWrmLock)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"FW download blocked as EEPROM Read/Write is in progress\n");
up(&Adapter->fw_download_sema);
return -EACCES;
}
Adapter->bBinDownloaded = TRUE;
Adapter->bCfgDownloaded = TRUE;
atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
Adapter->CurrNumRecvDescs = 0;
Adapter->downloadDDR = 0;
/* setting the Mips to Run */
Status = run_card_proc(Adapter);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
up(&Adapter->fw_download_sema);
up(&Adapter->NVMRdmWrmLock);
return Status;
} else {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
DBG_LVL_ALL, "Firm Download Over...\n");
}
mdelay(10);
/* Wait for MailBox Interrupt */
if (StartInterruptUrb((struct bcm_interface_adapter *)Adapter->pvInterfaceAdapter))
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
timeout = 5*HZ;
Adapter->waiting_to_fw_download_done = FALSE;
wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
Adapter->waiting_to_fw_download_done, timeout);
Adapter->fw_download_process_pid = INVALID_PID;
Adapter->fw_download_done = TRUE;
atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
Adapter->CurrNumRecvDescs = 0;
Adapter->PrevNumRecvDescs = 0;
atomic_set(&Adapter->cntrlpktCnt, 0);
Adapter->LinkUpStatus = 0;
Adapter->LinkStatus = 0;
if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
Adapter->DriverState = FW_DOWNLOAD_DONE;
wake_up(&Adapter->LEDInfo.notify_led_event);
}
if (!timeout)
Status = -ENODEV;
up(&Adapter->fw_download_sema);
up(&Adapter->NVMRdmWrmLock);
return Status;
}
case IOCTL_BE_BUCKET_SIZE:
Status = 0;
if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
Status = -EFAULT;
break;
case IOCTL_RTPS_BUCKET_SIZE:
Status = 0;
if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
Status = -EFAULT;
break;
case IOCTL_CHIP_RESET: {
INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
if (NVMAccess) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
return -EACCES;
}
down(&Adapter->RxAppControlQueuelock);
Status = reset_card_proc(Adapter);
flushAllAppQ();
up(&Adapter->RxAppControlQueuelock);
up(&Adapter->NVMRdmWrmLock);
ResetCounters(Adapter);
break;
}
case IOCTL_QOS_THRESHOLD: {
USHORT uiLoopIndex;
Status = 0;
for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
(unsigned long __user *)arg)) {
Status = -EFAULT;
break;
}
}
break;
}
case IOCTL_DUMP_PACKET_INFO:
DumpPackInfo(Adapter);
DumpPhsRules(&Adapter->stBCMPhsContext);
Status = STATUS_SUCCESS;
break;
case IOCTL_GET_PACK_INFO:
if (copy_to_user(argp, &Adapter->PackInfo, sizeof(struct bcm_packet_info)*NO_OF_QUEUES))
return -EFAULT;
Status = STATUS_SUCCESS;
break;
case IOCTL_BCM_SWITCH_TRANSFER_MODE: {
UINT uiData = 0;
if (copy_from_user(&uiData, argp, sizeof(UINT)))
return -EFAULT;
if (uiData) {
/* Allow All Packets */
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
} else {
/* Allow IP only Packets */
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
Adapter->TransferMode = IP_PACKET_ONLY_MODE;
}
Status = STATUS_SUCCESS;
break;
}
case IOCTL_BCM_GET_DRIVER_VERSION: {
ulong len;
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
len = min_t(ulong, IoBuffer.OutputLength, strlen(VER_FILEVERSION_STR) + 1);
if (copy_to_user(IoBuffer.OutputBuffer, VER_FILEVERSION_STR, len))
return -EFAULT;
Status = STATUS_SUCCESS;
break;
}
case IOCTL_BCM_GET_CURRENT_STATUS: {
struct bcm_link_state link_state;
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
return -EFAULT;
}
if (IoBuffer.OutputLength != sizeof(link_state)) {
Status = -EINVAL;
break;
}
memset(&link_state, 0, sizeof(link_state));
link_state.bIdleMode = Adapter->IdleMode;
link_state.bShutdownMode = Adapter->bShutStatus;
link_state.ucLinkStatus = Adapter->LinkStatus;
if (copy_to_user(IoBuffer.OutputBuffer, &link_state, min_t(size_t, sizeof(link_state), IoBuffer.OutputLength))) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
return -EFAULT;
}
Status = STATUS_SUCCESS;
break;
}
case IOCTL_BCM_SET_MAC_TRACING: {
UINT tracing_flag;
/* copy ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (copy_from_user(&tracing_flag, IoBuffer.InputBuffer, sizeof(UINT)))
return -EFAULT;
if (tracing_flag)
Adapter->pTarangs->MacTracingEnabled = TRUE;
else
Adapter->pTarangs->MacTracingEnabled = FALSE;
break;
}
case IOCTL_BCM_GET_DSX_INDICATION: {
ULONG ulSFId = 0;
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.OutputLength < sizeof(struct bcm_add_indication_alt)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Mismatch req: %lx needed is =0x%zx!!!",
IoBuffer.OutputLength, sizeof(struct bcm_add_indication_alt));
return -EINVAL;
}
if (copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
return -EFAULT;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId);
get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_BCM_GET_HOST_MIBS: {
PVOID temp_buff;
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.OutputLength != sizeof(struct bcm_host_stats_mibs)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
"Length Check failed %lu %zd\n",
IoBuffer.OutputLength, sizeof(struct bcm_host_stats_mibs));
return -EINVAL;
}
/* FIXME: HOST_STATS are too big for kmalloc (122048)! */
temp_buff = kzalloc(sizeof(struct bcm_host_stats_mibs), GFP_KERNEL);
if (!temp_buff)
return STATUS_FAILURE;
Status = ProcessGetHostMibs(Adapter, temp_buff);
GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
if (Status != STATUS_FAILURE)
if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(struct bcm_host_stats_mibs))) {
kfree(temp_buff);
return -EFAULT;
}
kfree(temp_buff);
break;
}
case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
if ((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE == Adapter->IdleMode)) {
Adapter->usIdleModePattern = ABORT_IDLE_MODE;
Adapter->bWakeUpDevice = TRUE;
wake_up(&Adapter->process_rx_cntrlpkt);
}
Status = STATUS_SUCCESS;
break;
case IOCTL_BCM_BULK_WRM: {
struct bcm_bulk_wrm_buffer *pBulkBuffer;
UINT uiTempVar = 0;
PCHAR pvBuffer = NULL;
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
Status = -EACCES;
break;
}
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.InputLength < sizeof(ULONG) * 2)
return -EINVAL;
pvBuffer = memdup_user(IoBuffer.InputBuffer,
IoBuffer.InputLength);
if (IS_ERR(pvBuffer))
return PTR_ERR(pvBuffer);
pBulkBuffer = (struct bcm_bulk_wrm_buffer *)pvBuffer;
if (((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
((ULONG)pBulkBuffer->Register & 0x3)) {
BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", (int)pBulkBuffer->Register);
kfree(pvBuffer);
Status = -EINVAL;
break;
}
uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
if (!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE) &&
((uiTempVar == EEPROM_REJECT_REG_1) ||
(uiTempVar == EEPROM_REJECT_REG_2) ||
(uiTempVar == EEPROM_REJECT_REG_3) ||
(uiTempVar == EEPROM_REJECT_REG_4)) &&
(cmd == IOCTL_BCM_REGISTER_WRITE)) {
kfree(pvBuffer);
BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
Status = -EFAULT;
break;
}
if (pBulkBuffer->SwapEndian == FALSE)
Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
else
Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
if (Status != STATUS_SUCCESS)
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
kfree(pvBuffer);
break;
}
case IOCTL_BCM_GET_NVM_SIZE:
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH) {
if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
return -EFAULT;
}
Status = STATUS_SUCCESS;
break;
case IOCTL_BCM_CAL_INIT: {
UINT uiSectorSize = 0 ;
if (Adapter->eNVMType == NVM_FLASH) {
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
return -EFAULT;
if ((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE)) {
if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
sizeof(UINT)))
return -EFAULT;
} else {
if (IsFlash2x(Adapter)) {
if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize, sizeof(UINT)))
return -EFAULT;
} else {
if ((TRUE == Adapter->bShutStatus) || (TRUE == Adapter->IdleMode)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is in Idle/Shutdown Mode\n");
return -EACCES;
}
Adapter->uiSectorSize = uiSectorSize;
BcmUpdateSectorSize(Adapter, Adapter->uiSectorSize);
}
}
Status = STATUS_SUCCESS;
} else {
Status = STATUS_FAILURE;
}
}
break;
case IOCTL_BCM_SET_DEBUG:
#ifdef DEBUG
{
struct bcm_user_debug_state sUserDebugState;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(struct bcm_user_debug_state)))
return -EFAULT;
BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
sUserDebugState.OnOff, sUserDebugState.Type);
/* sUserDebugState.Subtype <<= 1; */
sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
/* Update new 'DebugState' in the Adapter */
Adapter->stDebugState.type |= sUserDebugState.Type;
/* Subtype: A bitmap of 32 bits for Subtype per Type.
* Valid indexes in 'subtype' array: 1,2,4,8
* corresponding to valid Type values. Hence we can use the 'Type' field
* as the index value, ignoring the array entries 0,3,5,6,7 !
*/
if (sUserDebugState.OnOff)
Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
else
Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
BCM_SHOW_DEBUG_BITMAP(Adapter);
}
#endif
break;
case IOCTL_BCM_NVM_READ:
case IOCTL_BCM_NVM_WRITE: {
struct bcm_nvm_readwrite stNVMReadWrite;
PUCHAR pReadData = NULL;
ULONG ulDSDMagicNumInUsrBuff = 0;
struct timeval tv0, tv1;
memset(&tv0, 0, sizeof(struct timeval));
memset(&tv1, 0, sizeof(struct timeval));
if ((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
return -EFAULT;
}
if (IsFlash2x(Adapter)) {
if ((Adapter->eActiveDSD != DSD0) &&
(Adapter->eActiveDSD != DSD1) &&
(Adapter->eActiveDSD != DSD2)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "No DSD is active..hence NVM Command is blocked");
return STATUS_FAILURE;
}
}
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (copy_from_user(&stNVMReadWrite,
(IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
sizeof(struct bcm_nvm_readwrite)))
return -EFAULT;
/*
* Deny the access if the offset crosses the cal area limit.
*/
if (stNVMReadWrite.uiNumBytes > Adapter->uiNVMDSDSize)
return STATUS_FAILURE;
if (stNVMReadWrite.uiOffset > Adapter->uiNVMDSDSize - stNVMReadWrite.uiNumBytes) {
/* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allow access beyond NVM Size: 0x%x 0x%x\n", stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes); */
return STATUS_FAILURE;
}
pReadData = memdup_user(stNVMReadWrite.pBuffer,
stNVMReadWrite.uiNumBytes);
if (IS_ERR(pReadData))
return PTR_ERR(pReadData);
do_gettimeofday(&tv0);
if (IOCTL_BCM_NVM_READ == cmd) {
down(&Adapter->NVMRdmWrmLock);
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
up(&Adapter->NVMRdmWrmLock);
kfree(pReadData);
return -EACCES;
}
Status = BeceemNVMRead(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
up(&Adapter->NVMRdmWrmLock);
if (Status != STATUS_SUCCESS) {
kfree(pReadData);
return Status;
}
if (copy_to_user(stNVMReadWrite.pBuffer, pReadData, stNVMReadWrite.uiNumBytes)) {
kfree(pReadData);
return -EFAULT;
}
} else {
down(&Adapter->NVMRdmWrmLock);
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
up(&Adapter->NVMRdmWrmLock);
kfree(pReadData);
return -EACCES;
}
Adapter->bHeaderChangeAllowed = TRUE;
if (IsFlash2x(Adapter)) {
/*
* New Requirement:-
* DSD section updation will be allowed in two case:-
* 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
* 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
* corrupted then user space program first modify the DSD header with valid DSD sig so
* that this as well as further write may be worthwhile.
*
* This restriction has been put assuming that if DSD sig is corrupted, DSD
* data won't be considered valid.
*/
Status = BcmFlash2xCorruptSig(Adapter, Adapter->eActiveDSD);
if (Status != STATUS_SUCCESS) {
if (((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize) ||
(stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
up(&Adapter->NVMRdmWrmLock);
kfree(pReadData);
return Status;
}
ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
if (ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "DSD Sig is present neither in Flash nor User provided Input..");
up(&Adapter->NVMRdmWrmLock);
kfree(pReadData);
return Status;
}
}
}
Status = BeceemNVMWrite(Adapter, (PUINT)pReadData, stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
if (IsFlash2x(Adapter))
BcmFlash2xWriteSig(Adapter, Adapter->eActiveDSD);
Adapter->bHeaderChangeAllowed = FALSE;
up(&Adapter->NVMRdmWrmLock);
if (Status != STATUS_SUCCESS) {
kfree(pReadData);
return Status;
}
}
do_gettimeofday(&tv1);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " timetaken by Write/read :%ld msec\n", (tv1.tv_sec - tv0.tv_sec)*1000 + (tv1.tv_usec - tv0.tv_usec)/1000);
kfree(pReadData);
return STATUS_SUCCESS;
}
case IOCTL_BCM_FLASH2X_SECTION_READ: {
struct bcm_flash2x_readwrite sFlash2xRead = {0};
PUCHAR pReadBuff = NULL ;
UINT NOB = 0;
UINT BuffSize = 0;
UINT ReadBytes = 0;
UINT ReadOffset = 0;
void __user *OutPutBuff;
if (IsFlash2x(Adapter) != TRUE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
return -EINVAL;
}
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
/* Reading FLASH 2.x READ structure */
if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_readwrite)))
return -EFAULT;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xRead.Section);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%x", sFlash2xRead.offset);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xRead.numOfBytes);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xRead.bVerify);
/* This was internal to driver for raw read. now it has ben exposed to user space app. */
if (validateFlash2xReadWrite(Adapter, &sFlash2xRead) == FALSE)
return STATUS_FAILURE;
NOB = sFlash2xRead.numOfBytes;
if (NOB > Adapter->uiSectorSize)
BuffSize = Adapter->uiSectorSize;
else
BuffSize = NOB;
ReadOffset = sFlash2xRead.offset ;
OutPutBuff = IoBuffer.OutputBuffer;
pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
if (pReadBuff == NULL) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
return -ENOMEM;
}
down(&Adapter->NVMRdmWrmLock);
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
up(&Adapter->NVMRdmWrmLock);
kfree(pReadBuff);
return -EACCES;
}
while (NOB) {
if (NOB > Adapter->uiSectorSize)
ReadBytes = Adapter->uiSectorSize;
else
ReadBytes = NOB;
/* Reading the data from Flash 2.x */
Status = BcmFlash2xBulkRead(Adapter, (PUINT)pReadBuff, sFlash2xRead.Section, ReadOffset, ReadBytes);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Flash 2x read err with Status :%d", Status);
break;
}
BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy to use failed with status :%d", Status);
up(&Adapter->NVMRdmWrmLock);
kfree(pReadBuff);
return -EFAULT;
}
NOB = NOB - ReadBytes;
if (NOB) {
ReadOffset = ReadOffset + ReadBytes;
OutPutBuff = OutPutBuff + ReadBytes ;
}
}
up(&Adapter->NVMRdmWrmLock);
kfree(pReadBuff);
}
break;
case IOCTL_BCM_FLASH2X_SECTION_WRITE: {
struct bcm_flash2x_readwrite sFlash2xWrite = {0};
PUCHAR pWriteBuff;
void __user *InputAddr;
UINT NOB = 0;
UINT BuffSize = 0;
UINT WriteOffset = 0;
UINT WriteBytes = 0;
if (IsFlash2x(Adapter) != TRUE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
return -EINVAL;
}
/* First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite */
Adapter->bAllDSDWriteAllow = FALSE;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
/* Reading FLASH 2.x READ structure */
if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_readwrite)))
return -EFAULT;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.Section :%x", sFlash2xWrite.Section);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.offset :%d", sFlash2xWrite.offset);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.numOfBytes :%x", sFlash2xWrite.numOfBytes);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\nsFlash2xRead.bVerify :%x\n", sFlash2xWrite.bVerify);
if ((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) && (sFlash2xWrite.Section != VSA2)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Only VSA write is allowed");
return -EINVAL;
}
if (validateFlash2xReadWrite(Adapter, &sFlash2xWrite) == FALSE)
return STATUS_FAILURE;
InputAddr = sFlash2xWrite.pDataBuff;
WriteOffset = sFlash2xWrite.offset;
NOB = sFlash2xWrite.numOfBytes;
if (NOB > Adapter->uiSectorSize)
BuffSize = Adapter->uiSectorSize;
else
BuffSize = NOB ;
pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
if (pWriteBuff == NULL)
return -ENOMEM;
/* extracting the remainder of the given offset. */
WriteBytes = Adapter->uiSectorSize;
if (WriteOffset % Adapter->uiSectorSize)
WriteBytes = Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
if (NOB < WriteBytes)
WriteBytes = NOB;
down(&Adapter->NVMRdmWrmLock);
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
up(&Adapter->NVMRdmWrmLock);
kfree(pWriteBuff);
return -EACCES;
}
BcmFlash2xCorruptSig(Adapter, sFlash2xWrite.Section);
do {
Status = copy_from_user(pWriteBuff, InputAddr, WriteBytes);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to user failed with status :%d", Status);
up(&Adapter->NVMRdmWrmLock);
kfree(pWriteBuff);
return -EFAULT;
}
BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pWriteBuff, WriteBytes);
/* Writing the data from Flash 2.x */
Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pWriteBuff, sFlash2xWrite.Section, WriteOffset, WriteBytes, sFlash2xWrite.bVerify);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
break;
}
NOB = NOB - WriteBytes;
if (NOB) {
WriteOffset = WriteOffset + WriteBytes;
InputAddr = InputAddr + WriteBytes;
if (NOB > Adapter->uiSectorSize)
WriteBytes = Adapter->uiSectorSize;
else
WriteBytes = NOB;
}
} while (NOB > 0);
BcmFlash2xWriteSig(Adapter, sFlash2xWrite.Section);
up(&Adapter->NVMRdmWrmLock);
kfree(pWriteBuff);
}
break;
case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP: {
struct bcm_flash2x_bitmap *psFlash2xBitMap;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.OutputLength != sizeof(struct bcm_flash2x_bitmap))
return -EINVAL;
psFlash2xBitMap = kzalloc(sizeof(struct bcm_flash2x_bitmap), GFP_KERNEL);
if (psFlash2xBitMap == NULL) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory is not available");
return -ENOMEM;
}
/* Reading the Flash Sectio Bit map */
down(&Adapter->NVMRdmWrmLock);
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
up(&Adapter->NVMRdmWrmLock);
kfree(psFlash2xBitMap);
return -EACCES;
}
BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
up(&Adapter->NVMRdmWrmLock);
if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(struct bcm_flash2x_bitmap))) {
kfree(psFlash2xBitMap);
return -EFAULT;
}
kfree(psFlash2xBitMap);
}
break;
case IOCTL_BCM_SET_ACTIVE_SECTION: {
enum bcm_flash2x_section_val eFlash2xSectionVal = 0;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
if (IsFlash2x(Adapter) != TRUE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
return -EINVAL;
}
Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
return -EFAULT;
}
Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
return -EFAULT;
}
down(&Adapter->NVMRdmWrmLock);
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
up(&Adapter->NVMRdmWrmLock);
return -EACCES;
}
Status = BcmSetActiveSection(Adapter, eFlash2xSectionVal);
if (Status)
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Failed to make it's priority Highest. Status %d", Status);
up(&Adapter->NVMRdmWrmLock);
}
break;
case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION: {
/* Right Now we are taking care of only DSD */
Adapter->bAllDSDWriteAllow = FALSE;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
Status = STATUS_SUCCESS;
}
break;
case IOCTL_BCM_COPY_SECTION: {
struct bcm_flash2x_copy_section sCopySectStrut = {0};
Status = STATUS_SUCCESS;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
Adapter->bAllDSDWriteAllow = FALSE;
if (IsFlash2x(Adapter) != TRUE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
return -EINVAL;
}
Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
return -EFAULT;
}
Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(struct bcm_flash2x_copy_section));
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
return -EFAULT;
}
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
if (IsSectionExistInFlash(Adapter, sCopySectStrut.SrcSection) == FALSE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Source Section<%x> does not exixt in Flash ", sCopySectStrut.SrcSection);
return -EINVAL;
}
if (IsSectionExistInFlash(Adapter, sCopySectStrut.DstSection) == FALSE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut.DstSection);
return -EINVAL;
}
if (sCopySectStrut.SrcSection == sCopySectStrut.DstSection) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source and Destination section should be different");
return -EINVAL;
}
down(&Adapter->NVMRdmWrmLock);
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
up(&Adapter->NVMRdmWrmLock);
return -EACCES;
}
if (sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2) {
if (IsNonCDLessDevice(Adapter)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device is Non-CDLess hence won't have ISO !!");
Status = -EINVAL;
} else if (sCopySectStrut.numOfBytes == 0) {
Status = BcmCopyISO(Adapter, sCopySectStrut);
} else {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Partial Copy of ISO section is not Allowed..");
Status = STATUS_FAILURE;
}
up(&Adapter->NVMRdmWrmLock);
return Status;
}
Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
sCopySectStrut.DstSection, sCopySectStrut.offset, sCopySectStrut.numOfBytes);
up(&Adapter->NVMRdmWrmLock);
}
break;
case IOCTL_BCM_GET_FLASH_CS_INFO: {
Status = STATUS_SUCCESS;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
return -EFAULT;
}
if (Adapter->eNVMType != NVM_FLASH) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Connected device does not have flash");
Status = -EINVAL;
break;
}
if (IsFlash2x(Adapter) == TRUE) {
if (IoBuffer.OutputLength < sizeof(struct bcm_flash2x_cs_info))
return -EINVAL;
if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(struct bcm_flash2x_cs_info)))
return -EFAULT;
} else {
if (IoBuffer.OutputLength < sizeof(struct bcm_flash_cs_info))
return -EINVAL;
if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(struct bcm_flash_cs_info)))
return -EFAULT;
}
}
break;
case IOCTL_BCM_SELECT_DSD: {
UINT SectOfset = 0;
enum bcm_flash2x_section_val eFlash2xSectionVal;
eFlash2xSectionVal = NO_SECTION_VAL;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SELECT_DSD Called");
if (IsFlash2x(Adapter) != TRUE) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Does not have 2.x map");
return -EINVAL;
}
Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
return -EFAULT;
}
Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
return -EFAULT;
}
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read Section :%d", eFlash2xSectionVal);
if ((eFlash2xSectionVal != DSD0) &&
(eFlash2xSectionVal != DSD1) &&
(eFlash2xSectionVal != DSD2)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Passed section<%x> is not DSD section", eFlash2xSectionVal);
return STATUS_FAILURE;
}
SectOfset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal);
if (SectOfset == INVALID_OFFSET) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal);
return -EINVAL;
}
Adapter->bAllDSDWriteAllow = TRUE;
Adapter->ulFlashCalStart = SectOfset;
Adapter->eActiveDSD = eFlash2xSectionVal;
}
Status = STATUS_SUCCESS;
break;
case IOCTL_BCM_NVM_RAW_READ: {
struct bcm_nvm_readwrite stNVMRead;
INT NOB ;
INT BuffSize ;
INT ReadOffset = 0;
UINT ReadBytes = 0 ;
PUCHAR pReadBuff;
void __user *OutPutBuff;
if (Adapter->eNVMType != NVM_FLASH) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "NVM TYPE is not Flash");
return -EINVAL;
}
/* Copy Ioctl Buffer structure */
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
return -EFAULT;
}
if (copy_from_user(&stNVMRead, IoBuffer.OutputBuffer, sizeof(struct bcm_nvm_readwrite)))
return -EFAULT;
NOB = stNVMRead.uiNumBytes;
/* In Raw-Read max Buff size : 64MB */
if (NOB > DEFAULT_BUFF_SIZE)
BuffSize = DEFAULT_BUFF_SIZE;
else
BuffSize = NOB;
ReadOffset = stNVMRead.uiOffset;
OutPutBuff = stNVMRead.pBuffer;
pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
if (pReadBuff == NULL) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for Flash 2.x Read Structure");
Status = -ENOMEM;
break;
}
down(&Adapter->NVMRdmWrmLock);
if ((Adapter->IdleMode == TRUE) ||
(Adapter->bShutStatus == TRUE) ||
(Adapter->bPreparingForLowPowerMode == TRUE)) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Device is in Idle/Shutdown Mode\n");
kfree(pReadBuff);
up(&Adapter->NVMRdmWrmLock);
return -EACCES;
}
Adapter->bFlashRawRead = TRUE;
while (NOB) {
if (NOB > DEFAULT_BUFF_SIZE)
ReadBytes = DEFAULT_BUFF_SIZE;
else
ReadBytes = NOB;
/* Reading the data from Flash 2.x */
Status = BeceemNVMRead(Adapter, (PUINT)pReadBuff, ReadOffset, ReadBytes);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash 2x read err with Status :%d", Status);
break;
}
BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, pReadBuff, ReadBytes);
Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy to use failed with status :%d", Status);
up(&Adapter->NVMRdmWrmLock);
kfree(pReadBuff);
return -EFAULT;
}
NOB = NOB - ReadBytes;
if (NOB) {
ReadOffset = ReadOffset + ReadBytes;
OutPutBuff = OutPutBuff + ReadBytes;
}
}
Adapter->bFlashRawRead = FALSE;
up(&Adapter->NVMRdmWrmLock);
kfree(pReadBuff);
break;
}
case IOCTL_BCM_CNTRLMSG_MASK: {
ULONG RxCntrlMsgBitMask = 0;
/* Copy Ioctl Buffer structure */
Status = copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer));
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of Ioctl buffer is failed from user space");
return -EFAULT;
}
if (IoBuffer.InputLength != sizeof(unsigned long)) {
Status = -EINVAL;
break;
}
Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
if (Status) {
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "copy of control bit mask failed from user space");
return -EFAULT;
}
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask;
}
break;
case IOCTL_BCM_GET_DEVICE_DRIVER_INFO: {
struct bcm_driver_info DevInfo;
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
memset(&DevInfo, 0, sizeof(DevInfo));
DevInfo.MaxRDMBufferSize = BUFFER_4K;
DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
DevInfo.u32RxAlignmentCorrection = 0;
DevInfo.u32NVMType = Adapter->eNVMType;
DevInfo.u32InterfaceType = BCM_USB;
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.OutputLength < sizeof(DevInfo))
return -EINVAL;
if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
return -EFAULT;
}
break;
case IOCTL_BCM_TIME_SINCE_NET_ENTRY: {
struct bcm_time_elapsed stTimeElapsedSinceNetEntry = {0};
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
return -EFAULT;
if (IoBuffer.OutputLength < sizeof(struct bcm_time_elapsed))
return -EINVAL;
stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(struct bcm_time_elapsed)))
return -EFAULT;
}
break;
case IOCTL_CLOSE_NOTIFICATION:
BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_CLOSE_NOTIFICATION");
break;
default:
pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
Status = STATUS_FAILURE;
break;
}
return Status;
}
static const struct file_operations bcm_fops = {
.owner = THIS_MODULE,
.open = bcm_char_open,
.release = bcm_char_release,
.read = bcm_char_read,
.unlocked_ioctl = bcm_char_ioctl,
.llseek = no_llseek,
};
int register_control_device_interface(struct bcm_mini_adapter *Adapter)
{
if (Adapter->major > 0)
return Adapter->major;
Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
if (Adapter->major < 0) {
pr_err(DRV_NAME ": could not created character device\n");
return Adapter->major;
}
Adapter->pstCreatedClassDevice = device_create(bcm_class, NULL,
MKDEV(Adapter->major, 0),
Adapter, DEV_NAME);
if (IS_ERR(Adapter->pstCreatedClassDevice)) {
pr_err(DRV_NAME ": class device create failed\n");
unregister_chrdev(Adapter->major, DEV_NAME);
return PTR_ERR(Adapter->pstCreatedClassDevice);
}
return 0;
}
void unregister_control_device_interface(struct bcm_mini_adapter *Adapter)
{
if (Adapter->major > 0) {
device_destroy(bcm_class, MKDEV(Adapter->major, 0));
unregister_chrdev(Adapter->major, DEV_NAME);
}
}
| gpl-2.0 |
somcom3x/kernel_gogh | drivers/ata/pata_rdc.c | 3586 | 10956 | /*
* pata_rdc - Driver for later RDC PATA controllers
*
* This is actually a driver for hardware meeting
* INCITS 370-2004 (1510D): ATA Host Adapter Standards
*
* Based on ata_piix.
*
* 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, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/gfp.h>
#include <scsi/scsi_host.h>
#include <linux/libata.h>
#include <linux/dmi.h>
#define DRV_NAME "pata_rdc"
#define DRV_VERSION "0.01"
struct rdc_host_priv {
u32 saved_iocfg;
};
/**
* rdc_pata_cable_detect - Probe host controller cable detect info
* @ap: Port for which cable detect info is desired
*
* Read 80c cable indicator from ATA PCI device's PCI config
* register. This register is normally set by firmware (BIOS).
*
* LOCKING:
* None (inherited from caller).
*/
static int rdc_pata_cable_detect(struct ata_port *ap)
{
struct rdc_host_priv *hpriv = ap->host->private_data;
u8 mask;
/* check BIOS cable detect results */
mask = 0x30 << (2 * ap->port_no);
if ((hpriv->saved_iocfg & mask) == 0)
return ATA_CBL_PATA40;
return ATA_CBL_PATA80;
}
/**
* rdc_pata_prereset - prereset for PATA host controller
* @link: Target link
* @deadline: deadline jiffies for the operation
*
* LOCKING:
* None (inherited from caller).
*/
static int rdc_pata_prereset(struct ata_link *link, unsigned long deadline)
{
struct ata_port *ap = link->ap;
struct pci_dev *pdev = to_pci_dev(ap->host->dev);
static const struct pci_bits rdc_enable_bits[] = {
{ 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
{ 0x43U, 1U, 0x80UL, 0x80UL }, /* port 1 */
};
if (!pci_test_config_bits(pdev, &rdc_enable_bits[ap->port_no]))
return -ENOENT;
return ata_sff_prereset(link, deadline);
}
/**
* rdc_set_piomode - Initialize host controller PATA PIO timings
* @ap: Port whose timings we are configuring
* @adev: um
*
* Set PIO mode for device, in host controller PCI config space.
*
* LOCKING:
* None (inherited from caller).
*/
static void rdc_set_piomode(struct ata_port *ap, struct ata_device *adev)
{
unsigned int pio = adev->pio_mode - XFER_PIO_0;
struct pci_dev *dev = to_pci_dev(ap->host->dev);
unsigned int is_slave = (adev->devno != 0);
unsigned int master_port= ap->port_no ? 0x42 : 0x40;
unsigned int slave_port = 0x44;
u16 master_data;
u8 slave_data;
u8 udma_enable;
int control = 0;
static const /* ISP RTC */
u8 timings[][2] = { { 0, 0 },
{ 0, 0 },
{ 1, 0 },
{ 2, 1 },
{ 2, 3 }, };
if (pio >= 2)
control |= 1; /* TIME1 enable */
if (ata_pio_need_iordy(adev))
control |= 2; /* IE enable */
if (adev->class == ATA_DEV_ATA)
control |= 4; /* PPE enable */
/* PIO configuration clears DTE unconditionally. It will be
* programmed in set_dmamode which is guaranteed to be called
* after set_piomode if any DMA mode is available.
*/
pci_read_config_word(dev, master_port, &master_data);
if (is_slave) {
/* clear TIME1|IE1|PPE1|DTE1 */
master_data &= 0xff0f;
/* Enable SITRE (separate slave timing register) */
master_data |= 0x4000;
/* enable PPE1, IE1 and TIME1 as needed */
master_data |= (control << 4);
pci_read_config_byte(dev, slave_port, &slave_data);
slave_data &= (ap->port_no ? 0x0f : 0xf0);
/* Load the timing nibble for this slave */
slave_data |= ((timings[pio][0] << 2) | timings[pio][1])
<< (ap->port_no ? 4 : 0);
} else {
/* clear ISP|RCT|TIME0|IE0|PPE0|DTE0 */
master_data &= 0xccf0;
/* Enable PPE, IE and TIME as appropriate */
master_data |= control;
/* load ISP and RCT */
master_data |=
(timings[pio][0] << 12) |
(timings[pio][1] << 8);
}
pci_write_config_word(dev, master_port, master_data);
if (is_slave)
pci_write_config_byte(dev, slave_port, slave_data);
/* Ensure the UDMA bit is off - it will be turned back on if
UDMA is selected */
pci_read_config_byte(dev, 0x48, &udma_enable);
udma_enable &= ~(1 << (2 * ap->port_no + adev->devno));
pci_write_config_byte(dev, 0x48, udma_enable);
}
/**
* rdc_set_dmamode - Initialize host controller PATA PIO timings
* @ap: Port whose timings we are configuring
* @adev: Drive in question
*
* Set UDMA mode for device, in host controller PCI config space.
*
* LOCKING:
* None (inherited from caller).
*/
static void rdc_set_dmamode(struct ata_port *ap, struct ata_device *adev)
{
struct pci_dev *dev = to_pci_dev(ap->host->dev);
u8 master_port = ap->port_no ? 0x42 : 0x40;
u16 master_data;
u8 speed = adev->dma_mode;
int devid = adev->devno + 2 * ap->port_no;
u8 udma_enable = 0;
static const /* ISP RTC */
u8 timings[][2] = { { 0, 0 },
{ 0, 0 },
{ 1, 0 },
{ 2, 1 },
{ 2, 3 }, };
pci_read_config_word(dev, master_port, &master_data);
pci_read_config_byte(dev, 0x48, &udma_enable);
if (speed >= XFER_UDMA_0) {
unsigned int udma = adev->dma_mode - XFER_UDMA_0;
u16 udma_timing;
u16 ideconf;
int u_clock, u_speed;
/*
* UDMA is handled by a combination of clock switching and
* selection of dividers
*
* Handy rule: Odd modes are UDMATIMx 01, even are 02
* except UDMA0 which is 00
*/
u_speed = min(2 - (udma & 1), udma);
if (udma == 5)
u_clock = 0x1000; /* 100Mhz */
else if (udma > 2)
u_clock = 1; /* 66Mhz */
else
u_clock = 0; /* 33Mhz */
udma_enable |= (1 << devid);
/* Load the CT/RP selection */
pci_read_config_word(dev, 0x4A, &udma_timing);
udma_timing &= ~(3 << (4 * devid));
udma_timing |= u_speed << (4 * devid);
pci_write_config_word(dev, 0x4A, udma_timing);
/* Select a 33/66/100Mhz clock */
pci_read_config_word(dev, 0x54, &ideconf);
ideconf &= ~(0x1001 << devid);
ideconf |= u_clock << devid;
pci_write_config_word(dev, 0x54, ideconf);
} else {
/*
* MWDMA is driven by the PIO timings. We must also enable
* IORDY unconditionally along with TIME1. PPE has already
* been set when the PIO timing was set.
*/
unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
unsigned int control;
u8 slave_data;
const unsigned int needed_pio[3] = {
XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
};
int pio = needed_pio[mwdma] - XFER_PIO_0;
control = 3; /* IORDY|TIME1 */
/* If the drive MWDMA is faster than it can do PIO then
we must force PIO into PIO0 */
if (adev->pio_mode < needed_pio[mwdma])
/* Enable DMA timing only */
control |= 8; /* PIO cycles in PIO0 */
if (adev->devno) { /* Slave */
master_data &= 0xFF4F; /* Mask out IORDY|TIME1|DMAONLY */
master_data |= control << 4;
pci_read_config_byte(dev, 0x44, &slave_data);
slave_data &= (ap->port_no ? 0x0f : 0xf0);
/* Load the matching timing */
slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << (ap->port_no ? 4 : 0);
pci_write_config_byte(dev, 0x44, slave_data);
} else { /* Master */
master_data &= 0xCCF4; /* Mask out IORDY|TIME1|DMAONLY
and master timing bits */
master_data |= control;
master_data |=
(timings[pio][0] << 12) |
(timings[pio][1] << 8);
}
udma_enable &= ~(1 << devid);
pci_write_config_word(dev, master_port, master_data);
}
pci_write_config_byte(dev, 0x48, udma_enable);
}
static struct ata_port_operations rdc_pata_ops = {
.inherits = &ata_bmdma32_port_ops,
.cable_detect = rdc_pata_cable_detect,
.set_piomode = rdc_set_piomode,
.set_dmamode = rdc_set_dmamode,
.prereset = rdc_pata_prereset,
};
static struct ata_port_info rdc_port_info = {
.flags = ATA_FLAG_SLAVE_POSS,
.pio_mask = ATA_PIO4,
.mwdma_mask = ATA_MWDMA12_ONLY,
.udma_mask = ATA_UDMA5,
.port_ops = &rdc_pata_ops,
};
static struct scsi_host_template rdc_sht = {
ATA_BMDMA_SHT(DRV_NAME),
};
/**
* rdc_init_one - Register PIIX ATA PCI device with kernel services
* @pdev: PCI device to register
* @ent: Entry in rdc_pci_tbl matching with @pdev
*
* Called from kernel PCI layer. We probe for combined mode (sigh),
* and then hand over control to libata, for it to do the rest.
*
* LOCKING:
* Inherited from PCI layer (may sleep).
*
* RETURNS:
* Zero on success, or -ERRNO value.
*/
static int __devinit rdc_init_one(struct pci_dev *pdev,
const struct pci_device_id *ent)
{
static int printed_version;
struct device *dev = &pdev->dev;
struct ata_port_info port_info[2];
const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] };
unsigned long port_flags;
struct ata_host *host;
struct rdc_host_priv *hpriv;
int rc;
if (!printed_version++)
dev_printk(KERN_DEBUG, &pdev->dev,
"version " DRV_VERSION "\n");
port_info[0] = rdc_port_info;
port_info[1] = rdc_port_info;
port_flags = port_info[0].flags;
/* enable device and prepare host */
rc = pcim_enable_device(pdev);
if (rc)
return rc;
hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
if (!hpriv)
return -ENOMEM;
/* Save IOCFG, this will be used for cable detection, quirk
* detection and restoration on detach.
*/
pci_read_config_dword(pdev, 0x54, &hpriv->saved_iocfg);
rc = ata_pci_bmdma_prepare_host(pdev, ppi, &host);
if (rc)
return rc;
host->private_data = hpriv;
pci_intx(pdev, 1);
host->flags |= ATA_HOST_PARALLEL_SCAN;
pci_set_master(pdev);
return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, &rdc_sht);
}
static void rdc_remove_one(struct pci_dev *pdev)
{
struct ata_host *host = dev_get_drvdata(&pdev->dev);
struct rdc_host_priv *hpriv = host->private_data;
pci_write_config_dword(pdev, 0x54, hpriv->saved_iocfg);
ata_pci_remove_one(pdev);
}
static const struct pci_device_id rdc_pci_tbl[] = {
{ PCI_DEVICE(0x17F3, 0x1011), },
{ PCI_DEVICE(0x17F3, 0x1012), },
{ } /* terminate list */
};
static struct pci_driver rdc_pci_driver = {
.name = DRV_NAME,
.id_table = rdc_pci_tbl,
.probe = rdc_init_one,
.remove = rdc_remove_one,
};
static int __init rdc_init(void)
{
return pci_register_driver(&rdc_pci_driver);
}
static void __exit rdc_exit(void)
{
pci_unregister_driver(&rdc_pci_driver);
}
module_init(rdc_init);
module_exit(rdc_exit);
MODULE_AUTHOR("Alan Cox (based on ata_piix)");
MODULE_DESCRIPTION("SCSI low-level driver for RDC PATA controllers");
MODULE_LICENSE("GPL");
MODULE_DEVICE_TABLE(pci, rdc_pci_tbl);
MODULE_VERSION(DRV_VERSION);
| gpl-2.0 |
TeamHorizon/android_kernel_lge_hammerhead | arch/arm/mach-omap1/leds-osk.c | 4866 | 2020 | /*
* linux/arch/arm/mach-omap1/leds-osk.c
*
* LED driver for OSK with optional Mistral QVGA board
*/
#include <linux/gpio.h>
#include <linux/init.h>
#include <mach/hardware.h>
#include <asm/leds.h>
#include "leds.h"
#define LED_STATE_ENABLED (1 << 0)
#define LED_STATE_CLAIMED (1 << 1)
static u8 led_state;
#define TIMER_LED (1 << 3) /* Mistral board */
#define IDLE_LED (1 << 4) /* Mistral board */
static u8 hw_led_state;
#ifdef CONFIG_OMAP_OSK_MISTRAL
/* For now, all system indicators require the Mistral board, since that
* LED can be manipulated without a task context. This LED is either red,
* or green, but not both; it can't give the full "disco led" effect.
*/
#define GPIO_LED_RED 3
#define GPIO_LED_GREEN OMAP_MPUIO(4)
static void mistral_setled(void)
{
int red = 0;
int green = 0;
if (hw_led_state & TIMER_LED)
red = 1;
else if (hw_led_state & IDLE_LED)
green = 1;
/* else both sides are disabled */
gpio_set_value(GPIO_LED_GREEN, green);
gpio_set_value(GPIO_LED_RED, red);
}
#endif
void osk_leds_event(led_event_t evt)
{
unsigned long flags;
u16 leds;
local_irq_save(flags);
if (!(led_state & LED_STATE_ENABLED) && evt != led_start)
goto done;
leds = hw_led_state;
switch (evt) {
case led_start:
led_state |= LED_STATE_ENABLED;
hw_led_state = 0;
leds = ~0;
break;
case led_halted:
case led_stop:
led_state &= ~LED_STATE_ENABLED;
hw_led_state = 0;
break;
case led_claim:
led_state |= LED_STATE_CLAIMED;
hw_led_state = 0;
leds = ~0;
break;
case led_release:
led_state &= ~LED_STATE_CLAIMED;
hw_led_state = 0;
break;
#ifdef CONFIG_OMAP_OSK_MISTRAL
case led_timer:
hw_led_state ^= TIMER_LED;
mistral_setled();
break;
case led_idle_start: /* idle == off */
hw_led_state &= ~IDLE_LED;
mistral_setled();
break;
case led_idle_end:
hw_led_state |= IDLE_LED;
mistral_setled();
break;
#endif /* CONFIG_OMAP_OSK_MISTRAL */
default:
break;
}
leds ^= hw_led_state;
done:
local_irq_restore(flags);
}
| gpl-2.0 |
nhondong/android_kernel_samsung_v2wifixx | drivers/media/video/s5p-tv/sii9234_drv.c | 4866 | 10938 | /*
* Samsung MHL interface driver
*
* Copyright (C) 2011 Samsung Electronics Co.Ltd
* Author: Tomasz Stanislawski <t.stanislaws@samsung.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 <linux/delay.h>
#include <linux/err.h>
#include <linux/freezer.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/pm_runtime.h>
#include <linux/regulator/machine.h>
#include <linux/slab.h>
#include <mach/gpio.h>
#include <plat/gpio-cfg.h>
#include <media/sii9234.h>
#include <media/v4l2-subdev.h>
MODULE_AUTHOR("Tomasz Stanislawski <t.stanislaws@samsung.com>");
MODULE_DESCRIPTION("Samsung MHL interface driver");
MODULE_LICENSE("GPL");
struct sii9234_context {
struct i2c_client *client;
struct regulator *power;
int gpio_n_reset;
struct v4l2_subdev sd;
};
static inline struct sii9234_context *sd_to_context(struct v4l2_subdev *sd)
{
return container_of(sd, struct sii9234_context, sd);
}
static inline int sii9234_readb(struct i2c_client *client, int addr)
{
return i2c_smbus_read_byte_data(client, addr);
}
static inline int sii9234_writeb(struct i2c_client *client, int addr, int value)
{
return i2c_smbus_write_byte_data(client, addr, value);
}
static inline int sii9234_writeb_mask(struct i2c_client *client, int addr,
int value, int mask)
{
int ret;
ret = i2c_smbus_read_byte_data(client, addr);
if (ret < 0)
return ret;
ret = (ret & ~mask) | (value & mask);
return i2c_smbus_write_byte_data(client, addr, ret);
}
static inline int sii9234_readb_idx(struct i2c_client *client, int addr)
{
int ret;
ret = i2c_smbus_write_byte_data(client, 0xbc, addr >> 8);
if (ret < 0)
return ret;
ret = i2c_smbus_write_byte_data(client, 0xbd, addr & 0xff);
if (ret < 0)
return ret;
return i2c_smbus_read_byte_data(client, 0xbe);
}
static inline int sii9234_writeb_idx(struct i2c_client *client, int addr,
int value)
{
int ret;
ret = i2c_smbus_write_byte_data(client, 0xbc, addr >> 8);
if (ret < 0)
return ret;
ret = i2c_smbus_write_byte_data(client, 0xbd, addr & 0xff);
if (ret < 0)
return ret;
ret = i2c_smbus_write_byte_data(client, 0xbe, value);
return ret;
}
static inline int sii9234_writeb_idx_mask(struct i2c_client *client, int addr,
int value, int mask)
{
int ret;
ret = sii9234_readb_idx(client, addr);
if (ret < 0)
return ret;
ret = (ret & ~mask) | (value & mask);
return sii9234_writeb_idx(client, addr, ret);
}
static int sii9234_reset(struct sii9234_context *ctx)
{
struct i2c_client *client = ctx->client;
struct device *dev = &client->dev;
int ret, tries;
gpio_direction_output(ctx->gpio_n_reset, 1);
mdelay(1);
gpio_direction_output(ctx->gpio_n_reset, 0);
mdelay(1);
gpio_direction_output(ctx->gpio_n_reset, 1);
mdelay(1);
/* going to TTPI mode */
ret = sii9234_writeb(client, 0xc7, 0);
if (ret < 0) {
dev_err(dev, "failed to set TTPI mode\n");
return ret;
}
for (tries = 0; tries < 100 ; ++tries) {
ret = sii9234_readb(client, 0x1b);
if (ret > 0)
break;
if (ret < 0) {
dev_err(dev, "failed to reset device\n");
return -EIO;
}
mdelay(1);
}
if (tries == 100) {
dev_err(dev, "maximal number of tries reached\n");
return -EIO;
}
return 0;
}
static int sii9234_verify_version(struct i2c_client *client)
{
struct device *dev = &client->dev;
int family, rev, tpi_rev, dev_id, sub_id, hdcp, id;
family = sii9234_readb(client, 0x1b);
rev = sii9234_readb(client, 0x1c) & 0x0f;
tpi_rev = sii9234_readb(client, 0x1d) & 0x7f;
dev_id = sii9234_readb_idx(client, 0x0103);
sub_id = sii9234_readb_idx(client, 0x0102);
hdcp = sii9234_readb(client, 0x30);
if (family < 0 || rev < 0 || tpi_rev < 0 || dev_id < 0 ||
sub_id < 0 || hdcp < 0) {
dev_err(dev, "failed to read chip's version\n");
return -EIO;
}
id = (dev_id << 8) | sub_id;
dev_info(dev, "chip: SiL%02x family: %02x, rev: %02x\n",
id, family, rev);
dev_info(dev, "tpi_rev:%02x, hdcp: %02x\n", tpi_rev, hdcp);
if (id != 0x9234) {
dev_err(dev, "not supported chip\n");
return -ENODEV;
}
return 0;
}
static u8 data[][3] = {
/* setup from driver created by doonsoo45.kim */
{ 0x01, 0x05, 0x04 }, /* Enable Auto soft reset on SCDT = 0 */
{ 0x01, 0x08, 0x35 }, /* Power Up TMDS Tx Core */
{ 0x01, 0x0d, 0x1c }, /* HDMI Transcode mode enable */
{ 0x01, 0x2b, 0x01 }, /* Enable HDCP Compliance workaround */
{ 0x01, 0x79, 0x40 }, /* daniel test...MHL_INT */
{ 0x01, 0x80, 0x34 }, /* Enable Rx PLL Clock Value */
{ 0x01, 0x90, 0x27 }, /* Enable CBUS discovery */
{ 0x01, 0x91, 0xe5 }, /* Skip RGND detection */
{ 0x01, 0x92, 0x46 }, /* Force MHD mode */
{ 0x01, 0x93, 0xdc }, /* Disable CBUS pull-up during RGND measurement */
{ 0x01, 0x94, 0x66 }, /* 1.8V CBUS VTH & GND threshold */
{ 0x01, 0x95, 0x31 }, /* RGND block & single discovery attempt */
{ 0x01, 0x96, 0x22 }, /* use 1K and 2K setting */
{ 0x01, 0xa0, 0x10 }, /* SIMG: Term mode */
{ 0x01, 0xa1, 0xfc }, /* Disable internal Mobile HD driver */
{ 0x01, 0xa3, 0xfa }, /* SIMG: Output Swing default EB, 3x Clk Mult */
{ 0x01, 0xa5, 0x80 }, /* SIMG: RGND Hysterisis, 3x mode for Beast */
{ 0x01, 0xa6, 0x0c }, /* SIMG: Swing Offset */
{ 0x02, 0x3d, 0x3f }, /* Power up CVCC 1.2V core */
{ 0x03, 0x00, 0x00 }, /* SIMG: correcting HW default */
{ 0x03, 0x11, 0x01 }, /* Enable TxPLL Clock */
{ 0x03, 0x12, 0x15 }, /* Enable Tx Clock Path & Equalizer */
{ 0x03, 0x13, 0x60 }, /* SIMG: Set termination value */
{ 0x03, 0x14, 0xf0 }, /* SIMG: Change CKDT level */
{ 0x03, 0x17, 0x07 }, /* SIMG: PLL Calrefsel */
{ 0x03, 0x1a, 0x20 }, /* VCO Cal */
{ 0x03, 0x22, 0xe0 }, /* SIMG: Auto EQ */
{ 0x03, 0x23, 0xc0 }, /* SIMG: Auto EQ */
{ 0x03, 0x24, 0xa0 }, /* SIMG: Auto EQ */
{ 0x03, 0x25, 0x80 }, /* SIMG: Auto EQ */
{ 0x03, 0x26, 0x60 }, /* SIMG: Auto EQ */
{ 0x03, 0x27, 0x40 }, /* SIMG: Auto EQ */
{ 0x03, 0x28, 0x20 }, /* SIMG: Auto EQ */
{ 0x03, 0x29, 0x00 }, /* SIMG: Auto EQ */
{ 0x03, 0x31, 0x0b }, /* SIMG: Rx PLL BW value from I2C BW ~ 4MHz */
{ 0x03, 0x45, 0x06 }, /* SIMG: DPLL Mode */
{ 0x03, 0x4b, 0x06 }, /* SIMG: Correcting HW default */
{ 0x03, 0x4c, 0xa0 }, /* Manual zone control */
{ 0x03, 0x4d, 0x02 }, /* SIMG: PLL Mode Value (order is important) */
};
static int sii9234_set_internal(struct sii9234_context *ctx)
{
struct i2c_client *client = ctx->client;
int i, ret;
for (i = 0; i < ARRAY_SIZE(data); ++i) {
int addr = (data[i][0] << 8) | data[i][1];
ret = sii9234_writeb_idx(client, addr, data[i][2]);
if (ret < 0)
return ret;
}
return 0;
}
static int sii9234_runtime_suspend(struct device *dev)
{
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct sii9234_context *ctx = sd_to_context(sd);
struct i2c_client *client = ctx->client;
dev_info(dev, "suspend start\n");
sii9234_writeb_mask(client, 0x1e, 3, 3);
regulator_disable(ctx->power);
return 0;
}
static int sii9234_runtime_resume(struct device *dev)
{
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct sii9234_context *ctx = sd_to_context(sd);
struct i2c_client *client = ctx->client;
int ret;
dev_info(dev, "resume start\n");
regulator_enable(ctx->power);
ret = sii9234_reset(ctx);
if (ret)
goto fail;
/* enable tpi */
ret = sii9234_writeb_mask(client, 0x1e, 1, 0);
if (ret < 0)
goto fail;
ret = sii9234_set_internal(ctx);
if (ret < 0)
goto fail;
return 0;
fail:
dev_err(dev, "failed to resume\n");
regulator_disable(ctx->power);
return ret;
}
static const struct dev_pm_ops sii9234_pm_ops = {
.runtime_suspend = sii9234_runtime_suspend,
.runtime_resume = sii9234_runtime_resume,
};
static int sii9234_s_power(struct v4l2_subdev *sd, int on)
{
struct sii9234_context *ctx = sd_to_context(sd);
int ret;
if (on)
ret = pm_runtime_get_sync(&ctx->client->dev);
else
ret = pm_runtime_put(&ctx->client->dev);
/* only values < 0 indicate errors */
return IS_ERR_VALUE(ret) ? ret : 0;
}
static int sii9234_s_stream(struct v4l2_subdev *sd, int enable)
{
struct sii9234_context *ctx = sd_to_context(sd);
/* (dis/en)able TDMS output */
sii9234_writeb_mask(ctx->client, 0x1a, enable ? 0 : ~0 , 1 << 4);
return 0;
}
static const struct v4l2_subdev_core_ops sii9234_core_ops = {
.s_power = sii9234_s_power,
};
static const struct v4l2_subdev_video_ops sii9234_video_ops = {
.s_stream = sii9234_s_stream,
};
static const struct v4l2_subdev_ops sii9234_ops = {
.core = &sii9234_core_ops,
.video = &sii9234_video_ops,
};
static int __devinit sii9234_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct device *dev = &client->dev;
struct sii9234_platform_data *pdata = dev->platform_data;
struct sii9234_context *ctx;
int ret;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx) {
dev_err(dev, "out of memory\n");
ret = -ENOMEM;
goto fail;
}
ctx->client = client;
ctx->power = regulator_get(dev, "hdmi-en");
if (IS_ERR(ctx->power)) {
dev_err(dev, "failed to acquire regulator hdmi-en\n");
ret = PTR_ERR(ctx->power);
goto fail_ctx;
}
ctx->gpio_n_reset = pdata->gpio_n_reset;
ret = gpio_request(ctx->gpio_n_reset, "MHL_RST");
if (ret) {
dev_err(dev, "failed to acquire MHL_RST gpio\n");
goto fail_power;
}
v4l2_i2c_subdev_init(&ctx->sd, client, &sii9234_ops);
pm_runtime_enable(dev);
/* enable device */
ret = pm_runtime_get_sync(dev);
if (ret)
goto fail_pm;
/* verify chip version */
ret = sii9234_verify_version(client);
if (ret)
goto fail_pm_get;
/* stop processing */
pm_runtime_put(dev);
dev_info(dev, "probe successful\n");
return 0;
fail_pm_get:
pm_runtime_put_sync(dev);
fail_pm:
pm_runtime_disable(dev);
gpio_free(ctx->gpio_n_reset);
fail_power:
regulator_put(ctx->power);
fail_ctx:
kfree(ctx);
fail:
dev_err(dev, "probe failed\n");
return ret;
}
static int __devexit sii9234_remove(struct i2c_client *client)
{
struct device *dev = &client->dev;
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct sii9234_context *ctx = sd_to_context(sd);
pm_runtime_disable(dev);
gpio_free(ctx->gpio_n_reset);
regulator_put(ctx->power);
kfree(ctx);
dev_info(dev, "remove successful\n");
return 0;
}
static const struct i2c_device_id sii9234_id[] = {
{ "SII9234", 0 },
{ },
};
MODULE_DEVICE_TABLE(i2c, sii9234_id);
static struct i2c_driver sii9234_driver = {
.driver = {
.name = "sii9234",
.owner = THIS_MODULE,
.pm = &sii9234_pm_ops,
},
.probe = sii9234_probe,
.remove = __devexit_p(sii9234_remove),
.id_table = sii9234_id,
};
static int __init sii9234_init(void)
{
return i2c_add_driver(&sii9234_driver);
}
module_init(sii9234_init);
static void __exit sii9234_exit(void)
{
i2c_del_driver(&sii9234_driver);
}
module_exit(sii9234_exit);
| gpl-2.0 |
mialwe/midnight-i9000-kernel | net/ax25/ax25_addr.c | 5122 | 6217 | /*
* 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.
*
* Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
*/
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/sockios.h>
#include <linux/net.h>
#include <net/ax25.h>
#include <linux/inet.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <net/sock.h>
#include <asm/uaccess.h>
#include <asm/system.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
/*
* The default broadcast address of an interface is QST-0; the default address
* is LINUX-1. The null address is defined as a callsign of all spaces with
* an SSID of zero.
*/
const ax25_address ax25_bcast =
{{'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, 0 << 1}};
const ax25_address ax25_defaddr =
{{'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, 1 << 1}};
const ax25_address null_ax25_address =
{{' ' << 1, ' ' << 1, ' ' << 1, ' ' << 1, ' ' << 1, ' ' << 1, 0 << 1}};
EXPORT_SYMBOL_GPL(ax25_bcast);
EXPORT_SYMBOL_GPL(ax25_defaddr);
EXPORT_SYMBOL(null_ax25_address);
/*
* ax25 -> ascii conversion
*/
char *ax2asc(char *buf, const ax25_address *a)
{
char c, *s;
int n;
for (n = 0, s = buf; n < 6; n++) {
c = (a->ax25_call[n] >> 1) & 0x7F;
if (c != ' ') *s++ = c;
}
*s++ = '-';
if ((n = ((a->ax25_call[6] >> 1) & 0x0F)) > 9) {
*s++ = '1';
n -= 10;
}
*s++ = n + '0';
*s++ = '\0';
if (*buf == '\0' || *buf == '-')
return "*";
return buf;
}
EXPORT_SYMBOL(ax2asc);
/*
* ascii -> ax25 conversion
*/
void asc2ax(ax25_address *addr, const char *callsign)
{
const char *s;
int n;
for (s = callsign, n = 0; n < 6; n++) {
if (*s != '\0' && *s != '-')
addr->ax25_call[n] = *s++;
else
addr->ax25_call[n] = ' ';
addr->ax25_call[n] <<= 1;
addr->ax25_call[n] &= 0xFE;
}
if (*s++ == '\0') {
addr->ax25_call[6] = 0x00;
return;
}
addr->ax25_call[6] = *s++ - '0';
if (*s != '\0') {
addr->ax25_call[6] *= 10;
addr->ax25_call[6] += *s++ - '0';
}
addr->ax25_call[6] <<= 1;
addr->ax25_call[6] &= 0x1E;
}
EXPORT_SYMBOL(asc2ax);
/*
* Compare two ax.25 addresses
*/
int ax25cmp(const ax25_address *a, const ax25_address *b)
{
int ct = 0;
while (ct < 6) {
if ((a->ax25_call[ct] & 0xFE) != (b->ax25_call[ct] & 0xFE)) /* Clean off repeater bits */
return 1;
ct++;
}
if ((a->ax25_call[ct] & 0x1E) == (b->ax25_call[ct] & 0x1E)) /* SSID without control bit */
return 0;
return 2; /* Partial match */
}
EXPORT_SYMBOL(ax25cmp);
/*
* Compare two AX.25 digipeater paths.
*/
int ax25digicmp(const ax25_digi *digi1, const ax25_digi *digi2)
{
int i;
if (digi1->ndigi != digi2->ndigi)
return 1;
if (digi1->lastrepeat != digi2->lastrepeat)
return 1;
for (i = 0; i < digi1->ndigi; i++)
if (ax25cmp(&digi1->calls[i], &digi2->calls[i]) != 0)
return 1;
return 0;
}
/*
* Given an AX.25 address pull of to, from, digi list, command/response and the start of data
*
*/
const unsigned char *ax25_addr_parse(const unsigned char *buf, int len,
ax25_address *src, ax25_address *dest, ax25_digi *digi, int *flags,
int *dama)
{
int d = 0;
if (len < 14) return NULL;
if (flags != NULL) {
*flags = 0;
if (buf[6] & AX25_CBIT)
*flags = AX25_COMMAND;
if (buf[13] & AX25_CBIT)
*flags = AX25_RESPONSE;
}
if (dama != NULL)
*dama = ~buf[13] & AX25_DAMA_FLAG;
/* Copy to, from */
if (dest != NULL)
memcpy(dest, buf + 0, AX25_ADDR_LEN);
if (src != NULL)
memcpy(src, buf + 7, AX25_ADDR_LEN);
buf += 2 * AX25_ADDR_LEN;
len -= 2 * AX25_ADDR_LEN;
digi->lastrepeat = -1;
digi->ndigi = 0;
while (!(buf[-1] & AX25_EBIT)) {
if (d >= AX25_MAX_DIGIS) return NULL; /* Max of 6 digis */
if (len < 7) return NULL; /* Short packet */
memcpy(&digi->calls[d], buf, AX25_ADDR_LEN);
digi->ndigi = d + 1;
if (buf[6] & AX25_HBIT) {
digi->repeated[d] = 1;
digi->lastrepeat = d;
} else {
digi->repeated[d] = 0;
}
buf += AX25_ADDR_LEN;
len -= AX25_ADDR_LEN;
d++;
}
return buf;
}
/*
* Assemble an AX.25 header from the bits
*/
int ax25_addr_build(unsigned char *buf, const ax25_address *src,
const ax25_address *dest, const ax25_digi *d, int flag, int modulus)
{
int len = 0;
int ct = 0;
memcpy(buf, dest, AX25_ADDR_LEN);
buf[6] &= ~(AX25_EBIT | AX25_CBIT);
buf[6] |= AX25_SSSID_SPARE;
if (flag == AX25_COMMAND) buf[6] |= AX25_CBIT;
buf += AX25_ADDR_LEN;
len += AX25_ADDR_LEN;
memcpy(buf, src, AX25_ADDR_LEN);
buf[6] &= ~(AX25_EBIT | AX25_CBIT);
buf[6] &= ~AX25_SSSID_SPARE;
if (modulus == AX25_MODULUS)
buf[6] |= AX25_SSSID_SPARE;
else
buf[6] |= AX25_ESSID_SPARE;
if (flag == AX25_RESPONSE) buf[6] |= AX25_CBIT;
/*
* Fast path the normal digiless path
*/
if (d == NULL || d->ndigi == 0) {
buf[6] |= AX25_EBIT;
return 2 * AX25_ADDR_LEN;
}
buf += AX25_ADDR_LEN;
len += AX25_ADDR_LEN;
while (ct < d->ndigi) {
memcpy(buf, &d->calls[ct], AX25_ADDR_LEN);
if (d->repeated[ct])
buf[6] |= AX25_HBIT;
else
buf[6] &= ~AX25_HBIT;
buf[6] &= ~AX25_EBIT;
buf[6] |= AX25_SSSID_SPARE;
buf += AX25_ADDR_LEN;
len += AX25_ADDR_LEN;
ct++;
}
buf[-1] |= AX25_EBIT;
return len;
}
int ax25_addr_size(const ax25_digi *dp)
{
if (dp == NULL)
return 2 * AX25_ADDR_LEN;
return AX25_ADDR_LEN * (2 + dp->ndigi);
}
/*
* Reverse Digipeat List. May not pass both parameters as same struct
*/
void ax25_digi_invert(const ax25_digi *in, ax25_digi *out)
{
int ct;
out->ndigi = in->ndigi;
out->lastrepeat = in->ndigi - in->lastrepeat - 2;
/* Invert the digipeaters */
for (ct = 0; ct < in->ndigi; ct++) {
out->calls[ct] = in->calls[in->ndigi - ct - 1];
if (ct <= out->lastrepeat) {
out->calls[ct].ax25_call[6] |= AX25_HBIT;
out->repeated[ct] = 1;
} else {
out->calls[ct].ax25_call[6] &= ~AX25_HBIT;
out->repeated[ct] = 0;
}
}
}
| gpl-2.0 |
JianguoWEI/linux-efq-final | drivers/staging/vt6656/channel.c | 8194 | 74369 | /*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*
* File: channel.c
*
* Purpose: Channel number mapping
*
* Author: Lucas Lin
*
* Date: Dec 24, 2004
*
*
*
* Revision History:
* 01-18-2005 RobertYu: remove the for loop searching in ChannelValid,
* change ChannelRuleTab to lookup-type, reorder table items.
*
*
*/
#include <linux/kernel.h>
#include "country.h"
#include "channel.h"
#include "rf.h"
/*--------------------- Static Definitions -------------------------*/
static int msglevel = MSG_LEVEL_INFO;
//static int msglevel =MSG_LEVEL_DEBUG;
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Export Definitions -------------------------*/
static SChannelTblElement sChannelTbl[CB_MAX_CHANNEL+1] =
{
{0, 0, FALSE},
{1, 2412, TRUE},
{2, 2417, TRUE},
{3, 2422, TRUE},
{4, 2427, TRUE},
{5, 2432, TRUE},
{6, 2437, TRUE},
{7, 2442, TRUE},
{8, 2447, TRUE},
{9, 2452, TRUE},
{10, 2457, TRUE},
{11, 2462, TRUE},
{12, 2467, TRUE},
{13, 2472, TRUE},
{14, 2484, TRUE},
{183, 4915, TRUE}, //15
{184, 4920, TRUE}, //16
{185, 4925, TRUE}, //17
{187, 4935, TRUE}, //18
{188, 4940, TRUE}, //19
{189, 4945, TRUE}, //20
{192, 4960, TRUE}, //21
{196, 4980, TRUE}, //22
{7, 5035, TRUE}, //23
{8, 5040, TRUE}, //24
{9, 5045, TRUE}, //25
{11, 5055, TRUE}, //26
{12, 5060, TRUE}, //27
{16, 5080, TRUE}, //28
{34, 5170, TRUE}, //29
{36, 5180, TRUE}, //30
{38, 5190, TRUE}, //31
{40, 5200, TRUE}, //32
{42, 5210, TRUE}, //33
{44, 5220, TRUE}, //34
{46, 5230, TRUE}, //35
{48, 5240, TRUE}, //36
{52, 5260, TRUE}, //37
{56, 5280, TRUE}, //38
{60, 5300, TRUE}, //39
{64, 5320, TRUE}, //40
{100, 5500, TRUE}, //41
{104, 5520, TRUE}, //42
{108, 5540, TRUE}, //43
{112, 5560, TRUE}, //44
{116, 5580, TRUE}, //45
{120, 5600, TRUE}, //46
{124, 5620, TRUE}, //47
{128, 5640, TRUE}, //48
{132, 5660, TRUE}, //49
{136, 5680, TRUE}, //50
{140, 5700, TRUE}, //51
{149, 5745, TRUE}, //52
{153, 5765, TRUE}, //53
{157, 5785, TRUE}, //54
{161, 5805, TRUE}, //55
{165, 5825, TRUE} //56
};
/************************************************************************
* The Radar regulation rules for each country
************************************************************************/
static struct
{
BYTE byChannelCountryCode; /* The country code */
char chCountryCode[2];
BYTE bChannelIdxList[CB_MAX_CHANNEL]; /* Available channels Index */
BYTE byPower[CB_MAX_CHANNEL];
} ChannelRuleTab[] =
{
/************************************************************************
* This table is based on Athero driver rules
************************************************************************/
/* Country Available channels, ended with 0 */
/* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 */
{CCODE_FCC, {'U','S'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
, { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
{CCODE_TELEC, {'J','P'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
, { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 23, 0, 0, 23, 0, 23, 23, 0, 23, 0, 0, 23, 23, 23, 0, 23, 0, 23, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
{CCODE_ETSI, {'E','U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
, { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
{CCODE_RESV3, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0,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 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
, { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
{CCODE_FRANCE, {'F','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
, { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
{CCODE_GERMANY, {'D','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
, { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
{CCODE_GREECE, {'G','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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E_LITHUANIA, {'L','T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
, { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
{CCODE_LUXEMBURG, {'L','U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
, { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
{CCODE_MACAU, {'M','O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
, { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }
/* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 */
};
#define NUM_RULES ARRAY_SIZE(ChannelRuleTab)
/*--------------------- Export function -------------------------*/
/************************************************************************
* Country Channel Valid
* Input: CountryCode, ChannelNum
* ChanneIndex is defined as VT3253 MAC channel:
* 1 = 2.4G channel 1
* 2 = 2.4G channel 2
* ...
* 14 = 2.4G channel 14
* 15 = 4.9G channel 183
* 16 = 4.9G channel 184
* .....
* Output: TRUE if the specified 5GHz band is allowed to be used.
False otherwise.
// 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22)
// 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
// 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
************************************************************************/
BOOL
ChannelValid(unsigned int CountryCode, unsigned int ChannelIndex)
{
BOOL bValid;
bValid = FALSE;
/*
* If Channel Index is invalid, return invalid
*/
if ((ChannelIndex > CB_MAX_CHANNEL) ||
(ChannelIndex == 0))
{
bValid = FALSE;
goto exit;
}
bValid = sChannelTbl[ChannelIndex].bValid;
exit:
return (bValid);
} /* end ChannelValid */
/************************************************************************
* CHvChannelGetList
* Get Available Channel List for a given country
* Input:
* CountryCode = The country code defined in country.h
* Output:
* ChannelBitMask = (QWORD *) correspondent bit mask
* of available channels
* 0x0000000000000001 means channel 1 is supported
* 0x0000000000000003 means channel 1,2 are supported
* 0x000000000000000F means channel 1,2,..15 are supported
************************************************************************/
BOOL
CHvChannelGetList (
unsigned int uCountryCodeIdx,
PBYTE pbyChannelTable
)
{
if (uCountryCodeIdx >= CCODE_MAX) {
return (FALSE);
}
memcpy(pbyChannelTable, ChannelRuleTab[uCountryCodeIdx].bChannelIdxList, CB_MAX_CHANNEL);
return (TRUE);
}
void CHvInitChannelTable(void *pDeviceHandler)
{
PSDevice pDevice = (PSDevice) pDeviceHandler;
BOOL bMultiBand = FALSE;
unsigned int ii;
for (ii = 1; ii <= CB_MAX_CHANNEL; ii++)
sChannelTbl[ii].bValid = FALSE;
switch (pDevice->byRFType) {
case RF_AL2230:
case RF_AL2230S:
case RF_VT3226:
case RF_VT3226D0:
bMultiBand = FALSE;
break;
case RF_AIROHA7230:
case RF_VT3342A0:
default :
bMultiBand = TRUE;
break;
}
if ((pDevice->dwDiagRefCount != 0) ||
(pDevice->b11hEable == TRUE)) {
if (bMultiBand == TRUE) {
for (ii = 0; ii < CB_MAX_CHANNEL; ii++) {
sChannelTbl[ii+1].bValid = TRUE;
//pDevice->abyRegPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
//pDevice->abyLocalPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
}
for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
//pDevice->abyRegPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
//pDevice->abyLocalPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
}
} else {
for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
sChannelTbl[ii+1].bValid = TRUE;
//pDevice->abyRegPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
//pDevice->abyLocalPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
}
}
} else if (pDevice->byZoneType <= CCODE_MAX) {
if (bMultiBand == TRUE) {
for (ii = 0; ii < CB_MAX_CHANNEL; ii++) {
if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
sChannelTbl[ii+1].bValid = TRUE;
//pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
//pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
}
}
} else {
for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
sChannelTbl[ii+1].bValid = TRUE;
//pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
//pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
}
}
}
}
DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO"Zone=[%d][%c][%c]!!\n",pDevice->byZoneType,ChannelRuleTab[pDevice->byZoneType].chCountryCode[0],ChannelRuleTab[pDevice->byZoneType].chCountryCode[1]);
for (ii = 0; ii < CB_MAX_CHANNEL; ii++) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Channel[%d] is [%d]\n",sChannelTbl[ii].byChannelNumber,sChannelTbl[ii+1].bValid);
/*if (pDevice->abyRegPwr[ii+1] == 0) {
pDevice->abyRegPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
}
if (pDevice->abyLocalPwr[ii+1] == 0) {
pDevice->abyLocalPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
}*/
}
}
BYTE CHbyGetChannelMapping(BYTE byChannelNumber)
{
BYTE ii;
BYTE byCHMapping = 0;
for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) {
if (sChannelTbl[ii].byChannelNumber == byChannelNumber)
byCHMapping = ii;
}
return byCHMapping;
}
| gpl-2.0 |
lyfkevin/Wind_iproj_JB_kernel | drivers/ide/opti621.c | 9218 | 4592 | /*
* Copyright (C) 1996-1998 Linus Torvalds & authors (see below)
*/
/*
* Authors:
* Jaromir Koutek <miri@punknet.cz>,
* Jan Harkes <jaharkes@cwi.nl>,
* Mark Lord <mlord@pobox.com>
* Some parts of code are from ali14xx.c and from rz1000.c.
*/
#include <linux/types.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/ide.h>
#include <asm/io.h>
#define DRV_NAME "opti621"
#define READ_REG 0 /* index of Read cycle timing register */
#define WRITE_REG 1 /* index of Write cycle timing register */
#define CNTRL_REG 3 /* index of Control register */
#define STRAP_REG 5 /* index of Strap register */
#define MISC_REG 6 /* index of Miscellaneous register */
static int reg_base;
static DEFINE_SPINLOCK(opti621_lock);
/* Write value to register reg, base of register
* is at reg_base (0x1f0 primary, 0x170 secondary,
* if not changed by PCI configuration).
* This is from setupvic.exe program.
*/
static void write_reg(u8 value, int reg)
{
inw(reg_base + 1);
inw(reg_base + 1);
outb(3, reg_base + 2);
outb(value, reg_base + reg);
outb(0x83, reg_base + 2);
}
/* Read value from register reg, base of register
* is at reg_base (0x1f0 primary, 0x170 secondary,
* if not changed by PCI configuration).
* This is from setupvic.exe program.
*/
static u8 read_reg(int reg)
{
u8 ret = 0;
inw(reg_base + 1);
inw(reg_base + 1);
outb(3, reg_base + 2);
ret = inb(reg_base + reg);
outb(0x83, reg_base + 2);
return ret;
}
static void opti621_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
{
ide_drive_t *pair = ide_get_pair_dev(drive);
unsigned long flags;
unsigned long mode = drive->pio_mode, pair_mode;
const u8 pio = mode - XFER_PIO_0;
u8 tim, misc, addr_pio = pio, clk;
/* DRDY is default 2 (by OPTi Databook) */
static const u8 addr_timings[2][5] = {
{ 0x20, 0x10, 0x00, 0x00, 0x00 }, /* 33 MHz */
{ 0x10, 0x10, 0x00, 0x00, 0x00 }, /* 25 MHz */
};
static const u8 data_rec_timings[2][5] = {
{ 0x5b, 0x45, 0x32, 0x21, 0x20 }, /* 33 MHz */
{ 0x48, 0x34, 0x21, 0x10, 0x10 } /* 25 MHz */
};
ide_set_drivedata(drive, (void *)mode);
if (pair) {
pair_mode = (unsigned long)ide_get_drivedata(pair);
if (pair_mode && pair_mode < mode)
addr_pio = pair_mode - XFER_PIO_0;
}
spin_lock_irqsave(&opti621_lock, flags);
reg_base = hwif->io_ports.data_addr;
/* allow Register-B */
outb(0xc0, reg_base + CNTRL_REG);
/* hmm, setupvic.exe does this ;-) */
outb(0xff, reg_base + 5);
/* if reads 0xff, adapter not exist? */
(void)inb(reg_base + CNTRL_REG);
/* if reads 0xc0, no interface exist? */
read_reg(CNTRL_REG);
/* check CLK speed */
clk = read_reg(STRAP_REG) & 1;
printk(KERN_INFO "%s: CLK = %d MHz\n", hwif->name, clk ? 25 : 33);
tim = data_rec_timings[clk][pio];
misc = addr_timings[clk][addr_pio];
/* select Index-0/1 for Register-A/B */
write_reg(drive->dn & 1, MISC_REG);
/* set read cycle timings */
write_reg(tim, READ_REG);
/* set write cycle timings */
write_reg(tim, WRITE_REG);
/* use Register-A for drive 0 */
/* use Register-B for drive 1 */
write_reg(0x85, CNTRL_REG);
/* set address setup, DRDY timings, */
/* and read prefetch for both drives */
write_reg(misc, MISC_REG);
spin_unlock_irqrestore(&opti621_lock, flags);
}
static const struct ide_port_ops opti621_port_ops = {
.set_pio_mode = opti621_set_pio_mode,
};
static const struct ide_port_info opti621_chipset __devinitdata = {
.name = DRV_NAME,
.enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
.port_ops = &opti621_port_ops,
.host_flags = IDE_HFLAG_NO_DMA,
.pio_mask = ATA_PIO4,
};
static int __devinit opti621_init_one(struct pci_dev *dev, const struct pci_device_id *id)
{
return ide_pci_init_one(dev, &opti621_chipset, NULL);
}
static const struct pci_device_id opti621_pci_tbl[] = {
{ PCI_VDEVICE(OPTI, PCI_DEVICE_ID_OPTI_82C621), 0 },
{ PCI_VDEVICE(OPTI, PCI_DEVICE_ID_OPTI_82C825), 0 },
{ 0, },
};
MODULE_DEVICE_TABLE(pci, opti621_pci_tbl);
static struct pci_driver opti621_pci_driver = {
.name = "Opti621_IDE",
.id_table = opti621_pci_tbl,
.probe = opti621_init_one,
.remove = ide_pci_remove,
.suspend = ide_pci_suspend,
.resume = ide_pci_resume,
};
static int __init opti621_ide_init(void)
{
return ide_pci_register_driver(&opti621_pci_driver);
}
static void __exit opti621_ide_exit(void)
{
pci_unregister_driver(&opti621_pci_driver);
}
module_init(opti621_ide_init);
module_exit(opti621_ide_exit);
MODULE_AUTHOR("Jaromir Koutek, Jan Harkes, Mark Lord");
MODULE_DESCRIPTION("PCI driver module for Opti621 IDE");
MODULE_LICENSE("GPL");
| gpl-2.0 |
ssloy/trik-linux | arch/m68k/mm/hwtest.c | 10754 | 2506 | /* Tests for presence or absence of hardware registers.
* This code was originally in atari/config.c, but I noticed
* that it was also in drivers/nubus/nubus.c and I wanted to
* use it in hp300/config.c, so it seemed sensible to pull it
* out into its own file.
*
* The test is for use when trying to read a hardware register
* that isn't present would cause a bus error. We set up a
* temporary handler so that this doesn't kill the kernel.
*
* There is a test-by-reading and a test-by-writing; I present
* them here complete with the comments from the original atari
* config.c...
* -- PMM <pmaydell@chiark.greenend.org.uk>, 05/1998
*/
/* This function tests for the presence of an address, specially a
* hardware register address. It is called very early in the kernel
* initialization process, when the VBR register isn't set up yet. On
* an Atari, it still points to address 0, which is unmapped. So a bus
* error would cause another bus error while fetching the exception
* vector, and the CPU would do nothing at all. So we needed to set up
* a temporary VBR and a vector table for the duration of the test.
*/
#include <linux/module.h>
int hwreg_present( volatile void *regp )
{
int ret = 0;
long save_sp, save_vbr;
long tmp_vectors[3];
__asm__ __volatile__
( "movec %/vbr,%2\n\t"
"movel #Lberr1,%4@(8)\n\t"
"movec %4,%/vbr\n\t"
"movel %/sp,%1\n\t"
"moveq #0,%0\n\t"
"tstb %3@\n\t"
"nop\n\t"
"moveq #1,%0\n"
"Lberr1:\n\t"
"movel %1,%/sp\n\t"
"movec %2,%/vbr"
: "=&d" (ret), "=&r" (save_sp), "=&r" (save_vbr)
: "a" (regp), "a" (tmp_vectors)
);
return( ret );
}
EXPORT_SYMBOL(hwreg_present);
/* Basically the same, but writes a value into a word register, protected
* by a bus error handler. Returns 1 if successful, 0 otherwise.
*/
int hwreg_write( volatile void *regp, unsigned short val )
{
int ret;
long save_sp, save_vbr;
long tmp_vectors[3];
__asm__ __volatile__
( "movec %/vbr,%2\n\t"
"movel #Lberr2,%4@(8)\n\t"
"movec %4,%/vbr\n\t"
"movel %/sp,%1\n\t"
"moveq #0,%0\n\t"
"movew %5,%3@\n\t"
"nop \n\t" /* If this nop isn't present, 'ret' may already be
* loaded with 1 at the time the bus error
* happens! */
"moveq #1,%0\n"
"Lberr2:\n\t"
"movel %1,%/sp\n\t"
"movec %2,%/vbr"
: "=&d" (ret), "=&r" (save_sp), "=&r" (save_vbr)
: "a" (regp), "a" (tmp_vectors), "g" (val)
);
return( ret );
}
EXPORT_SYMBOL(hwreg_write);
| gpl-2.0 |
evaautomation/linux | drivers/acpi/reboot.c | 12802 | 1376 |
#include <linux/pci.h>
#include <linux/acpi.h>
#include <acpi/reboot.h>
void acpi_reboot(void)
{
struct acpi_generic_address *rr;
struct pci_bus *bus0;
u8 reset_value;
unsigned int devfn;
if (acpi_disabled)
return;
rr = &acpi_gbl_FADT.reset_register;
/* ACPI reset register was only introduced with v2 of the FADT */
if (acpi_gbl_FADT.header.revision < 2)
return;
/* Is the reset register supported? The spec says we should be
* checking the bit width and bit offset, but Windows ignores
* these fields */
if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER))
return;
reset_value = acpi_gbl_FADT.reset_value;
/* The reset register can only exist in I/O, Memory or PCI config space
* on a device on bus 0. */
switch (rr->space_id) {
case ACPI_ADR_SPACE_PCI_CONFIG:
/* The reset register can only live on bus 0. */
bus0 = pci_find_bus(0, 0);
if (!bus0)
return;
/* Form PCI device/function pair. */
devfn = PCI_DEVFN((rr->address >> 32) & 0xffff,
(rr->address >> 16) & 0xffff);
printk(KERN_DEBUG "Resetting with ACPI PCI RESET_REG.");
/* Write the value that resets us. */
pci_bus_write_config_byte(bus0, devfn,
(rr->address & 0xffff), reset_value);
break;
case ACPI_ADR_SPACE_SYSTEM_MEMORY:
case ACPI_ADR_SPACE_SYSTEM_IO:
printk(KERN_DEBUG "ACPI MEMORY or I/O RESET_REG.\n");
acpi_reset();
break;
}
}
| gpl-2.0 |
Jetson-TX1-AndroidTV/android_kernel_shield_tv_video4linux | drivers/iio/imu/inv_mpu/inv530/inv_mpu_misc.c | 3 | 17489 | /*
* Copyright (C) 2012 Invensense, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#define pr_fmt(fmt) "inv_mpu: " fmt
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/delay.h>
#include <linux/sysfs.h>
#include <linux/jiffies.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/kfifo.h>
#include <linux/poll.h>
#include <linux/miscdevice.h>
#include <linux/crc32.h>
#include "inv_mpu_iio.h"
#include "inv_test/inv_counters.h"
/* DMP defines */
#define FIRMWARE_CRC 0xda126847
#define FIRMWARE_CRC_1 0x24e5ed7e
int inv_get_pedometer_steps(struct inv_mpu_state *st, int *ped)
{
int r;
r = read_be32_from_mem(st, ped, PEDSTD_STEPCTR);
return r;
}
int inv_get_pedometer_time(struct inv_mpu_state *st, int *ped)
{
int r;
r = read_be32_from_mem(st, ped, PEDSTD_TIMECTR);
return r;
}
int inv_read_pedometer_counter(struct inv_mpu_state *st)
{
int result;
u32 last_step_counter, curr_counter;
u64 counter;
result = read_be32_from_mem(st, &last_step_counter, STPDET_TIMESTAMP);
if (result)
return result;
if (0 != last_step_counter) {
result = read_be32_from_mem(st, &curr_counter, DMPRATE_CNTR);
if (result)
return result;
counter = inv_get_cntr_diff(curr_counter, last_step_counter);
st->ped.last_step_time = get_time_ns() - counter *
st->eng_info[ENGINE_ACCEL].dur;
}
return 0;
}
/*
input param: fsr for accel parts
1: 1g. 2: 2g. 4: 4g. 8: 8g. 16: 16g. 32: 32g.
The goal is to set 1g data to 2^25, 2g data to 2^26, etc.
For 2g parts, raw accel data is 1g = 2^14, 2g = 2^15.
DMP takes raw accel data and shifts by 16 bits, so this scale means to shift by -5 bits.
In Q-30 math, >> 5 equals multiply by 2^25 = 33554432.
For 8g parts, raw accel data is 4g = 2^14, 8g = 2^15.
DMP takes raw accel data and shifts by 16 bits, so this scale means to shift by -3 bits.
In Q-30 math, >> 3 equals multiply by 2^27 = 134217728.
*/
int inv_set_accel_fsr_V3(struct inv_mpu_state *st)
{
u32 scale;
switch (st->chip_config.accel_fs) {
case 0: //2g
scale = 33554432; // 2^25
break;
case 1: //4g
scale = 67108864; // 2^26
break;
case 2: //8g
scale = 134217728; // 2^27
break;
case 3: //16g
scale = 268435456; // 2^28
break;
default:
return -EINVAL;
}
return write_be32_to_mem(st, scale, ACC_SCALE);
}
int inv_set_accel_scale2_V3(struct inv_mpu_state *st)
{
u32 scale;
switch (st->chip_config.accel_fs) {
case 0: //2g
scale = 524288; // 2^19
break;
case 1: //4g
scale = 262144; // 2^18
break;
case 2: //8g
scale = 131072; // 2^17
break;
case 3: //16g
scale = 65536; // 2^16
break;
default:
return -EINVAL;
}
return write_be32_to_mem(st, scale, ACC_SCALE2);
}
static int inv_load_firmware(struct inv_mpu_state *st)
{
int bank, write_size;
int result, size;
u16 memaddr;
u8 *data;
data = st->firmware;
size = DMP_IMAGE_SIZE - DMP_OFFSET;
for (bank = 0; size > 0; bank++, size -= write_size) {
if (size > MPU_MEM_BANK_SIZE)
write_size = MPU_MEM_BANK_SIZE;
else
write_size = size;
memaddr = (bank << 8);
if (!bank) {
memaddr = DMP_OFFSET;
write_size = MPU_MEM_BANK_SIZE - DMP_OFFSET;
data += DMP_OFFSET;
}
result = mem_w(memaddr, write_size, data);
if (result) {
pr_err("error writing firmware:%d\n", bank);
return result;
}
data += write_size;
}
return 0;
}
static int inv_verify_firmware(struct inv_mpu_state *st)
{
int bank, write_size, size;
int result;
u16 memaddr;
u8 firmware[MPU_MEM_BANK_SIZE];
u8 *data;
data = st->firmware;
size = DMP_IMAGE_SIZE - DMP_OFFSET;
for (bank = 0; size > 0; bank++, size -= write_size) {
if (size > MPU_MEM_BANK_SIZE)
write_size = MPU_MEM_BANK_SIZE;
else
write_size = size;
memaddr = (bank << 8);
if (!bank) {
memaddr = DMP_OFFSET;
write_size = MPU_MEM_BANK_SIZE - DMP_OFFSET;
data += DMP_OFFSET;
}
result = mem_r(memaddr, write_size, firmware);
if (result)
return result;
if (0 != memcmp(firmware, data, write_size)) {
pr_err("load data error, bank=%d\n", bank);
return -EINVAL;
}
data += write_size;
}
return 0;
}
static int inv_write_compass_matrix(struct inv_mpu_state *st, int *adj)
{
int addr[] = {CPASS_MTX_00, CPASS_MTX_01, CPASS_MTX_02,
CPASS_MTX_10, CPASS_MTX_11, CPASS_MTX_12,
CPASS_MTX_20, CPASS_MTX_21, CPASS_MTX_22};
int r, i;
for (i = 0; i < 9; i++) {
r = write_be32_to_mem(st, adj[i], addr[i]);
if (r)
return r;
}
return 0;
}
static int inv_compass_dmp_cal(struct inv_mpu_state *st)
{
s8 *compass_m, *m;
s8 trans[NINE_ELEM];
s32 tmp_m[NINE_ELEM];
int i, j, k, r;
int sens[THREE_AXES];
int *adj;
int scale;
int shift;
compass_m = st->plat_data.secondary_orientation;
m = st->plat_data.orientation;
for (i = 0; i < THREE_AXES; i++)
for (j = 0; j < THREE_AXES; j++)
trans[THREE_AXES * j + i] = m[THREE_AXES * i + j];
adj = st->current_compass_matrix;
st->slave_compass->get_scale(st, &scale);
if ((COMPASS_ID_AK8975 == st->plat_data.sec_slave_id) ||
(COMPASS_ID_AK8972 == st->plat_data.sec_slave_id) ||
(COMPASS_ID_AK8963 == st->plat_data.sec_slave_id))
shift = AK89XX_SHIFT;
else
shift = AK99XX_SHIFT;
for (i = 0; i < THREE_AXES; i++) {
sens[i] = st->chip_info.compass_sens[i] + 128;
sens[i] = inv_q30_mult(sens[i] << shift, scale);
}
for (i = 0; i < NINE_ELEM; i++) {
adj[i] = compass_m[i] * sens[i % THREE_AXES];
tmp_m[i] = 0;
}
for (i = 0; i < THREE_AXES; i++)
for (j = 0; j < THREE_AXES; j++)
for (k = 0; k < THREE_AXES; k++)
tmp_m[THREE_AXES * i + j] +=
trans[THREE_AXES * i + k] *
adj[THREE_AXES * k + j];
for (i = 0; i < NINE_ELEM; i++)
st->final_compass_matrix[i] = adj[i];
r = inv_write_compass_matrix(st, tmp_m);
return r;
}
static int inv_write_gyro_sf(struct inv_mpu_state *st)
{
int result;
result = write_be32_to_mem(st, st->gyro_sf, GYRO_SF);
return result;
}
static int inv_setup_dmp_firmware(struct inv_mpu_state *st)
{
int result;
u8 v[4] = {0, 0};
result = mem_w(DATA_OUT_CTL1, 2, v);
if (result)
return result;
result = mem_w(DATA_OUT_CTL2, 2, v);
if (result)
return result;
result = mem_w(DATA_INTR_CTL, 2, v);
if (result)
return result;
result = mem_w(MOTION_EVENT_CTL, 2, v);
if (result)
return result;
result = inv_write_gyro_sf(st);
if (result) {
pr_err("dmp loading eror:inv_write_gyro_sf\n");
return result;
}
result = inv_set_accel_fsr_V3(st);
if (result)
return result;
result = inv_set_accel_scale2_V3(st);
if (result)
return result;
if (st->chip_config.has_compass) {
result = inv_compass_dmp_cal(st);
if (result)
return result;
}
return result;
}
/*
* inv_firmware_load() - calling this function will load the firmware.
*/
static int inv_firmware_load(struct inv_mpu_state *st)
{
int result;
result = inv_switch_power_in_lp(st, true);
if (result) {
pr_err("load firmware set power error\n");
goto firmware_write_fail;
}
result = inv_plat_single_write(st, REG_USER_CTRL, st->i2c_dis);
if (result) {
pr_err("load firmware:stop dmp error\n");
goto firmware_write_fail;
}
result = inv_load_firmware(st);
if (result) {
pr_err("load firmware:load firmware eror\n");
goto firmware_write_fail;
}
result = inv_verify_firmware(st);
if (result) {
pr_err("load firmware:verify firmware error\n");
goto firmware_write_fail;
}
result = inv_setup_dmp_firmware(st);
if (result)
pr_err("load firmware:setup dmp error\n");
firmware_write_fail:
result |= inv_set_power(st, false);
if (result) {
pr_err("load firmware:shuting down power error\n");
return result;
}
st->chip_config.firmware_loaded = 1;
return 0;
}
/*
* inv_dmp_firmware_write() - calling this function will load the firmware.
*/
ssize_t inv_dmp_firmware_write(struct file *fp, struct kobject *kobj,
struct bin_attribute *attr, char *buf, loff_t pos, size_t size)
{
int result, offset;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
u32 crc;
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
if (!st->firmware) {
st->firmware = kmalloc(DMP_IMAGE_SIZE, GFP_KERNEL);
if (!st->firmware) {
pr_err("no memory while loading firmware\n");
return -ENOMEM;
}
}
offset = pos;
memcpy(st->firmware + pos, buf, size);
if ((!size) && (DMP_IMAGE_SIZE != pos)) {
pr_err("wrong size for DMP firmware 0x%08x vs 0x%08x\n",
offset, DMP_IMAGE_SIZE);
kfree(st->firmware);
st->firmware = 0;
return -EINVAL;
}
if (!strcmp(indio_dev->name, "icm20645"))
crc = FIRMWARE_CRC_1;
else
crc = FIRMWARE_CRC;
if (DMP_IMAGE_SIZE == (pos + size)) {
result = crc32(0, st->firmware, DMP_IMAGE_SIZE);
if (crc != result) {
pr_err("firmware CRC error - 0x%08x vs 0x%08x\n",
result, crc);
return -EINVAL;
}
mutex_lock(&indio_dev->mlock);
result = inv_firmware_load(st);
kfree(st->firmware);
st->firmware = 0;
mutex_unlock(&indio_dev->mlock);
if (result) {
pr_err("firmware load failed\n");
return result;
}
}
return size;
}
static int inv_dmp_read(struct inv_mpu_state *st, int off, int size, u8 *buf)
{
int bank, write_size, data, result;
u16 memaddr;
data = 0;
result = inv_switch_power_in_lp(st, true);
if (result)
return result;
inv_stop_dmp(st);
for (bank = (off >> 8); size > 0; bank++, size -= write_size,
data += write_size) {
if (size > MPU_MEM_BANK_SIZE)
write_size = MPU_MEM_BANK_SIZE;
else
write_size = size;
memaddr = (bank << 8);
result = mem_r(memaddr, write_size, &buf[data]);
if (result)
return result;
}
return 0;
}
ssize_t inv_dmp_firmware_read(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
int result, offset;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
if (!st->chip_config.firmware_loaded)
return -EINVAL;
mutex_lock(&indio_dev->mlock);
offset = off;
result = inv_dmp_read(st, offset, count, buf);
set_inv_enable(indio_dev);
mutex_unlock(&indio_dev->mlock);
if (result)
return result;
return count;
}
ssize_t inv_soft_iron_matrix_write(struct file *fp, struct kobject *kobj,
struct bin_attribute *attr, char *buf, loff_t pos, size_t size)
{
int result;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
int m[NINE_ELEM], *n, *r;
int i, j, k;
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
if (!st->chip_config.firmware_loaded)
return -EINVAL;
if (size != SOFT_IRON_MATRIX_SIZE) {
pr_err("wrong size for soft iron matrix 0x%08x vs 0x%08x\n",
(int)size, SOFT_IRON_MATRIX_SIZE);
return -EINVAL;
}
n = st->current_compass_matrix;
r = st->final_compass_matrix;
for (i = 0; i < NINE_ELEM; i++)
memcpy((u8 *)&m[i], &buf[i * sizeof(int)], sizeof(int));
for (i = 0; i < THREE_AXES; i++) {
for (j = 0; j < THREE_AXES; j++) {
r[i * THREE_AXES + j] = 0;
for (k = 0; k < THREE_AXES; k++)
r[i * THREE_AXES + j] +=
inv_q30_mult(m[i * THREE_AXES + k],
n[j + k * THREE_AXES]);
}
}
mutex_lock(&indio_dev->mlock);
result = inv_switch_power_in_lp(st, true);
if (result) {
mutex_unlock(&indio_dev->mlock);
return result;
}
result = inv_write_compass_matrix(st, r);
if (result) {
mutex_unlock(&indio_dev->mlock);
return result;
}
mutex_unlock(&indio_dev->mlock);
return size;
}
ssize_t inv_accel_covariance_write(struct file *fp, struct kobject *kobj,
struct bin_attribute *attr, char *buf, loff_t pos, size_t size)
{
int i;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
if (size != ACCEL_COVARIANCE_SIZE)
return -EINVAL;
for (i = 0; i < COVARIANCE_SIZE; i++)
memcpy((u8 *)&st->accel_covariance[i],
&buf[i * sizeof(int)], sizeof(int));
return size;
}
ssize_t inv_compass_covariance_write(struct file *fp, struct kobject *kobj,
struct bin_attribute *attr, char *buf, loff_t pos, size_t size)
{
int i;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
if (size != COMPASS_COVARIANCE_SIZE)
return -EINVAL;
for (i = 0; i < COVARIANCE_SIZE; i++)
memcpy((u8 *)&st->compass_covariance[i],
&buf[i * sizeof(int)], sizeof(int));
return size;
}
ssize_t inv_compass_covariance_cur_write(struct file *fp, struct kobject *kobj,
struct bin_attribute *attr, char *buf, loff_t pos, size_t size)
{
int i;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
if (size != COMPASS_COVARIANCE_SIZE)
return -EINVAL;
for (i = 0; i < COVARIANCE_SIZE; i++)
memcpy((u8 *)&st->curr_compass_covariance[i],
&buf[i * sizeof(int)], sizeof(int));
return size;
}
static int inv_dmp_covar_read(struct inv_mpu_state *st,
int off, int size, u8 *buf)
{
int data, result, i;
result = inv_switch_power_in_lp(st, true);
if (result)
return result;
inv_stop_dmp(st);
for (i = 0; i < COVARIANCE_SIZE * sizeof(int); i += sizeof(int)) {
result = read_be32_from_mem(st, (u32 *)&data, off + i);
if (result)
return result;
memcpy(buf + i, (u8 *)&data, sizeof(int));
}
return 0;
}
ssize_t inv_compass_covariance_cur_read(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
int result;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
if (!st->chip_config.firmware_loaded)
return -EINVAL;
mutex_lock(&indio_dev->mlock);
result = inv_dmp_covar_read(st, CPASS_COVARIANCE_CUR, count, buf);
set_inv_enable(indio_dev);
mutex_unlock(&indio_dev->mlock);
if (result)
return result;
return count;
}
ssize_t inv_compass_covariance_read(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
int result;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
if (!st->chip_config.firmware_loaded)
return -EINVAL;
mutex_lock(&indio_dev->mlock);
result = inv_dmp_covar_read(st, CPASS_COVARIANCE, count, buf);
set_inv_enable(indio_dev);
mutex_unlock(&indio_dev->mlock);
if (result)
return result;
return count;
}
ssize_t inv_accel_covariance_read(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
int result;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
if (!st->chip_config.firmware_loaded)
return -EINVAL;
mutex_lock(&indio_dev->mlock);
result = inv_dmp_covar_read(st, ACCEL_COVARIANCE, count, buf);
set_inv_enable(indio_dev);
mutex_unlock(&indio_dev->mlock);
if (result)
return result;
return count;
}
ssize_t inv_activity_read(struct file *filp,
struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t off, size_t count)
{
int copied;
struct iio_dev *indio_dev;
struct inv_mpu_state *st;
u8 ddd[128];
indio_dev = dev_get_drvdata(container_of(kobj, struct device, kobj));
st = iio_priv(indio_dev);
mutex_lock(&indio_dev->mlock);
copied = kfifo_out(&st->kf, ddd, count);
memcpy(buf, ddd, copied);
mutex_unlock(&indio_dev->mlock);
return copied;
}
ssize_t inv_load_dmp_bias(struct inv_mpu_state *st, int *out)
{
inv_switch_power_in_lp(st, true);
read_be32_from_mem(st, &out[0], ACCEL_BIAS_X);
read_be32_from_mem(st, &out[1], ACCEL_BIAS_Y);
read_be32_from_mem(st, &out[2], ACCEL_BIAS_Z);
read_be32_from_mem(st, &out[3], GYRO_BIAS_X);
read_be32_from_mem(st, &out[4], GYRO_BIAS_Y);
read_be32_from_mem(st, &out[5], GYRO_BIAS_Z);
read_be32_from_mem(st, &out[6], CPASS_BIAS_X);
read_be32_from_mem(st, &out[7], CPASS_BIAS_Y);
read_be32_from_mem(st, &out[8], CPASS_BIAS_Z);
inv_switch_power_in_lp(st, false);
return 0;
}
ssize_t inv_set_dmp_bias(struct inv_mpu_state *st, int *data)
{
int result;
inv_switch_power_in_lp(st, true);
result = write_be32_to_mem(st, data[0], ACCEL_BIAS_X);
result += write_be32_to_mem(st, data[1], ACCEL_BIAS_Y);
result += write_be32_to_mem(st, data[2], ACCEL_BIAS_Z);
if (result)
return result;
result = write_be32_to_mem(st, data[3], GYRO_BIAS_X);
result += write_be32_to_mem(st, data[4], GYRO_BIAS_Y);
result += write_be32_to_mem(st, data[5], GYRO_BIAS_Z);
if (result)
return result;
result = write_be32_to_mem(st, data[6], CPASS_BIAS_X);
result += write_be32_to_mem(st, data[7], CPASS_BIAS_Y);
result += write_be32_to_mem(st, data[8], CPASS_BIAS_Z);
if (result)
return result;
inv_switch_power_in_lp(st, false);
return 0;
}
| gpl-2.0 |
dorimanx/android-busybox-ndk | procps/nmeter.c | 3 | 21293 | /*
* Licensed under GPLv2, see file LICENSE in this source tree.
*
* Based on nanotop.c from floppyfw project
*
* Contact me: vda.linux@googlemail.com
*/
//config:config NMETER
//config: bool "nmeter (10 kb)"
//config: default y
//config: help
//config: Prints selected system stats continuously, one line per update.
//applet:IF_NMETER(APPLET(nmeter, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_NMETER) += nmeter.o
//usage:#define nmeter_trivial_usage
//usage: "[-d MSEC] FORMAT_STRING"
//usage:#define nmeter_full_usage "\n\n"
//usage: "Monitor system in real time"
//usage: "\n"
//usage: "\n -d MSEC Milliseconds between updates, default:1000, none:-1"
//usage: "\n"
//usage: "\nFormat specifiers:"
//usage: "\n %Nc or %[cN] CPU. N - bar size (default 10)"
//usage: "\n (displays: S:system U:user N:niced D:iowait I:irq i:softirq)"
//usage: "\n %[nINTERFACE] Network INTERFACE"
//usage: "\n %m Allocated memory"
//usage: "\n %[mf] Free memory"
//usage: "\n %[mt] Total memory"
//usage: "\n %s Allocated swap"
//usage: "\n %f Number of used file descriptors"
//usage: "\n %Ni Total/specific IRQ rate"
//usage: "\n %x Context switch rate"
//usage: "\n %p Forks"
//usage: "\n %[pn] # of processes"
//usage: "\n %b Block io"
//usage: "\n %Nt Time (with N decimal points)"
//usage: "\n %r Print <cr> instead of <lf> at EOL"
//TODO:
// simplify code
// /proc/locks
// /proc/stat:
// disk_io: (3,0):(22272,17897,410702,4375,54750)
// btime 1059401962
//TODO: use sysinfo libc call/syscall, if appropriate
// (faster than open/read/close):
// sysinfo({uptime=15017, loads=[5728, 15040, 16480]
// totalram=2107416576, freeram=211525632, sharedram=0, bufferram=157204480}
// totalswap=134209536, freeswap=134209536, procs=157})
#include "libbb.h"
#include "common_bufsiz.h"
typedef unsigned long long ullong;
enum { /* Preferably use powers of 2 */
PROC_MIN_FILE_SIZE = 256,
PROC_MAX_FILE_SIZE = 16 * 1024,
};
typedef struct proc_file {
char *file;
int file_sz;
smallint last_gen;
} proc_file;
static const char *const proc_name[] = {
"stat", // Must match the order of proc_file's!
"loadavg",
"net/dev",
"meminfo",
"diskstats",
"sys/fs/file-nr"
};
struct globals {
// Sample generation flip-flop
smallint gen;
// Linux 2.6? (otherwise assumes 2.4)
smallint is26;
// 1 if sample delay is not an integer fraction of a second
smallint need_seconds;
char final_char;
char *cur_outbuf;
int delta;
unsigned deltanz;
struct timeval tv;
#define first_proc_file proc_stat
proc_file proc_stat; // Must match the order of proc_name's!
proc_file proc_loadavg;
proc_file proc_net_dev;
proc_file proc_meminfo;
proc_file proc_diskstats;
proc_file proc_sys_fs_filenr;
};
#define G (*ptr_to_globals)
#define gen (G.gen )
#define is26 (G.is26 )
#define need_seconds (G.need_seconds )
#define cur_outbuf (G.cur_outbuf )
#define tv (G.tv )
#define proc_stat (G.proc_stat )
#define proc_loadavg (G.proc_loadavg )
#define proc_net_dev (G.proc_net_dev )
#define proc_meminfo (G.proc_meminfo )
#define proc_diskstats (G.proc_diskstats )
#define proc_sys_fs_filenr (G.proc_sys_fs_filenr)
#define outbuf bb_common_bufsiz1
#define INIT_G() do { \
setup_common_bufsiz(); \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
cur_outbuf = outbuf; \
G.final_char = '\n'; \
G.deltanz = G.delta = 1000000; \
} while (0)
static inline void reset_outbuf(void)
{
cur_outbuf = outbuf;
}
static inline int outbuf_count(void)
{
return cur_outbuf - outbuf;
}
static void print_outbuf(void)
{
int sz = cur_outbuf - outbuf;
if (sz > 0) {
xwrite(STDOUT_FILENO, outbuf, sz);
cur_outbuf = outbuf;
}
}
static void put(const char *s)
{
char *p = cur_outbuf;
int sz = outbuf + COMMON_BUFSIZE - p;
while (*s && --sz >= 0)
*p++ = *s++;
cur_outbuf = p;
}
static void put_c(char c)
{
if (cur_outbuf < outbuf + COMMON_BUFSIZE)
*cur_outbuf++ = c;
}
static void put_question_marks(int count)
{
while (count--)
put_c('?');
}
static void readfile_z(proc_file *pf, const char* fname)
{
// open_read_close() will do two reads in order to be sure we are at EOF,
// and we don't need/want that.
int fd;
int sz, rdsz;
char *buf;
sz = pf->file_sz;
buf = pf->file;
if (!buf) {
buf = xmalloc(PROC_MIN_FILE_SIZE);
sz = PROC_MIN_FILE_SIZE;
}
again:
fd = xopen(fname, O_RDONLY);
buf[0] = '\0';
rdsz = read(fd, buf, sz-1);
close(fd);
if (rdsz > 0) {
if (rdsz == sz-1 && sz < PROC_MAX_FILE_SIZE) {
sz *= 2;
buf = xrealloc(buf, sz);
goto again;
}
buf[rdsz] = '\0';
}
pf->file_sz = sz;
pf->file = buf;
}
static const char* get_file(proc_file *pf)
{
if (pf->last_gen != gen) {
pf->last_gen = gen;
readfile_z(pf, proc_name[pf - &first_proc_file]);
}
return pf->file;
}
static ullong read_after_slash(const char *p)
{
p = strchr(p, '/');
if (!p) return 0;
return strtoull(p+1, NULL, 10);
}
enum conv_type {
conv_decimal = 0,
conv_slash = 1
};
// Reads decimal values from line. Values start after key, for example:
// "cpu 649369 0 341297 4336769..." - key is "cpu" here.
// Values are stored in vec[].
// posbits is a bit lit of positions we are interested in.
// for example: 00100110 - we want 1st, 2nd and 5th value.
// posbits.bit0 encodes conversion type.
static int rdval(const char* p, const char* key, ullong *vec, long posbits)
{
unsigned curpos;
p = strstr(p, key);
if (!p) return 1;
p += strlen(key);
curpos = 1 << 1;
while (1) {
while (*p == ' ' || *p == '\t') p++;
if (*p == '\n' || *p == '\0') break;
if (curpos & posbits) { // read this value
*vec++ = (posbits & 1) == conv_decimal ?
strtoull(p, NULL, 10) :
read_after_slash(p);
posbits -= curpos;
if (posbits <= 1)
return 0;
}
while (*p > ' ') // skip over the value
p++;
curpos <<= 1;
}
return 0;
}
// Parses files with lines like "... ... ... 3/148 ...."
static int rdval_loadavg(const char* p, ullong *vec, long posbits)
{
int result;
result = rdval(p, "", vec, posbits | conv_slash);
return result;
}
// Parses /proc/diskstats
// 1 2 3 4 5 6(rd) 7 8 9 10(wr) 11 12 13 14
// 3 0 hda 51292 14441 841783 926052 25717 79650 843256 3029804 0 148459 3956933
// 3 1 hda1 0 0 0 0 <- ignore if only 4 fields
// Linux 3.0 (maybe earlier) started printing full stats for hda1 too.
// Had to add code which skips such devices.
static int rdval_diskstats(const char* p, ullong *vec)
{
char devname[32];
unsigned devname_len = 0;
int value_idx = 0;
vec[0] = 0;
vec[1] = 0;
while (1) {
value_idx++;
while (*p == ' ' || *p == '\t')
p++;
if (*p == '\0')
break;
if (*p == '\n') {
value_idx = 0;
p++;
continue;
}
if (value_idx == 3) {
char *end = strchrnul(p, ' ');
/* If this a hda1-like device (same prefix as last one + digit)? */
if (devname_len && strncmp(devname, p, devname_len) == 0 && isdigit(p[devname_len])) {
p = end;
goto skip_line; /* skip entire line */
}
/* It is not. Remember the name for future checks */
devname_len = end - p;
if (devname_len > sizeof(devname)-1)
devname_len = sizeof(devname)-1;
strncpy(devname, p, devname_len);
/* devname[devname_len] = '\0'; - not really needed */
p = end;
} else
if (value_idx == 6) {
// TODO: *sectorsize (don't know how to find out sectorsize)
vec[0] += strtoull(p, NULL, 10);
} else
if (value_idx == 10) {
// TODO: *sectorsize (don't know how to find out sectorsize)
vec[1] += strtoull(p, NULL, 10);
skip_line:
while (*p != '\n' && *p != '\0')
p++;
continue;
}
while ((unsigned char)(*p) > ' ') // skip over value
p++;
}
return 0;
}
static void scale(ullong ul)
{
char buf[5];
/* see http://en.wikipedia.org/wiki/Tera */
smart_ulltoa4(ul, buf, " kmgtpezy")[0] = '\0';
put(buf);
}
#define S_STAT(a) \
typedef struct a { \
struct s_stat *next; \
void (*collect)(struct a *s) FAST_FUNC; \
const char *label;
#define S_STAT_END(a) } a;
S_STAT(s_stat)
S_STAT_END(s_stat)
static void FAST_FUNC collect_literal(s_stat *s UNUSED_PARAM)
{
}
static s_stat* init_literal(void)
{
s_stat *s = xzalloc(sizeof(*s));
s->collect = collect_literal;
return (s_stat*)s;
}
static s_stat* init_cr(const char *param UNUSED_PARAM)
{
G.final_char = '\r';
return NULL;
}
// user nice system idle iowait irq softirq (last 3 only in 2.6)
//cpu 649369 0 341297 4336769 11640 7122 1183
//cpuN 649369 0 341297 4336769 11640 7122 1183
enum { CPU_FIELDCNT = 7 };
S_STAT(cpu_stat)
ullong old[CPU_FIELDCNT];
int bar_sz;
char bar[1];
S_STAT_END(cpu_stat)
static void FAST_FUNC collect_cpu(cpu_stat *s)
{
ullong data[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 };
unsigned frac[CPU_FIELDCNT] = { 0, 0, 0, 0, 0, 0, 0 };
ullong all = 0;
int norm_all = 0;
int bar_sz = s->bar_sz;
char *bar = s->bar;
int i;
if (rdval(get_file(&proc_stat), "cpu ", data, 0
| (1 << 1)
| (1 << 2)
| (1 << 3)
| (1 << 4)
| (1 << 5)
| (1 << 6)
| (1 << 7))
) {
put_question_marks(bar_sz);
return;
}
for (i = 0; i < CPU_FIELDCNT; i++) {
ullong old = s->old[i];
if (data[i] < old) old = data[i]; //sanitize
s->old[i] = data[i];
all += (data[i] -= old);
}
if (all) {
for (i = 0; i < CPU_FIELDCNT; i++) {
ullong t = bar_sz * data[i];
norm_all += data[i] = t / all;
frac[i] = t % all;
}
while (norm_all < bar_sz) {
unsigned max = frac[0];
int pos = 0;
for (i = 1; i < CPU_FIELDCNT; i++) {
if (frac[i] > max) max = frac[i], pos = i;
}
frac[pos] = 0; //avoid bumping up same value twice
data[pos]++;
norm_all++;
}
memset(bar, '.', bar_sz);
memset(bar, 'S', data[2]); bar += data[2]; //sys
memset(bar, 'U', data[0]); bar += data[0]; //usr
memset(bar, 'N', data[1]); bar += data[1]; //nice
memset(bar, 'D', data[4]); bar += data[4]; //iowait
memset(bar, 'I', data[5]); bar += data[5]; //irq
memset(bar, 'i', data[6]); bar += data[6]; //softirq
} else {
memset(bar, '?', bar_sz);
}
put(s->bar);
}
static s_stat* init_cpu(const char *param)
{
int sz;
cpu_stat *s;
sz = strtoul(param, NULL, 0); /* param can be "" */
if (sz < 10) sz = 10;
if (sz > 1000) sz = 1000;
s = xzalloc(sizeof(*s) + sz);
/*s->bar[sz] = '\0'; - xzalloc did it */
s->bar_sz = sz;
s->collect = collect_cpu;
return (s_stat*)s;
}
S_STAT(int_stat)
ullong old;
int no;
S_STAT_END(int_stat)
static void FAST_FUNC collect_int(int_stat *s)
{
ullong data[1];
ullong old;
if (rdval(get_file(&proc_stat), "intr", data, 1 << s->no)) {
put_question_marks(4);
return;
}
old = s->old;
if (data[0] < old) old = data[0]; //sanitize
s->old = data[0];
scale(data[0] - old);
}
static s_stat* init_int(const char *param)
{
int_stat *s = xzalloc(sizeof(*s));
s->collect = collect_int;
if (param[0] == '\0') {
s->no = 1;
} else {
int n = xatoi_positive(param);
s->no = n + 2;
}
return (s_stat*)s;
}
S_STAT(ctx_stat)
ullong old;
S_STAT_END(ctx_stat)
static void FAST_FUNC collect_ctx(ctx_stat *s)
{
ullong data[1];
ullong old;
if (rdval(get_file(&proc_stat), "ctxt", data, 1 << 1)) {
put_question_marks(4);
return;
}
old = s->old;
if (data[0] < old) old = data[0]; //sanitize
s->old = data[0];
scale(data[0] - old);
}
static s_stat* init_ctx(const char *param UNUSED_PARAM)
{
ctx_stat *s = xzalloc(sizeof(*s));
s->collect = collect_ctx;
return (s_stat*)s;
}
S_STAT(blk_stat)
const char* lookfor;
ullong old[2];
S_STAT_END(blk_stat)
static void FAST_FUNC collect_blk(blk_stat *s)
{
ullong data[2];
int i;
if (is26) {
i = rdval_diskstats(get_file(&proc_diskstats), data);
} else {
i = rdval(get_file(&proc_stat), s->lookfor, data, 0
| (1 << 1)
| (1 << 2)
);
// Linux 2.4 reports bio in Kbytes, convert to sectors:
data[0] *= 2;
data[1] *= 2;
}
if (i) {
put_question_marks(9);
return;
}
for (i=0; i<2; i++) {
ullong old = s->old[i];
if (data[i] < old) old = data[i]; //sanitize
s->old[i] = data[i];
data[i] -= old;
}
scale(data[0]*512); // TODO: *sectorsize
put_c(' ');
scale(data[1]*512);
}
static s_stat* init_blk(const char *param UNUSED_PARAM)
{
blk_stat *s = xzalloc(sizeof(*s));
s->collect = collect_blk;
s->lookfor = "page";
return (s_stat*)s;
}
S_STAT(fork_stat)
ullong old;
S_STAT_END(fork_stat)
static void FAST_FUNC collect_thread_nr(fork_stat *s UNUSED_PARAM)
{
ullong data[1];
if (rdval_loadavg(get_file(&proc_loadavg), data, 1 << 4)) {
put_question_marks(4);
return;
}
scale(data[0]);
}
static void FAST_FUNC collect_fork(fork_stat *s)
{
ullong data[1];
ullong old;
if (rdval(get_file(&proc_stat), "processes", data, 1 << 1)) {
put_question_marks(4);
return;
}
old = s->old;
if (data[0] < old) old = data[0]; //sanitize
s->old = data[0];
scale(data[0] - old);
}
static s_stat* init_fork(const char *param)
{
fork_stat *s = xzalloc(sizeof(*s));
if (*param == 'n') {
s->collect = collect_thread_nr;
} else {
s->collect = collect_fork;
}
return (s_stat*)s;
}
S_STAT(if_stat)
ullong old[4];
const char *device;
char *device_colon;
S_STAT_END(if_stat)
static void FAST_FUNC collect_if(if_stat *s)
{
ullong data[4];
int i;
if (rdval(get_file(&proc_net_dev), s->device_colon, data, 0
| (1 << 1)
| (1 << 3)
| (1 << 9)
| (1 << 11))
) {
put_question_marks(10);
return;
}
for (i=0; i<4; i++) {
ullong old = s->old[i];
if (data[i] < old) old = data[i]; //sanitize
s->old[i] = data[i];
data[i] -= old;
}
put_c(data[1] ? '*' : ' ');
scale(data[0]);
put_c(data[3] ? '*' : ' ');
scale(data[2]);
}
static s_stat* init_if(const char *device)
{
if_stat *s = xzalloc(sizeof(*s));
if (!device || !device[0])
bb_show_usage();
s->collect = collect_if;
s->device = device;
s->device_colon = xasprintf("%s:", device);
return (s_stat*)s;
}
S_STAT(mem_stat)
char opt;
S_STAT_END(mem_stat)
// "Memory" value should not include any caches.
// IOW: neither "ls -laR /" nor heavy read/write activity
// should affect it. We'd like to also include any
// long-term allocated kernel-side mem, but it is hard
// to figure out. For now, bufs, cached & slab are
// counted as "free" memory
//2.6.16:
//MemTotal: 773280 kB
//MemFree: 25912 kB - genuinely free
//Buffers: 320672 kB - cache
//Cached: 146396 kB - cache
//SwapCached: 0 kB
//Active: 183064 kB
//Inactive: 356892 kB
//HighTotal: 0 kB
//HighFree: 0 kB
//LowTotal: 773280 kB
//LowFree: 25912 kB
//SwapTotal: 131064 kB
//SwapFree: 131064 kB
//Dirty: 48 kB
//Writeback: 0 kB
//Mapped: 96620 kB
//Slab: 200668 kB - takes 7 Mb on my box fresh after boot,
// but includes dentries and inodes
// (== can take arbitrary amount of mem)
//CommitLimit: 517704 kB
//Committed_AS: 236776 kB
//PageTables: 1248 kB
//VmallocTotal: 516052 kB
//VmallocUsed: 3852 kB
//VmallocChunk: 512096 kB
//HugePages_Total: 0
//HugePages_Free: 0
//Hugepagesize: 4096 kB
static void FAST_FUNC collect_mem(mem_stat *s)
{
ullong m_total = 0;
ullong m_free = 0;
ullong m_bufs = 0;
ullong m_cached = 0;
ullong m_slab = 0;
if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1 << 1)) {
put_question_marks(4);
return;
}
if (s->opt == 't') {
scale(m_total << 10);
return;
}
if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1 << 1)
|| rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1 << 1)
|| rdval(proc_meminfo.file, "Cached:", &m_cached, 1 << 1)
|| rdval(proc_meminfo.file, "Slab:", &m_slab , 1 << 1)
) {
put_question_marks(4);
return;
}
m_free += m_bufs + m_cached + m_slab;
switch (s->opt) {
case 'f':
scale(m_free << 10); break;
default:
scale((m_total - m_free) << 10); break;
}
}
static s_stat* init_mem(const char *param)
{
mem_stat *s = xzalloc(sizeof(*s));
s->collect = collect_mem;
s->opt = param[0];
return (s_stat*)s;
}
S_STAT(swp_stat)
S_STAT_END(swp_stat)
static void FAST_FUNC collect_swp(swp_stat *s UNUSED_PARAM)
{
ullong s_total[1];
ullong s_free[1];
if (rdval(get_file(&proc_meminfo), "SwapTotal:", s_total, 1 << 1)
|| rdval(proc_meminfo.file, "SwapFree:" , s_free, 1 << 1)
) {
put_question_marks(4);
return;
}
scale((s_total[0]-s_free[0]) << 10);
}
static s_stat* init_swp(const char *param UNUSED_PARAM)
{
swp_stat *s = xzalloc(sizeof(*s));
s->collect = collect_swp;
return (s_stat*)s;
}
S_STAT(fd_stat)
S_STAT_END(fd_stat)
static void FAST_FUNC collect_fd(fd_stat *s UNUSED_PARAM)
{
ullong data[2];
if (rdval(get_file(&proc_sys_fs_filenr), "", data, 0
| (1 << 1)
| (1 << 2))
) {
put_question_marks(4);
return;
}
scale(data[0] - data[1]);
}
static s_stat* init_fd(const char *param UNUSED_PARAM)
{
fd_stat *s = xzalloc(sizeof(*s));
s->collect = collect_fd;
return (s_stat*)s;
}
S_STAT(time_stat)
unsigned prec;
unsigned scale;
S_STAT_END(time_stat)
static void FAST_FUNC collect_time(time_stat *s)
{
char buf[sizeof("12:34:56.123456")];
struct tm* tm;
unsigned us = tv.tv_usec + s->scale/2;
time_t t = tv.tv_sec;
if (us >= 1000000) {
t++;
us -= 1000000;
}
tm = localtime(&t);
sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
if (s->prec)
sprintf(buf+8, ".%0*d", s->prec, us / s->scale);
put(buf);
}
static s_stat* init_time(const char *param)
{
int prec;
time_stat *s = xzalloc(sizeof(*s));
s->collect = collect_time;
prec = param[0] - '0';
if (prec < 0) prec = 0;
else if (prec > 6) prec = 6;
s->prec = prec;
s->scale = 1;
while (prec++ < 6)
s->scale *= 10;
return (s_stat*)s;
}
static void FAST_FUNC collect_info(s_stat *s)
{
gen ^= 1;
while (s) {
put(s->label);
s->collect(s);
s = s->next;
}
}
typedef s_stat* init_func(const char *param);
static const char options[] ALIGN1 = "ncmsfixptbr";
static init_func *const init_functions[] = {
init_if,
init_cpu,
init_mem,
init_swp,
init_fd,
init_int,
init_ctx,
init_fork,
init_time,
init_blk,
init_cr
};
int nmeter_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nmeter_main(int argc UNUSED_PARAM, char **argv)
{
char buf[32];
s_stat *first = NULL;
s_stat *last = NULL;
s_stat *s;
char *opt_d;
char *cur, *prev;
INIT_G();
xchdir("/proc");
if (open_read_close("version", buf, sizeof(buf)-1) > 0) {
buf[sizeof(buf)-1] = '\0';
is26 = (strstr(buf, " 2.4.") == NULL);
}
if (getopt32(argv, "d:", &opt_d)) {
G.delta = xatoi(opt_d) * 1000;
G.deltanz = G.delta > 0 ? G.delta : 1;
need_seconds = (1000000 % G.deltanz) != 0;
}
argv += optind;
if (!argv[0])
bb_show_usage();
// Can use argv[0] directly, but this will mess up
// parameters as seen by e.g. ps. Making a copy...
cur = xstrdup(argv[0]);
while (1) {
char *param, *p;
prev = cur;
again:
cur = strchr(cur, '%');
if (!cur)
break;
if (cur[1] == '%') { // %%
overlapping_strcpy(cur, cur + 1);
cur++;
goto again;
}
*cur++ = '\0'; // overwrite %
if (cur[0] == '[') {
// format: %[foptstring]
cur++;
p = strchr(options, cur[0]);
param = cur+1;
while (cur[0] != ']') {
if (!cur[0])
bb_show_usage();
cur++;
}
*cur++ = '\0'; // overwrite [
} else {
// format: %NNNNNNf
param = cur;
while (cur[0] >= '0' && cur[0] <= '9')
cur++;
if (!cur[0])
bb_show_usage();
p = strchr(options, cur[0]);
*cur++ = '\0'; // overwrite format char
}
if (!p)
bb_show_usage();
s = init_functions[p-options](param);
if (s) {
s->label = prev;
/*s->next = NULL; - all initXXX funcs use xzalloc */
if (!first)
first = s;
else
last->next = s;
last = s;
} else {
// %r option. remove it from string
overlapping_strcpy(prev + strlen(prev), cur);
cur = prev;
}
}
if (prev[0]) {
s = init_literal();
s->label = prev;
/*s->next = NULL; - all initXXX funcs use xzalloc */
if (!first)
first = s;
else
last->next = s;
last = s;
}
// Generate first samples but do not print them, they're bogus
collect_info(first);
reset_outbuf();
if (G.delta >= 0) {
gettimeofday(&tv, NULL);
usleep(G.delta > 1000000 ? 1000000 : G.delta - tv.tv_usec % G.deltanz);
}
while (1) {
gettimeofday(&tv, NULL);
collect_info(first);
put_c(G.final_char);
print_outbuf();
// Negative delta -> no usleep at all
// This will hog the CPU but you can have REALLY GOOD
// time resolution ;)
// TODO: detect and avoid useless updates
// (like: nothing happens except time)
if (G.delta >= 0) {
int rem;
// can be commented out, will sacrifice sleep time precision a bit
gettimeofday(&tv, NULL);
if (need_seconds)
rem = G.delta - ((ullong)tv.tv_sec*1000000 + tv.tv_usec) % G.deltanz;
else
rem = G.delta - (unsigned)tv.tv_usec % G.deltanz;
// Sometimes kernel wakes us up just a tiny bit earlier than asked
// Do not go to very short sleep in this case
if (rem < (unsigned)G.delta / 128) {
rem += G.delta;
}
usleep(rem);
}
}
/*return 0;*/
}
| gpl-2.0 |
Everf/muli | src/bindings/ScriptDev2/scripts/northrend/icecrown_citadel/icecrown_citadel/boss_deathbringer_saurfang.cpp | 3 | 9809 | /* Copyright (C) 2006 - 2011 ScriptDev2 <http://www.scriptdev2.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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* ScriptData
SDName: boss_deathbringer_saurfang
SD%Complete: 75%
SDComment: by /dev/rsa
SDCategory: Icecrown Citadel
EndScriptData */
#include "precompiled.h"
#include "icecrown_citadel.h"
enum
{
//common
SPELL_BERSERK = 47008,
//yells
//summons
NPC_BLOOD_BEASTS = 38508,
//Abilities
SPELL_BLOOD_LINK = 72178,
SPELL_BLOOD_POWER = 72371,
SPELL_MARK = 72293,
SPELL_MARK_SELF = 72256,
SPELL_FRENZY = 72737,
SPELL_BOILING_BLOOD = 72385,
SPELL_BLOOD_NOVA = 72380,
SPELL_RUNE_OF_BLOOD = 72408,
SPELL_CALL_BLOOD_BEAST_1 = 72172,
SPELL_CALL_BLOOD_BEAST_2 = 72173,
SPELL_CALL_BLOOD_BEAST_3 = 72356,
SPELL_CALL_BLOOD_BEAST_4 = 72357,
SPELL_CALL_BLOOD_BEAST_5 = 72358,
SPELL_SCENT_OF_BLOOD = 72769,
SPELL_RESISTANT_SKIN = 72723,
SPELL_BLOOD_LINK_BEAST = 72176,
SPELL_ZERO_REGEN = 72242,
SPELL_ACHIEVEMENT_DEATHBRINGER_SAURFANG = 72928,
};
enum Equipment
{
EQUIP_MAIN = 50798,
EQUIP_OFFHAND = 50798,
EQUIP_RANGED = EQUIP_NO_CHANGE,
EQUIP_DONE = EQUIP_NO_CHANGE,
};
struct MANGOS_DLL_DECL boss_deathbringer_saurfangAI : public BSWScriptedAI
{
boss_deathbringer_saurfangAI(Creature* pCreature) : BSWScriptedAI(pCreature)
{
pInstance = (ScriptedInstance*)pCreature->GetInstanceData();
Reset();
}
ScriptedInstance *pInstance;
uint8 beasts;
int32 oldPower;
void Reset()
{
if(!pInstance)
return;
m_creature->SetRespawnDelay(7*DAY);
if (m_creature->isAlive())
pInstance->SetData(TYPE_SAURFANG, NOT_STARTED);
setStage(0);
beasts = 0;
resetTimers();
m_creature->SetPower(m_creature->getPowerType(), 0);
doCast(SPELL_ZERO_REGEN);
oldPower = 0;
}
void MoveInLineOfSight(Unit* pWho)
{
if (!pInstance)
return;
if (!pWho || pWho->GetTypeId() != TYPEID_PLAYER)
return;
if (!m_creature->isInCombat() && pWho->IsWithinDistInMap(m_creature, 20.0f))
{
m_creature->setFaction(21);
m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE);
m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE);
AttackStart(pWho);
}
ScriptedAI::MoveInLineOfSight(pWho);
}
void Aggro(Unit *who)
{
if(!pInstance)
return;
if (!pInstance->IsEncounterAvailable(TYPE_SAURFANG))
{
pInstance->SendGMEncounterNotification(who, TYPE_SAURFANG);
EnterEvadeMode();
return;
}
pInstance->SetData(TYPE_SAURFANG, IN_PROGRESS);
SetEquipmentSlots(false, EQUIP_MAIN, EQUIP_OFFHAND, EQUIP_RANGED);
DoScriptText(-1631100,m_creature);
doCast(SPELL_BLOOD_LINK);
m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
}
void DamageTaken(Unit* pDoneBy, uint32& uiDamage)
{
if (!pInstance)
return;
if (!pInstance->IsEncounterAvailable(TYPE_SAURFANG))
{
pInstance->SendGMEncounterNotification(pDoneBy, TYPE_SAURFANG);
EnterEvadeMode();
uiDamage = 0;
return;
}
}
void JustReachedHome()
{
if (pInstance)
pInstance->SetData(TYPE_SAURFANG, FAIL);
}
void KilledUnit(Unit* pVictim)
{
switch (urand(0,1))
{
case 0:
DoScriptText(-1631103,m_creature,pVictim);
break;
case 1:
DoScriptText(-1631104,m_creature,pVictim);
break;
}
}
void JustSummoned(Creature* summoned)
{
if(!pInstance || !summoned)
return;
summoned->SetOwnerGuid(m_creature->GetObjectGuid());
if (Unit* pTarget = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0) )
{
summoned->AddThreat(pTarget, 100.0f);
summoned->GetMotionMaster()->MoveChase(pTarget);
}
}
void JustDied(Unit *killer)
{
if(!pInstance)
return;
pInstance->SetData(TYPE_SAURFANG, DONE);
DoScriptText(-1631106,m_creature);
doRemoveFromAll(SPELL_MARK);
DoCastSpellIfCan(m_creature, SPELL_ACHIEVEMENT_DEATHBRINGER_SAURFANG, CAST_TRIGGERED | CAST_FORCE_CAST);
}
void UpdateAI(const uint32 diff)
{
if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())
return;
if (!m_creature->HasAura(SPELL_BLOOD_POWER))
doCast(SPELL_BLOOD_POWER);
if (!m_creature->HasAura(SPELL_BLOOD_LINK))
doCast(SPELL_BLOOD_LINK);
if (!m_creature->HasAura(SPELL_MARK_SELF))
doCast(SPELL_MARK_SELF);
switch(getStage())
{
case 0:
if (m_creature->GetHealthPercent() <= 30.0f) setStage(1);
break;
case 1:
doCast(SPELL_FRENZY);
setStage(2);
DoScriptText(-1631101,m_creature);
break;
case 2:
default:
break;
}
if (timedQuery(SPELL_MARK, diff))
{
if (Unit* pTarget = doSelectRandomPlayer(SPELL_MARK,false,120.0f))
doCast(SPELL_MARK, pTarget);
}
timedCast(SPELL_BLOOD_NOVA, diff);
timedCast(SPELL_BOILING_BLOOD, diff);
timedCast(SPELL_RUNE_OF_BLOOD, diff);
if (timedQuery(SPELL_CALL_BLOOD_BEAST_1, diff))
{
beasts = getSpellData(SPELL_CALL_BLOOD_BEAST_1);
DoScriptText(-1631102,m_creature);
}
if (beasts > 0)
{
CanCastResult res = CAST_FAIL_OTHER;
switch (beasts)
{
case 1: res = doCast(SPELL_CALL_BLOOD_BEAST_1); break;
case 2: res = doCast(SPELL_CALL_BLOOD_BEAST_2); break;
case 3: res = doCast(SPELL_CALL_BLOOD_BEAST_3); break;
case 4: res = doCast(SPELL_CALL_BLOOD_BEAST_4); break;
case 5: res = doCast(SPELL_CALL_BLOOD_BEAST_5); break;
default: break;
}
if ( res == CAST_OK)
--beasts;
}
if (timedQuery(SPELL_BERSERK, diff))
{
doCast(SPELL_BERSERK);
DoScriptText(-1631108,m_creature);
};
DoMeleeAttackIfReady();
}
};
CreatureAI* GetAI_boss_deathbringer_saurfang(Creature* pCreature)
{
return new boss_deathbringer_saurfangAI(pCreature);
}
struct MANGOS_DLL_DECL mob_blood_beastAI : public BSWScriptedAI
{
mob_blood_beastAI(Creature *pCreature) : BSWScriptedAI(pCreature)
{
pInstance = (ScriptedInstance*)pCreature->GetInstanceData();
Reset();
}
ScriptedInstance *pInstance;
Creature* pOwner;
bool scentcasted;
void Reset()
{
pOwner = m_creature->GetMap()->GetCreature(pInstance->GetData64(NPC_DEATHBRINGER_SAURFANG));
resetTimers();
scentcasted = false;
}
void UpdateAI(const uint32 uiDiff)
{
if (!pInstance || pInstance->GetData(TYPE_SAURFANG) != IN_PROGRESS)
m_creature->ForcedDespawn();
if (!m_creature->SelectHostileTarget() || !m_creature->getVictim())
return;
if (!m_creature->HasAura(SPELL_BLOOD_LINK_BEAST))
doCast(SPELL_BLOOD_LINK_BEAST);
if (!m_creature->HasAura(SPELL_RESISTANT_SKIN))
doCast(SPELL_RESISTANT_SKIN);
if (!scentcasted && (m_creature->GetHealthPercent() <= 20.0f))
{
if (urand(0,1)) //50%
doCast(SPELL_SCENT_OF_BLOOD);
scentcasted = true;
}
DoMeleeAttackIfReady();
}
};
CreatureAI* GetAI_mob_blood_beast(Creature* pCreature)
{
return new mob_blood_beastAI(pCreature);
}
void AddSC_boss_deathbringer_saurfang()
{
Script *newscript;
newscript = new Script;
newscript->Name = "boss_deathbringer_saurfang";
newscript->GetAI = &GetAI_boss_deathbringer_saurfang;
newscript->RegisterSelf();
newscript = new Script;
newscript->Name = "mob_blood_beast";
newscript->GetAI = &GetAI_mob_blood_beast;
newscript->RegisterSelf();
}
| gpl-2.0 |
eaas-framework/virtualbox | src/VBox/VMM/testcase/Instructions/tstVBInsTstR3.cpp | 3 | 3798 | /* $Id: tstVBInsTstR3.cpp $ */
/** @file
* Instruction Test Environment - IPRT ring-3 driver.
*/
/*
* Copyright (C) 2006-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/mem.h>
#include <iprt/string.h>
#include <iprt/test.h>
#ifdef RT_OS_WINDOWS
# define NO_LOW_MEM
#elif defined(RT_OS_OS2) || defined(RT_OS_HAIKU)
# define NO_LOW_MEM
#else
# include <sys/mman.h>
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
#if HC_ARCH_BITS == 64
typedef uint64_t VBINSTSTREG;
#else
typedef uint32_t VBINSTSTREG;
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
RTTEST g_hTest;
RT_C_DECLS_BEGIN
extern void *g_pvLow16Mem4K;
extern void *g_pvLow32Mem4K;
DECLASM(void) TestInstrMain(void);
DECLEXPORT(void) VBInsTstFailure(const char *pszMessage);
DECLEXPORT(void) VBInsTstFailure1(const char *pszFmt, VBINSTSTREG uArg1);
DECLEXPORT(void) VBInsTstFailure2(const char *pszFmt, VBINSTSTREG uArg1, VBINSTSTREG uArg2);
DECLEXPORT(void) VBInsTstFailure3(const char *pszFmt, VBINSTSTREG uArg1, VBINSTSTREG uArg2, VBINSTSTREG uArg3);
DECLEXPORT(void) VBInsTstFailure4(const char *pszFmt, VBINSTSTREG uArg1, VBINSTSTREG uArg2, VBINSTSTREG uArg3, VBINSTSTREG uArg4);
RT_C_DECLS_END
DECLEXPORT(void) VBInsTstFailure(const char *pszMessage)
{
RTTestFailed(g_hTest, "%s", pszMessage);
}
DECLEXPORT(void) VBInsTstFailure1(const char *pszFmt, VBINSTSTREG uArg1)
{
RTTestFailed(g_hTest, pszFmt, uArg1);
}
DECLEXPORT(void) VBInsTstFailure2(const char *pszFmt, VBINSTSTREG uArg1, VBINSTSTREG uArg2)
{
RTTestFailed(g_hTest, pszFmt, uArg1, uArg2);
}
DECLEXPORT(void) VBInsTstFailure3(const char *pszFmt, VBINSTSTREG uArg1, VBINSTSTREG uArg2, VBINSTSTREG uArg3)
{
RTTestFailed(g_hTest, pszFmt, uArg1, uArg2, uArg3);
}
DECLEXPORT(void) VBInsTstFailure4(const char *pszFmt, VBINSTSTREG uArg1, VBINSTSTREG uArg2, VBINSTSTREG uArg3, VBINSTSTREG uArg4)
{
RTTestFailed(g_hTest, pszFmt, uArg1, uArg2, uArg3, uArg4);
}
int main()
{
RTEXITCODE rcExit = RTTestInitAndCreate("VBInsTstR3", &g_hTest);
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
RTTestBanner(g_hTest);
int rc = RTMemAllocEx(_4K, 0, RTMEMALLOCEX_FLAGS_16BIT_REACH, &g_pvLow16Mem4K);
if (RT_FAILURE(rc))
{
RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Could not allocate low 16-bit memory (%Rrc)\n", rc);
g_pvLow16Mem4K = NULL;
}
rc = RTMemAllocEx(_4K, 0, RTMEMALLOCEX_FLAGS_32BIT_REACH, &g_pvLow32Mem4K);
if (RT_FAILURE(rc))
{
RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Could not allocate low 32-bit memory (%Rrc)\n", rc);
g_pvLow32Mem4K = NULL;
}
TestInstrMain();
return RTTestSummaryAndDestroy(g_hTest);
}
| gpl-2.0 |
GreenLunar/psi | src/tools/tunecontroller/plugins/winamp/winampcontroller.cpp | 3 | 5180 | /*
* winampcontroller.cpp
* Copyright (C) 2006 Remko Troncon
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <windows.h>
#ifdef Q_CC_MSVC
#pragma warning(push)
#pragma warning(disable: 4100)
#endif
// this file generates eight C4100 warnings, when compiled with MSVC2003
#include "third-party/wa_ipc.h"
#ifdef Q_CC_MSVC
#pragma warning(pop)
#endif
#include "winampcontroller.h"
/**
* \class WinAmpController
* \brief A controller for WinAmp.
*/
static const int NormInterval = 3000;
static const int AntiscrollInterval = 100;
/**
* \brief Constructs the controller.
*/
WinAmpController::WinAmpController()
: PollingTuneController(),
antiscrollCounter_(0)
{
startPoll();
setInterval(NormInterval);
}
template <typename char_type> const size_t length (const char_type * begin)
{
const char_type * end = begin;
for (; *end; ++end);
return end - begin;
}
// Returns a title of a track currently being played by WinAmp with given HWND (passed in waWnd)
QPair<bool, QString> WinAmpController::getTrackTitle(const HWND &waWnd) const
{
TCHAR waTitle[2048];
QString title;
// Get WinAmp window title. It always contains name of the track
SendMessage (waWnd, WM_GETTEXT, static_cast<WPARAM> (sizeof (waTitle) / sizeof (waTitle[0])), reinterpret_cast<LPARAM> (waTitle));
// Now, waTitle contains WinAmp window title
title = QString ((const QChar *) waTitle, length<TCHAR> ((const TCHAR *) waTitle));
if (title[0] == '*' || (title.length () && title[title.length() - 1] == '*')) {
// request to be called again soon.
return QPair<bool, QString>(false, QString());
}
// Check whether there is a need to do the all stuff
if (!title.length()) {
return QPair<bool, QString>(true,title);
}
QString winamp (" - Winamp ***");
int winampLength = winamp.length();
// Is title scrolling on the taskbar enabled?
title += title + title;
int waLast = title.indexOf (winamp, -1);
if (waLast != -1) {
if (title.length()) {
title.remove (waLast, title.length () - waLast);
}
int waFirst;
while ((waFirst = title.indexOf (winamp)) != -1) {
title.remove (0, waFirst + winampLength);
}
}
else {
title = QString ((const QChar *) waTitle, length<TCHAR> ((const TCHAR *) waTitle)); // Title is not scrolling
}
// Remove leading and trailing spaces
title = title.trimmed();
// Remove trailing " - Winamp" from title
if (title.length ()) {
winamp = " - Winamp";
winampLength = winamp.length ();
int waFirst = title.indexOf (winamp);
if (waFirst != -1)
{
title.remove (waFirst, waFirst + winampLength);
}
}
// Remove track number from title
if (title.length ()) {
QString dot(". ");
int dotFirst = title.indexOf (dot);
if (dotFirst != -1) {
// All symbols before the dot are digits?
bool allDigits = true;
for (int pos = dotFirst; pos > 0; --pos) {
allDigits = allDigits && title[pos].isNumber();
}
if (allDigits) {
title.remove(0, dotFirst + dot.length ());
}
}
}
// Remove leading and trailing spaces
if (title.length ()) {
while (title.length () && title[0] == ' ') {
title.remove (0, 1);
}
while (title.length () && title[title.length () - 1] == ' ') {
title.remove (title.length () - 1, 1);
}
}
return QPair<bool, QString>(true,title);
}
/**
* Polls for new song info.
*/
void WinAmpController::check()
{
Tune tune;
#ifdef UNICODE
HWND h = FindWindow(L"Winamp v1.x", NULL);
#else
HWND h = FindWindow("Winamp v1.x", NULL);
#endif
if (h && SendMessage(h, WM_WA_IPC, 0, IPC_ISPLAYING) == 1) {
tune = getTune(h);
}
prevTune_ = tune;
setInterval(NormInterval);
PollingTuneController::check();
}
Tune WinAmpController::getTune(const HWND &hWnd)
{
Tune tune = Tune();
int position = (int)SendMessage(hWnd, WM_WA_IPC, 0, IPC_GETLISTPOS);
if (position != -1) {
if (hWnd && SendMessage(hWnd,WM_WA_IPC,0,IPC_ISPLAYING) == 1) {
QPair<bool, QString> trackpair(getTrackTitle(hWnd));
if (!trackpair.first) {
// getTrackTitle wants us to retry in a few ms...
int interval = AntiscrollInterval;
if (++antiscrollCounter_ > 10) {
antiscrollCounter_ = 0;
interval = NormInterval;
}
setInterval(interval);
return Tune();
}
antiscrollCounter_ = 0;
tune.setName(trackpair.second);
tune.setURL(trackpair.second);
tune.setTrack(QString::number(position + 1));
tune.setTime(SendMessage(hWnd, WM_WA_IPC, 1, IPC_GETOUTPUTTIME));
}
}
return tune;
}
Tune WinAmpController::currentTune() const
{
return prevTune_;
}
| gpl-2.0 |
asyan4ik/android_kernel_huawei_h60 | drivers/power/huawei/hisi_battery_data.c | 3 | 18094 | /*****************************************************************************************
* Filename: hisi_battery_data.c
*
* Discription: driver for battery.
* Copyright: (C) 2014 huawei.
*
* revision history:
*
*
******************************************************************************************/
#include "hisi_battery_data.h"
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_address.h>
#include <linux/hw_log.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <asm/bug.h>
#include <linux/module.h>
#include <linux/huawei/dsm_pub.h>
#define HWLOG_TAG hisi_battery_data
HWLOG_REGIST();
#ifdef HISI_BATTERY_DATA_DEBUG
#define hisi_bat_info(fmt,args...) do { hwlog_info(fmt, ## args);} while(0)
#else
#define hisi_bat_info(fmt,args...) do {} while(0)
#endif
/***************************static variable definition***********************************/
static struct hisi_hi6421v300_coul_battery_data** p_data = NULL;
static unsigned int hisi_bat_data_size = 0; //used to store number of bat types defined in DTS
//used to judege whether bat_drv works fine or not, 1 means yes,0 means no
static int bat_param_status = 0;
static int temp_points[] ={-20, -10, 0, 25, 40, 60};
static struct dsm_dev dsm_battery_detect = {
.name = "dsm_battery_detect",
.fops = NULL,
.buff_size = 1024,
};
static struct dsm_client *battery_detect_dclient = NULL;
struct hisi_hi6421v300_coul_battery_data* get_battery_data(unsigned int id_voltage)
{
int i;
int dsm_error_found = -1;
int dsm_error_offset = 0;
if (!bat_param_status)
{
hwlog_err("battery param is invalid\n");
return NULL;
}
if(!dsm_client_ocuppy(battery_detect_dclient))
{
dsm_error_found++;
}
for(i = 0; i < hisi_bat_data_size; i++)
{
if((id_voltage > p_data[i]->id_identify_min) && (id_voltage <= p_data[i]->id_identify_max))
{
if ((id_voltage < p_data[i]->id_voltage_min) || (id_voltage > p_data[i]->id_voltage_max))
{
dsm_error_found++;
dsm_error_offset = 0;
dsm_client_record(battery_detect_dclient, "Battery id voltage:%d is out of normal range:[%d~%d],identify range:[%d~%d]!\n",id_voltage,
p_data[i]->id_voltage_min,p_data[i]->id_voltage_max,p_data[i]->id_identify_min,p_data[i]->id_identify_max);
}
break;
}
}
if(i == hisi_bat_data_size)
{
i = 0;
dsm_error_found++;
dsm_error_offset = 1;
dsm_client_record(battery_detect_dclient, "Battery id voltage:%d is invalid. Use the default battery params!\n",id_voltage);
}
if(dsm_error_found > 0)
{
dsm_client_notify(battery_detect_dclient, DSM_BATTERY_DETECT_ERROR_NO + dsm_error_offset);
}
else if(!dsm_error_found)
{
dsm_client_unocuppy(battery_detect_dclient);
}
else
{
hwlog_err("dsm battery_detect_dclient ocuppy failed!\n");
}
hwlog_info("current battery name is %s\n", p_data[i]->batt_brand);
return p_data[i];
}
static int get_dat(struct device_node* np, struct hisi_hi6421v300_coul_battery_data *pdat)
{
int ret = 0;
int i,j;
ret = of_property_read_u32(np, "fcc", &(pdat->fcc));
if(ret)
{
hwlog_err("get fcc failed\n");
return -EINVAL;
}
hisi_bat_info("fcc is %u\n", pdat->fcc);
ret = of_property_read_u32(np, "id_identify_min", (unsigned int*)(&(pdat->id_identify_min)));
if(ret)
{
hwlog_err("get id_identify_min failed\n");
return -EINVAL;
}
hisi_bat_info("id_identify_min is %d\n", pdat->id_identify_min);
ret = of_property_read_u32(np, "id_identify_max", (unsigned int*)(&(pdat->id_identify_max)));
if(ret)
{
hwlog_err("get id_identify_max failed\n");
return -EINVAL;
}
hisi_bat_info("id_identify_max is %d\n", pdat->id_identify_max);
ret = of_property_read_u32(np, "id_voltage_min", (unsigned int*)(&(pdat->id_voltage_min)));
if(ret)
{
hwlog_err("get id_voltage_min failed\n");
return -EINVAL;
}
hisi_bat_info("id_voltage_min is %d\n", pdat->id_voltage_min);
ret = of_property_read_u32(np, "id_voltage_max", (unsigned int*)(&(pdat->id_voltage_max)));
if(ret)
{
hwlog_err("get id_voltage_max failed\n");
return -EINVAL;
}
hisi_bat_info("id_voltage_max is %d\n", pdat->id_voltage_max);
ret = of_property_read_u32(np, "default_rbatt_mohm", (unsigned int*)(&(pdat->default_rbatt_mohm)));
if(ret)
{
hwlog_err("get default_rbatt_mohm failed\n");
return -EINVAL;
}
hisi_bat_info("default_rbatt_mohm is %d\n", pdat->default_rbatt_mohm);
ret = of_property_read_u32(np, "max_currentmA", &(pdat->max_currentmA));
if(ret)
{
hwlog_err("get max_currentmA failed\n");
return -EINVAL;
}
hisi_bat_info("max_currentmA is %u\n", pdat->max_currentmA);
ret = of_property_read_u32(np, "max_voltagemV", &(pdat->max_voltagemV));
if(ret)
{
hwlog_err("get max_voltagemV failed\n");
return -EINVAL;
}
hisi_bat_info("max_voltagemV is %u\n", pdat->max_voltagemV);
ret = of_property_read_u32(np, "max_cin_currentmA", &(pdat->max_cin_currentmA));
if(ret)
{
hwlog_err("get max_cin_currentmA failed\n");
return -EINVAL;
}
hisi_bat_info("max_cin_currentmA is %u\n", pdat->max_cin_currentmA);
ret = of_property_read_u32(np, "terminal_currentmA", &(pdat->terminal_currentmA));
if(ret)
{
hwlog_err("get terminal_currentmA failed\n");
return -EINVAL;
}
hisi_bat_info("terminal_currentmA is %u\n", pdat->terminal_currentmA);
ret = of_property_read_u32(np, "charge_in_temp_5", &(pdat->charge_in_temp_5));
if(ret)
{
hwlog_err("get charge_in_temp_5 failed\n");
return -EINVAL;
}
hisi_bat_info("charge_in_temp_5 is %u\n", pdat->charge_in_temp_5);
ret = of_property_read_u32(np, "charge_in_temp_10", &(pdat->charge_in_temp_10));
if(ret)
{
hwlog_err("get charge_in_temp_10 failed\n");
return -EINVAL;
}
hisi_bat_info("charge_in_temp_10 is %u\n", pdat->charge_in_temp_10);
ret = of_property_read_string(np, "batt_brand", (const char**)(&(pdat->batt_brand)));
if(ret)
{
hwlog_err("get batt_brand failed\n");
return -EINVAL;
}
hisi_bat_info("batt_brand is %s\n", pdat->batt_brand);
//fcc_temp
pdat->fcc_temp_lut->cols = TEMP_SAMPLING_POINTS;
for(i = 0; i < pdat->fcc_temp_lut->cols; i++)
{
pdat->fcc_temp_lut->x[i] = temp_points[i];
ret = of_property_read_u32_index(np, "fcc_temp", i, (unsigned int*)(&(pdat->fcc_temp_lut->y[i])));
if(ret)
{
hwlog_err("get fcc_temp[%d] failed\n", i);
return -EINVAL;
}
hisi_bat_info("fcc_temp[%d] is %d\n", i, pdat->fcc_temp_lut->y[i]);
}
//fcc_sf
ret = of_property_read_u32(np, "fcc_sf_cols", (unsigned int*)(&(pdat->fcc_sf_lut->cols)));
if(ret)
{
hwlog_err("get fcc_sf_cols failed\n");
return -EINVAL;
}
hisi_bat_info("fcc_sf_cols is %d\n",pdat->fcc_sf_lut->cols);
for(i = 0; i < pdat->fcc_sf_lut->cols; i++)
{
ret = of_property_read_u32_index(np, "fcc_sf_x", i, (unsigned int*)(&(pdat->fcc_sf_lut->x[i])));
if(ret)
{
hwlog_err("get fcc_sf_x[%d] failed\n", i);
return -EINVAL;
}
hisi_bat_info("fcc_sf_x[%d] is %d\n", i, pdat->fcc_sf_lut->x[i]);
ret = of_property_read_u32_index(np, "fcc_sf_y", i, (unsigned int*)(&(pdat->fcc_sf_lut->y[i])));
if(ret)
{
hwlog_err("get fcc_sf_y[%d] failed\n", i);
return -EINVAL;
}
hisi_bat_info("fcc_sf_y[%d] is %d\n", i, pdat->fcc_sf_lut->y[i]);
}
//pc_sf_lut
ret = of_property_read_u32(np, "pc_sf_rows", (unsigned int*)(&(pdat->pc_sf_lut->rows)));
if(ret)
{
hwlog_err("get pc_sf_rows failed\n");
return -EINVAL;
}
hisi_bat_info("pc_sf_rows is %d\n", pdat->pc_sf_lut->rows);
ret = of_property_read_u32(np, "pc_sf_cols", (unsigned int*)(&(pdat->pc_sf_lut->cols)));
if(ret)
{
hwlog_err("get pc_sf_cols failed\n");
return -EINVAL;
}
hisi_bat_info("pc_sf_cols is %d\n", pdat->pc_sf_lut->cols);
ret = of_property_read_u32(np, "pc_sf_row_entries", (unsigned int*)(&(pdat->pc_sf_lut->row_entries[0])));
if(ret)
{
hwlog_err("get pc_sf_row_entries failed\n");
return -EINVAL;
}
hisi_bat_info("pc_sf_row_entries is %d\n", pdat->pc_sf_lut->row_entries[0]);
ret = of_property_read_u32(np, "pc_sf_percent", (unsigned int*)(&(pdat->pc_sf_lut->percent[0])));
if(ret)
{
hwlog_err("get pc_sf_percent failed\n");
return -EINVAL;
}
hisi_bat_info("pc_sf_percent is %d\n", pdat->pc_sf_lut->percent[0]);
ret = of_property_read_u32(np, "pc_sf_sf", (unsigned int*)(&(pdat->pc_sf_lut->sf[0][0])));
if(ret)
{
hwlog_err("get pc_sf_sf failed\n");
return -EINVAL;
}
hisi_bat_info("pc_sf_sf is %d\n", pdat->pc_sf_lut->sf[0][0]);
//rbat_sf
ret = of_property_read_u32(np, "rbatt_sf_rows", (unsigned int*)(&(pdat->rbatt_sf_lut->rows)));
if(ret)
{
hwlog_err("get rbatt_sf_rows failed\n");
return -EINVAL;
}
hisi_bat_info("rbatt_sf_rows is %d\n", pdat->rbatt_sf_lut->rows);
ret = of_property_read_u32(np, "rbatt_sf_cols", (unsigned int*)(&(pdat->rbatt_sf_lut->cols)));
if(ret)
{
hwlog_err("get rbatt_sf_cols failed\n");
return -EINVAL;
}
hisi_bat_info("rbatt_sf_cols is %d\n", pdat->rbatt_sf_lut->cols);
for(i = 0; i < pdat->rbatt_sf_lut->rows; i++)
{
ret = of_property_read_u32_index(np, "rbatt_sf_percent", i, (unsigned int*)(&(pdat->rbatt_sf_lut->percent[i])));
if(ret)
{
hwlog_err("get rbatt_sf_percent[%d] failed\n", i);
return -EINVAL;
}
hisi_bat_info("rbatt_sf_percent[%d] is %d\n", i, pdat->rbatt_sf_lut->percent[i]);
}
for(i = 0; i < pdat->rbatt_sf_lut->cols; i++)
{
pdat->rbatt_sf_lut->row_entries[i] = temp_points[i];
}
for(i = 0; i < pdat->rbatt_sf_lut->cols; i++) //6
{
for(j = 0; j < pdat->rbatt_sf_lut->rows; j++) //28
{
ret = of_property_read_u32_index(np, "rbatt_sf_sf", j * 6 + i, (unsigned int*)(&(pdat->rbatt_sf_lut->sf[j][i])));
if(ret)
{
hwlog_err("get rbatt_sf_sf[%d] failed\n", j * 6 + i);
return -EINVAL;
}
hisi_bat_info("rbatt_sf_sf[%d] is %d\n", j * 6 + i, pdat->rbatt_sf_lut->sf[j][i]);
}
}
//pc_temp_ocv
ret = of_property_read_u32(np, "pc_temp_ocv_rows", (unsigned int*)(&(pdat->pc_temp_ocv_lut->rows)));
if(ret)
{
hwlog_err("get pc_temp_ocv_rows failed\n");
return -EINVAL;
}
hisi_bat_info("pc_temp_ocv_rows is %d\n", pdat->pc_temp_ocv_lut->rows);
ret = of_property_read_u32(np, "pc_temp_ocv_cols", (unsigned int*)(&(pdat->pc_temp_ocv_lut->cols)));
if(ret)
{
hwlog_err("get pc_temp_ocv_cols failed\n");
return -EINVAL;
}
hisi_bat_info("pc_temp_ocv_cols is %d\n", pdat->pc_temp_ocv_lut->cols);
for(i = 0; i < pdat->pc_temp_ocv_lut->rows - 1; i++)
{
ret = of_property_read_u32_index(np, "pc_temp_ocv_percent", i, (unsigned int*)(&(pdat->pc_temp_ocv_lut->percent[i])));
if(ret)
{
hwlog_err("get pc_temp_ocv_percent[%d] failed\n", i);
return -EINVAL;
}
hisi_bat_info("pc_temp_ocv_percent[%d] is %d\n", i, pdat->pc_temp_ocv_lut->percent[i]);
}
for(i = 0; i < pdat->pc_temp_ocv_lut->cols; i++)
{
pdat->pc_temp_ocv_lut->temp[i] = temp_points[i];
}
for(i = 0; i < pdat->pc_temp_ocv_lut->cols; i++) // 6
{
for(j = 0; j < pdat->pc_temp_ocv_lut->rows; j++) // 29
{
ret = of_property_read_u32_index(np, "pc_temp_ocv_ocv", j * 6 + i, (unsigned int*)(&(pdat->pc_temp_ocv_lut->ocv[j][i])));
if(ret)
{
hwlog_err("get pc_temp_ocv_ocv[%d] failed\n", j * 6 + i);
return -EINVAL;
}
hisi_bat_info("rbatt_sf_sf[%d] is %d\n", j * 6 + i, pdat->pc_temp_ocv_lut->ocv[j][i]);
}
}
return ret;
}
static int get_mem(struct hisi_hi6421v300_coul_battery_data** p)
{
struct hisi_hi6421v300_coul_battery_data* pdat;
pdat = (struct hisi_hi6421v300_coul_battery_data*)kzalloc(sizeof(struct hisi_hi6421v300_coul_battery_data), GFP_KERNEL);
if (NULL == pdat)
{
hwlog_err("alloc pdat failed\n");
return -ENOMEM;
}
pdat->fcc_temp_lut = (struct single_row_lut*)kzalloc(sizeof(struct single_row_lut), GFP_KERNEL);
if (NULL == pdat->fcc_temp_lut)
{
hwlog_err("alloc pdat->fcc_temp_lut failed\n");
return -ENOMEM;
}
pdat->fcc_sf_lut = (struct single_row_lut*)kzalloc(sizeof(struct single_row_lut), GFP_KERNEL);
if (NULL == pdat->fcc_sf_lut)
{
hwlog_err("alloc pdat->fcc_sf_lut failed\n");
return -ENOMEM;
}
pdat->pc_temp_ocv_lut = (struct pc_temp_ocv_lut*)kzalloc(sizeof(struct pc_temp_ocv_lut), GFP_KERNEL);
if (NULL == pdat->pc_temp_ocv_lut)
{
hwlog_err("alloc pdat->pc_temp_ocv_lut failed\n");
return -ENOMEM;
}
pdat->pc_sf_lut = (struct sf_lut*)kzalloc(sizeof(struct sf_lut), GFP_KERNEL);
if (NULL == pdat->pc_sf_lut)
{
hwlog_err("alloc pdat->pc_sf_lut failed\n");
return -ENOMEM;
}
pdat->rbatt_sf_lut = (struct sf_lut*)kzalloc(sizeof(struct sf_lut), GFP_KERNEL);
if (NULL == pdat->rbatt_sf_lut)
{
hwlog_err("alloc pdat->rbatt_sf_lut failed\n");
return -ENOMEM;
}
*p = pdat;
return 0;
}
static void free_mem(struct hisi_hi6421v300_coul_battery_data** p)
{
struct hisi_hi6421v300_coul_battery_data* pdat = *p;
if (NULL == pdat)
{
hwlog_err("pointer pd is already NULL\n");
return;
}
if (NULL != pdat->fcc_temp_lut)
{
kfree(pdat->fcc_temp_lut);
pdat->fcc_temp_lut = NULL;
}
if (NULL != pdat->fcc_sf_lut)
{
kfree(pdat->fcc_sf_lut);
pdat->fcc_sf_lut = NULL;
}
if (NULL != pdat->pc_temp_ocv_lut)
{
kfree(pdat->pc_temp_ocv_lut);
pdat->pc_temp_ocv_lut = NULL;
}
if (NULL != pdat->pc_sf_lut)
{
kfree(pdat->pc_sf_lut);
pdat->pc_sf_lut = NULL;
}
if (NULL != pdat->rbatt_sf_lut)
{
kfree(pdat->rbatt_sf_lut);
pdat->rbatt_sf_lut = NULL;
}
kfree(pdat);
*p = NULL;
}
static int hisi_battery_data_probe(struct platform_device *pdev)
{
int retval;
unsigned int i;
struct device_node* np;
struct device_node* bat_node;
//get device node for battery module
bat_param_status = 0;
np = pdev->dev.of_node;
if(NULL == np)
{
hwlog_err("get device node failed\n");
goto fatal_err;
}
//get numeber of types
for (i = 0; ; ++i)
{
if (!of_parse_phandle(np, "batt_name", i))
{
break;
}
}
if (0 == i)
{
hwlog_err("hisi_bat_data_size is zero\n");
goto fatal_err;
}
hisi_bat_data_size = i;
hwlog_info("hisi_bat_data_size = %u\n", hisi_bat_data_size);
//alloc memory to store pointers(point to battery data)
p_data = (struct hisi_hi6421v300_coul_battery_data**)kzalloc(hisi_bat_data_size * sizeof(struct hisi_hi6421v300_coul_battery_data*), GFP_KERNEL);
if (!p_data)
{
hwlog_err("alloc memory for p_data failed\n");
goto fatal_err;
}
for(i = 0; i < hisi_bat_data_size; ++i)
{
retval = get_mem(&(p_data[i]));
if (retval)
{
hwlog_err("get_mem[%d] failed\n", i);
goto fatal_err;
}
bat_node = of_parse_phandle(np, "batt_name", i);
if (NULL == bat_node)
{
hwlog_err("get bat_node failed\n");
goto fatal_err;
}
retval = get_dat(bat_node, p_data[i]);
if (retval)
{
hwlog_err("get_dat[%d] failed\n", i);
goto fatal_err;
}
}
platform_set_drvdata(pdev, p_data);
bat_param_status = 1;
if (!battery_detect_dclient) {
battery_detect_dclient = dsm_register_client(&dsm_battery_detect);
}
hwlog_info("probe ok\n");
return 0;
fatal_err:
if (NULL != p_data)
{
for(i = 0; i < hisi_bat_data_size; ++i)
{
free_mem(&(p_data[i]));
}
kfree(p_data);
}
p_data = NULL;
BUG();
return -EINVAL;
}
static int hisi_battery_data_remove(struct platform_device *pdev)
{
int i;
struct hisi_hi6421v300_coul_battery_data** di = platform_get_drvdata(pdev);
if (di)
{
for(i = 0; i < hisi_bat_data_size; ++i)
{
free_mem(&(di[i]));
}
kfree(di);
}
p_data = NULL;
return 0;
}
static struct of_device_id hisi_bat_match_table[] =
{
{
.compatible = "hisi_battery",
.data = NULL,
},
{
},
};
static struct platform_driver hisi_bat_driver =
{
.probe = hisi_battery_data_probe,
.remove = hisi_battery_data_remove,
.driver =
{
.name = "hisi_battery",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(hisi_bat_match_table),
},
};
int __init hisi_battery_init(void)
{
return (platform_driver_register(&hisi_bat_driver));
}
void __exit hisi_battery_exit(void)
{
platform_driver_unregister(&hisi_bat_driver);
}
fs_initcall(hisi_battery_init);
module_exit(hisi_battery_exit);
MODULE_AUTHOR("HUAWEI");
MODULE_DESCRIPTION("hisi battery module driver");
MODULE_LICENSE("GPL");
| gpl-2.0 |
ngvincent/android-kernel-oppo-find5 | drivers/video/msm/msm_dss_io_8960.c | 3 | 22234 | /* Copyright (c) 2008-2012, Code Aurora Forum. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/clk.h>
#include <mach/clk.h>
#include "msm_fb.h"
#include "mdp.h"
#include "mdp4.h"
#include "mipi_dsi.h"
#include "hdmi_msm.h"
#include <mach/msm_iomap.h>
/* HDMI PHY macros */
#define HDMI_PHY_REG_0 (0x00000400)
#define HDMI_PHY_REG_1 (0x00000404)
#define HDMI_PHY_REG_2 (0x00000408)
#define HDMI_PHY_REG_3 (0x0000040c)
#define HDMI_PHY_REG_4 (0x00000410)
#define HDMI_PHY_REG_5 (0x00000414)
#define HDMI_PHY_REG_6 (0x00000418)
#define HDMI_PHY_REG_7 (0x0000041c)
#define HDMI_PHY_REG_8 (0x00000420)
#define HDMI_PHY_REG_9 (0x00000424)
#define HDMI_PHY_REG_10 (0x00000428)
#define HDMI_PHY_REG_11 (0x0000042c)
#define HDMI_PHY_REG_12 (0x00000430)
#define HDMI_PHY_REG_BIST_CFG (0x00000434)
#define HDMI_PHY_DEBUG_BUS_SEL (0x00000438)
#define HDMI_PHY_REG_MISC0 (0x0000043c)
#define HDMI_PHY_REG_13 (0x00000440)
#define HDMI_PHY_REG_14 (0x00000444)
#define HDMI_PHY_REG_15 (0x00000448)
#define HDMI_PHY_CTRL (0x000002D4)
/* HDMI PHY/PLL bit field macros */
#define HDMI_PHY_PLL_STATUS0 (0x00000598)
#define SW_RESET BIT(2)
#define SW_RESET_PLL BIT(0)
#define PWRDN_B BIT(7)
/* multimedia sub system clock control */
char *mmss_cc_base = MSM_MMSS_CLK_CTL_BASE;
/* multimedia sub system sfpb */
char *mmss_sfpb_base;
void __iomem *periph_base;
static struct dsi_clk_desc dsicore_clk;
static struct dsi_clk_desc dsi_pclk;
static struct clk *dsi_byte_div_clk;
static struct clk *dsi_esc_clk;
static struct clk *dsi_m_pclk;
static struct clk *dsi_s_pclk;
static struct clk *amp_pclk;
int mipi_dsi_clk_on;
int mipi_dsi_clk_init(struct platform_device *pdev)
{
struct msm_fb_data_type *mfd;
struct device *dev = &pdev->dev;
mfd = platform_get_drvdata(pdev);
amp_pclk = clk_get(dev, "arb_clk");
if (IS_ERR_OR_NULL(amp_pclk)) {
pr_err("can't find amp_pclk\n");
amp_pclk = NULL;
goto mipi_dsi_clk_err;
}
dsi_m_pclk = clk_get(dev, "master_iface_clk");
if (IS_ERR_OR_NULL(dsi_m_pclk)) {
pr_err("can't find dsi_m_pclk\n");
dsi_m_pclk = NULL;
goto mipi_dsi_clk_err;
}
dsi_s_pclk = clk_get(dev, "slave_iface_clk");
if (IS_ERR_OR_NULL(dsi_s_pclk)) {
pr_err("can't find dsi_s_pclk\n");
dsi_s_pclk = NULL;
goto mipi_dsi_clk_err;
}
dsi_byte_div_clk = clk_get(dev, "byte_clk");
if (IS_ERR(dsi_byte_div_clk)) {
pr_err("can't find dsi_byte_div_clk\n");
dsi_byte_div_clk = NULL;
goto mipi_dsi_clk_err;
}
dsi_esc_clk = clk_get(dev, "esc_clk");
if (IS_ERR(dsi_esc_clk)) {
printk(KERN_ERR "can't find dsi_esc_clk\n");
dsi_esc_clk = NULL;
goto mipi_dsi_clk_err;
}
return 0;
mipi_dsi_clk_err:
mipi_dsi_clk_deinit(dev);
return -EPERM;
}
void mipi_dsi_clk_deinit(struct device *dev)
{
if (amp_pclk)
clk_put(amp_pclk);
if (amp_pclk)
clk_put(dsi_m_pclk);
if (dsi_s_pclk)
clk_put(dsi_s_pclk);
if (dsi_byte_div_clk)
clk_put(dsi_byte_div_clk);
if (dsi_esc_clk)
clk_put(dsi_esc_clk);
}
static void mipi_dsi_clk_ctrl(struct dsi_clk_desc *clk, int clk_en)
{
char *cc, *ns, *md;
int pmxo_sel = 0;
char mnd_en = 1, root_en = 1;
uint32 data, val;
cc = mmss_cc_base + 0x004c;
md = mmss_cc_base + 0x0050;
ns = mmss_cc_base + 0x0054;
if (clk_en) {
if (clk->mnd_mode == 0) {
data = clk->pre_div_func << 14;
data |= clk->src;
MIPI_OUTP_SECURE(ns, data);
MIPI_OUTP_SECURE(cc, ((pmxo_sel << 8)
| (clk->mnd_mode << 6)
| (root_en << 2) | clk_en));
} else {
val = clk->d * 2;
data = (~val) & 0x0ff;
data |= clk->m << 8;
MIPI_OUTP_SECURE(md, data);
val = clk->n - clk->m;
data = (~val) & 0x0ff;
data <<= 24;
data |= clk->src;
MIPI_OUTP_SECURE(ns, data);
MIPI_OUTP_SECURE(cc, ((pmxo_sel << 8)
| (clk->mnd_mode << 6)
| (mnd_en << 5)
| (root_en << 2) | clk_en));
}
} else
MIPI_OUTP_SECURE(cc, 0);
wmb();
}
static void mipi_dsi_sfpb_cfg(void)
{
char *sfpb;
int data;
sfpb = mmss_sfpb_base + 0x058;
data = MIPI_INP(sfpb);
data |= 0x01800;
MIPI_OUTP(sfpb, data);
wmb();
}
static void mipi_dsi_pclk_ctrl(struct dsi_clk_desc *clk, int clk_en)
{
char *cc, *ns, *md;
char mnd_en = 1, root_en = 1;
uint32 data, val;
cc = mmss_cc_base + 0x0130;
md = mmss_cc_base + 0x0134;
ns = mmss_cc_base + 0x0138;
if (clk_en) {
if (clk->mnd_mode == 0) {
data = clk->pre_div_func << 12;
data |= clk->src;
MIPI_OUTP_SECURE(ns, data);
MIPI_OUTP_SECURE(cc, ((clk->mnd_mode << 6)
| (root_en << 2) | clk_en));
} else {
val = clk->d * 2;
data = (~val) & 0x0ff;
data |= clk->m << 8;
MIPI_OUTP_SECURE(md, data);
val = clk->n - clk->m;
data = (~val) & 0x0ff;
data <<= 24;
data |= clk->src;
MIPI_OUTP_SECURE(ns, data);
MIPI_OUTP_SECURE(cc, ((clk->mnd_mode << 6)
| (mnd_en << 5)
| (root_en << 2) | clk_en));
}
} else
MIPI_OUTP_SECURE(cc, 0);
wmb();
}
static void mipi_dsi_ahb_en(void)
{
char *ahb;
ahb = mmss_cc_base + 0x08;
pr_debug("%s: ahb=%x %x\n",
__func__, (int) ahb, MIPI_INP_SECURE(ahb));
}
void mipi_dsi_lane_cfg(void)
{
int i, ln_offset;
ln_offset = 0x300;
for (i = 0; i < 4; i++) {
/* DSI1_DSIPHY_LN_CFG0 */
MIPI_OUTP(MIPI_DSI_BASE + ln_offset, 0x80);
/* DSI1_DSIPHY_LN_CFG1 */
MIPI_OUTP(MIPI_DSI_BASE + ln_offset + 0x04, 0x45);
/* DSI1_DSIPHY_LN_CFG2 */
MIPI_OUTP(MIPI_DSI_BASE + ln_offset + 0x08, 0x0);
/* DSI1_DSIPHY_LN_TEST_DATAPATH */
MIPI_OUTP(MIPI_DSI_BASE + ln_offset + 0x0c, 0x0);
/* DSI1_DSIPHY_LN_TEST_STR0 */
MIPI_OUTP(MIPI_DSI_BASE + ln_offset + 0x14, 0x1);
/* DSI1_DSIPHY_LN_TEST_STR1 */
MIPI_OUTP(MIPI_DSI_BASE + ln_offset + 0x18, 0x66);
ln_offset += 0x40;
}
MIPI_OUTP(MIPI_DSI_BASE + 0x0400, 0x40); /* DSI1_DSIPHY_LNCK_CFG0 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0404, 0x67); /* DSI1_DSIPHY_LNCK_CFG1 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0408, 0x0); /* DSI1_DSIPHY_LNCK_CFG2 */
/* DSI1_DSIPHY_LNCK_TEST_DATAPATH */
MIPI_OUTP(MIPI_DSI_BASE + 0x040c, 0x0);
MIPI_OUTP(MIPI_DSI_BASE + 0x0414, 0x1); /* DSI1_DSIPHY_LNCK_TEST_STR0 */
/* DSI1_DSIPHY_LNCK_TEST_STR1 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0418, 0x88);
}
void mipi_dsi_bist_ctrl(void)
{
MIPI_OUTP(MIPI_DSI_BASE + 0x049c, 0x0f); /* DSI1_DSIPHY_BIST_CTRL4 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0490, 0x03); /* DSI1_DSIPHY_BIST_CTRL1 */
MIPI_OUTP(MIPI_DSI_BASE + 0x048c, 0x03); /* DSI1_DSIPHY_BIST_CTRL0 */
MIPI_OUTP(MIPI_DSI_BASE + 0x049c, 0x0); /* DSI1_DSIPHY_BIST_CTRL4 */
}
static void mipi_dsi_calibration(void)
{
int i = 0;
uint32 term_cnt = 5000;
int cal_busy = MIPI_INP(MIPI_DSI_BASE + 0x550);
/* DSI1_DSIPHY_REGULATOR_CAL_PWR_CFG */
MIPI_OUTP(MIPI_DSI_BASE + 0x0518, 0x03);
/* DSI1_DSIPHY_CAL_SW_CFG2 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0534, 0x0);
/* DSI1_DSIPHY_CAL_HW_CFG1 */
MIPI_OUTP(MIPI_DSI_BASE + 0x053c, 0x5a);
/* DSI1_DSIPHY_CAL_HW_CFG3 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0544, 0x10);
/* DSI1_DSIPHY_CAL_HW_CFG4 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0548, 0x01);
/* DSI1_DSIPHY_CAL_HW_CFG0 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0538, 0x01);
/* DSI1_DSIPHY_CAL_HW_TRIGGER */
MIPI_OUTP(MIPI_DSI_BASE + 0x0528, 0x01);
usleep_range(5000, 5000);
/* DSI1_DSIPHY_CAL_HW_TRIGGER */
MIPI_OUTP(MIPI_DSI_BASE + 0x0528, 0x00);
cal_busy = MIPI_INP(MIPI_DSI_BASE + 0x550);
while (cal_busy & 0x10) {
i++;
if (i > term_cnt) {
pr_err("DSI1 PHY REGULATOR NOT READY,"
"exceeded polling TIMEOUT!\n");
break;
}
cal_busy = MIPI_INP(MIPI_DSI_BASE + 0x550);
}
}
void mipi_dsi_phy_rdy_poll(void)
{
uint32 phy_pll_busy;
uint32 i = 0;
uint32 term_cnt = 0xFFFFFF;
phy_pll_busy = MIPI_INP(MIPI_DSI_BASE + 0x280);
while (!(phy_pll_busy & 0x1)) {
i++;
if (i > term_cnt) {
pr_err("DSI1 PHY NOT READY, exceeded polling TIMEOUT!\n");
break;
}
phy_pll_busy = MIPI_INP(MIPI_DSI_BASE + 0x280);
}
}
#define PREF_DIV_RATIO 27
struct dsiphy_pll_divider_config pll_divider_config;
int mipi_dsi_phy_pll_config(u32 clk_rate)
{
struct dsiphy_pll_divider_config *dividers;
u32 fb_divider, tmp;
dividers = &pll_divider_config;
/* DSIPHY_PLL_CTRL_x: 1 2 3 8 9 10 */
/* masks 0xff 0x07 0x3f 0x0f 0xff 0xff */
/* DSIPHY_PLL_CTRL_1 */
fb_divider = ((dividers->fb_divider) / 2) - 1;
MIPI_OUTP(MIPI_DSI_BASE + 0x204, fb_divider & 0xff);
/* DSIPHY_PLL_CTRL_2 */
tmp = MIPI_INP(MIPI_DSI_BASE + 0x208);
tmp &= ~0x07;
tmp |= (fb_divider >> 8) & 0x07;
MIPI_OUTP(MIPI_DSI_BASE + 0x208, tmp);
/* DSIPHY_PLL_CTRL_3 */
tmp = MIPI_INP(MIPI_DSI_BASE + 0x20c);
tmp &= ~0x3f;
tmp |= (dividers->ref_divider_ratio - 1) & 0x3f;
MIPI_OUTP(MIPI_DSI_BASE + 0x20c, tmp);
/* DSIPHY_PLL_CTRL_8 */
tmp = MIPI_INP(MIPI_DSI_BASE + 0x220);
tmp &= ~0x0f;
tmp |= (dividers->bit_clk_divider - 1) & 0x0f;
MIPI_OUTP(MIPI_DSI_BASE + 0x220, tmp);
/* DSIPHY_PLL_CTRL_9 */
MIPI_OUTP(MIPI_DSI_BASE + 0x224, (dividers->byte_clk_divider - 1));
/* DSIPHY_PLL_CTRL_10 */
MIPI_OUTP(MIPI_DSI_BASE + 0x228, (dividers->dsi_clk_divider - 1));
return 0;
}
int mipi_dsi_clk_div_config(uint8 bpp, uint8 lanes,
uint32 *expected_dsi_pclk)
{
u32 fb_divider, rate, vco;
u32 div_ratio = 0;
struct dsi_clk_mnd_table const *mnd_entry = mnd_table;
if (pll_divider_config.clk_rate == 0)
pll_divider_config.clk_rate = 454000000;
//pll_divider_config.clk_rate = 320000000;// ky change
rate = pll_divider_config.clk_rate / 1000000; /* In Mhz */
if (rate < 125) {
vco = rate * 8;
div_ratio = 8;
} else if (rate < 250) {
vco = rate * 4;
div_ratio = 4;
} else if (rate < 600) {
vco = rate * 2;
div_ratio = 2;
} else {
vco = rate * 1;
div_ratio = 1;
}
/* find the mnd settings from mnd_table entry */
for (; mnd_entry != mnd_table + ARRAY_SIZE(mnd_table); ++mnd_entry) {
if (((mnd_entry->lanes) == lanes) &&
((mnd_entry->bpp) == bpp))
break;
}
if (mnd_entry == mnd_table + ARRAY_SIZE(mnd_table)) {
pr_err("%s: requested Lanes, %u & BPP, %u, not supported\n",
__func__, lanes, bpp);
return -EINVAL;
}
fb_divider = ((vco * PREF_DIV_RATIO) / 27);
pll_divider_config.fb_divider = fb_divider;
pll_divider_config.ref_divider_ratio = PREF_DIV_RATIO;
pll_divider_config.bit_clk_divider = div_ratio;
pll_divider_config.byte_clk_divider =
pll_divider_config.bit_clk_divider * 8;
pll_divider_config.dsi_clk_divider =
(mnd_entry->dsiclk_div) * div_ratio;
if (mnd_entry->dsiclk_d == 0) {
dsicore_clk.mnd_mode = 0;
dsicore_clk.src = 0x3;
dsicore_clk.pre_div_func = (mnd_entry->dsiclk_n - 1);
} else {
dsicore_clk.mnd_mode = 2;
dsicore_clk.src = 0x3;
dsicore_clk.m = mnd_entry->dsiclk_m;
dsicore_clk.n = mnd_entry->dsiclk_n;
dsicore_clk.d = mnd_entry->dsiclk_d;
}
if ((mnd_entry->pclk_d == 0)
|| (mnd_entry->pclk_m == 1)) {
dsi_pclk.mnd_mode = 0;
dsi_pclk.src = 0x3;
dsi_pclk.pre_div_func = (mnd_entry->pclk_n - 1);
*expected_dsi_pclk = ((vco * 1000000) /
((pll_divider_config.dsi_clk_divider)
* (mnd_entry->pclk_n)));
} else {
dsi_pclk.mnd_mode = 2;
dsi_pclk.src = 0x3;
dsi_pclk.m = mnd_entry->pclk_m;
dsi_pclk.n = mnd_entry->pclk_n;
dsi_pclk.d = mnd_entry->pclk_d;
*expected_dsi_pclk = ((vco * 1000000 * dsi_pclk.m) /
((pll_divider_config.dsi_clk_divider)
* (mnd_entry->pclk_n)));
}
return 0;
}
static void mipi_dsi_configure_serdes(void)
{
void __iomem *cc;
/* PHY registers programemd thru S2P interface */
if (periph_base) {
MIPI_OUTP(periph_base + 0x2c, 0x000000b6);
MIPI_OUTP(periph_base + 0x2c, 0x000001b5);
MIPI_OUTP(periph_base + 0x2c, 0x000001b4);
MIPI_OUTP(periph_base + 0x2c, 0x000003b3);
MIPI_OUTP(periph_base + 0x2c, 0x000003a2);
MIPI_OUTP(periph_base + 0x2c, 0x000002a1);
MIPI_OUTP(periph_base + 0x2c, 0x000008a0);
MIPI_OUTP(periph_base + 0x2c, 0x00000d9f);
MIPI_OUTP(periph_base + 0x2c, 0x0000109e);
MIPI_OUTP(periph_base + 0x2c, 0x0000209d);
MIPI_OUTP(periph_base + 0x2c, 0x0000109c);
MIPI_OUTP(periph_base + 0x2c, 0x0000079a);
MIPI_OUTP(periph_base + 0x2c, 0x00000c99);
MIPI_OUTP(periph_base + 0x2c, 0x00002298);
MIPI_OUTP(periph_base + 0x2c, 0x000000a7);
MIPI_OUTP(periph_base + 0x2c, 0x000000a6);
MIPI_OUTP(periph_base + 0x2c, 0x000000a5);
MIPI_OUTP(periph_base + 0x2c, 0x00007fa4);
MIPI_OUTP(periph_base + 0x2c, 0x0000eea8);
MIPI_OUTP(periph_base + 0x2c, 0x000006aa);
MIPI_OUTP(periph_base + 0x2c, 0x00002095);
MIPI_OUTP(periph_base + 0x2c, 0x00000493);
MIPI_OUTP(periph_base + 0x2c, 0x00001092);
MIPI_OUTP(periph_base + 0x2c, 0x00000691);
MIPI_OUTP(periph_base + 0x2c, 0x00005490);
MIPI_OUTP(periph_base + 0x2c, 0x0000038d);
MIPI_OUTP(periph_base + 0x2c, 0x0000148c);
MIPI_OUTP(periph_base + 0x2c, 0x0000058b);
MIPI_OUTP(periph_base + 0x2c, 0x0000078a);
MIPI_OUTP(periph_base + 0x2c, 0x00001f89);
MIPI_OUTP(periph_base + 0x2c, 0x00003388);
MIPI_OUTP(periph_base + 0x2c, 0x00006387);
MIPI_OUTP(periph_base + 0x2c, 0x00004886);
MIPI_OUTP(periph_base + 0x2c, 0x00005085);
MIPI_OUTP(periph_base + 0x2c, 0x00000084);
MIPI_OUTP(periph_base + 0x2c, 0x0000da83);
MIPI_OUTP(periph_base + 0x2c, 0x0000b182);
MIPI_OUTP(periph_base + 0x2c, 0x00002f81);
MIPI_OUTP(periph_base + 0x2c, 0x00004080);
MIPI_OUTP(periph_base + 0x2c, 0x00004180);
MIPI_OUTP(periph_base + 0x2c, 0x000006aa);
}
cc = MIPI_DSI_BASE + 0x0130;
MIPI_OUTP(cc, 0x806c11c8);
MIPI_OUTP(cc, 0x804c11c8);
MIPI_OUTP(cc, 0x806d0080);
MIPI_OUTP(cc, 0x804d0080);
MIPI_OUTP(cc, 0x00000000);
MIPI_OUTP(cc, 0x807b1597);
MIPI_OUTP(cc, 0x805b1597);
MIPI_OUTP(cc, 0x807c0080);
MIPI_OUTP(cc, 0x805c0080);
MIPI_OUTP(cc, 0x00000000);
MIPI_OUTP(cc, 0x807911c8);
MIPI_OUTP(cc, 0x805911c8);
MIPI_OUTP(cc, 0x807a0080);
MIPI_OUTP(cc, 0x805a0080);
MIPI_OUTP(cc, 0x00000000);
MIPI_OUTP(cc, 0x80721555);
MIPI_OUTP(cc, 0x80521555);
MIPI_OUTP(cc, 0x80730000);
MIPI_OUTP(cc, 0x80530000);
MIPI_OUTP(cc, 0x00000000);
}
void mipi_dsi_phy_init(int panel_ndx, struct msm_panel_info const *panel_info,
int target_type)
{
struct mipi_dsi_phy_ctrl *pd;
int i, off;
MIPI_OUTP(MIPI_DSI_BASE + 0x128, 0x0001);/* start phy sw reset */
wmb();
usleep(1);
MIPI_OUTP(MIPI_DSI_BASE + 0x128, 0x0000);/* end phy w reset */
wmb();
usleep(1);
MIPI_OUTP(MIPI_DSI_BASE + 0x500, 0x0003);/* regulator_ctrl_0 */
MIPI_OUTP(MIPI_DSI_BASE + 0x504, 0x0001);/* regulator_ctrl_1 */
MIPI_OUTP(MIPI_DSI_BASE + 0x508, 0x0001);/* regulator_ctrl_2 */
MIPI_OUTP(MIPI_DSI_BASE + 0x50c, 0x0000);/* regulator_ctrl_3 */
MIPI_OUTP(MIPI_DSI_BASE + 0x510, 0x0100);/* regulator_ctrl_4 */
MIPI_OUTP(MIPI_DSI_BASE + 0x4b0, 0x04);/* DSIPHY_LDO_CNTRL */
pd = (panel_info->mipi).dsi_phy_db;
off = 0x0480; /* strength 0 - 2 */
for (i = 0; i < 3; i++) {
MIPI_OUTP(MIPI_DSI_BASE + off, pd->strength[i]);
wmb();
off += 4;
}
off = 0x0470; /* ctrl 0 - 3 */
for (i = 0; i < 4; i++) {
MIPI_OUTP(MIPI_DSI_BASE + off, pd->ctrl[i]);
wmb();
off += 4;
}
off = 0x0500; /* regulator ctrl 0 - 4 */
for (i = 0; i < 5; i++) {
MIPI_OUTP(MIPI_DSI_BASE + off, pd->regulator[i]);
wmb();
off += 4;
}
mipi_dsi_calibration();
mipi_dsi_lane_cfg(); /* lane cfgs */
mipi_dsi_bist_ctrl(); /* bist ctrl */
off = 0x0204; /* pll ctrl 1 - 19, skip 0 */
for (i = 1; i < 20; i++) {
MIPI_OUTP(MIPI_DSI_BASE + off, pd->pll[i]);
wmb();
off += 4;
}
if (panel_info)
mipi_dsi_phy_pll_config(panel_info->clk_rate);
/* pll ctrl 0 */
MIPI_OUTP(MIPI_DSI_BASE + 0x200, pd->pll[0]);
wmb();
off = 0x0440; /* phy timing ctrl 0 - 11 */
for (i = 0; i < 12; i++) {
MIPI_OUTP(MIPI_DSI_BASE + off, pd->timing[i]);
wmb();
off += 4;
}
if (target_type == 1)
mipi_dsi_configure_serdes();
}
void cont_splash_clk_ctrl(int enable)
{
static int cont_splash_clks_enabled;
if (enable && !cont_splash_clks_enabled) {
clk_prepare_enable(dsi_byte_div_clk);
clk_prepare_enable(dsi_esc_clk);
cont_splash_clks_enabled = 1;
} else if (!enable && cont_splash_clks_enabled) {
clk_disable_unprepare(dsi_byte_div_clk);
clk_disable_unprepare(dsi_esc_clk);
cont_splash_clks_enabled = 0;
}
}
void mipi_dsi_prepare_clocks(void)
{
clk_prepare(amp_pclk);
clk_prepare(dsi_m_pclk);
clk_prepare(dsi_s_pclk);
clk_prepare(dsi_byte_div_clk);
clk_prepare(dsi_esc_clk);
}
void mipi_dsi_unprepare_clocks(void)
{
clk_unprepare(dsi_esc_clk);
clk_unprepare(dsi_byte_div_clk);
clk_unprepare(dsi_m_pclk);
clk_unprepare(dsi_s_pclk);
clk_unprepare(amp_pclk);
}
void mipi_dsi_ahb_ctrl(u32 enable)
{
static int ahb_ctrl_done;
if (enable) {
if (ahb_ctrl_done) {
pr_info("%s: ahb clks already ON\n", __func__);
return;
}
clk_enable(amp_pclk); /* clock for AHB-master to AXI */
clk_enable(dsi_m_pclk);
clk_enable(dsi_s_pclk);
mipi_dsi_ahb_en();
mipi_dsi_sfpb_cfg();
ahb_ctrl_done = 1;
} else {
if (ahb_ctrl_done == 0) {
pr_info("%s: ahb clks already OFF\n", __func__);
return;
}
clk_disable(dsi_m_pclk);
clk_disable(dsi_s_pclk);
clk_disable(amp_pclk); /* clock for AHB-master to AXI */
ahb_ctrl_done = 0;
}
}
void mipi_dsi_clk_enable(void)
{
u32 pll_ctrl = MIPI_INP(MIPI_DSI_BASE + 0x0200);
if (mipi_dsi_clk_on) {
pr_info("%s: mipi_dsi_clks already ON\n", __func__);
return;
}
MIPI_OUTP(MIPI_DSI_BASE + 0x0200, pll_ctrl | 0x01);
mipi_dsi_phy_rdy_poll();
if (clk_set_rate(dsi_byte_div_clk, 1) < 0) /* divided by 1 */
pr_err("%s: dsi_byte_div_clk - "
"clk_set_rate failed\n", __func__);
if (clk_set_rate(dsi_esc_clk, esc_byte_ratio) < 0) /* divided by esc */
pr_err("%s: dsi_esc_clk - " /* clk ratio */
"clk_set_rate failed\n", __func__);
mipi_dsi_pclk_ctrl(&dsi_pclk, 1);
mipi_dsi_clk_ctrl(&dsicore_clk, 1);
clk_enable(dsi_byte_div_clk);
clk_enable(dsi_esc_clk);
mipi_dsi_clk_on = 1;
mdp4_stat.dsi_clk_on++;
}
void mipi_dsi_clk_disable(void)
{
if (mipi_dsi_clk_on == 0) {
pr_info("%s: mipi_dsi_clks already OFF\n", __func__);
return;
}
clk_disable(dsi_esc_clk);
clk_disable(dsi_byte_div_clk);
mipi_dsi_pclk_ctrl(&dsi_pclk, 0);
mipi_dsi_clk_ctrl(&dsicore_clk, 0);
/* DSIPHY_PLL_CTRL_0, disable dsi pll */
MIPI_OUTP(MIPI_DSI_BASE + 0x0200, 0x0);
mipi_dsi_clk_on = 0;
mdp4_stat.dsi_clk_off++;
}
void mipi_dsi_phy_ctrl(int on)
{
if (on) {
/* DSIPHY_PLL_CTRL_5 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0214, 0x050);
} else {
/* DSIPHY_PLL_CTRL_5 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0214, 0x05f);
/* DSIPHY_REGULATOR_CTRL_0 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0500, 0x02);
/* DSIPHY_CTRL_0 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0470, 0x00);
/* DSIPHY_CTRL_1 */
MIPI_OUTP(MIPI_DSI_BASE + 0x0474, 0x7f);
/* disable dsi clk */
MIPI_OUTP(MIPI_DSI_BASE + 0x0118, 0);
}
}
#ifdef CONFIG_FB_MSM_HDMI_COMMON
void hdmi_phy_reset(void)
{
unsigned int phy_reset_polarity = 0x0;
unsigned int pll_reset_polarity = 0x0;
unsigned int val = HDMI_INP_ND(HDMI_PHY_CTRL);
phy_reset_polarity = val >> 3 & 0x1;
pll_reset_polarity = val >> 1 & 0x1;
if (phy_reset_polarity == 0)
HDMI_OUTP(HDMI_PHY_CTRL, val | SW_RESET);
else
HDMI_OUTP(HDMI_PHY_CTRL, val & (~SW_RESET));
if (pll_reset_polarity == 0)
HDMI_OUTP(HDMI_PHY_CTRL, val | SW_RESET_PLL);
else
HDMI_OUTP(HDMI_PHY_CTRL, val & (~SW_RESET_PLL));
msleep(100);
if (phy_reset_polarity == 0)
HDMI_OUTP(HDMI_PHY_CTRL, val & (~SW_RESET));
else
HDMI_OUTP(HDMI_PHY_CTRL, val | SW_RESET);
if (pll_reset_polarity == 0)
HDMI_OUTP(HDMI_PHY_CTRL, val & (~SW_RESET_PLL));
else
HDMI_OUTP(HDMI_PHY_CTRL, val | SW_RESET_PLL);
}
void hdmi_msm_reset_core(void)
{
hdmi_msm_clk(0);
udelay(5);
hdmi_msm_clk(1);
clk_reset(hdmi_msm_state->hdmi_app_clk, CLK_RESET_ASSERT);
udelay(20);
clk_reset(hdmi_msm_state->hdmi_app_clk, CLK_RESET_DEASSERT);
}
void hdmi_msm_init_phy(int video_format)
{
uint32 offset;
pr_err("Video format is : %u\n", video_format);
HDMI_OUTP(HDMI_PHY_REG_0, 0x1B);
HDMI_OUTP(HDMI_PHY_REG_1, 0xf2);
offset = HDMI_PHY_REG_4;
while (offset <= HDMI_PHY_REG_11) {
HDMI_OUTP(offset, 0x0);
offset += 0x4;
}
HDMI_OUTP(HDMI_PHY_REG_3, 0x20);
}
void hdmi_msm_powerdown_phy(void)
{
/* Power down PHY */
HDMI_OUTP_ND(HDMI_PHY_REG_2, 0x7F); /*0b01111111*/
}
void hdmi_frame_ctrl_cfg(const struct hdmi_disp_mode_timing_type *timing)
{
/* 0x02C8 HDMI_FRAME_CTRL
* 31 INTERLACED_EN Interlaced or progressive enable bit
* 0: Frame in progressive
* 1: Frame is interlaced
* 29 HSYNC_HDMI_POL HSYNC polarity fed to HDMI core
* 0: Active Hi Hsync, detect the rising edge of hsync
* 1: Active lo Hsync, Detect the falling edge of Hsync
* 28 VSYNC_HDMI_POL VSYNC polarity fed to HDMI core
* 0: Active Hi Vsync, detect the rising edge of vsync
* 1: Active Lo Vsync, Detect the falling edge of Vsync
* 12 RGB_MUX_SEL ALPHA mdp4 input is RGB, mdp4 input is BGR
*/
HDMI_OUTP(0x02C8,
((timing->interlaced << 31) & 0x80000000)
| ((timing->active_low_h << 29) & 0x20000000)
| ((timing->active_low_v << 28) & 0x10000000));
}
void hdmi_msm_phy_status_poll(void)
{
unsigned int lock_det, phy_ready;
lock_det = 0x1 & HDMI_INP_ND(HDMI_PHY_PLL_STATUS0);
if (lock_det) {
pr_debug("HDMI Phy PLL Lock Detect Bit is set\n");
} else {
pr_debug("HDMI Phy Lock Detect Bit is not set,"
"waiting for lock detection\n");
do {
lock_det = 0x1 & \
HDMI_INP_ND(HDMI_PHY_PLL_STATUS0);
} while (!lock_det);
}
phy_ready = 0x1 & HDMI_INP_ND(HDMI_PHY_REG_15);
if (phy_ready) {
pr_debug("HDMI Phy Status bit is set and ready\n");
} else {
pr_debug("HDMI Phy Status bit is not set,"
"waiting for ready status\n");
do {
phy_ready = 0x1 & HDMI_INP_ND(HDMI_PHY_REG_15);
} while (!phy_ready);
}
}
#endif
| gpl-2.0 |
PabloPiaggi/lammps | src/USER-MEAMC/meam_funcs.cpp | 3 | 8559 | /* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Sebastian Hütter (OvGU)
------------------------------------------------------------------------- */
#include "meam.h"
#include "math_special.h"
#include <cmath>
using namespace LAMMPS_NS;
//-----------------------------------------------------------------------------
// Compute G(gamma) based on selection flag ibar:
// 0 => G = sqrt(1+gamma)
// 1 => G = exp(gamma/2)
// 2 => not implemented
// 3 => G = 2/(1+exp(-gamma))
// 4 => G = sqrt(1+gamma)
// -5 => G = +-sqrt(abs(1+gamma))
//
double
MEAM::G_gam(const double gamma, const int ibar, int& errorflag) const
{
double gsmooth_switchpoint;
switch (ibar) {
case 0:
case 4:
gsmooth_switchpoint = -gsmooth_factor / (gsmooth_factor + 1);
if (gamma < gsmooth_switchpoint) {
// e.g. gsmooth_factor is 99, {:
// gsmooth_switchpoint = -0.99
// G = 0.01*(-0.99/gamma)**99
double G = 1 / (gsmooth_factor + 1) * pow((gsmooth_switchpoint / gamma), gsmooth_factor);
return sqrt(G);
} else {
return sqrt(1.0 + gamma);
}
case 1:
return MathSpecial::fm_exp(gamma / 2.0);
case 3:
return 2.0 / (1.0 + MathSpecial::fm_exp(-gamma));
case -5:
if ((1.0 + gamma) >= 0) {
return sqrt(1.0 + gamma);
} else {
return -sqrt(-1.0 - gamma);
}
}
errorflag = 1;
return 0.0;
}
//-----------------------------------------------------------------------------
// Compute G(gamma and dG(gamma) based on selection flag ibar:
// 0 => G = sqrt(1+gamma)
// 1 => G = exp(gamma/2)
// 2 => not implemented
// 3 => G = 2/(1+exp(-gamma))
// 4 => G = sqrt(1+gamma)
// -5 => G = +-sqrt(abs(1+gamma))
//
double
MEAM::dG_gam(const double gamma, const int ibar, double& dG) const
{
double gsmooth_switchpoint;
double G;
switch (ibar) {
case 0:
case 4:
gsmooth_switchpoint = -gsmooth_factor / (gsmooth_factor + 1);
if (gamma < gsmooth_switchpoint) {
// e.g. gsmooth_factor is 99, {:
// gsmooth_switchpoint = -0.99
// G = 0.01*(-0.99/gamma)**99
G = 1 / (gsmooth_factor + 1) * pow((gsmooth_switchpoint / gamma), gsmooth_factor);
G = sqrt(G);
dG = -gsmooth_factor * G / (2.0 * gamma);
return G;
} else {
G = sqrt(1.0 + gamma);
dG = 1.0 / (2.0 * G);
return G;
}
case 1:
G = MathSpecial::fm_exp(gamma / 2.0);
dG = G / 2.0;
return G;
case 3:
G = 2.0 / (1.0 + MathSpecial::fm_exp(-gamma));
dG = G * (2.0 - G) / 2;
return G;
case -5:
if ((1.0 + gamma) >= 0) {
G = sqrt(1.0 + gamma);
dG = 1.0 / (2.0 * G);
return G;
} else {
G = -sqrt(-1.0 - gamma);
dG = -1.0 / (2.0 * G);
return G;
}
}
dG = 1.0;
return 0.0;
}
//-----------------------------------------------------------------------------
// Compute ZBL potential
//
double
MEAM::zbl(const double r, const int z1, const int z2)
{
int i;
const double c[] = { 0.028171, 0.28022, 0.50986, 0.18175 };
const double d[] = { 0.20162, 0.40290, 0.94229, 3.1998 };
const double azero = 0.4685;
const double cc = 14.3997;
double a, x;
// azero = (9pi^2/128)^1/3 (0.529) Angstroms
a = azero / (pow(z1, 0.23) + pow(z2, 0.23));
double result = 0.0;
x = r / a;
for (i = 0; i <= 3; i++) {
result = result + c[i] * MathSpecial::fm_exp(-d[i] * x);
}
if (r > 0.0)
result = result * z1 * z2 / r * cc;
return result;
}
//-----------------------------------------------------------------------------
// Compute embedding function F(rhobar) and derivative F'(rhobar), eqn I.5
//
double
MEAM::embedding(const double A, const double Ec, const double rhobar, double& dF) const
{
const double AEc = A * Ec;
if (rhobar > 0.0) {
const double lrb = log(rhobar);
dF = AEc * (1.0 + lrb);
return AEc * rhobar * lrb;
} else {
if (this->emb_lin_neg == 0) {
dF = 0.0;
return 0.0;
} else {
dF = - AEc;
return - AEc * rhobar;
}
}
}
//-----------------------------------------------------------------------------
// Compute Rose energy function, I.16
//
double
MEAM::erose(const double r, const double re, const double alpha, const double Ec, const double repuls,
const double attrac, const int form)
{
double astar, a3;
double result = 0.0;
if (r > 0.0) {
astar = alpha * (r / re - 1.0);
a3 = 0.0;
if (astar >= 0)
a3 = attrac;
else if (astar < 0)
a3 = repuls;
if (form == 1)
result = -Ec * (1 + astar + (-attrac + repuls / r) * MathSpecial::cube(astar)) * MathSpecial::fm_exp(-astar);
else if (form == 2)
result = -Ec * (1 + astar + a3 * MathSpecial::cube(astar)) * MathSpecial::fm_exp(-astar);
else
result = -Ec * (1 + astar + a3 * MathSpecial::cube(astar) / (r / re)) * MathSpecial::fm_exp(-astar);
}
return result;
}
//-----------------------------------------------------------------------------
// Shape factors for various configurations
//
void
MEAM::get_shpfcn(const lattice_t latt, double (&s)[3])
{
switch (latt) {
case FCC:
case BCC:
case B1:
case B2:
s[0] = 0.0;
s[1] = 0.0;
s[2] = 0.0;
break;
case HCP:
s[0] = 0.0;
s[1] = 0.0;
s[2] = 1.0 / 3.0;
break;
case DIA:
s[0] = 0.0;
s[1] = 0.0;
s[2] = 32.0 / 9.0;
break;
case DIM:
s[0] = 1.0;
s[1] = 2.0 / 3.0;
// s(3) = 1.d0
s[2] = 0.40;
break;
default:
s[0] = 0.0;
// call error('Lattice not defined in get_shpfcn.')
}
}
//-----------------------------------------------------------------------------
// Number of neighbors for the reference structure
//
int
MEAM::get_Zij(const lattice_t latt)
{
switch (latt) {
case FCC:
return 12;
case BCC:
return 8;
case HCP:
return 12;
case B1:
return 6;
case DIA:
return 4;
case DIM:
return 1;
case C11:
return 10;
case L12:
return 12;
case B2:
return 8;
// call error('Lattice not defined in get_Zij.')
}
return 0;
}
//-----------------------------------------------------------------------------
// Number of second neighbors for the reference structure
// a = distance ratio R1/R2
// S = second neighbor screening function
//
int
MEAM::get_Zij2(const lattice_t latt, const double cmin, const double cmax, double& a, double& S)
{
double C, x, sijk;
int Zij2 = 0, numscr = 0;
switch (latt) {
case FCC:
Zij2 = 6;
a = sqrt(2.0);
numscr = 4;
break;
case BCC:
Zij2 = 6;
a = 2.0 / sqrt(3.0);
numscr = 4;
break;
case HCP:
Zij2 = 6;
a = sqrt(2.0);
numscr = 4;
break;
case B1:
Zij2 = 12;
a = sqrt(2.0);
numscr = 2;
break;
case DIA:
Zij2 = 12;
a = sqrt(8.0 / 3.0);
numscr = 1;
if (cmin < 0.500001) {
// call error('can not do 2NN MEAM for dia')
}
break;
case DIM:
// this really shouldn't be allowed; make sure screening is zero
a = 1.0;
S = 0.0;
return 0;
case L12:
Zij2 = 6;
a = sqrt(2.0);
numscr = 4;
break;
case B2:
Zij2 = 6;
a = 2.0 / sqrt(3.0);
numscr = 4;
break;
case C11:
// unsupported lattice flag C11 in get_Zij
break;
default:
// unknown lattic flag in get Zij
// call error('Lattice not defined in get_Zij.')
break;
}
// Compute screening for each first neighbor
C = 4.0 / (a * a) - 1.0;
x = (C - cmin) / (cmax - cmin);
sijk = fcut(x);
// There are numscr first neighbors screening the second neighbors
S = MathSpecial::powint(sijk, numscr);
return Zij2;
}
| gpl-2.0 |
vikasTmz/visp | modules/robot/src/wireframe-simulator/vpSkipio.cpp | 3 | 2656 | /****************************************************************************
*
* This file is part of the ViSP software.
* Copyright (C) 2005 - 2017 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* ("GPL") version 2 as published by the Free Software Foundation.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See http://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Le module "skipio.c" contient les procedures d'analyse
* syntaxique du fichier "source" qui permettent de traiter
* les commandes inconnues.
*
* Authors:
* Jean-Luc CORRE
*
*****************************************************************************/
#include <visp3/core/vpConfig.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#include "vpMy.h"
#include "vpToken.h"
#include "vpLex.h"
#include "vpSkipio.h"
#include <stdio.h>
/*
* La procedure "skip_cmd" saute les structures d'une commande
* jusqu'a reconnaitre le debut d'une nouvelle commande.
* Entree :
* f Fichier en sortie.
*/
void skip_cmd (void)
{
int token;
fprintf (stderr, "\n$ ");
fwrite (mytext, (size_t)mylength, 1, stderr);
while ((token = lexecho (stderr, '$')) != T_EOF && token != '$') {};
unlex ();
}
/*
* La procedure "skip_keyword" saute les structures des articles
* jusqu'a reconnaitre le mot cle de jeton "token".
* Entree :
* token Jeton du mot cle a reconnaitre.
* err Message d'erreur si le mot cle n'est pas reconnu.
*/
void skip_keyword (int token, const char *err)
{
int t;
switch (t = lex ()) {
case T_IDENT : /* saute le mot cle inconnu */
while ((t = lex ()) != 0){
switch (t) {
case '$' : /* nouvelle commande */
case T_EOF : /* fin de fichier */
lexerr ("start", err, NULL);
break;
default :
if (t == token) return;
break;
}
}
break;
default :
if (t == token) return;
break;
}
lexerr ("start", err, NULL);
}
#endif
| gpl-2.0 |
dezelin/virtualbox | src/VBox/Runtime/r3/stream.cpp | 3 | 32134 | /* $Id$ */
/** @file
* IPRT - I/O Stream.
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#if defined(RT_OS_LINUX) /* PORTME: check for the _unlocked functions in stdio.h */
#define HAVE_FWRITE_UNLOCKED
#endif
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/stream.h>
#include "internal/iprt.h"
#include <iprt/asm.h>
#ifndef HAVE_FWRITE_UNLOCKED
# include <iprt/critsect.h>
#endif
#include <iprt/string.h>
#include <iprt/assert.h>
#include <iprt/alloc.h>
#include <iprt/err.h>
#include <iprt/param.h>
#include <iprt/string.h>
#include "internal/alignmentchecks.h"
#include "internal/magics.h"
#include <stdio.h>
#include <errno.h>
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
# include <io.h>
# include <fcntl.h>
#endif
#ifdef RT_OS_WINDOWS
# include <Windows.h>
#endif
#ifdef RT_OS_OS2
# define _O_TEXT O_TEXT
# define _O_BINARY O_BINARY
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* File stream.
*/
typedef struct RTSTREAM
{
/** Magic value used to validate the stream. (RTSTREAM_MAGIC) */
uint32_t u32Magic;
/** File stream error. */
int32_t volatile i32Error;
/** Pointer to the LIBC file stream. */
FILE *pFile;
/** Stream is using the current process code set. */
bool fCurrentCodeSet;
/** Whether the stream was opened in binary mode. */
bool fBinary;
/** Whether to recheck the stream mode before writing.. */
bool fRecheckMode;
#ifndef HAVE_FWRITE_UNLOCKED
/** Critical section for serializing access to the stream. */
PRTCRITSECT pCritSect;
#endif
} RTSTREAM;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The standard input stream. */
static RTSTREAM g_StdIn =
{
RTSTREAM_MAGIC,
0,
stdin,
/*.fCurrentCodeSet = */ true,
/*.fBinary = */ false,
/*.fRecheckMode = */ true
#ifndef HAVE_FWRITE_UNLOCKED
, NULL
#endif
};
/** The standard error stream. */
static RTSTREAM g_StdErr =
{
RTSTREAM_MAGIC,
0,
stderr,
/*.fCurrentCodeSet = */ true,
/*.fBinary = */ false,
/*.fRecheckMode = */ true
#ifndef HAVE_FWRITE_UNLOCKED
, NULL
#endif
};
/** The standard output stream. */
static RTSTREAM g_StdOut =
{
RTSTREAM_MAGIC,
0,
stdout,
/*.fCurrentCodeSet = */ true,
/*.fBinary = */ false,
/*.fRecheckMode = */ true
#ifndef HAVE_FWRITE_UNLOCKED
, NULL
#endif
};
/** Pointer to the standard input stream. */
RTDATADECL(PRTSTREAM) g_pStdIn = &g_StdIn;
/** Pointer to the standard output stream. */
RTDATADECL(PRTSTREAM) g_pStdErr = &g_StdErr;
/** Pointer to the standard output stream. */
RTDATADECL(PRTSTREAM) g_pStdOut = &g_StdOut;
#ifndef HAVE_FWRITE_UNLOCKED
/**
* Allocates and acquires the lock for the stream.
*
* @returns IPRT status.
* @param pStream The stream (valid).
*/
static int rtStrmAllocLock(PRTSTREAM pStream)
{
Assert(pStream->pCritSect == NULL);
PRTCRITSECT pCritSect = (PRTCRITSECT)RTMemAlloc(sizeof(*pCritSect));
if (!pCritSect)
return VERR_NO_MEMORY;
/* The native stream lock are normally not recursive. */
int rc = RTCritSectInitEx(pCritSect, RTCRITSECT_FLAGS_NO_NESTING,
NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemSpinMutex");
if (RT_SUCCESS(rc))
{
rc = RTCritSectEnter(pCritSect);
if (RT_SUCCESS(rc))
{
if (RT_LIKELY(ASMAtomicCmpXchgPtr(&pStream->pCritSect, pCritSect, NULL)))
return VINF_SUCCESS;
RTCritSectLeave(pCritSect);
}
RTCritSectDelete(pCritSect);
}
RTMemFree(pCritSect);
/* Handle the lost race case... */
pCritSect = ASMAtomicReadPtrT(&pStream->pCritSect, PRTCRITSECT);
if (pCritSect)
return RTCritSectEnter(pCritSect);
return rc;
}
#endif /* !HAVE_FWRITE_UNLOCKED */
/**
* Locks the stream. May have to allocate the lock as well.
*
* @param pStream The stream (valid).
*/
DECLINLINE(void) rtStrmLock(PRTSTREAM pStream)
{
#ifdef HAVE_FWRITE_UNLOCKED
flockfile(pStream->pFile);
#else
if (RT_LIKELY(pStream->pCritSect))
RTCritSectEnter(pStream->pCritSect);
else
rtStrmAllocLock(pStream);
#endif
}
/**
* Unlocks the stream.
*
* @param pStream The stream (valid).
*/
DECLINLINE(void) rtStrmUnlock(PRTSTREAM pStream)
{
#ifdef HAVE_FWRITE_UNLOCKED
funlockfile(pStream->pFile);
#else
if (RT_LIKELY(pStream->pCritSect))
RTCritSectLeave(pStream->pCritSect);
#endif
}
/**
* Opens a file stream.
*
* @returns iprt status code.
* @param pszFilename Path to the file to open.
* @param pszMode The open mode. See fopen() standard.
* Format: <a|r|w>[+][b|t]
* @param ppStream Where to store the opened stream.
*/
RTR3DECL(int) RTStrmOpen(const char *pszFilename, const char *pszMode, PRTSTREAM *ppStream)
{
/*
* Validate input.
*/
if (!pszMode || !*pszMode)
{
AssertMsgFailed(("No pszMode!\n"));
return VERR_INVALID_PARAMETER;
}
if (!pszFilename)
{
AssertMsgFailed(("No pszFilename!\n"));
return VERR_INVALID_PARAMETER;
}
bool fOk = true;
bool fBinary = false;
switch (*pszMode)
{
case 'a':
case 'w':
case 'r':
switch (pszMode[1])
{
case '\0':
break;
case '+':
switch (pszMode[2])
{
case '\0':
break;
//case 't':
// break;
case 'b':
fBinary = true;
break;
default:
fOk = false;
break;
}
break;
//case 't':
// break;
case 'b':
fBinary = true;
break;
default:
fOk = false;
break;
}
break;
default:
fOk = false;
break;
}
if (!fOk)
{
AssertMsgFailed(("Invalid pszMode='%s', '<a|r|w>[+][b|t]'\n", pszMode));
return VINF_SUCCESS;
}
/*
* Allocate the stream handle and try open it.
*/
PRTSTREAM pStream = (PRTSTREAM)RTMemAlloc(sizeof(*pStream));
if (pStream)
{
pStream->u32Magic = RTSTREAM_MAGIC;
pStream->i32Error = VINF_SUCCESS;
pStream->fCurrentCodeSet = false;
pStream->fBinary = fBinary;
#ifndef HAVE_FWRITE_UNLOCKED
pStream->pCritSect = NULL;
#endif /* HAVE_FWRITE_UNLOCKED */
pStream->pFile = fopen(pszFilename, pszMode);
if (pStream->pFile)
{
*ppStream = pStream;
return VINF_SUCCESS;
}
RTMemFree(pStream);
return RTErrConvertFromErrno(errno);
}
return VERR_NO_MEMORY;
}
/**
* Opens a file stream.
*
* @returns iprt status code.
* @param pszMode The open mode. See fopen() standard.
* Format: <a|r|w>[+][b|t]
* @param ppStream Where to store the opened stream.
* @param pszFilenameFmt Filename path format string.
* @param args Arguments to the format string.
*/
RTR3DECL(int) RTStrmOpenFV(const char *pszMode, PRTSTREAM *ppStream, const char *pszFilenameFmt, va_list args)
{
int rc;
char szFilename[RTPATH_MAX];
size_t cch = RTStrPrintfV(szFilename, sizeof(szFilename), pszFilenameFmt, args);
if (cch < sizeof(szFilename))
rc = RTStrmOpen(szFilename, pszMode, ppStream);
else
{
AssertMsgFailed(("The filename is too long cch=%d\n", cch));
rc = VERR_FILENAME_TOO_LONG;
}
return rc;
}
/**
* Opens a file stream.
*
* @returns iprt status code.
* @param pszMode The open mode. See fopen() standard.
* Format: <a|r|w>[+][b|t]
* @param ppStream Where to store the opened stream.
* @param pszFilenameFmt Filename path format string.
* @param ... Arguments to the format string.
*/
RTR3DECL(int) RTStrmOpenF(const char *pszMode, PRTSTREAM *ppStream, const char *pszFilenameFmt, ...)
{
va_list args;
va_start(args, pszFilenameFmt);
int rc = RTStrmOpenFV(pszMode, ppStream, pszFilenameFmt, args);
va_end(args);
return rc;
}
/**
* Closes the specified stream.
*
* @returns iprt status code.
* @param pStream The stream to close.
*/
RTR3DECL(int) RTStrmClose(PRTSTREAM pStream)
{
if (!pStream)
return VINF_SUCCESS;
AssertReturn(RT_VALID_PTR(pStream) && pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_PARAMETER);
if (!fclose(pStream->pFile))
{
pStream->u32Magic = 0xdeaddead;
pStream->pFile = NULL;
#ifndef HAVE_FWRITE_UNLOCKED
if (pStream->pCritSect)
{
RTCritSectEnter(pStream->pCritSect);
RTCritSectLeave(pStream->pCritSect);
RTCritSectDelete(pStream->pCritSect);
RTMemFree(pStream->pCritSect);
pStream->pCritSect = NULL;
}
#endif
RTMemFree(pStream);
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
/**
* Get the pending error of the stream.
*
* @returns iprt status code. of the stream.
* @param pStream The stream.
*/
RTR3DECL(int) RTStrmError(PRTSTREAM pStream)
{
AssertReturn(RT_VALID_PTR(pStream) && pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_PARAMETER);
return pStream->i32Error;
}
/**
* Clears stream error condition.
*
* All stream operations save RTStrmClose and this will fail
* while an error is asserted on the stream
*
* @returns iprt status code.
* @param pStream The stream.
*/
RTR3DECL(int) RTStrmClearError(PRTSTREAM pStream)
{
AssertReturn(RT_VALID_PTR(pStream) && pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_PARAMETER);
clearerr(pStream->pFile);
ASMAtomicWriteS32(&pStream->i32Error, VINF_SUCCESS);
return VINF_SUCCESS;
}
RTR3DECL(int) RTStrmSetMode(PRTSTREAM pStream, int fBinary, int fCurrentCodeSet)
{
AssertPtrReturn(pStream, VERR_INVALID_HANDLE);
AssertReturn(pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_HANDLE);
AssertReturn((unsigned)(fBinary + 1) <= 2, VERR_INVALID_PARAMETER);
AssertReturn((unsigned)(fCurrentCodeSet + 1) <= 2, VERR_INVALID_PARAMETER);
rtStrmLock(pStream);
if (fBinary != -1)
{
pStream->fBinary = RT_BOOL(fBinary);
pStream->fRecheckMode = true;
}
if (fCurrentCodeSet != -1)
pStream->fCurrentCodeSet = RT_BOOL(fCurrentCodeSet);
rtStrmUnlock(pStream);
return VINF_SUCCESS;
}
/**
* Rewinds the stream.
*
* Stream errors will be reset on success.
*
* @returns IPRT status code.
*
* @param pStream The stream.
*
* @remarks Not all streams are rewindable and that behavior is currently
* undefined for those.
*/
RTR3DECL(int) RTStrmRewind(PRTSTREAM pStream)
{
AssertPtrReturn(pStream, VERR_INVALID_HANDLE);
AssertReturn(pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_HANDLE);
int rc;
clearerr(pStream->pFile);
errno = 0;
if (!fseek(pStream->pFile, 0, SEEK_SET))
{
ASMAtomicWriteS32(&pStream->i32Error, VINF_SUCCESS);
rc = VINF_SUCCESS;
}
else
{
rc = RTErrConvertFromErrno(errno);
ASMAtomicWriteS32(&pStream->i32Error, rc);
}
return rc;
}
/**
* Recheck the stream mode.
*
* @param pStream The stream (locked).
*/
static void rtStreamRecheckMode(PRTSTREAM pStream)
{
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
int fh = fileno(pStream->pFile);
if (fh >= 0)
{
int fExpected = pStream->fBinary ? _O_BINARY : _O_TEXT;
int fActual = _setmode(fh, fExpected);
if (fActual != -1 && fExpected != (fActual & (_O_BINARY | _O_TEXT)))
{
fActual = _setmode(fh, fActual & (_O_BINARY | _O_TEXT));
pStream->fBinary = !(fActual & _O_TEXT);
}
}
#else
NOREF(pStream);
#endif
pStream->fRecheckMode = false;
}
/**
* Reads from a file stream.
*
* @returns iprt status code.
* @param pStream The stream.
* @param pvBuf Where to put the read bits.
* Must be cbRead bytes or more.
* @param cbRead Number of bytes to read.
* @param pcbRead Where to store the number of bytes actually read.
* If NULL cbRead bytes are read or an error is returned.
*/
RTR3DECL(int) RTStrmReadEx(PRTSTREAM pStream, void *pvBuf, size_t cbRead, size_t *pcbRead)
{
AssertReturn(RT_VALID_PTR(pStream) && pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_PARAMETER);
int rc = pStream->i32Error;
if (RT_SUCCESS(rc))
{
if (pStream->fRecheckMode)
rtStreamRecheckMode(pStream);
if (pcbRead)
{
/*
* Can do with a partial read.
*/
*pcbRead = fread(pvBuf, 1, cbRead, pStream->pFile);
if ( *pcbRead == cbRead
|| !ferror(pStream->pFile))
return VINF_SUCCESS;
if (feof(pStream->pFile))
{
if (*pcbRead)
return VINF_EOF;
rc = VERR_EOF;
}
else if (ferror(pStream->pFile))
rc = VERR_READ_ERROR;
else
{
AssertMsgFailed(("This shouldn't happen\n"));
rc = VERR_INTERNAL_ERROR;
}
}
else
{
/*
* Must read it all!
*/
if (fread(pvBuf, cbRead, 1, pStream->pFile) == 1)
return VINF_SUCCESS;
/* possible error/eof. */
if (feof(pStream->pFile))
rc = VERR_EOF;
else if (ferror(pStream->pFile))
rc = VERR_READ_ERROR;
else
{
AssertMsgFailed(("This shouldn't happen\n"));
rc = VERR_INTERNAL_ERROR;
}
}
ASMAtomicWriteS32(&pStream->i32Error, rc);
}
return rc;
}
/**
* Check if the input text is valid UTF-8.
*
* @returns true/false.
* @param pvBuf Pointer to the buffer.
* @param cbBuf Size of the buffer.
*/
static bool rtStrmIsUtf8Text(const void *pvBuf, size_t cbBuf)
{
NOREF(pvBuf);
NOREF(cbBuf);
/** @todo not sure this is a good idea... Better redefine RTStrmWrite. */
return false;
}
#ifdef RT_OS_WINDOWS
/**
* Check if the stream is for a Window console.
*
* @returns true / false.
* @param pStream The stream.
* @param phCon Where to return the console handle.
*/
static bool rtStrmIsConsoleUnlocked(PRTSTREAM pStream, HANDLE *phCon)
{
int fh = fileno(pStream->pFile);
if (isatty(fh))
{
DWORD dwMode;
HANDLE hCon = (HANDLE)_get_osfhandle(fh);
if (GetConsoleMode(hCon, &dwMode))
{
*phCon = hCon;
return true;
}
}
return false;
}
#endif /* RT_OS_WINDOWS */
/**
* Internal write API, stream lock already held.
*
* @returns IPRT status code.
* @param pStream The stream.
* @param pvBuf What to write.
* @param cbWrite How much to write.
* @param pcbWritten Where to optionally return the number of bytes
* written.
* @param fSureIsText Set if we're sure this is UTF-8 text already.
*/
static int rtStrmWriteLocked(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten,
bool fSureIsText)
{
int rc = pStream->i32Error;
if (RT_FAILURE(rc))
return rc;
if (pStream->fRecheckMode)
rtStreamRecheckMode(pStream);
#ifdef RT_OS_WINDOWS
/*
* Use the unicode console API when possible in order to avoid stuff
* getting lost in unnecessary code page translations.
*/
HANDLE hCon;
if (rtStrmIsConsoleUnlocked(pStream, &hCon))
{
# ifdef HAVE_FWRITE_UNLOCKED
if (!fflush_unlocked(pStream->pFile))
# else
if (!fflush(pStream->pFile))
# endif
{
/** @todo Consider buffering later. For now, we'd rather correct output than
* fast output. */
DWORD cwcWritten = 0;
PRTUTF16 pwszSrc = NULL;
size_t cwcSrc = 0;
rc = RTStrToUtf16Ex((const char *)pvBuf, cbWrite, &pwszSrc, 0, &cwcSrc);
if (RT_SUCCESS(rc))
{
if (!WriteConsoleW(hCon, pwszSrc, (DWORD)cwcSrc, &cwcWritten, NULL))
{
/* try write char-by-char to avoid heap problem. */
cwcWritten = 0;
while (cwcWritten != cwcSrc)
{
DWORD cwcThis;
if (!WriteConsoleW(hCon, &pwszSrc[cwcWritten], 1, &cwcThis, NULL))
{
if (!pcbWritten || cwcWritten == 0)
rc = RTErrConvertFromErrno(GetLastError());
break;
}
if (cwcThis != 1) /* Unable to write current char (amount)? */
break;
cwcWritten++;
}
}
if (RT_SUCCESS(rc))
{
if (cwcWritten == cwcSrc)
{
if (pcbWritten)
*pcbWritten = cbWrite;
}
else if (pcbWritten)
{
PCRTUTF16 pwszCur = pwszSrc;
const char *pszCur = (const char *)pvBuf;
while ((uintptr_t)(pwszCur - pwszSrc) < cwcWritten)
{
RTUNICP CpIgnored;
RTUtf16GetCpEx(&pwszCur, &CpIgnored);
RTStrGetCpEx(&pszCur, &CpIgnored);
}
*pcbWritten = pszCur - (const char *)pvBuf;
}
else
rc = VERR_WRITE_ERROR;
}
RTUtf16Free(pwszSrc);
}
}
else
rc = RTErrConvertFromErrno(errno);
if (RT_FAILURE(rc))
ASMAtomicWriteS32(&pStream->i32Error, rc);
return rc;
}
#endif /* RT_OS_WINDOWS */
/*
* If we're sure it's text output, convert it from UTF-8 to the current
* code page before printing it.
*
* Note! Partial writes are not supported in this scenario because we
* cannot easily report back a written length matching the input.
*/
/** @todo Skip this if the current code set is UTF-8. */
if ( pStream->fCurrentCodeSet
&& !pStream->fBinary
&& ( fSureIsText
|| rtStrmIsUtf8Text(pvBuf, cbWrite))
)
{
char *pszSrcFree = NULL;
const char *pszSrc = (const char *)pvBuf;
if (pszSrc[cbWrite])
{
pszSrc = pszSrcFree = RTStrDupN(pszSrc, cbWrite);
if (pszSrc == NULL)
rc = VERR_NO_STR_MEMORY;
}
if (RT_SUCCESS(rc))
{
char *pszSrcCurCP;
rc = RTStrUtf8ToCurrentCP(&pszSrcCurCP, pszSrc);
if (RT_SUCCESS(rc))
{
size_t cchSrcCurCP = strlen(pszSrcCurCP);
IPRT_ALIGNMENT_CHECKS_DISABLE(); /* glibc / mempcpy again */
#ifdef HAVE_FWRITE_UNLOCKED
ssize_t cbWritten = fwrite_unlocked(pszSrcCurCP, cchSrcCurCP, 1, pStream->pFile);
#else
ssize_t cbWritten = fwrite(pszSrcCurCP, cchSrcCurCP, 1, pStream->pFile);
#endif
IPRT_ALIGNMENT_CHECKS_ENABLE();
if (cbWritten == 1)
{
if (pcbWritten)
*pcbWritten = cbWrite;
}
#ifdef HAVE_FWRITE_UNLOCKED
else if (!ferror_unlocked(pStream->pFile))
#else
else if (!ferror(pStream->pFile))
#endif
{
if (pcbWritten)
*pcbWritten = 0;
}
else
rc = VERR_WRITE_ERROR;
RTStrFree(pszSrcCurCP);
}
RTStrFree(pszSrcFree);
}
if (RT_FAILURE(rc))
ASMAtomicWriteS32(&pStream->i32Error, rc);
return rc;
}
/*
* Otherwise, just write it as-is.
*/
if (pcbWritten)
{
IPRT_ALIGNMENT_CHECKS_DISABLE(); /* glibc / mempcpy again */
#ifdef HAVE_FWRITE_UNLOCKED
*pcbWritten = fwrite_unlocked(pvBuf, 1, cbWrite, pStream->pFile);
#else
*pcbWritten = fwrite(pvBuf, 1, cbWrite, pStream->pFile);
#endif
IPRT_ALIGNMENT_CHECKS_ENABLE();
if ( *pcbWritten == cbWrite
#ifdef HAVE_FWRITE_UNLOCKED
|| !ferror_unlocked(pStream->pFile))
#else
|| !ferror(pStream->pFile))
#endif
return VINF_SUCCESS;
rc = VERR_WRITE_ERROR;
}
else
{
/* Must write it all! */
IPRT_ALIGNMENT_CHECKS_DISABLE(); /* glibc / mempcpy again */
#ifdef HAVE_FWRITE_UNLOCKED
size_t cbWritten = fwrite_unlocked(pvBuf, cbWrite, 1, pStream->pFile);
#else
size_t cbWritten = fwrite(pvBuf, cbWrite, 1, pStream->pFile);
#endif
IPRT_ALIGNMENT_CHECKS_ENABLE();
if (cbWritten == 1)
return VINF_SUCCESS;
#ifdef HAVE_FWRITE_UNLOCKED
if (!ferror_unlocked(pStream->pFile))
#else
if (!ferror(pStream->pFile))
#endif
return VINF_SUCCESS; /* WEIRD! But anyway... */
rc = VERR_WRITE_ERROR;
}
ASMAtomicWriteS32(&pStream->i32Error, rc);
return rc;
}
/**
* Internal write API.
*
* @returns IPRT status code.
* @param pStream The stream.
* @param pvBuf What to write.
* @param cbWrite How much to write.
* @param pcbWritten Where to optionally return the number of bytes
* written.
* @param fSureIsText Set if we're sure this is UTF-8 text already.
*/
static int rtStrmWrite(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten, bool fSureIsText)
{
rtStrmLock(pStream);
int rc = rtStrmWriteLocked(pStream, pvBuf, cbWrite, pcbWritten, fSureIsText);
rtStrmUnlock(pStream);
return rc;
}
/**
* Writes to a file stream.
*
* @returns iprt status code.
* @param pStream The stream.
* @param pvBuf Where to get the bits to write from.
* @param cbWrite Number of bytes to write.
* @param pcbWritten Where to store the number of bytes actually written.
* If NULL cbWrite bytes are written or an error is returned.
*/
RTR3DECL(int) RTStrmWriteEx(PRTSTREAM pStream, const void *pvBuf, size_t cbWrite, size_t *pcbWritten)
{
AssertReturn(RT_VALID_PTR(pStream) && pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_PARAMETER);
return rtStrmWrite(pStream, pvBuf, cbWrite, pcbWritten, false);
}
/**
* Reads a character from a file stream.
*
* @returns The char as an unsigned char cast to int.
* @returns -1 on failure.
* @param pStream The stream.
*/
RTR3DECL(int) RTStrmGetCh(PRTSTREAM pStream)
{
unsigned char ch;
int rc = RTStrmReadEx(pStream, &ch, 1, NULL);
if (RT_SUCCESS(rc))
return ch;
return -1;
}
/**
* Writes a character to a file stream.
*
* @returns iprt status code.
* @param pStream The stream.
* @param ch The char to write.
*/
RTR3DECL(int) RTStrmPutCh(PRTSTREAM pStream, int ch)
{
return rtStrmWrite(pStream, &ch, 1, NULL, true /*fSureIsText*/);
}
/**
* Writes a string to a file stream.
*
* @returns iprt status code.
* @param pStream The stream.
* @param pszString The string to write.
* No newlines or anything is appended or prepended.
* The terminating '\\0' is not written, of course.
*/
RTR3DECL(int) RTStrmPutStr(PRTSTREAM pStream, const char *pszString)
{
size_t cch = strlen(pszString);
return rtStrmWrite(pStream, pszString, cch, NULL, true /*fSureIsText*/);
}
RTR3DECL(int) RTStrmGetLine(PRTSTREAM pStream, char *pszString, size_t cbString)
{
AssertReturn(RT_VALID_PTR(pStream) && pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_PARAMETER);
int rc;
if (pszString && cbString > 1)
{
rc = pStream->i32Error;
if (RT_SUCCESS(rc))
{
cbString--; /* save space for the terminator. */
rtStrmLock(pStream);
for (;;)
{
#ifdef HAVE_FWRITE_UNLOCKED /** @todo darwin + freebsd(?) has fgetc_unlocked but not fwrite_unlocked, optimize... */
int ch = fgetc_unlocked(pStream->pFile);
#else
int ch = fgetc(pStream->pFile);
#endif
/* Deal with \r\n sequences here. We'll return lone CR, but
treat CRLF as LF. */
if (ch == '\r')
{
#ifdef HAVE_FWRITE_UNLOCKED /** @todo darwin + freebsd(?) has fgetc_unlocked but not fwrite_unlocked, optimize... */
ch = fgetc_unlocked(pStream->pFile);
#else
ch = fgetc(pStream->pFile);
#endif
if (ch == '\n')
break;
*pszString++ = '\r';
if (--cbString <= 0)
{
/* yeah, this is an error, we dropped a character. */
rc = VERR_BUFFER_OVERFLOW;
break;
}
}
/* Deal with end of file. */
if (ch == EOF)
{
#ifdef HAVE_FWRITE_UNLOCKED
if (feof_unlocked(pStream->pFile))
#else
if (feof(pStream->pFile))
#endif
{
rc = VERR_EOF;
break;
}
#ifdef HAVE_FWRITE_UNLOCKED
if (ferror_unlocked(pStream->pFile))
#else
if (ferror(pStream->pFile))
#endif
rc = VERR_READ_ERROR;
else
{
AssertMsgFailed(("This shouldn't happen\n"));
rc = VERR_INTERNAL_ERROR;
}
break;
}
/* Deal with null terminator and (lone) new line. */
if (ch == '\0' || ch == '\n')
break;
/* No special character, append it to the return string. */
*pszString++ = ch;
if (--cbString <= 0)
{
rc = VINF_BUFFER_OVERFLOW;
break;
}
}
rtStrmUnlock(pStream);
*pszString = '\0';
if (RT_FAILURE(rc))
ASMAtomicWriteS32(&pStream->i32Error, rc);
}
}
else
{
AssertMsgFailed(("no buffer or too small buffer!\n"));
rc = VERR_INVALID_PARAMETER;
}
return rc;
}
/**
* Flushes a stream.
*
* @returns iprt status code.
* @param pStream The stream to flush.
*/
RTR3DECL(int) RTStrmFlush(PRTSTREAM pStream)
{
if (!fflush(pStream->pFile))
return VINF_SUCCESS;
return RTErrConvertFromErrno(errno);
}
/**
* Output callback.
*
* @returns number of bytes written.
* @param pvArg User argument.
* @param pachChars Pointer to an array of utf-8 characters.
* @param cchChars Number of bytes in the character array pointed to by pachChars.
*/
static DECLCALLBACK(size_t) rtstrmOutput(void *pvArg, const char *pachChars, size_t cchChars)
{
if (cchChars)
rtStrmWriteLocked((PRTSTREAM)pvArg, pachChars, cchChars, NULL, true /*fSureIsText*/);
/* else: ignore termination call. */
return cchChars;
}
/**
* Prints a formatted string to the specified stream.
*
* @returns Number of bytes printed.
* @param pStream The stream to print to.
* @param pszFormat IPRT format string.
* @param args Arguments specified by pszFormat.
*/
RTR3DECL(int) RTStrmPrintfV(PRTSTREAM pStream, const char *pszFormat, va_list args)
{
AssertReturn(RT_VALID_PTR(pStream) && pStream->u32Magic == RTSTREAM_MAGIC, VERR_INVALID_PARAMETER);
int rc = pStream->i32Error;
if (RT_SUCCESS(rc))
{
rtStrmLock(pStream);
// pStream->fShouldFlush = true;
rc = (int)RTStrFormatV(rtstrmOutput, pStream, NULL, NULL, pszFormat, args);
rtStrmUnlock(pStream);
Assert(rc >= 0);
}
else
rc = -1;
return rc;
}
/**
* Prints a formatted string to the specified stream.
*
* @returns Number of bytes printed.
* @param pStream The stream to print to.
* @param pszFormat IPRT format string.
* @param ... Arguments specified by pszFormat.
*/
RTR3DECL(int) RTStrmPrintf(PRTSTREAM pStream, const char *pszFormat, ...)
{
va_list args;
va_start(args, pszFormat);
int rc = RTStrmPrintfV(pStream, pszFormat, args);
va_end(args);
return rc;
}
/**
* Prints a formatted string to the standard output stream (g_pStdOut).
*
* @returns Number of bytes printed.
* @param pszFormat IPRT format string.
* @param args Arguments specified by pszFormat.
*/
RTR3DECL(int) RTPrintfV(const char *pszFormat, va_list args)
{
return RTStrmPrintfV(g_pStdOut, pszFormat, args);
}
/**
* Prints a formatted string to the standard output stream (g_pStdOut).
*
* @returns Number of bytes printed.
* @param pszFormat IPRT format string.
* @param ... Arguments specified by pszFormat.
*/
RTR3DECL(int) RTPrintf(const char *pszFormat, ...)
{
va_list args;
va_start(args, pszFormat);
int rc = RTStrmPrintfV(g_pStdOut, pszFormat, args);
va_end(args);
return rc;
}
| gpl-2.0 |
chaodhib/TrinityCore | src/common/GitRevision.cpp | 3 | 2588 | /*
* Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
*
* 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "GitRevision.h"
#include "revision_data.h"
char const* GitRevision::GetHash()
{
return _HASH;
}
char const* GitRevision::GetDate()
{
return _DATE;
}
char const* GitRevision::GetBranch()
{
return _BRANCH;
}
char const* GitRevision::GetCMakeCommand()
{
return _CMAKE_COMMAND;
}
char const* GitRevision::GetCMakeVersion()
{
return _CMAKE_VERSION;
}
char const* GitRevision::GetHostOSVersion()
{
return _CMAKE_HOST_SYSTEM;
}
char const* GitRevision::GetBuildDirectory()
{
return _BUILD_DIRECTORY;
}
char const* GitRevision::GetSourceDirectory()
{
return _SOURCE_DIRECTORY;
}
char const* GitRevision::GetMySQLExecutable()
{
return _MYSQL_EXECUTABLE;
}
char const* GitRevision::GetFullDatabase()
{
return _FULL_DATABASE;
}
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
# ifdef _WIN64
# define TRINITY_PLATFORM_STR "Win64"
# else
# define TRINITY_PLATFORM_STR "Win32"
# endif
#elif TRINITY_PLATFORM == TRINITY_PLATFORM_APPLE
# define TRINITY_PLATFORM_STR "MacOSX"
#elif TRINITY_PLATFORM == TRINITY_PLATFORM_INTEL
# define TRINITY_PLATFORM_STR "Intel"
#else // TRINITY_PLATFORM_UNIX
# define TRINITY_PLATFORM_STR "Unix"
#endif
#ifndef TRINITY_API_USE_DYNAMIC_LINKING
# define TRINITY_LINKAGE_TYPE_STR "Static"
#else
# define TRINITY_LINKAGE_TYPE_STR "Dynamic"
#endif
char const* GitRevision::GetFullVersion()
{
return "TrinityCore rev. " VER_PRODUCTVERSION_STR
" (" TRINITY_PLATFORM_STR ", " _BUILD_DIRECTIVE ", " TRINITY_LINKAGE_TYPE_STR ")";
}
char const* GitRevision::GetCompanyNameStr()
{
return VER_COMPANYNAME_STR;
}
char const* GitRevision::GetLegalCopyrightStr()
{
return VER_LEGALCOPYRIGHT_STR;
}
char const* GitRevision::GetFileVersionStr()
{
return VER_FILEVERSION_STR;
}
char const* GitRevision::GetProductVersionStr()
{
return VER_PRODUCTVERSION_STR;
}
| gpl-2.0 |
unakatsuo/qemu-kvm-0.12.1.2-2.355.0.1.el6_4.9.src | hw/e1000.c | 3 | 44347 | /*
* QEMU e1000 emulation
*
* Nir Peleg, Tutis Systems Ltd. for Qumranet Inc.
* Copyright (c) 2008 Qumranet
* Based on work done by:
* Copyright (c) 2007 Dan Aloni
* Copyright (c) 2004 Antony T Curtis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "hw.h"
#include "pci.h"
#include "net.h"
#include "net/checksum.h"
#include "loader.h"
#include "sysemu.h"
#include "e1000_hw.h"
#define DEBUG
#ifdef DEBUG
enum {
DEBUG_GENERAL, DEBUG_IO, DEBUG_MMIO, DEBUG_INTERRUPT,
DEBUG_RX, DEBUG_TX, DEBUG_MDIC, DEBUG_EEPROM,
DEBUG_UNKNOWN, DEBUG_TXSUM, DEBUG_TXERR, DEBUG_RXERR,
DEBUG_RXFILTER, DEBUG_PHY, DEBUG_NOTYET,
};
#define DBGBIT(x) (1<<DEBUG_##x)
static int debugflags = DBGBIT(TXERR) | DBGBIT(GENERAL);
#define DBGOUT(what, fmt, ...) do { \
if (debugflags & DBGBIT(what)) \
fprintf(stderr, "e1000: " fmt, ## __VA_ARGS__); \
} while (0)
#else
#define DBGOUT(what, fmt, ...) do {} while (0)
#endif
#define IOPORT_SIZE 0x40
#define PNPMMIO_SIZE 0x20000
#define MIN_BUF_SIZE 60 /* Min. octets in an ethernet frame sans FCS */
/* this is the size past which hardware will drop packets when setting LPE=0 */
#define MAXIMUM_ETHERNET_VLAN_SIZE 1522
/* this is the size past which hardware will drop packets when setting LPE=1 */
#define MAXIMUM_ETHERNET_LPE_SIZE 16384
/*
* HW models:
* E1000_DEV_ID_82540EM works with Windows and Linux
* E1000_DEV_ID_82573L OK with windoze and Linux 2.6.22,
* appears to perform better than 82540EM, but breaks with Linux 2.6.18
* E1000_DEV_ID_82544GC_COPPER appears to work; not well tested
* Others never tested
*/
enum { E1000_DEVID = E1000_DEV_ID_82540EM };
/*
* May need to specify additional MAC-to-PHY entries --
* Intel's Windows driver refuses to initialize unless they match
*/
enum {
PHY_ID2_INIT = E1000_DEVID == E1000_DEV_ID_82573L ? 0xcc2 :
E1000_DEVID == E1000_DEV_ID_82544GC_COPPER ? 0xc30 :
/* default to E1000_DEV_ID_82540EM */ 0xc20
};
typedef struct E1000State_st {
PCIDevice dev;
NICState *nic;
NICConf conf;
int mmio_index;
uint32_t mac_reg[0x8000];
uint16_t phy_reg[0x20];
uint16_t eeprom_data[64];
uint32_t rxbuf_size;
uint32_t rxbuf_min_shift;
int check_rxov;
struct e1000_tx {
unsigned char header[256];
unsigned char vlan_header[4];
/* Fields vlan and data must not be reordered or separated. */
unsigned char vlan[4];
unsigned char data[0x10000];
uint16_t size;
unsigned char sum_needed;
unsigned char vlan_needed;
uint8_t ipcss;
uint8_t ipcso;
uint16_t ipcse;
uint8_t tucss;
uint8_t tucso;
uint16_t tucse;
uint8_t hdr_len;
uint16_t mss;
uint32_t paylen;
uint16_t tso_frames;
char tse;
int8_t ip;
int8_t tcp;
char cptse; // current packet tse bit
} tx;
struct {
uint32_t val_in; // shifted in from guest driver
uint16_t bitnum_in;
uint16_t bitnum_out;
uint16_t reading;
uint32_t old_eecd;
} eecd_state;
QEMUTimer *autoneg_timer;
/* Enabled compatibility for migration to/from rhel6.3.0 and older */
#define E1000_FLAG_RHEL630_BIT 0
#define E1000_FLAG_RHEL630 (1 << E1000_FLAG_RHEL630_BIT)
uint32_t compat_flags;
} E1000State;
#define defreg(x) x = (E1000_##x>>2)
enum {
defreg(CTRL), defreg(EECD), defreg(EERD), defreg(GPRC),
defreg(GPTC), defreg(ICR), defreg(ICS), defreg(IMC),
defreg(IMS), defreg(LEDCTL), defreg(MANC), defreg(MDIC),
defreg(MPC), defreg(PBA), defreg(RCTL), defreg(RDBAH),
defreg(RDBAL), defreg(RDH), defreg(RDLEN), defreg(RDT),
defreg(STATUS), defreg(SWSM), defreg(TCTL), defreg(TDBAH),
defreg(TDBAL), defreg(TDH), defreg(TDLEN), defreg(TDT),
defreg(TORH), defreg(TORL), defreg(TOTH), defreg(TOTL),
defreg(TPR), defreg(TPT), defreg(TXDCTL), defreg(WUFC),
defreg(RA), defreg(MTA), defreg(CRCERRS),defreg(VFTA),
defreg(VET),
};
static void
e1000_link_down(E1000State *s)
{
s->mac_reg[STATUS] &= ~E1000_STATUS_LU;
s->phy_reg[PHY_STATUS] &= ~MII_SR_LINK_STATUS;
}
static void
e1000_link_up(E1000State *s)
{
s->mac_reg[STATUS] |= E1000_STATUS_LU;
s->phy_reg[PHY_STATUS] |= MII_SR_LINK_STATUS;
}
static void
set_phy_ctrl(E1000State *s, int index, uint16_t val)
{
/* RHEL 6.3 does not support link auto-negotiation emulation, so if we
* migrate during auto negotiation, after migration the link will be
* down. */
if (s->compat_flags & E1000_FLAG_RHEL630) {
return;
}
if ((val & MII_CR_AUTO_NEG_EN) && (val & MII_CR_RESTART_AUTO_NEG)) {
e1000_link_down(s);
s->phy_reg[PHY_STATUS] &= ~MII_SR_AUTONEG_COMPLETE;
DBGOUT(PHY, "Start link auto negotiation\n");
qemu_mod_timer(s->autoneg_timer, qemu_get_clock(vm_clock) + 500000000);
}
}
static void
e1000_autoneg_timer(void *opaque)
{
E1000State *s = opaque;
if (!s->nic->nc.link_down) {
e1000_link_up(s);
}
s->phy_reg[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE;
DBGOUT(PHY, "Auto negotiation is completed\n");
}
static void (*phyreg_writeops[])(E1000State *, int, uint16_t) = {
[PHY_CTRL] = set_phy_ctrl,
};
enum { NPHYWRITEOPS = ARRAY_SIZE(phyreg_writeops) };
enum { PHY_R = 1, PHY_W = 2, PHY_RW = PHY_R | PHY_W };
static const char phy_regcap[0x20] = {
[PHY_STATUS] = PHY_R, [M88E1000_EXT_PHY_SPEC_CTRL] = PHY_RW,
[PHY_ID1] = PHY_R, [M88E1000_PHY_SPEC_CTRL] = PHY_RW,
[PHY_CTRL] = PHY_RW, [PHY_1000T_CTRL] = PHY_RW,
[PHY_LP_ABILITY] = PHY_R, [PHY_1000T_STATUS] = PHY_R,
[PHY_AUTONEG_ADV] = PHY_RW, [M88E1000_RX_ERR_CNTR] = PHY_R,
[PHY_ID2] = PHY_R, [M88E1000_PHY_SPEC_STATUS] = PHY_R
};
static const uint16_t phy_reg_init[] = {
[PHY_CTRL] = 0x1140,
[PHY_STATUS] = 0x794d, /* link initially up with not completed autoneg */
[PHY_ID1] = 0x141, [PHY_ID2] = PHY_ID2_INIT,
[PHY_1000T_CTRL] = 0x0e00, [M88E1000_PHY_SPEC_CTRL] = 0x360,
[M88E1000_EXT_PHY_SPEC_CTRL] = 0x0d60, [PHY_AUTONEG_ADV] = 0xde1,
[PHY_LP_ABILITY] = 0x1e0, [PHY_1000T_STATUS] = 0x3c00,
[M88E1000_PHY_SPEC_STATUS] = 0xac00,
};
static const uint32_t mac_reg_init[] = {
[PBA] = 0x00100030,
[LEDCTL] = 0x602,
[CTRL] = E1000_CTRL_SWDPIN2 | E1000_CTRL_SWDPIN0 |
E1000_CTRL_SPD_1000 | E1000_CTRL_SLU,
[STATUS] = 0x80000000 | E1000_STATUS_GIO_MASTER_ENABLE |
E1000_STATUS_ASDV | E1000_STATUS_MTXCKOK |
E1000_STATUS_SPEED_1000 | E1000_STATUS_FD |
E1000_STATUS_LU,
[MANC] = E1000_MANC_EN_MNG2HOST | E1000_MANC_RCV_TCO_EN |
E1000_MANC_ARP_EN | E1000_MANC_0298_EN |
E1000_MANC_RMCP_EN,
};
static void
ioport_map(PCIDevice *pci_dev, int region_num, pcibus_t addr,
pcibus_t size, int type)
{
DBGOUT(IO, "e1000_ioport_map addr=0x%04"FMT_PCIBUS
" size=0x%08"FMT_PCIBUS"\n", addr, size);
}
static void
set_interrupt_cause(E1000State *s, int index, uint32_t val)
{
if (val)
val |= E1000_ICR_INT_ASSERTED;
s->mac_reg[ICR] = val;
s->mac_reg[ICS] = val;
qemu_set_irq(s->dev.irq[0], (s->mac_reg[IMS] & s->mac_reg[ICR]) != 0);
}
static void
set_ics(E1000State *s, int index, uint32_t val)
{
DBGOUT(INTERRUPT, "set_ics %x, ICR %x, IMR %x\n", val, s->mac_reg[ICR],
s->mac_reg[IMS]);
set_interrupt_cause(s, 0, val | s->mac_reg[ICR]);
}
static int
rxbufsize(uint32_t v)
{
v &= E1000_RCTL_BSEX | E1000_RCTL_SZ_16384 | E1000_RCTL_SZ_8192 |
E1000_RCTL_SZ_4096 | E1000_RCTL_SZ_2048 | E1000_RCTL_SZ_1024 |
E1000_RCTL_SZ_512 | E1000_RCTL_SZ_256;
switch (v) {
case E1000_RCTL_BSEX | E1000_RCTL_SZ_16384:
return 16384;
case E1000_RCTL_BSEX | E1000_RCTL_SZ_8192:
return 8192;
case E1000_RCTL_BSEX | E1000_RCTL_SZ_4096:
return 4096;
case E1000_RCTL_SZ_1024:
return 1024;
case E1000_RCTL_SZ_512:
return 512;
case E1000_RCTL_SZ_256:
return 256;
}
return 2048;
}
static void e1000_reset(void *opaque)
{
E1000State *d = opaque;
qemu_del_timer(d->autoneg_timer);
memset(d->phy_reg, 0, sizeof d->phy_reg);
memmove(d->phy_reg, phy_reg_init, sizeof phy_reg_init);
memset(d->mac_reg, 0, sizeof d->mac_reg);
memmove(d->mac_reg, mac_reg_init, sizeof mac_reg_init);
d->rxbuf_min_shift = 1;
memset(&d->tx, 0, sizeof d->tx);
if (d->nic->nc.link_down) {
e1000_link_down(d);
}
}
static void
set_ctrl(E1000State *s, int index, uint32_t val)
{
/* RST is self clearing */
s->mac_reg[CTRL] = val & ~E1000_CTRL_RST;
}
static void
set_rx_control(E1000State *s, int index, uint32_t val)
{
s->mac_reg[RCTL] = val;
s->rxbuf_size = rxbufsize(val);
s->rxbuf_min_shift = ((val / E1000_RCTL_RDMTS_QUAT) & 3) + 1;
DBGOUT(RX, "RCTL: %d, mac_reg[RCTL] = 0x%x\n", s->mac_reg[RDT],
s->mac_reg[RCTL]);
qemu_flush_queued_packets(&s->nic->nc);
}
static void
set_mdic(E1000State *s, int index, uint32_t val)
{
uint32_t data = val & E1000_MDIC_DATA_MASK;
uint32_t addr = ((val & E1000_MDIC_REG_MASK) >> E1000_MDIC_REG_SHIFT);
if ((val & E1000_MDIC_PHY_MASK) >> E1000_MDIC_PHY_SHIFT != 1) // phy #
val = s->mac_reg[MDIC] | E1000_MDIC_ERROR;
else if (val & E1000_MDIC_OP_READ) {
DBGOUT(MDIC, "MDIC read reg 0x%x\n", addr);
if (!(phy_regcap[addr] & PHY_R)) {
DBGOUT(MDIC, "MDIC read reg %x unhandled\n", addr);
val |= E1000_MDIC_ERROR;
} else
val = (val ^ data) | s->phy_reg[addr];
} else if (val & E1000_MDIC_OP_WRITE) {
DBGOUT(MDIC, "MDIC write reg 0x%x, value 0x%x\n", addr, data);
if (!(phy_regcap[addr] & PHY_W)) {
DBGOUT(MDIC, "MDIC write reg %x unhandled\n", addr);
val |= E1000_MDIC_ERROR;
} else {
if (addr < NPHYWRITEOPS && phyreg_writeops[addr]) {
phyreg_writeops[addr](s, index, data);
}
s->phy_reg[addr] = data;
}
}
s->mac_reg[MDIC] = val | E1000_MDIC_READY;
if (val & E1000_MDIC_INT_EN) {
set_ics(s, 0, E1000_ICR_MDAC);
}
}
static uint32_t
get_eecd(E1000State *s, int index)
{
uint32_t ret = E1000_EECD_PRES|E1000_EECD_GNT | s->eecd_state.old_eecd;
DBGOUT(EEPROM, "reading eeprom bit %d (reading %d)\n",
s->eecd_state.bitnum_out, s->eecd_state.reading);
if (!s->eecd_state.reading ||
((s->eeprom_data[(s->eecd_state.bitnum_out >> 4) & 0x3f] >>
((s->eecd_state.bitnum_out & 0xf) ^ 0xf))) & 1)
ret |= E1000_EECD_DO;
return ret;
}
static void
set_eecd(E1000State *s, int index, uint32_t val)
{
uint32_t oldval = s->eecd_state.old_eecd;
s->eecd_state.old_eecd = val & (E1000_EECD_SK | E1000_EECD_CS |
E1000_EECD_DI|E1000_EECD_FWE_MASK|E1000_EECD_REQ);
if (!(E1000_EECD_SK & (val ^ oldval))) // no clock edge
return;
if (!(E1000_EECD_SK & val)) { // falling edge
s->eecd_state.bitnum_out++;
return;
}
if (!(val & E1000_EECD_CS)) { // rising, no CS (EEPROM reset)
memset(&s->eecd_state, 0, sizeof s->eecd_state);
/*
* restore old_eecd's E1000_EECD_SK (known to be on)
* to avoid false detection of a clock edge
*/
s->eecd_state.old_eecd = E1000_EECD_SK;
return;
}
s->eecd_state.val_in <<= 1;
if (val & E1000_EECD_DI)
s->eecd_state.val_in |= 1;
if (++s->eecd_state.bitnum_in == 9 && !s->eecd_state.reading) {
s->eecd_state.bitnum_out = ((s->eecd_state.val_in & 0x3f)<<4)-1;
s->eecd_state.reading = (((s->eecd_state.val_in >> 6) & 7) ==
EEPROM_READ_OPCODE_MICROWIRE);
}
DBGOUT(EEPROM, "eeprom bitnum in %d out %d, reading %d\n",
s->eecd_state.bitnum_in, s->eecd_state.bitnum_out,
s->eecd_state.reading);
}
static uint32_t
flash_eerd_read(E1000State *s, int x)
{
unsigned int index, r = s->mac_reg[EERD] & ~E1000_EEPROM_RW_REG_START;
if ((s->mac_reg[EERD] & E1000_EEPROM_RW_REG_START) == 0)
return (s->mac_reg[EERD]);
if ((index = r >> E1000_EEPROM_RW_ADDR_SHIFT) > EEPROM_CHECKSUM_REG)
return (E1000_EEPROM_RW_REG_DONE | r);
return ((s->eeprom_data[index] << E1000_EEPROM_RW_REG_DATA) |
E1000_EEPROM_RW_REG_DONE | r);
}
static void
putsum(uint8_t *data, uint32_t n, uint32_t sloc, uint32_t css, uint32_t cse)
{
uint32_t sum;
if (cse && cse < n)
n = cse + 1;
if (sloc < n-1) {
sum = net_checksum_add(n-css, data+css);
cpu_to_be16wu((uint16_t *)(data + sloc),
net_checksum_finish(sum));
}
}
static inline int
vlan_enabled(E1000State *s)
{
return ((s->mac_reg[CTRL] & E1000_CTRL_VME) != 0);
}
static inline int
vlan_rx_filter_enabled(E1000State *s)
{
return ((s->mac_reg[RCTL] & E1000_RCTL_VFE) != 0);
}
static inline int
is_vlan_packet(E1000State *s, const uint8_t *buf)
{
return (be16_to_cpup((uint16_t *)(buf + 12)) ==
le16_to_cpup((uint16_t *)(s->mac_reg + VET)));
}
static inline int
is_vlan_txd(uint32_t txd_lower)
{
return ((txd_lower & E1000_TXD_CMD_VLE) != 0);
}
/* FCS aka Ethernet CRC-32. We don't get it from backends and can't
* fill it in, just pad descriptor length by 4 bytes unless guest
* told us to strip it off the packet. */
static inline int
fcs_len(E1000State *s)
{
return (s->mac_reg[RCTL] & E1000_RCTL_SECRC) ? 0 : 4;
}
static void
xmit_seg(E1000State *s)
{
uint16_t len, *sp;
unsigned int frames = s->tx.tso_frames, css, sofar, n;
struct e1000_tx *tp = &s->tx;
if (tp->tse && tp->cptse) {
css = tp->ipcss;
DBGOUT(TXSUM, "frames %d size %d ipcss %d\n",
frames, tp->size, css);
if (tp->ip) { // IPv4
cpu_to_be16wu((uint16_t *)(tp->data+css+2),
tp->size - css);
cpu_to_be16wu((uint16_t *)(tp->data+css+4),
be16_to_cpup((uint16_t *)(tp->data+css+4))+frames);
} else // IPv6
cpu_to_be16wu((uint16_t *)(tp->data+css+4),
tp->size - css);
css = tp->tucss;
len = tp->size - css;
DBGOUT(TXSUM, "tcp %d tucss %d len %d\n", tp->tcp, css, len);
if (tp->tcp) {
sofar = frames * tp->mss;
cpu_to_be32wu((uint32_t *)(tp->data+css+4), // seq
be32_to_cpupu((uint32_t *)(tp->data+css+4))+sofar);
if (tp->paylen - sofar > tp->mss)
tp->data[css + 13] &= ~9; // PSH, FIN
} else // UDP
cpu_to_be16wu((uint16_t *)(tp->data+css+4), len);
if (tp->sum_needed & E1000_TXD_POPTS_TXSM) {
unsigned int phsum;
// add pseudo-header length before checksum calculation
sp = (uint16_t *)(tp->data + tp->tucso);
phsum = be16_to_cpup(sp) + len;
phsum = (phsum >> 16) + (phsum & 0xffff);
cpu_to_be16wu(sp, phsum);
}
tp->tso_frames++;
}
if (tp->sum_needed & E1000_TXD_POPTS_TXSM)
putsum(tp->data, tp->size, tp->tucso, tp->tucss, tp->tucse);
if (tp->sum_needed & E1000_TXD_POPTS_IXSM)
putsum(tp->data, tp->size, tp->ipcso, tp->ipcss, tp->ipcse);
if (tp->vlan_needed) {
memmove(tp->vlan, tp->data, 4);
memmove(tp->data, tp->data + 4, 8);
memcpy(tp->data + 8, tp->vlan_header, 4);
qemu_send_packet(&s->nic->nc, tp->vlan, tp->size + 4);
} else
qemu_send_packet(&s->nic->nc, tp->data, tp->size);
s->mac_reg[TPT]++;
s->mac_reg[GPTC]++;
n = s->mac_reg[TOTL];
if ((s->mac_reg[TOTL] += s->tx.size) < n)
s->mac_reg[TOTH]++;
}
static void
process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
{
uint32_t txd_lower = le32_to_cpu(dp->lower.data);
uint32_t dtype = txd_lower & (E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D);
unsigned int split_size = txd_lower & 0xffff, bytes, sz, op;
unsigned int msh = 0xfffff, hdr = 0;
uint64_t addr;
struct e1000_context_desc *xp = (struct e1000_context_desc *)dp;
struct e1000_tx *tp = &s->tx;
if (dtype == E1000_TXD_CMD_DEXT) { // context descriptor
op = le32_to_cpu(xp->cmd_and_length);
tp->ipcss = xp->lower_setup.ip_fields.ipcss;
tp->ipcso = xp->lower_setup.ip_fields.ipcso;
tp->ipcse = le16_to_cpu(xp->lower_setup.ip_fields.ipcse);
tp->tucss = xp->upper_setup.tcp_fields.tucss;
tp->tucso = xp->upper_setup.tcp_fields.tucso;
tp->tucse = le16_to_cpu(xp->upper_setup.tcp_fields.tucse);
tp->paylen = op & 0xfffff;
tp->hdr_len = xp->tcp_seg_setup.fields.hdr_len;
tp->mss = le16_to_cpu(xp->tcp_seg_setup.fields.mss);
tp->ip = (op & E1000_TXD_CMD_IP) ? 1 : 0;
tp->tcp = (op & E1000_TXD_CMD_TCP) ? 1 : 0;
tp->tse = (op & E1000_TXD_CMD_TSE) ? 1 : 0;
tp->tso_frames = 0;
if (tp->tucso == 0) { // this is probably wrong
DBGOUT(TXSUM, "TCP/UDP: cso 0!\n");
tp->tucso = tp->tucss + (tp->tcp ? 16 : 6);
}
return;
} else if (dtype == (E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D)) {
// data descriptor
if (tp->size == 0) {
tp->sum_needed = le32_to_cpu(dp->upper.data) >> 8;
}
tp->cptse = ( txd_lower & E1000_TXD_CMD_TSE ) ? 1 : 0;
} else
// legacy descriptor
tp->cptse = 0;
if (vlan_enabled(s) && is_vlan_txd(txd_lower) &&
(tp->cptse || txd_lower & E1000_TXD_CMD_EOP)) {
tp->vlan_needed = 1;
cpu_to_be16wu((uint16_t *)(tp->vlan_header),
le16_to_cpup((uint16_t *)(s->mac_reg + VET)));
cpu_to_be16wu((uint16_t *)(tp->vlan_header + 2),
le16_to_cpu(dp->upper.fields.special));
}
addr = le64_to_cpu(dp->buffer_addr);
if (tp->tse && tp->cptse) {
hdr = tp->hdr_len;
msh = hdr + tp->mss;
do {
bytes = split_size;
if (tp->size + bytes > msh)
bytes = msh - tp->size;
bytes = MIN(sizeof(tp->data) - tp->size, bytes);
cpu_physical_memory_read(addr, tp->data + tp->size, bytes);
if ((sz = tp->size + bytes) >= hdr && tp->size < hdr)
memmove(tp->header, tp->data, hdr);
tp->size = sz;
addr += bytes;
if (sz == msh) {
xmit_seg(s);
memmove(tp->data, tp->header, hdr);
tp->size = hdr;
}
} while (split_size -= bytes);
} else if (!tp->tse && tp->cptse) {
// context descriptor TSE is not set, while data descriptor TSE is set
DBGOUT(TXERR, "TCP segmentaion Error\n");
} else {
split_size = MIN(sizeof(tp->data) - tp->size, split_size);
cpu_physical_memory_read(addr, tp->data + tp->size, split_size);
tp->size += split_size;
}
if (!(txd_lower & E1000_TXD_CMD_EOP))
return;
if (!(tp->tse && tp->cptse && tp->size < hdr))
xmit_seg(s);
tp->tso_frames = 0;
tp->sum_needed = 0;
tp->vlan_needed = 0;
tp->size = 0;
tp->cptse = 0;
}
static uint32_t
txdesc_writeback(target_phys_addr_t base, struct e1000_tx_desc *dp)
{
uint32_t txd_upper, txd_lower = le32_to_cpu(dp->lower.data);
if (!(txd_lower & (E1000_TXD_CMD_RS|E1000_TXD_CMD_RPS)))
return 0;
txd_upper = (le32_to_cpu(dp->upper.data) | E1000_TXD_STAT_DD) &
~(E1000_TXD_STAT_EC | E1000_TXD_STAT_LC | E1000_TXD_STAT_TU);
dp->upper.data = cpu_to_le32(txd_upper);
cpu_physical_memory_write(base + ((char *)&dp->upper - (char *)dp),
(void *)&dp->upper, sizeof(dp->upper));
return E1000_ICR_TXDW;
}
static void
start_xmit(E1000State *s)
{
target_phys_addr_t base;
struct e1000_tx_desc desc;
uint32_t tdh_start = s->mac_reg[TDH], cause = E1000_ICS_TXQE;
if (!(s->mac_reg[TCTL] & E1000_TCTL_EN)) {
DBGOUT(TX, "tx disabled\n");
return;
}
while (s->mac_reg[TDH] != s->mac_reg[TDT]) {
base = ((uint64_t)s->mac_reg[TDBAH] << 32) + s->mac_reg[TDBAL] +
sizeof(struct e1000_tx_desc) * s->mac_reg[TDH];
cpu_physical_memory_read(base, (void *)&desc, sizeof(desc));
DBGOUT(TX, "index %d: %p : %x %x\n", s->mac_reg[TDH],
(void *)(intptr_t)desc.buffer_addr, desc.lower.data,
desc.upper.data);
process_tx_desc(s, &desc);
cause |= txdesc_writeback(base, &desc);
if (++s->mac_reg[TDH] * sizeof(desc) >= s->mac_reg[TDLEN])
s->mac_reg[TDH] = 0;
/*
* the following could happen only if guest sw assigns
* bogus values to TDT/TDLEN.
* there's nothing too intelligent we could do about this.
*/
if (s->mac_reg[TDH] == tdh_start) {
DBGOUT(TXERR, "TDH wraparound @%x, TDT %x, TDLEN %x\n",
tdh_start, s->mac_reg[TDT], s->mac_reg[TDLEN]);
break;
}
}
set_ics(s, 0, cause);
}
static int
receive_filter(E1000State *s, const uint8_t *buf, int size)
{
static uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
static int mta_shift[] = {4, 3, 2, 0};
uint32_t f, rctl = s->mac_reg[RCTL], ra[2], *rp;
if (is_vlan_packet(s, buf) && vlan_rx_filter_enabled(s)) {
uint16_t vid = be16_to_cpup((uint16_t *)(buf + 14));
uint32_t vfta = le32_to_cpup((uint32_t *)(s->mac_reg + VFTA) +
((vid >> 5) & 0x7f));
if ((vfta & (1 << (vid & 0x1f))) == 0)
return 0;
}
if (rctl & E1000_RCTL_UPE) // promiscuous
return 1;
if ((buf[0] & 1) && (rctl & E1000_RCTL_MPE)) // promiscuous mcast
return 1;
if ((rctl & E1000_RCTL_BAM) && !memcmp(buf, bcast, sizeof bcast))
return 1;
for (rp = s->mac_reg + RA; rp < s->mac_reg + RA + 32; rp += 2) {
if (!(rp[1] & E1000_RAH_AV))
continue;
ra[0] = cpu_to_le32(rp[0]);
ra[1] = cpu_to_le32(rp[1]);
if (!memcmp(buf, (uint8_t *)ra, 6)) {
DBGOUT(RXFILTER,
"unicast match[%d]: %02x:%02x:%02x:%02x:%02x:%02x\n",
(int)(rp - s->mac_reg - RA)/2,
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
return 1;
}
}
DBGOUT(RXFILTER, "unicast mismatch: %02x:%02x:%02x:%02x:%02x:%02x\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
f = mta_shift[(rctl >> E1000_RCTL_MO_SHIFT) & 3];
f = (((buf[5] << 8) | buf[4]) >> f) & 0xfff;
if (s->mac_reg[MTA + (f >> 5)] & (1 << (f & 0x1f)))
return 1;
DBGOUT(RXFILTER,
"dropping, inexact filter mismatch: %02x:%02x:%02x:%02x:%02x:%02x MO %d MTA[%d] %x\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
(rctl >> E1000_RCTL_MO_SHIFT) & 3, f >> 5,
s->mac_reg[MTA + (f >> 5)]);
return 0;
}
static void
e1000_set_link_status(VLANClientState *nc)
{
E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
uint32_t old_status = s->mac_reg[STATUS];
if (nc->link_down) {
e1000_link_down(s);
} else {
e1000_link_up(s);
}
if (s->mac_reg[STATUS] != old_status)
set_ics(s, 0, E1000_ICR_LSC);
}
static bool e1000_has_rxbufs(E1000State *s, size_t total_size)
{
int bufs;
/* Fast-path short packets */
if (total_size <= s->rxbuf_size) {
return s->mac_reg[RDH] != s->mac_reg[RDT] || !s->check_rxov;
}
if (s->mac_reg[RDH] < s->mac_reg[RDT]) {
bufs = s->mac_reg[RDT] - s->mac_reg[RDH];
} else if (s->mac_reg[RDH] > s->mac_reg[RDT] || !s->check_rxov) {
bufs = s->mac_reg[RDLEN] / sizeof(struct e1000_rx_desc) +
s->mac_reg[RDT] - s->mac_reg[RDH];
} else {
return false;
}
return total_size <= bufs * s->rxbuf_size;
}
static int
e1000_can_receive(VLANClientState *nc)
{
E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
return (s->mac_reg[STATUS] & E1000_STATUS_LU) &&
(s->mac_reg[RCTL] & E1000_RCTL_EN) && e1000_has_rxbufs(s, 1);
}
static ssize_t
e1000_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
{
E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
struct e1000_rx_desc desc;
target_phys_addr_t base;
unsigned int n, rdt;
uint32_t rdh_start;
uint16_t vlan_special = 0;
uint8_t vlan_status = 0, vlan_offset = 0;
size_t desc_offset;
size_t desc_size;
uint8_t min_buf[MIN_BUF_SIZE];
if (!(s->mac_reg[STATUS] & E1000_STATUS_LU)) {
return -1;
}
if (!(s->mac_reg[RCTL] & E1000_RCTL_EN)) {
return -1;
}
/* Pad to minimum Ethernet frame length */
if (size < sizeof(min_buf)) {
memcpy(min_buf, buf, size);
memset(&min_buf[size], 0, sizeof(min_buf) - size);
buf = min_buf;
size = sizeof(min_buf);
}
/* Discard oversized packets if !LPE and !SBP. */
if ((size > MAXIMUM_ETHERNET_LPE_SIZE ||
(size > MAXIMUM_ETHERNET_VLAN_SIZE
&& !(s->mac_reg[RCTL] & E1000_RCTL_LPE)))
&& !(s->mac_reg[RCTL] & E1000_RCTL_SBP)) {
return size;
}
if (!receive_filter(s, buf, size))
return size;
if (vlan_enabled(s) && is_vlan_packet(s, buf)) {
vlan_special = cpu_to_le16(be16_to_cpup((uint16_t *)(buf + 14)));
memmove((void *)(buf + 4), buf, 12);
vlan_status = E1000_RXD_STAT_VP;
vlan_offset = 4;
size -= 4;
}
rdh_start = s->mac_reg[RDH];
size += fcs_len(s);
desc_offset = 0;
if (!e1000_has_rxbufs(s, size)) {
set_ics(s, 0, E1000_ICS_RXO);
return -1;
}
do {
desc_size = size - desc_offset;
if (desc_size > s->rxbuf_size) {
desc_size = s->rxbuf_size;
}
base = ((uint64_t)s->mac_reg[RDBAH] << 32) + s->mac_reg[RDBAL] +
sizeof(desc) * s->mac_reg[RDH];
cpu_physical_memory_read(base, (void *)&desc, sizeof(desc));
desc.special = vlan_special;
desc.status |= (vlan_status | E1000_RXD_STAT_DD);
if (desc.buffer_addr) {
cpu_physical_memory_write(le64_to_cpu(desc.buffer_addr),
(void *)(buf + desc_offset + vlan_offset),
desc_size);
desc_offset += desc_size;
desc.length = cpu_to_le16(desc_size);
if (desc_offset >= size) {
desc.status |= E1000_RXD_STAT_EOP | E1000_RXD_STAT_IXSM;
} else {
/* Guest zeroing out status is not a hardware requirement.
Clear EOP in case guest didn't do it. */
desc.status &= ~E1000_RXD_STAT_EOP;
}
} else // as per intel docs; skip descriptors with null buf addr
DBGOUT(RX, "Null RX descriptor!!\n");
cpu_physical_memory_write(base, (void *)&desc, sizeof(desc));
if (++s->mac_reg[RDH] * sizeof(desc) >= s->mac_reg[RDLEN])
s->mac_reg[RDH] = 0;
s->check_rxov = 1;
/* see comment in start_xmit; same here */
if (s->mac_reg[RDH] == rdh_start) {
DBGOUT(RXERR, "RDH wraparound @%x, RDT %x, RDLEN %x\n",
rdh_start, s->mac_reg[RDT], s->mac_reg[RDLEN]);
set_ics(s, 0, E1000_ICS_RXO);
return -1;
}
} while (desc_offset < size);
s->mac_reg[GPRC]++;
s->mac_reg[TPR]++;
n = s->mac_reg[TORL];
if ((s->mac_reg[TORL] += size) < n)
s->mac_reg[TORH]++;
n = E1000_ICS_RXT0;
if ((rdt = s->mac_reg[RDT]) < s->mac_reg[RDH])
rdt += s->mac_reg[RDLEN] / sizeof(desc);
if (((rdt - s->mac_reg[RDH]) * sizeof(desc)) <= s->mac_reg[RDLEN] >>
s->rxbuf_min_shift)
n |= E1000_ICS_RXDMT0;
set_ics(s, 0, n);
return size;
}
static uint32_t
mac_readreg(E1000State *s, int index)
{
return s->mac_reg[index];
}
static uint32_t
mac_icr_read(E1000State *s, int index)
{
uint32_t ret = s->mac_reg[ICR];
DBGOUT(INTERRUPT, "ICR read: %x\n", ret);
set_interrupt_cause(s, 0, 0);
return ret;
}
static uint32_t
mac_read_clr4(E1000State *s, int index)
{
uint32_t ret = s->mac_reg[index];
s->mac_reg[index] = 0;
return ret;
}
static uint32_t
mac_read_clr8(E1000State *s, int index)
{
uint32_t ret = s->mac_reg[index];
s->mac_reg[index] = 0;
s->mac_reg[index-1] = 0;
return ret;
}
static void
mac_writereg(E1000State *s, int index, uint32_t val)
{
s->mac_reg[index] = val;
}
static void
set_rdt(E1000State *s, int index, uint32_t val)
{
s->check_rxov = 0;
s->mac_reg[index] = val & 0xffff;
if (e1000_has_rxbufs(s, 1)) {
qemu_flush_queued_packets(&s->nic->nc);
}
}
static void
set_16bit(E1000State *s, int index, uint32_t val)
{
s->mac_reg[index] = val & 0xffff;
}
static void
set_dlen(E1000State *s, int index, uint32_t val)
{
s->mac_reg[index] = val & 0xfff80;
}
static void
set_tctl(E1000State *s, int index, uint32_t val)
{
s->mac_reg[index] = val;
s->mac_reg[TDT] &= 0xffff;
start_xmit(s);
}
static void
set_icr(E1000State *s, int index, uint32_t val)
{
DBGOUT(INTERRUPT, "set_icr %x\n", val);
set_interrupt_cause(s, 0, s->mac_reg[ICR] & ~val);
}
static void
set_imc(E1000State *s, int index, uint32_t val)
{
s->mac_reg[IMS] &= ~val;
set_ics(s, 0, 0);
}
static void
set_ims(E1000State *s, int index, uint32_t val)
{
s->mac_reg[IMS] |= val;
set_ics(s, 0, 0);
}
#define getreg(x) [x] = mac_readreg
static uint32_t (*macreg_readops[])(E1000State *, int) = {
getreg(PBA), getreg(RCTL), getreg(TDH), getreg(TXDCTL),
getreg(WUFC), getreg(TDT), getreg(CTRL), getreg(LEDCTL),
getreg(MANC), getreg(MDIC), getreg(SWSM), getreg(STATUS),
getreg(TORL), getreg(TOTL), getreg(IMS), getreg(TCTL),
getreg(RDH), getreg(RDT), getreg(VET), getreg(ICS),
getreg(TDBAL), getreg(TDBAH), getreg(RDBAH), getreg(RDBAL),
getreg(TDLEN), getreg(RDLEN),
[TOTH] = mac_read_clr8, [TORH] = mac_read_clr8, [GPRC] = mac_read_clr4,
[GPTC] = mac_read_clr4, [TPR] = mac_read_clr4, [TPT] = mac_read_clr4,
[ICR] = mac_icr_read, [EECD] = get_eecd, [EERD] = flash_eerd_read,
[CRCERRS ... MPC] = &mac_readreg,
[RA ... RA+31] = &mac_readreg,
[MTA ... MTA+127] = &mac_readreg,
[VFTA ... VFTA+127] = &mac_readreg,
};
enum { NREADOPS = ARRAY_SIZE(macreg_readops) };
#define putreg(x) [x] = mac_writereg
static void (*macreg_writeops[])(E1000State *, int, uint32_t) = {
putreg(PBA), putreg(EERD), putreg(SWSM), putreg(WUFC),
putreg(TDBAL), putreg(TDBAH), putreg(TXDCTL), putreg(RDBAH),
putreg(RDBAL), putreg(LEDCTL), putreg(VET),
[TDLEN] = set_dlen, [RDLEN] = set_dlen, [TCTL] = set_tctl,
[TDT] = set_tctl, [MDIC] = set_mdic, [ICS] = set_ics,
[TDH] = set_16bit, [RDH] = set_16bit, [RDT] = set_rdt,
[IMC] = set_imc, [IMS] = set_ims, [ICR] = set_icr,
[EECD] = set_eecd, [RCTL] = set_rx_control, [CTRL] = set_ctrl,
[RA ... RA+31] = &mac_writereg,
[MTA ... MTA+127] = &mac_writereg,
[VFTA ... VFTA+127] = &mac_writereg,
};
enum { NWRITEOPS = ARRAY_SIZE(macreg_writeops) };
static void
e1000_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
{
E1000State *s = opaque;
unsigned int index = (addr & 0x1ffff) >> 2;
#ifdef TARGET_WORDS_BIGENDIAN
val = bswap32(val);
#endif
if (index < NWRITEOPS && macreg_writeops[index])
macreg_writeops[index](s, index, val);
else if (index < NREADOPS && macreg_readops[index])
DBGOUT(MMIO, "e1000_mmio_writel RO %x: 0x%04x\n", index<<2, val);
else
DBGOUT(UNKNOWN, "MMIO unknown write addr=0x%08x,val=0x%08x\n",
index<<2, val);
}
static void
e1000_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
{
// emulate hw without byte enables: no RMW
e1000_mmio_writel(opaque, addr & ~3,
(val & 0xffff) << (8*(addr & 3)));
}
static void
e1000_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
{
// emulate hw without byte enables: no RMW
e1000_mmio_writel(opaque, addr & ~3,
(val & 0xff) << (8*(addr & 3)));
}
static uint32_t
e1000_mmio_readl(void *opaque, target_phys_addr_t addr)
{
E1000State *s = opaque;
unsigned int index = (addr & 0x1ffff) >> 2;
if (index < NREADOPS && macreg_readops[index])
{
uint32_t val = macreg_readops[index](s, index);
#ifdef TARGET_WORDS_BIGENDIAN
val = bswap32(val);
#endif
return val;
}
DBGOUT(UNKNOWN, "MMIO unknown read addr=0x%08x\n", index<<2);
return 0;
}
static uint32_t
e1000_mmio_readb(void *opaque, target_phys_addr_t addr)
{
return ((e1000_mmio_readl(opaque, addr & ~3)) >>
(8 * (addr & 3))) & 0xff;
}
static uint32_t
e1000_mmio_readw(void *opaque, target_phys_addr_t addr)
{
return ((e1000_mmio_readl(opaque, addr & ~3)) >>
(8 * (addr & 3))) & 0xffff;
}
static bool is_version_1(void *opaque, int version_id)
{
return version_id == 1;
}
static void e1000_pre_save(void *opaque)
{
E1000State *s = opaque;
if (s->compat_flags & E1000_FLAG_RHEL630) {
return;
}
/*
* If link is down and auto-negotiation is ongoing, complete
* auto-negotiation immediately. This allows is to look at
* MII_SR_AUTONEG_COMPLETE to infer link status on load.
*/
if (s->nic->nc.link_down &&
s->phy_reg[PHY_CTRL] & MII_CR_AUTO_NEG_EN &&
s->phy_reg[PHY_CTRL] & MII_CR_RESTART_AUTO_NEG) {
s->phy_reg[PHY_STATUS] |= MII_SR_AUTONEG_COMPLETE;
}
}
static int e1000_post_load(void *opaque, int version_id)
{
E1000State *s = opaque;
/* nc.link_down can't be migrated, so infer link_down according
* to link status bit in mac_reg[STATUS].
* Alternatively, restart link negotiation if it was in progress. */
s->nic->nc.link_down = (s->mac_reg[STATUS] & E1000_STATUS_LU) == 0;
if (s->compat_flags & E1000_FLAG_RHEL630) {
return 0;
}
if (s->phy_reg[PHY_CTRL] & MII_CR_AUTO_NEG_EN &&
s->phy_reg[PHY_CTRL] & MII_CR_RESTART_AUTO_NEG &&
!(s->phy_reg[PHY_STATUS] & MII_SR_AUTONEG_COMPLETE)) {
s->nic->nc.link_down = false;
qemu_mod_timer(s->autoneg_timer, qemu_get_clock(vm_clock) + 500000000);
}
return 0;
}
static const VMStateDescription vmstate_e1000 = {
.name = "e1000",
.version_id = 2,
.minimum_version_id = 1,
.minimum_version_id_old = 1,
.pre_save = e1000_pre_save,
.post_load = e1000_post_load,
.fields = (VMStateField []) {
VMSTATE_PCI_DEVICE(dev, E1000State),
VMSTATE_UNUSED_TEST(is_version_1, 4), /* was instance id */
VMSTATE_UNUSED(4), /* Was mmio_base. */
VMSTATE_UINT32(rxbuf_size, E1000State),
VMSTATE_UINT32(rxbuf_min_shift, E1000State),
VMSTATE_UINT32(eecd_state.val_in, E1000State),
VMSTATE_UINT16(eecd_state.bitnum_in, E1000State),
VMSTATE_UINT16(eecd_state.bitnum_out, E1000State),
VMSTATE_UINT16(eecd_state.reading, E1000State),
VMSTATE_UINT32(eecd_state.old_eecd, E1000State),
VMSTATE_UINT8(tx.ipcss, E1000State),
VMSTATE_UINT8(tx.ipcso, E1000State),
VMSTATE_UINT16(tx.ipcse, E1000State),
VMSTATE_UINT8(tx.tucss, E1000State),
VMSTATE_UINT8(tx.tucso, E1000State),
VMSTATE_UINT16(tx.tucse, E1000State),
VMSTATE_UINT32(tx.paylen, E1000State),
VMSTATE_UINT8(tx.hdr_len, E1000State),
VMSTATE_UINT16(tx.mss, E1000State),
VMSTATE_UINT16(tx.size, E1000State),
VMSTATE_UINT16(tx.tso_frames, E1000State),
VMSTATE_UINT8(tx.sum_needed, E1000State),
VMSTATE_INT8(tx.ip, E1000State),
VMSTATE_INT8(tx.tcp, E1000State),
VMSTATE_BUFFER(tx.header, E1000State),
VMSTATE_BUFFER(tx.data, E1000State),
VMSTATE_UINT16_ARRAY(eeprom_data, E1000State, 64),
VMSTATE_UINT16_ARRAY(phy_reg, E1000State, 0x20),
VMSTATE_UINT32(mac_reg[CTRL], E1000State),
VMSTATE_UINT32(mac_reg[EECD], E1000State),
VMSTATE_UINT32(mac_reg[EERD], E1000State),
VMSTATE_UINT32(mac_reg[GPRC], E1000State),
VMSTATE_UINT32(mac_reg[GPTC], E1000State),
VMSTATE_UINT32(mac_reg[ICR], E1000State),
VMSTATE_UINT32(mac_reg[ICS], E1000State),
VMSTATE_UINT32(mac_reg[IMC], E1000State),
VMSTATE_UINT32(mac_reg[IMS], E1000State),
VMSTATE_UINT32(mac_reg[LEDCTL], E1000State),
VMSTATE_UINT32(mac_reg[MANC], E1000State),
VMSTATE_UINT32(mac_reg[MDIC], E1000State),
VMSTATE_UINT32(mac_reg[MPC], E1000State),
VMSTATE_UINT32(mac_reg[PBA], E1000State),
VMSTATE_UINT32(mac_reg[RCTL], E1000State),
VMSTATE_UINT32(mac_reg[RDBAH], E1000State),
VMSTATE_UINT32(mac_reg[RDBAL], E1000State),
VMSTATE_UINT32(mac_reg[RDH], E1000State),
VMSTATE_UINT32(mac_reg[RDLEN], E1000State),
VMSTATE_UINT32(mac_reg[RDT], E1000State),
VMSTATE_UINT32(mac_reg[STATUS], E1000State),
VMSTATE_UINT32(mac_reg[SWSM], E1000State),
VMSTATE_UINT32(mac_reg[TCTL], E1000State),
VMSTATE_UINT32(mac_reg[TDBAH], E1000State),
VMSTATE_UINT32(mac_reg[TDBAL], E1000State),
VMSTATE_UINT32(mac_reg[TDH], E1000State),
VMSTATE_UINT32(mac_reg[TDLEN], E1000State),
VMSTATE_UINT32(mac_reg[TDT], E1000State),
VMSTATE_UINT32(mac_reg[TORH], E1000State),
VMSTATE_UINT32(mac_reg[TORL], E1000State),
VMSTATE_UINT32(mac_reg[TOTH], E1000State),
VMSTATE_UINT32(mac_reg[TOTL], E1000State),
VMSTATE_UINT32(mac_reg[TPR], E1000State),
VMSTATE_UINT32(mac_reg[TPT], E1000State),
VMSTATE_UINT32(mac_reg[TXDCTL], E1000State),
VMSTATE_UINT32(mac_reg[WUFC], E1000State),
VMSTATE_UINT32(mac_reg[VET], E1000State),
VMSTATE_UINT32_SUB_ARRAY(mac_reg, E1000State, RA, 32),
VMSTATE_UINT32_SUB_ARRAY(mac_reg, E1000State, MTA, 128),
VMSTATE_UINT32_SUB_ARRAY(mac_reg, E1000State, VFTA, 128),
VMSTATE_END_OF_LIST()
}
};
static const uint16_t e1000_eeprom_template[64] = {
0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0x0000, 0x0000, 0x0000,
0x3000, 0x1000, 0x6403, E1000_DEVID, 0x8086, E1000_DEVID, 0x8086, 0x3040,
0x0008, 0x2000, 0x7e14, 0x0048, 0x1000, 0x00d8, 0x0000, 0x2700,
0x6cc9, 0x3150, 0x0722, 0x040b, 0x0984, 0x0000, 0xc000, 0x0706,
0x1008, 0x0000, 0x0f04, 0x7fff, 0x4d01, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0x0100, 0x4000, 0x121c, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000,
};
/* PCI interface */
static CPUWriteMemoryFunc * const e1000_mmio_write[] = {
e1000_mmio_writeb, e1000_mmio_writew, e1000_mmio_writel
};
static CPUReadMemoryFunc * const e1000_mmio_read[] = {
e1000_mmio_readb, e1000_mmio_readw, e1000_mmio_readl
};
static void
e1000_mmio_map(PCIDevice *pci_dev, int region_num,
pcibus_t addr, pcibus_t size, int type)
{
E1000State *d = DO_UPCAST(E1000State, dev, pci_dev);
int i;
const uint32_t excluded_regs[] = {
E1000_MDIC, E1000_ICR, E1000_ICS, E1000_IMS,
E1000_IMC, E1000_TCTL, E1000_TDT, PNPMMIO_SIZE
};
DBGOUT(MMIO, "e1000_mmio_map addr=0x%08"FMT_PCIBUS" 0x%08"FMT_PCIBUS"\n",
addr, size);
cpu_register_physical_memory(addr, PNPMMIO_SIZE, d->mmio_index);
qemu_register_coalesced_mmio(addr, excluded_regs[0]);
for (i = 0; excluded_regs[i] != PNPMMIO_SIZE; i++)
qemu_register_coalesced_mmio(addr + excluded_regs[i] + 4,
excluded_regs[i + 1] -
excluded_regs[i] - 4);
}
static void
e1000_cleanup(VLANClientState *nc)
{
E1000State *s = DO_UPCAST(NICState, nc, nc)->opaque;
s->nic = NULL;
}
static int
pci_e1000_uninit(PCIDevice *dev)
{
E1000State *d = DO_UPCAST(E1000State, dev, dev);
cpu_unregister_io_memory(d->mmio_index);
qemu_del_timer(d->autoneg_timer);
qemu_free_timer(d->autoneg_timer);
qemu_del_vlan_client(&d->nic->nc);
return 0;
}
static NetClientInfo net_e1000_info = {
.type = NET_CLIENT_TYPE_NIC,
.size = sizeof(NICState),
.can_receive = e1000_can_receive,
.receive = e1000_receive,
.cleanup = e1000_cleanup,
.link_status_changed = e1000_set_link_status,
};
static int pci_e1000_init(PCIDevice *pci_dev)
{
E1000State *d = DO_UPCAST(E1000State, dev, pci_dev);
uint8_t *pci_conf;
uint16_t checksum = 0;
int i;
uint8_t *macaddr;
pci_conf = d->dev.config;
pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
pci_config_set_device_id(pci_conf, E1000_DEVID);
if (d->compat_flags & E1000_FLAG_RHEL630) {
/*
* We have no capabilities, so capability list bit should normally be 0.
* Keep it on for compat machine types to avoid breaking migration.
*/
pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_CAP_LIST);
}
pci_conf[PCI_REVISION_ID] = 0x03;
pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
/* TODO: RST# value should be 0, PCI spec 6.2.4 */
pci_conf[PCI_CACHE_LINE_SIZE] = 0x10;
pci_conf[PCI_INTERRUPT_PIN] = 1; /* interrupt pin A */
d->mmio_index = cpu_register_io_memory(e1000_mmio_read,
e1000_mmio_write, d);
pci_register_bar((PCIDevice *)d, 0, PNPMMIO_SIZE,
PCI_BASE_ADDRESS_SPACE_MEMORY, e1000_mmio_map);
pci_register_bar((PCIDevice *)d, 1, IOPORT_SIZE,
PCI_BASE_ADDRESS_SPACE_IO, ioport_map);
memmove(d->eeprom_data, e1000_eeprom_template,
sizeof e1000_eeprom_template);
qemu_macaddr_default_if_unset(&d->conf.macaddr);
macaddr = d->conf.macaddr.a;
for (i = 0; i < 3; i++)
d->eeprom_data[i] = (macaddr[2*i+1]<<8) | macaddr[2*i];
for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
checksum += d->eeprom_data[i];
checksum = (uint16_t) EEPROM_SUM - checksum;
d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
d->dev.qdev.info->name, d->dev.qdev.id, d);
qemu_format_nic_info_str(&d->nic->nc, macaddr);
add_boot_device_path(d->conf.bootindex, &pci_dev->qdev, "/ethernet-phy@0");
d->autoneg_timer = qemu_new_timer(vm_clock, e1000_autoneg_timer, d);
return 0;
}
static void qdev_e1000_reset(DeviceState *dev)
{
E1000State *d = DO_UPCAST(E1000State, dev.qdev, dev);
e1000_reset(d);
}
static PCIDeviceInfo e1000_info = {
.qdev.name = "e1000",
.qdev.desc = "Intel Gigabit Ethernet",
.qdev.size = sizeof(E1000State),
.qdev.reset = qdev_e1000_reset,
.qdev.vmsd = &vmstate_e1000,
.init = pci_e1000_init,
.exit = pci_e1000_uninit,
.romfile = "pxe-e1000.bin",
.qdev.props = (Property[]) {
DEFINE_NIC_PROPERTIES(E1000State, conf),
DEFINE_PROP_BIT("x-__com_redhat_rhel630_compat", E1000State,
compat_flags, E1000_FLAG_RHEL630_BIT, false),
DEFINE_PROP_END_OF_LIST(),
}
};
static void e1000_register_devices(void)
{
pci_qdev_register(&e1000_info);
}
device_init(e1000_register_devices)
| gpl-2.0 |
Mic92/systemd | src/resolve/test-resolve-tables.c | 3 | 2609 | /* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd
Copyright 2013 Zbigniew Jędrzejewski-Szmek
systemd is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "dns-type.h"
#include "test-tables.h"
int main(int argc, char **argv) {
uint16_t i;
test_table_sparse(dns_type, DNS_TYPE);
log_info("/* DNS_TYPE */");
for (i = 0; i < _DNS_TYPE_MAX; i++) {
const char *s;
s = dns_type_to_string(i);
assert_se(s == NULL || strlen(s) < _DNS_TYPE_STRING_MAX);
if (s)
log_info("%-*s %s%s%s%s%s%s%s%s%s",
(int) _DNS_TYPE_STRING_MAX - 1, s,
dns_type_is_pseudo(i) ? "pseudo " : "",
dns_type_is_valid_query(i) ? "valid_query " : "",
dns_type_is_valid_rr(i) ? "is_valid_rr " : "",
dns_type_may_redirect(i) ? "may_redirect " : "",
dns_type_is_dnssec(i) ? "dnssec " : "",
dns_type_is_obsolete(i) ? "obsolete " : "",
dns_type_may_wildcard(i) ? "wildcard " : "",
dns_type_apex_only(i) ? "apex_only " : "",
dns_type_needs_authentication(i) ? "needs_authentication" : "");
}
log_info("/* DNS_CLASS */");
for (i = 0; i < _DNS_CLASS_MAX; i++) {
const char *s;
s = dns_class_to_string(i);
assert_se(s == NULL || strlen(s) < _DNS_CLASS_STRING_MAX);
if (s)
log_info("%-*s %s%s",
(int) _DNS_CLASS_STRING_MAX - 1, s,
dns_class_is_pseudo(i) ? "is_pseudo " : "",
dns_class_is_valid_rr(i) ? "is_valid_rr " : "");
}
return EXIT_SUCCESS;
}
| gpl-2.0 |
pevik/ltp | testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_getprioceiling/3-1.c | 3 | 1738 | /*
* Copyright (c) 2010, Ngie Cooper.
*
* Test that pthread_mutex_getprioceiling() fails because:
*
* [EINVAL]
* The protocol attribute of mutex is PTHREAD_PRIO_NONE.
*
* by not specifying PTHREAD_PRIO_NONE and noting that the default (as per
* pthread_mutexattr_getprotocol) is PTHREAD_PRIO_NONE.
*
* Steps:
* 1. Initialize a mutex via pthread_mutex_init.
* 2. Do not modify the mutex.
* 3. Call pthread_mutex_getprioceiling() to obtain the prioceiling.
*
*/
#include <pthread.h>
#include <errno.h>
#include <sched.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "posixtest.h"
int main(void)
{
#if defined(_SC_PRIORITY_SCHEDULING)
if (sysconf(_SC_PRIORITY_SCHEDULING) == -1) {
printf("PRIORITY_SCHEDULING not supported\n");
return PTS_UNSUPPORTED;
}
pthread_mutex_t mutex;
int error, prioceiling;
/*
* The default protocol is PTHREAD_PRIO_NONE according to
* pthread_mutexattr_getprotocol.
*/
/* Initialize a mutex object */
error = pthread_mutex_init(&mutex, NULL);
if (error) {
printf("pthread_mutex_init failed: %s\n", strerror(error));
return PTS_UNRESOLVED;
}
/* Get the prioceiling of the mutex. */
error = pthread_mutex_getprioceiling(&mutex, &prioceiling);
if (error) {
if (error == EINVAL) {
printf("pthread_mutex_getprioceiling failed as "
"expected\n");
} else {
printf("pthread_mutex_getprioceiling did not fail as "
"expected: %s\n", strerror(error));
}
} else
printf("pthread_mutex_getprioceiling passed unexpectedly\n");
(void)pthread_mutex_destroy(&mutex);
return (error == EINVAL ? PTS_PASS : PTS_FAIL);
#else
printf("pthread_mutex_getprioceiling not supported\n");
return PTS_UNSUPPORTED;
#endif
}
| gpl-2.0 |
NieNs/IM-A840S-kernel | sound/soc/msm/msm-dai-q6-hdmi.c | 3 | 7722 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/mfd/wcd9310/core.h>
#include <linux/bitops.h>
#include <linux/slab.h>
#include <linux/clk.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/soc.h>
#include <sound/apr_audio.h>
#include <sound/q6afe.h>
#include <sound/q6adm.h>
#include <sound/msm-dai-q6.h>
#include <mach/clk.h>
#include <mach/msm_hdmi_audio.h>
enum {
STATUS_PORT_STARTED, /* track if AFE port has started */
STATUS_MAX
};
struct msm_dai_q6_hdmi_dai_data {
DECLARE_BITMAP(status_mask, STATUS_MAX);
u32 rate;
u32 channels;
union afe_port_config port_config;
};
/* Current implementation assumes hw_param is called once
* This may not be the case but what to do when ADM and AFE
* port are already opened and parameter changes
*/
static int msm_dai_q6_hdmi_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
struct msm_dai_q6_hdmi_dai_data *dai_data = dev_get_drvdata(dai->dev);
u32 channel_allocation = 0;
#ifdef CONFIG_FB_MSM_HDMI_COMMON /*yjw*/
u32 level_shift = 0; /* 0dB */
bool down_mix = FALSE;
#endif
dai_data->channels = params_channels(params);
dai_data->rate = params_rate(params);
dai_data->port_config.hdmi_multi_ch.data_type = 0;
dai_data->port_config.hdmi_multi_ch.reserved = 0;
switch (dai_data->channels) {
case 2:
channel_allocation = 0;
#ifdef CONFIG_FB_MSM_HDMI_COMMON /*yjw*/
hdmi_msm_audio_info_setup(1, MSM_HDMI_AUDIO_CHANNEL_2,
channel_allocation, level_shift, down_mix);
#endif
dai_data->port_config.hdmi_multi_ch.channel_allocation =
channel_allocation;
break;
case 6:
channel_allocation = 0x0B;
#ifdef CONFIG_FB_MSM_HDMI_COMMON /*yjw*/
hdmi_msm_audio_info_setup(1, MSM_HDMI_AUDIO_CHANNEL_6,
channel_allocation, level_shift, down_mix);
#endif
dai_data->port_config.hdmi_multi_ch.channel_allocation =
channel_allocation;
break;
default:
dev_err(dai->dev, "invalid Channels = %u\n",
dai_data->channels);
return -EINVAL;
}
dev_dbg(dai->dev, "%s() num_ch = %u rate =%u"
" channel_allocation = %u\n", __func__, dai_data->channels,
dai_data->rate,
dai_data->port_config.hdmi_multi_ch.channel_allocation);
return 0;
}
static void msm_dai_q6_hdmi_shutdown(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct msm_dai_q6_hdmi_dai_data *dai_data = dev_get_drvdata(dai->dev);
int rc = 0;
if (!test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
pr_info("%s: afe port not started. dai_data->status_mask"
" = %ld\n", __func__, *dai_data->status_mask);
return;
}
rc = afe_close(dai->id); /* can block */
if (IS_ERR_VALUE(rc))
dev_err(dai->dev, "fail to close AFE port\n");
pr_debug("%s: dai_data->status_mask = %ld\n", __func__,
*dai_data->status_mask);
clear_bit(STATUS_PORT_STARTED, dai_data->status_mask);
}
static int msm_dai_q6_hdmi_prepare(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct msm_dai_q6_hdmi_dai_data *dai_data = dev_get_drvdata(dai->dev);
int rc = 0;
if (!test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
/* PORT START should be set if prepare called in active state */
rc = afe_q6_interface_prepare();
if (IS_ERR_VALUE(rc))
dev_err(dai->dev, "fail to open AFE APR\n");
}
return rc;
}
static int msm_dai_q6_hdmi_trigger(struct snd_pcm_substream *substream, int cmd,
struct snd_soc_dai *dai)
{
struct msm_dai_q6_hdmi_dai_data *dai_data = dev_get_drvdata(dai->dev);
/* Start/stop port without waiting for Q6 AFE response. Need to have
* native q6 AFE driver propagates AFE response in order to handle
* port start/stop command error properly if error does arise.
*/
pr_debug("%s:port:%d cmd:%d dai_data->status_mask = %ld",
__func__, dai->id, cmd, *dai_data->status_mask);
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
if (!test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
afe_port_start_nowait(dai->id, &dai_data->port_config,
dai_data->rate);
set_bit(STATUS_PORT_STARTED, dai_data->status_mask);
}
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
if (test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
afe_port_stop_nowait(dai->id);
clear_bit(STATUS_PORT_STARTED, dai_data->status_mask);
}
break;
default:
dev_err(dai->dev, "invalid Trigger command = %d\n", cmd);
return -EINVAL;
}
return 0;
}
static int msm_dai_q6_hdmi_dai_probe(struct snd_soc_dai *dai)
{
struct msm_dai_q6_hdmi_dai_data *dai_data;
int rc = 0;
dai_data = kzalloc(sizeof(struct msm_dai_q6_hdmi_dai_data),
GFP_KERNEL);
if (!dai_data) {
dev_err(dai->dev, "DAI-%d: fail to allocate dai data\n",
dai->id);
rc = -ENOMEM;
} else
dev_set_drvdata(dai->dev, dai_data);
return rc;
}
static int msm_dai_q6_hdmi_dai_remove(struct snd_soc_dai *dai)
{
struct msm_dai_q6_hdmi_dai_data *dai_data;
int rc;
dai_data = dev_get_drvdata(dai->dev);
/* If AFE port is still up, close it */
if (test_bit(STATUS_PORT_STARTED, dai_data->status_mask)) {
rc = afe_close(dai->id); /* can block */
if (IS_ERR_VALUE(rc))
dev_err(dai->dev, "fail to close AFE port\n");
clear_bit(STATUS_PORT_STARTED, dai_data->status_mask);
}
kfree(dai_data);
snd_soc_unregister_dai(dai->dev);
return 0;
}
static struct snd_soc_dai_ops msm_dai_q6_hdmi_ops = {
.prepare = msm_dai_q6_hdmi_prepare,
.trigger = msm_dai_q6_hdmi_trigger,
.hw_params = msm_dai_q6_hdmi_hw_params,
.shutdown = msm_dai_q6_hdmi_shutdown,
};
static struct snd_soc_dai_driver msm_dai_q6_hdmi_hdmi_rx_dai = {
.playback = {
.rates = SNDRV_PCM_RATE_48000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
.channels_min = 2,
.channels_max = 6,
.rate_max = 48000,
.rate_min = 48000,
},
.ops = &msm_dai_q6_hdmi_ops,
.probe = msm_dai_q6_hdmi_dai_probe,
.remove = msm_dai_q6_hdmi_dai_remove,
};
/* To do: change to register DAIs as batch */
static __devinit int msm_dai_q6_hdmi_dev_probe(struct platform_device *pdev)
{
int rc = 0;
dev_dbg(&pdev->dev, "dev name %s dev-id %d\n",
dev_name(&pdev->dev), pdev->id);
switch (pdev->id) {
case HDMI_RX:
rc = snd_soc_register_dai(&pdev->dev,
&msm_dai_q6_hdmi_hdmi_rx_dai);
break;
default:
dev_err(&pdev->dev, "invalid device ID %d\n", pdev->id);
rc = -ENODEV;
break;
}
return rc;
}
static __devexit int msm_dai_q6_hdmi_dev_remove(struct platform_device *pdev)
{
snd_soc_unregister_dai(&pdev->dev);
return 0;
}
static struct platform_driver msm_dai_q6_hdmi_driver = {
.probe = msm_dai_q6_hdmi_dev_probe,
.remove = msm_dai_q6_hdmi_dev_remove,
.driver = {
.name = "msm-dai-q6-hdmi",
.owner = THIS_MODULE,
},
};
static int __init msm_dai_q6_hdmi_init(void)
{
return platform_driver_register(&msm_dai_q6_hdmi_driver);
}
module_init(msm_dai_q6_hdmi_init);
static void __exit msm_dai_q6_hdmi_exit(void)
{
platform_driver_unregister(&msm_dai_q6_hdmi_driver);
}
module_exit(msm_dai_q6_hdmi_exit);
/* Module information */
MODULE_DESCRIPTION("MSM DSP HDMI DAI driver");
MODULE_LICENSE("GPL v2");
| gpl-2.0 |
engine95/navel-855 | drivers/char/diag/diagchar_mts.c | 259 | 11413 | /* Copyright (c) 2008-2012, Code Aurora Forum. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/uaccess.h>
#include <linux/diagchar.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/completion.h>
#ifdef CONFIG_DIAG_OVER_USB
#include <mach/usbdiag.h>
#endif
#include <asm/current.h>
#include "diagchar_hdlc.h"
#include "diagmem.h"
#include "diagchar.h"
#include "diagfwd.h"
#include "diagfwd_cntl.h"
#include "diag_dci.h"
#include <linux/timer.h>
#include "diag_debugfs.h"
#include "diag_masks.h"
#include "diagfwd_bridge.h"
MODULE_DESCRIPTION("Diag Char Driver for MTS");
MODULE_LICENSE("GPL v2");
/* Identifier for data from MDM */
#define MDM_TOKEN -1
#define BUSY_CHECK_COUNT 5
#define BUSY_WAITING_TIME_US (100 * 1000)
static int mts_mdlog_start;
DECLARE_COMPLETION(mts_read_completion);
static int mts_read_waiting;
struct smd_info_busy {
int in_busy_1;
int in_busy_2;
};
struct smd_info_busy smd_busy[NUM_SMD_DATA_CHANNELS];
#define COPY_USER_SPACE_OR_EXIT(buf, data, length) \
do { \
if ((count < ret+length) || (copy_to_user(buf, \
(void *)&data, length))) { \
ret = -EFAULT; \
goto exit; \
} \
ret += length; \
} while (0)
dev_t dev;
struct cdev *cdev_mts;
struct class *diagchar_mts_class;
extern struct diagchar_dev *driver;
static int diagchar_mts_open(struct inode *inode, struct file *file)
{
pr_info("diagchar_mts_open\n");
return 0;
}
static int diagchar_mts_close(struct inode *inode, struct file *file)
{
pr_info("diagchar_mts_close\n");
return 0;
}
long diagchar_mts_ioctl(struct file *filp,
unsigned int iocmd, unsigned long ioarg)
{
int success = 0;
if (iocmd == DIAG_IOCTL_SWITCH_LOGGING) {
if ((int)ioarg == MEMORY_DEVICE_MODE) {
mts_mdlog_start = 1;
success = 1;
} else if ((int)ioarg == USB_MODE) {
mts_mdlog_start = 0;
success = 1;
} else {
pr_err("invalid ioarg: %lu\n", ioarg);
success = -EINVAL;
}
} else {
pr_err("invalid iocmd: %d\n", iocmd);
success = -EINVAL;
}
return success;
}
int wait_mts_read_complete(void)
{
if (mts_mdlog_start && driver->usb_connected) {
mutex_lock(&driver->diagchar_mutex);
mts_read_waiting = 1;
mutex_unlock(&driver->diagchar_mutex);
wait_for_completion_timeout(&mts_read_completion, HZ);
INIT_COMPLETION(mts_read_completion);
mutex_lock(&driver->diagchar_mutex);
mts_read_waiting = 0;
mutex_unlock(&driver->diagchar_mutex);
return 1;
} else
return 0;
}
static int wait_smd_data_empty(void)
{
int i, j;
int smd_data_empty = 0;
i = 0;
do {
for (j = 0; j < NUM_SMD_DATA_CHANNELS; j++) {
struct diag_smd_info *data = &driver->smd_data[j];
if ((smd_busy[j].in_busy_1 == 1) && (data->in_busy_1 == 0)) {
smd_data_empty = 1;
break;
}
if ((smd_busy[j].in_busy_2 == 1) && (data->in_busy_2 == 0)) {
smd_data_empty = 1;
break;
}
}
usleep(BUSY_WAITING_TIME_US);
} while (!mts_read_waiting && !smd_data_empty && (++i < BUSY_CHECK_COUNT));
if (!smd_data_empty) {
for (j = 0; j < NUM_SMD_DATA_CHANNELS; j++) {
struct diag_smd_info *data = &driver->smd_data[j];
if ((smd_busy[j].in_busy_1 == 1) && (data->in_busy_1 == 1))
data->in_busy_1 = 0;
if ((smd_busy[j].in_busy_2 == 1) && (data->in_busy_2 == 1))
data->in_busy_2 = 0;
}
}
return smd_data_empty;
}
static void read_smd_data(void)
{
int i;
if (!mts_read_waiting) {
for (i = 0; i < NUM_SMD_DATA_CHANNELS; i++) {
if (driver->smd_data[i].ch)
queue_work(driver->diag_wq,
&(driver->smd_data[i].diag_read_smd_work));
}
}
}
static int smd_data_updated(void)
{
int i;
for (i = 0; i < NUM_SMD_DATA_CHANNELS; i++) {
struct diag_smd_info *data = &driver->smd_data[i];
if (data->in_busy_1 || data->in_busy_2)
return 1;
}
return 0;
}
static int diagchar_mts_read(struct file *file, char __user *buf, size_t count,
loff_t *ppos)
{
int index = -1, i = 0, ret = 0;
int num_data = 0, data_type;
for (i = 0; i < driver->num_clients; i++)
if (driver->client_map[i].pid == current->tgid)
index = i;
if (index == -1) {
pr_err("diag: Client PID not found in table");
return -EINVAL;
}
if (driver->usb_connected) {
if (!wait_smd_data_empty())
read_smd_data();
} else {
read_smd_data();
}
i = 0;
while (!mts_read_waiting && !smd_data_updated()) {
if (!mts_mdlog_start)
return -EINVAL;
usleep(BUSY_WAITING_TIME_US);
if (++i == BUSY_CHECK_COUNT)
return ret;
}
mutex_lock(&driver->diagchar_mutex);
driver->data_ready[index] |= USER_SPACE_DATA_TYPE;
/*Copy the type of data being passed*/
data_type = driver->data_ready[index] & USER_SPACE_DATA_TYPE;
COPY_USER_SPACE_OR_EXIT(buf, data_type, 4);
/* place holder for number of data field */
ret += 4;
for (i = 0; i < driver->poolsize_write_struct; i++) {
if (driver->buf_tbl[i].length > 0) {
#ifdef DIAG_DEBUG
pr_debug("diag: WRITING the buf address "
"and length is %x , %d\n", (unsigned int)
(driver->buf_tbl[i].buf),
driver->buf_tbl[i].length);
#endif
num_data++;
/* Copy the length of data being passed */
if (copy_to_user(buf+ret, (void *)&(driver->
buf_tbl[i].length), 4)) {
num_data--;
goto drop;
}
ret += 4;
/* Copy the actual data being passed */
if (copy_to_user(buf+ret, (void *)driver->
buf_tbl[i].buf, driver->buf_tbl[i].length)) {
ret -= 4;
num_data--;
goto drop;
}
ret += driver->buf_tbl[i].length;
drop:
#ifdef DIAG_DEBUG
pr_debug("diag: DEQUEUE buf address and"
" length is %x,%d\n", (unsigned int)
(driver->buf_tbl[i].buf), driver->
buf_tbl[i].length);
#endif
diagmem_free(driver, (unsigned char *)
(driver->buf_tbl[i].buf), POOL_TYPE_HDLC);
driver->buf_tbl[i].length = 0;
driver->buf_tbl[i].buf = 0;
}
}
/* copy modem data */
for (i = 0; i < NUM_SMD_DATA_CHANNELS; i++) {
struct diag_smd_info *data = &driver->smd_data[i];
if (data->in_busy_1 == 1) {
num_data++;
/*Copy the length of data being passed*/
COPY_USER_SPACE_OR_EXIT(buf+ret,
(data->write_ptr_1->length), 4);
/*Copy the actual data being passed*/
COPY_USER_SPACE_OR_EXIT(buf+ret,
*(data->buf_in_1),
data->write_ptr_1->length);
if (!driver->usb_connected || mts_read_waiting)
data->in_busy_1 = 0;
else
smd_busy[i].in_busy_1 = data->in_busy_1;
}
if (data->in_busy_2 == 1) {
num_data++;
/*Copy the length of data being passed*/
COPY_USER_SPACE_OR_EXIT(buf+ret,
(data->write_ptr_2->length), 4);
/*Copy the actual data being passed*/
COPY_USER_SPACE_OR_EXIT(buf+ret,
*(data->buf_in_2),
data->write_ptr_2->length);
if (!driver->usb_connected || mts_read_waiting)
data->in_busy_2 = 0;
else
smd_busy[i].in_busy_2 = data->in_busy_2;
}
}
/* copy number of data fields */
COPY_USER_SPACE_OR_EXIT(buf+4, num_data, 4);
ret -= 4;
driver->data_ready[index] ^= USER_SPACE_DATA_TYPE;
exit:
if (mts_read_waiting)
complete(&mts_read_completion);
mutex_unlock(&driver->diagchar_mutex);
return ret;
}
static int diagchar_mts_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
int err, pkt_type, token_offset = 0;
bool remote_data = false;
unsigned int payload_size;
void *user_space_data = NULL;
/* Get the packet type F3/log/event/Pkt response */
err = copy_from_user((&pkt_type), buf, 4);
/* First 4 bytes indicate the type of payload - ignore these */
if (count < 4) {
pr_err("diag: Client sending short data\n");
return -EBADMSG;
}
payload_size = count - 4;
if (payload_size > USER_SPACE_DATA) {
pr_err("diag: Dropping packet, packet payload size crosses 8KB limit. Current payload size %d\n",
payload_size);
driver->dropped_count++;
return -EBADMSG;
}
if (pkt_type == DCI_DATA_TYPE) {
user_space_data = diagmem_alloc(driver, payload_size,
POOL_TYPE_USER);
if (!user_space_data) {
driver->dropped_count++;
return -ENOMEM;
}
err = copy_from_user(user_space_data, buf + 4, payload_size);
if (err) {
pr_alert("diag: copy failed for DCI data\n");
diagmem_free(driver, user_space_data, POOL_TYPE_USER);
return DIAG_DCI_SEND_DATA_FAIL;
}
err = diag_process_dci_transaction(user_space_data,
payload_size);
diagmem_free(driver, user_space_data, POOL_TYPE_USER);
return err;
}
if (pkt_type == USER_SPACE_DATA_TYPE) {
user_space_data = diagmem_alloc(driver, payload_size,
POOL_TYPE_USER);
if (!user_space_data) {
driver->dropped_count++;
return -ENOMEM;
}
err = copy_from_user(user_space_data, buf + 4, payload_size);
if (err) {
pr_alert("diag: copy failed for user spave data\n");
diagmem_free(driver, user_space_data, POOL_TYPE_USER);
return -EIO;
}
/* Check for proc_type */
if (*(int *)user_space_data == MDM_TOKEN) {
remote_data = true;
token_offset = 4;
payload_size -= 4;
buf += 4;
}
if (!mask_request_validate(user_space_data +
token_offset)) {
pr_alert("diag: mask request Invalid\n");
diagmem_free(driver, user_space_data, POOL_TYPE_USER);
return -EFAULT;
}
buf = buf + 4;
/* send masks to 8k now */
if (!remote_data)
diag_process_hdlc((void *)
(user_space_data + token_offset),
payload_size);
diagmem_free(driver, user_space_data, POOL_TYPE_USER);
}
return 0;
}
static const struct file_operations diagchar_mts_fops = {
.owner = THIS_MODULE,
.read = diagchar_mts_read,
.write = diagchar_mts_write,
.unlocked_ioctl = diagchar_mts_ioctl,
.open = diagchar_mts_open,
.release = diagchar_mts_close
};
static int diagchar_setup_cdev(dev_t devno)
{
int err;
cdev_init(cdev_mts, &diagchar_mts_fops);
cdev_mts->owner = THIS_MODULE;
cdev_mts->ops = &diagchar_mts_fops;
err = cdev_add(cdev_mts, devno, 1);
if (err) {
printk(KERN_INFO "diagchar_mts cdev registration failed !\n\n");
return -1;
}
diagchar_mts_class = class_create(THIS_MODULE, "diag_mts");
if (IS_ERR(diagchar_mts_class)) {
printk(KERN_ERR "Error creating diagchar class.\n");
return -1;
}
device_create(diagchar_mts_class, NULL, devno, 0, "diag_mts");
return 0;
}
static int diagchar_cleanup(void)
{
if (cdev_mts) {
/* TODO - Check if device exists before deleting */
device_destroy(diagchar_mts_class, dev);
cdev_del(cdev_mts);
}
if (!IS_ERR(diagchar_mts_class))
class_destroy(diagchar_mts_class);
return 0;
}
static int __init diagchar_mts_init(void)
{
int error;
error = alloc_chrdev_region(&dev, 0, 1, "diag_mts");
if (error) {
printk(KERN_INFO "Major number not allocated\n");
goto fail;
}
cdev_mts = cdev_alloc();
diagchar_setup_cdev(dev);
return 0;
fail:
return -1;
}
static void diagchar_mts_exit(void)
{
diagchar_cleanup();
}
module_init(diagchar_mts_init);
module_exit(diagchar_mts_exit);
| gpl-2.0 |
kaustubh-kabra/xenified-jeremy-kernel- | tools/perf/util/values.c | 515 | 6621 | #include <stdlib.h>
#include "util.h"
#include "values.h"
void perf_read_values_init(struct perf_read_values *values)
{
values->threads_max = 16;
values->pid = malloc(values->threads_max * sizeof(*values->pid));
values->tid = malloc(values->threads_max * sizeof(*values->tid));
values->value = malloc(values->threads_max * sizeof(*values->value));
if (!values->pid || !values->tid || !values->value)
die("failed to allocate read_values threads arrays");
values->threads = 0;
values->counters_max = 16;
values->counterrawid = malloc(values->counters_max
* sizeof(*values->counterrawid));
values->countername = malloc(values->counters_max
* sizeof(*values->countername));
if (!values->counterrawid || !values->countername)
die("failed to allocate read_values counters arrays");
values->counters = 0;
}
void perf_read_values_destroy(struct perf_read_values *values)
{
int i;
if (!values->threads_max || !values->counters_max)
return;
for (i = 0; i < values->threads; i++)
free(values->value[i]);
free(values->pid);
free(values->tid);
free(values->counterrawid);
for (i = 0; i < values->counters; i++)
free(values->countername[i]);
free(values->countername);
}
static void perf_read_values__enlarge_threads(struct perf_read_values *values)
{
values->threads_max *= 2;
values->pid = realloc(values->pid,
values->threads_max * sizeof(*values->pid));
values->tid = realloc(values->tid,
values->threads_max * sizeof(*values->tid));
values->value = realloc(values->value,
values->threads_max * sizeof(*values->value));
if (!values->pid || !values->tid || !values->value)
die("failed to enlarge read_values threads arrays");
}
static int perf_read_values__findnew_thread(struct perf_read_values *values,
u32 pid, u32 tid)
{
int i;
for (i = 0; i < values->threads; i++)
if (values->pid[i] == pid && values->tid[i] == tid)
return i;
if (values->threads == values->threads_max)
perf_read_values__enlarge_threads(values);
i = values->threads++;
values->pid[i] = pid;
values->tid[i] = tid;
values->value[i] = malloc(values->counters_max * sizeof(**values->value));
if (!values->value[i])
die("failed to allocate read_values counters array");
return i;
}
static void perf_read_values__enlarge_counters(struct perf_read_values *values)
{
int i;
values->counters_max *= 2;
values->counterrawid = realloc(values->counterrawid,
values->counters_max * sizeof(*values->counterrawid));
values->countername = realloc(values->countername,
values->counters_max * sizeof(*values->countername));
if (!values->counterrawid || !values->countername)
die("failed to enlarge read_values counters arrays");
for (i = 0; i < values->threads; i++) {
values->value[i] = realloc(values->value[i],
values->counters_max * sizeof(**values->value));
if (!values->value[i])
die("failed to enlarge read_values counters arrays");
}
}
static int perf_read_values__findnew_counter(struct perf_read_values *values,
u64 rawid, const char *name)
{
int i;
for (i = 0; i < values->counters; i++)
if (values->counterrawid[i] == rawid)
return i;
if (values->counters == values->counters_max)
perf_read_values__enlarge_counters(values);
i = values->counters++;
values->counterrawid[i] = rawid;
values->countername[i] = strdup(name);
return i;
}
void perf_read_values_add_value(struct perf_read_values *values,
u32 pid, u32 tid,
u64 rawid, const char *name, u64 value)
{
int tindex, cindex;
tindex = perf_read_values__findnew_thread(values, pid, tid);
cindex = perf_read_values__findnew_counter(values, rawid, name);
values->value[tindex][cindex] = value;
}
static void perf_read_values__display_pretty(FILE *fp,
struct perf_read_values *values)
{
int i, j;
int pidwidth, tidwidth;
int *counterwidth;
counterwidth = malloc(values->counters * sizeof(*counterwidth));
if (!counterwidth)
die("failed to allocate counterwidth array");
tidwidth = 3;
pidwidth = 3;
for (j = 0; j < values->counters; j++)
counterwidth[j] = strlen(values->countername[j]);
for (i = 0; i < values->threads; i++) {
int width;
width = snprintf(NULL, 0, "%d", values->pid[i]);
if (width > pidwidth)
pidwidth = width;
width = snprintf(NULL, 0, "%d", values->tid[i]);
if (width > tidwidth)
tidwidth = width;
for (j = 0; j < values->counters; j++) {
width = snprintf(NULL, 0, "%Lu", values->value[i][j]);
if (width > counterwidth[j])
counterwidth[j] = width;
}
}
fprintf(fp, "# %*s %*s", pidwidth, "PID", tidwidth, "TID");
for (j = 0; j < values->counters; j++)
fprintf(fp, " %*s", counterwidth[j], values->countername[j]);
fprintf(fp, "\n");
for (i = 0; i < values->threads; i++) {
fprintf(fp, " %*d %*d", pidwidth, values->pid[i],
tidwidth, values->tid[i]);
for (j = 0; j < values->counters; j++)
fprintf(fp, " %*Lu",
counterwidth[j], values->value[i][j]);
fprintf(fp, "\n");
}
}
static void perf_read_values__display_raw(FILE *fp,
struct perf_read_values *values)
{
int width, pidwidth, tidwidth, namewidth, rawwidth, countwidth;
int i, j;
tidwidth = 3; /* TID */
pidwidth = 3; /* PID */
namewidth = 4; /* "Name" */
rawwidth = 3; /* "Raw" */
countwidth = 5; /* "Count" */
for (i = 0; i < values->threads; i++) {
width = snprintf(NULL, 0, "%d", values->pid[i]);
if (width > pidwidth)
pidwidth = width;
width = snprintf(NULL, 0, "%d", values->tid[i]);
if (width > tidwidth)
tidwidth = width;
}
for (j = 0; j < values->counters; j++) {
width = strlen(values->countername[j]);
if (width > namewidth)
namewidth = width;
width = snprintf(NULL, 0, "%llx", values->counterrawid[j]);
if (width > rawwidth)
rawwidth = width;
}
for (i = 0; i < values->threads; i++) {
for (j = 0; j < values->counters; j++) {
width = snprintf(NULL, 0, "%Lu", values->value[i][j]);
if (width > countwidth)
countwidth = width;
}
}
fprintf(fp, "# %*s %*s %*s %*s %*s\n",
pidwidth, "PID", tidwidth, "TID",
namewidth, "Name", rawwidth, "Raw",
countwidth, "Count");
for (i = 0; i < values->threads; i++)
for (j = 0; j < values->counters; j++)
fprintf(fp, " %*d %*d %*s %*llx %*Lu\n",
pidwidth, values->pid[i],
tidwidth, values->tid[i],
namewidth, values->countername[j],
rawwidth, values->counterrawid[j],
countwidth, values->value[i][j]);
}
void perf_read_values_display(FILE *fp, struct perf_read_values *values, int raw)
{
if (raw)
perf_read_values__display_raw(fp, values);
else
perf_read_values__display_pretty(fp, values);
}
| gpl-2.0 |
bq-dev/android_kernel_bq_msm8976 | drivers/hwmon/boost-dynamic-controller.c | 771 | 9298 | /* Copyright (c) 2014, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#define pr_fmt(fmt) "%s: " fmt, __func__
#include <linux/module.h>
#include <linux/err.h>
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/qpnp/qpnp-adc.h>
#include <soc/qcom/rpm-smd.h>
struct boost_dynamic_controller {
/* ADC_TM parameters */
struct qpnp_adc_tm_chip *boost_adc_tm_dev;
struct qpnp_adc_tm_btm_param boost_monitor_params;
u32 vph_high_thresh_uv;
u32 vph_low_thresh_uv;
/* Boost mode parameters */
int old_boost_mode;
/* RPM control parameters */
const char *boost_resource_type;
const char *boost_resource_key;
int resource_type;
u32 resource_key;
u32 resource_id;
struct mutex boost_mutex;
};
#define BOOST_DYNAMIC_CONTROLLER_DRIVER_NAME "qcom,boost-dynamic-controller"
static u32 rpm_vreg_string_to_int(const u8 *str)
{
int i, len;
u32 output = 0;
len = strnlen(str, sizeof(u32));
for (i = 0; i < len; i++)
output |= str[i] << (i * 8);
return output;
}
static int boost_dynamic_controller_parse_dt(
struct boost_dynamic_controller *boost_controller,
struct device_node *of_node)
{
int ret;
ret = of_property_read_u32(of_node,
"qcom,boost-dynamic-controller-vph-high-threshold-uv",
&boost_controller->vph_high_thresh_uv);
if (ret < 0) {
pr_err("qcom,boost-dynamic-controller-vph-high-threshold-uv is missing, ret = %d",
ret);
return ret;
}
ret = of_property_read_u32(of_node,
"qcom,boost-dynamic-controller-vph-low-threshold-uv",
&boost_controller->vph_low_thresh_uv);
if (ret < 0) {
pr_err("qcom,boost-dynamic-controller-vph-low-threshold-uv is missing, ret = %d",
ret);
return ret;
}
ret = of_property_read_u32(of_node,
"qcom,boost-dynamic-controller-boost-resource-id",
&boost_controller->resource_id);
if (ret < 0) {
pr_err("qcom,boost-dynamic-controller-boost-resource-id is missing, ret = %d",
ret);
return ret;
}
ret = of_property_read_string(of_node,
"qcom,boost-dynamic-controller-boost-resource-type",
&boost_controller->boost_resource_type);
if (ret < 0) {
pr_err("qcom,boost-dynamic-controller-boost-resource-type is missing, ret = %d",
ret);
return ret;
}
ret = of_property_read_string(of_node,
"qcom,boost-dynamic-controller-boost-resource-key",
&boost_controller->boost_resource_key);
if (ret < 0) {
pr_err("qcom,boost-dynamic-controller-boost-resource-key is missing, ret = %d",
ret);
return ret;
}
return ret;
}
static int boost_rpm_send_message(
struct boost_dynamic_controller *boost_controller,
u32 data)
{
int ret;
struct msm_rpm_kvp kvp = {
.key = boost_controller->resource_key,
.data = (void *)&data,
.length = sizeof(data),
};
ret = msm_rpm_send_message(MSM_RPM_CTX_ACTIVE_SET,
boost_controller->resource_type,
boost_controller->resource_id,
&kvp, 1);
if (ret < 0)
pr_err("failed to inform RPM! (err = %d)\n", ret);
return ret;
}
static void boost_dynamic_controller_notification(enum qpnp_tm_state state,
void *ctx)
{
struct boost_dynamic_controller *boost_controller = ctx;
int ret;
mutex_lock(&boost_controller->boost_mutex);
if (state == ADC_TM_LOW_STATE &&
boost_controller->old_boost_mode != ADC_TM_LOW_STATE) {
ret = boost_rpm_send_message(boost_controller, 1);
if (ret) {
pr_err("sending boost mode to RPM failed, ret=%d\n",
ret);
boost_controller->boost_monitor_params.state_request =
ADC_TM_LOW_THR_ENABLE;
} else {
boost_controller->old_boost_mode = ADC_TM_LOW_STATE;
boost_controller->boost_monitor_params.state_request =
ADC_TM_HIGH_THR_ENABLE;
}
} else if (state == ADC_TM_HIGH_STATE &&
boost_controller->old_boost_mode != ADC_TM_HIGH_STATE) {
ret = boost_rpm_send_message(boost_controller, 0);
if (ret) {
pr_err("sending boost mode to RPM failed, ret=%d\n",
ret);
boost_controller->boost_monitor_params.state_request =
ADC_TM_HIGH_THR_ENABLE;
} else {
boost_controller->old_boost_mode = ADC_TM_HIGH_STATE;
boost_controller->boost_monitor_params.state_request =
ADC_TM_LOW_THR_ENABLE;
}
}
mutex_unlock(&boost_controller->boost_mutex);
qpnp_adc_tm_channel_measure(boost_controller->boost_adc_tm_dev,
&boost_controller->boost_monitor_params);
}
static int boost_dynamic_controller_setup_vph_monitoring(
struct boost_dynamic_controller *boost_controller,
struct device *dev)
{
int ret;
char *key = NULL;
struct qpnp_vadc_chip *vadc_dev;
struct qpnp_vadc_result adc_result;
key = "vph-threshold";
boost_controller->boost_adc_tm_dev = qpnp_get_adc_tm(dev, key);
if (IS_ERR(boost_controller->boost_adc_tm_dev)) {
ret = PTR_ERR(boost_controller->boost_adc_tm_dev);
if (ret != -EPROBE_DEFER)
pr_err("adc_tm property missing, ret=%d\n", ret);
return ret;
}
boost_controller->boost_monitor_params.high_thr =
boost_controller->vph_high_thresh_uv;
boost_controller->boost_monitor_params.low_thr =
boost_controller->vph_low_thresh_uv;
boost_controller->boost_monitor_params.channel = VSYS;
boost_controller->boost_monitor_params.btm_ctx =
(void *)boost_controller;
boost_controller->boost_monitor_params.timer_interval =
ADC_MEAS1_INTERVAL_1S;
boost_controller->boost_monitor_params.threshold_notification =
&boost_dynamic_controller_notification;
key = "vph";
vadc_dev = qpnp_get_vadc(dev, key);
if (IS_ERR(vadc_dev)) {
ret = PTR_ERR(vadc_dev);
if (ret != -EPROBE_DEFER)
pr_err("vadc property missing, ret=%d\n", ret);
return ret;
}
ret = qpnp_vadc_read(vadc_dev, VSYS, &adc_result);
if (ret) {
pr_err("Unable to read VPH ret=%d\n", ret);
return ret;
}
if (adc_result.physical > boost_controller->vph_high_thresh_uv) {
ret = boost_rpm_send_message(boost_controller, 0);
if (ret) {
pr_err("sending boost mode to RPM failed, ret=%d\n",
ret);
return ret;
}
boost_controller->old_boost_mode = ADC_TM_HIGH_STATE;
boost_controller->boost_monitor_params.state_request =
ADC_TM_LOW_THR_ENABLE;
} else {
ret = boost_rpm_send_message(boost_controller, 1);
if (ret) {
pr_err("sending boost mode to RPM failed, ret=%d\n",
ret);
return ret;
}
boost_controller->old_boost_mode = ADC_TM_LOW_STATE;
boost_controller->boost_monitor_params.state_request =
ADC_TM_HIGH_THR_ENABLE;
}
ret = qpnp_adc_tm_channel_measure(boost_controller->boost_adc_tm_dev,
&boost_controller->boost_monitor_params);
if (ret) {
pr_err("adc-tm setup failed: ret = %d\n", ret);
return ret;
}
return ret;
}
static int boost_dynamic_controller_probe(struct platform_device *pdev)
{
struct boost_dynamic_controller *boost_controller = NULL;
struct device *dev = &pdev->dev;
int ret;
boost_controller = devm_kzalloc(dev,
sizeof(struct boost_dynamic_controller), GFP_KERNEL);
if (!boost_controller) {
dev_err(dev, "Cannot allocate boost_dynamic_controller\n");
return -ENOMEM;
}
if (!dev->of_node) {
dev_err(dev, "Device tree node is missing\n");
return -EINVAL;
}
ret = boost_dynamic_controller_parse_dt(boost_controller, dev->of_node);
if (ret) {
pr_err("Wrong DT parameter specified: ret = %d\n", ret);
return ret;
}
boost_controller->resource_type =
rpm_vreg_string_to_int(boost_controller->boost_resource_type);
boost_controller->resource_key =
rpm_vreg_string_to_int(boost_controller->boost_resource_key);
mutex_init(&boost_controller->boost_mutex);
ret = boost_dynamic_controller_setup_vph_monitoring(boost_controller,
dev);
if (ret) {
mutex_destroy(&boost_controller->boost_mutex);
if (ret != -EPROBE_DEFER)
pr_err("Vph monitor setup failure, ret = %d\n", ret);
return ret;
}
return ret;
}
static int boost_dynamic_controller_remove(struct platform_device *pdev)
{
struct boost_dynamic_controller *boost_controller;
boost_controller = platform_get_drvdata(pdev);
mutex_destroy(&boost_controller->boost_mutex);
return 0;
}
static struct of_device_id boost_dynamic_controller_match_table[] = {
{ .compatible = BOOST_DYNAMIC_CONTROLLER_DRIVER_NAME, },
{}
};
static struct platform_driver boost_dynamic_controller_driver = {
.driver = {
.name = BOOST_DYNAMIC_CONTROLLER_DRIVER_NAME,
.of_match_table = boost_dynamic_controller_match_table,
.owner = THIS_MODULE,
},
.probe = boost_dynamic_controller_probe,
.remove = boost_dynamic_controller_remove,
};
static int __init boost_dynamic_controller_init(void)
{
return platform_driver_register(&boost_dynamic_controller_driver);
}
module_init(boost_dynamic_controller_init);
static void __exit boost_dynamic_controller_exit(void)
{
platform_driver_unregister(&boost_dynamic_controller_driver);
}
module_exit(boost_dynamic_controller_exit);
MODULE_DESCRIPTION("Boost dynamic controller driver");
MODULE_LICENSE("GPL v2");
| gpl-2.0 |
silvesterlee/linux | fs/ceph/mdsmap.c | 1539 | 4616 | #include <linux/ceph/ceph_debug.h>
#include <linux/bug.h>
#include <linux/err.h>
#include <linux/random.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/ceph/mdsmap.h>
#include <linux/ceph/messenger.h>
#include <linux/ceph/decode.h>
#include "super.h"
/*
* choose a random mds that is "up" (i.e. has a state > 0), or -1.
*/
int ceph_mdsmap_get_random_mds(struct ceph_mdsmap *m)
{
int n = 0;
int i;
/* special case for one mds */
if (1 == m->m_max_mds && m->m_info[0].state > 0)
return 0;
/* count */
for (i = 0; i < m->m_max_mds; i++)
if (m->m_info[i].state > 0)
n++;
if (n == 0)
return -1;
/* pick */
n = prandom_u32() % n;
i = 0;
for (i = 0; n > 0; i++, n--)
while (m->m_info[i].state <= 0)
i++;
return i;
}
/*
* Decode an MDS map
*
* Ignore any fields we don't care about (there are quite a few of
* them).
*/
struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
{
struct ceph_mdsmap *m;
const void *start = *p;
int i, j, n;
int err = -EINVAL;
u16 version;
m = kzalloc(sizeof(*m), GFP_NOFS);
if (m == NULL)
return ERR_PTR(-ENOMEM);
ceph_decode_16_safe(p, end, version, bad);
if (version > 3) {
pr_warn("got mdsmap version %d > 3, failing", version);
goto bad;
}
ceph_decode_need(p, end, 8*sizeof(u32) + sizeof(u64), bad);
m->m_epoch = ceph_decode_32(p);
m->m_client_epoch = ceph_decode_32(p);
m->m_last_failure = ceph_decode_32(p);
m->m_root = ceph_decode_32(p);
m->m_session_timeout = ceph_decode_32(p);
m->m_session_autoclose = ceph_decode_32(p);
m->m_max_file_size = ceph_decode_64(p);
m->m_max_mds = ceph_decode_32(p);
m->m_info = kcalloc(m->m_max_mds, sizeof(*m->m_info), GFP_NOFS);
if (m->m_info == NULL)
goto badmem;
/* pick out active nodes from mds_info (state > 0) */
n = ceph_decode_32(p);
for (i = 0; i < n; i++) {
u64 global_id;
u32 namelen;
s32 mds, inc, state;
u64 state_seq;
u8 infoversion;
struct ceph_entity_addr addr;
u32 num_export_targets;
void *pexport_targets = NULL;
struct ceph_timespec laggy_since;
struct ceph_mds_info *info;
ceph_decode_need(p, end, sizeof(u64)*2 + 1 + sizeof(u32), bad);
global_id = ceph_decode_64(p);
infoversion = ceph_decode_8(p);
*p += sizeof(u64);
namelen = ceph_decode_32(p); /* skip mds name */
*p += namelen;
ceph_decode_need(p, end,
4*sizeof(u32) + sizeof(u64) +
sizeof(addr) + sizeof(struct ceph_timespec),
bad);
mds = ceph_decode_32(p);
inc = ceph_decode_32(p);
state = ceph_decode_32(p);
state_seq = ceph_decode_64(p);
ceph_decode_copy(p, &addr, sizeof(addr));
ceph_decode_addr(&addr);
ceph_decode_copy(p, &laggy_since, sizeof(laggy_since));
*p += sizeof(u32);
ceph_decode_32_safe(p, end, namelen, bad);
*p += namelen;
if (infoversion >= 2) {
ceph_decode_32_safe(p, end, num_export_targets, bad);
pexport_targets = *p;
*p += num_export_targets * sizeof(u32);
} else {
num_export_targets = 0;
}
dout("mdsmap_decode %d/%d %lld mds%d.%d %s %s\n",
i+1, n, global_id, mds, inc,
ceph_pr_addr(&addr.in_addr),
ceph_mds_state_name(state));
if (mds < 0 || mds >= m->m_max_mds || state <= 0)
continue;
info = &m->m_info[mds];
info->global_id = global_id;
info->state = state;
info->addr = addr;
info->laggy = (laggy_since.tv_sec != 0 ||
laggy_since.tv_nsec != 0);
info->num_export_targets = num_export_targets;
if (num_export_targets) {
info->export_targets = kcalloc(num_export_targets,
sizeof(u32), GFP_NOFS);
if (info->export_targets == NULL)
goto badmem;
for (j = 0; j < num_export_targets; j++)
info->export_targets[j] =
ceph_decode_32(&pexport_targets);
} else {
info->export_targets = NULL;
}
}
/* pg_pools */
ceph_decode_32_safe(p, end, n, bad);
m->m_num_data_pg_pools = n;
m->m_data_pg_pools = kcalloc(n, sizeof(u64), GFP_NOFS);
if (!m->m_data_pg_pools)
goto badmem;
ceph_decode_need(p, end, sizeof(u64)*(n+1), bad);
for (i = 0; i < n; i++)
m->m_data_pg_pools[i] = ceph_decode_64(p);
m->m_cas_pg_pool = ceph_decode_64(p);
/* ok, we don't care about the rest. */
dout("mdsmap_decode success epoch %u\n", m->m_epoch);
return m;
badmem:
err = -ENOMEM;
bad:
pr_err("corrupt mdsmap\n");
print_hex_dump(KERN_DEBUG, "mdsmap: ",
DUMP_PREFIX_OFFSET, 16, 1,
start, end - start, true);
ceph_mdsmap_destroy(m);
return ERR_PTR(err);
}
void ceph_mdsmap_destroy(struct ceph_mdsmap *m)
{
int i;
for (i = 0; i < m->m_max_mds; i++)
kfree(m->m_info[i].export_targets);
kfree(m->m_info);
kfree(m->m_data_pg_pools);
kfree(m);
}
| gpl-2.0 |
shakalaca/ASUS_ZenFone_ZC451CG | linux/kernel/drivers/staging/ozwpan/ozhcd.c | 2051 | 69912 | /* -----------------------------------------------------------------------------
* Copyright (c) 2011 Ozmo Inc
* Released under the GNU General Public License Version 2 (GPLv2).
*
* This file provides the implementation of a USB host controller device that
* does not have any associated hardware. Instead the virtual device is
* connected to the WiFi network and emulates the operation of a USB hcd by
* receiving and sending network frames.
* Note:
* We take great pains to reduce the amount of code where interrupts need to be
* disabled and in this respect we are different from standard HCD's. In
* particular we don't want in_irq() code bleeding over to the protocol side of
* the driver.
* The troublesome functions are the urb enqueue and dequeue functions both of
* which can be called in_irq(). So for these functions we put the urbs into a
* queue and request a tasklet to process them. This means that a spinlock with
* interrupts disabled must be held for insertion and removal but most code is
* is in tasklet or soft irq context. The lock that protects this list is called
* the tasklet lock and serves the purpose of the 'HCD lock' which must be held
* when calling the following functions.
* usb_hcd_link_urb_to_ep()
* usb_hcd_unlink_urb_from_ep()
* usb_hcd_flush_endpoint()
* usb_hcd_check_unlink_urb()
* -----------------------------------------------------------------------------
*/
#include <linux/platform_device.h>
#include <linux/usb.h>
#include <linux/jiffies.h>
#include <linux/slab.h>
#include <linux/export.h>
#include "linux/usb/hcd.h"
#include <asm/unaligned.h>
#include "ozconfig.h"
#include "ozusbif.h"
#include "oztrace.h"
#include "ozurbparanoia.h"
#include "ozevent.h"
#include "ozhcd.h"
/*------------------------------------------------------------------------------
* Number of units of buffering to capture for an isochronous IN endpoint before
* allowing data to be indicated up.
*/
#define OZ_IN_BUFFERING_UNITS 50
/* Name of our platform device.
*/
#define OZ_PLAT_DEV_NAME "ozwpan"
/* Maximum number of free urb links that can be kept in the pool.
*/
#define OZ_MAX_LINK_POOL_SIZE 16
/* Get endpoint object from the containing link.
*/
#define ep_from_link(__e) container_of((__e), struct oz_endpoint, link)
/*------------------------------------------------------------------------------
* Used to link urbs together and also store some status information for each
* urb.
* A cache of these are kept in a pool to reduce number of calls to kmalloc.
*/
struct oz_urb_link {
struct list_head link;
struct urb *urb;
struct oz_port *port;
u8 req_id;
u8 ep_num;
unsigned long submit_jiffies;
};
/* Holds state information about a USB endpoint.
*/
struct oz_endpoint {
struct list_head urb_list; /* List of oz_urb_link items. */
struct list_head link; /* For isoc ep, links in to isoc
lists of oz_port. */
unsigned long last_jiffies;
int credit;
int credit_ceiling;
u8 ep_num;
u8 attrib;
u8 *buffer;
int buffer_size;
int in_ix;
int out_ix;
int buffered_units;
unsigned flags;
int start_frame;
};
/* Bits in the flags field. */
#define OZ_F_EP_BUFFERING 0x1
#define OZ_F_EP_HAVE_STREAM 0x2
/* Holds state information about a USB interface.
*/
struct oz_interface {
unsigned ep_mask;
u8 alt;
};
/* Holds state information about an hcd port.
*/
#define OZ_NB_ENDPOINTS 16
struct oz_port {
unsigned flags;
unsigned status;
void *hpd;
struct oz_hcd *ozhcd;
spinlock_t port_lock;
u8 bus_addr;
u8 next_req_id;
u8 config_num;
int num_iface;
struct oz_interface *iface;
struct oz_endpoint *out_ep[OZ_NB_ENDPOINTS];
struct oz_endpoint *in_ep[OZ_NB_ENDPOINTS];
struct list_head isoc_out_ep;
struct list_head isoc_in_ep;
};
#define OZ_PORT_F_PRESENT 0x1
#define OZ_PORT_F_CHANGED 0x2
#define OZ_PORT_F_DYING 0x4
/* Data structure in the private context area of struct usb_hcd.
*/
#define OZ_NB_PORTS 8
struct oz_hcd {
spinlock_t hcd_lock;
struct list_head urb_pending_list;
struct list_head urb_cancel_list;
struct list_head orphanage;
int conn_port; /* Port that is currently connecting, -1 if none.*/
struct oz_port ports[OZ_NB_PORTS];
uint flags;
struct usb_hcd *hcd;
};
/* Bits in flags field.
*/
#define OZ_HDC_F_SUSPENDED 0x1
/*------------------------------------------------------------------------------
* Static function prototypes.
*/
static int oz_hcd_start(struct usb_hcd *hcd);
static void oz_hcd_stop(struct usb_hcd *hcd);
static void oz_hcd_shutdown(struct usb_hcd *hcd);
static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
gfp_t mem_flags);
static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
static void oz_hcd_endpoint_disable(struct usb_hcd *hcd,
struct usb_host_endpoint *ep);
static void oz_hcd_endpoint_reset(struct usb_hcd *hcd,
struct usb_host_endpoint *ep);
static int oz_hcd_get_frame_number(struct usb_hcd *hcd);
static int oz_hcd_hub_status_data(struct usb_hcd *hcd, char *buf);
static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue,
u16 windex, char *buf, u16 wlength);
static int oz_hcd_bus_suspend(struct usb_hcd *hcd);
static int oz_hcd_bus_resume(struct usb_hcd *hcd);
static int oz_plat_probe(struct platform_device *dev);
static int oz_plat_remove(struct platform_device *dev);
static void oz_plat_shutdown(struct platform_device *dev);
static int oz_plat_suspend(struct platform_device *dev, pm_message_t msg);
static int oz_plat_resume(struct platform_device *dev);
static void oz_urb_process_tasklet(unsigned long unused);
static int oz_build_endpoints_for_config(struct usb_hcd *hcd,
struct oz_port *port, struct usb_host_config *config,
gfp_t mem_flags);
static void oz_clean_endpoints_for_config(struct usb_hcd *hcd,
struct oz_port *port);
static int oz_build_endpoints_for_interface(struct usb_hcd *hcd,
struct oz_port *port,
struct usb_host_interface *intf, gfp_t mem_flags);
static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd,
struct oz_port *port, int if_ix);
static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
gfp_t mem_flags);
static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep,
struct urb *urb);
static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status);
/*------------------------------------------------------------------------------
* Static external variables.
*/
static struct platform_device *g_plat_dev;
static struct oz_hcd *g_ozhcd;
static DEFINE_SPINLOCK(g_hcdlock); /* Guards g_ozhcd. */
static const char g_hcd_name[] = "Ozmo WPAN";
static struct list_head *g_link_pool;
static int g_link_pool_size;
static DEFINE_SPINLOCK(g_link_lock);
static DEFINE_SPINLOCK(g_tasklet_lock);
static struct tasklet_struct g_urb_process_tasklet;
static struct tasklet_struct g_urb_cancel_tasklet;
static atomic_t g_pending_urbs = ATOMIC_INIT(0);
static const struct hc_driver g_oz_hc_drv = {
.description = g_hcd_name,
.product_desc = "Ozmo Devices WPAN",
.hcd_priv_size = sizeof(struct oz_hcd),
.flags = HCD_USB11,
.start = oz_hcd_start,
.stop = oz_hcd_stop,
.shutdown = oz_hcd_shutdown,
.urb_enqueue = oz_hcd_urb_enqueue,
.urb_dequeue = oz_hcd_urb_dequeue,
.endpoint_disable = oz_hcd_endpoint_disable,
.endpoint_reset = oz_hcd_endpoint_reset,
.get_frame_number = oz_hcd_get_frame_number,
.hub_status_data = oz_hcd_hub_status_data,
.hub_control = oz_hcd_hub_control,
.bus_suspend = oz_hcd_bus_suspend,
.bus_resume = oz_hcd_bus_resume,
};
static struct platform_driver g_oz_plat_drv = {
.probe = oz_plat_probe,
.remove = oz_plat_remove,
.shutdown = oz_plat_shutdown,
.suspend = oz_plat_suspend,
.resume = oz_plat_resume,
.driver = {
.name = OZ_PLAT_DEV_NAME,
.owner = THIS_MODULE,
},
};
/*------------------------------------------------------------------------------
* Gets our private context area (which is of type struct oz_hcd) from the
* usb_hcd structure.
* Context: any
*/
static inline struct oz_hcd *oz_hcd_private(struct usb_hcd *hcd)
{
return (struct oz_hcd *)hcd->hcd_priv;
}
/*------------------------------------------------------------------------------
* Searches list of ports to find the index of the one with a specified USB
* bus address. If none of the ports has the bus address then the connection
* port is returned, if there is one or -1 otherwise.
* Context: any
*/
static int oz_get_port_from_addr(struct oz_hcd *ozhcd, u8 bus_addr)
{
int i;
for (i = 0; i < OZ_NB_PORTS; i++) {
if (ozhcd->ports[i].bus_addr == bus_addr)
return i;
}
return ozhcd->conn_port;
}
/*------------------------------------------------------------------------------
* Allocates an urb link, first trying the pool but going to heap if empty.
* Context: any
*/
static struct oz_urb_link *oz_alloc_urb_link(void)
{
struct oz_urb_link *urbl = NULL;
unsigned long irq_state;
spin_lock_irqsave(&g_link_lock, irq_state);
if (g_link_pool) {
urbl = container_of(g_link_pool, struct oz_urb_link, link);
g_link_pool = urbl->link.next;
--g_link_pool_size;
}
spin_unlock_irqrestore(&g_link_lock, irq_state);
if (urbl == NULL)
urbl = kmalloc(sizeof(struct oz_urb_link), GFP_ATOMIC);
return urbl;
}
/*------------------------------------------------------------------------------
* Frees an urb link by putting it in the pool if there is enough space or
* deallocating it to heap otherwise.
* Context: any
*/
static void oz_free_urb_link(struct oz_urb_link *urbl)
{
if (urbl) {
unsigned long irq_state;
spin_lock_irqsave(&g_link_lock, irq_state);
if (g_link_pool_size < OZ_MAX_LINK_POOL_SIZE) {
urbl->link.next = g_link_pool;
g_link_pool = &urbl->link;
urbl = NULL;
g_link_pool_size++;
}
spin_unlock_irqrestore(&g_link_lock, irq_state);
kfree(urbl);
}
}
/*------------------------------------------------------------------------------
* Deallocates all the urb links in the pool.
* Context: unknown
*/
static void oz_empty_link_pool(void)
{
struct list_head *e;
unsigned long irq_state;
spin_lock_irqsave(&g_link_lock, irq_state);
e = g_link_pool;
g_link_pool = NULL;
g_link_pool_size = 0;
spin_unlock_irqrestore(&g_link_lock, irq_state);
while (e) {
struct oz_urb_link *urbl =
container_of(e, struct oz_urb_link, link);
e = e->next;
kfree(urbl);
}
}
/*------------------------------------------------------------------------------
* Allocates endpoint structure and optionally a buffer. If a buffer is
* allocated it immediately follows the endpoint structure.
* Context: softirq
*/
static struct oz_endpoint *oz_ep_alloc(gfp_t mem_flags, int buffer_size)
{
struct oz_endpoint *ep =
kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
if (ep) {
INIT_LIST_HEAD(&ep->urb_list);
INIT_LIST_HEAD(&ep->link);
ep->credit = -1;
if (buffer_size) {
ep->buffer_size = buffer_size;
ep->buffer = (u8 *)(ep+1);
}
}
return ep;
}
/*------------------------------------------------------------------------------
* Pre-condition: Must be called with g_tasklet_lock held and interrupts
* disabled.
* Context: softirq or process
*/
static struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb)
{
struct oz_urb_link *urbl;
struct list_head *e;
list_for_each(e, &ozhcd->urb_cancel_list) {
urbl = container_of(e, struct oz_urb_link, link);
if (urb == urbl->urb) {
list_del_init(e);
return urbl;
}
}
return NULL;
}
/*------------------------------------------------------------------------------
* This is called when we have finished processing an urb. It unlinks it from
* the ep and returns it to the core.
* Context: softirq or process
*/
static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb,
int status, unsigned long submit_jiffies)
{
struct oz_hcd *ozhcd = oz_hcd_private(hcd);
unsigned long irq_state;
struct oz_urb_link *cancel_urbl = NULL;
spin_lock_irqsave(&g_tasklet_lock, irq_state);
usb_hcd_unlink_urb_from_ep(hcd, urb);
/* Clear hcpriv which will prevent it being put in the cancel list
* in the event that an attempt is made to cancel it.
*/
urb->hcpriv = NULL;
/* Walk the cancel list in case the urb is already sitting there.
* Since we process the cancel list in a tasklet rather than in
* the dequeue function this could happen.
*/
cancel_urbl = oz_uncancel_urb(ozhcd, urb);
/* Note: we release lock but do not enable local irqs.
* It appears that usb_hcd_giveback_urb() expects irqs to be disabled,
* or at least other host controllers disable interrupts at this point
* so we do the same. We must, however, release the lock otherwise a
* deadlock will occur if an urb is submitted to our driver in the urb
* completion function. Because we disable interrupts it is possible
* that the urb_enqueue function can be called with them disabled.
*/
spin_unlock(&g_tasklet_lock);
if (oz_forget_urb(urb)) {
oz_trace("OZWPAN: ERROR Unknown URB %p\n", urb);
} else {
static unsigned long last_time;
atomic_dec(&g_pending_urbs);
oz_trace2(OZ_TRACE_URB,
"%lu: giveback_urb(%p,%x) %lu %lu pending:%d\n",
jiffies, urb, status, jiffies-submit_jiffies,
jiffies-last_time, atomic_read(&g_pending_urbs));
last_time = jiffies;
oz_event_log(OZ_EVT_URB_DONE, 0, 0, urb, status);
usb_hcd_giveback_urb(hcd, urb, status);
}
spin_lock(&g_tasklet_lock);
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
if (cancel_urbl)
oz_free_urb_link(cancel_urbl);
}
/*------------------------------------------------------------------------------
* Deallocates an endpoint including deallocating any associated stream and
* returning any queued urbs to the core.
* Context: softirq
*/
static void oz_ep_free(struct oz_port *port, struct oz_endpoint *ep)
{
oz_trace("oz_ep_free()\n");
if (port) {
struct list_head list;
struct oz_hcd *ozhcd = port->ozhcd;
INIT_LIST_HEAD(&list);
if (ep->flags & OZ_F_EP_HAVE_STREAM)
oz_usb_stream_delete(port->hpd, ep->ep_num);
/* Transfer URBs to the orphanage while we hold the lock. */
spin_lock_bh(&ozhcd->hcd_lock);
/* Note: this works even if ep->urb_list is empty.*/
list_replace_init(&ep->urb_list, &list);
/* Put the URBs in the orphanage. */
list_splice_tail(&list, &ozhcd->orphanage);
spin_unlock_bh(&ozhcd->hcd_lock);
}
oz_trace("Freeing endpoint memory\n");
kfree(ep);
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
static void oz_complete_buffered_urb(struct oz_port *port,
struct oz_endpoint *ep,
struct urb *urb)
{
u8 data_len, available_space, copy_len;
memcpy(&data_len, &ep->buffer[ep->out_ix], sizeof(u8));
if (data_len <= urb->transfer_buffer_length)
available_space = data_len;
else
available_space = urb->transfer_buffer_length;
if (++ep->out_ix == ep->buffer_size)
ep->out_ix = 0;
copy_len = ep->buffer_size - ep->out_ix;
if (copy_len >= available_space)
copy_len = available_space;
memcpy(urb->transfer_buffer, &ep->buffer[ep->out_ix], copy_len);
if (copy_len < available_space) {
memcpy((urb->transfer_buffer + copy_len), ep->buffer,
(available_space - copy_len));
ep->out_ix = available_space - copy_len;
} else {
ep->out_ix += copy_len;
}
urb->actual_length = available_space;
if (ep->out_ix == ep->buffer_size)
ep->out_ix = 0;
ep->buffered_units--;
oz_trace("Trying to give back buffered frame of size=%d\n",
available_space);
oz_complete_urb(port->ozhcd->hcd, urb, 0, 0);
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
struct urb *urb, u8 req_id)
{
struct oz_urb_link *urbl;
struct oz_endpoint *ep;
int err = 0;
if (ep_addr >= OZ_NB_ENDPOINTS) {
oz_trace("Invalid endpoint number in oz_enqueue_ep_urb().\n");
return -EINVAL;
}
urbl = oz_alloc_urb_link();
if (!urbl)
return -ENOMEM;
urbl->submit_jiffies = jiffies;
urbl->urb = urb;
urbl->req_id = req_id;
urbl->ep_num = ep_addr;
/* Hold lock while we insert the URB into the list within the
* endpoint structure.
*/
spin_lock_bh(&port->ozhcd->hcd_lock);
/* If the urb has been unlinked while out of any list then
* complete it now.
*/
if (urb->unlinked) {
spin_unlock_bh(&port->ozhcd->hcd_lock);
oz_trace("urb %p unlinked so complete immediately\n", urb);
oz_complete_urb(port->ozhcd->hcd, urb, 0, 0);
oz_free_urb_link(urbl);
return 0;
}
if (in_dir)
ep = port->in_ep[ep_addr];
else
ep = port->out_ep[ep_addr];
/*For interrupt endpoint check for buffered data
* & complete urb
*/
if (((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)
&& ep->buffered_units > 0) {
oz_free_urb_link(urbl);
spin_unlock_bh(&port->ozhcd->hcd_lock);
oz_complete_buffered_urb(port, ep, urb);
return 0;
}
if (ep && port->hpd) {
list_add_tail(&urbl->link, &ep->urb_list);
if (!in_dir && ep_addr && (ep->credit < 0)) {
ep->last_jiffies = jiffies;
ep->credit = 0;
oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num,
0, NULL, ep->credit);
}
} else {
err = -EPIPE;
}
spin_unlock_bh(&port->ozhcd->hcd_lock);
if (err)
oz_free_urb_link(urbl);
return err;
}
/*------------------------------------------------------------------------------
* Removes an urb from the queue in the endpoint.
* Returns 0 if it is found and -EIDRM otherwise.
* Context: softirq
*/
static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
struct urb *urb)
{
struct oz_urb_link *urbl = NULL;
struct oz_endpoint *ep;
spin_lock_bh(&port->ozhcd->hcd_lock);
if (in_dir)
ep = port->in_ep[ep_addr];
else
ep = port->out_ep[ep_addr];
if (ep) {
struct list_head *e;
list_for_each(e, &ep->urb_list) {
urbl = container_of(e, struct oz_urb_link, link);
if (urbl->urb == urb) {
list_del_init(e);
break;
}
urbl = NULL;
}
}
spin_unlock_bh(&port->ozhcd->hcd_lock);
if (urbl)
oz_free_urb_link(urbl);
return urbl ? 0 : -EIDRM;
}
/*------------------------------------------------------------------------------
* Finds an urb given its request id.
* Context: softirq
*/
static struct urb *oz_find_urb_by_id(struct oz_port *port, int ep_ix,
u8 req_id)
{
struct oz_hcd *ozhcd = port->ozhcd;
struct urb *urb = NULL;
struct oz_urb_link *urbl = NULL;
struct oz_endpoint *ep;
spin_lock_bh(&ozhcd->hcd_lock);
ep = port->out_ep[ep_ix];
if (ep) {
struct list_head *e;
list_for_each(e, &ep->urb_list) {
urbl = container_of(e, struct oz_urb_link, link);
if (urbl->req_id == req_id) {
urb = urbl->urb;
list_del_init(e);
break;
}
}
}
spin_unlock_bh(&ozhcd->hcd_lock);
/* If urb is non-zero then we we must have an urb link to delete.
*/
if (urb)
oz_free_urb_link(urbl);
return urb;
}
/*------------------------------------------------------------------------------
* Pre-condition: Port lock must be held.
* Context: softirq
*/
static void oz_acquire_port(struct oz_port *port, void *hpd)
{
INIT_LIST_HEAD(&port->isoc_out_ep);
INIT_LIST_HEAD(&port->isoc_in_ep);
port->flags |= OZ_PORT_F_PRESENT | OZ_PORT_F_CHANGED;
port->status |= USB_PORT_STAT_CONNECTION |
(USB_PORT_STAT_C_CONNECTION << 16);
oz_usb_get(hpd);
port->hpd = hpd;
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
static struct oz_hcd *oz_hcd_claim(void)
{
struct oz_hcd *ozhcd;
spin_lock_bh(&g_hcdlock);
ozhcd = g_ozhcd;
if (ozhcd)
usb_get_hcd(ozhcd->hcd);
spin_unlock_bh(&g_hcdlock);
return ozhcd;
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
static inline void oz_hcd_put(struct oz_hcd *ozhcd)
{
if (ozhcd)
usb_put_hcd(ozhcd->hcd);
}
/*------------------------------------------------------------------------------
* This is called by the protocol handler to notify that a PD has arrived.
* We allocate a port to associate with the PD and create a structure for
* endpoint 0. This port is made the connection port.
* In the event that one of the other port is already a connection port then
* we fail.
* TODO We should be able to do better than fail and should be able remember
* that this port needs configuring and make it the connection port once the
* current connection port has been assigned an address. Collisions here are
* probably very rare indeed.
* Context: softirq
*/
void *oz_hcd_pd_arrived(void *hpd)
{
int i;
void *hport = NULL;
struct oz_hcd *ozhcd = NULL;
struct oz_endpoint *ep;
oz_trace("oz_hcd_pd_arrived()\n");
ozhcd = oz_hcd_claim();
if (ozhcd == NULL)
return NULL;
/* Allocate an endpoint object in advance (before holding hcd lock) to
* use for out endpoint 0.
*/
ep = oz_ep_alloc(GFP_ATOMIC, 0);
spin_lock_bh(&ozhcd->hcd_lock);
if (ozhcd->conn_port >= 0) {
spin_unlock_bh(&ozhcd->hcd_lock);
oz_trace("conn_port >= 0\n");
goto out;
}
for (i = 0; i < OZ_NB_PORTS; i++) {
struct oz_port *port = &ozhcd->ports[i];
spin_lock(&port->port_lock);
if ((port->flags & OZ_PORT_F_PRESENT) == 0) {
oz_acquire_port(port, hpd);
spin_unlock(&port->port_lock);
break;
}
spin_unlock(&port->port_lock);
}
if (i < OZ_NB_PORTS) {
oz_trace("Setting conn_port = %d\n", i);
ozhcd->conn_port = i;
/* Attach out endpoint 0.
*/
ozhcd->ports[i].out_ep[0] = ep;
ep = NULL;
hport = &ozhcd->ports[i];
spin_unlock_bh(&ozhcd->hcd_lock);
if (ozhcd->flags & OZ_HDC_F_SUSPENDED) {
oz_trace("Resuming root hub\n");
usb_hcd_resume_root_hub(ozhcd->hcd);
}
usb_hcd_poll_rh_status(ozhcd->hcd);
} else {
spin_unlock_bh(&ozhcd->hcd_lock);
}
out:
if (ep) /* ep is non-null if not used. */
oz_ep_free(NULL, ep);
oz_hcd_put(ozhcd);
return hport;
}
/*------------------------------------------------------------------------------
* This is called by the protocol handler to notify that the PD has gone away.
* We need to deallocate all resources and then request that the root hub is
* polled. We release the reference we hold on the PD.
* Context: softirq
*/
void oz_hcd_pd_departed(void *hport)
{
struct oz_port *port = (struct oz_port *)hport;
struct oz_hcd *ozhcd;
void *hpd;
struct oz_endpoint *ep = NULL;
oz_trace("oz_hcd_pd_departed()\n");
if (port == NULL) {
oz_trace("oz_hcd_pd_departed() port = 0\n");
return;
}
ozhcd = port->ozhcd;
if (ozhcd == NULL)
return;
/* Check if this is the connection port - if so clear it.
*/
spin_lock_bh(&ozhcd->hcd_lock);
if ((ozhcd->conn_port >= 0) &&
(port == &ozhcd->ports[ozhcd->conn_port])) {
oz_trace("Clearing conn_port\n");
ozhcd->conn_port = -1;
}
spin_lock(&port->port_lock);
port->flags |= OZ_PORT_F_DYING;
spin_unlock(&port->port_lock);
spin_unlock_bh(&ozhcd->hcd_lock);
oz_clean_endpoints_for_config(ozhcd->hcd, port);
spin_lock_bh(&port->port_lock);
hpd = port->hpd;
port->hpd = NULL;
port->bus_addr = 0xff;
port->flags &= ~(OZ_PORT_F_PRESENT | OZ_PORT_F_DYING);
port->flags |= OZ_PORT_F_CHANGED;
port->status &= ~USB_PORT_STAT_CONNECTION;
port->status |= (USB_PORT_STAT_C_CONNECTION << 16);
/* If there is an endpont 0 then clear the pointer while we hold
* the spinlock be we deallocate it after releasing the lock.
*/
if (port->out_ep[0]) {
ep = port->out_ep[0];
port->out_ep[0] = NULL;
}
spin_unlock_bh(&port->port_lock);
if (ep)
oz_ep_free(port, ep);
usb_hcd_poll_rh_status(ozhcd->hcd);
oz_usb_put(hpd);
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
void oz_hcd_pd_reset(void *hpd, void *hport)
{
/* Cleanup the current configuration and report reset to the core.
*/
struct oz_port *port = (struct oz_port *)hport;
struct oz_hcd *ozhcd = port->ozhcd;
oz_trace("PD Reset\n");
spin_lock_bh(&port->port_lock);
port->flags |= OZ_PORT_F_CHANGED;
port->status |= USB_PORT_STAT_RESET;
port->status |= (USB_PORT_STAT_C_RESET << 16);
spin_unlock_bh(&port->port_lock);
oz_clean_endpoints_for_config(ozhcd->hcd, port);
usb_hcd_poll_rh_status(ozhcd->hcd);
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, const u8 *desc,
int length, int offset, int total_size)
{
struct oz_port *port = (struct oz_port *)hport;
struct urb *urb;
int err = 0;
oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, NULL, status);
oz_trace("oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n",
length, offset, total_size);
urb = oz_find_urb_by_id(port, 0, req_id);
if (!urb)
return;
if (status == 0) {
int copy_len;
int required_size = urb->transfer_buffer_length;
if (required_size > total_size)
required_size = total_size;
copy_len = required_size-offset;
if (length <= copy_len)
copy_len = length;
memcpy(urb->transfer_buffer+offset, desc, copy_len);
offset += copy_len;
if (offset < required_size) {
struct usb_ctrlrequest *setup =
(struct usb_ctrlrequest *)urb->setup_packet;
unsigned wvalue = le16_to_cpu(setup->wValue);
if (oz_enqueue_ep_urb(port, 0, 0, urb, req_id))
err = -ENOMEM;
else if (oz_usb_get_desc_req(port->hpd, req_id,
setup->bRequestType, (u8)(wvalue>>8),
(u8)wvalue, setup->wIndex, offset,
required_size-offset)) {
oz_dequeue_ep_urb(port, 0, 0, urb);
err = -ENOMEM;
}
if (err == 0)
return;
}
}
urb->actual_length = total_size;
oz_complete_urb(port->ozhcd->hcd, urb, 0, 0);
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
#ifdef WANT_TRACE
static void oz_display_conf_type(u8 t)
{
switch (t) {
case USB_REQ_GET_STATUS:
oz_trace("USB_REQ_GET_STATUS - cnf\n");
break;
case USB_REQ_CLEAR_FEATURE:
oz_trace("USB_REQ_CLEAR_FEATURE - cnf\n");
break;
case USB_REQ_SET_FEATURE:
oz_trace("USB_REQ_SET_FEATURE - cnf\n");
break;
case USB_REQ_SET_ADDRESS:
oz_trace("USB_REQ_SET_ADDRESS - cnf\n");
break;
case USB_REQ_GET_DESCRIPTOR:
oz_trace("USB_REQ_GET_DESCRIPTOR - cnf\n");
break;
case USB_REQ_SET_DESCRIPTOR:
oz_trace("USB_REQ_SET_DESCRIPTOR - cnf\n");
break;
case USB_REQ_GET_CONFIGURATION:
oz_trace("USB_REQ_GET_CONFIGURATION - cnf\n");
break;
case USB_REQ_SET_CONFIGURATION:
oz_trace("USB_REQ_SET_CONFIGURATION - cnf\n");
break;
case USB_REQ_GET_INTERFACE:
oz_trace("USB_REQ_GET_INTERFACE - cnf\n");
break;
case USB_REQ_SET_INTERFACE:
oz_trace("USB_REQ_SET_INTERFACE - cnf\n");
break;
case USB_REQ_SYNCH_FRAME:
oz_trace("USB_REQ_SYNCH_FRAME - cnf\n");
break;
}
}
#else
#define oz_display_conf_type(__x)
#endif /* WANT_TRACE */
/*------------------------------------------------------------------------------
* Context: softirq
*/
static void oz_hcd_complete_set_config(struct oz_port *port, struct urb *urb,
u8 rcode, u8 config_num)
{
int rc = 0;
struct usb_hcd *hcd = port->ozhcd->hcd;
if (rcode == 0) {
port->config_num = config_num;
oz_clean_endpoints_for_config(hcd, port);
if (oz_build_endpoints_for_config(hcd, port,
&urb->dev->config[port->config_num-1], GFP_ATOMIC)) {
rc = -ENOMEM;
}
} else {
rc = -ENOMEM;
}
oz_complete_urb(hcd, urb, rc, 0);
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb,
u8 rcode, u8 if_num, u8 alt)
{
struct usb_hcd *hcd = port->ozhcd->hcd;
int rc = 0;
if (rcode == 0) {
struct usb_host_config *config;
struct usb_host_interface *intf;
oz_trace("Set interface %d alt %d\n", if_num, alt);
oz_clean_endpoints_for_interface(hcd, port, if_num);
config = &urb->dev->config[port->config_num-1];
intf = &config->intf_cache[if_num]->altsetting[alt];
if (oz_build_endpoints_for_interface(hcd, port, intf,
GFP_ATOMIC))
rc = -ENOMEM;
else
port->iface[if_num].alt = alt;
} else {
rc = -ENOMEM;
}
oz_complete_urb(hcd, urb, rc, 0);
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data,
int data_len)
{
struct oz_port *port = (struct oz_port *)hport;
struct urb *urb;
struct usb_ctrlrequest *setup;
struct usb_hcd *hcd = port->ozhcd->hcd;
unsigned windex;
unsigned wvalue;
oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, NULL, rcode);
oz_trace("oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len);
urb = oz_find_urb_by_id(port, 0, req_id);
if (!urb) {
oz_trace("URB not found\n");
return;
}
setup = (struct usb_ctrlrequest *)urb->setup_packet;
windex = le16_to_cpu(setup->wIndex);
wvalue = le16_to_cpu(setup->wValue);
if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
/* Standard requests */
oz_display_conf_type(setup->bRequest);
switch (setup->bRequest) {
case USB_REQ_SET_CONFIGURATION:
oz_hcd_complete_set_config(port, urb, rcode,
(u8)wvalue);
break;
case USB_REQ_SET_INTERFACE:
oz_hcd_complete_set_interface(port, urb, rcode,
(u8)windex, (u8)wvalue);
break;
default:
oz_complete_urb(hcd, urb, 0, 0);
}
} else {
int copy_len;
oz_trace("VENDOR-CLASS - cnf\n");
if (data_len) {
if (data_len <= urb->transfer_buffer_length)
copy_len = data_len;
else
copy_len = urb->transfer_buffer_length;
memcpy(urb->transfer_buffer, data, copy_len);
urb->actual_length = copy_len;
}
oz_complete_urb(hcd, urb, 0, 0);
}
}
/*------------------------------------------------------------------------------
* Context: softirq-serialized
*/
static int oz_hcd_buffer_data(struct oz_endpoint *ep, const u8 *data,
int data_len)
{
int space;
int copy_len;
if (!ep->buffer)
return -1;
space = ep->out_ix-ep->in_ix-1;
if (space < 0)
space += ep->buffer_size;
if (space < (data_len+1)) {
oz_trace("Buffer full\n");
return -1;
}
ep->buffer[ep->in_ix] = (u8)data_len;
if (++ep->in_ix == ep->buffer_size)
ep->in_ix = 0;
copy_len = ep->buffer_size - ep->in_ix;
if (copy_len > data_len)
copy_len = data_len;
memcpy(&ep->buffer[ep->in_ix], data, copy_len);
if (copy_len < data_len) {
memcpy(ep->buffer, data+copy_len, data_len-copy_len);
ep->in_ix = data_len-copy_len;
} else {
ep->in_ix += copy_len;
}
if (ep->in_ix == ep->buffer_size)
ep->in_ix = 0;
ep->buffered_units++;
return 0;
}
/*------------------------------------------------------------------------------
* Context: softirq-serialized
*/
void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len)
{
struct oz_port *port = (struct oz_port *)hport;
struct oz_endpoint *ep;
struct oz_hcd *ozhcd = port->ozhcd;
spin_lock_bh(&ozhcd->hcd_lock);
ep = port->in_ep[endpoint & USB_ENDPOINT_NUMBER_MASK];
if (ep == NULL)
goto done;
switch (ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) {
case USB_ENDPOINT_XFER_INT:
case USB_ENDPOINT_XFER_BULK:
if (!list_empty(&ep->urb_list)) {
struct oz_urb_link *urbl =
list_first_entry(&ep->urb_list,
struct oz_urb_link, link);
struct urb *urb;
int copy_len;
list_del_init(&urbl->link);
spin_unlock_bh(&ozhcd->hcd_lock);
urb = urbl->urb;
oz_free_urb_link(urbl);
if (data_len <= urb->transfer_buffer_length)
copy_len = data_len;
else
copy_len = urb->transfer_buffer_length;
memcpy(urb->transfer_buffer, data, copy_len);
urb->actual_length = copy_len;
oz_complete_urb(port->ozhcd->hcd, urb, 0, 0);
return;
} else {
oz_trace("buffering frame as URB is not available\n");
oz_hcd_buffer_data(ep, data, data_len);
}
break;
case USB_ENDPOINT_XFER_ISOC:
oz_hcd_buffer_data(ep, data, data_len);
break;
}
done:
spin_unlock_bh(&ozhcd->hcd_lock);
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static inline int oz_usb_get_frame_number(void)
{
return jiffies_to_msecs(get_jiffies_64());
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
int oz_hcd_heartbeat(void *hport)
{
int rc = 0;
struct oz_port *port = (struct oz_port *)hport;
struct oz_hcd *ozhcd = port->ozhcd;
struct oz_urb_link *urbl;
struct list_head xfr_list;
struct list_head *e;
struct list_head *n;
struct urb *urb;
struct oz_endpoint *ep;
unsigned long now = jiffies;
INIT_LIST_HEAD(&xfr_list);
/* Check the OUT isoc endpoints to see if any URB data can be sent.
*/
spin_lock_bh(&ozhcd->hcd_lock);
list_for_each(e, &port->isoc_out_ep) {
ep = ep_from_link(e);
if (ep->credit < 0)
continue;
ep->credit += jiffies_to_msecs(now - ep->last_jiffies);
if (ep->credit > ep->credit_ceiling)
ep->credit = ep->credit_ceiling;
oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, NULL,
ep->credit);
ep->last_jiffies = now;
while (ep->credit && !list_empty(&ep->urb_list)) {
urbl = list_first_entry(&ep->urb_list,
struct oz_urb_link, link);
urb = urbl->urb;
if ((ep->credit + 1) < urb->number_of_packets)
break;
ep->credit -= urb->number_of_packets;
oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, NULL,
ep->credit);
list_move_tail(&urbl->link, &xfr_list);
}
}
spin_unlock_bh(&ozhcd->hcd_lock);
/* Send to PD and complete URBs.
*/
list_for_each_safe(e, n, &xfr_list) {
unsigned long t;
urbl = container_of(e, struct oz_urb_link, link);
urb = urbl->urb;
t = urbl->submit_jiffies;
list_del_init(e);
urb->error_count = 0;
urb->start_frame = oz_usb_get_frame_number();
oz_usb_send_isoc(port->hpd, urbl->ep_num, urb);
oz_free_urb_link(urbl);
oz_complete_urb(port->ozhcd->hcd, urb, 0, t);
}
/* Check the IN isoc endpoints to see if any URBs can be completed.
*/
spin_lock_bh(&ozhcd->hcd_lock);
list_for_each(e, &port->isoc_in_ep) {
struct oz_endpoint *ep = ep_from_link(e);
if (ep->flags & OZ_F_EP_BUFFERING) {
if (ep->buffered_units >= OZ_IN_BUFFERING_UNITS) {
ep->flags &= ~OZ_F_EP_BUFFERING;
ep->credit = 0;
oz_event_log(OZ_EVT_EP_CREDIT,
ep->ep_num | USB_DIR_IN,
0, NULL, ep->credit);
ep->last_jiffies = now;
ep->start_frame = 0;
oz_event_log(OZ_EVT_EP_BUFFERING,
ep->ep_num | USB_DIR_IN, 0, NULL, 0);
}
continue;
}
ep->credit += jiffies_to_msecs(now - ep->last_jiffies);
oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN,
0, NULL, ep->credit);
ep->last_jiffies = now;
while (!list_empty(&ep->urb_list)) {
struct oz_urb_link *urbl =
list_first_entry(&ep->urb_list,
struct oz_urb_link, link);
struct urb *urb = urbl->urb;
int len = 0;
int copy_len;
int i;
if ((ep->credit + 1) < urb->number_of_packets)
break;
if (ep->buffered_units < urb->number_of_packets)
break;
urb->actual_length = 0;
for (i = 0; i < urb->number_of_packets; i++) {
len = ep->buffer[ep->out_ix];
if (++ep->out_ix == ep->buffer_size)
ep->out_ix = 0;
copy_len = ep->buffer_size - ep->out_ix;
if (copy_len > len)
copy_len = len;
memcpy(urb->transfer_buffer,
&ep->buffer[ep->out_ix], copy_len);
if (copy_len < len) {
memcpy(urb->transfer_buffer+copy_len,
ep->buffer, len-copy_len);
ep->out_ix = len-copy_len;
} else
ep->out_ix += copy_len;
if (ep->out_ix == ep->buffer_size)
ep->out_ix = 0;
urb->iso_frame_desc[i].offset =
urb->actual_length;
urb->actual_length += len;
urb->iso_frame_desc[i].actual_length = len;
urb->iso_frame_desc[i].status = 0;
}
ep->buffered_units -= urb->number_of_packets;
urb->error_count = 0;
urb->start_frame = ep->start_frame;
ep->start_frame += urb->number_of_packets;
list_move_tail(&urbl->link, &xfr_list);
ep->credit -= urb->number_of_packets;
oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN,
0, NULL, ep->credit);
}
}
if (!list_empty(&port->isoc_out_ep) || !list_empty(&port->isoc_in_ep))
rc = 1;
spin_unlock_bh(&ozhcd->hcd_lock);
/* Complete the filled URBs.
*/
list_for_each_safe(e, n, &xfr_list) {
urbl = container_of(e, struct oz_urb_link, link);
urb = urbl->urb;
list_del_init(e);
oz_free_urb_link(urbl);
oz_complete_urb(port->ozhcd->hcd, urb, 0, 0);
}
/* Check if there are any ep0 requests that have timed out.
* If so resent to PD.
*/
ep = port->out_ep[0];
if (ep) {
struct list_head *e;
struct list_head *n;
spin_lock_bh(&ozhcd->hcd_lock);
list_for_each_safe(e, n, &ep->urb_list) {
urbl = container_of(e, struct oz_urb_link, link);
if (time_after(now, urbl->submit_jiffies+HZ/2)) {
oz_trace("%ld: Request 0x%p timeout\n",
now, urbl->urb);
urbl->submit_jiffies = now;
list_move_tail(e, &xfr_list);
}
}
if (!list_empty(&ep->urb_list))
rc = 1;
spin_unlock_bh(&ozhcd->hcd_lock);
e = xfr_list.next;
while (e != &xfr_list) {
urbl = container_of(e, struct oz_urb_link, link);
e = e->next;
oz_trace("Resending request to PD.\n");
oz_process_ep0_urb(ozhcd, urbl->urb, GFP_ATOMIC);
oz_free_urb_link(urbl);
}
}
return rc;
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
static int oz_build_endpoints_for_interface(struct usb_hcd *hcd,
struct oz_port *port,
struct usb_host_interface *intf, gfp_t mem_flags)
{
struct oz_hcd *ozhcd = port->ozhcd;
int i;
int if_ix = intf->desc.bInterfaceNumber;
int request_heartbeat = 0;
oz_trace("interface[%d] = %p\n", if_ix, intf);
for (i = 0; i < intf->desc.bNumEndpoints; i++) {
struct usb_host_endpoint *hep = &intf->endpoint[i];
u8 ep_addr = hep->desc.bEndpointAddress;
u8 ep_num = ep_addr & USB_ENDPOINT_NUMBER_MASK;
struct oz_endpoint *ep;
int buffer_size = 0;
oz_trace("%d bEndpointAddress = %x\n", i, ep_addr);
if (ep_addr & USB_ENDPOINT_DIR_MASK) {
switch (hep->desc.bmAttributes &
USB_ENDPOINT_XFERTYPE_MASK) {
case USB_ENDPOINT_XFER_ISOC:
buffer_size = 24*1024;
break;
case USB_ENDPOINT_XFER_INT:
buffer_size = 128;
break;
}
}
ep = oz_ep_alloc(mem_flags, buffer_size);
if (!ep) {
oz_clean_endpoints_for_interface(hcd, port, if_ix);
return -ENOMEM;
}
ep->attrib = hep->desc.bmAttributes;
ep->ep_num = ep_num;
if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK)
== USB_ENDPOINT_XFER_ISOC) {
oz_trace("wMaxPacketSize = %d\n",
hep->desc.wMaxPacketSize);
ep->credit_ceiling = 200;
if (ep_addr & USB_ENDPOINT_DIR_MASK) {
ep->flags |= OZ_F_EP_BUFFERING;
oz_event_log(OZ_EVT_EP_BUFFERING,
ep->ep_num | USB_DIR_IN, 1, NULL, 0);
} else {
ep->flags |= OZ_F_EP_HAVE_STREAM;
if (oz_usb_stream_create(port->hpd, ep_num))
ep->flags &= ~OZ_F_EP_HAVE_STREAM;
}
}
spin_lock_bh(&ozhcd->hcd_lock);
if (ep_addr & USB_ENDPOINT_DIR_MASK) {
port->in_ep[ep_num] = ep;
port->iface[if_ix].ep_mask |=
(1<<(ep_num+OZ_NB_ENDPOINTS));
if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK)
== USB_ENDPOINT_XFER_ISOC) {
list_add_tail(&ep->link, &port->isoc_in_ep);
request_heartbeat = 1;
}
} else {
port->out_ep[ep_num] = ep;
port->iface[if_ix].ep_mask |= (1<<ep_num);
if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK)
== USB_ENDPOINT_XFER_ISOC) {
list_add_tail(&ep->link, &port->isoc_out_ep);
request_heartbeat = 1;
}
}
spin_unlock_bh(&ozhcd->hcd_lock);
if (request_heartbeat && port->hpd)
oz_usb_request_heartbeat(port->hpd);
}
return 0;
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd,
struct oz_port *port, int if_ix)
{
struct oz_hcd *ozhcd = port->ozhcd;
unsigned mask;
int i;
struct list_head ep_list;
oz_trace("Deleting endpoints for interface %d\n", if_ix);
if (if_ix >= port->num_iface)
return;
INIT_LIST_HEAD(&ep_list);
spin_lock_bh(&ozhcd->hcd_lock);
mask = port->iface[if_ix].ep_mask;
port->iface[if_ix].ep_mask = 0;
for (i = 0; i < OZ_NB_ENDPOINTS; i++) {
struct list_head *e;
/* Gather OUT endpoints.
*/
if ((mask & (1<<i)) && port->out_ep[i]) {
e = &port->out_ep[i]->link;
port->out_ep[i] = NULL;
/* Remove from isoc list if present.
*/
list_move_tail(e, &ep_list);
}
/* Gather IN endpoints.
*/
if ((mask & (1<<(i+OZ_NB_ENDPOINTS))) && port->in_ep[i]) {
e = &port->in_ep[i]->link;
port->in_ep[i] = NULL;
list_move_tail(e, &ep_list);
}
}
spin_unlock_bh(&ozhcd->hcd_lock);
while (!list_empty(&ep_list)) {
struct oz_endpoint *ep =
list_first_entry(&ep_list, struct oz_endpoint, link);
list_del_init(&ep->link);
oz_ep_free(port, ep);
}
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
static int oz_build_endpoints_for_config(struct usb_hcd *hcd,
struct oz_port *port, struct usb_host_config *config,
gfp_t mem_flags)
{
struct oz_hcd *ozhcd = port->ozhcd;
int i;
int num_iface = config->desc.bNumInterfaces;
if (num_iface) {
struct oz_interface *iface;
iface = kmalloc(num_iface*sizeof(struct oz_interface),
mem_flags | __GFP_ZERO);
if (!iface)
return -ENOMEM;
spin_lock_bh(&ozhcd->hcd_lock);
port->iface = iface;
port->num_iface = num_iface;
spin_unlock_bh(&ozhcd->hcd_lock);
}
for (i = 0; i < num_iface; i++) {
struct usb_host_interface *intf =
&config->intf_cache[i]->altsetting[0];
if (oz_build_endpoints_for_interface(hcd, port, intf,
mem_flags))
goto fail;
}
return 0;
fail:
oz_clean_endpoints_for_config(hcd, port);
return -1;
}
/*------------------------------------------------------------------------------
* Context: softirq
*/
static void oz_clean_endpoints_for_config(struct usb_hcd *hcd,
struct oz_port *port)
{
struct oz_hcd *ozhcd = port->ozhcd;
int i;
oz_trace("Deleting endpoints for configuration.\n");
for (i = 0; i < port->num_iface; i++)
oz_clean_endpoints_for_interface(hcd, port, i);
spin_lock_bh(&ozhcd->hcd_lock);
if (port->iface) {
oz_trace("Freeing interfaces object.\n");
kfree(port->iface);
port->iface = NULL;
}
port->num_iface = 0;
spin_unlock_bh(&ozhcd->hcd_lock);
}
/*------------------------------------------------------------------------------
* Context: tasklet
*/
static void *oz_claim_hpd(struct oz_port *port)
{
void *hpd = NULL;
struct oz_hcd *ozhcd = port->ozhcd;
spin_lock_bh(&ozhcd->hcd_lock);
hpd = port->hpd;
if (hpd)
oz_usb_get(hpd);
spin_unlock_bh(&ozhcd->hcd_lock);
return hpd;
}
/*------------------------------------------------------------------------------
* Context: tasklet
*/
static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
gfp_t mem_flags)
{
struct usb_ctrlrequest *setup;
unsigned windex;
unsigned wvalue;
unsigned wlength;
void *hpd = NULL;
u8 req_id;
int rc = 0;
unsigned complete = 0;
int port_ix = -1;
struct oz_port *port = NULL;
oz_trace2(OZ_TRACE_URB, "%lu: oz_process_ep0_urb(%p)\n", jiffies, urb);
port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum);
if (port_ix < 0) {
rc = -EPIPE;
goto out;
}
port = &ozhcd->ports[port_ix];
if (((port->flags & OZ_PORT_F_PRESENT) == 0)
|| (port->flags & OZ_PORT_F_DYING)) {
oz_trace("Refusing URB port_ix = %d devnum = %d\n",
port_ix, urb->dev->devnum);
rc = -EPIPE;
goto out;
}
/* Store port in private context data.
*/
urb->hcpriv = port;
setup = (struct usb_ctrlrequest *)urb->setup_packet;
windex = le16_to_cpu(setup->wIndex);
wvalue = le16_to_cpu(setup->wValue);
wlength = le16_to_cpu(setup->wLength);
oz_trace2(OZ_TRACE_CTRL_DETAIL, "bRequestType = %x\n",
setup->bRequestType);
oz_trace2(OZ_TRACE_CTRL_DETAIL, "bRequest = %x\n", setup->bRequest);
oz_trace2(OZ_TRACE_CTRL_DETAIL, "wValue = %x\n", wvalue);
oz_trace2(OZ_TRACE_CTRL_DETAIL, "wIndex = %x\n", windex);
oz_trace2(OZ_TRACE_CTRL_DETAIL, "wLength = %x\n", wlength);
req_id = port->next_req_id++;
hpd = oz_claim_hpd(port);
if (hpd == NULL) {
oz_trace("Cannot claim port\n");
rc = -EPIPE;
goto out;
}
if ((setup->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
/* Standard requests
*/
switch (setup->bRequest) {
case USB_REQ_GET_DESCRIPTOR:
oz_trace("USB_REQ_GET_DESCRIPTOR - req\n");
break;
case USB_REQ_SET_ADDRESS:
oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest,
0, NULL, setup->bRequestType);
oz_trace("USB_REQ_SET_ADDRESS - req\n");
oz_trace("Port %d address is 0x%x\n", ozhcd->conn_port,
(u8)le16_to_cpu(setup->wValue));
spin_lock_bh(&ozhcd->hcd_lock);
if (ozhcd->conn_port >= 0) {
ozhcd->ports[ozhcd->conn_port].bus_addr =
(u8)le16_to_cpu(setup->wValue);
oz_trace("Clearing conn_port\n");
ozhcd->conn_port = -1;
}
spin_unlock_bh(&ozhcd->hcd_lock);
complete = 1;
break;
case USB_REQ_SET_CONFIGURATION:
oz_trace("USB_REQ_SET_CONFIGURATION - req\n");
break;
case USB_REQ_GET_CONFIGURATION:
/* We short circuit this case and reply directly since
* we have the selected configuration number cached.
*/
oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0,
NULL, setup->bRequestType);
oz_trace("USB_REQ_GET_CONFIGURATION - reply now\n");
if (urb->transfer_buffer_length >= 1) {
urb->actual_length = 1;
*((u8 *)urb->transfer_buffer) =
port->config_num;
complete = 1;
} else {
rc = -EPIPE;
}
break;
case USB_REQ_GET_INTERFACE:
/* We short circuit this case and reply directly since
* we have the selected interface alternative cached.
*/
oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0,
NULL, setup->bRequestType);
oz_trace("USB_REQ_GET_INTERFACE - reply now\n");
if (urb->transfer_buffer_length >= 1) {
urb->actual_length = 1;
*((u8 *)urb->transfer_buffer) =
port->iface[(u8)windex].alt;
oz_trace("interface = %d alt = %d\n",
windex, port->iface[(u8)windex].alt);
complete = 1;
} else {
rc = -EPIPE;
}
break;
case USB_REQ_SET_INTERFACE:
oz_trace("USB_REQ_SET_INTERFACE - req\n");
break;
}
}
if (!rc && !complete) {
int data_len = 0;
if ((setup->bRequestType & USB_DIR_IN) == 0)
data_len = wlength;
urb->actual_length = data_len;
if (oz_usb_control_req(port->hpd, req_id, setup,
urb->transfer_buffer, data_len)) {
rc = -ENOMEM;
} else {
/* Note: we are queuing the request after we have
* submitted it to be transmitted. If the request were
* to complete before we queued it then it would not
* be found in the queue. It seems impossible for
* this to happen but if it did the request would
* be resubmitted so the problem would hopefully
* resolve itself. Putting the request into the
* queue before it has been sent is worse since the
* urb could be cancelled while we are using it
* to build the request.
*/
if (oz_enqueue_ep_urb(port, 0, 0, urb, req_id))
rc = -ENOMEM;
}
}
oz_usb_put(hpd);
out:
if (rc || complete) {
oz_trace("Completing request locally\n");
oz_complete_urb(ozhcd->hcd, urb, rc, 0);
} else {
oz_usb_request_heartbeat(port->hpd);
}
}
/*------------------------------------------------------------------------------
* Context: tasklet
*/
static int oz_urb_process(struct oz_hcd *ozhcd, struct urb *urb)
{
int rc = 0;
struct oz_port *port = urb->hcpriv;
u8 ep_addr;
/* When we are paranoid we keep a list of urbs which we check against
* before handing one back. This is just for debugging during
* development and should be turned off in the released driver.
*/
oz_remember_urb(urb);
/* Check buffer is valid.
*/
if (!urb->transfer_buffer && urb->transfer_buffer_length)
return -EINVAL;
/* Check if there is a device at the port - refuse if not.
*/
if ((port->flags & OZ_PORT_F_PRESENT) == 0)
return -EPIPE;
ep_addr = usb_pipeendpoint(urb->pipe);
if (ep_addr) {
/* If the request is not for EP0 then queue it.
*/
if (oz_enqueue_ep_urb(port, ep_addr, usb_pipein(urb->pipe),
urb, 0))
rc = -EPIPE;
} else {
oz_process_ep0_urb(ozhcd, urb, GFP_ATOMIC);
}
return rc;
}
/*------------------------------------------------------------------------------
* Context: tasklet
*/
static void oz_urb_process_tasklet(unsigned long unused)
{
unsigned long irq_state;
struct urb *urb;
struct oz_hcd *ozhcd = oz_hcd_claim();
int rc = 0;
if (ozhcd == NULL)
return;
/* This is called from a tasklet so is in softirq context but the urb
* list is filled from any context so we need to lock
* appropriately while removing urbs.
*/
spin_lock_irqsave(&g_tasklet_lock, irq_state);
while (!list_empty(&ozhcd->urb_pending_list)) {
struct oz_urb_link *urbl =
list_first_entry(&ozhcd->urb_pending_list,
struct oz_urb_link, link);
list_del_init(&urbl->link);
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
urb = urbl->urb;
oz_free_urb_link(urbl);
rc = oz_urb_process(ozhcd, urb);
if (rc)
oz_complete_urb(ozhcd->hcd, urb, rc, 0);
spin_lock_irqsave(&g_tasklet_lock, irq_state);
}
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
oz_hcd_put(ozhcd);
}
/*------------------------------------------------------------------------------
* This function searches for the urb in any of the lists it could be in.
* If it is found it is removed from the list and completed. If the urb is
* being processed then it won't be in a list so won't be found. However, the
* call to usb_hcd_check_unlink_urb() will set the value of the unlinked field
* to a non-zero value. When an attempt is made to put the urb back in a list
* the unlinked field will be checked and the urb will then be completed.
* Context: tasklet
*/
static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb)
{
struct oz_urb_link *urbl = NULL;
struct list_head *e;
struct oz_hcd *ozhcd;
unsigned long irq_state;
u8 ix;
if (port == NULL) {
oz_trace("ERRORERROR: oz_urb_cancel(%p) port is null\n", urb);
return;
}
ozhcd = port->ozhcd;
if (ozhcd == NULL) {
oz_trace("ERRORERROR: oz_urb_cancel(%p) ozhcd is null\n", urb);
return;
}
/* Look in the tasklet queue.
*/
spin_lock_irqsave(&g_tasklet_lock, irq_state);
list_for_each(e, &ozhcd->urb_cancel_list) {
urbl = container_of(e, struct oz_urb_link, link);
if (urb == urbl->urb) {
list_del_init(e);
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
goto out2;
}
}
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
urbl = NULL;
/* Look in the orphanage.
*/
spin_lock_irqsave(&ozhcd->hcd_lock, irq_state);
list_for_each(e, &ozhcd->orphanage) {
urbl = container_of(e, struct oz_urb_link, link);
if (urbl->urb == urb) {
list_del(e);
oz_trace("Found urb in orphanage\n");
goto out;
}
}
ix = (ep_num & 0xf);
urbl = NULL;
if ((ep_num & USB_DIR_IN) && ix)
urbl = oz_remove_urb(port->in_ep[ix], urb);
else
urbl = oz_remove_urb(port->out_ep[ix], urb);
out:
spin_unlock_irqrestore(&ozhcd->hcd_lock, irq_state);
out2:
if (urbl) {
urb->actual_length = 0;
oz_free_urb_link(urbl);
oz_complete_urb(ozhcd->hcd, urb, -EPIPE, 0);
}
}
/*------------------------------------------------------------------------------
* Context: tasklet
*/
static void oz_urb_cancel_tasklet(unsigned long unused)
{
unsigned long irq_state;
struct urb *urb;
struct oz_hcd *ozhcd = oz_hcd_claim();
if (ozhcd == NULL)
return;
spin_lock_irqsave(&g_tasklet_lock, irq_state);
while (!list_empty(&ozhcd->urb_cancel_list)) {
struct oz_urb_link *urbl =
list_first_entry(&ozhcd->urb_cancel_list,
struct oz_urb_link, link);
list_del_init(&urbl->link);
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
urb = urbl->urb;
if (urb->unlinked)
oz_urb_cancel(urbl->port, urbl->ep_num, urb);
oz_free_urb_link(urbl);
spin_lock_irqsave(&g_tasklet_lock, irq_state);
}
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
oz_hcd_put(ozhcd);
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status)
{
if (ozhcd) {
struct oz_urb_link *urbl;
while (!list_empty(&ozhcd->orphanage)) {
urbl = list_first_entry(&ozhcd->orphanage,
struct oz_urb_link, link);
list_del(&urbl->link);
oz_complete_urb(ozhcd->hcd, urbl->urb, status, 0);
oz_free_urb_link(urbl);
}
}
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static int oz_hcd_start(struct usb_hcd *hcd)
{
oz_trace("oz_hcd_start()\n");
hcd->power_budget = 200;
hcd->state = HC_STATE_RUNNING;
hcd->uses_new_polling = 1;
return 0;
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static void oz_hcd_stop(struct usb_hcd *hcd)
{
oz_trace("oz_hcd_stop()\n");
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static void oz_hcd_shutdown(struct usb_hcd *hcd)
{
oz_trace("oz_hcd_shutdown()\n");
}
/*------------------------------------------------------------------------------
* Context: any
*/
#ifdef WANT_EVENT_TRACE
static u8 oz_get_irq_ctx(void)
{
u8 irq_info = 0;
if (in_interrupt())
irq_info |= 1;
if (in_irq())
irq_info |= 2;
return irq_info;
}
#endif /* WANT_EVENT_TRACE */
/*------------------------------------------------------------------------------
* Called to queue an urb for the device.
* This function should return a non-zero error code if it fails the urb but
* should not call usb_hcd_giveback_urb().
* Context: any
*/
static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
gfp_t mem_flags)
{
struct oz_hcd *ozhcd = oz_hcd_private(hcd);
int rc = 0;
int port_ix;
struct oz_port *port;
unsigned long irq_state;
struct oz_urb_link *urbl;
oz_trace2(OZ_TRACE_URB, "%lu: oz_hcd_urb_enqueue(%p)\n",
jiffies, urb);
oz_event_log(OZ_EVT_URB_SUBMIT, oz_get_irq_ctx(),
(u16)urb->number_of_packets, urb, urb->pipe);
if (unlikely(ozhcd == NULL)) {
oz_trace2(OZ_TRACE_URB, "%lu: Refused urb(%p) not ozhcd.\n",
jiffies, urb);
return -EPIPE;
}
if (unlikely(hcd->state != HC_STATE_RUNNING)) {
oz_trace2(OZ_TRACE_URB, "%lu: Refused urb(%p) not running.\n",
jiffies, urb);
return -EPIPE;
}
port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum);
if (port_ix < 0)
return -EPIPE;
port = &ozhcd->ports[port_ix];
if (port == NULL)
return -EPIPE;
if ((port->flags & OZ_PORT_F_PRESENT) == 0) {
oz_trace("Refusing URB port_ix = %d devnum = %d\n",
port_ix, urb->dev->devnum);
return -EPIPE;
}
urb->hcpriv = port;
/* Put request in queue for processing by tasklet.
*/
urbl = oz_alloc_urb_link();
if (unlikely(urbl == NULL))
return -ENOMEM;
urbl->urb = urb;
spin_lock_irqsave(&g_tasklet_lock, irq_state);
rc = usb_hcd_link_urb_to_ep(hcd, urb);
if (unlikely(rc)) {
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
oz_free_urb_link(urbl);
return rc;
}
list_add_tail(&urbl->link, &ozhcd->urb_pending_list);
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
tasklet_schedule(&g_urb_process_tasklet);
atomic_inc(&g_pending_urbs);
return 0;
}
/*------------------------------------------------------------------------------
* Context: tasklet
*/
static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep,
struct urb *urb)
{
struct oz_urb_link *urbl = NULL;
struct list_head *e;
if (unlikely(ep == NULL))
return NULL;
list_for_each(e, &ep->urb_list) {
urbl = container_of(e, struct oz_urb_link, link);
if (urbl->urb == urb) {
list_del_init(e);
if (usb_pipeisoc(urb->pipe)) {
ep->credit -= urb->number_of_packets;
if (ep->credit < 0)
ep->credit = 0;
oz_event_log(OZ_EVT_EP_CREDIT,
usb_pipein(urb->pipe) ?
(ep->ep_num | USB_DIR_IN) : ep->ep_num,
0, NULL, ep->credit);
}
return urbl;
}
}
return NULL;
}
/*------------------------------------------------------------------------------
* Called to dequeue a previously submitted urb for the device.
* Context: any
*/
static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
{
struct oz_hcd *ozhcd = oz_hcd_private(hcd);
struct oz_urb_link *urbl = NULL;
int rc;
unsigned long irq_state;
oz_trace2(OZ_TRACE_URB, "%lu: oz_hcd_urb_dequeue(%p)\n", jiffies, urb);
urbl = oz_alloc_urb_link();
if (unlikely(urbl == NULL))
return -ENOMEM;
spin_lock_irqsave(&g_tasklet_lock, irq_state);
/* The following function checks the urb is still in the queue
* maintained by the core and that the unlinked field is zero.
* If both are true the function sets the unlinked field and returns
* zero. Otherwise it returns an error.
*/
rc = usb_hcd_check_unlink_urb(hcd, urb, status);
/* We have to check we haven't completed the urb or are about
* to complete it. When we do we set hcpriv to 0 so if this has
* already happened we don't put the urb in the cancel queue.
*/
if ((rc == 0) && urb->hcpriv) {
urbl->urb = urb;
urbl->port = (struct oz_port *)urb->hcpriv;
urbl->ep_num = usb_pipeendpoint(urb->pipe);
if (usb_pipein(urb->pipe))
urbl->ep_num |= USB_DIR_IN;
list_add_tail(&urbl->link, &ozhcd->urb_cancel_list);
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
tasklet_schedule(&g_urb_cancel_tasklet);
} else {
spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
oz_free_urb_link(urbl);
}
return rc;
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static void oz_hcd_endpoint_disable(struct usb_hcd *hcd,
struct usb_host_endpoint *ep)
{
oz_trace("oz_hcd_endpoint_disable\n");
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static void oz_hcd_endpoint_reset(struct usb_hcd *hcd,
struct usb_host_endpoint *ep)
{
oz_trace("oz_hcd_endpoint_reset\n");
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static int oz_hcd_get_frame_number(struct usb_hcd *hcd)
{
oz_trace("oz_hcd_get_frame_number\n");
return oz_usb_get_frame_number();
}
/*------------------------------------------------------------------------------
* Context: softirq
* This is called as a consquence of us calling usb_hcd_poll_rh_status() and we
* always do that in softirq context.
*/
static int oz_hcd_hub_status_data(struct usb_hcd *hcd, char *buf)
{
struct oz_hcd *ozhcd = oz_hcd_private(hcd);
int i;
oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_status_data()\n");
buf[0] = 0;
spin_lock_bh(&ozhcd->hcd_lock);
for (i = 0; i < OZ_NB_PORTS; i++) {
if (ozhcd->ports[i].flags & OZ_PORT_F_CHANGED) {
oz_trace2(OZ_TRACE_HUB, "Port %d changed\n", i);
ozhcd->ports[i].flags &= ~OZ_PORT_F_CHANGED;
buf[0] |= 1<<(i+1);
}
}
spin_unlock_bh(&ozhcd->hcd_lock);
return buf[0] ? 1 : 0;
}
/*------------------------------------------------------------------------------
* Context: process
*/
static void oz_get_hub_descriptor(struct usb_hcd *hcd,
struct usb_hub_descriptor *desc)
{
oz_trace2(OZ_TRACE_HUB, "GetHubDescriptor\n");
memset(desc, 0, sizeof(*desc));
desc->bDescriptorType = 0x29;
desc->bDescLength = 9;
desc->wHubCharacteristics = (__force __u16)
__constant_cpu_to_le16(0x0001);
desc->bNbrPorts = OZ_NB_PORTS;
}
/*------------------------------------------------------------------------------
* Context: process
*/
static int oz_set_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex)
{
struct oz_port *port;
int err = 0;
u8 port_id = (u8)windex;
struct oz_hcd *ozhcd = oz_hcd_private(hcd);
unsigned set_bits = 0;
unsigned clear_bits = 0;
oz_trace2(OZ_TRACE_HUB, "SetPortFeature\n");
if ((port_id < 1) || (port_id > OZ_NB_PORTS))
return -EPIPE;
port = &ozhcd->ports[port_id-1];
switch (wvalue) {
case USB_PORT_FEAT_CONNECTION:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_CONNECTION\n");
break;
case USB_PORT_FEAT_ENABLE:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_ENABLE\n");
break;
case USB_PORT_FEAT_SUSPEND:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_SUSPEND\n");
break;
case USB_PORT_FEAT_OVER_CURRENT:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_OVER_CURRENT\n");
break;
case USB_PORT_FEAT_RESET:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_RESET\n");
set_bits = USB_PORT_STAT_ENABLE | (USB_PORT_STAT_C_RESET<<16);
clear_bits = USB_PORT_STAT_RESET;
ozhcd->ports[port_id-1].bus_addr = 0;
break;
case USB_PORT_FEAT_POWER:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_POWER\n");
set_bits |= USB_PORT_STAT_POWER;
break;
case USB_PORT_FEAT_LOWSPEED:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_LOWSPEED\n");
break;
case USB_PORT_FEAT_C_CONNECTION:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_CONNECTION\n");
break;
case USB_PORT_FEAT_C_ENABLE:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_ENABLE\n");
break;
case USB_PORT_FEAT_C_SUSPEND:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_SUSPEND\n");
break;
case USB_PORT_FEAT_C_OVER_CURRENT:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n");
break;
case USB_PORT_FEAT_C_RESET:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_RESET\n");
break;
case USB_PORT_FEAT_TEST:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_TEST\n");
break;
case USB_PORT_FEAT_INDICATOR:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_INDICATOR\n");
break;
default:
oz_trace2(OZ_TRACE_HUB, "Other %d\n", wvalue);
break;
}
if (set_bits || clear_bits) {
spin_lock_bh(&port->port_lock);
port->status &= ~clear_bits;
port->status |= set_bits;
spin_unlock_bh(&port->port_lock);
}
oz_trace2(OZ_TRACE_HUB, "Port[%d] status = 0x%x\n", port_id,
port->status);
return err;
}
/*------------------------------------------------------------------------------
* Context: process
*/
static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex)
{
struct oz_port *port;
int err = 0;
u8 port_id = (u8)windex;
struct oz_hcd *ozhcd = oz_hcd_private(hcd);
unsigned clear_bits = 0;
oz_trace2(OZ_TRACE_HUB, "ClearPortFeature\n");
if ((port_id < 1) || (port_id > OZ_NB_PORTS))
return -EPIPE;
port = &ozhcd->ports[port_id-1];
switch (wvalue) {
case USB_PORT_FEAT_CONNECTION:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_CONNECTION\n");
break;
case USB_PORT_FEAT_ENABLE:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_ENABLE\n");
clear_bits = USB_PORT_STAT_ENABLE;
break;
case USB_PORT_FEAT_SUSPEND:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_SUSPEND\n");
break;
case USB_PORT_FEAT_OVER_CURRENT:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_OVER_CURRENT\n");
break;
case USB_PORT_FEAT_RESET:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_RESET\n");
break;
case USB_PORT_FEAT_POWER:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_POWER\n");
clear_bits |= USB_PORT_STAT_POWER;
break;
case USB_PORT_FEAT_LOWSPEED:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_LOWSPEED\n");
break;
case USB_PORT_FEAT_C_CONNECTION:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_CONNECTION\n");
clear_bits = (USB_PORT_STAT_C_CONNECTION << 16);
break;
case USB_PORT_FEAT_C_ENABLE:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_ENABLE\n");
clear_bits = (USB_PORT_STAT_C_ENABLE << 16);
break;
case USB_PORT_FEAT_C_SUSPEND:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_SUSPEND\n");
break;
case USB_PORT_FEAT_C_OVER_CURRENT:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n");
break;
case USB_PORT_FEAT_C_RESET:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_RESET\n");
clear_bits = (USB_PORT_FEAT_C_RESET << 16);
break;
case USB_PORT_FEAT_TEST:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_TEST\n");
break;
case USB_PORT_FEAT_INDICATOR:
oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_INDICATOR\n");
break;
default:
oz_trace2(OZ_TRACE_HUB, "Other %d\n", wvalue);
break;
}
if (clear_bits) {
spin_lock_bh(&port->port_lock);
port->status &= ~clear_bits;
spin_unlock_bh(&port->port_lock);
}
oz_trace2(OZ_TRACE_HUB, "Port[%d] status = 0x%x\n", port_id,
ozhcd->ports[port_id-1].status);
return err;
}
/*------------------------------------------------------------------------------
* Context: process
*/
static int oz_get_port_status(struct usb_hcd *hcd, u16 windex, char *buf)
{
struct oz_hcd *ozhcd;
u32 status = 0;
if ((windex < 1) || (windex > OZ_NB_PORTS))
return -EPIPE;
ozhcd = oz_hcd_private(hcd);
oz_trace2(OZ_TRACE_HUB, "GetPortStatus windex = %d\n", windex);
status = ozhcd->ports[windex-1].status;
put_unaligned(cpu_to_le32(status), (__le32 *)buf);
oz_trace2(OZ_TRACE_HUB, "Port[%d] status = %x\n", windex, status);
return 0;
}
/*------------------------------------------------------------------------------
* Context: process
*/
static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue,
u16 windex, char *buf, u16 wlength)
{
int err = 0;
oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_control()\n");
switch (req_type) {
case ClearHubFeature:
oz_trace2(OZ_TRACE_HUB, "ClearHubFeature: %d\n", req_type);
break;
case ClearPortFeature:
err = oz_clear_port_feature(hcd, wvalue, windex);
break;
case GetHubDescriptor:
oz_get_hub_descriptor(hcd, (struct usb_hub_descriptor *)buf);
break;
case GetHubStatus:
oz_trace2(OZ_TRACE_HUB, "GetHubStatus: req_type = 0x%x\n",
req_type);
put_unaligned(__constant_cpu_to_le32(0), (__le32 *)buf);
break;
case GetPortStatus:
err = oz_get_port_status(hcd, windex, buf);
break;
case SetHubFeature:
oz_trace2(OZ_TRACE_HUB, "SetHubFeature: %d\n", req_type);
break;
case SetPortFeature:
err = oz_set_port_feature(hcd, wvalue, windex);
break;
default:
oz_trace2(OZ_TRACE_HUB, "Other: %d\n", req_type);
break;
}
return err;
}
/*------------------------------------------------------------------------------
* Context: process
*/
static int oz_hcd_bus_suspend(struct usb_hcd *hcd)
{
struct oz_hcd *ozhcd;
oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_suspend()\n");
ozhcd = oz_hcd_private(hcd);
spin_lock_bh(&ozhcd->hcd_lock);
hcd->state = HC_STATE_SUSPENDED;
ozhcd->flags |= OZ_HDC_F_SUSPENDED;
spin_unlock_bh(&ozhcd->hcd_lock);
return 0;
}
/*------------------------------------------------------------------------------
* Context: process
*/
static int oz_hcd_bus_resume(struct usb_hcd *hcd)
{
struct oz_hcd *ozhcd;
oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_resume()\n");
ozhcd = oz_hcd_private(hcd);
spin_lock_bh(&ozhcd->hcd_lock);
ozhcd->flags &= ~OZ_HDC_F_SUSPENDED;
hcd->state = HC_STATE_RUNNING;
spin_unlock_bh(&ozhcd->hcd_lock);
return 0;
}
/*------------------------------------------------------------------------------
*/
static void oz_plat_shutdown(struct platform_device *dev)
{
oz_trace("oz_plat_shutdown()\n");
}
/*------------------------------------------------------------------------------
* Context: process
*/
static int oz_plat_probe(struct platform_device *dev)
{
int i;
int err;
struct usb_hcd *hcd;
struct oz_hcd *ozhcd;
oz_trace("oz_plat_probe()\n");
hcd = usb_create_hcd(&g_oz_hc_drv, &dev->dev, dev_name(&dev->dev));
if (hcd == NULL) {
oz_trace("Failed to created hcd object OK\n");
return -ENOMEM;
}
ozhcd = oz_hcd_private(hcd);
memset(ozhcd, 0, sizeof(*ozhcd));
INIT_LIST_HEAD(&ozhcd->urb_pending_list);
INIT_LIST_HEAD(&ozhcd->urb_cancel_list);
INIT_LIST_HEAD(&ozhcd->orphanage);
ozhcd->hcd = hcd;
ozhcd->conn_port = -1;
spin_lock_init(&ozhcd->hcd_lock);
for (i = 0; i < OZ_NB_PORTS; i++) {
struct oz_port *port = &ozhcd->ports[i];
port->ozhcd = ozhcd;
port->flags = 0;
port->status = 0;
port->bus_addr = 0xff;
spin_lock_init(&port->port_lock);
}
err = usb_add_hcd(hcd, 0, 0);
if (err) {
oz_trace("Failed to add hcd object OK\n");
usb_put_hcd(hcd);
return -1;
}
spin_lock_bh(&g_hcdlock);
g_ozhcd = ozhcd;
spin_unlock_bh(&g_hcdlock);
return 0;
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static int oz_plat_remove(struct platform_device *dev)
{
struct usb_hcd *hcd = platform_get_drvdata(dev);
struct oz_hcd *ozhcd;
oz_trace("oz_plat_remove()\n");
if (hcd == NULL)
return -1;
ozhcd = oz_hcd_private(hcd);
spin_lock_bh(&g_hcdlock);
if (ozhcd == g_ozhcd)
g_ozhcd = NULL;
spin_unlock_bh(&g_hcdlock);
oz_trace("Clearing orphanage\n");
oz_hcd_clear_orphanage(ozhcd, -EPIPE);
oz_trace("Removing hcd\n");
usb_remove_hcd(hcd);
usb_put_hcd(hcd);
oz_empty_link_pool();
return 0;
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static int oz_plat_suspend(struct platform_device *dev, pm_message_t msg)
{
oz_trace("oz_plat_suspend()\n");
return 0;
}
/*------------------------------------------------------------------------------
* Context: unknown
*/
static int oz_plat_resume(struct platform_device *dev)
{
oz_trace("oz_plat_resume()\n");
return 0;
}
/*------------------------------------------------------------------------------
* Context: process
*/
int oz_hcd_init(void)
{
int err;
if (usb_disabled())
return -ENODEV;
tasklet_init(&g_urb_process_tasklet, oz_urb_process_tasklet, 0);
tasklet_init(&g_urb_cancel_tasklet, oz_urb_cancel_tasklet, 0);
err = platform_driver_register(&g_oz_plat_drv);
oz_trace("platform_driver_register() returned %d\n", err);
if (err)
goto error;
g_plat_dev = platform_device_alloc(OZ_PLAT_DEV_NAME, -1);
if (g_plat_dev == NULL) {
err = -ENOMEM;
goto error1;
}
oz_trace("platform_device_alloc() succeeded\n");
err = platform_device_add(g_plat_dev);
if (err)
goto error2;
oz_trace("platform_device_add() succeeded\n");
return 0;
error2:
platform_device_put(g_plat_dev);
error1:
platform_driver_unregister(&g_oz_plat_drv);
error:
tasklet_disable(&g_urb_process_tasklet);
tasklet_disable(&g_urb_cancel_tasklet);
oz_trace("oz_hcd_init() failed %d\n", err);
return err;
}
/*------------------------------------------------------------------------------
* Context: process
*/
void oz_hcd_term(void)
{
tasklet_kill(&g_urb_process_tasklet);
tasklet_kill(&g_urb_cancel_tasklet);
platform_device_unregister(g_plat_dev);
platform_driver_unregister(&g_oz_plat_drv);
oz_trace("Pending urbs:%d\n", atomic_read(&g_pending_urbs));
}
| gpl-2.0 |
moksha11/nvm_3.9 | fs/quota/quota.c | 2307 | 10336 | /*
* Quota code necessary even when VFS quota support is not compiled
* into the kernel. The interesting stuff is over in dquot.c, here
* we have symbols for initial quotactl(2) handling, the sysctl(2)
* variables, etc - things needed even when quota support disabled.
*/
#include <linux/fs.h>
#include <linux/namei.h>
#include <linux/slab.h>
#include <asm/current.h>
#include <linux/uaccess.h>
#include <linux/kernel.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/capability.h>
#include <linux/quotaops.h>
#include <linux/types.h>
#include <linux/writeback.h>
static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
qid_t id)
{
switch (cmd) {
/* these commands do not require any special privilegues */
case Q_GETFMT:
case Q_SYNC:
case Q_GETINFO:
case Q_XGETQSTAT:
case Q_XQUOTASYNC:
break;
/* allow to query information for dquots we "own" */
case Q_GETQUOTA:
case Q_XGETQUOTA:
if ((type == USRQUOTA && uid_eq(current_euid(), make_kuid(current_user_ns(), id))) ||
(type == GRPQUOTA && in_egroup_p(make_kgid(current_user_ns(), id))))
break;
/*FALLTHROUGH*/
default:
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
}
return security_quotactl(cmd, type, id, sb);
}
static void quota_sync_one(struct super_block *sb, void *arg)
{
if (sb->s_qcop && sb->s_qcop->quota_sync)
sb->s_qcop->quota_sync(sb, *(int *)arg);
}
static int quota_sync_all(int type)
{
int ret;
if (type >= MAXQUOTAS)
return -EINVAL;
ret = security_quotactl(Q_SYNC, type, 0, NULL);
if (!ret)
iterate_supers(quota_sync_one, &type);
return ret;
}
static int quota_quotaon(struct super_block *sb, int type, int cmd, qid_t id,
struct path *path)
{
if (!sb->s_qcop->quota_on && !sb->s_qcop->quota_on_meta)
return -ENOSYS;
if (sb->s_qcop->quota_on_meta)
return sb->s_qcop->quota_on_meta(sb, type, id);
if (IS_ERR(path))
return PTR_ERR(path);
return sb->s_qcop->quota_on(sb, type, id, path);
}
static int quota_getfmt(struct super_block *sb, int type, void __user *addr)
{
__u32 fmt;
down_read(&sb_dqopt(sb)->dqptr_sem);
if (!sb_has_quota_active(sb, type)) {
up_read(&sb_dqopt(sb)->dqptr_sem);
return -ESRCH;
}
fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id;
up_read(&sb_dqopt(sb)->dqptr_sem);
if (copy_to_user(addr, &fmt, sizeof(fmt)))
return -EFAULT;
return 0;
}
static int quota_getinfo(struct super_block *sb, int type, void __user *addr)
{
struct if_dqinfo info;
int ret;
if (!sb->s_qcop->get_info)
return -ENOSYS;
ret = sb->s_qcop->get_info(sb, type, &info);
if (!ret && copy_to_user(addr, &info, sizeof(info)))
return -EFAULT;
return ret;
}
static int quota_setinfo(struct super_block *sb, int type, void __user *addr)
{
struct if_dqinfo info;
if (copy_from_user(&info, addr, sizeof(info)))
return -EFAULT;
if (!sb->s_qcop->set_info)
return -ENOSYS;
return sb->s_qcop->set_info(sb, type, &info);
}
static void copy_to_if_dqblk(struct if_dqblk *dst, struct fs_disk_quota *src)
{
dst->dqb_bhardlimit = src->d_blk_hardlimit;
dst->dqb_bsoftlimit = src->d_blk_softlimit;
dst->dqb_curspace = src->d_bcount;
dst->dqb_ihardlimit = src->d_ino_hardlimit;
dst->dqb_isoftlimit = src->d_ino_softlimit;
dst->dqb_curinodes = src->d_icount;
dst->dqb_btime = src->d_btimer;
dst->dqb_itime = src->d_itimer;
dst->dqb_valid = QIF_ALL;
}
static int quota_getquota(struct super_block *sb, int type, qid_t id,
void __user *addr)
{
struct kqid qid;
struct fs_disk_quota fdq;
struct if_dqblk idq;
int ret;
if (!sb->s_qcop->get_dqblk)
return -ENOSYS;
qid = make_kqid(current_user_ns(), type, id);
if (!qid_valid(qid))
return -EINVAL;
ret = sb->s_qcop->get_dqblk(sb, qid, &fdq);
if (ret)
return ret;
copy_to_if_dqblk(&idq, &fdq);
if (copy_to_user(addr, &idq, sizeof(idq)))
return -EFAULT;
return 0;
}
static void copy_from_if_dqblk(struct fs_disk_quota *dst, struct if_dqblk *src)
{
dst->d_blk_hardlimit = src->dqb_bhardlimit;
dst->d_blk_softlimit = src->dqb_bsoftlimit;
dst->d_bcount = src->dqb_curspace;
dst->d_ino_hardlimit = src->dqb_ihardlimit;
dst->d_ino_softlimit = src->dqb_isoftlimit;
dst->d_icount = src->dqb_curinodes;
dst->d_btimer = src->dqb_btime;
dst->d_itimer = src->dqb_itime;
dst->d_fieldmask = 0;
if (src->dqb_valid & QIF_BLIMITS)
dst->d_fieldmask |= FS_DQ_BSOFT | FS_DQ_BHARD;
if (src->dqb_valid & QIF_SPACE)
dst->d_fieldmask |= FS_DQ_BCOUNT;
if (src->dqb_valid & QIF_ILIMITS)
dst->d_fieldmask |= FS_DQ_ISOFT | FS_DQ_IHARD;
if (src->dqb_valid & QIF_INODES)
dst->d_fieldmask |= FS_DQ_ICOUNT;
if (src->dqb_valid & QIF_BTIME)
dst->d_fieldmask |= FS_DQ_BTIMER;
if (src->dqb_valid & QIF_ITIME)
dst->d_fieldmask |= FS_DQ_ITIMER;
}
static int quota_setquota(struct super_block *sb, int type, qid_t id,
void __user *addr)
{
struct fs_disk_quota fdq;
struct if_dqblk idq;
struct kqid qid;
if (copy_from_user(&idq, addr, sizeof(idq)))
return -EFAULT;
if (!sb->s_qcop->set_dqblk)
return -ENOSYS;
qid = make_kqid(current_user_ns(), type, id);
if (!qid_valid(qid))
return -EINVAL;
copy_from_if_dqblk(&fdq, &idq);
return sb->s_qcop->set_dqblk(sb, qid, &fdq);
}
static int quota_setxstate(struct super_block *sb, int cmd, void __user *addr)
{
__u32 flags;
if (copy_from_user(&flags, addr, sizeof(flags)))
return -EFAULT;
if (!sb->s_qcop->set_xstate)
return -ENOSYS;
return sb->s_qcop->set_xstate(sb, flags, cmd);
}
static int quota_getxstate(struct super_block *sb, void __user *addr)
{
struct fs_quota_stat fqs;
int ret;
if (!sb->s_qcop->get_xstate)
return -ENOSYS;
ret = sb->s_qcop->get_xstate(sb, &fqs);
if (!ret && copy_to_user(addr, &fqs, sizeof(fqs)))
return -EFAULT;
return ret;
}
static int quota_setxquota(struct super_block *sb, int type, qid_t id,
void __user *addr)
{
struct fs_disk_quota fdq;
struct kqid qid;
if (copy_from_user(&fdq, addr, sizeof(fdq)))
return -EFAULT;
if (!sb->s_qcop->set_dqblk)
return -ENOSYS;
qid = make_kqid(current_user_ns(), type, id);
if (!qid_valid(qid))
return -EINVAL;
return sb->s_qcop->set_dqblk(sb, qid, &fdq);
}
static int quota_getxquota(struct super_block *sb, int type, qid_t id,
void __user *addr)
{
struct fs_disk_quota fdq;
struct kqid qid;
int ret;
if (!sb->s_qcop->get_dqblk)
return -ENOSYS;
qid = make_kqid(current_user_ns(), type, id);
if (!qid_valid(qid))
return -EINVAL;
ret = sb->s_qcop->get_dqblk(sb, qid, &fdq);
if (!ret && copy_to_user(addr, &fdq, sizeof(fdq)))
return -EFAULT;
return ret;
}
/* Copy parameters and call proper function */
static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
void __user *addr, struct path *path)
{
int ret;
if (type >= (XQM_COMMAND(cmd) ? XQM_MAXQUOTAS : MAXQUOTAS))
return -EINVAL;
if (!sb->s_qcop)
return -ENOSYS;
ret = check_quotactl_permission(sb, type, cmd, id);
if (ret < 0)
return ret;
switch (cmd) {
case Q_QUOTAON:
return quota_quotaon(sb, type, cmd, id, path);
case Q_QUOTAOFF:
if (!sb->s_qcop->quota_off)
return -ENOSYS;
return sb->s_qcop->quota_off(sb, type);
case Q_GETFMT:
return quota_getfmt(sb, type, addr);
case Q_GETINFO:
return quota_getinfo(sb, type, addr);
case Q_SETINFO:
return quota_setinfo(sb, type, addr);
case Q_GETQUOTA:
return quota_getquota(sb, type, id, addr);
case Q_SETQUOTA:
return quota_setquota(sb, type, id, addr);
case Q_SYNC:
if (!sb->s_qcop->quota_sync)
return -ENOSYS;
return sb->s_qcop->quota_sync(sb, type);
case Q_XQUOTAON:
case Q_XQUOTAOFF:
case Q_XQUOTARM:
return quota_setxstate(sb, cmd, addr);
case Q_XGETQSTAT:
return quota_getxstate(sb, addr);
case Q_XSETQLIM:
return quota_setxquota(sb, type, id, addr);
case Q_XGETQUOTA:
return quota_getxquota(sb, type, id, addr);
case Q_XQUOTASYNC:
if (sb->s_flags & MS_RDONLY)
return -EROFS;
/* XFS quotas are fully coherent now, making this call a noop */
return 0;
default:
return -EINVAL;
}
}
#ifdef CONFIG_BLOCK
/* Return 1 if 'cmd' will block on frozen filesystem */
static int quotactl_cmd_write(int cmd)
{
switch (cmd) {
case Q_GETFMT:
case Q_GETINFO:
case Q_SYNC:
case Q_XGETQSTAT:
case Q_XGETQUOTA:
case Q_XQUOTASYNC:
return 0;
}
return 1;
}
#endif /* CONFIG_BLOCK */
/*
* look up a superblock on which quota ops will be performed
* - use the name of a block device to find the superblock thereon
*/
static struct super_block *quotactl_block(const char __user *special, int cmd)
{
#ifdef CONFIG_BLOCK
struct block_device *bdev;
struct super_block *sb;
struct filename *tmp = getname(special);
if (IS_ERR(tmp))
return ERR_CAST(tmp);
bdev = lookup_bdev(tmp->name);
putname(tmp);
if (IS_ERR(bdev))
return ERR_CAST(bdev);
if (quotactl_cmd_write(cmd))
sb = get_super_thawed(bdev);
else
sb = get_super(bdev);
bdput(bdev);
if (!sb)
return ERR_PTR(-ENODEV);
return sb;
#else
return ERR_PTR(-ENODEV);
#endif
}
/*
* This is the system call interface. This communicates with
* the user-level programs. Currently this only supports diskquota
* calls. Maybe we need to add the process quotas etc. in the future,
* but we probably should use rlimits for that.
*/
SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
qid_t, id, void __user *, addr)
{
uint cmds, type;
struct super_block *sb = NULL;
struct path path, *pathp = NULL;
int ret;
cmds = cmd >> SUBCMDSHIFT;
type = cmd & SUBCMDMASK;
/*
* As a special case Q_SYNC can be called without a specific device.
* It will iterate all superblocks that have quota enabled and call
* the sync action on each of them.
*/
if (!special) {
if (cmds == Q_SYNC)
return quota_sync_all(type);
return -ENODEV;
}
/*
* Path for quotaon has to be resolved before grabbing superblock
* because that gets s_umount sem which is also possibly needed by path
* resolution (think about autofs) and thus deadlocks could arise.
*/
if (cmds == Q_QUOTAON) {
ret = user_path_at(AT_FDCWD, addr, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &path);
if (ret)
pathp = ERR_PTR(ret);
else
pathp = &path;
}
sb = quotactl_block(special, cmds);
if (IS_ERR(sb)) {
ret = PTR_ERR(sb);
goto out;
}
ret = do_quotactl(sb, type, cmds, id, addr, pathp);
drop_super(sb);
out:
if (pathp && !IS_ERR(pathp))
path_put(pathp);
return ret;
}
| gpl-2.0 |
cuboxi/android_kernel_imx6_cuboxi | drivers/char/mspec.c | 2307 | 10946 | /*
* Copyright (C) 2001-2006 Silicon Graphics, Inc. All rights
* reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*/
/*
* SN Platform Special Memory (mspec) Support
*
* This driver exports the SN special memory (mspec) facility to user
* processes.
* There are three types of memory made available thru this driver:
* fetchops, uncached and cached.
*
* Fetchops are atomic memory operations that are implemented in the
* memory controller on SGI SN hardware.
*
* Uncached are used for memory write combining feature of the ia64
* cpu.
*
* Cached are used for areas of memory that are used as cached addresses
* on our partition and used as uncached addresses from other partitions.
* Due to a design constraint of the SN2 Shub, you can not have processors
* on the same FSB perform both a cached and uncached reference to the
* same cache line. These special memory cached regions prevent the
* kernel from ever dropping in a TLB entry and therefore prevent the
* processor from ever speculating a cache line from this page.
*/
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
#include <linux/spinlock.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/vmalloc.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/numa.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <linux/atomic.h>
#include <asm/tlbflush.h>
#include <asm/uncached.h>
#include <asm/sn/addrs.h>
#include <asm/sn/arch.h>
#include <asm/sn/mspec.h>
#include <asm/sn/sn_cpuid.h>
#include <asm/sn/io.h>
#include <asm/sn/bte.h>
#include <asm/sn/shubio.h>
#define FETCHOP_ID "SGI Fetchop,"
#define CACHED_ID "Cached,"
#define UNCACHED_ID "Uncached"
#define REVISION "4.0"
#define MSPEC_BASENAME "mspec"
/*
* Page types allocated by the device.
*/
enum mspec_page_type {
MSPEC_FETCHOP = 1,
MSPEC_CACHED,
MSPEC_UNCACHED
};
#ifdef CONFIG_SGI_SN
static int is_sn2;
#else
#define is_sn2 0
#endif
/*
* One of these structures is allocated when an mspec region is mmaped. The
* structure is pointed to by the vma->vm_private_data field in the vma struct.
* This structure is used to record the addresses of the mspec pages.
* This structure is shared by all vma's that are split off from the
* original vma when split_vma()'s are done.
*
* The refcnt is incremented atomically because mm->mmap_sem does not
* protect in fork case where multiple tasks share the vma_data.
*/
struct vma_data {
atomic_t refcnt; /* Number of vmas sharing the data. */
spinlock_t lock; /* Serialize access to this structure. */
int count; /* Number of pages allocated. */
enum mspec_page_type type; /* Type of pages allocated. */
int flags; /* See VMD_xxx below. */
unsigned long vm_start; /* Original (unsplit) base. */
unsigned long vm_end; /* Original (unsplit) end. */
unsigned long maddr[0]; /* Array of MSPEC addresses. */
};
#define VMD_VMALLOCED 0x1 /* vmalloc'd rather than kmalloc'd */
/* used on shub2 to clear FOP cache in the HUB */
static unsigned long scratch_page[MAX_NUMNODES];
#define SH2_AMO_CACHE_ENTRIES 4
static inline int
mspec_zero_block(unsigned long addr, int len)
{
int status;
if (is_sn2) {
if (is_shub2()) {
int nid;
void *p;
int i;
nid = nasid_to_cnodeid(get_node_number(__pa(addr)));
p = (void *)TO_AMO(scratch_page[nid]);
for (i=0; i < SH2_AMO_CACHE_ENTRIES; i++) {
FETCHOP_LOAD_OP(p, FETCHOP_LOAD);
p += FETCHOP_VAR_SIZE;
}
}
status = bte_copy(0, addr & ~__IA64_UNCACHED_OFFSET, len,
BTE_WACQUIRE | BTE_ZERO_FILL, NULL);
} else {
memset((char *) addr, 0, len);
status = 0;
}
return status;
}
/*
* mspec_open
*
* Called when a device mapping is created by a means other than mmap
* (via fork, munmap, etc.). Increments the reference count on the
* underlying mspec data so it is not freed prematurely.
*/
static void
mspec_open(struct vm_area_struct *vma)
{
struct vma_data *vdata;
vdata = vma->vm_private_data;
atomic_inc(&vdata->refcnt);
}
/*
* mspec_close
*
* Called when unmapping a device mapping. Frees all mspec pages
* belonging to all the vma's sharing this vma_data structure.
*/
static void
mspec_close(struct vm_area_struct *vma)
{
struct vma_data *vdata;
int index, last_index;
unsigned long my_page;
vdata = vma->vm_private_data;
if (!atomic_dec_and_test(&vdata->refcnt))
return;
last_index = (vdata->vm_end - vdata->vm_start) >> PAGE_SHIFT;
for (index = 0; index < last_index; index++) {
if (vdata->maddr[index] == 0)
continue;
/*
* Clear the page before sticking it back
* into the pool.
*/
my_page = vdata->maddr[index];
vdata->maddr[index] = 0;
if (!mspec_zero_block(my_page, PAGE_SIZE))
uncached_free_page(my_page, 1);
else
printk(KERN_WARNING "mspec_close(): "
"failed to zero page %ld\n", my_page);
}
if (vdata->flags & VMD_VMALLOCED)
vfree(vdata);
else
kfree(vdata);
}
/*
* mspec_fault
*
* Creates a mspec page and maps it to user space.
*/
static int
mspec_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
{
unsigned long paddr, maddr;
unsigned long pfn;
pgoff_t index = vmf->pgoff;
struct vma_data *vdata = vma->vm_private_data;
maddr = (volatile unsigned long) vdata->maddr[index];
if (maddr == 0) {
maddr = uncached_alloc_page(numa_node_id(), 1);
if (maddr == 0)
return VM_FAULT_OOM;
spin_lock(&vdata->lock);
if (vdata->maddr[index] == 0) {
vdata->count++;
vdata->maddr[index] = maddr;
} else {
uncached_free_page(maddr, 1);
maddr = vdata->maddr[index];
}
spin_unlock(&vdata->lock);
}
if (vdata->type == MSPEC_FETCHOP)
paddr = TO_AMO(maddr);
else
paddr = maddr & ~__IA64_UNCACHED_OFFSET;
pfn = paddr >> PAGE_SHIFT;
/*
* vm_insert_pfn can fail with -EBUSY, but in that case it will
* be because another thread has installed the pte first, so it
* is no problem.
*/
vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn);
return VM_FAULT_NOPAGE;
}
static const struct vm_operations_struct mspec_vm_ops = {
.open = mspec_open,
.close = mspec_close,
.fault = mspec_fault,
};
/*
* mspec_mmap
*
* Called when mmapping the device. Initializes the vma with a fault handler
* and private data structure necessary to allocate, track, and free the
* underlying pages.
*/
static int
mspec_mmap(struct file *file, struct vm_area_struct *vma,
enum mspec_page_type type)
{
struct vma_data *vdata;
int pages, vdata_size, flags = 0;
if (vma->vm_pgoff != 0)
return -EINVAL;
if ((vma->vm_flags & VM_SHARED) == 0)
return -EINVAL;
if ((vma->vm_flags & VM_WRITE) == 0)
return -EPERM;
pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
vdata_size = sizeof(struct vma_data) + pages * sizeof(long);
if (vdata_size <= PAGE_SIZE)
vdata = kzalloc(vdata_size, GFP_KERNEL);
else {
vdata = vzalloc(vdata_size);
flags = VMD_VMALLOCED;
}
if (!vdata)
return -ENOMEM;
vdata->vm_start = vma->vm_start;
vdata->vm_end = vma->vm_end;
vdata->flags = flags;
vdata->type = type;
spin_lock_init(&vdata->lock);
atomic_set(&vdata->refcnt, 1);
vma->vm_private_data = vdata;
vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;
if (vdata->type == MSPEC_FETCHOP || vdata->type == MSPEC_UNCACHED)
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
vma->vm_ops = &mspec_vm_ops;
return 0;
}
static int
fetchop_mmap(struct file *file, struct vm_area_struct *vma)
{
return mspec_mmap(file, vma, MSPEC_FETCHOP);
}
static int
cached_mmap(struct file *file, struct vm_area_struct *vma)
{
return mspec_mmap(file, vma, MSPEC_CACHED);
}
static int
uncached_mmap(struct file *file, struct vm_area_struct *vma)
{
return mspec_mmap(file, vma, MSPEC_UNCACHED);
}
static const struct file_operations fetchop_fops = {
.owner = THIS_MODULE,
.mmap = fetchop_mmap,
.llseek = noop_llseek,
};
static struct miscdevice fetchop_miscdev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "sgi_fetchop",
.fops = &fetchop_fops
};
static const struct file_operations cached_fops = {
.owner = THIS_MODULE,
.mmap = cached_mmap,
.llseek = noop_llseek,
};
static struct miscdevice cached_miscdev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "mspec_cached",
.fops = &cached_fops
};
static const struct file_operations uncached_fops = {
.owner = THIS_MODULE,
.mmap = uncached_mmap,
.llseek = noop_llseek,
};
static struct miscdevice uncached_miscdev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "mspec_uncached",
.fops = &uncached_fops
};
/*
* mspec_init
*
* Called at boot time to initialize the mspec facility.
*/
static int __init
mspec_init(void)
{
int ret;
int nid;
/*
* The fetchop device only works on SN2 hardware, uncached and cached
* memory drivers should both be valid on all ia64 hardware
*/
#ifdef CONFIG_SGI_SN
if (ia64_platform_is("sn2")) {
is_sn2 = 1;
if (is_shub2()) {
ret = -ENOMEM;
for_each_node_state(nid, N_ONLINE) {
int actual_nid;
int nasid;
unsigned long phys;
scratch_page[nid] = uncached_alloc_page(nid, 1);
if (scratch_page[nid] == 0)
goto free_scratch_pages;
phys = __pa(scratch_page[nid]);
nasid = get_node_number(phys);
actual_nid = nasid_to_cnodeid(nasid);
if (actual_nid != nid)
goto free_scratch_pages;
}
}
ret = misc_register(&fetchop_miscdev);
if (ret) {
printk(KERN_ERR
"%s: failed to register device %i\n",
FETCHOP_ID, ret);
goto free_scratch_pages;
}
}
#endif
ret = misc_register(&cached_miscdev);
if (ret) {
printk(KERN_ERR "%s: failed to register device %i\n",
CACHED_ID, ret);
if (is_sn2)
misc_deregister(&fetchop_miscdev);
goto free_scratch_pages;
}
ret = misc_register(&uncached_miscdev);
if (ret) {
printk(KERN_ERR "%s: failed to register device %i\n",
UNCACHED_ID, ret);
misc_deregister(&cached_miscdev);
if (is_sn2)
misc_deregister(&fetchop_miscdev);
goto free_scratch_pages;
}
printk(KERN_INFO "%s %s initialized devices: %s %s %s\n",
MSPEC_BASENAME, REVISION, is_sn2 ? FETCHOP_ID : "",
CACHED_ID, UNCACHED_ID);
return 0;
free_scratch_pages:
for_each_node(nid) {
if (scratch_page[nid] != 0)
uncached_free_page(scratch_page[nid], 1);
}
return ret;
}
static void __exit
mspec_exit(void)
{
int nid;
misc_deregister(&uncached_miscdev);
misc_deregister(&cached_miscdev);
if (is_sn2) {
misc_deregister(&fetchop_miscdev);
for_each_node(nid) {
if (scratch_page[nid] != 0)
uncached_free_page(scratch_page[nid], 1);
}
}
}
module_init(mspec_init);
module_exit(mspec_exit);
MODULE_AUTHOR("Silicon Graphics, Inc. <linux-altix@sgi.com>");
MODULE_DESCRIPTION("Driver for SGI SN special memory operations");
MODULE_LICENSE("GPL");
| gpl-2.0 |
aapav01/android_kernel_samsung_j7elte | drivers/gpu/drm/gma500/oaktrail_hdmi.c | 2307 | 25135 | /*
* Copyright © 2010 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Authors:
* Li Peng <peng.li@intel.com>
*/
#include <drm/drmP.h>
#include <drm/drm.h>
#include "psb_intel_drv.h"
#include "psb_intel_reg.h"
#include "psb_drv.h"
#define HDMI_READ(reg) readl(hdmi_dev->regs + (reg))
#define HDMI_WRITE(reg, val) writel(val, hdmi_dev->regs + (reg))
#define HDMI_HCR 0x1000
#define HCR_ENABLE_HDCP (1 << 5)
#define HCR_ENABLE_AUDIO (1 << 2)
#define HCR_ENABLE_PIXEL (1 << 1)
#define HCR_ENABLE_TMDS (1 << 0)
#define HDMI_HICR 0x1004
#define HDMI_HSR 0x1008
#define HDMI_HISR 0x100C
#define HDMI_DETECT_HDP (1 << 0)
#define HDMI_VIDEO_REG 0x3000
#define HDMI_UNIT_EN (1 << 7)
#define HDMI_MODE_OUTPUT (1 << 0)
#define HDMI_HBLANK_A 0x3100
#define HDMI_AUDIO_CTRL 0x4000
#define HDMI_ENABLE_AUDIO (1 << 0)
#define PCH_HTOTAL_B 0x3100
#define PCH_HBLANK_B 0x3104
#define PCH_HSYNC_B 0x3108
#define PCH_VTOTAL_B 0x310C
#define PCH_VBLANK_B 0x3110
#define PCH_VSYNC_B 0x3114
#define PCH_PIPEBSRC 0x311C
#define PCH_PIPEB_DSL 0x3800
#define PCH_PIPEB_SLC 0x3804
#define PCH_PIPEBCONF 0x3808
#define PCH_PIPEBSTAT 0x3824
#define CDVO_DFT 0x5000
#define CDVO_SLEWRATE 0x5004
#define CDVO_STRENGTH 0x5008
#define CDVO_RCOMP 0x500C
#define DPLL_CTRL 0x6000
#define DPLL_PDIV_SHIFT 16
#define DPLL_PDIV_MASK (0xf << 16)
#define DPLL_PWRDN (1 << 4)
#define DPLL_RESET (1 << 3)
#define DPLL_FASTEN (1 << 2)
#define DPLL_ENSTAT (1 << 1)
#define DPLL_DITHEN (1 << 0)
#define DPLL_DIV_CTRL 0x6004
#define DPLL_CLKF_MASK 0xffffffc0
#define DPLL_CLKR_MASK (0x3f)
#define DPLL_CLK_ENABLE 0x6008
#define DPLL_EN_DISP (1 << 31)
#define DPLL_SEL_HDMI (1 << 8)
#define DPLL_EN_HDMI (1 << 1)
#define DPLL_EN_VGA (1 << 0)
#define DPLL_ADJUST 0x600C
#define DPLL_STATUS 0x6010
#define DPLL_UPDATE 0x6014
#define DPLL_DFT 0x6020
struct intel_range {
int min, max;
};
struct oaktrail_hdmi_limit {
struct intel_range vco, np, nr, nf;
};
struct oaktrail_hdmi_clock {
int np;
int nr;
int nf;
int dot;
};
#define VCO_MIN 320000
#define VCO_MAX 1650000
#define NP_MIN 1
#define NP_MAX 15
#define NR_MIN 1
#define NR_MAX 64
#define NF_MIN 2
#define NF_MAX 4095
static const struct oaktrail_hdmi_limit oaktrail_hdmi_limit = {
.vco = { .min = VCO_MIN, .max = VCO_MAX },
.np = { .min = NP_MIN, .max = NP_MAX },
.nr = { .min = NR_MIN, .max = NR_MAX },
.nf = { .min = NF_MIN, .max = NF_MAX },
};
static void oaktrail_hdmi_audio_enable(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = dev->dev_private;
struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
HDMI_WRITE(HDMI_HCR, 0x67);
HDMI_READ(HDMI_HCR);
HDMI_WRITE(0x51a8, 0x10);
HDMI_READ(0x51a8);
HDMI_WRITE(HDMI_AUDIO_CTRL, 0x1);
HDMI_READ(HDMI_AUDIO_CTRL);
}
static void oaktrail_hdmi_audio_disable(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = dev->dev_private;
struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
HDMI_WRITE(0x51a8, 0x0);
HDMI_READ(0x51a8);
HDMI_WRITE(HDMI_AUDIO_CTRL, 0x0);
HDMI_READ(HDMI_AUDIO_CTRL);
HDMI_WRITE(HDMI_HCR, 0x47);
HDMI_READ(HDMI_HCR);
}
static void wait_for_vblank(struct drm_device *dev)
{
/* Wait for 20ms, i.e. one cycle at 50hz. */
mdelay(20);
}
static unsigned int htotal_calculate(struct drm_display_mode *mode)
{
u32 htotal, new_crtc_htotal;
htotal = (mode->crtc_hdisplay - 1) | ((mode->crtc_htotal - 1) << 16);
/*
* 1024 x 768 new_crtc_htotal = 0x1024;
* 1280 x 1024 new_crtc_htotal = 0x0c34;
*/
new_crtc_htotal = (mode->crtc_htotal - 1) * 200 * 1000 / mode->clock;
DRM_DEBUG_KMS("new crtc htotal 0x%4x\n", new_crtc_htotal);
return (mode->crtc_hdisplay - 1) | (new_crtc_htotal << 16);
}
static void oaktrail_hdmi_find_dpll(struct drm_crtc *crtc, int target,
int refclk, struct oaktrail_hdmi_clock *best_clock)
{
int np_min, np_max, nr_min, nr_max;
int np, nr, nf;
np_min = DIV_ROUND_UP(oaktrail_hdmi_limit.vco.min, target * 10);
np_max = oaktrail_hdmi_limit.vco.max / (target * 10);
if (np_min < oaktrail_hdmi_limit.np.min)
np_min = oaktrail_hdmi_limit.np.min;
if (np_max > oaktrail_hdmi_limit.np.max)
np_max = oaktrail_hdmi_limit.np.max;
nr_min = DIV_ROUND_UP((refclk * 1000), (target * 10 * np_max));
nr_max = DIV_ROUND_UP((refclk * 1000), (target * 10 * np_min));
if (nr_min < oaktrail_hdmi_limit.nr.min)
nr_min = oaktrail_hdmi_limit.nr.min;
if (nr_max > oaktrail_hdmi_limit.nr.max)
nr_max = oaktrail_hdmi_limit.nr.max;
np = DIV_ROUND_UP((refclk * 1000), (target * 10 * nr_max));
nr = DIV_ROUND_UP((refclk * 1000), (target * 10 * np));
nf = DIV_ROUND_CLOSEST((target * 10 * np * nr), refclk);
DRM_DEBUG_KMS("np, nr, nf %d %d %d\n", np, nr, nf);
/*
* 1024 x 768 np = 1; nr = 0x26; nf = 0x0fd8000;
* 1280 x 1024 np = 1; nr = 0x17; nf = 0x1034000;
*/
best_clock->np = np;
best_clock->nr = nr - 1;
best_clock->nf = (nf << 14);
}
static void scu_busy_loop(void __iomem *scu_base)
{
u32 status = 0;
u32 loop_count = 0;
status = readl(scu_base + 0x04);
while (status & 1) {
udelay(1); /* scu processing time is in few u secods */
status = readl(scu_base + 0x04);
loop_count++;
/* break if scu doesn't reset busy bit after huge retry */
if (loop_count > 1000) {
DRM_DEBUG_KMS("SCU IPC timed out");
return;
}
}
}
/*
* You don't want to know, you really really don't want to know....
*
* This is magic. However it's safe magic because of the way the platform
* works and it is necessary magic.
*/
static void oaktrail_hdmi_reset(struct drm_device *dev)
{
void __iomem *base;
unsigned long scu_ipc_mmio = 0xff11c000UL;
int scu_len = 1024;
base = ioremap((resource_size_t)scu_ipc_mmio, scu_len);
if (base == NULL) {
DRM_ERROR("failed to map scu mmio\n");
return;
}
/* scu ipc: assert hdmi controller reset */
writel(0xff11d118, base + 0x0c);
writel(0x7fffffdf, base + 0x80);
writel(0x42005, base + 0x0);
scu_busy_loop(base);
/* scu ipc: de-assert hdmi controller reset */
writel(0xff11d118, base + 0x0c);
writel(0x7fffffff, base + 0x80);
writel(0x42005, base + 0x0);
scu_busy_loop(base);
iounmap(base);
}
int oaktrail_crtc_hdmi_mode_set(struct drm_crtc *crtc,
struct drm_display_mode *mode,
struct drm_display_mode *adjusted_mode,
int x, int y,
struct drm_framebuffer *old_fb)
{
struct drm_device *dev = crtc->dev;
struct drm_psb_private *dev_priv = dev->dev_private;
struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
int pipe = 1;
int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
int dspsize_reg = (pipe == 0) ? DSPASIZE : DSPBSIZE;
int dsppos_reg = (pipe == 0) ? DSPAPOS : DSPBPOS;
int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
int refclk;
struct oaktrail_hdmi_clock clock;
u32 dspcntr, pipeconf, dpll, temp;
int dspcntr_reg = DSPBCNTR;
if (!gma_power_begin(dev, true))
return 0;
/* Disable the VGA plane that we never use */
REG_WRITE(VGACNTRL, VGA_DISP_DISABLE);
/* Disable dpll if necessary */
dpll = REG_READ(DPLL_CTRL);
if ((dpll & DPLL_PWRDN) == 0) {
REG_WRITE(DPLL_CTRL, dpll | (DPLL_PWRDN | DPLL_RESET));
REG_WRITE(DPLL_DIV_CTRL, 0x00000000);
REG_WRITE(DPLL_STATUS, 0x1);
}
udelay(150);
/* Reset controller */
oaktrail_hdmi_reset(dev);
/* program and enable dpll */
refclk = 25000;
oaktrail_hdmi_find_dpll(crtc, adjusted_mode->clock, refclk, &clock);
/* Set the DPLL */
dpll = REG_READ(DPLL_CTRL);
dpll &= ~DPLL_PDIV_MASK;
dpll &= ~(DPLL_PWRDN | DPLL_RESET);
REG_WRITE(DPLL_CTRL, 0x00000008);
REG_WRITE(DPLL_DIV_CTRL, ((clock.nf << 6) | clock.nr));
REG_WRITE(DPLL_ADJUST, ((clock.nf >> 14) - 1));
REG_WRITE(DPLL_CTRL, (dpll | (clock.np << DPLL_PDIV_SHIFT) | DPLL_ENSTAT | DPLL_DITHEN));
REG_WRITE(DPLL_UPDATE, 0x80000000);
REG_WRITE(DPLL_CLK_ENABLE, 0x80050102);
udelay(150);
/* configure HDMI */
HDMI_WRITE(0x1004, 0x1fd);
HDMI_WRITE(0x2000, 0x1);
HDMI_WRITE(0x2008, 0x0);
HDMI_WRITE(0x3130, 0x8);
HDMI_WRITE(0x101c, 0x1800810);
temp = htotal_calculate(adjusted_mode);
REG_WRITE(htot_reg, temp);
REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
REG_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) | ((adjusted_mode->crtc_vtotal - 1) << 16));
REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) | ((adjusted_mode->crtc_vblank_end - 1) << 16));
REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
REG_WRITE(pipesrc_reg, ((mode->crtc_hdisplay - 1) << 16) | (mode->crtc_vdisplay - 1));
REG_WRITE(PCH_HTOTAL_B, (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
REG_WRITE(PCH_HBLANK_B, (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
REG_WRITE(PCH_HSYNC_B, (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
REG_WRITE(PCH_VTOTAL_B, (adjusted_mode->crtc_vdisplay - 1) | ((adjusted_mode->crtc_vtotal - 1) << 16));
REG_WRITE(PCH_VBLANK_B, (adjusted_mode->crtc_vblank_start - 1) | ((adjusted_mode->crtc_vblank_end - 1) << 16));
REG_WRITE(PCH_VSYNC_B, (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
REG_WRITE(PCH_PIPEBSRC, ((mode->crtc_hdisplay - 1) << 16) | (mode->crtc_vdisplay - 1));
temp = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start;
HDMI_WRITE(HDMI_HBLANK_A, ((adjusted_mode->crtc_hdisplay - 1) << 16) | temp);
REG_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
REG_WRITE(dsppos_reg, 0);
/* Flush the plane changes */
{
struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
crtc_funcs->mode_set_base(crtc, x, y, old_fb);
}
/* Set up the display plane register */
dspcntr = REG_READ(dspcntr_reg);
dspcntr |= DISPPLANE_GAMMA_ENABLE;
dspcntr |= DISPPLANE_SEL_PIPE_B;
dspcntr |= DISPLAY_PLANE_ENABLE;
/* setup pipeconf */
pipeconf = REG_READ(pipeconf_reg);
pipeconf |= PIPEACONF_ENABLE;
REG_WRITE(pipeconf_reg, pipeconf);
REG_READ(pipeconf_reg);
REG_WRITE(PCH_PIPEBCONF, pipeconf);
REG_READ(PCH_PIPEBCONF);
wait_for_vblank(dev);
REG_WRITE(dspcntr_reg, dspcntr);
wait_for_vblank(dev);
gma_power_end(dev);
return 0;
}
void oaktrail_crtc_hdmi_dpms(struct drm_crtc *crtc, int mode)
{
struct drm_device *dev = crtc->dev;
u32 temp;
DRM_DEBUG_KMS("%s %d\n", __func__, mode);
switch (mode) {
case DRM_MODE_DPMS_OFF:
REG_WRITE(VGACNTRL, 0x80000000);
/* Disable plane */
temp = REG_READ(DSPBCNTR);
if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
REG_WRITE(DSPBCNTR, temp & ~DISPLAY_PLANE_ENABLE);
REG_READ(DSPBCNTR);
/* Flush the plane changes */
REG_WRITE(DSPBSURF, REG_READ(DSPBSURF));
REG_READ(DSPBSURF);
}
/* Disable pipe B */
temp = REG_READ(PIPEBCONF);
if ((temp & PIPEACONF_ENABLE) != 0) {
REG_WRITE(PIPEBCONF, temp & ~PIPEACONF_ENABLE);
REG_READ(PIPEBCONF);
}
/* Disable LNW Pipes, etc */
temp = REG_READ(PCH_PIPEBCONF);
if ((temp & PIPEACONF_ENABLE) != 0) {
REG_WRITE(PCH_PIPEBCONF, temp & ~PIPEACONF_ENABLE);
REG_READ(PCH_PIPEBCONF);
}
/* wait for pipe off */
udelay(150);
/* Disable dpll */
temp = REG_READ(DPLL_CTRL);
if ((temp & DPLL_PWRDN) == 0) {
REG_WRITE(DPLL_CTRL, temp | (DPLL_PWRDN | DPLL_RESET));
REG_WRITE(DPLL_STATUS, 0x1);
}
/* wait for dpll off */
udelay(150);
break;
case DRM_MODE_DPMS_ON:
case DRM_MODE_DPMS_STANDBY:
case DRM_MODE_DPMS_SUSPEND:
/* Enable dpll */
temp = REG_READ(DPLL_CTRL);
if ((temp & DPLL_PWRDN) != 0) {
REG_WRITE(DPLL_CTRL, temp & ~(DPLL_PWRDN | DPLL_RESET));
temp = REG_READ(DPLL_CLK_ENABLE);
REG_WRITE(DPLL_CLK_ENABLE, temp | DPLL_EN_DISP | DPLL_SEL_HDMI | DPLL_EN_HDMI);
REG_READ(DPLL_CLK_ENABLE);
}
/* wait for dpll warm up */
udelay(150);
/* Enable pipe B */
temp = REG_READ(PIPEBCONF);
if ((temp & PIPEACONF_ENABLE) == 0) {
REG_WRITE(PIPEBCONF, temp | PIPEACONF_ENABLE);
REG_READ(PIPEBCONF);
}
/* Enable LNW Pipe B */
temp = REG_READ(PCH_PIPEBCONF);
if ((temp & PIPEACONF_ENABLE) == 0) {
REG_WRITE(PCH_PIPEBCONF, temp | PIPEACONF_ENABLE);
REG_READ(PCH_PIPEBCONF);
}
wait_for_vblank(dev);
/* Enable plane */
temp = REG_READ(DSPBCNTR);
if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
REG_WRITE(DSPBCNTR, temp | DISPLAY_PLANE_ENABLE);
/* Flush the plane changes */
REG_WRITE(DSPBSURF, REG_READ(DSPBSURF));
REG_READ(DSPBSURF);
}
psb_intel_crtc_load_lut(crtc);
}
/* DSPARB */
REG_WRITE(DSPARB, 0x00003fbf);
/* FW1 */
REG_WRITE(0x70034, 0x3f880a0a);
/* FW2 */
REG_WRITE(0x70038, 0x0b060808);
/* FW4 */
REG_WRITE(0x70050, 0x08030404);
/* FW5 */
REG_WRITE(0x70054, 0x04040404);
/* LNC Chicken Bits - Squawk! */
REG_WRITE(0x70400, 0x4000);
return;
}
static void oaktrail_hdmi_dpms(struct drm_encoder *encoder, int mode)
{
static int dpms_mode = -1;
struct drm_device *dev = encoder->dev;
struct drm_psb_private *dev_priv = dev->dev_private;
struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
u32 temp;
if (dpms_mode == mode)
return;
if (mode != DRM_MODE_DPMS_ON)
temp = 0x0;
else
temp = 0x99;
dpms_mode = mode;
HDMI_WRITE(HDMI_VIDEO_REG, temp);
}
static int oaktrail_hdmi_mode_valid(struct drm_connector *connector,
struct drm_display_mode *mode)
{
if (mode->clock > 165000)
return MODE_CLOCK_HIGH;
if (mode->clock < 20000)
return MODE_CLOCK_LOW;
if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
return MODE_NO_DBLESCAN;
return MODE_OK;
}
static bool oaktrail_hdmi_mode_fixup(struct drm_encoder *encoder,
const struct drm_display_mode *mode,
struct drm_display_mode *adjusted_mode)
{
return true;
}
static enum drm_connector_status
oaktrail_hdmi_detect(struct drm_connector *connector, bool force)
{
enum drm_connector_status status;
struct drm_device *dev = connector->dev;
struct drm_psb_private *dev_priv = dev->dev_private;
struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
u32 temp;
temp = HDMI_READ(HDMI_HSR);
DRM_DEBUG_KMS("HDMI_HSR %x\n", temp);
if ((temp & HDMI_DETECT_HDP) != 0)
status = connector_status_connected;
else
status = connector_status_disconnected;
return status;
}
static const unsigned char raw_edid[] = {
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x10, 0xac, 0x2f, 0xa0,
0x53, 0x55, 0x33, 0x30, 0x16, 0x13, 0x01, 0x03, 0x0e, 0x3a, 0x24, 0x78,
0xea, 0xe9, 0xf5, 0xac, 0x51, 0x30, 0xb4, 0x25, 0x11, 0x50, 0x54, 0xa5,
0x4b, 0x00, 0x81, 0x80, 0xa9, 0x40, 0x71, 0x4f, 0xb3, 0x00, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x28, 0x3c, 0x80, 0xa0, 0x70, 0xb0,
0x23, 0x40, 0x30, 0x20, 0x36, 0x00, 0x46, 0x6c, 0x21, 0x00, 0x00, 0x1a,
0x00, 0x00, 0x00, 0xff, 0x00, 0x47, 0x4e, 0x37, 0x32, 0x31, 0x39, 0x35,
0x52, 0x30, 0x33, 0x55, 0x53, 0x0a, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x44,
0x45, 0x4c, 0x4c, 0x20, 0x32, 0x37, 0x30, 0x39, 0x57, 0x0a, 0x20, 0x20,
0x00, 0x00, 0x00, 0xfd, 0x00, 0x38, 0x4c, 0x1e, 0x53, 0x11, 0x00, 0x0a,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x8d
};
static int oaktrail_hdmi_get_modes(struct drm_connector *connector)
{
struct i2c_adapter *i2c_adap;
struct edid *edid;
int ret = 0;
/*
* FIXME: We need to figure this lot out. In theory we can
* read the EDID somehow but I've yet to find working reference
* code.
*/
i2c_adap = i2c_get_adapter(3);
if (i2c_adap == NULL) {
DRM_ERROR("No ddc adapter available!\n");
edid = (struct edid *)raw_edid;
} else {
edid = (struct edid *)raw_edid;
/* FIXME ? edid = drm_get_edid(connector, i2c_adap); */
}
if (edid) {
drm_mode_connector_update_edid_property(connector, edid);
ret = drm_add_edid_modes(connector, edid);
}
return ret;
}
static void oaktrail_hdmi_mode_set(struct drm_encoder *encoder,
struct drm_display_mode *mode,
struct drm_display_mode *adjusted_mode)
{
struct drm_device *dev = encoder->dev;
oaktrail_hdmi_audio_enable(dev);
return;
}
static void oaktrail_hdmi_destroy(struct drm_connector *connector)
{
return;
}
static const struct drm_encoder_helper_funcs oaktrail_hdmi_helper_funcs = {
.dpms = oaktrail_hdmi_dpms,
.mode_fixup = oaktrail_hdmi_mode_fixup,
.prepare = psb_intel_encoder_prepare,
.mode_set = oaktrail_hdmi_mode_set,
.commit = psb_intel_encoder_commit,
};
static const struct drm_connector_helper_funcs
oaktrail_hdmi_connector_helper_funcs = {
.get_modes = oaktrail_hdmi_get_modes,
.mode_valid = oaktrail_hdmi_mode_valid,
.best_encoder = psb_intel_best_encoder,
};
static const struct drm_connector_funcs oaktrail_hdmi_connector_funcs = {
.dpms = drm_helper_connector_dpms,
.detect = oaktrail_hdmi_detect,
.fill_modes = drm_helper_probe_single_connector_modes,
.destroy = oaktrail_hdmi_destroy,
};
static void oaktrail_hdmi_enc_destroy(struct drm_encoder *encoder)
{
drm_encoder_cleanup(encoder);
}
static const struct drm_encoder_funcs oaktrail_hdmi_enc_funcs = {
.destroy = oaktrail_hdmi_enc_destroy,
};
void oaktrail_hdmi_init(struct drm_device *dev,
struct psb_intel_mode_device *mode_dev)
{
struct psb_intel_encoder *psb_intel_encoder;
struct psb_intel_connector *psb_intel_connector;
struct drm_connector *connector;
struct drm_encoder *encoder;
psb_intel_encoder = kzalloc(sizeof(struct psb_intel_encoder), GFP_KERNEL);
if (!psb_intel_encoder)
return;
psb_intel_connector = kzalloc(sizeof(struct psb_intel_connector), GFP_KERNEL);
if (!psb_intel_connector)
goto failed_connector;
connector = &psb_intel_connector->base;
encoder = &psb_intel_encoder->base;
drm_connector_init(dev, connector,
&oaktrail_hdmi_connector_funcs,
DRM_MODE_CONNECTOR_DVID);
drm_encoder_init(dev, encoder,
&oaktrail_hdmi_enc_funcs,
DRM_MODE_ENCODER_TMDS);
psb_intel_connector_attach_encoder(psb_intel_connector,
psb_intel_encoder);
psb_intel_encoder->type = INTEL_OUTPUT_HDMI;
drm_encoder_helper_add(encoder, &oaktrail_hdmi_helper_funcs);
drm_connector_helper_add(connector, &oaktrail_hdmi_connector_helper_funcs);
connector->display_info.subpixel_order = SubPixelHorizontalRGB;
connector->interlace_allowed = false;
connector->doublescan_allowed = false;
drm_sysfs_connector_add(connector);
dev_info(dev->dev, "HDMI initialised.\n");
return;
failed_connector:
kfree(psb_intel_encoder);
}
static DEFINE_PCI_DEVICE_TABLE(hdmi_ids) = {
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x080d) },
{ 0 }
};
void oaktrail_hdmi_setup(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = dev->dev_private;
struct pci_dev *pdev;
struct oaktrail_hdmi_dev *hdmi_dev;
int ret;
pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x080d, NULL);
if (!pdev)
return;
hdmi_dev = kzalloc(sizeof(struct oaktrail_hdmi_dev), GFP_KERNEL);
if (!hdmi_dev) {
dev_err(dev->dev, "failed to allocate memory\n");
goto out;
}
ret = pci_enable_device(pdev);
if (ret) {
dev_err(dev->dev, "failed to enable hdmi controller\n");
goto free;
}
hdmi_dev->mmio = pci_resource_start(pdev, 0);
hdmi_dev->mmio_len = pci_resource_len(pdev, 0);
hdmi_dev->regs = ioremap(hdmi_dev->mmio, hdmi_dev->mmio_len);
if (!hdmi_dev->regs) {
dev_err(dev->dev, "failed to map hdmi mmio\n");
goto free;
}
hdmi_dev->dev = pdev;
pci_set_drvdata(pdev, hdmi_dev);
/* Initialize i2c controller */
ret = oaktrail_hdmi_i2c_init(hdmi_dev->dev);
if (ret)
dev_err(dev->dev, "HDMI I2C initialization failed\n");
dev_priv->hdmi_priv = hdmi_dev;
oaktrail_hdmi_audio_disable(dev);
dev_info(dev->dev, "HDMI hardware present.\n");
return;
free:
kfree(hdmi_dev);
out:
return;
}
void oaktrail_hdmi_teardown(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = dev->dev_private;
struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
struct pci_dev *pdev;
if (hdmi_dev) {
pdev = hdmi_dev->dev;
pci_set_drvdata(pdev, NULL);
oaktrail_hdmi_i2c_exit(pdev);
iounmap(hdmi_dev->regs);
kfree(hdmi_dev);
pci_dev_put(pdev);
}
}
/* save HDMI register state */
void oaktrail_hdmi_save(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = dev->dev_private;
struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
struct psb_state *regs = &dev_priv->regs.psb;
struct psb_pipe *pipeb = &dev_priv->regs.pipe[1];
int i;
/* dpll */
hdmi_dev->saveDPLL_CTRL = PSB_RVDC32(DPLL_CTRL);
hdmi_dev->saveDPLL_DIV_CTRL = PSB_RVDC32(DPLL_DIV_CTRL);
hdmi_dev->saveDPLL_ADJUST = PSB_RVDC32(DPLL_ADJUST);
hdmi_dev->saveDPLL_UPDATE = PSB_RVDC32(DPLL_UPDATE);
hdmi_dev->saveDPLL_CLK_ENABLE = PSB_RVDC32(DPLL_CLK_ENABLE);
/* pipe B */
pipeb->conf = PSB_RVDC32(PIPEBCONF);
pipeb->src = PSB_RVDC32(PIPEBSRC);
pipeb->htotal = PSB_RVDC32(HTOTAL_B);
pipeb->hblank = PSB_RVDC32(HBLANK_B);
pipeb->hsync = PSB_RVDC32(HSYNC_B);
pipeb->vtotal = PSB_RVDC32(VTOTAL_B);
pipeb->vblank = PSB_RVDC32(VBLANK_B);
pipeb->vsync = PSB_RVDC32(VSYNC_B);
hdmi_dev->savePCH_PIPEBCONF = PSB_RVDC32(PCH_PIPEBCONF);
hdmi_dev->savePCH_PIPEBSRC = PSB_RVDC32(PCH_PIPEBSRC);
hdmi_dev->savePCH_HTOTAL_B = PSB_RVDC32(PCH_HTOTAL_B);
hdmi_dev->savePCH_HBLANK_B = PSB_RVDC32(PCH_HBLANK_B);
hdmi_dev->savePCH_HSYNC_B = PSB_RVDC32(PCH_HSYNC_B);
hdmi_dev->savePCH_VTOTAL_B = PSB_RVDC32(PCH_VTOTAL_B);
hdmi_dev->savePCH_VBLANK_B = PSB_RVDC32(PCH_VBLANK_B);
hdmi_dev->savePCH_VSYNC_B = PSB_RVDC32(PCH_VSYNC_B);
/* plane */
pipeb->cntr = PSB_RVDC32(DSPBCNTR);
pipeb->stride = PSB_RVDC32(DSPBSTRIDE);
pipeb->addr = PSB_RVDC32(DSPBBASE);
pipeb->surf = PSB_RVDC32(DSPBSURF);
pipeb->linoff = PSB_RVDC32(DSPBLINOFF);
pipeb->tileoff = PSB_RVDC32(DSPBTILEOFF);
/* cursor B */
regs->saveDSPBCURSOR_CTRL = PSB_RVDC32(CURBCNTR);
regs->saveDSPBCURSOR_BASE = PSB_RVDC32(CURBBASE);
regs->saveDSPBCURSOR_POS = PSB_RVDC32(CURBPOS);
/* save palette */
for (i = 0; i < 256; i++)
pipeb->palette[i] = PSB_RVDC32(PALETTE_B + (i << 2));
}
/* restore HDMI register state */
void oaktrail_hdmi_restore(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = dev->dev_private;
struct oaktrail_hdmi_dev *hdmi_dev = dev_priv->hdmi_priv;
struct psb_state *regs = &dev_priv->regs.psb;
struct psb_pipe *pipeb = &dev_priv->regs.pipe[1];
int i;
/* dpll */
PSB_WVDC32(hdmi_dev->saveDPLL_CTRL, DPLL_CTRL);
PSB_WVDC32(hdmi_dev->saveDPLL_DIV_CTRL, DPLL_DIV_CTRL);
PSB_WVDC32(hdmi_dev->saveDPLL_ADJUST, DPLL_ADJUST);
PSB_WVDC32(hdmi_dev->saveDPLL_UPDATE, DPLL_UPDATE);
PSB_WVDC32(hdmi_dev->saveDPLL_CLK_ENABLE, DPLL_CLK_ENABLE);
DRM_UDELAY(150);
/* pipe */
PSB_WVDC32(pipeb->src, PIPEBSRC);
PSB_WVDC32(pipeb->htotal, HTOTAL_B);
PSB_WVDC32(pipeb->hblank, HBLANK_B);
PSB_WVDC32(pipeb->hsync, HSYNC_B);
PSB_WVDC32(pipeb->vtotal, VTOTAL_B);
PSB_WVDC32(pipeb->vblank, VBLANK_B);
PSB_WVDC32(pipeb->vsync, VSYNC_B);
PSB_WVDC32(hdmi_dev->savePCH_PIPEBSRC, PCH_PIPEBSRC);
PSB_WVDC32(hdmi_dev->savePCH_HTOTAL_B, PCH_HTOTAL_B);
PSB_WVDC32(hdmi_dev->savePCH_HBLANK_B, PCH_HBLANK_B);
PSB_WVDC32(hdmi_dev->savePCH_HSYNC_B, PCH_HSYNC_B);
PSB_WVDC32(hdmi_dev->savePCH_VTOTAL_B, PCH_VTOTAL_B);
PSB_WVDC32(hdmi_dev->savePCH_VBLANK_B, PCH_VBLANK_B);
PSB_WVDC32(hdmi_dev->savePCH_VSYNC_B, PCH_VSYNC_B);
PSB_WVDC32(pipeb->conf, PIPEBCONF);
PSB_WVDC32(hdmi_dev->savePCH_PIPEBCONF, PCH_PIPEBCONF);
/* plane */
PSB_WVDC32(pipeb->linoff, DSPBLINOFF);
PSB_WVDC32(pipeb->stride, DSPBSTRIDE);
PSB_WVDC32(pipeb->tileoff, DSPBTILEOFF);
PSB_WVDC32(pipeb->cntr, DSPBCNTR);
PSB_WVDC32(pipeb->surf, DSPBSURF);
/* cursor B */
PSB_WVDC32(regs->saveDSPBCURSOR_CTRL, CURBCNTR);
PSB_WVDC32(regs->saveDSPBCURSOR_POS, CURBPOS);
PSB_WVDC32(regs->saveDSPBCURSOR_BASE, CURBBASE);
/* restore palette */
for (i = 0; i < 256; i++)
PSB_WVDC32(pipeb->palette[i], PALETTE_B + (i << 2));
}
| gpl-2.0 |
nocoast/android_kernel_lge_g2 | drivers/infiniband/ulp/ipoib/ipoib_multicast.c | 3331 | 25617 | /*
* Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
* Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2004 Voltaire, Inc. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <linux/skbuff.h>
#include <linux/rtnetlink.h>
#include <linux/moduleparam.h>
#include <linux/ip.h>
#include <linux/in.h>
#include <linux/igmp.h>
#include <linux/inetdevice.h>
#include <linux/delay.h>
#include <linux/completion.h>
#include <linux/slab.h>
#include <net/dst.h>
#include "ipoib.h"
#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
static int mcast_debug_level;
module_param(mcast_debug_level, int, 0644);
MODULE_PARM_DESC(mcast_debug_level,
"Enable multicast debug tracing if > 0");
#endif
static DEFINE_MUTEX(mcast_mutex);
struct ipoib_mcast_iter {
struct net_device *dev;
union ib_gid mgid;
unsigned long created;
unsigned int queuelen;
unsigned int complete;
unsigned int send_only;
};
static void ipoib_mcast_free(struct ipoib_mcast *mcast)
{
struct net_device *dev = mcast->dev;
struct ipoib_dev_priv *priv = netdev_priv(dev);
struct ipoib_neigh *neigh, *tmp;
int tx_dropped = 0;
ipoib_dbg_mcast(netdev_priv(dev), "deleting multicast group %pI6\n",
mcast->mcmember.mgid.raw);
spin_lock_irq(&priv->lock);
list_for_each_entry_safe(neigh, tmp, &mcast->neigh_list, list) {
/*
* It's safe to call ipoib_put_ah() inside priv->lock
* here, because we know that mcast->ah will always
* hold one more reference, so ipoib_put_ah() will
* never do more than decrement the ref count.
*/
if (neigh->ah)
ipoib_put_ah(neigh->ah);
ipoib_neigh_free(dev, neigh);
}
spin_unlock_irq(&priv->lock);
if (mcast->ah)
ipoib_put_ah(mcast->ah);
while (!skb_queue_empty(&mcast->pkt_queue)) {
++tx_dropped;
dev_kfree_skb_any(skb_dequeue(&mcast->pkt_queue));
}
netif_tx_lock_bh(dev);
dev->stats.tx_dropped += tx_dropped;
netif_tx_unlock_bh(dev);
kfree(mcast);
}
static struct ipoib_mcast *ipoib_mcast_alloc(struct net_device *dev,
int can_sleep)
{
struct ipoib_mcast *mcast;
mcast = kzalloc(sizeof *mcast, can_sleep ? GFP_KERNEL : GFP_ATOMIC);
if (!mcast)
return NULL;
mcast->dev = dev;
mcast->created = jiffies;
mcast->backoff = 1;
INIT_LIST_HEAD(&mcast->list);
INIT_LIST_HEAD(&mcast->neigh_list);
skb_queue_head_init(&mcast->pkt_queue);
return mcast;
}
static struct ipoib_mcast *__ipoib_mcast_find(struct net_device *dev, void *mgid)
{
struct ipoib_dev_priv *priv = netdev_priv(dev);
struct rb_node *n = priv->multicast_tree.rb_node;
while (n) {
struct ipoib_mcast *mcast;
int ret;
mcast = rb_entry(n, struct ipoib_mcast, rb_node);
ret = memcmp(mgid, mcast->mcmember.mgid.raw,
sizeof (union ib_gid));
if (ret < 0)
n = n->rb_left;
else if (ret > 0)
n = n->rb_right;
else
return mcast;
}
return NULL;
}
static int __ipoib_mcast_add(struct net_device *dev, struct ipoib_mcast *mcast)
{
struct ipoib_dev_priv *priv = netdev_priv(dev);
struct rb_node **n = &priv->multicast_tree.rb_node, *pn = NULL;
while (*n) {
struct ipoib_mcast *tmcast;
int ret;
pn = *n;
tmcast = rb_entry(pn, struct ipoib_mcast, rb_node);
ret = memcmp(mcast->mcmember.mgid.raw, tmcast->mcmember.mgid.raw,
sizeof (union ib_gid));
if (ret < 0)
n = &pn->rb_left;
else if (ret > 0)
n = &pn->rb_right;
else
return -EEXIST;
}
rb_link_node(&mcast->rb_node, pn, n);
rb_insert_color(&mcast->rb_node, &priv->multicast_tree);
return 0;
}
static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
struct ib_sa_mcmember_rec *mcmember)
{
struct net_device *dev = mcast->dev;
struct ipoib_dev_priv *priv = netdev_priv(dev);
struct ipoib_ah *ah;
int ret;
int set_qkey = 0;
mcast->mcmember = *mcmember;
/* Set the cached Q_Key before we attach if it's the broadcast group */
if (!memcmp(mcast->mcmember.mgid.raw, priv->dev->broadcast + 4,
sizeof (union ib_gid))) {
spin_lock_irq(&priv->lock);
if (!priv->broadcast) {
spin_unlock_irq(&priv->lock);
return -EAGAIN;
}
priv->qkey = be32_to_cpu(priv->broadcast->mcmember.qkey);
spin_unlock_irq(&priv->lock);
priv->tx_wr.wr.ud.remote_qkey = priv->qkey;
set_qkey = 1;
}
if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) {
if (test_and_set_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) {
ipoib_warn(priv, "multicast group %pI6 already attached\n",
mcast->mcmember.mgid.raw);
return 0;
}
ret = ipoib_mcast_attach(dev, be16_to_cpu(mcast->mcmember.mlid),
&mcast->mcmember.mgid, set_qkey);
if (ret < 0) {
ipoib_warn(priv, "couldn't attach QP to multicast group %pI6\n",
mcast->mcmember.mgid.raw);
clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags);
return ret;
}
}
{
struct ib_ah_attr av = {
.dlid = be16_to_cpu(mcast->mcmember.mlid),
.port_num = priv->port,
.sl = mcast->mcmember.sl,
.ah_flags = IB_AH_GRH,
.static_rate = mcast->mcmember.rate,
.grh = {
.flow_label = be32_to_cpu(mcast->mcmember.flow_label),
.hop_limit = mcast->mcmember.hop_limit,
.sgid_index = 0,
.traffic_class = mcast->mcmember.traffic_class
}
};
av.grh.dgid = mcast->mcmember.mgid;
ah = ipoib_create_ah(dev, priv->pd, &av);
if (IS_ERR(ah)) {
ipoib_warn(priv, "ib_address_create failed %ld\n",
-PTR_ERR(ah));
/* use original error */
return PTR_ERR(ah);
} else {
spin_lock_irq(&priv->lock);
mcast->ah = ah;
spin_unlock_irq(&priv->lock);
ipoib_dbg_mcast(priv, "MGID %pI6 AV %p, LID 0x%04x, SL %d\n",
mcast->mcmember.mgid.raw,
mcast->ah->ah,
be16_to_cpu(mcast->mcmember.mlid),
mcast->mcmember.sl);
}
}
/* actually send any queued packets */
netif_tx_lock_bh(dev);
while (!skb_queue_empty(&mcast->pkt_queue)) {
struct sk_buff *skb = skb_dequeue(&mcast->pkt_queue);
netif_tx_unlock_bh(dev);
skb->dev = dev;
if (dev_queue_xmit(skb))
ipoib_warn(priv, "dev_queue_xmit failed to requeue packet\n");
netif_tx_lock_bh(dev);
}
netif_tx_unlock_bh(dev);
return 0;
}
static int
ipoib_mcast_sendonly_join_complete(int status,
struct ib_sa_multicast *multicast)
{
struct ipoib_mcast *mcast = multicast->context;
struct net_device *dev = mcast->dev;
/* We trap for port events ourselves. */
if (status == -ENETRESET)
return 0;
if (!status)
status = ipoib_mcast_join_finish(mcast, &multicast->rec);
if (status) {
if (mcast->logcount++ < 20)
ipoib_dbg_mcast(netdev_priv(dev), "multicast join failed for %pI6, status %d\n",
mcast->mcmember.mgid.raw, status);
/* Flush out any queued packets */
netif_tx_lock_bh(dev);
while (!skb_queue_empty(&mcast->pkt_queue)) {
++dev->stats.tx_dropped;
dev_kfree_skb_any(skb_dequeue(&mcast->pkt_queue));
}
netif_tx_unlock_bh(dev);
/* Clear the busy flag so we try again */
status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY,
&mcast->flags);
}
return status;
}
static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast)
{
struct net_device *dev = mcast->dev;
struct ipoib_dev_priv *priv = netdev_priv(dev);
struct ib_sa_mcmember_rec rec = {
#if 0 /* Some SMs don't support send-only yet */
.join_state = 4
#else
.join_state = 1
#endif
};
int ret = 0;
if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) {
ipoib_dbg_mcast(priv, "device shutting down, no multicast joins\n");
return -ENODEV;
}
if (test_and_set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) {
ipoib_dbg_mcast(priv, "multicast entry busy, skipping\n");
return -EBUSY;
}
rec.mgid = mcast->mcmember.mgid;
rec.port_gid = priv->local_gid;
rec.pkey = cpu_to_be16(priv->pkey);
mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca,
priv->port, &rec,
IB_SA_MCMEMBER_REC_MGID |
IB_SA_MCMEMBER_REC_PORT_GID |
IB_SA_MCMEMBER_REC_PKEY |
IB_SA_MCMEMBER_REC_JOIN_STATE,
GFP_ATOMIC,
ipoib_mcast_sendonly_join_complete,
mcast);
if (IS_ERR(mcast->mc)) {
ret = PTR_ERR(mcast->mc);
clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
ipoib_warn(priv, "ib_sa_join_multicast failed (ret = %d)\n",
ret);
} else {
ipoib_dbg_mcast(priv, "no multicast record for %pI6, starting join\n",
mcast->mcmember.mgid.raw);
}
return ret;
}
void ipoib_mcast_carrier_on_task(struct work_struct *work)
{
struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
carrier_on_task);
struct ib_port_attr attr;
/*
* Take rtnl_lock to avoid racing with ipoib_stop() and
* turning the carrier back on while a device is being
* removed.
*/
if (ib_query_port(priv->ca, priv->port, &attr) ||
attr.state != IB_PORT_ACTIVE) {
ipoib_dbg(priv, "Keeping carrier off until IB port is active\n");
return;
}
rtnl_lock();
netif_carrier_on(priv->dev);
rtnl_unlock();
}
static int ipoib_mcast_join_complete(int status,
struct ib_sa_multicast *multicast)
{
struct ipoib_mcast *mcast = multicast->context;
struct net_device *dev = mcast->dev;
struct ipoib_dev_priv *priv = netdev_priv(dev);
ipoib_dbg_mcast(priv, "join completion for %pI6 (status %d)\n",
mcast->mcmember.mgid.raw, status);
/* We trap for port events ourselves. */
if (status == -ENETRESET)
return 0;
if (!status)
status = ipoib_mcast_join_finish(mcast, &multicast->rec);
if (!status) {
mcast->backoff = 1;
mutex_lock(&mcast_mutex);
if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
queue_delayed_work(ipoib_workqueue,
&priv->mcast_task, 0);
mutex_unlock(&mcast_mutex);
/*
* Defer carrier on work to ipoib_workqueue to avoid a
* deadlock on rtnl_lock here.
*/
if (mcast == priv->broadcast)
queue_work(ipoib_workqueue, &priv->carrier_on_task);
return 0;
}
if (mcast->logcount++ < 20) {
if (status == -ETIMEDOUT || status == -EAGAIN) {
ipoib_dbg_mcast(priv, "multicast join failed for %pI6, status %d\n",
mcast->mcmember.mgid.raw, status);
} else {
ipoib_warn(priv, "multicast join failed for %pI6, status %d\n",
mcast->mcmember.mgid.raw, status);
}
}
mcast->backoff *= 2;
if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
/* Clear the busy flag so we try again */
status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
mutex_lock(&mcast_mutex);
spin_lock_irq(&priv->lock);
if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
queue_delayed_work(ipoib_workqueue, &priv->mcast_task,
mcast->backoff * HZ);
spin_unlock_irq(&priv->lock);
mutex_unlock(&mcast_mutex);
return status;
}
static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
int create)
{
struct ipoib_dev_priv *priv = netdev_priv(dev);
struct ib_sa_mcmember_rec rec = {
.join_state = 1
};
ib_sa_comp_mask comp_mask;
int ret = 0;
ipoib_dbg_mcast(priv, "joining MGID %pI6\n", mcast->mcmember.mgid.raw);
rec.mgid = mcast->mcmember.mgid;
rec.port_gid = priv->local_gid;
rec.pkey = cpu_to_be16(priv->pkey);
comp_mask =
IB_SA_MCMEMBER_REC_MGID |
IB_SA_MCMEMBER_REC_PORT_GID |
IB_SA_MCMEMBER_REC_PKEY |
IB_SA_MCMEMBER_REC_JOIN_STATE;
if (create) {
comp_mask |=
IB_SA_MCMEMBER_REC_QKEY |
IB_SA_MCMEMBER_REC_MTU_SELECTOR |
IB_SA_MCMEMBER_REC_MTU |
IB_SA_MCMEMBER_REC_TRAFFIC_CLASS |
IB_SA_MCMEMBER_REC_RATE_SELECTOR |
IB_SA_MCMEMBER_REC_RATE |
IB_SA_MCMEMBER_REC_SL |
IB_SA_MCMEMBER_REC_FLOW_LABEL |
IB_SA_MCMEMBER_REC_HOP_LIMIT;
rec.qkey = priv->broadcast->mcmember.qkey;
rec.mtu_selector = IB_SA_EQ;
rec.mtu = priv->broadcast->mcmember.mtu;
rec.traffic_class = priv->broadcast->mcmember.traffic_class;
rec.rate_selector = IB_SA_EQ;
rec.rate = priv->broadcast->mcmember.rate;
rec.sl = priv->broadcast->mcmember.sl;
rec.flow_label = priv->broadcast->mcmember.flow_label;
rec.hop_limit = priv->broadcast->mcmember.hop_limit;
}
set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port,
&rec, comp_mask, GFP_KERNEL,
ipoib_mcast_join_complete, mcast);
if (IS_ERR(mcast->mc)) {
clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags);
ret = PTR_ERR(mcast->mc);
ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret);
mcast->backoff *= 2;
if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
mutex_lock(&mcast_mutex);
if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
queue_delayed_work(ipoib_workqueue,
&priv->mcast_task,
mcast->backoff * HZ);
mutex_unlock(&mcast_mutex);
}
}
void ipoib_mcast_join_task(struct work_struct *work)
{
struct ipoib_dev_priv *priv =
container_of(work, struct ipoib_dev_priv, mcast_task.work);
struct net_device *dev = priv->dev;
if (!test_bit(IPOIB_MCAST_RUN, &priv->flags))
return;
if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid))
ipoib_warn(priv, "ib_query_gid() failed\n");
else
memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid));
{
struct ib_port_attr attr;
if (!ib_query_port(priv->ca, priv->port, &attr))
priv->local_lid = attr.lid;
else
ipoib_warn(priv, "ib_query_port failed\n");
}
if (!priv->broadcast) {
struct ipoib_mcast *broadcast;
if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
return;
broadcast = ipoib_mcast_alloc(dev, 1);
if (!broadcast) {
ipoib_warn(priv, "failed to allocate broadcast group\n");
mutex_lock(&mcast_mutex);
if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
queue_delayed_work(ipoib_workqueue,
&priv->mcast_task, HZ);
mutex_unlock(&mcast_mutex);
return;
}
spin_lock_irq(&priv->lock);
memcpy(broadcast->mcmember.mgid.raw, priv->dev->broadcast + 4,
sizeof (union ib_gid));
priv->broadcast = broadcast;
__ipoib_mcast_add(dev, priv->broadcast);
spin_unlock_irq(&priv->lock);
}
if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) {
if (!test_bit(IPOIB_MCAST_FLAG_BUSY, &priv->broadcast->flags))
ipoib_mcast_join(dev, priv->broadcast, 0);
return;
}
while (1) {
struct ipoib_mcast *mcast = NULL;
spin_lock_irq(&priv->lock);
list_for_each_entry(mcast, &priv->multicast_list, list) {
if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)
&& !test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)
&& !test_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) {
/* Found the next unjoined group */
break;
}
}
spin_unlock_irq(&priv->lock);
if (&mcast->list == &priv->multicast_list) {
/* All done */
break;
}
ipoib_mcast_join(dev, mcast, 1);
return;
}
priv->mcast_mtu = IPOIB_UD_MTU(ib_mtu_enum_to_int(priv->broadcast->mcmember.mtu));
if (!ipoib_cm_admin_enabled(dev)) {
rtnl_lock();
dev_set_mtu(dev, min(priv->mcast_mtu, priv->admin_mtu));
rtnl_unlock();
}
ipoib_dbg_mcast(priv, "successfully joined all multicast groups\n");
clear_bit(IPOIB_MCAST_RUN, &priv->flags);
}
int ipoib_mcast_start_thread(struct net_device *dev)
{
struct ipoib_dev_priv *priv = netdev_priv(dev);
ipoib_dbg_mcast(priv, "starting multicast thread\n");
mutex_lock(&mcast_mutex);
if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags))
queue_delayed_work(ipoib_workqueue, &priv->mcast_task, 0);
mutex_unlock(&mcast_mutex);
return 0;
}
int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
{
struct ipoib_dev_priv *priv = netdev_priv(dev);
ipoib_dbg_mcast(priv, "stopping multicast thread\n");
mutex_lock(&mcast_mutex);
clear_bit(IPOIB_MCAST_RUN, &priv->flags);
cancel_delayed_work(&priv->mcast_task);
mutex_unlock(&mcast_mutex);
if (flush)
flush_workqueue(ipoib_workqueue);
return 0;
}
static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast)
{
struct ipoib_dev_priv *priv = netdev_priv(dev);
int ret = 0;
if (test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags))
ib_sa_free_multicast(mcast->mc);
if (test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) {
ipoib_dbg_mcast(priv, "leaving MGID %pI6\n",
mcast->mcmember.mgid.raw);
/* Remove ourselves from the multicast group */
ret = ib_detach_mcast(priv->qp, &mcast->mcmember.mgid,
be16_to_cpu(mcast->mcmember.mlid));
if (ret)
ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret);
}
return 0;
}
void ipoib_mcast_send(struct net_device *dev, void *mgid, struct sk_buff *skb)
{
struct ipoib_dev_priv *priv = netdev_priv(dev);
struct ipoib_mcast *mcast;
unsigned long flags;
spin_lock_irqsave(&priv->lock, flags);
if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags) ||
!priv->broadcast ||
!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) {
++dev->stats.tx_dropped;
dev_kfree_skb_any(skb);
goto unlock;
}
mcast = __ipoib_mcast_find(dev, mgid);
if (!mcast) {
/* Let's create a new send only group now */
ipoib_dbg_mcast(priv, "setting up send only multicast group for %pI6\n",
mgid);
mcast = ipoib_mcast_alloc(dev, 0);
if (!mcast) {
ipoib_warn(priv, "unable to allocate memory for "
"multicast structure\n");
++dev->stats.tx_dropped;
dev_kfree_skb_any(skb);
goto out;
}
set_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags);
memcpy(mcast->mcmember.mgid.raw, mgid, sizeof (union ib_gid));
__ipoib_mcast_add(dev, mcast);
list_add_tail(&mcast->list, &priv->multicast_list);
}
if (!mcast->ah) {
if (skb_queue_len(&mcast->pkt_queue) < IPOIB_MAX_MCAST_QUEUE)
skb_queue_tail(&mcast->pkt_queue, skb);
else {
++dev->stats.tx_dropped;
dev_kfree_skb_any(skb);
}
if (test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags))
ipoib_dbg_mcast(priv, "no address vector, "
"but multicast join already started\n");
else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags))
ipoib_mcast_sendonly_join(mcast);
/*
* If lookup completes between here and out:, don't
* want to send packet twice.
*/
mcast = NULL;
}
out:
if (mcast && mcast->ah) {
struct dst_entry *dst = skb_dst(skb);
struct neighbour *n = NULL;
rcu_read_lock();
if (dst)
n = dst_get_neighbour_noref(dst);
if (n && !*to_ipoib_neigh(n)) {
struct ipoib_neigh *neigh = ipoib_neigh_alloc(n,
skb->dev);
if (neigh) {
kref_get(&mcast->ah->ref);
neigh->ah = mcast->ah;
list_add_tail(&neigh->list, &mcast->neigh_list);
}
}
rcu_read_unlock();
spin_unlock_irqrestore(&priv->lock, flags);
ipoib_send(dev, skb, mcast->ah, IB_MULTICAST_QPN);
return;
}
unlock:
spin_unlock_irqrestore(&priv->lock, flags);
}
void ipoib_mcast_dev_flush(struct net_device *dev)
{
struct ipoib_dev_priv *priv = netdev_priv(dev);
LIST_HEAD(remove_list);
struct ipoib_mcast *mcast, *tmcast;
unsigned long flags;
ipoib_dbg_mcast(priv, "flushing multicast list\n");
spin_lock_irqsave(&priv->lock, flags);
list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) {
list_del(&mcast->list);
rb_erase(&mcast->rb_node, &priv->multicast_tree);
list_add_tail(&mcast->list, &remove_list);
}
if (priv->broadcast) {
rb_erase(&priv->broadcast->rb_node, &priv->multicast_tree);
list_add_tail(&priv->broadcast->list, &remove_list);
priv->broadcast = NULL;
}
spin_unlock_irqrestore(&priv->lock, flags);
list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
ipoib_mcast_leave(dev, mcast);
ipoib_mcast_free(mcast);
}
}
static int ipoib_mcast_addr_is_valid(const u8 *addr, const u8 *broadcast)
{
/* reserved QPN, prefix, scope */
if (memcmp(addr, broadcast, 6))
return 0;
/* signature lower, pkey */
if (memcmp(addr + 7, broadcast + 7, 3))
return 0;
return 1;
}
void ipoib_mcast_restart_task(struct work_struct *work)
{
struct ipoib_dev_priv *priv =
container_of(work, struct ipoib_dev_priv, restart_task);
struct net_device *dev = priv->dev;
struct netdev_hw_addr *ha;
struct ipoib_mcast *mcast, *tmcast;
LIST_HEAD(remove_list);
unsigned long flags;
struct ib_sa_mcmember_rec rec;
ipoib_dbg_mcast(priv, "restarting multicast task\n");
ipoib_mcast_stop_thread(dev, 0);
local_irq_save(flags);
netif_addr_lock(dev);
spin_lock(&priv->lock);
/*
* Unfortunately, the networking core only gives us a list of all of
* the multicast hardware addresses. We need to figure out which ones
* are new and which ones have been removed
*/
/* Clear out the found flag */
list_for_each_entry(mcast, &priv->multicast_list, list)
clear_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags);
/* Mark all of the entries that are found or don't exist */
netdev_for_each_mc_addr(ha, dev) {
union ib_gid mgid;
if (!ipoib_mcast_addr_is_valid(ha->addr, dev->broadcast))
continue;
memcpy(mgid.raw, ha->addr + 4, sizeof mgid);
mcast = __ipoib_mcast_find(dev, &mgid);
if (!mcast || test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) {
struct ipoib_mcast *nmcast;
/* ignore group which is directly joined by userspace */
if (test_bit(IPOIB_FLAG_UMCAST, &priv->flags) &&
!ib_sa_get_mcmember_rec(priv->ca, priv->port, &mgid, &rec)) {
ipoib_dbg_mcast(priv, "ignoring multicast entry for mgid %pI6\n",
mgid.raw);
continue;
}
/* Not found or send-only group, let's add a new entry */
ipoib_dbg_mcast(priv, "adding multicast entry for mgid %pI6\n",
mgid.raw);
nmcast = ipoib_mcast_alloc(dev, 0);
if (!nmcast) {
ipoib_warn(priv, "unable to allocate memory for multicast structure\n");
continue;
}
set_bit(IPOIB_MCAST_FLAG_FOUND, &nmcast->flags);
nmcast->mcmember.mgid = mgid;
if (mcast) {
/* Destroy the send only entry */
list_move_tail(&mcast->list, &remove_list);
rb_replace_node(&mcast->rb_node,
&nmcast->rb_node,
&priv->multicast_tree);
} else
__ipoib_mcast_add(dev, nmcast);
list_add_tail(&nmcast->list, &priv->multicast_list);
}
if (mcast)
set_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags);
}
/* Remove all of the entries don't exist anymore */
list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) {
if (!test_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags) &&
!test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) {
ipoib_dbg_mcast(priv, "deleting multicast group %pI6\n",
mcast->mcmember.mgid.raw);
rb_erase(&mcast->rb_node, &priv->multicast_tree);
/* Move to the remove list */
list_move_tail(&mcast->list, &remove_list);
}
}
spin_unlock(&priv->lock);
netif_addr_unlock(dev);
local_irq_restore(flags);
/* We have to cancel outside of the spinlock */
list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
ipoib_mcast_leave(mcast->dev, mcast);
ipoib_mcast_free(mcast);
}
if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
ipoib_mcast_start_thread(dev);
}
#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev)
{
struct ipoib_mcast_iter *iter;
iter = kmalloc(sizeof *iter, GFP_KERNEL);
if (!iter)
return NULL;
iter->dev = dev;
memset(iter->mgid.raw, 0, 16);
if (ipoib_mcast_iter_next(iter)) {
kfree(iter);
return NULL;
}
return iter;
}
int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter)
{
struct ipoib_dev_priv *priv = netdev_priv(iter->dev);
struct rb_node *n;
struct ipoib_mcast *mcast;
int ret = 1;
spin_lock_irq(&priv->lock);
n = rb_first(&priv->multicast_tree);
while (n) {
mcast = rb_entry(n, struct ipoib_mcast, rb_node);
if (memcmp(iter->mgid.raw, mcast->mcmember.mgid.raw,
sizeof (union ib_gid)) < 0) {
iter->mgid = mcast->mcmember.mgid;
iter->created = mcast->created;
iter->queuelen = skb_queue_len(&mcast->pkt_queue);
iter->complete = !!mcast->ah;
iter->send_only = !!(mcast->flags & (1 << IPOIB_MCAST_FLAG_SENDONLY));
ret = 0;
break;
}
n = rb_next(n);
}
spin_unlock_irq(&priv->lock);
return ret;
}
void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter,
union ib_gid *mgid,
unsigned long *created,
unsigned int *queuelen,
unsigned int *complete,
unsigned int *send_only)
{
*mgid = iter->mgid;
*created = iter->created;
*queuelen = iter->queuelen;
*complete = iter->complete;
*send_only = iter->send_only;
}
#endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */
| gpl-2.0 |
davidmueller13/TW_Kernel_LP | crypto/ccm.c | 4099 | 22053 | /*
* CCM: Counter with CBC-MAC
*
* (C) Copyright IBM Corp. 2007 - Joy Latten <latten@us.ibm.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 <crypto/internal/aead.h>
#include <crypto/internal/skcipher.h>
#include <crypto/scatterwalk.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include "internal.h"
struct ccm_instance_ctx {
struct crypto_skcipher_spawn ctr;
struct crypto_spawn cipher;
};
struct crypto_ccm_ctx {
struct crypto_cipher *cipher;
struct crypto_ablkcipher *ctr;
};
struct crypto_rfc4309_ctx {
struct crypto_aead *child;
u8 nonce[3];
};
struct crypto_ccm_req_priv_ctx {
u8 odata[16];
u8 idata[16];
u8 auth_tag[16];
u32 ilen;
u32 flags;
struct scatterlist src[2];
struct scatterlist dst[2];
struct ablkcipher_request abreq;
};
static inline struct crypto_ccm_req_priv_ctx *crypto_ccm_reqctx(
struct aead_request *req)
{
unsigned long align = crypto_aead_alignmask(crypto_aead_reqtfm(req));
return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1);
}
static int set_msg_len(u8 *block, unsigned int msglen, int csize)
{
__be32 data;
memset(block, 0, csize);
block += csize;
if (csize >= 4)
csize = 4;
else if (msglen > (1 << (8 * csize)))
return -EOVERFLOW;
data = cpu_to_be32(msglen);
memcpy(block - csize, (u8 *)&data + 4 - csize, csize);
return 0;
}
static int crypto_ccm_setkey(struct crypto_aead *aead, const u8 *key,
unsigned int keylen)
{
struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead);
struct crypto_ablkcipher *ctr = ctx->ctr;
struct crypto_cipher *tfm = ctx->cipher;
int err = 0;
crypto_ablkcipher_clear_flags(ctr, CRYPTO_TFM_REQ_MASK);
crypto_ablkcipher_set_flags(ctr, crypto_aead_get_flags(aead) &
CRYPTO_TFM_REQ_MASK);
err = crypto_ablkcipher_setkey(ctr, key, keylen);
crypto_aead_set_flags(aead, crypto_ablkcipher_get_flags(ctr) &
CRYPTO_TFM_RES_MASK);
if (err)
goto out;
crypto_cipher_clear_flags(tfm, CRYPTO_TFM_REQ_MASK);
crypto_cipher_set_flags(tfm, crypto_aead_get_flags(aead) &
CRYPTO_TFM_REQ_MASK);
err = crypto_cipher_setkey(tfm, key, keylen);
crypto_aead_set_flags(aead, crypto_cipher_get_flags(tfm) &
CRYPTO_TFM_RES_MASK);
out:
return err;
}
static int crypto_ccm_setauthsize(struct crypto_aead *tfm,
unsigned int authsize)
{
switch (authsize) {
case 4:
case 6:
case 8:
case 10:
case 12:
case 14:
case 16:
break;
default:
return -EINVAL;
}
return 0;
}
static int format_input(u8 *info, struct aead_request *req,
unsigned int cryptlen)
{
struct crypto_aead *aead = crypto_aead_reqtfm(req);
unsigned int lp = req->iv[0];
unsigned int l = lp + 1;
unsigned int m;
m = crypto_aead_authsize(aead);
memcpy(info, req->iv, 16);
/* format control info per RFC 3610 and
* NIST Special Publication 800-38C
*/
*info |= (8 * ((m - 2) / 2));
if (req->assoclen)
*info |= 64;
return set_msg_len(info + 16 - l, cryptlen, l);
}
static int format_adata(u8 *adata, unsigned int a)
{
int len = 0;
/* add control info for associated data
* RFC 3610 and NIST Special Publication 800-38C
*/
if (a < 65280) {
*(__be16 *)adata = cpu_to_be16(a);
len = 2;
} else {
*(__be16 *)adata = cpu_to_be16(0xfffe);
*(__be32 *)&adata[2] = cpu_to_be32(a);
len = 6;
}
return len;
}
static void compute_mac(struct crypto_cipher *tfm, u8 *data, int n,
struct crypto_ccm_req_priv_ctx *pctx)
{
unsigned int bs = 16;
u8 *odata = pctx->odata;
u8 *idata = pctx->idata;
int datalen, getlen;
datalen = n;
/* first time in here, block may be partially filled. */
getlen = bs - pctx->ilen;
if (datalen >= getlen) {
memcpy(idata + pctx->ilen, data, getlen);
crypto_xor(odata, idata, bs);
crypto_cipher_encrypt_one(tfm, odata, odata);
datalen -= getlen;
data += getlen;
pctx->ilen = 0;
}
/* now encrypt rest of data */
while (datalen >= bs) {
crypto_xor(odata, data, bs);
crypto_cipher_encrypt_one(tfm, odata, odata);
datalen -= bs;
data += bs;
}
/* check and see if there's leftover data that wasn't
* enough to fill a block.
*/
if (datalen) {
memcpy(idata + pctx->ilen, data, datalen);
pctx->ilen += datalen;
}
}
static void get_data_to_compute(struct crypto_cipher *tfm,
struct crypto_ccm_req_priv_ctx *pctx,
struct scatterlist *sg, unsigned int len)
{
struct scatter_walk walk;
u8 *data_src;
int n;
scatterwalk_start(&walk, sg);
while (len) {
n = scatterwalk_clamp(&walk, len);
if (!n) {
scatterwalk_start(&walk, sg_next(walk.sg));
n = scatterwalk_clamp(&walk, len);
}
data_src = scatterwalk_map(&walk);
compute_mac(tfm, data_src, n, pctx);
len -= n;
scatterwalk_unmap(data_src);
scatterwalk_advance(&walk, n);
scatterwalk_done(&walk, 0, len);
if (len)
crypto_yield(pctx->flags);
}
/* any leftover needs padding and then encrypted */
if (pctx->ilen) {
int padlen;
u8 *odata = pctx->odata;
u8 *idata = pctx->idata;
padlen = 16 - pctx->ilen;
memset(idata + pctx->ilen, 0, padlen);
crypto_xor(odata, idata, 16);
crypto_cipher_encrypt_one(tfm, odata, odata);
pctx->ilen = 0;
}
}
static int crypto_ccm_auth(struct aead_request *req, struct scatterlist *plain,
unsigned int cryptlen)
{
struct crypto_aead *aead = crypto_aead_reqtfm(req);
struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead);
struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
struct crypto_cipher *cipher = ctx->cipher;
unsigned int assoclen = req->assoclen;
u8 *odata = pctx->odata;
u8 *idata = pctx->idata;
int err;
/* format control data for input */
err = format_input(odata, req, cryptlen);
if (err)
goto out;
/* encrypt first block to use as start in computing mac */
crypto_cipher_encrypt_one(cipher, odata, odata);
/* format associated data and compute into mac */
if (assoclen) {
pctx->ilen = format_adata(idata, assoclen);
get_data_to_compute(cipher, pctx, req->assoc, req->assoclen);
} else {
pctx->ilen = 0;
}
/* compute plaintext into mac */
get_data_to_compute(cipher, pctx, plain, cryptlen);
out:
return err;
}
static void crypto_ccm_encrypt_done(struct crypto_async_request *areq, int err)
{
struct aead_request *req = areq->data;
struct crypto_aead *aead = crypto_aead_reqtfm(req);
struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
u8 *odata = pctx->odata;
if (!err)
scatterwalk_map_and_copy(odata, req->dst, req->cryptlen,
crypto_aead_authsize(aead), 1);
aead_request_complete(req, err);
}
static inline int crypto_ccm_check_iv(const u8 *iv)
{
/* 2 <= L <= 8, so 1 <= L' <= 7. */
if (1 > iv[0] || iv[0] > 7)
return -EINVAL;
return 0;
}
static int crypto_ccm_encrypt(struct aead_request *req)
{
struct crypto_aead *aead = crypto_aead_reqtfm(req);
struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead);
struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
struct ablkcipher_request *abreq = &pctx->abreq;
struct scatterlist *dst;
unsigned int cryptlen = req->cryptlen;
u8 *odata = pctx->odata;
u8 *iv = req->iv;
int err;
err = crypto_ccm_check_iv(iv);
if (err)
return err;
pctx->flags = aead_request_flags(req);
err = crypto_ccm_auth(req, req->src, cryptlen);
if (err)
return err;
/* Note: rfc 3610 and NIST 800-38C require counter of
* zero to encrypt auth tag.
*/
memset(iv + 15 - iv[0], 0, iv[0] + 1);
sg_init_table(pctx->src, 2);
sg_set_buf(pctx->src, odata, 16);
scatterwalk_sg_chain(pctx->src, 2, req->src);
dst = pctx->src;
if (req->src != req->dst) {
sg_init_table(pctx->dst, 2);
sg_set_buf(pctx->dst, odata, 16);
scatterwalk_sg_chain(pctx->dst, 2, req->dst);
dst = pctx->dst;
}
ablkcipher_request_set_tfm(abreq, ctx->ctr);
ablkcipher_request_set_callback(abreq, pctx->flags,
crypto_ccm_encrypt_done, req);
ablkcipher_request_set_crypt(abreq, pctx->src, dst, cryptlen + 16, iv);
err = crypto_ablkcipher_encrypt(abreq);
if (err)
return err;
/* copy authtag to end of dst */
scatterwalk_map_and_copy(odata, req->dst, cryptlen,
crypto_aead_authsize(aead), 1);
return err;
}
static void crypto_ccm_decrypt_done(struct crypto_async_request *areq,
int err)
{
struct aead_request *req = areq->data;
struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
struct crypto_aead *aead = crypto_aead_reqtfm(req);
unsigned int authsize = crypto_aead_authsize(aead);
unsigned int cryptlen = req->cryptlen - authsize;
if (!err) {
err = crypto_ccm_auth(req, req->dst, cryptlen);
if (!err && memcmp(pctx->auth_tag, pctx->odata, authsize))
err = -EBADMSG;
}
aead_request_complete(req, err);
}
static int crypto_ccm_decrypt(struct aead_request *req)
{
struct crypto_aead *aead = crypto_aead_reqtfm(req);
struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead);
struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
struct ablkcipher_request *abreq = &pctx->abreq;
struct scatterlist *dst;
unsigned int authsize = crypto_aead_authsize(aead);
unsigned int cryptlen = req->cryptlen;
u8 *authtag = pctx->auth_tag;
u8 *odata = pctx->odata;
u8 *iv = req->iv;
int err;
if (cryptlen < authsize)
return -EINVAL;
cryptlen -= authsize;
err = crypto_ccm_check_iv(iv);
if (err)
return err;
pctx->flags = aead_request_flags(req);
scatterwalk_map_and_copy(authtag, req->src, cryptlen, authsize, 0);
memset(iv + 15 - iv[0], 0, iv[0] + 1);
sg_init_table(pctx->src, 2);
sg_set_buf(pctx->src, authtag, 16);
scatterwalk_sg_chain(pctx->src, 2, req->src);
dst = pctx->src;
if (req->src != req->dst) {
sg_init_table(pctx->dst, 2);
sg_set_buf(pctx->dst, authtag, 16);
scatterwalk_sg_chain(pctx->dst, 2, req->dst);
dst = pctx->dst;
}
ablkcipher_request_set_tfm(abreq, ctx->ctr);
ablkcipher_request_set_callback(abreq, pctx->flags,
crypto_ccm_decrypt_done, req);
ablkcipher_request_set_crypt(abreq, pctx->src, dst, cryptlen + 16, iv);
err = crypto_ablkcipher_decrypt(abreq);
if (err)
return err;
err = crypto_ccm_auth(req, req->dst, cryptlen);
if (err)
return err;
/* verify */
if (memcmp(authtag, odata, authsize))
return -EBADMSG;
return err;
}
static int crypto_ccm_init_tfm(struct crypto_tfm *tfm)
{
struct crypto_instance *inst = (void *)tfm->__crt_alg;
struct ccm_instance_ctx *ictx = crypto_instance_ctx(inst);
struct crypto_ccm_ctx *ctx = crypto_tfm_ctx(tfm);
struct crypto_cipher *cipher;
struct crypto_ablkcipher *ctr;
unsigned long align;
int err;
cipher = crypto_spawn_cipher(&ictx->cipher);
if (IS_ERR(cipher))
return PTR_ERR(cipher);
ctr = crypto_spawn_skcipher(&ictx->ctr);
err = PTR_ERR(ctr);
if (IS_ERR(ctr))
goto err_free_cipher;
ctx->cipher = cipher;
ctx->ctr = ctr;
align = crypto_tfm_alg_alignmask(tfm);
align &= ~(crypto_tfm_ctx_alignment() - 1);
tfm->crt_aead.reqsize = align +
sizeof(struct crypto_ccm_req_priv_ctx) +
crypto_ablkcipher_reqsize(ctr);
return 0;
err_free_cipher:
crypto_free_cipher(cipher);
return err;
}
static void crypto_ccm_exit_tfm(struct crypto_tfm *tfm)
{
struct crypto_ccm_ctx *ctx = crypto_tfm_ctx(tfm);
crypto_free_cipher(ctx->cipher);
crypto_free_ablkcipher(ctx->ctr);
}
static struct crypto_instance *crypto_ccm_alloc_common(struct rtattr **tb,
const char *full_name,
const char *ctr_name,
const char *cipher_name)
{
struct crypto_attr_type *algt;
struct crypto_instance *inst;
struct crypto_alg *ctr;
struct crypto_alg *cipher;
struct ccm_instance_ctx *ictx;
int err;
algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt))
return ERR_PTR(err);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL);
cipher = crypto_alg_mod_lookup(cipher_name, CRYPTO_ALG_TYPE_CIPHER,
CRYPTO_ALG_TYPE_MASK);
err = PTR_ERR(cipher);
if (IS_ERR(cipher))
return ERR_PTR(err);
err = -EINVAL;
if (cipher->cra_blocksize != 16)
goto out_put_cipher;
inst = kzalloc(sizeof(*inst) + sizeof(*ictx), GFP_KERNEL);
err = -ENOMEM;
if (!inst)
goto out_put_cipher;
ictx = crypto_instance_ctx(inst);
err = crypto_init_spawn(&ictx->cipher, cipher, inst,
CRYPTO_ALG_TYPE_MASK);
if (err)
goto err_free_inst;
crypto_set_skcipher_spawn(&ictx->ctr, inst);
err = crypto_grab_skcipher(&ictx->ctr, ctr_name, 0,
crypto_requires_sync(algt->type,
algt->mask));
if (err)
goto err_drop_cipher;
ctr = crypto_skcipher_spawn_alg(&ictx->ctr);
/* Not a stream cipher? */
err = -EINVAL;
if (ctr->cra_blocksize != 1)
goto err_drop_ctr;
/* We want the real thing! */
if (ctr->cra_ablkcipher.ivsize != 16)
goto err_drop_ctr;
err = -ENAMETOOLONG;
if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
"ccm_base(%s,%s)", ctr->cra_driver_name,
cipher->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
goto err_drop_ctr;
memcpy(inst->alg.cra_name, full_name, CRYPTO_MAX_ALG_NAME);
inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
inst->alg.cra_flags |= ctr->cra_flags & CRYPTO_ALG_ASYNC;
inst->alg.cra_priority = cipher->cra_priority + ctr->cra_priority;
inst->alg.cra_blocksize = 1;
inst->alg.cra_alignmask = cipher->cra_alignmask | ctr->cra_alignmask |
(__alignof__(u32) - 1);
inst->alg.cra_type = &crypto_aead_type;
inst->alg.cra_aead.ivsize = 16;
inst->alg.cra_aead.maxauthsize = 16;
inst->alg.cra_ctxsize = sizeof(struct crypto_ccm_ctx);
inst->alg.cra_init = crypto_ccm_init_tfm;
inst->alg.cra_exit = crypto_ccm_exit_tfm;
inst->alg.cra_aead.setkey = crypto_ccm_setkey;
inst->alg.cra_aead.setauthsize = crypto_ccm_setauthsize;
inst->alg.cra_aead.encrypt = crypto_ccm_encrypt;
inst->alg.cra_aead.decrypt = crypto_ccm_decrypt;
out:
crypto_mod_put(cipher);
return inst;
err_drop_ctr:
crypto_drop_skcipher(&ictx->ctr);
err_drop_cipher:
crypto_drop_spawn(&ictx->cipher);
err_free_inst:
kfree(inst);
out_put_cipher:
inst = ERR_PTR(err);
goto out;
}
static struct crypto_instance *crypto_ccm_alloc(struct rtattr **tb)
{
int err;
const char *cipher_name;
char ctr_name[CRYPTO_MAX_ALG_NAME];
char full_name[CRYPTO_MAX_ALG_NAME];
cipher_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(cipher_name);
if (IS_ERR(cipher_name))
return ERR_PTR(err);
if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)",
cipher_name) >= CRYPTO_MAX_ALG_NAME)
return ERR_PTR(-ENAMETOOLONG);
if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "ccm(%s)", cipher_name) >=
CRYPTO_MAX_ALG_NAME)
return ERR_PTR(-ENAMETOOLONG);
return crypto_ccm_alloc_common(tb, full_name, ctr_name, cipher_name);
}
static void crypto_ccm_free(struct crypto_instance *inst)
{
struct ccm_instance_ctx *ctx = crypto_instance_ctx(inst);
crypto_drop_spawn(&ctx->cipher);
crypto_drop_skcipher(&ctx->ctr);
kfree(inst);
}
static struct crypto_template crypto_ccm_tmpl = {
.name = "ccm",
.alloc = crypto_ccm_alloc,
.free = crypto_ccm_free,
.module = THIS_MODULE,
};
static struct crypto_instance *crypto_ccm_base_alloc(struct rtattr **tb)
{
int err;
const char *ctr_name;
const char *cipher_name;
char full_name[CRYPTO_MAX_ALG_NAME];
ctr_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(ctr_name);
if (IS_ERR(ctr_name))
return ERR_PTR(err);
cipher_name = crypto_attr_alg_name(tb[2]);
err = PTR_ERR(cipher_name);
if (IS_ERR(cipher_name))
return ERR_PTR(err);
if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "ccm_base(%s,%s)",
ctr_name, cipher_name) >= CRYPTO_MAX_ALG_NAME)
return ERR_PTR(-ENAMETOOLONG);
return crypto_ccm_alloc_common(tb, full_name, ctr_name, cipher_name);
}
static struct crypto_template crypto_ccm_base_tmpl = {
.name = "ccm_base",
.alloc = crypto_ccm_base_alloc,
.free = crypto_ccm_free,
.module = THIS_MODULE,
};
static int crypto_rfc4309_setkey(struct crypto_aead *parent, const u8 *key,
unsigned int keylen)
{
struct crypto_rfc4309_ctx *ctx = crypto_aead_ctx(parent);
struct crypto_aead *child = ctx->child;
int err;
if (keylen < 3)
return -EINVAL;
keylen -= 3;
memcpy(ctx->nonce, key + keylen, 3);
crypto_aead_clear_flags(child, CRYPTO_TFM_REQ_MASK);
crypto_aead_set_flags(child, crypto_aead_get_flags(parent) &
CRYPTO_TFM_REQ_MASK);
err = crypto_aead_setkey(child, key, keylen);
crypto_aead_set_flags(parent, crypto_aead_get_flags(child) &
CRYPTO_TFM_RES_MASK);
return err;
}
static int crypto_rfc4309_setauthsize(struct crypto_aead *parent,
unsigned int authsize)
{
struct crypto_rfc4309_ctx *ctx = crypto_aead_ctx(parent);
switch (authsize) {
case 8:
case 12:
case 16:
break;
default:
return -EINVAL;
}
return crypto_aead_setauthsize(ctx->child, authsize);
}
static struct aead_request *crypto_rfc4309_crypt(struct aead_request *req)
{
struct aead_request *subreq = aead_request_ctx(req);
struct crypto_aead *aead = crypto_aead_reqtfm(req);
struct crypto_rfc4309_ctx *ctx = crypto_aead_ctx(aead);
struct crypto_aead *child = ctx->child;
u8 *iv = PTR_ALIGN((u8 *)(subreq + 1) + crypto_aead_reqsize(child),
crypto_aead_alignmask(child) + 1);
/* L' */
iv[0] = 3;
memcpy(iv + 1, ctx->nonce, 3);
memcpy(iv + 4, req->iv, 8);
aead_request_set_tfm(subreq, child);
aead_request_set_callback(subreq, req->base.flags, req->base.complete,
req->base.data);
aead_request_set_crypt(subreq, req->src, req->dst, req->cryptlen, iv);
aead_request_set_assoc(subreq, req->assoc, req->assoclen);
return subreq;
}
static int crypto_rfc4309_encrypt(struct aead_request *req)
{
req = crypto_rfc4309_crypt(req);
return crypto_aead_encrypt(req);
}
static int crypto_rfc4309_decrypt(struct aead_request *req)
{
req = crypto_rfc4309_crypt(req);
return crypto_aead_decrypt(req);
}
static int crypto_rfc4309_init_tfm(struct crypto_tfm *tfm)
{
struct crypto_instance *inst = (void *)tfm->__crt_alg;
struct crypto_aead_spawn *spawn = crypto_instance_ctx(inst);
struct crypto_rfc4309_ctx *ctx = crypto_tfm_ctx(tfm);
struct crypto_aead *aead;
unsigned long align;
aead = crypto_spawn_aead(spawn);
if (IS_ERR(aead))
return PTR_ERR(aead);
ctx->child = aead;
align = crypto_aead_alignmask(aead);
align &= ~(crypto_tfm_ctx_alignment() - 1);
tfm->crt_aead.reqsize = sizeof(struct aead_request) +
ALIGN(crypto_aead_reqsize(aead),
crypto_tfm_ctx_alignment()) +
align + 16;
return 0;
}
static void crypto_rfc4309_exit_tfm(struct crypto_tfm *tfm)
{
struct crypto_rfc4309_ctx *ctx = crypto_tfm_ctx(tfm);
crypto_free_aead(ctx->child);
}
static struct crypto_instance *crypto_rfc4309_alloc(struct rtattr **tb)
{
struct crypto_attr_type *algt;
struct crypto_instance *inst;
struct crypto_aead_spawn *spawn;
struct crypto_alg *alg;
const char *ccm_name;
int err;
algt = crypto_get_attr_type(tb);
err = PTR_ERR(algt);
if (IS_ERR(algt))
return ERR_PTR(err);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
return ERR_PTR(-EINVAL);
ccm_name = crypto_attr_alg_name(tb[1]);
err = PTR_ERR(ccm_name);
if (IS_ERR(ccm_name))
return ERR_PTR(err);
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
if (!inst)
return ERR_PTR(-ENOMEM);
spawn = crypto_instance_ctx(inst);
crypto_set_aead_spawn(spawn, inst);
err = crypto_grab_aead(spawn, ccm_name, 0,
crypto_requires_sync(algt->type, algt->mask));
if (err)
goto out_free_inst;
alg = crypto_aead_spawn_alg(spawn);
err = -EINVAL;
/* We only support 16-byte blocks. */
if (alg->cra_aead.ivsize != 16)
goto out_drop_alg;
/* Not a stream cipher? */
if (alg->cra_blocksize != 1)
goto out_drop_alg;
err = -ENAMETOOLONG;
if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
"rfc4309(%s)", alg->cra_name) >= CRYPTO_MAX_ALG_NAME ||
snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
"rfc4309(%s)", alg->cra_driver_name) >=
CRYPTO_MAX_ALG_NAME)
goto out_drop_alg;
inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
inst->alg.cra_flags |= alg->cra_flags & CRYPTO_ALG_ASYNC;
inst->alg.cra_priority = alg->cra_priority;
inst->alg.cra_blocksize = 1;
inst->alg.cra_alignmask = alg->cra_alignmask;
inst->alg.cra_type = &crypto_nivaead_type;
inst->alg.cra_aead.ivsize = 8;
inst->alg.cra_aead.maxauthsize = 16;
inst->alg.cra_ctxsize = sizeof(struct crypto_rfc4309_ctx);
inst->alg.cra_init = crypto_rfc4309_init_tfm;
inst->alg.cra_exit = crypto_rfc4309_exit_tfm;
inst->alg.cra_aead.setkey = crypto_rfc4309_setkey;
inst->alg.cra_aead.setauthsize = crypto_rfc4309_setauthsize;
inst->alg.cra_aead.encrypt = crypto_rfc4309_encrypt;
inst->alg.cra_aead.decrypt = crypto_rfc4309_decrypt;
inst->alg.cra_aead.geniv = "seqiv";
out:
return inst;
out_drop_alg:
crypto_drop_aead(spawn);
out_free_inst:
kfree(inst);
inst = ERR_PTR(err);
goto out;
}
static void crypto_rfc4309_free(struct crypto_instance *inst)
{
crypto_drop_spawn(crypto_instance_ctx(inst));
kfree(inst);
}
static struct crypto_template crypto_rfc4309_tmpl = {
.name = "rfc4309",
.alloc = crypto_rfc4309_alloc,
.free = crypto_rfc4309_free,
.module = THIS_MODULE,
};
static int __init crypto_ccm_module_init(void)
{
int err;
err = crypto_register_template(&crypto_ccm_base_tmpl);
if (err)
goto out;
err = crypto_register_template(&crypto_ccm_tmpl);
if (err)
goto out_undo_base;
err = crypto_register_template(&crypto_rfc4309_tmpl);
if (err)
goto out_undo_ccm;
out:
return err;
out_undo_ccm:
crypto_unregister_template(&crypto_ccm_tmpl);
out_undo_base:
crypto_unregister_template(&crypto_ccm_base_tmpl);
goto out;
}
static void __exit crypto_ccm_module_exit(void)
{
crypto_unregister_template(&crypto_rfc4309_tmpl);
crypto_unregister_template(&crypto_ccm_tmpl);
crypto_unregister_template(&crypto_ccm_base_tmpl);
}
module_init(crypto_ccm_module_init);
module_exit(crypto_ccm_module_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Counter with CBC MAC");
MODULE_ALIAS("ccm_base");
MODULE_ALIAS("rfc4309");
| gpl-2.0 |
HelllGuest/boom_kernel_sprout_kk | arch/arm/mach-sa1100/leds-badge4.c | 4867 | 2750 | /*
* linux/arch/arm/mach-sa1100/leds-badge4.c
*
* Author: Christopher Hoover <ch@hpl.hp.com>
* Copyright (C) 2002 Hewlett-Packard Company
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/init.h>
#include <mach/hardware.h>
#include <asm/leds.h>
#include "leds.h"
#define LED_STATE_ENABLED 1
#define LED_STATE_CLAIMED 2
static unsigned int led_state;
static unsigned int hw_led_state;
#define LED_RED GPIO_GPIO(7)
#define LED_GREEN GPIO_GPIO(9)
#define LED_MASK (LED_RED|LED_GREEN)
#define LED_IDLE LED_GREEN
#define LED_TIMER LED_RED
void badge4_leds_event(led_event_t evt)
{
unsigned long flags;
local_irq_save(flags);
switch (evt) {
case led_start:
GPDR |= LED_MASK;
hw_led_state = LED_MASK;
led_state = LED_STATE_ENABLED;
break;
case led_stop:
led_state &= ~LED_STATE_ENABLED;
break;
case led_claim:
led_state |= LED_STATE_CLAIMED;
hw_led_state = LED_MASK;
break;
case led_release:
led_state &= ~LED_STATE_CLAIMED;
hw_led_state = LED_MASK;
break;
#ifdef CONFIG_LEDS_TIMER
case led_timer:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state ^= LED_TIMER;
break;
#endif
#ifdef CONFIG_LEDS_CPU
case led_idle_start:
/* LED off when system is idle */
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state &= ~LED_IDLE;
break;
case led_idle_end:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state |= LED_IDLE;
break;
#endif
case led_red_on:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state &= ~LED_RED;
break;
case led_red_off:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state |= LED_RED;
break;
case led_green_on:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state &= ~LED_GREEN;
break;
case led_green_off:
if (!(led_state & LED_STATE_CLAIMED))
hw_led_state |= LED_GREEN;
break;
default:
break;
}
if (led_state & LED_STATE_ENABLED) {
GPSR = hw_led_state;
GPCR = hw_led_state ^ LED_MASK;
}
local_irq_restore(flags);
}
| gpl-2.0 |
Kurre/kernel_msm | drivers/net/ethernet/freescale/fsl_pq_mdio.c | 4867 | 10805 | /*
* Freescale PowerQUICC Ethernet Driver -- MIIM bus implementation
* Provides Bus interface for MIIM regs
*
* Author: Andy Fleming <afleming@freescale.com>
* Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
*
* Copyright 2002-2004, 2008-2009 Freescale Semiconductor, Inc.
*
* Based on gianfar_mii.c and ucc_geth_mii.c (Li Yang, Kim Phillips)
*
* 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 <linux/kernel.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/unistd.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/spinlock.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/crc32.h>
#include <linux/mii.h>
#include <linux/phy.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_mdio.h>
#include <linux/of_platform.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <asm/ucc.h>
#include "gianfar.h"
#include "fsl_pq_mdio.h"
struct fsl_pq_mdio_priv {
void __iomem *map;
struct fsl_pq_mdio __iomem *regs;
};
/*
* Write value to the PHY at mii_id at register regnum,
* on the bus attached to the local interface, which may be different from the
* generic mdio bus (tied to a single interface), waiting until the write is
* done before returning. This is helpful in programming interfaces like
* the TBI which control interfaces like onchip SERDES and are always tied to
* the local mdio pins, which may not be the same as system mdio bus, used for
* controlling the external PHYs, for example.
*/
int fsl_pq_local_mdio_write(struct fsl_pq_mdio __iomem *regs, int mii_id,
int regnum, u16 value)
{
/* Set the PHY address and the register address we want to write */
out_be32(®s->miimadd, (mii_id << 8) | regnum);
/* Write out the value we want */
out_be32(®s->miimcon, value);
/* Wait for the transaction to finish */
while (in_be32(®s->miimind) & MIIMIND_BUSY)
cpu_relax();
return 0;
}
/*
* Read the bus for PHY at addr mii_id, register regnum, and
* return the value. Clears miimcom first. All PHY operation
* done on the bus attached to the local interface,
* which may be different from the generic mdio bus
* This is helpful in programming interfaces like
* the TBI which, in turn, control interfaces like onchip SERDES
* and are always tied to the local mdio pins, which may not be the
* same as system mdio bus, used for controlling the external PHYs, for eg.
*/
int fsl_pq_local_mdio_read(struct fsl_pq_mdio __iomem *regs,
int mii_id, int regnum)
{
u16 value;
/* Set the PHY address and the register address we want to read */
out_be32(®s->miimadd, (mii_id << 8) | regnum);
/* Clear miimcom, and then initiate a read */
out_be32(®s->miimcom, 0);
out_be32(®s->miimcom, MII_READ_COMMAND);
/* Wait for the transaction to finish */
while (in_be32(®s->miimind) & (MIIMIND_NOTVALID | MIIMIND_BUSY))
cpu_relax();
/* Grab the value of the register from miimstat */
value = in_be32(®s->miimstat);
return value;
}
static struct fsl_pq_mdio __iomem *fsl_pq_mdio_get_regs(struct mii_bus *bus)
{
struct fsl_pq_mdio_priv *priv = bus->priv;
return priv->regs;
}
/*
* Write value to the PHY at mii_id at register regnum,
* on the bus, waiting until the write is done before returning.
*/
int fsl_pq_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value)
{
struct fsl_pq_mdio __iomem *regs = fsl_pq_mdio_get_regs(bus);
/* Write to the local MII regs */
return fsl_pq_local_mdio_write(regs, mii_id, regnum, value);
}
/*
* Read the bus for PHY at addr mii_id, register regnum, and
* return the value. Clears miimcom first.
*/
int fsl_pq_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
{
struct fsl_pq_mdio __iomem *regs = fsl_pq_mdio_get_regs(bus);
/* Read the local MII regs */
return fsl_pq_local_mdio_read(regs, mii_id, regnum);
}
/* Reset the MIIM registers, and wait for the bus to free */
static int fsl_pq_mdio_reset(struct mii_bus *bus)
{
struct fsl_pq_mdio __iomem *regs = fsl_pq_mdio_get_regs(bus);
int timeout = PHY_INIT_TIMEOUT;
mutex_lock(&bus->mdio_lock);
/* Reset the management interface */
out_be32(®s->miimcfg, MIIMCFG_RESET);
/* Setup the MII Mgmt clock speed */
out_be32(®s->miimcfg, MIIMCFG_INIT_VALUE);
/* Wait until the bus is free */
while ((in_be32(®s->miimind) & MIIMIND_BUSY) && timeout--)
cpu_relax();
mutex_unlock(&bus->mdio_lock);
if (timeout < 0) {
printk(KERN_ERR "%s: The MII Bus is stuck!\n",
bus->name);
return -EBUSY;
}
return 0;
}
void fsl_pq_mdio_bus_name(char *name, struct device_node *np)
{
const u32 *addr;
u64 taddr = OF_BAD_ADDR;
addr = of_get_address(np, 0, NULL, NULL);
if (addr)
taddr = of_translate_address(np, addr);
snprintf(name, MII_BUS_ID_SIZE, "%s@%llx", np->name,
(unsigned long long)taddr);
}
EXPORT_SYMBOL_GPL(fsl_pq_mdio_bus_name);
static u32 __iomem *get_gfar_tbipa(struct fsl_pq_mdio __iomem *regs, struct device_node *np)
{
#if defined(CONFIG_GIANFAR) || defined(CONFIG_GIANFAR_MODULE)
struct gfar __iomem *enet_regs;
/*
* This is mildly evil, but so is our hardware for doing this.
* Also, we have to cast back to struct gfar because of
* definition weirdness done in gianfar.h.
*/
if(of_device_is_compatible(np, "fsl,gianfar-mdio") ||
of_device_is_compatible(np, "fsl,gianfar-tbi") ||
of_device_is_compatible(np, "gianfar")) {
enet_regs = (struct gfar __iomem *)regs;
return &enet_regs->tbipa;
} else if (of_device_is_compatible(np, "fsl,etsec2-mdio") ||
of_device_is_compatible(np, "fsl,etsec2-tbi")) {
return of_iomap(np, 1);
}
#endif
return NULL;
}
static int get_ucc_id_for_range(u64 start, u64 end, u32 *ucc_id)
{
#if defined(CONFIG_UCC_GETH) || defined(CONFIG_UCC_GETH_MODULE)
struct device_node *np = NULL;
int err = 0;
for_each_compatible_node(np, NULL, "ucc_geth") {
struct resource tempres;
err = of_address_to_resource(np, 0, &tempres);
if (err)
continue;
/* if our mdio regs fall within this UCC regs range */
if ((start >= tempres.start) && (end <= tempres.end)) {
/* Find the id of the UCC */
const u32 *id;
id = of_get_property(np, "cell-index", NULL);
if (!id) {
id = of_get_property(np, "device-id", NULL);
if (!id)
continue;
}
*ucc_id = *id;
return 0;
}
}
if (err)
return err;
else
return -EINVAL;
#else
return -ENODEV;
#endif
}
static int fsl_pq_mdio_probe(struct platform_device *ofdev)
{
struct device_node *np = ofdev->dev.of_node;
struct device_node *tbi;
struct fsl_pq_mdio_priv *priv;
struct fsl_pq_mdio __iomem *regs = NULL;
void __iomem *map;
u32 __iomem *tbipa;
struct mii_bus *new_bus;
int tbiaddr = -1;
const u32 *addrp;
u64 addr = 0, size = 0;
int err;
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
new_bus = mdiobus_alloc();
if (!new_bus) {
err = -ENOMEM;
goto err_free_priv;
}
new_bus->name = "Freescale PowerQUICC MII Bus",
new_bus->read = &fsl_pq_mdio_read,
new_bus->write = &fsl_pq_mdio_write,
new_bus->reset = &fsl_pq_mdio_reset,
new_bus->priv = priv;
fsl_pq_mdio_bus_name(new_bus->id, np);
addrp = of_get_address(np, 0, &size, NULL);
if (!addrp) {
err = -EINVAL;
goto err_free_bus;
}
/* Set the PHY base address */
addr = of_translate_address(np, addrp);
if (addr == OF_BAD_ADDR) {
err = -EINVAL;
goto err_free_bus;
}
map = ioremap(addr, size);
if (!map) {
err = -ENOMEM;
goto err_free_bus;
}
priv->map = map;
if (of_device_is_compatible(np, "fsl,gianfar-mdio") ||
of_device_is_compatible(np, "fsl,gianfar-tbi") ||
of_device_is_compatible(np, "fsl,ucc-mdio") ||
of_device_is_compatible(np, "ucc_geth_phy"))
map -= offsetof(struct fsl_pq_mdio, miimcfg);
regs = map;
priv->regs = regs;
new_bus->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL);
if (NULL == new_bus->irq) {
err = -ENOMEM;
goto err_unmap_regs;
}
new_bus->parent = &ofdev->dev;
dev_set_drvdata(&ofdev->dev, new_bus);
if (of_device_is_compatible(np, "fsl,gianfar-mdio") ||
of_device_is_compatible(np, "fsl,gianfar-tbi") ||
of_device_is_compatible(np, "fsl,etsec2-mdio") ||
of_device_is_compatible(np, "fsl,etsec2-tbi") ||
of_device_is_compatible(np, "gianfar")) {
tbipa = get_gfar_tbipa(regs, np);
if (!tbipa) {
err = -EINVAL;
goto err_free_irqs;
}
} else if (of_device_is_compatible(np, "fsl,ucc-mdio") ||
of_device_is_compatible(np, "ucc_geth_phy")) {
u32 id;
static u32 mii_mng_master;
tbipa = ®s->utbipar;
if ((err = get_ucc_id_for_range(addr, addr + size, &id)))
goto err_free_irqs;
if (!mii_mng_master) {
mii_mng_master = id;
ucc_set_qe_mux_mii_mng(id - 1);
}
} else {
err = -ENODEV;
goto err_free_irqs;
}
for_each_child_of_node(np, tbi) {
if (!strncmp(tbi->type, "tbi-phy", 8))
break;
}
if (tbi) {
const u32 *prop = of_get_property(tbi, "reg", NULL);
if (prop)
tbiaddr = *prop;
if (tbiaddr == -1) {
err = -EBUSY;
goto err_free_irqs;
} else {
out_be32(tbipa, tbiaddr);
}
}
err = of_mdiobus_register(new_bus, np);
if (err) {
printk (KERN_ERR "%s: Cannot register as MDIO bus\n",
new_bus->name);
goto err_free_irqs;
}
return 0;
err_free_irqs:
kfree(new_bus->irq);
err_unmap_regs:
iounmap(priv->map);
err_free_bus:
kfree(new_bus);
err_free_priv:
kfree(priv);
return err;
}
static int fsl_pq_mdio_remove(struct platform_device *ofdev)
{
struct device *device = &ofdev->dev;
struct mii_bus *bus = dev_get_drvdata(device);
struct fsl_pq_mdio_priv *priv = bus->priv;
mdiobus_unregister(bus);
dev_set_drvdata(device, NULL);
iounmap(priv->map);
bus->priv = NULL;
mdiobus_free(bus);
kfree(priv);
return 0;
}
static struct of_device_id fsl_pq_mdio_match[] = {
{
.type = "mdio",
.compatible = "ucc_geth_phy",
},
{
.type = "mdio",
.compatible = "gianfar",
},
{
.compatible = "fsl,ucc-mdio",
},
{
.compatible = "fsl,gianfar-tbi",
},
{
.compatible = "fsl,gianfar-mdio",
},
{
.compatible = "fsl,etsec2-tbi",
},
{
.compatible = "fsl,etsec2-mdio",
},
{},
};
MODULE_DEVICE_TABLE(of, fsl_pq_mdio_match);
static struct platform_driver fsl_pq_mdio_driver = {
.driver = {
.name = "fsl-pq_mdio",
.owner = THIS_MODULE,
.of_match_table = fsl_pq_mdio_match,
},
.probe = fsl_pq_mdio_probe,
.remove = fsl_pq_mdio_remove,
};
module_platform_driver(fsl_pq_mdio_driver);
MODULE_LICENSE("GPL");
| gpl-2.0 |
xDARKMATT3Rx/xDARKMATT3Rx_davidskernel | arch/arm/mach-ixp4xx/ixdp425-pci.c | 5379 | 1914 | /*
* arch/arm/mach-ixp4xx/ixdp425-pci.c
*
* IXDP425 board-level PCI initialization
*
* Copyright (C) 2002 Intel Corporation.
* Copyright (C) 2003-2004 MontaVista Software, Inc.
*
* Maintainer: Deepak Saxena <dsaxena@plexity.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/irq.h>
#include <linux/delay.h>
#include <asm/mach/pci.h>
#include <asm/irq.h>
#include <mach/hardware.h>
#include <asm/mach-types.h>
#define MAX_DEV 4
#define IRQ_LINES 4
/* PCI controller GPIO to IRQ pin mappings */
#define INTA 11
#define INTB 10
#define INTC 9
#define INTD 8
void __init ixdp425_pci_preinit(void)
{
irq_set_irq_type(IXP4XX_GPIO_IRQ(INTA), IRQ_TYPE_LEVEL_LOW);
irq_set_irq_type(IXP4XX_GPIO_IRQ(INTB), IRQ_TYPE_LEVEL_LOW);
irq_set_irq_type(IXP4XX_GPIO_IRQ(INTC), IRQ_TYPE_LEVEL_LOW);
irq_set_irq_type(IXP4XX_GPIO_IRQ(INTD), IRQ_TYPE_LEVEL_LOW);
ixp4xx_pci_preinit();
}
static int __init ixdp425_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
{
static int pci_irq_table[IRQ_LINES] = {
IXP4XX_GPIO_IRQ(INTA),
IXP4XX_GPIO_IRQ(INTB),
IXP4XX_GPIO_IRQ(INTC),
IXP4XX_GPIO_IRQ(INTD)
};
if (slot >= 1 && slot <= MAX_DEV && pin >= 1 && pin <= IRQ_LINES)
return pci_irq_table[(slot + pin - 2) % 4];
return -1;
}
struct hw_pci ixdp425_pci __initdata = {
.nr_controllers = 1,
.preinit = ixdp425_pci_preinit,
.swizzle = pci_std_swizzle,
.setup = ixp4xx_setup,
.scan = ixp4xx_scan_bus,
.map_irq = ixdp425_map_irq,
};
int __init ixdp425_pci_init(void)
{
if (machine_is_ixdp425() || machine_is_ixcdp1100() ||
machine_is_ixdp465() || machine_is_kixrp435())
pci_common_init(&ixdp425_pci);
return 0;
}
subsys_initcall(ixdp425_pci_init);
| gpl-2.0 |
C-Aniruddh/SXD_kernel | drivers/tty/ipwireless/hardware.c | 8195 | 46474 | /*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h>
#include "hardware.h"
#include "setup_protocol.h"
#include "network.h"
#include "main.h"
static void ipw_send_setup_packet(struct ipw_hardware *hw);
static void handle_received_SETUP_packet(struct ipw_hardware *ipw,
unsigned int address,
const unsigned char *data, int len,
int is_last);
static void ipwireless_setup_timer(unsigned long data);
static void handle_received_CTRL_packet(struct ipw_hardware *hw,
unsigned int channel_idx, const unsigned char *data, int len);
/*#define TIMING_DIAGNOSTICS*/
#ifdef TIMING_DIAGNOSTICS
static struct timing_stats {
unsigned long last_report_time;
unsigned long read_time;
unsigned long write_time;
unsigned long read_bytes;
unsigned long write_bytes;
unsigned long start_time;
};
static void start_timing(void)
{
timing_stats.start_time = jiffies;
}
static void end_read_timing(unsigned length)
{
timing_stats.read_time += (jiffies - start_time);
timing_stats.read_bytes += length + 2;
report_timing();
}
static void end_write_timing(unsigned length)
{
timing_stats.write_time += (jiffies - start_time);
timing_stats.write_bytes += length + 2;
report_timing();
}
static void report_timing(void)
{
unsigned long since = jiffies - timing_stats.last_report_time;
/* If it's been more than one second... */
if (since >= HZ) {
int first = (timing_stats.last_report_time == 0);
timing_stats.last_report_time = jiffies;
if (!first)
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": %u us elapsed - read %lu bytes in %u us, wrote %lu bytes in %u us\n",
jiffies_to_usecs(since),
timing_stats.read_bytes,
jiffies_to_usecs(timing_stats.read_time),
timing_stats.write_bytes,
jiffies_to_usecs(timing_stats.write_time));
timing_stats.read_time = 0;
timing_stats.write_time = 0;
timing_stats.read_bytes = 0;
timing_stats.write_bytes = 0;
}
}
#else
static void start_timing(void) { }
static void end_read_timing(unsigned length) { }
static void end_write_timing(unsigned length) { }
#endif
/* Imported IPW definitions */
#define LL_MTU_V1 318
#define LL_MTU_V2 250
#define LL_MTU_MAX (LL_MTU_V1 > LL_MTU_V2 ? LL_MTU_V1 : LL_MTU_V2)
#define PRIO_DATA 2
#define PRIO_CTRL 1
#define PRIO_SETUP 0
/* Addresses */
#define ADDR_SETUP_PROT 0
/* Protocol ids */
enum {
/* Identifier for the Com Data protocol */
TL_PROTOCOLID_COM_DATA = 0,
/* Identifier for the Com Control protocol */
TL_PROTOCOLID_COM_CTRL = 1,
/* Identifier for the Setup protocol */
TL_PROTOCOLID_SETUP = 2
};
/* Number of bytes in NL packet header (cannot do
* sizeof(nl_packet_header) since it's a bitfield) */
#define NL_FIRST_PACKET_HEADER_SIZE 3
/* Number of bytes in NL packet header (cannot do
* sizeof(nl_packet_header) since it's a bitfield) */
#define NL_FOLLOWING_PACKET_HEADER_SIZE 1
struct nl_first_packet_header {
unsigned char protocol:3;
unsigned char address:3;
unsigned char packet_rank:2;
unsigned char length_lsb;
unsigned char length_msb;
};
struct nl_packet_header {
unsigned char protocol:3;
unsigned char address:3;
unsigned char packet_rank:2;
};
/* Value of 'packet_rank' above */
#define NL_INTERMEDIATE_PACKET 0x0
#define NL_LAST_PACKET 0x1
#define NL_FIRST_PACKET 0x2
union nl_packet {
/* Network packet header of the first packet (a special case) */
struct nl_first_packet_header hdr_first;
/* Network packet header of the following packets (if any) */
struct nl_packet_header hdr;
/* Complete network packet (header + data) */
unsigned char rawpkt[LL_MTU_MAX];
} __attribute__ ((__packed__));
#define HW_VERSION_UNKNOWN -1
#define HW_VERSION_1 1
#define HW_VERSION_2 2
/* IPW I/O ports */
#define IOIER 0x00 /* Interrupt Enable Register */
#define IOIR 0x02 /* Interrupt Source/ACK register */
#define IODCR 0x04 /* Data Control Register */
#define IODRR 0x06 /* Data Read Register */
#define IODWR 0x08 /* Data Write Register */
#define IOESR 0x0A /* Embedded Driver Status Register */
#define IORXR 0x0C /* Rx Fifo Register (Host to Embedded) */
#define IOTXR 0x0E /* Tx Fifo Register (Embedded to Host) */
/* I/O ports and bit definitions for version 1 of the hardware */
/* IER bits*/
#define IER_RXENABLED 0x1
#define IER_TXENABLED 0x2
/* ISR bits */
#define IR_RXINTR 0x1
#define IR_TXINTR 0x2
/* DCR bits */
#define DCR_RXDONE 0x1
#define DCR_TXDONE 0x2
#define DCR_RXRESET 0x4
#define DCR_TXRESET 0x8
/* I/O ports and bit definitions for version 2 of the hardware */
struct MEMCCR {
unsigned short reg_config_option; /* PCCOR: Configuration Option Register */
unsigned short reg_config_and_status; /* PCCSR: Configuration and Status Register */
unsigned short reg_pin_replacement; /* PCPRR: Pin Replacemant Register */
unsigned short reg_socket_and_copy; /* PCSCR: Socket and Copy Register */
unsigned short reg_ext_status; /* PCESR: Extendend Status Register */
unsigned short reg_io_base; /* PCIOB: I/O Base Register */
};
struct MEMINFREG {
unsigned short memreg_tx_old; /* TX Register (R/W) */
unsigned short pad1;
unsigned short memreg_rx_done; /* RXDone Register (R/W) */
unsigned short pad2;
unsigned short memreg_rx; /* RX Register (R/W) */
unsigned short pad3;
unsigned short memreg_pc_interrupt_ack; /* PC intr Ack Register (W) */
unsigned short pad4;
unsigned long memreg_card_present;/* Mask for Host to check (R) for
* CARD_PRESENT_VALUE */
unsigned short memreg_tx_new; /* TX2 (new) Register (R/W) */
};
#define CARD_PRESENT_VALUE (0xBEEFCAFEUL)
#define MEMTX_TX 0x0001
#define MEMRX_RX 0x0001
#define MEMRX_RX_DONE 0x0001
#define MEMRX_PCINTACKK 0x0001
#define NL_NUM_OF_PRIORITIES 3
#define NL_NUM_OF_PROTOCOLS 3
#define NL_NUM_OF_ADDRESSES NO_OF_IPW_CHANNELS
struct ipw_hardware {
unsigned int base_port;
short hw_version;
unsigned short ll_mtu;
spinlock_t lock;
int initializing;
int init_loops;
struct timer_list setup_timer;
/* Flag if hw is ready to send next packet */
int tx_ready;
/* Count of pending packets to be sent */
int tx_queued;
struct list_head tx_queue[NL_NUM_OF_PRIORITIES];
int rx_bytes_queued;
struct list_head rx_queue;
/* Pool of rx_packet structures that are not currently used. */
struct list_head rx_pool;
int rx_pool_size;
/* True if reception of data is blocked while userspace processes it. */
int blocking_rx;
/* True if there is RX data ready on the hardware. */
int rx_ready;
unsigned short last_memtx_serial;
/*
* Newer versions of the V2 card firmware send serial numbers in the
* MemTX register. 'serial_number_detected' is set true when we detect
* a non-zero serial number (indicating the new firmware). Thereafter,
* the driver can safely ignore the Timer Recovery re-sends to avoid
* out-of-sync problems.
*/
int serial_number_detected;
struct work_struct work_rx;
/* True if we are to send the set-up data to the hardware. */
int to_setup;
/* Card has been removed */
int removed;
/* Saved irq value when we disable the interrupt. */
int irq;
/* True if this driver is shutting down. */
int shutting_down;
/* Modem control lines */
unsigned int control_lines[NL_NUM_OF_ADDRESSES];
struct ipw_rx_packet *packet_assembler[NL_NUM_OF_ADDRESSES];
struct tasklet_struct tasklet;
/* The handle for the network layer, for the sending of events to it. */
struct ipw_network *network;
struct MEMINFREG __iomem *memory_info_regs;
struct MEMCCR __iomem *memregs_CCR;
void (*reboot_callback) (void *data);
void *reboot_callback_data;
unsigned short __iomem *memreg_tx;
};
/*
* Packet info structure for tx packets.
* Note: not all the fields defined here are required for all protocols
*/
struct ipw_tx_packet {
struct list_head queue;
/* channel idx + 1 */
unsigned char dest_addr;
/* SETUP, CTRL or DATA */
unsigned char protocol;
/* Length of data block, which starts at the end of this structure */
unsigned short length;
/* Sending state */
/* Offset of where we've sent up to so far */
unsigned long offset;
/* Count of packet fragments, starting at 0 */
int fragment_count;
/* Called after packet is sent and before is freed */
void (*packet_callback) (void *cb_data, unsigned int packet_length);
void *callback_data;
};
/* Signals from DTE */
#define COMCTRL_RTS 0
#define COMCTRL_DTR 1
/* Signals from DCE */
#define COMCTRL_CTS 2
#define COMCTRL_DCD 3
#define COMCTRL_DSR 4
#define COMCTRL_RI 5
struct ipw_control_packet_body {
/* DTE signal or DCE signal */
unsigned char sig_no;
/* 0: set signal, 1: clear signal */
unsigned char value;
} __attribute__ ((__packed__));
struct ipw_control_packet {
struct ipw_tx_packet header;
struct ipw_control_packet_body body;
};
struct ipw_rx_packet {
struct list_head queue;
unsigned int capacity;
unsigned int length;
unsigned int protocol;
unsigned int channel_idx;
};
static char *data_type(const unsigned char *buf, unsigned length)
{
struct nl_packet_header *hdr = (struct nl_packet_header *) buf;
if (length == 0)
return " ";
if (hdr->packet_rank & NL_FIRST_PACKET) {
switch (hdr->protocol) {
case TL_PROTOCOLID_COM_DATA: return "DATA ";
case TL_PROTOCOLID_COM_CTRL: return "CTRL ";
case TL_PROTOCOLID_SETUP: return "SETUP";
default: return "???? ";
}
} else
return " ";
}
#define DUMP_MAX_BYTES 64
static void dump_data_bytes(const char *type, const unsigned char *data,
unsigned length)
{
char prefix[56];
sprintf(prefix, IPWIRELESS_PCCARD_NAME ": %s %s ",
type, data_type(data, length));
print_hex_dump_bytes(prefix, 0, (void *)data,
length < DUMP_MAX_BYTES ? length : DUMP_MAX_BYTES);
}
static void swap_packet_bitfield_to_le(unsigned char *data)
{
#ifdef __BIG_ENDIAN_BITFIELD
unsigned char tmp = *data, ret = 0;
/*
* transform bits from aa.bbb.ccc to ccc.bbb.aa
*/
ret |= tmp & 0xc0 >> 6;
ret |= tmp & 0x38 >> 1;
ret |= tmp & 0x07 << 5;
*data = ret & 0xff;
#endif
}
static void swap_packet_bitfield_from_le(unsigned char *data)
{
#ifdef __BIG_ENDIAN_BITFIELD
unsigned char tmp = *data, ret = 0;
/*
* transform bits from ccc.bbb.aa to aa.bbb.ccc
*/
ret |= tmp & 0xe0 >> 5;
ret |= tmp & 0x1c << 1;
ret |= tmp & 0x03 << 6;
*data = ret & 0xff;
#endif
}
static void do_send_fragment(struct ipw_hardware *hw, unsigned char *data,
unsigned length)
{
unsigned i;
unsigned long flags;
start_timing();
BUG_ON(length > hw->ll_mtu);
if (ipwireless_debug)
dump_data_bytes("send", data, length);
spin_lock_irqsave(&hw->lock, flags);
hw->tx_ready = 0;
swap_packet_bitfield_to_le(data);
if (hw->hw_version == HW_VERSION_1) {
outw((unsigned short) length, hw->base_port + IODWR);
for (i = 0; i < length; i += 2) {
unsigned short d = data[i];
__le16 raw_data;
if (i + 1 < length)
d |= data[i + 1] << 8;
raw_data = cpu_to_le16(d);
outw(raw_data, hw->base_port + IODWR);
}
outw(DCR_TXDONE, hw->base_port + IODCR);
} else if (hw->hw_version == HW_VERSION_2) {
outw((unsigned short) length, hw->base_port);
for (i = 0; i < length; i += 2) {
unsigned short d = data[i];
__le16 raw_data;
if (i + 1 < length)
d |= data[i + 1] << 8;
raw_data = cpu_to_le16(d);
outw(raw_data, hw->base_port);
}
while ((i & 3) != 2) {
outw((unsigned short) 0xDEAD, hw->base_port);
i += 2;
}
writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx);
}
spin_unlock_irqrestore(&hw->lock, flags);
end_write_timing(length);
}
static void do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
{
unsigned short fragment_data_len;
unsigned short data_left = packet->length - packet->offset;
unsigned short header_size;
union nl_packet pkt;
header_size =
(packet->fragment_count == 0)
? NL_FIRST_PACKET_HEADER_SIZE
: NL_FOLLOWING_PACKET_HEADER_SIZE;
fragment_data_len = hw->ll_mtu - header_size;
if (data_left < fragment_data_len)
fragment_data_len = data_left;
/*
* hdr_first is now in machine bitfield order, which will be swapped
* to le just before it goes to hw
*/
pkt.hdr_first.protocol = packet->protocol;
pkt.hdr_first.address = packet->dest_addr;
pkt.hdr_first.packet_rank = 0;
/* First packet? */
if (packet->fragment_count == 0) {
pkt.hdr_first.packet_rank |= NL_FIRST_PACKET;
pkt.hdr_first.length_lsb = (unsigned char) packet->length;
pkt.hdr_first.length_msb =
(unsigned char) (packet->length >> 8);
}
memcpy(pkt.rawpkt + header_size,
((unsigned char *) packet) + sizeof(struct ipw_tx_packet) +
packet->offset, fragment_data_len);
packet->offset += fragment_data_len;
packet->fragment_count++;
/* Last packet? (May also be first packet.) */
if (packet->offset == packet->length)
pkt.hdr_first.packet_rank |= NL_LAST_PACKET;
do_send_fragment(hw, pkt.rawpkt, header_size + fragment_data_len);
/* If this packet has unsent data, then re-queue it. */
if (packet->offset < packet->length) {
/*
* Re-queue it at the head of the highest priority queue so
* it goes before all other packets
*/
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
list_add(&packet->queue, &hw->tx_queue[0]);
hw->tx_queued++;
spin_unlock_irqrestore(&hw->lock, flags);
} else {
if (packet->packet_callback)
packet->packet_callback(packet->callback_data,
packet->length);
kfree(packet);
}
}
static void ipw_setup_hardware(struct ipw_hardware *hw)
{
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (hw->hw_version == HW_VERSION_1) {
/* Reset RX FIFO */
outw(DCR_RXRESET, hw->base_port + IODCR);
/* SB: Reset TX FIFO */
outw(DCR_TXRESET, hw->base_port + IODCR);
/* Enable TX and RX interrupts. */
outw(IER_TXENABLED | IER_RXENABLED, hw->base_port + IOIER);
} else {
/*
* Set INTRACK bit (bit 0), which means we must explicitly
* acknowledge interrupts by clearing bit 2 of reg_config_and_status.
*/
unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
csr |= 1;
writew(csr, &hw->memregs_CCR->reg_config_and_status);
}
spin_unlock_irqrestore(&hw->lock, flags);
}
/*
* If 'packet' is NULL, then this function allocates a new packet, setting its
* length to 0 and ensuring it has the specified minimum amount of free space.
*
* If 'packet' is not NULL, then this function enlarges it if it doesn't
* have the specified minimum amount of free space.
*
*/
static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
struct ipw_rx_packet *packet,
int minimum_free_space)
{
if (!packet) {
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (!list_empty(&hw->rx_pool)) {
packet = list_first_entry(&hw->rx_pool,
struct ipw_rx_packet, queue);
hw->rx_pool_size--;
spin_unlock_irqrestore(&hw->lock, flags);
list_del(&packet->queue);
} else {
const int min_capacity =
ipwireless_ppp_mru(hw->network) + 2;
int new_capacity;
spin_unlock_irqrestore(&hw->lock, flags);
new_capacity =
(minimum_free_space > min_capacity
? minimum_free_space
: min_capacity);
packet = kmalloc(sizeof(struct ipw_rx_packet)
+ new_capacity, GFP_ATOMIC);
if (!packet)
return NULL;
packet->capacity = new_capacity;
}
packet->length = 0;
}
if (packet->length + minimum_free_space > packet->capacity) {
struct ipw_rx_packet *old_packet = packet;
packet = kmalloc(sizeof(struct ipw_rx_packet) +
old_packet->length + minimum_free_space,
GFP_ATOMIC);
if (!packet) {
kfree(old_packet);
return NULL;
}
memcpy(packet, old_packet,
sizeof(struct ipw_rx_packet)
+ old_packet->length);
packet->capacity = old_packet->length + minimum_free_space;
kfree(old_packet);
}
return packet;
}
static void pool_free(struct ipw_hardware *hw, struct ipw_rx_packet *packet)
{
if (hw->rx_pool_size > 6)
kfree(packet);
else {
hw->rx_pool_size++;
list_add(&packet->queue, &hw->rx_pool);
}
}
static void queue_received_packet(struct ipw_hardware *hw,
unsigned int protocol,
unsigned int address,
const unsigned char *data, int length,
int is_last)
{
unsigned int channel_idx = address - 1;
struct ipw_rx_packet *packet = NULL;
unsigned long flags;
/* Discard packet if channel index is out of range. */
if (channel_idx >= NL_NUM_OF_ADDRESSES) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": data packet has bad address %u\n", address);
return;
}
/*
* ->packet_assembler is safe to touch unlocked, this is the only place
*/
if (protocol == TL_PROTOCOLID_COM_DATA) {
struct ipw_rx_packet **assem =
&hw->packet_assembler[channel_idx];
/*
* Create a new packet, or assembler already contains one
* enlarge it by 'length' bytes.
*/
(*assem) = pool_allocate(hw, *assem, length);
if (!(*assem)) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": no memory for incomming data packet, dropped!\n");
return;
}
(*assem)->protocol = protocol;
(*assem)->channel_idx = channel_idx;
/* Append this packet data onto existing data. */
memcpy((unsigned char *)(*assem) +
sizeof(struct ipw_rx_packet)
+ (*assem)->length, data, length);
(*assem)->length += length;
if (is_last) {
packet = *assem;
*assem = NULL;
/* Count queued DATA bytes only */
spin_lock_irqsave(&hw->lock, flags);
hw->rx_bytes_queued += packet->length;
spin_unlock_irqrestore(&hw->lock, flags);
}
} else {
/* If it's a CTRL packet, don't assemble, just queue it. */
packet = pool_allocate(hw, NULL, length);
if (!packet) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": no memory for incomming ctrl packet, dropped!\n");
return;
}
packet->protocol = protocol;
packet->channel_idx = channel_idx;
memcpy((unsigned char *)packet + sizeof(struct ipw_rx_packet),
data, length);
packet->length = length;
}
/*
* If this is the last packet, then send the assembled packet on to the
* network layer.
*/
if (packet) {
spin_lock_irqsave(&hw->lock, flags);
list_add_tail(&packet->queue, &hw->rx_queue);
/* Block reception of incoming packets if queue is full. */
hw->blocking_rx =
(hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE);
spin_unlock_irqrestore(&hw->lock, flags);
schedule_work(&hw->work_rx);
}
}
/*
* Workqueue callback
*/
static void ipw_receive_data_work(struct work_struct *work_rx)
{
struct ipw_hardware *hw =
container_of(work_rx, struct ipw_hardware, work_rx);
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
while (!list_empty(&hw->rx_queue)) {
struct ipw_rx_packet *packet =
list_first_entry(&hw->rx_queue,
struct ipw_rx_packet, queue);
if (hw->shutting_down)
break;
list_del(&packet->queue);
/*
* Note: ipwireless_network_packet_received must be called in a
* process context (i.e. via schedule_work) because the tty
* output code can sleep in the tty_flip_buffer_push call.
*/
if (packet->protocol == TL_PROTOCOLID_COM_DATA) {
if (hw->network != NULL) {
/* If the network hasn't been disconnected. */
spin_unlock_irqrestore(&hw->lock, flags);
/*
* This must run unlocked due to tty processing
* and mutex locking
*/
ipwireless_network_packet_received(
hw->network,
packet->channel_idx,
(unsigned char *)packet
+ sizeof(struct ipw_rx_packet),
packet->length);
spin_lock_irqsave(&hw->lock, flags);
}
/* Count queued DATA bytes only */
hw->rx_bytes_queued -= packet->length;
} else {
/*
* This is safe to be called locked, callchain does
* not block
*/
handle_received_CTRL_packet(hw, packet->channel_idx,
(unsigned char *)packet
+ sizeof(struct ipw_rx_packet),
packet->length);
}
pool_free(hw, packet);
/*
* Unblock reception of incoming packets if queue is no longer
* full.
*/
hw->blocking_rx =
hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
if (hw->shutting_down)
break;
}
spin_unlock_irqrestore(&hw->lock, flags);
}
static void handle_received_CTRL_packet(struct ipw_hardware *hw,
unsigned int channel_idx,
const unsigned char *data, int len)
{
const struct ipw_control_packet_body *body =
(const struct ipw_control_packet_body *) data;
unsigned int changed_mask;
if (len != sizeof(struct ipw_control_packet_body)) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": control packet was %d bytes - wrong size!\n",
len);
return;
}
switch (body->sig_no) {
case COMCTRL_CTS:
changed_mask = IPW_CONTROL_LINE_CTS;
break;
case COMCTRL_DCD:
changed_mask = IPW_CONTROL_LINE_DCD;
break;
case COMCTRL_DSR:
changed_mask = IPW_CONTROL_LINE_DSR;
break;
case COMCTRL_RI:
changed_mask = IPW_CONTROL_LINE_RI;
break;
default:
changed_mask = 0;
}
if (changed_mask != 0) {
if (body->value)
hw->control_lines[channel_idx] |= changed_mask;
else
hw->control_lines[channel_idx] &= ~changed_mask;
if (hw->network)
ipwireless_network_notify_control_line_change(
hw->network,
channel_idx,
hw->control_lines[channel_idx],
changed_mask);
}
}
static void handle_received_packet(struct ipw_hardware *hw,
const union nl_packet *packet,
unsigned short len)
{
unsigned int protocol = packet->hdr.protocol;
unsigned int address = packet->hdr.address;
unsigned int header_length;
const unsigned char *data;
unsigned int data_len;
int is_last = packet->hdr.packet_rank & NL_LAST_PACKET;
if (packet->hdr.packet_rank & NL_FIRST_PACKET)
header_length = NL_FIRST_PACKET_HEADER_SIZE;
else
header_length = NL_FOLLOWING_PACKET_HEADER_SIZE;
data = packet->rawpkt + header_length;
data_len = len - header_length;
switch (protocol) {
case TL_PROTOCOLID_COM_DATA:
case TL_PROTOCOLID_COM_CTRL:
queue_received_packet(hw, protocol, address, data, data_len,
is_last);
break;
case TL_PROTOCOLID_SETUP:
handle_received_SETUP_packet(hw, address, data, data_len,
is_last);
break;
}
}
static void acknowledge_data_read(struct ipw_hardware *hw)
{
if (hw->hw_version == HW_VERSION_1)
outw(DCR_RXDONE, hw->base_port + IODCR);
else
writew(MEMRX_PCINTACKK,
&hw->memory_info_regs->memreg_pc_interrupt_ack);
}
/*
* Retrieve a packet from the IPW hardware.
*/
static void do_receive_packet(struct ipw_hardware *hw)
{
unsigned len;
unsigned i;
unsigned char pkt[LL_MTU_MAX];
start_timing();
if (hw->hw_version == HW_VERSION_1) {
len = inw(hw->base_port + IODRR);
if (len > hw->ll_mtu) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": received a packet of %u bytes - longer than the MTU!\n", len);
outw(DCR_RXDONE | DCR_RXRESET, hw->base_port + IODCR);
return;
}
for (i = 0; i < len; i += 2) {
__le16 raw_data = inw(hw->base_port + IODRR);
unsigned short data = le16_to_cpu(raw_data);
pkt[i] = (unsigned char) data;
pkt[i + 1] = (unsigned char) (data >> 8);
}
} else {
len = inw(hw->base_port);
if (len > hw->ll_mtu) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": received a packet of %u bytes - longer than the MTU!\n", len);
writew(MEMRX_PCINTACKK,
&hw->memory_info_regs->memreg_pc_interrupt_ack);
return;
}
for (i = 0; i < len; i += 2) {
__le16 raw_data = inw(hw->base_port);
unsigned short data = le16_to_cpu(raw_data);
pkt[i] = (unsigned char) data;
pkt[i + 1] = (unsigned char) (data >> 8);
}
while ((i & 3) != 2) {
inw(hw->base_port);
i += 2;
}
}
acknowledge_data_read(hw);
swap_packet_bitfield_from_le(pkt);
if (ipwireless_debug)
dump_data_bytes("recv", pkt, len);
handle_received_packet(hw, (union nl_packet *) pkt, len);
end_read_timing(len);
}
static int get_current_packet_priority(struct ipw_hardware *hw)
{
/*
* If we're initializing, don't send anything of higher priority than
* PRIO_SETUP. The network layer therefore need not care about
* hardware initialization - any of its stuff will simply be queued
* until setup is complete.
*/
return (hw->to_setup || hw->initializing
? PRIO_SETUP + 1 : NL_NUM_OF_PRIORITIES);
}
/*
* return 1 if something has been received from hw
*/
static int get_packets_from_hw(struct ipw_hardware *hw)
{
int received = 0;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
while (hw->rx_ready && !hw->blocking_rx) {
received = 1;
hw->rx_ready--;
spin_unlock_irqrestore(&hw->lock, flags);
do_receive_packet(hw);
spin_lock_irqsave(&hw->lock, flags);
}
spin_unlock_irqrestore(&hw->lock, flags);
return received;
}
/*
* Send pending packet up to given priority, prioritize SETUP data until
* hardware is fully setup.
*
* return 1 if more packets can be sent
*/
static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
{
int more_to_send = 0;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (hw->tx_queued && hw->tx_ready) {
int priority;
struct ipw_tx_packet *packet = NULL;
/* Pick a packet */
for (priority = 0; priority < priority_limit; priority++) {
if (!list_empty(&hw->tx_queue[priority])) {
packet = list_first_entry(
&hw->tx_queue[priority],
struct ipw_tx_packet,
queue);
hw->tx_queued--;
list_del(&packet->queue);
break;
}
}
if (!packet) {
hw->tx_queued = 0;
spin_unlock_irqrestore(&hw->lock, flags);
return 0;
}
spin_unlock_irqrestore(&hw->lock, flags);
/* Send */
do_send_packet(hw, packet);
/* Check if more to send */
spin_lock_irqsave(&hw->lock, flags);
for (priority = 0; priority < priority_limit; priority++)
if (!list_empty(&hw->tx_queue[priority])) {
more_to_send = 1;
break;
}
if (!more_to_send)
hw->tx_queued = 0;
}
spin_unlock_irqrestore(&hw->lock, flags);
return more_to_send;
}
/*
* Send and receive all queued packets.
*/
static void ipwireless_do_tasklet(unsigned long hw_)
{
struct ipw_hardware *hw = (struct ipw_hardware *) hw_;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (hw->shutting_down) {
spin_unlock_irqrestore(&hw->lock, flags);
return;
}
if (hw->to_setup == 1) {
/*
* Initial setup data sent to hardware
*/
hw->to_setup = 2;
spin_unlock_irqrestore(&hw->lock, flags);
ipw_setup_hardware(hw);
ipw_send_setup_packet(hw);
send_pending_packet(hw, PRIO_SETUP + 1);
get_packets_from_hw(hw);
} else {
int priority_limit = get_current_packet_priority(hw);
int again;
spin_unlock_irqrestore(&hw->lock, flags);
do {
again = send_pending_packet(hw, priority_limit);
again |= get_packets_from_hw(hw);
} while (again);
}
}
/*
* return true if the card is physically present.
*/
static int is_card_present(struct ipw_hardware *hw)
{
if (hw->hw_version == HW_VERSION_1)
return inw(hw->base_port + IOIR) != 0xFFFF;
else
return readl(&hw->memory_info_regs->memreg_card_present) ==
CARD_PRESENT_VALUE;
}
static irqreturn_t ipwireless_handle_v1_interrupt(int irq,
struct ipw_hardware *hw)
{
unsigned short irqn;
irqn = inw(hw->base_port + IOIR);
/* Check if card is present */
if (irqn == 0xFFFF)
return IRQ_NONE;
else if (irqn != 0) {
unsigned short ack = 0;
unsigned long flags;
/* Transmit complete. */
if (irqn & IR_TXINTR) {
ack |= IR_TXINTR;
spin_lock_irqsave(&hw->lock, flags);
hw->tx_ready = 1;
spin_unlock_irqrestore(&hw->lock, flags);
}
/* Received data */
if (irqn & IR_RXINTR) {
ack |= IR_RXINTR;
spin_lock_irqsave(&hw->lock, flags);
hw->rx_ready++;
spin_unlock_irqrestore(&hw->lock, flags);
}
if (ack != 0) {
outw(ack, hw->base_port + IOIR);
tasklet_schedule(&hw->tasklet);
}
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static void acknowledge_pcmcia_interrupt(struct ipw_hardware *hw)
{
unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
csr &= 0xfffd;
writew(csr, &hw->memregs_CCR->reg_config_and_status);
}
static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
struct ipw_hardware *hw)
{
int tx = 0;
int rx = 0;
int rx_repeat = 0;
int try_mem_tx_old;
unsigned long flags;
do {
unsigned short memtx = readw(hw->memreg_tx);
unsigned short memtx_serial;
unsigned short memrxdone =
readw(&hw->memory_info_regs->memreg_rx_done);
try_mem_tx_old = 0;
/* check whether the interrupt was generated by ipwireless card */
if (!(memtx & MEMTX_TX) && !(memrxdone & MEMRX_RX_DONE)) {
/* check if the card uses memreg_tx_old register */
if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
memtx = readw(&hw->memory_info_regs->memreg_tx_old);
if (memtx & MEMTX_TX) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": Using memreg_tx_old\n");
hw->memreg_tx =
&hw->memory_info_regs->memreg_tx_old;
} else {
return IRQ_NONE;
}
} else
return IRQ_NONE;
}
/*
* See if the card is physically present. Note that while it is
* powering up, it appears not to be present.
*/
if (!is_card_present(hw)) {
acknowledge_pcmcia_interrupt(hw);
return IRQ_HANDLED;
}
memtx_serial = memtx & (unsigned short) 0xff00;
if (memtx & MEMTX_TX) {
writew(memtx_serial, hw->memreg_tx);
if (hw->serial_number_detected) {
if (memtx_serial != hw->last_memtx_serial) {
hw->last_memtx_serial = memtx_serial;
spin_lock_irqsave(&hw->lock, flags);
hw->rx_ready++;
spin_unlock_irqrestore(&hw->lock, flags);
rx = 1;
} else
/* Ignore 'Timer Recovery' duplicates. */
rx_repeat = 1;
} else {
/*
* If a non-zero serial number is seen, then enable
* serial number checking.
*/
if (memtx_serial != 0) {
hw->serial_number_detected = 1;
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": memreg_tx serial num detected\n");
spin_lock_irqsave(&hw->lock, flags);
hw->rx_ready++;
spin_unlock_irqrestore(&hw->lock, flags);
}
rx = 1;
}
}
if (memrxdone & MEMRX_RX_DONE) {
writew(0, &hw->memory_info_regs->memreg_rx_done);
spin_lock_irqsave(&hw->lock, flags);
hw->tx_ready = 1;
spin_unlock_irqrestore(&hw->lock, flags);
tx = 1;
}
if (tx)
writew(MEMRX_PCINTACKK,
&hw->memory_info_regs->memreg_pc_interrupt_ack);
acknowledge_pcmcia_interrupt(hw);
if (tx || rx)
tasklet_schedule(&hw->tasklet);
else if (!rx_repeat) {
if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
if (hw->serial_number_detected)
printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
": spurious interrupt - new_tx mode\n");
else {
printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
": no valid memreg_tx value - switching to the old memreg_tx\n");
hw->memreg_tx =
&hw->memory_info_regs->memreg_tx_old;
try_mem_tx_old = 1;
}
} else
printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
": spurious interrupt - old_tx mode\n");
}
} while (try_mem_tx_old == 1);
return IRQ_HANDLED;
}
irqreturn_t ipwireless_interrupt(int irq, void *dev_id)
{
struct ipw_dev *ipw = dev_id;
if (ipw->hardware->hw_version == HW_VERSION_1)
return ipwireless_handle_v1_interrupt(irq, ipw->hardware);
else
return ipwireless_handle_v2_v3_interrupt(irq, ipw->hardware);
}
static void flush_packets_to_hw(struct ipw_hardware *hw)
{
int priority_limit;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
priority_limit = get_current_packet_priority(hw);
spin_unlock_irqrestore(&hw->lock, flags);
while (send_pending_packet(hw, priority_limit));
}
static void send_packet(struct ipw_hardware *hw, int priority,
struct ipw_tx_packet *packet)
{
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
list_add_tail(&packet->queue, &hw->tx_queue[priority]);
hw->tx_queued++;
spin_unlock_irqrestore(&hw->lock, flags);
flush_packets_to_hw(hw);
}
/* Create data packet, non-atomic allocation */
static void *alloc_data_packet(int data_size,
unsigned char dest_addr,
unsigned char protocol)
{
struct ipw_tx_packet *packet = kzalloc(
sizeof(struct ipw_tx_packet) + data_size,
GFP_ATOMIC);
if (!packet)
return NULL;
INIT_LIST_HEAD(&packet->queue);
packet->dest_addr = dest_addr;
packet->protocol = protocol;
packet->length = data_size;
return packet;
}
static void *alloc_ctrl_packet(int header_size,
unsigned char dest_addr,
unsigned char protocol,
unsigned char sig_no)
{
/*
* sig_no is located right after ipw_tx_packet struct in every
* CTRL or SETUP packets, we can use ipw_control_packet as a
* common struct
*/
struct ipw_control_packet *packet = kzalloc(header_size, GFP_ATOMIC);
if (!packet)
return NULL;
INIT_LIST_HEAD(&packet->header.queue);
packet->header.dest_addr = dest_addr;
packet->header.protocol = protocol;
packet->header.length = header_size - sizeof(struct ipw_tx_packet);
packet->body.sig_no = sig_no;
return packet;
}
int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
const unsigned char *data, unsigned int length,
void (*callback) (void *cb, unsigned int length),
void *callback_data)
{
struct ipw_tx_packet *packet;
packet = alloc_data_packet(length, (channel_idx + 1),
TL_PROTOCOLID_COM_DATA);
if (!packet)
return -ENOMEM;
packet->packet_callback = callback;
packet->callback_data = callback_data;
memcpy((unsigned char *) packet + sizeof(struct ipw_tx_packet), data,
length);
send_packet(hw, PRIO_DATA, packet);
return 0;
}
static int set_control_line(struct ipw_hardware *hw, int prio,
unsigned int channel_idx, int line, int state)
{
struct ipw_control_packet *packet;
int protocolid = TL_PROTOCOLID_COM_CTRL;
if (prio == PRIO_SETUP)
protocolid = TL_PROTOCOLID_SETUP;
packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet),
(channel_idx + 1), protocolid, line);
if (!packet)
return -ENOMEM;
packet->header.length = sizeof(struct ipw_control_packet_body);
packet->body.value = (state == 0 ? 0 : 1);
send_packet(hw, prio, &packet->header);
return 0;
}
static int set_DTR(struct ipw_hardware *hw, int priority,
unsigned int channel_idx, int state)
{
if (state != 0)
hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_DTR;
else
hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_DTR;
return set_control_line(hw, priority, channel_idx, COMCTRL_DTR, state);
}
static int set_RTS(struct ipw_hardware *hw, int priority,
unsigned int channel_idx, int state)
{
if (state != 0)
hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_RTS;
else
hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_RTS;
return set_control_line(hw, priority, channel_idx, COMCTRL_RTS, state);
}
int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
int state)
{
return set_DTR(hw, PRIO_CTRL, channel_idx, state);
}
int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
int state)
{
return set_RTS(hw, PRIO_CTRL, channel_idx, state);
}
struct ipw_setup_get_version_query_packet {
struct ipw_tx_packet header;
struct tl_setup_get_version_qry body;
};
struct ipw_setup_config_packet {
struct ipw_tx_packet header;
struct tl_setup_config_msg body;
};
struct ipw_setup_config_done_packet {
struct ipw_tx_packet header;
struct tl_setup_config_done_msg body;
};
struct ipw_setup_open_packet {
struct ipw_tx_packet header;
struct tl_setup_open_msg body;
};
struct ipw_setup_info_packet {
struct ipw_tx_packet header;
struct tl_setup_info_msg body;
};
struct ipw_setup_reboot_msg_ack {
struct ipw_tx_packet header;
struct TlSetupRebootMsgAck body;
};
/* This handles the actual initialization of the card */
static void __handle_setup_get_version_rsp(struct ipw_hardware *hw)
{
struct ipw_setup_config_packet *config_packet;
struct ipw_setup_config_done_packet *config_done_packet;
struct ipw_setup_open_packet *open_packet;
struct ipw_setup_info_packet *info_packet;
int port;
unsigned int channel_idx;
/* generate config packet */
for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
config_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_config_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_CONFIG_MSG);
if (!config_packet)
goto exit_nomem;
config_packet->header.length = sizeof(struct tl_setup_config_msg);
config_packet->body.port_no = port;
config_packet->body.prio_data = PRIO_DATA;
config_packet->body.prio_ctrl = PRIO_CTRL;
send_packet(hw, PRIO_SETUP, &config_packet->header);
}
config_done_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_config_done_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_CONFIG_DONE_MSG);
if (!config_done_packet)
goto exit_nomem;
config_done_packet->header.length = sizeof(struct tl_setup_config_done_msg);
send_packet(hw, PRIO_SETUP, &config_done_packet->header);
/* generate open packet */
for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
open_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_open_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_OPEN_MSG);
if (!open_packet)
goto exit_nomem;
open_packet->header.length = sizeof(struct tl_setup_open_msg);
open_packet->body.port_no = port;
send_packet(hw, PRIO_SETUP, &open_packet->header);
}
for (channel_idx = 0;
channel_idx < NL_NUM_OF_ADDRESSES; channel_idx++) {
int ret;
ret = set_DTR(hw, PRIO_SETUP, channel_idx,
(hw->control_lines[channel_idx] &
IPW_CONTROL_LINE_DTR) != 0);
if (ret) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": error setting DTR (%d)\n", ret);
return;
}
set_RTS(hw, PRIO_SETUP, channel_idx,
(hw->control_lines [channel_idx] &
IPW_CONTROL_LINE_RTS) != 0);
if (ret) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": error setting RTS (%d)\n", ret);
return;
}
}
/*
* For NDIS we assume that we are using sync PPP frames, for COM async.
* This driver uses NDIS mode too. We don't bother with translation
* from async -> sync PPP.
*/
info_packet = alloc_ctrl_packet(sizeof(struct ipw_setup_info_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_INFO_MSG);
if (!info_packet)
goto exit_nomem;
info_packet->header.length = sizeof(struct tl_setup_info_msg);
info_packet->body.driver_type = NDISWAN_DRIVER;
info_packet->body.major_version = NDISWAN_DRIVER_MAJOR_VERSION;
info_packet->body.minor_version = NDISWAN_DRIVER_MINOR_VERSION;
send_packet(hw, PRIO_SETUP, &info_packet->header);
/* Initialization is now complete, so we clear the 'to_setup' flag */
hw->to_setup = 0;
return;
exit_nomem:
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": not enough memory to alloc control packet\n");
hw->to_setup = -1;
}
static void handle_setup_get_version_rsp(struct ipw_hardware *hw,
unsigned char vers_no)
{
del_timer(&hw->setup_timer);
hw->initializing = 0;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": card is ready.\n");
if (vers_no == TL_SETUP_VERSION)
__handle_setup_get_version_rsp(hw);
else
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": invalid hardware version no %u\n",
(unsigned int) vers_no);
}
static void ipw_send_setup_packet(struct ipw_hardware *hw)
{
struct ipw_setup_get_version_query_packet *ver_packet;
ver_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_get_version_query_packet),
ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_GET_VERSION_QRY);
ver_packet->header.length = sizeof(struct tl_setup_get_version_qry);
/*
* Response is handled in handle_received_SETUP_packet
*/
send_packet(hw, PRIO_SETUP, &ver_packet->header);
}
static void handle_received_SETUP_packet(struct ipw_hardware *hw,
unsigned int address,
const unsigned char *data, int len,
int is_last)
{
const union ipw_setup_rx_msg *rx_msg = (const union ipw_setup_rx_msg *) data;
if (address != ADDR_SETUP_PROT) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": setup packet has bad address %d\n", address);
return;
}
switch (rx_msg->sig_no) {
case TL_SETUP_SIGNO_GET_VERSION_RSP:
if (hw->to_setup)
handle_setup_get_version_rsp(hw,
rx_msg->version_rsp_msg.version);
break;
case TL_SETUP_SIGNO_OPEN_MSG:
if (ipwireless_debug) {
unsigned int channel_idx = rx_msg->open_msg.port_no - 1;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": OPEN_MSG [channel %u] reply received\n",
channel_idx);
}
break;
case TL_SETUP_SIGNO_INFO_MSG_ACK:
if (ipwireless_debug)
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": card successfully configured as NDISWAN\n");
break;
case TL_SETUP_SIGNO_REBOOT_MSG:
if (hw->to_setup)
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": Setup not completed - ignoring reboot msg\n");
else {
struct ipw_setup_reboot_msg_ack *packet;
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": Acknowledging REBOOT message\n");
packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_reboot_msg_ack),
ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_REBOOT_MSG_ACK);
packet->header.length =
sizeof(struct TlSetupRebootMsgAck);
send_packet(hw, PRIO_SETUP, &packet->header);
if (hw->reboot_callback)
hw->reboot_callback(hw->reboot_callback_data);
}
break;
default:
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": unknown setup message %u received\n",
(unsigned int) rx_msg->sig_no);
}
}
static void do_close_hardware(struct ipw_hardware *hw)
{
unsigned int irqn;
if (hw->hw_version == HW_VERSION_1) {
/* Disable TX and RX interrupts. */
outw(0, hw->base_port + IOIER);
/* Acknowledge any outstanding interrupt requests */
irqn = inw(hw->base_port + IOIR);
if (irqn & IR_TXINTR)
outw(IR_TXINTR, hw->base_port + IOIR);
if (irqn & IR_RXINTR)
outw(IR_RXINTR, hw->base_port + IOIR);
synchronize_irq(hw->irq);
}
}
struct ipw_hardware *ipwireless_hardware_create(void)
{
int i;
struct ipw_hardware *hw =
kzalloc(sizeof(struct ipw_hardware), GFP_KERNEL);
if (!hw)
return NULL;
hw->irq = -1;
hw->initializing = 1;
hw->tx_ready = 1;
hw->rx_bytes_queued = 0;
hw->rx_pool_size = 0;
hw->last_memtx_serial = (unsigned short) 0xffff;
for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
INIT_LIST_HEAD(&hw->tx_queue[i]);
INIT_LIST_HEAD(&hw->rx_queue);
INIT_LIST_HEAD(&hw->rx_pool);
spin_lock_init(&hw->lock);
tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw);
INIT_WORK(&hw->work_rx, ipw_receive_data_work);
setup_timer(&hw->setup_timer, ipwireless_setup_timer,
(unsigned long) hw);
return hw;
}
void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
unsigned int base_port,
void __iomem *attr_memory,
void __iomem *common_memory,
int is_v2_card,
void (*reboot_callback) (void *data),
void *reboot_callback_data)
{
if (hw->removed) {
hw->removed = 0;
enable_irq(hw->irq);
}
hw->base_port = base_port;
hw->hw_version = (is_v2_card ? HW_VERSION_2 : HW_VERSION_1);
hw->ll_mtu = (hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2);
hw->memregs_CCR = (struct MEMCCR __iomem *)
((unsigned short __iomem *) attr_memory + 0x200);
hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory;
hw->memreg_tx = &hw->memory_info_regs->memreg_tx_new;
hw->reboot_callback = reboot_callback;
hw->reboot_callback_data = reboot_callback_data;
}
void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw)
{
hw->initializing = 1;
hw->init_loops = 0;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": waiting for card to start up...\n");
ipwireless_setup_timer((unsigned long) hw);
}
static void ipwireless_setup_timer(unsigned long data)
{
struct ipw_hardware *hw = (struct ipw_hardware *) data;
hw->init_loops++;
if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY &&
hw->hw_version == HW_VERSION_2 &&
hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": failed to startup using TX2, trying TX\n");
hw->memreg_tx = &hw->memory_info_regs->memreg_tx_old;
hw->init_loops = 0;
}
/* Give up after a certain number of retries */
if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": card failed to start up!\n");
hw->initializing = 0;
} else {
/* Do not attempt to write to the board if it is not present. */
if (is_card_present(hw)) {
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
hw->to_setup = 1;
hw->tx_ready = 1;
spin_unlock_irqrestore(&hw->lock, flags);
tasklet_schedule(&hw->tasklet);
}
mod_timer(&hw->setup_timer,
jiffies + msecs_to_jiffies(TL_SETUP_VERSION_QRY_TMO));
}
}
/*
* Stop any interrupts from executing so that, once this function returns,
* other layers of the driver can be sure they won't get any more callbacks.
* Thus must be called on a proper process context.
*/
void ipwireless_stop_interrupts(struct ipw_hardware *hw)
{
if (!hw->shutting_down) {
/* Tell everyone we are going down. */
hw->shutting_down = 1;
del_timer(&hw->setup_timer);
/* Prevent the hardware from sending any more interrupts */
do_close_hardware(hw);
}
}
void ipwireless_hardware_free(struct ipw_hardware *hw)
{
int i;
struct ipw_rx_packet *rp, *rq;
struct ipw_tx_packet *tp, *tq;
ipwireless_stop_interrupts(hw);
flush_work_sync(&hw->work_rx);
for (i = 0; i < NL_NUM_OF_ADDRESSES; i++)
if (hw->packet_assembler[i] != NULL)
kfree(hw->packet_assembler[i]);
for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
list_for_each_entry_safe(tp, tq, &hw->tx_queue[i], queue) {
list_del(&tp->queue);
kfree(tp);
}
list_for_each_entry_safe(rp, rq, &hw->rx_queue, queue) {
list_del(&rp->queue);
kfree(rp);
}
list_for_each_entry_safe(rp, rq, &hw->rx_pool, queue) {
list_del(&rp->queue);
kfree(rp);
}
kfree(hw);
}
/*
* Associate the specified network with this hardware, so it will receive events
* from it.
*/
void ipwireless_associate_network(struct ipw_hardware *hw,
struct ipw_network *network)
{
hw->network = network;
}
| gpl-2.0 |
JoinTheRealms/CopyCat-Kernel-P880 | drivers/tty/ipwireless/hardware.c | 8195 | 46474 | /*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h>
#include "hardware.h"
#include "setup_protocol.h"
#include "network.h"
#include "main.h"
static void ipw_send_setup_packet(struct ipw_hardware *hw);
static void handle_received_SETUP_packet(struct ipw_hardware *ipw,
unsigned int address,
const unsigned char *data, int len,
int is_last);
static void ipwireless_setup_timer(unsigned long data);
static void handle_received_CTRL_packet(struct ipw_hardware *hw,
unsigned int channel_idx, const unsigned char *data, int len);
/*#define TIMING_DIAGNOSTICS*/
#ifdef TIMING_DIAGNOSTICS
static struct timing_stats {
unsigned long last_report_time;
unsigned long read_time;
unsigned long write_time;
unsigned long read_bytes;
unsigned long write_bytes;
unsigned long start_time;
};
static void start_timing(void)
{
timing_stats.start_time = jiffies;
}
static void end_read_timing(unsigned length)
{
timing_stats.read_time += (jiffies - start_time);
timing_stats.read_bytes += length + 2;
report_timing();
}
static void end_write_timing(unsigned length)
{
timing_stats.write_time += (jiffies - start_time);
timing_stats.write_bytes += length + 2;
report_timing();
}
static void report_timing(void)
{
unsigned long since = jiffies - timing_stats.last_report_time;
/* If it's been more than one second... */
if (since >= HZ) {
int first = (timing_stats.last_report_time == 0);
timing_stats.last_report_time = jiffies;
if (!first)
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": %u us elapsed - read %lu bytes in %u us, wrote %lu bytes in %u us\n",
jiffies_to_usecs(since),
timing_stats.read_bytes,
jiffies_to_usecs(timing_stats.read_time),
timing_stats.write_bytes,
jiffies_to_usecs(timing_stats.write_time));
timing_stats.read_time = 0;
timing_stats.write_time = 0;
timing_stats.read_bytes = 0;
timing_stats.write_bytes = 0;
}
}
#else
static void start_timing(void) { }
static void end_read_timing(unsigned length) { }
static void end_write_timing(unsigned length) { }
#endif
/* Imported IPW definitions */
#define LL_MTU_V1 318
#define LL_MTU_V2 250
#define LL_MTU_MAX (LL_MTU_V1 > LL_MTU_V2 ? LL_MTU_V1 : LL_MTU_V2)
#define PRIO_DATA 2
#define PRIO_CTRL 1
#define PRIO_SETUP 0
/* Addresses */
#define ADDR_SETUP_PROT 0
/* Protocol ids */
enum {
/* Identifier for the Com Data protocol */
TL_PROTOCOLID_COM_DATA = 0,
/* Identifier for the Com Control protocol */
TL_PROTOCOLID_COM_CTRL = 1,
/* Identifier for the Setup protocol */
TL_PROTOCOLID_SETUP = 2
};
/* Number of bytes in NL packet header (cannot do
* sizeof(nl_packet_header) since it's a bitfield) */
#define NL_FIRST_PACKET_HEADER_SIZE 3
/* Number of bytes in NL packet header (cannot do
* sizeof(nl_packet_header) since it's a bitfield) */
#define NL_FOLLOWING_PACKET_HEADER_SIZE 1
struct nl_first_packet_header {
unsigned char protocol:3;
unsigned char address:3;
unsigned char packet_rank:2;
unsigned char length_lsb;
unsigned char length_msb;
};
struct nl_packet_header {
unsigned char protocol:3;
unsigned char address:3;
unsigned char packet_rank:2;
};
/* Value of 'packet_rank' above */
#define NL_INTERMEDIATE_PACKET 0x0
#define NL_LAST_PACKET 0x1
#define NL_FIRST_PACKET 0x2
union nl_packet {
/* Network packet header of the first packet (a special case) */
struct nl_first_packet_header hdr_first;
/* Network packet header of the following packets (if any) */
struct nl_packet_header hdr;
/* Complete network packet (header + data) */
unsigned char rawpkt[LL_MTU_MAX];
} __attribute__ ((__packed__));
#define HW_VERSION_UNKNOWN -1
#define HW_VERSION_1 1
#define HW_VERSION_2 2
/* IPW I/O ports */
#define IOIER 0x00 /* Interrupt Enable Register */
#define IOIR 0x02 /* Interrupt Source/ACK register */
#define IODCR 0x04 /* Data Control Register */
#define IODRR 0x06 /* Data Read Register */
#define IODWR 0x08 /* Data Write Register */
#define IOESR 0x0A /* Embedded Driver Status Register */
#define IORXR 0x0C /* Rx Fifo Register (Host to Embedded) */
#define IOTXR 0x0E /* Tx Fifo Register (Embedded to Host) */
/* I/O ports and bit definitions for version 1 of the hardware */
/* IER bits*/
#define IER_RXENABLED 0x1
#define IER_TXENABLED 0x2
/* ISR bits */
#define IR_RXINTR 0x1
#define IR_TXINTR 0x2
/* DCR bits */
#define DCR_RXDONE 0x1
#define DCR_TXDONE 0x2
#define DCR_RXRESET 0x4
#define DCR_TXRESET 0x8
/* I/O ports and bit definitions for version 2 of the hardware */
struct MEMCCR {
unsigned short reg_config_option; /* PCCOR: Configuration Option Register */
unsigned short reg_config_and_status; /* PCCSR: Configuration and Status Register */
unsigned short reg_pin_replacement; /* PCPRR: Pin Replacemant Register */
unsigned short reg_socket_and_copy; /* PCSCR: Socket and Copy Register */
unsigned short reg_ext_status; /* PCESR: Extendend Status Register */
unsigned short reg_io_base; /* PCIOB: I/O Base Register */
};
struct MEMINFREG {
unsigned short memreg_tx_old; /* TX Register (R/W) */
unsigned short pad1;
unsigned short memreg_rx_done; /* RXDone Register (R/W) */
unsigned short pad2;
unsigned short memreg_rx; /* RX Register (R/W) */
unsigned short pad3;
unsigned short memreg_pc_interrupt_ack; /* PC intr Ack Register (W) */
unsigned short pad4;
unsigned long memreg_card_present;/* Mask for Host to check (R) for
* CARD_PRESENT_VALUE */
unsigned short memreg_tx_new; /* TX2 (new) Register (R/W) */
};
#define CARD_PRESENT_VALUE (0xBEEFCAFEUL)
#define MEMTX_TX 0x0001
#define MEMRX_RX 0x0001
#define MEMRX_RX_DONE 0x0001
#define MEMRX_PCINTACKK 0x0001
#define NL_NUM_OF_PRIORITIES 3
#define NL_NUM_OF_PROTOCOLS 3
#define NL_NUM_OF_ADDRESSES NO_OF_IPW_CHANNELS
struct ipw_hardware {
unsigned int base_port;
short hw_version;
unsigned short ll_mtu;
spinlock_t lock;
int initializing;
int init_loops;
struct timer_list setup_timer;
/* Flag if hw is ready to send next packet */
int tx_ready;
/* Count of pending packets to be sent */
int tx_queued;
struct list_head tx_queue[NL_NUM_OF_PRIORITIES];
int rx_bytes_queued;
struct list_head rx_queue;
/* Pool of rx_packet structures that are not currently used. */
struct list_head rx_pool;
int rx_pool_size;
/* True if reception of data is blocked while userspace processes it. */
int blocking_rx;
/* True if there is RX data ready on the hardware. */
int rx_ready;
unsigned short last_memtx_serial;
/*
* Newer versions of the V2 card firmware send serial numbers in the
* MemTX register. 'serial_number_detected' is set true when we detect
* a non-zero serial number (indicating the new firmware). Thereafter,
* the driver can safely ignore the Timer Recovery re-sends to avoid
* out-of-sync problems.
*/
int serial_number_detected;
struct work_struct work_rx;
/* True if we are to send the set-up data to the hardware. */
int to_setup;
/* Card has been removed */
int removed;
/* Saved irq value when we disable the interrupt. */
int irq;
/* True if this driver is shutting down. */
int shutting_down;
/* Modem control lines */
unsigned int control_lines[NL_NUM_OF_ADDRESSES];
struct ipw_rx_packet *packet_assembler[NL_NUM_OF_ADDRESSES];
struct tasklet_struct tasklet;
/* The handle for the network layer, for the sending of events to it. */
struct ipw_network *network;
struct MEMINFREG __iomem *memory_info_regs;
struct MEMCCR __iomem *memregs_CCR;
void (*reboot_callback) (void *data);
void *reboot_callback_data;
unsigned short __iomem *memreg_tx;
};
/*
* Packet info structure for tx packets.
* Note: not all the fields defined here are required for all protocols
*/
struct ipw_tx_packet {
struct list_head queue;
/* channel idx + 1 */
unsigned char dest_addr;
/* SETUP, CTRL or DATA */
unsigned char protocol;
/* Length of data block, which starts at the end of this structure */
unsigned short length;
/* Sending state */
/* Offset of where we've sent up to so far */
unsigned long offset;
/* Count of packet fragments, starting at 0 */
int fragment_count;
/* Called after packet is sent and before is freed */
void (*packet_callback) (void *cb_data, unsigned int packet_length);
void *callback_data;
};
/* Signals from DTE */
#define COMCTRL_RTS 0
#define COMCTRL_DTR 1
/* Signals from DCE */
#define COMCTRL_CTS 2
#define COMCTRL_DCD 3
#define COMCTRL_DSR 4
#define COMCTRL_RI 5
struct ipw_control_packet_body {
/* DTE signal or DCE signal */
unsigned char sig_no;
/* 0: set signal, 1: clear signal */
unsigned char value;
} __attribute__ ((__packed__));
struct ipw_control_packet {
struct ipw_tx_packet header;
struct ipw_control_packet_body body;
};
struct ipw_rx_packet {
struct list_head queue;
unsigned int capacity;
unsigned int length;
unsigned int protocol;
unsigned int channel_idx;
};
static char *data_type(const unsigned char *buf, unsigned length)
{
struct nl_packet_header *hdr = (struct nl_packet_header *) buf;
if (length == 0)
return " ";
if (hdr->packet_rank & NL_FIRST_PACKET) {
switch (hdr->protocol) {
case TL_PROTOCOLID_COM_DATA: return "DATA ";
case TL_PROTOCOLID_COM_CTRL: return "CTRL ";
case TL_PROTOCOLID_SETUP: return "SETUP";
default: return "???? ";
}
} else
return " ";
}
#define DUMP_MAX_BYTES 64
static void dump_data_bytes(const char *type, const unsigned char *data,
unsigned length)
{
char prefix[56];
sprintf(prefix, IPWIRELESS_PCCARD_NAME ": %s %s ",
type, data_type(data, length));
print_hex_dump_bytes(prefix, 0, (void *)data,
length < DUMP_MAX_BYTES ? length : DUMP_MAX_BYTES);
}
static void swap_packet_bitfield_to_le(unsigned char *data)
{
#ifdef __BIG_ENDIAN_BITFIELD
unsigned char tmp = *data, ret = 0;
/*
* transform bits from aa.bbb.ccc to ccc.bbb.aa
*/
ret |= tmp & 0xc0 >> 6;
ret |= tmp & 0x38 >> 1;
ret |= tmp & 0x07 << 5;
*data = ret & 0xff;
#endif
}
static void swap_packet_bitfield_from_le(unsigned char *data)
{
#ifdef __BIG_ENDIAN_BITFIELD
unsigned char tmp = *data, ret = 0;
/*
* transform bits from ccc.bbb.aa to aa.bbb.ccc
*/
ret |= tmp & 0xe0 >> 5;
ret |= tmp & 0x1c << 1;
ret |= tmp & 0x03 << 6;
*data = ret & 0xff;
#endif
}
static void do_send_fragment(struct ipw_hardware *hw, unsigned char *data,
unsigned length)
{
unsigned i;
unsigned long flags;
start_timing();
BUG_ON(length > hw->ll_mtu);
if (ipwireless_debug)
dump_data_bytes("send", data, length);
spin_lock_irqsave(&hw->lock, flags);
hw->tx_ready = 0;
swap_packet_bitfield_to_le(data);
if (hw->hw_version == HW_VERSION_1) {
outw((unsigned short) length, hw->base_port + IODWR);
for (i = 0; i < length; i += 2) {
unsigned short d = data[i];
__le16 raw_data;
if (i + 1 < length)
d |= data[i + 1] << 8;
raw_data = cpu_to_le16(d);
outw(raw_data, hw->base_port + IODWR);
}
outw(DCR_TXDONE, hw->base_port + IODCR);
} else if (hw->hw_version == HW_VERSION_2) {
outw((unsigned short) length, hw->base_port);
for (i = 0; i < length; i += 2) {
unsigned short d = data[i];
__le16 raw_data;
if (i + 1 < length)
d |= data[i + 1] << 8;
raw_data = cpu_to_le16(d);
outw(raw_data, hw->base_port);
}
while ((i & 3) != 2) {
outw((unsigned short) 0xDEAD, hw->base_port);
i += 2;
}
writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx);
}
spin_unlock_irqrestore(&hw->lock, flags);
end_write_timing(length);
}
static void do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
{
unsigned short fragment_data_len;
unsigned short data_left = packet->length - packet->offset;
unsigned short header_size;
union nl_packet pkt;
header_size =
(packet->fragment_count == 0)
? NL_FIRST_PACKET_HEADER_SIZE
: NL_FOLLOWING_PACKET_HEADER_SIZE;
fragment_data_len = hw->ll_mtu - header_size;
if (data_left < fragment_data_len)
fragment_data_len = data_left;
/*
* hdr_first is now in machine bitfield order, which will be swapped
* to le just before it goes to hw
*/
pkt.hdr_first.protocol = packet->protocol;
pkt.hdr_first.address = packet->dest_addr;
pkt.hdr_first.packet_rank = 0;
/* First packet? */
if (packet->fragment_count == 0) {
pkt.hdr_first.packet_rank |= NL_FIRST_PACKET;
pkt.hdr_first.length_lsb = (unsigned char) packet->length;
pkt.hdr_first.length_msb =
(unsigned char) (packet->length >> 8);
}
memcpy(pkt.rawpkt + header_size,
((unsigned char *) packet) + sizeof(struct ipw_tx_packet) +
packet->offset, fragment_data_len);
packet->offset += fragment_data_len;
packet->fragment_count++;
/* Last packet? (May also be first packet.) */
if (packet->offset == packet->length)
pkt.hdr_first.packet_rank |= NL_LAST_PACKET;
do_send_fragment(hw, pkt.rawpkt, header_size + fragment_data_len);
/* If this packet has unsent data, then re-queue it. */
if (packet->offset < packet->length) {
/*
* Re-queue it at the head of the highest priority queue so
* it goes before all other packets
*/
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
list_add(&packet->queue, &hw->tx_queue[0]);
hw->tx_queued++;
spin_unlock_irqrestore(&hw->lock, flags);
} else {
if (packet->packet_callback)
packet->packet_callback(packet->callback_data,
packet->length);
kfree(packet);
}
}
static void ipw_setup_hardware(struct ipw_hardware *hw)
{
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (hw->hw_version == HW_VERSION_1) {
/* Reset RX FIFO */
outw(DCR_RXRESET, hw->base_port + IODCR);
/* SB: Reset TX FIFO */
outw(DCR_TXRESET, hw->base_port + IODCR);
/* Enable TX and RX interrupts. */
outw(IER_TXENABLED | IER_RXENABLED, hw->base_port + IOIER);
} else {
/*
* Set INTRACK bit (bit 0), which means we must explicitly
* acknowledge interrupts by clearing bit 2 of reg_config_and_status.
*/
unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
csr |= 1;
writew(csr, &hw->memregs_CCR->reg_config_and_status);
}
spin_unlock_irqrestore(&hw->lock, flags);
}
/*
* If 'packet' is NULL, then this function allocates a new packet, setting its
* length to 0 and ensuring it has the specified minimum amount of free space.
*
* If 'packet' is not NULL, then this function enlarges it if it doesn't
* have the specified minimum amount of free space.
*
*/
static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
struct ipw_rx_packet *packet,
int minimum_free_space)
{
if (!packet) {
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (!list_empty(&hw->rx_pool)) {
packet = list_first_entry(&hw->rx_pool,
struct ipw_rx_packet, queue);
hw->rx_pool_size--;
spin_unlock_irqrestore(&hw->lock, flags);
list_del(&packet->queue);
} else {
const int min_capacity =
ipwireless_ppp_mru(hw->network) + 2;
int new_capacity;
spin_unlock_irqrestore(&hw->lock, flags);
new_capacity =
(minimum_free_space > min_capacity
? minimum_free_space
: min_capacity);
packet = kmalloc(sizeof(struct ipw_rx_packet)
+ new_capacity, GFP_ATOMIC);
if (!packet)
return NULL;
packet->capacity = new_capacity;
}
packet->length = 0;
}
if (packet->length + minimum_free_space > packet->capacity) {
struct ipw_rx_packet *old_packet = packet;
packet = kmalloc(sizeof(struct ipw_rx_packet) +
old_packet->length + minimum_free_space,
GFP_ATOMIC);
if (!packet) {
kfree(old_packet);
return NULL;
}
memcpy(packet, old_packet,
sizeof(struct ipw_rx_packet)
+ old_packet->length);
packet->capacity = old_packet->length + minimum_free_space;
kfree(old_packet);
}
return packet;
}
static void pool_free(struct ipw_hardware *hw, struct ipw_rx_packet *packet)
{
if (hw->rx_pool_size > 6)
kfree(packet);
else {
hw->rx_pool_size++;
list_add(&packet->queue, &hw->rx_pool);
}
}
static void queue_received_packet(struct ipw_hardware *hw,
unsigned int protocol,
unsigned int address,
const unsigned char *data, int length,
int is_last)
{
unsigned int channel_idx = address - 1;
struct ipw_rx_packet *packet = NULL;
unsigned long flags;
/* Discard packet if channel index is out of range. */
if (channel_idx >= NL_NUM_OF_ADDRESSES) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": data packet has bad address %u\n", address);
return;
}
/*
* ->packet_assembler is safe to touch unlocked, this is the only place
*/
if (protocol == TL_PROTOCOLID_COM_DATA) {
struct ipw_rx_packet **assem =
&hw->packet_assembler[channel_idx];
/*
* Create a new packet, or assembler already contains one
* enlarge it by 'length' bytes.
*/
(*assem) = pool_allocate(hw, *assem, length);
if (!(*assem)) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": no memory for incomming data packet, dropped!\n");
return;
}
(*assem)->protocol = protocol;
(*assem)->channel_idx = channel_idx;
/* Append this packet data onto existing data. */
memcpy((unsigned char *)(*assem) +
sizeof(struct ipw_rx_packet)
+ (*assem)->length, data, length);
(*assem)->length += length;
if (is_last) {
packet = *assem;
*assem = NULL;
/* Count queued DATA bytes only */
spin_lock_irqsave(&hw->lock, flags);
hw->rx_bytes_queued += packet->length;
spin_unlock_irqrestore(&hw->lock, flags);
}
} else {
/* If it's a CTRL packet, don't assemble, just queue it. */
packet = pool_allocate(hw, NULL, length);
if (!packet) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": no memory for incomming ctrl packet, dropped!\n");
return;
}
packet->protocol = protocol;
packet->channel_idx = channel_idx;
memcpy((unsigned char *)packet + sizeof(struct ipw_rx_packet),
data, length);
packet->length = length;
}
/*
* If this is the last packet, then send the assembled packet on to the
* network layer.
*/
if (packet) {
spin_lock_irqsave(&hw->lock, flags);
list_add_tail(&packet->queue, &hw->rx_queue);
/* Block reception of incoming packets if queue is full. */
hw->blocking_rx =
(hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE);
spin_unlock_irqrestore(&hw->lock, flags);
schedule_work(&hw->work_rx);
}
}
/*
* Workqueue callback
*/
static void ipw_receive_data_work(struct work_struct *work_rx)
{
struct ipw_hardware *hw =
container_of(work_rx, struct ipw_hardware, work_rx);
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
while (!list_empty(&hw->rx_queue)) {
struct ipw_rx_packet *packet =
list_first_entry(&hw->rx_queue,
struct ipw_rx_packet, queue);
if (hw->shutting_down)
break;
list_del(&packet->queue);
/*
* Note: ipwireless_network_packet_received must be called in a
* process context (i.e. via schedule_work) because the tty
* output code can sleep in the tty_flip_buffer_push call.
*/
if (packet->protocol == TL_PROTOCOLID_COM_DATA) {
if (hw->network != NULL) {
/* If the network hasn't been disconnected. */
spin_unlock_irqrestore(&hw->lock, flags);
/*
* This must run unlocked due to tty processing
* and mutex locking
*/
ipwireless_network_packet_received(
hw->network,
packet->channel_idx,
(unsigned char *)packet
+ sizeof(struct ipw_rx_packet),
packet->length);
spin_lock_irqsave(&hw->lock, flags);
}
/* Count queued DATA bytes only */
hw->rx_bytes_queued -= packet->length;
} else {
/*
* This is safe to be called locked, callchain does
* not block
*/
handle_received_CTRL_packet(hw, packet->channel_idx,
(unsigned char *)packet
+ sizeof(struct ipw_rx_packet),
packet->length);
}
pool_free(hw, packet);
/*
* Unblock reception of incoming packets if queue is no longer
* full.
*/
hw->blocking_rx =
hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
if (hw->shutting_down)
break;
}
spin_unlock_irqrestore(&hw->lock, flags);
}
static void handle_received_CTRL_packet(struct ipw_hardware *hw,
unsigned int channel_idx,
const unsigned char *data, int len)
{
const struct ipw_control_packet_body *body =
(const struct ipw_control_packet_body *) data;
unsigned int changed_mask;
if (len != sizeof(struct ipw_control_packet_body)) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": control packet was %d bytes - wrong size!\n",
len);
return;
}
switch (body->sig_no) {
case COMCTRL_CTS:
changed_mask = IPW_CONTROL_LINE_CTS;
break;
case COMCTRL_DCD:
changed_mask = IPW_CONTROL_LINE_DCD;
break;
case COMCTRL_DSR:
changed_mask = IPW_CONTROL_LINE_DSR;
break;
case COMCTRL_RI:
changed_mask = IPW_CONTROL_LINE_RI;
break;
default:
changed_mask = 0;
}
if (changed_mask != 0) {
if (body->value)
hw->control_lines[channel_idx] |= changed_mask;
else
hw->control_lines[channel_idx] &= ~changed_mask;
if (hw->network)
ipwireless_network_notify_control_line_change(
hw->network,
channel_idx,
hw->control_lines[channel_idx],
changed_mask);
}
}
static void handle_received_packet(struct ipw_hardware *hw,
const union nl_packet *packet,
unsigned short len)
{
unsigned int protocol = packet->hdr.protocol;
unsigned int address = packet->hdr.address;
unsigned int header_length;
const unsigned char *data;
unsigned int data_len;
int is_last = packet->hdr.packet_rank & NL_LAST_PACKET;
if (packet->hdr.packet_rank & NL_FIRST_PACKET)
header_length = NL_FIRST_PACKET_HEADER_SIZE;
else
header_length = NL_FOLLOWING_PACKET_HEADER_SIZE;
data = packet->rawpkt + header_length;
data_len = len - header_length;
switch (protocol) {
case TL_PROTOCOLID_COM_DATA:
case TL_PROTOCOLID_COM_CTRL:
queue_received_packet(hw, protocol, address, data, data_len,
is_last);
break;
case TL_PROTOCOLID_SETUP:
handle_received_SETUP_packet(hw, address, data, data_len,
is_last);
break;
}
}
static void acknowledge_data_read(struct ipw_hardware *hw)
{
if (hw->hw_version == HW_VERSION_1)
outw(DCR_RXDONE, hw->base_port + IODCR);
else
writew(MEMRX_PCINTACKK,
&hw->memory_info_regs->memreg_pc_interrupt_ack);
}
/*
* Retrieve a packet from the IPW hardware.
*/
static void do_receive_packet(struct ipw_hardware *hw)
{
unsigned len;
unsigned i;
unsigned char pkt[LL_MTU_MAX];
start_timing();
if (hw->hw_version == HW_VERSION_1) {
len = inw(hw->base_port + IODRR);
if (len > hw->ll_mtu) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": received a packet of %u bytes - longer than the MTU!\n", len);
outw(DCR_RXDONE | DCR_RXRESET, hw->base_port + IODCR);
return;
}
for (i = 0; i < len; i += 2) {
__le16 raw_data = inw(hw->base_port + IODRR);
unsigned short data = le16_to_cpu(raw_data);
pkt[i] = (unsigned char) data;
pkt[i + 1] = (unsigned char) (data >> 8);
}
} else {
len = inw(hw->base_port);
if (len > hw->ll_mtu) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": received a packet of %u bytes - longer than the MTU!\n", len);
writew(MEMRX_PCINTACKK,
&hw->memory_info_regs->memreg_pc_interrupt_ack);
return;
}
for (i = 0; i < len; i += 2) {
__le16 raw_data = inw(hw->base_port);
unsigned short data = le16_to_cpu(raw_data);
pkt[i] = (unsigned char) data;
pkt[i + 1] = (unsigned char) (data >> 8);
}
while ((i & 3) != 2) {
inw(hw->base_port);
i += 2;
}
}
acknowledge_data_read(hw);
swap_packet_bitfield_from_le(pkt);
if (ipwireless_debug)
dump_data_bytes("recv", pkt, len);
handle_received_packet(hw, (union nl_packet *) pkt, len);
end_read_timing(len);
}
static int get_current_packet_priority(struct ipw_hardware *hw)
{
/*
* If we're initializing, don't send anything of higher priority than
* PRIO_SETUP. The network layer therefore need not care about
* hardware initialization - any of its stuff will simply be queued
* until setup is complete.
*/
return (hw->to_setup || hw->initializing
? PRIO_SETUP + 1 : NL_NUM_OF_PRIORITIES);
}
/*
* return 1 if something has been received from hw
*/
static int get_packets_from_hw(struct ipw_hardware *hw)
{
int received = 0;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
while (hw->rx_ready && !hw->blocking_rx) {
received = 1;
hw->rx_ready--;
spin_unlock_irqrestore(&hw->lock, flags);
do_receive_packet(hw);
spin_lock_irqsave(&hw->lock, flags);
}
spin_unlock_irqrestore(&hw->lock, flags);
return received;
}
/*
* Send pending packet up to given priority, prioritize SETUP data until
* hardware is fully setup.
*
* return 1 if more packets can be sent
*/
static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
{
int more_to_send = 0;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (hw->tx_queued && hw->tx_ready) {
int priority;
struct ipw_tx_packet *packet = NULL;
/* Pick a packet */
for (priority = 0; priority < priority_limit; priority++) {
if (!list_empty(&hw->tx_queue[priority])) {
packet = list_first_entry(
&hw->tx_queue[priority],
struct ipw_tx_packet,
queue);
hw->tx_queued--;
list_del(&packet->queue);
break;
}
}
if (!packet) {
hw->tx_queued = 0;
spin_unlock_irqrestore(&hw->lock, flags);
return 0;
}
spin_unlock_irqrestore(&hw->lock, flags);
/* Send */
do_send_packet(hw, packet);
/* Check if more to send */
spin_lock_irqsave(&hw->lock, flags);
for (priority = 0; priority < priority_limit; priority++)
if (!list_empty(&hw->tx_queue[priority])) {
more_to_send = 1;
break;
}
if (!more_to_send)
hw->tx_queued = 0;
}
spin_unlock_irqrestore(&hw->lock, flags);
return more_to_send;
}
/*
* Send and receive all queued packets.
*/
static void ipwireless_do_tasklet(unsigned long hw_)
{
struct ipw_hardware *hw = (struct ipw_hardware *) hw_;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (hw->shutting_down) {
spin_unlock_irqrestore(&hw->lock, flags);
return;
}
if (hw->to_setup == 1) {
/*
* Initial setup data sent to hardware
*/
hw->to_setup = 2;
spin_unlock_irqrestore(&hw->lock, flags);
ipw_setup_hardware(hw);
ipw_send_setup_packet(hw);
send_pending_packet(hw, PRIO_SETUP + 1);
get_packets_from_hw(hw);
} else {
int priority_limit = get_current_packet_priority(hw);
int again;
spin_unlock_irqrestore(&hw->lock, flags);
do {
again = send_pending_packet(hw, priority_limit);
again |= get_packets_from_hw(hw);
} while (again);
}
}
/*
* return true if the card is physically present.
*/
static int is_card_present(struct ipw_hardware *hw)
{
if (hw->hw_version == HW_VERSION_1)
return inw(hw->base_port + IOIR) != 0xFFFF;
else
return readl(&hw->memory_info_regs->memreg_card_present) ==
CARD_PRESENT_VALUE;
}
static irqreturn_t ipwireless_handle_v1_interrupt(int irq,
struct ipw_hardware *hw)
{
unsigned short irqn;
irqn = inw(hw->base_port + IOIR);
/* Check if card is present */
if (irqn == 0xFFFF)
return IRQ_NONE;
else if (irqn != 0) {
unsigned short ack = 0;
unsigned long flags;
/* Transmit complete. */
if (irqn & IR_TXINTR) {
ack |= IR_TXINTR;
spin_lock_irqsave(&hw->lock, flags);
hw->tx_ready = 1;
spin_unlock_irqrestore(&hw->lock, flags);
}
/* Received data */
if (irqn & IR_RXINTR) {
ack |= IR_RXINTR;
spin_lock_irqsave(&hw->lock, flags);
hw->rx_ready++;
spin_unlock_irqrestore(&hw->lock, flags);
}
if (ack != 0) {
outw(ack, hw->base_port + IOIR);
tasklet_schedule(&hw->tasklet);
}
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static void acknowledge_pcmcia_interrupt(struct ipw_hardware *hw)
{
unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
csr &= 0xfffd;
writew(csr, &hw->memregs_CCR->reg_config_and_status);
}
static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
struct ipw_hardware *hw)
{
int tx = 0;
int rx = 0;
int rx_repeat = 0;
int try_mem_tx_old;
unsigned long flags;
do {
unsigned short memtx = readw(hw->memreg_tx);
unsigned short memtx_serial;
unsigned short memrxdone =
readw(&hw->memory_info_regs->memreg_rx_done);
try_mem_tx_old = 0;
/* check whether the interrupt was generated by ipwireless card */
if (!(memtx & MEMTX_TX) && !(memrxdone & MEMRX_RX_DONE)) {
/* check if the card uses memreg_tx_old register */
if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
memtx = readw(&hw->memory_info_regs->memreg_tx_old);
if (memtx & MEMTX_TX) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": Using memreg_tx_old\n");
hw->memreg_tx =
&hw->memory_info_regs->memreg_tx_old;
} else {
return IRQ_NONE;
}
} else
return IRQ_NONE;
}
/*
* See if the card is physically present. Note that while it is
* powering up, it appears not to be present.
*/
if (!is_card_present(hw)) {
acknowledge_pcmcia_interrupt(hw);
return IRQ_HANDLED;
}
memtx_serial = memtx & (unsigned short) 0xff00;
if (memtx & MEMTX_TX) {
writew(memtx_serial, hw->memreg_tx);
if (hw->serial_number_detected) {
if (memtx_serial != hw->last_memtx_serial) {
hw->last_memtx_serial = memtx_serial;
spin_lock_irqsave(&hw->lock, flags);
hw->rx_ready++;
spin_unlock_irqrestore(&hw->lock, flags);
rx = 1;
} else
/* Ignore 'Timer Recovery' duplicates. */
rx_repeat = 1;
} else {
/*
* If a non-zero serial number is seen, then enable
* serial number checking.
*/
if (memtx_serial != 0) {
hw->serial_number_detected = 1;
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": memreg_tx serial num detected\n");
spin_lock_irqsave(&hw->lock, flags);
hw->rx_ready++;
spin_unlock_irqrestore(&hw->lock, flags);
}
rx = 1;
}
}
if (memrxdone & MEMRX_RX_DONE) {
writew(0, &hw->memory_info_regs->memreg_rx_done);
spin_lock_irqsave(&hw->lock, flags);
hw->tx_ready = 1;
spin_unlock_irqrestore(&hw->lock, flags);
tx = 1;
}
if (tx)
writew(MEMRX_PCINTACKK,
&hw->memory_info_regs->memreg_pc_interrupt_ack);
acknowledge_pcmcia_interrupt(hw);
if (tx || rx)
tasklet_schedule(&hw->tasklet);
else if (!rx_repeat) {
if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
if (hw->serial_number_detected)
printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
": spurious interrupt - new_tx mode\n");
else {
printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
": no valid memreg_tx value - switching to the old memreg_tx\n");
hw->memreg_tx =
&hw->memory_info_regs->memreg_tx_old;
try_mem_tx_old = 1;
}
} else
printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
": spurious interrupt - old_tx mode\n");
}
} while (try_mem_tx_old == 1);
return IRQ_HANDLED;
}
irqreturn_t ipwireless_interrupt(int irq, void *dev_id)
{
struct ipw_dev *ipw = dev_id;
if (ipw->hardware->hw_version == HW_VERSION_1)
return ipwireless_handle_v1_interrupt(irq, ipw->hardware);
else
return ipwireless_handle_v2_v3_interrupt(irq, ipw->hardware);
}
static void flush_packets_to_hw(struct ipw_hardware *hw)
{
int priority_limit;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
priority_limit = get_current_packet_priority(hw);
spin_unlock_irqrestore(&hw->lock, flags);
while (send_pending_packet(hw, priority_limit));
}
static void send_packet(struct ipw_hardware *hw, int priority,
struct ipw_tx_packet *packet)
{
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
list_add_tail(&packet->queue, &hw->tx_queue[priority]);
hw->tx_queued++;
spin_unlock_irqrestore(&hw->lock, flags);
flush_packets_to_hw(hw);
}
/* Create data packet, non-atomic allocation */
static void *alloc_data_packet(int data_size,
unsigned char dest_addr,
unsigned char protocol)
{
struct ipw_tx_packet *packet = kzalloc(
sizeof(struct ipw_tx_packet) + data_size,
GFP_ATOMIC);
if (!packet)
return NULL;
INIT_LIST_HEAD(&packet->queue);
packet->dest_addr = dest_addr;
packet->protocol = protocol;
packet->length = data_size;
return packet;
}
static void *alloc_ctrl_packet(int header_size,
unsigned char dest_addr,
unsigned char protocol,
unsigned char sig_no)
{
/*
* sig_no is located right after ipw_tx_packet struct in every
* CTRL or SETUP packets, we can use ipw_control_packet as a
* common struct
*/
struct ipw_control_packet *packet = kzalloc(header_size, GFP_ATOMIC);
if (!packet)
return NULL;
INIT_LIST_HEAD(&packet->header.queue);
packet->header.dest_addr = dest_addr;
packet->header.protocol = protocol;
packet->header.length = header_size - sizeof(struct ipw_tx_packet);
packet->body.sig_no = sig_no;
return packet;
}
int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
const unsigned char *data, unsigned int length,
void (*callback) (void *cb, unsigned int length),
void *callback_data)
{
struct ipw_tx_packet *packet;
packet = alloc_data_packet(length, (channel_idx + 1),
TL_PROTOCOLID_COM_DATA);
if (!packet)
return -ENOMEM;
packet->packet_callback = callback;
packet->callback_data = callback_data;
memcpy((unsigned char *) packet + sizeof(struct ipw_tx_packet), data,
length);
send_packet(hw, PRIO_DATA, packet);
return 0;
}
static int set_control_line(struct ipw_hardware *hw, int prio,
unsigned int channel_idx, int line, int state)
{
struct ipw_control_packet *packet;
int protocolid = TL_PROTOCOLID_COM_CTRL;
if (prio == PRIO_SETUP)
protocolid = TL_PROTOCOLID_SETUP;
packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet),
(channel_idx + 1), protocolid, line);
if (!packet)
return -ENOMEM;
packet->header.length = sizeof(struct ipw_control_packet_body);
packet->body.value = (state == 0 ? 0 : 1);
send_packet(hw, prio, &packet->header);
return 0;
}
static int set_DTR(struct ipw_hardware *hw, int priority,
unsigned int channel_idx, int state)
{
if (state != 0)
hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_DTR;
else
hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_DTR;
return set_control_line(hw, priority, channel_idx, COMCTRL_DTR, state);
}
static int set_RTS(struct ipw_hardware *hw, int priority,
unsigned int channel_idx, int state)
{
if (state != 0)
hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_RTS;
else
hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_RTS;
return set_control_line(hw, priority, channel_idx, COMCTRL_RTS, state);
}
int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
int state)
{
return set_DTR(hw, PRIO_CTRL, channel_idx, state);
}
int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
int state)
{
return set_RTS(hw, PRIO_CTRL, channel_idx, state);
}
struct ipw_setup_get_version_query_packet {
struct ipw_tx_packet header;
struct tl_setup_get_version_qry body;
};
struct ipw_setup_config_packet {
struct ipw_tx_packet header;
struct tl_setup_config_msg body;
};
struct ipw_setup_config_done_packet {
struct ipw_tx_packet header;
struct tl_setup_config_done_msg body;
};
struct ipw_setup_open_packet {
struct ipw_tx_packet header;
struct tl_setup_open_msg body;
};
struct ipw_setup_info_packet {
struct ipw_tx_packet header;
struct tl_setup_info_msg body;
};
struct ipw_setup_reboot_msg_ack {
struct ipw_tx_packet header;
struct TlSetupRebootMsgAck body;
};
/* This handles the actual initialization of the card */
static void __handle_setup_get_version_rsp(struct ipw_hardware *hw)
{
struct ipw_setup_config_packet *config_packet;
struct ipw_setup_config_done_packet *config_done_packet;
struct ipw_setup_open_packet *open_packet;
struct ipw_setup_info_packet *info_packet;
int port;
unsigned int channel_idx;
/* generate config packet */
for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
config_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_config_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_CONFIG_MSG);
if (!config_packet)
goto exit_nomem;
config_packet->header.length = sizeof(struct tl_setup_config_msg);
config_packet->body.port_no = port;
config_packet->body.prio_data = PRIO_DATA;
config_packet->body.prio_ctrl = PRIO_CTRL;
send_packet(hw, PRIO_SETUP, &config_packet->header);
}
config_done_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_config_done_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_CONFIG_DONE_MSG);
if (!config_done_packet)
goto exit_nomem;
config_done_packet->header.length = sizeof(struct tl_setup_config_done_msg);
send_packet(hw, PRIO_SETUP, &config_done_packet->header);
/* generate open packet */
for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
open_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_open_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_OPEN_MSG);
if (!open_packet)
goto exit_nomem;
open_packet->header.length = sizeof(struct tl_setup_open_msg);
open_packet->body.port_no = port;
send_packet(hw, PRIO_SETUP, &open_packet->header);
}
for (channel_idx = 0;
channel_idx < NL_NUM_OF_ADDRESSES; channel_idx++) {
int ret;
ret = set_DTR(hw, PRIO_SETUP, channel_idx,
(hw->control_lines[channel_idx] &
IPW_CONTROL_LINE_DTR) != 0);
if (ret) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": error setting DTR (%d)\n", ret);
return;
}
set_RTS(hw, PRIO_SETUP, channel_idx,
(hw->control_lines [channel_idx] &
IPW_CONTROL_LINE_RTS) != 0);
if (ret) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": error setting RTS (%d)\n", ret);
return;
}
}
/*
* For NDIS we assume that we are using sync PPP frames, for COM async.
* This driver uses NDIS mode too. We don't bother with translation
* from async -> sync PPP.
*/
info_packet = alloc_ctrl_packet(sizeof(struct ipw_setup_info_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_INFO_MSG);
if (!info_packet)
goto exit_nomem;
info_packet->header.length = sizeof(struct tl_setup_info_msg);
info_packet->body.driver_type = NDISWAN_DRIVER;
info_packet->body.major_version = NDISWAN_DRIVER_MAJOR_VERSION;
info_packet->body.minor_version = NDISWAN_DRIVER_MINOR_VERSION;
send_packet(hw, PRIO_SETUP, &info_packet->header);
/* Initialization is now complete, so we clear the 'to_setup' flag */
hw->to_setup = 0;
return;
exit_nomem:
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": not enough memory to alloc control packet\n");
hw->to_setup = -1;
}
static void handle_setup_get_version_rsp(struct ipw_hardware *hw,
unsigned char vers_no)
{
del_timer(&hw->setup_timer);
hw->initializing = 0;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": card is ready.\n");
if (vers_no == TL_SETUP_VERSION)
__handle_setup_get_version_rsp(hw);
else
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": invalid hardware version no %u\n",
(unsigned int) vers_no);
}
static void ipw_send_setup_packet(struct ipw_hardware *hw)
{
struct ipw_setup_get_version_query_packet *ver_packet;
ver_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_get_version_query_packet),
ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_GET_VERSION_QRY);
ver_packet->header.length = sizeof(struct tl_setup_get_version_qry);
/*
* Response is handled in handle_received_SETUP_packet
*/
send_packet(hw, PRIO_SETUP, &ver_packet->header);
}
static void handle_received_SETUP_packet(struct ipw_hardware *hw,
unsigned int address,
const unsigned char *data, int len,
int is_last)
{
const union ipw_setup_rx_msg *rx_msg = (const union ipw_setup_rx_msg *) data;
if (address != ADDR_SETUP_PROT) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": setup packet has bad address %d\n", address);
return;
}
switch (rx_msg->sig_no) {
case TL_SETUP_SIGNO_GET_VERSION_RSP:
if (hw->to_setup)
handle_setup_get_version_rsp(hw,
rx_msg->version_rsp_msg.version);
break;
case TL_SETUP_SIGNO_OPEN_MSG:
if (ipwireless_debug) {
unsigned int channel_idx = rx_msg->open_msg.port_no - 1;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": OPEN_MSG [channel %u] reply received\n",
channel_idx);
}
break;
case TL_SETUP_SIGNO_INFO_MSG_ACK:
if (ipwireless_debug)
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": card successfully configured as NDISWAN\n");
break;
case TL_SETUP_SIGNO_REBOOT_MSG:
if (hw->to_setup)
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": Setup not completed - ignoring reboot msg\n");
else {
struct ipw_setup_reboot_msg_ack *packet;
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": Acknowledging REBOOT message\n");
packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_reboot_msg_ack),
ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_REBOOT_MSG_ACK);
packet->header.length =
sizeof(struct TlSetupRebootMsgAck);
send_packet(hw, PRIO_SETUP, &packet->header);
if (hw->reboot_callback)
hw->reboot_callback(hw->reboot_callback_data);
}
break;
default:
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": unknown setup message %u received\n",
(unsigned int) rx_msg->sig_no);
}
}
static void do_close_hardware(struct ipw_hardware *hw)
{
unsigned int irqn;
if (hw->hw_version == HW_VERSION_1) {
/* Disable TX and RX interrupts. */
outw(0, hw->base_port + IOIER);
/* Acknowledge any outstanding interrupt requests */
irqn = inw(hw->base_port + IOIR);
if (irqn & IR_TXINTR)
outw(IR_TXINTR, hw->base_port + IOIR);
if (irqn & IR_RXINTR)
outw(IR_RXINTR, hw->base_port + IOIR);
synchronize_irq(hw->irq);
}
}
struct ipw_hardware *ipwireless_hardware_create(void)
{
int i;
struct ipw_hardware *hw =
kzalloc(sizeof(struct ipw_hardware), GFP_KERNEL);
if (!hw)
return NULL;
hw->irq = -1;
hw->initializing = 1;
hw->tx_ready = 1;
hw->rx_bytes_queued = 0;
hw->rx_pool_size = 0;
hw->last_memtx_serial = (unsigned short) 0xffff;
for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
INIT_LIST_HEAD(&hw->tx_queue[i]);
INIT_LIST_HEAD(&hw->rx_queue);
INIT_LIST_HEAD(&hw->rx_pool);
spin_lock_init(&hw->lock);
tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw);
INIT_WORK(&hw->work_rx, ipw_receive_data_work);
setup_timer(&hw->setup_timer, ipwireless_setup_timer,
(unsigned long) hw);
return hw;
}
void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
unsigned int base_port,
void __iomem *attr_memory,
void __iomem *common_memory,
int is_v2_card,
void (*reboot_callback) (void *data),
void *reboot_callback_data)
{
if (hw->removed) {
hw->removed = 0;
enable_irq(hw->irq);
}
hw->base_port = base_port;
hw->hw_version = (is_v2_card ? HW_VERSION_2 : HW_VERSION_1);
hw->ll_mtu = (hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2);
hw->memregs_CCR = (struct MEMCCR __iomem *)
((unsigned short __iomem *) attr_memory + 0x200);
hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory;
hw->memreg_tx = &hw->memory_info_regs->memreg_tx_new;
hw->reboot_callback = reboot_callback;
hw->reboot_callback_data = reboot_callback_data;
}
void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw)
{
hw->initializing = 1;
hw->init_loops = 0;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": waiting for card to start up...\n");
ipwireless_setup_timer((unsigned long) hw);
}
static void ipwireless_setup_timer(unsigned long data)
{
struct ipw_hardware *hw = (struct ipw_hardware *) data;
hw->init_loops++;
if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY &&
hw->hw_version == HW_VERSION_2 &&
hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": failed to startup using TX2, trying TX\n");
hw->memreg_tx = &hw->memory_info_regs->memreg_tx_old;
hw->init_loops = 0;
}
/* Give up after a certain number of retries */
if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": card failed to start up!\n");
hw->initializing = 0;
} else {
/* Do not attempt to write to the board if it is not present. */
if (is_card_present(hw)) {
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
hw->to_setup = 1;
hw->tx_ready = 1;
spin_unlock_irqrestore(&hw->lock, flags);
tasklet_schedule(&hw->tasklet);
}
mod_timer(&hw->setup_timer,
jiffies + msecs_to_jiffies(TL_SETUP_VERSION_QRY_TMO));
}
}
/*
* Stop any interrupts from executing so that, once this function returns,
* other layers of the driver can be sure they won't get any more callbacks.
* Thus must be called on a proper process context.
*/
void ipwireless_stop_interrupts(struct ipw_hardware *hw)
{
if (!hw->shutting_down) {
/* Tell everyone we are going down. */
hw->shutting_down = 1;
del_timer(&hw->setup_timer);
/* Prevent the hardware from sending any more interrupts */
do_close_hardware(hw);
}
}
void ipwireless_hardware_free(struct ipw_hardware *hw)
{
int i;
struct ipw_rx_packet *rp, *rq;
struct ipw_tx_packet *tp, *tq;
ipwireless_stop_interrupts(hw);
flush_work_sync(&hw->work_rx);
for (i = 0; i < NL_NUM_OF_ADDRESSES; i++)
if (hw->packet_assembler[i] != NULL)
kfree(hw->packet_assembler[i]);
for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
list_for_each_entry_safe(tp, tq, &hw->tx_queue[i], queue) {
list_del(&tp->queue);
kfree(tp);
}
list_for_each_entry_safe(rp, rq, &hw->rx_queue, queue) {
list_del(&rp->queue);
kfree(rp);
}
list_for_each_entry_safe(rp, rq, &hw->rx_pool, queue) {
list_del(&rp->queue);
kfree(rp);
}
kfree(hw);
}
/*
* Associate the specified network with this hardware, so it will receive events
* from it.
*/
void ipwireless_associate_network(struct ipw_hardware *hw,
struct ipw_network *network)
{
hw->network = network;
}
| gpl-2.0 |
HighwindONE/android_kernel_motorola_msm8226 | drivers/tty/ipwireless/hardware.c | 8195 | 46474 | /*
* IPWireless 3G PCMCIA Network Driver
*
* Original code
* by Stephen Blackheath <stephen@blacksapphire.com>,
* Ben Martel <benm@symmetric.co.nz>
*
* Copyrighted as follows:
* Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
*
* Various driver changes and rewrites, port to new kernels
* Copyright (C) 2006-2007 Jiri Kosina
*
* Misc code cleanups and updates
* Copyright (C) 2007 David Sterba
*/
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h>
#include "hardware.h"
#include "setup_protocol.h"
#include "network.h"
#include "main.h"
static void ipw_send_setup_packet(struct ipw_hardware *hw);
static void handle_received_SETUP_packet(struct ipw_hardware *ipw,
unsigned int address,
const unsigned char *data, int len,
int is_last);
static void ipwireless_setup_timer(unsigned long data);
static void handle_received_CTRL_packet(struct ipw_hardware *hw,
unsigned int channel_idx, const unsigned char *data, int len);
/*#define TIMING_DIAGNOSTICS*/
#ifdef TIMING_DIAGNOSTICS
static struct timing_stats {
unsigned long last_report_time;
unsigned long read_time;
unsigned long write_time;
unsigned long read_bytes;
unsigned long write_bytes;
unsigned long start_time;
};
static void start_timing(void)
{
timing_stats.start_time = jiffies;
}
static void end_read_timing(unsigned length)
{
timing_stats.read_time += (jiffies - start_time);
timing_stats.read_bytes += length + 2;
report_timing();
}
static void end_write_timing(unsigned length)
{
timing_stats.write_time += (jiffies - start_time);
timing_stats.write_bytes += length + 2;
report_timing();
}
static void report_timing(void)
{
unsigned long since = jiffies - timing_stats.last_report_time;
/* If it's been more than one second... */
if (since >= HZ) {
int first = (timing_stats.last_report_time == 0);
timing_stats.last_report_time = jiffies;
if (!first)
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": %u us elapsed - read %lu bytes in %u us, wrote %lu bytes in %u us\n",
jiffies_to_usecs(since),
timing_stats.read_bytes,
jiffies_to_usecs(timing_stats.read_time),
timing_stats.write_bytes,
jiffies_to_usecs(timing_stats.write_time));
timing_stats.read_time = 0;
timing_stats.write_time = 0;
timing_stats.read_bytes = 0;
timing_stats.write_bytes = 0;
}
}
#else
static void start_timing(void) { }
static void end_read_timing(unsigned length) { }
static void end_write_timing(unsigned length) { }
#endif
/* Imported IPW definitions */
#define LL_MTU_V1 318
#define LL_MTU_V2 250
#define LL_MTU_MAX (LL_MTU_V1 > LL_MTU_V2 ? LL_MTU_V1 : LL_MTU_V2)
#define PRIO_DATA 2
#define PRIO_CTRL 1
#define PRIO_SETUP 0
/* Addresses */
#define ADDR_SETUP_PROT 0
/* Protocol ids */
enum {
/* Identifier for the Com Data protocol */
TL_PROTOCOLID_COM_DATA = 0,
/* Identifier for the Com Control protocol */
TL_PROTOCOLID_COM_CTRL = 1,
/* Identifier for the Setup protocol */
TL_PROTOCOLID_SETUP = 2
};
/* Number of bytes in NL packet header (cannot do
* sizeof(nl_packet_header) since it's a bitfield) */
#define NL_FIRST_PACKET_HEADER_SIZE 3
/* Number of bytes in NL packet header (cannot do
* sizeof(nl_packet_header) since it's a bitfield) */
#define NL_FOLLOWING_PACKET_HEADER_SIZE 1
struct nl_first_packet_header {
unsigned char protocol:3;
unsigned char address:3;
unsigned char packet_rank:2;
unsigned char length_lsb;
unsigned char length_msb;
};
struct nl_packet_header {
unsigned char protocol:3;
unsigned char address:3;
unsigned char packet_rank:2;
};
/* Value of 'packet_rank' above */
#define NL_INTERMEDIATE_PACKET 0x0
#define NL_LAST_PACKET 0x1
#define NL_FIRST_PACKET 0x2
union nl_packet {
/* Network packet header of the first packet (a special case) */
struct nl_first_packet_header hdr_first;
/* Network packet header of the following packets (if any) */
struct nl_packet_header hdr;
/* Complete network packet (header + data) */
unsigned char rawpkt[LL_MTU_MAX];
} __attribute__ ((__packed__));
#define HW_VERSION_UNKNOWN -1
#define HW_VERSION_1 1
#define HW_VERSION_2 2
/* IPW I/O ports */
#define IOIER 0x00 /* Interrupt Enable Register */
#define IOIR 0x02 /* Interrupt Source/ACK register */
#define IODCR 0x04 /* Data Control Register */
#define IODRR 0x06 /* Data Read Register */
#define IODWR 0x08 /* Data Write Register */
#define IOESR 0x0A /* Embedded Driver Status Register */
#define IORXR 0x0C /* Rx Fifo Register (Host to Embedded) */
#define IOTXR 0x0E /* Tx Fifo Register (Embedded to Host) */
/* I/O ports and bit definitions for version 1 of the hardware */
/* IER bits*/
#define IER_RXENABLED 0x1
#define IER_TXENABLED 0x2
/* ISR bits */
#define IR_RXINTR 0x1
#define IR_TXINTR 0x2
/* DCR bits */
#define DCR_RXDONE 0x1
#define DCR_TXDONE 0x2
#define DCR_RXRESET 0x4
#define DCR_TXRESET 0x8
/* I/O ports and bit definitions for version 2 of the hardware */
struct MEMCCR {
unsigned short reg_config_option; /* PCCOR: Configuration Option Register */
unsigned short reg_config_and_status; /* PCCSR: Configuration and Status Register */
unsigned short reg_pin_replacement; /* PCPRR: Pin Replacemant Register */
unsigned short reg_socket_and_copy; /* PCSCR: Socket and Copy Register */
unsigned short reg_ext_status; /* PCESR: Extendend Status Register */
unsigned short reg_io_base; /* PCIOB: I/O Base Register */
};
struct MEMINFREG {
unsigned short memreg_tx_old; /* TX Register (R/W) */
unsigned short pad1;
unsigned short memreg_rx_done; /* RXDone Register (R/W) */
unsigned short pad2;
unsigned short memreg_rx; /* RX Register (R/W) */
unsigned short pad3;
unsigned short memreg_pc_interrupt_ack; /* PC intr Ack Register (W) */
unsigned short pad4;
unsigned long memreg_card_present;/* Mask for Host to check (R) for
* CARD_PRESENT_VALUE */
unsigned short memreg_tx_new; /* TX2 (new) Register (R/W) */
};
#define CARD_PRESENT_VALUE (0xBEEFCAFEUL)
#define MEMTX_TX 0x0001
#define MEMRX_RX 0x0001
#define MEMRX_RX_DONE 0x0001
#define MEMRX_PCINTACKK 0x0001
#define NL_NUM_OF_PRIORITIES 3
#define NL_NUM_OF_PROTOCOLS 3
#define NL_NUM_OF_ADDRESSES NO_OF_IPW_CHANNELS
struct ipw_hardware {
unsigned int base_port;
short hw_version;
unsigned short ll_mtu;
spinlock_t lock;
int initializing;
int init_loops;
struct timer_list setup_timer;
/* Flag if hw is ready to send next packet */
int tx_ready;
/* Count of pending packets to be sent */
int tx_queued;
struct list_head tx_queue[NL_NUM_OF_PRIORITIES];
int rx_bytes_queued;
struct list_head rx_queue;
/* Pool of rx_packet structures that are not currently used. */
struct list_head rx_pool;
int rx_pool_size;
/* True if reception of data is blocked while userspace processes it. */
int blocking_rx;
/* True if there is RX data ready on the hardware. */
int rx_ready;
unsigned short last_memtx_serial;
/*
* Newer versions of the V2 card firmware send serial numbers in the
* MemTX register. 'serial_number_detected' is set true when we detect
* a non-zero serial number (indicating the new firmware). Thereafter,
* the driver can safely ignore the Timer Recovery re-sends to avoid
* out-of-sync problems.
*/
int serial_number_detected;
struct work_struct work_rx;
/* True if we are to send the set-up data to the hardware. */
int to_setup;
/* Card has been removed */
int removed;
/* Saved irq value when we disable the interrupt. */
int irq;
/* True if this driver is shutting down. */
int shutting_down;
/* Modem control lines */
unsigned int control_lines[NL_NUM_OF_ADDRESSES];
struct ipw_rx_packet *packet_assembler[NL_NUM_OF_ADDRESSES];
struct tasklet_struct tasklet;
/* The handle for the network layer, for the sending of events to it. */
struct ipw_network *network;
struct MEMINFREG __iomem *memory_info_regs;
struct MEMCCR __iomem *memregs_CCR;
void (*reboot_callback) (void *data);
void *reboot_callback_data;
unsigned short __iomem *memreg_tx;
};
/*
* Packet info structure for tx packets.
* Note: not all the fields defined here are required for all protocols
*/
struct ipw_tx_packet {
struct list_head queue;
/* channel idx + 1 */
unsigned char dest_addr;
/* SETUP, CTRL or DATA */
unsigned char protocol;
/* Length of data block, which starts at the end of this structure */
unsigned short length;
/* Sending state */
/* Offset of where we've sent up to so far */
unsigned long offset;
/* Count of packet fragments, starting at 0 */
int fragment_count;
/* Called after packet is sent and before is freed */
void (*packet_callback) (void *cb_data, unsigned int packet_length);
void *callback_data;
};
/* Signals from DTE */
#define COMCTRL_RTS 0
#define COMCTRL_DTR 1
/* Signals from DCE */
#define COMCTRL_CTS 2
#define COMCTRL_DCD 3
#define COMCTRL_DSR 4
#define COMCTRL_RI 5
struct ipw_control_packet_body {
/* DTE signal or DCE signal */
unsigned char sig_no;
/* 0: set signal, 1: clear signal */
unsigned char value;
} __attribute__ ((__packed__));
struct ipw_control_packet {
struct ipw_tx_packet header;
struct ipw_control_packet_body body;
};
struct ipw_rx_packet {
struct list_head queue;
unsigned int capacity;
unsigned int length;
unsigned int protocol;
unsigned int channel_idx;
};
static char *data_type(const unsigned char *buf, unsigned length)
{
struct nl_packet_header *hdr = (struct nl_packet_header *) buf;
if (length == 0)
return " ";
if (hdr->packet_rank & NL_FIRST_PACKET) {
switch (hdr->protocol) {
case TL_PROTOCOLID_COM_DATA: return "DATA ";
case TL_PROTOCOLID_COM_CTRL: return "CTRL ";
case TL_PROTOCOLID_SETUP: return "SETUP";
default: return "???? ";
}
} else
return " ";
}
#define DUMP_MAX_BYTES 64
static void dump_data_bytes(const char *type, const unsigned char *data,
unsigned length)
{
char prefix[56];
sprintf(prefix, IPWIRELESS_PCCARD_NAME ": %s %s ",
type, data_type(data, length));
print_hex_dump_bytes(prefix, 0, (void *)data,
length < DUMP_MAX_BYTES ? length : DUMP_MAX_BYTES);
}
static void swap_packet_bitfield_to_le(unsigned char *data)
{
#ifdef __BIG_ENDIAN_BITFIELD
unsigned char tmp = *data, ret = 0;
/*
* transform bits from aa.bbb.ccc to ccc.bbb.aa
*/
ret |= tmp & 0xc0 >> 6;
ret |= tmp & 0x38 >> 1;
ret |= tmp & 0x07 << 5;
*data = ret & 0xff;
#endif
}
static void swap_packet_bitfield_from_le(unsigned char *data)
{
#ifdef __BIG_ENDIAN_BITFIELD
unsigned char tmp = *data, ret = 0;
/*
* transform bits from ccc.bbb.aa to aa.bbb.ccc
*/
ret |= tmp & 0xe0 >> 5;
ret |= tmp & 0x1c << 1;
ret |= tmp & 0x03 << 6;
*data = ret & 0xff;
#endif
}
static void do_send_fragment(struct ipw_hardware *hw, unsigned char *data,
unsigned length)
{
unsigned i;
unsigned long flags;
start_timing();
BUG_ON(length > hw->ll_mtu);
if (ipwireless_debug)
dump_data_bytes("send", data, length);
spin_lock_irqsave(&hw->lock, flags);
hw->tx_ready = 0;
swap_packet_bitfield_to_le(data);
if (hw->hw_version == HW_VERSION_1) {
outw((unsigned short) length, hw->base_port + IODWR);
for (i = 0; i < length; i += 2) {
unsigned short d = data[i];
__le16 raw_data;
if (i + 1 < length)
d |= data[i + 1] << 8;
raw_data = cpu_to_le16(d);
outw(raw_data, hw->base_port + IODWR);
}
outw(DCR_TXDONE, hw->base_port + IODCR);
} else if (hw->hw_version == HW_VERSION_2) {
outw((unsigned short) length, hw->base_port);
for (i = 0; i < length; i += 2) {
unsigned short d = data[i];
__le16 raw_data;
if (i + 1 < length)
d |= data[i + 1] << 8;
raw_data = cpu_to_le16(d);
outw(raw_data, hw->base_port);
}
while ((i & 3) != 2) {
outw((unsigned short) 0xDEAD, hw->base_port);
i += 2;
}
writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx);
}
spin_unlock_irqrestore(&hw->lock, flags);
end_write_timing(length);
}
static void do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
{
unsigned short fragment_data_len;
unsigned short data_left = packet->length - packet->offset;
unsigned short header_size;
union nl_packet pkt;
header_size =
(packet->fragment_count == 0)
? NL_FIRST_PACKET_HEADER_SIZE
: NL_FOLLOWING_PACKET_HEADER_SIZE;
fragment_data_len = hw->ll_mtu - header_size;
if (data_left < fragment_data_len)
fragment_data_len = data_left;
/*
* hdr_first is now in machine bitfield order, which will be swapped
* to le just before it goes to hw
*/
pkt.hdr_first.protocol = packet->protocol;
pkt.hdr_first.address = packet->dest_addr;
pkt.hdr_first.packet_rank = 0;
/* First packet? */
if (packet->fragment_count == 0) {
pkt.hdr_first.packet_rank |= NL_FIRST_PACKET;
pkt.hdr_first.length_lsb = (unsigned char) packet->length;
pkt.hdr_first.length_msb =
(unsigned char) (packet->length >> 8);
}
memcpy(pkt.rawpkt + header_size,
((unsigned char *) packet) + sizeof(struct ipw_tx_packet) +
packet->offset, fragment_data_len);
packet->offset += fragment_data_len;
packet->fragment_count++;
/* Last packet? (May also be first packet.) */
if (packet->offset == packet->length)
pkt.hdr_first.packet_rank |= NL_LAST_PACKET;
do_send_fragment(hw, pkt.rawpkt, header_size + fragment_data_len);
/* If this packet has unsent data, then re-queue it. */
if (packet->offset < packet->length) {
/*
* Re-queue it at the head of the highest priority queue so
* it goes before all other packets
*/
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
list_add(&packet->queue, &hw->tx_queue[0]);
hw->tx_queued++;
spin_unlock_irqrestore(&hw->lock, flags);
} else {
if (packet->packet_callback)
packet->packet_callback(packet->callback_data,
packet->length);
kfree(packet);
}
}
static void ipw_setup_hardware(struct ipw_hardware *hw)
{
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (hw->hw_version == HW_VERSION_1) {
/* Reset RX FIFO */
outw(DCR_RXRESET, hw->base_port + IODCR);
/* SB: Reset TX FIFO */
outw(DCR_TXRESET, hw->base_port + IODCR);
/* Enable TX and RX interrupts. */
outw(IER_TXENABLED | IER_RXENABLED, hw->base_port + IOIER);
} else {
/*
* Set INTRACK bit (bit 0), which means we must explicitly
* acknowledge interrupts by clearing bit 2 of reg_config_and_status.
*/
unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
csr |= 1;
writew(csr, &hw->memregs_CCR->reg_config_and_status);
}
spin_unlock_irqrestore(&hw->lock, flags);
}
/*
* If 'packet' is NULL, then this function allocates a new packet, setting its
* length to 0 and ensuring it has the specified minimum amount of free space.
*
* If 'packet' is not NULL, then this function enlarges it if it doesn't
* have the specified minimum amount of free space.
*
*/
static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
struct ipw_rx_packet *packet,
int minimum_free_space)
{
if (!packet) {
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (!list_empty(&hw->rx_pool)) {
packet = list_first_entry(&hw->rx_pool,
struct ipw_rx_packet, queue);
hw->rx_pool_size--;
spin_unlock_irqrestore(&hw->lock, flags);
list_del(&packet->queue);
} else {
const int min_capacity =
ipwireless_ppp_mru(hw->network) + 2;
int new_capacity;
spin_unlock_irqrestore(&hw->lock, flags);
new_capacity =
(minimum_free_space > min_capacity
? minimum_free_space
: min_capacity);
packet = kmalloc(sizeof(struct ipw_rx_packet)
+ new_capacity, GFP_ATOMIC);
if (!packet)
return NULL;
packet->capacity = new_capacity;
}
packet->length = 0;
}
if (packet->length + minimum_free_space > packet->capacity) {
struct ipw_rx_packet *old_packet = packet;
packet = kmalloc(sizeof(struct ipw_rx_packet) +
old_packet->length + minimum_free_space,
GFP_ATOMIC);
if (!packet) {
kfree(old_packet);
return NULL;
}
memcpy(packet, old_packet,
sizeof(struct ipw_rx_packet)
+ old_packet->length);
packet->capacity = old_packet->length + minimum_free_space;
kfree(old_packet);
}
return packet;
}
static void pool_free(struct ipw_hardware *hw, struct ipw_rx_packet *packet)
{
if (hw->rx_pool_size > 6)
kfree(packet);
else {
hw->rx_pool_size++;
list_add(&packet->queue, &hw->rx_pool);
}
}
static void queue_received_packet(struct ipw_hardware *hw,
unsigned int protocol,
unsigned int address,
const unsigned char *data, int length,
int is_last)
{
unsigned int channel_idx = address - 1;
struct ipw_rx_packet *packet = NULL;
unsigned long flags;
/* Discard packet if channel index is out of range. */
if (channel_idx >= NL_NUM_OF_ADDRESSES) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": data packet has bad address %u\n", address);
return;
}
/*
* ->packet_assembler is safe to touch unlocked, this is the only place
*/
if (protocol == TL_PROTOCOLID_COM_DATA) {
struct ipw_rx_packet **assem =
&hw->packet_assembler[channel_idx];
/*
* Create a new packet, or assembler already contains one
* enlarge it by 'length' bytes.
*/
(*assem) = pool_allocate(hw, *assem, length);
if (!(*assem)) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": no memory for incomming data packet, dropped!\n");
return;
}
(*assem)->protocol = protocol;
(*assem)->channel_idx = channel_idx;
/* Append this packet data onto existing data. */
memcpy((unsigned char *)(*assem) +
sizeof(struct ipw_rx_packet)
+ (*assem)->length, data, length);
(*assem)->length += length;
if (is_last) {
packet = *assem;
*assem = NULL;
/* Count queued DATA bytes only */
spin_lock_irqsave(&hw->lock, flags);
hw->rx_bytes_queued += packet->length;
spin_unlock_irqrestore(&hw->lock, flags);
}
} else {
/* If it's a CTRL packet, don't assemble, just queue it. */
packet = pool_allocate(hw, NULL, length);
if (!packet) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": no memory for incomming ctrl packet, dropped!\n");
return;
}
packet->protocol = protocol;
packet->channel_idx = channel_idx;
memcpy((unsigned char *)packet + sizeof(struct ipw_rx_packet),
data, length);
packet->length = length;
}
/*
* If this is the last packet, then send the assembled packet on to the
* network layer.
*/
if (packet) {
spin_lock_irqsave(&hw->lock, flags);
list_add_tail(&packet->queue, &hw->rx_queue);
/* Block reception of incoming packets if queue is full. */
hw->blocking_rx =
(hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE);
spin_unlock_irqrestore(&hw->lock, flags);
schedule_work(&hw->work_rx);
}
}
/*
* Workqueue callback
*/
static void ipw_receive_data_work(struct work_struct *work_rx)
{
struct ipw_hardware *hw =
container_of(work_rx, struct ipw_hardware, work_rx);
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
while (!list_empty(&hw->rx_queue)) {
struct ipw_rx_packet *packet =
list_first_entry(&hw->rx_queue,
struct ipw_rx_packet, queue);
if (hw->shutting_down)
break;
list_del(&packet->queue);
/*
* Note: ipwireless_network_packet_received must be called in a
* process context (i.e. via schedule_work) because the tty
* output code can sleep in the tty_flip_buffer_push call.
*/
if (packet->protocol == TL_PROTOCOLID_COM_DATA) {
if (hw->network != NULL) {
/* If the network hasn't been disconnected. */
spin_unlock_irqrestore(&hw->lock, flags);
/*
* This must run unlocked due to tty processing
* and mutex locking
*/
ipwireless_network_packet_received(
hw->network,
packet->channel_idx,
(unsigned char *)packet
+ sizeof(struct ipw_rx_packet),
packet->length);
spin_lock_irqsave(&hw->lock, flags);
}
/* Count queued DATA bytes only */
hw->rx_bytes_queued -= packet->length;
} else {
/*
* This is safe to be called locked, callchain does
* not block
*/
handle_received_CTRL_packet(hw, packet->channel_idx,
(unsigned char *)packet
+ sizeof(struct ipw_rx_packet),
packet->length);
}
pool_free(hw, packet);
/*
* Unblock reception of incoming packets if queue is no longer
* full.
*/
hw->blocking_rx =
hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
if (hw->shutting_down)
break;
}
spin_unlock_irqrestore(&hw->lock, flags);
}
static void handle_received_CTRL_packet(struct ipw_hardware *hw,
unsigned int channel_idx,
const unsigned char *data, int len)
{
const struct ipw_control_packet_body *body =
(const struct ipw_control_packet_body *) data;
unsigned int changed_mask;
if (len != sizeof(struct ipw_control_packet_body)) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": control packet was %d bytes - wrong size!\n",
len);
return;
}
switch (body->sig_no) {
case COMCTRL_CTS:
changed_mask = IPW_CONTROL_LINE_CTS;
break;
case COMCTRL_DCD:
changed_mask = IPW_CONTROL_LINE_DCD;
break;
case COMCTRL_DSR:
changed_mask = IPW_CONTROL_LINE_DSR;
break;
case COMCTRL_RI:
changed_mask = IPW_CONTROL_LINE_RI;
break;
default:
changed_mask = 0;
}
if (changed_mask != 0) {
if (body->value)
hw->control_lines[channel_idx] |= changed_mask;
else
hw->control_lines[channel_idx] &= ~changed_mask;
if (hw->network)
ipwireless_network_notify_control_line_change(
hw->network,
channel_idx,
hw->control_lines[channel_idx],
changed_mask);
}
}
static void handle_received_packet(struct ipw_hardware *hw,
const union nl_packet *packet,
unsigned short len)
{
unsigned int protocol = packet->hdr.protocol;
unsigned int address = packet->hdr.address;
unsigned int header_length;
const unsigned char *data;
unsigned int data_len;
int is_last = packet->hdr.packet_rank & NL_LAST_PACKET;
if (packet->hdr.packet_rank & NL_FIRST_PACKET)
header_length = NL_FIRST_PACKET_HEADER_SIZE;
else
header_length = NL_FOLLOWING_PACKET_HEADER_SIZE;
data = packet->rawpkt + header_length;
data_len = len - header_length;
switch (protocol) {
case TL_PROTOCOLID_COM_DATA:
case TL_PROTOCOLID_COM_CTRL:
queue_received_packet(hw, protocol, address, data, data_len,
is_last);
break;
case TL_PROTOCOLID_SETUP:
handle_received_SETUP_packet(hw, address, data, data_len,
is_last);
break;
}
}
static void acknowledge_data_read(struct ipw_hardware *hw)
{
if (hw->hw_version == HW_VERSION_1)
outw(DCR_RXDONE, hw->base_port + IODCR);
else
writew(MEMRX_PCINTACKK,
&hw->memory_info_regs->memreg_pc_interrupt_ack);
}
/*
* Retrieve a packet from the IPW hardware.
*/
static void do_receive_packet(struct ipw_hardware *hw)
{
unsigned len;
unsigned i;
unsigned char pkt[LL_MTU_MAX];
start_timing();
if (hw->hw_version == HW_VERSION_1) {
len = inw(hw->base_port + IODRR);
if (len > hw->ll_mtu) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": received a packet of %u bytes - longer than the MTU!\n", len);
outw(DCR_RXDONE | DCR_RXRESET, hw->base_port + IODCR);
return;
}
for (i = 0; i < len; i += 2) {
__le16 raw_data = inw(hw->base_port + IODRR);
unsigned short data = le16_to_cpu(raw_data);
pkt[i] = (unsigned char) data;
pkt[i + 1] = (unsigned char) (data >> 8);
}
} else {
len = inw(hw->base_port);
if (len > hw->ll_mtu) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": received a packet of %u bytes - longer than the MTU!\n", len);
writew(MEMRX_PCINTACKK,
&hw->memory_info_regs->memreg_pc_interrupt_ack);
return;
}
for (i = 0; i < len; i += 2) {
__le16 raw_data = inw(hw->base_port);
unsigned short data = le16_to_cpu(raw_data);
pkt[i] = (unsigned char) data;
pkt[i + 1] = (unsigned char) (data >> 8);
}
while ((i & 3) != 2) {
inw(hw->base_port);
i += 2;
}
}
acknowledge_data_read(hw);
swap_packet_bitfield_from_le(pkt);
if (ipwireless_debug)
dump_data_bytes("recv", pkt, len);
handle_received_packet(hw, (union nl_packet *) pkt, len);
end_read_timing(len);
}
static int get_current_packet_priority(struct ipw_hardware *hw)
{
/*
* If we're initializing, don't send anything of higher priority than
* PRIO_SETUP. The network layer therefore need not care about
* hardware initialization - any of its stuff will simply be queued
* until setup is complete.
*/
return (hw->to_setup || hw->initializing
? PRIO_SETUP + 1 : NL_NUM_OF_PRIORITIES);
}
/*
* return 1 if something has been received from hw
*/
static int get_packets_from_hw(struct ipw_hardware *hw)
{
int received = 0;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
while (hw->rx_ready && !hw->blocking_rx) {
received = 1;
hw->rx_ready--;
spin_unlock_irqrestore(&hw->lock, flags);
do_receive_packet(hw);
spin_lock_irqsave(&hw->lock, flags);
}
spin_unlock_irqrestore(&hw->lock, flags);
return received;
}
/*
* Send pending packet up to given priority, prioritize SETUP data until
* hardware is fully setup.
*
* return 1 if more packets can be sent
*/
static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
{
int more_to_send = 0;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (hw->tx_queued && hw->tx_ready) {
int priority;
struct ipw_tx_packet *packet = NULL;
/* Pick a packet */
for (priority = 0; priority < priority_limit; priority++) {
if (!list_empty(&hw->tx_queue[priority])) {
packet = list_first_entry(
&hw->tx_queue[priority],
struct ipw_tx_packet,
queue);
hw->tx_queued--;
list_del(&packet->queue);
break;
}
}
if (!packet) {
hw->tx_queued = 0;
spin_unlock_irqrestore(&hw->lock, flags);
return 0;
}
spin_unlock_irqrestore(&hw->lock, flags);
/* Send */
do_send_packet(hw, packet);
/* Check if more to send */
spin_lock_irqsave(&hw->lock, flags);
for (priority = 0; priority < priority_limit; priority++)
if (!list_empty(&hw->tx_queue[priority])) {
more_to_send = 1;
break;
}
if (!more_to_send)
hw->tx_queued = 0;
}
spin_unlock_irqrestore(&hw->lock, flags);
return more_to_send;
}
/*
* Send and receive all queued packets.
*/
static void ipwireless_do_tasklet(unsigned long hw_)
{
struct ipw_hardware *hw = (struct ipw_hardware *) hw_;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
if (hw->shutting_down) {
spin_unlock_irqrestore(&hw->lock, flags);
return;
}
if (hw->to_setup == 1) {
/*
* Initial setup data sent to hardware
*/
hw->to_setup = 2;
spin_unlock_irqrestore(&hw->lock, flags);
ipw_setup_hardware(hw);
ipw_send_setup_packet(hw);
send_pending_packet(hw, PRIO_SETUP + 1);
get_packets_from_hw(hw);
} else {
int priority_limit = get_current_packet_priority(hw);
int again;
spin_unlock_irqrestore(&hw->lock, flags);
do {
again = send_pending_packet(hw, priority_limit);
again |= get_packets_from_hw(hw);
} while (again);
}
}
/*
* return true if the card is physically present.
*/
static int is_card_present(struct ipw_hardware *hw)
{
if (hw->hw_version == HW_VERSION_1)
return inw(hw->base_port + IOIR) != 0xFFFF;
else
return readl(&hw->memory_info_regs->memreg_card_present) ==
CARD_PRESENT_VALUE;
}
static irqreturn_t ipwireless_handle_v1_interrupt(int irq,
struct ipw_hardware *hw)
{
unsigned short irqn;
irqn = inw(hw->base_port + IOIR);
/* Check if card is present */
if (irqn == 0xFFFF)
return IRQ_NONE;
else if (irqn != 0) {
unsigned short ack = 0;
unsigned long flags;
/* Transmit complete. */
if (irqn & IR_TXINTR) {
ack |= IR_TXINTR;
spin_lock_irqsave(&hw->lock, flags);
hw->tx_ready = 1;
spin_unlock_irqrestore(&hw->lock, flags);
}
/* Received data */
if (irqn & IR_RXINTR) {
ack |= IR_RXINTR;
spin_lock_irqsave(&hw->lock, flags);
hw->rx_ready++;
spin_unlock_irqrestore(&hw->lock, flags);
}
if (ack != 0) {
outw(ack, hw->base_port + IOIR);
tasklet_schedule(&hw->tasklet);
}
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static void acknowledge_pcmcia_interrupt(struct ipw_hardware *hw)
{
unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
csr &= 0xfffd;
writew(csr, &hw->memregs_CCR->reg_config_and_status);
}
static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
struct ipw_hardware *hw)
{
int tx = 0;
int rx = 0;
int rx_repeat = 0;
int try_mem_tx_old;
unsigned long flags;
do {
unsigned short memtx = readw(hw->memreg_tx);
unsigned short memtx_serial;
unsigned short memrxdone =
readw(&hw->memory_info_regs->memreg_rx_done);
try_mem_tx_old = 0;
/* check whether the interrupt was generated by ipwireless card */
if (!(memtx & MEMTX_TX) && !(memrxdone & MEMRX_RX_DONE)) {
/* check if the card uses memreg_tx_old register */
if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
memtx = readw(&hw->memory_info_regs->memreg_tx_old);
if (memtx & MEMTX_TX) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": Using memreg_tx_old\n");
hw->memreg_tx =
&hw->memory_info_regs->memreg_tx_old;
} else {
return IRQ_NONE;
}
} else
return IRQ_NONE;
}
/*
* See if the card is physically present. Note that while it is
* powering up, it appears not to be present.
*/
if (!is_card_present(hw)) {
acknowledge_pcmcia_interrupt(hw);
return IRQ_HANDLED;
}
memtx_serial = memtx & (unsigned short) 0xff00;
if (memtx & MEMTX_TX) {
writew(memtx_serial, hw->memreg_tx);
if (hw->serial_number_detected) {
if (memtx_serial != hw->last_memtx_serial) {
hw->last_memtx_serial = memtx_serial;
spin_lock_irqsave(&hw->lock, flags);
hw->rx_ready++;
spin_unlock_irqrestore(&hw->lock, flags);
rx = 1;
} else
/* Ignore 'Timer Recovery' duplicates. */
rx_repeat = 1;
} else {
/*
* If a non-zero serial number is seen, then enable
* serial number checking.
*/
if (memtx_serial != 0) {
hw->serial_number_detected = 1;
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": memreg_tx serial num detected\n");
spin_lock_irqsave(&hw->lock, flags);
hw->rx_ready++;
spin_unlock_irqrestore(&hw->lock, flags);
}
rx = 1;
}
}
if (memrxdone & MEMRX_RX_DONE) {
writew(0, &hw->memory_info_regs->memreg_rx_done);
spin_lock_irqsave(&hw->lock, flags);
hw->tx_ready = 1;
spin_unlock_irqrestore(&hw->lock, flags);
tx = 1;
}
if (tx)
writew(MEMRX_PCINTACKK,
&hw->memory_info_regs->memreg_pc_interrupt_ack);
acknowledge_pcmcia_interrupt(hw);
if (tx || rx)
tasklet_schedule(&hw->tasklet);
else if (!rx_repeat) {
if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
if (hw->serial_number_detected)
printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
": spurious interrupt - new_tx mode\n");
else {
printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
": no valid memreg_tx value - switching to the old memreg_tx\n");
hw->memreg_tx =
&hw->memory_info_regs->memreg_tx_old;
try_mem_tx_old = 1;
}
} else
printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
": spurious interrupt - old_tx mode\n");
}
} while (try_mem_tx_old == 1);
return IRQ_HANDLED;
}
irqreturn_t ipwireless_interrupt(int irq, void *dev_id)
{
struct ipw_dev *ipw = dev_id;
if (ipw->hardware->hw_version == HW_VERSION_1)
return ipwireless_handle_v1_interrupt(irq, ipw->hardware);
else
return ipwireless_handle_v2_v3_interrupt(irq, ipw->hardware);
}
static void flush_packets_to_hw(struct ipw_hardware *hw)
{
int priority_limit;
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
priority_limit = get_current_packet_priority(hw);
spin_unlock_irqrestore(&hw->lock, flags);
while (send_pending_packet(hw, priority_limit));
}
static void send_packet(struct ipw_hardware *hw, int priority,
struct ipw_tx_packet *packet)
{
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
list_add_tail(&packet->queue, &hw->tx_queue[priority]);
hw->tx_queued++;
spin_unlock_irqrestore(&hw->lock, flags);
flush_packets_to_hw(hw);
}
/* Create data packet, non-atomic allocation */
static void *alloc_data_packet(int data_size,
unsigned char dest_addr,
unsigned char protocol)
{
struct ipw_tx_packet *packet = kzalloc(
sizeof(struct ipw_tx_packet) + data_size,
GFP_ATOMIC);
if (!packet)
return NULL;
INIT_LIST_HEAD(&packet->queue);
packet->dest_addr = dest_addr;
packet->protocol = protocol;
packet->length = data_size;
return packet;
}
static void *alloc_ctrl_packet(int header_size,
unsigned char dest_addr,
unsigned char protocol,
unsigned char sig_no)
{
/*
* sig_no is located right after ipw_tx_packet struct in every
* CTRL or SETUP packets, we can use ipw_control_packet as a
* common struct
*/
struct ipw_control_packet *packet = kzalloc(header_size, GFP_ATOMIC);
if (!packet)
return NULL;
INIT_LIST_HEAD(&packet->header.queue);
packet->header.dest_addr = dest_addr;
packet->header.protocol = protocol;
packet->header.length = header_size - sizeof(struct ipw_tx_packet);
packet->body.sig_no = sig_no;
return packet;
}
int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
const unsigned char *data, unsigned int length,
void (*callback) (void *cb, unsigned int length),
void *callback_data)
{
struct ipw_tx_packet *packet;
packet = alloc_data_packet(length, (channel_idx + 1),
TL_PROTOCOLID_COM_DATA);
if (!packet)
return -ENOMEM;
packet->packet_callback = callback;
packet->callback_data = callback_data;
memcpy((unsigned char *) packet + sizeof(struct ipw_tx_packet), data,
length);
send_packet(hw, PRIO_DATA, packet);
return 0;
}
static int set_control_line(struct ipw_hardware *hw, int prio,
unsigned int channel_idx, int line, int state)
{
struct ipw_control_packet *packet;
int protocolid = TL_PROTOCOLID_COM_CTRL;
if (prio == PRIO_SETUP)
protocolid = TL_PROTOCOLID_SETUP;
packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet),
(channel_idx + 1), protocolid, line);
if (!packet)
return -ENOMEM;
packet->header.length = sizeof(struct ipw_control_packet_body);
packet->body.value = (state == 0 ? 0 : 1);
send_packet(hw, prio, &packet->header);
return 0;
}
static int set_DTR(struct ipw_hardware *hw, int priority,
unsigned int channel_idx, int state)
{
if (state != 0)
hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_DTR;
else
hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_DTR;
return set_control_line(hw, priority, channel_idx, COMCTRL_DTR, state);
}
static int set_RTS(struct ipw_hardware *hw, int priority,
unsigned int channel_idx, int state)
{
if (state != 0)
hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_RTS;
else
hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_RTS;
return set_control_line(hw, priority, channel_idx, COMCTRL_RTS, state);
}
int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
int state)
{
return set_DTR(hw, PRIO_CTRL, channel_idx, state);
}
int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
int state)
{
return set_RTS(hw, PRIO_CTRL, channel_idx, state);
}
struct ipw_setup_get_version_query_packet {
struct ipw_tx_packet header;
struct tl_setup_get_version_qry body;
};
struct ipw_setup_config_packet {
struct ipw_tx_packet header;
struct tl_setup_config_msg body;
};
struct ipw_setup_config_done_packet {
struct ipw_tx_packet header;
struct tl_setup_config_done_msg body;
};
struct ipw_setup_open_packet {
struct ipw_tx_packet header;
struct tl_setup_open_msg body;
};
struct ipw_setup_info_packet {
struct ipw_tx_packet header;
struct tl_setup_info_msg body;
};
struct ipw_setup_reboot_msg_ack {
struct ipw_tx_packet header;
struct TlSetupRebootMsgAck body;
};
/* This handles the actual initialization of the card */
static void __handle_setup_get_version_rsp(struct ipw_hardware *hw)
{
struct ipw_setup_config_packet *config_packet;
struct ipw_setup_config_done_packet *config_done_packet;
struct ipw_setup_open_packet *open_packet;
struct ipw_setup_info_packet *info_packet;
int port;
unsigned int channel_idx;
/* generate config packet */
for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
config_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_config_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_CONFIG_MSG);
if (!config_packet)
goto exit_nomem;
config_packet->header.length = sizeof(struct tl_setup_config_msg);
config_packet->body.port_no = port;
config_packet->body.prio_data = PRIO_DATA;
config_packet->body.prio_ctrl = PRIO_CTRL;
send_packet(hw, PRIO_SETUP, &config_packet->header);
}
config_done_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_config_done_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_CONFIG_DONE_MSG);
if (!config_done_packet)
goto exit_nomem;
config_done_packet->header.length = sizeof(struct tl_setup_config_done_msg);
send_packet(hw, PRIO_SETUP, &config_done_packet->header);
/* generate open packet */
for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
open_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_open_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_OPEN_MSG);
if (!open_packet)
goto exit_nomem;
open_packet->header.length = sizeof(struct tl_setup_open_msg);
open_packet->body.port_no = port;
send_packet(hw, PRIO_SETUP, &open_packet->header);
}
for (channel_idx = 0;
channel_idx < NL_NUM_OF_ADDRESSES; channel_idx++) {
int ret;
ret = set_DTR(hw, PRIO_SETUP, channel_idx,
(hw->control_lines[channel_idx] &
IPW_CONTROL_LINE_DTR) != 0);
if (ret) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": error setting DTR (%d)\n", ret);
return;
}
set_RTS(hw, PRIO_SETUP, channel_idx,
(hw->control_lines [channel_idx] &
IPW_CONTROL_LINE_RTS) != 0);
if (ret) {
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": error setting RTS (%d)\n", ret);
return;
}
}
/*
* For NDIS we assume that we are using sync PPP frames, for COM async.
* This driver uses NDIS mode too. We don't bother with translation
* from async -> sync PPP.
*/
info_packet = alloc_ctrl_packet(sizeof(struct ipw_setup_info_packet),
ADDR_SETUP_PROT,
TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_INFO_MSG);
if (!info_packet)
goto exit_nomem;
info_packet->header.length = sizeof(struct tl_setup_info_msg);
info_packet->body.driver_type = NDISWAN_DRIVER;
info_packet->body.major_version = NDISWAN_DRIVER_MAJOR_VERSION;
info_packet->body.minor_version = NDISWAN_DRIVER_MINOR_VERSION;
send_packet(hw, PRIO_SETUP, &info_packet->header);
/* Initialization is now complete, so we clear the 'to_setup' flag */
hw->to_setup = 0;
return;
exit_nomem:
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": not enough memory to alloc control packet\n");
hw->to_setup = -1;
}
static void handle_setup_get_version_rsp(struct ipw_hardware *hw,
unsigned char vers_no)
{
del_timer(&hw->setup_timer);
hw->initializing = 0;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": card is ready.\n");
if (vers_no == TL_SETUP_VERSION)
__handle_setup_get_version_rsp(hw);
else
printk(KERN_ERR IPWIRELESS_PCCARD_NAME
": invalid hardware version no %u\n",
(unsigned int) vers_no);
}
static void ipw_send_setup_packet(struct ipw_hardware *hw)
{
struct ipw_setup_get_version_query_packet *ver_packet;
ver_packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_get_version_query_packet),
ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_GET_VERSION_QRY);
ver_packet->header.length = sizeof(struct tl_setup_get_version_qry);
/*
* Response is handled in handle_received_SETUP_packet
*/
send_packet(hw, PRIO_SETUP, &ver_packet->header);
}
static void handle_received_SETUP_packet(struct ipw_hardware *hw,
unsigned int address,
const unsigned char *data, int len,
int is_last)
{
const union ipw_setup_rx_msg *rx_msg = (const union ipw_setup_rx_msg *) data;
if (address != ADDR_SETUP_PROT) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": setup packet has bad address %d\n", address);
return;
}
switch (rx_msg->sig_no) {
case TL_SETUP_SIGNO_GET_VERSION_RSP:
if (hw->to_setup)
handle_setup_get_version_rsp(hw,
rx_msg->version_rsp_msg.version);
break;
case TL_SETUP_SIGNO_OPEN_MSG:
if (ipwireless_debug) {
unsigned int channel_idx = rx_msg->open_msg.port_no - 1;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": OPEN_MSG [channel %u] reply received\n",
channel_idx);
}
break;
case TL_SETUP_SIGNO_INFO_MSG_ACK:
if (ipwireless_debug)
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": card successfully configured as NDISWAN\n");
break;
case TL_SETUP_SIGNO_REBOOT_MSG:
if (hw->to_setup)
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": Setup not completed - ignoring reboot msg\n");
else {
struct ipw_setup_reboot_msg_ack *packet;
printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
": Acknowledging REBOOT message\n");
packet = alloc_ctrl_packet(
sizeof(struct ipw_setup_reboot_msg_ack),
ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
TL_SETUP_SIGNO_REBOOT_MSG_ACK);
packet->header.length =
sizeof(struct TlSetupRebootMsgAck);
send_packet(hw, PRIO_SETUP, &packet->header);
if (hw->reboot_callback)
hw->reboot_callback(hw->reboot_callback_data);
}
break;
default:
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": unknown setup message %u received\n",
(unsigned int) rx_msg->sig_no);
}
}
static void do_close_hardware(struct ipw_hardware *hw)
{
unsigned int irqn;
if (hw->hw_version == HW_VERSION_1) {
/* Disable TX and RX interrupts. */
outw(0, hw->base_port + IOIER);
/* Acknowledge any outstanding interrupt requests */
irqn = inw(hw->base_port + IOIR);
if (irqn & IR_TXINTR)
outw(IR_TXINTR, hw->base_port + IOIR);
if (irqn & IR_RXINTR)
outw(IR_RXINTR, hw->base_port + IOIR);
synchronize_irq(hw->irq);
}
}
struct ipw_hardware *ipwireless_hardware_create(void)
{
int i;
struct ipw_hardware *hw =
kzalloc(sizeof(struct ipw_hardware), GFP_KERNEL);
if (!hw)
return NULL;
hw->irq = -1;
hw->initializing = 1;
hw->tx_ready = 1;
hw->rx_bytes_queued = 0;
hw->rx_pool_size = 0;
hw->last_memtx_serial = (unsigned short) 0xffff;
for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
INIT_LIST_HEAD(&hw->tx_queue[i]);
INIT_LIST_HEAD(&hw->rx_queue);
INIT_LIST_HEAD(&hw->rx_pool);
spin_lock_init(&hw->lock);
tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw);
INIT_WORK(&hw->work_rx, ipw_receive_data_work);
setup_timer(&hw->setup_timer, ipwireless_setup_timer,
(unsigned long) hw);
return hw;
}
void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
unsigned int base_port,
void __iomem *attr_memory,
void __iomem *common_memory,
int is_v2_card,
void (*reboot_callback) (void *data),
void *reboot_callback_data)
{
if (hw->removed) {
hw->removed = 0;
enable_irq(hw->irq);
}
hw->base_port = base_port;
hw->hw_version = (is_v2_card ? HW_VERSION_2 : HW_VERSION_1);
hw->ll_mtu = (hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2);
hw->memregs_CCR = (struct MEMCCR __iomem *)
((unsigned short __iomem *) attr_memory + 0x200);
hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory;
hw->memreg_tx = &hw->memory_info_regs->memreg_tx_new;
hw->reboot_callback = reboot_callback;
hw->reboot_callback_data = reboot_callback_data;
}
void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw)
{
hw->initializing = 1;
hw->init_loops = 0;
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": waiting for card to start up...\n");
ipwireless_setup_timer((unsigned long) hw);
}
static void ipwireless_setup_timer(unsigned long data)
{
struct ipw_hardware *hw = (struct ipw_hardware *) data;
hw->init_loops++;
if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY &&
hw->hw_version == HW_VERSION_2 &&
hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": failed to startup using TX2, trying TX\n");
hw->memreg_tx = &hw->memory_info_regs->memreg_tx_old;
hw->init_loops = 0;
}
/* Give up after a certain number of retries */
if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY) {
printk(KERN_INFO IPWIRELESS_PCCARD_NAME
": card failed to start up!\n");
hw->initializing = 0;
} else {
/* Do not attempt to write to the board if it is not present. */
if (is_card_present(hw)) {
unsigned long flags;
spin_lock_irqsave(&hw->lock, flags);
hw->to_setup = 1;
hw->tx_ready = 1;
spin_unlock_irqrestore(&hw->lock, flags);
tasklet_schedule(&hw->tasklet);
}
mod_timer(&hw->setup_timer,
jiffies + msecs_to_jiffies(TL_SETUP_VERSION_QRY_TMO));
}
}
/*
* Stop any interrupts from executing so that, once this function returns,
* other layers of the driver can be sure they won't get any more callbacks.
* Thus must be called on a proper process context.
*/
void ipwireless_stop_interrupts(struct ipw_hardware *hw)
{
if (!hw->shutting_down) {
/* Tell everyone we are going down. */
hw->shutting_down = 1;
del_timer(&hw->setup_timer);
/* Prevent the hardware from sending any more interrupts */
do_close_hardware(hw);
}
}
void ipwireless_hardware_free(struct ipw_hardware *hw)
{
int i;
struct ipw_rx_packet *rp, *rq;
struct ipw_tx_packet *tp, *tq;
ipwireless_stop_interrupts(hw);
flush_work_sync(&hw->work_rx);
for (i = 0; i < NL_NUM_OF_ADDRESSES; i++)
if (hw->packet_assembler[i] != NULL)
kfree(hw->packet_assembler[i]);
for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
list_for_each_entry_safe(tp, tq, &hw->tx_queue[i], queue) {
list_del(&tp->queue);
kfree(tp);
}
list_for_each_entry_safe(rp, rq, &hw->rx_queue, queue) {
list_del(&rp->queue);
kfree(rp);
}
list_for_each_entry_safe(rp, rq, &hw->rx_pool, queue) {
list_del(&rp->queue);
kfree(rp);
}
kfree(hw);
}
/*
* Associate the specified network with this hardware, so it will receive events
* from it.
*/
void ipwireless_associate_network(struct ipw_hardware *hw,
struct ipw_network *network)
{
hw->network = network;
}
| gpl-2.0 |
KimLemon/AKL-Kernel | net/wireless/lib80211.c | 8963 | 7256 | /*
* lib80211 -- common bits for IEEE802.11 drivers
*
* Copyright(c) 2008 John W. Linville <linville@tuxdriver.com>
*
* Portions copied from old ieee80211 component, w/ original copyright
* notices below:
*
* Host AP crypto routines
*
* Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
* Portions Copyright (C) 2004, Intel Corporation <jketreno@linux.intel.com>
*
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/ieee80211.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <net/lib80211.h>
#define DRV_NAME "lib80211"
#define DRV_DESCRIPTION "common routines for IEEE802.11 drivers"
MODULE_DESCRIPTION(DRV_DESCRIPTION);
MODULE_AUTHOR("John W. Linville <linville@tuxdriver.com>");
MODULE_LICENSE("GPL");
struct lib80211_crypto_alg {
struct list_head list;
struct lib80211_crypto_ops *ops;
};
static LIST_HEAD(lib80211_crypto_algs);
static DEFINE_SPINLOCK(lib80211_crypto_lock);
static void lib80211_crypt_deinit_entries(struct lib80211_crypt_info *info,
int force);
static void lib80211_crypt_quiescing(struct lib80211_crypt_info *info);
static void lib80211_crypt_deinit_handler(unsigned long data);
const char *print_ssid(char *buf, const char *ssid, u8 ssid_len)
{
const char *s = ssid;
char *d = buf;
ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN);
while (ssid_len--) {
if (isprint(*s)) {
*d++ = *s++;
continue;
}
*d++ = '\\';
if (*s == '\0')
*d++ = '0';
else if (*s == '\n')
*d++ = 'n';
else if (*s == '\r')
*d++ = 'r';
else if (*s == '\t')
*d++ = 't';
else if (*s == '\\')
*d++ = '\\';
else
d += snprintf(d, 3, "%03o", *s);
s++;
}
*d = '\0';
return buf;
}
EXPORT_SYMBOL(print_ssid);
int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
spinlock_t *lock)
{
memset(info, 0, sizeof(*info));
info->name = name;
info->lock = lock;
INIT_LIST_HEAD(&info->crypt_deinit_list);
setup_timer(&info->crypt_deinit_timer, lib80211_crypt_deinit_handler,
(unsigned long)info);
return 0;
}
EXPORT_SYMBOL(lib80211_crypt_info_init);
void lib80211_crypt_info_free(struct lib80211_crypt_info *info)
{
int i;
lib80211_crypt_quiescing(info);
del_timer_sync(&info->crypt_deinit_timer);
lib80211_crypt_deinit_entries(info, 1);
for (i = 0; i < NUM_WEP_KEYS; i++) {
struct lib80211_crypt_data *crypt = info->crypt[i];
if (crypt) {
if (crypt->ops) {
crypt->ops->deinit(crypt->priv);
module_put(crypt->ops->owner);
}
kfree(crypt);
info->crypt[i] = NULL;
}
}
}
EXPORT_SYMBOL(lib80211_crypt_info_free);
static void lib80211_crypt_deinit_entries(struct lib80211_crypt_info *info,
int force)
{
struct lib80211_crypt_data *entry, *next;
unsigned long flags;
spin_lock_irqsave(info->lock, flags);
list_for_each_entry_safe(entry, next, &info->crypt_deinit_list, list) {
if (atomic_read(&entry->refcnt) != 0 && !force)
continue;
list_del(&entry->list);
if (entry->ops) {
entry->ops->deinit(entry->priv);
module_put(entry->ops->owner);
}
kfree(entry);
}
spin_unlock_irqrestore(info->lock, flags);
}
/* After this, crypt_deinit_list won't accept new members */
static void lib80211_crypt_quiescing(struct lib80211_crypt_info *info)
{
unsigned long flags;
spin_lock_irqsave(info->lock, flags);
info->crypt_quiesced = 1;
spin_unlock_irqrestore(info->lock, flags);
}
static void lib80211_crypt_deinit_handler(unsigned long data)
{
struct lib80211_crypt_info *info = (struct lib80211_crypt_info *)data;
unsigned long flags;
lib80211_crypt_deinit_entries(info, 0);
spin_lock_irqsave(info->lock, flags);
if (!list_empty(&info->crypt_deinit_list) && !info->crypt_quiesced) {
printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
"deletion list\n", info->name);
info->crypt_deinit_timer.expires = jiffies + HZ;
add_timer(&info->crypt_deinit_timer);
}
spin_unlock_irqrestore(info->lock, flags);
}
void lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info,
struct lib80211_crypt_data **crypt)
{
struct lib80211_crypt_data *tmp;
unsigned long flags;
if (*crypt == NULL)
return;
tmp = *crypt;
*crypt = NULL;
/* must not run ops->deinit() while there may be pending encrypt or
* decrypt operations. Use a list of delayed deinits to avoid needing
* locking. */
spin_lock_irqsave(info->lock, flags);
if (!info->crypt_quiesced) {
list_add(&tmp->list, &info->crypt_deinit_list);
if (!timer_pending(&info->crypt_deinit_timer)) {
info->crypt_deinit_timer.expires = jiffies + HZ;
add_timer(&info->crypt_deinit_timer);
}
}
spin_unlock_irqrestore(info->lock, flags);
}
EXPORT_SYMBOL(lib80211_crypt_delayed_deinit);
int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops)
{
unsigned long flags;
struct lib80211_crypto_alg *alg;
alg = kzalloc(sizeof(*alg), GFP_KERNEL);
if (alg == NULL)
return -ENOMEM;
alg->ops = ops;
spin_lock_irqsave(&lib80211_crypto_lock, flags);
list_add(&alg->list, &lib80211_crypto_algs);
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
printk(KERN_DEBUG "lib80211_crypt: registered algorithm '%s'\n",
ops->name);
return 0;
}
EXPORT_SYMBOL(lib80211_register_crypto_ops);
int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops)
{
struct lib80211_crypto_alg *alg;
unsigned long flags;
spin_lock_irqsave(&lib80211_crypto_lock, flags);
list_for_each_entry(alg, &lib80211_crypto_algs, list) {
if (alg->ops == ops)
goto found;
}
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
return -EINVAL;
found:
printk(KERN_DEBUG "lib80211_crypt: unregistered algorithm '%s'\n",
ops->name);
list_del(&alg->list);
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
kfree(alg);
return 0;
}
EXPORT_SYMBOL(lib80211_unregister_crypto_ops);
struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name)
{
struct lib80211_crypto_alg *alg;
unsigned long flags;
spin_lock_irqsave(&lib80211_crypto_lock, flags);
list_for_each_entry(alg, &lib80211_crypto_algs, list) {
if (strcmp(alg->ops->name, name) == 0)
goto found;
}
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
return NULL;
found:
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
return alg->ops;
}
EXPORT_SYMBOL(lib80211_get_crypto_ops);
static void *lib80211_crypt_null_init(int keyidx)
{
return (void *)1;
}
static void lib80211_crypt_null_deinit(void *priv)
{
}
static struct lib80211_crypto_ops lib80211_crypt_null = {
.name = "NULL",
.init = lib80211_crypt_null_init,
.deinit = lib80211_crypt_null_deinit,
.owner = THIS_MODULE,
};
static int __init lib80211_init(void)
{
pr_info(DRV_DESCRIPTION "\n");
return lib80211_register_crypto_ops(&lib80211_crypt_null);
}
static void __exit lib80211_exit(void)
{
lib80211_unregister_crypto_ops(&lib80211_crypt_null);
BUG_ON(!list_empty(&lib80211_crypto_algs));
}
module_init(lib80211_init);
module_exit(lib80211_exit);
| gpl-2.0 |
AICP/kernel_lge_mako | net/wireless/lib80211.c | 8963 | 7256 | /*
* lib80211 -- common bits for IEEE802.11 drivers
*
* Copyright(c) 2008 John W. Linville <linville@tuxdriver.com>
*
* Portions copied from old ieee80211 component, w/ original copyright
* notices below:
*
* Host AP crypto routines
*
* Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
* Portions Copyright (C) 2004, Intel Corporation <jketreno@linux.intel.com>
*
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/ieee80211.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <net/lib80211.h>
#define DRV_NAME "lib80211"
#define DRV_DESCRIPTION "common routines for IEEE802.11 drivers"
MODULE_DESCRIPTION(DRV_DESCRIPTION);
MODULE_AUTHOR("John W. Linville <linville@tuxdriver.com>");
MODULE_LICENSE("GPL");
struct lib80211_crypto_alg {
struct list_head list;
struct lib80211_crypto_ops *ops;
};
static LIST_HEAD(lib80211_crypto_algs);
static DEFINE_SPINLOCK(lib80211_crypto_lock);
static void lib80211_crypt_deinit_entries(struct lib80211_crypt_info *info,
int force);
static void lib80211_crypt_quiescing(struct lib80211_crypt_info *info);
static void lib80211_crypt_deinit_handler(unsigned long data);
const char *print_ssid(char *buf, const char *ssid, u8 ssid_len)
{
const char *s = ssid;
char *d = buf;
ssid_len = min_t(u8, ssid_len, IEEE80211_MAX_SSID_LEN);
while (ssid_len--) {
if (isprint(*s)) {
*d++ = *s++;
continue;
}
*d++ = '\\';
if (*s == '\0')
*d++ = '0';
else if (*s == '\n')
*d++ = 'n';
else if (*s == '\r')
*d++ = 'r';
else if (*s == '\t')
*d++ = 't';
else if (*s == '\\')
*d++ = '\\';
else
d += snprintf(d, 3, "%03o", *s);
s++;
}
*d = '\0';
return buf;
}
EXPORT_SYMBOL(print_ssid);
int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
spinlock_t *lock)
{
memset(info, 0, sizeof(*info));
info->name = name;
info->lock = lock;
INIT_LIST_HEAD(&info->crypt_deinit_list);
setup_timer(&info->crypt_deinit_timer, lib80211_crypt_deinit_handler,
(unsigned long)info);
return 0;
}
EXPORT_SYMBOL(lib80211_crypt_info_init);
void lib80211_crypt_info_free(struct lib80211_crypt_info *info)
{
int i;
lib80211_crypt_quiescing(info);
del_timer_sync(&info->crypt_deinit_timer);
lib80211_crypt_deinit_entries(info, 1);
for (i = 0; i < NUM_WEP_KEYS; i++) {
struct lib80211_crypt_data *crypt = info->crypt[i];
if (crypt) {
if (crypt->ops) {
crypt->ops->deinit(crypt->priv);
module_put(crypt->ops->owner);
}
kfree(crypt);
info->crypt[i] = NULL;
}
}
}
EXPORT_SYMBOL(lib80211_crypt_info_free);
static void lib80211_crypt_deinit_entries(struct lib80211_crypt_info *info,
int force)
{
struct lib80211_crypt_data *entry, *next;
unsigned long flags;
spin_lock_irqsave(info->lock, flags);
list_for_each_entry_safe(entry, next, &info->crypt_deinit_list, list) {
if (atomic_read(&entry->refcnt) != 0 && !force)
continue;
list_del(&entry->list);
if (entry->ops) {
entry->ops->deinit(entry->priv);
module_put(entry->ops->owner);
}
kfree(entry);
}
spin_unlock_irqrestore(info->lock, flags);
}
/* After this, crypt_deinit_list won't accept new members */
static void lib80211_crypt_quiescing(struct lib80211_crypt_info *info)
{
unsigned long flags;
spin_lock_irqsave(info->lock, flags);
info->crypt_quiesced = 1;
spin_unlock_irqrestore(info->lock, flags);
}
static void lib80211_crypt_deinit_handler(unsigned long data)
{
struct lib80211_crypt_info *info = (struct lib80211_crypt_info *)data;
unsigned long flags;
lib80211_crypt_deinit_entries(info, 0);
spin_lock_irqsave(info->lock, flags);
if (!list_empty(&info->crypt_deinit_list) && !info->crypt_quiesced) {
printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
"deletion list\n", info->name);
info->crypt_deinit_timer.expires = jiffies + HZ;
add_timer(&info->crypt_deinit_timer);
}
spin_unlock_irqrestore(info->lock, flags);
}
void lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info,
struct lib80211_crypt_data **crypt)
{
struct lib80211_crypt_data *tmp;
unsigned long flags;
if (*crypt == NULL)
return;
tmp = *crypt;
*crypt = NULL;
/* must not run ops->deinit() while there may be pending encrypt or
* decrypt operations. Use a list of delayed deinits to avoid needing
* locking. */
spin_lock_irqsave(info->lock, flags);
if (!info->crypt_quiesced) {
list_add(&tmp->list, &info->crypt_deinit_list);
if (!timer_pending(&info->crypt_deinit_timer)) {
info->crypt_deinit_timer.expires = jiffies + HZ;
add_timer(&info->crypt_deinit_timer);
}
}
spin_unlock_irqrestore(info->lock, flags);
}
EXPORT_SYMBOL(lib80211_crypt_delayed_deinit);
int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops)
{
unsigned long flags;
struct lib80211_crypto_alg *alg;
alg = kzalloc(sizeof(*alg), GFP_KERNEL);
if (alg == NULL)
return -ENOMEM;
alg->ops = ops;
spin_lock_irqsave(&lib80211_crypto_lock, flags);
list_add(&alg->list, &lib80211_crypto_algs);
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
printk(KERN_DEBUG "lib80211_crypt: registered algorithm '%s'\n",
ops->name);
return 0;
}
EXPORT_SYMBOL(lib80211_register_crypto_ops);
int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops)
{
struct lib80211_crypto_alg *alg;
unsigned long flags;
spin_lock_irqsave(&lib80211_crypto_lock, flags);
list_for_each_entry(alg, &lib80211_crypto_algs, list) {
if (alg->ops == ops)
goto found;
}
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
return -EINVAL;
found:
printk(KERN_DEBUG "lib80211_crypt: unregistered algorithm '%s'\n",
ops->name);
list_del(&alg->list);
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
kfree(alg);
return 0;
}
EXPORT_SYMBOL(lib80211_unregister_crypto_ops);
struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name)
{
struct lib80211_crypto_alg *alg;
unsigned long flags;
spin_lock_irqsave(&lib80211_crypto_lock, flags);
list_for_each_entry(alg, &lib80211_crypto_algs, list) {
if (strcmp(alg->ops->name, name) == 0)
goto found;
}
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
return NULL;
found:
spin_unlock_irqrestore(&lib80211_crypto_lock, flags);
return alg->ops;
}
EXPORT_SYMBOL(lib80211_get_crypto_ops);
static void *lib80211_crypt_null_init(int keyidx)
{
return (void *)1;
}
static void lib80211_crypt_null_deinit(void *priv)
{
}
static struct lib80211_crypto_ops lib80211_crypt_null = {
.name = "NULL",
.init = lib80211_crypt_null_init,
.deinit = lib80211_crypt_null_deinit,
.owner = THIS_MODULE,
};
static int __init lib80211_init(void)
{
pr_info(DRV_DESCRIPTION "\n");
return lib80211_register_crypto_ops(&lib80211_crypt_null);
}
static void __exit lib80211_exit(void)
{
lib80211_unregister_crypto_ops(&lib80211_crypt_null);
BUG_ON(!list_empty(&lib80211_crypto_algs));
}
module_init(lib80211_init);
module_exit(lib80211_exit);
| gpl-2.0 |
Framework43/touchpad-kernel | drivers/staging/wlags49_h2/sta_h25.c | 9219 | 504432 | /*
* File: sta_h54.136
*
* Abstract: This file contains memory image 'fw_image'.
*
* Contents: Total size of the memory image: 81742 bytes.
* Total number of blocks: 4 blocks.
* Block 1 : load address 00000060, 388 bytes.
* Block 2 : load address 00000C16, 11278 bytes.
* Block 3 : load address 001E3824, 21726 bytes.
* Block 4 : load address 001F4000, 48350 bytes.
*
* Identity: component id: 31 (variant 4) version 1.36
*
* Compatibility:
* supplying interface 4 (variant 4) : 1 - 2
* acting on interface 1 (variant 7) : 3 - 3
* acting on interface 1 (variant 8) : 1 - 1
* acting on interface 2 (variant 4) : 1 - 2
*
* Generated: by g:\fw\fupu3.exe version 4.26
*
* Commandline: g:\fw\fupu3.exe /f=4 /n=fw_image /i=r4013600.hex
*/
#include "hcfcfg.h" // to get hcf_16 etc defined as well as
// possible settings which inluence mdd.h or dhf.h
#include "mdd.h" //to get COMP_ID_STA etc defined
#include "dhf.h" //used to be "fhfmem.h", to get memblock,plugrecord,
static const hcf_8 fw_image_1_data[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDA, 0x0C, 0x00, 0x00,
0x00, 0x0D, 0x00, 0x00, 0x00, 0x0D, 0x65, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x1B, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2, 0x1B, 0xB2, 0x1B,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEA, 0x00, 0x00, 0xFF, 0x07,
0x01, 0x00, 0x64, 0x00, 0x64, 0x00, 0x10, 0x27, 0x10, 0x27, 0x14, 0x00, 0xD0, 0x07, 0xD0, 0x07,
0x10, 0x27, 0x2F, 0x00, 0x32, 0x00, 0x32, 0x00, 0x05, 0x00, 0x02, 0x00, 0x02, 0x00, 0x10, 0x27,
0x05, 0x00, 0x00, 0x02, 0x00, 0x02, 0x13, 0x00, 0x07, 0x00, 0x03, 0x00, 0x32, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x09, 0x2B, 0x09, 0x2B, 0x09, 0xFF, 0x0F, 0xF0, 0x0F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x00, 0x40, 0x00, 0x32, 0x00, 0x32, 0x00, 0x0A, 0x00,
0x02, 0x00, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}; /* fw_image_1_data */
static const hcf_8 fw_image_2_data[] = {
0xF4, 0xA3, 0x00, 0x16, 0x08, 0x40, 0x0F, 0xD2, 0xE1, 0x28, 0xA5, 0x7C, 0x50, 0x30, 0xF1, 0x84,
0x44, 0x08, 0xAB, 0xAE, 0xA5, 0xB8, 0xFC, 0xBA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0xC6, 0x84, 0xF8, 0x99, 0xEE,
0x8D, 0xF6, 0x0D, 0xFF, 0xBD, 0xD6, 0xB1, 0xDE, 0x54, 0x91, 0x50, 0x60, 0x03, 0x02, 0xA9, 0xCE,
0x7D, 0x56, 0x19, 0xE7, 0x62, 0xB5, 0xE6, 0x4D, 0x9A, 0xEC, 0x45, 0x8F, 0x9D, 0x1F, 0x40, 0x89,
0x87, 0xFA, 0x15, 0xEF, 0xEB, 0xB2, 0xC9, 0x8E, 0x0B, 0xFB, 0xEC, 0x41, 0x67, 0xB3, 0xFD, 0x5F,
0xEA, 0x45, 0xBF, 0x23, 0xF7, 0x53, 0x96, 0xE4, 0x5B, 0x9B, 0xC2, 0x75, 0x1C, 0xE1, 0xAE, 0x3D,
0x6A, 0x4C, 0x5A, 0x6C, 0x41, 0x7E, 0x02, 0xF5, 0x4F, 0x83, 0x5C, 0x68, 0xF4, 0x51, 0x34, 0xD1,
0x08, 0xF9, 0x93, 0xE2, 0x73, 0xAB, 0x53, 0x62, 0x3F, 0x2A, 0x0C, 0x08, 0x52, 0x95, 0x65, 0x46,
0x5E, 0x9D, 0x28, 0x30, 0xA1, 0x37, 0x0F, 0x0A, 0xB5, 0x2F, 0x09, 0x0E, 0x36, 0x24, 0x9B, 0x1B,
0x3D, 0xDF, 0x26, 0xCD, 0x69, 0x4E, 0xCD, 0x7F, 0x9F, 0xEA, 0x1B, 0x12, 0x9E, 0x1D, 0x74, 0x58,
0x2E, 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A,
0x11, 0x1E, 0xCB, 0x7B, 0xFC, 0xA8, 0xD6, 0x6D, 0x3A, 0x2C, 0x00, 0x30, 0x00, 0x31, 0x00, 0x33,
0x00, 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, 0x38, 0x00, 0x38, 0x00, 0x3A, 0x00, 0x3B,
0x00, 0x3C, 0x00, 0x3D, 0x00, 0x3E, 0x00, 0x3F, 0x00, 0x3F, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x28, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x0A, 0x02, 0x14, 0x05, 0x32, 0x0B, 0x37, 0x08, 0x50, 0x0B, 0x6E,
0x02, 0x00, 0x04, 0x00, 0x0B, 0x00, 0x16, 0x00, 0x0C, 0x00, 0x12, 0x00, 0x18, 0x00, 0x24, 0x00,
0x30, 0x00, 0x48, 0x00, 0x60, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x39, 0x00, 0x39, 0x00, 0x20, 0x00, 0x39, 0x00, 0x39, 0x00, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10,
0x3E, 0x11, 0xF6, 0x10, 0x38, 0x11, 0xFC, 0x10, 0x32, 0x11, 0x02, 0x11, 0x2C, 0x11, 0x08, 0x11,
0x26, 0x11, 0x0E, 0x11, 0x20, 0x11, 0x14, 0x11, 0x1A, 0x11, 0x07, 0x01, 0x00, 0x00, 0x16, 0x22,
0x00, 0x04, 0x08, 0x01, 0x00, 0x00, 0x16, 0x26, 0x00, 0x04, 0x09, 0x01, 0x00, 0x00, 0x16, 0x2A,
0x00, 0x04, 0x0A, 0x01, 0x00, 0x00, 0x16, 0x2E, 0x00, 0x04, 0x0B, 0x01, 0x00, 0x00, 0x10, 0x24,
0x04, 0x04, 0x0C, 0x01, 0x00, 0x00, 0x10, 0x28, 0x04, 0x04, 0x0D, 0x01, 0x00, 0x00, 0x10, 0x2C,
0x04, 0x04, 0x0E, 0x01, 0x00, 0x00, 0x10, 0x30, 0x04, 0x04, 0x0F, 0x01, 0x00, 0x00, 0x14, 0x34,
0x08, 0x84, 0x10, 0x01, 0x00, 0x00, 0x14, 0x38, 0x08, 0x84, 0x11, 0x01, 0x00, 0x00, 0x14, 0x3C,
0x08, 0x84, 0x12, 0x01, 0x00, 0x00, 0x14, 0x40, 0x08, 0x84, 0x13, 0x01, 0x00, 0x00, 0x17, 0x64,
0x0C, 0x8B, 0x14, 0x01, 0x00, 0x00, 0x17, 0x68, 0x0C, 0x8B, 0x15, 0x01, 0x00, 0x00, 0x17, 0x6C,
0x0C, 0x8B, 0x16, 0x01, 0x00, 0x00, 0x17, 0x70, 0x0C, 0x8B, 0x17, 0x01, 0x00, 0x00, 0x17, 0x74,
0x0C, 0x8B, 0x18, 0x01, 0x00, 0x00, 0x17, 0x78, 0x0C, 0x8B, 0x19, 0x01, 0x00, 0x00, 0x17, 0x7C,
0x0C, 0x8B, 0x1A, 0x01, 0x00, 0x00, 0x17, 0x80, 0x0C, 0x8B, 0x1B, 0x01, 0x00, 0x00, 0x17, 0x84,
0x0C, 0x8B, 0x1C, 0x01, 0x00, 0x00, 0x17, 0x88, 0x0C, 0x8B, 0x1D, 0x01, 0x00, 0x00, 0x17, 0x8C,
0x0C, 0x8B, 0x1E, 0x01, 0x00, 0x00, 0x0E, 0x95, 0x17, 0x04, 0x1F, 0x01, 0x00, 0x00, 0x0E, 0x99,
0x17, 0x04, 0x20, 0x01, 0x00, 0x00, 0x0E, 0x9D, 0x17, 0x04, 0x21, 0x01, 0x00, 0x00, 0x0E, 0xA1,
0x17, 0x04, 0x22, 0x01, 0x00, 0x00, 0x0E, 0xA5, 0x00, 0x00, 0x60, 0x11, 0x80, 0x11, 0xA0, 0x11,
0xC0, 0x11, 0x18, 0x12, 0x68, 0x11, 0x88, 0x11, 0xA8, 0x11, 0xC8, 0x11, 0x20, 0x12, 0x70, 0x11,
0x90, 0x11, 0xB0, 0x11, 0xD0, 0x11, 0x28, 0x12, 0x78, 0x11, 0x98, 0x11, 0xB8, 0x11, 0xD8, 0x11,
0x30, 0x12, 0xE0, 0x11, 0xE8, 0x11, 0xF0, 0x11, 0xF8, 0x11, 0x00, 0x12, 0x08, 0x12, 0x10, 0x12,
0x38, 0x12, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x0A, 0x0A,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7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x9D, 0x9D, 0xA1, 0xB4,
0x10, 0x10, 0x00, 0x9D, 0x08, 0x02, 0x06, 0x00, 0xA5, 0xA5, 0xAA, 0xB4, 0x10, 0x10, 0x00, 0xA2,
0x15, 0x05, 0x07, 0x00, 0xAA, 0xAA, 0xB4, 0xB4, 0x10, 0x10, 0x00, 0xA7, 0x1C, 0x0A, 0x08, 0x00,
0xB7, 0xB7, 0xC1, 0xC1, 0x10, 0x10, 0x00, 0xB4, 0x29, 0x17, 0x08, 0x00, 0xBD, 0xBD, 0xC7, 0xC7,
0x10, 0x10, 0x00, 0xBA, 0x2F, 0x1D, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC4, 0x1F, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x42, 0x2A, 0x5B, 0x2A, 0x7E, 0x2A, 0x71, 0x30, 0xEE, 0x29, 0x88, 0x30, 0xB8, 0x2A,
0x9F, 0x30, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0x21, 0x35, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29,
0xEE, 0x29, 0xEE, 0x29, 0x93, 0x2C, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29,
0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29,
0xEE, 0x29, 0xEE, 0x29, 0xDE, 0x2C, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29,
0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29,
0xEE, 0x29, 0x61, 0x2C, 0x7C, 0x2C, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29, 0xEE, 0x29,
0xEE, 0x29, 0xE1, 0x27, 0xD7, 0x2A, 0xEA, 0x2A, 0x9A, 0x2B, 0x9E, 0x2B, 0xEE, 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FC, 0x45, 0x2D, 0x5B, 0x2D, 0x36, 0x2E, 0x02, 0x00, 0x27, 0xFC, 0x45, 0x2D, 0x5B, 0x2D,
0x38, 0x2E, 0x02, 0x00, 0xB2, 0xFC, 0x45, 0x2D, 0x55, 0x2D, 0x24, 0x2F, 0x22, 0x00, 0xC1, 0xFC,
0x45, 0x2D, 0x5B, 0x2D, 0x9E, 0x33, 0x20, 0x00, 0xB0, 0xFC, 0x18, 0x2D, 0x3D, 0x31, 0x00, 0x00,
0x00, 0x00, 0xC4, 0xFC, 0x18, 0x2D, 0x57, 0x30, 0x00, 0x00, 0x08, 0x00, 0xC8, 0xFC, 0x18, 0x2D,
0x55, 0x30, 0x00, 0x00, 0x08, 0x00, 0xB4, 0xFC, 0x18, 0x2D, 0x71, 0x31, 0x00, 0x00, 0x00, 0x00,
0xB6, 0xFC, 0x18, 0x2D, 0x19, 0x32, 0x00, 0x00, 0x00, 0x00, 0xB7, 0xFC, 0x18, 0x2D, 0x43, 0x32,
0x00, 0x00, 0x00, 0x00, 0xB8, 0xFC, 0x18, 0x2D, 0x99, 0x32, 0x00, 0x00, 0x00, 0x00, 0xBC, 0xFC,
0x18, 0x2D, 0xD2, 0x32, 0x00, 0x00, 0x00, 0x00, 0xBD, 0xFC, 0x18, 0x2D, 0x58, 0x33, 0x00, 0x00,
0x00, 0x00, 0xBE, 0xFC, 0x18, 0x2D, 0x82, 0x33, 0x00, 0x00, 0x00, 0x00, 0xBF, 0xFC, 0x18, 0x2D,
0xCF, 0x33, 0x00, 0x00, 0x00, 0x00, 0xB3, 0xFC, 0x45, 0x2D, 0x5B, 0x2D, 0xA0, 0x0F, 0x10, 0x00,
0xB5, 0xFC, 0x45, 0x2D, 0x5B, 0x2D, 0x38, 0x34, 0x02, 0x00, 0xB9, 0xFC, 0x45, 0x2D, 0x5B, 0x2D,
0x3A, 0x34, 0x02, 0x00, 0x90, 0xFD, 0x45, 0x2D, 0x22, 0x2D, 0x3E, 0x34, 0x02, 0x00, 0x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
0x22, 0xFD, 0x76, 0x2D, 0x22, 0x2D, 0x67, 0x40, 0x16, 0x00, 0x23, 0xFD, 0x76, 0x2D, 0x22, 0x2D,
0x72, 0x40, 0x0A, 0x00, 0x45, 0xFD, 0x45, 0x2D, 0x22, 0x2D, 0xFC, 0x00, 0x02, 0x00, 0x47, 0xFD,
0x45, 0x2D, 0x22, 0x2D, 0x72, 0x01, 0x02, 0x00, 0x48, 0xFD, 0x91, 0x2E, 0x22, 0x2D, 0x98, 0x01,
0x02, 0x00, 0x49, 0xFD, 0x91, 0x2E, 0x22, 0x2D, 0x9A, 0x01, 0x02, 0x00, 0x4A, 0xFD, 0x45, 0x2D,
0x22, 0x2D, 0x92, 0x01, 0x02, 0x00, 0x4B, 0xFD, 0x45, 0x2D, 0x22, 0x2D, 0x94, 0x01, 0x02, 0x00,
0x4D, 0xFD, 0x76, 0x2D, 0x22, 0x2D, 0x77, 0x40, 0x0C, 0x00, 0x4F, 0xFD, 0xA5, 0x2E, 0x22, 0x2D,
0x90, 0x32, 0x02, 0x00, 0xC2, 0xFD, 0x9B, 0x2E, 0x22, 0x2D, 0x00, 0x00, 0x02, 0x00, 0x40, 0xFD,
0x6E, 0x2D, 0x22, 0x2D, 0xB6, 0x01, 0x02, 0x00, 0x24, 0xFD, 0xB5, 0x2E, 0x22, 0x2D, 0x00, 0x00,
0x02, 0x00, 0x91, 0xFD, 0x45, 0x2D, 0x22, 0x2D, 0xC6, 0x25, 0x02, 0x00, 0x93, 0xFD, 0x45, 0x2D,
0x22, 0x2D, 0xCC, 0x25, 0x02, 0x00, 0x8F, 0xFD, 0xD5, 0x2E, 0x22, 0x2D, 0x00, 0x00, 0x08, 0x00,
0xC1, 0xFD, 0x00, 0x31, 0x22, 0x2D, 0xFA, 0x00, 0x02, 0x00, 0xC6, 0xFD, 0x45, 0x2D, 0x22, 0x2D,
0xF8, 0x37, 0x04, 0x00, 0x25, 0xFD, 0x45, 0x2D, 0x22, 0x2D, 0x9E, 0x01, 0x02, 0x00, 0x89, 0xFD,
0xB9, 0x30, 0x22, 0x2D, 0x00, 0x00, 0x00, 0x00, 0x8A, 0xFD, 0x93, 0x2D, 0x22, 0x2D, 0x12, 0x34,
0x24, 0x00, 0x41, 0xFD, 0x45, 0x2D, 0x22, 0x2D, 0xBE, 0x33, 0x22, 0x00, 0x42, 0xFD, 0x45, 0x2D,
0x22, 0x2D, 0xFE, 0x00, 0x06, 0x00, 0x43, 0xFD, 0xC2, 0x2E, 0x22, 0x2D, 0x00, 0x00, 0x06, 0x00,
0x44, 0xFD, 0xAC, 0x2E, 0x22, 0x2D, 0xB2, 0x01, 0x02, 0x00, 0x46, 0xFD, 0x21, 0x31, 0x22, 0x2D,
0x00, 0x00, 0x00, 0x00, 0x4C, 0xFD, 0x45, 0x2D, 0x22, 0x2D, 0x46, 0x2F, 0x02, 0x00, 0x50, 0xFD,
0x45, 0x2D, 0x22, 0x2D, 0xF2, 0x00, 0x02, 0x00, 0x51, 0xFD, 0x45, 0x2D, 0x22, 0x2D, 0xF4, 0x00,
0x02, 0x00, 0x52, 0xFD, 0x45, 0x2D, 0x22, 0x2D, 0xC4, 0x01, 0x02, 0x00, 0x8C, 0xFD, 0x38, 0x2D,
0x22, 0x2D, 0x98, 0x34, 0x56, 0x00, 0x8D, 0xFD, 0x38, 0x2D, 0x22, 0x2D, 0xF2, 0x34, 0x14, 0x00,
0x00, 0xF1, 0x46, 0x00, 0xDC, 0x2C, 0x36, 0x01, 0x01, 0xF1, 0x84, 0x07, 0xDA, 0x2C, 0x38, 0x01,
0x00, 0x03, 0xA0, 0x80, 0x1E, 0x00, 0x70, 0x01, 0xFA, 0x00, 0xD4, 0x01, 0xFE, 0x00, 0x3A, 0x01,
0xB6, 0x01, 0xCC, 0x2C, 0x54, 0x01, 0xC6, 0x25, 0x20, 0x00, 0x00, 0x00, 0xC0, 0x1D, 0x00, 0x00,
0xC4, 0x1F, 0x4E, 0x01, 0x0B, 0x00, 0xB8, 0x00, 0xEC, 0x00, 0x44, 0x00, 0x46, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1C, 0x09, 0x08, 0x24, 0x28, 0x06, 0x0C, 0x18, 0x08, 0x30, 0x14, 0x0C,
0x08, 0x36, 0x10, 0x12, 0x24, 0xB7, 0x97, 0xB6, 0xA3, 0xB7, 0xAC, 0xB7, 0xA8, 0xB6, 0x3E, 0xB7,
0x16, 0xB7, 0x79, 0x3E, 0x57, 0x3D, 0x79, 0x3E, 0xF9, 0x3D, 0x5F, 0x3D, 0x52, 0x3D, 0x33, 0x3E,
0x55, 0x3E, 0x6A, 0x3E, 0xAC, 0x3E, 0xD8, 0x3E, 0xF8, 0x3D, 0x22, 0x46, 0x22, 0x46, 0x22, 0x46,
0x22, 0x46, 0x22, 0x46, 0x22, 0x46, 0x22, 0x46, 0x22, 0x46, 0x22, 0x46, 0x22, 0x46, 0x22, 0x46,
0x23, 0x46, 0x23, 0x46, 0x23, 0x46, 0x1C, 0x47, 0x1C, 0x47, 0x1C, 0x47, 0x1C, 0x47, 0x1C, 0x47,
0x1C, 0x47, 0x1C, 0x47, 0x1C, 0x47, 0x1C, 0x47, 0x1C, 0x47, 0x1C, 0x47, 0x1C, 0x47, 0x1C, 0x47,
0x1D, 0x47, 0x9A, 0x48, 0xDA, 0x48, 0x1A, 0x48, 0x5A, 0x48, 0x9A, 0x48, 0xDA, 0x48, 0x1A, 0x48,
0x5A, 0x48, 0x9A, 0x48, 0xDA, 0x48, 0x1A, 0x48, 0x5A, 0x48, 0x9A, 0x48, 0x33, 0x48, 0x78, 0x49,
0x78, 0x49, 0x79, 0x49, 0x79, 0x49, 0x79, 0x49, 0x79, 0x49, 0x7A, 0x49, 0x7A, 0x49, 0x7A, 0x49,
0x7A, 0x49, 0x7B, 0x49, 0x7B, 0x49, 0x7B, 0x49, 0x7C, 0x49, 0xD8, 0x03, 0xDC, 0x03, 0xE0, 0x03,
0xE4, 0x03, 0xF0, 0x03, 0xF4, 0x03, 0xF8, 0x03, 0x0A, 0x04, 0x0E, 0x04, 0x12, 0x04, 0x16, 0x04,
0x0C, 0x04, 0x10, 0x04, 0x14, 0x04, 0x18, 0x04, 0x1C, 0x04, 0x20, 0x04, 0x24, 0x04, 0x28, 0x04,
0x4C, 0x04, 0x50, 0x04, 0x54, 0x04, 0x58, 0x04, 0x5C, 0x04, 0x60, 0x04, 0x64, 0x04, 0x68, 0x04,
0x6C, 0x04, 0x70, 0x04, 0x74, 0x04, 0x7D, 0x04, 0x81, 0x04, 0x85, 0x04, 0x89, 0x04, 0x8D, 0x04,
0x10, 0x00, 0x8E, 0x19, 0xAC, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3C, 0x0C, 0x00, 0x00,
0xFF, 0x3F, 0x44, 0x04, 0x00, 0x00, 0xD3, 0x22, 0x44, 0x04, 0x9C, 0x02, 0xCB, 0x54, 0x44, 0x04,
0x00, 0x00, 0x01, 0x00, 0x44, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0C, 0x71, 0x00, 0x30, 0x50,
0x20, 0x00, 0x80, 0xBF, 0x1F, 0xA6, 0x28, 0x00, 0x0B, 0x02, 0x60, 0x84, 0x4C, 0x00, 0x02, 0x00,
0x4B, 0x1C, 0x98, 0x00, 0x00, 0x00, 0x20, 0x0B, 0x34, 0x04, 0xFD, 0x34, 0x34, 0x00, 0x38, 0x04,
0xFD, 0x34, 0x34, 0x00, 0x3C, 0x04, 0x01, 0x00, 0x10, 0x00, 0x00, 0x08, 0x00, 0x52, 0x14, 0x00,
0x04, 0x08, 0x0E, 0x32, 0x00, 0xA6, 0x10, 0x08, 0xC4, 0x03, 0x50, 0x60, 0x18, 0x08, 0xF0, 0x3F,
0xFC, 0x01, 0x10, 0x0C, 0x00, 0x00, 0x80, 0x04, 0x14, 0x0C, 0x00, 0x00, 0x00, 0x41, 0x20, 0x0C,
0xB0, 0x00, 0xB0, 0xB8, 0x24, 0x0C, 0x00, 0x00, 0xAB, 0x05, 0x2C, 0x0C, 0x80, 0x05, 0x00, 0xFF,
0x30, 0x0C, 0x00, 0x00, 0xB0, 0x04, 0x34, 0x0C, 0x03, 0x00, 0x00, 0xE8, 0x44, 0x0C, 0x04, 0x00,
0xFF, 0x0F, 0x00, 0x10, 0x2E, 0x00, 0x0C, 0xE3, 0x44, 0x04, 0x00, 0x00, 0x01, 0x04, 0x44, 0x04,
0x00, 0x00, 0x01, 0x01, 0x44, 0x04, 0x00, 0x00, 0x01, 0x00, 0x44, 0x04, 0x00, 0x00, 0x01, 0x04,
0x44, 0x04, 0x00, 0x00, 0x80, 0x03, 0x48, 0x0C, 0x00, 0x00, 0x7F, 0x00, 0x04, 0x04, 0x08, 0x48,
0x00, 0x00, 0x04, 0x04, 0x08, 0x40, 0x00, 0x00, 0x00, 0x0C, 0x71, 0x00, 0x30, 0x30, 0x00, 0x00,
0x5E, 0x40, 0x01, 0x00, 0x18, 0x00, 0x36, 0xC0, 0xE8, 0x0E, 0x1C, 0x00, 0x78, 0xC8, 0xA5, 0x40,
0x24, 0x00, 0x9E, 0xB0, 0xB9, 0x95, 0x08, 0x08, 0x00, 0xEA, 0x40, 0x01, 0x0C, 0x08, 0x00, 0xEA,
0x00, 0x00, 0x1C, 0x08, 0x00, 0x00, 0x42, 0x07, 0x20, 0x08, 0x7B, 0x00, 0xD4, 0x09, 0x2C, 0x04,
0x14, 0x00, 0x50, 0x14, 0x30, 0x04, 0x28, 0x0F, 0x28, 0x7F, 0x18, 0x08, 0x20, 0x00, 0xFC, 0x01,
0x04, 0x10, 0x69, 0x00, 0xFD, 0xC3, 0x08, 0x10, 0x69, 0x00, 0xFD, 0xC3, 0x08, 0x0C, 0x00, 0x00,
0x00, 0x00, 0x48, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x48, 0x0C, 0x00, 0x00, 0x7F, 0x00, 0x04, 0x04,
0x08, 0x48, 0x02, 0x00, 0x00, 0x00, 0x5E, 0x48, 0x00, 0x00, 0x04, 0x04, 0x08, 0x40, 0x02, 0x00,
0x00, 0x0C, 0x71, 0x00, 0x30, 0x50, 0x00, 0x00, 0x5E, 0x48, 0x01, 0x00, 0x18, 0x00, 0x3A, 0xC0,
0xE8, 0x04, 0x1C, 0x00, 0x78, 0xD0, 0xA5, 0x40, 0x24, 0x00, 0x9E, 0xB0, 0xB9, 0x85, 0x2C, 0x04,
0x14, 0x00, 0x50, 0x14, 0x30, 0x04, 0x28, 0x0F, 0x28, 0x7F, 0x08, 0x08, 0x00, 0xEA, 0x40, 0x01,
0x0C, 0x08, 0x00, 0xEA, 0x00, 0x00, 0x1C, 0x08, 0x00, 0x00, 0x42, 0x07, 0x20, 0x08, 0x7B, 0x00,
0xD4, 0x09, 0x18, 0x08, 0xF0, 0x3F, 0xFC, 0x01, 0x04, 0x10, 0x69, 0x00, 0xDD, 0xCD, 0x08, 0x10,
0x69, 0x00, 0xDD, 0xCD, 0x08, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x48, 0x0C, 0x00, 0x00, 0x00, 0x00,
0x08, 0x04, 0x40, 0x01, 0x41, 0x01, 0x0C, 0x04, 0x40, 0x04, 0x41, 0x04, 0x10, 0x04, 0xD6, 0x08,
0x56, 0x0A, 0x14, 0x04, 0x42, 0x02, 0x56, 0x0A, 0x18, 0x04, 0x56, 0x0A, 0x40, 0x02, 0x1C, 0x04,
0x42, 0x0A, 0x42, 0x2A, 0x20, 0x04, 0xC2, 0x00, 0xD6, 0x08, 0x24, 0x04, 0xD6, 0x08, 0xC0, 0x00,
0x28, 0x04, 0xC2, 0x08, 0xC2, 0x28, 0x08, 0x04, 0x40, 0x01, 0x41, 0x01, 0x0C, 0x04, 0x00, 0x01,
0x01, 0x01, 0x10, 0x04, 0x56, 0x0A, 0x56, 0x0A, 0x14, 0x04, 0x42, 0x02, 0x56, 0x0A, 0x18, 0x04,
0x56, 0x0A, 0x40, 0x02, 0x1C, 0x04, 0x42, 0x0A, 0x42, 0x2A, 0x20, 0x04, 0x42, 0x02, 0x56, 0x0A,
0x24, 0x04, 0x56, 0x0A, 0x40, 0x02, 0x28, 0x04, 0x42, 0x0A, 0x42, 0x2A, 0x08, 0x04, 0x40, 0x01,
0x41, 0x01, 0x0C, 0x04, 0x40, 0x04, 0x41, 0x04, 0x10, 0x04, 0xCE, 0x08, 0x4E, 0x0A, 0x14, 0x04,
0x42, 0x02, 0x4E, 0x0A, 0x18, 0x04, 0x4E, 0x0A, 0x40, 0x02, 0x1C, 0x04, 0x42, 0x0A, 0x42, 0x2A,
0x20, 0x04, 0xC2, 0x00, 0xCE, 0x08, 0x24, 0x04, 0xCE, 0x08, 0xC0, 0x00, 0x28, 0x04, 0xC2, 0x08,
0xC2, 0x28, 0x08, 0x04, 0x40, 0x01, 0x41, 0x01, 0x0C, 0x04, 0x00, 0x01, 0x01, 0x01, 0x10, 0x04,
0x4E, 0x0A, 0x4E, 0x0A, 0x14, 0x04, 0x42, 0x02, 0x4E, 0x0A, 0x18, 0x04, 0x4E, 0x0A, 0x40, 0x02,
0x1C, 0x04, 0x42, 0x0A, 0x42, 0x2A, 0x20, 0x04, 0x42, 0x02, 0x4E, 0x0A, 0x24, 0x04, 0x4E, 0x0A,
0x40, 0x02, 0x28, 0x04, 0x42, 0x0A, 0x42, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x05, 0x00, 0xA0, 0x16, 0xA0, 0x16,
0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16,
0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16,
0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x16,
0xA0, 0x16, 0xA0, 0x16, 0xA0, 0x17, 0xA0, 0x17, 0xA0, 0x17, 0xA0, 0x18, 0xFF, 0x06, 0xFF, 0x06,
0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06,
0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06,
0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06,
0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x06, 0x00, 0x00, 0x65, 0x00,
0x65, 0x00, 0x65, 0x00, 0x65, 0x00, 0x5D, 0x00, 0x52, 0x00, 0x48, 0x00, 0x40, 0x00, 0x38, 0x00,
0x31, 0x00, 0x2C, 0x00, 0x27, 0x00, 0x23, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x65, 0x00, 0x65, 0x00,
0x65, 0x00, 0x65, 0x00, 0x5D, 0x00, 0x52, 0x00, 0x48, 0x00, 0x40, 0x00, 0x38, 0x00, 0x31, 0x00,
0x2C, 0x00, 0x27, 0x00, 0x23, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x19, 0x00, 0x19, 0x00, 0x19, 0x00,
0x19, 0x00, 0x19, 0x00, 0x19, 0x00, 0x19, 0x00, 0x19, 0x00, 0x19, 0x00, 0x19, 0x00, 0x19, 0x00,
0x19, 0x00, 0x19, 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00,
0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x15, 0x00, 0x6E, 0x6F, 0x6E, 0x2D,
0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x53, 0x53, 0x49, 0x44, 0x20, 0x21,
0x21, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x00, 0x00, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x09,
0x00, 0x00, 0x01, 0x00, 0x64, 0x00, 0x64, 0x00, 0x00, 0x00, 0x48, 0x45, 0x52, 0x4D, 0x45, 0x53,
0x20, 0x32, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00, 0x15, 0x00,
0x6E, 0x6F, 0x6E, 0x2D, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x53, 0x53,
0x49, 0x44, 0x20, 0x21, 0x21, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x01, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x00, 0x09, 0x00, 0x00, 0x01, 0x00, 0x64, 0x00, 0x64, 0x00, 0x00, 0x00, 0x48, 0x45,
0x52, 0x4D, 0x45, 0x53, 0x20, 0x32, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x69,
0x72, 0x73, 0x74, 0x20, 0x57, 0x61, 0x76, 0x65, 0x4C, 0x41, 0x4E, 0x20, 0x49, 0x49, 0x20, 0x53,
0x53, 0x49, 0x44, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x0F, 0xF0, 0x0F,
0x0F, 0x00, 0x50, 0x01, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00,
0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x24, 0x00, 0xFF, 0x00, 0x09, 0x00, 0x09, 0x00, 0x09, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0A, 0x00,
0x0B, 0x00, 0x0B, 0x00, 0x14, 0x00, 0x14, 0x00, 0x14, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x02, 0x01,
0x02, 0x04, 0x0B, 0x16, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x82, 0x84, 0x8B, 0x96, 0x00, 0x00,
0x00, 0x00, 0x1C, 0x85, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00,
0x00, 0x00, 0x03, 0x00, 0x20, 0x00, 0x1B, 0x00, 0x17, 0x00, 0x11, 0x00, 0x10, 0x00, 0x0B, 0x00,
0x0B, 0x00, 0x09, 0x00, 0x17, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0D, 0x00, 0x0B, 0x00, 0x09, 0x00,
0x08, 0x00, 0x07, 0x00, 0x0D, 0x00, 0x0A, 0x00, 0x09, 0x00, 0x08, 0x00, 0x05, 0x00, 0x05, 0x00,
0xD8, 0x0C, 0xC0, 0x08, 0x90, 0x0D, 0x60, 0x09, 0x48, 0x0E, 0x30, 0x0A, 0x24, 0x0F, 0x18, 0x0B,
0x0B, 0x6E, 0x0B, 0x37, 0x02, 0x14, 0x01, 0x0A, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x03, 0x00,
0x07, 0x00, 0x07, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x43, 0x75, 0x72, 0x72, 0x65,
0x6E, 0x74, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, 0x53, 0x65, 0x74, 0x20, 0x49,
0x64, 0x65, 0x6E, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x20, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x30, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xDD, 0x00, 0x50,
0xF2, 0x01, 0x01, 0x00, 0x00, 0x50, 0xF2, 0x05, 0x02, 0x00, 0x00, 0x50, 0xF2, 0x02, 0x00, 0x50,
0xF2, 0x04, 0x02, 0x00, 0x00, 0x50, 0xF2, 0x00, 0x00, 0x50, 0xF2, 0x01, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x15, 0x00, 0x14, 0x00, 0x15, 0x00, 0x36, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x14, 0x00,
0x11, 0x00, 0x36, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x10, 0x00, 0xBE, 0x33, 0x1E, 0x33, 0xCC, 0x35, 0xD0, 0x35, 0xD4, 0x35, 0x12, 0x34,
0x04, 0x36, 0x08, 0x36, 0xF2, 0x33, 0x00, 0x00, 0x00, 0x00, 0x24, 0x2F, 0x14, 0x33, 0x08, 0x36,
0xFF, 0xFF, 0x00, 0x00, 0xBE, 0x33, 0x1E, 0x33, 0xCC, 0x35, 0xD0, 0x35, 0xD4, 0x35, 0x12, 0x34,
0x04, 0x36, 0x08, 0x36, 0xF2, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0xBE, 0x33, 0x14, 0x33, 0x08, 0x36, 0x5C, 0x34, 0x2A, 0x33, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x00, 0x02, 0x06, 0x00, 0x00, 0x06, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2A,
0x00, 0x00, 0x08, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDD, 0x00, 0x30, 0x00, 0xFF, 0xFF, 0x1D, 0xFA,
0xF9, 0xF9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x19, 0x0A,
0x09, 0x46, 0x1C, 0x60, 0x18, 0x00, 0x19, 0x1D, 0x09, 0x42, 0x1C, 0x60, 0x00, 0x00,
}; /* fw_image_2_data */
static const hcf_8 fw_image_3_data[] = {
0x2A, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x08, 0x26, 0x1A, 0x00, 0x80, 0x3A, 0x15, 0x00, 0x7F, 0xF1,
0x32, 0xF2, 0x33, 0xF2, 0xD0, 0x80, 0x80, 0xF1, 0x0F, 0x02, 0xD0, 0x80, 0x34, 0xF2, 0x81, 0xF1,
0x0B, 0x02, 0xD0, 0x80, 0xFF, 0xFF, 0x08, 0x02, 0xE9, 0x60, 0x58, 0x4F, 0x30, 0x78, 0xFF, 0xFF,
0x24, 0x60, 0x58, 0x4F, 0xE3, 0x78, 0xFF, 0xFF, 0x1C, 0x60, 0xD7, 0x78, 0xFF, 0xFF, 0x00, 0xF4,
0xAA, 0x60, 0xAA, 0x65, 0x09, 0xF2, 0x5A, 0xD0, 0xD4, 0x80, 0x03, 0x64, 0x12, 0x02, 0xD0, 0x80,
0x1D, 0x60, 0x60, 0x65, 0x0E, 0x02, 0x5A, 0xD2, 0xFF, 0xFF, 0xD4, 0x80, 0x01, 0x60, 0x00, 0x65,
0x08, 0x02, 0x5A, 0xD2, 0xFF, 0xFF, 0xD4, 0x80, 0xFF, 0xFF, 0x03, 0x02, 0x1C, 0x60, 0xD7, 0x78,
0xFF, 0xFF, 0x00, 0x60, 0xEA, 0xF1, 0x5A, 0xD1, 0x44, 0x48, 0x5A, 0xD1, 0x44, 0x4A, 0x26, 0x46,
0x3F, 0xF2, 0x00, 0xF4, 0x44, 0x4C, 0xD8, 0x83, 0x70, 0x61, 0x68, 0x65, 0xD7, 0x80, 0xFF, 0xFF,
0x07, 0x0E, 0x08, 0xF2, 0x08, 0x00, 0x68, 0x65, 0xD7, 0x80, 0xFF, 0xFF, 0x01, 0x0E, 0x03, 0x00,
0x1C, 0x60, 0xED, 0x78, 0xFF, 0xFF, 0x58, 0x4F, 0x79, 0x00, 0x9C, 0x80, 0x01, 0x65, 0x02, 0x02,
0x00, 0x65, 0x02, 0x00, 0xFF, 0x3B, 0xF7, 0x01, 0x58, 0x4F, 0x70, 0x00, 0x9C, 0x80, 0x45, 0x42,
0xEA, 0x02, 0x58, 0x4F, 0x6B, 0x00, 0x9C, 0x80, 0xFF, 0xFF, 0xE5, 0x02, 0x58, 0x4F, 0x66, 0x00,
0x9C, 0x80, 0xFF, 0xFF, 0x03, 0x02, 0x00, 0x65, 0x45, 0x42, 0xF8, 0x01, 0xFF, 0x3A, 0x29, 0x00,
0x60, 0x47, 0xFF, 0xB5, 0x28, 0x44, 0xFF, 0xB4, 0x94, 0x80, 0xFF, 0xFF, 0xD4, 0x02, 0x60, 0x45,
0x28, 0x47, 0x2A, 0x5F, 0x40, 0x48, 0x2A, 0x47, 0x2C, 0x5F, 0x40, 0x4A, 0x2C, 0x47, 0x65, 0x5F,
0x40, 0x4C, 0x10, 0x64, 0x40, 0x42, 0x28, 0x45, 0x05, 0x00, 0x58, 0x4F, 0x47, 0x00, 0x94, 0x80,
0x28, 0x45, 0x26, 0x02, 0x58, 0x4F, 0x42, 0x00, 0x94, 0x80, 0x2A, 0x45, 0x21, 0x02, 0x58, 0x4F,
0x3D, 0x00, 0x94, 0x80, 0xFF, 0xFF, 0x1C, 0x02, 0x22, 0x44, 0x4C, 0x82, 0x2C, 0x45, 0x31, 0x03,
0xEC, 0x01, 0x10, 0x65, 0x45, 0x42, 0x28, 0x45, 0x94, 0x80, 0x2A, 0x45, 0x21, 0x02, 0x58, 0x4F,
0x2D, 0x00, 0x94, 0x80, 0x2C, 0x45, 0x1C, 0x02, 0x58, 0x4F, 0x28, 0x00, 0x94, 0x80, 0xFF, 0xFF,
0x17, 0x02, 0x22, 0x44, 0x4C, 0x82, 0x28, 0x45, 0x1C, 0x03, 0x58, 0x4F, 0x1F, 0x00, 0xEC, 0x01,
0x40, 0x4B, 0x28, 0x47, 0x40, 0x48, 0x2A, 0x47, 0x40, 0x4A, 0x2C, 0x47, 0x60, 0x45, 0x2A, 0x5E,
0x40, 0x4C, 0x2A, 0x44, 0x28, 0x5E, 0x40, 0x4A, 0x28, 0x44, 0x65, 0x5E, 0x40, 0x48, 0x2B, 0x44,
0x68, 0x65, 0xD7, 0x80, 0xFF, 0xFF, 0x17, 0x0E, 0x90, 0x01, 0x26, 0x46, 0xD0, 0x60, 0xB5, 0x78,
0xFF, 0xFF, 0xB9, 0xFF, 0x26, 0x46, 0xD0, 0x60, 0xB5, 0x78, 0xFF, 0xFF, 0xC9, 0x81, 0xCB, 0x83,
0x07, 0x1C, 0x01, 0x1D, 0x08, 0x00, 0x00, 0xF4, 0x01, 0xF2, 0xFF, 0xFF, 0xFF, 0xB4, 0xD8, 0x81,
0x5A, 0xD2, 0x2F, 0x58, 0xFF, 0xFF, 0x26, 0x46, 0xD0, 0x60, 0x58, 0x4F, 0xD1, 0x78, 0xFF, 0xFF,
0x01, 0x60, 0xFE, 0x61, 0x00, 0xF4, 0x12, 0x63, 0x6A, 0x64, 0x01, 0x65, 0xBD, 0xD0, 0xC8, 0x84,
0x59, 0xD9, 0xFC, 0x02, 0x65, 0x40, 0x01, 0x3A, 0x05, 0x00, 0x00, 0xF4, 0x00, 0x65, 0x0E, 0x64,
0x04, 0x63, 0xF4, 0x01, 0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 0x48, 0xF1, 0xFF, 0xB5, 0x64, 0x40, 0x02, 0x2B,
0x0B, 0x00, 0x60, 0x40, 0x03, 0x2E, 0x08, 0x00, 0x80, 0x2B, 0x06, 0x00, 0x32, 0x44, 0x00, 0x60,
0x80, 0x63, 0x3C, 0x94, 0x40, 0x52, 0x05, 0x00, 0x32, 0x44, 0xFF, 0x60, 0x7F, 0x63, 0x2C, 0x94,
0x40, 0x52, 0x65, 0x43, 0x16, 0x60, 0xAB, 0xFD, 0x16, 0x60, 0xC2, 0xF1, 0x66, 0x41, 0xA6, 0xF5,
0x3A, 0xF2, 0x64, 0x40, 0x01, 0x36, 0x22, 0x64, 0x3A, 0xFA, 0x61, 0x46, 0x32, 0x45, 0x16, 0x60,
0xCB, 0xF1, 0x10, 0x67, 0xB4, 0x85, 0x64, 0x40, 0x01, 0x2A, 0x94, 0x85, 0x45, 0x52, 0xFF, 0x60,
0xE7, 0x65, 0x32, 0x41, 0xA5, 0x81, 0x16, 0x60, 0xC2, 0xF3, 0x08, 0x65, 0xFF, 0xA0, 0xFF, 0xFF,
0x01, 0x03, 0x07, 0x00, 0x16, 0x60, 0xC4, 0xF3, 0xB5, 0x81, 0x10, 0x65, 0x60, 0x40, 0x01, 0x26,
0xB5, 0x81, 0x41, 0x52, 0x19, 0x60, 0x48, 0xF3, 0x37, 0x60, 0xE6, 0x63, 0xF0, 0x84, 0xF0, 0x84,
0xF0, 0x84, 0x03, 0xB5, 0xF0, 0x84, 0xF0, 0x84, 0x03, 0xB4, 0x65, 0x5C, 0xA3, 0xD9, 0x37, 0x60,
0xE8, 0x63, 0x02, 0xA8, 0xA3, 0xDB, 0x15, 0x02, 0x00, 0x60, 0xC8, 0x64, 0x1B, 0x60, 0xF5, 0xFB,
0x1B, 0x60, 0xF9, 0xFB, 0x07, 0x60, 0xD0, 0x64, 0x1B, 0x60, 0xF6, 0xFB, 0x1B, 0x60, 0xFA, 0xFB,
0x01, 0x60, 0x90, 0x64, 0x1B, 0x60, 0xF7, 0xFB, 0x00, 0x60, 0x64, 0x64, 0x1B, 0x60, 0xF8, 0xFB,
0x06, 0x00, 0x64, 0x64, 0x1B, 0x60, 0xF7, 0xFB, 0x64, 0x64, 0x1B, 0x60, 0xF8, 0xFB, 0x19, 0x60,
0x48, 0xF1, 0x01, 0x64, 0x64, 0x40, 0x40, 0x2A, 0x02, 0x00, 0x1B, 0x60, 0xEE, 0xFB, 0x33, 0x60,
0xBC, 0x61, 0x2D, 0x60, 0x0E, 0x64, 0x20, 0x63, 0x58, 0xD1, 0x59, 0xD9, 0xFD, 0x1F, 0xBA, 0xF1,
0x7E, 0xF9, 0x1A, 0x63, 0x00, 0x60, 0xFC, 0x61, 0x00, 0x64, 0x59, 0xDB, 0xFE, 0x1F, 0x40, 0x40,
0x01, 0x64, 0x85, 0xFB, 0x17, 0x60, 0x14, 0xF3, 0x35, 0x60, 0x36, 0x61, 0xFE, 0xA4, 0xE0, 0x84,
0x04, 0x24, 0x0C, 0x00, 0xE0, 0x84, 0x41, 0x91, 0x1A, 0x60, 0x1F, 0xF3, 0xA1, 0xD1, 0x59, 0xD1,
0xA0, 0x83, 0x1A, 0x60, 0x1B, 0xFD, 0xA0, 0x83, 0x1A, 0x60, 0x1A, 0xFD, 0xE4, 0xF3, 0x7D, 0xFB,
0xCF, 0xF1, 0x10, 0x60, 0xEC, 0x63, 0x2F, 0x18, 0x60, 0x40, 0x01, 0x27, 0x12, 0x00, 0xCC, 0x84,
0x06, 0xA3, 0xFD, 0x02, 0xA3, 0xD3, 0x10, 0x60, 0xF2, 0x63, 0x25, 0x1B, 0x11, 0x60, 0x44, 0x65,
0xA3, 0xD3, 0x06, 0xA3, 0xD7, 0x80, 0x02, 0x1B, 0xFB, 0x04, 0x1D, 0x00, 0xF8, 0xA3, 0xA3, 0xD3,
0x18, 0x00, 0x11, 0x60, 0x60, 0x63, 0x12, 0x60, 0x40, 0x65, 0xA3, 0xD1, 0x08, 0xA3, 0xD0, 0x80,
0xD7, 0x80, 0x02, 0x03, 0xFA, 0x04, 0x0F, 0x00, 0xFA, 0xA3, 0xA3, 0xD3, 0x11, 0x60, 0x62, 0x63,
0x0A, 0x1B, 0xA3, 0xD3, 0x08, 0xA3, 0xD7, 0x80, 0x02, 0x1B, 0xFB, 0x04, 0x04, 0x00, 0xF6, 0xA3,
0xA3, 0xD3, 0xE4, 0xFB, 0x7D, 0xFB, 0x2E, 0x60, 0x2E, 0x64, 0x2D, 0x60, 0x8A, 0x63, 0xA0, 0xD1,
0xA3, 0xD9, 0x64, 0x41, 0x58, 0xD1, 0x5B, 0xD9, 0x7D, 0xF3, 0x66, 0x45, 0xA6, 0xF5, 0x60, 0x40,
0x01, 0x27, 0x08, 0x00, 0x91, 0xFA, 0x61, 0x44, 0xFD, 0x60, 0x58, 0x4E, 0xAC, 0x78, 0xFF, 0xFF,
0x12, 0xFA, 0x07, 0x00, 0x11, 0xF8, 0x64, 0x44, 0xFD, 0x60, 0x58, 0x4E, 0xAC, 0x78, 0xFF, 0xFF,
0x12, 0xFA, 0x65, 0x46, 0x46, 0x48, 0xE2, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x05, 0x3A, 0x03, 0x00,
0x14, 0x60, 0x22, 0x66, 0x11, 0x00, 0x04, 0x3A, 0x03, 0x00, 0x14, 0x60, 0x16, 0x66, 0x0C, 0x00,
0x03, 0x3A, 0x03, 0x00, 0x14, 0x60, 0x0A, 0x66, 0x07, 0x00, 0x02, 0x3A, 0x03, 0x00, 0x13, 0x60,
0xFE, 0x66, 0x02, 0x00, 0x13, 0x60, 0xF2, 0x66, 0x60, 0xFE, 0xA6, 0xD3, 0xDE, 0x86, 0x13, 0x60,
0xDC, 0xFB, 0xA6, 0xD3, 0xDE, 0x86, 0x28, 0x60, 0x29, 0x63, 0xA3, 0xDB, 0x28, 0x60, 0xA1, 0x63,
0xA3, 0xDB, 0xA6, 0xD3, 0xDE, 0x86, 0x13, 0x60, 0xDB, 0xFB, 0xA6, 0xD3, 0xDE, 0x86, 0x27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 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60, 0x0C, 0xF1, 0x00, 0x60, 0x04, 0x64,
0xA0, 0x80, 0x9C, 0x84, 0x05, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x23, 0x60, 0x85, 0x78, 0xFF, 0xFF,
0x00, 0x60, 0x40, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x03, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0xE2, 0x01,
0x00, 0x60, 0x20, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x11, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x20, 0x40,
0x50, 0x27, 0xD8, 0x01, 0xAC, 0xF3, 0xFF, 0xFF, 0xFE, 0xA0, 0xFF, 0xFF, 0x0F, 0x06, 0x6B, 0xF3,
0xFF, 0xFF, 0xEC, 0xA0, 0xDC, 0x84, 0x01, 0x05, 0xA2, 0xDB, 0xCC, 0x01, 0x00, 0x60, 0x10, 0x64,
0xA0, 0x80, 0x9C, 0x84, 0xCF, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x01, 0x00, 0xC3, 0x01, 0x01, 0x64,
0x19, 0x60, 0xF3, 0xFB, 0xDF, 0xF3, 0x29, 0x45, 0xD4, 0x80, 0x6B, 0xF3, 0x03, 0x04, 0x21, 0x60,
0x28, 0x78, 0xFF, 0xFF, 0xEC, 0xA0, 0x00, 0x64, 0x04, 0x04, 0x40, 0x49, 0x21, 0x60, 0x28, 0x78,
0xFF, 0xFF, 0x00, 0x60, 0x64, 0x64, 0x08, 0x60, 0x0D, 0xFB, 0x20, 0x60, 0xFD, 0x64, 0x5A, 0xDB,
0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60, 0x0C, 0xF1, 0x00, 0x60, 0x04, 0x64, 0xA0, 0x80,
0x9C, 0x84, 0x05, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x23, 0x60, 0x85, 0x78, 0xFF, 0xFF, 0x00, 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60, 0xC2, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF,
0x04, 0xFF, 0x22, 0x60, 0x1B, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x74, 0x64, 0x08, 0x60, 0x0D, 0xFB,
0x21, 0x60, 0xD8, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60, 0x0C, 0xF1,
0x00, 0x60, 0x04, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x05, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x23, 0x60,
0x85, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x40, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x03, 0x03, 0xA0, 0x84,
0xA2, 0xDB, 0xB0, 0x01, 0x00, 0x60, 0x20, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x15, 0x03, 0xA0, 0x84,
0xA2, 0xDB, 0x20, 0x40, 0x50, 0x27, 0xA6, 0x01, 0xAC, 0xF3, 0x6B, 0xF3, 0xFE, 0xA0, 0xEC, 0xA0,
0x0A, 0x06, 0x03, 0x04, 0x00, 0x64, 0x55, 0xFB, 0x40, 0x49, 0x6B, 0xF3, 0xFF, 0xFF, 0xEC, 0xA0,
0xDC, 0x84, 0x01, 0x05, 0xA2, 0xDB, 0x96, 0x01, 0x00, 0x60, 0x10, 0x64, 0xA0, 0x80, 0x9C, 0x84,
0x0D, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x1C, 0x60, 0xCE, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64,
0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x21, 0x60, 0x28, 0x78, 0xFF, 0xFF, 0x21, 0x60, 0x9C, 0x78,
0xFF, 0xFF, 0x7D, 0xF3, 0x01, 0x60, 0x00, 0x65, 0xA4, 0x80, 0x24, 0x44, 0xFE, 0xB4, 0x01, 0x03,
0x01, 0xBC, 0x02, 0xB0, 0xFB, 0xB4, 0x01, 0x03, 0x04, 0xBC, 0x40, 0x44, 0xC0, 0xF1, 0x0E, 0x60,
0x63, 0xF9, 0xCF, 0xF3, 0x20, 0x60, 0x20, 0x65, 0x30, 0x1B, 0xA5, 0xD3, 0x24, 0x40, 0x01, 0x26,
0x16, 0x00, 0x60, 0x40, 0x20, 0x26, 0x29, 0x00, 0x01, 0xBC, 0xA5, 0xDB, 0x08, 0x60, 0x1E, 0xF1,
0x00, 0x60, 0x20, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x10, 0x60, 0x00, 0x64, 0x08, 0x60,
0x0D, 0xFB, 0x22, 0x60, 0x5F, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x60, 0x40,
0x10, 0x26, 0x13, 0x00, 0x01, 0xBC, 0xA5, 0xDB, 0x08, 0x60, 0x1E, 0xF1, 0x00, 0x60, 0x40, 0x64,
0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x10, 0x60, 0x00, 0x64, 0x08, 0x60, 0x0D, 0xFB, 0x22, 0x60,
0x5F, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x0D, 0x64, 0x53, 0xFB, 0x22, 0x60,
0x67, 0x64, 0x6A, 0xFB, 0x23, 0x60, 0xF6, 0x78, 0xFF, 0xFF, 0x1C, 0x60, 0xCE, 0x64, 0x13, 0x60,
0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x08, 0x60, 0x0C, 0xF1, 0xFF, 0x60,
0xDF, 0x64, 0xA0, 0x84, 0xA2, 0xDB, 0x86, 0xF1, 0x1B, 0x60, 0xB2, 0x63, 0xD3, 0x80, 0x67, 0xFD,
0x07, 0x02, 0x24, 0x44, 0x04, 0xB0, 0xFF, 0xFF, 0x36, 0x03, 0x05, 0x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
0x08, 0x60, 0x0C, 0xF1, 0x00, 0x60, 0x04, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x05, 0x03, 0xA0, 0x84,
0xA2, 0xDB, 0x23, 0x60, 0x85, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x40, 0x64, 0xA0, 0x80, 0x9C, 0x84,
0x03, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x67, 0x01, 0x00, 0x60, 0x20, 0x64, 0xA0, 0x80, 0x9C, 0x84,
0x15, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x20, 0x40, 0x50, 0x27, 0xE0, 0x01, 0xAC, 0xF3, 0x6B, 0xF3,
0xFE, 0xA0, 0xEC, 0xA0, 0x0A, 0x06, 0x03, 0x04, 0x00, 0x64, 0x55, 0xFB, 0x40, 0x49, 0x6B, 0xF3,
0xFF, 0xFF, 0xEC, 0xA0, 0xDC, 0x84, 0x01, 0x05, 0xA2, 0xDB, 0x4D, 0x01, 0x00, 0x60, 0x10, 0x64,
0xA0, 0x80, 0x9C, 0x84, 0xCB, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x1C, 0x60, 0xCE, 0x64, 0x13, 0x60,
0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x22, 0x60, 0x1B, 0x78, 0xFF, 0xFF,
0x08, 0x60, 0x00, 0x65, 0x20, 0x44, 0x34, 0x80, 0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x20, 0x64,
0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x1C, 0x60, 0xB6, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64,
0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x1C, 0x60, 0xC2, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64,
0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x1C, 0x60, 0xCE, 0x64, 0x13, 0x60, 0x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, 0x80, 0x60, 0x45, 0x02, 0x28, 0x64, 0x45,
0x55, 0xF1, 0x8B, 0x67, 0xD0, 0x80, 0x60, 0x41, 0x02, 0x24, 0x64, 0x41, 0xD5, 0x84, 0x80, 0x65,
0xC4, 0x87, 0x01, 0x05, 0x00, 0x64, 0xFF, 0xB4, 0x40, 0x49, 0x2E, 0x58, 0xFF, 0xFF, 0x08, 0x60,
0x0C, 0xF1, 0x00, 0x60, 0x08, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF,
0x08, 0x60, 0x0C, 0xF1, 0x00, 0x60, 0x10, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x2F, 0x58,
0xFF, 0xFF, 0x08, 0x60, 0x0C, 0xF1, 0x00, 0x60, 0x20, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE,
0x08, 0x60, 0x1B, 0xF1, 0x00, 0x60, 0x40, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x2F, 0x58,
0xFF, 0xFF, 0x26, 0x46, 0x27, 0xF2, 0x70, 0x63, 0x60, 0x40, 0x0A, 0x36, 0x10, 0x00, 0x14, 0x36,
0x14, 0x00, 0x37, 0x36, 0x0E, 0x00, 0x6E, 0x36, 0x0E, 0x00, 0x06, 0x36, 0x04, 0x00, 0x09, 0x36,
0x04, 0x00, 0x18, 0x63, 0x0A, 0x00, 0x30, 0x63, 0x08, 0x00, 0x26, 0x63, 0x06, 0x00, 0xD0, 0x63,
0x04, 0x00, 0x33, 0x63, 0x02, 0x00, 0x21, 0x63, 0x00, 0x00, 0x10, 0x60, 0x0E, 0xFD, 0x26, 0x46,
0x3F, 0xF2, 0x87, 0xF0, 0x00, 0xF4, 0x45, 0x43, 0x03, 0x4B, 0x60, 0x43, 0xF4, 0xA3, 0x00, 0x60,
0x1D, 0x61, 0x00, 0x60, 0x01, 0x65, 0x01, 0x60, 0xFF, 0x64, 0x40, 0x4C, 0xFD, 0x60, 0x58, 0x4E,
0x7A, 0x78, 0xFF, 0xFF, 0x00, 0xBB, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x64, 0x40, 0x4A, 0x60, 0xFE,
0x02, 0x60, 0x00, 0x63, 0xBD, 0xD3, 0xBD, 0xD3, 0x60, 0x41, 0xFE, 0x60, 0x58, 0x4E, 0x2C, 0x78,
0xFF, 0xFF, 0x20, 0xFE, 0x26, 0x46, 0x3F, 0xF2, 0x00, 0xF4, 0x60, 0x43, 0xF4, 0xA3, 0x00, 0x60,
0x1D, 0x61, 0x00, 0x60, 0x32, 0x65, 0x01, 0x60, 0xFF, 0x64, 0x40, 0x4C, 0xFD, 0x60, 0x58, 0x4E,
0x7A, 0x78, 0xFF, 0xFF, 0x00, 0xBB, 0xFF, 0xFF, 0x0B, 0x03, 0x60, 0xFE, 0x02, 0x60, 0x00, 0x63,
0xBD, 0xD3, 0xBD, 0xD3, 0x60, 0x41, 0xFE, 0x60, 0x58, 0x4E, 0x2C, 0x78, 0xFF, 0xFF, 0x20, 0xFE,
0x2A, 0x44, 0xFC, 0x60, 0x58, 0x4E, 0x34, 0x78, 0xFF, 0xFF, 0x26, 0x46, 0x3F, 0xF2, 0x01, 0x60,
0x00, 0x65, 0xF4, 0xA4, 0xD4, 0x80, 0x60, 0x41, 0x02, 0x24, 0x65, 0x41, 0x41, 0x48, 0x00, 0xF4,
0x1E, 0x65, 0x02, 0x60, 0x00, 0x63, 0xA5, 0xD0, 0xDA, 0x85, 0x80, 0x3A, 0x02, 0x00, 0x00, 0xF4,
0x04, 0x65, 0x64, 0x44, 0x00, 0x7F, 0xCD, 0x81, 0xBD, 0xDB, 0x05, 0x03, 0x64, 0x47, 0x00, 0x7F,
0xCD, 0x81, 0xBD, 0xDB, 0xF0, 0x02, 0x02, 0x60, 0x00, 0x63, 0x28, 0x41, 0xBD, 0xD3, 0xBD, 0xD1,
0xFD, 0xA0, 0xFE, 0xA1, 0x07, 0x03, 0x09, 0x06, 0x64, 0x44, 0xE0, 0x85, 0xD1, 0x81, 0xC7, 0x83,
0xF5, 0x07, 0x03, 0x00, 0xA3, 0xD3, 0x0E, 0x60, 0x3C, 0xFB, 0x31, 0x40, 0x06, 0x26, 0x57, 0x00,
0x00, 0x64, 0x6F, 0xFB, 0x02, 0x60, 0x00, 0x63, 0x28, 0x41, 0xBD, 0xD3, 0xBD, 0xD1, 0xFC, 0xA0,
0xFB, 0xA0, 0x09, 0x03, 0x28, 0x03, 0x64, 0x44, 0xE0, 0x85, 0xC7, 0x83, 0xD1, 0x81, 0xFE, 0xA1,
0x46, 0x06, 0xF3, 0x07, 0x44, 0x00, 0xBD, 0xD3, 0xBD, 0xD3, 0x00, 0xB8, 0x6F, 0xFB, 0x6E, 0xFB,
0xBD, 0xD3, 0x3D, 0x02, 0xA3, 0xD3, 0x60, 0x45, 0x60, 0x47, 0xB4, 0x84, 0x60, 0x41, 0x3F, 0xB5,
0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0x71, 0xFB, 0x65, 0x47,
0xE0, 0x84, 0xE0, 0x84, 0x70, 0xFB, 0x64, 0x44, 0xE0, 0x85, 0xFA, 0xA3, 0xC7, 0x83, 0x61, 0x44,
0x0E, 0x60, 0x38, 0xFB, 0xD2, 0x01, 0xBD, 0xD3, 0xA3, 0xD3, 0x00, 0xB8, 0x6D, 0xFB, 0x73, 0xFB,
0x1E, 0x02, 0x85, 0xF1, 0x6F, 0xF3, 0x6C, 0xF9, 0x04, 0x65, 0x60, 0x40, 0x00, 0x3A, 0x06, 0x65,
0x31, 0x44, 0xB4, 0x84, 0x40, 0x51, 0x02, 0x2A, 0x0B, 0x00, 0x08, 0xBC, 0x40, 0x51, 0x71, 0xF3,
0x70, 0xF1, 0x00, 0xB8, 0x64, 0x45, 0x01, 0x03, 0x67, 0x45, 0x65, 0x50, 0xCC, 0x84, 0x72, 0xFB,
0x08, 0x60, 0x15, 0xF1, 0x01, 0x60, 0x00, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x08, 0x60,
0x16, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x80, 0x2A, 0x3F, 0x00, 0x01, 0x64, 0x10, 0x60, 0x0A, 0xFB,
0x26, 0x60, 0x58, 0x4E, 0x65, 0x78, 0xFF, 0xFF, 0x26, 0x46, 0x00, 0xF4, 0x0D, 0xF2, 0x7E, 0xFB,
0x00, 0x64, 0x84, 0xFB, 0x26, 0x46, 0x3F, 0xF2, 0x00, 0xF4, 0x60, 0x43, 0xF4, 0xA3, 0x00, 0x60,
0x1D, 0x61, 0x00, 0x60, 0x07, 0x65, 0x01, 0x60, 0xFF, 0x64, 0x40, 0x4C, 0xFD, 0x60, 0x58, 0x4E,
0x7A, 0x78, 0xFF, 0xFF, 0x00, 0xBB, 0xFF, 0xFF, 0x14, 0x03, 0x02, 0x60, 0x00, 0x65, 0xA5, 0xD3,
0x1C, 0x60, 0xE6, 0x63, 0xFF, 0xB4, 0x01, 0xA4, 0x60, 0x41, 0xA5, 0xD1, 0xDA, 0x85, 0x64, 0x44,
0x00, 0x7F, 0xCD, 0x81, 0xBD, 0xDB, 0x05, 0x03, 0x64, 0x47, 0x00, 0x7F, 0xCD, 0x81, 0xBD, 0xDB,
0xF4, 0x02, 0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x80, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE,
0x32, 0x00, 0x27, 0x60, 0x57, 0x78, 0xFF, 0xFF, 0xDB, 0xF3, 0xFF, 0xFF, 0x03, 0xA8, 0x02, 0xA8,
0x02, 0x03, 0x3E, 0x02, 0xF6, 0x01, 0x08, 0x60, 0x15, 0xF1, 0xFF, 0x60, 0xFB, 0x64, 0xA0, 0x84,
0xA2, 0xDB, 0x1C, 0x60, 0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x02, 0x64, 0x4A, 0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65, 0xA5, 0x80, 0xCF, 0x83, 0x08, 0x02, 0x28, 0x44, 0x60, 0x88, 0x2A, 0x44,
0x70, 0x8A, 0x2C, 0x44, 0x70, 0x8C, 0xF1, 0x81, 0xF5, 0x01, 0xE7, 0xA3, 0x64, 0x44, 0x00, 0xA8,
0x00, 0x62, 0x02, 0x02, 0x00, 0x61, 0x1C, 0x00, 0xE0, 0x84, 0xDE, 0x82, 0xFD, 0x04, 0x42, 0xFE,
0xF8, 0x84, 0x62, 0x45, 0xC7, 0x83, 0x60, 0x45, 0x02, 0xFE, 0xD5, 0x84, 0x02, 0x05, 0x01, 0x05,
0x61, 0x44, 0xCF, 0x83, 0x60, 0x41, 0x08, 0x03, 0x28, 0x44, 0x60, 0x88, 0x2A, 0x44, 0x70, 0x8A,
0x2C, 0x44, 0x70, 0x8C, 0xF1, 0x81, 0xF1, 0x01, 0xCE, 0x82, 0xE9, 0x81, 0xFD, 0x02, 0xF1, 0x81,
0x09, 0xF2, 0xFF, 0xFF, 0x60, 0x47, 0xE8, 0x84, 0xE8, 0x84, 0x5A, 0xD2, 0x3F, 0xB5, 0xE0, 0x84,
0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xB4, 0x84, 0x61, 0x45, 0xD4, 0x84,
0xC0, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x93, 0x10, 0x60, 0x0A, 0xF3, 0xFF, 0xFF,
0x02, 0x18, 0x2E, 0x58, 0xFF, 0xFF, 0x16, 0x65, 0x32, 0x40, 0x80, 0x26, 0x16, 0x65, 0x73, 0x44,
0xD4, 0x93, 0x69, 0xF3, 0x26, 0x46, 0x04, 0xBC, 0xA2, 0xDB, 0x26, 0xF0, 0xFF, 0x67, 0x20, 0x88,
0x64, 0x5F, 0x40, 0x4A, 0x24, 0x60, 0x58, 0x4E, 0x80, 0x78, 0xFF, 0xFF, 0x0A, 0x48, 0x24, 0x60,
0x58, 0x4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 0xFF, 0xFF, 0x02, 0x03,
0x2A, 0xA3, 0xFB, 0x01, 0x63, 0x46, 0x10, 0x60, 0xF2, 0x63, 0x0E, 0x61, 0x60, 0xFE, 0xA6, 0xD1,
0xDE, 0x86, 0x01, 0x64, 0x64, 0x40, 0x7F, 0x36, 0x00, 0x64, 0xA3, 0xDB, 0xDB, 0x83, 0xA3, 0xD9,
0xCD, 0x81, 0x04, 0xA3, 0xF4, 0x02, 0x11, 0x60, 0x62, 0x63, 0x1C, 0x61, 0xA6, 0xD1, 0xDE, 0x86,
0x01, 0x64, 0x64, 0x40, 0x7F, 0x36, 0x00, 0x64, 0xA3, 0xDB, 0xDB, 0x83, 0xA3, 0xD9, 0xCD, 0x81,
0x06, 0xA3, 0xF4, 0x02, 0x20, 0xFE, 0x00, 0x60, 0x60, 0x64, 0x08, 0x60, 0x1F, 0xFB, 0x27, 0x60,
0xE1, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x11, 0x60, 0x44, 0x63, 0x08, 0x60,
0x66, 0xFD, 0x12, 0x60, 0x40, 0x63, 0x08, 0x60, 0x67, 0xFD, 0x00, 0x60, 0x60, 0x64, 0x08, 0x60,
0x1F, 0xFB, 0x27, 0x60, 0xE1, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x28, 0xF3,
0xFF, 0xFF, 0x60, 0x47, 0x0F, 0xB4, 0x98, 0x00, 0xFF, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x04, 0x64,
0x13, 0x60, 0x1C, 0xFB, 0x27, 0x00, 0x0C, 0x64, 0x3F, 0x40, 0x02, 0x2B, 0x23, 0x00, 0x29, 0xF1,
0x13, 0x60, 0x1C, 0xFB, 0x5A, 0xD9, 0x27, 0x60, 0xFD, 0x64, 0x9F, 0xFB, 0xFF, 0xFF, 0x2D, 0xFF,
0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF, 0x29, 0x60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x60, 0x0B, 0xFD, 0xFF, 0xFF, 0x62, 0xFF, 0x28, 0x60, 0x67, 0x63, 0x9F, 0xFD,
0xFF, 0xFF, 0x1A, 0xFF, 0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF, 0xA3, 0x60, 0xF4, 0x63, 0x06, 0x60,
0x0B, 0xFD, 0xFF, 0xFF, 0x62, 0xFF, 0x29, 0xF5, 0x26, 0x60, 0x20, 0x63, 0x25, 0x60, 0xF2, 0x64,
0xBD, 0xDB, 0x66, 0x44, 0xBD, 0xDB, 0x02, 0x64, 0xA3, 0xDB, 0xFF, 0xFF, 0x2B, 0xFF, 0xF9, 0xFE,
0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x68, 0x01, 0x00, 0x36, 0x69, 0x01, 0x01, 0x36, 0x6B, 0x01,
0x02, 0x36, 0x81, 0x01, 0x03, 0x36, 0x8B, 0x01, 0x04, 0x36, 0xC1, 0x01, 0x05, 0x36, 0xBF, 0x01,
0x06, 0x36, 0xF1, 0x01, 0x07, 0x36, 0xBB, 0x01, 0x08, 0x36, 0x8C, 0x01, 0x09, 0x36, 0x0C, 0x00,
0x0A, 0x36, 0x0D, 0x00, 0x0B, 0x36, 0x0E, 0x00, 0x0C, 0x36, 0x17, 0x00, 0x0D, 0x36, 0x0D, 0x00,
0x0E, 0x36, 0x1D, 0x00, 0x0F, 0x36, 0x41, 0x00, 0x02, 0x60, 0x00, 0x64, 0x08, 0x00, 0x04, 0x60,
0x00, 0x64, 0x05, 0x00, 0x00, 0x60, 0x01, 0x64, 0x02, 0x00, 0x20, 0x60, 0x00, 0x64, 0x32, 0x45,
0xB4, 0x85, 0x45, 0x52, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x29, 0x60, 0xDE, 0x63, 0x06, 0x60,
0x0B, 0xFD, 0x62, 0xFF, 0xFF, 0xFF, 0x1A, 0xFF, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x3F, 0x40,
0x02, 0x2B,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x60, 0xC8, 0x78, 0xFF, 0xFF, 0x36, 0x44, 0x00, 0x7F,
0xEE, 0xA0, 0x60, 0x45, 0x05, 0x05, 0x20, 0x60, 0xBA, 0x64, 0x44, 0xD7, 0xFF, 0xFF, 0xFF, 0xFF,
0x78, 0x43, 0x01, 0x61, 0x29, 0x60, 0xEA, 0x78, 0x78, 0x43, 0x01, 0x61, 0x29, 0x60, 0xEA, 0x78,
0x7F, 0x60, 0xC0, 0x64, 0x24, 0x45, 0xA4, 0x80, 0x7F, 0x67, 0x02, 0x61, 0x10, 0x02, 0x10, 0x64,
0x40, 0x40, 0x02, 0x64, 0x40, 0x50, 0x61, 0xFF, 0x3F, 0x40, 0x40, 0x26, 0x04, 0x00, 0x10, 0xE0,
0x46, 0x60, 0x09, 0xE0, 0x00, 0x00, 0x27, 0xF1, 0x00, 0x66, 0x20, 0x78, 0x42, 0xFE, 0x23, 0x58,
0xFF, 0xFF, 0x7F, 0x60, 0xC0, 0x64, 0x24, 0x45, 0xA4, 0x80, 0x7F, 0x67, 0x02, 0x61, 0x1A, 0x02,
0x0E, 0x60, 0xDD, 0xF3, 0x07, 0x7C, 0x20, 0xB5, 0x0C, 0xB5, 0x04, 0x03, 0x03, 0x02, 0xDB, 0xF9,
0x00, 0x67, 0x10, 0x00, 0x00, 0x61, 0x41, 0x56, 0xC7, 0xFE, 0xAD, 0x01, 0x36, 0x47, 0xFF, 0x23,
0x04, 0x00, 0x00, 0x7F, 0x60, 0x41, 0x7F, 0x67, 0x05, 0x00, 0x62, 0xFF, 0x20, 0x44, 0x80, 0xBC,
0x40, 0x40, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x7F, 0x60, 0xC0, 0x64, 0x24, 0x45, 0xA4, 0x80,
0x7F, 0x67, 0x02, 0x61, 0x31, 0x02, 0x0E, 0x60, 0xDD, 0xF3, 0x01, 0x7C, 0x20, 0xB5, 0x0C, 0xB5,
0x03, 0x03, 0x02, 0x02, 0xDB, 0xF9, 0xFF, 0xFF, 0x02, 0x61, 0x41, 0x56, 0xC7, 0xFE, 0x2A, 0x60,
0x1D, 0x78, 0xFF, 0xFF, 0x9D, 0xF1, 0x20, 0x44, 0x64, 0x40, 0xFF, 0x26, 0x1C, 0x00, 0x7F, 0xB4,
0x40, 0x40, 0x5C, 0x5E, 0x82, 0xFF, 0x26, 0x44, 0xFD, 0xB4, 0x40, 0x46, 0x5C, 0x41, 0x87, 0xFF,
0x62, 0xFF, 0x13, 0x60, 0x02, 0xF3, 0xFF, 0xFF, 0x00, 0xA8, 0x60, 0x46, 0x04, 0x03, 0x09, 0xF2,
0x8F, 0xFC, 0xAC, 0x86, 0xFB, 0x01, 0x95, 0xF3, 0xFF, 0xFF, 0x7F, 0xB4, 0x95, 0xFB, 0x06, 0x64,
0x13, 0x60, 0x1C, 0xFB, 0x2D, 0xFF, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x00, 0x67, 0x20, 0x40,
0x80, 0x2A, 0x02, 0x00, 0x7F, 0x67, 0x06, 0x61, 0x60, 0x45, 0x0E, 0x60, 0xDD, 0xF3, 0x61, 0x43,
0x04, 0xB4, 0x24, 0x44, 0x02, 0x03, 0x13, 0xFF, 0x56, 0x01, 0x3F, 0xB4, 0xB4, 0x84, 0xFF, 0x27,
0x05, 0xFD, 0x04, 0xFB, 0x20, 0x40, 0x80, 0x2A, 0x02, 0x00, 0x10, 0x75, 0x05, 0x00, 0x01, 0x64,
0x19, 0x60, 0xF7, 0xFB, 0x08, 0x60, 0x10, 0x75, 0x46, 0x01, 0x25, 0x46, 0x01, 0xF2, 0x08, 0xF0,
0x60, 0x47, 0x03, 0xB4, 0x03, 0xAC, 0x7F, 0x67, 0x03, 0x61, 0x08, 0x02, 0x26, 0x60, 0x20, 0x64,
0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF,
0x24, 0x40, 0x01, 0x2B, 0x49, 0x00, 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 0x36, 0x84, 0xFF,
0x05, 0x36, 0x85, 0xFF, 0x06, 0x36, 0x86, 0xFF, 0x25, 0x44, 0x00, 0x36, 0x44, 0x40, 0x01, 0x36,
0x44, 0x41, 0x02, 0x36, 0x44, 0x42, 0x03, 0x36, 0x44, 0x43, 0x04, 0x36, 0x44, 0x44, 0x05, 0x36,
0x44, 0x45, 0x06, 0x36, 0x44, 0x46, 0x07, 0x36, 0x44, 0x47, 0x08, 0x36, 0x44, 0x48, 0x09, 0x36,
0x44, 0x49, 0x0A, 0x36, 0x44, 0x4A, 0x0B, 0x36, 0x44, 0x4B, 0x0C, 0x36, 0x44, 0x4C, 0x0D, 0x36,
0x44, 0x4D, 0x0E, 0x36, 0x44, 0x4E, 0x0F, 0x36, 0x44, 0x4F, 0x87, 0xFF, 0x21, 0x00, 0x25, 0x44,
0x10, 0x36, 0x44, 0x50, 0x11, 0x36, 0x44, 0x51, 0x12, 0x36, 0x44, 0x52, 0x13, 0x36, 0x44, 0x53,
0x14, 0x36, 0x44, 0x54, 0x15, 0x36, 0x44, 0x55, 0x16, 0x36, 0x44, 0x56, 0x17, 0x36, 0x44, 0x57,
0x18, 0x36, 0x44, 0x58, 0x19, 0x36, 0x44, 0x59, 0x1A, 0x36, 0x44, 0x5A, 0x1B, 0x36, 0x44, 0x5B,
0x1C, 0x36, 0x44, 0x5C, 0x1D, 0x36, 0x44, 0x5D, 0x1E, 0x36, 0x44, 0x5E, 0x1F, 0x36, 0x44, 0x5F,
0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x25, 0x46, 0xB5, 0x60, 0x58, 0x4F, 0xCE, 0x78, 0xFF, 0xFF,
0x03, 0x61, 0x7F, 0x67, 0x0A, 0x02, 0x00, 0xF0, 0x04, 0x64, 0x13, 0x60, 0x10, 0xFB, 0x5A, 0xD9,
0x0A, 0x64, 0x5A, 0xDB, 0xFF, 0xFF, 0x2B, 0xFF, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x40, 0x60,
0xC0, 0x64, 0x24, 0x45, 0xA4, 0x80, 0x7F, 0x67, 0x02, 0x61, 0x12, 0x02, 0x14, 0x64, 0x13, 0x60,
0x1C, 0xFB, 0x00, 0x60, 0x50, 0x63, 0x5A, 0xDD, 0x2C, 0x60, 0x75, 0x64, 0x9F, 0xFB, 0x2D, 0xFF,
0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF, 0x2A, 0xF3, 0x05, 0xFB, 0x2B, 0xF3, 0x06, 0xFB, 0x00, 0x67,
0x23, 0x58, 0xFF, 0xFF, 0x40, 0x60, 0xC0, 0x64, 0x24, 0x45, 0xA4, 0x80, 0x7F, 0x67, 0x02, 0x61,
0x0E, 0x02, 0x16, 0x64, 0x13, 0x60, 0x1C, 0xFB, 0x00, 0x60, 0x50, 0x63, 0x5A, 0xDD, 0x2C, 0x60,
0x90, 0x64, 0x9F, 0xFB, 0x2D, 0xFF, 0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF, 0x00, 0x67, 0x23, 0x58,
0xFF, 0xFF, 0x7F, 0x60, 0xC0, 0x64, 0x24, 0x45, 0xA4, 0x80, 0x02, 0x61, 0x38, 0x02, 0x25, 0x45,
0x20, 0x44, 0x80, 0x2A, 0x34, 0x00, 0xF1, 0x60, 0x00, 0x64, 0xD4, 0x80, 0xFF, 0xFF, 0x06, 0x03,
0xF1, 0x60, 0x02, 0x64, 0xD4, 0x80, 0xFF, 0xFF, 0x2F, 0x03, 0x28, 0x00, 0x19, 0x60, 0x40, 0xF1,
0xB7, 0xF3, 0x20, 0x60, 0x22, 0x61, 0xA0, 0x84, 0xA1, 0xDB, 0x25, 0x45, 0x25, 0x60, 0x86, 0x63,
0x02, 0x61, 0xBD, 0xD3, 0xBD, 0xD1, 0xD4, 0x80, 0xBD, 0xD3, 0xBD, 0xD5, 0xCD, 0x81, 0x02, 0x03,
0x15, 0x03, 0xF7, 0x01, 0xA2, 0xFF, 0xA6, 0xD3, 0x40, 0x4C, 0x00, 0xA8, 0x67, 0x43, 0x0C, 0x02,
0xA2, 0xDD, 0x42, 0x48, 0x64, 0x41, 0xB6, 0x60, 0x58, 0x4D, 0x25, 0x78, 0xFF, 0xFF, 0x66, 0x44,
0x28, 0xDB, 0x02, 0x03, 0x2C, 0x58, 0xA3, 0xFF, 0x0C, 0x61, 0x03, 0x00, 0x04, 0x61, 0x7F, 0x67,
0x01, 0x00, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x01, 0x64, 0x10, 0x60, 0x13, 0xFB, 0xFF, 0xFF,
0xC4, 0xFE, 0xF7, 0x01, 0xC6, 0xFE, 0xF5, 0x01, 0x7E, 0x60, 0xC0, 0x64, 0x24, 0x45, 0xA4, 0x80,
0x02, 0x61, 0x3F, 0x02, 0x25, 0x45, 0xF8, 0x2B, 0x3B, 0x00, 0x2E, 0xF5, 0x67, 0x44, 0xD4, 0x80,
0x20, 0x60, 0xCC, 0x63, 0x39, 0x03, 0x79, 0x61, 0x24, 0x44, 0x01, 0x27, 0x29, 0x00, 0xA3, 0xFC,
0xA4, 0xF8, 0xBD, 0xD3, 0xA3, 0xD1, 0xD4, 0x80, 0xCD, 0x81, 0x08, 0x24, 0x64, 0x58, 0x08, 0xA3,
0xF8, 0x02, 0x08, 0x60, 0x00, 0x63, 0xBD, 0xD3, 0xA3, 0xD1, 0xFE, 0xA0, 0xFA, 0x60, 0x00, 0x64,
0xD0, 0x80, 0x14, 0x02, 0x13, 0x02, 0x04, 0xA3, 0xBE, 0xD3, 0xBD, 0xD1, 0x0F, 0x18, 0xD4, 0x80,
0x0D, 0x18, 0x03, 0x03, 0xC3, 0x83, 0xC3, 0x83, 0xF7, 0x01, 0x64, 0x41, 0xDD, 0x81, 0xE1, 0x81,
0xCB, 0x83, 0x46, 0x65, 0x36, 0x60, 0x58, 0x4F, 0x22, 0x78, 0xFF, 0xFF, 0x00, 0x67, 0x0A, 0x00,
0xBD, 0xD3, 0xBE, 0xD1, 0xD4, 0x80, 0xCD, 0x81, 0x08, 0x24, 0x64, 0x58, 0x08, 0xA3, 0xF8, 0x02,
0x04, 0x61, 0x7F, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x0F, 0x64, 0x23, 0xFA, 0x67, 0x44, 0x24, 0xFA,
0x62, 0x41, 0x3C, 0x60, 0x00, 0x65, 0x1A, 0x63, 0x80, 0x60, 0x9E, 0x64, 0x65, 0x46, 0x58, 0xD0,
0x2E, 0xF5, 0x59, 0xD8, 0xFB, 0x1F, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0xCB, 0x83, 0xBF, 0xD1,
0x4A, 0x65, 0x64, 0x43, 0xBD, 0xD3, 0xFF, 0xFF, 0x60, 0x41, 0x01, 0x26, 0xDC, 0x81, 0xE9, 0x84,
0xDC, 0x84, 0x23, 0xFA, 0x09, 0x00, 0x4B, 0xD3, 0xFF, 0xFF, 0x60, 0x41, 0xE8, 0x84, 0xDC, 0x84,
0x23, 0xFA, 0xBF, 0xD1, 0x4A, 0x65, 0x64, 0x43, 0x36, 0x60, 0x58, 0x4F, 0x22, 0x78, 0xFF, 0xFF,
0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x25, 0xF2, 0xFF, 0xFF, 0xE0, 0xA0, 0x20, 0x64, 0x01, 0x06,
0x25, 0xFA, 0x23, 0xF2, 0xDF, 0xD1, 0xCC, 0x84, 0xE0, 0x85, 0x0B, 0x06, 0xBF, 0xD1, 0x64, 0x41,
0xD5, 0x80, 0x64, 0x43, 0x01, 0x06, 0x65, 0x41, 0x4A, 0x65, 0x2E, 0x60, 0x58, 0x4F, 0x7A, 0x78,
0xFF, 0xFF, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0xDB, 0xF3, 0x02, 0x63, 0x23, 0xFC, 0x07, 0xB4,
0x25, 0xFA, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x4B, 0xD3, 0xBF, 0xD3, 0x60, 0x41, 0xC9, 0x83,
0xE9, 0x81, 0xDD, 0x81, 0xA3, 0xFA, 0xE0, 0x81, 0x3C, 0x60, 0x00, 0x67, 0x02, 0x24, 0x02, 0xA4,
0x60, 0x47, 0x40, 0x4B, 0xC9, 0x81, 0x4A, 0x65, 0xAB, 0x46, 0x59, 0xD0, 0xAB, 0x46, 0xA5, 0xD8,
0xDA, 0x85, 0x80, 0x3A, 0x02, 0x00, 0x00, 0xF4, 0x04, 0x65, 0xF6, 0x1F, 0x00, 0x67, 0x23, 0x58,
0xFF, 0xFF, 0xFC, 0xA3, 0xA3, 0xD1, 0x4C, 0x65, 0xA4, 0xD3, 0xDA, 0x83, 0x60, 0x47, 0x25, 0xFA,
0x00, 0x7E, 0x60, 0x47, 0x01, 0x26, 0xDC, 0x84, 0x60, 0x41, 0xE8, 0x84, 0xD8, 0x84, 0x23, 0xFA,
0xAB, 0x01, 0xFC, 0xA3, 0xA3, 0xD1, 0x4C, 0x65, 0xA4, 0xD3, 0xDA, 0x83, 0x00, 0x7F, 0x25, 0xFA,
0x60, 0x41, 0x01, 0x26, 0xDD, 0x81, 0xE9, 0x84, 0xD8, 0x84, 0x23, 0xFA, 0x9D, 0x01, 0x2E, 0x60,
0x40, 0x63, 0xBF, 0xD3, 0xFF, 0xFF, 0x60, 0x41, 0xE8, 0x84, 0xDC, 0x84, 0x23, 0xFA, 0x4A, 0x65,
0x36, 0x60, 0x58, 0x4F, 0x22, 0x78, 0xFF, 0xFF, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x2E, 0x60,
0x40, 0x63, 0x23, 0xF2, 0xC0, 0x65, 0xCC, 0x84, 0xE0, 0x81, 0x0A, 0x04, 0xBF, 0xDB, 0xD5, 0x80,
0x07, 0x03, 0x01, 0x06, 0x65, 0x41, 0x61, 0x44, 0xBF, 0xDB, 0x4A, 0x65, 0x58, 0x4F, 0xA8, 0x00,
0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x03, 0x4E, 0x2D, 0x60, 0x58, 0x43, 0x55, 0x78, 0xFF, 0xFF,
0x2F, 0x60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DC, 0x84, 0x25, 0xFA, 0x00, 0x67, 0x23, 0x58,
0xFF, 0xFF, 0x02, 0x64, 0x23, 0xFA, 0x01, 0x64, 0x9D, 0xFE, 0x02, 0x28, 0x02, 0x64, 0x25, 0xFA,
0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x02, 0x7C, 0x23, 0xF8, 0x01, 0x64, 0x25, 0xFA, 0x00, 0x67,
0x23, 0x58, 0xFF, 0xFF, 0xFC, 0xA3, 0xA3, 0xD1, 0x02, 0x64, 0x23, 0xFA, 0xA4, 0xD3, 0x25, 0xFA,
0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x02, 0x64, 0x23, 0xFA, 0x88, 0xFF, 0x75, 0x44, 0x8D, 0xFF,
0xE8, 0x87, 0xE8, 0x84, 0xE8, 0x84, 0x03, 0xB4, 0x25, 0xFA, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF,
0x04, 0x64, 0x23, 0xFA, 0x86, 0xFF, 0x29, 0x44, 0x87, 0xFF, 0x25, 0xFA, 0x55, 0xF3, 0x52, 0xF1,
0x80, 0x65, 0xC4, 0x87, 0x00, 0x7F, 0x26, 0xFA, 0x64, 0x44, 0xC4, 0x87, 0x00, 0x7F, 0x27, 0xFA,
0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x05, 0x64, 0x23, 0xFA, 0x52, 0x63, 0xB4, 0xF3, 0x4B, 0xDA,
0xB3, 0xF3, 0x4B, 0xDA, 0xB2, 0xF3, 0x4B, 0xDA, 0x60, 0x41, 0x88, 0xFF, 0x72, 0x5C, 0x89, 0xFF,
0x4A, 0xD8, 0xA2, 0x48, 0x20, 0x23, 0x0E, 0x00, 0x64, 0x40, 0x80, 0x27, 0x15, 0x00, 0xDC, 0x84,
0xBD, 0xDA, 0xBD, 0xD2, 0x11, 0x04, 0xDC, 0x84, 0xA2, 0xDA, 0xA3, 0xD2, 0x0D, 0x04, 0xDC, 0x84,
0xA3, 0xDA, 0x0A, 0x00, 0x52, 0x63, 0xB4, 0xF3, 0x4B, 0xDA, 0xB3, 0xF3, 0x4B, 0xDA, 0xB2, 0xF3,
0x4B, 0xDA, 0x54, 0x90, 0x4C, 0x63, 0xE0, 0x02, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x25, 0xF0,
0x23, 0xF2, 0x19, 0x60, 0x46, 0xF9, 0x02, 0xA8, 0x64, 0x44, 0x1F, 0x02, 0x3F, 0x40, 0x02, 0x2B,
0x16, 0x00, 0x00, 0x37, 0x14, 0x00, 0x01, 0x3B, 0x18, 0x00, 0x12, 0x60, 0x45, 0x65, 0x11, 0x60,
0x65, 0x63, 0xFF, 0xB7, 0x60, 0x5C, 0xA3, 0xD3, 0x08, 0xA3, 0x00, 0x7E, 0xD0, 0x80, 0xD7, 0x80,
0x03, 0x03, 0xF9, 0x02, 0x7F, 0x67, 0x0A, 0x00, 0xF4, 0xA3, 0xA3, 0xD1, 0x04, 0x00, 0x00, 0xBC,
0xF2, 0xA4, 0x03, 0x03, 0x02, 0x07, 0x16, 0x60, 0xCF, 0xF9, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF,
0x20, 0x63, 0x2E, 0x60, 0x00, 0x61, 0x48, 0x64, 0x58, 0xD0, 0x59, 0xD9, 0xFD, 0x1F, 0x25, 0xF0,
0x20, 0x64, 0xD0, 0x81, 0xFF, 0xFF, 0x02, 0x07, 0x25, 0xFA, 0x0F, 0x00, 0x2E, 0x60, 0x04, 0x63,
0xC3, 0x83, 0x01, 0x2A, 0x06, 0x00, 0xCF, 0x83, 0xA3, 0xD3, 0xCD, 0x81, 0x00, 0x7F, 0xBD, 0xDB,
0x04, 0x03, 0x00, 0x64, 0xC9, 0x81, 0xBD, 0xDB, 0xFD, 0x02, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF,
0x23, 0xF2, 0x25, 0xF0, 0x02, 0xA8, 0x01, 0x60, 0xA0, 0x62, 0x09, 0x02, 0xA2, 0xD9, 0x64, 0x41,
0x32, 0x44, 0x02, 0xB5, 0x00, 0xB9, 0xD4, 0x84, 0x08, 0x28, 0x02, 0xBC, 0x40, 0x52, 0x00, 0x67,
0x23, 0x58, 0xFF, 0xFF, 0x23, 0xF2, 0x25, 0xF0, 0x02, 0xA8, 0x01, 0x60, 0xA2, 0x62, 0x09, 0x02,
0xA2, 0xD9, 0x64, 0x41, 0x32, 0x44, 0x04, 0xB5, 0x00, 0xB9, 0xD4, 0x84, 0x08, 0x28, 0x04, 0xBC,
0x40, 0x52, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x23, 0xF2, 0x25, 0xF0, 0x02, 0xA8, 0x01, 0x60,
0xB0, 0x62, 0x15, 0x02, 0xA2, 0xD9, 0x64, 0x41, 0x32, 0x44, 0x40, 0xB5, 0x00, 0xB9, 0xD4, 0x84,
0x08, 0x24, 0x0C, 0x00, 0x40, 0xBC, 0x02, 0xB5, 0xD4, 0x84, 0x43, 0xF9, 0x37, 0x60, 0x76, 0x63,
0xD3, 0x80, 0x2F, 0x60, 0x50, 0x7C, 0x02, 0x03, 0x43, 0xFD, 0xA4, 0xDF, 0x40, 0x52, 0x00, 0x67,
0x23, 0x58, 0xFF, 0xFF, 0x37, 0x60, 0x76, 0x64, 0x43, 0xFB, 0x2D, 0x60, 0x5B, 0x78, 0xFF, 0xFF,
0x23, 0xF2, 0x25, 0xF0, 0x01, 0x60, 0xAC, 0x63, 0x7F, 0x67, 0x39, 0x18, 0xA3, 0xD9, 0x26, 0xF0,
0x7F, 0x67, 0x35, 0x18, 0x5B, 0xD9, 0x16, 0x60, 0x87, 0xF3, 0x25, 0xF0, 0x60, 0x40, 0x03, 0x3A,
0x2D, 0x00, 0xA6, 0xF3, 0x20, 0x63, 0xE3, 0x83, 0x60, 0x46, 0x0F, 0xF8, 0x30, 0x61, 0x94, 0xFA,
0x01, 0x61, 0x91, 0xFA, 0x16, 0x64, 0x12, 0xFA, 0x60, 0x40, 0x10, 0x36, 0x05, 0x00, 0x12, 0x36,
0x08, 0x00, 0x0C, 0x36, 0x0B, 0x00, 0x0F, 0x00, 0x40, 0x61, 0xA1, 0x80, 0x0A, 0x64, 0x11, 0x02,
0xF3, 0x01, 0x10, 0x61, 0xA1, 0x80, 0x0E, 0x64, 0x0C, 0x02, 0xEE, 0x01, 0x08, 0x61, 0xA1, 0x80,
0x10, 0x64, 0x07, 0x02, 0xE9, 0x01, 0xE1, 0x81, 0xA1, 0x80, 0x05, 0x05, 0xC8, 0x84, 0x01, 0x02,
0xE3, 0x01, 0x12, 0xFA, 0x91, 0xFA, 0x66, 0x44, 0x02, 0xA6, 0xD7, 0x1F, 0x00, 0x67, 0x23, 0x58,
0xFF, 0xFF, 0x25, 0xF2, 0x19, 0x60, 0x45, 0xFB, 0x19, 0x60, 0x4C, 0xF3, 0xFF, 0xFF, 0x60, 0x40,
0x08, 0x26, 0x18, 0x00, 0x19, 0x60, 0x45, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x2A, 0x0A, 0x00,
0x19, 0x60, 0x7B, 0xF3, 0xFF, 0xFF, 0x02, 0xBC, 0x60, 0x44, 0xA2, 0xDB, 0x19, 0x60, 0x45, 0xF3,
0xFF, 0xFF, 0x60, 0x40, 0x02, 0x2A, 0x06, 0x00, 0x19, 0x60, 0x7B, 0xF3, 0xFF, 0xFF, 0x04, 0xBC,
0x60, 0x44, 0xA2, 0xDB, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x23, 0xF2, 0x25, 0xF0, 0x02, 0xA8,
0x00, 0x67, 0x02, 0x02, 0x2D, 0xF9, 0x2C, 0xF9, 0x23, 0x58, 0xFF, 0xFF, 0x23, 0xF2, 0x25, 0xF2,
0x02, 0xA8, 0x00, 0xA8, 0x0A, 0x02, 0x07, 0x03, 0xD0, 0xA0, 0x30, 0x65, 0x03, 0x04, 0xA7, 0xA0,
0x59, 0x65, 0x01, 0x06, 0x65, 0x44, 0x16, 0x60, 0xCE, 0xFB, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF,
0x25, 0xF2, 0x19, 0x60, 0x4C, 0xFB, 0xFF, 0xFF, 0x08, 0x2A, 0x25, 0x00, 0x19, 0x60, 0x7B, 0xF3,
0xFF, 0xFF, 0xE9, 0xB4, 0x60, 0x44, 0x19, 0x60, 0x4C, 0xF1, 0xFF, 0xFF, 0x64, 0x40, 0x01, 0x26,
0x02, 0xBC, 0x64, 0x40, 0x02, 0x2A, 0x04, 0xBC, 0x64, 0x40, 0x04, 0x26, 0x08, 0x00, 0x19, 0x60,
0x7B, 0xFB, 0x13, 0x64, 0xCB, 0xFB, 0x01, 0x60, 0x67, 0x64, 0x37, 0xFB, 0x0C, 0x00, 0x10, 0xBC,
0x19, 0x60, 0x7B, 0xFB, 0x08, 0x64, 0xCB, 0xFB, 0xA1, 0xF3, 0x01, 0x60, 0x67, 0x7C, 0x60, 0x40,
0x01, 0x27, 0x5B, 0x7C, 0x37, 0xF9, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x25, 0xF2, 0x19, 0x60,
0x4D, 0xFB, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x25, 0xF2, 0x19, 0x60, 0x4E, 0xFB, 0x00, 0x67,
0x23, 0x58, 0xFF, 0xFF, 0x25, 0xF2, 0x19, 0x60, 0x89, 0xFB, 0xFF, 0xFF, 0x0F, 0x22, 0x41, 0x75,
0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x01, 0x64, 0x01, 0x00, 0x00, 0x64, 0x1B, 0x60, 0xFE, 0xFB,
0x7E, 0x60, 0xC0, 0x64, 0x24, 0x45, 0xA4, 0x80, 0x7F, 0x67, 0x02, 0x61, 0x0E, 0x02, 0x06, 0x61,
0x41, 0x56, 0xC7, 0xFE, 0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF, 0x36, 0x47, 0xFF, 0x23, 0x04, 0x00,
0x00, 0x7F, 0x60, 0x41, 0x7F, 0x67, 0x01, 0x00, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x7F, 0x60,
0xC0, 0x64, 0x24, 0x45, 0xA4, 0x80, 0x7F, 0x67, 0x02, 0x61, 0x0E, 0x02, 0x08, 0x61, 0x41, 0x56,
0xC7, 0xFE, 0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF, 0x36, 0x47, 0xFF, 0x23, 0x04, 0x00, 0x00, 0x7F,
0x60, 0x41, 0x7F, 0x67, 0x01, 0x00, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x7F, 0x60, 0xC0, 0x64,
0x24, 0x45, 0xA4, 0x80, 0x7F, 0x67, 0x02, 0x61, 0x0E, 0x02, 0x0A, 0x61, 0x41, 0x56, 0xC7, 0xFE,
0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF, 0x36, 0x47, 0xFF, 0x23, 0x04, 0x00, 0x00, 0x7F, 0x60, 0x41,
0x7F, 0x67, 0x01, 0x00, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x7E, 0x60, 0xC0, 0x64, 0x24, 0x45,
0xA4, 0x80, 0x7F, 0x67, 0x02, 0x61, 0x11, 0x02, 0x65, 0x43, 0x19, 0x60, 0xA5, 0xFD, 0x0C, 0x61,
0x41, 0x56, 0xC7, 0xFE, 0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF, 0x36, 0x47, 0xFF, 0x23, 0x04, 0x00,
0x00, 0x7F, 0x60, 0x41, 0x7F, 0x67, 0x01, 0x00, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x20, 0x64,
0x23, 0xFA, 0x4A, 0x61, 0x10, 0x60, 0xDA, 0x64, 0xA0, 0xD1, 0xA1, 0xD8, 0x58, 0xD1, 0x59, 0xD8,
0x58, 0xD1, 0x59, 0xD8, 0x01, 0xA1, 0x10, 0x60, 0xF2, 0x63, 0x5D, 0x65, 0xA3, 0xD3, 0x02, 0xA3,
0x02, 0x1B, 0x7F, 0x64, 0x01, 0x00, 0xA3, 0xD3, 0x60, 0xFE, 0x5D, 0xDA, 0x20, 0xFE, 0xD5, 0x80,
0x04, 0xA3, 0xF4, 0x02, 0x01, 0xA1, 0x10, 0x60, 0xE0, 0x64, 0xA0, 0xD1, 0xA1, 0xD8, 0x58, 0xD1,
0x59, 0xD8, 0x58, 0xD1, 0x59, 0xD8, 0x01, 0xA1, 0x60, 0xFE, 0x07, 0x63, 0x7F, 0x64, 0xCF, 0x83,
0x5D, 0xDA, 0xFD, 0x02, 0x20, 0xFE, 0x12, 0x60, 0x40, 0x7C, 0x11, 0x60, 0x62, 0x63, 0x7F, 0x65,
0xA3, 0xD3, 0x02, 0xA3, 0x02, 0x1B, 0x7F, 0x64, 0x01, 0x00, 0xA3, 0xD3, 0x60, 0xFE, 0x5D, 0xDA,
0x20, 0xFE, 0xD5, 0x80, 0x06, 0xA3, 0x03, 0x02, 0x46, 0x45, 0x00, 0xF4, 0x03, 0x61, 0xD3, 0x80,
0xFF, 0xFF, 0xEE, 0x04, 0x25, 0x46, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x02, 0x63, 0x7D, 0xF3,
0x23, 0xFC, 0x60, 0x40, 0x01, 0x23, 0x17, 0x00, 0x01, 0x60, 0xFF, 0x65, 0xA4, 0x84, 0x11, 0x60,
0x60, 0x61, 0x12, 0x60, 0x40, 0x65, 0xA1, 0xD1, 0xD5, 0x80, 0xD0, 0x80, 0x0B, 0x03, 0x02, 0x03,
0x08, 0xA1, 0xF9, 0x01, 0x04, 0xA1, 0xA1, 0xD3, 0x01, 0x60, 0x00, 0x65, 0x60, 0x47, 0xFF, 0xB4,
0xB4, 0x84, 0x01, 0x00, 0xFF, 0x64, 0x25, 0xFA, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x0C, 0x63,
0x23, 0xFC, 0xE2, 0xF3, 0x13, 0x60, 0xF2, 0x63, 0xCC, 0x84, 0xFF, 0xFF, 0x02, 0x06, 0x0C, 0xA3,
0xFB, 0x01, 0x48, 0x61, 0x61, 0x44, 0x18, 0xA5, 0x60, 0xFE, 0xBD, 0xD3, 0x20, 0xFE, 0x00, 0x7F,
0x59, 0xDA, 0xD5, 0x80, 0xFF, 0xFF, 0xF8, 0x04, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF, 0x25, 0xF0,
0x17, 0x60, 0x80, 0xF9, 0x11, 0x00, 0x0C, 0x60, 0xFE, 0x62, 0x40, 0x63, 0x5A, 0xDF, 0xFE, 0x1F,
0x04, 0x65, 0x0C, 0x60, 0xFE, 0x61, 0x48, 0x64, 0x3E, 0x63, 0x7C, 0xA8, 0x58, 0xD0, 0x59, 0xD9,
0x02, 0x02, 0x00, 0xF4, 0x02, 0x64, 0xF9, 0x1F, 0x17, 0x60, 0x80, 0xF1, 0x0C, 0x60, 0xDA, 0x65,
0x02, 0xFE, 0x64, 0x44, 0xF8, 0x84, 0xF8, 0x84, 0xF8, 0x87, 0x60, 0x41, 0x64, 0x44, 0xE0, 0x84,
0xE0, 0x84, 0xC4, 0x84, 0x3E, 0xFB, 0x60, 0x42, 0x61, 0x44, 0x03, 0xA2, 0x60, 0xFE, 0xA2, 0xDB,
0x20, 0xFE, 0x64, 0x44, 0x0D, 0x60, 0x00, 0x65, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84,
0xC4, 0x84, 0x40, 0xFB, 0xFF, 0xFF, 0x00, 0x67, 0x00, 0x61, 0x23, 0x58, 0xFF, 0xFF, 0x5C, 0x41,
0x25, 0xF2, 0xFF, 0xFF, 0x40, 0x42, 0x80, 0x2B, 0x04, 0x00, 0xFF, 0xB4, 0x40, 0x42, 0x01, 0x64,
0x40, 0x41, 0xA6, 0xF3, 0x46, 0x4B, 0x60, 0x46, 0x20, 0x63, 0xE3, 0x83, 0xAB, 0x46, 0x26, 0xF0,
0xAB, 0x46, 0x59, 0xF8, 0xAB, 0x46, 0x27, 0xF0, 0xAB, 0x46, 0x5A, 0xF8, 0xAB, 0x46, 0x28, 0xF0,
0xAB, 0x46, 0x5B, 0x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0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD3,
0x66, 0x41, 0x60, 0x46, 0x60, 0x43, 0x05, 0xF2, 0x16, 0x18, 0x61, 0x46, 0x27, 0xF0, 0x63, 0x46,
0xD0, 0x80, 0x04, 0xF2, 0x0C, 0x02, 0x61, 0x46, 0x26, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x03, 0xF2,
0x06, 0x02, 0x61, 0x46, 0x25, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0xFF, 0xFF, 0x07, 0x03, 0x80, 0xF4,
0xFF, 0xFF, 0x63, 0x46, 0xE8, 0x1B, 0xA6, 0xF3, 0x08, 0xFE, 0x60, 0x43, 0x61, 0x46, 0x01, 0x03,
0x2A, 0x00, 0x43, 0x4B, 0xAB, 0x46, 0x3B, 0xF2, 0x80, 0x60, 0x30, 0x7C, 0xB0, 0x84, 0xA2, 0xDA,
0x4E, 0x61, 0x76, 0x64, 0x0E, 0x63, 0xAB, 0x46, 0x59, 0xD0, 0xAB, 0x46, 0x58, 0xD8, 0xFB, 0x1F,
0x90, 0x64, 0x04, 0x63, 0xAB, 0x46, 0x59, 0xD0, 0xAB, 0x46, 0x58, 0xD8, 0xFB, 0x1F, 0xD9, 0x81,
0xA0, 0x64, 0x04, 0x63, 0xAB, 0x46, 0x59, 0xD0, 0xAB, 0x46, 0x58, 0xD8, 0xFB, 0x1F, 0xD9, 0x81,
0xB6, 0x64, 0x0E, 0x63, 0xAB, 0x46, 0x59, 0xD0, 0xAB, 0x46, 0x58, 0xD8, 0xFB, 0x1F, 0x00, 0x67,
0x00, 0x61, 0x23, 0x58, 0xFF, 0xFF, 0x01, 0x67, 0x20, 0x61, 0x23, 0x58, 0xFF, 0xFF, 0x27, 0xF2,
0x1D, 0x60, 0xC0, 0x65, 0x60, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD3, 0x66, 0x41, 0x60, 0x46,
0x60, 0x43, 0x05, 0xF2, 0x16, 0x18, 0x61, 0x46, 0x27, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x04, 0xF2,
0x0C, 0x02, 0x61, 0x46, 0x26, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x03, 0xF2, 0x06, 0x02, 0x61, 0x46,
0x25, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0xFF, 0xFF, 0x07, 0x03, 0x80, 0xF4, 0xFF, 0xFF, 0x63, 0x46,
0xE8, 0x1B, 0xA6, 0xF3, 0x08, 0xFE, 0x60, 0x43, 0x61, 0x46, 0x01, 0x03, 0x0D, 0x00, 0x43, 0x4B,
0xAB, 0x46, 0x3B, 0xF2, 0x80, 0x60, 0x30, 0x61, 0x9D, 0x85, 0xA4, 0x84, 0xA2, 0xDA, 0xAB, 0x46,
0x00, 0x67, 0x00, 0x61, 0x23, 0x58, 0xFF, 0xFF, 0x01, 0x67, 0x20, 0x61, 0x23, 0x58, 0xFF, 0xFF,
0x00, 0x64, 0x40, 0x41, 0x4A, 0x64, 0xA0, 0xD2, 0xFF, 0xFF, 0x40, 0x42, 0x80, 0x2B, 0x04, 0x00,
0xFF, 0xB4, 0x40, 0x42, 0x01, 0x64, 0x40, 0x41, 0xA6, 0xF3, 0x46, 0x4B, 0x60, 0x46, 0x20, 0x63,
0xE3, 0x83, 0xAB, 0x46, 0x32, 0xF0, 0xAB, 0x46, 0x59, 0xF8, 0xAB, 0x46, 0x33, 0xF0, 0xAB, 0x46,
0x5A, 0xF8, 0xAB, 0x46, 0x34, 0xF0, 0xAB, 0x46, 0x5B, 0xF8, 0x66, 0x44, 0x02, 0xA6, 0xF1, 0x1F,
0xA6, 0xF3, 0xFF, 0xFF, 0x60, 0x46, 0xAB, 0x46, 0x0C, 0x60, 0x38, 0x65, 0x22, 0x44, 0xFF, 0xB4,
0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xC4, 0x81, 0xC9, 0x81, 0x4A, 0x64, 0x0E, 0x63,
0x58, 0xD0, 0x59, 0xD9, 0xFD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0xA6, 0xF3, 0xFF, 0xFF, 0x60, 0x46, 0xBB, 0xF4, 0x80, 0x61, 0x02, 0x02, 0xE3, 0x83, 0xEB, 0x83,
0x22, 0x44, 0x88, 0xFF, 0xCC, 0x84, 0xE1, 0x81, 0xFD, 0x0D, 0x8D, 0xFF, 0x61, 0x47, 0x31, 0x91,
0x9D, 0x85, 0xA7, 0x83, 0x3B, 0xFC, 0x1F, 0x63, 0xE3, 0x83, 0x66, 0x44, 0x02, 0xA6, 0xBB, 0xF2,
0x66, 0x44, 0xA5, 0x81, 0xBB, 0xFA, 0x02, 0xA6, 0xFA, 0x1F, 0x00, 0x67, 0x23, 0x58, 0xFF, 0xFF,
0x27, 0xF2, 0x1D, 0x60, 0xC0, 0x65, 0x60, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD3, 0x66, 0x41,
0x60, 0x46, 0x60, 0x43, 0x05, 0xF2, 0x16, 0x18, 0x61, 0x46, 0x27, 0xF0, 0x63, 0x46, 0xD0, 0x80,
0x04, 0xF2, 0x0C, 0x02, 0x61, 0x46, 0x26, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x03, 0xF2, 0x06, 0x02,
0x61, 0x46, 0x25, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0xFF, 0xFF, 0x07, 0x03, 0x80, 0xF4, 0xFF, 0xFF,
0x63, 0x46, 0xE8, 0x1B, 0xA6, 0xF3, 0x08, 0xFE, 0x60, 0x43, 0x61, 0x46, 0x01, 0x03, 0x21, 0x00,
0x43, 0x4B, 0xAB, 0x46, 0x3B, 0xF2, 0x80, 0x60, 0x30, 0x7C, 0xB0, 0x84, 0xA2, 0xDA, 0x4E, 0x61,
0x76, 0x64, 0x0E, 0x63, 0xAB, 0x46, 0x59, 0xD0, 0xAB, 0x46, 0x58, 0xD8, 0xFB, 0x1F, 0x90, 0x64,
0x04, 0x63, 0xAB, 0x46, 0x59, 0xD0, 0xAB, 0x46, 0x58, 0xD8, 0xFB, 0x1F, 0xA0, 0x64, 0x04, 0x63,
0xAB, 0x46, 0x59, 0xD0, 0xAB, 0x46, 0x58, 0xD8, 0xFB, 0x1F, 0x00, 0x67, 0x00, 0x61, 0x23, 0x58,
0xFF, 0xFF, 0x01, 0x67, 0x20, 0x61, 0x23, 0x58, 0xFF, 0xFF, 0x27, 0xF2, 0x1D, 0x60, 0xC0, 0x65,
0x60, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD3, 0x66, 0x41, 0x60, 0x46, 0x60, 0x43, 0x05, 0xF2,
0x16, 0x18, 0x61, 0x46, 0x27, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x04, 0xF2, 0x0C, 0x02, 0x61, 0x46,
0x26, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x03, 0xF2, 0x06, 0x02, 0x61, 0x46, 0x25, 0xF0, 0x63, 0x46,
0xD0, 0x80, 0xFF, 0xFF, 0x07, 0x03, 0x80, 0xF4, 0xFF, 0xFF, 0x63, 0x46, 0xE8, 0x1B, 0xA6, 0xF3,
0x08, 0xFE, 0x60, 0x43, 0x61, 0x46, 0x01, 0x03, 0x0D, 0x00, 0x43, 0x4B, 0xAB, 0x46, 0x3B, 0xF2,
0x80, 0x60, 0x30, 0x61, 0x9D, 0x85, 0xA4, 0x84, 0xA2, 0xDA, 0xAB, 0x46, 0x00, 0x67, 0x00, 0x61,
0x23, 0x58, 0xFF, 0xFF, 0x01, 0x67, 0x20, 0x61, 0x23, 0x58, 0xFF, 0xFF, 0xA2, 0xFF, 0x46, 0x45,
0x02, 0xF0, 0x09, 0x60, 0x08, 0x64, 0xD0, 0x80, 0x00, 0xF4, 0x01, 0xF2, 0x66, 0x5C, 0x25, 0x46,
0x56, 0x02, 0x70, 0x27, 0x54, 0x00, 0x12, 0x64, 0x03, 0xFA, 0x04, 0xF8, 0x0E, 0xF2, 0x87, 0xFC,
0x8D, 0xFC, 0x8E, 0xFC, 0xDA, 0x82, 0x16, 0x61, 0x00, 0x63, 0xC9, 0x81,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xF4, 0x08, 0xF0, 0x25, 0x46, 0x06, 0xB4, 0xFF, 0x7F, 0x10, 0xBC,
0x06, 0x26, 0xFD, 0x7F, 0x0E, 0xFA, 0x3E, 0xF2, 0x3F, 0xF2, 0x60, 0x41, 0x08, 0x2A, 0x64, 0x47,
0x3F, 0xFA, 0x60, 0x45, 0xB9, 0xFC, 0x16, 0x60, 0xAA, 0xF3, 0xA3, 0xFC, 0xAB, 0xFC, 0x91, 0xFC,
0xD4, 0x80, 0x18, 0x60, 0x21, 0x65, 0xA5, 0x80, 0x01, 0x04, 0x07, 0x03, 0x23, 0xF0, 0x08, 0x64,
0xB0, 0x84, 0xA2, 0xDA, 0x35, 0x60, 0xEA, 0x78, 0xFF, 0xFF, 0x36, 0x60, 0x58, 0x4F, 0x30, 0x78,
0xFF, 0xFF, 0x0B, 0x04, 0x23, 0xF0, 0x04, 0x64, 0xB0, 0x84, 0xA2, 0xDA, 0x2C, 0x60, 0xEE, 0x64,
0xF1, 0x60, 0x78, 0x41, 0xE4, 0x78, 0xB5, 0xF1, 0x83, 0x00, 0xDB, 0xF3, 0xA6, 0xF1, 0x07, 0xB4,
0x64, 0x43, 0xFD, 0xA0, 0x2C, 0xF2, 0x71, 0x02, 0x01, 0xB0, 0x64, 0x43, 0x78, 0x02, 0x2E, 0xF2,
0x1D, 0x60, 0xC0, 0x65, 0x60, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD3, 0x66, 0x41, 0x60, 0x46,
0x60, 0x43, 0x05, 0xF2, 0x16, 0x18, 0x61, 0x46, 0x2E, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x04, 0xF2,
0x0C, 0x02, 0x61, 0x46, 0x2D, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x03, 0xF2, 0x06, 0x02, 0x61, 0x46,
0x2C, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0xFF, 0xFF, 0x07, 0x03, 0x80, 0xF4, 0xFF, 0xFF, 0x63, 0x46,
0xE8, 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xDC, 0x64, 0xD0, 0x80, 0x00, 0x64,
0x01, 0x06, 0x01, 0x64, 0x40, 0x4E, 0xB2, 0xF1, 0x66, 0x41, 0xE1, 0x81, 0xE1, 0x81, 0xE1, 0x81,
0xE1, 0x81, 0x61, 0x46, 0x73, 0x42, 0x5A, 0x92, 0x3F, 0x64, 0xA0, 0x84, 0x60, 0x47, 0xE0, 0x84,
0xE0, 0x85, 0x62, 0x47, 0xE8, 0x84, 0xE8, 0x84, 0x3F, 0xB4, 0x60, 0x41, 0x64, 0x44, 0x14, 0x90,
0x3F, 0x26, 0xCC, 0x84, 0x14, 0x90, 0x3F, 0x26, 0xCC, 0x84, 0x62, 0x41, 0x60, 0x55, 0xB2, 0xFB,
0x72, 0x5C, 0x67, 0x42, 0xD2, 0x80, 0xA2, 0x48, 0x20, 0x2B, 0x05, 0x00, 0x01, 0x02, 0x7C, 0x5C,
0x04, 0x60, 0x00, 0x64, 0xC4, 0x85, 0xE8, 0xE2, 0xE4, 0xE2, 0x61, 0x42, 0x49, 0x91, 0x64, 0x44,
0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xB4, 0x84, 0x60, 0x45,
0x51, 0x94, 0x04, 0x60, 0x00, 0x61, 0x01, 0x0D, 0x44, 0x94, 0x62, 0x41, 0x19, 0x60, 0xF5, 0xF1,
0x61, 0x42, 0x64, 0x43, 0xCF, 0x83, 0xCF, 0x83, 0x03, 0x03, 0xE3, 0x83, 0x48, 0x94, 0xFE, 0x1F,
0x2E, 0x40, 0x01, 0x26, 0xE0, 0x84, 0x60, 0x41, 0xE9, 0x81, 0xE9, 0x81, 0xE9, 0x81, 0xE9, 0x81,
0x44, 0x94, 0xE9, 0x81, 0xE9, 0x81, 0x54, 0x94, 0xE9, 0x81, 0xE9, 0x81, 0xE9, 0x81, 0x44, 0x94,
0xE9, 0x81, 0xE9, 0x81, 0xE9, 0x81, 0x54, 0x94, 0x19, 0xE2, 0x2E, 0x40, 0x01, 0x26, 0xE8, 0x84,
0x29, 0x61, 0x54, 0x91, 0x61, 0x43, 0x11, 0x06, 0x75, 0x44, 0x80, 0x2B, 0xAB, 0xFF, 0x80, 0x27,
0x0C, 0x00, 0x14, 0xE0, 0x94, 0xE0, 0x34, 0xE2, 0x61, 0x5A, 0x48, 0x21, 0xFE, 0x01, 0x00, 0xE0,
0x7A, 0x43, 0x15, 0xA1, 0x75, 0x40, 0x80, 0x2B, 0x06, 0xA1, 0x5D, 0x91, 0x61, 0x44, 0x2E, 0x40,
0x01, 0x26, 0xE0, 0x84, 0x60, 0x43, 0xEB, 0x83, 0xEB, 0x83, 0xEB, 0x83, 0x89, 0xFF, 0x10, 0xE0,
0x80, 0x60, 0x00, 0x75, 0x88, 0xFF, 0xEB, 0x83, 0xEB, 0x83, 0x5C, 0x94, 0xEB, 0x83, 0x5C, 0x94,
0xEB, 0x83, 0xEB, 0x83, 0xEB, 0x83, 0xEB, 0x83, 0xEB, 0x83, 0x4C, 0x94, 0x2E, 0x40, 0x01, 0x26,
0xE8, 0x84, 0x60, 0x43, 0x65, 0x41, 0x62, 0x45, 0xD5, 0x85, 0x04, 0x60, 0x00, 0x61, 0x01, 0x0D,
0xC5, 0x85, 0xC4, 0x84, 0x60, 0x43, 0x62, 0x41, 0xE1, 0x81, 0xE1, 0x81, 0xE1, 0x81, 0xE1, 0x81,
0xE1, 0x81, 0xE1, 0x9C, 0x00, 0x61, 0xDD, 0x81, 0x58, 0x94, 0x4A, 0x92, 0xFC, 0x05, 0x41, 0x4F,
0x00, 0x61, 0x62, 0x45, 0x1C, 0x60, 0x0A, 0xF3, 0xE3, 0x83, 0xF1, 0x81, 0xE3, 0x83, 0xF1, 0x81,
0xE3, 0x83, 0xF1, 0x81, 0xE3, 0x83, 0xF1, 0x81, 0xE3, 0x83, 0xF1, 0x81, 0xE3, 0x83, 0xF1, 0x81,
0xA0, 0x52, 0xB2, 0xF3, 0xC3, 0x9C, 0x44, 0x94, 0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,
0x62, 0xFF, 0x60, 0x40, 0x05, 0x36, 0x2D, 0xFF, 0x07, 0x36, 0xD5, 0xFE, 0x08, 0xE1, 0x88, 0x60,
0x85, 0x71, 0x8D, 0xE2, 0xA2, 0x60, 0x41, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x10, 0x62, 0x3D, 0x60,
0x58, 0x4D, 0x3B, 0x78, 0xFF, 0xFF, 0x64, 0x41, 0xA9, 0x9C, 0x60, 0x45, 0x3D, 0x60, 0x58, 0x4D,
0x0F, 0x78, 0xFF, 0xFF, 0xA1, 0xF1, 0x09, 0x60, 0xB4, 0x61, 0x64, 0x44, 0x01, 0x27, 0x24, 0x00,
0x60, 0x40, 0x0E, 0x3A, 0x0D, 0x00, 0x01, 0x7C, 0x14, 0x60, 0x6F, 0xF9, 0x44, 0x60, 0x08, 0x7C,
0x14, 0x60, 0x41, 0xF9, 0x16, 0x60, 0x62, 0xF1, 0x02, 0x60, 0xB0, 0x61, 0xB1, 0x9C, 0x26, 0x00,
0x00, 0x7C, 0x14, 0x60, 0x6F, 0xF9, 0x40, 0x60, 0x08, 0x7C, 0x14, 0x60, 0x41, 0xF9, 0x16, 0x60,
0x62, 0xF1, 0x02, 0x60, 0x90, 0x61, 0xB1, 0x9C, 0x09, 0x60, 0x67, 0x65, 0xFF, 0xB4, 0xC4, 0x85,
0xE0, 0x84, 0xE0, 0x84, 0xC4, 0x81, 0x12, 0x00, 0xFF, 0xB4, 0xED, 0xA0, 0x2C, 0x60, 0xC6, 0x61,
0x04, 0x04, 0xE2, 0xA0, 0xD9, 0x81, 0x01, 0x04, 0xD9, 0x81, 0xA1, 0xD1, 0x02, 0x60, 0x50, 0x61,
0x26, 0x60, 0xF0, 0x65, 0xE0, 0x84, 0x44, 0xD3, 0xB1, 0x9C, 0xC8, 0x81, 0x61, 0x47, 0x00, 0x7E,
0xE9, 0x81, 0x07, 0x60, 0xF0, 0x65, 0xA5, 0x81, 0x0B, 0xB9, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x85,
0xB5, 0x85, 0x04, 0x60, 0x44, 0x62, 0x3D, 0x60, 0x58, 0x4D, 0x0F, 0x78, 0xFF, 0xFF, 0xA1, 0xF3,
0xC8, 0x61, 0x61, 0x54, 0xCD, 0xE2, 0x60, 0x40, 0x01, 0x27, 0x2E, 0x00, 0xCC, 0x84, 0xE0, 0x85,
0x15, 0x60, 0xA2, 0xE7, 0x26, 0x60, 0x80, 0x64, 0x3D, 0x60, 0x58, 0x4F, 0x04, 0x78, 0xFF, 0xFF,
0x26, 0x60, 0x9C, 0x64, 0x3D, 0x60, 0x58, 0x4F, 0x04, 0x78, 0xFF, 0xFF, 0x26, 0x60, 0xB8, 0x64,
0x3D, 0x60, 0x58, 0x4F, 0x04, 0x78, 0xFF, 0xFF, 0x26, 0x60, 0xD4, 0x64, 0x3D, 0x60, 0x58, 0x4F,
0x04, 0x78, 0xFF, 0xFF, 0x75, 0x64, 0x06, 0x61, 0x61, 0x48, 0x60, 0x44, 0x80, 0xBC, 0xFF, 0xB4,
0x60, 0x4A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x28, 0x60, 0xE6, 0x7C, 0x07, 0x60, 0xE8, 0xF9,
0x28, 0x60, 0x6E, 0x63, 0x14, 0x61, 0x21, 0x00, 0x14, 0x60, 0xDF, 0xF1, 0xFF, 0xB4, 0xED, 0xA0,
0x64, 0x41, 0x04, 0x04, 0xE2, 0xA0, 0xD9, 0x81, 0x01, 0x04, 0xD9, 0x81, 0xA1, 0xD1, 0x14, 0x60,
0x0E, 0xF3, 0x64, 0x41, 0xFF, 0xB1, 0xFF, 0x60, 0x00, 0x65, 0xA4, 0x84, 0x34, 0x94, 0xA2, 0xDB,
0x5A, 0xD3, 0x64, 0x41, 0xA5, 0x81, 0xFF, 0xB4, 0x34, 0x94, 0xA2, 0xDB, 0x29, 0x60, 0x52, 0x7C,
0x07, 0x60, 0xE8, 0xF9, 0x27, 0x60, 0xFC, 0x63, 0x13, 0x61, 0x3D, 0x60, 0x58, 0x4D, 0x23, 0x78,
0xFF, 0xFF, 0x07, 0x60, 0xE8, 0xF3, 0x31, 0x40, 0x80, 0x26, 0x36, 0xA4, 0x07, 0x60, 0xE8, 0xFB,
0x60, 0x43, 0x09, 0x61, 0x3D, 0x60, 0x58, 0x4D, 0x23, 0x78, 0xFF, 0xFF, 0xA1, 0xF3, 0x29, 0x60,
0xBE, 0x61, 0x00, 0x7C, 0x7E, 0x63, 0x59, 0xD9, 0xFE, 0x1F, 0x60, 0x40, 0x01, 0x27, 0x03, 0x00,
0x2A, 0x60, 0x40, 0x65, 0x15, 0x00, 0xFF, 0xB4, 0xF9, 0xA0, 0x2A, 0x60, 0x62, 0x65, 0x01, 0x7C,
0x0D, 0x04, 0xED, 0xA0, 0x2A, 0x60, 0x84, 0x65, 0x11, 0x7C, 0x08, 0x04, 0xE2, 0xA0, 0x2A, 0x60,
0xA6, 0x65, 0x21, 0x7C, 0x03, 0x04, 0x2A, 0x60, 0xC8, 0x65, 0x31, 0x7C, 0x64, 0x5F, 0x7D, 0xFB,
0xA5, 0xD3, 0xDA, 0x85, 0xF0, 0xA0, 0x29, 0x60, 0xBE, 0x61, 0x08, 0x06, 0x40, 0x54, 0x58, 0x53,
0x08, 0xFF, 0x37, 0x60, 0x7A, 0x64, 0x43, 0xFB, 0x08, 0xFF, 0xFF, 0x01, 0x60, 0x43, 0x60, 0x46,
0xA5, 0xD1, 0xDA, 0x85, 0xA5, 0xD3, 0xDA, 0x85, 0x59, 0xD9, 0x59, 0xDB, 0x59, 0xD9, 0x59, 0xDB,
0xFB, 0x1F, 0x0C, 0x63, 0xA5, 0xD1, 0xDA, 0x85, 0xA5, 0xD3, 0xDA, 0x85, 0x59, 0xD9, 0x59, 0xDB,
0x59, 0xD9, 0x59, 0xDB, 0xF7, 0x1F, 0x66, 0x44, 0x0E, 0x63, 0x53, 0x93, 0x60, 0x40, 0x10, 0x36,
0x07, 0x00, 0x65, 0x44, 0x48, 0xD3, 0x59, 0xD9, 0x59, 0xDB, 0x59, 0xD9, 0x59, 0xDB, 0xFB, 0x1F,
0x16, 0x60, 0x39, 0xF1, 0x7D, 0xF3, 0x64, 0x43, 0xDB, 0x81, 0x2C, 0x60, 0x54, 0x65, 0x60, 0x40,
0x01, 0x37, 0x12, 0x00, 0x11, 0x37, 0x17, 0x00, 0x21, 0x37, 0x1D, 0x00, 0x31, 0x37, 0x22, 0x00,
0xA3, 0xD1, 0x16, 0x60, 0x34, 0xF5, 0x64, 0x44, 0xFF, 0xB4, 0x16, 0x60, 0x33, 0xFB, 0x64, 0x47,
0xFF, 0xB4, 0x16, 0x60, 0x2A, 0xF1, 0x1D, 0x00, 0xA1, 0xD3, 0x16, 0x60, 0x35, 0xF5, 0xFF, 0xB4,
0x16, 0x60, 0x2B, 0xF1, 0x16, 0x00, 0xA1, 0xD3, 0x16, 0x60, 0x36, 0xF5, 0x60, 0x47, 0xFF, 0xB4,
0x16, 0x60, 0x2C, 0xF1, 0x0E, 0x00, 0x59, 0xD3, 0x16, 0x60, 0x37, 0xF5, 0xFF, 0xB4, 0x16, 0x60,
0x2D, 0xF1, 0x07, 0x00, 0x59, 0xD3, 0x16, 0x60, 0x38, 0xF5, 0x60, 0x47, 0xFF, 0xB4, 0x16, 0x60,
0x2E, 0xF1, 0x16, 0x60, 0x32, 0xFB, 0x16, 0x60, 0x2F, 0xF9, 0x66, 0x42, 0xFC, 0xA2, 0xA2, 0xD3,
0x2B, 0x60, 0x42, 0x63, 0xCC, 0x84, 0xE8, 0x84, 0xCC, 0x81, 0x63, 0x45, 0xA6, 0xD3, 0xDA, 0x82,
0xFF, 0xB4, 0xFF, 0xFF, 0x03, 0x03, 0x60, 0x40, 0x80, 0x2B, 0x03, 0x00, 0xDA, 0x86, 0xCD, 0x81,
0xF5, 0x01, 0x00, 0xB9, 0xA6, 0xD3, 0x0B, 0x03, 0x5A, 0xD1, 0xDA, 0x86, 0xFF, 0xB4, 0xE0, 0x84,
0xC4, 0x84, 0x5C, 0x90, 0xBD, 0xD9, 0xFD, 0x02, 0xCD, 0x81, 0x66, 0x42, 0xF2, 0x02, 0x5A, 0xD3,
0x2B, 0x60, 0x80, 0x65, 0xD7, 0x80, 0xBD, 0xDB, 0xFD, 0x02, 0x7D, 0xF3, 0x19, 0x60, 0x7B, 0xF1,
0x60, 0x40, 0x01, 0x27, 0x09, 0x00, 0x64, 0x40, 0x10, 0x26, 0x06, 0x00, 0x13, 0x64, 0xCB, 0xFB,
0x01, 0x60, 0x67, 0x64, 0x37, 0xFB, 0x09, 0x00, 0x08, 0x64, 0xCB, 0xFB, 0xA1, 0xF3, 0x01, 0x60,
0x67, 0x7C, 0x60, 0x40, 0x01, 0x27, 0x5B, 0x7C, 0x37, 0xF9, 0x19, 0x60, 0x4D, 0xF1, 0x7D, 0xF3,
0x64, 0x40, 0x00, 0x3A, 0x1B, 0x00, 0x60, 0x40, 0x01, 0x27, 0x0D, 0x00, 0x32, 0x60, 0xAB, 0x63,
0x4C, 0x94, 0x0E, 0xA5, 0x60, 0xFE, 0xA0, 0xD1, 0xA5, 0xD3, 0x19, 0x60, 0x72, 0xF9, 0x19, 0x60,
0x73, 0xFB, 0x20, 0xFE, 0x0B, 0x00, 0xFF, 0xB4, 0xF8, 0xA4, 0x32, 0x60, 0xC8, 0x63, 0x4C, 0x94,
0x60, 0xFE, 0xA0, 0xD1, 0xFF, 0xFF, 0x19, 0x60, 0x73, 0xF9, 0x20, 0xFE, 0x19, 0x60, 0x75, 0xF3,
0x16, 0x60, 0xD8, 0xF1, 0x60, 0x43, 0xD3, 0x80, 0x19, 0x60, 0x76, 0xF3, 0x01, 0x07, 0x63, 0x5C,
0xD0, 0x80, 0xFF, 0xFF, 0x01, 0x07, 0x60, 0x5C, 0x19, 0x60, 0x4F, 0xF9, 0x19, 0x60, 0x53, 0xF9,
0x7D, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x27, 0x0A, 0x00, 0xFF, 0xB5, 0x10, 0x60, 0xF4, 0x63,
0x65, 0x41, 0xCD, 0x81, 0x06, 0xA3, 0xFD, 0x02, 0xFA, 0xA3, 0xA3, 0xD3, 0x0F, 0x00, 0x01, 0x60,
0xFF, 0x65, 0xA4, 0x84, 0x11, 0x60, 0x60, 0x61, 0xA1, 0xD1, 0xFF, 0xFF, 0xD0, 0x80, 0x08, 0xA1,
0xFB, 0x02, 0xFC, 0xA1, 0xA1, 0xD3, 0x19, 0x60, 0x4F, 0xF1, 0xFF, 0xB4, 0xD0, 0x80, 0xFF, 0xFF,
0x04, 0x07, 0x19, 0x60, 0x4F, 0xFB, 0x19, 0x60, 0x53, 0xFB, 0x19, 0x60, 0x4F, 0xF3, 0x19, 0x60,
0x72, 0xF1, 0x19, 0x60, 0x74, 0xFB, 0xD0, 0x80, 0xFF, 0xFF, 0x02, 0x04, 0x19, 0x60, 0x74, 0xF9,
0x2C, 0x60, 0x74, 0x63, 0x2B, 0x60, 0x02, 0x65, 0x16, 0x60, 0x33, 0xF1, 0x2A, 0x60, 0xEA, 0x61,
0x2C, 0x60, 0x62, 0x64, 0x40, 0x4F, 0x04, 0x64, 0xC3, 0x60, 0x58, 0x4D, 0x1A, 0x78, 0xFF, 0xFF,
0x19, 0x60, 0x4F, 0xF3, 0x19, 0x60, 0x73, 0xF1, 0x19, 0x60, 0x74, 0xFB, 0xD0, 0x80, 0xFF, 0xFF,
0x02, 0x04, 0x19, 0x60, 0x74, 0xF9, 0x2C, 0x60, 0x7C, 0x63, 0x16, 0x60, 0x32, 0xF1, 0x2B, 0x60,
0x42, 0x65, 0x2C, 0x60, 0x60, 0x64, 0x40, 0x4F, 0x08, 0x64, 0xC3, 0x60, 0x58, 0x4D, 0x1A, 0x78,
0xFF, 0xFF, 0x7D, 0xF3, 0x08, 0x7C, 0x38, 0xF9, 0x2B, 0x60, 0xDA, 0x61, 0x60, 0x40, 0x01, 0x2B,
0x0E, 0x00, 0x01, 0x37, 0x06, 0x00, 0x11, 0x37, 0x03, 0x00, 0x21, 0x3B, 0x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, 0x4A, 0x02, 0x64, 0x01, 0x16, 0xFE, 0x01, 0xCC, 0x84,
0xFF, 0xFF, 0xFD, 0x02, 0x7C, 0x49, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x68, 0x5C, 0x7C, 0x49,
0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x68, 0x44, 0x95, 0x60, 0x84, 0xE7, 0x2D, 0x58, 0xFF, 0xFF,
0x40, 0xFF, 0x20, 0x44, 0xBF, 0xB4, 0x40, 0x40, 0x03, 0x00, 0x20, 0x44, 0x40, 0xBC, 0x40, 0x40,
0x43, 0x45, 0x20, 0x44, 0x20, 0xBC, 0x40, 0x40, 0x02, 0x00, 0x43, 0x45, 0xF6, 0x01, 0x00, 0x64,
0x19, 0x60, 0xF2, 0xFB, 0x3F, 0x44, 0x40, 0x26, 0x05, 0x00, 0x1C, 0x60, 0x0F, 0xF3, 0x5A, 0xD1,
0xA0, 0x50, 0xA4, 0x50, 0xAE, 0x4F, 0xFD, 0xB4, 0x04, 0xBC, 0xA0, 0x5E, 0x00, 0x60, 0x02, 0x71,
0x8D, 0xE2, 0x40, 0xE1, 0x40, 0x29, 0xFE, 0x01, 0x04, 0xAC, 0xA0, 0x5E, 0xFF, 0xFF, 0x00, 0x60,
0x10, 0x62, 0x19, 0x60, 0x8E, 0x7C, 0x00, 0x60, 0xAC, 0x65, 0x3D, 0x60, 0x58, 0x4D, 0x0F, 0x78,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x60, 0x10, 0x62, 0x3D, 0x60, 0x58, 0x4D, 0x3B, 0x78, 0xFF, 0xFF,
0x60, 0x40, 0x19, 0x60, 0x8E, 0x64, 0x64, 0x40, 0xD0, 0x80, 0x14, 0x71, 0x05, 0x03, 0x8D, 0xE2,
0x40, 0xE1, 0x40, 0x29, 0xFE, 0x01, 0xE2, 0x01, 0x3F, 0x44, 0x40, 0x26, 0x05, 0x00, 0x1C, 0x60,
0x0D, 0xF3, 0x5A, 0xD1, 0xA0, 0x50, 0xA4, 0x52, 0x27, 0x60, 0x36, 0x63, 0x1E, 0x61, 0x3D, 0x60,
0x58, 0x4D, 0x23, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x14, 0x71, 0x8D, 0xE2, 0x40, 0xE1, 0x40, 0x29,
0xFE, 0x01, 0x31, 0x44, 0x40, 0x26, 0x02, 0x00, 0x80, 0x26, 0x17, 0x00, 0x28, 0x60, 0xE6, 0x63,
0x07, 0x60, 0xE8, 0xFD, 0x09, 0x61, 0x3D, 0x60, 0x58, 0x4D, 0x23, 0x78, 0xFF, 0xFF, 0x31, 0x44,
0x40, 0x2A, 0x14, 0x00, 0x31, 0x44, 0x7F, 0xB4, 0x40, 0x51, 0xAE, 0x4C, 0x10, 0x26, 0x0E, 0x00,
0x07, 0x60, 0xE9, 0xFB, 0x31, 0x44, 0x80, 0xBC, 0x40, 0x51, 0x29, 0x60, 0x1C, 0x63, 0x07, 0x60,
0xE8, 0xFD, 0x09, 0x61, 0x3D, 0x60, 0x58, 0x4D, 0x23, 0x78, 0xFF, 0xFF, 0x27, 0x60, 0xEA, 0x63,
0x03, 0x61, 0x3D, 0x60, 0x58, 0x4D, 0x23, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x10, 0x62, 0x19, 0x60,
0x8F, 0x7C, 0x00, 0x60, 0xAC, 0x65, 0x3D, 0x60, 0x58, 0x4D, 0x0F, 0x78, 0xFF, 0xFF, 0x80, 0xE1,
0xBF, 0xFE, 0xA1, 0x4F, 0x70, 0xB4, 0x50, 0x36, 0x0C, 0x00, 0x20, 0x36, 0x03, 0x00, 0x3A, 0x60,
0x77, 0x78, 0xFF, 0xFF, 0x01, 0x60, 0x1A, 0xE1, 0xDF, 0xFE, 0x19, 0xFF, 0x00, 0xE1, 0xA1, 0xFF,
0xFF, 0xFF, 0x20, 0x44, 0x40, 0x2A, 0x85, 0x00, 0x7D, 0xF1, 0x3B, 0x00, 0x83, 0x00, 0x19, 0x60,
0xF2, 0xF3, 0xFF, 0xFF, 0x01, 0x18, 0x59, 0x01, 0x43, 0x45, 0x20, 0x44, 0x20, 0xBC, 0x40, 0x40,
0x1C, 0x60, 0x0F, 0xF3, 0x3F, 0x40, 0x40, 0x26, 0x01, 0x00, 0xA0, 0x50, 0xAE, 0x4F, 0xFD, 0xB4,
0xA0, 0x5E, 0xAC, 0x4F, 0x10, 0xBC, 0xA0, 0x5C, 0xFF, 0xFF, 0x10, 0xAC, 0xA0, 0x5C, 0x00, 0x60,
0xC8, 0x71, 0x8D, 0xE2, 0x40, 0xE1, 0x40, 0x29, 0xFE, 0x01, 0x7D, 0xF1, 0x30, 0x61, 0x64, 0x44,
0x01, 0x2B, 0x20, 0xA1, 0x30, 0x64, 0x61, 0x5F, 0x60, 0x45, 0x0C, 0x60, 0x00, 0x62, 0x00, 0x60,
0x71, 0x7C, 0x3D, 0x60, 0x58, 0x4D, 0x0F, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0xC8, 0x71, 0x8D, 0xE2,
0x40, 0xE1, 0x40, 0x29, 0xFE, 0x01, 0x01, 0x60, 0x08, 0xE1, 0x7D, 0xF1, 0x20, 0x44, 0x40, 0xBC,
0x40, 0x40, 0x19, 0x60, 0xF2, 0xF3, 0xFF, 0xFF, 0x03, 0x18, 0x3D, 0x60, 0x57, 0x78, 0xFF, 0xFF,
0x1B, 0x60, 0xF3, 0xF1, 0xAD, 0x4F, 0x00, 0x7F, 0xFA, 0xB4, 0x64, 0x41, 0x7D, 0xF1, 0x02, 0xB1,
0x04, 0x65, 0x02, 0x02, 0x64, 0x40, 0x01, 0x2B, 0x01, 0x65, 0xB4, 0x84, 0xA0, 0x5D, 0x20, 0x44,
0x40, 0x2A, 0x43, 0x45, 0x20, 0xBC, 0x40, 0x40, 0xA1, 0xF9, 0x05, 0x64, 0xA2, 0xFB, 0xDF, 0xFE,
0x19, 0xFF, 0xDD, 0xFE, 0x26, 0x00, 0x20, 0x44, 0x20, 0xBC, 0x40, 0x40, 0x43, 0x45, 0xA4, 0xD1,
0xDA, 0x83, 0xC3, 0x85, 0x80, 0xE1, 0xDF, 0xFE, 0xBD, 0xD3, 0xFF, 0xFF, 0x60, 0x48, 0x60, 0x47,
0x80, 0xBC, 0x00, 0x7F, 0x60, 0x4A, 0xD7, 0x80, 0xA1, 0xFF, 0xF6, 0x02, 0xBF, 0xFE, 0x11, 0x00,
0x43, 0x45, 0xA4, 0xD1, 0xDA, 0x83, 0x0D, 0x18, 0x64, 0x44, 0x00, 0x61, 0xFA, 0xA4, 0xDD, 0x81,
0xFD, 0x02, 0x3D, 0x60, 0x58, 0x4D, 0x23, 0x78, 0xFF, 0xFF, 0xBF, 0xFE, 0x02, 0x00, 0xF1, 0xFE,
0x01, 0x00, 0x25, 0x43, 0x21, 0xE1, 0x00, 0x64, 0xBF, 0xDB, 0x20, 0x44, 0x20, 0x2A, 0x07, 0x00,
0x07, 0xB4, 0x04, 0x36, 0xC3, 0xFE, 0x06, 0x36, 0xCC, 0xFE, 0x07, 0x36, 0xD5, 0xFE, 0x20, 0x44,
0x98, 0xB4, 0x40, 0x40, 0x26, 0x60, 0x26, 0x63, 0xBD, 0xD3, 0x03, 0x61, 0x0F, 0x1B, 0x04, 0xA3,
0xBD, 0xD3, 0x04, 0x61, 0x0B, 0x1B, 0x04, 0xA3, 0xBD, 0xD3, 0x06, 0x61, 0x07, 0x1B, 0x04, 0xA3,
0xBD, 0xD3, 0x07, 0x61, 0x03, 0x1B, 0xC3, 0x60, 0x48, 0x78, 0xFF, 0xFF, 0xA3, 0xD1, 0x40, 0x44,
0x20, 0x44, 0x07, 0xB5, 0xD4, 0x85, 0x35, 0x80, 0x24, 0x45, 0x26, 0x60, 0x66, 0x64, 0x44, 0xD7,
0xFF, 0xFF, 0xFF, 0xFF, 0x43, 0x45, 0x20, 0x44, 0x20, 0xBC, 0x40, 0x40, 0x64, 0x43, 0xBD, 0xD3,
0xBD, 0xD1, 0x40, 0x44, 0x10, 0x27, 0x19, 0x00, 0x3F, 0x40, 0x02, 0x2B, 0x06, 0x00, 0x24, 0x47,
0x08, 0x2B, 0x13, 0x00, 0x07, 0xB4, 0x01, 0x36, 0x11, 0x00, 0xFF, 0x60, 0x7F, 0x65, 0x15, 0x60,
0xA2, 0x64, 0x24, 0x40, 0x08, 0x2B, 0xA4, 0x84, 0xA0, 0x57, 0xFF, 0xFF, 0x64, 0x49, 0xFF, 0xFF,
0x68, 0x44, 0x01, 0x16, 0xFD, 0x01, 0x00, 0x7F, 0xA3, 0xDB, 0xAB, 0x01, 0x64, 0x42, 0x3D, 0x60,
0x58, 0x4D, 0x3B, 0x78, 0xFF, 0xFF, 0xBD, 0xD9, 0xA3, 0xDB, 0xA3, 0x01, 0x43, 0x45, 0x20, 0x44,
0x20, 0xBC, 0x40, 0x40, 0x64, 0x43, 0xBD, 0xD3, 0xA3, 0xD1, 0x40, 0x44, 0x10, 0x2B, 0x16, 0x00,
0xBE, 0xD1, 0xFF, 0xFF, 0x15, 0x60, 0x80, 0xE7, 0x24, 0x40, 0x07, 0x27, 0x04, 0x00, 0xAC, 0x4F,
0x10, 0xBC, 0x00, 0x7F, 0xA0, 0x5C, 0x64, 0x4A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x24, 0x40,
0x20, 0x27, 0x1D, 0x00, 0xAC, 0x4F, 0xEF, 0xB4, 0xA0, 0x5C, 0x19, 0x00, 0x3F, 0x40, 0x02, 0x2B,
0x06, 0x00, 0x24, 0x47, 0x08, 0x2B, 0x13, 0x00, 0x07, 0xB4, 0x01, 0x36, 0x11, 0x00, 0x15, 0x60,
0x22, 0x64, 0x24, 0x40, 0x08, 0x27, 0x80, 0xBC, 0x7C, 0x48, 0xBE, 0xD3, 0xA0, 0x57, 0x60, 0x48,
0x64, 0x44, 0x80, 0xBC, 0xFF, 0xB4, 0x60, 0x4A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x69, 0x01,
0x01, 0x61, 0x3D, 0x60, 0x58, 0x4D, 0x23, 0x78, 0xFF, 0xFF, 0x63, 0x01, 0x30, 0x44, 0x02, 0xA8,
0x00, 0xE1, 0x07, 0x02, 0x62, 0xFF, 0x63, 0xFF, 0x64, 0xFF, 0x65, 0xFF, 0x66, 0xFF, 0xBF, 0xFE,
0xA1, 0xFF, 0x82, 0xFF, 0x88, 0xFF, 0x6C, 0x40, 0x41, 0xFF, 0xC4, 0xE2, 0x43, 0xFF, 0x5C, 0x49,
0x08, 0xE1, 0xA2, 0x60, 0x41, 0x78, 0xFF, 0xFF, 0x30, 0x44, 0x02, 0xA8, 0x00, 0xE1, 0x02, 0x02,
0xA1, 0xFF, 0xFF, 0xFF, 0x82, 0xFF, 0x88, 0xFF, 0xA8, 0xE2, 0xCB, 0xF1, 0x00, 0x6B, 0x89, 0xFF,
0x64, 0x54, 0x88, 0xFF, 0x9F, 0xFE, 0x02, 0x05, 0x64, 0x44, 0x60, 0x54, 0xCD, 0xE2, 0xC2, 0x64,
0x3A, 0xDB, 0xBC, 0xFF, 0xB5, 0xFF, 0x1D, 0xFF, 0x26, 0x44, 0x02, 0xB4, 0x40, 0x46, 0x3C, 0x44,
0x00, 0xBC, 0xFF, 0xFF, 0x06, 0x03, 0x27, 0x40, 0x26, 0x22, 0x03, 0x00, 0x02, 0x64, 0x31, 0xFB,
0xC0, 0xFE, 0x27, 0x44, 0x20, 0x2A, 0x04, 0x00, 0xA0, 0x60, 0x00, 0xEA, 0xB0, 0x60, 0x00, 0xEA,
0x5C, 0x44, 0x27, 0x44, 0x18, 0xB4, 0x40, 0x47, 0x00, 0xE1, 0x29, 0x40, 0x50, 0x2B, 0x37, 0x00,
0xEF, 0x60, 0xFF, 0x65, 0x29, 0x44, 0x24, 0x89, 0x31, 0x40, 0x08, 0x26, 0x0B, 0x00, 0x21, 0x46,
0xA7, 0xF4, 0x1D, 0xF2, 0xFF, 0xB3, 0x00, 0x7C, 0x05, 0x03, 0x06, 0x61, 0x5D, 0x91, 0x09, 0x60,
0x02, 0x65, 0x02, 0x03, 0x00, 0x61, 0x15, 0x00, 0xD4, 0x80, 0x63, 0x45, 0xFB, 0x07, 0x65, 0x43,
0x80, 0x60, 0x00, 0x62, 0xF6, 0x82, 0x53, 0x90, 0xE3, 0x83, 0xFC, 0x04, 0xEB, 0x83, 0xEB, 0x83,
0xEA, 0x82, 0x5C, 0x94, 0xB2, 0x9C, 0xF3, 0x07, 0x64, 0x41, 0xDD, 0x81, 0xE1, 0x81, 0xE1, 0x81,
0xE1, 0x81, 0x2B, 0x44, 0x54, 0x90, 0x70, 0x45, 0x02, 0x28, 0x61, 0x44, 0xC4, 0x84, 0xFF, 0xFF,
0x04, 0x24, 0x00, 0xB4, 0x60, 0x50, 0x08, 0x28, 0x01, 0x00, 0x20, 0x29, 0x6D, 0xE2, 0xA4, 0xE2,
0xC4, 0xE2, 0x47, 0xFF, 0xB6, 0xFF, 0xB7, 0xFF, 0xB4, 0xFF, 0x32, 0xF1, 0x08, 0x29, 0x09, 0x00,
0x64, 0x40, 0x07, 0x22, 0x06, 0x00, 0x43, 0xFF, 0x27, 0x44, 0x10, 0xBC, 0x40, 0x47, 0x00, 0x64,
0x32, 0xFB, 0x31, 0x41, 0x3C, 0x44, 0x01, 0xB1, 0x00, 0xBC, 0x0A, 0x02, 0x09, 0x03, 0x32, 0xF3,
0x00, 0x7C, 0x01, 0xB4, 0xFF, 0xFF, 0x04, 0x03, 0x32, 0xF9, 0x02, 0x64, 0x31, 0xFB, 0xC0, 0xFE,
0xC8, 0x60, 0x09, 0x7D, 0x00, 0x60, 0x00, 0x6B, 0x00, 0x64, 0x33, 0xFB, 0x0C, 0x60, 0x16, 0x64,
0xA0, 0xD7, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xE1, 0x30, 0x40, 0x02, 0x36, 0xA1, 0xFF, 0x83, 0xFF,
0x8D, 0xFF, 0x5C, 0x44, 0x5C, 0x43, 0x5C, 0x42, 0x5C, 0x41, 0x5C, 0x40, 0xAC, 0xFF, 0xAD, 0xFF,
0xE7, 0xE1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0xF4, 0x60, 0x58, 0x4F,
0xE9, 0x78, 0xFF, 0xFF, 0xE9, 0x60, 0x58, 0x4F, 0xCA, 0x78, 0xFF, 0xFF, 0x27, 0x60, 0x58, 0x4F,
0x71, 0x78, 0xFF, 0xFF, 0xEE, 0x60, 0x58, 0x4F, 0x69, 0x78, 0xFF, 0xFF, 0x1F, 0xE1, 0xA3, 0xFF,
0xCA, 0x60, 0xD4, 0x78, 0xFF, 0xFF, 0x03, 0xE1, 0xA3, 0xFF, 0xFE, 0xFC, 0xFF, 0xFC, 0x25, 0x60,
0x96, 0x63, 0x17, 0xFD, 0xAE, 0xFF, 0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF, 0x42, 0x6F, 0x6F, 0x74,
0x63, 0x6F, 0x64, 0x65, 0x20, 0x21, 0x21, 0x20, 0x20, 0x00, 0x53, 0x54, 0x41, 0x2F, 0x41, 0x50,
0x20, 0x46, 0x75, 0x6E, 0x63, 0x27, 0x73, 0x00, 0x1F, 0x00, 0x04, 0x00, 0x01, 0x00, 0x24, 0x00,
0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x04, 0x00,
0x06, 0x00, 0x07, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x06, 0x00, 0x06, 0x00, 0x07, 0x00,
0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00,
0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0xA6, 0xF3, 0x21, 0x61, 0x00, 0x7C, 0x01, 0x00, 0x00, 0xFA,
0x60, 0x46, 0xFE, 0x63, 0xA3, 0xD8, 0xFE, 0x1F, 0xCD, 0x81, 0xD8, 0x84, 0xF8, 0x02, 0x21, 0x61,
0x80, 0x67, 0x40, 0x4A, 0xA6, 0xF5, 0x05, 0x18, 0x2A, 0x43, 0x02, 0xFC, 0x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A0, 0x60, 0x00, 0xEB, 0xB0, 0x60, 0x00, 0xEB, 0xAB, 0x48, 0x40, 0x3B, 0x01, 0x00,
0xFC, 0x01, 0x00, 0xEB, 0x03, 0x60, 0x02, 0x64, 0xA0, 0xDB, 0x0F, 0x64, 0x60, 0x7F, 0xA0, 0x5A,
0x80, 0x60, 0x00, 0xEA, 0xA0, 0x60, 0x00, 0xEA, 0xD1, 0x60, 0x00, 0xEA, 0x24, 0x44, 0xFF, 0xB4,
0x04, 0xFB, 0x50, 0x60, 0x00, 0x64, 0x05, 0xFB, 0x10, 0x60, 0x10, 0x75, 0x2A, 0x60, 0x1D, 0x78,
0xFF, 0xFF, 0x3F, 0x40, 0x40, 0x26, 0x40, 0x00, 0x05, 0x60, 0xF9, 0xF1, 0x42, 0x60, 0x08, 0x64,
0x09, 0x60, 0x19, 0x63, 0x64, 0x40, 0x01, 0x2B, 0x04, 0x00, 0x42, 0x60, 0x09, 0x64, 0x0A, 0x60,
0x19, 0x63, 0x1C, 0x60, 0x0F, 0xFB, 0x04, 0x60, 0x00, 0xBC, 0x1C, 0x60, 0x0B, 0xFB, 0x1C, 0x60,
0x0A, 0xFD, 0x1D, 0x60, 0x19, 0x63, 0x1C, 0x60, 0x0E, 0xFD, 0x80, 0x60, 0x1C, 0x64, 0x3F, 0x40,
0x01, 0x2A, 0x02, 0x00, 0x60, 0x60, 0x1C, 0x64, 0x1C, 0x60, 0x10, 0xFB, 0x1C, 0x60, 0x0C, 0xFB,
0x1C, 0x60, 0x0F, 0xF3, 0xA0, 0x50, 0xA0, 0x50, 0x0B, 0x60, 0xF8, 0x63, 0xA3, 0xD1, 0x38, 0x60,
0x12, 0x61, 0xA1, 0xD3, 0xF8, 0xA3, 0x90, 0x84, 0xA2, 0xDB, 0xA3, 0xD1, 0x59, 0xD3, 0x06, 0xA3,
0x90, 0x84, 0xA2, 0xDB, 0xA3, 0xD1, 0x59, 0xD3, 0xFE, 0xA3, 0x90, 0x84, 0xA2, 0xDB, 0xA3, 0xD1,
0x59, 0xD3, 0xFF, 0xFF, 0x90, 0x84, 0xA2, 0xDB, 0x80, 0x60, 0x58, 0xEC, 0x80, 0x60, 0x00, 0xED,
0x80, 0x60, 0x80, 0xEE, 0x40, 0xEC, 0x00, 0xED, 0x00, 0xEE, 0xC0, 0x60, 0x59, 0xEC, 0xC0, 0x60,
0x07, 0xED, 0xC0, 0x60, 0x8F, 0xEE, 0xAD, 0x4F, 0xFA, 0xB4, 0xA0, 0x5D, 0x00, 0xF3, 0x28, 0xFB,
0x40, 0x44, 0x37, 0x60, 0x7B, 0x7C, 0x20, 0xF9, 0x3F, 0x60, 0x18, 0x7C, 0x21, 0xF9, 0x3F, 0x60,
0x2E, 0x7C, 0x22, 0xF9, 0x3F, 0x60, 0xC5, 0x7C, 0x23, 0xF9, 0x3F, 0x60, 0xD6, 0x7C, 0x24, 0xF9,
0x40, 0x60, 0x00, 0x7C, 0x25, 0xF9, 0x40, 0x60, 0x11, 0x7C, 0x26, 0xF9, 0xD0, 0x60, 0x00, 0xE8,
0x28, 0xE8, 0x44, 0x60, 0x01, 0xE6, 0x10, 0x67, 0x40, 0x52, 0x10, 0x60, 0x04, 0xE6, 0x08, 0x60,
0x06, 0x63, 0xFD, 0x60, 0x0C, 0x65, 0x5B, 0xD3, 0xBF, 0xD1, 0x10, 0x18, 0xC3, 0x83, 0xD4, 0x80,
0xC3, 0x83, 0xF9, 0x02, 0xFA, 0xA3, 0xA3, 0xD3, 0x02, 0x60, 0x00, 0x65, 0xF9, 0xA0, 0xFC, 0xA0,
0x0D, 0x05, 0x04, 0x05, 0x78, 0x43, 0x02, 0x61, 0x29, 0x60, 0xEA, 0x78, 0x21, 0x60, 0x00, 0x65,
0x3F, 0x43, 0x21, 0x60, 0x00, 0x65, 0xC0, 0x60, 0x8F, 0xEE, 0x08, 0x00, 0x02, 0x60, 0x00, 0x65,
0x00, 0x60, 0x00, 0x64, 0x18, 0xFB, 0x3F, 0x43, 0x11, 0x60, 0x10, 0xE6, 0xB7, 0x84, 0x40, 0x5F,
0x37, 0x60, 0xF8, 0x63, 0x3F, 0x40, 0x20, 0x27, 0x06, 0x00, 0x0F, 0x60, 0xFF, 0x64, 0xBD, 0xDB,
0x0F, 0x60, 0xF0, 0x64, 0x03, 0x00, 0x0F, 0x64, 0xBD, 0xDB, 0x00, 0x64, 0xA3, 0xDB, 0x00, 0x60,
0x30, 0xE2, 0x00, 0x60, 0x50, 0xE2, 0x00, 0x60, 0x79, 0xE2, 0x00, 0x60, 0x90, 0xE2, 0x01, 0x60,
0xD0, 0xE2, 0x01, 0x60, 0xF0, 0xE2, 0x01, 0x60, 0xB0, 0xE2, 0x13, 0x64, 0xCB, 0xFB, 0x01, 0x60,
0x67, 0x64, 0x37, 0xFB, 0x00, 0x60, 0x28, 0x64, 0x36, 0xFB, 0x09, 0x60, 0x2A, 0x64, 0xB6, 0xFB,
0x82, 0xFF, 0x92, 0xFF, 0x5C, 0x41, 0x5C, 0x46, 0x5C, 0x47, 0x00, 0xE1, 0xA3, 0x60, 0xF4, 0x63,
0x0C, 0x60, 0x16, 0x64, 0xA0, 0xDD, 0x87, 0xFF, 0x97, 0xFF, 0x0C, 0x60, 0x02, 0x64, 0x40, 0x5A,
0x06, 0xA4, 0x40, 0x5B, 0x5C, 0x5E, 0x16, 0x60, 0xCF, 0xF3, 0x7D, 0xFB, 0x3F, 0x40, 0x01, 0x22,
0x03, 0x00, 0x80, 0x60, 0x37, 0x7C, 0x02, 0x00, 0x80, 0x60, 0x27, 0x7C, 0x1A, 0x60, 0x1F, 0xF9,
0x01, 0x60, 0x06, 0x64, 0xA7, 0xFB, 0x02, 0x60, 0x7F, 0x64, 0x00, 0x60, 0x42, 0x65, 0xD4, 0x84,
0xA8, 0xFB, 0xDC, 0x84, 0xA6, 0xFB, 0x12, 0x60, 0xD8, 0xFB, 0x40, 0x60, 0x58, 0x4E, 0x7D, 0x78,
0xFF, 0xFF, 0x3F, 0x40, 0x40, 0x26, 0x05, 0x00, 0x1C, 0x60, 0x0D, 0xF3, 0x5A, 0xD1, 0xA0, 0x50,
0xA4, 0x52, 0x08, 0x60, 0x00, 0x63, 0xFA, 0x60, 0x00, 0x65, 0xBD, 0xD3, 0xA3, 0xD3, 0x02, 0xA8,
0xD4, 0x80, 0x21, 0x02, 0x20, 0x02, 0x19, 0x60, 0x48, 0xF1, 0xFF, 0xFF, 0x64, 0x40, 0x80, 0x26,
0x1A, 0x00, 0x04, 0xA3, 0xFD, 0x60, 0x0D, 0x65, 0x5B, 0xD3, 0xBF, 0xD1, 0x14, 0x18, 0xC3, 0x83,
0xD4, 0x80, 0xC3, 0x83, 0xF9, 0x02, 0xBF, 0xD3, 0xAD, 0x49, 0xFE, 0xA0, 0x00, 0x64, 0x0C, 0x04,
0x08, 0xB1, 0x20, 0xBC, 0x08, 0x28, 0x18, 0xBC, 0x07, 0x7C, 0x0E, 0x60, 0xDF, 0xF9, 0x05, 0x7C,
0x0E, 0x60, 0xDE, 0xF9, 0x01, 0x00, 0x00, 0x64, 0x0E, 0x60, 0xDD, 0xFB, 0x40, 0x60, 0x95, 0x78,
0xFF, 0xFF, 0x5C, 0x51, 0x3F, 0x41, 0xA5, 0x4C, 0x50, 0x37, 0x0B, 0x00, 0x01, 0xB9, 0x41, 0x5F,
0xB5, 0x60, 0x55, 0xE0, 0x05, 0x60, 0xF9, 0xF1, 0xC0, 0x67, 0x90, 0x84, 0x3F, 0x40, 0x01, 0x26,
0xA0, 0x50, 0x06, 0x60, 0x08, 0xF3, 0x01, 0x60, 0x01, 0x65, 0x01, 0x60, 0x02, 0x7C, 0xD4, 0x80,
0xD0, 0x80, 0x01, 0x03, 0x10, 0x02, 0x5A, 0xD1, 0x5A, 0xD3, 0x3C, 0x60, 0x00, 0x66, 0xE0, 0x87,
0x40, 0x4A, 0x80, 0x60, 0x9E, 0x61, 0x64, 0x44, 0xC8, 0x84, 0x0C, 0x63, 0xAA, 0x46, 0x58, 0xD0,
0xAA, 0x46, 0x59, 0xD8, 0xFB, 0x1F, 0x08, 0x60, 0x00, 0x63, 0xFA, 0x60, 0x00, 0x65, 0xBD, 0xD3,
0xA3, 0xD3, 0x02, 0xA8, 0xD4, 0x80, 0x07, 0x02, 0x06, 0x02, 0x8C, 0x60, 0xBA, 0x61, 0x3C, 0x60,
0x00, 0x66, 0x41, 0x4B, 0x03, 0x00, 0x46, 0x60, 0x3B, 0x78, 0xFF, 0xFF, 0x2B, 0x41, 0x8D, 0x60,
0x02, 0x7C, 0xD1, 0x80, 0xA1, 0xD2, 0x25, 0x05, 0x59, 0xD0, 0x60, 0x45, 0x59, 0xD2, 0x44, 0x47,
0xE0, 0x87, 0x40, 0x4A, 0x59, 0xD2, 0x59, 0x8B, 0x40, 0x4C, 0x08, 0x60, 0x00, 0x63, 0xBE, 0xD3,
0xBD, 0xD1, 0xEC, 0x18, 0xD4, 0x80, 0xEA, 0x18, 0x03, 0x03, 0xC3, 0x83, 0xC3, 0x83, 0xF7, 0x01,
0x67, 0x44, 0xC0, 0x84, 0xE0, 0x85, 0x2C, 0x44, 0xD4, 0x80, 0x63, 0x41, 0x01, 0x06, 0x65, 0x44,
0xC8, 0x83, 0xAA, 0x46, 0x59, 0xD1, 0x27, 0xD8, 0x5A, 0x87, 0xFC, 0x1F, 0xAA, 0x46, 0x2B, 0x41,
0xD5, 0x01, 0x8D, 0x60, 0x02, 0x61, 0x41, 0x4B, 0x2B, 0x41, 0x8D, 0x60, 0x02, 0x7C, 0xD1, 0x80,
0xA1, 0xD2, 0x27, 0x05, 0x59, 0xD0, 0x60, 0x45, 0x59, 0xD2, 0x44, 0x47, 0xE0, 0x87, 0x40, 0x4A,
0x59, 0xD2, 0x59, 0x8B, 0x40, 0x4C, 0x08, 0x60, 0x00, 0x63, 0xBE, 0xD3, 0xBD, 0xD1, 0xEC, 0x18,
0xD4, 0x80, 0xEA, 0x18, 0x03, 0x03, 0xC3, 0x83, 0xC3, 0x83, 0xF7, 0x01, 0x04, 0xA3, 0xA3, 0xD1,
0x5A, 0x88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x00, 0x00, 0x06, 0x00, 0x10, 0xFD,
0x6E, 0x01, 0x00, 0x00, 0x02, 0x00, 0x14, 0xFD, 0x8E, 0x32, 0x00, 0x00, 0x0A, 0x00, 0x41, 0xFA,
0x40, 0x2A, 0x00, 0x00, 0x22, 0x00, 0x42, 0xFA, 0x62, 0x2A, 0x00, 0x00, 0x22, 0x00, 0x43, 0xFA,
0x84, 0x2A, 0x00, 0x00, 0x22, 0x00, 0x44, 0xFA, 0xA6, 0x2A, 0x00, 0x00, 0x22, 0x00, 0x45, 0xFA,
0xC8, 0x2A, 0x00, 0x00, 0x22, 0x00, 0x25, 0xFD, 0x9E, 0x01, 0x00, 0x00, 0x02, 0x00,
}; /* fw_image_3_data */
static const hcf_8 fw_image_4_data[] = {
0x6C, 0x40, 0xA1, 0xFF, 0x98, 0xFF, 0x80, 0x3E, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x41, 0xFF, 0x33, 0xF3, 0x02, 0x11, 0x31, 0x18, 0x1E, 0x00, 0x44, 0xFF, 0x2E, 0x00, 0xFF, 0xFF,
0xC4, 0xE2, 0x27, 0x44, 0x20, 0x2A, 0x01, 0x00, 0xFF, 0xFF, 0x42, 0x64, 0x3A, 0xDB, 0x23, 0x00,
0x41, 0xFF, 0xA2, 0x60, 0x45, 0x78, 0xE2, 0xFE, 0x40, 0x49, 0x02, 0x60, 0x01, 0xE1, 0x1D, 0x00,
0x44, 0xFF, 0x1B, 0x09, 0x29, 0x44, 0x10, 0x2A, 0x04, 0x74, 0xCD, 0xE2, 0x10, 0x65, 0x0B, 0x00,
0xA3, 0x60, 0xC1, 0x78, 0xA4, 0xE2, 0x29, 0x44, 0x20, 0x2A, 0x0D, 0x00, 0x20, 0xAC, 0xEC, 0x01,
0xA3, 0x60, 0xC1, 0x78, 0x46, 0xFF, 0xB4, 0x84, 0x40, 0x49, 0xA1, 0xFF, 0xFF, 0xFF, 0x80, 0x3E,
0xA3, 0x60, 0xC1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0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x2A, 0x60, 0x1D, 0x78, 0x44, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x2A, 0x60, 0x1D, 0x78, 0x45, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x2A, 0x60, 0x1D, 0x78, 0x46, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x60, 0x87, 0x64, 0x80, 0x29, 0x09, 0xFB, 0x47, 0xFF, 0x2A, 0x60, 0x1D, 0x78, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x43, 0xF7, 0xA7, 0xFF, 0x41, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x37, 0x60, 0x82, 0x78, 0x42, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x36, 0x60, 0x8F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9, 0x01, 0x95, 0xF3,
0xFF, 0xFF, 0x80, 0xB4, 0xFF, 0xFF, 0x08, 0x24, 0x16, 0x00, 0x29, 0x44, 0x08, 0x26, 0xE1, 0x01,
0x72, 0x44, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xB2, 0xF3, 0xE8, 0x85,
0xFF, 0xB7, 0xE0, 0x84, 0xE0, 0x84, 0xB4, 0x85, 0x73, 0x44, 0xD4, 0x84, 0x10, 0x65, 0xD4, 0x80,
0xFF, 0xFF, 0x01, 0x05, 0x8F, 0x00, 0x80, 0x60, 0x01, 0xE0, 0xD5, 0x60, 0x84, 0xE7, 0xA1, 0xF3,
0x7C, 0x45, 0x60, 0x40, 0x01, 0x23, 0x02, 0x65, 0x8C, 0x60, 0x48, 0x6A, 0xFF, 0xFF, 0x01, 0x16,
0xFE, 0x01, 0x00, 0x60, 0x00, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x00, 0x60, 0x7F, 0x6A,
0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x84, 0x60, 0x04, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01,
0x48, 0x60, 0x08, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x65, 0x4A, 0xFF, 0xFF, 0x01, 0x16,
0xFE, 0x01, 0x84, 0x60, 0x04, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x40, 0x60, 0x08, 0x6A,
0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x65, 0x4A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x95, 0x60,
0x84, 0xE7, 0xBD, 0xFE, 0x0C, 0x60, 0x00, 0x62, 0x00, 0x60, 0x71, 0x7C, 0x00, 0x60, 0xB1, 0x65,
0x3D, 0x60, 0x58, 0x4D, 0x0F, 0x78, 0xFF, 0xFF, 0x08, 0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, 0xDC, 0x7A, 0xDC, 0xA1, 0xFF, 0x5A, 0xDC, 0x12, 0xE1, 0x02, 0x60, 0x01, 0xE1,
0xA1, 0xFF, 0x98, 0xFF, 0x80, 0x3E, 0x28, 0x40, 0x40, 0x2B, 0x03, 0x00, 0x29, 0x40, 0x20, 0x27,
0xA3, 0x00, 0xC8, 0x74, 0xCD, 0xE2, 0x29, 0x44, 0x08, 0xBC, 0x40, 0x49, 0x44, 0xFF, 0x05, 0xE1,
0xDB, 0xF3, 0x37, 0x60, 0xE8, 0x63, 0x03, 0xA8, 0x04, 0xA8, 0x06, 0x03, 0x05, 0x03, 0xA3, 0xD3,
0xFF, 0xFF, 0x01, 0xA8, 0x07, 0x18, 0x0A, 0x03, 0x28, 0x40, 0x08, 0x2A, 0x07, 0x00, 0x28, 0x40,
0x48, 0x36, 0x04, 0x00, 0xF1, 0xF3, 0xFF, 0xFF, 0x02, 0xBC, 0xF1, 0xFB, 0x29, 0x44, 0xFF, 0x60,
0xEF, 0x65, 0x24, 0x89, 0x40, 0x27, 0x3F, 0x00, 0x00, 0x00, 0x29, 0x40, 0x80, 0x27, 0x0B, 0x00,
0x07, 0x61, 0xA1, 0xFF, 0xCD, 0x81, 0x04, 0x25, 0x61, 0x00, 0x87, 0x4C, 0xFB, 0x02, 0xF3, 0x60,
0xA0, 0x64, 0x80, 0x4C, 0x07, 0x00, 0xA1, 0xFF, 0x9C, 0x4C, 0x9C, 0x4C, 0x9C, 0x4D, 0x05, 0x60,
0xCF, 0x64, 0x80, 0x4C, 0x28, 0x40, 0x40, 0x2B, 0x05, 0x00, 0x29, 0x40, 0x20, 0x27, 0x02, 0x00,
0x15, 0x60, 0x6F, 0x6B, 0x04, 0x25, 0x4A, 0x00, 0x30, 0x64, 0x3A, 0xDB, 0x44, 0xFF, 0x04, 0x25,
0x45, 0x00, 0x04, 0x60, 0x00, 0x65, 0x25, 0x44, 0xB4, 0x84, 0x80, 0x4E, 0x2D, 0x41, 0x04, 0x25,
0x3D, 0x00, 0x61, 0x4C, 0x00, 0x60, 0x8A, 0x65, 0xC5, 0x81, 0x61, 0x54, 0xA1, 0xFF, 0xFF, 0xFF,
0x04, 0x25, 0x34, 0x00, 0x67, 0x4E, 0x07, 0x64, 0x1C, 0xFB, 0x00, 0xE1, 0x02, 0x60, 0x05, 0xE1,
0xA1, 0xFF, 0x98, 0xFF, 0x80, 0x3E, 0x28, 0x40, 0x40, 0x27, 0x0A, 0x00, 0x1C, 0x65, 0x28, 0x40,
0xA4, 0x36, 0x14, 0x65, 0x23, 0x44, 0xC4, 0x84, 0x28, 0x40, 0x08, 0x2A, 0x0C, 0x00, 0x07, 0x00,
0x23, 0x44, 0x1C, 0xA4, 0x29, 0x40, 0x20, 0x27, 0x02, 0x00, 0x11, 0x60, 0x0F, 0x6B, 0x3C, 0x46,
0x98, 0xF0, 0x23, 0x44, 0xC4, 0x84, 0x06, 0x74, 0x25, 0x5C, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84,
0xE0, 0x84, 0xB0, 0x84, 0x80, 0x4C, 0x9C, 0x4C, 0x44, 0xFF, 0x18, 0xE1, 0x0A, 0x64, 0x1E, 0x74,
0x02, 0x60, 0x05, 0xE1, 0x40, 0x40, 0xA1, 0xFF, 0x98, 0xFF, 0x80, 0x3E, 0xC4, 0xE2, 0x27, 0x44,
0x20, 0x2A, 0x06, 0x00, 0x42, 0x64, 0x3A, 0xDB, 0x67, 0x4C, 0xB1, 0x60, 0xAD, 0x78, 0xFF, 0xFF,
0x41, 0x64, 0x3A, 0xDB, 0x62, 0xFF, 0x08, 0xE1, 0xE2, 0xFE, 0x72, 0x52, 0xA1, 0xFF, 0x98, 0xFF,
0x80, 0x3E, 0xA1, 0xFF, 0x98, 0xFF, 0x80, 0x3E, 0x28, 0x40, 0x08, 0x27, 0x5A, 0x01, 0x3C, 0x46,
0x8B, 0xFF, 0x84, 0x60, 0x00, 0xE4, 0x0F, 0x60, 0x90, 0x64, 0xC9, 0x60, 0x58, 0x4F, 0x56, 0x78,
0xFF, 0xFF, 0x3F, 0xF2, 0x00, 0x60, 0x18, 0x70, 0x18, 0x71, 0x20, 0x72, 0x00, 0xF2, 0x60, 0x53,
0x20, 0xE1, 0xA1, 0xFF, 0x88, 0x75, 0x00, 0xE1, 0xFF, 0xFF, 0x60, 0x50, 0x75, 0x44, 0x12, 0x71,
0x6E, 0x72, 0x81, 0x75, 0xFF, 0xFF, 0x88, 0xFF, 0xA3, 0x60, 0x21, 0x78, 0xFF, 0xFF, 0x32, 0xF3,
0x08, 0x29, 0x0A, 0x00, 0x60, 0x40, 0x07, 0x22, 0x07, 0x00, 0xFE, 0xB4, 0x32, 0xFB, 0x27, 0x44,
0x10, 0xBC, 0xF7, 0xB4, 0x40, 0x47, 0x43, 0xFF, 0x00, 0x64, 0x3A, 0xDB, 0x01, 0x60, 0x08, 0xE1,
0x31, 0x40, 0x01, 0x2A, 0x06, 0x00, 0x00, 0x64, 0x33, 0xFB, 0x01, 0x60, 0x0A, 0xE1, 0x25, 0x11,
0x24, 0x0A, 0xE5, 0xFE, 0x2D, 0x05, 0x32, 0x40, 0x80, 0x2A, 0x05, 0x00, 0x19, 0x60, 0xF2, 0xF3,
0xFF, 0xFF, 0x01, 0x18, 0x16, 0x00, 0x9F, 0xFE, 0x14, 0x05, 0x9D, 0xFE, 0x12, 0x04, 0x31, 0x41,
0x40, 0x2A, 0x0F, 0x00, 0x07, 0x60, 0xE9, 0xF1, 0xAE, 0x4C, 0x90, 0x80, 0x10, 0x2A, 0x09, 0x00,
0x7F, 0xB1, 0x07, 0x60, 0xE9, 0xFB, 0x60, 0x40, 0x10, 0x2A, 0x80, 0xB9, 0x41, 0x51, 0xDF, 0xFE,
0x19, 0xFF, 0x9F, 0xFE, 0x02, 0x04, 0x40, 0xE1, 0x08, 0x00, 0x7C, 0xE1, 0x31, 0x44, 0x01, 0x2A,
0x04, 0x00, 0xFD, 0xE1, 0x27, 0x44, 0x10, 0x26, 0x06, 0x00, 0xA1, 0xFF, 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0x40, 0x40, 0x2B, 0x14, 0x00, 0x61, 0x4C,
0x29, 0x60, 0xC0, 0x65, 0x61, 0x47, 0x1F, 0xB4, 0xE0, 0x84, 0xE0, 0x84, 0x44, 0xD3, 0x5A, 0xD1,
0x01, 0x60, 0x00, 0xE1, 0x01, 0x60, 0x09, 0x6B, 0x60, 0x4C, 0xB5, 0xFF, 0xFF, 0x60, 0xF2, 0x64,
0x64, 0x4C, 0x40, 0x43, 0x18, 0x00, 0x29, 0x47, 0x80, 0xB7, 0x34, 0x94, 0x60, 0x4C, 0x29, 0x60,
0xC0, 0x65, 0x61, 0x47, 0x1F, 0xB4, 0xE0, 0x84, 0xE0, 0x84, 0x44, 0xD3, 0x5A, 0xD1, 0x01, 0x60,
0x00, 0xE1, 0x05, 0x60, 0x69, 0x6B, 0x60, 0x4C, 0xB5, 0xFF, 0x64, 0x4C, 0x7C, 0x44, 0x29, 0x40,
0x80, 0x2B, 0x67, 0x44, 0x60, 0x4C, 0x40, 0xE1, 0x01, 0x60, 0x08, 0xE1, 0x28, 0x45, 0xBF, 0x60,
0xFF, 0x64, 0x24, 0x88, 0xC4, 0xE2, 0x08, 0x64, 0x3A, 0xDB, 0x21, 0x46, 0x2A, 0x44, 0x72, 0x45,
0x24, 0xFA, 0xB2, 0xF3, 0x06, 0x04, 0xE4, 0xE2, 0xDC, 0x9C, 0x29, 0x40, 0x01, 0x26, 0x64, 0x44,
0xB2, 0xF9, 0x25, 0xFA, 0xB3, 0xF3, 0x02, 0x04, 0xDC, 0x84, 0xB3, 0xFB, 0x28, 0xFA, 0xB4, 0xF3,
0x02, 0x04, 0xDC, 0x84, 0xB4, 0xFB, 0x29, 0xFA, 0x24, 0x44, 0x04, 0x2A, 0x06, 0x00, 0x28, 0x40,
0xA4, 0x36, 0x03, 0x00, 0xA6, 0x60, 0xB1, 0x78, 0xFF, 0xFF, 0x26, 0x43, 0x84, 0xBB, 0xFC, 0xB3,
0x21, 0x46, 0x01, 0x5D, 0x0F, 0xFC, 0x5C, 0x46, 0x05, 0xFF, 0x27, 0x44, 0x01, 0x2A, 0x13, 0x00,
0x50, 0xFE, 0x28, 0x40, 0x08, 0x3A, 0x12, 0x00, 0x2F, 0xF2, 0x30, 0xF0, 0x60, 0x43, 0x31, 0xF2,
0x22, 0x46, 0x64, 0x41, 0x2C, 0xF0, 0x2D, 0xF0, 0xD3, 0x80, 0x2E, 0xF0, 0xD1, 0x80, 0xD0, 0x80,
0x27, 0x44, 0x09, 0x0C, 0x03, 0x00, 0x27, 0x44, 0x06, 0x22, 0x05, 0x00, 0xB8, 0xB4, 0x40, 0x47,
0x02, 0x64, 0x31, 0xFB, 0xC0, 0xFE, 0xD4, 0x64, 0x40, 0x48, 0x0D, 0x64, 0x3A, 0xDB, 0x7C, 0x44,
0x1B, 0x60, 0xF0, 0xFB, 0x21, 0x46, 0x1C, 0xF2, 0x00, 0xE1, 0xF0, 0xFE, 0x00, 0x63, 0x28, 0x44,
0xA4, 0x36, 0x0A, 0x00, 0x04, 0x2B, 0x08, 0x00, 0x30, 0xF3, 0x2D, 0x45, 0xD4, 0x84, 0xCA, 0x65,
0xD4, 0x83, 0x01, 0x64, 0x1B, 0x60, 0xF0, 0xFB, 0xD4, 0x64, 0x35, 0x00, 0x0F, 0x64, 0x3A, 0xDB,
0x21, 0x46, 0x29, 0x40, 0x40, 0x27, 0x15, 0x00, 0x80, 0x27, 0x02, 0x00, 0xCA, 0x65, 0x01, 0x00,
0x6A, 0x65, 0x1C, 0xF2, 0xFF, 0xFF, 0x04, 0x7F, 0x40, 0x45, 0x0A, 0x36, 0x70, 0x64, 0x14, 0x36,
0x38, 0x64, 0x37, 0x36, 0x15, 0x64, 0x6E, 0x3A, 0x17, 0x00, 0x84, 0x7F, 0x40, 0x45, 0x0B, 0x64,
0x13, 0x00, 0x1C, 0xF2, 0x1E, 0x65, 0x40, 0x45, 0x0B, 0x36, 0x1E, 0x64, 0x0F, 0x36, 0x16, 0x64,
0x0A, 0x36, 0x12, 0x64, 0x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 0x44,
0xD4, 0x36, 0x03, 0x00, 0xA7, 0x60, 0xC8, 0x78, 0xFF, 0xFF, 0xA8, 0xE2, 0x27, 0x44, 0xFB, 0xB4,
0x40, 0x47, 0x1C, 0x42, 0x22, 0x46, 0x19, 0x60, 0xCF, 0xF3, 0xFF, 0xFF, 0x34, 0xFB, 0x2A, 0xF0,
0xF7, 0x60, 0xFF, 0x64, 0xA0, 0x84, 0xA2, 0xDA, 0x60, 0x40, 0x40, 0x2B, 0xC4, 0x00, 0x22, 0xF2,
0xFF, 0xFF, 0x60, 0x40, 0x22, 0x26, 0x3F, 0x00, 0x01, 0x26, 0x03, 0x00, 0x04, 0x26, 0x05, 0x00,
0xBA, 0x00, 0x04, 0x2B, 0xB8, 0x00, 0xA6, 0xF5, 0x01, 0x00, 0x07, 0xF4, 0x4B, 0xF2, 0xFF, 0xFF,
0xDC, 0x84, 0x4B, 0xFA, 0x0C, 0x60, 0xFC, 0x62, 0x80, 0xFF, 0xC8, 0x60, 0x78, 0x44, 0x02, 0xA4,
0xA2, 0xDB, 0x8C, 0x78, 0xFF, 0xFF, 0x82, 0xFF, 0xA6, 0xF3, 0x66, 0x5C, 0xD0, 0x80, 0x00, 0x7C,
0x07, 0x03, 0x66, 0x43, 0x22, 0x46, 0x22, 0xF2, 0x63, 0x46, 0x60, 0x40, 0x01, 0x2A, 0x01, 0x00,
0x3C, 0xF1, 0x4B, 0xF0, 0x64, 0x41, 0x64, 0x47, 0x60, 0x5F, 0x20, 0xBC, 0x80, 0x26, 0x80, 0xAC,
0x60, 0x47, 0x22, 0x46, 0x3A, 0xFA, 0x64, 0x44, 0x20, 0x7F, 0x34, 0x94, 0x3B, 0xFA, 0x08, 0x60,
0x00, 0xEA, 0x0F, 0x64, 0x60, 0x7F, 0xA0, 0x5A, 0x80, 0x60, 0x00, 0xEA, 0xA0, 0x60, 0x00, 0xEA,
0xD1, 0x60, 0x00, 0xEA, 0x80, 0x00, 0x2A, 0xF2, 0x00, 0x60, 0x7C,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0x32, 0x44, 0x00, 0x27,
0x03, 0x00, 0xA3, 0x60, 0xF4, 0x78, 0xFF, 0xFF, 0x0A, 0x64, 0x3A, 0xDB, 0xA3, 0x60, 0xF4, 0x78,
0xFF, 0xFF, 0x0E, 0x64, 0x3A, 0xDB, 0x3C, 0x44, 0x60, 0x46, 0x1E, 0xF0, 0x40, 0x42, 0x64, 0x40,
0x40, 0x27, 0x48, 0x00, 0x1F, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x40, 0x27, 0x3C, 0x00, 0x80, 0x2B,
0x0B, 0x00, 0xBF, 0x60, 0xFF, 0x65, 0x29, 0x44, 0x24, 0x89, 0x80, 0x60, 0x00, 0x65, 0x29, 0x44,
0x34, 0x89, 0x80, 0x60, 0x00, 0x63, 0x05, 0x00, 0x3F, 0x60, 0xFF, 0x65, 0x29, 0x44, 0x24, 0x89,
0x00, 0x63, 0x1E, 0xF2, 0x39, 0xF1, 0xC0, 0x60, 0xFF, 0xB5, 0x0A, 0x18, 0x60, 0x47, 0x1F, 0xB4,
0xD0, 0x84, 0xE0, 0xA0, 0x02, 0x0D, 0x00, 0x64, 0x02, 0x00, 0x01, 0x04, 0x1F, 0x64, 0x60, 0x47,
0xB4, 0x84, 0x07, 0x60, 0xEA, 0xF1, 0x3C, 0x94, 0xB0, 0x84, 0x60, 0x4C, 0x29, 0x60, 0xC0, 0x65,
0x60, 0x47, 0x1F, 0xB4, 0xE0, 0x84, 0xE0, 0x84, 0x44, 0xD3, 0x5A, 0xD1, 0x01, 0x60, 0x00, 0xE1,
0x05, 0x60, 0x69, 0x6B, 0x60, 0x4C, 0xB5, 0xFF, 0x64, 0x4C, 0x7C, 0x44, 0x29, 0x40, 0x80, 0x2B,
0x67, 0x44, 0x60, 0x4C, 0x32, 0x00, 0x19, 0x60, 0x7B, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x04, 0x26,
0xCB, 0x01, 0xBF, 0x01, 0x40, 0x60, 0x00, 0x65, 0x29, 0x44, 0x34, 0x89, 0x40, 0x60, 0x00, 0x63,
0x9F, 0xF2, 0x1E, 0xF2, 0x39, 0xF1, 0xC0, 0x60, 0xFF, 0xB5, 0x0A, 0x18, 0x60, 0x47, 0x1F, 0xB4,
0xD0, 0x84, 0xE0, 0xA0, 0x02, 0x0D, 0x00, 0x64, 0x02, 0x00, 0x01, 0x04, 0x1F, 0x64, 0x60, 0x47,
0xB4, 0x84, 0x07, 0x60, 0xEA, 0xF1, 0x3C, 0x94, 0xB0, 0x81, 0x61, 0x4C, 0x29, 0x60, 0xC0, 0x65,
0x61, 0x47, 0x1F, 0xB4, 0xE0, 0x84, 0xE0, 0x84, 0x44, 0xD3, 0x5A, 0xD1, 0x01, 0x60, 0x00, 0xE1,
0x01, 0x60, 0x09, 0x6B, 0x60, 0x4C, 0xB5, 0xFF, 0x64, 0x4C, 0x40, 0xE1, 0x01, 0x60, 0x08, 0xE1,
0x84, 0xFF, 0xC2, 0x60, 0x45, 0x64, 0x40, 0x42, 0x82, 0xFF, 0x2A, 0xF2, 0x10, 0x60, 0x00, 0x65,
0xA4, 0x84, 0xB4, 0xBC, 0x1E, 0xF0, 0x40, 0x48, 0x64, 0x40, 0x40, 0x27, 0x17, 0x00, 0x1C, 0xF2,
0xFF, 0xFF, 0x60, 0x40, 0x0A, 0x36, 0x06, 0x00, 0x14, 0x36, 0x07, 0x00, 0x37, 0x36, 0x08, 0x00,
0x6E, 0x36, 0x09, 0x00, 0x70, 0x7C, 0xA0, 0x63, 0x0F, 0x00, 0x38, 0x7C, 0x50, 0x63, 0x0C, 0x00,
0x15, 0x7C, 0x1E, 0x63, 0x09, 0x00, 0x0B, 0x7C, 0x0F, 0x63, 0x06, 0x00, 0x9C, 0xF4, 0xFF, 0x65,
0x63, 0x47, 0xA4, 0x9C, 0xA7, 0x84, 0x23, 0x00, 0x40, 0x45, 0x43, 0x4D, 0x00, 0xE1, 0xF0, 0xFE,
0x29, 0x40, 0x80, 0x2B, 0x03, 0x00, 0x00, 0x60, 0x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0x0B, 0x00, 0x07, 0xB4, 0x60, 0x40, 0x01, 0x36, 0x07, 0x00, 0x29, 0x44,
0xBF, 0x60, 0xFF, 0xB7, 0x80, 0xBF, 0x40, 0x49, 0x80, 0x67, 0x05, 0x00, 0x3F, 0x60, 0xFF, 0x65,
0x29, 0x44, 0x24, 0x89, 0x00, 0x64, 0x16, 0x60, 0x50, 0xF1, 0xFF, 0xFF, 0x19, 0x60, 0x55, 0xF9,
0x39, 0xF1, 0x16, 0x60, 0x3C, 0xF1, 0x64, 0x41, 0x64, 0x5E, 0x60, 0x45, 0x64, 0x47, 0x1F, 0xB4,
0x54, 0x94, 0xE0, 0xA0, 0x02, 0x0D, 0x00, 0x64, 0x02, 0x00, 0x01, 0x04, 0x1F, 0x64, 0x60, 0x47,
0x07, 0x60, 0xEA, 0xF1, 0xB4, 0x84, 0xB0, 0x8C, 0x29, 0x60, 0xC0, 0x7C, 0x60, 0x47, 0x1F, 0xB4,
0xE0, 0x84, 0xE0, 0x84, 0x40, 0xD3, 0x5A, 0xD1, 0x01, 0x60, 0x00, 0xE1, 0x05, 0x60, 0x69, 0x6B,
0x60, 0x4C, 0xB5, 0xFF, 0x64, 0x4C, 0x7C, 0x44, 0x29, 0x40, 0x80, 0x2B, 0x67, 0x44, 0x60, 0x4C,
0x40, 0xE1, 0x01, 0x60, 0x08, 0xE1, 0x84, 0xFF, 0xC2, 0x60, 0x45, 0x64, 0x40, 0x42, 0x82, 0xFF,
0x3C, 0x44, 0x60, 0x46, 0x40, 0x42, 0x13, 0x64, 0x3A, 0xDB, 0x10, 0x60, 0x00, 0x65, 0x3C, 0x46,
0x2A, 0xF2, 0x19, 0x60, 0x3B, 0xF1, 0xA4, 0x84, 0xC4, 0xBC, 0x40, 0x48, 0x64, 0x44, 0x04, 0x26,
0x09, 0x00, 0x02, 0x26, 0x0A, 0x00, 0x01, 0x26, 0x0B, 0x00, 0x08, 0x2A, 0x03, 0x00, 0x0B, 0x63,
0x6E, 0x64, 0x08, 0x00, 0x15, 0x63, 0x37, 0x64, 0x05, 0x00, 0x38, 0x63, 0x14, 0x64, 0x02, 0x00,
0x70, 0x63, 0x0A, 0x64, 0x43, 0x4D, 0x40, 0x45, 0x00, 0xE1, 0xF0, 0xFE, 0x00, 0x60, 0x1E, 0x64,
0x1B, 0xF0, 0x11, 0xF0, 0xC0, 0x84, 0xC0, 0x84, 0x60, 0x43, 0x28, 0x44, 0xA1, 0xFF, 0x12, 0x74,
0x80, 0x4E, 0x12, 0x74, 0x83, 0x4C, 0x9A, 0xFF, 0x12, 0x74, 0x5C, 0x62, 0x7A, 0xD4, 0x12, 0x74,
0x7A, 0xD4, 0x12, 0x74, 0x7A, 0xD4, 0x12, 0x74, 0xA1, 0xFF, 0x98, 0xFF, 0xB2, 0x60, 0x58, 0x4F,
0x2D, 0x78, 0xFF, 0xFF, 0x01, 0x60, 0x18, 0xE1, 0x78, 0x44, 0x03, 0xA4, 0x35, 0xFB, 0xB2, 0x60,
0x70, 0x78, 0xFF, 0xFF, 0xC4, 0xE2, 0x08, 0x64, 0x3A, 0xDB, 0xA4, 0x60, 0xBF, 0x78, 0xFF, 0xFF,
0x26, 0x43, 0x24, 0x40, 0x01, 0x2A, 0x0E, 0x00, 0x1D, 0xFF, 0x26, 0x44, 0x02, 0xBC, 0x40, 0x46,
0x27, 0x44, 0x07, 0x22, 0x05, 0x00, 0xF8, 0xB4, 0x40, 0x47, 0x06, 0x64, 0x31, 0xFB, 0xC0, 0xFE,
0x30, 0xF1, 0x81, 0x00, 0xFC, 0xB3, 0x32, 0x40, 0x01, 0x2A, 0x06, 0x00, 0x0A, 0xBB, 0x0F, 0xFC,
0xCB, 0xFE, 0xA3, 0x60, 0xF4, 0x78, 0xFF, 0xFF, 0x24, 0x44, 0x04, 0x26, 0x29, 0x00, 0x0F, 0xFC,
0x05, 0xFF, 0xDB, 0xF3, 0x28, 0x40, 0x80, 0x3A, 0x23, 0x00, 0x60, 0x40, 0x03, 0x3A, 0x20, 0x00,
0x32, 0xF2, 0x7F, 0xF1, 0x33, 0xF2, 0xD0, 0x80, 0x80, 0xF1, 0x1A, 0x02, 0xD0, 0x80, 0x34, 0xF2,
0x81, 0xF1, 0x16, 0x02, 0xD0, 0x80, 0x3C, 0x44, 0x13, 0x02, 0xAC, 0x86, 0xBB, 0xFE, 0x10, 0x03,
0x2A, 0xF2, 0x21, 0x46, 0x60, 0x40, 0x80, 0x3A, 0x0B, 0x00, 0x01, 0x64, 0x31, 0xFB, 0xC0, 0xFE,
0x00, 0x64, 0x32, 0xFB, 0x43, 0xFF, 0x84, 0xFF, 0xC2, 0x60, 0x45, 0x64, 0x40, 0x42, 0x82, 0xFF,
0x30, 0xF1, 0x27, 0x44, 0x05, 0x22, 0x34, 0x00, 0xFA, 0xB4, 0x40, 0x47, 0x24, 0x44, 0x10, 0x2A,
0x2B, 0x00, 0x28, 0x40, 0xD4, 0x3A, 0x28, 0x00, 0x31, 0x40, 0x08, 0x26, 0x00, 0x7C, 0x29, 0x40,
0x50, 0x2B, 0x0D, 0x00, 0xEF, 0x60, 0xFF, 0x65, 0x29, 0x44, 0x24, 0x89, 0x31, 0x40, 0x08, 0x2A,
0x06, 0x00, 0x1C, 0x60, 0x11, 0xF3, 0xFF, 0xFF, 0xE0, 0x85, 0x2B, 0x44, 0x05, 0x05, 0x2B, 0x44,
0xFF, 0xA4, 0x01, 0xA4, 0x04, 0x24, 0x00, 0x64, 0xD0, 0x80, 0x70, 0x45, 0x02, 0x28, 0x64, 0x44,
0xC4, 0x84, 0xFF, 0xFF, 0x04, 0x24, 0x00, 0xB4, 0x60, 0x50, 0x08, 0x28, 0x01, 0x00, 0x20, 0x29,
0x6D, 0xE2, 0xA5, 0x60, 0x7F, 0x78, 0xFF, 0xFF, 0x02, 0x64, 0x31, 0xFB, 0xC0, 0xFE, 0x07, 0x00,
0x02, 0x2A, 0x05, 0x00, 0xFD, 0xB4, 0x40, 0x47, 0x06, 0x64, 0x31, 0xFB, 0xC0, 0xFE, 0x05, 0x64,
0x3A, 0xDB, 0x28, 0x44, 0xA4, 0x3A, 0x07, 0x00, 0x01, 0x60, 0x02, 0x7C, 0x25, 0x44, 0x0A, 0x3A,
0x02, 0x00, 0x01, 0x60, 0x3A, 0x7C, 0x31, 0x40, 0x08, 0x26, 0x00, 0x7C, 0x29, 0x40, 0x50, 0x2B,
0x0D, 0x00, 0xEF, 0x60, 0xFF, 0x65, 0x29, 0x44, 0x24, 0x89, 0x31, 0x40, 0x08, 0x2A, 0x06, 0x00,
0x1C, 0x60, 0x11, 0xF3, 0xFF, 0xFF, 0xE0, 0x85, 0x2B, 0x44, 0x05, 0x05, 0x2B, 0x44, 0xFF, 0xA4,
0x01, 0xA4, 0x04, 0x24, 0x00, 0x64, 0xD0, 0x80, 0x70, 0x45, 0x02, 0x28, 0x64, 0x44, 0xC4, 0x84,
0xFF, 0xFF, 0x04, 0x24, 0x00, 0xB4, 0x28, 0x40, 0xE4, 0x36, 0x00, 0xB4, 0x60, 0x50, 0x08, 0x28,
0x01, 0x00, 0x20, 0x29, 0x6D, 0xE2, 0xA3, 0x60, 0xE7, 0x78, 0xFF, 0xFF, 0x27, 0x44, 0x05, 0x22,
0x09, 0x00, 0xBA, 0xB4, 0x40, 0x47, 0x3C, 0x46, 0x02, 0x64, 0x31, 0xFB, 0xC0, 0xFE, 0xA3, 0x60,
0xF4, 0x78, 0xFF, 0xFF, 0x27, 0x44, 0x02, 0x2A, 0x06, 0x00, 0xFD, 0xB4, 0x40, 0x47, 0x06, 0x64,
0x31, 0xFB, 0xC0, 0xFE, 0xF4, 0x01, 0xF3, 0x0A, 0x7C, 0x50, 0x6D, 0xE2, 0xF0, 0x01, 0x72, 0x45,
0xDC, 0x84, 0xB2, 0xFB, 0x11, 0x64, 0x3A, 0xDB, 0xB3, 0xF3, 0x06, 0x04, 0xDC, 0x84, 0xB3, 0xFB,
0xB4, 0xF3, 0x02, 0x04, 0xDC, 0x84, 0xB4, 0xFB, 0xA4, 0x60, 0x01, 0x78, 0xFF, 0xFF, 0x00, 0x61,
0x12, 0x64, 0x3A, 0xDB, 0x20, 0x60, 0x04, 0x63, 0xBD, 0xD3, 0x72, 0x45, 0x44, 0x8A, 0x02, 0x28,
0x03, 0x00, 0xE4, 0xE2, 0xDD, 0x81, 0x04, 0x00, 0x02, 0x28, 0x02, 0x00, 0xE4, 0xE2, 0xDD, 0x81,
0xBD, 0xD3, 0xB2, 0xF1, 0x61, 0x45, 0xC0, 0x84, 0x00, 0x61, 0x02, 0x24, 0x01, 0xB9, 0xC4, 0x84,
0x60, 0x55, 0x2A, 0x52, 0xE4, 0xE2, 0xB2, 0xFB, 0x02, 0x24, 0x01, 0xB9, 0xBD, 0xD3, 0xB3, 0xF1,
0x61, 0x45, 0xC0, 0x84, 0x00, 0x61, 0x02, 0x24, 0x01, 0xB9, 0xC4, 0x84, 0xB3, 0xFB, 0x02, 0x24,
0x01, 0xB9, 0xBD, 0xD3, 0xB4, 0xF1, 0x61, 0x45, 0xC0, 0x84, 0xC4, 0x84, 0xB4, 0xFB, 0xA5, 0x60,
0x14, 0x78, 0xFF, 0xFF, 0xB0, 0x60, 0x9E, 0x78, 0xFF, 0xFF, 0x47, 0xFF, 0x1B, 0x60, 0xEE, 0xF3,
0xFF, 0xFF, 0x04, 0x18, 0xAE, 0x4F, 0x08, 0xBC, 0x00, 0x7F, 0xA0, 0x5E, 0xC8, 0x74, 0xCD, 0xE2,
0xAA, 0x60, 0xB9, 0x78, 0x00, 0x61, 0xA3, 0x60, 0xF4, 0x78, 0xFF, 0xFF, 0xAB, 0x60, 0xE8, 0x78,
0xFF, 0xFF, 0x21, 0x46, 0x5C, 0x44, 0x26, 0x44, 0x02, 0x26, 0x01, 0x00, 0x3E, 0x46, 0x09, 0xF2,
0x46, 0x41, 0x66, 0x40, 0xF3, 0x18, 0x40, 0x5E, 0xFD, 0xFB, 0x02, 0x64, 0x40, 0x46, 0x41, 0x5D,
0x00, 0x64, 0x31, 0xFA, 0x00, 0xF2, 0x46, 0x45, 0x87,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80, 0x9A, 0xFF, 0x03, 0x07, 0xAB, 0x60, 0xDE, 0x78, 0xFF, 0xFF, 0x25, 0x44,
0x01, 0x26, 0x0F, 0xAC, 0x26, 0x60, 0x4A, 0x65, 0x44, 0xD3, 0x12, 0x65, 0x45, 0x46, 0x60, 0x47,
0x40, 0x7F, 0x27, 0xFA, 0x8F, 0xFC, 0x18, 0x61, 0xEA, 0xF1, 0xA1, 0xFF, 0x6C, 0x44, 0xDC, 0x80,
0xFF, 0xFF, 0x21, 0x03, 0x50, 0xFE, 0xAC, 0x60, 0xC1, 0x78, 0xFF, 0xFF, 0xC8, 0x60, 0x0B, 0x7D,
0x08, 0x60, 0x00, 0x6B, 0xB5, 0xFF, 0xB7, 0xFF, 0xB4, 0xFF, 0xAA, 0x74, 0xCD, 0xE2, 0x01, 0x64,
0x89, 0xFF, 0x60, 0x54, 0x88, 0xFF, 0x01, 0x60, 0x08, 0xE1, 0x05, 0xE1, 0xA1, 0xFF, 0xFF, 0xFF,
0x04, 0x25, 0x8B, 0x00, 0x6C, 0x44, 0x0A, 0x36, 0x07, 0x00, 0x14, 0x36, 0x05, 0x00, 0x37, 0x36,
0x03, 0x00, 0x6E, 0x36, 0x01, 0x00, 0x81, 0x00, 0x40, 0x45, 0x32, 0x74, 0xA1, 0xFF, 0x1C, 0xFA,
0x40, 0x4E, 0x8C, 0x44, 0x60, 0x43, 0x1D, 0xFA, 0x01, 0xE1, 0x20, 0x64, 0x3A, 0xDB, 0x2E, 0x44,
0x14, 0x36, 0x12, 0x00, 0x0A, 0x36, 0x0F, 0x00, 0x63, 0x45, 0xE3, 0x83, 0xE3, 0x83, 0xC7, 0x83,
0xE3, 0x83, 0xC7, 0x83, 0xFF, 0xFF, 0x37, 0x36, 0x05, 0x00, 0x6E, 0x36, 0x04, 0x00, 0xAC, 0x60,
0xBF, 0x78, 0xFF, 0xFF, 0xEB, 0x83, 0xEB, 0x83, 0xEB, 0x83, 0xEB, 0x83, 0xFF, 0xFF, 0x80, 0x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21, 0x64, 0x3A, 0xDB, 0xBD, 0x01,
0xAC, 0xE2, 0x01, 0x64, 0x33, 0xFB, 0x01, 0xE1, 0x3F, 0x60, 0xCF, 0x65, 0x29, 0x44, 0x24, 0x89,
0x2E, 0x44, 0x00, 0x36, 0x21, 0x00, 0x01, 0x3A, 0xF0, 0x01, 0x88, 0xFF, 0x40, 0x67, 0x29, 0x45,
0x34, 0x89, 0xA1, 0xFF, 0x6C, 0x45, 0x65, 0x44, 0x0F, 0xB4, 0x40, 0x45, 0x65, 0x44, 0x29, 0x41,
0xF9, 0x81, 0x52, 0x4A, 0x71, 0x89, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x83, 0x0E, 0x7C,
0xD3, 0x80, 0xFF, 0xFF, 0x03, 0x03, 0xAB, 0x60, 0xDE, 0x78, 0xFF, 0xFF, 0xA1, 0xFF, 0x6C, 0x44,
0xDC, 0x80, 0xFF, 0xFF, 0xD2, 0x03, 0x41, 0x00, 0xC8, 0x60, 0x0B, 0x7D, 0x08, 0x60, 0x00, 0x6B,
0xB5, 0xFF, 0xB7, 0xFF, 0xB4, 0xFF, 0xAA, 0x74, 0xCD, 0xE2, 0x01, 0x60, 0x08, 0xE1, 0x05, 0xE1,
0xA1, 0xFF, 0xFF, 0xFF, 0x04, 0x25, 0xC1, 0x01, 0x6C, 0x44, 0x0A, 0x36, 0x07, 0x00, 0x14, 0x36,
0x05, 0x00, 0x37, 0x36, 0x03, 0x00, 0x6E, 0x36, 0x01, 0x00, 0xB7, 0x01, 0x40, 0x45, 0x32, 0x74,
0xA1, 0xFF, 0x40, 0x4E, 0x8C, 0x44, 0x60, 0x43, 0x01, 0xE1, 0x20, 0x64, 0x3A, 0xDB, 0x2E, 0x44,
0x14, 0x36, 0x09, 0x00, 0x0A, 0x36, 0x07, 0x00, 0x37, 0x36, 0x05, 0x00, 0x6E, 0x36, 0x03, 0x00,
0xAC, 0x60, 0xBF, 0x78, 0xFF, 0xFF, 0x01, 0x64, 0x51, 0xFB, 0xA1, 0xFF, 0x29, 0x41, 0xF9, 0x81,
0x52, 0x4A, 0x71, 0x89, 0x0E, 0x7C, 0xD3, 0x80, 0x43, 0x43, 0x03, 0x03, 0xAB, 0x60, 0xDE, 0x78,
0xFF, 0xFF, 0x6C, 0x40, 0xFF, 0xFF, 0x01, 0x15, 0x90, 0x01, 0x12, 0x64, 0x40, 0x46, 0xEA, 0xF1,
0x50, 0xFE, 0xA1, 0xFF, 0x12, 0x61, 0x8C, 0x44, 0xEB, 0xF0, 0x40, 0x48, 0x8C, 0x44, 0x30, 0xFB,
0x04, 0x61, 0x50, 0xFE, 0x8C, 0x44, 0xD0, 0x80, 0x8C, 0x44, 0xD4, 0x80, 0x8C, 0x44, 0xEC, 0xF1,
0x00, 0x65, 0xD0, 0x80, 0x28, 0x44, 0x01, 0x0C, 0x13, 0x00, 0x10, 0x65, 0x60, 0x40, 0xC4, 0x36,
0x04, 0x00, 0xD4, 0x3A, 0x0D, 0x00, 0x27, 0x40, 0x40, 0x26, 0x30, 0x65, 0x35, 0x84, 0xA1, 0xFF,
0x8C, 0x44, 0x47, 0xFF, 0x50, 0x4B, 0x67, 0x50, 0x69, 0xE2, 0x6A, 0x44, 0x40, 0x2B, 0x09, 0x15,
0x2C, 0x60, 0xEC, 0x64, 0xF1, 0x60, 0x78, 0x41, 0xE4, 0x78, 0xB5, 0xF1, 0x2A, 0x64, 0x3A, 0xDB,
0x1C, 0x01, 0x29, 0x40, 0x10, 0x26, 0x02, 0x00, 0x04, 0x74, 0xCD, 0xE2, 0x8C, 0x44, 0xB6, 0xFF,
0xB7, 0xFF, 0x01, 0x60, 0x18, 0xE1, 0x05, 0xE1, 0x00, 0x64, 0x33, 0xFB, 0xA1, 0xFF, 0x6C, 0x44,
0xA1, 0xFF, 0x6C, 0x44, 0x29, 0x40, 0x40, 0x2B, 0x03, 0x00, 0xB6, 0xFF, 0xA1, 0xFF, 0x6C, 0x44,
0xA1, 0xFF, 0x02, 0x74, 0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F,
0x11, 0xBC, 0x40, 0x44, 0x28, 0x45, 0xBF, 0x60, 0xFF, 0x64, 0x24, 0x88, 0x55, 0x00, 0x30, 0xBC,
0x40, 0x44, 0x22, 0xF0, 0x40, 0x60, 0x00, 0x64, 0xB0, 0x84, 0xA2, 0xDA, 0x4D, 0x00, 0x20, 0xB9,
0x5C, 0x8E, 0xA1, 0xFF, 0x8C, 0x44, 0x2D, 0xFA, 0xDC, 0x9C, 0x6C, 0x44, 0x00, 0xE1, 0xF2, 0xFE,
0x2E, 0xFA, 0x08, 0x28, 0x44, 0x4E, 0xDC, 0x84, 0x2E, 0x5C, 0xB0, 0x84, 0xEF, 0xB1, 0x08, 0x24,
0x40, 0xB9, 0x41, 0x46, 0x39, 0x00, 0x23, 0x41, 0x13, 0x64, 0x51, 0x90, 0x56, 0x63, 0x03, 0x04,
0xAB, 0x60, 0xDE, 0x78, 0xFF, 0xFF, 0x8C, 0x44, 0x04, 0x61, 0x2B, 0xFA, 0x50, 0xFE, 0x80, 0x27,
0x00, 0x64, 0x30, 0xFB, 0x8C, 0x44, 0x2C, 0xFA, 0xD0, 0x80, 0x8C, 0x44, 0x2D, 0xFA, 0xD4, 0x80,
0x00, 0x65, 0x8C, 0x44, 0xEC, 0xF1, 0x2E, 0xFA, 0xD0, 0x80, 0x28, 0x44, 0x03, 0x0C, 0xA0, 0x2A,
0x0A, 0x00, 0x11, 0x00, 0x10, 0x65, 0x60, 0x40, 0xC4, 0x36, 0x04, 0x00, 0xD4, 0x3A, 0x08, 0x00,
0x27, 0x40, 0x40, 0x26, 0x30, 0x65, 0x00, 0x64, 0x3F, 0xFA, 0x46, 0x4E, 0x35, 0x84, 0x64, 0x00,
0x40, 0x26, 0xF9, 0x01, 0x30, 0x65, 0x7A, 0xDC, 0x7A, 0xDC, 0x7A, 0xDC, 0x04, 0x61, 0xF3, 0x01,
0xA1, 0xFF, 0xAB, 0x60, 0xA5, 0x78, 0xFF, 0xFF, 0xFF, 0x60, 0xFE, 0x65,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,
0x00, 0x65, 0x6C, 0x44, 0x1A, 0xFA, 0x09, 0x00, 0x65, 0x44, 0x0F, 0xB4, 0x06, 0xA8, 0x80, 0x60,
0x00, 0x65, 0x08, 0x28, 0x7C, 0x45, 0x29, 0x44, 0x34, 0x89, 0x00, 0x64, 0x33, 0xFB, 0x40, 0x21,
0x00, 0x00, 0xAC, 0xE2, 0x05, 0xE1, 0x27, 0xF0, 0x65, 0x44, 0x64, 0x5E, 0x27, 0xFA, 0x28, 0x44,
0x8F, 0xB0, 0x88, 0x3A, 0x09, 0x00, 0x39, 0xF2, 0xFF, 0xFF, 0x60, 0xB0, 0x20, 0x3A, 0x04, 0x00,
0x24, 0x44, 0xFF, 0x60, 0xDF, 0xB4, 0x40, 0x44, 0x28, 0x40, 0x03, 0x26, 0xE2, 0x00, 0x31, 0x40,
0x20, 0x2A, 0x03, 0x00, 0x28, 0x40, 0x50, 0x3A, 0xDC, 0x00, 0x24, 0x44, 0x20, 0x2A, 0xD9, 0x00,
0x29, 0x40, 0x50, 0x2B, 0x0D, 0x00, 0xEF, 0x60, 0xFF, 0x65, 0x29, 0x44, 0x24, 0x89, 0x31, 0x40,
0x08, 0x2A, 0x06, 0x00, 0x1C, 0x60, 0x11, 0xF3, 0xFF, 0xFF, 0xE0, 0x85, 0x2B, 0x44, 0x06, 0x05,
0x2B, 0x44, 0xFF, 0xA4, 0x01, 0xA4, 0x04, 0x24, 0x00, 0x64, 0x40, 0x4B, 0xAC, 0x80, 0x28, 0x40,
0xB4, 0x3A, 0x03, 0x00, 0x02, 0x03, 0x30, 0xFB, 0xBC, 0x00, 0x28, 0x44, 0xBF, 0x60, 0xFF, 0x65,
0xA4, 0x84, 0x40, 0x48, 0x2B, 0x50, 0xA1, 0xFF, 0xFF, 0xFF, 0x01, 0x60, 0x08, 0xE1, 0x1C, 0xF2,
0xC4, 0xE2, 0x40, 0x45, 0x28, 0x40, 0xC4, 0x36, 0x9C, 0x00, 0x29, 0x40, 0x40, 0x2B, 0x48, 0x00,
0x32, 0x60, 0xFA, 0x63, 0x60, 0x40, 0x0B, 0x36, 0x20, 0x00, 0x0F, 0x36, 0x1B, 0x00, 0x0A, 0x36,
0x16, 0x00, 0x0E, 0x36, 0x11, 0x00, 0x09, 0x36, 0x0C, 0x00, 0x0D, 0x36, 0x07, 0x00, 0x08, 0x36,
0x02, 0x00, 0xA3, 0xD3, 0x15, 0x00, 0x02, 0xA3, 0xA3, 0xD3, 0x12, 0x00, 0x04, 0xA3, 0xA3, 0xD3,
0x0F, 0x00, 0x06, 0xA3, 0xA3, 0xD3, 0x0C, 0x00, 0x08, 0xA3, 0xA3, 0xD3, 0x09, 0x00, 0x0A, 0xA3,
0xA3, 0xD3, 0x06, 0x00, 0x0C, 0xA3, 0xA3, 0xD3, 0x03, 0x00, 0x0E, 0xA3, 0xA3, 0xD3, 0xFF, 0xFF,
0x2C, 0x60, 0x7C, 0x63, 0x60, 0x40, 0x0C, 0x36, 0x19, 0x00, 0x08, 0x36, 0x15, 0x00, 0x0D, 0x36,
0x11, 0x00, 0x09, 0x36, 0x0D, 0x00, 0x0E, 0x36, 0x09, 0x00, 0x0A, 0x36, 0x05, 0x00, 0x0F, 0x36,
0x01, 0x00, 0x39, 0x00, 0x02, 0xA3, 0x37, 0x00, 0x04, 0xA3, 0x35, 0x00, 0x06, 0xA3, 0x33, 0x00,
0x08, 0xA3, 0x31, 0x00, 0x0A, 0xA3, 0x2F, 0x00, 0x0C, 0xA3, 0x2D, 0x00, 0x0E, 0xA3, 0x2B, 0x00,
0x33, 0x60, 0x0A, 0x63, 0x25, 0x44, 0x0A, 0x36, 0x0C, 0x00, 0x14, 0x36, 0x07, 0x00, 0x37, 0x36,
0x02, 0x00, 0xA3, 0xD3, 0x09, 0x00, 0x02, 0xA3, 0xA3, 0xD3, 0x06, 0x00, 0x04, 0xA3, 0xA3, 0xD3,
0x03, 0x00, 0x06, 0xA3, 0xA3, 0xD3, 0xFF, 0xFF, 0x40, 0x45, 0x0A, 0x36, 0x0D, 0x00, 0x14, 0x36,
0x38, 0x64, 0x37, 0x3A, 0x03, 0x00, 0x04, 0x7F, 0x40, 0x45, 0x15, 0x64, 0x6E, 0x3A, 0x09, 0x00,
0x84, 0x7F, 0x40, 0x45, 0x0B, 0x64, 0x05, 0x00, 0x29, 0x44, 0x7F, 0x60, 0xFF, 0xB4, 0x40, 0x49,
0x70, 0x64, 0x40, 0x4D, 0x02, 0x00, 0x40, 0x45, 0x0A, 0x00, 0x2C, 0x60, 0x74, 0x63, 0x0A, 0x36,
0x06, 0x00, 0x14, 0x36, 0x02, 0xA3, 0x37, 0x36, 0x04, 0xA3, 0x6E, 0x36, 0x06, 0xA3, 0x28, 0xA3,
0xA3, 0xD1, 0xD8, 0xA3, 0x19, 0x60, 0x55, 0xF9, 0x39, 0xF1, 0xA3, 0xD1, 0x64, 0x41, 0x64, 0x5E,
0x60, 0x45, 0x64, 0x47, 0x1F, 0xB4, 0x54, 0x94, 0xE0, 0xA0, 0x02, 0x0D, 0x00, 0x64, 0x02, 0x00,
0x01, 0x04, 0x1F, 0x64, 0x60, 0x47, 0xB4, 0x85, 0x29, 0x44, 0xC0, 0x60, 0x00, 0xB4, 0xB4, 0x84,
0x1F, 0xFA, 0xB5, 0xFF, 0xA1, 0xFF, 0xCB, 0xF3, 0xC4, 0xE2, 0x89, 0xFF, 0x60, 0x54, 0x88, 0xFF,
0xDC, 0x84, 0xE0, 0x94, 0xFF, 0x60, 0xCF, 0x65, 0x29, 0x44, 0x24, 0x89, 0xA5, 0x60, 0x88, 0x78,
0x04, 0xE1, 0xA1, 0xFF, 0xFF, 0xFF, 0xC4, 0xE2, 0xA1, 0xFF, 0xFF, 0x60, 0xCF, 0x65, 0x29, 0x44,
0x24, 0x89, 0xCB, 0xF3, 0xC4, 0xE2, 0x89, 0xFF, 0x60, 0x54, 0x88, 0xFF, 0xDC, 0x84, 0xE0, 0x94,
0x26, 0x44, 0x84, 0xBC, 0x24, 0x40, 0x0C, 0x22, 0xFD, 0xB4, 0x40, 0x46, 0x23, 0x64, 0x3A, 0xDB,
0xAD, 0x60, 0x4F, 0x78, 0xFF, 0xFF, 0x27, 0x40, 0x26, 0x22, 0x05, 0x00, 0xF8, 0xB4, 0x40, 0x47,
0x06, 0x64, 0x31, 0xFB, 0xC0, 0xFE, 0x29, 0x40, 0x10, 0x26, 0x02, 0x00, 0x04, 0x74, 0xCD, 0xE2,
0x01, 0x60, 0x18, 0xE1, 0x01, 0x60, 0x18, 0xE1, 0x01, 0x11, 0x12, 0x00, 0x29, 0x44, 0x20, 0xBC,
0x40, 0x49, 0x01, 0x64, 0x33, 0xFB, 0xB6, 0xFF, 0x00, 0xE1, 0x01, 0x60, 0x1A, 0xE1, 0xA1, 0xFF,
0xFF, 0xFF, 0x6C, 0x40, 0xFC, 0x11, 0x01, 0x60, 0x18, 0xE1, 0xAE, 0x4F, 0xF7, 0xB4, 0xA0, 0x5E,
0xB5, 0xFF, 0x47, 0xFF, 0xB6, 0xFF, 0xB7, 0xFF, 0xB4, 0xFF, 0xC8, 0x60, 0x09, 0x7D, 0x7C, 0x4B,
0x29, 0x40, 0x50, 0x2B, 0x1B, 0x00, 0x31, 0x40, 0x08, 0x2A, 0x0D, 0x00, 0x1C, 0x60, 0x11, 0xF3,
0xFF, 0xFF, 0xE0, 0x85, 0x2B, 0x44, 0x07, 0x04, 0x70, 0x45, 0xC4, 0x84, 0xEF, 0x60, 0xFF, 0x65,
0x29, 0x44, 0x24, 0x89, 0x11, 0x00, 0x2B, 0x44, 0x70, 0x45, 0xC4, 0x84, 0xFF, 0xFF, 0x04, 0x24,
0x00, 0xB4, 0x40, 0x4B, 0xEF, 0x60, 0xFF, 0x65, 0x29, 0x44, 0x24, 0x89, 0x37, 0xF3, 0x2B, 0x45,
0xD4, 0x80, 0xFF, 0xFF, 0x02, 0x28, 0x65, 0x44, 0x60, 0x50, 0xA0, 0x4C, 0x20, 0xBC, 0xFF, 0xB4,
0xA0, 0x51, 0x00, 0x60, 0x2E, 0x7C, 0x74, 0x44, 0xC0, 0x94, 0x32, 0x40, 0x02, 0x2A, 0x19, 0x00,
0x28, 0x44, 0xA4, 0x36, 0x03, 0x00, 0x0C, 0xB4, 0x04, 0x36, 0x13, 0x00, 0x26, 0x43, 0xFD, 0xB3,
0x04, 0xBB, 0x43, 0x46, 0x01, 0x2A, 0x03, 0x00, 0x28, 0x47, 0x40, 0xBF, 0x40, 0x48, 0x0A, 0xBB,
0x0F, 0xFC, 0x50, 0x4B, 0x67, 0x50, 0x00, 0x64, 0x30, 0xFB, 0x05, 0xFF, 0xAD, 0x60, 0x4F, 0x78,
0xFF, 0xFF, 0x24, 0x64, 0x3A, 0xDB, 0x28, 0x44, 0x04, 0x2A, 0x03, 0x00, 0xA3, 0x60, 0xE7, 0x78,
0xFF, 0xFF, 0x32, 0x40, 0x04, 0x2A, 0x1C, 0x00, 0x28, 0x44, 0x0C, 0xB0, 0x08, 0x3A, 0x18, 0x00,
0x2C, 0xF0, 0x22, 0xF0, 0x64, 0x40, 0x01, 0x26, 0x0B, 0x00, 0x64, 0x40, 0x40, 0x2B, 0x10, 0x00,
0x8F, 0xB0, 0x88, 0x3A, 0x0D, 0x00, 0x39, 0xF2, 0xFF, 0xFF, 0x60, 0xB0, 0x20, 0x3A, 0x08, 0x00,
0x26, 0x44, 0xFD, 0xB4, 0x04, 0xBC, 0x40, 0x46, 0xFC, 0xB4, 0x0F, 0xFA, 0x05, 0xFF, 0x01, 0x00,
0x1D, 0xFF, 0x01, 0xE2, 0x26, 0x40, 0x10, 0x2A, 0x06, 0x00, 0x2C, 0x60, 0xEA, 0x64, 0xF1, 0x60,
0x78, 0x41, 0xE4, 0x78, 0xB5, 0xF1, 0xA3, 0x60, 0xE7, 0x78, 0xFF, 0xFF, 0x03, 0x0A, 0xA3, 0x60,
0xF4, 0x78, 0xFF, 0xFF, 0x01, 0x64, 0x51, 0xFB, 0x1B, 0x60, 0xEE, 0xF3, 0xFF, 0xFF, 0x04, 0x18,
0xAE, 0x4F, 0x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 0x04, 0xF4, 0x23, 0x43, 0xA1, 0xFF, 0x12, 0x74,
0xA0, 0xD2, 0xFE, 0xA1, 0xCB, 0x83, 0x60, 0x4E, 0xAF, 0x83, 0x03, 0x1D, 0x05, 0x03, 0x12, 0x74,
0xEB, 0x01, 0xA1, 0xFF, 0x12, 0x74, 0xDF, 0x01, 0x12, 0x74, 0xDA, 0x83, 0x66, 0x44, 0x22, 0x46,
0x0C, 0xFA, 0x22, 0xF2, 0x0B, 0xFC, 0x28, 0x40, 0x40, 0x2B, 0x1A, 0x00, 0x10, 0x26, 0x04, 0x00,
0x26, 0x26, 0x0F, 0x00, 0x26, 0x27, 0x0D, 0x00, 0x00, 0xF4, 0x02, 0x62, 0xA1, 0xFF, 0x12, 0x74,
0x7A, 0xD4, 0x12, 0x74, 0x7A, 0xD4, 0x12, 0x74, 0x7A, 0xD4, 0x12, 0x74, 0x7A, 0xD4, 0x12, 0x74,
0x07, 0x00, 0xA1, 0xFF, 0x12, 0x74, 0x9C, 0x4E, 0x12, 0x74, 0x9C, 0x4C, 0x12, 0x74, 0x00, 0x00,
0x88, 0xFF, 0xA1, 0xFF, 0xB2, 0x60, 0x58, 0x4F, 0x2D, 0x78, 0xFF, 0xFF, 0x01, 0x60, 0x18, 0xE1,
0x78, 0x44, 0x02, 0xA4, 0x35, 0xFB, 0xCC, 0x00, 0x29, 0x44, 0xF7, 0xB4, 0x40, 0x49, 0x34, 0x64,
0x3A, 0xDB, 0x44, 0xE1, 0xA5, 0x60, 0x54, 0x78, 0xFF, 0xFF, 0x00, 0x6B, 0xBC, 0xFF, 0x15, 0xF3,
0xFF, 0xFF, 0xDC, 0x84, 0x15, 0xFB, 0x78, 0x5C, 0x07, 0x00, 0x78, 0x5C, 0x2F, 0x00, 0x62, 0xFF,
0xFF, 0xFF, 0xA1, 0xFF, 0x98, 0xFF, 0x80, 0x3E, 0x80, 0x60, 0x01, 0xE0, 0xD5, 0x60, 0x84, 0xE7,
0xA1, 0xF3, 0x40, 0x60, 0x60, 0x40, 0x01, 0x23, 0x48, 0x60, 0x5E, 0x65, 0x80, 0x60, 0x00, 0x6A,
0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x65, 0x4A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x00, 0x60,
0x00, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x80, 0x60, 0x00, 0x6A, 0xFF, 0xFF, 0x01, 0x16,
0xFE, 0x01, 0x65, 0x4A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x00, 0x60, 0x01, 0x6A, 0xFF, 0xFF,
0x01, 0x16, 0xFE, 0x01, 0x95, 0x60, 0x84, 0xE7, 0x64, 0x58, 0xFF, 0xFF, 0x80, 0x60, 0x01, 0xE0,
0xD5, 0x60, 0x84, 0xE7, 0xA1, 0xF3, 0x7C, 0x45, 0x60, 0x40, 0x01, 0x23, 0x02, 0x65, 0x8C, 0x60,
0x48, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x00, 0x60, 0x00, 0x6A, 0xFF, 0xFF, 0x01, 0x16,
0xFE, 0x01, 0x00, 0x60, 0x7F, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x84, 0x60, 0x04, 0x6A,
0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x48, 0x60, 0x08, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01,
0x65, 0x4A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x84, 0x60, 0x04, 0x6A, 0xFF, 0xFF, 0x01, 0x16,
0xFE, 0x01, 0x40, 0x60, 0x08, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x65, 0x4A, 0xFF, 0xFF,
0x01, 0x16, 0xFE, 0x01, 0x8C, 0x60, 0x48, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x00, 0x60,
0x00, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x00, 0x60, 0x00, 0x6A, 0xFF, 0xFF, 0x01, 0x16,
0xFE, 0x01, 0x95, 0x60, 0x84, 0xE7, 0x64, 0x58, 0xFF, 0xFF, 0x12, 0x74, 0x6A, 0x40, 0x87, 0x4F,
0x12, 0x74, 0x87, 0x4C, 0x12, 0x74, 0x29, 0x40, 0x40, 0x2B, 0x08, 0x00, 0x0A, 0x64, 0x89, 0xFF,
0x60, 0x54, 0x88, 0xFF, 0x87, 0x4D, 0x12, 0x74, 0x87, 0x4D, 0x09, 0x00, 0x03, 0x64, 0x89, 0xFF,
0x60, 0x54, 0x88, 0xFF, 0x87, 0x4F, 0x12, 0x74, 0x87, 0x4D, 0x12, 0x74, 0x87, 0x4D, 0x7C, 0x44,
0x01, 0x08, 0x01, 0x00, 0x67, 0x44, 0x12, 0x74, 0x87, 0x4C, 0x12, 0x74, 0x87, 0x4C, 0x12, 0x74,
0x87, 0x4C, 0x12, 0x74, 0x87, 0x4D, 0x12, 0x74, 0x87, 0x4D, 0x12, 0x74, 0x87, 0x4D, 0x12, 0x74,
0x04, 0x21, 0x04, 0x00, 0xFF, 0x2A, 0x01, 0x00, 0x04, 0x00, 0x03, 0x00, 0xFF, 0x2A, 0x0D, 0x00,
0x0C, 0x00, 0xBC, 0xFF, 0x61, 0xFF, 0x78, 0x5C, 0x57, 0x01, 0x78, 0x5C, 0x7F, 0x01, 0xB6, 0xFF,
0xB7, 0xFF, 0xB4, 0xFF, 0xC8, 0x60, 0x09, 0x7D, 0x7C, 0x4B, 0x6A, 0x44, 0x2F, 0x58, 0xFF, 0xFF,
0x04, 0x74, 0xC4, 0xE2, 0x04, 0xE1, 0x29, 0x40, 0x40, 0x2B, 0x05, 0x00, 0xA1, 0xFF, 0xFF, 0xFF,
0xBC, 0xFF, 0x14, 0x74, 0x01, 0x00, 0x04, 0x74, 0xC4, 0xE2, 0x04, 0xE1, 0xBC, 0xFF, 0xB5, 0xFF,
0x47, 0xFF, 0xB6, 0xFF, 0xB7, 0xFF, 0xB4, 0xFF, 0xC8, 0x60, 0x09, 0x7D, 0x7C, 0x4B, 0x29, 0x40,
0x40, 0x27, 0x04, 0x00, 0xC2, 0x60, 0x58, 0x4F, 0xBA, 0x78, 0xFF, 0xFF, 0xA1, 0xFF, 0x29, 0x40,
0x10, 0x26, 0x6D, 0x00, 0x80, 0x60, 0x01, 0xE0, 0xD5, 0x60, 0x84, 0xE7, 0xA1, 0xF3, 0x40, 0x60,
0x60, 0x40, 0x01, 0x23, 0x48, 0x60, 0x5E, 0x65, 0x80, 0x60, 0x00, 0x6A, 0xFF, 0xFF, 0x01, 0x16,
0xFE, 0x01, 0x65, 0x4A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x00, 0x60, 0x00, 0x6A, 0xFF, 0xFF,
0x01, 0x16, 0xFE, 0x01, 0x80, 0x60, 0x00, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x65, 0x4A,
0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x00, 0x60, 0x01, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01,
0x95, 0x60, 0x84, 0xE7, 0x80, 0x60, 0x01, 0xE0, 0xD5, 0x60, 0x84, 0xE7, 0xA1, 0xF3, 0x7C, 0x45,
0x60, 0x40, 0x01, 0x23, 0x02, 0x65, 0x8C, 0x60, 0x48, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01,
0x00, 0x60, 0x00, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x00, 0x60, 0x7F, 0x6A, 0xFF, 0xFF,
0x01, 0x16, 0xFE, 0x01, 0x84, 0x60, 0x04, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x48, 0x60,
0x08, 0x6A, 0xFF, 0xFF, 0x01, 0x16, 0xFE, 0x01, 0x65, 0x4A, 0xFF, 0xF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x00, 0x20, 0x44, 0xDC, 0x85, 0x0F, 0xB4, 0xFB, 0xA0,
0x7F, 0x67, 0x07, 0x63, 0x03, 0x05, 0x45, 0x40, 0x00, 0x67, 0xD8, 0xFE, 0xFF, 0x27, 0x05, 0xFD,
0x0A, 0x7E, 0x04, 0xFB, 0x61, 0x55, 0x48, 0x00, 0x28, 0xFB, 0x01, 0xF3, 0x29, 0xFB, 0x44, 0x46,
0x40, 0x45, 0x10, 0x61, 0x7E, 0x60, 0xC0, 0x64, 0xA0, 0x80, 0x7F, 0x67, 0x02, 0x63, 0x30, 0x02,
0xB5, 0x60, 0x58, 0x4F, 0xCE, 0x78, 0xFF, 0xFF, 0x7F, 0x67, 0x03, 0x63, 0x29, 0x02, 0x26, 0x40,
0x01, 0x2B, 0x23, 0x00, 0x98, 0xFE, 0x18, 0x05, 0x12, 0x60, 0xFC, 0xF5, 0x0E, 0xF2, 0x14, 0x18,
0x02, 0x18, 0x09, 0xF4, 0xFB, 0x01, 0x23, 0x44, 0x00, 0xA8, 0x08, 0x7E, 0x0A, 0x02, 0x66, 0x44,
0x11, 0xFB, 0x46, 0x43, 0x23, 0x47, 0x80, 0xBF, 0x3B, 0x42, 0x04, 0xA2, 0xA2, 0xDB, 0x08, 0xB9,
0x10, 0x7E, 0x00, 0x7F, 0x0E, 0xFA, 0x09, 0x00, 0x20, 0x44, 0xDC, 0x85, 0x0F, 0xB4, 0xFB, 0xA0,
0x7F, 0x67, 0x07, 0x63, 0x05, 0x05, 0x45, 0x40, 0xD8, 0xFE, 0x00, 0x67, 0xD0, 0xFE, 0xD9, 0xFE,
0xFF, 0x27, 0x05, 0xFD, 0x0B, 0x7E, 0x04, 0xFB, 0x0E, 0x60, 0xDD, 0xF3, 0xFF, 0xFF, 0x20, 0xB0,
0x80, 0xBC, 0x08, 0x28, 0xA2, 0xDB, 0x61, 0x55, 0x66, 0x00, 0x04, 0xB5, 0x82, 0xB5, 0x25, 0x02,
0x04, 0x03, 0x20, 0x44, 0x7F, 0xB4, 0x40, 0x40, 0xA3, 0xD3, 0x99, 0xFE, 0x04, 0x04, 0x02, 0xBC,
0xFE, 0xB4, 0xA3, 0xDB, 0x59, 0x00, 0xDB, 0xF3, 0x20, 0x40, 0x80, 0x26, 0x55, 0x00, 0xA3, 0xD3,
0xFF, 0xA0, 0xF8, 0xB4, 0x02, 0x02, 0xA3, 0xDB, 0x1C, 0x00, 0x04, 0xBC, 0xBF, 0xB4, 0xA3, 0xDB,
0x08, 0xB0, 0x01, 0x64, 0x08, 0x24, 0x02, 0x64, 0x28, 0xFB, 0x20, 0x44, 0x80, 0xBC, 0x40, 0x40,
0xD0, 0xFE, 0x42, 0x00, 0xBF, 0xB4, 0xA3, 0xDB, 0x3F, 0x00, 0x40, 0xB0, 0xFF, 0xFF, 0xFA, 0x02,
0xF8, 0xB4, 0xA3, 0xDB, 0x08, 0xB5, 0x07, 0x7C, 0x01, 0x02, 0xDB, 0xF9, 0x20, 0x44, 0x7F, 0xB4,
0x40, 0x40, 0x1D, 0x60, 0xBA, 0x63, 0xA3, 0xD3, 0xFF, 0xFF, 0x20, 0xB5, 0x07, 0xB5, 0x08, 0x28,
0xC4, 0x02, 0x99, 0xFE, 0x29, 0x05, 0x20, 0x44, 0x80, 0x26, 0x26, 0x00, 0x20, 0x2A, 0x03, 0x00,
0xDF, 0xB4, 0x40, 0x40, 0x74, 0x00, 0x40, 0x2A, 0x1F, 0x00, 0xBF, 0xB4, 0x40, 0x40, 0x09, 0x00,
0xA8, 0xFF, 0x20, 0x44, 0x99, 0xFE, 0x02, 0x05, 0x80, 0x2A, 0x03, 0x00, 0x40, 0xBC, 0x40, 0x40,
0x13, 0x00, 0x00, 0xF1, 0x80, 0xBC, 0x40, 0x40, 0x64, 0x44, 0xE0, 0x84, 0xE8, 0x84, 0x0A, 0x36,
0x29, 0x01, 0x0B, 0x36, 0x59, 0x01, 0x28, 0xFB, 0x01, 0xF1, 0x29, 0xF9, 0x02, 0xF1, 0x2A, 0xF9,
0x03,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xA5, 0x01, 0xA9, 0xFF,
0x77, 0x44, 0x60, 0x57, 0x40, 0x4A, 0x01, 0x2A, 0x31, 0x00, 0x24, 0x44, 0xAC, 0x86, 0x08, 0xF2,
0x2D, 0x03, 0x25, 0x60, 0xFE, 0x65, 0xD4, 0x80, 0x0E, 0xF2, 0x02, 0x03, 0xA5, 0xD5, 0x04, 0x00,
0x01, 0xBC, 0x0E, 0xFA, 0x09, 0xF4, 0xD1, 0xFE, 0x46, 0x44, 0x11, 0x1B, 0x32, 0x40, 0x80, 0x2A,
0x1D, 0x00, 0x9D, 0xFE, 0x1B, 0x05, 0x13, 0x60, 0x02, 0xF3, 0xFF, 0xFF, 0x00, 0xA8, 0x60, 0x46,
0x03, 0x03, 0x0F, 0xF2, 0xFF, 0xFF, 0x12, 0x1B, 0x08, 0x60, 0x00, 0x75, 0x0F, 0x00, 0x3F, 0xF2,
0x48, 0x65, 0xC4, 0x84, 0x13, 0xFB, 0x66, 0x44, 0x10, 0xFB, 0x66, 0x47, 0x20, 0xBF, 0x3B, 0x42,
0x04, 0xA2, 0xA2, 0xDB, 0x0E, 0xF2, 0x41, 0x75, 0x10, 0xBC, 0x0E, 0xFA, 0x2A, 0x44, 0x08, 0x2A,
0x17, 0x00, 0x23, 0x44, 0x00, 0xA8, 0x5C, 0x43, 0x13, 0x03, 0x12, 0x60, 0xFC, 0xF5, 0x01, 0x00,
0x09, 0xF4, 0x0E, 0xF2, 0x0D, 0x18, 0x08, 0xB0, 0x18, 0xAC, 0xFA, 0x03, 0x0E, 0xFA, 0x66, 0x43,
0x11, 0xFD, 0x46, 0x43, 0x23, 0x47, 0x80, 0xBF, 0x3B, 0x42, 0x04, 0xA2, 0xA2, 0xDB, 0x28, 0x75,
0x2A, 0x44, 0x06, 0x22, 0x2D, 0x00, 0x22, 0x44, 0x00, 0xA8, 0x60, 0x46, 0x0E, 0xF2, 0x28, 0x03,
0x10, 0xB0, 0x01, 0xBC, 0x03, 0x02, 0x00, 0x64, 0x40, 0x42, 0x22, 0x00, 0x0E, 0xFA, 0xD1, 0xFE,
0x25, 0x60, 0xF2, 0x64, 0x40, 0x47, 0x58, 0x4F, 0x94, 0x00, 0x46, 0x42, 0x19, 0x02, 0x22, 0x47,
0x40, 0xBF, 0x3B, 0x42, 0x04, 0xA2, 0xA2, 0xDB, 0x23, 0xF2, 0x66, 0x43, 0x00, 0xA8, 0x0E, 0xF2,
0x08, 0x02, 0x60, 0x40, 0x02, 0x2A, 0xE4, 0x01, 0x12, 0xFD, 0x10, 0x64, 0x0E, 0xFA, 0x02, 0x75,
0x07, 0x00, 0x60, 0x40, 0x04, 0x2A, 0xDC, 0x01, 0x12, 0xFD, 0x10, 0x64, 0x0E, 0xFA, 0x04, 0x75,
0x2A, 0x44, 0x80, 0x2A, 0x19, 0x00, 0x21, 0x44, 0xAC, 0x86, 0x0E, 0xF2, 0x15, 0x03, 0x01, 0xBC,
0x0E, 0xFA, 0xD1, 0xFE, 0x26, 0x60, 0x0A, 0x64, 0x40, 0x47, 0x58, 0x4F, 0x6A, 0x00, 0x46, 0x41,
0x0B, 0x02, 0x21, 0x47, 0x10, 0xBF, 0x3B, 0x42, 0x04, 0xA2, 0xA2, 0xDB, 0x0E, 0xF2, 0x66, 0x43,
0x08, 0xFD, 0x10, 0xBC, 0x0E, 0xFA, 0x80, 0x75, 0x2A, 0x44, 0x10, 0xB0, 0x20, 0x44, 0x18, 0x03,
0x7F, 0xB4, 0x40, 0x40, 0x1D, 0x60, 0xBA, 0x63, 0xA3, 0xD3, 0xFF, 0xFF, 0x20, 0xB0, 0x80, 0xB0,
0x09, 0x03, 0x08, 0x03, 0x40, 0xBC, 0x7F, 0xB4, 0x04, 0xB0, 0xA3, 0xDB, 0x03, 0x03, 0x20, 0x44,
0x80, 0xBC, 0x40, 0x40, 0x2A, 0x40, 0x08, 0x27, 0x03, 0x00, 0xB3, 0x60, 0xC9, 0x78, 0xFF, 0xFF,
0x2A, 0x40, 0x08, 0x2B, 0x0F, 0x00, 0x32, 0x40, 0x80, 0x26, 0x05, 0x00, 0x19, 0x60, 0xF7, 0xF3,
0xFF, 0xFF, 0x01, 0x1B, 0x07, 0x00, 0x19, 0x60, 0xF6, 0xF3, 0xFF, 0xFF, 0x01, 0xBC, 0xA2, 0xDB,
0xFF, 0xFF, 0x10, 0xFF, 0xB3, 0x60, 0xFC, 0x78, 0xFF, 0xFF, 0xE8, 0xFE, 0x14, 0x05, 0xEA, 0xFE,
0x23, 0x05, 0xE9, 0xFE, 0x1C, 0x05, 0xE7, 0xFE, 0x09, 0x05, 0x47, 0xFF, 0x20, 0x44, 0x0F, 0x22,
0x03, 0x00, 0xCC, 0x84, 0x40, 0x40, 0x0F, 0x22, 0xB8, 0xFE, 0xEC, 0x01, 0x23, 0x41, 0x00, 0xB9,
0x5C, 0x4A, 0xE8, 0x02, 0x5A, 0x01, 0x24, 0x41, 0x00, 0xB9, 0x25, 0x60, 0xFE, 0x65, 0x45, 0x47,
0xE1, 0x02, 0x58, 0x4F, 0x0E, 0x00, 0xDE, 0x02, 0x5C, 0x4A, 0x46, 0x44, 0x38, 0x01, 0x22, 0x41,
0x00, 0xB9, 0x5C, 0x4A, 0xD7, 0x02, 0x6C, 0x01, 0x21, 0x41, 0x00, 0xB9, 0x5C, 0x4A, 0x92, 0x03,
0xD1, 0x01, 0x27, 0xD3, 0x03, 0x00, 0x10, 0xB0, 0x09, 0xF2, 0x04, 0x03, 0xAC, 0x86, 0x0E, 0xF2,
0xFA, 0x02, 0x08, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x0E, 0xF3, 0x0F, 0x60, 0xFE, 0x65, 0x0C, 0xF3,
0x24, 0x86, 0x24, 0x46, 0x60, 0x40, 0xFB, 0x3B, 0x07, 0x00, 0x80, 0x26, 0x02, 0x00, 0x23, 0x46,
0x03, 0x4C, 0x46, 0x61, 0x3A, 0x65, 0x0C, 0x00, 0x2E, 0xF3, 0x40, 0x45, 0xF8, 0x2B, 0x02, 0x00,
0x40, 0x45, 0x03, 0x00, 0x58, 0x4F, 0x5A, 0x00, 0x07, 0x02, 0x58, 0x4F, 0x66, 0x00, 0x04, 0x05,
0x66, 0x50, 0x65, 0x52, 0x61, 0x51, 0x09, 0x00, 0x26, 0x47, 0x00, 0xBF, 0x0E, 0xFB, 0x2E, 0xF5,
0x05, 0xF0, 0x80, 0x60, 0x64, 0x50, 0x00, 0x72, 0x7E, 0x71, 0xAC, 0xFF, 0x31, 0x40, 0x01, 0x2A,
0x08, 0x00, 0x19, 0x60, 0xF2, 0xF3, 0xFF, 0xFF, 0x04, 0x18, 0x0C, 0x64, 0x13, 0x60, 0x13, 0xFB,
0x2D, 0xFF, 0xB3, 0x60, 0xFC, 0x78, 0xFF, 0xFF, 0x8E, 0xFF, 0x0F, 0xF3, 0x0F, 0x60, 0xFE, 0x65,
0x24, 0x86, 0x0D, 0xF3, 0x24, 0x46, 0x60, 0x40, 0xFB, 0x3B, 0x07, 0x00, 0x80, 0x26, 0x02, 0x00,
0x23, 0x46, 0x03, 0x4C, 0x46, 0x61, 0x3A, 0x65, 0x0C, 0x00, 0x2E, 0xF3, 0x40, 0x45, 0xF8, 0x2B,
0x02, 0x00, 0x40, 0x45, 0x03, 0x00, 0x58, 0x4F, 0x21, 0x00, 0x07, 0x02, 0x58, 0x4F, 0x2D, 0x00,
0x04, 0x05, 0x66, 0x50, 0x65, 0x52, 0x61, 0x51, 0x09, 0x00, 0x26, 0x47, 0x00, 0xBF, 0x0F, 0xFB,
0x2E, 0xF5, 0x05, 0xF0, 0x80, 0x60, 0x64, 0x50, 0x00, 0x72, 0x7E, 0x71, 0x8D, 0xFF, 0xAD, 0xFF,
0x31, 0x40, 0x01, 0x2A, 0xCE, 0x01, 0x19, 0x60, 0xF2, 0xF3, 0xFF, 0xFF, 0x04, 0x18, 0x0C, 0x64,
0x13, 0x60, 0x13, 0xFB, 0x2D, 0xFF, 0xB3, 0x60, 0xFC, 0x78, 0xFF, 0xFF, 0x25, 0x44, 0xA7, 0xF1,
0xA8, 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, 0x2A, 0x43, 0xB6, 0x60,
0x58, 0x4E, 0x65, 0x78, 0xFF, 0xFF, 0x08, 0xFE, 0x0C, 0x00, 0x13, 0x60, 0x08, 0xF3, 0xFF, 0xFF,
0xAC, 0x86, 0x0E, 0xF2, 0x06, 0x03, 0x00, 0xA8, 0x09, 0xF2, 0xFA, 0x02, 0x01, 0x67, 0x0E, 0xFA,
0x08, 0xFE, 0xA3, 0xFF, 0x2D, 0x58, 0xFF, 0xFF, 0xAA, 0xF3, 0x7C, 0x63, 0x00, 0xBE, 0x40, 0x45,
0x1A, 0x03, 0x00, 0x65, 0x65, 0x44, 0xDC, 0x85, 0x84, 0xA1, 0x00, 0xF2, 0x06, 0x06, 0x01, 0xFC,
0x00, 0xA8, 0x60, 0x46, 0xF7, 0x02, 0x40, 0x45, 0x0E, 0x00, 0xA9, 0xF3, 0x00, 0x63, 0xD4, 0x84,
0xA9, 0xFB, 0x80, 0x60, 0x7C, 0x64, 0x01, 0xFA, 0x00, 0xF0, 0x00, 0xFC, 0xD3, 0x80, 0xAA, 0xF9,
0x02, 0x02, 0xAB, 0xF9, 0x08, 0xFE, 0x2E, 0x58, 0xFF, 0xFF, 0x66, 0x44, 0x25, 0x46, 0x05, 0xFA,
0x06, 0xFA, 0x01, 0xF0, 0x03, 0x67, 0x02, 0xFC, 0xB0, 0x84, 0x3A, 0x7E, 0x01, 0xFA, 0x12, 0x64,
0x03, 0xFA, 0x00, 0xF0, 0x04, 0xF8, 0x00, 0x64, 0x0C, 0x61, 0x10, 0x63, 0x59, 0xDA, 0xFE, 0x1F,
0x2E, 0x58, 0xFF, 0xFF, 0x27, 0x43, 0xE3, 0x81, 0xE9, 0x81, 0x03, 0x05, 0x16, 0x03, 0x00, 0x61,
0x01, 0x00, 0xEC, 0x63, 0x61, 0x46, 0xBF, 0xD2, 0x27, 0x45, 0xDC, 0x84, 0xA2, 0xDA, 0xBE, 0xD2,
0x25, 0x46, 0x88, 0xF8, 0x04, 0x1B, 0x25, 0x44, 0x61, 0x46, 0xA3, 0xDA, 0x04, 0x00, 0x0A, 0xFA,
0x60, 0x46, 0x25, 0x44, 0x09, 0xFA, 0x61, 0x46, 0xBE, 0xDA, 0x2F, 0x58, 0xFF, 0xFF, 0x25, 0x44,
0x00, 0xA8, 0x07, 0x4B, 0x0C, 0x03, 0x58, 0x4F, 0x33, 0x00, 0x0B, 0x47, 0x26, 0x60, 0x04, 0x65,
0x27, 0x44, 0xD4, 0x80, 0x00, 0x64, 0x01, 0x02, 0x0F, 0xFA, 0x58, 0x4F, 0xD3, 0x01, 0x70, 0x00,
0x25, 0x43, 0xE3, 0x84, 0x7C, 0x41, 0x02, 0x04, 0xE8, 0x81, 0xEC, 0x63, 0x61, 0x46, 0xA3, 0xD2,
0x00, 0x7C, 0x40, 0x45, 0xBF, 0xD8, 0xA3, 0xD8, 0xBE, 0xD8, 0x27, 0x42, 0x5A, 0xD3, 0x25, 0x5C,
0x60, 0x41, 0x02, 0x1B, 0x27, 0xD9, 0x05, 0x00, 0x25, 0x46, 0x0A, 0xFA, 0x61, 0x46, 0x25, 0x44,
0x09, 0xFA, 0x25, 0x44, 0x27, 0x43, 0x00, 0x61, 0x60, 0x46, 0x09, 0xF2, 0x08, 0xFC, 0x00, 0xA8,
0xDD, 0x81, 0xFA, 0x02, 0xBF, 0xD1, 0x66, 0x44, 0xBE, 0xDB, 0xC1, 0x84, 0xBF, 0xDB, 0x48, 0x00,
0x25, 0x46, 0xEC, 0x63, 0x08, 0xF2, 0x89, 0xF2, 0x1E, 0x18, 0x40, 0x47, 0xE0, 0x84, 0xE8, 0x85,
0x02, 0x05, 0xE8, 0x83, 0x00, 0x65, 0x65, 0x46, 0xBF, 0xD2, 0x61, 0x5C, 0xCC, 0x84, 0xA2, 0xDA,
0x25, 0x46, 0x0A, 0xF2, 0x00, 0xB9, 0x65, 0x46, 0x08, 0x24, 0xBE, 0xDA, 0x02, 0x1B, 0xA3, 0xD8,
0x02, 0x00, 0x60, 0x46, 0x89, 0xFA, 0x00, 0xB9, 0x61, 0x46, 0x08, 0x28, 0x0A, 0xFA, 0x25, 0x46,
0x89, 0xFC, 0x8A, 0xFC, 0x88, 0xFC, 0x2F, 0x58, 0xFF, 0xFF, 0x00, 0x61, 0x28, 0x65, 0x25, 0x43,
0xAB, 0xF3, 0xAF, 0x83, 0x00, 0xBE, 0x18, 0x03, 0x02, 0x03, 0x00, 0xFC, 0x01, 0x00, 0xAA, 0xFD,
0x63, 0x46, 0x65, 0x44, 0xCC, 0x85, 0x00, 0xF2, 0x07, 0x02, 0xAB, 0xF5, 0x00, 0x64, 0x00, 0xFA,
0xDE, 0x60, 0xAF, 0x64, 0x09, 0xFB, 0x08, 0x00, 0x66, 0x43, 0x00, 0xBE, 0xDD, 0x81, 0xF1, 0x02,
0xA9, 0xF1, 0xAB, 0xFD, 0xC1, 0x84, 0xA9, 0xFB, 0x2E, 0x58, 0xFF, 0xFF, 0x00, 0x66, 0x46, 0x45,
0x29, 0x43, 0xFC, 0xA3, 0x66, 0x44, 0xBD, 0xDB, 0x25, 0x44, 0xBD, 0xDB, 0x00, 0x64, 0xBD, 0xDB,
0x03, 0x61, 0x0E, 0x65, 0x26, 0x60, 0x18, 0x63, 0x43, 0x49, 0xA3, 0xD3, 0x06, 0xA3, 0x00, 0xA8,
0xCD, 0x81, 0x04, 0x02, 0xF9, 0x02, 0xB3, 0x60, 0xFC, 0x78, 0xFF, 0xFF, 0x01, 0x26, 0xE6, 0x01,
0xD4, 0x80, 0x60, 0x45, 0xE3, 0x05, 0xF6, 0xA3, 0xBD, 0xD1, 0xBD, 0xD1, 0x44, 0x47, 0x44, 0x48,
0x44, 0x45, 0x26, 0x60, 0x5A, 0x64, 0x44, 0xD7, 0xFF, 0xFF, 0xFF, 0xFF, 0x25, 0x60, 0xC8, 0x63,
0x0D, 0x65, 0x00, 0x61, 0x41, 0x48, 0xA3, 0xD3, 0x06, 0xA3, 0xAC, 0x86, 0x00, 0x61, 0x09, 0x03,
0x00, 0xF2, 0x09, 0xF0, 0xAC, 0x86, 0x00, 0xF2, 0xDD, 0x81, 0xFC, 0x02, 0x64, 0x44, 0xAC, 0x86,
0xF6, 0x01, 0x61, 0x44, 0x25, 0x46, 0x27, 0xDA, 0x65, 0x44, 0x28, 0x45, 0x45, 0x88, 0xCC, 0x85,
0x5A, 0x87, 0xE9, 0x02, 0x00, 0x64, 0x27, 0xDA, 0x5A, 0xDA, 0x5A, 0x87, 0xA6, 0xF3, 0xA5, 0xF1,
0x02, 0xA4, 0x60, 0x46, 0x60, 0x45, 0x00, 0x61, 0x22, 0xF2, 0xFF, 0xFF, 0xAC, 0x86, 0x00, 0xF2,
0x04, 0x03, 0xAC, 0x86, 0x00, 0xF2, 0xDD, 0x81, 0xFC, 0x02, 0x65, 0x44, 0x02, 0xA5, 0x65, 0x46,
0x64, 0x44, 0xCC, 0x9C, 0xFF, 0xFF, 0xF0, 0x02, 0x61, 0x44, 0x25, 0x46, 0x27, 0xDA, 0x5A, 0x87,
0x28, 0x45, 0x45, 0x88, 0x00, 0x64, 0x27, 0xDA, 0x5A, 0x87, 0x06, 0x60, 0x40, 0x65, 0xAA, 0xF3,
0x01, 0x61, 0xAC, 0x86, 0x00, 0xF2, 0x03, 0x03, 0xD5, 0x80, 0xDD, 0x81, 0xFA, 0x04, 0xCD, 0x84,
0x25, 0x46, 0x27, 0xDA, 0x28, 0x45, 0xC4, 0x84, 0x5A, 0xDA, 0xDA, 0x81, 0xA9, 0xF1, 0x59, 0xD8,
0x25, 0x60, 0xC6, 0x64, 0x18, 0x63, 0xA0, 0xD1, 0x06, 0xA4, 0x59, 0xD8, 0xFC, 0x1F, 0x00, 0x64,
0x59, 0xDA, 0x59, 0xDA, 0x01, 0x60, 0x56, 0x64, 0x0A, 0x63, 0x58, 0xD1, 0x59, 0xD8, 0xFD, 0x1F,
0xDB, 0xF1, 0x59, 0xD8, 0x75, 0x01, 0x07, 0x4B, 0xB6, 0x60, 0x58, 0x4F, 0xD0, 0x78, 0xFF, 0xFF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83, 0x3E, 0x40, 0x60, 0x0B, 0x65,
0x2B, 0x44, 0x00, 0x63, 0xE8, 0x80, 0xF8, 0x84, 0x02, 0x24, 0x94, 0x84, 0xF3, 0x83, 0xCD, 0x81,
0xFF, 0xFF, 0xF8, 0x02, 0xDF, 0x83, 0x2F, 0x58, 0x40, 0x4B, 0x00, 0x62, 0x01, 0x64, 0xD4, 0x80,
0xE0, 0x84, 0x1A, 0x03, 0xD4, 0x80, 0xE0, 0x84, 0x15, 0x03, 0x61, 0x44, 0x11, 0x61, 0xE0, 0x84,
0xCD, 0x81, 0xFD, 0x04, 0x01, 0x00, 0xE0, 0x84, 0xF2, 0x82, 0xFF, 0xFF, 0x02, 0x24, 0xC6, 0x82,
0x02, 0x28, 0xD6, 0x82, 0xE2, 0x80, 0xCD, 0x81, 0x02, 0x28, 0x01, 0xBC, 0xF4, 0x02, 0x01, 0x2A,
0xC6, 0x82, 0x03, 0x00, 0xE9, 0x81, 0xF2, 0x82, 0x61, 0x44, 0x2D, 0x58, 0xFF, 0xFF, 0x00, 0x64,
0x3B, 0xDB, 0x3C, 0x44, 0xAC, 0x80, 0xFF, 0xFF, 0xC6, 0x02, 0x89, 0xF3, 0x8A, 0xF3, 0x02, 0xA8,
0x02, 0xA8, 0x08, 0x02, 0x00, 0x64, 0x8B, 0xFB, 0x89, 0xFB, 0x8A, 0xFB, 0x00, 0x64, 0x8C, 0xFB,
0xCA, 0xFE, 0x2A, 0x00, 0x03, 0x02, 0x00, 0x64, 0x8A, 0xFB, 0xCA, 0xFE, 0x01, 0x64, 0x3B, 0xDB,
0x12, 0x60, 0xE7, 0xF3, 0xFF, 0xFF, 0x00, 0xA8, 0x60, 0x46, 0x13, 0x03, 0xDB, 0xF3, 0x2A, 0xF2,
0xFD, 0xA0, 0x60, 0x40, 0x80, 0x3A, 0x33, 0x00, 0x32, 0x02, 0x9B, 0xFE, 0x30, 0x05, 0x00, 0x64,
0x13, 0x60, 0x0A, 0xFB, 0x66, 0x44, 0x5A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x60, 0x40, 0x22, 0x26,
0x64, 0x00, 0x60, 0x45, 0x63, 0x42, 0x5A, 0xD0, 0xCD, 0x81, 0x3C, 0x46, 0x1B, 0x02, 0x64, 0x44,
0x88, 0x3A, 0x18, 0x00, 0x8E, 0x37, 0x03, 0x00, 0xC7, 0x37, 0x01, 0x00, 0x13, 0x00, 0x65, 0x44,
0x01, 0x26, 0x7C, 0x00, 0x04, 0x26, 0x03, 0x00, 0x10, 0x26, 0x01, 0x00, 0x31, 0x00, 0xA3, 0x46,
0x3B, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x80, 0x27, 0x5B, 0x00, 0xA3, 0x46, 0x00, 0x7C, 0x22, 0xF8,
0xA3, 0x46, 0x6C, 0x00, 0xA3, 0x46, 0x65, 0x44, 0x01, 0x26, 0x0B, 0x00, 0x04, 0x26, 0x03, 0x00,
0x10, 0x26, 0x01, 0x00, 0x1D, 0x00, 0x3B, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x80, 0x27, 0x48, 0x00,
0x17, 0x00, 0xA6, 0xF3, 0xFF, 0xFF, 0x60, 0x46, 0x3A, 0xF2, 0x66, 0x43, 0xFF, 0xB4, 0x3C, 0x46,
0x22, 0xF0, 0x60, 0x47, 0xB0, 0x84, 0x22, 0xFA, 0x63, 0x46, 0x3B, 0xF0, 0x60, 0x40, 0x04, 0x27,
0x03, 0x00, 0x10, 0x27, 0x01, 0x00, 0x04, 0x00, 0x64, 0x40, 0x80, 0x27, 0x31, 0x00, 0x00, 0x00,
0x3C, 0x46, 0x02, 0x65, 0xBF, 0x60, 0x19, 0x78, 0xFF, 0xFF, 0xCD, 0x81, 0x63, 0x42, 0x5A, 0xD0,
0x3C, 0x46, 0x26, 0x02, 0x64, 0x44, 0x88, 0x3A, 0x23, 0x00, 0x77, 0x37, 0x37, 0x00, 0x78, 0x37,
0x35, 0x00, 0x8E, 0x37, 0x33, 0x00, 0xC7, 0x37, 0x31, 0x00, 0x1A, 0x00, 0x19, 0x60, 0xA3, 0xF3,
0xFF, 0xFF, 0x60, 0x40, 0x01, 0x2A, 0x2A, 0x00, 0x06, 0x00, 0x19, 0x60, 0xA3, 0xF3, 0xFF, 0xFF,
0x60, 0x40, 0x01, 0x2A, 0xE2, 0x01, 0x3C, 0x46, 0x3E, 0xF2, 0x40, 0x60, 0x00, 0x65, 0xF0, 0x84,
0xA4, 0x84, 0x3D, 0xFA, 0x2A, 0xF2, 0xBF, 0x60, 0xFF, 0x65, 0xA4, 0x84, 0x2A, 0xFA, 0x16, 0x00,
0x3C, 0x46, 0x22, 0xF0, 0x80, 0x67, 0xB0, 0x84, 0xA2, 0xDA, 0xFF, 0xFF, 0x3F, 0xF2, 0x3E, 0xF0,
0x08, 0xA4, 0x60, 0x41, 0x22, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x26, 0x03, 0x00, 0x04, 0x26,
0x03, 0x00, 0x04, 0x00, 0x04, 0x2B, 0x02, 0x00, 0x61, 0x44, 0x3F, 0xFA, 0x3C, 0x46, 0x2C, 0xF2,
0x27, 0x40, 0x01, 0x27, 0x32, 0xF2, 0xD3, 0xF1, 0x60, 0x40, 0x01, 0x26, 0x47, 0x00, 0x09, 0x60,
0x00, 0x64, 0xD0, 0x80, 0x3F, 0xF2, 0x09, 0x06, 0x2C, 0x45, 0xC4, 0x84, 0xD0, 0x80, 0x40, 0x4A,
0x34, 0x06, 0x60, 0x43, 0x64, 0x44, 0x54, 0x88, 0x17, 0x00, 0x60, 0x45, 0x16, 0x60, 0xC8, 0xF3,
0xDA, 0xF3, 0x00, 0xBC, 0x60, 0x47, 0xEC, 0xA0, 0x28, 0x03, 0x27, 0x07, 0x2C, 0x44, 0xC4, 0x81,
0x02, 0x60, 0x1C, 0x65, 0x45, 0x4A, 0xD5, 0x80, 0x2C, 0x45, 0x1F, 0x06, 0x27, 0x40, 0x04, 0x27,
0x25, 0x00, 0x2A, 0x43, 0xD7, 0x85, 0x45, 0x48, 0xD4, 0xF1, 0x0F, 0xF2, 0xD3, 0x80, 0x01, 0x65,
0x01, 0x07, 0x00, 0x65, 0xB4, 0x84, 0x0F, 0xFA, 0x00, 0x63, 0x3F, 0xF2, 0x28, 0x45, 0x60, 0x41,
0xD4, 0x84, 0xDF, 0x83, 0xFC, 0x07, 0x14, 0xFC, 0x17, 0xFA, 0x04, 0x60, 0x00, 0x64, 0x27, 0x45,
0xB4, 0x84, 0x2A, 0xFA, 0x28, 0x43, 0x16, 0xFC, 0x0D, 0x00, 0x3F, 0xF2, 0x2C, 0x45, 0xD4, 0xF1,
0xC4, 0x81, 0xD1, 0x80, 0x0F, 0xF2, 0x01, 0x06, 0x01, 0xBC, 0x0F, 0xFA, 0x3F, 0xF2, 0x17, 0xFA,
0x01, 0x64, 0x14, 0xFA, 0xAA, 0xF2, 0x19, 0x60, 0x3F, 0xF3, 0x07, 0xF0, 0x66, 0x43, 0x64, 0x46,
0x44, 0x44, 0x61, 0x40, 0x08, 0x26, 0x02, 0x00, 0x61, 0x40, 0x80, 0x36, 0x12, 0xF2, 0x63, 0x46,
0x33, 0x60, 0x86, 0x61, 0x00, 0x7F, 0x60, 0x45, 0x45, 0xD3, 0xFF, 0xFF, 0x60, 0x45, 0x00, 0x7F,
0x4B, 0xFB, 0x65, 0x44, 0x00, 0x7E, 0xDA, 0xFB, 0x07, 0xF0, 0x66, 0x43, 0x64, 0x46, 0x12, 0xF0,
0x60, 0x47, 0x63, 0x46, 0x64, 0x40, 0x10, 0x2A, 0x1E, 0x00, 0x33, 0x60, 0x0A, 0x63, 0x60, 0x40,
0x0A, 0x36, 0x0C, 0x00, 0x14, 0x36, 0x07, 0x00, 0x37, 0x36, 0x02, 0x00, 0xA3, 0xD3, 0x09, 0x00,
0x02, 0xA3, 0xA3, 0xD3, 0x06, 0x00, 0x04, 0xA3, 0xA3, 0xD3, 0x03, 0x00, 0x06, 0xA3, 0xA3, 0xD3,
0xFF, 0xFF, 0x60, 0x40, 0x0A, 0x36, 0x70, 0x64, 0x14, 0x36, 0x38, 0x64, 0x37, 0x36, 0x15, 0x64,
0x6E, 0x36, 0x0B, 0x64, 0x39, 0x00, 0x32, 0x60, 0xFA, 0x63, 0x60, 0x40, 0x0B, 0x36, 0x20, 0x00,
0x0F, 0x36, 0x1B, 0x00, 0x0A, 0x36, 0x16, 0x00, 0x0E, 0x36, 0x11, 0x00, 0x09, 0x36, 0x0C, 0x00,
0x0D, 0x36, 0x07, 0x00, 0x08, 0x36, 0x02, 0x00, 0xA3, 0xD3, 0x15, 0x00, 0x02, 0xA3, 0xA3, 0xD3,
0x12, 0x00, 0x04, 0xA3, 0xA3, 0xD3, 0x0F, 0x00, 0x06, 0xA3, 0xA3, 0xD3, 0x0C, 0x00, 0x08, 0xA3,
0xA3, 0xD3, 0x09, 0x00, 0x0A, 0xA3, 0xA3, 0xD3, 0x06, 0x00, 0x0C, 0xA3, 0xA3, 0xD3, 0x03, 0x00,
0x0E, 0xA3, 0xA3, 0xD3, 0xFF, 0xFF, 0x60, 0x40, 0x0B, 0x36, 0x1E, 0x64, 0x0F, 0x36, 0x16, 0x64,
0x0A, 0x36, 0x12, 0x64, 0x0E, 0x36, 0x0E, 0x64, 0x09, 0x36, 0x0E, 0x64, 0x0D, 0x36, 0x0A, 0x64,
0x08, 0x36, 0x0A, 0x64, 0x0C, 0x36, 0x0A, 0x64, 0x40, 0x46, 0x2A, 0xF2, 0x07, 0xF0, 0x60, 0x40,
0xB0, 0x3A, 0x03, 0x00, 0x40, 0x3B, 0x01, 0x00, 0x12, 0x00, 0x0C, 0xB4, 0x08, 0x3A, 0x44, 0x00,
0x22, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x80, 0x2B, 0x3F, 0x00, 0x17, 0xF2, 0x22, 0xF0, 0xFF, 0xFF,
0x64, 0x40, 0x22, 0x22, 0x04, 0x00, 0x00, 0xA8, 0x01, 0xA8, 0x36, 0x03, 0x35, 0x03, 0x3C, 0x46,
0x2A, 0xF0, 0x40, 0x67, 0xB0, 0x84, 0xA2, 0xDA, 0x60, 0x45, 0x22, 0xF2, 0xFF, 0xFF, 0x60, 0x43,
0x60, 0x40, 0x01, 0x26, 0x05, 0x00, 0x04, 0x26, 0x1D, 0x00, 0x10, 0x26, 0x10, 0x00, 0x04, 0x00,
0x04, 0x27, 0x18, 0x00, 0x10, 0x27, 0x0B, 0x00, 0x65, 0x44, 0x2A, 0x61, 0x60, 0x40, 0x03, 0x2B,
0x24, 0x61, 0x8F, 0xB0, 0x88, 0x36, 0x02, 0xA1, 0x41, 0x4C, 0x98, 0xFA, 0x15, 0x00, 0x65, 0x44,
0x32, 0x61, 0x60, 0x40, 0x03, 0x2B, 0x2C, 0x61, 0x8F, 0xB0, 0x88, 0x36, 0x02, 0xA1, 0x41, 0x4C,
0x98, 0xFA, 0x0A, 0x00, 0x65, 0x44, 0x2E, 0x61, 0x60, 0x40, 0x03, 0x2B, 0x28, 0x61, 0x8F, 0xB0,
0x88, 0x36, 0x02, 0xA1, 0x41, 0x4C, 0x98, 0xFA, 0x2A, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x40, 0x27,
0x03, 0x00, 0xBC, 0x60, 0x46, 0x78, 0xFF, 0xFF, 0x22, 0xF2, 0x46, 0x43, 0x60, 0x40, 0x22, 0x26,
0x09, 0x00, 0x01, 0x26, 0x0A, 0x00, 0x04, 0x26, 0x4B, 0x00, 0x10, 0x26, 0x10, 0x00, 0xBC, 0x60,
0x46, 0x78, 0xFF, 0xFF, 0xBB, 0x60, 0xC1, 0x78, 0xFF, 0xFF, 0x04, 0x27, 0x3D, 0x00, 0x10, 0x27,
0x03, 0x00, 0xBC, 0x60, 0x46, 0x78, 0xFF, 0xFF, 0xA6, 0xF3, 0x3C, 0xF1, 0x02, 0x00, 0x07, 0xF2,
0x00, 0x7C, 0x40, 0x43, 0x2A, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x08, 0x27, 0x21, 0x00, 0xA3, 0x46,
0x4B, 0xF2, 0xFF, 0xFF, 0xDC, 0x84, 0x4B, 0xFA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, 0x37, 0x00, 0x63,
0x0F, 0x37, 0x02, 0x63, 0x0A, 0x37, 0x04, 0x63, 0x0E, 0x37, 0x06, 0x63, 0x09, 0x37, 0x08, 0x63,
0x0D, 0x37, 0x0A, 0x63, 0x08, 0x37, 0x0C, 0x63, 0x0C, 0x37, 0x0E, 0x63, 0x28, 0xA3, 0x47, 0xD1,
0xD8, 0xA3, 0xD7, 0x83, 0x19, 0x60, 0x77, 0xF9, 0x47, 0xD1, 0x40, 0x67, 0xB0, 0x84, 0x1F, 0xFA,
0x58, 0x00, 0x2A, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x80, 0x36, 0x19, 0x00, 0x50, 0x36, 0x17, 0x00,
0x40, 0x36, 0x15, 0x00, 0x00, 0x36, 0x13, 0x00, 0x20, 0x36, 0x11, 0x00, 0xA0, 0x36, 0x0F, 0x00,
0xB0, 0x36, 0x0D, 0x00, 0xC0, 0x36, 0x0B, 0x00, 0xDA, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x0A, 0x37,
0x06, 0x00, 0x19, 0x60, 0x7B, 0xF3, 0x80, 0x60, 0x00, 0x61, 0x60, 0x40, 0x04, 0x26, 0x00, 0x61,
0xDA, 0xF3, 0x2C, 0x60, 0x74, 0x65, 0x60, 0x40, 0x0A, 0x37, 0x00, 0x63, 0x14, 0x37, 0x02, 0x63,
0x37, 0x37, 0x04, 0x63, 0x6E, 0x37, 0x06, 0x63, 0x28, 0xA3, 0x47, 0xD1, 0xD8, 0xA3, 0xD7, 0x83,
0x19, 0x60, 0x77, 0xF9, 0x47, 0xD1, 0xFF, 0xFF, 0xB1, 0x84, 0x1F, 0xFA, 0xDA, 0xF1, 0x2C, 0x45,
0x64, 0x43, 0x17, 0xF2, 0x4B, 0xF1, 0xC4, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x81, 0x63, 0x40,
0x37, 0x37, 0xE1, 0x81, 0x64, 0x45, 0xB8, 0x60, 0x58, 0x4D, 0x15, 0x78, 0xFF, 0xFF, 0xAE, 0x82,
0xFC, 0xA2, 0x0A, 0x03, 0x63, 0x40, 0x6E, 0x3B, 0x06, 0x00, 0x60, 0x41, 0x04, 0x0D, 0x63, 0x44,
0x80, 0x7E, 0xDA, 0xFB, 0x61, 0x44, 0xDC, 0x84, 0x2B, 0xF0, 0x1B, 0xFA, 0x64, 0x44, 0x80, 0x27,
0x58, 0x00, 0x07, 0xF0, 0x66, 0x45, 0x64, 0x46, 0x12, 0xF2, 0x65, 0x46, 0x60, 0x40, 0x10, 0x2A,
0x31, 0x00, 0x16, 0xF2, 0x0F, 0xF0, 0xAC, 0x84, 0x2C, 0x45, 0x2C, 0x03, 0x4B, 0xF1, 0xC4, 0x84,
0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x81, 0x63, 0x40, 0x37, 0x37, 0xE1, 0x81, 0x64, 0x45, 0x0F, 0xF0,
0xB8, 0x60, 0x58, 0x4D, 0x15, 0x78, 0xFF, 0xFF, 0xAE, 0x82, 0xFC, 0xA2, 0x0A, 0x03, 0x63, 0x40,
0x6E, 0x3B, 0x06, 0x00, 0x60, 0x41, 0x04, 0x0D, 0x80, 0x67, 0xB0, 0x84, 0x0F, 0xFA, 0x61, 0x44,
0xDC, 0x84, 0x1D, 0xFA, 0x1F, 0xF0, 0x01, 0x60, 0x3E, 0x65, 0x64, 0x40, 0x80, 0x27, 0x02, 0x00,
0x02, 0x60, 0x5E, 0x65, 0x1B, 0xF0, 0x26, 0x41, 0xE1, 0x81, 0xC5, 0x81, 0x44, 0x94, 0xC1, 0x81,
0x2B, 0xFA, 0x90, 0xFA, 0x26, 0x44, 0x2C, 0xF0, 0x0A, 0xA4, 0x66, 0x45, 0x24, 0x46, 0x92, 0xF2,
0x65, 0x46, 0x9F, 0xF0, 0x61, 0x40, 0x10, 0x2A, 0x05, 0x00, 0x60, 0xA4, 0x65, 0x40, 0x80, 0x2B,
0x60, 0xA4, 0x01, 0x00, 0x14, 0xA4, 0x64, 0x40, 0x01, 0x26, 0x00, 0x64, 0x60, 0x45, 0x2A, 0xF2,
0x39, 0xF0, 0x8F, 0xB0, 0x88, 0x3A, 0x04, 0x00, 0x64, 0x44, 0x60, 0xB0, 0x20, 0x36, 0x00, 0x65,
0x65, 0x44, 0x11, 0xFA, 0xDA, 0xF3, 0x13, 0xFA, 0x7C, 0x44, 0x1D, 0xFA, 0x0F, 0xF0, 0xFF, 0xFF,
0x64, 0x40, 0x01, 0x2A, 0x6F, 0x00, 0x7D, 0xF1, 0x19, 0x60, 0x7B, 0xF3, 0x64, 0x40, 0x01, 0x27,
0x03, 0x00, 0x60, 0x40, 0x02, 0x26, 0x14, 0x00, 0x07, 0xF0, 0x66, 0x43, 0x64, 0x46, 0x12, 0xF0,
0x19, 0x60, 0x7C, 0xF3, 0x63, 0x46, 0x64, 0x40, 0x10, 0x2A, 0x20, 0x00, 0x60, 0x40, 0x02, 0x26,
0x07, 0x00, 0x01, 0x26, 0x08, 0x00, 0x04, 0x26, 0x09, 0x00, 0x06, 0x61, 0x6E, 0x63, 0x08, 0x00,
0x02, 0x61, 0x14, 0x63, 0x05, 0x00, 0x00, 0x61, 0x0A, 0x63, 0x02, 0x00, 0x04, 0x61, 0x37, 0x63,
0x00, 0x64, 0x2C, 0x60, 0x9C, 0x65, 0x45, 0xD1, 0xD5, 0x81, 0x19, 0x60, 0x78, 0xF9, 0x2C, 0x60,
0x74, 0x65, 0x45, 0xD1, 0x1C, 0xFC, 0xB0, 0x84, 0x1E, 0xFA, 0x3C, 0x00, 0x60, 0x40, 0x10, 0x2A,
0x04, 0x00, 0x08, 0x61, 0x1E, 0x60, 0x0B, 0x63, 0x27, 0x00, 0x20, 0x2A, 0x04, 0x00, 0x0A, 0x61,
0x16, 0x60, 0x0F, 0x63, 0x21, 0x00, 0x40, 0x2A, 0x04, 0x00, 0x0C, 0x61, 0x12, 0x60, 0x0A, 0x63,
0x1B, 0x00, 0x80, 0x2A, 0x04, 0x00, 0x0E, 0x61, 0x0E, 0x60, 0x0E, 0x63, 0x15, 0x00, 0x01, 0x2B,
0x04, 0x00, 0x10, 0x61, 0x0E, 0x60, 0x09, 0x63, 0x0F, 0x00, 0x02, 0x2B, 0x04, 0x00, 0x12, 0x61,
0x0A, 0x60, 0x0D, 0x63, 0x09, 0x00, 0x04, 0x2B, 0x04, 0x00, 0x14, 0x61, 0x0A, 0x60, 0x08, 0x63,
0x03, 0x00, 0x16, 0x61, 0x0A, 0x60, 0x0C, 0x63, 0x1E, 0xF0, 0x40, 0x67, 0x2C, 0x60, 0x9C, 0x65,
0x45, 0xD1, 0xD5, 0x81, 0x19, 0x60, 0x78, 0xF9, 0x2C, 0x60, 0x74, 0x65, 0x45, 0xD1, 0x1C, 0xFC,
0xB0, 0x84, 0x1E, 0xFA, 0xFF, 0xFF, 0x0D, 0xF2, 0x3E, 0xF0, 0x60, 0x47, 0xFF, 0xB4, 0x64, 0x41,
0x01, 0xB1, 0x01, 0x63, 0x17, 0x02, 0x60, 0x41, 0xFF, 0x22, 0x04, 0x00, 0xB8, 0x60, 0x58, 0x4F,
0x06, 0x78, 0xFF, 0xFF, 0x07, 0x60, 0xED, 0xFD, 0x19, 0x60, 0xCF, 0xF3, 0xFF, 0xFF, 0x60, 0x41,
0x01, 0x63, 0x61, 0x40, 0xFF, 0x22, 0x04, 0x00, 0xB8, 0x60, 0x58, 0x4F, 0x06, 0x78, 0xFF, 0xFF,
0x07, 0x60, 0xEE, 0xFD, 0x02, 0x64, 0x3B, 0xDB, 0xBF, 0x60, 0xE4, 0x78, 0xFF, 0xFF, 0x66, 0x44,
0xFC, 0xFB, 0x07, 0xF0, 0x00, 0x64, 0xD0, 0x80, 0xA6, 0xF3, 0x0E, 0x03, 0xD0, 0x80, 0xFF, 0xFF,
0x0B, 0x03, 0x47, 0xF1, 0x07, 0xF0, 0x64, 0x40, 0x02, 0x26, 0x01, 0x00, 0x08, 0x00, 0x03, 0x12,
0xBE, 0x60, 0xA0, 0x78, 0xFF, 0xFF, 0xFC, 0x0A, 0xBF, 0x60, 0x00, 0x78, 0xFF, 0xFF, 0x87, 0xF0,
0xA6, 0xF3, 0x10, 0xF0, 0xD4, 0x80, 0xFF, 0xFF, 0x3D, 0x03, 0x66, 0x43, 0x65, 0x46, 0xFF, 0x67,
0x20, 0x85, 0x64, 0x5F, 0x40, 0x44, 0x15, 0xF0, 0x25, 0x44, 0xD0, 0x84, 0x03, 0xA4, 0x03, 0x0E,
0xE8, 0x84, 0xE8, 0x84, 0x04, 0x00, 0xFA, 0xA4, 0xE8, 0x84, 0xE8, 0x87, 0xC0, 0xBF, 0xC0, 0x84,
0x15, 0xFA, 0x40, 0x45, 0x14, 0xF0, 0x24, 0x44, 0xD0, 0x84, 0x1F, 0xA4, 0x06, 0x0E, 0xE8, 0x84,
0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0x07, 0x00, 0xC2, 0xA4, 0xE8, 0x84, 0xE8, 0x84,
0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x87, 0xF8, 0xBF, 0xC0, 0x84, 0x14, 0xFA, 0x60, 0x5C, 0x2F, 0x67,
0xD0, 0x80, 0x60, 0x45, 0x02, 0x28, 0x64, 0x45, 0x25, 0x5C, 0x8B, 0x67, 0xD0, 0x80, 0x60, 0x41,
0x02, 0x24, 0x64, 0x41, 0xD5, 0x84, 0x80, 0x65, 0xC4, 0x87, 0x01, 0x05, 0x00, 0x64, 0xFF, 0xB4,
0x0E, 0xFA, 0x63, 0x46, 0x07, 0xF0, 0x66, 0x43, 0x64, 0x46, 0x17, 0xF2, 0x63, 0x46, 0x60, 0x40,
0x00, 0x36, 0x2E, 0x00, 0x01, 0x36, 0x1E, 0x00, 0x03, 0x3A, 0x25, 0x00, 0x64, 0x46, 0x10, 0xF2,
0x11, 0xFA, 0x12, 0xF2, 0x00, 0x61, 0x60, 0x47, 0x00, 0x7F, 0x12, 0xFA, 0x97, 0xFA, 0x46, 0x44,
0x63, 0x46, 0xC2, 0x60, 0x58, 0x4E, 0x4C, 0x78, 0xFF, 0xFF, 0x65, 0x40, 0x00, 0x3A, 0x04, 0x00,
0xC2, 0x60, 0x58, 0x4E, 0x96, 0x78, 0xFF, 0xFF, 0x07, 0xF0, 0x66, 0x43, 0x64, 0x46, 0x96, 0xFC,
0x63, 0x46, 0x43, 0x00, 0x64, 0x46, 0x16, 0xF2, 0x00, 0x61, 0x20, 0x28, 0xFF, 0xA4, 0x97, 0xFA,
0x16, 0xFA, 0x63, 0x46, 0x3A, 0x00, 0x64, 0x46, 0x00, 0x61, 0x97, 0xFA, 0x63, 0x46, 0x35, 0x00,
0x07, 0xF0, 0x66, 0x41, 0x64, 0x46, 0x16, 0xF2, 0xFF, 0xFF, 0x20, 0x28, 0xFF, 0xA4, 0x16, 0xFA,
0x93, 0xF4, 0x12, 0xF2, 0x20, 0x28, 0xFF, 0xA3, 0x13, 0xFC, 0x61, 0x46, 0x63, 0x40, 0x00, 0x3A,
0x24, 0x00, 0xC2, 0x60, 0x58, 0x4E, 0x6D, 0x78, 0xFF, 0xFF, 0x61, 0x40, 0xFF, 0x36, 0x1D, 0x00,
0x66, 0x41, 0x64, 0x46, 0x12, 0xF2, 0x93, 0xF4, 0x61, 0x46, 0x20, 0x28, 0x16, 0x00, 0x44, 0x44,
0xC2, 0x60, 0x58, 0x4E, 0x4C, 0x78, 0xFF, 0xFF, 0x24, 0x5C, 0x65, 0x40, 0x00, 0x36, 0x06, 0x00,
0x66, 0x41, 0x64, 0x46, 0x01, 0x64, 0x17, 0xFA, 0x61, 0x46, 0x07, 0x00, 0x66, 0x43, 0x64, 0x46,
0xC2, 0x60, 0x58, 0x4E, 0x96, 0x78, 0xFF, 0xFF, 0x63, 0x46, 0xBF, 0x60, 0x00, 0x78, 0xFF, 0xFF,
0x07, 0xF0, 0x66, 0x43, 0x64, 0x46, 0x17, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0xFF, 0x27, 0xFF, 0xFF,
0x00, 0x36, 0x07, 0x00, 0x01, 0x36, 0x1C, 0x00, 0x02, 0x36, 0x24, 0x00, 0x03, 0x36, 0x43, 0x00,
0xFF, 0xFF, 0x19, 0x60, 0xA9, 0xF1, 0x16, 0xF2, 0x43, 0x44, 0xD0, 0x80, 0x33, 0x60, 0x84, 0x61,
0x09, 0x03, 0xA1, 0xD1, 0x33, 0x60, 0x82, 0x63, 0xC0, 0x84, 0x16, 0xFA, 0xA3, 0xD3, 0xFF, 0xFF,
0x13, 0xFA, 0x39, 0x00, 0x96, 0xFC, 0xC2, 0x60, 0x58, 0x4E, 0x96, 0x78, 0xFF, 0xFF, 0x33, 0x00,
0x43, 0x44, 0xC2, 0x60, 0x58, 0x4E, 0x96, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0xC1, 0xF3, 0x96, 0xFC,
0x13, 0xFA, 0x29, 0x00, 0x63, 0x46, 0x33, 0x60, 0x54, 0x63, 0xA3, 0xD3, 0x15, 0xF2, 0x60, 0x45,
0xD4, 0x80, 0x07, 0xF0, 0x0C, 0x03, 0x66, 0x41, 0x44, 0x44, 0x64, 0x46, 0x12, 0xF2, 0x61, 0x46,
0xC2, 0x60, 0x58, 0x4E, 0x4C, 0x78, 0xFF, 0xFF, 0x65, 0x40, 0x00, 0x3A, 0x19, 0x00, 0x66, 0x43,
0x24, 0x46, 0xC2, 0x60, 0x58, 0x4E, 0x96, 0x78, 0xFF, 0xFF, 0x12, 0xF2, 0x91, 0xF2, 0x90, 0xFA,
0x60, 0x5F, 0x12, 0xFA, 0x04, 0x00, 0xC2, 0x60, 0x58, 0x4E, 0x96, 0x78, 0xFF, 0xFF, 0x03, 0x64,
0x17, 0xFA, 0x63, 0x46, 0x05, 0x00, 0x24, 0x43, 0x02, 0x64, 0x17, 0xFA, 0x63, 0x46, 0x00, 0x00,
0x03, 0x64, 0x3B, 0xDB, 0xCA, 0xFE, 0x47, 0xF1, 0x01, 0x65, 0x32, 0x40, 0x04, 0x27, 0x11, 0x00,
0x2C, 0xF2, 0x64, 0x45, 0x02, 0x22, 0x0D, 0x00, 0x60, 0x40, 0x01, 0x26, 0x0A, 0x00, 0x2A, 0xF2,
0x39, 0xF0, 0x8F, 0xB0, 0x88, 0x3A, 0x77, 0x00, 0x64, 0x44, 0x60, 0xB0, 0x20, 0x36, 0x01, 0x00,
0x72, 0x00, 0x14, 0xF2, 0x65, 0x40, 0x01, 0x26, 0x0C, 0x00, 0x60, 0x45, 0x05, 0x64, 0x3B, 0xDB,
0x65, 0x44, 0xCC, 0x85, 0x2C, 0x60, 0xD0, 0x64, 0xF1, 0x60, 0x78, 0x41, 0xF0, 0x78, 0xB5, 0xF1,
0x50, 0x00, 0x60, 0x41, 0x2A, 0xF0, 0x00, 0x60, 0x0C, 0x64, 0xA0, 0x84, 0x04, 0x36, 0x02, 0x00,
0x0C, 0x3A, 0x01, 0x00, 0x46, 0x00, 0x61, 0x45, 0x60, 0x43, 0x2C, 0x60, 0xD0, 0x64, 0xF1, 0x60,
0x78, 0x41, 0xF0, 0x78, 0xB5, 0xF1, 0x63, 0x40, 0x08, 0x36, 0x01, 0x00, 0x3A, 0x00, 0x14, 0xF2,
0x1C, 0x65, 0x60, 0x41, 0x00, 0x63, 0xCD, 0x81, 0xC7, 0x83, 0xFD, 0x02, 0x3F, 0xF0, 0x2C, 0xF2,
0xC3, 0x83, 0x60, 0x40, 0x01, 0x2A, 0x0D, 0x00, 0x2C, 0x60, 0xCE, 0x64, 0xF1, 0x60, 0x78, 0x41,
0xE4, 0x78, 0xB5, 0xF1, 0x2C, 0x60, 0xD4, 0x64, 0xF1, 0x60, 0x78, 0x41, 0xEF, 0x78, 0x63, 0x45,
0x20, 0x00, 0x2C, 0x60, 0xCC, 0x64, 0xF1, 0x60, 0x78, 0x41, 0xE4, 0x78, 0xB5, 0xF1, 0x2C, 0x60,
0xD2, 0x64, 0xF1, 0x60, 0x78, 0x41, 0xEF, 0x78, 0x63, 0x45, 0x15, 0xF2, 0xFF, 0xFF, 0x0F, 0xB4,
0x00, 0xA8, 0x01, 0xA8, 0x0E, 0x03, 0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F5, 0xF9,
0x00, 0x64, 0x19, 0x60, 0xF4, 0xFB, 0x0E, 0x60, 0x37, 0xF3, 0xFF, 0xFF, 0xCC, 0x84, 0xFF, 0x2B,
0xA2, 0xDB, 0xCF, 0xF1, 0x07, 0x60, 0xE9, 0xF3, 0x64, 0x40, 0x02, 0x3A, 0x3A, 0x00, 0x0A, 0x60,
0x18, 0xF1, 0x10, 0xB4, 0x90, 0x80, 0xFF, 0xFF, 0x34, 0x03, 0x0A, 0x60, 0x18, 0xFB, 0x01, 0x63,
0x60, 0x40, 0x10, 0x22, 0x00, 0x63, 0x08, 0x60, 0xC1, 0xFD, 0x08, 0x60, 0xC5, 0xFD, 0x08, 0x60,
0xC9, 0xFD, 0x08, 0x60, 0xCD, 0xFD, 0x7D, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x23, 0x21, 0x00,
0x0B, 0x36, 0x07, 0x00, 0x0C, 0x36, 0x05, 0x00, 0x0D, 0x36, 0x03, 0x00, 0x0E, 0x36, 0x01, 0x00,
0x18, 0x00, 0xDB, 0xF3, 0x01, 0x63, 0x0E, 0x60, 0x36, 0xFD, 0x60, 0x40, 0x03, 0x3A, 0x08, 0x00,
0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x04, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x09, 0x00,
0x04, 0x3A, 0x07, 0x00, 0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x10, 0x64, 0xB0, 0x84, 0xA2, 0xDB,
0xCF, 0xFE, 0x10, 0x64, 0x3B, 0xDB, 0x7E, 0xF3, 0x73, 0x45, 0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84,
0xE0, 0x84, 0xC4, 0x93, 0xC9, 0xFE, 0x49, 0xF3, 0x3C, 0x46, 0x25, 0x18, 0xCC, 0x84, 0x49, 0xFB,
0x22, 0x02, 0xC2, 0x60, 0x45, 0x64, 0x40, 0x42, 0xFC, 0xFC, 0x00, 0x64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 0x00, 0x10, 0xAC, 0xA3, 0xDB, 0x05, 0x7C, 0x0E, 0x60, 0xDE, 0xF9,
0xB8, 0x60, 0x03, 0x78, 0xFF, 0xFF, 0x46, 0xF3, 0x45, 0xF1, 0x04, 0x1B, 0x64, 0x44, 0x02, 0x1B,
0x07, 0x60, 0xED, 0xF3, 0x45, 0xFB, 0x00, 0x63, 0x46, 0xFD, 0x60, 0x41, 0x25, 0x64, 0x3B, 0xDB,
0x27, 0x44, 0xEF, 0xB4, 0x40, 0x47, 0x00, 0xB9, 0x71, 0x40, 0x80, 0x27, 0x01, 0x12, 0x27, 0x03,
0xC1, 0x60, 0xC5, 0x62, 0x84, 0xFF, 0x42, 0x42, 0x82, 0xFF, 0xA0, 0x4C, 0x14, 0xBC, 0xFF, 0xB4,
0xA0, 0x51, 0x2D, 0x0A, 0xA1, 0xFF, 0xFF, 0xFF, 0x81, 0x3E, 0x70, 0x44, 0xAC, 0x80, 0x27, 0x0A,
0x71, 0x40, 0x80, 0x27, 0xF7, 0x12, 0x45, 0xF3, 0x48, 0x02, 0x11, 0x18, 0x1B, 0x60, 0xEE, 0xF3,
0x1B, 0x60, 0xEF, 0xF3, 0x07, 0x18, 0x06, 0x18, 0xAC, 0x4C, 0x80, 0x26, 0x03, 0x00, 0x00, 0x64,
0x45, 0xFB, 0x05, 0x00, 0x45, 0xF3, 0xFF, 0xFF, 0xCC, 0x84, 0x45, 0xFB, 0xE3, 0x02, 0x06, 0x0A,
0xA0, 0x4C, 0xFB, 0xB4, 0xA0, 0x51, 0xA4, 0x60, 0x58, 0x78, 0xFF, 0xFF, 0x84, 0xFF, 0xC1, 0x60,
0xA3, 0x64, 0x40, 0x42, 0x82, 0xFF, 0xA0, 0x4C, 0x14, 0xBC, 0xFF, 0xB4, 0xA0, 0x51, 0xB0, 0x60,
0x9E, 0x78, 0xFF, 0xFF, 0x3C, 0x44, 0xAC, 0x80, 0x32, 0xF1, 0x25, 0x03, 0x64, 0x40, 0x07, 0x22,
0x22, 0x00, 0xA4, 0x60, 0x36, 0x78, 0xFF, 0xFF, 0xA0, 0x4C, 0x1C, 0xBC, 0xDF, 0xB4, 0xA0, 0x51,
0x31, 0x40, 0x08, 0x2A, 0xEF, 0x01, 0x72, 0xF3, 0x70, 0xF1, 0x00, 0xA0, 0xDC, 0x80, 0x05, 0x03,
0x08, 0x03, 0xCC, 0x84, 0x72, 0xFB, 0x67, 0x50, 0x08, 0x00, 0xCC, 0x84, 0x72, 0xFB, 0x64, 0x50,
0x04, 0x00, 0x31, 0x44, 0xF7, 0xB4, 0x40, 0x51, 0x06, 0x00, 0x28, 0x64, 0x3A, 0xDB, 0xA0, 0x4C,
0x30, 0xBC, 0xF3, 0xB4, 0xA0, 0x51, 0xA1, 0xFF, 0xFF, 0xFF, 0x81, 0x3E, 0x28, 0x64, 0x3B, 0xDB,
0x07, 0x60, 0xEE, 0xF3, 0x32, 0x40, 0x02, 0x27, 0x16, 0x00, 0x46, 0xFB, 0x14, 0x18, 0xC2, 0x60,
0x33, 0x64, 0x84, 0xFF, 0x40, 0x42, 0x82, 0xFF, 0xA0, 0x4C, 0x15, 0xBC, 0xF7, 0xB4, 0xA0, 0x51,
0xA1, 0xFF, 0xFF, 0xFF, 0x81, 0x3E, 0x70, 0x44, 0xAC, 0x80, 0x46, 0xF3, 0xB8, 0x0A, 0xDD, 0x02,
0xCC, 0x84, 0x46, 0xFB, 0xF5, 0x02, 0x84, 0xFF, 0xC2, 0x60, 0x45, 0x64, 0x40, 0x42, 0x82, 0xFF,
0x27, 0x44, 0x08, 0xBC, 0x40, 0x47, 0xF9, 0xE1, 0x04, 0x00, 0x78, 0xE1, 0x31, 0x40, 0x01, 0x26,
0xF9, 0xE1, 0xA4, 0x60, 0x2D, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0xAB, 0xF1, 0x60, 0x45, 0x33, 0x60,
0x6A, 0x61, 0xC5, 0x83, 0xA3, 0xD3, 0xFF, 0xFF, 0x60, 0x41, 0x66, 0x45, 0x24, 0x46, 0x0E, 0xF2,
0x65, 0x46, 0x64, 0x45, 0xD5, 0x81, 0x61, 0x45, 0x00, 0x7F, 0xD4, 0x80, 0x64, 0x43, 0x08, 0x04,
0xE3, 0x83, 0x63, 0x45, 0xC5, 0x81, 0x61, 0x45, 0xD4, 0x80, 0x02, 0x65, 0x03, 0x07, 0x03, 0x00,
0x00, 0x65, 0x01, 0x00, 0x01, 0x65, 0x2E, 0x58, 0xFF, 0xFF, 0x66, 0x43, 0x64, 0x46, 0x8F, 0xF0,
0x12, 0xF2, 0x91, 0xF2, 0x60, 0x40, 0x10, 0x36, 0x05, 0x00, 0x12, 0x36, 0x08, 0x00, 0x0C, 0x36,
0x0B, 0x00, 0x0F, 0x00, 0x40, 0x61, 0xA5, 0x80, 0x0A, 0x64, 0x13, 0x02, 0xF3, 0x01, 0x10, 0x61,
0xA5, 0x80, 0x0E, 0x64, 0x0E, 0x02, 0xEE, 0x01, 0x08, 0x61, 0xA5, 0x80, 0x10, 0x64, 0x09, 0x02,
0xE9, 0x01, 0xE1, 0x81, 0xA5, 0x80, 0x03, 0x05, 0xC8, 0x84, 0x03, 0x02, 0xE3, 0x01, 0xFF, 0x61,
0x02, 0x00, 0x12, 0xFA, 0x91, 0xFA, 0x63, 0x46, 0x2E, 0x58, 0xFF, 0xFF, 0x8F, 0xF0, 0x12, 0xF2,
0x91, 0xF2, 0x60, 0x40, 0x0A, 0x36, 0x05, 0x00, 0x0E, 0x36, 0x08, 0x00, 0x10, 0x36, 0x0B, 0x00,
0x0F, 0x00, 0x08, 0x61, 0xA5, 0x80, 0x10, 0x7E, 0x11, 0x02, 0xF3, 0x01, 0x04, 0x61, 0xA5, 0x80,
0x12, 0x7E, 0x0C, 0x02, 0xEE, 0x01, 0x20, 0x61, 0xA5, 0x80, 0x0C, 0x7E, 0x07, 0x02, 0xE9, 0x01,
0xE9, 0x81, 0xA5, 0x80, 0x05, 0x05, 0xD8, 0x84, 0x01, 0x02, 0xE3, 0x01, 0x12, 0xFA, 0x91, 0xFA,
0x2E, 0x58, 0xFF, 0xFF, 0x28, 0x40, 0x08, 0x3A, 0x06, 0x00, 0x04, 0x60, 0x40, 0x62, 0x3D, 0x60,
0x58, 0x4D, 0x3B, 0x78, 0xFF, 0xFF, 0x2F, 0x58, 0xFF, 0xFF, 0x64, 0x40, 0x01, 0x2B, 0x50, 0x00,
0x28, 0x40, 0x08, 0x3A, 0x4D, 0x00, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0xE8, 0x84, 0x19, 0x60,
0x52, 0xFB, 0x7D, 0xF1, 0x2B, 0x60, 0x82, 0x63, 0x64, 0x40, 0x01, 0x27, 0x3C, 0xA3, 0x29, 0x40,
0x40, 0x2B, 0x1E, 0xA3, 0xBD, 0xD1, 0x63, 0x45, 0x44, 0x4E, 0x0E, 0x61, 0xBD, 0xD1, 0xCD, 0x81,
0xD0, 0x80, 0x01, 0x03, 0xFB, 0x04, 0xCB, 0x83, 0x19, 0x60, 0x55, 0xF3, 0x39, 0xF1, 0xD7, 0x83,
0xEB, 0x83, 0x2E, 0x41, 0x5D, 0x93, 0xDF, 0x83, 0x19, 0x60, 0x51, 0xFD, 0x19, 0x60, 0x50, 0xFB,
0x53, 0x93, 0xDF, 0x80, 0x10, 0x03, 0x38, 0xF3, 0xCF, 0x83, 0x08, 0x03, 0xDF, 0x83, 0x0B, 0x02,
0xDF, 0x83, 0xDC, 0x84, 0xF0, 0xA0, 0x38, 0xFB, 0x06, 0x03, 0x03, 0x00, 0xCC, 0x84, 0x38, 0xFB,
0x02, 0x03, 0x00, 0x63, 0x02, 0x00, 0x08, 0x64, 0x38, 0xFB, 0xE3, 0x80, 0xFB, 0x83, 0xC3, 0x83,
0x63, 0x44, 0xFC, 0xA0, 0x02, 0x0E, 0x08, 0x07, 0x08, 0x00, 0x04, 0xA4, 0xFF, 0xFF, 0x05, 0x0D,
0xFC, 0x64, 0xFF, 0x7F, 0x60, 0x43, 0x01, 0x00, 0x04, 0x63, 0x39, 0xF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03, 0xD7, 0x03,
0x2D, 0x46, 0x01, 0x64, 0x12, 0xFA, 0xF4, 0x01, 0x07, 0xF4, 0x66, 0x41, 0x03, 0xF2, 0x04, 0xF2,
0x40, 0x42, 0x05, 0xF2, 0x40, 0x43, 0x40, 0x44, 0x61, 0x46, 0x3C, 0xF2, 0x3D, 0xF2, 0x40, 0x40,
0x40, 0x41, 0x0D, 0x60, 0x70, 0x65, 0x00, 0x61, 0xEE, 0xF1, 0xED, 0xF5, 0x44, 0x4C, 0x2C, 0x5C,
0xE9, 0x80, 0x00, 0x64, 0xF0, 0x84, 0xF0, 0x84, 0xC0, 0x83, 0xBD, 0xD2, 0x24, 0x5C, 0x90, 0x9C,
0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1,
0x64, 0x47, 0x90, 0x9C, 0x20, 0x44, 0x40, 0x80, 0xDB, 0x83, 0xBD, 0xD2, 0x20, 0x5C, 0x90, 0x9C,
0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1,
0x64, 0x47, 0x90, 0x9C, 0x21, 0x44, 0x40, 0x81, 0xDB, 0x83, 0xBD, 0xD2, 0x21, 0x5C, 0x90, 0x9C,
0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1,
0x64, 0x47, 0x90, 0x9C, 0x22, 0x44, 0x40, 0x82, 0xDB, 0x83, 0xBD, 0xD2, 0x22, 0x5C, 0x90, 0x9C,
0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1,
0x64, 0x47, 0x90, 0x9C, 0x23, 0x44, 0x40, 0x83, 0xF2, 0xA3, 0xBD, 0xD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xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C, 0x21, 0x44,
0x40, 0x81, 0xBD, 0xD2, 0x21, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1,
0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C, 0x22, 0x44, 0x40, 0x82,
0xBD, 0xD2, 0x22, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44,
0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C, 0x23, 0x44, 0x40, 0x83, 0xBD, 0xD2,
0x23, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F,
0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C, 0x24, 0x44, 0x40, 0x84, 0xBD, 0xD2, 0x24, 0x5C,
0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84,
0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C, 0x25, 0x44, 0x40, 0x85, 0x61, 0x46, 0x3A, 0xF0, 0xFF, 0xFF,
0x64, 0x44, 0xE0, 0x7F, 0xA0, 0x5B, 0x64, 0x47, 0xE1, 0x7F, 0x5A, 0xD0, 0xA0, 0x5B, 0x64, 0x44,
0xE2, 0x7F, 0xA0, 0x5B, 0x64, 0x47, 0xED, 0xF5, 0xBD, 0xD2, 0x25, 0x5C, 0x90, 0x84, 0xE8, 0x80,
0xF8, 0x84, 0x20, 0x5C, 0x40, 0x80, 0x20, 0x44, 0xE4, 0x7F, 0xA0, 0x5B, 0x20, 0x47, 0xE5, 0x7F,
0xA0, 0x5B, 0xBD,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, 0x47, 0x00, 0x7F,
0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C,
0x26, 0x44, 0x40, 0x86, 0xDB, 0x83, 0xBD, 0xD2, 0x26, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F,
0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C,
0x27, 0x44, 0x40, 0x87, 0xDB, 0x83, 0xBD, 0xD2, 0x27, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F,
0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C,
0x28, 0x44, 0x40, 0x88, 0xDB, 0x83, 0xBD, 0xD2, 0x28, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F,
0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C,
0x29, 0x44, 0x40, 0x89, 0xF2, 0xA3, 0xBD, 0xD2, 0x29, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F,
0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C,
0x2A, 0x44, 0xC0, 0x9C, 0x41, 0x8A, 0xDD, 0x81, 0x08, 0x2A, 0xA7, 0x01, 0x26, 0x44, 0x44, 0xFA,
0x27, 0x44, 0x45, 0xFA, 0x28, 0x44, 0x46, 0xFA, 0x29, 0x44, 0x47, 0xFA, 0x2A, 0x44, 0x48, 0xFA,
0x06, 0x60, 0x7E, 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x60, 0x88, 0x7C, 0x44, 0x4D, 0x2D, 0x42,
0xA2, 0xD2, 0x5A, 0xD0, 0x40, 0x46, 0x44, 0x47, 0x5A, 0xD2, 0x5A, 0xD0, 0x40, 0x48, 0x5A, 0xD0,
0x44, 0x49, 0x4B, 0xF2, 0x44, 0x4A, 0x40, 0x8B, 0x60, 0x5C, 0x64, 0x47, 0xE0, 0x7F, 0xA0, 0x5A,
0xFF, 0xB4, 0x20, 0xBC, 0x7F, 0xB4, 0xE1, 0x7F, 0xA0, 0x5A, 0x64, 0x44, 0xE2, 0x7F, 0xA0, 0x5A,
0x00, 0x60, 0x78, 0x63, 0x0D, 0x60, 0x70, 0x65, 0xBD, 0xD2, 0x2B, 0x5C, 0x90, 0x9C, 0x64, 0x47,
0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47,
0x90, 0x9C, 0x26, 0x44, 0x40, 0x86, 0xBD, 0xD2, 0x26, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F,
0xE0, 0x84, 0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C,
0x27, 0x44, 0x40, 0x87, 0xBD, 0xD2, 0x27, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84,
0x44, 0xD1, 0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C, 0x28, 0x44,
0x40, 0x88, 0xBD, 0xD2, 0x28, 0x5C, 0x90, 0x9C, 0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1,
0x64, 0x44, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD1, 0x64, 0x47, 0x90, 0x9C, 0x29, 0x44, 0x40, 0x89,
0xBD, 0xD2, 0x29, 0x5C, 0x90, 0x9C, 0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x65, 0x40, 0x8F, 0xB0, 0x88, 0x3A,
0x02, 0x00, 0x39, 0xF0, 0x59, 0xD9, 0x2F, 0x58, 0xFF, 0xFF, 0x0C, 0x60, 0x16, 0x61, 0xA3, 0x46,
0x00, 0xF4, 0x02, 0x64, 0x0A, 0x63, 0x58, 0xD0, 0x59, 0xD9, 0xFD, 0x1F, 0x59, 0xDF, 0x59, 0xDF,
0xA0, 0x4C, 0x04, 0xBC, 0xFF, 0xB4, 0xA0, 0x51, 0x23, 0x44, 0x01, 0xA7, 0x80, 0xBF, 0x60, 0x50,
0x80, 0x60, 0x38, 0x71, 0x80, 0x60, 0x7C, 0x72, 0x01, 0x76, 0xFF, 0xFF, 0x76, 0x44, 0x01, 0x3A,
0xFD, 0x01, 0x40, 0x76, 0x40, 0x76, 0x42, 0xFF, 0xFF, 0xFF, 0x40, 0x76, 0x80, 0x60, 0x18, 0x70,
0x80, 0x60, 0x18, 0x71, 0x80, 0x60, 0x7C, 0x72, 0x80, 0x60, 0x10, 0x73, 0x02, 0x76, 0x76, 0x44,
0xFF, 0xFF, 0x76, 0x44, 0x02, 0x3A, 0xFD, 0x01, 0x40, 0x76, 0x42, 0xFF, 0x3C, 0x46, 0x00, 0xF2,
0x80, 0x60, 0x00, 0xBC, 0x60, 0x50, 0x80, 0x60, 0x12, 0x71, 0x80, 0x60, 0x6E, 0x72, 0x3F, 0xF2,
0xFF, 0xFF, 0xF8, 0xA7, 0x80, 0xBF, 0x60, 0x53, 0x04, 0x76, 0xFF, 0xFF, 0x88, 0xFF, 0x3C, 0x46,
0x07, 0xF2, 0xFF, 0xFF, 0x40, 0x43, 0xA3, 0x46, 0x2F, 0x58, 0xFF, 0xFF, 0x77, 0x40, 0x8B, 0xFF,
0xA0, 0x4B, 0x04, 0xE1, 0xFF, 0xFF, 0x76, 0x44, 0x04, 0x3A, 0xFD, 0x01, 0x40, 0x76, 0x42, 0xFF,
0xFF, 0xFF, 0x10, 0x76, 0xFF, 0xFF, 0x76, 0x44, 0x20, 0x3A, 0xFD, 0x01, 0x40, 0x76, 0x42, 0xFF,
0x63, 0x44, 0x00, 0x7F, 0xA0, 0x51, 0x02, 0x60, 0x00, 0x75, 0x88, 0xFF, 0xA0, 0x4C, 0xFB, 0xB4,
0xA0, 0x51, 0x06, 0x60, 0x1F, 0xE1, 0x16, 0xFF, 0x2F, 0x58, 0xFF, 0xFF, 0x26, 0x46, 0x3F, 0xF2,
0xFF, 0xFF, 0xF8, 0xA4, 0x3F, 0xFA, 0x00, 0xF4, 0x60, 0x47, 0x08, 0xFA, 0xA0, 0x48, 0x08, 0x26,
0x07, 0x00, 0xA0, 0x4C, 0x04, 0xE1, 0xFF, 0xFF, 0xA1, 0xFF, 0xFF, 0xFF, 0x00, 0x7F, 0xA0, 0x51,
0x42, 0xFF, 0x26, 0x46, 0x8B, 0xFF, 0x02, 0x60, 0x00, 0x75, 0x3C, 0xF2, 0x40, 0x76, 0x14, 0x1B,
0x26, 0x46, 0x3B, 0xF2, 0x0C, 0x60, 0xBA, 0x63, 0x60, 0x47, 0xC0, 0xB4, 0xE8, 0x84, 0xE8, 0x84,
0xE8, 0x84, 0x43, 0x93, 0xE3, 0x9C, 0x64, 0x47, 0x80, 0x7C, 0x64, 0x5F, 0x60, 0x50, 0x7F, 0x64,
0x23, 0x97, 0x80, 0xBF, 0x60, 0x51, 0x07, 0x00, 0x01, 0xA7, 0x80, 0xBF, 0x60, 0x50, 0x80, 0x60,
0x40, 0x71, 0x80, 0x60, 0x7C, 0x72, 0x01, 0x76, 0xFF, 0xFF, 0xA1, 0xFF, 0xFF, 0xFF, 0x0C, 0x21,
0xFC, 0x01, 0x04, 0x25, 0xD5, 0x01, 0x40, 0x76, 0x43, 0xFF, 0x0C, 0x60, 0x22, 0x61, 0x26, 0x46,
0x00, 0xF4, 0x02, 0x64, 0x0A, 0x63, 0x58, 0xD0, 0x59, 0xD9, 0xFD, 0x1F, 0x59, 0xDF, 0x59, 0xDF,
0x80, 0x60, 0x18, 0x70, 0x80, 0x60, 0x24, 0x71, 0x80, 0x60, 0x7C, 0x72, 0x80, 0x60, 0x10, 0x73,
0x02, 0x76, 0xFF, 0xFF, 0xA1, 0xFF, 0xFF, 0xFF, 0x0C, 0x21, 0xFC, 0x01, 0x04, 0x25, 0xB8, 0x01,
0x40, 0x76, 0x43, 0xFF, 0x26, 0x46, 0x00, 0xF2, 0xFF, 0xFF, 0x60, 0x47, 0x80, 0xBF, 0x60, 0x50,
0x80, 0x60, 0x12, 0x71, 0x3F, 0xF2, 0x80, 0x60, 0x6E, 0x72, 0x60, 0x47, 0x80, 0xBF, 0x60, 0x53,
0x04, 0x76, 0xFF, 0xFF, 0xA1, 0xFF, 0xFF, 0xFF, 0x0C, 0x21, 0xFC, 0x01, 0x04, 0x25, 0xA0, 0x01,
0x40, 0x76, 0x43, 0xFF, 0x08, 0x76, 0xFF, 0xFF, 0xA1, 0xFF, 0xFF, 0xFF, 0x0C, 0x21, 0xFC, 0x01,
0x04, 0x25, 0x96, 0x01, 0x76, 0x5C, 0xFF, 0xFF, 0x40, 0x76, 0x43, 0xFF, 0x88, 0xFF, 0x26, 0x46,
0x2F, 0x58, 0xFF, 0xFF, 0xEE, 0x60, 0x60, 0x78, 0xFF, 0xFF, 0x08, 0x60, 0x08, 0xF1, 0x80, 0x60,
0x00, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x2F, 0x00, 0xDB, 0xF3, 0x31, 0x41, 0x01, 0xB1,
0x03, 0xA8, 0x2A, 0x03, 0x15, 0x02, 0x20, 0x40, 0x04, 0x2B, 0x0B, 0x00, 0xBB, 0xFE, 0xCA, 0xFE,
0x1C, 0x60, 0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x02, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF,
0x07, 0x00, 0x08, 0x60, 0x09, 0xF1, 0x00, 0x60, 0x04, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE,
0x08, 0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, 0x2A, 0x03, 0x00, 0x07, 0x60,
0x01, 0x64, 0x22, 0x00, 0x02, 0x2A, 0x03, 0x00, 0x00, 0x60, 0x01, 0x64, 0x1D, 0x00, 0x04, 0x2A,
0x1F, 0x00, 0x2A, 0xF2, 0xFF, 0xFF, 0x0C, 0xB0, 0x08, 0x3A, 0x1A, 0x00, 0x2C, 0xF0, 0x22, 0xF0,
0x64, 0x40, 0x01, 0x26, 0x0B, 0x00, 0x64, 0x40, 0x40, 0x2B, 0x12, 0x00, 0x8F, 0xB0, 0x88, 0x3A,
0x0F, 0x00, 0x39, 0xF2, 0xFF, 0xFF, 0x60, 0xB0, 0x20, 0x3A, 0x0A, 0x00, 0x23, 0xF2, 0x00, 0x60,
0x01, 0x7C, 0xB0, 0x84, 0x23, 0xFA, 0x0C, 0x00, 0x23, 0xFA, 0xD0, 0x60, 0xC1, 0x78, 0xFF, 0xFF,
0xD0, 0x60, 0xB5, 0x78, 0xFF, 0xFF, 0x22, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x10, 0x27, 0xF8, 0x01,
0x0F, 0xF0, 0xFF, 0xFF, 0x64, 0x44, 0x08, 0x26, 0x64, 0x00, 0x2A, 0xF2, 0x60, 0x63, 0x60, 0x40,
0x02, 0x2B, 0x66, 0x63, 0xBE, 0xD2, 0x81, 0xF1, 0xA3, 0xD2, 0xD0, 0x80, 0x80, 0xF1, 0x0D, 0x02,
0xBF, 0xD2, 0xD0, 0x80, 0x7F, 0xF1, 0x09, 0x02, 0xD0, 0x80, 0xFF, 0xFF, 0x06, 0x02, 0x2C, 0x60,
0xF6, 0x64, 0xF1, 0x60, 0x78, 0x41, 0xE4, 0x78, 0xB5, 0xF1, 0x32, 0x44, 0x01, 0x2A, 0x03, 0x00,
0x07, 0x60, 0x02, 0x64, 0x04, 0x00, 0x02, 0x2A, 0x06, 0x00, 0x00, 0x60, 0x02, 0x64, 0x23, 0xFA,
0xD0, 0x60, 0xC1, 0x78, 0xFF, 0xFF, 0x2A,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08, 0x02, 0x2A, 0x44, 0xD0, 0x80, 0x2F, 0xF0, 0x04, 0x02, 0x28, 0x44, 0xD0, 0x80,
0xFF, 0xFF, 0x1E, 0x03, 0x34, 0xF0, 0x2C, 0x44, 0xD0, 0x80, 0x33, 0xF0, 0x08, 0x02, 0x2A, 0x44,
0xD0, 0x80, 0x32, 0xF0, 0x04, 0x02, 0x28, 0x44, 0xD0, 0x80, 0xFF, 0xFF, 0x11, 0x03, 0x38, 0xF0,
0x2C, 0x44, 0xD0, 0x80, 0x37, 0xF0, 0x08, 0x02, 0x2A, 0x44, 0xD0, 0x80, 0x36, 0xF0, 0x04, 0x02,
0x28, 0x44, 0xD0, 0x80, 0xFF, 0xFF, 0x04, 0x03, 0xFA, 0xA1, 0x06, 0xA3, 0xB7, 0x03, 0xC3, 0x01,
0x07, 0x60, 0x00, 0x64, 0x23, 0xFA, 0xD0, 0x60, 0xC1, 0x78, 0xFF, 0xFF, 0x2A, 0xF2, 0x0F, 0xF0,
0x60, 0x45, 0xA4, 0x36, 0x08, 0x00, 0x0C, 0xB4, 0x04, 0x36, 0x02, 0x00, 0x0C, 0x3A, 0x06, 0x00,
0xD0, 0x60, 0xB5, 0x78, 0xFF, 0xFF, 0xCE, 0x60, 0x7C, 0x78, 0xFF, 0xFF, 0x0F, 0xF0, 0x65, 0x40,
0x40, 0x2B, 0x17, 0x00, 0x32, 0x40, 0x08, 0x26, 0x14, 0x00, 0x07, 0xF4, 0x3A, 0xF2, 0xFF, 0xFF,
0x37, 0xB4, 0x26, 0x46, 0x0E, 0x02, 0x2C, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x26, 0x06, 0x00,
0x2C, 0x60, 0xF0, 0x64, 0xF1, 0x60, 0x78, 0x41, 0xE4, 0x78, 0xB5, 0xF1, 0xD0, 0x60, 0xB5, 0x78,
0xFF, 0xFF, 0x2A, 0xF2, 0x64, 0x40, 0x60, 0x26, 0x03, 0x00, 0xCE, 0x60, 0x4E, 0x78, 0xF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D, 0xA0, 0xFF, 0xFF, 0x03, 0x03, 0x20, 0x40,
0x10, 0x22, 0xF4, 0x01, 0x08, 0x60, 0x07, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x36, 0x07, 0x00,
0x01, 0x64, 0xA2, 0xDB, 0x01, 0x65, 0xF1, 0x60, 0x58, 0x4E, 0xC3, 0x78, 0xFF, 0xFF, 0x26, 0x46,
0x31, 0xF2, 0x1D, 0x60, 0xC0, 0x65, 0x60, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD3, 0x66, 0x41,
0x60, 0x46, 0x60, 0x43, 0x05, 0xF2, 0x16, 0x18, 0x61, 0x46, 0x31, 0xF0, 0x63, 0x46, 0xD0, 0x80,
0x04, 0xF2, 0x0C, 0x02, 0x61, 0x46, 0x30, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x03, 0xF2, 0x06, 0x02,
0x61, 0x46, 0x2F, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0xFF, 0xFF, 0x07, 0x03, 0x80, 0xF4, 0xFF, 0xFF,
0x63, 0x46, 0xE8, 0x1B, 0xA6, 0xF3, 0x08, 0xFE, 0x60, 0x43, 0x61, 0x46, 0xA6, 0xF1, 0x43, 0x43,
0xD3, 0x80, 0xFF, 0xFF, 0x03, 0x03, 0xCD, 0x60, 0xD9, 0x78, 0xFF, 0xFF, 0xD0, 0x60, 0x58, 0x4F,
0xFC, 0x78, 0xFF, 0xFF, 0x03, 0x4B, 0x3F, 0xF2, 0x00, 0xF4, 0x60, 0x43, 0xF4, 0xA3, 0x00, 0x60,
0x1D, 0x61, 0x00, 0x60, 0x01, 0x65, 0x01, 0x60, 0xFF, 0x64, 0x40, 0x4C, 0xFD, 0x60, 0x58, 0x4E,
0x7A, 0x78, 0xFF, 0xFF, 0x00, 0xBB, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x64, 0x40, 0x4A, 0x60, 0xFE,
0x02, 0x60, 0x00, 0x63, 0xBD, 0xD3, 0xBD, 0xD3, 0x60, 0x41, 0xFE, 0x60, 0x58, 0x4E, 0x2C, 0x78,
0xFF, 0xFF, 0x20, 0xFE, 0x00, 0x65, 0x00, 0x64, 0x19, 0x60, 0x3B, 0xFB, 0x02, 0x00, 0x20, 0xFE,
0xFF, 0x65, 0x02, 0x60, 0x00, 0x63, 0x60, 0xFE, 0xBD, 0xD3, 0xBD, 0xD3, 0x60, 0x41, 0x20, 0xFE,
0xCD, 0x81, 0x60, 0x40, 0x80, 0x2A, 0x39, 0x00, 0x7F, 0xB4, 0x02, 0x3A, 0x02, 0x00, 0x01, 0x64,
0x2E, 0x00, 0x04, 0x3A, 0x02, 0x00, 0x02, 0x64, 0x2A, 0x00, 0x0B, 0x3A, 0x02, 0x00, 0x04, 0x64,
0x26, 0x00, 0x16, 0x3A, 0x02, 0x00, 0x08, 0x64, 0x22, 0x00, 0x0C, 0x3A, 0x02, 0x00, 0x10, 0x64,
0x1E, 0x00, 0x12, 0x3A, 0x02, 0x00, 0x20, 0x64, 0x1A, 0x00, 0x18, 0x3A, 0x02, 0x00, 0x40, 0x64,
0x16, 0x00, 0x24, 0x3A, 0x02, 0x00, 0x80, 0x64, 0x12, 0x00, 0x30, 0x3A, 0x02, 0x00, 0x01, 0x67,
0x0E, 0x00, 0x48, 0x3A, 0x02, 0x00, 0x02, 0x67, 0x0A, 0x00, 0x60, 0x3A, 0x02, 0x00, 0x04, 0x67,
0x06, 0x00, 0x6C, 0x3A, 0x02, 0x00, 0x08, 0x67, 0x02, 0x00, 0x00, 0x64, 0x00, 0x00, 0x19, 0x60,
0x3B, 0xF1, 0xFF, 0xFF, 0xB0, 0x84, 0x19, 0x60, 0x3B, 0xFB, 0x61, 0x40, 0x00, 0x36, 0x05, 0x00,
0x60, 0xFE, 0xBD, 0xD3, 0xFF, 0xFF, 0x20, 0xFE, 0xBB, 0x01, 0x65, 0x40, 0x00, 0x3A, 0x1E, 0x00,
0x26, 0x46, 0x3F, 0xF2, 0x00, 0xF4, 0x60, 0x43, 0xF4, 0xA3, 0x00, 0x60, 0x1D, 0x61, 0x00, 0x60,
0x32, 0x65, 0x01, 0x60, 0xFF, 0x64, 0x40, 0x4C, 0xFD, 0x60, 0x58, 0x4E, 0x7A, 0x78, 0xFF, 0xFF,
0x00, 0xBB, 0xFF, 0xFF, 0x0B, 0x03, 0x60, 0xFE, 0x02, 0x60, 0x00, 0x63, 0xBD, 0xD3, 0xBD, 0xD3,
0x60, 0x41, 0xFE, 0x60, 0x58, 0x4E, 0x2C, 0x78, 0xFF, 0xFF, 0x91, 0x01, 0x20, 0xFE, 0x00, 0x65,
0xFC, 0x60, 0x58, 0x4E, 0xC7, 0x78, 0xFF, 0xFF, 0xA1, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x27,
0x04, 0x00, 0xFD, 0x60, 0x58, 0x4E, 0x11, 0x78, 0xFF, 0xFF, 0x20, 0xFE, 0x37, 0x60, 0xF8, 0x61,
0xA1, 0xD1, 0xA1, 0xF3, 0x01, 0x60, 0xAC, 0x63, 0x60, 0x45, 0x2A, 0x44, 0x79, 0xFB, 0xA3, 0xD5,
0x65, 0x40, 0x01, 0x27, 0x5B, 0xD5, 0x65, 0x40, 0x01, 0x27, 0x59, 0xD1, 0x66, 0x41, 0xA0, 0x84,
0x24, 0x94, 0x2B, 0x46, 0x0F, 0xFA, 0x7A, 0xFB, 0x16, 0x64, 0x12, 0xFA, 0x01, 0x64, 0x11, 0xFA,
0x66, 0x5C, 0xC2, 0x60, 0x58, 0x4E, 0x6D, 0x78, 0xFF, 0xFF, 0x7D, 0xF3, 0xFF, 0xFF, 0x60, 0x40,
0x01, 0x27, 0x28, 0x00, 0x19, 0x60, 0x44, 0xF3, 0x32, 0x60, 0x88, 0x63, 0xA3, 0xD3, 0xFF, 0xFF,
0x60, 0x40, 0x01, 0x2A, 0x0C, 0x00, 0x0F, 0x64, 0xFC, 0x60, 0x58, 0x4E, 0x34, 0x78, 0xFF, 0xFF,
0xFF, 0x60, 0xFF, 0x63, 0x1A, 0x60, 0xB3, 0xFD, 0x1A, 0x60, 0xC3, 0xFD, 0x1C, 0x00, 0x19, 0x60,
0x39, 0xF3, 0x3F, 0x40, 0x01, 0x27, 0x08, 0x00, 0x0F, 0x60, 0xFF, 0x65, 0xA4, 0x84, 0xFC, 0x60,
0x58, 0x4E, 0x34, 0x78, 0xFF, 0xFF, 0x0F, 0x00, 0x0F, 0xB4, 0xFC, 0x60, 0x58, 0x4E, 0x34, 0x78,
0xFF, 0xFF, 0x09, 0x00, 0x19, 0x60, 0x3A, 0xF3, 0x0F, 0x60, 0xFF, 0x65, 0xA4, 0x84, 0xFC, 0x60,
0x58, 0x4E, 0x34, 0x78, 0xFF, 0xFF, 0xD3, 0x60, 0x58, 0x4E, 0x78, 0x78, 0xFF, 0xFF, 0x26, 0x46,
0x23, 0x43, 0x32, 0x40, 0x08, 0x2A, 0x05, 0x00, 0x63, 0x46, 0x80, 0x60, 0x02, 0x64, 0x06, 0xFA,
0x26, 0x46, 0x2C, 0x60, 0xE4, 0x64, 0xF1, 0x60, 0x78, 0x41, 0xE4, 0x78, 0xB5, 0xF1, 0x27, 0xF2,
0xFF, 0xFF, 0x60, 0x40, 0x01, 0x3B, 0x07, 0x00, 0x2C, 0x60, 0xF2, 0x64, 0xF1, 0x60, 0x78, 0x41,
0xE4, 0x78, 0xB5, 0xF1, 0x08, 0x00, 0x02, 0x3B, 0x06, 0x00, 0x2C, 0x60, 0xF4, 0x64, 0xF1, 0x60,
0x78, 0x41, 0xE4, 0x78, 0xB5, 0xF1, 0x1B, 0xF2, 0xFF, 0xFF, 0xE4, 0xA4, 0x3E, 0xFA, 0x2A, 0xF2,
0x28, 0x41, 0x40, 0xA8, 0x01, 0xB1, 0x02, 0x02, 0x46, 0x02, 0x76, 0x00, 0x60, 0x40, 0x08, 0x2A,
0x0F, 0x00, 0x2C, 0x60, 0xE2, 0x64, 0xF1, 0x60, 0x78, 0x41, 0xE4, 0x78, 0xB5, 0xF1, 0x1B,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x7F, 0xF1, 0xBD, 0xD2, 0xD0, 0x80,
0x80, 0xF1, 0x07, 0x02, 0xD0, 0x80, 0xBD, 0xD2, 0x81, 0xF1, 0x03, 0x02, 0xD0, 0x80, 0xFF, 0xFF,
0x03, 0x03, 0xD0, 0x60, 0xB5, 0x78, 0xFF, 0xFF, 0xE9, 0x60, 0x58, 0x4F, 0x08, 0x78, 0xFF, 0xFF,
0x2A, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x08, 0x26, 0x06, 0x00, 0x20, 0x40, 0x10, 0x2B, 0x03, 0x00,
0xD0, 0x60, 0x6B, 0x78, 0xFF, 0xFF, 0x87, 0xF4, 0xA6, 0xF1, 0x27, 0x1B, 0x31, 0xF2, 0x1D, 0x60,
0xC0, 0x65, 0x60, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD3, 0x66, 0x41, 0x60, 0x46, 0x60, 0x43,
0x05, 0xF2, 0x16, 0x18, 0x61, 0x46, 0x31, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x04, 0xF2, 0x0C, 0x02,
0x61, 0x46, 0x30, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x03, 0xF2, 0x06, 0x02, 0x61, 0x46, 0x2F, 0xF0,
0x63, 0x46, 0xD0, 0x80, 0xFF, 0xFF, 0x07, 0x03, 0x80, 0xF4, 0xFF, 0xFF, 0x63, 0x46, 0xE8, 0x1B,
0xA6, 0xF3, 0x08, 0xFE, 0x60, 0x43, 0x61, 0x46, 0x03, 0x00, 0xD3, 0x80, 0xFF, 0xFF, 0xD6, 0x03,
0x43, 0x43, 0xDB, 0xF3, 0x32, 0x40, 0x02, 0x26, 0x04, 0x00, 0x07, 0xB4, 0x03, 0xA8, 0x2A, 0xF2,
0x45, 0x02, 0xA6, 0xF1, 0x23, 0x43, 0xD3, 0x80, 0xFF, 0xFF, 0x40, 0x02, 0xD0, 0x60, 0x58, 0x4F,
0xFC, 0x78, 0xFF, 0xFF, 0x32, 0x40, 0x02, 0x2A, 0x05, 0x00, 0x63, 0x46, 0x02, 0x64, 0x06, 0xFA,
0x26, 0x46, 0x34, 0x00, 0x32, 0x40, 0x08, 0x2A, 0x05, 0x00, 0x63, 0x46, 0x80, 0x60, 0x02, 0x64,
0x06, 0xFA, 0x26, 0x46, 0x43, 0x43, 0x7D, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x27, 0x09, 0x00,
0x19, 0x60, 0x44, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x2A, 0x03, 0x00, 0x23, 0x46, 0x0F, 0x64,
0x10, 0x00, 0x37, 0x60, 0xF8, 0x61, 0xA1, 0xD1, 0xA1, 0xF3, 0x01, 0x60, 0xAC, 0x63, 0x60, 0x45,
0xA3, 0xD3, 0x65, 0x40, 0x01, 0x27, 0x5B, 0xD3, 0x65, 0x40, 0x01, 0x27, 0x59, 0xD1, 0x23, 0x46,
0xA0, 0x84, 0x0F, 0xFA, 0x7A, 0xFB, 0x79, 0xFB, 0x16, 0x64, 0x12, 0xFA, 0x01, 0x64, 0x11, 0xFA,
0x66, 0x5C, 0xC2, 0x60, 0x58, 0x4E, 0x6D, 0x78, 0xFF, 0xFF, 0x26, 0x46, 0x07, 0xFC, 0x43, 0x43,
0x2A, 0xF2, 0x63, 0x45, 0x0C, 0xB4, 0x08, 0x3A, 0x0A, 0x00, 0xDB, 0xF3, 0x23, 0x46, 0x07, 0xB4,
0xFD, 0xA0, 0x06, 0xF2, 0x26, 0x46, 0x03, 0x03, 0x60, 0x40, 0x02, 0x2A, 0x0D, 0x00, 0x2A, 0xF2,
0x35, 0xF0, 0x60, 0x40, 0xA4, 0x36, 0x0B, 0x00, 0x08, 0x2B, 0x0C, 0x00, 0x23, 0x46, 0x26, 0xF2,
0x26, 0x46, 0xD0, 0x80, 0xFF, 0xFF, 0x06, 0x02, 0xD0, 0x60, 0xB5, 0x78, 0xFF, 0xFF, 0xD0, 0x60,
0x6B, 0x78, 0xFF, 0xFF, 0x23, 0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0x31, 0xF0,
0x39, 0x18, 0x66, 0x41, 0x1D, 0x60, 0xC0, 0x65, 0x64, 0x47, 0x00, 0x7F, 0xA6, 0xF1, 0xE0, 0x84,
0x44, 0xD3, 0x64, 0x43, 0x11, 0x18, 0x60, 0x46, 0x00, 0xF2, 0xFF, 0xFF, 0xFC, 0x1B, 0x66, 0x44,
0x64, 0x46, 0x80, 0xF0, 0x60, 0x46, 0x80, 0xF8, 0x65, 0x46, 0x65, 0x43, 0x80, 0xF0, 0x01, 0xFA,
0x80, 0xFC, 0x64, 0x46, 0x80, 0xF8, 0x0B, 0x00, 0x64, 0x46, 0x62, 0x43, 0x00, 0xF2, 0xA3, 0xDB,
0x60, 0x46, 0x80, 0xF0, 0x81, 0xFC, 0x80, 0xFC, 0x64, 0x46, 0x80, 0xF8, 0x60, 0x43, 0x61, 0x46,
0x1F, 0x60, 0xC2, 0x61, 0xA1, 0xD3, 0x20, 0x60, 0x04, 0x7C, 0xD0, 0x80, 0xFF, 0xFF, 0x07, 0x03,
0xA0, 0xDD, 0xDA, 0x9C, 0xA1, 0xD9, 0x49, 0xD3, 0xFF, 0xFF, 0xDC, 0x84, 0xA1, 0xDB, 0xD1, 0x60,
0x97, 0x78, 0xFF, 0xFF, 0x20, 0x7C, 0x72, 0x44, 0xFF, 0xB4, 0xD0, 0x80, 0xFF, 0xFF, 0x02, 0x04,
0xD0, 0x84, 0xFB, 0x01, 0xE0, 0x83, 0xA6, 0xF3, 0x02, 0xA3, 0x43, 0x93, 0xA6, 0xF3, 0xFF, 0xFF,
0x02, 0xA5, 0xD7, 0x80, 0x04, 0xA5, 0x08, 0x24, 0x65, 0x43, 0x66, 0x41, 0x63, 0x46, 0x05, 0xF2,
0x00, 0xF0, 0x81, 0xF0, 0x02, 0x18, 0x64, 0x46, 0x81, 0xF8, 0x07, 0x1B, 0x1D, 0x60, 0xC0, 0x65,
0x60, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD9, 0x02, 0x00, 0x65, 0x46, 0x00, 0xF8, 0xA6, 0xF3,
0x63, 0x45, 0x60, 0x46, 0x00, 0xF2, 0xFF, 0xFF, 0xD4, 0x80, 0x01, 0x18, 0xFA, 0x04, 0x80, 0xF8,
0x65, 0x46, 0x00, 0xFA, 0x06, 0xF2, 0xFF, 0xFF, 0x00, 0x7E, 0x06, 0xFA, 0x61, 0x46, 0x31, 0xF0,
0x66, 0x41, 0x1D, 0x60, 0xC0, 0x65, 0x64, 0x47, 0x00, 0x7F, 0xA6, 0xF1, 0xE0, 0x84, 0x44, 0xD3,
0x64, 0x43, 0x11, 0x18, 0x60, 0x46, 0x00, 0xF2, 0xFF, 0xFF, 0xFC, 0x1B, 0x66, 0x44, 0x64, 0x46,
0x80, 0xF0, 0x60, 0x46, 0x80, 0xF8, 0x65, 0x46, 0x65, 0x43, 0x80, 0xF0, 0x01, 0xFA, 0x80, 0xFC,
0x64, 0x46, 0x80, 0xF8, 0x0B, 0x00, 0x64, 0x46, 0x62, 0x43, 0x00, 0xF2, 0xA3, 0xDB, 0x60, 0x46,
0x80, 0xF0, 0x81, 0xFC, 0x80, 0xFC, 0x64, 0x46, 0x80, 0xF8, 0x60, 0x43, 0x61, 0x46, 0x2F, 0xF2,
0x30, 0xF0, 0x31, 0xF0, 0x64, 0x45, 0x46, 0x43, 0x63, 0x46, 0x03, 0xFA, 0x06, 0xF2, 0x84, 0xF8,
0x00, 0x7E, 0x06, 0xFA, 0x05, 0xF8, 0xA3, 0x46, 0x2F, 0x58, 0xFF, 0xFF, 0xDB, 0xF3, 0x2A, 0xF2,
0x07, 0xB0, 0x03, 0x3A, 0x2A, 0x00, 0x00, 0xF4, 0x09, 0xF2, 0x60, 0x45, 0x80, 0x3A, 0x05, 0x00,
0x0E, 0xF2, 0xFF, 0xFF, 0x02, 0xB0, 0x0F, 0xF2, 0x20, 0x03, 0x60, 0x47, 0x00, 0x3A, 0x1D, 0x00,
0x60, 0x41, 0x00, 0x36, 0x13, 0x00, 0xDA, 0x85, 0x33, 0x60, 0xBE, 0x63, 0xBD, 0xD1, 0xFF, 0xFF,
0xD1, 0x80, 0xFF, 0xFF, 0x12, 0x02, 0x60, 0xFE, 0xBD, 0xD3, 0xA5, 0xD0, 0xDE, 0x85, 0xD0, 0x80,
0xCD, 0x81, 0x0B, 0x02, 0xF9, 0x02, 0x20, 0xFE, 0x00, 0x64, 0x09, 0x00, 0x26, 0x46, 0x48, 0xFE,
0x65, 0x40, 0x40, 0x3A, 0x02, 0x00, 0x01, 0x64, 0x02, 0x00, 0x28, 0xFE, 0x00, 0x64, 0x40, 0x48,
0x26, 0x46, 0x2D, 0x58, 0xFF, 0xFF, 0x19, 0x60, 0xA3, 0xF3, 0x3D, 0xF2, 0x60, 0x40, 0x01, 0x26,
0x2A, 0xFA, 0x2A, 0xF2, 0xFF, 0xFF, 0x60, 0x40, 0x08, 0x26, 0x03, 0x00, 0xD2, 0x60, 0xB5, 0x78,
0xFF, 0xFF, 0x3F, 0xF0, 0x32, 0x40, 0x10, 0x2A, 0x0E, 0x00, 0x2C, 0xF0, 0x64, 0x41, 0x60, 0x40,
0x40, 0x27, 0x09, 0x00, 0xCD, 0x81, 0xDD, 0x81, 0x06, 0x03, 0x05, 0x03, 0x64, 0x40, 0x01, 0x26,
0x02, 0x00, 0x01, 0x61, 0x01, 0x00, 0x00, 0x61, 0x60, 0x40, 0x18, 0x36, 0x1F, 0x00, 0xD0, 0x60,
0x58, 0x4F, 0xD1, 0x78, 0xFF, 0xFF, 0x0F, 0xF0, 0xEA, 0xF1, 0x64, 0x44, 0x60, 0x22, 0x19, 0x00,
0xDB, 0xF3, 0xFF, 0xFF, 0x07, 0xB4, 0xFD, 0xA0, 0x2A, 0xF2, 0x03, 0x02, 0x08, 0xB0, 0xFF, 0xFF,
0x10, 0x02, 0x32, 0xF2, 0x33, 0xF2, 0xD0, 0x80, 0xEB, 0xF1, 0x0B, 0x02, 0xD0, 0x80, 0x34, 0xF2,
0x08, 0x02, 0xEC, 0xF1, 0xFF, 0xFF, 0xD0, 0x80, 0x0F, 0xF0, 0x03, 0x02, 0xD3, 0x60, 0x10, 0x78,
0xFF, 0xFF, 0x00, 0xF4, 0xAA, 0x60, 0xAA, 0x65, 0x09, 0xF2, 0x5A, 0xD0, 0xD4, 0x80, 0x03, 0x64,
0x57, 0x02, 0xD0, 0x80, 0x00, 0x64, 0x5A, 0xD0, 0x53, 0x02, 0x64, 0x45, 0xD4, 0x80, 0xF8, 0x7F,
0x08, 0x02, 0x5A, 0xD0, 0x26, 0x46, 0x64, 0x45, 0x23, 0xF0, 0x20, 0x67, 0xB0, 0x84, 0xA2, 0xDA,
0x0B, 0x00, 0xD4, 0x80, 0x1D, 0x60, 0x60, 0x64, 0x16, 0x02, 0x5A, 0xD0, 0x26, 0x46, 0x64, 0x45,
0x23, 0xF0, 0x40, 0x67, 0xB0, 0x84, 0xA2, 0xDA, 0x65, 0x44, 0x88, 0x3A, 0x07, 0x00, 0x77, 0x37,
0x08, 0x00, 0x78, 0x37, 0x06, 0x00, 0x8E, 0x37, 0x04, 0x00, 0x32, 0x00, 0x81, 0x3A, 0x30, 0x00,
0x80, 0x37, 0x00, 0x61, 0x2D, 0x00, 0xD4, 0x80, 0x01, 0x60, 0x00, 0x64, 0x5A, 0xD0, 0x28, 0x02,
0xD0, 0x80, 0x5A, 0xD0, 0x25, 0x02, 0x26, 0x46, 0x64, 0x47, 0x7F, 0xB4, 0xFD, 0xA0, 0x09, 0x03,
0x1F, 0x07, 0x32, 0x40, 0x02, 0x26, 0x44, 0x00, 0x23, 0xF0, 0x60, 0x67, 0xB0, 0x84, 0xA2, 0xDA,
0x3F, 0x00, 0x0F, 0xF2, 0x32, 0x40, 0x02, 0x26, 0x3B, 0x00, 0x2A, 0xF2, 0xFF, 0xFF, 0x60, 0x40,
0x08, 0x2A, 0x07, 0x00, 0x60, 0x40, 0x48, 0x36, 0x04, 0x00, 0xF1, 0xF3, 0xFF, 0xFF, 0x02, 0xBC,
0xF1, 0xFB, 0xF4, 0x60, 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,
0x05, 0x00, 0xF8, 0x60, 0x58, 0x4F, 0xE1, 0x78, 0xFF, 0xFF, 0x2E, 0x00, 0x40, 0x3A, 0x05, 0x00,
0xF0, 0x60, 0x58, 0x4F, 0x99, 0x78, 0xFF, 0xFF, 0x27, 0x00, 0x80, 0x3A, 0x24, 0x00, 0x7F, 0xF1,
0x32, 0xF2, 0x33, 0xF2, 0xD0, 0x80, 0x80, 0xF1, 0x23, 0x02, 0xD0, 0x80, 0x34, 0xF2, 0x81, 0xF1,
0x1F, 0x02, 0xD0, 0x80, 0xFF, 0xFF, 0x1C, 0x02, 0xE9, 0x60, 0x58, 0x4F, 0x30, 0x78, 0xFF, 0xFF,
0x7D, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x27, 0x0A, 0x00, 0x19, 0x60, 0x4C, 0xF3, 0xFF, 0xFF,
0x60, 0x40, 0x08, 0x26, 0x04, 0x00, 0xEE, 0x60, 0x58, 0x4F, 0x81, 0x78, 0xFF, 0xFF, 0x24, 0x60,
0x58, 0x4F, 0xE3, 0x78, 0xFF, 0xFF, 0x04, 0x00, 0x66, 0x44, 0x00, 0xA8, 0xFF, 0xFF, 0x0A, 0x03,
0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF,
0x00, 0x66, 0x46, 0x46, 0xD0, 0x60, 0xB2, 0x78, 0xFF, 0xFF, 0x2A, 0xF2, 0x3B, 0xF0, 0x60, 0x40,
0x40, 0x2B, 0x06, 0x00, 0xC0, 0x60, 0x00, 0x64, 0x64, 0x40, 0x20, 0x2B, 0x01, 0x00, 0x03, 0x00,
0xD3, 0x60, 0x4C, 0x78, 0xFF, 0xFF, 0x22, 0xF2, 0xFF, 0xFF, 0x04, 0xB4, 0xFF, 0xFF, 0xF8, 0x03,
0x23, 0xF2, 0x07, 0xF4, 0xBB, 0xF0, 0x26, 0x46, 0xA4, 0x84, 0xFF, 0xFF, 0x60, 0x40, 0x2F, 0x26,
0xD7, 0x01, 0x12, 0xF0, 0xFF, 0xFF, 0x10, 0x1B, 0xCA, 0x60, 0x58, 0x4F, 0x16, 0x78, 0xFF, 0xFF,
0x64, 0x40, 0x18, 0x36, 0x09, 0x00, 0x04, 0x65, 0xF1, 0x60, 0x58, 0x4E, 0x96, 0x78, 0xFF, 0xFF,
0x26, 0x46, 0xD3, 0x60, 0x10, 0x78, 0xFF, 0xFF, 0x25, 0x60, 0xFE, 0x64, 0x13, 0x60, 0x0D, 0xFB,
0x26, 0x44, 0x5A, 0xDB, 0x02, 0x64, 0x5A, 0xDB, 0xFF, 0xFF, 0x2B, 0xFF, 0xF8, 0xFE, 0xC0, 0x01,
0x1C, 0x60, 0x92, 0x63, 0x00, 0x64, 0xA3, 0xDB, 0x06, 0xA3, 0x10, 0x60, 0x94, 0x64, 0xBD, 0xDB,
0xBD, 0xDB, 0x06, 0x64, 0xA3, 0xDB, 0x00, 0x63, 0x08, 0x60, 0x77, 0xFD, 0xD9, 0x60, 0xA5, 0x64,
0x08, 0x60, 0x49, 0xFB, 0xD9, 0x60, 0x6A, 0x64, 0x08, 0x60, 0x35, 0xFB, 0x00, 0x60, 0x02, 0x64,
0x08, 0x60, 0x16, 0xFB, 0xD3, 0x60, 0x9C, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF,
0x7D, 0xF3, 0x33, 0x60, 0x20, 0x63, 0x60, 0x40, 0x01, 0x27, 0x03, 0x00, 0x19, 0x60, 0x3B, 0xF3,
0x02, 0x00, 0x19, 0x60, 0x3C, 0xF3, 0x08, 0x61, 0x60, 0xFE, 0xA3, 0xD1, 0xFF, 0xFF, 0x20, 0xFE,
0x00, 0xA8, 0xE8, 0x84, 0x0F, 0x03, 0x60, 0xFE, 0x02, 0x28, 0xF6, 0x01, 0x80, 0x62, 0xB2, 0x9C,
0xBD, 0xD9, 0x7B, 0xF9, 0xCD, 0x81, 0x00, 0x36,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 0x60,
0x00, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xD4, 0x60, 0x59, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58,
0xFF, 0xFF, 0xFD, 0x60, 0x89, 0x65, 0xF3, 0x60, 0x58, 0x4E, 0x27, 0x78, 0xFF, 0xFF, 0x10, 0x60,
0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x00, 0x64, 0x08, 0x60, 0x15, 0xFB, 0x5A, 0xDB, 0x10, 0x60,
0x4E, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0xF7, 0x60, 0xFF, 0x65, 0x20, 0x44, 0x24, 0x80, 0x08, 0x60,
0x08, 0xF1, 0x80, 0x60, 0x00, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0xBB, 0xFE, 0xFD, 0x60,
0x40, 0x65, 0xF3, 0x60, 0x58, 0x4E, 0x27, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x03, 0x64, 0x08, 0x60,
0x28, 0xFB, 0xD4, 0x60, 0x87, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60,
0x27, 0xF1, 0x00, 0x60, 0x02, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x07, 0x03, 0xA0, 0x84, 0xA2, 0xDB,
0x10, 0x60, 0x4E, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0xE2, 0x01, 0x10, 0x60, 0x4E, 0x62, 0x00, 0x64,
0xA2, 0xDB, 0x00, 0x64, 0x08, 0x60, 0x27, 0xFB, 0x5A, 0xDB, 0x20, 0x40, 0x04, 0x2B, 0x14, 0x00,
0x9B, 0xFE, 0x08, 0x04, 0xBB, 0xFE, 0x08, 0x60, 0x08, 0xF1, 0x80, 0x60, 0x00, 0x64, 0xB0, 0x84,
0xA2, 0xDB, 0xCF, 0xFE, 0x80, 0x60, 0x00, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xD4, 0x60, 0x95, 0x64,
0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60, 0x00, 0x65, 0x20, 0x44, 0x34, 0x80,
0x16, 0x60, 0xCC, 0xF3, 0x00, 0x61, 0x60, 0x40, 0x00, 0x36, 0x00, 0xB9, 0x60, 0x40, 0x01, 0x36,
0x01, 0xB9, 0x60, 0x40, 0x02, 0x36, 0x06, 0xB9, 0x60, 0x40, 0x03, 0x36, 0x07, 0xB9, 0x41, 0x44,
0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0xDE, 0xFE, 0x0A, 0x04, 0x40, 0x60, 0x00, 0x64,
0x08, 0x60, 0x16, 0xFB, 0xD4, 0x60, 0xC8, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF,
0x7D, 0xF1, 0x13, 0x60, 0x1A, 0xF9, 0x0C, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x2D, 0xFF, 0x20, 0x60,
0x00, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xD4, 0x60, 0xE9, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58,
0xFF, 0xFF, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0xBE, 0xFE, 0x08, 0x60, 0x08, 0xF1,
0x40, 0x60, 0x00, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x75, 0x00, 0x10, 0x60, 0x2A, 0x62,
0x00, 0x64, 0xA2, 0xDB, 0xBA, 0xFE, 0x02, 0x64, 0xDB, 0xFB, 0xF1, 0xF3, 0xFF, 0xFF, 0x01, 0xBC,
0xF1, 0xFB, 0x44, 0x60, 0x44, 0x64, 0x7F, 0xFB, 0x80, 0xFB, 0x81, 0xFB, 0xFF, 0xFF, 0x20, 0x40,
0x04, 0x2B, 0x14, 0x00, 0x9B, 0xFE, 0x08, 0x04, 0xBB, 0xFE, 0x08, 0x60, 0x08, 0xF1, 0x80, 0x60,
0x00, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x80, 0x60, 0x00, 0x64, 0x08, 0x60, 0x16, 0xFB,
0xD5, 0x60, 0x07, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60, 0x00, 0x65,
0x20, 0x44, 0x34, 0x80, 0x08, 0x60, 0x07, 0xF1, 0x02, 0x60, 0x00, 0x65, 0x20, 0x44, 0x34, 0x80,
0x64, 0x40, 0x01, 0x2A, 0x06, 0x00, 0xA2, 0xDF, 0x02, 0x65, 0xF1, 0x60, 0x58, 0x4E, 0xC3, 0x78,
0xFF, 0xFF, 0xCF, 0xF3, 0x20, 0x60, 0x20, 0x65, 0x36, 0x1B, 0xA5, 0xD3, 0x24, 0x40, 0x01, 0x26,
0x16, 0x00, 0x60, 0x40, 0x20, 0x26, 0x2F, 0x00, 0x01, 0xBC, 0xA5, 0xDB, 0x08, 0x60, 0x1E, 0xF1,
0x00, 0x60, 0x20, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x10, 0x60, 0x00, 0x64, 0x08, 0x60,
0x16, 0xFB, 0xD5, 0x60, 0x65, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x60, 0x40,
0x10, 0x26, 0x19, 0x00, 0x01, 0xBC, 0xA5, 0xDB, 0x08, 0x60, 0x1E, 0xF1, 0x00, 0x60, 0x40, 0x64,
0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x10, 0x60, 0x00, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xD5, 0x60,
0x65, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0xFD, 0x60, 0x89, 0x65, 0xF3, 0x60,
0x58, 0x4E, 0x27, 0x78, 0xFF, 0xFF, 0xCF, 0xF1, 0x07, 0x60, 0xE9, 0xF3, 0x64, 0x40, 0x02, 0x3A,
0x0C, 0x00, 0x01, 0x63, 0x60, 0x40, 0x10, 0x22, 0x00, 0x63, 0x08, 0x60, 0xC1, 0xFD, 0x08, 0x60,
0xC5, 0xFD, 0x08, 0x60, 0xC9, 0xFD, 0x08, 0x60, 0xCD, 0xFD, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64,
0xA2, 0xDB, 0x01, 0x64, 0x53, 0xFB, 0x2F, 0x60, 0x02, 0x64, 0x54, 0xFB, 0x24, 0x40, 0x01, 0x26,
0x11, 0x00, 0x08, 0x60, 0x12, 0xF1, 0x00, 0x60, 0x10, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE,
0x10, 0x60, 0x00, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xD5, 0x60, 0xAB, 0x64, 0x5A, 0xDB, 0xCF, 0xFE,
0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60, 0x12, 0xF1, 0x00, 0x60, 0x20, 0x64, 0xB0, 0x84, 0xA2, 0xDB,
0xCF, 0xFE, 0x10, 0x60, 0x00, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xD5, 0x60, 0xAB, 0x64, 0x5A, 0xDB,
0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0xFD, 0x60, 0xFF, 0x65, 0x20, 0x44, 0x24, 0x80, 0x08, 0x60,
0x08, 0xF1, 0x80, 0x60, 0x00, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x10, 0x60, 0x2A, 0x62,
0x00, 0x64, 0xA2, 0xDB, 0x86, 0xF1, 0x1B, 0x60, 0xB2, 0x63, 0xD3, 0x80, 0x20, 0x44, 0x03, 0x03,
0xD8, 0x60, 0xD0, 0x78, 0xFF, 0xFF, 0x87, 0xF3, 0xFF, 0xFF, 0xD0, 0x80, 0xFF, 0xFF, 0x1B, 0x02,
0x24, 0x44, 0x04, 0x22, 0x12, 0x00, 0x24, 0x44, 0x01, 0xAC, 0xFB, 0xB4, 0x40, 0x44, 0xF7, 0x60,
0xFF, 0x65, 0x20, 0x44, 0x24, 0x80, 0x08, 0x60, 0x08, 0xF1, 0x80, 0x60, 0x00, 0x64, 0xB0, 0x84,
0xA2, 0xDB, 0xCF, 0xFE, 0xD4, 0x60, 0xF6, 0x78, 0xFF, 0xFF, 0xD2, 0xF3, 0xFF, 0xFF, 0x00, 0xA8,
0xFF, 0xFF, 0x1F, 0x02, 0x87, 0x00, 0x20, 0x44, 0x10, 0xBC, 0x40, 0x40, 0x64, 0x42, 0x5A, 0xD1,
0x06, 0x63, 0xA4, 0xD1, 0xC3, 0x83, 0x7D, 0xF9, 0xBD, 0xD1, 0x7F, 0xF9, 0xBD, 0xD1, 0xFF, 0xFF,
0x80, 0xF9, 0xBD, 0xD1, 0x81, 0xF9, 0x04, 0xA3, 0xBD, 0xD1, 0x33, 0x60, 0xBE, 0x64, 0x64, 0x41,
0xDD, 0x81, 0xFE, 0xB1, 0xA0, 0xD9, 0x04, 0x03, 0xBD, 0xD1, 0xC9, 0x81, 0x58, 0xD9, 0xFC, 0x02,
0x39, 0x00, 0xE4, 0xF3, 0x7D, 0xFB, 0x66, 0x41, 0x60, 0x40, 0x01, 0x27, 0x06, 0x00, 0x10, 0x60,
0xF0, 0x63, 0x11, 0x60, 0x44, 0x65, 0x06, 0x66, 0x05, 0x00, 0x11, 0x60, 0x60, 0x63, 0x12, 0x60,
0x40, 0x65, 0x08, 0x66, 0xA3, 0xD1, 0x4B, 0x93, 0xD0, 0x80, 0xD7, 0x80, 0x02, 0x03, 0xFA, 0x04,
0x04, 0x00, 0x5B, 0x93, 0x02, 0xA3, 0x01, 0x64, 0xA3, 0xDB, 0x61, 0x46, 0x2F, 0x60, 0x02, 0x61,
0xA1, 0xD3, 0xFF, 0xFF, 0x00, 0xA8, 0x33, 0x60, 0xBE, 0x63, 0x02, 0x02, 0x2D, 0x60, 0x10, 0x61,
0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0x03, 0x00, 0x01, 0xAC, 0x04, 0xBC,
0x40, 0x44, 0x32, 0x40, 0x80, 0x2A, 0x8C, 0x00, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB,
0xDE, 0xFE, 0x0A, 0x04, 0x40, 0x60, 0x00, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xD6, 0x60, 0x8C, 0x64,
0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB,
0x95, 0xF3, 0xFF, 0xFF, 0x7F, 0xB4, 0x95, 0xFB, 0x26, 0x60, 0x34, 0x62, 0x06, 0x64, 0x4A, 0xDB,
0xFF, 0xFF, 0x2D, 0xFF, 0xFF, 0xFF, 0xBE, 0xFE, 0x08, 0x60, 0x08, 0xF1, 0x40, 0x60, 0x00, 0x64,
0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0xDA, 0xFE, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB,
0x12, 0x60, 0xFF, 0xF3, 0xFF, 0xFF, 0x00, 0xA8, 0x60, 0x46, 0x05, 0x03, 0x0E, 0xF2, 0xFF, 0xFF,
0x60, 0x40, 0x01, 0x2A, 0x22, 0x00, 0x13, 0x60, 0x02, 0xF3, 0xFF, 0xFF, 0x00, 0xA8, 0x60, 0x46,
0x03, 0x03, 0x0F, 0xF2, 0xFF, 0xFF, 0x19, 0x1B, 0x08, 0x60, 0x00, 0x64, 0x08, 0x60, 0x16, 0xFB,
0xD6, 0x60, 0xE5, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x01, 0x64, 0x19, 0x60, 0xF1, 0xFB, 0x19, 0x60,
0xF6, 0xF1, 0xFF, 0xFF, 0x64, 0x40, 0x01, 0x26, 0x05, 0x00, 0x89, 0xFF, 0x08, 0x60, 0x00, 0x75,
0x88, 0xFF, 0x01, 0x00, 0x10, 0xFF,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
0xE8, 0x64, 0xD4, 0x80, 0xFF, 0xFF, 0x01, 0x04, 0x65, 0x44, 0xA1, 0xDB, 0x32, 0x40, 0x80, 0x2A,
0x03, 0x00, 0xD4, 0x60, 0xF6, 0x78, 0xFF, 0xFF, 0x2F, 0x58, 0xFF, 0xFF, 0x00, 0x64, 0x08, 0x60,
0x27, 0xFB, 0x5A, 0xDB, 0xD4, 0x60, 0xF6, 0x78, 0xFF, 0xFF, 0x20, 0x40, 0x06, 0x23, 0x10, 0x00,
0x08, 0x60, 0x27, 0xF1, 0x7F, 0x60, 0xFF, 0x64, 0xA0, 0x84, 0xA2, 0xDB, 0x80, 0x60, 0x00, 0x64,
0x08, 0x60, 0x28, 0xFB, 0xD7, 0x60, 0x55, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF,
0x10, 0x60, 0x4E, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x00, 0x64, 0x08, 0x60, 0x27, 0xFB, 0x5A, 0xDB,
0x1C, 0x60, 0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF,
0xD3, 0x60, 0xD0, 0x78, 0xFF, 0xFF, 0x78, 0xF3, 0x79, 0xFB, 0x20, 0x60, 0x14, 0x62, 0xA2, 0xDF,
0xFF, 0x60, 0xDF, 0x65, 0x20, 0x44, 0x24, 0x80, 0xBC, 0xF1, 0x0E, 0x60, 0x4B, 0xF9, 0x1C, 0x60,
0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x02, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0xF7, 0x60,
0xFF, 0x65, 0x20, 0x44, 0x24, 0x80, 0x10, 0x26, 0x38, 0x00, 0x00, 0x64, 0xB2, 0xFB, 0xB3, 0xFB,
0xB4, 0xFB, 0x00, 0x75, 0x00, 0x72, 0xBA, 0xF1, 0x7E, 0xF9, 0x64, 0x44, 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x08, 0x00, 0x91, 0xFA, 0x61, 0x44, 0xFD, 0x60, 0x58, 0x4E,
0xAC, 0x78, 0xFF, 0xFF, 0x12, 0xFA, 0x07, 0x00, 0x11, 0xF8, 0x64, 0x44, 0xFD, 0x60, 0x58, 0x4E,
0xAC, 0x78, 0xFF, 0xFF, 0x12, 0xFA, 0x65, 0x46, 0x04, 0x00, 0xBB, 0xFE, 0xD4, 0x60, 0xF6, 0x78,
0xFF, 0xFF, 0x16, 0x60, 0xC2, 0xF1, 0x00, 0x65, 0x64, 0x40, 0x01, 0x36, 0x22, 0x65, 0x64, 0x40,
0x07, 0x36, 0x01, 0x65, 0x64, 0x40, 0x0A, 0x36, 0x01, 0x65, 0x64, 0x40, 0x0B, 0x36, 0x22, 0x65,
0xA6, 0xF3, 0x66, 0x5C, 0x60, 0x46, 0x1F, 0x63, 0xE3, 0x83, 0xBA, 0xF8, 0x02, 0xA6, 0x66, 0x44,
0xFC, 0x1F, 0x16, 0x60, 0xC2, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x07, 0x36, 0x03, 0x00, 0x0A, 0x36,
0x06, 0x00, 0x09, 0x00, 0xA6, 0xF3, 0x04, 0x65, 0x60, 0x46, 0xBA, 0xF8, 0x04, 0x00, 0xA6, 0xF3,
0x10, 0x65, 0x60, 0x46, 0xBA, 0xF8, 0x64, 0x46, 0xA6, 0xF3, 0x32, 0x41, 0x60, 0x45, 0x08, 0xB1,
0x66, 0x41, 0x16, 0x03, 0x65, 0x46, 0x17, 0x60, 0x80, 0xF3, 0x06, 0xF0, 0xE0, 0x84, 0xE0, 0x84,
0xE0, 0x84, 0xE0, 0x84, 0x80, 0xBF, 0xB0, 0x84, 0x06, 0xFA, 0x66, 0x43, 0x02, 0xA3, 0x63, 0x46,
0x06, 0xF0, 0xFF, 0xFF, 0xB0, 0x84, 0x06, 0xFA, 0x61, 0x46, 0x32, 0x44, 0x10, 0xBC, 0x40, 0x52,
0x01, 0x64, 0x10, 0x60, 0x0A, 0xFB, 0x0F, 0x4E, 0xEF, 0x60, 0x58, 0x4F, 0x3A, 0x78, 0xFF, 0xFF,
0x0E, 0x4F, 0x08, 0x60, 0x15, 0xF1, 0xFF, 0x60, 0xFB, 0x64, 0xA0, 0x84, 0xA2, 0xDB, 0x00, 0x60,
0x04, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xD3, 0x60, 0xAE, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x1C, 0x60,
0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x02, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0xBB, 0xFE,
0x20, 0x44, 0x04, 0x27, 0x11, 0x00, 0x10, 0x26, 0x02, 0x00, 0xDB, 0xFE, 0x14, 0x00, 0x08, 0x60,
0x07, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x36, 0x07, 0x00, 0x01, 0x64, 0xA2, 0xDB, 0x01, 0x65,
0xF1, 0x60, 0x58, 0x4E, 0xC3, 0x78, 0xFF, 0xFF, 0x08, 0x60, 0x08, 0xF1, 0x80, 0x60, 0x00, 0x64,
0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x01, 0x64, 0x8A, 0xFB, 0xFF, 0x60, 0xEF, 0x65, 0x20, 0x44,
0x24, 0x80, 0x03, 0x64, 0xDB, 0xFB, 0xF1, 0xF3, 0xFF, 0xFF, 0xFE, 0xB4, 0xF1, 0xFB, 0xC1, 0xFE,
0x00, 0x60, 0x02, 0x64, 0x08, 0x60, 0x28, 0xFB, 0xD8, 0x60, 0xAA, 0x64, 0x5A, 0xDB, 0xCF, 0xFE,
0x2F, 0x58, 0xFF, 0xFF, 0x20, 0x40, 0x06, 0x23, 0x10, 0x00, 0x08, 0x60, 0x27, 0xF1, 0x7F, 0x60,
0xFF, 0x64, 0xA0, 0x84, 0xA2, 0xDB, 0x80, 0x60, 0x00, 0x64, 0x08, 0x60, 0x28, 0xFB, 0xD8, 0x60,
0xAA, 0x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0xBD, 0xD1, 0x2C, 0xF8, 0x32, 0xF8, 0xBD, 0xD1, 0x2D, 0xF8, 0x33, 0xF8, 0xA3, 0xD1,
0x2E, 0xF8, 0x34, 0xF8, 0x06, 0x63, 0x3F, 0xFC, 0x20, 0x60, 0x16, 0x61, 0xDB, 0xF3, 0xA1, 0xD3,
0x03, 0xA8, 0xAC, 0x83, 0x0E, 0x02, 0x0D, 0x03, 0x20, 0x60, 0x18, 0x61, 0xA1, 0xD1, 0x66, 0x45,
0x00, 0xF4, 0x09, 0xFC, 0x01, 0x64, 0x0A, 0xFA, 0x0B, 0xF8, 0x20, 0x60, 0x16, 0x61, 0xA1, 0xDF,
0x25, 0x00, 0x16, 0x60, 0xC3, 0xF3, 0x66, 0x45, 0x00, 0xF4, 0x60, 0x40, 0x01, 0x36, 0x15, 0x00,
0x02, 0x36, 0xBD, 0x00, 0x03, 0x36, 0x07, 0x00, 0x04, 0x36, 0x0F, 0x00, 0x05, 0x36, 0xB7, 0x00,
0x06, 0x36, 0x01, 0x00, 0x0A, 0x00, 0x80, 0x64, 0x09, 0xFA, 0x01, 0x63, 0x0A, 0xFC, 0x00, 0x64,
0x0B, 0xFA, 0x80, 0x60, 0xF4, 0x62, 0xA2, 0xDF, 0x09, 0x00, 0x00, 0x64, 0x09, 0xFA, 0x01, 0x63,
0x0A, 0xFC, 0x00, 0x64, 0x0B, 0xFA, 0x80, 0x60, 0xF4, 0x62, 0xA2, 0xDF, 0x25, 0x60, 0xCE, 0x64,
0x13, 0x60, 0x0D, 0xFB, 0x65, 0x44, 0x5A, 0xDB, 0x02, 0x64, 0x5A, 0xDB, 0xFF, 0xFF, 0x2B, 0xFF,
0x00, 0x66, 0xDB, 0xF3, 0x46, 0x46, 0xFD, 0xA0, 0xC1, 0xFE, 0x02, 0x02, 0x2F, 0x58, 0xFF, 0xFF,
0x01, 0x64, 0x68, 0xFB, 0x43, 0x64, 0x3B, 0x42, 0x5A, 0xDB, 0x0E, 0x60, 0x38, 0xF3, 0xFF, 0xFF,
0x64, 0xA4, 0xA2, 0xDB, 0x0E, 0x60, 0x38, 0xF1, 0x0E, 0x60, 0x4B, 0xF9, 0x1C, 0x60, 0x92, 0x64,
0x13, 0x60, 0x22, 0xFB, 0x02, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x00, 0x60, 0x0C, 0x64,
0x08, 0x60, 0x16, 0xFB, 0xDB, 0x60, 0x00, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF,
0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x08, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x55, 0x03, 0xA0, 0x84,
0xA2, 0xDB, 0x1C, 0x60, 0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF,
0x04, 0xFF, 0x00, 0x64, 0x68, 0xFB, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x26, 0x46,
0x00, 0xF4, 0x09, 0xF2, 0x0A, 0xF2, 0x00, 0xA8, 0x0B, 0xF2, 0x02, 0xA8, 0x16, 0x02, 0x00, 0xA8,
0x1A, 0x02, 0x19, 0x02, 0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D,
0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66, 0x46, 0x46, 0x20, 0x40, 0x08, 0x2A, 0x03, 0x00, 0xDC, 0x60,
0xF6, 0x78, 0xFF, 0xFF, 0xE3, 0x60, 0x69, 0x78, 0xFF, 0xFF, 0x09, 0xF2, 0x0A, 0xF2, 0x80, 0xA8,
0x0B, 0xF2, 0x02, 0xA8, 0xE4, 0x03, 0x44, 0x64, 0x3B, 0x42, 0x5A, 0xDB, 0x0B, 0xF2, 0x26, 0x46,
0x40, 0x59, 0x02, 0x60, 0x00, 0x61, 0x2F, 0xF2, 0xA1, 0xDB, 0x30, 0xF2, 0x41, 0x58, 0x59, 0xDB,
0x31, 0xF2, 0x59, 0xDB, 0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D,
0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66, 0x46, 0x46, 0x03, 0x65, 0xF1, 0x60, 0x58, 0x4E, 0x96, 0x78,
0xFF, 0xFF, 0xE7, 0x60, 0x0B, 0x78, 0xFF, 0xFF, 0xFF, 0x60, 0xFB, 0x64, 0xA0, 0x84, 0xA2, 0xDB,
0x00, 0x64, 0x68, 0xFB, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x20, 0x40, 0x08, 0x2A,
0x03, 0x00, 0xD9, 0x60, 0xCA, 0x78, 0xFF, 0xFF, 0xE2, 0x60, 0x73, 0x78, 0xFF, 0xFF, 0x01, 0x63,
0x09, 0xFC, 0x32, 0x40, 0x08, 0x26, 0x14, 0x00, 0x16, 0x60, 0xC2, 0xF3, 0xFF, 0xFF, 0x60, 0x40,
0x0B, 0x36, 0x03, 0x00, 0xDA, 0x60, 0xC5, 0x78, 0xFF, 0xFF, 0x01, 0x64, 0xA2, 0xDB, 0x0B, 0x64,
0x19, 0x60, 0xA4, 0xFB, 0xA6, 0xF1, 0x66, 0x41, 0x64, 0x46, 0x22, 0x64, 0x3A, 0xFA, 0x61, 0x46,
0x01, 0x64, 0x0A, 0xFA, 0x00, 0x64, 0x0B, 0xFA, 0x01, 0x64, 0x40, 0x60, 0x7A, 0xFB, 0x01, 0x64,
0x68, 0xFB, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x25, 0x60, 0xCE, 0x64, 0x13, 0x60,
0x0D, 0xFB, 0x65, 0x44, 0x5A, 0xDB, 0x02, 0x64, 0x5A, 0xDB, 0xFF, 0xFF, 0x2B, 0xFF, 0x00, 0x66,
0xDB, 0xF3, 0x46, 0x46, 0xFD, 0xA0, 0xC1, 0xFE, 0x02, 0x02, 0x2F, 0x58, 0xFF, 0xFF, 0x1C, 0x60,
0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x02, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x00, 0x60,
0x0C, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xDB, 0x60, 0xB9, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58,
0xFF, 0xFF, 0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x08, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x3A, 0x03,
0xA0, 0x84, 0xA2, 0xDB, 0x1C, 0x60, 0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB,
0xFF, 0xFF, 0x04, 0xFF, 0x00, 0x64, 0x68, 0xFB, 0x26, 0x46, 0x00, 0xF4, 0x09, 0xF2, 0x0A, 0xF2,
0x01, 0xA8, 0x0B, 0xF2, 0x02, 0xA8, 0x04, 0x02, 0x00, 0xA8, 0x02, 0x02, 0x01, 0x02, 0x31, 0x00,
0xDC, 0x60, 0x58, 0x4D, 0xB9, 0x78, 0xFF, 0xFF, 0x0B, 0xF2, 0x26, 0x46, 0x40, 0x59, 0x02, 0x60,
0x00, 0x61, 0x2F, 0xF2, 0xA1, 0xDB, 0x30, 0xF2, 0x41, 0x58, 0x59, 0xDB, 0x31, 0xF2, 0x59, 0xDB,
0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF,
0x00, 0x66, 0x46, 0x46, 0x03, 0x65, 0xF1, 0x60, 0x58, 0x4E, 0x96, 0x78, 0xFF, 0xFF, 0xE7, 0x60,
0x0B, 0x78, 0xFF, 0xFF, 0xDC, 0x60, 0x58, 0x4D, 0xB9, 0x78, 0xFF, 0xFF, 0x00, 0x64, 0x68, 0xFB,
0x20, 0x40, 0x08, 0x2A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x60, 0x22, 0xFB,
0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x00, 0x64, 0x68, 0xFB, 0x26, 0x46, 0x00, 0xF4,
0x09, 0xF2, 0x0A, 0xF2, 0x01, 0xA8, 0x0B, 0xF2, 0x04, 0xA8, 0x1A, 0x02, 0x00, 0xA8, 0x18, 0x02,
0x17, 0x02, 0xDC, 0x60, 0x58, 0x4D, 0xB9, 0x78, 0xFF, 0xFF, 0x26, 0x46, 0x26, 0x60, 0x1A, 0x64,
0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66, 0x46, 0x46, 0x20, 0x40,
0x08, 0x2A, 0x03, 0x00, 0xDC, 0x60, 0xF6, 0x78, 0xFF, 0xFF, 0xE3, 0x60, 0x69, 0x78, 0xFF, 0xFF,
0xDC, 0x60, 0x58, 0x4D, 0xB9, 0x78, 0xFF, 0xFF, 0x0B, 0xF2, 0x26, 0x46, 0x40, 0x59, 0x02, 0x60,
0x00, 0x61, 0x2F, 0xF2, 0xA1, 0xDB, 0x30, 0xF2, 0x41, 0x58, 0x59, 0xDB, 0x31, 0xF2, 0x59, 0xDB,
0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF,
0x00, 0x66, 0x46, 0x46, 0x03, 0x65, 0xF1, 0x60, 0x58, 0x4E, 0x96, 0x78, 0xFF, 0xFF, 0xE7, 0x60,
0x0B, 0x78, 0xFF, 0xFF, 0xDC, 0x60, 0x58, 0x4D, 0xB9, 0x78, 0xFF, 0xFF, 0x00, 0x64, 0x68, 0xFB,
0x20, 0x40, 0x08, 0x2A, 0x03, 0x00, 0xD9, 0x60, 0xCA, 0x78, 0xFF, 0xFF, 0xE2, 0x60, 0x73, 0x78,
0xFF, 0xFF, 0x19, 0x60, 0xA4, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x0B, 0x3A, 0x06, 0x00, 0x0B, 0x64,
0x16, 0x60, 0xC2, 0xFB, 0x33, 0x60, 0x48, 0x62, 0xA2, 0xDF, 0x2D, 0x58, 0xFF, 0xFF, 0x16, 0x60,
0xC2, 0xF1, 0xA5, 0xD2, 0x64, 0x40, 0x0B, 0x2A, 0x20, 0x00, 0x85, 0x36, 0x0B, 0x00, 0x32, 0x3A,
0x1E, 0x00, 0x60, 0x47, 0xFF, 0xB4, 0x02, 0xA4, 0xC4, 0x85, 0xA5, 0xD2, 0xFF, 0xFF, 0x60, 0x40,
0x85, 0x3A, 0x15, 0x00, 0x65, 0x44, 0x0A, 0xA4, 0xA0, 0xD0, 0x33, 0x60, 0x46, 0x62, 0x64, 0x40,
0x18, 0x26, 0x09, 0x00, 0xA2, 0xDF, 0x01, 0x64, 0x16, 0x60, 0xC2, 0xFB, 0x32, 0x41, 0x08, 0x65,
0xB5, 0x81, 0x41, 0x52, 0x02, 0x00, 0x01, 0x64, 0xA2, 0xDB, 0x2D, 0x58, 0xFF, 0xFF, 0x33, 0x60,
0x46, 0x62, 0xA2, 0xDF, 0x01, 0x64, 0x16, 0x60, 0xC2, 0xFB, 0xF7, 0x01, 0x45, 0x64, 0x3B, 0x42,
0x5A, 0xDB, 0x35, 0x60, 0xAA, 0x7C, 0x35, 0x60, 0x98, 0x63, 0xA3, 0xD9, 0x64, 0x41, 0x2F, 0x60,
0x02, 0x63, 0xBD, 0xD3, 0x00, 0x7C, 0x03, 0x1B, 0x27, 0x43, 0x10, 0xA3, 0xBD, 0xD3, 0xFF, 0xFF,
0x60, 0x45, 0x64, 0x5F, 0xA1, 0xDB, 0x65, 0x44, 0xBD, 0xD1, 0xC8, 0x84, 0x59, 0xD8, 0xFC, 0x05,
0x27, 0x41, 0x10, 0xA1, 0xA1, 0xD1, 0xFF, 0xFF, 0xC1, 0x81, 0x01, 0x26, 0xDD, 0x81, 0x41, 0x4C,
0x59, 0xD1, 0x7C, 0x44, 0xB0, 0x84, 0x59, 0xD1, 0x59, 0xD1, 0xB0, 0x84, 0xB0, 0x84, 0xFF, 0xFF,
0x02, 0x02, 0x67, 0x44, 0xC2, 0x00, 0x34, 0x60, 0x5C, 0x63, 0xD9, 0x81, 0x59, 0xD3, 0x38, 0x60,
0x10, 0x62, 0x00, 0xBC, 0xA2, 0xDF, 0x09, 0x03, 0x01, 0x7C, 0xA2, 0xD9, 0x30, 0x60, 0x14, 0x64,
0xBD, 0xDA, 0x00, 0x60, 0x01, 0x64, 0xBD, 0xDA, 0x58, 0x00, 0xDD, 0x60, 0x18, 0x64, 0xBD, 0xDA,
0x50, 0x60, 0x00, 0x64, 0xBD, 0xDA, 0x01, 0x60, 0xF2, 0x64, 0xBD, 0xDA, 0x00, 0x60, 0x01, 0x64,
0xBD, 0xDA, 0x2C, 0x41, 0x59, 0xD3, 0x50, 0x60, 0x00, 0x7C, 0x60, 0x40, 0x02, 0x2A, 0x03, 0x00,
0x01, 0x60, 0xF2, 0x64, 0x0E, 0x00, 0x04, 0x2A, 0x03, 0x00, 0x02, 0x60, 0xF2, 0x64, 0x09, 0x00,
0x10, 0x2A, 0x03, 0x00, 0x04, 0x60, 0xF2, 0x64, 0x04, 0x00, 0x20, 0x2A, 0x04, 0x00, 0x05, 0x60,
0xF2, 0x64, 0xBD, 0xD9, 0xBD, 0xDB, 0x01, 0x64, 0xBD, 0xDB, 0x59, 0xD3, 0x50, 0x60, 0x00, 0x7C,
0x60, 0x40, 0x02, 0x2A, 0x03, 0x00, 0x01, 0x60, 0xF2, 0x64, 0x0E, 0x00, 0x04, 0x2A, 0x03, 0x00,
0x02, 0x60, 0xF2, 0x64, 0x09, 0x00, 0x10, 0x2A, 0x03, 0x00, 0x04, 0x60, 0xF2, 0x64, 0x04, 0x00,
0x20, 0x2A, 0x04, 0x00, 0x05, 0x60, 0xF2, 0x64, 0xBD, 0xD9, 0xBD, 0xDB, 0x01, 0x64, 0xBD, 0xDB,
0x59, 0xD3, 0x50, 0x60, 0x00, 0x7C, 0x60, 0x40, 0x01, 0x2A, 0x03, 0x00, 0x00, 0x60, 0xF2, 0x64,
0x09, 0x00, 0x02, 0x2A, 0x03, 0x00, 0x01, 0x60, 0xF2, 0x64, 0x04, 0x00, 0x04, 0x2A, 0x02, 0x00,
0x02, 0x60, 0xF2, 0x64, 0xBD, 0xD9, 0xBD, 0xDB, 0x4B, 0x00, 0x2C, 0x41, 0x59, 0xD3, 0x0F, 0x60,
0x00, 0x7C, 0x60, 0x40, 0x02, 0x2A, 0x03, 0x00, 0x01, 0x60, 0xAC, 0x64, 0x0E, 0x00, 0x04, 0x2A,
0x03, 0x00, 0x02, 0x60, 0xAC, 0x64, 0x09, 0x00, 0x10, 0x2A, 0x03, 0x00, 0x04, 0x60, 0xAC, 0x64,
0x04, 0x00, 0x20, 0x2A, 0x04, 0x00, 0x05, 0x60, 0xAC, 0x64, 0xBD, 0xD9, 0xBD, 0xDB, 0x01, 0x64,
0xBD, 0xDB, 0x59, 0xD3, 0x0F, 0x60, 0x00, 0x7C, 0x60, 0x40, 0x02, 0x2A, 0x03, 0x00, 0x01, 0x60,
0xAC, 0x64, 0x0E, 0x00, 0x04, 0x2A, 0x03, 0x00, 0x02, 0x60, 0xAC, 0x64, 0x09, 0x00, 0x10, 0x2A,
0x03, 0x00, 0x04, 0x60, 0xAC, 0x64, 0x04, 0x00, 0x20, 0x2A, 0x04, 0x00, 0x05, 0x60, 0xAC, 0x64,
0xBD, 0xD9, 0xBD, 0xDB, 0x01, 0x64, 0xBD, 0xDB, 0x59, 0xD3, 0x0F, 0x60, 0x00, 0x7C, 0x60, 0x40,
0x01, 0x2A, 0x03, 0x00, 0x00, 0x60, 0xAC, 0x64, 0x09, 0x00, 0x02, 0x2A, 0x03, 0x00, 0x01, 0x60,
0xAC, 0x64, 0x04, 0x00, 0x04, 0x2A, 0x02, 0x00, 0x02, 0x60, 0xAC, 0x64, 0xBD, 0xD9, 0xBD, 0xDB,
0x1C, 0x60, 0x08, 0xF3, 0xFF, 0x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0x60, 0x2A, 0x62, 0x00, 0x64,
0xA2, 0xDB, 0x26, 0x46, 0x00, 0xF4, 0x0A, 0xF2, 0x00, 0x63, 0x00, 0xA8, 0x68, 0xFD, 0x06, 0x02,
0x09, 0xF2, 0xFF, 0xFF, 0x01, 0xB0, 0x01, 0x7C, 0x5A, 0x02, 0x0A, 0xF8, 0x0A, 0xF2, 0x26, 0x46,
0x40, 0x59, 0x02, 0x60, 0x00, 0x61, 0x2F, 0xF2, 0xA1, 0xDB, 0x30, 0xF2, 0x41, 0x58, 0x59, 0xDB,
0x31, 0xF2, 0x59, 0xDB, 0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D,
0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66, 0x46, 0x46, 0x05, 0x65, 0xF1, 0x60, 0x58, 0x4E, 0x96, 0x78,
0xFF, 0xFF, 0xE7, 0x60, 0x0B, 0x78, 0xFF, 0xFF, 0x47, 0x64, 0x3B, 0x42, 0x5A, 0xDB, 0xD9, 0x60,
0xCA, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x10, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x20, 0x03, 0xA0, 0x84,
0xA2, 0xDB, 0x1C, 0x60, 0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF,
0x04, 0xFF, 0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78,
0xFF, 0xFF, 0x00, 0x66, 0x46, 0x46, 0x00, 0x64, 0x68, 0xFB, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64,
0xA2, 0xDB, 0x49, 0x64, 0x3B, 0x42, 0x5A, 0xDB, 0xDA, 0x60, 0x62, 0x78, 0xFF, 0xFF, 0xFF, 0x60,
0xFB, 0x64, 0xA0, 0x84, 0xA2, 0xDB, 0x00, 0x64, 0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 0x0F, 0x60, 0xFF, 0x64, 0xA0, 0x84, 0x83, 0xFB, 0x26, 0x46, 0x32, 0xF0, 0x7F, 0xF9,
0x33, 0xF0, 0x0E, 0x63, 0xC7, 0x81, 0x80, 0xF9, 0x34, 0xF0, 0x81, 0xF9, 0x59, 0xD1, 0xFF, 0xFF,
0x64, 0x44, 0x01, 0x2A, 0xC8, 0x84, 0x60, 0x43, 0x33, 0x60, 0xBC, 0x64, 0x58, 0xD9, 0x59, 0xD1,
0x58, 0xD9, 0xFD, 0x1F, 0x16, 0x60, 0xC2, 0xF1, 0x59, 0xD3, 0x64, 0x40, 0x01, 0x36, 0x22, 0x64,
0x64, 0x40, 0x00, 0x36, 0x50, 0x94, 0xA6, 0xF1, 0xFF, 0xFF, 0x44, 0x47, 0xA7, 0x46, 0x3A, 0xFA,
0xBB, 0xFC, 0xA7, 0x46, 0x0E, 0x60, 0x35, 0xF3, 0x85, 0xFB, 0x2E, 0x60, 0x2E, 0x64, 0x2D, 0x60,
0x8A, 0x63, 0xA0, 0xD1, 0xA3, 0xD9, 0x64, 0x41, 0x58, 0xD1, 0x5B, 0xD9, 0x7D, 0xF3, 0x66, 0x45,
0xA6, 0xF5, 0x60, 0x40, 0x01, 0x27, 0x08, 0x00, 0x91, 0xFA, 0x61, 0x44, 0xFD, 0x60, 0x58, 0x4E,
0xAC, 0x78, 0xFF, 0xFF, 0x12, 0xFA, 0x07, 0x00, 0x11, 0xF8, 0x64, 0x44, 0xFD, 0x60, 0x58, 0x4E,
0xAC, 0x78, 0xFF, 0xFF, 0x12, 0xFA, 0x65, 0x46, 0x31, 0xF2, 0x1D, 0x60, 0xC0, 0x65, 0x60, 0x47,
0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD3, 0x66, 0x41, 0x60, 0x46, 0x60, 0x43, 0x05, 0xF2, 0x16, 0x18,
0x61, 0x46, 0x31, 0xF0, 0x63, 0x46, 0xD0, 0x80, 0x04, 0xF2, 0x0C, 0x02, 0x61, 0x46, 0x30, 0xF0,
0x63, 0x46, 0xD0, 0x80, 0x03, 0xF2, 0x06, 0x02, 0x61, 0x46, 0x2F, 0xF0, 0x63, 0x46, 0xD0, 0x80,
0xFF, 0xFF, 0x07, 0x03, 0x80, 0xF4, 0xFF, 0xFF, 0x63, 0x46, 0xE8, 0x1B, 0xA6, 0xF3, 0x08, 0xFE,
0x60, 0x43, 0x61, 0x46, 0xA6, 0xF1, 0xFF, 0xFF, 0xD3, 0x80, 0x31, 0xF2, 0x27, 0x02, 0x66, 0x41,
0x1D, 0x60, 0xC0, 0x65, 0x60, 0x47, 0x00, 0x7F, 0xA6, 0xF1, 0xE0, 0x84, 0x44, 0xD3, 0x64, 0x43,
0x11, 0x18, 0x60, 0x46, 0x00, 0xF2, 0xFF, 0xFF, 0xFC, 0x1B, 0x66, 0x44, 0x64, 0x46, 0x80, 0xF0,
0x60, 0x46, 0x80, 0xF8, 0x65, 0x46, 0x65, 0x43, 0x80, 0xF0, 0x01, 0xFA, 0x80, 0xFC, 0x64, 0x46,
0x80, 0xF8, 0x0B, 0x00, 0x64, 0x46, 0x62, 0x43, 0x00, 0xF2, 0xA3, 0xDB, 0x60, 0x46, 0x80, 0xF0,
0x81, 0xFC, 0x80, 0xFC, 0x64, 0x46, 0x80, 0xF8, 0x60, 0x43, 0x61, 0x46, 0x43, 0x4B, 0x01, 0x65,
0xFD, 0x60, 0x58, 0x4E, 0xDD, 0x78, 0xFF, 0xFF, 0x43, 0x47, 0x3F, 0xF2, 0x00, 0xF4, 0x60, 0x43,
0xFA, 0xA3, 0x00, 0x60, 0x17, 0x61, 0x00, 0x60, 0x01, 0x65, 0x01, 0x60, 0xFF, 0x64, 0x40, 0x4C,
0xFD, 0x60, 0x58, 0x4E, 0x7A, 0x78, 0xFF, 0xFF, 0x00, 0xBB, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x64,
0x40, 0x4A, 0x60, 0xFE, 0x02, 0x60, 0x00, 0x63, 0xBD, 0xD3, 0xBD, 0xD3, 0x60, 0x41, 0xFE, 0x60,
0x58, 0x4E, 0x2C, 0x78, 0xFF, 0xFF, 0x20, 0xFE, 0x00, 0x65, 0x00, 0x64, 0x19, 0x60, 0x3B, 0xFB,
0x02, 0x00, 0x20, 0xFE, 0xFF, 0x65, 0x02, 0x60, 0x00, 0x63, 0x60, 0xFE, 0xBD, 0xD3, 0xBD, 0xD3,
0x60, 0x41, 0x20, 0xFE, 0xCD, 0x81, 0x60, 0x40, 0x80, 0x2A, 0x39, 0x00, 0x7F, 0xB4, 0x02, 0x3A,
0x02, 0x00, 0x01, 0x64, 0x2E, 0x00, 0x04, 0x3A, 0x02, 0x00, 0x02, 0x64, 0x2A, 0x00, 0x0B, 0x3A,
0x02, 0x00, 0x04, 0x64, 0x26, 0x00, 0x16, 0x3A, 0x02, 0x00, 0x08, 0x64, 0x22, 0x00, 0x0C, 0x3A,
0x02, 0x00, 0x10, 0x64, 0x1E, 0x00, 0x12, 0x3A, 0x02, 0x00, 0x20, 0x64, 0x1A, 0x00, 0x18, 0x3A,
0x02, 0x00, 0x40, 0x64, 0x16, 0x00, 0x24, 0x3A, 0x02, 0x00, 0x80, 0x64, 0x12, 0x00, 0x30, 0x3A,
0x02, 0x00, 0x01, 0x67, 0x0E, 0x00, 0x48, 0x3A, 0x02, 0x00, 0x02, 0x67, 0x0A, 0x00, 0x60, 0x3A,
0x02, 0x00, 0x04, 0x67, 0x06, 0x00, 0x6C, 0x3A, 0x02, 0x00, 0x08, 0x67, 0x02, 0x00, 0x00, 0x64,
0x00, 0x00, 0x19, 0x60, 0x3B, 0xF1, 0xFF, 0xFF, 0xB0, 0x84, 0x19, 0x60, 0x3B, 0xFB, 0x61, 0x40,
0x00, 0x36, 0x05, 0x00, 0x60, 0xFE, 0xBD, 0xD3, 0xFF, 0xFF, 0x20, 0xFE, 0xBB, 0x01, 0x65, 0x40,
0x00, 0x3A, 0x1E, 0x00, 0x26, 0x46, 0x3F, 0xF2, 0x00, 0xF4, 0x60, 0x43, 0xFA, 0xA3, 0x00, 0x60,
0x17, 0x61, 0x00, 0x60, 0x32, 0x65, 0x01, 0x60, 0xFF, 0x64, 0x40, 0x4C, 0xFD, 0x60, 0x58, 0x4E,
0x7A, 0x78, 0xFF, 0xFF, 0x00, 0xBB, 0xFF, 0xFF, 0x0B, 0x03, 0x60, 0xFE, 0x02, 0x60, 0x00, 0x63,
0xBD, 0xD3, 0xBD, 0xD3, 0x60, 0x41, 0xFE, 0x60, 0x58, 0x4E, 0x2C, 0x78, 0xFF, 0xFF, 0x91, 0x01,
0x20, 0xFE, 0x00, 0x65, 0xFC, 0x60, 0x58, 0x4E, 0xC7, 0x78, 0xFF, 0xFF, 0xA1, 0xF3, 0xFF, 0xFF,
0x60, 0x40, 0x01, 0x27, 0x04, 0x00, 0xFD, 0x60, 0x58, 0x4E, 0x11, 0x78, 0xFF, 0xFF, 0x20, 0xFE,
0x37, 0x60, 0xF8, 0x61, 0xA1, 0xD1, 0xA1, 0xF3, 0x01, 0x60, 0xAC, 0x63, 0x60, 0x45, 0x2A, 0x44,
0x79, 0xFB, 0xA3, 0xD5, 0x65, 0x40, 0x01, 0x27, 0x5B, 0xD5, 0x65, 0x40, 0x01, 0x27, 0x59, 0xD1,
0x66, 0x41, 0xA0, 0x84, 0x24, 0x94, 0x2B, 0x46, 0x0F, 0xFA, 0x7A, 0xFB, 0x16, 0x64, 0x12, 0xFA,
0x01, 0x64, 0x11, 0xFA, 0x66, 0x5C, 0xC2, 0x60, 0x58, 0x4E, 0x6D, 0x78, 0xFF, 0xFF, 0x1A, 0x60,
0x22, 0xF3, 0x1A, 0x60, 0x21, 0xF1, 0x60, 0x47, 0xB0, 0x84, 0x1C, 0x60, 0x08, 0xF1, 0xFF, 0xFF,
0x01, 0x18, 0x80, 0xBC, 0x16, 0x60, 0xC2, 0xF1, 0xFF, 0xFF, 0x64, 0x40, 0x01, 0x36, 0x22, 0x64,
0x64, 0x40, 0x00, 0x36, 0x50, 0x94, 0xA7, 0x46, 0x3A, 0xFA, 0xBB, 0xFC, 0xA7, 0x46, 0x80, 0x60,
0x03, 0x65, 0x32, 0x40, 0x08, 0x2A, 0x03, 0x65, 0xA7, 0x46, 0x06, 0xF0, 0x7F, 0x60, 0xFF, 0x64,
0xA0, 0x84, 0xB4, 0x84, 0x06, 0xFA, 0xBB, 0xFC, 0xA7, 0x46, 0x26, 0x46, 0x2F, 0xF0, 0x30, 0xF0,
0x64, 0x43, 0x31, 0xF2, 0x27, 0x46, 0x03, 0xFC, 0x04, 0xF8, 0x05, 0xFA, 0x26, 0x46, 0xD9, 0x60,
0x58, 0x4E, 0xAE, 0x78, 0xFF, 0xFF, 0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60,
0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66, 0x46, 0x46, 0x01, 0x64, 0x8A, 0xFB, 0x16, 0x60,
0xC9, 0xF3, 0x20, 0x41, 0x00, 0xBC, 0x20, 0xB9, 0x01, 0x03, 0x41, 0x40, 0x20, 0x60, 0x14, 0x61,
0xA1, 0xDF, 0x04, 0x64, 0xC1, 0xFE, 0xDB, 0xFB, 0xF1, 0xF3, 0xFF, 0xFF, 0xFE, 0xB4, 0xF1, 0xFB,
0xF7, 0x60, 0xFF, 0x65, 0x20, 0x44, 0x24, 0x80, 0x08, 0x60, 0x08, 0xF1, 0x80, 0x60, 0x00, 0x64,
0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x01, 0x65, 0xF1, 0x60, 0x58, 0x4E, 0xC3, 0x78, 0xFF, 0xFF,
0x33, 0x60, 0xE6, 0x65, 0xA5, 0xDF, 0x08, 0x60, 0x0C, 0xF1, 0x00, 0x60, 0x02, 0x64, 0xB0, 0x84,
0xA2, 0xDB, 0xCF, 0xFE, 0x0C, 0x64, 0x68, 0xFB, 0x00, 0x60, 0x31, 0x64, 0x08, 0x60, 0x16, 0xFB,
0xE1, 0x60, 0x36, 0x64, 0x5A, 0xDB, 0x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0xFF, 0x00, 0x60,
0x20, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0xFF, 0xFF, 0x08, 0x24, 0x46, 0x01, 0xA0, 0x84, 0xA2, 0xDB,
0x00, 0x63, 0x68, 0xFD, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x30, 0x00, 0x20, 0x40,
0x06, 0x23, 0x10, 0x00, 0x08, 0x60, 0x27, 0xF1, 0x7F, 0x60, 0xFF, 0x64, 0xA0, 0x84, 0xA2, 0xDB,
0x80, 0x60, 0x00, 0x64, 0x08, 0x60, 0x28, 0xFB, 0xE1, 0x60, 0xF7, 0x64, 0x5A, 0xDB, 0xCF, 0xFE,
0x2F, 0x58, 0xFF, 0xFF, 0x00, 0x64, 0x08, 0x60, 0x27, 0xFB, 0x5A, 0xDB, 0x10, 0x60, 0x4E, 0x62,
0x00, 0x64, 0xA2, 0xDB, 0x44, 0x01, 0x1C, 0x60, 0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64,
0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x00, 0x64, 0x68, 0xFB, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64,
0xA2, 0xDB, 0x01, 0x64, 0x8A, 0xFB, 0xFF, 0xFF, 0xC1, 0xFE, 0x2E, 0x58, 0xFF, 0xFF, 0x50, 0x64,
0x3B, 0x42, 0x5A, 0xDB, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x00, 0x60, 0x95, 0xF3,
0xFF, 0xFF, 0x10, 0xB0, 0xFF, 0xFF, 0x11, 0x03, 0x08, 0x60, 0x1B, 0xF1, 0x01, 0x60, 0x00, 0x64,
0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x04, 0x60, 0x00, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xE2, 0x60,
0x2A, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0x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B, 0x02, 0x64, 0x4A, 0xDB, 0xFF, 0xFF,
0x04, 0xFF, 0x00, 0x60, 0x1C, 0x64, 0x08, 0x60, 0x16, 0xFB, 0xE4, 0x60, 0x23, 0x64, 0x5A, 0xDB,
0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x04, 0x64, 0xA0, 0x80,
0x9C, 0x84, 0x0E, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x57, 0x64, 0x3B, 0x42, 0x5A, 0xDB, 0x00, 0x64,
0x68, 0xFB, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0xE2, 0x60, 0x73, 0x78, 0xFF, 0xFF,
0x00, 0x60, 0x10, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x16, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x1C, 0x60,
0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x58, 0x64,
0x3B, 0x42, 0x5A, 0xDB, 0x00, 0x64, 0x68, 0xFB, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB,
0xE6, 0x60, 0x36, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x08, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x3D, 0x03,
0xA0, 0x84, 0xA2, 0xDB, 0x1C, 0x60, 0x92, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB,
0xFF, 0xFF, 0x04, 0xFF, 0x00, 0x64, 0x68, 0xFB, 0x10, 0x60, 0x2A, 0x62, 0x00, 0x64, 0xA2, 0xDB,
0x26, 0x46, 0x00, 0xF4, 0x0A, 0xF2, 0x09, 0xF2, 0x04, 0x1B, 0x01, 0xB0, 0x01, 0x7C, 0x2D, 0x02,
0x0A, 0xF8, 0x59, 0x64, 0x3B, 0x42,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E, 0x7A, 0x78, 0xFF, 0xFF,
0x00, 0xBB, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x64, 0x40, 0x4A, 0x60, 0xFE, 0x02, 0x60, 0x00, 0x63,
0xBD, 0xD3, 0xBD, 0xD3, 0x60, 0x41, 0xFE, 0x60, 0x58, 0x4E, 0x2C, 0x78, 0xFF, 0xFF, 0x20, 0xFE,
0x00, 0x65, 0x00, 0x64, 0x19, 0x60, 0x3B, 0xFB, 0x02, 0x00, 0x20, 0xFE, 0xFF, 0x65, 0x02, 0x60,
0x00, 0x63, 0x60, 0xFE, 0xBD, 0xD3, 0xBD, 0xD3, 0x60, 0x41, 0x20, 0xFE, 0xCD, 0x81, 0x60, 0x40,
0x80, 0x2A, 0x39, 0x00, 0x7F, 0xB4, 0x02, 0x3A, 0x02, 0x00, 0x01, 0x64, 0x2E, 0x00, 0x04, 0x3A,
0x02, 0x00, 0x02, 0x64, 0x2A, 0x00, 0x0B, 0x3A, 0x02, 0x00, 0x04, 0x64, 0x26, 0x00, 0x16, 0x3A,
0x02, 0x00, 0x08, 0x64, 0x22, 0x00, 0x0C, 0x3A, 0x02, 0x00, 0x10, 0x64, 0x1E, 0x00, 0x12, 0x3A,
0x02, 0x00, 0x20, 0x64, 0x1A, 0x00, 0x18, 0x3A, 0x02, 0x00, 0x40, 0x64, 0x16, 0x00, 0x24, 0x3A,
0x02, 0x00, 0x80, 0x64, 0x12, 0x00, 0x30, 0x3A, 0x02, 0x00, 0x01, 0x67, 0x0E, 0x00, 0x48, 0x3A,
0x02, 0x00, 0x02, 0x67, 0x0A, 0x00, 0x60, 0x3A, 0x02, 0x00, 0x04, 0x67, 0x06, 0x00, 0x6C, 0x3A,
0x02, 0x00, 0x08, 0x67, 0x02, 0x00, 0x00, 0x64, 0x00, 0x00, 0x19, 0x60, 0x3B, 0xF1, 0xFF, 0xFF,
0xB0, 0x84, 0x19, 0x60, 0x3B, 0xFB, 0x61, 0x40, 0x00, 0x36, 0x05, 0x00, 0x60, 0xFE, 0xBD, 0xD3,
0xFF, 0xFF, 0x20, 0xFE, 0xBB, 0x01, 0x65, 0x40, 0x00, 0x3A, 0x1E, 0x00, 0x26, 0x46, 0x3F, 0xF2,
0x00, 0xF4, 0x60, 0x43, 0xFA, 0xA3, 0x00, 0x60, 0x17, 0x61, 0x00, 0x60, 0x32, 0x65, 0x01, 0x60,
0xFF, 0x64, 0x40, 0x4C, 0xFD, 0x60, 0x58, 0x4E, 0x7A, 0x78, 0xFF, 0xFF, 0x00, 0xBB, 0xFF, 0xFF,
0x0B, 0x03, 0x60, 0xFE, 0x02, 0x60, 0x00, 0x63, 0xBD, 0xD3, 0xBD, 0xD3, 0x60, 0x41, 0xFE, 0x60,
0x58, 0x4E, 0x2C, 0x78, 0xFF, 0xFF, 0x91, 0x01, 0x20, 0xFE, 0x00, 0x65, 0xFC, 0x60, 0x58, 0x4E,
0xC7, 0x78, 0xFF, 0xFF, 0xA1, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x27, 0x04, 0x00, 0xFD, 0x60,
0x58, 0x4E, 0x11, 0x78, 0xFF, 0xFF, 0x20, 0xFE, 0x37, 0x60, 0xF8, 0x61, 0xA1, 0xD1, 0xA1, 0xF3,
0x01, 0x60, 0xAC, 0x63, 0x60, 0x45, 0x2A, 0x44, 0x79, 0xFB, 0xA3, 0xD5, 0x65, 0x40, 0x01, 0x27,
0x5B, 0xD5, 0x65, 0x40, 0x01, 0x27, 0x59, 0xD1, 0x66, 0x41, 0xA0, 0x84, 0x24, 0x94, 0x2B, 0x46,
0x0F, 0xFA, 0x7A, 0xFB, 0x16, 0x64, 0x12, 0xFA, 0x01, 0x64, 0x11, 0xFA, 0x66, 0x5C, 0xC2, 0x60,
0x58, 0x4E, 0x6D, 0x78, 0xFF, 0xFF, 0xA6, 0xF3, 0xFF, 0xFF, 0x02, 0xA4, 0x40, 0x4B, 0x60, 0x46,
0x00, 0x64, 0x17, 0xFA, 0x00, 0x64, 0x16, 0xFA, 0x13, 0xFA, 0x00, 0x65, 0x26, 0x46, 0xFD, 0x60,
0x58, 0x4E, 0xDD, 0x78, 0xFF, 0xFF, 0xA6, 0xF3, 0x1D, 0x60, 0xC0, 0x65, 0x02, 0xA4, 0x60, 0x46,
0x05, 0xF0, 0x60, 0x41, 0x64, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x00, 0x7C, 0x44, 0xD9, 0x26, 0x46,
0x31, 0xF2, 0x61, 0x5C, 0x60, 0x47, 0x00, 0x7F, 0xE0, 0x84, 0x44, 0xD9, 0x26, 0x46, 0x2F, 0xF0,
0x61, 0x46, 0x03, 0xF8, 0x26, 0x46, 0x30, 0xF0, 0x61, 0x46, 0x04, 0xF8, 0x26, 0x46, 0x31, 0xF0,
0x61, 0x46, 0x05, 0xF8, 0x26, 0x46, 0xD9, 0x60, 0x58, 0x4E, 0xAE, 0x78, 0xFF, 0xFF, 0x26, 0x46,
0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66,
0x46, 0x46, 0x03, 0x65, 0xF1, 0x60, 0x58, 0x4E, 0xC3, 0x78, 0xFF, 0xFF, 0x01, 0x63, 0x8A, 0xFD,
0x08, 0x60, 0x0C, 0xF1, 0x00, 0x60, 0x02, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0xC1, 0xFE,
0x5C, 0x64, 0x3B, 0x42, 0x5A, 0xDB, 0xE1, 0x60, 0x22, 0x78, 0xFF, 0xFF, 0xFF, 0x60, 0xF7, 0x65,
0x20, 0x44, 0x24, 0x80, 0xDA, 0x60, 0x74, 0x78, 0xFF, 0xFF, 0xDB, 0xF3, 0xFF, 0xFF, 0xFD, 0xA0,
0x2A, 0xF2, 0x03, 0x03, 0xE6, 0x60, 0xDE, 0x78, 0xFF, 0xFF, 0x60, 0x40, 0xB0, 0x36, 0x11, 0x00,
0xC0, 0x36, 0x02, 0x00, 0x2F, 0x58, 0xFF, 0xFF, 0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B,
0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66, 0x46, 0x46, 0xDA, 0x60, 0x74, 0x78,
0xFF, 0xFF, 0x66, 0x45, 0x00, 0xF4, 0x0A, 0xF2, 0x0B, 0xF2, 0xFE, 0xA0, 0xF3, 0xA0, 0x67, 0x02,
0x60, 0x41, 0x09, 0xF2, 0x1D, 0x03, 0x00, 0xA0, 0xFF, 0xA0, 0x4B, 0x03, 0x5D, 0x03, 0x00, 0xA0,
0xFF, 0xFF, 0x47, 0x03, 0x01, 0x64, 0x10, 0x60, 0x0B, 0xFB, 0x0D, 0x64, 0x10, 0x60, 0x0C, 0xFB,
0x03, 0x64, 0x10, 0x60, 0x0D, 0xFB, 0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60,
0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66, 0x46, 0x46, 0xDA, 0x60, 0x74, 0x78, 0xFF, 0xFF,
0x16, 0x60, 0xC3, 0xF3, 0xFF, 0xFF, 0xFE, 0xA0, 0x20, 0x60, 0x16, 0x61, 0x15, 0x02, 0x01, 0x64,
0xA1, 0xDB, 0x00, 0x64, 0x10, 0x60, 0x0C, 0xFB, 0x01, 0x64, 0x10, 0x60, 0x0D, 0xFB, 0x26, 0x46,
0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66,
0x46, 0x46, 0xDA, 0x60, 0x74, 0x78, 0xFF, 0xFF, 0x02, 0x64, 0xA1, 0xDB, 0x00, 0x64, 0x10, 0x60,
0x0C, 0xFB, 0x01, 0x64, 0x10, 0x60, 0x0D, 0xFB, 0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B,
0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF, 0x00, 0x66, 0x46, 0x46, 0xDA, 0x60, 0x74, 0x78,
0xFF, 0xFF, 0x65, 0x46, 0x07, 0xF4, 0x06, 0xF2, 0xFF, 0xFF, 0x01, 0x7E, 0x06, 0xFA, 0x65, 0x46,
0x26, 0x46, 0x26, 0x60, 0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF,
0x00, 0x66, 0x46, 0x46, 0x2F, 0x58, 0xFF, 0xFF, 0xDC, 0x60, 0x09, 0x78, 0xFF, 0xFF, 0x0A, 0xF2,
0x09, 0xF2, 0xFC, 0xA0, 0xFF, 0xA0, 0x11, 0x02, 0x0A, 0x02, 0x0B, 0xF2, 0x65, 0x46, 0x0A, 0x1B,
0x66, 0x41, 0x07, 0xF4, 0x06, 0xF2, 0xFF, 0xFF, 0x01, 0x7E, 0x06, 0xFA, 0x61, 0x46, 0xDA, 0x60,
0x74, 0x78, 0xFF, 0xFF, 0x26, 0x46, 0x2F, 0x58, 0xFF, 0xFF, 0x65, 0x46, 0x68, 0xF1, 0x2A, 0xF2,
0x64, 0x41, 0x60, 0x40, 0xA0, 0x3A, 0x02, 0x00, 0x08, 0xB1, 0x04, 0x00, 0xC0, 0x3A, 0x0B, 0x00,
0x04, 0xB1, 0xFF, 0xFF, 0x1E, 0x03, 0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x10, 0x64, 0xB0, 0x84,
0xA2, 0xDB, 0xCF, 0xFE, 0x16, 0x00, 0xB0, 0x3A, 0x02, 0x00, 0x01, 0x65, 0x07, 0x00, 0x10, 0x3A,
0x02, 0x00, 0x02, 0x65, 0x03, 0x00, 0x30, 0x3A, 0x0C, 0x00, 0x10, 0x65, 0xA5, 0x80, 0xFF, 0xFF,
0x08, 0x03, 0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x08, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE,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0xFF, 0xFF, 0xC1, 0xFE, 0x10, 0x60, 0x1E, 0x62, 0x00, 0x64, 0xA2, 0xDB,
0x00, 0x60, 0x80, 0x64, 0x08, 0x60, 0x10, 0xFB, 0xE7, 0x60, 0xCB, 0x64, 0x5A, 0xDB, 0xCF, 0xFE,
0x2F, 0x58, 0xFF, 0xFF, 0x9C, 0xF1, 0x00, 0x64, 0xB0, 0x86, 0x9C, 0xFB, 0x07, 0x03, 0x26, 0x60,
0x1A, 0x64, 0x40, 0x4B, 0x34, 0x60, 0x58, 0x4D, 0x08, 0x78, 0xFF, 0xFF, 0xEB, 0x60, 0xFF, 0x65,
0x20, 0x44, 0x24, 0x80, 0x10, 0x60, 0x1E, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x00, 0x60, 0x80, 0x64,
0x08, 0x60, 0x10, 0xFB, 0xE7, 0x60, 0xCB, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF,
0x95, 0xF3, 0x26, 0x46, 0x60, 0x43, 0x01, 0x2A, 0x20, 0x00, 0x0F, 0xF2, 0x2A, 0xF0, 0x60, 0x40,
0x10, 0x2A, 0x0F, 0x00, 0x64, 0x40, 0x04, 0x27, 0x18, 0x00, 0xFD, 0xB3, 0x64, 0x40, 0x20, 0x27,
0x02, 0xBB, 0x08, 0x60, 0x1B, 0xF1, 0x00, 0x60, 0x08, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE,
0x0B, 0x00, 0xFB, 0xB3, 0x64, 0x40, 0x20, 0x27, 0x04, 0xBB, 0x08, 0x60, 0x1B, 0xF1, 0x00, 0x60,
0x10, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x95, 0xFD, 0x26, 0x46, 0x2F, 0x58, 0xFF, 0xFF,
0xDB, 0xF3, 0x3F, 0xF2, 0x04, 0xA8, 0x57, 0xFB, 0x02, 0x03, 0x2F, 0x58, 0xFF, 0xFF, 0x00, 0xF4,
0x1E, 0x63, 0x08, 0x64, 0x40, 0x48, 0xBD, 0xD2, 0xFF, 0xFF, 0x60, 0x47, 0x05, 0x36, 0x0B, 0x00,
0xFF, 0xB5, 0xC7, 0x83, 0x01, 0x2A, 0xF7, 0x01, 0x4F, 0xD2, 0x5B, 0xD2, 0x60, 0x40, 0x05, 0x37,
0x0B, 0x00, 0xDF, 0x83, 0xF5, 0x01, 0xFF, 0xB5, 0x65, 0x41, 0xA3, 0xD2, 0x47, 0x8A, 0x60, 0x47,
0x40, 0x4C, 0x5B, 0xD2, 0xDF, 0x83, 0x08, 0x00, 0x40, 0x4C, 0x00, 0x7F, 0xDC, 0x85, 0x47, 0x8A,
0x60, 0x41, 0x5B, 0xD2, 0xDB, 0x83, 0x60, 0x47, 0x01, 0xB0, 0xFE, 0xB5, 0x02, 0x03, 0x02, 0x64,
0x40, 0x48, 0x2C, 0x47, 0xFF, 0xB4, 0x73, 0xF1, 0x08, 0x28, 0x73, 0xFB, 0x83, 0xF1, 0x65, 0x44,
0xE0, 0x84, 0xE0, 0x84, 0xE0, 0x84, 0xFD, 0xA1, 0xE1, 0x81, 0xE1, 0x81, 0xE1, 0x85, 0xC4, 0x81,
0xD0, 0x84, 0xD1, 0x80, 0x28, 0x07, 0x27, 0x06, 0x9C, 0x84, 0xDC, 0x84, 0xE8, 0x84, 0xE8, 0x84,
0xE8, 0x85, 0x94, 0xF3, 0xC7, 0x83, 0x01, 0x26, 0x60, 0x47, 0xAB, 0x83, 0xFC, 0xA3, 0x02, 0x00,
0x03, 0x04, 0x00, 0xF4, 0x84, 0xA3, 0xFC, 0x01, 0x80, 0x65, 0x47, 0xD0, 0x28, 0x41, 0xA0, 0x80,
0xFE, 0xA1, 0x14, 0x03, 0x08, 0x02, 0x08, 0x60, 0x2D, 0xF1, 0x00, 0x60, 0x10, 0x64, 0xB0, 0x84,
0xA2, 0xDB, 0xCF, 0xFE, 0x1B, 0x00, 0x08, 0x60, 0x2D, 0xF1, 0x00, 0x60, 0x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xBA, 0xFE, 0x95, 0xF3, 0x00, 0x63, 0x82, 0xFD, 0x10, 0xBC, 0x95, 0xFB, 0xFE, 0x60, 0xFF, 0x65,
0x20, 0x44, 0x24, 0x80, 0x08, 0x60, 0x08, 0xF1, 0x80, 0x60, 0x00, 0x64, 0xB0, 0x84, 0xA2, 0xDB,
0xCF, 0xFE, 0x00, 0x60, 0x64, 0x63, 0x0E, 0x60, 0x37, 0xFD, 0x10, 0x60, 0x36, 0x62, 0x00, 0x64,
0xA2, 0xDB, 0x01, 0x60, 0x04, 0x64, 0x08, 0x60, 0x1C, 0xFB, 0xEA, 0x60, 0x73, 0x64, 0x5A, 0xDB,
0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60, 0x1B, 0xF1, 0x01, 0x60, 0x00, 0x64, 0xA0, 0x80,
0x9C, 0x84, 0x03, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0xA2, 0x01, 0x31, 0x40, 0x04, 0x2A, 0xE5, 0x01,
0x20, 0x40, 0x12, 0x23, 0x11, 0x00, 0x10, 0x60, 0x36, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x10, 0x60,
0x5A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x81, 0x60, 0x00, 0x64, 0x08, 0x60, 0x1C, 0xFB, 0xEA, 0x60,
0x73, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0xDD, 0x01, 0x10, 0x60, 0x36, 0x62, 0x00, 0x64, 0xA2, 0xDB,
0x01, 0x60, 0x00, 0x65, 0x20, 0x44, 0x34, 0x80, 0x64, 0xF5, 0xB9, 0xF1, 0x19, 0xF8, 0x7F, 0xF1,
0x2C, 0xF8, 0x32, 0xF8, 0x80, 0xF1, 0x2D, 0xF8, 0x33, 0xF8, 0x81, 0xF1, 0x2E, 0xF8, 0x34, 0xF8,
0xEA, 0xF1, 0x2F, 0xF8, 0xEB, 0xF1, 0x30, 0xF8, 0xEC, 0xF1, 0x31, 0xF8, 0x11, 0x60, 0x48, 0x64,
0x2A, 0xFA, 0x00, 0x64, 0x2B, 0xFA, 0x23, 0xFA, 0x25, 0x60, 0xCE, 0x64, 0x13, 0x60, 0x0D, 0xFB,
0x66, 0x44, 0x5A, 0xDB, 0x02, 0x64, 0x5A, 0xDB, 0xFF, 0xFF, 0x2B, 0xFF, 0xC1, 0xFE, 0x00, 0x60,
0x01, 0x64, 0x08, 0x60, 0x1C, 0xFB, 0xEA, 0x60, 0xC9, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58,
0xFF, 0xFF, 0x64, 0xF5, 0x23, 0xF2, 0xFF, 0xFF, 0x01, 0x18, 0x82, 0x01, 0x10, 0x67, 0x82, 0xFB,
0x03, 0x64, 0x96, 0xFB, 0xFE, 0x60, 0xFF, 0x65, 0x20, 0x44, 0x24, 0x80, 0x08, 0x60, 0x08, 0xF1,
0x80, 0x60, 0x00, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x10, 0x60, 0x36, 0x62, 0x00, 0x64,
0xA2, 0xDB, 0x81, 0x60, 0x00, 0x64, 0x08, 0x60, 0x1C, 0xFB, 0xEA, 0x60, 0xEA, 0x64, 0x5A, 0xDB,
0xCF, 0xFE, 0x0C, 0x00, 0x08, 0x60, 0x1B, 0xF1, 0x01, 0x60, 0x00, 0x64, 0xA0, 0x80, 0x9C, 0x84,
0x05, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0xEA, 0x60, 0x1F, 0x78, 0xFF, 0xFF, 0x06, 0x60, 0x00, 0x65,
0x20, 0x41, 0x8C, 0xF3, 0xA5, 0x80, 0x01, 0xB0, 0x01, 0x02, 0x06, 0x00, 0x10, 0x60, 0x36, 0x62,
0x00, 0x64, 0xA2, 0xDB, 0x2F, 0x58, 0xFF, 0xFF, 0x1C, 0x60, 0x6E, 0x65, 0xA5, 0xD3, 0x01, 0x63,
0x8A, 0xFD, 0x26, 0x1B, 0x00, 0x60, 0x64, 0x64, 0xA5, 0x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 0x00, 0x64, 0xA2, 0xDB, 0x01, 0x60, 0x46, 0x64, 0x08, 0x60, 0x1C, 0xFB,
0xEB, 0x60, 0x76, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x08, 0x60, 0x1B, 0xF1,
0x01, 0x60, 0x00, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x05, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0xEA, 0x60,
0x1F, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x04, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x45, 0x03, 0xA0, 0x84,
0xA2, 0xDB, 0x08, 0x60, 0x2D, 0xF1, 0x00, 0x60, 0x08, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x0F, 0x03,
0xA0, 0x84, 0xA2, 0xDB, 0x08, 0x60, 0x1B, 0xF1, 0x00, 0x60, 0x02, 0x64, 0xA0, 0x80, 0x9C, 0x84,
0x05, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0xED, 0x60, 0x6D, 0x78, 0xFF, 0xFF, 0x31, 0x01, 0x00, 0x60,
0x02, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x0B, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x16, 0x60, 0xAC, 0xF1,
0x95, 0xF3, 0x00, 0x61, 0xD1, 0x80, 0xF7, 0xB4, 0xF1, 0x03, 0x95, 0xFB, 0x33, 0x00, 0x00, 0x60,
0x10, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x0E, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x16, 0x60, 0xAC, 0xF1,
0x95, 0xF3, 0x00, 0x61, 0xD1, 0x80, 0x08, 0xBC, 0x03, 0x02, 0xEC, 0x60, 0x9C, 0x78, 0xFF, 0xFF,
0x95, 0xFB, 0x20, 0x00, 0x00, 0x60, 0x04, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x05, 0x03, 0xA0, 0x84,
0xA2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 0x1C, 0x60, 0x9E, 0x64,
0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x95, 0xF3, 0xFF, 0xFF,
0x60, 0x40, 0x08, 0x2A, 0x01, 0x00, 0x68, 0x00, 0x08, 0x60, 0x1B, 0xF1, 0x00, 0x60, 0x02, 0x64,
0xA0, 0x80, 0x9C, 0x84, 0x59, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0xED, 0x60, 0x6D, 0x78, 0xFF, 0xFF,
0x08, 0x60, 0x2D, 0xF1, 0x00, 0x60, 0x10, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x08, 0x03, 0xA0, 0x84,
0xA2, 0xDB, 0x95, 0xF3, 0xFF, 0xFF, 0x08, 0xBC, 0x95, 0xFB, 0x2F, 0x58, 0xFF, 0xFF, 0x00, 0x60,
0x02, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x03, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0xA4, 0x01, 0x00, 0x60,
0x04, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x0B, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x1C, 0x60, 0x9E, 0x64,
0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x35, 0x00, 0x00, 0x60,
0x08, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x0B, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x1C, 0x60, 0x9E, 0x64,
0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x1E, 0x00, 0x08, 0x60,
0x1B, 0xF1, 0x00, 0x60, 0x20, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x14, 0x03, 0xA0, 0x84, 0xA2, 0xDB,
0x95, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x08, 0x2A, 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, 0xFF, 0xFF, 0x2B, 0xFF, 0xC1, 0xFE, 0x1C, 0x60, 0xAA, 0x64,
0x13, 0x60, 0x22, 0xFB, 0x02, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0x10, 0x60, 0x36, 0x62,
0x00, 0x64, 0xA2, 0xDB, 0x10, 0x60, 0x5A, 0x62, 0x00, 0x64, 0xA2, 0xDB, 0x03, 0x60, 0x0E, 0x64,
0x08, 0x60, 0x1C, 0xFB, 0xED, 0x60, 0xB8, 0x64, 0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF,
0x08, 0x60, 0x1B, 0xF1, 0x01, 0x60, 0x00, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0x0D, 0x03, 0xA0, 0x84,
0xA2, 0xDB, 0x1C, 0x60, 0xAA, 0x64, 0x13, 0x60, 0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF,
0x04, 0xFF, 0xEA, 0x60, 0x1F, 0x78, 0xFF, 0xFF, 0x00, 0x60, 0x0A, 0x64, 0xA0, 0x80, 0x9C, 0x84,
0x03, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0xCA, 0x01, 0x00, 0x60, 0x04, 0x64, 0xA0, 0x80, 0x9C, 0x84,
0x14, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x08, 0x60, 0x2D, 0xF1, 0x00, 0x60, 0x04, 0x64, 0xA0, 0x80,
0x9C, 0x84, 0x03, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x91, 0x01, 0x00, 0x60, 0x12, 0x64, 0xA0, 0x80,
0x9C, 0x84, 0x03, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0xB1, 0x01, 0x08, 0x60, 0x1B, 0xF1, 0x02, 0x60,
0x00, 0x64, 0xA0, 0x80, 0x9C, 0x84, 0xB2, 0x03, 0xA0, 0x84, 0xA2, 0xDB, 0x10, 0x67, 0x82, 0xFB,
0x10, 0x60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x00, 0xBB, 0xFF, 0xFF, 0x01, 0x02, 0x3B, 0x00, 0x02, 0x60,
0x01, 0x63, 0xA3, 0xD1, 0xDB, 0xF3, 0xFF, 0xFF, 0x07, 0xB4, 0x03, 0x36, 0x1F, 0x00, 0x19, 0x60,
0x45, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x26, 0x09, 0x00, 0x19, 0x60, 0x7B, 0xF3, 0xFF, 0xFF,
0xFD, 0xB4, 0x60, 0x44, 0x64, 0x40, 0x02, 0x27, 0x02, 0xBC, 0xA2, 0xDB, 0x19, 0x60, 0x45, 0xF3,
0xFF, 0xFF, 0x60, 0x40, 0x02, 0x26, 0x1C, 0x00, 0x19, 0x60, 0x7B, 0xF3, 0xFF, 0xFF, 0xFB, 0xB4,
0x60, 0x44, 0x64, 0x40, 0x04, 0x27, 0x04, 0xBC, 0xA2, 0xDB, 0x12, 0x00, 0x64, 0x40, 0x02, 0x2B,
0x06, 0x00, 0x19, 0x60, 0x7B, 0xF3, 0xFF, 0xFF, 0x02, 0xBC, 0x60, 0x44, 0xA2, 0xDB, 0x64, 0x40,
0x04, 0x2B, 0x06, 0x00, 0x19, 0x60, 0x7B, 0xF3, 0xFF, 0xFF, 0x04, 0xBC, 0x60, 0x44, 0xA2, 0xDB,
0x2F, 0x58, 0xFF, 0xFF, 0x0E, 0xF0, 0xDB, 0xF3, 0xFF, 0xFF, 0x07, 0xB4, 0x03, 0x36, 0x18, 0x00,
0x19, 0x60, 0x7B, 0xF3, 0xFF, 0xFF, 0x02, 0xBC, 0x60, 0x44, 0xFB, 0xB4, 0x60, 0x44, 0x64, 0x40,
0x20, 0x2A, 0x0A, 0x00, 0x60, 0x43, 0x19, 0x60, 0x45, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x02, 0x26,
0x02, 0x00, 0x63, 0x44, 0x02, 0x00, 0x63, 0x44, 0x04, 0xBC, 0x19, 0x60, 0x7B, 0xFB, 0x09, 0x00,
0x64, 0x40, 0x20, 0x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, 0x0B, 0x00, 0x04, 0x2A, 0x02, 0x00, 0x02, 0x63,
0x07, 0x00, 0x10, 0x2A, 0x02, 0x00, 0x04, 0x63, 0x03, 0x00, 0x20, 0x2A, 0x01, 0x00, 0x05, 0x63,
0x63, 0x47, 0xB4, 0x83, 0x59, 0xD9, 0x59, 0xDD, 0x1A, 0x60, 0x1E, 0xF3, 0x1A, 0x60, 0x1B, 0xF3,
0xFE, 0xA0, 0x40, 0x4C, 0xD3, 0x03, 0x00, 0x60, 0x00, 0x63, 0x59, 0xDD, 0x41, 0x4A, 0x2C, 0x40,
0x01, 0x2A, 0x05, 0x00, 0x00, 0x63, 0x63, 0x47, 0xB4, 0x83, 0x59, 0xD9, 0x59, 0xDD, 0x2C, 0x40,
0x02, 0x2A, 0x03, 0x00, 0x01, 0x63, 0x59, 0xD9, 0x59, 0xDD, 0x2C, 0x40, 0x04, 0x2A, 0x05, 0x00,
0x02, 0x63, 0x63, 0x47, 0xB4, 0x83, 0x59, 0xD9, 0x59, 0xDD, 0x2C, 0x40, 0x10, 0x2A, 0x05, 0x00,
0x04, 0x63, 0x63, 0x47, 0xB4, 0x83, 0x59, 0xD9, 0x59, 0xDD, 0x2C, 0x40, 0x20, 0x2A, 0x05, 0x00,
0x05, 0x63, 0x63, 0x47, 0xB4, 0x83, 0x59, 0xD9, 0x59, 0xDD, 0x2A, 0x44, 0x51, 0x93, 0xEB, 0x83,
0xEB, 0x83, 0xA0, 0xDD, 0x1A, 0x60, 0x1E, 0xF3, 0x1A, 0x60, 0x1C, 0xF3, 0xFF, 0xA0, 0x40, 0x4C,
0x9D, 0x03, 0x59, 0xDF, 0x41, 0x4A, 0x2C, 0x40, 0x01, 0x2A, 0x05, 0x00, 0x00, 0x63, 0x63, 0x47,
0xB4, 0x83, 0x59, 0xD9, 0x59, 0xDD, 0x2C, 0x40, 0x02, 0x2A, 0x05, 0x00, 0x01, 0x63, 0x63, 0x47,
0xB4, 0x83, 0x59, 0xD9, 0x59, 0xDD, 0x2C, 0x40, 0x04, 0x2A, 0x05, 0x00, 0x02, 0x63, 0x63, 0x47,
0xB4, 0x83, 0x59, 0xD9, 0x59, 0xDD, 0x2A, 0x44, 0x51, 0x93, 0xEB, 0x83, 0xEB, 0x83, 0xA0, 0xDD,
0x2D, 0x58, 0xFF, 0xFF, 0x00, 0x60, 0x04, 0x64, 0x08, 0x60, 0x0A, 0xFB, 0xF0, 0x60, 0x44, 0x64,
0x5A, 0xDB, 0xCF, 0xFE, 0x2F, 0x58, 0xFF, 0xFF, 0x10, 0x60, 0x12, 0x62, 0x00, 0x64, 0xA2, 0xDB,
0x7D, 0xF1, 0x35, 0x60, 0xCC, 0x64, 0x64, 0x40, 0x01, 0x2B, 0x01, 0x00, 0x67, 0x44, 0x1A, 0x60,
0xAF, 0xFB, 0x1A, 0x60, 0xBF, 0xFB, 0x1A, 0x60, 0xE7, 0xF9, 0x35, 0x60, 0x62, 0x65, 0xF1, 0x60,
0x58, 0x4D, 0x74, 0x78, 0xFF, 0xFF, 0x7D, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x01, 0x2B, 0x05, 0x00,
0xFF, 0x60, 0xFF, 0x63, 0x1A, 0x60, 0xB3, 0xFD, 0x08, 0x00, 0x36, 0x60, 0x04, 0x63, 0x1A, 0x60,
0xB3, 0xFD, 0xF1, 0x60, 0x58, 0x4D, 0x8C, 0x78, 0xFF, 0xFF, 0x5C, 0xF5, 0x00, 0xF4, 0x7E, 0xF1,
0x06, 0xF8, 0x1B, 0x60, 0x09, 0xF3, 0x19, 0x60, 0x7B, 0xF1, 0xFB, 0x60, 0xFF, 0x65, 0x60, 0x44,
0xA4, 0x84, 0x60, 0x47, 0x64, 0x40, 0x10, 0x26, 0x04, 0xBC, 0x60, 0x47, 0x07, 0xFA, 0x35, 0x60,
0x5A, 0x64, 0x40, 0x48, 0x10, 0x61, 0x00, 0x60, 0x00, 0x64, 0xF1, 0x60, 0x58, 0x4D, 0x34, 0x78,
0xFF, 0xFF, 0x5C, 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 0x65, 0xFD, 0x60, 0x58, 0x4E,
0xDD, 0x78, 0xFF, 0xFF, 0x61, 0x44, 0x19, 0x60, 0x3F, 0xFB, 0x50, 0x63, 0x2A, 0xFC, 0xC9, 0xF3,
0x19, 0xFA, 0x00, 0x64, 0x3E, 0xFA, 0xA6, 0xF3, 0x07, 0xFA, 0x00, 0xF4, 0x7E, 0xF1, 0x06, 0xF8,
0x1B, 0x60, 0x09, 0xF3, 0x19, 0x60, 0x7B, 0xF1, 0xFB, 0x60, 0xFF, 0xB7, 0x64, 0x40, 0x10, 0x26,
0x04, 0xBC, 0x60, 0x47, 0x07, 0xFA, 0x35, 0x60, 0x82, 0x65, 0xF1, 0x60, 0x58, 0x4D, 0x74, 0x78,
0xFF, 0xFF, 0x7D, 0xF3, 0x36, 0x60, 0x04, 0x63, 0x60, 0x40, 0x01, 0x27, 0x67, 0x43, 0x1A, 0x60,
0xC3, 0xFD, 0x35, 0x60, 0x7A, 0x64, 0x40, 0x48, 0x10, 0x61, 0x00, 0x60, 0x00, 0x64, 0xF1, 0x60,
0x58, 0x4D, 0x34, 0x78, 0xFF, 0xFF, 0x26, 0x46, 0x3F, 0xFC, 0x25, 0x60, 0xCE, 0x64, 0x13, 0x60,
0x0D, 0xFB, 0x26, 0x44, 0x5A, 0xDB, 0x02, 0x64, 0x5A, 0xDB, 0xFF, 0xFF, 0x2B, 0xFF, 0xC1, 0xFE,
0x00, 0x66, 0x46, 0x46, 0x2F, 0x58, 0xFF, 0xFF, 0x00, 0x64, 0x08, 0x60, 0x09, 0xFB, 0x5A, 0xDB,
0x00, 0x64, 0x92, 0xFB, 0x2F, 0x58, 0xFF, 0xFF, 0x1B, 0x60, 0x0A, 0xFB, 0xCD, 0x81, 0x28, 0xD3,
0x5A, 0x88, 0xDC, 0x83, 0x31, 0x18, 0xFB, 0x03, 0x61, 0x40, 0x7F, 0x3A, 0x06, 0x00, 0x1B, 0x60,
0x0A, 0xF3, 0x03, 0x61, 0x7C, 0xA4, 0xA2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0x27, 0xF1, 0x00, 0x60, 0x02, 0x64, 0xB0, 0x84, 0xA2, 0xDB,
0xCF, 0xFE, 0xDB, 0xF3, 0x01, 0x63, 0xFD, 0xA0, 0x08, 0x60, 0x77, 0xFD, 0x07, 0x02, 0x08, 0x60,
0x30, 0xF1, 0x00, 0x60, 0x01, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0xB1, 0x01, 0x0E, 0x57,
0x32, 0x40, 0x40, 0x26, 0x1B, 0x00, 0x45, 0x48, 0x00, 0x60, 0x06, 0x61, 0xB6, 0x60, 0x58, 0x4D,
0x22, 0x78, 0xFF, 0xFF, 0x13, 0x03, 0x02, 0x64, 0x23, 0xFA, 0xF2, 0x60, 0x04, 0x64, 0x5A, 0xDA,
0x28, 0x44, 0x5A, 0xDA, 0xFF, 0xFF, 0x26, 0x60, 0x0A, 0x64, 0x13, 0x60, 0x0D, 0xFB, 0x66, 0x44,
0x5A, 0xDB, 0x02, 0x64, 0x5A, 0xDB, 0xFF, 0xFF, 0x2B, 0xFF, 0xFA, 0xFE, 0x37, 0x58, 0xFF, 0xFF,
0x08, 0x60, 0x15, 0xF1, 0x00, 0x60, 0x02, 0x64, 0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x88, 0x01,
0x12, 0x60, 0xF6, 0xF3, 0xFF, 0xFF, 0x00, 0xA8, 0x60, 0x46, 0x0E, 0xF2, 0x4B, 0x03, 0x60, 0x40,
0xF0, 0x37, 0x38, 0x00, 0xFF, 0x37, 0x2D, 0x00, 0xFD, 0x37, 0x25, 0x00, 0xF8, 0x37, 0x0A, 0x00,
0x60, 0x47, 0xFF, 0xB5, 0x10, 0x60, 0x12, 0x62, 0x46, 0xD1, 0x00, 0x60, 0x01, 0x64, 0xB0, 0x84,
0xA2, 0xDB, 0xCF, 0xFE, 0x00, 0x64, 0x13, 0x60, 0x0D, 0xFB, 0x66, 0x44, 0x5A, 0xDB, 0x02, 0x64,
0x5A, 0xDB, 0xF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0xF9, 0x01, 0x10, 0x60,
0x78, 0x65, 0x5A, 0xDF, 0xD6, 0x80, 0xFF, 0xFF, 0x02, 0x03, 0x5A, 0xDD, 0xFB, 0x01, 0x2F, 0x58,
0xFF, 0xFF, 0x10, 0x60, 0x12, 0x64, 0x40, 0x41, 0x10, 0x60, 0x10, 0x63, 0xA3, 0xD1, 0x00, 0x64,
0xD0, 0x80, 0x0C, 0x61, 0x08, 0x03, 0xBD, 0xDB, 0xA3, 0xD3, 0xFF, 0xFF, 0xB0, 0x84, 0xCD, 0x81,
0xA3, 0xDB, 0x06, 0xA3, 0xF9, 0x02, 0x10, 0x60, 0x60, 0x63, 0xA3, 0xD1, 0x00, 0x64, 0xD0, 0x80,
0x0D, 0x61, 0x19, 0x03, 0xBD, 0xDB, 0x64, 0x44, 0xFE, 0xA3, 0x02, 0xA3, 0xCD, 0x81, 0xE8, 0x84,
0xE3, 0x03, 0x02, 0x05, 0xE1, 0x03, 0xF9, 0x01, 0x97, 0xFB, 0x99, 0xFD, 0x61, 0x5C, 0xA3, 0xD3,
0x98, 0xF9, 0x03, 0x18, 0x58, 0x4F, 0x60, 0x58, 0xFF, 0xFF, 0x99, 0xF3, 0x98, 0xF1, 0x60, 0x43,
0x97, 0xF3, 0x64, 0x41, 0xEA, 0x01, 0x21, 0x43, 0x10, 0x60, 0x5A, 0x65, 0xD7, 0x80, 0xBD, 0xD1,
0xBD, 0xD3, 0x03, 0x02, 0xCA, 0x60, 0xD4, 0x78, 0xFF, 0xFF, 0xA0, 0x84, 0xBD, 0xD1, 0x43, 0x41,
0xF5, 0x03, 0xF3, 0x60, 0xDC, 0x64, 0x64, 0x58, 0x40, 0x4F, 0x2A, 0xF0, 0x83, 0x60, 0xFF, 0x65,
0x64, 0x47, 0x03, 0x2B, 0x01, 0x00, 0x14, 0x00, 0x03, 0x26, 0x03, 0xAC, 0x60, 0x47, 0xA4, 0x84,
0x2A, 0xFA, 0x2F, 0xF2, 0x2C, 0xFA, 0x30, 0xF2,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0A,
0x00, 0xA0, 0x00, 0x64, 0x02, 0x03, 0x51, 0xFB, 0xD9, 0x01, 0x1C, 0x60, 0x7A, 0x64, 0x13, 0x60,
0x22, 0xFB, 0x03, 0x64, 0x4A, 0xDB, 0xFF, 0xFF, 0x04, 0xFF, 0xB7, 0x01, 0x19, 0x60, 0x3E, 0xF3,
0xFD, 0x60, 0x58, 0x4E, 0xAC, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0x3F, 0xFB, 0x19, 0x60, 0x3A, 0xF3,
0x0F, 0x60, 0xFF, 0x65, 0xA4, 0x84, 0xFC, 0x60, 0x58, 0x4E, 0x34, 0x78, 0xFF, 0xFF, 0x5D, 0xF5,
0x35, 0x60, 0x70, 0x64, 0x00, 0xF4, 0x40, 0x48, 0x2F, 0x60, 0x24, 0x64, 0x20, 0x40, 0x10, 0x27,
0x02, 0x00, 0x2F, 0x60, 0x02, 0x64, 0x28, 0xDB, 0x04, 0x61, 0x00, 0x60, 0x00, 0x64, 0xF1, 0x60,
0x58, 0x4D, 0x34, 0x78, 0xFF, 0xFF, 0x5D, 0xF5, 0x3F, 0xFC, 0x53, 0xF3, 0x20, 0x40, 0x10, 0x23,
0x02, 0x00, 0x20, 0xBC, 0x04, 0x00, 0x60, 0x40, 0x01, 0x22, 0x40, 0xBC, 0x04, 0xBC, 0x80, 0xBC,
0x53, 0xFB, 0x11, 0x60, 0x62, 0x64, 0x08, 0x60, 0x6C, 0xFB, 0x06, 0x64, 0x08, 0x60, 0x73, 0xFB,
0x19, 0x60, 0x43, 0xF3, 0xFF, 0xFF, 0x07, 0xB4, 0xA2, 0xDB, 0x53, 0xF3, 0x08, 0x60, 0x6C, 0xF1,
0x60, 0x40, 0x20, 0x26, 0x03, 0x00, 0x01, 0x26, 0x32, 0x00, 0x45, 0x00, 0x08, 0x60, 0x73, 0xF3,
0xFF, 0xFF, 0xDD, 0xA0, 0x01, 0xA4, 0x58, 0x03, 0xA2, 0xDB, 0x32, 0x60, 0x82, 0x61, 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x03, 0x01, 0xA8, 0x61, 0x44, 0x02, 0xA8, 0x15, 0x03, 0x02, 0x02, 0xE9, 0x84, 0x12, 0x00,
0x65, 0x47, 0x60, 0x45, 0x61, 0x44, 0x09, 0x61, 0xCD, 0x81, 0xE0, 0x84, 0xFF, 0x23, 0xFC, 0x01,
0x02, 0x24, 0xC4, 0x84, 0x02, 0x28, 0xD4, 0x84, 0xCD, 0x81, 0x01, 0x0E, 0x01, 0xBC, 0x02, 0x03,
0xE0, 0x84, 0xF6, 0x01, 0x00, 0x7F, 0x2B, 0x41, 0x4D, 0x8B, 0xBF, 0xDB, 0xDD, 0x02, 0x14, 0x60,
0x32, 0x61, 0x88, 0xF3, 0x61, 0x43, 0xC4, 0xA5, 0x47, 0xD1, 0x0A, 0x04, 0xDA, 0x86, 0x1C, 0x60,
0x30, 0x63, 0xC3, 0x83, 0xC3, 0x83, 0xC3, 0x83, 0x43, 0xD1, 0xA6, 0xD9, 0x65, 0x44, 0xF2, 0x01,
0x53, 0xF3, 0x88, 0xF1, 0xF3, 0xB4, 0x53, 0xFB, 0x14, 0x60, 0x32, 0x63, 0xC3, 0x85, 0x45, 0x4A,
0x1B, 0x60, 0xB2, 0x65, 0x87, 0xF3, 0x45, 0x4C, 0x40, 0x48, 0x2A, 0x45, 0xD7, 0x80, 0x02, 0x65,
0x17, 0x05, 0x47, 0xD1, 0x02, 0x65, 0x47, 0xD3, 0x0A, 0x65, 0xD0, 0x81, 0x47, 0xD3, 0x01, 0x05,
0x00, 0x61, 0xF2, 0xA3, 0x01, 0xB0, 0x61, 0x44, 0x05, 0x03, 0x2C, 0xDB, 0x5A, 0xDD, 0x5A, 0x8C,
0x3C, 0xA3, 0xEB, 0x01, 0x28, 0x42, 0x4A, 0xDD, 0x4A, 0xDB, 0x42, 0x48, 0x3C, 0xA3, 0xE5, 0x01,
0x28, 0x44, 0x86, 0xFB, 0x86, 0xF1, 0x1B, 0x60, 0xB2, 0x63, 0x44, 0x48, 0x28, 0x45, 0xD7, 0x80,
0xA3, 0xD1, 0x15, 0x05, 0x04, 0x65, 0x46, 0xD3, 0x28, 0x45, 0xD6, 0x80, 0xD0, 0x80, 0x02, 0x04,
0x04, 0xA3, 0xF5, 0x01, 0xF7, 0x06, 0x62, 0x46, 0xA2, 0xD9, 0xA3, 0xDB, 0x5B, 0xD3, 0x66, 0x42,
0x5A, 0xD1, 0xA2, 0xDB, 0xA3, 0xD9, 0xFE, 0xA3, 0xA3, 0xD1, 0x66, 0x42, 0xEB, 0x01, 0x86, 0xF3,
0x87, 0xF1, 0x60, 0x43, 0x44, 0x48, 0x28, 0x45, 0xD7, 0x80, 0xA3, 0xD1, 0x15, 0x05, 0x04, 0x65,
0x46, 0xD3, 0x28, 0x45, 0xD6, 0x80, 0xD0, 0x80, 0x02, 0x04, 0x04, 0xA3, 0xF5, 0x01, 0xF7, 0x06,
0x62, 0x46, 0xA2, 0xD9, 0xA3, 0xDB, 0x5B, 0xD3, 0x66, 0x42, 0x5A, 0xD1, 0xA2, 0xDB, 0xA3, 0xD9,
0xFE, 0xA3, 0xA3, 0xD1, 0x66, 0x42, 0xEB, 0x01, 0x08, 0x60, 0x08, 0xF1, 0x10, 0x60, 0x00, 0x64,
0xB0, 0x84, 0xA2, 0xDB, 0xCF, 0xFE, 0x7D, 0xF1, 0x19, 0x60, 0x3D, 0xF3, 0x64, 0x40, 0x01, 0x27,
0x27, 0x00, 0xFD, 0x60, 0x58, 0x4E, 0xAC, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0x3F, 0xFB, 0x19, 0x60,
0x39, 0xF3, 0x3F, 0x40, 0x01, 0x27, 0x16, 0x00, 0x0F, 0x60, 0xFF, 0x65, 0x60, 0x41, 0xDB, 0xF3,
0xFF, 0xFF, 0x60, 0x40, 0x03, 0x36, 0x07, 0x00, 0x19, 0x60, 0x44, 0xF3, 0xFF, 0xFF, 0x60, 0x40,
0x01, 0x2A, 0x01, 0x00, 0x0F, 0x61, 0x61, 0x44, 0xA4, 0x84, 0xF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0x78, 0xFF, 0xFF,
0x5D, 0xD0, 0xFF, 0xFF, 0x64, 0x40, 0x00, 0x36, 0x04, 0x00, 0xF9, 0xA1, 0xF9, 0x60, 0x6B, 0x78,
0xFF, 0xFF, 0x60, 0x5C, 0x00, 0x36, 0x32, 0x00, 0x00, 0x64, 0xFB, 0x60, 0x58, 0x4E, 0x66, 0x78,
0xFF, 0xFF, 0x65, 0x40, 0x08, 0x26, 0xF7, 0x01, 0x1A, 0x60, 0x24, 0xFB, 0x64, 0x40, 0x00, 0x36,
0x2A, 0x00, 0x5D, 0xD2, 0xDD, 0x81, 0xFB, 0x60, 0x58, 0x4E, 0x66, 0x78, 0xFF, 0xFF, 0x65, 0x40,
0x08, 0x26, 0xF6, 0x01, 0x1A, 0x60, 0x25, 0xFB, 0x64, 0x40, 0x00, 0x36, 0x21, 0x00, 0x5D, 0xD2,
0xDD, 0x81, 0xFB, 0x60, 0x58, 0x4E, 0x66, 0x78, 0xFF, 0xFF, 0x65, 0x40, 0x08, 0x26, 0xF6, 0x01,
0x1A, 0x60, 0x26, 0xFB, 0x64, 0x40, 0x00, 0x36, 0x18, 0x00, 0x5D, 0xD0, 0x34, 0x60, 0x4E, 0x62,
0xA2, 0xD9, 0x5D, 0xD0, 0x34, 0x60, 0x4F, 0x62, 0xA2, 0xD9, 0x14, 0x00, 0x20, 0xFE, 0x00, 0x60,
0x04, 0x64, 0x1A, 0x60, 0x24, 0xFB, 0x20, 0xFE, 0x00, 0x60, 0x04, 0x64, 0x1A, 0x60, 0x25, 0xFB,
0x20, 0xFE, 0x00, 0x60, 0x02, 0x64, 0x1A, 0x60, 0x26, 0xFB, 0x20, 0xFE, 0x00, 0x60, 0x00, 0x64,
0x1A, 0x60, 0x27, 0xFB, 0x20, 0xFE, 0x1C, 0x60, 0x08, 0xF1, 0xFF, 0xFF, 0x03, 0x18, 0x01, 0x7C,
0x1C, 0x60, 0x08, 0xF9, 0x1A, 0x60, 0x2B, 0xF1, 0xA2, 0xDD, 0x61, 0x44, 0x1A, 0x60, 0x28, 0xFB,
0xD1, 0x84, 0xDC, 0x84, 0x64, 0x45, 0x34, 0x60, 0x10, 0x63, 0xBD, 0xDB, 0x60, 0x41, 0xCD, 0x84,
0x4C, 0x91, 0x60, 0x43, 0x60, 0xFE, 0xA5, 0xD2, 0xDE, 0x85, 0x7F, 0x26, 0x02, 0x00, 0x00, 0xF4,
0x04, 0x65, 0x5D, 0x93, 0xA3, 0xDB, 0x5D, 0x93, 0xA5, 0xD2, 0xF6, 0x1F, 0x5D, 0x93, 0x20, 0xFE,
0xDF, 0x83, 0x1A, 0x60, 0x09, 0xF3, 0xFF, 0xFF, 0x60, 0x47, 0xA2, 0xDB, 0x1A, 0x60, 0x28, 0xF3,
0x1A, 0x60, 0x2B, 0xF1, 0x60, 0x41, 0x64, 0x43, 0xF9, 0x60, 0x56, 0x78, 0xFF, 0xFF, 0x20, 0xFE,
0x7C, 0x44, 0x1A, 0x60, 0x20, 0xFB, 0x1A, 0x60, 0x1A, 0xF1, 0x1A, 0x60, 0x24, 0xF3, 0xFF, 0xFF,
0xA0, 0x84, 0xFF, 0xFF, 0x10, 0x26, 0x07, 0x00, 0x04, 0x26, 0x07, 0x00, 0x20, 0x26, 0x07, 0x00,
0x02, 0x26, 0x07, 0x00, 0x3F, 0x00, 0x10, 0x7C, 0x05, 0x00, 0x04, 0x7C, 0x03, 0x00, 0x20, 0x7C,
0x01, 0x00, 0x02, 0x7C, 0x1A, 0x60, 0x20, 0xF9, 0x7C, 0x44, 0x1A, 0x60, 0x21, 0xFB, 0x1A, 0x60,
0x1B, 0xF1, 0x1A, 0x60, 0x25, 0xF3, 0x34, 0x60, 0x40, 0x61, 0xA0, 0x84, 0xA1, 0xD1, 0xFF, 0xFF,
0x10, 0x26, 0x05, 0x00, 0x04, 0x26, 0x05, 0x00, 0x01, 0x26, 0x08, 0x00, 0x23, 0x00, 0x10, 0x7C,
0x06, 0x00, 0x64, 0x40, 0x10, 0x26, 0x1E, 0x00, 0x04, 0x7C, 0x01, 0x00, 0x01, 0x7C, 0x1A, 0x60,
0x21, 0xF9, 0x7C, 0x44, 0x1A, 0x60, 0x22, 0xFB, 0x1A, 0x60, 0x1C, 0xF1, 0x1A, 0x60, 0x26, 0xF3,
0xFF, 0xFF, 0xA0, 0x84, 0x60, 0x40, 0x02, 0x26, 0x05, 0x00, 0x04, 0x26, 0x05, 0x00, 0x01, 0x26,
0x05, 0x00, 0x08, 0x00, 0x02, 0x7C, 0x03, 0x00, 0x04, 0x7C, 0x01, 0x00, 0x20, 0x7C, 0x1A, 0x60,
0x22, 0xF9, 0x09, 0x00, 0x7C, 0x44, 0x1A, 0x60, 0x20, 0xFB, 0x1A, 0x60, 0x21, 0xFB, 0x1A, 0x60,
0x22, 0xFB, 0x1A, 0x60, 0x23, 0xFB, 0x7C, 0x44, 0x1A, 0x60, 0x20, 0xF1, 0xBD, 0xD9, 0x1A, 0x60,
0x21, 0xF1, 0xB0, 0x84, 0xBD, 0xD9, 0x1A, 0x60, 0x22, 0xF1, 0xB0, 0x84, 0xBD, 0xD9, 0x1A, 0x60,
0x1D, 0xF1, 0xB0, 0x84, 0xBD, 0xD9, 0x04, 0x03, 0x1C, 0x60, 0x08, 0xF1, 0xBD, 0xD9, 0x72, 0x00,
0x16, 0x60, 0xC2, 0xF3, 0xFF, 0xFF, 0xFF, 0xA0, 0xFF, 0xFF, 0x0C, 0x24, 0x6B, 0x00, 0x60, 0x40,
0x0B, 0x36, 0x68, 0x00, 0x20, 0x40, 0x10, 0x27, 0x65, 0x00, 0x91, 0x00, 0x20, 0xFE, 0x00, 0x65,
0x60, 0xFE, 0x1A, 0x60, 0x28, 0xFB, 0xE0, 0x84, 0xE0, 0x84, 0x08, 0x20, 0x03, 0x00, 0x01, 0x64,
0xA2, 0xDB, 0x02, 0x64, 0x02, 0xA5, 0x64, 0x44, 0xD4, 0x9C, 0xD4, 0x80, 0x34, 0x60, 0x52, 0x62,
0x02, 0x05, 0x08, 0x65, 0x4D, 0x00, 0xA2, 0xD9, 0x7C, 0x44, 0x34, 0x60, 0x54, 0x62, 0xA2, 0xDB,
0x20, 0xFE, 0x00, 0x64, 0x60, 0xFE, 0x1C, 0x60, 0x08, 0xF3, 0xFF, 0xFF, 0x00, 0xA0, 0x5D, 0xD0,
0x00, 0x65, 0x04, 0x03, 0x64, 0x40, 0x00, 0x3A, 0x01, 0x65, 0x03, 0x00, 0x64, 0x40, 0x00, 0x3A,
0x01, 0x65, 0x5D, 0xD0, 0x04, 0x03, 0x64, 0x40, 0x0F, 0x3A, 0x01, 0x65, 0x03, 0x00, 0x64, 0x40,
0x50, 0x3A, 0x01, 0x65, 0x5D, 0xD0, 0x04, 0x03, 0x64, 0x40, 0xAC, 0x3A, 0x01, 0x65, 0x03, 0x00,
0x64, 0x40, 0xF2, 0x3A, 0x01, 0x65, 0x5D, 0xD0, 0x65, 0x40, 0x00, 0x3A, 0x17, 0x00, 0x00, 0x60,
0x00, 0x65, 0x64, 0x40, 0x00, 0x36, 0x01, 0x65, 0x64, 0x40, 0x01, 0x36, 0x02, 0x65, 0x64, 0x40,
0x02, 0x36, 0x04, 0x65, 0x64, 0x40, 0x04, 0x36, 0x10, 0x65, 0x64, 0x40, 0x05, 0x36, 0x20, 0x65,
0x65, 0x5C, 0x1A, 0x60, 0x2A, 0xF3, 0xFF, 0xFF, 0xB0, 0x84, 0xA2, 0xDB, 0x1A, 0x60, 0x28, 0xF3,
0x00, 0x65, 0xFF, 0xA4, 0xA2, 0xDB, 0xBC, 0x02, 0x1A, 0x60, 0x2A, 0xF3, 0x1A, 0x60, 0x29, 0xF1,
0x2E, 0x58, 0xFF, 0xFF, 0x20, 0xFE, 0x88, 0xF3, 0xFF, 0xFF, 0x3C, 0xA4, 0x88, 0xFB, 0x87, 0xF3,
0x7D, 0xF1, 0x04, 0xA4, 0x87, 0xFB, 0x53, 0xF3, 0xFF, 0xFF, 0x60, 0x40, 0x80, 0x26, 0x0D, 0x00,
0x7D, 0xF3, 0x10, 0x60, 0xF2, 0x61, 0xCC, 0x84, 0xFF, 0xFF, 0x02, 0x03, 0x06, 0xA1, 0xFB, 0x01,
0xA1, 0xD3, 0xFF, 0xFF, 0x02, 0xBC, 0xA1, 0xDB, 0x12, 0x00, 0x7D, 0xF3, 0x11, 0x60, 0x60, 0x63,
0x01, 0x60, 0xFF, 0x65, 0xA4, 0x84, 0x12, 0x60, 0x40, 0x65, 0xA3, 0xD1, 0xD7, 0x80, 0xD0, 0x80,
0x06, 0x03, 0x02, 0x03, 0x08, 0xA3, 0xF9, 0x01, 0x02, 0xA3, 0x04, 0x64, 0xA3, 0xDB, 0x20, 0xFE,
0x26, 0x46, 0x31, 0x40, 0x20, 0x2A, 0x35, 0x00, 0x3F, 0xF2, 0x47, 0x65, 0xC4, 0x84, 0xE8, 0x84,
0x23, 0xFA, 0xF1, 0x60, 0x02, 0x64, 0x24, 0xFA, 0x7D, 0xF3, 0x01, 0x60, 0xFF, 0x65, 0xA4, 0x84,
0x01, 0x23, 0x14, 0x00, 0x11, 0x60, 0x60, 0x61, 0x12, 0x60, 0x40, 0x65, 0xA1, 0xD1, 0xD5, 0x80,
0xD0, 0x80, 0x0B, 0x03, 0x02, 0x03, 0x08, 0xA1, 0xF9, 0x01, 0x04, 0xA1, 0xA1, 0xD3, 0x01, 0x60,
0x00, 0x65, 0x60, 0x47, 0xFF, 0xB4, 0xB4, 0x84, 0x01, 0x00, 0x01, 0x64, 0x00, 0xF4, 0x08, 0xFA,
0xFF, 0xFF, 0x26, 0x46, 0x26, 0x60, 0x0A, 0x64, 0x13, 0x60, 0x0D, 0xFB, 0x26, 0x44, 0x5A, 0xDB,
0x02, 0x64, 0x5A, 0xDB, 0xFF, 0xFF, 0x2B, 0xFF, 0xFA, 0xFE, 0x00, 0x66, 0x46, 0x46, 0x2F, 0x58,
0xFF, 0xFF, 0x26, 0x46, 0x2F, 0x58, 0xFF, 0xFF, 0x78, 0xFB, 0xAC, 0x85, 0x60, 0x41, 0x55, 0x03,
0x32, 0x60, 0x00, 0x63, 0x1B, 0x60, 0x04, 0xFD, 0x62, 0x43, 0x1A, 0x60, 0xB4, 0xFD, 0x1A, 0x60,
0xBA, 0xFD, 0x1A, 0x60, 0xC4, 0xFD, 0x1A, 0x60, 0xCE, 0xFD, 0x00, 0x63, 0xE9, 0x81, 0x08, 0x64,
0x02, 0x24, 0xDF, 0x83, 0xFB, 0x02, 0x53, 0x94, 0x32, 0x7F, 0x03, 0x06, 0x1B, 0x60, 0x04, 0xFB,
0x08, 0x63, 0x63, 0x5E, 0x01, 0x7F, 0x19, 0x60, 0x8A, 0xFB, 0x65, 0x41, 0x33, 0x60, 0x16, 0x65,
0x0F, 0x60, 0xF4, 0x64, 0xE9, 0x81, 0x58, 0xD1, 0xFD, 0x04, 0xCF, 0x83, 0xA5, 0xD9, 0x0C, 0x03,
0xE9, 0x81, 0x58, 0xD1, 0xFD, 0x04, 0x40, 0x48, 0xA5, 0xD1, 0x64, 0x5F, 0x64, 0x5E, 0xA5, 0xDB,
0xDA, 0x85, 0xCF, 0x83, 0x28, 0x44, 0xEE, 0x02, 0x00, 0xB9, 0xD8, 0x83, 0x15, 0x03, 0x36, 0x60,
0x0A, 0x65, 0xE9, 0x81, 0xBD, 0xD1, 0x02, 0x05, 0xFC, 0x02, 0x17, 0x00, 0xA5, 0xD9, 0x15, 0x03,
0xE9, 0x81, 0xBD, 0xD1, 0x02, 0x05, 0xFC, 0x02, 0x10, 0x00, 0xA5, 0xD3, 0xFF, 0xFF, 0x64, 0x5F,
0xA5, 0xDB, 0xDA, 0x85, 0xEE, 0x02, 0x09, 0x00, 0x67, 0x43, 0x1A, 0x60, 0xB4, 0xFD, 0x1A, 0x60,
0xBA, 0xFD, 0x1A, 0x60, 0xC4, 0xFD, 0x1A, 0x60, 0xCE, 0xFD, 0x2E, 0x45, 0x25, 0x60, 0x46, 0x64,
0xD4, 0x80, 0xFF, 0xFF, 0x10, 0x03, 0x20, 0x40, 0x10, 0x27, 0x0D, 0x00, 0x33, 0x60, 0x1E, 0x61,
0x19, 0x60, 0x8A, 0xF3, 0xA1, 0xDB, 0xFF, 0xB4, 0xCC, 0x84, 0xA8, 0x83, 0x33, 0x60, 0x14, 0x64,
0x58, 0xD1, 0x59, 0xD9, 0xFD, 0x1F, 0x7D, 0xF3, 0x33, 0x60, 0x20, 0x63, 0x60, 0x40, 0x01, 0x27,
0x03, 0x00, 0x19, 0x60, 0x3B, 0xF3, 0x02, 0x00, 0x19, 0x60, 0x3C, 0xF3, 0x08, 0x61, 0x60, 0xFE,
0xA3, 0xD1, 0xFF, 0xFF, 0x20, 0xFE, 0x00, 0xA8, 0xE8, 0x84, 0x0F, 0x03, 0x60, 0xFE, 0x02, 0x28,
0xF6, 0x01, 0x80, 0x62, 0xB2, 0x9C, 0xBD, 0xD9, 0x7B, 0xF9, 0xCD, 0x81, 0x00, 0x36, 0x01, 0x00,
0xEE, 0x01, 0x36, 0x60, 0x0A, 0x63, 0x08, 0x61, 0xEA, 0x01, 0x2E, 0x58, 0xFF, 0xFF, 0x32, 0x60,
0x76, 0x63, 0x65, 0x40, 0xFF, 0x36, 0x02, 0xA3, 0xA3, 0xD3, 0xFF, 0xFF, 0xE8, 0x84, 0xE8, 0x84,
0xE8, 0x84, 0xE8, 0x84, 0x40, 0x26, 0x7F, 0xB4, 0x20, 0x26, 0x3F, 0xB4, 0x60, 0x45, 0x80, 0x63,
0xFD, 0x60, 0x58, 0x4D, 0x34, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0x7D, 0xFB, 0x40, 0x63, 0xFD, 0x60,
0x58, 0x4D, 0x34, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0x7E, 0xFB, 0x20, 0x63, 0xFD, 0x60, 0x58, 0x4D,
0x34, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0x7F, 0xFB, 0x10, 0x63, 0xFD, 0x60, 0x58, 0x4D, 0x34, 0x78,
0xFF, 0xFF, 0x19, 0x60, 0x80, 0xFB, 0x08, 0x63, 0xFD, 0x60, 0x58, 0x4D, 0x34, 0x78, 0xFF, 0xFF,
0x19, 0x60, 0x81, 0xFB, 0x04, 0x63, 0xFD, 0x60, 0x58, 0x4D, 0x34, 0x78, 0xFF, 0xFF, 0x19, 0x60,
0x82, 0xFB, 0x02, 0x63, 0xFD, 0x60, 0x58, 0x4D, 0x34, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0x83, 0xFB,
0x01, 0x63, 0xFD, 0x60, 0x58, 0x4D, 0x34, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0x84, 0xFB, 0x2E, 0x58,
0xFF, 0xFF, 0x19, 0x60, 0x3B, 0xF3, 0xFF, 0xFF, 0x0F, 0xB4, 0x60, 0x45, 0x08, 0x63, 0xFD, 0x60,
0x58, 0x4D, 0x5F, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0x85, 0xFB, 0x04, 0x63, 0xFD, 0x60, 0x58, 0x4D,
0x5F, 0x78, 0xFF, 0xFF, 0x19, 0x60, 0x86, 0xFB, 0x02, 0x63, 0xFD, 0x60, 0x58, 0x4D, 0x5F, 0x78,
0xFF, 0xFF, 0x19, 0x60, 0x87, 0xFB, 0x01, 0x63, 0xFD, 0x60, 0x58, 0x4D, 0x5F, 0x78, 0xFF, 0xFF,
0x19, 0x60, 0x88, 0xFB, 0x2E, 0x58, 0xFF, 0xFF, 0x63, 0x5C, 0xA7, 0x84, 0xEB, 0x83, 0x14, 0x02,
0x01, 0x03, 0xFB, 0x01, 0x64, 0x44, 0x01, 0x36, 0x0B, 0x64, 0x02, 0x36, 0x0B, 0x64, 0x04, 0x36,
0x0A, 0x64, 0x08, 0x36, 0x0A, 0x64, 0x10, 0x36, 0x09, 0x64, 0x20, 0x36, 0x09, 0x64, 0x40, 0x36,
0x09, 0x64, 0x80, 0x36, 0x09, 0x64, 0x11, 0x00, 0x60, 0x40, 0x01, 0x36, 0x0B, 0x64, 0x02, 0x36,
0x0F, 0x64, 0x04, 0x36, 0x0A, 0x64, 0x08, 0x36, 0x0E, 0x64, 0x10, 0x36, 0x09, 0x64, 0x20, 0x36,
0x0D, 0x64, 0x40, 0x36, 0x08, 0x64, 0x80, 0x36, 0x0C, 0x64, 0x2D, 0x58, 0xFF, 0xFF, 0x63, 0x5C,
0xA7, 0x84, 0xEB, 0x83, 0x0C, 0x02, 0x01, 0x03, 0xFB, 0x01, 0x64, 0x44, 0x01, 0x36, 0x0A, 0x64,
0x02, 0x36, 0x14, 0x64, 0x04, 0x36, 0x37, 0x64, 0x08, 0x36, 0x6E, 0x64, 0x09, 0x00, 0x60, 0x40,
0x01, 0x36, 0x0A, 0x64, 0x02, 0x36, 0x14, 0x64, 0x04, 0x36, 0x37, 0x64, 0x08, 0x36, 0x6E, 0x64,
0x2D, 0x58, 0xFF, 0xFF, 0x60, 0xFE, 0x81, 0xA1, 0x7F, 0xA1, 0x02, 0x06, 0x00, 0xF4, 0x03, 0x61,
0x5D, 0xD2, 0xCF, 0x83, 0xD4, 0x80, 0x25, 0x03, 0x16, 0x03, 0xCF, 0x83, 0x61, 0x44, 0x80, 0xA0,
0x20, 0x03, 0x02, 0x02, 0x00, 0xF4, 0x03, 0x61, 0x5D, 0xD2, 0xCF, 0x83, 0x81, 0xA1, 0x19, 0x03,
0x05, 0x07, 0x7F, 0xA1, 0xCC, 0x84, 0xDD, 0x81, 0xE6, 0x03, 0xF7, 0x01, 0x00, 0xF4, 0x00, 0xB8,
0x04, 0x61, 0xE6, 0x03, 0xF2, 0x01, 0x2C, 0x43, 0x5D, 0xD0, 0xDE, 0xD9, 0x64, 0x44, 0x5D, 0xD0,
0xDE, 0xD9, 0xCC, 0x84, 0x81, 0xA1, 0x05, 0x03, 0x7F, 0xA1, 0xF9, 0x04, 0x00, 0xF4, 0x03, 0x61,
0xF6, 0x01, 0x20, 0xFE, 0x2E, 0x58, 0xFF, 0xFF, 0x01, 0x3A, 0x02, 0x00, 0x16, 0x64, 0x2B, 0x00,
0x02, 0x3A, 0x02, 0x00, 0x14, 0x64, 0x27, 0x00, 0x04, 0x3A, 0x02, 0x00, 0x12, 0x64, 0x23, 0x00,
0x08, 0x3A, 0x02, 0x00, 0x10, 0x64, 0x1F, 0x00, 0x10, 0x3A, 0x02, 0x00, 0x0E, 0x64, 0x1B, 0x00,
0x20, 0x3A, 0x02, 0x00, 0x0C, 0x64, 0x17, 0x00, 0x40, 0x3A, 0x02, 0x00, 0x0A, 0x64, 0x13, 0x00,
0x80, 0x3A, 0x02, 0x00, 0x08, 0x64, 0x0F, 0x00, 0x01, 0x3B, 0x02, 0x00, 0x06, 0x64, 0x0B, 0x00,
0x02, 0x3B, 0x02, 0x00, 0x04, 0x64, 0x07, 0x00, 0x04, 0x3B, 0x02, 0x00, 0x02, 0x64, 0x03, 0x00,
0x08, 0x3B, 0xFF, 0x01, 0x00, 0x64, 0x2E, 0x58, 0xFF, 0xFF, 0x27, 0xF2, 0xFF, 0xFF, 0x60, 0x40,
0x36, 0x3A, 0x02, 0x00, 0x00, 0x61, 0x30, 0x00, 0x30, 0x3A, 0x02, 0x00, 0x02, 0x61, 0x2C, 0x00,
0x24, 0x3A, 0x02, 0x00, 0x04, 0x61, 0x28, 0x00, 0x18, 0x3A, 0x02, 0x00, 0x06, 0x61, 0x24, 0x00,
0x12, 0x3A, 0x02, 0x00, 0x08, 0x61, 0x20, 0x00, 0x0C, 0x3A, 0x02, 0x00, 0x0A, 0x61, 0x1C, 0x00,
0x09, 0x3A, 0x02, 0x00, 0x0C, 0x61, 0x18, 0x00, 0x06, 0x3A, 0x02, 0x00, 0x0E, 0x61, 0x14, 0x00,
0x6E, 0x3A, 0x02, 0x00, 0x10, 0x61, 0x10, 0x00, 0x37, 0x3A, 0x02, 0x00, 0x12, 0x61, 0x0C, 0x00,
0x14, 0x3A, 0x02, 0x00, 0x14, 0x61, 0x08, 0x00, 0x0A, 0x3A, 0x02, 0x00, 0x16, 0x61, 0x04, 0x00,
0x78, 0x43, 0x03, 0x61, 0x29, 0x60, 0xEA, 0x78, 0x65, 0x40, 0x01, 0x3A, 0x13, 0x00, 0x66, 0x45,
0x2B, 0x46, 0x92, 0xFA, 0x65, 0x46, 0x26, 0xF2, 0xFF, 0xFF, 0x60, 0x41, 0x00, 0x7F, 0x60, 0x45,
0x61, 0x47, 0x00, 0x7F, 0xD4, 0x84, 0x66, 0x41, 0x2B, 0x46, 0x0E, 0xF2, 0x60, 0x45, 0x65, 0x5E,
0x0E, 0xFA, 0x61, 0x46, 0x2E, 0x58, 0xFF, 0xFF, 0xCD, 0x81, 0x7F, 0xB4, 0x02, 0x3A, 0x02, 0x00,
0x01, 0x64, 0x32, 0x00, 0x04, 0x3A, 0x02, 0x00, 0x02, 0x64, 0x2E, 0x00, 0x0B, 0x3A, 0x02, 0x00,
0x04, 0x64, 0x2A, 0x00, 0x16, 0x3A, 0x02, 0x00, 0x08, 0x64, 0x26, 0x00, 0x0C, 0x3A, 0x02, 0x00,
0x10, 0x64, 0x22, 0x00, 0x12, 0x3A, 0x02, 0x00, 0x20, 0x64, 0x1E, 0x00, 0x18, 0x3A, 0x02, 0x00,
0x40, 0x64, 0x1A, 0x00, 0x24, 0x3A, 0x02, 0x00, 0x80, 0x64, 0x16, 0x00, 0x30, 0x3A, 0x03, 0x00,
0x00, 0x7E, 0x01, 0x7F, 0x11, 0x00, 0x48, 0x3A, 0x03, 0x00, 0x00, 0x7E, 0x02, 0x7F, 0x0C, 0x00,
0x60, 0x3A, 0x03, 0x00, 0x00, 0x7E, 0x04, 0x7F, 0x07, 0x00, 0x6C, 0x3A, 0x03, 0x00, 0x00, 0x7E,
0x08, 0x7F, 0x02, 0x00, 0x00, 0x64, 0x00, 0x00, 0x20, 0xFE, 0x2A, 0x45, 0x34, 0x8A, 0x60, 0xFE,
0x61, 0x40, 0x00, 0x36, 0x02, 0x00, 0xBD, 0xD3, 0xBF, 0x01, 0x2E, 0x58, 0xFF, 0xFF,
}; /* fw_image_4_data */
static const CFG_IDENTITY_STRCT fw_image_infoidentity[] = {
{
sizeof( CFG_IDENTITY_STRCT ) / sizeof(hcf_16) - 1,
CFG_FW_IDENTITY,
COMP_ID_FW_STA,
4, //Variant
1, //Major
36 //Minor
},
{ 0000, 0000, 0000, 0000, 0000, 0000 } //endsentinel
};
static const CFG_PROG_STRCT fw_image_code[] = {
{
8,
CFG_PROG,
CFG_PROG_VOLATILE, // mode
0x0184, // sizeof(fw_image_1_data),
0x00000060, // Target address in NIC Memory
0x0000, // CRC: yes/no TYPE: primary/station/tertiary
(hcf_8 FAR *) fw_image_1_data
},
{
8,
CFG_PROG,
CFG_PROG_VOLATILE, // mode
0x2c0e, // sizeof(fw_image_2_data),
0x00000C16, // Target address in NIC Memory
0x0000, // CRC: yes/no TYPE: primary/station/tertiary
(hcf_8 FAR *) fw_image_2_data
},
{
8,
CFG_PROG,
CFG_PROG_VOLATILE, // mode
0x54de, // sizeof(fw_image_3_data),
0x001E3824, // Target address in NIC Memory
0x0000, // CRC: yes/no TYPE: primary/station/tertiary
(hcf_8 FAR *) fw_image_3_data
},
{
8,
CFG_PROG,
CFG_PROG_VOLATILE, // mode
0xbcde, // sizeof(fw_image_4_data),
0x001F4000, // Target address in NIC Memory
0x0000, // CRC: yes/no TYPE: primary/station/tertiary
(hcf_8 FAR *) fw_image_4_data
},
{
5,
CFG_PROG,
CFG_PROG_STOP, // mode
0000,
0x000F429B, // Start execution address
},
{ 0000, 0000, 0000, 0000, 00000000, 0000, 00000000}
};
static const CFG_RANGE20_STRCT fw_image_infocompat[] = {
{ 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)),
CFG_FW_SUP_RANGE,
COMP_ROLE_SUPL,
COMP_ID_STA,
{
{ 4, 1, 2 } //variant, bottom, top
}
},
{ 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)),
CFG_MFI_ACT_RANGES_STA,
COMP_ROLE_ACT,
COMP_ID_MFI,
{
{ 7, 3, 3 }, //variant, bottom, top
{ 8, 1, 1 } //variant, bottom, top
}
},
{ 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)),
CFG_CFI_ACT_RANGES_STA,
COMP_ROLE_ACT,
COMP_ID_CFI,
{
{ 4, 1, 2 } //variant, bottom, top
}
},
{ 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } //endsentinel
};
memimage fw_image = {
"FUPU7D37dhfwci\001C", //signature, <format number>, C/Bin type
(CFG_PROG_STRCT *) fw_image_code,
0x000F429B,
00000000, //(dummy) pdaplug
00000000, //(dummy) priplug
(CFG_RANGE20_STRCT *) fw_image_infocompat,
(CFG_IDENTITY_STRCT *) fw_image_infoidentity,
};
| gpl-2.0 |
voltagex/msm | arch/ia64/kernel/acpi-ext.c | 11779 | 2798 | /*
* (c) Copyright 2003, 2006 Hewlett-Packard Development Company, L.P.
* Alex Williamson <alex.williamson@hp.com>
* Bjorn Helgaas <bjorn.helgaas@hp.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/acpi.h>
#include <asm/acpi-ext.h>
/*
* Device CSRs that do not appear in PCI config space should be described
* via ACPI. This would normally be done with Address Space Descriptors
* marked as "consumer-only," but old versions of Windows and Linux ignore
* the producer/consumer flag, so HP invented a vendor-defined resource to
* describe the location and size of CSR space.
*/
struct acpi_vendor_uuid hp_ccsr_uuid = {
.subtype = 2,
.data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
};
static acpi_status hp_ccsr_locate(acpi_handle obj, u64 *base, u64 *length)
{
acpi_status status;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
struct acpi_resource *resource;
struct acpi_resource_vendor_typed *vendor;
status = acpi_get_vendor_resource(obj, METHOD_NAME__CRS, &hp_ccsr_uuid,
&buffer);
resource = buffer.pointer;
vendor = &resource->data.vendor_typed;
if (ACPI_FAILURE(status) || vendor->byte_length < 16) {
status = AE_NOT_FOUND;
goto exit;
}
memcpy(base, vendor->byte_data, sizeof(*base));
memcpy(length, vendor->byte_data + 8, sizeof(*length));
exit:
kfree(buffer.pointer);
return status;
}
struct csr_space {
u64 base;
u64 length;
};
static acpi_status find_csr_space(struct acpi_resource *resource, void *data)
{
struct csr_space *space = data;
struct acpi_resource_address64 addr;
acpi_status status;
status = acpi_resource_to_address64(resource, &addr);
if (ACPI_SUCCESS(status) &&
addr.resource_type == ACPI_MEMORY_RANGE &&
addr.address_length &&
addr.producer_consumer == ACPI_CONSUMER) {
space->base = addr.minimum;
space->length = addr.address_length;
return AE_CTRL_TERMINATE;
}
return AE_OK; /* keep looking */
}
static acpi_status hp_crs_locate(acpi_handle obj, u64 *base, u64 *length)
{
struct csr_space space = { 0, 0 };
acpi_walk_resources(obj, METHOD_NAME__CRS, find_csr_space, &space);
if (!space.length)
return AE_NOT_FOUND;
*base = space.base;
*length = space.length;
return AE_OK;
}
acpi_status hp_acpi_csr_space(acpi_handle obj, u64 *csr_base, u64 *csr_length)
{
acpi_status status;
status = hp_ccsr_locate(obj, csr_base, csr_length);
if (ACPI_SUCCESS(status))
return status;
return hp_crs_locate(obj, csr_base, csr_length);
}
EXPORT_SYMBOL(hp_acpi_csr_space);
| gpl-2.0 |
Clust3r/android_kernel_oneplus_msm8994 | drivers/block/paride/bpck.c | 14851 | 9505 | /*
bpck.c (c) 1996-8 Grant R. Guenther <grant@torque.net>
Under the terms of the GNU General Public License.
bpck.c is a low-level protocol driver for the MicroSolutions
"backpack" parallel port IDE adapter.
*/
/* Changes:
1.01 GRG 1998.05.05 init_proto, release_proto, pi->delay
1.02 GRG 1998.08.15 default pi->delay returned to 4
*/
#define BPCK_VERSION "1.02"
#include <linux/module.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/wait.h>
#include <asm/io.h>
#include "paride.h"
#undef r2
#undef w2
#define PC pi->private
#define r2() (PC=(in_p(2) & 0xff))
#define w2(byte) {out_p(2,byte); PC = byte;}
#define t2(pat) {PC ^= pat; out_p(2,PC);}
#define e2() {PC &= 0xfe; out_p(2,PC);}
#define o2() {PC |= 1; out_p(2,PC);}
#define j44(l,h) (((l>>3)&0x7)|((l>>4)&0x8)|((h<<1)&0x70)|(h&0x80))
/* cont = 0 - access the IDE register file
cont = 1 - access the IDE command set
cont = 2 - use internal bpck register addressing
*/
static int cont_map[3] = { 0x40, 0x48, 0 };
static int bpck_read_regr( PIA *pi, int cont, int regr )
{ int r, l, h;
r = regr + cont_map[cont];
switch (pi->mode) {
case 0: w0(r & 0xf); w0(r); t2(2); t2(4);
l = r1();
t2(4);
h = r1();
return j44(l,h);
case 1: w0(r & 0xf); w0(r); t2(2);
e2(); t2(0x20);
t2(4); h = r0();
t2(1); t2(0x20);
return h;
case 2:
case 3:
case 4: w0(r); w2(9); w2(0); w2(0x20);
h = r4();
w2(0);
return h;
}
return -1;
}
static void bpck_write_regr( PIA *pi, int cont, int regr, int val )
{ int r;
r = regr + cont_map[cont];
switch (pi->mode) {
case 0:
case 1: w0(r);
t2(2);
w0(val);
o2(); t2(4); t2(1);
break;
case 2:
case 3:
case 4: w0(r); w2(9); w2(0);
w0(val); w2(1); w2(3); w2(0);
break;
}
}
/* These macros access the bpck registers in native addressing */
#define WR(r,v) bpck_write_regr(pi,2,r,v)
#define RR(r) (bpck_read_regr(pi,2,r))
static void bpck_write_block( PIA *pi, char * buf, int count )
{ int i;
switch (pi->mode) {
case 0: WR(4,0x40);
w0(0x40); t2(2); t2(1);
for (i=0;i<count;i++) { w0(buf[i]); t2(4); }
WR(4,0);
break;
case 1: WR(4,0x50);
w0(0x40); t2(2); t2(1);
for (i=0;i<count;i++) { w0(buf[i]); t2(4); }
WR(4,0x10);
break;
case 2: WR(4,0x48);
w0(0x40); w2(9); w2(0); w2(1);
for (i=0;i<count;i++) w4(buf[i]);
w2(0);
WR(4,8);
break;
case 3: WR(4,0x48);
w0(0x40); w2(9); w2(0); w2(1);
for (i=0;i<count/2;i++) w4w(((u16 *)buf)[i]);
w2(0);
WR(4,8);
break;
case 4: WR(4,0x48);
w0(0x40); w2(9); w2(0); w2(1);
for (i=0;i<count/4;i++) w4l(((u32 *)buf)[i]);
w2(0);
WR(4,8);
break;
}
}
static void bpck_read_block( PIA *pi, char * buf, int count )
{ int i, l, h;
switch (pi->mode) {
case 0: WR(4,0x40);
w0(0x40); t2(2);
for (i=0;i<count;i++) {
t2(4); l = r1();
t2(4); h = r1();
buf[i] = j44(l,h);
}
WR(4,0);
break;
case 1: WR(4,0x50);
w0(0x40); t2(2); t2(0x20);
for(i=0;i<count;i++) { t2(4); buf[i] = r0(); }
t2(1); t2(0x20);
WR(4,0x10);
break;
case 2: WR(4,0x48);
w0(0x40); w2(9); w2(0); w2(0x20);
for (i=0;i<count;i++) buf[i] = r4();
w2(0);
WR(4,8);
break;
case 3: WR(4,0x48);
w0(0x40); w2(9); w2(0); w2(0x20);
for (i=0;i<count/2;i++) ((u16 *)buf)[i] = r4w();
w2(0);
WR(4,8);
break;
case 4: WR(4,0x48);
w0(0x40); w2(9); w2(0); w2(0x20);
for (i=0;i<count/4;i++) ((u32 *)buf)[i] = r4l();
w2(0);
WR(4,8);
break;
}
}
static int bpck_probe_unit ( PIA *pi )
{ int o1, o0, f7, id;
int t, s;
id = pi->unit;
s = 0;
w2(4); w2(0xe); r2(); t2(2);
o1 = r1()&0xf8;
o0 = r0();
w0(255-id); w2(4); w0(id);
t2(8); t2(8); t2(8);
t2(2); t = r1()&0xf8;
f7 = ((id % 8) == 7);
if ((f7) || (t != o1)) { t2(2); s = r1()&0xf8; }
if ((t == o1) && ((!f7) || (s == o1))) {
w2(0x4c); w0(o0);
return 0;
}
t2(8); w0(0); t2(2); w2(0x4c); w0(o0);
return 1;
}
static void bpck_connect ( PIA *pi )
{ pi->saved_r0 = r0();
w0(0xff-pi->unit); w2(4); w0(pi->unit);
t2(8); t2(8); t2(8);
t2(2); t2(2);
switch (pi->mode) {
case 0: t2(8); WR(4,0);
break;
case 1: t2(8); WR(4,0x10);
break;
case 2:
case 3:
case 4: w2(0); WR(4,8);
break;
}
WR(5,8);
if (pi->devtype == PI_PCD) {
WR(0x46,0x10); /* fiddle with ESS logic ??? */
WR(0x4c,0x38);
WR(0x4d,0x88);
WR(0x46,0xa0);
WR(0x41,0);
WR(0x4e,8);
}
}
static void bpck_disconnect ( PIA *pi )
{ w0(0);
if (pi->mode >= 2) { w2(9); w2(0); } else t2(2);
w2(0x4c); w0(pi->saved_r0);
}
static void bpck_force_spp ( PIA *pi )
/* This fakes the EPP protocol to turn off EPP ... */
{ pi->saved_r0 = r0();
w0(0xff-pi->unit); w2(4); w0(pi->unit);
t2(8); t2(8); t2(8);
t2(2); t2(2);
w2(0);
w0(4); w2(9); w2(0);
w0(0); w2(1); w2(3); w2(0);
w0(0); w2(9); w2(0);
w2(0x4c); w0(pi->saved_r0);
}
#define TEST_LEN 16
static int bpck_test_proto( PIA *pi, char * scratch, int verbose )
{ int i, e, l, h, om;
char buf[TEST_LEN];
bpck_force_spp(pi);
switch (pi->mode) {
case 0: bpck_connect(pi);
WR(0x13,0x7f);
w0(0x13); t2(2);
for(i=0;i<TEST_LEN;i++) {
t2(4); l = r1();
t2(4); h = r1();
buf[i] = j44(l,h);
}
bpck_disconnect(pi);
break;
case 1: bpck_connect(pi);
WR(0x13,0x7f);
w0(0x13); t2(2); t2(0x20);
for(i=0;i<TEST_LEN;i++) { t2(4); buf[i] = r0(); }
t2(1); t2(0x20);
bpck_disconnect(pi);
break;
case 2:
case 3:
case 4: om = pi->mode;
pi->mode = 0;
bpck_connect(pi);
WR(7,3);
WR(4,8);
bpck_disconnect(pi);
pi->mode = om;
bpck_connect(pi);
w0(0x13); w2(9); w2(1); w0(0); w2(3); w2(0); w2(0xe0);
switch (pi->mode) {
case 2: for (i=0;i<TEST_LEN;i++) buf[i] = r4();
break;
case 3: for (i=0;i<TEST_LEN/2;i++) ((u16 *)buf)[i] = r4w();
break;
case 4: for (i=0;i<TEST_LEN/4;i++) ((u32 *)buf)[i] = r4l();
break;
}
w2(0);
WR(7,0);
bpck_disconnect(pi);
break;
}
if (verbose) {
printk("%s: bpck: 0x%x unit %d mode %d: ",
pi->device,pi->port,pi->unit,pi->mode);
for (i=0;i<TEST_LEN;i++) printk("%3d",buf[i]);
printk("\n");
}
e = 0;
for (i=0;i<TEST_LEN;i++) if (buf[i] != (i+1)) e++;
return e;
}
static void bpck_read_eeprom ( PIA *pi, char * buf )
{ int i,j,k,n,p,v,f, om, od;
bpck_force_spp(pi);
om = pi->mode; od = pi->delay;
pi->mode = 0; pi->delay = 6;
bpck_connect(pi);
n = 0;
WR(4,0);
for (i=0;i<64;i++) {
WR(6,8);
WR(6,0xc);
p = 0x100;
for (k=0;k<9;k++) {
f = (((i + 0x180) & p) != 0) * 2;
WR(6,f+0xc);
WR(6,f+0xd);
WR(6,f+0xc);
p = (p >> 1);
}
for (j=0;j<2;j++) {
v = 0;
for (k=0;k<8;k++) {
WR(6,0xc);
WR(6,0xd);
WR(6,0xc);
f = RR(0);
v = 2*v + (f == 0x84);
}
buf[2*i+1-j] = v;
}
}
WR(6,8);
WR(6,0);
WR(5,8);
bpck_disconnect(pi);
if (om >= 2) {
bpck_connect(pi);
WR(7,3);
WR(4,8);
bpck_disconnect(pi);
}
pi->mode = om; pi->delay = od;
}
static int bpck_test_port ( PIA *pi ) /* check for 8-bit port */
{ int i, r, m;
w2(0x2c); i = r0(); w0(255-i); r = r0(); w0(i);
m = -1;
if (r == i) m = 2;
if (r == (255-i)) m = 0;
w2(0xc); i = r0(); w0(255-i); r = r0(); w0(i);
if (r != (255-i)) m = -1;
if (m == 0) { w2(6); w2(0xc); r = r0(); w0(0xaa); w0(r); w0(0xaa); }
if (m == 2) { w2(0x26); w2(0xc); }
if (m == -1) return 0;
return 5;
}
static void bpck_log_adapter( PIA *pi, char * scratch, int verbose )
{ char *mode_string[5] = { "4-bit","8-bit","EPP-8",
"EPP-16","EPP-32" };
#ifdef DUMP_EEPROM
int i;
#endif
bpck_read_eeprom(pi,scratch);
#ifdef DUMP_EEPROM
if (verbose) {
for(i=0;i<128;i++)
if ((scratch[i] < ' ') || (scratch[i] > '~'))
scratch[i] = '.';
printk("%s: bpck EEPROM: %64.64s\n",pi->device,scratch);
printk("%s: %64.64s\n",pi->device,&scratch[64]);
}
#endif
printk("%s: bpck %s, backpack %8.8s unit %d",
pi->device,BPCK_VERSION,&scratch[110],pi->unit);
printk(" at 0x%x, mode %d (%s), delay %d\n",pi->port,
pi->mode,mode_string[pi->mode],pi->delay);
}
static struct pi_protocol bpck = {
.owner = THIS_MODULE,
.name = "bpck",
.max_mode = 5,
.epp_first = 2,
.default_delay = 4,
.max_units = 255,
.write_regr = bpck_write_regr,
.read_regr = bpck_read_regr,
.write_block = bpck_write_block,
.read_block = bpck_read_block,
.connect = bpck_connect,
.disconnect = bpck_disconnect,
.test_port = bpck_test_port,
.probe_unit = bpck_probe_unit,
.test_proto = bpck_test_proto,
.log_adapter = bpck_log_adapter,
};
static int __init bpck_init(void)
{
return paride_register(&bpck);
}
static void __exit bpck_exit(void)
{
paride_unregister(&bpck);
}
MODULE_LICENSE("GPL");
module_init(bpck_init)
module_exit(bpck_exit)
| gpl-2.0 |
rk34cj/qt-extend-4.4.3 | qtopiacore/qt/src/xmlpatterns/data/qsorttuple.cpp | 4 | 2727 | /****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the QtXMLPatterns module of the Qt Toolkit.
**
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information
** to ensure GNU General Public Licensing requirements will be met:
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html. In addition, as a special
** exception, Nokia gives you certain additional rights. These rights
** are described in the Nokia Qt GPL Exception version 1.3, included in
** the file GPL_EXCEPTION.txt in this package.
**
** Qt for Windows(R) Licensees
** As a special exception, Nokia, as the sole copyright holder for Qt
** Designer, grants users of the Qt/Eclipse Integration plug-in the
** right for the Qt/Eclipse Integration to link to functionality
** provided by Qt Designer and its related libraries.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
****************************************************************************/
#include <QString>
#include "qbuiltintypes_p.h"
#include "qsorttuple_p.h"
QT_BEGIN_NAMESPACE
using namespace QPatternist;
bool SortTuple::isAtomicValue() const
{
Q_ASSERT_X(false, Q_FUNC_INFO,
"It makes no sense to call this function.");
return false;
}
QString SortTuple::stringValue() const
{
return QLatin1String("SortTuple");
}
bool SortTuple::isNode() const
{
Q_ASSERT_X(false, Q_FUNC_INFO,
"It makes no sense to call this function.");
return false;
}
bool SortTuple::hasError() const
{
Q_ASSERT_X(false, Q_FUNC_INFO,
"It makes no sense to call this function.");
return false;
}
Item::Iterator::Ptr SortTuple::typedValue() const
{
Q_ASSERT_X(false, Q_FUNC_INFO,
"It makes no sense to call this function.");
return Item::Iterator::Ptr();
}
ItemType::Ptr SortTuple::type() const
{
return BuiltinTypes::xsAnyAtomicType;
}
QT_END_NAMESPACE
| gpl-2.0 |
andr00ib/victor-oficial-kernel | drivers/power/msm_battery.c | 4 | 51286 | /* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
/*
* this needs to be before <linux/kernel.h> is loaded,
* and <linux/sched.h> loads <linux/kernel.h>
*/
#define DEBUG 1
#include <linux/slab.h>
#include <linux/earlysuspend.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/sched.h>
#include <linux/signal.h>
#include <linux/uaccess.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
#include <asm/atomic.h>
#include <mach/msm_rpcrouter.h>
#include <mach/msm_battery.h>
//20130426 seongjun.cho@lge.com fake_mode_feature add
#define CONFIG_MACH_LG_FAKE_BATTERY
#ifdef CONFIG_LGE_DETECT_PIF_PATCH
#include <mach/board_lge.h>
#endif
#define BATTERY_RPC_PROG 0x30000089
#define BATTERY_RPC_VER_1_1 0x00010001
#define BATTERY_RPC_VER_2_1 0x00020001
#define BATTERY_RPC_VER_4_1 0x00040001
#define BATTERY_RPC_VER_5_1 0x00050001
#define BATTERY_RPC_CB_PROG (BATTERY_RPC_PROG | 0x01000000)
#define CHG_RPC_PROG 0x3000001a
#define CHG_RPC_VER_1_1 0x00010001
#define CHG_RPC_VER_1_3 0x00010003
#define CHG_RPC_VER_2_2 0x00020002
#define CHG_RPC_VER_3_1 0x00030001
#define CHG_RPC_VER_4_1 0x00040001
#define BATTERY_REGISTER_PROC 2
#define BATTERY_MODIFY_CLIENT_PROC 4
#define BATTERY_DEREGISTER_CLIENT_PROC 5
#define BATTERY_READ_MV_PROC 12
#define BATTERY_ENABLE_DISABLE_FILTER_PROC 14
#define VBATT_FILTER 2
#define BATTERY_CB_TYPE_PROC 1
#define BATTERY_CB_ID_ALL_ACTIV 1
#define BATTERY_CB_ID_LOW_VOL 2
#define BATTERY_LOW 3200
#define BATTERY_HIGH 4300
#define ONCRPC_CHG_GET_GENERAL_STATUS_PROC 12
#define ONCRPC_CHARGER_API_VERSIONS_PROC 0xffffffff
#define BATT_RPC_TIMEOUT 5000 /* 5 sec */
#define INVALID_BATT_HANDLE -1
#define RPC_TYPE_REQ 0
#define RPC_TYPE_REPLY 1
#define RPC_REQ_REPLY_COMMON_HEADER_SIZE (3 * sizeof(uint32_t))
#if DEBUG
#define DBG_LIMIT(x...) do {pr_info(x); } while (0)
#else
#define DBG_LIMIT(x...) do {} while (0)
#endif
enum {
BATTERY_REGISTRATION_SUCCESSFUL = 0,
BATTERY_DEREGISTRATION_SUCCESSFUL = BATTERY_REGISTRATION_SUCCESSFUL,
BATTERY_MODIFICATION_SUCCESSFUL = BATTERY_REGISTRATION_SUCCESSFUL,
BATTERY_INTERROGATION_SUCCESSFUL = BATTERY_REGISTRATION_SUCCESSFUL,
BATTERY_CLIENT_TABLE_FULL = 1,
BATTERY_REG_PARAMS_WRONG = 2,
BATTERY_DEREGISTRATION_FAILED = 4,
BATTERY_MODIFICATION_FAILED = 8,
BATTERY_INTERROGATION_FAILED = 16,
/* Client's filter could not be set because perhaps it does not exist */
BATTERY_SET_FILTER_FAILED = 32,
/* Client's could not be found for enabling or disabling the individual
* client */
BATTERY_ENABLE_DISABLE_INDIVIDUAL_CLIENT_FAILED = 64,
BATTERY_LAST_ERROR = 128,
};
enum {
BATTERY_VOLTAGE_UP = 0,
BATTERY_VOLTAGE_DOWN,
BATTERY_VOLTAGE_ABOVE_THIS_LEVEL,
BATTERY_VOLTAGE_BELOW_THIS_LEVEL,
BATTERY_VOLTAGE_LEVEL,
BATTERY_ALL_ACTIVITY,
VBATT_CHG_EVENTS,
BATTERY_VOLTAGE_UNKNOWN,
};
/*
* This enum contains defintions of the charger hardware status
*/
enum chg_charger_status_type {
/* The charger is good */
CHARGER_STATUS_GOOD,
/* The charger is bad */
CHARGER_STATUS_BAD,
/* The charger is weak */
CHARGER_STATUS_WEAK,
/* Invalid charger status. */
CHARGER_STATUS_INVALID
};
/*
*This enum contains defintions of the charger hardware type
*/
enum chg_charger_hardware_type {
/* The charger is removed */
CHARGER_TYPE_NONE,
/* The charger is a regular wall charger */
CHARGER_TYPE_WALL,
/* The charger is a PC USB */
CHARGER_TYPE_USB_PC,
/* The charger is a wall USB charger */
CHARGER_TYPE_USB_WALL,
/* The charger is a USB carkit */
CHARGER_TYPE_USB_CARKIT,
/* Invalid charger hardware status. */
CHARGER_TYPE_INVALID
};
/*
* This enum contains defintions of the battery status
*/
enum chg_battery_status_type {
/* The battery is good */
BATTERY_STATUS_GOOD,
/* The battery is cold/hot */
BATTERY_STATUS_BAD_TEMP,
/* The battery is bad */
BATTERY_STATUS_BAD,
/* The battery is removed */
BATTERY_STATUS_REMOVED, /* on v2.2 only */
BATTERY_STATUS_INVALID_v1 = BATTERY_STATUS_REMOVED,
/* Invalid battery status. */
BATTERY_STATUS_INVALID
};
/*
*This enum contains defintions of the battery voltage level
*/
enum chg_battery_level_type {
/* The battery voltage is dead/very low (less than 3.2V) */
BATTERY_LEVEL_DEAD,
/* The battery voltage is weak/low (between 3.2V and 3.4V) */
BATTERY_LEVEL_WEAK,
/* The battery voltage is good/normal(between 3.4V and 4.2V) */
BATTERY_LEVEL_GOOD,
/* The battery voltage is up to full (close to 4.2V) */
BATTERY_LEVEL_FULL,
/* Invalid battery voltage level. */
BATTERY_LEVEL_INVALID
};
#ifndef CONFIG_BATTERY_MSM_FAKE
struct rpc_reply_batt_chg_v1 {
struct rpc_reply_hdr hdr;
u32 more_data;
u32 charger_status;
u32 charger_type;
u32 battery_status;
u32 battery_level;
u32 battery_voltage;
u32 battery_temp;
#ifdef CONFIG_LGE_FUEL_GAUGE
u32 battery_soc;
#endif
};
struct rpc_reply_batt_chg_v2 {
struct rpc_reply_batt_chg_v1 v1;
u32 is_charger_valid;
u32 is_charging;
u32 is_battery_valid;
u32 ui_event;
};
union rpc_reply_batt_chg {
struct rpc_reply_batt_chg_v1 v1;
struct rpc_reply_batt_chg_v2 v2;
};
static union rpc_reply_batt_chg rep_batt_chg;
#endif
struct msm_battery_info {
u32 voltage_max_design;
u32 voltage_min_design;
u32 chg_api_version;
u32 batt_technology;
u32 batt_api_version;
u32 avail_chg_sources;
u32 current_chg_source;
u32 batt_status;
u32 batt_health;
u32 charger_valid;
u32 batt_valid;
u32 batt_capacity; /* in percentage */
u32 charger_status;
u32 charger_type;
u32 battery_status;
u32 battery_level;
u32 battery_voltage; /* in millie volts */
u32 battery_temp; /* in celsius */
u32(*calculate_capacity) (u32 voltage);
s32 batt_handle;
struct power_supply *msm_psy_ac;
struct power_supply *msm_psy_usb;
struct power_supply *msm_psy_batt;
struct power_supply *current_ps;
struct msm_rpc_client *batt_client;
struct msm_rpc_endpoint *chg_ep;
wait_queue_head_t wait_q;
u32 vbatt_modify_reply_avail;
struct early_suspend early_suspend;
};
static struct msm_battery_info msm_batt_info = {
.batt_handle = INVALID_BATT_HANDLE,
.charger_status = CHARGER_STATUS_BAD,
.charger_type = CHARGER_TYPE_INVALID,
.battery_status = BATTERY_STATUS_GOOD,
.battery_level = BATTERY_LEVEL_FULL,
.battery_voltage = BATTERY_HIGH,
.batt_capacity = 100,
.batt_status = POWER_SUPPLY_STATUS_DISCHARGING,
.batt_health = POWER_SUPPLY_HEALTH_GOOD,
.batt_valid = 1,
.battery_temp = 23,
.vbatt_modify_reply_avail = 0,
};
static enum power_supply_property msm_power_props[] = {
POWER_SUPPLY_PROP_ONLINE,
};
static char *msm_power_supplied_to[] = {
"battery",
};
#ifdef CONFIG_MACH_LG_FAKE_BATTERY
static bool msm_get_fake_battery(void);
#endif
static int msm_power_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
if (psy->type == POWER_SUPPLY_TYPE_MAINS) {
val->intval = msm_batt_info.current_chg_source & AC_CHG
? 1 : 0;
}
if (psy->type == POWER_SUPPLY_TYPE_USB) {
val->intval = msm_batt_info.current_chg_source & USB_CHG
? 1 : 0;
}
break;
default:
return -EINVAL;
}
return 0;
}
static struct power_supply msm_psy_ac = {
.name = "ac",
.type = POWER_SUPPLY_TYPE_MAINS,
.supplied_to = msm_power_supplied_to,
.num_supplicants = ARRAY_SIZE(msm_power_supplied_to),
.properties = msm_power_props,
.num_properties = ARRAY_SIZE(msm_power_props),
.get_property = msm_power_get_property,
};
static struct power_supply msm_psy_usb = {
.name = "usb",
.type = POWER_SUPPLY_TYPE_USB,
.supplied_to = msm_power_supplied_to,
.num_supplicants = ARRAY_SIZE(msm_power_supplied_to),
.properties = msm_power_props,
.num_properties = ARRAY_SIZE(msm_power_props),
.get_property = msm_power_get_property,
};
static enum power_supply_property msm_batt_power_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CAPACITY,
#ifdef CONFIG_MACH_LGE
POWER_SUPPLY_PROP_TEMP,
#endif
};
static int msm_batt_power_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
//DBG_LIMIT("msm_batt_power_get_property psp: %d\n",psp);
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
val->intval = msm_batt_info.batt_status;
break;
case POWER_SUPPLY_PROP_HEALTH:
val->intval = msm_batt_info.batt_health;
break;
case POWER_SUPPLY_PROP_PRESENT:
val->intval = msm_batt_info.batt_valid;
break;
case POWER_SUPPLY_PROP_TECHNOLOGY:
val->intval = msm_batt_info.batt_technology;
break;
case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
val->intval = msm_batt_info.voltage_max_design;
break;
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
val->intval = msm_batt_info.voltage_min_design;
break;
// LGE_UPDATE_S The unit of voltage_now is micro volt, not millie volt
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
val->intval = msm_batt_info.battery_voltage * 1000;
break;
// LGE_UPDATE_E
case POWER_SUPPLY_PROP_CAPACITY:
val->intval = msm_batt_info.batt_capacity;
break;
#ifdef CONFIG_MACH_LGE
case POWER_SUPPLY_PROP_TEMP:
/* 2011-05-19 by baborobo@lge.com
* The android framework used 0.1 degree Celsius.
*/
#ifdef CONFIG_MACH_LG_FAKE_BATTERY
DBG_LIMIT("msm_get_fake_battery : %d\n",psp);
if(msm_get_fake_battery() == true)
val->intval = 250; // return 25 degree Celsius
else
val->intval = (msm_batt_info.battery_temp)*10;
#else
val->intval = (msm_batt_info.battery_temp)*10;
#endif
break;
#endif
default:
return -EINVAL;
}
return 0;
}
static struct power_supply msm_psy_batt = {
.name = "battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = msm_batt_power_props,
.num_properties = ARRAY_SIZE(msm_batt_power_props),
.get_property = msm_batt_power_get_property,
};
#ifndef CONFIG_BATTERY_MSM_FAKE
struct msm_batt_get_volt_ret_data {
u32 battery_voltage;
};
static int msm_batt_get_volt_ret_func(struct msm_rpc_client *batt_client,
void *buf, void *data)
{
struct msm_batt_get_volt_ret_data *data_ptr, *buf_ptr;
data_ptr = (struct msm_batt_get_volt_ret_data *)data;
buf_ptr = (struct msm_batt_get_volt_ret_data *)buf;
data_ptr->battery_voltage = be32_to_cpu(buf_ptr->battery_voltage);
return 0;
}
static u32 msm_batt_get_vbatt_voltage(void)
{
int rc;
struct msm_batt_get_volt_ret_data rep;
rc = msm_rpc_client_req(msm_batt_info.batt_client,
BATTERY_READ_MV_PROC,
NULL, NULL,
msm_batt_get_volt_ret_func, &rep,
msecs_to_jiffies(BATT_RPC_TIMEOUT));
if (rc < 0) {
pr_err("%s: FAIL: vbatt get volt. rc=%d\n", __func__, rc);
return 0;
}
return rep.battery_voltage;
}
#define be32_to_cpu_self(v) (v = be32_to_cpu(v))
static int msm_batt_get_batt_chg_status(void)
{
int rc;
struct rpc_req_batt_chg {
struct rpc_request_hdr hdr;
u32 more_data;
} req_batt_chg;
struct rpc_reply_batt_chg_v1 *v1p;
req_batt_chg.more_data = cpu_to_be32(1);
memset(&rep_batt_chg, 0, sizeof(rep_batt_chg));
v1p = &rep_batt_chg.v1;
rc = msm_rpc_call_reply(msm_batt_info.chg_ep,
ONCRPC_CHG_GET_GENERAL_STATUS_PROC,
&req_batt_chg, sizeof(req_batt_chg),
&rep_batt_chg, sizeof(rep_batt_chg),
msecs_to_jiffies(BATT_RPC_TIMEOUT));
if (rc < 0) {
pr_err("%s: ERROR. msm_rpc_call_reply failed! proc=%d rc=%d\n",
__func__, ONCRPC_CHG_GET_GENERAL_STATUS_PROC, rc);
return rc;
} else if (be32_to_cpu(v1p->more_data)) {
be32_to_cpu_self(v1p->charger_status);
be32_to_cpu_self(v1p->charger_type);
be32_to_cpu_self(v1p->battery_status);
be32_to_cpu_self(v1p->battery_level);
be32_to_cpu_self(v1p->battery_voltage);
be32_to_cpu_self(v1p->battery_temp);
#ifdef CONFIG_LGE_FUEL_GAUGE
be32_to_cpu_self(v1p->battery_soc);
#endif
} else {
pr_err("%s: No battery/charger data in RPC reply\n", __func__);
return -EIO;
}
return 0;
}
#ifdef CONFIG_MACH_LGE
/* 2010-12-14 by baborobo@lge.com
* if it is updateing of battery-status by rpc,
* don't request updateing of battery-status
*/
static bool is_run_batt_update;
#endif
static void msm_batt_update_psy_status(void)
{
static u32 unnecessary_event_count;
u32 charger_status;
u32 charger_type;
u32 battery_status;
u32 battery_level;
u32 battery_voltage;
u32 battery_temp;
#ifdef CONFIG_LGE_FUEL_GAUGE
u32 battery_soc;
u32 battery_capacity;
#endif
struct power_supply *supp;
#ifdef CONFIG_MACH_LGE
/* 2010-12-14 by baborobo@lge.com
* to check the updating-status
*/
if (is_run_batt_update == true)
return;
is_run_batt_update = true;
if (msm_batt_get_batt_chg_status()) {
is_run_batt_update = false;
return;
}
#else
if (msm_batt_get_batt_chg_status())
return;
#endif
charger_status = rep_batt_chg.v1.charger_status;
charger_type = rep_batt_chg.v1.charger_type;
battery_status = rep_batt_chg.v1.battery_status;
battery_level = rep_batt_chg.v1.battery_level;
battery_voltage = rep_batt_chg.v1.battery_voltage;
battery_temp = rep_batt_chg.v1.battery_temp;
#ifdef CONFIG_LGE_FUEL_GAUGE
battery_soc = rep_batt_chg.v1.battery_soc;
#endif
/* Make correction for battery status */
#ifdef CONFIG_MACH_LGE
if (battery_status == BATTERY_STATUS_REMOVED) {
/* LGE_CHANGE : 2011-02-17 baborobo@lge.com
* for Battery Remove status
*/
battery_status = BATTERY_STATUS_INVALID;
battery_level = BATTERY_LEVEL_INVALID;
}
#else
if (battery_status == BATTERY_STATUS_INVALID_v1) {
if (msm_batt_info.chg_api_version < CHG_RPC_VER_3_1)
battery_status = BATTERY_STATUS_INVALID;
}
#endif
if (charger_status == msm_batt_info.charger_status &&
charger_type == msm_batt_info.charger_type &&
battery_status == msm_batt_info.battery_status &&
battery_level == msm_batt_info.battery_level &&
battery_voltage == msm_batt_info.battery_voltage &&
#ifdef CONFIG_LGE_FUEL_GAUGE
battery_soc == msm_batt_info.batt_capacity &&
#endif
battery_temp == msm_batt_info.battery_temp) {
/* Got unnecessary event from Modem PMIC VBATT driver.
* Nothing changed in Battery or charger status.
*/
unnecessary_event_count++;
if ((unnecessary_event_count % 20) == 1)
DBG_LIMIT("BATT: same event count = %u\n",
unnecessary_event_count);
#ifdef CONFIG_MACH_LGE
/* 2010-12-14 by baborobo@lge.com
* to check the updating-status
*/
is_run_batt_update = false;
#endif
return;
}
unnecessary_event_count = 0;
#ifdef CONFIG_LGE_FUEL_GAUGE
DBG_LIMIT("BATT: rcvd: %d, %d, %d, %d; %d, %d, %d\n",
charger_status, charger_type, battery_status,
battery_level, battery_voltage, battery_temp, battery_soc);
#else
DBG_LIMIT("BATT: rcvd: %d, %d, %d, %d; %d, %d\n",
charger_status, charger_type, battery_status,
battery_level, battery_voltage, battery_temp);
#endif
if (battery_status == BATTERY_STATUS_INVALID &&
battery_level != BATTERY_LEVEL_INVALID) {
DBG_LIMIT("BATT: change status(%d) to (%d) for level=%d\n",
battery_status, BATTERY_STATUS_GOOD, battery_level);
battery_status = BATTERY_STATUS_GOOD;
}
if (msm_batt_info.charger_type != charger_type) {
if (charger_type == CHARGER_TYPE_USB_WALL ||
charger_type == CHARGER_TYPE_USB_PC ||
charger_type == CHARGER_TYPE_USB_CARKIT) {
DBG_LIMIT("BATT: USB charger plugged in\n");
msm_batt_info.current_chg_source = USB_CHG;
supp = &msm_psy_usb;
} else if (charger_type == CHARGER_TYPE_WALL) {
DBG_LIMIT("BATT: AC Wall changer plugged in\n");
msm_batt_info.current_chg_source = AC_CHG;
supp = &msm_psy_ac;
} else {
if (msm_batt_info.current_chg_source & AC_CHG)
DBG_LIMIT("BATT: AC Wall charger removed\n");
else if (msm_batt_info.current_chg_source & USB_CHG)
DBG_LIMIT("BATT: USB charger removed\n");
else
DBG_LIMIT("BATT: No charger present\n");
msm_batt_info.current_chg_source = 0;
supp = &msm_psy_batt;
/* Correct charger status */
if (charger_status != CHARGER_STATUS_INVALID) {
DBG_LIMIT("BATT: No charging!\n");
charger_status = CHARGER_STATUS_INVALID;
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_NOT_CHARGING;
}
}
} else
supp = NULL;
if (msm_batt_info.charger_status != charger_status) {
if (charger_status == CHARGER_STATUS_GOOD ||
charger_status == CHARGER_STATUS_WEAK) {
if (msm_batt_info.current_chg_source) {
#ifdef CONFIG_MACH_LGE
/* LGE_CHANGE
* add for Full charging
* 2010-05-04 baborobo@lge.com
*/
if (battery_level == BATTERY_LEVEL_FULL) {
DBG_LIMIT("BATT: FULL.\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_FULL;
} else {
DBG_LIMIT("BATT: Charging.\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_CHARGING;
}
#else
DBG_LIMIT("BATT: Charging.\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_CHARGING;
#endif
/* Correct when supp==NULL */
if (msm_batt_info.current_chg_source & AC_CHG)
supp = &msm_psy_ac;
else
supp = &msm_psy_usb;
}
#ifdef CONFIG_MACH_LGE
/* LGE_CHANGE
* add for unpluged status of battery
* 2010-04-28 baborobo@lge.com
*/
if (battery_status == BATTERY_STATUS_INVALID
&& battery_level == BATTERY_LEVEL_INVALID) {
DBG_LIMIT("BATT: No Battery.\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_UNKNOWN;
}
#endif
} else {
#ifdef CONFIG_MACH_LGE
/* LGE_CHANGE
* add for unpluged status of battery
* 2011-02-17 baborobo@lge.com
*/
if (battery_status == BATTERY_STATUS_INVALID
&& battery_level == BATTERY_LEVEL_INVALID) {
DBG_LIMIT("BATT: No Battery.\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_UNKNOWN;
} else {
DBG_LIMIT("BATT: No charging.\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_NOT_CHARGING;
}
#else
DBG_LIMIT("BATT: No charging.\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_NOT_CHARGING;
#endif
supp = &msm_psy_batt;
}
} else {
#ifdef CONFIG_MACH_LGE
/* LGE_CHANGE
* add for unpluged status of battery
* 2010-04-07 baborobo@lge.com
*/
if (battery_status == BATTERY_STATUS_INVALID
&& battery_level == BATTERY_LEVEL_INVALID) {
DBG_LIMIT("BATT: No Battery\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_UNKNOWN;
} else
#endif
/* Correct charger status */
if (charger_type != CHARGER_TYPE_INVALID &&
charger_status == CHARGER_STATUS_GOOD) {
#ifdef CONFIG_MACH_LGE
/* LGE_CHANGE
* add for Full charging
* 2010-05-04 baborobo@lge.com
*/
if (battery_level == BATTERY_LEVEL_FULL) {
DBG_LIMIT("BATT: FULL\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_FULL;
} else {
DBG_LIMIT("BATT: In charging\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_CHARGING;
}
#else
DBG_LIMIT("BATT: In charging\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_CHARGING;
#endif
}
}
/* Correct battery voltage and status */
if (!battery_voltage) {
if (charger_status == CHARGER_STATUS_INVALID) {
DBG_LIMIT("BATT: Read VBATT\n");
battery_voltage = msm_batt_get_vbatt_voltage();
} else
/* Use previous */
battery_voltage = msm_batt_info.battery_voltage;
}
if (battery_status == BATTERY_STATUS_INVALID) {
#ifdef CONFIG_MACH_LGE
if (battery_level != BATTERY_LEVEL_INVALID
&& battery_voltage >= msm_batt_info.voltage_min_design
&& battery_voltage <= msm_batt_info.voltage_max_design) {
DBG_LIMIT("BATT: Battery valid\n");
msm_batt_info.batt_valid = 1;
battery_status = BATTERY_STATUS_GOOD;
}
#else
if (battery_voltage >= msm_batt_info.voltage_min_design
&& battery_voltage <= msm_batt_info.voltage_max_design) {
DBG_LIMIT("BATT: Battery valid\n");
msm_batt_info.batt_valid = 1;
battery_status = BATTERY_STATUS_GOOD;
}
#endif
}
if (msm_batt_info.battery_status != battery_status) {
if (battery_status != BATTERY_STATUS_INVALID) {
msm_batt_info.batt_valid = 1;
if (battery_status == BATTERY_STATUS_BAD) {
DBG_LIMIT("BATT: Battery bad.\n");
msm_batt_info.batt_health =
POWER_SUPPLY_HEALTH_DEAD;
} else if (battery_status == BATTERY_STATUS_BAD_TEMP) {
DBG_LIMIT("BATT: Battery overheat.\n");
msm_batt_info.batt_health =
POWER_SUPPLY_HEALTH_OVERHEAT;
} else {
DBG_LIMIT("BATT: Battery good.\n");
msm_batt_info.batt_health =
POWER_SUPPLY_HEALTH_GOOD;
}
} else {
msm_batt_info.batt_valid = 0;
DBG_LIMIT("BATT: Battery invalid.\n");
msm_batt_info.batt_health = POWER_SUPPLY_HEALTH_UNKNOWN;
}
#ifdef CONFIG_MACH_LGE
if (msm_batt_info.batt_status != POWER_SUPPLY_STATUS_CHARGING
&& msm_batt_info.batt_status != POWER_SUPPLY_STATUS_FULL) {
if (battery_status == BATTERY_STATUS_INVALID) {
DBG_LIMIT("BATT: Battery -> unknown\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_UNKNOWN;
} else {
DBG_LIMIT("BATT: Battery -> discharging\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_DISCHARGING;
}
}
#else
if (msm_batt_info.batt_status != POWER_SUPPLY_STATUS_CHARGING) {
if (battery_status == BATTERY_STATUS_INVALID) {
DBG_LIMIT("BATT: Battery -> unknown\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_UNKNOWN;
} else {
DBG_LIMIT("BATT: Battery -> discharging\n");
msm_batt_info.batt_status =
POWER_SUPPLY_STATUS_DISCHARGING;
}
}
#endif
if (!supp) {
if (msm_batt_info.current_chg_source) {
if (msm_batt_info.current_chg_source & AC_CHG)
supp = &msm_psy_ac;
else
supp = &msm_psy_usb;
} else
supp = &msm_psy_batt;
}
}
msm_batt_info.charger_status = charger_status;
msm_batt_info.charger_type = charger_type;
msm_batt_info.battery_status = battery_status;
msm_batt_info.battery_level = battery_level;
msm_batt_info.battery_temp = battery_temp;
#ifdef CONFIG_LGE_FUEL_GAUGE
battery_capacity = msm_batt_info.calculate_capacity(battery_soc);
if (msm_batt_info.battery_voltage != battery_voltage
|| msm_batt_info.batt_capacity != battery_capacity) {
msm_batt_info.battery_voltage = battery_voltage;
msm_batt_info.batt_capacity = battery_capacity;
DBG_LIMIT("BATT: voltage = %u mV [capacity = %d%%]\n",
battery_voltage, msm_batt_info.batt_capacity);
if (!supp)
supp = msm_batt_info.current_ps;
}
#else
if (msm_batt_info.battery_voltage != battery_voltage) {
msm_batt_info.battery_voltage = battery_voltage;
msm_batt_info.batt_capacity =
msm_batt_info.calculate_capacity(battery_voltage);
DBG_LIMIT("BATT: voltage = %u mV [capacity = %d%%]\n",
battery_voltage, msm_batt_info.batt_capacity);
if (!supp)
supp = msm_batt_info.current_ps;
}
#endif
if (supp) {
msm_batt_info.current_ps = supp;
DBG_LIMIT("BATT: Supply = %s\n", supp->name);
power_supply_changed(supp);
}
#ifdef CONFIG_MACH_LGE
/* 2010-12-14 by baborobo@lge.com
* to check the updating-status
*/
is_run_batt_update = false;
#endif
// check wakelock suspend for detecting abnormal wakelock
#ifdef CONFIG_MACH_LGE
has_wake_lock(WAKE_LOCK_SUSPEND);
#endif
}
struct batt_modify_client_req {
u32 client_handle;
/* The voltage at which callback (CB) should be called. */
u32 desired_batt_voltage;
/* The direction when the CB should be called. */
u32 voltage_direction;
/* The registered callback to be called when voltage and
* direction specs are met. */
u32 batt_cb_id;
/* The call back data */
u32 cb_data;
};
struct batt_modify_client_rep {
u32 result;
};
static int msm_batt_modify_client_arg_func(struct msm_rpc_client *batt_client,
void *buf, void *data)
{
struct batt_modify_client_req *batt_modify_client_req =
(struct batt_modify_client_req *)data;
u32 *req = (u32 *)buf;
int size = 0;
*req = cpu_to_be32(batt_modify_client_req->client_handle);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_modify_client_req->desired_batt_voltage);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_modify_client_req->voltage_direction);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_modify_client_req->batt_cb_id);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_modify_client_req->cb_data);
size += sizeof(u32);
return size;
}
static int msm_batt_modify_client_ret_func(struct msm_rpc_client *batt_client,
void *buf, void *data)
{
struct batt_modify_client_rep *data_ptr, *buf_ptr;
data_ptr = (struct batt_modify_client_rep *)data;
buf_ptr = (struct batt_modify_client_rep *)buf;
data_ptr->result = be32_to_cpu(buf_ptr->result);
return 0;
}
static int msm_batt_modify_client(u32 client_handle, u32 desired_batt_voltage,
u32 voltage_direction, u32 batt_cb_id, u32 cb_data)
{
int rc;
struct batt_modify_client_req req;
struct batt_modify_client_rep rep;
req.client_handle = client_handle;
req.desired_batt_voltage = desired_batt_voltage;
req.voltage_direction = voltage_direction;
req.batt_cb_id = batt_cb_id;
req.cb_data = cb_data;
rc = msm_rpc_client_req(msm_batt_info.batt_client,
BATTERY_MODIFY_CLIENT_PROC,
msm_batt_modify_client_arg_func, &req,
msm_batt_modify_client_ret_func, &rep,
msecs_to_jiffies(BATT_RPC_TIMEOUT));
if (rc < 0) {
pr_err("%s: ERROR. failed to modify Vbatt client\n",
__func__);
return rc;
}
if (rep.result != BATTERY_MODIFICATION_SUCCESSFUL) {
pr_err("%s: ERROR. modify client failed. result = %u\n",
__func__, rep.result);
return -EIO;
}
return 0;
}
#if 0 //def CONFIG_MACH_LGE // not use this function
/* 2011-02-17 by baborobo@lge.com
* it is notthing at early-suspend / msm_batt_late_resume
* the rpc_client-setting is executed at suspend/resume
* when the phone is wake up by charger(USB or Wall-chager),
* the screen must be on-status.
*/
static int msm_batt_suspend(struct platform_device *pdev, pm_message_t state)
{
int rc;
pr_debug("%s: enter\n", __func__);
if (msm_batt_info.batt_handle != INVALID_BATT_HANDLE) {
rc = msm_batt_modify_client(msm_batt_info.batt_handle,
BATTERY_LOW, BATTERY_VOLTAGE_BELOW_THIS_LEVEL,
BATTERY_CB_ID_LOW_VOL, BATTERY_LOW);
if (rc < 0) {
pr_err("%s: msm_batt_modify_client. rc=%d\n",
__func__, rc);
return 0;
}
} else {
pr_err("%s: ERROR. invalid batt_handle\n", __func__);
return 0;
}
pr_debug("%s: exit\n", __func__);
return 0;
}
static int msm_batt_resume(struct platform_device *pdev)
{
int rc;
pr_debug("%s: enter\n", __func__);
if (msm_batt_info.batt_handle != INVALID_BATT_HANDLE) {
rc = msm_batt_modify_client(msm_batt_info.batt_handle,
BATTERY_LOW, BATTERY_ALL_ACTIVITY,
BATTERY_CB_ID_ALL_ACTIV, BATTERY_ALL_ACTIVITY);
if (rc < 0) {
pr_err("%s: msm_batt_modify_client FAIL rc=%d\n",
__func__, rc);
return 0;
}
} else {
pr_err("%s: ERROR. invalid batt_handle\n", __func__);
return 0;
}
msm_batt_update_psy_status();
pr_debug("%s: exit\n", __func__);
return 0;
}
#else /* CONFIG_MACH_LGE */
#ifdef CONFIG_HAS_EARLYSUSPEND
void msm_batt_early_suspend(struct early_suspend *h)
{
int rc;
pr_debug("%s: enter\n", __func__);
if (msm_batt_info.batt_handle != INVALID_BATT_HANDLE) {
rc = msm_batt_modify_client(msm_batt_info.batt_handle,
BATTERY_LOW, BATTERY_VOLTAGE_BELOW_THIS_LEVEL,
BATTERY_CB_ID_LOW_VOL, BATTERY_LOW);
if (rc < 0) {
pr_err("%s: msm_batt_modify_client. rc=%d\n",
__func__, rc);
return;
}
} else {
pr_err("%s: ERROR. invalid batt_handle\n", __func__);
return;
}
pr_debug("%s: exit\n", __func__);
}
void msm_batt_late_resume(struct early_suspend *h)
{
int rc;
pr_debug("%s: enter\n", __func__);
if (msm_batt_info.batt_handle != INVALID_BATT_HANDLE) {
rc = msm_batt_modify_client(msm_batt_info.batt_handle,
BATTERY_LOW, BATTERY_ALL_ACTIVITY,
BATTERY_CB_ID_ALL_ACTIV, BATTERY_ALL_ACTIVITY);
if (rc < 0) {
pr_err("%s: msm_batt_modify_client FAIL rc=%d\n",
__func__, rc);
return;
}
} else {
pr_err("%s: ERROR. invalid batt_handle\n", __func__);
return;
}
msm_batt_update_psy_status();
pr_debug("%s: exit\n", __func__);
}
#endif /* CONFIG_HAS_EARLYSUSPEND */
#endif /* CONFIG_MACH_LGE */
struct msm_batt_vbatt_filter_req {
u32 batt_handle;
u32 enable_filter;
u32 vbatt_filter;
};
struct msm_batt_vbatt_filter_rep {
u32 result;
};
static int msm_batt_filter_arg_func(struct msm_rpc_client *batt_client,
void *buf, void *data)
{
struct msm_batt_vbatt_filter_req *vbatt_filter_req =
(struct msm_batt_vbatt_filter_req *)data;
u32 *req = (u32 *)buf;
int size = 0;
*req = cpu_to_be32(vbatt_filter_req->batt_handle);
size += sizeof(u32);
req++;
*req = cpu_to_be32(vbatt_filter_req->enable_filter);
size += sizeof(u32);
req++;
*req = cpu_to_be32(vbatt_filter_req->vbatt_filter);
size += sizeof(u32);
return size;
}
static int msm_batt_filter_ret_func(struct msm_rpc_client *batt_client,
void *buf, void *data)
{
struct msm_batt_vbatt_filter_rep *data_ptr, *buf_ptr;
data_ptr = (struct msm_batt_vbatt_filter_rep *)data;
buf_ptr = (struct msm_batt_vbatt_filter_rep *)buf;
data_ptr->result = be32_to_cpu(buf_ptr->result);
return 0;
}
static int msm_batt_enable_filter(u32 vbatt_filter)
{
int rc;
struct msm_batt_vbatt_filter_req vbatt_filter_req;
struct msm_batt_vbatt_filter_rep vbatt_filter_rep;
vbatt_filter_req.batt_handle = msm_batt_info.batt_handle;
vbatt_filter_req.enable_filter = 1;
vbatt_filter_req.vbatt_filter = vbatt_filter;
rc = msm_rpc_client_req(msm_batt_info.batt_client,
BATTERY_ENABLE_DISABLE_FILTER_PROC,
msm_batt_filter_arg_func, &vbatt_filter_req,
msm_batt_filter_ret_func, &vbatt_filter_rep,
msecs_to_jiffies(BATT_RPC_TIMEOUT));
if (rc < 0) {
pr_err("%s: FAIL: enable vbatt filter. rc=%d\n",
__func__, rc);
return rc;
}
if (vbatt_filter_rep.result != BATTERY_DEREGISTRATION_SUCCESSFUL) {
pr_err("%s: FAIL: enable vbatt filter: result=%d\n",
__func__, vbatt_filter_rep.result);
return -EIO;
}
pr_debug("%s: enable vbatt filter: OK\n", __func__);
return rc;
}
struct batt_client_registration_req {
/* The voltage at which callback (CB) should be called. */
u32 desired_batt_voltage;
/* The direction when the CB should be called. */
u32 voltage_direction;
/* The registered callback to be called when voltage and
* direction specs are met. */
u32 batt_cb_id;
/* The call back data */
u32 cb_data;
u32 more_data;
u32 batt_error;
};
struct batt_client_registration_req_4_1 {
/* The voltage at which callback (CB) should be called. */
u32 desired_batt_voltage;
/* The direction when the CB should be called. */
u32 voltage_direction;
/* The registered callback to be called when voltage and
* direction specs are met. */
u32 batt_cb_id;
/* The call back data */
u32 cb_data;
u32 batt_error;
};
struct batt_client_registration_rep {
u32 batt_handle;
};
struct batt_client_registration_rep_4_1 {
u32 batt_handle;
u32 more_data;
u32 err;
};
static int msm_batt_register_arg_func(struct msm_rpc_client *batt_client,
void *buf, void *data)
{
struct batt_client_registration_req *batt_reg_req =
(struct batt_client_registration_req *)data;
u32 *req = (u32 *)buf;
int size = 0;
if (msm_batt_info.batt_api_version == BATTERY_RPC_VER_4_1) {
*req = cpu_to_be32(batt_reg_req->desired_batt_voltage);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_reg_req->voltage_direction);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_reg_req->batt_cb_id);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_reg_req->cb_data);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_reg_req->batt_error);
size += sizeof(u32);
return size;
} else {
*req = cpu_to_be32(batt_reg_req->desired_batt_voltage);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_reg_req->voltage_direction);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_reg_req->batt_cb_id);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_reg_req->cb_data);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_reg_req->more_data);
size += sizeof(u32);
req++;
*req = cpu_to_be32(batt_reg_req->batt_error);
size += sizeof(u32);
return size;
}
}
static int msm_batt_register_ret_func(struct msm_rpc_client *batt_client,
void *buf, void *data)
{
struct batt_client_registration_rep *data_ptr, *buf_ptr;
struct batt_client_registration_rep_4_1 *data_ptr_4_1, *buf_ptr_4_1;
if (msm_batt_info.batt_api_version == BATTERY_RPC_VER_4_1) {
data_ptr_4_1 = (struct batt_client_registration_rep_4_1 *)data;
buf_ptr_4_1 = (struct batt_client_registration_rep_4_1 *)buf;
data_ptr_4_1->batt_handle
= be32_to_cpu(buf_ptr_4_1->batt_handle);
data_ptr_4_1->more_data
= be32_to_cpu(buf_ptr_4_1->more_data);
data_ptr_4_1->err = be32_to_cpu(buf_ptr_4_1->err);
return 0;
} else {
data_ptr = (struct batt_client_registration_rep *)data;
buf_ptr = (struct batt_client_registration_rep *)buf;
data_ptr->batt_handle = be32_to_cpu(buf_ptr->batt_handle);
return 0;
}
}
static int msm_batt_register(u32 desired_batt_voltage,
u32 voltage_direction, u32 batt_cb_id, u32 cb_data)
{
struct batt_client_registration_req batt_reg_req;
struct batt_client_registration_req_4_1 batt_reg_req_4_1;
struct batt_client_registration_rep batt_reg_rep;
struct batt_client_registration_rep_4_1 batt_reg_rep_4_1;
void *request;
void *reply;
int rc;
if (msm_batt_info.batt_api_version == BATTERY_RPC_VER_4_1) {
batt_reg_req_4_1.desired_batt_voltage = desired_batt_voltage;
batt_reg_req_4_1.voltage_direction = voltage_direction;
batt_reg_req_4_1.batt_cb_id = batt_cb_id;
batt_reg_req_4_1.cb_data = cb_data;
batt_reg_req_4_1.batt_error = 1;
request = &batt_reg_req_4_1;
} else {
batt_reg_req.desired_batt_voltage = desired_batt_voltage;
batt_reg_req.voltage_direction = voltage_direction;
batt_reg_req.batt_cb_id = batt_cb_id;
batt_reg_req.cb_data = cb_data;
batt_reg_req.more_data = 1;
batt_reg_req.batt_error = 0;
request = &batt_reg_req;
}
if (msm_batt_info.batt_api_version == BATTERY_RPC_VER_4_1)
reply = &batt_reg_rep_4_1;
else
reply = &batt_reg_rep;
rc = msm_rpc_client_req(msm_batt_info.batt_client,
BATTERY_REGISTER_PROC,
msm_batt_register_arg_func, request,
msm_batt_register_ret_func, reply,
msecs_to_jiffies(BATT_RPC_TIMEOUT));
if (rc < 0) {
pr_err("%s: FAIL: vbatt register. rc=%d\n", __func__, rc);
return rc;
}
if (msm_batt_info.batt_api_version == BATTERY_RPC_VER_4_1) {
if (batt_reg_rep_4_1.more_data != 0
&& batt_reg_rep_4_1.err
!= BATTERY_REGISTRATION_SUCCESSFUL) {
pr_err("%s: vBatt Registration Failed proc_num=%d\n"
, __func__, BATTERY_REGISTER_PROC);
return -EIO;
}
msm_batt_info.batt_handle = batt_reg_rep_4_1.batt_handle;
} else
msm_batt_info.batt_handle = batt_reg_rep.batt_handle;
return 0;
}
struct batt_client_deregister_req {
u32 batt_handle;
};
struct batt_client_deregister_rep {
u32 batt_error;
};
static int msm_batt_deregister_arg_func(struct msm_rpc_client *batt_client,
void *buf, void *data)
{
struct batt_client_deregister_req *deregister_req =
(struct batt_client_deregister_req *)data;
u32 *req = (u32 *)buf;
int size = 0;
*req = cpu_to_be32(deregister_req->batt_handle);
size += sizeof(u32);
return size;
}
static int msm_batt_deregister_ret_func(struct msm_rpc_client *batt_client,
void *buf, void *data)
{
struct batt_client_deregister_rep *data_ptr, *buf_ptr;
data_ptr = (struct batt_client_deregister_rep *)data;
buf_ptr = (struct batt_client_deregister_rep *)buf;
data_ptr->batt_error = be32_to_cpu(buf_ptr->batt_error);
return 0;
}
static int msm_batt_deregister(u32 batt_handle)
{
int rc;
struct batt_client_deregister_req req;
struct batt_client_deregister_rep rep;
req.batt_handle = batt_handle;
rc = msm_rpc_client_req(msm_batt_info.batt_client,
BATTERY_DEREGISTER_CLIENT_PROC,
msm_batt_deregister_arg_func, &req,
msm_batt_deregister_ret_func, &rep,
msecs_to_jiffies(BATT_RPC_TIMEOUT));
if (rc < 0) {
pr_err("%s: FAIL: vbatt deregister. rc=%d\n", __func__, rc);
return rc;
}
if (rep.batt_error != BATTERY_DEREGISTRATION_SUCCESSFUL) {
pr_err("%s: vbatt deregistration FAIL. error=%d, handle=%d\n",
__func__, rep.batt_error, batt_handle);
return -EIO;
}
return 0;
}
#endif /* CONFIG_BATTERY_MSM_FAKE */
static int msm_batt_cleanup(void)
{
int rc = 0;
#ifndef CONFIG_BATTERY_MSM_FAKE
if (msm_batt_info.batt_handle != INVALID_BATT_HANDLE) {
rc = msm_batt_deregister(msm_batt_info.batt_handle);
if (rc < 0)
pr_err("%s: FAIL: msm_batt_deregister. rc=%d\n",
__func__, rc);
}
msm_batt_info.batt_handle = INVALID_BATT_HANDLE;
if (msm_batt_info.batt_client)
msm_rpc_unregister_client(msm_batt_info.batt_client);
#endif /* CONFIG_BATTERY_MSM_FAKE */
if (msm_batt_info.msm_psy_ac)
power_supply_unregister(msm_batt_info.msm_psy_ac);
if (msm_batt_info.msm_psy_usb)
power_supply_unregister(msm_batt_info.msm_psy_usb);
if (msm_batt_info.msm_psy_batt)
power_supply_unregister(msm_batt_info.msm_psy_batt);
#ifndef CONFIG_BATTERY_MSM_FAKE
if (msm_batt_info.chg_ep) {
rc = msm_rpc_close(msm_batt_info.chg_ep);
if (rc < 0) {
pr_err("%s: FAIL. msm_rpc_close(chg_ep). rc=%d\n",
__func__, rc);
}
}
#ifndef CONFIG_MACH_LGE
#ifdef CONFIG_HAS_EARLYSUSPEND
if (msm_batt_info.early_suspend.suspend == msm_batt_early_suspend)
unregister_early_suspend(&msm_batt_info.early_suspend);
#endif /* CONFIG_HAS_EARLYSUSPEND */
#endif /* CONFIG_MACH_LGE */
#endif
return rc;
}
static u32 msm_batt_capacity(u32 current_voltage)
{
u32 low_voltage = msm_batt_info.voltage_min_design;
u32 high_voltage = msm_batt_info.voltage_max_design;
if (current_voltage <= low_voltage)
return 0;
else if (current_voltage >= high_voltage)
return 100;
else
return (current_voltage - low_voltage) * 100
/ (high_voltage - low_voltage);
}
#ifndef CONFIG_BATTERY_MSM_FAKE
int msm_batt_get_charger_api_version(void)
{
int rc ;
struct rpc_reply_hdr *reply;
struct rpc_req_chg_api_ver {
struct rpc_request_hdr hdr;
u32 more_data;
} req_chg_api_ver;
struct rpc_rep_chg_api_ver {
struct rpc_reply_hdr hdr;
u32 num_of_chg_api_versions;
u32 *chg_api_versions;
};
u32 num_of_versions;
struct rpc_rep_chg_api_ver *rep_chg_api_ver;
req_chg_api_ver.more_data = cpu_to_be32(1);
msm_rpc_setup_req(&req_chg_api_ver.hdr, CHG_RPC_PROG, CHG_RPC_VER_1_1,
ONCRPC_CHARGER_API_VERSIONS_PROC);
rc = msm_rpc_write(msm_batt_info.chg_ep, &req_chg_api_ver,
sizeof(req_chg_api_ver));
if (rc < 0) {
pr_err("%s: FAIL: msm_rpc_write. proc=0x%08x, rc=%d\n",
__func__, ONCRPC_CHARGER_API_VERSIONS_PROC, rc);
return rc;
}
for (;;) {
rc = msm_rpc_read(msm_batt_info.chg_ep, (void *) &reply, -1,
BATT_RPC_TIMEOUT);
if (rc < 0)
return rc;
if (rc < RPC_REQ_REPLY_COMMON_HEADER_SIZE) {
pr_err("%s: LENGTH ERR: msm_rpc_read. rc=%d (<%d)\n",
__func__, rc, RPC_REQ_REPLY_COMMON_HEADER_SIZE);
rc = -EIO;
break;
}
/* we should not get RPC REQ or call packets -- ignore them */
if (reply->type == RPC_TYPE_REQ) {
pr_err("%s: TYPE ERR: type=%d (!=%d)\n",
__func__, reply->type, RPC_TYPE_REQ);
kfree(reply);
continue;
}
/* If an earlier call timed out, we could get the (no
* longer wanted) reply for it. Ignore replies that
* we don't expect
*/
if (reply->xid != req_chg_api_ver.hdr.xid) {
pr_err("%s: XID ERR: xid=%d (!=%d)\n", __func__,
reply->xid, req_chg_api_ver.hdr.xid);
kfree(reply);
continue;
}
if (reply->reply_stat != RPCMSG_REPLYSTAT_ACCEPTED) {
rc = -EPERM;
break;
}
if (reply->data.acc_hdr.accept_stat !=
RPC_ACCEPTSTAT_SUCCESS) {
rc = -EINVAL;
break;
}
rep_chg_api_ver = (struct rpc_rep_chg_api_ver *)reply;
num_of_versions =
be32_to_cpu(rep_chg_api_ver->num_of_chg_api_versions);
rep_chg_api_ver->chg_api_versions = (u32 *)
((u8 *) reply + sizeof(struct rpc_reply_hdr) +
sizeof(rep_chg_api_ver->num_of_chg_api_versions));
rc = be32_to_cpu(
rep_chg_api_ver->chg_api_versions[num_of_versions - 1]);
pr_debug("%s: num_of_chg_api_versions = %u. "
"The chg api version = 0x%08x\n", __func__,
num_of_versions, rc);
break;
}
kfree(reply);
return rc;
}
static int msm_batt_cb_func(struct msm_rpc_client *client,
void *buffer, int in_size)
{
int rc = 0;
struct rpc_request_hdr *req;
u32 procedure;
u32 accept_status;
req = (struct rpc_request_hdr *)buffer;
procedure = be32_to_cpu(req->procedure);
switch (procedure) {
case BATTERY_CB_TYPE_PROC:
accept_status = RPC_ACCEPTSTAT_SUCCESS;
break;
default:
accept_status = RPC_ACCEPTSTAT_PROC_UNAVAIL;
pr_err("%s: ERROR. procedure (%d) not supported\n",
__func__, procedure);
break;
}
msm_rpc_start_accepted_reply(msm_batt_info.batt_client,
be32_to_cpu(req->xid), accept_status);
rc = msm_rpc_send_accepted_reply(msm_batt_info.batt_client, 0);
if (rc)
pr_err("%s: FAIL: sending reply. rc=%d\n", __func__, rc);
if (accept_status == RPC_ACCEPTSTAT_SUCCESS)
msm_batt_update_psy_status();
return rc;
}
#endif /* CONFIG_BATTERY_MSM_FAKE */
#if defined(CONFIG_LGE_DETECT_PIF_PATCH)
static unsigned pif_value;
static ssize_t
msm_batt_pif_show(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", pif_value);
}
static DEVICE_ATTR(pif, S_IRUGO, msm_batt_pif_show, NULL);
#if defined(CONFIG_MACH_LG_FAKE_BATTERY)
#define MAX_SIZE 128
static bool fake_battery = false;
static bool msm_get_fake_battery(void)
{
if(fake_battery == true) {
return true;
}
return false;
}
static ssize_t
msm_batt_fake_show(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", (fake_battery==true)? "on" : "off");
}
static ssize_t
msm_batt_fake_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
unsigned char string[10];
sscanf(buf, "%s", string);
if (!strncmp(string, "on", 2))
fake_battery = true;
else
fake_battery = false;
printk(KERN_INFO "[%s] fake_battery = %d \n", string, fake_battery);
power_supply_changed(&msm_psy_ac);
return count;
}
static DEVICE_ATTR(fake, S_IRUGO | S_IWUSR, msm_batt_fake_show, msm_batt_fake_store);
#endif /* defined(CONFIG_MACH_LG_FAKE_BATTERY) */
static struct attribute *dev_attrs[] = {
#if defined(CONFIG_LGE_DETECT_PIF_PATCH)
&dev_attr_pif.attr,
#endif
#if defined(CONFIG_MACH_LG_FAKE_BATTERY)
&dev_attr_fake.attr,
#endif
NULL,
};
static struct attribute_group dev_attr_grp = {
.attrs = dev_attrs,
};
#endif
static int __devinit msm_batt_probe(struct platform_device *pdev)
{
int rc;
struct msm_psy_batt_pdata *pdata = pdev->dev.platform_data;
if (pdev->id != -1) {
dev_err(&pdev->dev,
"%s: MSM chipsets Can only support one"
" battery ", __func__);
return -EINVAL;
}
#ifndef CONFIG_BATTERY_MSM_FAKE
if (pdata->avail_chg_sources & AC_CHG) {
#else
{
#endif
rc = power_supply_register(&pdev->dev, &msm_psy_ac);
if (rc < 0) {
dev_err(&pdev->dev,
"%s: power_supply_register failed"
" rc = %d\n", __func__, rc);
msm_batt_cleanup();
return rc;
}
msm_batt_info.msm_psy_ac = &msm_psy_ac;
msm_batt_info.avail_chg_sources |= AC_CHG;
}
if (pdata->avail_chg_sources & USB_CHG) {
rc = power_supply_register(&pdev->dev, &msm_psy_usb);
if (rc < 0) {
dev_err(&pdev->dev,
"%s: power_supply_register failed"
" rc = %d\n", __func__, rc);
msm_batt_cleanup();
return rc;
}
msm_batt_info.msm_psy_usb = &msm_psy_usb;
msm_batt_info.avail_chg_sources |= USB_CHG;
}
if (!msm_batt_info.msm_psy_ac && !msm_batt_info.msm_psy_usb) {
dev_err(&pdev->dev,
"%s: No external Power supply(AC or USB)"
"is avilable\n", __func__);
msm_batt_cleanup();
return -ENODEV;
}
msm_batt_info.voltage_max_design = pdata->voltage_max_design;
msm_batt_info.voltage_min_design = pdata->voltage_min_design;
msm_batt_info.batt_technology = pdata->batt_technology;
msm_batt_info.calculate_capacity = pdata->calculate_capacity;
if (!msm_batt_info.voltage_min_design)
msm_batt_info.voltage_min_design = BATTERY_LOW;
if (!msm_batt_info.voltage_max_design)
msm_batt_info.voltage_max_design = BATTERY_HIGH;
if (msm_batt_info.batt_technology == POWER_SUPPLY_TECHNOLOGY_UNKNOWN)
msm_batt_info.batt_technology = POWER_SUPPLY_TECHNOLOGY_LION;
if (!msm_batt_info.calculate_capacity)
msm_batt_info.calculate_capacity = msm_batt_capacity;
rc = power_supply_register(&pdev->dev, &msm_psy_batt);
if (rc < 0) {
dev_err(&pdev->dev, "%s: power_supply_register failed"
" rc=%d\n", __func__, rc);
msm_batt_cleanup();
return rc;
}
msm_batt_info.msm_psy_batt = &msm_psy_batt;
#ifndef CONFIG_BATTERY_MSM_FAKE
rc = msm_batt_register(BATTERY_LOW, BATTERY_ALL_ACTIVITY,
BATTERY_CB_ID_ALL_ACTIV, BATTERY_ALL_ACTIVITY);
if (rc < 0) {
dev_err(&pdev->dev,
"%s: msm_batt_register failed rc = %d\n", __func__, rc);
msm_batt_cleanup();
return rc;
}
rc = msm_batt_enable_filter(VBATT_FILTER);
if (rc < 0) {
dev_err(&pdev->dev,
"%s: msm_batt_enable_filter failed rc = %d\n",
__func__, rc);
msm_batt_cleanup();
return rc;
}
#ifndef CONFIG_MACH_LGE
#ifdef CONFIG_HAS_EARLYSUSPEND
msm_batt_info.early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN;
msm_batt_info.early_suspend.suspend = msm_batt_early_suspend;
msm_batt_info.early_suspend.resume = msm_batt_late_resume;
register_early_suspend(&msm_batt_info.early_suspend);
#endif /* CONFIG_HAS_EARLYSUSPEND */
#endif /* CONFIG_MACH_LGE */
msm_batt_update_psy_status();
#else
power_supply_changed(&msm_psy_ac);
#endif /* CONFIG_BATTERY_MSM_FAKE */
#if defined(CONFIG_LGE_DETECT_PIF_PATCH)
rc = sysfs_create_group(&pdev->dev.kobj, &dev_attr_grp);
if (rc < 0)
pr_err("%s: msm_batt_cleanup failed rc=%d\n", __func__, rc);
else
pif_value = lge_get_pif_info();
pr_info("%s : Using PIF ZIG (%d)\n", __func__, pif_value);
#endif
return 0;
}
static int __devexit msm_batt_remove(struct platform_device *pdev)
{
int rc;
#if defined(CONFIG_LGE_DETECT_PIF_PATCH)
sysfs_remove_group(&pdev->dev.kobj, &dev_attr_grp);
#endif
rc = msm_batt_cleanup();
if (rc < 0) {
dev_err(&pdev->dev,
"%s: msm_batt_cleanup failed rc=%d\n", __func__, rc);
return rc;
}
return 0;
}
static struct platform_driver msm_batt_driver = {
.probe = msm_batt_probe,
.remove = __devexit_p(msm_batt_remove),
#if 0 //def CONFIG_MACH_LGE // not use this function
.suspend = msm_batt_suspend,
.resume = msm_batt_resume,
#endif
.driver = {
.name = "msm-battery",
.owner = THIS_MODULE,
},
};
static int __devinit msm_batt_init_rpc(void)
{
int rc;
#ifdef CONFIG_BATTERY_MSM_FAKE
pr_info("Faking MSM battery\n");
#else
msm_batt_info.chg_ep =
msm_rpc_connect_compatible(CHG_RPC_PROG, CHG_RPC_VER_4_1, 0);
msm_batt_info.chg_api_version = CHG_RPC_VER_4_1;
if (msm_batt_info.chg_ep == NULL) {
pr_err("%s: rpc connect CHG_RPC_PROG = NULL\n", __func__);
return -ENODEV;
}
if (IS_ERR(msm_batt_info.chg_ep)) {
msm_batt_info.chg_ep = msm_rpc_connect_compatible(
CHG_RPC_PROG, CHG_RPC_VER_3_1, 0);
msm_batt_info.chg_api_version = CHG_RPC_VER_3_1;
}
if (IS_ERR(msm_batt_info.chg_ep)) {
msm_batt_info.chg_ep = msm_rpc_connect_compatible(
CHG_RPC_PROG, CHG_RPC_VER_1_1, 0);
msm_batt_info.chg_api_version = CHG_RPC_VER_1_1;
}
if (IS_ERR(msm_batt_info.chg_ep)) {
msm_batt_info.chg_ep = msm_rpc_connect_compatible(
CHG_RPC_PROG, CHG_RPC_VER_1_3, 0);
msm_batt_info.chg_api_version = CHG_RPC_VER_1_3;
}
if (IS_ERR(msm_batt_info.chg_ep)) {
msm_batt_info.chg_ep = msm_rpc_connect_compatible(
CHG_RPC_PROG, CHG_RPC_VER_2_2, 0);
msm_batt_info.chg_api_version = CHG_RPC_VER_2_2;
}
if (IS_ERR(msm_batt_info.chg_ep)) {
rc = PTR_ERR(msm_batt_info.chg_ep);
pr_err("%s: FAIL: rpc connect for CHG_RPC_PROG. rc=%d\n",
__func__, rc);
msm_batt_info.chg_ep = NULL;
return rc;
}
/* Get the real 1.x version */
if (msm_batt_info.chg_api_version == CHG_RPC_VER_1_1)
msm_batt_info.chg_api_version =
msm_batt_get_charger_api_version();
/* Fall back to 1.1 for default */
if (msm_batt_info.chg_api_version < 0)
msm_batt_info.chg_api_version = CHG_RPC_VER_1_1;
msm_batt_info.batt_api_version = BATTERY_RPC_VER_4_1;
msm_batt_info.batt_client =
msm_rpc_register_client("battery", BATTERY_RPC_PROG,
BATTERY_RPC_VER_4_1,
1, msm_batt_cb_func);
if (msm_batt_info.batt_client == NULL) {
pr_err("%s: FAIL: rpc_register_client. batt_client=NULL\n",
__func__);
return -ENODEV;
}
if (IS_ERR(msm_batt_info.batt_client)) {
msm_batt_info.batt_client =
msm_rpc_register_client("battery", BATTERY_RPC_PROG,
BATTERY_RPC_VER_1_1,
1, msm_batt_cb_func);
msm_batt_info.batt_api_version = BATTERY_RPC_VER_1_1;
}
if (IS_ERR(msm_batt_info.batt_client)) {
msm_batt_info.batt_client =
msm_rpc_register_client("battery", BATTERY_RPC_PROG,
BATTERY_RPC_VER_2_1,
1, msm_batt_cb_func);
msm_batt_info.batt_api_version = BATTERY_RPC_VER_2_1;
}
if (IS_ERR(msm_batt_info.batt_client)) {
msm_batt_info.batt_client =
msm_rpc_register_client("battery", BATTERY_RPC_PROG,
BATTERY_RPC_VER_5_1,
1, msm_batt_cb_func);
msm_batt_info.batt_api_version = BATTERY_RPC_VER_5_1;
}
if (IS_ERR(msm_batt_info.batt_client)) {
rc = PTR_ERR(msm_batt_info.batt_client);
pr_err("%s: ERROR: rpc_register_client: rc = %d\n ",
__func__, rc);
msm_batt_info.batt_client = NULL;
return rc;
}
#endif /* CONFIG_BATTERY_MSM_FAKE */
rc = platform_driver_register(&msm_batt_driver);
if (rc < 0)
pr_err("%s: FAIL: platform_driver_register. rc = %d\n",
__func__, rc);
return rc;
}
static int __init msm_batt_init(void)
{
int rc;
pr_debug("%s: enter\n", __func__);
rc = msm_batt_init_rpc();
if (rc < 0) {
pr_err("%s: FAIL: msm_batt_init_rpc. rc=%d\n", __func__, rc);
msm_batt_cleanup();
return rc;
}
pr_info("%s: Charger/Battery = 0x%08x/0x%08x (RPC version)\n",
__func__, msm_batt_info.chg_api_version,
msm_batt_info.batt_api_version);
return 0;
}
static void __exit msm_batt_exit(void)
{
platform_driver_unregister(&msm_batt_driver);
}
module_init(msm_batt_init);
module_exit(msm_batt_exit);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Kiran Kandi, Qualcomm Innovation Center, Inc.");
MODULE_DESCRIPTION("Battery driver for Qualcomm MSM chipsets.");
MODULE_VERSION("1.0");
MODULE_ALIAS("platform:msm_battery");
| gpl-2.0 |
Gurgel100/gcc | gcc/common/config/pru/pru-common.c | 4 | 1180 | /* Common hooks for TI PRU
Copyright (C) 2014-2021 Free Software Foundation, Inc.
This file is part of GCC.
GCC 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 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "diagnostic-core.h"
#include "tm.h"
#include "common/common-target.h"
#include "common/common-target-def.h"
#include "opts.h"
#include "flags.h"
#undef TARGET_DEFAULT_TARGET_FLAGS
#define TARGET_DEFAULT_TARGET_FLAGS (MASK_OPT_LOOP)
#undef TARGET_EXCEPT_UNWIND_INFO
#define TARGET_EXCEPT_UNWIND_INFO sjlj_except_unwind_info
struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER;
| gpl-2.0 |
pipelka/aeskulap | dcmtk/dcmjpeg/libijg8/jclhuff.c | 4 | 18809 | /*
* jclhuff.c
*
* Copyright (C) 1991-1998, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains Huffman entropy encoding routines for lossless JPEG.
*
* Much of the complexity here has to do with supporting output suspension.
* If the data destination module demands suspension, we want to be able to
* back up to the start of the current MCU. To do this, we copy state
* variables into local working storage, and update them back to the
* permanent JPEG objects only upon successful completion of an MCU.
*/
#define JPEG_INTERNALS
#include "jinclude8.h"
#include "jpeglib8.h"
#include "jlossls8.h" /* Private declarations for lossless codec */
#include "jchuff8.h" /* Declarations shared with jc*huff.c */
/* Expanded entropy encoder object for Huffman encoding.
*
* The savable_state subrecord contains fields that change within an MCU,
* but must not be updated permanently until we complete the MCU.
*/
typedef struct {
IJG_INT32 put_buffer; /* current bit-accumulation buffer */
int put_bits; /* # of bits now in it */
} savable_state;
/* This macro is to work around compilers with missing or broken
* structure assignment. You'll need to fix this code if you have
* such a compiler and you change MAX_COMPS_IN_SCAN.
*/
#ifndef NO_STRUCT_ASSIGN
#define ASSIGN_STATE(dest,src) ((dest) = (src))
#else
#define ASSIGN_STATE(dest,src) \
((dest).put_buffer = (src).put_buffer, \
(dest).put_bits = (src).put_bits)
#endif
typedef struct {
int ci, yoffset, MCU_width;
} lhe_input_ptr_info;
typedef struct {
savable_state saved; /* Bit buffer at start of MCU */
/* These fields are NOT loaded into local working state. */
unsigned int restarts_to_go; /* MCUs left in this restart interval */
int next_restart_num; /* next restart number to write (0-7) */
/* Pointers to derived tables (these workspaces have image lifespan) */
c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
/* Pointers to derived tables to be used for each data unit within an MCU */
c_derived_tbl * cur_tbls[C_MAX_DATA_UNITS_IN_MCU];
#ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
long * count_ptrs[NUM_HUFF_TBLS];
/* Pointers to stats tables to be used for each data unit within an MCU */
long * cur_counts[C_MAX_DATA_UNITS_IN_MCU];
#endif
/* Pointers to the proper input difference row for each group of data units
* within an MCU. For each component, there are Vi groups of Hi data units.
*/
JDIFFROW input_ptr[C_MAX_DATA_UNITS_IN_MCU];
/* Number of input pointers in use for the current MCU. This is the sum
* of all Vi in the MCU.
*/
int num_input_ptrs;
/* Information used for positioning the input pointers within the input
* difference rows.
*/
lhe_input_ptr_info input_ptr_info[C_MAX_DATA_UNITS_IN_MCU];
/* Index of the proper input pointer for each data unit within an MCU */
int input_ptr_index[C_MAX_DATA_UNITS_IN_MCU];
} lhuff_entropy_encoder;
typedef lhuff_entropy_encoder * lhuff_entropy_ptr;
/* Working state while writing an MCU.
* This struct contains all the fields that are needed by subroutines.
*/
typedef struct {
JOCTET * next_output_byte; /* => next byte to write in buffer */
size_t free_in_buffer; /* # of byte spaces remaining in buffer */
savable_state cur; /* Current bit buffer & DC state */
j_compress_ptr cinfo; /* dump_buffer needs access to this */
} working_state;
/* Forward declarations */
METHODDEF(JDIMENSION) encode_mcus_huff (j_compress_ptr cinfo,
JDIFFIMAGE diff_buf,
JDIMENSION MCU_row_num,
JDIMENSION MCU_col_num,
JDIMENSION nMCU);
METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
#ifdef ENTROPY_OPT_SUPPORTED
METHODDEF(JDIMENSION) encode_mcus_gather (j_compress_ptr cinfo,
JDIFFIMAGE diff_buf,
JDIMENSION MCU_row_num,
JDIMENSION MCU_col_num,
JDIMENSION nMCU);
METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
#endif
/*
* Initialize for a Huffman-compressed scan.
* If gather_statistics is TRUE, we do not output anything during the scan,
* just count the Huffman symbols used and generate Huffman code tables.
*/
METHODDEF(void)
start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
{
j_lossless_c_ptr losslsc = (j_lossless_c_ptr) cinfo->codec;
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr) losslsc->entropy_private;
int ci, dctbl, sampn, ptrn, yoffset, xoffset;
jpeg_component_info * compptr;
if (gather_statistics) {
#ifdef ENTROPY_OPT_SUPPORTED
losslsc->entropy_encode_mcus = encode_mcus_gather;
losslsc->pub.entropy_finish_pass = finish_pass_gather;
#else
ERREXIT(cinfo, JERR_NOT_COMPILED);
#endif
} else {
losslsc->entropy_encode_mcus = encode_mcus_huff;
losslsc->pub.entropy_finish_pass = finish_pass_huff;
}
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci];
dctbl = compptr->dc_tbl_no;
if (gather_statistics) {
#ifdef ENTROPY_OPT_SUPPORTED
/* Check for invalid table indexes */
/* (make_c_derived_tbl does this in the other path) */
if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
/* Allocate and zero the statistics tables */
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
if (entropy->count_ptrs[dctbl] == NULL)
entropy->count_ptrs[dctbl] = (long *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
257 * SIZEOF(long));
MEMZERO(entropy->count_ptrs[dctbl], 257 * SIZEOF(long));
#endif
} else {
/* Compute derived values for Huffman tables */
/* We may do this more than once for a table, but it's not expensive */
jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
& entropy->derived_tbls[dctbl]);
}
}
/* Precalculate encoding info for each sample in an MCU of this scan */
for (sampn = 0, ptrn = 0; sampn < cinfo->data_units_in_MCU;) {
compptr = cinfo->cur_comp_info[cinfo->MCU_membership[sampn]];
ci = compptr->component_index;
/* ci = cinfo->MCU_membership[sampn];
compptr = cinfo->cur_comp_info[ci];*/
for (yoffset = 0; yoffset < compptr->MCU_height; yoffset++, ptrn++) {
/* Precalculate the setup info for each input pointer */
entropy->input_ptr_info[ptrn].ci = ci;
entropy->input_ptr_info[ptrn].yoffset = yoffset;
entropy->input_ptr_info[ptrn].MCU_width = compptr->MCU_width;
for (xoffset = 0; xoffset < compptr->MCU_width; xoffset++, sampn++) {
/* Precalculate the input pointer index for each sample */
entropy->input_ptr_index[sampn] = ptrn;
/* Precalculate which tables to use for each sample */
entropy->cur_tbls[sampn] = entropy->derived_tbls[compptr->dc_tbl_no];
entropy->cur_counts[sampn] = entropy->count_ptrs[compptr->dc_tbl_no];
}
}
}
entropy->num_input_ptrs = ptrn;
/* Initialize bit buffer to empty */
entropy->saved.put_buffer = 0;
entropy->saved.put_bits = 0;
/* Initialize restart stuff */
entropy->restarts_to_go = cinfo->restart_interval;
entropy->next_restart_num = 0;
}
/* Outputting bytes to the file */
/* Emit a byte, taking 'action' if must suspend. */
#define emit_byte(state,val,action) \
{ *(state)->next_output_byte++ = (JOCTET) (val); \
if (--(state)->free_in_buffer == 0) \
if (! dump_buffer(state)) \
{ action; } }
LOCAL(boolean)
dump_buffer (working_state * state)
/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
{
struct jpeg_destination_mgr * dest = state->cinfo->dest;
if (! (*dest->empty_output_buffer) (state->cinfo))
return FALSE;
/* After a successful buffer dump, must reset buffer pointers */
state->next_output_byte = dest->next_output_byte;
state->free_in_buffer = dest->free_in_buffer;
return TRUE;
}
/* Outputting bits to the file */
/* Only the right 24 bits of put_buffer are used; the valid bits are
* left-justified in this part. At most 16 bits can be passed to emit_bits
* in one call, and we never retain more than 7 bits in put_buffer
* between calls, so 24 bits are sufficient.
*/
INLINE
LOCAL(boolean)
emit_bits (working_state * state, unsigned int code, int size)
/* Emit some bits; return TRUE if successful, FALSE if must suspend */
{
/* This routine is heavily used, so it's worth coding tightly. */
register IJG_INT32 put_buffer = (IJG_INT32) code;
register int put_bits = state->cur.put_bits;
/* if size is 0, caller used an invalid Huffman table entry */
if (size == 0)
ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
put_buffer &= (((IJG_INT32) 1)<<size) - 1; /* mask off any extra bits in code */
put_bits += size; /* new number of bits in buffer */
put_buffer <<= 24 - put_bits; /* align incoming bits */
put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
while (put_bits >= 8) {
int c = (int) ((put_buffer >> 16) & 0xFF);
emit_byte(state, c, return FALSE);
if (c == 0xFF) { /* need to stuff a zero byte? */
emit_byte(state, 0, return FALSE);
}
put_buffer <<= 8;
put_bits -= 8;
}
state->cur.put_buffer = put_buffer; /* update state variables */
state->cur.put_bits = put_bits;
return TRUE;
}
LOCAL(boolean)
flush_bits (working_state * state)
{
if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
return FALSE;
state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
state->cur.put_bits = 0;
return TRUE;
}
/*
* Emit a restart marker & resynchronize predictions.
*/
LOCAL(boolean)
emit_restart (working_state * state, int restart_num)
{
/* int ci; */
if (! flush_bits(state))
return FALSE;
emit_byte(state, 0xFF, return FALSE);
emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
/* The restart counter is not updated until we successfully write the MCU. */
return TRUE;
}
/*
* Encode and output one nMCU's worth of Huffman-compressed differences.
*/
METHODDEF(JDIMENSION)
encode_mcus_huff (j_compress_ptr cinfo, JDIFFIMAGE diff_buf,
JDIMENSION MCU_row_num, JDIMENSION MCU_col_num,
JDIMENSION nMCU)
{
j_lossless_c_ptr losslsc = (j_lossless_c_ptr) cinfo->codec;
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr) losslsc->entropy_private;
working_state state;
unsigned int mcu_num;
int sampn, ci, yoffset, MCU_width, ptrn;
/* jpeg_component_info * compptr; */
/* Load up working state */
state.next_output_byte = cinfo->dest->next_output_byte;
state.free_in_buffer = cinfo->dest->free_in_buffer;
ASSIGN_STATE(state.cur, entropy->saved);
state.cinfo = cinfo;
/* Emit restart marker if needed */
if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0)
if (! emit_restart(&state, entropy->next_restart_num))
return 0;
}
/* Set input pointer locations based on MCU_col_num */
for (ptrn = 0; ptrn < entropy->num_input_ptrs; ptrn++) {
ci = entropy->input_ptr_info[ptrn].ci;
yoffset = entropy->input_ptr_info[ptrn].yoffset;
MCU_width = entropy->input_ptr_info[ptrn].MCU_width;
entropy->input_ptr[ptrn] =
diff_buf[ci][MCU_row_num + yoffset] + (MCU_col_num * MCU_width);
}
for (mcu_num = 0; mcu_num < nMCU; mcu_num++) {
/* Inner loop handles the samples in the MCU */
for (sampn = 0; sampn < cinfo->data_units_in_MCU; sampn++) {
register int temp, temp2 /* , temp3 */ ;
register int nbits;
c_derived_tbl *dctbl = entropy->cur_tbls[sampn];
/* Encode the difference per section H.1.2.2 */
/* Input the sample difference */
temp = *entropy->input_ptr[entropy->input_ptr_index[sampn]]++;
if (temp & 0x8000) { /* instead of temp < 0 */
temp = (-temp) & 0x7FFF; /* absolute value, mod 2^16 */
if (temp == 0) /* special case: magnitude = 32768 */
temp2 = temp = 0x8000;
temp2 = ~ temp; /* one's complement of magnitude */
} else {
temp &= 0x7FFF; /* abs value mod 2^16 */
temp2 = temp; /* magnitude */
}
/* Find the number of bits needed for the magnitude of the difference */
nbits = 0;
while (temp) {
nbits++;
temp >>= 1;
}
/* Check for out-of-range difference values.
*/
if (nbits > MAX_DIFF_BITS)
ERREXIT(cinfo, JERR_BAD_DIFF);
/* Emit the Huffman-coded symbol for the number of bits */
if (! emit_bits(&state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
return mcu_num;
/* Emit that number of bits of the value, if positive, */
/* or the complement of its magnitude, if negative. */
if (nbits && /* emit_bits rejects calls with size 0 */
nbits != 16) /* special case: no bits should be emitted */
if (! emit_bits(&state, (unsigned int) temp2, nbits))
return mcu_num;
}
/* Completed MCU, so update state */
cinfo->dest->next_output_byte = state.next_output_byte;
cinfo->dest->free_in_buffer = state.free_in_buffer;
ASSIGN_STATE(entropy->saved, state.cur);
/* Update restart-interval state too */
if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) {
entropy->restarts_to_go = cinfo->restart_interval;
entropy->next_restart_num++;
entropy->next_restart_num &= 7;
}
entropy->restarts_to_go--;
}
}
return nMCU;
}
/*
* Finish up at the end of a Huffman-compressed scan.
*/
METHODDEF(void)
finish_pass_huff (j_compress_ptr cinfo)
{
j_lossless_c_ptr losslsc = (j_lossless_c_ptr) cinfo->codec;
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr) losslsc->entropy_private;
working_state state;
/* Load up working state ... flush_bits needs it */
state.next_output_byte = cinfo->dest->next_output_byte;
state.free_in_buffer = cinfo->dest->free_in_buffer;
ASSIGN_STATE(state.cur, entropy->saved);
state.cinfo = cinfo;
/* Flush out the last data */
if (! flush_bits(&state))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
/* Update state */
cinfo->dest->next_output_byte = state.next_output_byte;
cinfo->dest->free_in_buffer = state.free_in_buffer;
ASSIGN_STATE(entropy->saved, state.cur);
}
/*
* Huffman coding optimization.
*
* We first scan the supplied data and count the number of uses of each symbol
* that is to be Huffman-coded. (This process MUST agree with the code above.)
* Then we build a Huffman coding tree for the observed counts.
* Symbols which are not needed at all for the particular image are not
* assigned any code, which saves space in the DHT marker as well as in
* the compressed data.
*/
#ifdef ENTROPY_OPT_SUPPORTED
/*
* Trial-encode one nMCU's worth of Huffman-compressed differences.
* No data is actually output, so no suspension return is possible.
*/
METHODDEF(JDIMENSION)
encode_mcus_gather (j_compress_ptr cinfo, JDIFFIMAGE diff_buf,
JDIMENSION MCU_row_num, JDIMENSION MCU_col_num,
JDIMENSION nMCU)
{
j_lossless_c_ptr losslsc = (j_lossless_c_ptr) cinfo->codec;
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr) losslsc->entropy_private;
unsigned int mcu_num;
int sampn, ci, yoffset, MCU_width, ptrn;
/* jpeg_component_info * compptr; */
/* Take care of restart intervals if needed */
if (cinfo->restart_interval) {
if (entropy->restarts_to_go == 0) {
/* Update restart state */
entropy->restarts_to_go = cinfo->restart_interval;
}
entropy->restarts_to_go--;
}
/* Set input pointer locations based on MCU_col_num */
for (ptrn = 0; ptrn < entropy->num_input_ptrs; ptrn++) {
ci = entropy->input_ptr_info[ptrn].ci;
yoffset = entropy->input_ptr_info[ptrn].yoffset;
MCU_width = entropy->input_ptr_info[ptrn].MCU_width;
entropy->input_ptr[ptrn] =
diff_buf[ci][MCU_row_num + yoffset] + (MCU_col_num * MCU_width);
}
for (mcu_num = 0; mcu_num < nMCU; mcu_num++) {
/* Inner loop handles the samples in the MCU */
for (sampn = 0; sampn < cinfo->data_units_in_MCU; sampn++) {
register int temp;
register int nbits;
/* c_derived_tbl *dctbl = entropy->cur_tbls[sampn]; */
long * counts = entropy->cur_counts[sampn];
/* Encode the difference per section H.1.2.2 */
/* Input the sample difference */
temp = *entropy->input_ptr[entropy->input_ptr_index[sampn]]++;
if (temp & 0x8000) { /* instead of temp < 0 */
temp = (-temp) & 0x7FFF; /* absolute value, mod 2^16 */
if (temp == 0) /* special case: magnitude = 32768 */
temp = 0x8000;
} else
temp &= 0x7FFF; /* abs value mod 2^16 */
/* Find the number of bits needed for the magnitude of the difference */
nbits = 0;
while (temp) {
nbits++;
temp >>= 1;
}
/* Check for out-of-range difference values.
*/
if (nbits > MAX_DIFF_BITS)
ERREXIT(cinfo, JERR_BAD_DIFF);
/* Count the Huffman symbol for the number of bits */
counts[nbits]++;
}
}
return nMCU;
}
/*
* Finish up a statistics-gathering pass and create the new Huffman tables.
*/
METHODDEF(void)
finish_pass_gather (j_compress_ptr cinfo)
{
j_lossless_c_ptr losslsc = (j_lossless_c_ptr) cinfo->codec;
lhuff_entropy_ptr entropy = (lhuff_entropy_ptr) losslsc->entropy_private;
int ci, dctbl;
jpeg_component_info * compptr;
JHUFF_TBL **htblptr;
boolean did_dc[NUM_HUFF_TBLS];
/* It's important not to apply jpeg_gen_optimal_table more than once
* per table, because it clobbers the input frequency counts!
*/
MEMZERO(did_dc, SIZEOF(did_dc));
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
compptr = cinfo->cur_comp_info[ci];
dctbl = compptr->dc_tbl_no;
if (! did_dc[dctbl]) {
htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
if (*htblptr == NULL)
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[dctbl]);
did_dc[dctbl] = TRUE;
}
}
}
#endif /* ENTROPY_OPT_SUPPORTED */
METHODDEF(boolean)
need_optimization_pass (j_compress_ptr cinfo)
{
return TRUE;
}
/*
* Module initialization routine for Huffman entropy encoding.
*/
GLOBAL(void)
jinit_lhuff_encoder (j_compress_ptr cinfo)
{
j_lossless_c_ptr losslsc = (j_lossless_c_ptr) cinfo->codec;
lhuff_entropy_ptr entropy;
int i;
entropy = (lhuff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(lhuff_entropy_encoder));
losslsc->entropy_private = (struct jpeg_entropy_encoder *) entropy;
losslsc->pub.entropy_start_pass = start_pass_huff;
losslsc->pub.need_optimization_pass = need_optimization_pass;
/* Mark tables unallocated */
for (i = 0; i < NUM_HUFF_TBLS; i++) {
entropy->derived_tbls[i] = NULL;
#ifdef ENTROPY_OPT_SUPPORTED
entropy->count_ptrs[i] = NULL;
#endif
}
}
| gpl-2.0 |
alexthemitchell/cmusid | cmusid/chromaprint-1.4.2/tests/test_fingerprint_matcher.cpp | 4 | 6090 | #include <gtest/gtest.h>
#include <algorithm>
#include <vector>
#include <fstream>
#include "fingerprinter_configuration.h"
#include "fingerprint_matcher.h"
#include "utils.h"
namespace chromaprint
{
TEST(FingerprintMatcher, Match)
{
const int32_t fp1_data[] = { 1889975932, -257508804, -240734660, -236548548, -1275161041, -1283549650, -1288796626, -1288845782, -231944646, -227770598, -227596006, -428984294, 1717901370, 1847860266, 1848063034, 1849045002, 978722826, 994451466, 1002856472, 969236792, 969204600, 2026173048, 2026215160, 2026348248, 2022681304, -393368872, -393430280, -393429272, -1462980951, -1471637847, -1475836247, -1475752279, -1408508261, -1404080485, -1404098886, -1395845206, -1260649558, -185335378, -194965314, -262004554, -262000394, -261962634, -253506554, -235820026, -235689979, -210588412, -212693436, -216889788, -216889804, -1288588764, -1288375764, -1285242323, -1309883603, -1309878993, -1578117826, -1276185314, -1284510370, -1284669458, -1284683793, -1284683779, -1284548771, -1285074676, -1284157156, -1217105619, -1242275539, -1246273217, -1246338786, -1112055010, -1118472386, -1117960918, -1088601046, -1084668806, -1101269797, -19311413, -19377013, -27759477, -15127142, -48616006, -65392726, -597817414, -589954150, -657063522, -661311010, -661643170, -644866018, -879632354, -610950114, -610948034, -606815169, -1688355556, -1184907508, -1176519156, -1109817764, -1386707332, -1390831876, -1491496216, -1491500312, -1506163992, -1557658904, -1590950929, -1607728786, -1603534722, -521333698, -525386690, -256956306, -257017634, -257017650, 1370385550, 1403976846, 1391445390, 1458405790, 1449972222, 1584197934, 1585410350, 1581195839, 1602167353, 1568612921, 1551839800, 1558123048, 1490825577, 1486627321, 1485595851, 1485616331, 416066651, 416132123, 416197643, 467577871, 442403855, 440304655, 507478045, 507150399, 507166847, 505077871, 505110766, 1046175982, 1046110463, 1062863055, 1014628813, 1014694876, 477704956, 349775612, 886646376, 886650488, 349707865, 278404699, 282599130, 299636714, 301741482, 284964010, 276582554, 276578442, 276611210, 352309434, 352236794, 352236766, 1442751822, 1476306255, 1191163167, 1191031101, 1459467068, 1585427260, 1581228348, 1579147564, 1579017580, 1579017452, 1582298364, 1607389405, 1574617551, 1557840350, 1560003070, 1551618558, 1551463550, 1547527286, 1547527414, 1547003350, 1549231830, 1557394166, -594291978, -578776362, -578767242, -679434394, -1748979865, -1211650084, -1244225828, -1319663940, -1319270740, -1287814484, -1287798084, -1287793988, -1287851028, -1287784979, -1284680593, -1586531201, -1578114017, -1594890977, -1578186993, -1578187249, -1586510305, -1553074377, -1553144522, -1553407978, -1557344201, -1590738889, -1523711658, -444714402, -436329922, -436395474, -402902226, -402910946, -419680246, -402820069, -402795479, -436208615, -453055479, -461374199, 1685898841, 1681703659, 1681654523, 1681855067, -193064325, -184667797 };
const int32_t fp2_data[] = { -1288792466, -1288780246, -1288845782, -231977158, -226662118, -496031718, 1718564890, 1713642554, 1847931962, 1847996442, 1047928842, 978722826, 1002840075, 969367608, 969204024, 2026173048, 2026149496, 2026348280, 2022686424, -124802344, -393368872, -393429256, -1467171160, -1471365463, -1475836247, -1475836247, -1475752263, -1404080485, -1404080485, -1395841350, -1529080918, -1261174358, -193723970, -194826082, -262004490, -261992330, -253574058, -252457978, -235821049, -235755515, -210583804, -212693436, -216889788, -216820172, -1288658396, -1284181460, -1310407891, -1309884113, -1309813458, -1309682402, -1284506338, -1284510338, -1284677649, -1284683793, -1284552739, -1284549811, -1284026100, -1284222659, -1242271443, -1246404289, -1246273250, -1246338786, -1107860706, -1117956290, -1117960918, -1084668822, -1101409030, -19303205, -19377013, -27757429, -27775861, -14996070, -48615494, -60932182, -597817414, -657063010, -661188130, -661573154, -644865954, -644784098, -611196898, -610950122, -606755777, -606815171, -614615780, -1184909812, -1109420532, -1126592932, -1403478276, -1390823684, -1491495252, -1506032984, -1506065748, -1574436177, -1591213074, -1607729106, -529792978, -521391058, -257087442, -256956290, 1890465998, 1940813966, 1387191438, 1391363470, 1382908302, 1449955518, 1450045678, 1580068910, 1580146991, 1596858925, 1567564345, 1551839801, 1560220201, 1560089131, 1486627627, 1486628186, 1485628490, 1485614154, 411872346, 412003406, 432978958, 467573775, 442401805, 440370205, 507478068, 507166772, 440057957, 437936357, 442196199, 442196199, 450506951, 536477893, 477823445, 477696756, 486089340, 483993196, 483993196, 479805048, 345521737, 345517771, 362299386, 299373994, 299636138, 274464954, 8126602, 8142986, 16568474, 16707770, 12498170, 79602718, 1157539086, 1174381855, 1207805245, 1191031068, 1191153948, 1182699804, 1444852028, 1579066732, 1579148780, 1579017452, 1583342780, 1600050589, 534430095, 534496159, 1568391646, 1568232830, 1568502830, 1547527214, 1547002918, 1551327574, 1551262294, 1553453654, -577387946, -578776490, -545216905, -1752912011, -1748652076, -1782071596, -1780511052, -1327659348, -1319271764, -1317240148, -1287863636, -1287851347, -1288834067, -1288834577, -1322396185, -1603406729, -1594889129, -1594950377, -1594962681, -1594962169, -1586505929, -1553078985, -1574313705, -1574309881, -1574223817, -1557462681, -1486220425, -436329866, -436395410, -440651217, -436456674, -402902770, -402836469, -402820037, -402817991, -436208631, -436225015, -167993525, 1971094107, 1966916347, 1966953050, 1967002202, -176287382, -184668054, -188926869, -188992263, -188777271, -188818231, -33628727 };
// const int32_t fp1_data[] = { 1 << 28, 2 << 28, 3 << 28 };
// const int32_t fp2_data[] = { 4 << 28, 1 << 28, 2 << 28, 3 << 28 };
std::vector<uint32_t> fp1(fp1_data, fp1_data + sizeof(fp1_data)/sizeof(fp1_data[0]));
std::vector<uint32_t> fp2(fp2_data, fp2_data + sizeof(fp2_data)/sizeof(fp2_data[0]));
FingerprintMatcher matcher(CreateFingerprinterConfiguration(CHROMAPRINT_ALGORITHM_TEST2));
matcher.Match(fp1, fp2);
}
};
| gpl-2.0 |
DylanMcCall/Empathy---Hide-contact-groups | tests/empathy-tls-test.c | 4 | 20117 | #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libempathy/empathy-tls-certificate.h>
#include <libempathy/empathy-tls-verifier.h>
#include "test-helper.h"
#include <gcr/gcr.h>
#include <gnutls/gnutls.h>
#include <telepathy-glib/dbus-properties-mixin.h>
#include <telepathy-glib/enums.h>
#include <telepathy-glib/interfaces.h>
#include <telepathy-glib/svc-tls.h>
#include <telepathy-glib/svc-generic.h>
#include <telepathy-glib/telepathy-glib.h>
#define MOCK_TLS_CERTIFICATE_PATH "/mock/certificate"
/* Forward decl */
GType mock_tls_certificate_get_type (void);
#define MOCK_TLS_CERTIFICATE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), mock_tls_certificate_get_type (), \
MockTLSCertificate))
typedef struct _MockTLSCertificate {
GObject parent;
guint state;
GPtrArray *rejections;
gchar *cert_type;
GPtrArray *cert_data;
} MockTLSCertificate;
typedef struct _MockTLSCertificateClass {
GObjectClass parent;
TpDBusPropertiesMixinClass dbus_props_class;
} MockTLSCertificateClass;
enum {
PROP_0,
PROP_STATE,
PROP_REJECTIONS,
PROP_CERTIFICATE_TYPE,
PROP_CERTIFICATE_CHAIN_DATA
};
static void mock_tls_certificate_iface_init (gpointer, gpointer);
G_DEFINE_TYPE_WITH_CODE(MockTLSCertificate, mock_tls_certificate, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_AUTHENTICATION_TLS_CERTIFICATE,
mock_tls_certificate_iface_init)
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
tp_dbus_properties_mixin_iface_init)
)
static void
mock_tls_certificate_init (MockTLSCertificate *self)
{
self->state = TP_TLS_CERTIFICATE_STATE_PENDING;
self->cert_type = g_strdup ("x509");
self->cert_data = g_ptr_array_new_with_free_func((GDestroyNotify) g_array_unref);
self->rejections = g_ptr_array_new ();
}
static void
mock_tls_certificate_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
MockTLSCertificate *self = MOCK_TLS_CERTIFICATE (object);
switch (property_id)
{
case PROP_STATE:
g_value_set_uint (value, self->state);
break;
case PROP_REJECTIONS:
g_value_set_boxed (value, self->rejections);
break;
case PROP_CERTIFICATE_TYPE:
g_value_set_string (value, self->cert_type);
break;
case PROP_CERTIFICATE_CHAIN_DATA:
g_value_set_boxed (value, self->cert_data);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
mock_tls_certificate_finalize (GObject *object)
{
MockTLSCertificate *self = MOCK_TLS_CERTIFICATE (object);
tp_clear_boxed (TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
&self->rejections);
g_free (self->cert_type);
self->cert_type = NULL;
g_ptr_array_unref (self->cert_data);
self->cert_data = NULL;
G_OBJECT_CLASS (mock_tls_certificate_parent_class)->finalize (object);
}
static void
mock_tls_certificate_class_init (MockTLSCertificateClass *klass)
{
GObjectClass *oclass = G_OBJECT_CLASS (klass);
GParamSpec *pspec;
static TpDBusPropertiesMixinPropImpl object_props[] = {
{ "State", "state", NULL },
{ "Rejections", "rejections", NULL },
{ "CertificateType", "certificate-type", NULL },
{ "CertificateChainData", "certificate-chain-data", NULL },
{ NULL }
};
static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
{ TP_IFACE_AUTHENTICATION_TLS_CERTIFICATE,
tp_dbus_properties_mixin_getter_gobject_properties,
NULL,
object_props,
},
{ NULL }
};
oclass->get_property = mock_tls_certificate_get_property;
oclass->finalize = mock_tls_certificate_finalize;
pspec = g_param_spec_uint ("state",
"State of this certificate",
"The state of this TLS certificate.",
0, NUM_TP_TLS_CERTIFICATE_STATES - 1,
TP_TLS_CERTIFICATE_STATE_PENDING,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (oclass, PROP_STATE, pspec);
pspec = g_param_spec_boxed ("rejections",
"The reject reasons",
"The reasons why this TLS certificate has been rejected",
TP_ARRAY_TYPE_TLS_CERTIFICATE_REJECTION_LIST,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (oclass, PROP_REJECTIONS, pspec);
pspec = g_param_spec_string ("certificate-type",
"The certificate type",
"The type of this certificate.",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (oclass, PROP_CERTIFICATE_TYPE, pspec);
pspec = g_param_spec_boxed ("certificate-chain-data",
"The certificate chain data",
"The raw PEM-encoded trust chain of this certificate.",
TP_ARRAY_TYPE_UCHAR_ARRAY_LIST,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (oclass, PROP_CERTIFICATE_CHAIN_DATA, pspec);
klass->dbus_props_class.interfaces = prop_interfaces;
tp_dbus_properties_mixin_class_init (oclass,
G_STRUCT_OFFSET (MockTLSCertificateClass, dbus_props_class));
}
static void
mock_tls_certificate_accept (TpSvcAuthenticationTLSCertificate *base,
DBusGMethodInvocation *context)
{
MockTLSCertificate *self = MOCK_TLS_CERTIFICATE (base);
self->state = TP_TLS_CERTIFICATE_STATE_ACCEPTED;
tp_svc_authentication_tls_certificate_emit_accepted (self);
tp_svc_authentication_tls_certificate_return_from_accept (context);
}
static void
mock_tls_certificate_reject (TpSvcAuthenticationTLSCertificate *base,
const GPtrArray *in_Rejections,
DBusGMethodInvocation *context)
{
MockTLSCertificate *self = MOCK_TLS_CERTIFICATE (base);
self->state = TP_TLS_CERTIFICATE_STATE_REJECTED;
tp_svc_authentication_tls_certificate_emit_rejected (self, in_Rejections);
tp_svc_authentication_tls_certificate_return_from_reject (context);
}
static void
mock_tls_certificate_iface_init (gpointer g_iface,
gpointer iface_data)
{
TpSvcAuthenticationTLSCertificateClass *klass =
(TpSvcAuthenticationTLSCertificateClass*)g_iface;
tp_svc_authentication_tls_certificate_implement_accept (klass,
mock_tls_certificate_accept);
tp_svc_authentication_tls_certificate_implement_reject (klass,
mock_tls_certificate_reject);
}
#if 0
static void
mock_tls_certificate_assert_rejected (MockTLSCertificate *self,
EmpTLSCertificateRejectReason reason)
{
GValueArray *rejection;
EmpTLSCertificateRejectReason rejection_reason;
gchar *rejection_error;
GHashTable *rejection_details;
guint i;
g_assert (self->state == TP_TLS_CERTIFICATE_STATE_REJECTED);
g_assert (self->rejections);
g_assert (self->rejections->len > 0);
for (i = 0; i < self->rejections->len; ++i)
{
rejection = g_ptr_array_index (self->rejections, i);
tp_value_array_unpack (rejection, 3,
G_TYPE_UINT, &rejection_reason,
G_TYPE_STRING, &rejection_error,
TP_HASH_TYPE_STRING_VARIANT_MAP, &rejection_details,
NULL);
g_free (rejection_error);
g_hash_table_unref (rejection_details);
if (rejection_reason == reason)
return;
}
g_assert ("Certificate was not rejected for right reason" && 0);
}
#endif
static MockTLSCertificate*
mock_tls_certificate_new_and_register (TpDBusDaemon *dbus,
const gchar *path,
...)
{
MockTLSCertificate *cert;
GError *error = NULL;
gchar *filename, *contents;
GArray *der;
gsize length;
va_list va;
cert = g_object_new (mock_tls_certificate_get_type (), NULL);
va_start (va, path);
while (path != NULL) {
filename = g_build_filename (g_getenv ("EMPATHY_SRCDIR"),
"tests", "certificates", path, NULL);
g_file_get_contents (filename, &contents, &length, &error);
g_assert_no_error (error);
der = g_array_sized_new (TRUE, TRUE, sizeof (guchar), length);
g_array_append_vals (der, contents, length);
g_ptr_array_add (cert->cert_data, der);
g_free (contents);
g_free (filename);
path = va_arg (va, gchar*);
}
va_end (va);
tp_dbus_daemon_register_object (dbus, MOCK_TLS_CERTIFICATE_PATH, cert);
return cert;
}
/* ----------------------------------------------------------------------------
* TESTS
*/
typedef struct {
GMainLoop *loop;
TpDBusDaemon *dbus;
const gchar *dbus_name;
MockTLSCertificate *mock;
EmpathyTLSCertificate *cert;
GAsyncResult *result;
} Test;
static void
setup (Test *test, gconstpointer data)
{
GError *error = NULL;
test->loop = g_main_loop_new (NULL, FALSE);
test->dbus = tp_dbus_daemon_dup (&error);
g_assert_no_error (error);
test->dbus_name = tp_dbus_daemon_get_unique_name (test->dbus);
test->result = NULL;
test->cert = NULL;
/* No PKCS#11 modules by default, tests add them */
gcr_pkcs11_set_modules (NULL);
}
static void
teardown (Test *test, gconstpointer data)
{
test->dbus_name = NULL;
if (test->mock)
{
tp_dbus_daemon_unregister_object (test->dbus, test->mock);
g_object_unref (test->mock);
test->mock = NULL;
}
if (test->result)
g_object_unref (test->result);
test->result = NULL;
if (test->cert)
g_object_unref (test->cert);
test->cert = NULL;
g_main_loop_unref (test->loop);
test->loop = NULL;
g_object_unref (test->dbus);
test->dbus = NULL;
}
static void
add_pkcs11_module_for_testing (Test *test,
const gchar *filename,
const gchar *subdir)
{
GError *error = NULL;
gchar *args, *path, *directory;
gchar *standalone, *error_output;
gint exit_status;
directory = g_build_filename (g_getenv ("EMPATHY_SRCDIR"),
"tests", "certificates", subdir, NULL);
/*
* Lookup the directory for standalone pkcs11 modules installed by
* gnome-keyring. We use these for testing our implementation.
*/
g_spawn_command_line_sync ("pkg-config --variable=pkcs11standalonedir gcr-3",
&standalone, &error_output, &exit_status, &error);
g_assert_no_error (error);
if (exit_status != 0)
{
g_warning ("couldn't determine standalone pkcs11 module directory: %d: %s",
exit_status, error_output);
g_assert_not_reached ();
}
g_strstrip (standalone);
args = g_strdup_printf ("directory=\"%s\"", directory);
path = g_build_filename (standalone, filename, NULL);
gcr_pkcs11_add_module_from_file (path, args, &error);
g_assert_no_error (error);
g_free (directory);
g_free (standalone);
g_free (error_output);
g_free (args);
g_free (path);
}
static void
fetch_callback_result (GObject *object,
GAsyncResult *res,
gpointer user_data)
{
Test *test = user_data;
g_assert (!test->result);
test->result = g_object_ref (res);
g_main_loop_quit (test->loop);
}
static void
ensure_certificate_proxy (Test *test)
{
GError *error = NULL;
if (test->cert)
return;
/* Create and prepare a certificate */
test->cert = empathy_tls_certificate_new (test->dbus, test->dbus_name,
MOCK_TLS_CERTIFICATE_PATH, &error);
g_assert_no_error (error);
empathy_tls_certificate_prepare_async (test->cert, fetch_callback_result, test);
g_main_loop_run (test->loop);
empathy_tls_certificate_prepare_finish (test->cert, test->result, &error);
g_assert_no_error (error);
/* Clear for any future async stuff */
g_object_unref (test->result);
test->result = NULL;
}
/* A simple test to make sure the test infrastructure is working */
static void
test_certificate_mock_basics (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
GError *error = NULL;
test->mock = mock_tls_certificate_new_and_register (test->dbus,
"dhansak-collabora.cer", NULL);
ensure_certificate_proxy (test);
empathy_tls_certificate_accept_async (test->cert, fetch_callback_result, test);
g_main_loop_run (test->loop);
empathy_tls_certificate_accept_finish (test->cert, test->result, &error);
g_assert_no_error (error);
g_assert (test->mock->state == TP_TLS_CERTIFICATE_STATE_ACCEPTED);
}
static void
test_certificate_verify_success_with_pkcs11_lookup (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
EmpTLSCertificateRejectReason reason = 0;
GError *error = NULL;
EmpathyTLSVerifier *verifier;
const gchar *reference_identities[] = {
"www.collabora.co.uk",
NULL
};
/*
* In this test the mock TLS connection only has one certificate
* not a full certificat echain. The root anchor certificate is
* retrieved from PKCS#11 storage.
*/
test->mock = mock_tls_certificate_new_and_register (test->dbus,
"dhansak-collabora.cer", NULL);
/* We add the collabora directory with the collabora root */
add_pkcs11_module_for_testing (test, "gkm-roots-store-standalone.so",
"collabora-ca");
ensure_certificate_proxy (test);
verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
reference_identities);
empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
g_main_loop_run (test->loop);
empathy_tls_verifier_verify_finish (verifier, test->result, &reason,
NULL, &error);
g_assert_no_error (error);
/* Yay the verification was a success! */
g_clear_error (&error);
g_object_unref (verifier);
}
static void
test_certificate_verify_success_with_full_chain (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
EmpTLSCertificateRejectReason reason = 0;
GError *error = NULL;
EmpathyTLSVerifier *verifier;
const gchar *reference_identities[] = {
"www.collabora.co.uk",
NULL
};
/*
* In this test the mock TLS connection has a full certificate
* chain. We look for an anchor certificate in the chain.
*/
test->mock = mock_tls_certificate_new_and_register (test->dbus,
"dhansak-collabora.cer", "collabora-ca/collabora-ca.cer", NULL);
/* We add the collabora directory with the collabora root */
add_pkcs11_module_for_testing (test, "gkm-roots-store-standalone.so",
"collabora-ca");
ensure_certificate_proxy (test);
verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
reference_identities);
empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
g_main_loop_run (test->loop);
empathy_tls_verifier_verify_finish (verifier, test->result, &reason,
NULL, &error);
g_assert_no_error (error);
/* Yay the verification was a success! */
g_clear_error (&error);
g_object_unref (verifier);
}
static void
test_certificate_verify_root_not_found (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
EmpTLSCertificateRejectReason reason = 0;
GError *error = NULL;
EmpathyTLSVerifier *verifier;
const gchar *reference_identities[] = {
"www.collabora.co.uk",
NULL
};
test->mock = mock_tls_certificate_new_and_register (test->dbus,
"dhansak-collabora.cer", NULL);
/* Note that we're not adding any place to find root certs */
ensure_certificate_proxy (test);
verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
reference_identities);
empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
g_main_loop_run (test->loop);
empathy_tls_verifier_verify_finish (verifier, test->result, &reason,
NULL, &error);
/* And it should say we're self-signed (oddly enough) */
g_assert_error (error, G_IO_ERROR,
EMP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED);
g_clear_error (&error);
g_object_unref (verifier);
}
static void
test_certificate_verify_root_not_anchored (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
EmpTLSCertificateRejectReason reason = 0;
GError *error = NULL;
EmpathyTLSVerifier *verifier;
const gchar *reference_identities[] = {
"www.collabora.co.uk",
NULL
};
test->mock = mock_tls_certificate_new_and_register (test->dbus,
"dhansak-collabora.cer", "collabora-ca/collabora-ca.cer", NULL);
/* Note that we're not adding any place to find root certs */
ensure_certificate_proxy (test);
verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
reference_identities);
empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
g_main_loop_run (test->loop);
empathy_tls_verifier_verify_finish (verifier, test->result, &reason,
NULL, &error);
/* And it should say we're self-signed (oddly enough) */
g_assert_error (error, G_IO_ERROR,
EMP_TLS_CERTIFICATE_REJECT_REASON_SELF_SIGNED);
g_clear_error (&error);
g_object_unref (verifier);
}
static void
test_certificate_verify_identities_invalid (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
EmpTLSCertificateRejectReason reason = 0;
GError *error = NULL;
EmpathyTLSVerifier *verifier;
const gchar *reference_identities[] = {
"invalid.host.name",
NULL
};
test->mock = mock_tls_certificate_new_and_register (test->dbus,
"dhansak-collabora.cer", "collabora-ca/collabora-ca.cer", NULL);
/* We add the collabora directory with the collabora root */
add_pkcs11_module_for_testing (test, "gkm-roots-store-standalone.so",
"collabora-ca");
ensure_certificate_proxy (test);
verifier = empathy_tls_verifier_new (test->cert, "invalid.host.name",
reference_identities);
empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
g_main_loop_run (test->loop);
empathy_tls_verifier_verify_finish (verifier, test->result, &reason,
NULL, &error);
/* And it should say we're self-signed (oddly enough) */
g_assert_error (error, G_IO_ERROR,
EMP_TLS_CERTIFICATE_REJECT_REASON_HOSTNAME_MISMATCH);
g_clear_error (&error);
g_object_unref (verifier);
}
static void
test_certificate_verify_uses_reference_identities (Test *test,
gconstpointer data G_GNUC_UNUSED)
{
EmpTLSCertificateRejectReason reason = 0;
GError *error = NULL;
EmpathyTLSVerifier *verifier;
const gchar *reference_identities[] = {
"invalid.host.name",
NULL
};
test->mock = mock_tls_certificate_new_and_register (test->dbus,
"dhansak-collabora.cer", "collabora-ca/collabora-ca.cer", NULL);
/* We add the collabora directory with the collabora root */
add_pkcs11_module_for_testing (test, "gkm-roots-store-standalone.so",
"collabora-ca");
ensure_certificate_proxy (test);
/* Should be using the reference_identities and not host name for checks */
verifier = empathy_tls_verifier_new (test->cert, "www.collabora.co.uk",
reference_identities);
empathy_tls_verifier_verify_async (verifier, fetch_callback_result, test);
g_main_loop_run (test->loop);
empathy_tls_verifier_verify_finish (verifier, test->result, &reason,
NULL, &error);
/* And it should say we're self-signed (oddly enough) */
g_assert_error (error, G_IO_ERROR,
EMP_TLS_CERTIFICATE_REJECT_REASON_HOSTNAME_MISMATCH);
g_clear_error (&error);
g_object_unref (verifier);
}
int
main (int argc,
char **argv)
{
int result;
test_init (argc, argv);
gnutls_global_init ();
g_test_add ("/tls/certificate_basics", Test, NULL,
setup, test_certificate_mock_basics, teardown);
g_test_add ("/tls/certificate_verify_success_with_pkcs11_lookup", Test, NULL,
setup, test_certificate_verify_success_with_pkcs11_lookup, teardown);
g_test_add ("/tls/certificate_verify_success_with_full_chain", Test, NULL,
setup, test_certificate_verify_success_with_full_chain, teardown);
g_test_add ("/tls/certificate_verify_root_not_found", Test, NULL,
setup, test_certificate_verify_root_not_found, teardown);
g_test_add ("/tls/certificate_verify_root_not_anchored", Test, NULL,
setup, test_certificate_verify_root_not_anchored, teardown);
g_test_add ("/tls/certificate_verify_identities_invalid", Test, NULL,
setup, test_certificate_verify_identities_invalid, teardown);
g_test_add ("/tls/certificate_verify_uses_reference_identities", Test, NULL,
setup, test_certificate_verify_uses_reference_identities, teardown);
result = g_test_run ();
test_deinit ();
return result;
}
| gpl-2.0 |
GalaticStryder/kernel_lge_msm8974 | drivers/media/video/videobuf2-msm-mem.c | 4 | 9410 | /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
*
* Based on videobuf-dma-contig.c,
* (c) 2008 Magnus Damm
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* helper functions for physically contiguous pmem capture buffers
* The functions support contiguous memory allocations using pmem
* kernel API.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/pagemap.h>
#include <linux/sched.h>
#include <linux/io.h>
#include <linux/memory_alloc.h>
#include <media/videobuf2-msm-mem.h>
#include <media/msm_camera.h>
#include <mach/memory.h>
#include <media/videobuf2-core.h>
#include <mach/iommu_domains.h>
#define MAGIC_PMEM 0x0733ac64
#define MAGIC_CHECK(is, should) \
if (unlikely((is) != (should))) { \
pr_err("magic mismatch: %x expected %x\n", (is), (should)); \
BUG(); \
}
#ifdef CONFIG_MSM_CAMERA_DEBUG
#define D(fmt, args...) pr_debug("videobuf-msm-mem: " fmt, ##args)
#else
#define D(fmt, args...) do {} while (0)
#endif
static unsigned long msm_mem_allocate(struct videobuf2_contig_pmem *mem)
{
unsigned long phyaddr;
#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
int rc, len;
mem->client = msm_ion_client_create("camera");
if (IS_ERR((void *)mem->client)) {
pr_err("%s Could not create client\n", __func__);
goto client_failed;
}
mem->ion_handle = ion_alloc(mem->client, mem->size, SZ_4K,
(0x1 << ION_CP_MM_HEAP_ID | 0x1 << ION_IOMMU_HEAP_ID), 0);
if (IS_ERR((void *)mem->ion_handle)) {
pr_err("%s Could not allocate\n", __func__);
goto alloc_failed;
}
rc = ion_map_iommu(mem->client, mem->ion_handle,
-1, 0, SZ_4K, 0,
(unsigned long *)&phyaddr,
(unsigned long *)&len, 0, 0);
if (rc < 0) {
pr_err("%s Could not get physical address\n", __func__);
goto phys_failed;
}
#else
phyaddr = allocate_contiguous_ebi_nomap(mem->size, SZ_4K);
#endif
return phyaddr;
#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
phys_failed:
ion_free(mem->client, mem->ion_handle);
alloc_failed:
ion_client_destroy(mem->client);
client_failed:
return 0;
#endif
}
static int32_t msm_mem_free(struct videobuf2_contig_pmem *mem)
{
int32_t rc = 0;
#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
ion_unmap_iommu(mem->client, mem->ion_handle, -1, 0);
ion_free(mem->client, mem->ion_handle);
ion_client_destroy(mem->client);
#else
free_contiguous_memory_by_paddr(mem->phyaddr);
#endif
return rc;
}
static void videobuf2_vm_close(struct vm_area_struct *vma)
{
struct videobuf2_contig_pmem *mem = vma->vm_private_data;
D("vm_close %p [count=%u,vma=%08lx-%08lx]\n",
mem, mem->count, vma->vm_start, vma->vm_end);
mem->count--;
}
static void videobuf2_vm_open(struct vm_area_struct *vma)
{
struct videobuf2_contig_pmem *mem = vma->vm_private_data;
D("vm_open %p [count=%u,vma=%08lx-%08lx]\n",
mem, mem->count, vma->vm_start, vma->vm_end);
mem->count++;
}
static const struct vm_operations_struct videobuf2_vm_ops = {
.open = videobuf2_vm_open,
.close = videobuf2_vm_close,
};
static void *msm_vb2_mem_ops_alloc(void *alloc_ctx, unsigned long size)
{
struct videobuf2_contig_pmem *mem;
mem = kzalloc(sizeof(*mem), GFP_KERNEL);
if (!mem)
return ERR_PTR(-ENOMEM);
mem->magic = MAGIC_PMEM;
mem->size = PAGE_ALIGN(size);
mem->alloc_ctx = alloc_ctx;
mem->is_userptr = 0;
mem->phyaddr = msm_mem_allocate(mem);
if (!mem->phyaddr) {
pr_err("%s : pmem memory allocation failed\n", __func__);
kfree(mem);
return ERR_PTR(-ENOMEM);
}
mem->mapped_phyaddr = mem->phyaddr;
return mem;
}
static void msm_vb2_mem_ops_put(void *buf_priv)
{
struct videobuf2_contig_pmem *mem = buf_priv;
if (!mem->is_userptr) {
D("%s Freeing memory ", __func__);
msm_mem_free(mem);
}
kfree(mem);
}
int videobuf2_pmem_contig_mmap_get(struct videobuf2_contig_pmem *mem,
struct videobuf2_msm_offset *offset,
enum videobuf2_buffer_type buffer_type,
int path)
{
if (offset)
mem->offset = *offset;
else
memset(&mem->offset, 0, sizeof(struct videobuf2_msm_offset));
mem->buffer_type = buffer_type;
mem->path = path;
return 0;
}
EXPORT_SYMBOL_GPL(videobuf2_pmem_contig_mmap_get);
/**
* videobuf_pmem_contig_user_get() - setup user space memory pointer
* @mem: per-buffer private videobuf-contig-pmem data
* @vb: video buffer to map
*
* This function validates and sets up a pointer to user space memory.
* Only physically contiguous pfn-mapped memory is accepted.
*
* Returns 0 if successful.
*/
int videobuf2_pmem_contig_user_get(struct videobuf2_contig_pmem *mem,
struct videobuf2_msm_offset *offset,
enum videobuf2_buffer_type buffer_type,
uint32_t addr_offset, int path,
struct ion_client *client,
int domain_num)
{
int rc = 0;
#ifdef CONFIG_MSM_MULTIMEDIA_USE_ION
unsigned long len;
#endif
unsigned long paddr = 0;
if (mem->phyaddr != 0)
return 0;
#if defined(CONFIG_MSM_MULTIMEDIA_USE_ION)
mem->ion_handle = ion_import_dma_buf(client, (int)mem->vaddr);
if (IS_ERR_OR_NULL(mem->ion_handle)) {
pr_err("%s ION import failed\n", __func__);
return PTR_ERR(mem->ion_handle);
}
rc = ion_map_iommu(client, mem->ion_handle, domain_num, 0,
SZ_4K, 0, (unsigned long *)&mem->phyaddr, &len, 0, 0);
if (rc < 0)
ion_free(client, mem->ion_handle);
#else
paddr = 0;
#endif
if (offset)
mem->offset = *offset;
else
memset(&mem->offset, 0, sizeof(struct videobuf2_msm_offset));
mem->path = path;
mem->buffer_type = buffer_type;
paddr = mem->phyaddr;
mem->mapped_phyaddr = paddr + addr_offset;
mem->addr_offset = addr_offset;
return rc;
}
EXPORT_SYMBOL_GPL(videobuf2_pmem_contig_user_get);
void videobuf2_pmem_contig_user_put(struct videobuf2_contig_pmem *mem,
struct ion_client *client, int domain_num)
{
if (mem->is_userptr) {
#if defined(CONFIG_MSM_MULTIMEDIA_USE_ION)
ion_unmap_iommu(client, mem->ion_handle,
domain_num, 0);
ion_free(client, mem->ion_handle);
#endif
}
mem->is_userptr = 0;
mem->phyaddr = 0;
mem->size = 0;
mem->mapped_phyaddr = 0;
}
EXPORT_SYMBOL_GPL(videobuf2_pmem_contig_user_put);
static void *msm_vb2_mem_ops_get_userptr(void *alloc_ctx, unsigned long vaddr,
unsigned long size, int write)
{
struct videobuf2_contig_pmem *mem;
mem = kzalloc(sizeof(*mem), GFP_KERNEL);
if (!mem)
return ERR_PTR(-ENOMEM);
mem->magic = MAGIC_PMEM;
mem->is_userptr = 1;
mem->vaddr = (void *)vaddr;
mem->size = size;
mem->alloc_ctx = alloc_ctx;
return mem;
}
static void msm_vb2_mem_ops_put_userptr(void *buf_priv)
{
kfree(buf_priv);
}
static void *msm_vb2_mem_ops_vaddr(void *buf_priv)
{
struct videobuf2_contig_pmem *mem = buf_priv;
return mem->vaddr;
}
static void *msm_vb2_mem_ops_cookie(void *buf_priv)
{
return buf_priv;
}
static unsigned int msm_vb2_mem_ops_num_users(void *buf_priv)
{
struct videobuf2_contig_pmem *mem = buf_priv;
MAGIC_CHECK(mem->magic, MAGIC_PMEM);
return mem->count;
}
static int msm_vb2_mem_ops_mmap(void *buf_priv, struct vm_area_struct *vma)
{
struct videobuf2_contig_pmem *mem;
int retval;
unsigned long size;
D("%s\n", __func__);
mem = buf_priv;
D("mem = 0x%x\n", (u32)mem);
BUG_ON(!mem);
MAGIC_CHECK(mem->magic, MAGIC_PMEM);
/* Try to remap memory */
size = vma->vm_end - vma->vm_start;
size = (size < mem->size) ? size : mem->size;
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
retval = remap_pfn_range(vma, vma->vm_start,
mem->phyaddr >> PAGE_SHIFT,
size, vma->vm_page_prot);
if (retval) {
pr_err("mmap: remap failed with error %d. ", retval);
goto error;
}
mem->vaddr = (void *)vma->vm_start;
vma->vm_ops = &videobuf2_vm_ops;
vma->vm_flags |= VM_DONTEXPAND;
vma->vm_private_data = mem;
D("mmap %p: %08lx-%08lx (%lx) pgoff %08lx\n",
map, vma->vm_start, vma->vm_end,
(long int)mem->bsize, vma->vm_pgoff);
videobuf2_vm_open(vma);
return 0;
error:
return -ENOMEM;
}
static struct vb2_mem_ops msm_vb2_mem_ops = {
.alloc = msm_vb2_mem_ops_alloc,
.put = msm_vb2_mem_ops_put,
.get_userptr = msm_vb2_mem_ops_get_userptr,
.put_userptr = msm_vb2_mem_ops_put_userptr,
.vaddr = msm_vb2_mem_ops_vaddr,
.cookie = msm_vb2_mem_ops_cookie,
.num_users = msm_vb2_mem_ops_num_users,
.mmap = msm_vb2_mem_ops_mmap
};
void videobuf2_queue_pmem_contig_init(struct vb2_queue *q,
enum v4l2_buf_type type,
const struct vb2_ops *ops,
unsigned int size,
void *priv)
{
memset(q, 0, sizeof(struct vb2_queue));
q->mem_ops = &msm_vb2_mem_ops;
q->ops = ops;
q->drv_priv = priv;
q->type = type;
q->io_modes = VB2_MMAP | VB2_USERPTR;
q->io_flags = 0;
q->buf_struct_size = size;
vb2_queue_init(q);
}
EXPORT_SYMBOL_GPL(videobuf2_queue_pmem_contig_init);
unsigned long videobuf2_to_pmem_contig(struct vb2_buffer *vb,
unsigned int plane_no)
{
struct videobuf2_contig_pmem *mem;
mem = vb2_plane_cookie(vb, plane_no);
BUG_ON(!mem);
MAGIC_CHECK(mem->magic, MAGIC_PMEM);
return mem->mapped_phyaddr;
}
EXPORT_SYMBOL_GPL(videobuf2_to_pmem_contig);
MODULE_DESCRIPTION("helper module to manage video4linux PMEM contig buffers");
MODULE_LICENSE("GPL v2");
| gpl-2.0 |
grayj/Jedi-Academy | codemp/renderer/tr_cmds.cpp | 4 | 11421 | //Anything above this #include will be ignored by the compiler
#include "../qcommon/exe_headers.h"
#include "tr_local.h"
#ifdef _XBOX
#include "../cgame/cg_local.h"
#include "../client/cl_data.h"
#endif
/*
=====================
R_PerformanceCounters
=====================
*/
void R_PerformanceCounters( void ) {
#ifndef _XBOX
if ( !r_speeds->integer ) {
// clear the counters even if we aren't printing
Com_Memset( &tr.pc, 0, sizeof( tr.pc ) );
Com_Memset( &backEnd.pc, 0, sizeof( backEnd.pc ) );
return;
}
if (r_speeds->integer == 1) {
const float texSize = R_SumOfUsedImages( qfalse )/(8*1048576.0f)*(r_texturebits->integer?r_texturebits->integer:glConfig.colorBits);
Com_Printf ( "%i/%i shdrs/srfs %i leafs %i vrts %i/%i tris %.2fMB tex %.2f dc\n",
backEnd.pc.c_shaders, backEnd.pc.c_surfaces, tr.pc.c_leafs, backEnd.pc.c_vertexes,
backEnd.pc.c_indexes/3, backEnd.pc.c_totalIndexes/3,
texSize, backEnd.pc.c_overDraw / (float)(glConfig.vidWidth * glConfig.vidHeight) );
} else if (r_speeds->integer == 2) {
Com_Printf ( "(patch) %i sin %i sclip %i sout %i bin %i bclip %i bout\n",
tr.pc.c_sphere_cull_patch_in, tr.pc.c_sphere_cull_patch_clip, tr.pc.c_sphere_cull_patch_out,
tr.pc.c_box_cull_patch_in, tr.pc.c_box_cull_patch_clip, tr.pc.c_box_cull_patch_out );
Com_Printf ( "(md3) %i sin %i sclip %i sout %i bin %i bclip %i bout\n",
tr.pc.c_sphere_cull_md3_in, tr.pc.c_sphere_cull_md3_clip, tr.pc.c_sphere_cull_md3_out,
tr.pc.c_box_cull_md3_in, tr.pc.c_box_cull_md3_clip, tr.pc.c_box_cull_md3_out );
} else if (r_speeds->integer == 3) {
Com_Printf ( "viewcluster: %i\n", tr.viewCluster );
} else if (r_speeds->integer == 4) {
if ( backEnd.pc.c_dlightVertexes ) {
Com_Printf ( "dlight srf:%i culled:%i verts:%i tris:%i\n",
tr.pc.c_dlightSurfaces, tr.pc.c_dlightSurfacesCulled,
backEnd.pc.c_dlightVertexes, backEnd.pc.c_dlightIndexes / 3 );
}
}
else if (r_speeds->integer == 5 )
{
Com_Printf ("zFar: %.0f\n", tr.viewParms.zFar );
}
else if (r_speeds->integer == 6 )
{
Com_Printf ("flare adds:%i tests:%i renders:%i\n",
backEnd.pc.c_flareAdds, backEnd.pc.c_flareTests, backEnd.pc.c_flareRenders );
}
else if (r_speeds->integer == 7) {
const float texSize = R_SumOfUsedImages(qtrue) / (1048576.0f);
const float backBuff= glConfig.vidWidth * glConfig.vidHeight * glConfig.colorBits / (8.0f * 1024*1024);
const float depthBuff= glConfig.vidWidth * glConfig.vidHeight * glConfig.depthBits / (8.0f * 1024*1024);
const float stencilBuff= glConfig.vidWidth * glConfig.vidHeight * glConfig.stencilBits / (8.0f * 1024*1024);
Com_Printf ( "Tex MB %.2f + buffers %.2f MB = Total %.2fMB\n",
texSize, backBuff*2+depthBuff+stencilBuff, texSize+backBuff*2+depthBuff+stencilBuff);
}
#endif
Com_Memset( &tr.pc, 0, sizeof( tr.pc ) );
Com_Memset( &backEnd.pc, 0, sizeof( backEnd.pc ) );
}
/*
====================
R_InitCommandBuffers
====================
*/
void R_InitCommandBuffers( void ) {
}
/*
====================
R_ShutdownCommandBuffers
====================
*/
void R_ShutdownCommandBuffers( void ) {
}
/*
====================
R_IssueRenderCommands
====================
*/
void R_IssueRenderCommands( qboolean runPerformanceCounters ) {
renderCommandList_t *cmdList;
cmdList = &backEndData->commands;
assert(cmdList); // bk001205
// add an end-of-list command
*(int *)(cmdList->cmds + cmdList->used) = RC_END_OF_LIST;
// clear it out, in case this is a sync and not a buffer flip
cmdList->used = 0;
// at this point, the back end thread is idle, so it is ok
// to look at it's performance counters
if ( runPerformanceCounters ) {
R_PerformanceCounters();
}
// actually start the commands going
if ( !r_skipBackEnd->integer ) {
// let it start on the new batch
RB_ExecuteRenderCommands( cmdList->cmds );
}
}
/*
====================
R_SyncRenderThread
Issue any pending commands and wait for them to complete.
After exiting, the render thread will have completed its work
and will remain idle and the main thread is free to issue
OpenGL calls until R_IssueRenderCommands is called.
====================
*/
void R_SyncRenderThread( void ) {
#ifndef _XBOX
if ( !tr.registered ) {
return;
}
R_IssueRenderCommands( qfalse );
#endif
}
/*
============
R_GetCommandBuffer
make sure there is enough command space, waiting on the
render thread if needed.
============
*/
void *R_GetCommandBuffer( int bytes ) {
renderCommandList_t *cmdList;
cmdList = &backEndData->commands;
// always leave room for the end of list command
if ( cmdList->used + bytes + 4 > MAX_RENDER_COMMANDS ) {
#if defined(_DEBUG) && defined(_XBOX)
Com_Printf(S_COLOR_RED"Command buffer overflow! Tell Brian.\n");
#endif
if ( bytes > MAX_RENDER_COMMANDS - 4 ) {
Com_Error( ERR_FATAL, "R_GetCommandBuffer: bad size %i", bytes );
}
// if we run out of room, just start dropping commands
return NULL;
}
cmdList->used += bytes;
return cmdList->cmds + cmdList->used - bytes;
}
/*
=============
R_AddDrawSurfCmd
=============
*/
void R_AddDrawSurfCmd( drawSurf_t *drawSurfs, int numDrawSurfs ) {
drawSurfsCommand_t *cmd;
cmd = (drawSurfsCommand_t *) R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
return;
}
cmd->commandId = RC_DRAW_SURFS;
cmd->drawSurfs = drawSurfs;
cmd->numDrawSurfs = numDrawSurfs;
cmd->refdef = tr.refdef;
cmd->viewParms = tr.viewParms;
#ifdef _XBOX
cmd->clientNum = ClientManager::ActiveClientNum();
#endif
}
/*
=============
RE_SetColor
Passing NULL will set the color to white
=============
*/
void RE_SetColor( const float *rgba ) {
setColorCommand_t *cmd;
cmd = (setColorCommand_t *) R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
return;
}
cmd->commandId = RC_SET_COLOR;
if ( !rgba ) {
static float colorWhite[4] = { 1, 1, 1, 1 };
rgba = colorWhite;
}
cmd->color[0] = rgba[0];
cmd->color[1] = rgba[1];
cmd->color[2] = rgba[2];
cmd->color[3] = rgba[3];
}
/*
=============
RE_StretchPic
=============
*/
void RE_StretchPic ( float x, float y, float w, float h,
float s1, float t1, float s2, float t2, qhandle_t hShader ) {
stretchPicCommand_t *cmd;
cmd = (stretchPicCommand_t *) R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
return;
}
cmd->commandId = RC_STRETCH_PIC;
cmd->shader = R_GetShaderByHandle( hShader );
cmd->x = x;
cmd->y = y;
cmd->w = w;
cmd->h = h;
cmd->s1 = s1;
cmd->t1 = t1;
cmd->s2 = s2;
cmd->t2 = t2;
}
/*
=============
RE_RotatePic
=============
*/
void RE_RotatePic ( float x, float y, float w, float h,
float s1, float t1, float s2, float t2,float a, qhandle_t hShader ) {
rotatePicCommand_t *cmd;
cmd = (rotatePicCommand_t *) R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
return;
}
cmd->commandId = RC_ROTATE_PIC;
cmd->shader = R_GetShaderByHandle( hShader );
cmd->x = x;
cmd->y = y;
cmd->w = w;
cmd->h = h;
cmd->s1 = s1;
cmd->t1 = t1;
cmd->s2 = s2;
cmd->t2 = t2;
cmd->a = a;
}
/*
=============
RE_RotatePic2
=============
*/
void RE_RotatePic2 ( float x, float y, float w, float h,
float s1, float t1, float s2, float t2,float a, qhandle_t hShader ) {
rotatePicCommand_t *cmd;
cmd = (rotatePicCommand_t *) R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
return;
}
cmd->commandId = RC_ROTATE_PIC2;
cmd->shader = R_GetShaderByHandle( hShader );
cmd->x = x;
cmd->y = y;
cmd->w = w;
cmd->h = h;
cmd->s1 = s1;
cmd->t1 = t1;
cmd->s2 = s2;
cmd->t2 = t2;
cmd->a = a;
}
void RE_RenderWorldEffects(void)
{
drawBufferCommand_t *cmd;
cmd = (drawBufferCommand_t *)R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
return;
}
cmd->commandId = RC_WORLD_EFFECTS;
}
void RE_RenderAutoMap(void)
{
drawBufferCommand_t *cmd;
cmd = (drawBufferCommand_t *)R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd )
{
return;
}
cmd->commandId = RC_AUTO_MAP;
}
/*
====================
RE_BeginFrame
If running in stereo, RE_BeginFrame will be called twice
for each RE_EndFrame
====================
*/
void RE_BeginFrame( stereoFrame_t stereoFrame ) {
drawBufferCommand_t *cmd;
if ( !tr.registered ) {
return;
}
glState.finishCalled = qfalse;
tr.frameCount++;
tr.frameSceneNum = 0;
//
// do overdraw measurement
//
#ifndef _XBOX
if ( r_measureOverdraw->integer )
{
if ( glConfig.stencilBits < 4 )
{
Com_Printf ("Warning: not enough stencil bits to measure overdraw: %d\n", glConfig.stencilBits );
Cvar_Set( "r_measureOverdraw", "0" );
r_measureOverdraw->modified = qfalse;
}
else if ( r_shadows->integer == 2 )
{
Com_Printf ("Warning: stencil shadows and overdraw measurement are mutually exclusive\n" );
Cvar_Set( "r_measureOverdraw", "0" );
r_measureOverdraw->modified = qfalse;
}
else
{
R_SyncRenderThread();
qglEnable( GL_STENCIL_TEST );
qglStencilMask( ~0U );
qglClearStencil( 0U );
qglStencilFunc( GL_ALWAYS, 0U, ~0U );
qglStencilOp( GL_KEEP, GL_INCR, GL_INCR );
}
r_measureOverdraw->modified = qfalse;
}
else
{
// this is only reached if it was on and is now off
if ( r_measureOverdraw->modified ) {
R_SyncRenderThread();
qglDisable( GL_STENCIL_TEST );
}
r_measureOverdraw->modified = qfalse;
}
#endif
//
// texturemode stuff
//
if ( r_textureMode->modified || r_ext_texture_filter_anisotropic->modified) {
R_SyncRenderThread();
GL_TextureMode( r_textureMode->string );
r_textureMode->modified = qfalse;
r_ext_texture_filter_anisotropic->modified = qfalse;
}
//
// gamma stuff
//
if ( r_gamma->modified ) {
r_gamma->modified = qfalse;
R_SyncRenderThread();
R_SetColorMappings();
}
// check for errors
if ( !r_ignoreGLErrors->integer ) {
int err;
R_SyncRenderThread();
if ( ( err = qglGetError() ) != GL_NO_ERROR ) {
Com_Error( ERR_FATAL, "RE_BeginFrame() - glGetError() failed (0x%x)!\n", err );
}
}
//
// draw buffer stuff
//
cmd = (drawBufferCommand_t *) R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
return;
}
cmd->commandId = RC_DRAW_BUFFER;
if ( glConfig.stereoEnabled ) {
if ( stereoFrame == STEREO_LEFT ) {
cmd->buffer = (int)GL_BACK_LEFT;
} else if ( stereoFrame == STEREO_RIGHT ) {
cmd->buffer = (int)GL_BACK_RIGHT;
} else {
Com_Error( ERR_FATAL, "RE_BeginFrame: Stereo is enabled, but stereoFrame was %i", stereoFrame );
}
} else {
if ( stereoFrame != STEREO_CENTER ) {
Com_Error( ERR_FATAL, "RE_BeginFrame: Stereo is disabled, but stereoFrame was %i", stereoFrame );
}
// if ( !Q_stricmp( r_drawBuffer->string, "GL_FRONT" ) ) {
// cmd->buffer = (int)GL_FRONT;
// } else
{
cmd->buffer = (int)GL_BACK;
}
}
}
/*
=============
RE_EndFrame
Returns the number of msec spent in the back end
=============
*/
void RE_EndFrame( int *frontEndMsec, int *backEndMsec ) {
swapBuffersCommand_t *cmd;
if ( !tr.registered ) {
return;
}
cmd = (swapBuffersCommand_t *) R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
return;
}
cmd->commandId = RC_SWAP_BUFFERS;
#ifdef _XBOX
if (!qglBeginFrame()) return;
#endif
R_IssueRenderCommands( qtrue );
#ifdef _XBOX
qglEndFrame();
#endif
// use the other buffers next frame, because another CPU
// may still be rendering into the current ones
R_ToggleSmpFrame();
if ( frontEndMsec ) {
*frontEndMsec = tr.frontEndMsec;
}
tr.frontEndMsec = 0;
if ( backEndMsec ) {
*backEndMsec = backEnd.pc.msec;
}
backEnd.pc.msec = 0;
}
| gpl-2.0 |
azunite/wireshark_1023 | reordercap.c | 4 | 11637 | /* Reorder the frames from an input dump file, and write to output dump file.
* Martin Mathieson and Jakub Jawadzki
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef HAVE_LIBZ
#include <zlib.h> /* to get the libz version number */
#endif
#include "wtap.h"
#ifndef HAVE_GETOPT_LONG
#include "wsutil/wsgetopt.h"
#endif
#include <wsutil/crash_info.h>
#include <wsutil/file_util.h>
#include <wsutil/ws_diag_control.h>
#include <wsutil/ws_version_info.h>
/* Show command-line usage */
static void
print_usage(FILE *output)
{
fprintf(output, "\n");
fprintf(output, "Usage: reordercap [options] <infile> <outfile>\n");
fprintf(output, "\n");
fprintf(output, "Options:\n");
fprintf(output, " -n don't write to output file if the input file is ordered.\n");
fprintf(output, " -h display this help and exit.\n");
}
/* Remember where this frame was in the file */
typedef struct FrameRecord_t {
gint64 offset;
guint num;
nstime_t frame_time;
} FrameRecord_t;
/**************************************************/
/* Debugging only */
/* Enable this symbol to see debug output */
/* #define REORDER_DEBUG */
#ifdef REORDER_DEBUG
#define DEBUG_PRINT printf
#else
#define DEBUG_PRINT(...)
#endif
/**************************************************/
static void
frame_write(FrameRecord_t *frame, wtap *wth, wtap_dumper *pdh,
struct wtap_pkthdr *phdr, Buffer *buf, const char *infile)
{
int err;
gchar *err_info;
DEBUG_PRINT("\nDumping frame (offset=%" G_GINT64_MODIFIER "u)\n",
frame->offset);
/* Re-read the frame from the stored location */
if (!wtap_seek_read(wth, frame->offset, phdr, buf, &err, &err_info)) {
if (err != 0) {
/* Print a message noting that the read failed somewhere along the line. */
fprintf(stderr,
"reordercap: An error occurred while re-reading \"%s\": %s.\n",
infile, wtap_strerror(err));
if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
}
exit(1);
}
}
/* Copy, and set length and timestamp from item. */
/* TODO: remove when wtap_seek_read() fills in phdr,
including time stamps, for all file types */
phdr->ts = frame->frame_time;
/* Dump frame to outfile */
if (!wtap_dump(pdh, phdr, ws_buffer_start_ptr(buf), &err, &err_info)) {
fprintf(stderr, "reordercap: Error (%s) writing frame to outfile\n",
wtap_strerror(err));
if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
}
exit(1);
}
}
/* Comparing timestamps between 2 frames.
negative if (t1 < t2)
zero if (t1 == t2)
positive if (t1 > t2)
*/
static int
frames_compare(gconstpointer a, gconstpointer b)
{
const FrameRecord_t *frame1 = *(const FrameRecord_t *const *) a;
const FrameRecord_t *frame2 = *(const FrameRecord_t *const *) b;
const nstime_t *time1 = &frame1->frame_time;
const nstime_t *time2 = &frame2->frame_time;
return nstime_cmp(time1, time2);
}
static void
get_reordercap_compiled_info(GString *str)
{
/* LIBZ */
g_string_append(str, ", ");
#ifdef HAVE_LIBZ
g_string_append(str, "with libz ");
#ifdef ZLIB_VERSION
g_string_append(str, ZLIB_VERSION);
#else /* ZLIB_VERSION */
g_string_append(str, "(version unknown)");
#endif /* ZLIB_VERSION */
#else /* HAVE_LIBZ */
g_string_append(str, "without libz");
#endif /* HAVE_LIBZ */
}
static void
get_reordercap_runtime_info(GString *str)
{
/* zlib */
#if defined(HAVE_LIBZ) && !defined(_WIN32)
g_string_append_printf(str, ", with libz %s", zlibVersion());
#endif
}
/********************************************************************/
/* Main function. */
/********************************************************************/
int
main(int argc, char *argv[])
{
GString *comp_info_str;
GString *runtime_info_str;
wtap *wth = NULL;
wtap_dumper *pdh = NULL;
struct wtap_pkthdr dump_phdr;
Buffer buf;
int err;
gchar *err_info;
gint64 data_offset;
const struct wtap_pkthdr *phdr;
guint wrong_order_count = 0;
gboolean write_output_regardless = TRUE;
guint i;
wtapng_section_t *shb_hdr = NULL;
wtapng_iface_descriptions_t *idb_inf = NULL;
wtapng_name_res_t *nrb_hdr = NULL;
GPtrArray *frames;
FrameRecord_t *prevFrame = NULL;
int opt;
DIAG_OFF(cast-qual)
static const struct option long_options[] = {
{(char *)"help", no_argument, NULL, 'h'},
{(char *)"version", no_argument, NULL, 'v'},
{0, 0, 0, 0 }
};
DIAG_ON(cast-qual)
int file_count;
char *infile;
char *outfile;
/* Get the compile-time version information string */
comp_info_str = get_compiled_version_info(NULL, get_reordercap_compiled_info);
/* Get the run-time version information string */
runtime_info_str = get_runtime_version_info(get_reordercap_runtime_info);
/* Add it to the information to be reported on a crash. */
ws_add_crash_info("Reordercap (Wireshark) %s\n"
"\n"
"%s"
"\n"
"%s",
get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
/* Process the options first */
while ((opt = getopt_long(argc, argv, "hnv", long_options, NULL)) != -1) {
switch (opt) {
case 'n':
write_output_regardless = FALSE;
break;
case 'h':
printf("Reordercap (Wireshark) %s\n"
"Reorder timestamps of input file frames into output file.\n"
"See http://www.wireshark.org for more information.\n",
get_ws_vcs_version_info());
print_usage(stdout);
exit(0);
case 'v':
show_version("Reordercap (Wireshark)", comp_info_str, runtime_info_str);
g_string_free(comp_info_str, TRUE);
g_string_free(runtime_info_str, TRUE);
exit(0);
case '?':
print_usage(stderr);
exit(1);
}
}
/* Remaining args are file names */
file_count = argc - optind;
if (file_count == 2) {
infile = argv[optind];
outfile = argv[optind+1];
}
else {
print_usage(stderr);
exit(1);
}
/* Open infile */
/* TODO: if reordercap is ever changed to give the user a choice of which
open_routine reader to use, then the following needs to change. */
wth = wtap_open_offline(infile, WTAP_TYPE_AUTO, &err, &err_info, TRUE);
if (wth == NULL) {
fprintf(stderr, "reordercap: Can't open %s: %s\n", infile,
wtap_strerror(err));
if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
}
exit(1);
}
DEBUG_PRINT("file_type_subtype is %u\n", wtap_file_type_subtype(wth));
shb_hdr = wtap_file_get_shb_for_new_file(wth);
idb_inf = wtap_file_get_idb_info(wth);
nrb_hdr = wtap_file_get_nrb_for_new_file(wth);
/* Open outfile (same filetype/encap as input file) */
pdh = wtap_dump_open_ng(outfile, wtap_file_type_subtype(wth), wtap_file_encap(wth),
65535, FALSE, shb_hdr, idb_inf, nrb_hdr, &err);
g_free(idb_inf);
idb_inf = NULL;
if (pdh == NULL) {
fprintf(stderr, "reordercap: Failed to open output file: (%s) - error %s\n",
outfile, wtap_strerror(err));
wtap_free_shb(shb_hdr);
wtap_free_nrb(nrb_hdr);
exit(1);
}
/* Allocate the array of frame pointers. */
frames = g_ptr_array_new();
/* Read each frame from infile */
while (wtap_read(wth, &err, &err_info, &data_offset)) {
FrameRecord_t *newFrameRecord;
phdr = wtap_phdr(wth);
newFrameRecord = g_slice_new(FrameRecord_t);
newFrameRecord->num = frames->len + 1;
newFrameRecord->offset = data_offset;
if (phdr->presence_flags & WTAP_HAS_TS) {
newFrameRecord->frame_time = phdr->ts;
} else {
nstime_set_unset(&newFrameRecord->frame_time);
}
if (prevFrame && frames_compare(&newFrameRecord, &prevFrame) < 0) {
wrong_order_count++;
}
g_ptr_array_add(frames, newFrameRecord);
prevFrame = newFrameRecord;
}
if (err != 0) {
/* Print a message noting that the read failed somewhere along the line. */
fprintf(stderr,
"reordercap: An error occurred while reading \"%s\": %s.\n",
infile, wtap_strerror(err));
if (err_info != NULL) {
fprintf(stderr, "(%s)\n", err_info);
g_free(err_info);
}
}
printf("%u frames, %u out of order\n", frames->len, wrong_order_count);
/* Sort the frames */
if (wrong_order_count > 0) {
g_ptr_array_sort(frames, frames_compare);
}
/* Write out each sorted frame in turn */
wtap_phdr_init(&dump_phdr);
ws_buffer_init(&buf, 1500);
for (i = 0; i < frames->len; i++) {
FrameRecord_t *frame = (FrameRecord_t *)frames->pdata[i];
/* Avoid writing if already sorted and configured to */
if (write_output_regardless || (wrong_order_count > 0)) {
frame_write(frame, wth, pdh, &dump_phdr, &buf, infile);
}
g_slice_free(FrameRecord_t, frame);
}
wtap_phdr_cleanup(&dump_phdr);
ws_buffer_free(&buf);
if (!write_output_regardless && (wrong_order_count == 0)) {
printf("Not writing output file because input file is already in order!\n");
}
/* Free the whole array */
g_ptr_array_free(frames, TRUE);
/* Close outfile */
if (!wtap_dump_close(pdh, &err)) {
fprintf(stderr, "reordercap: Error closing %s: %s\n", outfile,
wtap_strerror(err));
wtap_free_shb(shb_hdr);
wtap_free_nrb(nrb_hdr);
exit(1);
}
wtap_free_shb(shb_hdr);
wtap_free_nrb(nrb_hdr);
/* Finally, close infile */
wtap_fdclose(wth);
return 0;
}
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/
| gpl-2.0 |
evaautomation/glibc-linaro | nptl/sem_init.c | 4 | 2560 | /* Copyright (C) 2002-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <errno.h>
#include <semaphore.h>
#include <shlib-compat.h>
#include "semaphoreP.h"
#include <kernel-features.h>
#include <futex-internal.h>
int
__new_sem_init (sem_t *sem, int pshared, unsigned int value)
{
/* Parameter sanity check. */
if (__glibc_unlikely (value > SEM_VALUE_MAX))
{
__set_errno (EINVAL);
return -1;
}
pshared = pshared != 0 ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE;
int err = futex_supports_pshared (pshared);
if (err != 0)
{
__set_errno (err);
return -1;
}
/* Map to the internal type. */
struct new_sem *isem = (struct new_sem *) sem;
/* Use the values the caller provided. */
#if __HAVE_64B_ATOMICS
isem->data = value;
#else
isem->value = value << SEM_VALUE_SHIFT;
/* pad is used as a mutex on pre-v9 sparc and ignored otherwise. */
isem->pad = 0;
isem->nwaiters = 0;
#endif
isem->private = (pshared == PTHREAD_PROCESS_PRIVATE
? FUTEX_PRIVATE : FUTEX_SHARED);
return 0;
}
versioned_symbol (libpthread, __new_sem_init, sem_init, GLIBC_2_1);
#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
int
attribute_compat_text_section
__old_sem_init (sem_t *sem, int pshared, unsigned int value)
{
/* Parameter sanity check. */
if (__glibc_unlikely (value > SEM_VALUE_MAX))
{
__set_errno (EINVAL);
return -1;
}
/* Map to the internal type. */
struct old_sem *isem = (struct old_sem *) sem;
/* Use the value the user provided. */
isem->value = value;
/* We cannot store the PSHARED attribute. So we always use the
operations needed for shared semaphores. */
return 0;
}
compat_symbol (libpthread, __old_sem_init, sem_init, GLIBC_2_0);
#endif
| gpl-2.0 |
beretta42/fuzix | Kernel/platform-rpipico/rawflash.c | 4 | 1072 | #include <stdint.h>
#include <stddef.h>
#include <kernel.h>
#include "lib/dhara/nand.h"
#include "picosdk.h"
#include <hardware/flash.h>
#include "globals.h"
int dhara_nand_erase(const struct dhara_nand *n, dhara_block_t b,
dhara_error_t *err)
{
irqflags_t f = di();
flash_range_erase(FLASH_OFFSET + (b*4096), 4096);
irqrestore(f);
if (err)
*err = DHARA_E_NONE;
return 0;
}
int dhara_nand_prog(const struct dhara_nand *n, dhara_page_t p,
const uint8_t *data,
dhara_error_t *err)
{
irqflags_t f = di();
flash_range_program(FLASH_OFFSET + (p*512), data, 512);
irqrestore(f);
if (err)
*err = DHARA_E_NONE;
return 0;
}
int dhara_nand_read(const struct dhara_nand *n, dhara_page_t p,
size_t offset, size_t length,
uint8_t *data,
dhara_error_t *err)
{
memcpy(data,
(uint8_t*)XIP_NOCACHE_NOALLOC_BASE + FLASH_OFFSET + (p*512) + offset,
length);
if (err)
*err = DHARA_E_NONE;
return 0;
}
/* vim: sw=4 ts=4 et: */
| gpl-2.0 |
CentOS/sig-core-t_ltp | testcases/kernel/io/direct_io/dma_thread_diotest7.c | 4 | 13288 | /******************************************************************************/
/* Copyright (c) Tim LaBerge <tim.laberge@quantum.com>, 2009 */
/* */
/* 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. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
/* the GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* File: dma_thread_diotest7.c */
/* */
/* Description: The man page for open(2) states the following: */
/* O_DIRECT (Since Linux 2.6.10). Try to minimize cache effects of the I/O */
/* to and from this file. In general this will degrade performance, but it */
/* is useful in special situations, such as when applications do their own */
/* caching. File I/O is done directly to/from user space buffers. The I/O is*/
/* synchronous, that is, at the completion of a read(2) or write(2), data is*/
/* guranteed to have been transferred. Under Linux 2.4 transfer sizes, and */
/* the alignment of user buffer and file offset must all be multiples of */
/* the logical block size of the file system. Under Linux 2.6 alignment to */
/* 512-byte bound-aries suffices. */
/* However, it appears that data corruption may occur when a multithreaded */
/* process reads into a non-page size aligned user buffer. A test program */
/* which reliably reproduces the problem on ext3 and xfs is attached. The */
/* program creates, patterns, reads, and verify a series of files. In the */
/* read phase, a file is opened with O_DIRECT n times, where n is the */
/* number of cpu's. A single buffer large enough to contain the file is */
/* allocated and patterned with data not found in any of the files. The */
/* alignment of the buffer is controlled by a command line option. Each file*/
/* is read in parallel by n threads, where n is the number of cpu's. Thread */
/* 0 reads the first page of data from the file into the first page of the */
/* buffer, thread 1 reads the second page of data in to the second page of */
/* the buffer, and so on. Thread n - 1 reads the remainder of the file into*/
/* the remainder of the buffer. */
/* After a thread reads data into the buffer, it immediately verifies that */
/* the contents of the buffer are correct. If the buffer contains corrupt */
/* data, the thread dumps the data surrounding the corruption and calls */
/* abort(). Otherwise, the thread exits. */
/* Crucially, before the reader threads are dispatched, another thread is */
/* started which calls fork()/msleep() in a loop until all reads are compl- */
/* eted. The child created by fork() does nothing but call exit(0). A comm- */
/* and line option controls whether the buffer is aligned. In the case wh- */
/* ere the buffer is aligned on a page boundary, all is well. In the case */
/* where the buffer is aligned on a page + 512 byte offset, corruption is */
/* seen frequently. */
/* I believe that what is happening is that in the direct IO path, because */
/* the user's buffer is not aligned, some user pages are being mapped twice.*/
/* When a fork() happens in between the calls to map the page, the page will*/
/* be marked as COW. When the second map happens (via get_user_pages()), a */
/* new physical page will be allocated and copied. Thus, there is a race */
/* between the completion of the first read from disk (and write to the user*/
/* page) and get_user_pages() mapping the page for the second time. If the */
/* write does not complete before the page is copied, the user will see */
/* stale data in the first 512 bytes of this page of their buffer. Indeed, */
/* this is corruption most frequently seen. (It's also possible for the race*/
/* to be lost the other way, so that the last 3584 bytes of the page are */
/* stale.) */
/* The attached program (which is a heavily modified version of a program */
/* provided by a customer seeing this problem) reliably reproduces the pro- */
/* blem on any multicore linux machine on both ext3 and xfs, although any */
/* filesystem using the generic blockdev_direct_IO() routine is probably */
/* vulnerable. I've seen a few threads that mention the potential for this */
/* kind of problem, but no definitive solution or workaround (other than */
/* "Don't do that"). */
/* http://marc.info/?l=linux-mm&m=122668235304637&w=2 */
/* */
/* Total Tests: 1 */
/* */
/* Test Name: dma_thread_diotest7 */
/* */
/* Author: Tim LaBerge <tim.laberge@quantum.com> */
/* */
/* History: Reported - Jan 07 2009 - Li Zefan <lizf@cn.fujitsu.com> */
/* Ported - Jan 23 2009 - Subrata <subrata@linux.vnet.ibm.com> */
/* */
/******************************************************************************/
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <memory.h>
#include <pthread.h>
#include <getopt.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#define FILESIZE (12*1024*1024)
#define READSIZE (1024*1024)
#define FILENAME "_dma_thread_test_%.04d.tmp"
#define FILECOUNT 100
#define MIN_WORKERS 2
#define MAX_WORKERS 256
#define PAGE_SIZE getpagesize()
#define true 1
#define false 0
typedef int bool;
bool done = false;
int workers = 2;
#define PATTERN (0xfa)
static void usage(void)
{
fprintf(stderr,
"\nUsage: dma_thread [-h | -a <alignment> [ -w <workers>]\n"
"\nWith no arguments, generate test files and exit.\n"
"-h Display this help and exit.\n"
"-a align read buffer to offset <alignment>.\n"
"-w number of worker threads, 2 (default) to 256,\n"
" defaults to number of cores.\n\n"
"Run first with no arguments to generate files.\n"
"Then run with -a <alignment> = 512 or 0. \n");
}
typedef struct {
pthread_t tid;
int worker_number;
int fd;
int offset;
int length;
int pattern;
unsigned char *buffer;
} worker_t;
void *worker_thread(void *arg)
{
int bytes_read;
int i, k;
worker_t *worker = (worker_t *) arg;
int offset = worker->offset;
int fd = worker->fd;
unsigned char *buffer = worker->buffer;
int pattern = worker->pattern;
int length = worker->length;
if (lseek(fd, offset, SEEK_SET) < 0) {
fprintf(stderr, "Failed to lseek to %d on fd %d: %s.\n",
offset, fd, strerror(errno));
exit(1);
}
bytes_read = read(fd, buffer, length);
if (bytes_read != length) {
fprintf(stderr, "read failed on fd %d: bytes_read %d, %s\n",
fd, bytes_read, strerror(errno));
exit(1);
}
/* Corruption check */
for (i = 0; i < length; i++) {
if (buffer[i] != pattern) {
printf("Bad data at 0x%.06x: %p, \n", i, buffer + i);
printf("Data dump starting at 0x%.06x:\n", i - 8);
printf("Expect 0x%x followed by 0x%x:\n",
pattern, PATTERN);
for (k = 0; k < 16; k++) {
printf("%02x ", buffer[i - 8 + k]);
if (k == 7) {
printf("\n");
}
}
printf("\n");
abort();
}
}
return 0;
}
void *fork_thread(void *arg)
{
pid_t pid;
while (!done) {
pid = fork();
if (pid == 0) {
exit(0);
} else if (pid < 0) {
fprintf(stderr, "Failed to fork child.\n");
exit(1);
}
waitpid(pid, NULL, 0);
usleep(100);
}
return NULL;
}
int main(int argc, char *argv[])
{
unsigned char *buffer = NULL;
char filename[1024];
int fd;
bool dowrite = true;
pthread_t fork_tid;
int c, n, j;
worker_t *worker;
int align = 0;
int offset, rc;
workers = sysconf(_SC_NPROCESSORS_ONLN);
while ((c = getopt(argc, argv, "a:hw:")) != -1) {
switch (c) {
case 'a':
align = atoi(optarg);
if (align < 0 || align > PAGE_SIZE) {
printf("Bad alignment %d.\n", align);
exit(1);
}
dowrite = false;
break;
case 'h':
usage();
exit(0);
break;
case 'w':
workers = atoi(optarg);
if (workers < MIN_WORKERS || workers > MAX_WORKERS) {
fprintf(stderr, "Worker count %d not between "
"%d and %d, inclusive.\n",
workers, MIN_WORKERS, MAX_WORKERS);
usage();
exit(1);
}
dowrite = false;
break;
default:
usage();
exit(1);
}
}
if (argc > 1 && (optind < argc)) {
fprintf(stderr, "Bad command line.\n");
usage();
exit(1);
}
if (dowrite) {
buffer = malloc(FILESIZE);
if (buffer == NULL) {
fprintf(stderr, "Failed to malloc write buffer.\n");
exit(1);
}
for (n = 1; n <= FILECOUNT; n++) {
sprintf(filename, FILENAME, n);
fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
printf("create failed(%s): %s.\n", filename,
strerror(errno));
exit(1);
}
memset(buffer, n, FILESIZE);
printf("Writing file %s.\n", filename);
if (write(fd, buffer, FILESIZE) != FILESIZE) {
printf("write failed (%s)\n", filename);
}
close(fd);
fd = -1;
}
free(buffer);
buffer = NULL;
printf("done\n");
exit(0);
}
printf("Using %d workers.\n", workers);
worker = malloc(workers * sizeof(worker_t));
if (worker == NULL) {
fprintf(stderr, "Failed to malloc worker array.\n");
exit(1);
}
for (j = 0; j < workers; j++) {
worker[j].worker_number = j;
}
printf("Using alignment %d.\n", align);
posix_memalign((void *)&buffer, PAGE_SIZE, READSIZE + align);
printf("Read buffer: %p.\n", buffer);
for (n = 1; n <= FILECOUNT; n++) {
sprintf(filename, FILENAME, n);
for (j = 0; j < workers; j++) {
if ((worker[j].fd =
open(filename, O_RDONLY | O_DIRECT)) < 0) {
fprintf(stderr, "Failed to open %s: %s.\n",
filename, strerror(errno));
exit(1);
}
worker[j].pattern = n;
}
printf("Reading file %d.\n", n);
for (offset = 0; offset < FILESIZE; offset += READSIZE) {
memset(buffer, PATTERN, READSIZE + align);
for (j = 0; j < workers; j++) {
worker[j].offset = offset + j * PAGE_SIZE;
worker[j].buffer =
buffer + align + j * PAGE_SIZE;
worker[j].length = PAGE_SIZE;
}
/* The final worker reads whatever is left over. */
worker[workers - 1].length =
READSIZE - PAGE_SIZE * (workers - 1);
done = 0;
rc = pthread_create(&fork_tid, NULL, fork_thread, NULL);
if (rc != 0) {
fprintf(stderr,
"Can't create fork thread: %s.\n",
strerror(rc));
exit(1);
}
for (j = 0; j < workers; j++) {
rc = pthread_create(&worker[j].tid,
NULL,
worker_thread, worker + j);
if (rc != 0) {
fprintf(stderr,
"Can't create worker thread %d: %s.\n",
j, strerror(rc));
exit(1);
}
}
for (j = 0; j < workers; j++) {
rc = pthread_join(worker[j].tid, NULL);
if (rc != 0) {
fprintf(stderr,
"Failed to join worker thread %d: %s.\n",
j, strerror(rc));
exit(1);
}
}
/* Let the fork thread know it's ok to exit */
done = 1;
rc = pthread_join(fork_tid, NULL);
if (rc != 0) {
fprintf(stderr,
"Failed to join fork thread: %s.\n",
strerror(rc));
exit(1);
}
}
/* Close the fd's for the next file. */
for (j = 0; j < workers; j++) {
close(worker[j].fd);
}
}
return 0;
}
| gpl-2.0 |
jbagel2/AVRDUDE | serbb_posix.c | 4 | 7202 | /*
* avrdude - A Downloader/Uploader for AVR device programmers
* Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean <bsd@bsdhome.com>
* Copyright (C) 2005 Michael Holzt <kju-avr@fqdn.org>
* Copyright (C) 2006 Joerg Wunsch <j@uriah.heep.sax.de>
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* $Id: serbb_posix.c 1294 2014-03-12 23:03:18Z joerg_wunsch $ */
/*
* Posix serial bitbanging interface for avrdude.
*/
#if !defined(WIN32NATIVE)
#include "ac_cfg.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <termios.h>
#include "avrdude.h"
#include "avr.h"
#include "pindefs.h"
#include "pgm.h"
#include "bitbang.h"
#include "serbb.h"
#undef DEBUG
static struct termios oldmode;
/*
serial port/pin mapping
1 cd <-
2 (rxd) <-
3 txd ->
4 dtr ->
5 GND
6 dsr <-
7 rts ->
8 cts <-
9 ri <-
*/
#define DB9PINS 9
static int serregbits[DB9PINS + 1] =
{ 0, TIOCM_CD, 0, 0, TIOCM_DTR, 0, TIOCM_DSR, TIOCM_RTS, TIOCM_CTS, TIOCM_RI };
#ifdef DEBUG
static char *serpins[DB9PINS + 1] =
{ "NONE", "CD", "RXD", "TXD", "DTR", "GND", "DSR", "RTS", "CTS", "RI" };
#endif
static int serbb_setpin(PROGRAMMER * pgm, int pinfunc, int value)
{
unsigned int ctl;
int r;
int pin = pgm->pinno[pinfunc]; // get its value
if (pin & PIN_INVERSE)
{
value = !value;
pin &= PIN_MASK;
}
if ( pin < 1 || pin > DB9PINS )
return -1;
#ifdef DEBUG
printf("%s to %d\n",serpins[pin],value);
#endif
switch ( pin )
{
case 3: /* txd */
r = ioctl(pgm->fd.ifd, value ? TIOCSBRK : TIOCCBRK, 0);
if (r < 0) {
perror("ioctl(\"TIOCxBRK\")");
return -1;
}
break;
case 4: /* dtr */
case 7: /* rts */
r = ioctl(pgm->fd.ifd, TIOCMGET, &ctl);
if (r < 0) {
perror("ioctl(\"TIOCMGET\")");
return -1;
}
if ( value )
ctl |= serregbits[pin];
else
ctl &= ~(serregbits[pin]);
r = ioctl(pgm->fd.ifd, TIOCMSET, &ctl);
if (r < 0) {
perror("ioctl(\"TIOCMSET\")");
return -1;
}
break;
default: /* impossible */
return -1;
}
if (pgm->ispdelay > 1)
bitbang_delay(pgm->ispdelay);
return 0;
}
static int serbb_getpin(PROGRAMMER * pgm, int pinfunc)
{
unsigned int ctl;
unsigned char invert;
int r;
int pin = pgm->pinno[pinfunc]; // get its value
if (pin & PIN_INVERSE)
{
invert = 1;
pin &= PIN_MASK;
} else
invert = 0;
if ( pin < 1 || pin > DB9PINS )
return(-1);
switch ( pin )
{
case 2: /* rxd, currently not implemented, FIXME */
return(-1);
case 1: /* cd */
case 6: /* dsr */
case 8: /* cts */
case 9: /* ri */
r = ioctl(pgm->fd.ifd, TIOCMGET, &ctl);
if (r < 0) {
perror("ioctl(\"TIOCMGET\")");
return -1;
}
if ( !invert )
{
#ifdef DEBUG
printf("%s is %d\n",serpins[pin],(ctl & serregbits[pin]) ? 1 : 0 );
#endif
return ( (ctl & serregbits[pin]) ? 1 : 0 );
}
else
{
#ifdef DEBUG
printf("%s is %d (~)\n",serpins[pin],(ctl & serregbits[pin]) ? 0 : 1 );
#endif
return (( ctl & serregbits[pin]) ? 0 : 1 );
}
default: /* impossible */
return(-1);
}
}
static int serbb_highpulsepin(PROGRAMMER * pgm, int pinfunc)
{
int pin = pgm->pinno[pinfunc]; // replace pin name by its value
if ( (pin & PIN_MASK) < 1 || (pin & PIN_MASK) > DB9PINS )
return -1;
serbb_setpin(pgm, pinfunc, 1);
serbb_setpin(pgm, pinfunc, 0);
return 0;
}
static void serbb_display(PROGRAMMER *pgm, const char *p)
{
/* MAYBE */
}
static void serbb_enable(PROGRAMMER *pgm)
{
/* nothing */
}
static void serbb_disable(PROGRAMMER *pgm)
{
/* nothing */
}
static void serbb_powerup(PROGRAMMER *pgm)
{
/* nothing */
}
static void serbb_powerdown(PROGRAMMER *pgm)
{
/* nothing */
}
static int serbb_open(PROGRAMMER *pgm, char *port)
{
struct termios mode;
int flags;
int r;
bitbang_check_prerequisites(pgm);
/* adapted from uisp code */
pgm->fd.ifd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (pgm->fd.ifd < 0) {
perror(port);
return(-1);
}
r = tcgetattr(pgm->fd.ifd, &mode);
if (r < 0) {
fprintf(stderr, "%s: ", port);
perror("tcgetattr");
return(-1);
}
oldmode = mode;
mode.c_iflag = IGNBRK | IGNPAR;
mode.c_oflag = 0;
mode.c_cflag = CLOCAL | CREAD | CS8 | B9600;
mode.c_cc [VMIN] = 1;
mode.c_cc [VTIME] = 0;
r = tcsetattr(pgm->fd.ifd, TCSANOW, &mode);
if (r < 0) {
fprintf(stderr, "%s: ", port);
perror("tcsetattr");
return(-1);
}
/* Clear O_NONBLOCK flag. */
flags = fcntl(pgm->fd.ifd, F_GETFL, 0);
if (flags == -1)
{
fprintf(stderr, "%s: Can not get flags: %s\n",
progname, strerror(errno));
return(-1);
}
flags &= ~O_NONBLOCK;
if (fcntl(pgm->fd.ifd, F_SETFL, flags) == -1)
{
fprintf(stderr, "%s: Can not clear nonblock flag: %s\n",
progname, strerror(errno));
return(-1);
}
return(0);
}
static void serbb_close(PROGRAMMER *pgm)
{
if (pgm->fd.ifd != -1)
{
(void)tcsetattr(pgm->fd.ifd, TCSANOW, &oldmode);
pgm->setpin(pgm, PIN_AVR_RESET, 1);
close(pgm->fd.ifd);
}
return;
}
const char serbb_desc[] = "Serial port bitbanging";
void serbb_initpgm(PROGRAMMER *pgm)
{
strcpy(pgm->type, "SERBB");
pgm_fill_old_pins(pgm); // TODO to be removed if old pin data no longer needed
pgm->rdy_led = bitbang_rdy_led;
pgm->err_led = bitbang_err_led;
pgm->pgm_led = bitbang_pgm_led;
pgm->vfy_led = bitbang_vfy_led;
pgm->initialize = bitbang_initialize;
pgm->display = serbb_display;
pgm->enable = serbb_enable;
pgm->disable = serbb_disable;
pgm->powerup = serbb_powerup;
pgm->powerdown = serbb_powerdown;
pgm->program_enable = bitbang_program_enable;
pgm->chip_erase = bitbang_chip_erase;
pgm->cmd = bitbang_cmd;
pgm->cmd_tpi = bitbang_cmd_tpi;
pgm->open = serbb_open;
pgm->close = serbb_close;
pgm->setpin = serbb_setpin;
pgm->getpin = serbb_getpin;
pgm->highpulsepin = serbb_highpulsepin;
pgm->read_byte = avr_read_byte_default;
pgm->write_byte = avr_write_byte_default;
}
#endif /* WIN32NATIVE */
| gpl-2.0 |
nikhil93uf/Qemu | hw/s390x/css.c | 4 | 43032 | /*
* Channel subsystem base support.
*
* Copyright 2012 IBM Corp.
* Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or (at
* your option) any later version. See the COPYING file in the top-level
* directory.
*/
#include <hw/qdev.h>
#include "qemu/bitops.h"
#include "exec/address-spaces.h"
#include "cpu.h"
#include "ioinst.h"
#include "css.h"
#include "trace.h"
#include "hw/s390x/s390_flic.h"
typedef struct CrwContainer {
CRW crw;
QTAILQ_ENTRY(CrwContainer) sibling;
} CrwContainer;
typedef struct ChpInfo {
uint8_t in_use;
uint8_t type;
uint8_t is_virtual;
} ChpInfo;
typedef struct SubchSet {
SubchDev *sch[MAX_SCHID + 1];
unsigned long schids_used[BITS_TO_LONGS(MAX_SCHID + 1)];
unsigned long devnos_used[BITS_TO_LONGS(MAX_SCHID + 1)];
} SubchSet;
typedef struct CssImage {
SubchSet *sch_set[MAX_SSID + 1];
ChpInfo chpids[MAX_CHPID + 1];
} CssImage;
typedef struct IoAdapter {
uint32_t id;
uint8_t type;
uint8_t isc;
QTAILQ_ENTRY(IoAdapter) sibling;
} IoAdapter;
typedef struct ChannelSubSys {
QTAILQ_HEAD(, CrwContainer) pending_crws;
bool do_crw_mchk;
bool crws_lost;
uint8_t max_cssid;
uint8_t max_ssid;
bool chnmon_active;
uint64_t chnmon_area;
CssImage *css[MAX_CSSID + 1];
uint8_t default_cssid;
QTAILQ_HEAD(, IoAdapter) io_adapters;
} ChannelSubSys;
static ChannelSubSys *channel_subsys;
int css_create_css_image(uint8_t cssid, bool default_image)
{
trace_css_new_image(cssid, default_image ? "(default)" : "");
if (cssid > MAX_CSSID) {
return -EINVAL;
}
if (channel_subsys->css[cssid]) {
return -EBUSY;
}
channel_subsys->css[cssid] = g_malloc0(sizeof(CssImage));
if (default_image) {
channel_subsys->default_cssid = cssid;
}
return 0;
}
int css_register_io_adapter(uint8_t type, uint8_t isc, bool swap,
bool maskable, uint32_t *id)
{
IoAdapter *adapter;
bool found = false;
int ret;
S390FLICState *fs = s390_get_flic();
S390FLICStateClass *fsc = S390_FLIC_COMMON_GET_CLASS(fs);
*id = 0;
QTAILQ_FOREACH(adapter, &channel_subsys->io_adapters, sibling) {
if ((adapter->type == type) && (adapter->isc == isc)) {
*id = adapter->id;
found = true;
ret = 0;
break;
}
if (adapter->id >= *id) {
*id = adapter->id + 1;
}
}
if (found) {
goto out;
}
adapter = g_new0(IoAdapter, 1);
ret = fsc->register_io_adapter(fs, *id, isc, swap, maskable);
if (ret == 0) {
adapter->id = *id;
adapter->isc = isc;
adapter->type = type;
QTAILQ_INSERT_TAIL(&channel_subsys->io_adapters, adapter, sibling);
} else {
g_free(adapter);
fprintf(stderr, "Unexpected error %d when registering adapter %d\n",
ret, *id);
}
out:
return ret;
}
uint16_t css_build_subchannel_id(SubchDev *sch)
{
if (channel_subsys->max_cssid > 0) {
return (sch->cssid << 8) | (1 << 3) | (sch->ssid << 1) | 1;
}
return (sch->ssid << 1) | 1;
}
static void css_inject_io_interrupt(SubchDev *sch)
{
uint8_t isc = (sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ISC) >> 11;
trace_css_io_interrupt(sch->cssid, sch->ssid, sch->schid,
sch->curr_status.pmcw.intparm, isc, "");
s390_io_interrupt(css_build_subchannel_id(sch),
sch->schid,
sch->curr_status.pmcw.intparm,
isc << 27);
}
void css_conditional_io_interrupt(SubchDev *sch)
{
/*
* If the subchannel is not currently status pending, make it pending
* with alert status.
*/
if (!(sch->curr_status.scsw.ctrl & SCSW_STCTL_STATUS_PEND)) {
uint8_t isc = (sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ISC) >> 11;
trace_css_io_interrupt(sch->cssid, sch->ssid, sch->schid,
sch->curr_status.pmcw.intparm, isc,
"(unsolicited)");
sch->curr_status.scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL;
sch->curr_status.scsw.ctrl |=
SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
/* Inject an I/O interrupt. */
s390_io_interrupt(css_build_subchannel_id(sch),
sch->schid,
sch->curr_status.pmcw.intparm,
isc << 27);
}
}
void css_adapter_interrupt(uint8_t isc)
{
uint32_t io_int_word = (isc << 27) | IO_INT_WORD_AI;
trace_css_adapter_interrupt(isc);
s390_io_interrupt(0, 0, 0, io_int_word);
}
static void sch_handle_clear_func(SubchDev *sch)
{
PMCW *p = &sch->curr_status.pmcw;
SCSW *s = &sch->curr_status.scsw;
int path;
/* Path management: In our simple css, we always choose the only path. */
path = 0x80;
/* Reset values prior to 'issuing the clear signal'. */
p->lpum = 0;
p->pom = 0xff;
s->flags &= ~SCSW_FLAGS_MASK_PNO;
/* We always 'attempt to issue the clear signal', and we always succeed. */
sch->channel_prog = 0x0;
sch->last_cmd_valid = false;
s->ctrl &= ~SCSW_ACTL_CLEAR_PEND;
s->ctrl |= SCSW_STCTL_STATUS_PEND;
s->dstat = 0;
s->cstat = 0;
p->lpum = path;
}
static void sch_handle_halt_func(SubchDev *sch)
{
PMCW *p = &sch->curr_status.pmcw;
SCSW *s = &sch->curr_status.scsw;
hwaddr curr_ccw = sch->channel_prog;
int path;
/* Path management: In our simple css, we always choose the only path. */
path = 0x80;
/* We always 'attempt to issue the halt signal', and we always succeed. */
sch->channel_prog = 0x0;
sch->last_cmd_valid = false;
s->ctrl &= ~SCSW_ACTL_HALT_PEND;
s->ctrl |= SCSW_STCTL_STATUS_PEND;
if ((s->ctrl & (SCSW_ACTL_SUBCH_ACTIVE | SCSW_ACTL_DEVICE_ACTIVE)) ||
!((s->ctrl & SCSW_ACTL_START_PEND) ||
(s->ctrl & SCSW_ACTL_SUSP))) {
s->dstat = SCSW_DSTAT_DEVICE_END;
}
if ((s->ctrl & (SCSW_ACTL_SUBCH_ACTIVE | SCSW_ACTL_DEVICE_ACTIVE)) ||
(s->ctrl & SCSW_ACTL_SUSP)) {
s->cpa = curr_ccw + 8;
}
s->cstat = 0;
p->lpum = path;
}
static void copy_sense_id_to_guest(SenseId *dest, SenseId *src)
{
int i;
dest->reserved = src->reserved;
dest->cu_type = cpu_to_be16(src->cu_type);
dest->cu_model = src->cu_model;
dest->dev_type = cpu_to_be16(src->dev_type);
dest->dev_model = src->dev_model;
dest->unused = src->unused;
for (i = 0; i < ARRAY_SIZE(dest->ciw); i++) {
dest->ciw[i].type = src->ciw[i].type;
dest->ciw[i].command = src->ciw[i].command;
dest->ciw[i].count = cpu_to_be16(src->ciw[i].count);
}
}
static CCW1 copy_ccw_from_guest(hwaddr addr, bool fmt1)
{
CCW0 tmp0;
CCW1 tmp1;
CCW1 ret;
if (fmt1) {
cpu_physical_memory_read(addr, &tmp1, sizeof(tmp1));
ret.cmd_code = tmp1.cmd_code;
ret.flags = tmp1.flags;
ret.count = be16_to_cpu(tmp1.count);
ret.cda = be32_to_cpu(tmp1.cda);
} else {
cpu_physical_memory_read(addr, &tmp0, sizeof(tmp0));
ret.cmd_code = tmp0.cmd_code;
ret.flags = tmp0.flags;
ret.count = be16_to_cpu(tmp0.count);
ret.cda = be16_to_cpu(tmp0.cda1) | (tmp0.cda0 << 16);
}
return ret;
}
static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr)
{
int ret;
bool check_len;
int len;
CCW1 ccw;
if (!ccw_addr) {
return -EIO;
}
/* Translate everything to format-1 ccws - the information is the same. */
ccw = copy_ccw_from_guest(ccw_addr, sch->ccw_fmt_1);
/* Check for invalid command codes. */
if ((ccw.cmd_code & 0x0f) == 0) {
return -EINVAL;
}
if (((ccw.cmd_code & 0x0f) == CCW_CMD_TIC) &&
((ccw.cmd_code & 0xf0) != 0)) {
return -EINVAL;
}
if (ccw.flags & CCW_FLAG_SUSPEND) {
return -EINPROGRESS;
}
check_len = !((ccw.flags & CCW_FLAG_SLI) && !(ccw.flags & CCW_FLAG_DC));
if (!ccw.cda) {
if (sch->ccw_no_data_cnt == 255) {
return -EINVAL;
}
sch->ccw_no_data_cnt++;
}
/* Look at the command. */
switch (ccw.cmd_code) {
case CCW_CMD_NOOP:
/* Nothing to do. */
ret = 0;
break;
case CCW_CMD_BASIC_SENSE:
if (check_len) {
if (ccw.count != sizeof(sch->sense_data)) {
ret = -EINVAL;
break;
}
}
len = MIN(ccw.count, sizeof(sch->sense_data));
cpu_physical_memory_write(ccw.cda, sch->sense_data, len);
sch->curr_status.scsw.count = ccw.count - len;
memset(sch->sense_data, 0, sizeof(sch->sense_data));
ret = 0;
break;
case CCW_CMD_SENSE_ID:
{
SenseId sense_id;
copy_sense_id_to_guest(&sense_id, &sch->id);
/* Sense ID information is device specific. */
if (check_len) {
if (ccw.count != sizeof(sense_id)) {
ret = -EINVAL;
break;
}
}
len = MIN(ccw.count, sizeof(sense_id));
/*
* Only indicate 0xff in the first sense byte if we actually
* have enough place to store at least bytes 0-3.
*/
if (len >= 4) {
sense_id.reserved = 0xff;
} else {
sense_id.reserved = 0;
}
cpu_physical_memory_write(ccw.cda, &sense_id, len);
sch->curr_status.scsw.count = ccw.count - len;
ret = 0;
break;
}
case CCW_CMD_TIC:
if (sch->last_cmd_valid && (sch->last_cmd.cmd_code == CCW_CMD_TIC)) {
ret = -EINVAL;
break;
}
if (ccw.flags & (CCW_FLAG_CC | CCW_FLAG_DC)) {
ret = -EINVAL;
break;
}
sch->channel_prog = ccw.cda;
ret = -EAGAIN;
break;
default:
if (sch->ccw_cb) {
/* Handle device specific commands. */
ret = sch->ccw_cb(sch, ccw);
} else {
ret = -ENOSYS;
}
break;
}
sch->last_cmd = ccw;
sch->last_cmd_valid = true;
if (ret == 0) {
if (ccw.flags & CCW_FLAG_CC) {
sch->channel_prog += 8;
ret = -EAGAIN;
}
}
return ret;
}
static void sch_handle_start_func(SubchDev *sch, ORB *orb)
{
PMCW *p = &sch->curr_status.pmcw;
SCSW *s = &sch->curr_status.scsw;
int path;
int ret;
/* Path management: In our simple css, we always choose the only path. */
path = 0x80;
if (!(s->ctrl & SCSW_ACTL_SUSP)) {
/* Look at the orb and try to execute the channel program. */
assert(orb != NULL); /* resume does not pass an orb */
p->intparm = orb->intparm;
if (!(orb->lpm & path)) {
/* Generate a deferred cc 3 condition. */
s->flags |= SCSW_FLAGS_MASK_CC;
s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
s->ctrl |= (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND);
return;
}
sch->ccw_fmt_1 = !!(orb->ctrl0 & ORB_CTRL0_MASK_FMT);
sch->ccw_no_data_cnt = 0;
} else {
s->ctrl &= ~(SCSW_ACTL_SUSP | SCSW_ACTL_RESUME_PEND);
}
sch->last_cmd_valid = false;
do {
ret = css_interpret_ccw(sch, sch->channel_prog);
switch (ret) {
case -EAGAIN:
/* ccw chain, continue processing */
break;
case 0:
/* success */
s->ctrl &= ~SCSW_ACTL_START_PEND;
s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
SCSW_STCTL_STATUS_PEND;
s->dstat = SCSW_DSTAT_CHANNEL_END | SCSW_DSTAT_DEVICE_END;
s->cpa = sch->channel_prog + 8;
break;
case -ENOSYS:
/* unsupported command, generate unit check (command reject) */
s->ctrl &= ~SCSW_ACTL_START_PEND;
s->dstat = SCSW_DSTAT_UNIT_CHECK;
/* Set sense bit 0 in ecw0. */
sch->sense_data[0] = 0x80;
s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
s->cpa = sch->channel_prog + 8;
break;
case -EFAULT:
/* memory problem, generate channel data check */
s->ctrl &= ~SCSW_ACTL_START_PEND;
s->cstat = SCSW_CSTAT_DATA_CHECK;
s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
s->cpa = sch->channel_prog + 8;
break;
case -EBUSY:
/* subchannel busy, generate deferred cc 1 */
s->flags &= ~SCSW_FLAGS_MASK_CC;
s->flags |= (1 << 8);
s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
s->ctrl |= SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
break;
case -EINPROGRESS:
/* channel program has been suspended */
s->ctrl &= ~SCSW_ACTL_START_PEND;
s->ctrl |= SCSW_ACTL_SUSP;
break;
default:
/* error, generate channel program check */
s->ctrl &= ~SCSW_ACTL_START_PEND;
s->cstat = SCSW_CSTAT_PROG_CHECK;
s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
s->cpa = sch->channel_prog + 8;
break;
}
} while (ret == -EAGAIN);
}
/*
* On real machines, this would run asynchronously to the main vcpus.
* We might want to make some parts of the ssch handling (interpreting
* read/writes) asynchronous later on if we start supporting more than
* our current very simple devices.
*/
static void do_subchannel_work(SubchDev *sch, ORB *orb)
{
SCSW *s = &sch->curr_status.scsw;
if (s->ctrl & SCSW_FCTL_CLEAR_FUNC) {
sch_handle_clear_func(sch);
} else if (s->ctrl & SCSW_FCTL_HALT_FUNC) {
sch_handle_halt_func(sch);
} else if (s->ctrl & SCSW_FCTL_START_FUNC) {
sch_handle_start_func(sch, orb);
} else {
/* Cannot happen. */
return;
}
css_inject_io_interrupt(sch);
}
static void copy_pmcw_to_guest(PMCW *dest, const PMCW *src)
{
int i;
dest->intparm = cpu_to_be32(src->intparm);
dest->flags = cpu_to_be16(src->flags);
dest->devno = cpu_to_be16(src->devno);
dest->lpm = src->lpm;
dest->pnom = src->pnom;
dest->lpum = src->lpum;
dest->pim = src->pim;
dest->mbi = cpu_to_be16(src->mbi);
dest->pom = src->pom;
dest->pam = src->pam;
for (i = 0; i < ARRAY_SIZE(dest->chpid); i++) {
dest->chpid[i] = src->chpid[i];
}
dest->chars = cpu_to_be32(src->chars);
}
static void copy_scsw_to_guest(SCSW *dest, const SCSW *src)
{
dest->flags = cpu_to_be16(src->flags);
dest->ctrl = cpu_to_be16(src->ctrl);
dest->cpa = cpu_to_be32(src->cpa);
dest->dstat = src->dstat;
dest->cstat = src->cstat;
dest->count = cpu_to_be16(src->count);
}
static void copy_schib_to_guest(SCHIB *dest, const SCHIB *src)
{
int i;
copy_pmcw_to_guest(&dest->pmcw, &src->pmcw);
copy_scsw_to_guest(&dest->scsw, &src->scsw);
dest->mba = cpu_to_be64(src->mba);
for (i = 0; i < ARRAY_SIZE(dest->mda); i++) {
dest->mda[i] = src->mda[i];
}
}
int css_do_stsch(SubchDev *sch, SCHIB *schib)
{
/* Use current status. */
copy_schib_to_guest(schib, &sch->curr_status);
return 0;
}
static void copy_pmcw_from_guest(PMCW *dest, const PMCW *src)
{
int i;
dest->intparm = be32_to_cpu(src->intparm);
dest->flags = be16_to_cpu(src->flags);
dest->devno = be16_to_cpu(src->devno);
dest->lpm = src->lpm;
dest->pnom = src->pnom;
dest->lpum = src->lpum;
dest->pim = src->pim;
dest->mbi = be16_to_cpu(src->mbi);
dest->pom = src->pom;
dest->pam = src->pam;
for (i = 0; i < ARRAY_SIZE(dest->chpid); i++) {
dest->chpid[i] = src->chpid[i];
}
dest->chars = be32_to_cpu(src->chars);
}
static void copy_scsw_from_guest(SCSW *dest, const SCSW *src)
{
dest->flags = be16_to_cpu(src->flags);
dest->ctrl = be16_to_cpu(src->ctrl);
dest->cpa = be32_to_cpu(src->cpa);
dest->dstat = src->dstat;
dest->cstat = src->cstat;
dest->count = be16_to_cpu(src->count);
}
static void copy_schib_from_guest(SCHIB *dest, const SCHIB *src)
{
int i;
copy_pmcw_from_guest(&dest->pmcw, &src->pmcw);
copy_scsw_from_guest(&dest->scsw, &src->scsw);
dest->mba = be64_to_cpu(src->mba);
for (i = 0; i < ARRAY_SIZE(dest->mda); i++) {
dest->mda[i] = src->mda[i];
}
}
int css_do_msch(SubchDev *sch, SCHIB *orig_schib)
{
SCSW *s = &sch->curr_status.scsw;
PMCW *p = &sch->curr_status.pmcw;
int ret;
SCHIB schib;
if (!(sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_DNV)) {
ret = 0;
goto out;
}
if (s->ctrl & SCSW_STCTL_STATUS_PEND) {
ret = -EINPROGRESS;
goto out;
}
if (s->ctrl &
(SCSW_FCTL_START_FUNC|SCSW_FCTL_HALT_FUNC|SCSW_FCTL_CLEAR_FUNC)) {
ret = -EBUSY;
goto out;
}
copy_schib_from_guest(&schib, orig_schib);
/* Only update the program-modifiable fields. */
p->intparm = schib.pmcw.intparm;
p->flags &= ~(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA |
PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME |
PMCW_FLAGS_MASK_MP);
p->flags |= schib.pmcw.flags &
(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA |
PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME |
PMCW_FLAGS_MASK_MP);
p->lpm = schib.pmcw.lpm;
p->mbi = schib.pmcw.mbi;
p->pom = schib.pmcw.pom;
p->chars &= ~(PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_CSENSE);
p->chars |= schib.pmcw.chars &
(PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_CSENSE);
sch->curr_status.mba = schib.mba;
ret = 0;
out:
return ret;
}
int css_do_xsch(SubchDev *sch)
{
SCSW *s = &sch->curr_status.scsw;
PMCW *p = &sch->curr_status.pmcw;
int ret;
if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
ret = -ENODEV;
goto out;
}
if (!(s->ctrl & SCSW_CTRL_MASK_FCTL) ||
((s->ctrl & SCSW_CTRL_MASK_FCTL) != SCSW_FCTL_START_FUNC) ||
(!(s->ctrl &
(SCSW_ACTL_RESUME_PEND | SCSW_ACTL_START_PEND | SCSW_ACTL_SUSP))) ||
(s->ctrl & SCSW_ACTL_SUBCH_ACTIVE)) {
ret = -EINPROGRESS;
goto out;
}
if (s->ctrl & SCSW_CTRL_MASK_STCTL) {
ret = -EBUSY;
goto out;
}
/* Cancel the current operation. */
s->ctrl &= ~(SCSW_FCTL_START_FUNC |
SCSW_ACTL_RESUME_PEND |
SCSW_ACTL_START_PEND |
SCSW_ACTL_SUSP);
sch->channel_prog = 0x0;
sch->last_cmd_valid = false;
s->dstat = 0;
s->cstat = 0;
ret = 0;
out:
return ret;
}
int css_do_csch(SubchDev *sch)
{
SCSW *s = &sch->curr_status.scsw;
PMCW *p = &sch->curr_status.pmcw;
int ret;
if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
ret = -ENODEV;
goto out;
}
/* Trigger the clear function. */
s->ctrl &= ~(SCSW_CTRL_MASK_FCTL | SCSW_CTRL_MASK_ACTL);
s->ctrl |= SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_CLEAR_FUNC;
do_subchannel_work(sch, NULL);
ret = 0;
out:
return ret;
}
int css_do_hsch(SubchDev *sch)
{
SCSW *s = &sch->curr_status.scsw;
PMCW *p = &sch->curr_status.pmcw;
int ret;
if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
ret = -ENODEV;
goto out;
}
if (((s->ctrl & SCSW_CTRL_MASK_STCTL) == SCSW_STCTL_STATUS_PEND) ||
(s->ctrl & (SCSW_STCTL_PRIMARY |
SCSW_STCTL_SECONDARY |
SCSW_STCTL_ALERT))) {
ret = -EINPROGRESS;
goto out;
}
if (s->ctrl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC)) {
ret = -EBUSY;
goto out;
}
/* Trigger the halt function. */
s->ctrl |= SCSW_FCTL_HALT_FUNC;
s->ctrl &= ~SCSW_FCTL_START_FUNC;
if (((s->ctrl & SCSW_CTRL_MASK_ACTL) ==
(SCSW_ACTL_SUBCH_ACTIVE | SCSW_ACTL_DEVICE_ACTIVE)) &&
((s->ctrl & SCSW_CTRL_MASK_STCTL) == SCSW_STCTL_INTERMEDIATE)) {
s->ctrl &= ~SCSW_STCTL_STATUS_PEND;
}
s->ctrl |= SCSW_ACTL_HALT_PEND;
do_subchannel_work(sch, NULL);
ret = 0;
out:
return ret;
}
static void css_update_chnmon(SubchDev *sch)
{
if (!(sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_MME)) {
/* Not active. */
return;
}
/* The counter is conveniently located at the beginning of the struct. */
if (sch->curr_status.pmcw.chars & PMCW_CHARS_MASK_MBFC) {
/* Format 1, per-subchannel area. */
uint32_t count;
count = ldl_phys(&address_space_memory, sch->curr_status.mba);
count++;
stl_phys(&address_space_memory, sch->curr_status.mba, count);
} else {
/* Format 0, global area. */
uint32_t offset;
uint16_t count;
offset = sch->curr_status.pmcw.mbi << 5;
count = lduw_phys(&address_space_memory,
channel_subsys->chnmon_area + offset);
count++;
stw_phys(&address_space_memory,
channel_subsys->chnmon_area + offset, count);
}
}
int css_do_ssch(SubchDev *sch, ORB *orb)
{
SCSW *s = &sch->curr_status.scsw;
PMCW *p = &sch->curr_status.pmcw;
int ret;
if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
ret = -ENODEV;
goto out;
}
if (s->ctrl & SCSW_STCTL_STATUS_PEND) {
ret = -EINPROGRESS;
goto out;
}
if (s->ctrl & (SCSW_FCTL_START_FUNC |
SCSW_FCTL_HALT_FUNC |
SCSW_FCTL_CLEAR_FUNC)) {
ret = -EBUSY;
goto out;
}
/* If monitoring is active, update counter. */
if (channel_subsys->chnmon_active) {
css_update_chnmon(sch);
}
sch->channel_prog = orb->cpa;
/* Trigger the start function. */
s->ctrl |= (SCSW_FCTL_START_FUNC | SCSW_ACTL_START_PEND);
s->flags &= ~SCSW_FLAGS_MASK_PNO;
do_subchannel_work(sch, orb);
ret = 0;
out:
return ret;
}
static void copy_irb_to_guest(IRB *dest, const IRB *src, PMCW *pmcw)
{
int i;
uint16_t stctl = src->scsw.ctrl & SCSW_CTRL_MASK_STCTL;
uint16_t actl = src->scsw.ctrl & SCSW_CTRL_MASK_ACTL;
copy_scsw_to_guest(&dest->scsw, &src->scsw);
for (i = 0; i < ARRAY_SIZE(dest->esw); i++) {
dest->esw[i] = cpu_to_be32(src->esw[i]);
}
for (i = 0; i < ARRAY_SIZE(dest->ecw); i++) {
dest->ecw[i] = cpu_to_be32(src->ecw[i]);
}
/* extended measurements enabled? */
if ((src->scsw.flags & SCSW_FLAGS_MASK_ESWF) ||
!(pmcw->flags & PMCW_FLAGS_MASK_TF) ||
!(pmcw->chars & PMCW_CHARS_MASK_XMWME)) {
return;
}
/* extended measurements pending? */
if (!(stctl & SCSW_STCTL_STATUS_PEND)) {
return;
}
if ((stctl & SCSW_STCTL_PRIMARY) ||
(stctl == SCSW_STCTL_SECONDARY) ||
((stctl & SCSW_STCTL_INTERMEDIATE) && (actl & SCSW_ACTL_SUSP))) {
for (i = 0; i < ARRAY_SIZE(dest->emw); i++) {
dest->emw[i] = cpu_to_be32(src->emw[i]);
}
}
}
int css_do_tsch(SubchDev *sch, IRB *target_irb)
{
SCSW *s = &sch->curr_status.scsw;
PMCW *p = &sch->curr_status.pmcw;
uint16_t stctl;
uint16_t fctl;
uint16_t actl;
IRB irb;
int ret;
if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
ret = 3;
goto out;
}
stctl = s->ctrl & SCSW_CTRL_MASK_STCTL;
fctl = s->ctrl & SCSW_CTRL_MASK_FCTL;
actl = s->ctrl & SCSW_CTRL_MASK_ACTL;
/* Prepare the irb for the guest. */
memset(&irb, 0, sizeof(IRB));
/* Copy scsw from current status. */
memcpy(&irb.scsw, s, sizeof(SCSW));
if (stctl & SCSW_STCTL_STATUS_PEND) {
if (s->cstat & (SCSW_CSTAT_DATA_CHECK |
SCSW_CSTAT_CHN_CTRL_CHK |
SCSW_CSTAT_INTF_CTRL_CHK)) {
irb.scsw.flags |= SCSW_FLAGS_MASK_ESWF;
irb.esw[0] = 0x04804000;
} else {
irb.esw[0] = 0x00800000;
}
/* If a unit check is pending, copy sense data. */
if ((s->dstat & SCSW_DSTAT_UNIT_CHECK) &&
(p->chars & PMCW_CHARS_MASK_CSENSE)) {
irb.scsw.flags |= SCSW_FLAGS_MASK_ESWF | SCSW_FLAGS_MASK_ECTL;
memcpy(irb.ecw, sch->sense_data, sizeof(sch->sense_data));
irb.esw[1] = 0x01000000 | (sizeof(sch->sense_data) << 8);
}
}
/* Store the irb to the guest. */
copy_irb_to_guest(target_irb, &irb, p);
/* Clear conditions on subchannel, if applicable. */
if (stctl & SCSW_STCTL_STATUS_PEND) {
s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
if ((stctl != (SCSW_STCTL_INTERMEDIATE | SCSW_STCTL_STATUS_PEND)) ||
((fctl & SCSW_FCTL_HALT_FUNC) &&
(actl & SCSW_ACTL_SUSP))) {
s->ctrl &= ~SCSW_CTRL_MASK_FCTL;
}
if (stctl != (SCSW_STCTL_INTERMEDIATE | SCSW_STCTL_STATUS_PEND)) {
s->flags &= ~SCSW_FLAGS_MASK_PNO;
s->ctrl &= ~(SCSW_ACTL_RESUME_PEND |
SCSW_ACTL_START_PEND |
SCSW_ACTL_HALT_PEND |
SCSW_ACTL_CLEAR_PEND |
SCSW_ACTL_SUSP);
} else {
if ((actl & SCSW_ACTL_SUSP) &&
(fctl & SCSW_FCTL_START_FUNC)) {
s->flags &= ~SCSW_FLAGS_MASK_PNO;
if (fctl & SCSW_FCTL_HALT_FUNC) {
s->ctrl &= ~(SCSW_ACTL_RESUME_PEND |
SCSW_ACTL_START_PEND |
SCSW_ACTL_HALT_PEND |
SCSW_ACTL_CLEAR_PEND |
SCSW_ACTL_SUSP);
} else {
s->ctrl &= ~SCSW_ACTL_RESUME_PEND;
}
}
}
/* Clear pending sense data. */
if (p->chars & PMCW_CHARS_MASK_CSENSE) {
memset(sch->sense_data, 0 , sizeof(sch->sense_data));
}
}
ret = ((stctl & SCSW_STCTL_STATUS_PEND) == 0);
out:
return ret;
}
static void copy_crw_to_guest(CRW *dest, const CRW *src)
{
dest->flags = cpu_to_be16(src->flags);
dest->rsid = cpu_to_be16(src->rsid);
}
int css_do_stcrw(CRW *crw)
{
CrwContainer *crw_cont;
int ret;
crw_cont = QTAILQ_FIRST(&channel_subsys->pending_crws);
if (crw_cont) {
QTAILQ_REMOVE(&channel_subsys->pending_crws, crw_cont, sibling);
copy_crw_to_guest(crw, &crw_cont->crw);
g_free(crw_cont);
ret = 0;
} else {
/* List was empty, turn crw machine checks on again. */
memset(crw, 0, sizeof(*crw));
channel_subsys->do_crw_mchk = true;
ret = 1;
}
return ret;
}
int css_do_tpi(IOIntCode *int_code, int lowcore)
{
/* No pending interrupts for !KVM. */
return 0;
}
int css_collect_chp_desc(int m, uint8_t cssid, uint8_t f_chpid, uint8_t l_chpid,
int rfmt, void *buf)
{
int i, desc_size;
uint32_t words[8];
uint32_t chpid_type_word;
CssImage *css;
if (!m && !cssid) {
css = channel_subsys->css[channel_subsys->default_cssid];
} else {
css = channel_subsys->css[cssid];
}
if (!css) {
return 0;
}
desc_size = 0;
for (i = f_chpid; i <= l_chpid; i++) {
if (css->chpids[i].in_use) {
chpid_type_word = 0x80000000 | (css->chpids[i].type << 8) | i;
if (rfmt == 0) {
words[0] = cpu_to_be32(chpid_type_word);
words[1] = 0;
memcpy(buf + desc_size, words, 8);
desc_size += 8;
} else if (rfmt == 1) {
words[0] = cpu_to_be32(chpid_type_word);
words[1] = 0;
words[2] = 0;
words[3] = 0;
words[4] = 0;
words[5] = 0;
words[6] = 0;
words[7] = 0;
memcpy(buf + desc_size, words, 32);
desc_size += 32;
}
}
}
return desc_size;
}
void css_do_schm(uint8_t mbk, int update, int dct, uint64_t mbo)
{
/* dct is currently ignored (not really meaningful for our devices) */
/* TODO: Don't ignore mbk. */
if (update && !channel_subsys->chnmon_active) {
/* Enable measuring. */
channel_subsys->chnmon_area = mbo;
channel_subsys->chnmon_active = true;
}
if (!update && channel_subsys->chnmon_active) {
/* Disable measuring. */
channel_subsys->chnmon_area = 0;
channel_subsys->chnmon_active = false;
}
}
int css_do_rsch(SubchDev *sch)
{
SCSW *s = &sch->curr_status.scsw;
PMCW *p = &sch->curr_status.pmcw;
int ret;
if (!(p->flags & (PMCW_FLAGS_MASK_DNV | PMCW_FLAGS_MASK_ENA))) {
ret = -ENODEV;
goto out;
}
if (s->ctrl & SCSW_STCTL_STATUS_PEND) {
ret = -EINPROGRESS;
goto out;
}
if (((s->ctrl & SCSW_CTRL_MASK_FCTL) != SCSW_FCTL_START_FUNC) ||
(s->ctrl & SCSW_ACTL_RESUME_PEND) ||
(!(s->ctrl & SCSW_ACTL_SUSP))) {
ret = -EINVAL;
goto out;
}
/* If monitoring is active, update counter. */
if (channel_subsys->chnmon_active) {
css_update_chnmon(sch);
}
s->ctrl |= SCSW_ACTL_RESUME_PEND;
do_subchannel_work(sch, NULL);
ret = 0;
out:
return ret;
}
int css_do_rchp(uint8_t cssid, uint8_t chpid)
{
uint8_t real_cssid;
if (cssid > channel_subsys->max_cssid) {
return -EINVAL;
}
if (channel_subsys->max_cssid == 0) {
real_cssid = channel_subsys->default_cssid;
} else {
real_cssid = cssid;
}
if (!channel_subsys->css[real_cssid]) {
return -EINVAL;
}
if (!channel_subsys->css[real_cssid]->chpids[chpid].in_use) {
return -ENODEV;
}
if (!channel_subsys->css[real_cssid]->chpids[chpid].is_virtual) {
fprintf(stderr,
"rchp unsupported for non-virtual chpid %x.%02x!\n",
real_cssid, chpid);
return -ENODEV;
}
/* We don't really use a channel path, so we're done here. */
css_queue_crw(CRW_RSC_CHP, CRW_ERC_INIT,
channel_subsys->max_cssid > 0 ? 1 : 0, chpid);
if (channel_subsys->max_cssid > 0) {
css_queue_crw(CRW_RSC_CHP, CRW_ERC_INIT, 0, real_cssid << 8);
}
return 0;
}
bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid)
{
SubchSet *set;
uint8_t real_cssid;
real_cssid = (!m && (cssid == 0)) ? channel_subsys->default_cssid : cssid;
if (real_cssid > MAX_CSSID || ssid > MAX_SSID ||
!channel_subsys->css[real_cssid] ||
!channel_subsys->css[real_cssid]->sch_set[ssid]) {
return true;
}
set = channel_subsys->css[real_cssid]->sch_set[ssid];
return schid > find_last_bit(set->schids_used,
(MAX_SCHID + 1) / sizeof(unsigned long));
}
static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t type)
{
CssImage *css;
trace_css_chpid_add(cssid, chpid, type);
if (cssid > MAX_CSSID) {
return -EINVAL;
}
css = channel_subsys->css[cssid];
if (!css) {
return -EINVAL;
}
if (css->chpids[chpid].in_use) {
return -EEXIST;
}
css->chpids[chpid].in_use = 1;
css->chpids[chpid].type = type;
css->chpids[chpid].is_virtual = 1;
css_generate_chp_crws(cssid, chpid);
return 0;
}
void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type)
{
PMCW *p = &sch->curr_status.pmcw;
SCSW *s = &sch->curr_status.scsw;
int i;
CssImage *css = channel_subsys->css[sch->cssid];
assert(css != NULL);
memset(p, 0, sizeof(PMCW));
p->flags |= PMCW_FLAGS_MASK_DNV;
p->devno = sch->devno;
/* single path */
p->pim = 0x80;
p->pom = 0xff;
p->pam = 0x80;
p->chpid[0] = chpid;
if (!css->chpids[chpid].in_use) {
css_add_virtual_chpid(sch->cssid, chpid, type);
}
memset(s, 0, sizeof(SCSW));
sch->curr_status.mba = 0;
for (i = 0; i < ARRAY_SIZE(sch->curr_status.mda); i++) {
sch->curr_status.mda[i] = 0;
}
}
SubchDev *css_find_subch(uint8_t m, uint8_t cssid, uint8_t ssid, uint16_t schid)
{
uint8_t real_cssid;
real_cssid = (!m && (cssid == 0)) ? channel_subsys->default_cssid : cssid;
if (!channel_subsys->css[real_cssid]) {
return NULL;
}
if (!channel_subsys->css[real_cssid]->sch_set[ssid]) {
return NULL;
}
return channel_subsys->css[real_cssid]->sch_set[ssid]->sch[schid];
}
bool css_subch_visible(SubchDev *sch)
{
if (sch->ssid > channel_subsys->max_ssid) {
return false;
}
if (sch->cssid != channel_subsys->default_cssid) {
return (channel_subsys->max_cssid > 0);
}
return true;
}
bool css_present(uint8_t cssid)
{
return (channel_subsys->css[cssid] != NULL);
}
bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno)
{
if (!channel_subsys->css[cssid]) {
return false;
}
if (!channel_subsys->css[cssid]->sch_set[ssid]) {
return false;
}
return !!test_bit(devno,
channel_subsys->css[cssid]->sch_set[ssid]->devnos_used);
}
void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
uint16_t devno, SubchDev *sch)
{
CssImage *css;
SubchSet *s_set;
trace_css_assign_subch(sch ? "assign" : "deassign", cssid, ssid, schid,
devno);
if (!channel_subsys->css[cssid]) {
fprintf(stderr,
"Suspicious call to %s (%x.%x.%04x) for non-existing css!\n",
__func__, cssid, ssid, schid);
return;
}
css = channel_subsys->css[cssid];
if (!css->sch_set[ssid]) {
css->sch_set[ssid] = g_malloc0(sizeof(SubchSet));
}
s_set = css->sch_set[ssid];
s_set->sch[schid] = sch;
if (sch) {
set_bit(schid, s_set->schids_used);
set_bit(devno, s_set->devnos_used);
} else {
clear_bit(schid, s_set->schids_used);
clear_bit(devno, s_set->devnos_used);
}
}
void css_queue_crw(uint8_t rsc, uint8_t erc, int chain, uint16_t rsid)
{
CrwContainer *crw_cont;
trace_css_crw(rsc, erc, rsid, chain ? "(chained)" : "");
/* TODO: Maybe use a static crw pool? */
crw_cont = g_try_malloc0(sizeof(CrwContainer));
if (!crw_cont) {
channel_subsys->crws_lost = true;
return;
}
crw_cont->crw.flags = (rsc << 8) | erc;
if (chain) {
crw_cont->crw.flags |= CRW_FLAGS_MASK_C;
}
crw_cont->crw.rsid = rsid;
if (channel_subsys->crws_lost) {
crw_cont->crw.flags |= CRW_FLAGS_MASK_R;
channel_subsys->crws_lost = false;
}
QTAILQ_INSERT_TAIL(&channel_subsys->pending_crws, crw_cont, sibling);
if (channel_subsys->do_crw_mchk) {
channel_subsys->do_crw_mchk = false;
/* Inject crw pending machine check. */
s390_crw_mchk();
}
}
void css_generate_sch_crws(uint8_t cssid, uint8_t ssid, uint16_t schid,
int hotplugged, int add)
{
uint8_t guest_cssid;
bool chain_crw;
if (add && !hotplugged) {
return;
}
if (channel_subsys->max_cssid == 0) {
/* Default cssid shows up as 0. */
guest_cssid = (cssid == channel_subsys->default_cssid) ? 0 : cssid;
} else {
/* Show real cssid to the guest. */
guest_cssid = cssid;
}
/*
* Only notify for higher subchannel sets/channel subsystems if the
* guest has enabled it.
*/
if ((ssid > channel_subsys->max_ssid) ||
(guest_cssid > channel_subsys->max_cssid) ||
((channel_subsys->max_cssid == 0) &&
(cssid != channel_subsys->default_cssid))) {
return;
}
chain_crw = (channel_subsys->max_ssid > 0) ||
(channel_subsys->max_cssid > 0);
css_queue_crw(CRW_RSC_SUBCH, CRW_ERC_IPI, chain_crw ? 1 : 0, schid);
if (chain_crw) {
css_queue_crw(CRW_RSC_SUBCH, CRW_ERC_IPI, 0,
(guest_cssid << 8) | (ssid << 4));
}
}
void css_generate_chp_crws(uint8_t cssid, uint8_t chpid)
{
/* TODO */
}
void css_generate_css_crws(uint8_t cssid)
{
css_queue_crw(CRW_RSC_CSS, 0, 0, cssid);
}
int css_enable_mcsse(void)
{
trace_css_enable_facility("mcsse");
channel_subsys->max_cssid = MAX_CSSID;
return 0;
}
int css_enable_mss(void)
{
trace_css_enable_facility("mss");
channel_subsys->max_ssid = MAX_SSID;
return 0;
}
void subch_device_save(SubchDev *s, QEMUFile *f)
{
int i;
qemu_put_byte(f, s->cssid);
qemu_put_byte(f, s->ssid);
qemu_put_be16(f, s->schid);
qemu_put_be16(f, s->devno);
qemu_put_byte(f, s->thinint_active);
/* SCHIB */
/* PMCW */
qemu_put_be32(f, s->curr_status.pmcw.intparm);
qemu_put_be16(f, s->curr_status.pmcw.flags);
qemu_put_be16(f, s->curr_status.pmcw.devno);
qemu_put_byte(f, s->curr_status.pmcw.lpm);
qemu_put_byte(f, s->curr_status.pmcw.pnom);
qemu_put_byte(f, s->curr_status.pmcw.lpum);
qemu_put_byte(f, s->curr_status.pmcw.pim);
qemu_put_be16(f, s->curr_status.pmcw.mbi);
qemu_put_byte(f, s->curr_status.pmcw.pom);
qemu_put_byte(f, s->curr_status.pmcw.pam);
qemu_put_buffer(f, s->curr_status.pmcw.chpid, 8);
qemu_put_be32(f, s->curr_status.pmcw.chars);
/* SCSW */
qemu_put_be16(f, s->curr_status.scsw.flags);
qemu_put_be16(f, s->curr_status.scsw.ctrl);
qemu_put_be32(f, s->curr_status.scsw.cpa);
qemu_put_byte(f, s->curr_status.scsw.dstat);
qemu_put_byte(f, s->curr_status.scsw.cstat);
qemu_put_be16(f, s->curr_status.scsw.count);
qemu_put_be64(f, s->curr_status.mba);
qemu_put_buffer(f, s->curr_status.mda, 4);
/* end SCHIB */
qemu_put_buffer(f, s->sense_data, 32);
qemu_put_be64(f, s->channel_prog);
/* last cmd */
qemu_put_byte(f, s->last_cmd.cmd_code);
qemu_put_byte(f, s->last_cmd.flags);
qemu_put_be16(f, s->last_cmd.count);
qemu_put_be32(f, s->last_cmd.cda);
qemu_put_byte(f, s->last_cmd_valid);
qemu_put_byte(f, s->id.reserved);
qemu_put_be16(f, s->id.cu_type);
qemu_put_byte(f, s->id.cu_model);
qemu_put_be16(f, s->id.dev_type);
qemu_put_byte(f, s->id.dev_model);
qemu_put_byte(f, s->id.unused);
for (i = 0; i < ARRAY_SIZE(s->id.ciw); i++) {
qemu_put_byte(f, s->id.ciw[i].type);
qemu_put_byte(f, s->id.ciw[i].command);
qemu_put_be16(f, s->id.ciw[i].count);
}
qemu_put_byte(f, s->ccw_fmt_1);
qemu_put_byte(f, s->ccw_no_data_cnt);
return;
}
int subch_device_load(SubchDev *s, QEMUFile *f)
{
int i;
s->cssid = qemu_get_byte(f);
s->ssid = qemu_get_byte(f);
s->schid = qemu_get_be16(f);
s->devno = qemu_get_be16(f);
s->thinint_active = qemu_get_byte(f);
/* SCHIB */
/* PMCW */
s->curr_status.pmcw.intparm = qemu_get_be32(f);
s->curr_status.pmcw.flags = qemu_get_be16(f);
s->curr_status.pmcw.devno = qemu_get_be16(f);
s->curr_status.pmcw.lpm = qemu_get_byte(f);
s->curr_status.pmcw.pnom = qemu_get_byte(f);
s->curr_status.pmcw.lpum = qemu_get_byte(f);
s->curr_status.pmcw.pim = qemu_get_byte(f);
s->curr_status.pmcw.mbi = qemu_get_be16(f);
s->curr_status.pmcw.pom = qemu_get_byte(f);
s->curr_status.pmcw.pam = qemu_get_byte(f);
qemu_get_buffer(f, s->curr_status.pmcw.chpid, 8);
s->curr_status.pmcw.chars = qemu_get_be32(f);
/* SCSW */
s->curr_status.scsw.flags = qemu_get_be16(f);
s->curr_status.scsw.ctrl = qemu_get_be16(f);
s->curr_status.scsw.cpa = qemu_get_be32(f);
s->curr_status.scsw.dstat = qemu_get_byte(f);
s->curr_status.scsw.cstat = qemu_get_byte(f);
s->curr_status.scsw.count = qemu_get_be16(f);
s->curr_status.mba = qemu_get_be64(f);
qemu_get_buffer(f, s->curr_status.mda, 4);
/* end SCHIB */
qemu_get_buffer(f, s->sense_data, 32);
s->channel_prog = qemu_get_be64(f);
/* last cmd */
s->last_cmd.cmd_code = qemu_get_byte(f);
s->last_cmd.flags = qemu_get_byte(f);
s->last_cmd.count = qemu_get_be16(f);
s->last_cmd.cda = qemu_get_be32(f);
s->last_cmd_valid = qemu_get_byte(f);
s->id.reserved = qemu_get_byte(f);
s->id.cu_type = qemu_get_be16(f);
s->id.cu_model = qemu_get_byte(f);
s->id.dev_type = qemu_get_be16(f);
s->id.dev_model = qemu_get_byte(f);
s->id.unused = qemu_get_byte(f);
for (i = 0; i < ARRAY_SIZE(s->id.ciw); i++) {
s->id.ciw[i].type = qemu_get_byte(f);
s->id.ciw[i].command = qemu_get_byte(f);
s->id.ciw[i].count = qemu_get_be16(f);
}
s->ccw_fmt_1 = qemu_get_byte(f);
s->ccw_no_data_cnt = qemu_get_byte(f);
return 0;
}
static void css_init(void)
{
channel_subsys = g_malloc0(sizeof(*channel_subsys));
QTAILQ_INIT(&channel_subsys->pending_crws);
channel_subsys->do_crw_mchk = true;
channel_subsys->crws_lost = false;
channel_subsys->chnmon_active = false;
QTAILQ_INIT(&channel_subsys->io_adapters);
}
machine_init(css_init);
void css_reset_sch(SubchDev *sch)
{
PMCW *p = &sch->curr_status.pmcw;
p->intparm = 0;
p->flags &= ~(PMCW_FLAGS_MASK_ISC | PMCW_FLAGS_MASK_ENA |
PMCW_FLAGS_MASK_LM | PMCW_FLAGS_MASK_MME |
PMCW_FLAGS_MASK_MP | PMCW_FLAGS_MASK_TF);
p->flags |= PMCW_FLAGS_MASK_DNV;
p->devno = sch->devno;
p->pim = 0x80;
p->lpm = p->pim;
p->pnom = 0;
p->lpum = 0;
p->mbi = 0;
p->pom = 0xff;
p->pam = 0x80;
p->chars &= ~(PMCW_CHARS_MASK_MBFC | PMCW_CHARS_MASK_XMWME |
PMCW_CHARS_MASK_CSENSE);
memset(&sch->curr_status.scsw, 0, sizeof(sch->curr_status.scsw));
sch->curr_status.mba = 0;
sch->channel_prog = 0x0;
sch->last_cmd_valid = false;
sch->thinint_active = false;
}
void css_reset(void)
{
CrwContainer *crw_cont;
/* Clean up monitoring. */
channel_subsys->chnmon_active = false;
channel_subsys->chnmon_area = 0;
/* Clear pending CRWs. */
while ((crw_cont = QTAILQ_FIRST(&channel_subsys->pending_crws))) {
QTAILQ_REMOVE(&channel_subsys->pending_crws, crw_cont, sibling);
g_free(crw_cont);
}
channel_subsys->do_crw_mchk = true;
channel_subsys->crws_lost = false;
/* Reset maximum ids. */
channel_subsys->max_cssid = 0;
channel_subsys->max_ssid = 0;
}
| gpl-2.0 |
spycrab/dolphin | Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp | 4 | 2228 | // Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include <cmath>
#include "Common/Common.h"
#include "Common/MathUtil.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
namespace ControllerEmu
{
AnalogStick::AnalogStick(const char* const name_, std::unique_ptr<StickGate>&& stick_gate)
: AnalogStick(name_, name_, std::move(stick_gate))
{
}
AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
std::unique_ptr<StickGate>&& stick_gate)
: ReshapableInput(name_, ui_name_, GroupType::Stick), m_stick_gate(std::move(stick_gate))
{
for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(Translate, named_direction));
controls.emplace_back(std::make_unique<Input>(Translate, _trans("Modifier")));
}
AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted)
{
const ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State();
const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State();
// Return raw values. (used in UI)
if (!adjusted)
return {x, y};
const ControlState modifier = controls[4]->control_ref->State();
return Reshape(x, y, modifier);
}
AnalogStick::StateData AnalogStick::GetState()
{
return GetReshapableState(true);
}
ControlState AnalogStick::GetGateRadiusAtAngle(double ang) const
{
return m_stick_gate->GetRadiusAtAngle(ang);
}
OctagonAnalogStick::OctagonAnalogStick(const char* name, ControlState gate_radius)
: OctagonAnalogStick(name, name, gate_radius)
{
}
OctagonAnalogStick::OctagonAnalogStick(const char* name, const char* ui_name,
ControlState gate_radius)
: AnalogStick(name, ui_name, std::make_unique<ControllerEmu::OctagonStickGate>(gate_radius))
{
}
} // namespace ControllerEmu
| gpl-2.0 |
holyangel/LGE_G3 | lib/scatterlist.c | 4 | 13085 | /*
* Copyright (C) 2007 Jens Axboe <jens.axboe@oracle.com>
*
* Scatterlist handling helpers.
*
* This source code is licensed under the GNU General Public License,
* Version 2. See the file COPYING for more details.
*/
#include <linux/export.h>
#include <linux/slab.h>
#include <linux/scatterlist.h>
#include <linux/highmem.h>
#include <linux/kmemleak.h>
/*
*/
struct scatterlist *sg_next(struct scatterlist *sg)
{
#ifdef CONFIG_DEBUG_SG
BUG_ON(sg->sg_magic != SG_MAGIC);
#endif
if (sg_is_last(sg))
return NULL;
sg++;
if (unlikely(sg_is_chain(sg)))
sg = sg_chain_ptr(sg);
return sg;
}
EXPORT_SYMBOL(sg_next);
/*
*/
struct scatterlist *sg_last(struct scatterlist *sgl, unsigned int nents)
{
#ifndef ARCH_HAS_SG_CHAIN
struct scatterlist *ret = &sgl[nents - 1];
#else
struct scatterlist *sg, *ret = NULL;
unsigned int i;
for_each_sg(sgl, sg, nents, i)
ret = sg;
#endif
#ifdef CONFIG_DEBUG_SG
BUG_ON(sgl[0].sg_magic != SG_MAGIC);
BUG_ON(!sg_is_last(ret));
#endif
return ret;
}
EXPORT_SYMBOL(sg_last);
/*
*/
void sg_init_table(struct scatterlist *sgl, unsigned int nents)
{
memset(sgl, 0, sizeof(*sgl) * nents);
#ifdef CONFIG_DEBUG_SG
{
unsigned int i;
for (i = 0; i < nents; i++)
sgl[i].sg_magic = SG_MAGIC;
}
#endif
sg_mark_end(&sgl[nents - 1]);
}
EXPORT_SYMBOL(sg_init_table);
/*
*/
void sg_init_one(struct scatterlist *sg, const void *buf, unsigned int buflen)
{
sg_init_table(sg, 1);
sg_set_buf(sg, buf, buflen);
}
EXPORT_SYMBOL(sg_init_one);
/*
*/
static struct scatterlist *sg_kmalloc(unsigned int nents, gfp_t gfp_mask)
{
if (nents == SG_MAX_SINGLE_ALLOC) {
/*
*/
void *ptr = (void *) __get_free_page(gfp_mask);
kmemleak_alloc(ptr, PAGE_SIZE, 1, gfp_mask);
return ptr;
} else
return kmalloc(nents * sizeof(struct scatterlist), gfp_mask);
}
static void sg_kfree(struct scatterlist *sg, unsigned int nents)
{
if (nents == SG_MAX_SINGLE_ALLOC) {
kmemleak_free(sg);
free_page((unsigned long) sg);
} else
kfree(sg);
}
/*
*/
void __sg_free_table(struct sg_table *table, unsigned int max_ents,
sg_free_fn *free_fn)
{
struct scatterlist *sgl, *next;
if (unlikely(!table->sgl))
return;
sgl = table->sgl;
while (table->orig_nents) {
unsigned int alloc_size = table->orig_nents;
unsigned int sg_size;
/*
*/
if (alloc_size > max_ents) {
next = sg_chain_ptr(&sgl[max_ents - 1]);
alloc_size = max_ents;
sg_size = alloc_size - 1;
} else {
sg_size = alloc_size;
next = NULL;
}
table->orig_nents -= sg_size;
free_fn(sgl, alloc_size);
sgl = next;
}
table->sgl = NULL;
}
EXPORT_SYMBOL(__sg_free_table);
/*
*/
void sg_free_table(struct sg_table *table)
{
__sg_free_table(table, SG_MAX_SINGLE_ALLOC, sg_kfree);
}
EXPORT_SYMBOL(sg_free_table);
/*
*/
int __sg_alloc_table(struct sg_table *table, unsigned int nents,
unsigned int max_ents, gfp_t gfp_mask,
sg_alloc_fn *alloc_fn)
{
struct scatterlist *sg, *prv;
unsigned int left;
memset(table, 0, sizeof(*table));
if (nents == 0)
return -EINVAL;
#ifndef ARCH_HAS_SG_CHAIN
BUG_ON(nents > max_ents);
#endif
left = nents;
prv = NULL;
do {
unsigned int sg_size, alloc_size = left;
if (alloc_size > max_ents) {
alloc_size = max_ents;
sg_size = alloc_size - 1;
} else
sg_size = alloc_size;
left -= sg_size;
sg = alloc_fn(alloc_size, gfp_mask);
if (unlikely(!sg)) {
/*
*/
if (prv)
table->nents = ++table->orig_nents;
return -ENOMEM;
}
sg_init_table(sg, alloc_size);
table->nents = table->orig_nents += sg_size;
/*
*/
if (prv)
sg_chain(prv, max_ents, sg);
else
table->sgl = sg;
/*
*/
if (!left)
sg_mark_end(&sg[sg_size - 1]);
/*
*/
gfp_mask &= ~__GFP_WAIT;
gfp_mask |= __GFP_HIGH;
prv = sg;
} while (left);
return 0;
}
EXPORT_SYMBOL(__sg_alloc_table);
/*
*/
int sg_alloc_table(struct sg_table *table, unsigned int nents, gfp_t gfp_mask)
{
int ret;
ret = __sg_alloc_table(table, nents, SG_MAX_SINGLE_ALLOC,
gfp_mask, sg_kmalloc);
if (unlikely(ret))
__sg_free_table(table, SG_MAX_SINGLE_ALLOC, sg_kfree);
return ret;
}
EXPORT_SYMBOL(sg_alloc_table);
/*
*/
void sg_miter_start(struct sg_mapping_iter *miter, struct scatterlist *sgl,
unsigned int nents, unsigned int flags)
{
memset(miter, 0, sizeof(struct sg_mapping_iter));
miter->__sg = sgl;
miter->__nents = nents;
miter->__offset = 0;
WARN_ON(!(flags & (SG_MITER_TO_SG | SG_MITER_FROM_SG)));
miter->__flags = flags;
}
EXPORT_SYMBOL(sg_miter_start);
/*
*/
bool sg_miter_next(struct sg_mapping_iter *miter)
{
unsigned int off, len;
/* */
if (!miter->__nents)
return false;
sg_miter_stop(miter);
/* */
while (miter->__offset == miter->__sg->length) {
if (--miter->__nents) {
miter->__sg = sg_next(miter->__sg);
miter->__offset = 0;
} else
return false;
}
/* */
off = miter->__sg->offset + miter->__offset;
len = miter->__sg->length - miter->__offset;
miter->page = nth_page(sg_page(miter->__sg), off >> PAGE_SHIFT);
off &= ~PAGE_MASK;
miter->length = min_t(unsigned int, len, PAGE_SIZE - off);
miter->consumed = miter->length;
if (miter->__flags & SG_MITER_ATOMIC)
miter->addr = kmap_atomic(miter->page) + off;
else
miter->addr = kmap(miter->page) + off;
return true;
}
EXPORT_SYMBOL(sg_miter_next);
/*
*/
void sg_miter_stop(struct sg_mapping_iter *miter)
{
WARN_ON(miter->consumed > miter->length);
/* */
if (miter->addr) {
miter->__offset += miter->consumed;
if (miter->__flags & SG_MITER_TO_SG)
flush_kernel_dcache_page(miter->page);
if (miter->__flags & SG_MITER_ATOMIC) {
WARN_ON(!irqs_disabled());
kunmap_atomic(miter->addr);
} else
kunmap(miter->page);
miter->page = NULL;
miter->addr = NULL;
miter->length = 0;
miter->consumed = 0;
}
}
EXPORT_SYMBOL(sg_miter_stop);
/*
*/
static size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents,
void *buf, size_t buflen, int to_buffer)
{
unsigned int offset = 0;
struct sg_mapping_iter miter;
unsigned long flags;
unsigned int sg_flags = SG_MITER_ATOMIC;
if (to_buffer)
sg_flags |= SG_MITER_FROM_SG;
else
sg_flags |= SG_MITER_TO_SG;
sg_miter_start(&miter, sgl, nents, sg_flags);
local_irq_save(flags);
while (sg_miter_next(&miter) && offset < buflen) {
unsigned int len;
len = min(miter.length, buflen - offset);
if (to_buffer)
memcpy(buf + offset, miter.addr, len);
else
memcpy(miter.addr, buf + offset, len);
offset += len;
}
sg_miter_stop(&miter);
local_irq_restore(flags);
return offset;
}
/*
*/
size_t sg_copy_from_buffer(struct scatterlist *sgl, unsigned int nents,
void *buf, size_t buflen)
{
return sg_copy_buffer(sgl, nents, buf, buflen, 0);
}
EXPORT_SYMBOL(sg_copy_from_buffer);
/*
*/
size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents,
void *buf, size_t buflen)
{
return sg_copy_buffer(sgl, nents, buf, buflen, 1);
}
EXPORT_SYMBOL(sg_copy_to_buffer);
| gpl-2.0 |
tsuibin/qtextended | src/applications/qtmail/readmail.cpp | 4 | 34580 | /****************************************************************************
**
** This file is part of the Qt Extended Opensource Package.
**
** Copyright (C) 2009 Trolltech ASA.
**
** Contact: Qt Extended Information (info@qtextended.org)
**
** This file may be used under the terms of the GNU General Public License
** version 2.0 as published by the Free Software Foundation and appearing
** in the file LICENSE.GPL included in the packaging of this file.
**
** Please review the following information to ensure GNU General Public
** Licensing requirements will be met:
** http://www.fsf.org/licensing/licenses/info/GPLv2.html.
**
**
****************************************************************************/
#include "readmail.h"
#include <qtopiaapplication.h>
#include <qtopiaipcenvelope.h>
#include <qtopianamespace.h>
#include <qtopiaservices.h>
#include <qsoftmenubar.h>
#include <qthumbnail.h>
#include <qcontact.h>
#include <qcontactmodel.h>
#include <qmailviewer.h>
#include <qlabel.h>
#include <qimage.h>
#include <qaction.h>
#include <qfile.h>
#include <qtextbrowser.h>
#include <qtextstream.h>
#include <qcursor.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qregexp.h>
#include <qstackedwidget.h>
#include <qmessagebox.h>
#include <qboxlayout.h>
#include <qevent.h>
#include <qimagereader.h>
#include <qalgorithms.h>
#include <qtmailwindow.h>
#include <QContactSelector>
#include <QContactFieldDefinition>
#include <QMailAccount>
#include <QMailComposerFactory>
#include <QMailFolder>
#include <QMailStore>
#include <QDrmContentPlugin>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QMenuBar>
#ifdef QTOPIA_HOMEUI
#include <private/homewidgets_p.h>
#endif
class SaveContactDialog : public QDialog
{
Q_OBJECT
public:
enum Selection { None = 0, Create, Existing };
SaveContactDialog(const QMailAddress &address, QWidget *parent = 0)
: QDialog(parent),
sel(None),
#ifdef QTOPIA_HOMEUI
createButton(new HomeActionButton(tr("Create new contact"), QtopiaHome::Green)),
existingButton(new HomeActionButton(tr("Add to existing"), QtopiaHome::Green)),
cancelButton(new HomeActionButton(tr("Cancel"), QtopiaHome::Red))
#else
createButton(new QPushButton(tr("Create new contact"))),
existingButton(new QPushButton(tr("Add to existing")))
#endif
{
setObjectName("SaveContactDialog");
setModal(true);
setWindowTitle(tr("Save"));
connect(createButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
connect(existingButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
#ifdef QTOPIA_HOMEUI
connect(cancelButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
#endif
QString text = tr("Saving '%1' to Contacts.", "%1=name/address/number").arg(address.address());
text += "\n";
text += tr("Create new contact or add to an existing contact?");
QPlainTextEdit* textEdit = new QPlainTextEdit(text, this);
textEdit->setReadOnly(true);
textEdit->setFocusPolicy(Qt::NoFocus);
textEdit->setFrameStyle(QFrame::NoFrame);
textEdit->viewport()->setBackgroundRole(QPalette::Window);
QVBoxLayout *vbl = new QVBoxLayout;
vbl->setSpacing(4);
vbl->setContentsMargins(0, 0, 0, 0);
vbl->addWidget(textEdit);
#ifdef QTOPIA_HOMEUI
QGridLayout* grid = new QGridLayout;
grid->addWidget(createButton, 0, 0);
grid->addWidget(existingButton, 0, 1);
grid->addWidget(cancelButton, 1, 1);
vbl->addLayout(grid);
#else
vbl->addWidget(createButton);
vbl->addWidget(existingButton);
#endif
setLayout(vbl);
#ifdef QTOPIA_HOMEUI
QtopiaHome::setPopupDialogStyle(this);
#endif
}
Selection selection() const { return sel; }
protected slots:
void buttonClicked()
{
if (sender() == createButton) {
sel = Create;
} else if (sender() == existingButton) {
sel = Existing;
} else {
reject();
return;
}
accept();
}
private:
Selection sel;
#ifdef QTOPIA_HOMEUI
HomeActionButton *createButton;
HomeActionButton *existingButton;
HomeActionButton *cancelButton;
#else
QPushButton *createButton;
QPushButton *existingButton;
#endif
};
ReadMail::ReadMail( QWidget* parent, Qt::WFlags fl )
: QMainWindow(parent, fl),
sending(false),
receiving(false),
firstRead(false),
hasNext(false),
hasPrevious(false),
initialized(false),
contactModel(0),
modelUpdatePending(false)
{
init();
}
ReadMail::~ReadMail()
{
delete contactModel;
}
void ReadMail::init()
{
QDrmContentPlugin::initialize();
getThisMailButton = new QAction( QIcon(":icon/getmail"), tr("Get message"), this );
connect(getThisMailButton, SIGNAL(triggered()), this, SLOT(getThisMail()) );
getThisMailButton->setWhatsThis( tr("Retrieve this message from the server. You can use this option to retrieve individual messages that would normally not be automatically downloaded.") );
sendThisMailButton = new QAction( QIcon(":icon/sendmail"), tr("Send message"), this );
connect(sendThisMailButton, SIGNAL(triggered()), this, SLOT(sendThisMail()));
sendThisMailButton->setWhatsThis( tr("Send this message. This option will not send any other messages in your outbox.") );
replyButton = new QAction( QIcon(":icon/reply"), tr("Reply"), this );
connect(replyButton, SIGNAL(triggered()), this, SLOT(reply()));
replyButton->setWhatsThis( tr("Reply to sender only. Select Reply all from the menu if you want to reply to all recipients.") );
replyAllAction = new QAction( QIcon(":icon/replytoall"), tr("Reply all"), this );
connect(replyAllAction, SIGNAL(triggered()), this, SLOT(replyAll()));
forwardAction = new QAction(tr("Forward"), this );
connect(forwardAction, SIGNAL(triggered()), this, SLOT(forward()));
modifyButton = new QAction( QIcon(":icon/edit"), tr("Modify"), this );
connect(modifyButton, SIGNAL(triggered()), this, SLOT(modify()));
modifyButton->setWhatsThis( tr("Opens this message in the composer so that you can make modifications to it.") );
previousButton = new QAction( QIcon( ":icon/up" ), tr( "Previous" ), this );
connect( previousButton, SIGNAL(triggered()), this, SIGNAL(viewPrevious()) );
previousButton->setWhatsThis( tr("Read the previous message in the folder.") );
nextButton = new QAction( QIcon( ":icon/down" ), tr( "Next" ), this );
connect( nextButton, SIGNAL(triggered()), this, SIGNAL(viewNext()) );
nextButton->setWhatsThis( tr("Read the next message in the folder.") );
attachmentsButton = new QAction( QIcon( ":icon/attach" ), tr( "Attachments" ), this );
connect( attachmentsButton, SIGNAL(triggered()), this,
SLOT(viewAttachments()) );
attachmentsButton->setWhatsThis( tr("View the attachments in the message.") );
deleteButton = new QAction( QIcon( ":icon/trash" ), tr( "Delete" ), this );
connect( deleteButton, SIGNAL(triggered()), this, SLOT(deleteItem()) );
deleteButton->setWhatsThis( tr("Move this message to the trash folder. If the message is already in the trash folder it will be deleted. ") );
storeButton = new QAction( QIcon( ":icon/save" ), tr( "Save Sender" ), this );
connect( storeButton, SIGNAL(triggered()), this, SLOT(storeContact()) );
views = new QStackedWidget(this);
setCentralWidget(views);
// Update the view if the displayed message changes
connect(QMailStore::instance(), SIGNAL(messagesUpdated(QMailMessageIdList)),
this, SLOT(messagesUpdated(QMailMessageIdList)));
}
QMailMessageId ReadMail::displayedMessage() const
{
return mail.id();
}
bool ReadMail::handleIncomingMessages(const QMailMessageIdList &list) const
{
if (QMailViewerInterface* viewer = currentViewer()) {
if (viewer->handleIncomingMessages(list)) {
// Mark each of these messages as read
quint64 status(QMailMessage::Read);
QMailStore::instance()->updateMessagesMetaData(QMailMessageKey(list), status, true);
return true;
}
}
return false;
}
bool ReadMail::handleOutgoingMessages(const QMailMessageIdList &list) const
{
if (QMailViewerInterface* viewer = currentViewer())
return viewer->handleOutgoingMessages(list);
return false;
}
/* We need to be careful here. Don't allow clicking on any links
to automatically install anything. If we want that, we need to
make sure that the mail doesn't contain mailicious link encoding
*/
void ReadMail::linkClicked(const QUrl &lnk)
{
QString str = lnk.toString();
QRegExp commandPattern("(\\w+);(.+)");
if (commandPattern.exactMatch(str)) {
QString command = commandPattern.cap(1);
QString param = commandPattern.cap(2);
if (command == "attachment") {
if (param == "view") { // No tr
viewAttachments();
} else if (param.startsWith("scrollto;")) {
if (QMailViewerInterface* viewer = currentViewer())
viewer->scrollToAnchor(param.mid(9));
} else if (param == "play") {
if (isMms)
viewMms();
}
} else if (command == "dial") {
dialNumber(param);
} else if (command == "message") {
emit sendMessageTo(QMailAddress(param), QMailMessage::Sms);
} else if (command == "store") {
storeContact(QMailAddress(param), mail.messageType());
} else if (command == "contact") {
displayContact(QUniqueId(param));
}
} else if (str.startsWith("mailto:")) {
// strip leading 'mailto:'
emit sendMessageTo( QMailAddress(str.mid(7)), mail.messageType() );
} else if (str.startsWith("http://")) {
QtopiaServiceRequest e( "WebAccess", "openURL(QString)" );
e << str;
e.send();
} else if (mail.messageType() == QMailMessage::System && str.startsWith(QLatin1String("qtopiaservice:"))) {
int commandPos = str.indexOf( QLatin1String( "::" ) ) + 2;
int argPos = str.indexOf( '?' ) + 1;
QString service = str.mid( 14, commandPos - 16 );
QString command;
QStringList args;
if (argPos > 0) {
command = str.mid( commandPos, argPos - commandPos - 1 );
args = str.mid( argPos ).split( ',' );
} else {
command = str.mid( commandPos );
}
QtopiaServiceRequest e( service, command );
foreach( const QString &arg, args )
e << arg;
e.send();
}
}
QString ReadMail::displayName(const QMailMessage& mail)
{
const bool outgoing(mail.status() & QMailMessage::Outgoing);
QString name;
if (outgoing) {
if (!mail.to().isEmpty())
name = mail.to().first().displayName();
} else {
name = mail.from().displayName();
}
if (name.isEmpty()) {
// Use the type of this message as the title
QString key(QMailComposerFactory::defaultKey(mail.messageType()));
if (!key.isEmpty())
name = QMailComposerFactory::displayName(key, mail.messageType());
else
name = tr("Message");
if (!name.isEmpty())
name[0] = name[0].toUpper();
}
if (outgoing)
name.prepend(tr("To:") + ' ');
return name;
}
void ReadMail::updateView(QMailViewerFactory::PresentationType type)
{
if ( !mail.id().isValid() )
return;
if (type == QMailViewerFactory::AnyPresentation) {
type = QMailViewerFactory::StandardPresentation;
if (mail.messageType() == QMailMessage::Instant) {
type = QMailViewerFactory::ConversationPresentation;
}
}
QMailMessage::ContentType content(mail.content());
if ((content == QMailMessage::NoContent) || (content == QMailMessage::UnknownContent)) {
// Attempt to show the message as text, from the subject if necessary
content = QMailMessage::PlainTextContent;
}
QMailViewerInterface* view = viewer(content, type);
if (!view) {
qLog(Messaging) << "Unable to view message" << mail.id() << "with content:" << content;
return;
}
// Mark message as read before showing viewer, to avoid reload on change notification
updateReadStatus();
view->clear();
if (!isSmil && (mail.messageType() != QMailMessage::System)) {
initImages(view);
}
view->setMessage(mail);
context = QSoftMenuBar::menuFor(view->widget());
context->clear();
context->addAction(getThisMailButton);
context->addAction(sendThisMailButton);
#ifndef QTOPIA_HOMEUI
context->addAction(replyButton);
context->addAction(replyAllAction);
context->addAction(forwardAction);
#endif
context->addAction(modifyButton);
#ifndef QTOPIA_HOMEUI
context->addAction(deleteButton);
#endif
context->addAction(storeButton);
context->addSeparator();
view->addActions(context);
#ifndef QTOPIA_NO_MMS
if(mail.messageType() == QMailMessage::Mms)
QtopiaApplication::setPowerConstraint(QtopiaApplication::Disable);
#endif
switchView(view, displayName(mail));
}
void ReadMail::keyPressEvent(QKeyEvent *e)
{
switch( e->key() ) {
case Qt::Key_A:
if ( attachmentsButton->isEnabled() )
viewAttachments();
break;
case Qt::Key_P:
if ( previousButton->isEnabled() )
emit viewPrevious();
break;
case Qt::Key_N:
if ( nextButton->isEnabled() )
emit viewNext();
break;
case Qt::Key_Delete:
deleteItem();
break;
case Qt::Key_R:
reply();
break;
case Qt::Key_F:
forward();
break;
case Qt::Key_E:
if ( modifyButton->isEnabled() )
modify();
default:
QMainWindow::keyPressEvent( e );
}
}
//update view with current EmailListItem (item)
void ReadMail::displayMessage(const QMailMessageId& id, QMailViewerFactory::PresentationType type, bool nextAvailable, bool previousAvailable)
{
if (!id.isValid())
return;
hasNext = nextAvailable;
hasPrevious = previousAvailable;
showMessage(id, type);
updateButtons();
//report currently viewed mail so that it will be
//placed first in the queue of new mails to download.
emit viewingMail(mail);
}
void ReadMail::buildMenu(const QString &mailbox)
{
Q_UNUSED(mailbox);
}
void ReadMail::messagesUpdated(const QMailMessageIdList& list)
{
if (!mail.id().isValid())
return;
if (list.contains(mail.id())) {
loadMessage(mail.id());
if (QMailViewerInterface* viewer = currentViewer())
viewer->setMessage(mail);
return;
}
updateButtons();
}
void ReadMail::showMessage(const QMailMessageId& id, QMailViewerFactory::PresentationType type)
{
loadMessage(id);
updateView(type);
}
void ReadMail::messageChanged(const QMailMessageId &id)
{
// Ignore updates from viewers that aren't currently top of the stack
if (sender() == static_cast<QObject*>(currentViewer())) {
loadMessage(id);
}
}
void ReadMail::loadMessage(const QMailMessageId &id)
{
mail = QMailMessage(id);
isMms = false;
isSmil = false;
#ifndef QTOPIA_NO_MMS
if (mail.messageType() == QMailMessage::Mms) {
QString mmsType = mail.headerFieldText("X-Mms-Message-Type");
if (mmsType.contains("m-retrieve-conf") || mmsType.contains("m-send-req")) {
isMms = true;
if (mail.contentType().content().toLower() == "multipart/related")
isSmil = true;
}
}
#endif
updateButtons();
}
void ReadMail::viewFinished()
{
//check for read reply flag
#ifndef QTOPIA_NO_MMS
if(mail.messageType() == QMailMessage::Mms)
QtopiaApplication::setPowerConstraint(QtopiaApplication::Enable);
QString mmsType = mail.headerFieldText("X-Mms-Message-Type");
QString msgClass = mail.headerFieldText("X-Mms-Message-Class");
QString readReply = mail.headerFieldText("X-Mms-Read-Reply");
if (mmsType.contains("m-retrieve-conf") &&
!msgClass.contains("Auto") &&
readReply.contains("Yes") &&
firstRead) {
emit readReplyRequested(mail);
}
#endif
closeView();
}
void ReadMail::closeView()
{
if (currentViewer()) {
if ((mail.messageType() == QMailMessage::Sms) && (mail.headerFieldText("X-Sms-Class") == "0")) {
// This is a 'flash' message just displayed - we should delete it after viewing
QMailMessageId deleteId(mail.id());
mail = QMailMessage();
emit removeMessage(deleteId, false);
}
currentView.pop();
if (currentView.isEmpty()) {
// Clear the current message record
mail = QMailMessage();
emit cancelView();
} else {
QTMailWindow::singleton()->setWindowTitle(currentView.top().second);
views->setCurrentWidget(currentView.top().first->widget());
}
}
}
//deletes item, tries bringing up next or previous, exits if unsucessful
void ReadMail::deleteItem()
{
if (deleteButton->isVisible()) {
QMailMessageId deleteId(mail.id());
if (deleteId.isValid()) {
// After deletion, we're finished viewing
viewFinished();
// Clear the current message, otherwise we will think it is updated by the deletion event
mail = QMailMessage();
emit removeMessage(deleteId, true);
}
}
}
void ReadMail::updateButtons()
{
static const QMailFolder trashFolder(QMailFolder::TrashFolder);
static const QMailFolder draftsFolder(QMailFolder::DraftsFolder);
if (!mail.id().isValid())
return;
bool incoming(mail.status() & QMailMessage::Incoming);
bool sent(mail.status() & QMailMessage::Sent);
bool outgoing(mail.status() & QMailMessage::Outgoing);
bool downloaded(mail.status() & QMailMessage::Downloaded);
bool removed(mail.status() & QMailMessage::Removed);
bool system(mail.messageType() == QMailMessage::System);
bool messageSent(sent || sending);
bool messageReceived(downloaded || receiving);
sendThisMailButton->setVisible( !messageSent && outgoing && mail.hasRecipients() );
modifyButton->setVisible( !messageSent && outgoing && (mail.parentFolderId() == draftsFolder.id()) );
getThisMailButton->setVisible( !messageReceived && !removed && incoming );
if (!downloaded || system) {
// We can't really forward/reply/reply-to-all without the message content
replyButton->setVisible(false);
replyAllAction->setVisible(false);
forwardAction->setVisible(false);
} else {
bool otherReplyTarget(!mail.cc().isEmpty() || mail.to().count() > 1);
// TODO: handle cases where: a) a Mail-Followup-To is specified, and
// b) a singular To address is not our own address, and is probably a mailing list...
replyButton->setVisible(incoming);
replyAllAction->setVisible(incoming && otherReplyTarget);
forwardAction->setVisible(true);
}
attachmentsButton->setVisible( mail.partCount() );
nextButton->setVisible(hasNext);
previousButton->setVisible(hasPrevious);
deleteButton->setText( mail.parentFolderId() == trashFolder.id() ? tr("Delete") : tr("Move to Trash") );
// Show the 'Save Sender' action if we don't have a matching contact
QMailAddress fromAddress(mail.from());
bool unknownContact = !fromAddress.matchesExistingContact();
storeButton->setVisible(!fromAddress.isNull() && unknownContact);
}
void ReadMail::viewAttachments()
{
ViewAtt dlg(&mail, (mail.status() & QMailMessage::Incoming));
QtopiaApplication::execDialog(&dlg);
QMailStore::instance()->updateMessage(&mail);
}
void ReadMail::viewMms()
{
#ifndef QTOPIA_NO_MMS
QMailViewerInterface* smilView = viewer(QMailMessage::SmilContent);
smilView->setObjectName( "smilView" );
if (smilView->setMessage(mail)) {
updateReadStatus();
switchView(smilView, tr("MMS"));
} else {
QMessageBox::warning(this, tr("Cannot view MMS"),
tr("<qt>Cannot play improperly formatted MMS.</qt>"), QMessageBox::Ok, QMessageBox::NoButton);
}
#endif
}
void ReadMail::reply()
{
#ifdef QTOPIA_HOMEUI
int replyType = 0;
if (mail.messageType() == QMailMessage::Instant) {
// Neither Reply-to-all nor Forward are sensible options
replyType = Reply;
if (mail.status() & QMailMessage::Outgoing) {
// Although we're technically replying to a message we sent, we should
// interpret this as a reply to the recipient of the message
emit sendMessageTo(mail.to().first(), mail.messageType());
return;
}
}
emit resendRequested(mail, replyType);
#else
if (replyButton->isVisible())
{
emit cancelView();
emit resendRequested(mail, Reply);
mail = QMailMessage();
}
#endif
}
void ReadMail::replyAll()
{
if (replyAllAction->isVisible())
{
emit cancelView();
emit resendRequested(mail, ReplyToAll);
mail = QMailMessage();
}
}
void ReadMail::forward()
{
if (forwardAction->isVisible())
{
emit cancelView();
emit resendRequested(mail, Forward);
mail = QMailMessage();
}
}
void ReadMail::setStatus(int id)
{
quint64 prevStatus(mail.status());
quint64 newStatus(prevStatus);
switch( id ) {
case 1:
newStatus &= ~( QMailMessage::Replied | QMailMessage::RepliedAll | QMailMessage::Forwarded | QMailMessage::Read );
break;
case 2:
newStatus &= ~( QMailMessage::RepliedAll | QMailMessage::Forwarded );
newStatus |= QMailMessage::Replied;
break;
case 3:
newStatus &= ~( QMailMessage::Replied | QMailMessage::RepliedAll );
newStatus |= QMailMessage::Forwarded;
break;
case 4:
newStatus |= QMailMessage::Sent;
break;
case 5:
newStatus &= ~QMailMessage::Sent;
break;
}
if ( newStatus != prevStatus) {
mail.setStatus( newStatus );
QMailStore::instance()->updateMessage(&mail);
}
updateButtons();
}
void ReadMail::modify()
{
if (modifyButton->isVisible())
emit modifyRequested(mail);
}
void ReadMail::getThisMail()
{
if (getThisMailButton->isVisible())
emit getMailRequested(mail);
}
void ReadMail::sendThisMail()
{
if (sendThisMailButton->isVisible())
emit sendMailRequested(mail);
}
void ReadMail::setSendingInProgress(bool on)
{
sending = on;
if ( isVisible() )
updateButtons();
}
void ReadMail::setRetrievalInProgress(bool on)
{
receiving = on;
if ( isVisible() )
updateButtons();
}
void ReadMail::initImages(QMailViewerInterface* view)
{
static QMap<QUrl, QVariant> resourceMap;
if (!initialized) {
// Add the predefined smiley images for EMS messages.
resourceMap.insert( QUrl( "x-sms-predefined:ironic" ),
QVariant( QImage( ":image/smiley/ironic" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:glad" ),
QVariant( QImage( ":image/smiley/glad" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:skeptical" ),
QVariant( QImage( ":image/smiley/skeptical" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:sad" ),
QVariant( QImage( ":image/smiley/sad" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:wow" ),
QVariant( QImage( ":image/smiley/wow" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:crying" ),
QVariant( QImage( ":image/smiley/crying" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:winking" ),
QVariant( QImage( ":image/smiley/winking" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:laughing" ),
QVariant( QImage( ":image/smiley/laughing" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:indifferent" ),
QVariant( QImage( ":image/smiley/indifferent" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:kissing" ),
QVariant( QImage( ":image/smiley/kissing" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:confused" ),
QVariant( QImage( ":image/smiley/confused" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:tongue" ),
QVariant( QImage( ":image/smiley/tongue" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:angry" ),
QVariant( QImage( ":image/smiley/angry" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:glasses" ),
QVariant( QImage( ":image/smiley/glasses" ) ) );
resourceMap.insert( QUrl( "x-sms-predefined:devil" ),
QVariant( QImage( ":image/smiley/devil" ) ) );
initialized = true;
}
QMap<QUrl, QVariant>::iterator it = resourceMap.begin(), end = resourceMap.end();
for ( ; it != end; ++it)
view->setResource( it.key(), it.value() );
}
void ReadMail::dialNumber(const QString& number)
{
if ( !number.isEmpty() ) {
QtopiaServiceRequest req( "Dialer", "showDialer(QString)" );
req << number;
req.send();
}
}
void ReadMail::switchView(QMailViewerInterface* viewer, const QString& title)
{
if (currentViewer() == viewer)
currentView.pop();
lastTitle = title;
updateWindowTitle();
views->setCurrentWidget(viewer->widget());
currentView.push(qMakePair(viewer, title));
}
void ReadMail::updateWindowTitle() const
{
QTMailWindow::singleton()->setWindowTitle(lastTitle);
}
QMailViewerInterface* ReadMail::currentViewer() const
{
if (currentView.isEmpty())
return 0;
return currentView.top().first;
}
static void addContactAddress(QContact &contact, QMailMessage::MessageType type, const QString &address)
{
if (type == QMailMessage::Instant) {
// Treat this address as a jabber URI
QStringList chatFields = QContactFieldDefinition::fields("chat");
if (!chatFields.isEmpty()) {
// Just use the first type; if there are multiple ones, we need to prevail
// upon PIM to provide services that delegate this stuff to addressbook...
QContactFieldDefinition field(chatFields.first());
field.setValue(contact, field.id() + ':' + address);
}
} else {
contact.insertEmail(address);
}
}
void ReadMail::storeContact(const QMailAddress &address, QMailMessage::MessageType type)
{
if (!address.isPhoneNumber() && !address.isEmailAddress()) {
qWarning() << "Unable to store unknown address type:" << address.toString();
} else {
SaveContactDialog dialog(address);
if ((QtopiaApplication::execDialog(&dialog) == QDialog::Accepted) &&
(dialog.selection() != SaveContactDialog::None)) {
bool newContact = (dialog.selection() == SaveContactDialog::Create);
if (!contactModel) {
// Once we have registered the new contact, we need to update our message display
contactModel = new QContactModel();
connect(contactModel, SIGNAL(modelReset()), this, SLOT(contactModelReset()) );
}
modelUpdatePending = true;
if (address.isPhoneNumber()) {
QtopiaServiceRequest req( "Contacts", (newContact ? "createNewContact(QString)"
: "addPhoneNumberToContact(QString)") );
req << address.toString();
req.send();
} else {
// The Contacts app doesn't provide email address services at this time
if (newContact) {
QContact contact;
addContactAddress(contact, type, address.address());
QtopiaServiceRequest req( "Contacts", "addAndEditContact(QContact)" );
req << contact;
req.send();
} else {
// For now, we need to do this ourselves
QContactSelector selector;
selector.setObjectName("select-contact");
QContactModel model(&selector);
QSettings config( "Trolltech", "Contacts" );
config.beginGroup( "default" );
if (config.contains("SelectedSources/size")) {
int count = config.beginReadArray("SelectedSources");
QSet<QPimSource> set;
for(int i = 0; i < count; ++i) {
config.setArrayIndex(i);
QPimSource s;
s.context = QUuid(config.value("context").toString());
s.identity = config.value("identity").toString();
set.insert(s);
}
config.endArray();
model.setVisibleSources(set);
}
selector.setModel(&model);
selector.setAcceptTextEnabled(false);
selector.showMaximized();
if (QtopiaApplication::execDialog(&selector) == QDialog::Accepted) {
QContact contact(selector.selectedContact());
addContactAddress(contact, type, address.address());
if (!model.updateContact(contact)) {
qWarning() << "Unable to update contact:" << contact.label();
}
}
}
}
}
}
}
void ReadMail::storeContact()
{
if (storeButton->isVisible()) {
// Store the address of the correspondent
if (mail.status() & QMailMessage::Incoming)
storeContact(mail.from(), mail.messageType());
else
storeContact(mail.to().first(), mail.messageType());
}
}
void ReadMail::contactModelReset()
{
if (modelUpdatePending) {
// TODO: In fact, we can't ignore unrequested reset events, because the first reset after
// our update may not include the change we requested...
//modelUpdatePending = false;
if (QMailViewerInterface *view = currentViewer()) {
// Update the view to reflect any changes in details from the contact model
view->setMessage(mail);
if (view->objectName() != "smilView") {
// Update the window title also
QTMailWindow::singleton()->setWindowTitle(displayName(mail));
}
}
updateButtons();
}
}
QMailViewerInterface* ReadMail::viewer(QMailMessage::ContentType content, QMailViewerFactory::PresentationType type)
{
ViewerMap::iterator it = contentViews.find(qMakePair(content, type));
if (it == contentViews.end()) {
QString key = QMailViewerFactory::defaultKey(content, type);
if (key.isEmpty())
return 0;
QMailViewerInterface* view = QMailViewerFactory::create(key, views);
view->setObjectName("read-message");
view->widget()->setWhatsThis(tr("This view displays the contents of the message."));
connect(view, SIGNAL(replyToSender()), replyButton, SLOT(trigger()));
connect(view, SIGNAL(replyToAll()), replyAllAction, SLOT(trigger()));
connect(view, SIGNAL(completeMessage()), getThisMailButton, SLOT(trigger()));
connect(view, SIGNAL(forwardMessage()), forwardAction, SLOT(trigger()));
connect(view, SIGNAL(deleteMessage()), deleteButton, SLOT(trigger()));
connect(view, SIGNAL(saveSender()), storeButton, SLOT(trigger()));
connect(view, SIGNAL(contactDetails(QContact)), this, SLOT(displayContact(QContact)));
connect(view, SIGNAL(anchorClicked(QUrl)), this, SLOT(linkClicked(QUrl)));
connect(view, SIGNAL(messageChanged(QMailMessageId)), this, SLOT(messageChanged(QMailMessageId)));
connect(view, SIGNAL(viewMessage(QMailMessageId,QMailViewerFactory::PresentationType)), this, SIGNAL(viewMessage(QMailMessageId,QMailViewerFactory::PresentationType)));
connect(view, SIGNAL(sendMessage(QMailMessage)), this, SIGNAL(sendMessage(QMailMessage)));
// Note: this connection must be queued to prevent spurious emission of close events:
connect(view, SIGNAL(finished()), this, SLOT(viewFinished()), Qt::QueuedConnection);
QWidget* viewWidget = view->widget();
viewWidget->setGeometry(geometry());
views->addWidget(viewWidget);
QSoftMenuBar::clearLabel(viewWidget, QSoftMenuBar::menuKey());
QSoftMenuBar::clearLabel(viewWidget, Qt::Key_Select);
it = contentViews.insert(qMakePair(content, type), view);
}
return it.value();
}
void ReadMail::displayContact(const QContact &contact)
{
displayContact(contact.uid());
}
void ReadMail::displayContact(const QUniqueId &uid)
{
QtopiaServiceRequest req("Contacts", "showContact(QUniqueId)");
req << uid;
req.send();
}
void ReadMail::updateReadStatus()
{
if (mail.id().isValid()) {
bool newMessage(mail.status() & QMailMessage::New);
// This message is no longer new
if (newMessage)
mail.setStatus(QMailMessage::New, false);
// Do not mark as read unless it has been downloaded
if (mail.status() & QMailMessage::Downloaded) {
firstRead = !(mail.status() & QMailMessage::Read);
if (firstRead)
mail.setStatus(QMailMessage::Read, true);
}
if (newMessage || firstRead) {
QMailStore::instance()->updateMessage(&mail);
}
}
}
#include "readmail.moc"
| gpl-2.0 |
pillforge/nesc | libcpp/files.c | 4 | 49791 | /* Part of CPP library. File handling.
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
Split out of cpplib.c, Zack Weinberg, Oct 1998
Reimplemented, Neil Booth, Jul 2003
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, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include "config.h"
#include "system.h"
#include "cpplib.h"
#include "internal.h"
#include "mkdeps.h"
#include "obstack.h"
#include "hashtab.h"
#include "md5.h"
#include <dirent.h>
/* Variable length record files on VMS will have a stat size that includes
record control characters that won't be included in the read size. */
#ifdef VMS
# define FAB_C_VAR 2 /* variable length records (see Starlet fabdef.h) */
# define STAT_SIZE_RELIABLE(ST) ((ST).st_fab_rfm != FAB_C_VAR)
#else
# define STAT_SIZE_RELIABLE(ST) true
#endif
#ifdef __DJGPP__
#include <io.h>
/* For DJGPP redirected input is opened in text mode. */
# define set_stdin_to_binary_mode() \
if (! isatty (0)) setmode (0, O_BINARY)
#else
# define set_stdin_to_binary_mode() /* Nothing */
#endif
/* This structure represents a file searched for by CPP, whether it
exists or not. An instance may be pointed to by more than one
file_hash_entry; at present no reference count is kept. */
struct _cpp_file
{
/* Filename as given to #include or command line switch. */
const char *name;
/* The full path used to find the file. */
const char *path;
/* The full path of the pch file. */
const char *pchname;
/* The file's path with the basename stripped. NULL if it hasn't
been calculated yet. */
const char *dir_name;
/* Chain through all files. */
struct _cpp_file *next_file;
/* The contents of NAME after calling read_file(). */
const uchar *buffer;
/* The macro, if any, preventing re-inclusion. */
const cpp_hashnode *cmacro;
/* The directory in the search path where FILE was found. Used for
#include_next and determining whether a header is a system
header. */
cpp_dir *dir;
/* As filled in by stat(2) for the file. */
struct stat st;
/* File descriptor. Invalid if -1, otherwise open. */
int fd;
/* Zero if this file was successfully opened and stat()-ed,
otherwise errno obtained from failure. */
int err_no;
/* Number of times the file has been stacked for preprocessing. */
unsigned short stack_count;
/* If opened with #import or contains #pragma once. */
bool once_only;
/* If read() failed before. */
bool dont_read;
/* If this file is the main file. */
bool main_file;
/* If BUFFER above contains the true contents of the file. */
bool buffer_valid;
/* File is a PCH (on return from find_include_file). */
bool pch;
};
/* A singly-linked list for all searches for a given file name, with
its head pointed to by a slot in FILE_HASH. The file name is what
appeared between the quotes in a #include directive; it can be
determined implicitly from the hash table location or explicitly
from FILE->name.
FILE is a structure containing details about the file that was
found with that search, or details of how the search failed.
START_DIR is the starting location of the search in the include
chain. The current directories for "" includes are also hashed in
the hash table and therefore unique. Files that are looked up
without using a search path, such as absolute filenames and file
names from the command line share a special starting directory so
they don't cause cache hits with normal include-chain lookups.
If START_DIR is NULL then the entry is for a directory, not a file,
and the directory is in DIR. Since the starting point in a file
lookup chain is never NULL, this means that simple pointer
comparisons against START_DIR can be made to determine cache hits
in file lookups.
If a cache lookup fails because of e.g. an extra "./" in the path,
then nothing will break. It is just less efficient as CPP will
have to do more work re-preprocessing the file, and/or comparing
its contents against earlier once-only files.
*/
struct file_hash_entry
{
struct file_hash_entry *next;
cpp_dir *start_dir;
source_location location;
union
{
_cpp_file *file;
cpp_dir *dir;
} u;
};
/* Number of entries to put in a file_hash_entry pool. */
#define FILE_HASH_POOL_SIZE 127
/* A file hash entry pool. We allocate file_hash_entry object from
one of these. */
struct file_hash_entry_pool
{
/* Number of entries used from this pool. */
unsigned int file_hash_entries_used;
/* Next pool in the chain; used when freeing. */
struct file_hash_entry_pool *next;
/* The memory pool. */
struct file_hash_entry pool[FILE_HASH_POOL_SIZE];
};
static bool open_file (_cpp_file *file);
static bool pch_open_file (cpp_reader *pfile, _cpp_file *file,
bool *invalid_pch);
static bool find_file_in_dir (cpp_reader *pfile, _cpp_file *file,
bool *invalid_pch);
static bool read_file_guts (cpp_reader *pfile, _cpp_file *file);
static bool read_file (cpp_reader *pfile, _cpp_file *file);
static bool should_stack_file (cpp_reader *, _cpp_file *file, bool import);
static struct cpp_dir *search_path_head (cpp_reader *, const char *fname,
int angle_brackets, enum include_type);
static const char *dir_name_of_file (_cpp_file *file);
static void open_file_failed (cpp_reader *pfile, _cpp_file *file, int);
static struct file_hash_entry *search_cache (struct file_hash_entry *head,
const cpp_dir *start_dir);
static _cpp_file *make_cpp_file (cpp_reader *, cpp_dir *, const char *fname);
static void destroy_cpp_file (_cpp_file *);
static cpp_dir *make_cpp_dir (cpp_reader *, const char *dir_name, int sysp);
static void allocate_file_hash_entries (cpp_reader *pfile);
static struct file_hash_entry *new_file_hash_entry (cpp_reader *pfile);
static int report_missing_guard (void **slot, void *b);
static hashval_t file_hash_hash (const void *p);
static int file_hash_eq (const void *p, const void *q);
static char *read_filename_string (int ch, FILE *f);
static void read_name_map (cpp_dir *dir);
static char *remap_filename (cpp_reader *pfile, _cpp_file *file);
static char *append_file_to_dir (const char *fname, cpp_dir *dir);
static bool validate_pch (cpp_reader *, _cpp_file *file, const char *pchname);
static int pchf_save_compare (const void *e1, const void *e2);
static int pchf_compare (const void *d_p, const void *e_p);
static bool check_file_against_entries (cpp_reader *, _cpp_file *, bool);
/* Given a filename in FILE->PATH, with the empty string interpreted
as <stdin>, open it.
On success FILE contains an open file descriptor and stat
information for the file. On failure the file descriptor is -1 and
the appropriate errno is also stored in FILE. Returns TRUE iff
successful.
We used to open files in nonblocking mode, but that caused more
problems than it solved. Do take care not to acquire a controlling
terminal by mistake (this can't happen on sane systems, but
paranoia is a virtue).
Use the three-argument form of open even though we aren't
specifying O_CREAT, to defend against broken system headers.
O_BINARY tells some runtime libraries (notably DJGPP) not to do
newline translation; we can handle DOS line breaks just fine
ourselves. */
static bool
open_file (_cpp_file *file)
{
if (file->path[0] == '\0')
{
file->fd = 0;
set_stdin_to_binary_mode ();
}
else
file->fd = open (file->path, O_RDONLY | O_NOCTTY | O_BINARY, 0666);
if (file->fd != -1)
{
if (fstat (file->fd, &file->st) == 0)
{
if (!S_ISDIR (file->st.st_mode))
{
file->err_no = 0;
return true;
}
/* Ignore a directory and continue the search. The file we're
looking for may be elsewhere in the search path. */
errno = ENOENT;
}
close (file->fd);
file->fd = -1;
}
#if defined(_WIN32) && !defined(__CYGWIN__)
else if (errno == EACCES)
{
/* On most UNIX systems, open succeeds on a directory. Above,
we check if we have opened a directory and if so, set errno
to ENOENT. However, on Windows, opening a directory
fails with EACCES. We want to return ENOENT in that
case too. */
if (stat (file->path, &file->st) == 0
&& S_ISDIR (file->st.st_mode))
errno = ENOENT;
else
/* The call to stat may have reset errno. */
errno = EACCES;
}
#endif
else if (errno == ENOTDIR)
errno = ENOENT;
file->err_no = errno;
return false;
}
/* Temporary PCH intercept of opening a file. Try to find a PCH file
based on FILE->name and FILE->dir, and test those found for
validity using PFILE->cb.valid_pch. Return true iff a valid file is
found. Set *INVALID_PCH if a PCH file is found but wasn't valid. */
static bool
pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
{
static const char extension[] = ".gch";
const char *path = file->path;
size_t len, flen;
char *pchname;
struct stat st;
bool valid = false;
/* No PCH on <stdin> or if not requested. */
if (file->name[0] == '\0' || !pfile->cb.valid_pch)
return false;
flen = strlen (path);
len = flen + sizeof (extension);
pchname = XNEWVEC (char, len);
memcpy (pchname, path, flen);
memcpy (pchname + flen, extension, sizeof (extension));
if (stat (pchname, &st) == 0)
{
DIR *pchdir;
struct dirent *d;
size_t dlen, plen = len;
if (!S_ISDIR (st.st_mode))
valid = validate_pch (pfile, file, pchname);
else if ((pchdir = opendir (pchname)) != NULL)
{
pchname[plen - 1] = '/';
while ((d = readdir (pchdir)) != NULL)
{
dlen = strlen (d->d_name) + 1;
if ((strcmp (d->d_name, ".") == 0)
|| (strcmp (d->d_name, "..") == 0))
continue;
if (dlen + plen > len)
{
len += dlen + 64;
pchname = XRESIZEVEC (char, pchname, len);
}
memcpy (pchname + plen, d->d_name, dlen);
valid = validate_pch (pfile, file, pchname);
if (valid)
break;
}
closedir (pchdir);
}
if (valid)
file->pch = true;
else
*invalid_pch = true;
}
if (valid)
file->pchname = pchname;
else
free (pchname);
return valid;
}
/* Try to open the path FILE->name appended to FILE->dir. This is
where remap and PCH intercept the file lookup process. Return true
if the file was found, whether or not the open was successful.
Set *INVALID_PCH to true if a PCH file is found but wasn't valid. */
static bool
find_file_in_dir (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
{
char *path;
if (CPP_OPTION (pfile, remap) && (path = remap_filename (pfile, file)))
;
else
if (file->dir->construct)
path = file->dir->construct (file->name, file->dir);
else
path = append_file_to_dir (file->name, file->dir);
if (path)
{
hashval_t hv = htab_hash_string (path);
char *copy;
void **pp;
if (htab_find_with_hash (pfile->nonexistent_file_hash, path, hv) != NULL)
{
file->err_no = ENOENT;
return false;
}
file->path = path;
if (pch_open_file (pfile, file, invalid_pch))
return true;
if (open_file (file))
return true;
if (file->err_no != ENOENT)
{
open_file_failed (pfile, file, 0);
return true;
}
/* We copy the path name onto an obstack partly so that we don't
leak the memory, but mostly so that we don't fragment the
heap. */
copy = obstack_copy0 (&pfile->nonexistent_file_ob, path,
strlen (path));
free (path);
pp = htab_find_slot_with_hash (pfile->nonexistent_file_hash,
copy, hv, INSERT);
*pp = copy;
file->path = file->name;
}
else
{
file->err_no = ENOENT;
file->path = NULL;
}
return false;
}
/* Return tue iff the missing_header callback found the given HEADER. */
static bool
search_path_exhausted (cpp_reader *pfile, const char *header, _cpp_file *file)
{
missing_header_cb func = pfile->cb.missing_header;
/* When the regular search path doesn't work, try context dependent
headers search paths. */
if (func
&& file->dir == NULL)
{
if ((file->path = func (pfile, header, &file->dir)) != NULL)
{
if (open_file (file))
return true;
free ((void *)file->path);
}
file->path = file->name;
}
return false;
}
bool
_cpp_find_failed (_cpp_file *file)
{
return file->err_no != 0;
}
/* Given a filename FNAME search for such a file in the include path
starting from START_DIR. If FNAME is the empty string it is
interpreted as STDIN if START_DIR is PFILE->no_search_path.
If the file is not found in the file cache fall back to the O/S and
add the result to our cache.
If the file was not found in the filesystem, or there was an error
opening it, then ERR_NO is nonzero and FD is -1. If the file was
found, then ERR_NO is zero and FD could be -1 or an open file
descriptor. FD can be -1 if the file was found in the cache and
had previously been closed. To open it again pass the return value
to open_file().
*/
_cpp_file *
_cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool fake, int angle_brackets)
{
struct file_hash_entry *entry, **hash_slot;
_cpp_file *file;
bool invalid_pch = false;
bool saw_bracket_include = false;
bool saw_quote_include = false;
struct cpp_dir *found_in_cache = NULL;
/* Ensure we get no confusion between cached files and directories. */
if (start_dir == NULL)
cpp_error (pfile, CPP_DL_ICE, "NULL directory in find_file");
hash_slot = (struct file_hash_entry **)
htab_find_slot_with_hash (pfile->file_hash, fname,
htab_hash_string (fname),
INSERT);
/* First check the cache before we resort to memory allocation. */
entry = search_cache (*hash_slot, start_dir);
if (entry)
return entry->u.file;
file = make_cpp_file (pfile, start_dir, fname);
/* Try each path in the include chain. */
for (; !fake ;)
{
if (find_file_in_dir (pfile, file, &invalid_pch))
break;
file->dir = file->dir->next;
if (file->dir == NULL)
{
if (search_path_exhausted (pfile, fname, file))
{
/* Although this file must not go in the cache, because
the file found might depend on things (like the current file)
that aren't represented in the cache, it still has to go in
the list of all files so that #import works. */
file->next_file = pfile->all_files;
pfile->all_files = file;
return file;
}
open_file_failed (pfile, file, angle_brackets);
if (invalid_pch)
{
cpp_error (pfile, CPP_DL_ERROR,
"one or more PCH files were found, but they were invalid");
if (!cpp_get_options (pfile)->warn_invalid_pch)
cpp_error (pfile, CPP_DL_ERROR,
"use -Winvalid-pch for more information");
}
break;
}
/* Only check the cache for the starting location (done above)
and the quote and bracket chain heads because there are no
other possible starting points for searches. */
if (file->dir == pfile->bracket_include)
saw_bracket_include = true;
else if (file->dir == pfile->quote_include)
saw_quote_include = true;
else
continue;
entry = search_cache (*hash_slot, file->dir);
if (entry)
{
found_in_cache = file->dir;
break;
}
}
if (entry)
{
/* Cache for START_DIR too, sharing the _cpp_file structure. */
free ((char *) file->name);
free (file);
file = entry->u.file;
}
else
{
/* This is a new file; put it in the list. */
file->next_file = pfile->all_files;
pfile->all_files = file;
}
/* Store this new result in the hash table. */
entry = new_file_hash_entry (pfile);
entry->next = *hash_slot;
entry->start_dir = start_dir;
entry->location = pfile->line_table->highest_location;
entry->u.file = file;
*hash_slot = entry;
/* If we passed the quote or bracket chain heads, cache them also.
This speeds up processing if there are lots of -I options. */
if (saw_bracket_include
&& pfile->bracket_include != start_dir
&& found_in_cache != pfile->bracket_include)
{
entry = new_file_hash_entry (pfile);
entry->next = *hash_slot;
entry->start_dir = pfile->bracket_include;
entry->location = pfile->line_table->highest_location;
entry->u.file = file;
*hash_slot = entry;
}
if (saw_quote_include
&& pfile->quote_include != start_dir
&& found_in_cache != pfile->quote_include)
{
entry = new_file_hash_entry (pfile);
entry->next = *hash_slot;
entry->start_dir = pfile->quote_include;
entry->location = pfile->line_table->highest_location;
entry->u.file = file;
*hash_slot = entry;
}
return file;
}
/* Read a file into FILE->buffer, returning true on success.
If FILE->fd is something weird, like a block device, we don't want
to read it at all. Don't even try to figure out what something is,
except for plain files and block devices, since there is no
reliable portable way of doing this.
FIXME: Flush file cache and try again if we run out of memory. */
static bool
read_file_guts (cpp_reader *pfile, _cpp_file *file)
{
ssize_t size, total, count;
uchar *buf;
bool regular;
if (S_ISBLK (file->st.st_mode))
{
cpp_error (pfile, CPP_DL_ERROR, "%s is a block device", file->path);
return false;
}
regular = S_ISREG (file->st.st_mode);
if (regular)
{
/* off_t might have a wider range than ssize_t - in other words,
the max size of a file might be bigger than the address
space. We can't handle a file that large. (Anyone with
a single source file bigger than 2GB needs to rethink
their coding style.) Some systems (e.g. AIX 4.1) define
SSIZE_MAX to be much smaller than the actual range of the
type. Use INTTYPE_MAXIMUM unconditionally to ensure this
does not bite us. */
if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t))
{
cpp_error (pfile, CPP_DL_ERROR, "%s is too large", file->path);
return false;
}
size = file->st.st_size;
}
else
/* 8 kilobytes is a sensible starting size. It ought to be bigger
than the kernel pipe buffer, and it's definitely bigger than
the majority of C source files. */
size = 8 * 1024;
buf = XNEWVEC (uchar, size + 1);
total = 0;
while ((count = read (file->fd, buf + total, size - total)) > 0)
{
total += count;
if (total == size)
{
if (regular)
break;
size *= 2;
buf = XRESIZEVEC (uchar, buf, size + 1);
}
}
if (count < 0)
{
cpp_errno (pfile, CPP_DL_ERROR, file->path);
return false;
}
if (regular && total != size && STAT_SIZE_RELIABLE (file->st))
cpp_error (pfile, CPP_DL_WARNING,
"%s is shorter than expected", file->path);
file->buffer = _cpp_convert_input (pfile, CPP_OPTION (pfile, input_charset),
buf, size, total, &file->st.st_size);
file->buffer_valid = true;
return true;
}
/* Convenience wrapper around read_file_guts that opens the file if
necessary and closes the file descriptor after reading. FILE must
have been passed through find_file() at some stage. */
static bool
read_file (cpp_reader *pfile, _cpp_file *file)
{
/* If we already have its contents in memory, succeed immediately. */
if (file->buffer_valid)
return true;
/* If an earlier read failed for some reason don't try again. */
if (file->dont_read || file->err_no)
return false;
if (file->fd == -1 && !open_file (file))
{
open_file_failed (pfile, file, 0);
return false;
}
file->dont_read = !read_file_guts (pfile, file);
close (file->fd);
file->fd = -1;
return !file->dont_read;
}
/* Returns TRUE if FILE's contents have been successfully placed in
FILE->buffer and the file should be stacked, otherwise false. */
static bool
should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import)
{
_cpp_file *f;
/* Skip once-only files. */
if (file->once_only)
return false;
/* We must mark the file once-only if #import now, before header
guard checks. Otherwise, undefining the header guard might
cause the file to be re-stacked. */
if (import)
{
_cpp_mark_file_once_only (pfile, file);
/* Don't stack files that have been stacked before. */
if (file->stack_count)
return false;
}
/* Skip if the file had a header guard and the macro is defined.
PCH relies on this appearing before the PCH handler below. */
if (file->cmacro && file->cmacro->type == NT_MACRO)
return false;
/* Handle PCH files immediately; don't stack them. */
if (file->pch)
{
pfile->cb.read_pch (pfile, file->pchname, file->fd, file->path);
close (file->fd);
file->fd = -1;
return false;
}
if (!read_file (pfile, file))
return false;
/* Check the file against the PCH file. This is done before
checking against files we've already seen, since it may save on
I/O. */
if (check_file_against_entries (pfile, file, import))
{
/* If this isn't a #import, but yet we can't include the file,
that means that it was #import-ed in the PCH file,
so we can never include it again. */
if (! import)
_cpp_mark_file_once_only (pfile, file);
return false;
}
/* Now we've read the file's contents, we can stack it if there
are no once-only files. */
if (!pfile->seen_once_only)
return true;
/* We may have read the file under a different name. Look
for likely candidates and compare file contents to be sure. */
for (f = pfile->all_files; f; f = f->next_file)
{
if (f == file)
continue;
if ((import || f->once_only)
&& f->err_no == 0
&& f->st.st_mtime == file->st.st_mtime
&& f->st.st_size == file->st.st_size)
{
_cpp_file *ref_file;
bool same_file_p = false;
if (f->buffer && !f->buffer_valid)
{
/* We already have a buffer but it is not valid, because
the file is still stacked. Make a new one. */
ref_file = make_cpp_file (pfile, f->dir, f->name);
ref_file->path = f->path;
}
else
/* The file is not stacked anymore. We can reuse it. */
ref_file = f;
same_file_p = read_file (pfile, ref_file)
/* Size might have changed in read_file(). */
&& ref_file->st.st_size == file->st.st_size
&& !memcmp (ref_file->buffer,
file->buffer,
file->st.st_size);
if (f->buffer && !f->buffer_valid)
{
ref_file->path = 0;
destroy_cpp_file (ref_file);
}
if (same_file_p)
break;
}
}
return f == NULL;
}
/* Place the file referenced by FILE into a new buffer on the buffer
stack if possible. IMPORT is true if this stacking attempt is
because of a #import directive. Returns true if a buffer is
stacked. */
bool
_cpp_stack_file (cpp_reader *pfile, _cpp_file *file, bool import)
{
cpp_buffer *buffer;
int sysp;
if (!should_stack_file (pfile, file, import))
return false;
if (pfile->buffer == NULL || file->dir == NULL)
sysp = 0;
else
sysp = MAX (pfile->buffer->sysp, file->dir->sysp);
/* Add the file to the dependencies on its first inclusion. */
if (CPP_OPTION (pfile, deps.style) > !!sysp && !file->stack_count)
{
if (!file->main_file || !CPP_OPTION (pfile, deps.ignore_main_file))
deps_add_dep (pfile->deps, file->path);
}
/* Clear buffer_valid since _cpp_clean_line messes it up. */
file->buffer_valid = false;
file->stack_count++;
/* Stack the buffer. */
buffer = cpp_push_buffer (pfile, file->buffer, file->st.st_size,
CPP_OPTION (pfile, preprocessed)
&& !CPP_OPTION (pfile, directives_only));
buffer->file = file;
buffer->sysp = sysp;
/* Initialize controlling macro state. */
pfile->mi_valid = true;
pfile->mi_cmacro = 0;
/* Generate the call back. */
_cpp_do_file_change (pfile, LC_ENTER, file->path, 1, sysp);
return true;
}
/* Mark FILE to be included once only. */
void
_cpp_mark_file_once_only (cpp_reader *pfile, _cpp_file *file)
{
pfile->seen_once_only = true;
file->once_only = true;
}
/* Return the directory from which searching for FNAME should start,
considering the directive TYPE and ANGLE_BRACKETS. If there is
nothing left in the path, returns NULL. */
static struct cpp_dir *
search_path_head (cpp_reader *pfile, const char *fname, int angle_brackets,
enum include_type type)
{
cpp_dir *dir;
_cpp_file *file;
if (IS_ABSOLUTE_PATH (fname))
return &pfile->no_search_path;
/* pfile->buffer is NULL when processing an -include command-line flag. */
file = pfile->buffer == NULL ? pfile->main_file : pfile->buffer->file;
/* For #include_next, skip in the search path past the dir in which
the current file was found, but if it was found via an absolute
path use the normal search logic. */
if (type == IT_INCLUDE_NEXT && file->dir
&& file->dir != &pfile->no_search_path)
dir = file->dir->next;
else if (angle_brackets)
dir = pfile->bracket_include;
else if (type == IT_CMDLINE)
/* -include and -imacros use the #include "" chain with the
preprocessor's cwd prepended. */
return make_cpp_dir (pfile, "./", false);
else if (pfile->quote_ignores_source_dir)
dir = pfile->quote_include;
else
return make_cpp_dir (pfile, dir_name_of_file (file),
pfile->buffer ? pfile->buffer->sysp : 0);
if (dir == NULL)
cpp_error (pfile, CPP_DL_ERROR,
"no include path in which to search for %s", fname);
return dir;
}
/* Strip the basename from the file's path. It ends with a slash if
of nonzero length. Note that this procedure also works for
<stdin>, which is represented by the empty string. */
static const char *
dir_name_of_file (_cpp_file *file)
{
if (!file->dir_name)
{
size_t len = lbasename (file->path) - file->path;
char *dir_name = XNEWVEC (char, len + 1);
memcpy (dir_name, file->path, len);
dir_name[len] = '\0';
file->dir_name = dir_name;
}
return file->dir_name;
}
/* Handles #include-family directives (distinguished by TYPE),
including HEADER, and the command line -imacros and -include.
Returns true if a buffer was stacked. */
bool
_cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
enum include_type type)
{
struct cpp_dir *dir;
_cpp_file *file;
dir = search_path_head (pfile, fname, angle_brackets, type);
if (!dir)
return false;
file = _cpp_find_file (pfile, fname, dir, false, angle_brackets);
/* Compensate for the increment in linemap_add. In the case of a
normal #include, we're currently at the start of the line
*following* the #include. A separate source_location for this
location makes no sense (until we do the LC_LEAVE), and
complicates LAST_SOURCE_LINE_LOCATION. This does not apply if we
found a PCH file (in which case linemap_add is not called) or we
were included from the command-line. */
if (! file->pch && file->err_no == 0 && type != IT_CMDLINE)
pfile->line_table->highest_location--;
return _cpp_stack_file (pfile, file, type == IT_IMPORT);
}
/* Could not open FILE. The complication is dependency output. */
static void
open_file_failed (cpp_reader *pfile, _cpp_file *file, int angle_brackets)
{
int sysp = pfile->line_table->highest_line > 1 && pfile->buffer ? pfile->buffer->sysp : 0;
bool print_dep = CPP_OPTION (pfile, deps.style) > (angle_brackets || !!sysp);
errno = file->err_no;
if (print_dep && CPP_OPTION (pfile, deps.missing_files) && errno == ENOENT)
deps_add_dep (pfile->deps, file->name);
else
{
/* If we are outputting dependencies but not for this file then
don't error because we can still produce correct output. */
if (CPP_OPTION (pfile, deps.style) && ! print_dep)
cpp_errno (pfile, CPP_DL_WARNING, file->path);
else
cpp_errno (pfile, CPP_DL_ERROR, file->path);
}
}
/* Search in the chain beginning at HEAD for a file whose search path
started at START_DIR != NULL. */
static struct file_hash_entry *
search_cache (struct file_hash_entry *head, const cpp_dir *start_dir)
{
while (head && head->start_dir != start_dir)
head = head->next;
return head;
}
/* Allocate a new _cpp_file structure. */
static _cpp_file *
make_cpp_file (cpp_reader *pfile, cpp_dir *dir, const char *fname)
{
_cpp_file *file;
file = XCNEW (_cpp_file);
file->main_file = !pfile->buffer;
file->fd = -1;
file->dir = dir;
file->name = xstrdup (fname);
return file;
}
/* Release a _cpp_file structure. */
static void
destroy_cpp_file (_cpp_file *file)
{
if (file->buffer)
free ((void *) file->buffer);
free ((void *) file->name);
free (file);
}
/* Release all the files allocated by this reader. */
static void
destroy_all_cpp_files (cpp_reader *pfile)
{
_cpp_file *iter = pfile->all_files;
while (iter)
{
_cpp_file *next = iter->next_file;
destroy_cpp_file (iter);
iter = next;
}
}
/* A hash of directory names. The directory names are the path names
of files which contain a #include "", the included file name is
appended to this directories.
To avoid duplicate entries we follow the convention that all
non-empty directory names should end in a '/'. DIR_NAME must be
stored in permanently allocated memory. */
static cpp_dir *
make_cpp_dir (cpp_reader *pfile, const char *dir_name, int sysp)
{
struct file_hash_entry *entry, **hash_slot;
cpp_dir *dir;
hash_slot = (struct file_hash_entry **)
htab_find_slot_with_hash (pfile->dir_hash, dir_name,
htab_hash_string (dir_name),
INSERT);
/* Have we already hashed this directory? */
for (entry = *hash_slot; entry; entry = entry->next)
if (entry->start_dir == NULL)
return entry->u.dir;
dir = XCNEW (cpp_dir);
dir->next = pfile->quote_include;
dir->name = (char *) dir_name;
dir->len = strlen (dir_name);
dir->sysp = sysp;
dir->construct = 0;
/* Store this new result in the hash table. */
entry = new_file_hash_entry (pfile);
entry->next = *hash_slot;
entry->start_dir = NULL;
entry->location = pfile->line_table->highest_location;
entry->u.dir = dir;
*hash_slot = entry;
return dir;
}
/* Create a new block of memory for file hash entries. */
static void
allocate_file_hash_entries (cpp_reader *pfile)
{
struct file_hash_entry_pool *pool = XNEW (struct file_hash_entry_pool);
pool->file_hash_entries_used = 0;
pool->next = pfile->file_hash_entries;
pfile->file_hash_entries = pool;
}
/* Return a new file hash entry. */
static struct file_hash_entry *
new_file_hash_entry (cpp_reader *pfile)
{
unsigned int idx;
if (pfile->file_hash_entries->file_hash_entries_used == FILE_HASH_POOL_SIZE)
allocate_file_hash_entries (pfile);
idx = pfile->file_hash_entries->file_hash_entries_used++;
return &pfile->file_hash_entries->pool[idx];
}
/* Free the file hash entry pools. */
static void
free_file_hash_entries (cpp_reader *pfile)
{
struct file_hash_entry_pool *iter = pfile->file_hash_entries;
while (iter)
{
struct file_hash_entry_pool *next = iter->next;
free (iter);
iter = next;
}
}
/* Returns TRUE if a file FNAME has ever been successfully opened.
This routine is not intended to correctly handle filenames aliased
by links or redundant . or .. traversals etc. */
bool
cpp_included (cpp_reader *pfile, const char *fname)
{
struct file_hash_entry *entry;
entry = (struct file_hash_entry *)
htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
while (entry && (entry->start_dir == NULL || entry->u.file->err_no))
entry = entry->next;
return entry != NULL;
}
/* Returns TRUE if a file FNAME has ever been successfully opened
before LOCATION. This routine is not intended to correctly handle
filenames aliased by links or redundant . or .. traversals etc. */
bool
cpp_included_before (cpp_reader *pfile, const char *fname,
source_location location)
{
struct file_hash_entry *entry;
entry = (struct file_hash_entry *)
htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
while (entry && (entry->start_dir == NULL || entry->u.file->err_no
|| entry->location > location))
entry = entry->next;
return entry != NULL;
}
/* Calculate the hash value of a file hash entry P. */
static hashval_t
file_hash_hash (const void *p)
{
struct file_hash_entry *entry = (struct file_hash_entry *) p;
const char *hname;
if (entry->start_dir)
hname = entry->u.file->name;
else
hname = entry->u.dir->name;
return htab_hash_string (hname);
}
/* Compare a string Q against a file hash entry P. */
static int
file_hash_eq (const void *p, const void *q)
{
struct file_hash_entry *entry = (struct file_hash_entry *) p;
const char *fname = (const char *) q;
const char *hname;
if (entry->start_dir)
hname = entry->u.file->name;
else
hname = entry->u.dir->name;
return strcmp (hname, fname) == 0;
}
/* Compare entries in the nonexistent file hash table. These are just
strings. */
static int
nonexistent_file_hash_eq (const void *p, const void *q)
{
return strcmp (p, q) == 0;
}
/* Initialize everything in this source file. */
void
_cpp_init_files (cpp_reader *pfile)
{
pfile->file_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
NULL, xcalloc, free);
pfile->dir_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
NULL, xcalloc, free);
allocate_file_hash_entries (pfile);
pfile->nonexistent_file_hash = htab_create_alloc (127, htab_hash_string,
nonexistent_file_hash_eq,
NULL, xcalloc, free);
_obstack_begin (&pfile->nonexistent_file_ob, 0, 0,
(void *(*) (long)) xmalloc,
(void (*) (void *)) free);
}
/* Finalize everything in this source file. */
void
_cpp_cleanup_files (cpp_reader *pfile)
{
htab_delete (pfile->file_hash);
htab_delete (pfile->dir_hash);
htab_delete (pfile->nonexistent_file_hash);
obstack_free (&pfile->nonexistent_file_ob, 0);
free_file_hash_entries (pfile);
destroy_all_cpp_files (pfile);
}
/* Make the parser forget about files it has seen. This can be useful
for resetting the parser to start another run. */
void
cpp_clear_file_cache (cpp_reader *pfile)
{
_cpp_cleanup_files (pfile);
pfile->file_hash_entries = NULL;
pfile->all_files = NULL;
_cpp_init_files (pfile);
}
/* Enter a file name in the hash for the sake of cpp_included. */
void
_cpp_fake_include (cpp_reader *pfile, const char *fname)
{
_cpp_find_file (pfile, fname, pfile->buffer->file->dir, true, 0);
}
/* Not everyone who wants to set system-header-ness on a buffer can
see the details of a buffer. This is an exported interface because
fix-header needs it. */
void
cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc)
{
int flags = 0;
const struct line_maps *line_table = pfile->line_table;
const struct line_map *map = &line_table->maps[line_table->used-1];
/* 1 = system header, 2 = system header to be treated as C. */
if (syshdr)
flags = 1 + (externc != 0);
pfile->buffer->sysp = flags;
_cpp_do_file_change (pfile, LC_RENAME, map->to_file,
SOURCE_LINE (map, pfile->line_table->highest_line), flags);
}
/* Allow the client to change the current file. Used by the front end
to achieve pseudo-file names like <built-in>.
If REASON is LC_LEAVE, then NEW_NAME must be NULL. */
void
cpp_change_file (cpp_reader *pfile, enum lc_reason reason,
const char *new_name)
{
_cpp_do_file_change (pfile, reason, new_name, 1, 0);
}
/* Callback function for htab_traverse. */
static int
report_missing_guard (void **slot, void *b)
{
struct file_hash_entry *entry = (struct file_hash_entry *) *slot;
int *bannerp = (int *) b;
/* Skip directories. */
if (entry->start_dir != NULL)
{
_cpp_file *file = entry->u.file;
/* We don't want MI guard advice for the main file. */
if (file->cmacro == NULL && file->stack_count == 1 && !file->main_file)
{
if (*bannerp == 0)
{
fputs (_("Multiple include guards may be useful for:\n"),
stderr);
*bannerp = 1;
}
fputs (entry->u.file->path, stderr);
putc ('\n', stderr);
}
}
return 0;
}
/* Report on all files that might benefit from a multiple include guard.
Triggered by -H. */
void
_cpp_report_missing_guards (cpp_reader *pfile)
{
int banner = 0;
htab_traverse (pfile->file_hash, report_missing_guard, &banner);
}
/* Locate HEADER, and determine whether it is newer than the current
file. If it cannot be located or dated, return -1, if it is
newer, return 1, otherwise 0. */
int
_cpp_compare_file_date (cpp_reader *pfile, const char *fname,
int angle_brackets)
{
_cpp_file *file;
struct cpp_dir *dir;
dir = search_path_head (pfile, fname, angle_brackets, IT_INCLUDE);
if (!dir)
return -1;
file = _cpp_find_file (pfile, fname, dir, false, angle_brackets);
if (file->err_no)
return -1;
if (file->fd != -1)
{
close (file->fd);
file->fd = -1;
}
return file->st.st_mtime > pfile->buffer->file->st.st_mtime;
}
/* Pushes the given file onto the buffer stack. Returns nonzero if
successful. */
bool
cpp_push_include (cpp_reader *pfile, const char *fname)
{
return _cpp_stack_include (pfile, fname, false, IT_CMDLINE);
}
/* Do appropriate cleanup when a file INC's buffer is popped off the
input stack. */
void
_cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file)
{
/* Record the inclusion-preventing macro, which could be NULL
meaning no controlling macro. */
if (pfile->mi_valid && file->cmacro == NULL)
file->cmacro = pfile->mi_cmacro;
/* Invalidate control macros in the #including file. */
pfile->mi_valid = false;
if (file->buffer)
{
free ((void *) file->buffer);
file->buffer = NULL;
file->buffer_valid = false;
}
}
/* Inteface to file statistics record in _cpp_file structure. */
struct stat *
_cpp_get_file_stat (_cpp_file *file)
{
return &file->st;
}
/* Set the include chain for "" to QUOTE, for <> to BRACKET. If
QUOTE_IGNORES_SOURCE_DIR, then "" includes do not look in the
directory of the including file.
If BRACKET does not lie in the QUOTE chain, it is set to QUOTE. */
void
cpp_set_include_chains (cpp_reader *pfile, cpp_dir *quote, cpp_dir *bracket,
int quote_ignores_source_dir)
{
pfile->quote_include = quote;
pfile->bracket_include = quote;
pfile->quote_ignores_source_dir = quote_ignores_source_dir;
for (; quote; quote = quote->next)
{
quote->name_map = NULL;
quote->len = strlen (quote->name);
if (quote == bracket)
pfile->bracket_include = bracket;
}
}
/* Append the file name to the directory to create the path, but don't
turn / into // or // into ///; // may be a namespace escape. */
static char *
append_file_to_dir (const char *fname, cpp_dir *dir)
{
size_t dlen, flen;
char *path;
dlen = dir->len;
flen = strlen (fname);
path = XNEWVEC (char, dlen + 1 + flen + 1);
memcpy (path, dir->name, dlen);
if (dlen && path[dlen - 1] != '/')
path[dlen++] = '/';
memcpy (&path[dlen], fname, flen + 1);
return path;
}
/* Read a space delimited string of unlimited length from a stdio
file F. */
static char *
read_filename_string (int ch, FILE *f)
{
char *alloc, *set;
int len;
len = 20;
set = alloc = XNEWVEC (char, len + 1);
if (! is_space (ch))
{
*set++ = ch;
while ((ch = getc (f)) != EOF && ! is_space (ch))
{
if (set - alloc == len)
{
len *= 2;
alloc = XRESIZEVEC (char, alloc, len + 1);
set = alloc + len / 2;
}
*set++ = ch;
}
}
*set = '\0';
ungetc (ch, f);
return alloc;
}
/* Read the file name map file for DIR. */
static void
read_name_map (cpp_dir *dir)
{
static const char FILE_NAME_MAP_FILE[] = "header.gcc";
char *name;
FILE *f;
size_t len, count = 0, room = 9;
len = dir->len;
name = (char *) alloca (len + sizeof (FILE_NAME_MAP_FILE) + 1);
memcpy (name, dir->name, len);
if (len && name[len - 1] != '/')
name[len++] = '/';
strcpy (name + len, FILE_NAME_MAP_FILE);
f = fopen (name, "r");
dir->name_map = XNEWVEC (const char *, room);
/* Silently return NULL if we cannot open. */
if (f)
{
int ch;
while ((ch = getc (f)) != EOF)
{
char *to;
if (is_space (ch))
continue;
if (count + 2 > room)
{
room += 8;
dir->name_map = XRESIZEVEC (const char *, dir->name_map, room);
}
dir->name_map[count] = read_filename_string (ch, f);
while ((ch = getc (f)) != EOF && is_hspace (ch))
;
to = read_filename_string (ch, f);
if (IS_ABSOLUTE_PATH (to))
dir->name_map[count + 1] = to;
else
{
dir->name_map[count + 1] = append_file_to_dir (to, dir);
free (to);
}
count += 2;
while ((ch = getc (f)) != '\n')
if (ch == EOF)
break;
}
fclose (f);
}
/* Terminate the list of maps. */
dir->name_map[count] = NULL;
}
/* Remap a FILE's name based on the file_name_map, if any, for
FILE->dir. If the file name has any directory separators,
recursively check those directories too. */
static char *
remap_filename (cpp_reader *pfile, _cpp_file *file)
{
const char *fname, *p;
char *new_dir;
cpp_dir *dir;
size_t index, len;
dir = file->dir;
fname = file->name;
for (;;)
{
if (!dir->name_map)
read_name_map (dir);
for (index = 0; dir->name_map[index]; index += 2)
if (!strcmp (dir->name_map[index], fname))
return xstrdup (dir->name_map[index + 1]);
p = strchr (fname, '/');
if (!p || p == fname)
return NULL;
len = dir->len + (p - fname + 1);
new_dir = XNEWVEC (char, len + 1);
memcpy (new_dir, dir->name, dir->len);
memcpy (new_dir + dir->len, fname, p - fname + 1);
new_dir[len] = '\0';
dir = make_cpp_dir (pfile, new_dir, dir->sysp);
fname = p + 1;
}
}
/* Returns true if PCHNAME is a valid PCH file for FILE. */
static bool
validate_pch (cpp_reader *pfile, _cpp_file *file, const char *pchname)
{
const char *saved_path = file->path;
bool valid = false;
file->path = pchname;
if (open_file (file))
{
valid = 1 & pfile->cb.valid_pch (pfile, pchname, file->fd);
if (!valid)
{
close (file->fd);
file->fd = -1;
}
if (CPP_OPTION (pfile, print_include_names))
{
unsigned int i;
for (i = 1; i < pfile->line_table->depth; i++)
putc ('.', stderr);
fprintf (stderr, "%c %s\n",
valid ? '!' : 'x', pchname);
}
}
file->path = saved_path;
return valid;
}
/* Get the path associated with the _cpp_file F. The path includes
the base name from the include directive and the directory it was
found in via the search path. */
const char *
cpp_get_path (struct _cpp_file *f)
{
return f->path;
}
/* Get the directory associated with the _cpp_file F. */
cpp_dir *
cpp_get_dir (struct _cpp_file *f)
{
return f->dir;
}
/* Get the cpp_buffer currently associated with the cpp_reader
PFILE. */
cpp_buffer *
cpp_get_buffer (cpp_reader *pfile)
{
return pfile->buffer;
}
/* Get the _cpp_file associated with the cpp_buffer B. */
_cpp_file *
cpp_get_file (cpp_buffer *b)
{
return b->file;
}
/* Get the previous cpp_buffer given a cpp_buffer B. The previous
buffer is the buffer that included the given buffer. */
cpp_buffer *
cpp_get_prev (cpp_buffer *b)
{
return b->prev;
}
/* This data structure holds the list of header files that were seen
while the PCH was being built. The 'entries' field is kept sorted
in memcmp() order; yes, this means that on little-endian systems,
it's sorted initially by the least-significant byte of 'size', but
that's OK. The code does rely on having entries with the same size
next to each other. */
struct pchf_entry {
/* The size of this file. This is used to save running a MD5 checksum
if the sizes don't match. */
off_t size;
/* The MD5 checksum of this file. */
unsigned char sum[16];
/* Is this file to be included only once? */
bool once_only;
};
struct pchf_data {
/* Number of pchf_entry structures. */
size_t count;
/* Are there any values with once_only set?
This is used as an optimisation, it means we don't have to search
the structure if we're processing a regular #include. */
bool have_once_only;
struct pchf_entry entries[1];
};
static struct pchf_data *pchf;
/* A qsort ordering function for pchf_entry structures. */
static int
pchf_save_compare (const void *e1, const void *e2)
{
return memcmp (e1, e2, sizeof (struct pchf_entry));
}
/* Create and write to F a pchf_data structure. */
bool
_cpp_save_file_entries (cpp_reader *pfile, FILE *fp)
{
size_t count = 0;
struct pchf_data *result;
size_t result_size;
_cpp_file *f;
for (f = pfile->all_files; f; f = f->next_file)
++count;
result_size = (sizeof (struct pchf_data)
+ sizeof (struct pchf_entry) * (count - 1));
result = XCNEWVAR (struct pchf_data, result_size);
result->count = 0;
result->have_once_only = false;
for (f = pfile->all_files; f; f = f->next_file)
{
size_t count;
/* This should probably never happen, since if a read error occurred
the PCH file shouldn't be written... */
if (f->dont_read || f->err_no)
continue;
if (f->stack_count == 0)
continue;
count = result->count++;
result->entries[count].once_only = f->once_only;
/* |= is avoided in the next line because of an HP C compiler bug */
result->have_once_only = result->have_once_only | f->once_only;
if (f->buffer_valid)
md5_buffer ((const char *)f->buffer,
f->st.st_size, result->entries[count].sum);
else
{
FILE *ff;
int oldfd = f->fd;
if (!open_file (f))
{
open_file_failed (pfile, f, 0);
return false;
}
ff = fdopen (f->fd, "rb");
md5_stream (ff, result->entries[count].sum);
fclose (ff);
f->fd = oldfd;
}
result->entries[count].size = f->st.st_size;
}
result_size = (sizeof (struct pchf_data)
+ sizeof (struct pchf_entry) * (result->count - 1));
qsort (result->entries, result->count, sizeof (struct pchf_entry),
pchf_save_compare);
return fwrite (result, result_size, 1, fp) == 1;
}
/* Read the pchf_data structure from F. */
bool
_cpp_read_file_entries (cpp_reader *pfile ATTRIBUTE_UNUSED, FILE *f)
{
struct pchf_data d;
if (fread (&d, sizeof (struct pchf_data) - sizeof (struct pchf_entry), 1, f)
!= 1)
return false;
pchf = XNEWVAR (struct pchf_data, sizeof (struct pchf_data)
+ sizeof (struct pchf_entry) * (d.count - 1));
memcpy (pchf, &d, sizeof (struct pchf_data) - sizeof (struct pchf_entry));
if (fread (pchf->entries, sizeof (struct pchf_entry), d.count, f)
!= d.count)
return false;
return true;
}
/* The parameters for pchf_compare. */
struct pchf_compare_data
{
/* The size of the file we're looking for. */
off_t size;
/* The MD5 checksum of the file, if it's been computed. */
unsigned char sum[16];
/* Is SUM valid? */
bool sum_computed;
/* Do we need to worry about entries that don't have ONCE_ONLY set? */
bool check_included;
/* The file that we're searching for. */
_cpp_file *f;
};
/* bsearch comparison function; look for D_P in E_P. */
static int
pchf_compare (const void *d_p, const void *e_p)
{
const struct pchf_entry *e = (const struct pchf_entry *)e_p;
struct pchf_compare_data *d = (struct pchf_compare_data *)d_p;
int result;
result = memcmp (&d->size, &e->size, sizeof (off_t));
if (result != 0)
return result;
if (! d->sum_computed)
{
_cpp_file *const f = d->f;
md5_buffer ((const char *)f->buffer, f->st.st_size, d->sum);
d->sum_computed = true;
}
result = memcmp (d->sum, e->sum, 16);
if (result != 0)
return result;
if (d->check_included || e->once_only)
return 0;
else
return 1;
}
/* Check that F is not in a list read from a PCH file (if any).
Assumes that f->buffer_valid is true. Return TRUE if the file
should not be read. */
static bool
check_file_against_entries (cpp_reader *pfile ATTRIBUTE_UNUSED,
_cpp_file *f,
bool check_included)
{
struct pchf_compare_data d;
if (pchf == NULL
|| (! check_included && ! pchf->have_once_only))
return false;
d.size = f->st.st_size;
d.sum_computed = false;
d.f = f;
d.check_included = check_included;
return bsearch (&d, pchf->entries, pchf->count, sizeof (struct pchf_entry),
pchf_compare) != NULL;
}
| gpl-2.0 |
tpmullan/android_kernel_asus_tf700 | drivers/dma/iop-adma.c | 260 | 50354 | /*
* offload engine driver for the Intel Xscale series of i/o processors
* Copyright © 2006, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
* This driver supports the asynchrounous DMA copy and RAID engines available
* on the Intel Xscale(R) family of I/O Processors (IOP 32x, 33x, 134x)
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <linux/spinlock.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/memory.h>
#include <linux/ioport.h>
#include <linux/raid/pq.h>
#include <linux/slab.h>
#include <mach/adma.h>
#define to_iop_adma_chan(chan) container_of(chan, struct iop_adma_chan, common)
#define to_iop_adma_device(dev) \
container_of(dev, struct iop_adma_device, common)
#define tx_to_iop_adma_slot(tx) \
container_of(tx, struct iop_adma_desc_slot, async_tx)
/**
* iop_adma_free_slots - flags descriptor slots for reuse
* @slot: Slot to free
* Caller must hold &iop_chan->lock while calling this function
*/
static void iop_adma_free_slots(struct iop_adma_desc_slot *slot)
{
int stride = slot->slots_per_op;
while (stride--) {
slot->slots_per_op = 0;
slot = list_entry(slot->slot_node.next,
struct iop_adma_desc_slot,
slot_node);
}
}
static void
iop_desc_unmap(struct iop_adma_chan *iop_chan, struct iop_adma_desc_slot *desc)
{
struct dma_async_tx_descriptor *tx = &desc->async_tx;
struct iop_adma_desc_slot *unmap = desc->group_head;
struct device *dev = &iop_chan->device->pdev->dev;
u32 len = unmap->unmap_len;
enum dma_ctrl_flags flags = tx->flags;
u32 src_cnt;
dma_addr_t addr;
dma_addr_t dest;
src_cnt = unmap->unmap_src_cnt;
dest = iop_desc_get_dest_addr(unmap, iop_chan);
if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
enum dma_data_direction dir;
if (src_cnt > 1) /* is xor? */
dir = DMA_BIDIRECTIONAL;
else
dir = DMA_FROM_DEVICE;
dma_unmap_page(dev, dest, len, dir);
}
if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
while (src_cnt--) {
addr = iop_desc_get_src_addr(unmap, iop_chan, src_cnt);
if (addr == dest)
continue;
dma_unmap_page(dev, addr, len, DMA_TO_DEVICE);
}
}
desc->group_head = NULL;
}
static void
iop_desc_unmap_pq(struct iop_adma_chan *iop_chan, struct iop_adma_desc_slot *desc)
{
struct dma_async_tx_descriptor *tx = &desc->async_tx;
struct iop_adma_desc_slot *unmap = desc->group_head;
struct device *dev = &iop_chan->device->pdev->dev;
u32 len = unmap->unmap_len;
enum dma_ctrl_flags flags = tx->flags;
u32 src_cnt = unmap->unmap_src_cnt;
dma_addr_t pdest = iop_desc_get_dest_addr(unmap, iop_chan);
dma_addr_t qdest = iop_desc_get_qdest_addr(unmap, iop_chan);
int i;
if (tx->flags & DMA_PREP_CONTINUE)
src_cnt -= 3;
if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP) && !desc->pq_check_result) {
dma_unmap_page(dev, pdest, len, DMA_BIDIRECTIONAL);
dma_unmap_page(dev, qdest, len, DMA_BIDIRECTIONAL);
}
if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
dma_addr_t addr;
for (i = 0; i < src_cnt; i++) {
addr = iop_desc_get_src_addr(unmap, iop_chan, i);
dma_unmap_page(dev, addr, len, DMA_TO_DEVICE);
}
if (desc->pq_check_result) {
dma_unmap_page(dev, pdest, len, DMA_TO_DEVICE);
dma_unmap_page(dev, qdest, len, DMA_TO_DEVICE);
}
}
desc->group_head = NULL;
}
static dma_cookie_t
iop_adma_run_tx_complete_actions(struct iop_adma_desc_slot *desc,
struct iop_adma_chan *iop_chan, dma_cookie_t cookie)
{
struct dma_async_tx_descriptor *tx = &desc->async_tx;
BUG_ON(tx->cookie < 0);
if (tx->cookie > 0) {
cookie = tx->cookie;
tx->cookie = 0;
/* call the callback (must not sleep or submit new
* operations to this channel)
*/
if (tx->callback)
tx->callback(tx->callback_param);
/* unmap dma addresses
* (unmap_single vs unmap_page?)
*/
if (desc->group_head && desc->unmap_len) {
if (iop_desc_is_pq(desc))
iop_desc_unmap_pq(iop_chan, desc);
else
iop_desc_unmap(iop_chan, desc);
}
}
/* run dependent operations */
dma_run_dependencies(tx);
return cookie;
}
static int
iop_adma_clean_slot(struct iop_adma_desc_slot *desc,
struct iop_adma_chan *iop_chan)
{
/* the client is allowed to attach dependent operations
* until 'ack' is set
*/
if (!async_tx_test_ack(&desc->async_tx))
return 0;
/* leave the last descriptor in the chain
* so we can append to it
*/
if (desc->chain_node.next == &iop_chan->chain)
return 1;
dev_dbg(iop_chan->device->common.dev,
"\tfree slot: %d slots_per_op: %d\n",
desc->idx, desc->slots_per_op);
list_del(&desc->chain_node);
iop_adma_free_slots(desc);
return 0;
}
static void __iop_adma_slot_cleanup(struct iop_adma_chan *iop_chan)
{
struct iop_adma_desc_slot *iter, *_iter, *grp_start = NULL;
dma_cookie_t cookie = 0;
u32 current_desc = iop_chan_get_current_descriptor(iop_chan);
int busy = iop_chan_is_busy(iop_chan);
int seen_current = 0, slot_cnt = 0, slots_per_op = 0;
dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
/* free completed slots from the chain starting with
* the oldest descriptor
*/
list_for_each_entry_safe(iter, _iter, &iop_chan->chain,
chain_node) {
pr_debug("\tcookie: %d slot: %d busy: %d "
"this_desc: %#x next_desc: %#x ack: %d\n",
iter->async_tx.cookie, iter->idx, busy,
iter->async_tx.phys, iop_desc_get_next_desc(iter),
async_tx_test_ack(&iter->async_tx));
prefetch(_iter);
prefetch(&_iter->async_tx);
/* do not advance past the current descriptor loaded into the
* hardware channel, subsequent descriptors are either in
* process or have not been submitted
*/
if (seen_current)
break;
/* stop the search if we reach the current descriptor and the
* channel is busy, or if it appears that the current descriptor
* needs to be re-read (i.e. has been appended to)
*/
if (iter->async_tx.phys == current_desc) {
BUG_ON(seen_current++);
if (busy || iop_desc_get_next_desc(iter))
break;
}
/* detect the start of a group transaction */
if (!slot_cnt && !slots_per_op) {
slot_cnt = iter->slot_cnt;
slots_per_op = iter->slots_per_op;
if (slot_cnt <= slots_per_op) {
slot_cnt = 0;
slots_per_op = 0;
}
}
if (slot_cnt) {
pr_debug("\tgroup++\n");
if (!grp_start)
grp_start = iter;
slot_cnt -= slots_per_op;
}
/* all the members of a group are complete */
if (slots_per_op != 0 && slot_cnt == 0) {
struct iop_adma_desc_slot *grp_iter, *_grp_iter;
int end_of_chain = 0;
pr_debug("\tgroup end\n");
/* collect the total results */
if (grp_start->xor_check_result) {
u32 zero_sum_result = 0;
slot_cnt = grp_start->slot_cnt;
grp_iter = grp_start;
list_for_each_entry_from(grp_iter,
&iop_chan->chain, chain_node) {
zero_sum_result |=
iop_desc_get_zero_result(grp_iter);
pr_debug("\titer%d result: %d\n",
grp_iter->idx, zero_sum_result);
slot_cnt -= slots_per_op;
if (slot_cnt == 0)
break;
}
pr_debug("\tgrp_start->xor_check_result: %p\n",
grp_start->xor_check_result);
*grp_start->xor_check_result = zero_sum_result;
}
/* clean up the group */
slot_cnt = grp_start->slot_cnt;
grp_iter = grp_start;
list_for_each_entry_safe_from(grp_iter, _grp_iter,
&iop_chan->chain, chain_node) {
cookie = iop_adma_run_tx_complete_actions(
grp_iter, iop_chan, cookie);
slot_cnt -= slots_per_op;
end_of_chain = iop_adma_clean_slot(grp_iter,
iop_chan);
if (slot_cnt == 0 || end_of_chain)
break;
}
/* the group should be complete at this point */
BUG_ON(slot_cnt);
slots_per_op = 0;
grp_start = NULL;
if (end_of_chain)
break;
else
continue;
} else if (slots_per_op) /* wait for group completion */
continue;
/* write back zero sum results (single descriptor case) */
if (iter->xor_check_result && iter->async_tx.cookie)
*iter->xor_check_result =
iop_desc_get_zero_result(iter);
cookie = iop_adma_run_tx_complete_actions(
iter, iop_chan, cookie);
if (iop_adma_clean_slot(iter, iop_chan))
break;
}
if (cookie > 0) {
iop_chan->completed_cookie = cookie;
pr_debug("\tcompleted cookie %d\n", cookie);
}
}
static void
iop_adma_slot_cleanup(struct iop_adma_chan *iop_chan)
{
spin_lock_bh(&iop_chan->lock);
__iop_adma_slot_cleanup(iop_chan);
spin_unlock_bh(&iop_chan->lock);
}
static void iop_adma_tasklet(unsigned long data)
{
struct iop_adma_chan *iop_chan = (struct iop_adma_chan *) data;
/* lockdep will flag depedency submissions as potentially
* recursive locking, this is not the case as a dependency
* submission will never recurse a channels submit routine.
* There are checks in async_tx.c to prevent this.
*/
spin_lock_nested(&iop_chan->lock, SINGLE_DEPTH_NESTING);
__iop_adma_slot_cleanup(iop_chan);
spin_unlock(&iop_chan->lock);
}
static struct iop_adma_desc_slot *
iop_adma_alloc_slots(struct iop_adma_chan *iop_chan, int num_slots,
int slots_per_op)
{
struct iop_adma_desc_slot *iter, *_iter, *alloc_start = NULL;
LIST_HEAD(chain);
int slots_found, retry = 0;
/* start search from the last allocated descrtiptor
* if a contiguous allocation can not be found start searching
* from the beginning of the list
*/
retry:
slots_found = 0;
if (retry == 0)
iter = iop_chan->last_used;
else
iter = list_entry(&iop_chan->all_slots,
struct iop_adma_desc_slot,
slot_node);
list_for_each_entry_safe_continue(
iter, _iter, &iop_chan->all_slots, slot_node) {
prefetch(_iter);
prefetch(&_iter->async_tx);
if (iter->slots_per_op) {
/* give up after finding the first busy slot
* on the second pass through the list
*/
if (retry)
break;
slots_found = 0;
continue;
}
/* start the allocation if the slot is correctly aligned */
if (!slots_found++) {
if (iop_desc_is_aligned(iter, slots_per_op))
alloc_start = iter;
else {
slots_found = 0;
continue;
}
}
if (slots_found == num_slots) {
struct iop_adma_desc_slot *alloc_tail = NULL;
struct iop_adma_desc_slot *last_used = NULL;
iter = alloc_start;
while (num_slots) {
int i;
dev_dbg(iop_chan->device->common.dev,
"allocated slot: %d "
"(desc %p phys: %#x) slots_per_op %d\n",
iter->idx, iter->hw_desc,
iter->async_tx.phys, slots_per_op);
/* pre-ack all but the last descriptor */
if (num_slots != slots_per_op)
async_tx_ack(&iter->async_tx);
list_add_tail(&iter->chain_node, &chain);
alloc_tail = iter;
iter->async_tx.cookie = 0;
iter->slot_cnt = num_slots;
iter->xor_check_result = NULL;
for (i = 0; i < slots_per_op; i++) {
iter->slots_per_op = slots_per_op - i;
last_used = iter;
iter = list_entry(iter->slot_node.next,
struct iop_adma_desc_slot,
slot_node);
}
num_slots -= slots_per_op;
}
alloc_tail->group_head = alloc_start;
alloc_tail->async_tx.cookie = -EBUSY;
list_splice(&chain, &alloc_tail->tx_list);
iop_chan->last_used = last_used;
iop_desc_clear_next_desc(alloc_start);
iop_desc_clear_next_desc(alloc_tail);
return alloc_tail;
}
}
if (!retry++)
goto retry;
/* perform direct reclaim if the allocation fails */
__iop_adma_slot_cleanup(iop_chan);
return NULL;
}
static dma_cookie_t
iop_desc_assign_cookie(struct iop_adma_chan *iop_chan,
struct iop_adma_desc_slot *desc)
{
dma_cookie_t cookie = iop_chan->common.cookie;
cookie++;
if (cookie < 0)
cookie = 1;
iop_chan->common.cookie = desc->async_tx.cookie = cookie;
return cookie;
}
static void iop_adma_check_threshold(struct iop_adma_chan *iop_chan)
{
dev_dbg(iop_chan->device->common.dev, "pending: %d\n",
iop_chan->pending);
if (iop_chan->pending >= IOP_ADMA_THRESHOLD) {
iop_chan->pending = 0;
iop_chan_append(iop_chan);
}
}
static dma_cookie_t
iop_adma_tx_submit(struct dma_async_tx_descriptor *tx)
{
struct iop_adma_desc_slot *sw_desc = tx_to_iop_adma_slot(tx);
struct iop_adma_chan *iop_chan = to_iop_adma_chan(tx->chan);
struct iop_adma_desc_slot *grp_start, *old_chain_tail;
int slot_cnt;
int slots_per_op;
dma_cookie_t cookie;
dma_addr_t next_dma;
grp_start = sw_desc->group_head;
slot_cnt = grp_start->slot_cnt;
slots_per_op = grp_start->slots_per_op;
spin_lock_bh(&iop_chan->lock);
cookie = iop_desc_assign_cookie(iop_chan, sw_desc);
old_chain_tail = list_entry(iop_chan->chain.prev,
struct iop_adma_desc_slot, chain_node);
list_splice_init(&sw_desc->tx_list,
&old_chain_tail->chain_node);
/* fix up the hardware chain */
next_dma = grp_start->async_tx.phys;
iop_desc_set_next_desc(old_chain_tail, next_dma);
BUG_ON(iop_desc_get_next_desc(old_chain_tail) != next_dma); /* flush */
/* check for pre-chained descriptors */
iop_paranoia(iop_desc_get_next_desc(sw_desc));
/* increment the pending count by the number of slots
* memcpy operations have a 1:1 (slot:operation) relation
* other operations are heavier and will pop the threshold
* more often.
*/
iop_chan->pending += slot_cnt;
iop_adma_check_threshold(iop_chan);
spin_unlock_bh(&iop_chan->lock);
dev_dbg(iop_chan->device->common.dev, "%s cookie: %d slot: %d\n",
__func__, sw_desc->async_tx.cookie, sw_desc->idx);
return cookie;
}
static void iop_chan_start_null_memcpy(struct iop_adma_chan *iop_chan);
static void iop_chan_start_null_xor(struct iop_adma_chan *iop_chan);
/**
* iop_adma_alloc_chan_resources - returns the number of allocated descriptors
* @chan - allocate descriptor resources for this channel
* @client - current client requesting the channel be ready for requests
*
* Note: We keep the slots for 1 operation on iop_chan->chain at all times. To
* avoid deadlock, via async_xor, num_descs_in_pool must at a minimum be
* greater than 2x the number slots needed to satisfy a device->max_xor
* request.
* */
static int iop_adma_alloc_chan_resources(struct dma_chan *chan)
{
char *hw_desc;
int idx;
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
struct iop_adma_desc_slot *slot = NULL;
int init = iop_chan->slots_allocated ? 0 : 1;
struct iop_adma_platform_data *plat_data =
iop_chan->device->pdev->dev.platform_data;
int num_descs_in_pool = plat_data->pool_size/IOP_ADMA_SLOT_SIZE;
/* Allocate descriptor slots */
do {
idx = iop_chan->slots_allocated;
if (idx == num_descs_in_pool)
break;
slot = kzalloc(sizeof(*slot), GFP_KERNEL);
if (!slot) {
printk(KERN_INFO "IOP ADMA Channel only initialized"
" %d descriptor slots", idx);
break;
}
hw_desc = (char *) iop_chan->device->dma_desc_pool_virt;
slot->hw_desc = (void *) &hw_desc[idx * IOP_ADMA_SLOT_SIZE];
dma_async_tx_descriptor_init(&slot->async_tx, chan);
slot->async_tx.tx_submit = iop_adma_tx_submit;
INIT_LIST_HEAD(&slot->tx_list);
INIT_LIST_HEAD(&slot->chain_node);
INIT_LIST_HEAD(&slot->slot_node);
hw_desc = (char *) iop_chan->device->dma_desc_pool;
slot->async_tx.phys =
(dma_addr_t) &hw_desc[idx * IOP_ADMA_SLOT_SIZE];
slot->idx = idx;
spin_lock_bh(&iop_chan->lock);
iop_chan->slots_allocated++;
list_add_tail(&slot->slot_node, &iop_chan->all_slots);
spin_unlock_bh(&iop_chan->lock);
} while (iop_chan->slots_allocated < num_descs_in_pool);
if (idx && !iop_chan->last_used)
iop_chan->last_used = list_entry(iop_chan->all_slots.next,
struct iop_adma_desc_slot,
slot_node);
dev_dbg(iop_chan->device->common.dev,
"allocated %d descriptor slots last_used: %p\n",
iop_chan->slots_allocated, iop_chan->last_used);
/* initialize the channel and the chain with a null operation */
if (init) {
if (dma_has_cap(DMA_MEMCPY,
iop_chan->device->common.cap_mask))
iop_chan_start_null_memcpy(iop_chan);
else if (dma_has_cap(DMA_XOR,
iop_chan->device->common.cap_mask))
iop_chan_start_null_xor(iop_chan);
else
BUG();
}
return (idx > 0) ? idx : -ENOMEM;
}
static struct dma_async_tx_descriptor *
iop_adma_prep_dma_interrupt(struct dma_chan *chan, unsigned long flags)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
struct iop_adma_desc_slot *sw_desc, *grp_start;
int slot_cnt, slots_per_op;
dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
spin_lock_bh(&iop_chan->lock);
slot_cnt = iop_chan_interrupt_slot_count(&slots_per_op, iop_chan);
sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
if (sw_desc) {
grp_start = sw_desc->group_head;
iop_desc_init_interrupt(grp_start, iop_chan);
grp_start->unmap_len = 0;
sw_desc->async_tx.flags = flags;
}
spin_unlock_bh(&iop_chan->lock);
return sw_desc ? &sw_desc->async_tx : NULL;
}
static struct dma_async_tx_descriptor *
iop_adma_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dma_dest,
dma_addr_t dma_src, size_t len, unsigned long flags)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
struct iop_adma_desc_slot *sw_desc, *grp_start;
int slot_cnt, slots_per_op;
if (unlikely(!len))
return NULL;
BUG_ON(unlikely(len > IOP_ADMA_MAX_BYTE_COUNT));
dev_dbg(iop_chan->device->common.dev, "%s len: %u\n",
__func__, len);
spin_lock_bh(&iop_chan->lock);
slot_cnt = iop_chan_memcpy_slot_count(len, &slots_per_op);
sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
if (sw_desc) {
grp_start = sw_desc->group_head;
iop_desc_init_memcpy(grp_start, flags);
iop_desc_set_byte_count(grp_start, iop_chan, len);
iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
iop_desc_set_memcpy_src_addr(grp_start, dma_src);
sw_desc->unmap_src_cnt = 1;
sw_desc->unmap_len = len;
sw_desc->async_tx.flags = flags;
}
spin_unlock_bh(&iop_chan->lock);
return sw_desc ? &sw_desc->async_tx : NULL;
}
static struct dma_async_tx_descriptor *
iop_adma_prep_dma_memset(struct dma_chan *chan, dma_addr_t dma_dest,
int value, size_t len, unsigned long flags)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
struct iop_adma_desc_slot *sw_desc, *grp_start;
int slot_cnt, slots_per_op;
if (unlikely(!len))
return NULL;
BUG_ON(unlikely(len > IOP_ADMA_MAX_BYTE_COUNT));
dev_dbg(iop_chan->device->common.dev, "%s len: %u\n",
__func__, len);
spin_lock_bh(&iop_chan->lock);
slot_cnt = iop_chan_memset_slot_count(len, &slots_per_op);
sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
if (sw_desc) {
grp_start = sw_desc->group_head;
iop_desc_init_memset(grp_start, flags);
iop_desc_set_byte_count(grp_start, iop_chan, len);
iop_desc_set_block_fill_val(grp_start, value);
iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
sw_desc->unmap_src_cnt = 1;
sw_desc->unmap_len = len;
sw_desc->async_tx.flags = flags;
}
spin_unlock_bh(&iop_chan->lock);
return sw_desc ? &sw_desc->async_tx : NULL;
}
static struct dma_async_tx_descriptor *
iop_adma_prep_dma_xor(struct dma_chan *chan, dma_addr_t dma_dest,
dma_addr_t *dma_src, unsigned int src_cnt, size_t len,
unsigned long flags)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
struct iop_adma_desc_slot *sw_desc, *grp_start;
int slot_cnt, slots_per_op;
if (unlikely(!len))
return NULL;
BUG_ON(unlikely(len > IOP_ADMA_XOR_MAX_BYTE_COUNT));
dev_dbg(iop_chan->device->common.dev,
"%s src_cnt: %d len: %u flags: %lx\n",
__func__, src_cnt, len, flags);
spin_lock_bh(&iop_chan->lock);
slot_cnt = iop_chan_xor_slot_count(len, src_cnt, &slots_per_op);
sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
if (sw_desc) {
grp_start = sw_desc->group_head;
iop_desc_init_xor(grp_start, src_cnt, flags);
iop_desc_set_byte_count(grp_start, iop_chan, len);
iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
sw_desc->unmap_src_cnt = src_cnt;
sw_desc->unmap_len = len;
sw_desc->async_tx.flags = flags;
while (src_cnt--)
iop_desc_set_xor_src_addr(grp_start, src_cnt,
dma_src[src_cnt]);
}
spin_unlock_bh(&iop_chan->lock);
return sw_desc ? &sw_desc->async_tx : NULL;
}
static struct dma_async_tx_descriptor *
iop_adma_prep_dma_xor_val(struct dma_chan *chan, dma_addr_t *dma_src,
unsigned int src_cnt, size_t len, u32 *result,
unsigned long flags)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
struct iop_adma_desc_slot *sw_desc, *grp_start;
int slot_cnt, slots_per_op;
if (unlikely(!len))
return NULL;
dev_dbg(iop_chan->device->common.dev, "%s src_cnt: %d len: %u\n",
__func__, src_cnt, len);
spin_lock_bh(&iop_chan->lock);
slot_cnt = iop_chan_zero_sum_slot_count(len, src_cnt, &slots_per_op);
sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
if (sw_desc) {
grp_start = sw_desc->group_head;
iop_desc_init_zero_sum(grp_start, src_cnt, flags);
iop_desc_set_zero_sum_byte_count(grp_start, len);
grp_start->xor_check_result = result;
pr_debug("\t%s: grp_start->xor_check_result: %p\n",
__func__, grp_start->xor_check_result);
sw_desc->unmap_src_cnt = src_cnt;
sw_desc->unmap_len = len;
sw_desc->async_tx.flags = flags;
while (src_cnt--)
iop_desc_set_zero_sum_src_addr(grp_start, src_cnt,
dma_src[src_cnt]);
}
spin_unlock_bh(&iop_chan->lock);
return sw_desc ? &sw_desc->async_tx : NULL;
}
static struct dma_async_tx_descriptor *
iop_adma_prep_dma_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
unsigned int src_cnt, const unsigned char *scf, size_t len,
unsigned long flags)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
struct iop_adma_desc_slot *sw_desc, *g;
int slot_cnt, slots_per_op;
int continue_srcs;
if (unlikely(!len))
return NULL;
BUG_ON(len > IOP_ADMA_XOR_MAX_BYTE_COUNT);
dev_dbg(iop_chan->device->common.dev,
"%s src_cnt: %d len: %u flags: %lx\n",
__func__, src_cnt, len, flags);
if (dmaf_p_disabled_continue(flags))
continue_srcs = 1+src_cnt;
else if (dmaf_continue(flags))
continue_srcs = 3+src_cnt;
else
continue_srcs = 0+src_cnt;
spin_lock_bh(&iop_chan->lock);
slot_cnt = iop_chan_pq_slot_count(len, continue_srcs, &slots_per_op);
sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
if (sw_desc) {
int i;
g = sw_desc->group_head;
iop_desc_set_byte_count(g, iop_chan, len);
/* even if P is disabled its destination address (bits
* [3:0]) must match Q. It is ok if P points to an
* invalid address, it won't be written.
*/
if (flags & DMA_PREP_PQ_DISABLE_P)
dst[0] = dst[1] & 0x7;
iop_desc_set_pq_addr(g, dst);
sw_desc->unmap_src_cnt = src_cnt;
sw_desc->unmap_len = len;
sw_desc->async_tx.flags = flags;
for (i = 0; i < src_cnt; i++)
iop_desc_set_pq_src_addr(g, i, src[i], scf[i]);
/* if we are continuing a previous operation factor in
* the old p and q values, see the comment for dma_maxpq
* in include/linux/dmaengine.h
*/
if (dmaf_p_disabled_continue(flags))
iop_desc_set_pq_src_addr(g, i++, dst[1], 1);
else if (dmaf_continue(flags)) {
iop_desc_set_pq_src_addr(g, i++, dst[0], 0);
iop_desc_set_pq_src_addr(g, i++, dst[1], 1);
iop_desc_set_pq_src_addr(g, i++, dst[1], 0);
}
iop_desc_init_pq(g, i, flags);
}
spin_unlock_bh(&iop_chan->lock);
return sw_desc ? &sw_desc->async_tx : NULL;
}
static struct dma_async_tx_descriptor *
iop_adma_prep_dma_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
unsigned int src_cnt, const unsigned char *scf,
size_t len, enum sum_check_flags *pqres,
unsigned long flags)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
struct iop_adma_desc_slot *sw_desc, *g;
int slot_cnt, slots_per_op;
if (unlikely(!len))
return NULL;
BUG_ON(len > IOP_ADMA_XOR_MAX_BYTE_COUNT);
dev_dbg(iop_chan->device->common.dev, "%s src_cnt: %d len: %u\n",
__func__, src_cnt, len);
spin_lock_bh(&iop_chan->lock);
slot_cnt = iop_chan_pq_zero_sum_slot_count(len, src_cnt + 2, &slots_per_op);
sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
if (sw_desc) {
/* for validate operations p and q are tagged onto the
* end of the source list
*/
int pq_idx = src_cnt;
g = sw_desc->group_head;
iop_desc_init_pq_zero_sum(g, src_cnt+2, flags);
iop_desc_set_pq_zero_sum_byte_count(g, len);
g->pq_check_result = pqres;
pr_debug("\t%s: g->pq_check_result: %p\n",
__func__, g->pq_check_result);
sw_desc->unmap_src_cnt = src_cnt+2;
sw_desc->unmap_len = len;
sw_desc->async_tx.flags = flags;
while (src_cnt--)
iop_desc_set_pq_zero_sum_src_addr(g, src_cnt,
src[src_cnt],
scf[src_cnt]);
iop_desc_set_pq_zero_sum_addr(g, pq_idx, src);
}
spin_unlock_bh(&iop_chan->lock);
return sw_desc ? &sw_desc->async_tx : NULL;
}
static void iop_adma_free_chan_resources(struct dma_chan *chan)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
struct iop_adma_desc_slot *iter, *_iter;
int in_use_descs = 0;
iop_adma_slot_cleanup(iop_chan);
spin_lock_bh(&iop_chan->lock);
list_for_each_entry_safe(iter, _iter, &iop_chan->chain,
chain_node) {
in_use_descs++;
list_del(&iter->chain_node);
}
list_for_each_entry_safe_reverse(
iter, _iter, &iop_chan->all_slots, slot_node) {
list_del(&iter->slot_node);
kfree(iter);
iop_chan->slots_allocated--;
}
iop_chan->last_used = NULL;
dev_dbg(iop_chan->device->common.dev, "%s slots_allocated %d\n",
__func__, iop_chan->slots_allocated);
spin_unlock_bh(&iop_chan->lock);
/* one is ok since we left it on there on purpose */
if (in_use_descs > 1)
printk(KERN_ERR "IOP: Freeing %d in use descriptors!\n",
in_use_descs - 1);
}
/**
* iop_adma_status - poll the status of an ADMA transaction
* @chan: ADMA channel handle
* @cookie: ADMA transaction identifier
* @txstate: a holder for the current state of the channel or NULL
*/
static enum dma_status iop_adma_status(struct dma_chan *chan,
dma_cookie_t cookie,
struct dma_tx_state *txstate)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
dma_cookie_t last_used;
dma_cookie_t last_complete;
enum dma_status ret;
last_used = chan->cookie;
last_complete = iop_chan->completed_cookie;
dma_set_tx_state(txstate, last_complete, last_used, 0);
ret = dma_async_is_complete(cookie, last_complete, last_used);
if (ret == DMA_SUCCESS)
return ret;
iop_adma_slot_cleanup(iop_chan);
last_used = chan->cookie;
last_complete = iop_chan->completed_cookie;
dma_set_tx_state(txstate, last_complete, last_used, 0);
return dma_async_is_complete(cookie, last_complete, last_used);
}
static irqreturn_t iop_adma_eot_handler(int irq, void *data)
{
struct iop_adma_chan *chan = data;
dev_dbg(chan->device->common.dev, "%s\n", __func__);
tasklet_schedule(&chan->irq_tasklet);
iop_adma_device_clear_eot_status(chan);
return IRQ_HANDLED;
}
static irqreturn_t iop_adma_eoc_handler(int irq, void *data)
{
struct iop_adma_chan *chan = data;
dev_dbg(chan->device->common.dev, "%s\n", __func__);
tasklet_schedule(&chan->irq_tasklet);
iop_adma_device_clear_eoc_status(chan);
return IRQ_HANDLED;
}
static irqreturn_t iop_adma_err_handler(int irq, void *data)
{
struct iop_adma_chan *chan = data;
unsigned long status = iop_chan_get_status(chan);
dev_printk(KERN_ERR, chan->device->common.dev,
"error ( %s%s%s%s%s%s%s)\n",
iop_is_err_int_parity(status, chan) ? "int_parity " : "",
iop_is_err_mcu_abort(status, chan) ? "mcu_abort " : "",
iop_is_err_int_tabort(status, chan) ? "int_tabort " : "",
iop_is_err_int_mabort(status, chan) ? "int_mabort " : "",
iop_is_err_pci_tabort(status, chan) ? "pci_tabort " : "",
iop_is_err_pci_mabort(status, chan) ? "pci_mabort " : "",
iop_is_err_split_tx(status, chan) ? "split_tx " : "");
iop_adma_device_clear_err_status(chan);
BUG();
return IRQ_HANDLED;
}
static void iop_adma_issue_pending(struct dma_chan *chan)
{
struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
if (iop_chan->pending) {
iop_chan->pending = 0;
iop_chan_append(iop_chan);
}
}
/*
* Perform a transaction to verify the HW works.
*/
#define IOP_ADMA_TEST_SIZE 2000
static int __devinit iop_adma_memcpy_self_test(struct iop_adma_device *device)
{
int i;
void *src, *dest;
dma_addr_t src_dma, dest_dma;
struct dma_chan *dma_chan;
dma_cookie_t cookie;
struct dma_async_tx_descriptor *tx;
int err = 0;
struct iop_adma_chan *iop_chan;
dev_dbg(device->common.dev, "%s\n", __func__);
src = kmalloc(IOP_ADMA_TEST_SIZE, GFP_KERNEL);
if (!src)
return -ENOMEM;
dest = kzalloc(IOP_ADMA_TEST_SIZE, GFP_KERNEL);
if (!dest) {
kfree(src);
return -ENOMEM;
}
/* Fill in src buffer */
for (i = 0; i < IOP_ADMA_TEST_SIZE; i++)
((u8 *) src)[i] = (u8)i;
/* Start copy, using first DMA channel */
dma_chan = container_of(device->common.channels.next,
struct dma_chan,
device_node);
if (iop_adma_alloc_chan_resources(dma_chan) < 1) {
err = -ENODEV;
goto out;
}
dest_dma = dma_map_single(dma_chan->device->dev, dest,
IOP_ADMA_TEST_SIZE, DMA_FROM_DEVICE);
src_dma = dma_map_single(dma_chan->device->dev, src,
IOP_ADMA_TEST_SIZE, DMA_TO_DEVICE);
tx = iop_adma_prep_dma_memcpy(dma_chan, dest_dma, src_dma,
IOP_ADMA_TEST_SIZE,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
cookie = iop_adma_tx_submit(tx);
iop_adma_issue_pending(dma_chan);
msleep(1);
if (iop_adma_status(dma_chan, cookie, NULL) !=
DMA_SUCCESS) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test copy timed out, disabling\n");
err = -ENODEV;
goto free_resources;
}
iop_chan = to_iop_adma_chan(dma_chan);
dma_sync_single_for_cpu(&iop_chan->device->pdev->dev, dest_dma,
IOP_ADMA_TEST_SIZE, DMA_FROM_DEVICE);
if (memcmp(src, dest, IOP_ADMA_TEST_SIZE)) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test copy failed compare, disabling\n");
err = -ENODEV;
goto free_resources;
}
free_resources:
iop_adma_free_chan_resources(dma_chan);
out:
kfree(src);
kfree(dest);
return err;
}
#define IOP_ADMA_NUM_SRC_TEST 4 /* must be <= 15 */
static int __devinit
iop_adma_xor_val_self_test(struct iop_adma_device *device)
{
int i, src_idx;
struct page *dest;
struct page *xor_srcs[IOP_ADMA_NUM_SRC_TEST];
struct page *zero_sum_srcs[IOP_ADMA_NUM_SRC_TEST + 1];
dma_addr_t dma_srcs[IOP_ADMA_NUM_SRC_TEST + 1];
dma_addr_t dma_addr, dest_dma;
struct dma_async_tx_descriptor *tx;
struct dma_chan *dma_chan;
dma_cookie_t cookie;
u8 cmp_byte = 0;
u32 cmp_word;
u32 zero_sum_result;
int err = 0;
struct iop_adma_chan *iop_chan;
dev_dbg(device->common.dev, "%s\n", __func__);
for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++) {
xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
if (!xor_srcs[src_idx]) {
while (src_idx--)
__free_page(xor_srcs[src_idx]);
return -ENOMEM;
}
}
dest = alloc_page(GFP_KERNEL);
if (!dest) {
while (src_idx--)
__free_page(xor_srcs[src_idx]);
return -ENOMEM;
}
/* Fill in src buffers */
for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++) {
u8 *ptr = page_address(xor_srcs[src_idx]);
for (i = 0; i < PAGE_SIZE; i++)
ptr[i] = (1 << src_idx);
}
for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++)
cmp_byte ^= (u8) (1 << src_idx);
cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
(cmp_byte << 8) | cmp_byte;
memset(page_address(dest), 0, PAGE_SIZE);
dma_chan = container_of(device->common.channels.next,
struct dma_chan,
device_node);
if (iop_adma_alloc_chan_resources(dma_chan) < 1) {
err = -ENODEV;
goto out;
}
/* test xor */
dest_dma = dma_map_page(dma_chan->device->dev, dest, 0,
PAGE_SIZE, DMA_FROM_DEVICE);
for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
dma_srcs[i] = dma_map_page(dma_chan->device->dev, xor_srcs[i],
0, PAGE_SIZE, DMA_TO_DEVICE);
tx = iop_adma_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
IOP_ADMA_NUM_SRC_TEST, PAGE_SIZE,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
cookie = iop_adma_tx_submit(tx);
iop_adma_issue_pending(dma_chan);
msleep(8);
if (iop_adma_status(dma_chan, cookie, NULL) !=
DMA_SUCCESS) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test xor timed out, disabling\n");
err = -ENODEV;
goto free_resources;
}
iop_chan = to_iop_adma_chan(dma_chan);
dma_sync_single_for_cpu(&iop_chan->device->pdev->dev, dest_dma,
PAGE_SIZE, DMA_FROM_DEVICE);
for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
u32 *ptr = page_address(dest);
if (ptr[i] != cmp_word) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test xor failed compare, disabling\n");
err = -ENODEV;
goto free_resources;
}
}
dma_sync_single_for_device(&iop_chan->device->pdev->dev, dest_dma,
PAGE_SIZE, DMA_TO_DEVICE);
/* skip zero sum if the capability is not present */
if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask))
goto free_resources;
/* zero sum the sources with the destintation page */
for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
zero_sum_srcs[i] = xor_srcs[i];
zero_sum_srcs[i] = dest;
zero_sum_result = 1;
for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++)
dma_srcs[i] = dma_map_page(dma_chan->device->dev,
zero_sum_srcs[i], 0, PAGE_SIZE,
DMA_TO_DEVICE);
tx = iop_adma_prep_dma_xor_val(dma_chan, dma_srcs,
IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE,
&zero_sum_result,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
cookie = iop_adma_tx_submit(tx);
iop_adma_issue_pending(dma_chan);
msleep(8);
if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test zero sum timed out, disabling\n");
err = -ENODEV;
goto free_resources;
}
if (zero_sum_result != 0) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test zero sum failed compare, disabling\n");
err = -ENODEV;
goto free_resources;
}
/* test memset */
dma_addr = dma_map_page(dma_chan->device->dev, dest, 0,
PAGE_SIZE, DMA_FROM_DEVICE);
tx = iop_adma_prep_dma_memset(dma_chan, dma_addr, 0, PAGE_SIZE,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
cookie = iop_adma_tx_submit(tx);
iop_adma_issue_pending(dma_chan);
msleep(8);
if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test memset timed out, disabling\n");
err = -ENODEV;
goto free_resources;
}
for (i = 0; i < PAGE_SIZE/sizeof(u32); i++) {
u32 *ptr = page_address(dest);
if (ptr[i]) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test memset failed compare, disabling\n");
err = -ENODEV;
goto free_resources;
}
}
/* test for non-zero parity sum */
zero_sum_result = 0;
for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++)
dma_srcs[i] = dma_map_page(dma_chan->device->dev,
zero_sum_srcs[i], 0, PAGE_SIZE,
DMA_TO_DEVICE);
tx = iop_adma_prep_dma_xor_val(dma_chan, dma_srcs,
IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE,
&zero_sum_result,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
cookie = iop_adma_tx_submit(tx);
iop_adma_issue_pending(dma_chan);
msleep(8);
if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test non-zero sum timed out, disabling\n");
err = -ENODEV;
goto free_resources;
}
if (zero_sum_result != 1) {
dev_printk(KERN_ERR, dma_chan->device->dev,
"Self-test non-zero sum failed compare, disabling\n");
err = -ENODEV;
goto free_resources;
}
free_resources:
iop_adma_free_chan_resources(dma_chan);
out:
src_idx = IOP_ADMA_NUM_SRC_TEST;
while (src_idx--)
__free_page(xor_srcs[src_idx]);
__free_page(dest);
return err;
}
#ifdef CONFIG_RAID6_PQ
static int __devinit
iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device)
{
/* combined sources, software pq results, and extra hw pq results */
struct page *pq[IOP_ADMA_NUM_SRC_TEST+2+2];
/* ptr to the extra hw pq buffers defined above */
struct page **pq_hw = &pq[IOP_ADMA_NUM_SRC_TEST+2];
/* address conversion buffers (dma_map / page_address) */
void *pq_sw[IOP_ADMA_NUM_SRC_TEST+2];
dma_addr_t pq_src[IOP_ADMA_NUM_SRC_TEST];
dma_addr_t pq_dest[2];
int i;
struct dma_async_tx_descriptor *tx;
struct dma_chan *dma_chan;
dma_cookie_t cookie;
u32 zero_sum_result;
int err = 0;
struct device *dev;
dev_dbg(device->common.dev, "%s\n", __func__);
for (i = 0; i < ARRAY_SIZE(pq); i++) {
pq[i] = alloc_page(GFP_KERNEL);
if (!pq[i]) {
while (i--)
__free_page(pq[i]);
return -ENOMEM;
}
}
/* Fill in src buffers */
for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++) {
pq_sw[i] = page_address(pq[i]);
memset(pq_sw[i], 0x11111111 * (1<<i), PAGE_SIZE);
}
pq_sw[i] = page_address(pq[i]);
pq_sw[i+1] = page_address(pq[i+1]);
dma_chan = container_of(device->common.channels.next,
struct dma_chan,
device_node);
if (iop_adma_alloc_chan_resources(dma_chan) < 1) {
err = -ENODEV;
goto out;
}
dev = dma_chan->device->dev;
/* initialize the dests */
memset(page_address(pq_hw[0]), 0 , PAGE_SIZE);
memset(page_address(pq_hw[1]), 0 , PAGE_SIZE);
/* test pq */
pq_dest[0] = dma_map_page(dev, pq_hw[0], 0, PAGE_SIZE, DMA_FROM_DEVICE);
pq_dest[1] = dma_map_page(dev, pq_hw[1], 0, PAGE_SIZE, DMA_FROM_DEVICE);
for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE,
DMA_TO_DEVICE);
tx = iop_adma_prep_dma_pq(dma_chan, pq_dest, pq_src,
IOP_ADMA_NUM_SRC_TEST, (u8 *)raid6_gfexp,
PAGE_SIZE,
DMA_PREP_INTERRUPT |
DMA_CTRL_ACK);
cookie = iop_adma_tx_submit(tx);
iop_adma_issue_pending(dma_chan);
msleep(8);
if (iop_adma_status(dma_chan, cookie, NULL) !=
DMA_SUCCESS) {
dev_err(dev, "Self-test pq timed out, disabling\n");
err = -ENODEV;
goto free_resources;
}
raid6_call.gen_syndrome(IOP_ADMA_NUM_SRC_TEST+2, PAGE_SIZE, pq_sw);
if (memcmp(pq_sw[IOP_ADMA_NUM_SRC_TEST],
page_address(pq_hw[0]), PAGE_SIZE) != 0) {
dev_err(dev, "Self-test p failed compare, disabling\n");
err = -ENODEV;
goto free_resources;
}
if (memcmp(pq_sw[IOP_ADMA_NUM_SRC_TEST+1],
page_address(pq_hw[1]), PAGE_SIZE) != 0) {
dev_err(dev, "Self-test q failed compare, disabling\n");
err = -ENODEV;
goto free_resources;
}
/* test correct zero sum using the software generated pq values */
for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 2; i++)
pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE,
DMA_TO_DEVICE);
zero_sum_result = ~0;
tx = iop_adma_prep_dma_pq_val(dma_chan, &pq_src[IOP_ADMA_NUM_SRC_TEST],
pq_src, IOP_ADMA_NUM_SRC_TEST,
raid6_gfexp, PAGE_SIZE, &zero_sum_result,
DMA_PREP_INTERRUPT|DMA_CTRL_ACK);
cookie = iop_adma_tx_submit(tx);
iop_adma_issue_pending(dma_chan);
msleep(8);
if (iop_adma_status(dma_chan, cookie, NULL) !=
DMA_SUCCESS) {
dev_err(dev, "Self-test pq-zero-sum timed out, disabling\n");
err = -ENODEV;
goto free_resources;
}
if (zero_sum_result != 0) {
dev_err(dev, "Self-test pq-zero-sum failed to validate: %x\n",
zero_sum_result);
err = -ENODEV;
goto free_resources;
}
/* test incorrect zero sum */
i = IOP_ADMA_NUM_SRC_TEST;
memset(pq_sw[i] + 100, 0, 100);
memset(pq_sw[i+1] + 200, 0, 200);
for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 2; i++)
pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE,
DMA_TO_DEVICE);
zero_sum_result = 0;
tx = iop_adma_prep_dma_pq_val(dma_chan, &pq_src[IOP_ADMA_NUM_SRC_TEST],
pq_src, IOP_ADMA_NUM_SRC_TEST,
raid6_gfexp, PAGE_SIZE, &zero_sum_result,
DMA_PREP_INTERRUPT|DMA_CTRL_ACK);
cookie = iop_adma_tx_submit(tx);
iop_adma_issue_pending(dma_chan);
msleep(8);
if (iop_adma_status(dma_chan, cookie, NULL) !=
DMA_SUCCESS) {
dev_err(dev, "Self-test !pq-zero-sum timed out, disabling\n");
err = -ENODEV;
goto free_resources;
}
if (zero_sum_result != (SUM_CHECK_P_RESULT | SUM_CHECK_Q_RESULT)) {
dev_err(dev, "Self-test !pq-zero-sum failed to validate: %x\n",
zero_sum_result);
err = -ENODEV;
goto free_resources;
}
free_resources:
iop_adma_free_chan_resources(dma_chan);
out:
i = ARRAY_SIZE(pq);
while (i--)
__free_page(pq[i]);
return err;
}
#endif
static int __devexit iop_adma_remove(struct platform_device *dev)
{
struct iop_adma_device *device = platform_get_drvdata(dev);
struct dma_chan *chan, *_chan;
struct iop_adma_chan *iop_chan;
struct iop_adma_platform_data *plat_data = dev->dev.platform_data;
dma_async_device_unregister(&device->common);
dma_free_coherent(&dev->dev, plat_data->pool_size,
device->dma_desc_pool_virt, device->dma_desc_pool);
list_for_each_entry_safe(chan, _chan, &device->common.channels,
device_node) {
iop_chan = to_iop_adma_chan(chan);
list_del(&chan->device_node);
kfree(iop_chan);
}
kfree(device);
return 0;
}
static int __devinit iop_adma_probe(struct platform_device *pdev)
{
struct resource *res;
int ret = 0, i;
struct iop_adma_device *adev;
struct iop_adma_chan *iop_chan;
struct dma_device *dma_dev;
struct iop_adma_platform_data *plat_data = pdev->dev.platform_data;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
if (!devm_request_mem_region(&pdev->dev, res->start,
resource_size(res), pdev->name))
return -EBUSY;
adev = kzalloc(sizeof(*adev), GFP_KERNEL);
if (!adev)
return -ENOMEM;
dma_dev = &adev->common;
/* allocate coherent memory for hardware descriptors
* note: writecombine gives slightly better performance, but
* requires that we explicitly flush the writes
*/
if ((adev->dma_desc_pool_virt = dma_alloc_writecombine(&pdev->dev,
plat_data->pool_size,
&adev->dma_desc_pool,
GFP_KERNEL)) == NULL) {
ret = -ENOMEM;
goto err_free_adev;
}
dev_dbg(&pdev->dev, "%s: allocted descriptor pool virt %p phys %p\n",
__func__, adev->dma_desc_pool_virt,
(void *) adev->dma_desc_pool);
adev->id = plat_data->hw_id;
/* discover transaction capabilites from the platform data */
dma_dev->cap_mask = plat_data->cap_mask;
adev->pdev = pdev;
platform_set_drvdata(pdev, adev);
INIT_LIST_HEAD(&dma_dev->channels);
/* set base routines */
dma_dev->device_alloc_chan_resources = iop_adma_alloc_chan_resources;
dma_dev->device_free_chan_resources = iop_adma_free_chan_resources;
dma_dev->device_tx_status = iop_adma_status;
dma_dev->device_issue_pending = iop_adma_issue_pending;
dma_dev->dev = &pdev->dev;
/* set prep routines based on capability */
if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask))
dma_dev->device_prep_dma_memcpy = iop_adma_prep_dma_memcpy;
if (dma_has_cap(DMA_MEMSET, dma_dev->cap_mask))
dma_dev->device_prep_dma_memset = iop_adma_prep_dma_memset;
if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
dma_dev->max_xor = iop_adma_get_max_xor();
dma_dev->device_prep_dma_xor = iop_adma_prep_dma_xor;
}
if (dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask))
dma_dev->device_prep_dma_xor_val =
iop_adma_prep_dma_xor_val;
if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
dma_set_maxpq(dma_dev, iop_adma_get_max_pq(), 0);
dma_dev->device_prep_dma_pq = iop_adma_prep_dma_pq;
}
if (dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask))
dma_dev->device_prep_dma_pq_val =
iop_adma_prep_dma_pq_val;
if (dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask))
dma_dev->device_prep_dma_interrupt =
iop_adma_prep_dma_interrupt;
iop_chan = kzalloc(sizeof(*iop_chan), GFP_KERNEL);
if (!iop_chan) {
ret = -ENOMEM;
goto err_free_dma;
}
iop_chan->device = adev;
iop_chan->mmr_base = devm_ioremap(&pdev->dev, res->start,
resource_size(res));
if (!iop_chan->mmr_base) {
ret = -ENOMEM;
goto err_free_iop_chan;
}
tasklet_init(&iop_chan->irq_tasklet, iop_adma_tasklet, (unsigned long)
iop_chan);
/* clear errors before enabling interrupts */
iop_adma_device_clear_err_status(iop_chan);
for (i = 0; i < 3; i++) {
irq_handler_t handler[] = { iop_adma_eot_handler,
iop_adma_eoc_handler,
iop_adma_err_handler };
int irq = platform_get_irq(pdev, i);
if (irq < 0) {
ret = -ENXIO;
goto err_free_iop_chan;
} else {
ret = devm_request_irq(&pdev->dev, irq,
handler[i], 0, pdev->name, iop_chan);
if (ret)
goto err_free_iop_chan;
}
}
spin_lock_init(&iop_chan->lock);
INIT_LIST_HEAD(&iop_chan->chain);
INIT_LIST_HEAD(&iop_chan->all_slots);
iop_chan->common.device = dma_dev;
list_add_tail(&iop_chan->common.device_node, &dma_dev->channels);
if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
ret = iop_adma_memcpy_self_test(adev);
dev_dbg(&pdev->dev, "memcpy self test returned %d\n", ret);
if (ret)
goto err_free_iop_chan;
}
if (dma_has_cap(DMA_XOR, dma_dev->cap_mask) ||
dma_has_cap(DMA_MEMSET, dma_dev->cap_mask)) {
ret = iop_adma_xor_val_self_test(adev);
dev_dbg(&pdev->dev, "xor self test returned %d\n", ret);
if (ret)
goto err_free_iop_chan;
}
if (dma_has_cap(DMA_PQ, dma_dev->cap_mask) &&
dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask)) {
#ifdef CONFIG_RAID6_PQ
ret = iop_adma_pq_zero_sum_self_test(adev);
dev_dbg(&pdev->dev, "pq self test returned %d\n", ret);
#else
/* can not test raid6, so do not publish capability */
dma_cap_clear(DMA_PQ, dma_dev->cap_mask);
dma_cap_clear(DMA_PQ_VAL, dma_dev->cap_mask);
ret = 0;
#endif
if (ret)
goto err_free_iop_chan;
}
dev_printk(KERN_INFO, &pdev->dev, "Intel(R) IOP: "
"( %s%s%s%s%s%s%s)\n",
dma_has_cap(DMA_PQ, dma_dev->cap_mask) ? "pq " : "",
dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask) ? "pq_val " : "",
dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "",
dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask) ? "xor_val " : "",
dma_has_cap(DMA_MEMSET, dma_dev->cap_mask) ? "fill " : "",
dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "",
dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : "");
dma_async_device_register(dma_dev);
goto out;
err_free_iop_chan:
kfree(iop_chan);
err_free_dma:
dma_free_coherent(&adev->pdev->dev, plat_data->pool_size,
adev->dma_desc_pool_virt, adev->dma_desc_pool);
err_free_adev:
kfree(adev);
out:
return ret;
}
static void iop_chan_start_null_memcpy(struct iop_adma_chan *iop_chan)
{
struct iop_adma_desc_slot *sw_desc, *grp_start;
dma_cookie_t cookie;
int slot_cnt, slots_per_op;
dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
spin_lock_bh(&iop_chan->lock);
slot_cnt = iop_chan_memcpy_slot_count(0, &slots_per_op);
sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
if (sw_desc) {
grp_start = sw_desc->group_head;
list_splice_init(&sw_desc->tx_list, &iop_chan->chain);
async_tx_ack(&sw_desc->async_tx);
iop_desc_init_memcpy(grp_start, 0);
iop_desc_set_byte_count(grp_start, iop_chan, 0);
iop_desc_set_dest_addr(grp_start, iop_chan, 0);
iop_desc_set_memcpy_src_addr(grp_start, 0);
cookie = iop_chan->common.cookie;
cookie++;
if (cookie <= 1)
cookie = 2;
/* initialize the completed cookie to be less than
* the most recently used cookie
*/
iop_chan->completed_cookie = cookie - 1;
iop_chan->common.cookie = sw_desc->async_tx.cookie = cookie;
/* channel should not be busy */
BUG_ON(iop_chan_is_busy(iop_chan));
/* clear any prior error-status bits */
iop_adma_device_clear_err_status(iop_chan);
/* disable operation */
iop_chan_disable(iop_chan);
/* set the descriptor address */
iop_chan_set_next_descriptor(iop_chan, sw_desc->async_tx.phys);
/* 1/ don't add pre-chained descriptors
* 2/ dummy read to flush next_desc write
*/
BUG_ON(iop_desc_get_next_desc(sw_desc));
/* run the descriptor */
iop_chan_enable(iop_chan);
} else
dev_printk(KERN_ERR, iop_chan->device->common.dev,
"failed to allocate null descriptor\n");
spin_unlock_bh(&iop_chan->lock);
}
static void iop_chan_start_null_xor(struct iop_adma_chan *iop_chan)
{
struct iop_adma_desc_slot *sw_desc, *grp_start;
dma_cookie_t cookie;
int slot_cnt, slots_per_op;
dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
spin_lock_bh(&iop_chan->lock);
slot_cnt = iop_chan_xor_slot_count(0, 2, &slots_per_op);
sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
if (sw_desc) {
grp_start = sw_desc->group_head;
list_splice_init(&sw_desc->tx_list, &iop_chan->chain);
async_tx_ack(&sw_desc->async_tx);
iop_desc_init_null_xor(grp_start, 2, 0);
iop_desc_set_byte_count(grp_start, iop_chan, 0);
iop_desc_set_dest_addr(grp_start, iop_chan, 0);
iop_desc_set_xor_src_addr(grp_start, 0, 0);
iop_desc_set_xor_src_addr(grp_start, 1, 0);
cookie = iop_chan->common.cookie;
cookie++;
if (cookie <= 1)
cookie = 2;
/* initialize the completed cookie to be less than
* the most recently used cookie
*/
iop_chan->completed_cookie = cookie - 1;
iop_chan->common.cookie = sw_desc->async_tx.cookie = cookie;
/* channel should not be busy */
BUG_ON(iop_chan_is_busy(iop_chan));
/* clear any prior error-status bits */
iop_adma_device_clear_err_status(iop_chan);
/* disable operation */
iop_chan_disable(iop_chan);
/* set the descriptor address */
iop_chan_set_next_descriptor(iop_chan, sw_desc->async_tx.phys);
/* 1/ don't add pre-chained descriptors
* 2/ dummy read to flush next_desc write
*/
BUG_ON(iop_desc_get_next_desc(sw_desc));
/* run the descriptor */
iop_chan_enable(iop_chan);
} else
dev_printk(KERN_ERR, iop_chan->device->common.dev,
"failed to allocate null descriptor\n");
spin_unlock_bh(&iop_chan->lock);
}
MODULE_ALIAS("platform:iop-adma");
static struct platform_driver iop_adma_driver = {
.probe = iop_adma_probe,
.remove = __devexit_p(iop_adma_remove),
.driver = {
.owner = THIS_MODULE,
.name = "iop-adma",
},
};
static int __init iop_adma_init (void)
{
return platform_driver_register(&iop_adma_driver);
}
static void __exit iop_adma_exit (void)
{
platform_driver_unregister(&iop_adma_driver);
return;
}
module_exit(iop_adma_exit);
module_init(iop_adma_init);
MODULE_AUTHOR("Intel Corporation");
MODULE_DESCRIPTION("IOP ADMA Engine Driver");
MODULE_LICENSE("GPL");
| gpl-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.