code stringlengths 3 1.01M | repo_name stringlengths 5 116 | path stringlengths 3 311 | language stringclasses 30
values | license stringclasses 15
values | size int64 3 1.01M |
|---|---|---|---|---|---|
package butterknife;
import android.view.View;
import butterknife.internal.ListenerClass;
import butterknife.internal.ListenerMethod;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static android.widget.AdapterView.OnItemSelectedListener;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.CLASS;
/**
* Bind a method to an {@link OnItemSelectedListener OnItemSelectedListener} on the view for each
* ID specified.
* <pre><code>
* {@literal @}OnItemSelected(R.id.example_list) void onItemSelected(int position) {
* Toast.makeText(this, "Selected position " + position + "!", Toast.LENGTH_SHORT).show();
* }
* </code></pre>
* Any number of parameters from
* {@link OnItemSelectedListener#onItemSelected(android.widget.AdapterView, android.view.View, int,
* long) onItemSelected} may be used on the method.
* <p>
* To bind to methods other than {@code onItemSelected}, specify a different {@code callback}.
* <pre><code>
* {@literal @}OnItemSelected(value = R.id.example_list, callback = NOTHING_SELECTED)
* void onNothingSelected() {
* Toast.makeText(this, "Nothing selected!", Toast.LENGTH_SHORT).show();
* }
* </code></pre>
*
* @see OnItemSelectedListener
*/
@Target(METHOD)
@Retention(CLASS)
@ListenerClass(
targetType = "android.widget.AdapterView<?>",
setter = "setOnItemSelectedListener",
type = "android.widget.AdapterView.OnItemSelectedListener",
callbacks = OnItemSelected.Callback.class
)
public @interface OnItemSelected {
/** View IDs to which the method will be bound. */
int[] value() default { View.NO_ID };
/** Listener callback to which the method will be bound. */
Callback callback() default Callback.ITEM_SELECTED;
/** {@link OnItemSelectedListener} callback methods. */
enum Callback {
/**
* {@link OnItemSelectedListener#onItemSelected(android.widget.AdapterView, android.view.View,
* int, long)}
*/
@ListenerMethod(
name = "onItemSelected",
parameters = {
"android.widget.AdapterView<?>",
"android.view.View",
"int",
"long"
}
)
ITEM_SELECTED,
/** {@link OnItemSelectedListener#onNothingSelected(android.widget.AdapterView)} */
@ListenerMethod(
name = "onNothingSelected",
parameters = "android.widget.AdapterView<?>"
)
NOTHING_SELECTED
}
}
| carollynn2253/butterknife | butterknife/src/main/java/butterknife/OnItemSelected.java | Java | apache-2.0 | 2,447 |
/**
******************************************************************************
* @file misc.c
* @author MCD Application Team
* @version V3.5.0
* @date 11-March-2011
* @brief This file provides all the miscellaneous firmware functions (add-on
* to CMSIS functions).
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "misc.h"
/** @addtogroup STM32F10x_StdPeriph_Driver
* @{
*/
/** @defgroup MISC
* @brief MISC driver modules
* @{
*/
/** @defgroup MISC_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup MISC_Private_Defines
* @{
*/
#define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
/**
* @}
*/
/** @defgroup MISC_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup MISC_Private_Variables
* @{
*/
/**
* @}
*/
/** @defgroup MISC_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup MISC_Private_Functions
* @{
*/
/**
* @brief Configures the priority grouping: pre-emption priority and subpriority.
* @param NVIC_PriorityGroup: specifies the priority grouping bits length.
* This parameter can be one of the following values:
* @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
* 4 bits for subpriority
* @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
* 3 bits for subpriority
* @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
* 2 bits for subpriority
* @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
* 1 bits for subpriority
* @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
* 0 bits for subpriority
* @retval None
*/
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
{
/* Check the parameters */
assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
/* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
}
/**
* @brief Initializes the NVIC peripheral according to the specified
* parameters in the NVIC_InitStruct.
* @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
* the configuration information for the specified NVIC peripheral.
* @retval None
*/
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
{
uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
{
/* Compute the Corresponding IRQ Priority --------------------------------*/
tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
tmppre = (0x4 - tmppriority);
tmpsub = tmpsub >> tmppriority;
tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
tmppriority = tmppriority << 0x04;
// [ILG]
#if defined ( __GNUC__ )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
// [ILG]
#if defined ( __GNUC__ )
#pragma GCC diagnostic pop
#endif
/* Enable the Selected IRQ Channels --------------------------------------*/
NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
(uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
}
else
{
/* Disable the Selected IRQ Channels -------------------------------------*/
NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
(uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
}
}
/**
* @brief Sets the vector table location and Offset.
* @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
* This parameter can be one of the following values:
* @arg NVIC_VectTab_RAM
* @arg NVIC_VectTab_FLASH
* @param Offset: Vector Table base offset field. This value must be a multiple
* of 0x200.
* @retval None
*/
void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
{
/* Check the parameters */
assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
assert_param(IS_NVIC_OFFSET(Offset));
SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
}
/**
* @brief Selects the condition for the system to enter low power mode.
* @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
* This parameter can be one of the following values:
* @arg NVIC_LP_SEVONPEND
* @arg NVIC_LP_SLEEPDEEP
* @arg NVIC_LP_SLEEPONEXIT
* @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_NVIC_LP(LowPowerMode));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
SCB->SCR |= LowPowerMode;
}
else
{
SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
}
}
/**
* @brief Configures the SysTick clock source.
* @param SysTick_CLKSource: specifies the SysTick clock source.
* This parameter can be one of the following values:
* @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
* @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
* @retval None
*/
void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
{
/* Check the parameters */
assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
{
SysTick->CTRL |= SysTick_CLKSource_HCLK;
}
else
{
SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
| cnshaker/myrx | system/src/stm32f1-stdperiph/misc.c | C | apache-2.0 | 7,042 |
topojson = (function() {
function merge(topology, arcs) {
var arcsByEnd = {},
fragmentByStart = {},
fragmentByEnd = {};
arcs.forEach(function(i) {
var e = ends(i);
(arcsByEnd[e[0]] || (arcsByEnd[e[0]] = [])).push(i);
(arcsByEnd[e[1]] || (arcsByEnd[e[1]] = [])).push(~i);
});
arcs.forEach(function(i) {
var e = ends(i),
start = e[0],
end = e[1],
f, g;
if (f = fragmentByEnd[start]) {
delete fragmentByEnd[f.end];
f.push(i);
f.end = end;
if (g = fragmentByStart[end]) {
delete fragmentByStart[g.start];
var fg = g === f ? f : f.concat(g);
fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg;
} else if (g = fragmentByEnd[end]) {
delete fragmentByStart[g.start];
delete fragmentByEnd[g.end];
var fg = f.concat(g.map(function(i) { return ~i; }).reverse());
fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.start] = fg;
} else {
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
}
} else if (f = fragmentByStart[end]) {
delete fragmentByStart[f.start];
f.unshift(i);
f.start = start;
if (g = fragmentByEnd[start]) {
delete fragmentByEnd[g.end];
var gf = g === f ? f : g.concat(f);
fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf;
} else if (g = fragmentByStart[start]) {
delete fragmentByStart[g.start];
delete fragmentByEnd[g.end];
var gf = g.map(function(i) { return ~i; }).reverse().concat(f);
fragmentByStart[gf.start = g.end] = fragmentByEnd[gf.end = f.end] = gf;
} else {
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
}
} else if (f = fragmentByStart[start]) {
delete fragmentByStart[f.start];
f.unshift(~i);
f.start = end;
if (g = fragmentByEnd[end]) {
delete fragmentByEnd[g.end];
var gf = g === f ? f : g.concat(f);
fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf;
} else if (g = fragmentByStart[end]) {
delete fragmentByStart[g.start];
delete fragmentByEnd[g.end];
var gf = g.map(function(i) { return ~i; }).reverse().concat(f);
fragmentByStart[gf.start = g.end] = fragmentByEnd[gf.end = f.end] = gf;
} else {
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
}
} else if (f = fragmentByEnd[end]) {
delete fragmentByEnd[f.end];
f.push(~i);
f.end = start;
if (g = fragmentByEnd[start]) {
delete fragmentByStart[g.start];
var fg = g === f ? f : f.concat(g);
fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg;
} else if (g = fragmentByStart[start]) {
delete fragmentByStart[g.start];
delete fragmentByEnd[g.end];
var fg = f.concat(g.map(function(i) { return ~i; }).reverse());
fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.start] = fg;
} else {
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
}
} else {
f = [i];
fragmentByStart[f.start = start] = fragmentByEnd[f.end = end] = f;
}
});
function ends(i) {
var arc = topology.arcs[i], p0 = arc[0], p1 = [0, 0];
arc.forEach(function(dp) { p1[0] += dp[0], p1[1] += dp[1]; });
return [p0, p1];
}
var fragments = [];
for (var k in fragmentByEnd) fragments.push(fragmentByEnd[k]);
return fragments;
}
function mesh(topology, o, filter) {
var arcs = [];
if (arguments.length > 1) {
var geomsByArc = [],
geom;
function arc(i) {
if (i < 0) i = ~i;
(geomsByArc[i] || (geomsByArc[i] = [])).push(geom);
}
function line(arcs) {
arcs.forEach(arc);
}
function polygon(arcs) {
arcs.forEach(line);
}
function geometry(o) {
if (o.type === "GeometryCollection") o.geometries.forEach(geometry);
else if (o.type in geometryType) {
geom = o;
geometryType[o.type](o.arcs);
}
}
var geometryType = {
LineString: line,
MultiLineString: polygon,
Polygon: polygon,
MultiPolygon: function(arcs) { arcs.forEach(polygon); }
};
geometry(o);
geomsByArc.forEach(arguments.length < 3
? function(geoms, i) { arcs.push([i]); }
: function(geoms, i) { if (filter(geoms[0], geoms[geoms.length - 1])) arcs.push([i]); });
} else {
for (var i = 0, n = topology.arcs.length; i < n; ++i) arcs.push([i]);
}
return object(topology, {type: "MultiLineString", arcs: merge(topology, arcs)});
}
function object(topology, o) {
var tf = topology.transform,
kx = tf.scale[0],
ky = tf.scale[1],
dx = tf.translate[0],
dy = tf.translate[1],
arcs = topology.arcs;
function arc(i, points) {
if (points.length) points.pop();
for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length, x = 0, y = 0, p; k < n; ++k) points.push([
(x += (p = a[k])[0]) * kx + dx,
(y += p[1]) * ky + dy
]);
if (i < 0) reverse(points, n);
}
function point(coordinates) {
return [coordinates[0] * kx + dx, coordinates[1] * ky + dy];
}
function line(arcs) {
var points = [];
for (var i = 0, n = arcs.length; i < n; ++i) arc(arcs[i], points);
if (points.length < 2) points.push(points[0]);
return points;
}
function ring(arcs) {
var points = line(arcs);
while (points.length < 4) points.push(points[0]);
return points;
}
function polygon(arcs) {
return arcs.map(ring);
}
function geometry(o) {
var t = o.type, g = t === "GeometryCollection" ? {type: t, geometries: o.geometries.map(geometry)}
: t in geometryType ? {type: t, coordinates: geometryType[t](o)}
: {type: null};
if ("id" in o) g.id = o.id;
if ("properties" in o) g.properties = o.properties;
return g;
}
var geometryType = {
Point: function(o) { return point(o.coordinates); },
MultiPoint: function(o) { return o.coordinates.map(point); },
LineString: function(o) { return line(o.arcs); },
MultiLineString: function(o) { return o.arcs.map(line); },
Polygon: function(o) { return polygon(o.arcs); },
MultiPolygon: function(o) { return o.arcs.map(polygon); }
};
return geometry(o);
}
function reverse(array, n) {
var t, j = array.length, i = j - n; while (i < --j) t = array[i], array[i++] = array[j], array[j] = t;
}
function bisect(a, x) {
var lo = 0, hi = a.length;
while (lo < hi) {
var mid = lo + hi >>> 1;
if (a[mid] < x) lo = mid + 1;
else hi = mid;
}
return lo;
}
function neighbors(objects) {
var objectsByArc = [],
neighbors = objects.map(function() { return []; });
function line(arcs, i) {
arcs.forEach(function(a) {
if (a < 0) a = ~a;
var o = objectsByArc[a] || (objectsByArc[a] = []);
if (!o[i]) o.forEach(function(j) {
var n, k;
k = bisect(n = neighbors[i], j); if (n[k] !== j) n.splice(k, 0, j);
k = bisect(n = neighbors[j], i); if (n[k] !== i) n.splice(k, 0, i);
}), o[i] = i;
});
}
function polygon(arcs, i) {
arcs.forEach(function(arc) { line(arc, i); });
}
function geometry(o, i) {
if (o.type === "GeometryCollection") o.geometries.forEach(function(o) { geometry(o, i); });
else if (o.type in geometryType) geometryType[o.type](o.arcs, i);
}
var geometryType = {
LineString: line,
MultiLineString: polygon,
Polygon: polygon,
MultiPolygon: function(arcs, i) { arcs.forEach(function(arc) { polygon(arc, i); }); }
};
objects.forEach(geometry);
return neighbors;
}
return {
version: "0.0.28",
mesh: mesh,
object: object,
neighbors: neighbors
};
})();
| pzp1997/cdnjs | ajax/libs/topojson/0.0.28/topojson.js | JavaScript | mit | 8,261 |
/* Public domain. */
#ifndef CDB_H
#define CDB_H
#include <string.h>
#include "types.h"
#define KVLSZ 4
#define CDB_MAX_KEY 0xff
#define CDB_MAX_VALUE 0xffffff
#define CDB_HASHSTART 5381
struct cdb {
char *map; /* 0 if no map is available */
int fd; /* filedescriptor */
ut32 size; /* initialized if map is nonzero */
ut32 loop; /* number of hash slots searched under this key */
ut32 khash; /* initialized if loop is nonzero */
ut32 kpos; /* initialized if loop is nonzero */
ut32 hpos; /* initialized if loop is nonzero */
ut32 hslots; /* initialized if loop is nonzero */
ut32 dpos; /* initialized if cdb_findnext() returns 1 */
ut32 dlen; /* initialized if cdb_findnext() returns 1 */
};
/* TODO THIS MUST GTFO! */
bool cdb_getkvlen(struct cdb *db, ut32 *klen, ut32 *vlen, ut32 pos);
void cdb_free(struct cdb *);
bool cdb_init(struct cdb *, int fd);
void cdb_findstart(struct cdb *);
bool cdb_read(struct cdb *, char *, unsigned int, ut32);
int cdb_findnext(struct cdb *, ut32 u, const char *, ut32);
#define cdb_datapos(c) ((c)->dpos)
#define cdb_datalen(c) ((c)->dlen)
#endif
| alvarofe/sdb | src/cdb.h | C | mit | 1,120 |
Package.describe({
summary: "Github OAuth flow",
version: "1.1.4-plugins.0"
});
Package.onUse(function(api) {
api.use('oauth2', ['client', 'server']);
api.use('oauth', ['client', 'server']);
api.use('http', ['server']);
api.use('underscore', 'client');
api.use('templating', 'client');
api.use('random', 'client');
api.use('service-configuration', ['client', 'server']);
api.export('Github');
api.addFiles(
['github_configure.html', 'github_configure.js'],
'client');
api.addFiles('github_server.js', 'server');
api.addFiles('github_client.js', 'client');
});
| joannekoong/meteor | packages/github/package.js | JavaScript | mit | 598 |
#--
# Copyright (c) 2006-2013 Philip Ross
#
# 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 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.
#++
module TZInfo
# Represents an offset defined in a Timezone data file.
#
# @private
class TimezoneOffsetInfo #:nodoc:
# The base offset of the timezone from UTC in seconds.
attr_reader :utc_offset
# The offset from standard time for the zone in seconds (i.e. non-zero if
# daylight savings is being observed).
attr_reader :std_offset
# The total offset of this observance from UTC in seconds
# (utc_offset + std_offset).
attr_reader :utc_total_offset
# The abbreviation that identifies this observance, e.g. "GMT"
# (Greenwich Mean Time) or "BST" (British Summer Time) for "Europe/London". The returned identifier is a
# symbol.
attr_reader :abbreviation
# Constructs a new TimezoneOffsetInfo. utc_offset and std_offset are
# specified in seconds.
def initialize(utc_offset, std_offset, abbreviation)
@utc_offset = utc_offset
@std_offset = std_offset
@abbreviation = abbreviation
@utc_total_offset = @utc_offset + @std_offset
end
# True if std_offset is non-zero.
def dst?
@std_offset != 0
end
# Converts a UTC DateTime to local time based on the offset of this period.
def to_local(utc)
TimeOrDateTime.wrap(utc) {|wrapped|
wrapped + @utc_total_offset
}
end
# Converts a local DateTime to UTC based on the offset of this period.
def to_utc(local)
TimeOrDateTime.wrap(local) {|wrapped|
wrapped - @utc_total_offset
}
end
# Returns true if and only if toi has the same utc_offset, std_offset
# and abbreviation as this TimezoneOffsetInfo.
def ==(toi)
toi.kind_of?(TimezoneOffsetInfo) &&
utc_offset == toi.utc_offset && std_offset == toi.std_offset && abbreviation == toi.abbreviation
end
# Returns true if and only if toi has the same utc_offset, std_offset
# and abbreviation as this TimezoneOffsetInfo.
def eql?(toi)
self == toi
end
# Returns a hash of this TimezoneOffsetInfo.
def hash
utc_offset.hash ^ std_offset.hash ^ abbreviation.hash
end
# Returns internal object state as a programmer-readable string.
def inspect
"#<#{self.class}: #@utc_offset,#@std_offset,#@abbreviation>"
end
end
end
| apcomplete/devise_security_questions | vendor/ruby/gems/tzinfo-0.3.39/lib/tzinfo/timezone_offset_info.rb | Ruby | mit | 3,439 |
define(
"dijit/form/nls/ca/validate", ({
invalidMessage: "El valor introduït no és vàlid",
missingMessage: "Aquest valor és necessari",
rangeMessage: "Aquest valor és fora de l'interval"
})
);
| Caspar12/zh.sw | zh.web.site.admin/src/main/resources/static/js/dojo/dijit/form/nls/ca/validate.js.uncompressed.js | JavaScript | apache-2.0 | 201 |
# 打印
> 编写:[jdneo](https://github.com/jdneo) - 原文:<http://developer.android.com/training/printing/index.html>
Android用户经常需要在设备上单独地阅览信息,但有时候也需要为了分享信息而不得不给其他人看自己设备的屏幕,这显然不是分享信息的好办法。如果我们可以通过Android应用把希望分享的信息打印出来,这将给用户提供一种从应用获取更多信息的好办法,更何况这么做还能将信息分享给其他那些不使用我们的应用的人。另外,打印服务还能创建信息的快照(生成PDF文件),而这一切不需要打印设备,无线网络连接,也不会消耗过多电量。
在Android 4.4(API Level 19)及更高版本的系统中,框架提供了直接从Android应用程序打印图片和文字的服务。这系列课程将展示如何启用打印:包括打印图片,HTML页面以及创建自定义的打印文档。
## Lessons
* [**打印照片**](photos.html)
这节课将展示如何打印一幅图像。
* [**打印HTML文档**](html-docs.html)
这节课将展示如何打印一个HTML文档。
* [**打印自定义文档**](custom-docs.html)
这节课将展示如何连接到Android打印管理器,创建一个打印适配器并建立要打印的内容。
| dupengwei/android-training-course-in-chinese | multimedia/printing/index.md | Markdown | apache-2.0 | 1,325 |
html {
overflow-y: auto;
}
body {
padding: 1em;
}
.snippets {
}
.snippet {
background: white;
padding: 10px 20px 0px 20px;
margin-top: 20px;
border: 1px solid #ddd;
}
.snippet h2 {
margin-top: 0;
margin-left: -10px;
}
.snippet pre {
font-size: 13px;
overflow: auto;
-webkit-user-select: initial;
}
.snippet h2 span {
display: inline-block;
margin-left: 1em;
font-size: 10px;
font-weight: normal;
}
.snippet h2 span a {
text-decoration: none;
} | Jabqooo/chrome-app-samples | samples/identity/sample_support/snippets.css | CSS | apache-2.0 | 482 |
/*
Copyright © 2002, The KPD-Team
All rights reserved.
http://www.mentalis.org/
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.
- Neither the name of the KPD-Team, 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.
*/
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace Org.Mentalis.Network.ProxySocket.Authentication {
/// <summary>
/// This class implements the 'username/password authentication' scheme.
/// </summary>
internal sealed class AuthUserPass : AuthMethod {
/// <summary>
/// Initializes a new AuthUserPass instance.
/// </summary>
/// <param name="server">The socket connection with the proxy server.</param>
/// <param name="user">The username to use.</param>
/// <param name="pass">The password to use.</param>
/// <exception cref="ArgumentNullException"><c>user</c> -or- <c>pass</c> is null.</exception>
public AuthUserPass(Socket server, string user, string pass) : base(server) {
Username = user;
Password = pass;
}
/// <summary>
/// Creates an array of bytes that has to be sent if the user wants to authenticate with the username/password authentication scheme.
/// </summary>
/// <returns>An array of bytes that has to be sent if the user wants to authenticate with the username/password authentication scheme.</returns>
private byte[] GetAuthenticationBytes() {
byte[] buffer = new byte[3 + Username.Length + Password.Length];
buffer[0] = 1;
buffer[1] = (byte)Username.Length;
Array.Copy(Encoding.ASCII.GetBytes(Username), 0, buffer, 2, Username.Length);
buffer[Username.Length + 2] = (byte)Password.Length;
Array.Copy(Encoding.ASCII.GetBytes(Password), 0, buffer, Username.Length + 3, Password.Length);
return buffer;
}
/// <summary>
/// Starts the authentication process.
/// </summary>
public override void Authenticate() {
Server.Send(GetAuthenticationBytes());
byte[] buffer = new byte[2];
int received = 0;
while (received != 2) {
received += Server.Receive(buffer, received, 2 - received, SocketFlags.None);
}
if (buffer[1] != 0) {
Server.Close();
throw new ProxyException("Username/password combination rejected.");
}
return;
}
/// <summary>
/// Starts the asynchronous authentication process.
/// </summary>
/// <param name="callback">The method to call when the authentication is complete.</param>
public override void BeginAuthenticate(HandShakeComplete callback) {
CallBack = callback;
Server.BeginSend(GetAuthenticationBytes(), 0, 3 + Username.Length + Password.Length, SocketFlags.None, new AsyncCallback(this.OnSent), Server);
return;
}
/// <summary>
/// Called when the authentication bytes have been sent.
/// </summary>
/// <param name="ar">Stores state information for this asynchronous operation as well as any user-defined data.</param>
private void OnSent(IAsyncResult ar) {
try {
Server.EndSend(ar);
Buffer = new byte[2];
Server.BeginReceive(Buffer, 0, 2, SocketFlags.None, new AsyncCallback(this.OnReceive), Server);
} catch (Exception e) {
CallBack(e);
}
}
/// <summary>
/// Called when the socket received an authentication reply.
/// </summary>
/// <param name="ar">Stores state information for this asynchronous operation as well as any user-defined data.</param>
private void OnReceive(IAsyncResult ar) {
try {
Received += Server.EndReceive(ar);
if (Received == Buffer.Length)
if (Buffer[1] == 0)
CallBack(null);
else
throw new ProxyException("Username/password combination not accepted.");
else
Server.BeginReceive(Buffer, Received, Buffer.Length - Received, SocketFlags.None, new AsyncCallback(this.OnReceive), Server);
} catch (Exception e) {
CallBack(e);
}
}
/// <summary>
/// Gets or sets the username to use when authenticating with the proxy server.
/// </summary>
/// <value>The username to use when authenticating with the proxy server.</value>
/// <exception cref="ArgumentNullException">The specified value is null.</exception>
private string Username {
get {
return m_Username;
}
set {
if (value == null)
throw new ArgumentNullException();
m_Username = value;
}
}
/// <summary>
/// Gets or sets the password to use when authenticating with the proxy server.
/// </summary>
/// <value>The password to use when authenticating with the proxy server.</value>
/// <exception cref="ArgumentNullException">The specified value is null.</exception>
private string Password {
get {
return m_Password;
}
set {
if (value == null)
throw new ArgumentNullException();
m_Password = value;
}
}
// private variables
/// <summary>Holds the value of the Username property.</summary>
private string m_Username;
/// <summary>Holds the value of the Password property.</summary>
private string m_Password;
}
} | kolrabi/DesktopBooru | Sources/Network/ProxySocket/AuthUserPass.cs | C# | gpl-3.0 | 6,063 |
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
// Package glacier provides the client and types for making API
// requests to Amazon Glacier.
//
// Amazon Glacier is a storage solution for "cold data."
//
// Amazon Glacier is an extremely low-cost storage service that provides secure,
// durable, and easy-to-use storage for data backup and archival. With Amazon
// Glacier, customers can store their data cost effectively for months, years,
// or decades. Amazon Glacier also enables customers to offload the administrative
// burdens of operating and scaling storage to AWS, so they don't have to worry
// about capacity planning, hardware provisioning, data replication, hardware
// failure and recovery, or time-consuming hardware migrations.
//
// Amazon Glacier is a great storage choice when low storage cost is paramount,
// your data is rarely retrieved, and retrieval latency of several hours is
// acceptable. If your application requires fast or frequent access to your
// data, consider using Amazon S3. For more information, see Amazon Simple Storage
// Service (Amazon S3) (http://aws.amazon.com/s3/).
//
// You can store any kind of data in any format. There is no maximum limit on
// the total amount of data you can store in Amazon Glacier.
//
// If you are a first-time user of Amazon Glacier, we recommend that you begin
// by reading the following sections in the Amazon Glacier Developer Guide:
//
// * What is Amazon Glacier (http://docs.aws.amazon.com/amazonglacier/latest/dev/introduction.html)
// - This section of the Developer Guide describes the underlying data model,
// the operations it supports, and the AWS SDKs that you can use to interact
// with the service.
//
// * Getting Started with Amazon Glacier (http://docs.aws.amazon.com/amazonglacier/latest/dev/amazon-glacier-getting-started.html)
// - The Getting Started section walks you through the process of creating
// a vault, uploading archives, creating jobs to download archives, retrieving
// the job output, and deleting archives.
//
// See glacier package documentation for more information.
// https://docs.aws.amazon.com/sdk-for-go/api/service/glacier/
//
// Using the Client
//
// To Amazon Glacier with the SDK use the New function to create
// a new service client. With that client you can make API requests to the service.
// These clients are safe to use concurrently.
//
// See the SDK's documentation for more information on how to use the SDK.
// https://docs.aws.amazon.com/sdk-for-go/api/
//
// See aws.Config documentation for more information on configuring SDK clients.
// https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
//
// See the Amazon Glacier client Glacier for more
// information on creating client for this service.
// https://docs.aws.amazon.com/sdk-for-go/api/service/glacier/#New
package glacier
| crobby/oshinko-cli | vendor/github.com/openshift/origin/cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/vendor/github.com/aws/aws-sdk-go/service/glacier/doc.go | GO | apache-2.0 | 2,876 |
#include "builtin.h"
#include "tree-walk.h"
#include "xdiff-interface.h"
#include "blob.h"
#include "exec_cmd.h"
#include "merge-blobs.h"
static const char merge_tree_usage[] = "git merge-tree <base-tree> <branch1> <branch2>";
struct merge_list {
struct merge_list *next;
struct merge_list *link; /* other stages for this object */
unsigned int stage : 2;
unsigned int mode;
const char *path;
struct blob *blob;
};
static struct merge_list *merge_result, **merge_result_end = &merge_result;
static void add_merge_entry(struct merge_list *entry)
{
*merge_result_end = entry;
merge_result_end = &entry->next;
}
static void merge_trees_recursive(struct tree_desc t[3], const char *base, int df_conflict);
static const char *explanation(struct merge_list *entry)
{
switch (entry->stage) {
case 0:
return "merged";
case 3:
return "added in remote";
case 2:
if (entry->link)
return "added in both";
return "added in local";
}
/* Existed in base */
entry = entry->link;
if (!entry)
return "removed in both";
if (entry->link)
return "changed in both";
if (entry->stage == 3)
return "removed in local";
return "removed in remote";
}
static void *result(struct merge_list *entry, unsigned long *size)
{
enum object_type type;
struct blob *base, *our, *their;
const char *path = entry->path;
if (!entry->stage)
return read_sha1_file(entry->blob->object.sha1, &type, size);
base = NULL;
if (entry->stage == 1) {
base = entry->blob;
entry = entry->link;
}
our = NULL;
if (entry && entry->stage == 2) {
our = entry->blob;
entry = entry->link;
}
their = NULL;
if (entry)
their = entry->blob;
return merge_blobs(path, base, our, their, size);
}
static void *origin(struct merge_list *entry, unsigned long *size)
{
enum object_type type;
while (entry) {
if (entry->stage == 2)
return read_sha1_file(entry->blob->object.sha1, &type, size);
entry = entry->link;
}
return NULL;
}
static int show_outf(void *priv_, mmbuffer_t *mb, int nbuf)
{
int i;
for (i = 0; i < nbuf; i++)
printf("%.*s", (int) mb[i].size, mb[i].ptr);
return 0;
}
static void show_diff(struct merge_list *entry)
{
unsigned long size;
mmfile_t src, dst;
xpparam_t xpp;
xdemitconf_t xecfg;
xdemitcb_t ecb;
xpp.flags = 0;
memset(&xecfg, 0, sizeof(xecfg));
xecfg.ctxlen = 3;
ecb.outf = show_outf;
ecb.priv = NULL;
src.ptr = origin(entry, &size);
if (!src.ptr)
size = 0;
src.size = size;
dst.ptr = result(entry, &size);
if (!dst.ptr)
size = 0;
dst.size = size;
xdi_diff(&src, &dst, &xpp, &xecfg, &ecb);
free(src.ptr);
free(dst.ptr);
}
static void show_result_list(struct merge_list *entry)
{
printf("%s\n", explanation(entry));
do {
struct merge_list *link = entry->link;
static const char *desc[4] = { "result", "base", "our", "their" };
printf(" %-6s %o %s %s\n", desc[entry->stage], entry->mode, sha1_to_hex(entry->blob->object.sha1), entry->path);
entry = link;
} while (entry);
}
static void show_result(void)
{
struct merge_list *walk;
walk = merge_result;
while (walk) {
show_result_list(walk);
show_diff(walk);
walk = walk->next;
}
}
/* An empty entry never compares same, not even to another empty entry */
static int same_entry(struct name_entry *a, struct name_entry *b)
{
return a->sha1 &&
b->sha1 &&
!hashcmp(a->sha1, b->sha1) &&
a->mode == b->mode;
}
static int both_empty(struct name_entry *a, struct name_entry *b)
{
return !(a->sha1 || b->sha1);
}
static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
{
struct merge_list *res = xcalloc(1, sizeof(*res));
res->stage = stage;
res->path = path;
res->mode = mode;
res->blob = lookup_blob(sha1);
return res;
}
static char *traverse_path(const struct traverse_info *info, const struct name_entry *n)
{
char *path = xmalloc(traverse_path_len(info, n) + 1);
return make_traverse_path(path, info, n);
}
static void resolve(const struct traverse_info *info, struct name_entry *ours, struct name_entry *result)
{
struct merge_list *orig, *final;
const char *path;
/* If it's already ours, don't bother showing it */
if (!ours)
return;
path = traverse_path(info, result);
orig = create_entry(2, ours->mode, ours->sha1, path);
final = create_entry(0, result->mode, result->sha1, path);
final->link = orig;
add_merge_entry(final);
}
static void unresolved_directory(const struct traverse_info *info, struct name_entry n[3],
int df_conflict)
{
char *newbase;
struct name_entry *p;
struct tree_desc t[3];
void *buf0, *buf1, *buf2;
for (p = n; p < n + 3; p++) {
if (p->mode && S_ISDIR(p->mode))
break;
}
if (n + 3 <= p)
return; /* there is no tree here */
newbase = traverse_path(info, p);
#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->sha1 : NULL)
buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
buf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2));
#undef ENTRY_SHA1
merge_trees_recursive(t, newbase, df_conflict);
free(buf0);
free(buf1);
free(buf2);
free(newbase);
}
static struct merge_list *link_entry(unsigned stage, const struct traverse_info *info, struct name_entry *n, struct merge_list *entry)
{
const char *path;
struct merge_list *link;
if (!n->mode)
return entry;
if (entry)
path = entry->path;
else
path = traverse_path(info, n);
link = create_entry(stage, n->mode, n->sha1, path);
link->link = entry;
return link;
}
static void unresolved(const struct traverse_info *info, struct name_entry n[3])
{
struct merge_list *entry = NULL;
int i;
unsigned dirmask = 0, mask = 0;
for (i = 0; i < 3; i++) {
mask |= (1 << i);
/*
* Treat missing entries as directories so that we return
* after unresolved_directory has handled this.
*/
if (!n[i].mode || S_ISDIR(n[i].mode))
dirmask |= (1 << i);
}
unresolved_directory(info, n, dirmask && (dirmask != mask));
if (dirmask == mask)
return;
if (n[2].mode && !S_ISDIR(n[2].mode))
entry = link_entry(3, info, n + 2, entry);
if (n[1].mode && !S_ISDIR(n[1].mode))
entry = link_entry(2, info, n + 1, entry);
if (n[0].mode && !S_ISDIR(n[0].mode))
entry = link_entry(1, info, n + 0, entry);
add_merge_entry(entry);
}
/*
* Merge two trees together (t[1] and t[2]), using a common base (t[0])
* as the origin.
*
* This walks the (sorted) trees in lock-step, checking every possible
* name. Note that directories automatically sort differently from other
* files (see "base_name_compare"), so you'll never see file/directory
* conflicts, because they won't ever compare the same.
*
* IOW, if a directory changes to a filename, it will automatically be
* seen as the directory going away, and the filename being created.
*
* Think of this as a three-way diff.
*
* The output will be either:
* - successful merge
* "0 mode sha1 filename"
* NOTE NOTE NOTE! FIXME! We really really need to walk the index
* in parallel with this too!
*
* - conflict:
* "1 mode sha1 filename"
* "2 mode sha1 filename"
* "3 mode sha1 filename"
* where not all of the 1/2/3 lines may exist, of course.
*
* The successful merge rules are the same as for the three-way merge
* in git-read-tree.
*/
static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *info)
{
/* Same in both? */
if (same_entry(entry+1, entry+2) || both_empty(entry+1, entry+2)) {
/* Modified, added or removed identically */
resolve(info, NULL, entry+1);
return mask;
}
if (same_entry(entry+0, entry+1)) {
if (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {
/* We did not touch, they modified -- take theirs */
resolve(info, entry+1, entry+2);
return mask;
}
/*
* If we did not touch a directory but they made it
* into a file, we fall through and unresolved()
* recurses down. Likewise for the opposite case.
*/
}
if (same_entry(entry+0, entry+2) || both_empty(entry+0, entry+2)) {
/* We added, modified or removed, they did not touch -- take ours */
resolve(info, NULL, entry+1);
return mask;
}
unresolved(info, entry);
return mask;
}
static void merge_trees_recursive(struct tree_desc t[3], const char *base, int df_conflict)
{
struct traverse_info info;
setup_traverse_info(&info, base);
info.data = &df_conflict;
info.fn = threeway_callback;
traverse_trees(3, t, &info);
}
static void merge_trees(struct tree_desc t[3], const char *base)
{
merge_trees_recursive(t, base, 0);
}
static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
{
unsigned char sha1[20];
void *buf;
if (get_sha1(rev, sha1))
die("unknown rev %s", rev);
buf = fill_tree_descriptor(desc, sha1);
if (!buf)
die("%s is not a tree", rev);
return buf;
}
int cmd_merge_tree(int argc, const char **argv, const char *prefix)
{
struct tree_desc t[3];
void *buf1, *buf2, *buf3;
if (argc != 4)
usage(merge_tree_usage);
buf1 = get_tree_descriptor(t+0, argv[1]);
buf2 = get_tree_descriptor(t+1, argv[2]);
buf3 = get_tree_descriptor(t+2, argv[3]);
merge_trees(t, "");
free(buf1);
free(buf2);
free(buf3);
show_result();
return 0;
}
| overtherain/scriptfile | tool-kit/git-2.1.2/builtin/merge-tree.c | C | mit | 9,196 |
// SPDX-License-Identifier: GPL-2.0-only
/* Tom Kelly's Scalable TCP
*
* See http://www.deneholme.net/tom/scalable/
*
* John Heffner <jheffner@sc.edu>
*/
#include <linux/module.h>
#include <net/tcp.h>
/* These factors derived from the recommended values in the aer:
* .01 and and 7/8.
*/
#define TCP_SCALABLE_AI_CNT 100U
#define TCP_SCALABLE_MD_SCALE 3
static void tcp_scalable_cong_avoid(struct sock *sk, u32 ack, u32 acked)
{
struct tcp_sock *tp = tcp_sk(sk);
if (!tcp_is_cwnd_limited(sk))
return;
if (tcp_in_slow_start(tp)) {
acked = tcp_slow_start(tp, acked);
if (!acked)
return;
}
tcp_cong_avoid_ai(tp, min(tp->snd_cwnd, TCP_SCALABLE_AI_CNT),
acked);
}
static u32 tcp_scalable_ssthresh(struct sock *sk)
{
const struct tcp_sock *tp = tcp_sk(sk);
return max(tp->snd_cwnd - (tp->snd_cwnd>>TCP_SCALABLE_MD_SCALE), 2U);
}
static struct tcp_congestion_ops tcp_scalable __read_mostly = {
.ssthresh = tcp_scalable_ssthresh,
.undo_cwnd = tcp_reno_undo_cwnd,
.cong_avoid = tcp_scalable_cong_avoid,
.owner = THIS_MODULE,
.name = "scalable",
};
static int __init tcp_scalable_register(void)
{
return tcp_register_congestion_control(&tcp_scalable);
}
static void __exit tcp_scalable_unregister(void)
{
tcp_unregister_congestion_control(&tcp_scalable);
}
module_init(tcp_scalable_register);
module_exit(tcp_scalable_unregister);
MODULE_AUTHOR("John Heffner");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Scalable TCP");
| penberg/linux | net/ipv4/tcp_scalable.c | C | gpl-2.0 | 1,460 |
/*
* include/linux/userfaultfd.h
*
* Copyright (C) 2007 Davide Libenzi <davidel@xmailserver.org>
* Copyright (C) 2015 Red Hat, Inc.
*
*/
#ifndef _LINUX_USERFAULTFD_H
#define _LINUX_USERFAULTFD_H
#include <linux/types.h>
/*
* If the UFFDIO_API is upgraded someday, the UFFDIO_UNREGISTER and
* UFFDIO_WAKE ioctls should be defined as _IOW and not as _IOR. In
* userfaultfd.h we assumed the kernel was reading (instead _IOC_READ
* means the userland is reading).
*/
#define UFFD_API ((__u64)0xAA)
#define UFFD_API_FEATURES (UFFD_FEATURE_EVENT_FORK | \
UFFD_FEATURE_EVENT_REMAP | \
UFFD_FEATURE_EVENT_REMOVE | \
UFFD_FEATURE_EVENT_UNMAP | \
UFFD_FEATURE_MISSING_HUGETLBFS | \
UFFD_FEATURE_MISSING_SHMEM)
#define UFFD_API_IOCTLS \
((__u64)1 << _UFFDIO_REGISTER | \
(__u64)1 << _UFFDIO_UNREGISTER | \
(__u64)1 << _UFFDIO_API)
#define UFFD_API_RANGE_IOCTLS \
((__u64)1 << _UFFDIO_WAKE | \
(__u64)1 << _UFFDIO_COPY | \
(__u64)1 << _UFFDIO_ZEROPAGE)
#define UFFD_API_RANGE_IOCTLS_BASIC \
((__u64)1 << _UFFDIO_WAKE | \
(__u64)1 << _UFFDIO_COPY)
/*
* Valid ioctl command number range with this API is from 0x00 to
* 0x3F. UFFDIO_API is the fixed number, everything else can be
* changed by implementing a different UFFD_API. If sticking to the
* same UFFD_API more ioctl can be added and userland will be aware of
* which ioctl the running kernel implements through the ioctl command
* bitmask written by the UFFDIO_API.
*/
#define _UFFDIO_REGISTER (0x00)
#define _UFFDIO_UNREGISTER (0x01)
#define _UFFDIO_WAKE (0x02)
#define _UFFDIO_COPY (0x03)
#define _UFFDIO_ZEROPAGE (0x04)
#define _UFFDIO_API (0x3F)
/* userfaultfd ioctl ids */
#define UFFDIO 0xAA
#define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \
struct uffdio_api)
#define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \
struct uffdio_register)
#define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \
struct uffdio_range)
#define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \
struct uffdio_range)
#define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \
struct uffdio_copy)
#define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \
struct uffdio_zeropage)
/* read() structure */
struct uffd_msg {
__u8 event;
__u8 reserved1;
__u16 reserved2;
__u32 reserved3;
union {
struct {
__u64 flags;
__u64 address;
} pagefault;
struct {
__u32 ufd;
} fork;
struct {
__u64 from;
__u64 to;
__u64 len;
} remap;
struct {
__u64 start;
__u64 end;
} remove;
struct {
/* unused reserved fields */
__u64 reserved1;
__u64 reserved2;
__u64 reserved3;
} reserved;
} arg;
} __packed;
/*
* Start at 0x12 and not at 0 to be more strict against bugs.
*/
#define UFFD_EVENT_PAGEFAULT 0x12
#define UFFD_EVENT_FORK 0x13
#define UFFD_EVENT_REMAP 0x14
#define UFFD_EVENT_REMOVE 0x15
#define UFFD_EVENT_UNMAP 0x16
/* flags for UFFD_EVENT_PAGEFAULT */
#define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */
#define UFFD_PAGEFAULT_FLAG_WP (1<<1) /* If reason is VM_UFFD_WP */
struct uffdio_api {
/* userland asks for an API number and the features to enable */
__u64 api;
/*
* Kernel answers below with the all available features for
* the API, this notifies userland of which events and/or
* which flags for each event are enabled in the current
* kernel.
*
* Note: UFFD_EVENT_PAGEFAULT and UFFD_PAGEFAULT_FLAG_WRITE
* are to be considered implicitly always enabled in all kernels as
* long as the uffdio_api.api requested matches UFFD_API.
*
* UFFD_FEATURE_MISSING_HUGETLBFS means an UFFDIO_REGISTER
* with UFFDIO_REGISTER_MODE_MISSING mode will succeed on
* hugetlbfs virtual memory ranges. Adding or not adding
* UFFD_FEATURE_MISSING_HUGETLBFS to uffdio_api.features has
* no real functional effect after UFFDIO_API returns, but
* it's only useful for an initial feature set probe at
* UFFDIO_API time. There are two ways to use it:
*
* 1) by adding UFFD_FEATURE_MISSING_HUGETLBFS to the
* uffdio_api.features before calling UFFDIO_API, an error
* will be returned by UFFDIO_API on a kernel without
* hugetlbfs missing support
*
* 2) the UFFD_FEATURE_MISSING_HUGETLBFS can not be added in
* uffdio_api.features and instead it will be set by the
* kernel in the uffdio_api.features if the kernel supports
* it, so userland can later check if the feature flag is
* present in uffdio_api.features after UFFDIO_API
* succeeded.
*
* UFFD_FEATURE_MISSING_SHMEM works the same as
* UFFD_FEATURE_MISSING_HUGETLBFS, but it applies to shmem
* (i.e. tmpfs and other shmem based APIs).
*/
#define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
#define UFFD_FEATURE_EVENT_FORK (1<<1)
#define UFFD_FEATURE_EVENT_REMAP (1<<2)
#define UFFD_FEATURE_EVENT_REMOVE (1<<3)
#define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4)
#define UFFD_FEATURE_MISSING_SHMEM (1<<5)
#define UFFD_FEATURE_EVENT_UNMAP (1<<6)
__u64 features;
__u64 ioctls;
};
struct uffdio_range {
__u64 start;
__u64 len;
};
struct uffdio_register {
struct uffdio_range range;
#define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0)
#define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1)
__u64 mode;
/*
* kernel answers which ioctl commands are available for the
* range, keep at the end as the last 8 bytes aren't read.
*/
__u64 ioctls;
};
struct uffdio_copy {
__u64 dst;
__u64 src;
__u64 len;
/*
* There will be a wrprotection flag later that allows to map
* pages wrprotected on the fly. And such a flag will be
* available if the wrprotection ioctl are implemented for the
* range according to the uffdio_register.ioctls.
*/
#define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0)
__u64 mode;
/*
* "copy" is written by the ioctl and must be at the end: the
* copy_from_user will not read the last 8 bytes.
*/
__s64 copy;
};
struct uffdio_zeropage {
struct uffdio_range range;
#define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0)
__u64 mode;
/*
* "zeropage" is written by the ioctl and must be at the end:
* the copy_from_user will not read the last 8 bytes.
*/
__s64 zeropage;
};
#endif /* _LINUX_USERFAULTFD_H */
| mkvdv/au-linux-kernel-autumn-2017 | linux/include/uapi/linux/userfaultfd.h | C | gpl-3.0 | 6,242 |
/*! interpolate.js v1.0.0 | (c) 2014 @toddmotto | https://github.com/toddmotto/interpolate */
!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e:t.interpolate=e()}(this,function(){"use strict";function t(t){"String"===e(t)&&(this.template=n(t))}function e(t){return Object.prototype.toString.call(t).slice(8,-1)}function n(t){return t.replace(/\s(?![^}}]*\{\{)/g,"")}return t.prototype.parse=function(t){if("Object"===e(t)){var n=this.template;for(var r in t){var i=new RegExp("{{"+r+"}}","g");i.test(n)&&(n=n.replace(i,t[r]))}return n}},function(e){var n=new t(e);return function(t){return n.parse(t)}}}); | rteasdale/cdnjs | ajax/libs/interpolate.js/1.0.0/interpolate.min.js | JavaScript | mit | 660 |
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Config\Definition\Builder;
use Symfony\Component\Config\Definition\EnumNode;
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
/**
* Enum Node Definition.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class EnumNodeDefinition extends ScalarNodeDefinition
{
private $values;
public function values(array $values)
{
$values = array_unique($values);
if (count($values) <= 1) {
throw new \InvalidArgumentException('->values() must be called with at least two distinct values.');
}
$this->values = $values;
return $this;
}
/**
* Instantiate a Node
*
* @return EnumNode The node
*
* @throws \RuntimeException
*/
protected function instantiateNode()
{
if (null === $this->values) {
throw new \RuntimeException('You must call ->values() on enum nodes.');
}
return new EnumNode($this->name, $this->parent, $this->values);
}
}
| LenLamberg/LenEntire_June_5 | winkler/profiles/commerce_kickstart/libraries/yotpo-php/vendor/symfony/config/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php | PHP | gpl-2.0 | 1,277 |
#!/bin/sh
test_description="Test the svn importer's input handling routines.
These tests provide some simple checks that the line_buffer API
behaves as advertised.
While at it, check that input of newlines and null bytes are handled
correctly.
"
. ./test-lib.sh
test_expect_success 'hello world' '
echo ">HELLO" >expect &&
test-line-buffer <<-\EOF >actual &&
binary 6
HELLO
EOF
test_cmp expect actual
'
test_expect_success '0-length read, send along greeting' '
echo ">HELLO" >expect &&
test-line-buffer <<-\EOF >actual &&
binary 0
copy 6
HELLO
EOF
test_cmp expect actual
'
test_expect_success 'read from file descriptor' '
rm -f input &&
echo hello >expect &&
echo hello >input &&
echo copy 6 |
test-line-buffer "&4" 4<input >actual &&
test_cmp expect actual
'
test_expect_success 'skip, copy null byte' '
echo Q | q_to_nul >expect &&
q_to_nul <<-\EOF | test-line-buffer >actual &&
skip 2
Q
copy 2
Q
EOF
test_cmp expect actual
'
test_expect_success 'read null byte' '
echo ">QhelloQ" | q_to_nul >expect &&
q_to_nul <<-\EOF | test-line-buffer >actual &&
binary 8
QhelloQ
EOF
test_cmp expect actual
'
test_expect_success 'long reads are truncated' '
echo ">foo" >expect &&
test-line-buffer <<-\EOF >actual &&
binary 5
foo
EOF
test_cmp expect actual
'
test_expect_success 'long copies are truncated' '
printf "%s\n" ">" foo >expect &&
test-line-buffer <<-\EOF >actual &&
binary 1
copy 5
foo
EOF
test_cmp expect actual
'
test_expect_success 'long binary reads are truncated' '
echo ">foo" >expect &&
test-line-buffer <<-\EOF >actual &&
binary 5
foo
EOF
test_cmp expect actual
'
test_done
| TextusData/Mover | thirdparty/git-1.7.11.3/t/t0081-line-buffer.sh | Shell | gpl-3.0 | 1,650 |
<?php
/**
* Order details table shown in emails.
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/plain/email-order-details.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email );
echo strtoupper( sprintf( __( 'Order number: %s', 'woocommerce' ), $order->get_order_number() ) ) . "\n";
echo date_i18n( __( 'jS F Y', 'woocommerce' ), strtotime( $order->order_date ) ) . "\n";
echo "\n" . $order->email_order_items_table( array(
'show_sku' => $sent_to_admin,
'show_image' => false,
'image_size' => array( 32, 32 ),
'plain_text' => true
) );
echo "==========\n\n";
if ( $totals = $order->get_order_item_totals() ) {
foreach ( $totals as $total ) {
echo $total['label'] . "\t " . $total['value'] . "\n";
}
}
if ( $sent_to_admin ) {
echo "\n" . sprintf( __( 'View order: %s', 'woocommerce'), admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ) . "\n";
}
do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email );
| befair/soulShape | wp/soulshape.earth/wp-content/plugins/woocommerce/templates/emails/plain/email-order-details.php | PHP | agpl-3.0 | 1,630 |
!function(a,b){function c(){function a(){"undefined"!=typeof _wpmejsSettings&&(c=b.extend(!0,{},_wpmejsSettings)),c.success=c.success||function(a){var b,c;"flash"===a.pluginType&&(b=a.attributes.autoplay&&"false"!==a.attributes.autoplay,c=a.attributes.loop&&"false"!==a.attributes.loop,b&&a.addEventListener("canplay",function(){a.play()},!1),c&&a.addEventListener("ended",function(){a.play()},!1))},b(".wp-audio-shortcode, .wp-video-shortcode").not(".mejs-container").filter(function(){return!b(this).parent().hasClass(".mejs-mediaelement")}).mediaelementplayer(c)}var c={};return{initialize:a}}a.wp=a.wp||{},mejs.plugins.silverlight[0].types.push("video/x-ms-wmv"),mejs.plugins.silverlight[0].types.push("audio/x-ms-wma"),a.wp.mediaelement=new c,b(a.wp.mediaelement.initialize)}(window,jQuery); | abbasarezoo/wp-starter-pack | www/wp-includes/js/mediaelement/wp-mediaelement.min.js | JavaScript | gpl-3.0 | 796 |
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.KeywordHighlighting
Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.KeywordHighlighting
Public Class MultiLineIfBlockHighlighterTests
Inherits AbstractVisualBasicKeywordHighlighterTests
Friend Overrides Function CreateHighlighter() As IHighlighter
Return New MultiLineIfBlockHighlighter()
End Function
<Fact, Trait(Traits.Feature, Traits.Features.KeywordHighlighting)>
Public Sub TestMultilineIf1()
Test(<Text><![CDATA[
Class C
Sub M()
{|Cursor:[|If|]|} a < b [|Then|]
a = b
[|ElseIf|] DateTime.Now.Ticks Mod 2 = 0
Throw New RandomException
[|Else|]
If a < b Then a = b Else b = a
[|End If|]
End Sub
End Class]]></Text>)
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.KeywordHighlighting)>
Public Sub TestMultilineIf2()
Test(<Text><![CDATA[
Class C
Sub M()
[|If|] a < b {|Cursor:[|Then|]|}
a = b
[|ElseIf|] DateTime.Now.Ticks Mod 2 = 0
Throw New RandomException
[|Else|]
If a < b Then a = b Else b = a
[|End If|]
End Sub
End Class]]></Text>)
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.KeywordHighlighting)>
Public Sub TestMultilineIf3()
Test(<Text><![CDATA[
Class C
Sub M()
[|If|] a < b [|Then|]
a = b
{|Cursor:[|ElseIf|]|} DateTime.Now.Ticks Mod 2 = 0
Throw New RandomException
[|Else|]
If a < b Then a = b Else b = a
[|End If|]
End Sub
End Class]]></Text>)
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.KeywordHighlighting)>
Public Sub TestMultilineIf4()
Test(<Text><![CDATA[
Class C
Sub M()
[|If|] a < b [|Then|]
a = b
[|ElseIf|] DateTime.Now.Ticks Mod 2 = 0
Throw New RandomException
[|{|Cursor:Else|}|]
If a < b Then a = b Else b = a
[|End If|]
End Sub
End Class]]></Text>)
End Sub
<Fact, Trait(Traits.Feature, Traits.Features.KeywordHighlighting)>
Public Sub TestMultilineIf5()
Test(<Text><![CDATA[
Class C
Sub M()
[|If|] a < b [|Then|]
a = b
[|ElseIf|] DateTime.Now.Ticks Mod 2 = 0
Throw New RandomException
[|Else|]
If a < b Then a = b Else b = a
{|Cursor:[|End If|]|}
End Sub
End Class]]></Text>)
End Sub
<WorkItem(542614)>
<Fact, Trait(Traits.Feature, Traits.Features.KeywordHighlighting)>
Public Sub TestMultilineIf6()
Test(<Text><![CDATA[
Imports System
Module M
Sub C()
Dim x As Integer = 5
[|If|] x < 0 [|Then|]
{|Cursor:[|Else If|]|}
[|End If|]
End Sub
End Module]]></Text>)
End Sub
End Class
End Namespace
| droyad/roslyn | src/EditorFeatures/VisualBasicTest/KeywordHighlighting/MultiLineIfBlockHighlighterTests.vb | Visual Basic | apache-2.0 | 2,847 |
/**
* \file
*
* \brief Chip-specific oscillator management functions.
*
* Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.
*
* \asf_license_start
*
* \page License
*
* 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. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an
* Atmel microcontroller product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/
#ifndef CHIP_OSC_H_INCLUDED
#define CHIP_OSC_H_INCLUDED
#include "board.h"
#include "pmc.h"
/// @cond 0
/**INDENT-OFF**/
#ifdef __cplusplus
extern "C" {
#endif
/**INDENT-ON**/
/// @endcond
/**
* \weakgroup osc_group
* @{
*/
//! \name Oscillator identifiers
//@{
#define OSC_SLCK_32K_RC 0 //!< Internal 32kHz RC oscillator.
#define OSC_SLCK_32K_XTAL 1 //!< External 32kHz crystal oscillator.
#define OSC_SLCK_32K_BYPASS 2 //!< External 32kHz bypass oscillator.
#define OSC_MAINCK_8M_RC 3 //!< Internal 8MHz RC oscillator.
#define OSC_MAINCK_16M_RC 4 //!< Internal 16MHz RC oscillator.
#define OSC_MAINCK_24M_RC 5 //!< Internal 24MHz RC oscillator.
#define OSC_MAINCK_XTAL 6 //!< External crystal oscillator.
#define OSC_MAINCK_BYPASS 7 //!< External bypass oscillator.
//@}
//! \name Oscillator clock speed in hertz
//@{
#define OSC_SLCK_32K_RC_HZ CHIP_FREQ_SLCK_RC //!< Internal 32kHz RC oscillator.
#define OSC_SLCK_32K_XTAL_HZ BOARD_FREQ_SLCK_XTAL //!< External 32kHz crystal oscillator.
#define OSC_SLCK_32K_BYPASS_HZ BOARD_FREQ_SLCK_BYPASS //!< External 32kHz bypass oscillator.
#define OSC_MAINCK_8M_RC_HZ CHIP_FREQ_MAINCK_RC_8MHZ //!< Internal 8MHz RC oscillator.
#define OSC_MAINCK_16M_RC_HZ CHIP_FREQ_MAINCK_RC_16MHZ //!< Internal 16MHz RC oscillator.
#define OSC_MAINCK_24M_RC_HZ CHIP_FREQ_MAINCK_RC_24MHZ //!< Internal 24MHz RC oscillator.
#define OSC_MAINCK_XTAL_HZ BOARD_FREQ_MAINCK_XTAL //!< External crystal oscillator.
#define OSC_MAINCK_BYPASS_HZ BOARD_FREQ_MAINCK_BYPASS //!< External bypass oscillator.
//@}
static inline void osc_enable(uint32_t ul_id)
{
switch (ul_id) {
case OSC_SLCK_32K_RC:
break;
case OSC_SLCK_32K_XTAL:
pmc_switch_sclk_to_32kxtal(PMC_OSC_XTAL);
break;
case OSC_SLCK_32K_BYPASS:
pmc_switch_sclk_to_32kxtal(PMC_OSC_BYPASS);
break;
case OSC_MAINCK_8M_RC:
pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_8_MHz);
break;
case OSC_MAINCK_16M_RC:
pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_16_MHz);
break;
case OSC_MAINCK_24M_RC:
pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_24_MHz);
break;
case OSC_MAINCK_XTAL:
pmc_switch_mainck_to_xtal(PMC_OSC_XTAL,
pmc_us_to_moscxtst(BOARD_OSC_STARTUP_US,
OSC_SLCK_32K_RC_HZ));
break;
case OSC_MAINCK_BYPASS:
pmc_switch_mainck_to_xtal(PMC_OSC_BYPASS,
pmc_us_to_moscxtst(BOARD_OSC_STARTUP_US,
OSC_SLCK_32K_RC_HZ));
break;
}
}
static inline void osc_disable(uint32_t ul_id)
{
switch (ul_id) {
case OSC_SLCK_32K_RC:
case OSC_SLCK_32K_XTAL:
case OSC_SLCK_32K_BYPASS:
break;
case OSC_MAINCK_8M_RC:
case OSC_MAINCK_16M_RC:
case OSC_MAINCK_24M_RC:
pmc_osc_disable_fastrc();
break;
case OSC_MAINCK_XTAL:
pmc_osc_disable_xtal(PMC_OSC_XTAL);
break;
case OSC_MAINCK_BYPASS:
pmc_osc_disable_xtal(PMC_OSC_BYPASS);
break;
}
}
static inline bool osc_is_ready(uint32_t ul_id)
{
switch (ul_id) {
case OSC_SLCK_32K_RC:
return 1;
case OSC_SLCK_32K_XTAL:
case OSC_SLCK_32K_BYPASS:
return pmc_osc_is_ready_32kxtal();
case OSC_MAINCK_8M_RC:
case OSC_MAINCK_16M_RC:
case OSC_MAINCK_24M_RC:
case OSC_MAINCK_XTAL:
case OSC_MAINCK_BYPASS:
return pmc_osc_is_ready_mainck();
}
return 0;
}
static inline uint32_t osc_get_rate(uint32_t ul_id)
{
switch (ul_id) {
case OSC_SLCK_32K_RC:
return OSC_SLCK_32K_RC_HZ;
#ifdef BOARD_FREQ_SLCK_XTAL
case OSC_SLCK_32K_XTAL:
return BOARD_FREQ_SLCK_XTAL;
#endif
#ifdef BOARD_FREQ_SLCK_BYPASS
case OSC_SLCK_32K_BYPASS:
return BOARD_FREQ_SLCK_BYPASS;
#endif
case OSC_MAINCK_8M_RC:
return OSC_MAINCK_8M_RC_HZ;
case OSC_MAINCK_16M_RC:
return OSC_MAINCK_16M_RC_HZ;
case OSC_MAINCK_24M_RC:
return OSC_MAINCK_24M_RC_HZ;
#ifdef BOARD_FREQ_MAINCK_XTAL
case OSC_MAINCK_XTAL:
return BOARD_FREQ_MAINCK_XTAL;
#endif
#ifdef BOARD_FREQ_MAINCK_BYPASS
case OSC_MAINCK_BYPASS:
return BOARD_FREQ_MAINCK_BYPASS;
#endif
}
return 0;
}
//! @}
/// @cond 0
/**INDENT-OFF**/
#ifdef __cplusplus
}
#endif
/**INDENT-ON**/
/// @endcond
#endif /* CHIP_OSC_H_INCLUDED */
| YarivCol/mbed-os | targets/TARGET_Atmel/TARGET_SAM_CortexM4/services/clock/samg/osc.h | C | apache-2.0 | 6,843 |
/* filename: main.c */
#include "issp_revision.h"
#ifdef PROJECT_REV_304
/* Copyright 2006-2007, Cypress Semiconductor Corporation.
//
//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 HOLDER 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 CONRTACT, 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.
//
// Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND,EXPRESS OR IMPLIED,
// WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Cypress reserves the right to make changes without further notice to the
// materials described herein. Cypress does not assume any liability arising
// out of the application or use of any product or circuit described herein.
// Cypress does not authorize its products for use as critical components in
// life-support systems where a malfunction or failure may reasonably be
// expected to result in significant injury to the user. The inclusion of
// Cypress product in a life-support systems application implies that the
// manufacturer assumes all risk of such use and in doing so indemnifies
// Cypress against all charges.
//
// Use may be limited by and subject to the applicable Cypress software
// license agreement.
//
//---------------------------------------------------------------------------*/
/* ############################################################################
################### CRITICAL PROJECT CONSTRAINTS ########################
############################################################################
ISSP programming can only occur within a temperature range of 5C to 50C.
- This project is written without temperature compensation and using
programming pulse-widths that match those used by programmers such as the
Mini-Prog and the ISSP Programmer.
This means that the die temperature of the PSoC device cannot be outside
of the above temperature range.
If a wider temperature range is required, contact your Cypress Semi-
conductor FAE or sales person for assistance.
The project can be configured to program devices at 5V or at 3.3V.
- Initialization of the device is different for different voltages. The
initialization is hardcoded and can only be set for one voltage range.
The supported voltages ranges are 3.3V (3.0V to 3.6V) and 5V (4.75V to
5.25V). See the device datasheet for more details. If varying voltage
ranges must be supported, contact your Cypress Semiconductor FAE or sales
person for assistance.
- ISSP programming for the 2.7V range (2.7V to 3.0V) is not supported.
This program does not support programming all PSoC Devices
- It does not support obsoleted PSoC devices. A list of devices that are
not supported is shown here:
CY8C22x13 - not supported
CY8C24x23 - not supported (CY8C24x23A is supported)
CY8C25x43 - not supported
CY8C26x43 - not supported
- It does not suport devices that have not been released for sale at the
time this version was created. If you need to ISSP program a newly released
device, please contact Cypress Semiconductor Applications, your FAE or
sales person for assistance.
The CY8C20x23 devices are not supported at the time of this release.
############################################################################
##########################################################################*/
/* This program uses information found in Cypress Semiconductor application
// notes "Programming - In-System Serial Programming Protocol", AN2026. The
// version of this application note that applies to the specific PSoC that is
// being In-System Serial Programmed should be read and and understood when
// using this program. (http://www.cypress.com)
// This project is included with releases of PSoC Programmer software. It is
// important to confirm that the latest revision of this software is used when
// it is used. The revision of this copy can be found in the Project History
// table below.
*/
/*/////////////////////////////////////////////////////////////////////////////
// PROJECT HISTORY
// date revision author description
// -------- -------- ------ -----------------------------------------------
// 7/23/08 3.04 ptj 1. CPU clock speed set to to 12MHz (default) after
// TSYNC is disabled. Previously, it was being set
// to 3MHz on accident. This affects the following
// mnemonics:
// ID_SETUP_1,
// VERIFY_SETUP,
// ERASE,
// SECURE,
// CHECKSUM_SETUP,
// PROGRAM_AND_VERIFY,
// ID_SETUP_2,
// SYNC_DISABLE
//
// 6/06/08 3.03 ptj 1. The Verify_Setup section can tell when flash
// is fully protected. bTargetStatus[0] shows a
// 01h when flash is "W" Full Protection
// 7/23/08 2. READ-ID-WORD updated to read Revision ID from
// Accumulator A and X, registers T,F0h and T,F3h
//
// 5/30/08 3.02 ptj 1. All vectors work.
// 2. Main function will execute the
// following programming sequence:
// . id setup 1
// . id setup 2
// . erase
// . program and verify
// . verify (although not necessary)
// . secure flash
// . read security
// . checksum
//
// 05/28/08 3.01 ptj TEST CODE - NOT COMPLETE
// 1. The sequence surrounding PROGRAM-AND-VERIFY was
// improved and works according to spec.
// 2. The sequence surroudning VERIFY-SETUP was devel-
// oped and improved.
// 3. TSYNC Enable is used to in a limited way
// 4. Working Vectors: ID-SETUP-1, ID-SETUP-2, ERASE,
// PROGRAM-AND-VERIFY, SECURE, VERIFY-SETUP,
// CHECKSUM-SETUP
// 5. Un-tested Vectors: READ-SECURITY
//
// 05/23/08 3.00 ptj TEST CODE - NOT COMPLETE
// 1. This code is a test platform for the development
// of the Krypton (cy8c20x66) Programming Sequence.
// See 001-15870 rev *A. This code works on "rev B"
// silicon.
// 2. Host is Hydra 29000, Target is Krypton "rev B"
// 3. Added Krypton device support
// 4. TYSNC Enable/Disable is not used.
// 5. Working Vectors: ID-SETUP-1, ID-SETUP-2, ERASE,
// PROGRAM-AND-VERIFY, SECURE
// 6. Non-working Vectors: CHECKSUM-SETUP
// 7. Un-tested Vectors: READ-SECURITY, VERIFY-SETUP
// 8. Other minor (non-SROM) vectors not listed.
//
// 09/23/07 2.11 dkn 1. Added searchable comments for the HSSP app note.
// 2. Added new device vectors.
// 3. Verified write and erase pulsewidths.
// 4. Modified some functions for easier porting to
// other processors.
//
// 09/23/06 2.10 mwl 1. Added #define SECURITY_BYTES_PER_BANK to
// file issp_defs.h. Modified function
// fSecureTargetFlashMain() in issp_routines.c
// to use new #define. Modified function
// fLoadSecurityData() in issp_driver_routines.c
// to accept a bank number. Modified the secure
// data loop in main.c to program multiple banks.
//
// 2. Created function fAccTargetBankChecksum to
// read and add the target bank checksum to the
// referenced accumulator. This allows the
// checksum loop in main.c to function at the
// same level of abstraction as the other
// programming steps. Accordingly, modified the
// checksum loop in main.c. Deleted previous
// function fVerifyTargetChecksum().
//
// 09/08/06 2.00 mwl 1. Array variable abTargetDataOUT was not
// getting intialized anywhere and compiled as a
// one-byte array. Modified issp_driver_routines.c
// line 44 to initialize with TARGET_DATABUFF_LEN.
//
// 2. Function void LoadProgramData(unsigned char
// bBlockNum) in issp_driver_routines.c had only
// one parameter bBlockNum but was being called
// from function main() with two parameters,
// LoadProgramData(bBankCounter, (unsigned char)
// iBlockCounter). Modified function
// LoadProgramData() to accept both parameters,
// and in turn modified InitTargetTestData() to
// accept and use both as well.
//
// 3. Corrected byte set_bank_number[1]
// inissp_vectors.h. Was 0xF2, correct value is
// 0xE2.
//
// 4. Corrected the logic to send the SET_BANK_NUM
// vectors per the AN2026B flow chart.The previous
// code version was sending once per block, but
// should have been once per bank. Removed the
// conditionally-compiled bank setting code blocks
// from the top of fProgramTargetBlock() and
// fVerifyTargetBlock() int issp_routines.c and
// created a conditionally-compiled subroutine in
// that same file called SetBankNumber(). Two
// conditionally-compiled calls to SetBankNumber()
// were added to main.c().
//
// 5. Corrected CY8C29x66 NUM_BANKS and
// BLOCKS_PER_BANK definitions in ISSP_Defs.h.
// Was 2 and 256 respectively, correct values are
// 4 and 128.
//
// 6. Modified function fVerifyTargetChecksum()
// in issp_routines.c to read and accumulate multiple
// banks of checksums as required for targets
// CY8C24x94 and CY8C29x66. Would have kept same
// level of abstraction as other multi-bank functions
// in main.c, but this implementation impacted the
// code the least.
//
// 7. Corrected byte checksum_v[26] of
// CHECKSUM_SETUP_24_29 in issp_vectors.h. Was 0x02,
// correct value is 0x04.
//
// 06/30/06 1.10 jvy Added support for 24x94 and 29x66 devices.
// 06/09/06 1.00 jvy Changed CPU Clk to 12MHz (from 24MHz) so the
// host can run from 3.3V.
// Simplified init of security data.
// 06/05/06 0.06 jvy Version #ifdef added to each file to make sure
// all of the file are from the same revision.
// Added flags to prevent multiple includes of H
// files.
// Changed pre-determined data for demo to be
// unique for each block.
// Changed block verify to check all blocks after
// block programming has been completed.
// Added SetSCLKHiZ to explicitly set the Clk to
// HighZ before power cycle acquire.
// Fixed wrong vectors in setting Security.
// Fixed wrong vectors in Block program.
// Added support for pods
// 06/05/06 0.05 jvy Comments from code review. First copy checked
// into perforce. Code has been updated enough to
// compile, by implementing some comments and
// fixing others.
// 06/04/06 0.04 jvy made code more efficient in bReceiveByte(), and
// SendVector() by re-arranging so that local vars
// could be eliminated.
// added defines for the delays used in the code.
// 06/02/06 0.03 jvy added number of Flash block adjustment to
// programming. added power cycle programming
// mode support. This is the version initially
// sent out for peer review.
// 06/02/06 0.02 jvy added framework for multiple chip support from
// one source code set using compiler directives.
// added timeout to high-low trasition detection.
// added multiple error message to allow tracking
// of failures.
// 05/30/06 0.01 jvy initial version,
// created from DBD's issp_27xxx_v3 program.
/////////////////////////////////////////////////////////////////////////////*/
/* (((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))
PSoC In-System Serial Programming (ISSP) Template
This PSoC Project is designed to be used as a template for designs that
require PSoC ISSP Functions.
This project is based on the AN2026 series of Application Notes. That app
note should be referenced before any modifications to this project are made.
The subroutines and files were created in such a way as to allow easy cut &
paste as needed. There are no customer-specific functions in this project.
This demo of the code utilizes a PSoC as the Host.
Some of the subroutines could be merged, or otherwise reduced, but they have
been written as independently as possible so that the specific steps involved
within each function can easily be seen. By merging things, some code-space
savings could be realized.
As is, and with all features enabled, the project consumes approximately 3500
bytes of code space, and 19-Bytes of RAM (not including stack usage). The
Block-Verify requires a 64-Byte buffer for read-back verification. This same
buffer could be used to hold the (actual) incoming program data.
Please refer to the compiler-directives file "directives.h" to see the various
features.
The pin used in this project are assigned as shown below. The HOST pins are
arbitrary and any 3 pins could be used (the masks used to control the pins
must be changed). The TARGET pins cannot be changed, these are fixed function
pins on the PSoC.
The PWR pin is used to provide power to the target device if power cycle
programming mode is used. The compiler directive RESET_MODE in ISSP_directives.h
is used to select the programming mode. This pin could control the enable on
a voltage regulator, or could control the gate of a FET that is used to turn
the power to the PSoC on.
The TP pin is a Test Point pin that can be used signal from the host processor
that the program has completed certain tasks. Predefined test points are
included that can be used to observe the timing for bulk erasing, block
programming and security programming.
SIGNAL HOST TARGET
---------------------
SDATA P1.7 P1.0
SCLK P1.6 P1.1
XRES P2.0 XRES
PWR P2.3 Vdd
TP P0.7 n/a
For test & demonstration, this project generates the program data internally.
It does not take-in the data from an external source such as I2C, UART, SPI,
etc. However, the program was written in such a way to be portable into such
designs. The spirit of this project was to keep it stripped to the minimum
functions required to do the ISSP functions only, thereby making a portable
framework for integration with other projects.
The high-level functions have been written in C in order to be portable to
other processors. The low-level functions that are processor dependent, such
as toggling pins and implementing specific delays, are all found in the file
ISSP_Drive_Routines.c. These functions must be converted to equivalent
functions for the HOST processor. Care must be taken to meet the timing
requirements when converting to a new processor. ISSP timing information can
be found in Application Note AN2026. All of the sections of this program
that need to be modified for the host processor have "PROCESSOR_SPECIFIC" in
the comments. By performing a "Find in files" using "PROCESSOR_SPECIFIC" these
sections can easily be identified.
The variables in this project use Hungarian notation. Hungarian prepends a
lower case letter to each variable that identifies the variable type. The
prefixes used in this program are defined below:
b = byte length variable, signed char and unsigned char
i = 2-byte length variable, signed int and unsigned int
f = byte length variable used as a flag (TRUE = 0, FALSE != 0)
ab = an array of byte length variables
After this program has been ported to the desired host processor the timing
of the signals must be confirmed. The maximum SCLK frequency must be checked
as well as the timing of the bulk erase, block write and security write
pulses.
The maximum SCLK frequency for the target device can be found in the device
datasheet under AC Programming Specifications with a Symbol of "Fsclk".
An oscilloscope should be used to make sure that no half-cycles (the high
time or the low time) are shorter than the half-period of the maximum
freqency. In other words, if the maximum SCLK frequency is 8MHz, there can be
no high or low pulses shorter than 1/(2*8MHz), or 62.5 nsec.
The test point (TP) functions, enabled by the define USE_TP, provide an output
from the host processor that brackets the timing of the internal bulk erase,
block write and security write programming pulses. An oscilloscope, along with
break points in the PSoC ICE Debugger should be used to verify the timing of
the programming. The Application Note, "Host-Sourced Serial Programming"
explains how to do these measurements and should be consulted for the expected
timing of the erase and program pulses.
############################################################################
############################################################################
(((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))) */
/*----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/sched.h>
#include <linux/pm.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/delay.h>
#include <linux/input.h>
#include <plat/gpio-nomadik.h>
/* #include <mach/regs-gpio.h> */
/* #include <plat/gpio-cfg.h> */
#include <asm/gpio.h>
#include <asm/uaccess.h>
#include <asm/io.h>
/* #include <m8c.h> // part specific constants and macros */
/* #include "PSoCAPI.h" // PSoC API definitions for all User Modules */
/* ------ Declarations Associated with ISSP Files & Routines -------
// Add these to your project as needed. */
#include "issp_extern.h"
#include "issp_directives.h"
#include "issp_defs.h"
#include "issp_errors.h"
#include "u8500-cypress-gpio.h"
/* ------------------------------------------------------------------------- */
unsigned char bBankCounter;
unsigned int iBlockCounter;
unsigned int iChecksumData;
unsigned int iChecksumTarget;
/* update version "eclair/vendor/samsung/apps/Lcdtest/src/com/sec/android/app/lcdtest/touch_firmware.java" */
unsigned char firmware_data0[] = { /* 111226 HW08 SW0B */
0x40, 0x7d, 0x00, 0x68, 0x30, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7d, 0x00, 0x68, 0x7e, 0x7e, 0x30, 0x30, 0x30, 0x7d, 0x04, 0xac, 0x7e, 0x7e, 0x30, 0x30, 0x30, 0x7d, 0x05, 0xf9, 0x7e, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30
, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x40, 0x71, 0x10, 0x62, 0xe3, 0x06, 0x70, 0xef, 0x62, 0xe3, 0x38, 0x50, 0x80, 0x4e, 0x62, 0xe3, 0x38, 0x5d, 0xd5, 0x08, 0x62, 0xd5, 0x00, 0x55
, 0xfa, 0x01, 0x40, 0x4f, 0x5b, 0x01, 0x03, 0x53, 0xf9, 0x55, 0xf8, 0x3a, 0x50, 0x06, 0x00, 0x40, 0x40, 0x71, 0x10, 0x51, 0xfa, 0x60, 0xe8, 0x70, 0xef, 0x18, 0x60, 0xd5, 0x55, 0xf8, 0x00, 0x55, 0xf9, 0x00, 0x71, 0x10, 0x62, 0xe0, 0x1a, 0x70, 0xef, 0x62, 0xe3, 0x38, 0x71, 0x10, 0x41, 0xe1, 0xfe, 0x70, 0xef, 0x62, 0xe3, 0x38, 0x62, 0xd1, 0x03, 0x50, 0x80, 0x4e, 0x62, 0xd3, 0x03, 0x62
, 0xd0, 0x00, 0x62, 0xd5, 0x00, 0x62, 0xd4, 0x00, 0x71, 0xc0, 0x7c, 0x03, 0x19, 0x62, 0xd0, 0x00, 0x50, 0x01, 0x57, 0xc0, 0x08, 0x28, 0x53, 0x5d, 0x18, 0x75, 0x09, 0x00, 0x28, 0x4b, 0x51, 0x5d, 0x80, 0x04, 0x75, 0x09, 0x00, 0x62, 0xe3, 0x00, 0x08, 0x28, 0x60, 0xd5, 0x74, 0xa0, 0x4b, 0x18, 0x75, 0x09, 0x00, 0x08, 0x28, 0x53, 0x5d, 0x18, 0x75, 0x09, 0x00, 0x08, 0x28, 0xa0, 0x1c, 0x53
, 0x5c, 0x18, 0x75, 0x09, 0x00, 0x08, 0x28, 0x3f, 0x5d, 0x47, 0x5d, 0xff, 0xb0, 0x06, 0x5d, 0xd5, 0x74, 0x60, 0xd5, 0x18, 0x7a, 0x5c, 0xbf, 0xeb, 0x8f, 0xc9, 0x18, 0x75, 0x09, 0x00, 0x08, 0x28, 0x53, 0x5c, 0x50, 0x00, 0x3f, 0x5d, 0x47, 0x5d, 0xff, 0xb0, 0x08, 0x5d, 0xd5, 0x74, 0x60, 0xd5, 0x50, 0x00, 0x7a, 0x5c, 0xbf, 0xef, 0x18, 0x8f, 0xaa, 0x18, 0x71, 0x10, 0x43, 0xe3, 0x00, 0x70
, 0xef, 0x62, 0xe0, 0x00, 0x41, 0xfe, 0xe7, 0x43, 0xfe, 0x10, 0x71, 0x10, 0x43, 0xe9, 0x20, 0x62, 0xe0, 0x1a, 0x70, 0xef, 0x62, 0xe2, 0x00, 0x7c, 0x19, 0x80, 0x8f, 0xff, 0x7f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x01, 0x99, 0x03, 0x33, 0x06, 0x66, 0x0c, 0xcc, 0x19, 0x99, 0x33, 0x33, 0x66, 0x66, 0xcc, 0xcc
, 0x01, 0x80, 0x03, 0x00, 0x06, 0x00, 0x0b, 0xff, 0x18, 0x00, 0x2f, 0xff, 0x5f, 0xff, 0xbf, 0xff, 0x01, 0x66, 0x02, 0xcc, 0x05, 0x99, 0x0b, 0x32, 0x16, 0x66, 0x2c, 0xcc, 0x59, 0x98, 0xb3, 0x32, 0x01, 0x4c, 0x02, 0x99, 0x05, 0x33, 0x0a, 0x66, 0x14, 0xcc, 0x29, 0x90, 0x53, 0x33, 0xa6, 0x66, 0x01, 0x33, 0x02, 0x66, 0x04, 0xcc, 0x09, 0x99, 0x13, 0x33, 0x26, 0x65, 0x4c, 0xcc, 0x99, 0x99
, 0x1c, 0x06, 0x70, 0xef, 0x62, 0x61, 0x00, 0x62, 0xfd, 0x00, 0x62, 0xcd, 0x00, 0x62, 0xce, 0x00, 0x62, 0xa5, 0x00, 0x62, 0xa4, 0x00, 0x62, 0xa0, 0x00, 0x62, 0xa1, 0x80, 0x62, 0xa2, 0xc0, 0x62, 0xa3, 0x0c, 0x62, 0xa8, 0x00, 0x62, 0xa6, 0x00, 0x62, 0xa7, 0x00, 0x62, 0x7c, 0x33, 0x62, 0x7a, 0x00, 0x62, 0x7b, 0x00, 0x62, 0x79, 0x00, 0x62, 0x36, 0x00, 0x62, 0x37, 0x00, 0x62, 0x38, 0x00
, 0x62, 0x39, 0x00, 0x62, 0x3a, 0x00, 0x62, 0x3b, 0x00, 0x62, 0x3c, 0x00, 0x62, 0x3d, 0x00, 0x62, 0x3e, 0x00, 0x62, 0x3f, 0x00, 0x62, 0x40, 0x00, 0x62, 0x41, 0x00, 0x62, 0x42, 0x00, 0x62, 0x43, 0x00, 0x62, 0x44, 0x00, 0x62, 0x45, 0x00, 0x62, 0x46, 0x00, 0x62, 0x47, 0x00, 0x62, 0x48, 0x00, 0x62, 0x49, 0x00, 0x62, 0x4a, 0x00, 0x62, 0x4b, 0x00, 0x62, 0x4c, 0x00, 0x62, 0x4d, 0x00, 0x62
, 0x4e, 0x00, 0x62, 0x4f, 0x00, 0x62, 0xca, 0x20, 0x62, 0xd6, 0x44, 0x62, 0xcf, 0x00, 0x62, 0xcb, 0x00, 0x62, 0xc8, 0x00, 0x62, 0xcc, 0x00, 0x62, 0xc9, 0x00, 0x62, 0xd7, 0x00, 0x62, 0xa9, 0x00, 0x62, 0x2b, 0x00, 0x62, 0xb0, 0x00, 0x62, 0xb3, 0x02, 0x62, 0xb6, 0x00, 0x62, 0xb2, 0x00, 0x62, 0xb5, 0x00, 0x62, 0xb8, 0x00, 0x62, 0xb1, 0x00, 0x62, 0xb4, 0x00, 0x62, 0xb7, 0x00, 0x62, 0x33
, 0x00, 0x62, 0x34, 0x00, 0x62, 0x35, 0x00, 0x71, 0x10, 0x62, 0x54, 0x00, 0x62, 0x55, 0x00, 0x62, 0x56, 0x00, 0x62, 0x57, 0x00, 0x62, 0x58, 0x00, 0x62, 0x59, 0x00, 0x62, 0x5a, 0x00, 0x62, 0x5b, 0x00, 0x62, 0xdc, 0x00, 0x62, 0xe2, 0x00, 0x62, 0xdd, 0x00, 0x62, 0xd8, 0x02, 0x62, 0xd9, 0x20, 0x62, 0xda, 0x20, 0x62, 0xdb, 0x00, 0x62, 0xdf, 0x00, 0x62, 0x29, 0x00, 0x62, 0x30, 0x00, 0x62
, 0xbd, 0x00, 0x70, 0xef, 0x70, 0xef, 0x62, 0x00, 0x00, 0x71, 0x10, 0x62, 0x00, 0x08, 0x62, 0x01, 0x92, 0x70, 0xef, 0x62, 0x04, 0x17, 0x71, 0x10, 0x62, 0x04, 0x17, 0x62, 0x05, 0xab, 0x70, 0xef, 0x62, 0x08, 0x00, 0x71, 0x10, 0x62, 0x08, 0x00, 0x62, 0x09, 0x28, 0x70, 0xef, 0x62, 0x0c, 0x00, 0x71, 0x10, 0x62, 0x0c, 0x00, 0x62, 0x0d, 0x00, 0x70, 0xef, 0x62, 0x10, 0x00, 0x71, 0x10, 0x62
, 0x10, 0x00, 0x62, 0x11, 0x00, 0x70, 0xef, 0x62, 0x01, 0x00, 0x62, 0x05, 0x00, 0x62, 0x09, 0x00, 0x62, 0x0d, 0x00, 0x62, 0x11, 0x00, 0x70, 0xef, 0x7f, 0x55, 0x02, 0x00, 0x55, 0x03, 0x17, 0x55, 0x04, 0x00, 0x7c, 0x03, 0x26, 0x7f, 0x7c, 0x01, 0xc2, 0x70, 0xef, 0x7f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x62, 0xd0, 0x00, 0x53
, 0x00, 0x71, 0x10, 0x5d, 0xe0, 0x08, 0x21, 0xf8, 0x29, 0x00, 0x70, 0xfe, 0x60, 0xe0, 0x70, 0xef, 0x4b, 0x4b, 0x4b, 0x4b, 0x51, 0x02, 0x21, 0xf7, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08
, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05
, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x47, 0x00, 0x00, 0x49, 0x01, 0x00, 0x29, 0x08, 0x60, 0x00, 0x57, 0x01, 0x79, 0xbf, 0xfe, 0x18, 0x71, 0x10, 0x60, 0xe0, 0x70, 0xef, 0x71, 0x01, 0x7f, 0x08, 0x67, 0x67, 0x67, 0x67, 0x21, 0x0f, 0xff, 0x40, 0x9f, 0x4e, 0x18, 0x21, 0x0f, 0xff, 0x39, 0x9f, 0x47, 0x7f, 0x08, 0x10, 0x28, 0xa0, 0x0b, 0x9f, 0x3f, 0x20, 0x18, 0x75
, 0xdf, 0xf5, 0x74, 0x8f, 0xf2, 0x38, 0xfe, 0x7f, 0x52, 0x00, 0xa0, 0x08, 0x10, 0x9f, 0x2d, 0x20, 0x75, 0x8f, 0xf6, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x50, 0x0d, 0x9f, 0x20, 0x50, 0x0a, 0x9f, 0x1c, 0x7f, 0x70, 0xbf, 0x62, 0xd3, 0x03, 0x4f, 0x52, 0xfb, 0xa0, 0x15, 0x7b, 0xfb, 0x52, 0xfc, 0x59, 0xfd, 0x60, 0xd3, 0x52, 0x00, 0x9f, 0x05, 0x4f, 0x62, 0xd3, 0x03, 0x77, 0xfd, 0x8f, 0xe9, 0x70
, 0x3f, 0x71, 0xc0, 0x7f, 0x3d, 0xfa, 0x00, 0xb0, 0x06, 0x3d, 0xfb, 0x00, 0xa0, 0x18, 0x10, 0x52, 0xfc, 0x59, 0xfd, 0x28, 0x9e, 0xe6, 0x20, 0x07, 0xfd, 0x01, 0x0f, 0xfc, 0x00, 0x17, 0xfb, 0x01, 0x1f, 0xfa, 0x00, 0x8f, 0xe0, 0x7f, 0x50, 0x01, 0x80, 0x03, 0x50, 0x00, 0x62, 0xd0, 0x00, 0x29, 0x00, 0xa0, 0x06, 0x26, 0x03, 0xfb, 0x80, 0x04, 0x2e, 0x03, 0x04, 0x51, 0x03, 0x60, 0x04, 0x70
, 0x3f, 0x71, 0xc0, 0x7f, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x50, 0x01, 0x80, 0x03, 0x50, 0x00, 0x62, 0xd0, 0x00, 0x29, 0x00, 0xa0, 0x06, 0x26, 0x03, 0xef, 0x80, 0x04, 0x2e, 0x03, 0x10, 0x51, 0x03, 0x60, 0x04, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x08, 0x10, 0x70, 0x3f, 0x71, 0x80, 0x5d, 0xd3, 0x08, 0x5d, 0xd0, 0x08, 0x62, 0xd0, 0x00, 0x51, 0x08, 0x60, 0xd3, 0x2e
, 0x05, 0x80, 0x49, 0xd7, 0x08, 0xa0, 0x09, 0x26, 0x05, 0xf0, 0x2e, 0x05, 0x00, 0x80, 0x08, 0x49, 0xd7, 0x20, 0xa0, 0x03, 0x80, 0xa6, 0x51, 0x05, 0x21, 0x0e, 0xe0, 0x01, 0x80, 0x11, 0x80, 0x67, 0x80, 0x79, 0x80, 0x47, 0x80, 0x96, 0x80, 0x94, 0x80, 0x92, 0x80, 0x90, 0x80, 0x97, 0x5d, 0xd8, 0x21, 0xfe, 0x39, 0x40, 0xa0, 0x06, 0x62, 0xd7, 0x00, 0x80, 0x8a, 0x49, 0xd8, 0x01, 0xb0, 0x0f
, 0x55, 0x0c, 0x02, 0x26, 0x05, 0xf0, 0x2e, 0x05, 0x02, 0x62, 0xd7, 0x10, 0x80, 0x77, 0x55, 0x0c, 0x01, 0x26, 0x05, 0xf0, 0x2e, 0x05, 0x06, 0x5f, 0x07, 0x06, 0x51, 0x09, 0x02, 0x07, 0x5c, 0x52, 0x00, 0x60, 0xd8, 0x76, 0x07, 0x62, 0xd7, 0x14, 0x80, 0x5b, 0x51, 0x0a, 0x78, 0x3a, 0x07, 0xc0, 0x0f, 0x51, 0x09, 0x02, 0x07, 0x5c, 0x52, 0x00, 0x60, 0xd8, 0x76, 0x07, 0x2e, 0x05, 0x20, 0x60
, 0xd8, 0x62, 0xd7, 0x04, 0x80, 0x3f, 0x5d, 0xd8, 0x3a, 0x0a, 0xd0, 0x2b, 0xa0, 0x29, 0x53, 0x07, 0x53, 0x06, 0x26, 0x05, 0xf0, 0x2e, 0x05, 0x04, 0x80, 0x18, 0x51, 0x0b, 0x78, 0x3a, 0x07, 0xc0, 0x16, 0x51, 0x09, 0x02, 0x07, 0x5c, 0x5d, 0xd8, 0x54, 0x00, 0x2e, 0x05, 0x10, 0x76, 0x07, 0x80, 0x01, 0x62, 0xd7, 0x10, 0x80, 0x0f, 0x62, 0xd7, 0x00, 0x80, 0x0a, 0x26, 0x05, 0xf0, 0x2e, 0x05
, 0x00, 0x55, 0x0c, 0x00, 0x18, 0x60, 0xd0, 0x18, 0x60, 0xd3, 0x20, 0x18, 0x7e, 0x62, 0xd0, 0x00, 0x71, 0x10, 0x41, 0x04, 0xfc, 0x43, 0x05, 0x03, 0x70, 0xef, 0x26, 0x03, 0xfc, 0x51, 0x03, 0x60, 0x04, 0x55, 0x0c, 0x00, 0x90, 0x28, 0x90, 0x2d, 0x40, 0x40, 0x40, 0x40, 0x40, 0x50, 0x00, 0x53, 0x06, 0x71, 0x10, 0x43, 0x04, 0x03, 0x43, 0x05, 0x03, 0x70, 0xef, 0x2e, 0x03, 0x03, 0x51, 0x03
, 0x60, 0x04, 0x7f, 0x62, 0xd0, 0x00, 0x51, 0x05, 0x21, 0xb0, 0x26, 0x05, 0x4f, 0x7f, 0x41, 0xe0, 0x7f, 0x43, 0xe0, 0x80, 0x7f, 0x43, 0xd6, 0x31, 0x7f, 0x41, 0xe0, 0x7f, 0x41, 0xd6, 0xfe, 0x7f, 0x62, 0xd0, 0x00, 0x4f, 0x52, 0xfd, 0x53, 0x0a, 0x52, 0xfc, 0x53, 0x0b, 0x52, 0xfb, 0x53, 0x09, 0x52, 0xfa, 0x53, 0x08, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x08, 0x5d, 0xa4, 0x04, 0x1b, 0x5d, 0xa5
, 0x0c, 0x1a, 0x55, 0x1c, 0x01, 0x18, 0x7e, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x70, 0xbf, 0x53, 0x1e, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x98, 0x62, 0xd3, 0x00, 0x13, 0x90, 0x62, 0xd3, 0x00, 0x54, 0x94, 0x62, 0xd3, 0x00, 0x52, 0x97, 0x62, 0xd3, 0x00, 0x1b, 0x8f, 0x62, 0xd3, 0x00, 0x54, 0x93, 0x48, 0x93, 0x80, 0xb0, 0x33, 0x3d, 0x93, 0x00, 0xb0, 0x7b, 0x51, 0x0d, 0x3b, 0x94, 0xc0, 0x75
, 0x52, 0x94, 0x58, 0x1e, 0x01, 0x00, 0x6d, 0x62, 0xd3, 0x00, 0x05, 0x5e, 0xc0, 0x09, 0x51, 0x0f, 0x3b, 0x5e, 0xd0, 0x12, 0xa0, 0x10, 0x56, 0x5e, 0x00, 0x5b, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x07, 0x90, 0x01, 0x0f, 0x8f, 0x00, 0x80, 0x41, 0x3d, 0x93, 0xff, 0xb0, 0x09, 0x50, 0xff, 0x12, 0x0e, 0x3b, 0x94, 0xc0, 0x20, 0x62, 0xd3, 0x00, 0x56, 0x94, 0x00, 0x56, 0x93, 0x00, 0x5b, 0x67, 0x5c
, 0x62, 0xd3, 0x00, 0x52, 0x65, 0x78, 0xd0, 0x03, 0x50, 0x00, 0x54, 0x65, 0x08, 0x5b, 0x64, 0x5c, 0x18, 0xb0, 0x2c, 0x62, 0xd3, 0x00, 0x52, 0x98, 0x62, 0xd3, 0x00, 0x54, 0x90, 0x62, 0xd3, 0x00, 0x52, 0x97, 0x62, 0xd3, 0x00, 0x54, 0x8f, 0x51, 0x1e, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x56, 0x94, 0x00, 0x56, 0x93, 0x00, 0x5b, 0x67, 0x5c, 0x62, 0xd3, 0x00, 0x51, 0x12, 0x54, 0x65, 0x70, 0x3f
, 0x71, 0xc0, 0x7f, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x70, 0xbf, 0x08, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x60, 0x53, 0x19, 0x55, 0x18, 0x00, 0x18, 0x08, 0x90, 0x7e, 0x62, 0xd3, 0x00, 0x23, 0x62, 0xb0, 0x2c, 0x51, 0x10, 0x04, 0x19, 0x0e, 0x18, 0x00, 0x18, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x94, 0x12, 0x19, 0x52, 0x93, 0x1a, 0x18, 0xc0, 0x39, 0x5b, 0x67, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x63
, 0x78, 0x54, 0x63, 0x08, 0x5b, 0x64, 0x5c, 0x18, 0xb0, 0x3e, 0x80, 0x18, 0x51, 0x10, 0x14, 0x19, 0x1e, 0x18, 0x00, 0x18, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x94, 0x12, 0x19, 0x52, 0x93, 0x1a, 0x18, 0xc0, 0x0e, 0x5b, 0x67, 0x90, 0x31, 0x62, 0xd3, 0x00, 0x2d, 0x62, 0x50, 0x01, 0x80, 0x24, 0x5b, 0x67, 0x08, 0x90, 0x23, 0x73, 0x62, 0xd3, 0x00, 0x25, 0x62, 0x62, 0xd3, 0x00, 0x20, 0x51
, 0x11, 0x54, 0x63, 0x50, 0x00, 0x80, 0x0d, 0x5b, 0x67, 0x90, 0x0d, 0x73, 0x62, 0xd3, 0x00, 0x25, 0x62, 0x50, 0x00, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x08, 0x67, 0x67, 0x67, 0x5c, 0x18, 0x21, 0x07, 0xf0, 0x01, 0x7f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x70, 0xbf, 0x70, 0xbf, 0x62, 0xd3, 0x00, 0x50, 0x02, 0x78, 0x08, 0x5c, 0x56, 0x60, 0x28, 0x18, 0x78, 0xdf, 0xf8, 0x70, 0x3f
, 0x71, 0xc0, 0x7f, 0x08, 0x91, 0xaf, 0x70, 0xbf, 0x18, 0x08, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x98, 0x62, 0xd3, 0x00, 0x54, 0x90, 0x62, 0xd3, 0x00, 0x52, 0x97, 0x62, 0xd3, 0x00, 0x54, 0x8f, 0x18, 0x78, 0xdf, 0xe0, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x62, 0xd0, 0x00, 0x55, 0x14, 0x00, 0x50, 0x02, 0x78, 0x08, 0x9f, 0x0e, 0x39, 0x01, 0xb0, 0x04, 0x55, 0x14, 0x01, 0x18, 0x78, 0xdf, 0xf3
, 0x51, 0x14, 0x7f, 0x08, 0x9e, 0x41, 0x18, 0x78, 0xdf, 0xfa, 0x7f, 0x98, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0xd8, 0xd9, 0xda, 0xdb, 0xdf, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x62, 0xd3, 0x00, 0x57, 0x00, 0x56, 0x62, 0x00, 0x79, 0xdf, 0xfb, 0x62, 0xd3, 0x00, 0x57, 0x01, 0x50, 0x03, 0x54, 0x63, 0x79, 0xdf, 0xfc, 0x62, 0xd3
, 0x00, 0x50, 0x14, 0x57, 0x01, 0x54, 0x65, 0x79, 0xdf, 0xfc, 0x70, 0x3f, 0x71, 0xc0, 0x55, 0x0d, 0x14, 0x55, 0x0e, 0x05, 0x55, 0x0f, 0x14, 0x55, 0x10, 0x01, 0x55, 0x11, 0x03, 0x55, 0x12, 0x14, 0x55, 0x22, 0x04, 0x55, 0x1f, 0x14, 0x43, 0x61, 0x0d, 0x57, 0x00, 0x50, 0x02, 0x90, 0xae, 0x50, 0x04, 0xff, 0x98, 0x29, 0x00, 0x60, 0xa9, 0x62, 0xa0, 0x08, 0x43, 0xa2, 0x04, 0x62, 0xa3, 0x70
, 0x43, 0x7a, 0x01, 0x43, 0xaa, 0x02, 0x43, 0xdf, 0x01, 0x50, 0x01, 0x57, 0x09, 0x90, 0x20, 0x90, 0x55, 0x57, 0x01, 0x50, 0xb3, 0x91, 0x5d, 0x50, 0x00, 0x57, 0x0d, 0x90, 0x12, 0x90, 0x47, 0x7f, 0x53, 0x22, 0xff, 0x67, 0x29, 0x00, 0x60, 0xa9, 0x51, 0x21, 0x58, 0x20, 0x90, 0x01, 0x7f, 0x62, 0xd0, 0x00, 0x21, 0x03, 0x53, 0x21, 0x64, 0x64, 0x64, 0x64, 0x64, 0x29, 0x80, 0x60, 0xa1, 0x5b
, 0x78, 0x21, 0x0f, 0x29, 0x08, 0x74, 0x53, 0x20, 0x12, 0x22, 0x02, 0x21, 0x5c, 0x50, 0x00, 0x53, 0x1d, 0x53, 0x23, 0x29, 0x01, 0x79, 0xa0, 0x08, 0x64, 0x6b, 0x1d, 0x6b, 0x23, 0x8f, 0xf5, 0x60, 0xb5, 0x51, 0x1d, 0x60, 0xb4, 0x7f, 0x50, 0x02, 0x78, 0x08, 0x90, 0x28, 0x90, 0x5a, 0x18, 0x78, 0xdf, 0xf8, 0x7f, 0x41, 0xdf, 0xfe, 0x71, 0x10, 0x41, 0xd8, 0xfd, 0x70, 0xef, 0x41, 0x61, 0xf3
, 0x41, 0xa2, 0xfb, 0x41, 0xa0, 0xf7, 0x62, 0xa3, 0x00, 0x62, 0xa9, 0x00, 0x41, 0xaa, 0xfd, 0x7f, 0x01, 0x20, 0x02, 0x20, 0x64, 0x5c, 0xff, 0xf8, 0x4b, 0x74, 0xff, 0xf4, 0x7f, 0x62, 0xd0, 0x00, 0x53, 0x1d, 0x10, 0x5b, 0x64, 0x64, 0x5c, 0x71, 0x10, 0x5e, 0x01, 0x2a, 0x1d, 0x61, 0x01, 0x36, 0x1d, 0xff, 0x5e, 0x00, 0x22, 0x1d, 0x61, 0x00, 0x36, 0x1d, 0xff, 0x18, 0xfe, 0xd6, 0x5c, 0x5e
, 0x00, 0x2a, 0x1d, 0x61, 0x00, 0x70, 0xef, 0x7f, 0x62, 0xd0, 0x00, 0x10, 0x73, 0x53, 0x1d, 0x71, 0x10, 0x5b, 0xfe, 0xc0, 0x5c, 0x5e, 0x00, 0x22, 0x1d, 0x61, 0x00, 0x70, 0xef, 0x18, 0x64, 0x64, 0x5c, 0x71, 0x10, 0x5e, 0x01, 0x22, 0x1d, 0x61, 0x01, 0x36, 0x1d, 0xff, 0x5e, 0x00, 0x2a, 0x1d, 0x61, 0x00, 0x70, 0xef, 0x7f, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x53, 0x1e, 0x50, 0x00, 0x53, 0x1a
, 0x53, 0x1b, 0x51, 0x1e, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x24, 0x53, 0x1f, 0x43, 0xa0, 0x01, 0x51, 0x1f, 0x60, 0xfd, 0x41, 0xa3, 0xdf, 0x51, 0x1e, 0x9f, 0x7a, 0x9f, 0x81, 0x58, 0x23, 0x55, 0x1c, 0x00, 0x62, 0xa5, 0x00, 0x62, 0xa4, 0x00, 0x43, 0xb3, 0x01, 0x51, 0x1c, 0xaf, 0xfd, 0x79, 0xdf, 0xee, 0x51, 0x1e, 0x9f, 0x5f, 0x9f, 0x91, 0x43, 0xa3, 0x20, 0x41, 0xa0, 0xfe, 0x62, 0xfd, 0x00
, 0x50, 0xff, 0x4c, 0x1b, 0x14, 0x1b, 0x51, 0x20, 0x11, 0x08, 0xfe, 0x4d, 0x4c, 0x1a, 0x1c, 0x1a, 0xd0, 0x07, 0x55, 0x1a, 0x00, 0x55, 0x1b, 0x00, 0x51, 0x1e, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x51, 0x1b, 0x54, 0x98, 0x51, 0x1a, 0x54, 0x97, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x08, 0x9f, 0x86, 0x18, 0x78, 0xdf, 0xfa, 0x7f, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x53, 0x27, 0x5a, 0x26, 0x55, 0x1e, 0x01
, 0x62, 0xd3, 0x00, 0x58, 0x1e, 0x56, 0x24, 0x80, 0x55, 0x29, 0x08, 0x55, 0x28, 0x80, 0x51, 0x1e, 0x9f, 0x63, 0x51, 0x1e, 0x9f, 0x5f, 0x70, 0xbf, 0x58, 0x1e, 0x62, 0xd3, 0x00, 0x51, 0x1b, 0x3a, 0x27, 0x51, 0x1a, 0x1a, 0x26, 0xd0, 0x06, 0x51, 0x28, 0x73, 0x25, 0x24, 0x68, 0x28, 0x26, 0x28, 0x7f, 0x51, 0x28, 0x2d, 0x24, 0x7a, 0x29, 0xbf, 0xd6, 0x7a, 0x1e, 0xdf, 0xc4, 0x70, 0x3f, 0x71
, 0xc0, 0x7f, 0x62, 0xd0, 0x00, 0x3c, 0xb4, 0x01, 0xb0, 0x29, 0x51, 0xae, 0x11, 0xfd, 0x51, 0xad, 0x19, 0x02, 0xd0, 0x12, 0x7c, 0x14, 0xdd, 0x39, 0x0f, 0xa0, 0x41, 0x62, 0xd0, 0x00, 0x76, 0xae, 0x0e, 0xad, 0x00, 0x80, 0x37, 0x62, 0xd0, 0x00, 0x55, 0xae, 0x00, 0x55, 0xad, 0x00, 0x90, 0xe1, 0x80, 0x2a, 0x62, 0xd0, 0x00, 0x51, 0xae, 0x11, 0xca, 0x51, 0xad, 0x19, 0x08, 0xd0, 0x12, 0x7c
, 0x14, 0xdd, 0x39, 0x0f, 0xa0, 0x16, 0x62, 0xd0, 0x00, 0x76, 0xae, 0x0e, 0xad, 0x00, 0x80, 0x0c, 0x62, 0xd0, 0x00, 0x55, 0xae, 0x00, 0x55, 0xad, 0x00, 0x90, 0xb6, 0x7f, 0x62, 0xd0, 0x00, 0x3c, 0xb4, 0x01, 0xb0, 0x06, 0x55, 0xb6, 0x05, 0x80, 0x07, 0x62, 0xd0, 0x00, 0x55, 0xb6, 0x03, 0x62, 0xd0, 0x00, 0x3c, 0xb3, 0xf0, 0xd0, 0x03, 0x76, 0xb3, 0x62, 0xd0, 0x00, 0x51, 0x2f, 0x21, 0x7f
, 0x53, 0x5d, 0x51, 0xb3, 0x3a, 0x5d, 0xb0, 0x4a, 0x7c, 0x14, 0xdd, 0x62, 0xd0, 0x00, 0x53, 0xbc, 0x3c, 0xbc, 0x0f, 0xa0, 0x37, 0x3c, 0xba, 0x00, 0xb0, 0x1c, 0x55, 0xa3, 0x00, 0x55, 0xa4, 0x00, 0x51, 0xbc, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x06, 0x5c, 0xa3, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60, 0xd5, 0x50, 0x08, 0x3f, 0x5c, 0x62, 0xd0, 0x00, 0x55, 0xb7, 0x00, 0x3c, 0xb2, 0x00, 0xb0, 0x12
, 0x7c, 0x15, 0x7a, 0x62, 0xd0, 0x00, 0x55, 0xb2, 0x01, 0x80, 0x07, 0x62, 0xd0, 0x00, 0x55, 0xb3, 0x00, 0x7f, 0x62, 0xd0, 0x00, 0x55, 0xae, 0x00, 0x55, 0xad, 0x00, 0x3c, 0xb2, 0x01, 0xb0, 0x31, 0x7a, 0xb6, 0x3c, 0xb6, 0x00, 0xb0, 0x2a, 0x3c, 0xb2, 0x01, 0xb0, 0x0a, 0x7c, 0x16, 0x11, 0x62, 0xd0, 0x00, 0x55, 0xb2, 0x00, 0x62, 0xd0, 0x00, 0x3c, 0xba, 0x00, 0xb0, 0x0e, 0x51, 0xbc, 0x53
, 0x5c, 0x55, 0x5d, 0x00, 0x06, 0x5c, 0xa3, 0x7c, 0x1b, 0xfa, 0x62, 0xd0, 0x00, 0x55, 0xb3, 0x00, 0x7f, 0x10, 0x4f, 0x38, 0x16, 0x62, 0xd0, 0x00, 0x3c, 0xb9, 0x00, 0xb0, 0x05, 0x51, 0xa7, 0x53, 0x24, 0x56, 0x0d, 0x00, 0x80, 0x96, 0x56, 0x00, 0x00, 0x80, 0x8a, 0x62, 0xd0, 0x00, 0x3c, 0xb9, 0x00, 0xb0, 0x1b, 0x52, 0x00, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x06, 0x5c, 0xa7, 0x7c, 0x1a, 0xa4
, 0x52, 0x00, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x06, 0x5a, 0x24, 0x7c, 0x1b, 0x87, 0x10, 0x52, 0x00, 0x7c, 0x09, 0x35, 0x20, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0, 0x00, 0x20, 0x39, 0x00, 0xbf, 0xee, 0x52, 0x00, 0x7c, 0x1a, 0x27, 0x7c, 0x1a, 0xc8, 0x70, 0xfb, 0x6e, 0x5b, 0x6e, 0x5a, 0x06, 0x5c, 0x6f, 0x0e, 0x5d, 0x00, 0x7c, 0x1a, 0xb0, 0x52, 0x00, 0x7c, 0x1a, 0x27, 0x53, 0x5b, 0x06, 0x5c
, 0x6f, 0x7c, 0x1a, 0xa4, 0x7c, 0x1b, 0x27, 0x7c, 0x1a, 0x3b, 0x52, 0x0d, 0x7c, 0x1b, 0xee, 0x02, 0x5c, 0x53, 0x5c, 0x51, 0x5b, 0x0a, 0x5d, 0x53, 0x5d, 0x52, 0x00, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x65, 0x5a, 0x6b, 0x5b, 0x06, 0x5a, 0x97, 0x0e, 0x5b, 0x00, 0x51, 0x5b, 0x7c, 0x1a, 0xc8, 0x7c, 0x1a, 0xb0, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xcf, 0x73, 0x77, 0x0d, 0x3d, 0x0d, 0x03, 0xcf, 0x67
, 0x56, 0x00, 0x00, 0x81, 0x04, 0x62, 0xd0, 0x00, 0x7c, 0x1a, 0x3b, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x54, 0x0e, 0x3e, 0x5c, 0x54, 0x0f, 0x52, 0x00, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x55, 0x5a, 0x06, 0x55, 0x5b, 0x00, 0x55, 0x55, 0x00, 0x55, 0x54, 0x00, 0x3c, 0x5b, 0x00, 0xb0, 0x06, 0x3c, 0x5a, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e, 0x5b, 0x6e, 0x5a, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51
, 0x5c, 0x04, 0x55, 0x51, 0x5d, 0x0c, 0x54, 0x65, 0x5c, 0x6b, 0x5d, 0x8f, 0xde, 0x5f, 0x5c, 0x55, 0x5f, 0x5d, 0x54, 0x62, 0xd0, 0x00, 0x5a, 0x5a, 0x06, 0x5a, 0x03, 0x51, 0x5a, 0x04, 0x5c, 0x0e, 0x5d, 0x03, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x54, 0x10, 0x3e, 0x5c, 0x54, 0x11, 0x52, 0x00, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x55, 0x5a, 0x06, 0x55, 0x5b, 0x00, 0x55, 0x55, 0x00, 0x55, 0x54
, 0x00, 0x3c, 0x5b, 0x00, 0xb0, 0x06, 0x3c, 0x5a, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e, 0x5b, 0x6e, 0x5a, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x5c, 0x04, 0x55, 0x51, 0x5d, 0x0c, 0x54, 0x65, 0x5c, 0x6b, 0x5d, 0x8f, 0xde, 0x5f, 0x5c, 0x55, 0x5f, 0x5d, 0x54, 0x62, 0xd0, 0x00, 0x5a, 0x5a, 0x06, 0x5a, 0x05, 0x51, 0x5a, 0x04, 0x5c, 0x0e, 0x5d, 0x03, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x54
, 0x12, 0x3e, 0x5c, 0x54, 0x13, 0x50, 0x03, 0x08, 0x5a, 0x5c, 0x06, 0x5c, 0x0e, 0x08, 0x51, 0x5c, 0x08, 0x7c, 0x18, 0xb7, 0x38, 0xfd, 0x62, 0xd0, 0x00, 0x51, 0x5c, 0x54, 0x15, 0x51, 0x5d, 0x54, 0x14, 0x52, 0x00, 0x7c, 0x1a, 0x27, 0x7c, 0x1b, 0x93, 0x06, 0x5c, 0x8f, 0x7c, 0x1b, 0xa9, 0x7c, 0x1a, 0xe9, 0x51, 0x5c, 0x01, 0x77, 0x7c, 0x1b, 0x4f, 0x51, 0x5c, 0x01, 0x7f, 0x7c, 0x1b, 0x4f
, 0x06, 0x5c, 0x87, 0x7c, 0x1b, 0xa9, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xce, 0xf9, 0x38, 0xea, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x16, 0x10, 0x57, 0x09, 0x50, 0x01, 0x7c, 0x08, 0x6f, 0x20, 0x62, 0xd0, 0x00, 0x50, 0x01, 0x10, 0x08, 0x57, 0xb0, 0x28, 0x53, 0x5d, 0x18, 0x75, 0x09, 0x00, 0x28, 0x53, 0x5c, 0x20, 0x10, 0x51, 0x5d, 0x08, 0x51, 0x5c, 0x20, 0x7c, 0x09, 0xb4, 0x20, 0x10, 0x57, 0x0d
, 0x50, 0x00, 0x7c, 0x08, 0x6f, 0x20, 0x62, 0xd0, 0x00, 0x3c, 0xb9, 0x01, 0xb0, 0x0b, 0x51, 0x24, 0x53, 0x30, 0x51, 0x25, 0x53, 0x31, 0x80, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0xa7, 0x53, 0x24, 0x51, 0xa8, 0x53, 0x25, 0x10, 0x50, 0x00, 0x7c, 0x09, 0x35, 0x20, 0x56, 0x0d, 0x00, 0x80, 0x96, 0x56, 0x00, 0x00, 0x80, 0x8a, 0x62, 0xd0, 0x00, 0x3c, 0xb9, 0x00, 0xb0, 0x1b, 0x52, 0x00, 0x53, 0x5c
, 0x55, 0x5d, 0x00, 0x06, 0x5c, 0xa7, 0x7c, 0x1a, 0xa4, 0x52, 0x00, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x06, 0x5a, 0x24, 0x7c, 0x1b, 0x87, 0x10, 0x52, 0x00, 0x7c, 0x09, 0x35, 0x20, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0, 0x00, 0x20, 0x39, 0x00, 0xbf, 0xee, 0x52, 0x00, 0x7c, 0x1a, 0x27, 0x7c, 0x1a, 0xc8, 0x70, 0xfb, 0x6e, 0x5b, 0x6e, 0x5a, 0x06, 0x5c, 0x6f, 0x0e, 0x5d, 0x00, 0x7c, 0x1a, 0xb0
, 0x52, 0x00, 0x7c, 0x1a, 0x27, 0x53, 0x5b, 0x06, 0x5c, 0x6f, 0x7c, 0x1a, 0xa4, 0x7c, 0x1b, 0x27, 0x7c, 0x1a, 0x3b, 0x52, 0x0d, 0x7c, 0x1b, 0xee, 0x02, 0x5c, 0x53, 0x5c, 0x51, 0x5b, 0x0a, 0x5d, 0x53, 0x5d, 0x52, 0x00, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x65, 0x5a, 0x6b, 0x5b, 0x06, 0x5a, 0x97, 0x0e, 0x5b, 0x00, 0x51, 0x5b, 0x7c, 0x1a, 0xc8, 0x7c, 0x1a, 0xb0, 0x77, 0x00, 0x3d, 0x00, 0x02
, 0xcf, 0x73, 0x77, 0x0d, 0x3d, 0x0d, 0x03, 0xcf, 0x67, 0x56, 0x00, 0x00, 0x81, 0x04, 0x62, 0xd0, 0x00, 0x7c, 0x1a, 0x3b, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x54, 0x0e, 0x3e, 0x5c, 0x54, 0x0f, 0x52, 0x00, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x55, 0x5a, 0x06, 0x55, 0x5b, 0x00, 0x55, 0x55, 0x00, 0x55, 0x54, 0x00, 0x3c, 0x5b, 0x00, 0xb0, 0x06, 0x3c, 0x5a, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e
, 0x5b, 0x6e, 0x5a, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x5c, 0x04, 0x55, 0x51, 0x5d, 0x0c, 0x54, 0x65, 0x5c, 0x6b, 0x5d, 0x8f, 0xde, 0x5f, 0x5c, 0x55, 0x5f, 0x5d, 0x54, 0x62, 0xd0, 0x00, 0x5a, 0x5a, 0x06, 0x5a, 0x03, 0x51, 0x5a, 0x04, 0x5c, 0x0e, 0x5d, 0x03, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x54, 0x10, 0x3e, 0x5c, 0x54, 0x11, 0x52, 0x00, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x55, 0x5a
, 0x06, 0x55, 0x5b, 0x00, 0x55, 0x55, 0x00, 0x55, 0x54, 0x00, 0x3c, 0x5b, 0x00, 0xb0, 0x06, 0x3c, 0x5a, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e, 0x5b, 0x6e, 0x5a, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x5c, 0x04, 0x55, 0x51, 0x5d, 0x0c, 0x54, 0x65, 0x5c, 0x6b, 0x5d, 0x8f, 0xde, 0x5f, 0x5c, 0x55, 0x5f, 0x5d, 0x54, 0x62, 0xd0, 0x00, 0x5a, 0x5a, 0x06, 0x5a, 0x05, 0x51, 0x5a, 0x04, 0x5c, 0x0e
, 0x5d, 0x03, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x54, 0x12, 0x3e, 0x5c, 0x54, 0x13, 0x50, 0x03, 0x08, 0x5a, 0x5c, 0x06, 0x5c, 0x0e, 0x08, 0x51, 0x5c, 0x08, 0x7c, 0x18, 0xb7, 0x38, 0xfd, 0x62, 0xd0, 0x00, 0x51, 0x5c, 0x54, 0x15, 0x51, 0x5d, 0x54, 0x14, 0x52, 0x00, 0x7c, 0x1a, 0x27, 0x7c, 0x1b, 0x93, 0x06, 0x5c, 0x8f, 0x7c, 0x1b, 0xa9, 0x7c, 0x1a, 0xe9, 0x51, 0x5c, 0x01, 0x77, 0x7c
, 0x1b, 0x4f, 0x51, 0x5c, 0x01, 0x7f, 0x7c, 0x1b, 0x4f, 0x06, 0x5c, 0x87, 0x7c, 0x1b, 0xa9, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xce, 0xf9, 0x56, 0x00, 0x00, 0x80, 0x19, 0x7c, 0x1b, 0x1c, 0x06, 0x5c, 0x24, 0x7c, 0x1a, 0xa4, 0x52, 0x00, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x06, 0x5a, 0x30, 0x7c, 0x1b, 0x87, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xcf, 0xe4, 0x38, 0xea, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x02
, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x01, 0x02, 0x53, 0x5c, 0x52, 0xfb, 0x09, 0x00, 0x7c, 0x1a, 0xd3, 0x52, 0xfc, 0x01, 0x04, 0x53, 0x5a, 0x52, 0xfb, 0x7c, 0x1a, 0xbd, 0x12, 0x5c, 0x51, 0x5b, 0x1a, 0x5d, 0xc0, 0x64, 0x52, 0xfc, 0x53, 0x5c, 0x52, 0xfb, 0x7c, 0x1a, 0xd3, 0x52, 0xfc, 0x01, 0x02, 0x53, 0x5a, 0x52, 0xfb, 0x7c, 0x1a, 0xbd, 0x12, 0x5c, 0x51, 0x5b, 0x1a, 0x5d, 0xc0, 0x10, 0x52
, 0xfc, 0x01, 0x02, 0x7c, 0x1b, 0x7c, 0x54, 0x00, 0x3e, 0x5c, 0x54, 0x01, 0x80, 0x9d, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x01, 0x04, 0x53, 0x5c, 0x52, 0xfb, 0x09, 0x00, 0x7c, 0x1a, 0xd3, 0x52, 0xfc, 0x53, 0x5a, 0x52, 0xfb, 0x7c, 0x1b, 0x6d, 0xc0, 0x10, 0x52, 0xfc, 0x01, 0x04, 0x7c, 0x1b, 0x7c, 0x54, 0x00, 0x3e, 0x5c, 0x54, 0x01, 0x80, 0x73, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x53, 0x5c, 0x52
, 0xfb, 0x7c, 0x1b, 0x9e, 0x80, 0x65, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x53, 0x5c, 0x52, 0xfb, 0x7c, 0x1a, 0xd3, 0x52, 0xfc, 0x01, 0x04, 0x53, 0x5a, 0x52, 0xfb, 0x7c, 0x1a, 0xbd, 0x12, 0x5c, 0x51, 0x5b, 0x1a, 0x5d, 0xc0, 0x10, 0x52, 0xfc, 0x01, 0x04, 0x7c, 0x1b, 0x7c, 0x54, 0x00, 0x3e, 0x5c, 0x54, 0x01, 0x80, 0x37, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x01, 0x02, 0x53, 0x5c, 0x52, 0xfb, 0x09
, 0x00, 0x7c, 0x1a, 0xd3, 0x52, 0xfc, 0x53, 0x5a, 0x52, 0xfb, 0x7c, 0x1b, 0x6d, 0xc0, 0x10, 0x52, 0xfc, 0x01, 0x02, 0x7c, 0x1b, 0x7c, 0x54, 0x00, 0x3e, 0x5c, 0x54, 0x01, 0x80, 0x0d, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x53, 0x5c, 0x52, 0xfb, 0x7c, 0x1b, 0x9e, 0x62, 0xd0, 0x00, 0x52, 0x01, 0x53, 0x5c, 0x52, 0x00, 0x53, 0x5d, 0x38, 0xfe, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x05, 0x62, 0xd0, 0x00
, 0x55, 0xbe, 0x00, 0x3c, 0xb9, 0x00, 0xb0, 0x05, 0x51, 0xa7, 0x53, 0x24, 0x56, 0x02, 0x00, 0x81, 0x62, 0x62, 0xd0, 0x00, 0x3c, 0xb9, 0x00, 0xb0, 0x1b, 0x52, 0x02, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x06, 0x5c, 0xa7, 0x7c, 0x1a, 0xa4, 0x52, 0x02, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x06, 0x5a, 0x24, 0x7c, 0x1b, 0x87, 0x62, 0xd0, 0x00, 0x3c, 0xb4, 0x01, 0xb0, 0xf9, 0x56, 0x01, 0x00, 0x80, 0x37
, 0x10, 0x52, 0x02, 0x7c, 0x09, 0x35, 0x20, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0, 0x00, 0x20, 0x39, 0x00, 0xbf, 0xee, 0x7c, 0x1a, 0x87, 0x06, 0x5c, 0x97, 0x7c, 0x1a, 0xa4, 0x3e, 0x5c, 0x53, 0x5c, 0x52, 0x01, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x65, 0x5a, 0x6b, 0x5b, 0x06, 0x5a, 0x40, 0x0e, 0x5b, 0x00, 0x7c, 0x1b, 0x60, 0x77, 0x01, 0x3d, 0x01, 0x05, 0xcf, 0xc6, 0x56, 0x01, 0x00, 0x80, 0x95
, 0x52, 0x01, 0x01, 0x01, 0x54, 0x00, 0x80, 0x86, 0x62, 0xd0, 0x00, 0x7c, 0x1a, 0xe9, 0x06, 0x5c, 0x40, 0x7c, 0x1a, 0xa4, 0x3e, 0x5c, 0x53, 0x5c, 0x52, 0x01, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x65, 0x5a, 0x6b, 0x5b, 0x06, 0x5a, 0x40, 0x0e, 0x5b, 0x00, 0x51, 0x5b, 0x7c, 0x1b, 0x6d, 0xd0, 0x5c, 0x7c, 0x1a, 0xe9, 0x06, 0x5c, 0x40, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x53
, 0xab, 0x3e, 0x5c, 0x53, 0xac, 0x52, 0x01, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x65, 0x5c, 0x6b, 0x5d, 0x06, 0x5c, 0x40, 0x7c, 0x1a, 0xa4, 0x3e, 0x5c, 0x53, 0x5c, 0x52, 0x00, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x65, 0x5a, 0x6b, 0x5b, 0x06, 0x5a, 0x40, 0x0e, 0x5b, 0x00, 0x7c, 0x1b, 0x60, 0x52, 0x01, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x65, 0x5c, 0x6b, 0x5d, 0x06, 0x5c, 0x40, 0x0e, 0x5d, 0x00, 0x51
, 0x5d, 0x60, 0xd5, 0x51, 0xab, 0x3f, 0x5c, 0x51, 0xac, 0x3f, 0x5c, 0x77, 0x00, 0x3d, 0x00, 0x05, 0xcf, 0x77, 0x77, 0x01, 0x3d, 0x01, 0x05, 0xcf, 0x68, 0x62, 0xd0, 0x00, 0x7c, 0x1a, 0x87, 0x06, 0x5c, 0x97, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60, 0xd5, 0x51, 0x44, 0x3f, 0x5c, 0x51, 0x45, 0x3f, 0x5c, 0x80, 0x14, 0x10, 0x52, 0x02, 0x7c, 0x09, 0x35, 0x20, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0
, 0x00, 0x20, 0x39, 0x00, 0xbf, 0xee, 0x62, 0xd0, 0x00, 0x52, 0x02, 0x7c, 0x1a, 0x27, 0x7c, 0x1a, 0xc8, 0x70, 0xfb, 0x6e, 0x5b, 0x6e, 0x5a, 0x06, 0x5c, 0x6f, 0x0e, 0x5d, 0x00, 0x7c, 0x1a, 0xb0, 0x52, 0x02, 0x7c, 0x1a, 0x27, 0x53, 0x5b, 0x06, 0x5c, 0x6f, 0x7c, 0x1a, 0xa4, 0x7c, 0x1b, 0x27, 0x77, 0x02, 0x3d, 0x02, 0x02, 0xce, 0x9b, 0x56, 0x02, 0x00, 0x82, 0x10, 0x62, 0xd0, 0x00, 0x52
, 0x02, 0x7c, 0x1a, 0x27, 0x7c, 0x1a, 0xc8, 0x06, 0x5c, 0x87, 0x7c, 0x1a, 0xa4, 0x7c, 0x1b, 0xd2, 0xd0, 0x56, 0x7c, 0x1a, 0x87, 0x7c, 0x1b, 0x06, 0x06, 0x5a, 0x01, 0x0e, 0x5b, 0x00, 0x7c, 0x1a, 0xb0, 0x52, 0x02, 0x7c, 0x1a, 0x27, 0x7c, 0x1a, 0xc8, 0x06, 0x5c, 0x87, 0x7c, 0x1a, 0xa4, 0x7c, 0x1b, 0xd2, 0xd0, 0xac, 0x7c, 0x1a, 0x87, 0x7c, 0x1b, 0x06, 0x06, 0x5a, 0x01, 0x0e, 0x5b, 0x00
, 0x7c, 0x1a, 0xb0, 0x52, 0x02, 0x7c, 0x1a, 0x27, 0x7c, 0x1a, 0xc8, 0x06, 0x5c, 0x87, 0x7c, 0x1a, 0xa4, 0x7c, 0x1b, 0xd2, 0xd0, 0x8a, 0x7c, 0x1a, 0x87, 0x7c, 0x1b, 0x06, 0x06, 0x5a, 0x01, 0x0e, 0x5b, 0x00, 0x7c, 0x1a, 0xb0, 0x80, 0x79, 0x62, 0xd0, 0x00, 0x52, 0x02, 0x7c, 0x1a, 0x27, 0x7c, 0x1a, 0xc8, 0x06, 0x5c, 0x87, 0x7c, 0x1a, 0xa4, 0x3e, 0x5c, 0x12, 0x5a, 0x51, 0x5d, 0x1a, 0x5b
, 0xd0, 0x5e, 0x7c, 0x1a, 0x87, 0x7c, 0x1b, 0x06, 0x16, 0x5a, 0x01, 0x1e, 0x5b, 0x00, 0x7c, 0x1a, 0xb0, 0x52, 0x02, 0x7c, 0x1a, 0x27, 0x7c, 0x1a, 0xc8, 0x06, 0x5c, 0x87, 0x7c, 0x1a, 0xa4, 0x3e, 0x5c, 0x12, 0x5a, 0x51, 0x5d, 0x1a, 0x5b, 0xd0, 0x37, 0x7c, 0x1a, 0x87, 0x7c, 0x1b, 0x06, 0x16, 0x5a, 0x01, 0x1e, 0x5b, 0x00, 0x7c, 0x1a, 0xb0, 0x52, 0x02, 0x97, 0xeb, 0x40, 0x7c, 0x1a, 0xc8
, 0x06, 0x5c, 0x87, 0x7c, 0x1a, 0xa4, 0x3e, 0x5c, 0x12, 0x5a, 0x51, 0x5d, 0x1a, 0x5b, 0xd0, 0x10, 0x7c, 0x1a, 0x87, 0x7c, 0x1b, 0x06, 0x16, 0x5a, 0x01, 0x1e, 0x5b, 0x00, 0x7c, 0x1a, 0xb0, 0x62, 0xd0, 0x00, 0x7c, 0x1a, 0x87, 0x51, 0x5c, 0x01, 0x7f, 0x7c, 0x1a, 0x93, 0x06, 0x5c, 0x77, 0x0e, 0x5d, 0x00, 0x7c, 0x1a, 0xb0, 0x7c, 0x1a, 0x87, 0x51, 0x5c, 0x01, 0x87, 0x7c, 0x1a, 0x93, 0x06
, 0x5c, 0x7f, 0x0e, 0x5d, 0x00, 0x7c, 0x1a, 0xb0, 0x52, 0x02, 0x97, 0x9b, 0x40, 0x7c, 0x1a, 0xc8, 0x06, 0x5c, 0x87, 0x0e, 0x5d, 0x00, 0x7c, 0x1a, 0xb0, 0x52, 0x02, 0x97, 0x8a, 0x40, 0x53, 0x5b, 0x60, 0xd4, 0x3e, 0x5a, 0x53, 0x59, 0x3e, 0x5a, 0x16, 0x5a, 0x02, 0x53, 0x58, 0x08, 0x51, 0x59, 0x53, 0x57, 0x18, 0x53, 0x56, 0x65, 0x56, 0x6b, 0x57, 0x06, 0x5c, 0x7f, 0x97, 0xe6, 0x40, 0x3e
, 0x5c, 0x53, 0x5c, 0x51, 0x56, 0x04, 0x5c, 0x51, 0x57, 0x0c, 0x5d, 0x51, 0x58, 0x04, 0x5c, 0x51, 0x59, 0x0c, 0x5d, 0x70, 0xfb, 0x6e, 0x5d, 0x6e, 0x5c, 0x70, 0xfb, 0x6e, 0x5d, 0x6e, 0x5c, 0x7c, 0x1b, 0x60, 0x10, 0x52, 0x02, 0x7c, 0x06, 0x07, 0x20, 0x62, 0xd0, 0x00, 0x52, 0x02, 0x97, 0x37, 0x40, 0x97, 0xd5, 0x40, 0x06, 0x5c, 0x8f, 0x97, 0xab, 0x40, 0x7c, 0x1b, 0xd2, 0xd0, 0x25, 0x52
, 0x02, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x06, 0x5c, 0x9f, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x7a, 0x5c, 0x53, 0x5b, 0x06, 0x5b, 0x01, 0x51, 0x5d, 0x60, 0xd5, 0x51, 0x5b, 0x3f, 0x5c, 0x80, 0x0a, 0x97, 0xb9, 0x40, 0x06, 0x5c, 0x9f, 0x7c, 0x1b, 0xfa, 0x97, 0xb0, 0x40, 0x06, 0x5c, 0x9f, 0x97, 0x70, 0x40, 0x50, 0x05, 0x3a, 0x5d, 0xd0, 0x4f, 0x97, 0x4a, 0x40, 0x51, 0x5c
, 0x01, 0x8f, 0x53, 0x5a, 0x51, 0x5d, 0x09, 0x00, 0x53, 0x5b, 0x06, 0x5c, 0x97, 0x97, 0x55, 0x40, 0x3e, 0x5c, 0x53, 0x5c, 0x51, 0x5b, 0x60, 0xd4, 0x3e, 0x5a, 0x53, 0x59, 0x3e, 0x5a, 0x16, 0x5a, 0x02, 0x02, 0x5c, 0x53, 0x5c, 0x51, 0x59, 0x0a, 0x5d, 0x53, 0x5d, 0x70, 0xfb, 0x6e, 0x5d, 0x6e, 0x5c, 0x97, 0xed, 0x40, 0x52, 0x02, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x06, 0x5c, 0x9f, 0x0e, 0x5d
, 0x00, 0x51, 0x5d, 0x60, 0xd5, 0x50, 0x00, 0x3f, 0x5c, 0x77, 0x02, 0x3d, 0x02, 0x02, 0xcd, 0xed, 0x62, 0xd0, 0x00, 0x3c, 0xb5, 0x02, 0xb0, 0xd6, 0x56, 0x02, 0x00, 0x80, 0xcc, 0x62, 0xd0, 0x00, 0x96, 0xe5, 0x40, 0x51, 0x5c, 0x01, 0x6f, 0x96, 0xea, 0x40, 0x51, 0x5c, 0x01, 0x97, 0x7c, 0x1b, 0xdf, 0x12, 0x5a, 0x53, 0x5a, 0x51, 0x59, 0x1a, 0x5b, 0x53, 0x5b, 0x06, 0x5c, 0x38, 0x0e, 0x5d
, 0x00, 0x96, 0xed, 0x40, 0x96, 0xc1, 0x40, 0x51, 0x5c, 0x01, 0x8f, 0x96, 0xc6, 0x40, 0x06, 0x5c, 0x3c, 0x0e, 0x5d, 0x00, 0x96, 0xda, 0x40, 0x96, 0xae, 0x40, 0x51, 0x5c, 0x01, 0x6f, 0x96, 0xb3, 0x40, 0x51, 0x5c, 0x01, 0x3c, 0x97, 0xf8, 0x40, 0x12, 0x5a, 0x53, 0x5a, 0x51, 0x59, 0x1a, 0x5b, 0x53, 0x5b, 0x06, 0x5c, 0x3c, 0x0e, 0x5d, 0x00, 0x96, 0xb6, 0x40, 0x96, 0x8a, 0x40, 0x51, 0x5c
, 0x01, 0x8f, 0x96, 0x8f, 0x40, 0x51, 0x5c, 0x01, 0x97, 0x97, 0xd4, 0x40, 0x53, 0x58, 0x51, 0x5a, 0x12, 0x58, 0x51, 0x5b, 0x1a, 0x59, 0xd0, 0x34, 0x52, 0x02, 0x97, 0xd2, 0x40, 0x01, 0x8f, 0x53, 0x58, 0x51, 0x5b, 0x09, 0x00, 0x60, 0xd4, 0x3e, 0x58, 0x53, 0x59, 0x3e, 0x58, 0x53, 0x58, 0x06, 0x5a, 0x97, 0x0e, 0x5b, 0x00, 0x51, 0x5b, 0x60, 0xd4, 0x3e, 0x5a, 0x53, 0x5b, 0x3e, 0x5a, 0x12
, 0x58, 0x54, 0x04, 0x51, 0x5b, 0x1a, 0x59, 0x54, 0x03, 0x80, 0x07, 0x56, 0x04, 0x00, 0x56, 0x03, 0x00, 0x62, 0xd0, 0x00, 0x06, 0x5c, 0x34, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60, 0xd5, 0x52, 0x03, 0x3f, 0x5c, 0x52, 0x04, 0x3f, 0x5c, 0x77, 0x02, 0x3d, 0x02, 0x02, 0xcf, 0x31, 0x38, 0xfb, 0x20, 0x7f, 0x10, 0x4f, 0x80, 0x02, 0x40, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x53, 0x5c, 0x52, 0xfb, 0x53
, 0x5d, 0x51, 0x5c, 0x11, 0x01, 0x54, 0xfc, 0x51, 0x5d, 0x19, 0x00, 0x54, 0xfb, 0x3c, 0x5d, 0x00, 0xbf, 0xe4, 0x3c, 0x5c, 0x00, 0xbf, 0xdf, 0x20, 0x7f, 0x10, 0x7c, 0x04, 0x8d, 0x7c, 0x04, 0x6a, 0x20, 0x7f, 0x10, 0x7c, 0x04, 0x89, 0x7c, 0x04, 0x66, 0x20, 0x7f, 0x62, 0xd0, 0x00, 0x51, 0x60, 0x12, 0x94, 0x50, 0x00, 0x1a, 0x93, 0xd0, 0x0f, 0x51, 0x61, 0x12, 0x96, 0x50, 0x00, 0x1a, 0x95
, 0xd0, 0x05, 0x50, 0x0f, 0x80, 0x17, 0x62, 0xd0, 0x00, 0x51, 0x96, 0x12, 0x94, 0x51, 0x95, 0x1a, 0x93, 0xd0, 0x05, 0x50, 0x00, 0x80, 0x06, 0x62, 0xd0, 0x00, 0x50, 0x01, 0x7f, 0x10, 0x4f, 0x38, 0x05, 0x62, 0xd0, 0x00, 0x51, 0x94, 0x54, 0x02, 0x51, 0x93, 0x54, 0x01, 0x56, 0x04, 0x00, 0x56, 0x00, 0x00, 0x56, 0x03, 0x00, 0x80, 0x69, 0x96, 0x23, 0x40, 0x06, 0x5c, 0x60, 0x0e, 0x5d, 0x00
, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x53, 0x5c, 0x52, 0x00, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x65, 0x5a, 0x6b, 0x5b, 0x06, 0x5a, 0x93, 0x0e, 0x5b, 0x00, 0x51, 0x5b, 0x95, 0xab, 0x40, 0x51, 0x5c, 0x12, 0x5a, 0x50, 0x00, 0x1a, 0x5b, 0xd0, 0x03, 0x77, 0x03, 0x62, 0xd0, 0x00, 0x95, 0xba, 0x40, 0x06, 0x5c, 0x93, 0x95, 0x6f, 0x40, 0x3e, 0x5c, 0x53, 0x5c, 0x52, 0x02, 0x12, 0x5c, 0x52, 0x01
, 0x1a, 0x5d, 0xd0, 0x1a, 0x95, 0xa3, 0x40, 0x06, 0x5c, 0x93, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x54, 0x01, 0x3e, 0x5c, 0x54, 0x02, 0x52, 0x00, 0x54, 0x04, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xcf, 0x94, 0x50, 0x01, 0x3b, 0x03, 0xd0, 0x08, 0x62, 0xd0, 0x00, 0x50, 0x0f, 0x80, 0x06, 0x52, 0x04, 0x62, 0xd0, 0x00, 0x38, 0xfb, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x02, 0x70, 0xfe
, 0x62, 0xd0, 0x00, 0x26, 0x2a, 0xf0, 0x51, 0xbc, 0x01, 0x01, 0x53, 0x5d, 0x51, 0x2a, 0x2a, 0x5d, 0x53, 0x2a, 0x51, 0x2a, 0x53, 0xb1, 0x71, 0x01, 0x62, 0xe3, 0x38, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0, 0x00, 0x20, 0x43, 0x00, 0x08, 0x56, 0x01, 0x00, 0x56, 0x00, 0x00, 0x80, 0x21, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0, 0x00, 0x20, 0x53, 0x5d, 0x47, 0x5d, 0x20, 0xa0, 0x03, 0x80, 0x1a, 0x50
, 0x00, 0x08, 0x50, 0x04, 0x08, 0x9e, 0xaa, 0x38, 0xfe, 0x77, 0x01, 0x0f, 0x00, 0x00, 0x52, 0x01, 0x11, 0xdc, 0x52, 0x00, 0x19, 0x05, 0xcf, 0xd7, 0x56, 0x01, 0x00, 0x56, 0x00, 0x00, 0x80, 0x21, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0, 0x00, 0x20, 0x53, 0x5d, 0x47, 0x5d, 0x20, 0xb0, 0x03, 0x80, 0x1a, 0x50, 0x00, 0x08, 0x50, 0x04, 0x08, 0x9e, 0x78, 0x38, 0xfe, 0x77, 0x01, 0x0f, 0x00, 0x00
, 0x52, 0x01, 0x11, 0x2c, 0x52, 0x00, 0x19, 0x01, 0xcf, 0xd7, 0x41, 0x00, 0xf7, 0x38, 0xfe, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x02, 0x70, 0xfe, 0x62, 0xd0, 0x00, 0x26, 0x2a, 0xf0, 0x51, 0xbc, 0x01, 0x09, 0x53, 0x5d, 0x51, 0x2a, 0x2a, 0x5d, 0x53, 0x2a, 0x51, 0x2a, 0x53, 0xb1, 0x71, 0x01, 0x62, 0xe3, 0x38, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0, 0x00, 0x20, 0x43, 0x00, 0x08, 0x56, 0x01, 0x00
, 0x56, 0x00, 0x00, 0x80, 0x21, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0, 0x00, 0x20, 0x53, 0x5d, 0x47, 0x5d, 0x20, 0xa0, 0x03, 0x80, 0x1a, 0x50, 0x00, 0x08, 0x50, 0x04, 0x08, 0x9e, 0x13, 0x38, 0xfe, 0x77, 0x01, 0x0f, 0x00, 0x00, 0x52, 0x01, 0x11, 0xdc, 0x52, 0x00, 0x19, 0x05, 0xcf, 0xd7, 0x56, 0x01, 0x00, 0x56, 0x00, 0x00, 0x80, 0x21, 0x10, 0x7c, 0x05, 0xc3, 0x62, 0xd0, 0x00, 0x20, 0x53
, 0x5d, 0x47, 0x5d, 0x20, 0xb0, 0x03, 0x80, 0x1a, 0x50, 0x00, 0x08, 0x50, 0x04, 0x08, 0x9d, 0xe1, 0x38, 0xfe, 0x77, 0x01, 0x0f, 0x00, 0x00, 0x52, 0x01, 0x11, 0x2c, 0x52, 0x00, 0x19, 0x01, 0xcf, 0xd7, 0x41, 0x00, 0xf7, 0x38, 0xfe, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x04, 0x62, 0xd0, 0x00, 0x51, 0x2a, 0x21, 0xf0, 0x54, 0x00, 0x51, 0x2d, 0x54, 0x01, 0x3c, 0x32, 0x01, 0xb0, 0x11, 0x3c, 0xb4
, 0x00, 0xb0, 0x1d, 0x55, 0xb4, 0x01, 0x55, 0x60, 0x3c, 0x55, 0x61, 0x5f, 0x80, 0x12, 0x62, 0xd0, 0x00, 0x3c, 0xb4, 0x01, 0xb0, 0x0a, 0x55, 0xb4, 0x00, 0x55, 0x60, 0x28, 0x55, 0x61, 0x28, 0x3d, 0x00, 0x10, 0xb0, 0x27, 0x62, 0xd0, 0x00, 0x55, 0xb7, 0x00, 0x3c, 0xba, 0x01, 0xb0, 0x09, 0x55, 0xa3, 0x00, 0x55, 0xa4, 0x00, 0x80, 0x0f, 0x62, 0xd0, 0x00, 0x3c, 0xb2, 0x01, 0xa0, 0x07, 0x55
, 0xa3, 0x00, 0x55, 0xa4, 0x00, 0x93, 0xee, 0x40, 0x81, 0x68, 0x3d, 0x00, 0x20, 0xb0, 0x15, 0x62, 0xd0, 0x00, 0x55, 0xb7, 0x01, 0x55, 0xb8, 0x00, 0x55, 0xa3, 0x08, 0x55, 0xa4, 0x08, 0x93, 0xd5, 0x40, 0x81, 0x4f, 0x3d, 0x00, 0x40, 0xb0, 0x0c, 0x62, 0xd0, 0x00, 0x55, 0xb5, 0x02, 0x93, 0xc5, 0x40, 0x81, 0x3f, 0x3d, 0x00, 0x50, 0xb0, 0xa1, 0x52, 0x01, 0x54, 0x03, 0x56, 0x02, 0x00, 0x3d
, 0x02, 0x00, 0xb0, 0x06, 0x3d, 0x03, 0x01, 0xa0, 0x21, 0x3d, 0x02, 0x00, 0xb0, 0x06, 0x3d, 0x03, 0x02, 0xa0, 0x28, 0x3d, 0x02, 0x00, 0xb0, 0x06, 0x3d, 0x03, 0x04, 0xa0, 0x36, 0x3d, 0x02, 0x00, 0xb0, 0x06, 0x3d, 0x03, 0x08, 0xa0, 0x48, 0x80, 0x62, 0x62, 0xd0, 0x00, 0x55, 0xb9, 0x01, 0x51, 0x2f, 0x29, 0x80, 0x53, 0x2f, 0x7c, 0x0c, 0xd1, 0x80, 0x51, 0x62, 0xd0, 0x00, 0x51, 0x2b, 0x53
, 0x60, 0x51, 0x2b, 0x53, 0x61, 0x51, 0x2b, 0x53, 0x2e, 0x51, 0x2c, 0x53, 0x0e, 0x55, 0x0d, 0x00, 0x80, 0x39, 0x62, 0xd0, 0x00, 0x51, 0x2b, 0x53, 0x2f, 0x3c, 0xb9, 0x00, 0xa0, 0x09, 0x51, 0x2f, 0x29, 0x80, 0x53, 0x2f, 0x80, 0x25, 0x62, 0xd0, 0x00, 0x26, 0x2f, 0x7f, 0x80, 0x1d, 0x62, 0xd0, 0x00, 0x55, 0xb9, 0x00, 0x26, 0x2f, 0x7f, 0x51, 0xa7, 0x53, 0x24, 0x51, 0x24, 0x53, 0x30, 0x51
, 0xa8, 0x53, 0x25, 0x51, 0x25, 0x53, 0x31, 0x7c, 0x0c, 0xd1, 0x93, 0x29, 0x40, 0x55, 0x2b, 0x0b, 0x55, 0x2c, 0x08, 0x55, 0x2d, 0x00, 0x80, 0x9a, 0x3d, 0x00, 0x60, 0xb0, 0x0c, 0x62, 0xd0, 0x00, 0x55, 0xba, 0x01, 0x93, 0x10, 0x40, 0x80, 0x8a, 0x3d, 0x00, 0x70, 0xb0, 0x0c, 0x62, 0xd0, 0x00, 0x55, 0xba, 0x00, 0x93, 0x00, 0x40, 0x80, 0x7a, 0x3d, 0x00, 0x80, 0xb0, 0x75, 0x92, 0xf6, 0x40
, 0x9c, 0x97, 0x10, 0x7c, 0x08, 0xb3, 0x7c, 0x05, 0xd9, 0x20, 0x70, 0xfe, 0x71, 0x10, 0x41, 0x00, 0xf7, 0x41, 0x01, 0xf7, 0x70, 0xcf, 0x62, 0xda, 0x00, 0x71, 0x10, 0x41, 0xdc, 0xfe, 0x70, 0xcf, 0x43, 0x01, 0x08, 0x43, 0x00, 0x08, 0x50, 0x00, 0x08, 0x50, 0x1e, 0x08, 0x9c, 0x43, 0x38, 0xfe, 0x71, 0x01, 0x43, 0xe0, 0x10, 0x41, 0x7a, 0xef, 0x41, 0x7a, 0xfe, 0x71, 0x10, 0x41, 0xdc, 0xfd
, 0x41, 0xec, 0xfd, 0x43, 0xe0, 0x40, 0x41, 0xe0, 0xdf, 0x70, 0xcf, 0x43, 0xff, 0x08, 0x43, 0x7a, 0x10, 0x43, 0x7a, 0x01, 0x70, 0xfe, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x10, 0x7c, 0x07, 0xe2, 0x7c, 0x05, 0x8d, 0x7c, 0x05, 0xce, 0x20, 0x93, 0x4f, 0x40, 0x62, 0xe3, 0x38, 0x92, 0x85, 0x40, 0x38, 0xfc, 0x20, 0x7f, 0x62, 0xd0, 0x00, 0x3c, 0xb7, 0x00, 0xa0, 0x10, 0x9c, 0x1a, 0x62
, 0xd0, 0x00, 0x3c, 0xb8, 0x00, 0xb0, 0x30, 0x55, 0xb8, 0x01, 0x80, 0x2b, 0x62, 0xd0, 0x00, 0x50, 0x01, 0x3a, 0xa3, 0xd0, 0x08, 0x10, 0x7c, 0x04, 0x8d, 0x20, 0x80, 0x06, 0x10, 0x7c, 0x04, 0x89, 0x20, 0x62, 0xd0, 0x00, 0x50, 0x01, 0x3a, 0xa4, 0xd0, 0x08, 0x10, 0x7c, 0x04, 0x6a, 0x20, 0x80, 0x06, 0x10, 0x7c, 0x04, 0x66, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x03, 0x56, 0x02, 0x00, 0x56, 0x01
, 0x00, 0x56, 0x00, 0x00, 0x80, 0x37, 0x62, 0xd0, 0x00, 0x92, 0x1e, 0x40, 0x52, 0xfc, 0x04, 0x5c, 0x52, 0xfb, 0x0c, 0x5d, 0x51, 0x5d, 0x91, 0xfb, 0x40, 0x52, 0x02, 0x12, 0x5c, 0x52, 0x01, 0x1a, 0x5d, 0xd0, 0x18, 0x92, 0x04, 0x40, 0x52, 0xfc, 0x04, 0x5c, 0x52, 0xfb, 0x0c, 0x5d, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x54, 0x01, 0x3e, 0x5c, 0x54, 0x02, 0x77, 0x00, 0x52, 0x00, 0x3b, 0xfa
, 0xcf, 0xc5, 0x62, 0xd0, 0x00, 0x52, 0x02, 0x53, 0x5c, 0x52, 0x01, 0x53, 0x5d, 0x38, 0xfd, 0x20, 0x7f, 0x10, 0x7c, 0x04, 0x18, 0x20, 0x10, 0x50, 0x04, 0x08, 0x50, 0x00, 0x08, 0x50, 0x97, 0x08, 0x7c, 0x04, 0x21, 0x38, 0xfd, 0x20, 0x10, 0x50, 0x04, 0x08, 0x50, 0x00, 0x08, 0x50, 0x8f, 0x08, 0x7c, 0x04, 0x21, 0x38, 0xfd, 0x20, 0x10, 0x50, 0x04, 0x08, 0x50, 0x00, 0x08, 0x50, 0x93, 0x08
, 0x7c, 0x04, 0x21, 0x38, 0xfd, 0x20, 0x10, 0x50, 0x00, 0x7c, 0x03, 0x3c, 0x20, 0x10, 0x50, 0xff, 0x7c, 0x03, 0x3c, 0x20, 0x10, 0x50, 0xff, 0x7c, 0x03, 0x3c, 0x20, 0x7f, 0x62, 0xd0, 0x00, 0x76, 0xb0, 0x0e, 0xaf, 0x00, 0x50, 0x38, 0x12, 0xb0, 0x50, 0x01, 0x1a, 0xaf, 0xd0, 0x12, 0x55, 0xb0, 0x00, 0x55, 0xaf, 0x00, 0x76, 0x33, 0x50, 0x80, 0x3a, 0x33, 0xd0, 0x04, 0x55, 0x33, 0x0a, 0x7f
, 0x62, 0xd0, 0x00, 0x55, 0xb9, 0x00, 0x55, 0xba, 0x01, 0x10, 0x7c, 0x04, 0x8d, 0x7c, 0x04, 0x6a, 0x20, 0x9b, 0x06, 0x62, 0xe3, 0x38, 0x71, 0x10, 0x43, 0x00, 0x08, 0x41, 0x01, 0xf7, 0x70, 0xcf, 0x41, 0x00, 0xf7, 0x62, 0xd0, 0x00, 0x55, 0x2a, 0x08, 0x55, 0x2b, 0x0b, 0x55, 0x2c, 0x08, 0x55, 0x2e, 0x28, 0x55, 0x2f, 0x05, 0x55, 0x30, 0x12, 0x55, 0x31, 0x0d, 0x55, 0x32, 0x00, 0x55, 0x33
, 0x00, 0x55, 0x33, 0x0a, 0x3c, 0xb9, 0x00, 0xa0, 0x09, 0x51, 0x2f, 0x29, 0x80, 0x53, 0x2f, 0x80, 0x07, 0x62, 0xd0, 0x00, 0x26, 0x2f, 0x7f, 0x10, 0x50, 0x00, 0x08, 0x50, 0x2a, 0x08, 0x50, 0x09, 0x08, 0x50, 0x16, 0x08, 0x7c, 0x05, 0xe0, 0x38, 0xfc, 0x7c, 0x05, 0x8d, 0x7c, 0x05, 0xce, 0x20, 0x91, 0xc7, 0x40, 0x10, 0x7c, 0x07, 0xe2, 0x7c, 0x07, 0x6b, 0x20, 0x7c, 0x0c, 0xd1, 0x80, 0x24
, 0x62, 0xe3, 0x38, 0x9f, 0x57, 0x7c, 0x0f, 0xf9, 0x10, 0x7c, 0x07, 0xa9, 0x62, 0xd0, 0x00, 0x20, 0x39, 0x00, 0xa0, 0x09, 0x7c, 0x0a, 0x02, 0x7c, 0x0a, 0x5c, 0x80, 0x04, 0x7c, 0x0a, 0xd2, 0x9c, 0x87, 0x9e, 0x52, 0x8f, 0xdc, 0x8f, 0xff, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x65, 0x5c, 0x6b, 0x5d, 0x51, 0x5c, 0x01, 0x97, 0x53, 0x5a, 0x51, 0x5d, 0x09, 0x00, 0x7f, 0x52, 0x00, 0x53, 0x5c, 0x55
, 0x5d, 0x00, 0x55, 0x5a, 0x06, 0x55, 0x5b, 0x00, 0x55, 0x55, 0x00, 0x55, 0x54, 0x00, 0x3c, 0x5b, 0x00, 0xb0, 0x06, 0x3c, 0x5a, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e, 0x5b, 0x6e, 0x5a, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x5c, 0x04, 0x55, 0x51, 0x5d, 0x0c, 0x54, 0x65, 0x5c, 0x6b, 0x5d, 0x8f, 0xde, 0x5f, 0x5c, 0x55, 0x5f, 0x5d, 0x54, 0x62, 0xd0, 0x00, 0x5a, 0x5a, 0x06, 0x5a, 0x01, 0x51
, 0x5a, 0x04, 0x5c, 0x0e, 0x5d, 0x03, 0x7f, 0x52, 0x02, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x65, 0x5c, 0x6b, 0x5d, 0x7f, 0x53, 0x5a, 0x51, 0x5d, 0x09, 0x00, 0x60, 0xd4, 0x3e, 0x5a, 0x53, 0x5b, 0x3e, 0x5a, 0x53, 0x5a, 0x7f, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x53, 0x5d, 0x7f, 0x51, 0x5d, 0x60, 0xd5, 0x51, 0x5b, 0x3f, 0x5c, 0x51, 0x5a, 0x3f, 0x5c, 0x7f, 0x09, 0x00, 0x60
, 0xd4, 0x3e, 0x5a, 0x53, 0x5b, 0x3e, 0x5a, 0x7f, 0x60, 0xd4, 0x3e, 0x5a, 0x53, 0x5b, 0x3e, 0x5a, 0x53, 0x5a, 0x7f, 0x60, 0xd4, 0x3e, 0x5c, 0x53, 0x5d, 0x3e, 0x5c, 0x53, 0x5c, 0x7f, 0x62, 0xd0, 0x00, 0x52, 0x02, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x7f, 0x52, 0x00, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x65, 0x5c, 0x6b, 0x5d, 0x7f, 0x56, 0x00, 0x00, 0x62, 0xd0, 0x00, 0x51, 0xb1, 0x62, 0xd0, 0x00
, 0x53, 0x2a, 0x26, 0x2a, 0x0f, 0x7f, 0x06, 0x5c, 0x97, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60, 0xd4, 0x3e, 0x5c, 0x53, 0x5b, 0x3e, 0x5c, 0x16, 0x5c, 0x02, 0x53, 0x5a, 0x7f, 0x62, 0xd0, 0x00, 0x52, 0x00, 0x53, 0x5c, 0x55, 0x5d, 0x00, 0x7f, 0x3e, 0x5c, 0x53, 0x5c, 0x51, 0x5b, 0x60, 0xd4, 0x3e, 0x5a, 0x53, 0x59, 0x3e, 0x5a, 0x16, 0x5a, 0x02, 0x02, 0x5c, 0x53, 0x5c, 0x51, 0x59, 0x0a, 0x5d
, 0x53, 0x5d, 0x51, 0x5b, 0x60, 0xd5, 0x51, 0x5d, 0x3f, 0x5a, 0x51, 0x5c, 0x3f, 0x5a, 0x7f, 0x53, 0x5a, 0x51, 0x5d, 0x09, 0x00, 0x60, 0xd5, 0x52, 0x14, 0x3f, 0x5a, 0x52, 0x15, 0x3f, 0x5a, 0x7f, 0x51, 0x5b, 0x60, 0xd5, 0x51, 0x5d, 0x3f, 0x5a, 0x51, 0x5c, 0x3f, 0x5a, 0x7f, 0x60, 0xd4, 0x3e, 0x5a, 0x53, 0x5b, 0x3e, 0x5a, 0x12, 0x5c, 0x51, 0x5b, 0x1a, 0x5d, 0x7f, 0x53, 0x5c, 0x52, 0xfb
, 0x09, 0x00, 0x60, 0xd4, 0x3e, 0x5c, 0x7f, 0x0e, 0x5b, 0x00, 0x51, 0x5b, 0x60, 0xd5, 0x51, 0x5d, 0x3f, 0x5a, 0x7f, 0x60, 0xd5, 0x52, 0x14, 0x3f, 0x5a, 0x52, 0x15, 0x3f, 0x5a, 0x7f, 0x60, 0xd4, 0x3e, 0x5c, 0x54, 0x00, 0x3e, 0x5c, 0x54, 0x01, 0x7f, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60, 0xd5, 0x52, 0x14, 0x3f, 0x5c, 0x52, 0x15, 0x3f, 0x5c, 0x7f, 0x71, 0x10, 0x41, 0x04, 0xfe, 0x41, 0x05
, 0xfe, 0x41, 0x04, 0xfd, 0x41, 0x05, 0xfd, 0x70, 0xcf, 0x43, 0x04, 0x01, 0x43, 0x04, 0x02, 0x71, 0x01, 0x7f, 0x3e, 0x5c, 0x53, 0x5c, 0x51, 0x5a, 0x12, 0x5c, 0x51, 0x5b, 0x1a, 0x5d, 0x7f, 0x53, 0x58, 0x51, 0x5d, 0x09, 0x00, 0x60, 0xd4, 0x3e, 0x58, 0x53, 0x59, 0x3e, 0x58, 0x7f, 0x53, 0x5a, 0x55, 0x5b, 0x00, 0x65, 0x5a, 0x6b, 0x5b, 0x51, 0x5a, 0x7f, 0x0e, 0x5d, 0x00, 0x51, 0x5d, 0x60
, 0xd5, 0x50, 0x00, 0x3f, 0x5c, 0x7f, 0x00, 0x2a, 0x00, 0x2a, 0x00, 0x67, 0x00, 0x28, 0x00, 0x9b, 0x00, 0x08, 0x00, 0xa3, 0x06, 0x08, 0x08, 0x08, 0x08, 0x12, 0x0d, 0x00, 0xa9, 0x00, 0x0d, 0x00, 0xb6, 0x09, 0x03, 0x01, 0x01, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0xff, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
};
unsigned char firmware_data1[] = { /* 111006 HW03 SW05 */
0x40, 0x7d, 0x00, 0x68, 0x30, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7d, 0x00, 0x68, 0x7e, 0x7e, 0x30, 0x30, 0x30, 0x7d, 0x05, 0x2c, 0x7e, 0x7e, 0x30, 0x30, 0x30, 0x7d, 0x06, 0x79, 0x7e, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30
, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x7e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x40, 0x71, 0x10, 0x62, 0xe3, 0x06, 0x70, 0xef, 0x62, 0xe3, 0x38, 0x50, 0x80, 0x4e, 0x62, 0xe3, 0x38, 0x5d, 0xd5, 0x08, 0x62, 0xd5, 0x00, 0x55
, 0xfa, 0x01, 0x40, 0x4f, 0x5b, 0x01, 0x03, 0x53, 0xf9, 0x55, 0xf8, 0x3a, 0x50, 0x06, 0x00, 0x40, 0x40, 0x71, 0x10, 0x51, 0xfa, 0x60, 0xe8, 0x70, 0xef, 0x18, 0x60, 0xd5, 0x55, 0xf8, 0x00, 0x55, 0xf9, 0x00, 0x71, 0x10, 0x62, 0xe0, 0x1a, 0x70, 0xef, 0x62, 0xe3, 0x38, 0x71, 0x10, 0x41, 0xe1, 0xfe, 0x70, 0xef, 0x62, 0xe3, 0x38, 0x62, 0xd1, 0x03, 0x50, 0x80, 0x4e, 0x62, 0xd3, 0x03, 0x62
, 0xd0, 0x00, 0x62, 0xd5, 0x00, 0x62, 0xd4, 0x00, 0x71, 0xc0, 0x7c, 0x03, 0x99, 0x62, 0xd0, 0x00, 0x50, 0x02, 0x57, 0x40, 0x08, 0x28, 0x53, 0x49, 0x18, 0x75, 0x09, 0x00, 0x28, 0x4b, 0x51, 0x49, 0x80, 0x04, 0x75, 0x09, 0x00, 0x62, 0xe3, 0x00, 0x08, 0x28, 0x60, 0xd5, 0x74, 0xa0, 0x4b, 0x18, 0x75, 0x09, 0x00, 0x08, 0x28, 0x53, 0x49, 0x18, 0x75, 0x09, 0x00, 0x08, 0x28, 0xa0, 0x1c, 0x53
, 0x48, 0x18, 0x75, 0x09, 0x00, 0x08, 0x28, 0x3f, 0x49, 0x47, 0x49, 0xff, 0xb0, 0x06, 0x5d, 0xd5, 0x74, 0x60, 0xd5, 0x18, 0x7a, 0x48, 0xbf, 0xeb, 0x8f, 0xc9, 0x18, 0x75, 0x09, 0x00, 0x08, 0x28, 0x53, 0x48, 0x50, 0x00, 0x3f, 0x49, 0x47, 0x49, 0xff, 0xb0, 0x08, 0x5d, 0xd5, 0x74, 0x60, 0xd5, 0x50, 0x00, 0x7a, 0x48, 0xbf, 0xef, 0x18, 0x8f, 0xaa, 0x18, 0x71, 0x10, 0x43, 0xe3, 0x00, 0x70
, 0xef, 0x62, 0xe0, 0x00, 0x41, 0xfe, 0xe7, 0x43, 0xfe, 0x10, 0x71, 0x10, 0x43, 0xe9, 0x20, 0x62, 0xe0, 0x1a, 0x70, 0xef, 0x62, 0xe2, 0x00, 0x7c, 0x19, 0x0d, 0x8f, 0xff, 0x7f, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x01, 0x99, 0x03, 0x33, 0x06, 0x66, 0x0c, 0xcc, 0x19, 0x99, 0x33, 0x33, 0x66, 0x66, 0xcc, 0xcc, 0x01, 0x80, 0x03, 0x00, 0x06, 0x00, 0x0b, 0xff, 0x18, 0x00, 0x2f, 0xff, 0x5f, 0xff, 0xbf, 0xff, 0x01, 0x66, 0x02, 0xcc, 0x05, 0x99, 0x0b, 0x32, 0x16, 0x66, 0x2c, 0xcc, 0x59, 0x98, 0xb3, 0x32, 0x01, 0x33, 0x02, 0x66, 0x04, 0xcc, 0x09, 0x99, 0x13, 0x33, 0x26, 0x65, 0x4c, 0xcc, 0x99, 0x99
, 0x1b, 0xa6, 0x70, 0xef, 0x62, 0x61, 0x00, 0x62, 0xfd, 0x00, 0x62, 0xcd, 0x00, 0x62, 0xce, 0x00, 0x62, 0xa5, 0x00, 0x62, 0xa4, 0x00, 0x62, 0xa0, 0x00, 0x62, 0xa1, 0x80, 0x62, 0xa2, 0xc0, 0x62, 0xa3, 0x0c, 0x62, 0xa8, 0x00, 0x62, 0xa6, 0x00, 0x62, 0xa7, 0x00, 0x62, 0x7c, 0x33, 0x62, 0x7a, 0x00, 0x62, 0x7b, 0x00, 0x62, 0x79, 0x00, 0x62, 0x36, 0x00, 0x62, 0x37, 0x00, 0x62, 0x38, 0x00
, 0x62, 0x39, 0x00, 0x62, 0x3a, 0x00, 0x62, 0x3b, 0x00, 0x62, 0x3c, 0x00, 0x62, 0x3d, 0x00, 0x62, 0x3e, 0x00, 0x62, 0x3f, 0x00, 0x62, 0x40, 0x00, 0x62, 0x41, 0x00, 0x62, 0x42, 0x00, 0x62, 0x43, 0x00, 0x62, 0x44, 0x00, 0x62, 0x45, 0x00, 0x62, 0x46, 0x00, 0x62, 0x47, 0x00, 0x62, 0x48, 0x00, 0x62, 0x49, 0x00, 0x62, 0x4a, 0x00, 0x62, 0x4b, 0x00, 0x62, 0x4c, 0x00, 0x62, 0x4d, 0x00, 0x62
, 0x4e, 0x00, 0x62, 0x4f, 0x00, 0x62, 0xca, 0x20, 0x62, 0xd6, 0x44, 0x62, 0xcf, 0x00, 0x62, 0xcb, 0x00, 0x62, 0xc8, 0x00, 0x62, 0xcc, 0x00, 0x62, 0xc9, 0x00, 0x62, 0xd7, 0x00, 0x62, 0xa9, 0x00, 0x62, 0x2b, 0x00, 0x62, 0xb0, 0x00, 0x62, 0xb3, 0x02, 0x62, 0xb6, 0x00, 0x62, 0xb2, 0x00, 0x62, 0xb5, 0x00, 0x62, 0xb8, 0x00, 0x62, 0xb1, 0x00, 0x62, 0xb4, 0x00, 0x62, 0xb7, 0x00, 0x62, 0x33
, 0x00, 0x62, 0x34, 0x00, 0x62, 0x35, 0x00, 0x71, 0x10, 0x62, 0x54, 0x00, 0x62, 0x55, 0x00, 0x62, 0x56, 0x00, 0x62, 0x57, 0x00, 0x62, 0x58, 0x00, 0x62, 0x59, 0x00, 0x62, 0x5a, 0x00, 0x62, 0x5b, 0x00, 0x62, 0xdc, 0x00, 0x62, 0xe2, 0x00, 0x62, 0xdd, 0x00, 0x62, 0xd8, 0x02, 0x62, 0xd9, 0x00, 0x62, 0xda, 0x28, 0x62, 0xdb, 0x00, 0x62, 0xdf, 0x00, 0x62, 0x29, 0x00, 0x62, 0x30, 0x00, 0x62
, 0xbd, 0x00, 0x70, 0xef, 0x70, 0xef, 0x62, 0x00, 0x00, 0x71, 0x10, 0x62, 0x00, 0x00, 0x62, 0x01, 0x9a, 0x70, 0xef, 0x62, 0x04, 0x17, 0x71, 0x10, 0x62, 0x04, 0x17, 0x62, 0x05, 0xab, 0x70, 0xef, 0x62, 0x08, 0x00, 0x71, 0x10, 0x62, 0x08, 0x00, 0x62, 0x09, 0x28, 0x70, 0xef, 0x62, 0x0c, 0x00, 0x71, 0x10, 0x62, 0x0c, 0x00, 0x62, 0x0d, 0x00, 0x70, 0xef, 0x62, 0x10, 0x00, 0x71, 0x10, 0x62
, 0x10, 0x00, 0x62, 0x11, 0x00, 0x70, 0xef, 0x62, 0x01, 0x00, 0x62, 0x05, 0x00, 0x62, 0x09, 0x00, 0x62, 0x0d, 0x00, 0x62, 0x11, 0x00, 0x70, 0xef, 0x7f, 0x55, 0x02, 0x00, 0x55, 0x03, 0x17, 0x55, 0x04, 0x00, 0x7c, 0x03, 0xa6, 0x7f, 0x7c, 0x02, 0x42, 0x70, 0xef, 0x7f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x62, 0xd0, 0x00, 0x53
, 0x00, 0x71, 0x10, 0x5d, 0xe0, 0x08, 0x21, 0xf8, 0x29, 0x00, 0x70, 0xfe, 0x60, 0xe0, 0x70, 0xef, 0x4b, 0x4b, 0x4b, 0x4b, 0x51, 0x02, 0x21, 0xf7, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08
, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x6e, 0x00, 0xc0, 0x05
, 0x21, 0xf7, 0x80, 0x05, 0x29, 0x08, 0x80, 0x01, 0x60, 0x00, 0x47, 0x00, 0x00, 0x49, 0x01, 0x00, 0x29, 0x08, 0x60, 0x00, 0x57, 0x01, 0x79, 0xbf, 0xfe, 0x18, 0x71, 0x10, 0x60, 0xe0, 0x70, 0xef, 0x71, 0x01, 0x7f, 0x08, 0x67, 0x67, 0x67, 0x67, 0x21, 0x0f, 0xff, 0x40, 0x9f, 0x4e, 0x18, 0x21, 0x0f, 0xff, 0x39, 0x9f, 0x47, 0x7f, 0x08, 0x10, 0x28, 0xa0, 0x0b, 0x9f, 0x3f, 0x20, 0x18, 0x75
, 0xdf, 0xf5, 0x74, 0x8f, 0xf2, 0x38, 0xfe, 0x7f, 0x52, 0x00, 0xa0, 0x08, 0x10, 0x9f, 0x2d, 0x20, 0x75, 0x8f, 0xf6, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x50, 0x0d, 0x9f, 0x20, 0x50, 0x0a, 0x9f, 0x1c, 0x7f, 0x70, 0xbf, 0x62, 0xd3, 0x03, 0x4f, 0x52, 0xfb, 0xa0, 0x15, 0x7b, 0xfb, 0x52, 0xfc, 0x59, 0xfd, 0x60, 0xd3, 0x52, 0x00, 0x9f, 0x05, 0x4f, 0x62, 0xd3, 0x03, 0x77, 0xfd, 0x8f, 0xe9, 0x70
, 0x3f, 0x71, 0xc0, 0x7f, 0x3d, 0xfa, 0x00, 0xb0, 0x06, 0x3d, 0xfb, 0x00, 0xa0, 0x18, 0x10, 0x52, 0xfc, 0x59, 0xfd, 0x28, 0x9e, 0xe6, 0x20, 0x07, 0xfd, 0x01, 0x0f, 0xfc, 0x00, 0x17, 0xfb, 0x01, 0x1f, 0xfa, 0x00, 0x8f, 0xe0, 0x7f, 0x50, 0x01, 0x80, 0x03, 0x50, 0x00, 0x62, 0xd0, 0x00, 0x29, 0x00, 0xa0, 0x06, 0x26, 0x03, 0xfb, 0x80, 0x04, 0x2e, 0x03, 0x04, 0x51, 0x03, 0x60, 0x04, 0x70
, 0x3f, 0x71, 0xc0, 0x7f, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x50, 0x01, 0x80, 0x03, 0x50, 0x00, 0x62, 0xd0, 0x00, 0x29, 0x00, 0xa0, 0x06, 0x26, 0x03, 0xef, 0x80, 0x04, 0x2e, 0x03, 0x10, 0x51, 0x03, 0x60, 0x04, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x08, 0x10, 0x70, 0x3f, 0x71, 0x80, 0x5d, 0xd3, 0x08, 0x5d, 0xd0, 0x08, 0x62, 0xd0, 0x00, 0x51, 0x08, 0x60, 0xd3, 0x2e
, 0x05, 0x80, 0x49, 0xd7, 0x08, 0xa0, 0x09, 0x26, 0x05, 0xf0, 0x2e, 0x05, 0x00, 0x80, 0x08, 0x49, 0xd7, 0x20, 0xa0, 0x03, 0x80, 0xa6, 0x51, 0x05, 0x21, 0x0e, 0xe0, 0x01, 0x80, 0x11, 0x80, 0x67, 0x80, 0x79, 0x80, 0x47, 0x80, 0x96, 0x80, 0x94, 0x80, 0x92, 0x80, 0x90, 0x80, 0x97, 0x5d, 0xd8, 0x21, 0xfe, 0x39, 0x40, 0xa0, 0x06, 0x62, 0xd7, 0x00, 0x80, 0x8a, 0x49, 0xd8, 0x01, 0xb0, 0x0f
, 0x55, 0x0c, 0x02, 0x26, 0x05, 0xf0, 0x2e, 0x05, 0x02, 0x62, 0xd7, 0x10, 0x80, 0x77, 0x55, 0x0c, 0x01, 0x26, 0x05, 0xf0, 0x2e, 0x05, 0x06, 0x5f, 0x07, 0x06, 0x51, 0x09, 0x02, 0x07, 0x5c, 0x52, 0x00, 0x60, 0xd8, 0x76, 0x07, 0x62, 0xd7, 0x14, 0x80, 0x5b, 0x51, 0x0a, 0x78, 0x3a, 0x07, 0xc0, 0x0f, 0x51, 0x09, 0x02, 0x07, 0x5c, 0x52, 0x00, 0x60, 0xd8, 0x76, 0x07, 0x2e, 0x05, 0x20, 0x60
, 0xd8, 0x62, 0xd7, 0x04, 0x80, 0x3f, 0x5d, 0xd8, 0x3a, 0x0a, 0xd0, 0x2b, 0xa0, 0x29, 0x53, 0x07, 0x53, 0x06, 0x26, 0x05, 0xf0, 0x2e, 0x05, 0x04, 0x80, 0x18, 0x51, 0x0b, 0x78, 0x3a, 0x07, 0xc0, 0x16, 0x51, 0x09, 0x02, 0x07, 0x5c, 0x5d, 0xd8, 0x54, 0x00, 0x2e, 0x05, 0x10, 0x76, 0x07, 0x80, 0x01, 0x62, 0xd7, 0x10, 0x80, 0x0f, 0x62, 0xd7, 0x00, 0x80, 0x0a, 0x26, 0x05, 0xf0, 0x2e, 0x05
, 0x00, 0x55, 0x0c, 0x00, 0x18, 0x60, 0xd0, 0x18, 0x60, 0xd3, 0x20, 0x18, 0x7e, 0x62, 0xd0, 0x00, 0x71, 0x10, 0x41, 0x04, 0xfc, 0x43, 0x05, 0x03, 0x70, 0xef, 0x26, 0x03, 0xfc, 0x51, 0x03, 0x60, 0x04, 0x55, 0x0c, 0x00, 0x90, 0x28, 0x90, 0x2d, 0x40, 0x40, 0x40, 0x40, 0x40, 0x50, 0x00, 0x53, 0x06, 0x71, 0x10, 0x43, 0x04, 0x03, 0x43, 0x05, 0x03, 0x70, 0xef, 0x2e, 0x03, 0x03, 0x51, 0x03
, 0x60, 0x04, 0x7f, 0x62, 0xd0, 0x00, 0x51, 0x05, 0x21, 0xb0, 0x26, 0x05, 0x4f, 0x7f, 0x41, 0xe0, 0x7f, 0x43, 0xe0, 0x80, 0x7f, 0x43, 0xd6, 0x31, 0x7f, 0x41, 0xe0, 0x7f, 0x41, 0xd6, 0xfe, 0x7f, 0x62, 0xd0, 0x00, 0x4f, 0x52, 0xfd, 0x53, 0x0a, 0x52, 0xfc, 0x53, 0x0b, 0x52, 0xfb, 0x53, 0x09, 0x52, 0xfa, 0x53, 0x08, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x08, 0x5d, 0xa4, 0x04, 0x1b, 0x5d, 0xa5
, 0x0c, 0x1a, 0x55, 0x1c, 0x01, 0x18, 0x7e, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x70, 0xbf, 0x53, 0x1e, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x8e, 0x62, 0xd3, 0x00, 0x13, 0x6c, 0x62, 0xd3, 0x00, 0x54, 0x70, 0x62, 0xd3, 0x00, 0x52, 0x8d, 0x62, 0xd3, 0x00, 0x1b, 0x6b, 0x62, 0xd3, 0x00, 0x54, 0x6f, 0x48, 0x6f, 0x80, 0xb0, 0x33, 0x3d, 0x6f, 0x00, 0xb0, 0x7b, 0x51, 0x0d, 0x3b, 0x70, 0xc0, 0x75
, 0x52, 0x70, 0x58, 0x1e, 0x01, 0x00, 0x6d, 0x62, 0xd3, 0x00, 0x05, 0x4a, 0xc0, 0x09, 0x51, 0x0f, 0x3b, 0x4a, 0xd0, 0x12, 0xa0, 0x10, 0x56, 0x4a, 0x00, 0x5b, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x07, 0x6c, 0x01, 0x0f, 0x6b, 0x00, 0x80, 0x41, 0x3d, 0x6f, 0xff, 0xb0, 0x09, 0x50, 0xff, 0x12, 0x0e, 0x3b, 0x70, 0xc0, 0x20, 0x62, 0xd3, 0x00, 0x56, 0x70, 0x00, 0x56, 0x6f, 0x00, 0x5b, 0x67, 0x5c
, 0x62, 0xd3, 0x00, 0x52, 0x51, 0x78, 0xd0, 0x03, 0x50, 0x00, 0x54, 0x51, 0x08, 0x5b, 0x64, 0x5c, 0x18, 0xb0, 0x2c, 0x62, 0xd3, 0x00, 0x52, 0x8e, 0x62, 0xd3, 0x00, 0x54, 0x6c, 0x62, 0xd3, 0x00, 0x52, 0x8d, 0x62, 0xd3, 0x00, 0x54, 0x6b, 0x51, 0x1e, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x56, 0x70, 0x00, 0x56, 0x6f, 0x00, 0x5b, 0x67, 0x5c, 0x62, 0xd3, 0x00, 0x51, 0x12, 0x54, 0x51, 0x70, 0x3f
, 0x71, 0xc0, 0x7f, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x70, 0xbf, 0x08, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x4c, 0x53, 0x19, 0x55, 0x18, 0x00, 0x18, 0x08, 0x90, 0x7e, 0x62, 0xd3, 0x00, 0x23, 0x4e, 0xb0, 0x2c, 0x51, 0x10, 0x04, 0x19, 0x0e, 0x18, 0x00, 0x18, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x70, 0x12, 0x19, 0x52, 0x6f, 0x1a, 0x18, 0xc0, 0x39, 0x5b, 0x67, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x4f
, 0x78, 0x54, 0x4f, 0x08, 0x5b, 0x64, 0x5c, 0x18, 0xb0, 0x3e, 0x80, 0x18, 0x51, 0x10, 0x14, 0x19, 0x1e, 0x18, 0x00, 0x18, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x70, 0x12, 0x19, 0x52, 0x6f, 0x1a, 0x18, 0xc0, 0x0e, 0x5b, 0x67, 0x90, 0x31, 0x62, 0xd3, 0x00, 0x2d, 0x4e, 0x50, 0x01, 0x80, 0x24, 0x5b, 0x67, 0x08, 0x90, 0x23, 0x73, 0x62, 0xd3, 0x00, 0x25, 0x4e, 0x62, 0xd3, 0x00, 0x20, 0x51
, 0x11, 0x54, 0x4f, 0x50, 0x00, 0x80, 0x0d, 0x5b, 0x67, 0x90, 0x0d, 0x73, 0x62, 0xd3, 0x00, 0x25, 0x4e, 0x50, 0x00, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x08, 0x67, 0x67, 0x67, 0x5c, 0x18, 0x21, 0x07, 0xf0, 0x01, 0x7f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x70, 0xbf, 0x70, 0xbf, 0x62, 0xd3, 0x00, 0x50, 0x02, 0x78, 0x08, 0x5c, 0x56, 0x4c, 0x32, 0x18, 0x78, 0xdf, 0xf8, 0x70, 0x3f
, 0x71, 0xc0, 0x7f, 0x08, 0x91, 0xb2, 0x70, 0xbf, 0x18, 0x08, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x8e, 0x62, 0xd3, 0x00, 0x54, 0x6c, 0x62, 0xd3, 0x00, 0x52, 0x8d, 0x62, 0xd3, 0x00, 0x54, 0x6b, 0x18, 0x78, 0xdf, 0xe0, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x62, 0xd0, 0x00, 0x55, 0x14, 0x00, 0x50, 0x02, 0x78, 0x08, 0x9f, 0x0e, 0x39, 0x01, 0xb0, 0x04, 0x55, 0x14, 0x01, 0x18, 0x78, 0xdf, 0xf3
, 0x51, 0x14, 0x7f, 0x50, 0x02, 0x78, 0x08, 0x9e, 0x3e, 0x18, 0x78, 0xdf, 0xfa, 0x7f, 0x98, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0xd8, 0xd9, 0xda, 0xdb, 0xdf, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x62, 0xd3, 0x00, 0x57, 0x00, 0x56, 0x4e, 0x00, 0x79, 0xdf, 0xfb, 0x62, 0xd3, 0x00, 0x57, 0x01, 0x50, 0x03, 0x54, 0x4f, 0x79, 0xdf
, 0xfc, 0x62, 0xd3, 0x00, 0x50, 0x14, 0x57, 0x01, 0x54, 0x51, 0x79, 0xdf, 0xfc, 0x70, 0x3f, 0x71, 0xc0, 0x55, 0x0d, 0x1e, 0x55, 0x0e, 0x05, 0x55, 0x0f, 0x14, 0x55, 0x10, 0x01, 0x55, 0x11, 0x03, 0x55, 0x12, 0x14, 0x55, 0x22, 0x04, 0x55, 0x1f, 0x14, 0x43, 0x61, 0x0d, 0x57, 0x00, 0x50, 0x02, 0x90, 0xae, 0x50, 0x04, 0xff, 0x98, 0x29, 0x00, 0x60, 0xa9, 0x62, 0xa0, 0x08, 0x43, 0xa2, 0x04
, 0x62, 0xa3, 0x70, 0x43, 0x7a, 0x01, 0x43, 0xaa, 0x02, 0x43, 0xdf, 0x01, 0x50, 0x01, 0x57, 0x09, 0x90, 0x20, 0x90, 0x55, 0x57, 0x01, 0x50, 0xb3, 0x91, 0x5d, 0x50, 0x00, 0x57, 0x0e, 0x90, 0x12, 0x90, 0x47, 0x7f, 0x53, 0x22, 0xff, 0x67, 0x29, 0x00, 0x60, 0xa9, 0x51, 0x21, 0x58, 0x20, 0x90, 0x01, 0x7f, 0x62, 0xd0, 0x00, 0x21, 0x03, 0x53, 0x21, 0x64, 0x64, 0x64, 0x64, 0x64, 0x29, 0x80
, 0x60, 0xa1, 0x5b, 0x78, 0x21, 0x0f, 0x29, 0x08, 0x74, 0x53, 0x20, 0x12, 0x22, 0x02, 0x21, 0x5c, 0x50, 0x00, 0x53, 0x1d, 0x53, 0x23, 0x29, 0x01, 0x79, 0xa0, 0x08, 0x64, 0x6b, 0x1d, 0x6b, 0x23, 0x8f, 0xf5, 0x60, 0xb5, 0x51, 0x1d, 0x60, 0xb4, 0x7f, 0x50, 0x02, 0x78, 0x08, 0x90, 0x28, 0x90, 0x5a, 0x18, 0x78, 0xdf, 0xf8, 0x7f, 0x41, 0xdf, 0xfe, 0x71, 0x10, 0x41, 0xd8, 0xfd, 0x70, 0xef
, 0x41, 0x61, 0xf3, 0x41, 0xa2, 0xfb, 0x41, 0xa0, 0xf7, 0x62, 0xa3, 0x00, 0x62, 0xa9, 0x00, 0x41, 0xaa, 0xfd, 0x7f, 0x02, 0x20, 0x02, 0x08, 0x64, 0x5c, 0xff, 0xf8, 0x4b, 0x74, 0xff, 0xf4, 0x7f, 0x62, 0xd0, 0x00, 0x53, 0x1d, 0x10, 0x5b, 0x64, 0x64, 0x5c, 0x71, 0x10, 0x5e, 0x01, 0x2a, 0x1d, 0x61, 0x01, 0x36, 0x1d, 0xff, 0x5e, 0x00, 0x22, 0x1d, 0x61, 0x00, 0x36, 0x1d, 0xff, 0x18, 0xfe
, 0xd6, 0x5c, 0x5e, 0x00, 0x2a, 0x1d, 0x61, 0x00, 0x70, 0xef, 0x7f, 0x62, 0xd0, 0x00, 0x10, 0x73, 0x53, 0x1d, 0x71, 0x10, 0x5b, 0xfe, 0xc0, 0x5c, 0x5e, 0x00, 0x22, 0x1d, 0x61, 0x00, 0x70, 0xef, 0x18, 0x64, 0x64, 0x5c, 0x71, 0x10, 0x5e, 0x01, 0x22, 0x1d, 0x61, 0x01, 0x36, 0x1d, 0xff, 0x5e, 0x00, 0x2a, 0x1d, 0x61, 0x00, 0x70, 0xef, 0x7f, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x53, 0x1e, 0x50
, 0x00, 0x53, 0x1a, 0x53, 0x1b, 0x51, 0x1e, 0x5c, 0x62, 0xd3, 0x00, 0x52, 0x24, 0x53, 0x1f, 0x43, 0xa0, 0x01, 0x51, 0x1f, 0x60, 0xfd, 0x41, 0xa3, 0xdf, 0x51, 0x1e, 0x9f, 0x7a, 0x9f, 0x81, 0x58, 0x23, 0x55, 0x1c, 0x00, 0x62, 0xa5, 0x00, 0x62, 0xa4, 0x00, 0x43, 0xb3, 0x01, 0x51, 0x1c, 0xaf, 0xfd, 0x79, 0xdf, 0xee, 0x51, 0x1e, 0x9f, 0x5f, 0x9f, 0x91, 0x43, 0xa3, 0x20, 0x41, 0xa0, 0xfe
, 0x62, 0xfd, 0x00, 0x50, 0xff, 0x4c, 0x1b, 0x14, 0x1b, 0x51, 0x20, 0x11, 0x08, 0xfe, 0x4d, 0x4c, 0x1a, 0x1c, 0x1a, 0xd0, 0x07, 0x55, 0x1a, 0x00, 0x55, 0x1b, 0x00, 0x51, 0x1e, 0x64, 0x5c, 0x62, 0xd3, 0x00, 0x51, 0x1b, 0x54, 0x8e, 0x51, 0x1a, 0x54, 0x8d, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x08, 0x9f, 0x86, 0x18, 0x78, 0xdf, 0xfa, 0x7f, 0x70, 0xbf, 0x62, 0xd0, 0x00, 0x53, 0x27, 0x5a, 0x26
, 0x55, 0x1e, 0x01, 0x62, 0xd3, 0x00, 0x58, 0x1e, 0x56, 0x24, 0x80, 0x55, 0x29, 0x08, 0x55, 0x28, 0x80, 0x51, 0x1e, 0x9f, 0x63, 0x51, 0x1e, 0x9f, 0x5f, 0x70, 0xbf, 0x58, 0x1e, 0x62, 0xd3, 0x00, 0x51, 0x1b, 0x3a, 0x27, 0x51, 0x1a, 0x1a, 0x26, 0xd0, 0x06, 0x51, 0x28, 0x73, 0x25, 0x24, 0x68, 0x28, 0x26, 0x28, 0x7f, 0x51, 0x28, 0x2d, 0x24, 0x7a, 0x29, 0xbf, 0xd6, 0x7a, 0x1e, 0xdf, 0xc4
, 0x70, 0x3f, 0x71, 0xc0, 0x7f, 0x62, 0xd0, 0x00, 0x51, 0x94, 0x11, 0x35, 0x51, 0x93, 0x19, 0x0c, 0xd0, 0x12, 0x7c, 0x14, 0x91, 0x39, 0x0f, 0xa0, 0x16, 0x62, 0xd0, 0x00, 0x76, 0x94, 0x0e, 0x93, 0x00, 0x80, 0x0c, 0x62, 0xd0, 0x00, 0x55, 0x94, 0x00, 0x55, 0x93, 0x00, 0x90, 0xa9, 0x7f, 0x62, 0xd0, 0x00, 0x3c, 0x9e, 0xf0, 0xd0, 0x03, 0x76, 0x9e, 0x62, 0xd0, 0x00, 0x51, 0x2f, 0x21, 0x7f
, 0x53, 0x49, 0x51, 0x9e, 0x3a, 0x49, 0xb0, 0x50, 0x7c, 0x14, 0x91, 0x62, 0xd0, 0x00, 0x53, 0x9f, 0x3c, 0x9f, 0x0f, 0xa0, 0x3d, 0x3c, 0x9b, 0x00, 0xb0, 0x1c, 0x55, 0x89, 0x00, 0x55, 0x8a, 0x00, 0x51, 0x9f, 0x53, 0x48, 0x55, 0x49, 0x00, 0x06, 0x48, 0x89, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd5, 0x50, 0x08, 0x3f, 0x48, 0x62, 0xd0, 0x00, 0x55, 0x98, 0x00, 0x3c, 0x9d, 0x00, 0xb0, 0x0a
, 0x7c, 0x15, 0x26, 0x62, 0xd0, 0x00, 0x55, 0x9d, 0x01, 0x62, 0xd0, 0x00, 0x55, 0x97, 0x05, 0x80, 0x07, 0x62, 0xd0, 0x00, 0x55, 0x9e, 0x00, 0x7f, 0x62, 0xd0, 0x00, 0x55, 0x94, 0x00, 0x55, 0x93, 0x00, 0x3c, 0x9d, 0x01, 0xb0, 0x31, 0x7a, 0x97, 0x3c, 0x97, 0x00, 0xb0, 0x2a, 0x3c, 0x9d, 0x01, 0xb0, 0x0a, 0x7c, 0x15, 0xb9, 0x62, 0xd0, 0x00, 0x55, 0x9d, 0x00, 0x62, 0xd0, 0x00, 0x3c, 0x9b
, 0x00, 0xb0, 0x0e, 0x51, 0x9f, 0x53, 0x48, 0x55, 0x49, 0x00, 0x06, 0x48, 0x89, 0x7c, 0x1b, 0x67, 0x62, 0xd0, 0x00, 0x55, 0x9e, 0x00, 0x7f, 0x10, 0x4f, 0x38, 0x16, 0x62, 0xd0, 0x00, 0x3c, 0x9a, 0x00, 0xb0, 0x05, 0x51, 0x79, 0x53, 0x24, 0x56, 0x0d, 0x00, 0x80, 0x67, 0x56, 0x00, 0x00, 0x80, 0x5b, 0x62, 0xd0, 0x00, 0x3c, 0x9a, 0x00, 0xb0, 0x1b, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00
, 0x06, 0x48, 0x79, 0x7c, 0x1a, 0x6d, 0x52, 0x00, 0x53, 0x46, 0x55, 0x47, 0x00, 0x06, 0x46, 0x24, 0x7c, 0x1b, 0x23, 0x10, 0x52, 0x00, 0x7c, 0x09, 0xb8, 0x20, 0x10, 0x7c, 0x06, 0x43, 0x62, 0xd0, 0x00, 0x20, 0x39, 0x00, 0xbf, 0xee, 0x7c, 0x19, 0xdc, 0x52, 0x0d, 0x7c, 0x1b, 0x5b, 0x02, 0x48, 0x53, 0x48, 0x51, 0x47, 0x0a, 0x49, 0x53, 0x49, 0x7c, 0x1b, 0x17, 0x06, 0x46, 0x8d, 0x0e, 0x47
, 0x00, 0x51, 0x47, 0x7c, 0x1a, 0x79, 0x7c, 0x1a, 0x8f, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xcf, 0xa2, 0x77, 0x0d, 0x3d, 0x0d, 0x03, 0xcf, 0x96, 0x56, 0x00, 0x00, 0x81, 0x05, 0x7c, 0x19, 0xc0, 0x7c, 0x1a, 0x28, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x54, 0x0e, 0x3e, 0x48, 0x54, 0x0f, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x55, 0x46, 0x06, 0x55, 0x47, 0x00, 0x55, 0x41, 0x00, 0x55, 0x40
, 0x00, 0x3c, 0x47, 0x00, 0xb0, 0x06, 0x3c, 0x46, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e, 0x47, 0x6e, 0x46, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x48, 0x04, 0x41, 0x51, 0x49, 0x0c, 0x40, 0x65, 0x48, 0x6b, 0x49, 0x8f, 0xde, 0x5f, 0x48, 0x41, 0x5f, 0x49, 0x40, 0x62, 0xd0, 0x00, 0x5a, 0x46, 0x06, 0x46, 0x03, 0x51, 0x46, 0x04, 0x48, 0x0e, 0x49, 0x03, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x54
, 0x10, 0x3e, 0x48, 0x54, 0x11, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x55, 0x46, 0x06, 0x55, 0x47, 0x00, 0x55, 0x41, 0x00, 0x55, 0x40, 0x00, 0x3c, 0x47, 0x00, 0xb0, 0x06, 0x3c, 0x46, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e, 0x47, 0x6e, 0x46, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x48, 0x04, 0x41, 0x51, 0x49, 0x0c, 0x40, 0x65, 0x48, 0x6b, 0x49, 0x8f, 0xde, 0x5f, 0x48, 0x41, 0x5f, 0x49
, 0x40, 0x62, 0xd0, 0x00, 0x5a, 0x46, 0x06, 0x46, 0x05, 0x51, 0x46, 0x04, 0x48, 0x0e, 0x49, 0x03, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x54, 0x12, 0x3e, 0x48, 0x54, 0x13, 0x50, 0x03, 0x08, 0x5a, 0x48, 0x06, 0x48, 0x0e, 0x08, 0x51, 0x48, 0x08, 0x7c, 0x18, 0x3d, 0x38, 0xfd, 0x62, 0xd0, 0x00, 0x51, 0x48, 0x54, 0x15, 0x51, 0x49, 0x54, 0x14, 0x7c, 0x19, 0xb4, 0x7c, 0x1a, 0xa7, 0x7c, 0x1a
, 0xf1, 0x06, 0x48, 0x6b, 0x7c, 0x1b, 0x07, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x5b, 0x7c, 0x1a, 0xc8, 0x51, 0x48, 0x01, 0x63, 0x7c, 0x1a, 0xc8, 0x06, 0x48, 0x53, 0x7c, 0x1b, 0x07, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xce, 0xf8, 0x38, 0xea, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x16, 0x10, 0x57, 0x09, 0x50, 0x01, 0x7c, 0x08, 0xf2, 0x20, 0x62, 0xd0, 0x00, 0x50, 0x02, 0x10, 0x08, 0x57, 0x30, 0x28
, 0x53, 0x49, 0x18, 0x75, 0x09, 0x00, 0x28, 0x53, 0x48, 0x20, 0x10, 0x51, 0x49, 0x08, 0x51, 0x48, 0x20, 0x7c, 0x0a, 0x37, 0x20, 0x10, 0x57, 0x0e, 0x50, 0x00, 0x7c, 0x08, 0xf2, 0x20, 0x62, 0xd0, 0x00, 0x3c, 0x9a, 0x01, 0xb0, 0x0b, 0x51, 0x24, 0x53, 0x30, 0x51, 0x25, 0x53, 0x31, 0x80, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x79, 0x53, 0x24, 0x51, 0x7a, 0x53, 0x25, 0x10, 0x50, 0x00, 0x7c, 0x09
, 0xb8, 0x20, 0x56, 0x0d, 0x00, 0x80, 0x67, 0x56, 0x00, 0x00, 0x80, 0x5b, 0x62, 0xd0, 0x00, 0x3c, 0x9a, 0x00, 0xb0, 0x1b, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x06, 0x48, 0x79, 0x7c, 0x1a, 0x6d, 0x52, 0x00, 0x53, 0x46, 0x55, 0x47, 0x00, 0x06, 0x46, 0x24, 0x7c, 0x1b, 0x23, 0x10, 0x52, 0x00, 0x7c, 0x09, 0xb8, 0x20, 0x10, 0x7c, 0x06, 0x43, 0x62, 0xd0, 0x00, 0x20, 0x39, 0x00, 0xbf
, 0xee, 0x7c, 0x19, 0xdc, 0x52, 0x0d, 0x7c, 0x1b, 0x5b, 0x02, 0x48, 0x53, 0x48, 0x51, 0x47, 0x0a, 0x49, 0x53, 0x49, 0x7c, 0x1b, 0x17, 0x06, 0x46, 0x8d, 0x0e, 0x47, 0x00, 0x51, 0x47, 0x7c, 0x1a, 0x79, 0x7c, 0x1a, 0x8f, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xcf, 0xa2, 0x77, 0x0d, 0x3d, 0x0d, 0x03, 0xcf, 0x96, 0x56, 0x00, 0x00, 0x81, 0x05, 0x7c, 0x19, 0xc0, 0x7c, 0x1a, 0x28, 0x51, 0x49, 0x60
, 0xd4, 0x3e, 0x48, 0x54, 0x0e, 0x3e, 0x48, 0x54, 0x0f, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x55, 0x46, 0x06, 0x55, 0x47, 0x00, 0x55, 0x41, 0x00, 0x55, 0x40, 0x00, 0x3c, 0x47, 0x00, 0xb0, 0x06, 0x3c, 0x46, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e, 0x47, 0x6e, 0x46, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x48, 0x04, 0x41, 0x51, 0x49, 0x0c, 0x40, 0x65, 0x48, 0x6b, 0x49, 0x8f, 0xde, 0x5f
, 0x48, 0x41, 0x5f, 0x49, 0x40, 0x62, 0xd0, 0x00, 0x5a, 0x46, 0x06, 0x46, 0x03, 0x51, 0x46, 0x04, 0x48, 0x0e, 0x49, 0x03, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x54, 0x10, 0x3e, 0x48, 0x54, 0x11, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x55, 0x46, 0x06, 0x55, 0x47, 0x00, 0x55, 0x41, 0x00, 0x55, 0x40, 0x00, 0x3c, 0x47, 0x00, 0xb0, 0x06, 0x3c, 0x46, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e
, 0x47, 0x6e, 0x46, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x48, 0x04, 0x41, 0x51, 0x49, 0x0c, 0x40, 0x65, 0x48, 0x6b, 0x49, 0x8f, 0xde, 0x5f, 0x48, 0x41, 0x5f, 0x49, 0x40, 0x62, 0xd0, 0x00, 0x5a, 0x46, 0x06, 0x46, 0x05, 0x51, 0x46, 0x04, 0x48, 0x0e, 0x49, 0x03, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x54, 0x12, 0x3e, 0x48, 0x54, 0x13, 0x50, 0x03, 0x08, 0x5a, 0x48, 0x06, 0x48, 0x0e, 0x08
, 0x51, 0x48, 0x08, 0x7c, 0x18, 0x3d, 0x38, 0xfd, 0x62, 0xd0, 0x00, 0x51, 0x48, 0x54, 0x15, 0x51, 0x49, 0x54, 0x14, 0x7c, 0x19, 0xb4, 0x7c, 0x1a, 0xa7, 0x7c, 0x1a, 0xf1, 0x06, 0x48, 0x6b, 0x7c, 0x1b, 0x07, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x5b, 0x7c, 0x1a, 0xc8, 0x51, 0x48, 0x01, 0x63, 0x7c, 0x1a, 0xc8, 0x06, 0x48, 0x53, 0x7c, 0x1b, 0x07, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xce, 0xf8
, 0x56, 0x00, 0x00, 0x80, 0x19, 0x7c, 0x19, 0xc0, 0x06, 0x48, 0x24, 0x7c, 0x1a, 0x6d, 0x52, 0x00, 0x53, 0x46, 0x55, 0x47, 0x00, 0x06, 0x46, 0x30, 0x7c, 0x1b, 0x23, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xcf, 0xe4, 0x38, 0xea, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x02, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x01, 0x02, 0x53, 0x48, 0x52, 0xfb, 0x09, 0x00, 0x7c, 0x1a, 0x9c, 0x52, 0xfc, 0x01, 0x04, 0x53, 0x46
, 0x52, 0xfb, 0x7c, 0x1a, 0x84, 0x12, 0x48, 0x51, 0x47, 0x1a, 0x49, 0xc0, 0x6f, 0x52, 0xfc, 0x53, 0x48, 0x52, 0xfb, 0x7c, 0x1a, 0x9c, 0x52, 0xfc, 0x01, 0x02, 0x53, 0x46, 0x52, 0xfb, 0x7c, 0x1a, 0x84, 0x12, 0x48, 0x51, 0x47, 0x1a, 0x49, 0xc0, 0x10, 0x52, 0xfc, 0x01, 0x02, 0x7c, 0x1a, 0xe6, 0x54, 0x00, 0x3e, 0x48, 0x54, 0x01, 0x80, 0xb3, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x01, 0x04, 0x53
, 0x48, 0x52, 0xfb, 0x09, 0x00, 0x7c, 0x1a, 0x9c, 0x52, 0xfc, 0x53, 0x46, 0x52, 0xfb, 0x60, 0xd4, 0x3e, 0x46, 0x53, 0x47, 0x3e, 0x46, 0x12, 0x48, 0x51, 0x47, 0x1a, 0x49, 0xc0, 0x10, 0x52, 0xfc, 0x01, 0x04, 0x7c, 0x1a, 0xe6, 0x54, 0x00, 0x3e, 0x48, 0x54, 0x01, 0x80, 0x7e, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x53, 0x48, 0x52, 0xfb, 0x7c, 0x1a, 0xfc, 0x80, 0x70, 0x62, 0xd0, 0x00, 0x52, 0xfc
, 0x53, 0x48, 0x52, 0xfb, 0x7c, 0x1a, 0x9c, 0x52, 0xfc, 0x01, 0x04, 0x53, 0x46, 0x52, 0xfb, 0x7c, 0x1a, 0x84, 0x12, 0x48, 0x51, 0x47, 0x1a, 0x49, 0xc0, 0x10, 0x52, 0xfc, 0x01, 0x04, 0x7c, 0x1a, 0xe6, 0x54, 0x00, 0x3e, 0x48, 0x54, 0x01, 0x80, 0x42, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x01, 0x02, 0x53, 0x48, 0x52, 0xfb, 0x09, 0x00, 0x7c, 0x1a, 0x9c, 0x52, 0xfc, 0x53, 0x46, 0x52, 0xfb, 0x60
, 0xd4, 0x3e, 0x46, 0x53, 0x47, 0x3e, 0x46, 0x12, 0x48, 0x51, 0x47, 0x1a, 0x49, 0xc0, 0x10, 0x52, 0xfc, 0x01, 0x02, 0x7c, 0x1a, 0xe6, 0x54, 0x00, 0x3e, 0x48, 0x54, 0x01, 0x80, 0x0d, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x53, 0x48, 0x52, 0xfb, 0x7c, 0x1a, 0xfc, 0x62, 0xd0, 0x00, 0x52, 0x01, 0x53, 0x48, 0x52, 0x00, 0x53, 0x49, 0x38, 0xfe, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x05, 0x62, 0xd0, 0x00
, 0x55, 0x96, 0x00, 0x3c, 0x9a, 0x00, 0xb0, 0x05, 0x51, 0x79, 0x53, 0x24, 0x10, 0x50, 0x00, 0x7c, 0x09, 0xb8, 0x20, 0x56, 0x00, 0x00, 0x80, 0x38, 0x62, 0xd0, 0x00, 0x3c, 0x9a, 0x00, 0xb0, 0x1b, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x06, 0x48, 0x79, 0x7c, 0x1a, 0x6d, 0x52, 0x00, 0x53, 0x46, 0x55, 0x47, 0x00, 0x06, 0x46, 0x24, 0x7c, 0x1b, 0x23, 0x10, 0x52, 0x00, 0x7c, 0x09, 0xb8
, 0x20, 0x10, 0x7c, 0x06, 0x43, 0x62, 0xd0, 0x00, 0x20, 0x39, 0x00, 0xbf, 0xee, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xcf, 0xc5, 0x56, 0x00, 0x00, 0x83, 0x04, 0x62, 0xd0, 0x00, 0x3c, 0xa0, 0x02, 0xa0, 0x9f, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x6b, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x8d, 0x7c, 0x1a, 0x6d, 0x7c, 0x1a, 0xd9, 0xd0, 0x16, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x6b, 0x7c, 0x19, 0xcb
, 0x06, 0x48, 0x8d, 0x7c, 0x1a, 0x6d, 0x7c, 0x1b, 0x73, 0x80, 0x17, 0x62, 0xd0, 0x00, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x8d, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x6b, 0x7c, 0x1a, 0x6d, 0x7c, 0x1b, 0x73, 0x50, 0xfa, 0x13, 0x02, 0x50, 0x00, 0x1b, 0x01, 0xc0, 0x4e, 0x62, 0xd0, 0x00, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x53, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x8d, 0x7c, 0x1a, 0x6d, 0x7c, 0x1a
, 0xd9, 0xd0, 0x16, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x53, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x8d, 0x7c, 0x1a, 0x6d, 0x7c, 0x1b, 0x80, 0x80, 0x17, 0x62, 0xd0, 0x00, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x8d, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x53, 0x7c, 0x1a, 0x6d, 0x7c, 0x1b, 0x80, 0x50, 0xfa, 0x13, 0x04, 0x50, 0x00, 0x1b, 0x03, 0xd0, 0x08, 0x62, 0xd0, 0x00, 0x76, 0x96, 0x82, 0x5c, 0x62
, 0xd0, 0x00, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x8d, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x53, 0x7c, 0x1a, 0x6d, 0x7c, 0x1a, 0xd9, 0xd0, 0x5a, 0x7c, 0x19, 0xb4, 0x7c, 0x1a, 0xb2, 0x06, 0x46, 0x01, 0x0e, 0x47, 0x00, 0x7c, 0x1a, 0x8f, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x8d, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x53, 0x7c, 0x1a, 0x6d, 0x7c, 0x1a, 0xd9, 0xd0, 0xb4, 0x7c, 0x19, 0xb4, 0x7c, 0x1a
, 0xb2, 0x06, 0x46, 0x01, 0x0e, 0x47, 0x00, 0x7c, 0x1a, 0x8f, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x8d, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x53, 0x7c, 0x1a, 0x6d, 0x7c, 0x1a, 0xd9, 0xd0, 0x90, 0x7c, 0x19, 0xb4, 0x7c, 0x1a, 0xb2, 0x06, 0x46, 0x01, 0x0e, 0x47, 0x00, 0x7c, 0x1a, 0x8f, 0x80, 0x7f, 0x62, 0xd0, 0x00, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x8d, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x53
, 0x7c, 0x1a, 0x6d, 0x3e, 0x48, 0x12, 0x46, 0x51, 0x49, 0x1a, 0x47, 0xd0, 0x62, 0x7c, 0x19, 0xb4, 0x7c, 0x1a, 0xb2, 0x16, 0x46, 0x01, 0x1e, 0x47, 0x00, 0x7c, 0x1a, 0x8f, 0x7c, 0x19, 0xb4, 0x51, 0x48, 0x01, 0x8d, 0x7c, 0x19, 0xcb, 0x06, 0x48, 0x53, 0x7c, 0x1a, 0x6d, 0x3e, 0x48, 0x12, 0x46, 0x51, 0x49, 0x1a, 0x47, 0xd0, 0x39, 0x97, 0xfc, 0x40, 0x7c, 0x1a, 0xb2, 0x16, 0x46, 0x01, 0x1e
, 0x47, 0x00, 0x7c, 0x1a, 0x8f, 0x97, 0xed, 0x40, 0x51, 0x48, 0x01, 0x8d, 0x97, 0xfd, 0x40, 0x06, 0x48, 0x53, 0x7c, 0x1a, 0x6d, 0x3e, 0x48, 0x12, 0x46, 0x51, 0x49, 0x1a, 0x47, 0xd0, 0x10, 0x97, 0xd3, 0x40, 0x7c, 0x1a, 0xb2, 0x16, 0x46, 0x01, 0x1e, 0x47, 0x00, 0x7c, 0x1a, 0x8f, 0x62, 0xd0, 0x00, 0x97, 0xc1, 0x40, 0x51, 0x48, 0x01, 0x63, 0x97, 0xd1, 0x40, 0x06, 0x48, 0x5b, 0x0e, 0x49
, 0x00, 0x7c, 0x1a, 0x8f, 0x97, 0xae, 0x40, 0x51, 0x48, 0x01, 0x53, 0x97, 0xbe, 0x40, 0x06, 0x48, 0x63, 0x0e, 0x49, 0x00, 0x7c, 0x1a, 0x8f, 0x97, 0x9b, 0x40, 0x51, 0x48, 0x01, 0x8d, 0x97, 0xab, 0x40, 0x06, 0x48, 0x53, 0x0e, 0x49, 0x00, 0x7c, 0x1a, 0x8f, 0x97, 0x88, 0x40, 0x06, 0x48, 0x5b, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x53, 0x73, 0x3e, 0x48, 0x53, 0x74, 0x97
, 0x73, 0x40, 0x06, 0x48, 0x63, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x53, 0x75, 0x3e, 0x48, 0x53, 0x76, 0x97, 0x5e, 0x40, 0x06, 0x48, 0x53, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x53, 0x77, 0x3e, 0x48, 0x53, 0x78, 0x50, 0x00, 0x08, 0x50, 0x73, 0x08, 0x9c, 0x75, 0x38, 0xfe, 0x62, 0xd0, 0x00, 0x7c, 0x1b, 0x17, 0x06, 0x46, 0x8d, 0x7c, 0x1b, 0x23, 0x51
, 0x48, 0x3f, 0x46, 0x97, 0x2f, 0x40, 0x7c, 0x1a, 0xa7, 0x53, 0x47, 0x7c, 0x1b, 0x9a, 0x53, 0x44, 0x08, 0x51, 0x45, 0x53, 0x43, 0x18, 0x53, 0x42, 0x65, 0x42, 0x6b, 0x43, 0x06, 0x48, 0x63, 0x97, 0xcc, 0x40, 0x3e, 0x48, 0x53, 0x48, 0x51, 0x42, 0x04, 0x48, 0x51, 0x43, 0x0c, 0x49, 0x51, 0x44, 0x04, 0x48, 0x51, 0x45, 0x0c, 0x49, 0x70, 0xfb, 0x6e, 0x49, 0x6e, 0x48, 0x7c, 0x1b, 0x48, 0x10
, 0x52, 0x00, 0x7c, 0x06, 0x87, 0x20, 0x62, 0xd0, 0x00, 0x96, 0xe9, 0x40, 0x51, 0x48, 0x01, 0x8d, 0x96, 0xf9, 0x40, 0x06, 0x48, 0x6b, 0x97, 0x95, 0x40, 0x97, 0xfe, 0x40, 0xd0, 0x25, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x06, 0x48, 0x85, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x7a, 0x48, 0x53, 0x47, 0x06, 0x47, 0x01, 0x51, 0x49, 0x60, 0xd5, 0x51, 0x47, 0x3f, 0x48
, 0x80, 0x0a, 0x96, 0xbc, 0x40, 0x06, 0x48, 0x85, 0x7c, 0x1b, 0x67, 0x96, 0xb3, 0x40, 0x06, 0x48, 0x85, 0x97, 0x5a, 0x40, 0x50, 0x05, 0x3a, 0x49, 0xd0, 0x41, 0x96, 0x98, 0x40, 0x51, 0x48, 0x01, 0x6b, 0x53, 0x46, 0x51, 0x49, 0x09, 0x00, 0x53, 0x47, 0x06, 0x48, 0x8d, 0x97, 0x3f, 0x40, 0x3e, 0x48, 0x53, 0x48, 0x51, 0x47, 0x7c, 0x1b, 0x9a, 0x02, 0x48, 0x53, 0x48, 0x51, 0x45, 0x0a, 0x49
, 0x53, 0x49, 0x7c, 0x1b, 0x48, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x06, 0x48, 0x85, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd5, 0x50, 0x00, 0x3f, 0x48, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xcc, 0xf9, 0x62, 0xd0, 0x00, 0x3c, 0xa0, 0x02, 0xb0, 0x9a, 0x56, 0x00, 0x00, 0x80, 0x90, 0x62, 0xd0, 0x00, 0x96, 0x41, 0x40, 0x51, 0x48, 0x01, 0x8d, 0x96, 0x51, 0x40, 0x06, 0x48, 0x38, 0x0e, 0x49
, 0x00, 0x97, 0x0c, 0x40, 0x96, 0x2e, 0x40, 0x51, 0x48, 0x01, 0x6b, 0x96, 0x3e, 0x40, 0x06, 0x48, 0x3c, 0x0e, 0x49, 0x00, 0x96, 0xf9, 0x40, 0x96, 0x1b, 0x40, 0x51, 0x48, 0x01, 0x6b, 0x96, 0x2b, 0x40, 0x51, 0x48, 0x01, 0x8d, 0x53, 0x44, 0x51, 0x49, 0x97, 0xe2, 0x40, 0x51, 0x46, 0x12, 0x44, 0x51, 0x47, 0x1a, 0x45, 0xd0, 0x2b, 0x97, 0x5f, 0x40, 0x51, 0x46, 0x01, 0x6b, 0x53, 0x44, 0x51
, 0x47, 0x97, 0xca, 0x40, 0x06, 0x46, 0x8d, 0x0e, 0x47, 0x00, 0x51, 0x47, 0x60, 0xd4, 0x3e, 0x46, 0x53, 0x47, 0x3e, 0x46, 0x12, 0x44, 0x54, 0x02, 0x51, 0x47, 0x1a, 0x45, 0x54, 0x01, 0x80, 0x07, 0x56, 0x02, 0x00, 0x56, 0x01, 0x00, 0x62, 0xd0, 0x00, 0x06, 0x48, 0x34, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd5, 0x52, 0x01, 0x3f, 0x48, 0x52, 0x02, 0x3f, 0x48, 0x77, 0x00, 0x3d, 0x00, 0x02
, 0xcf, 0x6d, 0x62, 0xd0, 0x00, 0x3c, 0xa0, 0x02, 0xa0, 0x18, 0x3c, 0x96, 0x00, 0xa0, 0x13, 0x50, 0x75, 0x08, 0x50, 0x30, 0x08, 0x90, 0x0e, 0x38, 0xfe, 0x7c, 0x0b, 0x57, 0x10, 0x7c, 0x08, 0x43, 0x20, 0x38, 0xfb, 0x20, 0x7f, 0x10, 0x4f, 0x80, 0x02, 0x40, 0x62, 0xd0, 0x00, 0x52, 0xfc, 0x53, 0x48, 0x52, 0xfb, 0x53, 0x49, 0x51, 0x48, 0x11, 0x01, 0x54, 0xfc, 0x51, 0x49, 0x19, 0x00, 0x54
, 0xfb, 0x3c, 0x49, 0x00, 0xbf, 0xe4, 0x3c, 0x48, 0x00, 0xbf, 0xdf, 0x20, 0x7f, 0x10, 0x7c, 0x05, 0x0d, 0x7c, 0x04, 0xea, 0x20, 0x7f, 0x10, 0x7c, 0x05, 0x09, 0x7c, 0x04, 0xe6, 0x20, 0x7f, 0x62, 0xd0, 0x00, 0x51, 0x4c, 0x12, 0x70, 0x50, 0x00, 0x1a, 0x6f, 0xd0, 0x0f, 0x51, 0x4d, 0x12, 0x72, 0x50, 0x00, 0x1a, 0x71, 0xd0, 0x05, 0x50, 0x0f, 0x80, 0x17, 0x62, 0xd0, 0x00, 0x51, 0x72, 0x12
, 0x70, 0x51, 0x71, 0x1a, 0x6f, 0xd0, 0x05, 0x50, 0x00, 0x80, 0x06, 0x62, 0xd0, 0x00, 0x50, 0x01, 0x7f, 0x10, 0x4f, 0x38, 0x05, 0x62, 0xd0, 0x00, 0x51, 0x70, 0x54, 0x02, 0x51, 0x6f, 0x54, 0x01, 0x56, 0x04, 0x00, 0x56, 0x00, 0x00, 0x56, 0x03, 0x00, 0x80, 0x61, 0x95, 0x13, 0x40, 0x06, 0x48, 0x4c, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x53, 0x48, 0x96, 0x59, 0x40, 0x06
, 0x46, 0x6f, 0x0e, 0x47, 0x00, 0x51, 0x47, 0x95, 0xb0, 0x40, 0x51, 0x48, 0x12, 0x46, 0x50, 0x00, 0x1a, 0x47, 0xd0, 0x03, 0x77, 0x03, 0x62, 0xd0, 0x00, 0x94, 0xd9, 0x40, 0x06, 0x48, 0x6f, 0x95, 0x8c, 0x40, 0x3e, 0x48, 0x53, 0x48, 0x52, 0x02, 0x12, 0x48, 0x52, 0x01, 0x1a, 0x49, 0xd0, 0x1a, 0x94, 0xc2, 0x40, 0x06, 0x48, 0x6f, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x54
, 0x01, 0x3e, 0x48, 0x54, 0x02, 0x52, 0x00, 0x54, 0x04, 0x77, 0x00, 0x3d, 0x00, 0x02, 0xcf, 0x9c, 0x50, 0x01, 0x3b, 0x03, 0xd0, 0x08, 0x62, 0xd0, 0x00, 0x50, 0x0f, 0x80, 0x06, 0x52, 0x04, 0x62, 0xd0, 0x00, 0x38, 0xfb, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x02, 0x70, 0xfe, 0x62, 0xd0, 0x00, 0x26, 0x2a, 0xf0, 0x51, 0x9f, 0x01, 0x01, 0x53, 0x49, 0x51, 0x2a, 0x2a, 0x49, 0x53, 0x2a, 0x71, 0x01
, 0x62, 0xe3, 0x38, 0x10, 0x7c, 0x06, 0x43, 0x62, 0xd0, 0x00, 0x20, 0x43, 0x00, 0x08, 0x56, 0x01, 0x00, 0x56, 0x00, 0x00, 0x80, 0x21, 0x10, 0x7c, 0x06, 0x43, 0x62, 0xd0, 0x00, 0x20, 0x53, 0x49, 0x47, 0x49, 0x20, 0xa0, 0x03, 0x80, 0x1a, 0x50, 0x00, 0x08, 0x50, 0x04, 0x08, 0x9e, 0xb6, 0x38, 0xfe, 0x77, 0x01, 0x0f, 0x00, 0x00, 0x52, 0x01, 0x11, 0xdc, 0x52, 0x00, 0x19, 0x05, 0xcf, 0xd7
, 0x56, 0x01, 0x00, 0x56, 0x00, 0x00, 0x80, 0x21, 0x10, 0x7c, 0x06, 0x43, 0x62, 0xd0, 0x00, 0x20, 0x53, 0x49, 0x47, 0x49, 0x20, 0xb0, 0x03, 0x80, 0x1a, 0x50, 0x00, 0x08, 0x50, 0x04, 0x08, 0x9e, 0x84, 0x38, 0xfe, 0x77, 0x01, 0x0f, 0x00, 0x00, 0x52, 0x01, 0x11, 0x2c, 0x52, 0x00, 0x19, 0x01, 0xcf, 0xd7, 0x41, 0x00, 0xf7, 0x38, 0xfe, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x02, 0x70, 0xfe, 0x62
, 0xd0, 0x00, 0x26, 0x2a, 0xf0, 0x51, 0x9f, 0x01, 0x09, 0x53, 0x49, 0x51, 0x2a, 0x2a, 0x49, 0x53, 0x2a, 0x71, 0x01, 0x62, 0xe3, 0x38, 0x10, 0x7c, 0x06, 0x43, 0x62, 0xd0, 0x00, 0x20, 0x43, 0x00, 0x08, 0x56, 0x01, 0x00, 0x56, 0x00, 0x00, 0x80, 0x21, 0x10, 0x7c, 0x06, 0x43, 0x62, 0xd0, 0x00, 0x20, 0x53, 0x49, 0x47, 0x49, 0x20, 0xa0, 0x03, 0x80, 0x1a, 0x50, 0x00, 0x08, 0x50, 0x04, 0x08
, 0x9e, 0x23, 0x38, 0xfe, 0x77, 0x01, 0x0f, 0x00, 0x00, 0x52, 0x01, 0x11, 0xdc, 0x52, 0x00, 0x19, 0x05, 0xcf, 0xd7, 0x56, 0x01, 0x00, 0x56, 0x00, 0x00, 0x80, 0x21, 0x10, 0x7c, 0x06, 0x43, 0x62, 0xd0, 0x00, 0x20, 0x53, 0x49, 0x47, 0x49, 0x20, 0xb0, 0x03, 0x80, 0x1a, 0x50, 0x00, 0x08, 0x50, 0x04, 0x08, 0x9d, 0xf1, 0x38, 0xfe, 0x77, 0x01, 0x0f, 0x00, 0x00, 0x52, 0x01, 0x11, 0x2c, 0x52
, 0x00, 0x19, 0x01, 0xcf, 0xd7, 0x41, 0x00, 0xf7, 0x38, 0xfe, 0x20, 0x7f, 0x10, 0x4f, 0x38, 0x04, 0x62, 0xd0, 0x00, 0x51, 0x2a, 0x21, 0xf0, 0x54, 0x00, 0x51, 0x2d, 0x54, 0x01, 0x3d, 0x00, 0x10, 0xb0, 0x2a, 0x55, 0x98, 0x00, 0x3c, 0x9b, 0x01, 0xb0, 0x09, 0x55, 0x89, 0x00, 0x55, 0x8a, 0x00, 0x80, 0x0f, 0x62, 0xd0, 0x00, 0x3c, 0x9d, 0x01, 0xa0, 0x07, 0x55, 0x89, 0x00, 0x55, 0x8a, 0x00
, 0x56, 0x00, 0x00, 0x62, 0xd0, 0x00, 0x26, 0x2a, 0x0f, 0x81, 0x6a, 0x3d, 0x00, 0x20, 0xb0, 0x18, 0x62, 0xd0, 0x00, 0x55, 0x98, 0x01, 0x55, 0x99, 0x00, 0x55, 0x89, 0x08, 0x55, 0x8a, 0x08, 0x56, 0x00, 0x00, 0x26, 0x2a, 0x0f, 0x81, 0x4e, 0x3d, 0x00, 0x40, 0xb0, 0x0f, 0x62, 0xd0, 0x00, 0x55, 0xa0, 0x02, 0x56, 0x00, 0x00, 0x26, 0x2a, 0x0f, 0x81, 0x3b, 0x3d, 0x00, 0x50, 0xb0, 0xa7, 0x52
, 0x01, 0x54, 0x03, 0x56, 0x02, 0x00, 0x3d, 0x02, 0x00, 0xb0, 0x06, 0x3d, 0x03, 0x01, 0xa0, 0x21, 0x3d, 0x02, 0x00, 0xb0, 0x06, 0x3d, 0x03, 0x02, 0xa0, 0x28, 0x3d, 0x02, 0x00, 0xb0, 0x06, 0x3d, 0x03, 0x04, 0xa0, 0x36, 0x3d, 0x02, 0x00, 0xb0, 0x06, 0x3d, 0x03, 0x08, 0xa0, 0x48, 0x80, 0x62, 0x62, 0xd0, 0x00, 0x55, 0x9a, 0x01, 0x51, 0x2f, 0x29, 0x80, 0x53, 0x2f, 0x7c, 0x0c, 0xe9, 0x80
, 0x51, 0x62, 0xd0, 0x00, 0x51, 0x2b, 0x53, 0x4c, 0x51, 0x2b, 0x53, 0x4d, 0x51, 0x2b, 0x53, 0x2e, 0x51, 0x2c, 0x53, 0x0e, 0x55, 0x0d, 0x00, 0x80, 0x39, 0x62, 0xd0, 0x00, 0x51, 0x2b, 0x53, 0x2f, 0x3c, 0x9a, 0x00, 0xa0, 0x09, 0x51, 0x2f, 0x29, 0x80, 0x53, 0x2f, 0x80, 0x25, 0x62, 0xd0, 0x00, 0x26, 0x2f, 0x7f, 0x80, 0x1d, 0x62, 0xd0, 0x00, 0x55, 0x9a, 0x00, 0x26, 0x2f, 0x7f, 0x51, 0x79
, 0x53, 0x24, 0x51, 0x24, 0x53, 0x30, 0x51, 0x7a, 0x53, 0x25, 0x51, 0x25, 0x53, 0x31, 0x7c, 0x0c, 0xe9, 0x56, 0x00, 0x00, 0x62, 0xd0, 0x00, 0x26, 0x2a, 0x0f, 0x55, 0x2b, 0x05, 0x55, 0x2c, 0x03, 0x55, 0x2d, 0x00, 0x80, 0x90, 0x3d, 0x00, 0x60, 0xb0, 0x0f, 0x62, 0xd0, 0x00, 0x55, 0x9b, 0x01, 0x56, 0x00, 0x00, 0x26, 0x2a, 0x0f, 0x80, 0x7d, 0x3d, 0x00, 0x70, 0xb0, 0x0f, 0x62, 0xd0, 0x00
, 0x55, 0x9b, 0x00, 0x56, 0x00, 0x00, 0x26, 0x2a, 0x0f, 0x80, 0x6a, 0x3d, 0x00, 0x80, 0xb0, 0x65, 0x56, 0x00, 0x00, 0x62, 0xd0, 0x00, 0x26, 0x2a, 0x0f, 0x9c, 0xb2, 0x10, 0x7c, 0x09, 0x36, 0x7c, 0x06, 0x59, 0x20, 0x70, 0xfe, 0x71, 0x10, 0x41, 0x00, 0xf7, 0x41, 0x01, 0xf7, 0x70, 0xcf, 0x62, 0xda, 0x00, 0x71, 0x10, 0x41, 0xdc, 0xfe, 0x70, 0xcf, 0x43, 0x01, 0x08, 0x43, 0x00, 0x08, 0x50
, 0x00, 0x08, 0x50, 0x1e, 0x08, 0x9c, 0x5e, 0x38, 0xfe, 0x71, 0x01, 0x43, 0xe0, 0x10, 0x43, 0xff, 0x08, 0x70, 0xfe, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x10, 0x7c, 0x08, 0x65, 0x7c, 0x06, 0x0d, 0x7c, 0x06, 0x4e, 0x20, 0x93, 0x48, 0x40, 0x62, 0xe3, 0x38, 0x56, 0x00, 0x00, 0x62, 0xd0, 0x00, 0x26, 0x2a, 0x0f, 0x38, 0xfc, 0x20, 0x7f, 0x62, 0xd0, 0x00, 0x3c, 0x98, 0x00, 0xa0, 0x13
, 0x9c, 0x4b, 0x62, 0xd0, 0x00, 0x3c, 0x99, 0x00, 0xb0, 0x33, 0x55, 0x99, 0x01, 0x7c, 0x0b, 0x57, 0x80, 0x2b, 0x62, 0xd0, 0x00, 0x50, 0x01, 0x3a, 0x89, 0xd0, 0x08, 0x10, 0x7c, 0x05, 0x0d, 0x20, 0x80, 0x06, 0x10, 0x7c, 0x05, 0x09, 0x20, 0x62, 0xd0, 0x00, 0x50, 0x01, 0x3a, 0x8a, 0xd0, 0x08, 0x10, 0x7c, 0x04, 0xea, 0x20, 0x80, 0x06, 0x10, 0x7c, 0x04, 0xe6, 0x20, 0x7f, 0x10, 0x4f, 0x38
, 0x03, 0x56, 0x02, 0x00, 0x56, 0x01, 0x00, 0x56, 0x00, 0x00, 0x80, 0x3e, 0x62, 0xd0, 0x00, 0x91, 0x63, 0x40, 0x52, 0xfc, 0x04, 0x48, 0x52, 0xfb, 0x0c, 0x49, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x53, 0x49, 0x3e, 0x48, 0x53, 0x48, 0x52, 0x02, 0x12, 0x48, 0x52, 0x01, 0x1a, 0x49, 0xd0, 0x18, 0x91, 0x42, 0x40, 0x52, 0xfc, 0x04, 0x48, 0x52, 0xfb, 0x0c, 0x49, 0x51, 0x49, 0x60, 0xd4, 0x3e
, 0x48, 0x54, 0x01, 0x3e, 0x48, 0x54, 0x02, 0x77, 0x00, 0x52, 0x00, 0x3b, 0xfa, 0xcf, 0xbe, 0x62, 0xd0, 0x00, 0x52, 0x02, 0x53, 0x48, 0x52, 0x01, 0x53, 0x49, 0x38, 0xfd, 0x20, 0x7f, 0x10, 0x7c, 0x04, 0x98, 0x20, 0x10, 0x50, 0x04, 0x08, 0x50, 0x00, 0x08, 0x50, 0x8d, 0x08, 0x7c, 0x04, 0xa1, 0x38, 0xfd, 0x20, 0x10, 0x50, 0x04, 0x08, 0x50, 0x00, 0x08, 0x50, 0x6b, 0x08, 0x7c, 0x04, 0xa1
, 0x38, 0xfd, 0x20, 0x10, 0x50, 0x04, 0x08, 0x50, 0x00, 0x08, 0x50, 0x6f, 0x08, 0x7c, 0x04, 0xa1, 0x38, 0xfd, 0x20, 0x10, 0x50, 0x00, 0x7c, 0x03, 0xbc, 0x20, 0x10, 0x50, 0xff, 0x7c, 0x03, 0xbc, 0x20, 0x10, 0x50, 0xff, 0x7c, 0x03, 0xbc, 0x20, 0x7f, 0x62, 0xd0, 0x00, 0x76, 0x92, 0x0e, 0x91, 0x00, 0x50, 0x38, 0x12, 0x92, 0x50, 0x01, 0x1a, 0x91, 0xd0, 0x12, 0x55, 0x92, 0x00, 0x55, 0x91
, 0x00, 0x76, 0x33, 0x50, 0x80, 0x3a, 0x33, 0xd0, 0x04, 0x55, 0x33, 0x0a, 0x7f, 0x62, 0xd0, 0x00, 0x55, 0x9a, 0x00, 0x55, 0x9b, 0x01, 0x10, 0x7c, 0x05, 0x0d, 0x7c, 0x04, 0xea, 0x20, 0x9b, 0x2d, 0x62, 0xe3, 0x38, 0x71, 0x10, 0x43, 0x00, 0x08, 0x41, 0x01, 0xf7, 0x70, 0xcf, 0x41, 0x00, 0xf7, 0x62, 0xd0, 0x00, 0x55, 0x2a, 0x08, 0x55, 0x2b, 0x05, 0x55, 0x2c, 0x03, 0x55, 0x2e, 0x32, 0x55
, 0x2f, 0x05, 0x55, 0x30, 0x18, 0x55, 0x31, 0x11, 0x55, 0x32, 0x11, 0x55, 0x33, 0x11, 0x55, 0x33, 0x0a, 0x3c, 0x9a, 0x00, 0xa0, 0x09, 0x51, 0x2f, 0x29, 0x80, 0x53, 0x2f, 0x80, 0x07, 0x62, 0xd0, 0x00, 0x26, 0x2f, 0x7f, 0x10, 0x50, 0x00, 0x08, 0x50, 0x2a, 0x08, 0x50, 0x06, 0x08, 0x50, 0x16, 0x08, 0x7c, 0x06, 0x60, 0x38, 0xfc, 0x7c, 0x06, 0x0d, 0x7c, 0x06, 0x4e, 0x20, 0x91, 0xb0, 0x40
, 0x10, 0x7c, 0x08, 0x65, 0x7c, 0x07, 0xeb, 0x20, 0x7c, 0x0c, 0xe9, 0x80, 0x24, 0x62, 0xe3, 0x38, 0x9f, 0x57, 0x7c, 0x0f, 0xf9, 0x10, 0x7c, 0x08, 0x29, 0x62, 0xd0, 0x00, 0x20, 0x39, 0x00, 0xa0, 0x09, 0x7c, 0x0a, 0x85, 0x7c, 0x0a, 0xaf, 0x80, 0x04, 0x7c, 0x0b, 0x18, 0x9c, 0x9e, 0x9e, 0x48, 0x8f, 0xdc, 0x8f, 0xff, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x65, 0x48, 0x6b, 0x49, 0x7f
, 0x62, 0xd0, 0x00, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x7f, 0x53, 0x46, 0x51, 0x49, 0x09, 0x00, 0x60, 0xd4, 0x3e, 0x46, 0x53, 0x47, 0x3e, 0x46, 0x53, 0x46, 0x7f, 0x52, 0x00, 0x53, 0x48, 0x55, 0x49, 0x00, 0x55, 0x46, 0x06, 0x55, 0x47, 0x00, 0x55, 0x41, 0x00, 0x55, 0x40, 0x00, 0x3c, 0x47, 0x00, 0xb0, 0x06, 0x3c, 0x46, 0x00, 0xa0, 0x1a, 0x70, 0xfb, 0x6e, 0x47, 0x6e, 0x46, 0xd0
, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x48, 0x04, 0x41, 0x51, 0x49, 0x0c, 0x40, 0x65, 0x48, 0x6b, 0x49, 0x8f, 0xde, 0x5f, 0x48, 0x41, 0x5f, 0x49, 0x40, 0x62, 0xd0, 0x00, 0x5a, 0x46, 0x06, 0x46, 0x01, 0x51, 0x46, 0x04, 0x48, 0x0e, 0x49, 0x03, 0x7f, 0x55, 0x46, 0x06, 0x55, 0x47, 0x00, 0x55, 0x41, 0x00, 0x55, 0x40, 0x00, 0x3c, 0x47, 0x00, 0xb0, 0x06, 0x3c, 0x46, 0x00, 0xa0, 0x1a, 0x70, 0xfb
, 0x6e, 0x47, 0x6e, 0x46, 0xd0, 0x0c, 0x62, 0xd0, 0x00, 0x51, 0x48, 0x04, 0x41, 0x51, 0x49, 0x0c, 0x40, 0x65, 0x48, 0x6b, 0x49, 0x8f, 0xde, 0x5f, 0x48, 0x41, 0x5f, 0x49, 0x40, 0x62, 0xd0, 0x00, 0x5a, 0x46, 0x06, 0x46, 0x01, 0x51, 0x46, 0x04, 0x48, 0x0e, 0x49, 0x03, 0x7f, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x53, 0x49, 0x7f, 0x60, 0xd4, 0x3e, 0x46, 0x53, 0x47, 0x3e
, 0x46, 0x53, 0x46, 0x7f, 0x09, 0x00, 0x60, 0xd4, 0x3e, 0x46, 0x53, 0x47, 0x3e, 0x46, 0x7f, 0x51, 0x49, 0x60, 0xd5, 0x51, 0x47, 0x3f, 0x48, 0x51, 0x46, 0x3f, 0x48, 0x7f, 0x60, 0xd4, 0x3e, 0x48, 0x53, 0x49, 0x3e, 0x48, 0x53, 0x48, 0x7f, 0x51, 0x48, 0x01, 0x8d, 0x53, 0x46, 0x51, 0x49, 0x09, 0x00, 0x7f, 0x06, 0x48, 0x8d, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd4, 0x3e, 0x48, 0x53, 0x47
, 0x3e, 0x48, 0x16, 0x48, 0x02, 0x53, 0x46, 0x7f, 0x53, 0x46, 0x51, 0x49, 0x09, 0x00, 0x60, 0xd5, 0x52, 0x14, 0x3f, 0x46, 0x52, 0x15, 0x3f, 0x46, 0x7f, 0x3e, 0x48, 0x53, 0x48, 0x51, 0x46, 0x12, 0x48, 0x51, 0x47, 0x1a, 0x49, 0x7f, 0x53, 0x48, 0x52, 0xfb, 0x09, 0x00, 0x60, 0xd4, 0x3e, 0x48, 0x7f, 0x60, 0xd5, 0x52, 0x14, 0x3f, 0x46, 0x52, 0x15, 0x3f, 0x46, 0x7f, 0x60, 0xd4, 0x3e, 0x48
, 0x54, 0x00, 0x3e, 0x48, 0x54, 0x01, 0x7f, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd5, 0x52, 0x14, 0x3f, 0x48, 0x52, 0x15, 0x3f, 0x48, 0x7f, 0x52, 0x00, 0x53, 0x46, 0x55, 0x47, 0x00, 0x65, 0x46, 0x6b, 0x47, 0x7f, 0x0e, 0x47, 0x00, 0x51, 0x47, 0x60, 0xd5, 0x51, 0x49, 0x3f, 0x46, 0x7f, 0x71, 0x10, 0x41, 0x04, 0xfe, 0x41, 0x05, 0xfe, 0x41, 0x04, 0xfd, 0x41, 0x05, 0xfd, 0x70, 0xcf, 0x43
, 0x04, 0x01, 0x43, 0x04, 0x02, 0x71, 0x01, 0x7f, 0x70, 0xfb, 0x6e, 0x49, 0x6e, 0x48, 0x51, 0x47, 0x60, 0xd5, 0x51, 0x49, 0x3f, 0x46, 0x51, 0x48, 0x3f, 0x46, 0x7f, 0x53, 0x46, 0x55, 0x47, 0x00, 0x65, 0x46, 0x6b, 0x47, 0x51, 0x46, 0x7f, 0x0e, 0x49, 0x00, 0x51, 0x49, 0x60, 0xd5, 0x50, 0x00, 0x3f, 0x48, 0x7f, 0x3e, 0x48, 0x12, 0x46, 0x54, 0x02, 0x51, 0x49, 0x1a, 0x47, 0x54, 0x01, 0x7f
, 0x3e, 0x48, 0x12, 0x46, 0x54, 0x04, 0x51, 0x49, 0x1a, 0x47, 0x54, 0x03, 0x7f, 0x09, 0x00, 0x60, 0xd4, 0x3e, 0x44, 0x53, 0x45, 0x3e, 0x44, 0x53, 0x44, 0x7f, 0x60, 0xd4, 0x3e, 0x46, 0x53, 0x45, 0x3e, 0x46, 0x16, 0x46, 0x02, 0x7f, 0x00, 0x2a, 0x00, 0x16, 0x00, 0x53, 0x00, 0x18, 0x00, 0x73, 0x00, 0x06, 0x00, 0x79, 0x04, 0x18, 0x11, 0x11, 0x11, 0x00, 0x7d, 0x00, 0x0c, 0x00, 0x89, 0x04
, 0x08, 0x08, 0x08, 0x08, 0x00, 0x91, 0x00, 0x04, 0x00, 0x95, 0x07, 0x02, 0x00, 0x05, 0x01, 0x01, 0x00, 0x01, 0x00, 0x9c, 0x00, 0x05, 0xff, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
};
/* I2C */
#define EXT_I2C_SCL_HIGH \
do { \
int delay_count; \
gpio_direction_output(_3_TOUCH_SCL_28V, 1); \
gpio_direction_input(_3_TOUCH_SCL_28V); \
delay_count = 100000; \
while (delay_count--) { \
if (gpio_get_value(_3_TOUCH_SCL_28V)) \
break; \
udelay(1); \
} \
} while (0);
#define EXT_I2C_SCL_LOW gpio_direction_output(_3_TOUCH_SCL_28V, 0);
#define EXT_I2C_SDA_HIGH gpio_direction_output(_3_TOUCH_SDA_28V, 1);
#define EXT_I2C_SDA_LOW gpio_direction_output(_3_TOUCH_SDA_28V, 0);
#define TRUE 1
#define FALSE 0
static void EXT_I2C_LOW(u32 delay)
{
EXT_I2C_SDA_LOW;
/* udelay(delay); */
EXT_I2C_SCL_HIGH;
/* udelay(delay); */
EXT_I2C_SCL_LOW;
/* udelay(delay); */
}
static void EXT_I2C_HIGH(u32 delay)
{
EXT_I2C_SDA_HIGH;
/* udelay(delay); */
EXT_I2C_SCL_HIGH;
/* udelay(delay); */
EXT_I2C_SCL_LOW;
/* udelay(delay); */
}
static void EXT_I2C_START(u32 delay)
{
EXT_I2C_SDA_HIGH;
EXT_I2C_SCL_HIGH;
/* udelay(delay); */
EXT_I2C_SDA_LOW;
/* udelay(delay); */
EXT_I2C_SCL_LOW;
/* udelay(delay); */
}
static void EXT_I2C_END(u32 delay)
{
EXT_I2C_SDA_LOW;
EXT_I2C_SCL_HIGH;
/* udelay(delay); */
EXT_I2C_SDA_HIGH;
}
static int EXT_I2C_ACK(u32 delay)
{
u32 ack;
/* SDA -> Input */
gpio_direction_input(_3_TOUCH_SDA_28V);
udelay(delay);
EXT_I2C_SCL_HIGH;
/* udelay(delay); */
ack = gpio_get_value(_3_TOUCH_SDA_28V);
EXT_I2C_SCL_LOW;
/* udelay(delay); */
if (ack)
printk(KERN_INFO "EXT_I2C No ACK\n");
return ack;
}
static void EXT_I2C_NACK(u32 delay)
{
EXT_I2C_SDA_HIGH;
EXT_I2C_SCL_HIGH;
/* udelay(delay); */
EXT_I2C_SCL_LOW;
/* udelay(delay); */
}
static void EXT_I2C_SEND_ACK(u32 delay)
{
gpio_direction_output(_3_TOUCH_SDA_28V, 0);
EXT_I2C_SCL_HIGH;
/* udelay(delay); */
EXT_I2C_SCL_LOW;
/* udelay(delay); */
}
#define EXT_I2C_DELAY 1
/*============================================================
//
// Porting section 6. I2C function calling
//
// Connect baseband i2c function
//
// Warning 1. !!!! Burst mode is not supported. Transfer 1 byte Only.
//
// Every i2c packet has to
// " START > Slave address > One byte > STOP " at download mode.
//
// Warning 2. !!!! Check return value of i2c function.
//
// _i2c_read_(), _i2c_write_() must return
// TRUE (1) if success,
// FALSE(0) if failed.
//
// If baseband i2c function returns different value, convert return value.
// ex> baseband_return = baseband_i2c_read( slave_addr, pData, cLength );
// return ( baseband_return == BASEBAND_RETURN_VALUE_SUCCESS );
//
//
// Warning 3. !!!! Check Slave address
//
// Slave address is '0x7F' at download mode. ( Diffrent with Normal touch working mode )
// '0x7F' is original address,
// If shift << 1 bit, It becomes '0xFE'
//
//============================================================*/
static int _i2c_read_(unsigned char SlaveAddr, unsigned char *pData, unsigned char cLength)
{
unsigned int i;
int delay_count = 10000;
EXT_I2C_START(EXT_I2C_DELAY);
SlaveAddr = SlaveAddr << 1;
for (i = 8; i > 1; i--) {
if ((SlaveAddr >> (i - 1)) & 0x1)
EXT_I2C_HIGH(EXT_I2C_DELAY);
else
EXT_I2C_LOW(EXT_I2C_DELAY);
}
EXT_I2C_HIGH(EXT_I2C_DELAY); /* readwrite */
if (EXT_I2C_ACK(EXT_I2C_DELAY)) {
EXT_I2C_END(EXT_I2C_DELAY);
return FALSE;
}
udelay(10);
gpio_direction_input(_3_TOUCH_SCL_28V);
delay_count = 100000;
while (delay_count--) {
if (gpio_get_value(_3_TOUCH_SCL_28V))
break;
udelay(1);
}
while (cLength--) {
*pData = 0;
for (i = 8; i > 0; i--) {
/* udelay(EXT_I2C_DELAY); */
EXT_I2C_SCL_HIGH;
/* udelay(EXT_I2C_DELAY); */
*pData |=
(!!(gpio_get_value(_3_TOUCH_SDA_28V)) << (i - 1));
/* udelay(EXT_I2C_DELAY); */
EXT_I2C_SCL_LOW;
/* udelay(EXT_I2C_DELAY); */
}
if (cLength) {
EXT_I2C_SEND_ACK(EXT_I2C_DELAY);
udelay(10);
pData++;
gpio_direction_input(_3_TOUCH_SDA_28V);
gpio_direction_input(_3_TOUCH_SCL_28V);
delay_count = 100000;
while (delay_count--) {
if (gpio_get_value(_3_TOUCH_SCL_28V))
break;
udelay(1);
}
} else
EXT_I2C_NACK(EXT_I2C_DELAY);
}
EXT_I2C_END(EXT_I2C_DELAY);
return TRUE;
}
#define TOUCHKEY_ADDRESS 0x20
int get_touchkey_firmware(char *version)
{
int retry = 3;
while (retry--) {
if (_i2c_read_(TOUCHKEY_ADDRESS, version, 3))
return 0;
}
return -1;
/* printk("%s F/W version: 0x%x, Module version:0x%x\n",__FUNCTION__, version[1],version[2]); */
}
/* =========================================================================
// ErrorTrap()
// Return is not valid from main for PSOC, so this ErrorTrap routine is used.
// For some systems returning an error code will work best. For those, the
// calls to ErrorTrap() should be replaced with a return(bErrorNumber). For
// other systems another method of reporting an error could be added to this
// function -- such as reporting over a communcations port.
// ========================================================================= */
void ErrorTrap(unsigned char bErrorNumber)
{
#ifndef RESET_MODE
/* Set all pins to highZ to avoid back powering the PSoC through the GPIO
// protection diodes. */
SetSCLKHiZ();
SetSDATAHiZ();
/* If Power Cycle programming, turn off the target */
RemoveTargetVDD();
#endif
printk(KERN_INFO "\r\nErrorTrap: errorNumber: %d\n", bErrorNumber);
/* TODO: write retry code or some processing. */
return;
/* while (1); */
}
/* ========================================================================= */
/* MAIN LOOP */
/* Based on the diagram in the AN2026 */
/* ========================================================================= */
int ISSP_main(void)
{
unsigned long flags;
/* -- This example section of commands show the high-level calls to -------
// -- perform Target Initialization, SilcionID Test, Bulk-Erase, Target ---
// -- RAM Load, FLASH-Block Program, and Target Checksum Verification. ----
// >>>> ISSP Programming Starts Here <<<<
// Acquire the device through reset or power cycle */
nmk_gpio_set_pull(_3_TOUCH_SCL_28V, NMK_GPIO_PULL_UP);
gpio_direction_output(_3_GPIO_TOUCH_EN, 0);
msleep(1);
#ifdef RESET_MODE
gpio_tlmm_config(LED_26V_EN);
gpio_tlmm_config(EXT_TSP_SCL);
gpio_tlmm_config(EXT_TSP_SDA);
gpio_tlmm_config(LED_RST);
gpio_out(LED_RST, GPIO_LOW_VALUE);
clk_busy_wait(10);
gpio_out(LED_26V_EN, GPIO_HIGH_VALUE);
for (temp = 0; temp < 16; temp++) {
clk_busy_wait(1000);
dog_kick();
}
/* Initialize the Host & Target for ISSP operations */
printk(KERN_INFO "fXRESInitializeTargetForISSP Start\n");
/* INTLOCK(); */
local_save_flags(flags);
local_irq_disable();
fIsError = fXRESInitializeTargetForISSP();
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
/* INTFREE(); */
#else
/* INTLOCK(); */
local_irq_save(flags);
/* Initialize the Host & Target for ISSP operations */
fIsError = fPowerCycleInitializeTargetForISSP(flags);
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
/* INTFREE(); */
#endif /* RESET_MODE */
#if 0 /* issp_test_2010 block */
printk("fXRESInitializeTargetForISSP END\n");
/* Run the SiliconID Verification, and proceed according to result. */
printk("fVerifySiliconID START\n");
#endif
/* INTLOCK(); */
fVerifySiliconID(); /* .. error // issp_test_20100709 unblock */
#if 0
fIsError = fVerifySiliconID();
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
#endif
/* INTFREE(); */
local_irq_restore(flags);
/* printk("fVerifySiliconID END\n"); // issp_test_2010 block */
/* Bulk-Erase the Device. */
/* printk("fEraseTarget START\n"); // issp_test_2010 block */
/* INTLOCK(); */
local_irq_save(flags);
fIsError = fEraseTarget();
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
/* INTFREE(); */
local_irq_restore(flags);
/* printk("fEraseTarget END\n"); // issp_test_2010 block */
/*==============================================================//
// Program Flash blocks with predetermined data. In the final application
// this data should come from the HEX output of PSoC Designer. */
/* printk("Program Flash Blocks Start\n"); */
iChecksumData = 0; /* Calculte the device checksum as you go */
for (bBankCounter = 0; bBankCounter < NUM_BANKS; bBankCounter++) { /* PTJ: NUM_BANKS should be 1 for Krypton */
local_irq_save(flags);
for (iBlockCounter = 0; iBlockCounter < BLOCKS_PER_BANK;
iBlockCounter++) {
/* printk("Program Loop : iBlockCounter %d \n",iBlockCounter); */
/* INTLOCK(); */
/* local_irq_save(flags); */
/* PTJ: READ-WRITE-SETUP used here to select SRAM Bank 1, and TSYNC Enable */
#ifdef CY8C20x66
fIsError = fSyncEnable();
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
fIsError = fReadWriteSetup();
if (fIsError) { /* send write command - swanhan */
ErrorTrap(fIsError);
return fIsError;
}
#endif
/* firmware read. */
/* LoadProgramData(bBankCounter, (unsigned char)iBlockCounter); //PTJ: this loads the Hydra with test data, not the krypton */
LoadProgramData((unsigned char)iBlockCounter, bBankCounter); /* PTJ: this loads the Hydra with test data, not the krypton */
iChecksumData += iLoadTarget(); /*PTJ: this loads the Krypton */
/* dog_kick(); */
fIsError = fProgramTargetBlock(bBankCounter,
(unsigned char)iBlockCounter);
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
#ifdef CY8C20x66 /* PTJ: READ-STATUS after PROGRAM-AND-VERIFY */
fIsError = fReadStatus();
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
#endif
/* INTFREE(); */
/* local_irq_restore(flags); */
}
local_irq_restore(flags);
}
/* printk("\r\n Program Flash Blocks End\n"); */
#if 1 /* security start */
/* =======================================================//
// Program security data into target PSoC. In the final application this
// data should come from the HEX output of PSoC Designer. */
/* printk("Program security data START\n"); */
/* INTLOCK(); */
local_irq_save(flags);
for (bBankCounter = 0; bBankCounter < NUM_BANKS; bBankCounter++) {
/* PTJ: READ-WRITE-SETUP used here to select SRAM Bank 1 */
#ifdef CY8C20x66
fIsError = fSyncEnable();
if (fIsError) { /* PTJ: 307, added for tsync enable testing. */
ErrorTrap(fIsError);
return fIsError;
}
fIsError = fReadWriteSetup();
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
#endif
/* Load one bank of security data from hex file into buffer */
fIsError = fLoadSecurityData(bBankCounter);
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
/* Secure one bank of the target flash */
fIsError = fSecureTargetFlash();
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
}
/* INTFREE(); */
local_irq_restore(flags);
/* printk("Program security data END\n"); */
/*==============================================================//
//PTJ: Do READ-SECURITY after SECURE
//Load one bank of security data from hex file into buffer
//loads abTargetDataOUT[] with security data that was used in secure bit stream */
/* INTLOCK(); */
local_irq_save(flags);
fIsError = fLoadSecurityData(bBankCounter);
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
#ifdef CY8C20x66
fIsError = fReadSecurity();
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
#endif
/* INTFREE(); */
local_irq_restore(flags);
/* printk("Load security data END\n"); */
#endif /* security end */
/*=======================================================//
//PTJ: Doing Checksum after READ-SECURITY */
/* INTLOCK(); */
local_irq_save(flags);
iChecksumTarget = 0;
for (bBankCounter = 0; bBankCounter < NUM_BANKS; bBankCounter++) {
fIsError = fAccTargetBankChecksum(&iChecksumTarget);
if (fIsError) {
ErrorTrap(fIsError);
return fIsError;
}
}
/* INTFREE(); */
local_irq_restore(flags);
/* printk("Checksum : iChecksumTarget (0x%X)\n", (unsigned char)iChecksumTarget); */
/* printk ("Checksum : iChecksumData (0x%X)\n", (unsigned char)iChecksumData); */
if ((unsigned short)(iChecksumTarget & 0xffff) !=
(unsigned short)(iChecksumData & 0xffff)) {
ErrorTrap(VERIFY_ERROR);
return fIsError;
}
/* printk("Doing Checksum END\n"); */
/* *** SUCCESS ***
// At this point, the Target has been successfully Initialize, ID-Checked,
// Bulk-Erased, Block-Loaded, Block-Programmed, Block-Verified, and Device-
// Checksum Verified. */
/* You may want to restart Your Target PSoC Here. */
local_irq_enable();
ReStartTarget(); /* Touch IC Reset. */
/* printk("ReStartTarget\n"); */
return 0;
}
/* end of main() */
#endif /* (PROJECT_REV_) end of file main.c */
| honeyx/S3mini_golden_kernel | drivers/input/keyboard/cypress/issp_main.c | C | gpl-2.0 | 132,606 |
/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 only,
* 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 version 2 for more details (a copy is included
* in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; If not, see
* http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* GPL HEADER END
*/
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 2012, 2015, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
* Lustre is a trademark of Sun Microsystems, Inc.
*
* lustre/obdclass/llog_cat.c
*
* OST<->MDS recovery logging infrastructure.
*
* Invariants in implementation:
* - we do not share logs among different OST<->MDS connections, so that
* if an OST or MDS fails it need only look at log(s) relevant to itself
*
* Author: Andreas Dilger <adilger@clusterfs.com>
* Author: Alexey Zhuravlev <alexey.zhuravlev@intel.com>
* Author: Mikhail Pershin <mike.pershin@intel.com>
*/
#define DEBUG_SUBSYSTEM S_LOG
#include "../include/obd_class.h"
#include "llog_internal.h"
/* Open an existent log handle and add it to the open list.
* This log handle will be closed when all of the records in it are removed.
*
* Assumes caller has already pushed us into the kernel context and is locking.
* We return a lock on the handle to ensure nobody yanks it from us.
*
* This takes extra reference on llog_handle via llog_handle_get() and require
* this reference to be put by caller using llog_handle_put()
*/
static int llog_cat_id2handle(const struct lu_env *env,
struct llog_handle *cathandle,
struct llog_handle **res,
struct llog_logid *logid)
{
struct llog_handle *loghandle;
int rc = 0;
if (!cathandle)
return -EBADF;
down_write(&cathandle->lgh_lock);
list_for_each_entry(loghandle, &cathandle->u.chd.chd_head,
u.phd.phd_entry) {
struct llog_logid *cgl = &loghandle->lgh_id;
if (ostid_id(&cgl->lgl_oi) == ostid_id(&logid->lgl_oi) &&
ostid_seq(&cgl->lgl_oi) == ostid_seq(&logid->lgl_oi)) {
if (cgl->lgl_ogen != logid->lgl_ogen) {
CERROR("%s: log "DOSTID" generation %x != %x\n",
loghandle->lgh_ctxt->loc_obd->obd_name,
POSTID(&logid->lgl_oi), cgl->lgl_ogen,
logid->lgl_ogen);
continue;
}
loghandle->u.phd.phd_cat_handle = cathandle;
up_write(&cathandle->lgh_lock);
rc = 0;
goto out;
}
}
up_write(&cathandle->lgh_lock);
rc = llog_open(env, cathandle->lgh_ctxt, &loghandle, logid, NULL,
LLOG_OPEN_EXISTS);
if (rc < 0) {
CERROR("%s: error opening log id "DOSTID":%x: rc = %d\n",
cathandle->lgh_ctxt->loc_obd->obd_name,
POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
return rc;
}
rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, NULL);
if (rc < 0) {
llog_close(env, loghandle);
loghandle = NULL;
return rc;
}
down_write(&cathandle->lgh_lock);
list_add(&loghandle->u.phd.phd_entry, &cathandle->u.chd.chd_head);
up_write(&cathandle->lgh_lock);
loghandle->u.phd.phd_cat_handle = cathandle;
loghandle->u.phd.phd_cookie.lgc_lgl = cathandle->lgh_id;
loghandle->u.phd.phd_cookie.lgc_index =
loghandle->lgh_hdr->llh_cat_idx;
out:
llog_handle_get(loghandle);
*res = loghandle;
return 0;
}
int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
{
struct llog_handle *loghandle, *n;
int rc;
list_for_each_entry_safe(loghandle, n, &cathandle->u.chd.chd_head,
u.phd.phd_entry) {
/* unlink open-not-created llogs */
list_del_init(&loghandle->u.phd.phd_entry);
llog_close(env, loghandle);
}
/* if handle was stored in ctxt, remove it too */
if (cathandle->lgh_ctxt->loc_handle == cathandle)
cathandle->lgh_ctxt->loc_handle = NULL;
rc = llog_close(env, cathandle);
return rc;
}
EXPORT_SYMBOL(llog_cat_close);
static int llog_cat_process_cb(const struct lu_env *env,
struct llog_handle *cat_llh,
struct llog_rec_hdr *rec, void *data)
{
struct llog_process_data *d = data;
struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
struct llog_handle *llh;
int rc;
if (rec->lrh_type != LLOG_LOGID_MAGIC) {
CERROR("invalid record in catalog\n");
return -EINVAL;
}
CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
rec->lrh_index, POSTID(&cat_llh->lgh_id.lgl_oi));
rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
if (rc) {
CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
cat_llh->lgh_ctxt->loc_obd->obd_name,
POSTID(&lir->lid_id.lgl_oi), rc);
return rc;
}
if (rec->lrh_index < d->lpd_startcat)
/* Skip processing of the logs until startcat */
rc = 0;
else if (d->lpd_startidx > 0) {
struct llog_process_cat_data cd;
cd.lpcd_first_idx = d->lpd_startidx;
cd.lpcd_last_idx = 0;
rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
&cd, false);
/* Continue processing the next log from idx 0 */
d->lpd_startidx = 0;
} else {
rc = llog_process_or_fork(env, llh, d->lpd_cb, d->lpd_data,
NULL, false);
}
llog_handle_put(llh);
return rc;
}
static int llog_cat_process_or_fork(const struct lu_env *env,
struct llog_handle *cat_llh,
llog_cb_t cb, void *data, int startcat,
int startidx, bool fork)
{
struct llog_process_data d;
struct llog_log_hdr *llh = cat_llh->lgh_hdr;
int rc;
LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
d.lpd_data = data;
d.lpd_cb = cb;
d.lpd_startcat = startcat;
d.lpd_startidx = startidx;
if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {
struct llog_process_cat_data cd;
CWARN("catlog "DOSTID" crosses index zero\n",
POSTID(&cat_llh->lgh_id.lgl_oi));
cd.lpcd_first_idx = llh->llh_cat_idx;
cd.lpcd_last_idx = 0;
rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
&d, &cd, fork);
if (rc != 0)
return rc;
cd.lpcd_first_idx = 0;
cd.lpcd_last_idx = cat_llh->lgh_last_idx;
rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
&d, &cd, fork);
} else {
rc = llog_process_or_fork(env, cat_llh, llog_cat_process_cb,
&d, NULL, fork);
}
return rc;
}
int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
llog_cb_t cb, void *data, int startcat, int startidx)
{
return llog_cat_process_or_fork(env, cat_llh, cb, data, startcat,
startidx, false);
}
EXPORT_SYMBOL(llog_cat_process);
| geminy/aidear | oss/linux/linux-4.7/drivers/staging/lustre/lustre/obdclass/llog_cat.c | C | gpl-3.0 | 7,203 |
<?php
/*!
* HybridAuth
* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
*/
/**
* Hybrid_Providers_MySpace provider adapter based on OAuth1 protocol
*
* http://hybridauth.sourceforge.net/userguide/IDProvider_info_MySpace.html
*/
class Hybrid_Providers_MySpace extends Hybrid_Provider_Model_OAuth1
{
/**
* IDp wrappers initializer
*/
function initialize()
{
parent::initialize();
// Provider api end-points
$this->api->api_endpoint_url = "http://api.myspace.com/v1/";
$this->api->authorize_url = "http://api.myspace.com/authorize";
$this->api->request_token_url = "http://api.myspace.com/request_token";
$this->api->access_token_url = "http://api.myspace.com/access_token";
}
/**
* get the connected uid from myspace api
*/
public function getCurrentUserId()
{
$response = $this->api->get( 'http://api.myspace.com/v1/user.json' );
if ( ! isset( $response->userId ) ){
throw new Exception( "User id request failed! {$this->providerId} returned an invalid response." );
}
return $response->userId;
}
/**
* load the user profile from the IDp api client
*/
function getUserProfile()
{
$userId = $this->getCurrentUserId();
$data = $this->api->get( 'http://api.myspace.com/v1/users/' . $userId . '/profile.json' );
if ( ! is_object( $data ) ){
throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
}
$this->user->profile->identifier = $userId;
$this->user->profile->displayName = $data->basicprofile->name;
$this->user->profile->description = $data->aboutme;
$this->user->profile->gender = $data->basicprofile->gender;
$this->user->profile->photoURL = $data->basicprofile->image;
$this->user->profile->profileURL = $data->basicprofile->webUri;
$this->user->profile->age = $data->age;
$this->user->profile->country = $data->country;
$this->user->profile->region = $data->region;
$this->user->profile->city = $data->city;
$this->user->profile->zip = $data->postalcode;
return $this->user->profile;
}
/**
* load the user contacts
*/
function getUserContacts()
{
$userId = $this->getCurrentUserId();
$response = $this->api->get( "http://api.myspace.com/v1/users/" . $userId . "/friends.json" );
if ( ! is_object( $response ) ){
throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
}
$contacts = ARRAY();
foreach( $response->Friends as $item ){
$uc = new Hybrid_User_Contact();
$uc->identifier = $item->userId;
$uc->displayName = $item->name;
$uc->profileURL = $item->webUri;
$uc->photoURL = $item->image;
$uc->description = $item->status;
$contacts[] = $uc;
}
return $contacts;
}
/**
* update user status
*/
function setUserStatus( $status )
{
// crappy myspace... gonna see this asaic
$userId = $this->getCurrentUserId();
$parameters = array( 'status' => $status );
$response = $this->api->api( "http://api.myspace.com/v1/users/" . $userId . "/status", 'PUT', $parameters );
// check the last HTTP status code returned
if ( $this->api->http_code != 200 )
{
throw new Exception( "Update user status failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ) );
}
}
/**
* load the user latest activity
* - timeline : all the stream
* - me : the user activity only
*/
function getUserActivity( $stream )
{
$userId = $this->getCurrentUserId();
if( $stream == "me" ){
$response = $this->api->get( "http://api.myspace.com/v1/users/" . $userId . "/status.json" );
}
else{
$response = $this->api->get( "http://api.myspace.com/v1/users/" . $userId . "/friends/status.json" );
}
if ( ! is_object( $response ) ){
throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
}
$activities = ARRAY();
if( $stream == "me" ){
// todo
}
else{
foreach( $response->FriendsStatus as $item ){
$ua = new Hybrid_User_Activity();
$ua->id = $item->statusId;
$ua->date = NULL; // to find out!!
$ua->text = $item->status;
$ua->user->identifier = $item->user->userId;
$ua->user->displayName = $item->user->name;
$ua->user->profileURL = $item->user->uri;
$ua->user->photoURL = $item->user->image;
$activities[] = $ua;
}
}
return $activities;
}
}
| tiltfactor/mg-game | www/protected/extensions/HybridAuth/hybridauth-2.1.2/hybridauth/Providers/MySpace.php | PHP | agpl-3.0 | 4,857 |
Shindo.tests('Fog::Compute::RackspaceV2 | network_tests', ['rackspace']) do
service = Fog::Compute.new(:provider => 'Rackspace', :version => 'V2')
network_format = {
'id' => String,
'label' => String,
'cidr' => Fog::Nullable::String
}
get_network_format = {
'network' => network_format
}
list_networks_format = {
'networks' => [network_format]
}
tests('success') do
network_id = nil
tests('#create_network').formats(get_network_format) do
service.create_network("fog_#{Time.now.to_i.to_s}", '192.168.0.0/24').body.tap do |r|
network_id = r['network']['id']
end
end
tests('#list_networks').formats(list_networks_format) do
service.list_networks.body
end
tests('#get_network').formats(get_network_format) do
service.get_network(network_id).body
end
tests('#delete_network').succeeds do
service.delete_network(network_id)
end
end
test('failure') do
tests('#get_network').raises(Fog::Compute::RackspaceV2::NotFound) do
service.get_network(0)
end
tests('#delete_network').raises(Fog::Compute::RackspaceV2::NotFound) do
service.delete_network(0)
end
end
end
| jreichhold/chef-repo | vendor/ruby/2.0.0/gems/fog-1.20.0/tests/rackspace/requests/compute_v2/network_tests.rb | Ruby | apache-2.0 | 1,208 |
<?php
namespace Gedmo\Uploadable\Stub;
use Gedmo\Uploadable\FileInfo\FileInfoArray;
class FileInfoStub extends FileInfoArray
{
}
| bantudevelopment/smis | vendor/gedmo1/doctrine-extensions/tests/Gedmo/Uploadable/Stub/FileInfoStub.php | PHP | bsd-3-clause | 132 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/disk_cache/blockfile/bitmap.h"
#include <algorithm>
#include "base/logging.h"
namespace {
// Returns the number of trailing zeros.
int FindLSBSetNonZero(uint32 word) {
// Get the LSB, put it on the exponent of a 32 bit float and remove the
// mantisa and the bias. This code requires IEEE 32 bit float compliance.
float f = static_cast<float>(word & -static_cast<int>(word));
// We use a union to go around strict-aliasing complains.
union {
float ieee_float;
uint32 as_uint;
} x;
x.ieee_float = f;
return (x.as_uint >> 23) - 0x7f;
}
// Returns the index of the first bit set to |value| from |word|. This code
// assumes that we'll be able to find that bit.
int FindLSBNonEmpty(uint32 word, bool value) {
// If we are looking for 0, negate |word| and look for 1.
if (!value)
word = ~word;
return FindLSBSetNonZero(word);
}
} // namespace
namespace disk_cache {
Bitmap::Bitmap(int num_bits, bool clear_bits)
: num_bits_(num_bits),
array_size_(RequiredArraySize(num_bits)),
alloc_(true) {
map_ = new uint32[array_size_];
// Initialize all of the bits.
if (clear_bits)
Clear();
}
Bitmap::Bitmap(uint32* map, int num_bits, int num_words)
: map_(map),
num_bits_(num_bits),
// If size is larger than necessary, trim because array_size_ is used
// as a bound by various methods.
array_size_(std::min(RequiredArraySize(num_bits), num_words)),
alloc_(false) {
}
Bitmap::~Bitmap() {
if (alloc_)
delete [] map_;
}
void Bitmap::Resize(int num_bits, bool clear_bits) {
DCHECK(alloc_ || !map_);
const int old_maxsize = num_bits_;
const int old_array_size = array_size_;
array_size_ = RequiredArraySize(num_bits);
if (array_size_ != old_array_size) {
uint32* new_map = new uint32[array_size_];
// Always clear the unused bits in the last word.
new_map[array_size_ - 1] = 0;
memcpy(new_map, map_,
sizeof(*map_) * std::min(array_size_, old_array_size));
if (alloc_)
delete[] map_; // No need to check for NULL.
map_ = new_map;
alloc_ = true;
}
num_bits_ = num_bits;
if (old_maxsize < num_bits_ && clear_bits) {
SetRange(old_maxsize, num_bits_, false);
}
}
void Bitmap::Set(int index, bool value) {
DCHECK_LT(index, num_bits_);
DCHECK_GE(index, 0);
const int i = index & (kIntBits - 1);
const int j = index / kIntBits;
if (value)
map_[j] |= (1 << i);
else
map_[j] &= ~(1 << i);
}
bool Bitmap::Get(int index) const {
DCHECK_LT(index, num_bits_);
DCHECK_GE(index, 0);
const int i = index & (kIntBits-1);
const int j = index / kIntBits;
return ((map_[j] & (1 << i)) != 0);
}
void Bitmap::Toggle(int index) {
DCHECK_LT(index, num_bits_);
DCHECK_GE(index, 0);
const int i = index & (kIntBits - 1);
const int j = index / kIntBits;
map_[j] ^= (1 << i);
}
void Bitmap::SetMapElement(int array_index, uint32 value) {
DCHECK_LT(array_index, array_size_);
DCHECK_GE(array_index, 0);
map_[array_index] = value;
}
uint32 Bitmap::GetMapElement(int array_index) const {
DCHECK_LT(array_index, array_size_);
DCHECK_GE(array_index, 0);
return map_[array_index];
}
void Bitmap::SetMap(const uint32* map, int size) {
memcpy(map_, map, std::min(size, array_size_) * sizeof(*map_));
}
void Bitmap::SetRange(int begin, int end, bool value) {
DCHECK_LE(begin, end);
int start_offset = begin & (kIntBits - 1);
if (start_offset) {
// Set the bits in the first word.
int len = std::min(end - begin, kIntBits - start_offset);
SetWordBits(begin, len, value);
begin += len;
}
if (begin == end)
return;
// Now set the bits in the last word.
int end_offset = end & (kIntBits - 1);
end -= end_offset;
SetWordBits(end, end_offset, value);
// Set all the words in the middle.
memset(map_ + (begin / kIntBits), (value ? 0xFF : 0x00),
((end / kIntBits) - (begin / kIntBits)) * sizeof(*map_));
}
// Return true if any bit between begin inclusive and end exclusive
// is set. 0 <= begin <= end <= bits() is required.
bool Bitmap::TestRange(int begin, int end, bool value) const {
DCHECK_LT(begin, num_bits_);
DCHECK_LE(end, num_bits_);
DCHECK_LE(begin, end);
DCHECK_GE(begin, 0);
DCHECK_GE(end, 0);
// Return false immediately if the range is empty.
if (begin >= end || end <= 0)
return false;
// Calculate the indices of the words containing the first and last bits,
// along with the positions of the bits within those words.
int word = begin / kIntBits;
int offset = begin & (kIntBits - 1);
int last_word = (end - 1) / kIntBits;
int last_offset = (end - 1) & (kIntBits - 1);
// If we are looking for zeros, negate the data from the map.
uint32 this_word = map_[word];
if (!value)
this_word = ~this_word;
// If the range spans multiple words, discard the extraneous bits of the
// first word by shifting to the right, and then test the remaining bits.
if (word < last_word) {
if (this_word >> offset)
return true;
offset = 0;
word++;
// Test each of the "middle" words that lies completely within the range.
while (word < last_word) {
this_word = map_[word++];
if (!value)
this_word = ~this_word;
if (this_word)
return true;
}
}
// Test the portion of the last word that lies within the range. (This logic
// also handles the case where the entire range lies within a single word.)
const uint32 mask = ((2 << (last_offset - offset)) - 1) << offset;
this_word = map_[last_word];
if (!value)
this_word = ~this_word;
return (this_word & mask) != 0;
}
bool Bitmap::FindNextBit(int* index, int limit, bool value) const {
DCHECK_LT(*index, num_bits_);
DCHECK_LE(limit, num_bits_);
DCHECK_LE(*index, limit);
DCHECK_GE(*index, 0);
DCHECK_GE(limit, 0);
const int bit_index = *index;
if (bit_index >= limit || limit <= 0)
return false;
// From now on limit != 0, since if it was we would have returned false.
int word_index = bit_index >> kLogIntBits;
uint32 one_word = map_[word_index];
// Simple optimization where we can immediately return true if the first
// bit is set. This helps for cases where many bits are set, and doesn't
// hurt too much if not.
if (Get(bit_index) == value)
return true;
const int first_bit_offset = bit_index & (kIntBits - 1);
// First word is special - we need to mask off leading bits.
uint32 mask = 0xFFFFFFFF << first_bit_offset;
if (value) {
one_word &= mask;
} else {
one_word |= ~mask;
}
uint32 empty_value = value ? 0 : 0xFFFFFFFF;
// Loop through all but the last word. Note that 'limit' is one
// past the last bit we want to check, and we don't want to read
// past the end of "words". E.g. if num_bits_ == 32 only words[0] is
// valid, so we want to avoid reading words[1] when limit == 32.
const int last_word_index = (limit - 1) >> kLogIntBits;
while (word_index < last_word_index) {
if (one_word != empty_value) {
*index = (word_index << kLogIntBits) + FindLSBNonEmpty(one_word, value);
return true;
}
one_word = map_[++word_index];
}
// Last word is special - we may need to mask off trailing bits. Note that
// 'limit' is one past the last bit we want to check, and if limit is a
// multiple of 32 we want to check all bits in this word.
const int last_bit_offset = (limit - 1) & (kIntBits - 1);
mask = 0xFFFFFFFE << last_bit_offset;
if (value) {
one_word &= ~mask;
} else {
one_word |= mask;
}
if (one_word != empty_value) {
*index = (word_index << kLogIntBits) + FindLSBNonEmpty(one_word, value);
return true;
}
return false;
}
int Bitmap::FindBits(int* index, int limit, bool value) const {
DCHECK_LT(*index, num_bits_);
DCHECK_LE(limit, num_bits_);
DCHECK_LE(*index, limit);
DCHECK_GE(*index, 0);
DCHECK_GE(limit, 0);
if (!FindNextBit(index, limit, value))
return false;
// Now see how many bits have the same value.
int end = *index;
if (!FindNextBit(&end, limit, !value))
return limit - *index;
return end - *index;
}
void Bitmap::SetWordBits(int start, int len, bool value) {
DCHECK_LT(len, kIntBits);
DCHECK_GE(len, 0);
if (!len)
return;
int word = start / kIntBits;
int offset = start % kIntBits;
uint32 to_add = 0xffffffff << len;
to_add = (~to_add) << offset;
if (value) {
map_[word] |= to_add;
} else {
map_[word] &= ~to_add;
}
}
} // namespace disk_cache
| anirudhSK/chromium | net/disk_cache/blockfile/bitmap.cc | C++ | bsd-3-clause | 8,691 |
/*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
*
* @bug 4959409
* @author Naoto Sato
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class bug4959409 extends javax.swing.JApplet {
public void init() {
new TestFrame();
}
}
class TestFrame extends JFrame implements KeyListener {
JTextField text;
JLabel label;
TestFrame () {
text = new JTextField();
text.addKeyListener(this);
label = new JLabel(" ");
Container c = getContentPane();
BorderLayout borderLayout1 = new BorderLayout();
c.setLayout(borderLayout1);
c.add(text, BorderLayout.CENTER);
c.add(label, BorderLayout.SOUTH);
setSize(300, 200);
setVisible(true);
}
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
int mods = e.getModifiers();
if (code == '1' && mods == KeyEvent.SHIFT_MASK) {
label.setText("KEYPRESS received for Shift+1");
} else {
label.setText(" ");
}
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
}
| rokn/Count_Words_2015 | testing/openjdk2/jdk/test/java/awt/im/4959409/bug4959409.java | Java | mit | 2,168 |
/**
* Copyright (c) 2011 Trusted Logic S.A.
* 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 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
*/
/*
* This header file contains extensions to the TEE Client API that are
* specific to the Trusted Foundations implementations
*/
#ifndef __TEE_CLIENT_API_EX_H__
#define __TEE_CLIENT_API_EX_H__
#include <linux/types.h>
/* Implementation-defined login types */
#define TEEC_LOGIN_AUTHENTICATION 0x80000000
#define TEEC_LOGIN_PRIVILEGED 0x80000002
#define TEEC_LOGIN_PRIVILEGED_KERNEL 0x80000002
/* Type definitions */
typedef u64 TEEC_TimeLimit;
void TEEC_EXPORT TEEC_GetTimeLimit(
TEEC_Context * context,
uint32_t timeout,
TEEC_TimeLimit *timeLimit);
TEEC_Result TEEC_EXPORT TEEC_OpenSessionEx(
TEEC_Context * context,
TEEC_Session * session,
const TEEC_TimeLimit *timeLimit,
const TEEC_UUID * destination,
uint32_t connectionMethod,
void *connectionData,
TEEC_Operation * operation,
uint32_t *errorOrigin);
TEEC_Result TEEC_EXPORT TEEC_InvokeCommandEx(
TEEC_Session * session,
const TEEC_TimeLimit *timeLimit,
uint32_t commandID,
TEEC_Operation * operation,
uint32_t *errorOrigin);
#endif /* __TEE_CLIENT_API_EX_H__ */
| prisciou/android_kernel_wiko_s9321 | security/tf_driver/tee_client_api_ex.h | C | gpl-2.0 | 1,902 |
/*
* Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
*
* @APPPLANT_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPPLANT_LICENSE_HEADER_END@
*/
package de.appplant.cordova.plugin.localnotification;
import de.appplant.cordova.plugin.notification.Builder;
import de.appplant.cordova.plugin.notification.Notification;
import de.appplant.cordova.plugin.notification.TriggerReceiver;
/**
* The receiver activity is triggered when a notification is clicked by a user.
* The activity calls the background callback and brings the launch intent
* up to foreground.
*/
public class ClickActivity extends de.appplant.cordova.plugin.notification.ClickActivity {
/**
* Called when local notification was clicked by the user.
*
* @param notification
* Wrapper around the local notification
*/
@Override
public void onClick(Notification notification) {
LocalNotification.fireEvent("click", notification);
if (!notification.getOptions().isOngoing()) {
String event = notification.isRepeating() ? "clear" : "cancel";
LocalNotification.fireEvent(event, notification);
}
super.onClick(notification);
}
/**
* Build notification specified by options.
*
* @param builder
* Notification builder
*/
@Override
public Notification buildNotification (Builder builder) {
return builder
.setTriggerReceiver(TriggerReceiver.class)
.build();
}
}
| ElieSauveterre/cordova-plugin-local-notifications | src/android/ClickActivity.java | Java | apache-2.0 | 2,346 |
declare var a: number;
var b: typeof a = "...";
var c: typeof a = "...";
type T = number;
var x:T = "...";
// what about recursive unions?
| kidaa/kythe | third_party/flow/tests/reflection/type.js | JavaScript | apache-2.0 | 141 |
/**
* Italian translation for bootstrap-datepicker
* Enrico Rubboli <rubboli@gmail.com>
*/
;(function($){
$.fn.datepicker.dates['it'] = {
days: ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato", "Domenica"],
daysShort: ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab", "Dom"],
daysMin: ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa", "Do"],
months: ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
monthsShort: ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"],
today: "Oggi",
weekStart: 1,
format: "dd/mm/yyyy"
};
}(jQuery));
| zxinStar/footshop | zxAdmin/assets/js/uncompressed/date-time/locales/bootstrap-datepicker.it.js | JavaScript | agpl-3.0 | 694 |
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\LdapBindAuthenticationProvider;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Ldap\Exception\ConnectionException;
/**
* @requires extension ldap
*/
class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
* @expectedExceptionMessage The presented password is invalid.
*/
public function testBindFailureShouldThrowAnException()
{
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
$ldap
->expects($this->once())
->method('bind')
->will($this->throwException(new ConnectionException()))
;
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
$reflection->setAccessible(true);
$reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', '', 'key'));
}
public function testRetrieveUser()
{
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
$userProvider
->expects($this->once())
->method('loadUserByUsername')
->with('foo')
;
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
$reflection = new \ReflectionMethod($provider, 'retrieveUser');
$reflection->setAccessible(true);
$reflection->invoke($provider, 'foo', new UsernamePasswordToken('foo', 'bar', 'key'));
}
}
| rakeshsojitra/test | vendor/symfony/symfony/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php | PHP | mit | 2,513 |
<a href='https://github.com/angular/angular.js/edit/v1.5.x/docs/content/error/$compile/nodomevents.ngdoc?message=docs(error%2Fnodomevents)%3A%20describe%20your%20change...' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit"> </i>Improve this Doc</a>
<h1>Error: $compile:nodomevents
<div><span class='hint'>Interpolated Event Attributes</span></div>
</h1>
<div>
<pre class="minerr-errmsg" error-display="Interpolations for HTML DOM event attributes are disallowed. Please use the ng- versions (such as ng-click instead of onclick) instead.">Interpolations for HTML DOM event attributes are disallowed. Please use the ng- versions (such as ng-click instead of onclick) instead.</pre>
</div>
<h2>Description</h2>
<div class="description">
<p>This error occurs when one tries to create a binding for event handler attributes like <code>onclick</code>, <code>onload</code>, <code>onsubmit</code>, etc.</p>
<p>There is no practical value in binding to these attributes and doing so only exposes your application to security vulnerabilities like XSS.
For these reasons binding to event handler attributes (all attributes that start with <code>on</code> and <code>formaction</code> attribute) is not supported.</p>
<p>An example code that would allow XSS vulnerability by evaluating user input in the window context could look like this:</p>
<pre><code><input ng-model="username">
<div onclick="{{username}}">click me</div>
</code></pre>
<p>Since the <code>onclick</code> evaluates the value as JavaScript code in the window context, setting the <code>username</code> model to a value like <code>javascript:alert('PWND')</code> would result in script injection when the <code>div</code> is clicked.</p>
</div>
| keithbox/PPSP-360_Degree_Evaluation_System | web_root/third-party/angularjs/angular-1.5.0/docs/partials/error/$compile/nodomevents.html | HTML | gpl-3.0 | 1,792 |
/*
* See file CREDITS for list of people who contributed to this
* project.
*
* 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
*/
/*
* lh7a40x SoC series common interface
*/
#ifndef __LH7A40X_H__
#define __LH7A40X_H__
/* (SMC) Static Memory Controller (usersguide 4.2.1) */
typedef struct {
volatile u32 attib;
volatile u32 com;
volatile u32 io;
volatile u32 rsvd1;
} /*__attribute__((__packed__))*/ lh7a40x_pccard_t;
typedef struct {
volatile u32 bcr[8];
lh7a40x_pccard_t pccard[2];
volatile u32 pcmciacon;
} /*__attribute__((__packed__))*/ lh7a40x_smc_t;
#define LH7A40X_SMC_BASE (0x80002000)
#define LH7A40X_SMC_PTR ((lh7a40x_smc_t*) LH7A40X_SMC_BASE)
/* (SDMC) Synchronous Dynamic Ram Controller (usersguide 5.3.1) */
typedef struct {
volatile u32 rsvd1;
volatile u32 gblcnfg;
volatile u32 rfshtmr;
volatile u32 bootstat;
volatile u32 sdcsc[4];
} /*__attribute__((__packed__))*/ lh7a40x_sdmc_t;
#define LH7A40X_SDMC_BASE (0x80002400)
#define LH7A40X_SDMC_PTR ((lh7a40x_sdmc_t*) LH7A40X_SDMC_BASE)
/* (CSC) Clock and State Controller (userguide 6.2.1) */
typedef struct {
volatile u32 pwrsr;
volatile u32 pwrcnt;
volatile u32 halt;
volatile u32 stby;
volatile u32 bleoi;
volatile u32 mceoi;
volatile u32 teoi;
volatile u32 stfclr;
volatile u32 clkset;
volatile u32 scrreg[2];
volatile u32 rsvd1;
volatile u32 usbreset;
} /*__attribute__((__packed__))*/ lh7a40x_csc_t;
#define LH7A40X_STPWR_BASE (0x80000400)
#define LH7A40X_CSC_PTR ((lh7a40x_csc_t*) LH7A40X_STPWR_BASE)
#define CLKSET_SMCROM (0x01000000)
#define CLKSET_PS (0x000C0000)
#define CLKSET_PS_0 (0x00000000)
#define CLKSET_PS_1 (0x00040000)
#define CLKSET_PS_2 (0x00080000)
#define CLKSET_PS_3 (0x000C0000)
#define CLKSET_PCLKDIV (0x00030000)
#define CLKSET_PCLKDIV_2 (0x00000000)
#define CLKSET_PCLKDIV_4 (0x00010000)
#define CLKSET_PCLKDIV_8 (0x00020000)
#define CLKSET_MAINDIV2 (0x0000f800)
#define CLKSET_MAINDIV1 (0x00000780)
#define CLKSET_PREDIV (0x0000007C)
#define CLKSET_HCLKDIV (0x00000003)
/* (DMA) Direct Memory Access Controller (userguide 9.2.1) */
typedef struct {
volatile u32 maxcnt;
volatile u32 base;
volatile u32 current;
volatile u32 rsvd1;
} lh7a40x_dmabuf_t;
typedef struct {
volatile u32 control;
volatile u32 interrupt;
volatile u32 rsvd1;
volatile u32 status;
volatile u32 rsvd2;
volatile u32 remain;
volatile u32 rsvd3;
volatile u32 rsvd4;
lh7a40x_dmabuf_t buf[2];
} /*__attribute__((__packed__))*/ lh7a40x_dmachan_t;
/* (WDT) Watchdog Timer (userguide 11.2.1) */
typedef struct {
volatile u32 ctl;
volatile u32 rst;
volatile u32 status;
volatile u32 count[4];
} /*__attribute__((__packed__))*/ lh7a40x_wdt_t;
#define LH7A40X_WDT_BASE (0x80001400)
#define LH7A40X_WDT_PTR ((lh7a40x_wdt_t*) LH7A40X_WDT_BASE)
/* (RTC) Real Time Clock (lh7a400 userguide 12.2.1, lh7a404 userguide 13.2.1) */
typedef struct {
volatile u32 rtcdr;
volatile u32 rtclr;
volatile u32 rtcmr;
volatile u32 unk1;
volatile u32 rtcstat_eoi;
volatile u32 rtccr;
volatile u32 rsvd1[58];
} /*__attribute__((__packed__))*/ lh7a40x_rtc_t;
#define LH7A40X_RTC_BASE (0x80000D00)
#define LH7A40X_RTC_PTR ((lh7a40x_rtc_t*) LH7A40X_RTC_BASE)
/* Timers (lh7a400 userguide 13.2.1, lh7a404 userguide 11.2.1) */
typedef struct {
volatile u32 load;
volatile u32 value;
volatile u32 control;
volatile u32 tceoi;
} /*__attribute__((__packed__))*/ lh7a40x_timer_t;
typedef struct {
lh7a40x_timer_t timer1;
volatile u32 rsvd1[4];
lh7a40x_timer_t timer2;
volatile u32 unk1[4];
volatile u32 bzcon;
volatile u32 unk2[15];
lh7a40x_timer_t timer3;
/*volatile u32 rsvd2;*/
} /*__attribute__((__packed__))*/ lh7a40x_timers_t;
#define LH7A40X_TIMERS_BASE (0x80000C00)
#define LH7A40X_TIMERS_PTR ((lh7a40x_timers_t*) LH7A40X_TIMERS_BASE)
#define TIMER_EN (0x00000080)
#define TIMER_PER (0x00000040)
#define TIMER_FREE (0x00000000)
#define TIMER_CLK508K (0x00000008)
#define TIMER_CLK2K (0x00000000)
/* (SSP) Sychronous Serial Ports (lh7a400 userguide 14.2.1, lh7a404 userguide 14.2.1) */
typedef struct {
volatile u32 cr0;
volatile u32 cr1;
volatile u32 irr_roeoi;
volatile u32 dr;
volatile u32 cpr;
volatile u32 sr;
/*volatile u32 rsvd1[58];*/
} /*__attribute__((__packed__))*/ lh7a40x_ssp_t;
#define LH7A40X_SSP_BASE (0x80000B00)
#define LH7A40X_SSP_PTR ((lh7a40x_ssp_t*) LH7A40X_SSP_BASE)
/* (UART) Universal Asychronous Receiver/Transmitter (lh7a400 userguide 15.2.1, lh7a404 userguide 15.2.1) */
typedef struct {
volatile u32 data;
volatile u32 fcon;
volatile u32 brcon;
volatile u32 con;
volatile u32 status;
volatile u32 rawisr;
volatile u32 inten;
volatile u32 isr;
volatile u32 rsvd1[56];
} /*__attribute__((__packed__))*/ lh7a40x_uart_t;
#define LH7A40X_UART_BASE (0x80000600)
#define LH7A40X_UART_PTR(n) \
((lh7a40x_uart_t*) (LH7A40X_UART_BASE + ((n-1) * sizeof(lh7a40x_uart_t))))
#define UART_BE (0x00000800) /* the rx error bits */
#define UART_OE (0x00000400)
#define UART_PE (0x00000200)
#define UART_FE (0x00000100)
#define UART_WLEN (0x00000060) /* fcon bits */
#define UART_WLEN_8 (0x00000060)
#define UART_WLEN_7 (0x00000040)
#define UART_WLEN_6 (0x00000020)
#define UART_WLEN_5 (0x00000000)
#define UART_FEN (0x00000010)
#define UART_STP2 (0x00000008)
#define UART_STP2_2 (0x00000008)
#define UART_STP2_1 (0x00000000)
#define UART_EPS (0x00000004)
#define UART_EPS_EVEN (0x00000004)
#define UART_EPS_ODD (0x00000000)
#define UART_PEN (0x00000002)
#define UART_BRK (0x00000001)
#define UART_BAUDDIV (0x0000ffff) /* brcon bits */
#define UART_SIRBD (0x00000080) /* con bits */
#define UART_LBE (0x00000040)
#define UART_MXP (0x00000020)
#define UART_TXP (0x00000010)
#define UART_RXP (0x00000008)
#define UART_SIRLP (0x00000004)
#define UART_SIRD (0x00000002)
#define UART_EN (0x00000001)
#define UART_TXFE (0x00000080) /* status bits */
#define UART_RXFF (0x00000040)
#define UART_TXFF (0x00000020)
#define UART_RXFE (0x00000010)
#define UART_BUSY (0x00000008)
#define UART_DCD (0x00000004)
#define UART_DSR (0x00000002)
#define UART_CTS (0x00000001)
#define UART_MSEOI (0xfffffff0) /* rawisr interrupt bits */
#define UART_RTI (0x00000008) /* generic interrupt bits */
#define UART_MI (0x00000004)
#define UART_TI (0x00000002)
#define UART_RI (0x00000001)
/* (GPIO) General Purpose IO and External Interrupts (userguide 16.2.1) */
typedef struct {
volatile u32 pad;
volatile u32 pbd;
volatile u32 pcd;
volatile u32 pdd;
volatile u32 padd;
volatile u32 pbdd;
volatile u32 pcdd;
volatile u32 pddd;
volatile u32 ped;
volatile u32 pedd;
volatile u32 kbdctl;
volatile u32 pinmux;
volatile u32 pfd;
volatile u32 pfdd;
volatile u32 pgd;
volatile u32 pgdd;
volatile u32 phd;
volatile u32 phdd;
volatile u32 rsvd1;
volatile u32 inttype1;
volatile u32 inttype2;
volatile u32 gpiofeoi;
volatile u32 gpiointen;
volatile u32 intstatus;
volatile u32 rawintstatus;
volatile u32 gpiodb;
volatile u32 papd;
volatile u32 pbpd;
volatile u32 pcpd;
volatile u32 pdpd;
volatile u32 pepd;
volatile u32 pfpd;
volatile u32 pgpd;
volatile u32 phpd;
} /*__attribute__((__packed__))*/ lh7a40x_gpioint_t;
#define LH7A40X_GPIOINT_BASE (0x80000E00)
#define LH7A40X_GPIOINT_PTR ((lh7a40x_gpioint_t*) LH7A40X_GPIOINT_BASE)
/* Embedded SRAM */
#define CFG_SRAM_BASE (0xB0000000)
#define CFG_SRAM_SIZE (80*1024) /* 80kB */
#endif /* __LH7A40X_H__ */
| daydaygit/flrelse | uboot1.1.6/include/lh7a40x.h | C | gpl-3.0 | 8,214 |
/*
* Copyright 2012 Twitter Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.twitter.zipkin.common.json
import com.twitter.zipkin.query.TraceTimeline
import com.twitter.finagle.tracing.SpanId
case class JsonTraceTimeline(traceId: String, rootSpanId: String, annotations: Seq[JsonTimelineAnnotation],
binaryAnnotations: Seq[JsonBinaryAnnotation])
extends WrappedJson
object JsonTraceTimeline {
def wrap(t: TraceTimeline) =
new JsonTraceTimeline(SpanId(t.traceId).toString, SpanId(t.rootSpanId).toString, t.annotations map { JsonTimelineAnnotation.wrap(_) }, t.binaryAnnotations map { JsonBinaryAnnotation.wrap(_) })
} | siddhaism/zipkin | zipkin-web/src/main/scala/com/twitter/zipkin/common/json/JsonTraceTimeline.scala | Scala | apache-2.0 | 1,188 |
// Copyright 2007, Google 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 Google Inc. 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.
// Google Test - The Google C++ Testing and Mocking Framework
//
// This file implements a universal value printer that can print a
// value of any type T:
//
// void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
//
// It uses the << operator when possible, and prints the bytes in the
// object otherwise. A user can override its behavior for a class
// type Foo by defining either operator<<(::std::ostream&, const Foo&)
// or void PrintTo(const Foo&, ::std::ostream*) in the namespace that
// defines Foo.
#include "gtest/gtest-printers.h"
#include <stdio.h>
#include <cctype>
#include <cwchar>
#include <ostream> // NOLINT
#include <string>
#include "gtest/internal/gtest-port.h"
#include "src/gtest-internal-inl.h"
namespace testing {
namespace {
using ::std::ostream;
// Prints a segment of bytes in the given object.
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
size_t count, ostream* os) {
char text[5] = "";
for (size_t i = 0; i != count; i++) {
const size_t j = start + i;
if (i != 0) {
// Organizes the bytes into groups of 2 for easy parsing by
// human.
if ((j % 2) == 0)
*os << ' ';
else
*os << '-';
}
GTEST_SNPRINTF_(text, sizeof(text), "%02X", obj_bytes[j]);
*os << text;
}
}
// Prints the bytes in the given value to the given ostream.
void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
ostream* os) {
// Tells the user how big the object is.
*os << count << "-byte object <";
const size_t kThreshold = 132;
const size_t kChunkSize = 64;
// If the object size is bigger than kThreshold, we'll have to omit
// some details by printing only the first and the last kChunkSize
// bytes.
if (count < kThreshold) {
PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
} else {
PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
*os << " ... ";
// Rounds up to 2-byte boundary.
const size_t resume_pos = (count - kChunkSize + 1)/2*2;
PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os);
}
*os << ">";
}
} // namespace
namespace internal2 {
// Delegates to PrintBytesInObjectToImpl() to print the bytes in the
// given object. The delegation simplifies the implementation, which
// uses the << operator and thus is easier done outside of the
// ::testing::internal namespace, which contains a << operator that
// sometimes conflicts with the one in STL.
void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count,
ostream* os) {
PrintBytesInObjectToImpl(obj_bytes, count, os);
}
} // namespace internal2
namespace internal {
// Depending on the value of a char (or wchar_t), we print it in one
// of three formats:
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
// - as a hexadecimal escape sequence (e.g. '\x7F'), or
// - as a special escape sequence (e.g. '\r', '\n').
enum CharFormat {
kAsIs,
kHexEscape,
kSpecialEscape
};
// Returns true if c is a printable ASCII character. We test the
// value of c directly instead of calling isprint(), which is buggy on
// Windows Mobile.
inline bool IsPrintableAscii(wchar_t c) {
return 0x20 <= c && c <= 0x7E;
}
// Prints a wide or narrow char c as a character literal without the
// quotes, escaping it when necessary; returns how c was formatted.
// The template argument UnsignedChar is the unsigned version of Char,
// which is the type of c.
template <typename UnsignedChar, typename Char>
static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
wchar_t w_c = static_cast<wchar_t>(c);
switch (w_c) {
case L'\0':
*os << "\\0";
break;
case L'\'':
*os << "\\'";
break;
case L'\\':
*os << "\\\\";
break;
case L'\a':
*os << "\\a";
break;
case L'\b':
*os << "\\b";
break;
case L'\f':
*os << "\\f";
break;
case L'\n':
*os << "\\n";
break;
case L'\r':
*os << "\\r";
break;
case L'\t':
*os << "\\t";
break;
case L'\v':
*os << "\\v";
break;
default:
if (IsPrintableAscii(w_c)) {
*os << static_cast<char>(c);
return kAsIs;
} else {
ostream::fmtflags flags = os->flags();
*os << "\\x" << std::hex << std::uppercase
<< static_cast<int>(static_cast<UnsignedChar>(c));
os->flags(flags);
return kHexEscape;
}
}
return kSpecialEscape;
}
// Prints a wchar_t c as if it's part of a string literal, escaping it when
// necessary; returns how c was formatted.
static CharFormat PrintAsStringLiteralTo(wchar_t c, ostream* os) {
switch (c) {
case L'\'':
*os << "'";
return kAsIs;
case L'"':
*os << "\\\"";
return kSpecialEscape;
default:
return PrintAsCharLiteralTo<wchar_t>(c, os);
}
}
// Prints a char c as if it's part of a string literal, escaping it when
// necessary; returns how c was formatted.
static CharFormat PrintAsStringLiteralTo(char c, ostream* os) {
return PrintAsStringLiteralTo(
static_cast<wchar_t>(static_cast<unsigned char>(c)), os);
}
// Prints a wide or narrow character c and its code. '\0' is printed
// as "'\\0'", other unprintable characters are also properly escaped
// using the standard C++ escape sequence. The template argument
// UnsignedChar is the unsigned version of Char, which is the type of c.
template <typename UnsignedChar, typename Char>
void PrintCharAndCodeTo(Char c, ostream* os) {
// First, print c as a literal in the most readable form we can find.
*os << ((sizeof(c) > 1) ? "L'" : "'");
const CharFormat format = PrintAsCharLiteralTo<UnsignedChar>(c, os);
*os << "'";
// To aid user debugging, we also print c's code in decimal, unless
// it's 0 (in which case c was printed as '\\0', making the code
// obvious).
if (c == 0)
return;
*os << " (" << static_cast<int>(c);
// For more convenience, we print c's code again in hexadecimal,
// unless c was already printed in the form '\x##' or the code is in
// [1, 9].
if (format == kHexEscape || (1 <= c && c <= 9)) {
// Do nothing.
} else {
*os << ", 0x" << String::FormatHexInt(static_cast<int>(c));
}
*os << ")";
}
void PrintTo(unsigned char c, ::std::ostream* os) {
PrintCharAndCodeTo<unsigned char>(c, os);
}
void PrintTo(signed char c, ::std::ostream* os) {
PrintCharAndCodeTo<unsigned char>(c, os);
}
// Prints a wchar_t as a symbol if it is printable or as its internal
// code otherwise and also as its code. L'\0' is printed as "L'\\0'".
void PrintTo(wchar_t wc, ostream* os) {
PrintCharAndCodeTo<wchar_t>(wc, os);
}
// Prints the given array of characters to the ostream. CharType must be either
// char or wchar_t.
// The array starts at begin, the length is len, it may include '\0' characters
// and may not be NUL-terminated.
template <typename CharType>
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
static CharFormat PrintCharsAsStringTo(
const CharType* begin, size_t len, ostream* os) {
const char* const kQuoteBegin = sizeof(CharType) == 1 ? "\"" : "L\"";
*os << kQuoteBegin;
bool is_previous_hex = false;
CharFormat print_format = kAsIs;
for (size_t index = 0; index < len; ++index) {
const CharType cur = begin[index];
if (is_previous_hex && IsXDigit(cur)) {
// Previous character is of '\x..' form and this character can be
// interpreted as another hexadecimal digit in its number. Break string to
// disambiguate.
*os << "\" " << kQuoteBegin;
}
is_previous_hex = PrintAsStringLiteralTo(cur, os) == kHexEscape;
// Remember if any characters required hex escaping.
if (is_previous_hex) {
print_format = kHexEscape;
}
}
*os << "\"";
return print_format;
}
// Prints a (const) char/wchar_t array of 'len' elements, starting at address
// 'begin'. CharType must be either char or wchar_t.
template <typename CharType>
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
static void UniversalPrintCharArray(
const CharType* begin, size_t len, ostream* os) {
// The code
// const char kFoo[] = "foo";
// generates an array of 4, not 3, elements, with the last one being '\0'.
//
// Therefore when printing a char array, we don't print the last element if
// it's '\0', such that the output matches the string literal as it's
// written in the source code.
if (len > 0 && begin[len - 1] == '\0') {
PrintCharsAsStringTo(begin, len - 1, os);
return;
}
// If, however, the last element in the array is not '\0', e.g.
// const char kFoo[] = { 'f', 'o', 'o' };
// we must print the entire array. We also print a message to indicate
// that the array is not NUL-terminated.
PrintCharsAsStringTo(begin, len, os);
*os << " (no terminating NUL)";
}
// Prints a (const) char array of 'len' elements, starting at address 'begin'.
void UniversalPrintArray(const char* begin, size_t len, ostream* os) {
UniversalPrintCharArray(begin, len, os);
}
// Prints a (const) wchar_t array of 'len' elements, starting at address
// 'begin'.
void UniversalPrintArray(const wchar_t* begin, size_t len, ostream* os) {
UniversalPrintCharArray(begin, len, os);
}
// Prints the given C string to the ostream.
void PrintTo(const char* s, ostream* os) {
if (s == nullptr) {
*os << "NULL";
} else {
*os << ImplicitCast_<const void*>(s) << " pointing to ";
PrintCharsAsStringTo(s, strlen(s), os);
}
}
// MSVC compiler can be configured to define whar_t as a typedef
// of unsigned short. Defining an overload for const wchar_t* in that case
// would cause pointers to unsigned shorts be printed as wide strings,
// possibly accessing more memory than intended and causing invalid
// memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
// wchar_t is implemented as a native type.
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
// Prints the given wide C string to the ostream.
void PrintTo(const wchar_t* s, ostream* os) {
if (s == nullptr) {
*os << "NULL";
} else {
*os << ImplicitCast_<const void*>(s) << " pointing to ";
PrintCharsAsStringTo(s, wcslen(s), os);
}
}
#endif // wchar_t is native
namespace {
bool ContainsUnprintableControlCodes(const char* str, size_t length) {
const unsigned char *s = reinterpret_cast<const unsigned char *>(str);
for (size_t i = 0; i < length; i++) {
unsigned char ch = *s++;
if (std::iscntrl(ch)) {
switch (ch) {
case '\t':
case '\n':
case '\r':
break;
default:
return true;
}
}
}
return false;
}
bool IsUTF8TrailByte(unsigned char t) { return 0x80 <= t && t<= 0xbf; }
bool IsValidUTF8(const char* str, size_t length) {
const unsigned char *s = reinterpret_cast<const unsigned char *>(str);
for (size_t i = 0; i < length;) {
unsigned char lead = s[i++];
if (lead <= 0x7f) {
continue; // single-byte character (ASCII) 0..7F
}
if (lead < 0xc2) {
return false; // trail byte or non-shortest form
} else if (lead <= 0xdf && (i + 1) <= length && IsUTF8TrailByte(s[i])) {
++i; // 2-byte character
} else if (0xe0 <= lead && lead <= 0xef && (i + 2) <= length &&
IsUTF8TrailByte(s[i]) &&
IsUTF8TrailByte(s[i + 1]) &&
// check for non-shortest form and surrogate
(lead != 0xe0 || s[i] >= 0xa0) &&
(lead != 0xed || s[i] < 0xa0)) {
i += 2; // 3-byte character
} else if (0xf0 <= lead && lead <= 0xf4 && (i + 3) <= length &&
IsUTF8TrailByte(s[i]) &&
IsUTF8TrailByte(s[i + 1]) &&
IsUTF8TrailByte(s[i + 2]) &&
// check for non-shortest form
(lead != 0xf0 || s[i] >= 0x90) &&
(lead != 0xf4 || s[i] < 0x90)) {
i += 3; // 4-byte character
} else {
return false;
}
}
return true;
}
void ConditionalPrintAsText(const char* str, size_t length, ostream* os) {
if (!ContainsUnprintableControlCodes(str, length) &&
IsValidUTF8(str, length)) {
*os << "\n As Text: \"" << str << "\"";
}
}
} // anonymous namespace
void PrintStringTo(const ::std::string& s, ostream* os) {
if (PrintCharsAsStringTo(s.data(), s.size(), os) == kHexEscape) {
if (GTEST_FLAG(print_utf8)) {
ConditionalPrintAsText(s.data(), s.size(), os);
}
}
}
#if GTEST_HAS_STD_WSTRING
void PrintWideStringTo(const ::std::wstring& s, ostream* os) {
PrintCharsAsStringTo(s.data(), s.size(), os);
}
#endif // GTEST_HAS_STD_WSTRING
} // namespace internal
} // namespace testing
| NeblioTeam/neblio | wallet/test/googletest/googletest/src/gtest-printers.cc | C++ | mit | 14,711 |
kitten_paw
==========
This is the firmware for the 2016 revision of the Kitten Paw controller by Bathroom Epiphanies. Most of the boilerplate code is the work of [BathroomEpiphanies](https://github.com/BathroomEpiphanies).
NKRO doesn't work at the moment, I don't know if I will take the time to find out how to fix this, so far 6KRO is enough for me.
Keyboard Maintainer: QMK Community
Hardware Supported: Kitten Paw PCB
Hardware Availability: https://geekhack.org/index.php?topic=46700.0
Make example for this keyboard (after setting up your build environment):
make bpiphany/kitten_paw:default
See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).
| chancegrissom/qmk_firmware | keyboards/bpiphany/kitten_paw/readme.md | Markdown | gpl-2.0 | 882 |
/*
* osd_initiator - Main body of the osd initiator library.
*
* Note: The file does not contain the advanced security functionality which
* is only needed by the security_manager's initiators.
*
* Copyright (C) 2008 Panasas Inc. All rights reserved.
*
* Authors:
* Boaz Harrosh <ooo@electrozaur.com>
* Benny Halevy <bhalevy@panasas.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
*
* 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. Neither the name of the Panasas company 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 ``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 REGENTS 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.
*/
#include <linux/slab.h>
#include <linux/module.h>
#include <scsi/osd_initiator.h>
#include <scsi/osd_sec.h>
#include <scsi/osd_attributes.h>
#include <scsi/osd_sense.h>
#include <scsi/scsi_device.h>
#include "osd_debug.h"
#ifndef __unused
# define __unused __attribute__((unused))
#endif
enum { OSD_REQ_RETRIES = 1 };
MODULE_AUTHOR("Boaz Harrosh <ooo@electrozaur.com>");
MODULE_DESCRIPTION("open-osd initiator library libosd.ko");
MODULE_LICENSE("GPL");
static inline void build_test(void)
{
/* structures were not packed */
BUILD_BUG_ON(sizeof(struct osd_capability) != OSD_CAP_LEN);
BUILD_BUG_ON(sizeof(struct osdv2_cdb) != OSD_TOTAL_CDB_LEN);
BUILD_BUG_ON(sizeof(struct osdv1_cdb) != OSDv1_TOTAL_CDB_LEN);
}
static const char *_osd_ver_desc(struct osd_request *or)
{
return osd_req_is_ver1(or) ? "OSD1" : "OSD2";
}
#define ATTR_DEF_RI(id, len) ATTR_DEF(OSD_APAGE_ROOT_INFORMATION, id, len)
static int _osd_get_print_system_info(struct osd_dev *od,
void *caps, struct osd_dev_info *odi)
{
struct osd_request *or;
struct osd_attr get_attrs[] = {
ATTR_DEF_RI(OSD_ATTR_RI_VENDOR_IDENTIFICATION, 8),
ATTR_DEF_RI(OSD_ATTR_RI_PRODUCT_IDENTIFICATION, 16),
ATTR_DEF_RI(OSD_ATTR_RI_PRODUCT_MODEL, 32),
ATTR_DEF_RI(OSD_ATTR_RI_PRODUCT_REVISION_LEVEL, 4),
ATTR_DEF_RI(OSD_ATTR_RI_PRODUCT_SERIAL_NUMBER, 64 /*variable*/),
ATTR_DEF_RI(OSD_ATTR_RI_OSD_NAME, 64 /*variable*/),
ATTR_DEF_RI(OSD_ATTR_RI_TOTAL_CAPACITY, 8),
ATTR_DEF_RI(OSD_ATTR_RI_USED_CAPACITY, 8),
ATTR_DEF_RI(OSD_ATTR_RI_NUMBER_OF_PARTITIONS, 8),
ATTR_DEF_RI(OSD_ATTR_RI_CLOCK, 6),
/* IBM-OSD-SIM Has a bug with this one put it last */
ATTR_DEF_RI(OSD_ATTR_RI_OSD_SYSTEM_ID, 20),
};
void *iter = NULL, *pFirst;
int nelem = ARRAY_SIZE(get_attrs), a = 0;
int ret;
or = osd_start_request(od, GFP_KERNEL);
if (!or)
return -ENOMEM;
/* get attrs */
osd_req_get_attributes(or, &osd_root_object);
osd_req_add_get_attr_list(or, get_attrs, ARRAY_SIZE(get_attrs));
ret = osd_finalize_request(or, 0, caps, NULL);
if (ret)
goto out;
ret = osd_execute_request(or);
if (ret) {
OSD_ERR("Failed to detect %s => %d\n", _osd_ver_desc(or), ret);
goto out;
}
osd_req_decode_get_attr_list(or, get_attrs, &nelem, &iter);
OSD_INFO("Detected %s device\n",
_osd_ver_desc(or));
pFirst = get_attrs[a++].val_ptr;
OSD_INFO("VENDOR_IDENTIFICATION [%s]\n",
(char *)pFirst);
pFirst = get_attrs[a++].val_ptr;
OSD_INFO("PRODUCT_IDENTIFICATION [%s]\n",
(char *)pFirst);
pFirst = get_attrs[a++].val_ptr;
OSD_INFO("PRODUCT_MODEL [%s]\n",
(char *)pFirst);
pFirst = get_attrs[a++].val_ptr;
OSD_INFO("PRODUCT_REVISION_LEVEL [%u]\n",
pFirst ? get_unaligned_be32(pFirst) : ~0U);
pFirst = get_attrs[a++].val_ptr;
OSD_INFO("PRODUCT_SERIAL_NUMBER [%s]\n",
(char *)pFirst);
odi->osdname_len = get_attrs[a].len;
/* Avoid NULL for memcmp optimization 0-length is good enough */
odi->osdname = kzalloc(odi->osdname_len + 1, GFP_KERNEL);
if (!odi->osdname) {
ret = -ENOMEM;
goto out;
}
if (odi->osdname_len)
memcpy(odi->osdname, get_attrs[a].val_ptr, odi->osdname_len);
OSD_INFO("OSD_NAME [%s]\n", odi->osdname);
a++;
pFirst = get_attrs[a++].val_ptr;
OSD_INFO("TOTAL_CAPACITY [0x%llx]\n",
pFirst ? _LLU(get_unaligned_be64(pFirst)) : ~0ULL);
pFirst = get_attrs[a++].val_ptr;
OSD_INFO("USED_CAPACITY [0x%llx]\n",
pFirst ? _LLU(get_unaligned_be64(pFirst)) : ~0ULL);
pFirst = get_attrs[a++].val_ptr;
OSD_INFO("NUMBER_OF_PARTITIONS [%llu]\n",
pFirst ? _LLU(get_unaligned_be64(pFirst)) : ~0ULL);
if (a >= nelem)
goto out;
/* FIXME: Where are the time utilities */
pFirst = get_attrs[a++].val_ptr;
OSD_INFO("CLOCK [0x%6phN]\n", pFirst);
if (a < nelem) { /* IBM-OSD-SIM bug, Might not have it */
unsigned len = get_attrs[a].len;
char sid_dump[32*4 + 2]; /* 2nibbles+space+ASCII */
hex_dump_to_buffer(get_attrs[a].val_ptr, len, 32, 1,
sid_dump, sizeof(sid_dump), true);
OSD_INFO("OSD_SYSTEM_ID(%d)\n"
" [%s]\n", len, sid_dump);
if (unlikely(len > sizeof(odi->systemid))) {
OSD_ERR("OSD Target error: OSD_SYSTEM_ID too long(%d). "
"device identification might not work\n", len);
len = sizeof(odi->systemid);
}
odi->systemid_len = len;
memcpy(odi->systemid, get_attrs[a].val_ptr, len);
a++;
}
out:
osd_end_request(or);
return ret;
}
int osd_auto_detect_ver(struct osd_dev *od,
void *caps, struct osd_dev_info *odi)
{
int ret;
/* Auto-detect the osd version */
ret = _osd_get_print_system_info(od, caps, odi);
if (ret) {
osd_dev_set_ver(od, OSD_VER1);
OSD_DEBUG("converting to OSD1\n");
ret = _osd_get_print_system_info(od, caps, odi);
}
return ret;
}
EXPORT_SYMBOL(osd_auto_detect_ver);
static unsigned _osd_req_cdb_len(struct osd_request *or)
{
return osd_req_is_ver1(or) ? OSDv1_TOTAL_CDB_LEN : OSD_TOTAL_CDB_LEN;
}
static unsigned _osd_req_alist_elem_size(struct osd_request *or, unsigned len)
{
return osd_req_is_ver1(or) ?
osdv1_attr_list_elem_size(len) :
osdv2_attr_list_elem_size(len);
}
static void _osd_req_alist_elem_encode(struct osd_request *or,
void *attr_last, const struct osd_attr *oa)
{
if (osd_req_is_ver1(or)) {
struct osdv1_attributes_list_element *attr = attr_last;
attr->attr_page = cpu_to_be32(oa->attr_page);
attr->attr_id = cpu_to_be32(oa->attr_id);
attr->attr_bytes = cpu_to_be16(oa->len);
memcpy(attr->attr_val, oa->val_ptr, oa->len);
} else {
struct osdv2_attributes_list_element *attr = attr_last;
attr->attr_page = cpu_to_be32(oa->attr_page);
attr->attr_id = cpu_to_be32(oa->attr_id);
attr->attr_bytes = cpu_to_be16(oa->len);
memcpy(attr->attr_val, oa->val_ptr, oa->len);
}
}
static int _osd_req_alist_elem_decode(struct osd_request *or,
void *cur_p, struct osd_attr *oa, unsigned max_bytes)
{
unsigned inc;
if (osd_req_is_ver1(or)) {
struct osdv1_attributes_list_element *attr = cur_p;
if (max_bytes < sizeof(*attr))
return -1;
oa->len = be16_to_cpu(attr->attr_bytes);
inc = _osd_req_alist_elem_size(or, oa->len);
if (inc > max_bytes)
return -1;
oa->attr_page = be32_to_cpu(attr->attr_page);
oa->attr_id = be32_to_cpu(attr->attr_id);
/* OSD1: On empty attributes we return a pointer to 2 bytes
* of zeros. This keeps similar behaviour with OSD2.
* (See below)
*/
oa->val_ptr = likely(oa->len) ? attr->attr_val :
(u8 *)&attr->attr_bytes;
} else {
struct osdv2_attributes_list_element *attr = cur_p;
if (max_bytes < sizeof(*attr))
return -1;
oa->len = be16_to_cpu(attr->attr_bytes);
inc = _osd_req_alist_elem_size(or, oa->len);
if (inc > max_bytes)
return -1;
oa->attr_page = be32_to_cpu(attr->attr_page);
oa->attr_id = be32_to_cpu(attr->attr_id);
/* OSD2: For convenience, on empty attributes, we return 8 bytes
* of zeros here. This keeps the same behaviour with OSD2r04,
* and is nice with null terminating ASCII fields.
* oa->val_ptr == NULL marks the end-of-list, or error.
*/
oa->val_ptr = likely(oa->len) ? attr->attr_val : attr->reserved;
}
return inc;
}
static unsigned _osd_req_alist_size(struct osd_request *or, void *list_head)
{
return osd_req_is_ver1(or) ?
osdv1_list_size(list_head) :
osdv2_list_size(list_head);
}
static unsigned _osd_req_sizeof_alist_header(struct osd_request *or)
{
return osd_req_is_ver1(or) ?
sizeof(struct osdv1_attributes_list_header) :
sizeof(struct osdv2_attributes_list_header);
}
static void _osd_req_set_alist_type(struct osd_request *or,
void *list, int list_type)
{
if (osd_req_is_ver1(or)) {
struct osdv1_attributes_list_header *attr_list = list;
memset(attr_list, 0, sizeof(*attr_list));
attr_list->type = list_type;
} else {
struct osdv2_attributes_list_header *attr_list = list;
memset(attr_list, 0, sizeof(*attr_list));
attr_list->type = list_type;
}
}
static bool _osd_req_is_alist_type(struct osd_request *or,
void *list, int list_type)
{
if (!list)
return false;
if (osd_req_is_ver1(or)) {
struct osdv1_attributes_list_header *attr_list = list;
return attr_list->type == list_type;
} else {
struct osdv2_attributes_list_header *attr_list = list;
return attr_list->type == list_type;
}
}
/* This is for List-objects not Attributes-Lists */
static void _osd_req_encode_olist(struct osd_request *or,
struct osd_obj_id_list *list)
{
struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
if (osd_req_is_ver1(or)) {
cdbh->v1.list_identifier = list->list_identifier;
cdbh->v1.start_address = list->continuation_id;
} else {
cdbh->v2.list_identifier = list->list_identifier;
cdbh->v2.start_address = list->continuation_id;
}
}
static osd_cdb_offset osd_req_encode_offset(struct osd_request *or,
u64 offset, unsigned *padding)
{
return __osd_encode_offset(offset, padding,
osd_req_is_ver1(or) ?
OSDv1_OFFSET_MIN_SHIFT : OSD_OFFSET_MIN_SHIFT,
OSD_OFFSET_MAX_SHIFT);
}
static struct osd_security_parameters *
_osd_req_sec_params(struct osd_request *or)
{
struct osd_cdb *ocdb = &or->cdb;
if (osd_req_is_ver1(or))
return (struct osd_security_parameters *)&ocdb->v1.sec_params;
else
return (struct osd_security_parameters *)&ocdb->v2.sec_params;
}
void osd_dev_init(struct osd_dev *osdd, struct scsi_device *scsi_device)
{
memset(osdd, 0, sizeof(*osdd));
osdd->scsi_device = scsi_device;
osdd->def_timeout = BLK_DEFAULT_SG_TIMEOUT;
#ifdef OSD_VER1_SUPPORT
osdd->version = OSD_VER2;
#endif
/* TODO: Allocate pools for osd_request attributes ... */
}
EXPORT_SYMBOL(osd_dev_init);
void osd_dev_fini(struct osd_dev *osdd)
{
/* TODO: De-allocate pools */
osdd->scsi_device = NULL;
}
EXPORT_SYMBOL(osd_dev_fini);
static struct osd_request *_osd_request_alloc(gfp_t gfp)
{
struct osd_request *or;
/* TODO: Use mempool with one saved request */
or = kzalloc(sizeof(*or), gfp);
return or;
}
static void _osd_request_free(struct osd_request *or)
{
kfree(or);
}
struct osd_request *osd_start_request(struct osd_dev *dev, gfp_t gfp)
{
struct osd_request *or;
or = _osd_request_alloc(gfp);
if (!or)
return NULL;
or->osd_dev = dev;
or->alloc_flags = gfp;
or->timeout = dev->def_timeout;
or->retries = OSD_REQ_RETRIES;
return or;
}
EXPORT_SYMBOL(osd_start_request);
static void _osd_free_seg(struct osd_request *or __unused,
struct _osd_req_data_segment *seg)
{
if (!seg->buff || !seg->alloc_size)
return;
kfree(seg->buff);
seg->buff = NULL;
seg->alloc_size = 0;
}
static void _put_request(struct request *rq)
{
/*
* If osd_finalize_request() was called but the request was not
* executed through the block layer, then we must release BIOs.
* TODO: Keep error code in or->async_error. Need to audit all
* code paths.
*/
if (unlikely(rq->bio))
blk_end_request(rq, -ENOMEM, blk_rq_bytes(rq));
else
blk_put_request(rq);
}
void osd_end_request(struct osd_request *or)
{
struct request *rq = or->request;
if (rq) {
if (rq->next_rq) {
_put_request(rq->next_rq);
rq->next_rq = NULL;
}
_put_request(rq);
}
_osd_free_seg(or, &or->get_attr);
_osd_free_seg(or, &or->enc_get_attr);
_osd_free_seg(or, &or->set_attr);
_osd_free_seg(or, &or->cdb_cont);
_osd_request_free(or);
}
EXPORT_SYMBOL(osd_end_request);
static void _set_error_resid(struct osd_request *or, struct request *req,
int error)
{
or->async_error = error;
or->req_errors = req->errors ? : error;
or->sense_len = req->sense_len;
if (or->out.req)
or->out.residual = or->out.req->resid_len;
if (or->in.req)
or->in.residual = or->in.req->resid_len;
}
int osd_execute_request(struct osd_request *or)
{
int error = blk_execute_rq(or->request->q, NULL, or->request, 0);
_set_error_resid(or, or->request, error);
return error;
}
EXPORT_SYMBOL(osd_execute_request);
static void osd_request_async_done(struct request *req, int error)
{
struct osd_request *or = req->end_io_data;
_set_error_resid(or, req, error);
if (req->next_rq) {
__blk_put_request(req->q, req->next_rq);
req->next_rq = NULL;
}
__blk_put_request(req->q, req);
or->request = NULL;
or->in.req = NULL;
or->out.req = NULL;
if (or->async_done)
or->async_done(or, or->async_private);
else
osd_end_request(or);
}
int osd_execute_request_async(struct osd_request *or,
osd_req_done_fn *done, void *private)
{
or->request->end_io_data = or;
or->async_private = private;
or->async_done = done;
blk_execute_rq_nowait(or->request->q, NULL, or->request, 0,
osd_request_async_done);
return 0;
}
EXPORT_SYMBOL(osd_execute_request_async);
u8 sg_out_pad_buffer[1 << OSDv1_OFFSET_MIN_SHIFT];
u8 sg_in_pad_buffer[1 << OSDv1_OFFSET_MIN_SHIFT];
static int _osd_realloc_seg(struct osd_request *or,
struct _osd_req_data_segment *seg, unsigned max_bytes)
{
void *buff;
if (seg->alloc_size >= max_bytes)
return 0;
buff = krealloc(seg->buff, max_bytes, or->alloc_flags);
if (!buff) {
OSD_ERR("Failed to Realloc %d-bytes was-%d\n", max_bytes,
seg->alloc_size);
return -ENOMEM;
}
memset(buff + seg->alloc_size, 0, max_bytes - seg->alloc_size);
seg->buff = buff;
seg->alloc_size = max_bytes;
return 0;
}
static int _alloc_cdb_cont(struct osd_request *or, unsigned total_bytes)
{
OSD_DEBUG("total_bytes=%d\n", total_bytes);
return _osd_realloc_seg(or, &or->cdb_cont, total_bytes);
}
static int _alloc_set_attr_list(struct osd_request *or,
const struct osd_attr *oa, unsigned nelem, unsigned add_bytes)
{
unsigned total_bytes = add_bytes;
for (; nelem; --nelem, ++oa)
total_bytes += _osd_req_alist_elem_size(or, oa->len);
OSD_DEBUG("total_bytes=%d\n", total_bytes);
return _osd_realloc_seg(or, &or->set_attr, total_bytes);
}
static int _alloc_get_attr_desc(struct osd_request *or, unsigned max_bytes)
{
OSD_DEBUG("total_bytes=%d\n", max_bytes);
return _osd_realloc_seg(or, &or->enc_get_attr, max_bytes);
}
static int _alloc_get_attr_list(struct osd_request *or)
{
OSD_DEBUG("total_bytes=%d\n", or->get_attr.total_bytes);
return _osd_realloc_seg(or, &or->get_attr, or->get_attr.total_bytes);
}
/*
* Common to all OSD commands
*/
static void _osdv1_req_encode_common(struct osd_request *or,
__be16 act, const struct osd_obj_id *obj, u64 offset, u64 len)
{
struct osdv1_cdb *ocdb = &or->cdb.v1;
/*
* For speed, the commands
* OSD_ACT_PERFORM_SCSI_COMMAND , V1 0x8F7E, V2 0x8F7C
* OSD_ACT_SCSI_TASK_MANAGEMENT , V1 0x8F7F, V2 0x8F7D
* are not supported here. Should pass zero and set after the call
*/
act &= cpu_to_be16(~0x0080); /* V1 action code */
OSD_DEBUG("OSDv1 execute opcode 0x%x\n", be16_to_cpu(act));
ocdb->h.varlen_cdb.opcode = VARIABLE_LENGTH_CMD;
ocdb->h.varlen_cdb.additional_cdb_length = OSD_ADDITIONAL_CDB_LENGTH;
ocdb->h.varlen_cdb.service_action = act;
ocdb->h.partition = cpu_to_be64(obj->partition);
ocdb->h.object = cpu_to_be64(obj->id);
ocdb->h.v1.length = cpu_to_be64(len);
ocdb->h.v1.start_address = cpu_to_be64(offset);
}
static void _osdv2_req_encode_common(struct osd_request *or,
__be16 act, const struct osd_obj_id *obj, u64 offset, u64 len)
{
struct osdv2_cdb *ocdb = &or->cdb.v2;
OSD_DEBUG("OSDv2 execute opcode 0x%x\n", be16_to_cpu(act));
ocdb->h.varlen_cdb.opcode = VARIABLE_LENGTH_CMD;
ocdb->h.varlen_cdb.additional_cdb_length = OSD_ADDITIONAL_CDB_LENGTH;
ocdb->h.varlen_cdb.service_action = act;
ocdb->h.partition = cpu_to_be64(obj->partition);
ocdb->h.object = cpu_to_be64(obj->id);
ocdb->h.v2.length = cpu_to_be64(len);
ocdb->h.v2.start_address = cpu_to_be64(offset);
}
static void _osd_req_encode_common(struct osd_request *or,
__be16 act, const struct osd_obj_id *obj, u64 offset, u64 len)
{
if (osd_req_is_ver1(or))
_osdv1_req_encode_common(or, act, obj, offset, len);
else
_osdv2_req_encode_common(or, act, obj, offset, len);
}
/*
* Device commands
*/
/*TODO: void osd_req_set_master_seed_xchg(struct osd_request *, ...); */
/*TODO: void osd_req_set_master_key(struct osd_request *, ...); */
void osd_req_format(struct osd_request *or, u64 tot_capacity)
{
_osd_req_encode_common(or, OSD_ACT_FORMAT_OSD, &osd_root_object, 0,
tot_capacity);
}
EXPORT_SYMBOL(osd_req_format);
int osd_req_list_dev_partitions(struct osd_request *or,
osd_id initial_id, struct osd_obj_id_list *list, unsigned nelem)
{
return osd_req_list_partition_objects(or, 0, initial_id, list, nelem);
}
EXPORT_SYMBOL(osd_req_list_dev_partitions);
static void _osd_req_encode_flush(struct osd_request *or,
enum osd_options_flush_scope_values op)
{
struct osd_cdb_head *ocdb = osd_cdb_head(&or->cdb);
ocdb->command_specific_options = op;
}
void osd_req_flush_obsd(struct osd_request *or,
enum osd_options_flush_scope_values op)
{
_osd_req_encode_common(or, OSD_ACT_FLUSH_OSD, &osd_root_object, 0, 0);
_osd_req_encode_flush(or, op);
}
EXPORT_SYMBOL(osd_req_flush_obsd);
/*TODO: void osd_req_perform_scsi_command(struct osd_request *,
const u8 *cdb, ...); */
/*TODO: void osd_req_task_management(struct osd_request *, ...); */
/*
* Partition commands
*/
static void _osd_req_encode_partition(struct osd_request *or,
__be16 act, osd_id partition)
{
struct osd_obj_id par = {
.partition = partition,
.id = 0,
};
_osd_req_encode_common(or, act, &par, 0, 0);
}
void osd_req_create_partition(struct osd_request *or, osd_id partition)
{
_osd_req_encode_partition(or, OSD_ACT_CREATE_PARTITION, partition);
}
EXPORT_SYMBOL(osd_req_create_partition);
void osd_req_remove_partition(struct osd_request *or, osd_id partition)
{
_osd_req_encode_partition(or, OSD_ACT_REMOVE_PARTITION, partition);
}
EXPORT_SYMBOL(osd_req_remove_partition);
/*TODO: void osd_req_set_partition_key(struct osd_request *,
osd_id partition, u8 new_key_id[OSD_CRYPTO_KEYID_SIZE],
u8 seed[OSD_CRYPTO_SEED_SIZE]); */
static int _osd_req_list_objects(struct osd_request *or,
__be16 action, const struct osd_obj_id *obj, osd_id initial_id,
struct osd_obj_id_list *list, unsigned nelem)
{
struct request_queue *q = osd_request_queue(or->osd_dev);
u64 len = nelem * sizeof(osd_id) + sizeof(*list);
struct bio *bio;
_osd_req_encode_common(or, action, obj, (u64)initial_id, len);
if (list->list_identifier)
_osd_req_encode_olist(or, list);
WARN_ON(or->in.bio);
bio = bio_map_kern(q, list, len, or->alloc_flags);
if (IS_ERR(bio)) {
OSD_ERR("!!! Failed to allocate list_objects BIO\n");
return PTR_ERR(bio);
}
bio->bi_rw &= ~REQ_WRITE;
or->in.bio = bio;
or->in.total_bytes = bio->bi_iter.bi_size;
return 0;
}
int osd_req_list_partition_collections(struct osd_request *or,
osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
unsigned nelem)
{
struct osd_obj_id par = {
.partition = partition,
.id = 0,
};
return osd_req_list_collection_objects(or, &par, initial_id, list,
nelem);
}
EXPORT_SYMBOL(osd_req_list_partition_collections);
int osd_req_list_partition_objects(struct osd_request *or,
osd_id partition, osd_id initial_id, struct osd_obj_id_list *list,
unsigned nelem)
{
struct osd_obj_id par = {
.partition = partition,
.id = 0,
};
return _osd_req_list_objects(or, OSD_ACT_LIST, &par, initial_id, list,
nelem);
}
EXPORT_SYMBOL(osd_req_list_partition_objects);
void osd_req_flush_partition(struct osd_request *or,
osd_id partition, enum osd_options_flush_scope_values op)
{
_osd_req_encode_partition(or, OSD_ACT_FLUSH_PARTITION, partition);
_osd_req_encode_flush(or, op);
}
EXPORT_SYMBOL(osd_req_flush_partition);
/*
* Collection commands
*/
/*TODO: void osd_req_create_collection(struct osd_request *,
const struct osd_obj_id *); */
/*TODO: void osd_req_remove_collection(struct osd_request *,
const struct osd_obj_id *); */
int osd_req_list_collection_objects(struct osd_request *or,
const struct osd_obj_id *obj, osd_id initial_id,
struct osd_obj_id_list *list, unsigned nelem)
{
return _osd_req_list_objects(or, OSD_ACT_LIST_COLLECTION, obj,
initial_id, list, nelem);
}
EXPORT_SYMBOL(osd_req_list_collection_objects);
/*TODO: void query(struct osd_request *, ...); V2 */
void osd_req_flush_collection(struct osd_request *or,
const struct osd_obj_id *obj, enum osd_options_flush_scope_values op)
{
_osd_req_encode_common(or, OSD_ACT_FLUSH_PARTITION, obj, 0, 0);
_osd_req_encode_flush(or, op);
}
EXPORT_SYMBOL(osd_req_flush_collection);
/*TODO: void get_member_attrs(struct osd_request *, ...); V2 */
/*TODO: void set_member_attrs(struct osd_request *, ...); V2 */
/*
* Object commands
*/
void osd_req_create_object(struct osd_request *or, struct osd_obj_id *obj)
{
_osd_req_encode_common(or, OSD_ACT_CREATE, obj, 0, 0);
}
EXPORT_SYMBOL(osd_req_create_object);
void osd_req_remove_object(struct osd_request *or, struct osd_obj_id *obj)
{
_osd_req_encode_common(or, OSD_ACT_REMOVE, obj, 0, 0);
}
EXPORT_SYMBOL(osd_req_remove_object);
/*TODO: void osd_req_create_multi(struct osd_request *or,
struct osd_obj_id *first, struct osd_obj_id_list *list, unsigned nelem);
*/
void osd_req_write(struct osd_request *or,
const struct osd_obj_id *obj, u64 offset,
struct bio *bio, u64 len)
{
_osd_req_encode_common(or, OSD_ACT_WRITE, obj, offset, len);
WARN_ON(or->out.bio || or->out.total_bytes);
WARN_ON(0 == (bio->bi_rw & REQ_WRITE));
or->out.bio = bio;
or->out.total_bytes = len;
}
EXPORT_SYMBOL(osd_req_write);
int osd_req_write_kern(struct osd_request *or,
const struct osd_obj_id *obj, u64 offset, void* buff, u64 len)
{
struct request_queue *req_q = osd_request_queue(or->osd_dev);
struct bio *bio = bio_map_kern(req_q, buff, len, GFP_KERNEL);
if (IS_ERR(bio))
return PTR_ERR(bio);
bio->bi_rw |= REQ_WRITE; /* FIXME: bio_set_dir() */
osd_req_write(or, obj, offset, bio, len);
return 0;
}
EXPORT_SYMBOL(osd_req_write_kern);
/*TODO: void osd_req_append(struct osd_request *,
const struct osd_obj_id *, struct bio *data_out); */
/*TODO: void osd_req_create_write(struct osd_request *,
const struct osd_obj_id *, struct bio *data_out, u64 offset); */
/*TODO: void osd_req_clear(struct osd_request *,
const struct osd_obj_id *, u64 offset, u64 len); */
/*TODO: void osd_req_punch(struct osd_request *,
const struct osd_obj_id *, u64 offset, u64 len); V2 */
void osd_req_flush_object(struct osd_request *or,
const struct osd_obj_id *obj, enum osd_options_flush_scope_values op,
/*V2*/ u64 offset, /*V2*/ u64 len)
{
if (unlikely(osd_req_is_ver1(or) && (offset || len))) {
OSD_DEBUG("OSD Ver1 flush on specific range ignored\n");
offset = 0;
len = 0;
}
_osd_req_encode_common(or, OSD_ACT_FLUSH, obj, offset, len);
_osd_req_encode_flush(or, op);
}
EXPORT_SYMBOL(osd_req_flush_object);
void osd_req_read(struct osd_request *or,
const struct osd_obj_id *obj, u64 offset,
struct bio *bio, u64 len)
{
_osd_req_encode_common(or, OSD_ACT_READ, obj, offset, len);
WARN_ON(or->in.bio || or->in.total_bytes);
WARN_ON(bio->bi_rw & REQ_WRITE);
or->in.bio = bio;
or->in.total_bytes = len;
}
EXPORT_SYMBOL(osd_req_read);
int osd_req_read_kern(struct osd_request *or,
const struct osd_obj_id *obj, u64 offset, void* buff, u64 len)
{
struct request_queue *req_q = osd_request_queue(or->osd_dev);
struct bio *bio = bio_map_kern(req_q, buff, len, GFP_KERNEL);
if (IS_ERR(bio))
return PTR_ERR(bio);
osd_req_read(or, obj, offset, bio, len);
return 0;
}
EXPORT_SYMBOL(osd_req_read_kern);
static int _add_sg_continuation_descriptor(struct osd_request *or,
const struct osd_sg_entry *sglist, unsigned numentries, u64 *len)
{
struct osd_sg_continuation_descriptor *oscd;
u32 oscd_size;
unsigned i;
int ret;
oscd_size = sizeof(*oscd) + numentries * sizeof(oscd->entries[0]);
if (!or->cdb_cont.total_bytes) {
/* First time, jump over the header, we will write to:
* cdb_cont.buff + cdb_cont.total_bytes
*/
or->cdb_cont.total_bytes =
sizeof(struct osd_continuation_segment_header);
}
ret = _alloc_cdb_cont(or, or->cdb_cont.total_bytes + oscd_size);
if (unlikely(ret))
return ret;
oscd = or->cdb_cont.buff + or->cdb_cont.total_bytes;
oscd->hdr.type = cpu_to_be16(SCATTER_GATHER_LIST);
oscd->hdr.pad_length = 0;
oscd->hdr.length = cpu_to_be32(oscd_size - sizeof(*oscd));
*len = 0;
/* copy the sg entries and convert to network byte order */
for (i = 0; i < numentries; i++) {
oscd->entries[i].offset = cpu_to_be64(sglist[i].offset);
oscd->entries[i].len = cpu_to_be64(sglist[i].len);
*len += sglist[i].len;
}
or->cdb_cont.total_bytes += oscd_size;
OSD_DEBUG("total_bytes=%d oscd_size=%d numentries=%d\n",
or->cdb_cont.total_bytes, oscd_size, numentries);
return 0;
}
static int _osd_req_finalize_cdb_cont(struct osd_request *or, const u8 *cap_key)
{
struct request_queue *req_q = osd_request_queue(or->osd_dev);
struct bio *bio;
struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
struct osd_continuation_segment_header *cont_seg_hdr;
if (!or->cdb_cont.total_bytes)
return 0;
cont_seg_hdr = or->cdb_cont.buff;
cont_seg_hdr->format = CDB_CONTINUATION_FORMAT_V2;
cont_seg_hdr->service_action = cdbh->varlen_cdb.service_action;
/* create a bio for continuation segment */
bio = bio_map_kern(req_q, or->cdb_cont.buff, or->cdb_cont.total_bytes,
GFP_KERNEL);
if (IS_ERR(bio))
return PTR_ERR(bio);
bio->bi_rw |= REQ_WRITE;
/* integrity check the continuation before the bio is linked
* with the other data segments since the continuation
* integrity is separate from the other data segments.
*/
osd_sec_sign_data(cont_seg_hdr->integrity_check, bio, cap_key);
cdbh->v2.cdb_continuation_length = cpu_to_be32(or->cdb_cont.total_bytes);
/* we can't use _req_append_segment, because we need to link in the
* continuation bio to the head of the bio list - the
* continuation segment (if it exists) is always the first segment in
* the out data buffer.
*/
bio->bi_next = or->out.bio;
or->out.bio = bio;
or->out.total_bytes += or->cdb_cont.total_bytes;
return 0;
}
/* osd_req_write_sg: Takes a @bio that points to the data out buffer and an
* @sglist that has the scatter gather entries. Scatter-gather enables a write
* of multiple none-contiguous areas of an object, in a single call. The extents
* may overlap and/or be in any order. The only constrain is that:
* total_bytes(sglist) >= total_bytes(bio)
*/
int osd_req_write_sg(struct osd_request *or,
const struct osd_obj_id *obj, struct bio *bio,
const struct osd_sg_entry *sglist, unsigned numentries)
{
u64 len;
int ret = _add_sg_continuation_descriptor(or, sglist, numentries, &len);
if (ret)
return ret;
osd_req_write(or, obj, 0, bio, len);
return 0;
}
EXPORT_SYMBOL(osd_req_write_sg);
/* osd_req_read_sg: Read multiple extents of an object into @bio
* See osd_req_write_sg
*/
int osd_req_read_sg(struct osd_request *or,
const struct osd_obj_id *obj, struct bio *bio,
const struct osd_sg_entry *sglist, unsigned numentries)
{
u64 len;
u64 off;
int ret;
if (numentries > 1) {
off = 0;
ret = _add_sg_continuation_descriptor(or, sglist, numentries,
&len);
if (ret)
return ret;
} else {
/* Optimize the case of single segment, read_sg is a
* bidi operation.
*/
len = sglist->len;
off = sglist->offset;
}
osd_req_read(or, obj, off, bio, len);
return 0;
}
EXPORT_SYMBOL(osd_req_read_sg);
/* SG-list write/read Kern API
*
* osd_req_{write,read}_sg_kern takes an array of @buff pointers and an array
* of sg_entries. @numentries indicates how many pointers and sg_entries there
* are. By requiring an array of buff pointers. This allows a caller to do a
* single write/read and scatter into multiple buffers.
* NOTE: Each buffer + len should not cross a page boundary.
*/
static struct bio *_create_sg_bios(struct osd_request *or,
void **buff, const struct osd_sg_entry *sglist, unsigned numentries)
{
struct request_queue *q = osd_request_queue(or->osd_dev);
struct bio *bio;
unsigned i;
bio = bio_kmalloc(GFP_KERNEL, numentries);
if (unlikely(!bio)) {
OSD_DEBUG("Failed to allocate BIO size=%u\n", numentries);
return ERR_PTR(-ENOMEM);
}
for (i = 0; i < numentries; i++) {
unsigned offset = offset_in_page(buff[i]);
struct page *page = virt_to_page(buff[i]);
unsigned len = sglist[i].len;
unsigned added_len;
BUG_ON(offset + len > PAGE_SIZE);
added_len = bio_add_pc_page(q, bio, page, len, offset);
if (unlikely(len != added_len)) {
OSD_DEBUG("bio_add_pc_page len(%d) != added_len(%d)\n",
len, added_len);
bio_put(bio);
return ERR_PTR(-ENOMEM);
}
}
return bio;
}
int osd_req_write_sg_kern(struct osd_request *or,
const struct osd_obj_id *obj, void **buff,
const struct osd_sg_entry *sglist, unsigned numentries)
{
struct bio *bio = _create_sg_bios(or, buff, sglist, numentries);
if (IS_ERR(bio))
return PTR_ERR(bio);
bio->bi_rw |= REQ_WRITE;
osd_req_write_sg(or, obj, bio, sglist, numentries);
return 0;
}
EXPORT_SYMBOL(osd_req_write_sg_kern);
int osd_req_read_sg_kern(struct osd_request *or,
const struct osd_obj_id *obj, void **buff,
const struct osd_sg_entry *sglist, unsigned numentries)
{
struct bio *bio = _create_sg_bios(or, buff, sglist, numentries);
if (IS_ERR(bio))
return PTR_ERR(bio);
osd_req_read_sg(or, obj, bio, sglist, numentries);
return 0;
}
EXPORT_SYMBOL(osd_req_read_sg_kern);
void osd_req_get_attributes(struct osd_request *or,
const struct osd_obj_id *obj)
{
_osd_req_encode_common(or, OSD_ACT_GET_ATTRIBUTES, obj, 0, 0);
}
EXPORT_SYMBOL(osd_req_get_attributes);
void osd_req_set_attributes(struct osd_request *or,
const struct osd_obj_id *obj)
{
_osd_req_encode_common(or, OSD_ACT_SET_ATTRIBUTES, obj, 0, 0);
}
EXPORT_SYMBOL(osd_req_set_attributes);
/*
* Attributes List-mode
*/
int osd_req_add_set_attr_list(struct osd_request *or,
const struct osd_attr *oa, unsigned nelem)
{
unsigned total_bytes = or->set_attr.total_bytes;
void *attr_last;
int ret;
if (or->attributes_mode &&
or->attributes_mode != OSD_CDB_GET_SET_ATTR_LISTS) {
WARN_ON(1);
return -EINVAL;
}
or->attributes_mode = OSD_CDB_GET_SET_ATTR_LISTS;
if (!total_bytes) { /* first-time: allocate and put list header */
total_bytes = _osd_req_sizeof_alist_header(or);
ret = _alloc_set_attr_list(or, oa, nelem, total_bytes);
if (ret)
return ret;
_osd_req_set_alist_type(or, or->set_attr.buff,
OSD_ATTR_LIST_SET_RETRIEVE);
}
attr_last = or->set_attr.buff + total_bytes;
for (; nelem; --nelem) {
unsigned elem_size = _osd_req_alist_elem_size(or, oa->len);
total_bytes += elem_size;
if (unlikely(or->set_attr.alloc_size < total_bytes)) {
or->set_attr.total_bytes = total_bytes - elem_size;
ret = _alloc_set_attr_list(or, oa, nelem, total_bytes);
if (ret)
return ret;
attr_last =
or->set_attr.buff + or->set_attr.total_bytes;
}
_osd_req_alist_elem_encode(or, attr_last, oa);
attr_last += elem_size;
++oa;
}
or->set_attr.total_bytes = total_bytes;
return 0;
}
EXPORT_SYMBOL(osd_req_add_set_attr_list);
static int _req_append_segment(struct osd_request *or,
unsigned padding, struct _osd_req_data_segment *seg,
struct _osd_req_data_segment *last_seg, struct _osd_io_info *io)
{
void *pad_buff;
int ret;
if (padding) {
/* check if we can just add it to last buffer */
if (last_seg &&
(padding <= last_seg->alloc_size - last_seg->total_bytes))
pad_buff = last_seg->buff + last_seg->total_bytes;
else
pad_buff = io->pad_buff;
ret = blk_rq_map_kern(io->req->q, io->req, pad_buff, padding,
or->alloc_flags);
if (ret)
return ret;
io->total_bytes += padding;
}
ret = blk_rq_map_kern(io->req->q, io->req, seg->buff, seg->total_bytes,
or->alloc_flags);
if (ret)
return ret;
io->total_bytes += seg->total_bytes;
OSD_DEBUG("padding=%d buff=%p total_bytes=%d\n", padding, seg->buff,
seg->total_bytes);
return 0;
}
static int _osd_req_finalize_set_attr_list(struct osd_request *or)
{
struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
unsigned padding;
int ret;
if (!or->set_attr.total_bytes) {
cdbh->attrs_list.set_attr_offset = OSD_OFFSET_UNUSED;
return 0;
}
cdbh->attrs_list.set_attr_bytes = cpu_to_be32(or->set_attr.total_bytes);
cdbh->attrs_list.set_attr_offset =
osd_req_encode_offset(or, or->out.total_bytes, &padding);
ret = _req_append_segment(or, padding, &or->set_attr,
or->out.last_seg, &or->out);
if (ret)
return ret;
or->out.last_seg = &or->set_attr;
return 0;
}
int osd_req_add_get_attr_list(struct osd_request *or,
const struct osd_attr *oa, unsigned nelem)
{
unsigned total_bytes = or->enc_get_attr.total_bytes;
void *attr_last;
int ret;
if (or->attributes_mode &&
or->attributes_mode != OSD_CDB_GET_SET_ATTR_LISTS) {
WARN_ON(1);
return -EINVAL;
}
or->attributes_mode = OSD_CDB_GET_SET_ATTR_LISTS;
/* first time calc data-in list header size */
if (!or->get_attr.total_bytes)
or->get_attr.total_bytes = _osd_req_sizeof_alist_header(or);
/* calc data-out info */
if (!total_bytes) { /* first-time: allocate and put list header */
unsigned max_bytes;
total_bytes = _osd_req_sizeof_alist_header(or);
max_bytes = total_bytes +
nelem * sizeof(struct osd_attributes_list_attrid);
ret = _alloc_get_attr_desc(or, max_bytes);
if (ret)
return ret;
_osd_req_set_alist_type(or, or->enc_get_attr.buff,
OSD_ATTR_LIST_GET);
}
attr_last = or->enc_get_attr.buff + total_bytes;
for (; nelem; --nelem) {
struct osd_attributes_list_attrid *attrid;
const unsigned cur_size = sizeof(*attrid);
total_bytes += cur_size;
if (unlikely(or->enc_get_attr.alloc_size < total_bytes)) {
or->enc_get_attr.total_bytes = total_bytes - cur_size;
ret = _alloc_get_attr_desc(or,
total_bytes + nelem * sizeof(*attrid));
if (ret)
return ret;
attr_last = or->enc_get_attr.buff +
or->enc_get_attr.total_bytes;
}
attrid = attr_last;
attrid->attr_page = cpu_to_be32(oa->attr_page);
attrid->attr_id = cpu_to_be32(oa->attr_id);
attr_last += cur_size;
/* calc data-in size */
or->get_attr.total_bytes +=
_osd_req_alist_elem_size(or, oa->len);
++oa;
}
or->enc_get_attr.total_bytes = total_bytes;
OSD_DEBUG(
"get_attr.total_bytes=%u(%u) enc_get_attr.total_bytes=%u(%Zu)\n",
or->get_attr.total_bytes,
or->get_attr.total_bytes - _osd_req_sizeof_alist_header(or),
or->enc_get_attr.total_bytes,
(or->enc_get_attr.total_bytes - _osd_req_sizeof_alist_header(or))
/ sizeof(struct osd_attributes_list_attrid));
return 0;
}
EXPORT_SYMBOL(osd_req_add_get_attr_list);
static int _osd_req_finalize_get_attr_list(struct osd_request *or)
{
struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
unsigned out_padding;
unsigned in_padding;
int ret;
if (!or->enc_get_attr.total_bytes) {
cdbh->attrs_list.get_attr_desc_offset = OSD_OFFSET_UNUSED;
cdbh->attrs_list.get_attr_offset = OSD_OFFSET_UNUSED;
return 0;
}
ret = _alloc_get_attr_list(or);
if (ret)
return ret;
/* The out-going buffer info update */
OSD_DEBUG("out-going\n");
cdbh->attrs_list.get_attr_desc_bytes =
cpu_to_be32(or->enc_get_attr.total_bytes);
cdbh->attrs_list.get_attr_desc_offset =
osd_req_encode_offset(or, or->out.total_bytes, &out_padding);
ret = _req_append_segment(or, out_padding, &or->enc_get_attr,
or->out.last_seg, &or->out);
if (ret)
return ret;
or->out.last_seg = &or->enc_get_attr;
/* The incoming buffer info update */
OSD_DEBUG("in-coming\n");
cdbh->attrs_list.get_attr_alloc_length =
cpu_to_be32(or->get_attr.total_bytes);
cdbh->attrs_list.get_attr_offset =
osd_req_encode_offset(or, or->in.total_bytes, &in_padding);
ret = _req_append_segment(or, in_padding, &or->get_attr, NULL,
&or->in);
if (ret)
return ret;
or->in.last_seg = &or->get_attr;
return 0;
}
int osd_req_decode_get_attr_list(struct osd_request *or,
struct osd_attr *oa, int *nelem, void **iterator)
{
unsigned cur_bytes, returned_bytes;
int n;
const unsigned sizeof_attr_list = _osd_req_sizeof_alist_header(or);
void *cur_p;
if (!_osd_req_is_alist_type(or, or->get_attr.buff,
OSD_ATTR_LIST_SET_RETRIEVE)) {
oa->attr_page = 0;
oa->attr_id = 0;
oa->val_ptr = NULL;
oa->len = 0;
*iterator = NULL;
return 0;
}
if (*iterator) {
BUG_ON((*iterator < or->get_attr.buff) ||
(or->get_attr.buff + or->get_attr.alloc_size < *iterator));
cur_p = *iterator;
cur_bytes = (*iterator - or->get_attr.buff) - sizeof_attr_list;
returned_bytes = or->get_attr.total_bytes;
} else { /* first time decode the list header */
cur_bytes = sizeof_attr_list;
returned_bytes = _osd_req_alist_size(or, or->get_attr.buff) +
sizeof_attr_list;
cur_p = or->get_attr.buff + sizeof_attr_list;
if (returned_bytes > or->get_attr.alloc_size) {
OSD_DEBUG("target report: space was not big enough! "
"Allocate=%u Needed=%u\n",
or->get_attr.alloc_size,
returned_bytes + sizeof_attr_list);
returned_bytes =
or->get_attr.alloc_size - sizeof_attr_list;
}
or->get_attr.total_bytes = returned_bytes;
}
for (n = 0; (n < *nelem) && (cur_bytes < returned_bytes); ++n) {
int inc = _osd_req_alist_elem_decode(or, cur_p, oa,
returned_bytes - cur_bytes);
if (inc < 0) {
OSD_ERR("BAD FOOD from target. list not valid!"
"c=%d r=%d n=%d\n",
cur_bytes, returned_bytes, n);
oa->val_ptr = NULL;
cur_bytes = returned_bytes; /* break the caller loop */
break;
}
cur_bytes += inc;
cur_p += inc;
++oa;
}
*iterator = (returned_bytes - cur_bytes) ? cur_p : NULL;
*nelem = n;
return returned_bytes - cur_bytes;
}
EXPORT_SYMBOL(osd_req_decode_get_attr_list);
/*
* Attributes Page-mode
*/
int osd_req_add_get_attr_page(struct osd_request *or,
u32 page_id, void *attar_page, unsigned max_page_len,
const struct osd_attr *set_one_attr)
{
struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
if (or->attributes_mode &&
or->attributes_mode != OSD_CDB_GET_ATTR_PAGE_SET_ONE) {
WARN_ON(1);
return -EINVAL;
}
or->attributes_mode = OSD_CDB_GET_ATTR_PAGE_SET_ONE;
or->get_attr.buff = attar_page;
or->get_attr.total_bytes = max_page_len;
cdbh->attrs_page.get_attr_page = cpu_to_be32(page_id);
cdbh->attrs_page.get_attr_alloc_length = cpu_to_be32(max_page_len);
if (!set_one_attr || !set_one_attr->attr_page)
return 0; /* The set is optional */
or->set_attr.buff = set_one_attr->val_ptr;
or->set_attr.total_bytes = set_one_attr->len;
cdbh->attrs_page.set_attr_page = cpu_to_be32(set_one_attr->attr_page);
cdbh->attrs_page.set_attr_id = cpu_to_be32(set_one_attr->attr_id);
cdbh->attrs_page.set_attr_length = cpu_to_be32(set_one_attr->len);
return 0;
}
EXPORT_SYMBOL(osd_req_add_get_attr_page);
static int _osd_req_finalize_attr_page(struct osd_request *or)
{
struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
unsigned in_padding, out_padding;
int ret;
/* returned page */
cdbh->attrs_page.get_attr_offset =
osd_req_encode_offset(or, or->in.total_bytes, &in_padding);
ret = _req_append_segment(or, in_padding, &or->get_attr, NULL,
&or->in);
if (ret)
return ret;
if (or->set_attr.total_bytes == 0)
return 0;
/* set one value */
cdbh->attrs_page.set_attr_offset =
osd_req_encode_offset(or, or->out.total_bytes, &out_padding);
ret = _req_append_segment(or, out_padding, &or->set_attr, NULL,
&or->out);
return ret;
}
static inline void osd_sec_parms_set_out_offset(bool is_v1,
struct osd_security_parameters *sec_parms, osd_cdb_offset offset)
{
if (is_v1)
sec_parms->v1.data_out_integrity_check_offset = offset;
else
sec_parms->v2.data_out_integrity_check_offset = offset;
}
static inline void osd_sec_parms_set_in_offset(bool is_v1,
struct osd_security_parameters *sec_parms, osd_cdb_offset offset)
{
if (is_v1)
sec_parms->v1.data_in_integrity_check_offset = offset;
else
sec_parms->v2.data_in_integrity_check_offset = offset;
}
static int _osd_req_finalize_data_integrity(struct osd_request *or,
bool has_in, bool has_out, struct bio *out_data_bio, u64 out_data_bytes,
const u8 *cap_key)
{
struct osd_security_parameters *sec_parms = _osd_req_sec_params(or);
int ret;
if (!osd_is_sec_alldata(sec_parms))
return 0;
if (has_out) {
struct _osd_req_data_segment seg = {
.buff = &or->out_data_integ,
.total_bytes = sizeof(or->out_data_integ),
};
unsigned pad;
or->out_data_integ.data_bytes = cpu_to_be64(out_data_bytes);
or->out_data_integ.set_attributes_bytes = cpu_to_be64(
or->set_attr.total_bytes);
or->out_data_integ.get_attributes_bytes = cpu_to_be64(
or->enc_get_attr.total_bytes);
osd_sec_parms_set_out_offset(osd_req_is_ver1(or), sec_parms,
osd_req_encode_offset(or, or->out.total_bytes, &pad));
ret = _req_append_segment(or, pad, &seg, or->out.last_seg,
&or->out);
if (ret)
return ret;
or->out.last_seg = NULL;
/* they are now all chained to request sign them all together */
osd_sec_sign_data(&or->out_data_integ, out_data_bio,
cap_key);
}
if (has_in) {
struct _osd_req_data_segment seg = {
.buff = &or->in_data_integ,
.total_bytes = sizeof(or->in_data_integ),
};
unsigned pad;
osd_sec_parms_set_in_offset(osd_req_is_ver1(or), sec_parms,
osd_req_encode_offset(or, or->in.total_bytes, &pad));
ret = _req_append_segment(or, pad, &seg, or->in.last_seg,
&or->in);
if (ret)
return ret;
or->in.last_seg = NULL;
}
return 0;
}
/*
* osd_finalize_request and helpers
*/
static struct request *_make_request(struct request_queue *q, bool has_write,
struct _osd_io_info *oii, gfp_t flags)
{
if (oii->bio)
return blk_make_request(q, oii->bio, flags);
else {
struct request *req;
req = blk_get_request(q, has_write ? WRITE : READ, flags);
if (IS_ERR(req))
return req;
blk_rq_set_block_pc(req);
return req;
}
}
static int _init_blk_request(struct osd_request *or,
bool has_in, bool has_out)
{
gfp_t flags = or->alloc_flags;
struct scsi_device *scsi_device = or->osd_dev->scsi_device;
struct request_queue *q = scsi_device->request_queue;
struct request *req;
int ret;
req = _make_request(q, has_out, has_out ? &or->out : &or->in, flags);
if (IS_ERR(req)) {
ret = PTR_ERR(req);
goto out;
}
or->request = req;
req->cmd_flags |= REQ_QUIET;
req->timeout = or->timeout;
req->retries = or->retries;
req->sense = or->sense;
req->sense_len = 0;
if (has_out) {
or->out.req = req;
if (has_in) {
/* allocate bidi request */
req = _make_request(q, false, &or->in, flags);
if (IS_ERR(req)) {
OSD_DEBUG("blk_get_request for bidi failed\n");
ret = PTR_ERR(req);
goto out;
}
blk_rq_set_block_pc(req);
or->in.req = or->request->next_rq = req;
}
} else if (has_in)
or->in.req = req;
ret = 0;
out:
OSD_DEBUG("or=%p has_in=%d has_out=%d => %d, %p\n",
or, has_in, has_out, ret, or->request);
return ret;
}
int osd_finalize_request(struct osd_request *or,
u8 options, const void *cap, const u8 *cap_key)
{
struct osd_cdb_head *cdbh = osd_cdb_head(&or->cdb);
bool has_in, has_out;
/* Save for data_integrity without the cdb_continuation */
struct bio *out_data_bio = or->out.bio;
u64 out_data_bytes = or->out.total_bytes;
int ret;
if (options & OSD_REQ_FUA)
cdbh->options |= OSD_CDB_FUA;
if (options & OSD_REQ_DPO)
cdbh->options |= OSD_CDB_DPO;
if (options & OSD_REQ_BYPASS_TIMESTAMPS)
cdbh->timestamp_control = OSD_CDB_BYPASS_TIMESTAMPS;
osd_set_caps(&or->cdb, cap);
has_in = or->in.bio || or->get_attr.total_bytes;
has_out = or->out.bio || or->cdb_cont.total_bytes ||
or->set_attr.total_bytes || or->enc_get_attr.total_bytes;
ret = _osd_req_finalize_cdb_cont(or, cap_key);
if (ret) {
OSD_DEBUG("_osd_req_finalize_cdb_cont failed\n");
return ret;
}
ret = _init_blk_request(or, has_in, has_out);
if (ret) {
OSD_DEBUG("_init_blk_request failed\n");
return ret;
}
or->out.pad_buff = sg_out_pad_buffer;
or->in.pad_buff = sg_in_pad_buffer;
if (!or->attributes_mode)
or->attributes_mode = OSD_CDB_GET_SET_ATTR_LISTS;
cdbh->command_specific_options |= or->attributes_mode;
if (or->attributes_mode == OSD_CDB_GET_ATTR_PAGE_SET_ONE) {
ret = _osd_req_finalize_attr_page(or);
if (ret) {
OSD_DEBUG("_osd_req_finalize_attr_page failed\n");
return ret;
}
} else {
/* TODO: I think that for the GET_ATTR command these 2 should
* be reversed to keep them in execution order (for embeded
* targets with low memory footprint)
*/
ret = _osd_req_finalize_set_attr_list(or);
if (ret) {
OSD_DEBUG("_osd_req_finalize_set_attr_list failed\n");
return ret;
}
ret = _osd_req_finalize_get_attr_list(or);
if (ret) {
OSD_DEBUG("_osd_req_finalize_get_attr_list failed\n");
return ret;
}
}
ret = _osd_req_finalize_data_integrity(or, has_in, has_out,
out_data_bio, out_data_bytes,
cap_key);
if (ret)
return ret;
osd_sec_sign_cdb(&or->cdb, cap_key);
or->request->cmd = or->cdb.buff;
or->request->cmd_len = _osd_req_cdb_len(or);
return 0;
}
EXPORT_SYMBOL(osd_finalize_request);
static bool _is_osd_security_code(int code)
{
return (code == osd_security_audit_value_frozen) ||
(code == osd_security_working_key_frozen) ||
(code == osd_nonce_not_unique) ||
(code == osd_nonce_timestamp_out_of_range) ||
(code == osd_invalid_dataout_buffer_integrity_check_value);
}
#define OSD_SENSE_PRINT1(fmt, a...) \
do { \
if (__cur_sense_need_output) \
OSD_ERR(fmt, ##a); \
} while (0)
#define OSD_SENSE_PRINT2(fmt, a...) OSD_SENSE_PRINT1(" " fmt, ##a)
int osd_req_decode_sense_full(struct osd_request *or,
struct osd_sense_info *osi, bool silent,
struct osd_obj_id *bad_obj_list __unused, int max_obj __unused,
struct osd_attr *bad_attr_list, int max_attr)
{
int sense_len, original_sense_len;
struct osd_sense_info local_osi;
struct scsi_sense_descriptor_based *ssdb;
void *cur_descriptor;
#if (CONFIG_SCSI_OSD_DPRINT_SENSE == 0)
const bool __cur_sense_need_output = false;
#else
bool __cur_sense_need_output = !silent;
#endif
int ret;
if (likely(!or->req_errors))
return 0;
osi = osi ? : &local_osi;
memset(osi, 0, sizeof(*osi));
ssdb = (typeof(ssdb))or->sense;
sense_len = or->sense_len;
if ((sense_len < (int)sizeof(*ssdb) || !ssdb->sense_key)) {
OSD_ERR("Block-layer returned error(0x%x) but "
"sense_len(%u) || key(%d) is empty\n",
or->req_errors, sense_len, ssdb->sense_key);
goto analyze;
}
if ((ssdb->response_code != 0x72) && (ssdb->response_code != 0x73)) {
OSD_ERR("Unrecognized scsi sense: rcode=%x length=%d\n",
ssdb->response_code, sense_len);
goto analyze;
}
osi->key = ssdb->sense_key;
osi->additional_code = be16_to_cpu(ssdb->additional_sense_code);
original_sense_len = ssdb->additional_sense_length + 8;
#if (CONFIG_SCSI_OSD_DPRINT_SENSE == 1)
if (__cur_sense_need_output)
__cur_sense_need_output = (osi->key > scsi_sk_recovered_error);
#endif
OSD_SENSE_PRINT1("Main Sense information key=0x%x length(%d, %d) "
"additional_code=0x%x async_error=%d errors=0x%x\n",
osi->key, original_sense_len, sense_len,
osi->additional_code, or->async_error,
or->req_errors);
if (original_sense_len < sense_len)
sense_len = original_sense_len;
cur_descriptor = ssdb->ssd;
sense_len -= sizeof(*ssdb);
while (sense_len > 0) {
struct scsi_sense_descriptor *ssd = cur_descriptor;
int cur_len = ssd->additional_length + 2;
sense_len -= cur_len;
if (sense_len < 0)
break; /* sense was truncated */
switch (ssd->descriptor_type) {
case scsi_sense_information:
case scsi_sense_command_specific_information:
{
struct scsi_sense_command_specific_data_descriptor
*sscd = cur_descriptor;
osi->command_info =
get_unaligned_be64(&sscd->information) ;
OSD_SENSE_PRINT2(
"command_specific_information 0x%llx \n",
_LLU(osi->command_info));
break;
}
case scsi_sense_key_specific:
{
struct scsi_sense_key_specific_data_descriptor
*ssks = cur_descriptor;
osi->sense_info = get_unaligned_be16(&ssks->value);
OSD_SENSE_PRINT2(
"sense_key_specific_information %u"
"sksv_cd_bpv_bp (0x%x)\n",
osi->sense_info, ssks->sksv_cd_bpv_bp);
break;
}
case osd_sense_object_identification:
{ /*FIXME: Keep first not last, Store in array*/
struct osd_sense_identification_data_descriptor
*osidd = cur_descriptor;
osi->not_initiated_command_functions =
le32_to_cpu(osidd->not_initiated_functions);
osi->completed_command_functions =
le32_to_cpu(osidd->completed_functions);
osi->obj.partition = be64_to_cpu(osidd->partition_id);
osi->obj.id = be64_to_cpu(osidd->object_id);
OSD_SENSE_PRINT2(
"object_identification pid=0x%llx oid=0x%llx\n",
_LLU(osi->obj.partition), _LLU(osi->obj.id));
OSD_SENSE_PRINT2(
"not_initiated_bits(%x) "
"completed_command_bits(%x)\n",
osi->not_initiated_command_functions,
osi->completed_command_functions);
break;
}
case osd_sense_response_integrity_check:
{
struct osd_sense_response_integrity_check_descriptor
*osricd = cur_descriptor;
const unsigned len =
sizeof(osricd->integrity_check_value);
char key_dump[len*4 + 2]; /* 2nibbles+space+ASCII */
hex_dump_to_buffer(osricd->integrity_check_value, len,
32, 1, key_dump, sizeof(key_dump), true);
OSD_SENSE_PRINT2("response_integrity [%s]\n", key_dump);
}
case osd_sense_attribute_identification:
{
struct osd_sense_attributes_data_descriptor
*osadd = cur_descriptor;
unsigned len = min(cur_len, sense_len);
struct osd_sense_attr *pattr = osadd->sense_attrs;
while (len >= sizeof(*pattr)) {
u32 attr_page = be32_to_cpu(pattr->attr_page);
u32 attr_id = be32_to_cpu(pattr->attr_id);
if (!osi->attr.attr_page) {
osi->attr.attr_page = attr_page;
osi->attr.attr_id = attr_id;
}
if (bad_attr_list && max_attr) {
bad_attr_list->attr_page = attr_page;
bad_attr_list->attr_id = attr_id;
bad_attr_list++;
max_attr--;
}
len -= sizeof(*pattr);
OSD_SENSE_PRINT2(
"osd_sense_attribute_identification"
"attr_page=0x%x attr_id=0x%x\n",
attr_page, attr_id);
}
}
/*These are not legal for OSD*/
case scsi_sense_field_replaceable_unit:
OSD_SENSE_PRINT2("scsi_sense_field_replaceable_unit\n");
break;
case scsi_sense_stream_commands:
OSD_SENSE_PRINT2("scsi_sense_stream_commands\n");
break;
case scsi_sense_block_commands:
OSD_SENSE_PRINT2("scsi_sense_block_commands\n");
break;
case scsi_sense_ata_return:
OSD_SENSE_PRINT2("scsi_sense_ata_return\n");
break;
default:
if (ssd->descriptor_type <= scsi_sense_Reserved_last)
OSD_SENSE_PRINT2(
"scsi_sense Reserved descriptor (0x%x)",
ssd->descriptor_type);
else
OSD_SENSE_PRINT2(
"scsi_sense Vendor descriptor (0x%x)",
ssd->descriptor_type);
}
cur_descriptor += cur_len;
}
analyze:
if (!osi->key) {
/* scsi sense is Empty, the request was never issued to target
* linux return code might tell us what happened.
*/
if (or->async_error == -ENOMEM)
osi->osd_err_pri = OSD_ERR_PRI_RESOURCE;
else
osi->osd_err_pri = OSD_ERR_PRI_UNREACHABLE;
ret = or->async_error;
} else if (osi->key <= scsi_sk_recovered_error) {
osi->osd_err_pri = 0;
ret = 0;
} else if (osi->additional_code == scsi_invalid_field_in_cdb) {
if (osi->cdb_field_offset == OSD_CFO_STARTING_BYTE) {
osi->osd_err_pri = OSD_ERR_PRI_CLEAR_PAGES;
ret = -EFAULT; /* caller should recover from this */
} else if (osi->cdb_field_offset == OSD_CFO_OBJECT_ID) {
osi->osd_err_pri = OSD_ERR_PRI_NOT_FOUND;
ret = -ENOENT;
} else if (osi->cdb_field_offset == OSD_CFO_PERMISSIONS) {
osi->osd_err_pri = OSD_ERR_PRI_NO_ACCESS;
ret = -EACCES;
} else {
osi->osd_err_pri = OSD_ERR_PRI_BAD_CRED;
ret = -EINVAL;
}
} else if (osi->additional_code == osd_quota_error) {
osi->osd_err_pri = OSD_ERR_PRI_NO_SPACE;
ret = -ENOSPC;
} else if (_is_osd_security_code(osi->additional_code)) {
osi->osd_err_pri = OSD_ERR_PRI_BAD_CRED;
ret = -EINVAL;
} else {
osi->osd_err_pri = OSD_ERR_PRI_EIO;
ret = -EIO;
}
if (!or->out.residual)
or->out.residual = or->out.total_bytes;
if (!or->in.residual)
or->in.residual = or->in.total_bytes;
return ret;
}
EXPORT_SYMBOL(osd_req_decode_sense_full);
/*
* Implementation of osd_sec.h API
* TODO: Move to a separate osd_sec.c file at a later stage.
*/
enum { OSD_SEC_CAP_V1_ALL_CAPS =
OSD_SEC_CAP_APPEND | OSD_SEC_CAP_OBJ_MGMT | OSD_SEC_CAP_REMOVE |
OSD_SEC_CAP_CREATE | OSD_SEC_CAP_SET_ATTR | OSD_SEC_CAP_GET_ATTR |
OSD_SEC_CAP_WRITE | OSD_SEC_CAP_READ | OSD_SEC_CAP_POL_SEC |
OSD_SEC_CAP_GLOBAL | OSD_SEC_CAP_DEV_MGMT
};
enum { OSD_SEC_CAP_V2_ALL_CAPS =
OSD_SEC_CAP_V1_ALL_CAPS | OSD_SEC_CAP_QUERY | OSD_SEC_CAP_M_OBJECT
};
void osd_sec_init_nosec_doall_caps(void *caps,
const struct osd_obj_id *obj, bool is_collection, const bool is_v1)
{
struct osd_capability *cap = caps;
u8 type;
u8 descriptor_type;
if (likely(obj->id)) {
if (unlikely(is_collection)) {
type = OSD_SEC_OBJ_COLLECTION;
descriptor_type = is_v1 ? OSD_SEC_OBJ_DESC_OBJ :
OSD_SEC_OBJ_DESC_COL;
} else {
type = OSD_SEC_OBJ_USER;
descriptor_type = OSD_SEC_OBJ_DESC_OBJ;
}
WARN_ON(!obj->partition);
} else {
type = obj->partition ? OSD_SEC_OBJ_PARTITION :
OSD_SEC_OBJ_ROOT;
descriptor_type = OSD_SEC_OBJ_DESC_PAR;
}
memset(cap, 0, sizeof(*cap));
cap->h.format = OSD_SEC_CAP_FORMAT_VER1;
cap->h.integrity_algorithm__key_version = 0; /* MAKE_BYTE(0, 0); */
cap->h.security_method = OSD_SEC_NOSEC;
/* cap->expiration_time;
cap->AUDIT[30-10];
cap->discriminator[42-30];
cap->object_created_time; */
cap->h.object_type = type;
osd_sec_set_caps(&cap->h, OSD_SEC_CAP_V1_ALL_CAPS);
cap->h.object_descriptor_type = descriptor_type;
cap->od.obj_desc.policy_access_tag = 0;
cap->od.obj_desc.allowed_partition_id = cpu_to_be64(obj->partition);
cap->od.obj_desc.allowed_object_id = cpu_to_be64(obj->id);
}
EXPORT_SYMBOL(osd_sec_init_nosec_doall_caps);
/* FIXME: Extract version from caps pointer.
* Also Pete's target only supports caps from OSDv1 for now
*/
void osd_set_caps(struct osd_cdb *cdb, const void *caps)
{
/* NOTE: They start at same address */
memcpy(&cdb->v1.caps, caps, OSDv1_CAP_LEN);
}
bool osd_is_sec_alldata(struct osd_security_parameters *sec_parms __unused)
{
return false;
}
void osd_sec_sign_cdb(struct osd_cdb *ocdb __unused, const u8 *cap_key __unused)
{
}
void osd_sec_sign_data(void *data_integ __unused,
struct bio *bio __unused, const u8 *cap_key __unused)
{
}
/*
* Declared in osd_protocol.h
* 4.12.5 Data-In and Data-Out buffer offsets
* byte offset = mantissa * (2^(exponent+8))
* Returns the smallest allowed encoded offset that contains given @offset
* The actual encoded offset returned is @offset + *@padding.
*/
osd_cdb_offset __osd_encode_offset(
u64 offset, unsigned *padding, int min_shift, int max_shift)
{
u64 try_offset = -1, mod, align;
osd_cdb_offset be32_offset;
int shift;
*padding = 0;
if (!offset)
return 0;
for (shift = min_shift; shift < max_shift; ++shift) {
try_offset = offset >> shift;
if (try_offset < (1 << OSD_OFFSET_MAX_BITS))
break;
}
BUG_ON(shift == max_shift);
align = 1 << shift;
mod = offset & (align - 1);
if (mod) {
*padding = align - mod;
try_offset += 1;
}
try_offset |= ((shift - 8) & 0xf) << 28;
be32_offset = cpu_to_be32((u32)try_offset);
OSD_DEBUG("offset=%llu mantissa=%llu exp=%d encoded=%x pad=%d\n",
_LLU(offset), _LLU(try_offset & 0x0FFFFFFF), shift,
be32_offset, *padding);
return be32_offset;
}
| geminy/aidear | oss/linux/linux-4.7/drivers/scsi/osd/osd_initiator.c | C | gpl-3.0 | 57,347 |
/*! formstone v0.8.26 [grid.ie.css] 2015-11-01 | MIT License | formstone.it */
.fs_grid_row {
width: 300px;
margin-left: auto;
margin-right: auto;
}
@media screen and (min-width: 500px) {
.fs_grid_row {
width: 480px;
}
}
@media screen and (min-width: 740px) {
.fs_grid_row {
width: 720px;
}
}
@media screen and (min-width: 980px) {
.fs_grid_row {
width: 960px;
}
}
@media screen and (min-width: 1220px) {
.fs_grid_row {
width: 1200px;
}
}
.fs_grid_row:after {
height: 0;
clear: both;
content: ".";
display: block;
line-height: 0;
visibility: hidden;
}
.fs_grid_row_fluid {
width: 96%;
width: -webkit-calc(100% - 40px);
width: calc(100% - 40px);
}
@media screen and (max-width: 739px) {
.fs_grid_row_fluid_sm {
width: 96%;
width: -webkit-calc(100% - 40px);
width: calc(100% - 40px);
}
}
.fs_grid_row_row {
width: 102.08333333%;
margin-left: -1.04166667%;
margin-right: -1.04166667%;
}
.fs_grid_row_row_contained {
width: 100%;
margin-left: 0;
margin-right: 0;
}
.fs_grid_cell {
width: 97.91666667%;
float: left;
margin-left: 1.04166667%;
margin-right: 1.04166667%;
}
.fs_grid_cell_centered {
float: none;
margin-left: auto;
margin-right: auto;
}
.fs_grid_cell_padded {
box-sizing: content-box;
margin-left: 0;
margin-right: 0;
padding-left: 1.04166667%;
padding-right: 1.04166667%;
}
.fs_grid_cell_contained {
margin-left: 0;
margin-right: 0;
}
.fs_grid_cell_right {
float: right;
}
*,
*:before,
*:after {
behavior: url(boxsizing.htc);
}
.fs-grid .fs-row {
width: 960px;
}
.fs-grid .fs-row .fs-lg-1 {
width: 6.25%;
}
.fs-grid .fs-row .fs-lg-2 {
width: 14.58333333%;
}
.fs-grid .fs-row .fs-lg-3 {
width: 22.91666667%;
}
.fs-grid .fs-row .fs-lg-4 {
width: 31.25%;
}
.fs-grid .fs-row .fs-lg-5 {
width: 39.58333333%;
}
.fs-grid .fs-row .fs-lg-6 {
width: 47.91666667%;
}
.fs-grid .fs-row .fs-lg-7 {
width: 56.25%;
}
.fs-grid .fs-row .fs-lg-8 {
width: 64.58333333%;
}
.fs-grid .fs-row .fs-lg-9 {
width: 72.91666667%;
}
.fs-grid .fs-row .fs-lg-10 {
width: 81.25%;
}
.fs-grid .fs-row .fs-lg-11 {
width: 89.58333333%;
}
.fs-grid .fs-row .fs-lg-12 {
width: 97.91666667%;
}
.fs-grid .fs-row .fs-lg-push-1 {
margin-left: 9.375%;
}
.fs-grid .fs-row .fs-lg-push-2 {
margin-left: 17.70833333%;
}
.fs-grid .fs-row .fs-lg-push-3 {
margin-left: 26.04166667%;
}
.fs-grid .fs-row .fs-lg-push-4 {
margin-left: 34.375%;
}
.fs-grid .fs-row .fs-lg-push-5 {
margin-left: 42.70833333%;
}
.fs-grid .fs-row .fs-lg-push-6 {
margin-left: 51.04166667%;
}
.fs-grid .fs-row .fs-lg-push-7 {
margin-left: 59.375%;
}
.fs-grid .fs-row .fs-lg-push-8 {
margin-left: 67.70833333%;
}
.fs-grid .fs-row .fs-lg-push-9 {
margin-left: 76.04166667%;
}
.fs-grid .fs-row .fs-lg-push-10 {
margin-left: 84.375%;
}
.fs-grid .fs-row .fs-lg-push-11 {
margin-left: 92.70833333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-1 {
width: 8.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-2 {
width: 16.66666667%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-3 {
width: 25%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-4 {
width: 33.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-5 {
width: 41.66666667%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-6 {
width: 50%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-7 {
width: 58.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-8 {
width: 66.66666667%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-9 {
width: 75%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-10 {
width: 83.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-11 {
width: 91.66666667%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-12 {
width: 100%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-1 {
margin-left: 8.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-2 {
margin-left: 16.66666667%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-3 {
margin-left: 25%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-4 {
margin-left: 33.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-5 {
margin-left: 41.66666667%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-6 {
margin-left: 50%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-7 {
margin-left: 58.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-8 {
margin-left: 66.66666667%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-9 {
margin-left: 75%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-10 {
margin-left: 83.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-11 {
margin-left: 91.66666667%;
}
.fs-grid .fs-row .fs-lg-fifth {
width: 17.91666667%;
}
.fs-grid .fs-row .fs-lg-fourth {
width: 22.91666667%;
}
.fs-grid .fs-row .fs-lg-third {
width: 31.25%;
}
.fs-grid .fs-row .fs-lg-half {
width: 47.91666667%;
}
.fs-grid .fs-row .fs-lg-full {
width: 97.91666667%;
}
.fs-grid .fs-row .fs-lg-push-fifth {
margin-left: 21.04166667%;
}
.fs-grid .fs-row .fs-lg-push-fourth {
margin-left: 26.04166667%;
}
.fs-grid .fs-row .fs-lg-push-third {
margin-left: 34.375%;
}
.fs-grid .fs-row .fs-lg-push-half {
margin-left: 51.04166667%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-fifth {
width: 20%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-fourth {
width: 25%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-third {
width: 33.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-half {
width: 50%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-full {
width: 100%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-fifth {
margin-left: 20%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-fourth {
margin-left: 25%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-third {
margin-left: 33.33333333%;
}
.fs-grid .fs-row [class*="-contained"].fs-lg-push-half {
margin-left: 50%;
}
.fs-grid .fs-row .fs-lg-hide {
display: none;
}
.fs-grid .fs-row .fs-cell.-padded {
behavior: none;
}
| ezekutor/jsdelivr | files/formstone/0.8.26/css/grid.ie.css | CSS | mit | 5,988 |
/*
* Driver for the Conexant CX23885 PCIe bridge
*
* Copyright (c) 2006 Steven Toth <stoth@linuxtv.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.
*/
#include <linux/pci.h>
#include <linux/i2c.h>
#include <linux/kdev_t.h>
#include <linux/slab.h>
#include <media/v4l2-device.h>
#include <media/v4l2-fh.h>
#include <media/v4l2-ctrls.h>
#include <media/tuner.h>
#include <media/tveeprom.h>
#include <media/videobuf2-dma-sg.h>
#include <media/videobuf2-dvb.h>
#include <media/rc-core.h>
#include "cx23885-reg.h"
#include "media/drv-intf/cx2341x.h"
#include <linux/mutex.h>
#define CX23885_VERSION "0.0.4"
#define UNSET (-1U)
#define CX23885_MAXBOARDS 8
/* Max number of inputs by card */
#define MAX_CX23885_INPUT 8
#define INPUT(nr) (&cx23885_boards[dev->board].input[nr])
#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
#define CX23885_BOARD_NOAUTO UNSET
#define CX23885_BOARD_UNKNOWN 0
#define CX23885_BOARD_HAUPPAUGE_HVR1800lp 1
#define CX23885_BOARD_HAUPPAUGE_HVR1800 2
#define CX23885_BOARD_HAUPPAUGE_HVR1250 3
#define CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP 4
#define CX23885_BOARD_HAUPPAUGE_HVR1500Q 5
#define CX23885_BOARD_HAUPPAUGE_HVR1500 6
#define CX23885_BOARD_HAUPPAUGE_HVR1200 7
#define CX23885_BOARD_HAUPPAUGE_HVR1700 8
#define CX23885_BOARD_HAUPPAUGE_HVR1400 9
#define CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP 10
#define CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP 11
#define CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H 12
#define CX23885_BOARD_COMPRO_VIDEOMATE_E650F 13
#define CX23885_BOARD_TBS_6920 14
#define CX23885_BOARD_TEVII_S470 15
#define CX23885_BOARD_DVBWORLD_2005 16
#define CX23885_BOARD_NETUP_DUAL_DVBS2_CI 17
#define CX23885_BOARD_HAUPPAUGE_HVR1270 18
#define CX23885_BOARD_HAUPPAUGE_HVR1275 19
#define CX23885_BOARD_HAUPPAUGE_HVR1255 20
#define CX23885_BOARD_HAUPPAUGE_HVR1210 21
#define CX23885_BOARD_MYGICA_X8506 22
#define CX23885_BOARD_MAGICPRO_PROHDTVE2 23
#define CX23885_BOARD_HAUPPAUGE_HVR1850 24
#define CX23885_BOARD_COMPRO_VIDEOMATE_E800 25
#define CX23885_BOARD_HAUPPAUGE_HVR1290 26
#define CX23885_BOARD_MYGICA_X8558PRO 27
#define CX23885_BOARD_LEADTEK_WINFAST_PXTV1200 28
#define CX23885_BOARD_GOTVIEW_X5_3D_HYBRID 29
#define CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF 30
#define CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H_XC4000 31
#define CX23885_BOARD_MPX885 32
#define CX23885_BOARD_MYGICA_X8507 33
#define CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL 34
#define CX23885_BOARD_TEVII_S471 35
#define CX23885_BOARD_HAUPPAUGE_HVR1255_22111 36
#define CX23885_BOARD_PROF_8000 37
#define CX23885_BOARD_HAUPPAUGE_HVR4400 38
#define CX23885_BOARD_AVERMEDIA_HC81R 39
#define CX23885_BOARD_TBS_6981 40
#define CX23885_BOARD_TBS_6980 41
#define CX23885_BOARD_LEADTEK_WINFAST_PXPVR2200 42
#define CX23885_BOARD_HAUPPAUGE_IMPACTVCBE 43
#define CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP2 44
#define CX23885_BOARD_DVBSKY_T9580 45
#define CX23885_BOARD_DVBSKY_T980C 46
#define CX23885_BOARD_DVBSKY_S950C 47
#define CX23885_BOARD_TT_CT2_4500_CI 48
#define CX23885_BOARD_DVBSKY_S950 49
#define CX23885_BOARD_DVBSKY_S952 50
#define CX23885_BOARD_DVBSKY_T982 51
#define CX23885_BOARD_HAUPPAUGE_HVR5525 52
#define CX23885_BOARD_HAUPPAUGE_STARBURST 53
#define CX23885_BOARD_VIEWCAST_260E 54
#define CX23885_BOARD_VIEWCAST_460E 55
#define CX23885_BOARD_HAUPPAUGE_QUADHD_DVB 56
#define CX23885_BOARD_HAUPPAUGE_QUADHD_ATSC 57
#define GPIO_0 0x00000001
#define GPIO_1 0x00000002
#define GPIO_2 0x00000004
#define GPIO_3 0x00000008
#define GPIO_4 0x00000010
#define GPIO_5 0x00000020
#define GPIO_6 0x00000040
#define GPIO_7 0x00000080
#define GPIO_8 0x00000100
#define GPIO_9 0x00000200
#define GPIO_10 0x00000400
#define GPIO_11 0x00000800
#define GPIO_12 0x00001000
#define GPIO_13 0x00002000
#define GPIO_14 0x00004000
#define GPIO_15 0x00008000
/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */
#define CX23885_NORMS (\
V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 | \
V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \
V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc | \
V4L2_STD_PAL_60 | V4L2_STD_SECAM_L | V4L2_STD_SECAM_DK)
struct cx23885_fmt {
char *name;
u32 fourcc; /* v4l2 format id */
int depth;
int flags;
u32 cxformat;
};
struct cx23885_tvnorm {
char *name;
v4l2_std_id id;
u32 cxiformat;
u32 cxoformat;
};
enum cx23885_itype {
CX23885_VMUX_COMPOSITE1 = 1,
CX23885_VMUX_COMPOSITE2,
CX23885_VMUX_COMPOSITE3,
CX23885_VMUX_COMPOSITE4,
CX23885_VMUX_SVIDEO,
CX23885_VMUX_COMPONENT,
CX23885_VMUX_TELEVISION,
CX23885_VMUX_CABLE,
CX23885_VMUX_DVB,
CX23885_VMUX_DEBUG,
CX23885_RADIO,
};
enum cx23885_src_sel_type {
CX23885_SRC_SEL_EXT_656_VIDEO = 0,
CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO
};
struct cx23885_riscmem {
unsigned int size;
__le32 *cpu;
__le32 *jmp;
dma_addr_t dma;
};
/* buffer for one video frame */
struct cx23885_buffer {
/* common v4l buffer stuff -- must be first */
struct vb2_v4l2_buffer vb;
struct list_head queue;
/* cx23885 specific */
unsigned int bpl;
struct cx23885_riscmem risc;
struct cx23885_fmt *fmt;
u32 count;
};
struct cx23885_input {
enum cx23885_itype type;
unsigned int vmux;
unsigned int amux;
u32 gpio0, gpio1, gpio2, gpio3;
};
typedef enum {
CX23885_MPEG_UNDEFINED = 0,
CX23885_MPEG_DVB,
CX23885_ANALOG_VIDEO,
CX23885_MPEG_ENCODER,
} port_t;
struct cx23885_board {
char *name;
port_t porta, portb, portc;
int num_fds_portb, num_fds_portc;
unsigned int tuner_type;
unsigned int radio_type;
unsigned char tuner_addr;
unsigned char radio_addr;
unsigned int tuner_bus;
/* Vendors can and do run the PCIe bridge at different
* clock rates, driven physically by crystals on the PCBs.
* The core has to accommodate this. This allows the user
* to add new boards with new frequencys. The value is
* expressed in Hz.
*
* The core framework will default this value based on
* current designs, but it can vary.
*/
u32 clk_freq;
struct cx23885_input input[MAX_CX23885_INPUT];
int ci_type; /* for NetUP */
/* Force bottom field first during DMA (888 workaround) */
u32 force_bff;
};
struct cx23885_subid {
u16 subvendor;
u16 subdevice;
u32 card;
};
struct cx23885_i2c {
struct cx23885_dev *dev;
int nr;
/* i2c i/o */
struct i2c_adapter i2c_adap;
struct i2c_client i2c_client;
u32 i2c_rc;
/* 885 registers used for raw addess */
u32 i2c_period;
u32 reg_ctrl;
u32 reg_stat;
u32 reg_addr;
u32 reg_rdata;
u32 reg_wdata;
};
struct cx23885_dmaqueue {
struct list_head active;
u32 count;
};
struct cx23885_tsport {
struct cx23885_dev *dev;
unsigned nr;
int sram_chno;
struct vb2_dvb_frontends frontends;
/* dma queues */
struct cx23885_dmaqueue mpegq;
u32 ts_packet_size;
u32 ts_packet_count;
int width;
int height;
spinlock_t slock;
/* registers */
u32 reg_gpcnt;
u32 reg_gpcnt_ctl;
u32 reg_dma_ctl;
u32 reg_lngth;
u32 reg_hw_sop_ctrl;
u32 reg_gen_ctrl;
u32 reg_bd_pkt_status;
u32 reg_sop_status;
u32 reg_fifo_ovfl_stat;
u32 reg_vld_misc;
u32 reg_ts_clk_en;
u32 reg_ts_int_msk;
u32 reg_ts_int_stat;
u32 reg_src_sel;
/* Default register vals */
int pci_irqmask;
u32 dma_ctl_val;
u32 ts_int_msk_val;
u32 gen_ctrl_val;
u32 ts_clk_en_val;
u32 src_sel_val;
u32 vld_misc_val;
u32 hw_sop_ctrl_val;
/* Allow a single tsport to have multiple frontends */
u32 num_frontends;
void (*gate_ctrl)(struct cx23885_tsport *port, int open);
void *port_priv;
/* Workaround for a temp dvb_frontend that the tuner can attached to */
struct dvb_frontend analog_fe;
struct i2c_client *i2c_client_demod;
struct i2c_client *i2c_client_tuner;
struct i2c_client *i2c_client_sec;
struct i2c_client *i2c_client_ci;
int (*set_frontend)(struct dvb_frontend *fe);
int (*fe_set_voltage)(struct dvb_frontend *fe,
enum fe_sec_voltage voltage);
};
struct cx23885_kernel_ir {
struct cx23885_dev *cx;
char *name;
char *phys;
struct rc_dev *rc;
};
struct cx23885_audio_buffer {
unsigned int bpl;
struct cx23885_riscmem risc;
void *vaddr;
struct scatterlist *sglist;
int sglen;
int nr_pages;
};
struct cx23885_audio_dev {
struct cx23885_dev *dev;
struct pci_dev *pci;
struct snd_card *card;
spinlock_t lock;
atomic_t count;
unsigned int dma_size;
unsigned int period_size;
unsigned int num_periods;
struct cx23885_audio_buffer *buf;
struct snd_pcm_substream *substream;
};
struct cx23885_dev {
atomic_t refcount;
struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler ctrl_handler;
/* pci stuff */
struct pci_dev *pci;
unsigned char pci_rev, pci_lat;
int pci_bus, pci_slot;
u32 __iomem *lmmio;
u8 __iomem *bmmio;
int pci_irqmask;
spinlock_t pci_irqmask_lock; /* protects mask reg too */
int hwrevision;
/* This valud is board specific and is used to configure the
* AV core so we see nice clean and stable video and audio. */
u32 clk_freq;
/* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
struct cx23885_i2c i2c_bus[3];
int nr;
struct mutex lock;
struct mutex gpio_lock;
/* board details */
unsigned int board;
char name[32];
struct cx23885_tsport ts1, ts2;
/* sram configuration */
struct sram_channel *sram_channels;
enum {
CX23885_BRIDGE_UNDEFINED = 0,
CX23885_BRIDGE_885 = 885,
CX23885_BRIDGE_887 = 887,
CX23885_BRIDGE_888 = 888,
} bridge;
/* Analog video */
unsigned int input;
unsigned int audinput; /* Selectable audio input */
u32 tvaudio;
v4l2_std_id tvnorm;
unsigned int tuner_type;
unsigned char tuner_addr;
unsigned int tuner_bus;
unsigned int radio_type;
unsigned char radio_addr;
struct v4l2_subdev *sd_cx25840;
struct work_struct cx25840_work;
/* Infrared */
struct v4l2_subdev *sd_ir;
struct work_struct ir_rx_work;
unsigned long ir_rx_notifications;
struct work_struct ir_tx_work;
unsigned long ir_tx_notifications;
struct cx23885_kernel_ir *kernel_ir;
atomic_t ir_input_stopping;
/* V4l */
u32 freq;
struct video_device *video_dev;
struct video_device *vbi_dev;
/* video capture */
struct cx23885_fmt *fmt;
unsigned int width, height;
unsigned field;
struct cx23885_dmaqueue vidq;
struct vb2_queue vb2_vidq;
struct cx23885_dmaqueue vbiq;
struct vb2_queue vb2_vbiq;
spinlock_t slock;
/* MPEG Encoder ONLY settings */
u32 cx23417_mailbox;
struct cx2341x_handler cxhdl;
struct video_device *v4l_device;
struct vb2_queue vb2_mpegq;
struct cx23885_tvnorm encodernorm;
/* Analog raw audio */
struct cx23885_audio_dev *audio_dev;
};
static inline struct cx23885_dev *to_cx23885(struct v4l2_device *v4l2_dev)
{
return container_of(v4l2_dev, struct cx23885_dev, v4l2_dev);
}
#define call_all(dev, o, f, args...) \
v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
#define CX23885_HW_888_IR (1 << 0)
#define CX23885_HW_AV_CORE (1 << 1)
#define call_hw(dev, grpid, o, f, args...) \
v4l2_device_call_all(&dev->v4l2_dev, grpid, o, f, ##args)
extern struct v4l2_subdev *cx23885_find_hw(struct cx23885_dev *dev, u32 hw);
#define SRAM_CH01 0 /* Video A */
#define SRAM_CH02 1 /* VBI A */
#define SRAM_CH03 2 /* Video B */
#define SRAM_CH04 3 /* Transport via B */
#define SRAM_CH05 4 /* VBI B */
#define SRAM_CH06 5 /* Video C */
#define SRAM_CH07 6 /* Transport via C */
#define SRAM_CH08 7 /* Audio Internal A */
#define SRAM_CH09 8 /* Audio Internal B */
#define SRAM_CH10 9 /* Audio External */
#define SRAM_CH11 10 /* COMB_3D_N */
#define SRAM_CH12 11 /* Comb 3D N1 */
#define SRAM_CH13 12 /* Comb 3D N2 */
#define SRAM_CH14 13 /* MOE Vid */
#define SRAM_CH15 14 /* MOE RSLT */
struct sram_channel {
char *name;
u32 cmds_start;
u32 ctrl_start;
u32 cdt;
u32 fifo_start;
u32 fifo_size;
u32 ptr1_reg;
u32 ptr2_reg;
u32 cnt1_reg;
u32 cnt2_reg;
u32 jumponly;
};
/* ----------------------------------------------------------- */
#define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
#define cx_write(reg, value) writel((value), dev->lmmio + ((reg)>>2))
#define cx_andor(reg, mask, value) \
writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
((value) & (mask)), dev->lmmio+((reg)>>2))
#define cx_set(reg, bit) cx_andor((reg), (bit), (bit))
#define cx_clear(reg, bit) cx_andor((reg), (bit), 0)
/* ----------------------------------------------------------- */
/* cx23885-core.c */
extern int cx23885_sram_channel_setup(struct cx23885_dev *dev,
struct sram_channel *ch,
unsigned int bpl, u32 risc);
extern void cx23885_sram_channel_dump(struct cx23885_dev *dev,
struct sram_channel *ch);
extern int cx23885_risc_buffer(struct pci_dev *pci, struct cx23885_riscmem *risc,
struct scatterlist *sglist,
unsigned int top_offset, unsigned int bottom_offset,
unsigned int bpl, unsigned int padding, unsigned int lines);
extern int cx23885_risc_vbibuffer(struct pci_dev *pci,
struct cx23885_riscmem *risc, struct scatterlist *sglist,
unsigned int top_offset, unsigned int bottom_offset,
unsigned int bpl, unsigned int padding, unsigned int lines);
int cx23885_start_dma(struct cx23885_tsport *port,
struct cx23885_dmaqueue *q,
struct cx23885_buffer *buf);
void cx23885_cancel_buffers(struct cx23885_tsport *port);
extern void cx23885_gpio_set(struct cx23885_dev *dev, u32 mask);
extern void cx23885_gpio_clear(struct cx23885_dev *dev, u32 mask);
extern u32 cx23885_gpio_get(struct cx23885_dev *dev, u32 mask);
extern void cx23885_gpio_enable(struct cx23885_dev *dev, u32 mask,
int asoutput);
extern void cx23885_irq_add_enable(struct cx23885_dev *dev, u32 mask);
extern void cx23885_irq_enable(struct cx23885_dev *dev, u32 mask);
extern void cx23885_irq_disable(struct cx23885_dev *dev, u32 mask);
extern void cx23885_irq_remove(struct cx23885_dev *dev, u32 mask);
/* ----------------------------------------------------------- */
/* cx23885-cards.c */
extern struct cx23885_board cx23885_boards[];
extern const unsigned int cx23885_bcount;
extern struct cx23885_subid cx23885_subids[];
extern const unsigned int cx23885_idcount;
extern int cx23885_tuner_callback(void *priv, int component,
int command, int arg);
extern void cx23885_card_list(struct cx23885_dev *dev);
extern int cx23885_ir_init(struct cx23885_dev *dev);
extern void cx23885_ir_pci_int_enable(struct cx23885_dev *dev);
extern void cx23885_ir_fini(struct cx23885_dev *dev);
extern void cx23885_gpio_setup(struct cx23885_dev *dev);
extern void cx23885_card_setup(struct cx23885_dev *dev);
extern void cx23885_card_setup_pre_i2c(struct cx23885_dev *dev);
extern int cx23885_dvb_register(struct cx23885_tsport *port);
extern int cx23885_dvb_unregister(struct cx23885_tsport *port);
extern int cx23885_buf_prepare(struct cx23885_buffer *buf,
struct cx23885_tsport *port);
extern void cx23885_buf_queue(struct cx23885_tsport *port,
struct cx23885_buffer *buf);
extern void cx23885_free_buffer(struct cx23885_dev *dev,
struct cx23885_buffer *buf);
/* ----------------------------------------------------------- */
/* cx23885-video.c */
/* Video */
extern int cx23885_video_register(struct cx23885_dev *dev);
extern void cx23885_video_unregister(struct cx23885_dev *dev);
extern int cx23885_video_irq(struct cx23885_dev *dev, u32 status);
extern void cx23885_video_wakeup(struct cx23885_dev *dev,
struct cx23885_dmaqueue *q, u32 count);
int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i);
int cx23885_set_input(struct file *file, void *priv, unsigned int i);
int cx23885_get_input(struct file *file, void *priv, unsigned int *i);
int cx23885_set_frequency(struct file *file, void *priv, const struct v4l2_frequency *f);
int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm);
/* ----------------------------------------------------------- */
/* cx23885-vbi.c */
extern int cx23885_vbi_fmt(struct file *file, void *priv,
struct v4l2_format *f);
extern void cx23885_vbi_timeout(unsigned long data);
extern struct vb2_ops cx23885_vbi_qops;
extern int cx23885_vbi_irq(struct cx23885_dev *dev, u32 status);
/* cx23885-i2c.c */
extern int cx23885_i2c_register(struct cx23885_i2c *bus);
extern int cx23885_i2c_unregister(struct cx23885_i2c *bus);
extern void cx23885_av_clk(struct cx23885_dev *dev, int enable);
/* ----------------------------------------------------------- */
/* cx23885-417.c */
extern int cx23885_417_register(struct cx23885_dev *dev);
extern void cx23885_417_unregister(struct cx23885_dev *dev);
extern int cx23885_irq_417(struct cx23885_dev *dev, u32 status);
extern void cx23885_417_check_encoder(struct cx23885_dev *dev);
extern void cx23885_mc417_init(struct cx23885_dev *dev);
extern int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value);
extern int mc417_memory_write(struct cx23885_dev *dev, u32 address, u32 value);
extern int mc417_register_read(struct cx23885_dev *dev,
u16 address, u32 *value);
extern int mc417_register_write(struct cx23885_dev *dev,
u16 address, u32 value);
extern void mc417_gpio_set(struct cx23885_dev *dev, u32 mask);
extern void mc417_gpio_clear(struct cx23885_dev *dev, u32 mask);
extern void mc417_gpio_enable(struct cx23885_dev *dev, u32 mask, int asoutput);
/* ----------------------------------------------------------- */
/* cx23885-alsa.c */
extern struct cx23885_audio_dev *cx23885_audio_register(
struct cx23885_dev *dev);
extern void cx23885_audio_unregister(struct cx23885_dev *dev);
extern int cx23885_audio_irq(struct cx23885_dev *dev, u32 status, u32 mask);
extern int cx23885_risc_databuffer(struct pci_dev *pci,
struct cx23885_riscmem *risc,
struct scatterlist *sglist,
unsigned int bpl,
unsigned int lines,
unsigned int lpi);
/* ----------------------------------------------------------- */
/* tv norms */
static inline unsigned int norm_maxh(v4l2_std_id norm)
{
return (norm & V4L2_STD_525_60) ? 480 : 576;
}
| Asus-T100/kernel | drivers/media/pci/cx23885/cx23885.h | C | gpl-2.0 | 20,871 |
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Extensions to the standard "os" package.
package osext // import "github.com/kardianos/osext"
import "path/filepath"
// Executable returns an absolute path that can be used to
// re-invoke the current program.
// It may not be valid after the current program exits.
func Executable() (string, error) {
p, err := executable()
return filepath.Clean(p), err
}
// Returns same path as Executable, returns just the folder
// path. Excludes the executable name.
func ExecutableFolder() (string, error) {
p, err := Executable()
if err != nil {
return "", err
}
folder, _ := filepath.Split(p)
return folder, nil
}
| sg00dwin/origin | vendor/github.com/kardianos/osext/osext.go | GO | apache-2.0 | 781 |
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QCUPSPRINTENGINE_P_H
#define QCUPSPRINTENGINE_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "QtPrintSupport/qprintengine.h"
#ifndef QT_NO_PRINTER
#include <QtCore/qstring.h>
#include <QtGui/qpaintengine.h>
#include <private/qpaintengine_p.h>
#include <private/qprintdevice_p.h>
#include <private/qprintengine_pdf_p.h>
QT_BEGIN_NAMESPACE
class QCupsPrintEnginePrivate;
class QCupsPrintEngine : public QPdfPrintEngine
{
Q_DECLARE_PRIVATE(QCupsPrintEngine)
public:
QCupsPrintEngine(QPrinter::PrinterMode m);
virtual ~QCupsPrintEngine();
// reimplementations QPdfPrintEngine
void setProperty(PrintEnginePropertyKey key, const QVariant &value);
QVariant property(PrintEnginePropertyKey key) const;
// end reimplementations QPdfPrintEngine
private:
Q_DISABLE_COPY(QCupsPrintEngine)
};
class QCupsPrintEnginePrivate : public QPdfPrintEnginePrivate
{
Q_DECLARE_PUBLIC(QCupsPrintEngine)
public:
QCupsPrintEnginePrivate(QPrinter::PrinterMode m);
~QCupsPrintEnginePrivate();
bool openPrintDevice();
void closePrintDevice();
private:
Q_DISABLE_COPY(QCupsPrintEnginePrivate)
void setupDefaultPrinter();
void changePrinter(const QString &newPrinter);
void setPageSize(const QPageSize &pageSize);
QPrintDevice m_printDevice;
QStringList cupsOptions;
QString cupsTempFile;
};
QT_END_NAMESPACE
#endif // QT_NO_PRINTER
#endif // QCUPSPRINTENGINE_P_H
| bmotlaghFLT/FLT_PhantomJS | src/qt/qtbase/src/plugins/printsupport/cups/qcupsprintengine_p.h | C | bsd-3-clause | 3,245 |
Germany, 2016-04-20
initOS GmbH agrees to the terms of the Odoo Corporate
Contributor License Agreement v1.0.
I declare that I am authorized and able to make this agreement and sign this
declaration.
Signed,
Frederik Kramer frederik.kramer@initos.com https://github.com/OSevangelist
List of contributors:
Markus Schneider markus.schneider@initos.com https://github.com/OSguard
Thomas Rehn thomas.rehn@initos.com https://github.com/tremlin
Katja Matthes katja.matthes@initos.com https://github.com/kmatthes
Frederik Kramer frederik.kramer@initos.com https://github.com/OSevangelist
Nikolina Todorova nikolina.todorova@initos.com https://github.com/ntodorova
Peter Hahn peter.hahn@initos.com https://github.com/codingforfun
Claudia Haida claudia.haida@initos.com
Andreas Zöllner andreas.zoellner@initos.com https://github.com/azoellner
Rami Alwafaie rami.alwafaie@initos.com https://github.com/rami-wafaie
| vileopratama/vitech | src/doc/cla/corporate/initos.md | Markdown | mit | 912 |
# BSD LICENSE
#
# Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
# 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 Intel Corporation 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.
ifeq ($(RTE_SDK),)
$(error "Please define RTE_SDK environment variable")
endif
# Default target, can be overriden by command line or environment
RTE_TARGET ?= x86_64-native-linuxapp-gcc
include $(RTE_SDK)/mk/rte.vars.mk
# binary name
APP = l2fwd
# all source are stored in SRCS-y
SRCS-y := main.c
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)
include $(RTE_SDK)/mk/rte.extapp.mk
| fatedier/studies | mtcp/dpdk-2.1.0/examples/l2fwd/Makefile | Makefile | gpl-3.0 | 2,035 |
<?php
namespace PicoFeed\Scraper;
use DomDocument;
use DOMXPath;
use PicoFeed\Logging\Logger;
use PicoFeed\Parser\XmlParser;
/**
* Candidate Parser.
*
* @author Frederic Guillot
*/
class CandidateParser implements ParserInterface
{
private $dom;
private $xpath;
/**
* List of attributes to try to get the content, order is important, generic terms at the end.
*
* @var array
*/
private $candidatesAttributes = array(
'articleBody',
'articlebody',
'article-body',
'articleContent',
'articlecontent',
'article-content',
'articlePage',
'post-content',
'post_content',
'entry-content',
'entry-body',
'main-content',
'story_content',
'storycontent',
'entryBox',
'entrytext',
'comic',
'post',
'article',
'content',
'main',
);
/**
* List of attributes to strip.
*
* @var array
*/
private $stripAttributes = array(
'comment',
'share',
'links',
'toolbar',
'fb',
'footer',
'credit',
'bottom',
'nav',
'header',
'social',
'tag',
'metadata',
'entry-utility',
'related-posts',
'tweet',
'categories',
'post_title',
'by_line',
'byline',
'sponsors',
);
/**
* Tags to remove.
*
* @var array
*/
private $stripTags = array(
'nav',
'header',
'footer',
'aside',
'form',
);
/**
* Constructor.
*
* @param string $html
*/
public function __construct($html)
{
$this->dom = XmlParser::getHtmlDocument('<?xml version="1.0" encoding="UTF-8">'.$html);
$this->xpath = new DOMXPath($this->dom);
}
/**
* Get the relevant content with the list of potential attributes.
*
* @return string
*/
public function execute()
{
$content = $this->findContentWithCandidates();
if (strlen($content) < 200) {
$content = $this->findContentWithArticle();
}
if (strlen($content) < 50) {
$content = $this->findContentWithBody();
}
return $this->stripGarbage($content);
}
/**
* Find content based on the list of tag candidates.
*
* @return string
*/
public function findContentWithCandidates()
{
foreach ($this->candidatesAttributes as $candidate) {
Logger::setMessage(get_called_class().': Try this candidate: "'.$candidate.'"');
$nodes = $this->xpath->query('//*[(contains(@class, "'.$candidate.'") or @id="'.$candidate.'") and not (contains(@class, "nav") or contains(@class, "page"))]');
if ($nodes !== false && $nodes->length > 0) {
Logger::setMessage(get_called_class().': Find candidate "'.$candidate.'"');
return $this->dom->saveXML($nodes->item(0));
}
}
return '';
}
/**
* Find <article/> tag.
*
* @return string
*/
public function findContentWithArticle()
{
$nodes = $this->xpath->query('//article');
if ($nodes !== false && $nodes->length > 0) {
Logger::setMessage(get_called_class().': Find <article/> tag');
return $this->dom->saveXML($nodes->item(0));
}
return '';
}
/**
* Find <body/> tag.
*
* @return string
*/
public function findContentWithBody()
{
$nodes = $this->xpath->query('//body');
if ($nodes !== false && $nodes->length > 0) {
Logger::setMessage(get_called_class().' Find <body/>');
return $this->dom->saveXML($nodes->item(0));
}
return '';
}
/**
* Strip useless tags.
*
* @param string $content
*
* @return string
*/
public function stripGarbage($content)
{
$dom = XmlParser::getDomDocument($content);
if ($dom !== false) {
$xpath = new DOMXPath($dom);
$this->stripTags($xpath);
$this->stripAttributes($dom, $xpath);
$content = $dom->saveXML($dom->documentElement);
}
return $content;
}
/**
* Remove blacklisted tags.
*
* @param DOMXPath $xpath
*/
public function stripTags(DOMXPath $xpath)
{
foreach ($this->stripTags as $tag) {
$nodes = $xpath->query('//'.$tag);
if ($nodes !== false && $nodes->length > 0) {
Logger::setMessage(get_called_class().': Strip tag: "'.$tag.'"');
foreach ($nodes as $node) {
$node->parentNode->removeChild($node);
}
}
}
}
/**
* Remove blacklisted attributes.
*
* @param DomDocument $dom
* @param DOMXPath $xpath
*/
public function stripAttributes(DomDocument $dom, DOMXPath $xpath)
{
foreach ($this->stripAttributes as $attribute) {
$nodes = $xpath->query('//*[contains(@class, "'.$attribute.'") or contains(@id, "'.$attribute.'")]');
if ($nodes !== false && $nodes->length > 0) {
Logger::setMessage(get_called_class().': Strip attribute: "'.$attribute.'"');
foreach ($nodes as $node) {
if ($this->shouldRemove($dom, $node)) {
$node->parentNode->removeChild($node);
}
}
}
}
}
/**
* Return false if the node should not be removed.
*
* @param DomDocument $dom
* @param DomNode $node
*
* @return bool
*/
public function shouldRemove(DomDocument $dom, $node)
{
$document_length = strlen($dom->textContent);
$node_length = strlen($node->textContent);
if ($document_length === 0) {
return true;
}
$ratio = $node_length * 100 / $document_length;
if ($ratio >= 90) {
Logger::setMessage(get_called_class().': Should not remove this node ('.$node->nodeName.') ratio: '.$ratio.'%');
return false;
}
return true;
}
}
| bkostrowiecki/devnote | www/user/plugins/admin/vendor/fguillot/picofeed/lib/PicoFeed/Scraper/CandidateParser.php | PHP | gpl-3.0 | 6,365 |
<div class="modal" ng-controller="EditorUnsavedChangesPopupCrtl">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h2 translate="EDITOR.POPUP.UNSAVED-CHANGES.TITLE"></h2>
</div>
<div class="modal-body">
<p translate="EDITOR.POPUP.UNSAVED-CHANGES.DESCRIPTION"></p>
</div>
<div class="modal-footer">
<div class="pull-right">
<button class="btn btn-danger" ng-click="ok()" translate="EDITOR.POPUP.UNSAVED-CHANGES.ACTION.DISCARD"></button>
<button class="btn btn-default" ng-click="cancel()" translate="EDITOR.POPUP.UNSAVED-CHANGES.ACTION.CONTINUE"></button>
</div>
<div class="loading pull-right" ng-show="loading">
<div class="l1"></div><div class="l2"></div><div class="l2"></div>
</div>
</div>
</div>
</div>
</div> | NJU-STP/STP | webapp/widgets/modeler/editor-app/popups/unsaved-changes.html | HTML | apache-2.0 | 977 |
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Displays the 'User groups' sub page under 'Users' page.
*
* @package PhpMyAdmin
*/
require_once 'libraries/common.inc.php';
require_once 'libraries/server_users.lib.php';
require_once 'libraries/server_user_groups.lib.php';
PMA_getRelationsParam();
if (! $GLOBALS['cfgRelation']['menuswork']) {
exit;
}
$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('server_user_groups.js');
/**
* Only allowed to superuser
*/
if (! $GLOBALS['is_superuser']) {
$response->addHTML(PMA_Message::error(__('No Privileges'))->getDisplay());
exit;
}
$response->addHTML('<div>');
$response->addHTML(PMA_getHtmlForSubMenusOnUsersPage('server_user_groups.php'));
/**
* Delete user group
*/
if (! empty($_REQUEST['deleteUserGroup'])) {
PMA_deleteUserGroup($_REQUEST['userGroup']);
}
/**
* Add a new user group
*/
if (! empty($_REQUEST['addUserGroupSubmit'])) {
PMA_editUserGroup($_REQUEST['userGroup'], true);
}
/**
* Update a user group
*/
if (! empty($_REQUEST['editUserGroupSubmit'])) {
PMA_editUserGroup($_REQUEST['userGroup']);
}
if (isset($_REQUEST['viewUsers'])) {
// Display users belonging to a user group
$response->addHTML(PMA_getHtmlForListingUsersofAGroup($_REQUEST['userGroup']));
}
if (isset($_REQUEST['addUserGroup'])) {
// Display add user group dialog
$response->addHTML(PMA_getHtmlToEditUserGroup());
} elseif (isset($_REQUEST['editUserGroup'])) {
// Display edit user group dialog
$response->addHTML(PMA_getHtmlToEditUserGroup($_REQUEST['userGroup']));
} else {
// Display user groups table
$response->addHTML(PMA_getHtmlForUserGroupsTable());
}
$response->addHTML('</div>');
| Dokaponteam/ITF_Project | xampp/phpMyAdmin/server_user_groups.php | PHP | mit | 1,786 |
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2013 - 2018 Intel Corporation. */
/* ethtool support for iavf */
#include "iavf.h"
#include <linux/uaccess.h>
/* ethtool statistics helpers */
/**
* struct iavf_stats - definition for an ethtool statistic
* @stat_string: statistic name to display in ethtool -S output
* @sizeof_stat: the sizeof() the stat, must be no greater than sizeof(u64)
* @stat_offset: offsetof() the stat from a base pointer
*
* This structure defines a statistic to be added to the ethtool stats buffer.
* It defines a statistic as offset from a common base pointer. Stats should
* be defined in constant arrays using the IAVF_STAT macro, with every element
* of the array using the same _type for calculating the sizeof_stat and
* stat_offset.
*
* The @sizeof_stat is expected to be sizeof(u8), sizeof(u16), sizeof(u32) or
* sizeof(u64). Other sizes are not expected and will produce a WARN_ONCE from
* the iavf_add_ethtool_stat() helper function.
*
* The @stat_string is interpreted as a format string, allowing formatted
* values to be inserted while looping over multiple structures for a given
* statistics array. Thus, every statistic string in an array should have the
* same type and number of format specifiers, to be formatted by variadic
* arguments to the iavf_add_stat_string() helper function.
**/
struct iavf_stats {
char stat_string[ETH_GSTRING_LEN];
int sizeof_stat;
int stat_offset;
};
/* Helper macro to define an iavf_stat structure with proper size and type.
* Use this when defining constant statistics arrays. Note that @_type expects
* only a type name and is used multiple times.
*/
#define IAVF_STAT(_type, _name, _stat) { \
.stat_string = _name, \
.sizeof_stat = sizeof_field(_type, _stat), \
.stat_offset = offsetof(_type, _stat) \
}
/* Helper macro for defining some statistics related to queues */
#define IAVF_QUEUE_STAT(_name, _stat) \
IAVF_STAT(struct iavf_ring, _name, _stat)
/* Stats associated with a Tx or Rx ring */
static const struct iavf_stats iavf_gstrings_queue_stats[] = {
IAVF_QUEUE_STAT("%s-%u.packets", stats.packets),
IAVF_QUEUE_STAT("%s-%u.bytes", stats.bytes),
};
/**
* iavf_add_one_ethtool_stat - copy the stat into the supplied buffer
* @data: location to store the stat value
* @pointer: basis for where to copy from
* @stat: the stat definition
*
* Copies the stat data defined by the pointer and stat structure pair into
* the memory supplied as data. Used to implement iavf_add_ethtool_stats and
* iavf_add_queue_stats. If the pointer is null, data will be zero'd.
*/
static void
iavf_add_one_ethtool_stat(u64 *data, void *pointer,
const struct iavf_stats *stat)
{
char *p;
if (!pointer) {
/* ensure that the ethtool data buffer is zero'd for any stats
* which don't have a valid pointer.
*/
*data = 0;
return;
}
p = (char *)pointer + stat->stat_offset;
switch (stat->sizeof_stat) {
case sizeof(u64):
*data = *((u64 *)p);
break;
case sizeof(u32):
*data = *((u32 *)p);
break;
case sizeof(u16):
*data = *((u16 *)p);
break;
case sizeof(u8):
*data = *((u8 *)p);
break;
default:
WARN_ONCE(1, "unexpected stat size for %s",
stat->stat_string);
*data = 0;
}
}
/**
* __iavf_add_ethtool_stats - copy stats into the ethtool supplied buffer
* @data: ethtool stats buffer
* @pointer: location to copy stats from
* @stats: array of stats to copy
* @size: the size of the stats definition
*
* Copy the stats defined by the stats array using the pointer as a base into
* the data buffer supplied by ethtool. Updates the data pointer to point to
* the next empty location for successive calls to __iavf_add_ethtool_stats.
* If pointer is null, set the data values to zero and update the pointer to
* skip these stats.
**/
static void
__iavf_add_ethtool_stats(u64 **data, void *pointer,
const struct iavf_stats stats[],
const unsigned int size)
{
unsigned int i;
for (i = 0; i < size; i++)
iavf_add_one_ethtool_stat((*data)++, pointer, &stats[i]);
}
/**
* iavf_add_ethtool_stats - copy stats into ethtool supplied buffer
* @data: ethtool stats buffer
* @pointer: location where stats are stored
* @stats: static const array of stat definitions
*
* Macro to ease the use of __iavf_add_ethtool_stats by taking a static
* constant stats array and passing the ARRAY_SIZE(). This avoids typos by
* ensuring that we pass the size associated with the given stats array.
*
* The parameter @stats is evaluated twice, so parameters with side effects
* should be avoided.
**/
#define iavf_add_ethtool_stats(data, pointer, stats) \
__iavf_add_ethtool_stats(data, pointer, stats, ARRAY_SIZE(stats))
/**
* iavf_add_queue_stats - copy queue statistics into supplied buffer
* @data: ethtool stats buffer
* @ring: the ring to copy
*
* Queue statistics must be copied while protected by
* u64_stats_fetch_begin_irq, so we can't directly use iavf_add_ethtool_stats.
* Assumes that queue stats are defined in iavf_gstrings_queue_stats. If the
* ring pointer is null, zero out the queue stat values and update the data
* pointer. Otherwise safely copy the stats from the ring into the supplied
* buffer and update the data pointer when finished.
*
* This function expects to be called while under rcu_read_lock().
**/
static void
iavf_add_queue_stats(u64 **data, struct iavf_ring *ring)
{
const unsigned int size = ARRAY_SIZE(iavf_gstrings_queue_stats);
const struct iavf_stats *stats = iavf_gstrings_queue_stats;
unsigned int start;
unsigned int i;
/* To avoid invalid statistics values, ensure that we keep retrying
* the copy until we get a consistent value according to
* u64_stats_fetch_retry_irq. But first, make sure our ring is
* non-null before attempting to access its syncp.
*/
do {
start = !ring ? 0 : u64_stats_fetch_begin_irq(&ring->syncp);
for (i = 0; i < size; i++)
iavf_add_one_ethtool_stat(&(*data)[i], ring, &stats[i]);
} while (ring && u64_stats_fetch_retry_irq(&ring->syncp, start));
/* Once we successfully copy the stats in, update the data pointer */
*data += size;
}
/**
* __iavf_add_stat_strings - copy stat strings into ethtool buffer
* @p: ethtool supplied buffer
* @stats: stat definitions array
* @size: size of the stats array
*
* Format and copy the strings described by stats into the buffer pointed at
* by p.
**/
static void __iavf_add_stat_strings(u8 **p, const struct iavf_stats stats[],
const unsigned int size, ...)
{
unsigned int i;
for (i = 0; i < size; i++) {
va_list args;
va_start(args, size);
vsnprintf(*p, ETH_GSTRING_LEN, stats[i].stat_string, args);
*p += ETH_GSTRING_LEN;
va_end(args);
}
}
/**
* iavf_add_stat_strings - copy stat strings into ethtool buffer
* @p: ethtool supplied buffer
* @stats: stat definitions array
*
* Format and copy the strings described by the const static stats value into
* the buffer pointed at by p.
*
* The parameter @stats is evaluated twice, so parameters with side effects
* should be avoided. Additionally, stats must be an array such that
* ARRAY_SIZE can be called on it.
**/
#define iavf_add_stat_strings(p, stats, ...) \
__iavf_add_stat_strings(p, stats, ARRAY_SIZE(stats), ## __VA_ARGS__)
#define VF_STAT(_name, _stat) \
IAVF_STAT(struct iavf_adapter, _name, _stat)
static const struct iavf_stats iavf_gstrings_stats[] = {
VF_STAT("rx_bytes", current_stats.rx_bytes),
VF_STAT("rx_unicast", current_stats.rx_unicast),
VF_STAT("rx_multicast", current_stats.rx_multicast),
VF_STAT("rx_broadcast", current_stats.rx_broadcast),
VF_STAT("rx_discards", current_stats.rx_discards),
VF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol),
VF_STAT("tx_bytes", current_stats.tx_bytes),
VF_STAT("tx_unicast", current_stats.tx_unicast),
VF_STAT("tx_multicast", current_stats.tx_multicast),
VF_STAT("tx_broadcast", current_stats.tx_broadcast),
VF_STAT("tx_discards", current_stats.tx_discards),
VF_STAT("tx_errors", current_stats.tx_errors),
};
#define IAVF_STATS_LEN ARRAY_SIZE(iavf_gstrings_stats)
#define IAVF_QUEUE_STATS_LEN ARRAY_SIZE(iavf_gstrings_queue_stats)
/* For now we have one and only one private flag and it is only defined
* when we have support for the SKIP_CPU_SYNC DMA attribute. Instead
* of leaving all this code sitting around empty we will strip it unless
* our one private flag is actually available.
*/
struct iavf_priv_flags {
char flag_string[ETH_GSTRING_LEN];
u32 flag;
bool read_only;
};
#define IAVF_PRIV_FLAG(_name, _flag, _read_only) { \
.flag_string = _name, \
.flag = _flag, \
.read_only = _read_only, \
}
static const struct iavf_priv_flags iavf_gstrings_priv_flags[] = {
IAVF_PRIV_FLAG("legacy-rx", IAVF_FLAG_LEGACY_RX, 0),
};
#define IAVF_PRIV_FLAGS_STR_LEN ARRAY_SIZE(iavf_gstrings_priv_flags)
/**
* iavf_get_link_ksettings - Get Link Speed and Duplex settings
* @netdev: network interface device structure
* @cmd: ethtool command
*
* Reports speed/duplex settings. Because this is a VF, we don't know what
* kind of link we really have, so we fake it.
**/
static int iavf_get_link_ksettings(struct net_device *netdev,
struct ethtool_link_ksettings *cmd)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
ethtool_link_ksettings_zero_link_mode(cmd, supported);
cmd->base.autoneg = AUTONEG_DISABLE;
cmd->base.port = PORT_NONE;
cmd->base.duplex = DUPLEX_FULL;
if (ADV_LINK_SUPPORT(adapter)) {
if (adapter->link_speed_mbps &&
adapter->link_speed_mbps < U32_MAX)
cmd->base.speed = adapter->link_speed_mbps;
else
cmd->base.speed = SPEED_UNKNOWN;
return 0;
}
switch (adapter->link_speed) {
case VIRTCHNL_LINK_SPEED_40GB:
cmd->base.speed = SPEED_40000;
break;
case VIRTCHNL_LINK_SPEED_25GB:
cmd->base.speed = SPEED_25000;
break;
case VIRTCHNL_LINK_SPEED_20GB:
cmd->base.speed = SPEED_20000;
break;
case VIRTCHNL_LINK_SPEED_10GB:
cmd->base.speed = SPEED_10000;
break;
case VIRTCHNL_LINK_SPEED_5GB:
cmd->base.speed = SPEED_5000;
break;
case VIRTCHNL_LINK_SPEED_2_5GB:
cmd->base.speed = SPEED_2500;
break;
case VIRTCHNL_LINK_SPEED_1GB:
cmd->base.speed = SPEED_1000;
break;
case VIRTCHNL_LINK_SPEED_100MB:
cmd->base.speed = SPEED_100;
break;
default:
break;
}
return 0;
}
/**
* iavf_get_sset_count - Get length of string set
* @netdev: network interface device structure
* @sset: id of string set
*
* Reports size of various string tables.
**/
static int iavf_get_sset_count(struct net_device *netdev, int sset)
{
if (sset == ETH_SS_STATS)
return IAVF_STATS_LEN +
(IAVF_QUEUE_STATS_LEN * 2 * IAVF_MAX_REQ_QUEUES);
else if (sset == ETH_SS_PRIV_FLAGS)
return IAVF_PRIV_FLAGS_STR_LEN;
else
return -EINVAL;
}
/**
* iavf_get_ethtool_stats - report device statistics
* @netdev: network interface device structure
* @stats: ethtool statistics structure
* @data: pointer to data buffer
*
* All statistics are added to the data buffer as an array of u64.
**/
static void iavf_get_ethtool_stats(struct net_device *netdev,
struct ethtool_stats *stats, u64 *data)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
unsigned int i;
iavf_add_ethtool_stats(&data, adapter, iavf_gstrings_stats);
rcu_read_lock();
for (i = 0; i < IAVF_MAX_REQ_QUEUES; i++) {
struct iavf_ring *ring;
/* Avoid accessing un-allocated queues */
ring = (i < adapter->num_active_queues ?
&adapter->tx_rings[i] : NULL);
iavf_add_queue_stats(&data, ring);
/* Avoid accessing un-allocated queues */
ring = (i < adapter->num_active_queues ?
&adapter->rx_rings[i] : NULL);
iavf_add_queue_stats(&data, ring);
}
rcu_read_unlock();
}
/**
* iavf_get_priv_flag_strings - Get private flag strings
* @netdev: network interface device structure
* @data: buffer for string data
*
* Builds the private flags string table
**/
static void iavf_get_priv_flag_strings(struct net_device *netdev, u8 *data)
{
unsigned int i;
for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++) {
snprintf(data, ETH_GSTRING_LEN, "%s",
iavf_gstrings_priv_flags[i].flag_string);
data += ETH_GSTRING_LEN;
}
}
/**
* iavf_get_stat_strings - Get stat strings
* @netdev: network interface device structure
* @data: buffer for string data
*
* Builds the statistics string table
**/
static void iavf_get_stat_strings(struct net_device *netdev, u8 *data)
{
unsigned int i;
iavf_add_stat_strings(&data, iavf_gstrings_stats);
/* Queues are always allocated in pairs, so we just use num_tx_queues
* for both Tx and Rx queues.
*/
for (i = 0; i < netdev->num_tx_queues; i++) {
iavf_add_stat_strings(&data, iavf_gstrings_queue_stats,
"tx", i);
iavf_add_stat_strings(&data, iavf_gstrings_queue_stats,
"rx", i);
}
}
/**
* iavf_get_strings - Get string set
* @netdev: network interface device structure
* @sset: id of string set
* @data: buffer for string data
*
* Builds string tables for various string sets
**/
static void iavf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
{
switch (sset) {
case ETH_SS_STATS:
iavf_get_stat_strings(netdev, data);
break;
case ETH_SS_PRIV_FLAGS:
iavf_get_priv_flag_strings(netdev, data);
break;
default:
break;
}
}
/**
* iavf_get_priv_flags - report device private flags
* @netdev: network interface device structure
*
* The get string set count and the string set should be matched for each
* flag returned. Add new strings for each flag to the iavf_gstrings_priv_flags
* array.
*
* Returns a u32 bitmap of flags.
**/
static u32 iavf_get_priv_flags(struct net_device *netdev)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
u32 i, ret_flags = 0;
for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++) {
const struct iavf_priv_flags *priv_flags;
priv_flags = &iavf_gstrings_priv_flags[i];
if (priv_flags->flag & adapter->flags)
ret_flags |= BIT(i);
}
return ret_flags;
}
/**
* iavf_set_priv_flags - set private flags
* @netdev: network interface device structure
* @flags: bit flags to be set
**/
static int iavf_set_priv_flags(struct net_device *netdev, u32 flags)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
u32 orig_flags, new_flags, changed_flags;
u32 i;
orig_flags = READ_ONCE(adapter->flags);
new_flags = orig_flags;
for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++) {
const struct iavf_priv_flags *priv_flags;
priv_flags = &iavf_gstrings_priv_flags[i];
if (flags & BIT(i))
new_flags |= priv_flags->flag;
else
new_flags &= ~(priv_flags->flag);
if (priv_flags->read_only &&
((orig_flags ^ new_flags) & ~BIT(i)))
return -EOPNOTSUPP;
}
/* Before we finalize any flag changes, any checks which we need to
* perform to determine if the new flags will be supported should go
* here...
*/
/* Compare and exchange the new flags into place. If we failed, that
* is if cmpxchg returns anything but the old value, this means
* something else must have modified the flags variable since we
* copied it. We'll just punt with an error and log something in the
* message buffer.
*/
if (cmpxchg(&adapter->flags, orig_flags, new_flags) != orig_flags) {
dev_warn(&adapter->pdev->dev,
"Unable to update adapter->flags as it was modified by another thread...\n");
return -EAGAIN;
}
changed_flags = orig_flags ^ new_flags;
/* Process any additional changes needed as a result of flag changes.
* The changed_flags value reflects the list of bits that were changed
* in the code above.
*/
/* issue a reset to force legacy-rx change to take effect */
if (changed_flags & IAVF_FLAG_LEGACY_RX) {
if (netif_running(netdev)) {
adapter->flags |= IAVF_FLAG_RESET_NEEDED;
queue_work(iavf_wq, &adapter->reset_task);
}
}
return 0;
}
/**
* iavf_get_msglevel - Get debug message level
* @netdev: network interface device structure
*
* Returns current debug message level.
**/
static u32 iavf_get_msglevel(struct net_device *netdev)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
return adapter->msg_enable;
}
/**
* iavf_set_msglevel - Set debug message level
* @netdev: network interface device structure
* @data: message level
*
* Set current debug message level. Higher values cause the driver to
* be noisier.
**/
static void iavf_set_msglevel(struct net_device *netdev, u32 data)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
if (IAVF_DEBUG_USER & data)
adapter->hw.debug_mask = data;
adapter->msg_enable = data;
}
/**
* iavf_get_drvinfo - Get driver info
* @netdev: network interface device structure
* @drvinfo: ethool driver info structure
*
* Returns information about the driver and device for display to the user.
**/
static void iavf_get_drvinfo(struct net_device *netdev,
struct ethtool_drvinfo *drvinfo)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
strlcpy(drvinfo->driver, iavf_driver_name, 32);
strlcpy(drvinfo->fw_version, "N/A", 4);
strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
drvinfo->n_priv_flags = IAVF_PRIV_FLAGS_STR_LEN;
}
/**
* iavf_get_ringparam - Get ring parameters
* @netdev: network interface device structure
* @ring: ethtool ringparam structure
*
* Returns current ring parameters. TX and RX rings are reported separately,
* but the number of rings is not reported.
**/
static void iavf_get_ringparam(struct net_device *netdev,
struct ethtool_ringparam *ring)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
ring->rx_max_pending = IAVF_MAX_RXD;
ring->tx_max_pending = IAVF_MAX_TXD;
ring->rx_pending = adapter->rx_desc_count;
ring->tx_pending = adapter->tx_desc_count;
}
/**
* iavf_set_ringparam - Set ring parameters
* @netdev: network interface device structure
* @ring: ethtool ringparam structure
*
* Sets ring parameters. TX and RX rings are controlled separately, but the
* number of rings is not specified, so all rings get the same settings.
**/
static int iavf_set_ringparam(struct net_device *netdev,
struct ethtool_ringparam *ring)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
u32 new_rx_count, new_tx_count;
if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
return -EINVAL;
new_tx_count = clamp_t(u32, ring->tx_pending,
IAVF_MIN_TXD,
IAVF_MAX_TXD);
new_tx_count = ALIGN(new_tx_count, IAVF_REQ_DESCRIPTOR_MULTIPLE);
new_rx_count = clamp_t(u32, ring->rx_pending,
IAVF_MIN_RXD,
IAVF_MAX_RXD);
new_rx_count = ALIGN(new_rx_count, IAVF_REQ_DESCRIPTOR_MULTIPLE);
/* if nothing to do return success */
if ((new_tx_count == adapter->tx_desc_count) &&
(new_rx_count == adapter->rx_desc_count))
return 0;
adapter->tx_desc_count = new_tx_count;
adapter->rx_desc_count = new_rx_count;
if (netif_running(netdev)) {
adapter->flags |= IAVF_FLAG_RESET_NEEDED;
queue_work(iavf_wq, &adapter->reset_task);
}
return 0;
}
/**
* __iavf_get_coalesce - get per-queue coalesce settings
* @netdev: the netdev to check
* @ec: ethtool coalesce data structure
* @queue: which queue to pick
*
* Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
* are per queue. If queue is <0 then we default to queue 0 as the
* representative value.
**/
static int __iavf_get_coalesce(struct net_device *netdev,
struct ethtool_coalesce *ec, int queue)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
struct iavf_vsi *vsi = &adapter->vsi;
struct iavf_ring *rx_ring, *tx_ring;
ec->tx_max_coalesced_frames = vsi->work_limit;
ec->rx_max_coalesced_frames = vsi->work_limit;
/* Rx and Tx usecs per queue value. If user doesn't specify the
* queue, return queue 0's value to represent.
*/
if (queue < 0)
queue = 0;
else if (queue >= adapter->num_active_queues)
return -EINVAL;
rx_ring = &adapter->rx_rings[queue];
tx_ring = &adapter->tx_rings[queue];
if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
ec->use_adaptive_rx_coalesce = 1;
if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
ec->use_adaptive_tx_coalesce = 1;
ec->rx_coalesce_usecs = rx_ring->itr_setting & ~IAVF_ITR_DYNAMIC;
ec->tx_coalesce_usecs = tx_ring->itr_setting & ~IAVF_ITR_DYNAMIC;
return 0;
}
/**
* iavf_get_coalesce - Get interrupt coalescing settings
* @netdev: network interface device structure
* @ec: ethtool coalesce structure
*
* Returns current coalescing settings. This is referred to elsewhere in the
* driver as Interrupt Throttle Rate, as this is how the hardware describes
* this functionality. Note that if per-queue settings have been modified this
* only represents the settings of queue 0.
**/
static int iavf_get_coalesce(struct net_device *netdev,
struct ethtool_coalesce *ec)
{
return __iavf_get_coalesce(netdev, ec, -1);
}
/**
* iavf_get_per_queue_coalesce - get coalesce values for specific queue
* @netdev: netdev to read
* @ec: coalesce settings from ethtool
* @queue: the queue to read
*
* Read specific queue's coalesce settings.
**/
static int iavf_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
struct ethtool_coalesce *ec)
{
return __iavf_get_coalesce(netdev, ec, queue);
}
/**
* iavf_set_itr_per_queue - set ITR values for specific queue
* @adapter: the VF adapter struct to set values for
* @ec: coalesce settings from ethtool
* @queue: the queue to modify
*
* Change the ITR settings for a specific queue.
**/
static void iavf_set_itr_per_queue(struct iavf_adapter *adapter,
struct ethtool_coalesce *ec, int queue)
{
struct iavf_ring *rx_ring = &adapter->rx_rings[queue];
struct iavf_ring *tx_ring = &adapter->tx_rings[queue];
struct iavf_q_vector *q_vector;
rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
rx_ring->itr_setting |= IAVF_ITR_DYNAMIC;
if (!ec->use_adaptive_rx_coalesce)
rx_ring->itr_setting ^= IAVF_ITR_DYNAMIC;
tx_ring->itr_setting |= IAVF_ITR_DYNAMIC;
if (!ec->use_adaptive_tx_coalesce)
tx_ring->itr_setting ^= IAVF_ITR_DYNAMIC;
q_vector = rx_ring->q_vector;
q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
q_vector = tx_ring->q_vector;
q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
/* The interrupt handler itself will take care of programming
* the Tx and Rx ITR values based on the values we have entered
* into the q_vector, no need to write the values now.
*/
}
/**
* __iavf_set_coalesce - set coalesce settings for particular queue
* @netdev: the netdev to change
* @ec: ethtool coalesce settings
* @queue: the queue to change
*
* Sets the coalesce settings for a particular queue.
**/
static int __iavf_set_coalesce(struct net_device *netdev,
struct ethtool_coalesce *ec, int queue)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
struct iavf_vsi *vsi = &adapter->vsi;
int i;
if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
vsi->work_limit = ec->tx_max_coalesced_frames_irq;
if (ec->rx_coalesce_usecs == 0) {
if (ec->use_adaptive_rx_coalesce)
netif_info(adapter, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
} else if ((ec->rx_coalesce_usecs < IAVF_MIN_ITR) ||
(ec->rx_coalesce_usecs > IAVF_MAX_ITR)) {
netif_info(adapter, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
return -EINVAL;
} else if (ec->tx_coalesce_usecs == 0) {
if (ec->use_adaptive_tx_coalesce)
netif_info(adapter, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
} else if ((ec->tx_coalesce_usecs < IAVF_MIN_ITR) ||
(ec->tx_coalesce_usecs > IAVF_MAX_ITR)) {
netif_info(adapter, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
return -EINVAL;
}
/* Rx and Tx usecs has per queue value. If user doesn't specify the
* queue, apply to all queues.
*/
if (queue < 0) {
for (i = 0; i < adapter->num_active_queues; i++)
iavf_set_itr_per_queue(adapter, ec, i);
} else if (queue < adapter->num_active_queues) {
iavf_set_itr_per_queue(adapter, ec, queue);
} else {
netif_info(adapter, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
adapter->num_active_queues - 1);
return -EINVAL;
}
return 0;
}
/**
* iavf_set_coalesce - Set interrupt coalescing settings
* @netdev: network interface device structure
* @ec: ethtool coalesce structure
*
* Change current coalescing settings for every queue.
**/
static int iavf_set_coalesce(struct net_device *netdev,
struct ethtool_coalesce *ec)
{
return __iavf_set_coalesce(netdev, ec, -1);
}
/**
* iavf_set_per_queue_coalesce - set specific queue's coalesce settings
* @netdev: the netdev to change
* @ec: ethtool's coalesce settings
* @queue: the queue to modify
*
* Modifies a specific queue's coalesce settings.
*/
static int iavf_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
struct ethtool_coalesce *ec)
{
return __iavf_set_coalesce(netdev, ec, queue);
}
/**
* iavf_get_rxnfc - command to get RX flow classification rules
* @netdev: network interface device structure
* @cmd: ethtool rxnfc command
* @rule_locs: pointer to store rule locations
*
* Returns Success if the command is supported.
**/
static int iavf_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
u32 *rule_locs)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
int ret = -EOPNOTSUPP;
switch (cmd->cmd) {
case ETHTOOL_GRXRINGS:
cmd->data = adapter->num_active_queues;
ret = 0;
break;
case ETHTOOL_GRXFH:
netdev_info(netdev,
"RSS hash info is not available to vf, use pf.\n");
break;
default:
break;
}
return ret;
}
/**
* iavf_get_channels: get the number of channels supported by the device
* @netdev: network interface device structure
* @ch: channel information structure
*
* For the purposes of our device, we only use combined channels, i.e. a tx/rx
* queue pair. Report one extra channel to match our "other" MSI-X vector.
**/
static void iavf_get_channels(struct net_device *netdev,
struct ethtool_channels *ch)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
/* Report maximum channels */
ch->max_combined = adapter->vsi_res->num_queue_pairs;
ch->max_other = NONQ_VECS;
ch->other_count = NONQ_VECS;
ch->combined_count = adapter->num_active_queues;
}
/**
* iavf_set_channels: set the new channel count
* @netdev: network interface device structure
* @ch: channel information structure
*
* Negotiate a new number of channels with the PF then do a reset. During
* reset we'll realloc queues and fix the RSS table. Returns 0 on success,
* negative on failure.
**/
static int iavf_set_channels(struct net_device *netdev,
struct ethtool_channels *ch)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
u32 num_req = ch->combined_count;
if ((adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_ADQ) &&
adapter->num_tc) {
dev_info(&adapter->pdev->dev, "Cannot set channels since ADq is enabled.\n");
return -EINVAL;
}
/* All of these should have already been checked by ethtool before this
* even gets to us, but just to be sure.
*/
if (num_req > adapter->vsi_res->num_queue_pairs)
return -EINVAL;
if (num_req == adapter->num_active_queues)
return 0;
if (ch->rx_count || ch->tx_count || ch->other_count != NONQ_VECS)
return -EINVAL;
adapter->num_req_queues = num_req;
adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
iavf_schedule_reset(adapter);
return 0;
}
/**
* iavf_get_rxfh_key_size - get the RSS hash key size
* @netdev: network interface device structure
*
* Returns the table size.
**/
static u32 iavf_get_rxfh_key_size(struct net_device *netdev)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
return adapter->rss_key_size;
}
/**
* iavf_get_rxfh_indir_size - get the rx flow hash indirection table size
* @netdev: network interface device structure
*
* Returns the table size.
**/
static u32 iavf_get_rxfh_indir_size(struct net_device *netdev)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
return adapter->rss_lut_size;
}
/**
* iavf_get_rxfh - get the rx flow hash indirection table
* @netdev: network interface device structure
* @indir: indirection table
* @key: hash key
* @hfunc: hash function in use
*
* Reads the indirection table directly from the hardware. Always returns 0.
**/
static int iavf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
u8 *hfunc)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
u16 i;
if (hfunc)
*hfunc = ETH_RSS_HASH_TOP;
if (!indir)
return 0;
memcpy(key, adapter->rss_key, adapter->rss_key_size);
/* Each 32 bits pointed by 'indir' is stored with a lut entry */
for (i = 0; i < adapter->rss_lut_size; i++)
indir[i] = (u32)adapter->rss_lut[i];
return 0;
}
/**
* iavf_set_rxfh - set the rx flow hash indirection table
* @netdev: network interface device structure
* @indir: indirection table
* @key: hash key
* @hfunc: hash function to use
*
* Returns -EINVAL if the table specifies an inavlid queue id, otherwise
* returns 0 after programming the table.
**/
static int iavf_set_rxfh(struct net_device *netdev, const u32 *indir,
const u8 *key, const u8 hfunc)
{
struct iavf_adapter *adapter = netdev_priv(netdev);
u16 i;
/* We do not allow change in unsupported parameters */
if (key ||
(hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
return -EOPNOTSUPP;
if (!indir)
return 0;
if (key)
memcpy(adapter->rss_key, key, adapter->rss_key_size);
/* Each 32 bits pointed by 'indir' is stored with a lut entry */
for (i = 0; i < adapter->rss_lut_size; i++)
adapter->rss_lut[i] = (u8)(indir[i]);
return iavf_config_rss(adapter);
}
static const struct ethtool_ops iavf_ethtool_ops = {
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
ETHTOOL_COALESCE_MAX_FRAMES |
ETHTOOL_COALESCE_MAX_FRAMES_IRQ |
ETHTOOL_COALESCE_USE_ADAPTIVE,
.get_drvinfo = iavf_get_drvinfo,
.get_link = ethtool_op_get_link,
.get_ringparam = iavf_get_ringparam,
.set_ringparam = iavf_set_ringparam,
.get_strings = iavf_get_strings,
.get_ethtool_stats = iavf_get_ethtool_stats,
.get_sset_count = iavf_get_sset_count,
.get_priv_flags = iavf_get_priv_flags,
.set_priv_flags = iavf_set_priv_flags,
.get_msglevel = iavf_get_msglevel,
.set_msglevel = iavf_set_msglevel,
.get_coalesce = iavf_get_coalesce,
.set_coalesce = iavf_set_coalesce,
.get_per_queue_coalesce = iavf_get_per_queue_coalesce,
.set_per_queue_coalesce = iavf_set_per_queue_coalesce,
.get_rxnfc = iavf_get_rxnfc,
.get_rxfh_indir_size = iavf_get_rxfh_indir_size,
.get_rxfh = iavf_get_rxfh,
.set_rxfh = iavf_set_rxfh,
.get_channels = iavf_get_channels,
.set_channels = iavf_set_channels,
.get_rxfh_key_size = iavf_get_rxfh_key_size,
.get_link_ksettings = iavf_get_link_ksettings,
};
/**
* iavf_set_ethtool_ops - Initialize ethtool ops struct
* @netdev: network interface device structure
*
* Sets ethtool ops struct in our netdev so that ethtool can call
* our functions.
**/
void iavf_set_ethtool_ops(struct net_device *netdev)
{
netdev->ethtool_ops = &iavf_ethtool_ops;
}
| GuillaumeSeren/linux | drivers/net/ethernet/intel/iavf/iavf_ethtool.c | C | gpl-2.0 | 31,144 |
public class Foo {
public void foo(boolean a, int x,
int y, int z) {
label1:
do {
try {
if (x > 0) {
int someVariable = a ?
x :
y;
}
else if (x < 0) {
int someVariable = (y +
z
);
someVariable = x =
x +
y;
}
else {
label2:
for (int i = 0;
i < 5;
i++)
doSomething(i);
}
switch (a) {
case 0:
doCase0();
break;
default:
doDefault();
}
}
catch (Exception e) {
processException(e.getMessage(),
x + y, z, a);
}
finally {
processFinally();
}
}
while (true);
if (2 < 3) return;
if (3 < 4)
return;
do x++ while (x < 10000);
while (x < 50000) x++;
for (int i = 0; i < 5; i++) System.out.println(i);
}
private class InnerClass implements I1,
I2 {
public void bar() throws E1,
E2 {
}
}
} | liveqmock/platform-tools-idea | java/java-tests/testData/psi/formatter/java/IfElse.java | Java | apache-2.0 | 1,720 |
# Copyright (c) 2007, Robert Coup <robert.coup@onetrackmind.co.nz>
# 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. Neither the name of Distance 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.
#
"""
Distance and Area objects to allow for sensible and convenient calculation
and conversions.
Authors: Robert Coup, Justin Bronn, Riccardo Di Virgilio
Inspired by GeoPy (http://exogen.case.edu/projects/geopy/)
and Geoff Biggs' PhD work on dimensioned units for robotics.
"""
__all__ = ['A', 'Area', 'D', 'Distance']
from decimal import Decimal
from functools import total_ordering
from django.utils import six
NUMERIC_TYPES = six.integer_types + (float, Decimal)
AREA_PREFIX = "sq_"
def pretty_name(obj):
return obj.__name__ if obj.__class__ == type else obj.__class__.__name__
@total_ordering
class MeasureBase(object):
STANDARD_UNIT = None
ALIAS = {}
UNITS = {}
LALIAS = {}
def __init__(self, default_unit=None, **kwargs):
value, self._default_unit = self.default_units(kwargs)
setattr(self, self.STANDARD_UNIT, value)
if default_unit and isinstance(default_unit, six.string_types):
self._default_unit = default_unit
def _get_standard(self):
return getattr(self, self.STANDARD_UNIT)
def _set_standard(self, value):
setattr(self, self.STANDARD_UNIT, value)
standard = property(_get_standard, _set_standard)
def __getattr__(self, name):
if name in self.UNITS:
return self.standard / self.UNITS[name]
else:
raise AttributeError('Unknown unit type: %s' % name)
def __repr__(self):
return '%s(%s=%s)' % (pretty_name(self), self._default_unit,
getattr(self, self._default_unit))
def __str__(self):
return '%s %s' % (getattr(self, self._default_unit), self._default_unit)
# **** Comparison methods ****
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.standard == other.standard
else:
return NotImplemented
def __lt__(self, other):
if isinstance(other, self.__class__):
return self.standard < other.standard
else:
return NotImplemented
# **** Operators methods ****
def __add__(self, other):
if isinstance(other, self.__class__):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard + other.standard)})
else:
raise TypeError('%(class)s must be added with %(class)s' % {"class": pretty_name(self)})
def __iadd__(self, other):
if isinstance(other, self.__class__):
self.standard += other.standard
return self
else:
raise TypeError('%(class)s must be added with %(class)s' % {"class": pretty_name(self)})
def __sub__(self, other):
if isinstance(other, self.__class__):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard - other.standard)})
else:
raise TypeError('%(class)s must be subtracted from %(class)s' % {"class": pretty_name(self)})
def __isub__(self, other):
if isinstance(other, self.__class__):
self.standard -= other.standard
return self
else:
raise TypeError('%(class)s must be subtracted from %(class)s' % {"class": pretty_name(self)})
def __mul__(self, other):
if isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard * other)})
else:
raise TypeError('%(class)s must be multiplied with number' % {"class": pretty_name(self)})
def __imul__(self, other):
if isinstance(other, NUMERIC_TYPES):
self.standard *= float(other)
return self
else:
raise TypeError('%(class)s must be multiplied with number' % {"class": pretty_name(self)})
def __rmul__(self, other):
return self * other
def __truediv__(self, other):
if isinstance(other, self.__class__):
return self.standard / other.standard
if isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard / other)})
else:
raise TypeError('%(class)s must be divided with number or %(class)s' % {"class": pretty_name(self)})
def __div__(self, other): # Python 2 compatibility
return type(self).__truediv__(self, other)
def __itruediv__(self, other):
if isinstance(other, NUMERIC_TYPES):
self.standard /= float(other)
return self
else:
raise TypeError('%(class)s must be divided with number' % {"class": pretty_name(self)})
def __idiv__(self, other): # Python 2 compatibility
return type(self).__itruediv__(self, other)
def __bool__(self):
return bool(self.standard)
def __nonzero__(self): # Python 2 compatibility
return type(self).__bool__(self)
def default_units(self, kwargs):
"""
Return the unit value and the default units specified
from the given keyword arguments dictionary.
"""
val = 0.0
default_unit = self.STANDARD_UNIT
for unit, value in six.iteritems(kwargs):
if not isinstance(value, float):
value = float(value)
if unit in self.UNITS:
val += self.UNITS[unit] * value
default_unit = unit
elif unit in self.ALIAS:
u = self.ALIAS[unit]
val += self.UNITS[u] * value
default_unit = u
else:
lower = unit.lower()
if lower in self.UNITS:
val += self.UNITS[lower] * value
default_unit = lower
elif lower in self.LALIAS:
u = self.LALIAS[lower]
val += self.UNITS[u] * value
default_unit = u
else:
raise AttributeError('Unknown unit type: %s' % unit)
return val, default_unit
@classmethod
def unit_attname(cls, unit_str):
"""
Retrieves the unit attribute name for the given unit string.
For example, if the given unit string is 'metre', 'm' would be returned.
An exception is raised if an attribute cannot be found.
"""
lower = unit_str.lower()
if unit_str in cls.UNITS:
return unit_str
elif lower in cls.UNITS:
return lower
elif lower in cls.LALIAS:
return cls.LALIAS[lower]
else:
raise Exception('Could not find a unit keyword associated with "%s"' % unit_str)
class Distance(MeasureBase):
STANDARD_UNIT = "m"
UNITS = {
'chain': 20.1168,
'chain_benoit': 20.116782,
'chain_sears': 20.1167645,
'british_chain_benoit': 20.1167824944,
'british_chain_sears': 20.1167651216,
'british_chain_sears_truncated': 20.116756,
'cm': 0.01,
'british_ft': 0.304799471539,
'british_yd': 0.914398414616,
'clarke_ft': 0.3047972654,
'clarke_link': 0.201166195164,
'fathom': 1.8288,
'ft': 0.3048,
'german_m': 1.0000135965,
'gold_coast_ft': 0.304799710181508,
'indian_yd': 0.914398530744,
'inch': 0.0254,
'km': 1000.0,
'link': 0.201168,
'link_benoit': 0.20116782,
'link_sears': 0.20116765,
'm': 1.0,
'mi': 1609.344,
'mm': 0.001,
'nm': 1852.0,
'nm_uk': 1853.184,
'rod': 5.0292,
'sears_yd': 0.91439841,
'survey_ft': 0.304800609601,
'um': 0.000001,
'yd': 0.9144,
}
# Unit aliases for `UNIT` terms encountered in Spatial Reference WKT.
ALIAS = {
'centimeter': 'cm',
'foot': 'ft',
'inches': 'inch',
'kilometer': 'km',
'kilometre': 'km',
'meter': 'm',
'metre': 'm',
'micrometer': 'um',
'micrometre': 'um',
'millimeter': 'mm',
'millimetre': 'mm',
'mile': 'mi',
'yard': 'yd',
'British chain (Benoit 1895 B)': 'british_chain_benoit',
'British chain (Sears 1922)': 'british_chain_sears',
'British chain (Sears 1922 truncated)': 'british_chain_sears_truncated',
'British foot (Sears 1922)': 'british_ft',
'British foot': 'british_ft',
'British yard (Sears 1922)': 'british_yd',
'British yard': 'british_yd',
"Clarke's Foot": 'clarke_ft',
"Clarke's link": 'clarke_link',
'Chain (Benoit)': 'chain_benoit',
'Chain (Sears)': 'chain_sears',
'Foot (International)': 'ft',
'German legal metre': 'german_m',
'Gold Coast foot': 'gold_coast_ft',
'Indian yard': 'indian_yd',
'Link (Benoit)': 'link_benoit',
'Link (Sears)': 'link_sears',
'Nautical Mile': 'nm',
'Nautical Mile (UK)': 'nm_uk',
'US survey foot': 'survey_ft',
'U.S. Foot': 'survey_ft',
'Yard (Indian)': 'indian_yd',
'Yard (Sears)': 'sears_yd'
}
LALIAS = {k.lower(): v for k, v in ALIAS.items()}
def __mul__(self, other):
if isinstance(other, self.__class__):
return Area(default_unit=AREA_PREFIX + self._default_unit,
**{AREA_PREFIX + self.STANDARD_UNIT: (self.standard * other.standard)})
elif isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard * other)})
else:
raise TypeError('%(distance)s must be multiplied with number or %(distance)s' % {
"distance": pretty_name(self.__class__),
})
class Area(MeasureBase):
STANDARD_UNIT = AREA_PREFIX + Distance.STANDARD_UNIT
# Getting the square units values and the alias dictionary.
UNITS = {'%s%s' % (AREA_PREFIX, k): v ** 2 for k, v in Distance.UNITS.items()}
ALIAS = {k: '%s%s' % (AREA_PREFIX, v) for k, v in Distance.ALIAS.items()}
LALIAS = {k.lower(): v for k, v in ALIAS.items()}
def __truediv__(self, other):
if isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard / other)})
else:
raise TypeError('%(class)s must be divided by a number' % {"class": pretty_name(self)})
def __div__(self, other): # Python 2 compatibility
return type(self).__truediv__(self, other)
# Shortcuts
D = Distance
A = Area
| Vvucinic/Wander | venv_2_7/lib/python2.7/site-packages/Django-1.9-py2.7.egg/django/contrib/gis/measure.py | Python | artistic-2.0 | 12,272 |
/*
* linux/kernel/printk.c
*
* Copyright (C) 1991, 1992 Linus Torvalds
*
* Modified to make sys_syslog() more flexible: added commands to
* return the last 4k of kernel messages, regardless of whether
* they've been read or not. Added option to suppress kernel printk's
* to the console. Added hook for sending the console messages
* elsewhere, in preparation for a serial line console (someday).
* Ted Ts'o, 2/11/93.
* Modified for sysctl support, 1/8/97, Chris Horn.
* Fixed SMP synchronization, 08/08/99, Manfred Spraul
* manfred@colorfullife.com
* Rewrote bits to get rid of console_lock
* 01Mar01 Andrew Morton
*/
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/console.h>
#include <linux/init.h>
#include <linux/jiffies.h>
#include <linux/nmi.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/interrupt.h> /* For in_interrupt() */
#include <linux/delay.h>
#include <linux/smp.h>
#include <linux/security.h>
#include <linux/bootmem.h>
#include <linux/memblock.h>
#include <linux/syscalls.h>
#include <linux/kexec.h>
#include <linux/kdb.h>
#include <linux/ratelimit.h>
#include <linux/kmsg_dump.h>
#include <linux/syslog.h>
#include <linux/cpu.h>
#include <linux/notifier.h>
#include <linux/rculist.h>
#include <asm/uaccess.h>
#include <mach/msm_rtb.h>
#define CREATE_TRACE_POINTS
#include <trace/events/printk.h>
/*
* Architectures can override it:
*/
void asmlinkage __attribute__((weak)) early_printk(const char *fmt, ...)
{
}
#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
/* printk's without a loglevel use this.. */
#define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL
/* We show everything that is MORE important than this.. */
#define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */
#define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */
DECLARE_WAIT_QUEUE_HEAD(log_wait);
int console_printk[4] = {
DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */
DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */
MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */
DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */
};
/*
* Low level drivers may need that to know if they can schedule in
* their unblank() callback or not. So let's export it.
*/
int oops_in_progress;
EXPORT_SYMBOL(oops_in_progress);
/*
* console_sem protects the console_drivers list, and also
* provides serialisation for access to the entire console
* driver system.
*/
static DEFINE_SEMAPHORE(console_sem);
struct console *console_drivers;
EXPORT_SYMBOL_GPL(console_drivers);
/*
* This is used for debugging the mess that is the VT code by
* keeping track if we have the console semaphore held. It's
* definitely not the perfect debug tool (we don't know if _WE_
* hold it are racing, but it helps tracking those weird code
* path in the console code where we end up in places I want
* locked without the console sempahore held
*/
static int console_locked, console_suspended;
/*
* logbuf_lock protects log_buf, log_start, log_end, con_start and logged_chars
* It is also used in interesting ways to provide interlocking in
* console_unlock();.
*/
static DEFINE_RAW_SPINLOCK(logbuf_lock);
#define LOG_BUF_MASK (log_buf_len-1)
#define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK])
/*
* The indices into log_buf are not constrained to log_buf_len - they
* must be masked before subscripting
*/
static unsigned log_start; /* Index into log_buf: next char to be read by syslog() */
static unsigned con_start; /* Index into log_buf: next char to be sent to consoles */
static unsigned log_end; /* Index into log_buf: most-recently-written-char + 1 */
/*
* If exclusive_console is non-NULL then only this console is to be printed to.
*/
static struct console *exclusive_console;
/*
* Array of consoles built from command line options (console=)
*/
struct console_cmdline
{
char name[8]; /* Name of the driver */
int index; /* Minor dev. to use */
char *options; /* Options for the driver */
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
char *brl_options; /* Options for braille driver */
#endif
};
#define MAX_CMDLINECONSOLES 8
static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
static int selected_console = -1;
static int preferred_console = -1;
int console_set_on_cmdline;
EXPORT_SYMBOL(console_set_on_cmdline);
/* Flag: console code may call schedule() */
static int console_may_schedule;
#ifdef CONFIG_PRINTK
static char __log_buf[__LOG_BUF_LEN];
static char *log_buf = __log_buf;
static int log_buf_len = __LOG_BUF_LEN;
static unsigned logged_chars; /* Number of chars produced since last read+clear operation */
static int saved_console_loglevel = -1;
#ifdef CONFIG_KEXEC
/*
* This appends the listed symbols to /proc/vmcoreinfo
*
* /proc/vmcoreinfo is used by various utiilties, like crash and makedumpfile to
* obtain access to symbols that are otherwise very difficult to locate. These
* symbols are specifically used so that utilities can access and extract the
* dmesg log from a vmcore file after a crash.
*/
void log_buf_kexec_setup(void)
{
VMCOREINFO_SYMBOL(log_buf);
VMCOREINFO_SYMBOL(log_end);
VMCOREINFO_SYMBOL(log_buf_len);
VMCOREINFO_SYMBOL(logged_chars);
}
#endif
/* requested log_buf_len from kernel cmdline */
static unsigned long __initdata new_log_buf_len;
/* save requested log_buf_len since it's too early to process it */
static int __init log_buf_len_setup(char *str)
{
unsigned size = memparse(str, &str);
if (size)
size = roundup_pow_of_two(size);
if (size > log_buf_len)
new_log_buf_len = size;
return 0;
}
early_param("log_buf_len", log_buf_len_setup);
void __init setup_log_buf(int early)
{
unsigned long flags;
unsigned start, dest_idx, offset;
char *new_log_buf;
int free;
if (!new_log_buf_len)
return;
if (early) {
unsigned long mem;
mem = memblock_alloc(new_log_buf_len, PAGE_SIZE);
if (!mem)
return;
new_log_buf = __va(mem);
} else {
new_log_buf = alloc_bootmem_nopanic(new_log_buf_len);
}
if (unlikely(!new_log_buf)) {
pr_err("log_buf_len: %ld bytes not available\n",
new_log_buf_len);
return;
}
raw_spin_lock_irqsave(&logbuf_lock, flags);
log_buf_len = new_log_buf_len;
log_buf = new_log_buf;
new_log_buf_len = 0;
free = __LOG_BUF_LEN - log_end;
offset = start = min(con_start, log_start);
dest_idx = 0;
while (start != log_end) {
unsigned log_idx_mask = start & (__LOG_BUF_LEN - 1);
log_buf[dest_idx] = __log_buf[log_idx_mask];
start++;
dest_idx++;
}
log_start -= offset;
con_start -= offset;
log_end -= offset;
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
pr_info("log_buf_len: %d\n", log_buf_len);
pr_info("early log buf free: %d(%d%%)\n",
free, (free * 100) / __LOG_BUF_LEN);
}
#ifdef CONFIG_BOOT_PRINTK_DELAY
static int boot_delay; /* msecs delay after each printk during bootup */
static unsigned long long loops_per_msec; /* based on boot_delay */
static int __init boot_delay_setup(char *str)
{
unsigned long lpj;
lpj = preset_lpj ? preset_lpj : 1000000; /* some guess */
loops_per_msec = (unsigned long long)lpj / 1000 * HZ;
get_option(&str, &boot_delay);
if (boot_delay > 10 * 1000)
boot_delay = 0;
pr_debug("boot_delay: %u, preset_lpj: %ld, lpj: %lu, "
"HZ: %d, loops_per_msec: %llu\n",
boot_delay, preset_lpj, lpj, HZ, loops_per_msec);
return 1;
}
__setup("boot_delay=", boot_delay_setup);
static void boot_delay_msec(void)
{
unsigned long long k;
unsigned long timeout;
if (boot_delay == 0 || system_state != SYSTEM_BOOTING)
return;
k = (unsigned long long)loops_per_msec * boot_delay;
timeout = jiffies + msecs_to_jiffies(boot_delay);
while (k) {
k--;
cpu_relax();
/*
* use (volatile) jiffies to prevent
* compiler reduction; loop termination via jiffies
* is secondary and may or may not happen.
*/
if (time_after(jiffies, timeout))
break;
touch_nmi_watchdog();
}
}
#else
static inline void boot_delay_msec(void)
{
}
#endif
/*
* Return the number of unread characters in the log buffer.
*/
static int log_buf_get_len(void)
{
return logged_chars;
}
/*
* Clears the ring-buffer
*/
void log_buf_clear(void)
{
logged_chars = 0;
}
/*
* Copy a range of characters from the log buffer.
*/
int log_buf_copy(char *dest, int idx, int len)
{
int ret, max;
bool took_lock = false;
if (!oops_in_progress) {
raw_spin_lock_irq(&logbuf_lock);
took_lock = true;
}
max = log_buf_get_len();
if (idx < 0 || idx >= max) {
ret = -1;
} else {
if (len > max - idx)
len = max - idx;
ret = len;
idx += (log_end - max);
while (len-- > 0)
dest[len] = LOG_BUF(idx + len);
}
if (took_lock)
raw_spin_unlock_irq(&logbuf_lock);
return ret;
}
#ifdef CONFIG_SECURITY_DMESG_RESTRICT
int dmesg_restrict = 1;
#else
int dmesg_restrict;
#endif
static int syslog_action_restricted(int type)
{
if (dmesg_restrict)
return 1;
/* Unless restricted, we allow "read all" and "get buffer size" for everybody */
return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
}
static int check_syslog_permissions(int type, bool from_file)
{
/*
* If this is from /proc/kmsg and we've already opened it, then we've
* already done the capabilities checks at open time.
*/
if (from_file && type != SYSLOG_ACTION_OPEN)
return 0;
if (syslog_action_restricted(type)) {
if (capable(CAP_SYSLOG))
return 0;
/* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
if (capable(CAP_SYS_ADMIN)) {
printk_once(KERN_WARNING "%s (%d): "
"Attempt to access syslog with CAP_SYS_ADMIN "
"but no CAP_SYSLOG (deprecated).\n",
current->comm, task_pid_nr(current));
return 0;
}
return -EPERM;
}
return 0;
}
int do_syslog(int type, char __user *buf, int len, bool from_file)
{
unsigned i, j, limit, count;
int do_clear = 0;
char c;
int error;
error = check_syslog_permissions(type, from_file);
if (error)
goto out;
error = security_syslog(type);
if (error)
return error;
switch (type) {
case SYSLOG_ACTION_CLOSE: /* Close log */
break;
case SYSLOG_ACTION_OPEN: /* Open log */
break;
case SYSLOG_ACTION_READ: /* Read from log */
error = -EINVAL;
if (!buf || len < 0)
goto out;
error = 0;
if (!len)
goto out;
if (!access_ok(VERIFY_WRITE, buf, len)) {
error = -EFAULT;
goto out;
}
error = wait_event_interruptible(log_wait,
(log_start - log_end));
if (error)
goto out;
i = 0;
raw_spin_lock_irq(&logbuf_lock);
while (!error && (log_start != log_end) && i < len) {
c = LOG_BUF(log_start);
log_start++;
raw_spin_unlock_irq(&logbuf_lock);
error = __put_user(c,buf);
buf++;
i++;
cond_resched();
raw_spin_lock_irq(&logbuf_lock);
}
raw_spin_unlock_irq(&logbuf_lock);
if (!error)
error = i;
break;
/* Read/clear last kernel messages */
case SYSLOG_ACTION_READ_CLEAR:
do_clear = 1;
/* FALL THRU */
/* Read last kernel messages */
case SYSLOG_ACTION_READ_ALL:
error = -EINVAL;
if (!buf || len < 0)
goto out;
error = 0;
if (!len)
goto out;
if (!access_ok(VERIFY_WRITE, buf, len)) {
error = -EFAULT;
goto out;
}
count = len;
if (count > log_buf_len)
count = log_buf_len;
raw_spin_lock_irq(&logbuf_lock);
if (count > logged_chars)
count = logged_chars;
if (do_clear)
logged_chars = 0;
limit = log_end;
/*
* __put_user() could sleep, and while we sleep
* printk() could overwrite the messages
* we try to copy to user space. Therefore
* the messages are copied in reverse. <manfreds>
*/
for (i = 0; i < count && !error; i++) {
j = limit-1-i;
if (j + log_buf_len < log_end)
break;
c = LOG_BUF(j);
raw_spin_unlock_irq(&logbuf_lock);
error = __put_user(c,&buf[count-1-i]);
cond_resched();
raw_spin_lock_irq(&logbuf_lock);
}
raw_spin_unlock_irq(&logbuf_lock);
if (error)
break;
error = i;
if (i != count) {
int offset = count-error;
/* buffer overflow during copy, correct user buffer. */
for (i = 0; i < error; i++) {
if (__get_user(c,&buf[i+offset]) ||
__put_user(c,&buf[i])) {
error = -EFAULT;
break;
}
cond_resched();
}
}
break;
/* Clear ring buffer */
case SYSLOG_ACTION_CLEAR:
logged_chars = 0;
break;
/* Disable logging to console */
case SYSLOG_ACTION_CONSOLE_OFF:
if (saved_console_loglevel == -1)
saved_console_loglevel = console_loglevel;
console_loglevel = minimum_console_loglevel;
break;
/* Enable logging to console */
case SYSLOG_ACTION_CONSOLE_ON:
if (saved_console_loglevel != -1) {
console_loglevel = saved_console_loglevel;
saved_console_loglevel = -1;
}
break;
/* Set level of messages printed to console */
case SYSLOG_ACTION_CONSOLE_LEVEL:
error = -EINVAL;
if (len < 1 || len > 8)
goto out;
if (len < minimum_console_loglevel)
len = minimum_console_loglevel;
console_loglevel = len;
/* Implicitly re-enable logging to console */
saved_console_loglevel = -1;
error = 0;
break;
/* Number of chars in the log buffer */
case SYSLOG_ACTION_SIZE_UNREAD:
error = log_end - log_start;
break;
/* Size of the log buffer */
case SYSLOG_ACTION_SIZE_BUFFER:
error = log_buf_len;
break;
default:
error = -EINVAL;
break;
}
out:
return error;
}
SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
{
return do_syslog(type, buf, len, SYSLOG_FROM_CALL);
}
#ifdef CONFIG_KGDB_KDB
/* kdb dmesg command needs access to the syslog buffer. do_syslog()
* uses locks so it cannot be used during debugging. Just tell kdb
* where the start and end of the physical and logical logs are. This
* is equivalent to do_syslog(3).
*/
void kdb_syslog_data(char *syslog_data[4])
{
syslog_data[0] = log_buf;
syslog_data[1] = log_buf + log_buf_len;
syslog_data[2] = log_buf + log_end -
(logged_chars < log_buf_len ? logged_chars : log_buf_len);
syslog_data[3] = log_buf + log_end;
}
#endif /* CONFIG_KGDB_KDB */
/*
* Call the console drivers on a range of log_buf
*/
static void __call_console_drivers(unsigned start, unsigned end)
{
struct console *con;
for_each_console(con) {
if (exclusive_console && con != exclusive_console)
continue;
if ((con->flags & CON_ENABLED) && con->write &&
(cpu_online(smp_processor_id()) ||
(con->flags & CON_ANYTIME)))
con->write(con, &LOG_BUF(start), end - start);
}
}
static bool __read_mostly ignore_loglevel;
static int __init ignore_loglevel_setup(char *str)
{
ignore_loglevel = 1;
printk(KERN_INFO "debug: ignoring loglevel setting.\n");
return 0;
}
early_param("ignore_loglevel", ignore_loglevel_setup);
module_param(ignore_loglevel, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(ignore_loglevel, "ignore loglevel setting, to"
"print all kernel messages to the console.");
/*
* Write out chars from start to end - 1 inclusive
*/
static void _call_console_drivers(unsigned start,
unsigned end, int msg_log_level)
{
trace_console(&LOG_BUF(0), start, end, log_buf_len);
if ((msg_log_level < console_loglevel || ignore_loglevel) &&
console_drivers && start != end) {
if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) {
/* wrapped write */
__call_console_drivers(start & LOG_BUF_MASK,
log_buf_len);
__call_console_drivers(0, end & LOG_BUF_MASK);
} else {
__call_console_drivers(start, end);
}
}
}
/*
* Parse the syslog header <[0-9]*>. The decimal value represents 32bit, the
* lower 3 bit are the log level, the rest are the log facility. In case
* userspace passes usual userspace syslog messages to /dev/kmsg or
* /dev/ttyprintk, the log prefix might contain the facility. Printk needs
* to extract the correct log level for in-kernel processing, and not mangle
* the original value.
*
* If a prefix is found, the length of the prefix is returned. If 'level' is
* passed, it will be filled in with the log level without a possible facility
* value. If 'special' is passed, the special printk prefix chars are accepted
* and returned. If no valid header is found, 0 is returned and the passed
* variables are not touched.
*/
static size_t log_prefix(const char *p, unsigned int *level, char *special)
{
unsigned int lev = 0;
char sp = '\0';
size_t len;
if (p[0] != '<' || !p[1])
return 0;
if (p[2] == '>') {
/* usual single digit level number or special char */
switch (p[1]) {
case '0' ... '7':
lev = p[1] - '0';
break;
case 'c': /* KERN_CONT */
case 'd': /* KERN_DEFAULT */
sp = p[1];
break;
default:
return 0;
}
len = 3;
} else {
/* multi digit including the level and facility number */
char *endp = NULL;
lev = (simple_strtoul(&p[1], &endp, 10) & 7);
if (endp == NULL || endp[0] != '>')
return 0;
len = (endp + 1) - p;
}
/* do not accept special char if not asked for */
if (sp && !special)
return 0;
if (special) {
*special = sp;
/* return special char, do not touch level */
if (sp)
return len;
}
if (level)
*level = lev;
return len;
}
/*
* Call the console drivers, asking them to write out
* log_buf[start] to log_buf[end - 1].
* The console_lock must be held.
*/
static void call_console_drivers(unsigned start, unsigned end)
{
unsigned cur_index, start_print;
static int msg_level = -1;
BUG_ON(((int)(start - end)) > 0);
cur_index = start;
start_print = start;
while (cur_index != end) {
if (msg_level < 0 && ((end - cur_index) > 2)) {
/* strip log prefix */
cur_index += log_prefix(&LOG_BUF(cur_index), &msg_level, NULL);
start_print = cur_index;
}
while (cur_index != end) {
char c = LOG_BUF(cur_index);
cur_index++;
if (c == '\n') {
if (msg_level < 0) {
/*
* printk() has already given us loglevel tags in
* the buffer. This code is here in case the
* log buffer has wrapped right round and scribbled
* on those tags
*/
msg_level = default_message_loglevel;
}
_call_console_drivers(start_print, cur_index, msg_level);
msg_level = -1;
start_print = cur_index;
break;
}
}
}
_call_console_drivers(start_print, end, msg_level);
}
static void emit_log_char(char c)
{
LOG_BUF(log_end) = c;
log_end++;
if (log_end - log_start > log_buf_len)
log_start = log_end - log_buf_len;
if (log_end - con_start > log_buf_len)
con_start = log_end - log_buf_len;
if (logged_chars < log_buf_len)
logged_chars++;
}
/*
* Zap console related locks when oopsing. Only zap at most once
* every 10 seconds, to leave time for slow consoles to print a
* full oops.
*/
static void zap_locks(void)
{
static unsigned long oops_timestamp;
if (time_after_eq(jiffies, oops_timestamp) &&
!time_after(jiffies, oops_timestamp + 30 * HZ))
return;
oops_timestamp = jiffies;
debug_locks_off();
/* If a crash is occurring, make sure we can't deadlock */
raw_spin_lock_init(&logbuf_lock);
/* And make sure that we print immediately */
sema_init(&console_sem, 1);
}
#if defined(CONFIG_PRINTK_TIME)
static bool printk_time = 1;
#else
static bool printk_time = 0;
#endif
module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
static bool always_kmsg_dump;
module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR);
/* Check if we have any console registered that can be called early in boot. */
static int have_callable_console(void)
{
struct console *con;
for_each_console(con)
if (con->flags & CON_ANYTIME)
return 1;
return 0;
}
/**
* printk - print a kernel message
* @fmt: format string
*
* This is printk(). It can be called from any context. We want it to work.
*
* We try to grab the console_lock. If we succeed, it's easy - we log the output and
* call the console drivers. If we fail to get the semaphore we place the output
* into the log buffer and return. The current holder of the console_sem will
* notice the new output in console_unlock(); and will send it to the
* consoles before releasing the lock.
*
* One effect of this deferred printing is that code which calls printk() and
* then changes console_loglevel may break. This is because console_loglevel
* is inspected when the actual printing occurs.
*
* See also:
* printf(3)
*
* See the vsnprintf() documentation for format string extensions over C99.
*/
asmlinkage int printk(const char *fmt, ...)
{
va_list args;
int r;
#ifdef CONFIG_MSM_RTB
void *caller = __builtin_return_address(0);
uncached_logk_pc(LOGK_LOGBUF, caller, (void *)log_end);
#endif
#ifdef CONFIG_KGDB_KDB
if (unlikely(kdb_trap_printk)) {
va_start(args, fmt);
r = vkdb_printf(fmt, args);
va_end(args);
return r;
}
#endif
va_start(args, fmt);
r = vprintk(fmt, args);
va_end(args);
return r;
}
/* cpu currently holding logbuf_lock */
static volatile unsigned int printk_cpu = UINT_MAX;
/*
* Can we actually use the console at this time on this cpu?
*
* Console drivers may assume that per-cpu resources have
* been allocated. So unless they're explicitly marked as
* being able to cope (CON_ANYTIME) don't call them until
* this CPU is officially up.
*/
static inline int can_use_console(unsigned int cpu)
{
return cpu_online(cpu) || have_callable_console();
}
/*
* Try to get console ownership to actually show the kernel
* messages from a 'printk'. Return true (and with the
* console_lock held, and 'console_locked' set) if it
* is successful, false otherwise.
*
* This gets called with the 'logbuf_lock' spinlock held and
* interrupts disabled. It should return with 'lockbuf_lock'
* released but interrupts still disabled.
*/
static int console_trylock_for_printk(unsigned int cpu)
__releases(&logbuf_lock)
{
int retval = 0, wake = 0;
if (console_trylock()) {
retval = 1;
/*
* If we can't use the console, we need to release
* the console semaphore by hand to avoid flushing
* the buffer. We need to hold the console semaphore
* in order to do this test safely.
*/
if (!can_use_console(cpu)) {
console_locked = 0;
wake = 1;
retval = 0;
}
}
printk_cpu = UINT_MAX;
if (wake)
up(&console_sem);
raw_spin_unlock(&logbuf_lock);
return retval;
}
static const char recursion_bug_msg [] =
KERN_CRIT "BUG: recent printk recursion!\n";
static int recursion_bug;
static int new_text_line = 1;
static char printk_buf[1024];
int printk_delay_msec __read_mostly;
static inline void printk_delay(void)
{
if (unlikely(printk_delay_msec)) {
int m = printk_delay_msec;
while (m--) {
mdelay(1);
touch_nmi_watchdog();
}
}
}
asmlinkage int vprintk(const char *fmt, va_list args)
{
int printed_len = 0;
int current_log_level = default_message_loglevel;
unsigned long flags;
int this_cpu;
char *p;
size_t plen;
char special;
boot_delay_msec();
printk_delay();
/* This stops the holder of console_sem just where we want him */
local_irq_save(flags);
this_cpu = smp_processor_id();
/*
* Ouch, printk recursed into itself!
*/
if (unlikely(printk_cpu == this_cpu)) {
/*
* If a crash is occurring during printk() on this CPU,
* then try to get the crash message out but make sure
* we can't deadlock. Otherwise just return to avoid the
* recursion and return - but flag the recursion so that
* it can be printed at the next appropriate moment:
*/
if (!oops_in_progress && !lockdep_recursing(current)) {
recursion_bug = 1;
goto out_restore_irqs;
}
zap_locks();
}
lockdep_off();
raw_spin_lock(&logbuf_lock);
printk_cpu = this_cpu;
if (recursion_bug) {
recursion_bug = 0;
strcpy(printk_buf, recursion_bug_msg);
printed_len = strlen(recursion_bug_msg);
}
/* Emit the output into the temporary buffer */
printed_len += vscnprintf(printk_buf + printed_len,
sizeof(printk_buf) - printed_len, fmt, args);
p = printk_buf;
/* Read log level and handle special printk prefix */
plen = log_prefix(p, ¤t_log_level, &special);
if (plen) {
p += plen;
switch (special) {
case 'c': /* Strip <c> KERN_CONT, continue line */
plen = 0;
break;
case 'd': /* Strip <d> KERN_DEFAULT, start new line */
plen = 0;
default:
if (!new_text_line) {
emit_log_char('\n');
new_text_line = 1;
}
}
}
/*
* Copy the output into log_buf. If the caller didn't provide
* the appropriate log prefix, we insert them here
*/
for (; *p; p++) {
if (new_text_line) {
new_text_line = 0;
if (plen) {
/* Copy original log prefix */
int i;
for (i = 0; i < plen; i++)
emit_log_char(printk_buf[i]);
printed_len += plen;
} else {
/* Add log prefix */
emit_log_char('<');
emit_log_char(current_log_level + '0');
emit_log_char('>');
printed_len += 3;
}
if (printk_time) {
/* Add the current time stamp */
char tbuf[50], *tp;
unsigned tlen;
unsigned long long t;
unsigned long nanosec_rem;
t = cpu_clock(printk_cpu);
nanosec_rem = do_div(t, 1000000000);
tlen = sprintf(tbuf, "[%5lu.%06lu] ",
(unsigned long) t,
nanosec_rem / 1000);
for (tp = tbuf; tp < tbuf + tlen; tp++)
emit_log_char(*tp);
printed_len += tlen;
}
if (!*p)
break;
}
emit_log_char(*p);
if (*p == '\n')
new_text_line = 1;
}
/*
* Try to acquire and then immediately release the
* console semaphore. The release will do all the
* actual magic (print out buffers, wake up klogd,
* etc).
*
* The console_trylock_for_printk() function
* will release 'logbuf_lock' regardless of whether it
* actually gets the semaphore or not.
*/
if (console_trylock_for_printk(this_cpu))
console_unlock();
lockdep_on();
out_restore_irqs:
local_irq_restore(flags);
return printed_len;
}
EXPORT_SYMBOL(printk);
EXPORT_SYMBOL(vprintk);
#else
static void call_console_drivers(unsigned start, unsigned end)
{
}
#endif
static int __add_preferred_console(char *name, int idx, char *options,
char *brl_options)
{
struct console_cmdline *c;
int i;
/*
* See if this tty is not yet registered, and
* if we have a slot free.
*/
for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
if (strcmp(console_cmdline[i].name, name) == 0 &&
console_cmdline[i].index == idx) {
if (!brl_options)
selected_console = i;
return 0;
}
if (i == MAX_CMDLINECONSOLES)
return -E2BIG;
if (!brl_options)
selected_console = i;
c = &console_cmdline[i];
strlcpy(c->name, name, sizeof(c->name));
c->options = options;
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
c->brl_options = brl_options;
#endif
c->index = idx;
return 0;
}
/*
* Set up a list of consoles. Called from init/main.c
*/
static int __init console_setup(char *str)
{
char buf[sizeof(console_cmdline[0].name) + 4]; /* 4 for index */
char *s, *options, *brl_options = NULL;
int idx;
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
if (!memcmp(str, "brl,", 4)) {
brl_options = "";
str += 4;
} else if (!memcmp(str, "brl=", 4)) {
brl_options = str + 4;
str = strchr(brl_options, ',');
if (!str) {
printk(KERN_ERR "need port name after brl=\n");
return 1;
}
*(str++) = 0;
}
#endif
/*
* Decode str into name, index, options.
*/
if (str[0] >= '0' && str[0] <= '9') {
strcpy(buf, "ttyS");
strncpy(buf + 4, str, sizeof(buf) - 5);
} else {
strncpy(buf, str, sizeof(buf) - 1);
}
buf[sizeof(buf) - 1] = 0;
if ((options = strchr(str, ',')) != NULL)
*(options++) = 0;
#ifdef __sparc__
if (!strcmp(str, "ttya"))
strcpy(buf, "ttyS0");
if (!strcmp(str, "ttyb"))
strcpy(buf, "ttyS1");
#endif
for (s = buf; *s; s++)
if ((*s >= '0' && *s <= '9') || *s == ',')
break;
idx = simple_strtoul(s, NULL, 10);
*s = 0;
__add_preferred_console(buf, idx, options, brl_options);
console_set_on_cmdline = 1;
return 1;
}
__setup("console=", console_setup);
/**
* add_preferred_console - add a device to the list of preferred consoles.
* @name: device name
* @idx: device index
* @options: options for this console
*
* The last preferred console added will be used for kernel messages
* and stdin/out/err for init. Normally this is used by console_setup
* above to handle user-supplied console arguments; however it can also
* be used by arch-specific code either to override the user or more
* commonly to provide a default console (ie from PROM variables) when
* the user has not supplied one.
*/
int add_preferred_console(char *name, int idx, char *options)
{
return __add_preferred_console(name, idx, options, NULL);
}
int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options)
{
struct console_cmdline *c;
int i;
for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
if (strcmp(console_cmdline[i].name, name) == 0 &&
console_cmdline[i].index == idx) {
c = &console_cmdline[i];
strlcpy(c->name, name_new, sizeof(c->name));
c->name[sizeof(c->name) - 1] = 0;
c->options = options;
c->index = idx_new;
return i;
}
/* not found */
return -1;
}
bool console_suspend_enabled = 1;
EXPORT_SYMBOL(console_suspend_enabled);
static int __init console_suspend_disable(char *str)
{
console_suspend_enabled = 0;
return 1;
}
__setup("no_console_suspend", console_suspend_disable);
module_param_named(console_suspend, console_suspend_enabled,
bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(console_suspend, "suspend console during suspend"
" and hibernate operations");
/**
* suspend_console - suspend the console subsystem
*
* This disables printk() while we go into suspend states
*/
void suspend_console(void)
{
if (!console_suspend_enabled)
return;
printk("Suspending console(s) (use no_console_suspend to debug)\n");
console_lock();
console_suspended = 1;
up(&console_sem);
}
void resume_console(void)
{
if (!console_suspend_enabled)
return;
down(&console_sem);
console_suspended = 0;
console_unlock();
}
static void __cpuinit console_flush(struct work_struct *work)
{
console_lock();
console_unlock();
}
static __cpuinitdata DECLARE_WORK(console_cpu_notify_work, console_flush);
/**
* console_cpu_notify - print deferred console messages after CPU hotplug
* @self: notifier struct
* @action: CPU hotplug event
* @hcpu: unused
*
* If printk() is called from a CPU that is not online yet, the messages
* will be spooled but will not show up on the console. This function is
* called when a new CPU comes online (or fails to come up), and ensures
* that any such output gets printed.
*
* Special handling must be done for cases invoked from an atomic context,
* as we can't be taking the console semaphore here.
*/
static int __cpuinit console_cpu_notify(struct notifier_block *self,
unsigned long action, void *hcpu)
{
switch (action) {
case CPU_DEAD:
case CPU_DOWN_FAILED:
case CPU_UP_CANCELED:
console_lock();
console_unlock();
break;
case CPU_ONLINE:
case CPU_DYING:
/* invoked with preemption disabled, so defer */
if (!console_trylock())
schedule_work(&console_cpu_notify_work);
else
console_unlock();
}
return NOTIFY_OK;
}
/**
* console_lock - lock the console system for exclusive use.
*
* Acquires a lock which guarantees that the caller has
* exclusive access to the console system and the console_drivers list.
*
* Can sleep, returns nothing.
*/
void console_lock(void)
{
BUG_ON(in_interrupt());
down(&console_sem);
if (console_suspended)
return;
console_locked = 1;
console_may_schedule = 1;
}
EXPORT_SYMBOL(console_lock);
/**
* console_trylock - try to lock the console system for exclusive use.
*
* Tried to acquire a lock which guarantees that the caller has
* exclusive access to the console system and the console_drivers list.
*
* returns 1 on success, and 0 on failure to acquire the lock.
*/
int console_trylock(void)
{
if (down_trylock(&console_sem))
return 0;
if (console_suspended) {
up(&console_sem);
return 0;
}
console_locked = 1;
console_may_schedule = 0;
return 1;
}
EXPORT_SYMBOL(console_trylock);
int is_console_locked(void)
{
return console_locked;
}
/*
* Delayed printk facility, for scheduler-internal messages:
*/
#define PRINTK_BUF_SIZE 512
#define PRINTK_PENDING_WAKEUP 0x01
#define PRINTK_PENDING_SCHED 0x02
static DEFINE_PER_CPU(int, printk_pending);
static DEFINE_PER_CPU(char [PRINTK_BUF_SIZE], printk_sched_buf);
void printk_tick(void)
{
if (__this_cpu_read(printk_pending)) {
int pending = __this_cpu_xchg(printk_pending, 0);
if (pending & PRINTK_PENDING_SCHED) {
char *buf = __get_cpu_var(printk_sched_buf);
printk(KERN_WARNING "[sched_delayed] %s", buf);
}
if (pending & PRINTK_PENDING_WAKEUP)
wake_up_interruptible(&log_wait);
}
}
int printk_needs_cpu(int cpu)
{
if (cpu_is_offline(cpu))
printk_tick();
return __this_cpu_read(printk_pending);
}
void wake_up_klogd(void)
{
if (waitqueue_active(&log_wait))
this_cpu_or(printk_pending, PRINTK_PENDING_WAKEUP);
}
/**
* console_unlock - unlock the console system
*
* Releases the console_lock which the caller holds on the console system
* and the console driver list.
*
* While the console_lock was held, console output may have been buffered
* by printk(). If this is the case, console_unlock(); emits
* the output prior to releasing the lock.
*
* If there is output waiting for klogd, we wake it up.
*
* console_unlock(); may be called from any context.
*/
void console_unlock(void)
{
unsigned long flags;
unsigned _con_start, _log_end;
unsigned wake_klogd = 0, retry = 0;
if (console_suspended) {
up(&console_sem);
return;
}
console_may_schedule = 0;
again:
for ( ; ; ) {
raw_spin_lock_irqsave(&logbuf_lock, flags);
wake_klogd |= log_start - log_end;
if (con_start == log_end)
break; /* Nothing to print */
_con_start = con_start;
_log_end = log_end;
con_start = log_end; /* Flush */
raw_spin_unlock(&logbuf_lock);
stop_critical_timings(); /* don't trace print latency */
call_console_drivers(_con_start, _log_end);
start_critical_timings();
local_irq_restore(flags);
}
console_locked = 0;
/* Release the exclusive_console once it is used */
if (unlikely(exclusive_console))
exclusive_console = NULL;
raw_spin_unlock(&logbuf_lock);
up(&console_sem);
/*
* Someone could have filled up the buffer again, so re-check if there's
* something to flush. In case we cannot trylock the console_sem again,
* there's a new owner and the console_unlock() from them will do the
* flush, no worries.
*/
raw_spin_lock(&logbuf_lock);
retry = con_start != log_end;
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
if (retry && console_trylock())
goto again;
if (wake_klogd)
wake_up_klogd();
}
EXPORT_SYMBOL(console_unlock);
/**
* console_conditional_schedule - yield the CPU if required
*
* If the console code is currently allowed to sleep, and
* if this CPU should yield the CPU to another task, do
* so here.
*
* Must be called within console_lock();.
*/
void __sched console_conditional_schedule(void)
{
if (console_may_schedule)
cond_resched();
}
EXPORT_SYMBOL(console_conditional_schedule);
void console_unblank(void)
{
struct console *c;
/*
* console_unblank can no longer be called in interrupt context unless
* oops_in_progress is set to 1..
*/
if (oops_in_progress) {
if (down_trylock(&console_sem) != 0)
return;
} else
console_lock();
console_locked = 1;
console_may_schedule = 0;
for_each_console(c)
if ((c->flags & CON_ENABLED) && c->unblank)
c->unblank();
console_unlock();
}
/*
* Return the console tty driver structure and its associated index
*/
struct tty_driver *console_device(int *index)
{
struct console *c;
struct tty_driver *driver = NULL;
console_lock();
for_each_console(c) {
if (!c->device)
continue;
driver = c->device(c, index);
if (driver)
break;
}
console_unlock();
return driver;
}
/*
* Prevent further output on the passed console device so that (for example)
* serial drivers can disable console output before suspending a port, and can
* re-enable output afterwards.
*/
void console_stop(struct console *console)
{
console_lock();
console->flags &= ~CON_ENABLED;
console_unlock();
}
EXPORT_SYMBOL(console_stop);
void console_start(struct console *console)
{
console_lock();
console->flags |= CON_ENABLED;
console_unlock();
}
EXPORT_SYMBOL(console_start);
static int __read_mostly keep_bootcon;
static int __init keep_bootcon_setup(char *str)
{
keep_bootcon = 1;
printk(KERN_INFO "debug: skip boot console de-registration.\n");
return 0;
}
early_param("keep_bootcon", keep_bootcon_setup);
/*
* The console driver calls this routine during kernel initialization
* to register the console printing procedure with printk() and to
* print any messages that were printed by the kernel before the
* console driver was initialized.
*
* This can happen pretty early during the boot process (because of
* early_printk) - sometimes before setup_arch() completes - be careful
* of what kernel features are used - they may not be initialised yet.
*
* There are two types of consoles - bootconsoles (early_printk) and
* "real" consoles (everything which is not a bootconsole) which are
* handled differently.
* - Any number of bootconsoles can be registered at any time.
* - As soon as a "real" console is registered, all bootconsoles
* will be unregistered automatically.
* - Once a "real" console is registered, any attempt to register a
* bootconsoles will be rejected
*/
void register_console(struct console *newcon)
{
int i;
unsigned long flags;
struct console *bcon = NULL;
/*
* before we register a new CON_BOOT console, make sure we don't
* already have a valid console
*/
if (console_drivers && newcon->flags & CON_BOOT) {
/* find the last or real console */
for_each_console(bcon) {
if (!(bcon->flags & CON_BOOT)) {
printk(KERN_INFO "Too late to register bootconsole %s%d\n",
newcon->name, newcon->index);
return;
}
}
}
if (console_drivers && console_drivers->flags & CON_BOOT)
bcon = console_drivers;
if (preferred_console < 0 || bcon || !console_drivers)
preferred_console = selected_console;
if (newcon->early_setup)
newcon->early_setup();
/*
* See if we want to use this console driver. If we
* didn't select a console we take the first one
* that registers here.
*/
if (preferred_console < 0) {
if (newcon->index < 0)
newcon->index = 0;
if (newcon->setup == NULL ||
newcon->setup(newcon, NULL) == 0) {
newcon->flags |= CON_ENABLED;
if (newcon->device) {
newcon->flags |= CON_CONSDEV;
preferred_console = 0;
}
}
}
/*
* See if this console matches one we selected on
* the command line.
*/
for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0];
i++) {
if (strcmp(console_cmdline[i].name, newcon->name) != 0)
continue;
if (newcon->index >= 0 &&
newcon->index != console_cmdline[i].index)
continue;
if (newcon->index < 0)
newcon->index = console_cmdline[i].index;
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
if (console_cmdline[i].brl_options) {
newcon->flags |= CON_BRL;
braille_register_console(newcon,
console_cmdline[i].index,
console_cmdline[i].options,
console_cmdline[i].brl_options);
return;
}
#endif
if (newcon->setup &&
newcon->setup(newcon, console_cmdline[i].options) != 0)
break;
newcon->flags |= CON_ENABLED;
newcon->index = console_cmdline[i].index;
if (i == selected_console) {
newcon->flags |= CON_CONSDEV;
preferred_console = selected_console;
}
break;
}
if (!(newcon->flags & CON_ENABLED))
return;
/*
* If we have a bootconsole, and are switching to a real console,
* don't print everything out again, since when the boot console, and
* the real console are the same physical device, it's annoying to
* see the beginning boot messages twice
*/
if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV))
newcon->flags &= ~CON_PRINTBUFFER;
/*
* Put this console in the list - keep the
* preferred driver at the head of the list.
*/
console_lock();
if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) {
newcon->next = console_drivers;
console_drivers = newcon;
if (newcon->next)
newcon->next->flags &= ~CON_CONSDEV;
} else {
newcon->next = console_drivers->next;
console_drivers->next = newcon;
}
if (newcon->flags & CON_PRINTBUFFER) {
/*
* console_unlock(); will print out the buffered messages
* for us.
*/
raw_spin_lock_irqsave(&logbuf_lock, flags);
con_start = log_start;
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
/*
* We're about to replay the log buffer. Only do this to the
* just-registered console to avoid excessive message spam to
* the already-registered consoles.
*/
exclusive_console = newcon;
}
console_unlock();
console_sysfs_notify();
/*
* By unregistering the bootconsoles after we enable the real console
* we get the "console xxx enabled" message on all the consoles -
* boot consoles, real consoles, etc - this is to ensure that end
* users know there might be something in the kernel's log buffer that
* went to the bootconsole (that they do not see on the real console)
*/
if (bcon &&
((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
!keep_bootcon) {
/* we need to iterate through twice, to make sure we print
* everything out, before we unregister the console(s)
*/
printk(KERN_INFO "console [%s%d] enabled, bootconsole disabled\n",
newcon->name, newcon->index);
for_each_console(bcon)
if (bcon->flags & CON_BOOT)
unregister_console(bcon);
} else {
printk(KERN_INFO "%sconsole [%s%d] enabled\n",
(newcon->flags & CON_BOOT) ? "boot" : "" ,
newcon->name, newcon->index);
}
}
EXPORT_SYMBOL(register_console);
int unregister_console(struct console *console)
{
struct console *a, *b;
int res = 1;
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
if (console->flags & CON_BRL)
return braille_unregister_console(console);
#endif
console_lock();
if (console_drivers == console) {
console_drivers=console->next;
res = 0;
} else if (console_drivers) {
for (a=console_drivers->next, b=console_drivers ;
a; b=a, a=b->next) {
if (a == console) {
b->next = a->next;
res = 0;
break;
}
}
}
/*
* If this isn't the last console and it has CON_CONSDEV set, we
* need to set it on the next preferred console.
*/
if (console_drivers != NULL && console->flags & CON_CONSDEV)
console_drivers->flags |= CON_CONSDEV;
console_unlock();
console_sysfs_notify();
return res;
}
EXPORT_SYMBOL(unregister_console);
static int __init printk_late_init(void)
{
struct console *con;
for_each_console(con) {
if (!keep_bootcon && con->flags & CON_BOOT) {
printk(KERN_INFO "turn off boot console %s%d\n",
con->name, con->index);
unregister_console(con);
}
}
hotcpu_notifier(console_cpu_notify, 0);
return 0;
}
late_initcall(printk_late_init);
#if defined CONFIG_PRINTK
int printk_sched(const char *fmt, ...)
{
unsigned long flags;
va_list args;
char *buf;
int r;
local_irq_save(flags);
buf = __get_cpu_var(printk_sched_buf);
va_start(args, fmt);
r = vsnprintf(buf, PRINTK_BUF_SIZE, fmt, args);
va_end(args);
__this_cpu_or(printk_pending, PRINTK_PENDING_SCHED);
local_irq_restore(flags);
return r;
}
/*
* printk rate limiting, lifted from the networking subsystem.
*
* This enforces a rate limit: not more than 10 kernel messages
* every 5s to make a denial-of-service attack impossible.
*/
DEFINE_RATELIMIT_STATE(printk_ratelimit_state, 5 * HZ, 10);
int __printk_ratelimit(const char *func)
{
return ___ratelimit(&printk_ratelimit_state, func);
}
EXPORT_SYMBOL(__printk_ratelimit);
/**
* printk_timed_ratelimit - caller-controlled printk ratelimiting
* @caller_jiffies: pointer to caller's state
* @interval_msecs: minimum interval between prints
*
* printk_timed_ratelimit() returns true if more than @interval_msecs
* milliseconds have elapsed since the last time printk_timed_ratelimit()
* returned true.
*/
bool printk_timed_ratelimit(unsigned long *caller_jiffies,
unsigned int interval_msecs)
{
if (*caller_jiffies == 0
|| !time_in_range(jiffies, *caller_jiffies,
*caller_jiffies
+ msecs_to_jiffies(interval_msecs))) {
*caller_jiffies = jiffies;
return true;
}
return false;
}
EXPORT_SYMBOL(printk_timed_ratelimit);
static DEFINE_SPINLOCK(dump_list_lock);
static LIST_HEAD(dump_list);
/**
* kmsg_dump_register - register a kernel log dumper.
* @dumper: pointer to the kmsg_dumper structure
*
* Adds a kernel log dumper to the system. The dump callback in the
* structure will be called when the kernel oopses or panics and must be
* set. Returns zero on success and %-EINVAL or %-EBUSY otherwise.
*/
int kmsg_dump_register(struct kmsg_dumper *dumper)
{
unsigned long flags;
int err = -EBUSY;
/* The dump callback needs to be set */
if (!dumper->dump)
return -EINVAL;
spin_lock_irqsave(&dump_list_lock, flags);
/* Don't allow registering multiple times */
if (!dumper->registered) {
dumper->registered = 1;
list_add_tail_rcu(&dumper->list, &dump_list);
err = 0;
}
spin_unlock_irqrestore(&dump_list_lock, flags);
return err;
}
EXPORT_SYMBOL_GPL(kmsg_dump_register);
/**
* kmsg_dump_unregister - unregister a kmsg dumper.
* @dumper: pointer to the kmsg_dumper structure
*
* Removes a dump device from the system. Returns zero on success and
* %-EINVAL otherwise.
*/
int kmsg_dump_unregister(struct kmsg_dumper *dumper)
{
unsigned long flags;
int err = -EINVAL;
spin_lock_irqsave(&dump_list_lock, flags);
if (dumper->registered) {
dumper->registered = 0;
list_del_rcu(&dumper->list);
err = 0;
}
spin_unlock_irqrestore(&dump_list_lock, flags);
synchronize_rcu();
return err;
}
EXPORT_SYMBOL_GPL(kmsg_dump_unregister);
/**
* kmsg_dump - dump kernel log to kernel message dumpers.
* @reason: the reason (oops, panic etc) for dumping
*
* Iterate through each of the dump devices and call the oops/panic
* callbacks with the log buffer.
*/
void kmsg_dump(enum kmsg_dump_reason reason)
{
unsigned long end;
unsigned chars;
struct kmsg_dumper *dumper;
const char *s1, *s2;
unsigned long l1, l2;
unsigned long flags;
if ((reason > KMSG_DUMP_OOPS) && !always_kmsg_dump)
return;
/* Theoretically, the log could move on after we do this, but
there's not a lot we can do about that. The new messages
will overwrite the start of what we dump. */
raw_spin_lock_irqsave(&logbuf_lock, flags);
end = log_end & LOG_BUF_MASK;
chars = logged_chars;
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
if (chars > end) {
s1 = log_buf + log_buf_len - chars + end;
l1 = chars - end;
s2 = log_buf;
l2 = end;
} else {
s1 = "";
l1 = 0;
s2 = log_buf + end - chars;
l2 = chars;
}
rcu_read_lock();
list_for_each_entry_rcu(dumper, &dump_list, list)
dumper->dump(dumper, reason, s1, l1, s2, l2);
rcu_read_unlock();
}
#endif
| CyanogenMod/android_kernel_sony_msm8974 | kernel/printk.c | C | gpl-2.0 | 46,989 |
<?php
/**
* @file
* Template file for Radix modal.
*/
?>
<!-- Button trigger modal -->
<?php print render($trigger_button); ?>
<!-- Modal -->
<div class="modal fade" id="<?php print $modal_id; ?>" tabindex="-1" role="dialog" aria-labelledby="<?php print $modal_id; ?>" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<?php if ($header): ?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">
<?php print $header; ?>
</h4>
</div>
<?php endif; ?>
<?php if ($content): ?>
<div class="modal-body">
<?php print render($content); ?>
</div>
<?php endif; ?>
<?php if (count($buttons)): ?>
<div class="modal-footer">
<?php foreach ($buttons as $button): ?>
<?php print $button; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
| angrycactus/dkan | webroot/profiles/dkan/themes/contrib/radix/templates/radix/radix-modal.tpl.php | PHP | gpl-2.0 | 1,060 |
/* SPDX-License-Identifier: GPL-2.0 */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <elf.h>
#include "elfconfig.h"
/* On BSD-alike OSes elf.h defines these according to host's word size */
#undef ELF_ST_BIND
#undef ELF_ST_TYPE
#undef ELF_R_SYM
#undef ELF_R_TYPE
#if KERNEL_ELFCLASS == ELFCLASS32
#define Elf_Ehdr Elf32_Ehdr
#define Elf_Shdr Elf32_Shdr
#define Elf_Sym Elf32_Sym
#define Elf_Addr Elf32_Addr
#define Elf_Sword Elf64_Sword
#define Elf_Section Elf32_Half
#define ELF_ST_BIND ELF32_ST_BIND
#define ELF_ST_TYPE ELF32_ST_TYPE
#define Elf_Rel Elf32_Rel
#define Elf_Rela Elf32_Rela
#define ELF_R_SYM ELF32_R_SYM
#define ELF_R_TYPE ELF32_R_TYPE
#else
#define Elf_Ehdr Elf64_Ehdr
#define Elf_Shdr Elf64_Shdr
#define Elf_Sym Elf64_Sym
#define Elf_Addr Elf64_Addr
#define Elf_Sword Elf64_Sxword
#define Elf_Section Elf64_Half
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_ST_TYPE ELF64_ST_TYPE
#define Elf_Rel Elf64_Rel
#define Elf_Rela Elf64_Rela
#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
#endif
/* The 64-bit MIPS ELF ABI uses an unusual reloc format. */
typedef struct
{
Elf32_Word r_sym; /* Symbol index */
unsigned char r_ssym; /* Special symbol for 2nd relocation */
unsigned char r_type3; /* 3rd relocation type */
unsigned char r_type2; /* 2nd relocation type */
unsigned char r_type1; /* 1st relocation type */
} _Elf64_Mips_R_Info;
typedef union
{
Elf64_Xword r_info_number;
_Elf64_Mips_R_Info r_info_fields;
} _Elf64_Mips_R_Info_union;
#define ELF64_MIPS_R_SYM(i) \
((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_sym)
#define ELF64_MIPS_R_TYPE(i) \
((__extension__ (_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_type1)
#if KERNEL_ELFDATA != HOST_ELFDATA
static inline void __endian(const void *src, void *dest, unsigned int size)
{
unsigned int i;
for (i = 0; i < size; i++)
((unsigned char*)dest)[i] = ((unsigned char*)src)[size - i-1];
}
#define TO_NATIVE(x) \
({ \
typeof(x) __x; \
__endian(&(x), &(__x), sizeof(__x)); \
__x; \
})
#else /* endianness matches */
#define TO_NATIVE(x) (x)
#endif
#define NOFAIL(ptr) do_nofail((ptr), #ptr)
void *do_nofail(void *ptr, const char *expr);
struct buffer {
char *p;
int pos;
int size;
};
void __attribute__((format(printf, 2, 3)))
buf_printf(struct buffer *buf, const char *fmt, ...);
void
buf_write(struct buffer *buf, const char *s, int len);
struct namespace_list {
struct namespace_list *next;
char namespace[];
};
struct module {
struct module *next;
int gpl_compatible;
struct symbol *unres;
int from_dump; /* 1 if module was loaded from *.symvers */
int is_vmlinux;
int seen;
int has_init;
int has_cleanup;
struct buffer dev_table_buf;
char srcversion[25];
// Missing namespace dependencies
struct namespace_list *missing_namespaces;
// Actual imported namespaces
struct namespace_list *imported_namespaces;
char name[];
};
struct elf_info {
size_t size;
Elf_Ehdr *hdr;
Elf_Shdr *sechdrs;
Elf_Sym *symtab_start;
Elf_Sym *symtab_stop;
Elf_Section export_sec;
Elf_Section export_unused_sec;
Elf_Section export_gpl_sec;
Elf_Section export_unused_gpl_sec;
Elf_Section export_gpl_future_sec;
char *strtab;
char *modinfo;
unsigned int modinfo_len;
/* support for 32bit section numbers */
unsigned int num_sections; /* max_secindex + 1 */
unsigned int secindex_strings;
/* if Nth symbol table entry has .st_shndx = SHN_XINDEX,
* take shndx from symtab_shndx_start[N] instead */
Elf32_Word *symtab_shndx_start;
Elf32_Word *symtab_shndx_stop;
};
static inline int is_shndx_special(unsigned int i)
{
return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE;
}
/*
* Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of
* the way to -256..-1, to avoid conflicting with real section
* indices.
*/
#define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1))
/* Accessor for sym->st_shndx, hides ugliness of "64k sections" */
static inline unsigned int get_secindex(const struct elf_info *info,
const Elf_Sym *sym)
{
if (is_shndx_special(sym->st_shndx))
return SPECIAL(sym->st_shndx);
if (sym->st_shndx != SHN_XINDEX)
return sym->st_shndx;
return info->symtab_shndx_start[sym - info->symtab_start];
}
/* file2alias.c */
extern unsigned int cross_build;
void handle_moddevtable(struct module *mod, struct elf_info *info,
Elf_Sym *sym, const char *symname);
void add_moddevtable(struct buffer *buf, struct module *mod);
/* sumversion.c */
void get_src_version(const char *modname, char sum[], unsigned sumlen);
/* from modpost.c */
char *read_text_file(const char *filename);
char *get_line(char **stringp);
enum loglevel {
LOG_WARN,
LOG_ERROR,
LOG_FATAL
};
void modpost_log(enum loglevel loglevel, const char *fmt, ...);
#define warn(fmt, args...) modpost_log(LOG_WARN, fmt, ##args)
#define merror(fmt, args...) modpost_log(LOG_ERROR, fmt, ##args)
#define fatal(fmt, args...) modpost_log(LOG_FATAL, fmt, ##args)
| chenshuo/linux-study | scripts/mod/modpost.h | C | gpl-2.0 | 5,201 |
'use strict';
var $ = require('jquery');
require('./github-node-cfg.js');
var AddonHelper = require('js/addonHelper');
$(window.contextVars.githubSettingsSelector).on('submit', AddonHelper.onSubmitSettings);
| ticklemepierce/osf.io | website/addons/github/static/node-cfg.js | JavaScript | apache-2.0 | 210 |
/*
* Copyright (C) 2011-2012, LG Eletronics,Inc. All rights reserved.
* LGIT LCD device driver
*
* 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.
*
* 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 <linux/gpio.h>
#include "msm_fb.h"
#include "mipi_dsi.h"
#include "mipi_lgit.h"
#include "mdp4.h"
static struct msm_panel_common_pdata *mipi_lgit_pdata;
static struct dsi_buf lgit_tx_buf;
static struct dsi_buf lgit_rx_buf;
static int skip_init;
#define DSV_ONBST 57
static int lgit_external_dsv_onoff(uint8_t on_off)
{
int ret =0;
static int init_done=0;
if (!init_done) {
ret = gpio_request(DSV_ONBST,"DSV_ONBST_en");
if (ret) {
pr_err("%s: failed to request DSV_ONBST gpio \n", __func__);
goto out;
}
ret = gpio_direction_output(DSV_ONBST, 1);
if (ret) {
pr_err("%s: failed to set DSV_ONBST direction\n", __func__);
goto err_gpio;
}
init_done = 1;
}
gpio_set_value(DSV_ONBST, on_off);
mdelay(20);
goto out;
err_gpio:
gpio_free(DSV_ONBST);
out:
return ret;
}
static int mipi_lgit_lcd_on(struct platform_device *pdev)
{
struct msm_fb_data_type *mfd;
int ret = 0;
pr_info("%s started\n", __func__);
mfd = platform_get_drvdata(pdev);
if (!mfd)
return -ENODEV;
if (mfd->key != MFD_KEY)
return -EINVAL;
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x10000000);
ret = mipi_dsi_cmds_tx(&lgit_tx_buf,
mipi_lgit_pdata->power_on_set_1,
mipi_lgit_pdata->power_on_set_size_1);
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x14000000);
if (ret < 0) {
pr_err("%s: failed to transmit power_on_set_1 cmds\n", __func__);
return ret;
}
if(!skip_init){
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x10000000);
ret = mipi_dsi_cmds_tx(&lgit_tx_buf,
mipi_lgit_pdata->power_on_set_2,
mipi_lgit_pdata->power_on_set_size_2);
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x14000000);
if (ret < 0) {
pr_err("%s: failed to transmit power_on_set_2 cmds\n", __func__);
return ret;
}
}
skip_init = false;
ret = lgit_external_dsv_onoff(1);
if (ret < 0) {
pr_err("%s: failed to turn on external dsv\n", __func__);
return ret;
}
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x10000000);
ret = mipi_dsi_cmds_tx(&lgit_tx_buf,
mipi_lgit_pdata->power_on_set_3,
mipi_lgit_pdata->power_on_set_size_3);
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x14000000);
if (ret < 0) {
pr_err("%s: failed to transmit power_on_set_3 cmds\n", __func__);
return ret;
}
pr_info("%s finished\n", __func__);
return 0;
}
static int mipi_lgit_lcd_off(struct platform_device *pdev)
{
struct msm_fb_data_type *mfd;
int ret = 0;
pr_info("%s started\n", __func__);
if (mipi_lgit_pdata->bl_pwm_disable)
mipi_lgit_pdata->bl_pwm_disable();
mfd = platform_get_drvdata(pdev);
if (!mfd)
return -ENODEV;
if (mfd->key != MFD_KEY)
return -EINVAL;
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x10000000);
ret = mipi_dsi_cmds_tx(&lgit_tx_buf,
mipi_lgit_pdata->power_off_set_1,
mipi_lgit_pdata->power_off_set_size_1);
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x14000000);
if (ret < 0) {
pr_err("%s: failed to transmit power_off_set_1 cmds\n", __func__);
return ret;
}
ret = lgit_external_dsv_onoff(0);
if (ret < 0) {
pr_err("%s: failed to turn off external dsv\n", __func__);
return ret;
}
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x10000000);
ret = mipi_dsi_cmds_tx(&lgit_tx_buf,
mipi_lgit_pdata->power_off_set_2,
mipi_lgit_pdata->power_off_set_size_2);
MIPI_OUTP(MIPI_DSI_BASE + 0x38, 0x14000000);
if (ret < 0) {
pr_err("%s: failed to transmit power_off_set_2 cmds\n", __func__);
return ret;
}
pr_info("%s finished\n", __func__);
return 0;
}
static int mipi_lgit_backlight_on_status(void)
{
return (mipi_lgit_pdata->bl_on_status());
}
static void mipi_lgit_set_backlight_board(struct msm_fb_data_type *mfd)
{
int level;
level = (int)mfd->bl_level;
mipi_lgit_pdata->backlight_level(level, 0, 0);
}
static int mipi_lgit_lcd_probe(struct platform_device *pdev)
{
if (pdev->id == 0) {
mipi_lgit_pdata = pdev->dev.platform_data;
return 0;
}
pr_info("%s start\n", __func__);
skip_init = true;
msm_fb_add_device(pdev);
return 0;
}
static struct platform_driver this_driver = {
.probe = mipi_lgit_lcd_probe,
.driver = {
.name = "mipi_lgit",
},
};
static struct msm_fb_panel_data lgit_panel_data = {
.on = mipi_lgit_lcd_on,
.off = mipi_lgit_lcd_off,
.set_backlight = mipi_lgit_set_backlight_board,
.get_backlight_on_status = mipi_lgit_backlight_on_status,
};
static int ch_used[3];
int mipi_lgit_device_register(struct msm_panel_info *pinfo,
u32 channel, u32 panel)
{
struct platform_device *pdev = NULL;
int ret;
if ((channel >= 3) || ch_used[channel])
return -ENODEV;
ch_used[channel] = TRUE;
pdev = platform_device_alloc("mipi_lgit", (panel << 8)|channel);
if (!pdev)
return -ENOMEM;
lgit_panel_data.panel_info = *pinfo;
ret = platform_device_add_data(pdev, &lgit_panel_data,
sizeof(lgit_panel_data));
if (ret) {
pr_err("%s: platform_device_add_data failed!\n", __func__);
goto err_device_put;
}
ret = platform_device_add(pdev);
if (ret) {
pr_err("%s: platform_device_register failed!\n", __func__);
goto err_device_put;
}
return 0;
err_device_put:
platform_device_put(pdev);
return ret;
}
static int __init mipi_lgit_lcd_init(void)
{
mipi_dsi_buf_alloc(&lgit_tx_buf, DSI_BUF_SIZE);
mipi_dsi_buf_alloc(&lgit_rx_buf, DSI_BUF_SIZE);
return platform_driver_register(&this_driver);
}
module_init(mipi_lgit_lcd_init);
| keeeener/nicki | kernel/drivers/video/msm/mipi_lgit.c | C | gpl-2.0 | 5,994 |
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/event_client_impl.h"
#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ui/aura/window.h"
#include "ui/keyboard/keyboard_util.h"
namespace ash {
EventClientImpl::EventClientImpl() {
}
EventClientImpl::~EventClientImpl() {
}
bool EventClientImpl::CanProcessEventsWithinSubtree(
const aura::Window* window) const {
const aura::Window* root_window = window ? window->GetRootWindow() : NULL;
if (!root_window ||
!Shell::GetInstance()->session_state_delegate()->IsUserSessionBlocked()) {
return true;
}
const aura::Window* lock_screen_containers = Shell::GetContainer(
root_window,
kShellWindowId_LockScreenContainersContainer);
const aura::Window* lock_background_containers = Shell::GetContainer(
root_window,
kShellWindowId_LockScreenBackgroundContainer);
const aura::Window* lock_screen_related_containers = Shell::GetContainer(
root_window,
kShellWindowId_LockScreenRelatedContainersContainer);
bool can_process_events = (window->Contains(lock_screen_containers) &&
window->Contains(lock_background_containers) &&
window->Contains(lock_screen_related_containers)) ||
lock_screen_containers->Contains(window) ||
lock_background_containers->Contains(window) ||
lock_screen_related_containers->Contains(window);
if (keyboard::IsKeyboardEnabled()) {
const aura::Window* virtual_keyboard_container = Shell::GetContainer(
root_window,
kShellWindowId_VirtualKeyboardContainer);
can_process_events |= (window->Contains(virtual_keyboard_container) ||
virtual_keyboard_container->Contains(window));
}
return can_process_events;
}
ui::EventTarget* EventClientImpl::GetToplevelEventTarget() {
return Shell::GetInstance();
}
} // namespace ash
| s20121035/rk3288_android5.1_repo | external/chromium_org/ash/wm/event_client_impl.cc | C++ | gpl-3.0 | 2,044 |
public enum A {
;
A(String s){}
} | asedunov/intellij-community | java/java-tests/testData/refactoring/moveMembers/enumConstant/before/A.java | Java | apache-2.0 | 37 |
class A {
public void f() {
Inner i = new Inner();
i.doStuff();
}
private class <caret>Inner {
public void doStuff() {
}
}
} | asedunov/intellij-community | java/java-tests/testData/refactoring/inlineToAnonymousClass/NoInlineMethodUsage.java | Java | apache-2.0 | 173 |
class MyException extends RuntimeException{}
class MyClass {
public void foo() throws MyException {
throw new MyException();<caret>
}
} | asedunov/intellij-community | java/java-tests/testData/codeInsight/completion/smartType/ExceptionTwice-out.java | Java | apache-2.0 | 139 |
/*!
* https://github.com/es-shims/es5-shim
* @license es5-shim Copyright 2009-2015 by contributors, MIT License
* see https://github.com/es-shims/es5-shim/blob/master/LICENSE
*/
// vim: ts=4 sts=4 sw=4 expandtab
// Add semicolon to prevent IIFE from being passed as argument to concatenated code.
;
// UMD (Universal Module Definition)
// see https://github.com/umdjs/umd/blob/master/returnExports.js
(function (root, factory) {
'use strict';
/* global define, exports, module */
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.returnExports = factory();
}
}(this, function () {
/**
* Brings an environment as close to ECMAScript 5 compliance
* as is possible with the facilities of erstwhile engines.
*
* Annotated ES5: http://es5.github.com/ (specific links below)
* ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
* Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
*/
// Shortcut to an often accessed properties, in order to avoid multiple
// dereference that costs universally. This also holds a reference to known-good
// functions.
var $Array = Array;
var ArrayPrototype = $Array.prototype;
var $Object = Object;
var ObjectPrototype = $Object.prototype;
var FunctionPrototype = Function.prototype;
var $String = String;
var StringPrototype = $String.prototype;
var $Number = Number;
var NumberPrototype = $Number.prototype;
var array_slice = ArrayPrototype.slice;
var array_splice = ArrayPrototype.splice;
var array_push = ArrayPrototype.push;
var array_unshift = ArrayPrototype.unshift;
var array_concat = ArrayPrototype.concat;
var call = FunctionPrototype.call;
var max = Math.max;
var min = Math.min;
// Having a toString local variable name breaks in Opera so use to_string.
var to_string = ObjectPrototype.toString;
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
var isRegex; /* inlined from https://npmjs.com/is-regex */ var regexExec = RegExp.prototype.exec, tryRegexExec = function tryRegexExec(value) { try { regexExec.call(value); return true; } catch (e) { return false; } }, regexClass = '[object RegExp]'; isRegex = function isRegex(value) { if (typeof value !== 'object') { return false; } return hasToStringTag ? tryRegexExec(value) : to_string.call(value) === regexClass; };
var isString; /* inlined from https://npmjs.com/is-string */ var strValue = String.prototype.valueOf, tryStringObject = function tryStringObject(value) { try { strValue.call(value); return true; } catch (e) { return false; } }, stringClass = '[object String]'; isString = function isString(value) { if (typeof value === 'string') { return true; } if (typeof value !== 'object') { return false; } return hasToStringTag ? tryStringObject(value) : to_string.call(value) === stringClass; };
/* inlined from http://npmjs.com/define-properties */
var defineProperties = (function (has) {
var supportsDescriptors = $Object.defineProperty && (function () {
try {
var obj = {};
$Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
for (var _ in obj) { return false; }
return obj.x === obj;
} catch (e) { /* this is ES3 */
return false;
}
}());
// Define configurable, writable and non-enumerable props
// if they don't exist.
var defineProperty;
if (supportsDescriptors) {
defineProperty = function (object, name, method, forceAssign) {
if (!forceAssign && (name in object)) { return; }
$Object.defineProperty(object, name, {
configurable: true,
enumerable: false,
writable: true,
value: method
});
};
} else {
defineProperty = function (object, name, method, forceAssign) {
if (!forceAssign && (name in object)) { return; }
object[name] = method;
};
}
return function defineProperties(object, map, forceAssign) {
for (var name in map) {
if (has.call(map, name)) {
defineProperty(object, name, map[name], forceAssign);
}
}
};
}(ObjectPrototype.hasOwnProperty));
//
// Util
// ======
//
/* replaceable with https://npmjs.com/package/es-abstract /helpers/isPrimitive */
var isPrimitive = function isPrimitive(input) {
var type = typeof input;
return input === null || (type !== 'object' && type !== 'function');
};
var isActualNaN = $Number.isNaN || function (x) { return x !== x; };
var ES = {
// ES5 9.4
// http://es5.github.com/#x9.4
// http://jsperf.com/to-integer
/* replaceable with https://npmjs.com/package/es-abstract ES5.ToInteger */
ToInteger: function ToInteger(num) {
var n = +num;
if (isActualNaN(n)) {
n = 0;
} else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
return n;
},
/* replaceable with https://npmjs.com/package/es-abstract ES5.ToPrimitive */
ToPrimitive: function ToPrimitive(input) {
var val, valueOf, toStr;
if (isPrimitive(input)) {
return input;
}
valueOf = input.valueOf;
if (isCallable(valueOf)) {
val = valueOf.call(input);
if (isPrimitive(val)) {
return val;
}
}
toStr = input.toString;
if (isCallable(toStr)) {
val = toStr.call(input);
if (isPrimitive(val)) {
return val;
}
}
throw new TypeError();
},
// ES5 9.9
// http://es5.github.com/#x9.9
/* replaceable with https://npmjs.com/package/es-abstract ES5.ToObject */
ToObject: function (o) {
/* jshint eqnull: true */
if (o == null) { // this matches both null and undefined
throw new TypeError("can't convert " + o + ' to object');
}
return $Object(o);
},
/* replaceable with https://npmjs.com/package/es-abstract ES5.ToUint32 */
ToUint32: function ToUint32(x) {
return x >>> 0;
}
};
//
// Function
// ========
//
// ES-5 15.3.4.5
// http://es5.github.com/#x15.3.4.5
var Empty = function Empty() {};
defineProperties(FunctionPrototype, {
bind: function bind(that) { // .length is 1
// 1. Let Target be the this value.
var target = this;
// 2. If IsCallable(Target) is false, throw a TypeError exception.
if (!isCallable(target)) {
throw new TypeError('Function.prototype.bind called on incompatible ' + target);
}
// 3. Let A be a new (possibly empty) internal list of all of the
// argument values provided after thisArg (arg1, arg2 etc), in order.
// XXX slicedArgs will stand in for "A" if used
var args = array_slice.call(arguments, 1); // for normal call
// 4. Let F be a new native ECMAScript object.
// 11. Set the [[Prototype]] internal property of F to the standard
// built-in Function prototype object as specified in 15.3.3.1.
// 12. Set the [[Call]] internal property of F as described in
// 15.3.4.5.1.
// 13. Set the [[Construct]] internal property of F as described in
// 15.3.4.5.2.
// 14. Set the [[HasInstance]] internal property of F as described in
// 15.3.4.5.3.
var bound;
var binder = function () {
if (this instanceof bound) {
// 15.3.4.5.2 [[Construct]]
// When the [[Construct]] internal method of a function object,
// F that was created using the bind function is called with a
// list of arguments ExtraArgs, the following steps are taken:
// 1. Let target be the value of F's [[TargetFunction]]
// internal property.
// 2. If target has no [[Construct]] internal method, a
// TypeError exception is thrown.
// 3. Let boundArgs be the value of F's [[BoundArgs]] internal
// property.
// 4. Let args be a new list containing the same values as the
// list boundArgs in the same order followed by the same
// values as the list ExtraArgs in the same order.
// 5. Return the result of calling the [[Construct]] internal
// method of target providing args as the arguments.
var result = target.apply(
this,
array_concat.call(args, array_slice.call(arguments))
);
if ($Object(result) === result) {
return result;
}
return this;
} else {
// 15.3.4.5.1 [[Call]]
// When the [[Call]] internal method of a function object, F,
// which was created using the bind function is called with a
// this value and a list of arguments ExtraArgs, the following
// steps are taken:
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
// property.
// 2. Let boundThis be the value of F's [[BoundThis]] internal
// property.
// 3. Let target be the value of F's [[TargetFunction]] internal
// property.
// 4. Let args be a new list containing the same values as the
// list boundArgs in the same order followed by the same
// values as the list ExtraArgs in the same order.
// 5. Return the result of calling the [[Call]] internal method
// of target providing boundThis as the this value and
// providing args as the arguments.
// equiv: target.call(this, ...boundArgs, ...args)
return target.apply(
that,
array_concat.call(args, array_slice.call(arguments))
);
}
};
// 15. If the [[Class]] internal property of Target is "Function", then
// a. Let L be the length property of Target minus the length of A.
// b. Set the length own property of F to either 0 or L, whichever is
// larger.
// 16. Else set the length own property of F to 0.
var boundLength = max(0, target.length - args.length);
// 17. Set the attributes of the length own property of F to the values
// specified in 15.3.5.1.
var boundArgs = [];
for (var i = 0; i < boundLength; i++) {
array_push.call(boundArgs, '$' + i);
}
// XXX Build a dynamic function with desired amount of arguments is the only
// way to set the length property of a function.
// In environments where Content Security Policies enabled (Chrome extensions,
// for ex.) all use of eval or Function costructor throws an exception.
// However in all of these environments Function.prototype.bind exists
// and so this code will never be executed.
bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
if (target.prototype) {
Empty.prototype = target.prototype;
bound.prototype = new Empty();
// Clean up dangling references.
Empty.prototype = null;
}
// TODO
// 18. Set the [[Extensible]] internal property of F to true.
// TODO
// 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
// 20. Call the [[DefineOwnProperty]] internal method of F with
// arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
// thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
// false.
// 21. Call the [[DefineOwnProperty]] internal method of F with
// arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
// [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
// and false.
// TODO
// NOTE Function objects created using Function.prototype.bind do not
// have a prototype property or the [[Code]], [[FormalParameters]], and
// [[Scope]] internal properties.
// XXX can't delete prototype in pure-js.
// 22. Return F.
return bound;
}
});
// _Please note: Shortcuts are defined after `Function.prototype.bind` as we
// us it in defining shortcuts.
var owns = call.bind(ObjectPrototype.hasOwnProperty);
var toStr = call.bind(ObjectPrototype.toString);
var strSlice = call.bind(StringPrototype.slice);
var strSplit = call.bind(StringPrototype.split);
var strIndexOf = call.bind(StringPrototype.indexOf);
//
// Array
// =====
//
var isArray = $Array.isArray || function isArray(obj) {
return toStr(obj) === '[object Array]';
};
// ES5 15.4.4.12
// http://es5.github.com/#x15.4.4.13
// Return len+argCount.
// [bugfix, ielt8]
// IE < 8 bug: [].unshift(0) === undefined but should be "1"
var hasUnshiftReturnValueBug = [].unshift(0) !== 1;
defineProperties(ArrayPrototype, {
unshift: function () {
array_unshift.apply(this, arguments);
return this.length;
}
}, hasUnshiftReturnValueBug);
// ES5 15.4.3.2
// http://es5.github.com/#x15.4.3.2
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
defineProperties($Array, { isArray: isArray });
// The IsCallable() check in the Array functions
// has been replaced with a strict check on the
// internal class of the object to trap cases where
// the provided function was actually a regular
// expression literal, which in V8 and
// JavaScriptCore is a typeof "function". Only in
// V8 are regular expression literals permitted as
// reduce parameters, so it is desirable in the
// general case for the shim to match the more
// strict and common behavior of rejecting regular
// expressions.
// ES5 15.4.4.18
// http://es5.github.com/#x15.4.4.18
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
// Check failure of by-index access of string characters (IE < 9)
// and failure of `0 in boxedString` (Rhino)
var boxedString = $Object('a');
var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
var properlyBoxesContext = function properlyBoxed(method) {
// Check node 0.6.21 bug where third parameter is not boxed
var properlyBoxesNonStrict = true;
var properlyBoxesStrict = true;
if (method) {
method.call('foo', function (_, __, context) {
if (typeof context !== 'object') { properlyBoxesNonStrict = false; }
});
method.call([1], function () {
'use strict';
properlyBoxesStrict = typeof this === 'string';
}, 'x');
}
return !!method && properlyBoxesNonStrict && properlyBoxesStrict;
};
defineProperties(ArrayPrototype, {
forEach: function forEach(callbackfn /*, thisArg*/) {
var object = ES.ToObject(this);
var self = splitString && isString(this) ? strSplit(this, '') : object;
var i = -1;
var length = ES.ToUint32(self.length);
var T;
if (arguments.length > 1) {
T = arguments[1];
}
// If no callback function or if callback is not a callable function
if (!isCallable(callbackfn)) {
throw new TypeError('Array.prototype.forEach callback must be a function');
}
while (++i < length) {
if (i in self) {
// Invoke the callback function with call, passing arguments:
// context, property value, property key, thisArg object
if (typeof T === 'undefined') {
callbackfn(self[i], i, object);
} else {
callbackfn.call(T, self[i], i, object);
}
}
}
}
}, !properlyBoxesContext(ArrayPrototype.forEach));
// ES5 15.4.4.19
// http://es5.github.com/#x15.4.4.19
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
defineProperties(ArrayPrototype, {
map: function map(callbackfn/*, thisArg*/) {
var object = ES.ToObject(this);
var self = splitString && isString(this) ? strSplit(this, '') : object;
var length = ES.ToUint32(self.length);
var result = $Array(length);
var T;
if (arguments.length > 1) {
T = arguments[1];
}
// If no callback function or if callback is not a callable function
if (!isCallable(callbackfn)) {
throw new TypeError('Array.prototype.map callback must be a function');
}
for (var i = 0; i < length; i++) {
if (i in self) {
if (typeof T === 'undefined') {
result[i] = callbackfn(self[i], i, object);
} else {
result[i] = callbackfn.call(T, self[i], i, object);
}
}
}
return result;
}
}, !properlyBoxesContext(ArrayPrototype.map));
// ES5 15.4.4.20
// http://es5.github.com/#x15.4.4.20
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
defineProperties(ArrayPrototype, {
filter: function filter(callbackfn /*, thisArg*/) {
var object = ES.ToObject(this);
var self = splitString && isString(this) ? strSplit(this, '') : object;
var length = ES.ToUint32(self.length);
var result = [];
var value;
var T;
if (arguments.length > 1) {
T = arguments[1];
}
// If no callback function or if callback is not a callable function
if (!isCallable(callbackfn)) {
throw new TypeError('Array.prototype.filter callback must be a function');
}
for (var i = 0; i < length; i++) {
if (i in self) {
value = self[i];
if (typeof T === 'undefined' ? callbackfn(value, i, object) : callbackfn.call(T, value, i, object)) {
array_push.call(result, value);
}
}
}
return result;
}
}, !properlyBoxesContext(ArrayPrototype.filter));
// ES5 15.4.4.16
// http://es5.github.com/#x15.4.4.16
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
defineProperties(ArrayPrototype, {
every: function every(callbackfn /*, thisArg*/) {
var object = ES.ToObject(this);
var self = splitString && isString(this) ? strSplit(this, '') : object;
var length = ES.ToUint32(self.length);
var T;
if (arguments.length > 1) {
T = arguments[1];
}
// If no callback function or if callback is not a callable function
if (!isCallable(callbackfn)) {
throw new TypeError('Array.prototype.every callback must be a function');
}
for (var i = 0; i < length; i++) {
if (i in self && !(typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
return false;
}
}
return true;
}
}, !properlyBoxesContext(ArrayPrototype.every));
// ES5 15.4.4.17
// http://es5.github.com/#x15.4.4.17
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
defineProperties(ArrayPrototype, {
some: function some(callbackfn/*, thisArg */) {
var object = ES.ToObject(this);
var self = splitString && isString(this) ? strSplit(this, '') : object;
var length = ES.ToUint32(self.length);
var T;
if (arguments.length > 1) {
T = arguments[1];
}
// If no callback function or if callback is not a callable function
if (!isCallable(callbackfn)) {
throw new TypeError('Array.prototype.some callback must be a function');
}
for (var i = 0; i < length; i++) {
if (i in self && (typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
return true;
}
}
return false;
}
}, !properlyBoxesContext(ArrayPrototype.some));
// ES5 15.4.4.21
// http://es5.github.com/#x15.4.4.21
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
var reduceCoercesToObject = false;
if (ArrayPrototype.reduce) {
reduceCoercesToObject = typeof ArrayPrototype.reduce.call('es5', function (_, __, ___, list) { return list; }) === 'object';
}
defineProperties(ArrayPrototype, {
reduce: function reduce(callbackfn /*, initialValue*/) {
var object = ES.ToObject(this);
var self = splitString && isString(this) ? strSplit(this, '') : object;
var length = ES.ToUint32(self.length);
// If no callback function or if callback is not a callable function
if (!isCallable(callbackfn)) {
throw new TypeError('Array.prototype.reduce callback must be a function');
}
// no value to return if no initial value and an empty array
if (length === 0 && arguments.length === 1) {
throw new TypeError('reduce of empty array with no initial value');
}
var i = 0;
var result;
if (arguments.length >= 2) {
result = arguments[1];
} else {
do {
if (i in self) {
result = self[i++];
break;
}
// if array contains no values, no initial value to return
if (++i >= length) {
throw new TypeError('reduce of empty array with no initial value');
}
} while (true);
}
for (; i < length; i++) {
if (i in self) {
result = callbackfn(result, self[i], i, object);
}
}
return result;
}
}, !reduceCoercesToObject);
// ES5 15.4.4.22
// http://es5.github.com/#x15.4.4.22
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
var reduceRightCoercesToObject = false;
if (ArrayPrototype.reduceRight) {
reduceRightCoercesToObject = typeof ArrayPrototype.reduceRight.call('es5', function (_, __, ___, list) { return list; }) === 'object';
}
defineProperties(ArrayPrototype, {
reduceRight: function reduceRight(callbackfn/*, initial*/) {
var object = ES.ToObject(this);
var self = splitString && isString(this) ? strSplit(this, '') : object;
var length = ES.ToUint32(self.length);
// If no callback function or if callback is not a callable function
if (!isCallable(callbackfn)) {
throw new TypeError('Array.prototype.reduceRight callback must be a function');
}
// no value to return if no initial value, empty array
if (length === 0 && arguments.length === 1) {
throw new TypeError('reduceRight of empty array with no initial value');
}
var result;
var i = length - 1;
if (arguments.length >= 2) {
result = arguments[1];
} else {
do {
if (i in self) {
result = self[i--];
break;
}
// if array contains no values, no initial value to return
if (--i < 0) {
throw new TypeError('reduceRight of empty array with no initial value');
}
} while (true);
}
if (i < 0) {
return result;
}
do {
if (i in self) {
result = callbackfn(result, self[i], i, object);
}
} while (i--);
return result;
}
}, !reduceRightCoercesToObject);
// ES5 15.4.4.14
// http://es5.github.com/#x15.4.4.14
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
var hasFirefox2IndexOfBug = ArrayPrototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
defineProperties(ArrayPrototype, {
indexOf: function indexOf(searchElement /*, fromIndex */) {
var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
var length = ES.ToUint32(self.length);
if (length === 0) {
return -1;
}
var i = 0;
if (arguments.length > 1) {
i = ES.ToInteger(arguments[1]);
}
// handle negative indices
i = i >= 0 ? i : max(0, length + i);
for (; i < length; i++) {
if (i in self && self[i] === searchElement) {
return i;
}
}
return -1;
}
}, hasFirefox2IndexOfBug);
// ES5 15.4.4.15
// http://es5.github.com/#x15.4.4.15
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
var hasFirefox2LastIndexOfBug = ArrayPrototype.lastIndexOf && [0, 1].lastIndexOf(0, -3) !== -1;
defineProperties(ArrayPrototype, {
lastIndexOf: function lastIndexOf(searchElement /*, fromIndex */) {
var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
var length = ES.ToUint32(self.length);
if (length === 0) {
return -1;
}
var i = length - 1;
if (arguments.length > 1) {
i = min(i, ES.ToInteger(arguments[1]));
}
// handle negative indices
i = i >= 0 ? i : length - Math.abs(i);
for (; i >= 0; i--) {
if (i in self && searchElement === self[i]) {
return i;
}
}
return -1;
}
}, hasFirefox2LastIndexOfBug);
// ES5 15.4.4.12
// http://es5.github.com/#x15.4.4.12
var spliceNoopReturnsEmptyArray = (function () {
var a = [1, 2];
var result = a.splice();
return a.length === 2 && isArray(result) && result.length === 0;
}());
defineProperties(ArrayPrototype, {
// Safari 5.0 bug where .splice() returns undefined
splice: function splice(start, deleteCount) {
if (arguments.length === 0) {
return [];
} else {
return array_splice.apply(this, arguments);
}
}
}, !spliceNoopReturnsEmptyArray);
var spliceWorksWithEmptyObject = (function () {
var obj = {};
ArrayPrototype.splice.call(obj, 0, 0, 1);
return obj.length === 1;
}());
defineProperties(ArrayPrototype, {
splice: function splice(start, deleteCount) {
if (arguments.length === 0) { return []; }
var args = arguments;
this.length = max(ES.ToInteger(this.length), 0);
if (arguments.length > 0 && typeof deleteCount !== 'number') {
args = array_slice.call(arguments);
if (args.length < 2) {
array_push.call(args, this.length - start);
} else {
args[1] = ES.ToInteger(deleteCount);
}
}
return array_splice.apply(this, args);
}
}, !spliceWorksWithEmptyObject);
var spliceWorksWithLargeSparseArrays = (function () {
// Per https://github.com/es-shims/es5-shim/issues/295
// Safari 7/8 breaks with sparse arrays of size 1e5 or greater
var arr = new $Array(1e5);
// note: the index MUST be 8 or larger or the test will false pass
arr[8] = 'x';
arr.splice(1, 1);
// note: this test must be defined *after* the indexOf shim
// per https://github.com/es-shims/es5-shim/issues/313
return arr.indexOf('x') === 7;
}());
var spliceWorksWithSmallSparseArrays = (function () {
// Per https://github.com/es-shims/es5-shim/issues/295
// Opera 12.15 breaks on this, no idea why.
var n = 256;
var arr = [];
arr[n] = 'a';
arr.splice(n + 1, 0, 'b');
return arr[n] === 'a';
}());
defineProperties(ArrayPrototype, {
splice: function splice(start, deleteCount) {
var O = ES.ToObject(this);
var A = [];
var len = ES.ToUint32(O.length);
var relativeStart = ES.ToInteger(start);
var actualStart = relativeStart < 0 ? max((len + relativeStart), 0) : min(relativeStart, len);
var actualDeleteCount = min(max(ES.ToInteger(deleteCount), 0), len - actualStart);
var k = 0;
var from;
while (k < actualDeleteCount) {
from = $String(actualStart + k);
if (owns(O, from)) {
A[k] = O[from];
}
k += 1;
}
var items = array_slice.call(arguments, 2);
var itemCount = items.length;
var to;
if (itemCount < actualDeleteCount) {
k = actualStart;
while (k < (len - actualDeleteCount)) {
from = $String(k + actualDeleteCount);
to = $String(k + itemCount);
if (owns(O, from)) {
O[to] = O[from];
} else {
delete O[to];
}
k += 1;
}
k = len;
while (k > (len - actualDeleteCount + itemCount)) {
delete O[k - 1];
k -= 1;
}
} else if (itemCount > actualDeleteCount) {
k = len - actualDeleteCount;
while (k > actualStart) {
from = $String(k + actualDeleteCount - 1);
to = $String(k + itemCount - 1);
if (owns(O, from)) {
O[to] = O[from];
} else {
delete O[to];
}
k -= 1;
}
}
k = actualStart;
for (var i = 0; i < items.length; ++i) {
O[k] = items[i];
k += 1;
}
O.length = len - actualDeleteCount + itemCount;
return A;
}
}, !spliceWorksWithLargeSparseArrays || !spliceWorksWithSmallSparseArrays);
//
// Object
// ======
//
// ES5 15.2.3.14
// http://es5.github.com/#x15.2.3.14
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
var hasDontEnumBug = !({ 'toString': null }).propertyIsEnumerable('toString');
var hasProtoEnumBug = function () {}.propertyIsEnumerable('prototype');
var hasStringEnumBug = !owns('x', '0');
var equalsConstructorPrototype = function (o) {
var ctor = o.constructor;
return ctor && ctor.prototype === o;
};
var blacklistedKeys = {
$window: true,
$console: true,
$parent: true,
$self: true,
$frame: true,
$frames: true,
$frameElement: true,
$webkitIndexedDB: true,
$webkitStorageInfo: true
};
var hasAutomationEqualityBug = (function () {
/* globals window */
if (typeof window === 'undefined') { return false; }
for (var k in window) {
try {
if (!blacklistedKeys['$' + k] && owns(window, k) && window[k] !== null && typeof window[k] === 'object') {
equalsConstructorPrototype(window[k]);
}
} catch (e) {
return true;
}
}
return false;
}());
var equalsConstructorPrototypeIfNotBuggy = function (object) {
if (typeof window === 'undefined' || !hasAutomationEqualityBug) { return equalsConstructorPrototype(object); }
try {
return equalsConstructorPrototype(object);
} catch (e) {
return false;
}
};
var dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
];
var dontEnumsLength = dontEnums.length;
// taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js
// can be replaced with require('is-arguments') if we ever use a build process instead
var isStandardArguments = function isArguments(value) {
return toStr(value) === '[object Arguments]';
};
var isLegacyArguments = function isArguments(value) {
return value !== null &&
typeof value === 'object' &&
typeof value.length === 'number' &&
value.length >= 0 &&
!isArray(value) &&
isCallable(value.callee);
};
var isArguments = isStandardArguments(arguments) ? isStandardArguments : isLegacyArguments;
defineProperties($Object, {
keys: function keys(object) {
var isFn = isCallable(object);
var isArgs = isArguments(object);
var isObject = object !== null && typeof object === 'object';
var isStr = isObject && isString(object);
if (!isObject && !isFn && !isArgs) {
throw new TypeError('Object.keys called on a non-object');
}
var theKeys = [];
var skipProto = hasProtoEnumBug && isFn;
if ((isStr && hasStringEnumBug) || isArgs) {
for (var i = 0; i < object.length; ++i) {
array_push.call(theKeys, $String(i));
}
}
if (!isArgs) {
for (var name in object) {
if (!(skipProto && name === 'prototype') && owns(object, name)) {
array_push.call(theKeys, $String(name));
}
}
}
if (hasDontEnumBug) {
var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
for (var j = 0; j < dontEnumsLength; j++) {
var dontEnum = dontEnums[j];
if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) {
array_push.call(theKeys, dontEnum);
}
}
}
return theKeys;
}
});
var keysWorksWithArguments = $Object.keys && (function () {
// Safari 5.0 bug
return $Object.keys(arguments).length === 2;
}(1, 2));
var keysHasArgumentsLengthBug = $Object.keys && (function () {
var argKeys = $Object.keys(arguments);
return arguments.length !== 1 || argKeys.length !== 1 || argKeys[0] !== 1;
}(1));
var originalKeys = $Object.keys;
defineProperties($Object, {
keys: function keys(object) {
if (isArguments(object)) {
return originalKeys(array_slice.call(object));
} else {
return originalKeys(object);
}
}
}, !keysWorksWithArguments || keysHasArgumentsLengthBug);
//
// Date
// ====
//
// ES5 15.9.5.43
// http://es5.github.com/#x15.9.5.43
// This function returns a String value represent the instance in time
// represented by this Date object. The format of the String is the Date Time
// string format defined in 15.9.1.15. All fields are present in the String.
// The time zone is always UTC, denoted by the suffix Z. If the time value of
// this object is not a finite Number a RangeError exception is thrown.
var negativeDate = -62198755200000;
var negativeYearString = '-000001';
var hasNegativeDateBug = Date.prototype.toISOString && new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1;
var hasSafari51DateBug = Date.prototype.toISOString && new Date(-1).toISOString() !== '1969-12-31T23:59:59.999Z';
defineProperties(Date.prototype, {
toISOString: function toISOString() {
var result, length, value, year, month;
if (!isFinite(this)) {
throw new RangeError('Date.prototype.toISOString called on non-finite value.');
}
year = this.getUTCFullYear();
month = this.getUTCMonth();
// see https://github.com/es-shims/es5-shim/issues/111
year += Math.floor(month / 12);
month = (month % 12 + 12) % 12;
// the date time string format is specified in 15.9.1.15.
result = [month + 1, this.getUTCDate(), this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
year = (
(year < 0 ? '-' : (year > 9999 ? '+' : '')) +
strSlice('00000' + Math.abs(year), (0 <= year && year <= 9999) ? -4 : -6)
);
length = result.length;
while (length--) {
value = result[length];
// pad months, days, hours, minutes, and seconds to have two
// digits.
if (value < 10) {
result[length] = '0' + value;
}
}
// pad milliseconds to have three digits.
return (
year + '-' + array_slice.call(result, 0, 2).join('-') +
'T' + array_slice.call(result, 2).join(':') + '.' +
strSlice('000' + this.getUTCMilliseconds(), -3) + 'Z'
);
}
}, hasNegativeDateBug || hasSafari51DateBug);
// ES5 15.9.5.44
// http://es5.github.com/#x15.9.5.44
// This function provides a String representation of a Date object for use by
// JSON.stringify (15.12.3).
var dateToJSONIsSupported = (function () {
try {
return Date.prototype.toJSON &&
new Date(NaN).toJSON() === null &&
new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
Date.prototype.toJSON.call({ // generic
toISOString: function () { return true; }
});
} catch (e) {
return false;
}
}());
if (!dateToJSONIsSupported) {
Date.prototype.toJSON = function toJSON(key) {
// When the toJSON method is called with argument key, the following
// steps are taken:
// 1. Let O be the result of calling ToObject, giving it the this
// value as its argument.
// 2. Let tv be ES.ToPrimitive(O, hint Number).
var O = $Object(this);
var tv = ES.ToPrimitive(O);
// 3. If tv is a Number and is not finite, return null.
if (typeof tv === 'number' && !isFinite(tv)) {
return null;
}
// 4. Let toISO be the result of calling the [[Get]] internal method of
// O with argument "toISOString".
var toISO = O.toISOString;
// 5. If IsCallable(toISO) is false, throw a TypeError exception.
if (!isCallable(toISO)) {
throw new TypeError('toISOString property is not callable');
}
// 6. Return the result of calling the [[Call]] internal method of
// toISO with O as the this value and an empty argument list.
return toISO.call(O);
// NOTE 1 The argument is ignored.
// NOTE 2 The toJSON function is intentionally generic; it does not
// require that its this value be a Date object. Therefore, it can be
// transferred to other kinds of objects for use as a method. However,
// it does require that any such object have a toISOString method. An
// object is free to use the argument key to filter its
// stringification.
};
}
// ES5 15.9.4.2
// http://es5.github.com/#x15.9.4.2
// based on work shared by Daniel Friesen (dantman)
// http://gist.github.com/303249
var supportsExtendedYears = Date.parse('+033658-09-27T01:46:40.000Z') === 1e15;
var acceptsInvalidDates = !isNaN(Date.parse('2012-04-04T24:00:00.500Z')) || !isNaN(Date.parse('2012-11-31T23:59:59.000Z')) || !isNaN(Date.parse('2012-12-31T23:59:60.000Z'));
var doesNotParseY2KNewYear = isNaN(Date.parse('2000-01-01T00:00:00.000Z'));
if (doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) {
// XXX global assignment won't work in embeddings that use
// an alternate object for the context.
/* global Date: true */
/* eslint-disable no-undef */
var maxSafeUnsigned32Bit = Math.pow(2, 31) - 1;
var secondsWithinMaxSafeUnsigned32Bit = Math.floor(maxSafeUnsigned32Bit / 1e3);
var hasSafariSignedIntBug = isActualNaN(new Date(1970, 0, 1, 0, 0, 0, maxSafeUnsigned32Bit + 1).getTime());
Date = (function (NativeDate) {
/* eslint-enable no-undef */
// Date.length === 7
var DateShim = function Date(Y, M, D, h, m, s, ms) {
var length = arguments.length;
var date;
if (this instanceof NativeDate) {
var seconds = s;
var millis = ms;
if (hasSafariSignedIntBug && length >= 7 && ms > maxSafeUnsigned32Bit) {
// work around a Safari 8/9 bug where it treats the seconds as signed
var msToShift = Math.floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
var sToShift = Math.floor(msToShift / 1e3);
seconds += sToShift;
millis -= sToShift * 1e3;
}
date = length === 1 && $String(Y) === Y ? // isString(Y)
// We explicitly pass it through parse:
new NativeDate(DateShim.parse(Y)) :
// We have to manually make calls depending on argument
// length here
length >= 7 ? new NativeDate(Y, M, D, h, m, seconds, millis) :
length >= 6 ? new NativeDate(Y, M, D, h, m, seconds) :
length >= 5 ? new NativeDate(Y, M, D, h, m) :
length >= 4 ? new NativeDate(Y, M, D, h) :
length >= 3 ? new NativeDate(Y, M, D) :
length >= 2 ? new NativeDate(Y, M) :
length >= 1 ? new NativeDate(Y) :
new NativeDate();
} else {
date = NativeDate.apply(this, arguments);
}
if (!isPrimitive(date)) {
// Prevent mixups with unfixed Date object
defineProperties(date, { constructor: DateShim }, true);
}
return date;
};
// 15.9.1.15 Date Time String Format.
var isoDateExpression = new RegExp('^' +
'(\\d{4}|[+-]\\d{6})' + // four-digit year capture or sign +
// 6-digit extended year
'(?:-(\\d{2})' + // optional month capture
'(?:-(\\d{2})' + // optional day capture
'(?:' + // capture hours:minutes:seconds.milliseconds
'T(\\d{2})' + // hours capture
':(\\d{2})' + // minutes capture
'(?:' + // optional :seconds.milliseconds
':(\\d{2})' + // seconds capture
'(?:(\\.\\d{1,}))?' + // milliseconds capture
')?' +
'(' + // capture UTC offset component
'Z|' + // UTC capture
'(?:' + // offset specifier +/-hours:minutes
'([-+])' + // sign capture
'(\\d{2})' + // hours offset capture
':(\\d{2})' + // minutes offset capture
')' +
')?)?)?)?' +
'$');
var months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
var dayFromMonth = function dayFromMonth(year, month) {
var t = month > 1 ? 1 : 0;
return (
months[month] +
Math.floor((year - 1969 + t) / 4) -
Math.floor((year - 1901 + t) / 100) +
Math.floor((year - 1601 + t) / 400) +
365 * (year - 1970)
);
};
var toUTC = function toUTC(t) {
var s = 0;
var ms = t;
if (hasSafariSignedIntBug && ms > maxSafeUnsigned32Bit) {
// work around a Safari 8/9 bug where it treats the seconds as signed
var msToShift = Math.floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
var sToShift = Math.floor(msToShift / 1e3);
s += sToShift;
ms -= sToShift * 1e3;
}
return $Number(new NativeDate(1970, 0, 1, 0, 0, s, ms));
};
// Copy any custom methods a 3rd party library may have added
for (var key in NativeDate) {
if (owns(NativeDate, key)) {
DateShim[key] = NativeDate[key];
}
}
// Copy "native" methods explicitly; they may be non-enumerable
defineProperties(DateShim, {
now: NativeDate.now,
UTC: NativeDate.UTC
}, true);
DateShim.prototype = NativeDate.prototype;
defineProperties(DateShim.prototype, {
constructor: DateShim
}, true);
// Upgrade Date.parse to handle simplified ISO 8601 strings
var parseShim = function parse(string) {
var match = isoDateExpression.exec(string);
if (match) {
// parse months, days, hours, minutes, seconds, and milliseconds
// provide default values if necessary
// parse the UTC offset component
var year = $Number(match[1]),
month = $Number(match[2] || 1) - 1,
day = $Number(match[3] || 1) - 1,
hour = $Number(match[4] || 0),
minute = $Number(match[5] || 0),
second = $Number(match[6] || 0),
millisecond = Math.floor($Number(match[7] || 0) * 1000),
// When time zone is missed, local offset should be used
// (ES 5.1 bug)
// see https://bugs.ecmascript.org/show_bug.cgi?id=112
isLocalTime = Boolean(match[4] && !match[8]),
signOffset = match[9] === '-' ? 1 : -1,
hourOffset = $Number(match[10] || 0),
minuteOffset = $Number(match[11] || 0),
result;
var hasMinutesOrSecondsOrMilliseconds = minute > 0 || second > 0 || millisecond > 0;
if (
hour < (hasMinutesOrSecondsOrMilliseconds ? 24 : 25) &&
minute < 60 && second < 60 && millisecond < 1000 &&
month > -1 && month < 12 && hourOffset < 24 &&
minuteOffset < 60 && // detect invalid offsets
day > -1 &&
day < (dayFromMonth(year, month + 1) - dayFromMonth(year, month))
) {
result = (
(dayFromMonth(year, month) + day) * 24 +
hour +
hourOffset * signOffset
) * 60;
result = (
(result + minute + minuteOffset * signOffset) * 60 +
second
) * 1000 + millisecond;
if (isLocalTime) {
result = toUTC(result);
}
if (-8.64e15 <= result && result <= 8.64e15) {
return result;
}
}
return NaN;
}
return NativeDate.parse.apply(this, arguments);
};
defineProperties(DateShim, { parse: parseShim });
return DateShim;
}(Date));
/* global Date: false */
}
// ES5 15.9.4.4
// http://es5.github.com/#x15.9.4.4
if (!Date.now) {
Date.now = function now() {
return new Date().getTime();
};
}
//
// Number
// ======
//
// ES5.1 15.7.4.5
// http://es5.github.com/#x15.7.4.5
var hasToFixedBugs = NumberPrototype.toFixed && (
(0.00008).toFixed(3) !== '0.000' ||
(0.9).toFixed(0) !== '1' ||
(1.255).toFixed(2) !== '1.25' ||
(1000000000000000128).toFixed(0) !== '1000000000000000128'
);
var toFixedHelpers = {
base: 1e7,
size: 6,
data: [0, 0, 0, 0, 0, 0],
multiply: function multiply(n, c) {
var i = -1;
var c2 = c;
while (++i < toFixedHelpers.size) {
c2 += n * toFixedHelpers.data[i];
toFixedHelpers.data[i] = c2 % toFixedHelpers.base;
c2 = Math.floor(c2 / toFixedHelpers.base);
}
},
divide: function divide(n) {
var i = toFixedHelpers.size, c = 0;
while (--i >= 0) {
c += toFixedHelpers.data[i];
toFixedHelpers.data[i] = Math.floor(c / n);
c = (c % n) * toFixedHelpers.base;
}
},
numToString: function numToString() {
var i = toFixedHelpers.size;
var s = '';
while (--i >= 0) {
if (s !== '' || i === 0 || toFixedHelpers.data[i] !== 0) {
var t = $String(toFixedHelpers.data[i]);
if (s === '') {
s = t;
} else {
s += strSlice('0000000', 0, 7 - t.length) + t;
}
}
}
return s;
},
pow: function pow(x, n, acc) {
return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
},
log: function log(x) {
var n = 0;
var x2 = x;
while (x2 >= 4096) {
n += 12;
x2 /= 4096;
}
while (x2 >= 2) {
n += 1;
x2 /= 2;
}
return n;
}
};
defineProperties(NumberPrototype, {
toFixed: function toFixed(fractionDigits) {
var f, x, s, m, e, z, j, k;
// Test for NaN and round fractionDigits down
f = $Number(fractionDigits);
f = isActualNaN(f) ? 0 : Math.floor(f);
if (f < 0 || f > 20) {
throw new RangeError('Number.toFixed called with invalid number of decimals');
}
x = $Number(this);
if (isActualNaN(x)) {
return 'NaN';
}
// If it is too big or small, return the string value of the number
if (x <= -1e21 || x >= 1e21) {
return $String(x);
}
s = '';
if (x < 0) {
s = '-';
x = -x;
}
m = '0';
if (x > 1e-21) {
// 1e-21 < x < 1e21
// -70 < log2(x) < 70
e = toFixedHelpers.log(x * toFixedHelpers.pow(2, 69, 1)) - 69;
z = (e < 0 ? x * toFixedHelpers.pow(2, -e, 1) : x / toFixedHelpers.pow(2, e, 1));
z *= 0x10000000000000; // Math.pow(2, 52);
e = 52 - e;
// -18 < e < 122
// x = z / 2 ^ e
if (e > 0) {
toFixedHelpers.multiply(0, z);
j = f;
while (j >= 7) {
toFixedHelpers.multiply(1e7, 0);
j -= 7;
}
toFixedHelpers.multiply(toFixedHelpers.pow(10, j, 1), 0);
j = e - 1;
while (j >= 23) {
toFixedHelpers.divide(1 << 23);
j -= 23;
}
toFixedHelpers.divide(1 << j);
toFixedHelpers.multiply(1, 1);
toFixedHelpers.divide(2);
m = toFixedHelpers.numToString();
} else {
toFixedHelpers.multiply(0, z);
toFixedHelpers.multiply(1 << (-e), 0);
m = toFixedHelpers.numToString() + strSlice('0.00000000000000000000', 2, 2 + f);
}
}
if (f > 0) {
k = m.length;
if (k <= f) {
m = s + strSlice('0.0000000000000000000', 0, f - k + 2) + m;
} else {
m = s + strSlice(m, 0, k - f) + '.' + strSlice(m, k - f);
}
} else {
m = s + m;
}
return m;
}
}, hasToFixedBugs);
//
// String
// ======
//
// ES5 15.5.4.14
// http://es5.github.com/#x15.5.4.14
// [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
// Many browsers do not split properly with regular expressions or they
// do not perform the split correctly under obscure conditions.
// See http://blog.stevenlevithan.com/archives/cross-browser-split
// I've tested in many browsers and this seems to cover the deviant ones:
// 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
// '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
// 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
// [undefined, "t", undefined, "e", ...]
// ''.split(/.?/) should be [], not [""]
// '.'.split(/()()/) should be ["."], not ["", "", "."]
if (
'ab'.split(/(?:ab)*/).length !== 2 ||
'.'.split(/(.?)(.?)/).length !== 4 ||
'tesst'.split(/(s)*/)[1] === 't' ||
'test'.split(/(?:)/, -1).length !== 4 ||
''.split(/.?/).length ||
'.'.split(/()()/).length > 1
) {
(function () {
var compliantExecNpcg = typeof (/()??/).exec('')[1] === 'undefined'; // NPCG: nonparticipating capturing group
var maxSafe32BitInt = Math.pow(2, 32) - 1;
StringPrototype.split = function (separator, limit) {
var string = this;
if (typeof separator === 'undefined' && limit === 0) {
return [];
}
// If `separator` is not a regex, use native split
if (!isRegex(separator)) {
return strSplit(this, separator, limit);
}
var output = [];
var flags = (separator.ignoreCase ? 'i' : '') +
(separator.multiline ? 'm' : '') +
(separator.unicode ? 'u' : '') + // in ES6
(separator.sticky ? 'y' : ''), // Firefox 3+ and ES6
lastLastIndex = 0,
// Make `global` and avoid `lastIndex` issues by working with a copy
separator2, match, lastIndex, lastLength;
var separatorCopy = new RegExp(separator.source, flags + 'g');
string += ''; // Type-convert
if (!compliantExecNpcg) {
// Doesn't need flags gy, but they don't hurt
separator2 = new RegExp('^' + separatorCopy.source + '$(?!\\s)', flags);
}
/* Values for `limit`, per the spec:
* If undefined: 4294967295 // maxSafe32BitInt
* If 0, Infinity, or NaN: 0
* If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
* If negative number: 4294967296 - Math.floor(Math.abs(limit))
* If other: Type-convert, then use the above rules
*/
var splitLimit = typeof limit === 'undefined' ? maxSafe32BitInt : ES.ToUint32(limit);
match = separatorCopy.exec(string);
while (match) {
// `separatorCopy.lastIndex` is not reliable cross-browser
lastIndex = match.index + match[0].length;
if (lastIndex > lastLastIndex) {
array_push.call(output, strSlice(string, lastLastIndex, match.index));
// Fix browsers whose `exec` methods don't consistently return `undefined` for
// nonparticipating capturing groups
if (!compliantExecNpcg && match.length > 1) {
/* eslint-disable no-loop-func */
match[0].replace(separator2, function () {
for (var i = 1; i < arguments.length - 2; i++) {
if (typeof arguments[i] === 'undefined') {
match[i] = void 0;
}
}
});
/* eslint-enable no-loop-func */
}
if (match.length > 1 && match.index < string.length) {
array_push.apply(output, array_slice.call(match, 1));
}
lastLength = match[0].length;
lastLastIndex = lastIndex;
if (output.length >= splitLimit) {
break;
}
}
if (separatorCopy.lastIndex === match.index) {
separatorCopy.lastIndex++; // Avoid an infinite loop
}
match = separatorCopy.exec(string);
}
if (lastLastIndex === string.length) {
if (lastLength || !separatorCopy.test('')) {
array_push.call(output, '');
}
} else {
array_push.call(output, strSlice(string, lastLastIndex));
}
return output.length > splitLimit ? strSlice(output, 0, splitLimit) : output;
};
}());
// [bugfix, chrome]
// If separator is undefined, then the result array contains just one String,
// which is the this value (converted to a String). If limit is not undefined,
// then the output array is truncated so that it contains no more than limit
// elements.
// "0".split(undefined, 0) -> []
} else if ('0'.split(void 0, 0).length) {
StringPrototype.split = function split(separator, limit) {
if (typeof separator === 'undefined' && limit === 0) { return []; }
return strSplit(this, separator, limit);
};
}
var str_replace = StringPrototype.replace;
var replaceReportsGroupsCorrectly = (function () {
var groups = [];
'x'.replace(/x(.)?/g, function (match, group) {
array_push.call(groups, group);
});
return groups.length === 1 && typeof groups[0] === 'undefined';
}());
if (!replaceReportsGroupsCorrectly) {
StringPrototype.replace = function replace(searchValue, replaceValue) {
var isFn = isCallable(replaceValue);
var hasCapturingGroups = isRegex(searchValue) && (/\)[*?]/).test(searchValue.source);
if (!isFn || !hasCapturingGroups) {
return str_replace.call(this, searchValue, replaceValue);
} else {
var wrappedReplaceValue = function (match) {
var length = arguments.length;
var originalLastIndex = searchValue.lastIndex;
searchValue.lastIndex = 0;
var args = searchValue.exec(match) || [];
searchValue.lastIndex = originalLastIndex;
array_push.call(args, arguments[length - 2], arguments[length - 1]);
return replaceValue.apply(this, args);
};
return str_replace.call(this, searchValue, wrappedReplaceValue);
}
};
}
// ECMA-262, 3rd B.2.3
// Not an ECMAScript standard, although ECMAScript 3rd Edition has a
// non-normative section suggesting uniform semantics and it should be
// normalized across all browsers
// [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
var string_substr = StringPrototype.substr;
var hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';
defineProperties(StringPrototype, {
substr: function substr(start, length) {
var normalizedStart = start;
if (start < 0) {
normalizedStart = max(this.length + start, 0);
}
return string_substr.call(this, normalizedStart, length);
}
}, hasNegativeSubstrBug);
// ES5 15.5.4.20
// whitespace from: http://es5.github.io/#x15.5.4.20
var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' +
'\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' +
'\u2029\uFEFF';
var zeroWidth = '\u200b';
var wsRegexChars = '[' + ws + ']';
var trimBeginRegexp = new RegExp('^' + wsRegexChars + wsRegexChars + '*');
var trimEndRegexp = new RegExp(wsRegexChars + wsRegexChars + '*$');
var hasTrimWhitespaceBug = StringPrototype.trim && (ws.trim() || !zeroWidth.trim());
defineProperties(StringPrototype, {
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
// http://perfectionkills.com/whitespace-deviations/
trim: function trim() {
if (typeof this === 'undefined' || this === null) {
throw new TypeError("can't convert " + this + ' to object');
}
return $String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
}
}, hasTrimWhitespaceBug);
var hasLastIndexBug = String.prototype.lastIndexOf && 'abcあい'.lastIndexOf('あい', 2) !== -1;
defineProperties(StringPrototype, {
lastIndexOf: function lastIndexOf(searchString) {
if (typeof this === 'undefined' || this === null) {
throw new TypeError("can't convert " + this + ' to object');
}
var S = $String(this);
var searchStr = $String(searchString);
var numPos = arguments.length > 1 ? $Number(arguments[1]) : NaN;
var pos = isActualNaN(numPos) ? Infinity : ES.ToInteger(numPos);
var start = min(max(pos, 0), S.length);
var searchLen = searchStr.length;
var k = start + searchLen;
while (k > 0) {
k = max(0, k - searchLen);
var index = strIndexOf(strSlice(S, k, start + searchLen), searchStr);
if (index !== -1) {
return k + index;
}
}
return -1;
}
}, hasLastIndexBug);
// ES-5 15.1.2.2
if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
/* global parseInt: true */
parseInt = (function (origParseInt) {
var hexRegex = /^0[xX]/;
return function parseInt(str, radix) {
var string = $String(str).trim();
var defaultedRadix = $Number(radix) || (hexRegex.test(string) ? 16 : 10);
return origParseInt(string, defaultedRadix);
};
}(parseInt));
}
}));
| staticmatrix/Triangle | refer/modules/es5-shim/4.2.0/es5-shim.js | JavaScript | mit | 61,950 |
// https://github.com/isaacs/sax-js/issues/124
require(__dirname).test
( { xml : "<!-- stand alone comment -->"
, expect :
[ [ "comment", " stand alone comment " ] ]
, strict : true
, opt : {}
}
)
| apere/spark.blog | wp-content/themes/sheri-theme/node_modules/gulp-imagemin/node_modules/imagemin/node_modules/imagemin-svgo/node_modules/svgo/node_modules/sax/test/stand-alone-comment.js | JavaScript | gpl-2.0 | 225 |
<?php
namespace Drupal\views_ui\Form\Ajax;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\ViewEntityInterface;
use Drupal\views\Views;
/**
* Provides a form for adding an item in the Views UI.
*/
class AddHandler extends ViewsFormBase {
/**
* Constructs a new AddHandler object.
*/
public function __construct($type = NULL) {
$this->setType($type);
}
/**
* {@inheritdoc}
*/
public function getFormKey() {
return 'add-handler';
}
/**
* {@inheritdoc}
*/
public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL) {
$this->setType($type);
return parent::getForm($view, $display_id, $js);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'views_ui_add_handler_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$view = $form_state->get('view');
$display_id = $form_state->get('display_id');
$type = $form_state->get('type');
$form = array(
'options' => array(
'#theme_wrappers' => array('container'),
'#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE),
),
);
$executable = $view->getExecutable();
if (!$executable->setDisplay($display_id)) {
$form['markup'] = array('#markup' => $this->t('Invalid display id @display', array('@display' => $display_id)));
return $form;
}
$display = &$executable->displayHandlers->get($display_id);
$types = ViewExecutable::getHandlerTypes();
$ltitle = $types[$type]['ltitle'];
$section = $types[$type]['plural'];
if (!empty($types[$type]['type'])) {
$type = $types[$type]['type'];
}
$form['#title'] = $this->t('Add @type', array('@type' => $ltitle));
$form['#section'] = $display_id . 'add-handler';
// Add the display override dropdown.
views_ui_standard_display_dropdown($form, $form_state, $section);
// Figure out all the base tables allowed based upon what the relationships provide.
$base_tables = $executable->getBaseTables();
$options = Views::viewsDataHelper()->fetchFields(array_keys($base_tables), $type, $display->useGroupBy(), $form_state->get('type'));
if (!empty($options)) {
$form['override']['controls'] = array(
'#theme_wrappers' => array('container'),
'#id' => 'views-filterable-options-controls',
'#attributes' => ['class' => ['form--inline', 'views-filterable-options-controls']],
);
$form['override']['controls']['options_search'] = array(
'#type' => 'textfield',
'#title' => $this->t('Search'),
);
$groups = array('all' => $this->t('- All -'));
$form['override']['controls']['group'] = array(
'#type' => 'select',
'#title' => $this->t('Type'),
'#options' => array(),
);
$form['options']['name'] = array(
'#prefix' => '<div class="views-radio-box form-checkboxes views-filterable-options">',
'#suffix' => '</div>',
'#type' => 'tableselect',
'#header' => array(
'title' => $this->t('Title'),
'group' => $this->t('Category'),
'help' => $this->t('Description'),
),
'#js_select' => FALSE,
);
$grouped_options = array();
foreach ($options as $key => $option) {
$group = preg_replace('/[^a-z0-9]/', '-', strtolower($option['group']));
$groups[$group] = $option['group'];
$grouped_options[$group][$key] = $option;
if (!empty($option['aliases']) && is_array($option['aliases'])) {
foreach ($option['aliases'] as $id => $alias) {
if (empty($alias['base']) || !empty($base_tables[$alias['base']])) {
$copy = $option;
$copy['group'] = $alias['group'];
$copy['title'] = $alias['title'];
if (isset($alias['help'])) {
$copy['help'] = $alias['help'];
}
$group = preg_replace('/[^a-z0-9]/', '-', strtolower($copy['group']));
$groups[$group] = $copy['group'];
$grouped_options[$group][$key . '$' . $id] = $copy;
}
}
}
}
foreach ($grouped_options as $group => $group_options) {
foreach ($group_options as $key => $option) {
$form['options']['name']['#options'][$key] = array(
'#attributes' => array(
'class' => array('filterable-option', $group),
),
'title' => array(
'data' => array(
'#title' => $option['title'],
'#plain_text' => $option['title'],
),
'class' => array('title'),
),
'group' => $option['group'],
'help' => array(
'data' => $option['help'],
'class' => array('description'),
),
);
}
}
$form['override']['controls']['group']['#options'] = $groups;
}
else {
$form['options']['markup'] = array(
'#markup' => '<div class="js-form-item form-item">' . $this->t('There are no @types available to add.', array('@types' => $ltitle)) . '</div>',
);
}
// Add a div to show the selected items
$form['selected'] = array(
'#type' => 'item',
'#markup' => '<span class="views-ui-view-title">' . $this->t('Selected:') . '</span> ' . '<div class="views-selected-options"></div>',
'#theme_wrappers' => array('form_element', 'views_ui_container'),
'#attributes' => array(
'class' => array('container-inline', 'views-add-form-selected', 'views-offset-bottom'),
'data-drupal-views-offset' => 'bottom',
),
);
$view->getStandardButtons($form, $form_state, 'views_ui_add_handler_form', $this->t('Add and configure @types', array('@types' => $ltitle)));
// Remove the default submit function.
$form['actions']['submit']['#submit'] = array_filter($form['actions']['submit']['#submit'], function($var) {
return !(is_array($var) && isset($var[1]) && $var[1] == 'standardSubmit');
});
$form['actions']['submit']['#submit'][] = array($view, 'submitItemAdd');
return $form;
}
}
| ngbentley/d8_devshop | web/core/modules/views_ui/src/Form/Ajax/AddHandler.php | PHP | gpl-2.0 | 6,305 |
<?php
class meter
{
function __construct()
{
}
function makeSVG($tag, $type, $value, $max, $min, $optimum, $low, $high)
{
$svg = '';
if ($tag == 'meter') {
if ($type == '2') {
/////////////////////////////////////////////////////////////////////////////////////
///////// CUSTOM <meter type="2">
/////////////////////////////////////////////////////////////////////////////////////
$h = 10;
$w = 160;
$border_radius = 0.143; // Factor of Height
$svg = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="' . $w . 'px" height="' . $h . 'px" viewBox="0 0 ' . $w . ' ' . $h . '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ><g>
<defs>
<linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
<stop offset="0%" stop-color="rgb(222, 222, 222)" />
<stop offset="20%" stop-color="rgb(232, 232, 232)" />
<stop offset="25%" stop-color="rgb(232, 232, 232)" />
<stop offset="100%" stop-color="rgb(182, 182, 182)" />
</linearGradient>
</defs>
';
$svg .= '<rect x="0" y="0" width="' . $w . '" height="' . $h . '" fill="#f4f4f4" stroke="none" />';
// LOW to HIGH region
//if ($low && $high && ($low != $min || $high != $max)) {
if ($low && $high) {
$barx = (($low - $min) / ($max - $min) ) * $w;
$barw = (($high - $low) / ($max - $min) ) * $w;
$svg .= '<rect x="' . $barx . '" y="0" width="' . $barw . '" height="' . $h . '" fill="url(#GrGRAY)" stroke="#888888" stroke-width="0.5px" />';
}
// OPTIMUM Marker (? AVERAGE)
if ($optimum) {
$barx = (($optimum - $min) / ($max - $min) ) * $w;
$barw = $h / 2;
$barcol = '#888888';
$svg .= '<rect x="' . $barx . '" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $barw . '" height="' . $h . '" fill="' . $barcol . '" stroke="none" />';
}
// VALUE Marker
if ($value) {
if ($min != $low && $value < $low) {
$col = 'orange';
} else if ($max != $high && $value > $high) {
$col = 'orange';
} else {
$col = '#008800';
}
$cx = (($value - $min) / ($max - $min) ) * $w;
$cy = $h / 2;
$rx = $h / 3.5;
$ry = $h / 2.2;
$svg .= '<ellipse fill="' . $col . '" stroke="#000000" stroke-width="0.5px" cx="' . $cx . '" cy="' . $cy . '" rx="' . $rx . '" ry="' . $ry . '"/>';
}
// BoRDER
$svg .= '<rect x="0" y="0" width="' . $w . '" height="' . $h . '" fill="none" stroke="#888888" stroke-width="0.5px" />';
$svg .= '</g></svg>';
} else if ($type == '3') {
/////////////////////////////////////////////////////////////////////////////////////
///////// CUSTOM <meter type="2">
/////////////////////////////////////////////////////////////////////////////////////
$h = 10;
$w = 100;
$border_radius = 0.143; // Factor of Height
$svg = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="' . $w . 'px" height="' . $h . 'px" viewBox="0 0 ' . $w . ' ' . $h . '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ><g>
<defs>
<linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
<stop offset="0%" stop-color="rgb(222, 222, 222)" />
<stop offset="20%" stop-color="rgb(232, 232, 232)" />
<stop offset="25%" stop-color="rgb(232, 232, 232)" />
<stop offset="100%" stop-color="rgb(182, 182, 182)" />
</linearGradient>
</defs>
';
$svg .= '<rect x="0" y="0" width="' . $w . '" height="' . $h . '" fill="#f4f4f4" stroke="none" />';
// LOW to HIGH region
if ($low && $high && ($low != $min || $high != $max)) {
//if ($low && $high) {
$barx = (($low - $min) / ($max - $min) ) * $w;
$barw = (($high - $low) / ($max - $min) ) * $w;
$svg .= '<rect x="' . $barx . '" y="0" width="' . $barw . '" height="' . $h . '" fill="url(#GrGRAY)" stroke="#888888" stroke-width="0.5px" />';
}
// OPTIMUM Marker (? AVERAGE)
if ($optimum) {
$barx = (($optimum - $min) / ($max - $min) ) * $w;
$barw = $h / 2;
$barcol = '#888888';
$svg .= '<rect x="' . $barx . '" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $barw . '" height="' . $h . '" fill="' . $barcol . '" stroke="none" />';
}
// VALUE Marker
if ($value) {
if ($min != $low && $value < $low) {
$col = 'orange';
} else if ($max != $high && $value > $high) {
$col = 'orange';
} else {
$col = 'orange';
}
$cx = (($value - $min) / ($max - $min) ) * $w;
$cy = $h / 2;
$rx = $h / 2.2;
$ry = $h / 2.2;
$svg .= '<ellipse fill="' . $col . '" stroke="#000000" stroke-width="0.5px" cx="' . $cx . '" cy="' . $cy . '" rx="' . $rx . '" ry="' . $ry . '"/>';
}
// BoRDER
$svg .= '<rect x="0" y="0" width="' . $w . '" height="' . $h . '" fill="none" stroke="#888888" stroke-width="0.5px" />';
$svg .= '</g></svg>';
} else {
/////////////////////////////////////////////////////////////////////////////////////
///////// DEFAULT <meter>
/////////////////////////////////////////////////////////////////////////////////////
$h = 10;
$w = 50;
$border_radius = 0.143; // Factor of Height
$svg = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="' . $w . 'px" height="' . $h . 'px" viewBox="0 0 ' . $w . ' ' . $h . '" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ><g>
<defs>
<linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
<stop offset="0%" stop-color="rgb(222, 222, 222)" />
<stop offset="20%" stop-color="rgb(232, 232, 232)" />
<stop offset="25%" stop-color="rgb(232, 232, 232)" />
<stop offset="100%" stop-color="rgb(182, 182, 182)" />
</linearGradient>
<linearGradient id="GrRED" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
<stop offset="0%" stop-color="rgb(255, 162, 162)" />
<stop offset="20%" stop-color="rgb(255, 218, 218)" />
<stop offset="25%" stop-color="rgb(255, 218, 218)" />
<stop offset="100%" stop-color="rgb(255, 0, 0)" />
</linearGradient>
<linearGradient id="GrGREEN" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
<stop offset="0%" stop-color="rgb(102, 230, 102)" />
<stop offset="20%" stop-color="rgb(218, 255, 218)" />
<stop offset="25%" stop-color="rgb(218, 255, 218)" />
<stop offset="100%" stop-color="rgb(0, 148, 0)" />
</linearGradient>
<linearGradient id="GrBLUE" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
<stop offset="0%" stop-color="rgb(102, 102, 230)" />
<stop offset="20%" stop-color="rgb(238, 238, 238)" />
<stop offset="25%" stop-color="rgb(238, 238, 238)" />
<stop offset="100%" stop-color="rgb(0, 0, 128)" />
</linearGradient>
<linearGradient id="GrORANGE" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
<stop offset="0%" stop-color="rgb(255, 186, 0)" />
<stop offset="20%" stop-color="rgb(255, 238, 168)" />
<stop offset="25%" stop-color="rgb(255, 238, 168)" />
<stop offset="100%" stop-color="rgb(255, 155, 0)" />
</linearGradient>
</defs>
<rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $w . '" height="' . $h . '" fill="url(#GrGRAY)" stroke="none" />
';
if ($value) {
$barw = (($value - $min) / ($max - $min) ) * $w;
if ($optimum < $low) {
if ($value < $low) {
$barcol = 'url(#GrGREEN)';
} else if ($value > $high) {
$barcol = 'url(#GrRED)';
} else {
$barcol = 'url(#GrORANGE)';
}
} else if ($optimum > $high) {
if ($value < $low) {
$barcol = 'url(#GrRED)';
} else if ($value > $high) {
$barcol = 'url(#GrGREEN)';
} else {
$barcol = 'url(#GrORANGE)';
}
} else {
if ($value < $low) {
$barcol = 'url(#GrORANGE)';
} else if ($value > $high) {
$barcol = 'url(#GrORANGE)';
} else {
$barcol = 'url(#GrGREEN)';
}
}
$svg .= '<rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $barw . '" height="' . $h . '" fill="' . $barcol . '" stroke="none" />';
}
// Borders
//$svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$w.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />';
if ($value) {
// $svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />';
}
$svg .= '</g></svg>';
}
} else { // $tag == 'progress'
if ($type == '2') {
/////////////////////////////////////////////////////////////////////////////////////
///////// CUSTOM <progress type="2">
/////////////////////////////////////////////////////////////////////////////////////
} else {
/////////////////////////////////////////////////////////////////////////////////////
///////// DEFAULT <progress>
/////////////////////////////////////////////////////////////////////////////////////
$h = 10;
$w = 100;
$border_radius = 0.143; // Factor of Height
if ($value or $value === '0') {
$fill = 'url(#GrGRAY)';
} else {
$fill = '#f8f8f8';
}
$svg = '<svg width="' . $w . 'px" height="' . $h . 'px" viewBox="0 0 ' . $w . ' ' . $h . '"><g>
<defs>
<linearGradient id="GrGRAY" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
<stop offset="0%" stop-color="rgb(222, 222, 222)" />
<stop offset="20%" stop-color="rgb(232, 232, 232)" />
<stop offset="25%" stop-color="rgb(232, 232, 232)" />
<stop offset="100%" stop-color="rgb(182, 182, 182)" />
</linearGradient>
<linearGradient id="GrGREEN" x1="0" y1="0" x2="0" y2="1" gradientUnits="boundingBox">
<stop offset="0%" stop-color="rgb(102, 230, 102)" />
<stop offset="20%" stop-color="rgb(218, 255, 218)" />
<stop offset="25%" stop-color="rgb(218, 255, 218)" />
<stop offset="100%" stop-color="rgb(0, 148, 0)" />
</linearGradient>
</defs>
<rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $w . '" height="' . $h . '" fill="' . $fill . '" stroke="none" />
';
if ($value) {
$barw = (($value - $min) / ($max - $min) ) * $w;
$barcol = 'url(#GrGREEN)';
$svg .= '<rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $barw . '" height="' . $h . '" fill="' . $barcol . '" stroke="none" />';
}
// Borders
$svg .= '<rect x="0" y="0" rx="' . ($h * $border_radius) . 'px" ry="' . ($h * $border_radius) . 'px" width="' . $w . '" height="' . $h . '" fill="none" stroke="#888888" stroke-width="0.5px" />';
if ($value) {
// $svg .= '<rect x="0" y="0" rx="'.($h*$border_radius).'px" ry="'.($h*$border_radius).'px" width="'.$barw.'" height="'.$h.'" fill="none" stroke="#888888" stroke-width="0.5px" />';
}
$svg .= '</g></svg>';
}
}
return $svg;
}
}
| wp-rio/wp-rio | wp-content/themes/wp-rio/inc/certificate/lib/mpdf/classes/meter.php | PHP | gpl-2.0 | 11,355 |
/*
* TI OMAP2 32kHz sync timer emulation.
*
* Copyright (C) 2007-2008 Nokia Corporation
* Written by Andrzej Zaborowski <andrew@openedhand.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 or
* (at your option) any later version of the License.
*
* 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 "hw.h"
#include "qemu-timer.h"
#include "omap.h"
struct omap_synctimer_s {
MemoryRegion iomem;
uint32_t val;
uint16_t readh;
};
/* 32-kHz Sync Timer of the OMAP2 */
static uint32_t omap_synctimer_read(struct omap_synctimer_s *s) {
return muldiv64(qemu_get_clock_ns(vm_clock), 0x8000, get_ticks_per_sec());
}
void omap_synctimer_reset(struct omap_synctimer_s *s)
{
s->val = omap_synctimer_read(s);
}
static uint32_t omap_synctimer_readw(void *opaque, target_phys_addr_t addr)
{
struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque;
switch (addr) {
case 0x00: /* 32KSYNCNT_REV */
return 0x21;
case 0x10: /* CR */
return omap_synctimer_read(s) - s->val;
}
OMAP_BAD_REG(addr);
return 0;
}
static uint32_t omap_synctimer_readh(void *opaque, target_phys_addr_t addr)
{
struct omap_synctimer_s *s = (struct omap_synctimer_s *) opaque;
uint32_t ret;
if (addr & 2)
return s->readh;
else {
ret = omap_synctimer_readw(opaque, addr);
s->readh = ret >> 16;
return ret & 0xffff;
}
}
static void omap_synctimer_write(void *opaque, target_phys_addr_t addr,
uint32_t value)
{
OMAP_BAD_REG(addr);
}
static const MemoryRegionOps omap_synctimer_ops = {
.old_mmio = {
.read = {
omap_badwidth_read32,
omap_synctimer_readh,
omap_synctimer_readw,
},
.write = {
omap_badwidth_write32,
omap_synctimer_write,
omap_synctimer_write,
},
},
.endianness = DEVICE_NATIVE_ENDIAN,
};
struct omap_synctimer_s *omap_synctimer_init(struct omap_target_agent_s *ta,
struct omap_mpu_state_s *mpu, omap_clk fclk, omap_clk iclk)
{
struct omap_synctimer_s *s = g_malloc0(sizeof(*s));
omap_synctimer_reset(s);
memory_region_init_io(&s->iomem, &omap_synctimer_ops, s, "omap.synctimer",
omap_l4_region_size(ta, 0));
omap_l4_attach(ta, 0, &s->iomem);
return s;
}
| SSLAB-HSA/HSAemu | qemu/hw/omap_synctimer.c | C | gpl-3.0 | 2,861 |
/************************************************************
Copyright 1996 by Thomas E. Dickey <dickey@clark.net>
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of the above listed
copyright holder(s) not be used in advertising or publicity pertaining
to distribution of the software without specific, written prior
permission.
THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
LIABLE FOR ANY SPECIAL, 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.
********************************************************/
#ifndef DIXGRABS_H
#define DIXGRABS_H 1
struct _GrabParameters;
extern GrabPtr CreateGrab(
int /* client */,
DeviceIntPtr /* device */,
DeviceIntPtr /* modDevice */,
WindowPtr /* window */,
GrabType /* grabtype */,
GrabMask * /* mask */,
struct _GrabParameters * /* param */,
int /* type */,
KeyCode /* keybut */,
WindowPtr /* confineTo */,
CursorPtr /* cursor */);
extern _X_EXPORT int DeletePassiveGrab(
pointer /* value */,
XID /* id */);
extern _X_EXPORT Bool GrabMatchesSecond(
GrabPtr /* pFirstGrab */,
GrabPtr /* pSecondGrab */,
Bool /*ignoreDevice*/);
extern _X_EXPORT int AddPassiveGrabToList(
ClientPtr /* client */,
GrabPtr /* pGrab */);
extern _X_EXPORT Bool DeletePassiveGrabFromList(
GrabPtr /* pMinuendGrab */);
#endif /* DIXGRABS_H */
| execunix/vinos | xsrc/external/mit/xorg-server/dist/include/dixgrabs.h | C | apache-2.0 | 2,009 |
/*
* mostcore.h - Interface between MostCore,
* Hardware Dependent Module (HDM) and Application Interface Module (AIM).
*
* Copyright (C) 2013-2015, Microchip Technology Germany II GmbH & Co. KG
*
* 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 file is licensed under GPLv2.
*/
/*
* Authors:
* Andrey Shvetsov <andrey.shvetsov@k2l.de>
* Christian Gromm <christian.gromm@microchip.com>
* Sebastian Graf
*/
#ifndef __MOST_CORE_H__
#define __MOST_CORE_H__
#include <linux/types.h>
struct kobject;
struct module;
/**
* Interface type
*/
enum most_interface_type {
ITYPE_LOOPBACK = 1,
ITYPE_I2C,
ITYPE_I2S,
ITYPE_TSI,
ITYPE_HBI,
ITYPE_MEDIALB_DIM,
ITYPE_MEDIALB_DIM2,
ITYPE_USB,
ITYPE_PCIE
};
/**
* Channel direction.
*/
enum most_channel_direction {
MOST_CH_RX = 1 << 0,
MOST_CH_TX = 1 << 1,
};
/**
* Channel data type.
*/
enum most_channel_data_type {
MOST_CH_CONTROL = 1 << 0,
MOST_CH_ASYNC = 1 << 1,
MOST_CH_ISOC = 1 << 2,
MOST_CH_SYNC = 1 << 5,
};
enum mbo_status_flags {
/* MBO was processed successfully (data was send or received )*/
MBO_SUCCESS = 0,
/* The MBO contains wrong or missing information. */
MBO_E_INVAL,
/* MBO was completed as HDM Channel will be closed */
MBO_E_CLOSE,
};
/**
* struct most_channel_capability - Channel capability
* @direction: Supported channel directions.
* The value is bitwise OR-combination of the values from the
* enumeration most_channel_direction. Zero is allowed value and means
* "channel may not be used".
* @data_type: Supported channel data types.
* The value is bitwise OR-combination of the values from the
* enumeration most_channel_data_type. Zero is allowed value and means
* "channel may not be used".
* @num_buffer_packet: Maximum number of buffers supported by this channel
* for packet data types (Async,Control,QoS)
* @buffer_size_packet: Maximum buffer size supported by this channel
* for packet data types (Async,Control,QoS)
* @num_buffer_streaming: Maximum number of buffers supported by this channel
* for streaming data types (Sync,AV Packetized)
* @buffer_size_streaming: Maximum buffer size supported by this channel
* for streaming data types (Sync,AV Packetized)
* @name_suffix: Optional suffix providean by an HDM that is attached to the
* regular channel name.
*
* Describes the capabilities of a MostCore channel like supported Data Types
* and directions. This information is provided by an HDM for the MostCore.
*
* The Core creates read only sysfs attribute files in
* /sys/devices/virtual/most/mostcore/devices/mdev-#/mdev#-ch#/ with the
* following attributes:
* -available_directions
* -available_datatypes
* -number_of_packet_buffers
* -number_of_stream_buffers
* -size_of_packet_buffer
* -size_of_stream_buffer
* where content of each file is a string with all supported properties of this
* very channel attribute.
*/
struct most_channel_capability {
u16 direction;
u16 data_type;
u16 num_buffers_packet;
u16 buffer_size_packet;
u16 num_buffers_streaming;
u16 buffer_size_streaming;
const char *name_suffix;
};
/**
* struct most_channel_config - stores channel configuration
* @direction: direction of the channel
* @data_type: data type travelling over this channel
* @num_buffers: number of buffers
* @buffer_size: size of a buffer for AIM.
* Buffer size may be cutted down by HDM in a configure callback
* to match to a given interface and channel type.
* @extra_len: additional buffer space for internal HDM purposes like padding.
* May be set by HDM in a configure callback if needed.
* @subbuffer_size: size of a subbuffer
* @packets_per_xact: number of MOST frames that are packet inside one USB
* packet. This is USB specific
*
* Describes the configuration for a MostCore channel. This information is
* provided from the MostCore to a HDM (like the Medusa PCIe Interface) as a
* parameter of the "configure" function call.
*/
struct most_channel_config {
enum most_channel_direction direction;
enum most_channel_data_type data_type;
u16 num_buffers;
u16 buffer_size;
u16 extra_len;
u16 subbuffer_size;
u16 packets_per_xact;
};
/*
* struct mbo - MOST Buffer Object.
* @context: context for core completion handler
* @priv: private data for HDM
*
* public: documented fields that are used for the communications
* between MostCore and HDMs
*
* @list: list head for use by the mbo's current owner
* @ifp: (in) associated interface instance
* @hdm_channel_id: (in) HDM channel instance
* @virt_address: (in) kernel virtual address of the buffer
* @bus_address: (in) bus address of the buffer
* @buffer_length: (in) buffer payload length
* @processed_length: (out) processed length
* @status: (out) transfer status
* @complete: (in) completion routine
*
* The MostCore allocates and initializes the MBO.
*
* The HDM receives MBO for transfer from MostCore with the call to enqueue().
* The HDM copies the data to- or from the buffer depending on configured
* channel direction, set "processed_length" and "status" and completes
* the transfer procedure by calling the completion routine.
*
* At the end the MostCore deallocates the MBO or recycles it for further
* transfers for the same or different HDM.
*
* Directions of usage:
* The core driver should never access any MBO fields (even if marked
* as "public") while the MBO is owned by an HDM. The ownership starts with
* the call of enqueue() and ends with the call of its complete() routine.
*
* II.
* Every HDM attached to the core driver _must_ ensure that it returns any MBO
* it owns (due to a previous call to enqueue() by the core driver) before it
* de-registers an interface or gets unloaded from the kernel. If this direction
* is violated memory leaks will occur, since the core driver does _not_ track
* MBOs it is currently not in control of.
*
*/
struct mbo {
void *context;
void *priv;
struct list_head list;
struct most_interface *ifp;
int *num_buffers_ptr;
u16 hdm_channel_id;
void *virt_address;
dma_addr_t bus_address;
u16 buffer_length;
u16 processed_length;
enum mbo_status_flags status;
void (*complete)(struct mbo *);
};
/**
* Interface instance description.
*
* Describes one instance of an interface like Medusa PCIe or Vantage USB.
* This structure is allocated and initialized in the HDM. MostCore may not
* modify this structure.
*
* @interface Interface type. \sa most_interface_type.
* @description PRELIMINARY.
* Unique description of the device instance from point of view of the
* interface in free text form (ASCII).
* It may be a hexadecimal presentation of the memory address for the MediaLB
* IP or USB device ID with USB properties for USB interface, etc.
* @num_channels Number of channels and size of the channel_vector.
* @channel_vector Properties of the channels.
* Array index represents channel ID by the driver.
* @configure Callback to change data type for the channel of the
* interface instance. May be zero if the instance of the interface is not
* configurable. Parameter channel_config describes direction and data
* type for the channel, configured by the higher level. The content of
* @enqueue Delivers MBO to the HDM for processing.
* After HDM completes Rx- or Tx- operation the processed MBO shall
* be returned back to the MostCore using completion routine.
* The reason to get the MBO delivered from the MostCore after the channel
* is poisoned is the re-opening of the channel by the application.
* In this case the HDM shall hold MBOs and service the channel as usual.
* The HDM must be able to hold at least one MBO for each channel.
* The callback returns a negative value on error, otherwise 0.
* @poison_channel Informs HDM about closing the channel. The HDM shall
* cancel all transfers and synchronously or asynchronously return
* all enqueued for this channel MBOs using the completion routine.
* The callback returns a negative value on error, otherwise 0.
* @request_netinfo: triggers retrieving of network info from the HDM by
* means of "Message exchange over MDP/MEP"
* The call of the function request_netinfo with the parameter on_netinfo as
* NULL prohibits use of the previously obtained function pointer.
* @priv Private field used by mostcore to store context information.
*/
struct most_interface {
struct module *mod;
enum most_interface_type interface;
const char *description;
int num_channels;
struct most_channel_capability *channel_vector;
int (*configure)(struct most_interface *iface, int channel_idx,
struct most_channel_config *channel_config);
int (*enqueue)(struct most_interface *iface, int channel_idx,
struct mbo *mbo);
int (*poison_channel)(struct most_interface *iface, int channel_idx);
void (*request_netinfo)(struct most_interface *iface, int channel_idx,
void (*on_netinfo)(struct most_interface *iface,
unsigned char link_stat,
unsigned char *mac_addr));
void *priv;
};
/**
* struct most_aim - identifies MOST device driver to mostcore
* @name: Driver name
* @probe_channel: function for core to notify driver about channel connection
* @disconnect_channel: callback function to disconnect a certain channel
* @rx_completion: completion handler for received packets
* @tx_completion: completion handler for transmitted packets
* @context: context pointer to be used by mostcore
*/
struct most_aim {
const char *name;
int (*probe_channel)(struct most_interface *iface, int channel_idx,
struct most_channel_config *cfg,
struct kobject *parent, char *name);
int (*disconnect_channel)(struct most_interface *iface,
int channel_idx);
int (*rx_completion)(struct mbo *mbo);
int (*tx_completion)(struct most_interface *iface, int channel_idx);
void *context;
};
/**
* most_register_interface - Registers instance of the interface.
* @iface: Pointer to the interface instance description.
*
* Returns a pointer to the kobject of the generated instance.
*
* Note: HDM has to ensure that any reference held on the kobj is
* released before deregistering the interface.
*/
struct kobject *most_register_interface(struct most_interface *iface);
/**
* Deregisters instance of the interface.
* @intf_instance Pointer to the interface instance description.
*/
void most_deregister_interface(struct most_interface *iface);
void most_submit_mbo(struct mbo *mbo);
/**
* most_stop_enqueue - prevents core from enqueing MBOs
* @iface: pointer to interface
* @channel_idx: channel index
*/
void most_stop_enqueue(struct most_interface *iface, int channel_idx);
/**
* most_resume_enqueue - allow core to enqueue MBOs again
* @iface: pointer to interface
* @channel_idx: channel index
*
* This clears the enqueue halt flag and enqueues all MBOs currently
* in wait fifo.
*/
void most_resume_enqueue(struct most_interface *iface, int channel_idx);
int most_register_aim(struct most_aim *aim);
int most_deregister_aim(struct most_aim *aim);
struct mbo *most_get_mbo(struct most_interface *iface, int channel_idx,
struct most_aim *);
void most_put_mbo(struct mbo *mbo);
int channel_has_mbo(struct most_interface *iface, int channel_idx,
struct most_aim *aim);
int most_start_channel(struct most_interface *iface, int channel_idx,
struct most_aim *);
int most_stop_channel(struct most_interface *iface, int channel_idx,
struct most_aim *);
#endif /* MOST_CORE_H_ */
| BPI-SINOVOIP/BPI-Mainline-kernel | linux-4.14/drivers/staging/most/mostcore/mostcore.h | C | gpl-2.0 | 11,695 |
// -*- C++ -*-
// Copyright (C) 2005-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library 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.
// 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
// General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
// Permission to use, copy, modify, sell, and distribute this software
// is hereby granted without fee, provided that the above copyright
// notice appears in all copies, and that both that copyright notice
// and this permission notice appear in supporting documentation. None
// of the above authors, nor IBM Haifa Research Laboratories, make any
// representation about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
/**
* @file cc_hash_table_map_/cmp_fn_imps.hpp
* Contains implementations of cc_ht_map_'s entire container comparison related
* functions.
*/
PB_DS_CLASS_T_DEC
template<typename Other_HT_Map_Type>
bool
PB_DS_CLASS_C_DEC::
operator==(const Other_HT_Map_Type& other) const
{ return cmp_with_other(other); }
PB_DS_CLASS_T_DEC
template<typename Other_Map_Type>
bool
PB_DS_CLASS_C_DEC::
cmp_with_other(const Other_Map_Type& other) const
{
if (size() != other.size())
return false;
for (typename Other_Map_Type::const_iterator it = other.begin();
it != other.end(); ++it)
{
key_const_reference r_key = key_const_reference(PB_DS_V2F(*it));
mapped_const_pointer p_mapped_value =
const_cast<PB_DS_CLASS_C_DEC& >(*this).
find_key_pointer(r_key, traits_base::m_store_extra_indicator);
if (p_mapped_value == 0)
return false;
#ifdef PB_DS_DATA_TRUE_INDICATOR
if (p_mapped_value->second != it->second)
return false;
#endif
}
return true;
}
PB_DS_CLASS_T_DEC
template<typename Other_HT_Map_Type>
bool
PB_DS_CLASS_C_DEC::
operator!=(const Other_HT_Map_Type& other) const
{ return !operator==(other); }
| ruibarreira/linuxtrail | usr/include/c++/4.9/ext/pb_ds/detail/cc_hash_table_map_/cmp_fn_imps.hpp | C++ | gpl-3.0 | 2,765 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PolyK - pixi.js</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">
<div id="doc">
<div id="hd" class="yui3-g header">
<div class="yui3-u-3-4">
<h1><img src="http://www.goodboydigital.com/pixijs/logo_small.png" title="pixi.js"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 1.5.3</em>
</div>
</div>
<div id="bd" class="yui3-g">
<div class="yui3-u-1-4">
<div id="docs-sidebar" class="sidebar apidocs">
<div id="api-list">
<h2 class="off-left">APIs</h2>
<div id="api-tabview" class="tabview">
<ul class="tabs">
<li><a href="#api-classes">Classes</a></li>
<li><a href="#api-modules">Modules</a></li>
</ul>
<div id="api-tabview-filter">
<input type="search" id="api-filter" placeholder="Type to filter APIs">
</div>
<div id="api-tabview-panel">
<ul id="api-classes" class="apis classes">
<li><a href="../classes/AbstractFilter.html">AbstractFilter</a></li>
<li><a href="../classes/AjaxRequest.html">AjaxRequest</a></li>
<li><a href="../classes/AlphaMaskFilter.html">AlphaMaskFilter</a></li>
<li><a href="../classes/AssetLoader.html">AssetLoader</a></li>
<li><a href="../classes/AtlasLoader.html">AtlasLoader</a></li>
<li><a href="../classes/autoDetectRenderer.html">autoDetectRenderer</a></li>
<li><a href="../classes/BaseTexture.html">BaseTexture</a></li>
<li><a href="../classes/BitmapFontLoader.html">BitmapFontLoader</a></li>
<li><a href="../classes/BitmapText.html">BitmapText</a></li>
<li><a href="../classes/BlurFilter.html">BlurFilter</a></li>
<li><a href="../classes/CanvasGraphics.html">CanvasGraphics</a></li>
<li><a href="../classes/CanvasMaskManager.html">CanvasMaskManager</a></li>
<li><a href="../classes/CanvasRenderer.html">CanvasRenderer</a></li>
<li><a href="../classes/CanvasTinter.html">CanvasTinter</a></li>
<li><a href="../classes/Circle.html">Circle</a></li>
<li><a href="../classes/ColorMatrixFilter.html">ColorMatrixFilter</a></li>
<li><a href="../classes/ColorStepFilter.html">ColorStepFilter</a></li>
<li><a href="../classes/DisplacementFilter.html">DisplacementFilter</a></li>
<li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
<li><a href="../classes/DisplayObjectContainer.html">DisplayObjectContainer</a></li>
<li><a href="../classes/DotScreenFilter.html">DotScreenFilter</a></li>
<li><a href="../classes/Ellipse.html">Ellipse</a></li>
<li><a href="../classes/EventTarget.html">EventTarget</a></li>
<li><a href="../classes/FilterTexture.html">FilterTexture</a></li>
<li><a href="../classes/getRecommendedRenderer.html">getRecommendedRenderer</a></li>
<li><a href="../classes/Graphics.html">Graphics</a></li>
<li><a href="../classes/GrayFilter.html">GrayFilter</a></li>
<li><a href="../classes/ImageLoader.html">ImageLoader</a></li>
<li><a href="../classes/InteractionData.html">InteractionData</a></li>
<li><a href="../classes/InteractionManager.html">InteractionManager</a></li>
<li><a href="../classes/InvertFilter.html">InvertFilter</a></li>
<li><a href="../classes/JsonLoader.html">JsonLoader</a></li>
<li><a href="../classes/MovieClip.html">MovieClip</a></li>
<li><a href="../classes/NormalMapFilter.html">NormalMapFilter</a></li>
<li><a href="../classes/PixelateFilter.html">PixelateFilter</a></li>
<li><a href="../classes/PixiFastShader.html">PixiFastShader</a></li>
<li><a href="../classes/PixiShader.html">PixiShader</a></li>
<li><a href="../classes/Point.html">Point</a></li>
<li><a href="../classes/Polygon.html">Polygon</a></li>
<li><a href="../classes/PolyK.html">PolyK</a></li>
<li><a href="../classes/PrimitiveShader.html">PrimitiveShader</a></li>
<li><a href="../classes/Rectangle.html">Rectangle</a></li>
<li><a href="../classes/Rope.html">Rope</a></li>
<li><a href="../classes/SepiaFilter.html">SepiaFilter</a></li>
<li><a href="../classes/Spine.html">Spine</a></li>
<li><a href="../classes/Sprite.html">Sprite</a></li>
<li><a href="../classes/SpriteBatch.html">SpriteBatch</a></li>
<li><a href="../classes/SpriteSheetLoader.html">SpriteSheetLoader</a></li>
<li><a href="../classes/Stage.html">Stage</a></li>
<li><a href="../classes/Strip.html">Strip</a></li>
<li><a href="../classes/Text.html">Text</a></li>
<li><a href="../classes/Texture.html">Texture</a></li>
<li><a href="../classes/TilingSprite.html">TilingSprite</a></li>
<li><a href="../classes/TwistFilter.html">TwistFilter</a></li>
<li><a href="../classes/WebGLFilterManager.html">WebGLFilterManager</a></li>
<li><a href="../classes/WebGLGraphics.html">WebGLGraphics</a></li>
<li><a href="../classes/WebGLMaskManager.html">WebGLMaskManager</a></li>
<li><a href="../classes/WebGLRenderer.html">WebGLRenderer</a></li>
<li><a href="../classes/WebGLShaderManager.html">WebGLShaderManager</a></li>
<li><a href="../classes/WebGLSpriteBatch.html">WebGLSpriteBatch</a></li>
</ul>
<ul id="api-modules" class="apis modules">
<li><a href="../modules/PIXI.html">PIXI</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="yui3-u-3-4">
<div id="api-options">
Show:
<label for="api-show-inherited">
<input type="checkbox" id="api-show-inherited" checked>
Inherited
</label>
<label for="api-show-protected">
<input type="checkbox" id="api-show-protected">
Protected
</label>
<label for="api-show-private">
<input type="checkbox" id="api-show-private">
Private
</label>
<label for="api-show-deprecated">
<input type="checkbox" id="api-show-deprecated">
Deprecated
</label>
</div>
<div class="apidocs">
<div id="docs-main">
<div class="content">
<h1>PolyK Class</h1>
<div class="box meta">
<div class="foundat">
Defined in: <a href="../files/src_pixi_utils_Polyk.js.html#l34"><code>src/pixi/utils/Polyk.js:34</code></a>
</div>
Module: <a href="../modules/PIXI.html">PIXI</a>
</div>
<div class="box intro">
<p>Based on the Polyk library <a href="http://polyk.ivank.net">http://polyk.ivank.net</a> released under MIT licence.
This is an amazing lib!
slightly modified by Mat Groves (matgroves.com);</p>
</div>
<div id="classdocs" class="tabview">
<ul class="api-class-tabs">
<li class="api-class-tab index"><a href="#index">Index</a></li>
<li class="api-class-tab methods"><a href="#methods">Methods</a></li>
</ul>
<div>
<div id="index" class="api-class-tabpanel index">
<h2 class="off-left">Item Index</h2>
<div class="index-section methods">
<h3>Methods</h3>
<ul class="index-list methods">
<li class="index-item method private">
<a href="#method__convex">_convex</a>
</li>
<li class="index-item method private">
<a href="#method__PointInTriangle">_PointInTriangle</a>
</li>
<li class="index-item method">
<a href="#method_Triangulate">Triangulate</a>
</li>
</ul>
</div>
</div>
<div id="methods" class="api-class-tabpanel">
<h2 class="off-left">Methods</h2>
<div id="method__convex" class="method item private">
<h3 class="name"><code>_convex</code></h3>
<span class="paren">()</span>
<span class="flag private">private</span>
<div class="meta">
<p>
Defined in
<a href="../files/src_pixi_utils_Polyk.js.html#l159"><code>src/pixi/utils/Polyk.js:159</code></a>
</p>
</div>
<div class="description">
<p>Checks whether a shape is convex</p>
</div>
</div>
<div id="method__PointInTriangle" class="method item private">
<h3 class="name"><code>_PointInTriangle</code></h3>
<div class="args">
<span class="paren">(</span><ul class="args-list inline commas">
<li class="arg">
<code>px</code>
</li>
<li class="arg">
<code>py</code>
</li>
<li class="arg">
<code>ax</code>
</li>
<li class="arg">
<code>ay</code>
</li>
<li class="arg">
<code>bx</code>
</li>
<li class="arg">
<code>by</code>
</li>
<li class="arg">
<code>cx</code>
</li>
<li class="arg">
<code>cy</code>
</li>
</ul><span class="paren">)</span>
</div>
<span class="flag private">private</span>
<div class="meta">
<p>
Defined in
<a href="../files/src_pixi_utils_Polyk.js.html#l122"><code>src/pixi/utils/Polyk.js:122</code></a>
</p>
</div>
<div class="description">
<p>Checks whether a point is within a triangle</p>
</div>
<div class="params">
<h4>Parameters:</h4>
<ul class="params-list">
<li class="param">
<code class="param-name">px</code>
<span class="type">Number</span>
<div class="param-description">
<p>x coordinate of the point to test</p>
</div>
</li>
<li class="param">
<code class="param-name">py</code>
<span class="type">Number</span>
<div class="param-description">
<p>y coordinate of the point to test</p>
</div>
</li>
<li class="param">
<code class="param-name">ax</code>
<span class="type">Number</span>
<div class="param-description">
<p>x coordinate of the a point of the triangle</p>
</div>
</li>
<li class="param">
<code class="param-name">ay</code>
<span class="type">Number</span>
<div class="param-description">
<p>y coordinate of the a point of the triangle</p>
</div>
</li>
<li class="param">
<code class="param-name">bx</code>
<span class="type">Number</span>
<div class="param-description">
<p>x coordinate of the b point of the triangle</p>
</div>
</li>
<li class="param">
<code class="param-name">by</code>
<span class="type">Number</span>
<div class="param-description">
<p>y coordinate of the b point of the triangle</p>
</div>
</li>
<li class="param">
<code class="param-name">cx</code>
<span class="type">Number</span>
<div class="param-description">
<p>x coordinate of the c point of the triangle</p>
</div>
</li>
<li class="param">
<code class="param-name">cy</code>
<span class="type">Number</span>
<div class="param-description">
<p>y coordinate of the c point of the triangle</p>
</div>
</li>
</ul>
</div>
</div>
<div id="method_Triangulate" class="method item">
<h3 class="name"><code>Triangulate</code></h3>
<span class="paren">()</span>
<div class="meta">
<p>
Defined in
<a href="../files/src_pixi_utils_Polyk.js.html#l43"><code>src/pixi/utils/Polyk.js:43</code></a>
</p>
</div>
<div class="description">
<p>Triangulates shapes for webGL graphic fills</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>
| prshreshtha/LaseRun | site/docs/pixi/classes/PolyK.html | HTML | apache-2.0 | 18,177 |
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1
import (
"time"
"k8s.io/kubernetes/pkg/api/unversioned"
apiv1 "k8s.io/kubernetes/pkg/api/v1"
client "k8s.io/kubernetes/pkg/client/unversioned"
)
type Policy struct {
unversioned.TypeMeta `json:",inline"`
// Holds the information to configure the fit predicate functions
Predicates []PredicatePolicy `json:"predicates"`
// Holds the information to configure the priority functions
Priorities []PriorityPolicy `json:"priorities"`
// Holds the information to communicate with the extender(s)
ExtenderConfigs []ExtenderConfig `json:"extenders"`
}
type PredicatePolicy struct {
// Identifier of the predicate policy
// For a custom predicate, the name can be user-defined
// For the Kubernetes provided predicates, the name is the identifier of the pre-defined predicate
Name string `json:"name"`
// Holds the parameters to configure the given predicate
Argument *PredicateArgument `json:"argument"`
}
type PriorityPolicy struct {
// Identifier of the priority policy
// For a custom priority, the name can be user-defined
// For the Kubernetes provided priority functions, the name is the identifier of the pre-defined priority function
Name string `json:"name"`
// The numeric multiplier for the node scores that the priority function generates
// The weight should be non-zero and can be a positive or a negative integer
Weight int `json:"weight"`
// Holds the parameters to configure the given priority function
Argument *PriorityArgument `json:"argument"`
}
// Represents the arguments that the different types of predicates take
// Only one of its members may be specified
type PredicateArgument struct {
// The predicate that provides affinity for pods belonging to a service
// It uses a label to identify nodes that belong to the same "group"
ServiceAffinity *ServiceAffinity `json:"serviceAffinity"`
// The predicate that checks whether a particular node has a certain label
// defined or not, regardless of value
LabelsPresence *LabelsPresence `json:"labelsPresence"`
}
// Represents the arguments that the different types of priorities take.
// Only one of its members may be specified
type PriorityArgument struct {
// The priority function that ensures a good spread (anti-affinity) for pods belonging to a service
// It uses a label to identify nodes that belong to the same "group"
ServiceAntiAffinity *ServiceAntiAffinity `json:"serviceAntiAffinity"`
// The priority function that checks whether a particular node has a certain label
// defined or not, regardless of value
LabelPreference *LabelPreference `json:"labelPreference"`
}
// Holds the parameters that are used to configure the corresponding predicate
type ServiceAffinity struct {
// The list of labels that identify node "groups"
// All of the labels should match for the node to be considered a fit for hosting the pod
Labels []string `json:"labels"`
}
// Holds the parameters that are used to configure the corresponding predicate
type LabelsPresence struct {
// The list of labels that identify node "groups"
// All of the labels should be either present (or absent) for the node to be considered a fit for hosting the pod
Labels []string `json:"labels"`
// The boolean flag that indicates whether the labels should be present or absent from the node
Presence bool `json:"presence"`
}
// Holds the parameters that are used to configure the corresponding priority function
type ServiceAntiAffinity struct {
// Used to identify node "groups"
Label string `json:"label"`
}
// Holds the parameters that are used to configure the corresponding priority function
type LabelPreference struct {
// Used to identify node "groups"
Label string `json:"label"`
// This is a boolean flag
// If true, higher priority is given to nodes that have the label
// If false, higher priority is given to nodes that do not have the label
Presence bool `json:"presence"`
}
// Holds the parameters used to communicate with the extender. If a verb is unspecified/empty,
// it is assumed that the extender chose not to provide that extension.
type ExtenderConfig struct {
// URLPrefix at which the extender is available
URLPrefix string `json:"urlPrefix"`
// Verb for the filter call, empty if not supported. This verb is appended to the URLPrefix when issuing the filter call to extender.
FilterVerb string `json:"filterVerb,omitempty"`
// Verb for the prioritize call, empty if not supported. This verb is appended to the URLPrefix when issuing the prioritize call to extender.
PrioritizeVerb string `json:"prioritizeVerb,omitempty"`
// The numeric multiplier for the node scores that the prioritize call generates.
// The weight should be a positive integer
Weight int `json:"weight,omitempty"`
// EnableHttps specifies whether https should be used to communicate with the extender
EnableHttps bool `json:"enableHttps,omitempty"`
// TLSConfig specifies the transport layer security config
TLSConfig *client.TLSClientConfig `json:"tlsConfig,omitempty"`
// HTTPTimeout specifies the timeout duration for a call to the extender. Filter timeout fails the scheduling of the pod. Prioritize
// timeout is ignored, k8s/other extenders priorities are used to select the node.
HTTPTimeout time.Duration `json:"httpTimeout,omitempty"`
}
// ExtenderArgs represents the arguments needed by the extender to filter/prioritize
// nodes for a pod.
type ExtenderArgs struct {
// Pod being scheduled
Pod apiv1.Pod `json:"pod"`
// List of candidate nodes where the pod can be scheduled
Nodes apiv1.NodeList `json:"nodes"`
}
// ExtenderFilterResult represents the results of a filter call to an extender
type ExtenderFilterResult struct {
// Filtered set of nodes where the pod can be scheduled
Nodes apiv1.NodeList `json:"nodes,omitempty"`
// Error message indicating failure
Error string `json:"error,omitempty"`
}
// HostPriority represents the priority of scheduling to a particular host, higher priority is better.
type HostPriority struct {
// Name of the host
Host string `json:"host"`
// Score associated with the host
Score int `json:"score"`
}
type HostPriorityList []HostPriority
func (h HostPriorityList) Len() int {
return len(h)
}
func (h HostPriorityList) Less(i, j int) bool {
if h[i].Score == h[j].Score {
return h[i].Host < h[j].Host
}
return h[i].Score < h[j].Score
}
func (h HostPriorityList) Swap(i, j int) {
h[i], h[j] = h[j], h[i]
}
| nagarjung/kubernetes | plugin/pkg/scheduler/api/v1/types.go | GO | apache-2.0 | 6,999 |
/**
* drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
*
* Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
* Author: Roger Quadros <rogerq@ti.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.
*
* 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/extcon.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/pinctrl/consumer.h>
#define USB_GPIO_DEBOUNCE_MS 20 /* ms */
struct usb_extcon_info {
struct device *dev;
struct extcon_dev *edev;
struct gpio_desc *id_gpiod;
struct gpio_desc *vbus_gpiod;
int id_irq;
int vbus_irq;
unsigned long debounce_jiffies;
struct delayed_work wq_detcable;
};
static const unsigned int usb_extcon_cable[] = {
EXTCON_USB,
EXTCON_USB_HOST,
EXTCON_NONE,
};
/*
* "USB" = VBUS and "USB-HOST" = !ID, so we have:
* Both "USB" and "USB-HOST" can't be set as active at the
* same time so if "USB-HOST" is active (i.e. ID is 0) we keep "USB" inactive
* even if VBUS is on.
*
* State | ID | VBUS
* ----------------------------------------
* [1] USB | H | H
* [2] none | H | L
* [3] USB-HOST | L | H
* [4] USB-HOST | L | L
*
* In case we have only one of these signals:
* - VBUS only - we want to distinguish between [1] and [2], so ID is always 1.
* - ID only - we want to distinguish between [1] and [4], so VBUS = ID.
*/
static void usb_extcon_detect_cable(struct work_struct *work)
{
int id, vbus;
struct usb_extcon_info *info = container_of(to_delayed_work(work),
struct usb_extcon_info,
wq_detcable);
/* check ID and VBUS and update cable state */
id = info->id_gpiod ?
gpiod_get_value_cansleep(info->id_gpiod) : 1;
vbus = info->vbus_gpiod ?
gpiod_get_value_cansleep(info->vbus_gpiod) : id;
/* at first we clean states which are no longer active */
if (id)
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false);
if (!vbus)
extcon_set_state_sync(info->edev, EXTCON_USB, false);
if (!id) {
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
} else {
if (vbus)
extcon_set_state_sync(info->edev, EXTCON_USB, true);
}
}
static irqreturn_t usb_irq_handler(int irq, void *dev_id)
{
struct usb_extcon_info *info = dev_id;
queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
info->debounce_jiffies);
return IRQ_HANDLED;
}
static int usb_extcon_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct usb_extcon_info *info;
int ret;
if (!np)
return -EINVAL;
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
if (!info)
return -ENOMEM;
info->dev = dev;
info->id_gpiod = devm_gpiod_get_optional(&pdev->dev, "id", GPIOD_IN);
info->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, "vbus",
GPIOD_IN);
if (!info->id_gpiod && !info->vbus_gpiod) {
dev_err(dev, "failed to get gpios\n");
return -ENODEV;
}
if (IS_ERR(info->id_gpiod))
return PTR_ERR(info->id_gpiod);
if (IS_ERR(info->vbus_gpiod))
return PTR_ERR(info->vbus_gpiod);
info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
if (IS_ERR(info->edev)) {
dev_err(dev, "failed to allocate extcon device\n");
return -ENOMEM;
}
ret = devm_extcon_dev_register(dev, info->edev);
if (ret < 0) {
dev_err(dev, "failed to register extcon device\n");
return ret;
}
if (info->id_gpiod)
ret = gpiod_set_debounce(info->id_gpiod,
USB_GPIO_DEBOUNCE_MS * 1000);
if (!ret && info->vbus_gpiod)
ret = gpiod_set_debounce(info->vbus_gpiod,
USB_GPIO_DEBOUNCE_MS * 1000);
if (ret < 0)
info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
if (info->id_gpiod) {
info->id_irq = gpiod_to_irq(info->id_gpiod);
if (info->id_irq < 0) {
dev_err(dev, "failed to get ID IRQ\n");
return info->id_irq;
}
ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
usb_irq_handler,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
pdev->name, info);
if (ret < 0) {
dev_err(dev, "failed to request handler for ID IRQ\n");
return ret;
}
}
if (info->vbus_gpiod) {
info->vbus_irq = gpiod_to_irq(info->vbus_gpiod);
if (info->vbus_irq < 0) {
dev_err(dev, "failed to get VBUS IRQ\n");
return info->vbus_irq;
}
ret = devm_request_threaded_irq(dev, info->vbus_irq, NULL,
usb_irq_handler,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
pdev->name, info);
if (ret < 0) {
dev_err(dev, "failed to request handler for VBUS IRQ\n");
return ret;
}
}
platform_set_drvdata(pdev, info);
device_set_wakeup_capable(&pdev->dev, true);
/* Perform initial detection */
usb_extcon_detect_cable(&info->wq_detcable.work);
return 0;
}
static int usb_extcon_remove(struct platform_device *pdev)
{
struct usb_extcon_info *info = platform_get_drvdata(pdev);
cancel_delayed_work_sync(&info->wq_detcable);
device_init_wakeup(&pdev->dev, false);
return 0;
}
#ifdef CONFIG_PM_SLEEP
static int usb_extcon_suspend(struct device *dev)
{
struct usb_extcon_info *info = dev_get_drvdata(dev);
int ret = 0;
if (device_may_wakeup(dev)) {
if (info->id_gpiod) {
ret = enable_irq_wake(info->id_irq);
if (ret)
return ret;
}
if (info->vbus_gpiod) {
ret = enable_irq_wake(info->vbus_irq);
if (ret) {
if (info->id_gpiod)
disable_irq_wake(info->id_irq);
return ret;
}
}
}
/*
* We don't want to process any IRQs after this point
* as GPIOs used behind I2C subsystem might not be
* accessible until resume completes. So disable IRQ.
*/
if (info->id_gpiod)
disable_irq(info->id_irq);
if (info->vbus_gpiod)
disable_irq(info->vbus_irq);
if (!device_may_wakeup(dev))
pinctrl_pm_select_sleep_state(dev);
return ret;
}
static int usb_extcon_resume(struct device *dev)
{
struct usb_extcon_info *info = dev_get_drvdata(dev);
int ret = 0;
if (!device_may_wakeup(dev))
pinctrl_pm_select_default_state(dev);
if (device_may_wakeup(dev)) {
if (info->id_gpiod) {
ret = disable_irq_wake(info->id_irq);
if (ret)
return ret;
}
if (info->vbus_gpiod) {
ret = disable_irq_wake(info->vbus_irq);
if (ret) {
if (info->id_gpiod)
enable_irq_wake(info->id_irq);
return ret;
}
}
}
if (info->id_gpiod)
enable_irq(info->id_irq);
if (info->vbus_gpiod)
enable_irq(info->vbus_irq);
queue_delayed_work(system_power_efficient_wq,
&info->wq_detcable, 0);
return ret;
}
#endif
static SIMPLE_DEV_PM_OPS(usb_extcon_pm_ops,
usb_extcon_suspend, usb_extcon_resume);
static const struct of_device_id usb_extcon_dt_match[] = {
{ .compatible = "linux,extcon-usb-gpio", },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, usb_extcon_dt_match);
static const struct platform_device_id usb_extcon_platform_ids[] = {
{ .name = "extcon-usb-gpio", },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(platform, usb_extcon_platform_ids);
static struct platform_driver usb_extcon_driver = {
.probe = usb_extcon_probe,
.remove = usb_extcon_remove,
.driver = {
.name = "extcon-usb-gpio",
.pm = &usb_extcon_pm_ops,
.of_match_table = usb_extcon_dt_match,
},
.id_table = usb_extcon_platform_ids,
};
module_platform_driver(usb_extcon_driver);
MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
MODULE_DESCRIPTION("USB GPIO extcon driver");
MODULE_LICENSE("GPL v2");
| mkvdv/au-linux-kernel-autumn-2017 | linux/drivers/extcon/extcon-usb-gpio.c | C | gpl-3.0 | 8,079 |
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the 2-clause BSD license.
* See license.txt in the OpenLayers distribution or repository for the
* full text of the license. */
/**
* @requires OpenLayers/BaseTypes/Class.js
*/
/**
* Class: OpenLayers.Protocol
* Abstract vector layer protocol class. Not to be instantiated directly. Use
* one of the protocol subclasses instead.
*/
OpenLayers.Protocol = OpenLayers.Class({
/**
* Property: format
* {<OpenLayers.Format>} The format used by this protocol.
*/
format: null,
/**
* Property: options
* {Object} Any options sent to the constructor.
*/
options: null,
/**
* Property: autoDestroy
* {Boolean} The creator of the protocol can set autoDestroy to false
* to fully control when the protocol is destroyed. Defaults to
* true.
*/
autoDestroy: true,
/**
* Property: defaultFilter
* {<OpenLayers.Filter>} Optional default filter to read requests
*/
defaultFilter: null,
/**
* Constructor: OpenLayers.Protocol
* Abstract class for vector protocols. Create instances of a subclass.
*
* Parameters:
* options - {Object} Optional object whose properties will be set on the
* instance.
*/
initialize: function(options) {
options = options || {};
OpenLayers.Util.extend(this, options);
this.options = options;
},
/**
* Method: mergeWithDefaultFilter
* Merge filter passed to the read method with the default one
*
* Parameters:
* filter - {<OpenLayers.Filter>}
*/
mergeWithDefaultFilter: function(filter) {
var merged;
if (filter && this.defaultFilter) {
merged = new OpenLayers.Filter.Logical({
type: OpenLayers.Filter.Logical.AND,
filters: [this.defaultFilter, filter]
});
} else {
merged = filter || this.defaultFilter || undefined;
}
return merged;
},
/**
* APIMethod: destroy
* Clean up the protocol.
*/
destroy: function() {
this.options = null;
this.format = null;
},
/**
* APIMethod: read
* Construct a request for reading new features.
*
* Parameters:
* options - {Object} Optional object for configuring the request.
*
* Returns:
* {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
* object, the same object will be passed to the callback function passed
* if one exists in the options object.
*/
read: function(options) {
options = options || {};
options.filter = this.mergeWithDefaultFilter(options.filter);
},
/**
* APIMethod: create
* Construct a request for writing newly created features.
*
* Parameters:
* features - {Array({<OpenLayers.Feature.Vector>})} or
* {<OpenLayers.Feature.Vector>}
* options - {Object} Optional object for configuring the request.
*
* Returns:
* {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
* object, the same object will be passed to the callback function passed
* if one exists in the options object.
*/
create: function() {
},
/**
* APIMethod: update
* Construct a request updating modified features.
*
* Parameters:
* features - {Array({<OpenLayers.Feature.Vector>})} or
* {<OpenLayers.Feature.Vector>}
* options - {Object} Optional object for configuring the request.
*
* Returns:
* {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
* object, the same object will be passed to the callback function passed
* if one exists in the options object.
*/
update: function() {
},
/**
* APIMethod: delete
* Construct a request deleting a removed feature.
*
* Parameters:
* feature - {<OpenLayers.Feature.Vector>}
* options - {Object} Optional object for configuring the request.
*
* Returns:
* {<OpenLayers.Protocol.Response>} An <OpenLayers.Protocol.Response>
* object, the same object will be passed to the callback function passed
* if one exists in the options object.
*/
"delete": function() {
},
/**
* APIMethod: commit
* Go over the features and for each take action
* based on the feature state. Possible actions are create,
* update and delete.
*
* Parameters:
* features - {Array({<OpenLayers.Feature.Vector>})}
* options - {Object} Object whose possible keys are "create", "update",
* "delete", "callback" and "scope", the values referenced by the
* first three are objects as passed to the "create", "update", and
* "delete" methods, the value referenced by the "callback" key is
* a function which is called when the commit operation is complete
* using the scope referenced by the "scope" key.
*
* Returns:
* {Array({<OpenLayers.Protocol.Response>})} An array of
* <OpenLayers.Protocol.Response> objects.
*/
commit: function() {
},
/**
* Method: abort
* Abort an ongoing request.
*
* Parameters:
* response - {<OpenLayers.Protocol.Response>}
*/
abort: function(response) {
},
/**
* Method: createCallback
* Returns a function that applies the given public method with resp and
* options arguments.
*
* Parameters:
* method - {Function} The method to be applied by the callback.
* response - {<OpenLayers.Protocol.Response>} The protocol response object.
* options - {Object} Options sent to the protocol method
*/
createCallback: function(method, response, options) {
return OpenLayers.Function.bind(function() {
method.apply(this, [response, options]);
}, this);
},
CLASS_NAME: "OpenLayers.Protocol"
});
/**
* Class: OpenLayers.Protocol.Response
* Protocols return Response objects to their users.
*/
OpenLayers.Protocol.Response = OpenLayers.Class({
/**
* Property: code
* {Number} - OpenLayers.Protocol.Response.SUCCESS or
* OpenLayers.Protocol.Response.FAILURE
*/
code: null,
/**
* Property: requestType
* {String} The type of request this response corresponds to. Either
* "create", "read", "update" or "delete".
*/
requestType: null,
/**
* Property: last
* {Boolean} - true if this is the last response expected in a commit,
* false otherwise, defaults to true.
*/
last: true,
/**
* Property: features
* {Array({<OpenLayers.Feature.Vector>})} or {<OpenLayers.Feature.Vector>}
* The features returned in the response by the server. Depending on the
* protocol's read payload, either features or data will be populated.
*/
features: null,
/**
* Property: data
* {Object}
* The data returned in the response by the server. Depending on the
* protocol's read payload, either features or data will be populated.
*/
data: null,
/**
* Property: reqFeatures
* {Array({<OpenLayers.Feature.Vector>})} or {<OpenLayers.Feature.Vector>}
* The features provided by the user and placed in the request by the
* protocol.
*/
reqFeatures: null,
/**
* Property: priv
*/
priv: null,
/**
* Property: error
* {Object} The error object in case a service exception was encountered.
*/
error: null,
/**
* Constructor: OpenLayers.Protocol.Response
*
* Parameters:
* options - {Object} Optional object whose properties will be set on the
* instance.
*/
initialize: function(options) {
OpenLayers.Util.extend(this, options);
},
/**
* Method: success
*
* Returns:
* {Boolean} - true on success, false otherwise
*/
success: function() {
return this.code > 0;
},
CLASS_NAME: "OpenLayers.Protocol.Response"
});
OpenLayers.Protocol.Response.SUCCESS = 1;
OpenLayers.Protocol.Response.FAILURE = 0;
| savchukoleksii/beaversteward | www/settings/tools/mysql/js/openlayers/src/openlayers/lib/OpenLayers/Protocol.js | JavaScript | mit | 8,407 |
(function($){
if(webshims.support.texttrackapi && document.addEventListener){
var trackOptions = webshims.cfg.track;
var trackListener = function(e){
$(e.target).filter('track').each(changeApi);
};
var trackBugs = webshims.bugs.track;
var changeApi = function(){
if(trackBugs || (!trackOptions.override && $.prop(this, 'readyState') == 3)){
trackOptions.override = true;
webshims.reTest('track');
document.removeEventListener('error', trackListener, true);
if(this && $.nodeName(this, 'track')){
webshims.error("track support was overwritten. Please check your vtt including your vtt mime-type");
} else {
webshims.info("track support was overwritten. due to bad browser support");
}
return false;
}
};
var detectTrackError = function(){
document.addEventListener('error', trackListener, true);
if(trackBugs){
changeApi();
} else {
$('track').each(changeApi);
}
if(!trackBugs && !trackOptions.override){
webshims.defineProperty(TextTrack.prototype, 'shimActiveCues', {
get: function(){
return this._shimActiveCues || this.activeCues;
}
});
}
};
if(!trackOptions.override){
$(detectTrackError);
}
}
})(webshims.$);
webshims.register('track-ui', function($, webshims, window, document, undefined){
"use strict";
var options = webshims.cfg.track;
var support = webshims.support;
//descriptions are not really shown, but they are inserted into the dom
var showTracks = {subtitles: 1, captions: 1, descriptions: 1};
var mediaelement = webshims.mediaelement;
var usesNativeTrack = function(){
return !options.override && support.texttrackapi;
};
var trackDisplay = {
update: function(baseData, media){
if(!baseData.activeCues.length){
this.hide(baseData);
} else {
if(!compareArray(baseData.displayedActiveCues, baseData.activeCues)){
baseData.displayedActiveCues = baseData.activeCues;
if(!baseData.trackDisplay){
baseData.trackDisplay = $('<div class="cue-display '+webshims.shadowClass+'"><span class="description-cues" aria-live="assertive" /></div>').insertAfter(media);
this.addEvents(baseData, media);
webshims.docObserve();
}
if(baseData.hasDirtyTrackDisplay){
media.triggerHandler('forceupdatetrackdisplay');
}
this.showCues(baseData);
}
}
},
showCues: function(baseData){
var element = $('<span class="cue-wrapper" />');
$.each(baseData.displayedActiveCues, function(i, cue){
var id = (cue.id) ? 'id="cue-id-'+cue.id +'"' : '';
var cueHTML = $('<span class="cue-line"><span '+ id+ ' class="cue" /></span>').find('span').html(cue.getCueAsHTML()).end();
if(cue.track.kind == 'descriptions'){
setTimeout(function(){
$('span.description-cues', baseData.trackDisplay).html(cueHTML);
}, 0);
} else {
element.prepend(cueHTML);
}
});
$('span.cue-wrapper', baseData.trackDisplay).remove();
baseData.trackDisplay.append(element);
},
addEvents: function(baseData, media){
if(options.positionDisplay){
var timer;
var positionDisplay = function(_force){
if(baseData.displayedActiveCues.length || _force === true){
baseData.trackDisplay.css({display: 'none'});
var uiElement = media.getShadowElement();
var uiHeight = uiElement.innerHeight();
var uiWidth = uiElement.innerWidth();
var position = uiElement.position();
baseData.trackDisplay.css({
left: position.left,
width: uiWidth,
height: uiHeight - 45,
top: position.top,
display: 'block'
});
baseData.trackDisplay.css('fontSize', Math.max(Math.round(uiHeight / 30), 7));
baseData.hasDirtyTrackDisplay = false;
} else {
baseData.hasDirtyTrackDisplay = true;
}
};
var delayed = function(e){
clearTimeout(timer);
timer = setTimeout(positionDisplay, 0);
};
var forceUpdate = function(){
positionDisplay(true);
};
media.on('playerdimensionchange mediaelementapichange updatetrackdisplay updatemediaelementdimensions swfstageresize', delayed);
media.on('forceupdatetrackdisplay', forceUpdate).onWSOff('updateshadowdom', delayed);
forceUpdate();
}
},
hide: function(baseData){
if(baseData.trackDisplay && baseData.displayedActiveCues.length){
baseData.displayedActiveCues = [];
$('span.cue-wrapper', baseData.trackDisplay).remove();
$('span.description-cues', baseData.trackDisplay).empty();
}
}
};
function compareArray(a1, a2){
var ret = true;
var i = 0;
var len = a1.length;
if(len != a2.length){
ret = false;
} else {
for(; i < len; i++){
if(a1[i] != a2[i]){
ret = false;
break;
}
}
}
return ret;
}
mediaelement.trackDisplay = trackDisplay;
if(!mediaelement.createCueList){
var cueListProto = {
getCueById: function(id){
var cue = null;
for(var i = 0, len = this.length; i < len; i++){
if(this[i].id === id){
cue = this[i];
break;
}
}
return cue;
}
};
mediaelement.createCueList = function(){
return $.extend([], cueListProto);
};
}
mediaelement.getActiveCue = function(track, media, time, baseData){
if(!track._lastFoundCue){
track._lastFoundCue = {index: 0, time: 0};
}
if(support.texttrackapi && !options.override && !track._shimActiveCues){
track._shimActiveCues = mediaelement.createCueList();
}
var i = 0;
var len;
var cue;
for(; i < track.shimActiveCues.length; i++){
cue = track.shimActiveCues[i];
if(cue.startTime > time || cue.endTime < time){
track.shimActiveCues.splice(i, 1);
i--;
if(cue.pauseOnExit){
$(media).pause();
}
$(track).triggerHandler('cuechange');
$(cue).triggerHandler('exit');
} else if(track.mode == 'showing' && showTracks[track.kind] && $.inArray(cue, baseData.activeCues) == -1){
baseData.activeCues.push(cue);
}
}
len = track.cues.length;
i = track._lastFoundCue.time < time ? track._lastFoundCue.index : 0;
for(; i < len; i++){
cue = track.cues[i];
if(cue.startTime <= time && cue.endTime >= time && $.inArray(cue, track.shimActiveCues) == -1){
track.shimActiveCues.push(cue);
if(track.mode == 'showing' && showTracks[track.kind]){
baseData.activeCues.push(cue);
}
$(track).triggerHandler('cuechange');
$(cue).triggerHandler('enter');
track._lastFoundCue.time = time;
track._lastFoundCue.index = i;
}
if(cue.startTime > time){
break;
}
}
};
if(usesNativeTrack()){
(function(){
var block;
var triggerDisplayUpdate = function(elem){
block = true;
setTimeout(function(){
$(elem).triggerHandler('updatetrackdisplay');
block = false;
}, 9);
};
var createUpdateFn = function(nodeName, prop, type){
var superType = '_sup'+type;
var desc = {prop: {}};
var superDesc;
desc.prop[type] = function(){
if(!block && usesNativeTrack()){
triggerDisplayUpdate($(this).closest('audio, video'));
}
return superDesc.prop[superType].apply(this, arguments);
};
superDesc = webshims.defineNodeNameProperty(nodeName, prop, desc);
};
createUpdateFn('track', 'track', 'get');
['audio', 'video'].forEach(function(nodeName){
createUpdateFn(nodeName, 'textTracks', 'get');
createUpdateFn('nodeName', 'addTextTrack', 'value');
});
})();
$.propHooks.activeCues = {
get: function(obj){
return obj._shimActiveCues || obj.activeCues;
}
};
}
webshims.addReady(function(context, insertedElement){
$('video, audio', context)
.add(insertedElement.filter('video, audio'))
.filter(function(){
return webshims.implement(this, 'trackui');
})
.each(function(){
var baseData, trackList, updateTimer, updateTimer2;
var elem = $(this);
var getDisplayCues = function(e){
var track;
var time;
if(!trackList || !baseData){
trackList = elem.prop('textTracks');
baseData = webshims.data(elem[0], 'mediaelementBase') || webshims.data(elem[0], 'mediaelementBase', {});
if(!baseData.displayedActiveCues){
baseData.displayedActiveCues = [];
}
}
if (!trackList){return;}
time = elem.prop('currentTime');
if(!time && time !== 0){return;}
baseData.activeCues = [];
for(var i = 0, len = trackList.length; i < len; i++){
track = trackList[i];
if(track.mode != 'disabled' && track.cues && track.cues.length){
mediaelement.getActiveCue(track, elem, time, baseData);
}
}
trackDisplay.update(baseData, elem);
};
var onUpdate = function(e){
clearTimeout(updateTimer);
if(e){
if(e.type == 'timeupdate'){
getDisplayCues();
}
updateTimer2 = setTimeout(onUpdate, 90);
} else {
updateTimer = setTimeout(getDisplayCues, 9);
}
};
var addTrackView = function(){
if(!trackList) {
trackList = elem.prop('textTracks');
}
//as soon as change on trackList is implemented in all browsers we do not need to have 'updatetrackdisplay' anymore
$( [trackList] ).on('change', onUpdate);
elem
.off('.trackview')
.on('play.trackview timeupdate.trackview updatetrackdisplay.trackview', onUpdate)
;
};
elem.on('remove', function(e){
if(!e.originalEvent && baseData && baseData.trackDisplay){
setTimeout(function(){
baseData.trackDisplay.remove();
}, 4);
}
});
if(!usesNativeTrack()){
addTrackView();
} else {
if(elem.hasClass('nonnative-api-active')){
addTrackView();
}
elem
.on('mediaelementapichange trackapichange', function(){
if(!usesNativeTrack() || elem.hasClass('nonnative-api-active')){
addTrackView();
} else {
clearTimeout(updateTimer);
clearTimeout(updateTimer2);
trackList = elem.prop('textTracks');
baseData = webshims.data(elem[0], 'mediaelementBase') || webshims.data(elem[0], 'mediaelementBase', {});
$.each(trackList, function(i, track){
if(track._shimActiveCues){
delete track._shimActiveCues;
}
});
trackDisplay.hide(baseData);
elem.off('.trackview');
}
})
;
}
})
;
});
});
| ttitto/ttitto.github.io | js-webshim/dev/shims/track-ui.js | JavaScript | mit | 10,440 |
/*
* Copyright (c) 2015-2016, 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.
*/
#ifndef __ADSP_ERR__
#define __ADSP_ERR__
int adsp_err_get_lnx_err_code(u32 adsp_error);
char *adsp_err_get_err_str(u32 adsp_error);
#endif
| butkevicius/motorola-moto-z-permissive-kernel | kernel/include/sound/adsp_err.h | C | gpl-2.0 | 679 |
/* { dg-do compile } */
/* { dg-skip-if "do not override -mfloat-abi" { *-*-* } { "-mfloat-abi=*" } {"-mfloat-abi=softfp" } } */
/* { dg-options "-O2 -fno-omit-frame-pointer -mabi=apcs-gnu -mfloat-abi=softfp" } */
struct super_block
{
int s_blocksize_bits;
};
struct btrfs_fs_info
{
struct super_block *sb;
};
struct btrfs_root
{
struct btrfs_fs_info *fs_info;
} *b;
int a, c, d;
long long e;
extern int foo1 (struct btrfs_root *, int, int, int);
extern int foo2 (struct btrfs_root *, int, int);
int
truncate_one_csum (struct btrfs_root *p1, long long p2, long long p3)
{
int f, g, i = p1->fs_info->sb->s_blocksize_bits;
g = a;
long long h = p2 + p3;
f = foo1 (b, 0, c, 0);
e = f / g;
e <<= p1->fs_info->sb->s_blocksize_bits;
if (d < p2)
{
int j = e - h >> i;
foo2 (p1, 0, j);
}
else
{
asm ("1\t.long ");
__builtin_unreachable ();
}
}
| selmentdev/selment-toolchain | source/gcc-latest/gcc/testsuite/gcc.target/arm/pr60650.c | C | gpl-3.0 | 903 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# GuessIt - A library for guessing information from filenames
# Copyright (c) 2012 Nicolas Wack <wackou@gmail.com>
#
# GuessIt is free software; you can redistribute it and/or modify it under
# the terms of the Lesser GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# GuessIt 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
# Lesser GNU General Public License for more details.
#
# You should have received a copy of the Lesser GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import unicode_literals
from guessit import Guess
from guessit.transfo import SingleNodeGuesser
from guessit.patterns import video_rexps, sep
import re
import logging
log = logging.getLogger(__name__)
def guess_video_rexps(string):
string = '-' + string + '-'
for rexp, confidence, span_adjust in video_rexps:
match = re.search(sep + rexp + sep, string, re.IGNORECASE)
if match:
metadata = match.groupdict()
# is this the better place to put it? (maybe, as it is at least
# the soonest that we can catch it)
if metadata.get('cdNumberTotal', -1) is None:
del metadata['cdNumberTotal']
span = (match.start() + span_adjust[0],
match.end() + span_adjust[1] - 2)
return (Guess(metadata, confidence=confidence, raw=string[span[0]:span[1]]),
span)
return None, None
def process(mtree):
SingleNodeGuesser(guess_video_rexps, None, log).process(mtree)
| loulich/Couchpotato | libs/guessit/transfo/guess_video_rexps.py | Python | gpl-3.0 | 1,837 |
//// [symbolDeclarationEmit8.ts]
var obj = {
[Symbol.isConcatSpreadable]: 0
}
//// [symbolDeclarationEmit8.js]
var obj = {
[Symbol.isConcatSpreadable]: 0
};
//// [symbolDeclarationEmit8.d.ts]
declare var obj: {
[Symbol.isConcatSpreadable]: number;
};
| shanexu/TypeScript | tests/baselines/reference/symbolDeclarationEmit8.js | JavaScript | apache-2.0 | 279 |
/*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include "libavutil/attributes.h"
#include "libavcodec/vp8dsp.h"
#include "vp8dsp.h"
void ff_vp8_luma_dc_wht_neon(int16_t block[4][4][16], int16_t dc[16]);
void ff_vp8_idct_add_neon(uint8_t *dst, int16_t block[16], ptrdiff_t stride);
void ff_vp8_idct_dc_add_neon(uint8_t *dst, int16_t block[16], ptrdiff_t stride);
void ff_vp8_idct_dc_add4y_neon(uint8_t *dst, int16_t block[4][16], ptrdiff_t stride);
void ff_vp8_idct_dc_add4uv_neon(uint8_t *dst, int16_t block[4][16], ptrdiff_t stride);
VP8_LF(neon);
VP8_EPEL(16, neon);
VP8_EPEL(8, neon);
VP8_EPEL(4, neon);
VP8_BILIN(16, neon);
VP8_BILIN(8, neon);
VP8_BILIN(4, neon);
av_cold void ff_vp78dsp_init_neon(VP8DSPContext *dsp)
{
dsp->put_vp8_epel_pixels_tab[0][0][0] = ff_put_vp8_pixels16_neon;
dsp->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_neon;
dsp->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_neon;
dsp->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_neon;
dsp->put_vp8_epel_pixels_tab[1][0][0] = ff_put_vp8_pixels8_neon;
dsp->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_neon;
dsp->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_neon;
dsp->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_neon;
dsp->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_neon;
dsp->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_neon;
dsp->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_neon;
dsp->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_neon;
dsp->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_neon;
dsp->put_vp8_epel_pixels_tab[2][0][1] = ff_put_vp8_epel4_h4_neon;
dsp->put_vp8_epel_pixels_tab[2][0][2] = ff_put_vp8_epel4_h6_neon;
dsp->put_vp8_epel_pixels_tab[2][1][0] = ff_put_vp8_epel4_v4_neon;
dsp->put_vp8_epel_pixels_tab[2][1][1] = ff_put_vp8_epel4_h4v4_neon;
dsp->put_vp8_epel_pixels_tab[2][1][2] = ff_put_vp8_epel4_h6v4_neon;
dsp->put_vp8_epel_pixels_tab[2][2][0] = ff_put_vp8_epel4_v6_neon;
dsp->put_vp8_epel_pixels_tab[2][2][1] = ff_put_vp8_epel4_h4v6_neon;
dsp->put_vp8_epel_pixels_tab[2][2][2] = ff_put_vp8_epel4_h6v6_neon;
dsp->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_neon;
dsp->put_vp8_bilinear_pixels_tab[0][0][1] = ff_put_vp8_bilin16_h_neon;
dsp->put_vp8_bilinear_pixels_tab[0][0][2] = ff_put_vp8_bilin16_h_neon;
dsp->put_vp8_bilinear_pixels_tab[0][1][0] = ff_put_vp8_bilin16_v_neon;
dsp->put_vp8_bilinear_pixels_tab[0][1][1] = ff_put_vp8_bilin16_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[0][1][2] = ff_put_vp8_bilin16_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[0][2][0] = ff_put_vp8_bilin16_v_neon;
dsp->put_vp8_bilinear_pixels_tab[0][2][1] = ff_put_vp8_bilin16_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[0][2][2] = ff_put_vp8_bilin16_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[1][0][0] = ff_put_vp8_pixels8_neon;
dsp->put_vp8_bilinear_pixels_tab[1][0][1] = ff_put_vp8_bilin8_h_neon;
dsp->put_vp8_bilinear_pixels_tab[1][0][2] = ff_put_vp8_bilin8_h_neon;
dsp->put_vp8_bilinear_pixels_tab[1][1][0] = ff_put_vp8_bilin8_v_neon;
dsp->put_vp8_bilinear_pixels_tab[1][1][1] = ff_put_vp8_bilin8_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[1][1][2] = ff_put_vp8_bilin8_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[1][2][0] = ff_put_vp8_bilin8_v_neon;
dsp->put_vp8_bilinear_pixels_tab[1][2][1] = ff_put_vp8_bilin8_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[1][2][2] = ff_put_vp8_bilin8_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[2][0][1] = ff_put_vp8_bilin4_h_neon;
dsp->put_vp8_bilinear_pixels_tab[2][0][2] = ff_put_vp8_bilin4_h_neon;
dsp->put_vp8_bilinear_pixels_tab[2][1][0] = ff_put_vp8_bilin4_v_neon;
dsp->put_vp8_bilinear_pixels_tab[2][1][1] = ff_put_vp8_bilin4_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[2][1][2] = ff_put_vp8_bilin4_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[2][2][0] = ff_put_vp8_bilin4_v_neon;
dsp->put_vp8_bilinear_pixels_tab[2][2][1] = ff_put_vp8_bilin4_hv_neon;
dsp->put_vp8_bilinear_pixels_tab[2][2][2] = ff_put_vp8_bilin4_hv_neon;
}
av_cold void ff_vp8dsp_init_neon(VP8DSPContext *dsp)
{
dsp->vp8_luma_dc_wht = ff_vp8_luma_dc_wht_neon;
dsp->vp8_idct_add = ff_vp8_idct_add_neon;
dsp->vp8_idct_dc_add = ff_vp8_idct_dc_add_neon;
dsp->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_neon;
dsp->vp8_idct_dc_add4uv = ff_vp8_idct_dc_add4uv_neon;
dsp->vp8_v_loop_filter16y = ff_vp8_v_loop_filter16_neon;
dsp->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16_neon;
dsp->vp8_v_loop_filter8uv = ff_vp8_v_loop_filter8uv_neon;
dsp->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_neon;
dsp->vp8_v_loop_filter16y_inner = ff_vp8_v_loop_filter16_inner_neon;
dsp->vp8_h_loop_filter16y_inner = ff_vp8_h_loop_filter16_inner_neon;
dsp->vp8_v_loop_filter8uv_inner = ff_vp8_v_loop_filter8uv_inner_neon;
dsp->vp8_h_loop_filter8uv_inner = ff_vp8_h_loop_filter8uv_inner_neon;
dsp->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter16_simple_neon;
dsp->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter16_simple_neon;
}
| CTSRD-SOAAP/chromium-42.0.2311.135 | third_party/ffmpeg/libavcodec/arm/vp8dsp_init_neon.c | C | bsd-3-clause | 5,935 |
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package controllers
import (
"fmt"
"github.com/golang/glog"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/tools/cache"
)
// WaitForCacheSync is a wrapper around cache.WaitForCacheSync that generates log messages
// indicating that the controller identified by controllerName is waiting for syncs, followed by
// either a successful or failed sync.
func WaitForCacheSync(controllerName string, stopCh <-chan struct{}, cacheSyncs ...cache.InformerSynced) bool {
glog.Infof("Waiting for caches to sync for %s controller", controllerName)
if !cache.WaitForCacheSync(stopCh, cacheSyncs...) {
utilruntime.HandleError(fmt.Errorf("Unable to sync caches for %s controller", controllerName))
return false
}
glog.Infof("Caches are synced for %s controller", controllerName)
return true
}
| bparees/open-service-broker-sdk | vendor/k8s.io/kubernetes/staging/src/k8s.io/kube-aggregator/pkg/controllers/cache.go | GO | apache-2.0 | 1,390 |
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// System.Array.Sort<T>(T[],System.Collections.Generic.IComparer<T>)
/// </summary>
public class ArraySort7
{
#region Public Methods
public bool RunTests()
{
bool retVal = true;
TestLibrary.TestFramework.LogInformation("[Positive]");
retVal = PosTest1() && retVal;
retVal = PosTest2() && retVal;
retVal = PosTest3() && retVal;
retVal = PosTest4() && retVal;
retVal = PosTest5() && retVal;
TestLibrary.TestFramework.LogInformation("[Negative]");
retVal = NegTest1() && retVal;
retVal = NegTest2() && retVal;
//Bug 385712: Wont fix
//retVal = NegTest3() && retVal;
return retVal;
}
#region Positive Test Cases
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Sort a string array using string comparer<string>");
try
{
string[] s1 = new string[7]{"Jack",
"Mary",
"Mike",
"Peter",
"Boy",
"Tom",
"Allin"};
IComparer<string> a = new A<string>();
Array.Sort<string>(s1, a);
string[] s2 = new string[7]{"Allin",
"Boy",
"Jack",
"Mary",
"Mike",
"Peter",
"Tom"};
for (int i = 0; i < 7; i++)
{
if (s1[i] != s2[i])
{
TestLibrary.TestFramework.LogError("001", "The result is not the value as expected");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2: Sort an int32 array using reverse comparer<int>");
try
{
int length = TestLibrary.Generator.GetInt16(-55);
int[] i1 = new int[length];
int[] i2 = new int[length];
for (int i = 0; i < length; i++)
{
int value = TestLibrary.Generator.GetByte(-55);
i1[i] = value;
i2[i] = value;
}
IComparer<int> b = new B<int>();
Array.Sort<int>(i1, b);
for (int i = 0; i < length - 1; i++) //manually quich sort
{
for (int j = i + 1; j < length; j++)
{
if (i2[i] < i2[j])
{
int temp = i2[i];
i2[i] = i2[j];
i2[j] = temp;
}
}
}
for (int i = 0; i < length; i++)
{
if (i1[i] != i2[i])
{
TestLibrary.TestFramework.LogError("003", "The result is not the value as expected");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
public bool PosTest3()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest3: Sort a char array using default comparer ");
try
{
int length = TestLibrary.Generator.GetInt16(-55);
char[] i1 = new char[length];
char[] i2 = new char[length];
for (int i = 0; i < length; i++)
{
char value = TestLibrary.Generator.GetChar(-55);
i1[i] = value;
i2[i] = value;
}
IComparer<char> c = null;
Array.Sort<char>(i1, c);
for (int i = 0; i < length - 1; i++) //manually quich sort
{
for (int j = i + 1; j < length; j++)
{
if (i2[i] > i2[j])
{
char temp = i2[i];
i2[i] = i2[j];
i2[j] = temp;
}
}
}
for (int i = 0; i < length; i++)
{
if (i1[i] != i2[i])
{
TestLibrary.TestFramework.LogError("005", "The result is not the value as expected");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
public bool PosTest4()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest4: Sort an array which has same elements using default Icomparer ");
try
{
int length = TestLibrary.Generator.GetByte(-55);
string[] s1 = new string[length];
string[] s2 = new string[length];
string value = TestLibrary.Generator.GetString(-55, false, 0, 10);
for (int i = 0; i < length; i++)
{
s1[i] = value;
s2[i] = value;
}
IComparer<string> c = null;
Array.Sort<string>(s1, c);
for (int i = 0; i < length; i++)
{
if (s1[i] != s2[i])
{
TestLibrary.TestFramework.LogError("007", "The result is not the value as expected");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
public bool PosTest5()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest5: Sort a string array including null reference and using customized comparer<T> interface");
try
{
string[] s1 = new string[9]{"Jack",
"Mary",
"Mike",
null,
"Peter",
"Boy",
"Tom",
null,
"Allin"};
IComparer<string> d = new D<string>();
Array.Sort<string>(s1, d);
string[] s2 = new string[9]{"Allin",
"Boy",
"Jack",
"Mary",
"Mike",
"Peter",
"Tom",
null,
null};
for (int i = 0; i < 7; i++)
{
if (s1[i] != s2[i])
{
TestLibrary.TestFramework.LogError("009", "The result is not the value as expected");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
#endregion
#region Nagetive Test Cases
public bool NegTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest1: The array is null ");
try
{
string[] s1 = null;
IComparer<string> a = new A<string>();
Array.Sort<string>(s1, a);
TestLibrary.TestFramework.LogError("101", "The ArgumentNullException is not throw as expected ");
retVal = false;
}
catch (ArgumentNullException)
{
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
public bool NegTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest2: Elements in array do not implement the IComparable<T> interface ");
try
{
E<int>[] a1 = new E<int>[4] { new E<int>(), new E<int>(), new E<int>(), new E<int>() };
IComparer<E<int>> d = null;
Array.Sort<E<int>>(a1, d);
TestLibrary.TestFramework.LogError("103", "The InvalidOperationException is not throw as expected ");
retVal = false;
}
catch (InvalidOperationException)
{
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
public bool NegTest3()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest3:The implementation of comparer<T> caused an error during the sort");
try
{
int[] i1 = new int[9] { 2, 34, 56, 87, 34, 23, 209, 34, 87 };
F f = new F();
Array.Sort<int>(i1, f);
TestLibrary.TestFramework.LogError("105", "The ArgumentException is not throw as expected ");
retVal = false;
}
catch (ArgumentException)
{
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("106", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
#endregion
#endregion
public static int Main()
{
ArraySort7 test = new ArraySort7();
TestLibrary.TestFramework.BeginTestCase("ArraySort7");
if (test.RunTests())
{
TestLibrary.TestFramework.EndTestCase();
TestLibrary.TestFramework.LogInformation("PASS");
return 100;
}
else
{
TestLibrary.TestFramework.EndTestCase();
TestLibrary.TestFramework.LogInformation("FAIL");
return 0;
}
}
class A<T> : IComparer<T> where T : IComparable
{
#region IComparer Members
public int Compare(T x, T y)
{
return x.CompareTo(y);
}
#endregion
}
class B<T> : IComparer<T> where T : IComparable
{
#region IComparer Members
public int Compare(T x, T y)
{
return (-(x).CompareTo(y));
}
#endregion
}
class D<T> : IComparer<T> where T : IComparable
{
#region IComparer Members
public int Compare(T x, T y)
{
if (x == null)
{
return 1;
}
if (y == null)
{
return -1;
}
return x.CompareTo(y);
}
#endregion
}
class E<T>
{
public E() { }
}
class F : IComparer<int>
{
#region IComparer<int> Members
int IComparer<int>.Compare(int a, int b)
{
if (a.CompareTo(a) == 0)
{
return -1;
}
return a.CompareTo(b);
}
#endregion
}
}
| sejongoh/coreclr | tests/src/CoreMangLib/cti/system/array/arraysort7.cs | C# | mit | 11,393 |
/*
* Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs
*
* 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 the Kustaa Nyholm or SpareTimeLabs 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 HOLDER 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.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdlib.h>
#include "platform.h"
#include "build_config.h"
#include "drivers/serial.h"
#include "io/serial.h"
#include "build_config.h"
#include "printf.h"
#ifdef REQUIRE_PRINTF_LONG_SUPPORT
#include "typeconversion.h"
#endif
static serialPort_t *printfSerialPort;
#ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT
typedef void (*putcf) (void *, char);
static putcf stdout_putf;
static void *stdout_putp;
// print bf, padded from left to at least n characters.
// padding is zero ('0') if z!=0, space (' ') otherwise
static int putchw(void *putp, putcf putf, int n, char z, char *bf)
{
int written = 0;
char fc = z ? '0' : ' ';
char ch;
char *p = bf;
while (*p++ && n > 0)
n--;
while (n-- > 0) {
putf(putp, fc); written++;
}
while ((ch = *bf++)) {
putf(putp, ch); written++;
}
return written;
}
// retrun number of bytes written
int tfp_format(void *putp, putcf putf, const char *fmt, va_list va)
{
char bf[12];
int written = 0;
char ch;
while ((ch = *(fmt++))) {
if (ch != '%') {
putf(putp, ch); written++;
} else {
char lz = 0;
#ifdef REQUIRE_PRINTF_LONG_SUPPORT
char lng = 0;
#endif
int w = 0;
ch = *(fmt++);
if (ch == '0') {
ch = *(fmt++);
lz = 1;
}
if (ch >= '0' && ch <= '9') {
ch = a2i(ch, &fmt, 10, &w);
}
#ifdef REQUIRE_PRINTF_LONG_SUPPORT
if (ch == 'l') {
ch = *(fmt++);
lng = 1;
}
#endif
switch (ch) {
case 0:
goto abort;
case 'u':{
#ifdef REQUIRE_PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int), 10, 0, bf);
else
#endif
ui2a(va_arg(va, unsigned int), 10, 0, bf);
written += putchw(putp, putf, w, lz, bf);
break;
}
case 'd':{
#ifdef REQUIRE_PRINTF_LONG_SUPPORT
if (lng)
li2a(va_arg(va, unsigned long int), bf);
else
#endif
i2a(va_arg(va, int), bf);
written += putchw(putp, putf, w, lz, bf);
break;
}
case 'x':
case 'X':
#ifdef REQUIRE_PRINTF_LONG_SUPPORT
if (lng)
uli2a(va_arg(va, unsigned long int), 16, (ch == 'X'), bf);
else
#endif
ui2a(va_arg(va, unsigned int), 16, (ch == 'X'), bf);
written += putchw(putp, putf, w, lz, bf);
break;
case 'c':
putf(putp, (char) (va_arg(va, int))); written++;
break;
case 's':
written += putchw(putp, putf, w, 0, va_arg(va, char *));
break;
case '%':
putf(putp, ch); written++;
break;
case 'n':
*va_arg(va, int*) = written;
break;
default:
break;
}
}
}
abort:
return written;
}
void init_printf(void *putp, void (*putf) (void *, char))
{
stdout_putf = putf;
stdout_putp = putp;
}
int tfp_printf(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
int written = tfp_format(stdout_putp, stdout_putf, fmt, va);
va_end(va);
while (!isSerialTransmitBufferEmpty(printfSerialPort));
return written;
}
static void putcp(void *p, char c)
{
*(*((char **) p))++ = c;
}
int tfp_sprintf(char *s, const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
int written = tfp_format(&s, putcp, fmt, va);
putcp(&s, 0);
va_end(va);
return written;
}
static void _putc(void *p, char c)
{
UNUSED(p);
serialWrite(printfSerialPort, c);
}
void printfSupportInit(void)
{
init_printf(NULL, _putc);
}
#else
// keil/armcc version
int fputc(int c, FILE *f)
{
// let DMA catch up a bit when using set or dump, we're too fast.
while (!isSerialTransmitBufferEmpty(printfSerialPort));
serialWrite(printfSerialPort, c);
return c;
}
void printfSupportInit(void)
{
// Nothing to do
}
#endif
void setPrintfSerialPort(serialPort_t *serialPort)
{
printfSerialPort = serialPort;
}
| subaklab/myflight | src/main/common/printf.c | C | gpl-3.0 | 6,103 |
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections;
using System.Collections.Generic;
namespace System.Data.Common
{
internal partial class DbConnectionOptions
{
protected DbConnectionOptions(string connectionString, Dictionary<string, string> synonyms)
: this (connectionString, new Hashtable(synonyms), false)
{
}
internal bool TryGetParsetableValue(string key, out string value)
{
if (_parsetable.ContainsKey(key))
{
value = (string)_parsetable[key];
return true;
}
value = null;
return false;
}
}
} | nbarbettini/corefx | src/System.Data.Common/src/System/Data/Common/DbConnectionOptions.Mono.cs | C# | mit | 843 |
<html>
<body>
<pre>BEGINhtml
body
pre
include:custom(opt='val' num=2) filters.include.custom.pug
END</pre>
</body>
</html>
| february29/Learning | web/vue/AccountBook-Express/node_modules/pug/test/cases/filters.include.custom.html | HTML | mit | 144 |
<div class="loader"></div>
| bleenco/abstruse | web/abstruse/src/app/shared/components/loader/loader.component.html | HTML | mit | 27 |
/*
* Kernel-based Virtual Machine driver for Linux
*
* This module enables machines with Intel VT-x extensions to run virtual
* machines without emulation or binary translation.
*
* Copyright (C) 2006 Qumranet, Inc.
*
* Authors:
* Avi Kivity <avi@qumranet.com>
* Yaniv Kamay <yaniv@qumranet.com>
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*
*/
#include "irq.h"
#include "mmu.h"
#include <linux/kvm_host.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/highmem.h>
#include <linux/sched.h>
#include <linux/moduleparam.h>
#include "kvm_cache_regs.h"
#include "x86.h"
#include <asm/io.h>
#include <asm/desc.h>
#include <asm/vmx.h>
#include <asm/virtext.h>
#define __ex(x) __kvm_handle_fault_on_reboot(x)
MODULE_AUTHOR("Qumranet");
MODULE_LICENSE("GPL");
static int bypass_guest_pf = 1;
module_param(bypass_guest_pf, bool, 0);
static int enable_vpid = 1;
module_param(enable_vpid, bool, 0);
static int flexpriority_enabled = 1;
module_param(flexpriority_enabled, bool, 0);
static int enable_ept = 1;
module_param(enable_ept, bool, 0);
static int emulate_invalid_guest_state = 0;
module_param(emulate_invalid_guest_state, bool, 0);
struct vmcs {
u32 revision_id;
u32 abort;
char data[0];
};
struct vcpu_vmx {
struct kvm_vcpu vcpu;
struct list_head local_vcpus_link;
unsigned long host_rsp;
int launched;
u8 fail;
u32 idt_vectoring_info;
struct kvm_msr_entry *guest_msrs;
struct kvm_msr_entry *host_msrs;
int nmsrs;
int save_nmsrs;
int msr_offset_efer;
#ifdef CONFIG_X86_64
int msr_offset_kernel_gs_base;
#endif
struct vmcs *vmcs;
struct {
int loaded;
u16 fs_sel, gs_sel, ldt_sel;
int gs_ldt_reload_needed;
int fs_reload_needed;
int guest_efer_loaded;
} host_state;
struct {
struct {
bool pending;
u8 vector;
unsigned rip;
} irq;
} rmode;
int vpid;
bool emulation_required;
/* Support for vnmi-less CPUs */
int soft_vnmi_blocked;
ktime_t entry_time;
s64 vnmi_blocked_time;
};
static inline struct vcpu_vmx *to_vmx(struct kvm_vcpu *vcpu)
{
return container_of(vcpu, struct vcpu_vmx, vcpu);
}
static int init_rmode(struct kvm *kvm);
static u64 construct_eptp(unsigned long root_hpa);
static DEFINE_PER_CPU(struct vmcs *, vmxarea);
static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
static DEFINE_PER_CPU(struct list_head, vcpus_on_cpu);
static struct page *vmx_io_bitmap_a;
static struct page *vmx_io_bitmap_b;
static struct page *vmx_msr_bitmap;
static DECLARE_BITMAP(vmx_vpid_bitmap, VMX_NR_VPIDS);
static DEFINE_SPINLOCK(vmx_vpid_lock);
static struct vmcs_config {
int size;
int order;
u32 revision_id;
u32 pin_based_exec_ctrl;
u32 cpu_based_exec_ctrl;
u32 cpu_based_2nd_exec_ctrl;
u32 vmexit_ctrl;
u32 vmentry_ctrl;
} vmcs_config;
static struct vmx_capability {
u32 ept;
u32 vpid;
} vmx_capability;
#define VMX_SEGMENT_FIELD(seg) \
[VCPU_SREG_##seg] = { \
.selector = GUEST_##seg##_SELECTOR, \
.base = GUEST_##seg##_BASE, \
.limit = GUEST_##seg##_LIMIT, \
.ar_bytes = GUEST_##seg##_AR_BYTES, \
}
static struct kvm_vmx_segment_field {
unsigned selector;
unsigned base;
unsigned limit;
unsigned ar_bytes;
} kvm_vmx_segment_fields[] = {
VMX_SEGMENT_FIELD(CS),
VMX_SEGMENT_FIELD(DS),
VMX_SEGMENT_FIELD(ES),
VMX_SEGMENT_FIELD(FS),
VMX_SEGMENT_FIELD(GS),
VMX_SEGMENT_FIELD(SS),
VMX_SEGMENT_FIELD(TR),
VMX_SEGMENT_FIELD(LDTR),
};
/*
* Keep MSR_K6_STAR at the end, as setup_msrs() will try to optimize it
* away by decrementing the array size.
*/
static const u32 vmx_msr_index[] = {
#ifdef CONFIG_X86_64
MSR_SYSCALL_MASK, MSR_LSTAR, MSR_CSTAR, MSR_KERNEL_GS_BASE,
#endif
MSR_EFER, MSR_K6_STAR,
};
#define NR_VMX_MSR ARRAY_SIZE(vmx_msr_index)
static void load_msrs(struct kvm_msr_entry *e, int n)
{
int i;
for (i = 0; i < n; ++i)
wrmsrl(e[i].index, e[i].data);
}
static void save_msrs(struct kvm_msr_entry *e, int n)
{
int i;
for (i = 0; i < n; ++i)
rdmsrl(e[i].index, e[i].data);
}
static inline int is_page_fault(u32 intr_info)
{
return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
INTR_INFO_VALID_MASK)) ==
(INTR_TYPE_EXCEPTION | PF_VECTOR | INTR_INFO_VALID_MASK);
}
static inline int is_no_device(u32 intr_info)
{
return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
INTR_INFO_VALID_MASK)) ==
(INTR_TYPE_EXCEPTION | NM_VECTOR | INTR_INFO_VALID_MASK);
}
static inline int is_invalid_opcode(u32 intr_info)
{
return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
INTR_INFO_VALID_MASK)) ==
(INTR_TYPE_EXCEPTION | UD_VECTOR | INTR_INFO_VALID_MASK);
}
static inline int is_external_interrupt(u32 intr_info)
{
return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK))
== (INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK);
}
static inline int cpu_has_vmx_msr_bitmap(void)
{
return (vmcs_config.cpu_based_exec_ctrl & CPU_BASED_USE_MSR_BITMAPS);
}
static inline int cpu_has_vmx_tpr_shadow(void)
{
return (vmcs_config.cpu_based_exec_ctrl & CPU_BASED_TPR_SHADOW);
}
static inline int vm_need_tpr_shadow(struct kvm *kvm)
{
return ((cpu_has_vmx_tpr_shadow()) && (irqchip_in_kernel(kvm)));
}
static inline int cpu_has_secondary_exec_ctrls(void)
{
return (vmcs_config.cpu_based_exec_ctrl &
CPU_BASED_ACTIVATE_SECONDARY_CONTROLS);
}
static inline bool cpu_has_vmx_virtualize_apic_accesses(void)
{
return flexpriority_enabled
&& (vmcs_config.cpu_based_2nd_exec_ctrl &
SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES);
}
static inline int cpu_has_vmx_invept_individual_addr(void)
{
return (!!(vmx_capability.ept & VMX_EPT_EXTENT_INDIVIDUAL_BIT));
}
static inline int cpu_has_vmx_invept_context(void)
{
return (!!(vmx_capability.ept & VMX_EPT_EXTENT_CONTEXT_BIT));
}
static inline int cpu_has_vmx_invept_global(void)
{
return (!!(vmx_capability.ept & VMX_EPT_EXTENT_GLOBAL_BIT));
}
static inline int cpu_has_vmx_ept(void)
{
return (vmcs_config.cpu_based_2nd_exec_ctrl &
SECONDARY_EXEC_ENABLE_EPT);
}
static inline int vm_need_ept(void)
{
return (cpu_has_vmx_ept() && enable_ept);
}
static inline int vm_need_virtualize_apic_accesses(struct kvm *kvm)
{
return ((cpu_has_vmx_virtualize_apic_accesses()) &&
(irqchip_in_kernel(kvm)));
}
static inline int cpu_has_vmx_vpid(void)
{
return (vmcs_config.cpu_based_2nd_exec_ctrl &
SECONDARY_EXEC_ENABLE_VPID);
}
static inline int cpu_has_virtual_nmis(void)
{
return vmcs_config.pin_based_exec_ctrl & PIN_BASED_VIRTUAL_NMIS;
}
static int __find_msr_index(struct vcpu_vmx *vmx, u32 msr)
{
int i;
for (i = 0; i < vmx->nmsrs; ++i)
if (vmx->guest_msrs[i].index == msr)
return i;
return -1;
}
static inline void __invvpid(int ext, u16 vpid, gva_t gva)
{
struct {
u64 vpid : 16;
u64 rsvd : 48;
u64 gva;
} operand = { vpid, 0, gva };
asm volatile (__ex(ASM_VMX_INVVPID)
/* CF==1 or ZF==1 --> rc = -1 */
"; ja 1f ; ud2 ; 1:"
: : "a"(&operand), "c"(ext) : "cc", "memory");
}
static inline void __invept(int ext, u64 eptp, gpa_t gpa)
{
struct {
u64 eptp, gpa;
} operand = {eptp, gpa};
asm volatile (__ex(ASM_VMX_INVEPT)
/* CF==1 or ZF==1 --> rc = -1 */
"; ja 1f ; ud2 ; 1:\n"
: : "a" (&operand), "c" (ext) : "cc", "memory");
}
static struct kvm_msr_entry *find_msr_entry(struct vcpu_vmx *vmx, u32 msr)
{
int i;
i = __find_msr_index(vmx, msr);
if (i >= 0)
return &vmx->guest_msrs[i];
return NULL;
}
static void vmcs_clear(struct vmcs *vmcs)
{
u64 phys_addr = __pa(vmcs);
u8 error;
asm volatile (__ex(ASM_VMX_VMCLEAR_RAX) "; setna %0"
: "=g"(error) : "a"(&phys_addr), "m"(phys_addr)
: "cc", "memory");
if (error)
printk(KERN_ERR "kvm: vmclear fail: %p/%llx\n",
vmcs, phys_addr);
}
static void __vcpu_clear(void *arg)
{
struct vcpu_vmx *vmx = arg;
int cpu = raw_smp_processor_id();
if (vmx->vcpu.cpu == cpu)
vmcs_clear(vmx->vmcs);
if (per_cpu(current_vmcs, cpu) == vmx->vmcs)
per_cpu(current_vmcs, cpu) = NULL;
rdtscll(vmx->vcpu.arch.host_tsc);
list_del(&vmx->local_vcpus_link);
vmx->vcpu.cpu = -1;
vmx->launched = 0;
}
static void vcpu_clear(struct vcpu_vmx *vmx)
{
if (vmx->vcpu.cpu == -1)
return;
smp_call_function_single(vmx->vcpu.cpu, __vcpu_clear, vmx, 1);
}
static inline void vpid_sync_vcpu_all(struct vcpu_vmx *vmx)
{
if (vmx->vpid == 0)
return;
__invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vmx->vpid, 0);
}
static inline void ept_sync_global(void)
{
if (cpu_has_vmx_invept_global())
__invept(VMX_EPT_EXTENT_GLOBAL, 0, 0);
}
static inline void ept_sync_context(u64 eptp)
{
if (vm_need_ept()) {
if (cpu_has_vmx_invept_context())
__invept(VMX_EPT_EXTENT_CONTEXT, eptp, 0);
else
ept_sync_global();
}
}
static inline void ept_sync_individual_addr(u64 eptp, gpa_t gpa)
{
if (vm_need_ept()) {
if (cpu_has_vmx_invept_individual_addr())
__invept(VMX_EPT_EXTENT_INDIVIDUAL_ADDR,
eptp, gpa);
else
ept_sync_context(eptp);
}
}
static unsigned long vmcs_readl(unsigned long field)
{
unsigned long value;
asm volatile (__ex(ASM_VMX_VMREAD_RDX_RAX)
: "=a"(value) : "d"(field) : "cc");
return value;
}
static u16 vmcs_read16(unsigned long field)
{
return vmcs_readl(field);
}
static u32 vmcs_read32(unsigned long field)
{
return vmcs_readl(field);
}
static u64 vmcs_read64(unsigned long field)
{
#ifdef CONFIG_X86_64
return vmcs_readl(field);
#else
return vmcs_readl(field) | ((u64)vmcs_readl(field+1) << 32);
#endif
}
static noinline void vmwrite_error(unsigned long field, unsigned long value)
{
printk(KERN_ERR "vmwrite error: reg %lx value %lx (err %d)\n",
field, value, vmcs_read32(VM_INSTRUCTION_ERROR));
dump_stack();
}
static void vmcs_writel(unsigned long field, unsigned long value)
{
u8 error;
asm volatile (__ex(ASM_VMX_VMWRITE_RAX_RDX) "; setna %0"
: "=q"(error) : "a"(value), "d"(field) : "cc");
if (unlikely(error))
vmwrite_error(field, value);
}
static void vmcs_write16(unsigned long field, u16 value)
{
vmcs_writel(field, value);
}
static void vmcs_write32(unsigned long field, u32 value)
{
vmcs_writel(field, value);
}
static void vmcs_write64(unsigned long field, u64 value)
{
vmcs_writel(field, value);
#ifndef CONFIG_X86_64
asm volatile ("");
vmcs_writel(field+1, value >> 32);
#endif
}
static void vmcs_clear_bits(unsigned long field, u32 mask)
{
vmcs_writel(field, vmcs_readl(field) & ~mask);
}
static void vmcs_set_bits(unsigned long field, u32 mask)
{
vmcs_writel(field, vmcs_readl(field) | mask);
}
static void update_exception_bitmap(struct kvm_vcpu *vcpu)
{
u32 eb;
eb = (1u << PF_VECTOR) | (1u << UD_VECTOR);
if (!vcpu->fpu_active)
eb |= 1u << NM_VECTOR;
if (vcpu->guest_debug.enabled)
eb |= 1u << DB_VECTOR;
if (vcpu->arch.rmode.active)
eb = ~0;
if (vm_need_ept())
eb &= ~(1u << PF_VECTOR); /* bypass_guest_pf = 0 */
vmcs_write32(EXCEPTION_BITMAP, eb);
}
static void reload_tss(void)
{
/*
* VT restores TR but not its size. Useless.
*/
struct descriptor_table gdt;
struct desc_struct *descs;
kvm_get_gdt(&gdt);
descs = (void *)gdt.base;
descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
load_TR_desc();
}
static void load_transition_efer(struct vcpu_vmx *vmx)
{
int efer_offset = vmx->msr_offset_efer;
u64 host_efer = vmx->host_msrs[efer_offset].data;
u64 guest_efer = vmx->guest_msrs[efer_offset].data;
u64 ignore_bits;
if (efer_offset < 0)
return;
/*
* NX is emulated; LMA and LME handled by hardware; SCE meaninless
* outside long mode
*/
ignore_bits = EFER_NX | EFER_SCE;
#ifdef CONFIG_X86_64
ignore_bits |= EFER_LMA | EFER_LME;
/* SCE is meaningful only in long mode on Intel */
if (guest_efer & EFER_LMA)
ignore_bits &= ~(u64)EFER_SCE;
#endif
if ((guest_efer & ~ignore_bits) == (host_efer & ~ignore_bits))
return;
vmx->host_state.guest_efer_loaded = 1;
guest_efer &= ~ignore_bits;
guest_efer |= host_efer & ignore_bits;
wrmsrl(MSR_EFER, guest_efer);
vmx->vcpu.stat.efer_reload++;
}
static void reload_host_efer(struct vcpu_vmx *vmx)
{
if (vmx->host_state.guest_efer_loaded) {
vmx->host_state.guest_efer_loaded = 0;
load_msrs(vmx->host_msrs + vmx->msr_offset_efer, 1);
}
}
static void vmx_save_host_state(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
if (vmx->host_state.loaded)
return;
vmx->host_state.loaded = 1;
/*
* Set host fs and gs selectors. Unfortunately, 22.2.3 does not
* allow segment selectors with cpl > 0 or ti == 1.
*/
vmx->host_state.ldt_sel = kvm_read_ldt();
vmx->host_state.gs_ldt_reload_needed = vmx->host_state.ldt_sel;
vmx->host_state.fs_sel = kvm_read_fs();
if (!(vmx->host_state.fs_sel & 7)) {
vmcs_write16(HOST_FS_SELECTOR, vmx->host_state.fs_sel);
vmx->host_state.fs_reload_needed = 0;
} else {
vmcs_write16(HOST_FS_SELECTOR, 0);
vmx->host_state.fs_reload_needed = 1;
}
vmx->host_state.gs_sel = kvm_read_gs();
if (!(vmx->host_state.gs_sel & 7))
vmcs_write16(HOST_GS_SELECTOR, vmx->host_state.gs_sel);
else {
vmcs_write16(HOST_GS_SELECTOR, 0);
vmx->host_state.gs_ldt_reload_needed = 1;
}
#ifdef CONFIG_X86_64
vmcs_writel(HOST_FS_BASE, read_msr(MSR_FS_BASE));
vmcs_writel(HOST_GS_BASE, read_msr(MSR_GS_BASE));
#else
vmcs_writel(HOST_FS_BASE, segment_base(vmx->host_state.fs_sel));
vmcs_writel(HOST_GS_BASE, segment_base(vmx->host_state.gs_sel));
#endif
#ifdef CONFIG_X86_64
if (is_long_mode(&vmx->vcpu))
save_msrs(vmx->host_msrs +
vmx->msr_offset_kernel_gs_base, 1);
#endif
load_msrs(vmx->guest_msrs, vmx->save_nmsrs);
load_transition_efer(vmx);
}
static void __vmx_load_host_state(struct vcpu_vmx *vmx)
{
unsigned long flags;
if (!vmx->host_state.loaded)
return;
++vmx->vcpu.stat.host_state_reload;
vmx->host_state.loaded = 0;
if (vmx->host_state.fs_reload_needed)
kvm_load_fs(vmx->host_state.fs_sel);
if (vmx->host_state.gs_ldt_reload_needed) {
kvm_load_ldt(vmx->host_state.ldt_sel);
/*
* If we have to reload gs, we must take care to
* preserve our gs base.
*/
local_irq_save(flags);
kvm_load_gs(vmx->host_state.gs_sel);
#ifdef CONFIG_X86_64
wrmsrl(MSR_GS_BASE, vmcs_readl(HOST_GS_BASE));
#endif
local_irq_restore(flags);
}
reload_tss();
save_msrs(vmx->guest_msrs, vmx->save_nmsrs);
load_msrs(vmx->host_msrs, vmx->save_nmsrs);
reload_host_efer(vmx);
}
static void vmx_load_host_state(struct vcpu_vmx *vmx)
{
preempt_disable();
__vmx_load_host_state(vmx);
preempt_enable();
}
/*
* Switches to specified vcpu, until a matching vcpu_put(), but assumes
* vcpu mutex is already taken.
*/
static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
u64 phys_addr = __pa(vmx->vmcs);
u64 tsc_this, delta, new_offset;
if (vcpu->cpu != cpu) {
vcpu_clear(vmx);
kvm_migrate_timers(vcpu);
vpid_sync_vcpu_all(vmx);
local_irq_disable();
list_add(&vmx->local_vcpus_link,
&per_cpu(vcpus_on_cpu, cpu));
local_irq_enable();
}
if (per_cpu(current_vmcs, cpu) != vmx->vmcs) {
u8 error;
per_cpu(current_vmcs, cpu) = vmx->vmcs;
asm volatile (__ex(ASM_VMX_VMPTRLD_RAX) "; setna %0"
: "=g"(error) : "a"(&phys_addr), "m"(phys_addr)
: "cc");
if (error)
printk(KERN_ERR "kvm: vmptrld %p/%llx fail\n",
vmx->vmcs, phys_addr);
}
if (vcpu->cpu != cpu) {
struct descriptor_table dt;
unsigned long sysenter_esp;
vcpu->cpu = cpu;
/*
* Linux uses per-cpu TSS and GDT, so set these when switching
* processors.
*/
vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
kvm_get_gdt(&dt);
vmcs_writel(HOST_GDTR_BASE, dt.base); /* 22.2.4 */
rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
/*
* Make sure the time stamp counter is monotonous.
*/
rdtscll(tsc_this);
if (tsc_this < vcpu->arch.host_tsc) {
delta = vcpu->arch.host_tsc - tsc_this;
new_offset = vmcs_read64(TSC_OFFSET) + delta;
vmcs_write64(TSC_OFFSET, new_offset);
}
}
}
static void vmx_vcpu_put(struct kvm_vcpu *vcpu)
{
__vmx_load_host_state(to_vmx(vcpu));
}
static void vmx_fpu_activate(struct kvm_vcpu *vcpu)
{
if (vcpu->fpu_active)
return;
vcpu->fpu_active = 1;
vmcs_clear_bits(GUEST_CR0, X86_CR0_TS);
if (vcpu->arch.cr0 & X86_CR0_TS)
vmcs_set_bits(GUEST_CR0, X86_CR0_TS);
update_exception_bitmap(vcpu);
}
static void vmx_fpu_deactivate(struct kvm_vcpu *vcpu)
{
if (!vcpu->fpu_active)
return;
vcpu->fpu_active = 0;
vmcs_set_bits(GUEST_CR0, X86_CR0_TS);
update_exception_bitmap(vcpu);
}
static unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu)
{
return vmcs_readl(GUEST_RFLAGS);
}
static void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
{
if (vcpu->arch.rmode.active)
rflags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM;
vmcs_writel(GUEST_RFLAGS, rflags);
}
static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
{
unsigned long rip;
u32 interruptibility;
rip = kvm_rip_read(vcpu);
rip += vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
kvm_rip_write(vcpu, rip);
/*
* We emulated an instruction, so temporary interrupt blocking
* should be removed, if set.
*/
interruptibility = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
if (interruptibility & 3)
vmcs_write32(GUEST_INTERRUPTIBILITY_INFO,
interruptibility & ~3);
vcpu->arch.interrupt_window_open = 1;
}
static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
bool has_error_code, u32 error_code)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
if (has_error_code)
vmcs_write32(VM_ENTRY_EXCEPTION_ERROR_CODE, error_code);
if (vcpu->arch.rmode.active) {
vmx->rmode.irq.pending = true;
vmx->rmode.irq.vector = nr;
vmx->rmode.irq.rip = kvm_rip_read(vcpu);
if (nr == BP_VECTOR)
vmx->rmode.irq.rip++;
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
nr | INTR_TYPE_SOFT_INTR
| (has_error_code ? INTR_INFO_DELIVER_CODE_MASK : 0)
| INTR_INFO_VALID_MASK);
vmcs_write32(VM_ENTRY_INSTRUCTION_LEN, 1);
kvm_rip_write(vcpu, vmx->rmode.irq.rip - 1);
return;
}
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
nr | INTR_TYPE_EXCEPTION
| (has_error_code ? INTR_INFO_DELIVER_CODE_MASK : 0)
| INTR_INFO_VALID_MASK);
}
static bool vmx_exception_injected(struct kvm_vcpu *vcpu)
{
return false;
}
/*
* Swap MSR entry in host/guest MSR entry array.
*/
#ifdef CONFIG_X86_64
static void move_msr_up(struct vcpu_vmx *vmx, int from, int to)
{
struct kvm_msr_entry tmp;
tmp = vmx->guest_msrs[to];
vmx->guest_msrs[to] = vmx->guest_msrs[from];
vmx->guest_msrs[from] = tmp;
tmp = vmx->host_msrs[to];
vmx->host_msrs[to] = vmx->host_msrs[from];
vmx->host_msrs[from] = tmp;
}
#endif
/*
* Set up the vmcs to automatically save and restore system
* msrs. Don't touch the 64-bit msrs if the guest is in legacy
* mode, as fiddling with msrs is very expensive.
*/
static void setup_msrs(struct vcpu_vmx *vmx)
{
int save_nmsrs;
vmx_load_host_state(vmx);
save_nmsrs = 0;
#ifdef CONFIG_X86_64
if (is_long_mode(&vmx->vcpu)) {
int index;
index = __find_msr_index(vmx, MSR_SYSCALL_MASK);
if (index >= 0)
move_msr_up(vmx, index, save_nmsrs++);
index = __find_msr_index(vmx, MSR_LSTAR);
if (index >= 0)
move_msr_up(vmx, index, save_nmsrs++);
index = __find_msr_index(vmx, MSR_CSTAR);
if (index >= 0)
move_msr_up(vmx, index, save_nmsrs++);
index = __find_msr_index(vmx, MSR_KERNEL_GS_BASE);
if (index >= 0)
move_msr_up(vmx, index, save_nmsrs++);
/*
* MSR_K6_STAR is only needed on long mode guests, and only
* if efer.sce is enabled.
*/
index = __find_msr_index(vmx, MSR_K6_STAR);
if ((index >= 0) && (vmx->vcpu.arch.shadow_efer & EFER_SCE))
move_msr_up(vmx, index, save_nmsrs++);
}
#endif
vmx->save_nmsrs = save_nmsrs;
#ifdef CONFIG_X86_64
vmx->msr_offset_kernel_gs_base =
__find_msr_index(vmx, MSR_KERNEL_GS_BASE);
#endif
vmx->msr_offset_efer = __find_msr_index(vmx, MSR_EFER);
}
/*
* reads and returns guest's timestamp counter "register"
* guest_tsc = host_tsc + tsc_offset -- 21.3
*/
static u64 guest_read_tsc(void)
{
u64 host_tsc, tsc_offset;
rdtscll(host_tsc);
tsc_offset = vmcs_read64(TSC_OFFSET);
return host_tsc + tsc_offset;
}
/*
* writes 'guest_tsc' into guest's timestamp counter "register"
* guest_tsc = host_tsc + tsc_offset ==> tsc_offset = guest_tsc - host_tsc
*/
static void guest_write_tsc(u64 guest_tsc)
{
u64 host_tsc;
rdtscll(host_tsc);
vmcs_write64(TSC_OFFSET, guest_tsc - host_tsc);
}
/*
* Reads an msr value (of 'msr_index') into 'pdata'.
* Returns 0 on success, non-0 otherwise.
* Assumes vcpu_load() was already called.
*/
static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
{
u64 data;
struct kvm_msr_entry *msr;
if (!pdata) {
printk(KERN_ERR "BUG: get_msr called with NULL pdata\n");
return -EINVAL;
}
switch (msr_index) {
#ifdef CONFIG_X86_64
case MSR_FS_BASE:
data = vmcs_readl(GUEST_FS_BASE);
break;
case MSR_GS_BASE:
data = vmcs_readl(GUEST_GS_BASE);
break;
case MSR_EFER:
return kvm_get_msr_common(vcpu, msr_index, pdata);
#endif
case MSR_IA32_TIME_STAMP_COUNTER:
data = guest_read_tsc();
break;
case MSR_IA32_SYSENTER_CS:
data = vmcs_read32(GUEST_SYSENTER_CS);
break;
case MSR_IA32_SYSENTER_EIP:
data = vmcs_readl(GUEST_SYSENTER_EIP);
break;
case MSR_IA32_SYSENTER_ESP:
data = vmcs_readl(GUEST_SYSENTER_ESP);
break;
default:
vmx_load_host_state(to_vmx(vcpu));
msr = find_msr_entry(to_vmx(vcpu), msr_index);
if (msr) {
data = msr->data;
break;
}
return kvm_get_msr_common(vcpu, msr_index, pdata);
}
*pdata = data;
return 0;
}
/*
* Writes msr value into into the appropriate "register".
* Returns 0 on success, non-0 otherwise.
* Assumes vcpu_load() was already called.
*/
static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct kvm_msr_entry *msr;
int ret = 0;
switch (msr_index) {
#ifdef CONFIG_X86_64
case MSR_EFER:
vmx_load_host_state(vmx);
ret = kvm_set_msr_common(vcpu, msr_index, data);
break;
case MSR_FS_BASE:
vmcs_writel(GUEST_FS_BASE, data);
break;
case MSR_GS_BASE:
vmcs_writel(GUEST_GS_BASE, data);
break;
#endif
case MSR_IA32_SYSENTER_CS:
vmcs_write32(GUEST_SYSENTER_CS, data);
break;
case MSR_IA32_SYSENTER_EIP:
vmcs_writel(GUEST_SYSENTER_EIP, data);
break;
case MSR_IA32_SYSENTER_ESP:
vmcs_writel(GUEST_SYSENTER_ESP, data);
break;
case MSR_IA32_TIME_STAMP_COUNTER:
guest_write_tsc(data);
break;
case MSR_P6_PERFCTR0:
case MSR_P6_PERFCTR1:
case MSR_P6_EVNTSEL0:
case MSR_P6_EVNTSEL1:
/*
* Just discard all writes to the performance counters; this
* should keep both older linux and windows 64-bit guests
* happy
*/
pr_unimpl(vcpu, "unimplemented perfctr wrmsr: 0x%x data 0x%llx\n", msr_index, data);
break;
case MSR_IA32_CR_PAT:
if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) {
vmcs_write64(GUEST_IA32_PAT, data);
vcpu->arch.pat = data;
break;
}
/* Otherwise falls through to kvm_set_msr_common */
default:
vmx_load_host_state(vmx);
msr = find_msr_entry(vmx, msr_index);
if (msr) {
msr->data = data;
break;
}
ret = kvm_set_msr_common(vcpu, msr_index, data);
}
return ret;
}
static void vmx_cache_reg(struct kvm_vcpu *vcpu, enum kvm_reg reg)
{
__set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
switch (reg) {
case VCPU_REGS_RSP:
vcpu->arch.regs[VCPU_REGS_RSP] = vmcs_readl(GUEST_RSP);
break;
case VCPU_REGS_RIP:
vcpu->arch.regs[VCPU_REGS_RIP] = vmcs_readl(GUEST_RIP);
break;
default:
break;
}
}
static int set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_debug_guest *dbg)
{
unsigned long dr7 = 0x400;
int old_singlestep;
old_singlestep = vcpu->guest_debug.singlestep;
vcpu->guest_debug.enabled = dbg->enabled;
if (vcpu->guest_debug.enabled) {
int i;
dr7 |= 0x200; /* exact */
for (i = 0; i < 4; ++i) {
if (!dbg->breakpoints[i].enabled)
continue;
vcpu->guest_debug.bp[i] = dbg->breakpoints[i].address;
dr7 |= 2 << (i*2); /* global enable */
dr7 |= 0 << (i*4+16); /* execution breakpoint */
}
vcpu->guest_debug.singlestep = dbg->singlestep;
} else
vcpu->guest_debug.singlestep = 0;
if (old_singlestep && !vcpu->guest_debug.singlestep) {
unsigned long flags;
flags = vmcs_readl(GUEST_RFLAGS);
flags &= ~(X86_EFLAGS_TF | X86_EFLAGS_RF);
vmcs_writel(GUEST_RFLAGS, flags);
}
update_exception_bitmap(vcpu);
vmcs_writel(GUEST_DR7, dr7);
return 0;
}
static int vmx_get_irq(struct kvm_vcpu *vcpu)
{
if (!vcpu->arch.interrupt.pending)
return -1;
return vcpu->arch.interrupt.nr;
}
static __init int cpu_has_kvm_support(void)
{
return cpu_has_vmx();
}
static __init int vmx_disabled_by_bios(void)
{
u64 msr;
rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
return (msr & (FEATURE_CONTROL_LOCKED |
FEATURE_CONTROL_VMXON_ENABLED))
== FEATURE_CONTROL_LOCKED;
/* locked but not enabled */
}
static void hardware_enable(void *garbage)
{
int cpu = raw_smp_processor_id();
u64 phys_addr = __pa(per_cpu(vmxarea, cpu));
u64 old;
INIT_LIST_HEAD(&per_cpu(vcpus_on_cpu, cpu));
rdmsrl(MSR_IA32_FEATURE_CONTROL, old);
if ((old & (FEATURE_CONTROL_LOCKED |
FEATURE_CONTROL_VMXON_ENABLED))
!= (FEATURE_CONTROL_LOCKED |
FEATURE_CONTROL_VMXON_ENABLED))
/* enable and lock */
wrmsrl(MSR_IA32_FEATURE_CONTROL, old |
FEATURE_CONTROL_LOCKED |
FEATURE_CONTROL_VMXON_ENABLED);
write_cr4(read_cr4() | X86_CR4_VMXE); /* FIXME: not cpu hotplug safe */
asm volatile (ASM_VMX_VMXON_RAX
: : "a"(&phys_addr), "m"(phys_addr)
: "memory", "cc");
}
static void vmclear_local_vcpus(void)
{
int cpu = raw_smp_processor_id();
struct vcpu_vmx *vmx, *n;
list_for_each_entry_safe(vmx, n, &per_cpu(vcpus_on_cpu, cpu),
local_vcpus_link)
__vcpu_clear(vmx);
}
/* Just like cpu_vmxoff(), but with the __kvm_handle_fault_on_reboot()
* tricks.
*/
static void kvm_cpu_vmxoff(void)
{
asm volatile (__ex(ASM_VMX_VMXOFF) : : : "cc");
write_cr4(read_cr4() & ~X86_CR4_VMXE);
}
static void hardware_disable(void *garbage)
{
vmclear_local_vcpus();
kvm_cpu_vmxoff();
}
static __init int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt,
u32 msr, u32 *result)
{
u32 vmx_msr_low, vmx_msr_high;
u32 ctl = ctl_min | ctl_opt;
rdmsr(msr, vmx_msr_low, vmx_msr_high);
ctl &= vmx_msr_high; /* bit == 0 in high word ==> must be zero */
ctl |= vmx_msr_low; /* bit == 1 in low word ==> must be one */
/* Ensure minimum (required) set of control bits are supported. */
if (ctl_min & ~ctl)
return -EIO;
*result = ctl;
return 0;
}
static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
{
u32 vmx_msr_low, vmx_msr_high;
u32 min, opt, min2, opt2;
u32 _pin_based_exec_control = 0;
u32 _cpu_based_exec_control = 0;
u32 _cpu_based_2nd_exec_control = 0;
u32 _vmexit_control = 0;
u32 _vmentry_control = 0;
min = PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING;
opt = PIN_BASED_VIRTUAL_NMIS;
if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PINBASED_CTLS,
&_pin_based_exec_control) < 0)
return -EIO;
min = CPU_BASED_HLT_EXITING |
#ifdef CONFIG_X86_64
CPU_BASED_CR8_LOAD_EXITING |
CPU_BASED_CR8_STORE_EXITING |
#endif
CPU_BASED_CR3_LOAD_EXITING |
CPU_BASED_CR3_STORE_EXITING |
CPU_BASED_USE_IO_BITMAPS |
CPU_BASED_MOV_DR_EXITING |
CPU_BASED_USE_TSC_OFFSETING |
CPU_BASED_INVLPG_EXITING;
opt = CPU_BASED_TPR_SHADOW |
CPU_BASED_USE_MSR_BITMAPS |
CPU_BASED_ACTIVATE_SECONDARY_CONTROLS;
if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PROCBASED_CTLS,
&_cpu_based_exec_control) < 0)
return -EIO;
#ifdef CONFIG_X86_64
if ((_cpu_based_exec_control & CPU_BASED_TPR_SHADOW))
_cpu_based_exec_control &= ~CPU_BASED_CR8_LOAD_EXITING &
~CPU_BASED_CR8_STORE_EXITING;
#endif
if (_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) {
min2 = 0;
opt2 = SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
SECONDARY_EXEC_WBINVD_EXITING |
SECONDARY_EXEC_ENABLE_VPID |
SECONDARY_EXEC_ENABLE_EPT;
if (adjust_vmx_controls(min2, opt2,
MSR_IA32_VMX_PROCBASED_CTLS2,
&_cpu_based_2nd_exec_control) < 0)
return -EIO;
}
#ifndef CONFIG_X86_64
if (!(_cpu_based_2nd_exec_control &
SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES))
_cpu_based_exec_control &= ~CPU_BASED_TPR_SHADOW;
#endif
if (_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_EPT) {
/* CR3 accesses and invlpg don't need to cause VM Exits when EPT
enabled */
min &= ~(CPU_BASED_CR3_LOAD_EXITING |
CPU_BASED_CR3_STORE_EXITING |
CPU_BASED_INVLPG_EXITING);
if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PROCBASED_CTLS,
&_cpu_based_exec_control) < 0)
return -EIO;
rdmsr(MSR_IA32_VMX_EPT_VPID_CAP,
vmx_capability.ept, vmx_capability.vpid);
}
min = 0;
#ifdef CONFIG_X86_64
min |= VM_EXIT_HOST_ADDR_SPACE_SIZE;
#endif
opt = VM_EXIT_SAVE_IA32_PAT | VM_EXIT_LOAD_IA32_PAT;
if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_EXIT_CTLS,
&_vmexit_control) < 0)
return -EIO;
min = 0;
opt = VM_ENTRY_LOAD_IA32_PAT;
if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_ENTRY_CTLS,
&_vmentry_control) < 0)
return -EIO;
rdmsr(MSR_IA32_VMX_BASIC, vmx_msr_low, vmx_msr_high);
/* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */
if ((vmx_msr_high & 0x1fff) > PAGE_SIZE)
return -EIO;
#ifdef CONFIG_X86_64
/* IA-32 SDM Vol 3B: 64-bit CPUs always have VMX_BASIC_MSR[48]==0. */
if (vmx_msr_high & (1u<<16))
return -EIO;
#endif
/* Require Write-Back (WB) memory type for VMCS accesses. */
if (((vmx_msr_high >> 18) & 15) != 6)
return -EIO;
vmcs_conf->size = vmx_msr_high & 0x1fff;
vmcs_conf->order = get_order(vmcs_config.size);
vmcs_conf->revision_id = vmx_msr_low;
vmcs_conf->pin_based_exec_ctrl = _pin_based_exec_control;
vmcs_conf->cpu_based_exec_ctrl = _cpu_based_exec_control;
vmcs_conf->cpu_based_2nd_exec_ctrl = _cpu_based_2nd_exec_control;
vmcs_conf->vmexit_ctrl = _vmexit_control;
vmcs_conf->vmentry_ctrl = _vmentry_control;
return 0;
}
static struct vmcs *alloc_vmcs_cpu(int cpu)
{
int node = cpu_to_node(cpu);
struct page *pages;
struct vmcs *vmcs;
pages = alloc_pages_node(node, GFP_KERNEL, vmcs_config.order);
if (!pages)
return NULL;
vmcs = page_address(pages);
memset(vmcs, 0, vmcs_config.size);
vmcs->revision_id = vmcs_config.revision_id; /* vmcs revision id */
return vmcs;
}
static struct vmcs *alloc_vmcs(void)
{
return alloc_vmcs_cpu(raw_smp_processor_id());
}
static void free_vmcs(struct vmcs *vmcs)
{
free_pages((unsigned long)vmcs, vmcs_config.order);
}
static void free_kvm_area(void)
{
int cpu;
for_each_online_cpu(cpu)
free_vmcs(per_cpu(vmxarea, cpu));
}
static __init int alloc_kvm_area(void)
{
int cpu;
for_each_online_cpu(cpu) {
struct vmcs *vmcs;
vmcs = alloc_vmcs_cpu(cpu);
if (!vmcs) {
free_kvm_area();
return -ENOMEM;
}
per_cpu(vmxarea, cpu) = vmcs;
}
return 0;
}
static __init int hardware_setup(void)
{
if (setup_vmcs_config(&vmcs_config) < 0)
return -EIO;
if (boot_cpu_has(X86_FEATURE_NX))
kvm_enable_efer_bits(EFER_NX);
return alloc_kvm_area();
}
static __exit void hardware_unsetup(void)
{
free_kvm_area();
}
static void fix_pmode_dataseg(int seg, struct kvm_save_segment *save)
{
struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
if (vmcs_readl(sf->base) == save->base && (save->base & AR_S_MASK)) {
vmcs_write16(sf->selector, save->selector);
vmcs_writel(sf->base, save->base);
vmcs_write32(sf->limit, save->limit);
vmcs_write32(sf->ar_bytes, save->ar);
} else {
u32 dpl = (vmcs_read16(sf->selector) & SELECTOR_RPL_MASK)
<< AR_DPL_SHIFT;
vmcs_write32(sf->ar_bytes, 0x93 | dpl);
}
}
static void enter_pmode(struct kvm_vcpu *vcpu)
{
unsigned long flags;
struct vcpu_vmx *vmx = to_vmx(vcpu);
vmx->emulation_required = 1;
vcpu->arch.rmode.active = 0;
vmcs_writel(GUEST_TR_BASE, vcpu->arch.rmode.tr.base);
vmcs_write32(GUEST_TR_LIMIT, vcpu->arch.rmode.tr.limit);
vmcs_write32(GUEST_TR_AR_BYTES, vcpu->arch.rmode.tr.ar);
flags = vmcs_readl(GUEST_RFLAGS);
flags &= ~(X86_EFLAGS_IOPL | X86_EFLAGS_VM);
flags |= (vcpu->arch.rmode.save_iopl << IOPL_SHIFT);
vmcs_writel(GUEST_RFLAGS, flags);
vmcs_writel(GUEST_CR4, (vmcs_readl(GUEST_CR4) & ~X86_CR4_VME) |
(vmcs_readl(CR4_READ_SHADOW) & X86_CR4_VME));
update_exception_bitmap(vcpu);
if (emulate_invalid_guest_state)
return;
fix_pmode_dataseg(VCPU_SREG_ES, &vcpu->arch.rmode.es);
fix_pmode_dataseg(VCPU_SREG_DS, &vcpu->arch.rmode.ds);
fix_pmode_dataseg(VCPU_SREG_GS, &vcpu->arch.rmode.gs);
fix_pmode_dataseg(VCPU_SREG_FS, &vcpu->arch.rmode.fs);
vmcs_write16(GUEST_SS_SELECTOR, 0);
vmcs_write32(GUEST_SS_AR_BYTES, 0x93);
vmcs_write16(GUEST_CS_SELECTOR,
vmcs_read16(GUEST_CS_SELECTOR) & ~SELECTOR_RPL_MASK);
vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
}
static gva_t rmode_tss_base(struct kvm *kvm)
{
if (!kvm->arch.tss_addr) {
gfn_t base_gfn = kvm->memslots[0].base_gfn +
kvm->memslots[0].npages - 3;
return base_gfn << PAGE_SHIFT;
}
return kvm->arch.tss_addr;
}
static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
{
struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
save->selector = vmcs_read16(sf->selector);
save->base = vmcs_readl(sf->base);
save->limit = vmcs_read32(sf->limit);
save->ar = vmcs_read32(sf->ar_bytes);
vmcs_write16(sf->selector, save->base >> 4);
vmcs_write32(sf->base, save->base & 0xfffff);
vmcs_write32(sf->limit, 0xffff);
vmcs_write32(sf->ar_bytes, 0xf3);
}
static void enter_rmode(struct kvm_vcpu *vcpu)
{
unsigned long flags;
struct vcpu_vmx *vmx = to_vmx(vcpu);
vmx->emulation_required = 1;
vcpu->arch.rmode.active = 1;
vcpu->arch.rmode.tr.base = vmcs_readl(GUEST_TR_BASE);
vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm));
vcpu->arch.rmode.tr.limit = vmcs_read32(GUEST_TR_LIMIT);
vmcs_write32(GUEST_TR_LIMIT, RMODE_TSS_SIZE - 1);
vcpu->arch.rmode.tr.ar = vmcs_read32(GUEST_TR_AR_BYTES);
vmcs_write32(GUEST_TR_AR_BYTES, 0x008b);
flags = vmcs_readl(GUEST_RFLAGS);
vcpu->arch.rmode.save_iopl
= (flags & X86_EFLAGS_IOPL) >> IOPL_SHIFT;
flags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM;
vmcs_writel(GUEST_RFLAGS, flags);
vmcs_writel(GUEST_CR4, vmcs_readl(GUEST_CR4) | X86_CR4_VME);
update_exception_bitmap(vcpu);
if (emulate_invalid_guest_state)
goto continue_rmode;
vmcs_write16(GUEST_SS_SELECTOR, vmcs_readl(GUEST_SS_BASE) >> 4);
vmcs_write32(GUEST_SS_LIMIT, 0xffff);
vmcs_write32(GUEST_SS_AR_BYTES, 0xf3);
vmcs_write32(GUEST_CS_AR_BYTES, 0xf3);
vmcs_write32(GUEST_CS_LIMIT, 0xffff);
if (vmcs_readl(GUEST_CS_BASE) == 0xffff0000)
vmcs_writel(GUEST_CS_BASE, 0xf0000);
vmcs_write16(GUEST_CS_SELECTOR, vmcs_readl(GUEST_CS_BASE) >> 4);
fix_rmode_seg(VCPU_SREG_ES, &vcpu->arch.rmode.es);
fix_rmode_seg(VCPU_SREG_DS, &vcpu->arch.rmode.ds);
fix_rmode_seg(VCPU_SREG_GS, &vcpu->arch.rmode.gs);
fix_rmode_seg(VCPU_SREG_FS, &vcpu->arch.rmode.fs);
continue_rmode:
kvm_mmu_reset_context(vcpu);
init_rmode(vcpu->kvm);
}
#ifdef CONFIG_X86_64
static void enter_lmode(struct kvm_vcpu *vcpu)
{
u32 guest_tr_ar;
guest_tr_ar = vmcs_read32(GUEST_TR_AR_BYTES);
if ((guest_tr_ar & AR_TYPE_MASK) != AR_TYPE_BUSY_64_TSS) {
printk(KERN_DEBUG "%s: tss fixup for long mode. \n",
__func__);
vmcs_write32(GUEST_TR_AR_BYTES,
(guest_tr_ar & ~AR_TYPE_MASK)
| AR_TYPE_BUSY_64_TSS);
}
vcpu->arch.shadow_efer |= EFER_LMA;
find_msr_entry(to_vmx(vcpu), MSR_EFER)->data |= EFER_LMA | EFER_LME;
vmcs_write32(VM_ENTRY_CONTROLS,
vmcs_read32(VM_ENTRY_CONTROLS)
| VM_ENTRY_IA32E_MODE);
}
static void exit_lmode(struct kvm_vcpu *vcpu)
{
vcpu->arch.shadow_efer &= ~EFER_LMA;
vmcs_write32(VM_ENTRY_CONTROLS,
vmcs_read32(VM_ENTRY_CONTROLS)
& ~VM_ENTRY_IA32E_MODE);
}
#endif
static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
{
vpid_sync_vcpu_all(to_vmx(vcpu));
if (vm_need_ept())
ept_sync_context(construct_eptp(vcpu->arch.mmu.root_hpa));
}
static void vmx_decache_cr4_guest_bits(struct kvm_vcpu *vcpu)
{
vcpu->arch.cr4 &= KVM_GUEST_CR4_MASK;
vcpu->arch.cr4 |= vmcs_readl(GUEST_CR4) & ~KVM_GUEST_CR4_MASK;
}
static void ept_load_pdptrs(struct kvm_vcpu *vcpu)
{
if (is_paging(vcpu) && is_pae(vcpu) && !is_long_mode(vcpu)) {
if (!load_pdptrs(vcpu, vcpu->arch.cr3)) {
printk(KERN_ERR "EPT: Fail to load pdptrs!\n");
return;
}
vmcs_write64(GUEST_PDPTR0, vcpu->arch.pdptrs[0]);
vmcs_write64(GUEST_PDPTR1, vcpu->arch.pdptrs[1]);
vmcs_write64(GUEST_PDPTR2, vcpu->arch.pdptrs[2]);
vmcs_write64(GUEST_PDPTR3, vcpu->arch.pdptrs[3]);
}
}
static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
static void ept_update_paging_mode_cr0(unsigned long *hw_cr0,
unsigned long cr0,
struct kvm_vcpu *vcpu)
{
if (!(cr0 & X86_CR0_PG)) {
/* From paging/starting to nonpaging */
vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
vmcs_read32(CPU_BASED_VM_EXEC_CONTROL) |
(CPU_BASED_CR3_LOAD_EXITING |
CPU_BASED_CR3_STORE_EXITING));
vcpu->arch.cr0 = cr0;
vmx_set_cr4(vcpu, vcpu->arch.cr4);
*hw_cr0 |= X86_CR0_PE | X86_CR0_PG;
*hw_cr0 &= ~X86_CR0_WP;
} else if (!is_paging(vcpu)) {
/* From nonpaging to paging */
vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
vmcs_read32(CPU_BASED_VM_EXEC_CONTROL) &
~(CPU_BASED_CR3_LOAD_EXITING |
CPU_BASED_CR3_STORE_EXITING));
vcpu->arch.cr0 = cr0;
vmx_set_cr4(vcpu, vcpu->arch.cr4);
if (!(vcpu->arch.cr0 & X86_CR0_WP))
*hw_cr0 &= ~X86_CR0_WP;
}
}
static void ept_update_paging_mode_cr4(unsigned long *hw_cr4,
struct kvm_vcpu *vcpu)
{
if (!is_paging(vcpu)) {
*hw_cr4 &= ~X86_CR4_PAE;
*hw_cr4 |= X86_CR4_PSE;
} else if (!(vcpu->arch.cr4 & X86_CR4_PAE))
*hw_cr4 &= ~X86_CR4_PAE;
}
static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
{
unsigned long hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK) |
KVM_VM_CR0_ALWAYS_ON;
vmx_fpu_deactivate(vcpu);
if (vcpu->arch.rmode.active && (cr0 & X86_CR0_PE))
enter_pmode(vcpu);
if (!vcpu->arch.rmode.active && !(cr0 & X86_CR0_PE))
enter_rmode(vcpu);
#ifdef CONFIG_X86_64
if (vcpu->arch.shadow_efer & EFER_LME) {
if (!is_paging(vcpu) && (cr0 & X86_CR0_PG))
enter_lmode(vcpu);
if (is_paging(vcpu) && !(cr0 & X86_CR0_PG))
exit_lmode(vcpu);
}
#endif
if (vm_need_ept())
ept_update_paging_mode_cr0(&hw_cr0, cr0, vcpu);
vmcs_writel(CR0_READ_SHADOW, cr0);
vmcs_writel(GUEST_CR0, hw_cr0);
vcpu->arch.cr0 = cr0;
if (!(cr0 & X86_CR0_TS) || !(cr0 & X86_CR0_PE))
vmx_fpu_activate(vcpu);
}
static u64 construct_eptp(unsigned long root_hpa)
{
u64 eptp;
/* TODO write the value reading from MSR */
eptp = VMX_EPT_DEFAULT_MT |
VMX_EPT_DEFAULT_GAW << VMX_EPT_GAW_EPTP_SHIFT;
eptp |= (root_hpa & PAGE_MASK);
return eptp;
}
static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
{
unsigned long guest_cr3;
u64 eptp;
guest_cr3 = cr3;
if (vm_need_ept()) {
eptp = construct_eptp(cr3);
vmcs_write64(EPT_POINTER, eptp);
ept_sync_context(eptp);
ept_load_pdptrs(vcpu);
guest_cr3 = is_paging(vcpu) ? vcpu->arch.cr3 :
VMX_EPT_IDENTITY_PAGETABLE_ADDR;
}
vmx_flush_tlb(vcpu);
vmcs_writel(GUEST_CR3, guest_cr3);
if (vcpu->arch.cr0 & X86_CR0_PE)
vmx_fpu_deactivate(vcpu);
}
static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
{
unsigned long hw_cr4 = cr4 | (vcpu->arch.rmode.active ?
KVM_RMODE_VM_CR4_ALWAYS_ON : KVM_PMODE_VM_CR4_ALWAYS_ON);
vcpu->arch.cr4 = cr4;
if (vm_need_ept())
ept_update_paging_mode_cr4(&hw_cr4, vcpu);
vmcs_writel(CR4_READ_SHADOW, cr4);
vmcs_writel(GUEST_CR4, hw_cr4);
}
static void vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct kvm_msr_entry *msr = find_msr_entry(vmx, MSR_EFER);
vcpu->arch.shadow_efer = efer;
if (!msr)
return;
if (efer & EFER_LMA) {
vmcs_write32(VM_ENTRY_CONTROLS,
vmcs_read32(VM_ENTRY_CONTROLS) |
VM_ENTRY_IA32E_MODE);
msr->data = efer;
} else {
vmcs_write32(VM_ENTRY_CONTROLS,
vmcs_read32(VM_ENTRY_CONTROLS) &
~VM_ENTRY_IA32E_MODE);
msr->data = efer & ~EFER_LME;
}
setup_msrs(vmx);
}
static u64 vmx_get_segment_base(struct kvm_vcpu *vcpu, int seg)
{
struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
return vmcs_readl(sf->base);
}
static void vmx_get_segment(struct kvm_vcpu *vcpu,
struct kvm_segment *var, int seg)
{
struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
u32 ar;
var->base = vmcs_readl(sf->base);
var->limit = vmcs_read32(sf->limit);
var->selector = vmcs_read16(sf->selector);
ar = vmcs_read32(sf->ar_bytes);
if (ar & AR_UNUSABLE_MASK)
ar = 0;
var->type = ar & 15;
var->s = (ar >> 4) & 1;
var->dpl = (ar >> 5) & 3;
var->present = (ar >> 7) & 1;
var->avl = (ar >> 12) & 1;
var->l = (ar >> 13) & 1;
var->db = (ar >> 14) & 1;
var->g = (ar >> 15) & 1;
var->unusable = (ar >> 16) & 1;
}
static int vmx_get_cpl(struct kvm_vcpu *vcpu)
{
struct kvm_segment kvm_seg;
if (!(vcpu->arch.cr0 & X86_CR0_PE)) /* if real mode */
return 0;
if (vmx_get_rflags(vcpu) & X86_EFLAGS_VM) /* if virtual 8086 */
return 3;
vmx_get_segment(vcpu, &kvm_seg, VCPU_SREG_CS);
return kvm_seg.selector & 3;
}
static u32 vmx_segment_access_rights(struct kvm_segment *var)
{
u32 ar;
if (var->unusable)
ar = 1 << 16;
else {
ar = var->type & 15;
ar |= (var->s & 1) << 4;
ar |= (var->dpl & 3) << 5;
ar |= (var->present & 1) << 7;
ar |= (var->avl & 1) << 12;
ar |= (var->l & 1) << 13;
ar |= (var->db & 1) << 14;
ar |= (var->g & 1) << 15;
}
if (ar == 0) /* a 0 value means unusable */
ar = AR_UNUSABLE_MASK;
return ar;
}
static void vmx_set_segment(struct kvm_vcpu *vcpu,
struct kvm_segment *var, int seg)
{
struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
u32 ar;
if (vcpu->arch.rmode.active && seg == VCPU_SREG_TR) {
vcpu->arch.rmode.tr.selector = var->selector;
vcpu->arch.rmode.tr.base = var->base;
vcpu->arch.rmode.tr.limit = var->limit;
vcpu->arch.rmode.tr.ar = vmx_segment_access_rights(var);
return;
}
vmcs_writel(sf->base, var->base);
vmcs_write32(sf->limit, var->limit);
vmcs_write16(sf->selector, var->selector);
if (vcpu->arch.rmode.active && var->s) {
/*
* Hack real-mode segments into vm86 compatibility.
*/
if (var->base == 0xffff0000 && var->selector == 0xf000)
vmcs_writel(sf->base, 0xf0000);
ar = 0xf3;
} else
ar = vmx_segment_access_rights(var);
vmcs_write32(sf->ar_bytes, ar);
}
static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
{
u32 ar = vmcs_read32(GUEST_CS_AR_BYTES);
*db = (ar >> 14) & 1;
*l = (ar >> 13) & 1;
}
static void vmx_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
{
dt->limit = vmcs_read32(GUEST_IDTR_LIMIT);
dt->base = vmcs_readl(GUEST_IDTR_BASE);
}
static void vmx_set_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
{
vmcs_write32(GUEST_IDTR_LIMIT, dt->limit);
vmcs_writel(GUEST_IDTR_BASE, dt->base);
}
static void vmx_get_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
{
dt->limit = vmcs_read32(GUEST_GDTR_LIMIT);
dt->base = vmcs_readl(GUEST_GDTR_BASE);
}
static void vmx_set_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
{
vmcs_write32(GUEST_GDTR_LIMIT, dt->limit);
vmcs_writel(GUEST_GDTR_BASE, dt->base);
}
static bool rmode_segment_valid(struct kvm_vcpu *vcpu, int seg)
{
struct kvm_segment var;
u32 ar;
vmx_get_segment(vcpu, &var, seg);
ar = vmx_segment_access_rights(&var);
if (var.base != (var.selector << 4))
return false;
if (var.limit != 0xffff)
return false;
if (ar != 0xf3)
return false;
return true;
}
static bool code_segment_valid(struct kvm_vcpu *vcpu)
{
struct kvm_segment cs;
unsigned int cs_rpl;
vmx_get_segment(vcpu, &cs, VCPU_SREG_CS);
cs_rpl = cs.selector & SELECTOR_RPL_MASK;
if (~cs.type & (AR_TYPE_CODE_MASK|AR_TYPE_ACCESSES_MASK))
return false;
if (!cs.s)
return false;
if (!(~cs.type & (AR_TYPE_CODE_MASK|AR_TYPE_WRITEABLE_MASK))) {
if (cs.dpl > cs_rpl)
return false;
} else if (cs.type & AR_TYPE_CODE_MASK) {
if (cs.dpl != cs_rpl)
return false;
}
if (!cs.present)
return false;
/* TODO: Add Reserved field check, this'll require a new member in the kvm_segment_field structure */
return true;
}
static bool stack_segment_valid(struct kvm_vcpu *vcpu)
{
struct kvm_segment ss;
unsigned int ss_rpl;
vmx_get_segment(vcpu, &ss, VCPU_SREG_SS);
ss_rpl = ss.selector & SELECTOR_RPL_MASK;
if ((ss.type != 3) || (ss.type != 7))
return false;
if (!ss.s)
return false;
if (ss.dpl != ss_rpl) /* DPL != RPL */
return false;
if (!ss.present)
return false;
return true;
}
static bool data_segment_valid(struct kvm_vcpu *vcpu, int seg)
{
struct kvm_segment var;
unsigned int rpl;
vmx_get_segment(vcpu, &var, seg);
rpl = var.selector & SELECTOR_RPL_MASK;
if (!var.s)
return false;
if (!var.present)
return false;
if (~var.type & (AR_TYPE_CODE_MASK|AR_TYPE_WRITEABLE_MASK)) {
if (var.dpl < rpl) /* DPL < RPL */
return false;
}
/* TODO: Add other members to kvm_segment_field to allow checking for other access
* rights flags
*/
return true;
}
static bool tr_valid(struct kvm_vcpu *vcpu)
{
struct kvm_segment tr;
vmx_get_segment(vcpu, &tr, VCPU_SREG_TR);
if (tr.selector & SELECTOR_TI_MASK) /* TI = 1 */
return false;
if ((tr.type != 3) || (tr.type != 11)) /* TODO: Check if guest is in IA32e mode */
return false;
if (!tr.present)
return false;
return true;
}
static bool ldtr_valid(struct kvm_vcpu *vcpu)
{
struct kvm_segment ldtr;
vmx_get_segment(vcpu, &ldtr, VCPU_SREG_LDTR);
if (ldtr.selector & SELECTOR_TI_MASK) /* TI = 1 */
return false;
if (ldtr.type != 2)
return false;
if (!ldtr.present)
return false;
return true;
}
static bool cs_ss_rpl_check(struct kvm_vcpu *vcpu)
{
struct kvm_segment cs, ss;
vmx_get_segment(vcpu, &cs, VCPU_SREG_CS);
vmx_get_segment(vcpu, &ss, VCPU_SREG_SS);
return ((cs.selector & SELECTOR_RPL_MASK) ==
(ss.selector & SELECTOR_RPL_MASK));
}
/*
* Check if guest state is valid. Returns true if valid, false if
* not.
* We assume that registers are always usable
*/
static bool guest_state_valid(struct kvm_vcpu *vcpu)
{
/* real mode guest state checks */
if (!(vcpu->arch.cr0 & X86_CR0_PE)) {
if (!rmode_segment_valid(vcpu, VCPU_SREG_CS))
return false;
if (!rmode_segment_valid(vcpu, VCPU_SREG_SS))
return false;
if (!rmode_segment_valid(vcpu, VCPU_SREG_DS))
return false;
if (!rmode_segment_valid(vcpu, VCPU_SREG_ES))
return false;
if (!rmode_segment_valid(vcpu, VCPU_SREG_FS))
return false;
if (!rmode_segment_valid(vcpu, VCPU_SREG_GS))
return false;
} else {
/* protected mode guest state checks */
if (!cs_ss_rpl_check(vcpu))
return false;
if (!code_segment_valid(vcpu))
return false;
if (!stack_segment_valid(vcpu))
return false;
if (!data_segment_valid(vcpu, VCPU_SREG_DS))
return false;
if (!data_segment_valid(vcpu, VCPU_SREG_ES))
return false;
if (!data_segment_valid(vcpu, VCPU_SREG_FS))
return false;
if (!data_segment_valid(vcpu, VCPU_SREG_GS))
return false;
if (!tr_valid(vcpu))
return false;
if (!ldtr_valid(vcpu))
return false;
}
/* TODO:
* - Add checks on RIP
* - Add checks on RFLAGS
*/
return true;
}
static int init_rmode_tss(struct kvm *kvm)
{
gfn_t fn = rmode_tss_base(kvm) >> PAGE_SHIFT;
u16 data = 0;
int ret = 0;
int r;
r = kvm_clear_guest_page(kvm, fn, 0, PAGE_SIZE);
if (r < 0)
goto out;
data = TSS_BASE_SIZE + TSS_REDIRECTION_SIZE;
r = kvm_write_guest_page(kvm, fn++, &data,
TSS_IOPB_BASE_OFFSET, sizeof(u16));
if (r < 0)
goto out;
r = kvm_clear_guest_page(kvm, fn++, 0, PAGE_SIZE);
if (r < 0)
goto out;
r = kvm_clear_guest_page(kvm, fn, 0, PAGE_SIZE);
if (r < 0)
goto out;
data = ~0;
r = kvm_write_guest_page(kvm, fn, &data,
RMODE_TSS_SIZE - 2 * PAGE_SIZE - 1,
sizeof(u8));
if (r < 0)
goto out;
ret = 1;
out:
return ret;
}
static int init_rmode_identity_map(struct kvm *kvm)
{
int i, r, ret;
pfn_t identity_map_pfn;
u32 tmp;
if (!vm_need_ept())
return 1;
if (unlikely(!kvm->arch.ept_identity_pagetable)) {
printk(KERN_ERR "EPT: identity-mapping pagetable "
"haven't been allocated!\n");
return 0;
}
if (likely(kvm->arch.ept_identity_pagetable_done))
return 1;
ret = 0;
identity_map_pfn = VMX_EPT_IDENTITY_PAGETABLE_ADDR >> PAGE_SHIFT;
r = kvm_clear_guest_page(kvm, identity_map_pfn, 0, PAGE_SIZE);
if (r < 0)
goto out;
/* Set up identity-mapping pagetable for EPT in real mode */
for (i = 0; i < PT32_ENT_PER_PAGE; i++) {
tmp = (i << 22) + (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER |
_PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_PSE);
r = kvm_write_guest_page(kvm, identity_map_pfn,
&tmp, i * sizeof(tmp), sizeof(tmp));
if (r < 0)
goto out;
}
kvm->arch.ept_identity_pagetable_done = true;
ret = 1;
out:
return ret;
}
static void seg_setup(int seg)
{
struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
vmcs_write16(sf->selector, 0);
vmcs_writel(sf->base, 0);
vmcs_write32(sf->limit, 0xffff);
vmcs_write32(sf->ar_bytes, 0xf3);
}
static int alloc_apic_access_page(struct kvm *kvm)
{
struct kvm_userspace_memory_region kvm_userspace_mem;
int r = 0;
down_write(&kvm->slots_lock);
if (kvm->arch.apic_access_page)
goto out;
kvm_userspace_mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
kvm_userspace_mem.flags = 0;
kvm_userspace_mem.guest_phys_addr = 0xfee00000ULL;
kvm_userspace_mem.memory_size = PAGE_SIZE;
r = __kvm_set_memory_region(kvm, &kvm_userspace_mem, 0);
if (r)
goto out;
kvm->arch.apic_access_page = gfn_to_page(kvm, 0xfee00);
out:
up_write(&kvm->slots_lock);
return r;
}
static int alloc_identity_pagetable(struct kvm *kvm)
{
struct kvm_userspace_memory_region kvm_userspace_mem;
int r = 0;
down_write(&kvm->slots_lock);
if (kvm->arch.ept_identity_pagetable)
goto out;
kvm_userspace_mem.slot = IDENTITY_PAGETABLE_PRIVATE_MEMSLOT;
kvm_userspace_mem.flags = 0;
kvm_userspace_mem.guest_phys_addr = VMX_EPT_IDENTITY_PAGETABLE_ADDR;
kvm_userspace_mem.memory_size = PAGE_SIZE;
r = __kvm_set_memory_region(kvm, &kvm_userspace_mem, 0);
if (r)
goto out;
kvm->arch.ept_identity_pagetable = gfn_to_page(kvm,
VMX_EPT_IDENTITY_PAGETABLE_ADDR >> PAGE_SHIFT);
out:
up_write(&kvm->slots_lock);
return r;
}
static void allocate_vpid(struct vcpu_vmx *vmx)
{
int vpid;
vmx->vpid = 0;
if (!enable_vpid || !cpu_has_vmx_vpid())
return;
spin_lock(&vmx_vpid_lock);
vpid = find_first_zero_bit(vmx_vpid_bitmap, VMX_NR_VPIDS);
if (vpid < VMX_NR_VPIDS) {
vmx->vpid = vpid;
__set_bit(vpid, vmx_vpid_bitmap);
}
spin_unlock(&vmx_vpid_lock);
}
static void vmx_disable_intercept_for_msr(struct page *msr_bitmap, u32 msr)
{
void *va;
if (!cpu_has_vmx_msr_bitmap())
return;
/*
* See Intel PRM Vol. 3, 20.6.9 (MSR-Bitmap Address). Early manuals
* have the write-low and read-high bitmap offsets the wrong way round.
* We can control MSRs 0x00000000-0x00001fff and 0xc0000000-0xc0001fff.
*/
va = kmap(msr_bitmap);
if (msr <= 0x1fff) {
__clear_bit(msr, va + 0x000); /* read-low */
__clear_bit(msr, va + 0x800); /* write-low */
} else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) {
msr &= 0x1fff;
__clear_bit(msr, va + 0x400); /* read-high */
__clear_bit(msr, va + 0xc00); /* write-high */
}
kunmap(msr_bitmap);
}
/*
* Sets up the vmcs for emulated real mode.
*/
static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
{
u32 host_sysenter_cs, msr_low, msr_high;
u32 junk;
u64 host_pat;
unsigned long a;
struct descriptor_table dt;
int i;
unsigned long kvm_vmx_return;
u32 exec_control;
/* I/O */
vmcs_write64(IO_BITMAP_A, page_to_phys(vmx_io_bitmap_a));
vmcs_write64(IO_BITMAP_B, page_to_phys(vmx_io_bitmap_b));
if (cpu_has_vmx_msr_bitmap())
vmcs_write64(MSR_BITMAP, page_to_phys(vmx_msr_bitmap));
vmcs_write64(VMCS_LINK_POINTER, -1ull); /* 22.3.1.5 */
/* Control */
vmcs_write32(PIN_BASED_VM_EXEC_CONTROL,
vmcs_config.pin_based_exec_ctrl);
exec_control = vmcs_config.cpu_based_exec_ctrl;
if (!vm_need_tpr_shadow(vmx->vcpu.kvm)) {
exec_control &= ~CPU_BASED_TPR_SHADOW;
#ifdef CONFIG_X86_64
exec_control |= CPU_BASED_CR8_STORE_EXITING |
CPU_BASED_CR8_LOAD_EXITING;
#endif
}
if (!vm_need_ept())
exec_control |= CPU_BASED_CR3_STORE_EXITING |
CPU_BASED_CR3_LOAD_EXITING |
CPU_BASED_INVLPG_EXITING;
vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, exec_control);
if (cpu_has_secondary_exec_ctrls()) {
exec_control = vmcs_config.cpu_based_2nd_exec_ctrl;
if (!vm_need_virtualize_apic_accesses(vmx->vcpu.kvm))
exec_control &=
~SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;
if (vmx->vpid == 0)
exec_control &= ~SECONDARY_EXEC_ENABLE_VPID;
if (!vm_need_ept())
exec_control &= ~SECONDARY_EXEC_ENABLE_EPT;
vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
}
vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK, !!bypass_guest_pf);
vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, !!bypass_guest_pf);
vmcs_write32(CR3_TARGET_COUNT, 0); /* 22.2.1 */
vmcs_writel(HOST_CR0, read_cr0()); /* 22.2.3 */
vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
vmcs_write16(HOST_DS_SELECTOR, __KERNEL_DS); /* 22.2.4 */
vmcs_write16(HOST_ES_SELECTOR, __KERNEL_DS); /* 22.2.4 */
vmcs_write16(HOST_FS_SELECTOR, kvm_read_fs()); /* 22.2.4 */
vmcs_write16(HOST_GS_SELECTOR, kvm_read_gs()); /* 22.2.4 */
vmcs_write16(HOST_SS_SELECTOR, __KERNEL_DS); /* 22.2.4 */
#ifdef CONFIG_X86_64
rdmsrl(MSR_FS_BASE, a);
vmcs_writel(HOST_FS_BASE, a); /* 22.2.4 */
rdmsrl(MSR_GS_BASE, a);
vmcs_writel(HOST_GS_BASE, a); /* 22.2.4 */
#else
vmcs_writel(HOST_FS_BASE, 0); /* 22.2.4 */
vmcs_writel(HOST_GS_BASE, 0); /* 22.2.4 */
#endif
vmcs_write16(HOST_TR_SELECTOR, GDT_ENTRY_TSS*8); /* 22.2.4 */
kvm_get_idt(&dt);
vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */
asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, 0);
rdmsr(MSR_IA32_SYSENTER_CS, host_sysenter_cs, junk);
vmcs_write32(HOST_IA32_SYSENTER_CS, host_sysenter_cs);
rdmsrl(MSR_IA32_SYSENTER_ESP, a);
vmcs_writel(HOST_IA32_SYSENTER_ESP, a); /* 22.2.3 */
rdmsrl(MSR_IA32_SYSENTER_EIP, a);
vmcs_writel(HOST_IA32_SYSENTER_EIP, a); /* 22.2.3 */
if (vmcs_config.vmexit_ctrl & VM_EXIT_LOAD_IA32_PAT) {
rdmsr(MSR_IA32_CR_PAT, msr_low, msr_high);
host_pat = msr_low | ((u64) msr_high << 32);
vmcs_write64(HOST_IA32_PAT, host_pat);
}
if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) {
rdmsr(MSR_IA32_CR_PAT, msr_low, msr_high);
host_pat = msr_low | ((u64) msr_high << 32);
/* Write the default value follow host pat */
vmcs_write64(GUEST_IA32_PAT, host_pat);
/* Keep arch.pat sync with GUEST_IA32_PAT */
vmx->vcpu.arch.pat = host_pat;
}
for (i = 0; i < NR_VMX_MSR; ++i) {
u32 index = vmx_msr_index[i];
u32 data_low, data_high;
u64 data;
int j = vmx->nmsrs;
if (rdmsr_safe(index, &data_low, &data_high) < 0)
continue;
if (wrmsr_safe(index, data_low, data_high) < 0)
continue;
data = data_low | ((u64)data_high << 32);
vmx->host_msrs[j].index = index;
vmx->host_msrs[j].reserved = 0;
vmx->host_msrs[j].data = data;
vmx->guest_msrs[j] = vmx->host_msrs[j];
++vmx->nmsrs;
}
vmcs_write32(VM_EXIT_CONTROLS, vmcs_config.vmexit_ctrl);
/* 22.2.1, 20.8.1 */
vmcs_write32(VM_ENTRY_CONTROLS, vmcs_config.vmentry_ctrl);
vmcs_writel(CR0_GUEST_HOST_MASK, ~0UL);
vmcs_writel(CR4_GUEST_HOST_MASK, KVM_GUEST_CR4_MASK);
return 0;
}
static int init_rmode(struct kvm *kvm)
{
if (!init_rmode_tss(kvm))
return 0;
if (!init_rmode_identity_map(kvm))
return 0;
return 1;
}
static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
u64 msr;
int ret;
vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP));
down_read(&vcpu->kvm->slots_lock);
if (!init_rmode(vmx->vcpu.kvm)) {
ret = -ENOMEM;
goto out;
}
vmx->vcpu.arch.rmode.active = 0;
vmx->soft_vnmi_blocked = 0;
vmx->vcpu.arch.regs[VCPU_REGS_RDX] = get_rdx_init_val();
kvm_set_cr8(&vmx->vcpu, 0);
msr = 0xfee00000 | MSR_IA32_APICBASE_ENABLE;
if (vmx->vcpu.vcpu_id == 0)
msr |= MSR_IA32_APICBASE_BSP;
kvm_set_apic_base(&vmx->vcpu, msr);
fx_init(&vmx->vcpu);
seg_setup(VCPU_SREG_CS);
/*
* GUEST_CS_BASE should really be 0xffff0000, but VT vm86 mode
* insists on having GUEST_CS_BASE == GUEST_CS_SELECTOR << 4. Sigh.
*/
if (vmx->vcpu.vcpu_id == 0) {
vmcs_write16(GUEST_CS_SELECTOR, 0xf000);
vmcs_writel(GUEST_CS_BASE, 0x000f0000);
} else {
vmcs_write16(GUEST_CS_SELECTOR, vmx->vcpu.arch.sipi_vector << 8);
vmcs_writel(GUEST_CS_BASE, vmx->vcpu.arch.sipi_vector << 12);
}
seg_setup(VCPU_SREG_DS);
seg_setup(VCPU_SREG_ES);
seg_setup(VCPU_SREG_FS);
seg_setup(VCPU_SREG_GS);
seg_setup(VCPU_SREG_SS);
vmcs_write16(GUEST_TR_SELECTOR, 0);
vmcs_writel(GUEST_TR_BASE, 0);
vmcs_write32(GUEST_TR_LIMIT, 0xffff);
vmcs_write32(GUEST_TR_AR_BYTES, 0x008b);
vmcs_write16(GUEST_LDTR_SELECTOR, 0);
vmcs_writel(GUEST_LDTR_BASE, 0);
vmcs_write32(GUEST_LDTR_LIMIT, 0xffff);
vmcs_write32(GUEST_LDTR_AR_BYTES, 0x00082);
vmcs_write32(GUEST_SYSENTER_CS, 0);
vmcs_writel(GUEST_SYSENTER_ESP, 0);
vmcs_writel(GUEST_SYSENTER_EIP, 0);
vmcs_writel(GUEST_RFLAGS, 0x02);
if (vmx->vcpu.vcpu_id == 0)
kvm_rip_write(vcpu, 0xfff0);
else
kvm_rip_write(vcpu, 0);
kvm_register_write(vcpu, VCPU_REGS_RSP, 0);
/* todo: dr0 = dr1 = dr2 = dr3 = 0; dr6 = 0xffff0ff0 */
vmcs_writel(GUEST_DR7, 0x400);
vmcs_writel(GUEST_GDTR_BASE, 0);
vmcs_write32(GUEST_GDTR_LIMIT, 0xffff);
vmcs_writel(GUEST_IDTR_BASE, 0);
vmcs_write32(GUEST_IDTR_LIMIT, 0xffff);
vmcs_write32(GUEST_ACTIVITY_STATE, 0);
vmcs_write32(GUEST_INTERRUPTIBILITY_INFO, 0);
vmcs_write32(GUEST_PENDING_DBG_EXCEPTIONS, 0);
guest_write_tsc(0);
/* Special registers */
vmcs_write64(GUEST_IA32_DEBUGCTL, 0);
setup_msrs(vmx);
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */
if (cpu_has_vmx_tpr_shadow()) {
vmcs_write64(VIRTUAL_APIC_PAGE_ADDR, 0);
if (vm_need_tpr_shadow(vmx->vcpu.kvm))
vmcs_write64(VIRTUAL_APIC_PAGE_ADDR,
page_to_phys(vmx->vcpu.arch.apic->regs_page));
vmcs_write32(TPR_THRESHOLD, 0);
}
if (vm_need_virtualize_apic_accesses(vmx->vcpu.kvm))
vmcs_write64(APIC_ACCESS_ADDR,
page_to_phys(vmx->vcpu.kvm->arch.apic_access_page));
if (vmx->vpid != 0)
vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid);
vmx->vcpu.arch.cr0 = 0x60000010;
vmx_set_cr0(&vmx->vcpu, vmx->vcpu.arch.cr0); /* enter rmode */
vmx_set_cr4(&vmx->vcpu, 0);
vmx_set_efer(&vmx->vcpu, 0);
vmx_fpu_activate(&vmx->vcpu);
update_exception_bitmap(&vmx->vcpu);
vpid_sync_vcpu_all(vmx);
ret = 0;
/* HACK: Don't enable emulation on guest boot/reset */
vmx->emulation_required = 0;
out:
up_read(&vcpu->kvm->slots_lock);
return ret;
}
static void enable_irq_window(struct kvm_vcpu *vcpu)
{
u32 cpu_based_vm_exec_control;
cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
}
static void enable_nmi_window(struct kvm_vcpu *vcpu)
{
u32 cpu_based_vm_exec_control;
if (!cpu_has_virtual_nmis()) {
enable_irq_window(vcpu);
return;
}
cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
cpu_based_vm_exec_control |= CPU_BASED_VIRTUAL_NMI_PENDING;
vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
}
static void vmx_inject_irq(struct kvm_vcpu *vcpu, int irq)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
KVMTRACE_1D(INJ_VIRQ, vcpu, (u32)irq, handler);
++vcpu->stat.irq_injections;
if (vcpu->arch.rmode.active) {
vmx->rmode.irq.pending = true;
vmx->rmode.irq.vector = irq;
vmx->rmode.irq.rip = kvm_rip_read(vcpu);
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
irq | INTR_TYPE_SOFT_INTR | INTR_INFO_VALID_MASK);
vmcs_write32(VM_ENTRY_INSTRUCTION_LEN, 1);
kvm_rip_write(vcpu, vmx->rmode.irq.rip - 1);
return;
}
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
irq | INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK);
}
static void vmx_inject_nmi(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
if (!cpu_has_virtual_nmis()) {
/*
* Tracking the NMI-blocked state in software is built upon
* finding the next open IRQ window. This, in turn, depends on
* well-behaving guests: They have to keep IRQs disabled at
* least as long as the NMI handler runs. Otherwise we may
* cause NMI nesting, maybe breaking the guest. But as this is
* highly unlikely, we can live with the residual risk.
*/
vmx->soft_vnmi_blocked = 1;
vmx->vnmi_blocked_time = 0;
}
++vcpu->stat.nmi_injections;
if (vcpu->arch.rmode.active) {
vmx->rmode.irq.pending = true;
vmx->rmode.irq.vector = NMI_VECTOR;
vmx->rmode.irq.rip = kvm_rip_read(vcpu);
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
NMI_VECTOR | INTR_TYPE_SOFT_INTR |
INTR_INFO_VALID_MASK);
vmcs_write32(VM_ENTRY_INSTRUCTION_LEN, 1);
kvm_rip_write(vcpu, vmx->rmode.irq.rip - 1);
return;
}
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR);
}
static void vmx_update_window_states(struct kvm_vcpu *vcpu)
{
u32 guest_intr = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
vcpu->arch.nmi_window_open =
!(guest_intr & (GUEST_INTR_STATE_STI |
GUEST_INTR_STATE_MOV_SS |
GUEST_INTR_STATE_NMI));
if (!cpu_has_virtual_nmis() && to_vmx(vcpu)->soft_vnmi_blocked)
vcpu->arch.nmi_window_open = 0;
vcpu->arch.interrupt_window_open =
((vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF) &&
!(guest_intr & (GUEST_INTR_STATE_STI |
GUEST_INTR_STATE_MOV_SS)));
}
static void kvm_do_inject_irq(struct kvm_vcpu *vcpu)
{
int word_index = __ffs(vcpu->arch.irq_summary);
int bit_index = __ffs(vcpu->arch.irq_pending[word_index]);
int irq = word_index * BITS_PER_LONG + bit_index;
clear_bit(bit_index, &vcpu->arch.irq_pending[word_index]);
if (!vcpu->arch.irq_pending[word_index])
clear_bit(word_index, &vcpu->arch.irq_summary);
kvm_queue_interrupt(vcpu, irq);
}
static void do_interrupt_requests(struct kvm_vcpu *vcpu,
struct kvm_run *kvm_run)
{
vmx_update_window_states(vcpu);
if (vcpu->arch.nmi_pending && !vcpu->arch.nmi_injected) {
if (vcpu->arch.interrupt.pending) {
enable_nmi_window(vcpu);
} else if (vcpu->arch.nmi_window_open) {
vcpu->arch.nmi_pending = false;
vcpu->arch.nmi_injected = true;
} else {
enable_nmi_window(vcpu);
return;
}
}
if (vcpu->arch.nmi_injected) {
vmx_inject_nmi(vcpu);
if (vcpu->arch.nmi_pending)
enable_nmi_window(vcpu);
else if (vcpu->arch.irq_summary
|| kvm_run->request_interrupt_window)
enable_irq_window(vcpu);
return;
}
if (vcpu->arch.interrupt_window_open) {
if (vcpu->arch.irq_summary && !vcpu->arch.interrupt.pending)
kvm_do_inject_irq(vcpu);
if (vcpu->arch.interrupt.pending)
vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
}
if (!vcpu->arch.interrupt_window_open &&
(vcpu->arch.irq_summary || kvm_run->request_interrupt_window))
enable_irq_window(vcpu);
}
static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr)
{
int ret;
struct kvm_userspace_memory_region tss_mem = {
.slot = TSS_PRIVATE_MEMSLOT,
.guest_phys_addr = addr,
.memory_size = PAGE_SIZE * 3,
.flags = 0,
};
ret = kvm_set_memory_region(kvm, &tss_mem, 0);
if (ret)
return ret;
kvm->arch.tss_addr = addr;
return 0;
}
static void kvm_guest_debug_pre(struct kvm_vcpu *vcpu)
{
struct kvm_guest_debug *dbg = &vcpu->guest_debug;
set_debugreg(dbg->bp[0], 0);
set_debugreg(dbg->bp[1], 1);
set_debugreg(dbg->bp[2], 2);
set_debugreg(dbg->bp[3], 3);
if (dbg->singlestep) {
unsigned long flags;
flags = vmcs_readl(GUEST_RFLAGS);
flags |= X86_EFLAGS_TF | X86_EFLAGS_RF;
vmcs_writel(GUEST_RFLAGS, flags);
}
}
static int handle_rmode_exception(struct kvm_vcpu *vcpu,
int vec, u32 err_code)
{
/*
* Instruction with address size override prefix opcode 0x67
* Cause the #SS fault with 0 error code in VM86 mode.
*/
if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0)
if (emulate_instruction(vcpu, NULL, 0, 0, 0) == EMULATE_DONE)
return 1;
/*
* Forward all other exceptions that are valid in real mode.
* FIXME: Breaks guest debugging in real mode, needs to be fixed with
* the required debugging infrastructure rework.
*/
switch (vec) {
case DE_VECTOR:
case DB_VECTOR:
case BP_VECTOR:
case OF_VECTOR:
case BR_VECTOR:
case UD_VECTOR:
case DF_VECTOR:
case SS_VECTOR:
case GP_VECTOR:
case MF_VECTOR:
kvm_queue_exception(vcpu, vec);
return 1;
}
return 0;
}
static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
u32 intr_info, error_code;
unsigned long cr2, rip;
u32 vect_info;
enum emulation_result er;
vect_info = vmx->idt_vectoring_info;
intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
if ((vect_info & VECTORING_INFO_VALID_MASK) &&
!is_page_fault(intr_info))
printk(KERN_ERR "%s: unexpected, vectoring info 0x%x "
"intr info 0x%x\n", __func__, vect_info, intr_info);
if (!irqchip_in_kernel(vcpu->kvm) && is_external_interrupt(vect_info)) {
int irq = vect_info & VECTORING_INFO_VECTOR_MASK;
set_bit(irq, vcpu->arch.irq_pending);
set_bit(irq / BITS_PER_LONG, &vcpu->arch.irq_summary);
}
if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR)
return 1; /* already handled by vmx_vcpu_run() */
if (is_no_device(intr_info)) {
vmx_fpu_activate(vcpu);
return 1;
}
if (is_invalid_opcode(intr_info)) {
er = emulate_instruction(vcpu, kvm_run, 0, 0, EMULTYPE_TRAP_UD);
if (er != EMULATE_DONE)
kvm_queue_exception(vcpu, UD_VECTOR);
return 1;
}
error_code = 0;
rip = kvm_rip_read(vcpu);
if (intr_info & INTR_INFO_DELIVER_CODE_MASK)
error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE);
if (is_page_fault(intr_info)) {
/* EPT won't cause page fault directly */
if (vm_need_ept())
BUG();
cr2 = vmcs_readl(EXIT_QUALIFICATION);
KVMTRACE_3D(PAGE_FAULT, vcpu, error_code, (u32)cr2,
(u32)((u64)cr2 >> 32), handler);
if (vcpu->arch.interrupt.pending || vcpu->arch.exception.pending)
kvm_mmu_unprotect_page_virt(vcpu, cr2);
return kvm_mmu_page_fault(vcpu, cr2, error_code);
}
if (vcpu->arch.rmode.active &&
handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK,
error_code)) {
if (vcpu->arch.halt_request) {
vcpu->arch.halt_request = 0;
return kvm_emulate_halt(vcpu);
}
return 1;
}
if ((intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK)) ==
(INTR_TYPE_EXCEPTION | 1)) {
kvm_run->exit_reason = KVM_EXIT_DEBUG;
return 0;
}
kvm_run->exit_reason = KVM_EXIT_EXCEPTION;
kvm_run->ex.exception = intr_info & INTR_INFO_VECTOR_MASK;
kvm_run->ex.error_code = error_code;
return 0;
}
static int handle_external_interrupt(struct kvm_vcpu *vcpu,
struct kvm_run *kvm_run)
{
++vcpu->stat.irq_exits;
KVMTRACE_1D(INTR, vcpu, vmcs_read32(VM_EXIT_INTR_INFO), handler);
return 1;
}
static int handle_triple_fault(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
kvm_run->exit_reason = KVM_EXIT_SHUTDOWN;
return 0;
}
static int handle_io(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
unsigned long exit_qualification;
int size, down, in, string, rep;
unsigned port;
++vcpu->stat.io_exits;
exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
string = (exit_qualification & 16) != 0;
if (string) {
if (emulate_instruction(vcpu,
kvm_run, 0, 0, 0) == EMULATE_DO_MMIO)
return 0;
return 1;
}
size = (exit_qualification & 7) + 1;
in = (exit_qualification & 8) != 0;
down = (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_DF) != 0;
rep = (exit_qualification & 32) != 0;
port = exit_qualification >> 16;
skip_emulated_instruction(vcpu);
return kvm_emulate_pio(vcpu, kvm_run, in, size, port);
}
static void
vmx_patch_hypercall(struct kvm_vcpu *vcpu, unsigned char *hypercall)
{
/*
* Patch in the VMCALL instruction:
*/
hypercall[0] = 0x0f;
hypercall[1] = 0x01;
hypercall[2] = 0xc1;
}
static int handle_cr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
unsigned long exit_qualification;
int cr;
int reg;
exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
cr = exit_qualification & 15;
reg = (exit_qualification >> 8) & 15;
switch ((exit_qualification >> 4) & 3) {
case 0: /* mov to cr */
KVMTRACE_3D(CR_WRITE, vcpu, (u32)cr,
(u32)kvm_register_read(vcpu, reg),
(u32)((u64)kvm_register_read(vcpu, reg) >> 32),
handler);
switch (cr) {
case 0:
kvm_set_cr0(vcpu, kvm_register_read(vcpu, reg));
skip_emulated_instruction(vcpu);
return 1;
case 3:
kvm_set_cr3(vcpu, kvm_register_read(vcpu, reg));
skip_emulated_instruction(vcpu);
return 1;
case 4:
kvm_set_cr4(vcpu, kvm_register_read(vcpu, reg));
skip_emulated_instruction(vcpu);
return 1;
case 8:
kvm_set_cr8(vcpu, kvm_register_read(vcpu, reg));
skip_emulated_instruction(vcpu);
if (irqchip_in_kernel(vcpu->kvm))
return 1;
kvm_run->exit_reason = KVM_EXIT_SET_TPR;
return 0;
};
break;
case 2: /* clts */
vmx_fpu_deactivate(vcpu);
vcpu->arch.cr0 &= ~X86_CR0_TS;
vmcs_writel(CR0_READ_SHADOW, vcpu->arch.cr0);
vmx_fpu_activate(vcpu);
KVMTRACE_0D(CLTS, vcpu, handler);
skip_emulated_instruction(vcpu);
return 1;
case 1: /*mov from cr*/
switch (cr) {
case 3:
kvm_register_write(vcpu, reg, vcpu->arch.cr3);
KVMTRACE_3D(CR_READ, vcpu, (u32)cr,
(u32)kvm_register_read(vcpu, reg),
(u32)((u64)kvm_register_read(vcpu, reg) >> 32),
handler);
skip_emulated_instruction(vcpu);
return 1;
case 8:
kvm_register_write(vcpu, reg, kvm_get_cr8(vcpu));
KVMTRACE_2D(CR_READ, vcpu, (u32)cr,
(u32)kvm_register_read(vcpu, reg), handler);
skip_emulated_instruction(vcpu);
return 1;
}
break;
case 3: /* lmsw */
kvm_lmsw(vcpu, (exit_qualification >> LMSW_SOURCE_DATA_SHIFT) & 0x0f);
skip_emulated_instruction(vcpu);
return 1;
default:
break;
}
kvm_run->exit_reason = 0;
pr_unimpl(vcpu, "unhandled control register: op %d cr %d\n",
(int)(exit_qualification >> 4) & 3, cr);
return 0;
}
static int handle_dr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
unsigned long exit_qualification;
unsigned long val;
int dr, reg;
/*
* FIXME: this code assumes the host is debugging the guest.
* need to deal with guest debugging itself too.
*/
exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
dr = exit_qualification & 7;
reg = (exit_qualification >> 8) & 15;
if (exit_qualification & 16) {
/* mov from dr */
switch (dr) {
case 6:
val = 0xffff0ff0;
break;
case 7:
val = 0x400;
break;
default:
val = 0;
}
kvm_register_write(vcpu, reg, val);
KVMTRACE_2D(DR_READ, vcpu, (u32)dr, (u32)val, handler);
} else {
/* mov to dr */
}
skip_emulated_instruction(vcpu);
return 1;
}
static int handle_cpuid(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
kvm_emulate_cpuid(vcpu);
return 1;
}
static int handle_rdmsr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
u32 ecx = vcpu->arch.regs[VCPU_REGS_RCX];
u64 data;
if (vmx_get_msr(vcpu, ecx, &data)) {
kvm_inject_gp(vcpu, 0);
return 1;
}
KVMTRACE_3D(MSR_READ, vcpu, ecx, (u32)data, (u32)(data >> 32),
handler);
/* FIXME: handling of bits 32:63 of rax, rdx */
vcpu->arch.regs[VCPU_REGS_RAX] = data & -1u;
vcpu->arch.regs[VCPU_REGS_RDX] = (data >> 32) & -1u;
skip_emulated_instruction(vcpu);
return 1;
}
static int handle_wrmsr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
u32 ecx = vcpu->arch.regs[VCPU_REGS_RCX];
u64 data = (vcpu->arch.regs[VCPU_REGS_RAX] & -1u)
| ((u64)(vcpu->arch.regs[VCPU_REGS_RDX] & -1u) << 32);
KVMTRACE_3D(MSR_WRITE, vcpu, ecx, (u32)data, (u32)(data >> 32),
handler);
if (vmx_set_msr(vcpu, ecx, data) != 0) {
kvm_inject_gp(vcpu, 0);
return 1;
}
skip_emulated_instruction(vcpu);
return 1;
}
static int handle_tpr_below_threshold(struct kvm_vcpu *vcpu,
struct kvm_run *kvm_run)
{
return 1;
}
static int handle_interrupt_window(struct kvm_vcpu *vcpu,
struct kvm_run *kvm_run)
{
u32 cpu_based_vm_exec_control;
/* clear pending irq */
cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING;
vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
KVMTRACE_0D(PEND_INTR, vcpu, handler);
++vcpu->stat.irq_window_exits;
/*
* If the user space waits to inject interrupts, exit as soon as
* possible
*/
if (kvm_run->request_interrupt_window &&
!vcpu->arch.irq_summary) {
kvm_run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN;
return 0;
}
return 1;
}
static int handle_halt(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
skip_emulated_instruction(vcpu);
return kvm_emulate_halt(vcpu);
}
static int handle_vmcall(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
skip_emulated_instruction(vcpu);
kvm_emulate_hypercall(vcpu);
return 1;
}
static int handle_invlpg(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
u64 exit_qualification = vmcs_read64(EXIT_QUALIFICATION);
kvm_mmu_invlpg(vcpu, exit_qualification);
skip_emulated_instruction(vcpu);
return 1;
}
static int handle_wbinvd(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
skip_emulated_instruction(vcpu);
/* TODO: Add support for VT-d/pass-through device */
return 1;
}
static int handle_apic_access(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
u64 exit_qualification;
enum emulation_result er;
unsigned long offset;
exit_qualification = vmcs_read64(EXIT_QUALIFICATION);
offset = exit_qualification & 0xffful;
er = emulate_instruction(vcpu, kvm_run, 0, 0, 0);
if (er != EMULATE_DONE) {
printk(KERN_ERR
"Fail to handle apic access vmexit! Offset is 0x%lx\n",
offset);
return -ENOTSUPP;
}
return 1;
}
static int handle_task_switch(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
unsigned long exit_qualification;
u16 tss_selector;
int reason;
exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
reason = (u32)exit_qualification >> 30;
if (reason == TASK_SWITCH_GATE && vmx->vcpu.arch.nmi_injected &&
(vmx->idt_vectoring_info & VECTORING_INFO_VALID_MASK) &&
(vmx->idt_vectoring_info & VECTORING_INFO_TYPE_MASK)
== INTR_TYPE_NMI_INTR) {
vcpu->arch.nmi_injected = false;
if (cpu_has_virtual_nmis())
vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO,
GUEST_INTR_STATE_NMI);
}
tss_selector = exit_qualification;
return kvm_task_switch(vcpu, tss_selector, reason);
}
static int handle_ept_violation(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
u64 exit_qualification;
enum emulation_result er;
gpa_t gpa;
unsigned long hva;
int gla_validity;
int r;
exit_qualification = vmcs_read64(EXIT_QUALIFICATION);
if (exit_qualification & (1 << 6)) {
printk(KERN_ERR "EPT: GPA exceeds GAW!\n");
return -ENOTSUPP;
}
gla_validity = (exit_qualification >> 7) & 0x3;
if (gla_validity != 0x3 && gla_validity != 0x1 && gla_validity != 0) {
printk(KERN_ERR "EPT: Handling EPT violation failed!\n");
printk(KERN_ERR "EPT: GPA: 0x%lx, GVA: 0x%lx\n",
(long unsigned int)vmcs_read64(GUEST_PHYSICAL_ADDRESS),
(long unsigned int)vmcs_read64(GUEST_LINEAR_ADDRESS));
printk(KERN_ERR "EPT: Exit qualification is 0x%lx\n",
(long unsigned int)exit_qualification);
kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
kvm_run->hw.hardware_exit_reason = 0;
return -ENOTSUPP;
}
gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
hva = gfn_to_hva(vcpu->kvm, gpa >> PAGE_SHIFT);
if (!kvm_is_error_hva(hva)) {
r = kvm_mmu_page_fault(vcpu, gpa & PAGE_MASK, 0);
if (r < 0) {
printk(KERN_ERR "EPT: Not enough memory!\n");
return -ENOMEM;
}
return 1;
} else {
/* must be MMIO */
er = emulate_instruction(vcpu, kvm_run, 0, 0, 0);
if (er == EMULATE_FAIL) {
printk(KERN_ERR
"EPT: Fail to handle EPT violation vmexit!er is %d\n",
er);
printk(KERN_ERR "EPT: GPA: 0x%lx, GVA: 0x%lx\n",
(long unsigned int)vmcs_read64(GUEST_PHYSICAL_ADDRESS),
(long unsigned int)vmcs_read64(GUEST_LINEAR_ADDRESS));
printk(KERN_ERR "EPT: Exit qualification is 0x%lx\n",
(long unsigned int)exit_qualification);
return -ENOTSUPP;
} else if (er == EMULATE_DO_MMIO)
return 0;
}
return 1;
}
static int handle_nmi_window(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
u32 cpu_based_vm_exec_control;
/* clear pending NMI */
cpu_based_vm_exec_control = vmcs_read32(CPU_BASED_VM_EXEC_CONTROL);
cpu_based_vm_exec_control &= ~CPU_BASED_VIRTUAL_NMI_PENDING;
vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
++vcpu->stat.nmi_window_exits;
return 1;
}
static void handle_invalid_guest_state(struct kvm_vcpu *vcpu,
struct kvm_run *kvm_run)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
int err;
preempt_enable();
local_irq_enable();
while (!guest_state_valid(vcpu)) {
err = emulate_instruction(vcpu, kvm_run, 0, 0, 0);
if (err == EMULATE_DO_MMIO)
break;
if (err != EMULATE_DONE) {
kvm_report_emulation_failure(vcpu, "emulation failure");
return;
}
if (signal_pending(current))
break;
if (need_resched())
schedule();
}
local_irq_disable();
preempt_disable();
/* Guest state should be valid now except if we need to
* emulate an MMIO */
if (guest_state_valid(vcpu))
vmx->emulation_required = 0;
}
/*
* The exit handlers return 1 if the exit was handled fully and guest execution
* may resume. Otherwise they set the kvm_run parameter to indicate what needs
* to be done to userspace and return 0.
*/
static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
struct kvm_run *kvm_run) = {
[EXIT_REASON_EXCEPTION_NMI] = handle_exception,
[EXIT_REASON_EXTERNAL_INTERRUPT] = handle_external_interrupt,
[EXIT_REASON_TRIPLE_FAULT] = handle_triple_fault,
[EXIT_REASON_NMI_WINDOW] = handle_nmi_window,
[EXIT_REASON_IO_INSTRUCTION] = handle_io,
[EXIT_REASON_CR_ACCESS] = handle_cr,
[EXIT_REASON_DR_ACCESS] = handle_dr,
[EXIT_REASON_CPUID] = handle_cpuid,
[EXIT_REASON_MSR_READ] = handle_rdmsr,
[EXIT_REASON_MSR_WRITE] = handle_wrmsr,
[EXIT_REASON_PENDING_INTERRUPT] = handle_interrupt_window,
[EXIT_REASON_HLT] = handle_halt,
[EXIT_REASON_INVLPG] = handle_invlpg,
[EXIT_REASON_VMCALL] = handle_vmcall,
[EXIT_REASON_TPR_BELOW_THRESHOLD] = handle_tpr_below_threshold,
[EXIT_REASON_APIC_ACCESS] = handle_apic_access,
[EXIT_REASON_WBINVD] = handle_wbinvd,
[EXIT_REASON_TASK_SWITCH] = handle_task_switch,
[EXIT_REASON_EPT_VIOLATION] = handle_ept_violation,
};
static const int kvm_vmx_max_exit_handlers =
ARRAY_SIZE(kvm_vmx_exit_handlers);
/*
* The guest has exited. See if we can fix it or if we need userspace
* assistance.
*/
static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
{
u32 exit_reason = vmcs_read32(VM_EXIT_REASON);
struct vcpu_vmx *vmx = to_vmx(vcpu);
u32 vectoring_info = vmx->idt_vectoring_info;
KVMTRACE_3D(VMEXIT, vcpu, exit_reason, (u32)kvm_rip_read(vcpu),
(u32)((u64)kvm_rip_read(vcpu) >> 32), entryexit);
/* If we need to emulate an MMIO from handle_invalid_guest_state
* we just return 0 */
if (vmx->emulation_required && emulate_invalid_guest_state)
return 0;
/* Access CR3 don't cause VMExit in paging mode, so we need
* to sync with guest real CR3. */
if (vm_need_ept() && is_paging(vcpu)) {
vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
ept_load_pdptrs(vcpu);
}
if (unlikely(vmx->fail)) {
kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
kvm_run->fail_entry.hardware_entry_failure_reason
= vmcs_read32(VM_INSTRUCTION_ERROR);
return 0;
}
if ((vectoring_info & VECTORING_INFO_VALID_MASK) &&
(exit_reason != EXIT_REASON_EXCEPTION_NMI &&
exit_reason != EXIT_REASON_EPT_VIOLATION &&
exit_reason != EXIT_REASON_TASK_SWITCH))
printk(KERN_WARNING "%s: unexpected, valid vectoring info "
"(0x%x) and exit reason is 0x%x\n",
__func__, vectoring_info, exit_reason);
if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked)) {
if (vcpu->arch.interrupt_window_open) {
vmx->soft_vnmi_blocked = 0;
vcpu->arch.nmi_window_open = 1;
} else if (vmx->vnmi_blocked_time > 1000000000LL &&
vcpu->arch.nmi_pending) {
/*
* This CPU don't support us in finding the end of an
* NMI-blocked window if the guest runs with IRQs
* disabled. So we pull the trigger after 1 s of
* futile waiting, but inform the user about this.
*/
printk(KERN_WARNING "%s: Breaking out of NMI-blocked "
"state on VCPU %d after 1 s timeout\n",
__func__, vcpu->vcpu_id);
vmx->soft_vnmi_blocked = 0;
vmx->vcpu.arch.nmi_window_open = 1;
}
}
if (exit_reason < kvm_vmx_max_exit_handlers
&& kvm_vmx_exit_handlers[exit_reason])
return kvm_vmx_exit_handlers[exit_reason](vcpu, kvm_run);
else {
kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
kvm_run->hw.hardware_exit_reason = exit_reason;
}
return 0;
}
static void update_tpr_threshold(struct kvm_vcpu *vcpu)
{
int max_irr, tpr;
if (!vm_need_tpr_shadow(vcpu->kvm))
return;
if (!kvm_lapic_enabled(vcpu) ||
((max_irr = kvm_lapic_find_highest_irr(vcpu)) == -1)) {
vmcs_write32(TPR_THRESHOLD, 0);
return;
}
tpr = (kvm_lapic_get_cr8(vcpu) & 0x0f) << 4;
vmcs_write32(TPR_THRESHOLD, (max_irr > tpr) ? tpr >> 4 : max_irr >> 4);
}
static void vmx_complete_interrupts(struct vcpu_vmx *vmx)
{
u32 exit_intr_info;
u32 idt_vectoring_info;
bool unblock_nmi;
u8 vector;
int type;
bool idtv_info_valid;
u32 error;
exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
if (cpu_has_virtual_nmis()) {
unblock_nmi = (exit_intr_info & INTR_INFO_UNBLOCK_NMI) != 0;
vector = exit_intr_info & INTR_INFO_VECTOR_MASK;
/*
* SDM 3: 25.7.1.2
* Re-set bit "block by NMI" before VM entry if vmexit caused by
* a guest IRET fault.
*/
if (unblock_nmi && vector != DF_VECTOR)
vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO,
GUEST_INTR_STATE_NMI);
} else if (unlikely(vmx->soft_vnmi_blocked))
vmx->vnmi_blocked_time +=
ktime_to_ns(ktime_sub(ktime_get(), vmx->entry_time));
idt_vectoring_info = vmx->idt_vectoring_info;
idtv_info_valid = idt_vectoring_info & VECTORING_INFO_VALID_MASK;
vector = idt_vectoring_info & VECTORING_INFO_VECTOR_MASK;
type = idt_vectoring_info & VECTORING_INFO_TYPE_MASK;
if (vmx->vcpu.arch.nmi_injected) {
/*
* SDM 3: 25.7.1.2
* Clear bit "block by NMI" before VM entry if a NMI delivery
* faulted.
*/
if (idtv_info_valid && type == INTR_TYPE_NMI_INTR)
vmcs_clear_bits(GUEST_INTERRUPTIBILITY_INFO,
GUEST_INTR_STATE_NMI);
else
vmx->vcpu.arch.nmi_injected = false;
}
kvm_clear_exception_queue(&vmx->vcpu);
if (idtv_info_valid && type == INTR_TYPE_EXCEPTION) {
if (idt_vectoring_info & VECTORING_INFO_DELIVER_CODE_MASK) {
error = vmcs_read32(IDT_VECTORING_ERROR_CODE);
kvm_queue_exception_e(&vmx->vcpu, vector, error);
} else
kvm_queue_exception(&vmx->vcpu, vector);
vmx->idt_vectoring_info = 0;
}
kvm_clear_interrupt_queue(&vmx->vcpu);
if (idtv_info_valid && type == INTR_TYPE_EXT_INTR) {
kvm_queue_interrupt(&vmx->vcpu, vector);
vmx->idt_vectoring_info = 0;
}
}
static void vmx_intr_assist(struct kvm_vcpu *vcpu)
{
update_tpr_threshold(vcpu);
vmx_update_window_states(vcpu);
if (vcpu->arch.nmi_pending && !vcpu->arch.nmi_injected) {
if (vcpu->arch.interrupt.pending) {
enable_nmi_window(vcpu);
} else if (vcpu->arch.nmi_window_open) {
vcpu->arch.nmi_pending = false;
vcpu->arch.nmi_injected = true;
} else {
enable_nmi_window(vcpu);
return;
}
}
if (vcpu->arch.nmi_injected) {
vmx_inject_nmi(vcpu);
if (vcpu->arch.nmi_pending)
enable_nmi_window(vcpu);
else if (kvm_cpu_has_interrupt(vcpu))
enable_irq_window(vcpu);
return;
}
if (!vcpu->arch.interrupt.pending && kvm_cpu_has_interrupt(vcpu)) {
if (vcpu->arch.interrupt_window_open)
kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu));
else
enable_irq_window(vcpu);
}
if (vcpu->arch.interrupt.pending) {
vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
if (kvm_cpu_has_interrupt(vcpu))
enable_irq_window(vcpu);
}
}
/*
* Failure to inject an interrupt should give us the information
* in IDT_VECTORING_INFO_FIELD. However, if the failure occurs
* when fetching the interrupt redirection bitmap in the real-mode
* tss, this doesn't happen. So we do it ourselves.
*/
static void fixup_rmode_irq(struct vcpu_vmx *vmx)
{
vmx->rmode.irq.pending = 0;
if (kvm_rip_read(&vmx->vcpu) + 1 != vmx->rmode.irq.rip)
return;
kvm_rip_write(&vmx->vcpu, vmx->rmode.irq.rip);
if (vmx->idt_vectoring_info & VECTORING_INFO_VALID_MASK) {
vmx->idt_vectoring_info &= ~VECTORING_INFO_TYPE_MASK;
vmx->idt_vectoring_info |= INTR_TYPE_EXT_INTR;
return;
}
vmx->idt_vectoring_info =
VECTORING_INFO_VALID_MASK
| INTR_TYPE_EXT_INTR
| vmx->rmode.irq.vector;
}
#ifdef CONFIG_X86_64
#define R "r"
#define Q "q"
#else
#define R "e"
#define Q "l"
#endif
static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
u32 intr_info;
/* Record the guest's net vcpu time for enforced NMI injections. */
if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked))
vmx->entry_time = ktime_get();
/* Handle invalid guest state instead of entering VMX */
if (vmx->emulation_required && emulate_invalid_guest_state) {
handle_invalid_guest_state(vcpu, kvm_run);
return;
}
if (test_bit(VCPU_REGS_RSP, (unsigned long *)&vcpu->arch.regs_dirty))
vmcs_writel(GUEST_RSP, vcpu->arch.regs[VCPU_REGS_RSP]);
if (test_bit(VCPU_REGS_RIP, (unsigned long *)&vcpu->arch.regs_dirty))
vmcs_writel(GUEST_RIP, vcpu->arch.regs[VCPU_REGS_RIP]);
/*
* Loading guest fpu may have cleared host cr0.ts
*/
vmcs_writel(HOST_CR0, read_cr0());
asm(
/* Store host registers */
"push %%"R"dx; push %%"R"bp;"
"push %%"R"cx \n\t"
"cmp %%"R"sp, %c[host_rsp](%0) \n\t"
"je 1f \n\t"
"mov %%"R"sp, %c[host_rsp](%0) \n\t"
__ex(ASM_VMX_VMWRITE_RSP_RDX) "\n\t"
"1: \n\t"
/* Check if vmlaunch of vmresume is needed */
"cmpl $0, %c[launched](%0) \n\t"
/* Load guest registers. Don't clobber flags. */
"mov %c[cr2](%0), %%"R"ax \n\t"
"mov %%"R"ax, %%cr2 \n\t"
"mov %c[rax](%0), %%"R"ax \n\t"
"mov %c[rbx](%0), %%"R"bx \n\t"
"mov %c[rdx](%0), %%"R"dx \n\t"
"mov %c[rsi](%0), %%"R"si \n\t"
"mov %c[rdi](%0), %%"R"di \n\t"
"mov %c[rbp](%0), %%"R"bp \n\t"
#ifdef CONFIG_X86_64
"mov %c[r8](%0), %%r8 \n\t"
"mov %c[r9](%0), %%r9 \n\t"
"mov %c[r10](%0), %%r10 \n\t"
"mov %c[r11](%0), %%r11 \n\t"
"mov %c[r12](%0), %%r12 \n\t"
"mov %c[r13](%0), %%r13 \n\t"
"mov %c[r14](%0), %%r14 \n\t"
"mov %c[r15](%0), %%r15 \n\t"
#endif
"mov %c[rcx](%0), %%"R"cx \n\t" /* kills %0 (ecx) */
/* Enter guest mode */
"jne .Llaunched \n\t"
__ex(ASM_VMX_VMLAUNCH) "\n\t"
"jmp .Lkvm_vmx_return \n\t"
".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
".Lkvm_vmx_return: "
/* Save guest registers, load host registers, keep flags */
"xchg %0, (%%"R"sp) \n\t"
"mov %%"R"ax, %c[rax](%0) \n\t"
"mov %%"R"bx, %c[rbx](%0) \n\t"
"push"Q" (%%"R"sp); pop"Q" %c[rcx](%0) \n\t"
"mov %%"R"dx, %c[rdx](%0) \n\t"
"mov %%"R"si, %c[rsi](%0) \n\t"
"mov %%"R"di, %c[rdi](%0) \n\t"
"mov %%"R"bp, %c[rbp](%0) \n\t"
#ifdef CONFIG_X86_64
"mov %%r8, %c[r8](%0) \n\t"
"mov %%r9, %c[r9](%0) \n\t"
"mov %%r10, %c[r10](%0) \n\t"
"mov %%r11, %c[r11](%0) \n\t"
"mov %%r12, %c[r12](%0) \n\t"
"mov %%r13, %c[r13](%0) \n\t"
"mov %%r14, %c[r14](%0) \n\t"
"mov %%r15, %c[r15](%0) \n\t"
#endif
"mov %%cr2, %%"R"ax \n\t"
"mov %%"R"ax, %c[cr2](%0) \n\t"
"pop %%"R"bp; pop %%"R"bp; pop %%"R"dx \n\t"
"setbe %c[fail](%0) \n\t"
: : "c"(vmx), "d"((unsigned long)HOST_RSP),
[launched]"i"(offsetof(struct vcpu_vmx, launched)),
[fail]"i"(offsetof(struct vcpu_vmx, fail)),
[host_rsp]"i"(offsetof(struct vcpu_vmx, host_rsp)),
[rax]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RAX])),
[rbx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RBX])),
[rcx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RCX])),
[rdx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RDX])),
[rsi]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RSI])),
[rdi]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RDI])),
[rbp]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RBP])),
#ifdef CONFIG_X86_64
[r8]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R8])),
[r9]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R9])),
[r10]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R10])),
[r11]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R11])),
[r12]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R12])),
[r13]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R13])),
[r14]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R14])),
[r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
#endif
[cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
: "cc", "memory"
, R"bx", R"di", R"si"
#ifdef CONFIG_X86_64
, "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
#endif
);
vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP));
vcpu->arch.regs_dirty = 0;
vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
if (vmx->rmode.irq.pending)
fixup_rmode_irq(vmx);
vmx_update_window_states(vcpu);
asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
vmx->launched = 1;
intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
/* We need to handle NMIs before interrupts are enabled */
if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR &&
(intr_info & INTR_INFO_VALID_MASK)) {
KVMTRACE_0D(NMI, vcpu, handler);
asm("int $2");
}
vmx_complete_interrupts(vmx);
}
#undef R
#undef Q
static void vmx_free_vmcs(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
if (vmx->vmcs) {
vcpu_clear(vmx);
free_vmcs(vmx->vmcs);
vmx->vmcs = NULL;
}
}
static void vmx_free_vcpu(struct kvm_vcpu *vcpu)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
spin_lock(&vmx_vpid_lock);
if (vmx->vpid != 0)
__clear_bit(vmx->vpid, vmx_vpid_bitmap);
spin_unlock(&vmx_vpid_lock);
vmx_free_vmcs(vcpu);
kfree(vmx->host_msrs);
kfree(vmx->guest_msrs);
kvm_vcpu_uninit(vcpu);
kmem_cache_free(kvm_vcpu_cache, vmx);
}
static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
{
int err;
struct vcpu_vmx *vmx = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
int cpu;
if (!vmx)
return ERR_PTR(-ENOMEM);
allocate_vpid(vmx);
err = kvm_vcpu_init(&vmx->vcpu, kvm, id);
if (err)
goto free_vcpu;
vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!vmx->guest_msrs) {
err = -ENOMEM;
goto uninit_vcpu;
}
vmx->host_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!vmx->host_msrs)
goto free_guest_msrs;
vmx->vmcs = alloc_vmcs();
if (!vmx->vmcs)
goto free_msrs;
vmcs_clear(vmx->vmcs);
cpu = get_cpu();
vmx_vcpu_load(&vmx->vcpu, cpu);
err = vmx_vcpu_setup(vmx);
vmx_vcpu_put(&vmx->vcpu);
put_cpu();
if (err)
goto free_vmcs;
if (vm_need_virtualize_apic_accesses(kvm))
if (alloc_apic_access_page(kvm) != 0)
goto free_vmcs;
if (vm_need_ept())
if (alloc_identity_pagetable(kvm) != 0)
goto free_vmcs;
return &vmx->vcpu;
free_vmcs:
free_vmcs(vmx->vmcs);
free_msrs:
kfree(vmx->host_msrs);
free_guest_msrs:
kfree(vmx->guest_msrs);
uninit_vcpu:
kvm_vcpu_uninit(&vmx->vcpu);
free_vcpu:
kmem_cache_free(kvm_vcpu_cache, vmx);
return ERR_PTR(err);
}
static void __init vmx_check_processor_compat(void *rtn)
{
struct vmcs_config vmcs_conf;
*(int *)rtn = 0;
if (setup_vmcs_config(&vmcs_conf) < 0)
*(int *)rtn = -EIO;
if (memcmp(&vmcs_config, &vmcs_conf, sizeof(struct vmcs_config)) != 0) {
printk(KERN_ERR "kvm: CPU %d feature inconsistency!\n",
smp_processor_id());
*(int *)rtn = -EIO;
}
}
static int get_ept_level(void)
{
return VMX_EPT_DEFAULT_GAW + 1;
}
static int vmx_get_mt_mask_shift(void)
{
return VMX_EPT_MT_EPTE_SHIFT;
}
static struct kvm_x86_ops vmx_x86_ops = {
.cpu_has_kvm_support = cpu_has_kvm_support,
.disabled_by_bios = vmx_disabled_by_bios,
.hardware_setup = hardware_setup,
.hardware_unsetup = hardware_unsetup,
.check_processor_compatibility = vmx_check_processor_compat,
.hardware_enable = hardware_enable,
.hardware_disable = hardware_disable,
.cpu_has_accelerated_tpr = cpu_has_vmx_virtualize_apic_accesses,
.vcpu_create = vmx_create_vcpu,
.vcpu_free = vmx_free_vcpu,
.vcpu_reset = vmx_vcpu_reset,
.prepare_guest_switch = vmx_save_host_state,
.vcpu_load = vmx_vcpu_load,
.vcpu_put = vmx_vcpu_put,
.set_guest_debug = set_guest_debug,
.guest_debug_pre = kvm_guest_debug_pre,
.get_msr = vmx_get_msr,
.set_msr = vmx_set_msr,
.get_segment_base = vmx_get_segment_base,
.get_segment = vmx_get_segment,
.set_segment = vmx_set_segment,
.get_cpl = vmx_get_cpl,
.get_cs_db_l_bits = vmx_get_cs_db_l_bits,
.decache_cr4_guest_bits = vmx_decache_cr4_guest_bits,
.set_cr0 = vmx_set_cr0,
.set_cr3 = vmx_set_cr3,
.set_cr4 = vmx_set_cr4,
.set_efer = vmx_set_efer,
.get_idt = vmx_get_idt,
.set_idt = vmx_set_idt,
.get_gdt = vmx_get_gdt,
.set_gdt = vmx_set_gdt,
.cache_reg = vmx_cache_reg,
.get_rflags = vmx_get_rflags,
.set_rflags = vmx_set_rflags,
.tlb_flush = vmx_flush_tlb,
.run = vmx_vcpu_run,
.handle_exit = kvm_handle_exit,
.skip_emulated_instruction = skip_emulated_instruction,
.patch_hypercall = vmx_patch_hypercall,
.get_irq = vmx_get_irq,
.set_irq = vmx_inject_irq,
.queue_exception = vmx_queue_exception,
.exception_injected = vmx_exception_injected,
.inject_pending_irq = vmx_intr_assist,
.inject_pending_vectors = do_interrupt_requests,
.set_tss_addr = vmx_set_tss_addr,
.get_tdp_level = get_ept_level,
.get_mt_mask_shift = vmx_get_mt_mask_shift,
};
static int __init vmx_init(void)
{
void *va;
int r;
vmx_io_bitmap_a = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
if (!vmx_io_bitmap_a)
return -ENOMEM;
vmx_io_bitmap_b = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
if (!vmx_io_bitmap_b) {
r = -ENOMEM;
goto out;
}
vmx_msr_bitmap = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
if (!vmx_msr_bitmap) {
r = -ENOMEM;
goto out1;
}
/*
* Allow direct access to the PC debug port (it is often used for I/O
* delays, but the vmexits simply slow things down).
*/
va = kmap(vmx_io_bitmap_a);
memset(va, 0xff, PAGE_SIZE);
clear_bit(0x80, va);
kunmap(vmx_io_bitmap_a);
va = kmap(vmx_io_bitmap_b);
memset(va, 0xff, PAGE_SIZE);
kunmap(vmx_io_bitmap_b);
va = kmap(vmx_msr_bitmap);
memset(va, 0xff, PAGE_SIZE);
kunmap(vmx_msr_bitmap);
set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */
r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), THIS_MODULE);
if (r)
goto out2;
vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_FS_BASE);
vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_GS_BASE);
vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_CS);
vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_ESP);
vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_EIP);
if (vm_need_ept()) {
bypass_guest_pf = 0;
kvm_mmu_set_base_ptes(VMX_EPT_READABLE_MASK |
VMX_EPT_WRITABLE_MASK);
kvm_mmu_set_mask_ptes(0ull, 0ull, 0ull, 0ull,
VMX_EPT_EXECUTABLE_MASK,
VMX_EPT_DEFAULT_MT << VMX_EPT_MT_EPTE_SHIFT);
kvm_enable_tdp();
} else
kvm_disable_tdp();
if (bypass_guest_pf)
kvm_mmu_set_nonpresent_ptes(~0xffeull, 0ull);
ept_sync_global();
return 0;
out2:
__free_page(vmx_msr_bitmap);
out1:
__free_page(vmx_io_bitmap_b);
out:
__free_page(vmx_io_bitmap_a);
return r;
}
static void __exit vmx_exit(void)
{
__free_page(vmx_msr_bitmap);
__free_page(vmx_io_bitmap_b);
__free_page(vmx_io_bitmap_a);
kvm_exit();
}
module_init(vmx_init)
module_exit(vmx_exit)
| felixhaedicke/nst-kernel | src/arch/x86/kvm/vmx.c | C | gpl-2.0 | 96,797 |
// +build !windows
package daemon
import (
"github.com/docker/docker/container"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/idtools"
)
func (daemon *Daemon) tarCopyOptions(container *container.Container, noOverwriteDirNonDir bool) (*archive.TarOptions, error) {
if container.Config.User == "" {
return daemon.defaultTarCopyOptions(noOverwriteDirNonDir), nil
}
user, err := idtools.LookupUser(container.Config.User)
if err != nil {
return nil, err
}
return &archive.TarOptions{
NoOverwriteDirNonDir: noOverwriteDirNonDir,
ChownOpts: &idtools.IDPair{UID: user.Uid, GID: user.Gid},
}, nil
}
| crobby/oshinko-cli | vendor/github.com/openshift/origin/cmd/cluster-capacity/go/src/github.com/kubernetes-incubator/cluster-capacity/vendor/github.com/docker/docker/daemon/archive_tarcopyoptions_unix.go | GO | apache-2.0 | 647 |
<?php
/**
* Memcache storage engine for cache
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Cache.Engine
* @since CakePHP(tm) v 1.2.0.4933
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Memcache storage engine for cache. Memcache has some limitations in the amount of
* control you have over expire times far in the future. See MemcacheEngine::write() for
* more information.
*
* @package Cake.Cache.Engine
* @deprecated 3.0.0 You should use the Memcached adapter instead.
*/
class MemcacheEngine extends CacheEngine {
/**
* Contains the compiled group names
* (prefixed with the global configuration prefix)
*
* @var array
*/
protected $_compiledGroupNames = array();
/**
* Memcache wrapper.
*
* @var Memcache
*/
protected $_Memcache = null;
/**
* Settings
*
* - servers = string or array of memcache servers, default => 127.0.0.1. If an
* array MemcacheEngine will use them as a pool.
* - compress = boolean, default => false
*
* @var array
*/
public $settings = array();
/**
* Initialize the Cache Engine
*
* Called automatically by the cache frontend
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
* @return bool True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
if (!class_exists('Memcache')) {
return false;
}
if (!isset($settings['prefix'])) {
$settings['prefix'] = Inflector::slug(APP_DIR) . '_';
}
$settings += array(
'engine' => 'Memcache',
'servers' => array('127.0.0.1'),
'compress' => false,
'persistent' => true
);
parent::init($settings);
if ($this->settings['compress']) {
$this->settings['compress'] = MEMCACHE_COMPRESSED;
}
if (is_string($this->settings['servers'])) {
$this->settings['servers'] = array($this->settings['servers']);
}
if (!isset($this->_Memcache)) {
$return = false;
$this->_Memcache = new Memcache();
foreach ($this->settings['servers'] as $server) {
list($host, $port) = $this->_parseServerString($server);
if ($this->_Memcache->addServer($host, $port, $this->settings['persistent'])) {
$return = true;
}
}
return $return;
}
return true;
}
/**
* Parses the server address into the host/port. Handles both IPv6 and IPv4
* addresses and Unix sockets
*
* @param string $server The server address string.
* @return array Array containing host, port
*/
protected function _parseServerString($server) {
if ($server[0] === 'u') {
return array($server, 0);
}
if (substr($server, 0, 1) === '[') {
$position = strpos($server, ']:');
if ($position !== false) {
$position++;
}
} else {
$position = strpos($server, ':');
}
$port = 11211;
$host = $server;
if ($position !== false) {
$host = substr($server, 0, $position);
$port = substr($server, $position + 1);
}
return array($host, $port);
}
/**
* Write data for key into cache. When using memcache as your cache engine
* remember that the Memcache pecl extension does not support cache expiry times greater
* than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
* @param int $duration How long to cache the data, in seconds
* @return bool True if the data was successfully cached, false on failure
* @see http://php.net/manual/en/memcache.set.php
*/
public function write($key, $value, $duration) {
if ($duration > 30 * DAY) {
$duration = 0;
}
return $this->_Memcache->set($key, $value, $this->settings['compress'], $duration);
}
/**
* Read a key from the cache
*
* @param string $key Identifier for the data
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
*/
public function read($key) {
return $this->_Memcache->get($key);
}
/**
* Increments the value of an integer cached key
*
* @param string $key Identifier for the data
* @param int $offset How much to increment
* @return New incremented value, false otherwise
* @throws CacheException when you try to increment with compress = true
*/
public function increment($key, $offset = 1) {
if ($this->settings['compress']) {
throw new CacheException(
__d('cake_dev', 'Method %s not implemented for compressed cache in %s', 'increment()', __CLASS__)
);
}
return $this->_Memcache->increment($key, $offset);
}
/**
* Decrements the value of an integer cached key
*
* @param string $key Identifier for the data
* @param int $offset How much to subtract
* @return New decremented value, false otherwise
* @throws CacheException when you try to decrement with compress = true
*/
public function decrement($key, $offset = 1) {
if ($this->settings['compress']) {
throw new CacheException(
__d('cake_dev', 'Method %s not implemented for compressed cache in %s', 'decrement()', __CLASS__)
);
}
return $this->_Memcache->decrement($key, $offset);
}
/**
* Delete a key from the cache
*
* @param string $key Identifier for the data
* @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return $this->_Memcache->delete($key);
}
/**
* Delete all keys from the cache
*
* @param bool $check If true no deletes will occur and instead CakePHP will rely
* on key TTL values.
* @return bool True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
if ($check) {
return true;
}
foreach ($this->_Memcache->getExtendedStats('slabs', 0) as $slabs) {
foreach (array_keys($slabs) as $slabId) {
if (!is_numeric($slabId)) {
continue;
}
foreach ($this->_Memcache->getExtendedStats('cachedump', $slabId, 0) as $stats) {
if (!is_array($stats)) {
continue;
}
foreach (array_keys($stats) as $key) {
if (strpos($key, $this->settings['prefix']) === 0) {
$this->_Memcache->delete($key);
}
}
}
}
}
return true;
}
/**
* Connects to a server in connection pool
*
* @param string $host host ip address or name
* @param int $port Server port
* @return bool True if memcache server was connected
*/
public function connect($host, $port = 11211) {
if ($this->_Memcache->getServerStatus($host, $port) === 0) {
if ($this->_Memcache->connect($host, $port)) {
return true;
}
return false;
}
return true;
}
/**
* Returns the `group value` for each of the configured groups
* If the group initial value was not found, then it initializes
* the group accordingly.
*
* @return array
*/
public function groups() {
if (empty($this->_compiledGroupNames)) {
foreach ($this->settings['groups'] as $group) {
$this->_compiledGroupNames[] = $this->settings['prefix'] . $group;
}
}
$groups = $this->_Memcache->get($this->_compiledGroupNames);
if (count($groups) !== count($this->settings['groups'])) {
foreach ($this->_compiledGroupNames as $group) {
if (!isset($groups[$group])) {
$this->_Memcache->set($group, 1, false, 0);
$groups[$group] = 1;
}
}
ksort($groups);
}
$result = array();
$groups = array_values($groups);
foreach ($this->settings['groups'] as $i => $group) {
$result[] = $group . $groups[$i];
}
return $result;
}
/**
* Increments the group value to simulate deletion of all keys under a group
* old values will remain in storage until they expire.
*
* @param string $group The group to clear.
* @return bool success
*/
public function clearGroup($group) {
return (bool)$this->_Memcache->increment($this->settings['prefix'] . $group);
}
}
| kcraam/rasp-fligthtime | webapp/lib/Cake/Cache/Engine/MemcacheEngine.php | PHP | bsd-3-clause | 8,310 |
class Nasm < Formula
desc "Netwide Assembler (NASM) is an 80x86 assembler"
homepage "http://www.nasm.us/"
revision 1
stable do
url "http://www.nasm.us/pub/nasm/releasebuilds/2.11.08/nasm-2.11.08.tar.xz"
sha256 "c99467c7072211c550d147640d8a1a0aa4d636d4d8cf849f3bf4317d900a1f7f"
# http://repo.or.cz/nasm.git/commit/4920a0324348716d6ab5106e65508496241dc7a2
# http://bugzilla.nasm.us/show_bug.cgi?id=3392306#c5
patch do
url "https://raw.githubusercontent.com/Homebrew/patches/7a329c65e/nasm/nasm_outmac64.patch"
sha256 "54bfb2a8e0941e0108efedb4a3bcdc6ce8dff0d31d3abdf2256410c0f93f5ad7"
end
end
bottle do
cellar :any_skip_relocation
sha256 "4023e31702e37163be8c0089550b50ccb06c5de78788271f3b72c17f235d0449" => :el_capitan
sha256 "3a3f2ead668f671710c08988ecd28d4ee778202b20fff12a4f7ffc397eda080d" => :yosemite
sha256 "ccbea16ab6ea7f786112531697b04b0abd2709ca72f4378b7f54db83f0d7364e" => :mavericks
end
devel do
url "http://www.nasm.us/pub/nasm/releasebuilds/2.11.09rc1/nasm-2.11.09rc1.tar.xz"
sha256 "8b76b7f40701a5bdc8ef29fc352edb0714a8e921b2383072283057d2b426a890"
end
option :universal
def install
ENV.universal_binary if build.universal?
system "./configure", "--prefix=#{prefix}"
system "make", "install", "install_rdf"
end
test do
(testpath/"foo.s").write <<-EOS
mov eax, 0
mov ebx, 0
int 0x80
EOS
system "#{bin}/nasm", "foo.s"
code = File.open("foo", "rb") { |f| f.read.unpack("C*") }
expected = [0x66, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x66, 0xbb,
0x00, 0x00, 0x00, 0x00, 0xcd, 0x80]
assert_equal expected, code
end
end
| rokn/Count_Words_2015 | fetched_code/ruby/nasm.rb | Ruby | mit | 1,684 |
/* mbed Microcontroller Library
* Copyright (c) 2006-2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_DEVICE_H
#define MBED_DEVICE_H
#define DEVICE_PORTIN 1
#define DEVICE_PORTOUT 1
#define DEVICE_PORTINOUT 1
#define DEVICE_INTERRUPTIN 1
#define DEVICE_ANALOGIN 1
#define DEVICE_ANALOGOUT 0
#define DEVICE_SERIAL 1
#define DEVICE_I2C 1
#define DEVICE_I2CSLAVE 1
#define DEVICE_SPI 1
#define DEVICE_SPISLAVE 1
#define DEVICE_CAN 0
#define DEVICE_RTC 0
#define DEVICE_ETHERNET 0
#define DEVICE_PWMOUT 1
#define DEVICE_SEMIHOST 0
#define DEVICE_LOCALFILESYSTEM 0
#define DEVICE_ID_LENGTH 32
#define DEVICE_MAC_OFFSET 20
#define DEVICE_SLEEP 1
#define DEVICE_DEBUG_AWARENESS 0
#define DEVICE_STDIO_MESSAGES 0
#define DEVICE_ERROR_PATTERN 1
#include "objects.h"
#endif
| ruriwo/ErgoThumb072_firmware | tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/TARGET_LPC11U34_421/device.h | C | gpl-2.0 | 1,504 |
/*
* Copyright (c) 2007-2011 Nicira Networks.
*
* 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.
*
* 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 "flow.h"
#include "datapath.h"
#include <linux/uaccess.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/if_ether.h>
#include <linux/if_vlan.h>
#include <net/llc_pdu.h>
#include <linux/kernel.h>
#include <linux/jhash.h>
#include <linux/jiffies.h>
#include <linux/llc.h>
#include <linux/module.h>
#include <linux/in.h>
#include <linux/rcupdate.h>
#include <linux/if_arp.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/icmp.h>
#include <linux/icmpv6.h>
#include <linux/rculist.h>
#include <net/ip.h>
#include <net/ipv6.h>
#include <net/ndisc.h>
static struct kmem_cache *flow_cache;
static int check_header(struct sk_buff *skb, int len)
{
if (unlikely(skb->len < len))
return -EINVAL;
if (unlikely(!pskb_may_pull(skb, len)))
return -ENOMEM;
return 0;
}
static bool arphdr_ok(struct sk_buff *skb)
{
return pskb_may_pull(skb, skb_network_offset(skb) +
sizeof(struct arp_eth_header));
}
static int check_iphdr(struct sk_buff *skb)
{
unsigned int nh_ofs = skb_network_offset(skb);
unsigned int ip_len;
int err;
err = check_header(skb, nh_ofs + sizeof(struct iphdr));
if (unlikely(err))
return err;
ip_len = ip_hdrlen(skb);
if (unlikely(ip_len < sizeof(struct iphdr) ||
skb->len < nh_ofs + ip_len))
return -EINVAL;
skb_set_transport_header(skb, nh_ofs + ip_len);
return 0;
}
static bool tcphdr_ok(struct sk_buff *skb)
{
int th_ofs = skb_transport_offset(skb);
int tcp_len;
if (unlikely(!pskb_may_pull(skb, th_ofs + sizeof(struct tcphdr))))
return false;
tcp_len = tcp_hdrlen(skb);
if (unlikely(tcp_len < sizeof(struct tcphdr) ||
skb->len < th_ofs + tcp_len))
return false;
return true;
}
static bool udphdr_ok(struct sk_buff *skb)
{
return pskb_may_pull(skb, skb_transport_offset(skb) +
sizeof(struct udphdr));
}
static bool icmphdr_ok(struct sk_buff *skb)
{
return pskb_may_pull(skb, skb_transport_offset(skb) +
sizeof(struct icmphdr));
}
u64 ovs_flow_used_time(unsigned long flow_jiffies)
{
struct timespec cur_ts;
u64 cur_ms, idle_ms;
ktime_get_ts(&cur_ts);
idle_ms = jiffies_to_msecs(jiffies - flow_jiffies);
cur_ms = (u64)cur_ts.tv_sec * MSEC_PER_SEC +
cur_ts.tv_nsec / NSEC_PER_MSEC;
return cur_ms - idle_ms;
}
#define SW_FLOW_KEY_OFFSET(field) \
(offsetof(struct sw_flow_key, field) + \
FIELD_SIZEOF(struct sw_flow_key, field))
static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key,
int *key_lenp)
{
unsigned int nh_ofs = skb_network_offset(skb);
unsigned int nh_len;
int payload_ofs;
struct ipv6hdr *nh;
uint8_t nexthdr;
__be16 frag_off;
int err;
*key_lenp = SW_FLOW_KEY_OFFSET(ipv6.label);
err = check_header(skb, nh_ofs + sizeof(*nh));
if (unlikely(err))
return err;
nh = ipv6_hdr(skb);
nexthdr = nh->nexthdr;
payload_ofs = (u8 *)(nh + 1) - skb->data;
key->ip.proto = NEXTHDR_NONE;
key->ip.tos = ipv6_get_dsfield(nh);
key->ip.ttl = nh->hop_limit;
key->ipv6.label = *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL);
key->ipv6.addr.src = nh->saddr;
key->ipv6.addr.dst = nh->daddr;
payload_ofs = ipv6_skip_exthdr(skb, payload_ofs, &nexthdr, &frag_off);
if (unlikely(payload_ofs < 0))
return -EINVAL;
if (frag_off) {
if (frag_off & htons(~0x7))
key->ip.frag = OVS_FRAG_TYPE_LATER;
else
key->ip.frag = OVS_FRAG_TYPE_FIRST;
}
nh_len = payload_ofs - nh_ofs;
skb_set_transport_header(skb, nh_ofs + nh_len);
key->ip.proto = nexthdr;
return nh_len;
}
static bool icmp6hdr_ok(struct sk_buff *skb)
{
return pskb_may_pull(skb, skb_transport_offset(skb) +
sizeof(struct icmp6hdr));
}
#define TCP_FLAGS_OFFSET 13
#define TCP_FLAG_MASK 0x3f
void ovs_flow_used(struct sw_flow *flow, struct sk_buff *skb)
{
u8 tcp_flags = 0;
if (flow->key.eth.type == htons(ETH_P_IP) &&
flow->key.ip.proto == IPPROTO_TCP) {
u8 *tcp = (u8 *)tcp_hdr(skb);
tcp_flags = *(tcp + TCP_FLAGS_OFFSET) & TCP_FLAG_MASK;
}
spin_lock(&flow->lock);
flow->used = jiffies;
flow->packet_count++;
flow->byte_count += skb->len;
flow->tcp_flags |= tcp_flags;
spin_unlock(&flow->lock);
}
struct sw_flow_actions *ovs_flow_actions_alloc(const struct nlattr *actions)
{
int actions_len = nla_len(actions);
struct sw_flow_actions *sfa;
/* At least DP_MAX_PORTS actions are required to be able to flood a
* packet to every port. Factor of 2 allows for setting VLAN tags,
* etc. */
if (actions_len > 2 * DP_MAX_PORTS * nla_total_size(4))
return ERR_PTR(-EINVAL);
sfa = kmalloc(sizeof(*sfa) + actions_len, GFP_KERNEL);
if (!sfa)
return ERR_PTR(-ENOMEM);
sfa->actions_len = actions_len;
memcpy(sfa->actions, nla_data(actions), actions_len);
return sfa;
}
struct sw_flow *ovs_flow_alloc(void)
{
struct sw_flow *flow;
flow = kmem_cache_alloc(flow_cache, GFP_KERNEL);
if (!flow)
return ERR_PTR(-ENOMEM);
spin_lock_init(&flow->lock);
flow->sf_acts = NULL;
return flow;
}
static struct hlist_head *find_bucket(struct flow_table *table, u32 hash)
{
hash = jhash_1word(hash, table->hash_seed);
return flex_array_get(table->buckets,
(hash & (table->n_buckets - 1)));
}
static struct flex_array *alloc_buckets(unsigned int n_buckets)
{
struct flex_array *buckets;
int i, err;
buckets = flex_array_alloc(sizeof(struct hlist_head *),
n_buckets, GFP_KERNEL);
if (!buckets)
return NULL;
err = flex_array_prealloc(buckets, 0, n_buckets, GFP_KERNEL);
if (err) {
flex_array_free(buckets);
return NULL;
}
for (i = 0; i < n_buckets; i++)
INIT_HLIST_HEAD((struct hlist_head *)
flex_array_get(buckets, i));
return buckets;
}
static void free_buckets(struct flex_array *buckets)
{
flex_array_free(buckets);
}
struct flow_table *ovs_flow_tbl_alloc(int new_size)
{
struct flow_table *table = kmalloc(sizeof(*table), GFP_KERNEL);
if (!table)
return NULL;
table->buckets = alloc_buckets(new_size);
if (!table->buckets) {
kfree(table);
return NULL;
}
table->n_buckets = new_size;
table->count = 0;
table->node_ver = 0;
table->keep_flows = false;
get_random_bytes(&table->hash_seed, sizeof(u32));
return table;
}
void ovs_flow_tbl_destroy(struct flow_table *table)
{
int i;
if (!table)
return;
if (table->keep_flows)
goto skip_flows;
for (i = 0; i < table->n_buckets; i++) {
struct sw_flow *flow;
struct hlist_head *head = flex_array_get(table->buckets, i);
struct hlist_node *node, *n;
int ver = table->node_ver;
hlist_for_each_entry_safe(flow, node, n, head, hash_node[ver]) {
hlist_del_rcu(&flow->hash_node[ver]);
ovs_flow_free(flow);
}
}
skip_flows:
free_buckets(table->buckets);
kfree(table);
}
static void flow_tbl_destroy_rcu_cb(struct rcu_head *rcu)
{
struct flow_table *table = container_of(rcu, struct flow_table, rcu);
ovs_flow_tbl_destroy(table);
}
void ovs_flow_tbl_deferred_destroy(struct flow_table *table)
{
if (!table)
return;
call_rcu(&table->rcu, flow_tbl_destroy_rcu_cb);
}
struct sw_flow *ovs_flow_tbl_next(struct flow_table *table, u32 *bucket, u32 *last)
{
struct sw_flow *flow;
struct hlist_head *head;
struct hlist_node *n;
int ver;
int i;
ver = table->node_ver;
while (*bucket < table->n_buckets) {
i = 0;
head = flex_array_get(table->buckets, *bucket);
hlist_for_each_entry_rcu(flow, n, head, hash_node[ver]) {
if (i < *last) {
i++;
continue;
}
*last = i + 1;
return flow;
}
(*bucket)++;
*last = 0;
}
return NULL;
}
static void flow_table_copy_flows(struct flow_table *old, struct flow_table *new)
{
int old_ver;
int i;
old_ver = old->node_ver;
new->node_ver = !old_ver;
/* Insert in new table. */
for (i = 0; i < old->n_buckets; i++) {
struct sw_flow *flow;
struct hlist_head *head;
struct hlist_node *n;
head = flex_array_get(old->buckets, i);
hlist_for_each_entry(flow, n, head, hash_node[old_ver])
ovs_flow_tbl_insert(new, flow);
}
old->keep_flows = true;
}
static struct flow_table *__flow_tbl_rehash(struct flow_table *table, int n_buckets)
{
struct flow_table *new_table;
new_table = ovs_flow_tbl_alloc(n_buckets);
if (!new_table)
return ERR_PTR(-ENOMEM);
flow_table_copy_flows(table, new_table);
return new_table;
}
struct flow_table *ovs_flow_tbl_rehash(struct flow_table *table)
{
return __flow_tbl_rehash(table, table->n_buckets);
}
struct flow_table *ovs_flow_tbl_expand(struct flow_table *table)
{
return __flow_tbl_rehash(table, table->n_buckets * 2);
}
void ovs_flow_free(struct sw_flow *flow)
{
if (unlikely(!flow))
return;
kfree((struct sf_flow_acts __force *)flow->sf_acts);
kmem_cache_free(flow_cache, flow);
}
/* RCU callback used by ovs_flow_deferred_free. */
static void rcu_free_flow_callback(struct rcu_head *rcu)
{
struct sw_flow *flow = container_of(rcu, struct sw_flow, rcu);
ovs_flow_free(flow);
}
/* Schedules 'flow' to be freed after the next RCU grace period.
* The caller must hold rcu_read_lock for this to be sensible. */
void ovs_flow_deferred_free(struct sw_flow *flow)
{
call_rcu(&flow->rcu, rcu_free_flow_callback);
}
/* RCU callback used by ovs_flow_deferred_free_acts. */
static void rcu_free_acts_callback(struct rcu_head *rcu)
{
struct sw_flow_actions *sf_acts = container_of(rcu,
struct sw_flow_actions, rcu);
kfree(sf_acts);
}
/* Schedules 'sf_acts' to be freed after the next RCU grace period.
* The caller must hold rcu_read_lock for this to be sensible. */
void ovs_flow_deferred_free_acts(struct sw_flow_actions *sf_acts)
{
call_rcu(&sf_acts->rcu, rcu_free_acts_callback);
}
static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
{
struct qtag_prefix {
__be16 eth_type; /* ETH_P_8021Q */
__be16 tci;
};
struct qtag_prefix *qp;
if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
return 0;
if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
sizeof(__be16))))
return -ENOMEM;
qp = (struct qtag_prefix *) skb->data;
key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
__skb_pull(skb, sizeof(struct qtag_prefix));
return 0;
}
static __be16 parse_ethertype(struct sk_buff *skb)
{
struct llc_snap_hdr {
u8 dsap; /* Always 0xAA */
u8 ssap; /* Always 0xAA */
u8 ctrl;
u8 oui[3];
__be16 ethertype;
};
struct llc_snap_hdr *llc;
__be16 proto;
proto = *(__be16 *) skb->data;
__skb_pull(skb, sizeof(__be16));
if (ntohs(proto) >= 1536)
return proto;
if (skb->len < sizeof(struct llc_snap_hdr))
return htons(ETH_P_802_2);
if (unlikely(!pskb_may_pull(skb, sizeof(struct llc_snap_hdr))))
return htons(0);
llc = (struct llc_snap_hdr *) skb->data;
if (llc->dsap != LLC_SAP_SNAP ||
llc->ssap != LLC_SAP_SNAP ||
(llc->oui[0] | llc->oui[1] | llc->oui[2]) != 0)
return htons(ETH_P_802_2);
__skb_pull(skb, sizeof(struct llc_snap_hdr));
return llc->ethertype;
}
static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key,
int *key_lenp, int nh_len)
{
struct icmp6hdr *icmp = icmp6_hdr(skb);
int error = 0;
int key_len;
/* The ICMPv6 type and code fields use the 16-bit transport port
* fields, so we need to store them in 16-bit network byte order.
*/
key->ipv6.tp.src = htons(icmp->icmp6_type);
key->ipv6.tp.dst = htons(icmp->icmp6_code);
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
if (icmp->icmp6_code == 0 &&
(icmp->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION ||
icmp->icmp6_type == NDISC_NEIGHBOUR_ADVERTISEMENT)) {
int icmp_len = skb->len - skb_transport_offset(skb);
struct nd_msg *nd;
int offset;
key_len = SW_FLOW_KEY_OFFSET(ipv6.nd);
/* In order to process neighbor discovery options, we need the
* entire packet.
*/
if (unlikely(icmp_len < sizeof(*nd)))
goto out;
if (unlikely(skb_linearize(skb))) {
error = -ENOMEM;
goto out;
}
nd = (struct nd_msg *)skb_transport_header(skb);
key->ipv6.nd.target = nd->target;
key_len = SW_FLOW_KEY_OFFSET(ipv6.nd);
icmp_len -= sizeof(*nd);
offset = 0;
while (icmp_len >= 8) {
struct nd_opt_hdr *nd_opt =
(struct nd_opt_hdr *)(nd->opt + offset);
int opt_len = nd_opt->nd_opt_len * 8;
if (unlikely(!opt_len || opt_len > icmp_len))
goto invalid;
/* Store the link layer address if the appropriate
* option is provided. It is considered an error if
* the same link layer option is specified twice.
*/
if (nd_opt->nd_opt_type == ND_OPT_SOURCE_LL_ADDR
&& opt_len == 8) {
if (unlikely(!is_zero_ether_addr(key->ipv6.nd.sll)))
goto invalid;
memcpy(key->ipv6.nd.sll,
&nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
} else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LL_ADDR
&& opt_len == 8) {
if (unlikely(!is_zero_ether_addr(key->ipv6.nd.tll)))
goto invalid;
memcpy(key->ipv6.nd.tll,
&nd->opt[offset+sizeof(*nd_opt)], ETH_ALEN);
}
icmp_len -= opt_len;
offset += opt_len;
}
}
goto out;
invalid:
memset(&key->ipv6.nd.target, 0, sizeof(key->ipv6.nd.target));
memset(key->ipv6.nd.sll, 0, sizeof(key->ipv6.nd.sll));
memset(key->ipv6.nd.tll, 0, sizeof(key->ipv6.nd.tll));
out:
*key_lenp = key_len;
return error;
}
/**
* ovs_flow_extract - extracts a flow key from an Ethernet frame.
* @skb: sk_buff that contains the frame, with skb->data pointing to the
* Ethernet header
* @in_port: port number on which @skb was received.
* @key: output flow key
* @key_lenp: length of output flow key
*
* The caller must ensure that skb->len >= ETH_HLEN.
*
* Returns 0 if successful, otherwise a negative errno value.
*
* Initializes @skb header pointers as follows:
*
* - skb->mac_header: the Ethernet header.
*
* - skb->network_header: just past the Ethernet header, or just past the
* VLAN header, to the first byte of the Ethernet payload.
*
* - skb->transport_header: If key->dl_type is ETH_P_IP or ETH_P_IPV6
* on output, then just past the IP header, if one is present and
* of a correct length, otherwise the same as skb->network_header.
* For other key->dl_type values it is left untouched.
*/
int ovs_flow_extract(struct sk_buff *skb, u16 in_port, struct sw_flow_key *key,
int *key_lenp)
{
int error = 0;
int key_len = SW_FLOW_KEY_OFFSET(eth);
struct ethhdr *eth;
memset(key, 0, sizeof(*key));
key->phy.priority = skb->priority;
key->phy.in_port = in_port;
skb_reset_mac_header(skb);
/* Link layer. We are guaranteed to have at least the 14 byte Ethernet
* header in the linear data area.
*/
eth = eth_hdr(skb);
memcpy(key->eth.src, eth->h_source, ETH_ALEN);
memcpy(key->eth.dst, eth->h_dest, ETH_ALEN);
__skb_pull(skb, 2 * ETH_ALEN);
if (vlan_tx_tag_present(skb))
key->eth.tci = htons(skb->vlan_tci);
else if (eth->h_proto == htons(ETH_P_8021Q))
if (unlikely(parse_vlan(skb, key)))
return -ENOMEM;
key->eth.type = parse_ethertype(skb);
if (unlikely(key->eth.type == htons(0)))
return -ENOMEM;
skb_reset_network_header(skb);
__skb_push(skb, skb->data - skb_mac_header(skb));
/* Network layer. */
if (key->eth.type == htons(ETH_P_IP)) {
struct iphdr *nh;
__be16 offset;
key_len = SW_FLOW_KEY_OFFSET(ipv4.addr);
error = check_iphdr(skb);
if (unlikely(error)) {
if (error == -EINVAL) {
skb->transport_header = skb->network_header;
error = 0;
}
goto out;
}
nh = ip_hdr(skb);
key->ipv4.addr.src = nh->saddr;
key->ipv4.addr.dst = nh->daddr;
key->ip.proto = nh->protocol;
key->ip.tos = nh->tos;
key->ip.ttl = nh->ttl;
offset = nh->frag_off & htons(IP_OFFSET);
if (offset) {
key->ip.frag = OVS_FRAG_TYPE_LATER;
goto out;
}
if (nh->frag_off & htons(IP_MF) ||
skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
key->ip.frag = OVS_FRAG_TYPE_FIRST;
/* Transport layer. */
if (key->ip.proto == IPPROTO_TCP) {
key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
if (tcphdr_ok(skb)) {
struct tcphdr *tcp = tcp_hdr(skb);
key->ipv4.tp.src = tcp->source;
key->ipv4.tp.dst = tcp->dest;
}
} else if (key->ip.proto == IPPROTO_UDP) {
key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
if (udphdr_ok(skb)) {
struct udphdr *udp = udp_hdr(skb);
key->ipv4.tp.src = udp->source;
key->ipv4.tp.dst = udp->dest;
}
} else if (key->ip.proto == IPPROTO_ICMP) {
key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
if (icmphdr_ok(skb)) {
struct icmphdr *icmp = icmp_hdr(skb);
/* The ICMP type and code fields use the 16-bit
* transport port fields, so we need to store
* them in 16-bit network byte order. */
key->ipv4.tp.src = htons(icmp->type);
key->ipv4.tp.dst = htons(icmp->code);
}
}
} else if (key->eth.type == htons(ETH_P_ARP) && arphdr_ok(skb)) {
struct arp_eth_header *arp;
arp = (struct arp_eth_header *)skb_network_header(skb);
if (arp->ar_hrd == htons(ARPHRD_ETHER)
&& arp->ar_pro == htons(ETH_P_IP)
&& arp->ar_hln == ETH_ALEN
&& arp->ar_pln == 4) {
/* We only match on the lower 8 bits of the opcode. */
if (ntohs(arp->ar_op) <= 0xff)
key->ip.proto = ntohs(arp->ar_op);
if (key->ip.proto == ARPOP_REQUEST
|| key->ip.proto == ARPOP_REPLY) {
memcpy(&key->ipv4.addr.src, arp->ar_sip, sizeof(key->ipv4.addr.src));
memcpy(&key->ipv4.addr.dst, arp->ar_tip, sizeof(key->ipv4.addr.dst));
memcpy(key->ipv4.arp.sha, arp->ar_sha, ETH_ALEN);
memcpy(key->ipv4.arp.tha, arp->ar_tha, ETH_ALEN);
key_len = SW_FLOW_KEY_OFFSET(ipv4.arp);
}
}
} else if (key->eth.type == htons(ETH_P_IPV6)) {
int nh_len; /* IPv6 Header + Extensions */
nh_len = parse_ipv6hdr(skb, key, &key_len);
if (unlikely(nh_len < 0)) {
if (nh_len == -EINVAL)
skb->transport_header = skb->network_header;
else
error = nh_len;
goto out;
}
if (key->ip.frag == OVS_FRAG_TYPE_LATER)
goto out;
if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
key->ip.frag = OVS_FRAG_TYPE_FIRST;
/* Transport layer. */
if (key->ip.proto == NEXTHDR_TCP) {
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
if (tcphdr_ok(skb)) {
struct tcphdr *tcp = tcp_hdr(skb);
key->ipv6.tp.src = tcp->source;
key->ipv6.tp.dst = tcp->dest;
}
} else if (key->ip.proto == NEXTHDR_UDP) {
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
if (udphdr_ok(skb)) {
struct udphdr *udp = udp_hdr(skb);
key->ipv6.tp.src = udp->source;
key->ipv6.tp.dst = udp->dest;
}
} else if (key->ip.proto == NEXTHDR_ICMP) {
key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
if (icmp6hdr_ok(skb)) {
error = parse_icmpv6(skb, key, &key_len, nh_len);
if (error < 0)
goto out;
}
}
}
out:
*key_lenp = key_len;
return error;
}
u32 ovs_flow_hash(const struct sw_flow_key *key, int key_len)
{
return jhash2((u32 *)key, DIV_ROUND_UP(key_len, sizeof(u32)), 0);
}
struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *table,
struct sw_flow_key *key, int key_len)
{
struct sw_flow *flow;
struct hlist_node *n;
struct hlist_head *head;
u32 hash;
hash = ovs_flow_hash(key, key_len);
head = find_bucket(table, hash);
hlist_for_each_entry_rcu(flow, n, head, hash_node[table->node_ver]) {
if (flow->hash == hash &&
!memcmp(&flow->key, key, key_len)) {
return flow;
}
}
return NULL;
}
void ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow)
{
struct hlist_head *head;
head = find_bucket(table, flow->hash);
hlist_add_head_rcu(&flow->hash_node[table->node_ver], head);
table->count++;
}
void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow)
{
hlist_del_rcu(&flow->hash_node[table->node_ver]);
table->count--;
BUG_ON(table->count < 0);
}
/* The size of the argument for each %OVS_KEY_ATTR_* Netlink attribute. */
const int ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
[OVS_KEY_ATTR_ENCAP] = -1,
[OVS_KEY_ATTR_PRIORITY] = sizeof(u32),
[OVS_KEY_ATTR_IN_PORT] = sizeof(u32),
[OVS_KEY_ATTR_ETHERNET] = sizeof(struct ovs_key_ethernet),
[OVS_KEY_ATTR_VLAN] = sizeof(__be16),
[OVS_KEY_ATTR_ETHERTYPE] = sizeof(__be16),
[OVS_KEY_ATTR_IPV4] = sizeof(struct ovs_key_ipv4),
[OVS_KEY_ATTR_IPV6] = sizeof(struct ovs_key_ipv6),
[OVS_KEY_ATTR_TCP] = sizeof(struct ovs_key_tcp),
[OVS_KEY_ATTR_UDP] = sizeof(struct ovs_key_udp),
[OVS_KEY_ATTR_ICMP] = sizeof(struct ovs_key_icmp),
[OVS_KEY_ATTR_ICMPV6] = sizeof(struct ovs_key_icmpv6),
[OVS_KEY_ATTR_ARP] = sizeof(struct ovs_key_arp),
[OVS_KEY_ATTR_ND] = sizeof(struct ovs_key_nd),
};
static int ipv4_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_len,
const struct nlattr *a[], u32 *attrs)
{
const struct ovs_key_icmp *icmp_key;
const struct ovs_key_tcp *tcp_key;
const struct ovs_key_udp *udp_key;
switch (swkey->ip.proto) {
case IPPROTO_TCP:
if (!(*attrs & (1 << OVS_KEY_ATTR_TCP)))
return -EINVAL;
*attrs &= ~(1 << OVS_KEY_ATTR_TCP);
*key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
tcp_key = nla_data(a[OVS_KEY_ATTR_TCP]);
swkey->ipv4.tp.src = tcp_key->tcp_src;
swkey->ipv4.tp.dst = tcp_key->tcp_dst;
break;
case IPPROTO_UDP:
if (!(*attrs & (1 << OVS_KEY_ATTR_UDP)))
return -EINVAL;
*attrs &= ~(1 << OVS_KEY_ATTR_UDP);
*key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
udp_key = nla_data(a[OVS_KEY_ATTR_UDP]);
swkey->ipv4.tp.src = udp_key->udp_src;
swkey->ipv4.tp.dst = udp_key->udp_dst;
break;
case IPPROTO_ICMP:
if (!(*attrs & (1 << OVS_KEY_ATTR_ICMP)))
return -EINVAL;
*attrs &= ~(1 << OVS_KEY_ATTR_ICMP);
*key_len = SW_FLOW_KEY_OFFSET(ipv4.tp);
icmp_key = nla_data(a[OVS_KEY_ATTR_ICMP]);
swkey->ipv4.tp.src = htons(icmp_key->icmp_type);
swkey->ipv4.tp.dst = htons(icmp_key->icmp_code);
break;
}
return 0;
}
static int ipv6_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_len,
const struct nlattr *a[], u32 *attrs)
{
const struct ovs_key_icmpv6 *icmpv6_key;
const struct ovs_key_tcp *tcp_key;
const struct ovs_key_udp *udp_key;
switch (swkey->ip.proto) {
case IPPROTO_TCP:
if (!(*attrs & (1 << OVS_KEY_ATTR_TCP)))
return -EINVAL;
*attrs &= ~(1 << OVS_KEY_ATTR_TCP);
*key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
tcp_key = nla_data(a[OVS_KEY_ATTR_TCP]);
swkey->ipv6.tp.src = tcp_key->tcp_src;
swkey->ipv6.tp.dst = tcp_key->tcp_dst;
break;
case IPPROTO_UDP:
if (!(*attrs & (1 << OVS_KEY_ATTR_UDP)))
return -EINVAL;
*attrs &= ~(1 << OVS_KEY_ATTR_UDP);
*key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
udp_key = nla_data(a[OVS_KEY_ATTR_UDP]);
swkey->ipv6.tp.src = udp_key->udp_src;
swkey->ipv6.tp.dst = udp_key->udp_dst;
break;
case IPPROTO_ICMPV6:
if (!(*attrs & (1 << OVS_KEY_ATTR_ICMPV6)))
return -EINVAL;
*attrs &= ~(1 << OVS_KEY_ATTR_ICMPV6);
*key_len = SW_FLOW_KEY_OFFSET(ipv6.tp);
icmpv6_key = nla_data(a[OVS_KEY_ATTR_ICMPV6]);
swkey->ipv6.tp.src = htons(icmpv6_key->icmpv6_type);
swkey->ipv6.tp.dst = htons(icmpv6_key->icmpv6_code);
if (swkey->ipv6.tp.src == htons(NDISC_NEIGHBOUR_SOLICITATION) ||
swkey->ipv6.tp.src == htons(NDISC_NEIGHBOUR_ADVERTISEMENT)) {
const struct ovs_key_nd *nd_key;
if (!(*attrs & (1 << OVS_KEY_ATTR_ND)))
return -EINVAL;
*attrs &= ~(1 << OVS_KEY_ATTR_ND);
*key_len = SW_FLOW_KEY_OFFSET(ipv6.nd);
nd_key = nla_data(a[OVS_KEY_ATTR_ND]);
memcpy(&swkey->ipv6.nd.target, nd_key->nd_target,
sizeof(swkey->ipv6.nd.target));
memcpy(swkey->ipv6.nd.sll, nd_key->nd_sll, ETH_ALEN);
memcpy(swkey->ipv6.nd.tll, nd_key->nd_tll, ETH_ALEN);
}
break;
}
return 0;
}
static int parse_flow_nlattrs(const struct nlattr *attr,
const struct nlattr *a[], u32 *attrsp)
{
const struct nlattr *nla;
u32 attrs;
int rem;
attrs = 0;
nla_for_each_nested(nla, attr, rem) {
u16 type = nla_type(nla);
int expected_len;
if (type > OVS_KEY_ATTR_MAX || attrs & (1 << type))
return -EINVAL;
expected_len = ovs_key_lens[type];
if (nla_len(nla) != expected_len && expected_len != -1)
return -EINVAL;
attrs |= 1 << type;
a[type] = nla;
}
if (rem)
return -EINVAL;
*attrsp = attrs;
return 0;
}
/**
* ovs_flow_from_nlattrs - parses Netlink attributes into a flow key.
* @swkey: receives the extracted flow key.
* @key_lenp: number of bytes used in @swkey.
* @attr: Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink attribute
* sequence.
*/
int ovs_flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp,
const struct nlattr *attr)
{
const struct nlattr *a[OVS_KEY_ATTR_MAX + 1];
const struct ovs_key_ethernet *eth_key;
int key_len;
u32 attrs;
int err;
memset(swkey, 0, sizeof(struct sw_flow_key));
key_len = SW_FLOW_KEY_OFFSET(eth);
err = parse_flow_nlattrs(attr, a, &attrs);
if (err)
return err;
/* Metadata attributes. */
if (attrs & (1 << OVS_KEY_ATTR_PRIORITY)) {
swkey->phy.priority = nla_get_u32(a[OVS_KEY_ATTR_PRIORITY]);
attrs &= ~(1 << OVS_KEY_ATTR_PRIORITY);
}
if (attrs & (1 << OVS_KEY_ATTR_IN_PORT)) {
u32 in_port = nla_get_u32(a[OVS_KEY_ATTR_IN_PORT]);
if (in_port >= DP_MAX_PORTS)
return -EINVAL;
swkey->phy.in_port = in_port;
attrs &= ~(1 << OVS_KEY_ATTR_IN_PORT);
} else {
swkey->phy.in_port = USHRT_MAX;
}
/* Data attributes. */
if (!(attrs & (1 << OVS_KEY_ATTR_ETHERNET)))
return -EINVAL;
attrs &= ~(1 << OVS_KEY_ATTR_ETHERNET);
eth_key = nla_data(a[OVS_KEY_ATTR_ETHERNET]);
memcpy(swkey->eth.src, eth_key->eth_src, ETH_ALEN);
memcpy(swkey->eth.dst, eth_key->eth_dst, ETH_ALEN);
if (attrs & (1u << OVS_KEY_ATTR_ETHERTYPE) &&
nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]) == htons(ETH_P_8021Q)) {
const struct nlattr *encap;
__be16 tci;
if (attrs != ((1 << OVS_KEY_ATTR_VLAN) |
(1 << OVS_KEY_ATTR_ETHERTYPE) |
(1 << OVS_KEY_ATTR_ENCAP)))
return -EINVAL;
encap = a[OVS_KEY_ATTR_ENCAP];
tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
if (tci & htons(VLAN_TAG_PRESENT)) {
swkey->eth.tci = tci;
err = parse_flow_nlattrs(encap, a, &attrs);
if (err)
return err;
} else if (!tci) {
/* Corner case for truncated 802.1Q header. */
if (nla_len(encap))
return -EINVAL;
swkey->eth.type = htons(ETH_P_8021Q);
*key_lenp = key_len;
return 0;
} else {
return -EINVAL;
}
}
if (attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) {
swkey->eth.type = nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]);
if (ntohs(swkey->eth.type) < 1536)
return -EINVAL;
attrs &= ~(1 << OVS_KEY_ATTR_ETHERTYPE);
} else {
swkey->eth.type = htons(ETH_P_802_2);
}
if (swkey->eth.type == htons(ETH_P_IP)) {
const struct ovs_key_ipv4 *ipv4_key;
if (!(attrs & (1 << OVS_KEY_ATTR_IPV4)))
return -EINVAL;
attrs &= ~(1 << OVS_KEY_ATTR_IPV4);
key_len = SW_FLOW_KEY_OFFSET(ipv4.addr);
ipv4_key = nla_data(a[OVS_KEY_ATTR_IPV4]);
if (ipv4_key->ipv4_frag > OVS_FRAG_TYPE_MAX)
return -EINVAL;
swkey->ip.proto = ipv4_key->ipv4_proto;
swkey->ip.tos = ipv4_key->ipv4_tos;
swkey->ip.ttl = ipv4_key->ipv4_ttl;
swkey->ip.frag = ipv4_key->ipv4_frag;
swkey->ipv4.addr.src = ipv4_key->ipv4_src;
swkey->ipv4.addr.dst = ipv4_key->ipv4_dst;
if (swkey->ip.frag != OVS_FRAG_TYPE_LATER) {
err = ipv4_flow_from_nlattrs(swkey, &key_len, a, &attrs);
if (err)
return err;
}
} else if (swkey->eth.type == htons(ETH_P_IPV6)) {
const struct ovs_key_ipv6 *ipv6_key;
if (!(attrs & (1 << OVS_KEY_ATTR_IPV6)))
return -EINVAL;
attrs &= ~(1 << OVS_KEY_ATTR_IPV6);
key_len = SW_FLOW_KEY_OFFSET(ipv6.label);
ipv6_key = nla_data(a[OVS_KEY_ATTR_IPV6]);
if (ipv6_key->ipv6_frag > OVS_FRAG_TYPE_MAX)
return -EINVAL;
swkey->ipv6.label = ipv6_key->ipv6_label;
swkey->ip.proto = ipv6_key->ipv6_proto;
swkey->ip.tos = ipv6_key->ipv6_tclass;
swkey->ip.ttl = ipv6_key->ipv6_hlimit;
swkey->ip.frag = ipv6_key->ipv6_frag;
memcpy(&swkey->ipv6.addr.src, ipv6_key->ipv6_src,
sizeof(swkey->ipv6.addr.src));
memcpy(&swkey->ipv6.addr.dst, ipv6_key->ipv6_dst,
sizeof(swkey->ipv6.addr.dst));
if (swkey->ip.frag != OVS_FRAG_TYPE_LATER) {
err = ipv6_flow_from_nlattrs(swkey, &key_len, a, &attrs);
if (err)
return err;
}
} else if (swkey->eth.type == htons(ETH_P_ARP)) {
const struct ovs_key_arp *arp_key;
if (!(attrs & (1 << OVS_KEY_ATTR_ARP)))
return -EINVAL;
attrs &= ~(1 << OVS_KEY_ATTR_ARP);
key_len = SW_FLOW_KEY_OFFSET(ipv4.arp);
arp_key = nla_data(a[OVS_KEY_ATTR_ARP]);
swkey->ipv4.addr.src = arp_key->arp_sip;
swkey->ipv4.addr.dst = arp_key->arp_tip;
if (arp_key->arp_op & htons(0xff00))
return -EINVAL;
swkey->ip.proto = ntohs(arp_key->arp_op);
memcpy(swkey->ipv4.arp.sha, arp_key->arp_sha, ETH_ALEN);
memcpy(swkey->ipv4.arp.tha, arp_key->arp_tha, ETH_ALEN);
}
if (attrs)
return -EINVAL;
*key_lenp = key_len;
return 0;
}
/**
* ovs_flow_metadata_from_nlattrs - parses Netlink attributes into a flow key.
* @in_port: receives the extracted input port.
* @key: Netlink attribute holding nested %OVS_KEY_ATTR_* Netlink attribute
* sequence.
*
* This parses a series of Netlink attributes that form a flow key, which must
* take the same form accepted by flow_from_nlattrs(), but only enough of it to
* get the metadata, that is, the parts of the flow key that cannot be
* extracted from the packet itself.
*/
int ovs_flow_metadata_from_nlattrs(u32 *priority, u16 *in_port,
const struct nlattr *attr)
{
const struct nlattr *nla;
int rem;
*in_port = USHRT_MAX;
*priority = 0;
nla_for_each_nested(nla, attr, rem) {
int type = nla_type(nla);
if (type <= OVS_KEY_ATTR_MAX && ovs_key_lens[type] > 0) {
if (nla_len(nla) != ovs_key_lens[type])
return -EINVAL;
switch (type) {
case OVS_KEY_ATTR_PRIORITY:
*priority = nla_get_u32(nla);
break;
case OVS_KEY_ATTR_IN_PORT:
if (nla_get_u32(nla) >= DP_MAX_PORTS)
return -EINVAL;
*in_port = nla_get_u32(nla);
break;
}
}
}
if (rem)
return -EINVAL;
return 0;
}
int ovs_flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb)
{
struct ovs_key_ethernet *eth_key;
struct nlattr *nla, *encap;
if (swkey->phy.priority)
NLA_PUT_U32(skb, OVS_KEY_ATTR_PRIORITY, swkey->phy.priority);
if (swkey->phy.in_port != USHRT_MAX)
NLA_PUT_U32(skb, OVS_KEY_ATTR_IN_PORT, swkey->phy.in_port);
nla = nla_reserve(skb, OVS_KEY_ATTR_ETHERNET, sizeof(*eth_key));
if (!nla)
goto nla_put_failure;
eth_key = nla_data(nla);
memcpy(eth_key->eth_src, swkey->eth.src, ETH_ALEN);
memcpy(eth_key->eth_dst, swkey->eth.dst, ETH_ALEN);
if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021Q)) {
NLA_PUT_BE16(skb, OVS_KEY_ATTR_ETHERTYPE, htons(ETH_P_8021Q));
NLA_PUT_BE16(skb, OVS_KEY_ATTR_VLAN, swkey->eth.tci);
encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
if (!swkey->eth.tci)
goto unencap;
} else {
encap = NULL;
}
if (swkey->eth.type == htons(ETH_P_802_2))
goto unencap;
NLA_PUT_BE16(skb, OVS_KEY_ATTR_ETHERTYPE, swkey->eth.type);
if (swkey->eth.type == htons(ETH_P_IP)) {
struct ovs_key_ipv4 *ipv4_key;
nla = nla_reserve(skb, OVS_KEY_ATTR_IPV4, sizeof(*ipv4_key));
if (!nla)
goto nla_put_failure;
ipv4_key = nla_data(nla);
ipv4_key->ipv4_src = swkey->ipv4.addr.src;
ipv4_key->ipv4_dst = swkey->ipv4.addr.dst;
ipv4_key->ipv4_proto = swkey->ip.proto;
ipv4_key->ipv4_tos = swkey->ip.tos;
ipv4_key->ipv4_ttl = swkey->ip.ttl;
ipv4_key->ipv4_frag = swkey->ip.frag;
} else if (swkey->eth.type == htons(ETH_P_IPV6)) {
struct ovs_key_ipv6 *ipv6_key;
nla = nla_reserve(skb, OVS_KEY_ATTR_IPV6, sizeof(*ipv6_key));
if (!nla)
goto nla_put_failure;
ipv6_key = nla_data(nla);
memcpy(ipv6_key->ipv6_src, &swkey->ipv6.addr.src,
sizeof(ipv6_key->ipv6_src));
memcpy(ipv6_key->ipv6_dst, &swkey->ipv6.addr.dst,
sizeof(ipv6_key->ipv6_dst));
ipv6_key->ipv6_label = swkey->ipv6.label;
ipv6_key->ipv6_proto = swkey->ip.proto;
ipv6_key->ipv6_tclass = swkey->ip.tos;
ipv6_key->ipv6_hlimit = swkey->ip.ttl;
ipv6_key->ipv6_frag = swkey->ip.frag;
} else if (swkey->eth.type == htons(ETH_P_ARP)) {
struct ovs_key_arp *arp_key;
nla = nla_reserve(skb, OVS_KEY_ATTR_ARP, sizeof(*arp_key));
if (!nla)
goto nla_put_failure;
arp_key = nla_data(nla);
memset(arp_key, 0, sizeof(struct ovs_key_arp));
arp_key->arp_sip = swkey->ipv4.addr.src;
arp_key->arp_tip = swkey->ipv4.addr.dst;
arp_key->arp_op = htons(swkey->ip.proto);
memcpy(arp_key->arp_sha, swkey->ipv4.arp.sha, ETH_ALEN);
memcpy(arp_key->arp_tha, swkey->ipv4.arp.tha, ETH_ALEN);
}
if ((swkey->eth.type == htons(ETH_P_IP) ||
swkey->eth.type == htons(ETH_P_IPV6)) &&
swkey->ip.frag != OVS_FRAG_TYPE_LATER) {
if (swkey->ip.proto == IPPROTO_TCP) {
struct ovs_key_tcp *tcp_key;
nla = nla_reserve(skb, OVS_KEY_ATTR_TCP, sizeof(*tcp_key));
if (!nla)
goto nla_put_failure;
tcp_key = nla_data(nla);
if (swkey->eth.type == htons(ETH_P_IP)) {
tcp_key->tcp_src = swkey->ipv4.tp.src;
tcp_key->tcp_dst = swkey->ipv4.tp.dst;
} else if (swkey->eth.type == htons(ETH_P_IPV6)) {
tcp_key->tcp_src = swkey->ipv6.tp.src;
tcp_key->tcp_dst = swkey->ipv6.tp.dst;
}
} else if (swkey->ip.proto == IPPROTO_UDP) {
struct ovs_key_udp *udp_key;
nla = nla_reserve(skb, OVS_KEY_ATTR_UDP, sizeof(*udp_key));
if (!nla)
goto nla_put_failure;
udp_key = nla_data(nla);
if (swkey->eth.type == htons(ETH_P_IP)) {
udp_key->udp_src = swkey->ipv4.tp.src;
udp_key->udp_dst = swkey->ipv4.tp.dst;
} else if (swkey->eth.type == htons(ETH_P_IPV6)) {
udp_key->udp_src = swkey->ipv6.tp.src;
udp_key->udp_dst = swkey->ipv6.tp.dst;
}
} else if (swkey->eth.type == htons(ETH_P_IP) &&
swkey->ip.proto == IPPROTO_ICMP) {
struct ovs_key_icmp *icmp_key;
nla = nla_reserve(skb, OVS_KEY_ATTR_ICMP, sizeof(*icmp_key));
if (!nla)
goto nla_put_failure;
icmp_key = nla_data(nla);
icmp_key->icmp_type = ntohs(swkey->ipv4.tp.src);
icmp_key->icmp_code = ntohs(swkey->ipv4.tp.dst);
} else if (swkey->eth.type == htons(ETH_P_IPV6) &&
swkey->ip.proto == IPPROTO_ICMPV6) {
struct ovs_key_icmpv6 *icmpv6_key;
nla = nla_reserve(skb, OVS_KEY_ATTR_ICMPV6,
sizeof(*icmpv6_key));
if (!nla)
goto nla_put_failure;
icmpv6_key = nla_data(nla);
icmpv6_key->icmpv6_type = ntohs(swkey->ipv6.tp.src);
icmpv6_key->icmpv6_code = ntohs(swkey->ipv6.tp.dst);
if (icmpv6_key->icmpv6_type == NDISC_NEIGHBOUR_SOLICITATION ||
icmpv6_key->icmpv6_type == NDISC_NEIGHBOUR_ADVERTISEMENT) {
struct ovs_key_nd *nd_key;
nla = nla_reserve(skb, OVS_KEY_ATTR_ND, sizeof(*nd_key));
if (!nla)
goto nla_put_failure;
nd_key = nla_data(nla);
memcpy(nd_key->nd_target, &swkey->ipv6.nd.target,
sizeof(nd_key->nd_target));
memcpy(nd_key->nd_sll, swkey->ipv6.nd.sll, ETH_ALEN);
memcpy(nd_key->nd_tll, swkey->ipv6.nd.tll, ETH_ALEN);
}
}
}
unencap:
if (encap)
nla_nest_end(skb, encap);
return 0;
nla_put_failure:
return -EMSGSIZE;
}
/* Initializes the flow module.
* Returns zero if successful or a negative error code. */
int ovs_flow_init(void)
{
flow_cache = kmem_cache_create("sw_flow", sizeof(struct sw_flow), 0,
0, NULL);
if (flow_cache == NULL)
return -ENOMEM;
return 0;
}
/* Uninitializes the flow module. */
void ovs_flow_exit(void)
{
kmem_cache_destroy(flow_cache);
}
| Andiry/Linux-xHCI-development | net/openvswitch/flow.c | C | gpl-2.0 | 35,704 |
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.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, 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 XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "system.h"
#if defined (HAVE_WAYLAND)
#include <boost/scoped_ptr.hpp>
#include "Application.h"
#include "xbmc/windowing/WindowingFactory.h"
#include "WinEventsWayland.h"
#include "wayland/EventListener.h"
#include "wayland/InputFactory.h"
#include "wayland/EventLoop.h"
namespace xwe = xbmc::wayland::events;
namespace
{
class XBMCListener :
public xbmc::IEventListener
{
public:
virtual void OnEvent(XBMC_Event &event);
virtual void OnFocused();
virtual void OnUnfocused();
};
XBMCListener g_listener;
boost::scoped_ptr <xbmc::InputFactory> g_inputInstance;
boost::scoped_ptr <xwe::Loop> g_eventLoop;
}
void XBMCListener::OnEvent(XBMC_Event &e)
{
g_application.OnEvent(e);
}
void XBMCListener::OnFocused()
{
g_application.m_AppFocused = true;
g_Windowing.NotifyAppFocusChange(g_application.m_AppFocused);
}
void XBMCListener::OnUnfocused()
{
g_application.m_AppFocused = false;
g_Windowing.NotifyAppFocusChange(g_application.m_AppFocused);
}
CWinEventsWayland::CWinEventsWayland()
{
}
void CWinEventsWayland::RefreshDevices()
{
}
bool CWinEventsWayland::IsRemoteLowBattery()
{
return false;
}
/* This function reads the display connection and dispatches
* any events through the specified object listeners */
bool CWinEventsWayland::MessagePump()
{
if (!g_eventLoop.get())
return false;
g_eventLoop->Dispatch();
return true;
}
size_t CWinEventsWayland::GetQueueSize()
{
/* We can't query the size of the queue */
return 0;
}
void CWinEventsWayland::SetEventQueueStrategy(xwe::IEventQueueStrategy &strategy)
{
g_eventLoop.reset(new xwe::Loop(g_listener, strategy));
}
void CWinEventsWayland::DestroyEventQueueStrategy()
{
g_eventLoop.reset();
}
/* Once we know about a wayland seat, we can just create our manager
* object to encapsulate all of that state. When the seat goes away
* we just unset the manager object and it is all cleaned up at that
* point */
void CWinEventsWayland::SetWaylandSeat(IDllWaylandClient &clientLibrary,
IDllXKBCommon &xkbCommonLibrary,
struct wl_seat *s)
{
if (!g_eventLoop.get())
throw std::logic_error("Must have a wl_display set before setting "
"the wl_seat in CWinEventsWayland ");
g_inputInstance.reset(new xbmc::InputFactory(clientLibrary,
xkbCommonLibrary,
s,
*g_eventLoop,
*g_eventLoop));
}
void CWinEventsWayland::DestroyWaylandSeat()
{
g_inputInstance.reset();
}
/* When a surface becomes available, this function should be called
* to register it as the current one for processing input events on.
*
* It is a precondition violation to call this function before
* a seat has been registered */
void CWinEventsWayland::SetXBMCSurface(struct wl_surface *s)
{
if (!g_inputInstance.get())
throw std::logic_error("Must have a wl_seat set before setting "
"the wl_surface in CWinEventsWayland");
g_inputInstance->SetXBMCSurface(s);
}
#endif
| TRex22/xbmc | xbmc/windowing/WinEventsWayland.cpp | C++ | gpl-2.0 | 3,936 |
/*
* Copyright (C) 2007 Esmertec AG.
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ws.com.google.android.mms.pdu;
import ws.com.google.android.mms.InvalidHeaderValueException;
public class ReadRecInd extends GenericPdu {
/**
* Constructor, used when composing a M-ReadRec.ind pdu.
*
* @param from the from value
* @param messageId the message ID value
* @param mmsVersion current viersion of mms
* @param readStatus the read status value
* @param to the to value
* @throws InvalidHeaderValueException if parameters are invalid.
* NullPointerException if messageId or to is null.
*/
public ReadRecInd(EncodedStringValue from,
byte[] messageId,
int mmsVersion,
int readStatus,
EncodedStringValue[] to) throws InvalidHeaderValueException {
super();
setMessageType(PduHeaders.MESSAGE_TYPE_READ_REC_IND);
setFrom(from);
setMessageId(messageId);
setMmsVersion(mmsVersion);
setTo(to);
setReadStatus(readStatus);
}
/**
* Constructor with given headers.
*
* @param headers Headers for this PDU.
*/
ReadRecInd(PduHeaders headers) {
super(headers);
}
/**
* Get Date value.
*
* @return the value
*/
public long getDate() {
return mPduHeaders.getLongInteger(PduHeaders.DATE);
}
/**
* Set Date value.
*
* @param value the value
*/
public void setDate(long value) {
mPduHeaders.setLongInteger(value, PduHeaders.DATE);
}
/**
* Get Message-ID value.
*
* @return the value
*/
public byte[] getMessageId() {
return mPduHeaders.getTextString(PduHeaders.MESSAGE_ID);
}
/**
* Set Message-ID value.
*
* @param value the value
* @throws NullPointerException if the value is null.
*/
public void setMessageId(byte[] value) {
mPduHeaders.setTextString(value, PduHeaders.MESSAGE_ID);
}
/**
* Get To value.
*
* @return the value
*/
public EncodedStringValue[] getTo() {
return mPduHeaders.getEncodedStringValues(PduHeaders.TO);
}
/**
* Set To value.
*
* @param value the value
* @throws NullPointerException if the value is null.
*/
public void setTo(EncodedStringValue[] value) {
mPduHeaders.setEncodedStringValues(value, PduHeaders.TO);
}
/**
* Get X-MMS-Read-status value.
*
* @return the value
*/
public int getReadStatus() {
return mPduHeaders.getOctet(PduHeaders.READ_STATUS);
}
/**
* Set X-MMS-Read-status value.
*
* @param value the value
* @throws InvalidHeaderValueException if the value is invalid.
*/
public void setReadStatus(int value) throws InvalidHeaderValueException {
mPduHeaders.setOctet(value, PduHeaders.READ_STATUS);
}
/*
* Optional, not supported header fields:
*
* public byte[] getApplicId() {return null;}
* public void setApplicId(byte[] value) {}
*
* public byte[] getAuxApplicId() {return null;}
* public void getAuxApplicId(byte[] value) {}
*
* public byte[] getReplyApplicId() {return 0x00;}
* public void setReplyApplicId(byte[] value) {}
*/
}
| jodson/TextSecure | src/ws/com/google/android/mms/pdu/ReadRecInd.java | Java | gpl-3.0 | 4,014 |
#include <string.h>
#include <node.h>
#include "macros.h"
#include "database.h"
#include "statement.h"
using namespace node_sqlite3;
Persistent<FunctionTemplate> Database::constructor_template;
void Database::Init(Handle<Object> target) {
NanScope();
Local<FunctionTemplate> t = NanNew<FunctionTemplate>(New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(NanNew("Database"));
NODE_SET_PROTOTYPE_METHOD(t, "close", Close);
NODE_SET_PROTOTYPE_METHOD(t, "exec", Exec);
NODE_SET_PROTOTYPE_METHOD(t, "wait", Wait);
NODE_SET_PROTOTYPE_METHOD(t, "loadExtension", LoadExtension);
NODE_SET_PROTOTYPE_METHOD(t, "serialize", Serialize);
NODE_SET_PROTOTYPE_METHOD(t, "parallelize", Parallelize);
NODE_SET_PROTOTYPE_METHOD(t, "configure", Configure);
NODE_SET_GETTER(t, "open", OpenGetter);
NanAssignPersistent(constructor_template, t);
target->Set(NanNew("Database"),
t->GetFunction());
}
void Database::Process() {
NanScope();
if (!open && locked && !queue.empty()) {
EXCEPTION(NanNew<String>("Database handle is closed"), SQLITE_MISUSE, exception);
Local<Value> argv[] = { exception };
bool called = false;
// Call all callbacks with the error object.
while (!queue.empty()) {
Call* call = queue.front();
Local<Function> cb = NanNew(call->baton->callback);
if (!cb.IsEmpty() && cb->IsFunction()) {
TRY_CATCH_CALL(NanObjectWrapHandle(this), cb, 1, argv);
called = true;
}
queue.pop();
// We don't call the actual callback, so we have to make sure that
// the baton gets destroyed.
delete call->baton;
delete call;
}
// When we couldn't call a callback function, emit an error on the
// Database object.
if (!called) {
Local<Value> args[] = { NanNew("error"), exception };
EMIT_EVENT(NanObjectWrapHandle(this), 2, args);
}
return;
}
while (open && (!locked || pending == 0) && !queue.empty()) {
Call* call = queue.front();
if (call->exclusive && pending > 0) {
break;
}
queue.pop();
locked = call->exclusive;
call->callback(call->baton);
delete call;
if (locked) break;
}
}
void Database::Schedule(Work_Callback callback, Baton* baton, bool exclusive) {
NanScope();
if (!open && locked) {
EXCEPTION(NanNew<String>("Database is closed"), SQLITE_MISUSE, exception);
Local<Function> cb = NanNew(baton->callback);
if (!cb.IsEmpty() && cb->IsFunction()) {
Local<Value> argv[] = { exception };
TRY_CATCH_CALL(NanObjectWrapHandle(this), cb, 1, argv);
}
else {
Local<Value> argv[] = { NanNew("error"), exception };
EMIT_EVENT(NanObjectWrapHandle(this), 2, argv);
}
return;
}
if (!open || ((locked || exclusive || serialize) && pending > 0)) {
queue.push(new Call(callback, baton, exclusive || serialize));
}
else {
locked = exclusive;
callback(baton);
}
}
NAN_METHOD(Database::New) {
NanScope();
if (!args.IsConstructCall()) {
return NanThrowTypeError("Use the new operator to create new Database objects");
}
REQUIRE_ARGUMENT_STRING(0, filename);
int pos = 1;
int mode;
if (args.Length() >= pos && args[pos]->IsInt32()) {
mode = args[pos++]->Int32Value();
} else {
mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
}
Local<Function> callback;
if (args.Length() >= pos && args[pos]->IsFunction()) {
callback = Local<Function>::Cast(args[pos++]);
}
Database* db = new Database();
db->Wrap(args.This());
args.This()->Set(NanNew("filename"), args[0]->ToString(), ReadOnly);
args.This()->Set(NanNew("mode"), NanNew<Integer>(mode), ReadOnly);
// Start opening the database.
OpenBaton* baton = new OpenBaton(db, callback, *filename, mode);
Work_BeginOpen(baton);
NanReturnValue(args.This());
}
void Database::Work_BeginOpen(Baton* baton) {
int status = uv_queue_work(uv_default_loop(),
&baton->request, Work_Open, (uv_after_work_cb)Work_AfterOpen);
assert(status == 0);
}
void Database::Work_Open(uv_work_t* req) {
OpenBaton* baton = static_cast<OpenBaton*>(req->data);
Database* db = baton->db;
baton->status = sqlite3_open_v2(
baton->filename.c_str(),
&db->_handle,
baton->mode,
NULL
);
if (baton->status != SQLITE_OK) {
baton->message = std::string(sqlite3_errmsg(db->_handle));
sqlite3_close(db->_handle);
db->_handle = NULL;
}
else {
// Set default database handle values.
sqlite3_busy_timeout(db->_handle, 1000);
}
}
void Database::Work_AfterOpen(uv_work_t* req) {
NanScope();
OpenBaton* baton = static_cast<OpenBaton*>(req->data);
Database* db = baton->db;
Local<Value> argv[1];
if (baton->status != SQLITE_OK) {
EXCEPTION(NanNew<String>(baton->message.c_str()), baton->status, exception);
argv[0] = exception;
}
else {
db->open = true;
argv[0] = NanNew(NanNull());
}
Local<Function> cb = NanNew(baton->callback);
if (!cb.IsEmpty() && cb->IsFunction()) {
TRY_CATCH_CALL(NanObjectWrapHandle(db), cb, 1, argv);
}
else if (!db->open) {
Local<Value> args[] = { NanNew("error"), argv[0] };
EMIT_EVENT(NanObjectWrapHandle(db), 2, args);
}
if (db->open) {
Local<Value> args[] = { NanNew("open") };
EMIT_EVENT(NanObjectWrapHandle(db), 1, args);
db->Process();
}
delete baton;
}
NAN_GETTER(Database::OpenGetter) {
NanScope();
Database* db = ObjectWrap::Unwrap<Database>(args.This());
NanReturnValue(NanNew<Boolean>(db->open));
}
NAN_METHOD(Database::Close) {
NanScope();
Database* db = ObjectWrap::Unwrap<Database>(args.This());
OPTIONAL_ARGUMENT_FUNCTION(0, callback);
Baton* baton = new Baton(db, callback);
db->Schedule(Work_BeginClose, baton, true);
NanReturnValue(args.This());
}
void Database::Work_BeginClose(Baton* baton) {
assert(baton->db->locked);
assert(baton->db->open);
assert(baton->db->_handle);
assert(baton->db->pending == 0);
baton->db->RemoveCallbacks();
int status = uv_queue_work(uv_default_loop(),
&baton->request, Work_Close, (uv_after_work_cb)Work_AfterClose);
assert(status == 0);
}
void Database::Work_Close(uv_work_t* req) {
Baton* baton = static_cast<Baton*>(req->data);
Database* db = baton->db;
baton->status = sqlite3_close(db->_handle);
if (baton->status != SQLITE_OK) {
baton->message = std::string(sqlite3_errmsg(db->_handle));
}
else {
db->_handle = NULL;
}
}
void Database::Work_AfterClose(uv_work_t* req) {
NanScope();
Baton* baton = static_cast<Baton*>(req->data);
Database* db = baton->db;
Local<Value> argv[1];
if (baton->status != SQLITE_OK) {
EXCEPTION(NanNew<String>(baton->message.c_str()), baton->status, exception);
argv[0] = exception;
}
else {
db->open = false;
// Leave db->locked to indicate that this db object has reached
// the end of its life.
argv[0] = NanNew(NanNull());
}
Local<Function> cb = NanNew(baton->callback);
// Fire callbacks.
if (!cb.IsEmpty() && cb->IsFunction()) {
TRY_CATCH_CALL(NanObjectWrapHandle(db), cb, 1, argv);
}
else if (db->open) {
Local<Value> args[] = { NanNew("error"), argv[0] };
EMIT_EVENT(NanObjectWrapHandle(db), 2, args);
}
if (!db->open) {
Local<Value> args[] = { NanNew("close"), argv[0] };
EMIT_EVENT(NanObjectWrapHandle(db), 1, args);
db->Process();
}
delete baton;
}
NAN_METHOD(Database::Serialize) {
NanScope();
Database* db = ObjectWrap::Unwrap<Database>(args.This());
OPTIONAL_ARGUMENT_FUNCTION(0, callback);
bool before = db->serialize;
db->serialize = true;
if (!callback.IsEmpty() && callback->IsFunction()) {
TRY_CATCH_CALL(args.This(), callback, 0, NULL);
db->serialize = before;
}
db->Process();
NanReturnValue(args.This());
}
NAN_METHOD(Database::Parallelize) {
NanScope();
Database* db = ObjectWrap::Unwrap<Database>(args.This());
OPTIONAL_ARGUMENT_FUNCTION(0, callback);
bool before = db->serialize;
db->serialize = false;
if (!callback.IsEmpty() && callback->IsFunction()) {
TRY_CATCH_CALL(args.This(), callback, 0, NULL);
db->serialize = before;
}
db->Process();
NanReturnValue(args.This());
}
NAN_METHOD(Database::Configure) {
NanScope();
Database* db = ObjectWrap::Unwrap<Database>(args.This());
REQUIRE_ARGUMENTS(2);
if (args[0]->Equals(NanNew("trace"))) {
Local<Function> handle;
Baton* baton = new Baton(db, handle);
db->Schedule(RegisterTraceCallback, baton);
}
else if (args[0]->Equals(NanNew("profile"))) {
Local<Function> handle;
Baton* baton = new Baton(db, handle);
db->Schedule(RegisterProfileCallback, baton);
}
else if (args[0]->Equals(NanNew("busyTimeout"))) {
if (!args[1]->IsInt32()) {
return NanThrowTypeError("Value must be an integer");
}
Local<Function> handle;
Baton* baton = new Baton(db, handle);
baton->status = args[1]->Int32Value();
db->Schedule(SetBusyTimeout, baton);
}
else {
return NanThrowError(Exception::Error(String::Concat(
args[0]->ToString(),
NanNew<String>(" is not a valid configuration option")
)));
}
db->Process();
NanReturnValue(args.This());
}
void Database::SetBusyTimeout(Baton* baton) {
assert(baton->db->open);
assert(baton->db->_handle);
// Abuse the status field for passing the timeout.
sqlite3_busy_timeout(baton->db->_handle, baton->status);
delete baton;
}
void Database::RegisterTraceCallback(Baton* baton) {
assert(baton->db->open);
assert(baton->db->_handle);
Database* db = baton->db;
if (db->debug_trace == NULL) {
// Add it.
db->debug_trace = new AsyncTrace(db, TraceCallback);
sqlite3_trace(db->_handle, TraceCallback, db);
}
else {
// Remove it.
sqlite3_trace(db->_handle, NULL, NULL);
db->debug_trace->finish();
db->debug_trace = NULL;
}
delete baton;
}
void Database::TraceCallback(void* db, const char* sql) {
// Note: This function is called in the thread pool.
// Note: Some queries, such as "EXPLAIN" queries, are not sent through this.
static_cast<Database*>(db)->debug_trace->send(new std::string(sql));
}
void Database::TraceCallback(Database* db, std::string* sql) {
// Note: This function is called in the main V8 thread.
NanScope();
Local<Value> argv[] = {
NanNew("trace"),
NanNew<String>(sql->c_str())
};
EMIT_EVENT(NanObjectWrapHandle(db), 2, argv);
delete sql;
}
void Database::RegisterProfileCallback(Baton* baton) {
assert(baton->db->open);
assert(baton->db->_handle);
Database* db = baton->db;
if (db->debug_profile == NULL) {
// Add it.
db->debug_profile = new AsyncProfile(db, ProfileCallback);
sqlite3_profile(db->_handle, ProfileCallback, db);
}
else {
// Remove it.
sqlite3_profile(db->_handle, NULL, NULL);
db->debug_profile->finish();
db->debug_profile = NULL;
}
delete baton;
}
void Database::ProfileCallback(void* db, const char* sql, sqlite3_uint64 nsecs) {
// Note: This function is called in the thread pool.
// Note: Some queries, such as "EXPLAIN" queries, are not sent through this.
ProfileInfo* info = new ProfileInfo();
info->sql = std::string(sql);
info->nsecs = nsecs;
static_cast<Database*>(db)->debug_profile->send(info);
}
void Database::ProfileCallback(Database *db, ProfileInfo* info) {
NanScope();
Local<Value> argv[] = {
NanNew("profile"),
NanNew<String>(info->sql.c_str()),
NanNew<Integer>((double)info->nsecs / 1000000.0)
};
EMIT_EVENT(NanObjectWrapHandle(db), 3, argv);
delete info;
}
void Database::RegisterUpdateCallback(Baton* baton) {
assert(baton->db->open);
assert(baton->db->_handle);
Database* db = baton->db;
if (db->update_event == NULL) {
// Add it.
db->update_event = new AsyncUpdate(db, UpdateCallback);
sqlite3_update_hook(db->_handle, UpdateCallback, db);
}
else {
// Remove it.
sqlite3_update_hook(db->_handle, NULL, NULL);
db->update_event->finish();
db->update_event = NULL;
}
delete baton;
}
void Database::UpdateCallback(void* db, int type, const char* database,
const char* table, sqlite3_int64 rowid) {
// Note: This function is called in the thread pool.
// Note: Some queries, such as "EXPLAIN" queries, are not sent through this.
UpdateInfo* info = new UpdateInfo();
info->type = type;
info->database = std::string(database);
info->table = std::string(table);
info->rowid = rowid;
static_cast<Database*>(db)->update_event->send(info);
}
void Database::UpdateCallback(Database *db, UpdateInfo* info) {
NanScope();
Local<Value> argv[] = {
NanNew(sqlite_authorizer_string(info->type)),
NanNew<String>(info->database.c_str()),
NanNew<String>(info->table.c_str()),
NanNew<Integer>(info->rowid),
};
EMIT_EVENT(NanObjectWrapHandle(db), 4, argv);
delete info;
}
NAN_METHOD(Database::Exec) {
NanScope();
Database* db = ObjectWrap::Unwrap<Database>(args.This());
REQUIRE_ARGUMENT_STRING(0, sql);
OPTIONAL_ARGUMENT_FUNCTION(1, callback);
Baton* baton = new ExecBaton(db, callback, *sql);
db->Schedule(Work_BeginExec, baton, true);
NanReturnValue(args.This());
}
void Database::Work_BeginExec(Baton* baton) {
assert(baton->db->locked);
assert(baton->db->open);
assert(baton->db->_handle);
assert(baton->db->pending == 0);
int status = uv_queue_work(uv_default_loop(),
&baton->request, Work_Exec, (uv_after_work_cb)Work_AfterExec);
assert(status == 0);
}
void Database::Work_Exec(uv_work_t* req) {
ExecBaton* baton = static_cast<ExecBaton*>(req->data);
char* message = NULL;
baton->status = sqlite3_exec(
baton->db->_handle,
baton->sql.c_str(),
NULL,
NULL,
&message
);
if (baton->status != SQLITE_OK && message != NULL) {
baton->message = std::string(message);
sqlite3_free(message);
}
}
void Database::Work_AfterExec(uv_work_t* req) {
NanScope();
ExecBaton* baton = static_cast<ExecBaton*>(req->data);
Database* db = baton->db;
Local<Function> cb = NanNew(baton->callback);
if (baton->status != SQLITE_OK) {
EXCEPTION(NanNew<String>(baton->message.c_str()), baton->status, exception);
if (!cb.IsEmpty() && cb->IsFunction()) {
Local<Value> argv[] = { exception };
TRY_CATCH_CALL(NanObjectWrapHandle(db), cb, 1, argv);
}
else {
Local<Value> args[] = { NanNew("error"), exception };
EMIT_EVENT(NanObjectWrapHandle(db), 2, args);
}
}
else if (!cb.IsEmpty() && cb->IsFunction()) {
Local<Value> argv[] = { NanNew(NanNull()) };
TRY_CATCH_CALL(NanObjectWrapHandle(db), cb, 1, argv);
}
db->Process();
delete baton;
}
NAN_METHOD(Database::Wait) {
NanScope();
Database* db = ObjectWrap::Unwrap<Database>(args.This());
OPTIONAL_ARGUMENT_FUNCTION(0, callback);
Baton* baton = new Baton(db, callback);
db->Schedule(Work_Wait, baton, true);
NanReturnValue(args.This());
}
void Database::Work_Wait(Baton* baton) {
NanScope();
assert(baton->db->locked);
assert(baton->db->open);
assert(baton->db->_handle);
assert(baton->db->pending == 0);
Local<Function> cb = NanNew(baton->callback);
if (!cb.IsEmpty() && cb->IsFunction()) {
Local<Value> argv[] = { NanNew(NanNull()) };
TRY_CATCH_CALL(NanObjectWrapHandle(baton->db), cb, 1, argv);
}
baton->db->Process();
delete baton;
}
NAN_METHOD(Database::LoadExtension) {
NanScope();
Database* db = ObjectWrap::Unwrap<Database>(args.This());
REQUIRE_ARGUMENT_STRING(0, filename);
OPTIONAL_ARGUMENT_FUNCTION(1, callback);
Baton* baton = new LoadExtensionBaton(db, callback, *filename);
db->Schedule(Work_BeginLoadExtension, baton, true);
NanReturnValue(args.This());
}
void Database::Work_BeginLoadExtension(Baton* baton) {
assert(baton->db->locked);
assert(baton->db->open);
assert(baton->db->_handle);
assert(baton->db->pending == 0);
int status = uv_queue_work(uv_default_loop(),
&baton->request, Work_LoadExtension, (uv_after_work_cb)Work_AfterLoadExtension);
assert(status == 0);
}
void Database::Work_LoadExtension(uv_work_t* req) {
LoadExtensionBaton* baton = static_cast<LoadExtensionBaton*>(req->data);
sqlite3_enable_load_extension(baton->db->_handle, 1);
char* message = NULL;
baton->status = sqlite3_load_extension(
baton->db->_handle,
baton->filename.c_str(),
0,
&message
);
sqlite3_enable_load_extension(baton->db->_handle, 0);
if (baton->status != SQLITE_OK && message != NULL) {
baton->message = std::string(message);
sqlite3_free(message);
}
}
void Database::Work_AfterLoadExtension(uv_work_t* req) {
NanScope();
LoadExtensionBaton* baton = static_cast<LoadExtensionBaton*>(req->data);
Database* db = baton->db;
Local<Function> cb = NanNew(baton->callback);
if (baton->status != SQLITE_OK) {
EXCEPTION(NanNew<String>(baton->message.c_str()), baton->status, exception);
if (!cb.IsEmpty() && cb->IsFunction()) {
Local<Value> argv[] = { exception };
TRY_CATCH_CALL(NanObjectWrapHandle(db), cb, 1, argv);
}
else {
Local<Value> args[] = { NanNew("error"), exception };
EMIT_EVENT(NanObjectWrapHandle(db), 2, args);
}
}
else if (!cb.IsEmpty() && cb->IsFunction()) {
Local<Value> argv[] = { NanNew(NanNull()) };
TRY_CATCH_CALL(NanObjectWrapHandle(db), cb, 1, argv);
}
db->Process();
delete baton;
}
void Database::RemoveCallbacks() {
if (debug_trace) {
debug_trace->finish();
debug_trace = NULL;
}
if (debug_profile) {
debug_profile->finish();
debug_profile = NULL;
}
}
| diagonalfish/reddit-post-scheduler | web/node_modules/sqlite3/src/database.cc | C++ | mit | 18,996 |
/*
* IOMMU implementation for Cell Broadband Processor Architecture
*
* (C) Copyright IBM Corporation 2006-2008
*
* Author: Jeremy Kerr <jk@ozlabs.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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#undef DEBUG
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/slab.h>
#include <linux/memblock.h>
#include <asm/prom.h>
#include <asm/iommu.h>
#include <asm/machdep.h>
#include <asm/pci-bridge.h>
#include <asm/udbg.h>
#include <asm/firmware.h>
#include <asm/cell-regs.h>
#include "cell.h"
#include "interrupt.h"
/* Define CELL_IOMMU_REAL_UNMAP to actually unmap non-used pages
* instead of leaving them mapped to some dummy page. This can be
* enabled once the appropriate workarounds for spider bugs have
* been enabled
*/
#define CELL_IOMMU_REAL_UNMAP
/* Define CELL_IOMMU_STRICT_PROTECTION to enforce protection of
* IO PTEs based on the transfer direction. That can be enabled
* once spider-net has been fixed to pass the correct direction
* to the DMA mapping functions
*/
#define CELL_IOMMU_STRICT_PROTECTION
#define NR_IOMMUS 2
/* IOC mmap registers */
#define IOC_Reg_Size 0x2000
#define IOC_IOPT_CacheInvd 0x908
#define IOC_IOPT_CacheInvd_NE_Mask 0xffe0000000000000ul
#define IOC_IOPT_CacheInvd_IOPTE_Mask 0x000003fffffffff8ul
#define IOC_IOPT_CacheInvd_Busy 0x0000000000000001ul
#define IOC_IOST_Origin 0x918
#define IOC_IOST_Origin_E 0x8000000000000000ul
#define IOC_IOST_Origin_HW 0x0000000000000800ul
#define IOC_IOST_Origin_HL 0x0000000000000400ul
#define IOC_IO_ExcpStat 0x920
#define IOC_IO_ExcpStat_V 0x8000000000000000ul
#define IOC_IO_ExcpStat_SPF_Mask 0x6000000000000000ul
#define IOC_IO_ExcpStat_SPF_S 0x6000000000000000ul
#define IOC_IO_ExcpStat_SPF_P 0x2000000000000000ul
#define IOC_IO_ExcpStat_ADDR_Mask 0x00000007fffff000ul
#define IOC_IO_ExcpStat_RW_Mask 0x0000000000000800ul
#define IOC_IO_ExcpStat_IOID_Mask 0x00000000000007fful
#define IOC_IO_ExcpMask 0x928
#define IOC_IO_ExcpMask_SFE 0x4000000000000000ul
#define IOC_IO_ExcpMask_PFE 0x2000000000000000ul
#define IOC_IOCmd_Offset 0x1000
#define IOC_IOCmd_Cfg 0xc00
#define IOC_IOCmd_Cfg_TE 0x0000800000000000ul
/* Segment table entries */
#define IOSTE_V 0x8000000000000000ul /* valid */
#define IOSTE_H 0x4000000000000000ul /* cache hint */
#define IOSTE_PT_Base_RPN_Mask 0x3ffffffffffff000ul /* base RPN of IOPT */
#define IOSTE_NPPT_Mask 0x0000000000000fe0ul /* no. pages in IOPT */
#define IOSTE_PS_Mask 0x0000000000000007ul /* page size */
#define IOSTE_PS_4K 0x0000000000000001ul /* - 4kB */
#define IOSTE_PS_64K 0x0000000000000003ul /* - 64kB */
#define IOSTE_PS_1M 0x0000000000000005ul /* - 1MB */
#define IOSTE_PS_16M 0x0000000000000007ul /* - 16MB */
/* IOMMU sizing */
#define IO_SEGMENT_SHIFT 28
#define IO_PAGENO_BITS(shift) (IO_SEGMENT_SHIFT - (shift))
/* The high bit needs to be set on every DMA address */
#define SPIDER_DMA_OFFSET 0x80000000ul
struct iommu_window {
struct list_head list;
struct cbe_iommu *iommu;
unsigned long offset;
unsigned long size;
unsigned int ioid;
struct iommu_table table;
};
#define NAMESIZE 8
struct cbe_iommu {
int nid;
char name[NAMESIZE];
void __iomem *xlate_regs;
void __iomem *cmd_regs;
unsigned long *stab;
unsigned long *ptab;
void *pad_page;
struct list_head windows;
};
/* Static array of iommus, one per node
* each contains a list of windows, keyed from dma_window property
* - on bus setup, look for a matching window, or create one
* - on dev setup, assign iommu_table ptr
*/
static struct cbe_iommu iommus[NR_IOMMUS];
static int cbe_nr_iommus;
static void invalidate_tce_cache(struct cbe_iommu *iommu, unsigned long *pte,
long n_ptes)
{
u64 __iomem *reg;
u64 val;
long n;
reg = iommu->xlate_regs + IOC_IOPT_CacheInvd;
while (n_ptes > 0) {
/* we can invalidate up to 1 << 11 PTEs at once */
n = min(n_ptes, 1l << 11);
val = (((n /*- 1*/) << 53) & IOC_IOPT_CacheInvd_NE_Mask)
| (__pa(pte) & IOC_IOPT_CacheInvd_IOPTE_Mask)
| IOC_IOPT_CacheInvd_Busy;
out_be64(reg, val);
while (in_be64(reg) & IOC_IOPT_CacheInvd_Busy)
;
n_ptes -= n;
pte += n;
}
}
static int tce_build_cell(struct iommu_table *tbl, long index, long npages,
unsigned long uaddr, enum dma_data_direction direction,
unsigned long attrs)
{
int i;
unsigned long *io_pte, base_pte;
struct iommu_window *window =
container_of(tbl, struct iommu_window, table);
/* implementing proper protection causes problems with the spidernet
* driver - check mapping directions later, but allow read & write by
* default for now.*/
#ifdef CELL_IOMMU_STRICT_PROTECTION
/* to avoid referencing a global, we use a trick here to setup the
* protection bit. "prot" is setup to be 3 fields of 4 bits appended
* together for each of the 3 supported direction values. It is then
* shifted left so that the fields matching the desired direction
* lands on the appropriate bits, and other bits are masked out.
*/
const unsigned long prot = 0xc48;
base_pte =
((prot << (52 + 4 * direction)) &
(CBE_IOPTE_PP_W | CBE_IOPTE_PP_R)) |
CBE_IOPTE_M | CBE_IOPTE_SO_RW |
(window->ioid & CBE_IOPTE_IOID_Mask);
#else
base_pte = CBE_IOPTE_PP_W | CBE_IOPTE_PP_R | CBE_IOPTE_M |
CBE_IOPTE_SO_RW | (window->ioid & CBE_IOPTE_IOID_Mask);
#endif
if (unlikely(attrs & DMA_ATTR_WEAK_ORDERING))
base_pte &= ~CBE_IOPTE_SO_RW;
io_pte = (unsigned long *)tbl->it_base + (index - tbl->it_offset);
for (i = 0; i < npages; i++, uaddr += (1 << tbl->it_page_shift))
io_pte[i] = base_pte | (__pa(uaddr) & CBE_IOPTE_RPN_Mask);
mb();
invalidate_tce_cache(window->iommu, io_pte, npages);
pr_debug("tce_build_cell(index=%lx,n=%lx,dir=%d,base_pte=%lx)\n",
index, npages, direction, base_pte);
return 0;
}
static void tce_free_cell(struct iommu_table *tbl, long index, long npages)
{
int i;
unsigned long *io_pte, pte;
struct iommu_window *window =
container_of(tbl, struct iommu_window, table);
pr_debug("tce_free_cell(index=%lx,n=%lx)\n", index, npages);
#ifdef CELL_IOMMU_REAL_UNMAP
pte = 0;
#else
/* spider bridge does PCI reads after freeing - insert a mapping
* to a scratch page instead of an invalid entry */
pte = CBE_IOPTE_PP_R | CBE_IOPTE_M | CBE_IOPTE_SO_RW |
__pa(window->iommu->pad_page) |
(window->ioid & CBE_IOPTE_IOID_Mask);
#endif
io_pte = (unsigned long *)tbl->it_base + (index - tbl->it_offset);
for (i = 0; i < npages; i++)
io_pte[i] = pte;
mb();
invalidate_tce_cache(window->iommu, io_pte, npages);
}
static irqreturn_t ioc_interrupt(int irq, void *data)
{
unsigned long stat, spf;
struct cbe_iommu *iommu = data;
stat = in_be64(iommu->xlate_regs + IOC_IO_ExcpStat);
spf = stat & IOC_IO_ExcpStat_SPF_Mask;
/* Might want to rate limit it */
printk(KERN_ERR "iommu: DMA exception 0x%016lx\n", stat);
printk(KERN_ERR " V=%d, SPF=[%c%c], RW=%s, IOID=0x%04x\n",
!!(stat & IOC_IO_ExcpStat_V),
(spf == IOC_IO_ExcpStat_SPF_S) ? 'S' : ' ',
(spf == IOC_IO_ExcpStat_SPF_P) ? 'P' : ' ',
(stat & IOC_IO_ExcpStat_RW_Mask) ? "Read" : "Write",
(unsigned int)(stat & IOC_IO_ExcpStat_IOID_Mask));
printk(KERN_ERR " page=0x%016lx\n",
stat & IOC_IO_ExcpStat_ADDR_Mask);
/* clear interrupt */
stat &= ~IOC_IO_ExcpStat_V;
out_be64(iommu->xlate_regs + IOC_IO_ExcpStat, stat);
return IRQ_HANDLED;
}
static int cell_iommu_find_ioc(int nid, unsigned long *base)
{
struct device_node *np;
struct resource r;
*base = 0;
/* First look for new style /be nodes */
for_each_node_by_name(np, "ioc") {
if (of_node_to_nid(np) != nid)
continue;
if (of_address_to_resource(np, 0, &r)) {
printk(KERN_ERR "iommu: can't get address for %pOF\n",
np);
continue;
}
*base = r.start;
of_node_put(np);
return 0;
}
/* Ok, let's try the old way */
for_each_node_by_type(np, "cpu") {
const unsigned int *nidp;
const unsigned long *tmp;
nidp = of_get_property(np, "node-id", NULL);
if (nidp && *nidp == nid) {
tmp = of_get_property(np, "ioc-translation", NULL);
if (tmp) {
*base = *tmp;
of_node_put(np);
return 0;
}
}
}
return -ENODEV;
}
static void cell_iommu_setup_stab(struct cbe_iommu *iommu,
unsigned long dbase, unsigned long dsize,
unsigned long fbase, unsigned long fsize)
{
struct page *page;
unsigned long segments, stab_size;
segments = max(dbase + dsize, fbase + fsize) >> IO_SEGMENT_SHIFT;
pr_debug("%s: iommu[%d]: segments: %lu\n",
__func__, iommu->nid, segments);
/* set up the segment table */
stab_size = segments * sizeof(unsigned long);
page = alloc_pages_node(iommu->nid, GFP_KERNEL, get_order(stab_size));
BUG_ON(!page);
iommu->stab = page_address(page);
memset(iommu->stab, 0, stab_size);
}
static unsigned long *cell_iommu_alloc_ptab(struct cbe_iommu *iommu,
unsigned long base, unsigned long size, unsigned long gap_base,
unsigned long gap_size, unsigned long page_shift)
{
struct page *page;
int i;
unsigned long reg, segments, pages_per_segment, ptab_size,
n_pte_pages, start_seg, *ptab;
start_seg = base >> IO_SEGMENT_SHIFT;
segments = size >> IO_SEGMENT_SHIFT;
pages_per_segment = 1ull << IO_PAGENO_BITS(page_shift);
/* PTEs for each segment must start on a 4K boundary */
pages_per_segment = max(pages_per_segment,
(1 << 12) / sizeof(unsigned long));
ptab_size = segments * pages_per_segment * sizeof(unsigned long);
pr_debug("%s: iommu[%d]: ptab_size: %lu, order: %d\n", __func__,
iommu->nid, ptab_size, get_order(ptab_size));
page = alloc_pages_node(iommu->nid, GFP_KERNEL, get_order(ptab_size));
BUG_ON(!page);
ptab = page_address(page);
memset(ptab, 0, ptab_size);
/* number of 4K pages needed for a page table */
n_pte_pages = (pages_per_segment * sizeof(unsigned long)) >> 12;
pr_debug("%s: iommu[%d]: stab at %p, ptab at %p, n_pte_pages: %lu\n",
__func__, iommu->nid, iommu->stab, ptab,
n_pte_pages);
/* initialise the STEs */
reg = IOSTE_V | ((n_pte_pages - 1) << 5);
switch (page_shift) {
case 12: reg |= IOSTE_PS_4K; break;
case 16: reg |= IOSTE_PS_64K; break;
case 20: reg |= IOSTE_PS_1M; break;
case 24: reg |= IOSTE_PS_16M; break;
default: BUG();
}
gap_base = gap_base >> IO_SEGMENT_SHIFT;
gap_size = gap_size >> IO_SEGMENT_SHIFT;
pr_debug("Setting up IOMMU stab:\n");
for (i = start_seg; i < (start_seg + segments); i++) {
if (i >= gap_base && i < (gap_base + gap_size)) {
pr_debug("\toverlap at %d, skipping\n", i);
continue;
}
iommu->stab[i] = reg | (__pa(ptab) + (n_pte_pages << 12) *
(i - start_seg));
pr_debug("\t[%d] 0x%016lx\n", i, iommu->stab[i]);
}
return ptab;
}
static void cell_iommu_enable_hardware(struct cbe_iommu *iommu)
{
int ret;
unsigned long reg, xlate_base;
unsigned int virq;
if (cell_iommu_find_ioc(iommu->nid, &xlate_base))
panic("%s: missing IOC register mappings for node %d\n",
__func__, iommu->nid);
iommu->xlate_regs = ioremap(xlate_base, IOC_Reg_Size);
iommu->cmd_regs = iommu->xlate_regs + IOC_IOCmd_Offset;
/* ensure that the STEs have updated */
mb();
/* setup interrupts for the iommu. */
reg = in_be64(iommu->xlate_regs + IOC_IO_ExcpStat);
out_be64(iommu->xlate_regs + IOC_IO_ExcpStat,
reg & ~IOC_IO_ExcpStat_V);
out_be64(iommu->xlate_regs + IOC_IO_ExcpMask,
IOC_IO_ExcpMask_PFE | IOC_IO_ExcpMask_SFE);
virq = irq_create_mapping(NULL,
IIC_IRQ_IOEX_ATI | (iommu->nid << IIC_IRQ_NODE_SHIFT));
BUG_ON(!virq);
ret = request_irq(virq, ioc_interrupt, 0, iommu->name, iommu);
BUG_ON(ret);
/* set the IOC segment table origin register (and turn on the iommu) */
reg = IOC_IOST_Origin_E | __pa(iommu->stab) | IOC_IOST_Origin_HW;
out_be64(iommu->xlate_regs + IOC_IOST_Origin, reg);
in_be64(iommu->xlate_regs + IOC_IOST_Origin);
/* turn on IO translation */
reg = in_be64(iommu->cmd_regs + IOC_IOCmd_Cfg) | IOC_IOCmd_Cfg_TE;
out_be64(iommu->cmd_regs + IOC_IOCmd_Cfg, reg);
}
static void cell_iommu_setup_hardware(struct cbe_iommu *iommu,
unsigned long base, unsigned long size)
{
cell_iommu_setup_stab(iommu, base, size, 0, 0);
iommu->ptab = cell_iommu_alloc_ptab(iommu, base, size, 0, 0,
IOMMU_PAGE_SHIFT_4K);
cell_iommu_enable_hardware(iommu);
}
#if 0/* Unused for now */
static struct iommu_window *find_window(struct cbe_iommu *iommu,
unsigned long offset, unsigned long size)
{
struct iommu_window *window;
/* todo: check for overlapping (but not equal) windows) */
list_for_each_entry(window, &(iommu->windows), list) {
if (window->offset == offset && window->size == size)
return window;
}
return NULL;
}
#endif
static inline u32 cell_iommu_get_ioid(struct device_node *np)
{
const u32 *ioid;
ioid = of_get_property(np, "ioid", NULL);
if (ioid == NULL) {
printk(KERN_WARNING "iommu: missing ioid for %pOF using 0\n",
np);
return 0;
}
return *ioid;
}
static struct iommu_table_ops cell_iommu_ops = {
.set = tce_build_cell,
.clear = tce_free_cell
};
static struct iommu_window * __init
cell_iommu_setup_window(struct cbe_iommu *iommu, struct device_node *np,
unsigned long offset, unsigned long size,
unsigned long pte_offset)
{
struct iommu_window *window;
struct page *page;
u32 ioid;
ioid = cell_iommu_get_ioid(np);
window = kzalloc_node(sizeof(*window), GFP_KERNEL, iommu->nid);
BUG_ON(window == NULL);
window->offset = offset;
window->size = size;
window->ioid = ioid;
window->iommu = iommu;
window->table.it_blocksize = 16;
window->table.it_base = (unsigned long)iommu->ptab;
window->table.it_index = iommu->nid;
window->table.it_page_shift = IOMMU_PAGE_SHIFT_4K;
window->table.it_offset =
(offset >> window->table.it_page_shift) + pte_offset;
window->table.it_size = size >> window->table.it_page_shift;
window->table.it_ops = &cell_iommu_ops;
iommu_init_table(&window->table, iommu->nid);
pr_debug("\tioid %d\n", window->ioid);
pr_debug("\tblocksize %ld\n", window->table.it_blocksize);
pr_debug("\tbase 0x%016lx\n", window->table.it_base);
pr_debug("\toffset 0x%lx\n", window->table.it_offset);
pr_debug("\tsize %ld\n", window->table.it_size);
list_add(&window->list, &iommu->windows);
if (offset != 0)
return window;
/* We need to map and reserve the first IOMMU page since it's used
* by the spider workaround. In theory, we only need to do that when
* running on spider but it doesn't really matter.
*
* This code also assumes that we have a window that starts at 0,
* which is the case on all spider based blades.
*/
page = alloc_pages_node(iommu->nid, GFP_KERNEL, 0);
BUG_ON(!page);
iommu->pad_page = page_address(page);
clear_page(iommu->pad_page);
__set_bit(0, window->table.it_map);
tce_build_cell(&window->table, window->table.it_offset, 1,
(unsigned long)iommu->pad_page, DMA_TO_DEVICE, 0);
return window;
}
static struct cbe_iommu *cell_iommu_for_node(int nid)
{
int i;
for (i = 0; i < cbe_nr_iommus; i++)
if (iommus[i].nid == nid)
return &iommus[i];
return NULL;
}
static unsigned long cell_dma_nommu_offset;
static unsigned long dma_iommu_fixed_base;
/* iommu_fixed_is_weak is set if booted with iommu_fixed=weak */
static int iommu_fixed_is_weak;
static struct iommu_table *cell_get_iommu_table(struct device *dev)
{
struct iommu_window *window;
struct cbe_iommu *iommu;
/* Current implementation uses the first window available in that
* node's iommu. We -might- do something smarter later though it may
* never be necessary
*/
iommu = cell_iommu_for_node(dev_to_node(dev));
if (iommu == NULL || list_empty(&iommu->windows)) {
dev_err(dev, "iommu: missing iommu for %pOF (node %d)\n",
dev->of_node, dev_to_node(dev));
return NULL;
}
window = list_entry(iommu->windows.next, struct iommu_window, list);
return &window->table;
}
/* A coherent allocation implies strong ordering */
static void *dma_fixed_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t flag,
unsigned long attrs)
{
if (iommu_fixed_is_weak)
return iommu_alloc_coherent(dev, cell_get_iommu_table(dev),
size, dma_handle,
device_to_mask(dev), flag,
dev_to_node(dev));
else
return dma_nommu_ops.alloc(dev, size, dma_handle, flag,
attrs);
}
static void dma_fixed_free_coherent(struct device *dev, size_t size,
void *vaddr, dma_addr_t dma_handle,
unsigned long attrs)
{
if (iommu_fixed_is_weak)
iommu_free_coherent(cell_get_iommu_table(dev), size, vaddr,
dma_handle);
else
dma_nommu_ops.free(dev, size, vaddr, dma_handle, attrs);
}
static dma_addr_t dma_fixed_map_page(struct device *dev, struct page *page,
unsigned long offset, size_t size,
enum dma_data_direction direction,
unsigned long attrs)
{
if (iommu_fixed_is_weak == (attrs & DMA_ATTR_WEAK_ORDERING))
return dma_nommu_ops.map_page(dev, page, offset, size,
direction, attrs);
else
return iommu_map_page(dev, cell_get_iommu_table(dev), page,
offset, size, device_to_mask(dev),
direction, attrs);
}
static void dma_fixed_unmap_page(struct device *dev, dma_addr_t dma_addr,
size_t size, enum dma_data_direction direction,
unsigned long attrs)
{
if (iommu_fixed_is_weak == (attrs & DMA_ATTR_WEAK_ORDERING))
dma_nommu_ops.unmap_page(dev, dma_addr, size, direction,
attrs);
else
iommu_unmap_page(cell_get_iommu_table(dev), dma_addr, size,
direction, attrs);
}
static int dma_fixed_map_sg(struct device *dev, struct scatterlist *sg,
int nents, enum dma_data_direction direction,
unsigned long attrs)
{
if (iommu_fixed_is_weak == (attrs & DMA_ATTR_WEAK_ORDERING))
return dma_nommu_ops.map_sg(dev, sg, nents, direction, attrs);
else
return ppc_iommu_map_sg(dev, cell_get_iommu_table(dev), sg,
nents, device_to_mask(dev),
direction, attrs);
}
static void dma_fixed_unmap_sg(struct device *dev, struct scatterlist *sg,
int nents, enum dma_data_direction direction,
unsigned long attrs)
{
if (iommu_fixed_is_weak == (attrs & DMA_ATTR_WEAK_ORDERING))
dma_nommu_ops.unmap_sg(dev, sg, nents, direction, attrs);
else
ppc_iommu_unmap_sg(cell_get_iommu_table(dev), sg, nents,
direction, attrs);
}
static int dma_suported_and_switch(struct device *dev, u64 dma_mask);
static const struct dma_map_ops dma_iommu_fixed_ops = {
.alloc = dma_fixed_alloc_coherent,
.free = dma_fixed_free_coherent,
.map_sg = dma_fixed_map_sg,
.unmap_sg = dma_fixed_unmap_sg,
.dma_supported = dma_suported_and_switch,
.map_page = dma_fixed_map_page,
.unmap_page = dma_fixed_unmap_page,
.mapping_error = dma_iommu_mapping_error,
};
static void cell_dma_dev_setup(struct device *dev)
{
if (get_pci_dma_ops() == &dma_iommu_ops)
set_iommu_table_base(dev, cell_get_iommu_table(dev));
else if (get_pci_dma_ops() == &dma_nommu_ops)
set_dma_offset(dev, cell_dma_nommu_offset);
else
BUG();
}
static void cell_pci_dma_dev_setup(struct pci_dev *dev)
{
cell_dma_dev_setup(&dev->dev);
}
static int cell_of_bus_notify(struct notifier_block *nb, unsigned long action,
void *data)
{
struct device *dev = data;
/* We are only intereted in device addition */
if (action != BUS_NOTIFY_ADD_DEVICE)
return 0;
/* We use the PCI DMA ops */
dev->dma_ops = get_pci_dma_ops();
cell_dma_dev_setup(dev);
return 0;
}
static struct notifier_block cell_of_bus_notifier = {
.notifier_call = cell_of_bus_notify
};
static int __init cell_iommu_get_window(struct device_node *np,
unsigned long *base,
unsigned long *size)
{
const __be32 *dma_window;
unsigned long index;
/* Use ibm,dma-window if available, else, hard code ! */
dma_window = of_get_property(np, "ibm,dma-window", NULL);
if (dma_window == NULL) {
*base = 0;
*size = 0x80000000u;
return -ENODEV;
}
of_parse_dma_window(np, dma_window, &index, base, size);
return 0;
}
static struct cbe_iommu * __init cell_iommu_alloc(struct device_node *np)
{
struct cbe_iommu *iommu;
int nid, i;
/* Get node ID */
nid = of_node_to_nid(np);
if (nid < 0) {
printk(KERN_ERR "iommu: failed to get node for %pOF\n",
np);
return NULL;
}
pr_debug("iommu: setting up iommu for node %d (%pOF)\n",
nid, np);
/* XXX todo: If we can have multiple windows on the same IOMMU, which
* isn't the case today, we probably want here to check whether the
* iommu for that node is already setup.
* However, there might be issue with getting the size right so let's
* ignore that for now. We might want to completely get rid of the
* multiple window support since the cell iommu supports per-page ioids
*/
if (cbe_nr_iommus >= NR_IOMMUS) {
printk(KERN_ERR "iommu: too many IOMMUs detected ! (%pOF)\n",
np);
return NULL;
}
/* Init base fields */
i = cbe_nr_iommus++;
iommu = &iommus[i];
iommu->stab = NULL;
iommu->nid = nid;
snprintf(iommu->name, sizeof(iommu->name), "iommu%d", i);
INIT_LIST_HEAD(&iommu->windows);
return iommu;
}
static void __init cell_iommu_init_one(struct device_node *np,
unsigned long offset)
{
struct cbe_iommu *iommu;
unsigned long base, size;
iommu = cell_iommu_alloc(np);
if (!iommu)
return;
/* Obtain a window for it */
cell_iommu_get_window(np, &base, &size);
pr_debug("\ttranslating window 0x%lx...0x%lx\n",
base, base + size - 1);
/* Initialize the hardware */
cell_iommu_setup_hardware(iommu, base, size);
/* Setup the iommu_table */
cell_iommu_setup_window(iommu, np, base, size,
offset >> IOMMU_PAGE_SHIFT_4K);
}
static void __init cell_disable_iommus(void)
{
int node;
unsigned long base, val;
void __iomem *xregs, *cregs;
/* Make sure IOC translation is disabled on all nodes */
for_each_online_node(node) {
if (cell_iommu_find_ioc(node, &base))
continue;
xregs = ioremap(base, IOC_Reg_Size);
if (xregs == NULL)
continue;
cregs = xregs + IOC_IOCmd_Offset;
pr_debug("iommu: cleaning up iommu on node %d\n", node);
out_be64(xregs + IOC_IOST_Origin, 0);
(void)in_be64(xregs + IOC_IOST_Origin);
val = in_be64(cregs + IOC_IOCmd_Cfg);
val &= ~IOC_IOCmd_Cfg_TE;
out_be64(cregs + IOC_IOCmd_Cfg, val);
(void)in_be64(cregs + IOC_IOCmd_Cfg);
iounmap(xregs);
}
}
static int __init cell_iommu_init_disabled(void)
{
struct device_node *np = NULL;
unsigned long base = 0, size;
/* When no iommu is present, we use direct DMA ops */
set_pci_dma_ops(&dma_nommu_ops);
/* First make sure all IOC translation is turned off */
cell_disable_iommus();
/* If we have no Axon, we set up the spider DMA magic offset */
if (of_find_node_by_name(NULL, "axon") == NULL)
cell_dma_nommu_offset = SPIDER_DMA_OFFSET;
/* Now we need to check to see where the memory is mapped
* in PCI space. We assume that all busses use the same dma
* window which is always the case so far on Cell, thus we
* pick up the first pci-internal node we can find and check
* the DMA window from there.
*/
for_each_node_by_name(np, "axon") {
if (np->parent == NULL || np->parent->parent != NULL)
continue;
if (cell_iommu_get_window(np, &base, &size) == 0)
break;
}
if (np == NULL) {
for_each_node_by_name(np, "pci-internal") {
if (np->parent == NULL || np->parent->parent != NULL)
continue;
if (cell_iommu_get_window(np, &base, &size) == 0)
break;
}
}
of_node_put(np);
/* If we found a DMA window, we check if it's big enough to enclose
* all of physical memory. If not, we force enable IOMMU
*/
if (np && size < memblock_end_of_DRAM()) {
printk(KERN_WARNING "iommu: force-enabled, dma window"
" (%ldMB) smaller than total memory (%lldMB)\n",
size >> 20, memblock_end_of_DRAM() >> 20);
return -ENODEV;
}
cell_dma_nommu_offset += base;
if (cell_dma_nommu_offset != 0)
cell_pci_controller_ops.dma_dev_setup = cell_pci_dma_dev_setup;
printk("iommu: disabled, direct DMA offset is 0x%lx\n",
cell_dma_nommu_offset);
return 0;
}
/*
* Fixed IOMMU mapping support
*
* This code adds support for setting up a fixed IOMMU mapping on certain
* cell machines. For 64-bit devices this avoids the performance overhead of
* mapping and unmapping pages at runtime. 32-bit devices are unable to use
* the fixed mapping.
*
* The fixed mapping is established at boot, and maps all of physical memory
* 1:1 into device space at some offset. On machines with < 30 GB of memory
* we setup the fixed mapping immediately above the normal IOMMU window.
*
* For example a machine with 4GB of memory would end up with the normal
* IOMMU window from 0-2GB and the fixed mapping window from 2GB to 6GB. In
* this case a 64-bit device wishing to DMA to 1GB would be told to DMA to
* 3GB, plus any offset required by firmware. The firmware offset is encoded
* in the "dma-ranges" property.
*
* On machines with 30GB or more of memory, we are unable to place the fixed
* mapping above the normal IOMMU window as we would run out of address space.
* Instead we move the normal IOMMU window to coincide with the hash page
* table, this region does not need to be part of the fixed mapping as no
* device should ever be DMA'ing to it. We then setup the fixed mapping
* from 0 to 32GB.
*/
static u64 cell_iommu_get_fixed_address(struct device *dev)
{
u64 cpu_addr, size, best_size, dev_addr = OF_BAD_ADDR;
struct device_node *np;
const u32 *ranges = NULL;
int i, len, best, naddr, nsize, pna, range_size;
np = of_node_get(dev->of_node);
while (1) {
naddr = of_n_addr_cells(np);
nsize = of_n_size_cells(np);
np = of_get_next_parent(np);
if (!np)
break;
ranges = of_get_property(np, "dma-ranges", &len);
/* Ignore empty ranges, they imply no translation required */
if (ranges && len > 0)
break;
}
if (!ranges) {
dev_dbg(dev, "iommu: no dma-ranges found\n");
goto out;
}
len /= sizeof(u32);
pna = of_n_addr_cells(np);
range_size = naddr + nsize + pna;
/* dma-ranges format:
* child addr : naddr cells
* parent addr : pna cells
* size : nsize cells
*/
for (i = 0, best = -1, best_size = 0; i < len; i += range_size) {
cpu_addr = of_translate_dma_address(np, ranges + i + naddr);
size = of_read_number(ranges + i + naddr + pna, nsize);
if (cpu_addr == 0 && size > best_size) {
best = i;
best_size = size;
}
}
if (best >= 0) {
dev_addr = of_read_number(ranges + best, naddr);
} else
dev_dbg(dev, "iommu: no suitable range found!\n");
out:
of_node_put(np);
return dev_addr;
}
static int dma_suported_and_switch(struct device *dev, u64 dma_mask)
{
if (dma_mask == DMA_BIT_MASK(64) &&
cell_iommu_get_fixed_address(dev) != OF_BAD_ADDR) {
u64 addr = cell_iommu_get_fixed_address(dev) +
dma_iommu_fixed_base;
dev_dbg(dev, "iommu: 64-bit OK, using fixed ops\n");
dev_dbg(dev, "iommu: fixed addr = %llx\n", addr);
set_dma_ops(dev, &dma_iommu_fixed_ops);
set_dma_offset(dev, addr);
return 1;
}
if (dma_iommu_dma_supported(dev, dma_mask)) {
dev_dbg(dev, "iommu: not 64-bit, using default ops\n");
set_dma_ops(dev, get_pci_dma_ops());
cell_dma_dev_setup(dev);
return 1;
}
return 0;
}
static void insert_16M_pte(unsigned long addr, unsigned long *ptab,
unsigned long base_pte)
{
unsigned long segment, offset;
segment = addr >> IO_SEGMENT_SHIFT;
offset = (addr >> 24) - (segment << IO_PAGENO_BITS(24));
ptab = ptab + (segment * (1 << 12) / sizeof(unsigned long));
pr_debug("iommu: addr %lx ptab %p segment %lx offset %lx\n",
addr, ptab, segment, offset);
ptab[offset] = base_pte | (__pa(addr) & CBE_IOPTE_RPN_Mask);
}
static void cell_iommu_setup_fixed_ptab(struct cbe_iommu *iommu,
struct device_node *np, unsigned long dbase, unsigned long dsize,
unsigned long fbase, unsigned long fsize)
{
unsigned long base_pte, uaddr, ioaddr, *ptab;
ptab = cell_iommu_alloc_ptab(iommu, fbase, fsize, dbase, dsize, 24);
dma_iommu_fixed_base = fbase;
pr_debug("iommu: mapping 0x%lx pages from 0x%lx\n", fsize, fbase);
base_pte = CBE_IOPTE_PP_W | CBE_IOPTE_PP_R | CBE_IOPTE_M |
(cell_iommu_get_ioid(np) & CBE_IOPTE_IOID_Mask);
if (iommu_fixed_is_weak)
pr_info("IOMMU: Using weak ordering for fixed mapping\n");
else {
pr_info("IOMMU: Using strong ordering for fixed mapping\n");
base_pte |= CBE_IOPTE_SO_RW;
}
for (uaddr = 0; uaddr < fsize; uaddr += (1 << 24)) {
/* Don't touch the dynamic region */
ioaddr = uaddr + fbase;
if (ioaddr >= dbase && ioaddr < (dbase + dsize)) {
pr_debug("iommu: fixed/dynamic overlap, skipping\n");
continue;
}
insert_16M_pte(uaddr, ptab, base_pte);
}
mb();
}
static int __init cell_iommu_fixed_mapping_init(void)
{
unsigned long dbase, dsize, fbase, fsize, hbase, hend;
struct cbe_iommu *iommu;
struct device_node *np;
/* The fixed mapping is only supported on axon machines */
np = of_find_node_by_name(NULL, "axon");
of_node_put(np);
if (!np) {
pr_debug("iommu: fixed mapping disabled, no axons found\n");
return -1;
}
/* We must have dma-ranges properties for fixed mapping to work */
np = of_find_node_with_property(NULL, "dma-ranges");
of_node_put(np);
if (!np) {
pr_debug("iommu: no dma-ranges found, no fixed mapping\n");
return -1;
}
/* The default setup is to have the fixed mapping sit after the
* dynamic region, so find the top of the largest IOMMU window
* on any axon, then add the size of RAM and that's our max value.
* If that is > 32GB we have to do other shennanigans.
*/
fbase = 0;
for_each_node_by_name(np, "axon") {
cell_iommu_get_window(np, &dbase, &dsize);
fbase = max(fbase, dbase + dsize);
}
fbase = _ALIGN_UP(fbase, 1 << IO_SEGMENT_SHIFT);
fsize = memblock_phys_mem_size();
if ((fbase + fsize) <= 0x800000000ul)
hbase = 0; /* use the device tree window */
else {
/* If we're over 32 GB we need to cheat. We can't map all of
* RAM with the fixed mapping, and also fit the dynamic
* region. So try to place the dynamic region where the hash
* table sits, drivers never need to DMA to it, we don't
* need a fixed mapping for that area.
*/
if (!htab_address) {
pr_debug("iommu: htab is NULL, on LPAR? Huh?\n");
return -1;
}
hbase = __pa(htab_address);
hend = hbase + htab_size_bytes;
/* The window must start and end on a segment boundary */
if ((hbase != _ALIGN_UP(hbase, 1 << IO_SEGMENT_SHIFT)) ||
(hend != _ALIGN_UP(hend, 1 << IO_SEGMENT_SHIFT))) {
pr_debug("iommu: hash window not segment aligned\n");
return -1;
}
/* Check the hash window fits inside the real DMA window */
for_each_node_by_name(np, "axon") {
cell_iommu_get_window(np, &dbase, &dsize);
if (hbase < dbase || (hend > (dbase + dsize))) {
pr_debug("iommu: hash window doesn't fit in"
"real DMA window\n");
return -1;
}
}
fbase = 0;
}
/* Setup the dynamic regions */
for_each_node_by_name(np, "axon") {
iommu = cell_iommu_alloc(np);
BUG_ON(!iommu);
if (hbase == 0)
cell_iommu_get_window(np, &dbase, &dsize);
else {
dbase = hbase;
dsize = htab_size_bytes;
}
printk(KERN_DEBUG "iommu: node %d, dynamic window 0x%lx-0x%lx "
"fixed window 0x%lx-0x%lx\n", iommu->nid, dbase,
dbase + dsize, fbase, fbase + fsize);
cell_iommu_setup_stab(iommu, dbase, dsize, fbase, fsize);
iommu->ptab = cell_iommu_alloc_ptab(iommu, dbase, dsize, 0, 0,
IOMMU_PAGE_SHIFT_4K);
cell_iommu_setup_fixed_ptab(iommu, np, dbase, dsize,
fbase, fsize);
cell_iommu_enable_hardware(iommu);
cell_iommu_setup_window(iommu, np, dbase, dsize, 0);
}
dma_iommu_ops.dma_supported = dma_suported_and_switch;
set_pci_dma_ops(&dma_iommu_ops);
return 0;
}
static int iommu_fixed_disabled;
static int __init setup_iommu_fixed(char *str)
{
struct device_node *pciep;
if (strcmp(str, "off") == 0)
iommu_fixed_disabled = 1;
/* If we can find a pcie-endpoint in the device tree assume that
* we're on a triblade or a CAB so by default the fixed mapping
* should be set to be weakly ordered; but only if the boot
* option WASN'T set for strong ordering
*/
pciep = of_find_node_by_type(NULL, "pcie-endpoint");
if (strcmp(str, "weak") == 0 || (pciep && strcmp(str, "strong") != 0))
iommu_fixed_is_weak = DMA_ATTR_WEAK_ORDERING;
of_node_put(pciep);
return 1;
}
__setup("iommu_fixed=", setup_iommu_fixed);
static u64 cell_dma_get_required_mask(struct device *dev)
{
const struct dma_map_ops *dma_ops;
if (!dev->dma_mask)
return 0;
if (!iommu_fixed_disabled &&
cell_iommu_get_fixed_address(dev) != OF_BAD_ADDR)
return DMA_BIT_MASK(64);
dma_ops = get_dma_ops(dev);
if (dma_ops->get_required_mask)
return dma_ops->get_required_mask(dev);
WARN_ONCE(1, "no get_required_mask in %p ops", dma_ops);
return DMA_BIT_MASK(64);
}
static int __init cell_iommu_init(void)
{
struct device_node *np;
/* If IOMMU is disabled or we have little enough RAM to not need
* to enable it, we setup a direct mapping.
*
* Note: should we make sure we have the IOMMU actually disabled ?
*/
if (iommu_is_off ||
(!iommu_force_on && memblock_end_of_DRAM() <= 0x80000000ull))
if (cell_iommu_init_disabled() == 0)
goto bail;
/* Setup various callbacks */
cell_pci_controller_ops.dma_dev_setup = cell_pci_dma_dev_setup;
ppc_md.dma_get_required_mask = cell_dma_get_required_mask;
if (!iommu_fixed_disabled && cell_iommu_fixed_mapping_init() == 0)
goto bail;
/* Create an iommu for each /axon node. */
for_each_node_by_name(np, "axon") {
if (np->parent == NULL || np->parent->parent != NULL)
continue;
cell_iommu_init_one(np, 0);
}
/* Create an iommu for each toplevel /pci-internal node for
* old hardware/firmware
*/
for_each_node_by_name(np, "pci-internal") {
if (np->parent == NULL || np->parent->parent != NULL)
continue;
cell_iommu_init_one(np, SPIDER_DMA_OFFSET);
}
/* Setup default PCI iommu ops */
set_pci_dma_ops(&dma_iommu_ops);
bail:
/* Register callbacks on OF platform device addition/removal
* to handle linking them to the right DMA operations
*/
bus_register_notifier(&platform_bus_type, &cell_of_bus_notifier);
return 0;
}
machine_arch_initcall(cell, cell_iommu_init);
| BPI-SINOVOIP/BPI-Mainline-kernel | linux-4.19/arch/powerpc/platforms/cell/iommu.c | C | gpl-2.0 | 34,916 |
/*
* Copyright (C) 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
*/
/*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
/*!
* @file km_adaptor.c
*
* @brief The Adaptor component provides an interface to the
* driver for a kernel user.
*/
#include <adaptor.h>
#include <sf_util.h>
#include <sah_queue_manager.h>
#include <sah_memory_mapper.h>
#include <fsl_shw_keystore.h>
#ifdef FSL_HAVE_SCC
#include <linux/mxc_scc_driver.h>
#elif defined (FSL_HAVE_SCC2)
#include <linux/mxc_scc2_driver.h>
#endif
EXPORT_SYMBOL(adaptor_Exec_Descriptor_Chain);
EXPORT_SYMBOL(sah_register);
EXPORT_SYMBOL(sah_deregister);
EXPORT_SYMBOL(sah_get_results);
EXPORT_SYMBOL(fsl_shw_smalloc);
EXPORT_SYMBOL(fsl_shw_sfree);
EXPORT_SYMBOL(fsl_shw_sstatus);
EXPORT_SYMBOL(fsl_shw_diminish_perms);
EXPORT_SYMBOL(do_scc_encrypt_region);
EXPORT_SYMBOL(do_scc_decrypt_region);
EXPORT_SYMBOL(do_system_keystore_slot_alloc);
EXPORT_SYMBOL(do_system_keystore_slot_dealloc);
EXPORT_SYMBOL(do_system_keystore_slot_load);
EXPORT_SYMBOL(do_system_keystore_slot_read);
EXPORT_SYMBOL(do_system_keystore_slot_encrypt);
EXPORT_SYMBOL(do_system_keystore_slot_decrypt);
#if defined(DIAG_DRV_IF) || defined(DIAG_MEM) || defined(DIAG_ADAPTOR)
#include <diagnostic.h>
#endif
#if defined(DIAG_DRV_IF) || defined(DIAG_MEM) || defined(DIAG_ADAPTOR)
#define MAX_DUMP 16
#define DIAG_MSG_SIZE 300
static char Diag_msg[DIAG_MSG_SIZE];
#endif
/* This is the wait queue to this mode of driver */
DECLARE_WAIT_QUEUE_HEAD(Wait_queue_km);
/*! This matches Sahara2 capabilities... */
fsl_shw_pco_t sahara2_capabilities = {
1, 3, /* api version number - major & minor */
1, 6, /* driver version number - major & minor */
{
FSL_KEY_ALG_AES,
FSL_KEY_ALG_DES,
FSL_KEY_ALG_TDES,
FSL_KEY_ALG_ARC4},
{
FSL_SYM_MODE_STREAM,
FSL_SYM_MODE_ECB,
FSL_SYM_MODE_CBC,
FSL_SYM_MODE_CTR},
{
FSL_HASH_ALG_MD5,
FSL_HASH_ALG_SHA1,
FSL_HASH_ALG_SHA224,
FSL_HASH_ALG_SHA256},
/*
* The following table must be set to handle all values of key algorithm
* and sym mode, and be in the correct order..
*/
{ /* Stream, ECB, CBC, CTR */
{0, 0, 0, 0}, /* HMAC */
{0, 1, 1, 1}, /* AES */
{0, 1, 1, 0}, /* DES */
{0, 1, 1, 0}, /* 3DES */
{1, 0, 0, 0} /* ARC4 */
},
0, 0,
0, 0, 0,
{{0, 0}}
};
#ifdef DIAG_ADAPTOR
void km_Dump_Chain(const sah_Desc * chain);
void km_Dump_Region(const char *prefix, const unsigned char *data,
unsigned length);
static void km_Dump_Link(const char *prefix, const sah_Link * link);
void km_Dump_Words(const char *prefix, const unsigned *data, unsigned length);
#endif
/**** Memory routines ****/
static void *my_malloc(void *ref, size_t n)
{
register void *mem;
#ifndef DIAG_MEM_ERRORS
mem = os_alloc_memory(n, GFP_KERNEL);
#else
{
uint32_t rand;
/* are we feeling lucky ? */
os_get_random_bytes(&rand, sizeof(rand));
if ((rand % DIAG_MEM_CONST) == 0) {
mem = 0;
} else {
mem = os_alloc_memory(n, GFP_ATOMIC);
}
}
#endif /* DIAG_MEM_ERRORS */
#ifdef DIAG_MEM
sprintf(Diag_msg, "API kmalloc: %p for %d\n", mem, n);
LOG_KDIAG(Diag_msg);
#endif
ref = 0; /* unused param warning */
return mem;
}
static sah_Head_Desc *my_alloc_head_desc(void *ref)
{
register sah_Head_Desc *ptr;
#ifndef DIAG_MEM_ERRORS
ptr = sah_Alloc_Head_Descriptor();
#else
{
uint32_t rand;
/* are we feeling lucky ? */
os_get_random_bytes(&rand, sizeof(rand));
if ((rand % DIAG_MEM_CONST) == 0) {
ptr = 0;
} else {
ptr = sah_Alloc_Head_Descriptor();
}
}
#endif
ref = 0;
return ptr;
}
static sah_Desc *my_alloc_desc(void *ref)
{
register sah_Desc *ptr;
#ifndef DIAG_MEM_ERRORS
ptr = sah_Alloc_Descriptor();
#else
{
uint32_t rand;
/* are we feeling lucky ? */
os_get_random_bytes(&rand, sizeof(rand));
if ((rand % DIAG_MEM_CONST) == 0) {
ptr = 0;
} else {
ptr = sah_Alloc_Descriptor();
}
}
#endif
ref = 0;
return ptr;
}
static sah_Link *my_alloc_link(void *ref)
{
register sah_Link *ptr;
#ifndef DIAG_MEM_ERRORS
ptr = sah_Alloc_Link();
#else
{
uint32_t rand;
/* are we feeling lucky ? */
os_get_random_bytes(&rand, sizeof(rand));
if ((rand % DIAG_MEM_CONST) == 0) {
ptr = 0;
} else {
ptr = sah_Alloc_Link();
}
}
#endif
ref = 0;
return ptr;
}
static void my_free(void *ref, void *ptr)
{
ref = 0; /* unused param warning */
#ifdef DIAG_MEM
sprintf(Diag_msg, "API kfree: %p\n", ptr);
LOG_KDIAG(Diag_msg);
#endif
os_free_memory(ptr);
}
static void my_free_head_desc(void *ref, sah_Head_Desc * ptr)
{
sah_Free_Head_Descriptor(ptr);
}
static void my_free_desc(void *ref, sah_Desc * ptr)
{
sah_Free_Descriptor(ptr);
}
static void my_free_link(void *ref, sah_Link * ptr)
{
sah_Free_Link(ptr);
}
static void *my_memcpy(void *ref, void *dest, const void *src, size_t n)
{
ref = 0; /* unused param warning */
return memcpy(dest, src, n);
}
static void *my_memset(void *ref, void *ptr, int ch, size_t n)
{
ref = 0; /* unused param warning */
return memset(ptr, ch, n);
}
/*! Standard memory manipulation routines for kernel API. */
static sah_Mem_Util std_kernelmode_mem_util = {
.mu_ref = 0,
.mu_malloc = my_malloc,
.mu_alloc_head_desc = my_alloc_head_desc,
.mu_alloc_desc = my_alloc_desc,
.mu_alloc_link = my_alloc_link,
.mu_free = my_free,
.mu_free_head_desc = my_free_head_desc,
.mu_free_desc = my_free_desc,
.mu_free_link = my_free_link,
.mu_memcpy = my_memcpy,
.mu_memset = my_memset
};
fsl_shw_return_t get_capabilities(fsl_shw_uco_t * user_ctx,
fsl_shw_pco_t * capabilities)
{
scc_config_t *scc_capabilities;
/* Fill in the Sahara2 capabilities. */
memcpy(capabilities, &sahara2_capabilities, sizeof(fsl_shw_pco_t));
/* Fill in the SCC portion of the capabilities object */
scc_capabilities = scc_get_configuration();
capabilities->scc_driver_major = scc_capabilities->driver_major_version;
capabilities->scc_driver_minor = scc_capabilities->driver_minor_version;
capabilities->scm_version = scc_capabilities->scm_version;
capabilities->smn_version = scc_capabilities->smn_version;
capabilities->block_size_bytes = scc_capabilities->block_size_bytes;
#ifdef FSL_HAVE_SCC
capabilities->scc_info.black_ram_size_blocks =
scc_capabilities->black_ram_size_blocks;
capabilities->scc_info.red_ram_size_blocks =
scc_capabilities->red_ram_size_blocks;
#elif defined(FSL_HAVE_SCC2)
capabilities->scc2_info.partition_size_bytes =
scc_capabilities->partition_size_bytes;
capabilities->scc2_info.partition_count =
scc_capabilities->partition_count;
#endif
return FSL_RETURN_OK_S;
}
/*!
* Sends a request to register this user
*
* @brief Sends a request to register this user
*
* @param[in,out] user_ctx part of the structure contains input parameters and
* part is filled in by the driver
*
* @return A return code of type #fsl_shw_return_t.
*/
fsl_shw_return_t sah_register(fsl_shw_uco_t * user_ctx)
{
fsl_shw_return_t status;
/* this field is used in user mode to indicate a file open has occured.
* it is used here, in kernel mode, to indicate that the uco is registered
*/
user_ctx->sahara_openfd = 0; /* set to 'registered' */
user_ctx->mem_util = &std_kernelmode_mem_util;
/* check that uco is valid */
status = sah_validate_uco(user_ctx);
/* If life is good, register this user */
if (status == FSL_RETURN_OK_S) {
status = sah_handle_registration(user_ctx);
}
if (status != FSL_RETURN_OK_S) {
user_ctx->sahara_openfd = -1; /* set to 'not registered' */
}
return status;
}
/*!
* Sends a request to deregister this user
*
* @brief Sends a request to deregister this user
*
* @param[in,out] user_ctx Info on user being deregistered.
*
* @return A return code of type #fsl_shw_return_t.
*/
fsl_shw_return_t sah_deregister(fsl_shw_uco_t * user_ctx)
{
fsl_shw_return_t status = FSL_RETURN_OK_S;
if (user_ctx->sahara_openfd == 0) {
status = sah_handle_deregistration(user_ctx);
user_ctx->sahara_openfd = -1; /* set to 'no registered */
}
return status;
}
/*!
* Sends a request to get results for this user
*
* @brief Sends a request to get results for this user
*
* @param[in,out] arg Pointer to structure to collect results
* @param uco User's context
*
* @return A return code of type #fsl_shw_return_t.
*/
fsl_shw_return_t sah_get_results(sah_results * arg, fsl_shw_uco_t * uco)
{
fsl_shw_return_t code = sah_get_results_from_pool(uco, arg);
if ((code == FSL_RETURN_OK_S) && (arg->actual != 0)) {
sah_Postprocess_Results(uco, arg);
}
return code;
}
/*!
* This function writes the Descriptor Chain to the kernel driver.
*
* @brief Writes the Descriptor Chain to the kernel driver.
*
* @param dar A pointer to a Descriptor Chain of type sah_Head_Desc
* @param uco The user context object
*
* @return A return code of type #fsl_shw_return_t.
*/
fsl_shw_return_t adaptor_Exec_Descriptor_Chain(sah_Head_Desc * dar,
fsl_shw_uco_t * uco)
{
sah_Head_Desc *kernel_space_desc = NULL;
fsl_shw_return_t code = FSL_RETURN_OK_S;
int os_error_code = 0;
unsigned blocking_mode = dar->uco_flags & FSL_UCO_BLOCKING_MODE;
#ifdef DIAG_ADAPTOR
km_Dump_Chain(&dar->desc);
#endif
dar->user_info = uco;
dar->user_desc = dar;
/* This code has been shamelessly copied from sah_driver_interface.c */
/* It needs to be moved somewhere common ... */
kernel_space_desc = sah_Physicalise_Descriptors(dar);
if (kernel_space_desc == NULL) {
/* We may have failed due to a -EFAULT as well, but we will return
* -ENOMEM since either way it is a memory related failure. */
code = FSL_RETURN_NO_RESOURCE_S;
#ifdef DIAG_DRV_IF
LOG_KDIAG("sah_Physicalise_Descriptors() failed\n");
#endif
} else {
if (blocking_mode) {
#ifdef SAHARA_POLL_MODE
os_error_code = sah_Handle_Poll(dar);
#else
os_error_code = sah_blocking_mode(dar);
#endif
if (os_error_code != 0) {
code = FSL_RETURN_ERROR_S;
} else { /* status of actual operation */
code = dar->result;
}
} else {
#ifdef SAHARA_POLL_MODE
sah_Handle_Poll(dar);
#else
/* just put someting in the DAR */
sah_Queue_Manager_Append_Entry(dar);
#endif /* SAHARA_POLL_MODE */
}
}
return code;
}
/* System keystore context, defined in sah_driver_interface.c */
extern fsl_shw_kso_t system_keystore;
fsl_shw_return_t do_system_keystore_slot_alloc(fsl_shw_uco_t * user_ctx,
uint32_t key_length,
uint64_t ownerid,
uint32_t * slot)
{
(void)user_ctx;
return keystore_slot_alloc(&system_keystore, key_length, ownerid, slot);
}
fsl_shw_return_t do_system_keystore_slot_dealloc(fsl_shw_uco_t * user_ctx,
uint64_t ownerid,
uint32_t slot)
{
(void)user_ctx;
return keystore_slot_dealloc(&system_keystore, ownerid, slot);
}
fsl_shw_return_t do_system_keystore_slot_load(fsl_shw_uco_t * user_ctx,
uint64_t ownerid,
uint32_t slot,
const uint8_t * key,
uint32_t key_length)
{
(void)user_ctx;
return keystore_slot_load(&system_keystore, ownerid, slot,
(void *)key, key_length);
}
fsl_shw_return_t do_system_keystore_slot_read(fsl_shw_uco_t * user_ctx,
uint64_t ownerid,
uint32_t slot,
uint32_t key_length,
const uint8_t * key)
{
(void)user_ctx;
return keystore_slot_read(&system_keystore, ownerid, slot,
key_length, (void *)key);
}
fsl_shw_return_t do_system_keystore_slot_encrypt(fsl_shw_uco_t * user_ctx,
uint64_t ownerid,
uint32_t slot,
uint32_t key_length,
uint8_t * black_data)
{
(void)user_ctx;
return keystore_slot_encrypt(NULL, &system_keystore, ownerid,
slot, key_length, black_data);
}
fsl_shw_return_t do_system_keystore_slot_decrypt(fsl_shw_uco_t * user_ctx,
uint64_t ownerid,
uint32_t slot,
uint32_t key_length,
const uint8_t * black_data)
{
(void)user_ctx;
return keystore_slot_decrypt(NULL, &system_keystore, ownerid,
slot, key_length, black_data);
}
void *fsl_shw_smalloc(fsl_shw_uco_t * user_ctx,
uint32_t size, const uint8_t * UMID, uint32_t permissions)
{
#ifdef FSL_HAVE_SCC2
int part_no;
void *part_base;
uint32_t part_phys;
scc_config_t *scc_configuration;
/* Check that the memory size requested is correct */
scc_configuration = scc_get_configuration();
if (size != scc_configuration->partition_size_bytes) {
return NULL;
}
/* Attempt to grab a partition. */
if (scc_allocate_partition(0, &part_no, &part_base, &part_phys)
!= SCC_RET_OK) {
return NULL;
}
printk(KERN_ALERT "In fsh_shw_smalloc (km): partition_base:%p "
"partition_base_phys: %p\n", part_base, (void *)part_phys);
/* these bits should be in a separate function */
printk(KERN_ALERT "writing UMID and MAP to secure the partition\n");
scc_engage_partition(part_base, UMID, permissions);
(void)user_ctx; /* unused param warning */
return part_base;
#else /* FSL_HAVE_SCC2 */
(void)user_ctx;
(void)size;
(void)UMID;
(void)permissions;
return NULL;
#endif /* FSL_HAVE_SCC2 */
}
fsl_shw_return_t fsl_shw_sfree(fsl_shw_uco_t * user_ctx, void *address)
{
(void)user_ctx;
#ifdef FSL_HAVE_SCC2
if (scc_release_partition(address) == SCC_RET_OK) {
return FSL_RETURN_OK_S;
}
#endif
return FSL_RETURN_ERROR_S;
}
fsl_shw_return_t fsl_shw_sstatus(fsl_shw_uco_t * user_ctx,
void *address,
fsl_shw_partition_status_t * status)
{
(void)user_ctx;
#ifdef FSL_HAVE_SCC2
*status = scc_partition_status(address);
return FSL_RETURN_OK_S;
#endif
return FSL_RETURN_ERROR_S;
}
/* Diminish permissions on some secure memory */
fsl_shw_return_t fsl_shw_diminish_perms(fsl_shw_uco_t * user_ctx,
void *address, uint32_t permissions)
{
(void)user_ctx; /* unused parameter warning */
#ifdef FSL_HAVE_SCC2
if (scc_diminish_permissions(address, permissions) == SCC_RET_OK) {
return FSL_RETURN_OK_S;
}
#endif
return FSL_RETURN_ERROR_S;
}
/*
* partition_base - physical address of the partition
* offset - offset, in blocks, of the data from the start of the partition
* length - length, in bytes, of the data to be encrypted (multiple of 4)
* black_data - virtual address that the encrypted data should be stored at
* Note that this virtual address must be translatable using the __virt_to_phys
* macro; ie, it can't be a specially mapped address. To do encryption with those
* addresses, use the scc_encrypt_region function directly. This is to make
* this function compatible with the user mode declaration, which does not know
* the physical addresses of the data it is using.
*/
fsl_shw_return_t
do_scc_encrypt_region(fsl_shw_uco_t * user_ctx,
void *partition_base, uint32_t offset_bytes,
uint32_t byte_count, uint8_t * black_data,
uint32_t * IV, fsl_shw_cypher_mode_t cypher_mode)
{
scc_return_t scc_ret;
fsl_shw_return_t retval = FSL_RETURN_ERROR_S;
#ifdef FSL_HAVE_SCC2
#ifdef DIAG_ADAPTOR
uint32_t *owner_32 = (uint32_t *) & (owner_id);
LOG_KDIAG_ARGS
("partition base: %p, offset: %i, count: %i, black data: %p\n",
partition_base, offset_bytes, byte_count, (void *)black_data);
#endif
(void)user_ctx;
os_cache_flush_range(black_data, byte_count);
scc_ret =
scc_encrypt_region((uint32_t) partition_base, offset_bytes,
byte_count, __virt_to_phys(black_data), IV,
cypher_mode);
if (scc_ret == SCC_RET_OK) {
retval = FSL_RETURN_OK_S;
} else {
retval = FSL_RETURN_ERROR_S;
}
/* The SCC2 DMA engine should have written to the black ram, so we need to
* invalidate that region of memory. Note that the red ram is not an
* because it is mapped with the cache disabled.
*/
os_cache_inv_range(black_data, byte_count);
#else
(void)scc_ret;
#endif /* FSL_HAVE_SCC2 */
return retval;
}
/*!
* Call the proper function to decrypt a region of encrypted secure memory
*
* @brief
*
* @param user_ctx User context of the partition owner (NULL in kernel)
* @param partition_base Base address (physical) of the partition
* @param offset_bytes Offset from base address that the decrypted data
* shall be placed
* @param byte_count Length of the message (bytes)
* @param black_data Pointer to where the encrypted data is stored
* @param owner_id
*
* @return status
*/
fsl_shw_return_t
do_scc_decrypt_region(fsl_shw_uco_t * user_ctx,
void *partition_base, uint32_t offset_bytes,
uint32_t byte_count, const uint8_t * black_data,
uint32_t * IV, fsl_shw_cypher_mode_t cypher_mode)
{
scc_return_t scc_ret;
fsl_shw_return_t retval = FSL_RETURN_ERROR_S;
#ifdef FSL_HAVE_SCC2
#ifdef DIAG_ADAPTOR
uint32_t *owner_32 = (uint32_t *) & (owner_id);
LOG_KDIAG_ARGS
("partition base: %p, offset: %i, count: %i, black data: %p\n",
partition_base, offset_bytes, byte_count, (void *)black_data);
#endif
(void)user_ctx;
/* The SCC2 DMA engine will be reading from the black ram, so we need to
* make sure that the data is pushed out of the cache. Note that the red
* ram is not an issue because it is mapped with the cache disabled.
*/
os_cache_flush_range(black_data, byte_count);
scc_ret =
scc_decrypt_region((uint32_t) partition_base, offset_bytes,
byte_count,
(uint8_t *) __virt_to_phys(black_data), IV,
cypher_mode);
if (scc_ret == SCC_RET_OK) {
retval = FSL_RETURN_OK_S;
} else {
retval = FSL_RETURN_ERROR_S;
}
#else
(void)scc_ret;
#endif /* FSL_HAVE_SCC2 */
return retval;
}
#ifdef DIAG_ADAPTOR
/*!
* Dump chain of descriptors to the log.
*
* @brief Dump descriptor chain
*
* @param chain Kernel virtual address of start of chain of descriptors
*
* @return void
*/
void km_Dump_Chain(const sah_Desc * chain)
{
while (chain != NULL) {
km_Dump_Words("Desc", (unsigned *)chain,
6 /*sizeof(*chain)/sizeof(unsigned) */ );
/* place this definition elsewhere */
if (chain->ptr1) {
if (chain->header & SAH_HDR_LLO) {
km_Dump_Region(" Data1", chain->ptr1,
chain->len1);
} else {
km_Dump_Link(" Link1", chain->ptr1);
}
}
if (chain->ptr2) {
if (chain->header & SAH_HDR_LLO) {
km_Dump_Region(" Data2", chain->ptr2,
chain->len2);
} else {
km_Dump_Link(" Link2", chain->ptr2);
}
}
chain = chain->next;
}
}
/*!
* Dump chain of links to the log.
*
* @brief Dump chain of links
*
* @param prefix Text to put in front of dumped data
* @param link Kernel virtual address of start of chain of links
*
* @return void
*/
static void km_Dump_Link(const char *prefix, const sah_Link * link)
{
while (link != NULL) {
km_Dump_Words(prefix, (unsigned *)link,
3 /* # words in h/w link */ );
if (link->flags & SAH_STORED_KEY_INFO) {
#ifdef CAN_DUMP_SCC_DATA
uint32_t len;
#endif
#ifdef CAN_DUMP_SCC_DATA
{
char buf[50];
scc_get_slot_info(link->ownerid, link->slot, (uint32_t *) & link->data, /* RED key address */
&len); /* key length */
sprintf(buf, " SCC slot %d: ", link->slot);
km_Dump_Words(buf,
(void *)IO_ADDRESS((uint32_t)
link->data),
link->len / 4);
}
#else
sprintf(Diag_msg, " SCC slot %d", link->slot);
LOG_KDIAG(Diag_msg);
#endif
} else if (link->data != NULL) {
km_Dump_Region(" Data", link->data, link->len);
}
link = link->next;
}
}
/*!
* Dump given region of data to the log.
*
* @brief Dump data
*
* @param prefix Text to put in front of dumped data
* @param data Kernel virtual address of start of region to dump
* @param length Amount of data to dump
*
* @return void
*/
void km_Dump_Region(const char *prefix, const unsigned char *data,
unsigned length)
{
unsigned count;
char *output;
unsigned data_len;
sprintf(Diag_msg, "%s (%08X,%u):", prefix, (uint32_t) data, length);
/* Restrict amount of data to dump */
if (length > MAX_DUMP) {
data_len = MAX_DUMP;
} else {
data_len = length;
}
/* We've already printed some text in output buffer, skip over it */
output = Diag_msg + strlen(Diag_msg);
for (count = 0; count < data_len; count++) {
if (count % 4 == 0) {
*output++ = ' ';
}
sprintf(output, "%02X", *data++);
output += 2;
}
LOG_KDIAG(Diag_msg);
}
/*!
* Dump given wors of data to the log.
*
* @brief Dump data
*
* @param prefix Text to put in front of dumped data
* @param data Kernel virtual address of start of region to dump
* @param word_count Amount of data to dump
*
* @return void
*/
void km_Dump_Words(const char *prefix, const unsigned *data,
unsigned word_count)
{
char *output;
sprintf(Diag_msg, "%s (%08X,%uw): ", prefix, (uint32_t) data,
word_count);
/* We've already printed some text in output buffer, skip over it */
output = Diag_msg + strlen(Diag_msg);
while (word_count--) {
sprintf(output, "%08X ", *data++);
output += 9;
}
LOG_KDIAG(Diag_msg);
}
#endif
| fwmiller/Conserver-Freescale-Linux-U-boot | rpm/BUILD/linux-3.0.35/drivers/mxc/security/sahara2/km_adaptor.c | C | gpl-2.0 | 21,252 |
! { dg-do run }
! { dg-additional-options "-msse2" { target sse2_runtime } }
! { dg-additional-options "-mavx" { target avx_runtime } }
integer :: a(1024), b(1024), k, m, i, s, t
k = 4
m = 2
t = 1
do i = 1, 1024
a(i) = i - 513
b(i) = modulo (i - 52, 39)
if (i.lt.52.and.b(i).ne.0) b(i) = b(i) - 39
end do
s = foo (b)
do i = 1, 1024
if (a(i).ne.((i - 513) * b(i))) call abort
if (i.lt.52.and.modulo (i - 52, 39).ne.0) then
if (b(i).ne.(modulo (i - 52, 39) - 39)) call abort
else
if (b(i).ne.(modulo (i - 52, 39))) call abort
end if
a(i) = i - 513
end do
if (k.ne.(4 + 3 * 1024).or.s.ne.1596127) call abort
k = 4
m = 2
t = 1
s = bar (b)
do i = 1, 1024
if (a(i).ne.((i - 513) * b(i))) call abort
if (i.lt.52.and.modulo (i - 52, 39).ne.0) then
if (b(i).ne.(modulo (i - 52, 39) - 39)) call abort
else
if (b(i).ne.(modulo (i - 52, 39))) call abort
end if
a(i) = i - 513
end do
if (k.ne.(4 + 3 * 1024).or.s.ne.1596127) call abort
k = 4
m = 2
t = 1
s = baz (b)
do i = 1, 1024
if (a(i).ne.((i - 513) * b(i))) call abort
if (i.lt.52.and.modulo (i - 52, 39).ne.0) then
if (b(i).ne.(modulo (i - 52, 39) - 39)) call abort
else
if (b(i).ne.(modulo (i - 52, 39))) call abort
end if
end do
if (k.ne.(4 + 3 * 1024).or.s.ne.1596127) call abort
contains
function foo (p)
integer :: p(1024), u, v, i, s, foo
s = 0
!$omp simd linear(k : m + 1) reduction(+: s) lastprivate(u, v)
do i = 1, 1024
a(i) = a(i) * p(i)
u = p(i) + k
k = k + m + 1
v = p(i) + k
s = s + p(i) + k
end do
!$omp end simd
if (i.ne.1025) call abort
if (u.ne.(36 + 4 + 3 * 1023).or.v.ne.(36 + 4 + 3 * 1024)) call abort
foo = s
end function foo
function bar (p)
integer :: p(1024), u, v, i, s, bar
s = 0
!$omp simd linear(k : m + 1) reduction(+: s) lastprivate(u, v)
do i = 1, 1024, t
a(i) = a(i) * p(i)
u = p(i) + k
k = k + m + 1
v = p(i) + k
s = s + p(i) + k
end do
!$omp end simd
if (i.ne.1025) call abort
if (u.ne.(36 + 4 + 3 * 1023).or.v.ne.(36 + 4 + 3 * 1024)) call abort
bar = s
end function bar
function baz (p)
integer :: p(1024), u, v, i, s, baz
s = 0
!$omp simd linear(k : m + 1) reduction(+: s) lastprivate(u, v) &
!$omp & linear(i : t)
do i = 1, 1024, t
a(i) = a(i) * p(i)
u = p(i) + k
k = k + m + 1
v = p(i) + k
s = s + p(i) + k
end do
if (i.ne.1025) call abort
if (u.ne.(36 + 4 + 3 * 1023).or.v.ne.(36 + 4 + 3 * 1024)) call abort
baz = s
end function baz
end
| lapesd/libgomp | src/libgomp/testsuite/libgomp.fortran/simd2.f90 | FORTRAN | gpl-3.0 | 2,682 |
/*
* File: private/randompatch.h
* ---------------------------
* This file patches the implementation of the random number library
* to avoid some serious bugs in standard implementations of rand,
* particularly on Mac OS X. It also includes a hack to set the
* seed from the RANDOM_SEED environment variable, which makes it
* possible to produce repeatable figures.
*/
/*
* Implementation notes: rand, srand
* ---------------------------------
* To ensure that this package works the same way on all platforms,
* this file completely reimplements the rand and srand methods. The
* algorithm is a conventional linear congruential generator with the
* parameters used in GNU's gclib. RAND_MAX for this implementation
* is 2147483647 (2^31 - 1).
*/
#define MULTIPLIER 1103515245
#define OFFSET 12345
static int _seed = 1;
#undef rand
#define rand() ((_seed = MULTIPLIER * _seed + OFFSET) & 0x7FFFFFFF)
#undef srand
#define srand(seed) (_seed = int(seed), _seed = (_seed <= 0) ? 1 : _seed)
#undef RAND_MAX
#define RAND_MAX 2147483647
/*
* Implementation notes: Windows patch
* -----------------------------------
* On some versions of Windows, the time function is too coarse to use
* as a random seed. On those versions, this definition substitutes the
* GetTickCount function.
*/
#if defined (_MSC_VER) && (_MSC_VER >= 1200)
# include <windows.h>
# define time(dummy) (GetTickCount())
#endif
#ifdef __APPLE__
# include <cstdlib>
static time_t patchedTime(time_t *) {
char *str = getenv("RANDOM_SEED");
if (str == NULL) {
return time(NULL);
} else {
return atoi(str);
}
}
# define time(dummy) patchedTime(dummy)
#endif
| ronny332/TA_CoE | lib/stanford-cpp-library/StanfordCPPLib/private/randompatch.h | C | gpl-3.0 | 1,708 |
package networks
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// List returns a Pager that allows you to iterate over a collection of Network.
func List(client *gophercloud.ServiceClient) pagination.Pager {
return pagination.NewPager(client, listURL(client), func(r pagination.PageResult) pagination.Page {
return NetworkPage{pagination.SinglePageBase(r)}
})
}
// Get returns data about a previously created Network.
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
return
}
| ashetty1/kedge | vendor/github.com/openshift/origin/cmd/service-catalog/go/src/github.com/kubernetes-incubator/service-catalog/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks/requests.go | GO | apache-2.0 | 615 |
/* Test the `vld4f32' ARM Neon intrinsic. */
/* This file was autogenerated by neon-testgen. */
/* { dg-do assemble } */
/* { dg-require-effective-target arm_neon_ok } */
/* { dg-options "-save-temps -O0" } */
/* { dg-add-options arm_neon } */
#include "arm_neon.h"
void test_vld4f32 (void)
{
float32x2x4_t out_float32x2x4_t;
out_float32x2x4_t = vld4_f32 (0);
}
/* { dg-final { scan-assembler "vld4\.32\[ \]+\\\{((\[dD\]\[0-9\]+-\[dD\]\[0-9\]+)|(\[dD\]\[0-9\]+, \[dD\]\[0-9\]+, \[dD\]\[0-9\]+, \[dD\]\[0-9\]+))\\\}, \\\[\[rR\]\[0-9\]+\(:\[0-9\]+\)?\\\]!?\(\[ \]+@\[a-zA-Z0-9 \]+\)?\n" } } */
/* { dg-final { cleanup-saved-temps } } */
| the-linix-project/linix-kernel-source | gccsrc/gcc-4.7.2/gcc/testsuite/gcc.target/arm/neon/vld4f32.c | C | bsd-2-clause | 648 |
/*
* A driver for the Griffin Technology, Inc. "PowerMate" USB controller dial.
*
* v1.1, (c)2002 William R Sowerbutts <will@sowerbutts.com>
*
* This device is a anodised aluminium knob which connects over USB. It can measure
* clockwise and anticlockwise rotation. The dial also acts as a pushbutton with
* a spring for automatic release. The base contains a pair of LEDs which illuminate
* the translucent base. It rotates without limit and reports its relative rotation
* back to the host when polled by the USB controller.
*
* Testing with the knob I have has shown that it measures approximately 94 "clicks"
* for one full rotation. Testing with my High Speed Rotation Actuator (ok, it was
* a variable speed cordless electric drill) has shown that the device can measure
* speeds of up to 7 clicks either clockwise or anticlockwise between pollings from
* the host. If it counts more than 7 clicks before it is polled, it will wrap back
* to zero and start counting again. This was at quite high speed, however, almost
* certainly faster than the human hand could turn it. Griffin say that it loses a
* pulse or two on a direction change; the granularity is so fine that I never
* noticed this in practice.
*
* The device's microcontroller can be programmed to set the LED to either a constant
* intensity, or to a rhythmic pulsing. Several patterns and speeds are available.
*
* Griffin were very happy to provide documentation and free hardware for development.
*
* Some userspace tools are available on the web: http://sowerbutts.com/powermate/
*
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/usb/input.h>
#define POWERMATE_VENDOR 0x077d /* Griffin Technology, Inc. */
#define POWERMATE_PRODUCT_NEW 0x0410 /* Griffin PowerMate */
#define POWERMATE_PRODUCT_OLD 0x04AA /* Griffin soundKnob */
#define CONTOUR_VENDOR 0x05f3 /* Contour Design, Inc. */
#define CONTOUR_JOG 0x0240 /* Jog and Shuttle */
/* these are the command codes we send to the device */
#define SET_STATIC_BRIGHTNESS 0x01
#define SET_PULSE_ASLEEP 0x02
#define SET_PULSE_AWAKE 0x03
#define SET_PULSE_MODE 0x04
/* these refer to bits in the powermate_device's requires_update field. */
#define UPDATE_STATIC_BRIGHTNESS (1<<0)
#define UPDATE_PULSE_ASLEEP (1<<1)
#define UPDATE_PULSE_AWAKE (1<<2)
#define UPDATE_PULSE_MODE (1<<3)
/* at least two versions of the hardware exist, with differing payload
sizes. the first three bytes always contain the "interesting" data in
the relevant format. */
#define POWERMATE_PAYLOAD_SIZE_MAX 6
#define POWERMATE_PAYLOAD_SIZE_MIN 3
struct powermate_device {
signed char *data;
dma_addr_t data_dma;
struct urb *irq, *config;
struct usb_ctrlrequest *configcr;
dma_addr_t configcr_dma;
struct usb_device *udev;
struct input_dev *input;
spinlock_t lock;
int static_brightness;
int pulse_speed;
int pulse_table;
int pulse_asleep;
int pulse_awake;
int requires_update; // physical settings which are out of sync
char phys[64];
};
static char pm_name_powermate[] = "Griffin PowerMate";
static char pm_name_soundknob[] = "Griffin SoundKnob";
static void powermate_config_complete(struct urb *urb);
/* Callback for data arriving from the PowerMate over the USB interrupt pipe */
static void powermate_irq(struct urb *urb)
{
struct powermate_device *pm = urb->context;
int retval;
switch (urb->status) {
case 0:
/* success */
break;
case -ECONNRESET:
case -ENOENT:
case -ESHUTDOWN:
/* this urb is terminated, clean up */
dbg("%s - urb shutting down with status: %d", __func__, urb->status);
return;
default:
dbg("%s - nonzero urb status received: %d", __func__, urb->status);
goto exit;
}
/* handle updates to device state */
input_report_key(pm->input, BTN_0, pm->data[0] & 0x01);
input_report_rel(pm->input, REL_DIAL, pm->data[1]);
input_sync(pm->input);
exit:
retval = usb_submit_urb (urb, GFP_ATOMIC);
if (retval)
err ("%s - usb_submit_urb failed with result %d",
__func__, retval);
}
/* Decide if we need to issue a control message and do so. Must be called with pm->lock taken */
static void powermate_sync_state(struct powermate_device *pm)
{
if (pm->requires_update == 0)
return; /* no updates are required */
if (pm->config->status == -EINPROGRESS)
return; /* an update is already in progress; it'll issue this update when it completes */
if (pm->requires_update & UPDATE_PULSE_ASLEEP){
pm->configcr->wValue = cpu_to_le16( SET_PULSE_ASLEEP );
pm->configcr->wIndex = cpu_to_le16( pm->pulse_asleep ? 1 : 0 );
pm->requires_update &= ~UPDATE_PULSE_ASLEEP;
}else if (pm->requires_update & UPDATE_PULSE_AWAKE){
pm->configcr->wValue = cpu_to_le16( SET_PULSE_AWAKE );
pm->configcr->wIndex = cpu_to_le16( pm->pulse_awake ? 1 : 0 );
pm->requires_update &= ~UPDATE_PULSE_AWAKE;
}else if (pm->requires_update & UPDATE_PULSE_MODE){
int op, arg;
/* the powermate takes an operation and an argument for its pulse algorithm.
the operation can be:
0: divide the speed
1: pulse at normal speed
2: multiply the speed
the argument only has an effect for operations 0 and 2, and ranges between
1 (least effect) to 255 (maximum effect).
thus, several states are equivalent and are coalesced into one state.
we map this onto a range from 0 to 510, with:
0 -- 254 -- use divide (0 = slowest)
255 -- use normal speed
256 -- 510 -- use multiple (510 = fastest).
Only values of 'arg' quite close to 255 are particularly useful/spectacular.
*/
if (pm->pulse_speed < 255) {
op = 0; // divide
arg = 255 - pm->pulse_speed;
} else if (pm->pulse_speed > 255) {
op = 2; // multiply
arg = pm->pulse_speed - 255;
} else {
op = 1; // normal speed
arg = 0; // can be any value
}
pm->configcr->wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE );
pm->configcr->wIndex = cpu_to_le16( (arg << 8) | op );
pm->requires_update &= ~UPDATE_PULSE_MODE;
} else if (pm->requires_update & UPDATE_STATIC_BRIGHTNESS) {
pm->configcr->wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS );
pm->configcr->wIndex = cpu_to_le16( pm->static_brightness );
pm->requires_update &= ~UPDATE_STATIC_BRIGHTNESS;
} else {
printk(KERN_ERR "powermate: unknown update required");
pm->requires_update = 0; /* fudge the bug */
return;
}
/* printk("powermate: %04x %04x\n", pm->configcr->wValue, pm->configcr->wIndex); */
pm->configcr->bRequestType = 0x41; /* vendor request */
pm->configcr->bRequest = 0x01;
pm->configcr->wLength = 0;
usb_fill_control_urb(pm->config, pm->udev, usb_sndctrlpipe(pm->udev, 0),
(void *) pm->configcr, NULL, 0,
powermate_config_complete, pm);
pm->config->setup_dma = pm->configcr_dma;
pm->config->transfer_flags |= URB_NO_SETUP_DMA_MAP;
if (usb_submit_urb(pm->config, GFP_ATOMIC))
printk(KERN_ERR "powermate: usb_submit_urb(config) failed");
}
/* Called when our asynchronous control message completes. We may need to issue another immediately */
static void powermate_config_complete(struct urb *urb)
{
struct powermate_device *pm = urb->context;
unsigned long flags;
if (urb->status)
printk(KERN_ERR "powermate: config urb returned %d\n", urb->status);
spin_lock_irqsave(&pm->lock, flags);
powermate_sync_state(pm);
spin_unlock_irqrestore(&pm->lock, flags);
}
/* Set the LED up as described and begin the sync with the hardware if required */
static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed,
int pulse_table, int pulse_asleep, int pulse_awake)
{
unsigned long flags;
if (pulse_speed < 0)
pulse_speed = 0;
if (pulse_table < 0)
pulse_table = 0;
if (pulse_speed > 510)
pulse_speed = 510;
if (pulse_table > 2)
pulse_table = 2;
pulse_asleep = !!pulse_asleep;
pulse_awake = !!pulse_awake;
spin_lock_irqsave(&pm->lock, flags);
/* mark state updates which are required */
if (static_brightness != pm->static_brightness) {
pm->static_brightness = static_brightness;
pm->requires_update |= UPDATE_STATIC_BRIGHTNESS;
}
if (pulse_asleep != pm->pulse_asleep) {
pm->pulse_asleep = pulse_asleep;
pm->requires_update |= (UPDATE_PULSE_ASLEEP | UPDATE_STATIC_BRIGHTNESS);
}
if (pulse_awake != pm->pulse_awake) {
pm->pulse_awake = pulse_awake;
pm->requires_update |= (UPDATE_PULSE_AWAKE | UPDATE_STATIC_BRIGHTNESS);
}
if (pulse_speed != pm->pulse_speed || pulse_table != pm->pulse_table) {
pm->pulse_speed = pulse_speed;
pm->pulse_table = pulse_table;
pm->requires_update |= UPDATE_PULSE_MODE;
}
powermate_sync_state(pm);
spin_unlock_irqrestore(&pm->lock, flags);
}
/* Callback from the Input layer when an event arrives from userspace to configure the LED */
static int powermate_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int _value)
{
unsigned int command = (unsigned int)_value;
struct powermate_device *pm = input_get_drvdata(dev);
if (type == EV_MSC && code == MSC_PULSELED){
/*
bits 0- 7: 8 bits: LED brightness
bits 8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster.
bits 17-18: 2 bits: pulse table (0, 1, 2 valid)
bit 19: 1 bit : pulse whilst asleep?
bit 20: 1 bit : pulse constantly?
*/
int static_brightness = command & 0xFF; // bits 0-7
int pulse_speed = (command >> 8) & 0x1FF; // bits 8-16
int pulse_table = (command >> 17) & 0x3; // bits 17-18
int pulse_asleep = (command >> 19) & 0x1; // bit 19
int pulse_awake = (command >> 20) & 0x1; // bit 20
powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake);
}
return 0;
}
static int powermate_alloc_buffers(struct usb_device *udev, struct powermate_device *pm)
{
pm->data = usb_buffer_alloc(udev, POWERMATE_PAYLOAD_SIZE_MAX,
GFP_ATOMIC, &pm->data_dma);
if (!pm->data)
return -1;
pm->configcr = usb_buffer_alloc(udev, sizeof(*(pm->configcr)),
GFP_ATOMIC, &pm->configcr_dma);
if (!pm->configcr)
return -1;
return 0;
}
static void powermate_free_buffers(struct usb_device *udev, struct powermate_device *pm)
{
usb_buffer_free(udev, POWERMATE_PAYLOAD_SIZE_MAX,
pm->data, pm->data_dma);
usb_buffer_free(udev, sizeof(*(pm->configcr)),
pm->configcr, pm->configcr_dma);
}
/* Called whenever a USB device matching one in our supported devices table is connected */
static int powermate_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
struct usb_device *udev = interface_to_usbdev (intf);
struct usb_host_interface *interface;
struct usb_endpoint_descriptor *endpoint;
struct powermate_device *pm;
struct input_dev *input_dev;
int pipe, maxp;
int error = -ENOMEM;
interface = intf->cur_altsetting;
endpoint = &interface->endpoint[0].desc;
if (!usb_endpoint_is_int_in(endpoint))
return -EIO;
usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
0x0a, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
0, interface->desc.bInterfaceNumber, NULL, 0,
USB_CTRL_SET_TIMEOUT);
pm = kzalloc(sizeof(struct powermate_device), GFP_KERNEL);
input_dev = input_allocate_device();
if (!pm || !input_dev)
goto fail1;
if (powermate_alloc_buffers(udev, pm))
goto fail2;
pm->irq = usb_alloc_urb(0, GFP_KERNEL);
if (!pm->irq)
goto fail2;
pm->config = usb_alloc_urb(0, GFP_KERNEL);
if (!pm->config)
goto fail3;
pm->udev = udev;
pm->input = input_dev;
usb_make_path(udev, pm->phys, sizeof(pm->phys));
strlcat(pm->phys, "/input0", sizeof(pm->phys));
spin_lock_init(&pm->lock);
switch (le16_to_cpu(udev->descriptor.idProduct)) {
case POWERMATE_PRODUCT_NEW:
input_dev->name = pm_name_powermate;
break;
case POWERMATE_PRODUCT_OLD:
input_dev->name = pm_name_soundknob;
break;
default:
input_dev->name = pm_name_soundknob;
printk(KERN_WARNING "powermate: unknown product id %04x\n",
le16_to_cpu(udev->descriptor.idProduct));
}
input_dev->phys = pm->phys;
usb_to_input_id(udev, &input_dev->id);
input_dev->dev.parent = &intf->dev;
input_set_drvdata(input_dev, pm);
input_dev->event = powermate_input_event;
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL) |
BIT_MASK(EV_MSC);
input_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0);
input_dev->relbit[BIT_WORD(REL_DIAL)] = BIT_MASK(REL_DIAL);
input_dev->mscbit[BIT_WORD(MSC_PULSELED)] = BIT_MASK(MSC_PULSELED);
/* get a handle to the interrupt data pipe */
pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
if (maxp < POWERMATE_PAYLOAD_SIZE_MIN || maxp > POWERMATE_PAYLOAD_SIZE_MAX) {
printk(KERN_WARNING "powermate: Expected payload of %d--%d bytes, found %d bytes!\n",
POWERMATE_PAYLOAD_SIZE_MIN, POWERMATE_PAYLOAD_SIZE_MAX, maxp);
maxp = POWERMATE_PAYLOAD_SIZE_MAX;
}
usb_fill_int_urb(pm->irq, udev, pipe, pm->data,
maxp, powermate_irq,
pm, endpoint->bInterval);
pm->irq->transfer_dma = pm->data_dma;
pm->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
/* register our interrupt URB with the USB system */
if (usb_submit_urb(pm->irq, GFP_KERNEL)) {
error = -EIO;
goto fail4;
}
error = input_register_device(pm->input);
if (error)
goto fail5;
/* force an update of everything */
pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS;
powermate_pulse_led(pm, 0x80, 255, 0, 1, 0); // set default pulse parameters
usb_set_intfdata(intf, pm);
return 0;
fail5: usb_kill_urb(pm->irq);
fail4: usb_free_urb(pm->config);
fail3: usb_free_urb(pm->irq);
fail2: powermate_free_buffers(udev, pm);
fail1: input_free_device(input_dev);
kfree(pm);
return error;
}
/* Called when a USB device we've accepted ownership of is removed */
static void powermate_disconnect(struct usb_interface *intf)
{
struct powermate_device *pm = usb_get_intfdata (intf);
usb_set_intfdata(intf, NULL);
if (pm) {
pm->requires_update = 0;
usb_kill_urb(pm->irq);
input_unregister_device(pm->input);
usb_free_urb(pm->irq);
usb_free_urb(pm->config);
powermate_free_buffers(interface_to_usbdev(intf), pm);
kfree(pm);
}
}
static struct usb_device_id powermate_devices [] = {
{ USB_DEVICE(POWERMATE_VENDOR, POWERMATE_PRODUCT_NEW) },
{ USB_DEVICE(POWERMATE_VENDOR, POWERMATE_PRODUCT_OLD) },
{ USB_DEVICE(CONTOUR_VENDOR, CONTOUR_JOG) },
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE (usb, powermate_devices);
static struct usb_driver powermate_driver = {
.name = "powermate",
.probe = powermate_probe,
.disconnect = powermate_disconnect,
.id_table = powermate_devices,
};
static int __init powermate_init(void)
{
return usb_register(&powermate_driver);
}
static void __exit powermate_cleanup(void)
{
usb_deregister(&powermate_driver);
}
module_init(powermate_init);
module_exit(powermate_cleanup);
MODULE_AUTHOR( "William R Sowerbutts" );
MODULE_DESCRIPTION( "Griffin Technology, Inc PowerMate driver" );
MODULE_LICENSE("GPL");
| EAVR/EV3.14 | ev3sources/extra/linux-03.20.00.13/drivers/input/misc/powermate.c | C | gpl-2.0 | 15,205 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.